1 | !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).jotaiVanilla={})}(this,(function(n){"use strict";var t=0;function r(n,t){(null==t||t>n.length)&&(t=n.length);for(var r=0,e=new Array(t);r<t;r++)e[r]=n[r];return e}function e(n,t){var e="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(e)return(e=e.call(n)).next.bind(e);if(Array.isArray(n)||(e=function(n,t){if(n){if("string"==typeof n)return r(n,t);var e=Object.prototype.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(n):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?r(n,t):void 0}}(n))||t&&n&&"number"==typeof n.length){e&&(n=e);var o=0;return function(){return o>=n.length?{done:!0}:{done:!1,value:n[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=function(n){return"init"in n},a=function(n){return!!n.write},u=new WeakMap,f=function(n,t){var r=u.get(n);r&&(u.delete(n),r(t))},c=function(n,t){return"v"in n&&"v"in t&&Object.is(n.v,t.v)},l=function(n){return"v"in n&&n.v instanceof Promise},v=function(n){if("e"in n)throw n.e;return n.v},d=function(){var n=new WeakMap,t=new WeakMap,r=new Map,o=function(t){return n.get(t)},d=function(t,e){var o=n.get(t);if(n.set(t,e),r.has(t)||r.set(t,o),o&&l(o)){var i="v"in e?e.v instanceof Promise?e.v:Promise.resolve(e.v):Promise.reject(e.e);f(o.v,i)}},s=function(n,t,r){var e=new Map,i=!1;r.forEach((function(r){var a=r===n?t:o(r);a&&(e.set(r,a),t.d.get(r)!==a&&(i=!0))})),(i||t.d.size!==e.size)&&(t.d=e)},y=function(n,t,r){var e=o(n),i={d:(null==e?void 0:e.d)||new Map,v:t};return r&&s(n,i,r),e&&c(e,i)&&e.d===i.d?e:(d(n,i),i)},p=function(n,t,r){var e,i,a=o(n),u={d:(null==a?void 0:a.d)||new Map,e:t};return r&&s(n,u,r),a&&(i=u,"e"in(e=a)&&"e"in i&&Object.is(e.e,i.e))&&a.d===u.d?a:(d(n,u),u)},g=function n(r,e){if(!e){var f=o(r);if(f&&(f.d.forEach((function(e,o){o===r||t.has(o)||n(o)})),Array.from(f.d).every((function(n){var t=n[0],e=n[1];return t===r||o(t)===e}))))return f}var c,l,d=new Set,s=!0,g={get signal(){return c||(c=new AbortController),c.signal},get setSelf(){return!l&&a(r)&&(l=function(){if(!s){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];return b.apply(void 0,[r].concat(t))}}),l}};try{var h=r.read((function(t){if(d.add(t),t===r){var e=o(t);if(e)return v(e);if(i(t))return t.init;throw new Error("no atom init")}var a=n(t);return v(a)}),g);if(h instanceof Promise){var w,m=new Promise((function(n,t){h.then((function(t){m.status="fulfilled",m.value=t,n(t)}),(function(n){m.status="rejected",m.reason=n,t(n)})).finally((function(){y(r,m,d)})),w=function(t){return n(t)}}));return m.status="pending",function(n,t){u.set(n,t),n.catch((function(){})).finally((function(){return u.delete(n)}))}(m,(function(n){var t;n&&w(n),null==(t=c)||t.abort()})),y(r,m,d)}return y(r,h,d)}catch(n){return p(r,n,d)}finally{s=!1}},h=function(n,t){return!t.l.size&&(!t.t.size||1===t.t.size&&t.t.has(n))},w=function n(r){var e=t.get(r);null==e||e.t.forEach((function(t){if(t!==r){var e=o(t),i=g(t);e&&c(e,i)||n(t)}}))},m=function n(t){for(var r=!0,e=function(n){return v(g(n))},a=function(e){for(var a,u=arguments.length,f=new Array(u>1?u-1:0),l=1;l<u;l++)f[l-1]=arguments[l];if(e===t){if(!i(e))throw new Error("atom not writable");var v=o(e),d=y(e,f[0]);v&&c(v,d)||w(e)}else a=n.apply(void 0,[e].concat(f));return r||M(),a},u=arguments.length,f=new Array(u>1?u-1:0),l=1;l<u;l++)f[l-1]=arguments[l];var d=t.write.apply(t,[e,a].concat(f));return r=!1,d},b=function(n){for(var t=arguments.length,r=new Array(t>1?t-1:0),e=1;e<t;e++)r[e-1]=arguments[e];var o=m.apply(void 0,[n].concat(r));return M(),o},A=function n(r,e){var o={t:new Set(e&&[e]),l:new Set};if(t.set(r,o),g(r).d.forEach((function(e,o){var i=t.get(o);i?i.t.add(r):o!==r&&n(o,r)})),g(r),a(r)&&r.onMount){var i=r.onMount((function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];return b.apply(void 0,[r].concat(t))}));i&&(o.u=i)}return o},S=function n(r){var e,i=null==(e=t.get(r))?void 0:e.u;i&&i(),t.delete(r);var a=o(r);a&&(l(a)&&f(a.v),a.d.forEach((function(e,o){if(o!==r){var i=t.get(o);i&&(i.t.delete(r),h(o,i)&&n(o))}})))},E=function(n,r,e){var o=new Set(r.d.keys());null==e||e.forEach((function(r,e){if(o.has(e))o.delete(e);else{var i=t.get(e);i&&(i.t.delete(n),h(e,i)&&S(e))}})),o.forEach((function(r){var e=t.get(r);e?e.t.add(n):t.has(n)&&A(r,n)}))},M=function(){for(;r.size;){var n=Array.from(r);r.clear(),n.forEach((function(n){var r=n[0],e=n[1],i=o(r);if(i){i.d!==(null==e?void 0:e.d)&&E(r,i,null==e?void 0:e.d);var a=t.get(r);null==a||a.l.forEach((function(n){return n()}))}}))}};return{get:function(n){return v(g(n))},set:b,sub:function(n,r){var e=function(n){var r=t.get(n);return r||(r=A(n)),r}(n),o=e.l;return o.add(r),M(),function(){o.delete(r),function(n){var r=t.get(n);r&&h(n,r)&&S(n)}(n)}},res:function(n){for(var t,r=e(n);!(t=r()).done;){var o=t.value,a=o[0],u=o[1];i(a)&&(y(a,u),w(a))}M()}}};n.atom=function(n,r){var e="atom"+ ++t,o={toString:function(){return e}};return"function"==typeof n?o.read=n:(o.init=n,o.read=function(n){return n(o)},o.write=function(n,t,r){return t(o,"function"==typeof r?r(n(o)):r)}),r&&(o.write=r),o},n.createStore=d,n.getDefaultStore=function(){return o||(o=d()),o}}));
|