@ixfx/ui 0.40.3 → 0.42.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.
@@ -0,0 +1,2 @@
1
+ import{__export as e}from"./chunk-Cl8Af3a2.js";function t(...e){for(let t of e){let e=typeof t==`object`?t:t();if(e===void 0||e.success)continue;throw r(e)}return!0}function n(e){return typeof e==`object`?!e.success:!1}function r(e){if(typeof e.error==`string`)throw Error(e.error,{cause:e.info});if(e.error instanceof Error)throw e.error;return Error(JSON.stringify(e.error),{cause:e.info})}const i=(...e)=>{let t;for(let n of e){if(t=typeof n==`object`?n:n(),t===void 0)continue;if(!t.success)return t}if(!t)throw Error(`No results`);return t},a=(e,t=``,n=`?`,r)=>{if(e===null)return{success:!1,error:`Parameter '${n}' is null`,info:r};if(e===void 0)return{success:!1,error:`Parameter '${n}' is undefined`,info:r};if(Number.isNaN(e))return{success:!1,error:`Parameter '${n}' is NaN`,info:r};if(typeof e!=`number`)return{success:!1,error:`Parameter '${n}' is not a number (${JSON.stringify(e)})`,info:r};switch(t){case`finite`:if(!Number.isFinite(e))return{success:!1,error:`Parameter '${n} must be finite (Got: ${e})`,info:r};break;case`positive`:if(e<0)return{success:!1,error:`Parameter '${n}' must be at least zero (${e})`,info:r};break;case`negative`:if(e>0)return{success:!1,error:`Parameter '${n}' must be zero or lower (${e})`,info:r};break;case`aboveZero`:if(e<=0)return{success:!1,error:`Parameter '${n}' must be above zero (${e})`,info:r};break;case`belowZero`:if(e>=0)return{success:!1,error:`Parameter '${n}' must be below zero (${e})`,info:r};break;case`percentage`:if(e>1||e<0)return{success:!1,error:`Parameter '${n}' must be in percentage range (0 to 1). (${e})`,info:r};break;case`nonZero`:if(e===0)return{success:!1,error:`Parameter '${n}' must non-zero. (${e})`,info:r};break;case`bipolar`:if(e>1||e<-1)return{success:!1,error:`Parameter '${n}' must be in bipolar percentage range (-1 to 1). (${e})`,info:r};break}return{success:!0,value:e,info:r}},o=(e,t=`?`,n)=>a(e,`percentage`,t,n),s=(e,t=``,n=`?`)=>i(a(e,t,n),()=>Number.isInteger(e)?{success:!0,value:e}:{success:!1,error:`Param '${n}' is not an integer`}),c=(e,t,n,r=`?`)=>typeof e==`number`?Number.isNaN(e)?{success:!1,error:`Param '${r}' is not within range ${t}-${n}. Got: NaN`}:Number.isFinite(e)?e<t?{success:!1,error:`Param '${r}' is below range ${t}-${n}. Got: ${e}`}:e>n?{success:!1,error:`Param '${r}' is above range ${t}-${n}. Got: ${e}`}:{success:!0,value:e}:{success:!1,error:`Param '${r}' is not within range ${t}-${n}. Got: infinite`}:{success:!1,error:`Param '${r}' is not a number type. Got type: '${typeof e}' value: '${JSON.stringify(e)}'`},l=e=>{if(typeof e!=`object`||!e)return{success:!1,error:`Value is null or not object type`};let t=Object.getPrototypeOf(e),n=(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e);return n?{success:!0,value:e}:{success:!1,error:`Fancy object`}},u=e=>{let t=typeof e;return t===`symbol`?{success:!1,error:`Symbol type`}:t===`function`?{success:!1,error:`Function type`}:t===`bigint`||t===`number`||t===`string`||t===`boolean`?{success:!0,value:e}:l(e)},d=(e,n,r={})=>{let i=y(n,0);t(s(i,`positive`,`interval`));let a=r.fireBeforeWait??!1,o=r.onStartCalled,c=r.signal,l=!1,u=`idle`,d=0,f=0,p=performance.now(),m=n??0,h=!1,g,_=()=>{g!==void 0&&(globalThis.clearTimeout(g),g=void 0,d=0,p=NaN)},ee=e=>{i===0?typeof requestAnimationFrame>`u`?g=globalThis.setTimeout(e,0):(g=void 0,requestAnimationFrame(e)):g=globalThis.setTimeout(e,i)},v=()=>{h||(h=!0,u!==`idle`&&(u=`idle`,_()))},te=async()=>{if(c?.aborted&&(u=`idle`),u===`idle`)return;u=`running`,d++,f++;let t=e(d,performance.now()-p),n=typeof t==`object`?await t:t;if(!h){if(u=`scheduled`,n!==void 0&&!n){v();return}h||ee(te)}},ne=()=>{if(l)throw Error(`Disposed`);if(h=!1,o!==void 0){let e=o(d,performance.now()-p);switch(e){case`cancel`:v();return;case`reset`:re();return;case`dispose`:l=!0,v();return}}u===`idle`&&(d=0,p=performance.now(),u=`scheduled`,a?te():ee(te))},re=()=>{if(l)throw Error(`Disposed`);h=!1,d=0,p=NaN,u!==`idle`&&v(),ne()};return{start:ne,reset:re,cancel:v,get interval(){return m},get runState(){return u},get startCountTotal(){return f},get startCount(){return d},set interval(e){let n=y(e,0);t(s(n,`positive`,`interval`)),i=n,m=e},get isDisposed(){return l},get elapsedMs(){return performance.now()-p}}},f=()=>{let e=performance.now();return()=>{let t=performance.now(),n=t-e;return e=t,n}};function*p(e,t=`.`){for(;e.length>0;){yield e;let n=g(e,t);if(n===e)break;e=n}}function*m(e,t=`.`){for(;e.length>0;){yield e;let n=h(e,t,{ifNoMatch:`original`,fromEnd:!0});if(n===e)break;e=n}}const h=(e,t,n={})=>{let r=_(e,t,n);return r[0]},g=(e,t,n={})=>{let r=_(e,t,n);return r[1]},_=(e,t,n={})=>{if(e===void 0)throw Error(`Param 'source' is undefined`);let r=n.fallback,i=n.ifNoMatch??(r?`fallback`:`original`);if(i===`original`&&(r=e),i===`fallback`&&r===void 0)throw Error(`Fallback must be provided`);let a=n.startPos??void 0,o=n.fromEnd??!1,s=o?e.lastIndexOf(t,a):e.indexOf(t,a);if(s<0&&i===`throw`)throw Error(`Match '${t}' not found in source.`);return s<0&&i===`original`?[e,e]:s<0&&i===`fallback`?[r,r]:[e.slice(0,s),e.slice(Math.max(0,s+t.length))]},ee=e=>{let t=e=>e.replaceAll(/([!$()*+./:=?[\\\]^{|}])/g,`\\$1`);e=e.split(`*`).map(e=>t(e)).join(`.*`),e=`^`+e+`$`;let n=new RegExp(e);return e=>n.test(e)},v=(e,t)=>e===t,te=(e,t,n)=>JSON.stringify(e)===JSON.stringify(t),ne=e=>{if(e===void 0)return!1;if(typeof e==`string`){let t=Number.parseInt(e);return Number.isNaN(t)?!1:t.toString()===e.toString()}return typeof e==`number`?Number.isNaN(e)||!Number.isFinite(e)?!1:Math.round(e)===e:!1};function re(e){return typeof e==`number`||typeof e==`string`||typeof e==`bigint`||typeof e==`boolean`}const ie=(e,t,n=v)=>{let r=[],i=[],a=[];for(let a of e){let e=!1;for(let r of t)if(n(a,r)){e=!0;break}e?r.push(a):i.push(a)}for(let r of t){let t=!1;for(let i of e)n(r,i)&&(t=!0);t||a.push(r)}let o=i.length===0&&a.length===0;return{shared:r,isSame:o,a:i,b:a}};function y(e,t){if(ae(e)){if(typeof e==`number`)return e;let t=e.millis??0;return t+=(e.hours??0)*60*60*1e3,t+=(e.mins??0)*60*1e3,t+=(e.secs??0)*1e3,t}else{if(t!==void 0)return t;throw Error(`Not a valid interval: ${JSON.stringify(e)}`)}}function ae(e){if(e==null)return!1;if(typeof e==`number`)return!(Number.isNaN(e)||!Number.isFinite(e));if(typeof e!=`object`)return!1;let t=`millis`in e,n=`secs`in e,r=`mins`in e,i=`hours`in e;return t&&!a(e.millis).success||n&&!a(e.secs).success||r&&!a(e.mins).success||i&&!a(e.hours).success?!1:!!(t||n||i||r)}const oe=e=>typeof e==`string`?e:e instanceof Error?e.message:e;(typeof window>`u`||!(`requestAnimationFrame`in window))&&typeof window>`u`&&(globalThis.requestAnimationFrame=e=>{setTimeout(e,1)});const se=e=>{let n=y(e,1),r=e.signal,i=e.value;return t(a(n,`positive`,`timeoutMs`)),n===0?new Promise(e=>requestAnimationFrame(t=>{e(i)})):new Promise((e,t)=>{let a=()=>{clearTimeout(o),r?(r.removeEventListener(`abort`,a),t(Error(r.reason))):t(Error(`Cancelled`))};r&&r.addEventListener(`abort`,a);let o=setTimeout(()=>{if(r?.removeEventListener(`abort`,a),r?.aborted){t(Error(r.reason));return}e(i)},n)})},ce=(e,t)=>{let n=ie(Object.keys(e),Object.keys(t));return n},le=(e,t)=>{if(e===void 0)throw Error(`Param 'target' is undefined`);if(e===null)throw Error(`Param 'target' is null`);if(typeof e!=`object`)throw Error(`Param 'target' is not an object (got: ${typeof e})`);if(t){let t=[];for(let n in e){let r=e[n];u(r)&&t.push([n,r])}return t}else return Object.entries(e)};function*ue(e,t,n={}){if(e===void 0){yield{path:n.pathPrefix??``,value:t,state:`added`};return}if(t===void 0){yield{path:n.pathPrefix??``,previous:e,value:void 0,state:`removed`};return}let r=n.asPartial??!1,i=n.undefinedValueMeansRemoved??!1,a=n.pathPrefix??``,o=n.deepEntries??!1,s=n.eq??te,c=n.includeMissingFromA??!1,l=n.includeParents??!1;if(re(e)&&re(t)){e!==t&&(yield{path:a,value:t,previous:e,state:`change`});return}if(re(t)){yield{path:a,value:t,previous:e,state:`change`};return}let u=le(e,o),d=new Set;for(let[e,o]of u){d.add(e);let c=e in t,u=t[e];if(typeof o==`object`&&o)if(c){if(u===void 0)throw Error(`Pathed.compareData Value for key ${e} is undefined`);{let r=[...ue(o,u,{...n,pathPrefix:a+e+`.`})];if(r.length>0){for(let e of r)yield e;l&&(yield{path:a+e,value:t[e],previous:o,state:`change`})}}}else{if(r)continue;yield{path:a+e,value:void 0,previous:o,state:`removed`}}else{let t=a+e;if(c)u===void 0&&i?yield{path:t,previous:o,value:void 0,state:`removed`}:s(o,u,t)||(yield{path:t,previous:o,value:u,state:`change`});else{if(r)continue;yield{path:t,previous:o,value:void 0,state:`removed`}}}}if(c){let e=le(t,o);for(let[t,n]of e){if(d.has(t))continue;yield{path:a+t,previous:void 0,value:n,state:`added`}}}}const de=(e,t,n,r=!1)=>{if(t===void 0)throw Error(`Parameter 'path' is undefined`);if(typeof t!=`string`)throw Error(`Parameter 'path' should be a string. Got: ${typeof t}`);if(e===void 0)throw Error(`Parameter 'target' is undefined`);if(e===null)throw Error(`Parameter 'target' is null`);let i=t.split(`.`),a=fe(e,i,n,r);return a},fe=(e,t,n,r)=>{if(t.length===0){if(r)return n;if(Array.isArray(e)&&!Array.isArray(n))throw Error(`Expected array value, got: '${JSON.stringify(n)}'. Set allowShapeChange=true to ignore.`);if(!Array.isArray(e)&&Array.isArray(n))throw Error(`Unexpected array value, got: '${JSON.stringify(n)}'. Set allowShapeChange=true to ignore.`);if(typeof e!=typeof n)throw Error(`Cannot reassign object type. (${typeof e} -> ${typeof n}). Set allowShapeChange=true to ignore.`);if(typeof e==`object`&&!Array.isArray(e)){let t=ce(e,n);if(t.a.length>0)throw Error(`New value is missing key(s): ${t.a.join(`,`)}`);if(t.b.length>0)throw Error(`New value cannot add new key(s): ${t.b.join(`,`)}`)}return n}let i=t.shift();if(!i)return n;let a=ne(i);if(a&&Array.isArray(e)){let a=Number.parseInt(i);if(a>=e.length&&!r)throw Error(`Array index ${a.toString()} is outside of the existing length of ${e.length.toString()}. Use allowShapeChange=true to permit this.`);let o=[...e];return o[a]=fe(o[a],t,n,r),o}else if(i in e){let a={...e};return a[i]=fe(a[i],t,n,r),a}else throw Error(`Path ${i} not found in data`)},pe=(e,t,n=`.`)=>{if(typeof t!=`string`)throw Error(`Param 'path' ought to be a string. Got: '${typeof t}'`);if(t.length===0)throw Error(`Param string 'path' is empty`);if(e===void 0)throw Error(`Param 'object' is undefined`);if(e===null)throw Error(`Param 'object' is null`);let r=t.split(n),i=me(e,r,t);return i},me=(e,t,n)=>{if(e===void 0)return{success:!1,error:`Param 'object' is undefined. Position: ${n}`};if(t.length===0)return{success:!1,error:`Path has been exhausted. position: ${n}`};let r=t.shift();if(!r)return{success:!1,error:`Unexpected empty split path. Position: ${n}`};let i=ne(r);if(i&&Array.isArray(e)){let i=Number.parseInt(r);return e[i]===void 0?{success:!1,error:`Index '${i}' does not exist. Length: ${e.length}. Position: ${n}`}:t.length===0?{value:e[i],success:!0}:me(e[i],t,t.join(`.`))}else if(typeof e==`object`&&r in e)return t.length===0?{value:e[r],success:!0}:me(e[r],t,t.join(`.`));else return{success:!1,error:`Path '${r}' not found. Position: ${n}`}};function*he(e,t=!1,n=2**53-1,r=``){e!=null&&(yield*ge(e,r,t,n))}function*ge(e,t,n=!1,r){if(!(r<=0)&&typeof e==`object`)for(let i of Object.entries(e)){let e=(t.length>0?t+`.`:``)+i[0],a=i[1],o=typeof a!=`object`;(n&&o||!n)&&(yield{path:e,value:a}),yield*ge(a,e,n,r-1)}}const _e=(e,i)=>{if(e===void 0)throw Error(`callback parameter is undefined`);let a=y(i);t(s(a,`aboveZero`,`interval`));let o,c=0,l=0,u=0,d=`idle`,f=()=>{c=0,globalThis.clearTimeout(o),d=`idle`},p=async(t=i,a)=>{let p=new Promise((i,p)=>{c=performance.now();let h=y(t),g=s(h,`aboveZero`,`altTimeoutMs`);if(n(g)){p(r(g));return}switch(d){case`scheduled`:m();break;case`running`:break}d=`scheduled`,o=globalThis.setTimeout(async()=>{if(d!==`scheduled`){console.warn(`Timeout skipping execution since state is not 'scheduled'`),f();return}let t=a??[];l++,u++,d=`running`,await e(performance.now()-c,...t),d=`idle`,f(),i()},h)});return p},m=()=>{d!==`idle`&&f()};return{start:p,cancel:m,get runState(){return d},get startCount(){return l},get startCountTotal(){return u}}};var ve=class{#handlers;#counter=0;#id=Math.floor(Math.random()*100);constructor(){this.#handlers=[]}isEmpty(){return this.#handlers.length===0}add(e,t={}){this.#counter++;let n=t.once??!1,r={id:`${this.#id} - ${this.#counter}`,handler:e,once:n};return this.#handlers.push(r),r.id}remove(e){let t=this.#handlers.length;return this.#handlers=this.#handlers.filter(t=>t.id!==e),this.#handlers.length!==t}notify(e){for(let t of this.#handlers)t.handler(e),t.once&&this.remove(t.id)}clear(){this.#handlers=[]}};const ye=e=>typeof e==`string`?e:JSON.stringify(e),be=(e,t=ye)=>{let n=new Set,r=[],i=e.flat(10);for(let e of i){let i=t(e);if(n.has(i))continue;n.add(i),r.push(e)}return r};var xe=class{#store=new Map;get(e){let t=this.#store.get(e);return t?[...t]:[]}size(e){let t=this.#store.get(e);return t?t.length:0}*iterateKey(e){let t=this.#store.get(e);t&&(yield*t.values())}*iterateValues(){for(let e of this.#store.keys())yield*this.iterateKey(e)}*iterateKeys(){yield*this.#store.keys()}addKeyedValues(e,...t){let n=this.#store.get(e);n||(n=[],this.#store.set(e,n)),n.push(...t)}deleteKeyValue(e,t){let n=this.#store.get(e);if(!n)return!1;let r=n.filter(e=>e!==t);return r.length===n.length?!1:(this.#store.set(e,r),!0)}clear(){this.#store.clear()}},Se=class{#listeners=new xe;#disposed=!1;dispose(){this.#disposed||this.clearEventListeners()}get isDisposed(){return this.#disposed}fireEvent(e,t){if(this.#disposed)throw Error(`Disposed`);for(let n of this.#listeners.iterateKey(e))n(t,this)}addEventListener(e,t){if(this.#disposed)throw Error(`Disposed`);this.#listeners.addKeyedValues(e,t)}removeEventListener(e,t){this.#disposed||this.#listeners.deleteKeyValue(e,t)}clearEventListeners(){this.#disposed||this.#listeners.clear()}};const Ce=e=>typeof e!=`object`||!e?!1:Symbol.asyncIterator in e,we=e=>typeof e!=`object`||!e?!1:Symbol.iterator in e,Te=(e,t,n)=>{let r=t.length+n.length,i=e.capacity??r,a=r-i,o=e.discardPolicy??`additions`;switch(o){case`additions`:return t.length===0?n.slice(0,n.length-a):t.length===e.capacity?t:[...t,...n.slice(0,a-1)];case`newer`:if(a>=t.length)return t.length===0?[...n.slice(0,i-1),n.at(-1)]:n.slice(Math.max(0,n.length-i),Math.min(n.length,i)+1);{let e=Math.max(1,n.length-t.length),r=n.slice(n.length-e,n.length),a=t.slice(0,Math.min(t.length,i-1)),o=[...a,...r];return o}case`older`:return[...t,...n].slice(a);default:throw Error(`Unknown overflow policy ${o}`)}},Ee=(e,t,...n)=>{if(e===void 0)throw Error(`opts parameter undefined`);let r=t.length+n.length,i=e.capacity&&r>e.capacity,a=i?Te(e,t,n):[...t,...n];if(e.capacity&&a.length!==e.capacity&&i)throw Error(`Bug! Expected return to be at capacity. Return len: ${a.length} capacity: ${e.capacity} opts: ${JSON.stringify(e)}`);if(!e.capacity&&a.length!==r)throw Error(`Bug! Return length not expected. Return len: ${a.length} expected: ${r} opts: ${JSON.stringify(e)}`);return a},De=(e,t)=>{if(t.length===0)throw Error(`Queue is empty`);return t.slice(1)},Oe=(e,t)=>t[0],ke=(e,t)=>t.length===0,Ae=(e,t)=>e.capacity?t.length>=e.capacity:!1;var je=class extends Se{options;data;eq;constructor(e={},t=[]){if(super(),e===void 0)throw Error(`opts parameter undefined`);this.options=e,this.data=t,this.eq=e.eq??v}clear(){let e=[...this.data];this.data=[],this.fireEvent(`removed`,{finalData:this.data,removed:e}),this.onClear()}onClear(){}at(e){if(e>=this.data.length)throw Error(`Index outside bounds of queue`);let t=this.data.at(e);if(t===void 0)throw Error(`Index appears to be outside range of queue`);return t}enqueue(...e){this.data=Ee(this.options,this.data,...e);let t=this.data.length;return this.onEnqueue(this.data,e),t}onEnqueue(e,t){this.fireEvent(`enqueue`,{added:t,finalData:e})}dequeue(){let e=Oe(this.options,this.data);if(e!==void 0)return this.data=De(this.options,this.data),this.fireEvent(`dequeue`,{removed:e,finalData:this.data}),this.onRemoved([e],this.data),e}onRemoved(e,t){this.fireEvent(`removed`,{removed:e,finalData:t})}removeWhere(e){let t=this.data.length,n=this.data.filter(t=>e(t));return n.length===0?0:(this.data=this.data.filter(t=>!e(t)),this.onRemoved(n,this.data),t-this.data.length)}toArray(){return[...this.data]}get isEmpty(){return ke(this.options,this.data)}get isFull(){return Ae(this.options,this.data)}get length(){return this.data.length}get peek(){return Oe(this.options,this.data)}};async function Me(e,t){let n=y(t,1e3),r=await Promise.race([(async()=>{await se({millis:n,signal:t.signal})})(),(async()=>await e.next())()]);if(r===void 0)throw Error(`Timeout`);return r}const Ne=(e,t)=>{for(let n of t)if(e.has(n))return e.get(n)},Pe=(e,t)=>{let[n,r]=Fe(e);if(!n)throw Error(r);let i=t??Object.keys(n.states)[0];if(n.states[i]===void 0)throw TypeError(`Initial state ('${i}') not found`);let a=ze(n.states);if(a===void 0)throw Error(`Could not normalise transitions`);return Object.freeze({value:i,visited:[],machine:Object.freeze(Object.fromEntries(a))})},Fe=e=>e===void 0?[void 0,`Parameter undefined`]:e===null?[void 0,`Parameter null`]:`states`in e?[e,``]:typeof e==`object`?[{states:e},``]:[void 0,`Unexpected type: ${typeof e}. Expected object`],Ie=e=>{Be(e);let t=e.machine[e.value];return t.length===1&&t[0].state===null?[]:t},Le=e=>{let t=Ie(e);return t.map(e=>e.state)},Re=e=>{let t=e=>{if(e===null)return{state:null};if(typeof e==`string`)return{state:e};if(typeof e==`object`&&`state`in e){let t=e.state;if(typeof t!=`string`)throw TypeError(`Target 'state' field is not a string. Got: ${typeof t}`);return`preconditions`in e?{state:t,preconditions:e.preconditions}:{state:t}}else throw Error(`Unexpected type: ${typeof e}. Expected string or object with 'state' field.`)};if(Array.isArray(e)){let n=!1,r=e.map(e=>{let r=t(e);if(!r)throw Error(`Invalid target`);return n||=r.state===null,r});if(n&&r.length>1)throw Error(`Cannot have null as an possible state`);return r}else{let n=t(e);return n?[n]:void 0}},ze=e=>{let t=new Map;for(let[n,r]of Object.entries(e)){if(n===void 0)throw TypeError(`Top-level undefined state`);if(r===void 0)throw TypeError(`Undefined target state for ${n}`);if(t.has(n))throw Error(`State defined twice: ${n}`);if(n.includes(` `))throw Error(`State names cannot contain spaces`);t.set(n,[])}for(let[n,r]of Object.entries(e)){let e=Re(r);if(e===void 0)throw Error(`Could not normalise target`);if(e!==null){let r=new Set;for(let i of e){if(r.has(i.state))throw Error(`Target state '${i.state}' already exists for '${n}'`);if(r.add(i.state),i.state===null)continue;if(!t.has(i.state))throw Error(`Target state '${i.state}' is not defined as a top-level state. Defined under: '${n}'`)}t.set(n,e)}}return t},Be=e=>{if(e===void 0)throw TypeError(`Param 'state' is undefined`);if(typeof e.value!=`string`)throw TypeError(`Existing state is not a string`)},b=(e,t)=>(Be(e),Ve(e,t),Object.freeze({value:t,machine:e.machine,visited:be([e.visited,[e.value]])})),Ve=(e,t)=>{if(t===null)throw Error(`Cannot transition to null state`);if(t===void 0)throw Error(`Cannot transition to undefined state`);if(typeof t!=`string`)throw TypeError(`Parameter 'toState' should be a string. Got: ${typeof t}`);let n=Le(e);if(n.length===0)throw Error(`Machine is in terminal state`);if(!n.includes(t))throw Error(`Target state '${t}' not available at current state '${e.value}'. Possible states: ${n.join(`, `)}`)};function He(e,t={}){let n=t.maximumRepeats??2**53-1,r=t.closeOnError??!0,i=t.interval?y(t.interval):-1,a=t.manual??!1;if(t.interval===void 0&&t.manual===void 0&&(a=!0),a&&t.interval)throw Error(`If option 'manual' is set, option 'interval' cannot be used`);let o=y(t.predelay,0),s=t.lazy??`very`,c=t.signal,l=new AbortController,u=e=>{l.abort(e)},f=0,p=!1,m=e=>{_.dispose(e),p=!1,g&&g.cancel()},h=async()=>{if(!p)return!1;if(o&&await se(o),f>=n)return m(`Maximum repeats reached ${n.toString()}`),!1;try{if(c?.aborted)return m(`Signal (${c.aborted})`),!1;let t=await e(u);return f++,_.set(t),!0}catch(e){return r?(m(`Function error: ${oe(e)}`),!1):(_.signal(`warn`,oe(e)),!0)}},g=a?void 0:d(async()=>{let e=await h();if(!e)return!1;if(l.signal.aborted)return m(`callback function aborted (${l.signal.reason})`),!1},i),_=Xe({lazy:s,onStart(){p=!0,g&&g.start()},onStop(){p=!1,g&&g.cancel()}});return s===`never`&&g&&g.start(),{..._,ping:h}}function Ue(e,t={}){let n=t.lazy??`very`,r=t.traceLifecycle?e=>{console.log(`Rx.From.iterator ${e}`)}:e=>{},i=y(t.readInterval,5),a=y(t.readTimeout,300*1e3),o=t.whenStopped??`continue`,s,c,l=Pe({idle:[`wait_for_next`],wait_for_next:[`processing_result`,`stopping`,`disposed`],processing_result:[`queued`,`disposed`,`stopping`],queued:[`wait_for_next`,`disposed`,`stopping`],stopping:`idle`,disposed:null},`idle`),u=()=>{r(`onExternalSignal`),c?.abort(t.signal?.reason)};t.signal&&t.signal.addEventListener(`abort`,u,{once:!0});let d=async()=>{r(`read. State: ${l.value}`),c=new AbortController;try{l=b(l,`wait_for_next`);let e=await Me(s,{signal:c.signal,millis:a});if(l=b(l,`processing_result`),c.abort(`nextWithTimeout completed`),e.done&&(r(`read v.done true`),f.dispose(`Generator complete`),l=b(l,`disposed`)),l.value===`stopping`){r(`read. sm.value = stopping`),l=b(l,`idle`);return}if(l.value===`disposed`){r(`read. sm.value = disposed`);return}f.set(e.value)}catch(e){f.dispose(`Generator error: ${e.toString()}`);return}l.value===`processing_result`?(l=b(l,`queued`),r(`scheduling read. State: ${l.value}`),setTimeout(d,i)):l=b(l,`idle`)},f=Xe({...t,lazy:n,onStart(){r(`onStart state: ${l.value} whenStopped: ${o}`),l.value===`idle`&&((l.value===`idle`&&o===`reset`||s===void 0)&&(s=Ce(e)?e[Symbol.asyncIterator]():e[Symbol.iterator]()),d())},onStop(){r(`onStop state: ${l.value} whenStopped: ${o}`),l=b(l,`stopping`),o===`reset`&&(r(`onStop reiniting iterator`),s=Ce(e)?e[Symbol.asyncIterator]():e[Symbol.iterator]())},onDispose(e){r(`onDispose (${e})`),c?.abort(`Rx.From.iterator disposed (${e})`),t.signal&&t.signal.removeEventListener(`abort`,u)}});return f}function We(e){return e.value===void 0?`signal`in e&&e.signal!==void 0:!1}function Ge(e){return e.value!==void 0}const x=e=>{if(!Ke(e))return!1;if(`last`in e){let t=e.last();if(t!==void 0)return!0}return!1},Ke=e=>typeof e!=`object`||!e?!1:`on`in e&&`onValue`in e,qe=e=>!(typeof e!=`object`||!(`source`in e)||!(`annotate`in e)),Je=(e,t={})=>{if(Ke(e))return e;let n=t.generator??{lazy:`initial`,interval:5},r=t.function??{lazy:`very`};if(Array.isArray(e))return Ue(e.values(),n);if(typeof e==`function`)return He(e,r);if(typeof e==`object`){if(qe(e))return e.source;if(we(e)||Ce(e))return Ue(e,n)}throw TypeError(`Unable to resolve source. Supports: array, Reactive, Async/Iterable. Got type: ${typeof e}`)};function Ye(e,t){let n=t.lazy??`initial`,r=t.disposeIfSourceDone??!0,i=t.onValue??(e=>{}),a=Je(e),o,s=t.debugLabel?`[${t.debugLabel}]`:``,c=()=>{o!==void 0&&(o(),o=void 0,t.onStop&&t.onStop())},l=()=>{o===void 0&&(t.onStart&&t.onStart(),o=a.on(e=>{We(e)?e.signal===`done`?(c(),u.signal(e.signal,e.context),r&&u.dispose(`Upstream source ${s} has completed (${e.context??``})`)):u.signal(e.signal,e.context):Ge(e)&&i(e.value)}))},u=Xe({...t,lazy:n,onStart:l,onStop:c});return u}function Xe(e){let t=e.lazy??`initial`,n=e.onStop??(()=>{}),r=e.onStart??(()=>{});e.debugLabel&&`${e.debugLabel}`;let i=S({...e,onFirstSubscribe(){t!==`never`&&r()},onNoSubscribers(){t===`very`&&n()}});return t===`never`&&r(),i}function S(e={}){let t,n=!1,r=!1,i=!0,a=e.onFirstSubscribe??void 0,o=e.onNoSubscribers??void 0,s=e.debugLabel?`[${e.debugLabel}]`:``,c=()=>{t!==void 0&&t.isEmpty&&(i||(i=!0,r=!1,o&&o()))},l=e=>{if(n)throw Error(`Disposed, cannot subscribe ${s}`);t===void 0&&(t=new ve);let o=t.add(e);return i=!1,r||(r=!0,a&&a()),()=>{t?.remove(o),c()}};return{dispose:r=>{n||(t?.notify({value:void 0,signal:`done`,context:`Disposed: ${r}`}),n=!0,e.onDispose&&e.onDispose(r))},isDisposed:()=>n,removeAllSubscribers:()=>{t?.clear(),c()},set:e=>{if(n)throw Error(`${s} Disposed, cannot set`);t?.notify({value:e})},signal:(e,r)=>{if(n)throw Error(`${s} Disposed, cannot signal`);t?.notify({signal:e,value:void 0,context:r})},on:e=>l(e),onValue:e=>{let t=l(t=>{Ge(t)&&e(t.value)});return t}}}function Ze(e,t={}){let i=t.eq??te,a=S(),o=S(),s=[],c=e,l=!1,u=e=>{let n=[...ue(c??{},e,{...t,includeMissingFromA:!0})];n.length!==0&&(c=e,a.set(e),o.set(n))},d=(e,t)=>{for(let[n,r,i]of s)n(e)&&i.notify({fieldName:e,pattern:r,value:t})},f={asPartial:!0,includeParents:!0},p=e=>{if(c===void 0){c=e,a.set(c);for(let[t,n]of Object.entries(e))d(t,n);return c}else{let t=[...ue(c,e,f)];if(t.length===0)return c;c={...c,...e},a.set(c),o.set(t);for(let e of t)d(e.path,e.value);return c}},m=(e,s)=>{if(c===void 0)throw Error(`Cannot update value when it has not already been set`);let l=pe(c,e);if(n(l))throw r(l);if(i(l.value,s,e))return;let u=[...ue(l.value,s,{...t,includeMissingFromA:!0})];u=u.map(t=>t.path.length>0?{...t,path:e+`.`+t.path}:{...t,path:e});let f=de(c,e,s,!0);c=f,a.set(f),o.set(u),d(e,s)},h=e=>{l||(o.dispose(e),a.dispose(e),l=!0)};return{dispose:h,isDisposed(){return l},updateField:m,last:()=>c,on:a.on,onValue:a.onValue,onDiff:o.onValue,onField(e,t){let n=ee(e),r=new ve;s.push([n,e,r]);let i=r.add(t);return()=>r.remove(i)},set:u,update:p}}const Qe=e=>({on:e.on,dispose:e.dispose,isDisposed:e.isDisposed,onValue:e.onValue});function $e(e,t,n,r={}){let i;if(typeof e==`string`){if(i=document.querySelector(e),i===null)throw Error(`Target query did not resolve to an element. Query: '${e}'`)}else i=e;if(i===null)throw Error(`Param 'targetOrQuery' is null`);let a=r.debugLifecycle??!1,o=r.debugFiring??!1,s=r.lazy??!1;n===void 0&&(n={});let c=Ze(n,{deepEntries:!0}),l=!1,u=!1,d=e=>{o&&console.log(`Reactive.event '${t}' firing '${JSON.stringify(e)}`),c.set(e)},f=()=>{l&&(l=!1,i.removeEventListener(t,d),a&&console.log(`Rx.From.event remove '${t}'`))},p=()=>{l||(l=!0,i.addEventListener(t,d),a&&console.log(`Rx.From.event add '${t}'`))};return s||p(),{last:()=>(s&&p(),c.last()),dispose:e=>{u||(u=!0,f(),c.dispose(e))},isDisposed(){return u},on:e=>(s&&p(),c.on(e)),onValue:e=>(s&&p(),c.onValue(e))}}function et(e,t,n={}){let r;if(typeof e==`string`){if(r=document.querySelector(e),r===null)throw Error(`Target query did not resolve to an element. Query: '${e}'`)}else r=e;if(r===null)throw Error(`Param 'targetOrQuery' is null`);let i=n.debugLifecycle??!1,a=n.debugFiring??!1,o=n.fireInitial??!1,s=0,c=f(),l=Xe({lazy:n.lazy??`very`,onStart(){r.addEventListener(t,u),i&&console.log(`Rx.From.eventTrigger add '${t}'`),o&&s===0&&((i||a)&&console.log(`Rx.From.eventTrigger: firing initial`),u())},onStop(){r.removeEventListener(t,u),i&&console.log(`Rx.From.eventTrigger remove '${t}'`)}}),u=e=>{a&&console.log(`Rx.From.eventTrigger '${t}' triggered'`),l.set({sinceLast:c(),total:++s})};return l}const C=e=>{let t=tt(e);if(t.success)return t.value;throw r(t)},tt=e=>{if(typeof e==`string`){let t=document.querySelector(e);if(t===null){let t=e.startsWith(`#`)?`Query '${e}' did not match anything. Try '#id', 'div', or '.class'`:`Query '${e}' did not match anything. Did you mean '#${e}?`;return{success:!1,error:t}}e=t}else if(e===null)return{success:!1,error:`Param 'domQueryOrEl' is null`};else if(e===void 0)return{success:!1,error:`Param 'domQueryOrEl' is undefined`};let t=e;return{success:!0,value:t}};function nt(e,t,n={}){let r=n.traceInput??!1,i=n.traceOutput??!1,a=Ye(e,{lazy:`initial`,...n,onValue(e){let n=t(e);r&&i?console.log(`Rx.Ops.transform input: ${JSON.stringify(e)} output: ${JSON.stringify(n)}`):r?console.log(`Rx.Ops.transform input: ${JSON.stringify(e)}`):i&&console.log(`Rx.Ops.transform output: ${JSON.stringify(n)}`),a.set(n)}});return Qe(a)}function rt(e,t={}){let n=y(t.elapsed,50),r,i=_e(()=>{let e=r;e&&(a.set(e),r=void 0)},n),a=Ye(e,{...t,onValue(e){r=e,i.start()}});return Qe(a)}function it(e){return t=>rt(t,e)}function at(e={}){let t=S(e);return{dispose:t.dispose,isDisposed:t.isDisposed,set(e){t.set(e)},on:t.on,onValue:t.onValue}}function ot(e){let t=st(e);return{dispose:t.dispose,isDisposed:t.isDisposed,on:t.on,onValue:t.onValue}}function st(e){let t=()=>{},n=at({onFirstSubscribe(){t=e(n)},onNoSubscribers(){t&&t()}});return{...n,onValue:e=>n.on(t=>{Ge(t)&&e(t.value)})}}const ct=(e,t)=>{if(e===null)throw Error(`Param 'elem' is null. Expected element to observe`);if(e===void 0)throw Error(`Param 'elem' is undefined. Expected element to observe`);let n=ot(t=>{let n=new ResizeObserver(e=>{t.set(e)});return n.observe(e),()=>{n.unobserve(e)}});return it({elapsed:t??100})(n)},lt=(e=document.documentElement)=>{let t=ot(t=>{let n=new MutationObserver(e=>{t.set(e)}),r={attributeFilter:[`class`],attributes:!0};return n.observe(e,r),()=>{n.disconnect()}});return t};function ut(e){let t=e,n=S(),r=e=>{t=e,n.set(e)};return{dispose:n.dispose,isDisposed:n.isDisposed,last:()=>t,on:n.on,onValue:n.onValue,set:r,setHsl:e=>{r(e)}}}var dt=Object.defineProperty,ft=(e,t,n)=>t in e?dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pt=(e,t)=>{for(var n in t)dt(e,n,{get:t[n],enumerable:!0})},w=(e,t,n)=>ft(e,typeof t==`symbol`?t:t+``,n);function T(e,t){if(e)return;let n=t?Error(t):Error(`Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.`);throw n.name=`colorizr`,n}var E={hsl:[`h`,`s`,`l`],oklab:[`l`,`a`,`b`],oklch:[`l`,`c`,`h`],rgb:[`r`,`g`,`b`]},mt=[`hsl`,`oklab`,`oklch`,`rgb`],ht=Math.PI/180,D={l:[.3963377773761749,.2158037573099136],m:[-.1055613458156586,-.0638541728258133],s:[-.0894841775298119,-1.2914855480194092]},O={l:[.4122214708,.5363325363,.0514459929],m:[.2119034982,.6806995451,.1073969566],s:[.0883024619,.2817188376,.6299787005]},k={l:[.2104542553,.793617785,.0040720468],a:[1.9779984951,2.428592205,.4505937099],b:[.0259040371,.7827717662,.808675766]},A={r:[4.076741636075958,-3.307711539258063,.2309699031821043],g:[-1.2684379732850315,2.609757349287688,-.341319376002657],b:[-.0041960761386756,-.7034186179359362,1.7076146940746117]},j=5,gt=180/Math.PI,M={alpha:`amount must be a number between 0 and 1`,hueRange:`hue must be a number between 0 and 360`,input:`input is required`,inputHex:`input is required and must be a hex`,inputNumber:`input is required and must be a number`,inputString:`input is required and must be a string`,invalid:`invalid input`,invalidCSS:`invalid CSS string`,left:`left is required and must be a string`,lightnessRange:`lightness must be a number between 0 and 1`,options:`invalid options`,right:`right is required and must be a string`,threshold:`threshold must be a number between 0 and 255`},_t={aliceblue:`#f0f8ff`,antiquewhite:`#faebd7`,aqua:`#00ffff`,aquamarine:`#7fffd4`,azure:`#f0ffff`,beige:`#f5f5dc`,bisque:`#ffe4c4`,black:`#000000`,blanchedalmond:`#ffebcd`,blue:`#0000ff`,blueviolet:`#8a2be2`,brown:`#a52a2a`,burlywood:`#deb887`,cadetblue:`#5f9ea0`,chartreuse:`#7fff00`,chocolate:`#d2691e`,coral:`#ff7f50`,cornflowerblue:`#6495ed`,cornsilk:`#fff8dc`,crimson:`#dc143c`,cyan:`#00ffff`,darkblue:`#00008b`,darkcyan:`#008b8b`,darkgoldenrod:`#b8860b`,darkgray:`#a9a9a9`,darkgreen:`#006400`,darkkhaki:`#bdb76b`,darkmagenta:`#8b008b`,darkolivegreen:`#556b2f`,darkorange:`#ff8c00`,darkorchid:`#9932cc`,darkred:`#8b0000`,darksalmon:`#e9967a`,darkseagreen:`#8fbc8f`,darkslateblue:`#483d8b`,darkslategray:`#2f4f4f`,darkslategrey:`#2f4f4f`,darkturquoise:`#00ced1`,darkviolet:`#9400d3`,deeppink:`#ff1493`,deepskyblue:`#00bfff`,dimgray:`#696969`,dimgrey:`#696969`,dodgerblue:`#1e90ff`,firebrick:`#b22222`,floralwhite:`#fffaf0`,forestgreen:`#228b22`,fuchsia:`#ff00ff`,gainsboro:`#dcdcdc`,ghostwhite:`#f8f8ff`,gold:`#ffd700`,goldenrod:`#daa520`,gray:`#808080`,grey:`#808080`,green:`#008000`,greenyellow:`#adff2f`,honeydew:`#f0fff0`,hotpink:`#ff69b4`,indianred:`#cd5c5c`,indigo:`#4b0082`,ivory:`#fffff0`,khaki:`#f0e68c`,lavender:`#e6e6fa`,lavenderblush:`#fff0f5`,lawngreen:`#7cfc00`,lemonchiffon:`#fffacd`,lightblue:`#add8e6`,lightcoral:`#f08080`,lightcyan:`#e0ffff`,lightgoldenrodyellow:`#fafad2`,lightgray:`#d3d3d3`,lightgreen:`#90ee90`,lightgrey:`#d3d3d3`,lightpink:`#ffb6c1`,lightsalmon:`#ffa07a`,lightseagreen:`#20b2aa`,lightskyblue:`#87cefa`,lightslategray:`#778899`,lightslategrey:`#778899`,lightsteelblue:`#b0c4de`,lightyellow:`#ffffe0`,lime:`#00ff00`,limegreen:`#32cd32`,linen:`#faf0e6`,magenta:`#ff00ff`,maroon:`#800000`,mediumaquamarine:`#66cdaa`,mediumblue:`#0000cd`,mediumorchid:`#ba55d3`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumslateblue:`#7b68ee`,mediumspringgreen:`#00fa9a`,mediumturquoise:`#48d1cc`,mediumvioletred:`#c71585`,midnightblue:`#191970`,mintcream:`#f5fffa`,mistyrose:`#ffe4e1`,moccasin:`#ffe4b5`,navajowhite:`#ffdead`,navy:`#000080`,oldlace:`#fdf5e6`,olive:`#808000`,olivedrab:`#6b8e23`,orange:`#ffa500`,orangered:`#ff4500`,orchid:`#da70d6`,palegoldenrod:`#eee8aa`,palegreen:`#98fb98`,paleturquoise:`#afeeee`,palevioletred:`#db7093`,papayawhip:`#ffefd5`,peachpuff:`#ffdab9`,peru:`#cd853f`,pink:`#ffc0cb`,plum:`#dda0dd`,powderblue:`#b0e0e6`,purple:`#800080`,rebeccapurple:`#663399`,red:`#ff0000`,rosybrown:`#bc8f8f`,royalblue:`#4169e1`,saddlebrown:`#8b4513`,salmon:`#fa8072`,sandybrown:`#f4a460`,seagreen:`#2e8b57`,seashell:`#fff5ee`,sienna:`#a0522d`,silver:`#c0c0c0`,skyblue:`#87ceeb`,slateblue:`#6a5acd`,slategray:`#708090`,slategrey:`#708090`,snow:`#fffafa`,springgreen:`#00ff7f`,steelblue:`#4682b4`,tan:`#d2b48c`,teal:`#008080`,thistle:`#d8bfd8`,tomato:`#ff6347`,turquoise:`#40e0d0`,violet:`#ee82ee`,wheat:`#f5deb3`,white:`#ffffff`,whitesmoke:`#f5f5f5`,yellow:`#ffff00`,yellowgreen:`#9acd32`};function vt(e){return Array.isArray(e)&&e.length===6}function N(e){return I(e)&&Object.keys(_t).includes(e.toLowerCase())}function P(e){return typeof e==`number`&&!Number.isNaN(e)}function F(e){if(!e)return!1;let{toString:t}=Object.prototype,n=Object.getPrototypeOf(e);return t.call(e)===`[object Object]`&&(n===null||n===Object.getPrototypeOf({}))}function I(e,t=!0){let n=typeof e==`string`;return t?n&&!!e.trim().length:n}function yt(e){return bt(e)||Ct(e)||xt(e)||St(e)}function L(e){return I(e)?/^#([\da-f]{3,4}|[\da-f]{6,8})$/i.test(e):!1}function bt(e){if(!F(e))return!1;let t=Object.entries(e);return!!t.length&&t.every(([e,t])=>e===`h`?t>=0&&t<=360:e===`alpha`?t>=0&&t<=1:E.hsl.includes(e)&&t>=0&&t<=100)}function xt(e){if(!F(e))return!1;let t=Object.entries(e);return!!t.length&&t.every(([e,t])=>e===`l`?t>=0&&t<=100:e===`alpha`?t>=0&&t<=1:E.oklab.includes(e)&&t>=-1&&t<=1)}function St(e){if(!F(e))return!1;let t=Object.entries(e);return!!t.length&&t.every(([e,t])=>e===`l`?t>=0&&t<=100:e===`alpha`?t>=0&&t<=1:E.oklch.includes(e)&&t>=0&&t<=(e===`h`?360:1))}function Ct(e){if(!F(e))return!1;let t=Object.entries(e);return!!t.length&&t.every(([e,t])=>e===`alpha`?t>=0&&t<=1:E.rgb.includes(e)&&t>=0&&t<=255)}function R(e,t){T(yt(e),M.invalid);let n=t;return!n||(n>1&&(n/=100),n===1)?e:{...e,alpha:n}}function z(e,t=0,n=100){return Math.min(Math.max(e,t),n)}function wt(e,t){T(P(e),M.inputNumber);let n=e+t;return n>360&&(n%=360),n<0&&(n+=360),Math.abs(n)}function B(e,t,n){switch(T(P(e),`Input is not a number`),T(mt.includes(t),`Invalid model${t?`: ${t}`:``}`),T(E[t].includes(n),`Invalid key${n?`: ${n}`:``}`),t){case`hsl`:return T(E.hsl.includes(n),`Invalid key`),[`s`,`l`].includes(n)?z(e):z(e,0,360);case`rgb`:return T(E.rgb.includes(n),`Invalid key`),z(e,0,255);default:throw Error(`Invalid inputs`)}}function V(e,t){let n=E[t],r={hsl:bt,oklab:xt,oklch:St,rgb:Ct};T(F(e)||Array.isArray(e),M.invalid);let i=Array.isArray(e)?{[n[0]]:e[0],[n[1]]:e[1],[n[2]]:e[2]}:e;return T(r[t](i),`invalid ${t} color`),i}function H(e,t=j,n=!0){let r=new Map(Object.entries(e));for(let[e,i]of r.entries())r.set(e,U(i,t,n));return Object.fromEntries(r)}function U(e,t=2,n=!0){if(!P(e)||e===0)return 0;if(n){let n=10**t;return Math.round(e*n)/n}let r=Math.abs(e),i=Math.abs(Math.ceil(Math.log(r)/Math.LN10));i===0?i=2:i>t&&(i=t);let a=t-(i<0?0:i);a<=1&&t>1?a=2:(a>t||a===0)&&(a=t);let o=10**a;return Math.round(e*o)/o}function Tt(e,t){return T(L(e),M.inputHex),T(P(t),M.inputNumber),t>=1?Ot(e):`${Ot(e)}${Et(t)}`}function Et(e){T(P(e),M.inputNumber);let t=e;return e>1&&(t/=100),Math.round(t*255).toString(16).padStart(2,`0`)}function Dt(e){T(L(e),M.inputString);let t=e.substring(7,9);return t?U(parseInt(t,16)/255):1}function Ot(e){return T(L(e),M.inputHex),e.length===5?e.substring(0,4):e.substring(0,7)}var W={};pt(W,{hex2hsl:()=>At,hex2oklab:()=>Ft,hex2oklch:()=>Bt,hex2rgb:()=>G,hsl2hex:()=>Ut,hsl2oklab:()=>Wt,hsl2oklch:()=>Gt,hsl2rgb:()=>q,oklab2hex:()=>Yt,oklab2hsl:()=>Xt,oklab2oklch:()=>Rt,oklab2rgb:()=>Jt,oklch2hex:()=>tn,oklch2hsl:()=>nn,oklch2oklab:()=>$t,oklch2rgb:()=>en,rgb2hex:()=>Ht,rgb2hsl:()=>K,rgb2oklab:()=>Pt,rgb2oklch:()=>zt});function kt(e){T(L(e),M.inputHex);let t=e.replace(`#`,``);if(t.length===3||t.length===4){let e=[...t];t=``,e.forEach(e=>{t+=`${e}${e}`})}let n=`#${t}`;return T(L(n),`invalid hex`),n}function G(e){T(L(e),M.inputHex);let t=kt(e).slice(1);return{r:parseInt(t.charAt(0)+t.charAt(1),16),g:parseInt(t.charAt(2)+t.charAt(3),16),b:parseInt(t.charAt(4)+t.charAt(5),16)}}function K(e){let t=V(e,`rgb`),n=B(t.r,`rgb`,`r`)/255,r=B(t.g,`rgb`,`g`)/255,i=B(t.b,`rgb`,`b`)/255,a=Math.min(n,r,i),o=Math.max(n,r,i),s=o-a,c=0,l,u=(o+a)/2,d;switch(o){case n:d=s?(r-i)/s:0,c=60*d;break;case r:d=(i-n)/s,c=60*d+120;break;case i:d=(n-r)/s,c=60*d+240;break;default:break}return c<0&&(c=360+c),l=a===o?0:u<.5?s/(2*u):s/(2-2*u),{h:Math.abs(+(c%360).toFixed(2)),s:+(l*100).toFixed(2),l:+(u*100).toFixed(2)}}function At(e){return T(L(e),M.inputHex),K(G(e))}var{cbrt:jt,sign:Mt}=Math;function Nt(e){let t=Math.abs(e);return t<.04045?e/12.92:(Mt(e)||1)*((t+.055)/1.055)**2.4}function Pt(e,t=j){let n=V(e,`rgb`),[r,i,a]=[Nt(n.r/255),Nt(n.g/255),Nt(n.b/255)],o=jt(O.l[0]*r+O.l[1]*i+O.l[2]*a),s=jt(O.m[0]*r+O.m[1]*i+O.m[2]*a),c=jt(O.s[0]*r+O.s[1]*i+O.s[2]*a),l={l:k.l[0]*o+k.l[1]*s-k.l[2]*c,a:k.a[0]*o-k.a[1]*s+k.a[2]*c,b:k.b[0]*o+k.b[1]*s-k.b[2]*c};return H(l,t)}function Ft(e,t){return T(L(e),M.inputHex),Pt(G(e),t)}var{atan2:It,sqrt:Lt}=Math;function Rt(e,t){let{l:n,a:r,b:i}=H(V(e,`oklab`)),a=Lt(r**2+i**2),o=(It(i,r)*gt+360)%360;return U(a*1e4)===0&&(o=0),H({l:n,c:a,h:o},t)}function zt(e,t){let n=V(e,`rgb`);return Rt(Pt(n,t),t)}function Bt(e,t){return T(L(e),M.inputHex),zt(G(e),t)}function Vt(e,t,n){T(P(e)&&P(t)&&P(n),`point, chroma and h are required`);let r=n;return r<0&&(r+=1),r>1&&--r,U(r<1/6?e+(t-e)*6*r:r<1/2?t:r<2/3?e+(t-e)*(2/3-r)*6:e,4)}function q(e){let t=V(e,`hsl`),n=U(t.h)/360,r=U(t.s)/100,i=U(t.l)/100,a,o,s,c,l;return r===0?(a=i,o=i,s=i):(l=i<.5?i*(1+r):i+r-i*r,c=2*i-l,a=Vt(c,l,n+1/3),o=Vt(c,l,n),s=Vt(c,l,n-1/3)),{r:Math.round(a*255),g:Math.round(o*255),b:Math.round(s*255)}}function Ht(e){let t=V(e,`rgb`);return`#${Object.values(t).map(e=>`0${Math.floor(e).toString(16)}`.slice(-2)).join(``)}`}function Ut(e){let t=V(e,`hsl`);return Ht(q(t))}function Wt(e,t){let n=V(e,`hsl`);return Pt(q(n),t)}function Gt(e,t){let n=V(e,`hsl`);return zt(q(n),t)}var{abs:Kt}=Math;function qt(e){let t=Kt(e),n=e<0?-1:1;return t>.0031308?n*(t**(1/2.4)*1.055-.055):e*12.92}function Jt(e,t=0){let{l:n,a:r,b:i}=V(e,`oklab`),a=(n+D.l[0]*r+D.l[1]*i)**3,o=(n+D.m[0]*r+D.m[1]*i)**3,s=(n+D.s[0]*r+D.s[1]*i)**3,c=255*qt(A.r[0]*a+A.r[1]*o+A.r[2]*s),l=255*qt(A.g[0]*a+A.g[1]*o+A.g[2]*s),u=255*qt(A.b[0]*a+A.b[1]*o+A.b[2]*s);return{r:z(U(c,t),0,255),g:z(U(l,t),0,255),b:z(U(u,t),0,255)}}function Yt(e){let t=V(e,`oklab`);return Ht(Jt(t))}function Xt(e){let t=V(e,`oklab`);return K(Jt(t))}var{sin:Zt,cos:Qt}=Math;function $t(e,t){let{l:n,c:r,h:i}=V(e,`oklch`);return(Number.isNaN(i)||i<0)&&(i=0),H({l:n,a:r*Qt(i*ht),b:r*Zt(i*ht)},t)}function en(e,t=0){let n=V(e,`oklch`);return Jt($t(n),t)}function tn(e){let t=V(e,`oklch`);return Ht(en(t))}function nn(e){let t=V(e,`oklch`);return K(en(t))}function J(e){if(T(I(e),M.inputString),L(e)){let t=E.rgb,{r:n,g:r,b:i}=G(e),a=Dt(e);return{model:`rgb`,[t[0]]:n,[t[1]]:r,[t[2]]:i,alpha:a<1?a:void 0}}let t=/(?:(rgb|hsl|oklab|oklch)a?\s*\(\s*([\d%.-]+)\s*[ ,/]\s*([\d%.-]+)\s*[ ,/]\s*([\d%.-]+)(?:\s*[ ,/]\s*([\d%.-]+))?\s*\))/i,n=t.exec(e);T(vt(n),M.invalidCSS);let r=n[1],i=E[r],a=n[5]?parseFloat(n[5]):1;return a>1&&(a/=100),{model:r,[i[0]]:parseFloat(n[2]),[i[1]]:parseFloat(n[3]),[i[2]]:parseFloat(n[4]),alpha:a<1?a:void 0}}function Y(e,t){T(I(e),M.inputString);let n,r=N(e)?_t[e.toLowerCase()]:e,i=t??(L(r)?`hex`:J(r).model),a=e=>Object.values(e);if(L(r)){let e=Dt(r);switch(i){case`hsl`:n=R(At(r),e);break;case`oklab`:n=R(Ft(r),e);break;case`oklch`:n=R(Bt(r),e);break;case`rgb`:n=R(G(r),e);break;default:n=`${Ot(r)}${e===1?``:Et(e)}`;break}return n}switch(i){case`hsl`:{let{alpha:e,model:t,...i}=J(r);[`oklab`,`oklch`].includes(t)&&i.l>1&&(i.l=U(i.l/100,j)),n=R(t===`hsl`?i:W[`${t}2hsl`](a(i)),e);break}case`oklab`:{let{alpha:e,model:t,...i}=J(r);[`oklab`,`oklch`].includes(t)&&i.l>1&&(i.l=U(i.l/100,j)),n=R(t===`oklab`?i:W[`${t}2oklab`](a(i)),e);break}case`oklch`:{let{alpha:e,model:t,...i}=J(r);[`oklab`,`oklch`].includes(t)&&i.l>1&&(i.l=U(i.l/100,j)),n=R(t===`oklch`?i:W[`${t}2oklch`](a(i)),e);break}case`rgb`:{let{alpha:e,model:t,...i}=J(r);[`oklab`,`oklch`].includes(t)&&i.l>1&&(i.l/=100),n=R(t===`rgb`?i:W[`${t}2rgb`](a(i)),e);break}case`hex`:default:{let{alpha:e,model:t,...i}=J(r),o=``;[`oklab`,`oklch`].includes(t)&&i.l>1&&(i.l=U(i.l/100,j)),e&&(o=Et(e)),n=`${W[`${t}2hex`](a(i))}${o}`;break}}return n}function rn(e){T(!!e,M.input);let t={};if(I(e)){let{alpha:n=1}=J(e),r=L(e)?`hex`:J(e).model;t.hex=Tt(Y(e,`hex`),n),t.hsl=R(Y(e,`hsl`),n),t.oklab=R(Y(e,`oklab`),n),t.oklch=R(Y(e,`oklch`),n),t.rgb=R(Y(e,`rgb`),n),t.alpha=n,t.type=r}else if(F(e)){let{alpha:n=1}=e;if(bt(e))t.hsl={h:B(e.h,`hsl`,`h`),s:B(e.s,`hsl`,`s`),l:B(e.l,`hsl`,`l`)},t.rgb=q(t.hsl),t.oklab=Wt(t.hsl),t.oklch=Gt(t.hsl),t.type=`hsl`;else if(xt(e))t.hsl=Xt(e),t.oklab=e,t.oklch=Rt(e),t.rgb=Jt(e),t.type=`oklab`;else if(St(e))t.hsl=nn(e),t.oklab=$t(e),t.oklch=e,t.rgb=en(e),t.type=`oklch`;else if(Ct(e))t.rgb={r:B(e.r,`rgb`,`r`),g:B(e.g,`rgb`,`g`),b:B(e.b,`rgb`,`b`)},t.hsl=K(t.rgb),t.oklab=Pt(t.rgb),t.oklch=zt(t.rgb),t.type=`rgb`;else throw Error(`invalid color`);t.hex=Tt(Ut(t.hsl),n),t.hsl=R(t.hsl,n),t.oklab=R(t.oklab,n),t.oklch=R(t.oklch,n),t.rgb=R(t.rgb,n),t.alpha=n}else throw Error(M.input);return t}function an(e,t,n=j){T(I(e),M.left),T(I(t),M.right);let r=Y(e,`rgb`),i=Y(t,`rgb`),a=(r.r*299+r.g*587+r.b*114)/1e3,o=(i.r*299+i.g*587+i.b*114)/1e3;return U(Math.abs(o-a),n)}function on(e){T(I(e),M.inputString);let{r:t,g:n,b:r}=Y(e,`rgb`),i=Math.max(t,n,r),a=Math.min(t,n,r);return U((i-a)/255,4)}function sn(e,t){T(I(e),M.left),T(I(t),M.right);let n=Y(e,`rgb`),r=Y(t,`rgb`);return Math.max(n.r,r.r)-Math.min(n.r,r.r)+(Math.max(n.g,r.g)-Math.min(n.g,r.g))+(Math.max(n.b,r.b)-Math.min(n.b,r.b))}function cn(e){T(I(e),M.inputString);let{r:t,g:n,b:r}=Y(e,`rgb`),i=[t/255,n/255,r/255];for(let e=0;e<i.length;e++)i[e]<=.03928?i[e]/=12.92:i[e]=((i[e]+.055)/1.055)**2.4;return U(.2126*i[0]+.7152*i[1]+.0722*i[2],4)}function ln(e,t){T(I(e),M.left),T(I(t),M.right);let n=cn(e),r=cn(t);return U(n>=r?(n+.05)/(r+.05):(r+.05)/(n+.05))}function un(e,t){T(I(e),M.left),T(I(t),M.right);let n=500,r=125,i=sn(e,t),a=ln(e,t),o=an(e,t),s=o>=r,c=i>=n,l=0;return s&&c?l=2:(s||c)&&(l=1),{brightnessDifference:o,colorDifference:i,compliant:l,contrast:a,largeAA:a>=3,largeAAA:a>=4.5,normalAA:a>=4.5,normalAAA:a>=7}}function dn(e){if(L(e)||N(e))return`hex`;if(I(e))return J(e).model;if(bt(e))return`hsl`;if(xt(e))return`oklab`;if(St(e))return`oklch`;if(Ct(e))return`rgb`;throw Error(M.invalid)}function fn(e,t){let n=N(e)?_t[e.toLowerCase()]:e,r=dn(n);if(r===t)return n;let i=`${r}2${t}`,a=W[i];if(!a)throw Error(`Converter not found for ${r} to ${t}`);switch(r){case`hex`:return t===`hex`?n:a(n);case`hsl`:return t===`hsl`?n:a(n);case`oklab`:return t===`oklab`?n:a(n);case`oklch`:return t===`oklch`?n:a(n);default:return t===`rgb`?n:a(n)}}function X(e,t={}){T(L(e)||yt(e),M.invalid);let{alpha:n,format:r=`hex`,precision:i=j,separator:a=` `}=t,o=n&&n!==1?`${U(n*100)}%`:null,s=[],c=a;switch(r){case`hsl`:{let{h:t,s:n,l:r}=fn(e,`hsl`);s=[t,`${n}%`,`${r}%`];break}case`oklab`:{c=` `;let{l:t,a:n,b:r}=H(fn(e,`oklab`),i);s=[`${U(t*100,i)}%`,n,r];break}case`oklch`:{c=` `;let{l:t,c:n,h:r}=H(fn(e,`oklch`),i);s=[`${U(t*100,i)}%`,n,r];break}case`rgb`:{let{r:t,g:n,b:r}=fn(e,`rgb`);s=[t,n,r];break}default:{let t=Ot(fn(e,`hex`));return n&&n!==1?`${t}${Et(n)}`:t}}return`${r}(${s.join(c)}${o?` / ${o}`:``})`}function pn(e,t,n){return(r,i)=>{T(I(r),M.inputString),T(P(i),M.alpha);let a=Y(r,`hsl`),o=L(r)||N(r)?`hex`:J(r).model;return X({...a,[e]:z(a[e]+(t===`+`?i:-i),0,100)},{format:n??o})}}function mn(e,t,n){return pn(`l`,`-`,n)(e,t)}function hn(e,t,n){return pn(`s`,`-`,n)(e,t)}function gn(e,t,n){T(I(e),M.inputString),T(P(t),`degrees must be a number`);let r=Y(e,`hsl`),i=L(e)||N(e)?`hex`:J(e).model;return X({...r,h:wt(r.h,t)},{format:n??i})}function _n(e){T(I(e),M.inputString);let t=L(e)||N(e)?`hex`:J(e).model,n=Y(e,`hex`);return X(gn(n,180),{format:t})}function vn(e,t,n){return pn(`l`,`+`,n)(e,t)}function yn(e,t,n){T(I(e),M.inputString),T(P(t),M.alpha);let r=L(e)||N(e)?`hex`:J(e).model,i=Y(e,`rgb`);return X(i,{format:n??r,alpha:t})}function bn(e){if(T(I(e),M.inputString),L(e))return Dt(e);if(Object.keys(_t).includes(e))return 1;let{alpha:t}=J(e);return t||1}function xn(e,t,n){return pn(`s`,`+`,n)(e,t)}function Sn(e,t={}){let{darkColor:n=`#000000`,lightColor:r=`#ffffff`,threshold:i=128}=t;T(I(e),M.inputString),T(i>=0&&i<=255,M.threshold);try{let{r:t,g:a,b:o}=G(Y(e,`hex`)),s=(t*299+a*587+o*114)/1e3;return s>=i?n:r}catch(t){return console.warn(`Invalid color input: ${e}`),console.warn(t),n}}function Cn(e,t,n){T(I(e),M.inputString),T(P(t),M.alpha),T(t>=-1&&t<=1,M.alpha);let r=Y(e,`oklab`),i=U(z(bn(e)-t,0,1));return X(r,{format:n,alpha:i})}var wn=class{constructor(e,t={}){w(this,`alpha`),w(this,`hex`),w(this,`hsl`),w(this,`oklab`),w(this,`oklch`),w(this,`rgb`),w(this,`type`),T(!!e,`color is required`);let{alpha:n,hex:r,hsl:i,oklab:a,oklch:o,rgb:s,type:c}=rn(e);this.hex=r,this.hsl=i,this.oklab=a,this.oklch=o,this.rgb=s,this.alpha=n,this.type=t.format??c}get css(){return this.selectedColor}get red(){return Number(this.rgb.r)}get green(){return Number(this.rgb.g)}get blue(){return Number(this.rgb.b)}get hue(){return Number(this.hsl.h)}get saturation(){return Number(this.hsl.s)}get lightness(){return Number(this.hsl.l)}get luminance(){return cn(this.selectedColor)}get chroma(){return on(this.selectedColor)}get opacity(){return bn(this.selectedColor)}get textColor(){return Sn(this.selectedColor)}get selectedColor(){return X(this[this.type],{format:this.type,alpha:this.alpha})}brightnessDifference(e){return an(this.selectedColor,e)}colorDifference(e){return sn(this.selectedColor,e)}compare(e){return un(this.selectedColor,e)}contrast(e){return ln(this.selectedColor,e)}format(e,t){return X(this.rgb,{alpha:this.alpha,format:e,precision:t})}lighten(e){return vn(this.selectedColor,e)}darken(e){return mn(this.selectedColor,e)}saturate(e){return xn(this.selectedColor,e)}desaturate(e){return hn(this.selectedColor,e)}invert(){return _n(this.selectedColor)}opacify(e=.9){return yn(this.selectedColor,e,this.type)}rotate(e){return gn(this.selectedColor,e)}transparentize(e=.1){return Cn(this.selectedColor,e,this.type)}};function Tn(e,t){let n=Y(e,t);return X(n,{format:t})}var En=wn;const Dn=e=>(typeof e==`object`&&(!(`h`in e&&`s`in e&&`l`in e)||!(`unit`in e)||`space`in e&&e.space),!1),On=e=>(typeof e==`object`&&(!(`r`in e&&`g`in e&&`b`in e)||!(`unit`in e)||`space`in e&&e.space),!1),kn=e=>{if(`r`in e&&`g`in e&&`b`in e){if(!(`unit`in e))if(e.r<=1&&e.g<=1&&e.b<=1)e.unit=`scalar`;else if(e.r>255&&e.g<=255&&e.b<=255)return;else e.unit=`8bit`;return`space`in e||(e.space=`srgb`),e}},An=e=>{if(`h`in e&&`s`in e&&`l`in e){if(!(`unit`in e))if(e.r<=1&&e.g<=1&&e.b<=1)e.unit=`scalar`;else if(e.s>100&&e.l<=100)return;else e.unit=`absolute`;return`space`in e||(e.space=`hsl`),e}},jn=e=>{if(typeof e==`object`){if(!(`l`in e&&`c`in e&&`h`in e)||!(`unit`in e))return!1;if(`space`in e&&(e.space===`lch`||e.space==`oklch`))return!0}return!1},Mn=e=>typeof e==`string`?!0:typeof e==`object`?!!(Dn(e)||jn(e)||On(e)):!1,Nn=Object.freeze({h:0,s:0,l:0,opacity:0,unit:`absolute`,space:`hsl`});function Pn(e,t={}){return In(At(e),t)}function Z(e,t={}){if(e=e.toLowerCase(),e.startsWith(`hsla(`))throw Error(`hsla() not supported`);if(e.startsWith(`rgba(`))throw Error(`rgba() not supported`);if(e.startsWith(`#`))return Pn(e,t);if(e===`transparent`)return Nn;if(Q[e]!==void 0)return Pn(Q[e],t);if(e.startsWith(`rgb(`)){let n=ur(e);return In(n,t)}if(!e.startsWith(`hsl(`))try{e=Tn(e,`hsl`)}catch(n){if(t.fallbackString)e=t.fallbackString;else throw n}try{let n=Hn(e);return t.scalar?Rn(n):Ln(n)}catch(e){if(t.fallbackColour)return t.fallbackColour;throw e}}const Fn=e=>{let t=Ln(e),n=`hsl(${t.h}deg ${t.s}% ${t.l}%`;return`opacity`in t&&t.opacity!==void 0&&t.opacity<100&&(n+=` / ${t.opacity}%`),n+=`)`,n};function In(e,n={}){if(e==null&&n.fallbackColour)return n.fallbackColour;let r=n.scalar??!0;return t(c(e.h,0,360,`h`),c(e.s,0,100,`s`),c(e.l,0,100,`l`),o(e.alpha??1,`alpha`)),r?Bn(e.h/360,e.s/100,e.l/100,e.alpha??1):Vn(e.h,e.s,e.l,(e.alpha??1)*100)}const Ln=e=>{if(typeof e==`string`)return Z(e,{scalar:!1});if(On(e))return Ln(In(ur(e),{scalar:!1}));let t=e;return zn(t),t.unit===`absolute`?t:{h:t.h*360,s:t.s*100,l:t.l*100,opacity:(t.opacity??1)*100,unit:`absolute`,space:`hsl`}},Rn=e=>{if(typeof e==`string`)return Z(e,{scalar:!0});if(On(e))return Rn(In(ur(e),{scalar:!0}));let t=e;return zn(t),t.unit===`scalar`?t:{h:t.h/360,s:t.s/100,l:t.l/100,opacity:(t.opacity??1)/100,unit:`scalar`,space:`hsl`}},zn=e=>{let{h:n,s:r,l:i,opacity:o,space:s,unit:l}=e;if(s!==`hsl`)throw Error(`Space is expected to be 'hsl'. Got: ${s}`);if(l===`absolute`)t(a(n,`finite`,`h`),c(r,0,100,`s`),c(i,0,100,`l`),()=>{if(typeof o==`number`)return c(o,0,100,`opacity`)});else if(l===`scalar`)t(a(n,`percentage`,`h`),a(r,`percentage`,`s`),a(i,`percentage`,`l`),()=>{if(typeof o==`number`)return a(o,`percentage`,`opacity`)});else throw Error(`Unit is expected to be 'absolute' or 'scalar'. Got: ${l}`)};function Bn(e=.5,t=1,n=.5,r=1){let i={unit:`scalar`,space:`hsl`,h:e,s:t,l:n,opacity:r};return zn(i),i}function Vn(e=200,t=100,n=50,r=100){let i={unit:`absolute`,space:`hsl`,h:e,s:t,l:n,opacity:r};return zn(i),i}function Hn(e){if(e.startsWith(`hsla`))throw Error(`hsla() is not supported`);if(!e.startsWith(`hsl(`))throw Error(`Expected hsl(..) CSS colour`);let t=e.indexOf(`(`),n=e.indexOf(`)`);if(n<t)throw Error(`Is hsl() not terminated? Missing ')'`);let r=e.substring(t+1,n),i=r.split(/[\s,]+/);if(i.length<3)throw Error(`Expected three tokens. Got: ${i.length} length`);let a=!1;i[0].endsWith(`%`)&&(a=!0),i[1].endsWith(`%`)&&i[2].endsWith(`%`)&&(a=!0);let o=(e,t)=>{if(e===`none`)return 0;if(e.endsWith(`%`))return Number.parseFloat(e.substring(0,e.length-1))/100;e.endsWith(`deg`)&&t===0&&(e=e.substring(0,e.length-3));let n=Number.parseFloat(e);return t===0?n/360:t===3?n:n/100},s=(e,t)=>{if(e===`none`)return 0;if(e.endsWith(`%`)){let n=Number.parseFloat(e.substring(0,e.length-1));return t===0?n*360:n}if(e.endsWith(`deg`)&&t===0)return Number.parseFloat(e.substring(0,e.length-3));let n=Number.parseFloat(e);return n};return i.length>3&&i[3]===`/`&&(i=[i[0],i[1],i[2],i[4]]),a?Bn(o(i[0],0),o(i[1],1),o(i[2],2),o(i[3]??`100%`,3)):Vn(s(i[0],0),s(i[1],1),s(i[2],2),s(i[3]??`100%`,3))}function Un(e){if(typeof e==`string`){let t=Z(e,{scalar:!1});return Un(t)}e=Ln(e);let t=q({h:e.h,s:e.s,l:e.l});return{...t,alpha:(e.opacity??100)/100*255}}const Wn=.4,Gn=e=>{let{l:n,c:r,h:i,opacity:a,space:s,unit:l}=e;if(s!==`oklch`)throw Error(`Space is expected to be 'oklch'. Got: ${s}`);if(l===`absolute`)t(o(n,`l`),()=>{if(typeof r==`number`)return c(r,0,Wn,`c`)},()=>{if(typeof i==`number`)return c(r,0,360,`h`)},o(a??1,`opacity`));else if(l===`scalar`)t(o(n,`l`),o(r,`c`),o(i,`h`),o(e.opacity??1,`opacity`));else throw Error(`Unit is expected to be 'absolute' or 'scalar'. Got: ${l}`)};function Kn(e,n={}){if(e==null&&n.fallbackColour)return n.fallbackColour;let r=n.scalar??!0;return t(o(e.l,`l`),o(e.c,`c`),c(e.h,0,360,`h`),o(e.alpha??1,`alpha`)),r?Zn(e.l,e.c/Wn,e.h/360,e.alpha??1):Qn(e.l,e.c,e.h,e.alpha??1)}const qn=(e,t={})=>Kn(Bt(e),t),Jn=Object.freeze({l:0,c:0,h:0,opacity:0,unit:`absolute`,space:`oklch`});function Yn(e,t={}){if(e=e.toLowerCase(),e.startsWith(`#`))return qn(e,t);if(e===`transparent`)return Jn;if(Q[e]!==void 0)return qn(Q[e],t);if(e.startsWith(`rgb(`)){let n=ar(lr(e)),r=zt({r:n.r,g:n.g,b:n.b});return Kn(r,t)}if(!e.startsWith(`hsl(`)&&!e.startsWith(`oklch(`))try{let t=Tn(e,`oklch`);e=t}catch(n){if(t.fallbackString)e=t.fallbackString;else throw n}let n=new En(e),r=n.oklch;return Kn(r,t)}const Xn=(e,t=3)=>{Gn(e);let{l:n,c:r,h:i,opacity:a}=e,o=``;switch(e.unit){case`absolute`:o=`oklch(${(n*100).toFixed(t)}% ${r.toFixed(t)} ${i.toFixed(t)}`;break;case`scalar`:o=`oklch(${n.toFixed(t)} ${(r*Wn).toFixed(t)} ${(i*360).toFixed(t)}`;break}return a!==void 0&&a!==1&&(o+=` / ${a.toFixed(t)}`),o+=`)`,o};function Zn(e=.7,t=.1,n=.5,r=1){let i={unit:`scalar`,space:`oklch`,l:e,c:t,h:n,opacity:r};return Gn(i),i}const Qn=(e,t,n,r=1)=>{let i={space:`oklch`,unit:`absolute`,opacity:r,l:e,c:t,h:n};return Gn(i),i},$n=e=>{if(e.startsWith(`#`))return er(e,!0);if(Q[e]!==void 0)return er(Q[e],!0);if(e.startsWith(`--`)){let t=getComputedStyle(document.body).getPropertyValue(e).trim();if(t.length===0||t===null)throw Error(`Variable missing: ${e}`);return $n(t)}if(e=e.toLowerCase(),e.startsWith(`hsl(`))return Z(e,{scalar:!0});if(e.startsWith(`rgb(`))return nr(e,{scalar:!0});if(e.startsWith(`oklch(`))return Yn(e,{scalar:!0});throw Error(`String colour is not a hex colour, CSS variable nor well-defined colour. Input: '${e}'`)},Q={aliceblue:`#f0f8ff`,antiquewhite:`#faebd7`,aqua:`#00ffff`,aquamarine:`#7fffd4`,azure:`#f0ffff`,beige:`#f5f5dc`,bisque:`#ffe4c4`,black:`#000000`,blanchedalmond:`#ffebcd`,blue:`#0000ff`,blueviolet:`#8a2be2`,brown:`#a52a2a`,burlywood:`#deb887`,cadetblue:`#5f9ea0`,chartreuse:`#7fff00`,chocolate:`#d2691e`,coral:`#ff7f50`,cornflowerblue:`#6495ed`,cornsilk:`#fff8dc`,crimson:`#dc143c`,cyan:`#00ffff`,darkblue:`#00008b`,darkcyan:`#008b8b`,darkgoldenrod:`#b8860b`,darkgray:`#a9a9a9`,darkgreen:`#006400`,darkkhaki:`#bdb76b`,darkmagenta:`#8b008b`,darkolivegreen:`#556b2f`,darkorange:`#ff8c00`,darkorchid:`#9932cc`,darkred:`#8b0000`,darksalmon:`#e9967a`,darkseagreen:`#8fbc8f`,darkslateblue:`#483d8b`,darkslategray:`#2f4f4f`,darkturquoise:`#00ced1`,darkviolet:`#9400d3`,deeppink:`#ff1493`,deepskyblue:`#00bfff`,dimgray:`#696969`,dodgerblue:`#1e90ff`,firebrick:`#b22222`,floralwhite:`#fffaf0`,forestgreen:`#228b22`,fuchsia:`#ff00ff`,gainsboro:`#dcdcdc`,ghostwhite:`#f8f8ff`,gold:`#ffd700`,goldenrod:`#daa520`,gray:`#808080`,green:`#008000`,greenyellow:`#adff2f`,honeydew:`#f0fff0`,hotpink:`#ff69b4`,indianred:`#cd5c5c`,indigo:`#4b0082`,ivory:`#fffff0`,khaki:`#f0e68c`,lavender:`#e6e6fa`,lavenderblush:`#fff0f5`,lawngreen:`#7cfc00`,lemonchiffon:`#fffacd`,lightblue:`#add8e6`,lightcoral:`#f08080`,lightcyan:`#e0ffff`,lightgoldenrodyellow:`#fafad2`,lightgray:`#d3d3d3`,lightgreen:`#90ee90`,lightpink:`#ffb6c1`,lightsalmon:`#ffa07a`,lightseagreen:`#20b2aa`,lightskyblue:`#87cefa`,lightslategray:`#778899`,lightsteelblue:`#b0c4de`,lightyellow:`#ffffe0`,lime:`#00ff00`,limegreen:`#32cd32`,linen:`#faf0e6`,magenta:`#ff00ff`,maroon:`#800000`,mediumaquamarine:`#66cdaa`,mediumblue:`#0000cd`,mediumorchid:`#ba55d3`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumslateblue:`#7b68ee`,mediumspringgreen:`#00fa9a`,mediumturquoise:`#48d1cc`,mediumvioletred:`#c71585`,midnightblue:`#191970`,mintcream:`#f5fffa`,mistyrose:`#ffe4e1`,moccasin:`#ffe4b5`,navajowhite:`#ffdead`,navy:`#000080`,oldlace:`#fdf5e6`,olive:`#808000`,olivedrab:`#6b8e23`,orange:`#ffa500`,orangered:`#ff4500`,orchid:`#da70d6`,palegoldenrod:`#eee8aa`,palegreen:`#98fb98`,paleturquoise:`#afeeee`,palevioletred:`#db7093`,papayawhip:`#ffefd5`,peachpuff:`#ffdab9`,peru:`#cd853f`,pink:`#ffc0cb`,plum:`#dda0dd`,powderblue:`#b0e0e6`,purple:`#800080`,rebeccapurple:`#663399`,red:`#ff0000`,rosybrown:`#bc8f8f`,royalblue:`#4169e1`,saddlebrown:`#8b4513`,salmon:`#fa8072`,sandybrown:`#f4a460`,seagreen:`#2e8b57`,seashell:`#fff5ee`,sienna:`#a0522d`,silver:`#c0c0c0`,skyblue:`#87ceeb`,slateblue:`#6a5acd`,slategray:`#708090`,snow:`#fffafa`,springgreen:`#00ff7f`,steelblue:`#4682b4`,tan:`#d2b48c`,teal:`#008080`,thistle:`#d8bfd8`,tomato:`#ff6347`,turquoise:`#40e0d0`,violet:`#ee82ee`,wheat:`#f5deb3`,white:`#ffffff`,whitesmoke:`#f5f5f5`,yellow:`#ffff00`,yellowgreen:`#9acd32`,transparent:`#00000000`};function er(e,t=!0){return ir(G(e),{scalar:t})}const tr=Object.freeze({r:0,g:0,b:0,opacity:0,unit:`8bit`,space:`srgb`});function nr(e,t={}){if(e=e.toLowerCase(),e.startsWith(`hsla(`))throw Error(`hsla() not supported`);if(e.startsWith(`rgba(`))throw Error(`rgba() not supported`);let n=t.scalar??!0;if(e.startsWith(`#`))return er(e,n);if(e===`transparent`)return tr;if(Q[e]!==void 0&&er(Q[e],n),e.startsWith(`hsl(`)){let n=Un(e);return ir(n,t)}if(!e.startsWith(`rgb(`))try{e=Tn(e,`rgb`)}catch(n){if(t.fallbackString)e=t.fallbackString;else throw n}try{let t=lr(e);return n?or(t):ar(t)}catch(e){if(t.fallbackColour)return t.fallbackColour;throw e}}const rr=e=>{switch($(e),e.unit){case`8bit`:return e.opacity===void 0||e.opacity===255?`rgb(${e.r} ${e.g} ${e.b})`:`rgb(${e.r} ${e.g} ${e.b} / ${(e.opacity??255)/255})`;case`scalar`:return e.opacity===void 0||e.opacity===1?`rgb(${e.r*100}% ${e.g*100}% ${e.b*100}%)`:`rgb(${e.r*100}% ${e.g*100}% ${e.b*100}% / ${(e.opacity??1)*100}%)`;default:throw Error(`Unknown unit: ${e.unit}`)}};function ir(e,t={}){return t.scalar?{r:e.r/255,g:e.g/255,b:e.b/255,opacity:e.alpha??1,unit:`scalar`,space:`srgb`}:{r:e.r,g:e.g,b:e.b,opacity:e.alpha??255,unit:`8bit`,space:`srgb`}}const ar=e=>typeof e==`string`?nr(e,{scalar:!1}):Dn(e)?ar(ir(Un(e),{scalar:!1})):($(e),e.unit===`8bit`?e:{r:e.r*255,g:e.g*255,b:e.b*255,opacity:(e.opacity??1)*255,unit:`8bit`,space:`srgb`}),or=e=>typeof e==`string`?nr(e,{scalar:!0}):Dn(e)?or(ir(Un(e),{scalar:!0})):($(e),e.unit===`scalar`?e:{r:e.r/255,g:e.g/255,b:e.b/255,opacity:(e.opacity??1)/255,unit:`scalar`,space:`srgb`}),$=e=>{let{r:n,g:r,b:i,opacity:o,space:s,unit:l}=e;if(s!==`srgb`)throw Error(`Space is expected to be 'srgb'. Got: ${s}`);if(l===`8bit`)t(c(n,0,255,`r`),c(r,0,255,`g`),c(i,0,255,`b`),()=>{if(typeof o==`number`)return c(o,0,255,`opacity`)});else if(l===`scalar`)t(a(n,`percentage`,`r`),a(r,`percentage`,`g`),a(i,`percentage`,`b`),()=>{if(typeof o==`number`)return a(o,`percentage`,`opacity`)});else throw Error(`Unit is expected to be '8bit' or 'scalar'. Got: ${l}`)};function sr(e=100,t=100,n=100,r=255){let i={unit:`8bit`,space:`srgb`,r:e,g:t,b:n,opacity:r};return $(i),i}function cr(e=.5,t=.5,n=.5,r=1){let i={unit:`scalar`,space:`srgb`,r:e,g:t,b:n,opacity:r};return $(i),i}function lr(e){if(e.startsWith(`rgba`))throw Error(`RGBA is not supported`);if(!e.startsWith(`rgb(`))throw Error(`Expected rgb(..) CSS colour`);let t=e.indexOf(`(`),n=e.indexOf(`)`);if(n<t)throw Error(`Is rgb() not terminated? Missing ')'`);let r=e.substring(t+1,n),i=r.split(/[\s,]+/);if(i.length<3)throw Error(`Expected three tokens. Got: ${i.length} length`);let a=0;for(let e of i)e.endsWith(`%`)&&a++;let o=(e,t)=>e.endsWith(`%`)?Number.parseFloat(e.substring(0,e.length-1))/100:t<3?Number.parseFloat(e)/255:Number.parseFloat(e),s=(e,t)=>e.endsWith(`%`)?Number.parseFloat(e.substring(0,e.length-1))/100*255:t<3?Number.parseFloat(e):Number.parseFloat(e)*255;return i.length>3&&i[3]===`/`&&(i=[i[0],i[1],i[2],i[4]]),a>1?cr(o(i[0],0),o(i[1],1),o(i[2],2),o(i[3]??`1`,3)):sr(s(i[0],0),s(i[1],1),s(i[2],2),s(i[3]??`1`,3))}function ur(e){if(typeof e==`string`){let t=nr(e,{scalar:!1});return ur(t)}e=ar(e);let t=K({r:e.r,g:e.g,b:e.b});return{...t,alpha:(e.opacity??255)/255}}const dr=e=>{if(typeof e==`string`)return e;if(Dn(e))return Fn(e);if(On(e))return rr(e);if(jn(e))return Xn(e);let t=kn(e);if(t)return rr(t);let n=An(e);if(n)return Fn(n);throw Error(`Unknown colour format: '${JSON.stringify(e)}'`)},fr=e=>{switch(e.space){case`hsl`:zn(e);break;case`srgb`:$(e);break;default:throw Error(`Unknown colour space: '${e.space}'`)}},pr=e=>{if(!Mn(e))throw Error(`Could not parse input. Expected CSS colour string or structured colour {r,g,b}, {h,s,l} etc.`);let t;if(t=typeof e==`string`?$n(e):e,t===void 0)throw Error(`Could not parse input. Expected CSS colour string or structured colour {r,g,b}, {h,s,l} etc.`);return fr(t),t};function mr(e,t={}){let n=gr(e,t),r=n.el,i=t.relative??!1,a=t.inverted??!1,o=nt(n,e=>Number.parseFloat(e));i&&(r.max=a?`0`:`1`,r.min=a?`1`:`0`,r.hasAttribute(`step`)||(r.step=`0.1`)),r.getAttribute(`type`)===null&&(r.type=`range`);let s=e=>{n.set(e.toString())};return{...o,last(){return Number.parseFloat(n.last())},set:s}}function hr(e,t={}){let n=gr(e,{...t,upstreamFilter:e=>typeof e==`object`?dr(e):e}),r=nt(n,e=>Z(e,{scalar:!0,ensureSafe:!0}));return{...r,last(){return Z(n.last(),{scalar:!0,ensureSafe:!0})},set(e){n.set(Fn(e))}}}function gr(e,t={}){let n=typeof e==`string`?document.querySelector(e):e;if(n===null&&typeof e==`string`)throw Error(`Element query could not be resolved '${e}'`);if(n===null)throw Error(`targetOrQuery is null`);let r=C(e),i=t.when??`changed`,a=i===`changed`?`change`:`input`,o=t.emitInitialValue??!1,s=t.fallbackValue??``,c=t.upstreamSource,l=()=>{},u=t.attributeName,d=t.fieldName;d===void 0&&u===void 0&&(u=d=`value`);let f=()=>{let e;return u&&(e=r.getAttribute(u)),d&&(e=r[d]),e??=s,e},p=e=>{u&&r.setAttribute(u,e),d&&(r[d]=e)},m=e=>{e=t.upstreamFilter?t.upstreamFilter(e):e,p(e)};c&&(l=c.onValue(m),x(c)&&m(c.last()));let h=et(r,a,{fireInitial:o,debugFiring:t.debugFiring??!1,debugLifecycle:t.debugLifecycle??!1}),g=nt(h,e=>f());return{...g,el:r,last(){return f()},set(e){p(e)},dispose(e){l(),g.dispose(e),h.dispose(e)}}}function _r(e,t={}){let n=C(e),r=t.when??`changed`,i=r===`changed`?`change`:`input`,a=t.emitInitialValue??!1,o=t.upstreamSource,s=new Map,c=()=>{},l=()=>{let e=new FormData(n),t=[];for(let[n,r]of e.entries()){let e=r.toString(),i=s.get(n);if(!i){let t=u(n,e);t&&(i=t.type===`range`||t.type===`number`?`number`:t.type===`color`?`colour`:t.type===`checkbox`&&(r===`true`||r===`on`)?`boolean`:`string`,s.set(n,i))}if(i===`number`)t.push([n,Number.parseFloat(e)]);else if(i===`boolean`){let r=e===`true`;t.push([n,r])}else if(i===`colour`){let r=dr(e);t.push([n,nr(r,{scalar:!1})])}else t.push([n,r.toString()])}for(let e of n.querySelectorAll(`input[type="checkbox"]`))!e.checked&&e.value===`true`&&t.push([e.name,!1]);let r=Object.fromEntries(t);return r},u=(e,t)=>{let r=n.querySelector(`[name="${e}"]`);if(!r){console.warn(`Form does not contain an element with name="${e}"`);return}if(r.type===`radio`){let r=n.querySelector(`[name="${e}"][value="${t}"]`);if(!r){console.warn(`Form does not contain radio option for name=${e} value=${t}`);return}return r}return r},d=(e,t)=>{let n=u(e,t);if(n&&(n.nodeName===`INPUT`||n.nodeName===`SELECT`)){if(n.type===`color`)typeof t==`object`&&(t=dr(t));else if(n.type===`checkbox`)if(typeof t==`boolean`){n.checked=t;return}else console.warn(`Rx.Sources.domForm: Trying to set non boolean type to a checkbox. Name: ${e} Value: ${t} (${typeof t})`);else if(n.type===`radio`){n.checked=!0;return}n.value=t}},f=e=>{for(let[n,r]of Object.entries(e)){let e=s.get(n);e||(e=typeof r,e===`object`&&(pr(r),e=`colour`),s.set(n,e));let i=t.upstreamFilter?t.upstreamFilter(n,r):r;d(n,i)}};o&&(c=o.onValue(f),x(o)&&f(o.last()));let p=et(n,i,{fireInitial:a,debugFiring:t.debugFiring??!1,debugLifecycle:t.debugLifecycle??!1}),m=nt(p,e=>l());return{...m,el:n,last(){return l()},set:f,setNamedValue:d,dispose(e){c(),m.dispose(e),p.dispose(e)}}}function vr(e){let t=[...document.querySelectorAll(e)];return Ze(t)}const yr=(e,t,n={})=>Sr(e,t,{...n,elField:`textContent`}),br=(e,t,n={})=>Sr(e,t,{...n,elField:`value`,attribName:`value`}),xr=(e,t,n={})=>Sr(e,t,{...n,elField:`innerHTML`}),Sr=(e,t,...n)=>{if(t===null)throw Error(`Param 'elOrQuery' is null`);if(t===void 0)throw Error(`Param 'elOrQuery' is undefined`);let r=C(t),i=[];n.length===0?i.push({elField:`textContent`}):i=[...n];let a=i.map(e=>`element`in e?e:{...e,element:r});return Er(e,...a)},Cr=(e,t)=>{let n=wr(e);return e=>{n(e,t)}},wr=e=>{if(e.elField!==void 0||e.cssVariable===void 0&&e.attribName===void 0&&e.cssProperty===void 0&&e.textContent===void 0&&e.htmlContent===void 0){let t=e.elField??`textContent`;return(e,n)=>{n[t]=e}}if(e.attribName!==void 0){let t=e.attribName;return(e,n)=>{n.setAttribute(t,e)}}if(e.textContent)return(e,t)=>{t.textContent=e};if(e.htmlContent)return(e,t)=>{t.innerHTML=e};if(e.cssVariable!==void 0){let t=e.cssVariable;return t.startsWith(`--`)||(t=`--`+t),(e,n)=>{n.style.setProperty(t,e)}}return e.cssProperty===void 0?(e,t)=>{}:(t,n)=>{n.style[e.cssProperty]=t}},Tr=e=>{if(!(!e.transform&&!e.transformValue)){if(e.transformValue){if(e.sourceField===void 0)throw Error(`Expects 'sourceField' to be set when 'transformValue' is set`);return t=>{let n=t[e.sourceField];return e.transformValue(n)}}else if(e.transform){if(e.sourceField!==void 0)throw Error(`If 'transform' is set, 'sourceField' is ignored`);return t=>e.transform(t)}}},Er=(e,...t)=>{let n=t.map(e=>{if(e.element&&e.element!==void 0)return e;if(e.query)return{...e,element:C(e.query)};throw Error(`Unable to resolve element. Missing 'element' or 'query' values on bind. ${JSON.stringify(e)}`)}),r=n.map(e=>({update:Cr(e,e.element),transformer:Tr(e),sourceField:e.sourceField})),i=e=>{for(let t of r)if(t.transformer)t.update(t.transformer(e));else{let n=t.sourceField?e[t.sourceField]:e;typeof n==`object`?(t.sourceField,t.update(JSON.stringify(n))):t.update(n)}},a=e.on(e=>{Ge(e)?i(e.value):We(e)&&console.warn(e)});return x(e)&&i(e.last()),{remove:e=>{if(a(),e)for(let e of n)e.element.remove()}}},Dr=(e,t,n)=>{let r=C(t),i=e=>{n(e,r)},a=e.on(e=>{Ge(e)?(console.log(e),i(e.value)):console.warn(e)});return x(e)&&i(e.last()),{remove:e=>{a(),e&&r.remove()}}},Or=(e,t,n,r={})=>{if(t===null)throw Error(`Param 'elOrQuery' is null`);if(t===void 0)throw Error(`Param 'elOrQuery' is undefined`);let i=C(t),a=e=>{n(e,i)},o=e.onDiff(e=>{a(e)}),s=()=>{x(e)&&r.initial&&r.initial(e.last(),i)};return s(),{refresh:()=>{s()},remove:e=>{o(),e&&i.remove()}}},kr=(e,t)=>{let n=t.container?C(t.container):document.body,r=t.defaultTag??`div`,i=new Map,a=new Map;for(let[e,n]of Object.entries(t.binds??{})){let t=n.tagName??r;a.set(e,{...n,update:wr(n),transform:Tr(n),tagName:t,path:e})}let o=e=>{let t=Ne(a,p(e));if(t!==void 0)return t;if(!e.includes(`.`))return a.get(`_root`)};function*s(e){for(let t of m(e))a.has(t)&&(yield a.get(t));a.has(`_root`)&&e.includes(`.`)&&(yield a.get(`_root`))}let c=(e,t)=>{let a=Ar(e);console.log(`Rx.Dom.elements.create: ${e} rooted: ${a} value: ${JSON.stringify(t)}`);let c=o(Ar(e)),u=r;c?.tagName&&(u=c.tagName);let d=document.createElement(u);d.setAttribute(`data-path`,e),l(e,d,t);let f;for(let t of s(a))if(t?.nestChildren){let n=h(e,`.`),r=t.path.replace(`_root`,n);if(f=i.get(r),f!==void 0)break}(f??n).append(d),i.set(e,d),console.log(`Added el: ${e}`)},l=(e,t,n)=>{console.log(`Rx.dom.update path: ${e} value:`,n);let r=o(Ar(e));r===void 0?(typeof n==`object`&&(n=JSON.stringify(n)),t.textContent=n):(r.transform&&(n=r.transform(n)),r.update(n,t))},u=e=>{let t=new je({},e),n=t.dequeue(),r=new Set;for(;n!==void 0;){let e=n.path;if(!(`previous`in n)||n.previous===void 0){console.log(`Rx.Dom.elements.changes no previous. path: ${e}`),c(e,n.value);let i=[...he(n.value,!1,2**53-1,e)];console.log(i);for(let e of i)r.has(e.path)||(t.enqueue(e),r.add(e.path))}else if(n.value===void 0){let t=i.get(e);t===void 0?console.warn(`No element to delete? ${e} `):(console.log(`Rx.Dom.elements.changes delete ${e}`),t.remove())}else{let t=i.get(e);t===void 0?(console.warn(`Rx.Dom.elements.changes No element to update ? ${e} `),c(e,n.value)):l(e,t,n.value)}n=t.dequeue()}};if(e.onDiff(e=>{u(e)}),x(e)){let t=e.last();u([...he(t,!1,1)])}},Ar=e=>{let t=g(e,`.`);return t===e?`_root`:`_root.`+t};function jr(){let e=()=>({width:window.innerWidth,height:window.innerHeight}),t=$e(window,`resize`,{lazy:`very`,transform:()=>e()}),n=$e(window,`pointermove`,{lazy:`very`,transform:e=>{if(e===void 0)return{x:0,y:0};let t=e;return{x:t.x,y:t.y}}}),r=(e=`Reactive.win.dispose`)=>{t.dispose(e),n.dispose(e)};return{dispose:r,size:t,pointer:n}}var Mr={};e(Mr,{bind:()=>Er,bindDiffUpdate:()=>Or,bindElement:()=>Sr,bindHtml:()=>xr,bindText:()=>yr,bindUpdate:()=>Dr,bindValueText:()=>br,browserResizeObservable:()=>ct,colour:()=>ut,cssClassChange:()=>lt,domForm:()=>_r,domHslInputValue:()=>hr,domInputValue:()=>gr,domNumberInputValue:()=>mr,elements:()=>kr,fromDomQuery:()=>vr,win:()=>jr});export{Mr as Rx};
2
+ //# sourceMappingURL=index.js.map