UNPKG

we-lib

Version:

wickedElements through customElements registry

2 lines (1 loc) 3.41 kB
self.weLib=function(e){"use strict";var t=(e,t)=>{const s=new WeakMap,r=new WeakMap,{filter:l}=[],a=(e,t)=>{for(let n=0,{length:s}=e;n<s;n++){const{target:s,attributeName:l,oldValue:a}=e[n],c=s.getAttribute(l);r.get(t).call(s,l,a,c)}},c=e=>"querySelectorAll"in e,o=e=>{for(let t=0,{length:n}=e;t<n;t++){const{addedNodes:n,removedNodes:s}=e[t];i(l.call(n,c),"c",new Set),i(l.call(s,c),"d",new Set)}},i=(e,r,l)=>{for(let a=0,{length:c}=e;a<c;a++){const c=e[a];l.has(c)||(l.add(c),s.has(c)?s.get(c)[r].forEach(n,c):"c"===r&&t(c),i(c.querySelectorAll("*"),r,l))}},u=new MutationObserver(o);return u.observe(e,{childList:!0,subtree:!0}),(e,{connectedCallback:t,disconnectedCallback:n,observedAttributes:l,attributeChangedCallback:c})=>{o(u.takeRecords());const{c:i,d:d}=s.get(e)||(e=>{const t={c:new Set,d:new Set};return s.set(e,t),t})(e);if(l){const t=new MutationObserver(a);t.observe(e,{attributes:!0,attributeOldValue:!0,attributeFilter:l.map(t=>(e.hasAttribute(t)&&c.call(e,t,null,e.getAttribute(t)),t))}),r.set(t,c)}return n&&d.add(n),t&&(i.add(t),e.ownerDocument.compareDocumentPosition(e)&e.DOCUMENT_POSITION_DISCONNECTED||t.call(e)),e}};function n(e){e.call(this)}const s="function"==typeof Promise?Promise:function(e){let t=[],n=0;return e(()=>{n=1,t.splice(0).forEach(s)}),{then:s};function s(e){return n?setTimeout(e):t.push(e),this}};const{create:r,keys:l}=Object,a=[],c=[],o={},i=new Set,u=new WeakMap,d=new WeakMap,{get:h,upgrade:f,whenDefined:g,$:b,_:p}=((e,n,r,l,a)=>{const c=(e,t)=>{for(let n=0,{length:s}=e;n<s;n++)t.has(e[n])||(t.add(e[n]),o(e[n],t))},o=(e,t)=>{for(let t=0,{length:s}=n;t<s;t++)(e.matches||e.webkitMatchesSelector||e.msMatchesSelector).call(e,n[t])&&a(e,r[t]);t&&((e,t)=>{n.length&&c(e.querySelectorAll(n),t)})(e,t)};return{get:e=>{const t=n.indexOf(e);return t<0?void 0:r[t].o},upgrade:e=>{o(e,new Set)},whenDefined:e=>{if(!(e in l)){let t,n=new s(e=>{t=e});l[e]={_:t,$:n}}return l[e].$},$:c,_:t(e,o)}})(document,c,a,o,(e,{m:t,l:n,o:s})=>{if(!t.has(e)){const l=r(s,{element:{enumerable:!0,value:e}});t.set(e,0),u.has(e)||u.set(e,[]),u.get(e).push(l);for(let t=0,{length:s}=n;t<s;t++)e.addEventListener(n[t].t,l,n[t].o);l.init&&l.init(),p(e,s)}}),w=(e,t,n)=>function(s){for(let r=u.get(this),l=0,{length:a}=r;l<a;l++)t===r[l][e]&&(n||-1<(r[l].observedAttributes||[]).indexOf(s))&&t.apply(r[l],arguments)},m=(e,t)=>{if(h(e))throw new Error("duplicated: "+e);const n=[],s=r(null);for(let e=l(t),r=0,{length:a}=e;r<a;r++){const l=e[r];if(/^(?:connected|disconnected|attributeChanged)$/.test(l))d.has(t[l])||d.set(t[l],w(l,t[l],"a"!==l[0])),t[l+"Callback"]=d.get(t[l]);else if(/^on/.test(l)&&!/Options$/.test(l)){const e=t[l+"Options"]||!1,r=l.toLowerCase();let a=r.slice(2);n.push({t:a,o:e}),s[a]=l,r!==l&&(a=l.slice(2,3).toLowerCase()+l.slice(3),s[a]=l,n.push({t:a,o:e}))}}n.length&&(t.handleEvent=function(e){this[s[e.type]](e)}),c.push(e),a.push({m:new WeakMap,l:n,o:t}),b(document.querySelectorAll(e),new Set),g(e),i.has(e)||o[e]._()},S=(e,t,n)=>{i.add(e),m(e,{init(){i.has(e)&&(i.delete(e),t().then(({default:t})=>{const s=c.indexOf(e);c.splice(s,1),a.splice(s,1),(n||m)(e,t)}))}})};return customElements.define("we-lib",class extends HTMLElement{static get define(){return m}static get defineAsync(){return S}static get get(){return h}static get upgrade(){return f}static get whenDefined(){return g}}),e.define=m,e.defineAsync=S,e.get=h,e.upgrade=f,e.whenDefined=g,e}({});