tosijs 1.0.3 → 1.0.4

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