recoil
Version:
Recoil - A state management library for React
1 lines • 128 kB
JavaScript
import react from"react";import reactDom from"react-dom";var Recoil_err=function(message){const error=new Error(message);if(void 0===error.stack)try{throw error}catch(_){}return error};var Recoil_isPromise=function(p){return!!p&&"function"==typeof p.then};var Recoil_nullthrows=function(x,message){if(null!=x)return x;throw Recoil_err(null!=message?message:"Got unexpected null or undefined")};function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}class BaseLoadable{getValue(){throw Recoil_err("BaseLoadable")}toPromise(){throw Recoil_err("BaseLoadable")}valueMaybe(){throw Recoil_err("BaseLoadable")}valueOrThrow(){throw Recoil_err(`Loadable expected value, but in "${this.state}" state`)}promiseMaybe(){throw Recoil_err("BaseLoadable")}promiseOrThrow(){throw Recoil_err(`Loadable expected promise, but in "${this.state}" state`)}errorMaybe(){throw Recoil_err("BaseLoadable")}errorOrThrow(){throw Recoil_err(`Loadable expected error, but in "${this.state}" state`)}is(other){return other.state===this.state&&other.contents===this.contents}map(_map){throw Recoil_err("BaseLoadable")}}class ValueLoadable extends BaseLoadable{constructor(value){super(),_defineProperty(this,"state","hasValue"),_defineProperty(this,"contents",void 0),this.contents=value}getValue(){return this.contents}toPromise(){return Promise.resolve(this.contents)}valueMaybe(){return this.contents}valueOrThrow(){return this.contents}promiseMaybe(){}errorMaybe(){}map(map){try{const next=map(this.contents);return Recoil_isPromise(next)?loadableWithPromise(next):isLoadable(next)?next:loadableWithValue(next)}catch(e){return Recoil_isPromise(e)?loadableWithPromise(e.next(()=>this.map(map))):loadableWithError(e)}}}class ErrorLoadable extends BaseLoadable{constructor(error){super(),_defineProperty(this,"state","hasError"),_defineProperty(this,"contents",void 0),this.contents=error}getValue(){throw this.contents}toPromise(){return Promise.reject(this.contents)}valueMaybe(){}promiseMaybe(){}errorMaybe(){return this.contents}errorOrThrow(){return this.contents}map(_map){return this}}class LoadingLoadable extends BaseLoadable{constructor(promise){super(),_defineProperty(this,"state","loading"),_defineProperty(this,"contents",void 0),this.contents=promise}getValue(){throw this.contents}toPromise(){return this.contents}valueMaybe(){}promiseMaybe(){return this.contents}promiseOrThrow(){return this.contents}errorMaybe(){}map(map){return loadableWithPromise(this.contents.then(value=>{const next=map(value);if(isLoadable(next)){const nextLoadable=next;switch(nextLoadable.state){case"hasValue":return nextLoadable.contents;case"hasError":throw nextLoadable.contents;case"loading":return nextLoadable.contents}}return next}).catch(e=>{if(Recoil_isPromise(e))return e.then(()=>this.map(map).contents);throw e}))}}function loadableWithValue(value){return Object.freeze(new ValueLoadable(value))}function loadableWithError(error){return Object.freeze(new ErrorLoadable(error))}function loadableWithPromise(promise){return Object.freeze(new LoadingLoadable(promise))}function loadableAll(inputs){const output=function(inputs){return inputs.every(i=>"hasValue"===i.state)?loadableWithValue(inputs.map(i=>i.contents)):inputs.some(i=>"hasError"===i.state)?loadableWithError(Recoil_nullthrows(inputs.find(i=>"hasError"===i.state),"Invalid loadable passed to loadableAll").contents):loadableWithPromise(Promise.all(inputs.map(i=>i.contents)))}(Array.isArray(inputs)?inputs:Object.getOwnPropertyNames(inputs).map(key=>inputs[key]));return Array.isArray(inputs)?output:output.map(outputs=>Object.getOwnPropertyNames(inputs).reduce((out,key,idx)=>({...out,[key]:outputs[idx]}),{}))}function isLoadable(x){return x instanceof BaseLoadable}const LoadableStaticInterface={of:value=>Recoil_isPromise(value)?loadableWithPromise(value):loadableWithValue(value),error:error=>loadableWithError(error),all:loadableAll,isLoadable:isLoadable};var _useMutableSource,Recoil_Loadable={loadableWithValue:loadableWithValue,loadableWithError:loadableWithError,loadableWithPromise:loadableWithPromise,loadableLoading:function(){return Object.freeze(new LoadingLoadable(new Promise(()=>{})))},loadableAll:loadableAll,isLoadable:isLoadable,RecoilLoadable:LoadableStaticInterface},Recoil_Loadable_1=Recoil_Loadable.loadableWithValue,Recoil_Loadable_2=Recoil_Loadable.loadableWithError,Recoil_Loadable_3=Recoil_Loadable.loadableWithPromise,Recoil_Loadable_4=Recoil_Loadable.loadableLoading,Recoil_Loadable_5=Recoil_Loadable.loadableAll,Recoil_Loadable_6=Recoil_Loadable.isLoadable,Recoil_Loadable_7=Recoil_Loadable.RecoilLoadable,Recoil_Loadable$1=Object.freeze({__proto__:null,loadableWithValue:Recoil_Loadable_1,loadableWithError:Recoil_Loadable_2,loadableWithPromise:Recoil_Loadable_3,loadableLoading:Recoil_Loadable_4,loadableAll:Recoil_Loadable_5,isLoadable:Recoil_Loadable_6,RecoilLoadable:Recoil_Loadable_7});const useMutableSource=null!==(_useMutableSource=react.useMutableSource)&&void 0!==_useMutableSource?_useMutableSource:react.unstable_useMutableSource;var Recoil_mutableSource={mutableSourceExists:function(){return useMutableSource&&!("undefined"!=typeof window&&window.$disableRecoilValueMutableSource_TEMP_HACK_DO_NOT_USE)},useMutableSource:useMutableSource};const{mutableSourceExists:mutableSourceExists$1}=Recoil_mutableSource,gks=(new Map).set("recoil_hamt_2020",!0).set("recoil_memory_managament_2020",!0).set("recoil_suppress_rerender_in_callback",!0);function Recoil_gkx(gk){var _gks$get;return!("recoil_early_rendering_2021"===gk&&!mutableSourceExists$1())&&(null!==(_gks$get=gks.get(gk))&&void 0!==_gks$get&&_gks$get)}Recoil_gkx.setPass=gk=>{gks.set(gk,!0)},Recoil_gkx.setFail=gk=>{gks.set(gk,!1)};var Recoil_gkx_1=Recoil_gkx;var Recoil_mapIterable=function(iterable,callback){return function*(){let index=0;for(const value of iterable)yield callback(value,index++)}()};var Recoil_recoverableViolation=function(message,projectName,{error:error}={}){return null};class AbstractRecoilValue{constructor(newKey){_defineProperty(this,"key",void 0),this.key=newKey}}class RecoilState extends AbstractRecoilValue{}class RecoilValueReadOnly extends AbstractRecoilValue{}var Recoil_RecoilValue={AbstractRecoilValue:AbstractRecoilValue,RecoilState:RecoilState,RecoilValueReadOnly:RecoilValueReadOnly,isRecoilValue:function(x){return x instanceof RecoilState||x instanceof RecoilValueReadOnly}},Recoil_RecoilValue_1=Recoil_RecoilValue.AbstractRecoilValue,Recoil_RecoilValue_2=Recoil_RecoilValue.RecoilState,Recoil_RecoilValue_3=Recoil_RecoilValue.RecoilValueReadOnly,Recoil_RecoilValue_4=Recoil_RecoilValue.isRecoilValue,Recoil_RecoilValue$1=Object.freeze({__proto__:null,AbstractRecoilValue:Recoil_RecoilValue_1,RecoilState:Recoil_RecoilValue_2,RecoilValueReadOnly:Recoil_RecoilValue_3,isRecoilValue:Recoil_RecoilValue_4});class DefaultValue{}const DEFAULT_VALUE=new DefaultValue;class RecoilValueNotReady extends Error{constructor(key){super(`Tried to set the value of Recoil selector ${key} using an updater function, but it is an async selector in a pending or error state; this is not supported.`)}}const nodes=new Map,recoilValues=new Map;class NodeMissingError extends Error{}const configDeletionHandlers=new Map;function getConfigDeletionHandler(key){return configDeletionHandlers.get(key)}var Recoil_Node={nodes:nodes,recoilValues:recoilValues,registerNode:function(node){if(nodes.has(node.key)){const message=`Duplicate atom key "${node.key}". This is a FATAL ERROR in\n production. But it is safe to ignore this warning if it occurred because of\n hot module replacement.`;console.warn(message)}nodes.set(node.key,node);const recoilValue=null==node.set?new Recoil_RecoilValue$1.RecoilValueReadOnly(node.key):new Recoil_RecoilValue$1.RecoilState(node.key);return recoilValues.set(node.key,recoilValue),recoilValue},getNode:function(key){const node=nodes.get(key);if(null==node)throw new NodeMissingError(`Missing definition for RecoilValue: "${key}""`);return node},getNodeMaybe:function(key){return nodes.get(key)},deleteNodeConfigIfPossible:function(key){var _node$shouldDeleteCon;if(!Recoil_gkx_1("recoil_memory_managament_2020"))return;const node=nodes.get(key);var _getConfigDeletionHan;(null==node||null===(_node$shouldDeleteCon=node.shouldDeleteConfigOnRelease)||void 0===_node$shouldDeleteCon?void 0:_node$shouldDeleteCon.call(node))&&(nodes.delete(key),null===(_getConfigDeletionHan=getConfigDeletionHandler(key))||void 0===_getConfigDeletionHan||_getConfigDeletionHan(),configDeletionHandlers.delete(key))},setConfigDeletionHandler:function(key,fn){Recoil_gkx_1("recoil_memory_managament_2020")&&(void 0===fn?configDeletionHandlers.delete(key):configDeletionHandlers.set(key,fn))},getConfigDeletionHandler:getConfigDeletionHandler,recoilValuesForKeys:function(keys){return Recoil_mapIterable(keys,key=>Recoil_nullthrows(recoilValues.get(key)))},NodeMissingError:NodeMissingError,DefaultValue:DefaultValue,DEFAULT_VALUE:DEFAULT_VALUE,RecoilValueNotReady:RecoilValueNotReady};var Recoil_Queue={enqueueExecution:function(s,f){f()}};var hamt_1=function(fn,module){return fn(module={exports:{}},module.exports),module.exports}((function(module){var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},hamt={},BUCKET_SIZE=Math.pow(2,5),MASK=BUCKET_SIZE-1,MAX_INDEX_NODE=BUCKET_SIZE/2,MIN_ARRAY_NODE=BUCKET_SIZE/4,nothing={},constant=function(x){return function(){return x}},hash=hamt.hash=function(str){var type=void 0===str?"undefined":_typeof(str);if("number"===type)return str;"string"!==type&&(str+="");for(var hash=0,i=0,len=str.length;i<len;++i){hash=(hash<<5)-hash+str.charCodeAt(i)|0}return hash},hashFragment=function(shift,h){return h>>>shift&MASK},toBitmap=function(x){return 1<<x},fromBitmap=function(bitmap,bit){return x=bitmap&bit-1,x=(x=(858993459&(x-=x>>1&1431655765))+(x>>2&858993459))+(x>>4)&252645135,x+=x>>8,127&(x+=x>>16);var x},arrayUpdate=function(mutate,at,v,arr){var out=arr;if(!mutate){var len=arr.length;out=new Array(len);for(var i=0;i<len;++i)out[i]=arr[i]}return out[at]=v,out},arraySpliceOut=function(mutate,at,arr){var newLen=arr.length-1,i=0,g=0,out=arr;if(mutate)i=g=at;else for(out=new Array(newLen);i<at;)out[g++]=arr[i++];for(++i;i<=newLen;)out[g++]=arr[i++];return mutate&&(out.length=newLen),out},empty={__hamt_isEmpty:!0},isEmptyNode=function(x){return x===empty||x&&x.__hamt_isEmpty},Leaf=function(edit,hash,key,value){return{type:1,edit:edit,hash:hash,key:key,value:value,_modify:Leaf__modify}},Collision=function(edit,hash,children){return{type:2,edit:edit,hash:hash,children:children,_modify:Collision__modify}},IndexedNode=function(edit,mask,children){return{type:3,edit:edit,mask:mask,children:children,_modify:IndexedNode__modify}},ArrayNode=function(edit,size,children){return{type:4,edit:edit,size:size,children:children,_modify:ArrayNode__modify}},mergeLeaves=function mergeLeaves(edit,shift,h1,n1,h2,n2){if(h1===h2)return Collision(edit,h1,[n2,n1]);var subH1=hashFragment(shift,h1),subH2=hashFragment(shift,h2);return IndexedNode(edit,toBitmap(subH1)|toBitmap(subH2),subH1===subH2?[mergeLeaves(edit,shift+5,h1,n1,h2,n2)]:subH1<subH2?[n1,n2]:[n2,n1])},canEditNode=function(edit,node){return edit===node.edit},Leaf__modify=function(edit,keyEq,shift,f,h,k,size){if(keyEq(k,this.key)){var _v=f(this.value);return _v===this.value?this:_v===nothing?(--size.value,empty):canEditNode(edit,this)?(this.value=_v,this):Leaf(edit,h,k,_v)}var v=f();return v===nothing?this:(++size.value,mergeLeaves(edit,shift,this.hash,this,h,Leaf(edit,h,k,v)))},Collision__modify=function(edit,keyEq,shift,f,h,k,size){if(h===this.hash){var list=function(mutate,edit,keyEq,h,list,f,k,size){for(var len=list.length,i=0;i<len;++i){var child=list[i];if(keyEq(k,child.key)){var value=child.value,_newValue=f(value);return _newValue===value?list:_newValue===nothing?(--size.value,arraySpliceOut(mutate,i,list)):arrayUpdate(mutate,i,Leaf(edit,h,k,_newValue),list)}}var newValue=f();return newValue===nothing?list:(++size.value,arrayUpdate(mutate,len,Leaf(edit,h,k,newValue),list))}(canEditNode(edit,this),edit,keyEq,this.hash,this.children,f,k,size);return list===this.children?this:list.length>1?Collision(edit,this.hash,list):list[0]}var v=f();return v===nothing?this:(++size.value,mergeLeaves(edit,shift,this.hash,this,h,Leaf(edit,h,k,v)))},IndexedNode__modify=function(edit,keyEq,shift,f,h,k,size){var mask=this.mask,children=this.children,frag=hashFragment(shift,h),bit=toBitmap(frag),indx=fromBitmap(mask,bit),exists=mask&bit,current=exists?children[indx]:empty,child=current._modify(edit,keyEq,shift+5,f,h,k,size);if(current===child)return this;var node,canEdit=canEditNode(edit,this),bitmap=mask,newChildren=void 0;if(exists&&isEmptyNode(child)){if(!(bitmap&=~bit))return empty;if(children.length<=2&&((node=children[1^indx])===empty||1===node.type||2===node.type))return children[1^indx];newChildren=arraySpliceOut(canEdit,indx,children)}else if(exists||isEmptyNode(child))newChildren=arrayUpdate(canEdit,indx,child,children);else{if(children.length>=MAX_INDEX_NODE)return function(edit,frag,child,bitmap,subNodes){for(var arr=[],bit=bitmap,count=0,i=0;bit;++i)1&bit&&(arr[i]=subNodes[count++]),bit>>>=1;return arr[frag]=child,ArrayNode(edit,count+1,arr)}(edit,frag,child,mask,children);bitmap|=bit,newChildren=function(mutate,at,v,arr){var len=arr.length;if(mutate){for(var _i=len;_i>=at;)arr[_i--]=arr[_i];return arr[at]=v,arr}for(var i=0,g=0,out=new Array(len+1);i<at;)out[g++]=arr[i++];for(out[at]=v;i<len;)out[++g]=arr[i++];return out}(canEdit,indx,child,children)}return canEdit?(this.mask=bitmap,this.children=newChildren,this):IndexedNode(edit,bitmap,newChildren)},ArrayNode__modify=function(edit,keyEq,shift,f,h,k,size){var count=this.size,children=this.children,frag=hashFragment(shift,h),child=children[frag],newChild=(child||empty)._modify(edit,keyEq,shift+5,f,h,k,size);if(child===newChild)return this;var canEdit=canEditNode(edit,this),newChildren=void 0;if(isEmptyNode(child)&&!isEmptyNode(newChild))++count,newChildren=arrayUpdate(canEdit,frag,newChild,children);else if(!isEmptyNode(child)&&isEmptyNode(newChild)){if(--count<=MIN_ARRAY_NODE)return function(edit,count,removed,elements){for(var children=new Array(count-1),g=0,bitmap=0,i=0,len=elements.length;i<len;++i)if(i!==removed){var elem=elements[i];elem&&!isEmptyNode(elem)&&(children[g++]=elem,bitmap|=1<<i)}return IndexedNode(edit,bitmap,children)}(edit,count,frag,children);newChildren=arrayUpdate(canEdit,frag,empty,children)}else newChildren=arrayUpdate(canEdit,frag,newChild,children);return canEdit?(this.size=count,this.children=newChildren,this):ArrayNode(edit,count,newChildren)};function Map(editable,edit,config,root,size){this._editable=editable,this._edit=edit,this._config=config,this._root=root,this._size=size}empty._modify=function(edit,keyEq,shift,f,h,k,size){var v=f();return v===nothing?empty:(++size.value,Leaf(edit,h,k,v))},Map.prototype.setTree=function(newRoot,newSize){return this._editable?(this._root=newRoot,this._size=newSize,this):newRoot===this._root?this:new Map(this._editable,this._edit,this._config,newRoot,newSize)};var tryGetHash=hamt.tryGetHash=function(alt,hash,key,map){for(var node=map._root,shift=0,keyEq=map._config.keyEq;;)switch(node.type){case 1:return keyEq(key,node.key)?node.value:alt;case 2:if(hash===node.hash)for(var children=node.children,i=0,len=children.length;i<len;++i){var child=children[i];if(keyEq(key,child.key))return child.value}return alt;case 3:var frag=hashFragment(shift,hash),bit=toBitmap(frag);if(node.mask&bit){node=node.children[fromBitmap(node.mask,bit)],shift+=5;break}return alt;case 4:if(node=node.children[hashFragment(shift,hash)]){shift+=5;break}return alt;default:return alt}};Map.prototype.tryGetHash=function(alt,hash,key){return tryGetHash(alt,hash,key,this)};var tryGet=hamt.tryGet=function(alt,key,map){return tryGetHash(alt,map._config.hash(key),key,map)};Map.prototype.tryGet=function(alt,key){return tryGet(alt,key,this)};var getHash=hamt.getHash=function(hash,key,map){return tryGetHash(void 0,hash,key,map)};Map.prototype.getHash=function(hash,key){return getHash(hash,key,this)};hamt.get=function(key,map){return tryGetHash(void 0,map._config.hash(key),key,map)};Map.prototype.get=function(key,alt){return tryGet(alt,key,this)};var hasHash=hamt.has=function(hash,key,map){return tryGetHash(nothing,hash,key,map)!==nothing};Map.prototype.hasHash=function(hash,key){return hasHash(hash,key,this)};var has=hamt.has=function(key,map){return hasHash(map._config.hash(key),key,map)};Map.prototype.has=function(key){return has(key,this)};var defKeyCompare=function(x,y){return x===y};hamt.make=function(config){return new Map(0,0,{keyEq:config&&config.keyEq||defKeyCompare,hash:config&&config.hash||hash},empty,0)},hamt.empty=hamt.make();var isEmpty=hamt.isEmpty=function(map){return map&&!!isEmptyNode(map._root)};Map.prototype.isEmpty=function(){return isEmpty(this)};var modifyHash=hamt.modifyHash=function(f,hash,key,map){var size={value:map._size},newRoot=map._root._modify(map._editable?map._edit:NaN,map._config.keyEq,0,f,hash,key,size);return map.setTree(newRoot,size.value)};Map.prototype.modifyHash=function(hash,key,f){return modifyHash(f,hash,key,this)};var modify=hamt.modify=function(f,key,map){return modifyHash(f,map._config.hash(key),key,map)};Map.prototype.modify=function(key,f){return modify(f,key,this)};var setHash=hamt.setHash=function(hash,key,value,map){return modifyHash(constant(value),hash,key,map)};Map.prototype.setHash=function(hash,key,value){return setHash(hash,key,value,this)};var set=hamt.set=function(key,value,map){return setHash(map._config.hash(key),key,value,map)};Map.prototype.set=function(key,value){return set(key,value,this)};var del=constant(nothing),removeHash=hamt.removeHash=function(hash,key,map){return modifyHash(del,hash,key,map)};Map.prototype.removeHash=Map.prototype.deleteHash=function(hash,key){return removeHash(hash,key,this)};var remove=hamt.remove=function(key,map){return removeHash(map._config.hash(key),key,map)};Map.prototype.remove=Map.prototype.delete=function(key){return remove(key,this)};var beginMutation=hamt.beginMutation=function(map){return new Map(map._editable+1,map._edit+1,map._config,map._root,map._size)};Map.prototype.beginMutation=function(){return beginMutation(this)};var endMutation=hamt.endMutation=function(map){return map._editable=map._editable&&map._editable-1,map};Map.prototype.endMutation=function(){return endMutation(this)};var mutate=hamt.mutate=function(f,map){var transient=beginMutation(map);return f(transient),endMutation(transient)};Map.prototype.mutate=function(f){return mutate(f,this)};var appk=function(k){return k&&lazyVisitChildren(k[0],k[1],k[2],k[3],k[4])},lazyVisitChildren=function(len,children,i,f,k){for(;i<len;){var child=children[i++];if(child&&!isEmptyNode(child))return lazyVisit(child,f,[len,children,i,f,k])}return appk(k)},lazyVisit=function(node,f,k){switch(node.type){case 1:return{value:f(node),rest:k};case 2:case 4:case 3:var children=node.children;return lazyVisitChildren(children.length,children,0,f,k);default:return appk(k)}},DONE={done:!0};function MapIterator(v){this.v=v}MapIterator.prototype.next=function(){if(!this.v)return DONE;var v0=this.v;return this.v=appk(v0.rest),v0},MapIterator.prototype[Symbol.iterator]=function(){return this};var visit=function(map,f){return new MapIterator(lazyVisit(map._root,f))},buildPairs=function(x){return[x.key,x.value]},entries=hamt.entries=function(map){return visit(map,buildPairs)};Map.prototype.entries=Map.prototype[Symbol.iterator]=function(){return entries(this)};var buildKeys=function(x){return x.key},keys=hamt.keys=function(map){return visit(map,buildKeys)};Map.prototype.keys=function(){return keys(this)};var buildValues=function(x){return x.value},values=hamt.values=Map.prototype.values=function(map){return visit(map,buildValues)};Map.prototype.values=function(){return values(this)};var fold=hamt.fold=function(f,z,m){var root=m._root;if(1===root.type)return f(z,root.value,root.key);for(var toVisit=[root.children],children=void 0;children=toVisit.pop();)for(var i=0,len=children.length;i<len;){var child=children[i++];child&&child.type&&(1===child.type?z=f(z,child.value,child.key):toVisit.push(child.children))}return z};Map.prototype.fold=function(f,z){return fold(f,z,this)};var forEach=hamt.forEach=function(f,map){return fold((function(_,value,key){return f(value,key,map)}),null,map)};Map.prototype.forEach=function(f){return forEach(f,this)};var count=hamt.count=function(map){return map._size};Map.prototype.count=function(){return count(this)},Object.defineProperty(Map.prototype,"size",{get:Map.prototype.count}),module.exports?module.exports=hamt:(void 0).hamt=hamt}));class BuiltInMap{constructor(existing){_defineProperty(this,"_map",void 0),this._map=new Map(null==existing?void 0:existing.entries())}keys(){return this._map.keys()}entries(){return this._map.entries()}get(k){return this._map.get(k)}has(k){return this._map.has(k)}set(k,v){return this._map.set(k,v),this}delete(k){return this._map.delete(k),this}clone(){return persistentMap(this)}toMap(){return new Map(this._map)}}class HashArrayMappedTrieMap{constructor(existing){if(_defineProperty(this,"_hamt",hamt_1.empty.beginMutation()),existing instanceof HashArrayMappedTrieMap){const h=existing._hamt.endMutation();existing._hamt=h.beginMutation(),this._hamt=h.beginMutation()}else if(existing)for(const[k,v]of existing.entries())this._hamt.set(k,v)}keys(){return this._hamt.keys()}entries(){return this._hamt.entries()}get(k){return this._hamt.get(k)}has(k){return this._hamt.has(k)}set(k,v){return this._hamt.set(k,v),this}delete(k){return this._hamt.delete(k),this}clone(){return persistentMap(this)}toMap(){return new Map(this._hamt)}}function persistentMap(existing){return Recoil_gkx_1("recoil_hamt_2020")?new HashArrayMappedTrieMap(existing):new BuiltInMap(existing)}var Recoil_PersistentMap_1=persistentMap,Recoil_PersistentMap$1=Object.freeze({__proto__:null,persistentMap:Recoil_PersistentMap_1});var Recoil_differenceSets=function(set,...setsWithValuesToRemove){const ret=new Set;FIRST:for(const value of set){for(const otherSet of setsWithValuesToRemove)if(otherSet.has(value))continue FIRST;ret.add(value)}return ret};var Recoil_mapMap=function(map,callback){const result=new Map;return map.forEach((value,key)=>{result.set(key,callback(value,key))}),result};function mergeDependencyMapIntoGraph(deps,graph,olderGraph){const{nodeDeps:nodeDeps,nodeToNodeSubscriptions:nodeToNodeSubscriptions}=graph;deps.forEach((upstreams,downstream)=>{const existingUpstreams=nodeDeps.get(downstream);if(existingUpstreams&&olderGraph&&existingUpstreams!==olderGraph.nodeDeps.get(downstream))return;nodeDeps.set(downstream,new Set(upstreams));if((null==existingUpstreams?upstreams:Recoil_differenceSets(upstreams,existingUpstreams)).forEach(upstream=>{nodeToNodeSubscriptions.has(upstream)||nodeToNodeSubscriptions.set(upstream,new Set);Recoil_nullthrows(nodeToNodeSubscriptions.get(upstream)).add(downstream)}),existingUpstreams){Recoil_differenceSets(existingUpstreams,upstreams).forEach(upstream=>{if(!nodeToNodeSubscriptions.has(upstream))return;const existing=Recoil_nullthrows(nodeToNodeSubscriptions.get(upstream));existing.delete(downstream),0===existing.size&&nodeToNodeSubscriptions.delete(upstream)})}})}var Recoil_Graph={addToDependencyMap:function(downstream,upstream,dependencyMap){dependencyMap.has(downstream)||dependencyMap.set(downstream,new Set),Recoil_nullthrows(dependencyMap.get(downstream)).add(upstream)},cloneGraph:function(graph){return{nodeDeps:Recoil_mapMap(graph.nodeDeps,s=>new Set(s)),nodeToNodeSubscriptions:Recoil_mapMap(graph.nodeToNodeSubscriptions,s=>new Set(s))}},graph:function(){return{nodeDeps:new Map,nodeToNodeSubscriptions:new Map}},mergeDepsIntoDependencyMap:function(from,into){from.forEach((upstreamDeps,downstreamNode)=>{into.has(downstreamNode)||into.set(downstreamNode,new Set);const deps=Recoil_nullthrows(into.get(downstreamNode));upstreamDeps.forEach(dep=>deps.add(dep))})},saveDependencyMapToStore:function(dependencyMap,store,version){var _storeState$nextTree,_storeState$previousT,_storeState$previousT2,_storeState$previousT3;const storeState=store.getState();version!==storeState.currentTree.version&&version!==(null===(_storeState$nextTree=storeState.nextTree)||void 0===_storeState$nextTree?void 0:_storeState$nextTree.version)&&(null===(_storeState$previousT=storeState.previousTree)||void 0===_storeState$previousT||_storeState$previousT.version);const graph=store.getGraph(version);if(mergeDependencyMapIntoGraph(dependencyMap,graph),version===(null===(_storeState$previousT2=storeState.previousTree)||void 0===_storeState$previousT2?void 0:_storeState$previousT2.version)){mergeDependencyMapIntoGraph(dependencyMap,store.getGraph(storeState.currentTree.version),graph)}if(version===(null===(_storeState$previousT3=storeState.previousTree)||void 0===_storeState$previousT3?void 0:_storeState$previousT3.version)||version===storeState.currentTree.version){var _storeState$nextTree2;const nextVersion=null===(_storeState$nextTree2=storeState.nextTree)||void 0===_storeState$nextTree2?void 0:_storeState$nextTree2.version;if(void 0!==nextVersion){mergeDependencyMapIntoGraph(dependencyMap,store.getGraph(nextVersion),graph)}}}};const{persistentMap:persistentMap$1}=Recoil_PersistentMap$1,{graph:graph$1}=Recoil_Graph;let nextTreeStateVersion=0;const getNextTreeStateVersion=()=>nextTreeStateVersion++;function makeEmptyTreeState(){const version=getNextTreeStateVersion();return{version:version,stateID:version,transactionMetadata:{},dirtyAtoms:new Set,atomValues:persistentMap$1(),nonvalidatedAtoms:persistentMap$1()}}var Recoil_State={makeEmptyTreeState:makeEmptyTreeState,makeEmptyStoreState:function(){const currentTree=makeEmptyTreeState();return{currentTree:currentTree,nextTree:null,previousTree:null,commitDepth:0,knownAtoms:new Set,knownSelectors:new Set,transactionSubscriptions:new Map,nodeTransactionSubscriptions:new Map,nodeToComponentSubscriptions:new Map,queuedComponentCallbacks_DEPRECATED:[],suspendedComponentResolvers:new Set,graphsByVersion:(new Map).set(currentTree.version,graph$1()),versionsUsedByComponent:new Map,retention:{referenceCounts:new Map,nodesRetainedByZone:new Map,retainablesToCheckForRelease:new Set},nodeCleanupFunctions:new Map}},getNextTreeStateVersion:getNextTreeStateVersion};var Recoil_unionSets=function(...sets){const result=new Set;for(const set of sets)for(const value of set)result.add(value);return result};var Recoil_CopyOnWrite={setByAddingToSet:function(set,v){const next=new Set(set);return next.add(v),next},setByDeletingFromSet:function(set,v){const next=new Set(set);return next.delete(v),next},mapBySettingInMap:function(map,k,v){const next=new Map(map);return next.set(k,v),next},mapByUpdatingInMap:function(map,k,updater){const next=new Map(map);return next.set(k,updater(next.get(k))),next},mapByDeletingFromMap:function(map,k){const next=new Map(map);return next.delete(k),next},mapByDeletingMultipleFromMap:function(map,ks){const next=new Map(map);return ks.forEach(k=>next.delete(k)),next}};var Recoil_filterIterable=function*(iterable,predicate){let index=0;for(const value of iterable)predicate(value,index++)&&(yield value)};class RetentionZone{}var Recoil_RetentionZone={RetentionZone:RetentionZone,retentionZone:function(){return new RetentionZone}};const{setByAddingToSet:setByAddingToSet$1}=Recoil_CopyOnWrite,{getNode:getNode$1,getNodeMaybe:getNodeMaybe$1,recoilValuesForKeys:recoilValuesForKeys$1}=Recoil_Node,{RetentionZone:RetentionZone$1}=Recoil_RetentionZone,emptySet=Object.freeze(new Set);class ReadOnlyRecoilValueError extends Error{}function initializeNodeIfNewToStore(store,treeState,key,trigger){const storeState=store.getState();if(storeState.nodeCleanupFunctions.has(key))return;const config=getNode$1(key),retentionCleanup=function(store,nodeKey,retainedBy){if(!Recoil_gkx_1("recoil_memory_managament_2020"))return()=>{};const{nodesRetainedByZone:nodesRetainedByZone}=store.getState().retention;function addToZone(zone){let set=nodesRetainedByZone.get(zone);set||nodesRetainedByZone.set(zone,set=new Set),set.add(nodeKey)}if(retainedBy instanceof RetentionZone$1)addToZone(retainedBy);else if(Array.isArray(retainedBy))for(const zone of retainedBy)addToZone(zone);return()=>{if(!Recoil_gkx_1("recoil_memory_managament_2020"))return;const nodesRetainedByZone=store.getState().retention.nodesRetainedByZone;function deleteFromZone(zone){const set=nodesRetainedByZone.get(zone);set&&set.delete(nodeKey),set&&0===set.size&&nodesRetainedByZone.delete(zone)}if(retainedBy instanceof RetentionZone$1)deleteFromZone(retainedBy);else if(Array.isArray(retainedBy))for(const zone of retainedBy)deleteFromZone(zone)}}(store,key,config.retainedBy),nodeCleanup=config.init(store,treeState,trigger);storeState.nodeCleanupFunctions.set(key,()=>{nodeCleanup(),retentionCleanup()})}function peekNodeLoadable(store,state,key){return getNode$1(key).peek(store,state)}function getDownstreamNodes(store,state,keys){const visitedNodes=new Set,visitingNodes=Array.from(keys),graph=store.getGraph(state.version);for(let key=visitingNodes.pop();key;key=visitingNodes.pop()){var _graph$nodeToNodeSubs;visitedNodes.add(key);const subscribedNodes=null!==(_graph$nodeToNodeSubs=graph.nodeToNodeSubscriptions.get(key))&&void 0!==_graph$nodeToNodeSubs?_graph$nodeToNodeSubs:emptySet;for(const downstreamNode of subscribedNodes)visitedNodes.has(downstreamNode)||visitingNodes.push(downstreamNode)}return visitedNodes}var Recoil_FunctionalCore={getNodeLoadable:function(store,state,key){return initializeNodeIfNewToStore(store,state,key,"get"),getNode$1(key).get(store,state)},peekNodeLoadable:peekNodeLoadable,setNodeValue:function(store,state,key,newValue){const node=getNode$1(key);if(null==node.set)throw new ReadOnlyRecoilValueError("Attempt to set read-only RecoilValue: "+key);const set=node.set;return initializeNodeIfNewToStore(store,state,key,"set"),set(store,state,newValue)},cleanUpNode:function(store,key){var _state$nodeCleanupFun;const state=store.getState();null===(_state$nodeCleanupFun=state.nodeCleanupFunctions.get(key))||void 0===_state$nodeCleanupFun||_state$nodeCleanupFun(),state.nodeCleanupFunctions.delete(key)},setUnvalidatedAtomValue_DEPRECATED:function(state,key,newValue){var _node$invalidate;const node=getNodeMaybe$1(key);return null==node||null===(_node$invalidate=node.invalidate)||void 0===_node$invalidate||_node$invalidate.call(node,state),{...state,atomValues:state.atomValues.clone().delete(key),nonvalidatedAtoms:state.nonvalidatedAtoms.clone().set(key,newValue),dirtyAtoms:setByAddingToSet$1(state.dirtyAtoms,key)}},peekNodeInfo:function(store,state,key){var _graph$nodeDeps$get,_storeState$nodeToCom,_storeState$nodeToCom2;const storeState=store.getState(),graph=store.getGraph(state.version),type=storeState.knownAtoms.has(key)?"atom":storeState.knownSelectors.has(key)?"selector":void 0,downstreamNodes=Recoil_filterIterable(getDownstreamNodes(store,state,new Set([key])),nodeKey=>nodeKey!==key);return{loadable:peekNodeLoadable(store,state,key),isActive:storeState.knownAtoms.has(key)||storeState.knownSelectors.has(key),isSet:"selector"!==type&&state.atomValues.has(key),isModified:state.dirtyAtoms.has(key),type:type,deps:recoilValuesForKeys$1(null!==(_graph$nodeDeps$get=graph.nodeDeps.get(key))&&void 0!==_graph$nodeDeps$get?_graph$nodeDeps$get:[]),subscribers:{nodes:recoilValuesForKeys$1(downstreamNodes),components:Recoil_mapIterable(null!==(_storeState$nodeToCom=null===(_storeState$nodeToCom2=storeState.nodeToComponentSubscriptions.get(key))||void 0===_storeState$nodeToCom2?void 0:_storeState$nodeToCom2.values())&&void 0!==_storeState$nodeToCom?_storeState$nodeToCom:[],([name])=>({name:name}))}}},getDownstreamNodes:getDownstreamNodes,initializeNodeIfNewToStore:initializeNodeIfNewToStore};const{getDownstreamNodes:getDownstreamNodes$1,getNodeLoadable:getNodeLoadable$1,setNodeValue:setNodeValue$1}=Recoil_FunctionalCore,{getNodeMaybe:getNodeMaybe$2}=Recoil_Node,{DefaultValue:DefaultValue$1,RecoilValueNotReady:RecoilValueNotReady$1}=Recoil_Node,{AbstractRecoilValue:AbstractRecoilValue$1,RecoilState:RecoilState$1,RecoilValueReadOnly:RecoilValueReadOnly$1,isRecoilValue:isRecoilValue$1}=Recoil_RecoilValue$1;function applyAction(store,state,action){if("set"===action.type){const{recoilValue:recoilValue,valueOrUpdater:valueOrUpdater}=action,newValue=function(store,state,{key:key},valueOrUpdater){if("function"==typeof valueOrUpdater){const current=getNodeLoadable$1(store,state,key);if("loading"===current.state)throw new RecoilValueNotReady$1(key);if("hasError"===current.state)throw current.contents;return valueOrUpdater(current.contents)}return valueOrUpdater}(store,state,recoilValue,valueOrUpdater),writes=setNodeValue$1(store,state,recoilValue.key,newValue);for(const[key,loadable]of writes.entries())writeLoadableToTreeState(state,key,loadable)}else if("setLoadable"===action.type){const{recoilValue:{key:key},loadable:loadable}=action;writeLoadableToTreeState(state,key,loadable)}else if("markModified"===action.type){const{recoilValue:{key:key}}=action;state.dirtyAtoms.add(key)}else if("setUnvalidated"===action.type){var _node$invalidate;const{recoilValue:{key:key},unvalidatedValue:unvalidatedValue}=action,node=getNodeMaybe$2(key);null==node||null===(_node$invalidate=node.invalidate)||void 0===_node$invalidate||_node$invalidate.call(node,state),state.atomValues.delete(key),state.nonvalidatedAtoms.set(key,unvalidatedValue),state.dirtyAtoms.add(key)}else Recoil_recoverableViolation("Unknown action "+action.type)}function writeLoadableToTreeState(state,key,loadable){"hasValue"===loadable.state&&loadable.contents instanceof DefaultValue$1?state.atomValues.delete(key):state.atomValues.set(key,loadable),state.dirtyAtoms.add(key),state.nonvalidatedAtoms.delete(key)}function applyActionsToStore(store,actions){store.replaceState(state=>{const newState=copyTreeState(state);for(const action of actions)applyAction(store,newState,action);return invalidateDownstreams(store,newState),newState})}function queueOrPerformStateUpdate(store,action){if(batchStack.length){const actionsByStore=batchStack[batchStack.length-1];let actions=actionsByStore.get(store);actions||actionsByStore.set(store,actions=[]),actions.push(action)}else applyActionsToStore(store,[action])}const batchStack=[];function copyTreeState(state){return{...state,atomValues:state.atomValues.clone(),nonvalidatedAtoms:state.nonvalidatedAtoms.clone(),dirtyAtoms:new Set(state.dirtyAtoms)}}function invalidateDownstreams(store,state){const downstreams=getDownstreamNodes$1(store,state,state.dirtyAtoms);for(const key of downstreams){var _getNodeMaybe,_getNodeMaybe$invalid;null===(_getNodeMaybe=getNodeMaybe$2(key))||void 0===_getNodeMaybe||null===(_getNodeMaybe$invalid=_getNodeMaybe.invalidate)||void 0===_getNodeMaybe$invalid||_getNodeMaybe$invalid.call(_getNodeMaybe,state)}}function setRecoilValue(store,recoilValue,valueOrUpdater){queueOrPerformStateUpdate(store,{type:"set",recoilValue:recoilValue,valueOrUpdater:valueOrUpdater})}let subscriptionID=0;var Recoil_RecoilValueInterface={RecoilValueReadOnly:RecoilValueReadOnly$1,AbstractRecoilValue:AbstractRecoilValue$1,RecoilState:RecoilState$1,getRecoilValueAsLoadable:function(store,{key:key},treeState=store.getState().currentTree){var _storeState$nextTree,_storeState$previousT;const storeState=store.getState();treeState.version!==storeState.currentTree.version&&treeState.version!==(null===(_storeState$nextTree=storeState.nextTree)||void 0===_storeState$nextTree?void 0:_storeState$nextTree.version)&&(treeState.version,null===(_storeState$previousT=storeState.previousTree)||void 0===_storeState$previousT||_storeState$previousT.version);const loadable=getNodeLoadable$1(store,treeState,key);return"loading"===loadable.state&&loadable.contents.catch(()=>{}),loadable},setRecoilValue:setRecoilValue,setRecoilValueLoadable:function(store,recoilValue,loadable){if(loadable instanceof DefaultValue$1)return setRecoilValue(store,recoilValue,loadable);queueOrPerformStateUpdate(store,{type:"setLoadable",recoilValue:recoilValue,loadable:loadable})},markRecoilValueModified:function(store,recoilValue){queueOrPerformStateUpdate(store,{type:"markModified",recoilValue:recoilValue})},setUnvalidatedRecoilValue:function(store,recoilValue,unvalidatedValue){queueOrPerformStateUpdate(store,{type:"setUnvalidated",recoilValue:recoilValue,unvalidatedValue:unvalidatedValue})},subscribeToRecoilValue:function(store,{key:key},callback,componentDebugName=null){const subID=subscriptionID++,storeState=store.getState();if(storeState.nodeToComponentSubscriptions.has(key)||storeState.nodeToComponentSubscriptions.set(key,new Map),Recoil_nullthrows(storeState.nodeToComponentSubscriptions.get(key)).set(subID,[null!=componentDebugName?componentDebugName:"<not captured>",callback]),Recoil_gkx_1("recoil_early_rendering_2021")){const nextTree=store.getState().nextTree;nextTree&&nextTree.dirtyAtoms.has(key)&&callback(nextTree)}return{release:()=>{const storeState=store.getState(),subs=storeState.nodeToComponentSubscriptions.get(key);void 0!==subs&&subs.has(subID)&&(subs.delete(subID),0===subs.size&&storeState.nodeToComponentSubscriptions.delete(key))}}},isRecoilValue:isRecoilValue$1,applyAtomValueWrites:function(atomValues,writes){const result=atomValues.clone();return writes.forEach((v,k)=>{"hasValue"===v.state&&v.contents instanceof DefaultValue$1?result.delete(k):result.set(k,v)}),result},batchStart:function(){const actionsByStore=new Map;return batchStack.push(actionsByStore),()=>{for(const[store,actions]of actionsByStore)applyActionsToStore(store,actions);batchStack.pop()}},writeLoadableToTreeState:writeLoadableToTreeState,invalidateDownstreams:invalidateDownstreams,copyTreeState:copyTreeState,invalidateDownstreams_FOR_TESTING:invalidateDownstreams};var Recoil_someSet=function(set,callback,context){const iterator=set.entries();let current=iterator.next();for(;!current.done;){const entry=current.value;if(callback.call(context,entry[1],entry[0],set))return!0;current=iterator.next()}return!1};const{cleanUpNode:cleanUpNode$1}=Recoil_FunctionalCore,{deleteNodeConfigIfPossible:deleteNodeConfigIfPossible$1,getNode:getNode$2}=Recoil_Node,{RetentionZone:RetentionZone$2}=Recoil_RetentionZone,emptySet$1=new Set;function releaseRetainablesNowOnCurrentTree(store,retainables){const storeState=store.getState(),treeState=storeState.currentTree;if(storeState.nextTree)return;const nodes=new Set;for(const r of retainables)if(r instanceof RetentionZone$2)for(const n of nodesRetainedByZone(storeState,r))nodes.add(n);else nodes.add(r);const releasableNodes=function(store,searchFromNodes){const storeState=store.getState(),treeState=storeState.currentTree,graph=store.getGraph(treeState.version),releasableNodes=new Set,nonReleasableNodes=new Set;return findReleasableNodesInner(searchFromNodes),releasableNodes;function findReleasableNodesInner(searchFromNodes){const releasableNodesFoundThisIteration=new Set,downstreams=function(store,treeState,nodes,doNotDescendInto1,doNotDescendInto2){const graph=store.getGraph(treeState.version),answer=[],visited=new Set;for(;nodes.size>0;)visit(Recoil_nullthrows(nodes.values().next().value));return answer;function visit(node){if(doNotDescendInto1.has(node)||doNotDescendInto2.has(node))return void nodes.delete(node);if(visited.has(node))return;const children=graph.nodeToNodeSubscriptions.get(node);if(children)for(const child of children)visit(child);visited.add(node),nodes.delete(node),answer.push(node)}}(store,treeState,searchFromNodes,releasableNodes,nonReleasableNodes);for(const node of downstreams){var _storeState$retention;if("recoilRoot"===getNode$2(node).retainedBy){nonReleasableNodes.add(node);continue}if((null!==(_storeState$retention=storeState.retention.referenceCounts.get(node))&&void 0!==_storeState$retention?_storeState$retention:0)>0){nonReleasableNodes.add(node);continue}if(zonesThatCouldRetainNode(node).some(z=>storeState.retention.referenceCounts.get(z))){nonReleasableNodes.add(node);continue}const nodeChildren=graph.nodeToNodeSubscriptions.get(node);nodeChildren&&Recoil_someSet(nodeChildren,child=>nonReleasableNodes.has(child))?nonReleasableNodes.add(node):(releasableNodes.add(node),releasableNodesFoundThisIteration.add(node))}const parents=new Set;for(const node of releasableNodesFoundThisIteration)for(const parent of null!==(_graph$nodeDeps$get=graph.nodeDeps.get(node))&&void 0!==_graph$nodeDeps$get?_graph$nodeDeps$get:emptySet$1){var _graph$nodeDeps$get;releasableNodes.has(parent)||parents.add(parent)}parents.size&&findReleasableNodesInner(parents)}}(store,nodes);for(const node of releasableNodes)releaseNode(store,treeState,node)}function releaseNode(store,treeState,node){if(!Recoil_gkx_1("recoil_memory_managament_2020"))return;cleanUpNode$1(store,node);const storeState=store.getState();storeState.knownAtoms.delete(node),storeState.knownSelectors.delete(node),storeState.nodeTransactionSubscriptions.delete(node),storeState.retention.referenceCounts.delete(node);const zones=zonesThatCouldRetainNode(node);for(const zone of zones){var _storeState$retention2;null===(_storeState$retention2=storeState.retention.nodesRetainedByZone.get(zone))||void 0===_storeState$retention2||_storeState$retention2.delete(node)}treeState.atomValues.delete(node),treeState.dirtyAtoms.delete(node),treeState.nonvalidatedAtoms.delete(node);const graph=storeState.graphsByVersion.get(treeState.version);if(graph){const deps=graph.nodeDeps.get(node);if(void 0!==deps){graph.nodeDeps.delete(node);for(const dep of deps){var _graph$nodeToNodeSubs;null===(_graph$nodeToNodeSubs=graph.nodeToNodeSubscriptions.get(dep))||void 0===_graph$nodeToNodeSubs||_graph$nodeToNodeSubs.delete(node)}}graph.nodeToNodeSubscriptions.delete(node)}deleteNodeConfigIfPossible$1(node)}function nodesRetainedByZone(storeState,zone){var _storeState$retention3;return null!==(_storeState$retention3=storeState.retention.nodesRetainedByZone.get(zone))&&void 0!==_storeState$retention3?_storeState$retention3:emptySet$1}function zonesThatCouldRetainNode(node){const retainedBy=getNode$2(node).retainedBy;return void 0===retainedBy||"components"===retainedBy||"recoilRoot"===retainedBy?[]:retainedBy instanceof RetentionZone$2?[retainedBy]:retainedBy}function updateRetainCountToZero(store,retainable){if(!Recoil_gkx_1("recoil_memory_managament_2020"))return;store.getState().retention.referenceCounts.delete(retainable),function(store,retainable){const state=store.getState();state.nextTree?state.retention.retainablesToCheckForRelease.add(retainable):releaseRetainablesNowOnCurrentTree(store,new Set([retainable]))}(store,retainable)}var Recoil_Retention={SUSPENSE_TIMEOUT_MS:12e4,updateRetainCount:function(store,retainable,delta){var _map$get;if(!Recoil_gkx_1("recoil_memory_managament_2020"))return;const map=store.getState().retention.referenceCounts,newCount=(null!==(_map$get=map.get(retainable))&&void 0!==_map$get?_map$get:0)+delta;0===newCount?updateRetainCountToZero(store,retainable):map.set(retainable,newCount)},updateRetainCountToZero:updateRetainCountToZero,releaseScheduledRetainablesNow:function(store){if(!Recoil_gkx_1("recoil_memory_managament_2020"))return;const state=store.getState();releaseRetainablesNowOnCurrentTree(store,state.retention.retainablesToCheckForRelease),state.retention.retainablesToCheckForRelease.clear()},retainedByOptionWithDefault:function(r){return void 0===r?"recoilRoot":r}};var Recoil_concatIterables=function*(iters){for(const iter of iters)for(const val of iter)yield val};var Recoil_Environment={isSSR:"undefined"==typeof window,isReactNative:"undefined"!=typeof navigator&&"ReactNative"===navigator.product};const{unstable_batchedUpdates:unstable_batchedUpdates}=reactDom;var ReactBatchedUpdates={unstable_batchedUpdates:unstable_batchedUpdates};const{unstable_batchedUpdates:unstable_batchedUpdates$1}=ReactBatchedUpdates;var Recoil_ReactBatchedUpdates={unstable_batchedUpdates:unstable_batchedUpdates$1};const{batchStart:batchStart$1}=Recoil_RecoilValueInterface,{unstable_batchedUpdates:unstable_batchedUpdates$2}=Recoil_ReactBatchedUpdates;let batcher=unstable_batchedUpdates$2;var Recoil_Batching={getBatcher:()=>batcher,setBatcher:newBatcher=>{batcher=newBatcher},batchUpdates:callback=>{batcher(()=>{let batchEnd=()=>{};try{batchEnd=batchStart$1(),callback()}finally{batchEnd()}})}};const{isSSR:isSSR$1}=Recoil_Environment,{batchUpdates:batchUpdates$1}=Recoil_Batching,{initializeNodeIfNewToStore:initializeNodeIfNewToStore$1,peekNodeInfo:peekNodeInfo$1}=Recoil_FunctionalCore,{graph:graph$2}=Recoil_Graph,{DEFAULT_VALUE:DEFAULT_VALUE$1,recoilValues:recoilValues$1,recoilValuesForKeys:recoilValuesForKeys$2}=Recoil_Node,{AbstractRecoilValue:AbstractRecoilValue$2,getRecoilValueAsLoadable:getRecoilValueAsLoadable$1,setRecoilValue:setRecoilValue$1,setUnvalidatedRecoilValue:setUnvalidatedRecoilValue$1}=Recoil_RecoilValueInterface,{updateRetainCount:updateRetainCount$1}=Recoil_Retention,{getNextTreeStateVersion:getNextTreeStateVersion$1,makeEmptyStoreState:makeEmptyStoreState$1}=Recoil_State;class Snapshot{constructor(storeState){_defineProperty(this,"_store",void 0),_defineProperty(this,"_refCount",0),_defineProperty(this,"getLoadable",recoilValue=>(this.checkRefCount_INTERNAL(),getRecoilValueAsLoadable$1(this._store,recoilValue))),_defineProperty(this,"getPromise",recoilValue=>(this.checkRefCount_INTERNAL(),this.getLoadable(recoilValue).toPromise())),_defineProperty(this,"getNodes_UNSTABLE",opt=>{if(this.checkRefCount_INTERNAL(),!0===(null==opt?void 0:opt.isModified)){if(!1===(null==opt?void 0:opt.isInitialized))return[];const state=this._store.getState().currentTree;return recoilValuesForKeys$2(state.dirtyAtoms)}const knownAtoms=this._store.getState().knownAtoms,knownSelectors=this._store.getState().knownSelectors;return null==(null==opt?void 0:opt.isInitialized)?recoilValues$1.values():!0===opt.isInitialized?recoilValuesForKeys$2(Recoil_concatIterables([this._store.getState().knownAtoms,this._store.getState().knownSelectors])):Recoil_filterIterable(recoilValues$1.values(),({key:key})=>!knownAtoms.has(key)&&!knownSelectors.has(key))}),_defineProperty(this,"getInfo_UNSTABLE",({key:key})=>(this.checkRefCount_INTERNAL(),peekNodeInfo$1(this._store,this._store.getState().currentTree,key))),_defineProperty(this,"map",mapper=>{this.checkRefCount_INTERNAL();const mutableSnapshot=new MutableSnapshot(this,batchUpdates$1);return mapper(mutableSnapshot),cloneSnapshot(mutableSnapshot.getStore_INTERNAL())}),_defineProperty(this,"asyncMap",async mapper=>{this.checkRefCount_INTERNAL();const mutableSnapshot=new MutableSnapshot(this,batchUpdates$1);return await mapper(mutableSnapshot),cloneSnapshot(mutableSnapshot.getStore_INTERNAL())}),this._store={getState:()=>storeState,replaceState:replacer=>{storeState.currentTree=replacer(storeState.currentTree)},getGraph:version=>{const graphs=storeState.graphsByVersion;if(graphs.has(version))return Recoil_nullthrows(graphs.get(version));const newGraph=graph$2();return graphs.set(version,newGraph),newGraph},subscribeToTransactions:()=>({release:()=>{}}),addTransactionMetadata:()=>{throw Recoil_err("Cannot subscribe to Snapshots")}};for(const nodeKey of this._store.getState().nodeCleanupFunctions.keys())initializeNodeIfNewToStore$1(this._store,storeState.currentTree,nodeKey,"get"),updateRetainCount$1(this._store,nodeKey,1);this.retain(),this.autorelease_INTERNAL()}retain(){if(!Recoil_gkx_1("recoil_memory_managament_2020"))return()=>{};this._refCount++;let released=!1;return()=>{released||(released=!0,this.release_INTERNAL())}}autorelease_INTERNAL(){Recoil_gkx_1("recoil_memory_managament_2020")&&(isSSR$1||window.setTimeout(()=>this.release_INTERNAL(),0))}release_INTERNAL(){Recoil_gkx_1("recoil_memory_managament_2020")&&(this._refCount--,this._refCount)}checkRefCount_INTERNAL(){Recoil_gkx_1("recoil_memory_managament_2020")&&this._refCount}getStore_INTERNAL(){return this.checkRefCount_INTERNAL(),this._store}getID(){return this.checkRefCount_INTERNAL(),this.getID_INTERNAL()}getID_INTERNAL(){return this.checkRefCount_INTERNAL(),this._store.getState().currentTree.stateID}}function cloneStoreState(store,treeState,bumpVersion=!1){const storeState=store.getState(),version=bumpVersion?getNextTreeStateVersion$1():treeState.version;return{currentTree:bumpVersion?{version:version,stateID:version,transactionMetadata:{...treeState.transactionMetadata},dirtyAtoms:new Set(treeState.dirtyAtoms),atomValues:treeState.atomValues.clone(),nonvalidatedAtoms:treeState.nonvalidatedAtoms.clone()}:treeState,commitDepth:0,nextTree:null,previousTree:null,knownAtoms:new Set(storeState.knownAtoms),knownSelectors:new Set(storeState.knownSelectors),transactionSubscriptions:new Map,nodeTransactionSubscriptions:new Map,nodeToComponentSubscriptions:new Map,queuedComponentCallbacks_DEPRECATED:[],suspendedComponentResolvers:new Set,graphsByVersion:(new Map).set(version,store.getGraph(treeState.version)),versionsUsedByComponent:new Map,retention:{referenceCounts:new Map,nodesRetainedByZone:new Map,retainablesToCheckForRelease:new Set},nodeCleanupFunctions:new Map}}function cloneSnapshot(store,version="current"){const storeState=store.getState(),treeState="current"===version?storeState.currentTree:Recoil_nullthrows(storeState.previousTree);return new Snapshot(cloneStoreState(store,treeState))}class MutableSnapshot extends Snapshot{constructor(snapshot,batch){super(cloneStoreState(snapshot.getStore_INTERNAL(),snapshot.getStore_INTERNAL().getState().currentTree,!0)),_defineProperty(this,"_batch",void 0),_defineProperty(this,"set",(recoilState,newValueOrUpdater)=>{this.checkRefCount_INTERNAL();const store=this.getStore_INTERNAL();this._batch(()=>{updateRetainCount$1(store,recoilState.key,1),s