<commit_before>import { html, render, TemplateResult } from 'lit-html';
import { Property } from './decorators';

/** Extending classes are expected to define `template` and `styles`. */
export interface Element {
  template: TemplateResult;
  styles: TemplateResult;
  shadowRoot: ShadowRoot;
}

export class Element extends HTMLElement {
  private _connected = false;

  constructor() {
    super();
    this.attachShadow({ mode: 'open' });
  }

  /** The component instance has been inserted into the DOM. */
  public connectedCallback() {
    this._connected = true;
    this.upgradeProperties();
    this.upgradeAttributes();
    this.render();
  }

  /** The component instance has been removed from the DOM. */
  public disconnectedCallback() {
    this._connected = false;
  }

  /** Rerender when the observed attributes change. */
  public attributeChangedCallback(_name: string, _oldValue: any, _newValue: any) {
    this.render();
  }

  /** Render the component. */
  public render(): void {
    if (this._connected) {
      render(this._template, this.shadowRoot as ShadowRoot);
    }
  }

  /** Combine the components styles and template. */
  private get _template(): TemplateResult {
    return html`
      ${this.styles}
      ${this.template}
    `;
  }

  /** Helper to quickly query the rendered shadowRoot. `this.$('div.actions')` */
  private $(selectors: string): Element | null {
    return (this.shadowRoot as ShadowRoot).querySelector(selectors);
  }

  /** Support lazy properties https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties */
  private upgradeProperties() {
    const instance = <any>this;
    const props = (instance).constructor['observedAttributes'].concat((instance).constructor['observedProperties']);
    props.forEach((prop: string) => {
      if (instance.hasOwnProperty(prop)) {
        let value = (instance)[prop];
        delete (instance)[prop];
        (instance)[prop] = value;
      }
    });
  }

  /** Perform a one-time upgrade of complex properties from JSON encoded attributes. */
  private upgradeAttributes() {
    const instance = <any>this;
    (instance).constructor['observedProperties'].forEach((prop: string) => {
      if (instance.hasAttribute(prop)) {
        (instance)[prop] = JSON.parse(instance.getAttribute(prop));
        instance.removeAttribute(prop);
      }
    });
  }
}

const Nutmeg = { Element: Element };

export { Nutmeg, Property, html, TemplateResult };<commit_msg>Export Seed alias for Element<commit_after>import { html, render, TemplateResult } from 'lit-html';
import { Property } from './decorators';

/** Extending classes are expected to define `template` and `styles`. */
export interface Element {
  template: TemplateResult;
  styles: TemplateResult;
  shadowRoot: ShadowRoot;
}

export class Element extends HTMLElement {
  private _connected = false;

  constructor() {
    super();
    this.attachShadow({ mode: 'open' });
  }

  /** The component instance has been inserted into the DOM. */
  public connectedCallback() {
    this._connected = true;
    this.upgradeProperties();
    this.upgradeAttributes();
    this.render();
  }

  /** The component instance has been removed from the DOM. */
  public disconnectedCallback() {
    this._connected = false;
  }

  /** Rerender when the observed attributes change. */
  public attributeChangedCallback(_name: string, _oldValue: any, _newValue: any) {
    this.render();
  }

  /** Render the component. */
  public render(): void {
    if (this._connected) {
      render(this._template, this.shadowRoot as ShadowRoot);
    }
  }

  /** Combine the components styles and template. */
  private get _template(): TemplateResult {
    return html`
      ${this.styles}
      ${this.template}
    `;
  }

  /** Helper to quickly query the rendered shadowRoot. `this.$('div.actions')` */
  private $(selectors: string): Element | null {
    return (this.shadowRoot as ShadowRoot).querySelector(selectors);
  }

  /** Support lazy properties https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties */
  private upgradeProperties() {
    const instance = <any>this;
    const props = (instance).constructor['observedAttributes'].concat((instance).constructor['observedProperties']);
    props.forEach((prop: string) => {
      if (instance.hasOwnProperty(prop)) {
        let value = (instance)[prop];
        delete (instance)[prop];
        (instance)[prop] = value;
      }
    });
  }

  /** Perform a one-time upgrade of complex properties from JSON encoded attributes. */
  private upgradeAttributes() {
    const instance = <any>this;
    (instance).constructor['observedProperties'].forEach((prop: string) => {
      if (instance.hasAttribute(prop)) {
        (instance)[prop] = JSON.parse(instance.getAttribute(prop));
        instance.removeAttribute(prop);
      }
    });
  }
}

const Nutmeg = {
  Element: Element,
  Seed: Element,
};

export { Nutmeg, Property, html, TemplateResult };
{'fraction_non_alphanumeric': 0.13355891719745222, 'fraction_numerical': 0.0, 'mean_word_length': 3.466666666666667, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '602293', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1357, 'n_words': 370}