diff --git a/README.md b/README.md index 7cd58710..ca2533b5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ⚠️ Expect API changes until v1.0.0 ⚠️ -Current version: 0.3.6. +Current version: 0.3.7. Bundle Size: 14kb minified & gzipped. diff --git a/build/cami.cdn.js b/build/cami.cdn.js index 69f96c2f..05d8dc11 100644 --- a/build/cami.cdn.js +++ b/build/cami.cdn.js @@ -1,5 +1,5 @@ var cami=(()=>{var se=Object.defineProperty;var At=Object.defineProperties;var xt=Object.getOwnPropertyDescriptor;var $t=Object.getOwnPropertyDescriptors;var Et=Object.getOwnPropertyNames;var Ve=Object.getOwnPropertySymbols;var We=Object.prototype.hasOwnProperty;var Ot=Object.prototype.propertyIsEnumerable;var qe=(r,e)=>{if(e=Symbol[r])return e;throw Error("Symbol."+r+" is not defined")};var ye=(r,e,t)=>e in r?se(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var C=(r,e)=>{for(var t in e||(e={}))if(We.call(e,t))ye(r,t,e[t]);if(Ve)for(var t of Ve(e)){if(Ot.call(e,t))ye(r,t,e[t])}return r};var ge=(r,e)=>At(r,$t(e));var St=(r,e)=>{for(var t in e)se(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 Et(e))if(!We.call(r,n)&&n!==t)se(r,n,{get:()=>e[n],enumerable:!(s=xt(e,n))||s.enumerable})}return r};var Ct=r=>Pt(se({},"__esModule",{value:true}),r);var Be=(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=c=>{try{a(t.next(c))}catch(u){n(u)}};var o=c=>{try{a(t.throw(c))}catch(u){n(u)}};var a=c=>c.done?s(c.value):Promise.resolve(c.value).then(i,o);a((t=t.apply(r,e)).next())})};var ve=(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,a,c)=>(i=n.call(r,i),c=i.done,Promise.resolve(i.value).then(u=>o({value:u,done:c}),a)))),t("next"),t("return"),e);var Kt={};St(Kt,{Observable:()=>b,ObservableElement:()=>_e,ObservableState:()=>A,ObservableStore:()=>j,ObservableStream:()=>w,ReactiveElement:()=>de,computed:()=>he,css:()=>ie,debug:()=>Zt,effect:()=>pe,events:()=>Yt,html:()=>Pe,http:()=>y,store:()=>vt,svg:()=>it});var J=globalThis;var ne=J.trustedTypes;var Qe=ne?ne.createPolicy("lit-html",{createHTML:r=>r}):void 0;var et="$lit$";var T=`lit$${(Math.random()+"").slice(9)}$`;var tt="?"+T;var Tt=`<${tt}>`;var I=document;var X=()=>I.createComment("");var G=r=>null===r||"object"!=typeof r&&"function"!=typeof r;var rt=Array.isArray;var jt=r=>rt(r)||"function"==typeof(r==null?void 0:r[Symbol.iterator]);var we="[ \n\f\r]";var Q=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g;var Je=/-->/g;var Xe=/>/g;var N=RegExp(`>|${we}(?:([^\\s"'>=/]+)(${we}*=${we}*(?:[^ -\f\r"'\`<>=]|("|')|))|$)`,"g");var Ge=/'/g;var Ze=/"/g;var st=/^(?:script|style|textarea|title)$/i;var nt=r=>(e,...t)=>({_$litType$:r,strings:e,values:t});var Pe=nt(1);var it=nt(2);var Z=Symbol.for("lit-noChange");var d=Symbol.for("lit-nothing");var Ye=new WeakMap;var M=I.createTreeWalker(I,129);function ot(r,e){if(!Array.isArray(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==Qe?Qe.createHTML(e):e}var Dt=(r,e)=>{const t=r.length-1,s=[];let n,i=2===e?"":"",o=Q;for(let a=0;a"===f[0]?(o=n!=null?n:Q,l=-1):void 0===f[1]?l=-2:(l=o.lastIndex-f[2].length,u=f[1],o=void 0===f[3]?N:'"'===f[3]?Ze:Ge):o===Ze||o===Ge?o=N:o===Je||o===Xe?o=Q:(o=N,n=void 0);const _=o===N&&r[a+1].startsWith("/>")?" ":"";i+=o===Q?c+Tt:l>=0?(s.push(u),c.slice(0,l)+et+c.slice(l)+T+_):c+T+(-2===l?a:_)}return[ot(r,i+(r[t]||"")+(2===e?"":"")),s]};var Y=class r{constructor({strings:e,_$litType$:t},s){let n;this.parts=[];let i=0,o=0;const a=e.length-1,c=this.parts,[u,f]=Dt(e,t);if(this.el=r.createElement(u,s),M.currentNode=this.el.content,2===t){const l=this.el.content.firstChild;l.replaceWith(...l.childNodes)}for(;null!==(n=M.nextNode())&&c.length0){n.textContent=ne?ne.emptyScript:"";for(let _=0;_2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=d}_$AI(e,t=this,s,n){const i=this.strings;let o=false;if(void 0===i)e=L(this,e,t,0),o=!G(e)||e!==this._$AH&&e!==Z,o&&(this._$AH=e);else{const a=e;let c,u;for(e=i[0],c=0;c{var i,o;const s=(i=t==null?void 0:t.renderBefore)!=null?i:e;let n=s._$litPart$;if(void 0===n){const a=(o=t==null?void 0:t.renderBefore)!=null?o:null;s._$litPart$=n=new K(e.insertBefore(X(),a),a,void 0,t!=null?t:{})}return n._$AI(r),n};var Nt={data:""};var Mt=r=>"object"==typeof window?((r?r.querySelector("#_goober"):window._goober)||Object.assign((r||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:r||Nt;var It=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g;var zt=/\/\*[^]*?\*\/| +/g;var at=/\n+/g;var z=(r,e)=>{let t="",s="",n="";for(let i in r){let o=r[i];"@"==i[0]?"i"==i[1]?t=i+" "+o+";":s+="f"==i[1]?z(o,i):i+"{"+z(o,"k"==i[1]?"":e)+"}":"object"==typeof o?s+=z(o,e?e.replace(/([^,])+/g,a=>i.replace(/(^:.*)|([^,])+/g,c=>/&/.test(c)?c.replace(/&/g,a):a?a+" "+c:c)):i):null!=o&&(i=/^--/.test(i)?i:i.replace(/[A-Z]/g,"-$&").toLowerCase(),n+=z.p?z.p(i,o):i+":"+o+";")}return t+(e&&n?e+"{"+n+"}":n)+s};var P={};var ct=r=>{if("object"==typeof r){let e="";for(let t in r)e+=t+ct(r[t]);return e}return r};var Ft=(r,e,t,s,n)=>{let i=ct(r),o=P[i]||(P[i]=(c=>{let u=0,f=11;for(;u>>0;return"go"+f})(i));if(!P[o]){let c=i!==r?r:(u=>{let f,l,h=[{}];for(;f=It.exec(u.replace(zt,""));)f[4]?h.shift():f[3]?(l=f[3].replace(at," ").trim(),h.unshift(h[0][l]=h[0][l]||{})):h[0][f[1]]=f[2].replace(at," ").trim();return h[0]})(r);P[o]=z(n?{["@keyframes "+o]:c}:c,t?"":"."+o)}let a=t&&P.g?P.g:null;return t&&(P.g=P[o]),((c,u,f,l)=>{l?u.data=u.data.replace(l,c):-1===u.data.indexOf(c)&&(u.data=f?c+u.data:u.data+c)})(P[o],e,s,a),o};var Ht=(r,e,t)=>r.reduce((s,n,i)=>{let o=e[i];if(o&&o.call){let a=o(t),c=a&&a.props&&a.props.className||/^go/.test(a)&&a;o=c?"."+c:a&&"object"==typeof a?a.props?"":z(a,""):false===a?"":a}return s+n+(null==o?"":o)},"");function ie(r){let e=this||{},t=r.call?r(e.p):r;return Ft(t.unshift?t.raw?Ht(t,[].slice.call(arguments,1),e.p):t.reduce((s,n)=>Object.assign(s,n&&n.call?n(e.p):n),{}):t,Mt(e.target),e.g,e.o,e.k)}var rr=ie.bind({g:1});var sr=ie.bind({k:1});var dt=Symbol.for("immer-nothing");var ut=Symbol.for("immer-draftable");var g=Symbol.for("immer-state");var Ut=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.","Immer forbids 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 an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(r){return`'original' expects a draft, got: ${r}`}]:[];function m(r,...e){if(true){const t=Ut[r];const s=typeof t==="function"?t.apply(null,e):t;throw new Error(`[Immer] ${s}`)}throw new Error(`[Immer] minified error nr: ${r}. Full error at: https://bit.ly/3cXEKWf`)}var q=Object.getPrototypeOf;function W(r){return!!r&&!!r[g]}function H(r){var e;if(!r)return false;return _t(r)||Array.isArray(r)||!!r[ut]||!!((e=r.constructor)==null?void 0:e[ut])||ue(r)||le(r)}var Rt=Object.prototype.constructor.toString();function _t(r){if(!r||typeof r!=="object")return false;const e=q(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)===Rt}function ee(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[g];return e?e.type_:Array.isArray(r)?1:ue(r)?2:le(r)?3:0}function De(r,e){return ce(r)===2?r.has(e):Object.prototype.hasOwnProperty.call(r,e)}function mt(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 kt(r,e){if(r===e){return r!==0||1/r===1/e}else{return r!==r&&e!==e}}function ue(r){return r instanceof Map}function le(r){return r instanceof Set}function F(r){return r.copy_||r.base_}function Ne(r,e){if(ue(r)){return new Map(r)}if(le(r)){return new Set(r)}if(Array.isArray(r))return Array.prototype.slice.call(r);if(!e&&_t(r)){if(!q(r)){const n=Object.create(null);return Object.assign(n,r)}return C({},r)}const t=Object.getOwnPropertyDescriptors(r);delete t[g];let s=Reflect.ownKeys(t);for(let n=0;n1){r.set=r.add=r.clear=r.delete=Lt}Object.freeze(r);if(e)ee(r,(t,s)=>He(s,true),true);return r}function Lt(){m(2)}function fe(r){return Object.isFrozen(r)}var Vt={};function U(r){const e=Vt[r];if(!e){m(0,r)}return e}var te;function bt(){return te}function qt(r,e){return{drafts_:[],parent_:r,immer_:e,canAutoFreeze_:true,unfinalizedDrafts_:0}}function lt(r,e){if(e){U("Patches");r.patches_=[];r.inversePatches_=[];r.patchListener_=e}}function Me(r){Ie(r);r.drafts_.forEach(Wt);r.drafts_=null}function Ie(r){if(r===te){te=r.parent_}}function ft(r){return te=qt(te,r)}function Wt(r){const e=r[g];if(e.type_===0||e.type_===1)e.revoke_();else e.revoked_=true}function ht(r,e){e.unfinalizedDrafts_=e.drafts_.length;const t=e.drafts_[0];const s=r!==void 0&&r!==t;if(s){if(t[g].modified_){Me(e);m(4)}if(H(r)){r=oe(e,r);if(!e.parent_)ae(e,r)}if(e.patches_){U("Patches").generateReplacementPatches_(t[g].base_,r,e.patches_,e.inversePatches_)}}else{r=oe(e,t,[])}Me(e);if(e.patches_){e.patchListener_(e.patches_,e.inversePatches_)}return r!==dt?r:void 0}function oe(r,e,t){if(fe(e))return e;const s=e[g];if(!s){ee(e,(n,i)=>pt(r,s,e,n,i,t),true);return e}if(s.scope_!==r)return e;if(!s.modified_){ae(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}ee(i,(a,c)=>pt(r,s,n,a,c,t,o));ae(r,n,false);if(t&&r.patches_){U("Patches").generatePatches_(s,t,r.patches_,r.inversePatches_)}}return s.copy_}function pt(r,e,t,s,n,i,o){if(n===t)m(5);if(W(n)){const a=i&&e&&e.type_!==3&&!De(e.assigned_,s)?i.concat(s):void 0;const c=oe(r,n,a);mt(t,s,c);if(W(c)){r.canAutoFreeze_=false}else return}else if(o){t.add(n)}if(H(n)&&!fe(n)){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1){return}oe(r,n);if(!e||!e.scope_.parent_)ae(r,n)}}function ae(r,e,t=false){if(!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_){He(e,t)}}function Bt(r,e){const t=Array.isArray(r);const s={type_:t?1:0,scope_:e?e.scope_:bt(),modified_:false,finalized_:false,assigned_:{},parent_:e,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:false};let n=s;let i=Ue;if(t){n=[s];i=re}const{revoke:o,proxy:a}=Proxy.revocable(n,i);s.draft_=a;s.revoke_=o;return a}var Ue={get(r,e){if(e===g)return r;const t=F(r);if(!De(t,e)){return Qt(r,t,e)}const s=t[e];if(r.finalized_||!H(s)){return s}if(s===Te(r.base_,e)){je(r);return r.copy_[e]=Fe(s,r)}return s},has(r,e){return e in F(r)},ownKeys(r){return Reflect.ownKeys(F(r))},set(r,e,t){const s=yt(F(r),e);if(s==null?void 0:s.set){s.set.call(r.draft_,t);return true}if(!r.modified_){const n=Te(F(r),e);const i=n==null?void 0:n[g];if(i&&i.base_===t){r.copy_[e]=t;r.assigned_[e]=false;return true}if(kt(t,n)&&(t!==void 0||De(r.base_,e)))return true;je(r);ze(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(Te(r.base_,e)!==void 0||e in r.base_){r.assigned_[e]=false;je(r);ze(r)}else{delete r.assigned_[e]}if(r.copy_){delete r.copy_[e]}return true},getOwnPropertyDescriptor(r,e){const t=F(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(){m(11)},getPrototypeOf(r){return q(r.base_)},setPrototypeOf(){m(12)}};var re={};ee(Ue,(r,e)=>{re[r]=function(){arguments[0]=arguments[0][0];return e.apply(this,arguments)}});re.deleteProperty=function(r,e){if(isNaN(parseInt(e)))m(13);return re.set.call(this,r,e,void 0)};re.set=function(r,e,t){if(e!=="length"&&isNaN(parseInt(e)))m(14);return Ue.set.call(this,r[0],e,t,r[0])};function Te(r,e){const t=r[g];const s=t?F(t):r;return s[e]}function Qt(r,e,t){var n;const s=yt(e,t);return s?`value`in s?s.value:(n=s.get)==null?void 0:n.call(r.draft_):void 0}function yt(r,e){if(!(e in r))return void 0;let t=q(r);while(t){const s=Object.getOwnPropertyDescriptor(t,e);if(s)return s;t=q(t)}return void 0}function ze(r){if(!r.modified_){r.modified_=true;if(r.parent_){ze(r.parent_)}}}function je(r){if(!r.copy_){r.copy_=Ne(r.base_,r.scope_.immer_.useStrictShallowCopy_)}}var Jt=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 a(c=i,...u){return o.produce(c,f=>t.call(this,f,...u))}}if(typeof t!=="function")m(6);if(s!==void 0&&typeof s!=="function")m(7);let n;if(H(e)){const i=ft(this);const o=Fe(e,void 0);let a=true;try{n=t(o);a=false}finally{if(a)Me(i);else Ie(i)}lt(i,s);return ht(n,i)}else if(!e||typeof e!=="object"){n=t(e);if(n===void 0)n=e;if(n===dt)n=void 0;if(this.autoFreeze_)He(n,true);if(s){const i=[];const o=[];U("Patches").generateReplacementPatches_(e,n,i,o);s(i,o)}return n}else m(1,e)};this.produceWithPatches=(e,t)=>{if(typeof e==="function"){return(o,...a)=>this.produceWithPatches(o,c=>e(c,...a))}let s,n;const i=this.produce(e,t,(o,a)=>{s=o;n=a});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(!H(r))m(8);if(W(r))r=Xt(r);const e=ft(this);const t=Fe(r,void 0);t[g].isManual_=true;Ie(e);return t}finishDraft(r,e){const t=r&&r[g];if(!t||!t.isManual_)m(9);const{scope_:s}=t;lt(s,e);return ht(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=U("Patches").applyPatches_;if(W(r)){return s(r,e)}return this.produce(r,n=>s(n,e))}};function Fe(r,e){const t=ue(r)?U("MapSet").proxyMap_(r,e):le(r)?U("MapSet").proxySet_(r,e):Bt(r,e);const s=e?e.scope_:bt();s.drafts_.push(t);return t}function Xt(r){if(!W(r))m(10,r);return gt(r)}function gt(r){if(!H(r)||fe(r))return r;const e=r[g];let t;if(e){if(!e.modified_)return e.base_;e.finalized_=true;t=Ne(r,e.scope_.immer_.useStrictShallowCopy_)}else{t=Ne(r,true)}ee(t,(s,n)=>{mt(t,s,gt(n))});if(e){e.finalized_=false}return t}var v=new Jt;var R=v.produce;var ir=v.produceWithPatches.bind(v);var or=v.setAutoFreeze.bind(v);var ar=v.setUseStrictShallowCopy.bind(v);var cr=v.applyPatches.bind(v);var ur=v.createDraft.bind(v);var lr=v.finishDraft.bind(v);var Re=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 b=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 Re(n);let o=()=>{};try{o=this.subscribeCallback(i)}catch(a){if(i.error){i.error(a)}else{console.error("[Cami.js] Error in Subscriber:",a)}return}i.addTeardown(o);this._observers.push(i);return{unsubscribe:()=>i.unsubscribe(),complete:()=>i.complete(),error:a=>i.error(a)}}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=class extends b{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();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)}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)}}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);this.state=R(this.state,n=>{s(n,t)});this._observers.forEach(n=>n.next(this.state));if(this.devTools){this.devTools.send(e,this.state)}}};var Gt=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 a=new r(e);a.init=()=>{if(n){const c=localStorage.getItem(s);const u=localStorage.getItem(`${s}-expiry`);const f=new Date().getTime();if(c&&u){const l=f>=parseInt(u,10);if(!l){a.state=JSON.parse(c)}else{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`)}}}};a.init();a.reset=()=>{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`);a.state=e;a._observers.forEach(c=>c.next(a.state))};a.subscribe(c=>{const u=new Date().getTime();const f=u+o;localStorage.setItem(s,JSON.stringify(c));localStorage.setItem(`${s}-expiry`,f.toString())});return a}};var vt=(r,e={})=>{const t={localStorage:true,name:"cami-store",expiry:864e5};const s=C(C({},t),e);if(s.localStorage){const n=Gt(j)(r,s);return n}else{return new j(r)}};var w=class r extends b{static from(e){if(e instanceof b){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=ve(e),i,o,a;i=!(o=yield n.next()).done;i=false){const c=o.value;if(s)return;t.next(c)}}catch(o){a=[o]}finally{try{i&&(o=n.return)&&(yield o.call(n))}finally{if(a)throw a[0]}}t.complete()}catch(c){t.error(c)}}))();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:a=>{i=e(i,a)},error:a=>n(a),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 a=o.subscribe({next:c=>t.next(c),error:c=>t.error(c),complete:()=>{s.delete(a);if(s.size===0){t.complete()}}});s.add(a)},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:a=>t.next(a),error:a=>t.error(a),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 A(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 b){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=ve(e),s,n,i;s=!(n=yield t.next()).done;s=false){const o=n.value;this._observers.forEach(a=>a.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(a=>a.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:a=>{if(!n){n=true;const c=e(a);s=c.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(a)}},error:a=>t.error(a),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:a=>{s[o]=a;if(!s.includes(void 0)){t.next([...s])}},error:a=>t.error(a),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 B={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 p(r,...e){if(B.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={current:null};var A=class extends b{constructor(e=null,t=null,{last:s=false,name:n=null}={}){super();if(s){this._lastObserver=t}else{this._observers.push(t)}this._value=R(e,i=>{});this._pendingUpdates=[];this._updateScheduled=false;this._name=n}get value(){if(D.current!=null){D.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=R(this._value,t)}else{this._value=t(this._value)}}if(e!==this._value){this._notifyObservers();if(B.events.isEnabled&&typeof window!=="undefined"){const t=new CustomEvent("cami:state:change",{detail:{name:this._name,oldValue:e,newValue:this._value}});window.dispatchEvent(t)}p("cami:state:change",this._name,e,this._value)}this._updateScheduled=false}toStream(){const e=new w;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 ke=class extends A{constructor(e){super(null);this.computeFn=e;this.dependencies=new Set;this.subscriptions=new Map;this._compute()}get value(){if(D.current){D.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)}}};D.current=e;const t=this.computeFn();D.current=null;if(t!==this._value){this._value=t;this._notifyObservers()}}dispose(){this.subscriptions.forEach(e=>{e.unsubscribe()})}};var he=function(r){return new ke(r)};var pe=function(r){let e=()=>{};let t=new Set;let s=new Map;const n={addDependency:a=>{if(!t.has(a)){const c=a.onValue(i);t.add(a);s.set(a,c)}}};const i=()=>{e();D.current=n;e=r()||(()=>{});D.current=null};if(typeof window!=="undefined"){requestAnimationFrame(i)}else{setTimeout(i,0)}const o=()=>{s.forEach(a=>{a.unsubscribe()});e()};return o};var E=new Map;var de=class extends HTMLElement{constructor(){super();this.onCreate();this._unsubscribers=new Map;this._computed=he.bind(this);this.effect=pe.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:a=>a;n=R(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 j)){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 w(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:a=null,gcTime:c=1e3*60*5,retry:u=3,retryDelay:f=l=>Math.pow(2,l)*1e3}){const l=Array.isArray(e)?e.map(x=>typeof x==="object"?JSON.stringify(x):x).join(":"):e;this._queryFunctions.set(l,t);p("query","Starting query with key:",l);const h=this._observable({data:null,status:"pending",fetchStatus:"idle",error:null,lastUpdated:E.has(l)?E.get(l).lastUpdated:null},l);const _=this._observableProxy(h);const $=(x=0)=>k(this,null,function*(){const Le=Date.now();const be=E.get(l);if(be&&Le-be.lastUpdated{S.data=be.data;S.status="success";S.fetchStatus="idle"})}else{p("fetchData (else)","Fetching data for key:",l);try{h.update(O=>{O.status="pending";O.fetchStatus="fetching"});const S=yield t();E.set(l,{data:S,lastUpdated:Le});h.update(O=>{O.data=S;O.status="success";O.fetchStatus="idle"})}catch(S){p("fetchData (catch)","Fetch error for key:",l,S);if(x$(x+1),f(x))}else{h.update(O=>{O.error={message:S.message};O.status="error";O.fetchStatus="idle"})}}}});if(i){p("query","Setting up refetch on mount for key:",l);$()}if(n){p("query","Setting up refetch on window focus for key:",l);const x=()=>$();window.addEventListener("focus",x);this._unsubscribers.set(`focus:${l}`,()=>window.removeEventListener("focus",x))}if(o){p("query","Setting up refetch on reconnect for key:",l);window.addEventListener("online",$);this._unsubscribers.set(`online:${l}`,()=>window.removeEventListener("online",$))}if(a){p("query","Setting up refetch interval for key:",l);const x=setInterval($,a);this._unsubscribers.set(`interval:${l}`,()=>clearInterval(x))}const wt=setTimeout(()=>{E.delete(l)},c);this._unsubscribers.set(`gc:${l}`,()=>clearTimeout(wt));return _}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 a=this._observableProxy(o);const c=u=>k(this,null,function*(){p("mutation","Starting mutation for variables:",u);let f;const l=o.value;if(t){p("mutation","Performing optimistic update for variables:",u);f=t(u,l);o.update(h=>{h.data=f.optimisticData;h.status="pending";h.error=null})}else{p("mutation","Performing mutation without optimistic update for variables:",u);o.update(h=>{h.status="pending";h.error=null})}try{const h=yield e(u);o.update(_=>{_.data=h;_.status="success"});if(n){n(h,u,f)}p("mutation","Mutation successful for variables:",u,h)}catch(h){p("mutation","Mutation error for variables:",u,h);o.update(_=>{_.error={message:h.message};_.status="error";if(!s&&f&&f.rollback){p("mutation","Rolling back mutation for variables:",u);f.rollback()}});if(s){s(h,u,f)}}finally{if(!o.value.isSettled){o.update(h=>{h.isSettled=true});if(i){p("mutation","Calling onSettled for variables:",u);i(o.value.data,o.value.error,u,f)}}}});a.mutate=c;a.reset=()=>{o.update(u=>{u.data=null;u.status="idle";u.error=null;u.isSettled=false})};return a}invalidateQueries(e){const t=Array.isArray(e)?e.join(":"):e;p("invalidateQueries","Invalidating query with key:",t);E.delete(t);this._refetchQuery(t)}onCreate(){}connectedCallback(){this._setup({infer:true});this.effect(()=>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 A)){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 A)){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){if(!(e instanceof A)){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}})}_setup(e){if(e.infer===true){Object.keys(this).forEach(t=>{if(typeof this[t]!=="function"&&!t.startsWith("_")){if(this[t]instanceof b){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=null){if(!this._isAllowedType(e)){const n=Object.prototype.toString.call(e);throw new Error(`[Cami.js] The type ${n} of initialValue is not allowed in observables.`)}const s=new A(e);this._registerObservables(s);return s}_refetchQuery(e){p("_refetchQuery","Refetching query with key:",e);const t=this._queryFunctions.get(e);if(t){p("_refetchQuery","Found query function for key:",e);const s=E.get(e)||{data:void 0,status:"idle",error:null};E.set(e,ge(C({},s),{status:"pending",error:null}));t().then(n=>{E.set(e,{data:n,status:"success",error:null,lastUpdated:Date.now()});p("_refetchQuery","Refetch successful for key:",e,n)}).catch(n=>{if(s.data!==void 0){p("_refetchQuery","Rolling back refetch for key:",e);E.set(e,s)}E.set(e,ge(C({},s),{status:"error",error:n}))}).finally(()=>{this.query({queryKey:e,queryFn:t});p("_refetchQuery","Refetch complete for key:",e)})}}_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 A)){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();Ce(e,this)}};var _e=class extends w{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 w(s=>{const n=i=>{s.next(i)};this.element.addEventListener(e,n,t);return()=>{this.element.removeEventListener(e,n,t)}})}};var me=class extends w{constructor(){super(...arguments);Be(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 y=r=>{if(typeof r==="string"){return y.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()}})};y.get=(r,e={})=>{e.url=r;e.method="GET";return y(e)};y.post=(r,e={},t={})=>{t.url=r;t.data=e;t.method="POST";return y(t)};y.put=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PUT";return y(t)};y.patch=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PATCH";return y(t)};y.delete=(r,e={})=>{e.url=r;e.method="DELETE";return y(e)};y.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:Zt,events:Yt}=B;return Ct(Kt);})(); +\f\r"'\`<>=]|("|')|))|$)`,"g");var Ge=/'/g;var Ze=/"/g;var st=/^(?:script|style|textarea|title)$/i;var nt=r=>(e,...t)=>({_$litType$:r,strings:e,values:t});var Pe=nt(1);var it=nt(2);var Z=Symbol.for("lit-noChange");var d=Symbol.for("lit-nothing");var Ye=new WeakMap;var M=I.createTreeWalker(I,129);function ot(r,e){if(!Array.isArray(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==Qe?Qe.createHTML(e):e}var Dt=(r,e)=>{const t=r.length-1,s=[];let n,i=2===e?"":"",o=Q;for(let a=0;a"===f[0]?(o=n!=null?n:Q,l=-1):void 0===f[1]?l=-2:(l=o.lastIndex-f[2].length,u=f[1],o=void 0===f[3]?N:'"'===f[3]?Ze:Ge):o===Ze||o===Ge?o=N:o===Je||o===Xe?o=Q:(o=N,n=void 0);const _=o===N&&r[a+1].startsWith("/>")?" ":"";i+=o===Q?c+Tt:l>=0?(s.push(u),c.slice(0,l)+et+c.slice(l)+T+_):c+T+(-2===l?a:_)}return[ot(r,i+(r[t]||"")+(2===e?"":"")),s]};var Y=class r{constructor({strings:e,_$litType$:t},s){let n;this.parts=[];let i=0,o=0;const a=e.length-1,c=this.parts,[u,f]=Dt(e,t);if(this.el=r.createElement(u,s),M.currentNode=this.el.content,2===t){const l=this.el.content.firstChild;l.replaceWith(...l.childNodes)}for(;null!==(n=M.nextNode())&&c.length0){n.textContent=ne?ne.emptyScript:"";for(let _=0;_2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=d}_$AI(e,t=this,s,n){const i=this.strings;let o=false;if(void 0===i)e=L(this,e,t,0),o=!G(e)||e!==this._$AH&&e!==Z,o&&(this._$AH=e);else{const a=e;let c,u;for(e=i[0],c=0;c{var i,o;const s=(i=t==null?void 0:t.renderBefore)!=null?i:e;let n=s._$litPart$;if(void 0===n){const a=(o=t==null?void 0:t.renderBefore)!=null?o:null;s._$litPart$=n=new K(e.insertBefore(X(),a),a,void 0,t!=null?t:{})}return n._$AI(r),n};var Nt={data:""};var Mt=r=>"object"==typeof window?((r?r.querySelector("#_goober"):window._goober)||Object.assign((r||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:r||Nt;var It=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g;var zt=/\/\*[^]*?\*\/| +/g;var at=/\n+/g;var z=(r,e)=>{let t="",s="",n="";for(let i in r){let o=r[i];"@"==i[0]?"i"==i[1]?t=i+" "+o+";":s+="f"==i[1]?z(o,i):i+"{"+z(o,"k"==i[1]?"":e)+"}":"object"==typeof o?s+=z(o,e?e.replace(/([^,])+/g,a=>i.replace(/(^:.*)|([^,])+/g,c=>/&/.test(c)?c.replace(/&/g,a):a?a+" "+c:c)):i):null!=o&&(i=/^--/.test(i)?i:i.replace(/[A-Z]/g,"-$&").toLowerCase(),n+=z.p?z.p(i,o):i+":"+o+";")}return t+(e&&n?e+"{"+n+"}":n)+s};var P={};var ct=r=>{if("object"==typeof r){let e="";for(let t in r)e+=t+ct(r[t]);return e}return r};var Ft=(r,e,t,s,n)=>{let i=ct(r),o=P[i]||(P[i]=(c=>{let u=0,f=11;for(;u>>0;return"go"+f})(i));if(!P[o]){let c=i!==r?r:(u=>{let f,l,h=[{}];for(;f=It.exec(u.replace(zt,""));)f[4]?h.shift():f[3]?(l=f[3].replace(at," ").trim(),h.unshift(h[0][l]=h[0][l]||{})):h[0][f[1]]=f[2].replace(at," ").trim();return h[0]})(r);P[o]=z(n?{["@keyframes "+o]:c}:c,t?"":"."+o)}let a=t&&P.g?P.g:null;return t&&(P.g=P[o]),((c,u,f,l)=>{l?u.data=u.data.replace(l,c):-1===u.data.indexOf(c)&&(u.data=f?c+u.data:u.data+c)})(P[o],e,s,a),o};var Ht=(r,e,t)=>r.reduce((s,n,i)=>{let o=e[i];if(o&&o.call){let a=o(t),c=a&&a.props&&a.props.className||/^go/.test(a)&&a;o=c?"."+c:a&&"object"==typeof a?a.props?"":z(a,""):false===a?"":a}return s+n+(null==o?"":o)},"");function ie(r){let e=this||{},t=r.call?r(e.p):r;return Ft(t.unshift?t.raw?Ht(t,[].slice.call(arguments,1),e.p):t.reduce((s,n)=>Object.assign(s,n&&n.call?n(e.p):n),{}):t,Mt(e.target),e.g,e.o,e.k)}var rr=ie.bind({g:1});var sr=ie.bind({k:1});var dt=Symbol.for("immer-nothing");var ut=Symbol.for("immer-draftable");var g=Symbol.for("immer-state");var Ut=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.","Immer forbids 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 an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(r){return`'original' expects a draft, got: ${r}`}]:[];function m(r,...e){if(true){const t=Ut[r];const s=typeof t==="function"?t.apply(null,e):t;throw new Error(`[Immer] ${s}`)}throw new Error(`[Immer] minified error nr: ${r}. Full error at: https://bit.ly/3cXEKWf`)}var q=Object.getPrototypeOf;function W(r){return!!r&&!!r[g]}function H(r){var e;if(!r)return false;return _t(r)||Array.isArray(r)||!!r[ut]||!!((e=r.constructor)==null?void 0:e[ut])||ue(r)||le(r)}var Rt=Object.prototype.constructor.toString();function _t(r){if(!r||typeof r!=="object")return false;const e=q(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)===Rt}function ee(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[g];return e?e.type_:Array.isArray(r)?1:ue(r)?2:le(r)?3:0}function De(r,e){return ce(r)===2?r.has(e):Object.prototype.hasOwnProperty.call(r,e)}function mt(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 kt(r,e){if(r===e){return r!==0||1/r===1/e}else{return r!==r&&e!==e}}function ue(r){return r instanceof Map}function le(r){return r instanceof Set}function F(r){return r.copy_||r.base_}function Ne(r,e){if(ue(r)){return new Map(r)}if(le(r)){return new Set(r)}if(Array.isArray(r))return Array.prototype.slice.call(r);if(!e&&_t(r)){if(!q(r)){const n=Object.create(null);return Object.assign(n,r)}return C({},r)}const t=Object.getOwnPropertyDescriptors(r);delete t[g];let s=Reflect.ownKeys(t);for(let n=0;n1){r.set=r.add=r.clear=r.delete=Lt}Object.freeze(r);if(e)ee(r,(t,s)=>He(s,true),true);return r}function Lt(){m(2)}function fe(r){return Object.isFrozen(r)}var Vt={};function U(r){const e=Vt[r];if(!e){m(0,r)}return e}var te;function bt(){return te}function qt(r,e){return{drafts_:[],parent_:r,immer_:e,canAutoFreeze_:true,unfinalizedDrafts_:0}}function lt(r,e){if(e){U("Patches");r.patches_=[];r.inversePatches_=[];r.patchListener_=e}}function Me(r){Ie(r);r.drafts_.forEach(Wt);r.drafts_=null}function Ie(r){if(r===te){te=r.parent_}}function ft(r){return te=qt(te,r)}function Wt(r){const e=r[g];if(e.type_===0||e.type_===1)e.revoke_();else e.revoked_=true}function ht(r,e){e.unfinalizedDrafts_=e.drafts_.length;const t=e.drafts_[0];const s=r!==void 0&&r!==t;if(s){if(t[g].modified_){Me(e);m(4)}if(H(r)){r=oe(e,r);if(!e.parent_)ae(e,r)}if(e.patches_){U("Patches").generateReplacementPatches_(t[g].base_,r,e.patches_,e.inversePatches_)}}else{r=oe(e,t,[])}Me(e);if(e.patches_){e.patchListener_(e.patches_,e.inversePatches_)}return r!==dt?r:void 0}function oe(r,e,t){if(fe(e))return e;const s=e[g];if(!s){ee(e,(n,i)=>pt(r,s,e,n,i,t),true);return e}if(s.scope_!==r)return e;if(!s.modified_){ae(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}ee(i,(a,c)=>pt(r,s,n,a,c,t,o));ae(r,n,false);if(t&&r.patches_){U("Patches").generatePatches_(s,t,r.patches_,r.inversePatches_)}}return s.copy_}function pt(r,e,t,s,n,i,o){if(n===t)m(5);if(W(n)){const a=i&&e&&e.type_!==3&&!De(e.assigned_,s)?i.concat(s):void 0;const c=oe(r,n,a);mt(t,s,c);if(W(c)){r.canAutoFreeze_=false}else return}else if(o){t.add(n)}if(H(n)&&!fe(n)){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1){return}oe(r,n);if(!e||!e.scope_.parent_)ae(r,n)}}function ae(r,e,t=false){if(!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_){He(e,t)}}function Bt(r,e){const t=Array.isArray(r);const s={type_:t?1:0,scope_:e?e.scope_:bt(),modified_:false,finalized_:false,assigned_:{},parent_:e,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:false};let n=s;let i=Ue;if(t){n=[s];i=re}const{revoke:o,proxy:a}=Proxy.revocable(n,i);s.draft_=a;s.revoke_=o;return a}var Ue={get(r,e){if(e===g)return r;const t=F(r);if(!De(t,e)){return Qt(r,t,e)}const s=t[e];if(r.finalized_||!H(s)){return s}if(s===Te(r.base_,e)){je(r);return r.copy_[e]=Fe(s,r)}return s},has(r,e){return e in F(r)},ownKeys(r){return Reflect.ownKeys(F(r))},set(r,e,t){const s=yt(F(r),e);if(s==null?void 0:s.set){s.set.call(r.draft_,t);return true}if(!r.modified_){const n=Te(F(r),e);const i=n==null?void 0:n[g];if(i&&i.base_===t){r.copy_[e]=t;r.assigned_[e]=false;return true}if(kt(t,n)&&(t!==void 0||De(r.base_,e)))return true;je(r);ze(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(Te(r.base_,e)!==void 0||e in r.base_){r.assigned_[e]=false;je(r);ze(r)}else{delete r.assigned_[e]}if(r.copy_){delete r.copy_[e]}return true},getOwnPropertyDescriptor(r,e){const t=F(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(){m(11)},getPrototypeOf(r){return q(r.base_)},setPrototypeOf(){m(12)}};var re={};ee(Ue,(r,e)=>{re[r]=function(){arguments[0]=arguments[0][0];return e.apply(this,arguments)}});re.deleteProperty=function(r,e){if(isNaN(parseInt(e)))m(13);return re.set.call(this,r,e,void 0)};re.set=function(r,e,t){if(e!=="length"&&isNaN(parseInt(e)))m(14);return Ue.set.call(this,r[0],e,t,r[0])};function Te(r,e){const t=r[g];const s=t?F(t):r;return s[e]}function Qt(r,e,t){var n;const s=yt(e,t);return s?`value`in s?s.value:(n=s.get)==null?void 0:n.call(r.draft_):void 0}function yt(r,e){if(!(e in r))return void 0;let t=q(r);while(t){const s=Object.getOwnPropertyDescriptor(t,e);if(s)return s;t=q(t)}return void 0}function ze(r){if(!r.modified_){r.modified_=true;if(r.parent_){ze(r.parent_)}}}function je(r){if(!r.copy_){r.copy_=Ne(r.base_,r.scope_.immer_.useStrictShallowCopy_)}}var Jt=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 a(c=i,...u){return o.produce(c,f=>t.call(this,f,...u))}}if(typeof t!=="function")m(6);if(s!==void 0&&typeof s!=="function")m(7);let n;if(H(e)){const i=ft(this);const o=Fe(e,void 0);let a=true;try{n=t(o);a=false}finally{if(a)Me(i);else Ie(i)}lt(i,s);return ht(n,i)}else if(!e||typeof e!=="object"){n=t(e);if(n===void 0)n=e;if(n===dt)n=void 0;if(this.autoFreeze_)He(n,true);if(s){const i=[];const o=[];U("Patches").generateReplacementPatches_(e,n,i,o);s(i,o)}return n}else m(1,e)};this.produceWithPatches=(e,t)=>{if(typeof e==="function"){return(o,...a)=>this.produceWithPatches(o,c=>e(c,...a))}let s,n;const i=this.produce(e,t,(o,a)=>{s=o;n=a});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(!H(r))m(8);if(W(r))r=Xt(r);const e=ft(this);const t=Fe(r,void 0);t[g].isManual_=true;Ie(e);return t}finishDraft(r,e){const t=r&&r[g];if(!t||!t.isManual_)m(9);const{scope_:s}=t;lt(s,e);return ht(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=U("Patches").applyPatches_;if(W(r)){return s(r,e)}return this.produce(r,n=>s(n,e))}};function Fe(r,e){const t=ue(r)?U("MapSet").proxyMap_(r,e):le(r)?U("MapSet").proxySet_(r,e):Bt(r,e);const s=e?e.scope_:bt();s.drafts_.push(t);return t}function Xt(r){if(!W(r))m(10,r);return gt(r)}function gt(r){if(!H(r)||fe(r))return r;const e=r[g];let t;if(e){if(!e.modified_)return e.base_;e.finalized_=true;t=Ne(r,e.scope_.immer_.useStrictShallowCopy_)}else{t=Ne(r,true)}ee(t,(s,n)=>{mt(t,s,gt(n))});if(e){e.finalized_=false}return t}var v=new Jt;var R=v.produce;var ir=v.produceWithPatches.bind(v);var or=v.setAutoFreeze.bind(v);var ar=v.setUseStrictShallowCopy.bind(v);var cr=v.applyPatches.bind(v);var ur=v.createDraft.bind(v);var lr=v.finishDraft.bind(v);var Re=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 b=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 Re(n);let o=()=>{};try{o=this.subscribeCallback(i)}catch(a){if(i.error){i.error(a)}else{console.error("[Cami.js] Error in Subscriber:",a)}return}i.addTeardown(o);this._observers.push(i);return{unsubscribe:()=>i.unsubscribe(),complete:()=>i.complete(),error:a=>i.error(a)}}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=class extends b{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();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)}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)}}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);this.state=R(this.state,n=>{s(n,t)});this._observers.forEach(n=>n.next(this.state));if(this.devTools){this.devTools.send(e,this.state)}}};var Gt=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 a=new r(e);a.init=()=>{if(n){const c=localStorage.getItem(s);const u=localStorage.getItem(`${s}-expiry`);const f=new Date().getTime();if(c&&u){const l=f>=parseInt(u,10);if(!l){a.state=JSON.parse(c)}else{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`)}}}};a.init();a.reset=()=>{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`);a.state=e;a._observers.forEach(c=>c.next(a.state))};a.subscribe(c=>{const u=new Date().getTime();const f=u+o;localStorage.setItem(s,JSON.stringify(c));localStorage.setItem(`${s}-expiry`,f.toString())});return a}};var vt=(r,e={})=>{const t={localStorage:true,name:"cami-store",expiry:864e5};const s=C(C({},t),e);if(s.localStorage){const n=Gt(j)(r,s);return n}else{return new j(r)}};var w=class r extends b{static from(e){if(e instanceof b){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=ve(e),i,o,a;i=!(o=yield n.next()).done;i=false){const c=o.value;if(s)return;t.next(c)}}catch(o){a=[o]}finally{try{i&&(o=n.return)&&(yield o.call(n))}finally{if(a)throw a[0]}}t.complete()}catch(c){t.error(c)}}))();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:a=>{i=e(i,a)},error:a=>n(a),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 a=o.subscribe({next:c=>t.next(c),error:c=>t.error(c),complete:()=>{s.delete(a);if(s.size===0){t.complete()}}});s.add(a)},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:a=>t.next(a),error:a=>t.error(a),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 A(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 b){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=ve(e),s,n,i;s=!(n=yield t.next()).done;s=false){const o=n.value;this._observers.forEach(a=>a.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(a=>a.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:a=>{if(!n){n=true;const c=e(a);s=c.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(a)}},error:a=>t.error(a),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:a=>{s[o]=a;if(!s.includes(void 0)){t.next([...s])}},error:a=>t.error(a),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 B={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 p(r,...e){if(B.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={current:null};var A=class extends b{constructor(e=null,t=null,{last:s=false,name:n=null}={}){super();if(s){this._lastObserver=t}else{this._observers.push(t)}this._value=R(e,i=>{});this._pendingUpdates=[];this._updateScheduled=false;this._name=n}get value(){if(D.current!=null){D.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=R(this._value,t)}else{this._value=t(this._value)}}if(e!==this._value){this._notifyObservers();if(B.events.isEnabled&&typeof window!=="undefined"){const t=new CustomEvent("cami:state:change",{detail:{name:this._name,oldValue:e,newValue:this._value}});window.dispatchEvent(t)}p("cami:state:change",this._name,e,this._value)}this._updateScheduled=false}toStream(){const e=new w;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 ke=class extends A{constructor(e){super(null);this.computeFn=e;this.dependencies=new Set;this.subscriptions=new Map;this._compute()}get value(){if(D.current){D.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)}}};D.current=e;const t=this.computeFn();D.current=null;if(t!==this._value){this._value=t;this._notifyObservers()}}dispose(){this.subscriptions.forEach(e=>{e.unsubscribe()})}};var he=function(r){return new ke(r)};var pe=function(r){let e=()=>{};let t=new Set;let s=new Map;const n={addDependency:a=>{if(!t.has(a)){const c=a.onValue(i);t.add(a);s.set(a,c)}}};const i=()=>{e();D.current=n;e=r()||(()=>{});D.current=null};if(typeof window!=="undefined"){requestAnimationFrame(i)}else{setTimeout(i,0)}const o=()=>{s.forEach(a=>{a.unsubscribe()});e()};return o};var E=new Map;var de=class extends HTMLElement{constructor(){super();this.onCreate();this._unsubscribers=new Map;this._computed=he.bind(this);this.effect=pe.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:a=>a;n=R(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 j)){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 w(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:a=null,gcTime:c=1e3*60*5,retry:u=3,retryDelay:f=l=>Math.pow(2,l)*1e3}){const l=Array.isArray(e)?e.map(x=>typeof x==="object"?JSON.stringify(x):x).join(":"):e;this._queryFunctions.set(l,t);p("query","Starting query with key:",l);const h=this._observable({data:null,status:"pending",fetchStatus:"idle",error:null,lastUpdated:E.has(l)?E.get(l).lastUpdated:null},l);const _=this._observableProxy(h);const $=(x=0)=>k(this,null,function*(){const Le=Date.now();const be=E.get(l);if(be&&Le-be.lastUpdated{S.data=be.data;S.status="success";S.fetchStatus="idle"})}else{p("fetchData (else)","Fetching data for key:",l);try{h.update(O=>{O.status="pending";O.fetchStatus="fetching"});const S=yield t();E.set(l,{data:S,lastUpdated:Le});h.update(O=>{O.data=S;O.status="success";O.fetchStatus="idle"})}catch(S){p("fetchData (catch)","Fetch error for key:",l,S);if(x$(x+1),f(x))}else{h.update(O=>{O.error={message:S.message};O.status="error";O.fetchStatus="idle"})}}}});if(i){p("query","Setting up refetch on mount for key:",l);$()}if(n){p("query","Setting up refetch on window focus for key:",l);const x=()=>$();window.addEventListener("focus",x);this._unsubscribers.set(`focus:${l}`,()=>window.removeEventListener("focus",x))}if(o){p("query","Setting up refetch on reconnect for key:",l);window.addEventListener("online",$);this._unsubscribers.set(`online:${l}`,()=>window.removeEventListener("online",$))}if(a){p("query","Setting up refetch interval for key:",l);const x=setInterval($,a);this._unsubscribers.set(`interval:${l}`,()=>clearInterval(x))}const wt=setTimeout(()=>{E.delete(l)},c);this._unsubscribers.set(`gc:${l}`,()=>clearTimeout(wt));return _}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 a=this._observableProxy(o);const c=u=>k(this,null,function*(){p("mutation","Starting mutation for variables:",u);let f;const l=o.value;if(t){p("mutation","Performing optimistic update for variables:",u);f=t(u,l);o.update(h=>{h.data=f.optimisticData;h.status="pending";h.error=null})}else{p("mutation","Performing mutation without optimistic update for variables:",u);o.update(h=>{h.status="pending";h.error=null})}try{const h=yield e(u);o.update(_=>{_.data=h;_.status="success"});if(n){n(h,u,f)}p("mutation","Mutation successful for variables:",u,h)}catch(h){p("mutation","Mutation error for variables:",u,h);o.update(_=>{_.error={message:h.message};_.status="error";if(!s&&f&&f.rollback){p("mutation","Rolling back mutation for variables:",u);f.rollback()}});if(s){s(h,u,f)}}finally{if(!o.value.isSettled){o.update(h=>{h.isSettled=true});if(i){p("mutation","Calling onSettled for variables:",u);i(o.value.data,o.value.error,u,f)}}}});a.mutate=c;a.reset=()=>{o.update(u=>{u.data=null;u.status="idle";u.error=null;u.isSettled=false})};return a}invalidateQueries(e){const t=Array.isArray(e)?e.join(":"):e;p("invalidateQueries","Invalidating query with key:",t);E.delete(t);this._refetchQuery(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 A)){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 A)){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){if(!(e instanceof A)){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}})}_setup(e){if(e.infer===true){Object.keys(this).forEach(t=>{if(typeof this[t]!=="function"&&!t.startsWith("_")){if(this[t]instanceof b){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=null){if(!this._isAllowedType(e)){const n=Object.prototype.toString.call(e);throw new Error(`[Cami.js] The type ${n} of initialValue is not allowed in observables.`)}const s=new A(e);this._registerObservables(s);return s}_refetchQuery(e){p("_refetchQuery","Refetching query with key:",e);const t=this._queryFunctions.get(e);if(t){p("_refetchQuery","Found query function for key:",e);const s=E.get(e)||{data:void 0,status:"idle",error:null};E.set(e,ge(C({},s),{status:"pending",error:null}));t().then(n=>{E.set(e,{data:n,status:"success",error:null,lastUpdated:Date.now()});p("_refetchQuery","Refetch successful for key:",e,n)}).catch(n=>{if(s.data!==void 0){p("_refetchQuery","Rolling back refetch for key:",e);E.set(e,s)}E.set(e,ge(C({},s),{status:"error",error:n}))}).finally(()=>{this.query({queryKey:e,queryFn:t});p("_refetchQuery","Refetch complete for key:",e)})}}_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 A)){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();Ce(e,this)}};var _e=class extends w{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 w(s=>{const n=i=>{s.next(i)};this.element.addEventListener(e,n,t);return()=>{this.element.removeEventListener(e,n,t)}})}};var me=class extends w{constructor(){super(...arguments);Be(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 y=r=>{if(typeof r==="string"){return y.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()}})};y.get=(r,e={})=>{e.url=r;e.method="GET";return y(e)};y.post=(r,e={},t={})=>{t.url=r;t.data=e;t.method="POST";return y(t)};y.put=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PUT";return y(t)};y.patch=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PATCH";return y(t)};y.delete=(r,e={})=>{e.url=r;e.method="DELETE";return y(e)};y.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:Zt,events:Yt}=B;return Ct(Kt);})(); /** * @license * Copyright (c) 2023 Kenn Costales diff --git a/build/cami.cdn.js.map b/build/cami.cdn.js.map index 99de1a47..0d4dd402 100644 --- a/build/cami.cdn.js.map +++ b/build/cami.cdn.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../src/cami.js", "../node_modules/lit-html/src/lit-html.ts", "../node_modules/goober/dist/goober.modern.js", "../node_modules/immer/src/utils/env.ts", "../node_modules/immer/src/utils/errors.ts", "../node_modules/immer/src/utils/common.ts", "../node_modules/immer/src/utils/plugins.ts", "../node_modules/immer/src/core/scope.ts", "../node_modules/immer/src/core/finalize.ts", "../node_modules/immer/src/core/proxy.ts", "../node_modules/immer/src/core/immerClass.ts", "../node_modules/immer/src/core/current.ts", "../node_modules/immer/src/plugins/patches.ts", "../node_modules/immer/src/plugins/mapset.ts", "../node_modules/immer/src/immer.ts", "../src/observables/observable.js", "../src/observables/observable-store.js", "../src/observables/observable-stream.js", "../src/config.js", "../src/trace.js", "../src/observables/observable-state.js", "../src/reactive-element.js", "../src/observables/observable-element.js", "../src/http.js"], - "sourcesContent": ["/**\n * @license\n * Copyright (c) 2023 Kenn Costales\n * MIT License\n */\n\n/**\n * @module cami\n */\nimport { html, render, svg } from 'lit-html';\nimport { css } from 'goober';\nimport { produce } from \"immer\"\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 'lit-html'\n * @exports svg - The svg function from 'lit-html'\n * @exports css - The css function from 'goober'\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, css, ReactiveElement, ObservableStream, ObservableElement, Observable, ObservableState, ObservableStore, http, debug, events, computed, effect };\n", "/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n// IMPORTANT: these imports must be type-only\nimport type {Directive, DirectiveResult, PartInfo} from './directive.js';\n\nconst DEV_MODE = true;\nconst ENABLE_EXTRA_SECURITY_HOOKS = true;\nconst ENABLE_SHADYDOM_NOPATCH = true;\nconst NODE_MODE = false;\n\n// Allows minifiers to rename references to globalThis\nconst global = globalThis;\n\n/**\n * Contains types that are part of the unstable debug API.\n *\n * Everything in this API is not stable and may change or be removed in the future,\n * even on patch releases.\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace LitUnstable {\n /**\n * When Lit is running in dev mode and `window.emitLitDebugLogEvents` is true,\n * we will emit 'lit-debug' events to window, with live details about the update and render\n * lifecycle. These can be useful for writing debug tooling and visualizations.\n *\n * Please be aware that running with window.emitLitDebugLogEvents has performance overhead,\n * making certain operations that are normally very cheap (like a no-op render) much slower,\n * because we must copy data and dispatch events.\n */\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace DebugLog {\n export type Entry =\n | TemplatePrep\n | TemplateInstantiated\n | TemplateInstantiatedAndUpdated\n | TemplateUpdating\n | BeginRender\n | EndRender\n | CommitPartEntry\n | SetPartValue;\n export interface TemplatePrep {\n kind: 'template prep';\n template: Template;\n strings: TemplateStringsArray;\n clonableTemplate: HTMLTemplateElement;\n parts: TemplatePart[];\n }\n export interface BeginRender {\n kind: 'begin render';\n id: number;\n value: unknown;\n container: HTMLElement | DocumentFragment;\n options: RenderOptions | undefined;\n part: ChildPart | undefined;\n }\n export interface EndRender {\n kind: 'end render';\n id: number;\n value: unknown;\n container: HTMLElement | DocumentFragment;\n options: RenderOptions | undefined;\n part: ChildPart;\n }\n export interface TemplateInstantiated {\n kind: 'template instantiated';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n fragment: Node;\n parts: Array;\n values: unknown[];\n }\n export interface TemplateInstantiatedAndUpdated {\n kind: 'template instantiated and updated';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n fragment: Node;\n parts: Array;\n values: unknown[];\n }\n export interface TemplateUpdating {\n kind: 'template updating';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n parts: Array;\n values: unknown[];\n }\n export interface SetPartValue {\n kind: 'set part';\n part: Part;\n value: unknown;\n valueIndex: number;\n values: unknown[];\n templateInstance: TemplateInstance;\n }\n\n export type CommitPartEntry =\n | CommitNothingToChildEntry\n | CommitText\n | CommitNode\n | CommitAttribute\n | CommitProperty\n | CommitBooleanAttribute\n | CommitEventListener\n | CommitToElementBinding;\n\n export interface CommitNothingToChildEntry {\n kind: 'commit nothing to child';\n start: ChildNode;\n end: ChildNode | null;\n parent: Disconnectable | undefined;\n options: RenderOptions | undefined;\n }\n\n export interface CommitText {\n kind: 'commit text';\n node: Text;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitNode {\n kind: 'commit node';\n start: Node;\n parent: Disconnectable | undefined;\n value: Node;\n options: RenderOptions | undefined;\n }\n\n export interface CommitAttribute {\n kind: 'commit attribute';\n element: Element;\n name: string;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitProperty {\n kind: 'commit property';\n element: Element;\n name: string;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitBooleanAttribute {\n kind: 'commit boolean attribute';\n element: Element;\n name: string;\n value: boolean;\n options: RenderOptions | undefined;\n }\n\n export interface CommitEventListener {\n kind: 'commit event listener';\n element: Element;\n name: string;\n value: unknown;\n oldListener: unknown;\n options: RenderOptions | undefined;\n // True if we're removing the old event listener (e.g. because settings changed, or value is nothing)\n removeListener: boolean;\n // True if we're adding a new event listener (e.g. because first render, or settings changed)\n addListener: boolean;\n }\n\n export interface CommitToElementBinding {\n kind: 'commit to element binding';\n element: Element;\n value: unknown;\n options: RenderOptions | undefined;\n }\n }\n}\n\ninterface DebugLoggingWindow {\n // Even in dev mode, we generally don't want to emit these events, as that's\n // another level of cost, so only emit them when DEV_MODE is true _and_ when\n // window.emitLitDebugEvents is true.\n emitLitDebugLogEvents?: boolean;\n}\n\n/**\n * Useful for visualizing and logging insights into what the Lit template system is doing.\n *\n * Compiled out of prod mode builds.\n */\nconst debugLogEvent = DEV_MODE\n ? (event: LitUnstable.DebugLog.Entry) => {\n const shouldEmit = (global as unknown as DebugLoggingWindow)\n .emitLitDebugLogEvents;\n if (!shouldEmit) {\n return;\n }\n global.dispatchEvent(\n new CustomEvent('lit-debug', {\n detail: event,\n })\n );\n }\n : undefined;\n// Used for connecting beginRender and endRender events when there are nested\n// renders when errors are thrown preventing an endRender event from being\n// called.\nlet debugLogRenderId = 0;\n\nlet issueWarning: (code: string, warning: string) => void;\n\nif (DEV_MODE) {\n global.litIssuedWarnings ??= new Set();\n\n // Issue a warning, if we haven't already.\n issueWarning = (code: string, warning: string) => {\n warning += code\n ? ` See https://lit.dev/msg/${code} for more information.`\n : '';\n if (!global.litIssuedWarnings!.has(warning)) {\n console.warn(warning);\n global.litIssuedWarnings!.add(warning);\n }\n };\n\n issueWarning(\n 'dev-mode',\n `Lit is in dev mode. Not recommended for production!`\n );\n}\n\nconst wrap =\n ENABLE_SHADYDOM_NOPATCH &&\n global.ShadyDOM?.inUse &&\n global.ShadyDOM?.noPatch === true\n ? (global.ShadyDOM!.wrap as (node: T) => T)\n : (node: T) => node;\n\nconst trustedTypes = (global as unknown as Window).trustedTypes;\n\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('lit-html', {\n createHTML: (s) => s,\n })\n : undefined;\n\n/**\n * Used to sanitize any value before it is written into the DOM. This can be\n * used to implement a security policy of allowed and disallowed values in\n * order to prevent XSS attacks.\n *\n * One way of using this callback would be to check attributes and properties\n * against a list of high risk fields, and require that values written to such\n * fields be instances of a class which is safe by construction. Closure's Safe\n * HTML Types is one implementation of this technique (\n * https://github.com/google/safe-html-types/blob/master/doc/safehtml-types.md).\n * The TrustedTypes polyfill in API-only mode could also be used as a basis\n * for this technique (https://github.com/WICG/trusted-types).\n *\n * @param node The HTML node (usually either a #text node or an Element) that\n * is being written to. Note that this is just an exemplar node, the write\n * may take place against another instance of the same class of node.\n * @param name The name of an attribute or property (for example, 'href').\n * @param type Indicates whether the write that's about to be performed will\n * be to a property or a node.\n * @return A function that will sanitize this class of writes.\n */\nexport type SanitizerFactory = (\n node: Node,\n name: string,\n type: 'property' | 'attribute'\n) => ValueSanitizer;\n\n/**\n * A function which can sanitize values that will be written to a specific kind\n * of DOM sink.\n *\n * See SanitizerFactory.\n *\n * @param value The value to sanitize. Will be the actual value passed into\n * the lit-html template literal, so this could be of any type.\n * @return The value to write to the DOM. Usually the same as the input value,\n * unless sanitization is needed.\n */\nexport type ValueSanitizer = (value: unknown) => unknown;\n\nconst identityFunction: ValueSanitizer = (value: unknown) => value;\nconst noopSanitizer: SanitizerFactory = (\n _node: Node,\n _name: string,\n _type: 'property' | 'attribute'\n) => identityFunction;\n\n/** Sets the global sanitizer factory. */\nconst setSanitizer = (newSanitizer: SanitizerFactory) => {\n if (!ENABLE_EXTRA_SECURITY_HOOKS) {\n return;\n }\n if (sanitizerFactoryInternal !== noopSanitizer) {\n throw new Error(\n `Attempted to overwrite existing lit-html security policy.` +\n ` setSanitizeDOMValueFactory should be called at most once.`\n );\n }\n sanitizerFactoryInternal = newSanitizer;\n};\n\n/**\n * Only used in internal tests, not a part of the public API.\n */\nconst _testOnlyClearSanitizerFactoryDoNotCallOrElse = () => {\n sanitizerFactoryInternal = noopSanitizer;\n};\n\nconst createSanitizer: SanitizerFactory = (node, name, type) => {\n return sanitizerFactoryInternal(node, name, type);\n};\n\n// Added to an attribute name to mark the attribute as bound so we can find\n// it easily.\nconst boundAttributeSuffix = '$lit$';\n\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 = `lit$${String(Math.random()).slice(9)}$`;\n\n// String used to tell if a comment is a marker comment\nconst markerMatch = '?' + marker;\n\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}>`;\n\nconst d =\n NODE_MODE && global.document === undefined\n ? ({\n createTreeWalker() {\n return {};\n },\n } as unknown as Document)\n : document;\n\n// Creates a dynamic marker. We never have to search for these in the DOM.\nconst createMarker = () => d.createComment('');\n\n// https://tc39.github.io/ecma262/#sec-typeof-operator\ntype Primitive = null | undefined | boolean | number | string | symbol | bigint;\nconst isPrimitive = (value: unknown): value is Primitive =>\n value === null || (typeof value != 'object' && typeof value != 'function');\nconst isArray = Array.isArray;\nconst isIterable = (value: unknown): value is Iterable =>\n isArray(value) ||\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (value as any)?.[Symbol.iterator] === 'function';\n\nconst SPACE_CHAR = `[ \\t\\n\\f\\r]`;\nconst ATTR_VALUE_CHAR = `[^ \\t\\n\\f\\r\"'\\`<>=]`;\nconst NAME_CHAR = `[^\\\\s\"'>=/]`;\n\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/**\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;\n\nconst commentEndRegex = /-->/g;\n/**\n * Comments not started with /g;\n/**\n * Comments not started with /g;var Be=/>/g;var D=RegExp(`>|${_e}(?:([^\\s"'>=/]+)(${_e}*=${_e}*(?:[^ -\f\r"'\`<>=]|("|')|))|$)`,"g");var Qe=/'/g;var Je=/"/g;var et=/^(?:script|style|textarea|title)$/i;var tt=r=>(e,...t)=>({_$litType$:r,strings:e,values:t});var rt=tt(1);var Et=tt(2);var Z=Symbol.for("lit-noChange");var d=Symbol.for("lit-nothing");var Xe=new WeakMap;var N=M.createTreeWalker(M,129);function st(r,e){if(!Array.isArray(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==qe?qe.createHTML(e):e}var Ot=(r,e)=>{const t=r.length-1,s=[];let n,i=2===e?"":"",o=Q;for(let a=0;a"===f[0]?(o=n!=null?n:Q,l=-1):void 0===f[1]?l=-2:(l=o.lastIndex-f[2].length,u=f[1],o=void 0===f[3]?D:'"'===f[3]?Je:Qe):o===Je||o===Qe?o=D:o===We||o===Be?o=Q:(o=D,n=void 0);const _=o===D&&r[a+1].startsWith("/>")?" ":"";i+=o===Q?c+xt:l>=0?(s.push(u),c.slice(0,l)+Ze+c.slice(l)+T+_):c+T+(-2===l?a:_)}return[st(r,i+(r[t]||"")+(2===e?"":"")),s]};var Y=class r{constructor({strings:e,_$litType$:t},s){let n;this.parts=[];let i=0,o=0;const a=e.length-1,c=this.parts,[u,f]=Ot(e,t);if(this.el=r.createElement(u,s),N.currentNode=this.el.content,2===t){const l=this.el.content.firstChild;l.replaceWith(...l.childNodes)}for(;null!==(n=N.nextNode())&&c.length0){n.textContent=se?se.emptyScript:"";for(let _=0;_2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=d}_$AI(e,t=this,s,n){const i=this.strings;let o=false;if(void 0===i)e=L(this,e,t,0),o=!G(e)||e!==this._$AH&&e!==Z,o&&(this._$AH=e);else{const a=e;let c,u;for(e=i[0],c=0;c{var i,o;const s=(i=t==null?void 0:t.renderBefore)!=null?i:e;let n=s._$litPart$;if(void 0===n){const a=(o=t==null?void 0:t.renderBefore)!=null?o:null;s._$litPart$=n=new K(e.insertBefore(X(),a),a,void 0,t!=null?t:{})}return n._$AI(r),n};var St={data:""};var Pt=r=>"object"==typeof window?((r?r.querySelector("#_goober"):window._goober)||Object.assign((r||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:r||St;var Ct=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g;var Tt=/\/\*[^]*?\*\/| +/g;var nt=/\n+/g;var I=(r,e)=>{let t="",s="",n="";for(let i in r){let o=r[i];"@"==i[0]?"i"==i[1]?t=i+" "+o+";":s+="f"==i[1]?I(o,i):i+"{"+I(o,"k"==i[1]?"":e)+"}":"object"==typeof o?s+=I(o,e?e.replace(/([^,])+/g,a=>i.replace(/(^:.*)|([^,])+/g,c=>/&/.test(c)?c.replace(/&/g,a):a?a+" "+c:c)):i):null!=o&&(i=/^--/.test(i)?i:i.replace(/[A-Z]/g,"-$&").toLowerCase(),n+=I.p?I.p(i,o):i+":"+o+";")}return t+(e&&n?e+"{"+n+"}":n)+s};var P={};var it=r=>{if("object"==typeof r){let e="";for(let t in r)e+=t+it(r[t]);return e}return r};var jt=(r,e,t,s,n)=>{let i=it(r),o=P[i]||(P[i]=(c=>{let u=0,f=11;for(;u>>0;return"go"+f})(i));if(!P[o]){let c=i!==r?r:(u=>{let f,l,h=[{}];for(;f=Ct.exec(u.replace(Tt,""));)f[4]?h.shift():f[3]?(l=f[3].replace(nt," ").trim(),h.unshift(h[0][l]=h[0][l]||{})):h[0][f[1]]=f[2].replace(nt," ").trim();return h[0]})(r);P[o]=I(n?{["@keyframes "+o]:c}:c,t?"":"."+o)}let a=t&&P.g?P.g:null;return t&&(P.g=P[o]),((c,u,f,l)=>{l?u.data=u.data.replace(l,c):-1===u.data.indexOf(c)&&(u.data=f?c+u.data:u.data+c)})(P[o],e,s,a),o};var Dt=(r,e,t)=>r.reduce((s,n,i)=>{let o=e[i];if(o&&o.call){let a=o(t),c=a&&a.props&&a.props.className||/^go/.test(a)&&a;o=c?"."+c:a&&"object"==typeof a?a.props?"":I(a,""):false===a?"":a}return s+n+(null==o?"":o)},"");function xe(r){let e=this||{},t=r.call?r(e.p):r;return jt(t.unshift?t.raw?Dt(t,[].slice.call(arguments,1),e.p):t.reduce((s,n)=>Object.assign(s,n&&n.call?n(e.p):n),{}):t,Pt(e.target),e.g,e.o,e.k)}var Jt=xe.bind({g:1});var Xt=xe.bind({k:1});var ft=Symbol.for("immer-nothing");var ot=Symbol.for("immer-draftable");var b=Symbol.for("immer-state");var Nt=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.","Immer forbids 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 an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(r){return`'original' expects a draft, got: ${r}`}]:[];function m(r,...e){if(true){const t=Nt[r];const s=typeof t==="function"?t.apply(null,e):t;throw new Error(`[Immer] ${s}`)}throw new Error(`[Immer] minified error nr: ${r}. Full error at: https://bit.ly/3cXEKWf`)}var q=Object.getPrototypeOf;function W(r){return!!r&&!!r[b]}function F(r){var e;if(!r)return false;return ht(r)||Array.isArray(r)||!!r[ot]||!!((e=r.constructor)==null?void 0:e[ot])||ae(r)||ce(r)}var Mt=Object.prototype.constructor.toString();function ht(r){if(!r||typeof r!=="object")return false;const e=q(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)===Mt}function ee(r,e){if(oe(r)===0){Object.entries(r).forEach(([t,s])=>{e(t,s,r)})}else{r.forEach((t,s)=>e(s,t,r))}}function oe(r){const e=r[b];return e?e.type_:Array.isArray(r)?1:ae(r)?2:ce(r)?3:0}function Oe(r,e){return oe(r)===2?r.has(e):Object.prototype.hasOwnProperty.call(r,e)}function pt(r,e,t){const s=oe(r);if(s===2)r.set(e,t);else if(s===3){r.add(t)}else r[e]=t}function It(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 ce(r){return r instanceof Set}function z(r){return r.copy_||r.base_}function Se(r,e){if(ae(r)){return new Map(r)}if(ce(r)){return new Set(r)}if(Array.isArray(r))return Array.prototype.slice.call(r);if(!e&&ht(r)){if(!q(r)){const n=Object.create(null);return Object.assign(n,r)}return C({},r)}const t=Object.getOwnPropertyDescriptors(r);delete t[b];let s=Reflect.ownKeys(t);for(let n=0;n1){r.set=r.add=r.clear=r.delete=zt}Object.freeze(r);if(e)ee(r,(t,s)=>De(s,true),true);return r}function zt(){m(2)}function ue(r){return Object.isFrozen(r)}var Ft={};function H(r){const e=Ft[r];if(!e){m(0,r)}return e}var te;function dt(){return te}function Ht(r,e){return{drafts_:[],parent_:r,immer_:e,canAutoFreeze_:true,unfinalizedDrafts_:0}}function at(r,e){if(e){H("Patches");r.patches_=[];r.inversePatches_=[];r.patchListener_=e}}function Pe(r){Ce(r);r.drafts_.forEach(Ut);r.drafts_=null}function Ce(r){if(r===te){te=r.parent_}}function ct(r){return te=Ht(te,r)}function Ut(r){const e=r[b];if(e.type_===0||e.type_===1)e.revoke_();else e.revoked_=true}function ut(r,e){e.unfinalizedDrafts_=e.drafts_.length;const t=e.drafts_[0];const s=r!==void 0&&r!==t;if(s){if(t[b].modified_){Pe(e);m(4)}if(F(r)){r=ne(e,r);if(!e.parent_)ie(e,r)}if(e.patches_){H("Patches").generateReplacementPatches_(t[b].base_,r,e.patches_,e.inversePatches_)}}else{r=ne(e,t,[])}Pe(e);if(e.patches_){e.patchListener_(e.patches_,e.inversePatches_)}return r!==ft?r:void 0}function ne(r,e,t){if(ue(e))return e;const s=e[b];if(!s){ee(e,(n,i)=>lt(r,s,e,n,i,t),true);return e}if(s.scope_!==r)return e;if(!s.modified_){ie(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}ee(i,(a,c)=>lt(r,s,n,a,c,t,o));ie(r,n,false);if(t&&r.patches_){H("Patches").generatePatches_(s,t,r.patches_,r.inversePatches_)}}return s.copy_}function lt(r,e,t,s,n,i,o){if(n===t)m(5);if(W(n)){const a=i&&e&&e.type_!==3&&!Oe(e.assigned_,s)?i.concat(s):void 0;const c=ne(r,n,a);pt(t,s,c);if(W(c)){r.canAutoFreeze_=false}else return}else if(o){t.add(n)}if(F(n)&&!ue(n)){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1){return}ne(r,n);if(!e||!e.scope_.parent_)ie(r,n)}}function ie(r,e,t=false){if(!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_){De(e,t)}}function Rt(r,e){const t=Array.isArray(r);const s={type_:t?1:0,scope_:e?e.scope_:dt(),modified_:false,finalized_:false,assigned_:{},parent_:e,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:false};let n=s;let i=Ne;if(t){n=[s];i=re}const{revoke:o,proxy:a}=Proxy.revocable(n,i);s.draft_=a;s.revoke_=o;return a}var Ne={get(r,e){if(e===b)return r;const t=z(r);if(!Oe(t,e)){return kt(r,t,e)}const s=t[e];if(r.finalized_||!F(s)){return s}if(s===$e(r.base_,e)){Ee(r);return r.copy_[e]=je(s,r)}return s},has(r,e){return e in z(r)},ownKeys(r){return Reflect.ownKeys(z(r))},set(r,e,t){const s=_t(z(r),e);if(s==null?void 0:s.set){s.set.call(r.draft_,t);return true}if(!r.modified_){const n=$e(z(r),e);const i=n==null?void 0:n[b];if(i&&i.base_===t){r.copy_[e]=t;r.assigned_[e]=false;return true}if(It(t,n)&&(t!==void 0||Oe(r.base_,e)))return true;Ee(r);Te(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($e(r.base_,e)!==void 0||e in r.base_){r.assigned_[e]=false;Ee(r);Te(r)}else{delete r.assigned_[e]}if(r.copy_){delete r.copy_[e]}return true},getOwnPropertyDescriptor(r,e){const t=z(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(){m(11)},getPrototypeOf(r){return q(r.base_)},setPrototypeOf(){m(12)}};var re={};ee(Ne,(r,e)=>{re[r]=function(){arguments[0]=arguments[0][0];return e.apply(this,arguments)}});re.deleteProperty=function(r,e){if(isNaN(parseInt(e)))m(13);return re.set.call(this,r,e,void 0)};re.set=function(r,e,t){if(e!=="length"&&isNaN(parseInt(e)))m(14);return Ne.set.call(this,r[0],e,t,r[0])};function $e(r,e){const t=r[b];const s=t?z(t):r;return s[e]}function kt(r,e,t){var n;const s=_t(e,t);return s?`value`in s?s.value:(n=s.get)==null?void 0:n.call(r.draft_):void 0}function _t(r,e){if(!(e in r))return void 0;let t=q(r);while(t){const s=Object.getOwnPropertyDescriptor(t,e);if(s)return s;t=q(t)}return void 0}function Te(r){if(!r.modified_){r.modified_=true;if(r.parent_){Te(r.parent_)}}}function Ee(r){if(!r.copy_){r.copy_=Se(r.base_,r.scope_.immer_.useStrictShallowCopy_)}}var Lt=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 a(c=i,...u){return o.produce(c,f=>t.call(this,f,...u))}}if(typeof t!=="function")m(6);if(s!==void 0&&typeof s!=="function")m(7);let n;if(F(e)){const i=ct(this);const o=je(e,void 0);let a=true;try{n=t(o);a=false}finally{if(a)Pe(i);else Ce(i)}at(i,s);return ut(n,i)}else if(!e||typeof e!=="object"){n=t(e);if(n===void 0)n=e;if(n===ft)n=void 0;if(this.autoFreeze_)De(n,true);if(s){const i=[];const o=[];H("Patches").generateReplacementPatches_(e,n,i,o);s(i,o)}return n}else m(1,e)};this.produceWithPatches=(e,t)=>{if(typeof e==="function"){return(o,...a)=>this.produceWithPatches(o,c=>e(c,...a))}let s,n;const i=this.produce(e,t,(o,a)=>{s=o;n=a});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))m(8);if(W(r))r=Vt(r);const e=ct(this);const t=je(r,void 0);t[b].isManual_=true;Ce(e);return t}finishDraft(r,e){const t=r&&r[b];if(!t||!t.isManual_)m(9);const{scope_:s}=t;at(s,e);return ut(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=H("Patches").applyPatches_;if(W(r)){return s(r,e)}return this.produce(r,n=>s(n,e))}};function je(r,e){const t=ae(r)?H("MapSet").proxyMap_(r,e):ce(r)?H("MapSet").proxySet_(r,e):Rt(r,e);const s=e?e.scope_:dt();s.drafts_.push(t);return t}function Vt(r){if(!W(r))m(10,r);return mt(r)}function mt(r){if(!F(r)||ue(r))return r;const e=r[b];let t;if(e){if(!e.modified_)return e.base_;e.finalized_=true;t=Se(r,e.scope_.immer_.useStrictShallowCopy_)}else{t=Se(r,true)}ee(t,(s,n)=>{pt(t,s,mt(n))});if(e){e.finalized_=false}return t}var y=new Lt;var U=y.produce;var Zt=y.produceWithPatches.bind(y);var Yt=y.setAutoFreeze.bind(y);var Kt=y.setUseStrictShallowCopy.bind(y);var er=y.applyPatches.bind(y);var tr=y.createDraft.bind(y);var rr=y.finishDraft.bind(y);var Me=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 g=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 Me(n);let o=()=>{};try{o=this.subscribeCallback(i)}catch(a){if(i.error){i.error(a)}else{console.error("[Cami.js] Error in Subscriber:",a)}return}i.addTeardown(o);this._observers.push(i);return{unsubscribe:()=>i.unsubscribe(),complete:()=>i.complete(),error:a=>i.error(a)}}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 R=class extends g{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();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)}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)}}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);this.state=U(this.state,n=>{s(n,t)});this._observers.forEach(n=>n.next(this.state));if(this.devTools){this.devTools.send(e,this.state)}}};var qt=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 a=new r(e);a.init=()=>{if(n){const c=localStorage.getItem(s);const u=localStorage.getItem(`${s}-expiry`);const f=new Date().getTime();if(c&&u){const l=f>=parseInt(u,10);if(!l){a.state=JSON.parse(c)}else{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`)}}}};a.init();a.reset=()=>{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`);a.state=e;a._observers.forEach(c=>c.next(a.state))};a.subscribe(c=>{const u=new Date().getTime();const f=u+o;localStorage.setItem(s,JSON.stringify(c));localStorage.setItem(`${s}-expiry`,f.toString())});return a}};var Wt=(r,e={})=>{const t={localStorage:true,name:"cami-store",expiry:864e5};const s=C(C({},t),e);if(s.localStorage){const n=qt(R)(r,s);return n}else{return new R(r)}};var A=class r extends g{static from(e){if(e instanceof g){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=de(e),i,o,a;i=!(o=yield n.next()).done;i=false){const c=o.value;if(s)return;t.next(c)}}catch(o){a=[o]}finally{try{i&&(o=n.return)&&(yield o.call(n))}finally{if(a)throw a[0]}}t.complete()}catch(c){t.error(c)}}))();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:a=>{i=e(i,a)},error:a=>n(a),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 a=o.subscribe({next:c=>t.next(c),error:c=>t.error(c),complete:()=>{s.delete(a);if(s.size===0){t.complete()}}});s.add(a)},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:a=>t.next(a),error:a=>t.error(a),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 x(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 g){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=de(e),s,n,i;s=!(n=yield t.next()).done;s=false){const o=n.value;this._observers.forEach(a=>a.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(a=>a.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:a=>{if(!n){n=true;const c=e(a);s=c.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(a)}},error:a=>t.error(a),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:a=>{s[o]=a;if(!s.includes(void 0)){t.next([...s])}},error:a=>t.error(a),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 B={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 p(r,...e){if(B.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 j={current:null};var x=class extends g{constructor(e=null,t=null,{last:s=false,name:n=null}={}){super();if(s){this._lastObserver=t}else{this._observers.push(t)}this._value=U(e,i=>{});this._pendingUpdates=[];this._updateScheduled=false;this._name=n}get value(){if(j.current!=null){j.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=U(this._value,t)}else{this._value=t(this._value)}}if(e!==this._value){this._notifyObservers();if(B.events.isEnabled&&typeof window!=="undefined"){const t=new CustomEvent("cami:state:change",{detail:{name:this._name,oldValue:e,newValue:this._value}});window.dispatchEvent(t)}p("cami:state:change",this._name,e,this._value)}this._updateScheduled=false}toStream(){const e=new A;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 Ie=class extends x{constructor(e){super(null);this.computeFn=e;this.dependencies=new Set;this.subscriptions=new Map;this._compute()}get value(){if(j.current){j.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)}}};j.current=e;const t=this.computeFn();j.current=null;if(t!==this._value){this._value=t;this._notifyObservers()}}dispose(){this.subscriptions.forEach(e=>{e.unsubscribe()})}};var ze=function(r){return new Ie(r)};var Fe=function(r){let e=()=>{};let t=new Set;let s=new Map;const n={addDependency:a=>{if(!t.has(a)){const c=a.onValue(i);t.add(a);s.set(a,c)}}};const i=()=>{e();j.current=n;e=r()||(()=>{});j.current=null};if(typeof window!=="undefined"){requestAnimationFrame(i)}else{setTimeout(i,0)}const o=()=>{s.forEach(a=>{a.unsubscribe()});e()};return o};var E=new Map;var He=class extends HTMLElement{constructor(){super();this.onCreate();this._unsubscribers=new Map;this._computed=ze.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:a=>a;n=U(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 R)){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 A(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:a=null,gcTime:c=1e3*60*5,retry:u=3,retryDelay:f=l=>Math.pow(2,l)*1e3}){const l=Array.isArray(e)?e.map(w=>typeof w==="object"?JSON.stringify(w):w).join(":"):e;this._queryFunctions.set(l,t);p("query","Starting query with key:",l);const h=this._observable({data:null,status:"pending",fetchStatus:"idle",error:null,lastUpdated:E.has(l)?E.get(l).lastUpdated:null},l);const _=this._observableProxy(h);const $=(w=0)=>k(this,null,function*(){const Re=Date.now();const fe=E.get(l);if(fe&&Re-fe.lastUpdated{S.data=fe.data;S.status="success";S.fetchStatus="idle"})}else{p("fetchData (else)","Fetching data for key:",l);try{h.update(O=>{O.status="pending";O.fetchStatus="fetching"});const S=yield t();E.set(l,{data:S,lastUpdated:Re});h.update(O=>{O.data=S;O.status="success";O.fetchStatus="idle"})}catch(S){p("fetchData (catch)","Fetch error for key:",l,S);if(w$(w+1),f(w))}else{h.update(O=>{O.error={message:S.message};O.status="error";O.fetchStatus="idle"})}}}});if(i){p("query","Setting up refetch on mount for key:",l);$()}if(n){p("query","Setting up refetch on window focus for key:",l);const w=()=>$();window.addEventListener("focus",w);this._unsubscribers.set(`focus:${l}`,()=>window.removeEventListener("focus",w))}if(o){p("query","Setting up refetch on reconnect for key:",l);window.addEventListener("online",$);this._unsubscribers.set(`online:${l}`,()=>window.removeEventListener("online",$))}if(a){p("query","Setting up refetch interval for key:",l);const w=setInterval($,a);this._unsubscribers.set(`interval:${l}`,()=>clearInterval(w))}const bt=setTimeout(()=>{E.delete(l)},c);this._unsubscribers.set(`gc:${l}`,()=>clearTimeout(bt));return _}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 a=this._observableProxy(o);const c=u=>k(this,null,function*(){p("mutation","Starting mutation for variables:",u);let f;const l=o.value;if(t){p("mutation","Performing optimistic update for variables:",u);f=t(u,l);o.update(h=>{h.data=f.optimisticData;h.status="pending";h.error=null})}else{p("mutation","Performing mutation without optimistic update for variables:",u);o.update(h=>{h.status="pending";h.error=null})}try{const h=yield e(u);o.update(_=>{_.data=h;_.status="success"});if(n){n(h,u,f)}p("mutation","Mutation successful for variables:",u,h)}catch(h){p("mutation","Mutation error for variables:",u,h);o.update(_=>{_.error={message:h.message};_.status="error";if(!s&&f&&f.rollback){p("mutation","Rolling back mutation for variables:",u);f.rollback()}});if(s){s(h,u,f)}}finally{if(!o.value.isSettled){o.update(h=>{h.isSettled=true});if(i){p("mutation","Calling onSettled for variables:",u);i(o.value.data,o.value.error,u,f)}}}});a.mutate=c;a.reset=()=>{o.update(u=>{u.data=null;u.status="idle";u.error=null;u.isSettled=false})};return a}invalidateQueries(e){const t=Array.isArray(e)?e.join(":"):e;p("invalidateQueries","Invalidating query with key:",t);E.delete(t);this._refetchQuery(t)}onCreate(){}connectedCallback(){this._setup({infer:true});this.effect(()=>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 x)){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 x)){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){if(!(e instanceof x)){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}})}_setup(e){if(e.infer===true){Object.keys(this).forEach(t=>{if(typeof this[t]!=="function"&&!t.startsWith("_")){if(this[t]instanceof g){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=null){if(!this._isAllowedType(e)){const n=Object.prototype.toString.call(e);throw new Error(`[Cami.js] The type ${n} of initialValue is not allowed in observables.`)}const s=new x(e);this._registerObservables(s);return s}_refetchQuery(e){p("_refetchQuery","Refetching query with key:",e);const t=this._queryFunctions.get(e);if(t){p("_refetchQuery","Found query function for key:",e);const s=E.get(e)||{data:void 0,status:"idle",error:null};E.set(e,pe(C({},s),{status:"pending",error:null}));t().then(n=>{E.set(e,{data:n,status:"success",error:null,lastUpdated:Date.now()});p("_refetchQuery","Refetch successful for key:",e,n)}).catch(n=>{if(s.data!==void 0){p("_refetchQuery","Rolling back refetch for key:",e);E.set(e,s)}E.set(e,pe(C({},s),{status:"error",error:n}))}).finally(()=>{this.query({queryKey:e,queryFn:t});p("_refetchQuery","Refetch complete for key:",e)})}}_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 x)){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();Ae(e,this)}};var Ue=class extends A{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 A(s=>{const n=i=>{s.next(i)};this.element.addEventListener(e,n,t);return()=>{this.element.removeEventListener(e,n,t)}})}};var le=class extends A{constructor(){super(...arguments);Ve(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 v=r=>{if(typeof r==="string"){return v.get(r)}return new le(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()}})};v.get=(r,e={})=>{e.url=r;e.method="GET";return v(e)};v.post=(r,e={},t={})=>{t.url=r;t.data=e;t.method="POST";return v(t)};v.put=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PUT";return v(t)};v.patch=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PATCH";return v(t)};v.delete=(r,e={})=>{e.url=r;e.method="DELETE";return v(e)};v.sse=(r,e={})=>{const t=new le(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:Xr,events:Gr}=B;export{g as Observable,Ue as ObservableElement,x as ObservableState,R as ObservableStore,A as ObservableStream,He as ReactiveElement,ze as computed,xe as css,Xr as debug,Fe as effect,Gr as events,rt as html,v as http,Wt as store,Et as svg}; +\f\r"'\`<>=]|("|')|))|$)`,"g");var Qe=/'/g;var Je=/"/g;var et=/^(?:script|style|textarea|title)$/i;var tt=r=>(e,...t)=>({_$litType$:r,strings:e,values:t});var rt=tt(1);var Et=tt(2);var Z=Symbol.for("lit-noChange");var d=Symbol.for("lit-nothing");var Xe=new WeakMap;var N=M.createTreeWalker(M,129);function st(r,e){if(!Array.isArray(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==qe?qe.createHTML(e):e}var Ot=(r,e)=>{const t=r.length-1,s=[];let n,i=2===e?"":"",o=Q;for(let a=0;a"===f[0]?(o=n!=null?n:Q,l=-1):void 0===f[1]?l=-2:(l=o.lastIndex-f[2].length,u=f[1],o=void 0===f[3]?D:'"'===f[3]?Je:Qe):o===Je||o===Qe?o=D:o===We||o===Be?o=Q:(o=D,n=void 0);const _=o===D&&r[a+1].startsWith("/>")?" ":"";i+=o===Q?c+xt:l>=0?(s.push(u),c.slice(0,l)+Ze+c.slice(l)+T+_):c+T+(-2===l?a:_)}return[st(r,i+(r[t]||"")+(2===e?"":"")),s]};var Y=class r{constructor({strings:e,_$litType$:t},s){let n;this.parts=[];let i=0,o=0;const a=e.length-1,c=this.parts,[u,f]=Ot(e,t);if(this.el=r.createElement(u,s),N.currentNode=this.el.content,2===t){const l=this.el.content.firstChild;l.replaceWith(...l.childNodes)}for(;null!==(n=N.nextNode())&&c.length0){n.textContent=se?se.emptyScript:"";for(let _=0;_2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=d}_$AI(e,t=this,s,n){const i=this.strings;let o=false;if(void 0===i)e=L(this,e,t,0),o=!G(e)||e!==this._$AH&&e!==Z,o&&(this._$AH=e);else{const a=e;let c,u;for(e=i[0],c=0;c{var i,o;const s=(i=t==null?void 0:t.renderBefore)!=null?i:e;let n=s._$litPart$;if(void 0===n){const a=(o=t==null?void 0:t.renderBefore)!=null?o:null;s._$litPart$=n=new K(e.insertBefore(X(),a),a,void 0,t!=null?t:{})}return n._$AI(r),n};var St={data:""};var Pt=r=>"object"==typeof window?((r?r.querySelector("#_goober"):window._goober)||Object.assign((r||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:r||St;var Ct=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g;var Tt=/\/\*[^]*?\*\/| +/g;var nt=/\n+/g;var I=(r,e)=>{let t="",s="",n="";for(let i in r){let o=r[i];"@"==i[0]?"i"==i[1]?t=i+" "+o+";":s+="f"==i[1]?I(o,i):i+"{"+I(o,"k"==i[1]?"":e)+"}":"object"==typeof o?s+=I(o,e?e.replace(/([^,])+/g,a=>i.replace(/(^:.*)|([^,])+/g,c=>/&/.test(c)?c.replace(/&/g,a):a?a+" "+c:c)):i):null!=o&&(i=/^--/.test(i)?i:i.replace(/[A-Z]/g,"-$&").toLowerCase(),n+=I.p?I.p(i,o):i+":"+o+";")}return t+(e&&n?e+"{"+n+"}":n)+s};var P={};var it=r=>{if("object"==typeof r){let e="";for(let t in r)e+=t+it(r[t]);return e}return r};var jt=(r,e,t,s,n)=>{let i=it(r),o=P[i]||(P[i]=(c=>{let u=0,f=11;for(;u>>0;return"go"+f})(i));if(!P[o]){let c=i!==r?r:(u=>{let f,l,h=[{}];for(;f=Ct.exec(u.replace(Tt,""));)f[4]?h.shift():f[3]?(l=f[3].replace(nt," ").trim(),h.unshift(h[0][l]=h[0][l]||{})):h[0][f[1]]=f[2].replace(nt," ").trim();return h[0]})(r);P[o]=I(n?{["@keyframes "+o]:c}:c,t?"":"."+o)}let a=t&&P.g?P.g:null;return t&&(P.g=P[o]),((c,u,f,l)=>{l?u.data=u.data.replace(l,c):-1===u.data.indexOf(c)&&(u.data=f?c+u.data:u.data+c)})(P[o],e,s,a),o};var Dt=(r,e,t)=>r.reduce((s,n,i)=>{let o=e[i];if(o&&o.call){let a=o(t),c=a&&a.props&&a.props.className||/^go/.test(a)&&a;o=c?"."+c:a&&"object"==typeof a?a.props?"":I(a,""):false===a?"":a}return s+n+(null==o?"":o)},"");function xe(r){let e=this||{},t=r.call?r(e.p):r;return jt(t.unshift?t.raw?Dt(t,[].slice.call(arguments,1),e.p):t.reduce((s,n)=>Object.assign(s,n&&n.call?n(e.p):n),{}):t,Pt(e.target),e.g,e.o,e.k)}var Jt=xe.bind({g:1});var Xt=xe.bind({k:1});var ft=Symbol.for("immer-nothing");var ot=Symbol.for("immer-draftable");var b=Symbol.for("immer-state");var Nt=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.","Immer forbids 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 an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(r){return`'original' expects a draft, got: ${r}`}]:[];function m(r,...e){if(true){const t=Nt[r];const s=typeof t==="function"?t.apply(null,e):t;throw new Error(`[Immer] ${s}`)}throw new Error(`[Immer] minified error nr: ${r}. Full error at: https://bit.ly/3cXEKWf`)}var q=Object.getPrototypeOf;function W(r){return!!r&&!!r[b]}function F(r){var e;if(!r)return false;return ht(r)||Array.isArray(r)||!!r[ot]||!!((e=r.constructor)==null?void 0:e[ot])||ae(r)||ce(r)}var Mt=Object.prototype.constructor.toString();function ht(r){if(!r||typeof r!=="object")return false;const e=q(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)===Mt}function ee(r,e){if(oe(r)===0){Object.entries(r).forEach(([t,s])=>{e(t,s,r)})}else{r.forEach((t,s)=>e(s,t,r))}}function oe(r){const e=r[b];return e?e.type_:Array.isArray(r)?1:ae(r)?2:ce(r)?3:0}function Oe(r,e){return oe(r)===2?r.has(e):Object.prototype.hasOwnProperty.call(r,e)}function pt(r,e,t){const s=oe(r);if(s===2)r.set(e,t);else if(s===3){r.add(t)}else r[e]=t}function It(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 ce(r){return r instanceof Set}function z(r){return r.copy_||r.base_}function Se(r,e){if(ae(r)){return new Map(r)}if(ce(r)){return new Set(r)}if(Array.isArray(r))return Array.prototype.slice.call(r);if(!e&&ht(r)){if(!q(r)){const n=Object.create(null);return Object.assign(n,r)}return C({},r)}const t=Object.getOwnPropertyDescriptors(r);delete t[b];let s=Reflect.ownKeys(t);for(let n=0;n1){r.set=r.add=r.clear=r.delete=zt}Object.freeze(r);if(e)ee(r,(t,s)=>De(s,true),true);return r}function zt(){m(2)}function ue(r){return Object.isFrozen(r)}var Ft={};function H(r){const e=Ft[r];if(!e){m(0,r)}return e}var te;function dt(){return te}function Ht(r,e){return{drafts_:[],parent_:r,immer_:e,canAutoFreeze_:true,unfinalizedDrafts_:0}}function at(r,e){if(e){H("Patches");r.patches_=[];r.inversePatches_=[];r.patchListener_=e}}function Pe(r){Ce(r);r.drafts_.forEach(Ut);r.drafts_=null}function Ce(r){if(r===te){te=r.parent_}}function ct(r){return te=Ht(te,r)}function Ut(r){const e=r[b];if(e.type_===0||e.type_===1)e.revoke_();else e.revoked_=true}function ut(r,e){e.unfinalizedDrafts_=e.drafts_.length;const t=e.drafts_[0];const s=r!==void 0&&r!==t;if(s){if(t[b].modified_){Pe(e);m(4)}if(F(r)){r=ne(e,r);if(!e.parent_)ie(e,r)}if(e.patches_){H("Patches").generateReplacementPatches_(t[b].base_,r,e.patches_,e.inversePatches_)}}else{r=ne(e,t,[])}Pe(e);if(e.patches_){e.patchListener_(e.patches_,e.inversePatches_)}return r!==ft?r:void 0}function ne(r,e,t){if(ue(e))return e;const s=e[b];if(!s){ee(e,(n,i)=>lt(r,s,e,n,i,t),true);return e}if(s.scope_!==r)return e;if(!s.modified_){ie(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}ee(i,(a,c)=>lt(r,s,n,a,c,t,o));ie(r,n,false);if(t&&r.patches_){H("Patches").generatePatches_(s,t,r.patches_,r.inversePatches_)}}return s.copy_}function lt(r,e,t,s,n,i,o){if(n===t)m(5);if(W(n)){const a=i&&e&&e.type_!==3&&!Oe(e.assigned_,s)?i.concat(s):void 0;const c=ne(r,n,a);pt(t,s,c);if(W(c)){r.canAutoFreeze_=false}else return}else if(o){t.add(n)}if(F(n)&&!ue(n)){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1){return}ne(r,n);if(!e||!e.scope_.parent_)ie(r,n)}}function ie(r,e,t=false){if(!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_){De(e,t)}}function Rt(r,e){const t=Array.isArray(r);const s={type_:t?1:0,scope_:e?e.scope_:dt(),modified_:false,finalized_:false,assigned_:{},parent_:e,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:false};let n=s;let i=Ne;if(t){n=[s];i=re}const{revoke:o,proxy:a}=Proxy.revocable(n,i);s.draft_=a;s.revoke_=o;return a}var Ne={get(r,e){if(e===b)return r;const t=z(r);if(!Oe(t,e)){return kt(r,t,e)}const s=t[e];if(r.finalized_||!F(s)){return s}if(s===$e(r.base_,e)){Ee(r);return r.copy_[e]=je(s,r)}return s},has(r,e){return e in z(r)},ownKeys(r){return Reflect.ownKeys(z(r))},set(r,e,t){const s=_t(z(r),e);if(s==null?void 0:s.set){s.set.call(r.draft_,t);return true}if(!r.modified_){const n=$e(z(r),e);const i=n==null?void 0:n[b];if(i&&i.base_===t){r.copy_[e]=t;r.assigned_[e]=false;return true}if(It(t,n)&&(t!==void 0||Oe(r.base_,e)))return true;Ee(r);Te(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($e(r.base_,e)!==void 0||e in r.base_){r.assigned_[e]=false;Ee(r);Te(r)}else{delete r.assigned_[e]}if(r.copy_){delete r.copy_[e]}return true},getOwnPropertyDescriptor(r,e){const t=z(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(){m(11)},getPrototypeOf(r){return q(r.base_)},setPrototypeOf(){m(12)}};var re={};ee(Ne,(r,e)=>{re[r]=function(){arguments[0]=arguments[0][0];return e.apply(this,arguments)}});re.deleteProperty=function(r,e){if(isNaN(parseInt(e)))m(13);return re.set.call(this,r,e,void 0)};re.set=function(r,e,t){if(e!=="length"&&isNaN(parseInt(e)))m(14);return Ne.set.call(this,r[0],e,t,r[0])};function $e(r,e){const t=r[b];const s=t?z(t):r;return s[e]}function kt(r,e,t){var n;const s=_t(e,t);return s?`value`in s?s.value:(n=s.get)==null?void 0:n.call(r.draft_):void 0}function _t(r,e){if(!(e in r))return void 0;let t=q(r);while(t){const s=Object.getOwnPropertyDescriptor(t,e);if(s)return s;t=q(t)}return void 0}function Te(r){if(!r.modified_){r.modified_=true;if(r.parent_){Te(r.parent_)}}}function Ee(r){if(!r.copy_){r.copy_=Se(r.base_,r.scope_.immer_.useStrictShallowCopy_)}}var Lt=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 a(c=i,...u){return o.produce(c,f=>t.call(this,f,...u))}}if(typeof t!=="function")m(6);if(s!==void 0&&typeof s!=="function")m(7);let n;if(F(e)){const i=ct(this);const o=je(e,void 0);let a=true;try{n=t(o);a=false}finally{if(a)Pe(i);else Ce(i)}at(i,s);return ut(n,i)}else if(!e||typeof e!=="object"){n=t(e);if(n===void 0)n=e;if(n===ft)n=void 0;if(this.autoFreeze_)De(n,true);if(s){const i=[];const o=[];H("Patches").generateReplacementPatches_(e,n,i,o);s(i,o)}return n}else m(1,e)};this.produceWithPatches=(e,t)=>{if(typeof e==="function"){return(o,...a)=>this.produceWithPatches(o,c=>e(c,...a))}let s,n;const i=this.produce(e,t,(o,a)=>{s=o;n=a});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))m(8);if(W(r))r=Vt(r);const e=ct(this);const t=je(r,void 0);t[b].isManual_=true;Ce(e);return t}finishDraft(r,e){const t=r&&r[b];if(!t||!t.isManual_)m(9);const{scope_:s}=t;at(s,e);return ut(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=H("Patches").applyPatches_;if(W(r)){return s(r,e)}return this.produce(r,n=>s(n,e))}};function je(r,e){const t=ae(r)?H("MapSet").proxyMap_(r,e):ce(r)?H("MapSet").proxySet_(r,e):Rt(r,e);const s=e?e.scope_:dt();s.drafts_.push(t);return t}function Vt(r){if(!W(r))m(10,r);return mt(r)}function mt(r){if(!F(r)||ue(r))return r;const e=r[b];let t;if(e){if(!e.modified_)return e.base_;e.finalized_=true;t=Se(r,e.scope_.immer_.useStrictShallowCopy_)}else{t=Se(r,true)}ee(t,(s,n)=>{pt(t,s,mt(n))});if(e){e.finalized_=false}return t}var y=new Lt;var U=y.produce;var Zt=y.produceWithPatches.bind(y);var Yt=y.setAutoFreeze.bind(y);var Kt=y.setUseStrictShallowCopy.bind(y);var er=y.applyPatches.bind(y);var tr=y.createDraft.bind(y);var rr=y.finishDraft.bind(y);var Me=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 g=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 Me(n);let o=()=>{};try{o=this.subscribeCallback(i)}catch(a){if(i.error){i.error(a)}else{console.error("[Cami.js] Error in Subscriber:",a)}return}i.addTeardown(o);this._observers.push(i);return{unsubscribe:()=>i.unsubscribe(),complete:()=>i.complete(),error:a=>i.error(a)}}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 R=class extends g{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();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)}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)}}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);this.state=U(this.state,n=>{s(n,t)});this._observers.forEach(n=>n.next(this.state));if(this.devTools){this.devTools.send(e,this.state)}}};var qt=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 a=new r(e);a.init=()=>{if(n){const c=localStorage.getItem(s);const u=localStorage.getItem(`${s}-expiry`);const f=new Date().getTime();if(c&&u){const l=f>=parseInt(u,10);if(!l){a.state=JSON.parse(c)}else{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`)}}}};a.init();a.reset=()=>{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`);a.state=e;a._observers.forEach(c=>c.next(a.state))};a.subscribe(c=>{const u=new Date().getTime();const f=u+o;localStorage.setItem(s,JSON.stringify(c));localStorage.setItem(`${s}-expiry`,f.toString())});return a}};var Wt=(r,e={})=>{const t={localStorage:true,name:"cami-store",expiry:864e5};const s=C(C({},t),e);if(s.localStorage){const n=qt(R)(r,s);return n}else{return new R(r)}};var A=class r extends g{static from(e){if(e instanceof g){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=de(e),i,o,a;i=!(o=yield n.next()).done;i=false){const c=o.value;if(s)return;t.next(c)}}catch(o){a=[o]}finally{try{i&&(o=n.return)&&(yield o.call(n))}finally{if(a)throw a[0]}}t.complete()}catch(c){t.error(c)}}))();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:a=>{i=e(i,a)},error:a=>n(a),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 a=o.subscribe({next:c=>t.next(c),error:c=>t.error(c),complete:()=>{s.delete(a);if(s.size===0){t.complete()}}});s.add(a)},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:a=>t.next(a),error:a=>t.error(a),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 x(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 g){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=de(e),s,n,i;s=!(n=yield t.next()).done;s=false){const o=n.value;this._observers.forEach(a=>a.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(a=>a.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:a=>{if(!n){n=true;const c=e(a);s=c.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(a)}},error:a=>t.error(a),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:a=>{s[o]=a;if(!s.includes(void 0)){t.next([...s])}},error:a=>t.error(a),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 B={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 p(r,...e){if(B.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 j={current:null};var x=class extends g{constructor(e=null,t=null,{last:s=false,name:n=null}={}){super();if(s){this._lastObserver=t}else{this._observers.push(t)}this._value=U(e,i=>{});this._pendingUpdates=[];this._updateScheduled=false;this._name=n}get value(){if(j.current!=null){j.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=U(this._value,t)}else{this._value=t(this._value)}}if(e!==this._value){this._notifyObservers();if(B.events.isEnabled&&typeof window!=="undefined"){const t=new CustomEvent("cami:state:change",{detail:{name:this._name,oldValue:e,newValue:this._value}});window.dispatchEvent(t)}p("cami:state:change",this._name,e,this._value)}this._updateScheduled=false}toStream(){const e=new A;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 Ie=class extends x{constructor(e){super(null);this.computeFn=e;this.dependencies=new Set;this.subscriptions=new Map;this._compute()}get value(){if(j.current){j.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)}}};j.current=e;const t=this.computeFn();j.current=null;if(t!==this._value){this._value=t;this._notifyObservers()}}dispose(){this.subscriptions.forEach(e=>{e.unsubscribe()})}};var ze=function(r){return new Ie(r)};var Fe=function(r){let e=()=>{};let t=new Set;let s=new Map;const n={addDependency:a=>{if(!t.has(a)){const c=a.onValue(i);t.add(a);s.set(a,c)}}};const i=()=>{e();j.current=n;e=r()||(()=>{});j.current=null};if(typeof window!=="undefined"){requestAnimationFrame(i)}else{setTimeout(i,0)}const o=()=>{s.forEach(a=>{a.unsubscribe()});e()};return o};var E=new Map;var He=class extends HTMLElement{constructor(){super();this.onCreate();this._unsubscribers=new Map;this._computed=ze.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:a=>a;n=U(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 R)){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 A(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:a=null,gcTime:c=1e3*60*5,retry:u=3,retryDelay:f=l=>Math.pow(2,l)*1e3}){const l=Array.isArray(e)?e.map(w=>typeof w==="object"?JSON.stringify(w):w).join(":"):e;this._queryFunctions.set(l,t);p("query","Starting query with key:",l);const h=this._observable({data:null,status:"pending",fetchStatus:"idle",error:null,lastUpdated:E.has(l)?E.get(l).lastUpdated:null},l);const _=this._observableProxy(h);const $=(w=0)=>k(this,null,function*(){const Re=Date.now();const fe=E.get(l);if(fe&&Re-fe.lastUpdated{S.data=fe.data;S.status="success";S.fetchStatus="idle"})}else{p("fetchData (else)","Fetching data for key:",l);try{h.update(O=>{O.status="pending";O.fetchStatus="fetching"});const S=yield t();E.set(l,{data:S,lastUpdated:Re});h.update(O=>{O.data=S;O.status="success";O.fetchStatus="idle"})}catch(S){p("fetchData (catch)","Fetch error for key:",l,S);if(w$(w+1),f(w))}else{h.update(O=>{O.error={message:S.message};O.status="error";O.fetchStatus="idle"})}}}});if(i){p("query","Setting up refetch on mount for key:",l);$()}if(n){p("query","Setting up refetch on window focus for key:",l);const w=()=>$();window.addEventListener("focus",w);this._unsubscribers.set(`focus:${l}`,()=>window.removeEventListener("focus",w))}if(o){p("query","Setting up refetch on reconnect for key:",l);window.addEventListener("online",$);this._unsubscribers.set(`online:${l}`,()=>window.removeEventListener("online",$))}if(a){p("query","Setting up refetch interval for key:",l);const w=setInterval($,a);this._unsubscribers.set(`interval:${l}`,()=>clearInterval(w))}const bt=setTimeout(()=>{E.delete(l)},c);this._unsubscribers.set(`gc:${l}`,()=>clearTimeout(bt));return _}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 a=this._observableProxy(o);const c=u=>k(this,null,function*(){p("mutation","Starting mutation for variables:",u);let f;const l=o.value;if(t){p("mutation","Performing optimistic update for variables:",u);f=t(u,l);o.update(h=>{h.data=f.optimisticData;h.status="pending";h.error=null})}else{p("mutation","Performing mutation without optimistic update for variables:",u);o.update(h=>{h.status="pending";h.error=null})}try{const h=yield e(u);o.update(_=>{_.data=h;_.status="success"});if(n){n(h,u,f)}p("mutation","Mutation successful for variables:",u,h)}catch(h){p("mutation","Mutation error for variables:",u,h);o.update(_=>{_.error={message:h.message};_.status="error";if(!s&&f&&f.rollback){p("mutation","Rolling back mutation for variables:",u);f.rollback()}});if(s){s(h,u,f)}}finally{if(!o.value.isSettled){o.update(h=>{h.isSettled=true});if(i){p("mutation","Calling onSettled for variables:",u);i(o.value.data,o.value.error,u,f)}}}});a.mutate=c;a.reset=()=>{o.update(u=>{u.data=null;u.status="idle";u.error=null;u.isSettled=false})};return a}invalidateQueries(e){const t=Array.isArray(e)?e.join(":"):e;p("invalidateQueries","Invalidating query with key:",t);E.delete(t);this._refetchQuery(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 x)){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 x)){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){if(!(e instanceof x)){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}})}_setup(e){if(e.infer===true){Object.keys(this).forEach(t=>{if(typeof this[t]!=="function"&&!t.startsWith("_")){if(this[t]instanceof g){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=null){if(!this._isAllowedType(e)){const n=Object.prototype.toString.call(e);throw new Error(`[Cami.js] The type ${n} of initialValue is not allowed in observables.`)}const s=new x(e);this._registerObservables(s);return s}_refetchQuery(e){p("_refetchQuery","Refetching query with key:",e);const t=this._queryFunctions.get(e);if(t){p("_refetchQuery","Found query function for key:",e);const s=E.get(e)||{data:void 0,status:"idle",error:null};E.set(e,pe(C({},s),{status:"pending",error:null}));t().then(n=>{E.set(e,{data:n,status:"success",error:null,lastUpdated:Date.now()});p("_refetchQuery","Refetch successful for key:",e,n)}).catch(n=>{if(s.data!==void 0){p("_refetchQuery","Rolling back refetch for key:",e);E.set(e,s)}E.set(e,pe(C({},s),{status:"error",error:n}))}).finally(()=>{this.query({queryKey:e,queryFn:t});p("_refetchQuery","Refetch complete for key:",e)})}}_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 x)){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();Ae(e,this)}};var Ue=class extends A{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 A(s=>{const n=i=>{s.next(i)};this.element.addEventListener(e,n,t);return()=>{this.element.removeEventListener(e,n,t)}})}};var le=class extends A{constructor(){super(...arguments);Ve(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 v=r=>{if(typeof r==="string"){return v.get(r)}return new le(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()}})};v.get=(r,e={})=>{e.url=r;e.method="GET";return v(e)};v.post=(r,e={},t={})=>{t.url=r;t.data=e;t.method="POST";return v(t)};v.put=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PUT";return v(t)};v.patch=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PATCH";return v(t)};v.delete=(r,e={})=>{e.url=r;e.method="DELETE";return v(e)};v.sse=(r,e={})=>{const t=new le(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:Xr,events:Gr}=B;export{g as Observable,Ue as ObservableElement,x as ObservableState,R as ObservableStore,A as ObservableStream,He as ReactiveElement,ze as computed,xe as css,Xr as debug,Fe as effect,Gr as events,rt as html,v as http,Wt as store,Et as svg}; /** * @license * Copyright (c) 2023 Kenn Costales diff --git a/build/cami.module.js.map b/build/cami.module.js.map index ffac660b..88e1041c 100644 --- a/build/cami.module.js.map +++ b/build/cami.module.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../node_modules/lit-html/src/lit-html.ts", "../node_modules/goober/dist/goober.modern.js", "../node_modules/immer/src/utils/env.ts", "../node_modules/immer/src/utils/errors.ts", "../node_modules/immer/src/utils/common.ts", "../node_modules/immer/src/utils/plugins.ts", "../node_modules/immer/src/core/scope.ts", "../node_modules/immer/src/core/finalize.ts", "../node_modules/immer/src/core/proxy.ts", "../node_modules/immer/src/core/immerClass.ts", "../node_modules/immer/src/core/current.ts", "../node_modules/immer/src/plugins/patches.ts", "../node_modules/immer/src/plugins/mapset.ts", "../node_modules/immer/src/immer.ts", "../src/observables/observable.js", "../src/observables/observable-store.js", "../src/observables/observable-stream.js", "../src/config.js", "../src/trace.js", "../src/observables/observable-state.js", "../src/reactive-element.js", "../src/observables/observable-element.js", "../src/http.js", "../src/cami.js"], - "sourcesContent": ["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n// IMPORTANT: these imports must be type-only\nimport type {Directive, DirectiveResult, PartInfo} from './directive.js';\n\nconst DEV_MODE = true;\nconst ENABLE_EXTRA_SECURITY_HOOKS = true;\nconst ENABLE_SHADYDOM_NOPATCH = true;\nconst NODE_MODE = false;\n\n// Allows minifiers to rename references to globalThis\nconst global = globalThis;\n\n/**\n * Contains types that are part of the unstable debug API.\n *\n * Everything in this API is not stable and may change or be removed in the future,\n * even on patch releases.\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace LitUnstable {\n /**\n * When Lit is running in dev mode and `window.emitLitDebugLogEvents` is true,\n * we will emit 'lit-debug' events to window, with live details about the update and render\n * lifecycle. These can be useful for writing debug tooling and visualizations.\n *\n * Please be aware that running with window.emitLitDebugLogEvents has performance overhead,\n * making certain operations that are normally very cheap (like a no-op render) much slower,\n * because we must copy data and dispatch events.\n */\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace DebugLog {\n export type Entry =\n | TemplatePrep\n | TemplateInstantiated\n | TemplateInstantiatedAndUpdated\n | TemplateUpdating\n | BeginRender\n | EndRender\n | CommitPartEntry\n | SetPartValue;\n export interface TemplatePrep {\n kind: 'template prep';\n template: Template;\n strings: TemplateStringsArray;\n clonableTemplate: HTMLTemplateElement;\n parts: TemplatePart[];\n }\n export interface BeginRender {\n kind: 'begin render';\n id: number;\n value: unknown;\n container: HTMLElement | DocumentFragment;\n options: RenderOptions | undefined;\n part: ChildPart | undefined;\n }\n export interface EndRender {\n kind: 'end render';\n id: number;\n value: unknown;\n container: HTMLElement | DocumentFragment;\n options: RenderOptions | undefined;\n part: ChildPart;\n }\n export interface TemplateInstantiated {\n kind: 'template instantiated';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n fragment: Node;\n parts: Array;\n values: unknown[];\n }\n export interface TemplateInstantiatedAndUpdated {\n kind: 'template instantiated and updated';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n fragment: Node;\n parts: Array;\n values: unknown[];\n }\n export interface TemplateUpdating {\n kind: 'template updating';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n parts: Array;\n values: unknown[];\n }\n export interface SetPartValue {\n kind: 'set part';\n part: Part;\n value: unknown;\n valueIndex: number;\n values: unknown[];\n templateInstance: TemplateInstance;\n }\n\n export type CommitPartEntry =\n | CommitNothingToChildEntry\n | CommitText\n | CommitNode\n | CommitAttribute\n | CommitProperty\n | CommitBooleanAttribute\n | CommitEventListener\n | CommitToElementBinding;\n\n export interface CommitNothingToChildEntry {\n kind: 'commit nothing to child';\n start: ChildNode;\n end: ChildNode | null;\n parent: Disconnectable | undefined;\n options: RenderOptions | undefined;\n }\n\n export interface CommitText {\n kind: 'commit text';\n node: Text;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitNode {\n kind: 'commit node';\n start: Node;\n parent: Disconnectable | undefined;\n value: Node;\n options: RenderOptions | undefined;\n }\n\n export interface CommitAttribute {\n kind: 'commit attribute';\n element: Element;\n name: string;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitProperty {\n kind: 'commit property';\n element: Element;\n name: string;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitBooleanAttribute {\n kind: 'commit boolean attribute';\n element: Element;\n name: string;\n value: boolean;\n options: RenderOptions | undefined;\n }\n\n export interface CommitEventListener {\n kind: 'commit event listener';\n element: Element;\n name: string;\n value: unknown;\n oldListener: unknown;\n options: RenderOptions | undefined;\n // True if we're removing the old event listener (e.g. because settings changed, or value is nothing)\n removeListener: boolean;\n // True if we're adding a new event listener (e.g. because first render, or settings changed)\n addListener: boolean;\n }\n\n export interface CommitToElementBinding {\n kind: 'commit to element binding';\n element: Element;\n value: unknown;\n options: RenderOptions | undefined;\n }\n }\n}\n\ninterface DebugLoggingWindow {\n // Even in dev mode, we generally don't want to emit these events, as that's\n // another level of cost, so only emit them when DEV_MODE is true _and_ when\n // window.emitLitDebugEvents is true.\n emitLitDebugLogEvents?: boolean;\n}\n\n/**\n * Useful for visualizing and logging insights into what the Lit template system is doing.\n *\n * Compiled out of prod mode builds.\n */\nconst debugLogEvent = DEV_MODE\n ? (event: LitUnstable.DebugLog.Entry) => {\n const shouldEmit = (global as unknown as DebugLoggingWindow)\n .emitLitDebugLogEvents;\n if (!shouldEmit) {\n return;\n }\n global.dispatchEvent(\n new CustomEvent('lit-debug', {\n detail: event,\n })\n );\n }\n : undefined;\n// Used for connecting beginRender and endRender events when there are nested\n// renders when errors are thrown preventing an endRender event from being\n// called.\nlet debugLogRenderId = 0;\n\nlet issueWarning: (code: string, warning: string) => void;\n\nif (DEV_MODE) {\n global.litIssuedWarnings ??= new Set();\n\n // Issue a warning, if we haven't already.\n issueWarning = (code: string, warning: string) => {\n warning += code\n ? ` See https://lit.dev/msg/${code} for more information.`\n : '';\n if (!global.litIssuedWarnings!.has(warning)) {\n console.warn(warning);\n global.litIssuedWarnings!.add(warning);\n }\n };\n\n issueWarning(\n 'dev-mode',\n `Lit is in dev mode. Not recommended for production!`\n );\n}\n\nconst wrap =\n ENABLE_SHADYDOM_NOPATCH &&\n global.ShadyDOM?.inUse &&\n global.ShadyDOM?.noPatch === true\n ? (global.ShadyDOM!.wrap as (node: T) => T)\n : (node: T) => node;\n\nconst trustedTypes = (global as unknown as Window).trustedTypes;\n\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('lit-html', {\n createHTML: (s) => s,\n })\n : undefined;\n\n/**\n * Used to sanitize any value before it is written into the DOM. This can be\n * used to implement a security policy of allowed and disallowed values in\n * order to prevent XSS attacks.\n *\n * One way of using this callback would be to check attributes and properties\n * against a list of high risk fields, and require that values written to such\n * fields be instances of a class which is safe by construction. Closure's Safe\n * HTML Types is one implementation of this technique (\n * https://github.com/google/safe-html-types/blob/master/doc/safehtml-types.md).\n * The TrustedTypes polyfill in API-only mode could also be used as a basis\n * for this technique (https://github.com/WICG/trusted-types).\n *\n * @param node The HTML node (usually either a #text node or an Element) that\n * is being written to. Note that this is just an exemplar node, the write\n * may take place against another instance of the same class of node.\n * @param name The name of an attribute or property (for example, 'href').\n * @param type Indicates whether the write that's about to be performed will\n * be to a property or a node.\n * @return A function that will sanitize this class of writes.\n */\nexport type SanitizerFactory = (\n node: Node,\n name: string,\n type: 'property' | 'attribute'\n) => ValueSanitizer;\n\n/**\n * A function which can sanitize values that will be written to a specific kind\n * of DOM sink.\n *\n * See SanitizerFactory.\n *\n * @param value The value to sanitize. Will be the actual value passed into\n * the lit-html template literal, so this could be of any type.\n * @return The value to write to the DOM. Usually the same as the input value,\n * unless sanitization is needed.\n */\nexport type ValueSanitizer = (value: unknown) => unknown;\n\nconst identityFunction: ValueSanitizer = (value: unknown) => value;\nconst noopSanitizer: SanitizerFactory = (\n _node: Node,\n _name: string,\n _type: 'property' | 'attribute'\n) => identityFunction;\n\n/** Sets the global sanitizer factory. */\nconst setSanitizer = (newSanitizer: SanitizerFactory) => {\n if (!ENABLE_EXTRA_SECURITY_HOOKS) {\n return;\n }\n if (sanitizerFactoryInternal !== noopSanitizer) {\n throw new Error(\n `Attempted to overwrite existing lit-html security policy.` +\n ` setSanitizeDOMValueFactory should be called at most once.`\n );\n }\n sanitizerFactoryInternal = newSanitizer;\n};\n\n/**\n * Only used in internal tests, not a part of the public API.\n */\nconst _testOnlyClearSanitizerFactoryDoNotCallOrElse = () => {\n sanitizerFactoryInternal = noopSanitizer;\n};\n\nconst createSanitizer: SanitizerFactory = (node, name, type) => {\n return sanitizerFactoryInternal(node, name, type);\n};\n\n// Added to an attribute name to mark the attribute as bound so we can find\n// it easily.\nconst boundAttributeSuffix = '$lit$';\n\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 = `lit$${String(Math.random()).slice(9)}$`;\n\n// String used to tell if a comment is a marker comment\nconst markerMatch = '?' + marker;\n\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}>`;\n\nconst d =\n NODE_MODE && global.document === undefined\n ? ({\n createTreeWalker() {\n return {};\n },\n } as unknown as Document)\n : document;\n\n// Creates a dynamic marker. We never have to search for these in the DOM.\nconst createMarker = () => d.createComment('');\n\n// https://tc39.github.io/ecma262/#sec-typeof-operator\ntype Primitive = null | undefined | boolean | number | string | symbol | bigint;\nconst isPrimitive = (value: unknown): value is Primitive =>\n value === null || (typeof value != 'object' && typeof value != 'function');\nconst isArray = Array.isArray;\nconst isIterable = (value: unknown): value is Iterable =>\n isArray(value) ||\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (value as any)?.[Symbol.iterator] === 'function';\n\nconst SPACE_CHAR = `[ \\t\\n\\f\\r]`;\nconst ATTR_VALUE_CHAR = `[^ \\t\\n\\f\\r\"'\\`<>=]`;\nconst NAME_CHAR = `[^\\\\s\"'>=/]`;\n\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/**\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;\n\nconst commentEndRegex = /-->/g;\n/**\n * Comments not started with /g;\n/**\n * Comments not started with /g;var Xe=/>/g;var N=RegExp(`>|${we}(?:([^\\s"'>=/]+)(${we}*=${we}*(?:[^ -\f\r"'\`<>=]|("|')|))|$)`,"g");var Ge=/'/g;var Ze=/"/g;var st=/^(?:script|style|textarea|title)$/i;var nt=r=>(e,...t)=>({_$litType$:r,strings:e,values:t});var Pe=nt(1);var it=nt(2);var Z=Symbol.for("lit-noChange");var d=Symbol.for("lit-nothing");var Ye=new WeakMap;var M=I.createTreeWalker(I,129);function ot(r,e){if(!Array.isArray(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==Qe?Qe.createHTML(e):e}var Dt=(r,e)=>{const t=r.length-1,s=[];let n,i=2===e?"":"",o=Q;for(let a=0;a"===f[0]?(o=n!=null?n:Q,l=-1):void 0===f[1]?l=-2:(l=o.lastIndex-f[2].length,u=f[1],o=void 0===f[3]?N:'"'===f[3]?Ze:Ge):o===Ze||o===Ge?o=N:o===Je||o===Xe?o=Q:(o=N,n=void 0);const _=o===N&&r[a+1].startsWith("/>")?" ":"";i+=o===Q?c+Tt:l>=0?(s.push(u),c.slice(0,l)+et+c.slice(l)+T+_):c+T+(-2===l?a:_)}return[ot(r,i+(r[t]||"")+(2===e?"":"")),s]};var Y=class r{constructor({strings:e,_$litType$:t},s){let n;this.parts=[];let i=0,o=0;const a=e.length-1,c=this.parts,[u,f]=Dt(e,t);if(this.el=r.createElement(u,s),M.currentNode=this.el.content,2===t){const l=this.el.content.firstChild;l.replaceWith(...l.childNodes)}for(;null!==(n=M.nextNode())&&c.length0){n.textContent=ne?ne.emptyScript:"";for(let _=0;_2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=d}_$AI(e,t=this,s,n){const i=this.strings;let o=false;if(void 0===i)e=L(this,e,t,0),o=!G(e)||e!==this._$AH&&e!==Z,o&&(this._$AH=e);else{const a=e;let c,u;for(e=i[0],c=0;c{var i,o;const s=(i=t==null?void 0:t.renderBefore)!=null?i:e;let n=s._$litPart$;if(void 0===n){const a=(o=t==null?void 0:t.renderBefore)!=null?o:null;s._$litPart$=n=new K(e.insertBefore(X(),a),a,void 0,t!=null?t:{})}return n._$AI(r),n};var Nt={data:""};var Mt=r=>"object"==typeof window?((r?r.querySelector("#_goober"):window._goober)||Object.assign((r||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:r||Nt;var It=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g;var zt=/\/\*[^]*?\*\/| +/g;var at=/\n+/g;var z=(r,e)=>{let t="",s="",n="";for(let i in r){let o=r[i];"@"==i[0]?"i"==i[1]?t=i+" "+o+";":s+="f"==i[1]?z(o,i):i+"{"+z(o,"k"==i[1]?"":e)+"}":"object"==typeof o?s+=z(o,e?e.replace(/([^,])+/g,a=>i.replace(/(^:.*)|([^,])+/g,c=>/&/.test(c)?c.replace(/&/g,a):a?a+" "+c:c)):i):null!=o&&(i=/^--/.test(i)?i:i.replace(/[A-Z]/g,"-$&").toLowerCase(),n+=z.p?z.p(i,o):i+":"+o+";")}return t+(e&&n?e+"{"+n+"}":n)+s};var P={};var ct=r=>{if("object"==typeof r){let e="";for(let t in r)e+=t+ct(r[t]);return e}return r};var Ft=(r,e,t,s,n)=>{let i=ct(r),o=P[i]||(P[i]=(c=>{let u=0,f=11;for(;u>>0;return"go"+f})(i));if(!P[o]){let c=i!==r?r:(u=>{let f,l,h=[{}];for(;f=It.exec(u.replace(zt,""));)f[4]?h.shift():f[3]?(l=f[3].replace(at," ").trim(),h.unshift(h[0][l]=h[0][l]||{})):h[0][f[1]]=f[2].replace(at," ").trim();return h[0]})(r);P[o]=z(n?{["@keyframes "+o]:c}:c,t?"":"."+o)}let a=t&&P.g?P.g:null;return t&&(P.g=P[o]),((c,u,f,l)=>{l?u.data=u.data.replace(l,c):-1===u.data.indexOf(c)&&(u.data=f?c+u.data:u.data+c)})(P[o],e,s,a),o};var Ht=(r,e,t)=>r.reduce((s,n,i)=>{let o=e[i];if(o&&o.call){let a=o(t),c=a&&a.props&&a.props.className||/^go/.test(a)&&a;o=c?"."+c:a&&"object"==typeof a?a.props?"":z(a,""):false===a?"":a}return s+n+(null==o?"":o)},"");function ie(r){let e=this||{},t=r.call?r(e.p):r;return Ft(t.unshift?t.raw?Ht(t,[].slice.call(arguments,1),e.p):t.reduce((s,n)=>Object.assign(s,n&&n.call?n(e.p):n),{}):t,Mt(e.target),e.g,e.o,e.k)}var rr=ie.bind({g:1});var sr=ie.bind({k:1});var dt=Symbol.for("immer-nothing");var ut=Symbol.for("immer-draftable");var g=Symbol.for("immer-state");var Ut=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.","Immer forbids 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 an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(r){return`'original' expects a draft, got: ${r}`}]:[];function m(r,...e){if(true){const t=Ut[r];const s=typeof t==="function"?t.apply(null,e):t;throw new Error(`[Immer] ${s}`)}throw new Error(`[Immer] minified error nr: ${r}. Full error at: https://bit.ly/3cXEKWf`)}var q=Object.getPrototypeOf;function W(r){return!!r&&!!r[g]}function H(r){var e;if(!r)return false;return _t(r)||Array.isArray(r)||!!r[ut]||!!((e=r.constructor)==null?void 0:e[ut])||ue(r)||le(r)}var Rt=Object.prototype.constructor.toString();function _t(r){if(!r||typeof r!=="object")return false;const e=q(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)===Rt}function ee(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[g];return e?e.type_:Array.isArray(r)?1:ue(r)?2:le(r)?3:0}function De(r,e){return ce(r)===2?r.has(e):Object.prototype.hasOwnProperty.call(r,e)}function mt(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 kt(r,e){if(r===e){return r!==0||1/r===1/e}else{return r!==r&&e!==e}}function ue(r){return r instanceof Map}function le(r){return r instanceof Set}function F(r){return r.copy_||r.base_}function Ne(r,e){if(ue(r)){return new Map(r)}if(le(r)){return new Set(r)}if(Array.isArray(r))return Array.prototype.slice.call(r);if(!e&&_t(r)){if(!q(r)){const n=Object.create(null);return Object.assign(n,r)}return C({},r)}const t=Object.getOwnPropertyDescriptors(r);delete t[g];let s=Reflect.ownKeys(t);for(let n=0;n1){r.set=r.add=r.clear=r.delete=Lt}Object.freeze(r);if(e)ee(r,(t,s)=>He(s,true),true);return r}function Lt(){m(2)}function fe(r){return Object.isFrozen(r)}var Vt={};function U(r){const e=Vt[r];if(!e){m(0,r)}return e}var te;function bt(){return te}function qt(r,e){return{drafts_:[],parent_:r,immer_:e,canAutoFreeze_:true,unfinalizedDrafts_:0}}function lt(r,e){if(e){U("Patches");r.patches_=[];r.inversePatches_=[];r.patchListener_=e}}function Me(r){Ie(r);r.drafts_.forEach(Wt);r.drafts_=null}function Ie(r){if(r===te){te=r.parent_}}function ft(r){return te=qt(te,r)}function Wt(r){const e=r[g];if(e.type_===0||e.type_===1)e.revoke_();else e.revoked_=true}function ht(r,e){e.unfinalizedDrafts_=e.drafts_.length;const t=e.drafts_[0];const s=r!==void 0&&r!==t;if(s){if(t[g].modified_){Me(e);m(4)}if(H(r)){r=oe(e,r);if(!e.parent_)ae(e,r)}if(e.patches_){U("Patches").generateReplacementPatches_(t[g].base_,r,e.patches_,e.inversePatches_)}}else{r=oe(e,t,[])}Me(e);if(e.patches_){e.patchListener_(e.patches_,e.inversePatches_)}return r!==dt?r:void 0}function oe(r,e,t){if(fe(e))return e;const s=e[g];if(!s){ee(e,(n,i)=>pt(r,s,e,n,i,t),true);return e}if(s.scope_!==r)return e;if(!s.modified_){ae(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}ee(i,(a,c)=>pt(r,s,n,a,c,t,o));ae(r,n,false);if(t&&r.patches_){U("Patches").generatePatches_(s,t,r.patches_,r.inversePatches_)}}return s.copy_}function pt(r,e,t,s,n,i,o){if(n===t)m(5);if(W(n)){const a=i&&e&&e.type_!==3&&!De(e.assigned_,s)?i.concat(s):void 0;const c=oe(r,n,a);mt(t,s,c);if(W(c)){r.canAutoFreeze_=false}else return}else if(o){t.add(n)}if(H(n)&&!fe(n)){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1){return}oe(r,n);if(!e||!e.scope_.parent_)ae(r,n)}}function ae(r,e,t=false){if(!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_){He(e,t)}}function Bt(r,e){const t=Array.isArray(r);const s={type_:t?1:0,scope_:e?e.scope_:bt(),modified_:false,finalized_:false,assigned_:{},parent_:e,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:false};let n=s;let i=Ue;if(t){n=[s];i=re}const{revoke:o,proxy:a}=Proxy.revocable(n,i);s.draft_=a;s.revoke_=o;return a}var Ue={get(r,e){if(e===g)return r;const t=F(r);if(!De(t,e)){return Qt(r,t,e)}const s=t[e];if(r.finalized_||!H(s)){return s}if(s===Te(r.base_,e)){je(r);return r.copy_[e]=Fe(s,r)}return s},has(r,e){return e in F(r)},ownKeys(r){return Reflect.ownKeys(F(r))},set(r,e,t){const s=yt(F(r),e);if(s==null?void 0:s.set){s.set.call(r.draft_,t);return true}if(!r.modified_){const n=Te(F(r),e);const i=n==null?void 0:n[g];if(i&&i.base_===t){r.copy_[e]=t;r.assigned_[e]=false;return true}if(kt(t,n)&&(t!==void 0||De(r.base_,e)))return true;je(r);ze(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(Te(r.base_,e)!==void 0||e in r.base_){r.assigned_[e]=false;je(r);ze(r)}else{delete r.assigned_[e]}if(r.copy_){delete r.copy_[e]}return true},getOwnPropertyDescriptor(r,e){const t=F(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(){m(11)},getPrototypeOf(r){return q(r.base_)},setPrototypeOf(){m(12)}};var re={};ee(Ue,(r,e)=>{re[r]=function(){arguments[0]=arguments[0][0];return e.apply(this,arguments)}});re.deleteProperty=function(r,e){if(isNaN(parseInt(e)))m(13);return re.set.call(this,r,e,void 0)};re.set=function(r,e,t){if(e!=="length"&&isNaN(parseInt(e)))m(14);return Ue.set.call(this,r[0],e,t,r[0])};function Te(r,e){const t=r[g];const s=t?F(t):r;return s[e]}function Qt(r,e,t){var n;const s=yt(e,t);return s?`value`in s?s.value:(n=s.get)==null?void 0:n.call(r.draft_):void 0}function yt(r,e){if(!(e in r))return void 0;let t=q(r);while(t){const s=Object.getOwnPropertyDescriptor(t,e);if(s)return s;t=q(t)}return void 0}function ze(r){if(!r.modified_){r.modified_=true;if(r.parent_){ze(r.parent_)}}}function je(r){if(!r.copy_){r.copy_=Ne(r.base_,r.scope_.immer_.useStrictShallowCopy_)}}var Jt=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 a(c=i,...u){return o.produce(c,f=>t.call(this,f,...u))}}if(typeof t!=="function")m(6);if(s!==void 0&&typeof s!=="function")m(7);let n;if(H(e)){const i=ft(this);const o=Fe(e,void 0);let a=true;try{n=t(o);a=false}finally{if(a)Me(i);else Ie(i)}lt(i,s);return ht(n,i)}else if(!e||typeof e!=="object"){n=t(e);if(n===void 0)n=e;if(n===dt)n=void 0;if(this.autoFreeze_)He(n,true);if(s){const i=[];const o=[];U("Patches").generateReplacementPatches_(e,n,i,o);s(i,o)}return n}else m(1,e)};this.produceWithPatches=(e,t)=>{if(typeof e==="function"){return(o,...a)=>this.produceWithPatches(o,c=>e(c,...a))}let s,n;const i=this.produce(e,t,(o,a)=>{s=o;n=a});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(!H(r))m(8);if(W(r))r=Xt(r);const e=ft(this);const t=Fe(r,void 0);t[g].isManual_=true;Ie(e);return t}finishDraft(r,e){const t=r&&r[g];if(!t||!t.isManual_)m(9);const{scope_:s}=t;lt(s,e);return ht(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=U("Patches").applyPatches_;if(W(r)){return s(r,e)}return this.produce(r,n=>s(n,e))}};function Fe(r,e){const t=ue(r)?U("MapSet").proxyMap_(r,e):le(r)?U("MapSet").proxySet_(r,e):Bt(r,e);const s=e?e.scope_:bt();s.drafts_.push(t);return t}function Xt(r){if(!W(r))m(10,r);return gt(r)}function gt(r){if(!H(r)||fe(r))return r;const e=r[g];let t;if(e){if(!e.modified_)return e.base_;e.finalized_=true;t=Ne(r,e.scope_.immer_.useStrictShallowCopy_)}else{t=Ne(r,true)}ee(t,(s,n)=>{mt(t,s,gt(n))});if(e){e.finalized_=false}return t}var v=new Jt;var R=v.produce;var ir=v.produceWithPatches.bind(v);var or=v.setAutoFreeze.bind(v);var ar=v.setUseStrictShallowCopy.bind(v);var cr=v.applyPatches.bind(v);var ur=v.createDraft.bind(v);var lr=v.finishDraft.bind(v);var Re=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 b=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 Re(n);let o=()=>{};try{o=this.subscribeCallback(i)}catch(a){if(i.error){i.error(a)}else{console.error("[Cami.js] Error in Subscriber:",a)}return}i.addTeardown(o);this._observers.push(i);return{unsubscribe:()=>i.unsubscribe(),complete:()=>i.complete(),error:a=>i.error(a)}}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=class extends b{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();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)}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)}}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);this.state=R(this.state,n=>{s(n,t)});this._observers.forEach(n=>n.next(this.state));if(this.devTools){this.devTools.send(e,this.state)}}};var Gt=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 a=new r(e);a.init=()=>{if(n){const c=localStorage.getItem(s);const u=localStorage.getItem(`${s}-expiry`);const f=new Date().getTime();if(c&&u){const l=f>=parseInt(u,10);if(!l){a.state=JSON.parse(c)}else{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`)}}}};a.init();a.reset=()=>{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`);a.state=e;a._observers.forEach(c=>c.next(a.state))};a.subscribe(c=>{const u=new Date().getTime();const f=u+o;localStorage.setItem(s,JSON.stringify(c));localStorage.setItem(`${s}-expiry`,f.toString())});return a}};var vt=(r,e={})=>{const t={localStorage:true,name:"cami-store",expiry:864e5};const s=C(C({},t),e);if(s.localStorage){const n=Gt(j)(r,s);return n}else{return new j(r)}};var w=class r extends b{static from(e){if(e instanceof b){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=ve(e),i,o,a;i=!(o=yield n.next()).done;i=false){const c=o.value;if(s)return;t.next(c)}}catch(o){a=[o]}finally{try{i&&(o=n.return)&&(yield o.call(n))}finally{if(a)throw a[0]}}t.complete()}catch(c){t.error(c)}}))();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:a=>{i=e(i,a)},error:a=>n(a),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 a=o.subscribe({next:c=>t.next(c),error:c=>t.error(c),complete:()=>{s.delete(a);if(s.size===0){t.complete()}}});s.add(a)},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:a=>t.next(a),error:a=>t.error(a),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 A(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 b){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=ve(e),s,n,i;s=!(n=yield t.next()).done;s=false){const o=n.value;this._observers.forEach(a=>a.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(a=>a.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:a=>{if(!n){n=true;const c=e(a);s=c.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(a)}},error:a=>t.error(a),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:a=>{s[o]=a;if(!s.includes(void 0)){t.next([...s])}},error:a=>t.error(a),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 B={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 p(r,...e){if(B.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={current:null};var A=class extends b{constructor(e=null,t=null,{last:s=false,name:n=null}={}){super();if(s){this._lastObserver=t}else{this._observers.push(t)}this._value=R(e,i=>{});this._pendingUpdates=[];this._updateScheduled=false;this._name=n}get value(){if(D.current!=null){D.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=R(this._value,t)}else{this._value=t(this._value)}}if(e!==this._value){this._notifyObservers();if(B.events.isEnabled&&typeof window!=="undefined"){const t=new CustomEvent("cami:state:change",{detail:{name:this._name,oldValue:e,newValue:this._value}});window.dispatchEvent(t)}p("cami:state:change",this._name,e,this._value)}this._updateScheduled=false}toStream(){const e=new w;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 ke=class extends A{constructor(e){super(null);this.computeFn=e;this.dependencies=new Set;this.subscriptions=new Map;this._compute()}get value(){if(D.current){D.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)}}};D.current=e;const t=this.computeFn();D.current=null;if(t!==this._value){this._value=t;this._notifyObservers()}}dispose(){this.subscriptions.forEach(e=>{e.unsubscribe()})}};var he=function(r){return new ke(r)};var pe=function(r){let e=()=>{};let t=new Set;let s=new Map;const n={addDependency:a=>{if(!t.has(a)){const c=a.onValue(i);t.add(a);s.set(a,c)}}};const i=()=>{e();D.current=n;e=r()||(()=>{});D.current=null};if(typeof window!=="undefined"){requestAnimationFrame(i)}else{setTimeout(i,0)}const o=()=>{s.forEach(a=>{a.unsubscribe()});e()};return o};var E=new Map;var de=class extends HTMLElement{constructor(){super();this.onCreate();this._unsubscribers=new Map;this._computed=he.bind(this);this.effect=pe.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:a=>a;n=R(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 j)){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 w(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:a=null,gcTime:c=1e3*60*5,retry:u=3,retryDelay:f=l=>Math.pow(2,l)*1e3}){const l=Array.isArray(e)?e.map(x=>typeof x==="object"?JSON.stringify(x):x).join(":"):e;this._queryFunctions.set(l,t);p("query","Starting query with key:",l);const h=this._observable({data:null,status:"pending",fetchStatus:"idle",error:null,lastUpdated:E.has(l)?E.get(l).lastUpdated:null},l);const _=this._observableProxy(h);const $=(x=0)=>k(this,null,function*(){const Le=Date.now();const be=E.get(l);if(be&&Le-be.lastUpdated{S.data=be.data;S.status="success";S.fetchStatus="idle"})}else{p("fetchData (else)","Fetching data for key:",l);try{h.update(O=>{O.status="pending";O.fetchStatus="fetching"});const S=yield t();E.set(l,{data:S,lastUpdated:Le});h.update(O=>{O.data=S;O.status="success";O.fetchStatus="idle"})}catch(S){p("fetchData (catch)","Fetch error for key:",l,S);if(x$(x+1),f(x))}else{h.update(O=>{O.error={message:S.message};O.status="error";O.fetchStatus="idle"})}}}});if(i){p("query","Setting up refetch on mount for key:",l);$()}if(n){p("query","Setting up refetch on window focus for key:",l);const x=()=>$();window.addEventListener("focus",x);this._unsubscribers.set(`focus:${l}`,()=>window.removeEventListener("focus",x))}if(o){p("query","Setting up refetch on reconnect for key:",l);window.addEventListener("online",$);this._unsubscribers.set(`online:${l}`,()=>window.removeEventListener("online",$))}if(a){p("query","Setting up refetch interval for key:",l);const x=setInterval($,a);this._unsubscribers.set(`interval:${l}`,()=>clearInterval(x))}const wt=setTimeout(()=>{E.delete(l)},c);this._unsubscribers.set(`gc:${l}`,()=>clearTimeout(wt));return _}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 a=this._observableProxy(o);const c=u=>k(this,null,function*(){p("mutation","Starting mutation for variables:",u);let f;const l=o.value;if(t){p("mutation","Performing optimistic update for variables:",u);f=t(u,l);o.update(h=>{h.data=f.optimisticData;h.status="pending";h.error=null})}else{p("mutation","Performing mutation without optimistic update for variables:",u);o.update(h=>{h.status="pending";h.error=null})}try{const h=yield e(u);o.update(_=>{_.data=h;_.status="success"});if(n){n(h,u,f)}p("mutation","Mutation successful for variables:",u,h)}catch(h){p("mutation","Mutation error for variables:",u,h);o.update(_=>{_.error={message:h.message};_.status="error";if(!s&&f&&f.rollback){p("mutation","Rolling back mutation for variables:",u);f.rollback()}});if(s){s(h,u,f)}}finally{if(!o.value.isSettled){o.update(h=>{h.isSettled=true});if(i){p("mutation","Calling onSettled for variables:",u);i(o.value.data,o.value.error,u,f)}}}});a.mutate=c;a.reset=()=>{o.update(u=>{u.data=null;u.status="idle";u.error=null;u.isSettled=false})};return a}invalidateQueries(e){const t=Array.isArray(e)?e.join(":"):e;p("invalidateQueries","Invalidating query with key:",t);E.delete(t);this._refetchQuery(t)}onCreate(){}connectedCallback(){this._setup({infer:true});this.effect(()=>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 A)){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 A)){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){if(!(e instanceof A)){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}})}_setup(e){if(e.infer===true){Object.keys(this).forEach(t=>{if(typeof this[t]!=="function"&&!t.startsWith("_")){if(this[t]instanceof b){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=null){if(!this._isAllowedType(e)){const n=Object.prototype.toString.call(e);throw new Error(`[Cami.js] The type ${n} of initialValue is not allowed in observables.`)}const s=new A(e);this._registerObservables(s);return s}_refetchQuery(e){p("_refetchQuery","Refetching query with key:",e);const t=this._queryFunctions.get(e);if(t){p("_refetchQuery","Found query function for key:",e);const s=E.get(e)||{data:void 0,status:"idle",error:null};E.set(e,ge(C({},s),{status:"pending",error:null}));t().then(n=>{E.set(e,{data:n,status:"success",error:null,lastUpdated:Date.now()});p("_refetchQuery","Refetch successful for key:",e,n)}).catch(n=>{if(s.data!==void 0){p("_refetchQuery","Rolling back refetch for key:",e);E.set(e,s)}E.set(e,ge(C({},s),{status:"error",error:n}))}).finally(()=>{this.query({queryKey:e,queryFn:t});p("_refetchQuery","Refetch complete for key:",e)})}}_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 A)){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();Ce(e,this)}};var _e=class extends w{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 w(s=>{const n=i=>{s.next(i)};this.element.addEventListener(e,n,t);return()=>{this.element.removeEventListener(e,n,t)}})}};var me=class extends w{constructor(){super(...arguments);Be(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 y=r=>{if(typeof r==="string"){return y.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()}})};y.get=(r,e={})=>{e.url=r;e.method="GET";return y(e)};y.post=(r,e={},t={})=>{t.url=r;t.data=e;t.method="POST";return y(t)};y.put=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PUT";return y(t)};y.patch=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PATCH";return y(t)};y.delete=(r,e={})=>{e.url=r;e.method="DELETE";return y(e)};y.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:Zt,events:Yt}=B;return Ct(Kt);})(); +\f\r"'\`<>=]|("|')|))|$)`,"g");var Ge=/'/g;var Ze=/"/g;var st=/^(?:script|style|textarea|title)$/i;var nt=r=>(e,...t)=>({_$litType$:r,strings:e,values:t});var Pe=nt(1);var it=nt(2);var Z=Symbol.for("lit-noChange");var d=Symbol.for("lit-nothing");var Ye=new WeakMap;var M=I.createTreeWalker(I,129);function ot(r,e){if(!Array.isArray(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==Qe?Qe.createHTML(e):e}var Dt=(r,e)=>{const t=r.length-1,s=[];let n,i=2===e?"":"",o=Q;for(let a=0;a"===f[0]?(o=n!=null?n:Q,l=-1):void 0===f[1]?l=-2:(l=o.lastIndex-f[2].length,u=f[1],o=void 0===f[3]?N:'"'===f[3]?Ze:Ge):o===Ze||o===Ge?o=N:o===Je||o===Xe?o=Q:(o=N,n=void 0);const _=o===N&&r[a+1].startsWith("/>")?" ":"";i+=o===Q?c+Tt:l>=0?(s.push(u),c.slice(0,l)+et+c.slice(l)+T+_):c+T+(-2===l?a:_)}return[ot(r,i+(r[t]||"")+(2===e?"":"")),s]};var Y=class r{constructor({strings:e,_$litType$:t},s){let n;this.parts=[];let i=0,o=0;const a=e.length-1,c=this.parts,[u,f]=Dt(e,t);if(this.el=r.createElement(u,s),M.currentNode=this.el.content,2===t){const l=this.el.content.firstChild;l.replaceWith(...l.childNodes)}for(;null!==(n=M.nextNode())&&c.length0){n.textContent=ne?ne.emptyScript:"";for(let _=0;_2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=d}_$AI(e,t=this,s,n){const i=this.strings;let o=false;if(void 0===i)e=L(this,e,t,0),o=!G(e)||e!==this._$AH&&e!==Z,o&&(this._$AH=e);else{const a=e;let c,u;for(e=i[0],c=0;c{var i,o;const s=(i=t==null?void 0:t.renderBefore)!=null?i:e;let n=s._$litPart$;if(void 0===n){const a=(o=t==null?void 0:t.renderBefore)!=null?o:null;s._$litPart$=n=new K(e.insertBefore(X(),a),a,void 0,t!=null?t:{})}return n._$AI(r),n};var Nt={data:""};var Mt=r=>"object"==typeof window?((r?r.querySelector("#_goober"):window._goober)||Object.assign((r||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:r||Nt;var It=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g;var zt=/\/\*[^]*?\*\/| +/g;var at=/\n+/g;var z=(r,e)=>{let t="",s="",n="";for(let i in r){let o=r[i];"@"==i[0]?"i"==i[1]?t=i+" "+o+";":s+="f"==i[1]?z(o,i):i+"{"+z(o,"k"==i[1]?"":e)+"}":"object"==typeof o?s+=z(o,e?e.replace(/([^,])+/g,a=>i.replace(/(^:.*)|([^,])+/g,c=>/&/.test(c)?c.replace(/&/g,a):a?a+" "+c:c)):i):null!=o&&(i=/^--/.test(i)?i:i.replace(/[A-Z]/g,"-$&").toLowerCase(),n+=z.p?z.p(i,o):i+":"+o+";")}return t+(e&&n?e+"{"+n+"}":n)+s};var P={};var ct=r=>{if("object"==typeof r){let e="";for(let t in r)e+=t+ct(r[t]);return e}return r};var Ft=(r,e,t,s,n)=>{let i=ct(r),o=P[i]||(P[i]=(c=>{let u=0,f=11;for(;u>>0;return"go"+f})(i));if(!P[o]){let c=i!==r?r:(u=>{let f,l,h=[{}];for(;f=It.exec(u.replace(zt,""));)f[4]?h.shift():f[3]?(l=f[3].replace(at," ").trim(),h.unshift(h[0][l]=h[0][l]||{})):h[0][f[1]]=f[2].replace(at," ").trim();return h[0]})(r);P[o]=z(n?{["@keyframes "+o]:c}:c,t?"":"."+o)}let a=t&&P.g?P.g:null;return t&&(P.g=P[o]),((c,u,f,l)=>{l?u.data=u.data.replace(l,c):-1===u.data.indexOf(c)&&(u.data=f?c+u.data:u.data+c)})(P[o],e,s,a),o};var Ht=(r,e,t)=>r.reduce((s,n,i)=>{let o=e[i];if(o&&o.call){let a=o(t),c=a&&a.props&&a.props.className||/^go/.test(a)&&a;o=c?"."+c:a&&"object"==typeof a?a.props?"":z(a,""):false===a?"":a}return s+n+(null==o?"":o)},"");function ie(r){let e=this||{},t=r.call?r(e.p):r;return Ft(t.unshift?t.raw?Ht(t,[].slice.call(arguments,1),e.p):t.reduce((s,n)=>Object.assign(s,n&&n.call?n(e.p):n),{}):t,Mt(e.target),e.g,e.o,e.k)}var rr=ie.bind({g:1});var sr=ie.bind({k:1});var dt=Symbol.for("immer-nothing");var ut=Symbol.for("immer-draftable");var g=Symbol.for("immer-state");var Ut=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.","Immer forbids 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 an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(r){return`'original' expects a draft, got: ${r}`}]:[];function m(r,...e){if(true){const t=Ut[r];const s=typeof t==="function"?t.apply(null,e):t;throw new Error(`[Immer] ${s}`)}throw new Error(`[Immer] minified error nr: ${r}. Full error at: https://bit.ly/3cXEKWf`)}var q=Object.getPrototypeOf;function W(r){return!!r&&!!r[g]}function H(r){var e;if(!r)return false;return _t(r)||Array.isArray(r)||!!r[ut]||!!((e=r.constructor)==null?void 0:e[ut])||ue(r)||le(r)}var Rt=Object.prototype.constructor.toString();function _t(r){if(!r||typeof r!=="object")return false;const e=q(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)===Rt}function ee(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[g];return e?e.type_:Array.isArray(r)?1:ue(r)?2:le(r)?3:0}function De(r,e){return ce(r)===2?r.has(e):Object.prototype.hasOwnProperty.call(r,e)}function mt(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 kt(r,e){if(r===e){return r!==0||1/r===1/e}else{return r!==r&&e!==e}}function ue(r){return r instanceof Map}function le(r){return r instanceof Set}function F(r){return r.copy_||r.base_}function Ne(r,e){if(ue(r)){return new Map(r)}if(le(r)){return new Set(r)}if(Array.isArray(r))return Array.prototype.slice.call(r);if(!e&&_t(r)){if(!q(r)){const n=Object.create(null);return Object.assign(n,r)}return C({},r)}const t=Object.getOwnPropertyDescriptors(r);delete t[g];let s=Reflect.ownKeys(t);for(let n=0;n1){r.set=r.add=r.clear=r.delete=Lt}Object.freeze(r);if(e)ee(r,(t,s)=>He(s,true),true);return r}function Lt(){m(2)}function fe(r){return Object.isFrozen(r)}var Vt={};function U(r){const e=Vt[r];if(!e){m(0,r)}return e}var te;function bt(){return te}function qt(r,e){return{drafts_:[],parent_:r,immer_:e,canAutoFreeze_:true,unfinalizedDrafts_:0}}function lt(r,e){if(e){U("Patches");r.patches_=[];r.inversePatches_=[];r.patchListener_=e}}function Me(r){Ie(r);r.drafts_.forEach(Wt);r.drafts_=null}function Ie(r){if(r===te){te=r.parent_}}function ft(r){return te=qt(te,r)}function Wt(r){const e=r[g];if(e.type_===0||e.type_===1)e.revoke_();else e.revoked_=true}function ht(r,e){e.unfinalizedDrafts_=e.drafts_.length;const t=e.drafts_[0];const s=r!==void 0&&r!==t;if(s){if(t[g].modified_){Me(e);m(4)}if(H(r)){r=oe(e,r);if(!e.parent_)ae(e,r)}if(e.patches_){U("Patches").generateReplacementPatches_(t[g].base_,r,e.patches_,e.inversePatches_)}}else{r=oe(e,t,[])}Me(e);if(e.patches_){e.patchListener_(e.patches_,e.inversePatches_)}return r!==dt?r:void 0}function oe(r,e,t){if(fe(e))return e;const s=e[g];if(!s){ee(e,(n,i)=>pt(r,s,e,n,i,t),true);return e}if(s.scope_!==r)return e;if(!s.modified_){ae(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}ee(i,(a,c)=>pt(r,s,n,a,c,t,o));ae(r,n,false);if(t&&r.patches_){U("Patches").generatePatches_(s,t,r.patches_,r.inversePatches_)}}return s.copy_}function pt(r,e,t,s,n,i,o){if(n===t)m(5);if(W(n)){const a=i&&e&&e.type_!==3&&!De(e.assigned_,s)?i.concat(s):void 0;const c=oe(r,n,a);mt(t,s,c);if(W(c)){r.canAutoFreeze_=false}else return}else if(o){t.add(n)}if(H(n)&&!fe(n)){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1){return}oe(r,n);if(!e||!e.scope_.parent_)ae(r,n)}}function ae(r,e,t=false){if(!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_){He(e,t)}}function Bt(r,e){const t=Array.isArray(r);const s={type_:t?1:0,scope_:e?e.scope_:bt(),modified_:false,finalized_:false,assigned_:{},parent_:e,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:false};let n=s;let i=Ue;if(t){n=[s];i=re}const{revoke:o,proxy:a}=Proxy.revocable(n,i);s.draft_=a;s.revoke_=o;return a}var Ue={get(r,e){if(e===g)return r;const t=F(r);if(!De(t,e)){return Qt(r,t,e)}const s=t[e];if(r.finalized_||!H(s)){return s}if(s===Te(r.base_,e)){je(r);return r.copy_[e]=Fe(s,r)}return s},has(r,e){return e in F(r)},ownKeys(r){return Reflect.ownKeys(F(r))},set(r,e,t){const s=yt(F(r),e);if(s==null?void 0:s.set){s.set.call(r.draft_,t);return true}if(!r.modified_){const n=Te(F(r),e);const i=n==null?void 0:n[g];if(i&&i.base_===t){r.copy_[e]=t;r.assigned_[e]=false;return true}if(kt(t,n)&&(t!==void 0||De(r.base_,e)))return true;je(r);ze(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(Te(r.base_,e)!==void 0||e in r.base_){r.assigned_[e]=false;je(r);ze(r)}else{delete r.assigned_[e]}if(r.copy_){delete r.copy_[e]}return true},getOwnPropertyDescriptor(r,e){const t=F(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(){m(11)},getPrototypeOf(r){return q(r.base_)},setPrototypeOf(){m(12)}};var re={};ee(Ue,(r,e)=>{re[r]=function(){arguments[0]=arguments[0][0];return e.apply(this,arguments)}});re.deleteProperty=function(r,e){if(isNaN(parseInt(e)))m(13);return re.set.call(this,r,e,void 0)};re.set=function(r,e,t){if(e!=="length"&&isNaN(parseInt(e)))m(14);return Ue.set.call(this,r[0],e,t,r[0])};function Te(r,e){const t=r[g];const s=t?F(t):r;return s[e]}function Qt(r,e,t){var n;const s=yt(e,t);return s?`value`in s?s.value:(n=s.get)==null?void 0:n.call(r.draft_):void 0}function yt(r,e){if(!(e in r))return void 0;let t=q(r);while(t){const s=Object.getOwnPropertyDescriptor(t,e);if(s)return s;t=q(t)}return void 0}function ze(r){if(!r.modified_){r.modified_=true;if(r.parent_){ze(r.parent_)}}}function je(r){if(!r.copy_){r.copy_=Ne(r.base_,r.scope_.immer_.useStrictShallowCopy_)}}var Jt=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 a(c=i,...u){return o.produce(c,f=>t.call(this,f,...u))}}if(typeof t!=="function")m(6);if(s!==void 0&&typeof s!=="function")m(7);let n;if(H(e)){const i=ft(this);const o=Fe(e,void 0);let a=true;try{n=t(o);a=false}finally{if(a)Me(i);else Ie(i)}lt(i,s);return ht(n,i)}else if(!e||typeof e!=="object"){n=t(e);if(n===void 0)n=e;if(n===dt)n=void 0;if(this.autoFreeze_)He(n,true);if(s){const i=[];const o=[];U("Patches").generateReplacementPatches_(e,n,i,o);s(i,o)}return n}else m(1,e)};this.produceWithPatches=(e,t)=>{if(typeof e==="function"){return(o,...a)=>this.produceWithPatches(o,c=>e(c,...a))}let s,n;const i=this.produce(e,t,(o,a)=>{s=o;n=a});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(!H(r))m(8);if(W(r))r=Xt(r);const e=ft(this);const t=Fe(r,void 0);t[g].isManual_=true;Ie(e);return t}finishDraft(r,e){const t=r&&r[g];if(!t||!t.isManual_)m(9);const{scope_:s}=t;lt(s,e);return ht(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=U("Patches").applyPatches_;if(W(r)){return s(r,e)}return this.produce(r,n=>s(n,e))}};function Fe(r,e){const t=ue(r)?U("MapSet").proxyMap_(r,e):le(r)?U("MapSet").proxySet_(r,e):Bt(r,e);const s=e?e.scope_:bt();s.drafts_.push(t);return t}function Xt(r){if(!W(r))m(10,r);return gt(r)}function gt(r){if(!H(r)||fe(r))return r;const e=r[g];let t;if(e){if(!e.modified_)return e.base_;e.finalized_=true;t=Ne(r,e.scope_.immer_.useStrictShallowCopy_)}else{t=Ne(r,true)}ee(t,(s,n)=>{mt(t,s,gt(n))});if(e){e.finalized_=false}return t}var v=new Jt;var R=v.produce;var ir=v.produceWithPatches.bind(v);var or=v.setAutoFreeze.bind(v);var ar=v.setUseStrictShallowCopy.bind(v);var cr=v.applyPatches.bind(v);var ur=v.createDraft.bind(v);var lr=v.finishDraft.bind(v);var Re=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 b=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 Re(n);let o=()=>{};try{o=this.subscribeCallback(i)}catch(a){if(i.error){i.error(a)}else{console.error("[Cami.js] Error in Subscriber:",a)}return}i.addTeardown(o);this._observers.push(i);return{unsubscribe:()=>i.unsubscribe(),complete:()=>i.complete(),error:a=>i.error(a)}}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=class extends b{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();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)}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)}}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);this.state=R(this.state,n=>{s(n,t)});this._observers.forEach(n=>n.next(this.state));if(this.devTools){this.devTools.send(e,this.state)}}};var Gt=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 a=new r(e);a.init=()=>{if(n){const c=localStorage.getItem(s);const u=localStorage.getItem(`${s}-expiry`);const f=new Date().getTime();if(c&&u){const l=f>=parseInt(u,10);if(!l){a.state=JSON.parse(c)}else{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`)}}}};a.init();a.reset=()=>{localStorage.removeItem(s);localStorage.removeItem(`${s}-expiry`);a.state=e;a._observers.forEach(c=>c.next(a.state))};a.subscribe(c=>{const u=new Date().getTime();const f=u+o;localStorage.setItem(s,JSON.stringify(c));localStorage.setItem(`${s}-expiry`,f.toString())});return a}};var vt=(r,e={})=>{const t={localStorage:true,name:"cami-store",expiry:864e5};const s=C(C({},t),e);if(s.localStorage){const n=Gt(j)(r,s);return n}else{return new j(r)}};var w=class r extends b{static from(e){if(e instanceof b){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=ve(e),i,o,a;i=!(o=yield n.next()).done;i=false){const c=o.value;if(s)return;t.next(c)}}catch(o){a=[o]}finally{try{i&&(o=n.return)&&(yield o.call(n))}finally{if(a)throw a[0]}}t.complete()}catch(c){t.error(c)}}))();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:a=>{i=e(i,a)},error:a=>n(a),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 a=o.subscribe({next:c=>t.next(c),error:c=>t.error(c),complete:()=>{s.delete(a);if(s.size===0){t.complete()}}});s.add(a)},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:a=>t.next(a),error:a=>t.error(a),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 A(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 b){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=ve(e),s,n,i;s=!(n=yield t.next()).done;s=false){const o=n.value;this._observers.forEach(a=>a.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(a=>a.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:a=>{if(!n){n=true;const c=e(a);s=c.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(a)}},error:a=>t.error(a),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:a=>{s[o]=a;if(!s.includes(void 0)){t.next([...s])}},error:a=>t.error(a),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 B={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 p(r,...e){if(B.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={current:null};var A=class extends b{constructor(e=null,t=null,{last:s=false,name:n=null}={}){super();if(s){this._lastObserver=t}else{this._observers.push(t)}this._value=R(e,i=>{});this._pendingUpdates=[];this._updateScheduled=false;this._name=n}get value(){if(D.current!=null){D.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=R(this._value,t)}else{this._value=t(this._value)}}if(e!==this._value){this._notifyObservers();if(B.events.isEnabled&&typeof window!=="undefined"){const t=new CustomEvent("cami:state:change",{detail:{name:this._name,oldValue:e,newValue:this._value}});window.dispatchEvent(t)}p("cami:state:change",this._name,e,this._value)}this._updateScheduled=false}toStream(){const e=new w;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 ke=class extends A{constructor(e){super(null);this.computeFn=e;this.dependencies=new Set;this.subscriptions=new Map;this._compute()}get value(){if(D.current){D.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)}}};D.current=e;const t=this.computeFn();D.current=null;if(t!==this._value){this._value=t;this._notifyObservers()}}dispose(){this.subscriptions.forEach(e=>{e.unsubscribe()})}};var he=function(r){return new ke(r)};var pe=function(r){let e=()=>{};let t=new Set;let s=new Map;const n={addDependency:a=>{if(!t.has(a)){const c=a.onValue(i);t.add(a);s.set(a,c)}}};const i=()=>{e();D.current=n;e=r()||(()=>{});D.current=null};if(typeof window!=="undefined"){requestAnimationFrame(i)}else{setTimeout(i,0)}const o=()=>{s.forEach(a=>{a.unsubscribe()});e()};return o};var E=new Map;var de=class extends HTMLElement{constructor(){super();this.onCreate();this._unsubscribers=new Map;this._computed=he.bind(this);this.effect=pe.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:a=>a;n=R(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 j)){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 w(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:a=null,gcTime:c=1e3*60*5,retry:u=3,retryDelay:f=l=>Math.pow(2,l)*1e3}){const l=Array.isArray(e)?e.map(x=>typeof x==="object"?JSON.stringify(x):x).join(":"):e;this._queryFunctions.set(l,t);p("query","Starting query with key:",l);const h=this._observable({data:null,status:"pending",fetchStatus:"idle",error:null,lastUpdated:E.has(l)?E.get(l).lastUpdated:null},l);const _=this._observableProxy(h);const $=(x=0)=>k(this,null,function*(){const Le=Date.now();const be=E.get(l);if(be&&Le-be.lastUpdated{S.data=be.data;S.status="success";S.fetchStatus="idle"})}else{p("fetchData (else)","Fetching data for key:",l);try{h.update(O=>{O.status="pending";O.fetchStatus="fetching"});const S=yield t();E.set(l,{data:S,lastUpdated:Le});h.update(O=>{O.data=S;O.status="success";O.fetchStatus="idle"})}catch(S){p("fetchData (catch)","Fetch error for key:",l,S);if(x$(x+1),f(x))}else{h.update(O=>{O.error={message:S.message};O.status="error";O.fetchStatus="idle"})}}}});if(i){p("query","Setting up refetch on mount for key:",l);$()}if(n){p("query","Setting up refetch on window focus for key:",l);const x=()=>$();window.addEventListener("focus",x);this._unsubscribers.set(`focus:${l}`,()=>window.removeEventListener("focus",x))}if(o){p("query","Setting up refetch on reconnect for key:",l);window.addEventListener("online",$);this._unsubscribers.set(`online:${l}`,()=>window.removeEventListener("online",$))}if(a){p("query","Setting up refetch interval for key:",l);const x=setInterval($,a);this._unsubscribers.set(`interval:${l}`,()=>clearInterval(x))}const wt=setTimeout(()=>{E.delete(l)},c);this._unsubscribers.set(`gc:${l}`,()=>clearTimeout(wt));return _}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 a=this._observableProxy(o);const c=u=>k(this,null,function*(){p("mutation","Starting mutation for variables:",u);let f;const l=o.value;if(t){p("mutation","Performing optimistic update for variables:",u);f=t(u,l);o.update(h=>{h.data=f.optimisticData;h.status="pending";h.error=null})}else{p("mutation","Performing mutation without optimistic update for variables:",u);o.update(h=>{h.status="pending";h.error=null})}try{const h=yield e(u);o.update(_=>{_.data=h;_.status="success"});if(n){n(h,u,f)}p("mutation","Mutation successful for variables:",u,h)}catch(h){p("mutation","Mutation error for variables:",u,h);o.update(_=>{_.error={message:h.message};_.status="error";if(!s&&f&&f.rollback){p("mutation","Rolling back mutation for variables:",u);f.rollback()}});if(s){s(h,u,f)}}finally{if(!o.value.isSettled){o.update(h=>{h.isSettled=true});if(i){p("mutation","Calling onSettled for variables:",u);i(o.value.data,o.value.error,u,f)}}}});a.mutate=c;a.reset=()=>{o.update(u=>{u.data=null;u.status="idle";u.error=null;u.isSettled=false})};return a}invalidateQueries(e){const t=Array.isArray(e)?e.join(":"):e;p("invalidateQueries","Invalidating query with key:",t);E.delete(t);this._refetchQuery(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 A)){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 A)){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){if(!(e instanceof A)){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}})}_setup(e){if(e.infer===true){Object.keys(this).forEach(t=>{if(typeof this[t]!=="function"&&!t.startsWith("_")){if(this[t]instanceof b){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=null){if(!this._isAllowedType(e)){const n=Object.prototype.toString.call(e);throw new Error(`[Cami.js] The type ${n} of initialValue is not allowed in observables.`)}const s=new A(e);this._registerObservables(s);return s}_refetchQuery(e){p("_refetchQuery","Refetching query with key:",e);const t=this._queryFunctions.get(e);if(t){p("_refetchQuery","Found query function for key:",e);const s=E.get(e)||{data:void 0,status:"idle",error:null};E.set(e,ge(C({},s),{status:"pending",error:null}));t().then(n=>{E.set(e,{data:n,status:"success",error:null,lastUpdated:Date.now()});p("_refetchQuery","Refetch successful for key:",e,n)}).catch(n=>{if(s.data!==void 0){p("_refetchQuery","Rolling back refetch for key:",e);E.set(e,s)}E.set(e,ge(C({},s),{status:"error",error:n}))}).finally(()=>{this.query({queryKey:e,queryFn:t});p("_refetchQuery","Refetch complete for key:",e)})}}_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 A)){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();Ce(e,this)}};var _e=class extends w{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 w(s=>{const n=i=>{s.next(i)};this.element.addEventListener(e,n,t);return()=>{this.element.removeEventListener(e,n,t)}})}};var me=class extends w{constructor(){super(...arguments);Be(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 y=r=>{if(typeof r==="string"){return y.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()}})};y.get=(r,e={})=>{e.url=r;e.method="GET";return y(e)};y.post=(r,e={},t={})=>{t.url=r;t.data=e;t.method="POST";return y(t)};y.put=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PUT";return y(t)};y.patch=(r,e={},t={})=>{t.url=r;t.data=e;t.method="PATCH";return y(t)};y.delete=(r,e={})=>{e.url=r;e.method="DELETE";return y(e)};y.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:Zt,events:Yt}=B;return Ct(Kt);})(); /** * @license * Copyright (c) 2023 Kenn Costales diff --git a/docs/javascripts/cami.cdn.js.map b/docs/javascripts/cami.cdn.js.map index 99de1a47..0d4dd402 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", "../node_modules/lit-html/src/lit-html.ts", "../node_modules/goober/dist/goober.modern.js", "../node_modules/immer/src/utils/env.ts", "../node_modules/immer/src/utils/errors.ts", "../node_modules/immer/src/utils/common.ts", "../node_modules/immer/src/utils/plugins.ts", "../node_modules/immer/src/core/scope.ts", "../node_modules/immer/src/core/finalize.ts", "../node_modules/immer/src/core/proxy.ts", "../node_modules/immer/src/core/immerClass.ts", "../node_modules/immer/src/core/current.ts", "../node_modules/immer/src/plugins/patches.ts", "../node_modules/immer/src/plugins/mapset.ts", "../node_modules/immer/src/immer.ts", "../src/observables/observable.js", "../src/observables/observable-store.js", "../src/observables/observable-stream.js", "../src/config.js", "../src/trace.js", "../src/observables/observable-state.js", "../src/reactive-element.js", "../src/observables/observable-element.js", "../src/http.js"], - "sourcesContent": ["/**\n * @license\n * Copyright (c) 2023 Kenn Costales\n * MIT License\n */\n\n/**\n * @module cami\n */\nimport { html, render, svg } from 'lit-html';\nimport { css } from 'goober';\nimport { produce } from \"immer\"\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 'lit-html'\n * @exports svg - The svg function from 'lit-html'\n * @exports css - The css function from 'goober'\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, css, ReactiveElement, ObservableStream, ObservableElement, Observable, ObservableState, ObservableStore, http, debug, events, computed, effect };\n", "/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n// IMPORTANT: these imports must be type-only\nimport type {Directive, DirectiveResult, PartInfo} from './directive.js';\n\nconst DEV_MODE = true;\nconst ENABLE_EXTRA_SECURITY_HOOKS = true;\nconst ENABLE_SHADYDOM_NOPATCH = true;\nconst NODE_MODE = false;\n\n// Allows minifiers to rename references to globalThis\nconst global = globalThis;\n\n/**\n * Contains types that are part of the unstable debug API.\n *\n * Everything in this API is not stable and may change or be removed in the future,\n * even on patch releases.\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace LitUnstable {\n /**\n * When Lit is running in dev mode and `window.emitLitDebugLogEvents` is true,\n * we will emit 'lit-debug' events to window, with live details about the update and render\n * lifecycle. These can be useful for writing debug tooling and visualizations.\n *\n * Please be aware that running with window.emitLitDebugLogEvents has performance overhead,\n * making certain operations that are normally very cheap (like a no-op render) much slower,\n * because we must copy data and dispatch events.\n */\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace DebugLog {\n export type Entry =\n | TemplatePrep\n | TemplateInstantiated\n | TemplateInstantiatedAndUpdated\n | TemplateUpdating\n | BeginRender\n | EndRender\n | CommitPartEntry\n | SetPartValue;\n export interface TemplatePrep {\n kind: 'template prep';\n template: Template;\n strings: TemplateStringsArray;\n clonableTemplate: HTMLTemplateElement;\n parts: TemplatePart[];\n }\n export interface BeginRender {\n kind: 'begin render';\n id: number;\n value: unknown;\n container: HTMLElement | DocumentFragment;\n options: RenderOptions | undefined;\n part: ChildPart | undefined;\n }\n export interface EndRender {\n kind: 'end render';\n id: number;\n value: unknown;\n container: HTMLElement | DocumentFragment;\n options: RenderOptions | undefined;\n part: ChildPart;\n }\n export interface TemplateInstantiated {\n kind: 'template instantiated';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n fragment: Node;\n parts: Array;\n values: unknown[];\n }\n export interface TemplateInstantiatedAndUpdated {\n kind: 'template instantiated and updated';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n fragment: Node;\n parts: Array;\n values: unknown[];\n }\n export interface TemplateUpdating {\n kind: 'template updating';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n parts: Array;\n values: unknown[];\n }\n export interface SetPartValue {\n kind: 'set part';\n part: Part;\n value: unknown;\n valueIndex: number;\n values: unknown[];\n templateInstance: TemplateInstance;\n }\n\n export type CommitPartEntry =\n | CommitNothingToChildEntry\n | CommitText\n | CommitNode\n | CommitAttribute\n | CommitProperty\n | CommitBooleanAttribute\n | CommitEventListener\n | CommitToElementBinding;\n\n export interface CommitNothingToChildEntry {\n kind: 'commit nothing to child';\n start: ChildNode;\n end: ChildNode | null;\n parent: Disconnectable | undefined;\n options: RenderOptions | undefined;\n }\n\n export interface CommitText {\n kind: 'commit text';\n node: Text;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitNode {\n kind: 'commit node';\n start: Node;\n parent: Disconnectable | undefined;\n value: Node;\n options: RenderOptions | undefined;\n }\n\n export interface CommitAttribute {\n kind: 'commit attribute';\n element: Element;\n name: string;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitProperty {\n kind: 'commit property';\n element: Element;\n name: string;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitBooleanAttribute {\n kind: 'commit boolean attribute';\n element: Element;\n name: string;\n value: boolean;\n options: RenderOptions | undefined;\n }\n\n export interface CommitEventListener {\n kind: 'commit event listener';\n element: Element;\n name: string;\n value: unknown;\n oldListener: unknown;\n options: RenderOptions | undefined;\n // True if we're removing the old event listener (e.g. because settings changed, or value is nothing)\n removeListener: boolean;\n // True if we're adding a new event listener (e.g. because first render, or settings changed)\n addListener: boolean;\n }\n\n export interface CommitToElementBinding {\n kind: 'commit to element binding';\n element: Element;\n value: unknown;\n options: RenderOptions | undefined;\n }\n }\n}\n\ninterface DebugLoggingWindow {\n // Even in dev mode, we generally don't want to emit these events, as that's\n // another level of cost, so only emit them when DEV_MODE is true _and_ when\n // window.emitLitDebugEvents is true.\n emitLitDebugLogEvents?: boolean;\n}\n\n/**\n * Useful for visualizing and logging insights into what the Lit template system is doing.\n *\n * Compiled out of prod mode builds.\n */\nconst debugLogEvent = DEV_MODE\n ? (event: LitUnstable.DebugLog.Entry) => {\n const shouldEmit = (global as unknown as DebugLoggingWindow)\n .emitLitDebugLogEvents;\n if (!shouldEmit) {\n return;\n }\n global.dispatchEvent(\n new CustomEvent('lit-debug', {\n detail: event,\n })\n );\n }\n : undefined;\n// Used for connecting beginRender and endRender events when there are nested\n// renders when errors are thrown preventing an endRender event from being\n// called.\nlet debugLogRenderId = 0;\n\nlet issueWarning: (code: string, warning: string) => void;\n\nif (DEV_MODE) {\n global.litIssuedWarnings ??= new Set();\n\n // Issue a warning, if we haven't already.\n issueWarning = (code: string, warning: string) => {\n warning += code\n ? ` See https://lit.dev/msg/${code} for more information.`\n : '';\n if (!global.litIssuedWarnings!.has(warning)) {\n console.warn(warning);\n global.litIssuedWarnings!.add(warning);\n }\n };\n\n issueWarning(\n 'dev-mode',\n `Lit is in dev mode. Not recommended for production!`\n );\n}\n\nconst wrap =\n ENABLE_SHADYDOM_NOPATCH &&\n global.ShadyDOM?.inUse &&\n global.ShadyDOM?.noPatch === true\n ? (global.ShadyDOM!.wrap as (node: T) => T)\n : (node: T) => node;\n\nconst trustedTypes = (global as unknown as Window).trustedTypes;\n\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('lit-html', {\n createHTML: (s) => s,\n })\n : undefined;\n\n/**\n * Used to sanitize any value before it is written into the DOM. This can be\n * used to implement a security policy of allowed and disallowed values in\n * order to prevent XSS attacks.\n *\n * One way of using this callback would be to check attributes and properties\n * against a list of high risk fields, and require that values written to such\n * fields be instances of a class which is safe by construction. Closure's Safe\n * HTML Types is one implementation of this technique (\n * https://github.com/google/safe-html-types/blob/master/doc/safehtml-types.md).\n * The TrustedTypes polyfill in API-only mode could also be used as a basis\n * for this technique (https://github.com/WICG/trusted-types).\n *\n * @param node The HTML node (usually either a #text node or an Element) that\n * is being written to. Note that this is just an exemplar node, the write\n * may take place against another instance of the same class of node.\n * @param name The name of an attribute or property (for example, 'href').\n * @param type Indicates whether the write that's about to be performed will\n * be to a property or a node.\n * @return A function that will sanitize this class of writes.\n */\nexport type SanitizerFactory = (\n node: Node,\n name: string,\n type: 'property' | 'attribute'\n) => ValueSanitizer;\n\n/**\n * A function which can sanitize values that will be written to a specific kind\n * of DOM sink.\n *\n * See SanitizerFactory.\n *\n * @param value The value to sanitize. Will be the actual value passed into\n * the lit-html template literal, so this could be of any type.\n * @return The value to write to the DOM. Usually the same as the input value,\n * unless sanitization is needed.\n */\nexport type ValueSanitizer = (value: unknown) => unknown;\n\nconst identityFunction: ValueSanitizer = (value: unknown) => value;\nconst noopSanitizer: SanitizerFactory = (\n _node: Node,\n _name: string,\n _type: 'property' | 'attribute'\n) => identityFunction;\n\n/** Sets the global sanitizer factory. */\nconst setSanitizer = (newSanitizer: SanitizerFactory) => {\n if (!ENABLE_EXTRA_SECURITY_HOOKS) {\n return;\n }\n if (sanitizerFactoryInternal !== noopSanitizer) {\n throw new Error(\n `Attempted to overwrite existing lit-html security policy.` +\n ` setSanitizeDOMValueFactory should be called at most once.`\n );\n }\n sanitizerFactoryInternal = newSanitizer;\n};\n\n/**\n * Only used in internal tests, not a part of the public API.\n */\nconst _testOnlyClearSanitizerFactoryDoNotCallOrElse = () => {\n sanitizerFactoryInternal = noopSanitizer;\n};\n\nconst createSanitizer: SanitizerFactory = (node, name, type) => {\n return sanitizerFactoryInternal(node, name, type);\n};\n\n// Added to an attribute name to mark the attribute as bound so we can find\n// it easily.\nconst boundAttributeSuffix = '$lit$';\n\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 = `lit$${String(Math.random()).slice(9)}$`;\n\n// String used to tell if a comment is a marker comment\nconst markerMatch = '?' + marker;\n\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}>`;\n\nconst d =\n NODE_MODE && global.document === undefined\n ? ({\n createTreeWalker() {\n return {};\n },\n } as unknown as Document)\n : document;\n\n// Creates a dynamic marker. We never have to search for these in the DOM.\nconst createMarker = () => d.createComment('');\n\n// https://tc39.github.io/ecma262/#sec-typeof-operator\ntype Primitive = null | undefined | boolean | number | string | symbol | bigint;\nconst isPrimitive = (value: unknown): value is Primitive =>\n value === null || (typeof value != 'object' && typeof value != 'function');\nconst isArray = Array.isArray;\nconst isIterable = (value: unknown): value is Iterable =>\n isArray(value) ||\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (value as any)?.[Symbol.iterator] === 'function';\n\nconst SPACE_CHAR = `[ \\t\\n\\f\\r]`;\nconst ATTR_VALUE_CHAR = `[^ \\t\\n\\f\\r\"'\\`<>=]`;\nconst NAME_CHAR = `[^\\\\s\"'>=/]`;\n\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/**\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;\n\nconst commentEndRegex = /-->/g;\n/**\n * Comments not started with /g;\n/**\n * Comments not started with