-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesm.min.js
2 lines (2 loc) · 4.63 KB
/
esm.min.js
1
2
/*! (c) Andrea Giammarchi - ISC */
const t=(()=>{const t="DOMContentLoaded",e=new WeakMap,n=[],s=t=>{do{if(t.nextSibling)return!0}while(t=t.parentNode);return!1},i=()=>{n.splice(0).forEach((t=>{!0!==e.get(t[0])&&(e.set(t[0],!0),t[0][t[1]]())}))};document.addEventListener(t,i);class r extends HTMLElement{static withParsedCallback(r,o="parsed"){const{prototype:c}=r,{connectedCallback:a}=c,l=o+"Callback",u=(e,n,s,i)=>{n.disconnect(),s.removeEventListener(t,i),h(e)},h=t=>{n.length||requestAnimationFrame(i),n.push([t,l])};return Object.defineProperties(c,{connectedCallback:{configurable:!0,writable:!0,value(){if(a&&a.apply(this,arguments),l in this&&!e.has(this)){const n=this,{ownerDocument:i}=n;if(e.set(n,!1),"complete"===i.readyState||s(n))h(n);else{const e=()=>u(n,r,i,e);i.addEventListener(t,e);const r=new MutationObserver((()=>{s(n)&&u(n,r,i,e)}));r.observe(n.parentNode,{childList:!0,subtree:!0})}}}},[o]:{configurable:!0,get(){return!0===e.get(this)}}}),r}}return r.withParsedCallback(r)})(),e=t=>{t.hasAttribute("level-up")&&t.replaceWith(...t.children)};let n=class extends t{#t;constructor(t={}){super(),this.#t=t}connectedCallback(){this.parsed&&this.#t.oneConnect||super.connectedCallback()}parsedCallback(){this.init&&("AsyncFunction"===this.init.constructor.name?this.init().then((()=>e(this))):(this.init(),e(this)))}};const s=("dry-"+Math.random()).replace(".","");let i=1;const r=()=>s+i++,o="#inner#",c=/\{(?<content>t-\w[\-\w]+)\}/;function a(t){const e=document.getElementById(t),n=e.getAttribute("class"),s=e.content.cloneNode(!0),i=function(t){const e=t.querySelectorAll("*"),n=new Map;for(const t of e){const e=t.attributes;for(let s=0,i=e.length;s<i;s++){const{nodeName:i,nodeValue:r}=e.item(s),o=r.match(c);if(o){const e=h(t);n.get(e)||n.set(e,[]);const s="on"===i.substring(0,2)?{type:i.substring(2)}:null;n.get(e).push([i,o.groups.content,s])}}}return n}(s);var r;r=i,f(s,(function(t){if(0===t.childElementCount){const e=t.textContent.match(c);if(e){const n=h(t);r.get(n)||r.set(n,[]),r.get(n).push([o,e.groups.content])}}}));const a=new Set;for(const[,t]of i)for(const[e,n,s]of t)a.add(n);return{refClone:s,refData:i,attributes:[...a],tClass:n}}function l(t){if(!function(t){if(!t)return!1;const e=t.indexOf("-");return 0!==e&-1!==e}(t))return;const{refClone:e,refData:s,tClass:i}=a(t);customElements.define(t,class extends n{constructor(){super()}init(){this.style.display="block",this.hasAttribute("class")||this.setAttribute("class",i),this.tRefs=structuredClone(s),this.append(e.cloneNode(!0)),function(t){const e=[];for(const n of t.tRefs){const[s,i]=n,r=t.querySelector("#"+s);for(const[e,n,s]of i){u(r,e,t.getAttribute(n))}e.push([r,i,s])}for(const[n,s,i]of e){const e=r();n.setAttribute("id",e),t.tRefs.set(e,s),t.tRefs.delete(i)}}(this)}})}function u(t,e,n){e===o?t.innerText=n:"class"===e?(t.classList.remove(...t.classList),t.classList.add(n)):t.setAttribute(e,n)}function h(t){let e=t.getAttribute("id");return e||(e=r(),t.setAttribute("id",e)),e}function f(t,e){e(t),t.firstElementChild&&f(t.firstElementChild,e),t.nextElementSibling&&f(t.nextElementSibling,e)}const d=Object.getOwnPropertyDescriptors(Response.prototype),p=t=>"function"==typeof t,g={get:(t,e)=>d.hasOwnProperty(e)?((t,e,{get:n,value:s})=>n||!p(s)?t.then((t=>t[e])):(...n)=>t.then((t=>t[e](...n))))(t,e,d[e]):((t,e)=>p(e)?e.bind(t):e)(t,t[e])};class m extends t{#t;#e;constructor(t){super(),this.#t=t||{}}#n(t,e){const n=this.#e;if(n)return t&&(this.#e=null),e?n.textContent:n}#s(t){t.hasAttribute("level-up")&&t.replaceWith(...t.children),t.dispatchEvent(new Event("load")),t.lodaed=!0}originalFragment(t=!0){return this.#n(t,!1)}originalText(t=!0){return this.#n(t,!0)}parsedCallback(){const t=()=>this.#s(this);this.#e=document.createDocumentFragment(),this.#e.append(...this.childNodes),this.innerHTML=this.#t.onLoadHtml||"",this.init?"AsyncFunction"===this.init.constructor.name?this.init().then(t):(this.init(),t()):t()}}customElements.define("layout-m",class extends m{constructor(){super()}async init(){await async function(t){const e=t.getAttribute("source");if(!e)return;const n=await async function(t){if("#"===t.substring(0,1)){const e=document.getElementById(t.substring(1));if(e)try{return JSON.parse(e.textContent)}catch(t){return!1}}else try{return await((t,...e)=>new Proxy(fetch(t,...e),g))(t).json()}catch(t){return!1}}(e);if(!n)return;t.data=n}(this)}set data(t){const e=this.getAttribute("template");if(e){try{l(e)}catch(t){}this.innerHTML=this.createList(e,t)}}createList(t,e){return e.map((e=>`\n <${t}\n ${function(t){return Object.entries(t).map((([t,e])=>`t-${t}="${e}"`))}(e).join("\n")}\n ></${t}>\n `)).join("\n")}});