@webcomponents/scoped-custom-element-registry
Version:
Scoped CustomElementRegistry Polyfill
48 lines (45 loc) • 13 kB
JavaScript
(function(){
/*
Copyright (c) 2020 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at
http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at
http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at
http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at
http://polymer.github.io/PATENTS.txt
*/
'use strict';function k(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}}var l="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,d){if(a==Array.prototype||a==Object.prototype)return a;a[b]=d.value;return a};
function m(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var d=a[b];if(d&&d.Math==Math)return d}throw Error("Cannot find global object");}var n=m(this);function p(a,b){if(b)a:{var d=n;a=a.split(".");for(var e=0;e<a.length-1;e++){var c=a[e];if(!(c in d))break a;d=d[c]}a=a[a.length-1];e=d[a];b=b(e);b!=e&&null!=b&&l(d,a,{configurable:!0,writable:!0,value:b})}}
p("Symbol",function(a){function b(c){if(this instanceof b)throw new TypeError("Symbol is not a constructor");return new d("jscomp_symbol_"+(c||"")+"_"+e++,c)}function d(c,f){this.l=c;l(this,"description",{configurable:!0,writable:!0,value:f})}if(a)return a;d.prototype.toString=function(){return this.l};var e=0;return b});
p("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),d=0;d<b.length;d++){var e=n[b[d]];"function"===typeof e&&"function"!=typeof e.prototype[a]&&l(e.prototype,a,{configurable:!0,writable:!0,value:function(){return aa(k(this))}})}return a});function aa(a){a={next:a};a[Symbol.iterator]=function(){return this};return a}
function q(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):{next:k(a)}}function r(a){if(!(a instanceof Array)){a=q(a);for(var b,d=[];!(b=a.next()).done;)d.push(b.value);a=d}return a}
var t="function"==typeof Object.create?Object.create:function(a){function b(){}b.prototype=a;return new b},ba=function(){function a(){function d(){}new d;Reflect.construct(d,[],function(){});return new d instanceof d}if("undefined"!=typeof Reflect&&Reflect.construct){if(a())return Reflect.construct;var b=Reflect.construct;return function(d,e,c){d=b(d,e);c&&Reflect.setPrototypeOf(d,c.prototype);return d}}return function(d,e,c){void 0===c&&(c=d);c=t(c.prototype||Object.prototype);return Function.prototype.apply.call(d,
c,e)||c}}(),v;if("function"==typeof Object.setPrototypeOf)v=Object.setPrototypeOf;else{var w;a:{var ca={a:!0},x={};try{x.__proto__=ca;w=x.a;break a}catch(a){}w=!1}v=w?function(a,b){a.__proto__=b;if(a.__proto__!==b)throw new TypeError(a+" is not extensible");return a}:null}var y=v,z=window,A;if(void 0===(null==(A=z.CustomElementRegistryPolyfill)?void 0:A.formAssociated)){var B={};z.CustomElementRegistryPolyfill=(B.formAssociated=new Set,B)}
var C=window.HTMLElement,da=window.customElements.define,ea=window.customElements.get,D=window.customElements,E=new WeakMap,F=new WeakMap,G=new WeakMap,H=new WeakMap;function fa(){var a;this.promise=new Promise(function(b){a=b});this.resolve=a}function I(){this.h=new Map;this.m=new Map;this.j=new Map;this.i=new Map}
I.prototype.define=function(a,b){a=a.toLowerCase();if(void 0!==this.h.get(a))throw new DOMException("Failed to execute 'define' on 'CustomElementRegistry': the name \""+a+'" has already been used with this registry');if(void 0!==this.m.get(b))throw new DOMException("Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry");var d=b.prototype.attributeChangedCallback,e=new Set(b.observedAttributes||[]);ha(b,e,d);var c=ea.call(D,a),f,g,h=null!=
(g=null==(f=c)?void 0:f.s)?g:b.formAssociated||z.CustomElementRegistryPolyfill.formAssociated.has(a);h&&z.CustomElementRegistryPolyfill.formAssociated.add(a);if(h!=b.formAssociated)try{b.formAssociated=h}catch(u){}d={tagName:a,g:b,connectedCallback:b.prototype.connectedCallback,disconnectedCallback:b.prototype.disconnectedCallback,adoptedCallback:b.prototype.adoptedCallback,attributeChangedCallback:d,formAssociated:h,formAssociatedCallback:b.prototype.formAssociatedCallback,formDisabledCallback:b.prototype.formDisabledCallback,
formResetCallback:b.prototype.formResetCallback,formStateRestoreCallback:b.prototype.formStateRestoreCallback,observedAttributes:e};this.h.set(a,d);this.m.set(b,d);c||(c=ia(a),da.call(D,a,c));this===window.customElements&&(G.set(b,d),d.o=c);if(c=this.i.get(a))for(this.i.delete(a),c=q(c),e=c.next();!e.done;e=c.next())e=e.value,F.delete(e),J(e,d,!0);c=this.j.get(a);void 0!==c&&(c.resolve(b),this.j.delete(a));return b};
I.prototype.upgrade=function(a){for(var b=[],d=0;d<arguments.length;++d)b[d]=arguments[d];K.push(this);D.upgrade.apply(D,r(b));K.pop()};I.prototype.get=function(a){var b;return null==(b=this.h.get(a))?void 0:b.g};I.prototype.whenDefined=function(a){var b=this.h.get(a);if(void 0!==b)return Promise.resolve(b.g);b=this.j.get(a);void 0===b&&(b=new fa,this.j.set(a,b));return b.promise};function L(a,b,d,e){var c=a.i.get(d);c||a.i.set(d,c=new Set);e?c.add(b):c.delete(b)}var M;
window.HTMLElement=function(){var a=M;if(a)return M=void 0,a;var b=G.get(this.constructor);if(!b)throw new TypeError("Illegal constructor (custom element class must be registered with global customElements registry to be newable)");a=Reflect.construct(C,[],b.o);Object.setPrototypeOf(a,this.constructor.prototype);E.set(a,b);return a};window.HTMLElement.prototype=C.prototype;
function ia(a){function b(){var d=Reflect.construct(C,[],this.constructor);Object.setPrototypeOf(d,HTMLElement.prototype);a:{var e=d.getRootNode();if(!(e===document||e instanceof ShadowRoot)){e=K[K.length-1];if(e instanceof CustomElementRegistry){var c=e;break a}e=e.getRootNode();e===document||e instanceof ShadowRoot||(e=(null==(c=H.get(e))?void 0:c.getRootNode())||document)}c=e.registry}c=c||window.customElements;(e=c.h.get(a))?J(d,e):F.set(d,c);return d}n.Object.defineProperty(b,"formAssociated",
{configurable:!0,enumerable:!0,get:function(){return z.CustomElementRegistryPolyfill.formAssociated.has(a)}});b.prototype.connectedCallback=function(d){for(var e=[],c=0;c<arguments.length;++c)e[c]=arguments[c];N(this);(c=E.get(this))?c.connectedCallback&&c.connectedCallback.apply(this,e):L(F.get(this),this,a,!0)};b.prototype.disconnectedCallback=function(d){for(var e=[],c=0;c<arguments.length;++c)e[c]=arguments[c];(c=E.get(this))?c.disconnectedCallback&&c.disconnectedCallback.apply(this,e):L(F.get(this),
this,a,!1)};b.prototype.adoptedCallback=function(d){for(var e=[],c=0;c<arguments.length;++c)e[c]=arguments[c];var f,g;null==(f=E.get(this))||null==(g=f.adoptedCallback)||g.apply(this,e)};b.prototype.formAssociatedCallback=function(d){for(var e=[],c=0;c<arguments.length;++c)e[c]=arguments[c];c=E.get(this);if(null==c?0:c.formAssociated){var f;null==c||null==(f=c.formAssociatedCallback)||f.apply(this,e)}};b.prototype.formDisabledCallback=function(d){for(var e=[],c=0;c<arguments.length;++c)e[c]=arguments[c];
c=E.get(this);if(null==c?0:c.formAssociated){var f;null==c||null==(f=c.formDisabledCallback)||f.apply(this,e)}};b.prototype.formResetCallback=function(d){for(var e=[],c=0;c<arguments.length;++c)e[c]=arguments[c];c=E.get(this);if(null==c?0:c.formAssociated){var f;null==c||null==(f=c.formResetCallback)||f.apply(this,e)}};b.prototype.formStateRestoreCallback=function(d){for(var e=[],c=0;c<arguments.length;++c)e[c]=arguments[c];c=E.get(this);if(null==c?0:c.formAssociated){var f;null==c||null==(f=c.formStateRestoreCallback)||
f.apply(this,e)}};return b}window.CustomElementRegistry=I;
function ha(a,b,d){if(0!==b.size&&void 0!==d){var e=a.prototype.setAttribute;e&&(a.prototype.setAttribute=function(g,h){N(this);g=g.toLowerCase();if(b.has(g)){var u=this.getAttribute(g);e.call(this,g,h);d.call(this,g,u,h)}else e.call(this,g,h)});var c=a.prototype.removeAttribute;c&&(a.prototype.removeAttribute=function(g){N(this);g=g.toLowerCase();if(b.has(g)){var h=this.getAttribute(g);c.call(this,g);d.call(this,g,h,null)}else c.call(this,g)});var f=a.prototype.toggleAttribute;f&&(a.prototype.toggleAttribute=
function(g,h){N(this);g=g.toLowerCase();if(b.has(g)){var u=this.getAttribute(g);f.call(this,g,h);h=this.getAttribute(g);u!==h&&d.call(this,g,u,h)}else f.call(this,g,h)})}}var O;"loading"===document.readyState&&(O=new Set,document.addEventListener("readystatechange",function(){O.forEach(function(a){return P(a,E.get(a))})},{once:!0}));function N(a){var b;null!=(b=O)&&b.has(a)&&P(a,E.get(a))}
function P(a,b){var d;null==(d=O)||d.delete(a);b.attributeChangedCallback&&b.observedAttributes.forEach(function(e){a.hasAttribute(e)&&b.attributeChangedCallback.call(a,e,null,a.getAttribute(e))})}function Q(a){var b=Object.getPrototypeOf(a);if(b!==window.HTMLElement)return b===C?Object.setPrototypeOf(a,window.HTMLElement):Q(b)}
function J(a,b,d){d=void 0===d?!1:d;Object.setPrototypeOf(a,b.g.prototype);E.set(a,b);M=a;try{new b.g}catch(e){Q(b.g),new b.g}b.attributeChangedCallback&&(void 0===O||a.hasAttributes()?P(a,b):O.add(a));d&&b.connectedCallback&&a.isConnected&&b.connectedCallback.call(a)}var R=Element.prototype.attachShadow;
Element.prototype.attachShadow=function(a,b){for(var d=[],e=1;e<arguments.length;++e)d[e-1]=arguments[e];var c=Object.assign({},a);e=a.customElements;e=void 0===a.registry?e:a.registry;c=(delete c.customElements,delete c.registry,c);d=R.call.apply(R,[this,c].concat(r(d)));void 0!==e&&(d.customElements=d.registry=e);return d};var K=[document];
function S(a,b,d){var e=(d?Object.getPrototypeOf(d):a.prototype)[b];a.prototype[b]=function(c){for(var f=[],g=0;g<arguments.length;++g)f[g]=arguments[g];K.push(this);f=e.apply(d||this,f);void 0!==f&&H.set(f,this);K.pop();return f}}S(ShadowRoot,"createElement",document);S(ShadowRoot,"createElementNS",document);S(ShadowRoot,"importNode",document);S(Element,"insertAdjacentHTML");
function T(a){var b=Object.getOwnPropertyDescriptor(a.prototype,"innerHTML");Object.defineProperty(a.prototype,"innerHTML",Object.assign({},b,{set:function(d){K.push(this);b.set.call(this,d);K.pop()}}))}T(Element);T(ShadowRoot);Object.defineProperty(window,"customElements",{value:new CustomElementRegistry,configurable:!0,writable:!0});
if(window.ElementInternals&&window.ElementInternals.prototype.setFormValue){var U=new WeakMap,V=HTMLElement.prototype.attachInternals,methods=["setFormValue","setValidity","checkValidity","reportValidity"];HTMLElement.prototype.attachInternals=function(a){for(var b=[],d=0;d<arguments.length;++d)b[d]=arguments[d];b=V.call.apply(V,[this].concat(r(b)));U.set(b,this);return b};methods.forEach(function(a){var b=window.ElementInternals.prototype,d=b[a];b[a]=function(e){for(var c=[],f=0;f<arguments.length;++f)c[f]=
arguments[f];f=U.get(this);if(!0===E.get(f).formAssociated)return null==d?void 0:d.call.apply(d,[this].concat(r(c)));throw new DOMException("Failed to execute "+d+" on 'ElementInternals': The target element is not a form-associated custom element.");}});var RadioNodeList=function(a){var b=ba(Array,[].concat(r(a)),this.constructor);b.l=a;return b},W=RadioNodeList,X=Array;W.prototype=t(X.prototype);W.prototype.constructor=W;if(y)y(W,X);else for(var Y in X)if("prototype"!=Y)if(Object.defineProperties){var Z=
Object.getOwnPropertyDescriptor(X,Y);Z&&Object.defineProperty(W,Y,Z)}else W[Y]=X[Y];W.u=X.prototype;n.Object.defineProperty(RadioNodeList.prototype,"value",{configurable:!0,enumerable:!0,get:function(){var a;return(null==(a=this.l.find(function(b){return!0===b.checked}))?void 0:a.value)||""}});var HTMLFormControlsCollection=function(a){var b=this,d=new Map;a.forEach(function(e,c){var f=e.getAttribute("name"),g=d.get(f)||[];b[+c]=e;g.push(e);d.set(f,g)});this.length=a.length;d.forEach(function(e,c){e&&
"length"!==c&&"item"!==c&&"namedItem"!==c&&(b[c]=1===e.length?e[0]:new RadioNodeList(e))})};HTMLFormControlsCollection.prototype.item=function(a){var b;return null!=(b=this[a])?b:null};HTMLFormControlsCollection.prototype[Symbol.iterator]=function(){throw Error("Method not implemented.");};HTMLFormControlsCollection.prototype.namedItem=function(a){var b;return null!=(b=this[a])?b:null};var ja=Object.getOwnPropertyDescriptor(HTMLFormElement.prototype,"elements");Object.defineProperty(HTMLFormElement.prototype,
"elements",{get:function(){var a=ja.get.call(this),b=[];a=q(a);for(var d=a.next();!d.done;d=a.next()){d=d.value;var e=E.get(d);e&&!0!==e.formAssociated||b.push(d)}return new HTMLFormControlsCollection(b)}})};
}).call(typeof globalThis === 'object' ? globalThis : window);
//# sourceMappingURL=scoped-custom-element-registry.min.js.map