-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesm-min.js
2 lines (2 loc) · 3.22 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},o=()=>{n.splice(0).forEach((t=>{!0!==e.get(t[0])&&(e.set(t[0],!0),t[0][t[1]]())}))};document.addEventListener(t,o);class i extends HTMLElement{static withParsedCallback(i,c="parsed"){const{prototype:r}=i,{connectedCallback:a}=r,l=c+"Callback",u=(e,n,s,o)=>{n.disconnect(),s.removeEventListener(t,o),d(e)},d=t=>{n.length||requestAnimationFrame(o),n.push([t,l])};return Object.defineProperties(r,{connectedCallback:{configurable:!0,writable:!0,value(){if(a&&a.apply(this,arguments),l in this&&!e.has(this)){const n=this,{ownerDocument:o}=n;if(e.set(n,!1),"complete"===o.readyState||s(n))d(n);else{const e=()=>u(n,i,o,e);o.addEventListener(t,e);const i=new MutationObserver((()=>{s(n)&&u(n,i,o,e)}));i.observe(n.parentNode,{childList:!0,subtree:!0})}}}},[c]:{configurable:!0,get(){return!0===e.get(this)}}}),i}}return i.withParsedCallback(i)})(),e=t=>{t.hasAttribute("level-up")&&t.replaceWith(...t.children)};class n 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 o=1;const i=()=>s+o++,c="#inner#",r=/\{(?<content>t-\w[\-\w]+)\}/;function a(t){return l(t).attributes}function l(t){const e=document.getElementById(t),n=e.getAttribute("class"),s=e.content.cloneNode(!0),o=function(t){const e=t.querySelectorAll("*"),n=new Map;for(const t of e){const e=t.attributes;for(let s=0,o=e.length;s<o;s++){const{nodeName:o,nodeValue:i}=e.item(s),c=i.match(r);if(c){const e=h(t);n.get(e)||n.set(e,[]);const s="on"===o.substring(0,2)?{type:o.substring(2)}:null;n.get(e).push([o,c.groups.content,s])}}}return n}(s);var i;i=o,b(s,(function(t){if(0===t.childElementCount){const e=t.textContent.match(r);if(e){const n=h(t);i.get(n)||i.set(n,[]),i.get(n).push([c,e.groups.content])}}}));const a=new Set;for(const[,t]of o)for(const[e,n,s]of t)a.add(n);return{refClone:s,refData:o,attributes:[...a],tClass:n}}function u(){for(const t of[...document.getElementsByTagName("template")])d(t.id)}function d(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:o}=l(t);customElements.define(t,class extends n{constructor(){super()}init(){this.style.display="block",this.hasAttribute("class")||this.setAttribute("class",o),this.tRefs=structuredClone(s),this.append(e.cloneNode(!0)),function(t){const e=[];for(const n of t.tRefs){const[s,o]=n,i=t.querySelector("#"+s);for(const[e,n,s]of o){f(i,e,t.getAttribute(n))}e.push([i,o,s])}for(const[n,s,o]of e){const e=i();n.setAttribute("id",e),t.tRefs.set(e,s),t.tRefs.delete(o)}}(this)}})}function f(t,e,n){e===c?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=i(),t.setAttribute("id",e)),e}function b(t,e){e(t),t.firstElementChild&&b(t.firstElementChild,e),t.nextElementSibling&&b(t.nextElementSibling,e)}export{d as defineCustomElement,u as defineCustomElements,a as getAttributes};