UNPKG

@diondre27/smart-components

Version:

Smart Web Components

1 lines 8.99 kB
let e,t,n=0,s=!1;const r=window,o=document,l=(HTMLElement,{t:0,s:"",jmp:e=>e(),raf:e=>requestAnimationFrame(e),ael:(e,t,n,s)=>e.addEventListener(t,n,s),rel:(e,t,n,s)=>e.removeEventListener(t,n,s)}),c=(()=>!!o.documentElement.attachShadow)(),i=(()=>{try{return new CSSStyleSheet,!0}catch(e){}return!1})(),a=new WeakMap,f=e=>a.get(e),u=(e,t)=>a.set(t.o=e,t),$=(e,t)=>t in e,m=e=>console.error(e),p=new Map,h=new Map,d=[],y=[],w=[],b=(e,t)=>n=>{e.push(n),s||(s=!0,t&&4&l.t?v(g):l.raf(g))},_=(e,t)=>{let n=0,s=0;for(;n<e.length&&(s=performance.now())<t;)try{e[n++](s)}catch(e){m(e)}n===e.length?e.length=0:0!==n&&e.splice(0,n)},g=()=>{n++,(e=>{for(let t=0;t<e.length;t++)try{e[t](performance.now())}catch(e){m(e)}e.length=0})(d);const e=2==(6&l.t)?performance.now()+10*Math.ceil(n*(1/22)):1/0;_(y,e),_(w,e),y.length>0&&(w.push(...y),y.length=0),(s=d.length+y.length+w.length>0)?l.raf(g):n=0},v=e=>Promise.resolve().then(e),j=b(y,!0),M={},S=e=>null!=e,k=e=>e.toLowerCase(),R=e=>"object"==(e=typeof e)||"function"===e,U=()=>r.CSS&&r.CSS.supports&&r.CSS.supports("color","var(--c)")?Promise.resolve():__sc_import_smarts("./p-aea6ba87.js"),L=async()=>{const e=new RegExp("/smarts(\\.esm)?\\.js($|\\?|#)"),t=Array.from(o.querySelectorAll("script")).find(t=>e.test(t.src)||"smarts"===t.getAttribute("data-namespace")),n=t["data-opts"];{const e=new URL(".",new URL(t.getAttribute("data-resources-url")||t.src,r.location.href));return O(e.href),window.customElements||await __sc_import_smarts("./p-020f8d73.js"),Object.assign(Object.assign({},n),{resourcesUrl:e.href})}},O=e=>{const t=(()=>`__sc_import_${"smarts".replace(/\s|-/g,"_")}`)();try{r[t]=new Function("w",`return import(w);//${Math.random()}`)}catch(n){const s=new Map;r[t]=n=>{const l=new URL(n,e).href;let c=s.get(l);if(!c){const e=o.createElement("script");e.type="module",e.src=URL.createObjectURL(new Blob([`import * as m from '${l}'; window.${t}.m = m;`],{type:"application/javascript"})),c=new Promise(n=>{e.onload=()=>{n(r[t].m),e.remove()}}),s.set(l,c),o.head.appendChild(e)}return c}}},x=new WeakMap,E=e=>"sc-"+e,C=(e,t,...n)=>{let s,r=null,o=!1,l=!1,c=[];const i=t=>{for(let n=0;n<t.length;n++)r=t[n],Array.isArray(r)?i(r):null!=r&&"boolean"!=typeof r&&((o="function"!=typeof e&&!R(r))&&(r=String(r)),o&&l?c[c.length-1].l+=r:c.push(o?{t:0,l:r}:r),l=o)};if(i(n),t){s=t.key||void 0;{const e=t.className||t.class;e&&(t.class="object"!=typeof e?e:Object.keys(e).filter(t=>e[t]).join(" "))}}if("function"==typeof e)return e(t,c,T);const a={t:0,i:e,u:c.length>0?c:null,$:void 0,p:t};return a.h=s,a},P={},T={forEach:(e,t)=>e.map(A).forEach(t),map:(e,t)=>e.map(A).map(t).map(H)},A=e=>({vattrs:e.p,vchildren:e.u,vkey:e.h,vname:e._,vtag:e.i,vtext:e.l}),H=e=>({t:0,p:e.vattrs,u:e.vchildren,h:e.vkey,_:e.vname,i:e.vtag,l:e.vtext}),F=(e,t,n,s,r,o)=>{if(n!==s)if("class"===t){const t=e.classList;W(n).forEach(e=>t.remove(e)),W(s).forEach(e=>t.add(e))}else if("style"===t){for(const t in n)s&&null!=s[t]||(t.includes("-")?e.style.removeProperty(t):e.style[t]="");for(const t in s)n&&s[t]===n[t]||(t.includes("-")?e.style.setProperty(t,s[t]):e.style[t]=s[t])}else if("key"===t);else if("ref"===t)s&&s(e);else if(t.startsWith("on")&&!$(e,t))t=$(e,k(t))?k(t.substring(2)):k(t[2])+t.substring(3),n&&l.rel(e,t,n,!1),s&&l.ael(e,t,s,!1);else{const n=$(e,t),l=R(s);if((n||l&&null!==s)&&!r)try{if(e.tagName.includes("-"))e[t]=s;else{const n=null==s?"":s;e[t]!==n&&(e[t]=n)}}catch(e){}null==s||!1===s?e.removeAttribute(t):(!n||4&o||r)&&!l&&(s=!0===s?"":s.toString(),e.setAttribute(t,s))}},W=e=>e?e.split(/\s+/).filter(e=>e):[],q=(e,t,n,s)=>{const r=11===t.$.nodeType&&t.$.host?t.$.host:t.$,o=e&&e.p||M,l=t.p||M;for(s in o)s in l||F(r,s,o[s],void 0,n,t.t);for(s in l)F(r,s,o[s],l[s],n,t.t)},B=(t,n,s)=>{let r,l,c=n.u[s],i=0;if(S(c.l))c.$=o.createTextNode(c.l);else if(r=c.$=o.createElement(c.i),q(null,c,!1),S(e)&&r["s-si"]!==e&&r.classList.add(r["s-si"]=e),c.u)for(i=0;i<c.u.length;++i)(l=B(t,c,i))&&r.appendChild(l);return c.$},N=(e,n,s,r,o,l)=>{let c,i=e;for(i.shadowRoot&&k(i.tagName)===t&&(i=i.shadowRoot);o<=l;++o)r[o]&&(c=B(null,s,o))&&(r[o].$=c,i.insertBefore(c,n))},V=(e,t,n,s)=>{for(;t<=n;++t)S(e[t])&&(s=e[t].$,G(e[t],!0),s.remove())},z=(e,t)=>e.i===t.i&&e.h===t.h,D=(e,t)=>{const n=t.$=e.$,s=e.u,r=t.u;S(t.l)?e.l!==t.l&&(n.textContent=t.l):(q(e,t,!1),S(s)&&S(r)?((e,t,n,s)=>{let r,o,l=0,c=0,i=0,a=0,f=t.length-1,u=t[0],$=t[f],m=s.length-1,p=s[0],h=s[m];for(;l<=f&&c<=m;)if(null==u)u=t[++l];else if(null==$)$=t[--f];else if(null==p)p=s[++c];else if(null==h)h=s[--m];else if(z(u,p))D(u,p),u=t[++l],p=s[++c];else if(z($,h))D($,h),$=t[--f],h=s[--m];else if(z(u,h))D(u,h),e.insertBefore(u.$,$.$.nextSibling),u=t[++l],h=s[--m];else if(z($,p))D($,p),e.insertBefore($.$,u.$),$=t[--f],p=s[++c];else{for(i=-1,a=l;a<=f;++a)if(t[a]&&S(t[a].h)&&t[a].h===p.h){i=a;break}i>=0?((o=t[i]).i!==p.i?r=B(t&&t[c],n,i):(D(o,p),t[i]=void 0,r=o.$),p=s[++c]):(r=B(t&&t[c],n,c),p=s[++c]),r&&u.$.parentNode.insertBefore(r,u.$)}l>f?N(e,null==s[m+1]?null:s[m+1].$,n,s,c,m):c>m&&V(t,l,f)})(n,s,t,r):S(r)?(S(e.l)&&(n.textContent=""),N(n,null,t,r,0,r.length-1)):S(s)&&V(s,0,s.length-1))},G=(e,t)=>{e&&(e.p&&e.p.ref&&e.p.ref(t?null:e.$),e.u&&e.u.forEach(e=>{G(e,t)}))},I=(e,t,n,s)=>{t.t|=16;const r=t.o,o=()=>J(e,t,n,r,s);return X(void 0,()=>j(o))},J=(n,s,r,l,i)=>{s.t&=-17,i&&((e,t)=>{const n=((e,t)=>{let n=E(t.g),s=h.get(n);if(e=11===e.nodeType?e:o,s)if("string"==typeof s){let t,r=x.get(e=e.head||e);r||x.set(e,r=new Set),r.has(n)||((t=o.createElement("style")).innerHTML=s,e.insertBefore(t,e.querySelector("link")),r&&r.add(n))}else e.adoptedStyleSheets.includes(s)||(e.adoptedStyleSheets=[...e.adoptedStyleSheets,s]);return n})(c&&e.shadowRoot?e.shadowRoot:e.getRootNode(),t);10&t.t&&(e["s-sc"]=n,e.classList.add(n+"-h"))})(n,r),s.t|=4;try{((n,s,r,o)=>{t=k(n.tagName);const l=s.v||{t:0},c=(e=>e&&e.i===P)(o)?o:C(null,null,o);c.i=null,c.t|=4,s.v=c,c.$=l.$=n.shadowRoot||n,e=n["s-sc"],D(l,c)})(n,s,0,l.render())}catch(e){m(e)}s.t&=-5,s.t|=2,K(n,s)},K=(e,t)=>{if(!e["s-al"]){const n=t.j;64&t.t||(t.t|=64,e.classList.add("hydrated"),t.M(e),n||Q())}},Q=()=>{o.documentElement.classList.add("hydrated"),l.t|=2},X=(e,t)=>e&&e.then?e.then(t):t(),Y=(e,t,n)=>{if(t.S){e.watchers&&(t.k=e.watchers);const s=Object.entries(t.S),r=e.prototype;if(s.forEach(([e,[s]])=>{(31&s||2&n&&32&s)&&Object.defineProperty(r,e,{get(){return((e,t)=>f(e).R.get(t))(this,e)},set(n){((e,t,n,s)=>{const r=f(this),o=r.U,l=r.R.get(t),c=r.t;if(!((n=((e,t)=>null==e||R(e)?e:1&t?String(e):e)(n,s.S[t][0]))===l||8&c&&void 0!==l)&&(r.R.set(t,n),r.o)){if(s.k&&128&c){const e=s.k[t];e&&e.forEach(e=>{try{r.o[e].call(r.o,n,l,t)}catch(e){m(e)}})}2==(22&c)&&I(o,r,s,!1)}})(0,e,n,t)},configurable:!0,enumerable:!0})}),1&n){const t=new Map;r.attributeChangedCallback=function(e,n,s){l.jmp(()=>{const n=t.get(e);this[n]=(null!==s||"boolean"!=typeof this[n])&&s})},e.observedAttributes=s.filter(([e,t])=>15&t[0]).map(([e,n])=>{const s=n[1]||e;return t.set(s,e),s})}}return e},Z=e=>{(e=>{if(e&&e.connectedCallback)try{e.connectedCallback(void 0)}catch(e){m(e)}})(e)},ee=(e,t={})=>{const n=[],s=t.exclude||[],u=o.head,$=r.customElements,d=u.querySelector("meta[charset]"),y=o.createElement("style");let w;Object.assign(l,t),l.s=new URL(t.resourcesUrl||"./",o.baseURI).href,t.syncQueue&&(l.t|=4),e.forEach(e=>e[1].forEach(t=>{const r={t:t[0],g:t[1],S:t[2],L:t[3],k:{}};!c&&1&r.t&&(r.t|=8);const o=r.g;r.O=e[0],s.includes(o)||$.get(o)||(n.push(o),$.define(o,Y(class extends HTMLElement{constructor(e){super(e),(e=>{{const t={t:0,U:e,R:new Map};t.C=new Promise(e=>t.M=e),a.set(e,t)}})(e=this),1&r.t&&(c?e.attachShadow({mode:"open"}):"shadowRoot"in e||(e.shadowRoot=e))}connectedCallback(){w&&(clearTimeout(w),w=null),l.jmp(()=>((e,t)=>{if(0==(1&l.t)){const n=f(e);1&n.t||(n.t|=1,t.S&&Object.entries(t.S).forEach(([t,[n]])=>{if(31&n&&e.hasOwnProperty(t)){const n=e[t];delete e[t],e[t]=n}}),v(()=>(async(e,t,n,s,r)=>{if(0==(32&t.t)){t.t|=32,(r=(e=>{const t=e.g.replace(/-/g,"_"),n=e.O,s=p.get(n);return s?s[t]:__sc_import_smarts(`./${n}.entry.js`).then(e=>(p.set(n,e),e[t]),m)})(n)).then&&(r=await r),r.isProxied||(n.k=r.watchers,Y(r,n,2),r.isProxied=!0),t.t|=8;try{new r(t)}catch(e){m(e)}t.t&=-9,t.t|=128,Z(t.o);const e=E(n.g);if(!h.has(e)&&r.style){let t=r.style;8&n.t&&(t=await __sc_import_smarts("./p-affe7c09.js").then(n=>n.scopeCss(t,e,!1))),((e,t,n)=>{let s=h.get(e);i&&n?(s=s||new CSSStyleSheet).replace(t):s=t,h.set(e,s)})(e,t,!!(1&n.t))}}(()=>I(e,t,n,!0))()})(e,n,t))),Z(n.o)}})(this,r))}disconnectedCallback(){l.jmp(()=>void 0)}"s-init"(){const e=f(this);e.o&&K(this,e)}"s-hmr"(e){}forceUpdate(){((e,t)=>{{const n=f(e);2&n.t&&I(e,n,t,!1)}})(this,r)}componentOnReady(){return f(this).C}},r,1)))})),y.innerHTML=n+"{visibility:hidden}.hydrated{visibility:inherit}",y.setAttribute("data-styles",""),u.insertBefore(y,d?d.nextSibling:u.firstChild),l.jmp(()=>w=setTimeout(Q,30))},te=e=>{const t=new URL(e,l.s);return t.origin!==r.location.origin?t.href:t.pathname};export{P as H,U as a,ee as b,te as g,C as h,L as p,u as r};