@rusticarcade/palette 0.1.0 → 0.3.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 +74 -2
- package/dist/dev/index.js +54 -37
- package/dist/prod/index.d.ts +1 -1
- package/dist/prod/index.js +2 -2
- package/dist/test/index.d.ts +803 -0
- package/dist/test/index.js +347 -0
- package/package.json +37 -10
package/dist/prod/index.d.ts
CHANGED
|
@@ -395,7 +395,7 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
|
|
|
395
395
|
*/
|
|
396
396
|
static template: HTMLTemplateElement | Template;
|
|
397
397
|
/**
|
|
398
|
-
* A {@link CSSStyleSheet} array to adopt
|
|
398
|
+
* A {@link CSSStyleSheet} array or string to adopt as the component's scoped styles
|
|
399
399
|
*/
|
|
400
400
|
static styles: ComponentStyles;
|
|
401
401
|
/**
|
package/dist/prod/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
class U extends Error{name="PaletteError";code;constructor(L,...Y){let Z=`Code: ${L}`;super(Z);this.code=L}}function E(L,...Y){let Z=L[0]??"";for(let Q=0;Q<Y.length;Q++){let W=Y[Q]??"",X=L[Q+1]??"";Z+=`${W}${X}`}let G=new CSSStyleSheet;return G.replaceSync(Z),G}function P(...L){let Y="";for(let Z=0;Z<L.length;Z++){let G=L[Z];if(!G)continue;if(typeof G==="string"||typeof G==="number"){if(Y)Y+=" ";Y+=G;continue}if(Array.isArray(G)){let Q=P(...G);if(Q){if(Y)Y+=" ";Y+=Q}continue}if(typeof G==="object"){for(let Q in G)if(G[Q]){if(Y)Y+=" ";Y+=Q}}}return Y}function K(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 f(L){let Y=new Map;if(L instanceof HTMLElement){for(let Z of L.getAttributeNames())Y.set(Z,K(L.getAttribute(Z)));return Y}if(L instanceof Map){for(let[Z,G]of L)Y.set(Z,K(G));return Y}if(typeof L==="object"&&L!==null){for(let[Z,G]of Object.entries(L))Y.set(Z,K(G));return Y}throw new U(0)}function y(L,Y){let Z=new Set(L.getAttributeNames()),G=new Set(Y.keys()),Q=Z.difference(G);for(let W of Q)L.removeAttribute(W);for(let[W,X]of Y)if(X===null)L.removeAttribute(W);else L.setAttribute(W,X)}function v(L,Y){let Z=document.createElement(Y);while(L.firstChild!==null)Z.appendChild(L.firstChild);for(let G of L.getAttributeNames()){let Q=L.getAttribute(G);if(Q!==null)Z.setAttribute(G,Q)}return L.replaceWith(Z),Z}function h(L){for(let Y=0;Y<L.length;Y++){let Z=L.charCodeAt(Y);if(!(Z===45||Z>=65&&Z<=90||Z>=97&&Z<=122))return!1}return!0}function c(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(h(Y))return L.tagName.toLowerCase()===Y.toLowerCase();if(Y[0]==="["&&Y[Y.length-1]==="]"&&Y.indexOf(" ")===-1&&Y.indexOf(":")===-1){let Z=Y.slice(1,-1),G=Z.indexOf("=");if(G===-1)return L.hasAttribute(Z);let Q=Z.slice(0,G),W=Z.slice(G+1).replace(/^["']|["']$/g,"");return L.getAttribute(Q)===W}return L.matches(Y)}class b{_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)}};get metrics(){return{lookups:0,hits:0,misses:0,capacity:0,entries:0,hitRate:0}}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 m=b;var V=new m;function q(L){let Y=V.get(L);if(Y!==void 0)return Y.cloneNode(!0);let Z=document.createElement("template");return Z.innerHTML=L,V.set(L,Z.content),Z.content.cloneNode(!0)}function Y2(L){if(L instanceof HTMLTemplateElement)return L.innerHTML;if(typeof L==="function"&&(L.prototype instanceof I||L===I)){let Y=L.tagName;if(!h(Y))throw new U(202,L.name,L.tagName);return Y}if(typeof L==="string")return`<span ::swap="${L}"></span>`;throw new U(200,String(L))}function Z2(L,...Y){let Z=L.reduce((Q,W,X)=>{let F=Y[X]?`${Y2(Y[X])}`:"";return Q+W+F},""),G=document.createElement("template");return G.innerHTML=Z,G}var G2=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]);class R{_data;_listeners=new Set;_proxy;_proxyCache=new WeakMap;_reverseProxyCache=new WeakMap;_isLocked=!1;_hasWarned=!0;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 Z=this._proxyCache.get(L);if(Z)return Z;let G=new Proxy(L,{get:(Q,W)=>{if(typeof W==="symbol")return Q[W];let X=Q[W];if(Array.isArray(Q)&&typeof X==="function"){let F=G2.has(W);return(...M)=>{let H=this.snapshot(),z=H;for(let _ of Y)z=z[_];let $=z[W](...M);if(F){if(this._isLocked)throw new U(305);this._processIncomingState(H)}return $}}if(typeof X==="object"&&X!==null)return this._createProxy(X,[...Y,W]);return X},set:(Q,W,X)=>{if(this._isLocked)throw new U(305);if(typeof W==="symbol")return!1;let F=[...Y,W];return this._setNested(F,this._unwrapProxy(X)),!0},has:(Q,W)=>{return W in Q},ownKeys:(Q)=>{return Reflect.ownKeys(Q)},getOwnPropertyDescriptor:(Q,W)=>{let X=Object.getOwnPropertyDescriptor(Q,W);if(X)X.configurable=!0;return X},deleteProperty:(Q,W)=>{if(typeof W==="symbol"||!(W in Q))return!1;let X=[...Y,W];return this._setNested(X,void 0),!0}});return this._proxyCache.set(L,G),this._reverseProxyCache.set(G,L),G}_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((Z)=>this._unwrapProxy(Z));if(Object.getPrototypeOf(L)===Object.prototype){let Z={};for(let G in L)if(Object.hasOwn(L,G))Z[G]=this._unwrapProxy(L[G]);return Z}return L}_setNested(L,Y){if(!L.length)return;let Z=this._data;for(let Q=0;Q<L.length-1;Q++){let W=L[Q]??"";if(!(W in Z))throw new U(303,L.join("."));Z=Z[W]}let G=L[L.length-1]??"";if(!(G in Z))throw new U(303,L.join("."));if(Z[G]!==Y&&!Object.is(Z[G],Y))Z[G]=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[Z,G]of Object.entries(L)){let Q=this._data[Z];if(!Object.is(Q,G))Y=!0,this._data[Z]=G}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 Z={};Z[L]=Y,this._processIncomingState(Z)};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 Z=await L(this.snapshot());if(this._processIncomingState(Z),Y)this._isLocked=!1;return this};transaction=(L)=>{if(this._isLocked)throw new U(305);this._isLocked=!0;let Y=!0;try{let Z=new R(this.snapshot());L(Z),this._processIncomingState(Z.current)}catch(Z){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 Z=new R(this.snapshot());await L(Z),this._processIncomingState(Z.current)}catch(Z){Y=!1}finally{this._isLocked=!1}return Y}}function p(L){if(L[0]!==":"||L.length<2)return!1;for(let Y=1;Y<L.length;Y++){let Z=L.charCodeAt(Y);if(!(Z===45||Z>=65&&Z<=90||Z>=97&&Z<=122))return!1}return!0}var Q2={["@"]:"attr",["$"]:"state",["*"]:"data",["#"]:"item"},W2=new Map(Object.entries(Q2));function g(L){let Y=!1,Z="",G=[],Q=!0;for(let W of L)if(Q&&W==="!")Y=!0;else if(Q){let X=W2.get(W);if(!X)throw new U(201,L);G.push(X),Q=!1}else if(W===".")if(Z.length)G.push(Z),Z="";else throw new U(201,L);else Z+=W;if(!Z.length)throw new U(201,L);if(G.push(Z),G.length<2)throw new U(201,L);return{base:L,path:G,modifiers:Y?{not:!0}:void 0}}function k(L){let{path:Y,modifiers:Z}=L;if(Y.length<2)throw new U(0);if(Y.length===2){let[G,Q]=Y;if(G===void 0||Q===void 0)throw new U(0);return(W)=>{let X=W?.[G]?.[Q]??null;if(Z?.not){if(G==="attr")return X!==""&&!X;return!X}return X}}if(Y.length===3){let[G,Q,W]=Y;if(G===void 0||Q===void 0||W===void 0)throw new U(0);return(X)=>{let F=X?.[G]?.[Q]?.[W]??null;if(Z?.not){if(G==="attr")return F!==""&&!F;return!F}return F}}return(G)=>{let Q=G;for(let W of Y){if(!Q||typeof Q!=="object")return null;Q=Q[W]}if(Z?.not){if(Y[0]==="attr")return Q!==""&&!Q;return!Q}return Q}}var S="data-node-ref";function X2(L){let Y=document.createTreeWalker(L,NodeFilter.SHOW_ELEMENT),Z=new Set,G=[],Q=Y.nextNode();while(Q){if(!(Q instanceof HTMLElement)){Q=Y.nextNode();continue}let W=Q.parentNode,X=!1;while(W&&!X){if(Z.has(W)||W instanceof HTMLElement&&W.hasAttribute("::each")){X=!0,Z.add(Q);break}W=W.parentNode}if(!X)G.push(Q);Q=Y.nextNode()}return G}function d(L){let Y=new Map,Z=[],G=0,Q=($)=>{let _=$.getAttribute(S);if(!_)_=`el-${G++}`,$.setAttribute(S,_);return _},W=L.content.cloneNode(!0),X=X2(W);for(let $ of X){let _=new Map;for(let B of $.getAttributeNames())_.set(B,$.getAttribute(B));for(let[B,j]of _){if(j===null||B[0]!==":")continue;let O=Y.get(j);if(O===void 0)O=g(j),Y.set(j,O);if($.removeAttribute(B),B==="::key")continue;if(B==="::tag")Z.push({type:"tag",notation:O,nodeRef:Q($)});else if(B==="::each"){let x=Q($),A=$.getAttribute("::key");if(A===null)throw new U(206);$.removeAttribute("::key");let C=$.innerHTML;while($.firstChild)$.removeChild($.firstChild);let e={type:"each",notation:O,keyNotation:g(A),nodeRef:x,listContentHtml:C};Z.push(e)}else if(B==="::swap"){let x={type:"swap",notation:O,nodeRef:Q($)};Z.push(x)}else if(p(B)){let x=B.slice(1),A={type:"attr",notation:O,attribute:x,nodeRef:Q($)};Z.push(A)}}}let F={};for(let[$,_]of Y)F[$]=_;let M=document.createElement("div");return M.appendChild(W.cloneNode(!0)),{html:M.innerHTML,schemes:Z,notations:F}}function u(L,Y){let Z=new Map,G=new Map,Q=new Map;for(let[z,$]of Object.entries(L.notations))G.set(z,k($));let W=Y??q(L.html),X=document.createTreeWalker(W,NodeFilter.SHOW_ELEMENT,{acceptNode(z){return z.hasAttribute(S)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}}),F=X.nextNode();while(F){if(!(F instanceof HTMLElement))continue;let z=F.getAttribute(S);if(z===null)throw new U(0);Q.set(z,F),F.removeAttribute(S),F=X.nextNode()}let M=(z,$)=>{let _=Z.get($);if(!_)_=new Set,Z.set($,_);_.add(z)},H=(z)=>{let $=Q.get(z);if($)return $;throw new U(204)};for(let z of L.schemes)if(z.type==="each"){let $=H(z.nodeRef),_=$.parentElement;if(!_)throw new U(205);let B=document.createComment("list-start"),j=document.createComment("list-end");_.insertBefore(B,$),_.insertBefore(j,$.nextSibling);let O=$.cloneNode(!1),x=q(z.listContentHtml),A=document.createElement("template");A.appendChild(x),$.remove();let C={type:"each",notation:z.notation,keyNotation:z.keyNotation,listContainerElement:_,rowTemplateElement:A,rowRootElement:O,startMarker:B,endMarker:j,rowTemplatesByRoot:new WeakMap,rowRootsByKey:new Map};M(C,z.notation.base)}else if(z.type==="swap"){let $={type:"swap",notation:z.notation,node:H(z.nodeRef)};M($,z.notation.base)}else if(z.type==="tag"){let $={type:"tag",notation:z.notation,node:H(z.nodeRef)};M($,$.notation.base)}else if(z.type==="attr"){let $={type:"attr",attribute:z.attribute,notation:z.notation,node:H(z.nodeRef)};M($,$.notation.base)}return{plansByNotation:Z,notationAccessors:G,fragment:W}}var J=Symbol("noop");function i(L,Y){let Z=Y.get(L.notation.base),G=typeof Z==="function"?Z(L.node):Z;if(L.attribute==="class"&&typeof G!=="string")G=P(G);let Q=K(G),W=L.node.getAttribute(L.attribute);if(Q!==W)return[L.node,L.attribute,Q];return J}function s(L){for(let[Y,Z,G]of L)if(G===null)Y.removeAttribute(Z);else Y.setAttribute(Z,G)}function l(L,Y){let Z=Y.get(L.notation.base),G=typeof Z==="function"?Z(L.node):Z;if(typeof G==="string"||typeof G==="number"||typeof G==="boolean"){let Q=`${G}`;if(L.node.textContent===Q)return J;return[L,document.createTextNode(Q)]}else if(G===null||G===void 0){if(L.node instanceof Comment)return J;return[L,document.createComment("empty")]}else if(G instanceof HTMLElement){if(Object.is(L.node,G))return J;return[L,G.cloneNode(!0)]}else throw new U(302,typeof G,JSON.stringify(G))}function o(L){for(let[Y,Z]of L){let G=Y.node.parentNode;if(!G)throw new U(0);G.replaceChild(Z,Y.node),Y.node=Z}}function n(L,Y){let Z=Y.get(L.notation.base)??"",Q=`${typeof Z==="function"?Z(L.node):Z}`.toLowerCase(),W=L.node.tagName.toLowerCase();if(!Q||Q===W)return J;return[L,Q]}function a(L){for(let[Y,Z]of L)Y.node=v(Y.node,Z)}function $2(L,Y){let Z=Y.get(L.notation.base),G=typeof Z==="function"?Z(L.startMarker.parentNode):Z;if(G===null||G===void 0)return[];if(Array.isArray(G))return G;throw new U(203)}function U2(L,Y){let Z=L,G=new Set;while(Z&&Z!==Y){if(Z instanceof HTMLElement)G.add(Z);Z=Z.nextSibling}return G}function r(L,Y){let Z=$2(L,Y);if(Z.length===0)return[L,[]];let{rowTemplatesByRoot:G,rowTemplateElement:Q,rowRootElement:W}=L,X=k(L.keyNotation),F=new Map;for(let M of Z){let H={item:M},z=X(H);if(F.has(z))throw new U(207,String(z));let $=L.rowRootsByKey.get(z);if($===void 0)$=W.cloneNode(!1),L.rowRootsByKey.set(z,$);let _=G.get($);if(_===void 0)_=new T(Q),G.set($,_);let B={context:H,root:$,template:_,attrMap:f(M)};F.set(z,B)}for(let[M,H]of L.rowRootsByKey)if(!F.has(M))L.rowRootsByKey.delete(M),L.rowTemplatesByRoot.delete(H);return[L,Array.from(F.values())]}function t(L){for(let[Y,Z]of L){let{endMarker:G,listContainerElement:Q}=Y;if(Z.length===0){for(let M of Y.rowRootsByKey.values())M.remove();Y.rowRootsByKey.clear();continue}let W=Array.from(U2(Y.startMarker,Y.endMarker)),X=new Set,F=0;for(let M of Z){let{root:H,attrMap:z,context:$,template:_}=M,B=W[F];if(y(H,z),_.render(H,$),X.add(H),Object.is(B,H)){F+=1;continue}if(!B){Q.insertBefore(H,G);continue}Q.insertBefore(H,B)}for(let M of W)if(!X.has(M))M.remove(),Y.rowTemplatesByRoot.delete(M)}}var N=new b;class T{static cache={clear:()=>{V.clear(),N.clear()},setCapacity:(L)=>{V.setCapacity(L),N.setCapacity(L)}};_compiled;_templateElement;_mountedRoot;_latestRenderedValues=new Map;_fragment;_plansByNotation=new Map;_notationAccessors=new Map;constructor(L){if(L instanceof HTMLTemplateElement){this._templateElement=L;let Q=N.get(L)??d(L);this._compiled=Q,N.set(L,Q)}else this._compiled=L;let Y=q(this._compiled.html),Z=u(this._compiled,Y);this._plansByNotation=Z.plansByNotation,this._notationAccessors=Z.notationAccessors,this._fragment=Z.fragment}clone=()=>{return new T(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;for(let[Z,G]of this._notationAccessors){let Q=this._latestRenderedValues.get(Z),W=G(L);if(Q!==W&&!Object.is(Q,W))Y.set(Z,W)}return Y};_update(L){let Y=new Set,Z=[],G=[],Q=[],W=[];for(let[X]of L){let F=this._plansByNotation.get(X);if(F)for(let M of F){if(Y.has(M))continue;switch(Y.add(M),M.type){case"attr":{let H=i(M,L);if(H!==J)Z.push(H);break}case"each":{let H=r(M,L);if(H!==J)W.push(H);break}case"swap":{let H=l(M,L);if(H!==J)G.push(H);break}case"tag":{let H=n(M,L);if(H!==J)Q.push(H);break}default:throw new U(0)}}}s(Z),t(W),o(G),a(Q)}render=(L,Y)=>{if(L!==this._mountedRoot){this._mountedRoot=L;while(L.firstChild)L.removeChild(L.firstChild);L.append(this._fragment)}let Z=this._collectUpdatedValues(Y);if(Z.size!==0){this._update(Z);for(let[G,Q]of Z)this._latestRenderedValues.set(G,Q)}}}class w{static nextListenerId=0;static processTargetDescriptor(L){if(L instanceof HTMLElement)if(L.id.length)return`#${L.id}`;else{let Y=`listen-${w.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 Z=this._handlersForEvent(L),G=Z.get(Y);if(G===void 0)G=new Set,Z.set(Y,G);return G}_createRootListener(L){if(this._rootListeners.has(L))return;let Y=(Z)=>{let G=this._handlersForEvent(L),{target:Q}=Z;if(Q===null||!(Q instanceof Node))return;let W=Q,X=!1,F=Z.stopImmediatePropagation;Z.stopImmediatePropagation=()=>{F.call(Z),X=!0};while(W){if(W===this._root)break;if(!(W instanceof Element)){W=W.parentNode;continue}for(let[M,H]of G)if(M==="*"||c(W,M)){for(let z of H)if(z.call(W,Z),X||Z.defaultPrevented)return}if(Z.cancelBubble)return;if(W=W.parentNode,W===this._root||W instanceof ShadowRoot)break}};this._rootListeners.set(L,Y),this._root.addEventListener(L,Y)}addListener(L,Y,Z="*"){this._handlersForEventAndQuery(L,Z).add(Y),this._createRootListener(L)}removeListener(L,Y,Z){let G=this._handlersForEventAndQuery(L,Z);if(G.delete(Y),G.size===0)this._handlersForEvent(L).delete(Z)}cleanup=()=>{for(let[L,Y]of this._rootListeners)this._root.removeEventListener(L,Y);this._rootListeners.clear()}}var z2=100,F2=document.createElement("template");class I extends HTMLElement{static register(L,Y){if(typeof window>"u"||typeof window.customElements>"u")throw new U(1);let Z="tagName"in L&&typeof L.tagName==="string"?L.tagName:null,G=Y??Z;if(G===null||G.length===0||!G.includes("-"))throw new U(101);if(window.customElements.get(G))throw new U(100,Y??"");window.customElements.define(G,L)}static tagName="";static template=F2;static styles=[];static observedAttributes=[];static shadowRootMode="closed";initialState;computedProperties;liveAttributes;_isComponentMounted=!1;_template;_root;_state;_delegator;_ownListeners=new Set;_liveAttributeConfigs=new Map;_cleanupFn;_renderInternals={willRender:!1,isRendering:!1,sequentialRenders:0,postRenderCallbacks:new Set,lastRenderedAttributeMap:new Map,trackedAttributeChanges:new Map};constructor(){super();let{template:L,styles:Y,shadowRootMode:Z}=this.constructor,G=Array.isArray(Y)?Y:typeof Y==="object"?[Y]:[E`${Y}`];this._root=this.attachShadow({mode:Z}),this._root.adoptedStyleSheets.push(...G),this._template=L instanceof T?L:new T(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 I&&"onError"in Y&&typeof Y.onError==="function"){console.log("Escalating to",Y);return}Y=Y.parentNode}throw L}_reportError(L){if(!this.onError)this._escalateError(L);else this.onError(L)}_executeAttributeChangeHandlers=()=>{let L=this._renderInternals.lastRenderedAttributeMap,Y=new Map(this._renderInternals.trackedAttributeChanges);this._renderInternals.trackedAttributeChanges.clear();for(let[Z,G]of Y){let Q=this._liveAttributeConfigs.get(Z);if(!Q)continue;if("onChange"in Q){let W=L.get(Z)??null;if(Q&&W!==G)Q.onChange?.call(this,G,W)}}};_reflectLiveAttributes=()=>{let L=[];for(let[Y,Z]of this._liveAttributeConfigs)if("reflect"in Z){let G=K(Z.reflect?.call(this)),Q=this.getAttribute(Y);if(G!==Q)L.push([Y,G])}for(let[Y,Z]of L)this.reflectAttribute(Y,Z)};_performUpdate=()=>{try{this._renderInternals.isRendering=!0,this._renderInternals.willRender=!1,this._executeAttributeChangeHandlers();let L=this._renderInternals.lastRenderedAttributeMap;this.beforeUpdate?.call(this);let Y=f(this);if(this._template.render(this.root,this._getRenderContext(Y)),this._renderInternals.lastRenderedAttributeMap=Y,this.afterUpdate?.call(this,L),this._reflectLiveAttributes(),this._renderInternals.postRenderCallbacks.size){let Z=Array.from(this._renderInternals.postRenderCallbacks);this._renderInternals.postRenderCallbacks.clear();for(let G of Z)G()}if(this._renderInternals.willRender){if(this._renderInternals.sequentialRenders+=1,this._renderInternals.sequentialRenders>=z2)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 R?L:new R(L);this._state=Y,this._state.removeListener(this._scheduleUpdate),this._state.addListener(this._scheduleUpdate)}connectedCallback(){if(this._isComponentMounted)return;try{let L=f(this);if(this._liveAttributeConfigs=new Map(Object.entries(this.liveAttributes??{})),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._isComponentMounted=!0,this._cleanupFn=this.script?.call(this)??void 0}catch(L){this._reportError(L)}}disconnectedCallback(){queueMicrotask(()=>{if(!this.isConnected&&this._isComponentMounted)try{if(this._delegator?.cleanup(),this._ownListeners.size>0)for(let L of this._ownListeners)this.removeEventListener(L.event,L.handler);this._cleanupFn?.call(this),this._isComponentMounted=!1}catch(L){this._reportError(L)}finally{try{this.finalize?.call(this)}catch(L){this._reportError(L)}}})}attributeChangedCallback(L,Y,Z){if(this._renderInternals.isRendering)return;if(Z===this._renderInternals.lastRenderedAttributeMap?.get(L))return;if(this._renderInternals.trackedAttributeChanges.set(L,Z),!this._renderInternals.willRender)this._scheduleUpdate()}get root(){return this._root}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.add(L);this._scheduleUpdate()}listen(L,Y,Z){let G=w.processTargetDescriptor(L);if(G===":host"||G===":HOST"){this.addEventListener(Y,Z),this._ownListeners.add({handler:Z,event:Y});return}if(!this._delegator)this._delegator=new w(this.root);this._delegator.addListener(Y,Z,G)}stopListening(L,Y,Z){let G=w.processTargetDescriptor(L);if(G===":host"||G===":HOST"){this.removeEventListener(Y,Z);for(let Q of this._ownListeners)if(Q.event===Y&&Q.handler===Z)this._ownListeners.delete(Q);return}if(!this._delegator)return;this._delegator.removeListener(Y,Z,G)}dispatchEvent(L,Y,Z){if(L instanceof Event)return super.dispatchEvent(L);let G={bubbles:!0,cancelable:!0,composed:!0,...Z??{}};return super.dispatchEvent(new CustomEvent(L,{detail:Y,...G}))}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 Z=K(Y);if(Z===null)HTMLElement.prototype.removeAttribute.call(this,L);else HTMLElement.prototype.setAttribute.call(this,L,Z)}getAttribute(L,Y){let Z=HTMLElement.prototype.getAttribute.call(this,L);if(Y===void 0)return Z;if(typeof Y==="number"){if(Z===null)return Y;let G=Number(Z);if(Number.isNaN(G))return Y;return G}throw new U(0)}reflectAttribute(L,Y){let Z=this.getAttribute(L),G=K(Y);if(Z!==G)this.setAttribute(L,G)}toString(L=!1){let Y=this.constructor.name,Z=this.getAttributeNames().map((Q)=>{let W=this.getAttribute(Q);return W?`${Q}="${W}"`:""}).join(" "),G=Z.length>0?` ${Z}`:"";if(L)return`Component<${Y}${G}>
|
|
1
|
+
class U extends Error{name="PaletteError";code;constructor(L,...Y){let Z=`Code: ${L}`;super(Z);this.code=L}}function h(L,...Y){let Z=L[0]??"";for(let Q=0;Q<Y.length;Q++){let W=Y[Q]??"",$=L[Q+1]??"";Z+=`${W}${$}`}let G=new CSSStyleSheet;return G.replaceSync(Z),G}function S(...L){let Y="";for(let Z=0;Z<L.length;Z++){let G=L[Z];if(!G)continue;if(typeof G==="string"||typeof G==="number"){if(Y)Y+=" ";Y+=G;continue}if(Array.isArray(G)){let Q=S(...G);if(Q){if(Y)Y+=" ";Y+=Q}continue}if(typeof G==="object"){for(let Q in G)if(G[Q]){if(Y)Y+=" ";Y+=Q}}}return Y}function K(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 f(L){let Y=new Map;if(L instanceof HTMLElement){for(let Z of L.getAttributeNames())Y.set(Z,K(L.getAttribute(Z)));return Y}if(L instanceof Map){for(let[Z,G]of L)Y.set(Z,K(G));return Y}if(typeof L==="object"&&L!==null){for(let[Z,G]of Object.entries(L))Y.set(Z,K(G));return Y}throw new U(0)}function y(L,Y){let Z=new Set(L.getAttributeNames()),G=new Set(Y.keys()),Q=Z.difference(G);for(let W of Q)L.removeAttribute(W);for(let[W,$]of Y)if($===null)L.removeAttribute(W);else L.setAttribute(W,$)}function v(L,Y){let Z=document.createElement(Y);while(L.firstChild!==null)Z.appendChild(L.firstChild);for(let G of L.getAttributeNames()){let Q=L.getAttribute(G);if(Q!==null)Z.setAttribute(G,Q)}return L.replaceWith(Z),Z}function E(L){for(let Y=0;Y<L.length;Y++){let Z=L.charCodeAt(Y);if(!(Z===45||Z>=65&&Z<=90||Z>=97&&Z<=122))return!1}return!0}function c(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 Z=Y.slice(1,-1),G=Z.indexOf("=");if(G===-1)return L.hasAttribute(Z);let Q=Z.slice(0,G),W=Z.slice(G+1).replace(/^["']|["']$/g,"");return L.getAttribute(Q)===W}return L.matches(Y)}class b{_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)}};get metrics(){return{lookups:0,hits:0,misses:0,capacity:0,entries:0,hitRate:0}}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 m=b;var V=new m;function q(L){let Y=V.get(L);if(Y!==void 0)return Y.cloneNode(!0);let Z=document.createElement("template");return Z.innerHTML=L,V.set(L,Z.content),Z.content.cloneNode(!0)}function Y2(L){if(L instanceof HTMLTemplateElement)return L.innerHTML;if(typeof L==="function"&&(L.prototype instanceof I||L===I)){let Y=L.tagName;if(!E(Y))throw new U(202,L.name,L.tagName);return Y}if(typeof L==="string")return`<span ::swap="${L}"></span>`;throw new U(200,String(L))}function Z2(L,...Y){let Z=L.reduce((Q,W,$)=>{let M=Y[$]?`${Y2(Y[$])}`:"";return Q+W+M},""),G=document.createElement("template");return G.innerHTML=Z,G}var G2=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),Q2=new Set(["add","delete","clear","set"]);class D{_data;_listeners=new Set;_proxy;_proxyCache=new WeakMap;_reverseProxyCache=new WeakMap;_isLocked=!1;_hasWarned=!0;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 Z=this._proxyCache.get(L);if(Z)return Z;let G=new Proxy(L,{get:(Q,W)=>{if(typeof W==="symbol")return Q[W];let $=Q[W];if((Q instanceof Set||Q instanceof Map||Array.isArray(Q))&&typeof $==="function"){let F=(Array.isArray(Q)?G2:Q2).has(W);return(...H)=>{let z=this.snapshot(),X=z;for(let B of Y)X=X[B];let _=X[W](...H);if(F){if(this._isLocked)throw new U(305);this._processIncomingState(z)}return _}}if(typeof $==="object"&&$!==null)return this._createProxy($,[...Y,W]);return $},set:(Q,W,$)=>{if(this._isLocked)throw new U(305);if(typeof W==="symbol")return!1;let M=[...Y,W];return this._setNested(M,this._unwrapProxy($)),!0},has:(Q,W)=>{return W in Q},ownKeys:(Q)=>{return Reflect.ownKeys(Q)},getOwnPropertyDescriptor:(Q,W)=>{let $=Object.getOwnPropertyDescriptor(Q,W);if($)$.configurable=!0;return $},deleteProperty:(Q,W)=>{if(typeof W==="symbol"||!(W in Q))return!1;let $=[...Y,W];return this._setNested($,void 0),!0}});return this._proxyCache.set(L,G),this._reverseProxyCache.set(G,L),G}_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((Z)=>this._unwrapProxy(Z));if(Object.getPrototypeOf(L)===Object.prototype){let Z={};for(let G in L)if(Object.hasOwn(L,G))Z[G]=this._unwrapProxy(L[G]);return Z}return L}_setNested(L,Y){if(!L.length)return;let Z=this._data;for(let Q=0;Q<L.length-1;Q++){let W=L[Q]??"";if(!(W in Z))throw new U(303,L.join("."));Z=Z[W]}let G=L[L.length-1]??"";if(!(G in Z))throw new U(303,L.join("."));if(Z[G]!==Y&&!Object.is(Z[G],Y))Z[G]=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[Z,G]of Object.entries(L)){let Q=this._data[Z];if(!Object.is(Q,G))Y=!0,this._data[Z]=G}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 Z={};Z[L]=Y,this._processIncomingState(Z)};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 Z=await L(this.snapshot());if(this._processIncomingState(Z),Y)this._isLocked=!1;return this};transaction=(L)=>{if(this._isLocked)throw new U(305);this._isLocked=!0;let Y=!0;try{let Z=new D(this.snapshot());L(Z),this._processIncomingState(Z.current)}catch(Z){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 Z=new D(this.snapshot());await L(Z),this._processIncomingState(Z.current)}catch(Z){Y=!1}finally{this._isLocked=!1}return Y}}function p(L){if(L[0]!==":"||L.length<2)return!1;for(let Y=1;Y<L.length;Y++){let Z=L.charCodeAt(Y);if(!(Z===45||Z>=65&&Z<=90||Z>=97&&Z<=122))return!1}return!0}var W2={["@"]:"attr",["$"]:"state",["*"]:"data",["#"]:"item"},X2=new Map(Object.entries(W2));function g(L){let Y=!1,Z="",G=[],Q=!0;for(let W of L)if(Q&&W==="!")Y=!0;else if(Q){let $=X2.get(W);if(!$)throw new U(201,L);G.push($),Q=!1}else if(W===".")if(Z.length)G.push(Z),Z="";else throw new U(201,L);else Z+=W;if(!Z.length)throw new U(201,L);if(G.push(Z),G.length<2)throw new U(201,L);return{base:L,path:G,modifiers:Y?{not:!0}:void 0}}function k(L){let{path:Y,modifiers:Z}=L;if(Y.length<2)throw new U(0);if(Y.length===2){let[G,Q]=Y;if(G===void 0||Q===void 0)throw new U(0);return(W)=>{let $=W?.[G]?.[Q]??null;if(Z?.not){if(G==="attr")return $!==""&&!$;return!$}return $}}if(Y.length===3){let[G,Q,W]=Y;if(G===void 0||Q===void 0||W===void 0)throw new U(0);return($)=>{let M=$?.[G]?.[Q]?.[W]??null;if(Z?.not){if(G==="attr")return M!==""&&!M;return!M}return M}}return(G)=>{let Q=G;for(let W of Y){if(!Q||typeof Q!=="object")return null;Q=Q[W]}if(Z?.not){if(Y[0]==="attr")return Q!==""&&!Q;return!Q}return Q}}var P="data-node-ref";function $2(L){let Y=document.createTreeWalker(L,NodeFilter.SHOW_ELEMENT),Z=new Set,G=[],Q=Y.nextNode();while(Q){if(!(Q instanceof HTMLElement)){Q=Y.nextNode();continue}let W=Q.parentNode,$=!1;while(W&&!$){if(Z.has(W)||W instanceof HTMLElement&&W.hasAttribute("::each")){$=!0,Z.add(Q);break}W=W.parentNode}if(!$)G.push(Q);Q=Y.nextNode()}return G}function d(L){let Y=new Map,Z=[],G=0,Q=(X)=>{let _=X.getAttribute(P);if(!_)_=`el-${G++}`,X.setAttribute(P,_);return _},W=L.content.cloneNode(!0),$=$2(W);for(let X of $){let _=new Map;for(let B of X.getAttributeNames())_.set(B,X.getAttribute(B));for(let[B,J]of _){if(J===null||B[0]!==":")continue;let O=Y.get(J);if(O===void 0)O=g(J),Y.set(J,O);if(X.removeAttribute(B),B==="::key")continue;if(B==="::tag")Z.push({type:"tag",notation:O,nodeRef:Q(X)});else if(B==="::each"){let A=Q(X),x=X.getAttribute("::key");if(x===null)throw new U(206);X.removeAttribute("::key");let C=X.innerHTML;while(X.firstChild)X.removeChild(X.firstChild);let e={type:"each",notation:O,keyNotation:g(x),nodeRef:A,listContentHtml:C};Z.push(e)}else if(B==="::swap"){let A={type:"swap",notation:O,nodeRef:Q(X)};Z.push(A)}else if(p(B)){let A=B.slice(1),x={type:"attr",notation:O,attribute:A,nodeRef:Q(X)};Z.push(x)}}}let M={};for(let[X,_]of Y)M[X]=_;let F=document.createElement("div");return F.appendChild(W.cloneNode(!0)),{html:F.innerHTML,schemes:Z,notations:M}}function u(L,Y){let Z=new Map,G=new Map,Q=new Map;for(let[z,X]of Object.entries(L.notations))G.set(z,k(X));let W=Y??q(L.html),$=document.createTreeWalker(W,NodeFilter.SHOW_ELEMENT,{acceptNode(z){return z.hasAttribute(P)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}}),M=$.nextNode();while(M){if(!(M instanceof HTMLElement))continue;let z=M.getAttribute(P);if(z===null)throw new U(0);Q.set(z,M),M.removeAttribute(P),M=$.nextNode()}let F=(z,X)=>{let _=Z.get(X);if(!_)_=new Set,Z.set(X,_);_.add(z)},H=(z)=>{let X=Q.get(z);if(X)return X;throw new U(204)};for(let z of L.schemes)if(z.type==="each"){let X=H(z.nodeRef),_=X.parentElement;if(!_)throw new U(205);let B=document.createComment("list-start"),J=document.createComment("list-end");_.insertBefore(B,X),_.insertBefore(J,X.nextSibling);let O=X.cloneNode(!1),A=q(z.listContentHtml),x=document.createElement("template");x.appendChild(A),X.remove();let C={type:"each",notation:z.notation,keyNotation:z.keyNotation,listContainerElement:_,rowTemplateElement:x,rowRootElement:O,startMarker:B,endMarker:J,rowTemplatesByRoot:new WeakMap,rowRootsByKey:new Map};F(C,z.notation.base)}else if(z.type==="swap"){let X={type:"swap",notation:z.notation,node:H(z.nodeRef)};F(X,z.notation.base)}else if(z.type==="tag"){let X={type:"tag",notation:z.notation,node:H(z.nodeRef)};F(X,X.notation.base)}else if(z.type==="attr"){let X={type:"attr",attribute:z.attribute,notation:z.notation,node:H(z.nodeRef)};F(X,X.notation.base)}return{plansByNotation:Z,notationAccessors:G,fragment:W}}var j=Symbol("noop");function i(L,Y){let Z=Y.get(L.notation.base),G=typeof Z==="function"?Z(L.node):Z;if(L.attribute==="class"&&typeof G!=="string")G=S(G);let Q=K(G),W=L.node.getAttribute(L.attribute);if(Q!==W)return[L.node,L.attribute,Q];return j}function s(L){for(let[Y,Z,G]of L)if(G===null)Y.removeAttribute(Z);else Y.setAttribute(Z,G)}function l(L,Y){let Z=Y.get(L.notation.base),G=typeof Z==="function"?Z(L.node):Z;if(typeof G==="string"||typeof G==="number"||typeof G==="boolean"){let Q=`${G}`;if(L.node.textContent===Q)return j;return[L,document.createTextNode(Q)]}else if(G===null||G===void 0){if(L.node instanceof Comment)return j;return[L,document.createComment("empty")]}else if(G instanceof HTMLElement){if(Object.is(L.node,G))return j;return[L,G.cloneNode(!0)]}else throw new U(302,typeof G,JSON.stringify(G))}function o(L){for(let[Y,Z]of L){let G=Y.node.parentNode;if(!G)throw new U(0);G.replaceChild(Z,Y.node),Y.node=Z}}function n(L,Y){let Z=Y.get(L.notation.base)??"",Q=`${typeof Z==="function"?Z(L.node):Z}`.toLowerCase(),W=L.node.tagName.toLowerCase();if(!Q||Q===W)return j;return[L,Q]}function a(L){for(let[Y,Z]of L)Y.node=v(Y.node,Z)}function U2(L,Y){let Z=Y.get(L.notation.base),G=typeof Z==="function"?Z(L.startMarker.parentNode):Z;if(G===null||G===void 0)return[];if(Array.isArray(G))return G;throw new U(203)}function z2(L,Y){let Z=L,G=new Set;while(Z&&Z!==Y){if(Z instanceof HTMLElement)G.add(Z);Z=Z.nextSibling}return G}function r(L,Y){let Z=U2(L,Y);if(Z.length===0)return[L,[]];let{rowTemplatesByRoot:G,rowTemplateElement:Q,rowRootElement:W}=L,$=k(L.keyNotation),M=new Map;for(let F of Z){let H={item:F},z=$(H);if(M.has(z))throw new U(207,String(z));let X=L.rowRootsByKey.get(z);if(X===void 0)X=W.cloneNode(!1),L.rowRootsByKey.set(z,X);let _=G.get(X);if(_===void 0)_=new T(Q),G.set(X,_);let B={context:H,root:X,template:_,attrMap:f(F)};M.set(z,B)}for(let[F,H]of L.rowRootsByKey)if(!M.has(F))L.rowRootsByKey.delete(F),L.rowTemplatesByRoot.delete(H);return[L,Array.from(M.values())]}function t(L){for(let[Y,Z]of L){let{endMarker:G,listContainerElement:Q}=Y;if(Z.length===0){for(let F of Y.rowRootsByKey.values())F.remove();Y.rowRootsByKey.clear();continue}let W=Array.from(z2(Y.startMarker,Y.endMarker)),$=new Set,M=0;for(let F of Z){let{root:H,attrMap:z,context:X,template:_}=F,B=W[M];if(y(H,z),_.render(H,X),$.add(H),Object.is(B,H)){M+=1;continue}if(!B){Q.insertBefore(H,G);continue}Q.insertBefore(H,B)}for(let F of W)if(!$.has(F))F.remove(),Y.rowTemplatesByRoot.delete(F)}}var N=new b;class T{static cache={clear:()=>{V.clear(),N.clear()},setCapacity:(L)=>{V.setCapacity(L),N.setCapacity(L)}};_compiled;_templateElement;_mountedRoot;_latestRenderedValues=new Map;_fragment;_plansByNotation=new Map;_notationAccessors=new Map;constructor(L){if(L instanceof HTMLTemplateElement){this._templateElement=L;let Q=N.get(L)??d(L);this._compiled=Q,N.set(L,Q)}else this._compiled=L;let Y=q(this._compiled.html),Z=u(this._compiled,Y);this._plansByNotation=Z.plansByNotation,this._notationAccessors=Z.notationAccessors,this._fragment=Z.fragment}clone=()=>{return new T(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;for(let[Z,G]of this._notationAccessors){let Q=this._latestRenderedValues.get(Z),W=G(L);if(Q!==W&&!Object.is(Q,W))Y.set(Z,W)}return Y};_update(L){let Y=new Set,Z=[],G=[],Q=[],W=[];for(let[$]of L){let M=this._plansByNotation.get($);if(M)for(let F of M){if(Y.has(F))continue;switch(Y.add(F),F.type){case"attr":{let H=i(F,L);if(H!==j)Z.push(H);break}case"each":{let H=r(F,L);if(H!==j)W.push(H);break}case"swap":{let H=l(F,L);if(H!==j)G.push(H);break}case"tag":{let H=n(F,L);if(H!==j)Q.push(H);break}default:throw new U(0)}}}s(Z),t(W),o(G),a(Q)}render=(L,Y)=>{if(L!==this._mountedRoot){this._mountedRoot=L;while(L.firstChild)L.removeChild(L.firstChild);L.append(this._fragment)}let Z=this._collectUpdatedValues(Y);if(Z.size!==0){this._update(Z);for(let[G,Q]of Z)this._latestRenderedValues.set(G,Q)}}}class w{static nextListenerId=0;static processTargetDescriptor(L){if(L instanceof HTMLElement)if(L.id.length)return`#${L.id}`;else{let Y=`listen-${w.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 Z=this._handlersForEvent(L),G=Z.get(Y);if(G===void 0)G=new Set,Z.set(Y,G);return G}_createRootListener(L){if(this._rootListeners.has(L))return;let Y=(Z)=>{let G=this._handlersForEvent(L),{target:Q}=Z;if(Q===null||!(Q instanceof Node))return;let W=Q,$=!1,M=Z.stopImmediatePropagation;Z.stopImmediatePropagation=()=>{M.call(Z),$=!0};while(W){if(W===this._root)break;if(!(W instanceof Element)){W=W.parentNode;continue}for(let[F,H]of G)if(F==="*"||c(W,F)){for(let z of H)if(z.call(W,Z),$||Z.defaultPrevented)return}if(Z.cancelBubble)return;if(W=W.parentNode,W===this._root||W instanceof ShadowRoot)break}};this._rootListeners.set(L,Y),this._root.addEventListener(L,Y)}addListener(L,Y,Z="*"){this._handlersForEventAndQuery(L,Z).add(Y),this._createRootListener(L)}removeListener(L,Y,Z){let G=this._handlersForEventAndQuery(L,Z);if(G.delete(Y),G.size===0)this._handlersForEvent(L).delete(Z)}cleanup=()=>{for(let[L,Y]of this._rootListeners)this._root.removeEventListener(L,Y);this._rootListeners.clear()}}var F2=100,M2=document.createElement("template");class I extends HTMLElement{static register(L,Y){if(typeof window>"u"||typeof window.customElements>"u")throw new U(1);let Z="tagName"in L&&typeof L.tagName==="string"?L.tagName:null,G=Y??Z;if(G===null||G.length===0||!G.includes("-"))throw new U(101);if(window.customElements.get(G))throw new U(100,Y??"");window.customElements.define(G,L)}static tagName="";static template=M2;static styles=[];static observedAttributes=[];static shadowRootMode="closed";initialState;computedProperties;liveAttributes;_isComponentMounted=!1;_template;_root;_state;_delegator;_ownListeners=new Set;_liveAttributeConfigs=new Map;_cleanupFn;_renderInternals={willRender:!1,isRendering:!1,sequentialRenders:0,postRenderCallbacks:new Set,lastRenderedAttributeMap:new Map,trackedAttributeChanges:new Map};constructor(){super();let{template:L,styles:Y,shadowRootMode:Z}=this.constructor,G=Array.isArray(Y)?Y:typeof Y==="object"?[Y]:[h`${Y}`];this._root=this.attachShadow({mode:Z}),this._root.adoptedStyleSheets.push(...G),this._template=L instanceof T?L:new T(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 I&&"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=()=>{let L=this._renderInternals.lastRenderedAttributeMap,Y=new Map(this._renderInternals.trackedAttributeChanges);this._renderInternals.trackedAttributeChanges.clear();for(let[Z,G]of Y){let Q=this._liveAttributeConfigs.get(Z);if(!Q)continue;if("onChange"in Q){let W=L.get(Z)??null;if(Q&&W!==G)Q.onChange?.call(this,G,W)}}};_reflectLiveAttributes=()=>{let L=[];for(let[Y,Z]of this._liveAttributeConfigs)if("reflect"in Z){let G=K(Z.reflect?.call(this)),Q=this.getAttribute(Y);if(G!==Q)L.push([Y,G])}for(let[Y,Z]of L)this.reflectAttribute(Y,Z)};_performUpdate=()=>{try{this._renderInternals.isRendering=!0,this._renderInternals.willRender=!1,this._executeAttributeChangeHandlers();let L=this._renderInternals.lastRenderedAttributeMap;this.beforeUpdate?.();let Y=f(this);if(this._template.render(this.root,this._getRenderContext(Y)),this._renderInternals.lastRenderedAttributeMap=Y,this.afterUpdate?.(L),this._reflectLiveAttributes(),this._renderInternals.postRenderCallbacks.size){let Z=Array.from(this._renderInternals.postRenderCallbacks);this._renderInternals.postRenderCallbacks.clear();for(let G of Z)G()}if(this._renderInternals.willRender){if(this._renderInternals.sequentialRenders+=1,this._renderInternals.sequentialRenders>=F2)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 D?L:new D(L);this._state=Y,this._state.removeListener(this._scheduleUpdate),this._state.addListener(this._scheduleUpdate)}connectedCallback(){if(this._isComponentMounted)return;queueMicrotask(()=>{try{this._renderInternals.isRendering=!0,this._renderInternals.willRender=!1;let L=f(this);if(this._liveAttributeConfigs=new Map(Object.entries(this.liveAttributes??{})),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._isComponentMounted=!0,this._cleanupFn=this.script?.()??void 0}catch(L){this._reportError(L)}finally{this._renderInternals.isRendering=!1}})}disconnectedCallback(){queueMicrotask(()=>{if(this.isConnected||!this._isComponentMounted)return;try{if(this._delegator?.cleanup(),this._ownListeners.size>0)for(let L of this._ownListeners)this.removeEventListener(L.event,L.handler);this._cleanupFn?.(),this._isComponentMounted=!1}catch(L){this._reportError(L)}finally{try{this.finalize?.()}catch(L){this._reportError(L)}}})}attributeChangedCallback(L,Y,Z){if(this._renderInternals.isRendering)return;if(Z===this._renderInternals.lastRenderedAttributeMap?.get(L))return;if(this._renderInternals.trackedAttributeChanges.set(L,Z),!this._renderInternals.willRender)this._scheduleUpdate()}get root(){return this._root}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.add(L);this._scheduleUpdate()}listen(L,Y,Z){let G=w.processTargetDescriptor(L);if(G===":host"||G===":HOST"){this.addEventListener(Y,Z),this._ownListeners.add({handler:Z,event:Y});return}if(!this._delegator)this._delegator=new w(this.root);this._delegator.addListener(Y,Z,G)}stopListening(L,Y,Z){let G=w.processTargetDescriptor(L);if(G===":host"||G===":HOST"){this.removeEventListener(Y,Z);for(let Q of this._ownListeners)if(Q.event===Y&&Q.handler===Z)this._ownListeners.delete(Q);return}if(!this._delegator)return;this._delegator.removeListener(Y,Z,G)}dispatchEvent(L,Y,Z){if(L instanceof Event)return super.dispatchEvent(L);let G={bubbles:!0,cancelable:!0,composed:!0,...Z??{}};return super.dispatchEvent(new CustomEvent(L,{detail:Y,...G}))}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 Z=K(Y);if(Z===null)HTMLElement.prototype.removeAttribute.call(this,L);else HTMLElement.prototype.setAttribute.call(this,L,Z)}getAttribute(L,Y){let Z=HTMLElement.prototype.getAttribute.call(this,L);if(Y===void 0)return Z;if(typeof Y==="number"){if(Z===null)return Y;let G=Number(Z);if(Number.isNaN(G))return Y;return G}throw new U(0)}reflectAttribute(L,Y){let Z=this.getAttribute(L),G=K(Y);if(Z!==G)this.setAttribute(L,G)}toString(L=!1){let Y=this.constructor.name,Z=this.getAttributeNames().map((Q)=>{let W=this.getAttribute(Q);return W?`${Q}="${W}"`:""}).join(" "),G=Z.length>0?` ${Z}`:"";if(L)return`Component<${Y}${G}>
|
|
2
2
|
${this.root.innerHTML}
|
|
3
|
-
</${Y}>`;return`Component<${Y}${G}>`}}var
|
|
3
|
+
</${Y}>`;return`Component<${Y}${G}>`}}var H2=document.createElement("template");function _2(L,Y){let{template:Z=H2,styles:G=[],shadowRootMode:Q="closed",initialState:W,computedProperties:$={},liveAttributes:M={},script:F,beforeUpdate:H,afterUpdate:z,finalize:X,onError:_}=Y,B=Array.from(new Set([...Object.keys(M)])),J=class extends I{static tagName=L;static template=Z;static styles=G;static observedAttributes=[...B];static shadowRootMode=Q;constructor(){super();this.initialState=typeof W==="function"?W.bind(this):W,this.computedProperties=typeof $==="function"?$.bind(this):$,this.liveAttributes=M;for(let O of Object.values(this.liveAttributes)){if(O.onChange)O.onChange=O.onChange.bind(this);if(O.reflect)O.reflect=O.reflect.bind(this)}this.script=F?.bind(this)??void 0,this.beforeUpdate=H?.bind(this)??void 0,this.afterUpdate=z?.bind(this)??void 0,this.finalize=X?.bind(this)??void 0,this.onError=_?.bind(this)??void 0}};return I.register(J,L),J}export{Z2 as html,_2 as define,h as css,S as classify,T as Template,D as State,U as PaletteError,I as Component};
|