UNPKG

lu2

Version:

Simple and flexible UI component library based on native HTML and JavaScript

1 lines 3.89 kB
class AnyClass extends HTMLBRElement{constructor(){super(),this.someMethod=!0}}customElements.get("any-class")||customElements.define("any-class",AnyClass,{extends:"br"});const isSupportBuildIn=document.createElement("br",{is:"any-class"}).someMethod;!function(){"use strict";if(isSupportBuildIn)return;const{keys:e}=Object,{document:t,MutationObserver:r,Set:s,WeakMap:l}=self,n=e=>"querySelectorAll"in e,{filter:o}=[];var a=e=>{const a=new l,c=t=>{const{query:r}=e;if(r.length)for(let e=0,{length:s}=t;e<s;e++)u(o.call(t[e].addedNodes,n),!0,r),u(o.call(t[e].removedNodes,n),!1,r)},u=(t,r,l,n=new s)=>{for(let o,c,h=0,{length:f}=t;h<f;h++)if(!n.has(c=t[h])){if(n.add(c),r)for(let t,n=i(c),u=0,{length:h}=l;u<h;u++)n.call(c,t=l[u])&&(a.has(c)||a.set(c,new s),o=a.get(c),o.has(t)||(o.add(t),e.handle(c,r,t)));else a.has(c)&&(o=a.get(c),a.delete(c),o.forEach((t=>{e.handle(c,r,t)})));u(d(c),r,l,n)}},i=e=>e.matches||e.webkitMatchesSelector||e.msMatchesSelector,h=(t,r=!0)=>{u(t,r,e.query)},d=e=>p.length?e.querySelectorAll(p):p,f=new r(c),g=e.root||t,{query:p}=e;return f.observe(g,{childList:!0,subtree:!0}),h(d(g)),{drop:e=>{for(let t=0,{length:r}=e;t<r;t++)a.delete(e[t])},flush:()=>{c(f.takeRecords())},observer:f,parse:h}};const{customElements:c,document:u,Element:i,MutationObserver:h,Object:d,Promise:f,Map:g,Set:p,WeakMap:y,Reflect:b}=self,{attachShadow:m}=i.prototype,{createElement:w}=u,{define:v,get:E}=c,{construct:S}=b||{construct(e){return e.call(this)}},{defineProperty:A,keys:q,getOwnPropertyNames:M,setPrototypeOf:k}=d,O=new y,C=new p,N=new g,P=new g,$=new g,x=new g,B=[],I=[],L=e=>x.get(e)||E.call(c,e),R=(t,r,s)=>{const l=$.get(s);if(r&&!l.isPrototypeOf(t)){const r=(t=>{const r=e(t),s=[],{length:l}=r;for(let e=0;e<l;e++)s[e]=t[r[e]],delete t[r[e]];return()=>{for(let e=0;e<l;e++)t[r[e]]=s[e]}})(t);W=k(t,l);try{new l.constructor}finally{W=null,r()}}const n=(r?"":"dis")+"connectedCallback";n in l&&t[n]()},{parse:T}=a({query:I,handle:R}),{parse:V}=a({query:B,handle(e,t){O.has(e)&&(t?C.add(e):C.delete(e),I.length&&_.call(I,e))}}),j=e=>{if(!P.has(e)){let t,r=new f((e=>{t=e}));P.set(e,{$:r,_:t})}return P.get(e).$},H=((e,t)=>{const r=e=>{for(let t=0,{length:r}=e;t<r;t++)s(e[t])},s=({target:e,attributeName:t,oldValue:r})=>{e.attributeChangedCallback(t,r,e.getAttribute(t))};return(l,n)=>{const{observedAttributes:o}=l.constructor;return o&&e(n).then((()=>{new t(r).observe(l,{attributes:!0,attributeOldValue:!0,attributeFilter:o});for(let e=0,{length:t}=o;e<t;e++)l.hasAttribute(o[e])&&s({target:l,attributeName:o[e],oldValue:null})})),l}})(j,h);let W=null;function _(e){const{parse:t,root:r}=O.get(e);t(r.querySelectorAll(this),e.isConnected)}M(self).filter((e=>/^HTML/.test(e))).forEach((e=>{const t=self[e];function r(){const{constructor:e}=this;if(!N.has(e))throw new TypeError("Illegal constructor");const{is:r,tag:s}=N.get(e);if(r){if(W)return H(W,r);const t=w.call(u,s);return t.setAttribute("is",r),H(k(t,e.prototype),r)}return S.call(this,t,[],e)}k(r,t),A(r.prototype=t.prototype,"constructor",{value:r}),A(self,e,{value:r})})),A(u,"createElement",{configurable:!0,value(e,t){const r=t&&t.is;if(r){const t=x.get(r);if(t&&N.get(t).tag===e)return new t}const s=w.call(u,e);return r&&s.setAttribute("is",r),s}}),m&&A(i.prototype,"attachShadow",{configurable:!0,value(){const e=m.apply(this,arguments),{parse:t}=a({query:I,root:e,handle:R});return O.set(this,{root:e,parse:t}),e}}),A(c,"get",{configurable:!0,value:L}),A(c,"whenDefined",{configurable:!0,value:j}),A(c,"define",{configurable:!0,value(e,t,r){if(L(e))throw new Error(`'${e}' has already been defined as a custom element`);let s;const l=r&&r.extends;N.set(t,l?{is:e,tag:l}:{is:"",tag:e}),l?(s=`${l}[is="${e}"]`,$.set(s,t.prototype),x.set(e,t),I.push(s)):(v.apply(c,arguments),B.push(s=e)),j(e).then((()=>{l?(T(u.querySelectorAll(s)),C.forEach(_,[s])):V(u.querySelectorAll(s))})),P.get(e)._(t)}})}();