From 0fb71e38bd11e51117175c98df6084b3a443be8b Mon Sep 17 00:00:00 2001 From: kennyfrc Date: Sun, 26 May 2024 12:36:30 +0800 Subject: [PATCH] docs: v0.3.20 --- docs/api/observable_store.md | 39 ++++++++++++ docs/javascripts/cami.cdn.js | 6 +- docs/javascripts/cami.cdn.js.map | 6 +- site/api/observable_store/index.html | 91 +++++++++++++++++++++++++-- site/javascripts/cami.cdn.js | 6 +- site/javascripts/cami.cdn.js.map | 6 +- site/search/search_index.json | 2 +- site/sitemap.xml.gz | Bin 127 -> 127 bytes 8 files changed, 138 insertions(+), 18 deletions(-) diff --git a/docs/api/observable_store.md b/docs/api/observable_store.md index 710003a7..8f3df1cf 100644 --- a/docs/api/observable_store.md +++ b/docs/api/observable_store.md @@ -8,6 +8,9 @@ ## Functions
+
slice(store, options)Object
+

Creates a slice of the store with its own state and actions, namespaced to avoid conflicts.

+
store(initialState, [options])ObservableStore

This function creates a new instance of ObservableStore with the provided initial state and enhances it with localStorage support if enabled. The store's state will be automatically persisted to and loaded from localStorage, using the provided name as the key. The localStorage option enables this behavior and can be toggled off if persistence is not needed.

@@ -253,6 +256,42 @@ Use this method to dispatch redux-style actions or flux actions, triggering stat // Dispatching an action with a payload CartStore.dispatch('add', { id: 1, name: 'Product 1', quantity: 2 }); ``` + + +## slice(store, options) ⇒ Object +Creates a slice of the store with its own state and actions, namespaced to avoid conflicts. + +**Kind**: global function +**Returns**: Object - - An object containing the action methods for the slice. + +| Param | Type | Description | +| --- | --- | --- | +| store | Object | The main store instance. | +| options | Object | The options for creating the slice. | +| options.name | string | The name of the slice. | +| options.state | Object | The initial state of the slice. | +| options.actions | Object | The actions for the slice. | + +**Example** +```javascript +const userSlice = slice(appStore, { + name: 'user', + state: { + userInfo: null, + isLoggedIn: false, + }, + actions: { + login(state, userInfo) { + state.userInfo = userInfo; + state.isLoggedIn = true; + }, + logout(state) { + state.userInfo = null; + state.isLoggedIn = false; + }, + } +}); +``` ## store(initialState, [options]) ⇒ [ObservableStore](#ObservableStore) diff --git a/docs/javascripts/cami.cdn.js b/docs/javascripts/cami.cdn.js index f77381f1..357ebb60 100644 --- a/docs/javascripts/cami.cdn.js +++ b/docs/javascripts/cami.cdn.js @@ -1,6 +1,6 @@ -var cami=(()=>{var Z=Object.defineProperty;var $t=Object.defineProperties;var Ot=Object.getOwnPropertyDescriptor;var Tt=Object.getOwnPropertyDescriptors;var At=Object.getOwnPropertyNames;var Qe=Object.getOwnPropertySymbols;var Be=Object.prototype.hasOwnProperty;var St=Object.prototype.propertyIsEnumerable;var qe=(r,e)=>{return(e=Symbol[r])?e:Symbol.for("Symbol."+r)};var ye=(r,e,t)=>e in r?Z(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var S=(r,e)=>{for(var t in e||(e={}))if(Be.call(e,t))ye(r,t,e[t]);if(Qe)for(var t of Qe(e)){if(St.call(e,t))ye(r,t,e[t])}return r};var we=(r,e)=>$t(r,Tt(e));var Ct=(r,e)=>{for(var t in e)Z(r,t,{get:e[t],enumerable:true})};var Pt=(r,e,t,s)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let n of At(e))if(!Be.call(r,n)&&n!==t)Z(r,n,{get:()=>e[n],enumerable:!(s=Ot(e,n))||s.enumerable})}return r};var jt=r=>Pt(Z({},"__esModule",{value:true}),r);var Ge=(r,e,t)=>{ye(r,typeof e!=="symbol"?e+"":e,t);return t};var k=(r,e,t)=>{return new Promise((s,n)=>{var i=a=>{try{c(t.next(a))}catch(u){n(u)}};var o=a=>{try{c(t.throw(a))}catch(u){n(u)}};var c=a=>a.done?s(a.value):Promise.resolve(a.value).then(i,o);c((t=t.apply(r,e)).next())})};var ge=(r,e,t)=>(e=r[qe("asyncIterator")])?e.call(r):(r=r[qe("iterator")](),e={},t=(s,n)=>(n=r[s])&&(e[s]=i=>new Promise((o,c,a)=>(i=n.call(r,i),a=i.done,Promise.resolve(i.value).then(u=>o({value:u,done:a}),c)))),t("next"),t("return"),e);var cr={};Ct(cr,{Observable:()=>y,ObservableElement:()=>pe,ObservableState:()=>w,ObservableStore:()=>D,ObservableStream:()=>v,ReactiveElement:()=>_e,computed:()=>he,debug:()=>ir,effect:()=>fe,events:()=>or,html:()=>Pe,http:()=>g,store:()=>Et,svg:()=>ut});var Dt=globalThis;var $=r=>r;var ee=Dt.trustedTypes;var Je=ee?ee.createPolicy("cami-html",{createHTML:r=>r}):void 0;var nt="$cami$";var P=`cami$${String(Math.random()).slice(9)}$`;var it="?"+P;var Rt=`<${it}>`;var I=document;var B=()=>I.createComment("");var G=r=>r===null||typeof r!="object"&&typeof r!="function";var ot=Array.isArray;var Vt=r=>ot(r)||typeof(r==null?void 0:r[Symbol.iterator])==="function";var xe=`[ -\f\r]`;var Mt=`[^ -\f\r"'\`<>=]`;var It=`[^\\s"'>=/]`;var q=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g;var Ke=1;var ve=2;var Nt=3;var Xe=/-->/g;var Ye=/>/g;var V=new RegExp(`>|${xe}(?:(${It}+)(${xe}*=${xe}*(?:${Mt}|("|')|))|$)`,"g");var Ft=0;var Ze=1;var zt=2;var et=3;var tt=/'/g;var rt=/"/g;var ct=/^(?:script|style|textarea|title)$/i;var Ut=1;var te=2;var Se=1;var re=2;var kt=3;var Ht=4;var Lt=5;var Ce=6;var Wt=7;var at=r=>(e,...t)=>{return{["_$camiType$"]:r,strings:e,values:t}};var Pe=at(Ut);var ut=at(te);var J=Symbol.for("cami-noChange");var p=Symbol.for("cami-nothing");var st=new WeakMap;var M=I.createTreeWalker(I,129);function lt(r,e){if(!Array.isArray(r)||!r.hasOwnProperty("raw")){let t="invalid template strings array";throw new Error(t)}return Je!==void 0?Je.createHTML(e):e}var Qt=(r,e)=>{const t=r.length-1;const s=[];let n=e===te?"":"";let i;let o=q;for(let a=0;a"){o=i!=null?i:q;f=-1}else if(h[Ze]===void 0){f=-2}else{f=o.lastIndex-h[zt].length;l=h[Ze];o=h[et]===void 0?V:h[et]==='"'?rt:tt}}else if(o===rt||o===tt){o=V}else if(o===Xe||o===Ye){o=q}else{o=V;i=void 0}}const m=o===V&&r[a+1].startsWith("/>")?" ":"";n+=o===q?u+Rt:f>=0?(s.push(l),u.slice(0,f)+nt+u.slice(f))+P+m:u+P+(f===-2?a:m)}const c=n+(r[t]||"")+(e===te?"":"");return[lt(r,c),s]};var se=class r{constructor({strings:e,["_$camiType$"]:t},s){this.parts=[];let n;let i=0;let o=0;const c=e.length-1;const a=this.parts;const[u,f]=Qt(e,t);this.el=r.createElement(u,s);M.currentNode=this.el.content;if(t===te){const l=this.el.content.firstChild;l.replaceWith(...l.childNodes)}while((n=M.nextNode())!==null&&a.length0){n.textContent=ee?ee.emptyScript:"";for(let h=0;h2||s[0]!==""||s[1]!==""){this._$committedValue=new Array(s.length-1).fill(new String);this.strings=s}else{this._$committedValue=p}}_$setValue(e,t=this,s,n){const i=this.strings;let o=false;if(i===void 0){e=H(this,e,t,0);o=!G(e)||e!==this._$committedValue&&e!==J;if(o){this._$committedValue=e}}else{const c=e;e=i[0];let a,u;for(a=0;a{var i,o;const s=(i=t==null?void 0:t.renderBefore)!=null?i:e;let n=s["_$camiPart$"];if(n===void 0){const c=(o=t==null?void 0:t.renderBefore)!=null?o:null;s["_$camiPart$"]=n=new ne(e.insertBefore(B(),c),c,void 0,t!=null?t:{})}n._$setValue(r);return n};var mt=Symbol.for("immer-nothing");var ht=Symbol.for("immer-draftable");var x=Symbol.for("immer-state");var qt=true?[function(r){return`The plugin for '${r}' has not been loaded into Immer. To enable the plugin, import and call \`enable${r}()\` when initializing your application.`},function(r){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${r}'`},"This object has been frozen and should not be mutated",function(r){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+r},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Cami Observables forbid circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(r){return`'current' expects a draft, got: ${r}`},"Object.defineProperty() cannot be used on a Cami Observable draft","Object.setPrototypeOf() cannot be used on a Cami Observable draft","Cami Observables only support deleting array indices","Cami Observables only support setting array indices and the 'length' property",function(r){return`'original' expects a draft, got: ${r}`}]:[];function b(r,...e){if(true){const t=qt[r];const s=typeof t==="function"?t.apply(null,e):t;throw new Error(`[Cami.js] ${s}`)}throw new Error(`[Cami.js] minified error nr: ${r}.`)}var W=Object.getPrototypeOf;function Q(r){return!!r&&!!r[x]}function F(r){var e;if(!r)return false;return bt(r)||Array.isArray(r)||!!r[ht]||!!((e=r.constructor)==null?void 0:e[ht])||ae(r)||ue(r)}var Bt=Object.prototype.constructor.toString();function bt(r){if(!r||typeof r!=="object")return false;const e=W(r);if(e===null){return true}const t=Object.hasOwnProperty.call(e,"constructor")&&e.constructor;if(t===Object)return true;return typeof t=="function"&&Function.toString.call(t)===Bt}function K(r,e){if(ce(r)===0){Object.entries(r).forEach(([t,s])=>{e(t,s,r)})}else{r.forEach((t,s)=>e(s,t,r))}}function ce(r){const e=r[x];return e?e.type_:Array.isArray(r)?1:ae(r)?2:ue(r)?3:0}function Ve(r,e){return ce(r)===2?r.has(e):Object.prototype.hasOwnProperty.call(r,e)}function yt(r,e,t){const s=ce(r);if(s===2)r.set(e,t);else if(s===3){r.add(t)}else r[e]=t}function Gt(r,e){if(r===e){return r!==0||1/r===1/e}else{return r!==r&&e!==e}}function ae(r){return r instanceof Map}function ue(r){return r instanceof Set}function N(r){return r.copy_||r.base_}function Me(r,e){if(ae(r)){return new Map(r)}if(ue(r)){return new Set(r)}if(Array.isArray(r))return Array.prototype.slice.call(r);if(!e&&bt(r)){if(!W(r)){const n=Object.create(null);return Object.assign(n,r)}return S({},r)}const t=Object.getOwnPropertyDescriptors(r);delete t[x];let s=Reflect.ownKeys(t);for(let n=0;n1){r.set=r.add=r.clear=r.delete=Jt}Object.freeze(r);if(e)K(r,(t,s)=>Ue(s,true),true);return r}function Jt(){b(2)}function le(r){return Object.isFrozen(r)}var Kt={};function z(r){const e=Kt[r];if(!e){b(0,r)}return e}var X;function wt(){return X}function Xt(r,e){return{drafts_:[],parent_:r,immer_:e,canAutoFreeze_:true,unfinalizedDrafts_:0}}function ft(r,e){if(e){z("Patches");r.patches_=[];r.inversePatches_=[];r.patchListener_=e}}function Ie(r){Ne(r);r.drafts_.forEach(Yt);r.drafts_=null}function Ne(r){if(r===X){X=r.parent_}}function dt(r){return X=Xt(X,r)}function Yt(r){const e=r[x];if(e.type_===0||e.type_===1)e.revoke_();else e.revoked_=true}function _t(r,e){e.unfinalizedDrafts_=e.drafts_.length;const t=e.drafts_[0];const s=r!==void 0&&r!==t;if(s){if(t[x].modified_){Ie(e);b(4)}if(F(r)){r=ie(e,r);if(!e.parent_)oe(e,r)}if(e.patches_){z("Patches").generateReplacementPatches_(t[x].base_,r,e.patches_,e.inversePatches_)}}else{r=ie(e,t,[])}Ie(e);if(e.patches_){e.patchListener_(e.patches_,e.inversePatches_)}return r!==mt?r:void 0}function ie(r,e,t){if(le(e))return e;const s=e[x];if(!s){K(e,(n,i)=>pt(r,s,e,n,i,t),true);return e}if(s.scope_!==r)return e;if(!s.modified_){oe(r,s.base_,true);return s.base_}if(!s.finalized_){s.finalized_=true;s.scope_.unfinalizedDrafts_--;const n=s.copy_;let i=n;let o=false;if(s.type_===3){i=new Set(n);n.clear();o=true}K(i,(c,a)=>pt(r,s,n,c,a,t,o));oe(r,n,false);if(t&&r.patches_){z("Patches").generatePatches_(s,t,r.patches_,r.inversePatches_)}}return s.copy_}function pt(r,e,t,s,n,i,o){if(n===t)b(5);if(Q(n)){const c=i&&e&&e.type_!==3&&!Ve(e.assigned_,s)?i.concat(s):void 0;const a=ie(r,n,c);yt(t,s,a);if(Q(a)){r.canAutoFreeze_=false}else return}else if(o){t.add(n)}if(F(n)&&!le(n)){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1){return}ie(r,n);if(!e||!e.scope_.parent_)oe(r,n)}}function oe(r,e,t=false){if(!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_){Ue(e,t)}}function Zt(r,e){const t=Array.isArray(r);const s={type_:t?1:0,scope_:e?e.scope_:wt(),modified_:false,finalized_:false,assigned_:{},parent_:e,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:false};let n=s;let i=ke;if(t){n=[s];i=Y}const{revoke:o,proxy:c}=Proxy.revocable(n,i);s.draft_=c;s.revoke_=o;return c}var ke={get(r,e){if(e===x)return r;const t=N(r);if(!Ve(t,e)){return er(r,t,e)}const s=t[e];if(r.finalized_||!F(s)){return s}if(s===De(r.base_,e)){Re(r);return r.copy_[e]=ze(s,r)}return s},has(r,e){return e in N(r)},ownKeys(r){return Reflect.ownKeys(N(r))},set(r,e,t){const s=gt(N(r),e);if(s==null?void 0:s.set){s.set.call(r.draft_,t);return true}if(!r.modified_){const n=De(N(r),e);const i=n==null?void 0:n[x];if(i&&i.base_===t){r.copy_[e]=t;r.assigned_[e]=false;return true}if(Gt(t,n)&&(t!==void 0||Ve(r.base_,e)))return true;Re(r);Fe(r)}if(r.copy_[e]===t&&(t!==void 0||e in r.copy_)||Number.isNaN(t)&&Number.isNaN(r.copy_[e]))return true;r.copy_[e]=t;r.assigned_[e]=true;return true},deleteProperty(r,e){if(De(r.base_,e)!==void 0||e in r.base_){r.assigned_[e]=false;Re(r);Fe(r)}else{delete r.assigned_[e]}if(r.copy_){delete r.copy_[e]}return true},getOwnPropertyDescriptor(r,e){const t=N(r);const s=Reflect.getOwnPropertyDescriptor(t,e);if(!s)return s;return{writable:true,configurable:r.type_!==1||e!=="length",enumerable:s.enumerable,value:t[e]}},defineProperty(){b(11)},getPrototypeOf(r){return W(r.base_)},setPrototypeOf(){b(12)}};var Y={};K(ke,(r,e)=>{Y[r]=function(){arguments[0]=arguments[0][0];return e.apply(this,arguments)}});Y.deleteProperty=function(r,e){if(isNaN(parseInt(e)))b(13);return Y.set.call(this,r,e,void 0)};Y.set=function(r,e,t){if(e!=="length"&&isNaN(parseInt(e)))b(14);return ke.set.call(this,r[0],e,t,r[0])};function De(r,e){const t=r[x];const s=t?N(t):r;return s[e]}function er(r,e,t){var n;const s=gt(e,t);return s?`value`in s?s.value:(n=s.get)==null?void 0:n.call(r.draft_):void 0}function gt(r,e){if(!(e in r))return void 0;let t=W(r);while(t){const s=Object.getOwnPropertyDescriptor(t,e);if(s)return s;t=W(t)}return void 0}function Fe(r){if(!r.modified_){r.modified_=true;if(r.parent_){Fe(r.parent_)}}}function Re(r){if(!r.copy_){r.copy_=Me(r.base_,r.scope_.immer_.useStrictShallowCopy_)}}var tr=class{constructor(r){this.autoFreeze_=true;this.useStrictShallowCopy_=false;this.produce=(e,t,s)=>{if(typeof e==="function"&&typeof t!=="function"){const i=t;t=e;const o=this;return function c(a=i,...u){return o.produce(a,f=>t.call(this,f,...u))}}if(typeof t!=="function")b(6);if(s!==void 0&&typeof s!=="function")b(7);let n;if(F(e)){const i=dt(this);const o=ze(e,void 0);let c=true;try{n=t(o);c=false}finally{if(c)Ie(i);else Ne(i)}ft(i,s);return _t(n,i)}else if(!e||typeof e!=="object"){n=t(e);if(n===void 0)n=e;if(n===mt)n=void 0;if(this.autoFreeze_)Ue(n,true);if(s){const i=[];const o=[];z("Patches").generateReplacementPatches_(e,n,i,o);s(i,o)}return n}else b(1,e)};this.produceWithPatches=(e,t)=>{if(typeof e==="function"){return(o,...c)=>this.produceWithPatches(o,a=>e(a,...c))}let s,n;const i=this.produce(e,t,(o,c)=>{s=o;n=c});return[i,s,n]};if(typeof(r==null?void 0:r.autoFreeze)==="boolean")this.setAutoFreeze(r.autoFreeze);if(typeof(r==null?void 0:r.useStrictShallowCopy)==="boolean")this.setUseStrictShallowCopy(r.useStrictShallowCopy)}createDraft(r){if(!F(r))b(8);if(Q(r))r=rr(r);const e=dt(this);const t=ze(r,void 0);t[x].isManual_=true;Ne(e);return t}finishDraft(r,e){const t=r&&r[x];if(!t||!t.isManual_)b(9);const{scope_:s}=t;ft(s,e);return _t(void 0,s)}setAutoFreeze(r){this.autoFreeze_=r}setUseStrictShallowCopy(r){this.useStrictShallowCopy_=r}applyPatches(r,e){let t;for(t=e.length-1;t>=0;t--){const n=e[t];if(n.path.length===0&&n.op==="replace"){r=n.value;break}}if(t>-1){e=e.slice(t+1)}const s=z("Patches").applyPatches_;if(Q(r)){return s(r,e)}return this.produce(r,n=>s(n,e))}};function ze(r,e){const t=ae(r)?z("MapSet").proxyMap_(r,e):ue(r)?z("MapSet").proxySet_(r,e):Zt(r,e);const s=e?e.scope_:wt();s.drafts_.push(t);return t}function rr(r){if(!Q(r))b(10,r);return xt(r)}function xt(r){if(!F(r)||le(r))return r;const e=r[x];let t;if(e){if(!e.modified_)return e.base_;e.finalized_=true;t=Me(r,e.scope_.immer_.useStrictShallowCopy_)}else{t=Me(r,true)}K(t,(s,n)=>{yt(t,s,xt(n))});if(e){e.finalized_=false}return t}var sr=new tr;var C=sr.produce;var He=class{constructor(e){if(typeof e==="function"){this.observer={next:e}}else{this.observer=e}this.teardowns=[];if(typeof AbortController!=="undefined"){this.controller=new AbortController;this.signal=this.controller.signal}this.isUnsubscribed=false}next(e){if(!this.isUnsubscribed&&this.observer.next){this.observer.next(e)}}complete(){if(!this.isUnsubscribed){if(this.observer.complete){this.observer.complete()}this.unsubscribe()}}error(e){if(!this.isUnsubscribed){if(this.observer.error){this.observer.error(e)}this.unsubscribe()}}addTeardown(e){this.teardowns.push(e)}unsubscribe(){if(!this.isUnsubscribed){this.isUnsubscribed=true;if(this.controller){this.controller.abort()}this.teardowns.forEach(e=>{if(typeof e!=="function"){throw new Error("[Cami.js] Teardown must be a function. Please implement a teardown function in your subscriber.")}e()})}}};var y=class{constructor(e=()=>()=>{}){this.__observers=[];this.subscribeCallback=e}subscribe(e=()=>{},t=()=>{},s=()=>{}){let n;if(typeof e==="function"){n={next:e,error:t,complete:s}}else if(typeof e==="object"){n=e}else{throw new Error("[Cami.js] First argument to subscribe must be a next callback or an observer object")}const i=new He(n);let o=()=>{};try{o=this.subscribeCallback(i)}catch(c){if(i.error){i.error(c)}else{console.error("[Cami.js] Error in Subscriber:",c)}return}i.addTeardown(o);this.__observers.push(i);return{unsubscribe:()=>i.unsubscribe(),complete:()=>i.complete(),error:c=>i.error(c)}}next(e){this.__observers.forEach(t=>{t.next(e)})}error(e){this.__observers.forEach(t=>{t.error(e)})}complete(){this.__observers.forEach(e=>{e.complete()})}onValue(e){return this.subscribe({next:e})}onError(e){return this.subscribe({error:e})}onEnd(e){return this.subscribe({complete:e})}[Symbol.asyncIterator](){let e;let t;let s=new Promise(n=>t=n);e={next:n=>{t({value:n,done:false});s=new Promise(i=>t=i)},complete:()=>{t({done:true})},error:n=>{throw n}};this.subscribe(e);return{next:()=>s}}};var j={events:{__state:true,get isEnabled(){return this.__state},enable:function(){this.__state=true},disable:function(){this.__state=false}},debug:{__state:false,get isEnabled(){return this.__state},enable:function(){console.log("Cami.js debug mode enabled");this.__state=true},disable:function(){this.__state=false}}};function _(r,...e){if(j.debug.isEnabled){if(r==="cami:state:change"){console.groupCollapsed(`%c[${r}]`,"color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;",`${e[0]} changed`);console.log(`oldValue:`,e[1]);console.log(`newValue:`,e[2])}else{console.groupCollapsed(`%c[${r}]`,"color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;",...e)}console.trace();console.groupEnd()}}var D=class extends y{constructor(e){if(typeof e!=="object"||e===null){throw new TypeError("[Cami.js] initialState must be an object")}super(t=>{this.__subscriber=t;return()=>{this.__subscriber=null}});this.state=new Proxy(e,{get:(t,s)=>{return t[s]},set:(t,s,n)=>{t[s]=n;this.__observers.forEach(i=>i.next(this.state));if(this.devTools){this.devTools.send(s,this.state)}return true}});this.reducers={};this.middlewares=[];this.devTools=this.__connectToDevTools();this.dispatchQueue=[];this.isDispatching=false;this.queryCache=new Map;this.queryFunctions=new Map;this.queries={};this.intervals=new Map;this.focusHandlers=new Map;this.reconnectHandlers=new Map;this.gcTimeouts=new Map;Object.keys(e).forEach(t=>{if(typeof e[t]==="function"){this.register(t,e[t])}else{this.state[t]=e[t]}})}__applyMiddleware(e,...t){const s={state:this.state,action:e,payload:t};for(const n of this.middlewares){n(s)}}__connectToDevTools(){if(typeof window!=="undefined"&&window["__REDUX_DEVTOOLS_EXTENSION__"]){const e=window["__REDUX_DEVTOOLS_EXTENSION__"].connect();e.init(this.state);return e}return null}use(e){this.middlewares.push(e)}getState(){return this.state}register(e,t){if(this.reducers[e]){throw new Error(`[Cami.js] Action type ${e} is already registered.`)}this.reducers[e]=t;this[e]=(...s)=>{this.dispatch(e,...s)}}query(e,t){const{queryKey:s,queryFn:n,staleTime:i=0,refetchOnWindowFocus:o=true,refetchInterval:c=null,refetchOnReconnect:a=true,gcTime:u=1e3*60*5,retry:f=3,retryDelay:l=h=>Math.pow(2,h)*1e3}=t;this.queries[e]={queryKey:s,queryFn:n,staleTime:i,refetchOnWindowFocus:o,refetchInterval:c,refetchOnReconnect:a,gcTime:u,retry:f,retryDelay:l};this.queryFunctions.set(s,n);_(`query`,`Starting query with key: ${e}`);if(c!==null){const h=setInterval(()=>{_(`query`,`Interval expired, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e}:`,m))},c);this.intervals[e]=h}if(o){const h=()=>{_(`query`,`Window focus detected, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e} on window focus:`,m))};window.addEventListener("focus",h);this.focusHandlers[e]=h}if(a){const h=()=>{_(`query`,`Reconnect detected, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e} on reconnect:`,m))};window.addEventListener("online",h);this.reconnectHandlers[e]=h}const d=setTimeout(()=>{_(`query`,`Garbage collection timeout expired, refetching query: ${e}`);this.fetch(e).catch(h=>console.error(`Error refetching query ${e} on gc timeout:`,h))},u);this.gcTimeouts[e]=d;this[e]=(...h)=>{return this.fetch(e,...h)}}fetch(e,...t){const s=this.queries[e];if(!s){throw new Error(`[Cami.js] No query found for name: ${e}`)}const{queryKey:n,queryFn:i,staleTime:o,retry:c,retryDelay:a}=s;const u=Array.isArray(n)?n.join(":"):n;const f=this.queryCache.get(u);if(f&&!this._isStale(f,o)){_(`fetch`,`Returning cached data for: ${e} with cacheKey: ${u}`);return Promise.resolve(f.data)}_(`fetch`,`Data is stale or not cached, fetching new data for: ${e}`);this.dispatch(`${e}/pending`);return this._fetchWithRetry(i,t,c,a).then(l=>{this.queryCache.set(u,{data:l,timestamp:Date.now()});this.dispatch(`${e}/success`,l);return l}).catch(l=>{this.dispatch(`${e}/error`,l);throw l})}invalidateQueries(e){const t=this.queries[e];if(!t)return;const s=Array.isArray(t.queryKey)?t.queryKey.join(":"):t.queryKey;_(`invalidateQueries`,`Invalidating query with key: ${e}`);if(this.intervals[e]){clearInterval(this.intervals[e]);delete this.intervals[e]}if(this.focusHandlers[e]){window.removeEventListener("focus",this.focusHandlers[e]);delete this.focusHandlers[e]}if(this.reconnectHandlers[e]){window.removeEventListener("online",this.reconnectHandlers[e]);delete this.reconnectHandlers[e]}if(this.gcTimeouts[e]){clearTimeout(this.gcTimeouts[e]);delete this.gcTimeouts[e]}this.queryCache.delete(s)}_fetchWithRetry(e,t,s,n){return e(...t).catch(i=>{if(s===0){throw i}const o=n(s);return new Promise(c=>setTimeout(c,o)).then(()=>_(`fetchWithRetry`,`Retrying query with key: ${queryName}`),this._fetchWithRetry(e,t,s-1,n))})}_isStale(e,t){const s=Date.now()-e.timestamp>t;_(`isStale`,`isDataStale: ${s} (Current Time: ${Date.now()}, Data Timestamp: ${e.timestamp}, Stale Time: ${t})`);return s}dispatch(e,t){this.dispatchQueue.push({action:e,payload:t});if(!this.isDispatching){this._processDispatchQueue()}}_processDispatchQueue(){while(this.dispatchQueue.length>0){const{action:e,payload:t}=this.dispatchQueue.shift();this.isDispatching=true;this._dispatch(e,t);this.isDispatching=false}}_dispatch(e,t){if(typeof e==="function"){return e(this._dispatch.bind(this),()=>this.state)}if(typeof e!=="string"){throw new Error(`[Cami.js] Action type must be a string. Got: ${typeof e}`)}const s=this.reducers[e];if(!s){console.warn(`No reducer found for action ${e}`);return}this.__applyMiddleware(e,t);const n=this.state;const i=C(this.state,o=>{s(o,t)});this.state=i;this.__observers.forEach(o=>o.next(this.state));if(this.devTools){this.devTools.send(e,this.state)}if(n!==i){if(j.events.isEnabled&&typeof window!=="undefined"){const o=new CustomEvent("cami:store:state:change",{detail:{action:e,oldValue:n,newValue:i}});window.dispatchEvent(o)}_("cami:store:state:change",e,n,i)}}};var vt=function(r,e){if(typeof r!=="object"||r===null){return e}Object.keys(e).forEach(t=>{const s=r[t];const n=e[t];if(Array.isArray(s)&&Array.isArray(n)){r[t]=[...s,...n]}else if(typeof s==="object"&&s!==null&&typeof n==="object"&&n!==null){r[t]=vt(S({},s),n)}else{r[t]=n}});Object.keys(r).forEach(t=>{if(!e.hasOwnProperty(t)){r[t]=r[t]}});return r};var nr=r=>{return(e,t)=>{const s=(t==null?void 0:t.name)||"default-store";const n=(t==null?void 0:t.load)!==false;const i=24*60*60*1e3;const o=(t==null?void 0:t.expiry)!==void 0?t.expiry:i;const c=new r(e);c.init=()=>{if(n){const a=localStorage.getItem(s);const u=localStorage.getItem(`${s}-expiry`);const f=new Date().getTime();if(a&&u){const l=f>=parseInt(u,10);if(!l){const d=JSON.parse(a);c.state=vt(e,d)}else{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`)}}}};c.init();c.reset=()=>{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`);c.state=e;c.__observers.forEach(a=>a.next(c.state))};c.subscribe(a=>{const u=new Date().getTime();const f=u+o;localStorage.setItem(s,JSON.stringify(a));localStorage.setItem(`${s}-expiry`,f.toString())});return c}};var Et=(r,e={})=>{const t={localStorage:true,name:"cami-store",expiry:864e5};const s=S(S({},t),e);if(s.localStorage){const n=nr(D)(r,s);return n}else{return new D(r)}};var v=class r extends y{static from(e){if(e instanceof y){return new r(t=>{const s=e.subscribe({next:n=>t.next(n),error:n=>t.error(n),complete:()=>t.complete()});return()=>{if(!s.closed){s.unsubscribe()}}})}else if(e[Symbol.asyncIterator]){return new r(t=>{let s=false;(()=>k(this,null,function*(){try{try{for(var n=ge(e),i,o,c;i=!(o=yield n.next()).done;i=false){const a=o.value;if(s)return;t.next(a)}}catch(o){c=[o]}finally{try{i&&(o=n.return)&&(yield o.call(n))}finally{if(c)throw c[0]}}t.complete()}catch(a){t.error(a)}}))();return()=>{s=true}})}else if(e[Symbol.iterator]){return new r(t=>{try{for(const s of e){t.next(s)}t.complete()}catch(s){t.error(s)}return()=>{if(!subscription.closed){subscription.unsubscribe()}}})}else if(e instanceof Promise){return new r(t=>{e.then(s=>{t.next(s);t.complete()},s=>t.error(s));return()=>{}})}else{throw new TypeError("[Cami.js] ObservableStream.from requires an Observable, AsyncIterable, Iterable, or Promise")}}map(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(e(n)),error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}filter(e){return new r(t=>{const s=this.subscribe({next:n=>{if(e(n)){t.next(n)}},error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}reduce(e,t){return new Promise((s,n)=>{let i=t;const o=this.subscribe({next:c=>{i=e(i,c)},error:c=>n(c),complete:()=>s(i)});return()=>o.unsubscribe()})}takeUntil(e){return new r(t=>{const s=this.subscribe({next:i=>t.next(i),error:i=>t.error(i),complete:()=>t.complete()});const n=e.subscribe({next:()=>{t.complete();s.unsubscribe();n.unsubscribe()},error:i=>t.error(i)});return()=>{s.unsubscribe();n.unsubscribe()}})}take(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{if(s++t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}drop(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{if(s++>=e){t.next(i)}},error:i=>t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}flatMap(e){return new r(t=>{const s=new Set;const n=this.subscribe({next:i=>{const o=e(i);const c=o.subscribe({next:a=>t.next(a),error:a=>t.error(a),complete:()=>{s.delete(c);if(s.size===0){t.complete()}}});s.add(c)},error:i=>t.error(i),complete:()=>{if(s.size===0){t.complete()}}});return()=>{n.unsubscribe();s.forEach(i=>i.unsubscribe())}})}switchMap(e){return new r(t=>{let s=null;const n=this.subscribe({next:i=>{if(s){s.unsubscribe()}const o=e(i);s=o.subscribe({next:c=>t.next(c),error:c=>t.error(c),complete:()=>{if(s){s.unsubscribe();s=null}}})},error:i=>t.error(i),complete:()=>{if(s){s.unsubscribe()}t.complete()}});return()=>{n.unsubscribe();if(s){s.unsubscribe()}}})}toArray(){return new Promise((e,t)=>{const s=[];this.subscribe({next:n=>s.push(n),error:n=>t(n),complete:()=>e(s)})})}forEach(e){return new Promise((t,s)=>{this.subscribe({next:n=>e(n),error:n=>s(n),complete:()=>t()})})}every(e){return new Promise((t,s)=>{let n=true;this.subscribe({next:i=>{if(!e(i)){n=false;t(false)}},error:i=>s(i),complete:()=>t(n)})})}find(e){return new Promise((t,s)=>{const n=this.subscribe({next:i=>{if(e(i)){t(i);n.unsubscribe()}},error:i=>s(i),complete:()=>t(void 0)})})}some(e){return new Promise((t,s)=>{const n=this.subscribe({next:i=>{if(e(i)){t(true);n.unsubscribe()}},error:i=>s(i),complete:()=>t(false)})})}finally(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(n),error:n=>{e();t.error(n)},complete:()=>{e();t.complete()}});return()=>{s.unsubscribe()}})}toState(e=null){const t=new w(e,null,{name:"ObservableStream"});this.subscribe({next:s=>t.update(()=>s),error:s=>t.error(s),complete:()=>t.complete()});return t}push(e){if(e instanceof y){const t=e.subscribe({next:s=>this.__observers.forEach(n=>n.next(s)),error:s=>this.__observers.forEach(n=>n.error(s)),complete:()=>this.__observers.forEach(s=>s.complete())})}else if(e[Symbol.asyncIterator]){(()=>k(this,null,function*(){try{try{for(var t=ge(e),s,n,i;s=!(n=yield t.next()).done;s=false){const o=n.value;this.__observers.forEach(c=>c.next(o))}}catch(n){i=[n]}finally{try{s&&(n=t.return)&&(yield n.call(t))}finally{if(i)throw i[0]}}this.__observers.forEach(o=>o.complete())}catch(o){this.__observers.forEach(c=>c.error(o))}}))()}else if(e[Symbol.iterator]){try{for(const t of e){this.__observers.forEach(s=>s.next(t))}this.__observers.forEach(t=>t.complete())}catch(t){this.__observers.forEach(s=>s.error(t))}}else if(e instanceof Promise){e.then(t=>{this.__observers.forEach(s=>s.next(t));this.__observers.forEach(s=>s.complete())},t=>this.__observers.forEach(s=>s.error(t)))}else{this.__observers.forEach(t=>t.next(e))}}plug(e){e.subscribe({next:t=>this.push(t),error:t=>this.__observers.forEach(s=>s.error(t)),complete:()=>this.__observers.forEach(t=>t.complete())})}end(){this.__observers.forEach(e=>{if(e&&typeof e.complete==="function"){e.complete()}})}catchError(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(n),error:n=>{const i=e(n);i.subscribe({next:o=>t.next(o),error:o=>t.error(o),complete:()=>t.complete()})},complete:()=>t.complete()});return()=>s.unsubscribe()})}debounce(e){return new r(t=>{let s=null;const n=this.subscribe({next:i=>{clearTimeout(s);s=setTimeout(()=>{t.next(i)},e)},error:i=>t.error(i),complete:()=>{clearTimeout(s);t.complete()}});return()=>{clearTimeout(s);n.unsubscribe()}})}tap(e){return new r(t=>{const s=this.subscribe({next:n=>{e(n);t.next(n)},error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}throttle(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{const o=Date.now();if(o-s>e){s=o;t.next(i)}},error:i=>t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}distinctUntilChanged(){return new r(e=>{let t;let s=true;const n=this.subscribe({next:i=>{if(s||i!==t){s=false;t=i;e.next(i)}},error:i=>e.error(i),complete:()=>e.complete()});return()=>n.unsubscribe()})}concatMap(e){return new r(t=>{let s=null;let n=false;const i=[];const o=this.subscribe({next:c=>{if(!n){n=true;const a=e(c);s=a.subscribe({next:u=>t.next(u),error:u=>t.error(u),complete:()=>{if(i.length>0){const u=i.shift();const f=e(u);s=f.subscribe({next:l=>t.next(l),error:l=>t.error(l),complete:()=>n=false})}else{n=false}}})}else{i.push(c)}},error:c=>t.error(c),complete:()=>{if(!n){t.complete()}}});return()=>{o.unsubscribe();if(s){s.unsubscribe()}}})}combineLatest(...e){return new r(t=>{const s=new Array(e.length).fill(void 0);const n=e.map((i,o)=>i.subscribe({next:c=>{s[o]=c;if(!s.includes(void 0)){t.next([...s])}},error:c=>t.error(c),complete:()=>{}}));return()=>n.forEach(i=>i.unsubscribe())})}startWith(...e){return new r(t=>{e.forEach(n=>t.next(n));const s=this.subscribe({next:n=>t.next(n),error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}};var R={current:null};var w=class extends y{constructor(e=null,t=null,{last:s=false,name:n=null}={}){super();if(s){this.__lastObserver=t}else{this.__observers.push(t)}this.__value=C(e,i=>{});this.__pendingUpdates=[];this.__updateScheduled=false;this.__name=n}get value(){if(R.current!=null){R.current.addDependency(this)}return this.__value}set value(e){this.update(()=>e)}assign(e){if(typeof this.__value!=="object"||this.__value===null){throw new Error("[Cami.js] Observable value is not an object")}this.update(t=>Object.assign(t,e))}set(e,t){if(typeof this.__value!=="object"||this.__value===null){throw new Error("[Cami.js] Observable value is not an object")}this.update(s=>{const n=e.split(".");let i=s;for(let o=0;o{const s=e.split(".");let n=t;for(let i=0;i({}))}push(...e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.push(...e)})}pop(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.pop()})}shift(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.shift()})}splice(e,t,...s){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.splice(e,t,...s)})}unshift(...e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.unshift(...e)})}reverse(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.reverse()})}sort(e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.sort(e)})}fill(e,t=0,s=this.__value.length){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.fill(e,t,s)})}copyWithin(e,t,s=this.__value.length){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.copyWithin(e,t,s)})}update(e){this.__pendingUpdates.push(e);this.__scheduleupdate()}__scheduleupdate(){if(!this.__updateScheduled){this.__updateScheduled=true;this.__applyUpdates()}}__notifyObservers(){const e=[...this.__observers,this.__lastObserver];e.forEach(t=>{if(t&&typeof t==="function"){t(this.__value)}else if(t&&t.next){t.next(this.__value)}})}__applyUpdates(){let e=this.__value;while(this.__pendingUpdates.length>0){const t=this.__pendingUpdates.shift();if(typeof this.__value==="object"&&this.__value!==null&&this.__value.constructor===Object||Array.isArray(this.__value)){this.__value=C(this.__value,t)}else{this.__value=t(this.__value)}}if(e!==this.__value){this.__notifyObservers();if(j.events.isEnabled&&typeof window!=="undefined"){const t=new CustomEvent("cami:state:change",{detail:{name:this.__name,oldValue:e,newValue:this.__value}});window.dispatchEvent(t)}_("cami:state:change",this.__name,e,this.__value)}this.__updateScheduled=false}toStream(){const e=new v;this.subscribe({next:t=>e.emit(t),error:t=>e.error(t),complete:()=>e.end()});return e}complete(){this.__observers.forEach(e=>{if(e&&typeof e.complete==="function"){e.complete()}})}};var Le=class extends w{constructor(e){super(null);this.computeFn=e;this.dependencies=new Set;this.subscriptions=new Map;this.__compute()}get value(){if(R.current){R.current.addDependency(this)}return this.__value}__compute(){const e={addDependency:s=>{if(!this.dependencies.has(s)){const n=s.onValue(()=>this.__compute());this.dependencies.add(s);this.subscriptions.set(s,n)}}};R.current=e;const t=this.computeFn();R.current=null;if(t!==this.__value){this.__value=t;this.__notifyObservers()}}dispose(){this.subscriptions.forEach(e=>{e.unsubscribe()})}};var he=function(r){return new Le(r)};var fe=function(r){let e=()=>{};let t=new Set;let s=new Map;const n={addDependency:c=>{if(!t.has(c)){const a=c.onValue(i);t.add(c);s.set(c,a)}}};const i=()=>{e();R.current=n;e=r()||(()=>{});R.current=null};if(typeof window!=="undefined"){requestAnimationFrame(i)}else{setTimeout(i,0)}const o=()=>{s.forEach(c=>{c.unsubscribe()});e()};return o};var de=class{constructor(e){if(!(e instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}return new Proxy(e,{get:(t,s)=>{if(typeof t[s]==="function"){return t[s].bind(t)}else if(s in t){return t[s]}else if(typeof t.value[s]==="function"){return(...n)=>t.value[s](...n)}else{return t.value[s]}},set:(t,s,n)=>{t[s]=n;t.update(()=>t.value);return true}})}};var O=new Map;var _e=class extends HTMLElement{constructor(){super();this.onCreate();this.__unsubscribers=new Map;this.__computed=he.bind(this);this.effect=fe.bind(this);this.__queryFunctions=new Map}observableAttributes(e){Object.entries(e).forEach(([t,s])=>{let n=this.getAttribute(t);const i=typeof s==="function"?s:c=>c;n=C(n,i);const o=this.__observable(n,t);if(this.__isObjectOrArray(o.value)){this.__createObservablePropertyForObjOrArr(this,t,o,true)}else{this.__createObservablePropertyForPrimitive(this,t,o,true)}})}__computed(e){const t=super._computed(e);console.log(t);this.__registerObservables(t);return t}effect(e){const t=super.effect(e);this.__unsubscribers.set(e,t)}connect(e,t){if(!(e instanceof D)){throw new TypeError("Expected store to be an instance of ObservableStore")}const s=this.__observable(e.state[t],t);const n=e.subscribe(i=>{s.update(()=>i[t])});this.__unsubscribers.set(t,n);if(this.__isObjectOrArray(s.value)){this.__createObservablePropertyForObjOrArr(this,t,s);return this[t]}else{this.__createObservablePropertyForPrimitive(this,t,s);return this[t]}}stream(e){return new v(e)}template(){throw new Error("[Cami.js] You have to implement the method template()!")}query({queryKey:e,queryFn:t,staleTime:s=0,refetchOnWindowFocus:n=true,refetchOnMount:i=true,refetchOnReconnect:o=true,refetchInterval:c=null,gcTime:a=1e3*60*5,retry:u=3,retryDelay:f=l=>Math.pow(2,l)*1e3}){const l=Array.isArray(e)?e.map(E=>typeof E==="object"?JSON.stringify(E):E).join(":"):e;this.__queryFunctions.set(l,t);_("query","Starting query with key:",l);const d=this.__observable({data:null,status:"pending",fetchStatus:"idle",error:null,lastUpdated:O.has(l)?O.get(l).lastUpdated:null},l);const h=this.__observableProxy(d);const m=(E=0)=>k(this,null,function*(){const We=Date.now();const be=O.get(l);if(be&&We-be.lastUpdated{T.data=be.data;T.status="success";T.fetchStatus="idle"})}else{_("fetchData (else)","Fetching data for key:",l);try{h.update(A=>{A.status="pending";A.fetchStatus="fetching"});const T=yield t();O.set(l,{data:T,lastUpdated:We});h.update(A=>{A.data=T;A.status="success";A.fetchStatus="idle"})}catch(T){_("fetchData (catch)","Fetch error for key:",l,T);if(Em(E+1),f(E))}else{h.update(A=>{A.errorDetails={message:T.message,stack:T.stack};A.status="error";A.fetchStatus="idle"})}}}});if(i){_("query","Setting up refetch on mount for key:",l);m()}if(n){_("query","Setting up refetch on window focus for key:",l);const E=()=>m();window.addEventListener("focus",E);this.__unsubscribers.set(`focus:${l}`,()=>window.removeEventListener("focus",E))}if(o){_("query","Setting up refetch on reconnect for key:",l);window.addEventListener("online",m);this.__unsubscribers.set(`online:${l}`,()=>window.removeEventListener("online",m))}if(c){_("query","Setting up refetch interval for key:",l);const E=setInterval(m,c);this.__unsubscribers.set(`interval:${l}`,()=>clearInterval(E))}const U=setTimeout(()=>{O.delete(l)},a);this.__unsubscribers.set(`gc:${l}`,()=>clearTimeout(U));return h}mutation({mutationFn:e,onMutate:t,onError:s,onSuccess:n,onSettled:i}){const o=this.__observable({data:null,status:"idle",error:null,isSettled:false},"mutation");const c=this.__observableProxy(o);const a=u=>k(this,null,function*(){_("mutation","Starting mutation for variables:",u);let f;const l=c.value;if(t){_("mutation","Performing optimistic update for variables:",u);f=t(u,l);c.update(d=>{d.data=f.optimisticData;d.status="pending";d.errorDetails=null})}else{_("mutation","Performing mutation without optimistic update for variables:",u);c.update(d=>{d.status="pending";d.errorDetails=null})}try{const d=yield e(u);c.update(h=>{h.data=d;h.status="success"});if(n){n(d,u,f)}_("mutation","Mutation successful for variables:",u,d)}catch(d){_("mutation","Mutation error for variables:",u,d);c.update(h=>{h.errorDetails={message:d.message};h.status="error";if(!s&&f&&f.rollback){_("mutation","Rolling back mutation for variables:",u);f.rollback()}});if(s){s(d,u,f)}}finally{if(!c.value.isSettled){c.update(d=>{d.isSettled=true});if(i){_("mutation","Calling onSettled for variables:",u);i(c.value.data,c.value.error,u,f)}}}});c.mutate=a;c.reset=()=>{c.update(u=>{u.data=null;u.status="idle";u.errorDetails=null;u.isSettled=false})};return c}invalidateQueries(e){const t=Array.isArray(e)?e.join(":"):e;_("invalidateQueries","Invalidating query with key:",t);O.delete(t);this.__updateCache(t)}onCreate(){}connectedCallback(){this.__setup({infer:true});this.effect(()=>this.render());this.render();this.onConnect()}onConnect(){}disconnectedCallback(){this.onDisconnect();this.__unsubscribers.forEach(e=>e())}onDisconnect(){}attributeChangedCallback(e,t,s){this.onAttributeChange(e,t,s)}onAttributeChange(e,t,s){}adoptedCallback(){this.onAdopt()}onAdopt(){}__isObjectOrArray(e){return e!==null&&(typeof e==="object"||Array.isArray(e))}__createObservablePropertyForObjOrArr(e,t,s,n=false){if(!(s instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}const i=this.__observableProxy(s);Object.defineProperty(e,t,{get:()=>i,set:o=>{s.update(()=>o);if(n){this.setAttribute(t,o)}}})}__createObservablePropertyForPrimitive(e,t,s,n=false){if(!(s instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}Object.defineProperty(e,t,{get:()=>s.value,set:i=>{s.update(()=>i);if(n){this.setAttribute(t,i)}}})}__observableProxy(e){return new de(e)}__setup(e){if(e.infer===true){Object.keys(this).forEach(t=>{if(typeof this[t]!=="function"&&!t.startsWith("__")){if(this[t]instanceof y){return}else{const s=this.__observable(this[t],t);if(this.__isObjectOrArray(s.value)){this.__createObservablePropertyForObjOrArr(this,t,s)}else{this.__createObservablePropertyForPrimitive(this,t,s)}}}})}}__observable(e,t){if(!this.__isAllowedType(e)){const n=Object.prototype.toString.call(e);throw new Error(`[Cami.js] The value of type ${n} is not allowed in observables. Only primitive values, arrays, and plain objects are allowed.`)}const s=new w(e,null,{name:t});this.__registerObservables(s);return s}__updateCache(e){_("__updateCache","Invalidating cache with key:",e);const t=this.__queryFunctions.get(e);if(t){_("__updateCache","Found query function for key:",e);const s=O.get(e)||{data:void 0,status:"idle",error:null};O.set(e,we(S({},s),{status:"pending",error:null}));t().then(n=>{O.set(e,{data:n,status:"success",error:null,lastUpdated:Date.now()});_("__updateCache","Refetch successful for key:",e,n)}).catch(n=>{if(s.data!==void 0){_("__updateCache","Rolling back refetch for key:",e);O.set(e,s)}O.set(e,we(S({},s),{status:"error",error:n}))})}}__isAllowedType(e){const t=["number","string","boolean","object","undefined"];const s=typeof e;if(s==="object"){return e===null||Array.isArray(e)||this.__isPlainObject(e)}return t.includes(s)}__isPlainObject(e){if(Object.prototype.toString.call(e)!=="[object Object]"){return false}const t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}__registerObservables(e){if(!(e instanceof w)){throw new TypeError("Expected observableState to be an instance of ObservableState")}this.__unsubscribers.set(e,()=>{if(typeof e.dispose==="function"){e.dispose()}})}render(){const e=this.template();je(e,this)}};var pe=class extends v{constructor(e){super();if(typeof e==="string"){this.element=document.querySelector(e);if(!this.element){throw new Error(`[Cami.js] Element not found for selector: ${e}`)}}else if(e instanceof Element||e instanceof Document){this.element=e}else{throw new Error(`[Cami.js] Invalid argument: ${e}`)}}on(e,t={}){return new v(s=>{const n=i=>{s.next(i)};this.element.addEventListener(e,n,t);return()=>{this.element.removeEventListener(e,n,t)}})}};var me=class extends v{constructor(){super(...arguments);Ge(this,"__handlers",{})}toJson(){return new Promise((t,s)=>{this.subscribe({next:n=>{try{if(typeof n==="object"){t(n)}else{t(JSON.parse(n))}}catch(i){s(i)}},error:n=>s(n)})})}on(t,s){if(!this.__handlers[t]){this.__handlers[t]=[]}this.__handlers[t].push(s);return this}};var g=r=>{if(typeof r==="string"){return g.get(r)}return new me(e=>{const t=new XMLHttpRequest;t.open(r.method||"GET",r.url);if(r.headers){Object.keys(r.headers).forEach(s=>{t.setRequestHeader(s,r.headers[s])})}t.onload=()=>{let s=t.responseText;const n=r.transformResponse||(i=>{try{return JSON.parse(i)}catch(o){return i}});s=n(s);e.next(s);e.complete()};t.onerror=()=>e.error(t.statusText);t.send(r.data?JSON.stringify(r.data):null);return()=>{t.abort()}})};g.get=(r,e={})=>{e.url=r;e.method="GET";return g(e)};g.post=(r,e={},t={})=>{t.url=r;t.data=e;t.method="POST";return g(t)};g.put=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PUT";return g(t)};g.patch=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PATCH";return g(t)};g.delete=(r,e={})=>{e.url=r;e.method="DELETE";return g(e)};g.sse=(r,e={})=>{const t=new me(s=>{const n=new EventSource(r,e);n.onmessage=i=>{if(t.__handlers[i.type]){t.__handlers[i.type].forEach(o=>o(i))}s.next(i)};n.onerror=i=>s.error(i);return()=>{n.close()}});return t};var{debug:ir,events:or}=j;return jt(cr);})(); +var cami=(()=>{var Z=Object.defineProperty;var Ot=Object.defineProperties;var At=Object.getOwnPropertyDescriptor;var Tt=Object.getOwnPropertyDescriptors;var St=Object.getOwnPropertyNames;var Qe=Object.getOwnPropertySymbols;var Be=Object.prototype.hasOwnProperty;var Ct=Object.prototype.propertyIsEnumerable;var qe=(r,e)=>{return(e=Symbol[r])?e:Symbol.for("Symbol."+r)};var ye=(r,e,t)=>e in r?Z(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var S=(r,e)=>{for(var t in e||(e={}))if(Be.call(e,t))ye(r,t,e[t]);if(Qe)for(var t of Qe(e)){if(Ct.call(e,t))ye(r,t,e[t])}return r};var we=(r,e)=>Ot(r,Tt(e));var Pt=(r,e)=>{for(var t in e)Z(r,t,{get:e[t],enumerable:true})};var jt=(r,e,t,s)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let n of St(e))if(!Be.call(r,n)&&n!==t)Z(r,n,{get:()=>e[n],enumerable:!(s=At(e,n))||s.enumerable})}return r};var Dt=r=>jt(Z({},"__esModule",{value:true}),r);var Ge=(r,e,t)=>{ye(r,typeof e!=="symbol"?e+"":e,t);return t};var k=(r,e,t)=>{return new Promise((s,n)=>{var i=a=>{try{c(t.next(a))}catch(u){n(u)}};var o=a=>{try{c(t.throw(a))}catch(u){n(u)}};var c=a=>a.done?s(a.value):Promise.resolve(a.value).then(i,o);c((t=t.apply(r,e)).next())})};var ge=(r,e,t)=>(e=r[qe("asyncIterator")])?e.call(r):(r=r[qe("iterator")](),e={},t=(s,n)=>(n=r[s])&&(e[s]=i=>new Promise((o,c,a)=>(i=n.call(r,i),a=i.done,Promise.resolve(i.value).then(u=>o({value:u,done:a}),c)))),t("next"),t("return"),e);var ar={};Pt(ar,{Observable:()=>y,ObservableElement:()=>pe,ObservableState:()=>w,ObservableStore:()=>D,ObservableStream:()=>v,ReactiveElement:()=>_e,computed:()=>he,debug:()=>or,effect:()=>fe,events:()=>cr,html:()=>Pe,http:()=>g,slice:()=>vt,store:()=>$t,svg:()=>ut});var Rt=globalThis;var $=r=>r;var ee=Rt.trustedTypes;var Je=ee?ee.createPolicy("cami-html",{createHTML:r=>r}):void 0;var nt="$cami$";var P=`cami$${String(Math.random()).slice(9)}$`;var it="?"+P;var Vt=`<${it}>`;var I=document;var B=()=>I.createComment("");var G=r=>r===null||typeof r!="object"&&typeof r!="function";var ot=Array.isArray;var Mt=r=>ot(r)||typeof(r==null?void 0:r[Symbol.iterator])==="function";var xe=`[ +\f\r]`;var It=`[^ +\f\r"'\`<>=]`;var Nt=`[^\\s"'>=/]`;var q=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g;var Xe=1;var ve=2;var Ft=3;var Ke=/-->/g;var Ye=/>/g;var V=new RegExp(`>|${xe}(?:(${Nt}+)(${xe}*=${xe}*(?:${It}|("|')|))|$)`,"g");var zt=0;var Ze=1;var Ut=2;var et=3;var tt=/'/g;var rt=/"/g;var ct=/^(?:script|style|textarea|title)$/i;var kt=1;var te=2;var Se=1;var re=2;var Ht=3;var Lt=4;var Wt=5;var Ce=6;var Qt=7;var at=r=>(e,...t)=>{return{["_$camiType$"]:r,strings:e,values:t}};var Pe=at(kt);var ut=at(te);var J=Symbol.for("cami-noChange");var p=Symbol.for("cami-nothing");var st=new WeakMap;var M=I.createTreeWalker(I,129);function lt(r,e){if(!Array.isArray(r)||!r.hasOwnProperty("raw")){let t="invalid template strings array";throw new Error(t)}return Je!==void 0?Je.createHTML(e):e}var qt=(r,e)=>{const t=r.length-1;const s=[];let n=e===te?"":"";let i;let o=q;for(let a=0;a"){o=i!=null?i:q;f=-1}else if(h[Ze]===void 0){f=-2}else{f=o.lastIndex-h[Ut].length;l=h[Ze];o=h[et]===void 0?V:h[et]==='"'?rt:tt}}else if(o===rt||o===tt){o=V}else if(o===Ke||o===Ye){o=q}else{o=V;i=void 0}}const m=o===V&&r[a+1].startsWith("/>")?" ":"";n+=o===q?u+Vt:f>=0?(s.push(l),u.slice(0,f)+nt+u.slice(f))+P+m:u+P+(f===-2?a:m)}const c=n+(r[t]||"")+(e===te?"":"");return[lt(r,c),s]};var se=class r{constructor({strings:e,["_$camiType$"]:t},s){this.parts=[];let n;let i=0;let o=0;const c=e.length-1;const a=this.parts;const[u,f]=qt(e,t);this.el=r.createElement(u,s);M.currentNode=this.el.content;if(t===te){const l=this.el.content.firstChild;l.replaceWith(...l.childNodes)}while((n=M.nextNode())!==null&&a.length0){n.textContent=ee?ee.emptyScript:"";for(let h=0;h2||s[0]!==""||s[1]!==""){this._$committedValue=new Array(s.length-1).fill(new String);this.strings=s}else{this._$committedValue=p}}_$setValue(e,t=this,s,n){const i=this.strings;let o=false;if(i===void 0){e=H(this,e,t,0);o=!G(e)||e!==this._$committedValue&&e!==J;if(o){this._$committedValue=e}}else{const c=e;e=i[0];let a,u;for(a=0;a{var i,o;const s=(i=t==null?void 0:t.renderBefore)!=null?i:e;let n=s["_$camiPart$"];if(n===void 0){const c=(o=t==null?void 0:t.renderBefore)!=null?o:null;s["_$camiPart$"]=n=new ne(e.insertBefore(B(),c),c,void 0,t!=null?t:{})}n._$setValue(r);return n};var mt=Symbol.for("immer-nothing");var ht=Symbol.for("immer-draftable");var x=Symbol.for("immer-state");var Bt=true?[function(r){return`The plugin for '${r}' has not been loaded into Immer. To enable the plugin, import and call \`enable${r}()\` when initializing your application.`},function(r){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${r}'`},"This object has been frozen and should not be mutated",function(r){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+r},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Cami Observables forbid circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(r){return`'current' expects a draft, got: ${r}`},"Object.defineProperty() cannot be used on a Cami Observable draft","Object.setPrototypeOf() cannot be used on a Cami Observable draft","Cami Observables only support deleting array indices","Cami Observables only support setting array indices and the 'length' property",function(r){return`'original' expects a draft, got: ${r}`}]:[];function b(r,...e){if(true){const t=Bt[r];const s=typeof t==="function"?t.apply(null,e):t;throw new Error(`[Cami.js] ${s}`)}throw new Error(`[Cami.js] minified error nr: ${r}.`)}var W=Object.getPrototypeOf;function Q(r){return!!r&&!!r[x]}function F(r){var e;if(!r)return false;return bt(r)||Array.isArray(r)||!!r[ht]||!!((e=r.constructor)==null?void 0:e[ht])||ae(r)||ue(r)}var Gt=Object.prototype.constructor.toString();function bt(r){if(!r||typeof r!=="object")return false;const e=W(r);if(e===null){return true}const t=Object.hasOwnProperty.call(e,"constructor")&&e.constructor;if(t===Object)return true;return typeof t=="function"&&Function.toString.call(t)===Gt}function X(r,e){if(ce(r)===0){Object.entries(r).forEach(([t,s])=>{e(t,s,r)})}else{r.forEach((t,s)=>e(s,t,r))}}function ce(r){const e=r[x];return e?e.type_:Array.isArray(r)?1:ae(r)?2:ue(r)?3:0}function Ve(r,e){return ce(r)===2?r.has(e):Object.prototype.hasOwnProperty.call(r,e)}function yt(r,e,t){const s=ce(r);if(s===2)r.set(e,t);else if(s===3){r.add(t)}else r[e]=t}function Jt(r,e){if(r===e){return r!==0||1/r===1/e}else{return r!==r&&e!==e}}function ae(r){return r instanceof Map}function ue(r){return r instanceof Set}function N(r){return r.copy_||r.base_}function Me(r,e){if(ae(r)){return new Map(r)}if(ue(r)){return new Set(r)}if(Array.isArray(r))return Array.prototype.slice.call(r);if(!e&&bt(r)){if(!W(r)){const n=Object.create(null);return Object.assign(n,r)}return S({},r)}const t=Object.getOwnPropertyDescriptors(r);delete t[x];let s=Reflect.ownKeys(t);for(let n=0;n1){r.set=r.add=r.clear=r.delete=Xt}Object.freeze(r);if(e)X(r,(t,s)=>Ue(s,true),true);return r}function Xt(){b(2)}function le(r){return Object.isFrozen(r)}var Kt={};function z(r){const e=Kt[r];if(!e){b(0,r)}return e}var K;function wt(){return K}function Yt(r,e){return{drafts_:[],parent_:r,immer_:e,canAutoFreeze_:true,unfinalizedDrafts_:0}}function ft(r,e){if(e){z("Patches");r.patches_=[];r.inversePatches_=[];r.patchListener_=e}}function Ie(r){Ne(r);r.drafts_.forEach(Zt);r.drafts_=null}function Ne(r){if(r===K){K=r.parent_}}function dt(r){return K=Yt(K,r)}function Zt(r){const e=r[x];if(e.type_===0||e.type_===1)e.revoke_();else e.revoked_=true}function _t(r,e){e.unfinalizedDrafts_=e.drafts_.length;const t=e.drafts_[0];const s=r!==void 0&&r!==t;if(s){if(t[x].modified_){Ie(e);b(4)}if(F(r)){r=ie(e,r);if(!e.parent_)oe(e,r)}if(e.patches_){z("Patches").generateReplacementPatches_(t[x].base_,r,e.patches_,e.inversePatches_)}}else{r=ie(e,t,[])}Ie(e);if(e.patches_){e.patchListener_(e.patches_,e.inversePatches_)}return r!==mt?r:void 0}function ie(r,e,t){if(le(e))return e;const s=e[x];if(!s){X(e,(n,i)=>pt(r,s,e,n,i,t),true);return e}if(s.scope_!==r)return e;if(!s.modified_){oe(r,s.base_,true);return s.base_}if(!s.finalized_){s.finalized_=true;s.scope_.unfinalizedDrafts_--;const n=s.copy_;let i=n;let o=false;if(s.type_===3){i=new Set(n);n.clear();o=true}X(i,(c,a)=>pt(r,s,n,c,a,t,o));oe(r,n,false);if(t&&r.patches_){z("Patches").generatePatches_(s,t,r.patches_,r.inversePatches_)}}return s.copy_}function pt(r,e,t,s,n,i,o){if(n===t)b(5);if(Q(n)){const c=i&&e&&e.type_!==3&&!Ve(e.assigned_,s)?i.concat(s):void 0;const a=ie(r,n,c);yt(t,s,a);if(Q(a)){r.canAutoFreeze_=false}else return}else if(o){t.add(n)}if(F(n)&&!le(n)){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1){return}ie(r,n);if(!e||!e.scope_.parent_)oe(r,n)}}function oe(r,e,t=false){if(!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_){Ue(e,t)}}function er(r,e){const t=Array.isArray(r);const s={type_:t?1:0,scope_:e?e.scope_:wt(),modified_:false,finalized_:false,assigned_:{},parent_:e,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:false};let n=s;let i=ke;if(t){n=[s];i=Y}const{revoke:o,proxy:c}=Proxy.revocable(n,i);s.draft_=c;s.revoke_=o;return c}var ke={get(r,e){if(e===x)return r;const t=N(r);if(!Ve(t,e)){return tr(r,t,e)}const s=t[e];if(r.finalized_||!F(s)){return s}if(s===De(r.base_,e)){Re(r);return r.copy_[e]=ze(s,r)}return s},has(r,e){return e in N(r)},ownKeys(r){return Reflect.ownKeys(N(r))},set(r,e,t){const s=gt(N(r),e);if(s==null?void 0:s.set){s.set.call(r.draft_,t);return true}if(!r.modified_){const n=De(N(r),e);const i=n==null?void 0:n[x];if(i&&i.base_===t){r.copy_[e]=t;r.assigned_[e]=false;return true}if(Jt(t,n)&&(t!==void 0||Ve(r.base_,e)))return true;Re(r);Fe(r)}if(r.copy_[e]===t&&(t!==void 0||e in r.copy_)||Number.isNaN(t)&&Number.isNaN(r.copy_[e]))return true;r.copy_[e]=t;r.assigned_[e]=true;return true},deleteProperty(r,e){if(De(r.base_,e)!==void 0||e in r.base_){r.assigned_[e]=false;Re(r);Fe(r)}else{delete r.assigned_[e]}if(r.copy_){delete r.copy_[e]}return true},getOwnPropertyDescriptor(r,e){const t=N(r);const s=Reflect.getOwnPropertyDescriptor(t,e);if(!s)return s;return{writable:true,configurable:r.type_!==1||e!=="length",enumerable:s.enumerable,value:t[e]}},defineProperty(){b(11)},getPrototypeOf(r){return W(r.base_)},setPrototypeOf(){b(12)}};var Y={};X(ke,(r,e)=>{Y[r]=function(){arguments[0]=arguments[0][0];return e.apply(this,arguments)}});Y.deleteProperty=function(r,e){if(isNaN(parseInt(e)))b(13);return Y.set.call(this,r,e,void 0)};Y.set=function(r,e,t){if(e!=="length"&&isNaN(parseInt(e)))b(14);return ke.set.call(this,r[0],e,t,r[0])};function De(r,e){const t=r[x];const s=t?N(t):r;return s[e]}function tr(r,e,t){var n;const s=gt(e,t);return s?`value`in s?s.value:(n=s.get)==null?void 0:n.call(r.draft_):void 0}function gt(r,e){if(!(e in r))return void 0;let t=W(r);while(t){const s=Object.getOwnPropertyDescriptor(t,e);if(s)return s;t=W(t)}return void 0}function Fe(r){if(!r.modified_){r.modified_=true;if(r.parent_){Fe(r.parent_)}}}function Re(r){if(!r.copy_){r.copy_=Me(r.base_,r.scope_.immer_.useStrictShallowCopy_)}}var rr=class{constructor(r){this.autoFreeze_=true;this.useStrictShallowCopy_=false;this.produce=(e,t,s)=>{if(typeof e==="function"&&typeof t!=="function"){const i=t;t=e;const o=this;return function c(a=i,...u){return o.produce(a,f=>t.call(this,f,...u))}}if(typeof t!=="function")b(6);if(s!==void 0&&typeof s!=="function")b(7);let n;if(F(e)){const i=dt(this);const o=ze(e,void 0);let c=true;try{n=t(o);c=false}finally{if(c)Ie(i);else Ne(i)}ft(i,s);return _t(n,i)}else if(!e||typeof e!=="object"){n=t(e);if(n===void 0)n=e;if(n===mt)n=void 0;if(this.autoFreeze_)Ue(n,true);if(s){const i=[];const o=[];z("Patches").generateReplacementPatches_(e,n,i,o);s(i,o)}return n}else b(1,e)};this.produceWithPatches=(e,t)=>{if(typeof e==="function"){return(o,...c)=>this.produceWithPatches(o,a=>e(a,...c))}let s,n;const i=this.produce(e,t,(o,c)=>{s=o;n=c});return[i,s,n]};if(typeof(r==null?void 0:r.autoFreeze)==="boolean")this.setAutoFreeze(r.autoFreeze);if(typeof(r==null?void 0:r.useStrictShallowCopy)==="boolean")this.setUseStrictShallowCopy(r.useStrictShallowCopy)}createDraft(r){if(!F(r))b(8);if(Q(r))r=sr(r);const e=dt(this);const t=ze(r,void 0);t[x].isManual_=true;Ne(e);return t}finishDraft(r,e){const t=r&&r[x];if(!t||!t.isManual_)b(9);const{scope_:s}=t;ft(s,e);return _t(void 0,s)}setAutoFreeze(r){this.autoFreeze_=r}setUseStrictShallowCopy(r){this.useStrictShallowCopy_=r}applyPatches(r,e){let t;for(t=e.length-1;t>=0;t--){const n=e[t];if(n.path.length===0&&n.op==="replace"){r=n.value;break}}if(t>-1){e=e.slice(t+1)}const s=z("Patches").applyPatches_;if(Q(r)){return s(r,e)}return this.produce(r,n=>s(n,e))}};function ze(r,e){const t=ae(r)?z("MapSet").proxyMap_(r,e):ue(r)?z("MapSet").proxySet_(r,e):er(r,e);const s=e?e.scope_:wt();s.drafts_.push(t);return t}function sr(r){if(!Q(r))b(10,r);return xt(r)}function xt(r){if(!F(r)||le(r))return r;const e=r[x];let t;if(e){if(!e.modified_)return e.base_;e.finalized_=true;t=Me(r,e.scope_.immer_.useStrictShallowCopy_)}else{t=Me(r,true)}X(t,(s,n)=>{yt(t,s,xt(n))});if(e){e.finalized_=false}return t}var nr=new rr;var C=nr.produce;var He=class{constructor(e){if(typeof e==="function"){this.observer={next:e}}else{this.observer=e}this.teardowns=[];if(typeof AbortController!=="undefined"){this.controller=new AbortController;this.signal=this.controller.signal}this.isUnsubscribed=false}next(e){if(!this.isUnsubscribed&&this.observer.next){this.observer.next(e)}}complete(){if(!this.isUnsubscribed){if(this.observer.complete){this.observer.complete()}this.unsubscribe()}}error(e){if(!this.isUnsubscribed){if(this.observer.error){this.observer.error(e)}this.unsubscribe()}}addTeardown(e){this.teardowns.push(e)}unsubscribe(){if(!this.isUnsubscribed){this.isUnsubscribed=true;if(this.controller){this.controller.abort()}this.teardowns.forEach(e=>{if(typeof e!=="function"){throw new Error("[Cami.js] Teardown must be a function. Please implement a teardown function in your subscriber.")}e()})}}};var y=class{constructor(e=()=>()=>{}){this.__observers=[];this.subscribeCallback=e}subscribe(e=()=>{},t=()=>{},s=()=>{}){let n;if(typeof e==="function"){n={next:e,error:t,complete:s}}else if(typeof e==="object"){n=e}else{throw new Error("[Cami.js] First argument to subscribe must be a next callback or an observer object")}const i=new He(n);let o=()=>{};try{o=this.subscribeCallback(i)}catch(c){if(i.error){i.error(c)}else{console.error("[Cami.js] Error in Subscriber:",c)}return}i.addTeardown(o);this.__observers.push(i);return{unsubscribe:()=>i.unsubscribe(),complete:()=>i.complete(),error:c=>i.error(c)}}next(e){this.__observers.forEach(t=>{t.next(e)})}error(e){this.__observers.forEach(t=>{t.error(e)})}complete(){this.__observers.forEach(e=>{e.complete()})}onValue(e){return this.subscribe({next:e})}onError(e){return this.subscribe({error:e})}onEnd(e){return this.subscribe({complete:e})}[Symbol.asyncIterator](){let e;let t;let s=new Promise(n=>t=n);e={next:n=>{t({value:n,done:false});s=new Promise(i=>t=i)},complete:()=>{t({done:true})},error:n=>{throw n}};this.subscribe(e);return{next:()=>s}}};var j={events:{__state:true,get isEnabled(){return this.__state},enable:function(){this.__state=true},disable:function(){this.__state=false}},debug:{__state:false,get isEnabled(){return this.__state},enable:function(){console.log("Cami.js debug mode enabled");this.__state=true},disable:function(){this.__state=false}}};function _(r,...e){if(j.debug.isEnabled){if(r==="cami:state:change"){console.groupCollapsed(`%c[${r}]`,"color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;",`${e[0]} changed`);console.log(`oldValue:`,e[1]);console.log(`newValue:`,e[2])}else{console.groupCollapsed(`%c[${r}]`,"color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;",...e)}console.trace();console.groupEnd()}}var D=class extends y{constructor(e){if(typeof e!=="object"||e===null){throw new TypeError("[Cami.js] initialState must be an object")}super(t=>{this.__subscriber=t;return()=>{this.__subscriber=null}});this.state=new Proxy(e,{get:(t,s)=>{return t[s]},set:(t,s,n)=>{t[s]=n;this.__observers.forEach(i=>i.next(this.state));if(this.devTools){this.devTools.send(s,this.state)}return true}});this.reducers={};this.middlewares=[];this.devTools=this.__connectToDevTools();this.dispatchQueue=[];this.isDispatching=false;this.queryCache=new Map;this.queryFunctions=new Map;this.queries={};this.intervals=new Map;this.focusHandlers=new Map;this.reconnectHandlers=new Map;this.gcTimeouts=new Map;Object.keys(e).forEach(t=>{if(typeof e[t]==="function"){this.register(t,e[t])}else{this.state[t]=e[t]}})}__applyMiddleware(e,...t){const s={state:this.state,action:e,payload:t};for(const n of this.middlewares){n(s)}}__connectToDevTools(){if(typeof window!=="undefined"&&window["__REDUX_DEVTOOLS_EXTENSION__"]){const e=window["__REDUX_DEVTOOLS_EXTENSION__"].connect();e.init(this.state);return e}return null}use(e){this.middlewares.push(e)}getState(){return this.state}register(e,t){if(this.reducers[e]){throw new Error(`[Cami.js] Action type ${e} is already registered.`)}this.reducers[e]=t;this[e]=(...s)=>{this.dispatch(e,...s)}}query(e,t){const{queryKey:s,queryFn:n,staleTime:i=0,refetchOnWindowFocus:o=true,refetchInterval:c=null,refetchOnReconnect:a=true,gcTime:u=1e3*60*5,retry:f=3,retryDelay:l=h=>Math.pow(2,h)*1e3}=t;this.queries[e]={queryKey:s,queryFn:n,staleTime:i,refetchOnWindowFocus:o,refetchInterval:c,refetchOnReconnect:a,gcTime:u,retry:f,retryDelay:l};this.queryFunctions.set(s,n);_(`query`,`Starting query with key: ${e}`);if(c!==null){const h=setInterval(()=>{_(`query`,`Interval expired, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e}:`,m))},c);this.intervals[e]=h}if(o){const h=()=>{_(`query`,`Window focus detected, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e} on window focus:`,m))};window.addEventListener("focus",h);this.focusHandlers[e]=h}if(a){const h=()=>{_(`query`,`Reconnect detected, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e} on reconnect:`,m))};window.addEventListener("online",h);this.reconnectHandlers[e]=h}const d=setTimeout(()=>{_(`query`,`Garbage collection timeout expired, refetching query: ${e}`);this.fetch(e).catch(h=>console.error(`Error refetching query ${e} on gc timeout:`,h))},u);this.gcTimeouts[e]=d;this[e]=(...h)=>{return this.fetch(e,...h)}}fetch(e,...t){const s=this.queries[e];if(!s){throw new Error(`[Cami.js] No query found for name: ${e}`)}const{queryKey:n,queryFn:i,staleTime:o,retry:c,retryDelay:a}=s;const u=Array.isArray(n)?n.join(":"):n;const f=this.queryCache.get(u);if(f&&!this._isStale(f,o)){_(`fetch`,`Returning cached data for: ${e} with cacheKey: ${u}`);return Promise.resolve(f.data)}_(`fetch`,`Data is stale or not cached, fetching new data for: ${e}`);this.dispatch(`${e}/pending`);return this._fetchWithRetry(i,t,c,a).then(l=>{this.queryCache.set(u,{data:l,timestamp:Date.now()});this.dispatch(`${e}/success`,l);return l}).catch(l=>{this.dispatch(`${e}/error`,l);throw l})}invalidateQueries(e){const t=this.queries[e];if(!t)return;const s=Array.isArray(t.queryKey)?t.queryKey.join(":"):t.queryKey;_(`invalidateQueries`,`Invalidating query with key: ${e}`);if(this.intervals[e]){clearInterval(this.intervals[e]);delete this.intervals[e]}if(this.focusHandlers[e]){window.removeEventListener("focus",this.focusHandlers[e]);delete this.focusHandlers[e]}if(this.reconnectHandlers[e]){window.removeEventListener("online",this.reconnectHandlers[e]);delete this.reconnectHandlers[e]}if(this.gcTimeouts[e]){clearTimeout(this.gcTimeouts[e]);delete this.gcTimeouts[e]}this.queryCache.delete(s)}_fetchWithRetry(e,t,s,n){return e(...t).catch(i=>{if(s===0){throw i}const o=n(s);return new Promise(c=>setTimeout(c,o)).then(()=>_(`fetchWithRetry`,`Retrying query with key: ${queryName}`),this._fetchWithRetry(e,t,s-1,n))})}_isStale(e,t){const s=Date.now()-e.timestamp>t;_(`isStale`,`isDataStale: ${s} (Current Time: ${Date.now()}, Data Timestamp: ${e.timestamp}, Stale Time: ${t})`);return s}dispatch(e,t){this.dispatchQueue.push({action:e,payload:t});if(!this.isDispatching){this._processDispatchQueue()}}_processDispatchQueue(){while(this.dispatchQueue.length>0){const{action:e,payload:t}=this.dispatchQueue.shift();this.isDispatching=true;this._dispatch(e,t);this.isDispatching=false}}_dispatch(e,t){if(typeof e==="function"){return e(this._dispatch.bind(this),()=>this.state)}if(typeof e!=="string"){throw new Error(`[Cami.js] Action type must be a string. Got: ${typeof e}`)}const s=this.reducers[e];if(!s){console.warn(`No reducer found for action ${e}`);return}this.__applyMiddleware(e,t);const n=this.state;const i=C(this.state,o=>{s(o,t)});this.state=i;this.__observers.forEach(o=>o.next(this.state));if(this.devTools){this.devTools.send(e,this.state)}if(n!==i){if(j.events.isEnabled&&typeof window!=="undefined"){const o=new CustomEvent("cami:store:state:change",{detail:{action:e,oldValue:n,newValue:i}});window.dispatchEvent(o)}_("cami:store:state:change",e,n,i)}}};var vt=(r,{name:e,state:t,actions:s})=>{if(r.slices&&r.slices[e]){throw new Error(`[Cami.js] Slice name ${e} is already in use.`)}if(!r.slices){r.slices={}}r.slices[e]=true;r.state[e]=t;const n={};Object.keys(s).forEach(i=>{const o=`${e}/${i}`;r.register(o,(c,a)=>{s[i](c[e],a)});n[i]=(...c)=>{r.dispatch(o,...c)}});return n};var Et=function(r,e){if(typeof r!=="object"||r===null){return e}Object.keys(e).forEach(t=>{const s=r[t];const n=e[t];if(Array.isArray(s)&&Array.isArray(n)){r[t]=[...s,...n]}else if(typeof s==="object"&&s!==null&&typeof n==="object"&&n!==null){r[t]=Et(S({},s),n)}else{r[t]=n}});Object.keys(r).forEach(t=>{if(!e.hasOwnProperty(t)){r[t]=r[t]}});return r};var ir=r=>{return(e,t)=>{const s=(t==null?void 0:t.name)||"default-store";const n=(t==null?void 0:t.load)!==false;const i=24*60*60*1e3;const o=(t==null?void 0:t.expiry)!==void 0?t.expiry:i;const c=new r(e);c.init=()=>{if(n){const a=localStorage.getItem(s);const u=localStorage.getItem(`${s}-expiry`);const f=new Date().getTime();if(a&&u){const l=f>=parseInt(u,10);if(!l){const d=JSON.parse(a);c.state=Et(e,d)}else{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`)}}}};c.init();c.reset=()=>{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`);c.state=e;c.__observers.forEach(a=>a.next(c.state))};c.subscribe(a=>{const u=new Date().getTime();const f=u+o;localStorage.setItem(s,JSON.stringify(a));localStorage.setItem(`${s}-expiry`,f.toString())});return c}};var $t=(r,e={})=>{const t={localStorage:true,name:"cami-store",expiry:864e5};const s=S(S({},t),e);if(s.localStorage){const n=ir(D)(r,s);return n}else{return new D(r)}};var v=class r extends y{static from(e){if(e instanceof y){return new r(t=>{const s=e.subscribe({next:n=>t.next(n),error:n=>t.error(n),complete:()=>t.complete()});return()=>{if(!s.closed){s.unsubscribe()}}})}else if(e[Symbol.asyncIterator]){return new r(t=>{let s=false;(()=>k(this,null,function*(){try{try{for(var n=ge(e),i,o,c;i=!(o=yield n.next()).done;i=false){const a=o.value;if(s)return;t.next(a)}}catch(o){c=[o]}finally{try{i&&(o=n.return)&&(yield o.call(n))}finally{if(c)throw c[0]}}t.complete()}catch(a){t.error(a)}}))();return()=>{s=true}})}else if(e[Symbol.iterator]){return new r(t=>{try{for(const s of e){t.next(s)}t.complete()}catch(s){t.error(s)}return()=>{if(!subscription.closed){subscription.unsubscribe()}}})}else if(e instanceof Promise){return new r(t=>{e.then(s=>{t.next(s);t.complete()},s=>t.error(s));return()=>{}})}else{throw new TypeError("[Cami.js] ObservableStream.from requires an Observable, AsyncIterable, Iterable, or Promise")}}map(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(e(n)),error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}filter(e){return new r(t=>{const s=this.subscribe({next:n=>{if(e(n)){t.next(n)}},error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}reduce(e,t){return new Promise((s,n)=>{let i=t;const o=this.subscribe({next:c=>{i=e(i,c)},error:c=>n(c),complete:()=>s(i)});return()=>o.unsubscribe()})}takeUntil(e){return new r(t=>{const s=this.subscribe({next:i=>t.next(i),error:i=>t.error(i),complete:()=>t.complete()});const n=e.subscribe({next:()=>{t.complete();s.unsubscribe();n.unsubscribe()},error:i=>t.error(i)});return()=>{s.unsubscribe();n.unsubscribe()}})}take(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{if(s++t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}drop(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{if(s++>=e){t.next(i)}},error:i=>t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}flatMap(e){return new r(t=>{const s=new Set;const n=this.subscribe({next:i=>{const o=e(i);const c=o.subscribe({next:a=>t.next(a),error:a=>t.error(a),complete:()=>{s.delete(c);if(s.size===0){t.complete()}}});s.add(c)},error:i=>t.error(i),complete:()=>{if(s.size===0){t.complete()}}});return()=>{n.unsubscribe();s.forEach(i=>i.unsubscribe())}})}switchMap(e){return new r(t=>{let s=null;const n=this.subscribe({next:i=>{if(s){s.unsubscribe()}const o=e(i);s=o.subscribe({next:c=>t.next(c),error:c=>t.error(c),complete:()=>{if(s){s.unsubscribe();s=null}}})},error:i=>t.error(i),complete:()=>{if(s){s.unsubscribe()}t.complete()}});return()=>{n.unsubscribe();if(s){s.unsubscribe()}}})}toArray(){return new Promise((e,t)=>{const s=[];this.subscribe({next:n=>s.push(n),error:n=>t(n),complete:()=>e(s)})})}forEach(e){return new Promise((t,s)=>{this.subscribe({next:n=>e(n),error:n=>s(n),complete:()=>t()})})}every(e){return new Promise((t,s)=>{let n=true;this.subscribe({next:i=>{if(!e(i)){n=false;t(false)}},error:i=>s(i),complete:()=>t(n)})})}find(e){return new Promise((t,s)=>{const n=this.subscribe({next:i=>{if(e(i)){t(i);n.unsubscribe()}},error:i=>s(i),complete:()=>t(void 0)})})}some(e){return new Promise((t,s)=>{const n=this.subscribe({next:i=>{if(e(i)){t(true);n.unsubscribe()}},error:i=>s(i),complete:()=>t(false)})})}finally(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(n),error:n=>{e();t.error(n)},complete:()=>{e();t.complete()}});return()=>{s.unsubscribe()}})}toState(e=null){const t=new w(e,null,{name:"ObservableStream"});this.subscribe({next:s=>t.update(()=>s),error:s=>t.error(s),complete:()=>t.complete()});return t}push(e){if(e instanceof y){const t=e.subscribe({next:s=>this.__observers.forEach(n=>n.next(s)),error:s=>this.__observers.forEach(n=>n.error(s)),complete:()=>this.__observers.forEach(s=>s.complete())})}else if(e[Symbol.asyncIterator]){(()=>k(this,null,function*(){try{try{for(var t=ge(e),s,n,i;s=!(n=yield t.next()).done;s=false){const o=n.value;this.__observers.forEach(c=>c.next(o))}}catch(n){i=[n]}finally{try{s&&(n=t.return)&&(yield n.call(t))}finally{if(i)throw i[0]}}this.__observers.forEach(o=>o.complete())}catch(o){this.__observers.forEach(c=>c.error(o))}}))()}else if(e[Symbol.iterator]){try{for(const t of e){this.__observers.forEach(s=>s.next(t))}this.__observers.forEach(t=>t.complete())}catch(t){this.__observers.forEach(s=>s.error(t))}}else if(e instanceof Promise){e.then(t=>{this.__observers.forEach(s=>s.next(t));this.__observers.forEach(s=>s.complete())},t=>this.__observers.forEach(s=>s.error(t)))}else{this.__observers.forEach(t=>t.next(e))}}plug(e){e.subscribe({next:t=>this.push(t),error:t=>this.__observers.forEach(s=>s.error(t)),complete:()=>this.__observers.forEach(t=>t.complete())})}end(){this.__observers.forEach(e=>{if(e&&typeof e.complete==="function"){e.complete()}})}catchError(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(n),error:n=>{const i=e(n);i.subscribe({next:o=>t.next(o),error:o=>t.error(o),complete:()=>t.complete()})},complete:()=>t.complete()});return()=>s.unsubscribe()})}debounce(e){return new r(t=>{let s=null;const n=this.subscribe({next:i=>{clearTimeout(s);s=setTimeout(()=>{t.next(i)},e)},error:i=>t.error(i),complete:()=>{clearTimeout(s);t.complete()}});return()=>{clearTimeout(s);n.unsubscribe()}})}tap(e){return new r(t=>{const s=this.subscribe({next:n=>{e(n);t.next(n)},error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}throttle(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{const o=Date.now();if(o-s>e){s=o;t.next(i)}},error:i=>t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}distinctUntilChanged(){return new r(e=>{let t;let s=true;const n=this.subscribe({next:i=>{if(s||i!==t){s=false;t=i;e.next(i)}},error:i=>e.error(i),complete:()=>e.complete()});return()=>n.unsubscribe()})}concatMap(e){return new r(t=>{let s=null;let n=false;const i=[];const o=this.subscribe({next:c=>{if(!n){n=true;const a=e(c);s=a.subscribe({next:u=>t.next(u),error:u=>t.error(u),complete:()=>{if(i.length>0){const u=i.shift();const f=e(u);s=f.subscribe({next:l=>t.next(l),error:l=>t.error(l),complete:()=>n=false})}else{n=false}}})}else{i.push(c)}},error:c=>t.error(c),complete:()=>{if(!n){t.complete()}}});return()=>{o.unsubscribe();if(s){s.unsubscribe()}}})}combineLatest(...e){return new r(t=>{const s=new Array(e.length).fill(void 0);const n=e.map((i,o)=>i.subscribe({next:c=>{s[o]=c;if(!s.includes(void 0)){t.next([...s])}},error:c=>t.error(c),complete:()=>{}}));return()=>n.forEach(i=>i.unsubscribe())})}startWith(...e){return new r(t=>{e.forEach(n=>t.next(n));const s=this.subscribe({next:n=>t.next(n),error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}};var R={current:null};var w=class extends y{constructor(e=null,t=null,{last:s=false,name:n=null}={}){super();if(s){this.__lastObserver=t}else{this.__observers.push(t)}this.__value=C(e,i=>{});this.__pendingUpdates=[];this.__updateScheduled=false;this.__name=n}get value(){if(R.current!=null){R.current.addDependency(this)}return this.__value}set value(e){this.update(()=>e)}assign(e){if(typeof this.__value!=="object"||this.__value===null){throw new Error("[Cami.js] Observable value is not an object")}this.update(t=>Object.assign(t,e))}set(e,t){if(typeof this.__value!=="object"||this.__value===null){throw new Error("[Cami.js] Observable value is not an object")}this.update(s=>{const n=e.split(".");let i=s;for(let o=0;o{const s=e.split(".");let n=t;for(let i=0;i({}))}push(...e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.push(...e)})}pop(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.pop()})}shift(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.shift()})}splice(e,t,...s){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.splice(e,t,...s)})}unshift(...e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.unshift(...e)})}reverse(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.reverse()})}sort(e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.sort(e)})}fill(e,t=0,s=this.__value.length){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.fill(e,t,s)})}copyWithin(e,t,s=this.__value.length){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.copyWithin(e,t,s)})}update(e){this.__pendingUpdates.push(e);this.__scheduleupdate()}__scheduleupdate(){if(!this.__updateScheduled){this.__updateScheduled=true;this.__applyUpdates()}}__notifyObservers(){const e=[...this.__observers,this.__lastObserver];e.forEach(t=>{if(t&&typeof t==="function"){t(this.__value)}else if(t&&t.next){t.next(this.__value)}})}__applyUpdates(){let e=this.__value;while(this.__pendingUpdates.length>0){const t=this.__pendingUpdates.shift();if(typeof this.__value==="object"&&this.__value!==null&&this.__value.constructor===Object||Array.isArray(this.__value)){this.__value=C(this.__value,t)}else{this.__value=t(this.__value)}}if(e!==this.__value){this.__notifyObservers();if(j.events.isEnabled&&typeof window!=="undefined"){const t=new CustomEvent("cami:state:change",{detail:{name:this.__name,oldValue:e,newValue:this.__value}});window.dispatchEvent(t)}_("cami:state:change",this.__name,e,this.__value)}this.__updateScheduled=false}toStream(){const e=new v;this.subscribe({next:t=>e.emit(t),error:t=>e.error(t),complete:()=>e.end()});return e}complete(){this.__observers.forEach(e=>{if(e&&typeof e.complete==="function"){e.complete()}})}};var Le=class extends w{constructor(e){super(null);this.computeFn=e;this.dependencies=new Set;this.subscriptions=new Map;this.__compute()}get value(){if(R.current){R.current.addDependency(this)}return this.__value}__compute(){const e={addDependency:s=>{if(!this.dependencies.has(s)){const n=s.onValue(()=>this.__compute());this.dependencies.add(s);this.subscriptions.set(s,n)}}};R.current=e;const t=this.computeFn();R.current=null;if(t!==this.__value){this.__value=t;this.__notifyObservers()}}dispose(){this.subscriptions.forEach(e=>{e.unsubscribe()})}};var he=function(r){return new Le(r)};var fe=function(r){let e=()=>{};let t=new Set;let s=new Map;const n={addDependency:c=>{if(!t.has(c)){const a=c.onValue(i);t.add(c);s.set(c,a)}}};const i=()=>{e();R.current=n;e=r()||(()=>{});R.current=null};if(typeof window!=="undefined"){requestAnimationFrame(i)}else{setTimeout(i,0)}const o=()=>{s.forEach(c=>{c.unsubscribe()});e()};return o};var de=class{constructor(e){if(!(e instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}return new Proxy(e,{get:(t,s)=>{if(typeof t[s]==="function"){return t[s].bind(t)}else if(s in t){return t[s]}else if(typeof t.value[s]==="function"){return(...n)=>t.value[s](...n)}else{return t.value[s]}},set:(t,s,n)=>{t[s]=n;t.update(()=>t.value);return true}})}};var O=new Map;var _e=class extends HTMLElement{constructor(){super();this.onCreate();this.__unsubscribers=new Map;this.__computed=he.bind(this);this.effect=fe.bind(this);this.__queryFunctions=new Map}observableAttributes(e){Object.entries(e).forEach(([t,s])=>{let n=this.getAttribute(t);const i=typeof s==="function"?s:c=>c;n=C(n,i);const o=this.__observable(n,t);if(this.__isObjectOrArray(o.value)){this.__createObservablePropertyForObjOrArr(this,t,o,true)}else{this.__createObservablePropertyForPrimitive(this,t,o,true)}})}__computed(e){const t=super._computed(e);console.log(t);this.__registerObservables(t);return t}effect(e){const t=super.effect(e);this.__unsubscribers.set(e,t)}connect(e,t){if(!(e instanceof D)){throw new TypeError("Expected store to be an instance of ObservableStore")}const s=this.__observable(e.state[t],t);const n=e.subscribe(i=>{s.update(()=>i[t])});this.__unsubscribers.set(t,n);if(this.__isObjectOrArray(s.value)){this.__createObservablePropertyForObjOrArr(this,t,s);return this[t]}else{this.__createObservablePropertyForPrimitive(this,t,s);return this[t]}}stream(e){return new v(e)}template(){throw new Error("[Cami.js] You have to implement the method template()!")}query({queryKey:e,queryFn:t,staleTime:s=0,refetchOnWindowFocus:n=true,refetchOnMount:i=true,refetchOnReconnect:o=true,refetchInterval:c=null,gcTime:a=1e3*60*5,retry:u=3,retryDelay:f=l=>Math.pow(2,l)*1e3}){const l=Array.isArray(e)?e.map(E=>typeof E==="object"?JSON.stringify(E):E).join(":"):e;this.__queryFunctions.set(l,t);_("query","Starting query with key:",l);const d=this.__observable({data:null,status:"pending",fetchStatus:"idle",error:null,lastUpdated:O.has(l)?O.get(l).lastUpdated:null},l);const h=this.__observableProxy(d);const m=(E=0)=>k(this,null,function*(){const We=Date.now();const be=O.get(l);if(be&&We-be.lastUpdated{A.data=be.data;A.status="success";A.fetchStatus="idle"})}else{_("fetchData (else)","Fetching data for key:",l);try{h.update(T=>{T.status="pending";T.fetchStatus="fetching"});const A=yield t();O.set(l,{data:A,lastUpdated:We});h.update(T=>{T.data=A;T.status="success";T.fetchStatus="idle"})}catch(A){_("fetchData (catch)","Fetch error for key:",l,A);if(Em(E+1),f(E))}else{h.update(T=>{T.errorDetails={message:A.message,stack:A.stack};T.status="error";T.fetchStatus="idle"})}}}});if(i){_("query","Setting up refetch on mount for key:",l);m()}if(n){_("query","Setting up refetch on window focus for key:",l);const E=()=>m();window.addEventListener("focus",E);this.__unsubscribers.set(`focus:${l}`,()=>window.removeEventListener("focus",E))}if(o){_("query","Setting up refetch on reconnect for key:",l);window.addEventListener("online",m);this.__unsubscribers.set(`online:${l}`,()=>window.removeEventListener("online",m))}if(c){_("query","Setting up refetch interval for key:",l);const E=setInterval(m,c);this.__unsubscribers.set(`interval:${l}`,()=>clearInterval(E))}const U=setTimeout(()=>{O.delete(l)},a);this.__unsubscribers.set(`gc:${l}`,()=>clearTimeout(U));return h}mutation({mutationFn:e,onMutate:t,onError:s,onSuccess:n,onSettled:i}){const o=this.__observable({data:null,status:"idle",error:null,isSettled:false},"mutation");const c=this.__observableProxy(o);const a=u=>k(this,null,function*(){_("mutation","Starting mutation for variables:",u);let f;const l=c.value;if(t){_("mutation","Performing optimistic update for variables:",u);f=t(u,l);c.update(d=>{d.data=f.optimisticData;d.status="pending";d.errorDetails=null})}else{_("mutation","Performing mutation without optimistic update for variables:",u);c.update(d=>{d.status="pending";d.errorDetails=null})}try{const d=yield e(u);c.update(h=>{h.data=d;h.status="success"});if(n){n(d,u,f)}_("mutation","Mutation successful for variables:",u,d)}catch(d){_("mutation","Mutation error for variables:",u,d);c.update(h=>{h.errorDetails={message:d.message};h.status="error";if(!s&&f&&f.rollback){_("mutation","Rolling back mutation for variables:",u);f.rollback()}});if(s){s(d,u,f)}}finally{if(!c.value.isSettled){c.update(d=>{d.isSettled=true});if(i){_("mutation","Calling onSettled for variables:",u);i(c.value.data,c.value.error,u,f)}}}});c.mutate=a;c.reset=()=>{c.update(u=>{u.data=null;u.status="idle";u.errorDetails=null;u.isSettled=false})};return c}invalidateQueries(e){const t=Array.isArray(e)?e.join(":"):e;_("invalidateQueries","Invalidating query with key:",t);O.delete(t);this.__updateCache(t)}onCreate(){}connectedCallback(){this.__setup({infer:true});this.effect(()=>this.render());this.render();this.onConnect()}onConnect(){}disconnectedCallback(){this.onDisconnect();this.__unsubscribers.forEach(e=>e())}onDisconnect(){}attributeChangedCallback(e,t,s){this.onAttributeChange(e,t,s)}onAttributeChange(e,t,s){}adoptedCallback(){this.onAdopt()}onAdopt(){}__isObjectOrArray(e){return e!==null&&(typeof e==="object"||Array.isArray(e))}__createObservablePropertyForObjOrArr(e,t,s,n=false){if(!(s instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}const i=this.__observableProxy(s);Object.defineProperty(e,t,{get:()=>i,set:o=>{s.update(()=>o);if(n){this.setAttribute(t,o)}}})}__createObservablePropertyForPrimitive(e,t,s,n=false){if(!(s instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}Object.defineProperty(e,t,{get:()=>s.value,set:i=>{s.update(()=>i);if(n){this.setAttribute(t,i)}}})}__observableProxy(e){return new de(e)}__setup(e){if(e.infer===true){Object.keys(this).forEach(t=>{if(typeof this[t]!=="function"&&!t.startsWith("__")){if(this[t]instanceof y){return}else{const s=this.__observable(this[t],t);if(this.__isObjectOrArray(s.value)){this.__createObservablePropertyForObjOrArr(this,t,s)}else{this.__createObservablePropertyForPrimitive(this,t,s)}}}})}}__observable(e,t){if(!this.__isAllowedType(e)){const n=Object.prototype.toString.call(e);throw new Error(`[Cami.js] The value of type ${n} is not allowed in observables. Only primitive values, arrays, and plain objects are allowed.`)}const s=new w(e,null,{name:t});this.__registerObservables(s);return s}__updateCache(e){_("__updateCache","Invalidating cache with key:",e);const t=this.__queryFunctions.get(e);if(t){_("__updateCache","Found query function for key:",e);const s=O.get(e)||{data:void 0,status:"idle",error:null};O.set(e,we(S({},s),{status:"pending",error:null}));t().then(n=>{O.set(e,{data:n,status:"success",error:null,lastUpdated:Date.now()});_("__updateCache","Refetch successful for key:",e,n)}).catch(n=>{if(s.data!==void 0){_("__updateCache","Rolling back refetch for key:",e);O.set(e,s)}O.set(e,we(S({},s),{status:"error",error:n}))})}}__isAllowedType(e){const t=["number","string","boolean","object","undefined"];const s=typeof e;if(s==="object"){return e===null||Array.isArray(e)||this.__isPlainObject(e)}return t.includes(s)}__isPlainObject(e){if(Object.prototype.toString.call(e)!=="[object Object]"){return false}const t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}__registerObservables(e){if(!(e instanceof w)){throw new TypeError("Expected observableState to be an instance of ObservableState")}this.__unsubscribers.set(e,()=>{if(typeof e.dispose==="function"){e.dispose()}})}render(){const e=this.template();je(e,this)}};var pe=class extends v{constructor(e){super();if(typeof e==="string"){this.element=document.querySelector(e);if(!this.element){throw new Error(`[Cami.js] Element not found for selector: ${e}`)}}else if(e instanceof Element||e instanceof Document){this.element=e}else{throw new Error(`[Cami.js] Invalid argument: ${e}`)}}on(e,t={}){return new v(s=>{const n=i=>{s.next(i)};this.element.addEventListener(e,n,t);return()=>{this.element.removeEventListener(e,n,t)}})}};var me=class extends v{constructor(){super(...arguments);Ge(this,"__handlers",{})}toJson(){return new Promise((t,s)=>{this.subscribe({next:n=>{try{if(typeof n==="object"){t(n)}else{t(JSON.parse(n))}}catch(i){s(i)}},error:n=>s(n)})})}on(t,s){if(!this.__handlers[t]){this.__handlers[t]=[]}this.__handlers[t].push(s);return this}};var g=r=>{if(typeof r==="string"){return g.get(r)}return new me(e=>{const t=new XMLHttpRequest;t.open(r.method||"GET",r.url);if(r.headers){Object.keys(r.headers).forEach(s=>{t.setRequestHeader(s,r.headers[s])})}t.onload=()=>{let s=t.responseText;const n=r.transformResponse||(i=>{try{return JSON.parse(i)}catch(o){return i}});s=n(s);e.next(s);e.complete()};t.onerror=()=>e.error(t.statusText);t.send(r.data?JSON.stringify(r.data):null);return()=>{t.abort()}})};g.get=(r,e={})=>{e.url=r;e.method="GET";return g(e)};g.post=(r,e={},t={})=>{t.url=r;t.data=e;t.method="POST";return g(t)};g.put=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PUT";return g(t)};g.patch=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PATCH";return g(t)};g.delete=(r,e={})=>{e.url=r;e.method="DELETE";return g(e)};g.sse=(r,e={})=>{const t=new me(s=>{const n=new EventSource(r,e);n.onmessage=i=>{if(t.__handlers[i.type]){t.__handlers[i.type].forEach(o=>o(i))}s.next(i)};n.onerror=i=>s.error(i);return()=>{n.close()}});return t};var{debug:or,events:cr}=j;return Dt(ar);})(); /** * @license * lit-html diff --git a/docs/javascripts/cami.cdn.js.map b/docs/javascripts/cami.cdn.js.map index 64660038..87ed9c45 100644 --- a/docs/javascripts/cami.cdn.js.map +++ b/docs/javascripts/cami.cdn.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../src/cami.js", "../src/html.js", "../src/produce.js", "../src/observables/observable.js", "../src/config.js", "../src/trace.js", "../src/observables/observable-store.js", "../src/observables/observable-stream.js", "../src/observables/observable-state.js", "../src/observables/observable-proxy.js", "../src/reactive-element.js", "../src/observables/observable-element.js", "../src/http.js"], - "sourcesContent": ["/**\n * @license\n * cami.js\n * Copyright (c) 2023 Kenn Costales\n * MIT License\n */\n\n/**\n * @module cami\n */\nimport { html, render, svg } from './html.js';\nimport { produce } from \"./produce.js\"\nimport { ReactiveElement } from './reactive-element.js';\nimport { ObservableStore, store } from './observables/observable-store.js';\nimport { Observable } from './observables/observable.js';\nimport { ObservableState, computed, effect } from './observables/observable-state.js';\nimport { ObservableStream } from './observables/observable-stream.js';\nimport { ObservableElement } from './observables/observable-element.js';\nimport { __config } from './config.js';\nimport { __trace } from './trace.js';\nimport { http } from './http.js';\n\nconst { debug, events } = __config;\n\n/**\n * @exports store - The store object from observable-store.js. This uses local storage by default.\n * @exports html - The html function from html.js\n * @exports svg - The svg function from html.js\n * @exports ReactiveElement - The ReactiveElement class from reactive_element.js\n * @exports ObservableStream - The ObservableStream class from observable-stream.js\n * @exports ObservableElement - The ObservableElement class from observable-element.js\n * @exports Observable - The Observable class from observable.js\n * @exports ObservableState - The ObservableState class from observable-state.js\n * @exports ObservableStore - The ObservableStore class from observable-store.js\n * @exports http - The http function from http.js\n * @exports debug - The debug property from __config\n * @exports events - The events property from __config\n */\nexport { store, html, svg, ReactiveElement, ObservableStream, ObservableElement, Observable, ObservableState, ObservableStore, http, debug, events, computed, effect };\n", "/**\n * @license\n * lit-html\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n// Allows minifiers to rename references to globalThis\nconst global = globalThis;\nconst wrap = (node) => node;\nconst trustedTypes = global.trustedTypes;\n/**\n * Our TrustedTypePolicy for HTML which is declared using the html template\n * tag function.\n *\n * That HTML is a developer-authored constant, and is parsed with innerHTML\n * before any untrusted expressions have been mixed in. Therefor it is\n * considered safe by construction.\n */\nconst policy = trustedTypes\n ? trustedTypes.createPolicy('cami-html', {\n createHTML: (s) => s,\n })\n : undefined;\n// Added to an attribute name to mark the attribute as bound so we can find\n// it easily.\nconst boundAttributeSuffix = '$cami$';\n// This marker is used in many syntactic positions in HTML, so it must be\n// a valid element name and attribute name. We don't support dynamic names (yet)\n// but this at least ensures that the parse tree is closer to the template\n// intention.\nconst marker = `cami$${String(Math.random()).slice(9)}$`;\n// String used to tell if a comment is a marker comment\nconst markerMatch = '?' + marker;\n// Text used to insert a comment marker node. We use processing instruction\n// syntax because it's slightly smaller, but parses as a comment node.\nconst nodeMarker = `<${markerMatch}>`;\nconst d = document;\n// Creates a dynamic marker. We never have to search for these in the DOM.\nconst createMarker = () => d.createComment('');\nconst isPrimitive = (value) => value === null || (typeof value != 'object' && typeof value != 'function');\nconst isArray = Array.isArray;\nconst isIterable = (value) => isArray(value) ||\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof value?.[Symbol.iterator] === 'function';\nconst SPACE_CHAR = `[ \\t\\n\\f\\r]`;\nconst ATTR_VALUE_CHAR = `[^ \\t\\n\\f\\r\"'\\`<>=]`;\nconst NAME_CHAR = `[^\\\\s\"'>=/]`;\n// These regexes represent the five parsing states that we care about in the\n// Template's HTML scanner. They match the *end* of the state they're named\n// after.\n// Depending on the match, we transition to a new state. If there's no match,\n// we stay in the same state.\n// Note that the regexes are stateful. We utilize lastIndex and sync it\n// across the multiple regexes used. In addition to the five regexes below\n// we also dynamically create a regex to find the matching end tags for raw\n// text elements.\n/**\n * End of text is: `<` followed by:\n * (comment start) or (tag) or (dynamic tag binding)\n */\nconst textEndRegex = /<(?:(!--|\\/[^a-zA-Z])|(\\/?[a-zA-Z][^>\\s]*)|(\\/?$))/g;\nconst COMMENT_START = 1;\nconst TAG_NAME = 2;\nconst DYNAMIC_TAG_NAME = 3;\nconst commentEndRegex = /-->/g;\n/**\n * Comments not started with /g;\n/**\n * Comments not started with /g;var Ye=/>/g;var V=new RegExp(`>|${xe}(?:(${It}+)(${xe}*=${xe}*(?:${Mt}|("|')|))|$)`,"g");var Ft=0;var Ze=1;var zt=2;var et=3;var tt=/'/g;var rt=/"/g;var ct=/^(?:script|style|textarea|title)$/i;var Ut=1;var te=2;var Se=1;var re=2;var kt=3;var Ht=4;var Lt=5;var Ce=6;var Wt=7;var at=r=>(e,...t)=>{return{["_$camiType$"]:r,strings:e,values:t}};var Pe=at(Ut);var ut=at(te);var J=Symbol.for("cami-noChange");var p=Symbol.for("cami-nothing");var st=new WeakMap;var M=I.createTreeWalker(I,129);function lt(r,e){if(!Array.isArray(r)||!r.hasOwnProperty("raw")){let t="invalid template strings array";throw new Error(t)}return Je!==void 0?Je.createHTML(e):e}var Qt=(r,e)=>{const t=r.length-1;const s=[];let n=e===te?"":"";let i;let o=q;for(let a=0;a"){o=i!=null?i:q;f=-1}else if(h[Ze]===void 0){f=-2}else{f=o.lastIndex-h[zt].length;l=h[Ze];o=h[et]===void 0?V:h[et]==='"'?rt:tt}}else if(o===rt||o===tt){o=V}else if(o===Xe||o===Ye){o=q}else{o=V;i=void 0}}const m=o===V&&r[a+1].startsWith("/>")?" ":"";n+=o===q?u+Rt:f>=0?(s.push(l),u.slice(0,f)+nt+u.slice(f))+P+m:u+P+(f===-2?a:m)}const c=n+(r[t]||"")+(e===te?"":"");return[lt(r,c),s]};var se=class r{constructor({strings:e,["_$camiType$"]:t},s){this.parts=[];let n;let i=0;let o=0;const c=e.length-1;const a=this.parts;const[u,f]=Qt(e,t);this.el=r.createElement(u,s);M.currentNode=this.el.content;if(t===te){const l=this.el.content.firstChild;l.replaceWith(...l.childNodes)}while((n=M.nextNode())!==null&&a.length0){n.textContent=ee?ee.emptyScript:"";for(let h=0;h2||s[0]!==""||s[1]!==""){this._$committedValue=new Array(s.length-1).fill(new String);this.strings=s}else{this._$committedValue=p}}_$setValue(e,t=this,s,n){const i=this.strings;let o=false;if(i===void 0){e=H(this,e,t,0);o=!G(e)||e!==this._$committedValue&&e!==J;if(o){this._$committedValue=e}}else{const c=e;e=i[0];let a,u;for(a=0;a{var i,o;const s=(i=t==null?void 0:t.renderBefore)!=null?i:e;let n=s["_$camiPart$"];if(n===void 0){const c=(o=t==null?void 0:t.renderBefore)!=null?o:null;s["_$camiPart$"]=n=new ne(e.insertBefore(B(),c),c,void 0,t!=null?t:{})}n._$setValue(r);return n};var mt=Symbol.for("immer-nothing");var ht=Symbol.for("immer-draftable");var x=Symbol.for("immer-state");var qt=true?[function(r){return`The plugin for '${r}' has not been loaded into Immer. To enable the plugin, import and call \`enable${r}()\` when initializing your application.`},function(r){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${r}'`},"This object has been frozen and should not be mutated",function(r){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+r},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Cami Observables forbid circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(r){return`'current' expects a draft, got: ${r}`},"Object.defineProperty() cannot be used on a Cami Observable draft","Object.setPrototypeOf() cannot be used on a Cami Observable draft","Cami Observables only support deleting array indices","Cami Observables only support setting array indices and the 'length' property",function(r){return`'original' expects a draft, got: ${r}`}]:[];function b(r,...e){if(true){const t=qt[r];const s=typeof t==="function"?t.apply(null,e):t;throw new Error(`[Cami.js] ${s}`)}throw new Error(`[Cami.js] minified error nr: ${r}.`)}var W=Object.getPrototypeOf;function Q(r){return!!r&&!!r[x]}function F(r){var e;if(!r)return false;return bt(r)||Array.isArray(r)||!!r[ht]||!!((e=r.constructor)==null?void 0:e[ht])||ae(r)||ue(r)}var Bt=Object.prototype.constructor.toString();function bt(r){if(!r||typeof r!=="object")return false;const e=W(r);if(e===null){return true}const t=Object.hasOwnProperty.call(e,"constructor")&&e.constructor;if(t===Object)return true;return typeof t=="function"&&Function.toString.call(t)===Bt}function K(r,e){if(ce(r)===0){Object.entries(r).forEach(([t,s])=>{e(t,s,r)})}else{r.forEach((t,s)=>e(s,t,r))}}function ce(r){const e=r[x];return e?e.type_:Array.isArray(r)?1:ae(r)?2:ue(r)?3:0}function Ve(r,e){return ce(r)===2?r.has(e):Object.prototype.hasOwnProperty.call(r,e)}function yt(r,e,t){const s=ce(r);if(s===2)r.set(e,t);else if(s===3){r.add(t)}else r[e]=t}function Gt(r,e){if(r===e){return r!==0||1/r===1/e}else{return r!==r&&e!==e}}function ae(r){return r instanceof Map}function ue(r){return r instanceof Set}function N(r){return r.copy_||r.base_}function Me(r,e){if(ae(r)){return new Map(r)}if(ue(r)){return new Set(r)}if(Array.isArray(r))return Array.prototype.slice.call(r);if(!e&&bt(r)){if(!W(r)){const n=Object.create(null);return Object.assign(n,r)}return S({},r)}const t=Object.getOwnPropertyDescriptors(r);delete t[x];let s=Reflect.ownKeys(t);for(let n=0;n1){r.set=r.add=r.clear=r.delete=Jt}Object.freeze(r);if(e)K(r,(t,s)=>Ue(s,true),true);return r}function Jt(){b(2)}function le(r){return Object.isFrozen(r)}var Kt={};function z(r){const e=Kt[r];if(!e){b(0,r)}return e}var X;function wt(){return X}function Xt(r,e){return{drafts_:[],parent_:r,immer_:e,canAutoFreeze_:true,unfinalizedDrafts_:0}}function ft(r,e){if(e){z("Patches");r.patches_=[];r.inversePatches_=[];r.patchListener_=e}}function Ie(r){Ne(r);r.drafts_.forEach(Yt);r.drafts_=null}function Ne(r){if(r===X){X=r.parent_}}function dt(r){return X=Xt(X,r)}function Yt(r){const e=r[x];if(e.type_===0||e.type_===1)e.revoke_();else e.revoked_=true}function _t(r,e){e.unfinalizedDrafts_=e.drafts_.length;const t=e.drafts_[0];const s=r!==void 0&&r!==t;if(s){if(t[x].modified_){Ie(e);b(4)}if(F(r)){r=ie(e,r);if(!e.parent_)oe(e,r)}if(e.patches_){z("Patches").generateReplacementPatches_(t[x].base_,r,e.patches_,e.inversePatches_)}}else{r=ie(e,t,[])}Ie(e);if(e.patches_){e.patchListener_(e.patches_,e.inversePatches_)}return r!==mt?r:void 0}function ie(r,e,t){if(le(e))return e;const s=e[x];if(!s){K(e,(n,i)=>pt(r,s,e,n,i,t),true);return e}if(s.scope_!==r)return e;if(!s.modified_){oe(r,s.base_,true);return s.base_}if(!s.finalized_){s.finalized_=true;s.scope_.unfinalizedDrafts_--;const n=s.copy_;let i=n;let o=false;if(s.type_===3){i=new Set(n);n.clear();o=true}K(i,(c,a)=>pt(r,s,n,c,a,t,o));oe(r,n,false);if(t&&r.patches_){z("Patches").generatePatches_(s,t,r.patches_,r.inversePatches_)}}return s.copy_}function pt(r,e,t,s,n,i,o){if(n===t)b(5);if(Q(n)){const c=i&&e&&e.type_!==3&&!Ve(e.assigned_,s)?i.concat(s):void 0;const a=ie(r,n,c);yt(t,s,a);if(Q(a)){r.canAutoFreeze_=false}else return}else if(o){t.add(n)}if(F(n)&&!le(n)){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1){return}ie(r,n);if(!e||!e.scope_.parent_)oe(r,n)}}function oe(r,e,t=false){if(!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_){Ue(e,t)}}function Zt(r,e){const t=Array.isArray(r);const s={type_:t?1:0,scope_:e?e.scope_:wt(),modified_:false,finalized_:false,assigned_:{},parent_:e,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:false};let n=s;let i=ke;if(t){n=[s];i=Y}const{revoke:o,proxy:c}=Proxy.revocable(n,i);s.draft_=c;s.revoke_=o;return c}var ke={get(r,e){if(e===x)return r;const t=N(r);if(!Ve(t,e)){return er(r,t,e)}const s=t[e];if(r.finalized_||!F(s)){return s}if(s===De(r.base_,e)){Re(r);return r.copy_[e]=ze(s,r)}return s},has(r,e){return e in N(r)},ownKeys(r){return Reflect.ownKeys(N(r))},set(r,e,t){const s=gt(N(r),e);if(s==null?void 0:s.set){s.set.call(r.draft_,t);return true}if(!r.modified_){const n=De(N(r),e);const i=n==null?void 0:n[x];if(i&&i.base_===t){r.copy_[e]=t;r.assigned_[e]=false;return true}if(Gt(t,n)&&(t!==void 0||Ve(r.base_,e)))return true;Re(r);Fe(r)}if(r.copy_[e]===t&&(t!==void 0||e in r.copy_)||Number.isNaN(t)&&Number.isNaN(r.copy_[e]))return true;r.copy_[e]=t;r.assigned_[e]=true;return true},deleteProperty(r,e){if(De(r.base_,e)!==void 0||e in r.base_){r.assigned_[e]=false;Re(r);Fe(r)}else{delete r.assigned_[e]}if(r.copy_){delete r.copy_[e]}return true},getOwnPropertyDescriptor(r,e){const t=N(r);const s=Reflect.getOwnPropertyDescriptor(t,e);if(!s)return s;return{writable:true,configurable:r.type_!==1||e!=="length",enumerable:s.enumerable,value:t[e]}},defineProperty(){b(11)},getPrototypeOf(r){return W(r.base_)},setPrototypeOf(){b(12)}};var Y={};K(ke,(r,e)=>{Y[r]=function(){arguments[0]=arguments[0][0];return e.apply(this,arguments)}});Y.deleteProperty=function(r,e){if(isNaN(parseInt(e)))b(13);return Y.set.call(this,r,e,void 0)};Y.set=function(r,e,t){if(e!=="length"&&isNaN(parseInt(e)))b(14);return ke.set.call(this,r[0],e,t,r[0])};function De(r,e){const t=r[x];const s=t?N(t):r;return s[e]}function er(r,e,t){var n;const s=gt(e,t);return s?`value`in s?s.value:(n=s.get)==null?void 0:n.call(r.draft_):void 0}function gt(r,e){if(!(e in r))return void 0;let t=W(r);while(t){const s=Object.getOwnPropertyDescriptor(t,e);if(s)return s;t=W(t)}return void 0}function Fe(r){if(!r.modified_){r.modified_=true;if(r.parent_){Fe(r.parent_)}}}function Re(r){if(!r.copy_){r.copy_=Me(r.base_,r.scope_.immer_.useStrictShallowCopy_)}}var tr=class{constructor(r){this.autoFreeze_=true;this.useStrictShallowCopy_=false;this.produce=(e,t,s)=>{if(typeof e==="function"&&typeof t!=="function"){const i=t;t=e;const o=this;return function c(a=i,...u){return o.produce(a,f=>t.call(this,f,...u))}}if(typeof t!=="function")b(6);if(s!==void 0&&typeof s!=="function")b(7);let n;if(F(e)){const i=dt(this);const o=ze(e,void 0);let c=true;try{n=t(o);c=false}finally{if(c)Ie(i);else Ne(i)}ft(i,s);return _t(n,i)}else if(!e||typeof e!=="object"){n=t(e);if(n===void 0)n=e;if(n===mt)n=void 0;if(this.autoFreeze_)Ue(n,true);if(s){const i=[];const o=[];z("Patches").generateReplacementPatches_(e,n,i,o);s(i,o)}return n}else b(1,e)};this.produceWithPatches=(e,t)=>{if(typeof e==="function"){return(o,...c)=>this.produceWithPatches(o,a=>e(a,...c))}let s,n;const i=this.produce(e,t,(o,c)=>{s=o;n=c});return[i,s,n]};if(typeof(r==null?void 0:r.autoFreeze)==="boolean")this.setAutoFreeze(r.autoFreeze);if(typeof(r==null?void 0:r.useStrictShallowCopy)==="boolean")this.setUseStrictShallowCopy(r.useStrictShallowCopy)}createDraft(r){if(!F(r))b(8);if(Q(r))r=rr(r);const e=dt(this);const t=ze(r,void 0);t[x].isManual_=true;Ne(e);return t}finishDraft(r,e){const t=r&&r[x];if(!t||!t.isManual_)b(9);const{scope_:s}=t;ft(s,e);return _t(void 0,s)}setAutoFreeze(r){this.autoFreeze_=r}setUseStrictShallowCopy(r){this.useStrictShallowCopy_=r}applyPatches(r,e){let t;for(t=e.length-1;t>=0;t--){const n=e[t];if(n.path.length===0&&n.op==="replace"){r=n.value;break}}if(t>-1){e=e.slice(t+1)}const s=z("Patches").applyPatches_;if(Q(r)){return s(r,e)}return this.produce(r,n=>s(n,e))}};function ze(r,e){const t=ae(r)?z("MapSet").proxyMap_(r,e):ue(r)?z("MapSet").proxySet_(r,e):Zt(r,e);const s=e?e.scope_:wt();s.drafts_.push(t);return t}function rr(r){if(!Q(r))b(10,r);return xt(r)}function xt(r){if(!F(r)||le(r))return r;const e=r[x];let t;if(e){if(!e.modified_)return e.base_;e.finalized_=true;t=Me(r,e.scope_.immer_.useStrictShallowCopy_)}else{t=Me(r,true)}K(t,(s,n)=>{yt(t,s,xt(n))});if(e){e.finalized_=false}return t}var sr=new tr;var C=sr.produce;var He=class{constructor(e){if(typeof e==="function"){this.observer={next:e}}else{this.observer=e}this.teardowns=[];if(typeof AbortController!=="undefined"){this.controller=new AbortController;this.signal=this.controller.signal}this.isUnsubscribed=false}next(e){if(!this.isUnsubscribed&&this.observer.next){this.observer.next(e)}}complete(){if(!this.isUnsubscribed){if(this.observer.complete){this.observer.complete()}this.unsubscribe()}}error(e){if(!this.isUnsubscribed){if(this.observer.error){this.observer.error(e)}this.unsubscribe()}}addTeardown(e){this.teardowns.push(e)}unsubscribe(){if(!this.isUnsubscribed){this.isUnsubscribed=true;if(this.controller){this.controller.abort()}this.teardowns.forEach(e=>{if(typeof e!=="function"){throw new Error("[Cami.js] Teardown must be a function. Please implement a teardown function in your subscriber.")}e()})}}};var y=class{constructor(e=()=>()=>{}){this.__observers=[];this.subscribeCallback=e}subscribe(e=()=>{},t=()=>{},s=()=>{}){let n;if(typeof e==="function"){n={next:e,error:t,complete:s}}else if(typeof e==="object"){n=e}else{throw new Error("[Cami.js] First argument to subscribe must be a next callback or an observer object")}const i=new He(n);let o=()=>{};try{o=this.subscribeCallback(i)}catch(c){if(i.error){i.error(c)}else{console.error("[Cami.js] Error in Subscriber:",c)}return}i.addTeardown(o);this.__observers.push(i);return{unsubscribe:()=>i.unsubscribe(),complete:()=>i.complete(),error:c=>i.error(c)}}next(e){this.__observers.forEach(t=>{t.next(e)})}error(e){this.__observers.forEach(t=>{t.error(e)})}complete(){this.__observers.forEach(e=>{e.complete()})}onValue(e){return this.subscribe({next:e})}onError(e){return this.subscribe({error:e})}onEnd(e){return this.subscribe({complete:e})}[Symbol.asyncIterator](){let e;let t;let s=new Promise(n=>t=n);e={next:n=>{t({value:n,done:false});s=new Promise(i=>t=i)},complete:()=>{t({done:true})},error:n=>{throw n}};this.subscribe(e);return{next:()=>s}}};var j={events:{__state:true,get isEnabled(){return this.__state},enable:function(){this.__state=true},disable:function(){this.__state=false}},debug:{__state:false,get isEnabled(){return this.__state},enable:function(){console.log("Cami.js debug mode enabled");this.__state=true},disable:function(){this.__state=false}}};function _(r,...e){if(j.debug.isEnabled){if(r==="cami:state:change"){console.groupCollapsed(`%c[${r}]`,"color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;",`${e[0]} changed`);console.log(`oldValue:`,e[1]);console.log(`newValue:`,e[2])}else{console.groupCollapsed(`%c[${r}]`,"color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;",...e)}console.trace();console.groupEnd()}}var D=class extends y{constructor(e){if(typeof e!=="object"||e===null){throw new TypeError("[Cami.js] initialState must be an object")}super(t=>{this.__subscriber=t;return()=>{this.__subscriber=null}});this.state=new Proxy(e,{get:(t,s)=>{return t[s]},set:(t,s,n)=>{t[s]=n;this.__observers.forEach(i=>i.next(this.state));if(this.devTools){this.devTools.send(s,this.state)}return true}});this.reducers={};this.middlewares=[];this.devTools=this.__connectToDevTools();this.dispatchQueue=[];this.isDispatching=false;this.queryCache=new Map;this.queryFunctions=new Map;this.queries={};this.intervals=new Map;this.focusHandlers=new Map;this.reconnectHandlers=new Map;this.gcTimeouts=new Map;Object.keys(e).forEach(t=>{if(typeof e[t]==="function"){this.register(t,e[t])}else{this.state[t]=e[t]}})}__applyMiddleware(e,...t){const s={state:this.state,action:e,payload:t};for(const n of this.middlewares){n(s)}}__connectToDevTools(){if(typeof window!=="undefined"&&window["__REDUX_DEVTOOLS_EXTENSION__"]){const e=window["__REDUX_DEVTOOLS_EXTENSION__"].connect();e.init(this.state);return e}return null}use(e){this.middlewares.push(e)}getState(){return this.state}register(e,t){if(this.reducers[e]){throw new Error(`[Cami.js] Action type ${e} is already registered.`)}this.reducers[e]=t;this[e]=(...s)=>{this.dispatch(e,...s)}}query(e,t){const{queryKey:s,queryFn:n,staleTime:i=0,refetchOnWindowFocus:o=true,refetchInterval:c=null,refetchOnReconnect:a=true,gcTime:u=1e3*60*5,retry:f=3,retryDelay:l=h=>Math.pow(2,h)*1e3}=t;this.queries[e]={queryKey:s,queryFn:n,staleTime:i,refetchOnWindowFocus:o,refetchInterval:c,refetchOnReconnect:a,gcTime:u,retry:f,retryDelay:l};this.queryFunctions.set(s,n);_(`query`,`Starting query with key: ${e}`);if(c!==null){const h=setInterval(()=>{_(`query`,`Interval expired, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e}:`,m))},c);this.intervals[e]=h}if(o){const h=()=>{_(`query`,`Window focus detected, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e} on window focus:`,m))};window.addEventListener("focus",h);this.focusHandlers[e]=h}if(a){const h=()=>{_(`query`,`Reconnect detected, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e} on reconnect:`,m))};window.addEventListener("online",h);this.reconnectHandlers[e]=h}const d=setTimeout(()=>{_(`query`,`Garbage collection timeout expired, refetching query: ${e}`);this.fetch(e).catch(h=>console.error(`Error refetching query ${e} on gc timeout:`,h))},u);this.gcTimeouts[e]=d;this[e]=(...h)=>{return this.fetch(e,...h)}}fetch(e,...t){const s=this.queries[e];if(!s){throw new Error(`[Cami.js] No query found for name: ${e}`)}const{queryKey:n,queryFn:i,staleTime:o,retry:c,retryDelay:a}=s;const u=Array.isArray(n)?n.join(":"):n;const f=this.queryCache.get(u);if(f&&!this._isStale(f,o)){_(`fetch`,`Returning cached data for: ${e} with cacheKey: ${u}`);return Promise.resolve(f.data)}_(`fetch`,`Data is stale or not cached, fetching new data for: ${e}`);this.dispatch(`${e}/pending`);return this._fetchWithRetry(i,t,c,a).then(l=>{this.queryCache.set(u,{data:l,timestamp:Date.now()});this.dispatch(`${e}/success`,l);return l}).catch(l=>{this.dispatch(`${e}/error`,l);throw l})}invalidateQueries(e){const t=this.queries[e];if(!t)return;const s=Array.isArray(t.queryKey)?t.queryKey.join(":"):t.queryKey;_(`invalidateQueries`,`Invalidating query with key: ${e}`);if(this.intervals[e]){clearInterval(this.intervals[e]);delete this.intervals[e]}if(this.focusHandlers[e]){window.removeEventListener("focus",this.focusHandlers[e]);delete this.focusHandlers[e]}if(this.reconnectHandlers[e]){window.removeEventListener("online",this.reconnectHandlers[e]);delete this.reconnectHandlers[e]}if(this.gcTimeouts[e]){clearTimeout(this.gcTimeouts[e]);delete this.gcTimeouts[e]}this.queryCache.delete(s)}_fetchWithRetry(e,t,s,n){return e(...t).catch(i=>{if(s===0){throw i}const o=n(s);return new Promise(c=>setTimeout(c,o)).then(()=>_(`fetchWithRetry`,`Retrying query with key: ${queryName}`),this._fetchWithRetry(e,t,s-1,n))})}_isStale(e,t){const s=Date.now()-e.timestamp>t;_(`isStale`,`isDataStale: ${s} (Current Time: ${Date.now()}, Data Timestamp: ${e.timestamp}, Stale Time: ${t})`);return s}dispatch(e,t){this.dispatchQueue.push({action:e,payload:t});if(!this.isDispatching){this._processDispatchQueue()}}_processDispatchQueue(){while(this.dispatchQueue.length>0){const{action:e,payload:t}=this.dispatchQueue.shift();this.isDispatching=true;this._dispatch(e,t);this.isDispatching=false}}_dispatch(e,t){if(typeof e==="function"){return e(this._dispatch.bind(this),()=>this.state)}if(typeof e!=="string"){throw new Error(`[Cami.js] Action type must be a string. Got: ${typeof e}`)}const s=this.reducers[e];if(!s){console.warn(`No reducer found for action ${e}`);return}this.__applyMiddleware(e,t);const n=this.state;const i=C(this.state,o=>{s(o,t)});this.state=i;this.__observers.forEach(o=>o.next(this.state));if(this.devTools){this.devTools.send(e,this.state)}if(n!==i){if(j.events.isEnabled&&typeof window!=="undefined"){const o=new CustomEvent("cami:store:state:change",{detail:{action:e,oldValue:n,newValue:i}});window.dispatchEvent(o)}_("cami:store:state:change",e,n,i)}}};var vt=function(r,e){if(typeof r!=="object"||r===null){return e}Object.keys(e).forEach(t=>{const s=r[t];const n=e[t];if(Array.isArray(s)&&Array.isArray(n)){r[t]=[...s,...n]}else if(typeof s==="object"&&s!==null&&typeof n==="object"&&n!==null){r[t]=vt(S({},s),n)}else{r[t]=n}});Object.keys(r).forEach(t=>{if(!e.hasOwnProperty(t)){r[t]=r[t]}});return r};var nr=r=>{return(e,t)=>{const s=(t==null?void 0:t.name)||"default-store";const n=(t==null?void 0:t.load)!==false;const i=24*60*60*1e3;const o=(t==null?void 0:t.expiry)!==void 0?t.expiry:i;const c=new r(e);c.init=()=>{if(n){const a=localStorage.getItem(s);const u=localStorage.getItem(`${s}-expiry`);const f=new Date().getTime();if(a&&u){const l=f>=parseInt(u,10);if(!l){const d=JSON.parse(a);c.state=vt(e,d)}else{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`)}}}};c.init();c.reset=()=>{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`);c.state=e;c.__observers.forEach(a=>a.next(c.state))};c.subscribe(a=>{const u=new Date().getTime();const f=u+o;localStorage.setItem(s,JSON.stringify(a));localStorage.setItem(`${s}-expiry`,f.toString())});return c}};var Et=(r,e={})=>{const t={localStorage:true,name:"cami-store",expiry:864e5};const s=S(S({},t),e);if(s.localStorage){const n=nr(D)(r,s);return n}else{return new D(r)}};var v=class r extends y{static from(e){if(e instanceof y){return new r(t=>{const s=e.subscribe({next:n=>t.next(n),error:n=>t.error(n),complete:()=>t.complete()});return()=>{if(!s.closed){s.unsubscribe()}}})}else if(e[Symbol.asyncIterator]){return new r(t=>{let s=false;(()=>k(this,null,function*(){try{try{for(var n=ge(e),i,o,c;i=!(o=yield n.next()).done;i=false){const a=o.value;if(s)return;t.next(a)}}catch(o){c=[o]}finally{try{i&&(o=n.return)&&(yield o.call(n))}finally{if(c)throw c[0]}}t.complete()}catch(a){t.error(a)}}))();return()=>{s=true}})}else if(e[Symbol.iterator]){return new r(t=>{try{for(const s of e){t.next(s)}t.complete()}catch(s){t.error(s)}return()=>{if(!subscription.closed){subscription.unsubscribe()}}})}else if(e instanceof Promise){return new r(t=>{e.then(s=>{t.next(s);t.complete()},s=>t.error(s));return()=>{}})}else{throw new TypeError("[Cami.js] ObservableStream.from requires an Observable, AsyncIterable, Iterable, or Promise")}}map(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(e(n)),error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}filter(e){return new r(t=>{const s=this.subscribe({next:n=>{if(e(n)){t.next(n)}},error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}reduce(e,t){return new Promise((s,n)=>{let i=t;const o=this.subscribe({next:c=>{i=e(i,c)},error:c=>n(c),complete:()=>s(i)});return()=>o.unsubscribe()})}takeUntil(e){return new r(t=>{const s=this.subscribe({next:i=>t.next(i),error:i=>t.error(i),complete:()=>t.complete()});const n=e.subscribe({next:()=>{t.complete();s.unsubscribe();n.unsubscribe()},error:i=>t.error(i)});return()=>{s.unsubscribe();n.unsubscribe()}})}take(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{if(s++t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}drop(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{if(s++>=e){t.next(i)}},error:i=>t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}flatMap(e){return new r(t=>{const s=new Set;const n=this.subscribe({next:i=>{const o=e(i);const c=o.subscribe({next:a=>t.next(a),error:a=>t.error(a),complete:()=>{s.delete(c);if(s.size===0){t.complete()}}});s.add(c)},error:i=>t.error(i),complete:()=>{if(s.size===0){t.complete()}}});return()=>{n.unsubscribe();s.forEach(i=>i.unsubscribe())}})}switchMap(e){return new r(t=>{let s=null;const n=this.subscribe({next:i=>{if(s){s.unsubscribe()}const o=e(i);s=o.subscribe({next:c=>t.next(c),error:c=>t.error(c),complete:()=>{if(s){s.unsubscribe();s=null}}})},error:i=>t.error(i),complete:()=>{if(s){s.unsubscribe()}t.complete()}});return()=>{n.unsubscribe();if(s){s.unsubscribe()}}})}toArray(){return new Promise((e,t)=>{const s=[];this.subscribe({next:n=>s.push(n),error:n=>t(n),complete:()=>e(s)})})}forEach(e){return new Promise((t,s)=>{this.subscribe({next:n=>e(n),error:n=>s(n),complete:()=>t()})})}every(e){return new Promise((t,s)=>{let n=true;this.subscribe({next:i=>{if(!e(i)){n=false;t(false)}},error:i=>s(i),complete:()=>t(n)})})}find(e){return new Promise((t,s)=>{const n=this.subscribe({next:i=>{if(e(i)){t(i);n.unsubscribe()}},error:i=>s(i),complete:()=>t(void 0)})})}some(e){return new Promise((t,s)=>{const n=this.subscribe({next:i=>{if(e(i)){t(true);n.unsubscribe()}},error:i=>s(i),complete:()=>t(false)})})}finally(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(n),error:n=>{e();t.error(n)},complete:()=>{e();t.complete()}});return()=>{s.unsubscribe()}})}toState(e=null){const t=new w(e,null,{name:"ObservableStream"});this.subscribe({next:s=>t.update(()=>s),error:s=>t.error(s),complete:()=>t.complete()});return t}push(e){if(e instanceof y){const t=e.subscribe({next:s=>this.__observers.forEach(n=>n.next(s)),error:s=>this.__observers.forEach(n=>n.error(s)),complete:()=>this.__observers.forEach(s=>s.complete())})}else if(e[Symbol.asyncIterator]){(()=>k(this,null,function*(){try{try{for(var t=ge(e),s,n,i;s=!(n=yield t.next()).done;s=false){const o=n.value;this.__observers.forEach(c=>c.next(o))}}catch(n){i=[n]}finally{try{s&&(n=t.return)&&(yield n.call(t))}finally{if(i)throw i[0]}}this.__observers.forEach(o=>o.complete())}catch(o){this.__observers.forEach(c=>c.error(o))}}))()}else if(e[Symbol.iterator]){try{for(const t of e){this.__observers.forEach(s=>s.next(t))}this.__observers.forEach(t=>t.complete())}catch(t){this.__observers.forEach(s=>s.error(t))}}else if(e instanceof Promise){e.then(t=>{this.__observers.forEach(s=>s.next(t));this.__observers.forEach(s=>s.complete())},t=>this.__observers.forEach(s=>s.error(t)))}else{this.__observers.forEach(t=>t.next(e))}}plug(e){e.subscribe({next:t=>this.push(t),error:t=>this.__observers.forEach(s=>s.error(t)),complete:()=>this.__observers.forEach(t=>t.complete())})}end(){this.__observers.forEach(e=>{if(e&&typeof e.complete==="function"){e.complete()}})}catchError(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(n),error:n=>{const i=e(n);i.subscribe({next:o=>t.next(o),error:o=>t.error(o),complete:()=>t.complete()})},complete:()=>t.complete()});return()=>s.unsubscribe()})}debounce(e){return new r(t=>{let s=null;const n=this.subscribe({next:i=>{clearTimeout(s);s=setTimeout(()=>{t.next(i)},e)},error:i=>t.error(i),complete:()=>{clearTimeout(s);t.complete()}});return()=>{clearTimeout(s);n.unsubscribe()}})}tap(e){return new r(t=>{const s=this.subscribe({next:n=>{e(n);t.next(n)},error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}throttle(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{const o=Date.now();if(o-s>e){s=o;t.next(i)}},error:i=>t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}distinctUntilChanged(){return new r(e=>{let t;let s=true;const n=this.subscribe({next:i=>{if(s||i!==t){s=false;t=i;e.next(i)}},error:i=>e.error(i),complete:()=>e.complete()});return()=>n.unsubscribe()})}concatMap(e){return new r(t=>{let s=null;let n=false;const i=[];const o=this.subscribe({next:c=>{if(!n){n=true;const a=e(c);s=a.subscribe({next:u=>t.next(u),error:u=>t.error(u),complete:()=>{if(i.length>0){const u=i.shift();const f=e(u);s=f.subscribe({next:l=>t.next(l),error:l=>t.error(l),complete:()=>n=false})}else{n=false}}})}else{i.push(c)}},error:c=>t.error(c),complete:()=>{if(!n){t.complete()}}});return()=>{o.unsubscribe();if(s){s.unsubscribe()}}})}combineLatest(...e){return new r(t=>{const s=new Array(e.length).fill(void 0);const n=e.map((i,o)=>i.subscribe({next:c=>{s[o]=c;if(!s.includes(void 0)){t.next([...s])}},error:c=>t.error(c),complete:()=>{}}));return()=>n.forEach(i=>i.unsubscribe())})}startWith(...e){return new r(t=>{e.forEach(n=>t.next(n));const s=this.subscribe({next:n=>t.next(n),error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}};var R={current:null};var w=class extends y{constructor(e=null,t=null,{last:s=false,name:n=null}={}){super();if(s){this.__lastObserver=t}else{this.__observers.push(t)}this.__value=C(e,i=>{});this.__pendingUpdates=[];this.__updateScheduled=false;this.__name=n}get value(){if(R.current!=null){R.current.addDependency(this)}return this.__value}set value(e){this.update(()=>e)}assign(e){if(typeof this.__value!=="object"||this.__value===null){throw new Error("[Cami.js] Observable value is not an object")}this.update(t=>Object.assign(t,e))}set(e,t){if(typeof this.__value!=="object"||this.__value===null){throw new Error("[Cami.js] Observable value is not an object")}this.update(s=>{const n=e.split(".");let i=s;for(let o=0;o{const s=e.split(".");let n=t;for(let i=0;i({}))}push(...e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.push(...e)})}pop(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.pop()})}shift(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.shift()})}splice(e,t,...s){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.splice(e,t,...s)})}unshift(...e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.unshift(...e)})}reverse(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.reverse()})}sort(e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.sort(e)})}fill(e,t=0,s=this.__value.length){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.fill(e,t,s)})}copyWithin(e,t,s=this.__value.length){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.copyWithin(e,t,s)})}update(e){this.__pendingUpdates.push(e);this.__scheduleupdate()}__scheduleupdate(){if(!this.__updateScheduled){this.__updateScheduled=true;this.__applyUpdates()}}__notifyObservers(){const e=[...this.__observers,this.__lastObserver];e.forEach(t=>{if(t&&typeof t==="function"){t(this.__value)}else if(t&&t.next){t.next(this.__value)}})}__applyUpdates(){let e=this.__value;while(this.__pendingUpdates.length>0){const t=this.__pendingUpdates.shift();if(typeof this.__value==="object"&&this.__value!==null&&this.__value.constructor===Object||Array.isArray(this.__value)){this.__value=C(this.__value,t)}else{this.__value=t(this.__value)}}if(e!==this.__value){this.__notifyObservers();if(j.events.isEnabled&&typeof window!=="undefined"){const t=new CustomEvent("cami:state:change",{detail:{name:this.__name,oldValue:e,newValue:this.__value}});window.dispatchEvent(t)}_("cami:state:change",this.__name,e,this.__value)}this.__updateScheduled=false}toStream(){const e=new v;this.subscribe({next:t=>e.emit(t),error:t=>e.error(t),complete:()=>e.end()});return e}complete(){this.__observers.forEach(e=>{if(e&&typeof e.complete==="function"){e.complete()}})}};var Le=class extends w{constructor(e){super(null);this.computeFn=e;this.dependencies=new Set;this.subscriptions=new Map;this.__compute()}get value(){if(R.current){R.current.addDependency(this)}return this.__value}__compute(){const e={addDependency:s=>{if(!this.dependencies.has(s)){const n=s.onValue(()=>this.__compute());this.dependencies.add(s);this.subscriptions.set(s,n)}}};R.current=e;const t=this.computeFn();R.current=null;if(t!==this.__value){this.__value=t;this.__notifyObservers()}}dispose(){this.subscriptions.forEach(e=>{e.unsubscribe()})}};var he=function(r){return new Le(r)};var fe=function(r){let e=()=>{};let t=new Set;let s=new Map;const n={addDependency:c=>{if(!t.has(c)){const a=c.onValue(i);t.add(c);s.set(c,a)}}};const i=()=>{e();R.current=n;e=r()||(()=>{});R.current=null};if(typeof window!=="undefined"){requestAnimationFrame(i)}else{setTimeout(i,0)}const o=()=>{s.forEach(c=>{c.unsubscribe()});e()};return o};var de=class{constructor(e){if(!(e instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}return new Proxy(e,{get:(t,s)=>{if(typeof t[s]==="function"){return t[s].bind(t)}else if(s in t){return t[s]}else if(typeof t.value[s]==="function"){return(...n)=>t.value[s](...n)}else{return t.value[s]}},set:(t,s,n)=>{t[s]=n;t.update(()=>t.value);return true}})}};var O=new Map;var _e=class extends HTMLElement{constructor(){super();this.onCreate();this.__unsubscribers=new Map;this.__computed=he.bind(this);this.effect=fe.bind(this);this.__queryFunctions=new Map}observableAttributes(e){Object.entries(e).forEach(([t,s])=>{let n=this.getAttribute(t);const i=typeof s==="function"?s:c=>c;n=C(n,i);const o=this.__observable(n,t);if(this.__isObjectOrArray(o.value)){this.__createObservablePropertyForObjOrArr(this,t,o,true)}else{this.__createObservablePropertyForPrimitive(this,t,o,true)}})}__computed(e){const t=super._computed(e);console.log(t);this.__registerObservables(t);return t}effect(e){const t=super.effect(e);this.__unsubscribers.set(e,t)}connect(e,t){if(!(e instanceof D)){throw new TypeError("Expected store to be an instance of ObservableStore")}const s=this.__observable(e.state[t],t);const n=e.subscribe(i=>{s.update(()=>i[t])});this.__unsubscribers.set(t,n);if(this.__isObjectOrArray(s.value)){this.__createObservablePropertyForObjOrArr(this,t,s);return this[t]}else{this.__createObservablePropertyForPrimitive(this,t,s);return this[t]}}stream(e){return new v(e)}template(){throw new Error("[Cami.js] You have to implement the method template()!")}query({queryKey:e,queryFn:t,staleTime:s=0,refetchOnWindowFocus:n=true,refetchOnMount:i=true,refetchOnReconnect:o=true,refetchInterval:c=null,gcTime:a=1e3*60*5,retry:u=3,retryDelay:f=l=>Math.pow(2,l)*1e3}){const l=Array.isArray(e)?e.map(E=>typeof E==="object"?JSON.stringify(E):E).join(":"):e;this.__queryFunctions.set(l,t);_("query","Starting query with key:",l);const d=this.__observable({data:null,status:"pending",fetchStatus:"idle",error:null,lastUpdated:O.has(l)?O.get(l).lastUpdated:null},l);const h=this.__observableProxy(d);const m=(E=0)=>k(this,null,function*(){const We=Date.now();const be=O.get(l);if(be&&We-be.lastUpdated{T.data=be.data;T.status="success";T.fetchStatus="idle"})}else{_("fetchData (else)","Fetching data for key:",l);try{h.update(A=>{A.status="pending";A.fetchStatus="fetching"});const T=yield t();O.set(l,{data:T,lastUpdated:We});h.update(A=>{A.data=T;A.status="success";A.fetchStatus="idle"})}catch(T){_("fetchData (catch)","Fetch error for key:",l,T);if(Em(E+1),f(E))}else{h.update(A=>{A.errorDetails={message:T.message,stack:T.stack};A.status="error";A.fetchStatus="idle"})}}}});if(i){_("query","Setting up refetch on mount for key:",l);m()}if(n){_("query","Setting up refetch on window focus for key:",l);const E=()=>m();window.addEventListener("focus",E);this.__unsubscribers.set(`focus:${l}`,()=>window.removeEventListener("focus",E))}if(o){_("query","Setting up refetch on reconnect for key:",l);window.addEventListener("online",m);this.__unsubscribers.set(`online:${l}`,()=>window.removeEventListener("online",m))}if(c){_("query","Setting up refetch interval for key:",l);const E=setInterval(m,c);this.__unsubscribers.set(`interval:${l}`,()=>clearInterval(E))}const U=setTimeout(()=>{O.delete(l)},a);this.__unsubscribers.set(`gc:${l}`,()=>clearTimeout(U));return h}mutation({mutationFn:e,onMutate:t,onError:s,onSuccess:n,onSettled:i}){const o=this.__observable({data:null,status:"idle",error:null,isSettled:false},"mutation");const c=this.__observableProxy(o);const a=u=>k(this,null,function*(){_("mutation","Starting mutation for variables:",u);let f;const l=c.value;if(t){_("mutation","Performing optimistic update for variables:",u);f=t(u,l);c.update(d=>{d.data=f.optimisticData;d.status="pending";d.errorDetails=null})}else{_("mutation","Performing mutation without optimistic update for variables:",u);c.update(d=>{d.status="pending";d.errorDetails=null})}try{const d=yield e(u);c.update(h=>{h.data=d;h.status="success"});if(n){n(d,u,f)}_("mutation","Mutation successful for variables:",u,d)}catch(d){_("mutation","Mutation error for variables:",u,d);c.update(h=>{h.errorDetails={message:d.message};h.status="error";if(!s&&f&&f.rollback){_("mutation","Rolling back mutation for variables:",u);f.rollback()}});if(s){s(d,u,f)}}finally{if(!c.value.isSettled){c.update(d=>{d.isSettled=true});if(i){_("mutation","Calling onSettled for variables:",u);i(c.value.data,c.value.error,u,f)}}}});c.mutate=a;c.reset=()=>{c.update(u=>{u.data=null;u.status="idle";u.errorDetails=null;u.isSettled=false})};return c}invalidateQueries(e){const t=Array.isArray(e)?e.join(":"):e;_("invalidateQueries","Invalidating query with key:",t);O.delete(t);this.__updateCache(t)}onCreate(){}connectedCallback(){this.__setup({infer:true});this.effect(()=>this.render());this.render();this.onConnect()}onConnect(){}disconnectedCallback(){this.onDisconnect();this.__unsubscribers.forEach(e=>e())}onDisconnect(){}attributeChangedCallback(e,t,s){this.onAttributeChange(e,t,s)}onAttributeChange(e,t,s){}adoptedCallback(){this.onAdopt()}onAdopt(){}__isObjectOrArray(e){return e!==null&&(typeof e==="object"||Array.isArray(e))}__createObservablePropertyForObjOrArr(e,t,s,n=false){if(!(s instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}const i=this.__observableProxy(s);Object.defineProperty(e,t,{get:()=>i,set:o=>{s.update(()=>o);if(n){this.setAttribute(t,o)}}})}__createObservablePropertyForPrimitive(e,t,s,n=false){if(!(s instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}Object.defineProperty(e,t,{get:()=>s.value,set:i=>{s.update(()=>i);if(n){this.setAttribute(t,i)}}})}__observableProxy(e){return new de(e)}__setup(e){if(e.infer===true){Object.keys(this).forEach(t=>{if(typeof this[t]!=="function"&&!t.startsWith("__")){if(this[t]instanceof y){return}else{const s=this.__observable(this[t],t);if(this.__isObjectOrArray(s.value)){this.__createObservablePropertyForObjOrArr(this,t,s)}else{this.__createObservablePropertyForPrimitive(this,t,s)}}}})}}__observable(e,t){if(!this.__isAllowedType(e)){const n=Object.prototype.toString.call(e);throw new Error(`[Cami.js] The value of type ${n} is not allowed in observables. Only primitive values, arrays, and plain objects are allowed.`)}const s=new w(e,null,{name:t});this.__registerObservables(s);return s}__updateCache(e){_("__updateCache","Invalidating cache with key:",e);const t=this.__queryFunctions.get(e);if(t){_("__updateCache","Found query function for key:",e);const s=O.get(e)||{data:void 0,status:"idle",error:null};O.set(e,we(S({},s),{status:"pending",error:null}));t().then(n=>{O.set(e,{data:n,status:"success",error:null,lastUpdated:Date.now()});_("__updateCache","Refetch successful for key:",e,n)}).catch(n=>{if(s.data!==void 0){_("__updateCache","Rolling back refetch for key:",e);O.set(e,s)}O.set(e,we(S({},s),{status:"error",error:n}))})}}__isAllowedType(e){const t=["number","string","boolean","object","undefined"];const s=typeof e;if(s==="object"){return e===null||Array.isArray(e)||this.__isPlainObject(e)}return t.includes(s)}__isPlainObject(e){if(Object.prototype.toString.call(e)!=="[object Object]"){return false}const t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}__registerObservables(e){if(!(e instanceof w)){throw new TypeError("Expected observableState to be an instance of ObservableState")}this.__unsubscribers.set(e,()=>{if(typeof e.dispose==="function"){e.dispose()}})}render(){const e=this.template();je(e,this)}};var pe=class extends v{constructor(e){super();if(typeof e==="string"){this.element=document.querySelector(e);if(!this.element){throw new Error(`[Cami.js] Element not found for selector: ${e}`)}}else if(e instanceof Element||e instanceof Document){this.element=e}else{throw new Error(`[Cami.js] Invalid argument: ${e}`)}}on(e,t={}){return new v(s=>{const n=i=>{s.next(i)};this.element.addEventListener(e,n,t);return()=>{this.element.removeEventListener(e,n,t)}})}};var me=class extends v{constructor(){super(...arguments);Ge(this,"__handlers",{})}toJson(){return new Promise((t,s)=>{this.subscribe({next:n=>{try{if(typeof n==="object"){t(n)}else{t(JSON.parse(n))}}catch(i){s(i)}},error:n=>s(n)})})}on(t,s){if(!this.__handlers[t]){this.__handlers[t]=[]}this.__handlers[t].push(s);return this}};var g=r=>{if(typeof r==="string"){return g.get(r)}return new me(e=>{const t=new XMLHttpRequest;t.open(r.method||"GET",r.url);if(r.headers){Object.keys(r.headers).forEach(s=>{t.setRequestHeader(s,r.headers[s])})}t.onload=()=>{let s=t.responseText;const n=r.transformResponse||(i=>{try{return JSON.parse(i)}catch(o){return i}});s=n(s);e.next(s);e.complete()};t.onerror=()=>e.error(t.statusText);t.send(r.data?JSON.stringify(r.data):null);return()=>{t.abort()}})};g.get=(r,e={})=>{e.url=r;e.method="GET";return g(e)};g.post=(r,e={},t={})=>{t.url=r;t.data=e;t.method="POST";return g(t)};g.put=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PUT";return g(t)};g.patch=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PATCH";return g(t)};g.delete=(r,e={})=>{e.url=r;e.method="DELETE";return g(e)};g.sse=(r,e={})=>{const t=new me(s=>{const n=new EventSource(r,e);n.onmessage=i=>{if(t.__handlers[i.type]){t.__handlers[i.type].forEach(o=>o(i))}s.next(i)};n.onerror=i=>s.error(i);return()=>{n.close()}});return t};var{debug:ir,events:or}=j;return jt(cr);})(); +var cami=(()=>{var Z=Object.defineProperty;var Ot=Object.defineProperties;var At=Object.getOwnPropertyDescriptor;var Tt=Object.getOwnPropertyDescriptors;var St=Object.getOwnPropertyNames;var Qe=Object.getOwnPropertySymbols;var Be=Object.prototype.hasOwnProperty;var Ct=Object.prototype.propertyIsEnumerable;var qe=(r,e)=>{return(e=Symbol[r])?e:Symbol.for("Symbol."+r)};var ye=(r,e,t)=>e in r?Z(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var S=(r,e)=>{for(var t in e||(e={}))if(Be.call(e,t))ye(r,t,e[t]);if(Qe)for(var t of Qe(e)){if(Ct.call(e,t))ye(r,t,e[t])}return r};var we=(r,e)=>Ot(r,Tt(e));var Pt=(r,e)=>{for(var t in e)Z(r,t,{get:e[t],enumerable:true})};var jt=(r,e,t,s)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let n of St(e))if(!Be.call(r,n)&&n!==t)Z(r,n,{get:()=>e[n],enumerable:!(s=At(e,n))||s.enumerable})}return r};var Dt=r=>jt(Z({},"__esModule",{value:true}),r);var Ge=(r,e,t)=>{ye(r,typeof e!=="symbol"?e+"":e,t);return t};var k=(r,e,t)=>{return new Promise((s,n)=>{var i=a=>{try{c(t.next(a))}catch(u){n(u)}};var o=a=>{try{c(t.throw(a))}catch(u){n(u)}};var c=a=>a.done?s(a.value):Promise.resolve(a.value).then(i,o);c((t=t.apply(r,e)).next())})};var ge=(r,e,t)=>(e=r[qe("asyncIterator")])?e.call(r):(r=r[qe("iterator")](),e={},t=(s,n)=>(n=r[s])&&(e[s]=i=>new Promise((o,c,a)=>(i=n.call(r,i),a=i.done,Promise.resolve(i.value).then(u=>o({value:u,done:a}),c)))),t("next"),t("return"),e);var ar={};Pt(ar,{Observable:()=>y,ObservableElement:()=>pe,ObservableState:()=>w,ObservableStore:()=>D,ObservableStream:()=>v,ReactiveElement:()=>_e,computed:()=>he,debug:()=>or,effect:()=>fe,events:()=>cr,html:()=>Pe,http:()=>g,slice:()=>vt,store:()=>$t,svg:()=>ut});var Rt=globalThis;var $=r=>r;var ee=Rt.trustedTypes;var Je=ee?ee.createPolicy("cami-html",{createHTML:r=>r}):void 0;var nt="$cami$";var P=`cami$${String(Math.random()).slice(9)}$`;var it="?"+P;var Vt=`<${it}>`;var I=document;var B=()=>I.createComment("");var G=r=>r===null||typeof r!="object"&&typeof r!="function";var ot=Array.isArray;var Mt=r=>ot(r)||typeof(r==null?void 0:r[Symbol.iterator])==="function";var xe=`[ +\f\r]`;var It=`[^ +\f\r"'\`<>=]`;var Nt=`[^\\s"'>=/]`;var q=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g;var Xe=1;var ve=2;var Ft=3;var Ke=/-->/g;var Ye=/>/g;var V=new RegExp(`>|${xe}(?:(${Nt}+)(${xe}*=${xe}*(?:${It}|("|')|))|$)`,"g");var zt=0;var Ze=1;var Ut=2;var et=3;var tt=/'/g;var rt=/"/g;var ct=/^(?:script|style|textarea|title)$/i;var kt=1;var te=2;var Se=1;var re=2;var Ht=3;var Lt=4;var Wt=5;var Ce=6;var Qt=7;var at=r=>(e,...t)=>{return{["_$camiType$"]:r,strings:e,values:t}};var Pe=at(kt);var ut=at(te);var J=Symbol.for("cami-noChange");var p=Symbol.for("cami-nothing");var st=new WeakMap;var M=I.createTreeWalker(I,129);function lt(r,e){if(!Array.isArray(r)||!r.hasOwnProperty("raw")){let t="invalid template strings array";throw new Error(t)}return Je!==void 0?Je.createHTML(e):e}var qt=(r,e)=>{const t=r.length-1;const s=[];let n=e===te?"":"";let i;let o=q;for(let a=0;a"){o=i!=null?i:q;f=-1}else if(h[Ze]===void 0){f=-2}else{f=o.lastIndex-h[Ut].length;l=h[Ze];o=h[et]===void 0?V:h[et]==='"'?rt:tt}}else if(o===rt||o===tt){o=V}else if(o===Ke||o===Ye){o=q}else{o=V;i=void 0}}const m=o===V&&r[a+1].startsWith("/>")?" ":"";n+=o===q?u+Vt:f>=0?(s.push(l),u.slice(0,f)+nt+u.slice(f))+P+m:u+P+(f===-2?a:m)}const c=n+(r[t]||"")+(e===te?"":"");return[lt(r,c),s]};var se=class r{constructor({strings:e,["_$camiType$"]:t},s){this.parts=[];let n;let i=0;let o=0;const c=e.length-1;const a=this.parts;const[u,f]=qt(e,t);this.el=r.createElement(u,s);M.currentNode=this.el.content;if(t===te){const l=this.el.content.firstChild;l.replaceWith(...l.childNodes)}while((n=M.nextNode())!==null&&a.length0){n.textContent=ee?ee.emptyScript:"";for(let h=0;h2||s[0]!==""||s[1]!==""){this._$committedValue=new Array(s.length-1).fill(new String);this.strings=s}else{this._$committedValue=p}}_$setValue(e,t=this,s,n){const i=this.strings;let o=false;if(i===void 0){e=H(this,e,t,0);o=!G(e)||e!==this._$committedValue&&e!==J;if(o){this._$committedValue=e}}else{const c=e;e=i[0];let a,u;for(a=0;a{var i,o;const s=(i=t==null?void 0:t.renderBefore)!=null?i:e;let n=s["_$camiPart$"];if(n===void 0){const c=(o=t==null?void 0:t.renderBefore)!=null?o:null;s["_$camiPart$"]=n=new ne(e.insertBefore(B(),c),c,void 0,t!=null?t:{})}n._$setValue(r);return n};var mt=Symbol.for("immer-nothing");var ht=Symbol.for("immer-draftable");var x=Symbol.for("immer-state");var Bt=true?[function(r){return`The plugin for '${r}' has not been loaded into Immer. To enable the plugin, import and call \`enable${r}()\` when initializing your application.`},function(r){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${r}'`},"This object has been frozen and should not be mutated",function(r){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+r},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Cami Observables forbid circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(r){return`'current' expects a draft, got: ${r}`},"Object.defineProperty() cannot be used on a Cami Observable draft","Object.setPrototypeOf() cannot be used on a Cami Observable draft","Cami Observables only support deleting array indices","Cami Observables only support setting array indices and the 'length' property",function(r){return`'original' expects a draft, got: ${r}`}]:[];function b(r,...e){if(true){const t=Bt[r];const s=typeof t==="function"?t.apply(null,e):t;throw new Error(`[Cami.js] ${s}`)}throw new Error(`[Cami.js] minified error nr: ${r}.`)}var W=Object.getPrototypeOf;function Q(r){return!!r&&!!r[x]}function F(r){var e;if(!r)return false;return bt(r)||Array.isArray(r)||!!r[ht]||!!((e=r.constructor)==null?void 0:e[ht])||ae(r)||ue(r)}var Gt=Object.prototype.constructor.toString();function bt(r){if(!r||typeof r!=="object")return false;const e=W(r);if(e===null){return true}const t=Object.hasOwnProperty.call(e,"constructor")&&e.constructor;if(t===Object)return true;return typeof t=="function"&&Function.toString.call(t)===Gt}function X(r,e){if(ce(r)===0){Object.entries(r).forEach(([t,s])=>{e(t,s,r)})}else{r.forEach((t,s)=>e(s,t,r))}}function ce(r){const e=r[x];return e?e.type_:Array.isArray(r)?1:ae(r)?2:ue(r)?3:0}function Ve(r,e){return ce(r)===2?r.has(e):Object.prototype.hasOwnProperty.call(r,e)}function yt(r,e,t){const s=ce(r);if(s===2)r.set(e,t);else if(s===3){r.add(t)}else r[e]=t}function Jt(r,e){if(r===e){return r!==0||1/r===1/e}else{return r!==r&&e!==e}}function ae(r){return r instanceof Map}function ue(r){return r instanceof Set}function N(r){return r.copy_||r.base_}function Me(r,e){if(ae(r)){return new Map(r)}if(ue(r)){return new Set(r)}if(Array.isArray(r))return Array.prototype.slice.call(r);if(!e&&bt(r)){if(!W(r)){const n=Object.create(null);return Object.assign(n,r)}return S({},r)}const t=Object.getOwnPropertyDescriptors(r);delete t[x];let s=Reflect.ownKeys(t);for(let n=0;n1){r.set=r.add=r.clear=r.delete=Xt}Object.freeze(r);if(e)X(r,(t,s)=>Ue(s,true),true);return r}function Xt(){b(2)}function le(r){return Object.isFrozen(r)}var Kt={};function z(r){const e=Kt[r];if(!e){b(0,r)}return e}var K;function wt(){return K}function Yt(r,e){return{drafts_:[],parent_:r,immer_:e,canAutoFreeze_:true,unfinalizedDrafts_:0}}function ft(r,e){if(e){z("Patches");r.patches_=[];r.inversePatches_=[];r.patchListener_=e}}function Ie(r){Ne(r);r.drafts_.forEach(Zt);r.drafts_=null}function Ne(r){if(r===K){K=r.parent_}}function dt(r){return K=Yt(K,r)}function Zt(r){const e=r[x];if(e.type_===0||e.type_===1)e.revoke_();else e.revoked_=true}function _t(r,e){e.unfinalizedDrafts_=e.drafts_.length;const t=e.drafts_[0];const s=r!==void 0&&r!==t;if(s){if(t[x].modified_){Ie(e);b(4)}if(F(r)){r=ie(e,r);if(!e.parent_)oe(e,r)}if(e.patches_){z("Patches").generateReplacementPatches_(t[x].base_,r,e.patches_,e.inversePatches_)}}else{r=ie(e,t,[])}Ie(e);if(e.patches_){e.patchListener_(e.patches_,e.inversePatches_)}return r!==mt?r:void 0}function ie(r,e,t){if(le(e))return e;const s=e[x];if(!s){X(e,(n,i)=>pt(r,s,e,n,i,t),true);return e}if(s.scope_!==r)return e;if(!s.modified_){oe(r,s.base_,true);return s.base_}if(!s.finalized_){s.finalized_=true;s.scope_.unfinalizedDrafts_--;const n=s.copy_;let i=n;let o=false;if(s.type_===3){i=new Set(n);n.clear();o=true}X(i,(c,a)=>pt(r,s,n,c,a,t,o));oe(r,n,false);if(t&&r.patches_){z("Patches").generatePatches_(s,t,r.patches_,r.inversePatches_)}}return s.copy_}function pt(r,e,t,s,n,i,o){if(n===t)b(5);if(Q(n)){const c=i&&e&&e.type_!==3&&!Ve(e.assigned_,s)?i.concat(s):void 0;const a=ie(r,n,c);yt(t,s,a);if(Q(a)){r.canAutoFreeze_=false}else return}else if(o){t.add(n)}if(F(n)&&!le(n)){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1){return}ie(r,n);if(!e||!e.scope_.parent_)oe(r,n)}}function oe(r,e,t=false){if(!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_){Ue(e,t)}}function er(r,e){const t=Array.isArray(r);const s={type_:t?1:0,scope_:e?e.scope_:wt(),modified_:false,finalized_:false,assigned_:{},parent_:e,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:false};let n=s;let i=ke;if(t){n=[s];i=Y}const{revoke:o,proxy:c}=Proxy.revocable(n,i);s.draft_=c;s.revoke_=o;return c}var ke={get(r,e){if(e===x)return r;const t=N(r);if(!Ve(t,e)){return tr(r,t,e)}const s=t[e];if(r.finalized_||!F(s)){return s}if(s===De(r.base_,e)){Re(r);return r.copy_[e]=ze(s,r)}return s},has(r,e){return e in N(r)},ownKeys(r){return Reflect.ownKeys(N(r))},set(r,e,t){const s=gt(N(r),e);if(s==null?void 0:s.set){s.set.call(r.draft_,t);return true}if(!r.modified_){const n=De(N(r),e);const i=n==null?void 0:n[x];if(i&&i.base_===t){r.copy_[e]=t;r.assigned_[e]=false;return true}if(Jt(t,n)&&(t!==void 0||Ve(r.base_,e)))return true;Re(r);Fe(r)}if(r.copy_[e]===t&&(t!==void 0||e in r.copy_)||Number.isNaN(t)&&Number.isNaN(r.copy_[e]))return true;r.copy_[e]=t;r.assigned_[e]=true;return true},deleteProperty(r,e){if(De(r.base_,e)!==void 0||e in r.base_){r.assigned_[e]=false;Re(r);Fe(r)}else{delete r.assigned_[e]}if(r.copy_){delete r.copy_[e]}return true},getOwnPropertyDescriptor(r,e){const t=N(r);const s=Reflect.getOwnPropertyDescriptor(t,e);if(!s)return s;return{writable:true,configurable:r.type_!==1||e!=="length",enumerable:s.enumerable,value:t[e]}},defineProperty(){b(11)},getPrototypeOf(r){return W(r.base_)},setPrototypeOf(){b(12)}};var Y={};X(ke,(r,e)=>{Y[r]=function(){arguments[0]=arguments[0][0];return e.apply(this,arguments)}});Y.deleteProperty=function(r,e){if(isNaN(parseInt(e)))b(13);return Y.set.call(this,r,e,void 0)};Y.set=function(r,e,t){if(e!=="length"&&isNaN(parseInt(e)))b(14);return ke.set.call(this,r[0],e,t,r[0])};function De(r,e){const t=r[x];const s=t?N(t):r;return s[e]}function tr(r,e,t){var n;const s=gt(e,t);return s?`value`in s?s.value:(n=s.get)==null?void 0:n.call(r.draft_):void 0}function gt(r,e){if(!(e in r))return void 0;let t=W(r);while(t){const s=Object.getOwnPropertyDescriptor(t,e);if(s)return s;t=W(t)}return void 0}function Fe(r){if(!r.modified_){r.modified_=true;if(r.parent_){Fe(r.parent_)}}}function Re(r){if(!r.copy_){r.copy_=Me(r.base_,r.scope_.immer_.useStrictShallowCopy_)}}var rr=class{constructor(r){this.autoFreeze_=true;this.useStrictShallowCopy_=false;this.produce=(e,t,s)=>{if(typeof e==="function"&&typeof t!=="function"){const i=t;t=e;const o=this;return function c(a=i,...u){return o.produce(a,f=>t.call(this,f,...u))}}if(typeof t!=="function")b(6);if(s!==void 0&&typeof s!=="function")b(7);let n;if(F(e)){const i=dt(this);const o=ze(e,void 0);let c=true;try{n=t(o);c=false}finally{if(c)Ie(i);else Ne(i)}ft(i,s);return _t(n,i)}else if(!e||typeof e!=="object"){n=t(e);if(n===void 0)n=e;if(n===mt)n=void 0;if(this.autoFreeze_)Ue(n,true);if(s){const i=[];const o=[];z("Patches").generateReplacementPatches_(e,n,i,o);s(i,o)}return n}else b(1,e)};this.produceWithPatches=(e,t)=>{if(typeof e==="function"){return(o,...c)=>this.produceWithPatches(o,a=>e(a,...c))}let s,n;const i=this.produce(e,t,(o,c)=>{s=o;n=c});return[i,s,n]};if(typeof(r==null?void 0:r.autoFreeze)==="boolean")this.setAutoFreeze(r.autoFreeze);if(typeof(r==null?void 0:r.useStrictShallowCopy)==="boolean")this.setUseStrictShallowCopy(r.useStrictShallowCopy)}createDraft(r){if(!F(r))b(8);if(Q(r))r=sr(r);const e=dt(this);const t=ze(r,void 0);t[x].isManual_=true;Ne(e);return t}finishDraft(r,e){const t=r&&r[x];if(!t||!t.isManual_)b(9);const{scope_:s}=t;ft(s,e);return _t(void 0,s)}setAutoFreeze(r){this.autoFreeze_=r}setUseStrictShallowCopy(r){this.useStrictShallowCopy_=r}applyPatches(r,e){let t;for(t=e.length-1;t>=0;t--){const n=e[t];if(n.path.length===0&&n.op==="replace"){r=n.value;break}}if(t>-1){e=e.slice(t+1)}const s=z("Patches").applyPatches_;if(Q(r)){return s(r,e)}return this.produce(r,n=>s(n,e))}};function ze(r,e){const t=ae(r)?z("MapSet").proxyMap_(r,e):ue(r)?z("MapSet").proxySet_(r,e):er(r,e);const s=e?e.scope_:wt();s.drafts_.push(t);return t}function sr(r){if(!Q(r))b(10,r);return xt(r)}function xt(r){if(!F(r)||le(r))return r;const e=r[x];let t;if(e){if(!e.modified_)return e.base_;e.finalized_=true;t=Me(r,e.scope_.immer_.useStrictShallowCopy_)}else{t=Me(r,true)}X(t,(s,n)=>{yt(t,s,xt(n))});if(e){e.finalized_=false}return t}var nr=new rr;var C=nr.produce;var He=class{constructor(e){if(typeof e==="function"){this.observer={next:e}}else{this.observer=e}this.teardowns=[];if(typeof AbortController!=="undefined"){this.controller=new AbortController;this.signal=this.controller.signal}this.isUnsubscribed=false}next(e){if(!this.isUnsubscribed&&this.observer.next){this.observer.next(e)}}complete(){if(!this.isUnsubscribed){if(this.observer.complete){this.observer.complete()}this.unsubscribe()}}error(e){if(!this.isUnsubscribed){if(this.observer.error){this.observer.error(e)}this.unsubscribe()}}addTeardown(e){this.teardowns.push(e)}unsubscribe(){if(!this.isUnsubscribed){this.isUnsubscribed=true;if(this.controller){this.controller.abort()}this.teardowns.forEach(e=>{if(typeof e!=="function"){throw new Error("[Cami.js] Teardown must be a function. Please implement a teardown function in your subscriber.")}e()})}}};var y=class{constructor(e=()=>()=>{}){this.__observers=[];this.subscribeCallback=e}subscribe(e=()=>{},t=()=>{},s=()=>{}){let n;if(typeof e==="function"){n={next:e,error:t,complete:s}}else if(typeof e==="object"){n=e}else{throw new Error("[Cami.js] First argument to subscribe must be a next callback or an observer object")}const i=new He(n);let o=()=>{};try{o=this.subscribeCallback(i)}catch(c){if(i.error){i.error(c)}else{console.error("[Cami.js] Error in Subscriber:",c)}return}i.addTeardown(o);this.__observers.push(i);return{unsubscribe:()=>i.unsubscribe(),complete:()=>i.complete(),error:c=>i.error(c)}}next(e){this.__observers.forEach(t=>{t.next(e)})}error(e){this.__observers.forEach(t=>{t.error(e)})}complete(){this.__observers.forEach(e=>{e.complete()})}onValue(e){return this.subscribe({next:e})}onError(e){return this.subscribe({error:e})}onEnd(e){return this.subscribe({complete:e})}[Symbol.asyncIterator](){let e;let t;let s=new Promise(n=>t=n);e={next:n=>{t({value:n,done:false});s=new Promise(i=>t=i)},complete:()=>{t({done:true})},error:n=>{throw n}};this.subscribe(e);return{next:()=>s}}};var j={events:{__state:true,get isEnabled(){return this.__state},enable:function(){this.__state=true},disable:function(){this.__state=false}},debug:{__state:false,get isEnabled(){return this.__state},enable:function(){console.log("Cami.js debug mode enabled");this.__state=true},disable:function(){this.__state=false}}};function _(r,...e){if(j.debug.isEnabled){if(r==="cami:state:change"){console.groupCollapsed(`%c[${r}]`,"color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;",`${e[0]} changed`);console.log(`oldValue:`,e[1]);console.log(`newValue:`,e[2])}else{console.groupCollapsed(`%c[${r}]`,"color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;",...e)}console.trace();console.groupEnd()}}var D=class extends y{constructor(e){if(typeof e!=="object"||e===null){throw new TypeError("[Cami.js] initialState must be an object")}super(t=>{this.__subscriber=t;return()=>{this.__subscriber=null}});this.state=new Proxy(e,{get:(t,s)=>{return t[s]},set:(t,s,n)=>{t[s]=n;this.__observers.forEach(i=>i.next(this.state));if(this.devTools){this.devTools.send(s,this.state)}return true}});this.reducers={};this.middlewares=[];this.devTools=this.__connectToDevTools();this.dispatchQueue=[];this.isDispatching=false;this.queryCache=new Map;this.queryFunctions=new Map;this.queries={};this.intervals=new Map;this.focusHandlers=new Map;this.reconnectHandlers=new Map;this.gcTimeouts=new Map;Object.keys(e).forEach(t=>{if(typeof e[t]==="function"){this.register(t,e[t])}else{this.state[t]=e[t]}})}__applyMiddleware(e,...t){const s={state:this.state,action:e,payload:t};for(const n of this.middlewares){n(s)}}__connectToDevTools(){if(typeof window!=="undefined"&&window["__REDUX_DEVTOOLS_EXTENSION__"]){const e=window["__REDUX_DEVTOOLS_EXTENSION__"].connect();e.init(this.state);return e}return null}use(e){this.middlewares.push(e)}getState(){return this.state}register(e,t){if(this.reducers[e]){throw new Error(`[Cami.js] Action type ${e} is already registered.`)}this.reducers[e]=t;this[e]=(...s)=>{this.dispatch(e,...s)}}query(e,t){const{queryKey:s,queryFn:n,staleTime:i=0,refetchOnWindowFocus:o=true,refetchInterval:c=null,refetchOnReconnect:a=true,gcTime:u=1e3*60*5,retry:f=3,retryDelay:l=h=>Math.pow(2,h)*1e3}=t;this.queries[e]={queryKey:s,queryFn:n,staleTime:i,refetchOnWindowFocus:o,refetchInterval:c,refetchOnReconnect:a,gcTime:u,retry:f,retryDelay:l};this.queryFunctions.set(s,n);_(`query`,`Starting query with key: ${e}`);if(c!==null){const h=setInterval(()=>{_(`query`,`Interval expired, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e}:`,m))},c);this.intervals[e]=h}if(o){const h=()=>{_(`query`,`Window focus detected, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e} on window focus:`,m))};window.addEventListener("focus",h);this.focusHandlers[e]=h}if(a){const h=()=>{_(`query`,`Reconnect detected, refetching query: ${e}`);this.fetch(e).catch(m=>console.error(`Error refetching query ${e} on reconnect:`,m))};window.addEventListener("online",h);this.reconnectHandlers[e]=h}const d=setTimeout(()=>{_(`query`,`Garbage collection timeout expired, refetching query: ${e}`);this.fetch(e).catch(h=>console.error(`Error refetching query ${e} on gc timeout:`,h))},u);this.gcTimeouts[e]=d;this[e]=(...h)=>{return this.fetch(e,...h)}}fetch(e,...t){const s=this.queries[e];if(!s){throw new Error(`[Cami.js] No query found for name: ${e}`)}const{queryKey:n,queryFn:i,staleTime:o,retry:c,retryDelay:a}=s;const u=Array.isArray(n)?n.join(":"):n;const f=this.queryCache.get(u);if(f&&!this._isStale(f,o)){_(`fetch`,`Returning cached data for: ${e} with cacheKey: ${u}`);return Promise.resolve(f.data)}_(`fetch`,`Data is stale or not cached, fetching new data for: ${e}`);this.dispatch(`${e}/pending`);return this._fetchWithRetry(i,t,c,a).then(l=>{this.queryCache.set(u,{data:l,timestamp:Date.now()});this.dispatch(`${e}/success`,l);return l}).catch(l=>{this.dispatch(`${e}/error`,l);throw l})}invalidateQueries(e){const t=this.queries[e];if(!t)return;const s=Array.isArray(t.queryKey)?t.queryKey.join(":"):t.queryKey;_(`invalidateQueries`,`Invalidating query with key: ${e}`);if(this.intervals[e]){clearInterval(this.intervals[e]);delete this.intervals[e]}if(this.focusHandlers[e]){window.removeEventListener("focus",this.focusHandlers[e]);delete this.focusHandlers[e]}if(this.reconnectHandlers[e]){window.removeEventListener("online",this.reconnectHandlers[e]);delete this.reconnectHandlers[e]}if(this.gcTimeouts[e]){clearTimeout(this.gcTimeouts[e]);delete this.gcTimeouts[e]}this.queryCache.delete(s)}_fetchWithRetry(e,t,s,n){return e(...t).catch(i=>{if(s===0){throw i}const o=n(s);return new Promise(c=>setTimeout(c,o)).then(()=>_(`fetchWithRetry`,`Retrying query with key: ${queryName}`),this._fetchWithRetry(e,t,s-1,n))})}_isStale(e,t){const s=Date.now()-e.timestamp>t;_(`isStale`,`isDataStale: ${s} (Current Time: ${Date.now()}, Data Timestamp: ${e.timestamp}, Stale Time: ${t})`);return s}dispatch(e,t){this.dispatchQueue.push({action:e,payload:t});if(!this.isDispatching){this._processDispatchQueue()}}_processDispatchQueue(){while(this.dispatchQueue.length>0){const{action:e,payload:t}=this.dispatchQueue.shift();this.isDispatching=true;this._dispatch(e,t);this.isDispatching=false}}_dispatch(e,t){if(typeof e==="function"){return e(this._dispatch.bind(this),()=>this.state)}if(typeof e!=="string"){throw new Error(`[Cami.js] Action type must be a string. Got: ${typeof e}`)}const s=this.reducers[e];if(!s){console.warn(`No reducer found for action ${e}`);return}this.__applyMiddleware(e,t);const n=this.state;const i=C(this.state,o=>{s(o,t)});this.state=i;this.__observers.forEach(o=>o.next(this.state));if(this.devTools){this.devTools.send(e,this.state)}if(n!==i){if(j.events.isEnabled&&typeof window!=="undefined"){const o=new CustomEvent("cami:store:state:change",{detail:{action:e,oldValue:n,newValue:i}});window.dispatchEvent(o)}_("cami:store:state:change",e,n,i)}}};var vt=(r,{name:e,state:t,actions:s})=>{if(r.slices&&r.slices[e]){throw new Error(`[Cami.js] Slice name ${e} is already in use.`)}if(!r.slices){r.slices={}}r.slices[e]=true;r.state[e]=t;const n={};Object.keys(s).forEach(i=>{const o=`${e}/${i}`;r.register(o,(c,a)=>{s[i](c[e],a)});n[i]=(...c)=>{r.dispatch(o,...c)}});return n};var Et=function(r,e){if(typeof r!=="object"||r===null){return e}Object.keys(e).forEach(t=>{const s=r[t];const n=e[t];if(Array.isArray(s)&&Array.isArray(n)){r[t]=[...s,...n]}else if(typeof s==="object"&&s!==null&&typeof n==="object"&&n!==null){r[t]=Et(S({},s),n)}else{r[t]=n}});Object.keys(r).forEach(t=>{if(!e.hasOwnProperty(t)){r[t]=r[t]}});return r};var ir=r=>{return(e,t)=>{const s=(t==null?void 0:t.name)||"default-store";const n=(t==null?void 0:t.load)!==false;const i=24*60*60*1e3;const o=(t==null?void 0:t.expiry)!==void 0?t.expiry:i;const c=new r(e);c.init=()=>{if(n){const a=localStorage.getItem(s);const u=localStorage.getItem(`${s}-expiry`);const f=new Date().getTime();if(a&&u){const l=f>=parseInt(u,10);if(!l){const d=JSON.parse(a);c.state=Et(e,d)}else{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`)}}}};c.init();c.reset=()=>{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`);c.state=e;c.__observers.forEach(a=>a.next(c.state))};c.subscribe(a=>{const u=new Date().getTime();const f=u+o;localStorage.setItem(s,JSON.stringify(a));localStorage.setItem(`${s}-expiry`,f.toString())});return c}};var $t=(r,e={})=>{const t={localStorage:true,name:"cami-store",expiry:864e5};const s=S(S({},t),e);if(s.localStorage){const n=ir(D)(r,s);return n}else{return new D(r)}};var v=class r extends y{static from(e){if(e instanceof y){return new r(t=>{const s=e.subscribe({next:n=>t.next(n),error:n=>t.error(n),complete:()=>t.complete()});return()=>{if(!s.closed){s.unsubscribe()}}})}else if(e[Symbol.asyncIterator]){return new r(t=>{let s=false;(()=>k(this,null,function*(){try{try{for(var n=ge(e),i,o,c;i=!(o=yield n.next()).done;i=false){const a=o.value;if(s)return;t.next(a)}}catch(o){c=[o]}finally{try{i&&(o=n.return)&&(yield o.call(n))}finally{if(c)throw c[0]}}t.complete()}catch(a){t.error(a)}}))();return()=>{s=true}})}else if(e[Symbol.iterator]){return new r(t=>{try{for(const s of e){t.next(s)}t.complete()}catch(s){t.error(s)}return()=>{if(!subscription.closed){subscription.unsubscribe()}}})}else if(e instanceof Promise){return new r(t=>{e.then(s=>{t.next(s);t.complete()},s=>t.error(s));return()=>{}})}else{throw new TypeError("[Cami.js] ObservableStream.from requires an Observable, AsyncIterable, Iterable, or Promise")}}map(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(e(n)),error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}filter(e){return new r(t=>{const s=this.subscribe({next:n=>{if(e(n)){t.next(n)}},error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}reduce(e,t){return new Promise((s,n)=>{let i=t;const o=this.subscribe({next:c=>{i=e(i,c)},error:c=>n(c),complete:()=>s(i)});return()=>o.unsubscribe()})}takeUntil(e){return new r(t=>{const s=this.subscribe({next:i=>t.next(i),error:i=>t.error(i),complete:()=>t.complete()});const n=e.subscribe({next:()=>{t.complete();s.unsubscribe();n.unsubscribe()},error:i=>t.error(i)});return()=>{s.unsubscribe();n.unsubscribe()}})}take(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{if(s++t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}drop(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{if(s++>=e){t.next(i)}},error:i=>t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}flatMap(e){return new r(t=>{const s=new Set;const n=this.subscribe({next:i=>{const o=e(i);const c=o.subscribe({next:a=>t.next(a),error:a=>t.error(a),complete:()=>{s.delete(c);if(s.size===0){t.complete()}}});s.add(c)},error:i=>t.error(i),complete:()=>{if(s.size===0){t.complete()}}});return()=>{n.unsubscribe();s.forEach(i=>i.unsubscribe())}})}switchMap(e){return new r(t=>{let s=null;const n=this.subscribe({next:i=>{if(s){s.unsubscribe()}const o=e(i);s=o.subscribe({next:c=>t.next(c),error:c=>t.error(c),complete:()=>{if(s){s.unsubscribe();s=null}}})},error:i=>t.error(i),complete:()=>{if(s){s.unsubscribe()}t.complete()}});return()=>{n.unsubscribe();if(s){s.unsubscribe()}}})}toArray(){return new Promise((e,t)=>{const s=[];this.subscribe({next:n=>s.push(n),error:n=>t(n),complete:()=>e(s)})})}forEach(e){return new Promise((t,s)=>{this.subscribe({next:n=>e(n),error:n=>s(n),complete:()=>t()})})}every(e){return new Promise((t,s)=>{let n=true;this.subscribe({next:i=>{if(!e(i)){n=false;t(false)}},error:i=>s(i),complete:()=>t(n)})})}find(e){return new Promise((t,s)=>{const n=this.subscribe({next:i=>{if(e(i)){t(i);n.unsubscribe()}},error:i=>s(i),complete:()=>t(void 0)})})}some(e){return new Promise((t,s)=>{const n=this.subscribe({next:i=>{if(e(i)){t(true);n.unsubscribe()}},error:i=>s(i),complete:()=>t(false)})})}finally(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(n),error:n=>{e();t.error(n)},complete:()=>{e();t.complete()}});return()=>{s.unsubscribe()}})}toState(e=null){const t=new w(e,null,{name:"ObservableStream"});this.subscribe({next:s=>t.update(()=>s),error:s=>t.error(s),complete:()=>t.complete()});return t}push(e){if(e instanceof y){const t=e.subscribe({next:s=>this.__observers.forEach(n=>n.next(s)),error:s=>this.__observers.forEach(n=>n.error(s)),complete:()=>this.__observers.forEach(s=>s.complete())})}else if(e[Symbol.asyncIterator]){(()=>k(this,null,function*(){try{try{for(var t=ge(e),s,n,i;s=!(n=yield t.next()).done;s=false){const o=n.value;this.__observers.forEach(c=>c.next(o))}}catch(n){i=[n]}finally{try{s&&(n=t.return)&&(yield n.call(t))}finally{if(i)throw i[0]}}this.__observers.forEach(o=>o.complete())}catch(o){this.__observers.forEach(c=>c.error(o))}}))()}else if(e[Symbol.iterator]){try{for(const t of e){this.__observers.forEach(s=>s.next(t))}this.__observers.forEach(t=>t.complete())}catch(t){this.__observers.forEach(s=>s.error(t))}}else if(e instanceof Promise){e.then(t=>{this.__observers.forEach(s=>s.next(t));this.__observers.forEach(s=>s.complete())},t=>this.__observers.forEach(s=>s.error(t)))}else{this.__observers.forEach(t=>t.next(e))}}plug(e){e.subscribe({next:t=>this.push(t),error:t=>this.__observers.forEach(s=>s.error(t)),complete:()=>this.__observers.forEach(t=>t.complete())})}end(){this.__observers.forEach(e=>{if(e&&typeof e.complete==="function"){e.complete()}})}catchError(e){return new r(t=>{const s=this.subscribe({next:n=>t.next(n),error:n=>{const i=e(n);i.subscribe({next:o=>t.next(o),error:o=>t.error(o),complete:()=>t.complete()})},complete:()=>t.complete()});return()=>s.unsubscribe()})}debounce(e){return new r(t=>{let s=null;const n=this.subscribe({next:i=>{clearTimeout(s);s=setTimeout(()=>{t.next(i)},e)},error:i=>t.error(i),complete:()=>{clearTimeout(s);t.complete()}});return()=>{clearTimeout(s);n.unsubscribe()}})}tap(e){return new r(t=>{const s=this.subscribe({next:n=>{e(n);t.next(n)},error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}throttle(e){return new r(t=>{let s=0;const n=this.subscribe({next:i=>{const o=Date.now();if(o-s>e){s=o;t.next(i)}},error:i=>t.error(i),complete:()=>t.complete()});return()=>n.unsubscribe()})}distinctUntilChanged(){return new r(e=>{let t;let s=true;const n=this.subscribe({next:i=>{if(s||i!==t){s=false;t=i;e.next(i)}},error:i=>e.error(i),complete:()=>e.complete()});return()=>n.unsubscribe()})}concatMap(e){return new r(t=>{let s=null;let n=false;const i=[];const o=this.subscribe({next:c=>{if(!n){n=true;const a=e(c);s=a.subscribe({next:u=>t.next(u),error:u=>t.error(u),complete:()=>{if(i.length>0){const u=i.shift();const f=e(u);s=f.subscribe({next:l=>t.next(l),error:l=>t.error(l),complete:()=>n=false})}else{n=false}}})}else{i.push(c)}},error:c=>t.error(c),complete:()=>{if(!n){t.complete()}}});return()=>{o.unsubscribe();if(s){s.unsubscribe()}}})}combineLatest(...e){return new r(t=>{const s=new Array(e.length).fill(void 0);const n=e.map((i,o)=>i.subscribe({next:c=>{s[o]=c;if(!s.includes(void 0)){t.next([...s])}},error:c=>t.error(c),complete:()=>{}}));return()=>n.forEach(i=>i.unsubscribe())})}startWith(...e){return new r(t=>{e.forEach(n=>t.next(n));const s=this.subscribe({next:n=>t.next(n),error:n=>t.error(n),complete:()=>t.complete()});return()=>s.unsubscribe()})}};var R={current:null};var w=class extends y{constructor(e=null,t=null,{last:s=false,name:n=null}={}){super();if(s){this.__lastObserver=t}else{this.__observers.push(t)}this.__value=C(e,i=>{});this.__pendingUpdates=[];this.__updateScheduled=false;this.__name=n}get value(){if(R.current!=null){R.current.addDependency(this)}return this.__value}set value(e){this.update(()=>e)}assign(e){if(typeof this.__value!=="object"||this.__value===null){throw new Error("[Cami.js] Observable value is not an object")}this.update(t=>Object.assign(t,e))}set(e,t){if(typeof this.__value!=="object"||this.__value===null){throw new Error("[Cami.js] Observable value is not an object")}this.update(s=>{const n=e.split(".");let i=s;for(let o=0;o{const s=e.split(".");let n=t;for(let i=0;i({}))}push(...e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.push(...e)})}pop(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.pop()})}shift(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.shift()})}splice(e,t,...s){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.splice(e,t,...s)})}unshift(...e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.unshift(...e)})}reverse(){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(e=>{e.reverse()})}sort(e){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(t=>{t.sort(e)})}fill(e,t=0,s=this.__value.length){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.fill(e,t,s)})}copyWithin(e,t,s=this.__value.length){if(!Array.isArray(this.__value)){throw new Error("[Cami.js] Observable value is not an array")}this.update(n=>{n.copyWithin(e,t,s)})}update(e){this.__pendingUpdates.push(e);this.__scheduleupdate()}__scheduleupdate(){if(!this.__updateScheduled){this.__updateScheduled=true;this.__applyUpdates()}}__notifyObservers(){const e=[...this.__observers,this.__lastObserver];e.forEach(t=>{if(t&&typeof t==="function"){t(this.__value)}else if(t&&t.next){t.next(this.__value)}})}__applyUpdates(){let e=this.__value;while(this.__pendingUpdates.length>0){const t=this.__pendingUpdates.shift();if(typeof this.__value==="object"&&this.__value!==null&&this.__value.constructor===Object||Array.isArray(this.__value)){this.__value=C(this.__value,t)}else{this.__value=t(this.__value)}}if(e!==this.__value){this.__notifyObservers();if(j.events.isEnabled&&typeof window!=="undefined"){const t=new CustomEvent("cami:state:change",{detail:{name:this.__name,oldValue:e,newValue:this.__value}});window.dispatchEvent(t)}_("cami:state:change",this.__name,e,this.__value)}this.__updateScheduled=false}toStream(){const e=new v;this.subscribe({next:t=>e.emit(t),error:t=>e.error(t),complete:()=>e.end()});return e}complete(){this.__observers.forEach(e=>{if(e&&typeof e.complete==="function"){e.complete()}})}};var Le=class extends w{constructor(e){super(null);this.computeFn=e;this.dependencies=new Set;this.subscriptions=new Map;this.__compute()}get value(){if(R.current){R.current.addDependency(this)}return this.__value}__compute(){const e={addDependency:s=>{if(!this.dependencies.has(s)){const n=s.onValue(()=>this.__compute());this.dependencies.add(s);this.subscriptions.set(s,n)}}};R.current=e;const t=this.computeFn();R.current=null;if(t!==this.__value){this.__value=t;this.__notifyObservers()}}dispose(){this.subscriptions.forEach(e=>{e.unsubscribe()})}};var he=function(r){return new Le(r)};var fe=function(r){let e=()=>{};let t=new Set;let s=new Map;const n={addDependency:c=>{if(!t.has(c)){const a=c.onValue(i);t.add(c);s.set(c,a)}}};const i=()=>{e();R.current=n;e=r()||(()=>{});R.current=null};if(typeof window!=="undefined"){requestAnimationFrame(i)}else{setTimeout(i,0)}const o=()=>{s.forEach(c=>{c.unsubscribe()});e()};return o};var de=class{constructor(e){if(!(e instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}return new Proxy(e,{get:(t,s)=>{if(typeof t[s]==="function"){return t[s].bind(t)}else if(s in t){return t[s]}else if(typeof t.value[s]==="function"){return(...n)=>t.value[s](...n)}else{return t.value[s]}},set:(t,s,n)=>{t[s]=n;t.update(()=>t.value);return true}})}};var O=new Map;var _e=class extends HTMLElement{constructor(){super();this.onCreate();this.__unsubscribers=new Map;this.__computed=he.bind(this);this.effect=fe.bind(this);this.__queryFunctions=new Map}observableAttributes(e){Object.entries(e).forEach(([t,s])=>{let n=this.getAttribute(t);const i=typeof s==="function"?s:c=>c;n=C(n,i);const o=this.__observable(n,t);if(this.__isObjectOrArray(o.value)){this.__createObservablePropertyForObjOrArr(this,t,o,true)}else{this.__createObservablePropertyForPrimitive(this,t,o,true)}})}__computed(e){const t=super._computed(e);console.log(t);this.__registerObservables(t);return t}effect(e){const t=super.effect(e);this.__unsubscribers.set(e,t)}connect(e,t){if(!(e instanceof D)){throw new TypeError("Expected store to be an instance of ObservableStore")}const s=this.__observable(e.state[t],t);const n=e.subscribe(i=>{s.update(()=>i[t])});this.__unsubscribers.set(t,n);if(this.__isObjectOrArray(s.value)){this.__createObservablePropertyForObjOrArr(this,t,s);return this[t]}else{this.__createObservablePropertyForPrimitive(this,t,s);return this[t]}}stream(e){return new v(e)}template(){throw new Error("[Cami.js] You have to implement the method template()!")}query({queryKey:e,queryFn:t,staleTime:s=0,refetchOnWindowFocus:n=true,refetchOnMount:i=true,refetchOnReconnect:o=true,refetchInterval:c=null,gcTime:a=1e3*60*5,retry:u=3,retryDelay:f=l=>Math.pow(2,l)*1e3}){const l=Array.isArray(e)?e.map(E=>typeof E==="object"?JSON.stringify(E):E).join(":"):e;this.__queryFunctions.set(l,t);_("query","Starting query with key:",l);const d=this.__observable({data:null,status:"pending",fetchStatus:"idle",error:null,lastUpdated:O.has(l)?O.get(l).lastUpdated:null},l);const h=this.__observableProxy(d);const m=(E=0)=>k(this,null,function*(){const We=Date.now();const be=O.get(l);if(be&&We-be.lastUpdated{A.data=be.data;A.status="success";A.fetchStatus="idle"})}else{_("fetchData (else)","Fetching data for key:",l);try{h.update(T=>{T.status="pending";T.fetchStatus="fetching"});const A=yield t();O.set(l,{data:A,lastUpdated:We});h.update(T=>{T.data=A;T.status="success";T.fetchStatus="idle"})}catch(A){_("fetchData (catch)","Fetch error for key:",l,A);if(Em(E+1),f(E))}else{h.update(T=>{T.errorDetails={message:A.message,stack:A.stack};T.status="error";T.fetchStatus="idle"})}}}});if(i){_("query","Setting up refetch on mount for key:",l);m()}if(n){_("query","Setting up refetch on window focus for key:",l);const E=()=>m();window.addEventListener("focus",E);this.__unsubscribers.set(`focus:${l}`,()=>window.removeEventListener("focus",E))}if(o){_("query","Setting up refetch on reconnect for key:",l);window.addEventListener("online",m);this.__unsubscribers.set(`online:${l}`,()=>window.removeEventListener("online",m))}if(c){_("query","Setting up refetch interval for key:",l);const E=setInterval(m,c);this.__unsubscribers.set(`interval:${l}`,()=>clearInterval(E))}const U=setTimeout(()=>{O.delete(l)},a);this.__unsubscribers.set(`gc:${l}`,()=>clearTimeout(U));return h}mutation({mutationFn:e,onMutate:t,onError:s,onSuccess:n,onSettled:i}){const o=this.__observable({data:null,status:"idle",error:null,isSettled:false},"mutation");const c=this.__observableProxy(o);const a=u=>k(this,null,function*(){_("mutation","Starting mutation for variables:",u);let f;const l=c.value;if(t){_("mutation","Performing optimistic update for variables:",u);f=t(u,l);c.update(d=>{d.data=f.optimisticData;d.status="pending";d.errorDetails=null})}else{_("mutation","Performing mutation without optimistic update for variables:",u);c.update(d=>{d.status="pending";d.errorDetails=null})}try{const d=yield e(u);c.update(h=>{h.data=d;h.status="success"});if(n){n(d,u,f)}_("mutation","Mutation successful for variables:",u,d)}catch(d){_("mutation","Mutation error for variables:",u,d);c.update(h=>{h.errorDetails={message:d.message};h.status="error";if(!s&&f&&f.rollback){_("mutation","Rolling back mutation for variables:",u);f.rollback()}});if(s){s(d,u,f)}}finally{if(!c.value.isSettled){c.update(d=>{d.isSettled=true});if(i){_("mutation","Calling onSettled for variables:",u);i(c.value.data,c.value.error,u,f)}}}});c.mutate=a;c.reset=()=>{c.update(u=>{u.data=null;u.status="idle";u.errorDetails=null;u.isSettled=false})};return c}invalidateQueries(e){const t=Array.isArray(e)?e.join(":"):e;_("invalidateQueries","Invalidating query with key:",t);O.delete(t);this.__updateCache(t)}onCreate(){}connectedCallback(){this.__setup({infer:true});this.effect(()=>this.render());this.render();this.onConnect()}onConnect(){}disconnectedCallback(){this.onDisconnect();this.__unsubscribers.forEach(e=>e())}onDisconnect(){}attributeChangedCallback(e,t,s){this.onAttributeChange(e,t,s)}onAttributeChange(e,t,s){}adoptedCallback(){this.onAdopt()}onAdopt(){}__isObjectOrArray(e){return e!==null&&(typeof e==="object"||Array.isArray(e))}__createObservablePropertyForObjOrArr(e,t,s,n=false){if(!(s instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}const i=this.__observableProxy(s);Object.defineProperty(e,t,{get:()=>i,set:o=>{s.update(()=>o);if(n){this.setAttribute(t,o)}}})}__createObservablePropertyForPrimitive(e,t,s,n=false){if(!(s instanceof w)){throw new TypeError("Expected observable to be an instance of ObservableState")}Object.defineProperty(e,t,{get:()=>s.value,set:i=>{s.update(()=>i);if(n){this.setAttribute(t,i)}}})}__observableProxy(e){return new de(e)}__setup(e){if(e.infer===true){Object.keys(this).forEach(t=>{if(typeof this[t]!=="function"&&!t.startsWith("__")){if(this[t]instanceof y){return}else{const s=this.__observable(this[t],t);if(this.__isObjectOrArray(s.value)){this.__createObservablePropertyForObjOrArr(this,t,s)}else{this.__createObservablePropertyForPrimitive(this,t,s)}}}})}}__observable(e,t){if(!this.__isAllowedType(e)){const n=Object.prototype.toString.call(e);throw new Error(`[Cami.js] The value of type ${n} is not allowed in observables. Only primitive values, arrays, and plain objects are allowed.`)}const s=new w(e,null,{name:t});this.__registerObservables(s);return s}__updateCache(e){_("__updateCache","Invalidating cache with key:",e);const t=this.__queryFunctions.get(e);if(t){_("__updateCache","Found query function for key:",e);const s=O.get(e)||{data:void 0,status:"idle",error:null};O.set(e,we(S({},s),{status:"pending",error:null}));t().then(n=>{O.set(e,{data:n,status:"success",error:null,lastUpdated:Date.now()});_("__updateCache","Refetch successful for key:",e,n)}).catch(n=>{if(s.data!==void 0){_("__updateCache","Rolling back refetch for key:",e);O.set(e,s)}O.set(e,we(S({},s),{status:"error",error:n}))})}}__isAllowedType(e){const t=["number","string","boolean","object","undefined"];const s=typeof e;if(s==="object"){return e===null||Array.isArray(e)||this.__isPlainObject(e)}return t.includes(s)}__isPlainObject(e){if(Object.prototype.toString.call(e)!=="[object Object]"){return false}const t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}__registerObservables(e){if(!(e instanceof w)){throw new TypeError("Expected observableState to be an instance of ObservableState")}this.__unsubscribers.set(e,()=>{if(typeof e.dispose==="function"){e.dispose()}})}render(){const e=this.template();je(e,this)}};var pe=class extends v{constructor(e){super();if(typeof e==="string"){this.element=document.querySelector(e);if(!this.element){throw new Error(`[Cami.js] Element not found for selector: ${e}`)}}else if(e instanceof Element||e instanceof Document){this.element=e}else{throw new Error(`[Cami.js] Invalid argument: ${e}`)}}on(e,t={}){return new v(s=>{const n=i=>{s.next(i)};this.element.addEventListener(e,n,t);return()=>{this.element.removeEventListener(e,n,t)}})}};var me=class extends v{constructor(){super(...arguments);Ge(this,"__handlers",{})}toJson(){return new Promise((t,s)=>{this.subscribe({next:n=>{try{if(typeof n==="object"){t(n)}else{t(JSON.parse(n))}}catch(i){s(i)}},error:n=>s(n)})})}on(t,s){if(!this.__handlers[t]){this.__handlers[t]=[]}this.__handlers[t].push(s);return this}};var g=r=>{if(typeof r==="string"){return g.get(r)}return new me(e=>{const t=new XMLHttpRequest;t.open(r.method||"GET",r.url);if(r.headers){Object.keys(r.headers).forEach(s=>{t.setRequestHeader(s,r.headers[s])})}t.onload=()=>{let s=t.responseText;const n=r.transformResponse||(i=>{try{return JSON.parse(i)}catch(o){return i}});s=n(s);e.next(s);e.complete()};t.onerror=()=>e.error(t.statusText);t.send(r.data?JSON.stringify(r.data):null);return()=>{t.abort()}})};g.get=(r,e={})=>{e.url=r;e.method="GET";return g(e)};g.post=(r,e={},t={})=>{t.url=r;t.data=e;t.method="POST";return g(t)};g.put=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PUT";return g(t)};g.patch=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PATCH";return g(t)};g.delete=(r,e={})=>{e.url=r;e.method="DELETE";return g(e)};g.sse=(r,e={})=>{const t=new me(s=>{const n=new EventSource(r,e);n.onmessage=i=>{if(t.__handlers[i.type]){t.__handlers[i.type].forEach(o=>o(i))}s.next(i)};n.onerror=i=>s.error(i);return()=>{n.close()}});return t};var{debug:or,events:cr}=j;return Dt(ar);})(); /** * @license * lit-html diff --git a/site/javascripts/cami.cdn.js.map b/site/javascripts/cami.cdn.js.map index 64660038..87ed9c45 100644 --- a/site/javascripts/cami.cdn.js.map +++ b/site/javascripts/cami.cdn.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../src/cami.js", "../src/html.js", "../src/produce.js", "../src/observables/observable.js", "../src/config.js", "../src/trace.js", "../src/observables/observable-store.js", "../src/observables/observable-stream.js", "../src/observables/observable-state.js", "../src/observables/observable-proxy.js", "../src/reactive-element.js", "../src/observables/observable-element.js", "../src/http.js"], - "sourcesContent": ["/**\n * @license\n * cami.js\n * Copyright (c) 2023 Kenn Costales\n * MIT License\n */\n\n/**\n * @module cami\n */\nimport { html, render, svg } from './html.js';\nimport { produce } from \"./produce.js\"\nimport { ReactiveElement } from './reactive-element.js';\nimport { ObservableStore, store } from './observables/observable-store.js';\nimport { Observable } from './observables/observable.js';\nimport { ObservableState, computed, effect } from './observables/observable-state.js';\nimport { ObservableStream } from './observables/observable-stream.js';\nimport { ObservableElement } from './observables/observable-element.js';\nimport { __config } from './config.js';\nimport { __trace } from './trace.js';\nimport { http } from './http.js';\n\nconst { debug, events } = __config;\n\n/**\n * @exports store - The store object from observable-store.js. This uses local storage by default.\n * @exports html - The html function from html.js\n * @exports svg - The svg function from html.js\n * @exports ReactiveElement - The ReactiveElement class from reactive_element.js\n * @exports ObservableStream - The ObservableStream class from observable-stream.js\n * @exports ObservableElement - The ObservableElement class from observable-element.js\n * @exports Observable - The Observable class from observable.js\n * @exports ObservableState - The ObservableState class from observable-state.js\n * @exports ObservableStore - The ObservableStore class from observable-store.js\n * @exports http - The http function from http.js\n * @exports debug - The debug property from __config\n * @exports events - The events property from __config\n */\nexport { store, html, svg, ReactiveElement, ObservableStream, ObservableElement, Observable, ObservableState, ObservableStore, http, debug, events, computed, effect };\n", "/**\n * @license\n * lit-html\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n// Allows minifiers to rename references to globalThis\nconst global = globalThis;\nconst wrap = (node) => node;\nconst trustedTypes = global.trustedTypes;\n/**\n * Our TrustedTypePolicy for HTML which is declared using the html template\n * tag function.\n *\n * That HTML is a developer-authored constant, and is parsed with innerHTML\n * before any untrusted expressions have been mixed in. Therefor it is\n * considered safe by construction.\n */\nconst policy = trustedTypes\n ? trustedTypes.createPolicy('cami-html', {\n createHTML: (s) => s,\n })\n : undefined;\n// Added to an attribute name to mark the attribute as bound so we can find\n// it easily.\nconst boundAttributeSuffix = '$cami$';\n// This marker is used in many syntactic positions in HTML, so it must be\n// a valid element name and attribute name. We don't support dynamic names (yet)\n// but this at least ensures that the parse tree is closer to the template\n// intention.\nconst marker = `cami$${String(Math.random()).slice(9)}$`;\n// String used to tell if a comment is a marker comment\nconst markerMatch = '?' + marker;\n// Text used to insert a comment marker node. We use processing instruction\n// syntax because it's slightly smaller, but parses as a comment node.\nconst nodeMarker = `<${markerMatch}>`;\nconst d = document;\n// Creates a dynamic marker. We never have to search for these in the DOM.\nconst createMarker = () => d.createComment('');\nconst isPrimitive = (value) => value === null || (typeof value != 'object' && typeof value != 'function');\nconst isArray = Array.isArray;\nconst isIterable = (value) => isArray(value) ||\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof value?.[Symbol.iterator] === 'function';\nconst SPACE_CHAR = `[ \\t\\n\\f\\r]`;\nconst ATTR_VALUE_CHAR = `[^ \\t\\n\\f\\r\"'\\`<>=]`;\nconst NAME_CHAR = `[^\\\\s\"'>=/]`;\n// These regexes represent the five parsing states that we care about in the\n// Template's HTML scanner. They match the *end* of the state they're named\n// after.\n// Depending on the match, we transition to a new state. If there's no match,\n// we stay in the same state.\n// Note that the regexes are stateful. We utilize lastIndex and sync it\n// across the multiple regexes used. In addition to the five regexes below\n// we also dynamically create a regex to find the matching end tags for raw\n// text elements.\n/**\n * End of text is: `<` followed by:\n * (comment start) or (tag) or (dynamic tag binding)\n */\nconst textEndRegex = /<(?:(!--|\\/[^a-zA-Z])|(\\/?[a-zA-Z][^>\\s]*)|(\\/?$))/g;\nconst COMMENT_START = 1;\nconst TAG_NAME = 2;\nconst DYNAMIC_TAG_NAME = 3;\nconst commentEndRegex = /-->/g;\n/**\n * Comments not started with /g;\n/**\n * Comments not started with