import{i as e,n as t}from"./rolldown-runtime-ConPGZeh.js";var n,r,readQueryParam,getStorageKey,isValidQueryRecord,readFromStorage,writeToStorage,hydratePreservedQuery,capturePreservedQuery,mergePreservedQueryIntoQuery,clearPreservedQuery,i=t((()=>{n=`Comfy.PreservedQuery.`,r=new Map,readQueryParam=e=>typeof e==`string`?e:void 0,getStorageKey=e=>`${n}${e}`,isValidQueryRecord=e=>typeof e!=`object`||!e||Array.isArray(e)?!1:Object.values(e).every(e=>typeof e==`string`),readFromStorage=e=>{try{let t=sessionStorage.getItem(getStorageKey(e));if(!t)return null;let n=JSON.parse(t);return isValidQueryRecord(n)?n:(console.warn(`[preservedQuery] invalid storage format`),sessionStorage.removeItem(getStorageKey(e)),null)}catch{return console.warn(`[preservedQuery] storage operation failed`),sessionStorage.removeItem(getStorageKey(e)),null}},writeToStorage=(e,t)=>{try{if(!t||Object.keys(t).length===0){sessionStorage.removeItem(getStorageKey(e));return}sessionStorage.setItem(getStorageKey(e),JSON.stringify(t))}catch(t){console.warn(`[preservedQuery] failed to write storage`,{namespace:e,error:t})}},hydratePreservedQuery=e=>{if(r.has(e))return;let t=readFromStorage(e);t&&r.set(e,t)},capturePreservedQuery=(e,t,n)=>{let i={};n.forEach(e=>{let n=readQueryParam(t[e]);n&&(i[e]=n)}),Object.keys(i).length!==0&&(r.set(e,i),writeToStorage(e,i))},mergePreservedQueryIntoQuery=(e,t)=>{let n=r.get(e);if(!n)return;let i={...t||{}},a=!1;for(let[e,t]of Object.entries(n))typeof i[e]!=`string`&&(i[e]=t,a=!0);return a?i:void 0},clearPreservedQuery=e=>{r.has(e)&&(r.delete(e),writeToStorage(e,null))}})),a,o=t((()=>{a={TEMPLATE:`template`}}));export{hydratePreservedQuery as a,clearPreservedQuery as i,o as n,i as o,capturePreservedQuery as r,mergePreservedQueryIntoQuery as s,a as t};
//# sourceMappingURL=preservedQueryNamespaces-DSiugp_p.js.map