tosijs 1.0.10 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -1,13 +1,13 @@
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
- ${s}
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 o={};for(let n in e){let r=e[n];if(e!=null&&typeof e==="object")o[n]=S(r);else o[n]=r}return o}var Ce="-xin-data",D=`.${Ce}`,be="-xin-event",Ee=`.${be}`,C="xinPath",F="xinValue",xe="xinObserve",Me="xinBind",Te="xinOn",B=Symbol("list-binding"),ne=Symbol("list-instance"),X=(e)=>{return e&&e[C]||void 0};function b(e){if(typeof e==="object"&&e!==null){let o=e[F];return o!==void 0?o:e}return e}var W=new WeakMap,H=new WeakMap;var J=(e)=>{let o=e.cloneNode();if(o instanceof Element){let n=H.get(e),r=W.get(e);if(n!=null)H.set(o,S(n));if(r!=null)W.set(o,S(r))}for(let n of Array.from(e instanceof HTMLTemplateElement?e.content.childNodes:e.childNodes))if(n instanceof Element||n instanceof DocumentFragment)o.appendChild(J(n));else o.appendChild(n.cloneNode());return o};var j={debug:!1,perf:!1};var oo=Symbol("observer should be removed"),re=[],te=[],Le=!1,ke,ge;class no{description;test;callback;constructor(e,o){let n=typeof o==="string"?`"${o}"`:`function ${o.name}`,r;if(typeof e==="string")this.test=(t)=>typeof t==="string"&&t!==""&&(e.startsWith(t)||t.startsWith(e)),r=`test = "${e}"`;else if(e instanceof RegExp)this.test=e.test.bind(e),r=`test = "${e.toString()}"`;else if(e instanceof Function)this.test=e,r=`test = function ${e.name}`;else throw Error("expect listener test to be a string, RegExp, or test function");if(this.description=`${r}, ${n}`,typeof o==="function")this.callback=o;else throw Error("expect callback to be a path or function");re.push(this)}}var ro=async()=>{if(ke===void 0)return;await ke},Wo=()=>{if(j.perf)console.time("xin async update");let e=Array.from(te);for(let o of e)re.filter((n)=>{let r;try{r=n.test(o)}catch(t){throw Error(`Listener ${n.description} threw "${t}" at "${o}"`)}if(r===oo)return q(n),!1;return r}).forEach((n)=>{let r;try{r=n.callback(o)}catch(t){console.error(`Listener ${n.description} threw "${t}" handling "${o}"`)}if(r===oo)q(n)});if(te.splice(0),Le=!1,typeof ge==="function")ge();if(j.perf)console.timeEnd("xin async update")},K=(e)=>{let o=typeof e==="string"?e:X(e);if(o===void 0)throw console.error("touch was called on an invalid target",e),Error("touch was called on an invalid target");if(Le===!1)ke=new Promise((n)=>{ge=n}),Le=setTimeout(Wo);if(te.find((n)=>o.startsWith(n))==null)te.push(o)},Q=(e,o)=>{return new no(e,o)},q=(e)=>{let o=re.indexOf(e);if(o>-1)re.splice(o,1);else throw Error("unobserve failed, listener not found")};var _={},Se=null,to=(e)=>{Se=e},ie=()=>{if(Se===null)throw Error("xin proxy not initialized");return Se},He=null,Xe=null,io=(e,o)=>{He=e,Xe=o},se=()=>{if(He===null)throw Error("bind not initialized");return He},ce=()=>{if(Xe===null)throw Error("on not initialized");return Xe};var $e=(e,o)=>{let n=new Event(o);e.dispatchEvent(n)},co=(e)=>{if(e instanceof HTMLInputElement)return e.type;else if(e instanceof HTMLSelectElement&&e.hasAttribute("multiple"))return"multi-select";else return"other"},mo=(e,o)=>{switch(co(e)){case"radio":e.checked=e.value===o;break;case"checkbox":e.checked=!!o;break;case"date":e.valueAsDate=new Date(o);break;case"multi-select":for(let n of Array.from(e.querySelectorAll("option")))n.selected=o[n.value];break;default:e.value=o}},lo=(e)=>{switch(co(e)){case"radio":{let o=e.parentElement?.querySelector(`[name="${e.name}"]:checked`);return o!=null?o.value:null}case"checkbox":return e.checked;case"date":return e.valueAsDate?.toISOString();case"multi-select":return Array.from(e.querySelectorAll("option")).reduce((o,n)=>{return o[n.value]=n.selected,o},{});default:return e.value}},{ResizeObserver:so}=globalThis,N=so!=null?new so((e)=>{for(let o of e){let n=o.target;$e(n,"resize")}}):{observe(){},unobserve(){}},ze=(e,o,n=!0)=>{if(e!=null&&o!=null)if(typeof o==="string")e.textContent=o;else if(Array.isArray(o))o.forEach((r)=>{e.append(r instanceof Node&&n?J(r):r)});else if(o instanceof Node)e.append(n?J(o):o);else throw Error("expect text content or document node")};var De=(e,o=250)=>{let n;return(...r)=>{if(n!==void 0)clearTimeout(n);n=setTimeout(()=>{e(...r)},o)}},me=(e,o=250)=>{let n,r=Date.now()-o,t=!1;return(...i)=>{if(clearTimeout(n),n=setTimeout(()=>{e(...i),r=Date.now()},o),!t&&Date.now()-r>=o){t=!0;try{e(...i),r=Date.now()}finally{t=!1}}}};var Jo=(e)=>{try{return JSON.stringify(e)}catch(o){return"{has circular references}"}},Fe=(...e)=>Error(e.map(Jo).join(" "));var jo=()=>new Date(parseInt("1000000000",36)+Date.now()).valueOf().toString(36).slice(1),qo=0,Qo=()=>(parseInt("10000",36)+ ++qo).toString(36).slice(-5),Go=()=>jo()+Qo(),We=Symbol("delete"),uo=Symbol("new-object"),Ye=Symbol("automatic-index");function yo(e){if(e==="")return[];if(Array.isArray(e))return e;else{let o=[];while(e.length>0){let n=e.search(/\[[^\]]+\]/);if(n===-1){o.push(e.split("."));break}else{let r=e.slice(0,n);if(e=e.slice(n),r!=="")o.push(r.split("."));if(n=e.indexOf("]")+1,o.push(e.slice(1,n-1)),e.slice(n,n+1)===".")n+=1;e=e.slice(n)}}return o}}var $=new WeakMap;function ho(e,o){if($.get(e)===void 0)$.set(e,{});if($.get(e)[o]===void 0)$.get(e)[o]={};let n=$.get(e)[o];if(o==="_auto_")e.forEach((r,t)=>{if(r[Ye]===void 0)r[Ye]=Go();n[r[Ye]+""]=t});else e.forEach((r,t)=>{n[G(r,o)+""]=t});return n}function Zo(e,o){if($.get(e)===void 0||$.get(e)[o]===void 0)return ho(e,o);else return $.get(e)[o]}function Ao(e,o,n){n=n+"";let r=Zo(e,o)[n];if(r===void 0||G(e[r],o)+""!==n)r=ho(e,o)[n];return r}function Oo(e,o,n){if(e[o]===void 0&&n!==void 0)e[o]=n;return e[o]}function po(e,o,n,r){let t=o!==""?Ao(e,o,n):n;if(r===We)return e.splice(t,1),$.delete(e),Symbol("deleted");else if(r===uo){if(o===""&&e[t]===void 0)e[t]={}}else if(r!==void 0)if(t!==void 0)e[t]=r;else if(o!==""&&G(r,o)+""===n+"")e.push(r),t=e.length-1;else throw Error(`byIdPath insert failed at [${o}=${n}]`);return e[t]}function fo(e){if(!Array.isArray(e))throw Fe("setByPath failed: expected array, found",e)}function ao(e){if(e==null||!(e instanceof Object))throw Fe("setByPath failed: expected Object, found",e)}function G(e,o){let n=yo(o),r=e,t,i,m,s;for(t=0,i=n.length;r!==void 0&&t<i;t++){let c=n[t];if(Array.isArray(c))for(m=0,s=c.length;r!==void 0&&m<s;m++){let l=c[m];r=r[l]}else if(r.length===0){if(r=r[Number(c.slice(1))],c[0]!=="=")return}else if(c.includes("=")){let[l,...a]=c.split("=");r=po(r,l,a.join("="))}else m=parseInt(c,10),r=r[m]}return r}function wo(e,o,n){let r=e;if(o==="")throw Error("setByPath cannot be used to set the root object");let t=yo(o);while(r!=null&&t.length>0){let i=t.shift();if(typeof i==="string"){let m=i.indexOf("=");if(m>-1){if(m===0)ao(r);else fo(r);let s=i.slice(0,m),c=i.slice(m+1);if(r=po(r,s,c,t.length>0?uo:n),t.length===0)return!0}else{fo(r);let s=parseInt(i,10);if(t.length>0)r=r[s];else{if(n!==We){if(r[s]===n)return!1;r[s]=n}else r.splice(s,1);return!0}}}else if(Array.isArray(i)&&i.length>0){ao(r);while(i.length>0){let m=i.shift();if(i.length>0||t.length>0)r=Oo(r,m,i.length>0?{}:[]);else{if(n!==We){if(r[m]===n)return!1;r[m]=n}else{if(!Object.prototype.hasOwnProperty.call(r,m))return!1;delete r[m]}return!0}}}else throw Error(`setByPath failed, bad path ${o}`)}throw Error(`setByPath(${e}, ${o}, ${n}) failed`)}var le={value:{toDOM:mo,fromDOM(e){return lo(e)}},text:{toDOM(e,o){e.textContent=o}},enabled:{toDOM(e,o){e.disabled=!o}},disabled:{toDOM(e,o){e.disabled=Boolean(o)}},list:{toDOM(e,o,n){fe(e,o,n).update(o)}}};function x(e){return e.replace(/[A-Z]/g,(o)=>{return`-${o.toLocaleLowerCase()}`})}function Co(e){return e.replace(/-([a-z])/g,(o,n)=>{return n.toLocaleUpperCase()})}var vo=180/Math.PI,Uo=Math.PI/180;function M(e,o,n){return n<e?NaN:o<e?e:o>n?n:o}function z(e,o,n,r=!0){if(r)n=M(0,n,1);return n*(o-e)+e}var Ko={RADIANS_TO_DEGREES:vo,DEGREES_TO_RADIANS:Uo,clamp:M,lerp:z};function Je(e,o=document.body){let n=getComputedStyle(o);if(e.endsWith(")")&&e.startsWith("var("))e=e.slice(4,-1);return n.getPropertyValue(e).trim()}var Ro=(e,o,n)=>{return(0.299*e+0.587*o+0.114*n)/255},Z=(e)=>("00"+Math.round(Number(e)).toString(16)).slice(-2);class bo{h;s;l;constructor(e,o,n){e/=255,o/=255,n/=255;let r=Math.max(e,o,n),t=r-Math.min(e,o,n),i=t!==0?r===e?(o-n)/t:r===o?2+(n-e)/t:4+(e-o)/t:0;this.h=60*i<0?60*i+360:60*i,this.s=t!==0?r<=0.5?t/(2*r-t):t/(2-(2*r-t)):0,this.l=(2*r-t)/2}}var R=globalThis.document!==void 0?globalThis.document.createElement("span"):void 0;class f{r;g;b;a;static fromVar(e,o=document.body){return f.fromCss(Je(e,o))}static fromCss(e){let o=e;if(R instanceof HTMLSpanElement)R.style.color="black",R.style.color=e,document.body.appendChild(R),o=getComputedStyle(R).color,R.remove();let[n,r,t,i]=o.match(/[\d.]+/g)||["0","0","0","0"],m=o.startsWith("color(srgb")?255:1;return new f(Number(n)*m,Number(r)*m,Number(t)*m,i==null?1:Number(i))}static fromHsl(e,o,n,r=1){let t,i,m;if(o===0)t=i=m=n;else{let c=(w,T,p)=>{if(p<0)p+=1;if(p>1)p-=1;if(p<0.16666666666666666)return w+(T-w)*6*p;if(p<0.5)return T;if(p<0.6666666666666666)return w+(T-w)*(0.6666666666666666-p)*6;return w},l=n<0.5?n*(1+o):n+o-n*o,a=2*n-l,y=(e%360+360)%360/360;t=c(a,l,y+0.3333333333333333),i=c(a,l,y),m=c(a,l,y-0.3333333333333333)}let s=new f(t*255,i*255,m*255,r);return s.hslCached={h:(e%360+360)%360,s:o,l:n},s}static black=new f(0,0,0);static white=new f(255,255,255);constructor(e,o,n,r=1){this.r=M(0,e,255),this.g=M(0,o,255),this.b=M(0,n,255),this.a=M(0,r,1)}get inverse(){return new f(255-this.r,255-this.g,255-this.b,this.a)}get inverseLuminance(){let{h:e,s:o,l:n}=this._hsl;return f.fromHsl(e,o,1-n,this.a)}get opaque(){return this.a===1?this:new f(this.r,this.g,this.b,1)}contrasting(e=1){return this.opaque.blend(this.brightness>0.5?f.black:f.white,e)}get rgb(){let{r:e,g:o,b:n}=this;return`rgb(${e.toFixed(0)},${o.toFixed(0)},${n.toFixed(0)})`}get rgba(){let{r:e,g:o,b:n,a:r}=this;return`rgba(${e.toFixed(0)},${o.toFixed(0)},${n.toFixed(0)},${r.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 bo(this.r,this.g,this.b);return this.hslCached}get hsl(){let{h:e,s:o,l:n}=this._hsl;return`hsl(${e.toFixed(0)}deg ${(o*100).toFixed(0)}% ${(n*100).toFixed(0)}%)`}get hsla(){let{h:e,s:o,l:n}=this._hsl;return`hsl(${e.toFixed(0)}deg ${(o*100).toFixed(0)}% ${(n*100).toFixed(0)}% / ${(this.a*100).toFixed(0)}%)`}get mono(){let e=this.brightness*255;return new f(e,e,e)}get brightness(){return Ro(this.r,this.g,this.b)}get html(){return this.toString()}toString(){return this.a===1?"#"+Z(this.r)+Z(this.g)+Z(this.b):"#"+Z(this.r)+Z(this.g)+Z(this.b)+Z(Math.floor(255*this.a))}brighten(e){let{h:o,s:n,l:r}=this._hsl,t=M(0,r+e*(1-r),1);return f.fromHsl(o,n,t,this.a)}darken(e){let{h:o,s:n,l:r}=this._hsl,t=M(0,r*(1-e),1);return f.fromHsl(o,n,t,this.a)}saturate(e){let{h:o,s:n,l:r}=this._hsl,t=M(0,n+e*(1-n),1);return f.fromHsl(o,t,r,this.a)}desaturate(e){let{h:o,s:n,l:r}=this._hsl,t=M(0,n*(1-e),1);return f.fromHsl(o,t,r,this.a)}rotate(e){let{h:o,s:n,l:r}=this._hsl,t=(o+360+e)%360;return f.fromHsl(t,n,r,this.a)}opacity(e){let{h:o,s:n,l:r}=this._hsl;return f.fromHsl(o,n,r,e)}swatch(){return console.log(`%c %c ${this.html}, ${this.rgba}`,`background-color: ${this.html}`,"background-color: transparent"),this}blend(e,o){return new f(z(this.r,e.r,o),z(this.g,e.g,o),z(this.b,e.b,o),z(this.a,e.a,o))}static blendHue(e,o,n){let r=(o-e+720)%360;if(r<180)return e+n*r;else return e-(360-r)*n}mix(e,o){let n=this._hsl,r=e._hsl;return f.fromHsl(n.s===0?r.h:r.s===0?n.h:f.blendHue(n.h,r.h,o),z(n.s,r.s,o),z(n.l,r.l,o),z(this.a,e.a,o))}colorMix(e,o){return f.fromCss(`color-mix(in hsl, ${this.html}, ${e.html} ${(o*100).toFixed(0)}%)`)}}function Vo(e,o){let n=d.style(V(o));n.id=e,document.head.append(n)}var Io=["animation-iteration-count","flex","flex-base","flex-grow","flex-shrink","opacity","order","tab-size","widows","z-index","zoom"],je=(e,o)=>{if(typeof o==="number"&&!Io.includes(e))o=`${o}px`;if(e.startsWith("_"))if(e.startsWith("__"))e="--"+e.substring(2),o=`var(${e}-default, ${o})`;else e="--"+e.substring(1);return{prop:e,value:String(o)}},Po=(e,o,n)=>{if(n===void 0)return"";if(n instanceof f)n=n.html;let r=je(o,n);return`${e} ${r.prop}: ${r.value};`},Eo=(e,o,n="")=>{let r=x(e);if(typeof o==="object"&&!(o instanceof f)){let t=Object.keys(o).map((i)=>Eo(i,o[i],`${n} `)).join(`
2
+ `);return`${n} ${e} {
3
+ ${t}
4
+ ${n} }`}else return Po(n,r,o)},V=(e,o="")=>{return Object.keys(e).map((r)=>{let t=e[r];if(typeof t==="string"){if(r==="@import")return`@import url('${t}');`;throw Error("top-level string value only allowed for `@import`")}let i=Object.keys(t).map((m)=>Eo(m,t[m])).join(`
5
+ `);return`${o}${r} {
6
+ ${i}
7
7
  }`}).join(`
8
8
 
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};
9
+ `)},Bo=(e)=>{console.warn("initVars is deprecated. Just use _ and __ prefixes instead.");let o={};for(let n of Object.keys(e)){let r=e[n],t=x(n);o[`--${t}`]=typeof r==="number"&&r!==0?String(r)+"px":r}return o},_o=(e)=>{let o={};for(let n of Object.keys(e)){let r=e[n];if(r instanceof f)o[n]=r.inverseLuminance;else if(typeof r==="string"&&r.match(/^(#[0-9a-fA-F]{3}|rgba?\(|hsla?\()/))o[n]=f.fromCss(r).inverseLuminance}return o},ae=new Proxy({},{get(e,o){if(e[o]===void 0){let n="--"+x(o);e[o]=(r)=>`var(${n}, ${r})`}return e[o]}}),qe=new Proxy({},{get(e,o){if(o==="default")return ae;if(e[o]==null){o=x(o);let[,n,,r,t,i]=o.match(/^([-\w]*?)((_)?(\d+)(\w?))?$/)||["",o],m=`--${n}`;if(t!=null){let s=r==null?Number(t)/100:-Number(t)/100;switch(i){case"b":{let c=f.fromVar(m);e[o]=s>0?c.brighten(s).rgba:c.darken(-s).rgba}break;case"s":{let c=f.fromVar(m);e[o]=s>0?c.saturate(s).rgba:c.desaturate(-s).rgba}break;case"h":{let c=f.fromVar(m);e[o]=c.rotate(s*100).rgba}break;case"o":{let c=f.fromVar(m);e[o]=c.opacity(s).rgba}break;case"":e[o]=`calc(var(${m}) * ${s})`;break;default:throw console.error(i),Error(`Unrecognized method ${i} for css variable ${m}`)}}else e[o]=`var(${m})`}return e[o]}});var xo="http://www.w3.org/1998/Math/MathML",Mo="http://www.w3.org/2000/svg";var de={},To=(e,o,n)=>{let r=je(x(o),n);if(r.prop.startsWith("--"))e.style.setProperty(r.prop,r.value);else e.style[o]=r.value},No=(e)=>{return{toDOM(o,n){To(o,e,n)}}},Lo=(e,o,n)=>{if(o==="style")if(typeof n==="object")for(let r of Object.keys(n))if(X(n[r]))g(e,n[r],No(r));else To(e,r,n[r]);else e.setAttribute("style",n);else if(e[o]!==void 0){let{MathMLElement:r}=globalThis;if(e instanceof SVGElement||r!==void 0&&e instanceof r)e.setAttribute(o,n);else e[o]=n}else{let r=x(o);if(r==="class")n.split(" ").forEach((t)=>{e.classList.add(t)});else if(e[r]!==void 0)e[r]=n;else if(typeof n==="boolean")n?e.setAttribute(r,""):e.removeAttribute(r);else e.setAttribute(r,n)}},en=(e)=>{return{toDOM(o,n){Lo(o,e,n)}}},on=(e,o,n)=>{if(o==="apply")n(e);else if(o.match(/^on[A-Z]/)!=null){let r=o.substring(2).toLowerCase();I(e,r,n)}else if(o==="bind")if((typeof n.binding==="string"?le[n.binding]:n.binding)!==void 0&&n.value!==void 0)g(e,n.value,n.binding instanceof Function?{toDOM:n.binding}:n.binding);else throw Error("bad binding");else if(o.match(/^bind[A-Z]/)!=null){let r=o.substring(4,5).toLowerCase()+o.substring(5),t=le[r];if(t!==void 0)g(e,n,t);else throw Error(`${o} is not allowed, bindings.${r} is not defined`)}else if(X(n))g(e,n,en(o));else Lo(e,o,n)},Qe=(e,...o)=>{if(de[e]===void 0){let[t,i]=e.split("|");if(i===void 0)de[e]=globalThis.document.createElement(t);else de[e]=globalThis.document.createElementNS(i,t)}let n=de[e].cloneNode(),r={};for(let t of o)if(t instanceof Element||t instanceof DocumentFragment||typeof t==="string"||typeof t==="number")if(n instanceof HTMLTemplateElement)n.content.append(t);else n.append(t);else if(X(t))n.append(d.span({bindText:t}));else Object.assign(r,t);for(let t of Object.keys(r)){let i=r[t];on(n,t,i)}return n},Ge=(...e)=>{let o=globalThis.document.createDocumentFragment();for(let n of e)o.append(n);return o},d=new Proxy({fragment:Ge},{get(e,o){if(o=o.replace(/[A-Z]/g,(n)=>`-${n.toLocaleLowerCase()}`),e[o]===void 0)e[o]=(...n)=>Qe(o,...n);return e[o]},set(){throw Error("You may not add new properties to elements")}}),Ze=new Proxy({fragment:Ge},{get(e,o){if(e[o]===void 0)e[o]=(...n)=>Qe(`${o}|${Mo}`,...n);return e[o]},set(){throw Error("You may not add new properties to elements")}}),Ae=new Proxy({fragment:Ge},{get(e,o){if(e[o]===void 0)e[o]=(...n)=>Qe(`${o}|${xo}`,...n);return e[o]},set(){throw Error("You may not add new properties to elements")}});var nn=["sort","splice","copyWithin","fill","pop","push","reverse","shift","unshift"],rn=!0,tn=/^\.?([^.[\](),])+(\.[^.[\](),]+|\[\d+\]|\[[^=[\](),]*=[^[\]()]+\])*$/,sn=(e)=>tn.test(e),A=(e="",o="")=>{if(e==="")return o;else if(o.match(/^\d+$/)!==null||o.includes("="))return`${e}[${o}]`;else return`${e}.${o}`},So=Symbol("boxed-scalar"),cn={[So]:!0};function Oe(e,o){if(e!==null&&(typeof e==="object"||typeof e==="function"))return e;return new Proxy(cn,v(o,!0))}var ve=()=>new Proxy({},v("^",!0)),ko=!1;function O(){if(!ko)console.warn("xinValue, tosiValue, xinPath, tosiPath, etc. are deprecated. Use value, path, observe, bind, on, binding, listBinding instead."),ko=!0}var go=(e)=>{return e!=null&&So in e},v=(e,o)=>({get(n,r){if(go(n)){let s=()=>G(_,e);switch(r){case"path":return e;case"value":return s();case"valueOf":case"toJSON":return()=>s();case Symbol.toPrimitive:return(c)=>{let l=s();if(c==="number")return Number(l);if(c==="string")return String(l);return l};case"toString":return()=>String(s());case"observe":return(c)=>{let l=Q(e,c);return()=>q(l)};case"on":return(c,l)=>ce()(c,l,s());case"bind":return(c,l,a)=>{se()(c,e,l,a)};case"binding":return(c)=>({bind:{value:e,binding:c}});case"listBinding":return(c=({span:a})=>a({bindText:"^"}),l={})=>[{bindList:{value:e,...l}},d.template(c(d,ve()))];case F:case"tosiValue":return O(),s();case C:case"tosiPath":return O(),e;case xe:case"tosiObserve":return O(),(c)=>{let l=Q(e,c);return()=>q(l)};case Te:case"tosiOn":return O(),(c,l)=>ce()(c,l,s());case Me:case"tosiBind":return O(),(c,l,a)=>{se()(c,e,l,a)};case"tosiBinding":return O(),(c)=>({bind:{value:e,binding:c}});case"tosiListBinding":return O(),(c=({span:a})=>a({bindText:"^"}),l={})=>[{bindList:{value:e,...l}},d.template(c(d,ve()))]}if(typeof r==="string"&&/^\d+$/.test(r)){let c=s();if(typeof c==="string")return c[parseInt(r,10)]}if(r==="length"){let c=s();if(typeof c==="string")return c.length}return}switch(r){case C:case"tosiPath":return e;case F:case"tosiValue":return n.valueOf?n.valueOf():n;case xe:case"tosiObserve":return(s)=>{let c=Q(e,s);return()=>q(c)};case Te:case"tosiOn":return(s,c)=>ce()(s,c,b(n));case Me:case"tosiBind":return(s,c,l)=>{se()(s,e,c,l)};case"tosiBinding":return(s)=>({bind:{value:e,binding:s}});case"tosiListBinding":return(s=({span:l})=>l({bindText:"^"}),c={})=>[{bindList:{value:e,...c}},d.template(s(d,ve()))]}if(typeof r==="symbol")return n[r];let t=Object.getOwnPropertyDescriptor(n,r);if(t&&!t.configurable&&!t.writable&&"value"in t)return t.value;let i=r,m=i.match(/^([^.[]+)\.(.+)$/)??i.match(/^([^\]]+)(\[.+)/)??i.match(/^(\[[^\]]+\])\.(.+)$/)??i.match(/^(\[[^\]]+\])\[(.+)$/);if(m!==null){let[,s,c]=m,l=A(e,s),a=G(n,s);return a!==null&&typeof a==="object"?new Proxy(a,v(l,o))[c]:a}if(i.startsWith("[")&&i.endsWith("]"))i=i.substring(1,i.length-1);if(!Array.isArray(n)&&n[i]!==void 0||Array.isArray(n)&&i.includes("=")){let s;if(i.includes("=")){let[c,l]=i.split("=");s=n.find((a)=>`${G(a,c)}`===l)}else s=n[i];if(s instanceof Object){let c=A(e,i);return new Proxy(s instanceof Function?s.bind(n):s,v(c,o))}else return o?Oe(s,A(e,i)):s}else if(Array.isArray(n)){let s=n[i];return typeof s==="function"?(...c)=>{let l=c.map((y)=>b(y)),a=s.apply(n,l);if(nn.includes(i))K(e);return a}:typeof s==="object"?new Proxy(s,v(A(e,i),o)):o?Oe(s,A(e,i)):s}else return o?Oe(n[i],A(e,i)):n[i]},set(n,r,t){t=b(t);let m=r===F||r==="value"&&go(n)?e:A(e,r);if(rn&&!sn(m))throw Error(`setting invalid path ${m}`);if(b(u[m])!==t&&wo(_,m,t))K(m);return!0}}),Ue=(e,o)=>{let n=typeof o==="function"?o:u[o];if(typeof n!=="function")throw Error(`observe expects a function or path to a function, ${o} is neither`);return Q(e,n)},u=new Proxy(_,v("",!1));to(u);var P=new Proxy(_,v("",!0));var mn=16,ln=100;function Ho(e,o){let n=Array.from(e.querySelectorAll(D));if(e.matches(D))n.unshift(e);for(let r of n){let t=H.get(r);for(let i of t){if(i.path.startsWith("^"))i.path=`${o}${i.path.substring(1)}`;if(i.binding.toDOM!=null)i.binding.toDOM(r,u[i.path])}}}class Xo{boundElement;listTop;listBottom;template;options;itemToElement;array=[];_update;_previousSlice;static filterBoundObservers=new WeakMap;constructor(e,o,n={}){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 r=e.children[0];if(r.content.children.length!==1)throw Error("ListBinding expects a template with exactly one child element");this.template=J(r.content.children[0])}else this.template=e.children[0],this.template.remove();if(this.options=n,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),n.virtual!=null)if(N.observe(this.boundElement),this._update=me(()=>{this.update(this.array,!0)},mn),this.boundElement.addEventListener("resize",this._update),n.virtual.scrollContainer==="window")window.addEventListener("scroll",this._update),window.addEventListener("resize",this._update);else this.boundElement.addEventListener("scroll",this._update)}visibleSlice(){let{virtual:e,hiddenProp:o,visibleProp:n}=this.options,r=this.array;if(o!==void 0)r=r.filter((c)=>c[o]!==!0);if(n!==void 0)r=r.filter((c)=>c[n]===!0);if(this.options.filter&&this.needle!==void 0)r=this.options.filter(r,this.needle);let t=0,i=r.length-1,m=0,s=0;if(e!=null&&this.boundElement instanceof HTMLElement){let c=this.boundElement.offsetWidth,l=e.scrollContainer==="window",a,y;if(l){a=window.innerHeight;let U=this.boundElement.getBoundingClientRect();y=Math.max(0,-U.top)}else a=this.boundElement.offsetHeight,y=this.boundElement.scrollTop;if(e.visibleColumns==null)e.visibleColumns=e.width!=null?Math.max(1,Math.floor(c/e.width)):1;let w=Math.ceil(a/e.height)+(e.rowChunkSize||1),T=Math.ceil(r.length/e.visibleColumns),p=e.visibleColumns*w,L=Math.floor(y/e.height);if(L>T-w+1)L=Math.max(0,T-w+1);if(e.rowChunkSize)L-=L%e.rowChunkSize;t=L*e.visibleColumns,i=t+p-1,m=L*e.height,s=Math.max((T-w)*e.height-m,0)}return{items:r,firstItem:t,lastItem:i,topBuffer:m,bottomBuffer:s}}needle;filter=me((e)=>{if(this.needle!==e)this.needle=e,this.update(this.array)},ln);update(e,o){if(e==null)e=[];this.array=e;let{hiddenProp:n,visibleProp:r}=this.options,t=X(e),i=this.visibleSlice();this.boundElement.classList.toggle("-xin-empty-list",i.items.length===0);let m=this._previousSlice,{firstItem:s,lastItem:c,topBuffer:l,bottomBuffer:a}=i;if(n===void 0&&r===void 0&&o===!0&&m!=null&&s===m.firstItem&&c===m.lastItem)return;this._previousSlice=i;let y=0,w=0,T=0;for(let h of Array.from(this.boundElement.children)){if(h===this.listTop||h===this.listBottom)continue;let k=h[ne];if(k==null)h.remove();else{let E=i.items.indexOf(k);if(E<s||E>c)h.remove(),this.itemToElement.delete(k),y++}}this.listTop.style.height=String(l)+"px",this.listBottom.style.height=String(a)+"px";let p=[],{idPath:L}=this.options;for(let h=s;h<=c;h++){let k=i.items[h];if(k===void 0)continue;let E=this.itemToElement.get(b(k));if(E==null){if(T++,E=J(this.template),typeof k==="object")this.itemToElement.set(b(k),E),E[ne]=b(k);if(this.boundElement.insertBefore(E,this.listBottom),L!=null){let we=k[L],Yo=`${t}[${L}=${we}]`;Ho(E,Yo)}else{let we=`${t}[${h}]`;Ho(E,we)}}p.push(E)}let U=null;for(let h of p){if(h.previousElementSibling!==U)if(w++,U?.nextElementSibling!=null)this.boundElement.insertBefore(h,U.nextElementSibling);else this.boundElement.insertBefore(h,this.listBottom);U=h}if(j.perf)console.log(t,"updated",{removed:y,created:T,moved:w})}}var fe=(e,o,n)=>{let r=e[B];if(o&&r===void 0)r=new Xo(e,o,n),e[B]=r;return r},Ke=(e)=>{let o;while(!(o=e[ne])&&e&&e.parentElement)e=e.parentElement;return o?{element:e,item:o}:void 0},Re=(e)=>{let o=Ke(e);return o?o.item:void 0},fn=(e)=>{let o=Ke(e);if(!o)return console.error("deleteListItem failed, element is not part of a list instance",e),!1;let n=fe(o.element.parentElement);if(!n.options.idPath)return console.error("deleteListItem failed, list binding has no idPath",e.parentElement,n),!1;let r=n.array.indexOf(o.item);if(r>-1)return n.array.splice(r,1),!0;return!1};var{document:ee,MutationObserver:$o}=globalThis,Ve=(e,o)=>{let n=H.get(e);if(n==null)return;for(let r of n){let{binding:t,options:i}=r,{path:m}=r,{toDOM:s}=t;if(s!=null){if(m.startsWith("^")){let c=Re(e);if(c!=null&&c[C]!=null)m=r.path=`${c[C]}${m.substring(1)}`;else throw console.error(`Cannot resolve relative binding ${m}`,e,"is not part of a list"),Error(`Cannot resolve relative binding ${m}`)}if(o==null||m.startsWith(o))s(e,ie()[m],i)}}};if($o!=null)new $o((o)=>{o.forEach((n)=>{Array.from(n.addedNodes).forEach((r)=>{if(r instanceof Element)Array.from(r.querySelectorAll(D)).forEach((t)=>Ve(t))})})}).observe(ee.body,{subtree:!0,childList:!0});Q(()=>!0,(e)=>{let o=Array.from(ee.querySelectorAll(D));for(let n of o)Ve(n,e)});var zo=(e)=>{let o=e.target?.closest(D);while(o!=null){let n=H.get(o);for(let r of n){let{binding:t,path:i}=r,{fromDOM:m}=t;if(m!=null){let s;try{s=m(o,r.options)}catch(c){throw console.error("Cannot get value from",o,"via",r),Error("Cannot obtain value fromDOM")}if(s!=null){let c=ie(),l=c[i];if(l==null)c[i]=s;else{let a=l[C]!=null?l[F]:l,y=s[C]!=null?s[F]:s;if(a!==y)c[i]=y}}}}o=o.parentElement.closest(D)}};if(globalThis.document!=null)ee.body.addEventListener("change",zo,!0),ee.body.addEventListener("input",zo,!0);function g(e,o,n,r){if(e instanceof DocumentFragment)throw Error("bind cannot bind to a DocumentFragment");let t;if(typeof o==="object"&&o[C]===void 0&&r===void 0){let{value:s}=o;t=typeof s==="string"?s:s[C],r=o,delete r.value}else t=typeof o==="string"?o:o[C];if(t==null)throw Error("bind requires a path or object with xin Proxy");let{toDOM:i}=n;e.classList?.add(Ce);let m=H.get(e);if(m==null)m=[],H.set(e,m);if(m.push({path:t,binding:n,options:r}),i!=null&&!t.startsWith("^"))K(t);if(r?.filter&&r?.needle)g(e,r.needle,{toDOM(s,c){console.log({needle:c}),s[B]?.filter(c)}});return e}var Do=new Set,an=(e)=>{let o=e?.target?.closest(Ee),n=!1,r=new Proxy(e,{get(i,m){if(m==="stopPropagation")return()=>{e.stopPropagation(),n=!0};else{let s=i[m];return typeof s==="function"?s.bind(i):s}}}),t=new Set;while(!n&&o!=null){let m=W.get(o)[e.type]||t;for(let s of m){if(typeof s==="function")s(r);else{let c=ie()[s];if(typeof c==="function")c(r);else throw Error(`no event handler found at path ${s}`)}if(n)continue}o=o.parentElement!=null?o.parentElement.closest(Ee):null}};function I(e,o,n){let r=W.get(e);if(e.classList.add(be),r==null)r={},W.set(e,r);if(!r[o])r[o]=new Set;if(r[o].add(n),!Do.has(o))Do.add(o),ee.body.addEventListener(o,an,!0);return()=>{r[o].delete(n)}}io(g,I);var dn=0;function Ie(){return`custom-elt${(dn++).toString(36)}`}var Fo=0,oe={};function un(e,o){let n=oe[e],r=V(o).replace(/:host\b/g,e);oe[e]=n?n+`
10
+ `+r:r}function yn(e){if(oe[e])document.head.append(d.style({id:e+"-component"},oe[e]));delete oe[e]}class Y extends HTMLElement{static elements=d;static _elementCreator;instanceId;styleNode;static styleSpec;static styleNode;content=d.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"),d.style(V(e))}static elementCreator(e={}){let o=this;if(o._elementCreator==null){let{tag:n,styleSpec:r}=e,t=e!=null?n:null;if(t==null)if(typeof o.name==="string"&&o.name!==""){if(t=x(o.name),t.startsWith("-"))t=t.slice(1)}else t=Ie();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=Ie();while(customElements.get(t)!==void 0)t=Ie();if(o._tagName=t,r!==void 0)un(t,r);window.customElements.define(t,this,e),o._elementCreator=d[t]}return o._elementCreator}initAttributes(...e){let o={},n={};new MutationObserver((t)=>{let i=!1;if(t.forEach((m)=>{i=!!(m.attributeName&&e.includes(Co(m.attributeName)))}),i&&this.queueRender!==void 0)this.queueRender(!1)}).observe(this,{attributes:!0}),e.forEach((t)=>{o[t]=S(this[t]);let i=x(t);Object.defineProperty(this,t,{enumerable:!1,get(){if(typeof o[t]==="boolean")return this.hasAttribute(i);else if(this.hasAttribute(i))return typeof o[t]==="number"?parseFloat(this.getAttribute(i)):this.getAttribute(i);else if(n[t]!==void 0)return n[t];else return o[t]},set(m){if(typeof o[t]==="boolean"){if(m!==this[t]){if(m)this.setAttribute(i,"");else this.removeAttribute(i);this.queueRender()}}else if(typeof o[t]==="number"){if(m!==parseFloat(this[t]))this.setAttribute(i,m),this.queueRender()}else if(typeof m==="object"||`${m}`!==`${this[t]}`){if(m===null||m===void 0||typeof m==="object")this.removeAttribute(i);else this.setAttribute(i,m);this.queueRender(),n[t]=m}}})})}initValue(){let e=Object.getOwnPropertyDescriptor(this,"value");if(e===void 0||e.get!==void 0||e.set!==void 0)return;let o=this.hasAttribute("value")?this.getAttribute("value"):S(this.value);delete this.value,Object.defineProperty(this,"value",{enumerable:!1,get(){return o},set(n){if(o!==n)o=n,this.queueRender(!0)}})}_parts;get parts(){let e=this.shadowRoot!=null?this.shadowRoot:this;if(this._parts==null)this._parts=new Proxy({},{get(o,n){if(o[n]===void 0){let r=e.querySelector(`[part="${n}"]`);if(r==null)r=e.querySelector(n);if(r==null)throw Error(`elementRef "${n}" does not exist!`);r.removeAttribute("data-ref"),o[n]=r}return o[n]}});return this._parts}constructor(){super();Fo+=1,this.initAttributes("hidden"),this.instanceId=`${this.tagName.toLocaleLowerCase()}-${Fo}`,this._value=S(this.defaultValue)}connectedCallback(){if(yn(this.constructor.tagName),this.hydrate(),this.role!=null)this.setAttribute("role",this.role);if(this.onResize!==void 0){if(N.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(){N.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)$e(this,"change");this._changeQueued=!1,this._renderQueued=!1,this.render()})}_hydrated=!1;hydrate(){if(!this._hydrated){this.initValue();let e=typeof this.content!=="function",o=typeof this.content==="function"?this.content(d):this.content,{styleSpec:n}=this.constructor,{styleNode:r}=this.constructor;if(n)r=this.constructor.styleNode=d.style(V(n)),delete this.constructor.styleNode;if(this.styleNode)console.warn(this,"styleNode is deprecrated, use static styleNode or statc styleSpec instead"),r=this.styleNode;if(r){let t=this.attachShadow({mode:"open"});t.appendChild(r.cloneNode(!0)),ze(t,o,e)}else if(o!==null){let t=Array.from(this.childNodes);ze(this,o,e),this.isSlotted=this.querySelector("slot,xin-slot")!==void 0;let i=Array.from(this.querySelectorAll("slot"));if(i.length>0)i.forEach(Pe.replaceSlot);if(t.length>0){let m={"":this};Array.from(this.querySelectorAll("xin-slot")).forEach((s)=>{m[s.name]=s}),t.forEach((s)=>{let c=m[""],l=s instanceof Element?m[s.slot]:c;(l!==void 0?l:c).append(s)})}}this._hydrated=!0}}render(){}}class Pe extends Y{name="";content=null;static replaceSlot(e){let o=document.createElement("xin-slot");if(e.name!=="")o.setAttribute("name",e.name);e.replaceWith(o)}constructor(){super();this.initAttributes("name")}}var $r=Pe.elementCreator({tag:"xin-slot"});var hn=(e=()=>!0)=>{let o=localStorage.getItem("xin-state");if(o!=null){let r=JSON.parse(o);for(let t of Object.keys(r).filter(e))if(u[t]!==void 0)Object.assign(u[t],r[t]);else u[t]=r[t]}let n=De(()=>{let r={},t=b(u);for(let i of Object.keys(t).filter(e))r[i]=t[i];localStorage.setItem("xin-state",JSON.stringify(r)),console.log("xin state saved to localStorage")},500);Ue(e,n)};var Be="1.1.0";function ue(e){return Object.assign(P,e),P}function ye(e){return console.warn("boxedProxy is deprecated, please use tosi() instead"),ue(e)}function _e(e,o=!1){if(o)return console.warn("xinProxy(..., true) is deprecated; use tosi(...) instead"),ye(e);return Object.keys(e).forEach((n)=>{u[n]=e[n]}),u}var pn={};async function he(e,o){let{type:n,styleSpec:r}=await o(e,{Color:f,Component:Y,elements:d,svgElements:Ze,mathML:Ae,varDefault:ae,vars:qe,xin:u,boxed:P,xinProxy:_e,boxedProxy:ye,tosi:ue,makeComponent:he,bind:g,on:I,version:Be}),t={type:n,creator:n.elementCreator({tag:e,styleSpec:r})};return pn[e]=t,t}var Ne={},wn=(e)=>import(e);class pe extends Y{tag="anon-elt";src="";property="default";loaded;blueprintLoaded=(e)=>{};async packaged(){let{tag:e,src:o,property:n}=this,r=`${e}.${n}:${o}`;if(!this.loaded){if(Ne[r]===void 0)Ne[r]=wn(o).then((t)=>{let i=t[n];return he(e,i)});else console.log(`using cached ${e} with signature ${r}`);this.loaded=await Ne[r],this.blueprintLoaded(this.loaded)}return this.loaded}constructor(){super();this.initAttributes("tag","src","property")}}var Cn=pe.elementCreator({tag:"xin-blueprint",styleSpec:{":host":{display:"none"}}});class eo extends Y{allLoaded=()=>{};constructor(){super()}async load(){let o=Array.from(this.querySelectorAll(pe.tagName)).filter((n)=>n.src).map((n)=>n.packaged());await Promise.all(o),this.allLoaded()}connectedCallback(){super.connectedCallback(),this.load()}}var bn=eo.elementCreator({tag:"xin-loader",styleSpec:{":host":{display:"none"}}});export{b as xinValue,_e as xinProxy,X as xinPath,u as xin,Be as version,qe as vars,ae as varDefault,ro as updates,q as unobserve,Ve as touchElement,K as touch,ue as tosi,me as throttle,Ze as svgElements,j as settings,I as on,Ue as observe,Ae as mathML,he as makeComponent,_o as invertLuminance,Bo as initVars,hn as hotReload,Re as getListItem,Ke as getListInstance,fe as getListBinding,Je as getCssVar,d as elements,fn as deleteListItem,De as debounce,V as css,ye as boxedProxy,P as boxed,bn as blueprintLoader,Cn as blueprint,le as bindings,g as bind,Vo as StyleSheet,Ko as MoreMath,Y as Component,f as Color,eo as BlueprintLoader,pe as Blueprint};
11
11
 
12
- //# debugId=D83C5C39D6BE877264756E2164756E21
12
+ //# debugId=4591CFE7CF413B4464756E2164756E21
13
13
  //# sourceMappingURL=module.js.map