@bulmil/core
Version:

4 lines • 11.9 kB
JavaScript
/*!
* Bulmil - MIT License
*/
let e,t,l=!1,n=!1,o=!1,s=!1;const i="undefined"!=typeof window?window:{},r=i.document||{head:{}},c={t:0,l:"",jmp:e=>e(),raf:e=>requestAnimationFrame(e),ael:(e,t,l,n)=>e.addEventListener(t,l,n),rel:(e,t,l,n)=>e.removeEventListener(t,l,n),ce:(e,t)=>new CustomEvent(e,t)},f=e=>Promise.resolve(e),u=(()=>{try{return new CSSStyleSheet,"function"==typeof(new CSSStyleSheet).replace}catch(e){}return!1})(),$=new WeakMap,a=e=>"sc-"+e.o,d={},h=e=>"object"==(e=typeof e)||"function"===e,y=(e,t,...l)=>{let n=null,o=null,s=!1,i=!1,r=[];const c=t=>{for(let l=0;l<t.length;l++)n=t[l],Array.isArray(n)?c(n):null!=n&&"boolean"!=typeof n&&((s="function"!=typeof e&&!h(n))&&(n+=""),s&&i?r[r.length-1].i+=n:r.push(s?p(null,n):n),i=s)};if(c(l),t){t.name&&(o=t.name);{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(null===t?{}:t,r,b);const f=p(e,null);return f.u=t,r.length>0&&(f.$=r),f.h=o,f},p=(e,t)=>({t:0,p:e,i:t,m:null,$:null,u:null,h:null}),m={},b={forEach:(e,t)=>e.map(w).forEach(t),map:(e,t)=>e.map(w).map(t).map(g)},w=e=>({vattrs:e.u,vchildren:e.$,vkey:e.g,vname:e.h,vtag:e.p,vtext:e.i}),g=e=>{if("function"==typeof e.vtag){const t=Object.assign({},e.vattrs);return e.vkey&&(t.key=e.vkey),e.vname&&(t.name=e.vname),y(e.vtag,t,...e.vchildren||[])}const t=p(e.vtag,e.vtext);return t.u=e.vattrs,t.$=e.vchildren,t.g=e.vkey,t.h=e.vname,t},v=(e,t,l,n,o,s)=>{if(l!==n){let r=le(e,t),f=t.toLowerCase();if("class"===t){const t=e.classList,o=k(l),s=k(n);t.remove(...o.filter((e=>e&&!s.includes(e)))),t.add(...s.filter((e=>e&&!o.includes(e))))}else if(r||"o"!==t[0]||"n"!==t[1]){const i=h(n);if((r||i&&null!==n)&&!o)try{if(e.tagName.includes("-"))e[t]=n;else{let o=null==n?"":n;"list"===t?r=!1:null!=l&&e[t]==o||(e[t]=o)}}catch(e){}null==n||!1===n?!1===n&&""!==e.getAttribute(t)||e.removeAttribute(t):(!r||4&s||o)&&!i&&e.setAttribute(t,n=!0===n?"":n)}else t="-"===t[2]?t.slice(3):le(i,f)?f.slice(2):f[2]+t.slice(3),l&&c.rel(e,t,l,!1),n&&c.ael(e,t,n,!1)}},S=/\s/,k=e=>e?e.split(S):[],j=(e,t,l,n)=>{const o=11===t.m.nodeType&&t.m.host?t.m.host:t.m,s=e&&e.u||d,i=t.u||d;for(n in s)n in i||v(o,n,s[n],void 0,l,t.t);for(n in i)v(o,n,s[n],i[n],l,t.t)},M=(n,s,i)=>{let c,f,u,$=s.$[i],a=0;if(l||(o=!0,"slot"===$.p&&($.t|=$.$?2:1)),null!==$.i)c=$.m=r.createTextNode($.i);else if(1&$.t)c=$.m=r.createTextNode("");else if(c=$.m=r.createElement(2&$.t?"slot-fb":$.p),j(null,$,!1),$.$)for(a=0;a<$.$.length;++a)f=M(n,$,a),f&&c.appendChild(f);return c["s-hn"]=t,3&$.t&&(c["s-sr"]=!0,c["s-cr"]=e,c["s-sn"]=$.h||"",u=n&&n.$&&n.$[i],u&&u.p===$.p&&n.m&&x(n.m,!1)),c},x=(e,l)=>{c.t|=1;const n=e.childNodes;for(let e=n.length-1;e>=0;e--){const s=n[e];s["s-hn"]!==t&&s["s-ol"]&&(E(s).insertBefore(s,T(s)),s["s-ol"].remove(),s["s-ol"]=void 0,o=!0),l&&x(s,l)}c.t&=-2},O=(e,t,l,n,o,s)=>{let i,r=e["s-cr"]&&e["s-cr"].parentNode||e;for(;o<=s;++o)n[o]&&(i=M(null,l,o),i&&(n[o].m=i,r.insertBefore(i,T(t))))},C=(e,t,l,o,s)=>{for(;t<=l;++t)(o=e[t])&&(n=!0,(s=o.m)["s-ol"]?s["s-ol"].remove():x(s,!0),s.remove())},R=(e,t)=>e.p===t.p&&("slot"!==e.p||e.h===t.h),T=e=>e&&e["s-ol"]||e,E=e=>(e["s-ol"]?e["s-ol"]:e).parentNode,I=(e,t)=>{const l=t.m=e.m,n=e.$,o=t.$,s=t.i;let i;null===s?("slot"===t.p||j(e,t,!1),null!==n&&null!==o?((e,t,l,n)=>{let o,s=0,i=0,r=t.length-1,c=t[0],f=t[r],u=n.length-1,$=n[0],a=n[u];for(;s<=r&&i<=u;)null==c?c=t[++s]:null==f?f=t[--r]:null==$?$=n[++i]:null==a?a=n[--u]:R(c,$)?(I(c,$),c=t[++s],$=n[++i]):R(f,a)?(I(f,a),f=t[--r],a=n[--u]):R(c,a)?("slot"!==c.p&&"slot"!==a.p||x(c.m.parentNode,!1),I(c,a),e.insertBefore(c.m,f.m.nextSibling),c=t[++s],a=n[--u]):R(f,$)?("slot"!==c.p&&"slot"!==a.p||x(f.m.parentNode,!1),I(f,$),e.insertBefore(f.m,c.m),f=t[--r],$=n[++i]):(o=M(t&&t[i],l,i),$=n[++i],o&&E(c.m).insertBefore(o,T(c.m)));s>r?O(e,null==n[u+1]?null:n[u+1].m,l,n,i,u):i>u&&C(t,s,r)})(l,n,t,o):null!==o?(null!==e.i&&(l.textContent=""),O(l,null,t,o,0,o.length-1)):null!==n&&C(n,0,n.length-1)):(i=l["s-cr"])?i.parentNode.textContent=s:e.i!==s&&(l.data=s)},P=e=>{let t,l,n,o,s,i,r=e.childNodes;for(l=0,n=r.length;l<n;l++)if(t=r[l],1===t.nodeType){if(t["s-sr"])for(s=t["s-sn"],t.hidden=!1,o=0;o<n;o++)if(i=r[o].nodeType,r[o]["s-hn"]!==t["s-hn"]||""!==s){if(1===i&&s===r[o].getAttribute("slot")){t.hidden=!0;break}}else if(1===i||3===i&&""!==r[o].textContent.trim()){t.hidden=!0;break}P(t)}},A=[],F=e=>{let t,l,o,s,i,r,c=0,f=e.childNodes,u=f.length;for(;c<u;c++){if(t=f[c],t["s-sr"]&&(l=t["s-cr"])&&l.parentNode)for(o=l.parentNode.childNodes,s=t["s-sn"],r=o.length-1;r>=0;r--)l=o[r],l["s-cn"]||l["s-nr"]||l["s-hn"]===t["s-hn"]||(H(l,s)?(i=A.find((e=>e.v===l)),n=!0,l["s-sn"]=l["s-sn"]||s,i?i.S=t:A.push({S:t,v:l}),l["s-sr"]&&A.map((e=>{H(e.v,l["s-sn"])&&(i=A.find((e=>e.v===l)),i&&!e.S&&(e.S=i.S))}))):A.some((e=>e.v===l))||A.push({v:l}));1===t.nodeType&&F(t)}},H=(e,t)=>1===e.nodeType?null===e.getAttribute("slot")&&""===t||e.getAttribute("slot")===t:e["s-sn"]===t||""===t,L=(e,t)=>{t&&!e.k&&t["s-p"]&&t["s-p"].push(new Promise((t=>e.k=t)))},N=(e,t)=>{if(e.t|=16,!(4&e.t))return L(e,e.j),de((()=>U(e,t)));e.t|=512},U=(e,t)=>{const l=e.M;return z(void 0,(()=>W(e,l,t)))},W=async(e,t,l)=>{const n=e.O,o=n["s-rc"];l&&(e=>{const t=e.C;((e,t)=>{let l=a(t),n=ie.get(l);if(e=11===e.nodeType?e:r,n)if("string"==typeof n){let t,o=$.get(e=e.head||e);o||$.set(e,o=new Set),o.has(l)||(e.host&&(t=e.querySelector(`[sty-id="${l}"]`))?t.innerHTML=n:(t=r.createElement("style"),t.innerHTML=n,e.insertBefore(t,e.querySelector("link"))),o&&o.add(l))}else e.adoptedStyleSheets.includes(n)||(e.adoptedStyleSheets=[...e.adoptedStyleSheets,n])})(e.O.getRootNode(),t)})(e);q(e,t),o&&(o.map((e=>e())),n["s-rc"]=void 0);{const t=n["s-p"],l=()=>V(e);0===t.length?l():(Promise.all(t).then(l),e.t|=4,t.length=0)}},q=(s,i)=>{try{i=i.render(),s.t&=-17,s.t|=2,((s,i)=>{const f=s.O,u=s.C,$=s.R||p(null,null),a=(e=>e&&e.p===m)(i)?i:y(null,null,i);if(t=f.tagName,u.T&&(a.u=a.u||{},u.T.map((([e,t])=>a.u[t]=f[e]))),a.p=null,a.t|=4,s.R=a,a.m=$.m=f,e=f["s-cr"],l=0!=(1&u.t),n=!1,I($,a),c.t|=1,o){let e,t,l,n,o,s;F(a.m);let i=0;for(;i<A.length;i++)e=A[i],t=e.v,t["s-ol"]||(l=r.createTextNode(""),l["s-nr"]=t,t.parentNode.insertBefore(t["s-ol"]=l,t));for(i=0;i<A.length;i++)if(e=A[i],t=e.v,e.S){for(n=e.S.parentNode,o=e.S.nextSibling,l=t["s-ol"];l=l.previousSibling;)if(s=l["s-nr"],s&&s["s-sn"]===t["s-sn"]&&n===s.parentNode&&(s=s.nextSibling,!s||!s["s-nr"])){o=s;break}(!o&&n!==t.parentNode||t.nextSibling!==o)&&t!==o&&(!t["s-hn"]&&t["s-ol"]&&(t["s-hn"]=t["s-ol"].parentNode.nodeName),n.insertBefore(t,o))}else 1===t.nodeType&&(t.hidden=!0)}n&&P(a.m),c.t&=-2,A.length=0})(s,i)}catch(e){ne(e,s.O)}return null},V=e=>{const t=e.O,l=e.j;64&e.t||(e.t|=64,B(t),e.I(t),l||_()),e.k&&(e.k(),e.k=void 0),512&e.t&&ae((()=>N(e,!1))),e.t&=-517},_=()=>{B(r.documentElement),ae((()=>(e=>{const t=c.ce("appload",{detail:{namespace:"bulmil"}});return e.dispatchEvent(t),t})(i)))},z=(e,t)=>e&&e.then?e.then(t):t(),B=e=>e.classList.add("hydrated"),D=(e,t,l,n,o,s,i)=>{let r,c,f,u;if(1===s.nodeType){for(r=s.getAttribute("c-id"),r&&(c=r.split("."),c[0]!==i&&"0"!==c[0]||(f={t:0,P:c[0],A:c[1],F:c[2],H:c[3],p:s.tagName.toLowerCase(),m:s,u:null,$:null,g:null,h:null,i:null},t.push(f),s.removeAttribute("c-id"),e.$||(e.$=[]),e.$[f.H]=f,e=f,n&&"0"===f.F&&(n[f.H]=f.m))),u=s.childNodes.length-1;u>=0;u--)D(e,t,l,n,o,s.childNodes[u],i);if(s.shadowRoot)for(u=s.shadowRoot.childNodes.length-1;u>=0;u--)D(e,t,l,n,o,s.shadowRoot.childNodes[u],i)}else if(8===s.nodeType)c=s.nodeValue.split("."),c[1]!==i&&"0"!==c[1]||(r=c[0],f={t:0,P:c[1],A:c[2],F:c[3],H:c[4],m:s,u:null,$:null,g:null,h:null,p:null,i:null},"t"===r?(f.m=s.nextSibling,f.m&&3===f.m.nodeType&&(f.i=f.m.textContent,t.push(f),s.remove(),e.$||(e.$=[]),e.$[f.H]=f,n&&"0"===f.F&&(n[f.H]=f.m))):f.P===i&&("s"===r?(f.p="slot",s["s-sn"]=c[5]?f.h=c[5]:"",s["s-sr"]=!0,l.push(f),e.$||(e.$=[]),e.$[f.H]=f):"r"===r&&(o["s-cr"]=s,s["s-cn"]=!0)));else if(e&&"style"===e.p){const t=p(null,s.textContent);t.m=s,t.H="0",e.$=[t]}},G=(e,t)=>{if(1===e.nodeType){let l=0;for(;l<e.childNodes.length;l++)G(e.childNodes[l],t);if(e.shadowRoot)for(l=0;l<e.shadowRoot.childNodes.length;l++)G(e.shadowRoot.childNodes[l],t)}else if(8===e.nodeType){const l=e.nodeValue.split(".");"o"===l[0]&&(t.set(l[1]+"."+l[2],e),e.nodeValue="",e["s-en"]=l[3])}},J=(e,t,l)=>{if(t.L){const n=Object.entries(t.L),o=e.prototype;if(n.map((([e,[n]])=>{(31&n||2&l&&32&n)&&Object.defineProperty(o,e,{get(){return((e,t)=>Z(this).N.get(t))(0,e)},set(l){((e,t,l,n)=>{const o=Z(e),s=o.N.get(t),i=o.t,r=o.M;l=((e,t)=>null==e||h(e)?e:4&t?"false"!==e&&(""===e||!!e):2&t?parseFloat(e):1&t?e+"":e)(l,n.L[t][0]),8&i&&void 0!==s||l===s||(o.N.set(t,l),r&&2==(18&i)&&N(o,!1))})(this,e,l,t)},configurable:!0,enumerable:!0})})),1&l){const l=new Map;o.attributeChangedCallback=function(e,t,n){c.jmp((()=>{const t=l.get(e);if(this.hasOwnProperty(t))n=this[t],delete this[t];else if(o.hasOwnProperty(t)&&"number"==typeof this[t]&&this[t]==n)return;this[t]=(null!==n||"boolean"!=typeof this[t])&&n}))},e.observedAttributes=n.filter((([e,t])=>15&t[0])).map((([e,n])=>{const o=n[1]||e;return l.set(o,e),512&n[0]&&t.T.push([e,o]),o}))}}return e},K=e=>{if(0==(1&c.t)){const t=Z(e),l=t.C,n=()=>{};if(!(1&t.t)){let n;t.t|=1,n=e.getAttribute("s-id"),n&&((e,t,l,n)=>{const o=e.shadowRoot,s=[],i=n.R=p(t,null);c.U||G(r.body,c.U=new Map),e["s-id"]=l,e.removeAttribute("s-id"),D(i,s,[],null,e,e,l),s.map((e=>{const l=e.P+"."+e.A,n=c.U.get(l),s=e.m;n&&""===n["s-en"]&&n.parentNode.insertBefore(s,n.nextSibling),o||(s["s-hn"]=t,n&&(s["s-ol"]=n,s["s-ol"]["s-nr"]=s)),c.U.delete(l)}))})(e,l.o,n,t),n||12&l.t&&Q(e);{let l=e;for(;l=l.parentNode||l.host;)if(1===l.nodeType&&l.hasAttribute("s-id")&&l["s-p"]||l["s-p"]){L(t,t.j=l);break}}l.L&&Object.entries(l.L).map((([t,[l]])=>{if(31&l&&e.hasOwnProperty(t)){const l=e[t];delete e[t],e[t]=l}})),(async(e,t,l,n,o)=>{if(0==(32&t.t)){{if(t.t|=32,(o=se(l)).then){const e=()=>{};o=await o,e()}o.isProxied||(J(o,l,2),o.isProxied=!0);const e=()=>{};t.t|=8;try{new o(t)}catch(e){ne(e)}t.t&=-9,e()}if(o.style){let e=o.style;const t=a(l);if(!ie.has(t)){const n=()=>{};((e,t,l)=>{let n=ie.get(e);u&&l?(n=n||new CSSStyleSheet,n.replace(t)):n=t,ie.set(e,n)})(t,e,!!(1&l.t)),n()}}}const s=t.j,i=()=>N(t,!0);s&&s["s-rc"]?s["s-rc"].push(i):i()})(0,t,l)}n()}},Q=e=>{const t=e["s-cr"]=r.createComment("");t["s-cn"]=!0,e.insertBefore(t,e.firstChild)},X=(e,t={})=>{const l=[],n=t.exclude||[],o=i.customElements,s=r.head,f=s.querySelector("meta[charset]"),u=r.createElement("style"),$=[];let a,d=!0;Object.assign(c,t),c.l=new URL(t.resourcesUrl||"./",r.baseURI).href,c.t|=2,e.map((e=>{e[1].map((t=>{const s={t:t[0],o:t[1],L:t[2],W:t[3]};s.L=t[2],s.T=[];const i=s.o,r=class extends HTMLElement{constructor(e){super(e),te(e=this,s)}connectedCallback(){a&&(clearTimeout(a),a=null),d?$.push(this):c.jmp((()=>K(this)))}disconnectedCallback(){c.jmp((()=>{}))}componentOnReady(){return Z(this).q}};s.V=e[0],n.includes(i)||o.get(i)||(l.push(i),o.define(i,J(r,s,1)))}))})),u.innerHTML=l+"{visibility:hidden}.hydrated{visibility:inherit}",u.setAttribute("data-styles",""),s.insertBefore(u,f?f.nextSibling:s.firstChild),d=!1,$.length?$.map((e=>e.connectedCallback())):c.jmp((()=>a=setTimeout(_,30)))},Y=new WeakMap,Z=e=>Y.get(e),ee=(e,t)=>Y.set(t.M=e,t),te=(e,t)=>{const l={t:0,O:e,C:t,N:new Map};return l.q=new Promise((e=>l.I=e)),e["s-p"]=[],e["s-rc"]=[],Y.set(e,l)},le=(e,t)=>t in e,ne=(e,t)=>(0,console.error)(e,t),oe=new Map,se=e=>{const t=e.o.replace(/-/g,"_"),l=e.V,n=oe.get(l);return n?n[t]:import(`./${l}.entry.js`).then((e=>(oe.set(l,e),e[t])),ne)},ie=new Map,re=[],ce=[],fe=(e,t)=>l=>{e.push(l),s||(s=!0,t&&4&c.t?ae($e):c.raf($e))},ue=e=>{for(let t=0;t<e.length;t++)try{e[t](performance.now())}catch(e){ne(e)}e.length=0},$e=()=>{ue(re),ue(ce),(s=re.length>0)&&c.raf($e)},ae=e=>f().then(e),de=fe(ce,!0);export{m as H,X as b,y as h,f as p,ee as r}