perlite
Version:
[]()
3 lines (2 loc) • 26.3 kB
JavaScript
const e=["String","Number","Object","Array","Boolean","Date"];function t(e){return e&&"object"==typeof e}function n(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!1,configurable:!0})}function s(e,t,s){n(e,"__key",t),n(e,"__parent",s)}const i={computedStack:[],observersMap:new WeakMap,computedDependenciesTracker:new WeakMap};let r=null;const o=new Set;function a(){for(const e of o)e();o.clear(),r=null}function l(e,t){null===r&&(r=setTimeout(a,!0===t?0:t)),o.add(e)}const{observersMap:c,computedStack:d,computedDependenciesTracker:u}=i;const{computedStack:h,computedDependenciesTracker:p}=i;var f={observe:function i(r,o={}){const{props:a,ignore:h,batch:p,deep:f=!0,bubble:m,bind:v}=o;if(r.__observed)return r;const g=e=>(!a||a.includes(e))&&(!h||!h.includes(e));c.set(r,new Map),f&&Object.entries(r).forEach((function([e,n]){t(n)&&(r[e]=i(n,o),m&&s(r[e],e,r))}));const y=new Proxy(r,{get(e,t){if("__observed"===t)return!0;if(g(t)&&d.length){const e=c.get(r);e.has(t)||e.set(t,new Set);const n=u.get(d[0]);n&&(n.has(r)||n.set(r,new Set),n.get(r).add(t)),e.get(t).add(d[0])}return r[t]},set(e,a,h){if("__handler"===a)n(r,"__handler",h);else if(g(a)){if(Array.isArray(r)&&"length"===a||r[a]!==h){const e=f&&t(h),n=c.get(r),v=r[a];t(v)&&delete r[a],r[a]=e?i(h,o):h,e&&m&&s(r[a],a,r);const g=[a];let b=r;for(;b&&(!b.__handler||!1!==b.__handler(g,h,v,y));)b.__key&&b.__parent?(g.unshift(b.__key),b=b.__parent):b=null;const _=n.get(a);if(_)for(const e of _){const t=u.get(e);e.__disposed||t&&(!t.has(r)||!t.get(r).has(a))?_.delete(e):e!==d[0]&&(p?l(e,p):e())}}}else r[a]=h;return!0}});var b;return v&&(b=r,Object.getOwnPropertyNames(b).concat(Object.getPrototypeOf(b)&&e.indexOf(Object.getPrototypeOf(b).constructor.name)<0?Object.getOwnPropertyNames(Object.getPrototypeOf(b)):[]).filter((e=>"constructor"!==e&&"function"==typeof b[e]))).forEach((e=>r[e]=r[e].bind(y))),y},computed:function(e,{autoRun:t=!0,callback:n,bind:s,disableTracking:i=!1}={}){const r=new Proxy(e,{apply(e,t,o){function a(a){i||p.set(n||r,new WeakMap),h.unshift(n||r);const l=a?a():e.apply(s||t,o);return h.shift(),l}return o.push({computeAsync:function(e){return a(e)}}),a()}});return t&&r(),r},dispose:function(e){return i.computedDependenciesTracker.delete(e),e.__disposed=!0}};const m=new WeakMap,v=e=>(...t)=>{const n=e(...t);return m.set(n,!0),n},g=e=>"function"==typeof e&&m.has(e),y="undefined"!=typeof window&&null!=window.customElements&&void 0!==window.customElements.polyfillWrapFlushCallback,b=(e,t,n=null,s=null)=>{for(;t!==n;){const n=t.nextSibling;e.insertBefore(t,s),t=n}},_=(e,t,n=null)=>{for(;t!==n;){const n=t.nextSibling;e.removeChild(t),t=n}},w={},x={},N=`{{lit-${String(Math.random()).slice(2)}}}`,E=`\x3c!--${N}--\x3e`,V=new RegExp(`${N}|${E}`);class T{constructor(e,t){this.parts=[],this.element=t;const n=[],s=[],i=document.createTreeWalker(t.content,133,null,!1);let r=0,o=-1,a=0;const{strings:l,values:{length:c}}=e;for(;a<c;){const e=i.nextNode();if(null!==e){if(o++,1===e.nodeType){if(e.hasAttributes()){const t=e.attributes,{length:n}=t;let s=0;for(let e=0;e<n;e++)A(t[e].name,"$lit$")&&s++;for(;s-- >0;){const t=l[a],n=k.exec(t)[2],s=n.toLowerCase()+"$lit$",i=e.getAttribute(s);e.removeAttribute(s);const r=i.split(V);this.parts.push({type:"attribute",index:o,name:n,strings:r}),a+=r.length-1}}"TEMPLATE"===e.tagName&&(s.push(e),i.currentNode=e.content)}else if(3===e.nodeType){const t=e.data;if(t.indexOf(N)>=0){const s=e.parentNode,i=t.split(V),r=i.length-1;for(let t=0;t<r;t++){let n,r=i[t];if(""===r)n=M();else{const e=k.exec(r);null!==e&&A(e[2],"$lit$")&&(r=r.slice(0,e.index)+e[1]+e[2].slice(0,-"$lit$".length)+e[3]),n=document.createTextNode(r)}s.insertBefore(n,e),this.parts.push({type:"node",index:++o})}""===i[r]?(s.insertBefore(M(),e),n.push(e)):e.data=i[r],a+=r}}else if(8===e.nodeType)if(e.data===N){const t=e.parentNode;null!==e.previousSibling&&o!==r||(o++,t.insertBefore(M(),e)),r=o,this.parts.push({type:"node",index:o}),null===e.nextSibling?e.data="":(n.push(e),o--),a++}else{let t=-1;for(;-1!==(t=e.data.indexOf(N,t+1));)this.parts.push({type:"node",index:-1}),a++}}else i.currentNode=s.pop()}for(const e of n)e.parentNode.removeChild(e)}}const A=(e,t)=>{const n=e.length-t.length;return n>=0&&e.slice(n)===t},S=e=>-1!==e.index,M=()=>document.createComment(""),k=/([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;class O{constructor(e,t,n){this.__parts=[],this.template=e,this.processor=t,this.options=n}update(e){let t=0;for(const n of this.__parts)void 0!==n&&n.setValue(e[t]),t++;for(const e of this.__parts)void 0!==e&&e.commit()}_clone(){const e=y?this.template.element.content.cloneNode(!0):document.importNode(this.template.element.content,!0),t=[],n=this.template.parts,s=document.createTreeWalker(e,133,null,!1);let i,r=0,o=0,a=s.nextNode();for(;r<n.length;)if(i=n[r],S(i)){for(;o<i.index;)o++,"TEMPLATE"===a.nodeName&&(t.push(a),s.currentNode=a.content),null===(a=s.nextNode())&&(s.currentNode=t.pop(),a=s.nextNode());if("node"===i.type){const e=this.processor.handleTextExpression(this.options);e.insertAfterNode(a.previousSibling),this.__parts.push(e)}else this.__parts.push(...this.processor.handleAttributeExpressions(a,i.name,i.strings,this.options));r++}else this.__parts.push(void 0),r++;return y&&(document.adoptNode(e),customElements.upgrade(e)),e}}const P=window.trustedTypes&&trustedTypes.createPolicy("lit-html",{createHTML:e=>e}),L=` ${N} `;class I{constructor(e,t,n,s){this.strings=e,this.values=t,this.type=n,this.processor=s}getHTML(){const e=this.strings.length-1;let t="",n=!1;for(let s=0;s<e;s++){const e=this.strings[s],i=e.lastIndexOf("\x3c!--");n=(i>-1||n)&&-1===e.indexOf("--\x3e",i+1);const r=k.exec(e);t+=null===r?e+(n?L:E):e.substr(0,r.index)+r[1]+r[2]+"$lit$"+r[3]+N}return t+=this.strings[e],t}getTemplateElement(){const e=document.createElement("template");let t=this.getHTML();return void 0!==P&&(t=P.createHTML(t)),e.innerHTML=t,e}}class C extends I{getHTML(){return`<svg>${super.getHTML()}</svg>`}getTemplateElement(){const e=super.getTemplateElement(),t=e.content,n=t.firstChild;return t.removeChild(n),b(t,n.firstChild),e}}const W=e=>null===e||!("object"==typeof e||"function"==typeof e),H=e=>Array.isArray(e)||!(!e||!e[Symbol.iterator]);class j{constructor(e,t,n){this.dirty=!0,this.element=e,this.name=t,this.strings=n,this.parts=[];for(let e=0;e<n.length-1;e++)this.parts[e]=this._createPart()}_createPart(){return new $(this)}_getValue(){const e=this.strings,t=e.length-1,n=this.parts;if(1===t&&""===e[0]&&""===e[1]){const e=n[0].value;if("symbol"==typeof e)return String(e);if("string"==typeof e||!H(e))return e}let s="";for(let i=0;i<t;i++){s+=e[i];const t=n[i];if(void 0!==t){const e=t.value;if(W(e)||!H(e))s+="string"==typeof e?e:String(e);else for(const t of e)s+="string"==typeof t?t:String(t)}}return s+=e[t],s}commit(){this.dirty&&(this.dirty=!1,this.element.setAttribute(this.name,this._getValue()))}}class ${constructor(e){this.value=void 0,this.committer=e}setValue(e){e===w||W(e)&&e===this.value||(this.value=e,g(e)||(this.committer.dirty=!0))}commit(){for(;g(this.value);){const e=this.value;this.value=w,e(this)}this.value!==w&&this.committer.commit()}}class B{constructor(e){this.value=void 0,this.__pendingValue=void 0,this.options=e}appendInto(e){this.startNode=e.appendChild(M()),this.endNode=e.appendChild(M())}insertAfterNode(e){this.startNode=e,this.endNode=e.nextSibling}appendIntoPart(e){e.__insert(this.startNode=M()),e.__insert(this.endNode=M())}insertAfterPart(e){e.__insert(this.startNode=M()),this.endNode=e.endNode,e.endNode=this.startNode}setValue(e){this.__pendingValue=e}commit(){if(null===this.startNode.parentNode)return;for(;g(this.__pendingValue);){const e=this.__pendingValue;this.__pendingValue=w,e(this)}const e=this.__pendingValue;e!==w&&(W(e)?e!==this.value&&this.__commitText(e):e instanceof I?this.__commitTemplateResult(e):e instanceof Node?this.__commitNode(e):H(e)?this.__commitIterable(e):e===x?(this.value=x,this.clear()):this.__commitText(e))}__insert(e){this.endNode.parentNode.insertBefore(e,this.endNode)}__commitNode(e){this.value!==e&&(this.clear(),this.__insert(e),this.value=e)}__commitText(e){const t=this.startNode.nextSibling,n="string"==typeof(e=null==e?"":e)?e:String(e);t===this.endNode.previousSibling&&3===t.nodeType?t.data=n:this.__commitNode(document.createTextNode(n)),this.value=e}__commitTemplateResult(e){const t=this.options.templateFactory(e);if(this.value instanceof O&&this.value.template===t)this.value.update(e.values);else{const n=new O(t,e.processor,this.options),s=n._clone();n.update(e.values),this.__commitNode(s),this.value=n}}__commitIterable(e){Array.isArray(this.value)||(this.value=[],this.clear());const t=this.value;let n,s=0;for(const i of e)n=t[s],void 0===n&&(n=new B(this.options),t.push(n),0===s?n.appendIntoPart(this):n.insertAfterPart(t[s-1])),n.setValue(i),n.commit(),s++;s<t.length&&(t.length=s,this.clear(n&&n.endNode))}clear(e=this.startNode){_(this.startNode.parentNode,e.nextSibling,this.endNode)}}class R{constructor(e,t,n){if(this.value=void 0,this.__pendingValue=void 0,2!==n.length||""!==n[0]||""!==n[1])throw new Error("Boolean attributes can only contain a single expression");this.element=e,this.name=t,this.strings=n}setValue(e){this.__pendingValue=e}commit(){for(;g(this.__pendingValue);){const e=this.__pendingValue;this.__pendingValue=w,e(this)}if(this.__pendingValue===w)return;const e=!!this.__pendingValue;this.value!==e&&(e?this.element.setAttribute(this.name,""):this.element.removeAttribute(this.name),this.value=e),this.__pendingValue=w}}class F extends j{constructor(e,t,n){super(e,t,n),this.single=2===n.length&&""===n[0]&&""===n[1]}_createPart(){return new D(this)}_getValue(){return this.single?this.parts[0].value:super._getValue()}commit(){this.dirty&&(this.dirty=!1,this.element[this.name]=this._getValue())}}class D extends ${}let J=!1;(()=>{try{const e={get capture(){return J=!0,!1}};window.addEventListener("test",e,e),window.removeEventListener("test",e,e)}catch(e){}})();class U{constructor(e,t,n){this.value=void 0,this.__pendingValue=void 0,this.element=e,this.eventName=t,this.eventContext=n,this.__boundHandleEvent=e=>this.handleEvent(e)}setValue(e){this.__pendingValue=e}commit(){for(;g(this.__pendingValue);){const e=this.__pendingValue;this.__pendingValue=w,e(this)}if(this.__pendingValue===w)return;const e=this.__pendingValue,t=this.value,n=null==e||null!=t&&(e.capture!==t.capture||e.once!==t.once||e.passive!==t.passive),s=null!=e&&(null==t||n);n&&this.element.removeEventListener(this.eventName,this.__boundHandleEvent,this.__options),s&&(this.__options=z(e),this.element.addEventListener(this.eventName,this.__boundHandleEvent,this.__options)),this.value=e,this.__pendingValue=w}handleEvent(e){"function"==typeof this.value?this.value.call(this.eventContext||this.element,e):this.value.handleEvent(e)}}const z=e=>e&&(J?{capture:e.capture,passive:e.passive,once:e.once}:e.capture);class G{handleAttributeExpressions(e,t,n,s){const i=t[0];if("."===i){return new F(e,t.slice(1),n).parts}if("@"===i)return[new U(e,t.slice(1),s.eventContext)];if("?"===i)return[new R(e,t.slice(1),n)];return new j(e,t,n).parts}handleTextExpression(e){return new B(e)}}const Z=new G;function q(e){let t=K.get(e.type);void 0===t&&(t={stringsArray:new WeakMap,keyString:new Map},K.set(e.type,t));let n=t.stringsArray.get(e.strings);if(void 0!==n)return n;const s=e.strings.join(N);return n=t.keyString.get(s),void 0===n&&(n=new T(e,e.getTemplateElement()),t.keyString.set(s,n)),t.stringsArray.set(e.strings,n),n}const K=new Map,Q=new WeakMap,X=(e,t,n)=>{let s=Q.get(t);void 0===s&&(_(t,t.firstChild),Q.set(t,s=new B(Object.assign({templateFactory:q},n))),s.appendInto(t)),s.setValue(e),s.commit()};"undefined"!=typeof window&&(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.3.0");const Y=(e,...t)=>new I(e,t,"html",Z),ee=(e,...t)=>new C(e,t,"svg",Z),te=e=>X(x,e),ne=(...e)=>{},se=(e=ne)=>new Promise((e=>setTimeout(e))).then(e),ie=(e,t)=>{const n=new Map;return(...s)=>{let i;if("function"==typeof t){const r=t.apply(e,s);!1===r?(i=JSON.stringify(s),n.delete(i)):!0!==r&&(i=r)}if(void 0===i&&(i=JSON.stringify(s)),n.has(i))return n.get(i);const r=e.apply(e,s);return n.set(i,r),r}};function re(e){if("true"===e||"false"===e)return"true"===e;if("null"===e)return null;if("undefined"!==e){if(""!==e&&!isNaN(Number(e)))return Number(e);try{return JSON.parse(e)}catch(e){}return e}}function oe(e,t=!1){const n=e.replace(/-([a-z])/g,((e,t)=>t.toUpperCase()));return t?n.replace(/^\w/,(e=>e.toUpperCase())):n}function ae(e){return e.replace(/[A-Z]/g,"-$&").toLowerCase()}const le=(e,t)=>{const n=e.startNode.parentNode,s=void 0===t?e.endNode:t.startNode,i=n.insertBefore(M(),s);n.insertBefore(M(),s);const r=new B(e.options);return r.insertAfterNode(i),r},ce=(e,t)=>(e.setValue(t),e.commit(),e),de=(e,t,n)=>{const s=e.startNode.parentNode,i=n?n.startNode:e.endNode,r=t.endNode.nextSibling;r!==i&&b(s,t.startNode,r,i)},ue=e=>{_(e.startNode.parentNode,e.startNode,e.endNode.nextSibling)},he=(e,t,n)=>{const s=new Map;for(let i=t;i<=n;i++)s.set(e[i],i);return s},pe=new WeakMap,fe=new WeakMap,me=v(((e,t,n)=>{let s;return void 0===n?n=t:void 0!==t&&(s=t),t=>{if(!(t instanceof B))throw new Error("repeat can only be used in text bindings");const i=pe.get(t)||[],r=fe.get(t)||[],o=[],a=[],l=[];let c,d,u=0;for(const t of e)l[u]=s?s(t,u):u,a[u]=n(t,u),u++;let h=0,p=i.length-1,f=0,m=a.length-1;for(;h<=p&&f<=m;)if(null===i[h])h++;else if(null===i[p])p--;else if(r[h]===l[f])o[f]=ce(i[h],a[f]),h++,f++;else if(r[p]===l[m])o[m]=ce(i[p],a[m]),p--,m--;else if(r[h]===l[m])o[m]=ce(i[h],a[m]),de(t,i[h],o[m+1]),h++,m--;else if(r[p]===l[f])o[f]=ce(i[p],a[f]),de(t,i[p],i[h]),p--,f++;else if(void 0===c&&(c=he(l,f,m),d=he(r,h,p)),c.has(r[h]))if(c.has(r[p])){const e=d.get(l[f]),n=void 0!==e?i[e]:null;if(null===n){const e=le(t,i[h]);ce(e,a[f]),o[f]=e}else o[f]=ce(n,a[f]),de(t,n,i[h]),i[e]=null;f++}else ue(i[p]),p--;else ue(i[h]),h++;for(;f<=m;){const e=le(t,o[m+1]);ce(e,a[f]),o[f++]=e}for(;h<=p;){const e=i[h++];null!==e&&ue(e)}pe.set(t,o),fe.set(t,l)}})),ve=new WeakMap,ge=v((e=>t=>{if(!(t instanceof B))throw new Error("cache can only be used in text bindings");let n=ve.get(t);void 0===n&&(n=new WeakMap,ve.set(t,n));const s=t.value;if(s instanceof O){if(e instanceof I&&s.template===t.options.templateFactory(e))return void t.setValue(e);{let e=n.get(s.template);void 0===e&&(e={instance:s,nodes:document.createDocumentFragment()},n.set(s.template,e)),b(e.nodes,t.startNode.nextSibling,t.endNode)}}if(e instanceof I){const s=t.options.templateFactory(e),i=n.get(s);void 0!==i&&(t.setValue(i.nodes),t.commit(),t.value=i.instance)}t.setValue(e)})),ye=new WeakMap,be=v(((...e)=>t=>{let n=ye.get(t);void 0===n&&(n={lastRenderedIndex:2147483647,values:[]},ye.set(t,n));const s=n.values;let i=s.length;n.values=e;for(let r=0;r<e.length&&!(r>n.lastRenderedIndex);r++){const o=e[r];if(W(o)||"function"!=typeof o.then){t.setValue(o),n.lastRenderedIndex=r;break}r<i&&o===s[r]||(n.lastRenderedIndex=2147483647,i=0,Promise.resolve(o).then((e=>{const s=n.values.indexOf(o);s>-1&&s<n.lastRenderedIndex&&(n.lastRenderedIndex=s,t.setValue(e),t.commit())})))}})),_e=v((e=>t=>{let n;if(t instanceof U||t instanceof B)throw new Error("The `live` directive is not allowed on text or event bindings");if(t instanceof R)we(t.strings),n=t.element.hasAttribute(t.name),t.value=n;else{const{element:s,name:i,strings:r}=t.committer;if(we(r),t instanceof D){if(n=s[i],n===e)return}else t instanceof $&&(n=s.getAttribute(i));if(n===String(e))return}t.setValue(e)})),we=e=>{if(2!==e.length||""!==e[0]||""!==e[1])throw new Error("`live` bindings can only contain a single expression")},xe=new WeakMap,Ne=v(((e,t)=>n=>{const s=xe.get(n);if(Array.isArray(e)){if(Array.isArray(s)&&s.length===e.length&&e.every(((e,t)=>e===s[t])))return}else if(s===e&&(void 0!==e||xe.has(n)))return;n.setValue(t()),xe.set(n,Array.isArray(e)?Array.from(e):e)}));class Ee{constructor(e){this.classes=new Set,this.changed=!1,this.element=e;const t=(e.getAttribute("class")||"").split(/\s+/);for(const e of t)this.classes.add(e)}add(e){this.classes.add(e),this.changed=!0}remove(e){this.classes.delete(e),this.changed=!0}commit(){if(this.changed){let e="";this.classes.forEach((t=>e+=t+" ")),this.element.setAttribute("class",e)}}}const Ve=new WeakMap,Te=v((e=>t=>{if(!(t instanceof $)||t instanceof D||"class"!==t.committer.name||t.committer.parts.length>1)throw new Error("The `classMap` directive must be used in the `class` attribute and must be the only part in the attribute.");const{committer:n}=t,{element:s}=n;let i=Ve.get(t);void 0===i&&(s.setAttribute("class",n.strings.join(" ")),Ve.set(t,i=new Set));const r=s.classList||new Ee(s);i.forEach((t=>{t in e||(r.remove(t),i.delete(t))}));for(const t in e){const n=e[t];n!=i.has(t)&&(n?(r.add(t),i.add(t)):(r.remove(t),i.delete(t)))}"function"==typeof r.commit&&r.commit()})),Ae=new WeakMap,Se=v((e=>t=>{if(!(t instanceof $)||t instanceof D||"style"!==t.committer.name||t.committer.parts.length>1)throw new Error("The `styleMap` directive must be used in the style attribute and must be the only part in the attribute.");const{committer:n}=t,{style:s}=n.element;let i=Ae.get(t);void 0===i&&(s.cssText=n.strings.join(" "),Ae.set(t,i=new Set)),i.forEach((t=>{t in e||(i.delete(t),-1===t.indexOf("-")?s[t]=null:s.removeProperty(t))}));for(const t in e)i.add(t),-1===t.indexOf("-")?s[t]=e[t]:s.setProperty(t,e[t])})),Me=new WeakMap,ke=v((e=>t=>{const n=Me.get(t);if(void 0===e&&t instanceof $){if(void 0!==n||!Me.has(t)){const e=t.committer.name;t.committer.element.removeAttribute(e)}}else e!==n&&t.setValue(e);Me.set(t,e)}));var Oe=function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),t={},s("next"),s("throw"),s("return"),t[Symbol.asyncIterator]=function(){return this},t);function s(n){t[n]=e[n]&&function(t){return new Promise((function(s,i){(function(e,t,n,s){Promise.resolve(s).then((function(t){e({value:t,done:n})}),t)})(s,i,(t=e[n](t)).done,t.value)}))}}};const Pe=v(((e,t)=>async n=>{var s,i;if(!(n instanceof B))throw new Error("asyncAppend can only be used in text bindings");if(e===n.value)return;let r;n.value=e;let o=0;try{for(var a,l=Oe(e);!(a=await l.next()).done;){let s=a.value;if(n.value!==e)break;0===o&&n.clear(),void 0!==t&&(s=t(s,o));let i=n.startNode;void 0!==r&&(i=M(),r.endNode=i,n.endNode.parentNode.insertBefore(i,n.endNode)),r=new B(n.options),r.insertAfterNode(i),r.setValue(s),r.commit(),o++}}catch(e){s={error:e}}finally{try{a&&!a.done&&(i=l.return)&&await i.call(l)}finally{if(s)throw s.error}}}));var Le=function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),t={},s("next"),s("throw"),s("return"),t[Symbol.asyncIterator]=function(){return this},t);function s(n){t[n]=e[n]&&function(t){return new Promise((function(s,i){(function(e,t,n,s){Promise.resolve(s).then((function(t){e({value:t,done:n})}),t)})(s,i,(t=e[n](t)).done,t.value)}))}}};const Ie=v(((e,t)=>async n=>{var s,i;if(!(n instanceof B))throw new Error("asyncReplace can only be used in text bindings");if(e===n.value)return;const r=new B(n.options);n.value=e;let o=0;try{for(var a,l=Le(e);!(a=await l.next()).done;){let s=a.value;if(n.value!==e)break;0===o&&(n.clear(),r.appendIntoPart(n)),void 0!==t&&(s=t(s,o)),r.setValue(s),r.commit(),o++}}catch(e){s={error:e}}finally{try{a&&!a.done&&(i=l.return)&&await i.call(l)}finally{if(s)throw s.error}}})),Ce=new WeakMap,We=v((e=>t=>{if(!(t instanceof B))throw new Error("templateContent can only be used in text bindings");const n=Ce.get(t);if(void 0!==n&&e===n.template&&t.value===n.fragment)return;const s=document.importNode(e.content,!0);t.setValue(s),Ce.set(t,{template:e,fragment:s})})),He=new WeakMap,je=v((e=>t=>{if(!(t instanceof B))throw new Error("unsafeHTML can only be used in text bindings");const n=He.get(t);if(void 0!==n&&W(e)&&e===n.value&&t.value===n.fragment)return;const s=document.createElement("template");s.innerHTML=e;const i=document.importNode(s.content,!0);t.setValue(i),He.set(t,{value:e,fragment:i})})),$e=new WeakMap,Be=window.navigator.userAgent.indexOf("Trident/")>0,Re=v((e=>t=>{if(!(t instanceof B))throw new Error("unsafeSVG can only be used in text bindings");const n=$e.get(t);if(void 0!==n&&W(e)&&e===n.value&&t.value===n.fragment)return;const s=document.createElement("template"),i=s.content;let r;Be?(s.innerHTML=`<svg>${e}</svg>`,r=i.firstChild):(r=document.createElementNS("http://www.w3.org/2000/svg","svg"),i.appendChild(r),r.innerHTML=e),i.removeChild(r),b(i,r.firstChild);const o=document.importNode(i,!0);t.setValue(o),$e.set(t,{value:e,fragment:o})})),Fe=(e,t,n=(e=>e))=>me(e,n,t),De=v((e=>t=>e(t.element))),Je=new WeakMap,Ue=v(((e,...t)=>{const n=s=>{const i=s.element;if(Je.has(s)){const[i,r]=Je.get(s);r!==e?(i.destroy(),Je.delete(s),n(s)):i.update(...t)}else{const n=e(i,...t);Je.set(s,[n,e])}};return n})),ze=v((e=>t=>{if(!(t instanceof U))throw new Error('"bind" directive can only be used in event listeners');const n=t.element,s=n instanceof HTMLInputElement,i=n instanceof HTMLSelectElement,r=n instanceof HTMLTextAreaElement,o=n instanceof HTMLButtonElement;if(!(s||i||r||o))throw new Error('"bind" directive can only be applied to input/select/textarea/button elements.');t.setValue((function(...t){let r=n.defaultValue;if(i&&n.options.length>0){const e=n.selectedIndex>=0?n.selectedIndex:0;r=n.options[e].value}else if(s)switch(n.type){case"number":case"range":r=n.valueAsNumber;break;case"checkbox":case"radio":r=!!n.checked;break;case"time":case"date":case"datetime":case"datetime-local":r=n.valueAsDate;break;default:r=n.value}else r=n.value;e.call(this,r,...t)}))})),Ge=(e,...t)=>function(...n){e.call(this,...n,...t)},Ze=v((e=>t=>{if(!(t instanceof U))throw new Error('"capture" directive can only be used in event listeners');t.setValue("object"==typeof e?{...e,capture:!0}:{handleEvent:e,capture:!0})})),qe=v((e=>t=>{if(!(t instanceof U))throw new Error('"once" directive can only be used in event listeners');t.setValue("object"==typeof e?{...e,once:!0}:{handleEvent:e,once:!0})})),Ke=v((e=>t=>{if(!(t instanceof U))throw new Error('"passive" directive can only be used in event listeners');t.setValue("object"==typeof e?{...e,passive:!0}:{handleEvent:e,passive:!0})})),Qe=v((e=>t=>{if(!(t instanceof U))throw new Error('"prevent" directive can only be used in event listeners');const{handleEvent:n,...s}=e;t.setValue({handleEvent:function(t){t.preventDefault(),(n||e).call(this,t)},...s})})),Xe=v(((e,t=!1)=>n=>{if(!(n instanceof U))throw new Error('"stop" directive can only be used in event listeners');const{handleEvent:s,...i}=e;n.setValue({handleEvent:function(n){t?n.stopImmediatePropagation():n.stopPropagation(),(s||e).call(this,n)},...i})})),Ye=v((e=>t=>{if(!(t instanceof U))throw new Error('"self" directive can only be used in event listeners');const{handleEvent:n,...s}=e;t.setValue({handleEvent:function(t){t.target===t.currentTarget&&(n||e).call(this,t)},...s})})),{observe:et,computed:tt,dispose:nt}=f,st=({render:e=(()=>x),state:t={},target:n=document.body,...s},...i)=>{const r="function"==typeof t?t(...i):t;Object.entries(n.dataset).forEach((([e,t])=>{e in r&&(r[e]=re(t))}));const o=et(r,{batch:!0,deep:!0,bind:!0,...s}),a=(e,t,{bubbles:s=!1,cancelable:i=!0}={})=>{n.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:s,cancelable:i}))};let l=!1;const c=()=>{X(e(o,a,...i),n),l||(a("mount",r),l=!0),a("update",r)},d=tt((({computeAsync:e})=>l&&!document.contains(n)?f():(a("state",r),Promise.resolve().then((()=>e(c))).catch((e=>a("error",e)))))),u=new Set,h=new Set,p=new MutationObserver((e=>{e.forEach((e=>{if("attributes"!==e.type)return;const t=e.target,n=oe(e.attributeName.replace("data-",""));if(!(n in o))return;const s=t.getAttribute(e.attributeName);if(s!==e.oldValue){const e=re(s);o[n]!==e&&(o[n]=e)}}))}));p.observe(n,{attributeFilter:Object.entries(r).reduce(((e,[t,n])=>("function"!=typeof n&&e.push("data-"+ae(t)),e)),[]),attributeOldValue:!0,characterData:!1,childList:!1,subtree:!1});const f=(e=ne)=>{p.disconnect(),nt(d),h.forEach((e=>e())),h.clear(),a("destroy",r),u.forEach((e=>e())),u.clear(),te(n),e(r)};return{on:(e,t,s)=>{n.addEventListener(e,t,s);const i=()=>(n.removeEventListener(e,t,s),u.delete(i));return u.add(i),i},ctx:e=>e(...i),model:r,state:o,effect:(e,t)=>{const n=tt(e,t),s=()=>(nt(n),h.delete(s));return h.add(s),s},target:n,destroy:f,render:c}},it=({target:e,...t},...n)=>{e.length||(e=[e]);const s=Array.prototype.map.call(e,(e=>st({...t,target:e},...n)));return{...s,effect:(e,t)=>{const n=s.map((n=>n.effect(e(n.state),t)));return()=>n.forEach((e=>e()))},on:(...e)=>{const t=s.map((t=>t.on(...e)));return()=>t.forEach((e=>e()))},destroy:e=>s.forEach((t=>t.destroy(e))),render:()=>s.forEach((e=>e.render())),state:e=>{s.forEach((t=>e(t.state)))},ctx:e=>e(...n),forEach:Array.prototype.forEach.bind(s),target:e}};export{st as $,it as $$,j as AttributeCommitter,$ as AttributePart,R as BooleanAttributePart,G as DefaultTemplateProcessor,U as EventPart,B as NodePart,F as PropertyCommitter,D as PropertyPart,C as SVGTemplateResult,T as Template,O as TemplateInstance,I as TemplateResult,Pe as asyncAppend,Ie as asyncReplace,re as attrToVal,ze as bind,ge as cache,Ge as call,oe as camelCase,Ze as capture,Te as classMap,tt as computed,M as createMarker,Ue as decorator,Z as defaultTemplateProcessor,v as directive,nt as dispose,Fe as each,Ne as guard,Y as html,ke as ifDefined,g as isDirective,H as isIterable,W as isPrimitive,S as isTemplatePartActive,ae as kebabCase,_e as live,ie as memo,w as noChange,ne as noop,x as nothing,et as observe,qe as once,Q as parts,Ke as passive,Qe as prevent,De as ref,_ as removeNodes,X as render,b as reparentNodes,me as repeat,Ye as self,Xe as stop,Se as styleMap,ee as svg,K as templateCaches,We as templateContent,q as templateFactory,se as tick,te as unrender,je as unsafeHTML,Re as unsafeSVG,be as until};
//# sourceMappingURL=perlite.min.mjs.map