@rusticarcade/palette 0.4.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/dev/index.js +588 -722
- package/dist/prod/index.d.ts +154 -360
- package/dist/prod/index.js +1 -1
- package/dist/test/index.d.ts +128 -317
- package/dist/test/index.js +14 -210
- package/package.json +1 -1
package/dist/prod/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class U extends Error{name="PaletteError";code;constructor(L,...Y){let W=`Code: ${L}`;super(W);this.code=L}}function D(L){if(typeof L==="string"||typeof L==="number")return`${L}`;if(L===!0)return"";if(L===null||L===!1||L===void 0)return null;return L.toString()}function V(L){let Y=new Map;if(L instanceof HTMLElement){for(let W of L.getAttributeNames())Y.set(W,D(L.getAttribute(W)));return Y}if(L instanceof Map){for(let[W,Z]of L)Y.set(W,D(Z));return Y}if(typeof L==="object"&&L!==null){for(let[W,Z]of Object.entries(L))Y.set(W,D(Z));return Y}throw new U(0)}function s(L,Y){let W=new Set(L.getAttributeNames()),Z=new Set(Y.keys()),Q=W.difference(Z);for(let X of Q)L.removeAttribute(X);for(let[X,G]of Y)if(G===null)L.removeAttribute(X);else L.setAttribute(X,G)}function E(L){for(let Y=0;Y<L.length;Y++){let W=L.charAt(Y);if(!(W==="-"||W>="A"&&W<="Z"||W>="a"&&W<="z"))return!1}return!0}function l(L,Y){if(Y[0]==="#"&&Y.indexOf(" ")===-1&&Y.indexOf(".")===-1&&Y.indexOf("[")===-1&&Y.indexOf(":")===-1&&Y.indexOf(">")===-1)return L.id===Y.slice(1);if(Y[0]==="."&&Y.indexOf(" ")===-1&&Y.indexOf("#")===-1&&Y.indexOf("[")===-1&&Y.indexOf(":")===-1&&Y.indexOf(">")===-1)return L.classList.contains(Y.slice(1));if(E(Y))return L.tagName.toLowerCase()===Y.toLowerCase();if(Y[0]==="["&&Y[Y.length-1]==="]"&&Y.indexOf(" ")===-1&&Y.indexOf(":")===-1){let W=Y.slice(1,-1),Z=W.indexOf("=");if(Z===-1)return L.hasAttribute(W);let Q=W.slice(0,Z),X=W.slice(Z+1).replace(/^["']|["']$/g,"");return L.getAttribute(Q)===X}return L.matches(Y)}class q{_maxSize;_data;_metrics={hits:0,misses:0};constructor(L=500){if(L<=0)throw Error("LRU Cache capacity must be >= 1");this._maxSize=L,this._data=new Map}_trim=()=>{while(this._data.size>this._maxSize){let L=this._data.keys().next().value;if(L===void 0)throw Error("Absurd");this._data.delete(L)}};getMetrics(){}setCapacity=(L)=>{L<=0,this._maxSize=L,this._trim()};get(L){let Y=this._data.get(L);if(Y===void 0)return;return this._data.delete(L),this._data.set(L,Y),Y}set(L,Y){if(this._data.has(L))this._data.delete(L);if(this._data.set(L,Y),this._data.size>this._maxSize)this._trim()}clear(){this._data.clear()}get size(){return this._data.size}}var o=q;var N=new o;function k(L){let Y=N.get(L);if(Y!==void 0)return Y.cloneNode(!0);let W=document.createElement("template");return W.innerHTML=L,N.set(L,W.content),W.content.cloneNode(!0)}function n(L,Y){N.set(L,Y)}function J2(L){if(typeof L==="function"){let Y=L.tagName;if(!E(Y))throw new U(203,L.name,L.tagName);return Y}if(typeof L==="string")return L;throw new U(200,String(L))}function u(L,...Y){let W=L[0]??"";for(let Q=0;Q<Y.length;Q++){let X=Y[Q]??"",G=L[Q+1]??"";W+=J2(X),W+=G}let Z=new CSSStyleSheet;return Z.replaceSync(W),Z}function m(...L){let Y="";for(let W=0;W<L.length;W++){let Z=L[W];if(!Z)continue;if(typeof Z==="string"||typeof Z==="number"){if(Y)Y+=" ";Y+=Z;continue}if(Array.isArray(Z)){let Q=m(...Z);if(Q){if(Y)Y+=" ";Y+=Q}continue}if(typeof Z==="object"){for(let Q in Z)if(Z[Q]){if(Y)Y+=" ";Y+=Q}}}return Y}function I2(L){if(L instanceof HTMLTemplateElement)return L.innerHTML;if(typeof L==="function"&&(L.prototype instanceof w||L===w)){let Y=L.tagName;if(!E(Y))throw new U(203,L.name,L.tagName);return Y}if(typeof L==="string")return`<span ::swap="${L}"></span>`;throw new U(200,String(L))}function B2(L,...Y){let W=L.reduce((Q,X,G)=>{let M=Y[G]?`${I2(Y[G])}`:"";return Q+X+M},""),Z=document.createElement("template");return Z.innerHTML=W,Z}var A2=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),x2=new Set(["add","delete","clear","set"]);class S{_data;_listeners=new Set;_proxy;_proxyCache=new WeakMap;_reverseProxyCache=new WeakMap;_isLocked=!1;constructor(L,Y){if(this._data=L,this.get=this.get.bind(this),Y)this._listeners.add(Y)}_createProxy(L,Y=[]){if(typeof L!=="object"||L===null)return L;let W=this._proxyCache.get(L);if(W)return W;let Z=new Proxy(L,{get:(Q,X)=>{if(typeof X==="symbol")return Q[X];let G=Q[X];if((Q instanceof Set||Q instanceof Map||Array.isArray(Q))&&typeof G==="function"){let H=(Array.isArray(Q)?A2:x2).has(X);return(...O)=>{let $=this.snapshot(),F=$;for(let z of Y)F=F[z];let _=F[X](...O);if(H){if(this._isLocked)throw new U(305);this._processIncomingState($)}return _}}if(typeof G==="object"&&G!==null)return this._createProxy(G,[...Y,X]);return G},set:(Q,X,G)=>{if(this._isLocked)throw new U(305);if(typeof X==="symbol")return!1;let M=[...Y,X];return this._setNested(M,this._unwrapProxy(G)),!0},has:(Q,X)=>{return X in Q},ownKeys:(Q)=>{return Reflect.ownKeys(Q)},getOwnPropertyDescriptor:(Q,X)=>{let G=Object.getOwnPropertyDescriptor(Q,X);if(G)G.configurable=!0;return G},deleteProperty:(Q,X)=>{if(typeof X==="symbol"||!(X in Q))return!1;let G=[...Y,X];return this._setNested(G,void 0),!0}});return this._proxyCache.set(L,Z),this._reverseProxyCache.set(Z,L),Z}_unwrapProxy(L){if(typeof L!=="object"||L===null)return L;let Y=this._reverseProxyCache.get(L);if(Y)return Y;if(Array.isArray(L))return L.map((W)=>this._unwrapProxy(W));if(Object.getPrototypeOf(L)===Object.prototype){let W={};for(let Z in L)if(Object.hasOwn(L,Z))W[Z]=this._unwrapProxy(L[Z]);return W}return L}_setNested(L,Y){if(!L.length)return;let W=this._data;for(let Q=0;Q<L.length-1;Q++){let X=L[Q]??"";if(W===void 0)throw new U(303,L.join("."));W=W[X]}let Z=L[L.length-1]??"";if(W===void 0)throw new U(303,L.join("."));if(W[Z]!==Y&&!Object.is(W[Z],Y))W[Z]=Y,this._emit(this.current)}_processIncomingState=(L)=>{if(typeof L!=="object"||L===null||Array.isArray(L))throw new U(304,JSON.stringify(L));let Y=!1;for(let[W,Z]of Object.entries(L)){let Q=this._data[W];if(!Object.is(Q,Z))Y=!0,this._data[W]=Z}if(Y)this._emit(this._data)};_emit=(L)=>{for(let Y of this._listeners)Y(L)};get current(){return this._data}get live(){if(!this._proxy)this._proxy=this._createProxy(this._data);return this._proxy}get isLocked(){return this._isLocked}addListener=(L)=>{this._listeners.add(L)};removeListener=(L)=>{this._listeners.delete(L)};get=(L)=>{return this._data[L]};snapshot=()=>{return structuredClone(this._data)};set=(L,Y)=>{if(this._isLocked)throw new U(305);let W={};W[L]=Y,this._processIncomingState(W)};patch=(L)=>{if(this._isLocked)throw new U(305);return this._processIncomingState(L),this};replace=(L)=>{if(this._isLocked)throw new U(305);return this._data=L,this._emit(this._data),this};lock=()=>{if(this._isLocked)throw new U(305);return this._isLocked=!0,this};unlock=()=>{return this._isLocked=!1,this};mutate=(L)=>{if(this._isLocked)throw new U(305);return this._processIncomingState(L(this.snapshot())),this};mutateAsync=async(L,Y=!1)=>{if(this._isLocked)throw new U(305);if(Y)this._isLocked=!0;let W=await L(this.snapshot());if(this._processIncomingState(W),Y)this._isLocked=!1;return this};transaction=(L)=>{if(this._isLocked)throw new U(305);this._isLocked=!0;let Y=!0;try{let W=new S(this.snapshot());L(W),this._processIncomingState(W.current)}catch(W){Y=!1}finally{this._isLocked=!1}return Y};transactionAsync=async(L)=>{if(this._isLocked)throw new U(305);this._isLocked=!0;let Y=!0;try{let W=new S(this.snapshot());await L(W),this._processIncomingState(W.current)}catch(W){Y=!1}finally{this._isLocked=!1}return Y}}var P="data-node-ref";var j2={["@"]:"attr",["$"]:"state",["*"]:"data",["#"]:"item"},T2=new Map(Object.entries(j2)),y=new q;function h(L){let Y=y.get(L);if(Y)return Y;let W=!1,Z="",Q=[],X=!0;for(let M of L)if(X&&M==="!")W=!0;else if(X){let H=T2.get(M);if(!H)throw new U(201,L);Q.push(H),X=!1}else if(M===".")if(Z.length)Q.push(Z),Z="";else throw new U(201,L);else Z+=M;if(!Z.length)throw new U(201,L);if(Q.push(Z),Q.length<2)throw new U(201,L);let G={base:L,path:Q,modifiers:W?{not:!0}:void 0};return y.set(L,G),G}var g=new q;function p(L){let{path:Y,modifiers:W,base:Z}=L,Q=g.get(Z);if(Q)return Q;if(Y.length<2)throw new U(0);let X=(G)=>{let M=G;for(let H of Y){if(!M||typeof M!=="object")return null;M=M[H]}if(W?.not){if(Y[0]==="attr")return M!==""&&!M;return!M}return M};return g.set(Z,X),X}function c(L){let Y=k(L),W=document.createElement("template");return W.content.appendChild(Y),new R(W)}function r(L){let Y=document.createTreeWalker(L,NodeFilter.SHOW_ELEMENT),W=new Set,Z=[],Q=Y.nextNode();while(Q){if(!(Q instanceof HTMLElement)){Q=Y.nextNode();continue}let X=Q.parentNode,G=!1;while(X&&!G){if(W.has(X)||X instanceof HTMLElement&&(X.hasAttribute("::each")||X.hasAttribute("::if")||X.hasAttribute("::else")||X.hasAttribute("::else-if"))){G=!0,W.add(Q);break}X=X.parentNode}if(!G)Z.push(Q);Q=Y.nextNode()}return Z}var f2=new Set(["::each","::if","::else-if","::key","::swap","::tag"]),v=new q;function t(L){let Y=v.get(L);if(Y)return Y;let W=new Map,Z=[],Q=0,X=(_)=>{let z=_.getAttribute(P);if(!z)z=`el-${Q++}`,_.setAttribute(P,z);return z},G=L.content.cloneNode(!0),M=r(G);for(let _ of M){let z=V(_);for(let[I,j]of z){if(j===null||I[0]!==":")continue;if(I[1]!==":"){let J=I.slice(1),x={type:"attr",notation:h(j),attribute:J,nodeRef:X(_)};Z.push(x)}if(I==="::key"){if(!z.has("::each"))throw new U(208);continue}if(f2.has(I)&&j==="")throw new U(202,I);let B=W.get(j);if(B===void 0)B=h(j),W.set(j,B);if(_.removeAttribute(I),I==="::tag")Z.push({type:"tag",notation:B,nodeRef:X(_)});else if(I==="::each"){let J=X(_),x=_.getAttribute("::key");if(x===null)throw new U(205);_.removeAttribute("::key");let K=_.innerHTML;while(_.firstChild)_.removeChild(_.firstChild);let f={type:"each",notation:B,keyNotation:h(x),nodeRef:J,listContentHtml:K};Z.push(f)}else if(I==="::swap"){let J={type:"swap",notation:B,nodeRef:X(_)};Z.push(J)}else if(I==="::if"){let J={type:"cond",branches:[]};_.removeAttribute("::if");let x={type:"::if",notation:B,branchRootRef:X(_),branchTemplateHTML:_.innerHTML};J.branches.push(x);let K=_.nextElementSibling;while(K?.hasAttribute("::else-if")){if(!(K instanceof HTMLElement))break;let f=K.getAttribute("::else-if");if(!f)throw new U(202,"::else-if");let C=W.get(f);if(C===void 0)C=h(f),W.set(f,C);K.removeAttribute("::else-if");let $2={type:"::else-if",notation:C,branchRootRef:X(K),branchTemplateHTML:K.innerHTML};J.branches.push($2),K=K.nextElementSibling}if(K&&K instanceof HTMLElement&&K?.hasAttribute("::else")){K.removeAttribute("::else");let f={type:"::else",branchRootRef:X(K),branchTemplateHTML:K.innerHTML};J.branches.push(f)}Z.push(J)}}}let H={};for(let[_,z]of W)H[_]=z;let O=document.createElement("div");O.appendChild(G.cloneNode(!0));let $=O.innerHTML,F={html:$,schemes:Z,notations:H};return v.set(L,F),n($,G),F}var A=Symbol("noop");function a(L,Y){let W=Y.get(L.notation.base),Z=typeof W==="function"?W(L.node):W;if(L.attribute==="class"&&typeof Z!=="string")Z=m(Z);let Q=D(Z),X=L.node.getAttribute(L.attribute);if(Q!==X)return[L.node,L.attribute,Q];return A}function e(L){for(let[Y,W,Z]of L)if(Z===null)Y.removeAttribute(W);else Y.setAttribute(W,Z)}function L2(L,Y){let W=null;for(let Z of L.branches)if(Z.type==="::else"){W=Z;break}else{let Q=Y.get(Z.notation.base);if(typeof Q==="function"?Q(L.start):Q){W=Z;break}}return[L,W,Y]}function Y2(L){for(let[Y,W,Z]of L){let Q=Y.start.parentNode;if(!Q)throw new U(209);if(W===null||!Object.is(Y.currentRoot,W.branchRoot)){let X=new Set,G=Y.start;while(G&&G!==Y.end){if(G instanceof HTMLElement)X.add(G);G=G.nextSibling}for(let M of X)Q.removeChild(M);if(W)Q.insertBefore(W.branchRoot,Y.end)}if(W===null)continue;W.branchTemplate.renderWithValues(W.branchRoot,Z)}}function D2(L,Y){let W=Y.get(L.notation.base),Z=typeof W==="function"?W(L.startMarker.parentNode):W;if(Z===null||Z===void 0)return[];if(Array.isArray(Z))return Z;throw new U(204)}function R2(L,Y){let W=L,Z=new Set;while(W&&W!==Y){if(W instanceof HTMLElement)Z.add(W);W=W.nextSibling}return Z}function W2(L,Y){let W=D2(L,Y);if(W.length===0)return[L,[]];let{rowTemplatesByRoot:Z,rowTemplateElement:Q,rowRootPrototype:X}=L,G=p(L.keyNotation),M=new Map;for(let H of W){let O={item:H},$=G(O);if(M.has($))throw new U(206,String($));let F=L.rowRootsByKey.get($);if(F===void 0)F=X.cloneNode(!1),L.rowRootsByKey.set($,F);let _=Z.get(F);if(_===void 0)_=new R(Q),Z.set(F,_);let z={context:O,root:F,template:_,attrMap:V(H)};M.set($,z)}for(let[H,O]of L.rowRootsByKey)if(!M.has(H))L.rowRootsByKey.delete(H),L.rowTemplatesByRoot.delete(O);return[L,Array.from(M.values())]}function Z2(L){for(let[Y,W]of L){let{endMarker:Z,listContainer:Q}=Y;if(W.length===0){for(let H of Y.rowRootsByKey.values())H.remove();Y.rowRootsByKey.clear();continue}let X=Array.from(R2(Y.startMarker,Y.endMarker)),G=new Set,M=0;for(let H of W){let{root:O,attrMap:$,context:F,template:_}=H,z=X[M];if(s(O,$),_.render(O,F),G.add(O),Object.is(z,O)){M+=1;continue}if(!z){Q.insertBefore(O,Z);continue}Q.insertBefore(O,z)}for(let H of X)if(!G.has(H))H.remove(),Y.rowTemplatesByRoot.delete(H)}}function Q2(L,Y){let W=Y.get(L.notation.base),Z=typeof W==="function"?W(L.node):W;if(typeof Z==="string"||typeof Z==="number"||typeof Z==="boolean"){let Q=`${Z}`;if(L.node.textContent===Q)return A;return[L,document.createTextNode(Q)]}else if(Z===null||Z===void 0){if(L.node instanceof Comment)return A;return[L,document.createComment("empty")]}else if(Z instanceof HTMLElement){if(Object.is(L.node,Z))return A;return[L,Z.cloneNode(!0)]}else throw new U(302,typeof Z,JSON.stringify(Z))}function X2(L){for(let[Y,W]of L){let Z=Y.node.parentNode;if(!Z)throw new U(0);Z.replaceChild(W,Y.node),Y.node=W}}function w2(L,Y){let W=document.createElement(Y);while(L.firstChild!==null)W.appendChild(L.firstChild);for(let Z of L.getAttributeNames()){let Q=L.getAttribute(Z);if(Q!==null)W.setAttribute(Z,Q)}return L.replaceWith(W),W}function G2(L,Y){let W=Y.get(L.notation.base)??"",Q=`${typeof W==="function"?W(L.node):W}`.toLowerCase(),X=L.node.tagName.toLowerCase();if(!Q||Q===X)return A;return[L,Q]}function U2(L){for(let[Y,W]of L)Y.node=w2(Y.node,W)}function _2(L,Y){let W={conditionals:[],attributes:[],swaps:[],tags:[],lists:[]};for(let Z of L)switch(Z.type){case"cond":{let Q=L2(Z,Y);if(Q!==A)W.conditionals.push(Q);break}case"attr":{let Q=a(Z,Y);if(Q!==A)W.attributes.push(Q);break}case"each":{let Q=W2(Z,Y);if(Q!==A)W.lists.push(Q);break}case"swap":{let Q=Q2(Z,Y);if(Q!==A)W.swaps.push(Q);break}case"tag":{let Q=G2(Z,Y);if(Q!==A)W.tags.push(Q);break}default:throw new U(0)}return W}function F2(L){Y2(L.conditionals),e(L.attributes),Z2(L.lists),X2(L.swaps),U2(L.tags)}var i=(L)=>{if(!L.parentNode)throw new U(209);return L.parentNode},M2=(L,Y="")=>{let W=i(L),Z=document.createComment(Y);return W.insertBefore(Z,L),Z},H2=(L,Y="")=>{let W=i(L),Z=document.createComment(Y);return W.insertBefore(Z,L.nextSibling),Z};function K2(L,Y){let W=new Map,Z=new Map,Q=new Set,X=new Map;for(let[F,_]of Object.entries(L.notations))Z.set(F,p(_));let G=Y??k(L.html),M=document.createTreeWalker(G,NodeFilter.SHOW_ELEMENT,{acceptNode(F){return F.hasAttribute(P)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}}),H=M.nextNode();while(H){if(!(H instanceof HTMLElement))continue;let F=H.getAttribute(P);if(F===null)throw new U(0);X.set(F,H),H.removeAttribute(P),H=M.nextNode()}let O=(F,_)=>{let z=W.get(_);if(!z)z=new Set,W.set(_,z);z.add(F)},$=(F)=>{let _=X.get(F);if(_)return _;throw new U(3)};for(let F of L.schemes)if(F.type==="each"){let _=$(F.nodeRef),z=i(_),I=_.cloneNode(!1),j=M2(_),B=H2(_);_.remove();let J=k(F.listContentHtml),x=document.createElement("template");x.content.appendChild(J);let K={type:"each",notation:F.notation,keyNotation:F.keyNotation,listContainer:z,rowTemplateElement:x,rowRootPrototype:I,startMarker:j,endMarker:B,rowTemplatesByRoot:new WeakMap,rowRootsByKey:new Map};O(K,F.notation.base)}else if(F.type==="cond"){let _=F.branches[0];if(!_)throw new U(0);let z=$(_.branchRootRef),I=M2(z),j=F.branches[F.branches.length-1],B=$(j.branchRootRef),J=H2(B),x={type:"cond",start:I,end:J,branches:[]};for(let K of F.branches)if(K.type==="::if"||K.type==="::else-if"){let f=$(K.branchRootRef),C=c(K.branchTemplateHTML);Q.add(C),x.branches.push({type:K.type,notation:K.notation,branchRoot:$(K.branchRootRef),branchTemplate:c(K.branchTemplateHTML)}),O(x,K.notation.base),f.remove()}else x.branches.push({type:K.type,branchRoot:$(K.branchRootRef),branchTemplate:c(K.branchTemplateHTML)})}else if(F.type==="swap"||F.type==="tag"){let _={type:F.type,notation:F.notation,node:$(F.nodeRef)};O(_,F.notation.base)}else if(F.type==="attr"){let _={type:"attr",attribute:F.attribute,notation:F.notation,node:$(F.nodeRef)};O(_,_.notation.base)}return{plansByNotation:W,notationAccessors:Z,fragment:G,subtemplates:Q}}class R{static cache={clear:()=>{N.clear(),v.clear(),g.clear(),y.clear()},setCapacity:(L)=>{N.setCapacity(L),v.setCapacity(L),g.setCapacity(L),y.setCapacity(L)}};_compiled;_templateElement;_mountedRoot;_latestRenderedValues=new Map;_fragment;_plansByNotation=new Map;_notationAccessors=new Map;_subtemplates=new Set;constructor(L){this._templateElement=L,this._compiled=t(L);let Y=k(this._compiled.html),W=K2(this._compiled,Y);this._plansByNotation=W.plansByNotation,this._notationAccessors=W.notationAccessors,this._fragment=W.fragment,this._subtemplates=W.subtemplates;let Z=new Map(this._notationAccessors);for(let Q of this._subtemplates)for(let[X,G]of Q.notationMap)Z.set(X,G);this._notationAccessors=Z}get compiled(){return this._compiled}get notationMap(){return this._notationAccessors}clone=()=>{return new R(this.element())};element=()=>{if(this._templateElement)return this._templateElement;let L=document.createElement("template");return L.innerHTML=this._compiled.html,L};_collectUpdatedValues=(L)=>{let Y=new Map,W=!1;for(let[Z,Q]of this._notationAccessors){let X=this._latestRenderedValues.get(Z),G=Q(L);if(Y.set(Z,G),X!==G&&!Object.is(X,G))W=!0}return[W,Y]};_update(L){let Y=new Set;for(let[Z]of L){let Q=this._plansByNotation.get(Z);if(!Q)continue;for(let X of Q)Y.add(X)}let W=_2(Y,L);F2(W)}renderWithValues=(L,Y)=>{if(L!==this._mountedRoot){this._mountedRoot=L;while(L.firstChild)L.removeChild(L.firstChild);L.append(this._fragment)}this._update(Y)};render=(L,Y)=>{let[W,Z]=this._collectUpdatedValues(Y);if(L===this._mountedRoot&&!W)return;this.renderWithValues(L,Z),this._latestRenderedValues=Z}}class b{static nextListenerId=0;static processTargetDescriptor(L){if(L instanceof HTMLElement)if(L.id.length)return`#${L.id}`;else{let Y=`listen-${b.nextListenerId++}`;return L.setAttribute("data-listener-id",Y),`[data-listener-id="${Y}"]`}else if(typeof L==="function")return L.tagName;return L}_root;_rootListeners=new Map;_events=new Map;constructor(L=document){this._root=L}_handlersForEvent(L){let Y=this._events.get(L);if(Y===void 0)Y=new Map,this._events.set(L,Y);return Y}_handlersForEventAndQuery(L,Y){let W=this._handlersForEvent(L),Z=W.get(Y);if(Z===void 0)Z=new Set,W.set(Y,Z);return Z}_createRootListener(L){if(this._rootListeners.has(L))return;let Y=(W)=>{let Z=this._handlersForEvent(L),{target:Q}=W;if(Q===null||!(Q instanceof Node))return;let X=Q,G=!1,M=W.stopImmediatePropagation;W.stopImmediatePropagation=()=>{M.call(W),G=!0};while(X){if(X===this._root)break;if(!(X instanceof Element)){X=X.parentNode;continue}for(let[H,O]of Z)if(H==="*"||l(X,H)){for(let $ of O)if($.call(X,W),G||W.defaultPrevented)return}if(W.cancelBubble)return;if(X=X.parentNode,X===this._root||X instanceof ShadowRoot)break}};this._rootListeners.set(L,Y),this._root.addEventListener(L,Y)}addListener(L,Y,W="*"){this._handlersForEventAndQuery(L,W).add(Y),this._createRootListener(L)}removeListener(L,Y,W){let Z=this._handlersForEventAndQuery(L,W);if(Z.delete(Y),Z.size===0)this._handlersForEvent(L).delete(W)}cleanup=()=>{for(let[L,Y]of this._rootListeners)this._root.removeEventListener(L,Y);this._rootListeners.clear()}}var V2=1e4,q2=document.createElement("template"),z2;((W)=>{W.Closed="closed";W.Open="open"})(z2||={});class w extends HTMLElement{static tagName="";static template=q2;static styles=[];static observedAttributes=[];static rootMode="closed";initialState;computedProperties;liveAttributes;_template;_root;_state;_delegator;_ownListeners=new Set;_cleanupFn;_renderInternals={isFinalized:!1,initialRenderComplete:!1,willRender:!1,isRendering:!1,sequentialRenders:0,postRenderCallbacks:[],lastRenderedAttributeMap:new Map,trackedAttributeChanges:new Map};constructor(){super();let{template:L,styles:Y,rootMode:W}=this.constructor,Z=Array.isArray(Y)?Y:typeof Y==="object"?[Y]:[u`${Y}`];this._root=this.attachShadow({mode:W}),this._root.adoptedStyleSheets.push(...Z),this._template=L instanceof R?L:new R(L)}_getRenderContext(L){return{attr:Object.fromEntries(L),data:typeof this.computedProperties==="function"?this.computedProperties():this.computedProperties,state:this._state?this._state.current:void 0}}_escalateError(L){let Y=this.parentNode;while(Y)if(Y instanceof w&&"onError"in Y&&typeof Y.onError==="function"){Y.onError(L);return}else if(Y instanceof ShadowRoot)Y=Y.host;else Y=Y.parentNode;throw L}_reportError(L){if(!this.onError)this._escalateError(L);else this.onError(L)}_executeAttributeChangeHandlers=()=>{if(!this.liveAttributes)return;let L=this._renderInternals.lastRenderedAttributeMap,Y=new Map(this._renderInternals.trackedAttributeChanges);this._renderInternals.trackedAttributeChanges.clear();for(let[W,Z]of Y){let Q=this.liveAttributes[W];if(!Q)continue;if("onChange"in Q){let X=L.get(W)??null;if(Q&&X!==Z)Q.onChange?.call(this,Z,X)}}};_reflectLiveAttributes=()=>{if(!this.liveAttributes)return;let L=[];for(let[Y,W]of Object.entries(this.liveAttributes))if("reflect"in W){let Z=D(W.reflect?.call(this)),Q=this.getAttribute(Y);if(Z!==Q)L.push([Y,Z])}for(let[Y,W]of L)this.reflectAttribute(Y,W)};_performUpdate=()=>{try{this._renderInternals.isRendering=!0,this._renderInternals.willRender=!1,this._executeAttributeChangeHandlers();let L=this._renderInternals.lastRenderedAttributeMap;this.beforeUpdate?.();let Y=V(this);if(this._template.render(this.root,this._getRenderContext(Y)),this._renderInternals.lastRenderedAttributeMap=Y,this.afterUpdate?.(L),this._reflectLiveAttributes(),this._renderInternals.postRenderCallbacks.length){let W=this._renderInternals.postRenderCallbacks;this._renderInternals.postRenderCallbacks=[];for(let Z of W)Z()}if(this._renderInternals.willRender){if(this._renderInternals.sequentialRenders+=1,this._renderInternals.sequentialRenders>=V2)throw new U(306,`${this._renderInternals.sequentialRenders}`);this._performUpdate()}else this._renderInternals.sequentialRenders=0}catch(L){this._renderInternals.willRender=!1,this._reportError(L)}finally{this._renderInternals.isRendering=!1}};_scheduleUpdate=()=>{if(this._renderInternals.willRender)return;if(this._renderInternals.willRender=!0,this._renderInternals.isRendering)return;requestAnimationFrame(this._performUpdate)};_adoptState(L){if(Object.is(this._state,L))return;if(this._state)this._state.removeListener(this._scheduleUpdate),this._scheduleUpdate();let Y=L instanceof S?L:new S(L);this._state=Y,this._state.removeListener(this._scheduleUpdate),this._state.addListener(this._scheduleUpdate)}connectedCallback(){if(this._renderInternals.initialRenderComplete)return;queueMicrotask(()=>{try{this._renderInternals.isRendering=!0,this._renderInternals.willRender=!1;let L=V(this);if(this.initialState){let Y=typeof this.initialState==="object"?this.initialState:this.initialState();this._adoptState(Y)}this._template.render(this.root,this._getRenderContext(L)),this._reflectLiveAttributes(),this._renderInternals.lastRenderedAttributeMap=L,this._renderInternals.initialRenderComplete=!0,this._cleanupFn=this.script?.()??void 0}catch(L){this._reportError(L)}finally{this._renderInternals.isRendering=!1}})}disconnectedCallback(){if(this._renderInternals.isFinalized)return;queueMicrotask(()=>{if(this.isConnected||!this._renderInternals.initialRenderComplete)return;this._renderInternals.isFinalized=!0;try{if(this._delegator?.cleanup(),this._ownListeners&&this._ownListeners.size>0)for(let L of this._ownListeners)this.removeEventListener(L.event,L.handler);this._cleanupFn?.()}catch(L){this._reportError(L)}finally{try{this.finalize?.()}catch(L){this._reportError(L)}}})}attributeChangedCallback(L,Y,W){if(this._renderInternals.isRendering)return;if(W===this._renderInternals.lastRenderedAttributeMap?.get(L))return;if(this._renderInternals.trackedAttributeChanges.set(L,W),!this._renderInternals.willRender)this._scheduleUpdate()}get root(){return this._root}get isMounted(){return this.isConnected&&this._renderInternals.initialRenderComplete}get state(){if(!this._state)throw new U(301);return this._state.live}set state(L){this._adoptState(L)}getState(){if(!this._state)throw new U(301);return this._state}requestRender(L){if(L)this._renderInternals.postRenderCallbacks.push(L);this._scheduleUpdate()}listen(L,Y,W){let Z=b.processTargetDescriptor(L);if(Z===":host"||Z===":HOST"){if(this._ownListeners===void 0)this._ownListeners=new Set;this.addEventListener(Y,W),this._ownListeners.add({handler:W,event:Y});return}if(!this._delegator)this._delegator=new b(this.root);this._delegator.addListener(Y,W,Z)}stopListening(L,Y,W){let Z=b.processTargetDescriptor(L);if(Z===":host"||Z===":HOST"){if(this._ownListeners===void 0)this._ownListeners=new Set;this.removeEventListener(Y,W);for(let Q of this._ownListeners)if(Q.event===Y&&Q.handler===W)this._ownListeners.delete(Q);return}if(!this._delegator)return;this._delegator.removeListener(Y,W,Z)}dispatchEvent(L,Y,W){if(L instanceof Event)return super.dispatchEvent(L);let Z={bubbles:!0,cancelable:!0,composed:!0,...W??{}};return super.dispatchEvent(new CustomEvent(L,{detail:Y,...Z}))}querySelector(L){return this._root.querySelector(L)}querySelectorAll(L){return this._root.querySelectorAll(L)}getElementById(L){if(this._root instanceof ShadowRoot)return this._root.getElementById(L);else return HTMLElement.prototype.querySelector.call(this,`#${L}`)}requireElementById(L){let Y=this.getElementById(L);if(!Y)throw new U(300);return Y}setAttribute(L,Y){let W=D(Y);if(W===null)HTMLElement.prototype.removeAttribute.call(this,L);else HTMLElement.prototype.setAttribute.call(this,L,W)}getAttribute(L,Y){let W=HTMLElement.prototype.getAttribute.call(this,L);if(Y===void 0)return W;if(typeof Y==="number"){if(W===null)return Y;let Z=Number(W);if(Number.isNaN(Z))return Y;return Z}throw new U(2)}reflectAttribute(L,Y){let W=this.getAttribute(L),Z=D(Y);if(W!==Z)this.setAttribute(L,Z)}toString(){let{tagName:L,name:Y}=this.constructor,W=L===""?Y:L,Z=this.getAttributeNames().map((X)=>{let G=this.getAttribute(X);return G?`${X}="${G}"`:""}).join(" "),Q=Z.length>0?` ${Z}`:"";return`<${W}${Q}></${W}>`}}var k2=document.createElement("template");function O2(L,Y){if(Y&&L.tagName==="")L.tagName=Y;window.customElements.define(L.tagName,L)}function S2(L,Y){if(typeof L==="function")return O2(L),L;if(typeof L==="string"&&typeof Y==="function")return O2(Y,L),Y;if(Y===void 0)throw new U(2);let W=L,Z=Y;if(typeof Z==="function"){if(Z.tagName==="")Z.tagName=W;return window.customElements.define(W,Z),Z}let{template:Q=k2,styles:X=[],shadowRootMode:G="closed",initialState:M,computedProperties:H={},liveAttributes:O={},script:$,beforeUpdate:F,afterUpdate:_,finalize:z,onError:I}=Z,j=Array.from(new Set([...Object.keys(O)])),B=class extends w{static tagName=W;static template=Q;static styles=X;static observedAttributes=[...j];static shadowRootMode=G;constructor(){super();this.initialState=typeof M==="function"?M.bind(this):M,this.computedProperties=typeof H==="function"?H.bind(this):H,this.liveAttributes=O;for(let J of Object.values(this.liveAttributes)){if(J.onChange)J.onChange=J.onChange.bind(this);if(J.reflect)J.reflect=J.reflect.bind(this)}this.script=$?.bind(this)??void 0,this.beforeUpdate=F?.bind(this)??void 0,this.afterUpdate=_?.bind(this)??void 0,this.finalize=z?.bind(this)??void 0,this.onError=I?.bind(this)??void 0}};return customElements.define(W,B),B}export{B2 as html,S2 as define,u as css,m as classify,R as Template,S as State,z2 as RootMode,U as PaletteError,w as Component};
|
|
1
|
+
class F extends Error{name="PaletteError";code;constructor(_,...Q){let Y=`Code: ${_}`;super(Y);this.code=_}}var w2=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),P2=new Set(["add","delete","clear","set"]);class T{static isState(_){return _!==null&&typeof _==="object"&&_ instanceof T}_data;_listeners=new Set;_proxy;_proxyCache=new WeakMap;_reverseProxyCache=new WeakMap;constructor(_,Q){if(this._data=_,Q)this._listeners.add(Q)}_createProxy(_,Q=[]){if(typeof _!=="object"||_===null)return _;let Y=this._proxyCache.get(_);if(Y)return Y;let L=new Proxy(_,{get:(W,Z)=>{if(typeof Z==="symbol")return W[Z];let X=W[Z];if((W instanceof Set||W instanceof Map||Array.isArray(W))&&typeof X==="function"){let M=(Array.isArray(W)?w2:P2).has(Z);return(...J)=>{let $=this.snapshot(),G=$;for(let K of Q)G=G[K];let f=G[Z](...J);if(M)this._processIncomingState($);return f}}if(typeof X==="object"&&X!==null)return this._createProxy(X,[...Q,Z]);return X},set:(W,Z,X)=>{if(typeof Z==="symbol")return!1;let z=[...Q,Z];return this._setNested(z,this._unwrapProxy(X)),!0},has:(W,Z)=>{return Z in W},ownKeys:(W)=>{return Reflect.ownKeys(W)},getOwnPropertyDescriptor:(W,Z)=>{let X=Object.getOwnPropertyDescriptor(W,Z);if(X)X.configurable=!0;return X},deleteProperty:(W,Z)=>{if(typeof Z==="symbol"||!(Z in W))return!1;let X=[...Q,Z];return this._setNested(X,void 0),!0}});return this._proxyCache.set(_,L),this._reverseProxyCache.set(L,_),L}_unwrapProxy(_){if(typeof _!=="object"||_===null)return _;let Q=this._reverseProxyCache.get(_);if(Q)return Q;if(Array.isArray(_))return _.map((Y)=>this._unwrapProxy(Y));if(Object.getPrototypeOf(_)===Object.prototype){let Y={};for(let L in _)if(Object.hasOwn(_,L))Y[L]=this._unwrapProxy(_[L]);return Y}return _}_setNested(_,Q){if(!_.length)return;let Y=this._data;for(let W=0;W<_.length-1;W++){let Z=_[W]??"";if(Y===void 0)throw new F(303,_.join("."));Y=Y[Z]}let L=_[_.length-1]??"";if(Y===void 0)throw new F(303,_.join("."));if(Y[L]!==Q&&!Object.is(Y[L],Q))Y[L]=Q,this._emit(this.raw)}_processIncomingState=(_)=>{if(typeof _!=="object"||_===null||Array.isArray(_))throw new F(304,JSON.stringify(_));let Q=!1;for(let[Y,L]of Object.entries(_)){let W=this._data[Y];if(!Object.is(W,L))Q=!0,this._data[Y]=L}if(Q)this._emit(this._data);return this};_emit=(_)=>{for(let Q of this._listeners)Q(_)};get raw(){return this._data}get live(){if(!this._proxy)this._proxy=this._createProxy(this._data);return this._proxy}addListener=(_)=>{this._listeners.add(_)};removeListener=(_)=>{this._listeners.delete(_)};get=(_)=>{return this._data[_]};snapshot=()=>{return structuredClone(this._data)};set=(_,Q)=>{let Y={};return Y[_]=Q,this._processIncomingState(Y)};patch=(_)=>{return this._processIncomingState(_)};replace=(_)=>{return this._data=_,this._emit(this._data),this};mutate=(_)=>{return this._processIncomingState(_(this.snapshot()))}}class w{_maxSize;_data;_metrics={hits:0,misses:0};constructor(_=500){if(_<=0)throw Error("LRU Cache capacity must be >= 1");this._maxSize=_,this._data=new Map}_trim=()=>{while(this._data.size>this._maxSize){let _=this._data.keys().next().value;if(_===void 0)throw Error("Absurd");this._data.delete(_)}};getMetrics(){}setCapacity=(_)=>{_<=0,this._maxSize=_,this._trim()};get(_){let Q=this._data.get(_);if(Q===void 0)return;return this._data.delete(_),this._data.set(_,Q),Q}set(_,Q){if(this._data.has(_))this._data.delete(_);if(this._data.set(_,Q),this._data.size>this._maxSize)this._trim()}clear(){this._data.clear()}get size(){return this._data.size}}var r=w;var b=new r;function P(_){let Q=b.get(_);if(Q!==void 0)return Q.cloneNode(!0);let Y=document.createElement("template");return Y.innerHTML=_,b.set(_,Y.content),Y.content.cloneNode(!0)}function t(_,Q){b.set(_,Q)}function C(_){if(typeof _==="string"||typeof _==="number")return`${_}`;if(_===!0)return"";if(_===null||_===!1||_===void 0)return null;return _.toString()}function s(_,Q,Y){if(Y===null)_.removeAttribute(Q);else _.setAttribute(Q,Y)}function p(_){let Q={};for(let Y of _.getAttributeNames())Q[Y]=C(_.getAttribute(Y));return Q}function a(_,Q){let Y=new Set(_.getAttributeNames()),L=new Set(Object.keys(Q)),W=Y.difference(L);for(let Z of W)_.removeAttribute(Z);for(let[Z,X]of Object.entries(Q))s(_,Z,C(X))}function e(_){let Q={};for(let[Y,L]of Object.entries(_))Q[Y]=C(L);return Q}function N(_){for(let Q=0;Q<_.length;Q++){let Y=_.charAt(Q);if(!(Y==="-"||Y>="A"&&Y<="Z"||Y>="a"&&Y<="z"))return!1}return!0}function _2(_,Q){if(Q[0]==="#"&&Q.indexOf(" ")===-1&&Q.indexOf(".")===-1&&Q.indexOf("[")===-1&&Q.indexOf(":")===-1&&Q.indexOf(">")===-1)return _.id===Q.slice(1);if(Q[0]==="."&&Q.indexOf(" ")===-1&&Q.indexOf("#")===-1&&Q.indexOf("[")===-1&&Q.indexOf(":")===-1&&Q.indexOf(">")===-1)return _.classList.contains(Q.slice(1));if(N(Q))return _.tagName.toLowerCase()===Q.toLowerCase();if(Q[0]==="["&&Q[Q.length-1]==="]"&&Q.indexOf(" ")===-1&&Q.indexOf(":")===-1){let Y=Q.slice(1,-1),L=Y.indexOf("=");if(L===-1)return _.hasAttribute(Y);let W=Y.slice(0,L),Z=Y.slice(L+1).replace(/^["']|["']$/g,"");return _.getAttribute(W)===Z}return _.matches(Q)}function Q2(_,Q){let Y=_.parentNode;while(Y!==null){if(Q(Y))return!0;if(i(Y))Y=Y.host;else Y=Y.parentNode}return!1}function Y2(_){return _!==null&&typeof _==="object"&&_ instanceof Element}function U(_){return _!==null&&typeof _==="object"&&_ instanceof HTMLElement}function L2(_){return _!==null&&typeof _==="object"&&_ instanceof HTMLTemplateElement}function i(_){return _!==null&&typeof _==="object"&&_ instanceof ShadowRoot}function W2(_){return _!==null&&typeof _==="object"&&_ instanceof Node}function Z2(_){return _!==null&&typeof _==="object"&&_ instanceof Comment}var q="data-node-ref";var q2={["@"]:"attr",["$"]:"state",["*"]:"data",["#"]:"item"},S2=new Map(Object.entries(q2)),g=new w;function h(_){let Q=g.get(_);if(Q)return Q;let Y=!1,L="",W=[],Z=!0;for(let z of _)if(Z&&z==="!")Y=!0;else if(Z){let M=S2.get(z);if(!M)throw new F(201,_);W.push(M),Z=!1}else if(z===".")if(L.length)W.push(L),L="";else throw new F(201,_);else L+=z;if(!L.length)throw new F(201,_);if(W.push(L),W.length<2)throw new F(201,_);let X={base:_,path:W,modifiers:Y?{not:!0}:void 0};return g.set(_,X),X}var E=new w;function c(_){let{path:Q,modifiers:Y,base:L}=_,W=E.get(L);if(W)return W;if(Q.length<2)throw new F(0);let Z=(X)=>{let z=X;for(let M of Q){if(!z||typeof z!=="object")return null;z=z[M]}if(Y?.not){if(Q[0]==="attr")return z!==""&&!z;return!z}return z};return E.set(L,Z),Z}function v(_){let Q=P(_),Y=document.createElement("template");return Y.content.appendChild(Q),new R(Y)}function X2(_){let Q=document.createTreeWalker(_,NodeFilter.SHOW_ELEMENT),Y=new Set,L=[],W=Q.nextNode();while(W){if(!U(W)){W=Q.nextNode();continue}let Z=W.parentNode,X=!1;while(Z&&!X){if(Y.has(Z)||U(Z)&&(Z.hasAttribute("::each")||Z.hasAttribute("::if")||Z.hasAttribute("::else")||Z.hasAttribute("::else-if"))){X=!0,Y.add(W);break}Z=Z.parentNode}if(!X)L.push(W);W=Q.nextNode()}return L}var T2=new Set(["::each","::if","::else-if","::key","::swap","::tag"]),y=new w;function G2(_){let Q=y.get(_);if(Q)return Q;let Y=new Map,L=[],W=0,Z=(f)=>{let K=f.getAttribute(q);if(!K)K=`el-${W++}`,f.setAttribute(q,K);return K},X=_.content.cloneNode(!0),z=X2(X);for(let f of z){let K=f.getAttributeNames();for(let A of K){let x=f.getAttribute(A);if(x===null||A[0]!==":")continue;if(A==="::key"){if(!K.includes("::each"))throw new F(208);continue}if(T2.has(A)&&x==="")throw new F(202,A);let H=Y.get(x);if(H===void 0)H=h(x),Y.set(x,H);if(f.removeAttribute(A),A[1]!==":"){let I=A.slice(1),j={type:"attr",notation:h(x),attribute:I,nodeRef:Z(f)};L.push(j)}else if(A==="::tag")L.push({type:"tag",notation:H,nodeRef:Z(f)});else if(A==="::each"){let I=Z(f),j=f.getAttribute("::key");if(j===null)throw new F(205);f.removeAttribute("::key");let O=f.innerHTML;while(f.firstChild)f.removeChild(f.firstChild);let D={type:"list",notation:H,keyNotation:h(j),nodeRef:I,listContentHtml:O};L.push(D)}else if(A==="::swap"){let I={type:"swap",notation:H,nodeRef:Z(f)};L.push(I)}else if(A==="::if"){let I={type:"cond",branches:[]};f.removeAttribute("::if");let j={type:"::if",notation:H,branchRootRef:Z(f),branchTemplateHTML:f.innerHTML};I.branches.push(j);let O=f.nextElementSibling;while(O?.hasAttribute("::else-if")){if(!U(O))break;let D=O.getAttribute("::else-if");if(!D)throw new F(202,"::else-if");let S=Y.get(D);if(S===void 0)S=h(D),Y.set(D,S);O.removeAttribute("::else-if");let R2={type:"::else-if",notation:S,branchRootRef:Z(O),branchTemplateHTML:O.innerHTML};I.branches.push(R2),O=O.nextElementSibling}if(O&&U(O)&&O?.hasAttribute("::else")){O.removeAttribute("::else");let D={type:"::else",branchRootRef:Z(O),branchTemplateHTML:O.innerHTML};I.branches.push(D)}L.push(I)}}}let M={};for(let[f,K]of Y)M[f]=K;let J=document.createElement("div");J.appendChild(X.cloneNode(!0));let $=J.innerHTML,G={html:$,schemes:L,notations:M};return y.set(_,G),t($,X),G}function b2(_){if(typeof _==="function"){let Q=_.tagName;if(!N(Q))throw new F(203,_.name,_.tagName);return Q}if(typeof _==="string")return _;throw new F(200,String(_))}function C2(_,...Q){let Y=_[0]??"";for(let W=0;W<Q.length;W++){let Z=Q[W]??"",X=_[W+1]??"";Y+=b2(Z),Y+=X}let L=new CSSStyleSheet;return L.replaceSync(Y),L}function m(..._){let Q="";for(let Y=0;Y<_.length;Y++){let L=_[Y];if(!L)continue;if(typeof L==="string"||typeof L==="number"){if(Q)Q+=" ";Q+=L;continue}if(Array.isArray(L)){let W=m(...L);if(W){if(Q)Q+=" ";Q+=W}continue}if(typeof L==="object"){for(let W in L)if(L[W]){if(Q)Q+=" ";Q+=W}}}return Q}function N2(_){if(L2(_))return _.innerHTML;if(V.isComponentClass(_)){let Q=_.tagName;if(!N(Q))throw new F(203,_.name,_.tagName);return Q}if(typeof _==="string")return`<span ::swap="${_}"></span>`;throw new F(200,String(_))}function g2(_,...Q){let Y=_.reduce((W,Z,X)=>{let z=Q[X]?`${N2(Q[X])}`:"";return W+Z+z},""),L=document.createElement("template");return L.innerHTML=Y,L}var B=Symbol("noop");function F2(_,Q){let Y=Q.get(_.notation.base),L=typeof Y==="function"?Y(_.node):Y;if(_.attribute==="class"&&typeof L!=="string")L=m(L);let W=C(L),Z=_.node.getAttribute(_.attribute);if(W!==Z)return[_.node,_.attribute,W];return B}function z2(_){for(let[Q,Y,L]of _)s(Q,Y,L)}function M2(_,Q){let Y=null;for(let L of _.branches)if(L.type==="::else"){Y=L;break}else{let W=Q.get(L.notation.base);if(typeof W==="function"?W(_.start):W){Y=L;break}}return[_,Y,Q]}function O2(_){for(let[Q,Y,L]of _){let W=Q.start.parentNode;if(!W)throw new F(209);if(Y===null||!Object.is(Q.currentRoot,Y.branchRoot)){let Z=new Set,X=Q.start;while(X&&X!==Q.end){if(U(X))Z.add(X);X=X.nextSibling}for(let z of Z)W.removeChild(z);if(Y)W.insertBefore(Y.branchRoot,Q.end)}if(Y===null)continue;Y.branchTemplate.renderWithValues(Y.branchRoot,L)}}function E2(_,Q){let Y=Q.get(_.notation.base),L=typeof Y==="function"?Y(_.startMarker.parentNode):Y;if(L===null||L===void 0)return[];if(Array.isArray(L))return L;throw new F(204)}function h2(_,Q){let Y=_,L=new Set;while(Y&&Y!==Q){if(U(Y))L.add(Y);Y=Y.nextSibling}return L}function K2(_,Q){let Y=E2(_,Q);if(Y.length===0)return[_,[]];let{rowTemplatesByRoot:L,rowTemplateElement:W,rowRootPrototype:Z}=_,X=c(_.keyNotation),z=new Map;for(let M of Y){let J={item:M},$=X(J);if(z.has($))throw new F(206,String($));let G=_.rowRootsByKey.get($);if(G===void 0)G=Z.cloneNode(!1),_.rowRootsByKey.set($,G);let f=L.get(G);if(f===void 0)f=new R(W),L.set(G,f);let K={context:J,root:G,template:f,attrs:e(M)};z.set($,K)}for(let[M,J]of _.rowRootsByKey)if(!z.has(M))_.rowRootsByKey.delete(M),_.rowTemplatesByRoot.delete(J);return[_,Array.from(z.values())]}function $2(_){for(let[Q,Y]of _){let{endMarker:L,listContainer:W}=Q;if(Y.length===0){for(let M of Q.rowRootsByKey.values())M.remove();Q.rowRootsByKey.clear();continue}let Z=Array.from(h2(Q.startMarker,Q.endMarker)),X=new Set,z=0;for(let M of Y){let{root:J,attrs:$,context:G,template:f}=M,K=Z[z];if(a(J,$),f.render(J,G),X.add(J),Object.is(K,J)){z+=1;continue}if(!K){W.insertBefore(J,L);continue}W.insertBefore(J,K)}for(let M of Z)if(!X.has(M))M.remove(),Q.rowTemplatesByRoot.delete(M)}}function J2(_,Q){let Y=Q.get(_.notation.base),L=typeof Y==="function"?Y(_.node):Y;if(typeof L==="string"||typeof L==="number"||typeof L==="boolean"){let W=`${L}`;if(_.node.textContent===W)return B;return[_,document.createTextNode(W)]}else if(L===null||L===void 0){if(Z2(_.node))return B;return[_,document.createComment("empty")]}else if(U(L)){if(Object.is(_.node,L))return B;return[_,L.cloneNode(!0)]}else throw new F(302,typeof L,JSON.stringify(L))}function H2(_){for(let[Q,Y]of _){let L=Q.node.parentNode;if(!L)throw new F(0);L.replaceChild(Y,Q.node),Q.node=Y}}function y2(_,Q){let Y=document.createElement(Q);while(_.firstChild!==null)Y.appendChild(_.firstChild);for(let L of _.getAttributeNames()){let W=_.getAttribute(L);if(W!==null)Y.setAttribute(L,W)}return _.replaceWith(Y),Y}function A2(_,Q){let Y=Q.get(_.notation.base)??"",W=`${typeof Y==="function"?Y(_.node):Y}`.toLowerCase(),Z=_.node.tagName.toLowerCase();if(!W||W===Z)return B;return[_,W]}function I2(_){for(let[Q,Y]of _)Q.node=y2(Q.node,Y)}function U2(_,Q){let Y={conditionals:[],attributes:[],swaps:[],tags:[],lists:[]};for(let L of _)switch(L.type){case"cond":{let W=M2(L,Q);if(W!==B)Y.conditionals.push(W);break}case"attr":{let W=F2(L,Q);if(W!==B)Y.attributes.push(W);break}case"list":{let W=K2(L,Q);if(W!==B)Y.lists.push(W);break}case"swap":{let W=J2(L,Q);if(W!==B)Y.swaps.push(W);break}case"tag":{let W=A2(L,Q);if(W!==B)Y.tags.push(W);break}default:throw new F(0)}return Y}function B2(_){O2(_.conditionals),z2(_.attributes),$2(_.lists),H2(_.swaps),I2(_.tags)}var l=(_)=>{if(!_.parentNode)throw new F(209);return _.parentNode},x2=(_,Q="")=>{let Y=l(_),L=document.createComment(Q);return Y.insertBefore(L,_),L},j2=(_,Q="")=>{let Y=l(_),L=document.createComment(Q);return Y.insertBefore(L,_.nextSibling),L};function k2(_,Q){let Y=new Map,L=new Map,W=new Set,Z=new Map;for(let[G,f]of Object.entries(_.notations))L.set(G,c(f));let X=Q??P(_.html),z=document.createTreeWalker(X,NodeFilter.SHOW_ELEMENT,{acceptNode(G){return G.hasAttribute(q)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}}),M=z.nextNode();while(M){if(!U(M))continue;let G=M.getAttribute(q);if(G===null)throw new F(0);Z.set(G,M),M.removeAttribute(q),M=z.nextNode()}let J=(G,f)=>{let K=Y.get(f);if(!K)K=new Set,Y.set(f,K);K.add(G)},$=(G)=>{let f=Z.get(G);if(f)return f;throw new F(3)};for(let G of _.schemes)if(G.type==="list"){let f=$(G.nodeRef),K=l(f),A=f.cloneNode(!1),x=x2(f),H=j2(f);f.remove();let I=P(G.listContentHtml),j=document.createElement("template");j.content.appendChild(I);let O={type:"list",notation:G.notation,keyNotation:G.keyNotation,listContainer:K,rowTemplateElement:j,rowRootPrototype:A,startMarker:x,endMarker:H,rowTemplatesByRoot:new WeakMap,rowRootsByKey:new Map};J(O,G.notation.base)}else if(G.type==="cond"){let f=G.branches[0];if(!f)throw new F(0);let K=$(f.branchRootRef),A=x2(K),x=G.branches[G.branches.length-1],H=$(x.branchRootRef),I=j2(H),j={type:"cond",start:A,end:I,branches:[]};for(let O of G.branches)if(O.type==="::if"||O.type==="::else-if"){let D=$(O.branchRootRef),S=v(O.branchTemplateHTML);W.add(S),j.branches.push({type:O.type,notation:O.notation,branchRoot:$(O.branchRootRef),branchTemplate:v(O.branchTemplateHTML)}),J(j,O.notation.base),D.remove()}else j.branches.push({type:O.type,branchRoot:$(O.branchRootRef),branchTemplate:v(O.branchTemplateHTML)})}else if(G.type==="swap"||G.type==="tag"){let f={type:G.type,notation:G.notation,node:$(G.nodeRef)};J(f,G.notation.base)}else if(G.type==="attr"){let f={type:"attr",attribute:G.attribute,notation:G.notation,node:$(G.nodeRef)};J(f,f.notation.base)}return{plansByNotation:Y,notationAccessors:L,fragment:X,subtemplates:W}}class R{static isTemplate(_){return _!==null&&typeof _==="object"&&_ instanceof R}static cache={clear:()=>{b.clear(),y.clear(),E.clear(),g.clear()},setCapacity:(_)=>{b.setCapacity(_),y.setCapacity(_),E.setCapacity(_),g.setCapacity(_)}};_compiled;_templateElement;_mountedRoot;_latestRenderedValues=new Map;_fragment;_plansByNotation=new Map;_notationAccessors=new Map;_subtemplates=new Set;constructor(_){this._templateElement=_,this._compiled=G2(_);let Q=P(this._compiled.html),Y=k2(this._compiled,Q);this._plansByNotation=Y.plansByNotation,this._notationAccessors=Y.notationAccessors,this._fragment=Y.fragment,this._subtemplates=Y.subtemplates;let L=new Map(this._notationAccessors);for(let W of this._subtemplates)for(let[Z,X]of W.notationMap)L.set(Z,X);this._notationAccessors=L}get compiled(){return this._compiled}get notationMap(){return this._notationAccessors}clone=()=>{return new R(this.element())};element=()=>{if(this._templateElement)return this._templateElement;let _=document.createElement("template");return _.innerHTML=this._compiled.html,_};_collectUpdatedValues=(_)=>{let Q=new Map,Y=!1;for(let[L,W]of this._notationAccessors){let Z=this._latestRenderedValues.get(L),X=W(_);if(Q.set(L,X),Z!==X&&!Object.is(Z,X))Y=!0}return[Y,Q]};_update(_){let Q=new Set;for(let[L]of _){let W=this._plansByNotation.get(L);if(!W)continue;for(let Z of W)Q.add(Z)}let Y=U2(Q,_);B2(Y)}renderWithValues=(_,Q)=>{if(_!==this._mountedRoot){this._mountedRoot=_;while(_.firstChild)_.removeChild(_.firstChild);_.append(this._fragment)}this._update(Q)};render=(_,Q)=>{let[Y,L]=this._collectUpdatedValues(Q);if(_===this._mountedRoot&&!Y)return;this.renderWithValues(_,L),this._latestRenderedValues=L}}class V2{_queues={tasks:[],frames:[]};_promises={};_resolvers={};_onError;constructor(_){this._onError=_}_flushQueue=(_)=>{let Q=this._queues[_];try{while(Q.length)Q.shift()?.()}catch(Y){if(this._onError)this._onError(Y);else throw Y}finally{this._resolvers[_]?.(),this._resolvers[_]=void 0,this._promises[_]=void 0}};_schedule=(_,Q,Y=!1)=>{let L=this._queues[_];if(Y)L.unshift(Q);else L.push(Q);if(!this._promises[_])if(this._promises[_]=new Promise((W)=>{this._resolvers[_]=W}),_==="frames")requestAnimationFrame(this._flushQueue.bind(this,"frames"));else queueMicrotask(this._flushQueue.bind(this,"tasks"));return this._promises[_]};scheduleMicrotask=(_,Q=!1)=>{return this._schedule("tasks",_,Q)};scheduleFrameTask=(_,Q=!1)=>{return this._schedule("frames",_,Q)}}var u=new V2;class o{_root;_rootListeners=new Map;_events=new Map;constructor(_=document){this._root=_}_handlersForEvent(_){let Q=this._events.get(_);if(Q===void 0)Q=new Map,this._events.set(_,Q);return Q}_handlersForEventAndQuery(_,Q){let Y=this._handlersForEvent(_),L=Y.get(Q);if(L===void 0)L=new Set,Y.set(Q,L);return L}_createRootListener(_){if(this._rootListeners.has(_))return;let Q=(Y)=>{let L=this._handlersForEvent(_),{target:W}=Y;if(W===null||!W2(W))return;let Z=W,X=!1,z=Y.stopImmediatePropagation;Y.stopImmediatePropagation=()=>{z.call(Y),X=!0};while(Z){if(Z===this._root)break;if(!Y2(Z)){Z=Z.parentNode;continue}for(let[M,J]of L)if(M==="*"||_2(Z,M)){for(let $ of J)if($.call(Z,Y),X||Y.defaultPrevented)return}if(Y.cancelBubble)return;if(Z=Z.parentNode,Z===this._root||i(Z))break}};this._rootListeners.set(_,Q),this._root.addEventListener(_,Q)}addListener(_,Q,Y="*"){this._handlersForEventAndQuery(_,Y).add(Q),this._createRootListener(_)}removeListener(_,Q,Y){let L=this._handlersForEventAndQuery(_,Y);if(L.delete(Q),L.size===0)this._handlersForEvent(_).delete(Y)}cleanup=()=>{for(let[_,Q]of this._rootListeners)this._root.removeEventListener(_,Q);this._rootListeners.clear()}}var c2=1e4,v2=document.createElement("template"),m2=":host",n;((Y)=>{Y.Closed="closed";Y.Open="open"})(n||={});class V extends HTMLElement{static isComponent(_){return typeof _==="object"&&_!==null&&_ instanceof V}static isComponentClass(_){return _!==null&&typeof _==="function"&&(_.prototype instanceof V||_===V)}static readComponentTagName(_){let{tagName:Q}=_;return Q}static tagName="";static template=v2;static style=[];static observedAttributes=[];static rootMode="closed";root;template;_cmp={isFinalized:!1,isInitialRenderComplete:!1,isRenderScheduled:!1,isRendering:!1,sequentialRenderCount:0,lastRenderedAttributes:{},pendingAttributeChanges:{}};constructor(){super();let{template:_,style:Q,rootMode:Y}=this.constructor;this.root=this.attachShadow({mode:Y});let L=[];if(Array.isArray(Q))L=Q;else if(Q instanceof CSSStyleSheet)L=[Q];else{let W=new CSSStyleSheet;W.replaceSync(Q),L=[W]}this.root.adoptedStyleSheets.push(...L),this.template=R.isTemplate(_)?_:new R(_)}_getRenderContext(_){let Q=this._cmp.state?.raw??{},Y=this.computedProperties?.call(this,_,Q);return{attr:_,data:Y,state:Q}}_escalateError(_){if(!Q2(this,(Y)=>{if(Y instanceof V&&Y.onError)return Y.onError(_),!0}))throw _}_reportError(_){this.onError?this.onError(_):this._escalateError(_)}_render=()=>{try{this._cmp.isRendering=!0,this._cmp.isRenderScheduled=!1;let _=this._cmp.lastRenderedAttributes;this.beforeUpdate?.(this._cmp.pendingAttributeChanges);let Q=p(this);if(this.template.render(this.root,this._getRenderContext(Q)),this._cmp.lastRenderedAttributes=Q,this.afterUpdate?.(_),this._cmp.isRenderScheduled){if(this._cmp.sequentialRenderCount+=1,this._cmp.sequentialRenderCount>=c2)throw new F(306,`${this._cmp.sequentialRenderCount}`);this._render()}else this._cmp.sequentialRenderCount=0}catch(_){this._cmp.isRenderScheduled=!1,this._reportError(_)}finally{this._cmp.isRendering=!1}};_adoptState(_){if(Object.is(this._cmp.state,_))return;if(this._cmp.state)this._cmp.state.removeListener(this.render),this.render();let Q=T.isState(_)?_:new T(_);this._cmp.state=Q,this._cmp.state.removeListener(this.render),this._cmp.state.addListener(this.render)}connectedCallback(){if(this._cmp.isInitialRenderComplete)return;u.scheduleMicrotask(()=>{try{this._cmp.isRendering=!0,this._cmp.isRenderScheduled=!1;let _=p(this);if(this.initialState)this._adoptState(this.initialState());this.template.render(this.root,this._getRenderContext(_)),this._cmp.lastRenderedAttributes=_,this._cmp.isInitialRenderComplete=!0,this._cmp.cleanupFn=this.script?.()??void 0}catch(_){this._reportError(_)}finally{this._cmp.isRendering=!1}})}disconnectedCallback(){if(this._cmp.isFinalized)return;u.scheduleMicrotask(()=>{if(this.isConnected||!this._cmp.isInitialRenderComplete)return;this._cmp.isFinalized=!0;try{let{delegator:_,cleanupFn:Q,hostListeners:Y}=this._cmp;if(_?.cleanup(),Y&&Y.size>0)for(let L of Y)this.removeEventListener(L.event,L.handler);Q?.()}catch(_){this._reportError(_)}finally{try{this.finalize?.()}catch(_){this._reportError(_)}}})}attributeChangedCallback(_,Q,Y){if(this._cmp.isRendering)return;if(this._cmp.pendingAttributeChanges[_]=Y,!this._cmp.isRenderScheduled)this.render()}get isMounted(){return this.isConnected&&this._cmp.isInitialRenderComplete}getState(){if(!this._cmp.state)throw new F(301);return this._cmp.state}get state(){return this.getState().live}set state(_){this._adoptState(_)}render=()=>{if(this._cmp.isRenderScheduled)return;if(this._cmp.isRenderScheduled=!0,this._cmp.isRendering)return;u.scheduleFrameTask(this._render)};listen(_,Q,Y){if(_===m2||_===this){if(!this._cmp.hostListeners)this._cmp.hostListeners=new Set;let Z=this._cmp.hostListeners,X={event:Q,handler:Y};return Z.add(X),this.addEventListener(Q,Y),()=>{this.removeEventListener(Q,Y),Z.delete(X)}}if(typeof _==="object")throw new F(2);if(!this._cmp.delegator)this._cmp.delegator=new o(this.root);let L=this._cmp.delegator,W=typeof _==="string"?_:V.readComponentTagName(_);return L.addListener(Q,Y,W),()=>{L.removeListener(Q,Y,W)}}dispatchEvent(_,Q){if(typeof _==="object"&&typeof Q>"u")return super.dispatchEvent(_);else if(typeof _==="string")return super.dispatchEvent(new CustomEvent(_,{bubbles:!0,cancelable:!0,composed:!0,...Q}));else throw new F(2)}ref(_){let Q=this.root.getElementById(_);if(!Q)throw new F(300);return Q}toString(){let{tagName:_,name:Q}=this.constructor,Y=_===""?Q:_,L=this.getAttributeNames().map((Z)=>{let X=this.getAttribute(Z);return X?`${Z}="${X}"`:""}).join(" "),W=L.length>0?` ${L}`:"";return`<${Y}${W}></${Y}>`}}var u2=document.createElement("template");function D2(_,Q){if(Q&&_.tagName==="")_.tagName=Q;window.customElements.define(_.tagName,_)}function s2(_,Q){if(typeof _==="function")return D2(_),_;if(typeof _==="string"&&typeof Q==="function")return D2(Q,_),Q;if(Q===void 0)throw new F(2);let Y=_,L=Q;if(typeof L==="function"){if(L.tagName==="")L.tagName=Y;return window.customElements.define(Y,L),L}let{template:W=u2,style:Z=[],rootMode:X="closed",initialState:z,computedProperties:M,observedAttributes:J=[],script:$,beforeUpdate:G,afterUpdate:f,finalize:K,onError:A}=L,x;if(z)x=typeof z==="function"?z:()=>z;let H=class extends V{static tagName=Y;static template=W;static style=Z;static observedAttributes=[...J];static shadowRootMode=X};return H.prototype.initialState=x,H.prototype.computedProperties=M,H.prototype.script=$,H.prototype.beforeUpdate=G,H.prototype.afterUpdate=f,H.prototype.finalize=K,H.prototype.onError=A,customElements.define(Y,H),H}export{g2 as html,s2 as define,C2 as css,m as classify,R as Template,T as State,n as RootMode,F as PaletteError,V as Component};
|