var St=Object.create;var v=Object.defineProperty;var dt=Object.getOwnPropertyDescriptor;var Tt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty;var xt=(r,t)=>{for(var e in t)v(r,e,{get:t[e],enumerable:!0})},et=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Tt(t))!bt.call(r,i)&&i!==e&&v(r,i,{get:()=>t[i],enumerable:!(n=dt(t,i))||n.enumerable});return r};var Pt=(r,t,e)=>(e=r!=null?St(gt(r)):{},et(t||!r||!r.__esModule?v(e,"default",{value:r,enumerable:!0}):e,r)),At=r=>et(v({},"__esModule",{value:!0}),r);var Ot={};xt(Ot,{Store:()=>F,adder:()=>L,appender:()=>R,composeActions:()=>rt,consoleLogger:()=>J,cycler:()=>z,fetcher:()=>at,mapper:()=>D,merger:()=>k,observable:()=>Q,persistState:()=>W,pipeActions:()=>it,remover:()=>U,replacePath:()=>x,replacer:()=>H,selectPath:()=>y,setter:()=>ot,setterInput:()=>st,shallowCopy:()=>g,shallowOverride:()=>d,syncUrl:()=>Z,toggler:()=>$,undo:()=>V,updatePath:()=>_,useStoreSelector:()=>O,useStoreState:()=>K});module.exports=At(Ot);var E=class{#t={};on=(t,e)=>(this.#t[t]||(this.#t[t]=[]),this.#t[t].push(e),this);hasSubscriber=t=>this.#t[t]?.length||this.#t["*"]?.length;off=(t,e)=>(this.#t[t]||(this.#t[t]=[]),this.#t[t]=this.#t[t].filter(n=>n!==e),this);once=(t,e)=>{let n=i=>{this.off(t,n),e.call(this,i)};return this.on(t,n),this};emit=(t,e=void 0)=>{let n={target:this,type:t,data:e};if(this.#t["*"]?.length>0)for(let i of this.#t["*"])i.call(this,n);if(this.#t[t]?.length>0)for(let i of this.#t[t])i.call(this,n);return n}};function u(r){return Array.isArray(r)}function d(r,t){if(u(r))return u(t)?[...r,...t]:[...r];if(r&&typeof r=="object"){let e={...r};return t&&typeof t=="object"&&Object.assign(e,t),e}else return t===void 0?r:t}var T=class r{#t={};#r=[];maxSize;constructor(t=1e3){this.maxSize=t}has(t){return t in this.#t}get(t){return this.#t[t]}set(t,e){this.#r.length>=this.maxSize&&this.#f(),this.#t[t]=e,this.#r.push(t)}get size(){return this.#r.length}#f(){let t=this.#r.shift();this.#t[t]=void 0}static memoize(t,e){let n=new r(t);return function(a){if(n.has(a))return n.get(a);let o=e(a);return n.set(a,o),o}}};var Et=r=>r;function Ft(r){if(r==="@")return Et;let t=r.split(/[\[\].]/).filter(Boolean);if(t.length===1)return function(i){return i[t[0]]};return function(i){return e(i,t)};function e(n,i){return i.length===0?n:i[0]==="*"&&u(n)?(i=i.slice(1),n.map(a=>e(a,i)).flat()):n&&i[0]in n?e(n[i[0]],i.slice(1)):void 0}}var vt=T.memoize(5e3,Ft),y=vt;function s(r){return typeof r=="function"}function g(r){return!r||typeof r=="string"?r:s(r[Symbol.iterator])?[...r]:typeof r=="object"?{...r}:r}function x(r,t,e){if(typeof t!="string")throw new Error("react-thermals: replacePath(path,transform) - path must be a string");let n=t.split(/[\[\].]/).filter(Boolean);if(n.length===0)throw new Error("react-thermals: replacePath(path,transform) path string cannot be empty");return w(r,n,e)}function w(r,t,e){if(!r)return r;let n=g(r);if(t[0]==="*"&&n instanceof Array)return t=t.slice(1),n.map(i=>t.length===0?s(e)?e(i):e:w(i,t,e));if(typeof n=="object"&&t[0]in n)t.length===1?n[t[0]]=s(e)?e(n[t[0]]):e:n[t[0]]=w(n[t[0]],t.slice(1),e);else if(typeof n=="object")if(t.length===1)n[t[0]]=s(e)?e(n[t[0]]):e;else if(t[1]==="*")n[t[0]]=[];else{let i=/^(\d+)$/.test(t[1])?[]:{};n[t[0]]=w(i,t.slice(1),e)}return n}function b(r){return s(r?.then)}var nt=1,F=class extends E{#t;#r=!1;#f;#i;#a=[];#c=[];#n=[];#e;#o=0;#s=[];#p=!1;id;locals;constructor(t=void 0,{autoReset:e=!1,id:n=""}={}){super(),this.on("BeforeInitialize",()=>{this.#r=!0}),this.#i=t,this.#e=t,this.id=String(n||`store-${nt}`),this.#f=nt++,this.#t=e,this.locals={}}attachComponent=t=>{this.#o++===0&&this.emit("BeforeFirstUse",this.#e),this.#n.length===0&&this.emit("AfterFirstMount"),this.#n.includes(t)||(this.#n.push(t),this.emit("AfterMount",this.#n.length)),this.#o===1&&this.emit("AfterFirstUse",this.#e)};detachComponent=t=>{let e=this.#n.indexOf(t);e>-1&&this.#n.splice(e,1),this.emit("AfterUnmount",this.#n.length),this.#n.length===0&&(this.#t&&(this.reset(),this.emit("AfterReset")),this.emit("AfterLastUnmount"))};getInitialState=()=>this.#i;getInitialStateAt=t=>y(t)(this.#i);getState=()=>this.#e;getStateAt=t=>y(t)(this.#e);reset=(t={})=>(this.resetState(t),this.#r=!1,this.#o=0,this);resetState=(t={})=>(this.setState(this.#i,t),this);resetStateAt=(t,e={})=>(this.setStateAt(t,this.getInitialStateAt(t),e),this);nextState=()=>new Promise(t=>{this.once("AfterUpdate",e=>t(e.data.next))});connect=(t,e,n=null)=>(...i)=>{this.setStateAt(t,e(...i)),n&&this.nextState().then(()=>{n(this.getStateAt(t))})};chain=(t,e)=>async()=>{let n=this.getStateAt(t);for(let i of e)n=await i(n);return this.setStateAt(t,n),n};getUsedCount=()=>this.#o;hasInitialized=()=>this.#r;getMountCount=()=>this.#n.length;plugin=t=>{let e=t(this);return this.#c.push(t),e};getPlugins=()=>this.#c;use=(...t)=>(this.#a.push(...t),this);#y=(t,e)=>{let n=0,i=()=>{n===this.#a.length?e():this.#a[n++](t,i)};i()};#u=(t,e)=>{if(this.#a.length===0&&!this.hasSubscriber("AfterUpdate")||e.bypassMiddleware||e.bypassAll){let i=this.#e;this.#e=t,this.#l(i,t,e);return}let n={prev:Object.freeze(this.#e),next:t,store:this};this.#y(n,()=>{if(this.#e=n.next,this.#s.length>0){let i=this.#s.shift();this.#s.length===0&&(this.#p=!1),this.setState(i,e)}else this.#l(n.prev,n.next,e)})};setState=(t,e={})=>this.#p?(this.#s.push(t),this):(s(t)&&(t=t(this.#e)),b(t)?(this.#p=!0,t.then(n=>this.#u(n,e),n=>this.emit("SetterRejection",n))):this.#u(t,e),this);setStateAt=(t,e,n={})=>{if(t==="@")return this.setState(e,n);let i=this.getStateAt(t);if(t.includes("*")&&u(i)&&s(e)?i=this.#h(i,e):s(e)?i=e(i):i=e,b(i))i.then(a=>{let o=x(this.#e,t,a);this.#u(o,n)},a=>this.emit("SetterRejection",a));else{let a=x(this.#e,t,i);this.#u(a,n)}return this};initState=t=>this.setState(t,{bypassAll:!0});initStateAt=(t,e)=>this.setStateAt(t,e,{bypassAll:!0});#h=(t,e)=>{let n=t.map(e),i=0;return n.some(b)?Promise.all(n).then(a=>()=>a[i++]):()=>n[i++]};mergeState=(t,e={})=>(this.setState(n=>(s(t)&&(t=t(n)),b(t)?t.then(i=>d(n,i)):d(n,t)),e),this);mergeStateAt=(t,e,n={})=>t==="@"?this.mergeState(e,n):(this.setStateAt(t,i=>(s(e)&&(e=e(i)),b(e)?e.then(a=>d(i,a)):d(i,e)),n),this);#l=(t,e,n)=>{this.#e=e,!n.bypassRender&&!n.bypassAll&&this.#n.forEach(i=>{this.#m(t,this.#e)(i)}),!n.bypassEvent&&!n.bypassAll&&Promise.resolve().then(()=>this.emit("AfterUpdate",{prev:t,next:this.#e}))};#m=(t,e)=>function(i){if(s(i.mapState)&&s(i.equalityFn)){let a=i.mapState(t),o=i.mapState(e);i.equalityFn(a,o)||i.handler(o)}else i.handler(e)};subscribe=P("observable","subscribe");undo=P("undo","undo");redo=P("undo","redo");jump=P("undo","jump");jumpTo=P("undo","jumpTo");getHistory=P("undo","getHistory")};function P(r,t){return function(){throw new Error(`Import ${r} and register it with "store.plugin(${r}())" to use the "store.${t}()" function.`)}}var A=require("react");var wt=["bigint","boolean","function","number","string","symbol","undefined"];function N(r,t){if(r===null&&t===null)return!0;if(r===null||t===null)return!1;if(typeof r=="number"&&isNaN(r)&&typeof t=="number"&&isNaN(t))return!0;if(wt.includes(typeof r))return r===t;if(u(r)){if(!u(t)||r.length!==t.length)return!1;for(let e=0,n=r.length;er;function I(r){if(typeof r=="string")return r.includes(".")?y(r):t=>t[r];if(typeof r=="number")return t=>t[r];if(u(r)){let t=r.map(I);return e=>t.map(n=>n(e))}else{if(s(r))return r;if(r==null)return It;throw new Error('react-thermals: "mapState" function must be a function, string, number, array, null, or undefined.')}}function O(r,t=void 0,e=void 0){let[n,i]=(0,A.useMemo)(()=>[I(t),e||N],[]),[a,o]=(0,A.useState)(()=>{let f=r.getState();return r.hasInitialized()||(r.emit("BeforeInitialize",f),f=r.getState(),r.emit("AfterInitialize",f)),n(f)});return(0,A.useEffect)(()=>{let f={mapState:n,equalityFn:i,handler:o};return r.attachComponent(f),()=>r.detachComponent(f)},[r,o]),a}var j=require("react");function K(r){let[t,e]=(0,j.useState)(()=>{let n=r.getState();return r.hasInitialized()||(r.emit("BeforeInitialize",n),n=r.getState(),r.emit("AfterInitialize",n)),n});return(0,j.useEffect)(()=>{let n={handler:e};return r.attachComponent(n),()=>r.detachComponent(n)},[r]),t}function L(r=0){return function(e=0){return n=>n+r+e}}function R(){return function(...t){return e=>!e||!u(e)?e:[...e,...t]}}function rt(r){return function(...e){let n;for(let i of r){let a=i(...e);n===void 0&&(n=a)}return n}}function it(r){return function(e){for(let n of r)e=n(e);return e}}function z(r){return function(){return e=>{let n=r.indexOf(e);return r[(n+1)%r.length]}}}function at(r,t={},e=n=>n.json()){return function(...i){return()=>{let a,o;return s(r)?a=r(...i):a=r,s(t)?o=t(...i):o=t,fetch(a,o).then(e)}}}function D(r){return function(){return e=>e.map(r)}}function k(){return function(t){return e=>({...e,...t})}}function U(){return function(...t){return e=>!e||!u(e)?e:e.filter(n=>!t.includes(n))}}function H(){return function(t,e){return n=>n.map(i=>i===t?s(e)?e(i):e:i)}}function ot(){return function(t){return t}}function st(){return function(t){return t.target.value}}function $(){return function(){return t=>!t}}function q(r=void 0){if(s(r))return function(e,n,...i){return s(n)&&(e=n(e,...i)),r(e,n,...i)};if(u(r)&&r.every(s))return function(e,...n){let i=e;for(let a of r)i=a(i,...n);return i};if(r===void 0)return jt;{throw new Error("react-thermals: updatePath(path,transform) - transform must be a function, an array of functions or undefined")}}function jt(r,t){return s(t)?t(r):t}var B=new T(5e3);function _(r,t=void 0){if(typeof r!="string")throw new Error("react-thermals: updatePath(path,transform) - path must be a string");if(t===void 0&&B.has(r))return B.get(r);let e=r.split(/[\[\].]/).filter(Boolean);if(e.length===0)throw new Error("updatePath path string cannot be empty");let n=q(t);if(r==="@")return n;e[0]==="@"&&e.shift();let i=Ct(n);function a(o,...f){return i(o,e,f)}return t===void 0&&B.set(r,a),a}function Ct(r){return function t(e,n,i){let a=g(e);if(n[0]==="*"&&a instanceof Array)return n=n.slice(1),a.map(o=>n.length===0?r(o,...i):t(o,n,i));if(typeof a=="object"&&n[0]in a)n.length===1?a[n[0]]=r(a[n[0]],...i):a[n[0]]=t(a[n[0]],n.slice(1),i);else if(typeof a=="object")if(n.length===1)a[n[0]]=r(void 0,...i);else if(n[1]==="*")a[n[0]]=[];else{let o=/^(\d+)$/.test(n[1])?[]:{};a[n[0]]=t(o,n.slice(1),i)}return a}}function J({eventTypes:r=["*"],logHandler:t=console.log}={}){return function(n){if(!u(r)||r.length===0)throw new Error("react-thermals: consoleLogger must receive one or more eventTypes");for(let i of r)n.on(i,a=>{t({storeId:n.id,eventType:a.type,event:a})})}}function Q(){return function(t){let e=[];t.subscribe=function(...i){let a;if(s(i[0])){let[o,f,h]=i;a={next:o,error:f,complete:h}}else a=i[0];if(typeof a?.next!="function")throw new Error("react-thermals: observable plugin requires that observer.next be a function");return e.push(a),{unsubscribe(){let o=e.indexOf(a);o>-1&&e.splice(o,1)}}},t.on("AfterUpdate",n=>{for(let i of e)i.next(n.data.next)}),t.on("SetterRejection",n=>{for(let i of e)i.error?.(n.data)}),t.on("AfterLastUnmount",()=>{for(let n of e)n.complete?.()})}}function ut(r,t){try{return r(t)}catch(e){console.error("react-thermals: persistState plugin parse error: ",e);return}}function ft(r,t){try{return r(t)}catch(e){return console.error("react-thermals: persistState plugin stringify error: ",e),""}}function W({key:r=void 0,path:t="@",storage:e=localStorage,parse:n=JSON.parse,stringify:i=JSON.stringify}){if(typeof e?.getItem!="function"||typeof e?.setItem!="function")throw new Error("react-thermals: persistState plugin must receive a Storage object such as localStorage or sessionStorage");return function(f){r||(r=f.id),f.on("BeforeInitialize",h=>{let m=e.getItem(r),p;m&&(p=ut(n,m)),p===void 0&&(p=y(t)(h.data)),p!==void 0&&f.setStateAt(t,p,{bypassAll:!0}),a(p)}),f.on("AfterUpdate",h=>a(y(t)(h.data.next)))};function a(o){e.setItem(r,ft(i,o))}}var G=Pt(require("any-date-parser"),1);function pt(r,t){let e={};for(let[n,i]of Object.entries(t))e[n]=Mt(r,n,i);return e}function ct(r,t){let e={};for(let[n,i]of Object.entries(t))e[n]=Nt(r,n,i);return e}function Mt(r,t,e){let n=r[t];if(!n)return e;switch(n.toLowerCase()){case"string":case"string[]":case"number":case"number[]":return String(e);case"date":let i=G.default.fromString(e);return new Intl.DateTimeFormat().format(i);case"date[]":return e.map(a=>{let o=G.default.fromString(a);return new Intl.DateTimeFormat().format(o)});case"boolean":return e?"true":"false";case"boolean[]":return e.map(a=>a?"true":"false");default:throw new Error(`react-thermals: unknown schema type "${n}"`)}}function Nt(r,t,e){let n=r[t];if(!n)return e;switch(n.toLowerCase()){case"string":return e;case"string[]":return e.split(",");case"number":return parseFloat(e);case"number[]":return e.split(",").map(parseFloat);case"date":return new Date(Date.parse(e));case"date[]":return e.split(",").map(i=>new Date(Date.parse(i)));case"boolean":return e==="true";case"boolean[]":return e.split(",").map(i=>i==="true");default:throw new Error(`react-thermals: unknown schema type "${n}"`)}}function lt(r){let t={};for(let[e,n]of new URLSearchParams(r))t[e]=n;return t}function yt(r){let t=new URLSearchParams(r);return t.sort(),t.toString()}function X(r){for(let t in r){if(Object.prototype.hasOwnProperty.call(r,t))return!1}return!0}function ht(r,t){let e={};for(let[n,i]of Object.entries(t))r.includes(n)&&(e[n]=i);return e}function mt(r,t){let e={};for(let[n,i]of Object.entries(t))r.includes(n)||(e[n]=i);return e}function C(r){history.replaceState({},document.title,r)}function Y(r){history.pushState({},document.title,r)}function Z({fields:r=void 0,schema:t=void 0,replace:e=!1,parse:n=lt,stringify:i=yt}={}){if(r&&t||!r&&!t)throw new Error('react-thermals: syncUrl must receive "fields" or "schema" but not both');let a=t||{},o=r||Object.keys(a);return function(c){c.on("BeforeInitialize",S=>{let tt=n(location.search.slice(1)),M=ht(o,tt);M&&!X(M)&&c.mergeState(ct(a,M),{bypassAll:!0}),f(pt(a,{...tt,...S.data}))}),c.on("AfterUpdate",S=>{h(S.data.next)}),c.on("AfterLastUnmount",m)};function f(l){let c="?"+i(l);C(c)}function h(l){let c=p(l);e?C(c):Y(c)}function m(){let l=n(location.search),c=mt(o,l),S="?"+i(c);e?C(S):Y(S)}function p(l){let S={...n(location.search),...l};return"?"+i(S)}}function V({maxSize:r=100}={}){return function(e){let n=0,i=!1,a=[];e.undo=o,e.redo=f,e.jump=h,e.jumpTo=m,e.getHistory=()=>a,e.on("AfterFirstMount",()=>{a.push(e.getState())}),e.on("AfterLastUnmount",()=>{a.length=0,n=0}),e.on("AfterUpdate",p=>{if(i){i=!1;return}nr?a.shift():n++});function o(){return n>0&&m(n-1),e}function f(){return n=a.length){let l=Number(p);throw new Error(`react-thermals: undo plugin - invalid history index ${l}; history size is ${a.length}.`)}return e.setState(a[p]),i=!0,n=p,e}}}0&&(module.exports={Store,adder,appender,composeActions,consoleLogger,cycler,fetcher,mapper,merger,observable,persistState,pipeActions,remover,replacePath,replacer,selectPath,setter,setterInput,shallowCopy,shallowOverride,syncUrl,toggler,undo,updatePath,useStoreSelector,useStoreState}); /* istanbul ignore next @preserve */