tosijs 1.0.3
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/LICENSE +29 -0
- package/README.md +385 -0
- package/dist/bind.d.ts +9 -0
- package/dist/bindings.d.ts +4 -0
- package/dist/blueprint-loader.d.ts +19 -0
- package/dist/by-path.d.ts +8 -0
- package/dist/color.d.ts +46 -0
- package/dist/component.d.ts +37 -0
- package/dist/css-colors.d.ts +3 -0
- package/dist/css-system-color.d.ts +1 -0
- package/dist/css-types.d.ts +250 -0
- package/dist/css.d.ts +22 -0
- package/dist/deep-clone.d.ts +5 -0
- package/dist/dom.d.ts +9 -0
- package/dist/elements.d.ts +142 -0
- package/dist/get-css-var.d.ts +1 -0
- package/dist/hot-reload.d.ts +2 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +33 -0
- package/dist/list-binding.d.ts +37 -0
- package/dist/main.js +13 -0
- package/dist/main.js.map +33 -0
- package/dist/make-component.d.ts +39 -0
- package/dist/make-error.d.ts +1 -0
- package/dist/metadata.d.ts +32 -0
- package/dist/module.js +13 -0
- package/dist/module.js.map +33 -0
- package/dist/more-math.d.ts +10 -0
- package/dist/object-property-list.d.ts +8 -0
- package/dist/path-listener.d.ts +13 -0
- package/dist/settings.d.ts +4 -0
- package/dist/string-case.d.ts +2 -0
- package/dist/throttle.d.ts +4 -0
- package/dist/version.d.ts +1 -0
- package/dist/xin-proxy.d.ts +4 -0
- package/dist/xin-types.d.ts +111 -0
- package/dist/xin.d.ts +16 -0
- package/package.json +71 -0
package/dist/main.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var{defineProperty:Tn,getOwnPropertyNames:Ce,getOwnPropertyDescriptor:Me}=Object,De=Object.prototype.hasOwnProperty;var Vn=new WeakMap,Fe=(n)=>{var e=Vn.get(n),o;if(e)return e;if(e=Tn({},"__esModule",{value:!0}),n&&typeof n==="object"||typeof n==="function")Ce(n).map((t)=>!De.call(e,t)&&Tn(e,t,{get:()=>n[t],enumerable:!(o=Me(n,t))||o.enumerable}));return Vn.set(n,e),e};var Le=(n,e)=>{for(var o in e)Tn(n,o,{get:e[o],enumerable:!0,configurable:!0,set:(t)=>e[o]=()=>t})};var fo={};Le(fo,{xinValue:()=>y,xinProxy:()=>bn,xinPath:()=>S,xin:()=>d,version:()=>hn,vars:()=>xn,varDefault:()=>R,updates:()=>Dn,unobserve:()=>Y,touchElement:()=>fn,touch:()=>z,tosi:()=>Yn,throttle:()=>Z,svgElements:()=>yn,settings:()=>M,on:()=>F,observe:()=>q,mathML:()=>mn,makeComponent:()=>en,invertLuminance:()=>Xe,initVars:()=>we,hotReload:()=>Ee,getListItem:()=>sn,getCssVar:()=>un,elements:()=>p,debounce:()=>an,css:()=>j,boxedProxy:()=>nn,boxed:()=>A,blueprintLoader:()=>ke,blueprint:()=>Se,bindings:()=>K,bind:()=>m,StyleSheet:()=>be,MoreMath:()=>pe,Component:()=>C,Color:()=>a,BlueprintLoader:()=>gn,Blueprint:()=>on});module.exports=Fe(fo);var M={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 En="-xin-data",D=`.${En}`,Sn="-xin-event",kn=`.${Sn}`,h="xinPath",B="xinValue",qn="xinObserve",Jn="xinBind",Un="xinOn",S=(n)=>{return n&&n[h]||void 0};function y(n){return typeof n==="object"&&n!==null?n[B]||n:n}var O=new WeakMap,E=new WeakMap;var H=(n)=>{let e=n.cloneNode();if(e instanceof Element){let o=E.get(n),t=O.get(n);if(o!=null)E.set(e,T(o));if(t!=null)O.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(H(o));else e.appendChild(o.cloneNode());return e},U=new WeakMap,sn=(n)=>{let e=document.body.parentElement;while(n.parentElement!=null&&n.parentElement!==e){let o=U.get(n);if(o!=null)return o;n=n.parentElement}return!1};var Gn=Symbol("observer should be removed"),cn=[],ln=[],vn=!1,Cn,Mn;class Zn{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");cn.push(this)}}var Dn=async()=>{if(Cn===void 0)return;await Cn},Oe=()=>{if(M.perf)console.time("xin async update");let n=Array.from(ln);for(let e of n)cn.filter((o)=>{let t;try{t=o.test(e)}catch(i){throw new Error(`Listener ${o.description} threw "${i}" at "${e}"`)}if(t===Gn)return Y(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===Gn)Y(o)});if(ln.splice(0),vn=!1,typeof Mn==="function")Mn();if(M.perf)console.timeEnd("xin async update")},z=(n)=>{let e=typeof n==="string"?n:S(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(vn===!1)Cn=new Promise((o)=>{Mn=o}),vn=setTimeout(Oe);if(ln.find((o)=>e.startsWith(o))==null)ln.push(e)},Fn=(n,e)=>{return new Zn(n,e)},Y=(n)=>{let e=cn.indexOf(n);if(e>-1)cn.splice(e,1);else throw new Error("unobserve failed, listener not found")};var Be=(n)=>{try{return JSON.stringify(n)}catch(e){return"{has circular references}"}},Ln=(...n)=>new Error(n.map(Be).join(" "));var He=()=>new Date(parseInt("1000000000",36)+Date.now()).valueOf().toString(36).slice(1),ze=0,$e=()=>(parseInt("10000",36)+ ++ze).toString(36).slice(-5),Ae=()=>He()+$e(),On={},Rn={};function Nn(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 k=new WeakMap;function ne(n,e){if(k.get(n)===void 0)k.set(n,{});if(k.get(n)[e]===void 0)k.get(n)[e]={};let o=k.get(n)[e];if(e==="_auto_")n.forEach((t,i)=>{if(t._auto_===void 0)t._auto_=Ae();o[t._auto_+""]=i});else n.forEach((t,i)=>{o[_(t,e)+""]=i});return o}function Pe(n,e){if(k.get(n)===void 0||k.get(n)[e]===void 0)return ne(n,e);else return k.get(n)[e]}function je(n,e,o){o=o+"";let t=Pe(n,e)[o];if(t===void 0||_(n[t],e)+""!==o)t=ne(n,e)[o];return t}function We(n,e,o){if(n[e]===void 0&&o!==void 0)n[e]=o;return n[e]}function ee(n,e,o,t){let i=e!==""?je(n,e,o):o;if(t===On)return n.splice(i,1),k.delete(n),Symbol("deleted");else if(t===Rn){if(e===""&&n[i]===void 0)n[i]={}}else if(t!==void 0)if(i!==void 0)n[i]=t;else if(e!==""&&_(t,e)+""===o+"")n.push(t),i=n.length-1;else throw new Error(`byIdPath insert failed at [${e}=${o}]`);return n[i]}function Qn(n){if(!Array.isArray(n))throw Ln("setByPath failed: expected array, found",n)}function Kn(n){if(n==null||!(n instanceof Object))throw Ln("setByPath failed: expected Object, found",n)}function _(n,e){let o=Nn(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=ee(t,f,w.join("="))}else r=parseInt(l,10),t=t[r]}return t}function oe(n,e,o){let t=n,i=Nn(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)Kn(t);else Qn(t);let c=s.slice(0,r),l=s.slice(r+1);if(t=ee(t,c,l,i.length>0?Rn:o),i.length===0)return!0}else{Qn(t);let c=parseInt(s,10);if(i.length>0)t=t[c];else{if(o!==On){if(t[c]===o)return!1;t[c]=o}else t.splice(c,1);return!0}}}else if(Array.isArray(s)&&s.length>0){Kn(t);while(s.length>0){let r=s.shift();if(s.length>0||i.length>0)t=We(t,r,s.length>0?{}:[]);else{if(o!==On){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 Ie=["sort","splice","copyWithin","fill","pop","push","reverse","shift","unshift"],Hn={},Ye=!0,_e=/^\.?([^.[\](),])+(\.[^.[\](),]+|\[\d+\]|\[[^=[\](),]*=[^[\]()]+\])*$/,Ve=(n)=>_e.test(n),$=(n="",e="")=>{if(n==="")return e;else if(e.match(/^\d+$/)!==null||e.includes("="))return`${n}[${e}]`;else return`${n}.${e}`},qe={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 Bn(n,e){let o=typeof n;if(n===void 0||o==="object"||o==="function")return n;else return new Proxy(qe[typeof n](n),V(e,!0))}var V=(n,e)=>({get(o,t){switch(t){case h:return n;case B:return o.valueOf?o.valueOf():o;case qn:return(r)=>{let c=Fn(n,r);return()=>Y(c)};case Un:return(r,c)=>F(r,c,y(o));case Jn:return(r,c,l)=>{m(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=$(n,r),f=_(o,r);return f!==null&&typeof f==="object"?new Proxy(f,V(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)=>`${_(f,c)}`===l)}else r=o[i];if(r instanceof Object){let c=$(n,i);return new Proxy(r instanceof Function?r.bind(o):r,V(c,e))}else return e?Bn(r,$(n,i)):r}else if(Array.isArray(o)){let r=o[i];return typeof r==="function"?(...c)=>{let l=r.apply(o,c);if(Ie.includes(i))z(n);return l}:typeof r==="object"?new Proxy(r,V($(n,i),e)):e?Bn(r,$(n,i)):r}else return e?Bn(o[i],$(n,i)):o[i]},set(o,t,i){i=y(i);let s=t!==B?$(n,t):n;if(Ye&&!Ve(s))throw new Error(`setting invalid path ${s}`);if(y(d[s])!==i&&oe(Hn,s,i))z(s);return!0}}),q=(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 Fn(n,o)},d=new Proxy(Hn,V("",!1)),A=new Proxy(Hn,V("",!0));var zn=(n,e)=>{let o=new Event(e);n.dispatchEvent(o)},ie=(n)=>{if(n instanceof HTMLInputElement)return n.type;else if(n instanceof HTMLSelectElement&&n.hasAttribute("multiple"))return"multi-select";else return"other"},re=(n,e)=>{switch(ie(n)){case"radio":n.checked=n.value===e;break;case"checkbox":n.checked=!!e;break;case"date":n.valueAsDate=new Date(e);break;case"multi-select":for(let o of Array.from(n.querySelectorAll("option")))o.selected=e[o.value];break;default:n.value=e}},se=(n)=>{switch(ie(n)){case"radio":{let e=n.parentElement?.querySelector(`[name="${n.name}"]:checked`);return e!=null?e.value:null}case"checkbox":return n.checked;case"date":return n.valueAsDate?.toISOString();case"multi-select":return Array.from(n.querySelectorAll("option")).reduce((e,o)=>{return e[o.value]=o.selected,e},{});default:return n.value}},{ResizeObserver:te}=globalThis,G=te!=null?new te((n)=>{for(let e of n){let o=e.target;zn(o,"resize")}}):{observe(){},unobserve(){}},$n=(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?H(t):t)});else if(e instanceof Node)n.append(o?H(e):e);else throw new Error("expect text content or document node")};var an=(n,e=250)=>{let o;return(...t)=>{if(o!==void 0)clearTimeout(o);o=setTimeout(()=>{n(...t)},e)}},Z=(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 dn=Symbol("list-binding"),Je=16,Ue=100;function ce(n,e){let o=Array.from(n.querySelectorAll(D));if(n.matches(D))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 le{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=H(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=Z(()=>{this.update(this._array,!0)},Je),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,W=Math.ceil(f/n.height)+1,I=Math.ceil(t.length/w),tn=w*W,L=Math.floor(this.boundElement.scrollTop/n.height);if(L>I-W+1)L=Math.max(0,I-W+1);i=L*w,s=i+tn-1,r=L*n.height,c=Math.max(I*n.height-f-r,0)}return{items:t,firstItem:i,lastItem:s,topBuffer:r,bottomBuffer:c}}needle;filter=Z((n)=>{if(this.needle!==n)this.needle=n,this.update(this._array)},Ue);update(n,e){if(n==null)n=[];this._array=n;let{hiddenProp:o,visibleProp:t}=this.options,i=S(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 W=0,I=0,tn=0;for(let u of Array.from(this.boundElement.children)){if(u===this.listTop||u===this.listBottom)continue;let X=U.get(u);if(X==null)u.remove();else{let x=s.items.indexOf(X);if(x<c||x>l)u.remove(),this.itemToElement.delete(X),U.delete(u),W++}}this.listTop.style.height=String(f)+"px",this.listBottom.style.height=String(w)+"px";let L=[],{idPath:wn}=this.options;for(let u=c;u<=l;u++){let X=s.items[u];if(X===void 0)continue;let x=this.itemToElement.get(y(X));if(x==null){if(tn++,x=H(this.template),typeof X==="object")this.itemToElement.set(y(X),x),U.set(x,y(X));if(this.boundElement.insertBefore(x,this.listBottom),wn!=null){let Xn=X[wn],ve=`${i}[${wn}=${Xn}]`;ce(x,ve)}else{let Xn=`${i}[${u}]`;ce(x,Xn)}}L.push(x)}let rn=null;for(let u of L){if(u.previousElementSibling!==rn)if(I++,rn?.nextElementSibling!=null)this.boundElement.insertBefore(u,rn.nextElementSibling);else this.boundElement.insertBefore(u,this.listBottom);rn=u}if(M.perf)console.log(i,"updated",{removed:W,created:tn,moved:I})}}var ae=(n,e,o)=>{let t=n[dn];if(t===void 0)t=new le(n,e,o),n[dn]=t;return t};var{document:Q,MutationObserver:de}=globalThis,fn=(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=sn(n);if(l!=null&&l[h]!=null)r=t.path=`${l[h]}${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(de!=null)new de((e)=>{e.forEach((o)=>{Array.from(o.addedNodes).forEach((t)=>{if(t instanceof Element)Array.from(t.querySelectorAll(D)).forEach((i)=>fn(i))})})}).observe(Q.body,{subtree:!0,childList:!0});q(()=>!0,(n)=>{let e=Array.from(Q.querySelectorAll(D));for(let o of e)fn(o,n)});var fe=(n)=>{let e=n.target.closest(D);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[h]!=null?l[B]:l,w=c[h]!=null?c[B]:c;if(f!==w)d[s]=w}}}}e=e.parentElement.closest(D)}};if(globalThis.document!=null)Q.body.addEventListener("change",fe,!0),Q.body.addEventListener("input",fe,!0);function m(n,e,o,t){if(n instanceof DocumentFragment)throw new Error("bind cannot bind to a DocumentFragment");let i;if(typeof e==="object"&&e[h]===void 0&&t===void 0){let{value:c}=e;i=typeof c==="string"?c:c[h],t=e,delete t.value}else i=typeof e==="string"?e:e[h];if(i==null)throw new Error("bind requires a path or object with xin Proxy");let{toDOM:s}=o;n.classList?.add(En);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("^"))z(i);if(t?.filter&&t?.needle)m(n,t.needle,{toDOM(c,l){console.log({needle:l}),c[dn]?.filter(l)}});return n}var ue=new Set,Ge=(n)=>{let e=n?.target.closest(kn),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=O.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(kn):null}};function F(n,e,o){let t=O.get(n);if(n.classList.add(Sn),t==null)t={},O.set(n,t);if(!t[e])t[e]=new Set;if(t[e].add(o),!ue.has(e))ue.add(e),Q.body.addEventListener(e,Ge,!0);return()=>{t[e].delete(o)}}var K={value:{toDOM:re,fromDOM(n){return se(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){ae(n,e,o).update(e)}}};var Ze=180/Math.PI,Qe=Math.PI/180;function b(n,e,o){return o<n?NaN:e<n?n:e>o?o:e}function v(n,e,o,t=!0){if(t)o=b(0,o,1);return o*(e-n)+n}var pe={RADIANS_TO_DEGREES:Ze,DEGREES_TO_RADIANS:Qe,clamp:b,lerp:v};function un(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 Ke=(n,e,o)=>{return(0.299*n+0.587*e+0.114*o)/255},P=(n)=>("00"+Math.round(Number(n)).toString(16)).slice(-2);class ye{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 J=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(un(n,e))}static fromCss(n){let e=n;if(J instanceof HTMLSpanElement)J.style.color="black",J.style.color=n,document.body.appendChild(J),e=getComputedStyle(J).color,J.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 ye(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 Ke(this.r,this.g,this.b)}get html(){return this.toString()}toString(){return this.a===1?"#"+P(this.r)+P(this.g)+P(this.b):"#"+P(this.r)+P(this.g)+P(this.b)+P(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(v(this.r,n.r,e),v(this.g,n.g,e),v(this.b,n.b,e),v(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),v(o.s,t.s,e),v(o.l,t.l,e),v(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 me(n){return n.replace(/-([a-z])/g,(e,o)=>{return o.toLocaleUpperCase()})}var Re="http://www.w3.org/1998/Math/MathML",Ne="http://www.w3.org/2000/svg",pn={},xe=(n,e,o)=>{let t=jn(g(e),o);if(t.prop.startsWith("--"))n.style.setProperty(t.prop,t.value);else n.style[e]=t.value},no=(n)=>{return{toDOM(e,o){xe(e,n,o)}}},he=(n,e,o)=>{if(e==="style")if(typeof o==="object")for(let t of Object.keys(o))if(S(o[t]))m(n,o[t],no(t));else xe(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)}},eo=(n)=>{return{toDOM(e,o){he(e,n,o)}}},oo=(n,e,o)=>{if(e==="apply")o(n);else if(e.match(/^on[A-Z]/)!=null){let t=e.substring(2).toLowerCase();F(n,t,o)}else if(e==="bind")if((typeof o.binding==="string"?K[o.binding]:o.binding)!==void 0&&o.value!==void 0)m(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=K[t];if(i!==void 0)m(n,o,i);else throw new Error(`${e} is not allowed, bindings.${t} is not defined`)}else if(S(o))m(n,o,eo(e));else he(n,e,o)},An=(n,...e)=>{if(pn[n]===void 0){let[i,s]=n.split("|");if(s===void 0)pn[n]=globalThis.document.createElement(i);else pn[n]=globalThis.document.createElementNS(s,i)}let o=pn[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];oo(o,i,s)}return o},Pn=(...n)=>{let e=globalThis.document.createDocumentFragment();for(let o of n)e.append(o);return e},p=new Proxy({fragment:Pn},{get(n,e){if(e=e.replace(/[A-Z]/g,(o)=>`-${o.toLocaleLowerCase()}`),n[e]===void 0)n[e]=(...o)=>An(e,...o);return n[e]},set(){throw new Error("You may not add new properties to elements")}}),yn=new Proxy({fragment:Pn},{get(n,e){if(n[e]===void 0)n[e]=(...o)=>An(`${e}|${Ne}`,...o);return n[e]},set(){throw new Error("You may not add new properties to elements")}}),mn=new Proxy({fragment:Pn},{get(n,e){if(n[e]===void 0)n[e]=(...o)=>An(`${e}|${Re}`,...o);return n[e]},set(){throw new Error("You may not add new properties to elements")}});function be(n,e){let o=p.style(j(e));o.id=n,document.head.append(o)}var to=["animation-iteration-count","flex","flex-base","flex-grow","flex-shrink","opacity","order","tab-size","widows","z-index","zoom"],jn=(n,e)=>{if(typeof e==="number"&&!to.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)}},io=(n,e,o)=>{if(o===void 0)return"";if(o instanceof a)o=o.html;let t=jn(e,o);return`${n} ${t.prop}: ${t.value};`},ge=(n,e,o="")=>{let t=g(n);if(typeof e==="object"&&!(e instanceof a)){let i=Object.keys(e).map((s)=>ge(s,e[s],`${o} `)).join(`
|
|
2
|
+
`);return`${o} ${n} {
|
|
3
|
+
${i}
|
|
4
|
+
${o} }`}else return io(o,t,e)},j=(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)=>ge(r,i[r])).join(`
|
|
5
|
+
`);return`${e}${t} {
|
|
6
|
+
${s}
|
|
7
|
+
}`}).join(`
|
|
8
|
+
|
|
9
|
+
`)},we=(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},Xe=(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},R=new Proxy({},{get(n,e){if(n[e]===void 0){let o="--"+g(e);n[e]=(t)=>`var(${o}, ${t})`}return n[e]}}),xn=new Proxy({},{get(n,e){if(e==="default")return R;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 ro=0;function Wn(){return`custom-elt${(ro++).toString(36)}`}var Te=0,N={};function so(n,e){let o=N[n],t=j(e).replace(/:host\b/g,n);N[n]=o?o+`
|
|
10
|
+
`+t:t}function co(n){if(N[n])document.head.append(p.style({id:n+"-component"},N[n]));delete N[n]}class C 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(j(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=Wn();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=Wn();while(customElements.get(t)!==void 0)t=Wn();if(this._tagName=t,o!==void 0)so(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(me(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();Te+=1,this.initAttributes("hidden"),this.instanceId=`${this.tagName.toLocaleLowerCase()}-${Te}`,this._value=T(this.defaultValue)}connectedCallback(){if(co(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)zn(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(j(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)),$n(i,e,n)}else if(e!==null){let i=Array.from(this.childNodes);$n(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(In.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 In extends C{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 bt=In.elementCreator({tag:"xin-slot"});var Ee=(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=an(()=>{let t={},i=y(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);q(n,o)};var hn="1.0.3";function Yn(n){return Object.assign(A,n),A}function nn(n){return console.warn("boxedProxy is deprecated, please use tosi() instead"),Yn(n)}function bn(n,e=!1){if(e)return console.warn("xinProxy(..., true) is deprecated; use tosi(...) instead"),nn(n);return Object.keys(n).forEach((o)=>{d[o]=n[o]}),d}var lo={};async function en(n,e){let{type:o,styleSpec:t}=await e(n,{Color:a,Component:C,elements:p,svgElements:yn,mathML:mn,varDefault:R,vars:xn,xin:d,boxed:A,xinProxy:bn,boxedProxy:nn,makeComponent:en,bind:m,on:F,version:hn}),i={type:o,creator:o.elementCreator({tag:n,styleSpec:t})};return lo[n]=i,i}var _n={},ao=(n)=>import(n);class on extends C{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(_n[t]===void 0)_n[t]=ao(e).then((i)=>{let s=i[o];return en(n,s)});else console.log(`using cached ${n}`);this.loaded=await _n[t],this.blueprintLoaded(this.loaded)}return this.loaded}constructor(){super();this.initAttributes("tag","src","property")}}var Se=on.elementCreator({tag:"xin-blueprint",styleSpec:{":host":{display:"none"}}});class gn extends C{allLoaded=()=>{};constructor(){super()}async load(){let e=Array.from(this.querySelectorAll(on.tagName)).filter((o)=>o.src).map((o)=>o.packaged());await Promise.all(e),this.allLoaded()}connectedCallback(){super.connectedCallback(),this.load()}}var ke=gn.elementCreator({tag:"xin-loader",styleSpec:{":host":{display:"none"}}});
|
|
11
|
+
|
|
12
|
+
//# debugId=E6D29AC82798A0F764756E2164756E21
|
|
13
|
+
//# sourceMappingURL=main.js.map
|