tosijs 1.0.8 → 1.0.10

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.
@@ -6,7 +6,7 @@ import { bind, on } from './bind';
6
6
  import { elements, svgElements, mathML } from './elements';
7
7
  import { ElementCreator, PartsMap } from './xin-types';
8
8
  import { xin, boxed } from './xin';
9
- import { xinProxy, boxedProxy } from './xin-proxy';
9
+ import { xinProxy, tosi, boxedProxy } from './xin-proxy';
10
10
  export interface XinFactory {
11
11
  Color: typeof Color;
12
12
  Component: typeof Component;
@@ -19,6 +19,7 @@ export interface XinFactory {
19
19
  boxed: typeof boxed;
20
20
  xinProxy: typeof xinProxy;
21
21
  boxedProxy: typeof boxedProxy;
22
+ tosi: typeof tosi;
22
23
  makeComponent: typeof makeComponent;
23
24
  bind: typeof bind;
24
25
  on: typeof on;
@@ -5,10 +5,11 @@ export declare const EVENT_CLASS = "-xin-event";
5
5
  export declare const EVENT_SELECTOR = ".-xin-event";
6
6
  export declare const XIN_PATH = "xinPath";
7
7
  export declare const XIN_VALUE = "xinValue";
8
- export declare const XIN_SET = "xinSet";
9
8
  export declare const XIN_OBSERVE = "xinObserve";
10
9
  export declare const XIN_BIND = "xinBind";
11
10
  export declare const XIN_ON = "xinOn";
11
+ export declare const LIST_BINDING_REF: unique symbol;
12
+ export declare const LIST_INSTANCE_REF: unique symbol;
12
13
  export declare const xinPath: (x: any) => string | undefined;
13
14
  export declare function xinValue<T>(x: T): Unboxed<T>;
14
15
  export interface DataBinding<T extends Element = Element> {
@@ -28,6 +29,4 @@ interface ElementMetadata {
28
29
  }
29
30
  export declare const getElementBindings: (element: Element) => ElementMetadata;
30
31
  export declare const cloneWithBindings: (element: Node) => Node;
31
- export declare const elementToItem: WeakMap<Element, XinObject>;
32
- export declare const getListItem: (element: Element) => any;
33
32
  export {};
package/dist/module.js CHANGED
@@ -1,13 +1,13 @@
1
- var H={debug:!1,perf:!1};function C(n){if(n==null||typeof n!=="object")return n;if(n instanceof Set)return new Set(n);else if(Array.isArray(n))return n.map(C);let e={};for(let o in n){let i=n[o];if(n!=null&&typeof n==="object")e[o]=C(i);else e[o]=i}return e}var un="-xin-data",L=`.${un}`,pn="-xin-event",yn=`.${pn}`,b="xinPath",O="xinValue",Yn="xinSet",Jn="xinObserve",Vn="xinBind",Un="xinOn",M=(n)=>{return n&&n[b]||void 0};function w(n){return typeof n==="object"&&n!==null?n[O]||n:n}var $=new WeakMap,v=new WeakMap;var z=(n)=>{let e=n.cloneNode();if(e instanceof Element){let o=v.get(n),i=$.get(n);if(o!=null)v.set(e,C(o));if(i!=null)$.set(e,C(i))}for(let o of Array.from(n instanceof HTMLTemplateElement?n.content.childNodes:n.childNodes))if(o instanceof Element||o instanceof DocumentFragment)e.appendChild(z(o));else e.appendChild(o.cloneNode());return e},_=new WeakMap,mn=(n)=>{let e=document.body.parentElement;while(n.parentElement!=null&&n.parentElement!==e){let o=_.get(n);if(o!=null)return o;n=n.parentElement}return!1};var _n=Symbol("observer should be removed"),N=[],nn=[],xn=!1,hn,bn;class Gn{description;test;callback;constructor(n,e){let o=typeof e==="string"?`"${e}"`:`function ${e.name}`,i;if(typeof n==="string")this.test=(t)=>typeof t==="string"&&t!==""&&(n.startsWith(t)||t.startsWith(n)),i=`test = "${n}"`;else if(n instanceof RegExp)this.test=n.test.bind(n),i=`test = "${n.toString()}"`;else if(n instanceof Function)this.test=n,i=`test = function ${n.name}`;else throw Error("expect listener test to be a string, RegExp, or test function");if(this.description=`${i}, ${o}`,typeof e==="function")this.callback=e;else throw Error("expect callback to be a path or function");N.push(this)}}var Zn=async()=>{if(hn===void 0)return;await hn},ge=()=>{if(H.perf)console.time("xin async update");let n=Array.from(nn);for(let e of n)N.filter((o)=>{let i;try{i=o.test(e)}catch(t){throw Error(`Listener ${o.description} threw "${t}" at "${e}"`)}if(i===_n)return G(o),!1;return i}).forEach((o)=>{let i;try{i=o.callback(e)}catch(t){console.error(`Listener ${o.description} threw "${t}" handling "${e}"`)}if(i===_n)G(o)});if(nn.splice(0),xn=!1,typeof bn==="function")bn();if(H.perf)console.timeEnd("xin async update")},W=(n)=>{let e=typeof n==="string"?n:M(n);if(e===void 0)throw console.error("touch was called on an invalid target",n),Error("touch was called on an invalid target");if(xn===!1)hn=new Promise((o)=>{bn=o}),xn=setTimeout(ge);if(nn.find((o)=>e.startsWith(o))==null)nn.push(e)},wn=(n,e)=>{return new Gn(n,e)},G=(n)=>{let e=N.indexOf(n);if(e>-1)N.splice(e,1);else throw Error("unobserve failed, listener not found")};var Te=(n)=>{try{return JSON.stringify(n)}catch(e){return"{has circular references}"}},gn=(...n)=>Error(n.map(Te).join(" "));var Xe=()=>new Date(parseInt("1000000000",36)+Date.now()).valueOf().toString(36).slice(1),Se=0,Ee=()=>(parseInt("10000",36)+ ++Se).toString(36).slice(-5),ke=()=>Xe()+Ee(),Xn=Symbol("delete"),Kn=Symbol("new-object"),Tn=Symbol("automatic-index");function Rn(n){if(n==="")return[];if(Array.isArray(n))return n;else{let e=[];while(n.length>0){let o=n.search(/\[[^\]]+\]/);if(o===-1){e.push(n.split("."));break}else{let i=n.slice(0,o);if(n=n.slice(o),i!=="")e.push(i.split("."));if(o=n.indexOf("]")+1,e.push(n.slice(1,o-1)),n.slice(o,o+1)===".")o+=1;n=n.slice(o)}}return e}}var D=new WeakMap;function Nn(n,e){if(D.get(n)===void 0)D.set(n,{});if(D.get(n)[e]===void 0)D.get(n)[e]={};let o=D.get(n)[e];if(e==="_auto_")n.forEach((i,t)=>{if(i[Tn]===void 0)i[Tn]=ke();o[i[Tn]+""]=t});else n.forEach((i,t)=>{o[I(i,e)+""]=t});return o}function Ce(n,e){if(D.get(n)===void 0||D.get(n)[e]===void 0)return Nn(n,e);else return D.get(n)[e]}function ve(n,e,o){o=o+"";let i=Ce(n,e)[o];if(i===void 0||I(n[i],e)+""!==o)i=Nn(n,e)[o];return i}function Me(n,e,o){if(n[e]===void 0&&o!==void 0)n[e]=o;return n[e]}function ne(n,e,o,i){let t=e!==""?ve(n,e,o):o;if(i===Xn)return n.splice(t,1),D.delete(n),Symbol("deleted");else if(i===Kn){if(e===""&&n[t]===void 0)n[t]={}}else if(i!==void 0)if(t!==void 0)n[t]=i;else if(e!==""&&I(i,e)+""===o+"")n.push(i),t=n.length-1;else throw Error(`byIdPath insert failed at [${e}=${o}]`);return n[t]}function qn(n){if(!Array.isArray(n))throw gn("setByPath failed: expected array, found",n)}function Qn(n){if(n==null||!(n instanceof Object))throw gn("setByPath failed: expected Object, found",n)}function I(n,e){let o=Rn(e),i=n,t,s,r,c;for(t=0,s=o.length;i!==void 0&&t<s;t++){let d=o[t];if(Array.isArray(d))for(r=0,c=d.length;i!==void 0&&r<c;r++){let l=d[r];i=i[l]}else if(i.length===0){if(i=i[Number(d.slice(1))],d[0]!=="=")return}else if(d.includes("=")){let[l,...p]=d.split("=");i=ne(i,l,p.join("="))}else r=parseInt(d,10),i=i[r]}return i}function ee(n,e,o){let i=n;if(e==="")throw Error("setByPath cannot be used to set the root object");let t=Rn(e);while(i!=null&&t.length>0){let s=t.shift();if(typeof s==="string"){let r=s.indexOf("=");if(r>-1){if(r===0)Qn(i);else qn(i);let c=s.slice(0,r),d=s.slice(r+1);if(i=ne(i,c,d,t.length>0?Kn:o),t.length===0)return!0}else{qn(i);let c=parseInt(s,10);if(t.length>0)i=i[c];else{if(o!==Xn){if(i[c]===o)return!1;i[c]=o}else i.splice(c,1);return!0}}}else if(Array.isArray(s)&&s.length>0){Qn(i);while(s.length>0){let r=s.shift();if(s.length>0||t.length>0)i=Me(i,r,s.length>0?{}:[]);else{if(o!==Xn){if(i[r]===o)return!1;i[r]=o}else{if(!Object.prototype.hasOwnProperty.call(i,r))return!1;delete i[r]}return!0}}}else throw Error(`setByPath failed, bad path ${e}`)}throw Error(`setByPath(${n}, ${e}, ${o}) failed`)}var De=["sort","splice","copyWithin","fill","pop","push","reverse","shift","unshift"],En={},Fe=!0,Le=/^\.?([^.[\](),])+(\.[^.[\](),]+|\[\d+\]|\[[^=[\](),]*=[^[\]()]+\])*$/,Be=(n)=>Le.test(n),A=(n="",e="")=>{if(n==="")return e;else if(e.match(/^\d+$/)!==null||e.includes("="))return`${n}[${e}]`;else return`${n}.${e}`},He={string(n){return new String(n)},boolean(n){return new Boolean(n)},bigint(n){return n},symbol(n){return n},number(n){return new Number(n)}};function Sn(n,e){let o=typeof n;if(n===void 0||o==="object"||o==="function")return n;else return new Proxy(He[typeof n](n),Y(e,!0))}var Y=(n,e)=>({get(o,i){switch(i){case b:return n;case O:return o.valueOf?o.valueOf():o;case Yn:return(r)=>f[n]=r;case Jn:return(r)=>{let c=wn(n,r);return()=>G(c)};case Un:return(r,c)=>P(r,c,w(o));case Vn:return(r,c,d)=>{g(r,n,c,d)}}if(typeof i==="symbol")return o[i];let t=i,s=t.match(/^([^.[]+)\.(.+)$/)??t.match(/^([^\]]+)(\[.+)/)??t.match(/^(\[[^\]]+\])\.(.+)$/)??t.match(/^(\[[^\]]+\])\[(.+)$/);if(s!==null){let[,r,c]=s,d=A(n,r),l=I(o,r);return l!==null&&typeof l==="object"?new Proxy(l,Y(d,e))[c]:l}if(t.startsWith("[")&&t.endsWith("]"))t=t.substring(1,t.length-1);if(!Array.isArray(o)&&o[t]!==void 0||Array.isArray(o)&&t.includes("=")){let r;if(t.includes("=")){let[c,d]=t.split("=");r=o.find((l)=>`${I(l,c)}`===d)}else r=o[t];if(r instanceof Object){let c=A(n,t);return new Proxy(r instanceof Function?r.bind(o):r,Y(c,e))}else return e?Sn(r,A(n,t)):r}else if(Array.isArray(o)){let r=o[t];return typeof r==="function"?(...c)=>{let d=r.apply(o,c);if(De.includes(t))W(n);return d}:typeof r==="object"?new Proxy(r,Y(A(n,t),e)):e?Sn(r,A(n,t)):r}else return e?Sn(o[t],A(n,t)):o[t]},set(o,i,t){t=w(t);let s=i!==O?A(n,i):n;if(Fe&&!Be(s))throw Error(`setting invalid path ${s}`);if(w(f[s])!==t&&ee(En,s,t))W(s);return!0}}),Z=(n,e)=>{let o=typeof e==="function"?e:f[e];if(typeof o!=="function")throw Error(`observe expects a function or path to a function, ${e} is neither`);return wn(n,o)},f=new Proxy(En,Y("",!1)),J=new Proxy(En,Y("",!0));var kn=(n,e)=>{let o=new Event(e);n.dispatchEvent(o)},ie=(n)=>{if(n instanceof HTMLInputElement)return n.type;else if(n instanceof HTMLSelectElement&&n.hasAttribute("multiple"))return"multi-select";else return"other"},te=(n,e)=>{switch(ie(n)){case"radio":n.checked=n.value===e;break;case"checkbox":n.checked=!!e;break;case"date":n.valueAsDate=new Date(e);break;case"multi-select":for(let o of Array.from(n.querySelectorAll("option")))o.selected=e[o.value];break;default:n.value=e}},re=(n)=>{switch(ie(n)){case"radio":{let e=n.parentElement?.querySelector(`[name="${n.name}"]:checked`);return e!=null?e.value:null}case"checkbox":return n.checked;case"date":return n.valueAsDate?.toISOString();case"multi-select":return Array.from(n.querySelectorAll("option")).reduce((e,o)=>{return e[o.value]=o.selected,e},{});default:return n.value}},{ResizeObserver:oe}=globalThis,q=oe!=null?new oe((n)=>{for(let e of n){let o=e.target;kn(o,"resize")}}):{observe(){},unobserve(){}},Cn=(n,e,o=!0)=>{if(n!=null&&e!=null)if(typeof e==="string")n.textContent=e;else if(Array.isArray(e))e.forEach((i)=>{n.append(i instanceof Node&&o?z(i):i)});else if(e instanceof Node)n.append(o?z(e):e);else throw Error("expect text content or document node")};var vn=(n,e=250)=>{let o;return(...i)=>{if(o!==void 0)clearTimeout(o);o=setTimeout(()=>{n(...i)},e)}},en=(n,e=250)=>{let o,i=Date.now()-e,t=!1;return(...s)=>{if(clearTimeout(o),o=setTimeout(()=>{n(...s),i=Date.now()},e),!t&&Date.now()-i>=e){t=!0;try{n(...s),i=Date.now()}finally{t=!1}}}};var on=Symbol("list-binding"),$e=16,Oe=100;function se(n,e){let o=Array.from(n.querySelectorAll(L));if(n.matches(L))o.unshift(n);for(let i of o){let t=v.get(i);for(let s of t){if(s.path.startsWith("^"))s.path=`${e}${s.path.substring(1)}`;if(s.binding.toDOM!=null)s.binding.toDOM(i,f[s.path])}}}class ce{boundElement;listTop;listBottom;template;options;itemToElement;_array=[];_update;_previousSlice;static filterBoundObservers=new WeakMap;constructor(n,e,o={}){if(this.boundElement=n,this.itemToElement=new WeakMap,n.children.length!==1)throw Error("ListBinding expects an element with exactly one child element");if(n.children[0]instanceof HTMLTemplateElement){let i=n.children[0];if(i.content.children.length!==1)throw Error("ListBinding expects a template with exactly one child element");this.template=z(i.content.children[0])}else this.template=n.children[0],this.template.remove();if(this.options=o,this.listTop=document.createElement("div"),this.listBottom=document.createElement("div"),this.listTop.classList.add("virtual-list-padding"),this.listBottom.classList.add("virtual-list-padding"),this.boundElement.append(this.listTop),this.boundElement.append(this.listBottom),o.virtual!=null)q.observe(this.boundElement),this._update=en(()=>{this.update(this._array,!0)},$e),this.boundElement.addEventListener("scroll",this._update),this.boundElement.addEventListener("resize",this._update)}visibleSlice(){let{virtual:n,hiddenProp:e,visibleProp:o}=this.options,i=this._array;if(e!==void 0)i=i.filter((d)=>d[e]!==!0);if(o!==void 0)i=i.filter((d)=>d[o]===!0);if(this.options.filter&&this.needle!==void 0)i=this.options.filter(i,this.needle);let t=0,s=i.length-1,r=0,c=0;if(n!=null&&this.boundElement instanceof HTMLElement){let d=this.boundElement.offsetWidth,l=this.boundElement.offsetHeight;if(n.visibleColumns==null)n.visibleColumns=n.width!=null?Math.max(1,Math.floor(d/n.width)):1;let p=Math.ceil(l/n.height)+(n.rowChunkSize||1),S=Math.ceil(i.length/n.visibleColumns),E=n.visibleColumns*p,y=Math.floor(this.boundElement.scrollTop/n.height);if(y>S-p+1)y=Math.max(0,S-p+1);if(n.rowChunkSize)y-=y%n.rowChunkSize;t=y*n.visibleColumns,s=t+E-1,r=y*n.height,c=Math.max((S-p)*n.height-r,0)}return{items:i,firstItem:t,lastItem:s,topBuffer:r,bottomBuffer:c}}needle;filter=en((n)=>{if(this.needle!==n)this.needle=n,this.update(this._array)},Oe);update(n,e){if(n==null)n=[];this._array=n;let{hiddenProp:o,visibleProp:i}=this.options,t=M(n),s=this.visibleSlice();this.boundElement.classList.toggle("-xin-empty-list",s.items.length===0);let r=this._previousSlice,{firstItem:c,lastItem:d,topBuffer:l,bottomBuffer:p}=s;if(o===void 0&&i===void 0&&e===!0&&r!=null&&c===r.firstItem&&d===r.lastItem)return;this._previousSlice=s;let S=0,E=0,y=0;for(let u of Array.from(this.boundElement.children)){if(u===this.listTop||u===this.listBottom)continue;let k=_.get(u);if(k==null)u.remove();else{let h=s.items.indexOf(k);if(h<c||h>d)u.remove(),this.itemToElement.delete(k),_.delete(u),S++}}this.listTop.style.height=String(l)+"px",this.listBottom.style.height=String(p)+"px";let x=[],{idPath:ln}=this.options;for(let u=c;u<=d;u++){let k=s.items[u];if(k===void 0)continue;let h=this.itemToElement.get(w(k));if(h==null){if(y++,h=z(this.template),typeof k==="object")this.itemToElement.set(w(k),h),_.set(h,w(k));if(this.boundElement.insertBefore(h,this.listBottom),ln!=null){let fn=k[ln],we=`${t}[${ln}=${fn}]`;se(h,we)}else{let fn=`${t}[${u}]`;se(h,fn)}}x.push(h)}let R=null;for(let u of x){if(u.previousElementSibling!==R)if(E++,R?.nextElementSibling!=null)this.boundElement.insertBefore(u,R.nextElementSibling);else this.boundElement.insertBefore(u,this.listBottom);R=u}if(H.perf)console.log(t,"updated",{removed:S,created:y,moved:E})}}var de=(n,e,o)=>{let i=n[on];if(i===void 0)i=new ce(n,e,o),n[on]=i;return i};var{document:Q,MutationObserver:ae}=globalThis,Mn=(n,e)=>{let o=v.get(n);if(o==null)return;for(let i of o){let{binding:t,options:s}=i,{path:r}=i,{toDOM:c}=t;if(c!=null){if(r.startsWith("^")){let d=mn(n);if(d!=null&&d[b]!=null)r=i.path=`${d[b]}${r.substring(1)}`;else throw console.error(`Cannot resolve relative binding ${r}`,n,"is not part of a list"),Error(`Cannot resolve relative binding ${r}`)}if(e==null||r.startsWith(e))c(n,f[r],s)}}};if(ae!=null)new ae((e)=>{e.forEach((o)=>{Array.from(o.addedNodes).forEach((i)=>{if(i instanceof Element)Array.from(i.querySelectorAll(L)).forEach((t)=>Mn(t))})})}).observe(Q.body,{subtree:!0,childList:!0});Z(()=>!0,(n)=>{let e=Array.from(Q.querySelectorAll(L));for(let o of e)Mn(o,n)});var le=(n)=>{let e=n.target.closest(L);while(e!=null){let o=v.get(e);for(let i of o){let{binding:t,path:s}=i,{fromDOM:r}=t;if(r!=null){let c;try{c=r(e,i.options)}catch(d){throw console.error("Cannot get value from",e,"via",i),Error("Cannot obtain value fromDOM")}if(c!=null){let d=f[s];if(d==null)f[s]=c;else{let l=d[b]!=null?d[O]:d,p=c[b]!=null?c[O]:c;if(l!==p)f[s]=p}}}}e=e.parentElement.closest(L)}};if(globalThis.document!=null)Q.body.addEventListener("change",le,!0),Q.body.addEventListener("input",le,!0);function g(n,e,o,i){if(n instanceof DocumentFragment)throw Error("bind cannot bind to a DocumentFragment");let t;if(typeof e==="object"&&e[b]===void 0&&i===void 0){let{value:c}=e;t=typeof c==="string"?c:c[b],i=e,delete i.value}else t=typeof e==="string"?e:e[b];if(t==null)throw Error("bind requires a path or object with xin Proxy");let{toDOM:s}=o;n.classList?.add(un);let r=v.get(n);if(r==null)r=[],v.set(n,r);if(r.push({path:t,binding:o,options:i}),s!=null&&!t.startsWith("^"))W(t);if(i?.filter&&i?.needle)g(n,i.needle,{toDOM(c,d){console.log({needle:d}),c[on]?.filter(d)}});return n}var fe=new Set,ze=(n)=>{let e=n?.target.closest(yn),o=!1,i=new Proxy(n,{get(s,r){if(r==="stopPropagation")return()=>{n.stopPropagation(),o=!0};else{let c=s[r];return typeof c==="function"?c.bind(s):c}}}),t=new Set;while(!o&&e!=null){let r=$.get(e)[n.type]||t;for(let c of r){if(typeof c==="function")c(i);else{let d=f[c];if(typeof d==="function")d(i);else throw Error(`no event handler found at path ${c}`)}if(o)continue}e=e.parentElement!=null?e.parentElement.closest(yn):null}};function P(n,e,o){let i=$.get(n);if(n.classList.add(pn),i==null)i={},$.set(n,i);if(!i[e])i[e]=new Set;if(i[e].add(o),!fe.has(e))fe.add(e),Q.body.addEventListener(e,ze,!0);return()=>{i[e].delete(o)}}var tn={value:{toDOM:te,fromDOM(n){return re(n)}},text:{toDOM(n,e){n.textContent=e}},enabled:{toDOM(n,e){n.disabled=!e}},disabled:{toDOM(n,e){n.disabled=Boolean(e)}},list:{toDOM(n,e,o){de(n,e,o).update(e)}}};var Ae=180/Math.PI,Pe=Math.PI/180;function T(n,e,o){return o<n?NaN:e<n?n:e>o?o:e}function F(n,e,o,i=!0){if(i)o=T(0,o,1);return o*(e-n)+n}var je={RADIANS_TO_DEGREES:Ae,DEGREES_TO_RADIANS:Pe,clamp:T,lerp:F};function Dn(n,e=document.body){let o=getComputedStyle(e);if(n.endsWith(")")&&n.startsWith("var("))n=n.slice(4,-1);return o.getPropertyValue(n).trim()}var We=(n,e,o)=>{return(0.299*n+0.587*e+0.114*o)/255},j=(n)=>("00"+Math.round(Number(n)).toString(16)).slice(-2);class ue{h;s;l;constructor(n,e,o){n/=255,e/=255,o/=255;let i=Math.max(n,e,o),t=i-Math.min(n,e,o),s=t!==0?i===n?(e-o)/t:i===e?2+(o-n)/t:4+(n-e)/t:0;this.h=60*s<0?60*s+360:60*s,this.s=t!==0?i<=0.5?t/(2*i-t):t/(2-(2*i-t)):0,this.l=(2*i-t)/2}}var V=globalThis.document!==void 0?globalThis.document.createElement("span"):void 0;class a{r;g;b;a;static fromVar(n,e=document.body){return a.fromCss(Dn(n,e))}static fromCss(n){let e=n;if(V instanceof HTMLSpanElement)V.style.color="black",V.style.color=n,document.body.appendChild(V),e=getComputedStyle(V).color,V.remove();let[o,i,t,s]=e.match(/[\d.]+/g)||["0","0","0","0"],r=e.startsWith("color(srgb")?255:1;return new a(Number(o)*r,Number(i)*r,Number(t)*r,s==null?1:Number(s))}static fromHsl(n,e,o,i=1){let t,s,r;if(e===0)t=s=r=o;else{let d=(E,y,x)=>{if(x<0)x+=1;if(x>1)x-=1;if(x<0.16666666666666666)return E+(y-E)*6*x;if(x<0.5)return y;if(x<0.6666666666666666)return E+(y-E)*(0.6666666666666666-x)*6;return E},l=o<0.5?o*(1+e):o+e-o*e,p=2*o-l,S=(n%360+360)%360/360;t=d(p,l,S+0.3333333333333333),s=d(p,l,S),r=d(p,l,S-0.3333333333333333)}let c=new a(t*255,s*255,r*255,i);return c.hslCached={h:(n%360+360)%360,s:e,l:o},c}static black=new a(0,0,0);static white=new a(255,255,255);constructor(n,e,o,i=1){this.r=T(0,n,255),this.g=T(0,e,255),this.b=T(0,o,255),this.a=T(0,i,1)}get inverse(){return new a(255-this.r,255-this.g,255-this.b,this.a)}get inverseLuminance(){let{h:n,s:e,l:o}=this._hsl;return a.fromHsl(n,e,1-o,this.a)}get opaque(){return this.a===1?this:new a(this.r,this.g,this.b,1)}contrasting(n=1){return this.opaque.blend(this.brightness>0.5?a.black:a.white,n)}get rgb(){let{r:n,g:e,b:o}=this;return`rgb(${n.toFixed(0)},${e.toFixed(0)},${o.toFixed(0)})`}get rgba(){let{r:n,g:e,b:o,a:i}=this;return`rgba(${n.toFixed(0)},${e.toFixed(0)},${o.toFixed(0)},${i.toFixed(2)})`}get RGBA(){return[this.r/255,this.g/255,this.b/255,this.a]}get ARGB(){return[this.a,this.r/255,this.g/255,this.b/255]}hslCached;get _hsl(){if(this.hslCached==null)this.hslCached=new ue(this.r,this.g,this.b);return this.hslCached}get hsl(){let{h:n,s:e,l:o}=this._hsl;return`hsl(${n.toFixed(0)}deg ${(e*100).toFixed(0)}% ${(o*100).toFixed(0)}%)`}get hsla(){let{h:n,s:e,l:o}=this._hsl;return`hsl(${n.toFixed(0)}deg ${(e*100).toFixed(0)}% ${(o*100).toFixed(0)}% / ${(this.a*100).toFixed(0)}%)`}get mono(){let n=this.brightness*255;return new a(n,n,n)}get brightness(){return We(this.r,this.g,this.b)}get html(){return this.toString()}toString(){return this.a===1?"#"+j(this.r)+j(this.g)+j(this.b):"#"+j(this.r)+j(this.g)+j(this.b)+j(Math.floor(255*this.a))}brighten(n){let{h:e,s:o,l:i}=this._hsl,t=T(0,i+n*(1-i),1);return a.fromHsl(e,o,t,this.a)}darken(n){let{h:e,s:o,l:i}=this._hsl,t=T(0,i*(1-n),1);return a.fromHsl(e,o,t,this.a)}saturate(n){let{h:e,s:o,l:i}=this._hsl,t=T(0,o+n*(1-o),1);return a.fromHsl(e,t,i,this.a)}desaturate(n){let{h:e,s:o,l:i}=this._hsl,t=T(0,o*(1-n),1);return a.fromHsl(e,t,i,this.a)}rotate(n){let{h:e,s:o,l:i}=this._hsl,t=(e+360+n)%360;return a.fromHsl(t,o,i,this.a)}opacity(n){let{h:e,s:o,l:i}=this._hsl;return a.fromHsl(e,o,i,n)}swatch(){return console.log(`%c %c ${this.html}, ${this.rgba}`,`background-color: ${this.html}`,"background-color: transparent"),this}blend(n,e){return new a(F(this.r,n.r,e),F(this.g,n.g,e),F(this.b,n.b,e),F(this.a,n.a,e))}static blendHue(n,e,o){let i=(e-n+720)%360;if(i<180)return n+o*i;else return n-(360-i)*o}mix(n,e){let o=this._hsl,i=n._hsl;return a.fromHsl(o.s===0?i.h:i.s===0?o.h:a.blendHue(o.h,i.h,e),F(o.s,i.s,e),F(o.l,i.l,e),F(this.a,n.a,e))}colorMix(n,e){return a.fromCss(`color-mix(in hsl, ${this.html}, ${n.html} ${(e*100).toFixed(0)}%)`)}}function X(n){return n.replace(/[A-Z]/g,(e)=>{return`-${e.toLocaleLowerCase()}`})}function pe(n){return n.replace(/-([a-z])/g,(e,o)=>{return o.toLocaleUpperCase()})}var Ie="http://www.w3.org/1998/Math/MathML",Ye="http://www.w3.org/2000/svg",rn={},ye=(n,e,o)=>{let i=$n(X(e),o);if(i.prop.startsWith("--"))n.style.setProperty(i.prop,i.value);else n.style[e]=i.value},Je=(n)=>{return{toDOM(e,o){ye(e,n,o)}}},me=(n,e,o)=>{if(e==="style")if(typeof o==="object")for(let i of Object.keys(o))if(M(o[i]))g(n,o[i],Je(i));else ye(n,i,o[i]);else n.setAttribute("style",o);else if(n[e]!==void 0){let{MathMLElement:i}=globalThis;if(n instanceof SVGElement||i!==void 0&&n instanceof i)n.setAttribute(e,o);else n[e]=o}else{let i=X(e);if(i==="class")o.split(" ").forEach((t)=>{n.classList.add(t)});else if(n[i]!==void 0)n[i]=o;else if(typeof o==="boolean")o?n.setAttribute(i,""):n.removeAttribute(i);else n.setAttribute(i,o)}},Ve=(n)=>{return{toDOM(e,o){me(e,n,o)}}},Ue=(n,e,o)=>{if(e==="apply")o(n);else if(e.match(/^on[A-Z]/)!=null){let i=e.substring(2).toLowerCase();P(n,i,o)}else if(e==="bind")if((typeof o.binding==="string"?tn[o.binding]:o.binding)!==void 0&&o.value!==void 0)g(n,o.value,o.binding instanceof Function?{toDOM:o.binding}:o.binding);else throw Error("bad binding");else if(e.match(/^bind[A-Z]/)!=null){let i=e.substring(4,5).toLowerCase()+e.substring(5),t=tn[i];if(t!==void 0)g(n,o,t);else throw Error(`${e} is not allowed, bindings.${i} is not defined`)}else if(M(o))g(n,o,Ve(e));else me(n,e,o)},Fn=(n,...e)=>{if(rn[n]===void 0){let[t,s]=n.split("|");if(s===void 0)rn[n]=globalThis.document.createElement(t);else rn[n]=globalThis.document.createElementNS(s,t)}let o=rn[n].cloneNode(),i={};for(let t of e)if(t instanceof Element||t instanceof DocumentFragment||typeof t==="string"||typeof t==="number")if(o instanceof HTMLTemplateElement)o.content.append(t);else o.append(t);else if(M(t))o.append(m.span({bindText:t}));else Object.assign(i,t);for(let t of Object.keys(i)){let s=i[t];Ue(o,t,s)}return o},Ln=(...n)=>{let e=globalThis.document.createDocumentFragment();for(let o of n)e.append(o);return e},m=new Proxy({fragment:Ln},{get(n,e){if(e=e.replace(/[A-Z]/g,(o)=>`-${o.toLocaleLowerCase()}`),n[e]===void 0)n[e]=(...o)=>Fn(e,...o);return n[e]},set(){throw Error("You may not add new properties to elements")}}),Bn=new Proxy({fragment:Ln},{get(n,e){if(n[e]===void 0)n[e]=(...o)=>Fn(`${e}|${Ye}`,...o);return n[e]},set(){throw Error("You may not add new properties to elements")}}),Hn=new Proxy({fragment:Ln},{get(n,e){if(n[e]===void 0)n[e]=(...o)=>Fn(`${e}|${Ie}`,...o);return n[e]},set(){throw Error("You may not add new properties to elements")}});function _e(n,e){let o=m.style(U(e));o.id=n,document.head.append(o)}var Ge=["animation-iteration-count","flex","flex-base","flex-grow","flex-shrink","opacity","order","tab-size","widows","z-index","zoom"],$n=(n,e)=>{if(typeof e==="number"&&!Ge.includes(n))e=`${e}px`;if(n.startsWith("_"))if(n.startsWith("__"))n="--"+n.substring(2),e=`var(${n}-default, ${e})`;else n="--"+n.substring(1);return{prop:n,value:String(e)}},Ze=(n,e,o)=>{if(o===void 0)return"";if(o instanceof a)o=o.html;let i=$n(e,o);return`${n} ${i.prop}: ${i.value};`},xe=(n,e,o="")=>{let i=X(n);if(typeof e==="object"&&!(e instanceof a)){let t=Object.keys(e).map((s)=>xe(s,e[s],`${o} `)).join(`
2
- `);return`${o} ${n} {
3
- ${t}
4
- ${o} }`}else return Ze(o,i,e)},U=(n,e="")=>{return Object.keys(n).map((i)=>{let t=n[i];if(typeof t==="string"){if(i==="@import")return`@import url('${t}');`;throw Error("top-level string value only allowed for `@import`")}let s=Object.keys(t).map((r)=>xe(r,t[r])).join(`
5
- `);return`${e}${i} {
1
+ var P={debug:!1,perf:!1};function S(e){if(e==null||typeof e!=="object")return e;if(e instanceof Set)return new Set(e);else if(Array.isArray(e))return e.map(S);let n={};for(let o in e){let t=e[o];if(e!=null&&typeof e==="object")n[o]=S(t);else n[o]=t}return n}var ue="-xin-data",B=`.${ue}`,pe="-xin-event",ye=`.${pe}`,b="xinPath",$="xinValue",Je="xinObserve",Ge="xinBind",qe="xinOn",G=Symbol("list-binding"),N=Symbol("list-instance"),H=(e)=>{return e&&e[b]||void 0};function E(e){return typeof e==="object"&&e!==null?e[$]||e:e}var O=new WeakMap,L=new WeakMap;var z=(e)=>{let n=e.cloneNode();if(n instanceof Element){let o=L.get(e),t=O.get(e);if(o!=null)L.set(n,S(o));if(t!=null)O.set(n,S(t))}for(let o of Array.from(e instanceof HTMLTemplateElement?e.content.childNodes:e.childNodes))if(o instanceof Element||o instanceof DocumentFragment)n.appendChild(z(o));else n.appendChild(o.cloneNode());return n};var Qe=Symbol("observer should be removed"),ee=[],ne=[],xe=!1,he,be;class Ze{description;test;callback;constructor(e,n){let o=typeof n==="string"?`"${n}"`:`function ${n.name}`,t;if(typeof e==="string")this.test=(r)=>typeof r==="string"&&r!==""&&(e.startsWith(r)||r.startsWith(e)),t=`test = "${e}"`;else if(e instanceof RegExp)this.test=e.test.bind(e),t=`test = "${e.toString()}"`;else if(e instanceof Function)this.test=e,t=`test = function ${e.name}`;else throw Error("expect listener test to be a string, RegExp, or test function");if(this.description=`${t}, ${o}`,typeof n==="function")this.callback=n;else throw Error("expect callback to be a path or function");ee.push(this)}}var Ke=async()=>{if(he===void 0)return;await he},Cn=()=>{if(P.perf)console.time("xin async update");let e=Array.from(ne);for(let n of e)ee.filter((o)=>{let t;try{t=o.test(n)}catch(r){throw Error(`Listener ${o.description} threw "${r}" at "${n}"`)}if(t===Qe)return q(o),!1;return t}).forEach((o)=>{let t;try{t=o.callback(n)}catch(r){console.error(`Listener ${o.description} threw "${r}" handling "${n}"`)}if(t===Qe)q(o)});if(ne.splice(0),xe=!1,typeof be==="function")be();if(P.perf)console.timeEnd("xin async update")},Y=(e)=>{let n=typeof e==="string"?e:H(e);if(n===void 0)throw console.error("touch was called on an invalid target",e),Error("touch was called on an invalid target");if(xe===!1)he=new Promise((o)=>{be=o}),xe=setTimeout(Cn);if(ne.find((o)=>n.startsWith(o))==null)ne.push(n)},Ee=(e,n)=>{return new Ze(e,n)},q=(e)=>{let n=ee.indexOf(e);if(n>-1)ee.splice(n,1);else throw Error("unobserve failed, listener not found")};var Xn=(e)=>{try{return JSON.stringify(e)}catch(n){return"{has circular references}"}},Te=(...e)=>Error(e.map(Xn).join(" "));var Mn=()=>new Date(parseInt("1000000000",36)+Date.now()).valueOf().toString(36).slice(1),Sn=0,Ln=()=>(parseInt("10000",36)+ ++Sn).toString(36).slice(-5),Hn=()=>Mn()+Ln(),we=Symbol("delete"),Ne=Symbol("new-object"),ge=Symbol("automatic-index");function en(e){if(e==="")return[];if(Array.isArray(e))return e;else{let n=[];while(e.length>0){let o=e.search(/\[[^\]]+\]/);if(o===-1){n.push(e.split("."));break}else{let t=e.slice(0,o);if(e=e.slice(o),t!=="")n.push(t.split("."));if(o=e.indexOf("]")+1,n.push(e.slice(1,o-1)),e.slice(o,o+1)===".")o+=1;e=e.slice(o)}}return n}}var k=new WeakMap;function nn(e,n){if(k.get(e)===void 0)k.set(e,{});if(k.get(e)[n]===void 0)k.get(e)[n]={};let o=k.get(e)[n];if(n==="_auto_")e.forEach((t,r)=>{if(t[ge]===void 0)t[ge]=Hn();o[t[ge]+""]=r});else e.forEach((t,r)=>{o[V(t,n)+""]=r});return o}function kn(e,n){if(k.get(e)===void 0||k.get(e)[n]===void 0)return nn(e,n);else return k.get(e)[n]}function vn(e,n,o){o=o+"";let t=kn(e,n)[o];if(t===void 0||V(e[t],n)+""!==o)t=nn(e,n)[o];return t}function Bn(e,n,o){if(e[n]===void 0&&o!==void 0)e[n]=o;return e[n]}function on(e,n,o,t){let r=n!==""?vn(e,n,o):o;if(t===we)return e.splice(r,1),k.delete(e),Symbol("deleted");else if(t===Ne){if(n===""&&e[r]===void 0)e[r]={}}else if(t!==void 0)if(r!==void 0)e[r]=t;else if(n!==""&&V(t,n)+""===o+"")e.push(t),r=e.length-1;else throw Error(`byIdPath insert failed at [${n}=${o}]`);return e[r]}function Re(e){if(!Array.isArray(e))throw Te("setByPath failed: expected array, found",e)}function _e(e){if(e==null||!(e instanceof Object))throw Te("setByPath failed: expected Object, found",e)}function V(e,n){let o=en(n),t=e,r,s,i,c;for(r=0,s=o.length;t!==void 0&&r<s;r++){let l=o[r];if(Array.isArray(l))for(i=0,c=l.length;t!==void 0&&i<c;i++){let m=l[i];t=t[m]}else if(t.length===0){if(t=t[Number(l.slice(1))],l[0]!=="=")return}else if(l.includes("=")){let[m,...u]=l.split("=");t=on(t,m,u.join("="))}else i=parseInt(l,10),t=t[i]}return t}function tn(e,n,o){let t=e;if(n==="")throw Error("setByPath cannot be used to set the root object");let r=en(n);while(t!=null&&r.length>0){let s=r.shift();if(typeof s==="string"){let i=s.indexOf("=");if(i>-1){if(i===0)_e(t);else Re(t);let c=s.slice(0,i),l=s.slice(i+1);if(t=on(t,c,l,r.length>0?Ne:o),r.length===0)return!0}else{Re(t);let c=parseInt(s,10);if(r.length>0)t=t[c];else{if(o!==we){if(t[c]===o)return!1;t[c]=o}else t.splice(c,1);return!0}}}else if(Array.isArray(s)&&s.length>0){_e(t);while(s.length>0){let i=s.shift();if(s.length>0||r.length>0)t=Bn(t,i,s.length>0?{}:[]);else{if(o!==we){if(t[i]===o)return!1;t[i]=o}else{if(!Object.prototype.hasOwnProperty.call(t,i))return!1;delete t[i]}return!0}}}else throw Error(`setByPath failed, bad path ${n}`)}throw Error(`setByPath(${e}, ${n}, ${o}) failed`)}var Ce=(e,n)=>{let o=new Event(n);e.dispatchEvent(o)},sn=(e)=>{if(e instanceof HTMLInputElement)return e.type;else if(e instanceof HTMLSelectElement&&e.hasAttribute("multiple"))return"multi-select";else return"other"},cn=(e,n)=>{switch(sn(e)){case"radio":e.checked=e.value===n;break;case"checkbox":e.checked=!!n;break;case"date":e.valueAsDate=new Date(n);break;case"multi-select":for(let o of Array.from(e.querySelectorAll("option")))o.selected=n[o.value];break;default:e.value=n}},ln=(e)=>{switch(sn(e)){case"radio":{let n=e.parentElement?.querySelector(`[name="${e.name}"]:checked`);return n!=null?n.value:null}case"checkbox":return e.checked;case"date":return e.valueAsDate?.toISOString();case"multi-select":return Array.from(e.querySelectorAll("option")).reduce((n,o)=>{return n[o.value]=o.selected,n},{});default:return e.value}},{ResizeObserver:rn}=globalThis,Q=rn!=null?new rn((e)=>{for(let n of e){let o=n.target;Ce(o,"resize")}}):{observe(){},unobserve(){}},Xe=(e,n,o=!0)=>{if(e!=null&&n!=null)if(typeof n==="string")e.textContent=n;else if(Array.isArray(n))n.forEach((t)=>{e.append(t instanceof Node&&o?z(t):t)});else if(n instanceof Node)e.append(o?z(n):n);else throw Error("expect text content or document node")};var Me=(e,n=250)=>{let o;return(...t)=>{if(o!==void 0)clearTimeout(o);o=setTimeout(()=>{e(...t)},n)}},oe=(e,n=250)=>{let o,t=Date.now()-n,r=!1;return(...s)=>{if(clearTimeout(o),o=setTimeout(()=>{e(...s),t=Date.now()},n),!r&&Date.now()-t>=n){r=!0;try{e(...s),t=Date.now()}finally{r=!1}}}};var Dn=16,Fn=100;function an(e,n){let o=Array.from(e.querySelectorAll(B));if(e.matches(B))o.unshift(e);for(let t of o){let r=L.get(t);for(let s of r){if(s.path.startsWith("^"))s.path=`${n}${s.path.substring(1)}`;if(s.binding.toDOM!=null)s.binding.toDOM(t,d[s.path])}}}class mn{boundElement;listTop;listBottom;template;options;itemToElement;array=[];_update;_previousSlice;static filterBoundObservers=new WeakMap;constructor(e,n,o={}){if(this.boundElement=e,this.itemToElement=new WeakMap,e.children.length!==1)throw Error("ListBinding expects an element with exactly one child element");if(e.children[0]instanceof HTMLTemplateElement){let t=e.children[0];if(t.content.children.length!==1)throw Error("ListBinding expects a template with exactly one child element");this.template=z(t.content.children[0])}else this.template=e.children[0],this.template.remove();if(this.options=o,this.listTop=document.createElement("div"),this.listBottom=document.createElement("div"),this.listTop.classList.add("virtual-list-padding"),this.listBottom.classList.add("virtual-list-padding"),this.boundElement.append(this.listTop),this.boundElement.append(this.listBottom),o.virtual!=null)Q.observe(this.boundElement),this._update=oe(()=>{this.update(this.array,!0)},Dn),this.boundElement.addEventListener("scroll",this._update),this.boundElement.addEventListener("resize",this._update)}visibleSlice(){let{virtual:e,hiddenProp:n,visibleProp:o}=this.options,t=this.array;if(n!==void 0)t=t.filter((l)=>l[n]!==!0);if(o!==void 0)t=t.filter((l)=>l[o]===!0);if(this.options.filter&&this.needle!==void 0)t=this.options.filter(t,this.needle);let r=0,s=t.length-1,i=0,c=0;if(e!=null&&this.boundElement instanceof HTMLElement){let l=this.boundElement.offsetWidth,m=this.boundElement.offsetHeight;if(e.visibleColumns==null)e.visibleColumns=e.width!=null?Math.max(1,Math.floor(l/e.width)):1;let u=Math.ceil(m/e.height)+(e.rowChunkSize||1),C=Math.ceil(t.length/e.visibleColumns),X=e.visibleColumns*u,y=Math.floor(this.boundElement.scrollTop/e.height);if(y>C-u+1)y=Math.max(0,C-u+1);if(e.rowChunkSize)y-=y%e.rowChunkSize;r=y*e.visibleColumns,s=r+X-1,i=y*e.height,c=Math.max((C-u)*e.height-i,0)}return{items:t,firstItem:r,lastItem:s,topBuffer:i,bottomBuffer:c}}needle;filter=oe((e)=>{if(this.needle!==e)this.needle=e,this.update(this.array)},Fn);update(e,n){if(e==null)e=[];this.array=e;let{hiddenProp:o,visibleProp:t}=this.options,r=H(e),s=this.visibleSlice();this.boundElement.classList.toggle("-xin-empty-list",s.items.length===0);let i=this._previousSlice,{firstItem:c,lastItem:l,topBuffer:m,bottomBuffer:u}=s;if(o===void 0&&t===void 0&&n===!0&&i!=null&&c===i.firstItem&&l===i.lastItem)return;this._previousSlice=s;let C=0,X=0,y=0;for(let p of Array.from(this.boundElement.children)){if(p===this.listTop||p===this.listBottom)continue;let M=p[N];if(M==null)p.remove();else{let h=s.items.indexOf(M);if(h<c||h>l)p.remove(),this.itemToElement.delete(M),C++}}this.listTop.style.height=String(m)+"px",this.listBottom.style.height=String(u)+"px";let x=[],{idPath:de}=this.options;for(let p=c;p<=l;p++){let M=s.items[p];if(M===void 0)continue;let h=this.itemToElement.get(E(M));if(h==null){if(y++,h=z(this.template),typeof M==="object")this.itemToElement.set(E(M),h),h[N]=E(M);if(this.boundElement.insertBefore(h,this.listBottom),de!=null){let fe=M[de],wn=`${r}[${de}=${fe}]`;an(h,wn)}else{let fe=`${r}[${p}]`;an(h,fe)}}x.push(h)}let _=null;for(let p of x){if(p.previousElementSibling!==_)if(X++,_?.nextElementSibling!=null)this.boundElement.insertBefore(p,_.nextElementSibling);else this.boundElement.insertBefore(p,this.listBottom);_=p}if(P.perf)console.log(r,"updated",{removed:C,created:y,moved:X})}}var te=(e,n,o)=>{let t=e[G];if(n&&t===void 0)t=new mn(e,n,o),e[G]=t;return t},Se=(e)=>{let n;while(!(n=e[N])&&e&&e.parentElement)e=e.parentElement;return n?{element:e,item:n}:void 0},Le=(e)=>{let n=Se(e);return n?n.item:void 0},Pn=(e)=>{let n=Se(e);if(!n)return console.error("deleteListItem failed, element is not part of a list instance",e),!1;let o=te(n.element.parentElement);if(!o.options.idPath)return console.error("deleteListItem failed, list binding has no idPath",e.parentElement,o),!1;let t=o.array.indexOf(n.item);if(t>-1)return o.array.splice(t,1),!0;return!1};var re={value:{toDOM:cn,fromDOM(e){return ln(e)}},text:{toDOM(e,n){e.textContent=n}},enabled:{toDOM(e,n){e.disabled=!n}},disabled:{toDOM(e,n){e.disabled=Boolean(n)}},list:{toDOM(e,n,o){te(e,n,o).update(n)}}};function T(e){return e.replace(/[A-Z]/g,(n)=>{return`-${n.toLocaleLowerCase()}`})}function dn(e){return e.replace(/-([a-z])/g,(n,o)=>{return o.toLocaleUpperCase()})}var On=180/Math.PI,$n=Math.PI/180;function g(e,n,o){return o<e?NaN:n<e?e:n>o?o:n}function v(e,n,o,t=!0){if(t)o=g(0,o,1);return o*(n-e)+e}var zn={RADIANS_TO_DEGREES:On,DEGREES_TO_RADIANS:$n,clamp:g,lerp:v};function He(e,n=document.body){let o=getComputedStyle(n);if(e.endsWith(")")&&e.startsWith("var("))e=e.slice(4,-1);return o.getPropertyValue(e).trim()}var An=(e,n,o)=>{return(0.299*e+0.587*n+0.114*o)/255},A=(e)=>("00"+Math.round(Number(e)).toString(16)).slice(-2);class fn{h;s;l;constructor(e,n,o){e/=255,n/=255,o/=255;let t=Math.max(e,n,o),r=t-Math.min(e,n,o),s=r!==0?t===e?(n-o)/r:t===n?2+(o-e)/r:4+(e-n)/r:0;this.h=60*s<0?60*s+360:60*s,this.s=r!==0?t<=0.5?r/(2*t-r):r/(2-(2*t-r)):0,this.l=(2*t-r)/2}}var U=globalThis.document!==void 0?globalThis.document.createElement("span"):void 0;class a{r;g;b;a;static fromVar(e,n=document.body){return a.fromCss(He(e,n))}static fromCss(e){let n=e;if(U instanceof HTMLSpanElement)U.style.color="black",U.style.color=e,document.body.appendChild(U),n=getComputedStyle(U).color,U.remove();let[o,t,r,s]=n.match(/[\d.]+/g)||["0","0","0","0"],i=n.startsWith("color(srgb")?255:1;return new a(Number(o)*i,Number(t)*i,Number(r)*i,s==null?1:Number(s))}static fromHsl(e,n,o,t=1){let r,s,i;if(n===0)r=s=i=o;else{let l=(X,y,x)=>{if(x<0)x+=1;if(x>1)x-=1;if(x<0.16666666666666666)return X+(y-X)*6*x;if(x<0.5)return y;if(x<0.6666666666666666)return X+(y-X)*(0.6666666666666666-x)*6;return X},m=o<0.5?o*(1+n):o+n-o*n,u=2*o-m,C=(e%360+360)%360/360;r=l(u,m,C+0.3333333333333333),s=l(u,m,C),i=l(u,m,C-0.3333333333333333)}let c=new a(r*255,s*255,i*255,t);return c.hslCached={h:(e%360+360)%360,s:n,l:o},c}static black=new a(0,0,0);static white=new a(255,255,255);constructor(e,n,o,t=1){this.r=g(0,e,255),this.g=g(0,n,255),this.b=g(0,o,255),this.a=g(0,t,1)}get inverse(){return new a(255-this.r,255-this.g,255-this.b,this.a)}get inverseLuminance(){let{h:e,s:n,l:o}=this._hsl;return a.fromHsl(e,n,1-o,this.a)}get opaque(){return this.a===1?this:new a(this.r,this.g,this.b,1)}contrasting(e=1){return this.opaque.blend(this.brightness>0.5?a.black:a.white,e)}get rgb(){let{r:e,g:n,b:o}=this;return`rgb(${e.toFixed(0)},${n.toFixed(0)},${o.toFixed(0)})`}get rgba(){let{r:e,g:n,b:o,a:t}=this;return`rgba(${e.toFixed(0)},${n.toFixed(0)},${o.toFixed(0)},${t.toFixed(2)})`}get RGBA(){return[this.r/255,this.g/255,this.b/255,this.a]}get ARGB(){return[this.a,this.r/255,this.g/255,this.b/255]}hslCached;get _hsl(){if(this.hslCached==null)this.hslCached=new fn(this.r,this.g,this.b);return this.hslCached}get hsl(){let{h:e,s:n,l:o}=this._hsl;return`hsl(${e.toFixed(0)}deg ${(n*100).toFixed(0)}% ${(o*100).toFixed(0)}%)`}get hsla(){let{h:e,s:n,l:o}=this._hsl;return`hsl(${e.toFixed(0)}deg ${(n*100).toFixed(0)}% ${(o*100).toFixed(0)}% / ${(this.a*100).toFixed(0)}%)`}get mono(){let e=this.brightness*255;return new a(e,e,e)}get brightness(){return An(this.r,this.g,this.b)}get html(){return this.toString()}toString(){return this.a===1?"#"+A(this.r)+A(this.g)+A(this.b):"#"+A(this.r)+A(this.g)+A(this.b)+A(Math.floor(255*this.a))}brighten(e){let{h:n,s:o,l:t}=this._hsl,r=g(0,t+e*(1-t),1);return a.fromHsl(n,o,r,this.a)}darken(e){let{h:n,s:o,l:t}=this._hsl,r=g(0,t*(1-e),1);return a.fromHsl(n,o,r,this.a)}saturate(e){let{h:n,s:o,l:t}=this._hsl,r=g(0,o+e*(1-o),1);return a.fromHsl(n,r,t,this.a)}desaturate(e){let{h:n,s:o,l:t}=this._hsl,r=g(0,o*(1-e),1);return a.fromHsl(n,r,t,this.a)}rotate(e){let{h:n,s:o,l:t}=this._hsl,r=(n+360+e)%360;return a.fromHsl(r,o,t,this.a)}opacity(e){let{h:n,s:o,l:t}=this._hsl;return a.fromHsl(n,o,t,e)}swatch(){return console.log(`%c %c ${this.html}, ${this.rgba}`,`background-color: ${this.html}`,"background-color: transparent"),this}blend(e,n){return new a(v(this.r,e.r,n),v(this.g,e.g,n),v(this.b,e.b,n),v(this.a,e.a,n))}static blendHue(e,n,o){let t=(n-e+720)%360;if(t<180)return e+o*t;else return e-(360-t)*o}mix(e,n){let o=this._hsl,t=e._hsl;return a.fromHsl(o.s===0?t.h:t.s===0?o.h:a.blendHue(o.h,t.h,n),v(o.s,t.s,n),v(o.l,t.l,n),v(this.a,e.a,n))}colorMix(e,n){return a.fromCss(`color-mix(in hsl, ${this.html}, ${e.html} ${(n*100).toFixed(0)}%)`)}}function jn(e,n){let o=f.style(I(n));o.id=e,document.head.append(o)}var Wn=["animation-iteration-count","flex","flex-base","flex-grow","flex-shrink","opacity","order","tab-size","widows","z-index","zoom"],ke=(e,n)=>{if(typeof n==="number"&&!Wn.includes(e))n=`${n}px`;if(e.startsWith("_"))if(e.startsWith("__"))e="--"+e.substring(2),n=`var(${e}-default, ${n})`;else e="--"+e.substring(1);return{prop:e,value:String(n)}},Yn=(e,n,o)=>{if(o===void 0)return"";if(o instanceof a)o=o.html;let t=ke(n,o);return`${e} ${t.prop}: ${t.value};`},un=(e,n,o="")=>{let t=T(e);if(typeof n==="object"&&!(n instanceof a)){let r=Object.keys(n).map((s)=>un(s,n[s],`${o} `)).join(`
2
+ `);return`${o} ${e} {
3
+ ${r}
4
+ ${o} }`}else return Yn(o,t,n)},I=(e,n="")=>{return Object.keys(e).map((t)=>{let r=e[t];if(typeof r==="string"){if(t==="@import")return`@import url('${r}');`;throw Error("top-level string value only allowed for `@import`")}let s=Object.keys(r).map((i)=>un(i,r[i])).join(`
5
+ `);return`${n}${t} {
6
6
  ${s}
7
7
  }`}).join(`
8
8
 
9
- `)},qe=(n)=>{console.warn("initVars is deprecated. Just use _ and __ prefixes instead.");let e={};for(let o of Object.keys(n)){let i=n[o],t=X(o);e[`--${t}`]=typeof i==="number"&&i!==0?String(i)+"px":i}return e},Qe=(n)=>{let e={};for(let o of Object.keys(n)){let i=n[o];if(i instanceof a)e[o]=i.inverseLuminance;else if(typeof i==="string"&&i.match(/^(#[0-9a-fA-F]{3}|rgba?\(|hsla?\()/))e[o]=a.fromCss(i).inverseLuminance}return e},sn=new Proxy({},{get(n,e){if(n[e]===void 0){let o="--"+X(e);n[e]=(i)=>`var(${o}, ${i})`}return n[e]}}),On=new Proxy({},{get(n,e){if(e==="default")return sn;if(n[e]==null){e=X(e);let[,o,,i,t,s]=e.match(/^([-\w]*?)((_)?(\d+)(\w?))?$/)||["",e],r=`--${o}`;if(t!=null){let c=i==null?Number(t)/100:-Number(t)/100;switch(s){case"b":{let d=a.fromVar(r);n[e]=c>0?d.brighten(c).rgba:d.darken(-c).rgba}break;case"s":{let d=a.fromVar(r);n[e]=c>0?d.saturate(c).rgba:d.desaturate(-c).rgba}break;case"h":{let d=a.fromVar(r);n[e]=d.rotate(c*100).rgba}break;case"o":{let d=a.fromVar(r);n[e]=d.opacity(c).rgba}break;case"":n[e]=`calc(var(${r}) * ${c})`;break;default:throw console.error(s),Error(`Unrecognized method ${s} for css variable ${r}`)}}else n[e]=`var(${r})`}return n[e]}});var Ke=0;function zn(){return`custom-elt${(Ke++).toString(36)}`}var he=0,K={};function Re(n,e){let o=K[n],i=U(e).replace(/:host\b/g,n);K[n]=o?o+`
10
- `+i:i}function Ne(n){if(K[n])document.head.append(m.style({id:n+"-component"},K[n]));delete K[n]}class B extends HTMLElement{static elements=m;static _elementCreator;instanceId;styleNode;static styleSpec;static styleNode;content=m.slot();isSlotted;static _tagName=null;static get tagName(){return this._tagName}static StyleNode(n){return console.warn("StyleNode is deprecated, just assign static styleSpec: XinStyleSheet to the class directly"),m.style(U(n))}static elementCreator(n={}){let e=this;if(e._elementCreator==null){let{tag:o,styleSpec:i}=n,t=n!=null?o:null;if(t==null)if(typeof e.name==="string"&&e.name!==""){if(t=X(e.name),t.startsWith("-"))t=t.slice(1)}else t=zn();if(customElements.get(t)!=null)console.warn(`${t} is already defined`);if(t.match(/\w+(-\w+)+/)==null)console.warn(`${t} is not a legal tag for a custom-element`),t=zn();while(customElements.get(t)!==void 0)t=zn();if(e._tagName=t,i!==void 0)Re(t,i);window.customElements.define(t,this,n),e._elementCreator=m[t]}return e._elementCreator}initAttributes(...n){let e={},o={};new MutationObserver((t)=>{let s=!1;if(t.forEach((r)=>{s=!!(r.attributeName&&n.includes(pe(r.attributeName)))}),s&&this.queueRender!==void 0)this.queueRender(!1)}).observe(this,{attributes:!0}),n.forEach((t)=>{e[t]=C(this[t]);let s=X(t);Object.defineProperty(this,t,{enumerable:!1,get(){if(typeof e[t]==="boolean")return this.hasAttribute(s);else if(this.hasAttribute(s))return typeof e[t]==="number"?parseFloat(this.getAttribute(s)):this.getAttribute(s);else if(o[t]!==void 0)return o[t];else return e[t]},set(r){if(typeof e[t]==="boolean"){if(r!==this[t]){if(r)this.setAttribute(s,"");else this.removeAttribute(s);this.queueRender()}}else if(typeof e[t]==="number"){if(r!==parseFloat(this[t]))this.setAttribute(s,r),this.queueRender()}else if(typeof r==="object"||`${r}`!==`${this[t]}`){if(r===null||r===void 0||typeof r==="object")this.removeAttribute(s);else this.setAttribute(s,r);this.queueRender(),o[t]=r}}})})}initValue(){let n=Object.getOwnPropertyDescriptor(this,"value");if(n===void 0||n.get!==void 0||n.set!==void 0)return;let e=this.hasAttribute("value")?this.getAttribute("value"):C(this.value);delete this.value,Object.defineProperty(this,"value",{enumerable:!1,get(){return e},set(o){if(e!==o)e=o,this.queueRender(!0)}})}_parts;get parts(){let n=this.shadowRoot!=null?this.shadowRoot:this;if(this._parts==null)this._parts=new Proxy({},{get(e,o){if(e[o]===void 0){let i=n.querySelector(`[part="${o}"]`);if(i==null)i=n.querySelector(o);if(i==null)throw Error(`elementRef "${o}" does not exist!`);i.removeAttribute("data-ref"),e[o]=i}return e[o]}});return this._parts}constructor(){super();he+=1,this.initAttributes("hidden"),this.instanceId=`${this.tagName.toLocaleLowerCase()}-${he}`,this._value=C(this.defaultValue)}connectedCallback(){if(Ne(this.constructor.tagName),this.hydrate(),this.role!=null)this.setAttribute("role",this.role);if(this.onResize!==void 0){if(q.observe(this),this._onResize==null)this._onResize=this.onResize.bind(this);this.addEventListener("resize",this._onResize)}if(this.value!=null&&this.getAttribute("value")!=null)this._value=this.getAttribute("value");this.queueRender()}disconnectedCallback(){q.unobserve(this)}_changeQueued=!1;_renderQueued=!1;queueRender(n=!1){if(!this._hydrated)return;if(!this._changeQueued)this._changeQueued=n;if(!this._renderQueued)this._renderQueued=!0,requestAnimationFrame(()=>{if(this._changeQueued)kn(this,"change");this._changeQueued=!1,this._renderQueued=!1,this.render()})}_hydrated=!1;hydrate(){if(!this._hydrated){this.initValue();let n=typeof this.content!=="function",e=typeof this.content==="function"?this.content():this.content,{styleSpec:o}=this.constructor,{styleNode:i}=this.constructor;if(o)i=this.constructor.styleNode=m.style(U(o)),delete this.constructor.styleNode;if(this.styleNode)console.warn(this,"styleNode is deprecrated, use static styleNode or statc styleSpec instead"),i=this.styleNode;if(i){let t=this.attachShadow({mode:"open"});t.appendChild(i.cloneNode(!0)),Cn(t,e,n)}else if(e!==null){let t=Array.from(this.childNodes);Cn(this,e,n),this.isSlotted=this.querySelector("slot,xin-slot")!==void 0;let s=Array.from(this.querySelectorAll("slot"));if(s.length>0)s.forEach(An.replaceSlot);if(t.length>0){let r={"":this};Array.from(this.querySelectorAll("xin-slot")).forEach((c)=>{r[c.name]=c}),t.forEach((c)=>{let d=r[""],l=c instanceof Element?r[c.slot]:d;(l!==void 0?l:d).append(c)})}}this._hydrated=!0}}render(){}}class An extends B{name="";content=null;static replaceSlot(n){let e=document.createElement("xin-slot");if(n.name!=="")e.setAttribute("name",n.name);n.replaceWith(e)}constructor(){super();this.initAttributes("name")}}var fi=An.elementCreator({tag:"xin-slot"});var no=(n=()=>!0)=>{let e=localStorage.getItem("xin-state");if(e!=null){let i=JSON.parse(e);for(let t of Object.keys(i).filter(n))if(f[t]!==void 0)Object.assign(f[t],i[t]);else f[t]=i[t]}let o=vn(()=>{let i={},t=w(f);for(let s of Object.keys(t).filter(n))i[s]=t[s];localStorage.setItem("xin-state",JSON.stringify(i)),console.log("xin state saved to localStorage")},500);Z(n,o)};var Pn="1.0.8";function be(n){return Object.assign(J,n),J}function cn(n){return console.warn("boxedProxy is deprecated, please use tosi() instead"),be(n)}function jn(n,e=!1){if(e)return console.warn("xinProxy(..., true) is deprecated; use tosi(...) instead"),cn(n);return Object.keys(n).forEach((o)=>{f[o]=n[o]}),f}var eo={};async function dn(n,e){let{type:o,styleSpec:i}=await e(n,{Color:a,Component:B,elements:m,svgElements:Bn,mathML:Hn,varDefault:sn,vars:On,xin:f,boxed:J,xinProxy:jn,boxedProxy:cn,makeComponent:dn,bind:g,on:P,version:Pn}),t={type:o,creator:o.elementCreator({tag:n,styleSpec:i})};return eo[n]=t,t}var Wn={},oo=(n)=>import(n);class an extends B{tag="anon-elt";src="";property="default";loaded;blueprintLoaded=(n)=>{};async packaged(){let{tag:n,src:e,property:o}=this,i=`${n}.${o}:${e}`;if(!this.loaded){if(Wn[i]===void 0)Wn[i]=oo(e).then((t)=>{let s=t[o];return dn(n,s)});else console.log(`using cached ${n} with signature ${i}`);this.loaded=await Wn[i],this.blueprintLoaded(this.loaded)}return this.loaded}constructor(){super();this.initAttributes("tag","src","property")}}var io=an.elementCreator({tag:"xin-blueprint",styleSpec:{":host":{display:"none"}}});class In extends B{allLoaded=()=>{};constructor(){super()}async load(){let e=Array.from(this.querySelectorAll(an.tagName)).filter((o)=>o.src).map((o)=>o.packaged());await Promise.all(e),this.allLoaded()}connectedCallback(){super.connectedCallback(),this.load()}}var to=In.elementCreator({tag:"xin-loader",styleSpec:{":host":{display:"none"}}});export{w as xinValue,jn as xinProxy,M as xinPath,f as xin,Pn as version,On as vars,sn as varDefault,Zn as updates,G as unobserve,Mn as touchElement,W as touch,be as tosi,en as throttle,Bn as svgElements,H as settings,P as on,Z as observe,Hn as mathML,dn as makeComponent,Qe as invertLuminance,qe as initVars,no as hotReload,mn as getListItem,Dn as getCssVar,m as elements,vn as debounce,U as css,cn as boxedProxy,J as boxed,to as blueprintLoader,io as blueprint,tn as bindings,g as bind,_e as StyleSheet,je as MoreMath,B as Component,a as Color,In as BlueprintLoader,an as Blueprint};
9
+ `)},Vn=(e)=>{console.warn("initVars is deprecated. Just use _ and __ prefixes instead.");let n={};for(let o of Object.keys(e)){let t=e[o],r=T(o);n[`--${r}`]=typeof t==="number"&&t!==0?String(t)+"px":t}return n},Un=(e)=>{let n={};for(let o of Object.keys(e)){let t=e[o];if(t instanceof a)n[o]=t.inverseLuminance;else if(typeof t==="string"&&t.match(/^(#[0-9a-fA-F]{3}|rgba?\(|hsla?\()/))n[o]=a.fromCss(t).inverseLuminance}return n},ie=new Proxy({},{get(e,n){if(e[n]===void 0){let o="--"+T(n);e[n]=(t)=>`var(${o}, ${t})`}return e[n]}}),ve=new Proxy({},{get(e,n){if(n==="default")return ie;if(e[n]==null){n=T(n);let[,o,,t,r,s]=n.match(/^([-\w]*?)((_)?(\d+)(\w?))?$/)||["",n],i=`--${o}`;if(r!=null){let c=t==null?Number(r)/100:-Number(r)/100;switch(s){case"b":{let l=a.fromVar(i);e[n]=c>0?l.brighten(c).rgba:l.darken(-c).rgba}break;case"s":{let l=a.fromVar(i);e[n]=c>0?l.saturate(c).rgba:l.desaturate(-c).rgba}break;case"h":{let l=a.fromVar(i);e[n]=l.rotate(c*100).rgba}break;case"o":{let l=a.fromVar(i);e[n]=l.opacity(c).rgba}break;case"":e[n]=`calc(var(${i}) * ${c})`;break;default:throw console.error(s),Error(`Unrecognized method ${s} for css variable ${i}`)}}else e[n]=`var(${i})`}return e[n]}});var pn="http://www.w3.org/1998/Math/MathML",yn="http://www.w3.org/2000/svg";var se={},xn=(e,n,o)=>{let t=ke(T(n),o);if(t.prop.startsWith("--"))e.style.setProperty(t.prop,t.value);else e.style[n]=t.value},In=(e)=>{return{toDOM(n,o){xn(n,e,o)}}},hn=(e,n,o)=>{if(n==="style")if(typeof o==="object")for(let t of Object.keys(o))if(H(o[t]))w(e,o[t],In(t));else xn(e,t,o[t]);else e.setAttribute("style",o);else if(e[n]!==void 0){let{MathMLElement:t}=globalThis;if(e instanceof SVGElement||t!==void 0&&e instanceof t)e.setAttribute(n,o);else e[n]=o}else{let t=T(n);if(t==="class")o.split(" ").forEach((r)=>{e.classList.add(r)});else if(e[t]!==void 0)e[t]=o;else if(typeof o==="boolean")o?e.setAttribute(t,""):e.removeAttribute(t);else e.setAttribute(t,o)}},Jn=(e)=>{return{toDOM(n,o){hn(n,e,o)}}},Gn=(e,n,o)=>{if(n==="apply")o(e);else if(n.match(/^on[A-Z]/)!=null){let t=n.substring(2).toLowerCase();j(e,t,o)}else if(n==="bind")if((typeof o.binding==="string"?re[o.binding]:o.binding)!==void 0&&o.value!==void 0)w(e,o.value,o.binding instanceof Function?{toDOM:o.binding}:o.binding);else throw Error("bad binding");else if(n.match(/^bind[A-Z]/)!=null){let t=n.substring(4,5).toLowerCase()+n.substring(5),r=re[t];if(r!==void 0)w(e,o,r);else throw Error(`${n} is not allowed, bindings.${t} is not defined`)}else if(H(o))w(e,o,Jn(n));else hn(e,n,o)},Be=(e,...n)=>{if(se[e]===void 0){let[r,s]=e.split("|");if(s===void 0)se[e]=globalThis.document.createElement(r);else se[e]=globalThis.document.createElementNS(s,r)}let o=se[e].cloneNode(),t={};for(let r of n)if(r instanceof Element||r instanceof DocumentFragment||typeof r==="string"||typeof r==="number")if(o instanceof HTMLTemplateElement)o.content.append(r);else o.append(r);else if(H(r))o.append(f.span({bindText:r}));else Object.assign(t,r);for(let r of Object.keys(t)){let s=t[r];Gn(o,r,s)}return o},De=(...e)=>{let n=globalThis.document.createDocumentFragment();for(let o of e)n.append(o);return n},f=new Proxy({fragment:De},{get(e,n){if(n=n.replace(/[A-Z]/g,(o)=>`-${o.toLocaleLowerCase()}`),e[n]===void 0)e[n]=(...o)=>Be(n,...o);return e[n]},set(){throw Error("You may not add new properties to elements")}}),Fe=new Proxy({fragment:De},{get(e,n){if(e[n]===void 0)e[n]=(...o)=>Be(`${n}|${yn}`,...o);return e[n]},set(){throw Error("You may not add new properties to elements")}}),Pe=new Proxy({fragment:De},{get(e,n){if(e[n]===void 0)e[n]=(...o)=>Be(`${n}|${pn}`,...o);return e[n]},set(){throw Error("You may not add new properties to elements")}});var qn=["sort","splice","copyWithin","fill","pop","push","reverse","shift","unshift"],ze={},Qn=!0,Zn=/^\.?([^.[\](),])+(\.[^.[\](),]+|\[\d+\]|\[[^=[\](),]*=[^[\]()]+\])*$/,Kn=(e)=>Zn.test(e),W=(e="",n="")=>{if(e==="")return n;else if(n.match(/^\d+$/)!==null||n.includes("="))return`${e}[${n}]`;else return`${e}.${n}`},Rn={string(e){return new String(e)},boolean(e){return new Boolean(e)},bigint(e){return e},symbol(e){return e},number(e){return new Number(e)}},$e=Symbol("undefined");function Oe(e,n){if(e===void 0||e===null)return new Proxy({[$e]:e===null?"null":"undefined"},D(n,!0));let o=typeof e;if(o==="object"||o==="function")return e;else return new Proxy(Rn[typeof e](e),D(n,!0))}var _n=()=>new Proxy({},D("^",!0)),D=(e,n)=>({get(o,t){switch(t){case b:case"tosiPath":return e;case $:case"tosiValue":return o[$e]?o[$e]==="null"?null:void 0:o.valueOf?o.valueOf():o;case Je:case"tosiObserve":return(i)=>{let c=Ee(e,i);return()=>q(c)};case qe:case"tosiOn":return(i,c)=>j(i,c,E(o));case Ge:case"tosiBind":return(i,c,l)=>{w(i,e,c,l)};case"tosiBinding":return(i)=>({bind:{value:e,binding:i}});case"tosiListBinding":return(i=({span:l})=>l({bindText:"^"}),c={})=>[{bindList:{value:e,...c}},f.template(i(f,_n()))]}if(typeof t==="symbol")return o[t];let r=t,s=r.match(/^([^.[]+)\.(.+)$/)??r.match(/^([^\]]+)(\[.+)/)??r.match(/^(\[[^\]]+\])\.(.+)$/)??r.match(/^(\[[^\]]+\])\[(.+)$/);if(s!==null){let[,i,c]=s,l=W(e,i),m=V(o,i);return m!==null&&typeof m==="object"?new Proxy(m,D(l,n))[c]:m}if(r.startsWith("[")&&r.endsWith("]"))r=r.substring(1,r.length-1);if(!Array.isArray(o)&&o[r]!==void 0||Array.isArray(o)&&r.includes("=")){let i;if(r.includes("=")){let[c,l]=r.split("=");i=o.find((m)=>`${V(m,c)}`===l)}else i=o[r];if(i instanceof Object){let c=W(e,r);return new Proxy(i instanceof Function?i.bind(o):i,D(c,n))}else return n?Oe(i,W(e,r)):i}else if(Array.isArray(o)){let i=o[r];return typeof i==="function"?(...c)=>{let l=i.apply(o,c);if(qn.includes(r))Y(e);return l}:typeof i==="object"?new Proxy(i,D(W(e,r),n)):n?Oe(i,W(e,r)):i}else return n?Oe(o[r],W(e,r)):o[r]},set(o,t,r){r=E(r);let s=t!==$?W(e,t):e;if(Qn&&!Kn(s))throw Error(`setting invalid path ${s}`);if(E(d[s])!==r&&tn(ze,s,r))Y(s);return!0}}),Z=(e,n)=>{let o=typeof n==="function"?n:d[n];if(typeof o!=="function")throw Error(`observe expects a function or path to a function, ${n} is neither`);return Ee(e,o)},d=new Proxy(ze,D("",!1)),J=new Proxy(ze,D("",!0));var{document:K,MutationObserver:bn}=globalThis,Ae=(e,n)=>{let o=L.get(e);if(o==null)return;for(let t of o){let{binding:r,options:s}=t,{path:i}=t,{toDOM:c}=r;if(c!=null){if(i.startsWith("^")){let l=Le(e);if(l!=null&&l[b]!=null)i=t.path=`${l[b]}${i.substring(1)}`;else throw console.error(`Cannot resolve relative binding ${i}`,e,"is not part of a list"),Error(`Cannot resolve relative binding ${i}`)}if(n==null||i.startsWith(n))c(e,d[i],s)}}};if(bn!=null)new bn((n)=>{n.forEach((o)=>{Array.from(o.addedNodes).forEach((t)=>{if(t instanceof Element)Array.from(t.querySelectorAll(B)).forEach((r)=>Ae(r))})})}).observe(K.body,{subtree:!0,childList:!0});Z(()=>!0,(e)=>{let n=Array.from(K.querySelectorAll(B));for(let o of n)Ae(o,e)});var En=(e)=>{let n=e.target.closest(B);while(n!=null){let o=L.get(n);for(let t of o){let{binding:r,path:s}=t,{fromDOM:i}=r;if(i!=null){let c;try{c=i(n,t.options)}catch(l){throw console.error("Cannot get value from",n,"via",t),Error("Cannot obtain value fromDOM")}if(c!=null){let l=d[s];if(l==null)d[s]=c;else{let m=l[b]!=null?l[$]:l,u=c[b]!=null?c[$]:c;if(m!==u)d[s]=u}}}}n=n.parentElement.closest(B)}};if(globalThis.document!=null)K.body.addEventListener("change",En,!0),K.body.addEventListener("input",En,!0);function w(e,n,o,t){if(e instanceof DocumentFragment)throw Error("bind cannot bind to a DocumentFragment");let r;if(typeof n==="object"&&n[b]===void 0&&t===void 0){let{value:c}=n;r=typeof c==="string"?c:c[b],t=n,delete t.value}else r=typeof n==="string"?n:n[b];if(r==null)throw Error("bind requires a path or object with xin Proxy");let{toDOM:s}=o;e.classList?.add(ue);let i=L.get(e);if(i==null)i=[],L.set(e,i);if(i.push({path:r,binding:o,options:t}),s!=null&&!r.startsWith("^"))Y(r);if(t?.filter&&t?.needle)w(e,t.needle,{toDOM(c,l){console.log({needle:l}),c[G]?.filter(l)}});return e}var Tn=new Set,Nn=(e)=>{let n=e?.target.closest(ye),o=!1,t=new Proxy(e,{get(s,i){if(i==="stopPropagation")return()=>{e.stopPropagation(),o=!0};else{let c=s[i];return typeof c==="function"?c.bind(s):c}}}),r=new Set;while(!o&&n!=null){let i=O.get(n)[e.type]||r;for(let c of i){if(typeof c==="function")c(t);else{let l=d[c];if(typeof l==="function")l(t);else throw Error(`no event handler found at path ${c}`)}if(o)continue}n=n.parentElement!=null?n.parentElement.closest(ye):null}};function j(e,n,o){let t=O.get(e);if(e.classList.add(pe),t==null)t={},O.set(e,t);if(!t[n])t[n]=new Set;if(t[n].add(o),!Tn.has(n))Tn.add(n),K.body.addEventListener(n,Nn,!0);return()=>{t[n].delete(o)}}var eo=0;function je(){return`custom-elt${(eo++).toString(36)}`}var gn=0,R={};function no(e,n){let o=R[e],t=I(n).replace(/:host\b/g,e);R[e]=o?o+`
10
+ `+t:t}function oo(e){if(R[e])document.head.append(f.style({id:e+"-component"},R[e]));delete R[e]}class F extends HTMLElement{static elements=f;static _elementCreator;instanceId;styleNode;static styleSpec;static styleNode;content=f.slot();isSlotted;static _tagName=null;static get tagName(){return this._tagName}static StyleNode(e){return console.warn("StyleNode is deprecated, just assign static styleSpec: XinStyleSheet to the class directly"),f.style(I(e))}static elementCreator(e={}){let n=this;if(n._elementCreator==null){let{tag:o,styleSpec:t}=e,r=e!=null?o:null;if(r==null)if(typeof n.name==="string"&&n.name!==""){if(r=T(n.name),r.startsWith("-"))r=r.slice(1)}else r=je();if(customElements.get(r)!=null)console.warn(`${r} is already defined`);if(r.match(/\w+(-\w+)+/)==null)console.warn(`${r} is not a legal tag for a custom-element`),r=je();while(customElements.get(r)!==void 0)r=je();if(n._tagName=r,t!==void 0)no(r,t);window.customElements.define(r,this,e),n._elementCreator=f[r]}return n._elementCreator}initAttributes(...e){let n={},o={};new MutationObserver((r)=>{let s=!1;if(r.forEach((i)=>{s=!!(i.attributeName&&e.includes(dn(i.attributeName)))}),s&&this.queueRender!==void 0)this.queueRender(!1)}).observe(this,{attributes:!0}),e.forEach((r)=>{n[r]=S(this[r]);let s=T(r);Object.defineProperty(this,r,{enumerable:!1,get(){if(typeof n[r]==="boolean")return this.hasAttribute(s);else if(this.hasAttribute(s))return typeof n[r]==="number"?parseFloat(this.getAttribute(s)):this.getAttribute(s);else if(o[r]!==void 0)return o[r];else return n[r]},set(i){if(typeof n[r]==="boolean"){if(i!==this[r]){if(i)this.setAttribute(s,"");else this.removeAttribute(s);this.queueRender()}}else if(typeof n[r]==="number"){if(i!==parseFloat(this[r]))this.setAttribute(s,i),this.queueRender()}else if(typeof i==="object"||`${i}`!==`${this[r]}`){if(i===null||i===void 0||typeof i==="object")this.removeAttribute(s);else this.setAttribute(s,i);this.queueRender(),o[r]=i}}})})}initValue(){let e=Object.getOwnPropertyDescriptor(this,"value");if(e===void 0||e.get!==void 0||e.set!==void 0)return;let n=this.hasAttribute("value")?this.getAttribute("value"):S(this.value);delete this.value,Object.defineProperty(this,"value",{enumerable:!1,get(){return n},set(o){if(n!==o)n=o,this.queueRender(!0)}})}_parts;get parts(){let e=this.shadowRoot!=null?this.shadowRoot:this;if(this._parts==null)this._parts=new Proxy({},{get(n,o){if(n[o]===void 0){let t=e.querySelector(`[part="${o}"]`);if(t==null)t=e.querySelector(o);if(t==null)throw Error(`elementRef "${o}" does not exist!`);t.removeAttribute("data-ref"),n[o]=t}return n[o]}});return this._parts}constructor(){super();gn+=1,this.initAttributes("hidden"),this.instanceId=`${this.tagName.toLocaleLowerCase()}-${gn}`,this._value=S(this.defaultValue)}connectedCallback(){if(oo(this.constructor.tagName),this.hydrate(),this.role!=null)this.setAttribute("role",this.role);if(this.onResize!==void 0){if(Q.observe(this),this._onResize==null)this._onResize=this.onResize.bind(this);this.addEventListener("resize",this._onResize)}if(this.value!=null&&this.getAttribute("value")!=null)this._value=this.getAttribute("value");this.queueRender()}disconnectedCallback(){Q.unobserve(this)}_changeQueued=!1;_renderQueued=!1;queueRender(e=!1){if(!this._hydrated)return;if(!this._changeQueued)this._changeQueued=e;if(!this._renderQueued)this._renderQueued=!0,requestAnimationFrame(()=>{if(this._changeQueued)Ce(this,"change");this._changeQueued=!1,this._renderQueued=!1,this.render()})}_hydrated=!1;hydrate(){if(!this._hydrated){this.initValue();let e=typeof this.content!=="function",n=typeof this.content==="function"?this.content(f):this.content,{styleSpec:o}=this.constructor,{styleNode:t}=this.constructor;if(o)t=this.constructor.styleNode=f.style(I(o)),delete this.constructor.styleNode;if(this.styleNode)console.warn(this,"styleNode is deprecrated, use static styleNode or statc styleSpec instead"),t=this.styleNode;if(t){let r=this.attachShadow({mode:"open"});r.appendChild(t.cloneNode(!0)),Xe(r,n,e)}else if(n!==null){let r=Array.from(this.childNodes);Xe(this,n,e),this.isSlotted=this.querySelector("slot,xin-slot")!==void 0;let s=Array.from(this.querySelectorAll("slot"));if(s.length>0)s.forEach(We.replaceSlot);if(r.length>0){let i={"":this};Array.from(this.querySelectorAll("xin-slot")).forEach((c)=>{i[c.name]=c}),r.forEach((c)=>{let l=i[""],m=c instanceof Element?i[c.slot]:l;(m!==void 0?m:l).append(c)})}}this._hydrated=!0}}render(){}}class We extends F{name="";content=null;static replaceSlot(e){let n=document.createElement("xin-slot");if(e.name!=="")n.setAttribute("name",e.name);e.replaceWith(n)}constructor(){super();this.initAttributes("name")}}var xt=We.elementCreator({tag:"xin-slot"});var to=(e=()=>!0)=>{let n=localStorage.getItem("xin-state");if(n!=null){let t=JSON.parse(n);for(let r of Object.keys(t).filter(e))if(d[r]!==void 0)Object.assign(d[r],t[r]);else d[r]=t[r]}let o=Me(()=>{let t={},r=E(d);for(let s of Object.keys(r).filter(e))t[s]=r[s];localStorage.setItem("xin-state",JSON.stringify(t)),console.log("xin state saved to localStorage")},500);Z(e,o)};var Ye="1.0.10";function ce(e){return Object.assign(J,e),J}function le(e){return console.warn("boxedProxy is deprecated, please use tosi() instead"),ce(e)}function Ve(e,n=!1){if(n)return console.warn("xinProxy(..., true) is deprecated; use tosi(...) instead"),le(e);return Object.keys(e).forEach((o)=>{d[o]=e[o]}),d}var ro={};async function ae(e,n){let{type:o,styleSpec:t}=await n(e,{Color:a,Component:F,elements:f,svgElements:Fe,mathML:Pe,varDefault:ie,vars:ve,xin:d,boxed:J,xinProxy:Ve,boxedProxy:le,tosi:ce,makeComponent:ae,bind:w,on:j,version:Ye}),r={type:o,creator:o.elementCreator({tag:e,styleSpec:t})};return ro[e]=r,r}var Ue={},io=(e)=>import(e);class me extends F{tag="anon-elt";src="";property="default";loaded;blueprintLoaded=(e)=>{};async packaged(){let{tag:e,src:n,property:o}=this,t=`${e}.${o}:${n}`;if(!this.loaded){if(Ue[t]===void 0)Ue[t]=io(n).then((r)=>{let s=r[o];return ae(e,s)});else console.log(`using cached ${e} with signature ${t}`);this.loaded=await Ue[t],this.blueprintLoaded(this.loaded)}return this.loaded}constructor(){super();this.initAttributes("tag","src","property")}}var so=me.elementCreator({tag:"xin-blueprint",styleSpec:{":host":{display:"none"}}});class Ie extends F{allLoaded=()=>{};constructor(){super()}async load(){let n=Array.from(this.querySelectorAll(me.tagName)).filter((o)=>o.src).map((o)=>o.packaged());await Promise.all(n),this.allLoaded()}connectedCallback(){super.connectedCallback(),this.load()}}var co=Ie.elementCreator({tag:"xin-loader",styleSpec:{":host":{display:"none"}}});export{E as xinValue,Ve as xinProxy,H as xinPath,d as xin,Ye as version,ve as vars,ie as varDefault,Ke as updates,q as unobserve,Ae as touchElement,Y as touch,ce as tosi,oe as throttle,Fe as svgElements,P as settings,j as on,Z as observe,Pe as mathML,ae as makeComponent,Un as invertLuminance,Vn as initVars,to as hotReload,Le as getListItem,Se as getListInstance,te as getListBinding,He as getCssVar,f as elements,Pn as deleteListItem,Me as debounce,I as css,le as boxedProxy,J as boxed,co as blueprintLoader,so as blueprint,re as bindings,w as bind,jn as StyleSheet,zn as MoreMath,F as Component,a as Color,Ie as BlueprintLoader,me as Blueprint};
11
11
 
12
- //# debugId=EDD1BF537E34F89164756E2164756E21
12
+ //# debugId=D83C5C39D6BE877264756E2164756E21
13
13
  //# sourceMappingURL=module.js.map