!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("valtio/vanilla"),require("derive-valtio")):"function"==typeof define&&define.amd?define(["exports","valtio/vanilla","derive-valtio"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).valtioVanillaUtils={},t.valtioVanilla,t.deriveValtio)}(this,(function(t,e,r){"use strict";function n(t,e,r,n){var o={configurable:!0,enumerable:!0};return o[t]=n,Object.defineProperty(e,r,o)}function o(){o=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var o=e&&e.prototype instanceof g?e:g,a=Object.create(o.prototype),u=new k(n||[]);return i(a,"_invoke",{value:_(t,r,u)}),a}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=l;var p="suspendedStart",d="suspendedYield",y="executing",v="completed",b={};function g(){}function m(){}function w(){}var O={};f(O,u,(function(){return this}));var x=Object.getPrototypeOf,j=x&&x(x(A([])));j&&j!==r&&n.call(j,u)&&(O=j);var E=w.prototype=g.prototype=Object.create(O);function S(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function L(t,e){function r(o,i,a,u){var c=h(t[o],t,i);if("throw"!==c.type){var s=c.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}var o;i(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}})}function _(e,r,n){var o=p;return function(i,a){if(o===y)throw new Error("Generator is already running");if(o===v){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=P(u,n);if(c){if(c===b)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var s=h(e,r,n);if("normal"===s.type){if(o=n.done?v:d,s.arg===b)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=v,n.method="throw",n.arg=s.arg)}}}function P(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,P(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),b;var i=h(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,b;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,b):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,b)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function N(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function A(e){if(e||""===e){var r=e[u];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),N(r),b}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;N(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:A(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),b}},e}function i(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function a(){return a=Object.assign?Object.assign.bind():function(t){for(var e=1;e=0||(o[r]=t[r]);return o}(o,c);try{n=null!=i&&i&&window.__REDUX_DEVTOOLS_EXTENSION__}catch(t){}if(n){var h=!1,p=n.connect(a({name:f},l)),d=e.subscribe(t,(function(r){var n=r.filter((function(t){return t[0],t[1][0]!==s})).map((function(t){return t[0]+":"+t[1].map(String).join(".")})).join(", ");if(n)if(h)h=!1;else{var o=Object.assign({},e.snapshot(t));delete o[s],p.send({type:n,updatedAt:(new Date).toLocaleString()},o)}})),y=p.subscribe((function(r){var n,o;if("ACTION"===r.type&&r.payload)try{Object.assign(t,JSON.parse(r.payload))}catch(t){console.error("please dispatch a serializable value that JSON.parse() and proxy() support\n",t)}if("DISPATCH"===r.type&&r.state){var i,a;if("JUMP_TO_ACTION"===(null==(i=r.payload)?void 0:i.type)||"JUMP_TO_STATE"===(null==(a=r.payload)?void 0:a.type)){h=!0;var u=JSON.parse(r.state);Object.assign(t,u)}t[s]=r}else if("DISPATCH"===r.type&&"COMMIT"===(null==(n=r.payload)?void 0:n.type))p.init(e.snapshot(t));else if("DISPATCH"===r.type&&"IMPORT_STATE"===(null==(o=r.payload)?void 0:o.type)){var c,f,l=null==(c=r.payload.nextLiftedState)?void 0:c.actionsById,d=(null==(f=r.payload.nextLiftedState)?void 0:f.computedStates)||[];h=!0,d.forEach((function(r,n){var o=r.state,i=l[n]||"No action found";Object.assign(t,o),0===n?p.init(e.snapshot(t)):p.send(i,e.snapshot(t))}))}}));return p.init(e.snapshot(t)),function(){d(),null==y||y()}}},t.proxyMap=function(t){var r,o=e.proxy((n("get",r={data:Array.from(t||[]),has:function(t){return this.data.some((function(e){return e[0]===t}))},set:function(t,e){var r=this.data.find((function(e){return e[0]===t}));return r?r[1]=e:this.data.push([t,e]),this},get:function(t){var e;return null==(e=this.data.find((function(e){return e[0]===t})))?void 0:e[1]},delete:function(t){var e=this.data.findIndex((function(e){return e[0]===t}));return-1!==e&&(this.data.splice(e,1),!0)},clear:function(){this.data.splice(0)},get size(){return this.data.length},toJSON:function(){return new Map(this.data)},forEach:function(t){var e=this;this.data.forEach((function(r){t(r[1],r[0],e)}))},keys:function(){return this.data.map((function(t){return t[0]})).values()},values:function(){return this.data.map((function(t){return t[1]})).values()},entries:function(){return new Map(this.data).entries()}},Symbol.toStringTag,(function(){return"Map"})),r[Symbol.iterator]=function(){return this.entries()},r));return Object.defineProperties(o,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(o),o},t.proxySet=function(t){var r,o=e.proxy((n("get",r={data:Array.from(new Set(t)),has:function(t){return-1!==this.data.indexOf(t)},add:function(t){var r=!1;return"object"==typeof t&&null!==t&&(r=-1!==this.data.indexOf(e.proxy(t))),-1!==this.data.indexOf(t)||r||this.data.push(t),this},delete:function(t){var e=this.data.indexOf(t);return-1!==e&&(this.data.splice(e,1),!0)},clear:function(){this.data.splice(0)},get size(){return this.data.length},forEach:function(t){var e=this;this.data.forEach((function(r){t(r,r,e)}))}},Symbol.toStringTag,(function(){return"Set"})),r.toJSON=function(){return new Set(this.data)},r[Symbol.iterator]=function(){return this.data[Symbol.iterator]()},r.values=function(){return this.data.values()},r.keys=function(){return this.data.values()},r.entries=function(){return new Set(this.data).entries()},r));return Object.defineProperties(o,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(o),o},t.proxyWithComputed=function(t,r){Object.keys(r).forEach((function(o){if(Object.getOwnPropertyDescriptor(t,o))throw new Error("object property already defined");var i=r[o],a="function"==typeof i?{get:i}:i,u=a.get,c=a.set,s={get:function(){return u(e.snapshot(n))}};c&&(s.set=function(t){return c(n,t)}),Object.defineProperty(t,o,s)}));var n=e.proxy(t);return n},t.proxyWithHistory=function(t,r){void 0===r&&(r=!1);var n=e.proxy({value:t,history:e.ref({wip:void 0,snapshots:[],index:-1}),clone:l,canUndo:function(){return n.history.index>0},undo:function(){n.canUndo()&&(n.value=n.history.wip=n.clone(n.history.snapshots[--n.history.index]))},canRedo:function(){return n.history.index