<commit_before>
import create from './create.js';

/**
element(name, options)

- name: 'name'     Custom element tag name, eg. ''
- options: {
       extends:    Name of tag to extend, makes the element a custom built-in element
       mode:       'open' or 'closed', defaults to closed
       template:   String or template node or id used to create a shadow DOM
       attributes: A `{name: fn}` map called when named attributes change
       properties: A map of properties defined on the element prototype. Where
            the property `value` is defined extra work is done to make the
            element work inside a form
       construct:  Lifecycle handler called during element construction with shadow as first argument
       connect:    Lifecycle handler called when element added to DOM with shadow as first argument
       disconnect: Lifecycle handler called when element removed from DOM
       enable:     Lifecycle handler called when form element enabled
       disable:    Lifecycle handler called when form element disabled
       reset:      Lifecycle handler called when form element reset
       restore:    Lifecycle handler called when form element restored
   }
*/

const assign = Object.assign;

const constructors = {
    'a':        HTMLAnchorElement,
    'p':        HTMLParagraphElement,
    'br':       HTMLBRElement,
    'img':      HTMLImageElement,
    'template': HTMLTemplateElement
};

//const inputEvent = new CustomEvent('input', eventOptions);

const $internals = Symbol('internals');
const $shadow    = Symbol('shadow');

const formProperties = {
    // These properties echo those provided by native form controls.
    // They are not strictly necessary, but provided for consistency.
    type: { value: 'text' },

    name: {
        set: function(name) { return this.setAttribute('name', name); },
        get: function() { return this.getAttribute('name') || ''; }
    },

    form: { get: function() { return this[$internals].form; }},
    labels: { get: function() { return this[$internals].labels; }},
    validity: { get: function() { return this[$internals].validity; }},
    validationMessage: { get: function() { return this[$internals].validationMessage; }},
    willValidate: { get: function() { return this[$internals].willValidate; }},

    // Methods
    checkValidity: { value: function() { return this[$internals].checkValidity(); }},
    reportValidity: { value: function() { return this[$internals].reportValidity(); }}
};

function getElementConstructor(tag) {
        // Return a constructor from the known list of tag names – not all tags
        // have constructor names that match their tags
    return constructors[tag]
        // Or assemble the tag name in the form "HTMLTagElement" and return
        // that property of the window object
        || window['HTML' + tag[0].toUpperCase() + tag.slice(1) + 'Element']
        || (() => {
            throw new Error('Constructor not found for tag "' + tag + '"');
        })();
}

function transferProperty(elem, key) {
    if (elem.hasOwnProperty(key)) {
        const value = elem[key];
        delete elem[key];
        elem[key] = value;
    }

    return elem;
}

function getTemplateById(id) {
    const template = document.getElementById(id);

    if (!template || !template.content) {
        throw new Error('Template id="' + id + '" not found in document');
    }

    return template;
}

function createShadow(template, elem, options) {
    if (!template) { return; }

    // Create a shadow root if there is DOM content. Shadows may be 'open' or
    // 'closed'. Closed shadows are not exposed via element.shadowRoot, and
    // events propagating from inside of them report the element as target.
    const shadow = elem.attachShadow({ mode: options.mode || 'closed' }) ;
    elem[$shadow] = shadow;

    // If template is a <template>
    if (typeof template === 'string') {
        shadow.innerHTML = template;
    }
    else {
        shadow.appendChild(template.content.cloneNode(true));
    }
<commit_msg>Element<commit_after>
import create from './create.js';

/**
element(name, options)

- name: 'name'     Custom element tag name, eg. ''
- options: {
       extends:    Name of tag to extend, makes the element a custom built-in element
       mode:       'open' or 'closed', defaults to closed
       template:   String or template node or id used to create a shadow DOM
       attributes: A `{name: fn}` map called when named attributes change
       properties: A map of properties defined on the element prototype. Where
            the property `value` is defined extra work is done to make the
            element work inside a form
       construct:  Lifecycle handler called during element construction with shadow as first argument
       connect:    Lifecycle handler called when element added to DOM with shadow as first argument
       disconnect: Lifecycle handler called when element removed from DOM
       enable:     Lifecycle handler called when form element enabled
       disable:    Lifecycle handler called when form element disabled
       reset:      Lifecycle handler called when form element reset
       restore:    Lifecycle handler called when form element restored
   }
*/

const assign = Object.assign;

const constructors = {
    'a':        HTMLAnchorElement,
    'p':        HTMLParagraphElement,
    'br':       HTMLBRElement,
    'img':      HTMLImageElement,
    'template': HTMLTemplateElement
};

//const inputEvent = new CustomEvent('input', eventOptions);

const $internals = Symbol('internals');
const $shadow    = Symbol('shadow');

const formProperties = {
    // These properties echo those provided by native form controls.
    // They are not strictly necessary, but provided for consistency.
    type: { value: 'text' },

    name: {
        set: function(name) { return this.setAttribute('name', name); },
        get: function() { return this.getAttribute('name') || ''; }
    },

    form: { get: function() { return this[$internals].form; }},
    labels: { get: function() { return this[$internals].labels; }},
    validity: { get: function() { return this[$internals].validity; }},
    validationMessage: { get: function() { return this[$internals].validationMessage; }},
    willValidate: { get: function() { return this[$internals].willValidate; }},

    // Methods
    checkValidity: { value: function() { return this[$internals].checkValidity(); }},
    reportValidity: { value: function() { return this[$internals].reportValidity(); }}
};

function getElementConstructor(tag) {
        // Return a constructor from the known list of tag names – not all tags
        // have constructor names that match their tags
    return constructors[tag]
        // Or assemble the tag name in the form "HTMLTagElement" and return
        // that property of the window object
        || window['HTML' + tag[0].toUpperCase() + tag.slice(1) + 'Element']
        || (() => {
            throw new Error('Constructor not found for tag "' + tag + '"');
        })();
}

function transferProperty(elem, key) {
    if (elem.hasOwnProperty(key)) {
        const value = elem[key];
        delete elem[key];
        elem[key] = value;
    }

    return elem;
}

function getTemplateById(id) {
    const template = document.getElementById(id);

    if (!template || !template.content) {
        throw new Error('Template id="' + id + '" not found in document');
    }

    return template;
}

function createShadow(template, elem, options) {
    if (!template) { return; }

    // Create a shadow root if there is DOM content. Shadows may be 'open' or
    // 'closed'. Closed shadows are not exposed via element.shadowRoot, and
    // events propagating from inside of them report the element as target.
    const shadow = elem.attachShadow({
        mode: options.mode || 'closed',
        delegatesFocus: true
    });

    elem[$shadow] = shadow;

    // If template is a <template>
    if (typeof template === 'string') {
        shadow.innerHTML = template;
    }
    else {
        shadow.appendChild(template.content.cloneNode(true));
    }

{'fraction_non_alphanumeric': 0.10925196850393701, 'fraction_numerical': 0.0004921259842519685, 'mean_word_length': 2.8913355672570606, 'pattern_counts': {'":': 0, '<': 5, '<?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': '67145', 'n_tokens_mistral': 2106, 'n_tokens_neox': 2081, 'n_words': 796}