!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((n="undefined"!=typeof globalThis?globalThis:n||self).jotaiVanilla={})}(this,(function(n){"use strict";var r=0;function e(n){return n(this)}function t(n,r,e){return r(this,"function"==typeof e?e(n(this)):e)}function a(n,r){(null==r||r>n.length)&&(r=n.length);for(var e=0,t=Array(r);e=n.length?{done:!0}:{done:!1,value:n[t++]}}}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 i,u=function(n,r){return n.unstable_is?n.unstable_is(r):r===n},f=function(n){return"init"in n},l=function(n){return!!n.write},c=new WeakMap,v=function(n){var r;return d(n)&&!(null!=(r=c.get(n))&&r[1])},d=function(n){return"function"==typeof(null==n?void 0:n.then)},s=function(n){return"v"in n||"e"in n},y=function(n){if("e"in n)throw n.e;return n.v},p=function(n,r,e){e.p.has(n)||(e.p.add(n),r.then((function(){e.p.delete(n)}),(function(){e.p.delete(n)})))},h=function(n,r,e,t,a){var o;e.d.set(t,a.n),v(e.v)&&p(r,e.v,a),null==(o=a.m)||o.t.add(r),n&&b(n,t,r)},m=function(){return{D:new Map,H:new Set,M:new Set,L:new Set}},w=function(n,r,e){n[r].add(e)},g=function(n,r,e){n.D.has(r)||(n.D.set(r,new Set),w(n,"M",(function(){var r;null==(r=e.m)||r.l.forEach((function(r){return w(n,"M",r)}))})))},b=function(n,r,e){var t=n.D.get(r);t&&t.add(e)},S=function(n){for(var r,e=!1,t=function(n){try{n()}catch(n){e||(r=n,e=!0)}};n.H.size||n.M.size||n.L.size;)n.D.clear(),n.H.forEach(t),n.H.clear(),n.M.forEach(t),n.M.clear(),n.L.forEach(t),n.L.clear();if(e)throw r},A=function(){for(var n=arguments.length,r=new Array(n),e=0;e2?a-2:0),c=2;c1?l-1:0),v=1;v0;){var f=u[u.length-1],l=f[0],c=f[1];if(i.has(l))u.pop();else if(a.has(l))t.push([l,c,c.n]),i.add(l),c.x=!0,u.pop();else{a.add(l);for(var v,d=o(x(n,l,c));!(v=d()).done;){var s=v.value,y=s[0],p=s[1];l===y||a.has(y)||u.push([y,p])}}}w(n,"H",(function(){for(var e=new Set([r]),a=t.length-1;a>=0;--a){for(var i,u=t[a],f=u[0],l=u[1],c=u[2],v=!1,d=o(l.d.keys());!(i=d()).done;){var s=i.value;if(s!==f&&e.has(s)){v=!0;break}}v&&(k(n,f),L(n,f,l),c!==l.n&&(g(n,f,l),e.add(f))),delete l.x}}))}(n,a,i)))}return E.apply(void 0,[n,a].concat(c))}finally{e||S(n)}}].concat(l))}finally{e=!1}},D=function(n){var r=m();try{for(var e=arguments.length,t=new Array(e>1?e-1:0),a=1;a1?r-1:0),t=1;t1?r-1:0),t=1;t1?r-1:0),t=1;t