From 81009a8c65ec13a140a2ffe9a20192f4be007822 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Fri, 31 Mar 2017 17:44:00 -0600 Subject: [PATCH 01/10] Implementing customized builtin elements --- custom-elements.min.js | 53 +++++---- custom-elements.min.js.map | 2 +- src/CustomElementInternals.js | 38 +++++-- src/CustomElementRegistry.js | 62 +++++++---- src/Patch/Document.js | 17 ++- src/Patch/HTMLElementSubclasses.js | 69 ++++++++++++ src/Patch/Native.js | 67 ++++++++++++ src/custom-elements.js | 2 + tests/js/babel.js | 60 ++++++++++ tests/js/instanceof.js | 14 +++ tests/js/reactions.js | 170 ++++++++++++++++++++++++++++- tests/js/registry.js | 15 +++ tests/js/upgrade.js | 12 +- 13 files changed, 514 insertions(+), 67 deletions(-) create mode 100644 src/Patch/HTMLElementSubclasses.js diff --git a/custom-elements.min.js b/custom-elements.min.js index e93a91a..3bfabd8 100644 --- a/custom-elements.min.js +++ b/custom-elements.min.js @@ -1,29 +1,36 @@ (function(){ 'use strict';var g=new function(){};var aa=new Set("annotation-xml color-profile font-face font-face-src font-face-uri font-face-format font-face-name missing-glyph".split(" "));function k(b){var a=aa.has(b);b=/^[a-z][.0-9_a-z]*-[\-.0-9_a-z]*$/.test(b);return!a&&b}function l(b){var a=b.isConnected;if(void 0!==a)return a;for(;b&&!(b.__CE_isImportDocument||b instanceof Document);)b=b.parentNode||(window.ShadowRoot&&b instanceof ShadowRoot?b.host:void 0);return!(!b||!(b.__CE_isImportDocument||b instanceof Document))} function m(b,a){for(;a&&a!==b&&!a.nextSibling;)a=a.parentNode;return a&&a!==b?a.nextSibling:null} -function n(b,a,e){e=e?e:new Set;for(var c=b;c;){if(c.nodeType===Node.ELEMENT_NODE){var d=c;a(d);var h=d.localName;if("link"===h&&"import"===d.getAttribute("rel")){c=d.import;if(c instanceof Node&&!e.has(c))for(e.add(c),c=c.firstChild;c;c=c.nextSibling)n(c,a,e);c=m(b,d);continue}else if("template"===h){c=m(b,d);continue}if(d=d.__CE_shadowRoot)for(d=d.firstChild;d;d=d.nextSibling)n(d,a,e)}c=c.firstChild?c.firstChild:m(b,c)}}function q(b,a,e){b[a]=e};function r(){this.a=new Map;this.f=new Map;this.c=[];this.b=!1}function ba(b,a,e){b.a.set(a,e);b.f.set(e.constructor,e)}function t(b,a){b.b=!0;b.c.push(a)}function v(b,a){b.b&&n(a,function(a){return w(b,a)})}function w(b,a){if(b.b&&!a.__CE_patched){a.__CE_patched=!0;for(var e=0;e=} visitedImports\n */\nexport function walkDeepDescendantElements(root, callback, visitedImports = new Set()) {\n let node = root;\n while (node) {\n if (node.nodeType === Node.ELEMENT_NODE) {\n const element = /** @type {!Element} */(node);\n\n callback(element);\n\n const localName = element.localName;\n if (localName === 'link' && element.getAttribute('rel') === 'import') {\n // If this import (polyfilled or not) has it's root node available,\n // walk it.\n const importNode = /** @type {!Node} */ (element.import);\n if (importNode instanceof Node && !visitedImports.has(importNode)) {\n // Prevent multiple walks of the same import root.\n visitedImports.add(importNode);\n\n for (let child = importNode.firstChild; child; child = child.nextSibling) {\n walkDeepDescendantElements(child, callback, visitedImports);\n }\n }\n\n // Ignore descendants of import links to prevent attempting to walk the\n // elements created by the HTML Imports polyfill that we just walked\n // above.\n node = nextSiblingOrAncestorSibling(root, element);\n continue;\n } else if (localName === 'template') {\n // Ignore descendants of templates. There shouldn't be any descendants\n // because they will be moved into `.content` during construction in\n // browsers that support template but, in case they exist and are still\n // waiting to be moved by a polyfill, they will be ignored.\n node = nextSiblingOrAncestorSibling(root, element);\n continue;\n }\n\n // Walk shadow roots.\n const shadowRoot = element.__CE_shadowRoot;\n if (shadowRoot) {\n for (let child = shadowRoot.firstChild; child; child = child.nextSibling) {\n walkDeepDescendantElements(child, callback, visitedImports);\n }\n }\n }\n\n node = nextNode(root, node);\n }\n}\n\n/**\n * Used to suppress Closure's \"Modifying the prototype is only allowed if the\n * constructor is in the same scope\" warning without using\n * `@suppress {newCheckTypes, duplicate}` because `newCheckTypes` is too broad.\n *\n * @param {!Object} destination\n * @param {string} name\n * @param {*} value\n */\nexport function setPropertyUnchecked(destination, name, value) {\n destination[name] = value;\n}\n","import * as Utilities from './Utilities.js';\nimport CEState from './CustomElementState.js';\n\nexport default class CustomElementInternals {\n constructor() {\n /** @type {!Map} */\n this._localNameToDefinition = new Map();\n\n /** @type {!Map} */\n this._constructorToDefinition = new Map();\n\n /** @type {!Array} */\n this._patches = [];\n\n /** @type {boolean} */\n this._hasPatches = false;\n }\n\n /**\n * @param {string} localName\n * @param {!CustomElementDefinition} definition\n */\n setDefinition(localName, definition) {\n this._localNameToDefinition.set(localName, definition);\n this._constructorToDefinition.set(definition.constructor, definition);\n }\n\n /**\n * @param {string} localName\n * @return {!CustomElementDefinition|undefined}\n */\n localNameToDefinition(localName) {\n return this._localNameToDefinition.get(localName);\n }\n\n /**\n * @param {!Function} constructor\n * @return {!CustomElementDefinition|undefined}\n */\n constructorToDefinition(constructor) {\n return this._constructorToDefinition.get(constructor);\n }\n\n /**\n * @param {!function(!Node)} listener\n */\n addPatch(listener) {\n this._hasPatches = true;\n this._patches.push(listener);\n }\n\n /**\n * @param {!Node} node\n */\n patchTree(node) {\n if (!this._hasPatches) return;\n\n Utilities.walkDeepDescendantElements(node, element => this.patch(element));\n }\n\n /**\n * @param {!Node} node\n */\n patch(node) {\n if (!this._hasPatches) return;\n\n if (node.__CE_patched) return;\n node.__CE_patched = true;\n\n for (let i = 0; i < this._patches.length; i++) {\n this._patches[i](node);\n }\n }\n\n /**\n * @param {!Node} root\n */\n connectTree(root) {\n const elements = [];\n\n Utilities.walkDeepDescendantElements(root, element => elements.push(element));\n\n for (let i = 0; i < elements.length; i++) {\n const element = elements[i];\n if (element.__CE_state === CEState.custom) {\n this.connectedCallback(element);\n } else {\n this.upgradeElement(element);\n }\n }\n }\n\n /**\n * @param {!Node} root\n */\n disconnectTree(root) {\n const elements = [];\n\n Utilities.walkDeepDescendantElements(root, element => elements.push(element));\n\n for (let i = 0; i < elements.length; i++) {\n const element = elements[i];\n if (element.__CE_state === CEState.custom) {\n this.disconnectedCallback(element);\n }\n }\n }\n\n /**\n * Upgrades all uncustomized custom elements at and below a root node for\n * which there is a definition. When custom element reaction callbacks are\n * assumed to be called synchronously (which, by the current DOM / HTML spec\n * definitions, they are *not*), callbacks for both elements customized\n * synchronously by the parser and elements being upgraded occur in the same\n * relative order.\n *\n * NOTE: This function, when used to simulate the construction of a tree that\n * is already created but not customized (i.e. by the parser), does *not*\n * prevent the element from reading the 'final' (true) state of the tree. For\n * example, the element, during truly synchronous parsing / construction would\n * see that it contains no children as they have not yet been inserted.\n * However, this function does not modify the tree, the element will\n * (incorrectly) have children. Additionally, self-modification restrictions\n * for custom element constructors imposed by the DOM spec are *not* enforced.\n *\n *\n * The following nested list shows the steps extending down from the HTML\n * spec's parsing section that cause elements to be synchronously created and\n * upgraded:\n *\n * The \"in body\" insertion mode:\n * https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody\n * - Switch on token:\n * .. other cases ..\n * -> Any other start tag\n * - [Insert an HTML element](below) for the token.\n *\n * Insert an HTML element:\n * https://html.spec.whatwg.org/multipage/syntax.html#insert-an-html-element\n * - Insert a foreign element for the token in the HTML namespace:\n * https://html.spec.whatwg.org/multipage/syntax.html#insert-a-foreign-element\n * - Create an element for a token:\n * https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-the-token\n * - Will execute script flag is true?\n * - (Element queue pushed to the custom element reactions stack.)\n * - Create an element:\n * https://dom.spec.whatwg.org/#concept-create-element\n * - Sync CE flag is true?\n * - Constructor called.\n * - Self-modification restrictions enforced.\n * - Sync CE flag is false?\n * - (Upgrade reaction enqueued.)\n * - Attributes appended to element.\n * (`attributeChangedCallback` reactions enqueued.)\n * - Will execute script flag is true?\n * - (Element queue popped from the custom element reactions stack.\n * Reactions in the popped stack are invoked.)\n * - (Element queue pushed to the custom element reactions stack.)\n * - Insert the element:\n * https://dom.spec.whatwg.org/#concept-node-insert\n * - Shadow-including descendants are connected. During parsing\n * construction, there are no shadow-*excluding* descendants.\n * However, the constructor may have validly attached a shadow\n * tree to itself and added descendants to that shadow tree.\n * (`connectedCallback` reactions enqueued.)\n * - (Element queue popped from the custom element reactions stack.\n * Reactions in the popped stack are invoked.)\n *\n * @param {!Node} root\n * @param {!Set=} visitedImports\n */\n patchAndUpgradeTree(root, visitedImports = new Set()) {\n const elements = [];\n\n const gatherElements = element => {\n if (element.localName === 'link' && element.getAttribute('rel') === 'import') {\n // The HTML Imports polyfill sets a descendant element of the link to\n // the `import` property, specifically this is *not* a Document.\n const importNode = /** @type {?Node} */ (element.import);\n\n if (importNode instanceof Node && importNode.readyState === 'complete') {\n importNode.__CE_isImportDocument = true;\n\n // Connected links are associated with the registry.\n importNode.__CE_hasRegistry = true;\n } else {\n // If this link's import root is not available, its contents can't be\n // walked. Wait for 'load' and walk it when it's ready.\n element.addEventListener('load', () => {\n const importNode = /** @type {!Node} */ (element.import);\n\n if (importNode.__CE_documentLoadHandled) return;\n importNode.__CE_documentLoadHandled = true;\n\n importNode.__CE_isImportDocument = true;\n\n // Connected links are associated with the registry.\n importNode.__CE_hasRegistry = true;\n\n // Clone the `visitedImports` set that was populated sync during\n // the `patchAndUpgradeTree` call that caused this 'load' handler to\n // be added. Then, remove *this* link's import node so that we can\n // walk that import again, even if it was partially walked later\n // during the same `patchAndUpgradeTree` call.\n const clonedVisitedImports = new Set(visitedImports);\n visitedImports.delete(importNode);\n\n this.patchAndUpgradeTree(importNode, visitedImports);\n });\n }\n } else {\n elements.push(element);\n }\n };\n\n // `walkDeepDescendantElements` populates (and internally checks against)\n // `visitedImports` when traversing a loaded import.\n Utilities.walkDeepDescendantElements(root, gatherElements, visitedImports);\n\n if (this._hasPatches) {\n for (let i = 0; i < elements.length; i++) {\n this.patch(elements[i]);\n }\n }\n\n for (let i = 0; i < elements.length; i++) {\n this.upgradeElement(elements[i]);\n }\n }\n\n /**\n * @param {!Element} element\n */\n upgradeElement(element) {\n const currentState = element.__CE_state;\n if (currentState !== undefined) return;\n\n const definition = this.localNameToDefinition(element.localName);\n if (!definition) return;\n\n definition.constructionStack.push(element);\n\n const constructor = definition.constructor;\n try {\n try {\n let result = new (constructor)();\n if (result !== element) {\n throw new Error('The custom element constructor did not produce the element being upgraded.');\n }\n } finally {\n definition.constructionStack.pop();\n }\n } catch (e) {\n element.__CE_state = CEState.failed;\n throw e;\n }\n\n element.__CE_state = CEState.custom;\n element.__CE_definition = definition;\n\n if (definition.attributeChangedCallback) {\n const observedAttributes = definition.observedAttributes;\n for (let i = 0; i < observedAttributes.length; i++) {\n const name = observedAttributes[i];\n const value = element.getAttribute(name);\n if (value !== null) {\n this.attributeChangedCallback(element, name, null, value, null);\n }\n }\n }\n\n if (Utilities.isConnected(element)) {\n this.connectedCallback(element);\n }\n }\n\n /**\n * @param {!Element} element\n */\n connectedCallback(element) {\n const definition = element.__CE_definition;\n if (definition.connectedCallback) {\n definition.connectedCallback.call(element);\n }\n }\n\n /**\n * @param {!Element} element\n */\n disconnectedCallback(element) {\n const definition = element.__CE_definition;\n if (definition.disconnectedCallback) {\n definition.disconnectedCallback.call(element);\n }\n }\n\n /**\n * @param {!Element} element\n * @param {string} name\n * @param {?string} oldValue\n * @param {?string} newValue\n * @param {?string} namespace\n */\n attributeChangedCallback(element, name, oldValue, newValue, namespace) {\n const definition = element.__CE_definition;\n if (\n definition.attributeChangedCallback &&\n definition.observedAttributes.indexOf(name) > -1\n ) {\n definition.attributeChangedCallback.call(element, name, oldValue, newValue, namespace);\n }\n }\n}\n","/**\n * @enum {number}\n */\nconst CustomElementState = {\n custom: 1,\n failed: 2,\n};\n\nexport default CustomElementState;\n","import CustomElementInternals from './CustomElementInternals.js';\n\nexport default class DocumentConstructionObserver {\n constructor(internals, doc) {\n /**\n * @type {!CustomElementInternals}\n */\n this._internals = internals;\n\n /**\n * @type {!Document}\n */\n this._document = doc;\n\n /**\n * @type {MutationObserver|undefined}\n */\n this._observer = undefined;\n\n\n // Simulate tree construction for all currently accessible nodes in the\n // document.\n this._internals.patchAndUpgradeTree(this._document);\n\n if (this._document.readyState === 'loading') {\n this._observer = new MutationObserver(this._handleMutations.bind(this));\n\n // Nodes created by the parser are given to the observer *before* the next\n // task runs. Inline scripts are run in a new task. This means that the\n // observer will be able to handle the newly parsed nodes before the inline\n // script is run.\n this._observer.observe(this._document, {\n childList: true,\n subtree: true,\n });\n }\n }\n\n disconnect() {\n if (this._observer) {\n this._observer.disconnect();\n }\n }\n\n /**\n * @param {!Array} mutations\n */\n _handleMutations(mutations) {\n // Once the document's `readyState` is 'interactive' or 'complete', all new\n // nodes created within that document will be the result of script and\n // should be handled by patching.\n const readyState = this._document.readyState;\n if (readyState === 'interactive' || readyState === 'complete') {\n this.disconnect();\n }\n\n for (let i = 0; i < mutations.length; i++) {\n const addedNodes = mutations[i].addedNodes;\n for (let j = 0; j < addedNodes.length; j++) {\n const node = addedNodes[j];\n this._internals.patchAndUpgradeTree(node);\n }\n }\n }\n}\n","/**\n * @template T\n */\nexport default class Deferred {\n constructor() {\n /**\n * @private\n * @type {T|undefined}\n */\n this._value = undefined;\n\n /**\n * @private\n * @type {Function|undefined}\n */\n this._resolve = undefined;\n\n /**\n * @private\n * @type {!Promise}\n */\n this._promise = new Promise(resolve => {\n this._resolve = resolve;\n\n if (this._value) {\n resolve(this._value);\n }\n });\n }\n\n /**\n * @param {T} value\n */\n resolve(value) {\n if (this._value) {\n throw new Error('Already resolved.');\n }\n\n this._value = value;\n\n if (this._resolve) {\n this._resolve(value);\n }\n }\n\n /**\n * @return {!Promise}\n */\n toPromise() {\n return this._promise;\n }\n}\n","import CustomElementInternals from './CustomElementInternals.js';\nimport DocumentConstructionObserver from './DocumentConstructionObserver.js';\nimport Deferred from './Deferred.js';\nimport * as Utilities from './Utilities.js';\n\n/**\n * @unrestricted\n */\nexport default class CustomElementRegistry {\n\n /**\n * @param {!CustomElementInternals} internals\n */\n constructor(internals) {\n /**\n * @private\n * @type {boolean}\n */\n this._elementDefinitionIsRunning = false;\n\n /**\n * @private\n * @type {!CustomElementInternals}\n */\n this._internals = internals;\n\n /**\n * @private\n * @type {!Map>}\n */\n this._whenDefinedDeferred = new Map();\n\n /**\n * The default flush callback triggers the document walk synchronously.\n * @private\n * @type {!Function}\n */\n this._flushCallback = fn => fn();\n\n /**\n * @private\n * @type {boolean}\n */\n this._flushPending = false;\n\n /**\n * @private\n * @type {!Array}\n */\n this._unflushedLocalNames = [];\n\n /**\n * @private\n * @type {!DocumentConstructionObserver}\n */\n this._documentConstructionObserver = new DocumentConstructionObserver(internals, document);\n }\n\n /**\n * @param {string} localName\n * @param {!Function} constructor\n */\n define(localName, constructor) {\n if (!(constructor instanceof Function)) {\n throw new TypeError('Custom element constructors must be functions.');\n }\n\n if (!Utilities.isValidCustomElementName(localName)) {\n throw new SyntaxError(`The element name '${localName}' is not valid.`);\n }\n\n if (this._internals.localNameToDefinition(localName)) {\n throw new Error(`A custom element with name '${localName}' has already been defined.`);\n }\n\n if (this._elementDefinitionIsRunning) {\n throw new Error('A custom element is already being defined.');\n }\n this._elementDefinitionIsRunning = true;\n\n let connectedCallback;\n let disconnectedCallback;\n let adoptedCallback;\n let attributeChangedCallback;\n let observedAttributes;\n try {\n /** @type {!Object} */\n const prototype = constructor.prototype;\n if (!(prototype instanceof Object)) {\n throw new TypeError('The custom element constructor\\'s prototype is not an object.');\n }\n\n function getCallback(name) {\n const callbackValue = prototype[name];\n if (callbackValue !== undefined && !(callbackValue instanceof Function)) {\n throw new Error(`The '${name}' callback must be a function.`);\n }\n return callbackValue;\n }\n\n connectedCallback = getCallback('connectedCallback');\n disconnectedCallback = getCallback('disconnectedCallback');\n adoptedCallback = getCallback('adoptedCallback');\n attributeChangedCallback = getCallback('attributeChangedCallback');\n observedAttributes = constructor['observedAttributes'] || [];\n } catch (e) {\n return;\n } finally {\n this._elementDefinitionIsRunning = false;\n }\n\n const definition = {\n localName,\n constructor,\n connectedCallback,\n disconnectedCallback,\n adoptedCallback,\n attributeChangedCallback,\n observedAttributes,\n constructionStack: [],\n };\n\n this._internals.setDefinition(localName, definition);\n\n this._unflushedLocalNames.push(localName);\n\n // If we've already called the flush callback and it hasn't called back yet,\n // don't call it again.\n if (!this._flushPending) {\n this._flushPending = true;\n this._flushCallback(() => this._flush());\n }\n }\n\n _flush() {\n // If no new definitions were defined, don't attempt to flush. This could\n // happen if a flush callback keeps the function it is given and calls it\n // multiple times.\n if (this._flushPending === false) return;\n\n this._flushPending = false;\n this._internals.patchAndUpgradeTree(document);\n\n while (this._unflushedLocalNames.length > 0) {\n const localName = this._unflushedLocalNames.shift();\n const deferred = this._whenDefinedDeferred.get(localName);\n if (deferred) {\n deferred.resolve(undefined);\n }\n }\n }\n\n /**\n * @param {string} localName\n * @return {Function|undefined}\n */\n get(localName) {\n const definition = this._internals.localNameToDefinition(localName);\n if (definition) {\n return definition.constructor;\n }\n\n return undefined;\n }\n\n /**\n * @param {string} localName\n * @return {!Promise}\n */\n whenDefined(localName) {\n if (!Utilities.isValidCustomElementName(localName)) {\n return Promise.reject(new SyntaxError(`'${localName}' is not a valid custom element name.`));\n }\n\n const prior = this._whenDefinedDeferred.get(localName);\n if (prior) {\n return prior.toPromise();\n }\n\n const deferred = new Deferred();\n this._whenDefinedDeferred.set(localName, deferred);\n\n const definition = this._internals.localNameToDefinition(localName);\n // Resolve immediately only if the given local name has a definition *and*\n // the full document walk to upgrade elements with that local name has\n // already happened.\n if (definition && this._unflushedLocalNames.indexOf(localName) === -1) {\n deferred.resolve(undefined);\n }\n\n return deferred.toPromise();\n }\n\n polyfillWrapFlushCallback(outer) {\n this._documentConstructionObserver.disconnect();\n const inner = this._flushCallback;\n this._flushCallback = flush => outer(() => inner(flush));\n }\n}\n\n// Closure compiler exports.\nwindow['CustomElementRegistry'] = CustomElementRegistry;\nCustomElementRegistry.prototype['define'] = CustomElementRegistry.prototype.define;\nCustomElementRegistry.prototype['get'] = CustomElementRegistry.prototype.get;\nCustomElementRegistry.prototype['whenDefined'] = CustomElementRegistry.prototype.whenDefined;\nCustomElementRegistry.prototype['polyfillWrapFlushCallback'] = CustomElementRegistry.prototype.polyfillWrapFlushCallback;\n","export default {\n Document_createElement: window.Document.prototype.createElement,\n Document_createElementNS: window.Document.prototype.createElementNS,\n Document_importNode: window.Document.prototype.importNode,\n Document_prepend: window.Document.prototype['prepend'],\n Document_append: window.Document.prototype['append'],\n Node_cloneNode: window.Node.prototype.cloneNode,\n Node_appendChild: window.Node.prototype.appendChild,\n Node_insertBefore: window.Node.prototype.insertBefore,\n Node_removeChild: window.Node.prototype.removeChild,\n Node_replaceChild: window.Node.prototype.replaceChild,\n Node_textContent: Object.getOwnPropertyDescriptor(window.Node.prototype, 'textContent'),\n Element_attachShadow: window.Element.prototype['attachShadow'],\n Element_innerHTML: Object.getOwnPropertyDescriptor(window.Element.prototype, 'innerHTML'),\n Element_getAttribute: window.Element.prototype.getAttribute,\n Element_setAttribute: window.Element.prototype.setAttribute,\n Element_removeAttribute: window.Element.prototype.removeAttribute,\n Element_getAttributeNS: window.Element.prototype.getAttributeNS,\n Element_setAttributeNS: window.Element.prototype.setAttributeNS,\n Element_removeAttributeNS: window.Element.prototype.removeAttributeNS,\n Element_insertAdjacentElement: window.Element.prototype['insertAdjacentElement'],\n Element_prepend: window.Element.prototype['prepend'],\n Element_append: window.Element.prototype['append'],\n Element_before: window.Element.prototype['before'],\n Element_after: window.Element.prototype['after'],\n Element_replaceWith: window.Element.prototype['replaceWith'],\n Element_remove: window.Element.prototype['remove'],\n HTMLElement: window.HTMLElement,\n HTMLElement_innerHTML: Object.getOwnPropertyDescriptor(window.HTMLElement.prototype, 'innerHTML'),\n HTMLElement_insertAdjacentElement: window.HTMLElement.prototype['insertAdjacentElement'],\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport CEState from '../CustomElementState.js';\nimport AlreadyConstructedMarker from '../AlreadyConstructedMarker.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n window['HTMLElement'] = (function() {\n /**\n * @type {function(new: HTMLElement): !HTMLElement}\n */\n function HTMLElement() {\n // This should really be `new.target` but `new.target` can't be emulated\n // in ES5. Assuming the user keeps the default value of the constructor's\n // prototype's `constructor` property, this is equivalent.\n /** @type {!Function} */\n const constructor = this.constructor;\n\n const definition = internals.constructorToDefinition(constructor);\n if (!definition) {\n throw new Error('The custom element being constructed was not registered with `customElements`.');\n }\n\n const constructionStack = definition.constructionStack;\n\n if (constructionStack.length === 0) {\n const element = Native.Document_createElement.call(document, definition.localName);\n Object.setPrototypeOf(element, constructor.prototype);\n element.__CE_state = CEState.custom;\n element.__CE_definition = definition;\n internals.patch(element);\n return element;\n }\n\n const lastIndex = constructionStack.length - 1;\n const element = constructionStack[lastIndex];\n if (element === AlreadyConstructedMarker) {\n throw new Error('The HTMLElement constructor was either called reentrantly for this constructor or called multiple times.');\n }\n constructionStack[lastIndex] = AlreadyConstructedMarker;\n\n Object.setPrototypeOf(element, constructor.prototype);\n internals.patch(/** @type {!HTMLElement} */ (element));\n\n return element;\n }\n\n HTMLElement.prototype = Native.HTMLElement.prototype;\n\n return HTMLElement;\n })();\n};\n","/**\n * @license\n * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.\n * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\n * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\n * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\n * Code distributed by Google as part of the polymer project is also\n * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n */\n\nimport CustomElementInternals from './CustomElementInternals.js';\nimport CustomElementRegistry from './CustomElementRegistry.js';\n\nimport PatchHTMLElement from './Patch/HTMLElement.js';\nimport PatchDocument from './Patch/Document.js';\nimport PatchNode from './Patch/Node.js';\nimport PatchElement from './Patch/Element.js';\n\nconst priorCustomElements = window['customElements'];\n\nif (!priorCustomElements ||\n priorCustomElements['forcePolyfill'] ||\n (typeof priorCustomElements['define'] != 'function') ||\n (typeof priorCustomElements['get'] != 'function')) {\n /** @type {!CustomElementInternals} */\n const internals = new CustomElementInternals();\n\n PatchHTMLElement(internals);\n PatchDocument(internals);\n PatchNode(internals);\n PatchElement(internals);\n\n // The main document is always associated with the registry.\n document.__CE_hasRegistry = true;\n\n /** @type {!CustomElementRegistry} */\n const customElements = new CustomElementRegistry(internals);\n\n Object.defineProperty(window, 'customElements', {\n configurable: true,\n enumerable: true,\n value: customElements,\n });\n}\n","import CustomElementInternals from '../../CustomElementInternals.js';\nimport * as Utilities from '../../Utilities.js';\n\n/**\n * @typedef {{\n * prepend: !function(...(!Node|string)),\n * append: !function(...(!Node|string)),\n * }}\n */\nlet ParentNodeNativeMethods;\n\n/**\n * @param {!CustomElementInternals} internals\n * @param {!Object} destination\n * @param {!ParentNodeNativeMethods} builtIn\n */\nexport default function(internals, destination, builtIn) {\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['prepend'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.prepend.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['append'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.append.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport * as Utilities from '../Utilities.js';\n\nimport PatchParentNode from './Interface/ParentNode.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n Utilities.setPropertyUnchecked(Document.prototype, 'createElement',\n /**\n * @this {Document}\n * @param {string} localName\n * @return {!Element}\n */\n function(localName) {\n // Only create custom elements if this document is associated with the registry.\n if (this.__CE_hasRegistry) {\n const definition = internals.localNameToDefinition(localName);\n if (definition) {\n return new (definition.constructor)();\n }\n }\n\n const result = /** @type {!Element} */\n (Native.Document_createElement.call(this, localName));\n internals.patch(result);\n return result;\n });\n\n Utilities.setPropertyUnchecked(Document.prototype, 'importNode',\n /**\n * @this {Document}\n * @param {!Node} node\n * @param {boolean=} deep\n * @return {!Node}\n */\n function(node, deep) {\n const clone = Native.Document_importNode.call(this, node, deep);\n // Only create custom elements if this document is associated with the registry.\n if (!this.__CE_hasRegistry) {\n internals.patchTree(clone);\n } else {\n internals.patchAndUpgradeTree(clone);\n }\n return clone;\n });\n\n const NS_HTML = \"http://www.w3.org/1999/xhtml\";\n\n Utilities.setPropertyUnchecked(Document.prototype, 'createElementNS',\n /**\n * @this {Document}\n * @param {?string} namespace\n * @param {string} localName\n * @return {!Element}\n */\n function(namespace, localName) {\n // Only create custom elements if this document is associated with the registry.\n if (this.__CE_hasRegistry && (namespace === null || namespace === NS_HTML)) {\n const definition = internals.localNameToDefinition(localName);\n if (definition) {\n return new (definition.constructor)();\n }\n }\n\n const result = /** @type {!Element} */\n (Native.Document_createElementNS.call(this, namespace, localName));\n internals.patch(result);\n return result;\n });\n\n PatchParentNode(internals, Document.prototype, {\n prepend: Native.Document_prepend,\n append: Native.Document_append,\n });\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport * as Utilities from '../Utilities.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n // `Node#nodeValue` is implemented on `Attr`.\n // `Node#textContent` is implemented on `Attr`, `Element`.\n\n Utilities.setPropertyUnchecked(Node.prototype, 'insertBefore',\n /**\n * @this {Node}\n * @param {!Node} node\n * @param {?Node} refNode\n * @return {!Node}\n */\n function(node, refNode) {\n if (node instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(node.childNodes);\n const nativeResult = Native.Node_insertBefore.call(this, node, refNode);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_insertBefore.call(this, node, refNode);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n if (Utilities.isConnected(this)) {\n internals.connectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'appendChild',\n /**\n * @this {Node}\n * @param {!Node} node\n * @return {!Node}\n */\n function(node) {\n if (node instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(node.childNodes);\n const nativeResult = Native.Node_appendChild.call(this, node);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_appendChild.call(this, node);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n if (Utilities.isConnected(this)) {\n internals.connectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'cloneNode',\n /**\n * @this {Node}\n * @param {boolean=} deep\n * @return {!Node}\n */\n function(deep) {\n const clone = Native.Node_cloneNode.call(this, deep);\n // Only create custom elements if this element's owner document is\n // associated with the registry.\n if (!this.ownerDocument.__CE_hasRegistry) {\n internals.patchTree(clone);\n } else {\n internals.patchAndUpgradeTree(clone);\n }\n return clone;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'removeChild',\n /**\n * @this {Node}\n * @param {!Node} node\n * @return {!Node}\n */\n function(node) {\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_removeChild.call(this, node);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'replaceChild',\n /**\n * @this {Node}\n * @param {!Node} nodeToInsert\n * @param {!Node} nodeToRemove\n * @return {!Node}\n */\n function(nodeToInsert, nodeToRemove) {\n if (nodeToInsert instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(nodeToInsert.childNodes);\n const nativeResult = Native.Node_replaceChild.call(this, nodeToInsert, nodeToRemove);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n internals.disconnectTree(nodeToRemove);\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeToInsertWasConnected = Utilities.isConnected(nodeToInsert);\n const nativeResult = Native.Node_replaceChild.call(this, nodeToInsert, nodeToRemove);\n const thisIsConnected = Utilities.isConnected(this);\n\n if (thisIsConnected) {\n internals.disconnectTree(nodeToRemove);\n }\n\n if (nodeToInsertWasConnected) {\n internals.disconnectTree(nodeToInsert);\n }\n\n if (thisIsConnected) {\n internals.connectTree(nodeToInsert);\n }\n\n return nativeResult;\n });\n\n\n function patch_textContent(destination, baseDescriptor) {\n Object.defineProperty(destination, 'textContent', {\n enumerable: baseDescriptor.enumerable,\n configurable: true,\n get: baseDescriptor.get,\n set: /** @this {Node} */ function(assignedValue) {\n // If this is a text node then there are no nodes to disconnect.\n if (this.nodeType === Node.TEXT_NODE) {\n baseDescriptor.set.call(this, assignedValue);\n return;\n }\n\n let removedNodes = undefined;\n // Checking for `firstChild` is faster than reading `childNodes.length`\n // to compare with 0.\n if (this.firstChild) {\n // Using `childNodes` is faster than `children`, even though we only\n // care about elements.\n const childNodes = this.childNodes;\n const childNodesLength = childNodes.length;\n if (childNodesLength > 0 && Utilities.isConnected(this)) {\n // Copying an array by iterating is faster than using slice.\n removedNodes = new Array(childNodesLength);\n for (let i = 0; i < childNodesLength; i++) {\n removedNodes[i] = childNodes[i];\n }\n }\n }\n\n baseDescriptor.set.call(this, assignedValue);\n\n if (removedNodes) {\n for (let i = 0; i < removedNodes.length; i++) {\n internals.disconnectTree(removedNodes[i]);\n }\n }\n },\n });\n }\n\n if (Native.Node_textContent && Native.Node_textContent.get) {\n patch_textContent(Node.prototype, Native.Node_textContent);\n } else {\n internals.addPatch(function(element) {\n patch_textContent(element, {\n enumerable: true,\n configurable: true,\n // NOTE: This implementation of the `textContent` getter assumes that\n // text nodes' `textContent` getter will not be patched.\n get: /** @this {Node} */ function() {\n /** @type {!Array} */\n const parts = [];\n\n for (let i = 0; i < this.childNodes.length; i++) {\n parts.push(this.childNodes[i].textContent);\n }\n\n return parts.join('');\n },\n set: /** @this {Node} */ function(assignedValue) {\n while (this.firstChild) {\n Native.Node_removeChild.call(this, this.firstChild);\n }\n Native.Node_appendChild.call(this, document.createTextNode(assignedValue));\n },\n });\n });\n }\n};\n","import CustomElementInternals from '../../CustomElementInternals.js';\nimport * as Utilities from '../../Utilities.js';\n\n/**\n * @typedef {{\n * before: !function(...(!Node|string)),\n * after: !function(...(!Node|string)),\n * replaceWith: !function(...(!Node|string)),\n * remove: !function(),\n * }}\n */\nlet ChildNodeNativeMethods;\n\n/**\n * @param {!CustomElementInternals} internals\n * @param {!Object} destination\n * @param {!ChildNodeNativeMethods} builtIn\n */\nexport default function(internals, destination, builtIn) {\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['before'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.before.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['after'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.after.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['replaceWith'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n const wasConnected = Utilities.isConnected(this);\n\n builtIn.replaceWith.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (wasConnected) {\n internals.disconnectTree(this);\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n destination['remove'] = function() {\n const wasConnected = Utilities.isConnected(this);\n\n builtIn.remove.call(this);\n\n if (wasConnected) {\n internals.disconnectTree(this);\n }\n };\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport CEState from '../CustomElementState.js';\nimport * as Utilities from '../Utilities.js';\n\nimport PatchParentNode from './Interface/ParentNode.js';\nimport PatchChildNode from './Interface/ChildNode.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n if (Native.Element_attachShadow) {\n Utilities.setPropertyUnchecked(Element.prototype, 'attachShadow',\n /**\n * @this {Element}\n * @param {!{mode: string}} init\n * @return {ShadowRoot}\n */\n function(init) {\n const shadowRoot = Native.Element_attachShadow.call(this, init);\n this.__CE_shadowRoot = shadowRoot;\n return shadowRoot;\n });\n } else {\n console.warn('Custom Elements: `Element#attachShadow` was not patched.');\n }\n\n\n function patch_innerHTML(destination, baseDescriptor) {\n Object.defineProperty(destination, 'innerHTML', {\n enumerable: baseDescriptor.enumerable,\n configurable: true,\n get: baseDescriptor.get,\n set: /** @this {Element} */ function(htmlString) {\n const isConnected = Utilities.isConnected(this);\n\n // NOTE: In IE11, when using the native `innerHTML` setter, all nodes\n // that were previously descendants of the context element have all of\n // their children removed as part of the set - the entire subtree is\n // 'disassembled'. This work around walks the subtree *before* using the\n // native setter.\n /** @type {!Array|undefined} */\n let removedElements = undefined;\n if (isConnected) {\n removedElements = [];\n Utilities.walkDeepDescendantElements(this, element => {\n if (element !== this) {\n removedElements.push(element);\n }\n });\n }\n\n baseDescriptor.set.call(this, htmlString);\n\n if (removedElements) {\n for (let i = 0; i < removedElements.length; i++) {\n const element = removedElements[i];\n if (element.__CE_state === CEState.custom) {\n internals.disconnectedCallback(element);\n }\n }\n }\n\n // Only create custom elements if this element's owner document is\n // associated with the registry.\n if (!this.ownerDocument.__CE_hasRegistry) {\n internals.patchTree(this);\n } else {\n internals.patchAndUpgradeTree(this);\n }\n return htmlString;\n },\n });\n }\n\n if (Native.Element_innerHTML && Native.Element_innerHTML.get) {\n patch_innerHTML(Element.prototype, Native.Element_innerHTML);\n } else if (Native.HTMLElement_innerHTML && Native.HTMLElement_innerHTML.get) {\n patch_innerHTML(HTMLElement.prototype, Native.HTMLElement_innerHTML);\n } else {\n\n /** @type {HTMLDivElement} */\n const rawDiv = Native.Document_createElement.call(document, 'div');\n\n internals.addPatch(function(element) {\n patch_innerHTML(element, {\n enumerable: true,\n configurable: true,\n // Implements getting `innerHTML` by performing an unpatched `cloneNode`\n // of the element and returning the resulting element's `innerHTML`.\n // TODO: Is this too expensive?\n get: /** @this {Element} */ function() {\n return Native.Node_cloneNode.call(this, true).innerHTML;\n },\n // Implements setting `innerHTML` by creating an unpatched element,\n // setting `innerHTML` of that element and replacing the target\n // element's children with those of the unpatched element.\n set: /** @this {Element} */ function(assignedValue) {\n // NOTE: re-route to `content` for `template` elements.\n // We need to do this because `template.appendChild` does not\n // route into `template.content`.\n /** @type {!Node} */\n const content = this.localName === 'template' ? (/** @type {!HTMLTemplateElement} */ (this)).content : this;\n rawDiv.innerHTML = assignedValue;\n\n while (content.childNodes.length > 0) {\n Native.Node_removeChild.call(content, content.childNodes[0]);\n }\n while (rawDiv.childNodes.length > 0) {\n Native.Node_appendChild.call(content, rawDiv.childNodes[0]);\n }\n },\n });\n });\n }\n\n\n Utilities.setPropertyUnchecked(Element.prototype, 'setAttribute',\n /**\n * @this {Element}\n * @param {string} name\n * @param {string} newValue\n */\n function(name, newValue) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_setAttribute.call(this, name, newValue);\n }\n\n const oldValue = Native.Element_getAttribute.call(this, name);\n Native.Element_setAttribute.call(this, name, newValue);\n newValue = Native.Element_getAttribute.call(this, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, null);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'setAttributeNS',\n /**\n * @this {Element}\n * @param {?string} namespace\n * @param {string} name\n * @param {string} newValue\n */\n function(namespace, name, newValue) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_setAttributeNS.call(this, namespace, name, newValue);\n }\n\n const oldValue = Native.Element_getAttributeNS.call(this, namespace, name);\n Native.Element_setAttributeNS.call(this, namespace, name, newValue);\n newValue = Native.Element_getAttributeNS.call(this, namespace, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, namespace);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'removeAttribute',\n /**\n * @this {Element}\n * @param {string} name\n */\n function(name) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_removeAttribute.call(this, name);\n }\n\n const oldValue = Native.Element_getAttribute.call(this, name);\n Native.Element_removeAttribute.call(this, name);\n if (oldValue !== null) {\n internals.attributeChangedCallback(this, name, oldValue, null, null);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'removeAttributeNS',\n /**\n * @this {Element}\n * @param {?string} namespace\n * @param {string} name\n */\n function(namespace, name) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_removeAttributeNS.call(this, namespace, name);\n }\n\n const oldValue = Native.Element_getAttributeNS.call(this, namespace, name);\n Native.Element_removeAttributeNS.call(this, namespace, name);\n // In older browsers, `Element#getAttributeNS` may return the empty string\n // instead of null if the attribute does not exist. For details, see;\n // https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttributeNS#Notes\n const newValue = Native.Element_getAttributeNS.call(this, namespace, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, namespace);\n }\n });\n\n\n function patch_insertAdjacentElement(destination, baseMethod) {\n Utilities.setPropertyUnchecked(destination, 'insertAdjacentElement',\n /**\n * @this {Element}\n * @param {string} where\n * @param {!Element} element\n * @return {?Element}\n */\n function(where, element) {\n const wasConnected = Utilities.isConnected(element);\n const insertedElement = /** @type {!Element} */\n (baseMethod.call(this, where, element));\n\n if (wasConnected) {\n internals.disconnectTree(element);\n }\n\n if (Utilities.isConnected(insertedElement)) {\n internals.connectTree(element);\n }\n return insertedElement;\n });\n }\n\n if (Native.HTMLElement_insertAdjacentElement) {\n patch_insertAdjacentElement(HTMLElement.prototype, Native.HTMLElement_insertAdjacentElement);\n } else if (Native.Element_insertAdjacentElement) {\n patch_insertAdjacentElement(Element.prototype, Native.Element_insertAdjacentElement);\n } else {\n console.warn('Custom Elements: `Element#insertAdjacentElement` was not patched.');\n }\n\n\n PatchParentNode(internals, Element.prototype, {\n prepend: Native.Element_prepend,\n append: Native.Element_append,\n });\n\n PatchChildNode(internals, Element.prototype, {\n before: Native.Element_before,\n after: Native.Element_after,\n replaceWith: Native.Element_replaceWith,\n remove: Native.Element_remove,\n });\n};\n"]} \ No newline at end of file +{"version":3,"sources":["src/AlreadyConstructedMarker.js","src/Utilities.js","src/CustomElementInternals.js","src/CustomElementState.js","src/DocumentConstructionObserver.js","src/Deferred.js","src/CustomElementRegistry.js","src/Patch/Native.js","src/Patch/HTMLElement.js","src/custom-elements.js","src/Patch/HTMLElementSubclasses.js","src/Patch/Interface/ParentNode.js","src/Patch/Document.js","src/Patch/Node.js","src/Patch/Interface/ChildNode.js","src/Patch/Element.js"],"names":["$jscompDefaultExport","AlreadyConstructedMarker","reservedTagList","Set","isValidCustomElementName$$module$$src$Utilities","isValidCustomElementName","localName","reserved","has","validForm","test","isConnected$$module$$src$Utilities","isConnected","node","nativeValue","undefined","current","__CE_isImportDocument","Document","parentNode","window","ShadowRoot","host","nextSiblingOrAncestorSibling$$module$$src$Utilities","nextSiblingOrAncestorSibling","root","start","nextSibling","walkDeepDescendantElements$$module$$src$Utilities","walkDeepDescendantElements","callback","visitedImports","nodeType","Node","ELEMENT_NODE","element","getAttribute","importNode","import","add","child","firstChild","shadowRoot","__CE_shadowRoot","setPropertyUnchecked$$module$$src$Utilities","setPropertyUnchecked","destination","name","value","constructor","CustomElementInternals","_nameToDefinition","Map","_constructorToDefinition","_patches","_hasPatches","setDefinition","definition","set","addPatch","listener","push","patchTree","patch","__CE_patched","i","length","connectTree","elements","custom","__CE_state","connectedCallback","upgradeElement","disconnectTree","disconnectedCallback","patchAndUpgradeTree","gatherElements","readyState","__CE_hasRegistry","addEventListener","__CE_documentLoadHandled","delete","hasAttribute","is","__CE_is","removeAttribute","nodeToDefinition","get","constructionStack","result","Error","pop","e","failed","__CE_definition","attributeChangedCallback","observedAttributes","call","oldValue","newValue","namespace","indexOf","DocumentConstructionObserver","internals","doc","_internals","_document","_observer","MutationObserver","_handleMutations","bind","observe","childList","subtree","disconnect","mutations","addedNodes","j","Deferred","_resolve","_value","_promise","Promise","resolve","CustomElementRegistry","_elementDefinitionIsRunning","_whenDefinedDeferred","_flushCallback","this._flushCallback","fn","_flushPending","_unflushedNames","_documentConstructionObserver","document","define","options","Function","TypeError","SyntaxError","extends","createElement","el","adoptedCallback","getCallback","callbackValue","prototype","Object","_flush","shift","deferred","whenDefined","reject","prior","polyfillWrapFlushCallback","outer","inner","flush","Document_createElement","Document_createElementNS","createElementNS","Document_importNode","Document_prepend","Document_append","Node_cloneNode","cloneNode","Node_appendChild","appendChild","Node_insertBefore","insertBefore","Node_removeChild","removeChild","Node_replaceChild","replaceChild","Node_textContent","getOwnPropertyDescriptor","Element_attachShadow","Element","Element_innerHTML","Element_getAttribute","Element_setAttribute","setAttribute","Element_removeAttribute","Element_getAttributeNS","getAttributeNS","Element_setAttributeNS","setAttributeNS","Element_removeAttributeNS","removeAttributeNS","Element_insertAdjacentElement","Element_prepend","Element_append","Element_before","Element_after","Element_replaceWith","Element_remove","HTMLElement","HTMLElement_innerHTML","HTMLElement_insertAdjacentElement","HTMLElement_subclasses","$jscompDefaultExport$$module$$src$Patch$HTMLElement","$jscompDefaultExport$$module$$src$Patch$Native.Document_createElement.call","setPrototypeOf","lastIndex","$jscompDefaultExport$$module$$src$Patch$Native.HTMLElement","$jscompDefaultExport$$module$$src$Patch$HTMLElementSubclasses","patchElement","elementName","NativeElement","PatchedElement","subclass","$jscompDefaultExport$$module$$src$Patch$Native.HTMLElement_subclasses","$jscompDefaultExport$$module$$src$Patch$Interface$ParentNode","builtIn","connectedBefore","nodes","filter","prepend","apply","append","$jscompDefaultExport$$module$$src$Patch$Document","deep","clone","$jscompDefaultExport$$module$$src$Patch$Native.Document_importNode.call","NS_HTML","$jscompDefaultExport$$module$$src$Patch$Native.Document_createElementNS.call","$jscompDefaultExport$$module$$src$Patch$Native.Document_prepend","$jscompDefaultExport$$module$$src$Patch$Native.Document_append","$jscompDefaultExport$$module$$src$Patch$Node","patch_textContent","baseDescriptor","defineProperty","enumerable","configurable","assignedValue","TEXT_NODE","removedNodes","childNodes","childNodesLength","Array","refNode","DocumentFragment","insertedNodes","slice","nativeResult","$jscompDefaultExport$$module$$src$Patch$Native.Node_insertBefore.call","nodeWasConnected","$jscompDefaultExport$$module$$src$Patch$Native.Node_appendChild.call","$jscompDefaultExport$$module$$src$Patch$Native.Node_cloneNode.call","ownerDocument","$jscompDefaultExport$$module$$src$Patch$Native.Node_removeChild.call","nodeToInsert","nodeToRemove","$jscompDefaultExport$$module$$src$Patch$Native.Node_replaceChild.call","nodeToInsertWasConnected","thisIsConnected","$jscompDefaultExport$$module$$src$Patch$Native.Node_textContent","$jscompDefaultExport$$module$$src$Patch$Native.Node_textContent.get","parts","textContent","join","createTextNode","$jscompDefaultExport$$module$$src$Patch$Interface$ChildNode","$jscompDefaultExport$$module$$src$Patch$Native.Element_before","$jscompDefaultExport$$module$$src$Patch$Native.Element_after","wasConnected","$jscompDefaultExport$$module$$src$Patch$Native.Element_replaceWith","$jscompDefaultExport$$module$$src$Patch$Native.Element_remove","$jscompDefaultExport$$module$$src$Patch$Element","patch_innerHTML","htmlString","removedElements","patch_insertAdjacentElement","baseMethod","where","insertedElement","$jscompDefaultExport$$module$$src$Patch$Native.Element_attachShadow","init","$jscompDefaultExport$$module$$src$Patch$Native.Element_attachShadow.call","console","warn","$jscompDefaultExport$$module$$src$Patch$Native.Element_innerHTML","$jscompDefaultExport$$module$$src$Patch$Native.Element_innerHTML.get","$jscompDefaultExport$$module$$src$Patch$Native.HTMLElement_innerHTML","$jscompDefaultExport$$module$$src$Patch$Native.HTMLElement_innerHTML.get","rawDiv","innerHTML","content","$jscompDefaultExport$$module$$src$Patch$Native.Element_setAttribute.call","$jscompDefaultExport$$module$$src$Patch$Native.Element_getAttribute.call","$jscompDefaultExport$$module$$src$Patch$Native.Element_setAttributeNS.call","$jscompDefaultExport$$module$$src$Patch$Native.Element_getAttributeNS.call","$jscompDefaultExport$$module$$src$Patch$Native.Element_removeAttribute.call","$jscompDefaultExport$$module$$src$Patch$Native.Element_removeAttributeNS.call","$jscompDefaultExport$$module$$src$Patch$Native.HTMLElement_insertAdjacentElement","$jscompDefaultExport$$module$$src$Patch$Native.Element_insertAdjacentElement","$jscompDefaultExport$$module$$src$Patch$Native.Element_prepend","$jscompDefaultExport$$module$$src$Patch$Native.Element_append","priorCustomElements","customElements"],"mappings":"A;aASA,IAAAA,EAAe,IAFfC,QAAA,EAAA,E,CCPA,IAAMC,GAAkB,IAAIC,GAAJ,CAAQ,kHAAA,MAAA,CAAA,GAAA,CAAR,CAejBC,SAASC,EAAwB,CAACC,CAAD,CAAY,CAClD,IAAMC,EAAWL,EAAAM,IAAA,CAAoBF,CAApB,CACXG,EAAAA,CAAY,kCAAAC,KAAA,CAAwCJ,CAAxC,CAClB,OAAO,CAACC,CAAR,EAAoBE,CAH8B,CAW7CE,QAASC,EAAW,CAACC,CAAD,CAAO,CAEhC,IAAMC,EAAcD,CAAAD,YACpB,IAAoBG,IAAAA,EAApB,GAAID,CAAJ,CACE,MAAOA,EAKT,KAAA,CAAOE,CAAP,EAAoB,EAAAA,CAAAC,sBAAA,EAAiCD,CAAjC,WAAoDE,SAApD,CAApB,CAAA,CACEF,CAAA,CAAUA,CAAAG,WAAV,GAAiCC,MAAAC,WAAA,EAAqBL,CAArB,WAAwCK,WAAxC,CAAqDL,CAAAM,KAArD,CAAoEP,IAAAA,EAArG,CAEF,OAAO,EAAGC,CAAA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CAE9CD,WAAY,CAAA,CAFkC,CAG9CvL,MAAO0P,EAHuC,CAAhD,CAhBsD","file":"custom-elements.min.js","sourcesContent":["/**\n * This class exists only to work around Closure's lack of a way to describe\n * singletons. It represents the 'already constructed marker' used in custom\n * element construction stacks.\n *\n * https://html.spec.whatwg.org/#concept-already-constructed-marker\n */\nclass AlreadyConstructedMarker {}\n\nexport default new AlreadyConstructedMarker();\n","const reservedTagList = new Set([\n 'annotation-xml',\n 'color-profile',\n 'font-face',\n 'font-face-src',\n 'font-face-uri',\n 'font-face-format',\n 'font-face-name',\n 'missing-glyph',\n]);\n\n/**\n * @param {string} localName\n * @returns {boolean}\n */\nexport function isValidCustomElementName(localName) {\n const reserved = reservedTagList.has(localName);\n const validForm = /^[a-z][.0-9_a-z]*-[\\-.0-9_a-z]*$/.test(localName);\n return !reserved && validForm;\n}\n\n/**\n * @private\n * @param {!Node} node\n * @return {boolean}\n */\nexport function isConnected(node) {\n // Use `Node#isConnected`, if defined.\n const nativeValue = node.isConnected;\n if (nativeValue !== undefined) {\n return nativeValue;\n }\n\n /** @type {?Node|undefined} */\n let current = node;\n while (current && !(current.__CE_isImportDocument || current instanceof Document)) {\n current = current.parentNode || (window.ShadowRoot && current instanceof ShadowRoot ? current.host : undefined);\n }\n return !!(current && (current.__CE_isImportDocument || current instanceof Document));\n}\n\n/**\n * @param {!Node} root\n * @param {!Node} start\n * @return {?Node}\n */\nfunction nextSiblingOrAncestorSibling(root, start) {\n let node = start;\n while (node && node !== root && !node.nextSibling) {\n node = node.parentNode;\n }\n return (!node || node === root) ? null : node.nextSibling;\n}\n\n/**\n * @param {!Node} root\n * @param {!Node} start\n * @return {?Node}\n */\nfunction nextNode(root, start) {\n return start.firstChild ? start.firstChild : nextSiblingOrAncestorSibling(root, start);\n}\n\n/**\n * @param {!Node} root\n * @param {!function(!Element)} callback\n * @param {!Set=} visitedImports\n */\nexport function walkDeepDescendantElements(root, callback, visitedImports = new Set()) {\n let node = root;\n while (node) {\n if (node.nodeType === Node.ELEMENT_NODE) {\n const element = /** @type {!Element} */(node);\n\n callback(element);\n\n const localName = element.localName;\n if (localName === 'link' && element.getAttribute('rel') === 'import') {\n // If this import (polyfilled or not) has it's root node available,\n // walk it.\n const importNode = /** @type {!Node} */ (element.import);\n if (importNode instanceof Node && !visitedImports.has(importNode)) {\n // Prevent multiple walks of the same import root.\n visitedImports.add(importNode);\n\n for (let child = importNode.firstChild; child; child = child.nextSibling) {\n walkDeepDescendantElements(child, callback, visitedImports);\n }\n }\n\n // Ignore descendants of import links to prevent attempting to walk the\n // elements created by the HTML Imports polyfill that we just walked\n // above.\n node = nextSiblingOrAncestorSibling(root, element);\n continue;\n } else if (localName === 'template') {\n // Ignore descendants of templates. There shouldn't be any descendants\n // because they will be moved into `.content` during construction in\n // browsers that support template but, in case they exist and are still\n // waiting to be moved by a polyfill, they will be ignored.\n node = nextSiblingOrAncestorSibling(root, element);\n continue;\n }\n\n // Walk shadow roots.\n const shadowRoot = element.__CE_shadowRoot;\n if (shadowRoot) {\n for (let child = shadowRoot.firstChild; child; child = child.nextSibling) {\n walkDeepDescendantElements(child, callback, visitedImports);\n }\n }\n }\n\n node = nextNode(root, node);\n }\n}\n\n/**\n * Used to suppress Closure's \"Modifying the prototype is only allowed if the\n * constructor is in the same scope\" warning without using\n * `@suppress {newCheckTypes, duplicate}` because `newCheckTypes` is too broad.\n *\n * @param {!Object} destination\n * @param {string} name\n * @param {*} value\n */\nexport function setPropertyUnchecked(destination, name, value) {\n destination[name] = value;\n}\n","import * as Utilities from './Utilities.js';\nimport CEState from './CustomElementState.js';\n\nexport default class CustomElementInternals {\n constructor() {\n /** @type {!Map} */\n this._nameToDefinition = new Map();\n\n /** @type {!Map} */\n this._constructorToDefinition = new Map();\n\n /** @type {!Array} */\n this._patches = [];\n\n /** @type {boolean} */\n this._hasPatches = false;\n }\n\n /**\n * @param {string} name\n * @param {!CustomElementDefinition} definition\n */\n setDefinition(name, definition) {\n this._nameToDefinition.set(name, definition);\n this._constructorToDefinition.set(definition.constructor, definition);\n }\n\n /**\n * @param {string} name\n * @return {!CustomElementDefinition|undefined}\n */\n nameToDefinition(name) {\n return this._nameToDefinition.get(name);\n }\n\n /**\n * @param {!Function} constructor\n * @return {!CustomElementDefinition|undefined}\n */\n constructorToDefinition(constructor) {\n return this._constructorToDefinition.get(constructor);\n }\n\n /**\n * @param {!Node} node\n * @return {!CustomElementDefinition|null}\n */\n nodeToDefinition(node) {\n const name = typeof node.__CE_is === 'string' ? node.__CE_is : node.localName;\n const definition = this.nameToDefinition(name);\n if (definition && definition.localName === node.localName) {\n return definition;\n } else {\n return null;\n }\n }\n\n /**\n * @param {!function(!Node)} listener\n */\n addPatch(listener) {\n this._hasPatches = true;\n this._patches.push(listener);\n }\n\n /**\n * @param {!Node} node\n */\n patchTree(node) {\n if (!this._hasPatches) return;\n\n Utilities.walkDeepDescendantElements(node, element => this.patch(element));\n }\n\n /**\n * @param {!Node} node\n */\n patch(node) {\n if (!this._hasPatches) return;\n\n if (node.__CE_patched) return;\n node.__CE_patched = true;\n\n for (let i = 0; i < this._patches.length; i++) {\n this._patches[i](node);\n }\n }\n\n /**\n * @param {!Node} root\n */\n connectTree(root) {\n const elements = [];\n\n Utilities.walkDeepDescendantElements(root, element => elements.push(element));\n\n for (let i = 0; i < elements.length; i++) {\n const element = elements[i];\n if (element.__CE_state === CEState.custom) {\n this.connectedCallback(element);\n } else {\n this.upgradeElement(element);\n }\n }\n }\n\n /**\n * @param {!Node} root\n */\n disconnectTree(root) {\n const elements = [];\n\n Utilities.walkDeepDescendantElements(root, element => elements.push(element));\n\n for (let i = 0; i < elements.length; i++) {\n const element = elements[i];\n if (element.__CE_state === CEState.custom) {\n this.disconnectedCallback(element);\n }\n }\n }\n\n /**\n * Upgrades all uncustomized custom elements at and below a root node for\n * which there is a definition. When custom element reaction callbacks are\n * assumed to be called synchronously (which, by the current DOM / HTML spec\n * definitions, they are *not*), callbacks for both elements customized\n * synchronously by the parser and elements being upgraded occur in the same\n * relative order.\n *\n * NOTE: This function, when used to simulate the construction of a tree that\n * is already created but not customized (i.e. by the parser), does *not*\n * prevent the element from reading the 'final' (true) state of the tree. For\n * example, the element, during truly synchronous parsing / construction would\n * see that it contains no children as they have not yet been inserted.\n * However, this function does not modify the tree, the element will\n * (incorrectly) have children. Additionally, self-modification restrictions\n * for custom element constructors imposed by the DOM spec are *not* enforced.\n *\n *\n * The following nested list shows the steps extending down from the HTML\n * spec's parsing section that cause elements to be synchronously created and\n * upgraded:\n *\n * The \"in body\" insertion mode:\n * https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody\n * - Switch on token:\n * .. other cases ..\n * -> Any other start tag\n * - [Insert an HTML element](below) for the token.\n *\n * Insert an HTML element:\n * https://html.spec.whatwg.org/multipage/syntax.html#insert-an-html-element\n * - Insert a foreign element for the token in the HTML namespace:\n * https://html.spec.whatwg.org/multipage/syntax.html#insert-a-foreign-element\n * - Create an element for a token:\n * https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-the-token\n * - Will execute script flag is true?\n * - (Element queue pushed to the custom element reactions stack.)\n * - Create an element:\n * https://dom.spec.whatwg.org/#concept-create-element\n * - Sync CE flag is true?\n * - Constructor called.\n * - Self-modification restrictions enforced.\n * - Sync CE flag is false?\n * - (Upgrade reaction enqueued.)\n * - Attributes appended to element.\n * (`attributeChangedCallback` reactions enqueued.)\n * - Will execute script flag is true?\n * - (Element queue popped from the custom element reactions stack.\n * Reactions in the popped stack are invoked.)\n * - (Element queue pushed to the custom element reactions stack.)\n * - Insert the element:\n * https://dom.spec.whatwg.org/#concept-node-insert\n * - Shadow-including descendants are connected. During parsing\n * construction, there are no shadow-*excluding* descendants.\n * However, the constructor may have validly attached a shadow\n * tree to itself and added descendants to that shadow tree.\n * (`connectedCallback` reactions enqueued.)\n * - (Element queue popped from the custom element reactions stack.\n * Reactions in the popped stack are invoked.)\n *\n * @param {!Node} root\n * @param {!Set=} visitedImports\n */\n patchAndUpgradeTree(root, visitedImports = new Set()) {\n const elements = [];\n\n const gatherElements = element => {\n if (element.localName === 'link' && element.getAttribute('rel') === 'import') {\n // The HTML Imports polyfill sets a descendant element of the link to\n // the `import` property, specifically this is *not* a Document.\n const importNode = /** @type {?Node} */ (element.import);\n\n if (importNode instanceof Node && importNode.readyState === 'complete') {\n importNode.__CE_isImportDocument = true;\n\n // Connected links are associated with the registry.\n importNode.__CE_hasRegistry = true;\n } else {\n // If this link's import root is not available, its contents can't be\n // walked. Wait for 'load' and walk it when it's ready.\n element.addEventListener('load', () => {\n const importNode = /** @type {!Node} */ (element.import);\n\n if (importNode.__CE_documentLoadHandled) return;\n importNode.__CE_documentLoadHandled = true;\n\n importNode.__CE_isImportDocument = true;\n\n // Connected links are associated with the registry.\n importNode.__CE_hasRegistry = true;\n\n // Clone the `visitedImports` set that was populated sync during\n // the `patchAndUpgradeTree` call that caused this 'load' handler to\n // be added. Then, remove *this* link's import node so that we can\n // walk that import again, even if it was partially walked later\n // during the same `patchAndUpgradeTree` call.\n const clonedVisitedImports = new Set(visitedImports);\n visitedImports.delete(importNode);\n\n this.patchAndUpgradeTree(importNode, visitedImports);\n });\n }\n } else if (element.hasAttribute('is') || element.is) {\n element.__CE_is = element.getAttribute('is') || element.is;\n element.removeAttribute('is');\n delete element.is;\n\t\t\t\telements.push(element);\n } else {\n elements.push(element);\n }\n };\n\n // `walkDeepDescendantElements` populates (and internally checks against)\n // `visitedImports` when traversing a loaded import.\n Utilities.walkDeepDescendantElements(root, gatherElements, visitedImports);\n\n if (this._hasPatches) {\n for (let i = 0; i < elements.length; i++) {\n this.patch(elements[i]);\n }\n }\n\n for (let i = 0; i < elements.length; i++) {\n this.upgradeElement(elements[i]);\n }\n }\n\n /**\n * @param {!Element} element\n */\n upgradeElement(element) {\n const currentState = element.__CE_state;\n\t\tif (currentState !== undefined) return;\n const definition = this.nodeToDefinition(element);\n if (!definition) return;\n\n definition.constructionStack.push(element);\n\n const constructor = definition.constructor;\n try {\n try {\n let result = new (constructor)();\n if (result !== element) {\n throw new Error('The custom element constructor did not produce the element being upgraded.');\n }\n } finally {\n definition.constructionStack.pop();\n }\n } catch (e) {\n element.__CE_state = CEState.failed;\n throw e;\n }\n\n element.__CE_state = CEState.custom;\n element.__CE_definition = definition;\n\n if (definition.attributeChangedCallback) {\n const observedAttributes = definition.observedAttributes;\n for (let i = 0; i < observedAttributes.length; i++) {\n const name = observedAttributes[i];\n const value = element.getAttribute(name);\n if (value !== null) {\n this.attributeChangedCallback(element, name, null, value, null);\n }\n }\n }\n\n if (Utilities.isConnected(element)) {\n this.connectedCallback(element);\n }\n }\n\n /**\n * @param {!Element} element\n */\n connectedCallback(element) {\n const definition = element.__CE_definition;\n if (definition.connectedCallback) {\n definition.connectedCallback.call(element);\n }\n }\n\n /**\n * @param {!Element} element\n */\n disconnectedCallback(element) {\n const definition = element.__CE_definition;\n if (definition.disconnectedCallback) {\n definition.disconnectedCallback.call(element);\n }\n }\n\n /**\n * @param {!Element} element\n * @param {string} name\n * @param {?string} oldValue\n * @param {?string} newValue\n * @param {?string} namespace\n */\n attributeChangedCallback(element, name, oldValue, newValue, namespace) {\n const definition = element.__CE_definition;\n if (\n definition.attributeChangedCallback &&\n definition.observedAttributes.indexOf(name) > -1\n ) {\n definition.attributeChangedCallback.call(element, name, oldValue, newValue, namespace);\n }\n }\n}\n","/**\n * @enum {number}\n */\nconst CustomElementState = {\n custom: 1,\n failed: 2,\n};\n\nexport default CustomElementState;\n","import CustomElementInternals from './CustomElementInternals.js';\n\nexport default class DocumentConstructionObserver {\n constructor(internals, doc) {\n /**\n * @type {!CustomElementInternals}\n */\n this._internals = internals;\n\n /**\n * @type {!Document}\n */\n this._document = doc;\n\n /**\n * @type {MutationObserver|undefined}\n */\n this._observer = undefined;\n\n\n // Simulate tree construction for all currently accessible nodes in the\n // document.\n this._internals.patchAndUpgradeTree(this._document);\n\n if (this._document.readyState === 'loading') {\n this._observer = new MutationObserver(this._handleMutations.bind(this));\n\n // Nodes created by the parser are given to the observer *before* the next\n // task runs. Inline scripts are run in a new task. This means that the\n // observer will be able to handle the newly parsed nodes before the inline\n // script is run.\n this._observer.observe(this._document, {\n childList: true,\n subtree: true,\n });\n }\n }\n\n disconnect() {\n if (this._observer) {\n this._observer.disconnect();\n }\n }\n\n /**\n * @param {!Array} mutations\n */\n _handleMutations(mutations) {\n // Once the document's `readyState` is 'interactive' or 'complete', all new\n // nodes created within that document will be the result of script and\n // should be handled by patching.\n const readyState = this._document.readyState;\n if (readyState === 'interactive' || readyState === 'complete') {\n this.disconnect();\n }\n\n for (let i = 0; i < mutations.length; i++) {\n const addedNodes = mutations[i].addedNodes;\n for (let j = 0; j < addedNodes.length; j++) {\n const node = addedNodes[j];\n this._internals.patchAndUpgradeTree(node);\n }\n }\n }\n}\n","/**\n * @template T\n */\nexport default class Deferred {\n constructor() {\n /**\n * @private\n * @type {T|undefined}\n */\n this._value = undefined;\n\n /**\n * @private\n * @type {Function|undefined}\n */\n this._resolve = undefined;\n\n /**\n * @private\n * @type {!Promise}\n */\n this._promise = new Promise(resolve => {\n this._resolve = resolve;\n\n if (this._value) {\n resolve(this._value);\n }\n });\n }\n\n /**\n * @param {T} value\n */\n resolve(value) {\n if (this._value) {\n throw new Error('Already resolved.');\n }\n\n this._value = value;\n\n if (this._resolve) {\n this._resolve(value);\n }\n }\n\n /**\n * @return {!Promise}\n */\n toPromise() {\n return this._promise;\n }\n}\n","import CustomElementInternals from './CustomElementInternals.js';\nimport DocumentConstructionObserver from './DocumentConstructionObserver.js';\nimport Deferred from './Deferred.js';\nimport * as Utilities from './Utilities.js';\n\n/**\n * @unrestricted\n */\nexport default class CustomElementRegistry {\n\n /**\n * @param {!CustomElementInternals} internals\n */\n constructor(internals) {\n /**\n * @private\n * @type {boolean}\n */\n this._elementDefinitionIsRunning = false;\n\n /**\n * @private\n * @type {!CustomElementInternals}\n */\n this._internals = internals;\n\n /**\n * @private\n * @type {!Map>}\n */\n this._whenDefinedDeferred = new Map();\n\n /**\n * The default flush callback triggers the document walk synchronously.\n * @private\n * @type {!Function}\n */\n this._flushCallback = fn => fn();\n\n /**\n * @private\n * @type {boolean}\n */\n this._flushPending = false;\n\n /**\n * @private\n * @type {!Array}\n */\n this._unflushedNames = [];\n\n /**\n * @private\n * @type {!DocumentConstructionObserver}\n */\n this._documentConstructionObserver = new DocumentConstructionObserver(internals, document);\n }\n\n /**\n * @param {string} name\n * @param {!Function} constructor\n */\n define(name, constructor, options) {\n if (!(constructor instanceof Function)) {\n throw new TypeError('Custom element constructors must be functions.');\n }\n\n if (!Utilities.isValidCustomElementName(name)) {\n throw new SyntaxError(`The element name '${name}' is not valid.`);\n }\n\n if (this._internals.nameToDefinition(name)) {\n throw new Error(`A custom element with name '${name}' has already been defined.`);\n }\n\n let localName = name;\n\n if (options && options.extends) {\n if (Utilities.isValidCustomElementName(options.extends)) {\n throw new Error(`A customized builtin element may not extend a custom element.`);\n }\n\n const el = document.createElement(options.extends);\n if (el instanceof window['HTMLUnknownElement']) {\n throw new Error(`Cannot extend '${options.extends}': is not a read HTML element`);\n }\n\n localName = options.extends;\n }\n\n if (this._elementDefinitionIsRunning) {\n throw new Error('A custom element is already being defined.');\n }\n this._elementDefinitionIsRunning = true;\n\n let connectedCallback;\n let disconnectedCallback;\n let adoptedCallback;\n let attributeChangedCallback;\n let observedAttributes;\n try {\n /** @type {!Object} */\n const prototype = constructor.prototype;\n if (!(prototype instanceof Object)) {\n throw new TypeError('The custom element constructor\\'s prototype is not an object.');\n }\n\n function getCallback(name) {\n const callbackValue = prototype[name];\n if (callbackValue !== undefined && !(callbackValue instanceof Function)) {\n throw new Error(`The '${name}' callback must be a function.`);\n }\n return callbackValue;\n }\n\n connectedCallback = getCallback('connectedCallback');\n disconnectedCallback = getCallback('disconnectedCallback');\n adoptedCallback = getCallback('adoptedCallback');\n attributeChangedCallback = getCallback('attributeChangedCallback');\n observedAttributes = constructor['observedAttributes'] || [];\n } catch (e) {\n return;\n } finally {\n this._elementDefinitionIsRunning = false;\n }\n\n const definition = {\n name,\n localName,\n constructor,\n connectedCallback,\n disconnectedCallback,\n adoptedCallback,\n attributeChangedCallback,\n observedAttributes,\n constructionStack: [],\n };\n\n this._internals.setDefinition(name, definition);\n\n this._unflushedNames.push(name);\n\n // If we've already called the flush callback and it hasn't called back yet,\n // don't call it again.\n if (!this._flushPending) {\n this._flushPending = true;\n this._flushCallback(() => this._flush());\n }\n }\n\n _flush() {\n // If no new definitions were defined, don't attempt to flush. This could\n // happen if a flush callback keeps the function it is given and calls it\n // multiple times.\n if (this._flushPending === false) return;\n\n this._flushPending = false;\n this._internals.patchAndUpgradeTree(document);\n\n while (this._unflushedNames.length > 0) {\n const name = this._unflushedNames.shift();\n const deferred = this._whenDefinedDeferred.get(name);\n if (deferred) {\n deferred.resolve(undefined);\n }\n }\n }\n\n /**\n * @param {string} name\n * @return {Function|undefined}\n */\n get(name) {\n const definition = this._internals.nameToDefinition(name);\n if (definition) {\n return definition.constructor;\n }\n\n return undefined;\n }\n\n /**\n * @param {string} name\n * @return {!Promise}\n */\n whenDefined(name) {\n if (!Utilities.isValidCustomElementName(name)) {\n return Promise.reject(new SyntaxError(`'${name}' is not a valid custom element name.`));\n }\n\n const prior = this._whenDefinedDeferred.get(name);\n if (prior) {\n return prior.toPromise();\n }\n\n const deferred = new Deferred();\n this._whenDefinedDeferred.set(name, deferred);\n\n const definition = this._internals.nameToDefinition(name);\n // Resolve immediately only if the given local name has a definition *and*\n // the full document walk to upgrade elements with that local name has\n // already happened.\n if (definition && this._unflushedNames.indexOf(name) === -1) {\n deferred.resolve(undefined);\n }\n\n return deferred.toPromise();\n }\n\n polyfillWrapFlushCallback(outer) {\n this._documentConstructionObserver.disconnect();\n const inner = this._flushCallback;\n this._flushCallback = flush => outer(() => inner(flush));\n }\n}\n\n// Closure compiler exports.\nwindow['CustomElementRegistry'] = CustomElementRegistry;\nCustomElementRegistry.prototype['define'] = CustomElementRegistry.prototype.define;\nCustomElementRegistry.prototype['get'] = CustomElementRegistry.prototype.get;\nCustomElementRegistry.prototype['whenDefined'] = CustomElementRegistry.prototype.whenDefined;\nCustomElementRegistry.prototype['polyfillWrapFlushCallback'] = CustomElementRegistry.prototype.polyfillWrapFlushCallback;\n","export default {\n Document_createElement: window.Document.prototype.createElement,\n Document_createElementNS: window.Document.prototype.createElementNS,\n Document_importNode: window.Document.prototype.importNode,\n Document_prepend: window.Document.prototype['prepend'],\n Document_append: window.Document.prototype['append'],\n Node_cloneNode: window.Node.prototype.cloneNode,\n Node_appendChild: window.Node.prototype.appendChild,\n Node_insertBefore: window.Node.prototype.insertBefore,\n Node_removeChild: window.Node.prototype.removeChild,\n Node_replaceChild: window.Node.prototype.replaceChild,\n Node_textContent: Object.getOwnPropertyDescriptor(window.Node.prototype, 'textContent'),\n Element_attachShadow: window.Element.prototype['attachShadow'],\n Element_innerHTML: Object.getOwnPropertyDescriptor(window.Element.prototype, 'innerHTML'),\n Element_getAttribute: window.Element.prototype.getAttribute,\n Element_setAttribute: window.Element.prototype.setAttribute,\n Element_removeAttribute: window.Element.prototype.removeAttribute,\n Element_getAttributeNS: window.Element.prototype.getAttributeNS,\n Element_setAttributeNS: window.Element.prototype.setAttributeNS,\n Element_removeAttributeNS: window.Element.prototype.removeAttributeNS,\n Element_insertAdjacentElement: window.Element.prototype['insertAdjacentElement'],\n Element_prepend: window.Element.prototype['prepend'],\n Element_append: window.Element.prototype['append'],\n Element_before: window.Element.prototype['before'],\n Element_after: window.Element.prototype['after'],\n Element_replaceWith: window.Element.prototype['replaceWith'],\n Element_remove: window.Element.prototype['remove'],\n HTMLElement: window.HTMLElement,\n HTMLElement_innerHTML: Object.getOwnPropertyDescriptor(window.HTMLElement.prototype, 'innerHTML'),\n HTMLElement_insertAdjacentElement: window.HTMLElement.prototype['insertAdjacentElement'],\n HTMLElement_subclasses: {\n 'Button': window['HTMLButtonElement'],\n 'Canvas': window['HTMLCanvasElement'],\n 'Data': window['HTMLDataElement'],\n 'Head': window['HTMLHeadElement'],\n 'Mod': window['HTMLModElement'],\n 'TableCell': window['HTMLTableCellElement'],\n 'TableCol': window['HTMLTableColElement'],\n 'Anchor': window['HTMLAnchorElement'],\n 'Area': window['HTMLAreaElement'],\n 'Base': window['HTMLBaseElement'],\n 'Body': window['HTMLBodyElement'],\n 'BR': window['HTMLBRElement'],\n 'DataList': window['HTMLDataListElement'],\n 'Details': window['HTMLDetailsElement'],\n 'Dialog': window['HTMLDialogElement'],\n 'Div': window['HTMLDivElement'],\n 'DList': window['HTMLDListElement'],\n 'Embed': window['HTMLEmbedElement'],\n 'FieldSet': window['HTMLFieldSetElement'],\n 'Form': window['HTMLFormElement'],\n 'Heading': window['HTMLHeadingElement'],\n 'HR': window['HTMLHRElement'],\n 'Html': window['HTMLHtmlElement'],\n 'IFrame': window['HTMLIFrameElement'],\n 'Image': window['HTMLImageElement'],\n 'Input': window['HTMLInputElement'],\n 'Keygen': window['HTMLKeygenElement'],\n 'Label': window['HTMLLabelElement'],\n 'Legend': window['HTMLLegendElement'],\n 'LI': window['HTMLLIElement'],\n 'Link': window['HTMLLinkElement'],\n 'Map': window['HTMLMapElement'],\n 'Media': window['HTMLMediaElement'],\n 'Menu': window['HTMLMenuElement'],\n 'MenuItem': window['HTMLMenuItemElement'],\n 'Meta': window['HTMLMetaElement'],\n 'Meter': window['HTMLMeterElement'],\n 'Object': window['HTMLObjectElement'],\n 'OList': window['HTMLOListElement'],\n 'OptGroup': window['HTMLOptGroupElement'],\n 'Option': window['HTMLOptionElement'],\n 'Output': window['HTMLOutputElement'],\n 'Paragraph': window['HTMLParagraphElement'],\n 'Param': window['HTMLParamElement'],\n 'Picture': window['HTMLPictureElement'],\n 'Pre': window['HTMLPreElement'],\n 'Progress': window['HTMLProgressElement'],\n 'Quote': window['HTMLQuoteElement'],\n 'Script': window['HTMLScriptElement'],\n 'Select': window['HTMLSelectElement'],\n 'Slot': window['HTMLSlotElement'],\n 'Source': window['HTMLSourceElement'],\n 'Span': window['HTMLSpanElement'],\n 'Style': window['HTMLStyleElement'],\n 'TableCaption': window['HTMLTableCaptionElement'],\n 'Table': window['HTMLTableElement'],\n 'TableRow': window['HTMLTableRowElement'],\n 'TableSection': window['HTMLTableSectionElement'],\n 'Template': window['HTMLTemplateElement'],\n 'TextArea': window['HTMLTextAreaElement'],\n 'Time': window['HTMLTimeElement'],\n 'Title': window['HTMLTitleElement'],\n 'Track': window['HTMLTrackElement'],\n 'UList': window['HTMLUListElement'],\n 'Unknown': window['HTMLUnknownElement'],\n },\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport CEState from '../CustomElementState.js';\nimport AlreadyConstructedMarker from '../AlreadyConstructedMarker.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n window['HTMLElement'] = (function() {\n /**\n * @type {function(new: HTMLElement): !HTMLElement}\n */\n function HTMLElement() {\n // This should really be `new.target` but `new.target` can't be emulated\n // in ES5. Assuming the user keeps the default value of the constructor's\n // prototype's `constructor` property, this is equivalent.\n /** @type {!Function} */\n const constructor = this.constructor;\n\n const definition = internals.constructorToDefinition(constructor);\n if (!definition) {\n throw new Error('The custom element being constructed was not registered with `customElements`.');\n }\n\n const constructionStack = definition.constructionStack;\n\n if (constructionStack.length === 0) {\n const element = Native.Document_createElement.call(document, definition.localName);\n Object.setPrototypeOf(element, constructor.prototype);\n element.__CE_state = CEState.custom;\n element.__CE_definition = definition;\n internals.patch(element);\n return element;\n }\n\n const lastIndex = constructionStack.length - 1;\n const element = constructionStack[lastIndex];\n if (element === AlreadyConstructedMarker) {\n throw new Error('The HTMLElement constructor was either called reentrantly for this constructor or called multiple times.');\n }\n constructionStack[lastIndex] = AlreadyConstructedMarker;\n\n Object.setPrototypeOf(element, constructor.prototype);\n internals.patch(/** @type {!HTMLElement} */ (element));\n\n return element;\n }\n\n HTMLElement.prototype = Native.HTMLElement.prototype;\n\n return HTMLElement;\n })();\n};\n","/**\n * @license\n * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.\n * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\n * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\n * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\n * Code distributed by Google as part of the polymer project is also\n * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n */\n\nimport CustomElementInternals from './CustomElementInternals.js';\nimport CustomElementRegistry from './CustomElementRegistry.js';\n\nimport PatchHTMLElement from './Patch/HTMLElement.js';\nimport PatchHTMLElementSubclasses from './Patch/HTMLElementSubclasses.js';\nimport PatchDocument from './Patch/Document.js';\nimport PatchNode from './Patch/Node.js';\nimport PatchElement from './Patch/Element.js';\n\nconst priorCustomElements = window['customElements'];\n\nif (!priorCustomElements ||\n priorCustomElements['forcePolyfill'] ||\n (typeof priorCustomElements['define'] != 'function') ||\n (typeof priorCustomElements['get'] != 'function')) {\n /** @type {!CustomElementInternals} */\n const internals = new CustomElementInternals();\n\n PatchHTMLElement(internals);\n\tPatchHTMLElementSubclasses(internals);\n PatchDocument(internals);\n PatchNode(internals);\n PatchElement(internals);\n\n // The main document is always associated with the registry.\n document.__CE_hasRegistry = true;\n\n /** @type {!CustomElementRegistry} */\n const customElements = new CustomElementRegistry(internals);\n\n Object.defineProperty(window, 'customElements', {\n configurable: true,\n enumerable: true,\n value: customElements,\n });\n}\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport CEState from '../CustomElementState.js';\nimport AlreadyConstructedMarker from '../AlreadyConstructedMarker.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n for (let subclass in Native.HTMLElement_subclasses) {\n patchElement(`HTML${subclass}Element`, Native.HTMLElement_subclasses[subclass]);\n }\n\n function patchElement(elementName, NativeElement) {\n if (!NativeElement) {\n return;\n }\n\n window[elementName] = (function() {\n /**\n * @type {function(new: HTMLElement): !HTMLElement}\n */\n function PatchedElement() {\n // This should really be `new.target` but `new.target` can't be emulated\n // in ES5. Assuming the user keeps the default value of the constructor's\n // prototype's `constructor` property, this is equivalent.\n /** @type {!Function} */\n const constructor = this.constructor;\n\n const definition = internals.constructorToDefinition(constructor);\n if (!definition) {\n throw new Error('The custom element being constructed was not registered with `customElements`.');\n }\n\n const constructionStack = definition.constructionStack;\n\n if (constructionStack.length === 0) {\n let element;\n if (definition.name !== definition.localName) {\n element = Native.Document_createElement.call(document, definition.localName, {is: definition.name});\n } else {\n element = Native.Document_createElement.call(document, definition.localName);\n }\n Object.setPrototypeOf(element, constructor.prototype);\n element.__CE_state = CEState.custom;\n element.__CE_definition = definition;\n internals.patch(element);\n return element;\n }\n\n const lastIndex = constructionStack.length - 1;\n const element = constructionStack[lastIndex];\n if (element === AlreadyConstructedMarker) {\n throw new Error(`The ${elementName} constructor was either called reentrantly for this constructor or called multiple times.`);\n }\n constructionStack[lastIndex] = AlreadyConstructedMarker;\n\n Object.setPrototypeOf(element, constructor.prototype);\n internals.patch(/** @type {!HTMLElement} */ (element));\n\n return /** @type {!HTMLElement} */ (element);\n }\n\n PatchedElement.prototype = NativeElement.prototype;\n\n return PatchedElement;\n })();\n }\n};\n","import CustomElementInternals from '../../CustomElementInternals.js';\nimport * as Utilities from '../../Utilities.js';\n\n/**\n * @typedef {{\n * prepend: !function(...(!Node|string)),\n * append: !function(...(!Node|string)),\n * }}\n */\nlet ParentNodeNativeMethods;\n\n/**\n * @param {!CustomElementInternals} internals\n * @param {!Object} destination\n * @param {!ParentNodeNativeMethods} builtIn\n */\nexport default function(internals, destination, builtIn) {\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['prepend'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.prepend.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['append'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.append.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport * as Utilities from '../Utilities.js';\n\nimport PatchParentNode from './Interface/ParentNode.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n Utilities.setPropertyUnchecked(document, 'createElement',\n /**\n * @this {Document}\n * @param {string} localName\n * @return {!Element}\n */\n function(localName, options) {\n // Only create custom elements if this document is associated with the registry.\n if (this.__CE_hasRegistry) {\n\t\t\t\tconst name = options && options.is ? options.is : localName;\n const definition = internals.nameToDefinition(name);\n if (definition) {\n return new (definition.constructor)();\n }\n }\n\n const result = /** @type {!Element} */\n (Native.Document_createElement.call(this, localName));\n\t\t\tif (options && options.is) {\n\t\t\t\tresult.__CE_is = options.is;\n\t\t\t}\n internals.patch(result);\n return result;\n });\n\n Utilities.setPropertyUnchecked(Document.prototype, 'importNode',\n /**\n * @this {Document}\n * @param {!Node} node\n * @param {boolean=} deep\n * @return {!Node}\n */\n function(node, deep) {\n const clone = Native.Document_importNode.call(this, node, deep);\n // Only create custom elements if this document is associated with the registry.\n if (!this.__CE_hasRegistry) {\n internals.patchTree(clone);\n } else {\n internals.patchAndUpgradeTree(clone);\n }\n return clone;\n });\n\n const NS_HTML = \"http://www.w3.org/1999/xhtml\";\n\n Utilities.setPropertyUnchecked(document, 'createElementNS',\n /**\n * @this {Document}\n * @param {?string} namespace\n * @param {string} localName\n * @return {!Element}\n */\n function(namespace, localName, options) {\n // Only create custom elements if this document is associated with the registry.\n if (this.__CE_hasRegistry && (namespace === null || namespace === NS_HTML)) {\n\t\t\t\tconst name = options && options.is ? options.is : localName;\n const definition = internals.nameToDefinition(name);\n if (definition) {\n return new (definition.constructor)();\n }\n }\n\n const result = /** @type {!Element} */\n (Native.Document_createElementNS.call(this, namespace, localName));\n internals.patch(result);\n return result;\n });\n\n PatchParentNode(internals, Document.prototype, {\n prepend: Native.Document_prepend,\n append: Native.Document_append,\n });\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport * as Utilities from '../Utilities.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n // `Node#nodeValue` is implemented on `Attr`.\n // `Node#textContent` is implemented on `Attr`, `Element`.\n\n Utilities.setPropertyUnchecked(Node.prototype, 'insertBefore',\n /**\n * @this {Node}\n * @param {!Node} node\n * @param {?Node} refNode\n * @return {!Node}\n */\n function(node, refNode) {\n if (node instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(node.childNodes);\n const nativeResult = Native.Node_insertBefore.call(this, node, refNode);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_insertBefore.call(this, node, refNode);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n if (Utilities.isConnected(this)) {\n internals.connectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'appendChild',\n /**\n * @this {Node}\n * @param {!Node} node\n * @return {!Node}\n */\n function(node) {\n if (node instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(node.childNodes);\n const nativeResult = Native.Node_appendChild.call(this, node);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_appendChild.call(this, node);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n if (Utilities.isConnected(this)) {\n internals.connectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'cloneNode',\n /**\n * @this {Node}\n * @param {boolean=} deep\n * @return {!Node}\n */\n function(deep) {\n const clone = Native.Node_cloneNode.call(this, deep);\n // Only create custom elements if this element's owner document is\n // associated with the registry.\n if (!this.ownerDocument.__CE_hasRegistry) {\n internals.patchTree(clone);\n } else {\n internals.patchAndUpgradeTree(clone);\n }\n return clone;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'removeChild',\n /**\n * @this {Node}\n * @param {!Node} node\n * @return {!Node}\n */\n function(node) {\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_removeChild.call(this, node);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'replaceChild',\n /**\n * @this {Node}\n * @param {!Node} nodeToInsert\n * @param {!Node} nodeToRemove\n * @return {!Node}\n */\n function(nodeToInsert, nodeToRemove) {\n if (nodeToInsert instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(nodeToInsert.childNodes);\n const nativeResult = Native.Node_replaceChild.call(this, nodeToInsert, nodeToRemove);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n internals.disconnectTree(nodeToRemove);\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeToInsertWasConnected = Utilities.isConnected(nodeToInsert);\n const nativeResult = Native.Node_replaceChild.call(this, nodeToInsert, nodeToRemove);\n const thisIsConnected = Utilities.isConnected(this);\n\n if (thisIsConnected) {\n internals.disconnectTree(nodeToRemove);\n }\n\n if (nodeToInsertWasConnected) {\n internals.disconnectTree(nodeToInsert);\n }\n\n if (thisIsConnected) {\n internals.connectTree(nodeToInsert);\n }\n\n return nativeResult;\n });\n\n\n function patch_textContent(destination, baseDescriptor) {\n Object.defineProperty(destination, 'textContent', {\n enumerable: baseDescriptor.enumerable,\n configurable: true,\n get: baseDescriptor.get,\n set: /** @this {Node} */ function(assignedValue) {\n // If this is a text node then there are no nodes to disconnect.\n if (this.nodeType === Node.TEXT_NODE) {\n baseDescriptor.set.call(this, assignedValue);\n return;\n }\n\n let removedNodes = undefined;\n // Checking for `firstChild` is faster than reading `childNodes.length`\n // to compare with 0.\n if (this.firstChild) {\n // Using `childNodes` is faster than `children`, even though we only\n // care about elements.\n const childNodes = this.childNodes;\n const childNodesLength = childNodes.length;\n if (childNodesLength > 0 && Utilities.isConnected(this)) {\n // Copying an array by iterating is faster than using slice.\n removedNodes = new Array(childNodesLength);\n for (let i = 0; i < childNodesLength; i++) {\n removedNodes[i] = childNodes[i];\n }\n }\n }\n\n baseDescriptor.set.call(this, assignedValue);\n\n if (removedNodes) {\n for (let i = 0; i < removedNodes.length; i++) {\n internals.disconnectTree(removedNodes[i]);\n }\n }\n },\n });\n }\n\n if (Native.Node_textContent && Native.Node_textContent.get) {\n patch_textContent(Node.prototype, Native.Node_textContent);\n } else {\n internals.addPatch(function(element) {\n patch_textContent(element, {\n enumerable: true,\n configurable: true,\n // NOTE: This implementation of the `textContent` getter assumes that\n // text nodes' `textContent` getter will not be patched.\n get: /** @this {Node} */ function() {\n /** @type {!Array} */\n const parts = [];\n\n for (let i = 0; i < this.childNodes.length; i++) {\n parts.push(this.childNodes[i].textContent);\n }\n\n return parts.join('');\n },\n set: /** @this {Node} */ function(assignedValue) {\n while (this.firstChild) {\n Native.Node_removeChild.call(this, this.firstChild);\n }\n Native.Node_appendChild.call(this, document.createTextNode(assignedValue));\n },\n });\n });\n }\n};\n","import CustomElementInternals from '../../CustomElementInternals.js';\nimport * as Utilities from '../../Utilities.js';\n\n/**\n * @typedef {{\n * before: !function(...(!Node|string)),\n * after: !function(...(!Node|string)),\n * replaceWith: !function(...(!Node|string)),\n * remove: !function(),\n * }}\n */\nlet ChildNodeNativeMethods;\n\n/**\n * @param {!CustomElementInternals} internals\n * @param {!Object} destination\n * @param {!ChildNodeNativeMethods} builtIn\n */\nexport default function(internals, destination, builtIn) {\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['before'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.before.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['after'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.after.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['replaceWith'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n const wasConnected = Utilities.isConnected(this);\n\n builtIn.replaceWith.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (wasConnected) {\n internals.disconnectTree(this);\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n destination['remove'] = function() {\n const wasConnected = Utilities.isConnected(this);\n\n builtIn.remove.call(this);\n\n if (wasConnected) {\n internals.disconnectTree(this);\n }\n };\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport CEState from '../CustomElementState.js';\nimport * as Utilities from '../Utilities.js';\n\nimport PatchParentNode from './Interface/ParentNode.js';\nimport PatchChildNode from './Interface/ChildNode.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n if (Native.Element_attachShadow) {\n Utilities.setPropertyUnchecked(Element.prototype, 'attachShadow',\n /**\n * @this {Element}\n * @param {!{mode: string}} init\n * @return {ShadowRoot}\n */\n function(init) {\n const shadowRoot = Native.Element_attachShadow.call(this, init);\n this.__CE_shadowRoot = shadowRoot;\n return shadowRoot;\n });\n } else {\n console.warn('Custom Elements: `Element#attachShadow` was not patched.');\n }\n\n\n function patch_innerHTML(destination, baseDescriptor) {\n Object.defineProperty(destination, 'innerHTML', {\n enumerable: baseDescriptor.enumerable,\n configurable: true,\n get: baseDescriptor.get,\n set: /** @this {Element} */ function(htmlString) {\n const isConnected = Utilities.isConnected(this);\n\n // NOTE: In IE11, when using the native `innerHTML` setter, all nodes\n // that were previously descendants of the context element have all of\n // their children removed as part of the set - the entire subtree is\n // 'disassembled'. This work around walks the subtree *before* using the\n // native setter.\n /** @type {!Array|undefined} */\n let removedElements = undefined;\n if (isConnected) {\n removedElements = [];\n Utilities.walkDeepDescendantElements(this, element => {\n if (element !== this) {\n removedElements.push(element);\n }\n });\n }\n\n baseDescriptor.set.call(this, htmlString);\n\n if (removedElements) {\n for (let i = 0; i < removedElements.length; i++) {\n const element = removedElements[i];\n if (element.__CE_state === CEState.custom) {\n internals.disconnectedCallback(element);\n }\n }\n }\n\n // Only create custom elements if this element's owner document is\n // associated with the registry.\n if (!this.ownerDocument.__CE_hasRegistry) {\n internals.patchTree(this);\n } else {\n internals.patchAndUpgradeTree(this);\n }\n return htmlString;\n },\n });\n }\n\n if (Native.Element_innerHTML && Native.Element_innerHTML.get) {\n patch_innerHTML(Element.prototype, Native.Element_innerHTML);\n } else if (Native.HTMLElement_innerHTML && Native.HTMLElement_innerHTML.get) {\n patch_innerHTML(HTMLElement.prototype, Native.HTMLElement_innerHTML);\n } else {\n\n /** @type {HTMLDivElement} */\n const rawDiv = Native.Document_createElement.call(document, 'div');\n\n internals.addPatch(function(element) {\n patch_innerHTML(element, {\n enumerable: true,\n configurable: true,\n // Implements getting `innerHTML` by performing an unpatched `cloneNode`\n // of the element and returning the resulting element's `innerHTML`.\n // TODO: Is this too expensive?\n get: /** @this {Element} */ function() {\n return Native.Node_cloneNode.call(this, true).innerHTML;\n },\n // Implements setting `innerHTML` by creating an unpatched element,\n // setting `innerHTML` of that element and replacing the target\n // element's children with those of the unpatched element.\n set: /** @this {Element} */ function(assignedValue) {\n // NOTE: re-route to `content` for `template` elements.\n // We need to do this because `template.appendChild` does not\n // route into `template.content`.\n /** @type {!Node} */\n const content = this.localName === 'template' ? (/** @type {!HTMLTemplateElement} */ (this)).content : this;\n rawDiv.innerHTML = assignedValue;\n\n while (content.childNodes.length > 0) {\n Native.Node_removeChild.call(content, content.childNodes[0]);\n }\n while (rawDiv.childNodes.length > 0) {\n Native.Node_appendChild.call(content, rawDiv.childNodes[0]);\n }\n },\n });\n });\n }\n\n\n Utilities.setPropertyUnchecked(Element.prototype, 'setAttribute',\n /**\n * @this {Element}\n * @param {string} name\n * @param {string} newValue\n */\n function(name, newValue) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_setAttribute.call(this, name, newValue);\n }\n\n const oldValue = Native.Element_getAttribute.call(this, name);\n Native.Element_setAttribute.call(this, name, newValue);\n newValue = Native.Element_getAttribute.call(this, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, null);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'setAttributeNS',\n /**\n * @this {Element}\n * @param {?string} namespace\n * @param {string} name\n * @param {string} newValue\n */\n function(namespace, name, newValue) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_setAttributeNS.call(this, namespace, name, newValue);\n }\n\n const oldValue = Native.Element_getAttributeNS.call(this, namespace, name);\n Native.Element_setAttributeNS.call(this, namespace, name, newValue);\n newValue = Native.Element_getAttributeNS.call(this, namespace, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, namespace);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'removeAttribute',\n /**\n * @this {Element}\n * @param {string} name\n */\n function(name) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_removeAttribute.call(this, name);\n }\n\n const oldValue = Native.Element_getAttribute.call(this, name);\n Native.Element_removeAttribute.call(this, name);\n if (oldValue !== null) {\n internals.attributeChangedCallback(this, name, oldValue, null, null);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'removeAttributeNS',\n /**\n * @this {Element}\n * @param {?string} namespace\n * @param {string} name\n */\n function(namespace, name) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_removeAttributeNS.call(this, namespace, name);\n }\n\n const oldValue = Native.Element_getAttributeNS.call(this, namespace, name);\n Native.Element_removeAttributeNS.call(this, namespace, name);\n // In older browsers, `Element#getAttributeNS` may return the empty string\n // instead of null if the attribute does not exist. For details, see;\n // https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttributeNS#Notes\n const newValue = Native.Element_getAttributeNS.call(this, namespace, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, namespace);\n }\n });\n\n\n function patch_insertAdjacentElement(destination, baseMethod) {\n Utilities.setPropertyUnchecked(destination, 'insertAdjacentElement',\n /**\n * @this {Element}\n * @param {string} where\n * @param {!Element} element\n * @return {?Element}\n */\n function(where, element) {\n const wasConnected = Utilities.isConnected(element);\n const insertedElement = /** @type {!Element} */\n (baseMethod.call(this, where, element));\n\n if (wasConnected) {\n internals.disconnectTree(element);\n }\n\n if (Utilities.isConnected(insertedElement)) {\n internals.connectTree(element);\n }\n return insertedElement;\n });\n }\n\n if (Native.HTMLElement_insertAdjacentElement) {\n patch_insertAdjacentElement(HTMLElement.prototype, Native.HTMLElement_insertAdjacentElement);\n } else if (Native.Element_insertAdjacentElement) {\n patch_insertAdjacentElement(Element.prototype, Native.Element_insertAdjacentElement);\n } else {\n console.warn('Custom Elements: `Element#insertAdjacentElement` was not patched.');\n }\n\n\n PatchParentNode(internals, Element.prototype, {\n prepend: Native.Element_prepend,\n append: Native.Element_append,\n });\n\n PatchChildNode(internals, Element.prototype, {\n before: Native.Element_before,\n after: Native.Element_after,\n replaceWith: Native.Element_replaceWith,\n remove: Native.Element_remove,\n });\n};\n"]} \ No newline at end of file diff --git a/src/CustomElementInternals.js b/src/CustomElementInternals.js index 3f08897..ab19db5 100644 --- a/src/CustomElementInternals.js +++ b/src/CustomElementInternals.js @@ -4,7 +4,7 @@ import CEState from './CustomElementState.js'; export default class CustomElementInternals { constructor() { /** @type {!Map} */ - this._localNameToDefinition = new Map(); + this._nameToDefinition = new Map(); /** @type {!Map} */ this._constructorToDefinition = new Map(); @@ -17,20 +17,20 @@ export default class CustomElementInternals { } /** - * @param {string} localName + * @param {string} name * @param {!CustomElementDefinition} definition */ - setDefinition(localName, definition) { - this._localNameToDefinition.set(localName, definition); + setDefinition(name, definition) { + this._nameToDefinition.set(name, definition); this._constructorToDefinition.set(definition.constructor, definition); } /** - * @param {string} localName + * @param {string} name * @return {!CustomElementDefinition|undefined} */ - localNameToDefinition(localName) { - return this._localNameToDefinition.get(localName); + nameToDefinition(name) { + return this._nameToDefinition.get(name); } /** @@ -41,6 +41,20 @@ export default class CustomElementInternals { return this._constructorToDefinition.get(constructor); } + /** + * @param {!Node} node + * @return {!CustomElementDefinition|null} + */ + nodeToDefinition(node) { + const name = typeof node.__CE_is === 'string' ? node.__CE_is : node.localName; + const definition = this.nameToDefinition(name); + if (definition && definition.localName === node.localName) { + return definition; + } else { + return null; + } + } + /** * @param {!function(!Node)} listener */ @@ -208,6 +222,11 @@ export default class CustomElementInternals { this.patchAndUpgradeTree(importNode, visitedImports); }); } + } else if (element.hasAttribute('is') || element.is) { + element.__CE_is = element.getAttribute('is') || element.is; + element.removeAttribute('is'); + delete element.is; + elements.push(element); } else { elements.push(element); } @@ -233,9 +252,8 @@ export default class CustomElementInternals { */ upgradeElement(element) { const currentState = element.__CE_state; - if (currentState !== undefined) return; - - const definition = this.localNameToDefinition(element.localName); + if (currentState !== undefined) return; + const definition = this.nodeToDefinition(element); if (!definition) return; definition.constructionStack.push(element); diff --git a/src/CustomElementRegistry.js b/src/CustomElementRegistry.js index c83e4d3..3933a48 100644 --- a/src/CustomElementRegistry.js +++ b/src/CustomElementRegistry.js @@ -47,7 +47,7 @@ export default class CustomElementRegistry { * @private * @type {!Array} */ - this._unflushedLocalNames = []; + this._unflushedNames = []; /** * @private @@ -57,20 +57,35 @@ export default class CustomElementRegistry { } /** - * @param {string} localName + * @param {string} name * @param {!Function} constructor */ - define(localName, constructor) { + define(name, constructor, options) { if (!(constructor instanceof Function)) { throw new TypeError('Custom element constructors must be functions.'); } - if (!Utilities.isValidCustomElementName(localName)) { - throw new SyntaxError(`The element name '${localName}' is not valid.`); + if (!Utilities.isValidCustomElementName(name)) { + throw new SyntaxError(`The element name '${name}' is not valid.`); } - if (this._internals.localNameToDefinition(localName)) { - throw new Error(`A custom element with name '${localName}' has already been defined.`); + if (this._internals.nameToDefinition(name)) { + throw new Error(`A custom element with name '${name}' has already been defined.`); + } + + let localName = name; + + if (options && options.extends) { + if (Utilities.isValidCustomElementName(options.extends)) { + throw new Error(`A customized builtin element may not extend a custom element.`); + } + + const el = document.createElement(options.extends); + if (el instanceof window['HTMLUnknownElement']) { + throw new Error(`Cannot extend '${options.extends}': is not a read HTML element`); + } + + localName = options.extends; } if (this._elementDefinitionIsRunning) { @@ -110,6 +125,7 @@ export default class CustomElementRegistry { } const definition = { + name, localName, constructor, connectedCallback, @@ -120,9 +136,9 @@ export default class CustomElementRegistry { constructionStack: [], }; - this._internals.setDefinition(localName, definition); + this._internals.setDefinition(name, definition); - this._unflushedLocalNames.push(localName); + this._unflushedNames.push(name); // If we've already called the flush callback and it hasn't called back yet, // don't call it again. @@ -141,9 +157,9 @@ export default class CustomElementRegistry { this._flushPending = false; this._internals.patchAndUpgradeTree(document); - while (this._unflushedLocalNames.length > 0) { - const localName = this._unflushedLocalNames.shift(); - const deferred = this._whenDefinedDeferred.get(localName); + while (this._unflushedNames.length > 0) { + const name = this._unflushedNames.shift(); + const deferred = this._whenDefinedDeferred.get(name); if (deferred) { deferred.resolve(undefined); } @@ -151,11 +167,11 @@ export default class CustomElementRegistry { } /** - * @param {string} localName + * @param {string} name * @return {Function|undefined} */ - get(localName) { - const definition = this._internals.localNameToDefinition(localName); + get(name) { + const definition = this._internals.nameToDefinition(name); if (definition) { return definition.constructor; } @@ -164,27 +180,27 @@ export default class CustomElementRegistry { } /** - * @param {string} localName + * @param {string} name * @return {!Promise} */ - whenDefined(localName) { - if (!Utilities.isValidCustomElementName(localName)) { - return Promise.reject(new SyntaxError(`'${localName}' is not a valid custom element name.`)); + whenDefined(name) { + if (!Utilities.isValidCustomElementName(name)) { + return Promise.reject(new SyntaxError(`'${name}' is not a valid custom element name.`)); } - const prior = this._whenDefinedDeferred.get(localName); + const prior = this._whenDefinedDeferred.get(name); if (prior) { return prior.toPromise(); } const deferred = new Deferred(); - this._whenDefinedDeferred.set(localName, deferred); + this._whenDefinedDeferred.set(name, deferred); - const definition = this._internals.localNameToDefinition(localName); + const definition = this._internals.nameToDefinition(name); // Resolve immediately only if the given local name has a definition *and* // the full document walk to upgrade elements with that local name has // already happened. - if (definition && this._unflushedLocalNames.indexOf(localName) === -1) { + if (definition && this._unflushedNames.indexOf(name) === -1) { deferred.resolve(undefined); } diff --git a/src/Patch/Document.js b/src/Patch/Document.js index f764362..a98177f 100644 --- a/src/Patch/Document.js +++ b/src/Patch/Document.js @@ -8,16 +8,17 @@ import PatchParentNode from './Interface/ParentNode.js'; * @param {!CustomElementInternals} internals */ export default function(internals) { - Utilities.setPropertyUnchecked(Document.prototype, 'createElement', + Utilities.setPropertyUnchecked(document, 'createElement', /** * @this {Document} * @param {string} localName * @return {!Element} */ - function(localName) { + function(localName, options) { // Only create custom elements if this document is associated with the registry. if (this.__CE_hasRegistry) { - const definition = internals.localNameToDefinition(localName); + const name = options && options.is ? options.is : localName; + const definition = internals.nameToDefinition(name); if (definition) { return new (definition.constructor)(); } @@ -25,6 +26,9 @@ export default function(internals) { const result = /** @type {!Element} */ (Native.Document_createElement.call(this, localName)); + if (options && options.is) { + result.__CE_is = options.is; + } internals.patch(result); return result; }); @@ -49,17 +53,18 @@ export default function(internals) { const NS_HTML = "http://www.w3.org/1999/xhtml"; - Utilities.setPropertyUnchecked(Document.prototype, 'createElementNS', + Utilities.setPropertyUnchecked(document, 'createElementNS', /** * @this {Document} * @param {?string} namespace * @param {string} localName * @return {!Element} */ - function(namespace, localName) { + function(namespace, localName, options) { // Only create custom elements if this document is associated with the registry. if (this.__CE_hasRegistry && (namespace === null || namespace === NS_HTML)) { - const definition = internals.localNameToDefinition(localName); + const name = options && options.is ? options.is : localName; + const definition = internals.nameToDefinition(name); if (definition) { return new (definition.constructor)(); } diff --git a/src/Patch/HTMLElementSubclasses.js b/src/Patch/HTMLElementSubclasses.js new file mode 100644 index 0000000..89b6a82 --- /dev/null +++ b/src/Patch/HTMLElementSubclasses.js @@ -0,0 +1,69 @@ +import Native from './Native.js'; +import CustomElementInternals from '../CustomElementInternals.js'; +import CEState from '../CustomElementState.js'; +import AlreadyConstructedMarker from '../AlreadyConstructedMarker.js'; + +/** + * @param {!CustomElementInternals} internals + */ +export default function(internals) { + for (let subclass in Native.HTMLElement_subclasses) { + patchElement(`HTML${subclass}Element`, Native.HTMLElement_subclasses[subclass]); + } + + function patchElement(elementName, NativeElement) { + if (!NativeElement) { + return; + } + + window[elementName] = (function() { + /** + * @type {function(new: HTMLElement): !HTMLElement} + */ + function PatchedElement() { + // This should really be `new.target` but `new.target` can't be emulated + // in ES5. Assuming the user keeps the default value of the constructor's + // prototype's `constructor` property, this is equivalent. + /** @type {!Function} */ + const constructor = this.constructor; + + const definition = internals.constructorToDefinition(constructor); + if (!definition) { + throw new Error('The custom element being constructed was not registered with `customElements`.'); + } + + const constructionStack = definition.constructionStack; + + if (constructionStack.length === 0) { + let element; + if (definition.name !== definition.localName) { + element = Native.Document_createElement.call(document, definition.localName, {is: definition.name}); + } else { + element = Native.Document_createElement.call(document, definition.localName); + } + Object.setPrototypeOf(element, constructor.prototype); + element.__CE_state = CEState.custom; + element.__CE_definition = definition; + internals.patch(element); + return element; + } + + const lastIndex = constructionStack.length - 1; + const element = constructionStack[lastIndex]; + if (element === AlreadyConstructedMarker) { + throw new Error(`The ${elementName} constructor was either called reentrantly for this constructor or called multiple times.`); + } + constructionStack[lastIndex] = AlreadyConstructedMarker; + + Object.setPrototypeOf(element, constructor.prototype); + internals.patch(/** @type {!HTMLElement} */ (element)); + + return /** @type {!HTMLElement} */ (element); + } + + PatchedElement.prototype = NativeElement.prototype; + + return PatchedElement; + })(); + } +}; diff --git a/src/Patch/Native.js b/src/Patch/Native.js index 8b761f3..e600efc 100644 --- a/src/Patch/Native.js +++ b/src/Patch/Native.js @@ -28,4 +28,71 @@ export default { HTMLElement: window.HTMLElement, HTMLElement_innerHTML: Object.getOwnPropertyDescriptor(window.HTMLElement.prototype, 'innerHTML'), HTMLElement_insertAdjacentElement: window.HTMLElement.prototype['insertAdjacentElement'], + HTMLElement_subclasses: { + 'Button': window['HTMLButtonElement'], + 'Canvas': window['HTMLCanvasElement'], + 'Data': window['HTMLDataElement'], + 'Head': window['HTMLHeadElement'], + 'Mod': window['HTMLModElement'], + 'TableCell': window['HTMLTableCellElement'], + 'TableCol': window['HTMLTableColElement'], + 'Anchor': window['HTMLAnchorElement'], + 'Area': window['HTMLAreaElement'], + 'Base': window['HTMLBaseElement'], + 'Body': window['HTMLBodyElement'], + 'BR': window['HTMLBRElement'], + 'DataList': window['HTMLDataListElement'], + 'Details': window['HTMLDetailsElement'], + 'Dialog': window['HTMLDialogElement'], + 'Div': window['HTMLDivElement'], + 'DList': window['HTMLDListElement'], + 'Embed': window['HTMLEmbedElement'], + 'FieldSet': window['HTMLFieldSetElement'], + 'Form': window['HTMLFormElement'], + 'Heading': window['HTMLHeadingElement'], + 'HR': window['HTMLHRElement'], + 'Html': window['HTMLHtmlElement'], + 'IFrame': window['HTMLIFrameElement'], + 'Image': window['HTMLImageElement'], + 'Input': window['HTMLInputElement'], + 'Keygen': window['HTMLKeygenElement'], + 'Label': window['HTMLLabelElement'], + 'Legend': window['HTMLLegendElement'], + 'LI': window['HTMLLIElement'], + 'Link': window['HTMLLinkElement'], + 'Map': window['HTMLMapElement'], + 'Media': window['HTMLMediaElement'], + 'Menu': window['HTMLMenuElement'], + 'MenuItem': window['HTMLMenuItemElement'], + 'Meta': window['HTMLMetaElement'], + 'Meter': window['HTMLMeterElement'], + 'Object': window['HTMLObjectElement'], + 'OList': window['HTMLOListElement'], + 'OptGroup': window['HTMLOptGroupElement'], + 'Option': window['HTMLOptionElement'], + 'Output': window['HTMLOutputElement'], + 'Paragraph': window['HTMLParagraphElement'], + 'Param': window['HTMLParamElement'], + 'Picture': window['HTMLPictureElement'], + 'Pre': window['HTMLPreElement'], + 'Progress': window['HTMLProgressElement'], + 'Quote': window['HTMLQuoteElement'], + 'Script': window['HTMLScriptElement'], + 'Select': window['HTMLSelectElement'], + 'Slot': window['HTMLSlotElement'], + 'Source': window['HTMLSourceElement'], + 'Span': window['HTMLSpanElement'], + 'Style': window['HTMLStyleElement'], + 'TableCaption': window['HTMLTableCaptionElement'], + 'Table': window['HTMLTableElement'], + 'TableRow': window['HTMLTableRowElement'], + 'TableSection': window['HTMLTableSectionElement'], + 'Template': window['HTMLTemplateElement'], + 'TextArea': window['HTMLTextAreaElement'], + 'Time': window['HTMLTimeElement'], + 'Title': window['HTMLTitleElement'], + 'Track': window['HTMLTrackElement'], + 'UList': window['HTMLUListElement'], + 'Unknown': window['HTMLUnknownElement'], + }, }; diff --git a/src/custom-elements.js b/src/custom-elements.js index 7d8a375..249b217 100644 --- a/src/custom-elements.js +++ b/src/custom-elements.js @@ -12,6 +12,7 @@ import CustomElementInternals from './CustomElementInternals.js'; import CustomElementRegistry from './CustomElementRegistry.js'; import PatchHTMLElement from './Patch/HTMLElement.js'; +import PatchHTMLElementSubclasses from './Patch/HTMLElementSubclasses.js'; import PatchDocument from './Patch/Document.js'; import PatchNode from './Patch/Node.js'; import PatchElement from './Patch/Element.js'; @@ -26,6 +27,7 @@ if (!priorCustomElements || const internals = new CustomElementInternals(); PatchHTMLElement(internals); + PatchHTMLElementSubclasses(internals); PatchDocument(internals); PatchNode(internals); PatchElement(internals); diff --git a/tests/js/babel.js b/tests/js/babel.js index 4523a82..8a41cc1 100644 --- a/tests/js/babel.js +++ b/tests/js/babel.js @@ -43,6 +43,38 @@ suite('Babel ES5 Output', function() { assert.instanceOf(e, XBabel); }); + test('Babel generated ES5 works via new() when extending builtin HTML Elements', function() { + "use strict"; + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + + function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + + function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + + var XBabelBuiltin = function (_HTMLButtonElement) { + _inherits(XBabelBuiltin, _HTMLButtonElement); + + function XBabelBuiltin() { + _classCallCheck(this, XBabelBuiltin); + + return _possibleConstructorReturn(this, (XBabelBuiltin.__proto__ || Object.getPrototypeOf(XBabelBuiltin)).call(this)); + } + + return XBabelBuiltin; + }(HTMLButtonElement); + + // register x-foo + customElements.define('x-babel-builtin', XBabelBuiltin, {extends: 'button'}); + // create an instance via new + var e = new XBabelBuiltin(); + // test localName + assert.equal(e.localName, 'button'); + // test instanceof + assert.instanceOf(e, XBabelBuiltin); + assert.instanceOf(e, HTMLButtonElement); + }); + test('Babel generated ES5 works via createElement', function() { 'use strict'; @@ -74,4 +106,32 @@ suite('Babel ES5 Output', function() { assert.instanceOf(e, XBabel2); }); + test('Babel generated ES5 works via createElement for customized builtins', function() { + "use strict"; + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + + function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + + function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + + var XBabel2Builtin = function (_HTMLButtonElement) { + _inherits(XBabel2Builtin, _HTMLButtonElement); + + function XBabel2Builtin() { + _classCallCheck(this, XBabel2Builtin); + + return _possibleConstructorReturn(this, (XBabel2Builtin.__proto__ || Object.getPrototypeOf(XBabel2Builtin)).call(this)); + } + + return XBabel2Builtin; + }(HTMLButtonElement); + + customElements.define('x-babel2-builtin', XBabel2Builtin, {extends: 'button'}); + var e = document.createElement('button', {is: 'x-babel2-builtin'}); + assert.equal(e.localName, 'button'); + assert.instanceOf(e, XBabel2Builtin); + assert.instanceOf(e, HTMLButtonElement); + }); + }); diff --git a/tests/js/instanceof.js b/tests/js/instanceof.js index 2fc596e..86aee1f 100644 --- a/tests/js/instanceof.js +++ b/tests/js/instanceof.js @@ -140,4 +140,18 @@ suite('Built-in Element instanceof', function() { }); + test('customized builtins are instance of the native elements they extend', function () { + class XInstanceofBuiltin extends HTMLStyleElement { + } + customElements.define('x-instanceof-builtin', XInstanceofBuiltin, {extends: 'style'}); + + var el = new XInstanceofBuiltin(); + assert.isTrue(el instanceof XInstanceofBuiltin); + assert.isTrue(el instanceof HTMLStyleElement); + + el = document.createElement('style', {is: 'x-instanceof-builtin'}); + assert.isTrue(el instanceof HTMLStyleElement); + assert.isTrue(el instanceof XInstanceofBuiltin); + }); + }); diff --git a/tests/js/reactions.js b/tests/js/reactions.js index 9959b8e..0d260f8 100644 --- a/tests/js/reactions.js +++ b/tests/js/reactions.js @@ -33,6 +33,16 @@ suite('Custom Element Reactions', function() { assert.instanceOf(xnew, XNew); }); + test('new E() instantiates a new customized builtin element', function() { + class XNewBuiltin extends HTMLButtonElement {} + customElements.define('x-new-builtin', XNewBuiltin, {extends: 'button'}); + var xnewbuiltin = new XNewBuiltin(); + + assert.equal(xnewbuiltin.localName, 'button'); + assert.instanceOf(xnewbuiltin, XNewBuiltin); + assert.instanceOf(xnewbuiltin, HTMLElement); + }); + test('new E() instantiates subclasses', function() { class XSuper extends HTMLElement {} class XSub extends XSuper {} @@ -81,6 +91,23 @@ suite('Custom Element Reactions', function() { assert.isTrue(pass); }); + test('constructor is called on customized builtins when instantiated via createElement', function() { + var pass = false; + class XFoo2Builtin extends HTMLButtonElement { + constructor() { + super(); + pass = true; + } + } + customElements.define('x-foo2-builtin', XFoo2Builtin, {extends: 'button'}); + + var el = document.createElement('button', {is: 'x-foo2-builtin'}); + assert.equal(el.localName, 'button'); + assert.instanceOf(el, XFoo2Builtin); + assert.instanceOf(el, HTMLButtonElement); + assert.isTrue(pass); + }); + test('subclass constructor is called when instantiated via createElement', function() { class XSuper2 extends HTMLElement {} var pass = false; @@ -133,6 +160,21 @@ suite('Custom Element Reactions', function() { assert.isTrue(pass); }); + test('constructor for customized builtin is called when instantiated via createElementNS', function() { + var pass = false; + class XFoo3Builtin extends HTMLButtonElement { + constructor() { + super(); + pass = true; + } + } + + customElements.define('x-foo3-builtin', XFoo3Builtin, {extends: 'button'}); + var xfooBuiltin = document.createElementNS(HTMLNS, 'button', {is: 'x-foo3-builtin'}); + assert.instanceOf(xfooBuiltin, XFoo3Builtin); + assert.isTrue(pass); + }); + test('constructor is called for each instance', function() { var count = 0; class XFoo4 extends HTMLElement { @@ -162,6 +204,23 @@ suite('Custom Element Reactions', function() { assert.equal(count, 1); }); + test('calls constructor only once for customized builtins', function() { + var count = 0; + class XConstructorBuiltin extends HTMLInputElement { + constructor() { + super(); + count++; + } + } + customElements.define('x-constructor-builtin', XConstructorBuiltin, {extends: 'input'}); + var xconstructorBuiltin = new XConstructorBuiltin(); + assert.equal(count, 1); + + count = 0; + var el = document.createElement('input', {is: 'x-constructor-builtin'}); + assert.equal(count, 1); + }); + test('innerHTML on disconnected elements customizes contents', function() { var passed = false; class XInner extends HTMLElement { @@ -171,11 +230,41 @@ suite('Custom Element Reactions', function() { } } customElements.define('x-inner', XInner); + passed = false; var div = document.createElement('div'); div.innerHTML = ''; assert.isTrue(passed); }); + test('innerHTML on disconnected elements customizes contents with customized builtin elements', function() { + var passed = false; + class XInnerBuiltin extends HTMLDivElement { + constructor() { + super(); + passed = true; + } + } + customElements.define('x-inner-builtin', XInnerBuiltin, {extends: 'div'}); + var div = document.createElement('div'); + passed = false; + div.innerHTML = '
'; + assert.isTrue(passed); + }); + + test('doesn\'t upgrade a native element if it\'s not created with the {is: "x-foo"} option', function() { + var upgraded; + class XNativeBuiltin extends HTMLSpanElement { + constructor() { + super(); + upgraded = true; + } + } + customElements.define('x-native-builtin', XNativeBuiltin, {extends: 'span'}); + upgraded = false; + document.createElement('span'); + assert.isFalse(upgraded); + }); + }); suite('attributeChangedCallback', function() { @@ -209,6 +298,24 @@ suite('Custom Element Reactions', function() { xboo.setAttribute('foo', 'zot'); }); + test('called when setting observed attribute on customized built-in element', function(done) { + class XBooBuiltin extends HTMLInputElement { + static get observedAttributes() { + return ['foo']; + } + + attributeChangedCallback(inName, inOldValue) { + if (inName === 'foo' && inOldValue === 'bar' && this.attributes.foo.value === 'zot') { + done(); + } + } + } + customElements.define('x-boo-builtin', XBooBuiltin, {extends: 'input'}); + var xbooBuiltin = new XBooBuiltin(); + xbooBuiltin.setAttribute('foo', 'bar'); + xbooBuiltin.setAttribute('foo', 'zot'); + }); + test('called for existing observed attributes', function () { var changed = []; class XBoo extends HTMLElement { @@ -243,7 +350,7 @@ suite('Custom Element Reactions', function() { }); suite('connectedCallback', function() { - var connectedCount; + var connectedCount, builtinConnectedCount; class XConnected extends HTMLElement { connectedCallback() { connectedCount++; @@ -251,13 +358,24 @@ suite('Custom Element Reactions', function() { } customElements.define('x-connected', XConnected); + class XConnectedBuiltin extends HTMLButtonElement { + connectedCallback() { + builtinConnectedCount++; + } + } + customElements.define('x-connected-builtin', XConnectedBuiltin, {extends: 'button'}); + setup(function() { connectedCount = 0; + builtinConnectedCount = 0; }); test('is not called for disconnected custom elements', function() { new XConnected(); assert.equal(connectedCount, 0); + + new XConnectedBuiltin(); + assert.equal(builtinConnectedCount, 0); }); test('is not called for deeply disconnected custom elements', function() { @@ -265,11 +383,19 @@ suite('Custom Element Reactions', function() { var child = new XConnected(); parent.appendChild(child); assert.equal(connectedCount, 0); + + parent = new XConnectedBuiltin(); + child = new XConnectedBuiltin(); + parent.appendChild(child); + assert.equal(builtinConnectedCount, 0); }); test('called when appended to main document', function() { work.appendChild(new XConnected()); assert.equal(connectedCount, 1); + + work.appendChild(new XConnectedBuiltin()); + assert.equal(builtinConnectedCount, 1); }); test('called when re-appended to main document', function() { @@ -278,6 +404,12 @@ suite('Custom Element Reactions', function() { work.removeChild(el); work.appendChild(el); assert.equal(connectedCount, 2); + + el = new XConnectedBuiltin(); + work.appendChild(el); + work.removeChild(el); + work.appendChild(el); + assert.equal(builtinConnectedCount, 2); }); test('called in tree order', function() { @@ -289,7 +421,14 @@ suite('Custom Element Reactions', function() { } } + class XOrderingBuiltin extends HTMLDivElement { + connectedCallback() { + log.push(this.id); + } + } + customElements.define('x-ordering', XOrdering); + customElements.define('x-ordering-builtin', XOrderingBuiltin, {extends: 'div'}); work.innerHTML = '' + @@ -297,10 +436,11 @@ suite('Custom Element Reactions', function() { '' + '' + '' + + '
' + '
' + '
'; - assert.deepEqual(log, ['a', 'b', 'c', 'd', 'e']); + assert.deepEqual(log, ['a', 'b', 'c', 'd', 'e', 'f']); }); }); @@ -335,6 +475,22 @@ suite('Custom Element Reactions', function() { assert(removed, 'removed must be true [XBooBoo]'); }); + test('called on customized builtins when disconnected from main document', function() { + var removed = false; + class XZotBuiltin extends HTMLBRElement { + disconnectedCallback() { + removed = true; + } + } + customElements.define('x-zot-builtin', XZotBuiltin, {extends: 'br'}); + var xZotBuiltin = new XZotBuiltin(); + assert(!removed, 'XZotBuiltin shouldn\'t be removed before even connected'); + work.appendChild(xZotBuiltin); + assert(!removed, 'XZotBuiltin shouldn\'t be removed when it is connected'); + work.removeChild(xZotBuiltin); + assert(removed, 'XZotBuiltin should be removed when disconnected from dom'); + }); + test('called in tree order', function() { var log = []; class XOrdering2 extends HTMLElement { @@ -344,17 +500,25 @@ suite('Custom Element Reactions', function() { } customElements.define('x-ordering2', XOrdering2); + class XOrdering2Builtin extends HTMLTitleElement { + disconnectedCallback() { + log.push(this.id) + } + } + customElements.define('x-ordering2-builtin', XOrdering2Builtin, {extends: 'div'}); + work.innerHTML = '' + '' + '' + '' + '' + + '
' + '
' + '
'; work.removeChild(work.firstElementChild); - assert.deepEqual(['a', 'b', 'c', 'd', 'e'], log); + assert.deepEqual(['a', 'b', 'c', 'd', 'e', 'f'], log); }); }); diff --git a/tests/js/registry.js b/tests/js/registry.js index b2d52ae..80a3a33 100644 --- a/tests/js/registry.js +++ b/tests/js/registry.js @@ -77,6 +77,12 @@ suite('CustomElementsRegistry', function() { }, '', 'customElements.define failed to throw with a constructor argument with no prototype'); }); + test('second argument with an invalid extends property', function() { + class XInvalidExtends extends HTMLInputElement {} + assert.throws(function() { + customElements.define('x-invalid-extends', XInvalidExtends, {extends: new Date()}); + }, '', 'customElements.define failed to throw with an invalid extends option'); + }); }); suite('get', function() { @@ -91,6 +97,15 @@ suite('CustomElementsRegistry', function() { assert.isUndefined(customElements.get('x-undefined')); }); + test('returns a defined constructor for a customized builtin element', function () { + class XGetBuiltin extends HTMLLinkElement {} + customElements.define('x-get-builtin', XGetBuiltin, {extends: 'link'}); + // Customized builtin elements should be retrievable from the registry + assert.equal(XGetBuiltin, customElements.get('x-get-builtin')); + // The element being extended cannot be retrieved from the registry + assert.isUndefined(customElements.get('link')); + }); + }); suite('whenDefined', function() { diff --git a/tests/js/upgrade.js b/tests/js/upgrade.js index 653f902..4fd653e 100644 --- a/tests/js/upgrade.js +++ b/tests/js/upgrade.js @@ -22,37 +22,47 @@ suite('Upgrades', function() { }); test('connected elements upgrade when defined', function() { - work.innerHTML = ''; + work.innerHTML = ''; var e1 = work.firstChild; var e2 = e1.firstChild; + var e3 = e2.firstChild; class X1 extends HTMLElement {} class X2 extends HTMLElement {} + class XMarkupBuiltin1 extends HTMLButtonElement {} customElements.define('x-markup-1', X1); customElements.define('x-markup-2', X2); + customElements.define('x-markup-builtin-1', XMarkupBuiltin1, {extends: 'button'}); assert.instanceOf(e1, X1); assert.instanceOf(e2, X2); + assert.instanceOf(e3, XMarkupBuiltin1); }); test('defined disconnected elements upgrade when connected', function() { var e1 = document.createElement('x-disconnected-1'); var e2 = document.createElement('x-disconnected-2'); + var e3 = document.createElement('span', {is: 'x-disconnected-builtin-1'}); e1.appendChild(e2); + e2.appendChild(e3); class X1 extends HTMLElement {} class X2 extends HTMLElement {} + class XDisconnectedBuiltin1 extends HTMLSpanElement {} customElements.define('x-disconnected-1', X1); customElements.define('x-disconnected-2', X2); + customElements.define('x-disconnected-builtin-1', XDisconnectedBuiltin1, {extends: 'span'}); // disconnected elements should not be upgraded assert.notInstanceOf(e1, X1); assert.notInstanceOf(e2, X2); + assert.notInstanceOf(e3, XDisconnectedBuiltin1); // they should upgrade when connected work.appendChild(e1); assert.instanceOf(e1, X1); assert.instanceOf(e2, X2); + assert.instanceOf(e3, XDisconnectedBuiltin1); }); }); From b7b6f3994dfe14c431ad272ea8ef8c263aa815f8 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Fri, 31 Mar 2017 18:02:48 -0600 Subject: [PATCH 02/10] Readme --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index e66cff1..c6771e7 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,20 @@ and [HTML](https://html.spec.whatwg.org/) specifications are marked with the that `F.prototype.constructor === F` remains true. Otherwise, the polyfill will not be able to create or upgrade your custom elements. +## Customized built-in elements. +[Customized built-in elements](https://html.spec.whatwg.org/multipage/scripting.html#customized-built-in-element) +are implemented behind a flag and can be enabled by setting +`customElements.enableCustomizedBuiltins = true` before defining any customized +builtin elements. + +The status of customized built-in elements is somewhat controversial, which is why +the implementation is turned off by default. Although the v1 spec for custom +elements is finalized, there is not a consensus from browsers about whether +customized builtins will be implemented. For example, Webkit (Safari) has +stated that they will not implement customized builtins. + +You can read more in [this github issue](https://github.com/w3c/webcomponents/issues/509). + ### ES5 vs ES2015 The custom elements v1 spec is not compatible with ES5 style classes. This means From 64e072c2ef524c19dc541819cfb6538330cfcb6c Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Fri, 31 Mar 2017 18:08:05 -0600 Subject: [PATCH 03/10] Undoing changes to custom-elements.min.js --- custom-elements.min.js | 53 +++++++++++++++++--------------------- custom-elements.min.js.map | 2 +- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/custom-elements.min.js b/custom-elements.min.js index 3bfabd8..e93a91a 100644 --- a/custom-elements.min.js +++ b/custom-elements.min.js @@ -1,36 +1,29 @@ (function(){ 'use strict';var g=new function(){};var aa=new Set("annotation-xml color-profile font-face font-face-src font-face-uri font-face-format font-face-name missing-glyph".split(" "));function k(b){var a=aa.has(b);b=/^[a-z][.0-9_a-z]*-[\-.0-9_a-z]*$/.test(b);return!a&&b}function l(b){var a=b.isConnected;if(void 0!==a)return a;for(;b&&!(b.__CE_isImportDocument||b instanceof Document);)b=b.parentNode||(window.ShadowRoot&&b instanceof ShadowRoot?b.host:void 0);return!(!b||!(b.__CE_isImportDocument||b instanceof Document))} function m(b,a){for(;a&&a!==b&&!a.nextSibling;)a=a.parentNode;return a&&a!==b?a.nextSibling:null} -function n(b,a,e){e=e?e:new Set;for(var c=b;c;){if(c.nodeType===Node.ELEMENT_NODE){var d=c;a(d);var h=d.localName;if("link"===h&&"import"===d.getAttribute("rel")){c=d.import;if(c instanceof Node&&!e.has(c))for(e.add(c),c=c.firstChild;c;c=c.nextSibling)n(c,a,e);c=m(b,d);continue}else if("template"===h){c=m(b,d);continue}if(d=d.__CE_shadowRoot)for(d=d.firstChild;d;d=d.nextSibling)n(d,a,e)}c=c.firstChild?c.firstChild:m(b,c)}}function p(b,a,e){b[a]=e};function q(){this.a=new Map;this.c=new Map;this.f=[];this.b=!1}function ba(b,a,e){b.a.set(a,e);b.c.set(e.constructor,e)}function r(b,a){b.b=!0;b.f.push(a)}function v(b,a){b.b&&n(a,function(a){return w(b,a)})}function w(b,a){if(b.b&&!a.__CE_patched){a.__CE_patched=!0;for(var e=0;e=} visitedImports\n */\nexport function walkDeepDescendantElements(root, callback, visitedImports = new Set()) {\n let node = root;\n while (node) {\n if (node.nodeType === Node.ELEMENT_NODE) {\n const element = /** @type {!Element} */(node);\n\n callback(element);\n\n const localName = element.localName;\n if (localName === 'link' && element.getAttribute('rel') === 'import') {\n // If this import (polyfilled or not) has it's root node available,\n // walk it.\n const importNode = /** @type {!Node} */ (element.import);\n if (importNode instanceof Node && !visitedImports.has(importNode)) {\n // Prevent multiple walks of the same import root.\n visitedImports.add(importNode);\n\n for (let child = importNode.firstChild; child; child = child.nextSibling) {\n walkDeepDescendantElements(child, callback, visitedImports);\n }\n }\n\n // Ignore descendants of import links to prevent attempting to walk the\n // elements created by the HTML Imports polyfill that we just walked\n // above.\n node = nextSiblingOrAncestorSibling(root, element);\n continue;\n } else if (localName === 'template') {\n // Ignore descendants of templates. There shouldn't be any descendants\n // because they will be moved into `.content` during construction in\n // browsers that support template but, in case they exist and are still\n // waiting to be moved by a polyfill, they will be ignored.\n node = nextSiblingOrAncestorSibling(root, element);\n continue;\n }\n\n // Walk shadow roots.\n const shadowRoot = element.__CE_shadowRoot;\n if (shadowRoot) {\n for (let child = shadowRoot.firstChild; child; child = child.nextSibling) {\n walkDeepDescendantElements(child, callback, visitedImports);\n }\n }\n }\n\n node = nextNode(root, node);\n }\n}\n\n/**\n * Used to suppress Closure's \"Modifying the prototype is only allowed if the\n * constructor is in the same scope\" warning without using\n * `@suppress {newCheckTypes, duplicate}` because `newCheckTypes` is too broad.\n *\n * @param {!Object} destination\n * @param {string} name\n * @param {*} value\n */\nexport function setPropertyUnchecked(destination, name, value) {\n destination[name] = value;\n}\n","import * as Utilities from './Utilities.js';\nimport CEState from './CustomElementState.js';\n\nexport default class CustomElementInternals {\n constructor() {\n /** @type {!Map} */\n this._nameToDefinition = new Map();\n\n /** @type {!Map} */\n this._constructorToDefinition = new Map();\n\n /** @type {!Array} */\n this._patches = [];\n\n /** @type {boolean} */\n this._hasPatches = false;\n }\n\n /**\n * @param {string} name\n * @param {!CustomElementDefinition} definition\n */\n setDefinition(name, definition) {\n this._nameToDefinition.set(name, definition);\n this._constructorToDefinition.set(definition.constructor, definition);\n }\n\n /**\n * @param {string} name\n * @return {!CustomElementDefinition|undefined}\n */\n nameToDefinition(name) {\n return this._nameToDefinition.get(name);\n }\n\n /**\n * @param {!Function} constructor\n * @return {!CustomElementDefinition|undefined}\n */\n constructorToDefinition(constructor) {\n return this._constructorToDefinition.get(constructor);\n }\n\n /**\n * @param {!Node} node\n * @return {!CustomElementDefinition|null}\n */\n nodeToDefinition(node) {\n const name = typeof node.__CE_is === 'string' ? node.__CE_is : node.localName;\n const definition = this.nameToDefinition(name);\n if (definition && definition.localName === node.localName) {\n return definition;\n } else {\n return null;\n }\n }\n\n /**\n * @param {!function(!Node)} listener\n */\n addPatch(listener) {\n this._hasPatches = true;\n this._patches.push(listener);\n }\n\n /**\n * @param {!Node} node\n */\n patchTree(node) {\n if (!this._hasPatches) return;\n\n Utilities.walkDeepDescendantElements(node, element => this.patch(element));\n }\n\n /**\n * @param {!Node} node\n */\n patch(node) {\n if (!this._hasPatches) return;\n\n if (node.__CE_patched) return;\n node.__CE_patched = true;\n\n for (let i = 0; i < this._patches.length; i++) {\n this._patches[i](node);\n }\n }\n\n /**\n * @param {!Node} root\n */\n connectTree(root) {\n const elements = [];\n\n Utilities.walkDeepDescendantElements(root, element => elements.push(element));\n\n for (let i = 0; i < elements.length; i++) {\n const element = elements[i];\n if (element.__CE_state === CEState.custom) {\n this.connectedCallback(element);\n } else {\n this.upgradeElement(element);\n }\n }\n }\n\n /**\n * @param {!Node} root\n */\n disconnectTree(root) {\n const elements = [];\n\n Utilities.walkDeepDescendantElements(root, element => elements.push(element));\n\n for (let i = 0; i < elements.length; i++) {\n const element = elements[i];\n if (element.__CE_state === CEState.custom) {\n this.disconnectedCallback(element);\n }\n }\n }\n\n /**\n * Upgrades all uncustomized custom elements at and below a root node for\n * which there is a definition. When custom element reaction callbacks are\n * assumed to be called synchronously (which, by the current DOM / HTML spec\n * definitions, they are *not*), callbacks for both elements customized\n * synchronously by the parser and elements being upgraded occur in the same\n * relative order.\n *\n * NOTE: This function, when used to simulate the construction of a tree that\n * is already created but not customized (i.e. by the parser), does *not*\n * prevent the element from reading the 'final' (true) state of the tree. For\n * example, the element, during truly synchronous parsing / construction would\n * see that it contains no children as they have not yet been inserted.\n * However, this function does not modify the tree, the element will\n * (incorrectly) have children. Additionally, self-modification restrictions\n * for custom element constructors imposed by the DOM spec are *not* enforced.\n *\n *\n * The following nested list shows the steps extending down from the HTML\n * spec's parsing section that cause elements to be synchronously created and\n * upgraded:\n *\n * The \"in body\" insertion mode:\n * https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody\n * - Switch on token:\n * .. other cases ..\n * -> Any other start tag\n * - [Insert an HTML element](below) for the token.\n *\n * Insert an HTML element:\n * https://html.spec.whatwg.org/multipage/syntax.html#insert-an-html-element\n * - Insert a foreign element for the token in the HTML namespace:\n * https://html.spec.whatwg.org/multipage/syntax.html#insert-a-foreign-element\n * - Create an element for a token:\n * https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-the-token\n * - Will execute script flag is true?\n * - (Element queue pushed to the custom element reactions stack.)\n * - Create an element:\n * https://dom.spec.whatwg.org/#concept-create-element\n * - Sync CE flag is true?\n * - Constructor called.\n * - Self-modification restrictions enforced.\n * - Sync CE flag is false?\n * - (Upgrade reaction enqueued.)\n * - Attributes appended to element.\n * (`attributeChangedCallback` reactions enqueued.)\n * - Will execute script flag is true?\n * - (Element queue popped from the custom element reactions stack.\n * Reactions in the popped stack are invoked.)\n * - (Element queue pushed to the custom element reactions stack.)\n * - Insert the element:\n * https://dom.spec.whatwg.org/#concept-node-insert\n * - Shadow-including descendants are connected. During parsing\n * construction, there are no shadow-*excluding* descendants.\n * However, the constructor may have validly attached a shadow\n * tree to itself and added descendants to that shadow tree.\n * (`connectedCallback` reactions enqueued.)\n * - (Element queue popped from the custom element reactions stack.\n * Reactions in the popped stack are invoked.)\n *\n * @param {!Node} root\n * @param {!Set=} visitedImports\n */\n patchAndUpgradeTree(root, visitedImports = new Set()) {\n const elements = [];\n\n const gatherElements = element => {\n if (element.localName === 'link' && element.getAttribute('rel') === 'import') {\n // The HTML Imports polyfill sets a descendant element of the link to\n // the `import` property, specifically this is *not* a Document.\n const importNode = /** @type {?Node} */ (element.import);\n\n if (importNode instanceof Node && importNode.readyState === 'complete') {\n importNode.__CE_isImportDocument = true;\n\n // Connected links are associated with the registry.\n importNode.__CE_hasRegistry = true;\n } else {\n // If this link's import root is not available, its contents can't be\n // walked. Wait for 'load' and walk it when it's ready.\n element.addEventListener('load', () => {\n const importNode = /** @type {!Node} */ (element.import);\n\n if (importNode.__CE_documentLoadHandled) return;\n importNode.__CE_documentLoadHandled = true;\n\n importNode.__CE_isImportDocument = true;\n\n // Connected links are associated with the registry.\n importNode.__CE_hasRegistry = true;\n\n // Clone the `visitedImports` set that was populated sync during\n // the `patchAndUpgradeTree` call that caused this 'load' handler to\n // be added. Then, remove *this* link's import node so that we can\n // walk that import again, even if it was partially walked later\n // during the same `patchAndUpgradeTree` call.\n const clonedVisitedImports = new Set(visitedImports);\n visitedImports.delete(importNode);\n\n this.patchAndUpgradeTree(importNode, visitedImports);\n });\n }\n } else if (element.hasAttribute('is') || element.is) {\n element.__CE_is = element.getAttribute('is') || element.is;\n element.removeAttribute('is');\n delete element.is;\n\t\t\t\telements.push(element);\n } else {\n elements.push(element);\n }\n };\n\n // `walkDeepDescendantElements` populates (and internally checks against)\n // `visitedImports` when traversing a loaded import.\n Utilities.walkDeepDescendantElements(root, gatherElements, visitedImports);\n\n if (this._hasPatches) {\n for (let i = 0; i < elements.length; i++) {\n this.patch(elements[i]);\n }\n }\n\n for (let i = 0; i < elements.length; i++) {\n this.upgradeElement(elements[i]);\n }\n }\n\n /**\n * @param {!Element} element\n */\n upgradeElement(element) {\n const currentState = element.__CE_state;\n\t\tif (currentState !== undefined) return;\n const definition = this.nodeToDefinition(element);\n if (!definition) return;\n\n definition.constructionStack.push(element);\n\n const constructor = definition.constructor;\n try {\n try {\n let result = new (constructor)();\n if (result !== element) {\n throw new Error('The custom element constructor did not produce the element being upgraded.');\n }\n } finally {\n definition.constructionStack.pop();\n }\n } catch (e) {\n element.__CE_state = CEState.failed;\n throw e;\n }\n\n element.__CE_state = CEState.custom;\n element.__CE_definition = definition;\n\n if (definition.attributeChangedCallback) {\n const observedAttributes = definition.observedAttributes;\n for (let i = 0; i < observedAttributes.length; i++) {\n const name = observedAttributes[i];\n const value = element.getAttribute(name);\n if (value !== null) {\n this.attributeChangedCallback(element, name, null, value, null);\n }\n }\n }\n\n if (Utilities.isConnected(element)) {\n this.connectedCallback(element);\n }\n }\n\n /**\n * @param {!Element} element\n */\n connectedCallback(element) {\n const definition = element.__CE_definition;\n if (definition.connectedCallback) {\n definition.connectedCallback.call(element);\n }\n }\n\n /**\n * @param {!Element} element\n */\n disconnectedCallback(element) {\n const definition = element.__CE_definition;\n if (definition.disconnectedCallback) {\n definition.disconnectedCallback.call(element);\n }\n }\n\n /**\n * @param {!Element} element\n * @param {string} name\n * @param {?string} oldValue\n * @param {?string} newValue\n * @param {?string} namespace\n */\n attributeChangedCallback(element, name, oldValue, newValue, namespace) {\n const definition = element.__CE_definition;\n if (\n definition.attributeChangedCallback &&\n definition.observedAttributes.indexOf(name) > -1\n ) {\n definition.attributeChangedCallback.call(element, name, oldValue, newValue, namespace);\n }\n }\n}\n","/**\n * @enum {number}\n */\nconst CustomElementState = {\n custom: 1,\n failed: 2,\n};\n\nexport default CustomElementState;\n","import CustomElementInternals from './CustomElementInternals.js';\n\nexport default class DocumentConstructionObserver {\n constructor(internals, doc) {\n /**\n * @type {!CustomElementInternals}\n */\n this._internals = internals;\n\n /**\n * @type {!Document}\n */\n this._document = doc;\n\n /**\n * @type {MutationObserver|undefined}\n */\n this._observer = undefined;\n\n\n // Simulate tree construction for all currently accessible nodes in the\n // document.\n this._internals.patchAndUpgradeTree(this._document);\n\n if (this._document.readyState === 'loading') {\n this._observer = new MutationObserver(this._handleMutations.bind(this));\n\n // Nodes created by the parser are given to the observer *before* the next\n // task runs. Inline scripts are run in a new task. This means that the\n // observer will be able to handle the newly parsed nodes before the inline\n // script is run.\n this._observer.observe(this._document, {\n childList: true,\n subtree: true,\n });\n }\n }\n\n disconnect() {\n if (this._observer) {\n this._observer.disconnect();\n }\n }\n\n /**\n * @param {!Array} mutations\n */\n _handleMutations(mutations) {\n // Once the document's `readyState` is 'interactive' or 'complete', all new\n // nodes created within that document will be the result of script and\n // should be handled by patching.\n const readyState = this._document.readyState;\n if (readyState === 'interactive' || readyState === 'complete') {\n this.disconnect();\n }\n\n for (let i = 0; i < mutations.length; i++) {\n const addedNodes = mutations[i].addedNodes;\n for (let j = 0; j < addedNodes.length; j++) {\n const node = addedNodes[j];\n this._internals.patchAndUpgradeTree(node);\n }\n }\n }\n}\n","/**\n * @template T\n */\nexport default class Deferred {\n constructor() {\n /**\n * @private\n * @type {T|undefined}\n */\n this._value = undefined;\n\n /**\n * @private\n * @type {Function|undefined}\n */\n this._resolve = undefined;\n\n /**\n * @private\n * @type {!Promise}\n */\n this._promise = new Promise(resolve => {\n this._resolve = resolve;\n\n if (this._value) {\n resolve(this._value);\n }\n });\n }\n\n /**\n * @param {T} value\n */\n resolve(value) {\n if (this._value) {\n throw new Error('Already resolved.');\n }\n\n this._value = value;\n\n if (this._resolve) {\n this._resolve(value);\n }\n }\n\n /**\n * @return {!Promise}\n */\n toPromise() {\n return this._promise;\n }\n}\n","import CustomElementInternals from './CustomElementInternals.js';\nimport DocumentConstructionObserver from './DocumentConstructionObserver.js';\nimport Deferred from './Deferred.js';\nimport * as Utilities from './Utilities.js';\n\n/**\n * @unrestricted\n */\nexport default class CustomElementRegistry {\n\n /**\n * @param {!CustomElementInternals} internals\n */\n constructor(internals) {\n /**\n * @private\n * @type {boolean}\n */\n this._elementDefinitionIsRunning = false;\n\n /**\n * @private\n * @type {!CustomElementInternals}\n */\n this._internals = internals;\n\n /**\n * @private\n * @type {!Map>}\n */\n this._whenDefinedDeferred = new Map();\n\n /**\n * The default flush callback triggers the document walk synchronously.\n * @private\n * @type {!Function}\n */\n this._flushCallback = fn => fn();\n\n /**\n * @private\n * @type {boolean}\n */\n this._flushPending = false;\n\n /**\n * @private\n * @type {!Array}\n */\n this._unflushedNames = [];\n\n /**\n * @private\n * @type {!DocumentConstructionObserver}\n */\n this._documentConstructionObserver = new DocumentConstructionObserver(internals, document);\n }\n\n /**\n * @param {string} name\n * @param {!Function} constructor\n */\n define(name, constructor, options) {\n if (!(constructor instanceof Function)) {\n throw new TypeError('Custom element constructors must be functions.');\n }\n\n if (!Utilities.isValidCustomElementName(name)) {\n throw new SyntaxError(`The element name '${name}' is not valid.`);\n }\n\n if (this._internals.nameToDefinition(name)) {\n throw new Error(`A custom element with name '${name}' has already been defined.`);\n }\n\n let localName = name;\n\n if (options && options.extends) {\n if (Utilities.isValidCustomElementName(options.extends)) {\n throw new Error(`A customized builtin element may not extend a custom element.`);\n }\n\n const el = document.createElement(options.extends);\n if (el instanceof window['HTMLUnknownElement']) {\n throw new Error(`Cannot extend '${options.extends}': is not a read HTML element`);\n }\n\n localName = options.extends;\n }\n\n if (this._elementDefinitionIsRunning) {\n throw new Error('A custom element is already being defined.');\n }\n this._elementDefinitionIsRunning = true;\n\n let connectedCallback;\n let disconnectedCallback;\n let adoptedCallback;\n let attributeChangedCallback;\n let observedAttributes;\n try {\n /** @type {!Object} */\n const prototype = constructor.prototype;\n if (!(prototype instanceof Object)) {\n throw new TypeError('The custom element constructor\\'s prototype is not an object.');\n }\n\n function getCallback(name) {\n const callbackValue = prototype[name];\n if (callbackValue !== undefined && !(callbackValue instanceof Function)) {\n throw new Error(`The '${name}' callback must be a function.`);\n }\n return callbackValue;\n }\n\n connectedCallback = getCallback('connectedCallback');\n disconnectedCallback = getCallback('disconnectedCallback');\n adoptedCallback = getCallback('adoptedCallback');\n attributeChangedCallback = getCallback('attributeChangedCallback');\n observedAttributes = constructor['observedAttributes'] || [];\n } catch (e) {\n return;\n } finally {\n this._elementDefinitionIsRunning = false;\n }\n\n const definition = {\n name,\n localName,\n constructor,\n connectedCallback,\n disconnectedCallback,\n adoptedCallback,\n attributeChangedCallback,\n observedAttributes,\n constructionStack: [],\n };\n\n this._internals.setDefinition(name, definition);\n\n this._unflushedNames.push(name);\n\n // If we've already called the flush callback and it hasn't called back yet,\n // don't call it again.\n if (!this._flushPending) {\n this._flushPending = true;\n this._flushCallback(() => this._flush());\n }\n }\n\n _flush() {\n // If no new definitions were defined, don't attempt to flush. This could\n // happen if a flush callback keeps the function it is given and calls it\n // multiple times.\n if (this._flushPending === false) return;\n\n this._flushPending = false;\n this._internals.patchAndUpgradeTree(document);\n\n while (this._unflushedNames.length > 0) {\n const name = this._unflushedNames.shift();\n const deferred = this._whenDefinedDeferred.get(name);\n if (deferred) {\n deferred.resolve(undefined);\n }\n }\n }\n\n /**\n * @param {string} name\n * @return {Function|undefined}\n */\n get(name) {\n const definition = this._internals.nameToDefinition(name);\n if (definition) {\n return definition.constructor;\n }\n\n return undefined;\n }\n\n /**\n * @param {string} name\n * @return {!Promise}\n */\n whenDefined(name) {\n if (!Utilities.isValidCustomElementName(name)) {\n return Promise.reject(new SyntaxError(`'${name}' is not a valid custom element name.`));\n }\n\n const prior = this._whenDefinedDeferred.get(name);\n if (prior) {\n return prior.toPromise();\n }\n\n const deferred = new Deferred();\n this._whenDefinedDeferred.set(name, deferred);\n\n const definition = this._internals.nameToDefinition(name);\n // Resolve immediately only if the given local name has a definition *and*\n // the full document walk to upgrade elements with that local name has\n // already happened.\n if (definition && this._unflushedNames.indexOf(name) === -1) {\n deferred.resolve(undefined);\n }\n\n return deferred.toPromise();\n }\n\n polyfillWrapFlushCallback(outer) {\n this._documentConstructionObserver.disconnect();\n const inner = this._flushCallback;\n this._flushCallback = flush => outer(() => inner(flush));\n }\n}\n\n// Closure compiler exports.\nwindow['CustomElementRegistry'] = CustomElementRegistry;\nCustomElementRegistry.prototype['define'] = CustomElementRegistry.prototype.define;\nCustomElementRegistry.prototype['get'] = CustomElementRegistry.prototype.get;\nCustomElementRegistry.prototype['whenDefined'] = CustomElementRegistry.prototype.whenDefined;\nCustomElementRegistry.prototype['polyfillWrapFlushCallback'] = CustomElementRegistry.prototype.polyfillWrapFlushCallback;\n","export default {\n Document_createElement: window.Document.prototype.createElement,\n Document_createElementNS: window.Document.prototype.createElementNS,\n Document_importNode: window.Document.prototype.importNode,\n Document_prepend: window.Document.prototype['prepend'],\n Document_append: window.Document.prototype['append'],\n Node_cloneNode: window.Node.prototype.cloneNode,\n Node_appendChild: window.Node.prototype.appendChild,\n Node_insertBefore: window.Node.prototype.insertBefore,\n Node_removeChild: window.Node.prototype.removeChild,\n Node_replaceChild: window.Node.prototype.replaceChild,\n Node_textContent: Object.getOwnPropertyDescriptor(window.Node.prototype, 'textContent'),\n Element_attachShadow: window.Element.prototype['attachShadow'],\n Element_innerHTML: Object.getOwnPropertyDescriptor(window.Element.prototype, 'innerHTML'),\n Element_getAttribute: window.Element.prototype.getAttribute,\n Element_setAttribute: window.Element.prototype.setAttribute,\n Element_removeAttribute: window.Element.prototype.removeAttribute,\n Element_getAttributeNS: window.Element.prototype.getAttributeNS,\n Element_setAttributeNS: window.Element.prototype.setAttributeNS,\n Element_removeAttributeNS: window.Element.prototype.removeAttributeNS,\n Element_insertAdjacentElement: window.Element.prototype['insertAdjacentElement'],\n Element_prepend: window.Element.prototype['prepend'],\n Element_append: window.Element.prototype['append'],\n Element_before: window.Element.prototype['before'],\n Element_after: window.Element.prototype['after'],\n Element_replaceWith: window.Element.prototype['replaceWith'],\n Element_remove: window.Element.prototype['remove'],\n HTMLElement: window.HTMLElement,\n HTMLElement_innerHTML: Object.getOwnPropertyDescriptor(window.HTMLElement.prototype, 'innerHTML'),\n HTMLElement_insertAdjacentElement: window.HTMLElement.prototype['insertAdjacentElement'],\n HTMLElement_subclasses: {\n 'Button': window['HTMLButtonElement'],\n 'Canvas': window['HTMLCanvasElement'],\n 'Data': window['HTMLDataElement'],\n 'Head': window['HTMLHeadElement'],\n 'Mod': window['HTMLModElement'],\n 'TableCell': window['HTMLTableCellElement'],\n 'TableCol': window['HTMLTableColElement'],\n 'Anchor': window['HTMLAnchorElement'],\n 'Area': window['HTMLAreaElement'],\n 'Base': window['HTMLBaseElement'],\n 'Body': window['HTMLBodyElement'],\n 'BR': window['HTMLBRElement'],\n 'DataList': window['HTMLDataListElement'],\n 'Details': window['HTMLDetailsElement'],\n 'Dialog': window['HTMLDialogElement'],\n 'Div': window['HTMLDivElement'],\n 'DList': window['HTMLDListElement'],\n 'Embed': window['HTMLEmbedElement'],\n 'FieldSet': window['HTMLFieldSetElement'],\n 'Form': window['HTMLFormElement'],\n 'Heading': window['HTMLHeadingElement'],\n 'HR': window['HTMLHRElement'],\n 'Html': window['HTMLHtmlElement'],\n 'IFrame': window['HTMLIFrameElement'],\n 'Image': window['HTMLImageElement'],\n 'Input': window['HTMLInputElement'],\n 'Keygen': window['HTMLKeygenElement'],\n 'Label': window['HTMLLabelElement'],\n 'Legend': window['HTMLLegendElement'],\n 'LI': window['HTMLLIElement'],\n 'Link': window['HTMLLinkElement'],\n 'Map': window['HTMLMapElement'],\n 'Media': window['HTMLMediaElement'],\n 'Menu': window['HTMLMenuElement'],\n 'MenuItem': window['HTMLMenuItemElement'],\n 'Meta': window['HTMLMetaElement'],\n 'Meter': window['HTMLMeterElement'],\n 'Object': window['HTMLObjectElement'],\n 'OList': window['HTMLOListElement'],\n 'OptGroup': window['HTMLOptGroupElement'],\n 'Option': window['HTMLOptionElement'],\n 'Output': window['HTMLOutputElement'],\n 'Paragraph': window['HTMLParagraphElement'],\n 'Param': window['HTMLParamElement'],\n 'Picture': window['HTMLPictureElement'],\n 'Pre': window['HTMLPreElement'],\n 'Progress': window['HTMLProgressElement'],\n 'Quote': window['HTMLQuoteElement'],\n 'Script': window['HTMLScriptElement'],\n 'Select': window['HTMLSelectElement'],\n 'Slot': window['HTMLSlotElement'],\n 'Source': window['HTMLSourceElement'],\n 'Span': window['HTMLSpanElement'],\n 'Style': window['HTMLStyleElement'],\n 'TableCaption': window['HTMLTableCaptionElement'],\n 'Table': window['HTMLTableElement'],\n 'TableRow': window['HTMLTableRowElement'],\n 'TableSection': window['HTMLTableSectionElement'],\n 'Template': window['HTMLTemplateElement'],\n 'TextArea': window['HTMLTextAreaElement'],\n 'Time': window['HTMLTimeElement'],\n 'Title': window['HTMLTitleElement'],\n 'Track': window['HTMLTrackElement'],\n 'UList': window['HTMLUListElement'],\n 'Unknown': window['HTMLUnknownElement'],\n },\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport CEState from '../CustomElementState.js';\nimport AlreadyConstructedMarker from '../AlreadyConstructedMarker.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n window['HTMLElement'] = (function() {\n /**\n * @type {function(new: HTMLElement): !HTMLElement}\n */\n function HTMLElement() {\n // This should really be `new.target` but `new.target` can't be emulated\n // in ES5. Assuming the user keeps the default value of the constructor's\n // prototype's `constructor` property, this is equivalent.\n /** @type {!Function} */\n const constructor = this.constructor;\n\n const definition = internals.constructorToDefinition(constructor);\n if (!definition) {\n throw new Error('The custom element being constructed was not registered with `customElements`.');\n }\n\n const constructionStack = definition.constructionStack;\n\n if (constructionStack.length === 0) {\n const element = Native.Document_createElement.call(document, definition.localName);\n Object.setPrototypeOf(element, constructor.prototype);\n element.__CE_state = CEState.custom;\n element.__CE_definition = definition;\n internals.patch(element);\n return element;\n }\n\n const lastIndex = constructionStack.length - 1;\n const element = constructionStack[lastIndex];\n if (element === AlreadyConstructedMarker) {\n throw new Error('The HTMLElement constructor was either called reentrantly for this constructor or called multiple times.');\n }\n constructionStack[lastIndex] = AlreadyConstructedMarker;\n\n Object.setPrototypeOf(element, constructor.prototype);\n internals.patch(/** @type {!HTMLElement} */ (element));\n\n return element;\n }\n\n HTMLElement.prototype = Native.HTMLElement.prototype;\n\n return HTMLElement;\n })();\n};\n","/**\n * @license\n * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.\n * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\n * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\n * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\n * Code distributed by Google as part of the polymer project is also\n * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n */\n\nimport CustomElementInternals from './CustomElementInternals.js';\nimport CustomElementRegistry from './CustomElementRegistry.js';\n\nimport PatchHTMLElement from './Patch/HTMLElement.js';\nimport PatchHTMLElementSubclasses from './Patch/HTMLElementSubclasses.js';\nimport PatchDocument from './Patch/Document.js';\nimport PatchNode from './Patch/Node.js';\nimport PatchElement from './Patch/Element.js';\n\nconst priorCustomElements = window['customElements'];\n\nif (!priorCustomElements ||\n priorCustomElements['forcePolyfill'] ||\n (typeof priorCustomElements['define'] != 'function') ||\n (typeof priorCustomElements['get'] != 'function')) {\n /** @type {!CustomElementInternals} */\n const internals = new CustomElementInternals();\n\n PatchHTMLElement(internals);\n\tPatchHTMLElementSubclasses(internals);\n PatchDocument(internals);\n PatchNode(internals);\n PatchElement(internals);\n\n // The main document is always associated with the registry.\n document.__CE_hasRegistry = true;\n\n /** @type {!CustomElementRegistry} */\n const customElements = new CustomElementRegistry(internals);\n\n Object.defineProperty(window, 'customElements', {\n configurable: true,\n enumerable: true,\n value: customElements,\n });\n}\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport CEState from '../CustomElementState.js';\nimport AlreadyConstructedMarker from '../AlreadyConstructedMarker.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n for (let subclass in Native.HTMLElement_subclasses) {\n patchElement(`HTML${subclass}Element`, Native.HTMLElement_subclasses[subclass]);\n }\n\n function patchElement(elementName, NativeElement) {\n if (!NativeElement) {\n return;\n }\n\n window[elementName] = (function() {\n /**\n * @type {function(new: HTMLElement): !HTMLElement}\n */\n function PatchedElement() {\n // This should really be `new.target` but `new.target` can't be emulated\n // in ES5. Assuming the user keeps the default value of the constructor's\n // prototype's `constructor` property, this is equivalent.\n /** @type {!Function} */\n const constructor = this.constructor;\n\n const definition = internals.constructorToDefinition(constructor);\n if (!definition) {\n throw new Error('The custom element being constructed was not registered with `customElements`.');\n }\n\n const constructionStack = definition.constructionStack;\n\n if (constructionStack.length === 0) {\n let element;\n if (definition.name !== definition.localName) {\n element = Native.Document_createElement.call(document, definition.localName, {is: definition.name});\n } else {\n element = Native.Document_createElement.call(document, definition.localName);\n }\n Object.setPrototypeOf(element, constructor.prototype);\n element.__CE_state = CEState.custom;\n element.__CE_definition = definition;\n internals.patch(element);\n return element;\n }\n\n const lastIndex = constructionStack.length - 1;\n const element = constructionStack[lastIndex];\n if (element === AlreadyConstructedMarker) {\n throw new Error(`The ${elementName} constructor was either called reentrantly for this constructor or called multiple times.`);\n }\n constructionStack[lastIndex] = AlreadyConstructedMarker;\n\n Object.setPrototypeOf(element, constructor.prototype);\n internals.patch(/** @type {!HTMLElement} */ (element));\n\n return /** @type {!HTMLElement} */ (element);\n }\n\n PatchedElement.prototype = NativeElement.prototype;\n\n return PatchedElement;\n })();\n }\n};\n","import CustomElementInternals from '../../CustomElementInternals.js';\nimport * as Utilities from '../../Utilities.js';\n\n/**\n * @typedef {{\n * prepend: !function(...(!Node|string)),\n * append: !function(...(!Node|string)),\n * }}\n */\nlet ParentNodeNativeMethods;\n\n/**\n * @param {!CustomElementInternals} internals\n * @param {!Object} destination\n * @param {!ParentNodeNativeMethods} builtIn\n */\nexport default function(internals, destination, builtIn) {\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['prepend'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.prepend.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['append'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.append.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport * as Utilities from '../Utilities.js';\n\nimport PatchParentNode from './Interface/ParentNode.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n Utilities.setPropertyUnchecked(document, 'createElement',\n /**\n * @this {Document}\n * @param {string} localName\n * @return {!Element}\n */\n function(localName, options) {\n // Only create custom elements if this document is associated with the registry.\n if (this.__CE_hasRegistry) {\n\t\t\t\tconst name = options && options.is ? options.is : localName;\n const definition = internals.nameToDefinition(name);\n if (definition) {\n return new (definition.constructor)();\n }\n }\n\n const result = /** @type {!Element} */\n (Native.Document_createElement.call(this, localName));\n\t\t\tif (options && options.is) {\n\t\t\t\tresult.__CE_is = options.is;\n\t\t\t}\n internals.patch(result);\n return result;\n });\n\n Utilities.setPropertyUnchecked(Document.prototype, 'importNode',\n /**\n * @this {Document}\n * @param {!Node} node\n * @param {boolean=} deep\n * @return {!Node}\n */\n function(node, deep) {\n const clone = Native.Document_importNode.call(this, node, deep);\n // Only create custom elements if this document is associated with the registry.\n if (!this.__CE_hasRegistry) {\n internals.patchTree(clone);\n } else {\n internals.patchAndUpgradeTree(clone);\n }\n return clone;\n });\n\n const NS_HTML = \"http://www.w3.org/1999/xhtml\";\n\n Utilities.setPropertyUnchecked(document, 'createElementNS',\n /**\n * @this {Document}\n * @param {?string} namespace\n * @param {string} localName\n * @return {!Element}\n */\n function(namespace, localName, options) {\n // Only create custom elements if this document is associated with the registry.\n if (this.__CE_hasRegistry && (namespace === null || namespace === NS_HTML)) {\n\t\t\t\tconst name = options && options.is ? options.is : localName;\n const definition = internals.nameToDefinition(name);\n if (definition) {\n return new (definition.constructor)();\n }\n }\n\n const result = /** @type {!Element} */\n (Native.Document_createElementNS.call(this, namespace, localName));\n internals.patch(result);\n return result;\n });\n\n PatchParentNode(internals, Document.prototype, {\n prepend: Native.Document_prepend,\n append: Native.Document_append,\n });\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport * as Utilities from '../Utilities.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n // `Node#nodeValue` is implemented on `Attr`.\n // `Node#textContent` is implemented on `Attr`, `Element`.\n\n Utilities.setPropertyUnchecked(Node.prototype, 'insertBefore',\n /**\n * @this {Node}\n * @param {!Node} node\n * @param {?Node} refNode\n * @return {!Node}\n */\n function(node, refNode) {\n if (node instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(node.childNodes);\n const nativeResult = Native.Node_insertBefore.call(this, node, refNode);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_insertBefore.call(this, node, refNode);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n if (Utilities.isConnected(this)) {\n internals.connectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'appendChild',\n /**\n * @this {Node}\n * @param {!Node} node\n * @return {!Node}\n */\n function(node) {\n if (node instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(node.childNodes);\n const nativeResult = Native.Node_appendChild.call(this, node);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_appendChild.call(this, node);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n if (Utilities.isConnected(this)) {\n internals.connectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'cloneNode',\n /**\n * @this {Node}\n * @param {boolean=} deep\n * @return {!Node}\n */\n function(deep) {\n const clone = Native.Node_cloneNode.call(this, deep);\n // Only create custom elements if this element's owner document is\n // associated with the registry.\n if (!this.ownerDocument.__CE_hasRegistry) {\n internals.patchTree(clone);\n } else {\n internals.patchAndUpgradeTree(clone);\n }\n return clone;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'removeChild',\n /**\n * @this {Node}\n * @param {!Node} node\n * @return {!Node}\n */\n function(node) {\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_removeChild.call(this, node);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'replaceChild',\n /**\n * @this {Node}\n * @param {!Node} nodeToInsert\n * @param {!Node} nodeToRemove\n * @return {!Node}\n */\n function(nodeToInsert, nodeToRemove) {\n if (nodeToInsert instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(nodeToInsert.childNodes);\n const nativeResult = Native.Node_replaceChild.call(this, nodeToInsert, nodeToRemove);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n internals.disconnectTree(nodeToRemove);\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeToInsertWasConnected = Utilities.isConnected(nodeToInsert);\n const nativeResult = Native.Node_replaceChild.call(this, nodeToInsert, nodeToRemove);\n const thisIsConnected = Utilities.isConnected(this);\n\n if (thisIsConnected) {\n internals.disconnectTree(nodeToRemove);\n }\n\n if (nodeToInsertWasConnected) {\n internals.disconnectTree(nodeToInsert);\n }\n\n if (thisIsConnected) {\n internals.connectTree(nodeToInsert);\n }\n\n return nativeResult;\n });\n\n\n function patch_textContent(destination, baseDescriptor) {\n Object.defineProperty(destination, 'textContent', {\n enumerable: baseDescriptor.enumerable,\n configurable: true,\n get: baseDescriptor.get,\n set: /** @this {Node} */ function(assignedValue) {\n // If this is a text node then there are no nodes to disconnect.\n if (this.nodeType === Node.TEXT_NODE) {\n baseDescriptor.set.call(this, assignedValue);\n return;\n }\n\n let removedNodes = undefined;\n // Checking for `firstChild` is faster than reading `childNodes.length`\n // to compare with 0.\n if (this.firstChild) {\n // Using `childNodes` is faster than `children`, even though we only\n // care about elements.\n const childNodes = this.childNodes;\n const childNodesLength = childNodes.length;\n if (childNodesLength > 0 && Utilities.isConnected(this)) {\n // Copying an array by iterating is faster than using slice.\n removedNodes = new Array(childNodesLength);\n for (let i = 0; i < childNodesLength; i++) {\n removedNodes[i] = childNodes[i];\n }\n }\n }\n\n baseDescriptor.set.call(this, assignedValue);\n\n if (removedNodes) {\n for (let i = 0; i < removedNodes.length; i++) {\n internals.disconnectTree(removedNodes[i]);\n }\n }\n },\n });\n }\n\n if (Native.Node_textContent && Native.Node_textContent.get) {\n patch_textContent(Node.prototype, Native.Node_textContent);\n } else {\n internals.addPatch(function(element) {\n patch_textContent(element, {\n enumerable: true,\n configurable: true,\n // NOTE: This implementation of the `textContent` getter assumes that\n // text nodes' `textContent` getter will not be patched.\n get: /** @this {Node} */ function() {\n /** @type {!Array} */\n const parts = [];\n\n for (let i = 0; i < this.childNodes.length; i++) {\n parts.push(this.childNodes[i].textContent);\n }\n\n return parts.join('');\n },\n set: /** @this {Node} */ function(assignedValue) {\n while (this.firstChild) {\n Native.Node_removeChild.call(this, this.firstChild);\n }\n Native.Node_appendChild.call(this, document.createTextNode(assignedValue));\n },\n });\n });\n }\n};\n","import CustomElementInternals from '../../CustomElementInternals.js';\nimport * as Utilities from '../../Utilities.js';\n\n/**\n * @typedef {{\n * before: !function(...(!Node|string)),\n * after: !function(...(!Node|string)),\n * replaceWith: !function(...(!Node|string)),\n * remove: !function(),\n * }}\n */\nlet ChildNodeNativeMethods;\n\n/**\n * @param {!CustomElementInternals} internals\n * @param {!Object} destination\n * @param {!ChildNodeNativeMethods} builtIn\n */\nexport default function(internals, destination, builtIn) {\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['before'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.before.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['after'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.after.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['replaceWith'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n const wasConnected = Utilities.isConnected(this);\n\n builtIn.replaceWith.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (wasConnected) {\n internals.disconnectTree(this);\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n destination['remove'] = function() {\n const wasConnected = Utilities.isConnected(this);\n\n builtIn.remove.call(this);\n\n if (wasConnected) {\n internals.disconnectTree(this);\n }\n };\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport CEState from '../CustomElementState.js';\nimport * as Utilities from '../Utilities.js';\n\nimport PatchParentNode from './Interface/ParentNode.js';\nimport PatchChildNode from './Interface/ChildNode.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n if (Native.Element_attachShadow) {\n Utilities.setPropertyUnchecked(Element.prototype, 'attachShadow',\n /**\n * @this {Element}\n * @param {!{mode: string}} init\n * @return {ShadowRoot}\n */\n function(init) {\n const shadowRoot = Native.Element_attachShadow.call(this, init);\n this.__CE_shadowRoot = shadowRoot;\n return shadowRoot;\n });\n } else {\n console.warn('Custom Elements: `Element#attachShadow` was not patched.');\n }\n\n\n function patch_innerHTML(destination, baseDescriptor) {\n Object.defineProperty(destination, 'innerHTML', {\n enumerable: baseDescriptor.enumerable,\n configurable: true,\n get: baseDescriptor.get,\n set: /** @this {Element} */ function(htmlString) {\n const isConnected = Utilities.isConnected(this);\n\n // NOTE: In IE11, when using the native `innerHTML` setter, all nodes\n // that were previously descendants of the context element have all of\n // their children removed as part of the set - the entire subtree is\n // 'disassembled'. This work around walks the subtree *before* using the\n // native setter.\n /** @type {!Array|undefined} */\n let removedElements = undefined;\n if (isConnected) {\n removedElements = [];\n Utilities.walkDeepDescendantElements(this, element => {\n if (element !== this) {\n removedElements.push(element);\n }\n });\n }\n\n baseDescriptor.set.call(this, htmlString);\n\n if (removedElements) {\n for (let i = 0; i < removedElements.length; i++) {\n const element = removedElements[i];\n if (element.__CE_state === CEState.custom) {\n internals.disconnectedCallback(element);\n }\n }\n }\n\n // Only create custom elements if this element's owner document is\n // associated with the registry.\n if (!this.ownerDocument.__CE_hasRegistry) {\n internals.patchTree(this);\n } else {\n internals.patchAndUpgradeTree(this);\n }\n return htmlString;\n },\n });\n }\n\n if (Native.Element_innerHTML && Native.Element_innerHTML.get) {\n patch_innerHTML(Element.prototype, Native.Element_innerHTML);\n } else if (Native.HTMLElement_innerHTML && Native.HTMLElement_innerHTML.get) {\n patch_innerHTML(HTMLElement.prototype, Native.HTMLElement_innerHTML);\n } else {\n\n /** @type {HTMLDivElement} */\n const rawDiv = Native.Document_createElement.call(document, 'div');\n\n internals.addPatch(function(element) {\n patch_innerHTML(element, {\n enumerable: true,\n configurable: true,\n // Implements getting `innerHTML` by performing an unpatched `cloneNode`\n // of the element and returning the resulting element's `innerHTML`.\n // TODO: Is this too expensive?\n get: /** @this {Element} */ function() {\n return Native.Node_cloneNode.call(this, true).innerHTML;\n },\n // Implements setting `innerHTML` by creating an unpatched element,\n // setting `innerHTML` of that element and replacing the target\n // element's children with those of the unpatched element.\n set: /** @this {Element} */ function(assignedValue) {\n // NOTE: re-route to `content` for `template` elements.\n // We need to do this because `template.appendChild` does not\n // route into `template.content`.\n /** @type {!Node} */\n const content = this.localName === 'template' ? (/** @type {!HTMLTemplateElement} */ (this)).content : this;\n rawDiv.innerHTML = assignedValue;\n\n while (content.childNodes.length > 0) {\n Native.Node_removeChild.call(content, content.childNodes[0]);\n }\n while (rawDiv.childNodes.length > 0) {\n Native.Node_appendChild.call(content, rawDiv.childNodes[0]);\n }\n },\n });\n });\n }\n\n\n Utilities.setPropertyUnchecked(Element.prototype, 'setAttribute',\n /**\n * @this {Element}\n * @param {string} name\n * @param {string} newValue\n */\n function(name, newValue) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_setAttribute.call(this, name, newValue);\n }\n\n const oldValue = Native.Element_getAttribute.call(this, name);\n Native.Element_setAttribute.call(this, name, newValue);\n newValue = Native.Element_getAttribute.call(this, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, null);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'setAttributeNS',\n /**\n * @this {Element}\n * @param {?string} namespace\n * @param {string} name\n * @param {string} newValue\n */\n function(namespace, name, newValue) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_setAttributeNS.call(this, namespace, name, newValue);\n }\n\n const oldValue = Native.Element_getAttributeNS.call(this, namespace, name);\n Native.Element_setAttributeNS.call(this, namespace, name, newValue);\n newValue = Native.Element_getAttributeNS.call(this, namespace, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, namespace);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'removeAttribute',\n /**\n * @this {Element}\n * @param {string} name\n */\n function(name) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_removeAttribute.call(this, name);\n }\n\n const oldValue = Native.Element_getAttribute.call(this, name);\n Native.Element_removeAttribute.call(this, name);\n if (oldValue !== null) {\n internals.attributeChangedCallback(this, name, oldValue, null, null);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'removeAttributeNS',\n /**\n * @this {Element}\n * @param {?string} namespace\n * @param {string} name\n */\n function(namespace, name) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_removeAttributeNS.call(this, namespace, name);\n }\n\n const oldValue = Native.Element_getAttributeNS.call(this, namespace, name);\n Native.Element_removeAttributeNS.call(this, namespace, name);\n // In older browsers, `Element#getAttributeNS` may return the empty string\n // instead of null if the attribute does not exist. For details, see;\n // https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttributeNS#Notes\n const newValue = Native.Element_getAttributeNS.call(this, namespace, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, namespace);\n }\n });\n\n\n function patch_insertAdjacentElement(destination, baseMethod) {\n Utilities.setPropertyUnchecked(destination, 'insertAdjacentElement',\n /**\n * @this {Element}\n * @param {string} where\n * @param {!Element} element\n * @return {?Element}\n */\n function(where, element) {\n const wasConnected = Utilities.isConnected(element);\n const insertedElement = /** @type {!Element} */\n (baseMethod.call(this, where, element));\n\n if (wasConnected) {\n internals.disconnectTree(element);\n }\n\n if (Utilities.isConnected(insertedElement)) {\n internals.connectTree(element);\n }\n return insertedElement;\n });\n }\n\n if (Native.HTMLElement_insertAdjacentElement) {\n patch_insertAdjacentElement(HTMLElement.prototype, Native.HTMLElement_insertAdjacentElement);\n } else if (Native.Element_insertAdjacentElement) {\n patch_insertAdjacentElement(Element.prototype, Native.Element_insertAdjacentElement);\n } else {\n console.warn('Custom Elements: `Element#insertAdjacentElement` was not patched.');\n }\n\n\n PatchParentNode(internals, Element.prototype, {\n prepend: Native.Element_prepend,\n append: Native.Element_append,\n });\n\n PatchChildNode(internals, Element.prototype, {\n before: Native.Element_before,\n after: Native.Element_after,\n replaceWith: Native.Element_replaceWith,\n remove: Native.Element_remove,\n });\n};\n"]} \ No newline at end of file +{"version":3,"sources":["src/AlreadyConstructedMarker.js","src/Utilities.js","src/CustomElementInternals.js","src/CustomElementState.js","src/DocumentConstructionObserver.js","src/Deferred.js","src/CustomElementRegistry.js","src/Patch/Native.js","src/Patch/HTMLElement.js","src/custom-elements.js","src/Patch/Interface/ParentNode.js","src/Patch/Document.js","src/Patch/Node.js","src/Patch/Interface/ChildNode.js","src/Patch/Element.js"],"names":["$jscompDefaultExport","AlreadyConstructedMarker","reservedTagList","Set","isValidCustomElementName$$module$$src$Utilities","isValidCustomElementName","localName","reserved","has","validForm","test","isConnected$$module$$src$Utilities","isConnected","node","nativeValue","undefined","current","__CE_isImportDocument","Document","parentNode","window","ShadowRoot","host","nextSiblingOrAncestorSibling$$module$$src$Utilities","nextSiblingOrAncestorSibling","root","start","nextSibling","walkDeepDescendantElements$$module$$src$Utilities","walkDeepDescendantElements","callback","visitedImports","nodeType","Node","ELEMENT_NODE","element","getAttribute","importNode","import","add","child","firstChild","shadowRoot","__CE_shadowRoot","setPropertyUnchecked$$module$$src$Utilities","setPropertyUnchecked","destination","name","value","constructor","CustomElementInternals","_localNameToDefinition","Map","_constructorToDefinition","_patches","_hasPatches","setDefinition","definition","set","addPatch","listener","push","patchTree","patch","__CE_patched","i","length","connectTree","elements","custom","__CE_state","connectedCallback","upgradeElement","disconnectTree","disconnectedCallback","patchAndUpgradeTree","gatherElements","readyState","__CE_hasRegistry","addEventListener","__CE_documentLoadHandled","delete","localNameToDefinition","get","constructionStack","result","Error","pop","e","failed","__CE_definition","attributeChangedCallback","observedAttributes","call","oldValue","newValue","namespace","indexOf","DocumentConstructionObserver","internals","doc","_internals","_document","_observer","MutationObserver","_handleMutations","bind","observe","childList","subtree","disconnect","mutations","addedNodes","j","Deferred","_resolve","_value","_promise","Promise","resolve","CustomElementRegistry","_elementDefinitionIsRunning","_whenDefinedDeferred","_flushCallback","this._flushCallback","fn","_flushPending","_unflushedLocalNames","_documentConstructionObserver","document","define","Function","TypeError","SyntaxError","adoptedCallback","getCallback","callbackValue","prototype","Object","_flush","shift","deferred","whenDefined","reject","prior","polyfillWrapFlushCallback","outer","inner","flush","Document_createElement","createElement","Document_createElementNS","createElementNS","Document_importNode","Document_prepend","Document_append","Node_cloneNode","cloneNode","Node_appendChild","appendChild","Node_insertBefore","insertBefore","Node_removeChild","removeChild","Node_replaceChild","replaceChild","Node_textContent","getOwnPropertyDescriptor","Element_attachShadow","Element","Element_innerHTML","Element_getAttribute","Element_setAttribute","setAttribute","Element_removeAttribute","removeAttribute","Element_getAttributeNS","getAttributeNS","Element_setAttributeNS","setAttributeNS","Element_removeAttributeNS","removeAttributeNS","Element_insertAdjacentElement","Element_prepend","Element_append","Element_before","Element_after","Element_replaceWith","Element_remove","HTMLElement","HTMLElement_innerHTML","HTMLElement_insertAdjacentElement","$jscompDefaultExport$$module$$src$Patch$HTMLElement","$jscompDefaultExport$$module$$src$Patch$Native.Document_createElement.call","setPrototypeOf","lastIndex","$jscompDefaultExport$$module$$src$Patch$Native.HTMLElement","$jscompDefaultExport$$module$$src$Patch$Interface$ParentNode","builtIn","connectedBefore","nodes","filter","prepend","apply","append","$jscompDefaultExport$$module$$src$Patch$Document","deep","clone","$jscompDefaultExport$$module$$src$Patch$Native.Document_importNode.call","NS_HTML","$jscompDefaultExport$$module$$src$Patch$Native.Document_createElementNS.call","$jscompDefaultExport$$module$$src$Patch$Native.Document_prepend","$jscompDefaultExport$$module$$src$Patch$Native.Document_append","$jscompDefaultExport$$module$$src$Patch$Node","patch_textContent","baseDescriptor","defineProperty","enumerable","configurable","assignedValue","TEXT_NODE","removedNodes","childNodes","childNodesLength","Array","refNode","DocumentFragment","insertedNodes","slice","nativeResult","$jscompDefaultExport$$module$$src$Patch$Native.Node_insertBefore.call","nodeWasConnected","$jscompDefaultExport$$module$$src$Patch$Native.Node_appendChild.call","$jscompDefaultExport$$module$$src$Patch$Native.Node_cloneNode.call","ownerDocument","$jscompDefaultExport$$module$$src$Patch$Native.Node_removeChild.call","nodeToInsert","nodeToRemove","$jscompDefaultExport$$module$$src$Patch$Native.Node_replaceChild.call","nodeToInsertWasConnected","thisIsConnected","$jscompDefaultExport$$module$$src$Patch$Native.Node_textContent","$jscompDefaultExport$$module$$src$Patch$Native.Node_textContent.get","parts","textContent","join","createTextNode","$jscompDefaultExport$$module$$src$Patch$Interface$ChildNode","$jscompDefaultExport$$module$$src$Patch$Native.Element_before","$jscompDefaultExport$$module$$src$Patch$Native.Element_after","wasConnected","$jscompDefaultExport$$module$$src$Patch$Native.Element_replaceWith","$jscompDefaultExport$$module$$src$Patch$Native.Element_remove","$jscompDefaultExport$$module$$src$Patch$Element","patch_innerHTML","htmlString","removedElements","patch_insertAdjacentElement","baseMethod","where","insertedElement","$jscompDefaultExport$$module$$src$Patch$Native.Element_attachShadow","init","$jscompDefaultExport$$module$$src$Patch$Native.Element_attachShadow.call","console","warn","$jscompDefaultExport$$module$$src$Patch$Native.Element_innerHTML","$jscompDefaultExport$$module$$src$Patch$Native.Element_innerHTML.get","$jscompDefaultExport$$module$$src$Patch$Native.HTMLElement_innerHTML","$jscompDefaultExport$$module$$src$Patch$Native.HTMLElement_innerHTML.get","rawDiv","innerHTML","content","$jscompDefaultExport$$module$$src$Patch$Native.Element_setAttribute.call","$jscompDefaultExport$$module$$src$Patch$Native.Element_getAttribute.call","$jscompDefaultExport$$module$$src$Patch$Native.Element_setAttributeNS.call","$jscompDefaultExport$$module$$src$Patch$Native.Element_getAttributeNS.call","$jscompDefaultExport$$module$$src$Patch$Native.Element_removeAttribute.call","$jscompDefaultExport$$module$$src$Patch$Native.Element_removeAttributeNS.call","$jscompDefaultExport$$module$$src$Patch$Native.HTMLElement_insertAdjacentElement","$jscompDefaultExport$$module$$src$Patch$Native.Element_insertAdjacentElement","$jscompDefaultExport$$module$$src$Patch$Native.Element_prepend","$jscompDefaultExport$$module$$src$Patch$Native.Element_append","priorCustomElements","customElements"],"mappings":"A;aASA,IAAAA,EAAe,IAFfC,QAAA,EAAA,E,CCPA,IAAMC,GAAkB,IAAIC,GAAJ,CAAQ,kHAAA,MAAA,CAAA,GAA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,UAA3B,CAA8C,CAC5CiE,EAAS+E,EADmC,CAE5C7E,OAAQ8E,EAFoC,CAA9C,CDxNa1R,GC6Nb,CAAemG,CAAf,CApOiC,C;;;;;;;;;ALOnC,IAAMwL,EAAsBvQ,MAAA,eAE5B,IAAKuQ,CAAAA,CAAL,EACKA,CAAA,cADL,EAE8C,UAF9C,EAEM,MAAOA,EAAA,OAFb,EAG2C,UAH3C,EAGM,MAAOA,EAAA,IAHb,CAGwD,CAEtD,IAAMxL,EAAY,IPtBLjD,CMKAlD,GCmBb,EElBaA,GFmBb,EGrBaA,GHsBb,EKlBaA,GLmBb,EAGAiI,SAAAnD,iBAAA,CAA4B,CAAA,CAG5B,KAAM8M,GAAiB,IH5BVpK,CG4BU,CAA0BrB,CAA1B,CAEvBuC,OAAA8E,eAAA,CAAsBpM,MAAtB,CAA8B,gBAA9B,CAAgD,CAC9CsM,aAAc,CAAA,CADgC,CAE9CD,WAAY,CAAA,CAFkC,CAG9CzK,MAAO4O,EAHuC,CAAhD,CAfsD","file":"custom-elements.min.js","sourcesContent":["/**\n * This class exists only to work around Closure's lack of a way to describe\n * singletons. It represents the 'already constructed marker' used in custom\n * element construction stacks.\n *\n * https://html.spec.whatwg.org/#concept-already-constructed-marker\n */\nclass AlreadyConstructedMarker {}\n\nexport default new AlreadyConstructedMarker();\n","const reservedTagList = new Set([\n 'annotation-xml',\n 'color-profile',\n 'font-face',\n 'font-face-src',\n 'font-face-uri',\n 'font-face-format',\n 'font-face-name',\n 'missing-glyph',\n]);\n\n/**\n * @param {string} localName\n * @returns {boolean}\n */\nexport function isValidCustomElementName(localName) {\n const reserved = reservedTagList.has(localName);\n const validForm = /^[a-z][.0-9_a-z]*-[\\-.0-9_a-z]*$/.test(localName);\n return !reserved && validForm;\n}\n\n/**\n * @private\n * @param {!Node} node\n * @return {boolean}\n */\nexport function isConnected(node) {\n // Use `Node#isConnected`, if defined.\n const nativeValue = node.isConnected;\n if (nativeValue !== undefined) {\n return nativeValue;\n }\n\n /** @type {?Node|undefined} */\n let current = node;\n while (current && !(current.__CE_isImportDocument || current instanceof Document)) {\n current = current.parentNode || (window.ShadowRoot && current instanceof ShadowRoot ? current.host : undefined);\n }\n return !!(current && (current.__CE_isImportDocument || current instanceof Document));\n}\n\n/**\n * @param {!Node} root\n * @param {!Node} start\n * @return {?Node}\n */\nfunction nextSiblingOrAncestorSibling(root, start) {\n let node = start;\n while (node && node !== root && !node.nextSibling) {\n node = node.parentNode;\n }\n return (!node || node === root) ? null : node.nextSibling;\n}\n\n/**\n * @param {!Node} root\n * @param {!Node} start\n * @return {?Node}\n */\nfunction nextNode(root, start) {\n return start.firstChild ? start.firstChild : nextSiblingOrAncestorSibling(root, start);\n}\n\n/**\n * @param {!Node} root\n * @param {!function(!Element)} callback\n * @param {!Set=} visitedImports\n */\nexport function walkDeepDescendantElements(root, callback, visitedImports = new Set()) {\n let node = root;\n while (node) {\n if (node.nodeType === Node.ELEMENT_NODE) {\n const element = /** @type {!Element} */(node);\n\n callback(element);\n\n const localName = element.localName;\n if (localName === 'link' && element.getAttribute('rel') === 'import') {\n // If this import (polyfilled or not) has it's root node available,\n // walk it.\n const importNode = /** @type {!Node} */ (element.import);\n if (importNode instanceof Node && !visitedImports.has(importNode)) {\n // Prevent multiple walks of the same import root.\n visitedImports.add(importNode);\n\n for (let child = importNode.firstChild; child; child = child.nextSibling) {\n walkDeepDescendantElements(child, callback, visitedImports);\n }\n }\n\n // Ignore descendants of import links to prevent attempting to walk the\n // elements created by the HTML Imports polyfill that we just walked\n // above.\n node = nextSiblingOrAncestorSibling(root, element);\n continue;\n } else if (localName === 'template') {\n // Ignore descendants of templates. There shouldn't be any descendants\n // because they will be moved into `.content` during construction in\n // browsers that support template but, in case they exist and are still\n // waiting to be moved by a polyfill, they will be ignored.\n node = nextSiblingOrAncestorSibling(root, element);\n continue;\n }\n\n // Walk shadow roots.\n const shadowRoot = element.__CE_shadowRoot;\n if (shadowRoot) {\n for (let child = shadowRoot.firstChild; child; child = child.nextSibling) {\n walkDeepDescendantElements(child, callback, visitedImports);\n }\n }\n }\n\n node = nextNode(root, node);\n }\n}\n\n/**\n * Used to suppress Closure's \"Modifying the prototype is only allowed if the\n * constructor is in the same scope\" warning without using\n * `@suppress {newCheckTypes, duplicate}` because `newCheckTypes` is too broad.\n *\n * @param {!Object} destination\n * @param {string} name\n * @param {*} value\n */\nexport function setPropertyUnchecked(destination, name, value) {\n destination[name] = value;\n}\n","import * as Utilities from './Utilities.js';\nimport CEState from './CustomElementState.js';\n\nexport default class CustomElementInternals {\n constructor() {\n /** @type {!Map} */\n this._localNameToDefinition = new Map();\n\n /** @type {!Map} */\n this._constructorToDefinition = new Map();\n\n /** @type {!Array} */\n this._patches = [];\n\n /** @type {boolean} */\n this._hasPatches = false;\n }\n\n /**\n * @param {string} localName\n * @param {!CustomElementDefinition} definition\n */\n setDefinition(localName, definition) {\n this._localNameToDefinition.set(localName, definition);\n this._constructorToDefinition.set(definition.constructor, definition);\n }\n\n /**\n * @param {string} localName\n * @return {!CustomElementDefinition|undefined}\n */\n localNameToDefinition(localName) {\n return this._localNameToDefinition.get(localName);\n }\n\n /**\n * @param {!Function} constructor\n * @return {!CustomElementDefinition|undefined}\n */\n constructorToDefinition(constructor) {\n return this._constructorToDefinition.get(constructor);\n }\n\n /**\n * @param {!function(!Node)} listener\n */\n addPatch(listener) {\n this._hasPatches = true;\n this._patches.push(listener);\n }\n\n /**\n * @param {!Node} node\n */\n patchTree(node) {\n if (!this._hasPatches) return;\n\n Utilities.walkDeepDescendantElements(node, element => this.patch(element));\n }\n\n /**\n * @param {!Node} node\n */\n patch(node) {\n if (!this._hasPatches) return;\n\n if (node.__CE_patched) return;\n node.__CE_patched = true;\n\n for (let i = 0; i < this._patches.length; i++) {\n this._patches[i](node);\n }\n }\n\n /**\n * @param {!Node} root\n */\n connectTree(root) {\n const elements = [];\n\n Utilities.walkDeepDescendantElements(root, element => elements.push(element));\n\n for (let i = 0; i < elements.length; i++) {\n const element = elements[i];\n if (element.__CE_state === CEState.custom) {\n this.connectedCallback(element);\n } else {\n this.upgradeElement(element);\n }\n }\n }\n\n /**\n * @param {!Node} root\n */\n disconnectTree(root) {\n const elements = [];\n\n Utilities.walkDeepDescendantElements(root, element => elements.push(element));\n\n for (let i = 0; i < elements.length; i++) {\n const element = elements[i];\n if (element.__CE_state === CEState.custom) {\n this.disconnectedCallback(element);\n }\n }\n }\n\n /**\n * Upgrades all uncustomized custom elements at and below a root node for\n * which there is a definition. When custom element reaction callbacks are\n * assumed to be called synchronously (which, by the current DOM / HTML spec\n * definitions, they are *not*), callbacks for both elements customized\n * synchronously by the parser and elements being upgraded occur in the same\n * relative order.\n *\n * NOTE: This function, when used to simulate the construction of a tree that\n * is already created but not customized (i.e. by the parser), does *not*\n * prevent the element from reading the 'final' (true) state of the tree. For\n * example, the element, during truly synchronous parsing / construction would\n * see that it contains no children as they have not yet been inserted.\n * However, this function does not modify the tree, the element will\n * (incorrectly) have children. Additionally, self-modification restrictions\n * for custom element constructors imposed by the DOM spec are *not* enforced.\n *\n *\n * The following nested list shows the steps extending down from the HTML\n * spec's parsing section that cause elements to be synchronously created and\n * upgraded:\n *\n * The \"in body\" insertion mode:\n * https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody\n * - Switch on token:\n * .. other cases ..\n * -> Any other start tag\n * - [Insert an HTML element](below) for the token.\n *\n * Insert an HTML element:\n * https://html.spec.whatwg.org/multipage/syntax.html#insert-an-html-element\n * - Insert a foreign element for the token in the HTML namespace:\n * https://html.spec.whatwg.org/multipage/syntax.html#insert-a-foreign-element\n * - Create an element for a token:\n * https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-the-token\n * - Will execute script flag is true?\n * - (Element queue pushed to the custom element reactions stack.)\n * - Create an element:\n * https://dom.spec.whatwg.org/#concept-create-element\n * - Sync CE flag is true?\n * - Constructor called.\n * - Self-modification restrictions enforced.\n * - Sync CE flag is false?\n * - (Upgrade reaction enqueued.)\n * - Attributes appended to element.\n * (`attributeChangedCallback` reactions enqueued.)\n * - Will execute script flag is true?\n * - (Element queue popped from the custom element reactions stack.\n * Reactions in the popped stack are invoked.)\n * - (Element queue pushed to the custom element reactions stack.)\n * - Insert the element:\n * https://dom.spec.whatwg.org/#concept-node-insert\n * - Shadow-including descendants are connected. During parsing\n * construction, there are no shadow-*excluding* descendants.\n * However, the constructor may have validly attached a shadow\n * tree to itself and added descendants to that shadow tree.\n * (`connectedCallback` reactions enqueued.)\n * - (Element queue popped from the custom element reactions stack.\n * Reactions in the popped stack are invoked.)\n *\n * @param {!Node} root\n * @param {!Set=} visitedImports\n */\n patchAndUpgradeTree(root, visitedImports = new Set()) {\n const elements = [];\n\n const gatherElements = element => {\n if (element.localName === 'link' && element.getAttribute('rel') === 'import') {\n // The HTML Imports polyfill sets a descendant element of the link to\n // the `import` property, specifically this is *not* a Document.\n const importNode = /** @type {?Node} */ (element.import);\n\n if (importNode instanceof Node && importNode.readyState === 'complete') {\n importNode.__CE_isImportDocument = true;\n\n // Connected links are associated with the registry.\n importNode.__CE_hasRegistry = true;\n } else {\n // If this link's import root is not available, its contents can't be\n // walked. Wait for 'load' and walk it when it's ready.\n element.addEventListener('load', () => {\n const importNode = /** @type {!Node} */ (element.import);\n\n if (importNode.__CE_documentLoadHandled) return;\n importNode.__CE_documentLoadHandled = true;\n\n importNode.__CE_isImportDocument = true;\n\n // Connected links are associated with the registry.\n importNode.__CE_hasRegistry = true;\n\n // Clone the `visitedImports` set that was populated sync during\n // the `patchAndUpgradeTree` call that caused this 'load' handler to\n // be added. Then, remove *this* link's import node so that we can\n // walk that import again, even if it was partially walked later\n // during the same `patchAndUpgradeTree` call.\n const clonedVisitedImports = new Set(visitedImports);\n visitedImports.delete(importNode);\n\n this.patchAndUpgradeTree(importNode, visitedImports);\n });\n }\n } else {\n elements.push(element);\n }\n };\n\n // `walkDeepDescendantElements` populates (and internally checks against)\n // `visitedImports` when traversing a loaded import.\n Utilities.walkDeepDescendantElements(root, gatherElements, visitedImports);\n\n if (this._hasPatches) {\n for (let i = 0; i < elements.length; i++) {\n this.patch(elements[i]);\n }\n }\n\n for (let i = 0; i < elements.length; i++) {\n this.upgradeElement(elements[i]);\n }\n }\n\n /**\n * @param {!Element} element\n */\n upgradeElement(element) {\n const currentState = element.__CE_state;\n if (currentState !== undefined) return;\n\n const definition = this.localNameToDefinition(element.localName);\n if (!definition) return;\n\n definition.constructionStack.push(element);\n\n const constructor = definition.constructor;\n try {\n try {\n let result = new (constructor)();\n if (result !== element) {\n throw new Error('The custom element constructor did not produce the element being upgraded.');\n }\n } finally {\n definition.constructionStack.pop();\n }\n } catch (e) {\n element.__CE_state = CEState.failed;\n throw e;\n }\n\n element.__CE_state = CEState.custom;\n element.__CE_definition = definition;\n\n if (definition.attributeChangedCallback) {\n const observedAttributes = definition.observedAttributes;\n for (let i = 0; i < observedAttributes.length; i++) {\n const name = observedAttributes[i];\n const value = element.getAttribute(name);\n if (value !== null) {\n this.attributeChangedCallback(element, name, null, value, null);\n }\n }\n }\n\n if (Utilities.isConnected(element)) {\n this.connectedCallback(element);\n }\n }\n\n /**\n * @param {!Element} element\n */\n connectedCallback(element) {\n const definition = element.__CE_definition;\n if (definition.connectedCallback) {\n definition.connectedCallback.call(element);\n }\n }\n\n /**\n * @param {!Element} element\n */\n disconnectedCallback(element) {\n const definition = element.__CE_definition;\n if (definition.disconnectedCallback) {\n definition.disconnectedCallback.call(element);\n }\n }\n\n /**\n * @param {!Element} element\n * @param {string} name\n * @param {?string} oldValue\n * @param {?string} newValue\n * @param {?string} namespace\n */\n attributeChangedCallback(element, name, oldValue, newValue, namespace) {\n const definition = element.__CE_definition;\n if (\n definition.attributeChangedCallback &&\n definition.observedAttributes.indexOf(name) > -1\n ) {\n definition.attributeChangedCallback.call(element, name, oldValue, newValue, namespace);\n }\n }\n}\n","/**\n * @enum {number}\n */\nconst CustomElementState = {\n custom: 1,\n failed: 2,\n};\n\nexport default CustomElementState;\n","import CustomElementInternals from './CustomElementInternals.js';\n\nexport default class DocumentConstructionObserver {\n constructor(internals, doc) {\n /**\n * @type {!CustomElementInternals}\n */\n this._internals = internals;\n\n /**\n * @type {!Document}\n */\n this._document = doc;\n\n /**\n * @type {MutationObserver|undefined}\n */\n this._observer = undefined;\n\n\n // Simulate tree construction for all currently accessible nodes in the\n // document.\n this._internals.patchAndUpgradeTree(this._document);\n\n if (this._document.readyState === 'loading') {\n this._observer = new MutationObserver(this._handleMutations.bind(this));\n\n // Nodes created by the parser are given to the observer *before* the next\n // task runs. Inline scripts are run in a new task. This means that the\n // observer will be able to handle the newly parsed nodes before the inline\n // script is run.\n this._observer.observe(this._document, {\n childList: true,\n subtree: true,\n });\n }\n }\n\n disconnect() {\n if (this._observer) {\n this._observer.disconnect();\n }\n }\n\n /**\n * @param {!Array} mutations\n */\n _handleMutations(mutations) {\n // Once the document's `readyState` is 'interactive' or 'complete', all new\n // nodes created within that document will be the result of script and\n // should be handled by patching.\n const readyState = this._document.readyState;\n if (readyState === 'interactive' || readyState === 'complete') {\n this.disconnect();\n }\n\n for (let i = 0; i < mutations.length; i++) {\n const addedNodes = mutations[i].addedNodes;\n for (let j = 0; j < addedNodes.length; j++) {\n const node = addedNodes[j];\n this._internals.patchAndUpgradeTree(node);\n }\n }\n }\n}\n","/**\n * @template T\n */\nexport default class Deferred {\n constructor() {\n /**\n * @private\n * @type {T|undefined}\n */\n this._value = undefined;\n\n /**\n * @private\n * @type {Function|undefined}\n */\n this._resolve = undefined;\n\n /**\n * @private\n * @type {!Promise}\n */\n this._promise = new Promise(resolve => {\n this._resolve = resolve;\n\n if (this._value) {\n resolve(this._value);\n }\n });\n }\n\n /**\n * @param {T} value\n */\n resolve(value) {\n if (this._value) {\n throw new Error('Already resolved.');\n }\n\n this._value = value;\n\n if (this._resolve) {\n this._resolve(value);\n }\n }\n\n /**\n * @return {!Promise}\n */\n toPromise() {\n return this._promise;\n }\n}\n","import CustomElementInternals from './CustomElementInternals.js';\nimport DocumentConstructionObserver from './DocumentConstructionObserver.js';\nimport Deferred from './Deferred.js';\nimport * as Utilities from './Utilities.js';\n\n/**\n * @unrestricted\n */\nexport default class CustomElementRegistry {\n\n /**\n * @param {!CustomElementInternals} internals\n */\n constructor(internals) {\n /**\n * @private\n * @type {boolean}\n */\n this._elementDefinitionIsRunning = false;\n\n /**\n * @private\n * @type {!CustomElementInternals}\n */\n this._internals = internals;\n\n /**\n * @private\n * @type {!Map>}\n */\n this._whenDefinedDeferred = new Map();\n\n /**\n * The default flush callback triggers the document walk synchronously.\n * @private\n * @type {!Function}\n */\n this._flushCallback = fn => fn();\n\n /**\n * @private\n * @type {boolean}\n */\n this._flushPending = false;\n\n /**\n * @private\n * @type {!Array}\n */\n this._unflushedLocalNames = [];\n\n /**\n * @private\n * @type {!DocumentConstructionObserver}\n */\n this._documentConstructionObserver = new DocumentConstructionObserver(internals, document);\n }\n\n /**\n * @param {string} localName\n * @param {!Function} constructor\n */\n define(localName, constructor) {\n if (!(constructor instanceof Function)) {\n throw new TypeError('Custom element constructors must be functions.');\n }\n\n if (!Utilities.isValidCustomElementName(localName)) {\n throw new SyntaxError(`The element name '${localName}' is not valid.`);\n }\n\n if (this._internals.localNameToDefinition(localName)) {\n throw new Error(`A custom element with name '${localName}' has already been defined.`);\n }\n\n if (this._elementDefinitionIsRunning) {\n throw new Error('A custom element is already being defined.');\n }\n this._elementDefinitionIsRunning = true;\n\n let connectedCallback;\n let disconnectedCallback;\n let adoptedCallback;\n let attributeChangedCallback;\n let observedAttributes;\n try {\n /** @type {!Object} */\n const prototype = constructor.prototype;\n if (!(prototype instanceof Object)) {\n throw new TypeError('The custom element constructor\\'s prototype is not an object.');\n }\n\n function getCallback(name) {\n const callbackValue = prototype[name];\n if (callbackValue !== undefined && !(callbackValue instanceof Function)) {\n throw new Error(`The '${name}' callback must be a function.`);\n }\n return callbackValue;\n }\n\n connectedCallback = getCallback('connectedCallback');\n disconnectedCallback = getCallback('disconnectedCallback');\n adoptedCallback = getCallback('adoptedCallback');\n attributeChangedCallback = getCallback('attributeChangedCallback');\n observedAttributes = constructor['observedAttributes'] || [];\n } catch (e) {\n return;\n } finally {\n this._elementDefinitionIsRunning = false;\n }\n\n const definition = {\n localName,\n constructor,\n connectedCallback,\n disconnectedCallback,\n adoptedCallback,\n attributeChangedCallback,\n observedAttributes,\n constructionStack: [],\n };\n\n this._internals.setDefinition(localName, definition);\n\n this._unflushedLocalNames.push(localName);\n\n // If we've already called the flush callback and it hasn't called back yet,\n // don't call it again.\n if (!this._flushPending) {\n this._flushPending = true;\n this._flushCallback(() => this._flush());\n }\n }\n\n _flush() {\n // If no new definitions were defined, don't attempt to flush. This could\n // happen if a flush callback keeps the function it is given and calls it\n // multiple times.\n if (this._flushPending === false) return;\n\n this._flushPending = false;\n this._internals.patchAndUpgradeTree(document);\n\n while (this._unflushedLocalNames.length > 0) {\n const localName = this._unflushedLocalNames.shift();\n const deferred = this._whenDefinedDeferred.get(localName);\n if (deferred) {\n deferred.resolve(undefined);\n }\n }\n }\n\n /**\n * @param {string} localName\n * @return {Function|undefined}\n */\n get(localName) {\n const definition = this._internals.localNameToDefinition(localName);\n if (definition) {\n return definition.constructor;\n }\n\n return undefined;\n }\n\n /**\n * @param {string} localName\n * @return {!Promise}\n */\n whenDefined(localName) {\n if (!Utilities.isValidCustomElementName(localName)) {\n return Promise.reject(new SyntaxError(`'${localName}' is not a valid custom element name.`));\n }\n\n const prior = this._whenDefinedDeferred.get(localName);\n if (prior) {\n return prior.toPromise();\n }\n\n const deferred = new Deferred();\n this._whenDefinedDeferred.set(localName, deferred);\n\n const definition = this._internals.localNameToDefinition(localName);\n // Resolve immediately only if the given local name has a definition *and*\n // the full document walk to upgrade elements with that local name has\n // already happened.\n if (definition && this._unflushedLocalNames.indexOf(localName) === -1) {\n deferred.resolve(undefined);\n }\n\n return deferred.toPromise();\n }\n\n polyfillWrapFlushCallback(outer) {\n this._documentConstructionObserver.disconnect();\n const inner = this._flushCallback;\n this._flushCallback = flush => outer(() => inner(flush));\n }\n}\n\n// Closure compiler exports.\nwindow['CustomElementRegistry'] = CustomElementRegistry;\nCustomElementRegistry.prototype['define'] = CustomElementRegistry.prototype.define;\nCustomElementRegistry.prototype['get'] = CustomElementRegistry.prototype.get;\nCustomElementRegistry.prototype['whenDefined'] = CustomElementRegistry.prototype.whenDefined;\nCustomElementRegistry.prototype['polyfillWrapFlushCallback'] = CustomElementRegistry.prototype.polyfillWrapFlushCallback;\n","export default {\n Document_createElement: window.Document.prototype.createElement,\n Document_createElementNS: window.Document.prototype.createElementNS,\n Document_importNode: window.Document.prototype.importNode,\n Document_prepend: window.Document.prototype['prepend'],\n Document_append: window.Document.prototype['append'],\n Node_cloneNode: window.Node.prototype.cloneNode,\n Node_appendChild: window.Node.prototype.appendChild,\n Node_insertBefore: window.Node.prototype.insertBefore,\n Node_removeChild: window.Node.prototype.removeChild,\n Node_replaceChild: window.Node.prototype.replaceChild,\n Node_textContent: Object.getOwnPropertyDescriptor(window.Node.prototype, 'textContent'),\n Element_attachShadow: window.Element.prototype['attachShadow'],\n Element_innerHTML: Object.getOwnPropertyDescriptor(window.Element.prototype, 'innerHTML'),\n Element_getAttribute: window.Element.prototype.getAttribute,\n Element_setAttribute: window.Element.prototype.setAttribute,\n Element_removeAttribute: window.Element.prototype.removeAttribute,\n Element_getAttributeNS: window.Element.prototype.getAttributeNS,\n Element_setAttributeNS: window.Element.prototype.setAttributeNS,\n Element_removeAttributeNS: window.Element.prototype.removeAttributeNS,\n Element_insertAdjacentElement: window.Element.prototype['insertAdjacentElement'],\n Element_prepend: window.Element.prototype['prepend'],\n Element_append: window.Element.prototype['append'],\n Element_before: window.Element.prototype['before'],\n Element_after: window.Element.prototype['after'],\n Element_replaceWith: window.Element.prototype['replaceWith'],\n Element_remove: window.Element.prototype['remove'],\n HTMLElement: window.HTMLElement,\n HTMLElement_innerHTML: Object.getOwnPropertyDescriptor(window.HTMLElement.prototype, 'innerHTML'),\n HTMLElement_insertAdjacentElement: window.HTMLElement.prototype['insertAdjacentElement'],\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport CEState from '../CustomElementState.js';\nimport AlreadyConstructedMarker from '../AlreadyConstructedMarker.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n window['HTMLElement'] = (function() {\n /**\n * @type {function(new: HTMLElement): !HTMLElement}\n */\n function HTMLElement() {\n // This should really be `new.target` but `new.target` can't be emulated\n // in ES5. Assuming the user keeps the default value of the constructor's\n // prototype's `constructor` property, this is equivalent.\n /** @type {!Function} */\n const constructor = this.constructor;\n\n const definition = internals.constructorToDefinition(constructor);\n if (!definition) {\n throw new Error('The custom element being constructed was not registered with `customElements`.');\n }\n\n const constructionStack = definition.constructionStack;\n\n if (constructionStack.length === 0) {\n const element = Native.Document_createElement.call(document, definition.localName);\n Object.setPrototypeOf(element, constructor.prototype);\n element.__CE_state = CEState.custom;\n element.__CE_definition = definition;\n internals.patch(element);\n return element;\n }\n\n const lastIndex = constructionStack.length - 1;\n const element = constructionStack[lastIndex];\n if (element === AlreadyConstructedMarker) {\n throw new Error('The HTMLElement constructor was either called reentrantly for this constructor or called multiple times.');\n }\n constructionStack[lastIndex] = AlreadyConstructedMarker;\n\n Object.setPrototypeOf(element, constructor.prototype);\n internals.patch(/** @type {!HTMLElement} */ (element));\n\n return element;\n }\n\n HTMLElement.prototype = Native.HTMLElement.prototype;\n\n return HTMLElement;\n })();\n};\n","/**\n * @license\n * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.\n * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\n * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\n * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\n * Code distributed by Google as part of the polymer project is also\n * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n */\n\nimport CustomElementInternals from './CustomElementInternals.js';\nimport CustomElementRegistry from './CustomElementRegistry.js';\n\nimport PatchHTMLElement from './Patch/HTMLElement.js';\nimport PatchDocument from './Patch/Document.js';\nimport PatchNode from './Patch/Node.js';\nimport PatchElement from './Patch/Element.js';\n\nconst priorCustomElements = window['customElements'];\n\nif (!priorCustomElements ||\n priorCustomElements['forcePolyfill'] ||\n (typeof priorCustomElements['define'] != 'function') ||\n (typeof priorCustomElements['get'] != 'function')) {\n /** @type {!CustomElementInternals} */\n const internals = new CustomElementInternals();\n\n PatchHTMLElement(internals);\n PatchDocument(internals);\n PatchNode(internals);\n PatchElement(internals);\n\n // The main document is always associated with the registry.\n document.__CE_hasRegistry = true;\n\n /** @type {!CustomElementRegistry} */\n const customElements = new CustomElementRegistry(internals);\n\n Object.defineProperty(window, 'customElements', {\n configurable: true,\n enumerable: true,\n value: customElements,\n });\n}\n","import CustomElementInternals from '../../CustomElementInternals.js';\nimport * as Utilities from '../../Utilities.js';\n\n/**\n * @typedef {{\n * prepend: !function(...(!Node|string)),\n * append: !function(...(!Node|string)),\n * }}\n */\nlet ParentNodeNativeMethods;\n\n/**\n * @param {!CustomElementInternals} internals\n * @param {!Object} destination\n * @param {!ParentNodeNativeMethods} builtIn\n */\nexport default function(internals, destination, builtIn) {\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['prepend'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.prepend.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['append'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.append.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport * as Utilities from '../Utilities.js';\n\nimport PatchParentNode from './Interface/ParentNode.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n Utilities.setPropertyUnchecked(Document.prototype, 'createElement',\n /**\n * @this {Document}\n * @param {string} localName\n * @return {!Element}\n */\n function(localName) {\n // Only create custom elements if this document is associated with the registry.\n if (this.__CE_hasRegistry) {\n const definition = internals.localNameToDefinition(localName);\n if (definition) {\n return new (definition.constructor)();\n }\n }\n\n const result = /** @type {!Element} */\n (Native.Document_createElement.call(this, localName));\n internals.patch(result);\n return result;\n });\n\n Utilities.setPropertyUnchecked(Document.prototype, 'importNode',\n /**\n * @this {Document}\n * @param {!Node} node\n * @param {boolean=} deep\n * @return {!Node}\n */\n function(node, deep) {\n const clone = Native.Document_importNode.call(this, node, deep);\n // Only create custom elements if this document is associated with the registry.\n if (!this.__CE_hasRegistry) {\n internals.patchTree(clone);\n } else {\n internals.patchAndUpgradeTree(clone);\n }\n return clone;\n });\n\n const NS_HTML = \"http://www.w3.org/1999/xhtml\";\n\n Utilities.setPropertyUnchecked(Document.prototype, 'createElementNS',\n /**\n * @this {Document}\n * @param {?string} namespace\n * @param {string} localName\n * @return {!Element}\n */\n function(namespace, localName) {\n // Only create custom elements if this document is associated with the registry.\n if (this.__CE_hasRegistry && (namespace === null || namespace === NS_HTML)) {\n const definition = internals.localNameToDefinition(localName);\n if (definition) {\n return new (definition.constructor)();\n }\n }\n\n const result = /** @type {!Element} */\n (Native.Document_createElementNS.call(this, namespace, localName));\n internals.patch(result);\n return result;\n });\n\n PatchParentNode(internals, Document.prototype, {\n prepend: Native.Document_prepend,\n append: Native.Document_append,\n });\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport * as Utilities from '../Utilities.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n // `Node#nodeValue` is implemented on `Attr`.\n // `Node#textContent` is implemented on `Attr`, `Element`.\n\n Utilities.setPropertyUnchecked(Node.prototype, 'insertBefore',\n /**\n * @this {Node}\n * @param {!Node} node\n * @param {?Node} refNode\n * @return {!Node}\n */\n function(node, refNode) {\n if (node instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(node.childNodes);\n const nativeResult = Native.Node_insertBefore.call(this, node, refNode);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_insertBefore.call(this, node, refNode);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n if (Utilities.isConnected(this)) {\n internals.connectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'appendChild',\n /**\n * @this {Node}\n * @param {!Node} node\n * @return {!Node}\n */\n function(node) {\n if (node instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(node.childNodes);\n const nativeResult = Native.Node_appendChild.call(this, node);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_appendChild.call(this, node);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n if (Utilities.isConnected(this)) {\n internals.connectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'cloneNode',\n /**\n * @this {Node}\n * @param {boolean=} deep\n * @return {!Node}\n */\n function(deep) {\n const clone = Native.Node_cloneNode.call(this, deep);\n // Only create custom elements if this element's owner document is\n // associated with the registry.\n if (!this.ownerDocument.__CE_hasRegistry) {\n internals.patchTree(clone);\n } else {\n internals.patchAndUpgradeTree(clone);\n }\n return clone;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'removeChild',\n /**\n * @this {Node}\n * @param {!Node} node\n * @return {!Node}\n */\n function(node) {\n const nodeWasConnected = Utilities.isConnected(node);\n const nativeResult = Native.Node_removeChild.call(this, node);\n\n if (nodeWasConnected) {\n internals.disconnectTree(node);\n }\n\n return nativeResult;\n });\n\n Utilities.setPropertyUnchecked(Node.prototype, 'replaceChild',\n /**\n * @this {Node}\n * @param {!Node} nodeToInsert\n * @param {!Node} nodeToRemove\n * @return {!Node}\n */\n function(nodeToInsert, nodeToRemove) {\n if (nodeToInsert instanceof DocumentFragment) {\n const insertedNodes = Array.prototype.slice.apply(nodeToInsert.childNodes);\n const nativeResult = Native.Node_replaceChild.call(this, nodeToInsert, nodeToRemove);\n\n // DocumentFragments can't be connected, so `disconnectTree` will never\n // need to be called on a DocumentFragment's children after inserting it.\n\n if (Utilities.isConnected(this)) {\n internals.disconnectTree(nodeToRemove);\n for (let i = 0; i < insertedNodes.length; i++) {\n internals.connectTree(insertedNodes[i]);\n }\n }\n\n return nativeResult;\n }\n\n const nodeToInsertWasConnected = Utilities.isConnected(nodeToInsert);\n const nativeResult = Native.Node_replaceChild.call(this, nodeToInsert, nodeToRemove);\n const thisIsConnected = Utilities.isConnected(this);\n\n if (thisIsConnected) {\n internals.disconnectTree(nodeToRemove);\n }\n\n if (nodeToInsertWasConnected) {\n internals.disconnectTree(nodeToInsert);\n }\n\n if (thisIsConnected) {\n internals.connectTree(nodeToInsert);\n }\n\n return nativeResult;\n });\n\n\n function patch_textContent(destination, baseDescriptor) {\n Object.defineProperty(destination, 'textContent', {\n enumerable: baseDescriptor.enumerable,\n configurable: true,\n get: baseDescriptor.get,\n set: /** @this {Node} */ function(assignedValue) {\n // If this is a text node then there are no nodes to disconnect.\n if (this.nodeType === Node.TEXT_NODE) {\n baseDescriptor.set.call(this, assignedValue);\n return;\n }\n\n let removedNodes = undefined;\n // Checking for `firstChild` is faster than reading `childNodes.length`\n // to compare with 0.\n if (this.firstChild) {\n // Using `childNodes` is faster than `children`, even though we only\n // care about elements.\n const childNodes = this.childNodes;\n const childNodesLength = childNodes.length;\n if (childNodesLength > 0 && Utilities.isConnected(this)) {\n // Copying an array by iterating is faster than using slice.\n removedNodes = new Array(childNodesLength);\n for (let i = 0; i < childNodesLength; i++) {\n removedNodes[i] = childNodes[i];\n }\n }\n }\n\n baseDescriptor.set.call(this, assignedValue);\n\n if (removedNodes) {\n for (let i = 0; i < removedNodes.length; i++) {\n internals.disconnectTree(removedNodes[i]);\n }\n }\n },\n });\n }\n\n if (Native.Node_textContent && Native.Node_textContent.get) {\n patch_textContent(Node.prototype, Native.Node_textContent);\n } else {\n internals.addPatch(function(element) {\n patch_textContent(element, {\n enumerable: true,\n configurable: true,\n // NOTE: This implementation of the `textContent` getter assumes that\n // text nodes' `textContent` getter will not be patched.\n get: /** @this {Node} */ function() {\n /** @type {!Array} */\n const parts = [];\n\n for (let i = 0; i < this.childNodes.length; i++) {\n parts.push(this.childNodes[i].textContent);\n }\n\n return parts.join('');\n },\n set: /** @this {Node} */ function(assignedValue) {\n while (this.firstChild) {\n Native.Node_removeChild.call(this, this.firstChild);\n }\n Native.Node_appendChild.call(this, document.createTextNode(assignedValue));\n },\n });\n });\n }\n};\n","import CustomElementInternals from '../../CustomElementInternals.js';\nimport * as Utilities from '../../Utilities.js';\n\n/**\n * @typedef {{\n * before: !function(...(!Node|string)),\n * after: !function(...(!Node|string)),\n * replaceWith: !function(...(!Node|string)),\n * remove: !function(),\n * }}\n */\nlet ChildNodeNativeMethods;\n\n/**\n * @param {!CustomElementInternals} internals\n * @param {!Object} destination\n * @param {!ChildNodeNativeMethods} builtIn\n */\nexport default function(internals, destination, builtIn) {\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['before'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.before.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['after'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n builtIn.after.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (Utilities.isConnected(this)) {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n /**\n * @param {...(!Node|string)} nodes\n */\n destination['replaceWith'] = function(...nodes) {\n // TODO: Fix this for when one of `nodes` is a DocumentFragment!\n const connectedBefore = /** @type {!Array} */ (nodes.filter(node => {\n // DocumentFragments are not connected and will not be added to the list.\n return node instanceof Node && Utilities.isConnected(node);\n }));\n\n const wasConnected = Utilities.isConnected(this);\n\n builtIn.replaceWith.apply(this, nodes);\n\n for (let i = 0; i < connectedBefore.length; i++) {\n internals.disconnectTree(connectedBefore[i]);\n }\n\n if (wasConnected) {\n internals.disconnectTree(this);\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if (node instanceof Element) {\n internals.connectTree(node);\n }\n }\n }\n };\n\n destination['remove'] = function() {\n const wasConnected = Utilities.isConnected(this);\n\n builtIn.remove.call(this);\n\n if (wasConnected) {\n internals.disconnectTree(this);\n }\n };\n};\n","import Native from './Native.js';\nimport CustomElementInternals from '../CustomElementInternals.js';\nimport CEState from '../CustomElementState.js';\nimport * as Utilities from '../Utilities.js';\n\nimport PatchParentNode from './Interface/ParentNode.js';\nimport PatchChildNode from './Interface/ChildNode.js';\n\n/**\n * @param {!CustomElementInternals} internals\n */\nexport default function(internals) {\n if (Native.Element_attachShadow) {\n Utilities.setPropertyUnchecked(Element.prototype, 'attachShadow',\n /**\n * @this {Element}\n * @param {!{mode: string}} init\n * @return {ShadowRoot}\n */\n function(init) {\n const shadowRoot = Native.Element_attachShadow.call(this, init);\n this.__CE_shadowRoot = shadowRoot;\n return shadowRoot;\n });\n } else {\n console.warn('Custom Elements: `Element#attachShadow` was not patched.');\n }\n\n\n function patch_innerHTML(destination, baseDescriptor) {\n Object.defineProperty(destination, 'innerHTML', {\n enumerable: baseDescriptor.enumerable,\n configurable: true,\n get: baseDescriptor.get,\n set: /** @this {Element} */ function(htmlString) {\n const isConnected = Utilities.isConnected(this);\n\n // NOTE: In IE11, when using the native `innerHTML` setter, all nodes\n // that were previously descendants of the context element have all of\n // their children removed as part of the set - the entire subtree is\n // 'disassembled'. This work around walks the subtree *before* using the\n // native setter.\n /** @type {!Array|undefined} */\n let removedElements = undefined;\n if (isConnected) {\n removedElements = [];\n Utilities.walkDeepDescendantElements(this, element => {\n if (element !== this) {\n removedElements.push(element);\n }\n });\n }\n\n baseDescriptor.set.call(this, htmlString);\n\n if (removedElements) {\n for (let i = 0; i < removedElements.length; i++) {\n const element = removedElements[i];\n if (element.__CE_state === CEState.custom) {\n internals.disconnectedCallback(element);\n }\n }\n }\n\n // Only create custom elements if this element's owner document is\n // associated with the registry.\n if (!this.ownerDocument.__CE_hasRegistry) {\n internals.patchTree(this);\n } else {\n internals.patchAndUpgradeTree(this);\n }\n return htmlString;\n },\n });\n }\n\n if (Native.Element_innerHTML && Native.Element_innerHTML.get) {\n patch_innerHTML(Element.prototype, Native.Element_innerHTML);\n } else if (Native.HTMLElement_innerHTML && Native.HTMLElement_innerHTML.get) {\n patch_innerHTML(HTMLElement.prototype, Native.HTMLElement_innerHTML);\n } else {\n\n /** @type {HTMLDivElement} */\n const rawDiv = Native.Document_createElement.call(document, 'div');\n\n internals.addPatch(function(element) {\n patch_innerHTML(element, {\n enumerable: true,\n configurable: true,\n // Implements getting `innerHTML` by performing an unpatched `cloneNode`\n // of the element and returning the resulting element's `innerHTML`.\n // TODO: Is this too expensive?\n get: /** @this {Element} */ function() {\n return Native.Node_cloneNode.call(this, true).innerHTML;\n },\n // Implements setting `innerHTML` by creating an unpatched element,\n // setting `innerHTML` of that element and replacing the target\n // element's children with those of the unpatched element.\n set: /** @this {Element} */ function(assignedValue) {\n // NOTE: re-route to `content` for `template` elements.\n // We need to do this because `template.appendChild` does not\n // route into `template.content`.\n /** @type {!Node} */\n const content = this.localName === 'template' ? (/** @type {!HTMLTemplateElement} */ (this)).content : this;\n rawDiv.innerHTML = assignedValue;\n\n while (content.childNodes.length > 0) {\n Native.Node_removeChild.call(content, content.childNodes[0]);\n }\n while (rawDiv.childNodes.length > 0) {\n Native.Node_appendChild.call(content, rawDiv.childNodes[0]);\n }\n },\n });\n });\n }\n\n\n Utilities.setPropertyUnchecked(Element.prototype, 'setAttribute',\n /**\n * @this {Element}\n * @param {string} name\n * @param {string} newValue\n */\n function(name, newValue) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_setAttribute.call(this, name, newValue);\n }\n\n const oldValue = Native.Element_getAttribute.call(this, name);\n Native.Element_setAttribute.call(this, name, newValue);\n newValue = Native.Element_getAttribute.call(this, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, null);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'setAttributeNS',\n /**\n * @this {Element}\n * @param {?string} namespace\n * @param {string} name\n * @param {string} newValue\n */\n function(namespace, name, newValue) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_setAttributeNS.call(this, namespace, name, newValue);\n }\n\n const oldValue = Native.Element_getAttributeNS.call(this, namespace, name);\n Native.Element_setAttributeNS.call(this, namespace, name, newValue);\n newValue = Native.Element_getAttributeNS.call(this, namespace, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, namespace);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'removeAttribute',\n /**\n * @this {Element}\n * @param {string} name\n */\n function(name) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_removeAttribute.call(this, name);\n }\n\n const oldValue = Native.Element_getAttribute.call(this, name);\n Native.Element_removeAttribute.call(this, name);\n if (oldValue !== null) {\n internals.attributeChangedCallback(this, name, oldValue, null, null);\n }\n });\n\n Utilities.setPropertyUnchecked(Element.prototype, 'removeAttributeNS',\n /**\n * @this {Element}\n * @param {?string} namespace\n * @param {string} name\n */\n function(namespace, name) {\n // Fast path for non-custom elements.\n if (this.__CE_state !== CEState.custom) {\n return Native.Element_removeAttributeNS.call(this, namespace, name);\n }\n\n const oldValue = Native.Element_getAttributeNS.call(this, namespace, name);\n Native.Element_removeAttributeNS.call(this, namespace, name);\n // In older browsers, `Element#getAttributeNS` may return the empty string\n // instead of null if the attribute does not exist. For details, see;\n // https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttributeNS#Notes\n const newValue = Native.Element_getAttributeNS.call(this, namespace, name);\n if (oldValue !== newValue) {\n internals.attributeChangedCallback(this, name, oldValue, newValue, namespace);\n }\n });\n\n\n function patch_insertAdjacentElement(destination, baseMethod) {\n Utilities.setPropertyUnchecked(destination, 'insertAdjacentElement',\n /**\n * @this {Element}\n * @param {string} where\n * @param {!Element} element\n * @return {?Element}\n */\n function(where, element) {\n const wasConnected = Utilities.isConnected(element);\n const insertedElement = /** @type {!Element} */\n (baseMethod.call(this, where, element));\n\n if (wasConnected) {\n internals.disconnectTree(element);\n }\n\n if (Utilities.isConnected(insertedElement)) {\n internals.connectTree(element);\n }\n return insertedElement;\n });\n }\n\n if (Native.HTMLElement_insertAdjacentElement) {\n patch_insertAdjacentElement(HTMLElement.prototype, Native.HTMLElement_insertAdjacentElement);\n } else if (Native.Element_insertAdjacentElement) {\n patch_insertAdjacentElement(Element.prototype, Native.Element_insertAdjacentElement);\n } else {\n console.warn('Custom Elements: `Element#insertAdjacentElement` was not patched.');\n }\n\n\n PatchParentNode(internals, Element.prototype, {\n prepend: Native.Element_prepend,\n append: Native.Element_append,\n });\n\n PatchChildNode(internals, Element.prototype, {\n before: Native.Element_before,\n after: Native.Element_after,\n replaceWith: Native.Element_replaceWith,\n remove: Native.Element_remove,\n });\n};\n"]} \ No newline at end of file From acd7b88d0ffb0e83ce254a8fb0ace03077b58a99 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Fri, 31 Mar 2017 18:15:13 -0600 Subject: [PATCH 04/10] Tabs -> spaces --- src/CustomElementInternals.js | 2 +- src/Patch/Document.js | 10 +-- src/custom-elements.js | 2 +- tests/js/babel.js | 84 ++++++++++---------- tests/js/instanceof.js | 22 +++--- tests/js/reactions.js | 144 +++++++++++++++++----------------- tests/js/upgrade.js | 8 +- 7 files changed, 136 insertions(+), 136 deletions(-) diff --git a/src/CustomElementInternals.js b/src/CustomElementInternals.js index ab19db5..c4267df 100644 --- a/src/CustomElementInternals.js +++ b/src/CustomElementInternals.js @@ -252,7 +252,7 @@ export default class CustomElementInternals { */ upgradeElement(element) { const currentState = element.__CE_state; - if (currentState !== undefined) return; + if (currentState !== undefined) return; const definition = this.nodeToDefinition(element); if (!definition) return; diff --git a/src/Patch/Document.js b/src/Patch/Document.js index a98177f..36f1d4e 100644 --- a/src/Patch/Document.js +++ b/src/Patch/Document.js @@ -17,7 +17,7 @@ export default function(internals) { function(localName, options) { // Only create custom elements if this document is associated with the registry. if (this.__CE_hasRegistry) { - const name = options && options.is ? options.is : localName; + const name = options && options.is ? options.is : localName; const definition = internals.nameToDefinition(name); if (definition) { return new (definition.constructor)(); @@ -26,9 +26,9 @@ export default function(internals) { const result = /** @type {!Element} */ (Native.Document_createElement.call(this, localName)); - if (options && options.is) { - result.__CE_is = options.is; - } + if (options && options.is) { + result.__CE_is = options.is; + } internals.patch(result); return result; }); @@ -63,7 +63,7 @@ export default function(internals) { function(namespace, localName, options) { // Only create custom elements if this document is associated with the registry. if (this.__CE_hasRegistry && (namespace === null || namespace === NS_HTML)) { - const name = options && options.is ? options.is : localName; + const name = options && options.is ? options.is : localName; const definition = internals.nameToDefinition(name); if (definition) { return new (definition.constructor)(); diff --git a/src/custom-elements.js b/src/custom-elements.js index 249b217..1856edb 100644 --- a/src/custom-elements.js +++ b/src/custom-elements.js @@ -27,7 +27,7 @@ if (!priorCustomElements || const internals = new CustomElementInternals(); PatchHTMLElement(internals); - PatchHTMLElementSubclasses(internals); + PatchHTMLElementSubclasses(internals); PatchDocument(internals); PatchNode(internals); PatchElement(internals); diff --git a/tests/js/babel.js b/tests/js/babel.js index 8a41cc1..9ed8597 100644 --- a/tests/js/babel.js +++ b/tests/js/babel.js @@ -43,37 +43,37 @@ suite('Babel ES5 Output', function() { assert.instanceOf(e, XBabel); }); - test('Babel generated ES5 works via new() when extending builtin HTML Elements', function() { - "use strict"; + test('Babel generated ES5 works via new() when extending builtin HTML Elements', function() { + "use strict"; - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - var XBabelBuiltin = function (_HTMLButtonElement) { - _inherits(XBabelBuiltin, _HTMLButtonElement); + var XBabelBuiltin = function (_HTMLButtonElement) { + _inherits(XBabelBuiltin, _HTMLButtonElement); - function XBabelBuiltin() { - _classCallCheck(this, XBabelBuiltin); + function XBabelBuiltin() { + _classCallCheck(this, XBabelBuiltin); - return _possibleConstructorReturn(this, (XBabelBuiltin.__proto__ || Object.getPrototypeOf(XBabelBuiltin)).call(this)); - } + return _possibleConstructorReturn(this, (XBabelBuiltin.__proto__ || Object.getPrototypeOf(XBabelBuiltin)).call(this)); + } - return XBabelBuiltin; - }(HTMLButtonElement); + return XBabelBuiltin; + }(HTMLButtonElement); - // register x-foo - customElements.define('x-babel-builtin', XBabelBuiltin, {extends: 'button'}); - // create an instance via new - var e = new XBabelBuiltin(); - // test localName - assert.equal(e.localName, 'button'); - // test instanceof - assert.instanceOf(e, XBabelBuiltin); - assert.instanceOf(e, HTMLButtonElement); - }); + // register x-foo + customElements.define('x-babel-builtin', XBabelBuiltin, {extends: 'button'}); + // create an instance via new + var e = new XBabelBuiltin(); + // test localName + assert.equal(e.localName, 'button'); + // test instanceof + assert.instanceOf(e, XBabelBuiltin); + assert.instanceOf(e, HTMLButtonElement); + }); test('Babel generated ES5 works via createElement', function() { 'use strict'; @@ -106,32 +106,32 @@ suite('Babel ES5 Output', function() { assert.instanceOf(e, XBabel2); }); - test('Babel generated ES5 works via createElement for customized builtins', function() { - "use strict"; + test('Babel generated ES5 works via createElement for customized builtins', function() { + "use strict"; - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - var XBabel2Builtin = function (_HTMLButtonElement) { - _inherits(XBabel2Builtin, _HTMLButtonElement); + var XBabel2Builtin = function (_HTMLButtonElement) { + _inherits(XBabel2Builtin, _HTMLButtonElement); - function XBabel2Builtin() { - _classCallCheck(this, XBabel2Builtin); + function XBabel2Builtin() { + _classCallCheck(this, XBabel2Builtin); - return _possibleConstructorReturn(this, (XBabel2Builtin.__proto__ || Object.getPrototypeOf(XBabel2Builtin)).call(this)); - } + return _possibleConstructorReturn(this, (XBabel2Builtin.__proto__ || Object.getPrototypeOf(XBabel2Builtin)).call(this)); + } - return XBabel2Builtin; - }(HTMLButtonElement); + return XBabel2Builtin; + }(HTMLButtonElement); - customElements.define('x-babel2-builtin', XBabel2Builtin, {extends: 'button'}); - var e = document.createElement('button', {is: 'x-babel2-builtin'}); - assert.equal(e.localName, 'button'); - assert.instanceOf(e, XBabel2Builtin); - assert.instanceOf(e, HTMLButtonElement); - }); + customElements.define('x-babel2-builtin', XBabel2Builtin, {extends: 'button'}); + var e = document.createElement('button', {is: 'x-babel2-builtin'}); + assert.equal(e.localName, 'button'); + assert.instanceOf(e, XBabel2Builtin); + assert.instanceOf(e, HTMLButtonElement); + }); }); diff --git a/tests/js/instanceof.js b/tests/js/instanceof.js index 86aee1f..a0c2577 100644 --- a/tests/js/instanceof.js +++ b/tests/js/instanceof.js @@ -140,18 +140,18 @@ suite('Built-in Element instanceof', function() { }); - test('customized builtins are instance of the native elements they extend', function () { - class XInstanceofBuiltin extends HTMLStyleElement { - } - customElements.define('x-instanceof-builtin', XInstanceofBuiltin, {extends: 'style'}); + test('customized builtins are instance of the native elements they extend', function () { + class XInstanceofBuiltin extends HTMLStyleElement { + } + customElements.define('x-instanceof-builtin', XInstanceofBuiltin, {extends: 'style'}); - var el = new XInstanceofBuiltin(); - assert.isTrue(el instanceof XInstanceofBuiltin); - assert.isTrue(el instanceof HTMLStyleElement); + var el = new XInstanceofBuiltin(); + assert.isTrue(el instanceof XInstanceofBuiltin); + assert.isTrue(el instanceof HTMLStyleElement); - el = document.createElement('style', {is: 'x-instanceof-builtin'}); - assert.isTrue(el instanceof HTMLStyleElement); - assert.isTrue(el instanceof XInstanceofBuiltin); - }); + el = document.createElement('style', {is: 'x-instanceof-builtin'}); + assert.isTrue(el instanceof HTMLStyleElement); + assert.isTrue(el instanceof XInstanceofBuiltin); + }); }); diff --git a/tests/js/reactions.js b/tests/js/reactions.js index 0d260f8..833c6fb 100644 --- a/tests/js/reactions.js +++ b/tests/js/reactions.js @@ -91,22 +91,22 @@ suite('Custom Element Reactions', function() { assert.isTrue(pass); }); - test('constructor is called on customized builtins when instantiated via createElement', function() { - var pass = false; - class XFoo2Builtin extends HTMLButtonElement { - constructor() { - super(); - pass = true; - } - } - customElements.define('x-foo2-builtin', XFoo2Builtin, {extends: 'button'}); - - var el = document.createElement('button', {is: 'x-foo2-builtin'}); - assert.equal(el.localName, 'button'); - assert.instanceOf(el, XFoo2Builtin); - assert.instanceOf(el, HTMLButtonElement); - assert.isTrue(pass); - }); + test('constructor is called on customized builtins when instantiated via createElement', function() { + var pass = false; + class XFoo2Builtin extends HTMLButtonElement { + constructor() { + super(); + pass = true; + } + } + customElements.define('x-foo2-builtin', XFoo2Builtin, {extends: 'button'}); + + var el = document.createElement('button', {is: 'x-foo2-builtin'}); + assert.equal(el.localName, 'button'); + assert.instanceOf(el, XFoo2Builtin); + assert.instanceOf(el, HTMLButtonElement); + assert.isTrue(pass); + }); test('subclass constructor is called when instantiated via createElement', function() { class XSuper2 extends HTMLElement {} @@ -305,15 +305,15 @@ suite('Custom Element Reactions', function() { } attributeChangedCallback(inName, inOldValue) { - if (inName === 'foo' && inOldValue === 'bar' && this.attributes.foo.value === 'zot') { - done(); - } + if (inName === 'foo' && inOldValue === 'bar' && this.attributes.foo.value === 'zot') { + done(); + } } } - customElements.define('x-boo-builtin', XBooBuiltin, {extends: 'input'}); - var xbooBuiltin = new XBooBuiltin(); - xbooBuiltin.setAttribute('foo', 'bar'); - xbooBuiltin.setAttribute('foo', 'zot'); + customElements.define('x-boo-builtin', XBooBuiltin, {extends: 'input'}); + var xbooBuiltin = new XBooBuiltin(); + xbooBuiltin.setAttribute('foo', 'bar'); + xbooBuiltin.setAttribute('foo', 'zot'); }); test('called for existing observed attributes', function () { @@ -358,24 +358,24 @@ suite('Custom Element Reactions', function() { } customElements.define('x-connected', XConnected); - class XConnectedBuiltin extends HTMLButtonElement { - connectedCallback() { - builtinConnectedCount++; - } - } - customElements.define('x-connected-builtin', XConnectedBuiltin, {extends: 'button'}); + class XConnectedBuiltin extends HTMLButtonElement { + connectedCallback() { + builtinConnectedCount++; + } + } + customElements.define('x-connected-builtin', XConnectedBuiltin, {extends: 'button'}); setup(function() { connectedCount = 0; - builtinConnectedCount = 0; + builtinConnectedCount = 0; }); test('is not called for disconnected custom elements', function() { new XConnected(); assert.equal(connectedCount, 0); - new XConnectedBuiltin(); - assert.equal(builtinConnectedCount, 0); + new XConnectedBuiltin(); + assert.equal(builtinConnectedCount, 0); }); test('is not called for deeply disconnected custom elements', function() { @@ -384,18 +384,18 @@ suite('Custom Element Reactions', function() { parent.appendChild(child); assert.equal(connectedCount, 0); - parent = new XConnectedBuiltin(); - child = new XConnectedBuiltin(); - parent.appendChild(child); - assert.equal(builtinConnectedCount, 0); + parent = new XConnectedBuiltin(); + child = new XConnectedBuiltin(); + parent.appendChild(child); + assert.equal(builtinConnectedCount, 0); }); test('called when appended to main document', function() { work.appendChild(new XConnected()); assert.equal(connectedCount, 1); - work.appendChild(new XConnectedBuiltin()); - assert.equal(builtinConnectedCount, 1); + work.appendChild(new XConnectedBuiltin()); + assert.equal(builtinConnectedCount, 1); }); test('called when re-appended to main document', function() { @@ -405,11 +405,11 @@ suite('Custom Element Reactions', function() { work.appendChild(el); assert.equal(connectedCount, 2); - el = new XConnectedBuiltin(); - work.appendChild(el); - work.removeChild(el); - work.appendChild(el); - assert.equal(builtinConnectedCount, 2); + el = new XConnectedBuiltin(); + work.appendChild(el); + work.removeChild(el); + work.appendChild(el); + assert.equal(builtinConnectedCount, 2); }); test('called in tree order', function() { @@ -421,14 +421,14 @@ suite('Custom Element Reactions', function() { } } - class XOrderingBuiltin extends HTMLDivElement { - connectedCallback() { - log.push(this.id); - } - } + class XOrderingBuiltin extends HTMLDivElement { + connectedCallback() { + log.push(this.id); + } + } customElements.define('x-ordering', XOrdering); - customElements.define('x-ordering-builtin', XOrderingBuiltin, {extends: 'div'}); + customElements.define('x-ordering-builtin', XOrderingBuiltin, {extends: 'div'}); work.innerHTML = '' + @@ -436,7 +436,7 @@ suite('Custom Element Reactions', function() { '' + '' + '' + - '
' + + '
' + '
' + '
'; @@ -475,21 +475,21 @@ suite('Custom Element Reactions', function() { assert(removed, 'removed must be true [XBooBoo]'); }); - test('called on customized builtins when disconnected from main document', function() { - var removed = false; - class XZotBuiltin extends HTMLBRElement { - disconnectedCallback() { - removed = true; - } - } - customElements.define('x-zot-builtin', XZotBuiltin, {extends: 'br'}); - var xZotBuiltin = new XZotBuiltin(); - assert(!removed, 'XZotBuiltin shouldn\'t be removed before even connected'); - work.appendChild(xZotBuiltin); - assert(!removed, 'XZotBuiltin shouldn\'t be removed when it is connected'); - work.removeChild(xZotBuiltin); - assert(removed, 'XZotBuiltin should be removed when disconnected from dom'); - }); + test('called on customized builtins when disconnected from main document', function() { + var removed = false; + class XZotBuiltin extends HTMLBRElement { + disconnectedCallback() { + removed = true; + } + } + customElements.define('x-zot-builtin', XZotBuiltin, {extends: 'br'}); + var xZotBuiltin = new XZotBuiltin(); + assert(!removed, 'XZotBuiltin shouldn\'t be removed before even connected'); + work.appendChild(xZotBuiltin); + assert(!removed, 'XZotBuiltin shouldn\'t be removed when it is connected'); + work.removeChild(xZotBuiltin); + assert(removed, 'XZotBuiltin should be removed when disconnected from dom'); + }); test('called in tree order', function() { var log = []; @@ -500,12 +500,12 @@ suite('Custom Element Reactions', function() { } customElements.define('x-ordering2', XOrdering2); - class XOrdering2Builtin extends HTMLTitleElement { - disconnectedCallback() { - log.push(this.id) - } - } - customElements.define('x-ordering2-builtin', XOrdering2Builtin, {extends: 'div'}); + class XOrdering2Builtin extends HTMLTitleElement { + disconnectedCallback() { + log.push(this.id) + } + } + customElements.define('x-ordering2-builtin', XOrdering2Builtin, {extends: 'div'}); work.innerHTML = '' + @@ -513,7 +513,7 @@ suite('Custom Element Reactions', function() { '' + '' + '' + - '
' + + '
' + '
' + '
'; diff --git a/tests/js/upgrade.js b/tests/js/upgrade.js index 4fd653e..bc72f9c 100644 --- a/tests/js/upgrade.js +++ b/tests/js/upgrade.js @@ -48,21 +48,21 @@ suite('Upgrades', function() { class X1 extends HTMLElement {} class X2 extends HTMLElement {} - class XDisconnectedBuiltin1 extends HTMLSpanElement {} + class XDisconnectedBuiltin1 extends HTMLSpanElement {} customElements.define('x-disconnected-1', X1); customElements.define('x-disconnected-2', X2); - customElements.define('x-disconnected-builtin-1', XDisconnectedBuiltin1, {extends: 'span'}); + customElements.define('x-disconnected-builtin-1', XDisconnectedBuiltin1, {extends: 'span'}); // disconnected elements should not be upgraded assert.notInstanceOf(e1, X1); assert.notInstanceOf(e2, X2); - assert.notInstanceOf(e3, XDisconnectedBuiltin1); + assert.notInstanceOf(e3, XDisconnectedBuiltin1); // they should upgrade when connected work.appendChild(e1); assert.instanceOf(e1, X1); assert.instanceOf(e2, X2); - assert.instanceOf(e3, XDisconnectedBuiltin1); + assert.instanceOf(e3, XDisconnectedBuiltin1); }); }); From 673c2694231eac4837d6f860960017e30e2223c9 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Fri, 31 Mar 2017 18:32:50 -0600 Subject: [PATCH 05/10] Putting builtins behind flag --- src/CustomElementRegistry.js | 4 ++++ src/custom-elements.js | 1 + tests/index.html | 1 + tests/js/registry.js | 40 +++++++++++++++++++++++------------- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/CustomElementRegistry.js b/src/CustomElementRegistry.js index 3933a48..2b4e8ed 100644 --- a/src/CustomElementRegistry.js +++ b/src/CustomElementRegistry.js @@ -76,6 +76,10 @@ export default class CustomElementRegistry { let localName = name; if (options && options.extends) { + if (!this.enableCustomizedBuiltins) { + throw new Error(`Customized builtin elements are disabled by default. Set customElements.enableCustomizedBuiltins = true.`); + } + if (Utilities.isValidCustomElementName(options.extends)) { throw new Error(`A customized builtin element may not extend a custom element.`); } diff --git a/src/custom-elements.js b/src/custom-elements.js index 1856edb..40bbee5 100644 --- a/src/custom-elements.js +++ b/src/custom-elements.js @@ -37,6 +37,7 @@ if (!priorCustomElements || /** @type {!CustomElementRegistry} */ const customElements = new CustomElementRegistry(internals); + customElements.enableCustomizedBuiltins = priorCustomElements.enableCustomizedBuiltins; Object.defineProperty(window, 'customElements', { configurable: true, diff --git a/tests/index.html b/tests/index.html index 681b9b9..d52c96d 100644 --- a/tests/index.html +++ b/tests/index.html @@ -12,6 +12,7 @@ diff --git a/tests/js/registry.js b/tests/js/registry.js index 80a3a33..888fc10 100644 --- a/tests/js/registry.js +++ b/tests/js/registry.js @@ -77,12 +77,24 @@ suite('CustomElementsRegistry', function() { }, '', 'customElements.define failed to throw with a constructor argument with no prototype'); }); - test('second argument with an invalid extends property', function() { - class XInvalidExtends extends HTMLInputElement {} - assert.throws(function() { - customElements.define('x-invalid-extends', XInvalidExtends, {extends: new Date()}); - }, '', 'customElements.define failed to throw with an invalid extends option'); - }); + test('second argument with an invalid extends property', function() { + class XInvalidExtends extends HTMLInputElement {} + assert.throws(function() { + customElements.define('x-invalid-extends', XInvalidExtends, {extends: new Date()}); + }, '', 'customElements.define failed to throw with an invalid extends option'); + }); + + test('throws an error if a customized builtin is defined but the feature flag is off', function() { + class XBuiltinNotEnabled extends HTMLButtonElement {} + + customElements.enableCustomizedBuiltins = false; + + assert.throws(function() { + customElements.define('x-builtin-not-enabled', XBuiltinNotEnabled, {extends: 'button'}); + }, '', 'customElements.define failed to throw when enableCustomizedBuiltins is falsy'); + + customElements.enableCustomizedBuiltins = true; + }); }); suite('get', function() { @@ -97,14 +109,14 @@ suite('CustomElementsRegistry', function() { assert.isUndefined(customElements.get('x-undefined')); }); - test('returns a defined constructor for a customized builtin element', function () { - class XGetBuiltin extends HTMLLinkElement {} - customElements.define('x-get-builtin', XGetBuiltin, {extends: 'link'}); - // Customized builtin elements should be retrievable from the registry - assert.equal(XGetBuiltin, customElements.get('x-get-builtin')); - // The element being extended cannot be retrieved from the registry - assert.isUndefined(customElements.get('link')); - }); + test('returns a defined constructor for a customized builtin element', function () { + class XGetBuiltin extends HTMLLinkElement {} + customElements.define('x-get-builtin', XGetBuiltin, {extends: 'link'}); + // Customized builtin elements should be retrievable from the registry + assert.equal(XGetBuiltin, customElements.get('x-get-builtin')); + // The element being extended cannot be retrieved from the registry + assert.isUndefined(customElements.get('link')); + }); }); From c02b1c180acb1e9a919bf42f68b5f9aec26e9bb8 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Fri, 31 Mar 2017 18:33:19 -0600 Subject: [PATCH 06/10] Tabs -> spaces --- src/CustomElementInternals.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CustomElementInternals.js b/src/CustomElementInternals.js index c4267df..129c245 100644 --- a/src/CustomElementInternals.js +++ b/src/CustomElementInternals.js @@ -226,7 +226,7 @@ export default class CustomElementInternals { element.__CE_is = element.getAttribute('is') || element.is; element.removeAttribute('is'); delete element.is; - elements.push(element); + elements.push(element); } else { elements.push(element); } From 881ce96fb0cd8bb975fc79a33e896ff30de748dc Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Fri, 31 Mar 2017 18:48:18 -0600 Subject: [PATCH 07/10] Self review --- src/Patch/Document.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Patch/Document.js b/src/Patch/Document.js index 36f1d4e..f4a4e59 100644 --- a/src/Patch/Document.js +++ b/src/Patch/Document.js @@ -8,7 +8,7 @@ import PatchParentNode from './Interface/ParentNode.js'; * @param {!CustomElementInternals} internals */ export default function(internals) { - Utilities.setPropertyUnchecked(document, 'createElement', + Utilities.setPropertyUnchecked(Document.prototype, 'createElement', /** * @this {Document} * @param {string} localName @@ -53,7 +53,7 @@ export default function(internals) { const NS_HTML = "http://www.w3.org/1999/xhtml"; - Utilities.setPropertyUnchecked(document, 'createElementNS', + Utilities.setPropertyUnchecked(Document.prototype, 'createElementNS', /** * @this {Document} * @param {?string} namespace From 3c53e49c98366198ab8760155f55c7ed7adb42b8 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Fri, 31 Mar 2017 18:57:06 -0600 Subject: [PATCH 08/10] One more self review --- tests/js/reactions.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/js/reactions.js b/tests/js/reactions.js index 833c6fb..0aabd86 100644 --- a/tests/js/reactions.js +++ b/tests/js/reactions.js @@ -230,7 +230,6 @@ suite('Custom Element Reactions', function() { } } customElements.define('x-inner', XInner); - passed = false; var div = document.createElement('div'); div.innerHTML = ''; assert.isTrue(passed); From fed4381b53df0fd59a0cd4f6a6bc75e966218fd5 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Wed, 5 Apr 2017 14:14:43 -0600 Subject: [PATCH 09/10] Addressing feedback, fixing tests --- externs/custom-elements.js | 4 ++++ src/CustomElementInternals.js | 14 +++++++------- src/CustomElementRegistry.js | 4 ++-- src/Patch/Document.js | 5 +++++ src/Patch/HTMLElementSubclasses.js | 13 ++++--------- src/custom-elements.js | 2 +- tests/js/reactions.js | 16 ++++++++++++++++ 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/externs/custom-elements.js b/externs/custom-elements.js index bc59b2b..bb40ec7 100644 --- a/externs/custom-elements.js +++ b/externs/custom-elements.js @@ -13,6 +13,7 @@ const CustomElementState = { /** * @typedef {{ + * name: string, * localName: string, * constructor: !Function, * connectedCallback: Function, @@ -59,3 +60,6 @@ Element.prototype.__CE_definition; /** @type {!DocumentFragment|undefined} */ Element.prototype.__CE_shadowRoot; + +/** @type {!String|undefined} */ +Element.prototype.__CE_is; diff --git a/src/CustomElementInternals.js b/src/CustomElementInternals.js index 129c245..6620d99 100644 --- a/src/CustomElementInternals.js +++ b/src/CustomElementInternals.js @@ -45,8 +45,8 @@ export default class CustomElementInternals { * @param {!Node} node * @return {!CustomElementDefinition|null} */ - nodeToDefinition(node) { - const name = typeof node.__CE_is === 'string' ? node.__CE_is : node.localName; + nodeToCustomElementDefinition(node) { + const name = node.__CE_is || node.localName; const definition = this.nameToDefinition(name); if (definition && definition.localName === node.localName) { return definition; @@ -187,6 +187,8 @@ export default class CustomElementInternals { const elements = []; const gatherElements = element => { + let isAttribute; + if (element.localName === 'link' && element.getAttribute('rel') === 'import') { // The HTML Imports polyfill sets a descendant element of the link to // the `import` property, specifically this is *not* a Document. @@ -222,10 +224,8 @@ export default class CustomElementInternals { this.patchAndUpgradeTree(importNode, visitedImports); }); } - } else if (element.hasAttribute('is') || element.is) { - element.__CE_is = element.getAttribute('is') || element.is; - element.removeAttribute('is'); - delete element.is; + } else if (isAttribute = element.getAttribute('is')) { + element.__CE_is = isAttribute; elements.push(element); } else { elements.push(element); @@ -253,7 +253,7 @@ export default class CustomElementInternals { upgradeElement(element) { const currentState = element.__CE_state; if (currentState !== undefined) return; - const definition = this.nodeToDefinition(element); + const definition = this.nodeToCustomElementDefinition(element); if (!definition) return; definition.constructionStack.push(element); diff --git a/src/CustomElementRegistry.js b/src/CustomElementRegistry.js index 2b4e8ed..3e376b4 100644 --- a/src/CustomElementRegistry.js +++ b/src/CustomElementRegistry.js @@ -76,7 +76,7 @@ export default class CustomElementRegistry { let localName = name; if (options && options.extends) { - if (!this.enableCustomizedBuiltins) { + if (!this['enableCustomizedBuiltins']) { throw new Error(`Customized builtin elements are disabled by default. Set customElements.enableCustomizedBuiltins = true.`); } @@ -86,7 +86,7 @@ export default class CustomElementRegistry { const el = document.createElement(options.extends); if (el instanceof window['HTMLUnknownElement']) { - throw new Error(`Cannot extend '${options.extends}': is not a read HTML element`); + throw new Error(`Cannot extend '${options.extends}': is not a real HTML element`); } localName = options.extends; diff --git a/src/Patch/Document.js b/src/Patch/Document.js index f4a4e59..21baa13 100644 --- a/src/Patch/Document.js +++ b/src/Patch/Document.js @@ -28,6 +28,7 @@ export default function(internals) { (Native.Document_createElement.call(this, localName)); if (options && options.is) { result.__CE_is = options.is; + result.setAttribute('is', options.is) } internals.patch(result); return result; @@ -72,6 +73,10 @@ export default function(internals) { const result = /** @type {!Element} */ (Native.Document_createElementNS.call(this, namespace, localName)); + if (options && options.is) { + result.__CE_is = options.is; + result.setAttribute('is', options.is) + } internals.patch(result); return result; }); diff --git a/src/Patch/HTMLElementSubclasses.js b/src/Patch/HTMLElementSubclasses.js index 89b6a82..d334ac1 100644 --- a/src/Patch/HTMLElementSubclasses.js +++ b/src/Patch/HTMLElementSubclasses.js @@ -24,8 +24,7 @@ export default function(internals) { // This should really be `new.target` but `new.target` can't be emulated // in ES5. Assuming the user keeps the default value of the constructor's // prototype's `constructor` property, this is equivalent. - /** @type {!Function} */ - const constructor = this.constructor; + const constructor = /** @type {!Function} */ (this.constructor); const definition = internals.constructorToDefinition(constructor); if (!definition) { @@ -35,17 +34,13 @@ export default function(internals) { const constructionStack = definition.constructionStack; if (constructionStack.length === 0) { - let element; - if (definition.name !== definition.localName) { - element = Native.Document_createElement.call(document, definition.localName, {is: definition.name}); - } else { - element = Native.Document_createElement.call(document, definition.localName); - } + let element = Native.Document_createElement.call(document, definition.localName); + element.setAttribute('is', definition.name); Object.setPrototypeOf(element, constructor.prototype); element.__CE_state = CEState.custom; element.__CE_definition = definition; internals.patch(element); - return element; + return /** @type {!HTMLElement} */ (element); } const lastIndex = constructionStack.length - 1; diff --git a/src/custom-elements.js b/src/custom-elements.js index 40bbee5..e226940 100644 --- a/src/custom-elements.js +++ b/src/custom-elements.js @@ -37,7 +37,7 @@ if (!priorCustomElements || /** @type {!CustomElementRegistry} */ const customElements = new CustomElementRegistry(internals); - customElements.enableCustomizedBuiltins = priorCustomElements.enableCustomizedBuiltins; + customElements['enableCustomizedBuiltins'] = priorCustomElements['enableCustomizedBuiltins']; Object.defineProperty(window, 'customElements', { configurable: true, diff --git a/tests/js/reactions.js b/tests/js/reactions.js index 0aabd86..e13039d 100644 --- a/tests/js/reactions.js +++ b/tests/js/reactions.js @@ -91,6 +91,22 @@ suite('Custom Element Reactions', function() { assert.isTrue(pass); }); + test('is attribute is added to customized builtins instantiated via createElement', function() { + class XIsAttributeBuiltin extends HTMLButtonElement { + } + customElements.define('x-is-attribute-builtin', XIsAttributeBuiltin, {extends: 'button'}); + var el = document.createElement('button', {is: 'x-is-attribute-builtin'}); + assert.equal(el.getAttribute('is'), 'x-is-attribute-builtin'); + }); + + test('is attribute is added to customized builtins instantiated via constructor', function() { + class XIsAttributeBuiltin2 extends HTMLButtonElement { + } + customElements.define('x-is-attribute-builtin2', XIsAttributeBuiltin2, {extends: 'button'}); + var el = new XIsAttributeBuiltin2(); + assert.equal(el.getAttribute('is'), 'x-is-attribute-builtin2'); + }); + test('constructor is called on customized builtins when instantiated via createElement', function() { var pass = false; class XFoo2Builtin extends HTMLButtonElement { From d9c59aee4a765dd6cbff14bbf95287dc05fd1207 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Wed, 5 Apr 2017 14:17:53 -0600 Subject: [PATCH 10/10] elementName -> constructorName --- src/Patch/HTMLElementSubclasses.js | 12 ++++++------ tests/js/reactions.js | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Patch/HTMLElementSubclasses.js b/src/Patch/HTMLElementSubclasses.js index d334ac1..9192d8f 100644 --- a/src/Patch/HTMLElementSubclasses.js +++ b/src/Patch/HTMLElementSubclasses.js @@ -11,12 +11,12 @@ export default function(internals) { patchElement(`HTML${subclass}Element`, Native.HTMLElement_subclasses[subclass]); } - function patchElement(elementName, NativeElement) { + function patchElement(constructorName, NativeElement) { if (!NativeElement) { return; } - window[elementName] = (function() { + window[constructorName] = (function() { /** * @type {function(new: HTMLElement): !HTMLElement} */ @@ -24,7 +24,7 @@ export default function(internals) { // This should really be `new.target` but `new.target` can't be emulated // in ES5. Assuming the user keeps the default value of the constructor's // prototype's `constructor` property, this is equivalent. - const constructor = /** @type {!Function} */ (this.constructor); + const constructor = /** @type {!Function} */ (this.constructor); const definition = internals.constructorToDefinition(constructor); if (!definition) { @@ -35,18 +35,18 @@ export default function(internals) { if (constructionStack.length === 0) { let element = Native.Document_createElement.call(document, definition.localName); - element.setAttribute('is', definition.name); + element.setAttribute('is', definition.name); Object.setPrototypeOf(element, constructor.prototype); element.__CE_state = CEState.custom; element.__CE_definition = definition; internals.patch(element); - return /** @type {!HTMLElement} */ (element); + return /** @type {!HTMLElement} */ (element); } const lastIndex = constructionStack.length - 1; const element = constructionStack[lastIndex]; if (element === AlreadyConstructedMarker) { - throw new Error(`The ${elementName} constructor was either called reentrantly for this constructor or called multiple times.`); + throw new Error(`The ${constructorName} constructor was either called reentrantly for this constructor or called multiple times.`); } constructionStack[lastIndex] = AlreadyConstructedMarker; diff --git a/tests/js/reactions.js b/tests/js/reactions.js index e13039d..f6a53f6 100644 --- a/tests/js/reactions.js +++ b/tests/js/reactions.js @@ -91,21 +91,21 @@ suite('Custom Element Reactions', function() { assert.isTrue(pass); }); - test('is attribute is added to customized builtins instantiated via createElement', function() { - class XIsAttributeBuiltin extends HTMLButtonElement { - } - customElements.define('x-is-attribute-builtin', XIsAttributeBuiltin, {extends: 'button'}); - var el = document.createElement('button', {is: 'x-is-attribute-builtin'}); - assert.equal(el.getAttribute('is'), 'x-is-attribute-builtin'); - }); - - test('is attribute is added to customized builtins instantiated via constructor', function() { - class XIsAttributeBuiltin2 extends HTMLButtonElement { - } - customElements.define('x-is-attribute-builtin2', XIsAttributeBuiltin2, {extends: 'button'}); - var el = new XIsAttributeBuiltin2(); - assert.equal(el.getAttribute('is'), 'x-is-attribute-builtin2'); - }); + test('is attribute is added to customized builtins instantiated via createElement', function() { + class XIsAttributeBuiltin extends HTMLButtonElement { + } + customElements.define('x-is-attribute-builtin', XIsAttributeBuiltin, {extends: 'button'}); + var el = document.createElement('button', {is: 'x-is-attribute-builtin'}); + assert.equal(el.getAttribute('is'), 'x-is-attribute-builtin'); + }); + + test('is attribute is added to customized builtins instantiated via constructor', function() { + class XIsAttributeBuiltin2 extends HTMLButtonElement { + } + customElements.define('x-is-attribute-builtin2', XIsAttributeBuiltin2, {extends: 'button'}); + var el = new XIsAttributeBuiltin2(); + assert.equal(el.getAttribute('is'), 'x-is-attribute-builtin2'); + }); test('constructor is called on customized builtins when instantiated via createElement', function() { var pass = false;