@rusticarcade/palette 0.3.1 → 0.4.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.
@@ -1,3 +1 @@
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 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,$]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 S="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(S);if(!_)_=`el-${G++}`,X.setAttribute(S,_);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(S)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}}),M=$.nextNode();while(M){if(!(M instanceof HTMLElement))continue;let z=M.getAttribute(S);if(z===null)throw new U(0);Q.set(z,M),M.removeAttribute(S),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.content.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=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 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
- ${this.root.innerHTML}
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,P as classify,T as Template,D as State,U as PaletteError,I as Component};
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};
@@ -35,7 +35,6 @@ declare class State<Shape extends object> {
35
35
  private _proxyCache;
36
36
  private _reverseProxyCache;
37
37
  private _isLocked;
38
- private _hasWarned;
39
38
  constructor(initialData: Shape, onChange?: StateListener<Shape>);
40
39
  /**
41
40
  * Lazily create and cache proxies into the state for reactive updates on
@@ -68,28 +67,12 @@ declare class State<Shape extends object> {
68
67
  */
69
68
  get current(): Readonly<Shape>;
70
69
  /**
71
- * Proxied access to state properties with automatic reconciliation.
70
+ * Live reactive accessor for state data. Deeply nested changes trigger
71
+ * automatic updates, including array, Map, and Set mutations.
72
72
  *
73
- * Allows direct property access for both reading and writing state values.
74
- *
75
- * @example
76
- *
77
- * Deep reactivity with the `.live` accessor
78
- *
79
- * ```typescript
80
- * const state = new State({
81
- * nested: {
82
- * values: [1, 2, 3],
83
- * }
84
- * });
85
- *
86
- * // Deep value assignment triggers state updates
87
- * state.live.nested.values[1] = 5;
88
- *
89
- * // Array mutators are automatically reactive as well
90
- * state.live.nested.values.push(4);
91
- * state.live.nested.values.reverse();
92
- * ```
73
+ * @remarks
74
+ * For deeply nested values, the `.live` accessor may add performance overhead
75
+ * compared to directly accessing the value via `.current`
93
76
  */
94
77
  get live(): Shape;
95
78
  /**
@@ -281,6 +264,72 @@ declare class State<Shape extends object> {
281
264
  */
282
265
  transactionAsync: (fn: (state: State<Shape>) => Promise<void>) => Promise<boolean>;
283
266
  }
267
+ type ParsedNotation = {
268
+ /** The raw string representation of the parsed notation */
269
+ base: string;
270
+ /** An array of property names forming a path to the notation value */
271
+ path: string[];
272
+ modifiers?: {
273
+ not?: boolean;
274
+ };
275
+ };
276
+ type NotationAccessor = (source: unknown) => unknown;
277
+ declare const enum Directive {
278
+ Each = "::each",
279
+ Key = "::key",
280
+ Tag = "::tag",
281
+ Swap = "::swap",
282
+ If = "::if",
283
+ ElseIf = "::else-if",
284
+ Else = "::else"
285
+ }
286
+ type ConditionalRenderSchemeBranch = {
287
+ type: Directive.If | Directive.ElseIf;
288
+ notation: ParsedNotation;
289
+ branchRootRef: string;
290
+ branchTemplateHTML: string;
291
+ } | {
292
+ type: Directive.Else;
293
+ branchRootRef: string;
294
+ branchTemplateHTML: string;
295
+ };
296
+ interface ConditionalRenderScheme {
297
+ type: "cond";
298
+ branches: ConditionalRenderSchemeBranch[];
299
+ }
300
+ interface AttributeUpdateScheme {
301
+ type: "attr";
302
+ notation: ParsedNotation;
303
+ attribute: string;
304
+ nodeRef: string;
305
+ }
306
+ interface TagChangeScheme {
307
+ type: "tag";
308
+ notation: ParsedNotation;
309
+ nodeRef: string;
310
+ }
311
+ interface ContentSwapScheme {
312
+ type: "swap";
313
+ notation: ParsedNotation;
314
+ nodeRef: string;
315
+ }
316
+ interface ListRenderScheme {
317
+ type: "each";
318
+ notation: ParsedNotation;
319
+ keyNotation: ParsedNotation;
320
+ nodeRef: string;
321
+ listContentHtml: string;
322
+ }
323
+ type AnyScheme = AttributeUpdateScheme | TagChangeScheme | ContentSwapScheme | ListRenderScheme | ConditionalRenderScheme;
324
+ /**
325
+ * A JSON-serializable representation of a {@link Template} instance, including
326
+ * everything needed to recreate the template.
327
+ */
328
+ interface CompiledTemplate {
329
+ html: string;
330
+ schemes: AnyScheme[];
331
+ notations: Record<string, ParsedNotation>;
332
+ }
284
333
  type TemplateRoot = HTMLElement | ShadowRoot;
285
334
  type TemplateContext = {
286
335
  attr?: Record<string, string | null>;
@@ -355,7 +404,10 @@ declare class Template {
355
404
  private _plansByNotation;
356
405
  /** Value Notations -> Accessor functions */
357
406
  private _notationAccessors;
407
+ private _subtemplates;
358
408
  constructor(template: HTMLTemplateElement);
409
+ get compiled(): CompiledTemplate;
410
+ get notationMap(): Map<string, NotationAccessor>;
359
411
  /**
360
412
  * Create a full copy of this template for use in rendering to another root
361
413
  */
@@ -366,6 +418,7 @@ declare class Template {
366
418
  element: () => HTMLTemplateElement;
367
419
  private _collectUpdatedValues;
368
420
  private _update;
421
+ renderWithValues: (root: TemplateRoot, values: Map<string, unknown>) => void;
369
422
  /**
370
423
  * Render this template into a target host element.
371
424
  */
@@ -383,31 +436,26 @@ type ComputedProperties<StateShape extends object = {}> = Record<string, unknown
383
436
  type ComponentStyles = CSSStyleSheet | CSSStyleSheet[] | string;
384
437
  type AttributeMap = Map<string, string | null>;
385
438
  type StateInitializer<Shape extends object = {}> = Shape | State<Shape> | ((this: Component<Shape>) => Shape | State<Shape>);
439
+ declare enum RootMode {
440
+ Closed = "closed",
441
+ Open = "open"
442
+ }
386
443
  /**
387
444
  * The **Component** class extends the base HTMLElement class to provide an
388
445
  * ergonomic way to design and develop Web Components with reactive state,
389
446
  * managed attributes, and dynamic templating.
390
447
  */
391
448
  declare abstract class Component<StateShape extends object = {}> extends HTMLElement {
392
- /**
393
- * Register a Component with the browser. Optionally provide an overriding
394
- * tag name.
395
- */
396
- static register(component: CustomElementConstructor | typeof Component, tagName?: string): void;
397
- /**
398
- * The HTML tag name to use for this Component
399
- */
449
+ /** The HTML tag name to use for this Component */
400
450
  static tagName: string;
401
- /**
402
- * An HTML Template element for this element to use.
403
- */
451
+ /** An HTML Template element for this element to use. */
404
452
  static template: HTMLTemplateElement | Template;
405
453
  /**
406
- * A {@link CSSStyleSheet} array or string to adopt as the component's scoped styles
454
+ * Styles for this Component
407
455
  */
408
456
  static styles: ComponentStyles;
409
457
  /**
410
- * An array of html attribute names to observe to trigger updates.
458
+ * A list of attribute names to track changes for
411
459
  *
412
460
  * @remarks
413
461
  * If you use the {@link define} factory helper, this value will be
@@ -415,39 +463,23 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
415
463
  */
416
464
  static observedAttributes: string[];
417
465
  /**
418
- * The mode for this Component's ShadowRoot.
419
- *
420
- * - `"open"` allows JS access to the children of this component
421
- * - `"closed"` (default) disallows internal JS access
466
+ * The mode for this Component's ShadowRoot. Must be a {@link RootMode}
422
467
  */
423
- static shadowRootMode: "closed" | "open";
468
+ static rootMode: RootMode;
424
469
  /**
425
- * Called immediately before each template update
470
+ * Initialization lifecycle method. Main scripting and event listeners.
471
+ * @returns a function to handle cleanup tasks when the component unmounts
426
472
  */
473
+ protected script?(): VoidFunction | void;
474
+ /** Called immediately before each template update */
427
475
  protected beforeUpdate?(): void;
428
- /**
429
- * Called immediately after each template update
430
- */
476
+ /** Called immediately after each template update */
431
477
  protected afterUpdate?(previousAttributes: AttributeMap): void;
432
- /**
433
- * Called as the final lifecycle method at the end of the unmounting process.
434
- *
435
- * Content has been removed from the DOM and the component is no longer
436
- * considered mounted when this function runs.
437
- *
438
- * Use this for final cleanup tasks and freeing resources.
439
- */
478
+ /** Final lifecycle method called at the end of the unmounting process. */
440
479
  protected finalize?(): void;
441
480
  /**
442
- * If defined, receives errors caught during the lifecycle methods of this
443
- * component and it's children. If not defined, this component will instead
444
- * throw errors as they are found.
445
- *
446
- * If the error cannot be handled, `onError()` should re-throw it for a higher
447
- * up component to evaluate.
448
- *
449
- * To display an error message while removing an erroring component from the
450
- * DOM, use `this.replaceWith()` and a newly constructed placeholder element.
481
+ * When defined, catches any errors thrown during lifecycle mthods of this
482
+ * component as well as any uncaught errors from child components.
451
483
  *
452
484
  * @example
453
485
  *
@@ -455,16 +487,12 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
455
487
  *
456
488
  * ```typescript
457
489
  * onError(error) {
458
- * // Handle known errors
459
- * if (error.message = "Invalid Input") {
460
- * this.state.input = "";
490
+ * if (error.canRecover) {
491
+ * this.recover();
461
492
  * return;
462
493
  * }
463
494
  *
464
- * // Display a fallback banner
465
- * const banner = document.createElement("div");
466
- * banner.textContent = "An unexpected error done did";
467
- * this.replaceWith(banner);
495
+ * this.replaceWith("Oh dear, an error happened real bad");
468
496
  * }
469
497
  * ```
470
498
  */
@@ -472,6 +500,7 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
472
500
  /**
473
501
  * The initial value for this Component's reactive internal state, if any.
474
502
  *
503
+ * @remarks
475
504
  * If `initialState` is defined as a function, the function is evaluated at
476
505
  * mounting time and the return value is used as the initial state.
477
506
  */
@@ -480,20 +509,6 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
480
509
  * An object or function returning an object which populates the `data` values
481
510
  * in the templating engine. Such values are accessed using the `*` notation.
482
511
  *
483
- * When a hosted value is accessed, it's value is coerced based on the way it
484
- * is being used. For attributes, values are serialized to a string or null,
485
- * which will set the attribute (string) or remove it (null).
486
- *
487
- * For content swaps, strings, numbers and booleans are rendered as strings
488
- * and set as textContent. null and undefined values render nothing (with a
489
- * comment placeholder), an HTMLElement will be swapped in as a cloned node.
490
- *
491
- * Functions are evaluated at render/update time, and their return value is
492
- * used instead. Functions are passed the current target node accessing the
493
- * property as its first and only argument.
494
- *
495
- * Other types are unsupported.
496
- *
497
512
  * @example
498
513
  *
499
514
  * ```typescript
@@ -510,17 +525,8 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
510
525
  */
511
526
  protected computedProperties?: ComputedProperties<StateShape>;
512
527
  /**
513
- * Declaration of attribute behaviors during updates.
514
- *
515
- * Each key is the name of an attribute. Values are an object with two
516
- * optional function definitions:
517
- *
518
- * `onChange(newValue, oldValue): void`, a handler function for when the value
519
- * of this attribute has changed. Runs once per update cycle, *before* the
520
- * update occurs.
521
- *
522
- * `reflect(): unknown`, a function which returns a value to serialize and set
523
- * as this attribute *after* an update completes.
528
+ * Define attribute update and reflection behaviors as a record of attribute
529
+ * name keys to objects with optionally defined behaviors.
524
530
  *
525
531
  * @example
526
532
  *
@@ -536,22 +542,24 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
536
542
  * ```
537
543
  *
538
544
  * @remarks
545
+ * The optional functions are:
546
+ *
547
+ * `onChange(newValue, oldValue): void`, a handler function for when the value
548
+ * of this attribute has changed. Runs once per update cycle, *before* the
549
+ * update occurs.
550
+ *
551
+ * `reflect(): unknown`, a function which returns a value to serialize and set
552
+ * as this attribute *after* an update completes.
539
553
  *
540
554
  * If using the {@link define} helper, the keys of this property are
541
555
  * automatically merged with any defined {@link observedAttributes}.
542
- *
543
- * If you are directly extending the class, `observedAttributes` must be
544
- * explicitly defined with any attributes that should be monitored, regardless
545
- * of if they're defined here.
546
556
  */
547
557
  protected liveAttributes?: LiveAttributes<StateShape>;
548
- private _isComponentMounted;
549
558
  private _template;
550
559
  private _root;
551
560
  private _state?;
552
561
  private _delegator?;
553
- private _ownListeners;
554
- private _liveAttributeConfigs;
562
+ private _ownListeners?;
555
563
  private _cleanupFn?;
556
564
  private _renderInternals;
557
565
  constructor();
@@ -582,86 +590,29 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
582
590
  * The ShadowRoot node of this element
583
591
  */
584
592
  get root(): ShadowRoot;
593
+ get isMounted(): boolean;
585
594
  /**
586
- * Directly access and manipulate this Component's reactive state with deep
587
- * reactivity enabled.
588
- *
589
- * @example
595
+ * Accessor for live reactive state.
590
596
  *
591
- * ```typescript
592
- * initialState = { values: { count: 1, time: 0 } };
593
- *
594
- * increment() {
595
- * this.state.values.count = 2;
596
- * }
597
- * ```
598
- *
599
- * @remarks
600
- * This is a shorthand getter for `this.getState().live`
597
+ * For the full state manipulation API, use {@link getState}
601
598
  */
602
599
  get state(): StateShape;
603
600
  /**
604
601
  * Replace the current state with a new value or adopt a whole different State
605
602
  * instance
606
- *
607
- * @example
608
- *
609
- * State replacement
610
- *
611
- * ```typescript
612
- * // Always triggers a render
613
- * this.state = { some: "newState" }
614
- *
615
- * // Adopt a new state instance altogether
616
- * const otherState = new State({some: "newState"});
617
- * this.state = otherState;
618
- *
619
- * // Causes a render
620
- * otherState.set("some", "value");
621
- * ```
622
603
  */
623
604
  set state(newState: StateShape | State<StateShape>);
624
605
  /**
625
606
  * Access the full {@link State} instance for this Component.
626
607
  *
627
- * Using this method on a component which is not using reactive state
608
+ * @remarks
609
+ * Calling this method on a component which is not using reactive state
628
610
  * will result in an error being thrown.
629
- *
630
- * @example
631
- *
632
- * Retrieve stateful value
633
- *
634
- * ```typescript
635
- * class Example extends Component {
636
- * initialState = { count: 1 };
637
- *
638
- * script() {
639
- * const state = this.getState();
640
- * console.log(`The count is ${state.get("count")}`);
641
- * }
642
- *
643
- * }
644
- * ```
645
- *
646
- * @example
647
- *
648
- * Set a stateful value
649
- *
650
- * ```typescript
651
- * class Example extends Component {
652
- * initialState = { count: 1 };
653
- *
654
- * increment() {
655
- * const state = this.getState();
656
- * const current = state.get("count");
657
- * state.set("count", current + 1);
658
- * }
659
- * }
660
- * ```
661
611
  */
662
612
  getState(): State<StateShape>;
663
613
  /**
664
- * Manually schedule a render to occur
614
+ * Manually schedule a render to occur, optionally providing a callback to
615
+ * invoke after the render completes.
665
616
  *
666
617
  * @remarks
667
618
  * Calling {@link requestRender} multiple times in the same event loop won't
@@ -670,57 +621,19 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
670
621
  */
671
622
  requestRender(callback?: VoidFunction): void;
672
623
  /**
673
- * Create a managed event listener on this Component with an optional query
674
- * filter string to specify which elements to listen to events from.
624
+ * Listen for events from within this Component.
675
625
  *
676
- * Event handlers set up with `listen()` are automatically cleaned up when
677
- * the component is unmounted.
678
- *
679
- * Handlers are delegated to a single listener per event on the root of the
680
- * Component, which is the closed ShadowRoot by default.
681
- *
682
- * @example
683
- *
684
- * Set up an event listener for a click event from a button with ID "submit"
685
- *
686
- * ```typescript
687
- * this.listen("#submit", "click", this.handleClick);
688
- * ```
626
+ * Provide a query string to target specific element events, or use `:host`
627
+ * to create listeners on the host element itself.
689
628
  *
690
- * @example
691
- *
692
- * Set up an event listener on the host element itself (`this`).
693
- *
694
- * ```typescript
695
- * // Use ":host" or ":HOST" as the query selector to targe the host element
696
- * this.listen(":host", "animationend", this.handler);
697
- * ```
629
+ * Event listeners created with this method are automatically cleaned up when
630
+ * the component unmounts.
698
631
  */
699
632
  listen<E extends EventName>(targetDescriptor: string | typeof Component<any> | HTMLElement, eventName: E, eventHandler: EventHandler<E>): void;
700
633
  stopListening<E extends EventName>(targetDescriptor: string | typeof Component<any> | HTMLElement, eventName: E, eventHandler: EventHandler<E>): void;
701
634
  dispatchEvent(event: Event): boolean;
702
635
  /**
703
636
  * Dispatch a {@link CustomEvent} with the specified name and detail
704
- *
705
- * @example Defining custom events
706
- *
707
- * ```typescript
708
- * // Define types. This can happen in the same file or elsewhere for common
709
- * // and shared events.
710
- * type MyEvent = CustomEvent<T> // Set `T` to the event detail type
711
- *
712
- * declare global {
713
- * interface GlobalEventHandlersEventMap {
714
- * "my-event-name": MyEvent
715
- * }
716
- * }
717
- *
718
- * // Dispatch a custom event
719
- * this.dispatchEvent("my-event-name", T);
720
- *
721
- * // Listen to a custom event
722
- * $el.addEventListener("my-event-name", ...);
723
- * ```
724
637
  */
725
638
  dispatchEvent<T>(event: string, detail?: T, options?: {
726
639
  bubbles: boolean;
@@ -742,11 +655,8 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
742
655
  /**
743
656
  * Get an attribute as a number, falling back to a specified default.
744
657
  *
745
- *
746
658
  * `null` attributes are returned as `null`, while string attributes are
747
- * parsed using the `Number()` constructor.
748
- *
749
- * Values which evaluate to NaN are returned as `null`.
659
+ * parsed using the `Number()` constructor. NaN is coerced to `null`.
750
660
  */
751
661
  getAttribute(name: string, defaultValue: number): number;
752
662
  /**
@@ -761,7 +671,7 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
761
671
  /**
762
672
  * Serialize this element to a string
763
673
  */
764
- toString(full?: boolean): string;
674
+ toString(): string;
765
675
  }
766
676
  /**
767
677
  * Render a Palette Component class as a test element