<commit_before>import { inject } from "tandem-common/decorators";
import { HTMLFile } from "tandem-html-extension/models/html-file";
import { Observable } from "tandem-common/observable";
import { MetadataKeys } from "tandem-front-end/constants";
import { DocumentFile } from "tandem-front-end/models";
import { watchProperty } from "tandem-common/observable";
import { GroupNodeSection } from "tandem-html-extension/dom";
import { CSSStylesheetsDependency } from "tandem-html-extension/dependencies";
import { parseCSS, CSSRootExpression } from "tandem-html-extension/ast";
import { Dependencies, DEPENDENCIES_NS, Injector } from "tandem-common/dependencies";
import {BaseEntity, EntityMetadata, IEntityDocument } from "tandem-common/ast/entities";

import { CSSRuleEntity } from "./rule";
import  { ICSSRuleEntity } from "./base";

export class CSSRootEntity extends BaseEntity<CSSRootExpression> {

  public owner: HTMLFile;
  public content: string;
  public document: DocumentFile<any>;

  async mapContext(context) {
    this.content = await this.loadCSS(context);
    context.dependencies = context.dependencies.clone();
    CSSStylesheetsDependency.getInstance(context.dependencies).addStyleSheet(this);
    return context;
  }

  async loadCSS(context) {
    return this.document.content;
  }

  getInitialMetadata() {
    return Object.assign(super.getInitialMetadata(), {
      [MetadataKeys.HIDDEN]: true
    });
  }

  cloneLeaf() {
    return new CSSRootEntity(this.source);
  }
}<commit_msg>detect when css changes in tree<commit_after>import { WrapBus } from "mesh";
import { HTMLFile } from "tandem-html-extension/models/html-file";
import { MetadataKeys } from "tandem-front-end/constants";
import { DocumentFile } from "tandem-front-end/models";
import { GroupNodeSection } from "tandem-html-extension/dom";
import { CSSStylesheetsDependency } from "tandem-html-extension/dependencies";
import { parseCSS, CSSRootExpression } from "tandem-html-extension/ast";
import { inject, Action, Observable, BaseEntity } from "tandem-common";

import { CSSRuleEntity } from "./rule";
import  { ICSSRuleEntity } from "./base";

export class CSSRootEntity extends BaseEntity<CSSRootExpression> {

  public owner: HTMLFile;
  public content: string;
  public document: DocumentFile<any>;
  private _useASTAsContent: boolean;

  constructor(source: CSSRootExpression) {
    super(source);
    source.observe(new WrapBus(this.onSourceAction.bind(this)));
  }

  async mapContext(context) {
    this.content = await this.loadCSS(context);
    context.dependencies = context.dependencies.clone();
    CSSStylesheetsDependency.getInstance(context.dependencies).addStyleSheet(this);
    return context;
  }

  async loadCSS(context) {

    // slight optimization -- if the ast is modified, then we want to use that
    // for the HTML document, otherwise we want to go the faster rought and use the document content
    return this._useASTAsContent ? this.source.toString() : this.document.content;
  }

  getInitialMetadata() {
    return Object.assign(super.getInitialMetadata(), {
      [MetadataKeys.HIDDEN]: true
    });
  }

  protected onSourceAction(action: Action) {
    this._useASTAsContent = true;
  }

  cloneLeaf() {
    return new CSSRootEntity(this.source);
  }
}
{'fraction_non_alphanumeric': 0.11439902379499695, 'fraction_numerical': 0.0, 'mean_word_length': 4.682842287694974, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6608102', 'n_tokens_mistral': 977, 'n_tokens_neox': 936, 'n_words': 225}