import{at as e}from"./vscode-api-DjORcpSo.js";import{c as t,f as n}from"./persisted-signal-CweW-bgN.js";var r=Symbol(``);function i(e,t){let n=null,r=new Map,i=new Set,a=i=>{let s;if(t===void 0)s=r.get(i);else for(let[e,n]of r)if(t(e,i)){s=n;break}if(s!==void 0)if(n?.(s[1],i))a.remove(i);else return s[0];let c=e(i);return r.set(i,[c,Date.now()]),o(`CREATE`,i,c),c},o=(e,t,n)=>{for(let r of i)r({type:e,param:t,atom:n})};return a.unstable_listen=e=>(i.add(e),()=>{i.delete(e)}),a.getParams=()=>r.keys(),a.remove=e=>{if(t===void 0){if(!r.has(e))return;let[t]=r.get(e);r.delete(e),o(`REMOVE`,e,t)}else for(let[n,[i]]of r)if(t(n,e)){r.delete(n),o(`REMOVE`,n,i);break}},a.setShouldRemove=e=>{if(n=e,n)for(let[e,[t,i]]of r)n(i,e)&&(r.delete(e),o(`REMOVE`,e,t))},a}var a=e=>typeof e?.then==`function`;function o(e=()=>{try{return window.localStorage}catch{return}},t){let n,r,i={getItem:(i,o)=>{let s=e=>{if(e||=``,n!==e){try{r=JSON.parse(e,t?.reviver)}catch{return o}n=e}return r},c=e()?.getItem(i)??null;return a(c)?c.then(s):s(c)},setItem:(n,r)=>e()?.setItem(n,JSON.stringify(r,t?.replacer)),removeItem:t=>e()?.removeItem(t)},o=e=>(t,n,r)=>e(t,e=>{let t;try{t=JSON.parse(e||``)}catch{t=r}n(t)}),s;try{s=e()?.subscribe}catch{}return!s&&typeof window<`u`&&typeof window.addEventListener==`function`&&window.Storage&&(s=(t,n)=>{if(!(e()instanceof window.Storage))return()=>{};let r=r=>{r.storageArea===e()&&r.key===t&&n(r.newValue)};return window.addEventListener(`storage`,r),()=>{window.removeEventListener(`storage`,r)}}),s&&(i.subscribe=o(s)),i}var s=o();function c(t,n,i=s,o){let c=e(o?.getOnInit?i.getItem(t,n):n);return c.onMount=e=>(e(i.getItem(t,n)),i.subscribe?.call(i,t,e,n)),e(e=>e(c),(e,o,s)=>{let l=typeof s==`function`?s(e(c)):s;return l===r?(o(c,n),i.removeItem(t)):a(l)?l.then(e=>(o(c,e),i.setItem(t,e))):(o(c,l),i.setItem(t,l))})}function l(){n()}function u(e,n){return c(e,n,t())}export{l as n,i as r,u as t};
//# sourceMappingURL=persisted-atom-D9Fx3rWR.js.map