soft-components
Version:
Simple soft flexible set of web components
1 lines • 12.1 kB
JavaScript
let e,t,l,n=!1,o=!1,s=!1,i=!1,r=!1;const c="undefined"!=typeof window?window:{},f=c.document||{head:{}},a={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)},u=e=>Promise.resolve(e),$=(()=>{try{return new CSSStyleSheet,!0}catch(e){}return!1})(),d=(e,t,l)=>{l&&l.map((([l,n,o])=>{const s=e,i=p(t,o),r=h(l);a.ael(s,n,i,r),(t.o=t.o||[]).push((()=>a.rel(s,n,i,r)))}))},p=(e,t)=>l=>{try{256&e.t?e.i[t](l):(e.u=e.u||[]).push([t,l])}catch(e){ae(e)}},h=e=>0!=(2&e),y="http://www.w3.org/1999/xlink",m=new WeakMap,b=e=>"sc-"+e.$,w={},g=e=>"object"==(e=typeof e)||"function"===e,v=(e,t,...l)=>{let n=null,o=null,s=null,i=!1,r=!1,c=[];const f=t=>{for(let l=0;l<t.length;l++)n=t[l],Array.isArray(n)?f(n):null!=n&&"boolean"!=typeof n&&((i="function"!=typeof e&&!g(n))&&(n+=""),i&&r?c[c.length-1].p+=n:c.push(i?k(null,n):n),r=i)};if(f(l),t){t.key&&(o=t.key),t.name&&(s=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,c,O);const a=k(e,null);return a.h=t,c.length>0&&(a.m=c),a.g=o,a.v=s,a},k=(e,t)=>({t:0,k:e,p:t,j:null,m:null,h:null,g:null,v:null}),j={},O={forEach:(e,t)=>e.map(S).forEach(t),map:(e,t)=>e.map(S).map(t).map(M)},S=e=>({vattrs:e.h,vchildren:e.m,vkey:e.g,vname:e.v,vtag:e.k,vtext:e.p}),M=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),v(e.vtag,t,...e.vchildren||[])}const t=k(e.vtag,e.vtext);return t.h=e.vattrs,t.m=e.vchildren,t.g=e.vkey,t.v=e.vname,t},x=(e,t,l,n,o,s)=>{if(l!==n){let i=fe(e,t),r=t.toLowerCase();if("class"===t){const t=e.classList,o=P(l),s=P(n);t.remove(...o.filter((e=>e&&!s.includes(e)))),t.add(...s.filter((e=>e&&!o.includes(e))))}else if("style"===t){for(const t in l)n&&null!=n[t]||(t.includes("-")?e.style.removeProperty(t):e.style[t]="");for(const t in n)l&&n[t]===l[t]||(t.includes("-")?e.style.setProperty(t,n[t]):e.style[t]=n[t])}else if("key"===t);else if("ref"===t)n&&n(e);else if(i||"o"!==t[0]||"n"!==t[1]){const c=g(n);if((i||c&&null!==n)&&!o)try{if(e.tagName.includes("-"))e[t]=n;else{let o=null==n?"":n;"list"===t?i=!1:null!=l&&e[t]==o||(e[t]=o)}}catch(e){}let f=!1;r!==(r=r.replace(/^xlink\:?/,""))&&(t=r,f=!0),null==n||!1===n?!1===n&&""!==e.getAttribute(t)||(f?e.removeAttributeNS(y,t):e.removeAttribute(t)):(!i||4&s||o)&&!c&&(n=!0===n?"":n,f?e.setAttributeNS(y,t,n):e.setAttribute(t,n))}else t="-"===t[2]?t.slice(3):fe(c,r)?r.slice(2):r[2]+t.slice(3),l&&a.rel(e,t,l,!1),n&&a.ael(e,t,n,!1)}},C=/\s/,P=e=>e?e.split(C):[],R=(e,t,l,n)=>{const o=11===t.j.nodeType&&t.j.host?t.j.host:t.j,s=e&&e.h||w,i=t.h||w;for(n in s)n in i||x(o,n,s[n],void 0,l,t.t);for(n in i)x(o,n,s[n],i[n],l,t.t)},T=(o,r,c,a)=>{let u,$,d,p=r.m[c],h=0;if(n||(s=!0,"slot"===p.k&&(e&&a.classList.add(e+"-s"),p.t|=p.m?2:1)),null!==p.p)u=p.j=f.createTextNode(p.p);else if(1&p.t)u=p.j=f.createTextNode("");else{if(i||(i="svg"===p.k),u=p.j=f.createElementNS(i?"http://www.w3.org/2000/svg":"http://www.w3.org/1999/xhtml",2&p.t?"slot-fb":p.k),i&&"foreignObject"===p.k&&(i=!1),R(null,p,i),null!=e&&u["s-si"]!==e&&u.classList.add(u["s-si"]=e),p.m)for(h=0;h<p.m.length;++h)$=T(o,p,h,u),$&&u.appendChild($);"svg"===p.k?i=!1:"foreignObject"===u.tagName&&(i=!0)}return u["s-hn"]=l,3&p.t&&(u["s-sr"]=!0,u["s-cr"]=t,u["s-sn"]=p.v||"",d=o&&o.m&&o.m[c],d&&d.k===p.k&&o.j&&E(o.j,!1)),u},E=(e,t)=>{a.t|=1;const n=e.childNodes;for(let e=n.length-1;e>=0;e--){const o=n[e];o["s-hn"]!==l&&o["s-ol"]&&(H(o).insertBefore(o,F(o)),o["s-ol"].remove(),o["s-ol"]=void 0,s=!0),t&&E(o,t)}a.t&=-2},L=(e,t,n,o,s,i)=>{let r,c=e["s-cr"]&&e["s-cr"].parentNode||e;for(c.shadowRoot&&c.tagName===l&&(c=c.shadowRoot);s<=i;++s)o[s]&&(r=T(null,n,s,e),r&&(o[s].j=r,c.insertBefore(r,F(t))))},W=(e,t,l,n,s)=>{for(;t<=l;++t)(n=e[t])&&(s=n.j,_(n),o=!0,s["s-ol"]?s["s-ol"].remove():E(s,!0),s.remove())},A=(e,t)=>e.k===t.k&&("slot"===e.k?e.v===t.v:e.g===t.g),F=e=>e&&e["s-ol"]||e,H=e=>(e["s-ol"]?e["s-ol"]:e).parentNode,N=(e,t)=>{const l=t.j=e.j,n=e.m,o=t.m,s=t.k,r=t.p;let c;null===r?(i="svg"===s||"foreignObject"!==s&&i,"slot"===s||R(e,t,i),null!==n&&null!==o?((e,t,l,n)=>{let o,s,i=0,r=0,c=0,f=0,a=t.length-1,u=t[0],$=t[a],d=n.length-1,p=n[0],h=n[d];for(;i<=a&&r<=d;)if(null==u)u=t[++i];else if(null==$)$=t[--a];else if(null==p)p=n[++r];else if(null==h)h=n[--d];else if(A(u,p))N(u,p),u=t[++i],p=n[++r];else if(A($,h))N($,h),$=t[--a],h=n[--d];else if(A(u,h))"slot"!==u.k&&"slot"!==h.k||E(u.j.parentNode,!1),N(u,h),e.insertBefore(u.j,$.j.nextSibling),u=t[++i],h=n[--d];else if(A($,p))"slot"!==u.k&&"slot"!==h.k||E($.j.parentNode,!1),N($,p),e.insertBefore($.j,u.j),$=t[--a],p=n[++r];else{for(c=-1,f=i;f<=a;++f)if(t[f]&&null!==t[f].g&&t[f].g===p.g){c=f;break}c>=0?(s=t[c],s.k!==p.k?o=T(t&&t[r],l,c,e):(N(s,p),t[c]=void 0,o=s.j),p=n[++r]):(o=T(t&&t[r],l,r,e),p=n[++r]),o&&H(u.j).insertBefore(o,F(u.j))}i>a?L(e,null==n[d+1]?null:n[d+1].j,l,n,r,d):r>d&&W(t,i,a)})(l,n,t,o):null!==o?(null!==e.p&&(l.textContent=""),L(l,null,t,o,0,o.length-1)):null!==n&&W(n,0,n.length-1),i&&"svg"===s&&(i=!1)):(c=l["s-cr"])?c.parentNode.textContent=r:e.p!==r&&(l.data=r)},U=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(r[o]["s-hn"]!==t["s-hn"])if(i=r[o].nodeType,""!==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}U(t)}},q=[],D=e=>{let t,l,n,s,i,r,c=0,f=e.childNodes,a=f.length;for(;c<a;c++){if(t=f[c],t["s-sr"]&&(l=t["s-cr"]))for(n=l.parentNode.childNodes,s=t["s-sn"],r=n.length-1;r>=0;r--)l=n[r],l["s-cn"]||l["s-nr"]||l["s-hn"]===t["s-hn"]||(V(l,s)?(i=q.find((e=>e.O===l)),o=!0,l["s-sn"]=l["s-sn"]||s,i?i.S=t:q.push({S:t,O:l}),l["s-sr"]&&q.map((e=>{V(e.O,l["s-sn"])&&(i=q.find((e=>e.O===l)),i&&!e.S&&(e.S=i.S))}))):q.some((e=>e.O===l))||q.push({O:l}));1===t.nodeType&&D(t)}},V=(e,t)=>1===e.nodeType?null===e.getAttribute("slot")&&""===t||e.getAttribute("slot")===t:e["s-sn"]===t||""===t,_=e=>{e.h&&e.h.ref&&e.h.ref(null),e.m&&e.m.map(_)},z=e=>ie(e).M,B=(e,t,l)=>{const n=z(e);return{emit:e=>G(n,t,{bubbles:!!(4&l),composed:!!(2&l),cancelable:!!(1&l),detail:e})}},G=(e,t,l)=>{const n=a.ce(t,l);return e.dispatchEvent(n),n},I=(e,t)=>{t&&!e.C&&t["s-p"]&&t["s-p"].push(new Promise((t=>e.C=t)))},J=(e,t)=>{if(e.t|=16,!(4&e.t))return I(e,e.P),ge((()=>K(e,t)));e.t|=512},K=(e,t)=>{const l=e.i;let n;return t&&(e.t|=256,e.u&&(e.u.map((([e,t])=>ee(l,e,t))),e.u=null),n=ee(l,"componentWillLoad")),te(n,(()=>Q(e,l,t)))},Q=async(i,r,c)=>{const u=i.M,$=u["s-rc"];c&&(e=>{const t=e.R,l=e.M,n=t.t,o=((e,t)=>{let l=b(t),n=de.get(l);if(e=11===e.nodeType?e:f,n)if("string"==typeof n){let t,o=m.get(e=e.head||e);o||m.set(e,o=new Set),o.has(l)||(t=f.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]);return l})(l.shadowRoot?l.shadowRoot:l.getRootNode(),t);10&n&&(l["s-sc"]=o,l.classList.add(o+"-h"))})(i);((i,r)=>{const c=i.M,u=i.R,$=i.T||k(null,null),d=(e=>e&&e.k===j)(r)?r:v(null,null,r);if(l=c.tagName,u.L&&(d.h=d.h||{},u.L.map((([e,t])=>d.h[t]=c[e]))),d.k=null,d.t|=4,i.T=d,d.j=$.j=c.shadowRoot||c,e=c["s-sc"],t=c["s-cr"],n=0!=(1&u.t),o=!1,N($,d),a.t|=1,s){let e,t,l,n,o,s;D(d.j);let i=0;for(;i<q.length;i++)e=q[i],t=e.O,t["s-ol"]||(l=f.createTextNode(""),l["s-nr"]=t,t.parentNode.insertBefore(t["s-ol"]=l,t));for(i=0;i<q.length;i++)if(e=q[i],t=e.O,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)}o&&U(d.j),a.t&=-2,q.length=0})(i,X(i,r)),$&&($.map((e=>e())),u["s-rc"]=void 0);{const e=u["s-p"],t=()=>Y(i);0===e.length?t():(Promise.all(e).then(t),i.t|=4,e.length=0)}},X=(e,t)=>{try{t=t.render&&t.render(),e.t&=-17,e.t|=2}catch(t){ae(t,e.M)}return t},Y=e=>{const t=e.M,l=e.i,n=e.P;64&e.t||(e.t|=64,le(t),ee(l,"componentDidLoad"),e.W(t),n||Z()),e.A(t),e.C&&(e.C(),e.C=void 0),512&e.t&&we((()=>J(e,!1))),e.t&=-517},Z=()=>{le(f.documentElement),we((()=>G(c,"appload",{detail:{namespace:"soft-components"}})))},ee=(e,t,l)=>{if(e&&e[t])try{return e[t](l)}catch(e){ae(e)}},te=(e,t)=>e&&e.then?e.then(t):t(),le=e=>e.classList.add("hydrated"),ne=(e,t,l)=>{if(t.F){e.watchers&&(t.H=e.watchers);const n=Object.entries(t.F),o=e.prototype;if(n.map((([e,[n]])=>{31&n||2&l&&32&n?Object.defineProperty(o,e,{get(){return((e,t)=>ie(this).N.get(t))(0,e)},set(l){((e,t,l,n)=>{const o=ie(e),s=o.M,i=o.N.get(t),r=o.t,c=o.i;if(l=((e,t)=>null==e||g(e)?e:4&t?"false"!==e&&(""===e||!!e):2&t?parseFloat(e):1&t?e+"":e)(l,n.F[t][0]),!(8&r&&void 0!==i||l===i)&&(o.N.set(t,l),c)){if(n.H&&128&r){const e=n.H[t];e&&e.map((e=>{try{c[e](l,i,t)}catch(e){ae(e,s)}}))}2==(18&r)&&J(o,!1)}})(this,e,l,t)},configurable:!0,enumerable:!0}):1&l&&64&n&&Object.defineProperty(o,e,{value(...t){const l=ie(this);return l.U.then((()=>l.i[e](...t)))}})})),1&l){const l=new Map;o.attributeChangedCallback=function(e,t,n){a.jmp((()=>{const t=l.get(e);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.L.push([e,o]),o}))}}return e},oe=(e,t={})=>{const l=[],n=t.exclude||[],o=c.customElements,s=f.head,i=s.querySelector("meta[charset]"),r=f.createElement("style"),u=[];let p,h=!0;Object.assign(a,t),a.l=new URL(t.resourcesUrl||"./",f.baseURI).href,e.map((e=>e[1].map((t=>{const s={t:t[0],$:t[1],F:t[2],q:t[3]};s.F=t[2],s.q=t[3],s.L=[],s.H={};const i=s.$,r=class extends HTMLElement{constructor(e){super(e),ce(e=this,s),1&s.t&&e.attachShadow({mode:"open"})}connectedCallback(){p&&(clearTimeout(p),p=null),h?u.push(this):a.jmp((()=>(e=>{if(0==(1&a.t)){const t=ie(e),l=t.R,n=()=>{};if(1&t.t)d(e,t,l.q);else{t.t|=1,12&l.t&&(e=>{const t=e["s-cr"]=f.createComment("");t["s-cn"]=!0,e.insertBefore(t,e.firstChild)})(e);{let l=e;for(;l=l.parentNode||l.host;)if(l["s-p"]){I(t,t.P=l);break}}l.F&&Object.entries(l.F).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=$e(l)).then){const e=()=>{};o=await o,e()}o.isProxied||(l.H=o.watchers,ne(o,l,2),o.isProxied=!0);const e=()=>{};t.t|=8;try{new o(t)}catch(e){ae(e)}t.t&=-9,t.t|=128,e()}if(o.style){let e=o.style;const t=b(l);if(!de.has(t)){const n=()=>{};((e,t,l)=>{let n=de.get(e);$&&l?(n=n||new CSSStyleSheet,n.replace(t)):n=t,de.set(e,n)})(t,e,!!(1&l.t)),n()}}}const s=t.P,i=()=>J(t,!0);s&&s["s-rc"]?s["s-rc"].push(i):i()})(0,t,l)}n()}})(this)))}disconnectedCallback(){a.jmp((()=>(()=>{if(0==(1&a.t)){const e=ie(this),t=e.i;e.o&&(e.o.map((e=>e())),e.o=void 0),ee(t,"disconnectedCallback")}})()))}componentOnReady(){return ie(this).D}};s.V=e[0],n.includes(i)||o.get(i)||(l.push(i),o.define(i,ne(r,s,1)))})))),r.innerHTML=l+"{visibility:hidden}.hydrated{visibility:inherit}",r.setAttribute("data-styles",""),s.insertBefore(r,i?i.nextSibling:s.firstChild),h=!1,u.length?u.map((e=>e.connectedCallback())):a.jmp((()=>p=setTimeout(Z,30)))},se=new WeakMap,ie=e=>se.get(e),re=(e,t)=>se.set(t.i=e,t),ce=(e,t)=>{const l={t:0,M:e,R:t,N:new Map};return l.U=new Promise((e=>l.A=e)),l.D=new Promise((e=>l.W=e)),e["s-p"]=[],e["s-rc"]=[],d(e,l,t.q),se.set(e,l)},fe=(e,t)=>t in e,ae=(e,t)=>(0,console.error)(e,t),ue=new Map,$e=e=>{const t=e.$.replace(/-/g,"_"),l=e.V,n=ue.get(l);return n?n[t]:import(`./${l}.entry.js`).then((e=>(ue.set(l,e),e[t])),ae)},de=new Map,pe=[],he=[],ye=(e,t)=>l=>{e.push(l),r||(r=!0,t&&4&a.t?we(be):a.raf(be))},me=e=>{for(let t=0;t<e.length;t++)try{e[t](performance.now())}catch(e){ae(e)}e.length=0},be=()=>{me(pe),me(he),(r=pe.length>0)&&a.raf(be)},we=e=>u().then(e),ge=ye(he,!0);export{j as H,oe as b,B as c,z as g,v as h,u as p,re as r}