@rusticarcade/palette 0.1.0-rc.5 → 0.2.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.
@@ -360,10 +360,6 @@ declare class Template {
360
360
  private _update;
361
361
  /**
362
362
  * Render this template into a target host element.
363
- *
364
- * @remarks
365
- * If no context is provided, the root element is used as the context, which
366
- * allows for accessing nested properties of the host element itself.
367
363
  */
368
364
  render: (root: TemplateRoot, context: TemplateContext) => void;
369
365
  }
@@ -399,7 +395,7 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
399
395
  */
400
396
  static template: HTMLTemplateElement | Template;
401
397
  /**
402
- * A {@link CSSStyleSheet} array to adopt to the element's shadow DOM
398
+ * A {@link CSSStyleSheet} array or string to adopt as the component's scoped styles
403
399
  */
404
400
  static styles: ComponentStyles;
405
401
  /**
@@ -424,7 +420,7 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
424
420
  /**
425
421
  * Called immediately after each template update
426
422
  */
427
- protected afterUpdate?(previousAttributes: Map<string, string | null>): void;
423
+ protected afterUpdate?(previousAttributes: AttributeMap): void;
428
424
  /**
429
425
  * Called as the final lifecycle method at the end of the unmounting process.
430
426
  *
@@ -548,13 +544,12 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
548
544
  private _delegator?;
549
545
  private _ownListeners;
550
546
  private _liveAttributeConfigs;
551
- private _nextListenerAutoId;
552
547
  private _cleanupFn?;
553
548
  private _renderInternals;
554
549
  constructor();
555
550
  /** Produce the data object to pass to the template's render function */
556
551
  private _getRenderContext;
557
- private _safeGetState;
552
+ private _escalateError;
558
553
  private _reportError;
559
554
  private _executeAttributeChangeHandlers;
560
555
  private _reflectLiveAttributes;
@@ -671,8 +666,7 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
671
666
  * filter string to specify which elements to listen to events from.
672
667
  *
673
668
  * Event handlers set up with `listen()` are automatically cleaned up when
674
- * the component is unmounted. Event listeners are executed with this instance
675
- * as the `this` binding.
669
+ * the component is unmounted.
676
670
  *
677
671
  * Handlers are delegated to a single listener per event on the root of the
678
672
  * Component, which is the closed ShadowRoot by default.
@@ -695,6 +689,7 @@ declare abstract class Component<StateShape extends object = {}> extends HTMLEle
695
689
  * ```
696
690
  */
697
691
  listen<E extends EventName>(targetDescriptor: string | typeof Component<any> | HTMLElement, eventName: E, eventHandler: EventHandler<E>): void;
692
+ stopListening<E extends EventName>(targetDescriptor: string | typeof Component<any> | HTMLElement, eventName: E, eventHandler: EventHandler<E>): void;
698
693
  dispatchEvent(event: Event): boolean;
699
694
  /**
700
695
  * Dispatch a {@link CustomEvent} with the specified name and detail
@@ -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 C(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 I(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 P(L){let Y=new Map;if(L instanceof HTMLElement){for(let Z of L.getAttributeNames())Y.set(Z,I(L.getAttribute(Z)));return Y}if(L instanceof Map){for(let[Z,G]of L)Y.set(Z,I(G));return Y}if(typeof L==="object"&&L!==null){for(let[Z,G]of Object.entries(L))Y.set(Z,I(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 w{_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=w;var V=new m;function f(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 D||L===D)){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"]);class K{_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(Array.isArray(Q)&&typeof $==="function"){let M=G2.has(W);return(...z)=>{let H=this.snapshot(),F=H;for(let _ of Y)F=F[_];let X=F[W](...z);if(M){if(this._isLocked)throw new U(305);this._processIncomingState(H)}return X}}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 K(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 K(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}function h(L){let Y=L,Z=!1;if(L[0]==="N"&&L[1]==="O"&&L[2]==="T"&&L[3]===":")Y=L.slice(4),Z=!0;let G=Y[0];if(G==="@")Y=`attr.${Y.slice(1)}`;else if(G==="$")Y=`state.${Y.slice(1)}`;else if(G==="*")Y=`data.${Y.slice(1)}`;else if(G==="#")Y=`item.${Y.slice(1)}`;else throw new U(201,Y);let Q=Y.split(".");if(Q.length<2)throw new U(201,Y);return{base:L,path:Q,modifiers:Z?{not:!0}:void 0}}function b(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)=>{if(Z?.not){let $=W?.[G]?.[Q]??null;if(G==="attr")return $!==""&&!$;return!$}return W?.[G]?.[Q]??null}}if(Y.length===3){let[G,Q,W]=Y;if(G===void 0||Q===void 0||W===void 0)throw new U(0);return($)=>{if(Z?.not){let M=$?.[G]?.[Q]?.[W]??null;if(G==="attr")return M!==""&&!M;return!M}return $?.[G]?.[Q]?.[W]??null}}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 q="data-node-ref";function Q2(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(q);if(!_)_=`el-${G++}`,X.setAttribute(q,_);return _},W=L.content.cloneNode(!0),$=Q2(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=h(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 x=Q(X),A=X.getAttribute("::key");if(A===null)throw new U(206);X.removeAttribute("::key");let N=X.innerHTML;while(X.firstChild)X.removeChild(X.firstChild);let e={type:"each",notation:O,keyNotation:h(A),nodeRef:x,listContentHtml:N};Z.push(e)}else if(B==="::swap"){let x={type:"swap",notation:O,nodeRef:Q(X)};Z.push(x)}else if(p(B)){let x=B.slice(1),A={type:"attr",notation:O,attribute:x,nodeRef:Q(X)};Z.push(A)}}}let M={};for(let[X,_]of Y)M[X]=_;let z=document.createElement("div");return z.appendChild(W.cloneNode(!0)),{html:z.innerHTML,schemes:Z,notations:M}}function u(L,Y){let Z=new Map,G=new Map,Q=new Map;for(let[F,X]of Object.entries(L.notations))G.set(F,b(X));let W=Y??f(L.html),$=document.createTreeWalker(W,NodeFilter.SHOW_ELEMENT,{acceptNode(F){return F.hasAttribute(q)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}}),M=$.nextNode();while(M){if(!(M instanceof HTMLElement))continue;let F=M.getAttribute(q);if(F===null)throw new U(0);Q.set(F,M),M.removeAttribute(q),M=$.nextNode()}let z=(F,X)=>{let _=Z.get(X);if(!_)_=new Set,Z.set(X,_);_.add(F)},H=(F)=>{let X=Q.get(F);if(X)return X;throw new U(204)};for(let F of L.schemes)if(F.type==="each"){let X=H(F.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),x=f(F.listContentHtml),A=document.createElement("template");A.appendChild(x),X.remove();let N={type:"each",notation:F.notation,keyNotation:F.keyNotation,listContainerElement:_,rowTemplateElement:A,rowRootElement:O,startMarker:B,endMarker:j,rowTemplatesByRoot:new WeakMap,rowRootsByKey:new Map};z(N,F.notation.base)}else if(F.type==="swap"){let X={type:"swap",notation:F.notation,node:H(F.nodeRef)};z(X,F.notation.base)}else if(F.type==="tag"){let X={type:"tag",notation:F.notation,node:H(F.nodeRef)};z(X,X.notation.base)}else if(F.type==="attr"){let X={type:"attr",attribute:F.attribute,notation:F.notation,node:H(F.nodeRef)};z(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=I(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 W2(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 X2(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=W2(L,Y);if(Z.length===0)return[L,[]];let{rowTemplatesByRoot:G,rowTemplateElement:Q,rowRootElement:W}=L,$=b(L.keyNotation),M=new Map;for(let z of Z){let H={item:z},F=$(H);if(M.has(F))throw new U(207,String(F));let X=L.rowRootsByKey.get(F);if(X===void 0)X=W.cloneNode(!1),L.rowRootsByKey.set(F,X);let _=G.get(X);if(_===void 0)_=new T(Q),G.set(X,_);let B={context:H,root:X,template:_,attrMap:P(z)};M.set(F,B)}for(let[z,H]of L.rowRootsByKey)if(!M.has(z))L.rowRootsByKey.delete(z),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 z of Y.rowRootsByKey.values())z.remove();Y.rowRootsByKey.clear();continue}let W=Array.from(X2(Y.startMarker,Y.endMarker)),$=new Set,M=0;for(let z of Z){let{root:H,attrMap:F,context:X,template:_}=z,B=W[M];if(y(H,F),_.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 z of W)if(!$.has(z))z.remove(),Y.rowTemplatesByRoot.delete(z)}}var k=new w;class T{static cache={clear:()=>{V.clear(),k.clear()},setCapacity:(L)=>{V.setCapacity(L),k.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=k.get(L)??d(L);this._compiled=Q,k.set(L,Q)}else this._compiled=L;let Y=f(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 z of M){if(Y.has(z))continue;switch(Y.add(z),z.type){case"attr":{let H=i(z,L);if(H!==J)Z.push(H);break}case"each":{let H=r(z,L);if(H!==J)W.push(H);break}case"swap":{let H=l(z,L);if(H!==J)G.push(H);break}case"tag":{let H=n(z,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 g{_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[z,H]of G)if(z==="*"||c(W,z)){for(let F of H)if(F.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 $2=100,U2=document.createElement("template");class D 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=U2;static styles=[];static observedAttributes=[];static shadowRootMode="closed";initialState;computedProperties;liveAttributes;_isComponentMounted=!1;_template;_root;_state;_delegator;_ownListeners=new Set;_liveAttributeConfigs=new Map;_nextListenerAutoId=0;_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]:[C`${Y}`];this._root=this.attachShadow({mode:Z}),this._root.adoptedStyleSheets.push(...G),this._template=L instanceof T?L:new T(L)}_getRenderContext(L){let Y=typeof this.computedProperties==="function"?this.computedProperties():this.computedProperties,Z=this.initialState?this._safeGetState().current:void 0;return{data:Y,attr:Object.fromEntries(L),state:Z}}_safeGetState(){if(!this.initialState||!this._state)throw new U(301);return this._state}_reportError(L){if(!this.onError)throw L;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=I(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=P(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>=$2)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(this._state)this._state.removeListener(this._scheduleUpdate),this._scheduleUpdate();let Y=L instanceof K?L:new K(L);this._state=Y,this._state.removeListener(this._scheduleUpdate),this._state.addListener(this._scheduleUpdate)}connectedCallback(){if(this._isComponentMounted)return;try{let L=P(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(){return this._safeGetState().live}set state(L){if(!this._state)throw new U(301);else if(L instanceof K)this._state=L,this._state.addListener(()=>{this.requestRender()}),this.requestRender();else this._state.replace(L)}getState(){return this._safeGetState()}requestRender(L){if(L)this._renderInternals.postRenderCallbacks.add(L);this._scheduleUpdate()}listen(L,Y,Z){let G="";if(L instanceof HTMLElement)if(L.id.length)G=`#${L.id}`;else{let Q=`listen-${this._nextListenerAutoId++}`;L.setAttribute("data-listener-id",Q),G=`[data-listener-id="${Q}"]`}else if(typeof L==="function")G=L.tagName;else G=L;if(G===":host"||G===":HOST"){let Q=Z.bind(this);this.addEventListener(Y,Q),this._ownListeners.add({handler:Q,event:Y});return}if(!this._delegator)this._delegator=new g(this.root);this._delegator.addListener(Y,Z.bind(this),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=I(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=I(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 E(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 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,$)=>{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 x=Q(X),A=X.getAttribute("::key");if(A===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(A),nodeRef:x,listContentHtml:C};Z.push(e)}else if(B==="::swap"){let x={type:"swap",notation:O,nodeRef:Q(X)};Z.push(x)}else if(p(B)){let x=B.slice(1),A={type:"attr",notation:O,attribute:x,nodeRef:Q(X)};Z.push(A)}}}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),x=q(z.listContentHtml),A=document.createElement("template");A.appendChild(x),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};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]:[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"){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 F2=document.createElement("template");function z2(L,Y){let{template:Z=F2,styles:G=[],shadowRootMode:Q="closed",initialState:W,computedProperties:$={},liveAttributes:M={},script:z,beforeUpdate:H,afterUpdate:F,finalize:X,onError:_}=Y,B=Array.from(new Set([...Object.keys(M)])),j=class extends D{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=z?.bind(this)??void 0,this.beforeUpdate=H?.bind(this)??void 0,this.afterUpdate=F?.bind(this)??void 0,this.finalize=X?.bind(this)??void 0,this.onError=_?.bind(this)??void 0}};return D.register(j,L),j}export{Z2 as html,z2 as define,C as css,S as classify,T as Template,K as State,U as PaletteError,D as Component};
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,E as css,S as classify,T as Template,D as State,U as PaletteError,I as Component};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rusticarcade/palette",
3
- "description": "Build web apps like the hipster you are",
4
- "version": "0.1.0-rc.5",
3
+ "description": "Native web development, but make it joyful",
4
+ "version": "0.2.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist/prod",