import{g as getRenderingRef,f as forceUpdate}from"./index-745b6bec.js";const appendToMap=(e,t,r)=>{const s=e.get(t);s?s.includes(r)||s.push(r):e.set(t,[r])},debounce=(e,t)=>{let r;return(...s)=>{r&&clearTimeout(r),r=setTimeout((()=>{r=0,e(...s)}),t)}},isConnected=e=>!("isConnected"in e)||e.isConnected,cleanupElements=debounce((e=>{for(let t of e.keys())e.set(t,e.get(t).filter(isConnected))}),2e3),stencilSubscription=()=>{if("function"!=typeof getRenderingRef)return{};const e=new Map;return{dispose:()=>e.clear(),get:t=>{const r=getRenderingRef();r&&appendToMap(e,t,r)},set:t=>{const r=e.get(t);r&&e.set(t,r.filter(forceUpdate)),cleanupElements(e)},reset:()=>{e.forEach((e=>e.forEach(forceUpdate))),cleanupElements(e)}}},unwrap=e=>"function"==typeof e?e():e,createObservableMap=(e,t=((e,t)=>e!==t))=>{const r=unwrap(e);let s=new Map(Object.entries(null!=r?r:{}));const n={dispose:[],get:[],set:[],reset:[]},o=()=>{var t;s=new Map(Object.entries(null!==(t=unwrap(e))&&void 0!==t?t:{})),n.reset.forEach((e=>e()))},c=e=>(n.get.forEach((t=>t(e))),s.get(e)),a=(e,r)=>{const o=s.get(e);t(r,o,e)&&(s.set(e,r),n.set.forEach((t=>t(e,r,o))))},p="undefined"==typeof Proxy?{}:new Proxy(r,{get(e,t){return c(t)},ownKeys(e){return Array.from(s.keys())},getOwnPropertyDescriptor(){return{enumerable:!0,configurable:!0}},has(e,t){return s.has(t)},set(e,t,r){return a(t,r),!0}}),u=(e,t)=>(n[e].push(t),()=>{removeFromArray(n[e],t)});return{state:p,get:c,set:a,on:u,onChange:(t,r)=>{const s=u("set",((e,s)=>{e===t&&r(s)})),n=u("reset",(()=>r(unwrap(e)[t])));return()=>{s(),n()}},use:(...e)=>{const t=e.reduce(((e,t)=>(t.set&&e.push(u("set",t.set)),t.get&&e.push(u("get",t.get)),t.reset&&e.push(u("reset",t.reset)),t.dispose&&e.push(u("dispose",t.dispose)),e)),[]);return()=>t.forEach((e=>e()))},dispose:()=>{n.dispose.forEach((e=>e())),o()},reset:o,forceUpdate:e=>{const t=s.get(e);n.set.forEach((r=>r(e,t,t)))}}},removeFromArray=(e,t)=>{const r=e.indexOf(t);r>=0&&(e[r]=e[e.length-1],e.length--)},createStore=(e,t)=>{const r=createObservableMap(e,t);return r.use(stencilSubscription()),r};export{createStore as c};