@granularjs/core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +576 -0
  2. package/dist/granular.min.js +2 -0
  3. package/dist/granular.min.js.map +7 -0
  4. package/package.json +54 -0
  5. package/src/core/bootstrap.js +63 -0
  6. package/src/core/collections/observable-array.js +204 -0
  7. package/src/core/component/function-component.js +82 -0
  8. package/src/core/context.js +172 -0
  9. package/src/core/dom/dom.js +25 -0
  10. package/src/core/dom/element.js +725 -0
  11. package/src/core/dom/error-boundary.js +111 -0
  12. package/src/core/dom/input-format.js +82 -0
  13. package/src/core/dom/list.js +185 -0
  14. package/src/core/dom/portal.js +57 -0
  15. package/src/core/dom/tags.js +182 -0
  16. package/src/core/dom/virtual-list.js +242 -0
  17. package/src/core/dom/when.js +138 -0
  18. package/src/core/events/event-hub.js +97 -0
  19. package/src/core/forms/form.js +127 -0
  20. package/src/core/internal/symbols.js +5 -0
  21. package/src/core/network/websocket.js +165 -0
  22. package/src/core/query/query-client.js +529 -0
  23. package/src/core/reactivity/after-flush.js +20 -0
  24. package/src/core/reactivity/computed.js +51 -0
  25. package/src/core/reactivity/concat.js +89 -0
  26. package/src/core/reactivity/dirty-host.js +162 -0
  27. package/src/core/reactivity/observe.js +421 -0
  28. package/src/core/reactivity/persist.js +180 -0
  29. package/src/core/reactivity/resolve.js +8 -0
  30. package/src/core/reactivity/signal.js +97 -0
  31. package/src/core/reactivity/state.js +294 -0
  32. package/src/core/renderable/render-string.js +51 -0
  33. package/src/core/renderable/renderable.js +21 -0
  34. package/src/core/renderable/renderer.js +66 -0
  35. package/src/core/router/router.js +865 -0
  36. package/src/core/runtime.js +28 -0
  37. package/src/index.js +42 -0
  38. package/types/core/bootstrap.d.ts +11 -0
  39. package/types/core/collections/observable-array.d.ts +25 -0
  40. package/types/core/component/function-component.d.ts +14 -0
  41. package/types/core/context.d.ts +29 -0
  42. package/types/core/dom/dom.d.ts +13 -0
  43. package/types/core/dom/element.d.ts +10 -0
  44. package/types/core/dom/error-boundary.d.ts +8 -0
  45. package/types/core/dom/input-format.d.ts +6 -0
  46. package/types/core/dom/list.d.ts +8 -0
  47. package/types/core/dom/portal.d.ts +8 -0
  48. package/types/core/dom/tags.d.ts +114 -0
  49. package/types/core/dom/virtual-list.d.ts +8 -0
  50. package/types/core/dom/when.d.ts +13 -0
  51. package/types/core/events/event-hub.d.ts +48 -0
  52. package/types/core/forms/form.d.ts +9 -0
  53. package/types/core/internal/symbols.d.ts +4 -0
  54. package/types/core/network/websocket.d.ts +18 -0
  55. package/types/core/query/query-client.d.ts +73 -0
  56. package/types/core/reactivity/after-flush.d.ts +4 -0
  57. package/types/core/reactivity/computed.d.ts +1 -0
  58. package/types/core/reactivity/concat.d.ts +1 -0
  59. package/types/core/reactivity/dirty-host.d.ts +42 -0
  60. package/types/core/reactivity/observe.d.ts +10 -0
  61. package/types/core/reactivity/persist.d.ts +1 -0
  62. package/types/core/reactivity/resolve.d.ts +1 -0
  63. package/types/core/reactivity/signal.d.ts +11 -0
  64. package/types/core/reactivity/state.d.ts +14 -0
  65. package/types/core/renderable/render-string.d.ts +2 -0
  66. package/types/core/renderable/renderable.d.ts +15 -0
  67. package/types/core/renderable/renderer.d.ts +38 -0
  68. package/types/core/router/router.d.ts +57 -0
  69. package/types/core/runtime.d.ts +26 -0
  70. package/types/index.d.ts +2 -0
@@ -0,0 +1,2 @@
1
+ var T=class{mountInto(){throw new Error("Renderable.mountInto() must be implemented")}unmount(){throw new Error("Renderable.unmount() must be implemented")}};var m=class r{static isDomNode(t){return!!t&&typeof t=="object"&&typeof t.nodeType=="number"}static isRenderable(t){return t instanceof T}static toText(t){if(t==null||t===!1)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="bigint")return String(t);if(typeof t=="boolean")return t?"true":"";try{return String(t)}catch{return""}}static normalize(t){return t==null||t===!1?[]:Array.isArray(t)?t.flatMap(e=>r.normalize(e)):r.isRenderable(t)||r.isDomNode(t)?[t]:[document.createTextNode(r.toText(t))]}static unmount(t){r.isRenderable(t)&&t.unmount()}};async function qt(r,t){let e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error("bootstrap target not found");if(typeof r!="function")throw new Error("bootstrap: component must be a function or class");let n=null;if(r.__zbFactory)n=r();else try{n=new r}catch{n=null}if(n){if(typeof n.attach=="function")return await n.attach(e),n;if(typeof n.mountInto=="function")return n.mountInto(e,null),n}let s=r(),i=m.normalize(s);for(let o of i)m.isRenderable(o)?o.mountInto(e,null):m.isDomNode(o)&&e.appendChild(o);return{unmount(){for(let o of i)m.isRenderable(o)?o.unmount():m.isDomNode(o)&&o.remove()}}}var pt=!1,yt=new Set;function Me(){pt=!1;for(let r of yt)r()}var Ft={schedule(){pt||(pt=!0,queueMicrotask(Me))},add(r){return yt.add(r),()=>yt.delete(r)}};var gt=Object.freeze({instrumentBoundProp:Symbol("zb.instrumentBoundProp"),subscribeProp:Symbol("zb.subscribeProp")});var H=class{#t=new Map;#n=new Map;#e=new Set;on(t,e,n){let s=t==="before"?this.#t:this.#n;if(t==="after"&&e==="*")return this.#e.add(n),()=>this.#e.delete(n);let i=s.get(e);return i||(i=new Set,s.set(e,i)),i.add(n),()=>i.delete(n)}emitBefore(t,e,n){let s=this.#t.get(t);if(!s)return!0;for(let i of s)if(i(e,n)===!1)return!1;return!0}emitAfter(t,e,n){let s=this.#n.get(t);if(s)for(let i of s)i(e,n);for(let i of this.#e)i(e,n)}phase(t){let e=this,n={on(s,i){return e.on(t,s,i)},any(s){return e.on(t,"*",s)}};return new Proxy(n,{get(s,i){return typeof i!="string"||i in s?s[i]:o=>e.on(t,i,o)}})}};var Wt=new WeakMap;function j(r){return!!r&&typeof r=="object"&&Wt.has(r)}function Ce(r,t){return r<0?Math.max(0,t+r):Math.min(r,t)}function Ht(r=[]){let t=Array.isArray(r)?r.slice():[],e=new Set,n=new H,s=(o,u)=>{for(let a of e)a(o,u);n.emitAfter(o.type,o,u||{array:i})},i=new Proxy(t,{get(o,u,a){if(u==="subscribe")return c=>(e.add(c),()=>e.delete(c));if(u==="reset")return c=>{let l=o.slice(),h=Array.isArray(c)?c.slice():[],d={array:i,op:"reset",args:[c],prevLength:o.length,nextLength:h.length},b={type:"reset",items:h,prevItems:l};n.emitBefore("reset",b,d)&&(o.length=0,Array.isArray(c)&&o.push(...c),s({type:"reset",items:o.slice(),prevItems:l},d))};if(u==="after")return()=>n.phase("after");if(u==="before")return()=>n.phase("before");let f=Reflect.get(o,u,a);return typeof f!="function"?f:u==="push"?(...c)=>{let l=o.length,h={array:i,op:"push",args:c,prevLength:o.length,nextLength:o.length+c.length},d={type:"insert",index:l,items:c.slice()};if(c.length&&!n.emitBefore("insert",d,h))return o.length;let b=Array.prototype.push.apply(o,c);return c.length&&s({type:"insert",index:l,items:c},h),b}:u==="pop"?()=>{if(o.length===0)return;let c=o.length-1,l=[o[c]],h={array:i,op:"pop",args:[],prevLength:o.length,nextLength:o.length-1},d={type:"remove",index:c,count:1,items:l};if(!n.emitBefore("remove",d,h))return;let b=Array.prototype.pop.apply(o);return s({type:"remove",index:c,count:1,items:l},h),b}:u==="unshift"?(...c)=>{let l={array:i,op:"unshift",args:c,prevLength:o.length,nextLength:o.length+c.length},h={type:"insert",index:0,items:c.slice()};if(c.length&&!n.emitBefore("insert",h,l))return o.length;let d=Array.prototype.unshift.apply(o,c);return c.length&&s({type:"insert",index:0,items:c},l),d}:u==="shift"?()=>{if(o.length===0)return;let c=[o[0]],l={array:i,op:"shift",args:[],prevLength:o.length,nextLength:o.length-1},h={type:"remove",index:0,count:1,items:c};if(!n.emitBefore("remove",h,l))return;let d=Array.prototype.shift.apply(o);return s({type:"remove",index:0,count:1,items:c},l),d}:u==="splice"?(c,l,...h)=>{let d=o.length,b=Ce(Number(c)||0,d),g=l===void 0?d-b:Math.max(0,Number(l)||0),p={array:i,op:"splice",args:[c,l,...h],prevLength:o.length,nextLength:o.length-g+h.length};if(g){let S={type:"remove",index:b,count:g,items:o.slice(b,b+g)};if(!n.emitBefore("remove",S,p))return[]}if(h.length){let S={type:"insert",index:b,items:h.slice()};if(!n.emitBefore("insert",S,p))return[]}let y=Array.prototype.splice.apply(o,[b,g,...h]);return g&&s({type:"remove",index:b,count:g,items:y},p),h.length&&s({type:"insert",index:b,items:h},p),y}:f.bind(o)},set(o,u,a,f){if(u==="length"){let p=o.length,y=Number(a)||0,S=o.slice(),z=y<p?o.slice(y,p):[],B={array:i,op:"length",args:[y],prevLength:p,nextLength:y},k=Reflect.set(o,u,y,f);if(k&&y<p){let O={type:"remove",index:y,count:p-y,items:z};n.emitBefore("remove",O,B)&&s(O,B)}return k&&y>p&&s({type:"reset",items:o.slice(),prevItems:S},B),k}let c=typeof u=="string"&&/^\d+$/.test(u)?Number(u):null;if(c==null)return Reflect.set(o,u,a,f);let l=o.length,h=c<o.length?o[c]:void 0,d={array:i,op:"set",args:[u,a],prevLength:o.length,nextLength:o.length};if(!Reflect.set(o,u,a,f))return!1;if(c<l){let p={type:"set",index:c,value:a,prev:h};return n.emitBefore("set",p,d)&&s(p,d),!0}if(c===l){let p={type:"insert",index:c,items:[a]};return d.nextLength=o.length,n.emitBefore("insert",p,d)&&s(p,d),!0}let g=o.slice(0,l);return s({type:"reset",items:o.slice(),prevItems:g},d),!0}});return Wt.set(i,{target:t,subs:e}),i}var et=class extends T{#t=new Set;#n=!1;#e=new Map;#s=new Set;#r=new Map;#o=new Map;#i=new H;before(){return this.#i.phase("before")}after(){return this.#i.phase("after")}emitBefore(t,e,n){return this.#i.emitBefore(t,e,n)}emitAfter(t,e,n){this.#i.emitAfter(t,e,n)}set(t){let e=this.#n;this.#n=!0;try{t()}finally{this.#n=e,this.update()}}update(){if(this.#t.size===0)return;let t=Array.from(this.#t);this.#t.clear();for(let e of t){let n=this.#e.get(e);if(n)for(let s of n)s()}this.#i.emitAfter("flush",{props:t},{target:this}),Ft.schedule()}[gt.subscribeProp](t,e){let n=this.#e.get(t);return n||(n=new Set,this.#e.set(t,n)),n.add(e),()=>n.delete(e)}[gt.instrumentBoundProp](t){if(this.#s.has(t))return;this.#s.add(t);let e=Object.getOwnPropertyDescriptor(this,t);e&&e.configurable===!1||(this.#r.set(t,this[t]),this.#u(t,this.#r.get(t)),Object.defineProperty(this,t,{get:()=>this.#r.get(t),set:n=>{let s=this.#r.get(t);s===n||!this.#i.emitBefore("set",{prop:t,prev:s,next:n},{target:this})||(this.#r.set(t,n),this.#u(t,n),this.#c(t),this.#i.emitAfter("set",{prop:t,prev:s,next:n},{target:this}))},enumerable:!0,configurable:!0}))}#u(t,e){let n=this.#o.get(t);if(n&&(n(),this.#o.delete(t)),!j(e)||typeof e.subscribe!="function")return;let s=e.subscribe(()=>{this.#c(t)});this.#o.set(t,s)}#c(t){this.#t.add(t),this.#f()}#f(){this.#n||(this.#n=!0,queueMicrotask(()=>{this.#n=!1,this.update()}))}};function De(r){return new Proxy(r,{get:(t,e)=>{if(e==="onCleanup")return t.onCleanup.bind(t);if(e==="$")return s=>t[s];if(typeof e=="string"&&e.startsWith("$"))return t[e.slice(1)];let n=t[e];return typeof n=="function"?n.bind(t):n},set:(t,e,n)=>(t[e]=n,!0)})}var bt=class extends et{#t=null;#n=[];#e=[];constructor(t,e){super(),this.props=e||{};let n=De(this),s=t.call(n,e);this.#t=s,this.#n=m.normalize(s)}mountInto(t,e){for(let n of this.#n){if(m.isRenderable(n)){n.mountInto(t,e);continue}m.isDomNode(n)&&t.insertBefore(n,e)}}unmount(){for(let t of this.#e)t();this.#e=[];for(let t of this.#n){if(m.isRenderable(t)){t.unmount();continue}m.isDomNode(t)&&t.remove()}}renderToString(t){return t(this.#t)}onCleanup(t){typeof t=="function"&&this.#e.push(t)}};function Ut(r){if(typeof r!="function")throw new Error("component(fn): fn must be a function");let t=e=>new bt(r,e);return t.__zbFactory=!0,t}var St=Symbol("zb.signal"),Vt=Symbol("zb.signal.map");function Ne(r){return r!==null&&typeof r=="object"}function q(r){let t={[St]:!0,value:r,subs:new Set,before:new Set},e=i=>{for(let o of t.subs)o(t.value,i)},n={get(){return t.value},set(i,o=!1){let u=t.value;if(!o&&u===i)return!0;for(let a of t.before)if(a(u,i)===!1)return!1;return t.value=i,e(u),!0},subscribe(i){return t.subs.add(i),()=>t.subs.delete(i)},before(i){return t.before.add(i),()=>t.before.delete(i)}},s=new Proxy(n,{get(i,o){if(o===St)return!0;if(o==="value")return t.value;if(o==="get")return n.get;if(o==="set")return n.set;if(o==="subscribe")return n.subscribe;if(o==="before")return n.before;if(o===Symbol.toPrimitive)return()=>t.value;if(o==="valueOf")return()=>t.value;if(o==="toString")return()=>String(t.value);let u=t.value;if(Array.isArray(u)&&o==="map")return a=>{let f=u.map(a);return Object.defineProperty(f,Vt,{value:{signal:s,mapFn:a}}),f};if(Ne(u)){let a=u[o];return typeof a=="function"?a.bind(u):a}}});return s}function v(r){return!!r&&r[St]===!0}function L(r,t){return r?.subscribe?.(t)}function A(r){return r?.get?.()}function F(r,t,e=!1){return r?.set?.(t,e)}function _t(r){return Array.isArray(r)&&r[Vt]||null}var wt=Symbol("zb.state"),U=Symbol("zb.state.meta");function qe(r){return r!==null&&typeof r=="object"}function Gt(r){return r?Array.isArray(r)?r:String(r).split(".").map(t=>t.trim()).filter(Boolean):[]}function rt(r,t){let e=r;for(let n of t){if(!e)return;e=e[n]}return e}function W(r,t,e){let n=e===void 0?r.get():e,s=rt(n,t),i=r.defaults;if(!i||!r.defaultsWhen(s))return s;let u=rt(i,t);return u===void 0?s:typeof u=="function"?u({value:s,path:t,root:n}):u}function _(r,t,e){if(!t.length)return e;let n=Array.isArray(r)?r.slice():{...r||{}},s=n;for(let i=0;i<t.length-1;i++){let o=t[i],u=s[o],a=Array.isArray(u)?u.slice():{...u||{}};s[o]=a,s=a}return s[t[t.length-1]]=e,n}function Jt(r,t){return new Proxy({},{get(e,n){if(n==="increment")return()=>{let s=rt(r.get(),t),i=(Number(s)||0)+1;r.set(_(r.get(),t,i))};if(n==="decrement")return()=>{let s=rt(r.get(),t),i=(Number(s)||0)-1;r.set(_(r.get(),t,i))};if(n==="mutate")return(...s)=>r.mutate?.(...s);if(typeof n=="string")return Jt(r,t.concat(n))},set(e,n,s){let i=t.concat(String(n));return r.set(_(r.get(),i,s)),!0}})}function Qt(r,t=[]){let e={adapter:r,path:t};return new Proxy({},{get(n,s){if(s===wt)return!0;if(s===U)return e;if(s==="get")return o=>o===void 0?r.get():W(r,t.concat(Gt(o)));if(s==="set")return(...o)=>{if(o.length===0)return Jt(r,t);if(o.length===1)return r.set(_(r.get(),t,o[0]));let[u,a]=o;return typeof u=="string"?r.set(_(r.get(),t.concat(Gt(u)),a)):r.set(_(r.get(),t,u))};if(s==="subscribe")return o=>r.subscribe(o);if(s==="before")return r.before;if(s==="mutate")return(...o)=>r.mutate?.(...o);if(s===Symbol.toPrimitive)return()=>W(r,t);if(s==="valueOf")return()=>W(r,t);if(s==="toString")return()=>String(W(r,t));let i=W(r,t);if(Array.isArray(i)&&s==="map")return o=>{let u=i.map(o);return Object.defineProperty(u,U,{value:{adapter:r,path:t,mapFn:o}}),u};if(qe(i)&&typeof s=="string")return Qt(r,t.concat(s))},set(n,s,i){if(typeof s=="string")throw new Error(`Direct mutation is not allowed. Use .set().${s} = value or .set("${t.concat(s).join(".")}", value).`);return!1}})}function I(r){let t=q(r),e={kind:"state",get:()=>A(t),set:n=>F(t,n,!0),subscribe:n=>L(t,n),before:t.before,mutate:(n,s,i={})=>We(e,n,s,i)};return G(e)}function G(r){let t=Qt(r,[]);return Object.defineProperty(t,wt,{value:!0}),t}function Fe(r,t){return typeof t.clone=="function"?t.clone(r):r}async function We(r,t,e,n={}){if(typeof t!="function"||typeof e!="function")throw new Error("mutate(optimistic, mutation, options?): invalid arguments");let s=Fe(r.get(),n);t();try{return await e()}catch(i){throw typeof n.rollback=="function"?n.rollback(i,s):r.set(s),i}}function w(r){return!!r&&r[wt]===!0}function C(r){let t=r?.[U];return!!t&&t.adapter?.kind==="computed"}function x(r){return!!r&&r[U]}function R(r){let t=r?.[U];if(t)return W(t.adapter,t.path)}function xt(r,t){let e=r?.[U];if(e)return W(e.adapter,e.path,t)}function D(r,t){let e=r?.[U];return e?e.adapter.subscribe((n,s)=>{let i=W(e.adapter,e.path,n),o=W(e.adapter,e.path,s);i!==o&&t(i,o)}):null}function Zt(r){if(r)return W(r.adapter,r.path)}function Kt(r,t){return r?r.adapter.subscribe((e,n)=>{let s=W(r.adapter,r.path,e),i=W(r.adapter,r.path,n);s!==i&&t(s,i)}):null}function nt(r,t){let e=r?.[U];if(e)return e.adapter.set(_(e.adapter.get(),e.path,t))}function Xt(r){let t=r?.[U];return!t||!t.mapFn?null:t}function V(r){if(!r||typeof r!="object")return r;try{return Object.freeze(r)}catch{return r}}function ee(r){return r.length===1&&Array.isArray(r[0])&&!j(r[0])?r[0]:r}function re(r){if(w(r)||x(r))return R(r);if(v(r))return A(r);if(j(r))return r}function Yt(r,t){if(w(r)||x(r))return D(r,(e,n)=>t(V(e),V(n),null));if(v(r))return L(r,(e,n)=>t(V(e),V(n),null));if(j(r))return r.after().any((e,n)=>{let s=n?.prevLength??r.length,i=n?.nextLength??r.length,{next:o,prev:u}=se(r,e,n,"after");t(o,u,{patch:e,prevLength:s,nextLength:i,array:r})});throw new Error("after(x).change: unsupported target")}function te(r,t){if(w(r)||x(r))return r.before?.((e,n)=>{let s=xt(r,e),i=n!==void 0?xt(r,n):s;return i===s?!0:t(V(i),V(s),null)!==!1});if(v(r))return r.before((e,n)=>t(V(n),V(e),null));if(j(r))return r.before().any((e,n)=>{let s=r.length,i=n?.nextLength??s,{next:o,prev:u}=se(r,e,n,"before");return t(o,u,{patch:e,prevLength:s,nextLength:i,array:r})!==!1});throw new Error("before(x).change: unsupported target")}function ne(){let r=q(void 0);return{value:G({kind:"computed",get:()=>A(r),set:()=>{throw new Error("Computed values are read-only.")},subscribe:s=>L(r,s),before:void 0}),setValue:s=>F(r,s,!0)}}function He(r,t,e){if(!Array.isArray(r))return[];let n=r.slice();return!t||!t.type?n:t.type==="insert"?(n.splice(t.index,0,...t.items||[]),n):t.type==="remove"?(n.splice(t.index,t.count||0),n):t.type==="set"?(n[t.index]=t.value,n):t.type==="reset"?Array.isArray(t.items)?t.items.slice():[]:n}function Ue(r,t,e){if(!Array.isArray(r))return[];let n=r.slice();if(!t||!t.type)return n;if(t.type==="insert")return n.splice(t.index,(t.items||[]).length),n;if(t.type==="remove"){let s=t.items||[];return n.splice(t.index,0,...s),n}return t.type==="set"?(n[t.index]=t.prev,n):t.type==="reset"?Array.isArray(t.prevItems)?t.prevItems.slice():[]:n}function se(r,t,e,n){let s={prev:null,next:null};return{prev:()=>(s.prev||(s.prev=n==="after"?Ue(r,t,e):r.slice()),s.prev),next:()=>(s.next||(s.next=n==="after"?r.slice():He(r,t,e)),s.next)}}function At(r){return j(r)?()=>r.slice():re(r)}function $(...r){let t=ee(r);if(!t.length)throw new Error("after(...targets): at least one target is required");return{change(e){let n=t.map(s=>Yt(s,(i,o,u)=>e(i,o,u)));return()=>{for(let s of n)typeof s=="function"&&s()}},compute(e,n={}){let{value:s,setValue:i}=ne(),o=0,u,a,f=null,c=!1,l=t.map(At),h=typeof n.equals=="function"?n.equals:Object.is,d=y=>{if(typeof n.onError=="function"){n.onError(y);return}typeof console<"u"&&typeof console.error=="function"&&console.error(y)},b=(y,S,z)=>{if(c)return;let B=++o,k=y;if(typeof n.hash=="function"){let E;try{E=t.length===1?n.hash(k[0],S[0],z[0]):n.hash(k,S,z)}catch(N){d(N);return}if(E===u)return;u=E}let O;try{O=t.length===1?e(k[0],S[0],z[0]):e(k,S,z)}catch(E){d(E);return}if(O&&typeof O.then=="function"){O.then(E=>{B!==o||c||h(a,E)||(a=E,i(E))}).catch(E=>d(E));return}h(a,O)||(a=O,i(O))},g=(y,S,z)=>{if(c)return;let B=Math.max(0,n.debounce??0);if(!B){b(y,S,z);return}f&&clearTimeout(f),f=setTimeout(()=>{f=null,b(y,S,z)},B)};g(l,l,t.map(()=>null));let p=t.map((y,S)=>Yt(y,(z,B,k)=>{let O=t.map(At);O[S]=z;let E=l.slice();E[S]=B,l=O;let N=t.map(()=>null);N[S]=k,g(O,E,N)}));return Object.defineProperty(s,"dispose",{value:()=>{c=!0,o++,f&&clearTimeout(f);for(let y of p)typeof y=="function"&&y()},enumerable:!1}),s}}}function ie(...r){let t=ee(r);if(!t.length)throw new Error("before(...targets): at least one target is required");return{change(e){let n=t.map(s=>te(s,(i,o,u)=>e(i,o,u)));return()=>{for(let s of n)typeof s=="function"&&s()}},compute(e,n={}){let{value:s,setValue:i}=ne(),o=0,u,a,f=null,c=!1,l=typeof n.equals=="function"?n.equals:Object.is,h=p=>{if(typeof n.onError=="function"){n.onError(p);return}typeof console<"u"&&typeof console.error=="function"&&console.error(p)},d=(p,y,S)=>{if(c)return;let z=++o;if(typeof n.hash=="function"){let k;try{k=t.length===1?n.hash(p[0],y[0],S[0]):n.hash(p,y,S)}catch(O){h(O);return}if(k===u)return;u=k}let B;try{B=t.length===1?e(p[0],y[0],S[0]):e(p,y,S)}catch(k){h(k);return}if(B&&typeof B.then=="function"){B.then(k=>{z!==o||c||l(a,k)||(a=k,i(k))}).catch(k=>h(k));return}l(a,B)||(a=B,i(B))},b=(p,y,S)=>{if(c)return;let z=Math.max(0,n.debounce??0);if(!z){d(p,y,S);return}f&&clearTimeout(f),f=setTimeout(()=>{f=null,d(p,y,S)},z)},g=t.map((p,y)=>te(p,(S,z,B)=>{let k=t.map(At),O=k.slice();O[y]=S;let E=k.slice();E[y]=z;let N=t.map(()=>null);N[y]=B,b(O,E,N)}));return Object.defineProperty(s,"dispose",{value:()=>{c=!0,o++,f&&clearTimeout(f);for(let p of g)typeof p=="function"&&p()},enumerable:!1}),s}}}function oe(r,t){if(w(r)||x(r)){nt(r,t);return}if(v(r)){F(r,t);return}if(j(r)){if(typeof r.reset!="function")throw new Error("set(array, value): observableArray must implement reset");r.reset(t);return}throw new Error("set(target, value): unsupported target")}function vt(r){return typeof r=="function"?r():r}function ue(r,t,e,n){if(typeof t!="function")throw new Error("subscribe(target, selector, listener?): selector must be a function");if(e===void 0)return $(r).compute(o=>t(vt(o)));if(typeof e!="function")throw new Error("subscribe(target, selector, listener): listener must be a function");let s=typeof n=="function"?n:Object.is,i=t(vt(re(r)));return $(r).change(o=>{let u=t(vt(o));if(s(i,u))return;let a=i;i=u,e(u,a)})}function Z(r){return v(r)?A(r):w(r)||x(r)?R(r):r}function Et(r){return C(r)?r:v(r)?typeof A(r)=="function"?(...e)=>{let n=A(r);if(typeof n=="function")return n(...e)}:$(r).compute(e=>e):w(r)||x(r)?typeof R(r)=="function"?(...e)=>{let n=R(r);if(typeof n=="function")return n(...e)}:$(r).compute(e=>e):typeof r=="function"?r:$(I(r)).compute(t=>t)}function ae(r){if(v(r)||w(r)||x(r)||!r||typeof r!="object")return Et(r);let t=new Map;return new Proxy(r,{get(e,n){if(typeof n=="symbol")return e[n];if(t.has(n))return t.get(n);let s=e[n],i=Et(s);return t.set(n,i),i}})}function Ve(r){return r!==null&&typeof r=="object"}function st(r){return v(r)||w(r)||x(r)||C(r)}function _e(r){if(!Array.isArray(r)||r.length!==2)return!1;let t=r[0],e=r[1];return st(t),typeof e=="function"||typeof e=="string"}function ce(r,t=[]){for(let e of r){if(_e(e)){t.push(e);continue}if(Array.isArray(e)){ce(e,t);continue}t.push(e)}return t}function Ge(r){if(!r.length)return{parts:r,options:{separator:"",filterFalsy:!1}};let t=r[r.length-1];if(Ve(t)&&!Array.isArray(t)&&!st(t)&&(Object.prototype.hasOwnProperty.call(t,"separator")||Object.prototype.hasOwnProperty.call(t,"filterFalsy"))){let e={separator:t.separator??"",filterFalsy:t.filterFalsy??!1};return{parts:r.slice(0,-1),options:e}}return{parts:r,options:{separator:"",filterFalsy:!1}}}function Je(r,t){if(st(r)&&t.push(r),Array.isArray(r)&&r.length){let e=r[0];st(e)&&t.push(e)}}function Qe(r){if(Array.isArray(r)){let t=r[0],e=r[1],n=Z(t);return typeof e=="function"?e(n):typeof e=="string"?n?e:"":n}return typeof r=="function"?r():Z(r)}function fe(...r){let t=ce(r),{parts:e,options:n}=Ge(t),s=[];for(let o of e)Je(o,s);let i=()=>{let o=e.map(Qe).map(a=>a==null?"":String(a));return(n.filterFalsy?o.filter(Boolean):o).join(n.separator)};return s.length?$(s).compute(i):i()}function kt(r){return!!r&&typeof r=="object"&&typeof r.getState=="function"&&typeof r.setState=="function"&&typeof r.subscribe=="function"}function Rt(r){return w(r)||x(r)}function Ze(r,t){let e=r;for(let n of t){if(!e)return;e=e[n]}return e}function Ke(r,t,e){if(!t.length)return e;let n=Array.isArray(r)?r.slice():{...r||{}},s=n;for(let i=0;i<t.length-1;i++){let o=t[i],u=s[o],a=Array.isArray(u)?u.slice():{...u||{}};s[o]=a,s=a}return s[t[t.length-1]]=e,n}function Xe(r){return!r||!r.length?null:r.map(t=>String(t).split(".").map(e=>e.trim()).filter(Boolean))}function le(r,t){if(!t)return r;let e=r;for(let n of t){let s=Ze(r,n);e=Ke(e,n,s)}return e}function Ye(r){return JSON.stringify(r,(t,e)=>{if(typeof e!="function"&&typeof e!="symbol")return e})}function tr(r){return JSON.parse(r)}function er(r,t){if(Rt(r))return le(R(r),t);if(kt(r))return le(r.getState(),t);throw new Error("persist(target): unsupported target")}function rr(r,t){if(Rt(r)){nt(r,t);return}if(kt(r)){r.setState(t,!0);return}throw new Error("persist(target): unsupported target")}function nr(r,t){if(Rt(r))return $(r).change(t);if(kt(r))return r.subscribe(t);throw new Error("persist(target): unsupported target")}function sr(r){try{return!r||typeof r.getItem!="function"?null:r}catch{return null}}function he(r,t={}){let e=t.key;if(!e)throw new Error("persist(target): options.key is required");let n=sr(t.storage??(typeof localStorage<"u"?localStorage:null)),s=Xe(t.paths),i=t.serialize||Ye,o=t.deserialize||tr,u=t.version??1,a=t.migrate||null,f=t.reconcile||null,c=Math.max(0,t.throttle??0);if(n){let p=n.getItem(e);if(p!=null){let y=null;try{y=o(p)}catch{y=null}if(y!=null){let S=y,z=null;y&&typeof y=="object"&&"data"in y&&"v"in y&&(S=y.data,z=y.v),z!=null&&z!==u&&typeof a=="function"&&(S=a(S,z)),typeof f=="function"&&(S=f(S)),S!==void 0&&rr(r,S)}}}let l=!1,h=null,d=()=>{l=!1;let p=er(r,s),y={v:u,data:p};try{n?.setItem?.(e,i(y))}catch{return}},g=nr(r,()=>{if(n){if(c<=0){d();return}l||(l=!0,h=setTimeout(d,c))}});return Object.defineProperty(r,"persistDispose",{value:()=>{h&&clearTimeout(h),typeof g=="function"&&g()},enumerable:!1}),r}function it(r){return r!==null&&typeof r=="object"}function K(r){if(!it(r))return r;if(Array.isArray(r))return r.map(K);let t={};for(let[e,n]of Object.entries(r))t[e]=K(n);return t}function Pt(r,t){if(r===t)return!0;if(typeof r!=typeof t||!it(r)||!it(t)||Array.isArray(r)!==Array.isArray(t))return!1;if(Array.isArray(r)){if(r.length!==t.length)return!1;for(let s=0;s<r.length;s++)if(!Pt(r[s],t[s]))return!1;return!0}let e=Object.keys(r),n=Object.keys(t);if(e.length!==n.length)return!1;for(let s of e)if(!Object.prototype.hasOwnProperty.call(t,s)||!Pt(r[s],t[s]))return!1;return!0}function zt(r,t){if(t==null||t===!0)return r;if(t===!1)return r._form=!0,r;if(typeof t=="string")return r._form=t,r;if(it(t)){for(let[e,n]of Object.entries(t))r[e]=n;return r}return r}function de(r){let t=K(r),e=I(K(r)),n=I({}),s=I({}),i=I({}),o=I(!1),u=new Set,a=0,f=()=>{let l=++a,h={},d=e.get(),b=[];for(let g of u)try{let p=g(d);p&&typeof p.then=="function"?b.push(p.then(y=>{zt(h,y)})):zt(h,p)}catch(p){zt(h,p?.message||!0)}if(b.length){Promise.all(b).then(()=>{l===a&&s.set(h)});return}s.set(h)};return $(e).change(()=>{let l=!Pt(e.get(),t);o.get()!==l&&o.set(l),u.size&&f()}),{values:e,meta:n,errors:s,touched:i,dirty:o,validators:u,reset:()=>{e.set(K(t)),i.set({}),s.set({}),o.set(!1),n.set({})}}}function P(r,t){return document.createComment(`${r}:${t}`)}function M(r,t,e){let n=r.nextSibling;for(;n&&n!==t;){let s=n.nextSibling;e?.(n),n.remove(),n=s}}var Tt=class extends T{#t;#n;#e=null;#s=null;#r=!1;#o=null;#i=[];constructor(t,e){super(),this.#t=t,this.#n=e}mountInto(t,e){if(this.#r)return;this.#r=!0,this.#e=P("zb:list:start","list"),this.#s=P("zb:list:end","list"),t.insertBefore(this.#e,e),t.insertBefore(this.#s,e);let n=this.#u();this.#f(n),this.#c()}unmount(){this.#r&&(this.#r=!1,this.#o&&this.#o(),this.#o=null,this.#l(),this.#e&&this.#s&&(M(this.#e,this.#s),this.#e.remove(),this.#s.remove()),this.#e=null,this.#s=null)}renderToString(t){return this.#u().map((n,s)=>{let i=I(n),o=q(s);return t(this.#n(i,o))}).join("")}#u(){return j(this.#t)?this.#t:v(this.#t)?A(this.#t)||[]:w(this.#t)||x(this.#t)?R(this.#t)||[]:Array.isArray(this.#t)?this.#t:[]}#c(){if(j(this.#t)){this.#o=this.#t.subscribe(t=>{if(this.#r){if(t.type==="reset"){this.#a(t.items);return}if(t.type==="insert"){for(let e=0;e<t.items.length;e++)this.#p(t.index+e,t.items[e]);this.#m(t.index+t.items.length);return}if(t.type==="remove"){this.#d(t.index,t.count),this.#m(t.index);return}t.type==="set"&&this.#h(t.index,t.value)}});return}if(v(this.#t)){this.#o=L(this.#t,()=>{this.#a(this.#u())});return}(w(this.#t)||x(this.#t))&&(this.#o=D(this.#t,()=>{this.#a(this.#u())}))}#f(t){this.#i=[];for(let e=0;e<t.length;e++)this.#p(e,t[e])}#l(){for(let t of this.#i){for(let e of t.values)m.unmount(e);M(t.start,t.end),t.start.remove(),t.end.remove()}this.#i=[]}#a(t){this.#l(),this.#f(t)}#p(t,e){let n=t<this.#i.length?this.#i[t].start:this.#s,s=P("zb:item:start","item"),i=P("zb:item:end","item"),o=this.#s.parentNode;o.insertBefore(s,n),o.insertBefore(i,n);let u=I(e),a=q(t),f=this.#n?this.#n(u,a):e,c=m.normalize(f);for(let l of c)this.#w(o,l,i);this.#i.splice(t,0,{start:s,end:i,values:c,state:u,index:a})}#d(t,e){let n=this.#i.splice(t,e);for(let s of n){for(let i of s.values)m.unmount(i);M(s.start,s.end),s.start.remove(),s.end.remove()}}#h(t,e){let n=this.#i[t];if(n&&n.state){n.state.set(e);return}this.#d(t,1),this.#p(t,e)}#m(t){for(let e=t;e<this.#i.length;e++){let n=this.#i[e];n.index&&F(n.index,e)}}#w(t,e,n){if(m.isRenderable(e)){e.mountInto(t,n);return}m.isDomNode(e)&&t.insertBefore(e,n)}};function me(r,t){return new Tt(r,t)}var pe=Symbol("zb.when");function ir(r){if(r==null)return!0;let t=typeof r;return t==="string"||t==="number"||t==="boolean"||t==="object"&&!Array.isArray(r)}var Lt=class extends T{#t;#n;#e;#s=null;#r=null;#o=!1;#i=null;#u=[];constructor(t,e,n){super(),this.#t=t,this.#n=e,this.#e=n,Object.defineProperty(this,pe,{value:!0})}mountInto(t,e){this.#o||(this.#o=!0,this.#s=P("zb:when:start","when"),this.#r=P("zb:when:end","when"),t.insertBefore(this.#s,e),t.insertBefore(this.#r,e),this.#a(),this.#c())}unmount(){this.#o&&(this.#o=!1,this.#i&&this.#i(),this.#i=null,this.#l(),this.#s&&this.#r&&(M(this.#s,this.#r),this.#s.remove(),this.#r.remove()),this.#s=null,this.#r=null)}#c(){if(w(this.#t)||x(this.#t)){this.#i=D(this.#t,()=>this.#a());return}v(this.#t)&&(this.#i=L(this.#t,()=>this.#a()))}#f(){return w(this.#t)||x(this.#t)?!!R(this.#t):v(this.#t)?!!A(this.#t):!!this.#t}readValue(){let e=this.#f()?this.#n():this.#e?.();if(!(m.isRenderable(e)||m.isDomNode(e))&&ir(e))return e}subscribeValue(t){return w(this.#t)||x(this.#t)?D(this.#t,()=>t(this.readValue())):v(this.#t)?L(this.#t,()=>t(this.readValue())):null}#l(){for(let t of this.#u)m.unmount(t);this.#u=[],this.#s&&this.#r&&M(this.#s,this.#r)}#a(){this.#l();let e=this.#f()?this.#n():this.#e?.(),n=m.normalize(e);this.#u=n;for(let s of n)m.isRenderable(s)?s.mountInto(this.#r.parentNode,this.#r):m.isDomNode(s)&&this.#r.parentNode.insertBefore(s,this.#r)}renderToString(t){let n=this.#f()?this.#n():this.#e?.();return t(n)}};function ye(r,t,e){return new Lt(r,t,e)}function ot(r){return!!r&&r[pe]===!0}function ut(r){return r?.readValue?.()}function ge(r,t){return r?.subscribeValue?.(t)}var Bt=class extends T{#t;#n;#e;#s=null;#r=null;#o=!1;#i=[];constructor(t,e){super(),this.#t=t?.fallback??null,this.#n=t?.onError??null,this.#e=e}mountInto(t,e){this.#o||(this.#o=!0,this.#s=P("zb:error:start","error"),this.#r=P("zb:error:end","error"),t.insertBefore(this.#s,e),t.insertBefore(this.#r,e),this.#f())}unmount(){this.#o&&(this.#o=!1,this.#u(),this.#s&&this.#r&&(M(this.#s,this.#r),this.#s.remove(),this.#r.remove()),this.#s=null,this.#r=null)}#u(){for(let t of this.#i)m.unmount(t);this.#i=[],this.#s&&this.#r&&M(this.#s,this.#r)}#c(t){let e=m.normalize(t);this.#i=e;for(let n of e)m.isRenderable(n)?n.mountInto(this.#r.parentNode,this.#r):m.isDomNode(n)&&this.#r.parentNode.insertBefore(n,this.#r)}#f(){this.#u();try{let t=typeof this.#e=="function"?this.#e():this.#e;this.#c(t)}catch(t){this.#l(t)}}#l(t){try{typeof this.#n=="function"&&this.#n(t,{phase:"render"})}catch{}try{if(this.#t){let e=typeof this.#t=="function"?this.#t(t):this.#t;this.#c(e)}}catch{}}renderToString(t){try{let e=typeof this.#e=="function"?this.#e():this.#e;return t(e)}catch(e){if(typeof this.#n=="function")try{this.#n(e,{phase:"render"})}catch{}if(this.#t){let n=typeof this.#t=="function"?this.#t(e):this.#t;return t(n)}return""}}};function be(r,t){return new Bt(r,t)}function Se(r,t,e){return Math.max(t,Math.min(e,r))}function Ot(r){return typeof r=="number"&&!Number.isNaN(r)}var jt=class extends T{#t;#n;#e;#s;#r;#o=null;#i=null;#u=null;#c=!1;#f=null;#l=null;#a=0;#p=0;#d=-1;#h=[];#m=!1;constructor(t,e={}){super(),this.#t=t,this.#n=e.render,this.#e=e.direction==="horizontal"?"horizontal":"vertical",this.#s=Ot(e.overscan)?Math.max(0,e.overscan):2,this.#r=Ot(e.itemSize)?e.itemSize:null}mountInto(t,e){if(this.#c)return;if(typeof this.#n!="function")throw new Error("virtualList(items, options): options.render is required");this.#c=!0;let n=document.createElement("div");n.style.position="relative",n.style.overflow="auto",n.style.width="100%",n.style.height="100%",n.style.contain="layout paint";let s=document.createElement("div");s.style.position="relative",s.style.width=this.#e==="horizontal"?"0px":"100%",s.style.height=this.#e==="horizontal"?"100%":"0px";let i=document.createElement("div");i.style.position="absolute",i.style.top="0",i.style.left="0",i.style.willChange="transform",this.#e==="horizontal"&&(i.style.display="flex",i.style.flexDirection="row"),n.appendChild(s),n.appendChild(i),t.insertBefore(n,e),this.#o=n,this.#i=s,this.#u=i,n.addEventListener("scroll",this.#E),this.#y(t),this.#g(t),this.#S(),this.#x()}unmount(){this.#c&&(this.#c=!1,this.#f&&this.#f(),this.#f=null,this.#o&&this.#o.removeEventListener("scroll",this.#E),this.#l&&(this.#l.disconnect(),this.#l=null),this.#v(),this.#o?.remove(),this.#o=null,this.#i=null,this.#u=null)}#w(){return j(this.#t)?this.#t:v(this.#t)?A(this.#t)||[]:w(this.#t)||x(this.#t)?R(this.#t)||[]:Array.isArray(this.#t)?this.#t:[]}#x(){if(j(this.#t)){this.#f=this.#t.subscribe(()=>this.#S());return}if(v(this.#t)){this.#f=L(this.#t,()=>this.#S());return}(w(this.#t)||x(this.#t))&&(this.#f=D(this.#t,()=>this.#S()))}#y(t){typeof ResizeObserver>"u"||(this.#l=new ResizeObserver(()=>{this.#g(t),this.#S()}),this.#l.observe(t))}#g(t){let e=t?.getBoundingClientRect?.();e&&(this.#a=this.#e==="horizontal"?e.width:e.height)}#b(){if(this.#r!=null||!this.#u)return;let t=this.#u.firstElementChild;if(!t)return;let e=t.getBoundingClientRect(),n=this.#e==="horizontal"?e.width:e.height;Ot(n)&&n>0&&(this.#r=n)}#v(){for(let t of this.#h)m.unmount(t);this.#h=[],this.#u&&this.#u.replaceChildren()}#A(t,e,n,s){if(!this.#u)return;this.#v();let i=t.slice(e,n+1),o=[];for(let u=0;u<i.length;u++){let a=e+u,f=this.#n(i[u],a),c=m.normalize(f);for(let l of c)o.push(l)}this.#h=o;for(let u of o)m.isRenderable(u)?u.mountInto(this.#u,null):m.isDomNode(u)&&this.#u.appendChild(u);this.#e==="horizontal"?this.#u.style.transform=`translateX(${s}px)`:this.#u.style.transform=`translateY(${s}px)`}#S(){if(!this.#c||!this.#o)return;let t=this.#w(),e=t.length;if(!this.#i)return;if(e===0){this.#i.style.width=this.#e==="horizontal"?"0px":"100%",this.#i.style.height=this.#e==="horizontal"?"100%":"0px",this.#v();return}if(this.#r==null&&!this.#m){this.#m=!0,this.#A(t,0,0,0),requestAnimationFrame(()=>{this.#b(),this.#m=!1,this.#S()});return}let n=this.#r||1,s=this.#a||(this.#e==="horizontal"?this.#o.clientWidth:this.#o.clientHeight),i=this.#e==="horizontal"?this.#o.scrollLeft:this.#o.scrollTop,o=Math.ceil(s/n),u=Se(Math.floor(i/n)-this.#s,0,Math.max(0,e-1)),a=Se(u+o+this.#s*2-1,0,e-1),f=u*n,c=e*n;this.#e==="horizontal"?(this.#i.style.width=`${c}px`,this.#i.style.height="100%"):(this.#i.style.height=`${c}px`,this.#i.style.width="100%"),!(u===this.#p&&a===this.#d)&&(this.#p=u,this.#d=a,this.#A(t,u,a,f))}#E=()=>{this.#S()};renderToString(t){return this.#w().map((n,s)=>t(this.#n(n,s))).join("")}};function we(r,t){return new jt(r,t)}function or(r){return!r&&typeof document<"u"?document.body:typeof r=="string"?document.querySelector(r):r}var at=class extends T{#t;#n;#e=!1;#s=[];constructor(t,e){super(),this.#t=t,this.#n=e}mountInto(t,e){if(this.#e)return;this.#e=!0;let n=or(this.#t);if(!n)throw new Error("portal: target not found");let s=typeof this.#n=="function"?this.#n():this.#n,i=m.normalize(s);this.#s=i;for(let o of i)m.isRenderable(o)?o.mountInto(n,null):m.isDomNode(o)&&n.appendChild(o)}unmount(){if(this.#e){this.#e=!1;for(let t of this.#s)m.unmount(t);this.#s=[]}}renderToString(t){let e=typeof this.#n=="function"?this.#n():this.#n;return t(e)}};function xe(r,t){return t===void 0?new at(null,r):new at(r,t)}function ur(r){return typeof r=="string"||r instanceof ArrayBuffer||r instanceof Blob?r:JSON.stringify(r)}function ar(r){return r}function cr(r){return Math.min(1e3*Math.pow(2,Math.max(0,r-1)),1e4)}var X=class{#t;#n;#e=null;#s=new H;#r;#o=!1;#i=null;#u;#c;#f;#l;#a;constructor(t={}){this.#t=t.url,this.#n=t.protocols,this.#u=typeof t.serialize=="function"?t.serialize:ur,this.#c=typeof t.parse=="function"?t.parse:ar,this.#f=t.reconnect??!0,this.#l=t.maxRetries??1/0,this.#a=typeof t.reconnectDelay=="function"?t.reconnectDelay:cr,this.#r=I({status:"idle",connected:!1,reconnecting:!1,attempts:0,lastMessage:null,lastError:null}),(t.autoConnect??!0)&&this.connect()}state(){return this.#r}before(){return this.#s.phase("before")}after(){return this.#s.phase("after")}setUrl(t){this.#t=t}connect(){if(!this.#t)throw new Error("WebSocketClient.connect: url is required");if(this.#e&&(this.#e.readyState===WebSocket.OPEN||this.#e.readyState===WebSocket.CONNECTING))return;this.#d(),this.#o=!1,this.#r.set().status="connecting",this.#r.set().reconnecting=!1;let t=new WebSocket(this.#t,this.#n);this.#e=t,t.addEventListener("open",e=>{this.#r.set().status="open",this.#r.set().connected=!0,this.#r.set().reconnecting=!1,this.#r.set().attempts=0,this.#s.emitAfter("open",{event:e},{client:this})}),t.addEventListener("message",e=>{let n=e.data;try{n=this.#c(n)}catch(o){this.#r.set().lastError=o,this.#s.emitAfter("error",{error:o},{client:this});return}let s={data:n,raw:e.data};this.#s.emitBefore("message",s,{client:this})&&(this.#r.set().lastMessage=n,this.#s.emitAfter("message",s,{client:this}))}),t.addEventListener("error",e=>{this.#r.set().lastError=e,this.#s.emitAfter("error",{error:e},{client:this})}),t.addEventListener("close",e=>{this.#r.set().status="closed",this.#r.set().connected=!1,this.#s.emitAfter("close",{event:e},{client:this}),!this.#o&&this.#f&&this.#p()})}send(t){if(!this.#e||this.#e.readyState!==WebSocket.OPEN)throw new Error("WebSocketClient.send: socket is not open");let e={data:t};if(!this.#s.emitBefore("send",e,{client:this}))return;let s=this.#u(t);this.#e.send(s),this.#s.emitAfter("send",{data:t,raw:s},{client:this})}close(t,e){this.#o=!0,this.#d(),this.#e?.close(t,e)}#p(){if(this.#i)return;let t=this.#r.get().attempts+1;if(t>this.#l)return;this.#r.set().attempts=t,this.#r.set().reconnecting=!0;let e=Math.max(0,this.#a(t));this.#s.emitAfter("reconnect",{attempt:t,delay:e},{client:this}),this.#i=setTimeout(()=>{this.#i=null,this.connect()},e)}#d(){this.#i&&(clearTimeout(this.#i),this.#i=null)}};function ve(r){return new X(r)}var Ae={d:r=>/[0-9]/.test(r),a:r=>/[A-Za-z]/.test(r),"*":r=>/[A-Za-z0-9]/.test(r),s:r=>/[^A-Za-z0-9]/.test(r)},Ee=r=>Object.prototype.hasOwnProperty.call(Ae,r);function fr(r,t){let e=[],n=0;for(let s of r){for(;n<t.length&&!Ee(t[n]);)n+=1;if(n>=t.length)break;let i=t[n];Ae[i]?.(s)&&(e.push(s),n+=1)}return e}function lr(r,t){let e=fr(r,t),n="",s=0;for(let i=0;i<t.length;i+=1){let o=t[i];if(Ee(o)){if(s>=e.length)break;n+=e[s],s+=1;continue}s!==0&&s<e.length&&(n+=o)}return{raw:e.join(""),visual:n}}function ct(r){return r==null?null:typeof r=="function"?{format:r,mode:"both"}:typeof r=="string"?{pattern:r,mode:"both"}:typeof r=="object"?{mode:"both",...r}:null}function It(r,t){let e=ct(t),n=String(r??"");if(!e)return{value:n,visual:n,raw:n};if(typeof e.format=="function"){let s=n;try{s=e.format(n)}catch{}if(s&&typeof s=="object"){let i=s.value??s.visual??"",o=s.visual??s.value??"",u=s.raw??i??"";return{value:String(i),visual:String(o),raw:String(u)}}return{value:String(s??""),visual:String(s??""),raw:String(s??"")}}if(e.pattern){let{raw:s,visual:i}=lr(n,String(e.pattern));return{value:i,visual:i,raw:s}}if(e.regex){let s=n.match(e.regex),i=s?s[0]:"";return{value:i,visual:i,raw:i}}return{value:n,visual:n,raw:n}}var ke=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),J=class extends T{tagName;props;children;#t=null;#n=[];#e=[];#s=!1;constructor(t,e={},n=[]){super(),this.tagName=t,this.props=e||{},this.children=Array.isArray(n)?n:[n],ke.has(t.toLowerCase())&&(this.children=[])}mountInto(t,e){if(this.#s)return;this.#s=!0;let n=document.createElement(this.tagName);this.#t=n,this.#o(n),this.#w(n),t.insertBefore(n,e)}unmount(){if(this.#s){this.#s=!1;for(let t of this.#n)t();this.#n=[],this.#r(),this.#t?.remove(),this.#t=null}}renderToString(t){let e=this.tagName,n=this.props||{},s=e.toLowerCase(),i=[],o=null,u=null;for(let[l,h]of Object.entries(n)){if(l==="node"||l==="children"||l==="content"||l==="format"||l.startsWith("on")&&typeof h=="function")continue;let d=h;if(ot(d)&&(d=ut(d)),v(d)&&(d=A(d)),(w(d)||x(d))&&(d=R(d)),l==="style"){if(d&&typeof d=="object"){let b=[];for(let[g,p]of Object.entries(d)){if(p==null||p===!1)continue;let y=g.replace(/[A-Z]/g,S=>`-${S.toLowerCase()}`);b.push(`${y}:${p}`)}b.length&&i.push(`style="${b.join(";")}"`)}else typeof d=="string"&&i.push(`style="${t.escape(d)}"`);continue}if(l==="className"||l==="class"){d!=null&&d!==!1&&i.push(`class="${t.escape(String(d))}"`);continue}if(l==="htmlFor"){d!=null&&d!==!1&&i.push(`for="${t.escape(String(d))}"`);continue}if(l==="value"&&s==="input"&&n.format!=null){let b=v(n.format)?A(n.format):w(n.format)||x(n.format)?R(n.format):n.format,g=ct(b),p=g?.mode??"both",y=It(d??"",g);d=p==="value-only"?y.raw??y.value??"":y.visual??y.value??""}if(l==="textContent"){u=d==null?"":String(d);continue}if(l==="innerHTML"){o=d==null?"":String(d);continue}if(d===!0){i.push(`${l}`);continue}d===!1||d==null||i.push(`${l}="${t.escape(String(d))}"`)}let a=i.length?` ${i.join(" ")}`:"";if(ke.has(s))return`<${e}${a}>`;if(o!=null)return`<${e}${a}>${o}</${e}>`;if(u!=null)return`<${e}${a}>${t.escape(u)}</${e}>`;let c=(Array.isArray(this.children)?this.children:[this.children]).map(l=>t(l)).join("");return`<${e}${a}>${c}</${e}>`}#r(){if(this.#t)for(let t of Array.from(this.#t.childNodes))t.remove()}#o(t){let e=this.props||{},n=this.tagName.toLowerCase(),s=!1,i=!1,{formatConfig:o}=this.#i();for(let[u,a]of Object.entries(e)){if(u==="value"&&(i=!0),u==="node"||u==="children"||u==="content"||u==="format")continue;if(u==="style"){this.#m(t,a);continue}let f={el:t,key:u,rawValue:a,formatConfig:o};if(ot(a)){this.#a(f);continue}if(v(a)){u==="value"&&o&&(s=!0),this.#p(f);continue}if(w(a)||x(a)){u==="value"&&o&&(s=!0),this.#d(f);continue}if(u==="value"&&o){let{visualValue:c}=this.#u(a);this.#h(t,u,c),s=!0;continue}if((u==="onInput"||u==="onChange")&&typeof a=="function"&&o){let c=l=>{a?.(l,l?.target?.rawValue)};this.#h(t,u,c);continue}if(u==="onInput"&&!s){let c=l=>{o&&this.#c(l),a?.(l)};this.#h(t,u,c);continue}this.#h(t,u,a)}if(!i&&o){let u=a=>{let{visualValue:f}=this.#c({target:t});this.#h(t,"value",f)};u(),this.#f(t,u,!0),s=!0}if(e.node&&(w(e.node)||x(e.node))&&e.node.set(this.#t),o&&!s){let u=a=>{this.#c(a)};this.#f(t,u,!0)}}#i(){let t=this.props||{},s=this.tagName.toLowerCase()==="input"?ct((o=>v(o)?A(o):w(o)||x(o)?R(o):o)(t.format)):null,i=s?.mode??"both";return{formatConfig:s,formatMode:i}}#u(t){let{formatConfig:e,formatMode:n}=this.#i(),s=It(t??"",e),i=n==="value-only"?s.raw??s.value??"":s.visual??s.value??"",o=n==="visual-only"?s.raw??s.value??"":s.value??s.visual??"";return{formatted:s,visualValue:i,stateValue:o}}#c(t){let{formatted:e,visualValue:n,stateValue:s}=this.#u(t.target.value??""),i=e?.raw??s;return t.target.value=n,t.target.rawValue=i,{visualValue:n,stateValue:s,rawValue:i}}#f(t,e,n){t.addEventListener("input",e,n),t.addEventListener("change",e,n),this.#n.push(()=>{t.removeEventListener("input",e,n),t.removeEventListener("change",e,n)})}#l({key:t,el:e,rawValue:n,read:s,subscribe:i,formatConfig:o}){let u=()=>{let f=s(n);if(t==="value"&&o){let{visualValue:c}=this.#u(f);this.#h(e,t,c);return}this.#h(e,t,f)};u();let a=i(n,u);return a&&this.#n.push(a),u}#a(t){this.#l({...t,read:ut,subscribe:ge})}#p({el:t,key:e,rawValue:n,formatConfig:s}){let i=this.#l({key:e,el:t,rawValue:n,formatConfig:s,read:A,subscribe:L});if(e==="value")if(s){let o=u=>{let{stateValue:a}=this.#c(u);if(C(n))return;n.set?.(a)===!1&&i()};this.#f(t,o,!0)}else{let o=u=>{if(C(n))return;n.set?.(u.target?.value??"")===!1&&i()};this.#f(t,o)}if(e==="checked"){let o=u=>{if(C(n))return;n.set?.(!!u.target?.checked)===!1&&i()};t.addEventListener("change",o),this.#n.push(()=>t.removeEventListener("change",o))}}#d({el:t,key:e,rawValue:n,formatConfig:s}){let i=this.#l({key:e,el:t,rawValue:n,formatConfig:s,read:R,subscribe:D});if(e==="value")if(s){let o=u=>{let{stateValue:a}=this.#c(u);if(C(n))return;n.set?.(a)===!1&&i()};this.#f(t,o,!0)}else{let o=u=>{if(C(n))return;n.set?.(u.target?.value??"")===!1&&i()};this.#f(t,o)}if(e==="checked"){let o=u=>{if(C(n))return;n.set?.(!!u.target?.checked)===!1&&i()};t.addEventListener("change",o),this.#n.push(()=>t.removeEventListener("change",o))}}#h(t,e,n){if(ot(n)&&(n=ut(n)),v(n)&&(n=A(n)),(w(n)||x(n))&&(n=R(n)),e==="style"){if(n&&typeof n=="object"){Object.assign(t.style,n);return}if(typeof n=="string"){t.style.cssText=n;return}}if(e.startsWith("on")&&typeof n=="function"){let s=e.substring(2).toLowerCase();t.addEventListener(s,n),this.#n.push(()=>t.removeEventListener(s,n));return}if(e==="className"||e==="class"){t.className=n??"";return}if(e==="htmlFor"){t.setAttribute("for",n??"");return}if(e==="value"){try{t.value=n??""}catch{}return}if(e==="checked"){try{t.checked=!!n}catch{}return}if(e==="contentEditable"){try{t.contentEditable=n?"true":"false"}catch{}return}if(e==="textContent"){t.textContent=n??"";return}if(e==="innerHTML"){t.innerHTML=n??"";return}if(n===!1||n==null){if(t.removeAttribute(e),e in t)try{t[e]=!1}catch{}return}if(n===!0){if(t.setAttribute(e,""),e in t)try{t[e]=!0}catch{}return}if(t.setAttribute(e,n),e in t)try{t[e]=n}catch{}}#m(t,e){let n=()=>{for(let o of this.#e)o();this.#e=[]},s=o=>{if(typeof o=="string"){n(),t.style.cssText=o;return}o&&typeof o=="object"&&(n(),i(o))},i=o=>{if(!(!o||typeof o!="object"))for(let[u,a]of Object.entries(o)){if(typeof a=="function"){try{t.style[u]=a()}catch{t.style[u]=""}continue}if(v(a)){let f=()=>{try{t.style[u]=A(a)??""}catch{t.style[u]=""}};f();let c=L(a,f);c&&this.#e.push(c);continue}if(w(a)||x(a)){let f=()=>{try{t.style[u]=R(a)??""}catch{t.style[u]=""}};f();let c=D(a,f);c&&this.#e.push(c);continue}else t.style[u]=a??""}};if(n(),v(e)){let o=()=>s(A(e));o();let u=L(e,o);u&&this.#n.push(u);return}if(w(e)||x(e)){let o=()=>s(R(e));o();let u=D(e,o);u&&this.#n.push(u);return}if(typeof e=="function"){try{s(e())}catch{return}return}s(e)}#w(t){let e=Object.prototype.hasOwnProperty.call(this.props,"content")?this.props.content:null,n=this.children.length?this.children:e!=null?[e]:[];for(let s of n)this.#x(t,s,null)}#x(t,e,n){if(e==null||e===!1)return;let s=_t(e)||Xt(e);if(s){let i=P("zb:bind:start","map"),o=P("zb:bind:end","map");t.insertBefore(i,n),t.insertBefore(o,n);let u={kind:"static",values:[]},a=()=>{let c=s.path?Zt(s):A(s.signal),l=Array.isArray(c)?c.map(s.mapFn):[];this.#g(l,i,o,u)};a();let f=s.path?Kt(s,a):L(s.signal,a);f&&this.#n.push(()=>{f(),this.#y(u,i,o),i.remove(),o.remove()});return}if(v(e)){let i=P("zb:bind:start","signal"),o=P("zb:bind:end","signal");t.insertBefore(i,n),t.insertBefore(o,n);let u={kind:"static",values:[]},a=()=>this.#g(A(e),i,o,u);a();let f=L(e,a);f&&this.#n.push(()=>{f(),this.#y(u,i,o),i.remove(),o.remove()});return}if(w(e)||x(e)){let i=P("zb:bind:start","state"),o=P("zb:bind:end","state");t.insertBefore(i,n),t.insertBefore(o,n);let u={kind:"static",values:[]},a=()=>this.#g(R(e),i,o,u);a();let f=D(e,a);f&&this.#n.push(()=>{f(),this.#y(u,i,o),i.remove(),o.remove()});return}if(j(e)){let i=P("zb:bind:start","list"),o=P("zb:bind:end","list");t.insertBefore(i,n),t.insertBefore(o,n);let u={kind:"list",items:[],unsub:null,source:e};this.#g(e,i,o,u),this.#n.push(()=>{this.#y(u,i,o),i.remove(),o.remove()});return}if(Array.isArray(e)){for(let i of e)this.#x(t,i,n);return}if(m.isRenderable(e)){e.mountInto(t,n),this.#n.push(()=>e.unmount());return}if(m.isDomNode(e)){t.insertBefore(e,n);return}t.insertBefore(document.createTextNode(m.toText(e)),n)}#y(t,e,n){if(t.kind==="static"){for(let s of t.values)m.unmount(s);t.values=[],e&&n&&M(e,n);return}if(t.kind==="list"){t.unsub?.();for(let s of t.items){for(let i of s.values)m.unmount(i);M(s.start,s.end),s.start.remove(),s.end.remove()}t.items=[]}}#g(t,e,n,s){if(j(t)){if(s.kind==="list"&&s.source===t)return;this.#y(s,e,n),s.kind="list",s.source=t;let o=n.parentNode,u=[],a=(h,d)=>{let b=h<u.length?u[h].start:n,g=P("zb:item:start","item"),p=P("zb:item:end","item");o.insertBefore(g,b),o.insertBefore(p,b);let y=m.normalize(d);for(let S of y)this.#b(o,S,p);u.splice(h,0,{start:g,end:p,values:y})},f=(h,d)=>{let b=u.splice(h,d);for(let g of b){for(let p of g.values)m.unmount(p);M(g.start,g.end),g.start.remove(),g.end.remove()}},c=(h,d)=>{f(h,1),a(h,d)};for(let h=0;h<t.length;h++)a(h,t[h]);let l=t.subscribe(h=>{if(this.#s){if(h.type==="reset"){f(0,u.length);for(let d=0;d<h.items.length;d++)a(d,h.items[d]);return}if(h.type==="insert"){for(let d=0;d<h.items.length;d++)a(h.index+d,h.items[d]);return}if(h.type==="remove"){f(h.index,h.count);return}h.type==="set"&&c(h.index,h.value)}});s.items=u,s.unsub=l;return}if(Array.isArray(t)){this.#y(s,e,n),s.kind="static";let o=m.normalize(t);s.values=o;for(let u of o)this.#b(n.parentNode,u,n);return}this.#y(s,e,n),s.kind="static";let i=m.normalize(t);s.values=i;for(let o of i)this.#b(n.parentNode,o,n)}#b(t,e,n){if(m.isRenderable(e)){e.mountInto(t,n);return}m.isDomNode(e)&&t.insertBefore(e,n)}};function Re(r){return String(r).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function hr(r,t){return r==null||r===!1?"":Array.isArray(r)?r.map(e=>t(e)).join(""):v(r)?t(A(r)):w(r)||x(r)?t(R(r)):r instanceof T&&typeof r.renderToString=="function"||r instanceof J?r.renderToString(t):m.isDomNode(r)?r.outerHTML||"":Re(m.toText(r))}function ze(r){let t=e=>hr(e,t);return t.escape=Re,t(r)}function Pe(r,t){let e=typeof r=="string"?document.querySelector(r):r;if(!e)throw new Error("hydrate(target): target not found");for(;e.firstChild;)e.removeChild(e.firstChild);let n=m.normalize(t);for(let s of n)m.isRenderable(s)?s.mountInto(e,null):m.isDomNode(s)&&e.appendChild(s)}function Te(r){return 250*Math.pow(2,Math.max(0,r-1))}function ft(r){return Array.isArray(r)?JSON.stringify(r):JSON.stringify([r])}function $t(){return Date.now()}function dr(r){if(!r||typeof r!="object")return"";let t=new URLSearchParams;for(let[n,s]of Object.entries(r))if(Array.isArray(s))for(let i of s)t.append(n,String(i));else s!=null&&t.set(n,String(s));let e=t.toString();return e?`?${e}`:""}function mr(r,t){return t?String(r).replace(/:([A-Za-z0-9_]+)/g,(e,n)=>{if(!Object.prototype.hasOwnProperty.call(t,n))throw new Error(`Missing route param "${n}" for "${r}"`);return encodeURIComponent(String(t[n]))}):r}function pr(r){return!r||typeof r!="object"||Array.isArray(r)||r instanceof FormData||r instanceof URLSearchParams||r instanceof Blob||r instanceof ArrayBuffer?!1:Object.prototype.toString.call(r)==="[object Object]"}async function yr(r){return(r.headers.get("content-type")||"").includes("application/json")?await r.json():await r.text()}function gr(r,t){return async e=>{let n=-1,s=async i=>{if(i<=n)throw new Error("Middleware next() called multiple times");n=i;let o=r[i]||t;if(o)return o===t?await t(e):await o(e,()=>s(i+1))};return await s(0)}}function br(r){if(r.invalidated||r.updatedAt==null)return!0;let t=r.staleTime??0;return t===0?!0:$t()-r.updatedAt>t}var Mt=class{key;fetcher;staleTime;cacheTime;refetchOnFocus;refetchOnReconnect;retry;retryDelay;dedupe;refetchOnInvalidate;#t=null;#n=null;#e=null;#s=null;#r=0;#o=null;constructor(t){this.key=t.key,this.fetcher=t.fetcher,this.staleTime=t.staleTime??0,this.cacheTime=t.cacheTime??5*6e4,this.refetchOnFocus=t.refetchOnFocus??!0,this.refetchOnReconnect=t.refetchOnReconnect??!0,this.retry=t.retry??0,this.retryDelay=t.retryDelay??Te,this.dedupe=t.dedupe??!0,this.refetchOnInvalidate=t.refetchOnInvalidate??!0,this.#t=I({data:void 0,error:null,status:"idle",fetching:!1,updatedAt:null,errorAt:null,invalidated:!1})}get data(){return this.#t.get().data}get error(){return this.#t.get().error}get status(){return this.#t.get().status}get fetching(){return this.#t.get().fetching}get updatedAt(){return this.#t.get().updatedAt}get errorAt(){return this.#t.get().errorAt}get invalidated(){return this.#t.get().invalidated}get isStale(){return br(this)}async refetch(){return this.dedupe&&this.#n?this.#n:await this.#c({force:!0})}invalidate(){this.setState({invalidated:!0}),this.refetchOnInvalidate&&this.refetch()}cancel(){this.#e?.abort()}ensure(){return this.isStale?this.#c({force:!1}):null}subscribe(t,e,n){this.#r++,this.#u();let s=this.#f(t,e,n);return()=>{s(),this.#r=Math.max(0,this.#r-1),this.#i()}}#i(){if(this.#r>0)return;let t=this.cacheTime??0;t<=0||(this.#s=setTimeout(()=>{this.#r>0||(this.cancel(),this.#o?.())},t))}#u(){this.#s&&(clearTimeout(this.#s),this.#s=null)}setGcHandler(t){this.#o=t}async#c({force:t}){if(!t&&!this.isStale)return this.data;if(this.dedupe&&this.#n)return this.#n;let e=new AbortController;this.#e=e;let n={key:this.key,signal:e.signal},s=this.updatedAt!=null;this.setState({fetching:!0,status:s?this.status:"loading",error:null});let i=async()=>{let o=Math.max(0,this.retry??0);for(let u=1;u<=o+1;u++)try{let a=await this.fetcher(n);return this.setState({data:a,error:null,status:"success",fetching:!1,updatedAt:$t(),errorAt:null,invalidated:!1}),a}catch(a){if(e.signal.aborted)throw this.setState({fetching:!1}),a;if(u>o)throw this.setState({error:a,status:"error",fetching:!1,errorAt:$t()}),a;let f=this.retryDelay?.(u)??Te(u);await new Promise(c=>setTimeout(c,f))}};return this.#n=i().finally(()=>{this.#n=null}),this.#n}state(){return this.#t}getState(){return this.#t.get()}setState(t){let e=this.#t.get();this.#t.set({...e,...t||{}})}#f(t,e,n){if(typeof t=="function"&&e===void 0){let u=t;return this.#t.subscribe((a,f)=>u(a,f))}let s=t;if(typeof s!="function"||typeof e!="function")throw new Error("subscribe(selector, listener, equalityFn?): invalid arguments");let i=typeof n=="function"?n:Object.is,o=s(this.#t.get());return this.#t.subscribe(u=>{let a=s(u);if(i(o,a))return;let f=o;o=a,e(a,f)})}},lt=class{#t=new Map;#n=!1;#e=[];constructor(){this.#s()}query(t){let e=ft(t.key),n=this.#t.get(e);if(n)return n.ensure(),n;let s=new Mt(t);return s.setGcHandler(()=>this.#t.delete(e)),this.#t.set(e,s),s.ensure(),s}use(t){if(typeof t!="function")throw new Error("QueryClient.use(middleware): middleware must be a function");return this.#e.push(t),()=>{let e=this.#e.indexOf(t);e>=0&&this.#e.splice(e,1)}}service(t={}){let e=t.baseUrl||"",n=Array.isArray(t.middlewares)?t.middlewares.slice():[],s=t.endpoints||{},i=this,o=async(a,f={})=>{if(!a||typeof a!="object")throw new Error("service.request(endpoint, params, options): invalid endpoint");let c=f.params||{},l=(a.method||"GET").toUpperCase(),h=mr(a.path||"",c),d=f.query||a.query||null,b=f.body!==void 0?f.body:void 0,g={...a.headers||{},...f.headers||{}},p=f.map||a.map||null,y=[...i.#e,...n,...a.middlewares||[],...f.middlewares||[]],S=`${e}${h}${dr(d)}`,z=async E=>{let N={method:E.method,headers:E.headers,signal:E.signal};E.body!==void 0&&E.method!=="GET"&&E.method!=="HEAD"&&(pr(E.body)?(N.headers["Content-Type"]||(N.headers["Content-Type"]="application/json"),N.body=JSON.stringify(E.body)):N.body=E.body);let tt=await fetch(E.url,N),Nt=await yr(tt);if(!tt.ok){let mt=new Error(`Request failed: ${tt.status}`);throw mt.status=tt.status,mt.data=Nt,mt}return Nt},B={method:l,url:S,path:h,baseUrl:e,headers:g,query:d,body:b,params:c,endpoint:a,signal:f.signal},O=await gr(y,z)(B);return typeof p=="function"?p(O):O},u={request:o};for(let[a,f]of Object.entries(s))u[a]=(c={})=>o(f,c);return u}invalidate(t){let e=this.#t.get(ft(t));e&&e.invalidate()}refetch(t){let e=this.#t.get(ft(t));return e?e.refetch():null}remove(t){let e=ft(t),n=this.#t.get(e);n&&(n.cancel(),this.#t.delete(e))}#s(){this.#n||typeof window>"u"||(this.#n=!0,window.addEventListener("focus",()=>{for(let t of this.#t.values())t.refetchOnFocus&&t.isStale&&t.refetch()}),window.addEventListener("online",()=>{for(let t of this.#t.values())t.refetchOnReconnect&&t.isStale&&t.refetch()}))}};function Sr(r){if(!r)return"";let t=r.trim();return t.startsWith("/")||(t=`/${t}`),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t}function Y(r,t){let e=r||"/";return e.startsWith("/")||(e=`/${e}`),e.length>1&&e.endsWith("/")&&t!=="preserve"&&(e=e.slice(0,-1)),e}function wr(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function xr(r,{caseSensitive:t,trailingSlash:e}){let s=Y(r===""?"/":r,"preserve");if(s==="/*"||s==="*")return{regex:/^.*$/,keys:["*"],score:0};let i=s.split("/").filter(Boolean),o=[],u=0,a="^";for(let c of i){if(c==="*"){o.push("*"),a+="(?:/(.*))?",u+=1;continue}if(c.startsWith(":")){let l=c.slice(1),h=l.endsWith("?"),d=h?l.slice(0,-1):l;o.push(d),h?a+="(?:/([^/]+))?":a+="/([^/]+)",u+=2;continue}a+=`/${wr(c)}`,u+=3}i.length===0&&(a+="/?"),e==="preserve"?a+="$":a+="/?$";let f=t?"":"i";return{regex:new RegExp(a,f),keys:o,score:u}}function vr(r){let t={};if(!r)return t;let e=new URLSearchParams(r.startsWith("?")?r:`?${r}`);for(let[n,s]of e.entries())if(Object.prototype.hasOwnProperty.call(t,n)){let i=t[n];t[n]=Array.isArray(i)?i.concat(s):[i,s]}else t[n]=s;return t}function ht(r){if(!r||typeof r!="object")return"";let t=new URLSearchParams;for(let[n,s]of Object.entries(r))if(Array.isArray(s))for(let i of s)t.append(n,String(i));else s!=null&&t.set(n,String(s));let e=t.toString();return e?`?${e}`:""}function Ar({pathname:r,search:t,hash:e}){return`${r}${t||""}${e||""}`}function Le(r,t){let e=t==null?"":String(t).trim();if(e.startsWith("/"))return e||"/";let n=r&&r!=="/"?r:"";return e?`${n}/${e}`:n||"/"}function Er(r){return typeof r=="string"?document.querySelector(r):r}function dt(r){return typeof r=="function"}function Be(r){return!!r&&typeof r.then=="function"}var Q=class{#t=[];#n=0;#e;#s=null;#r=null;#o=null;#i=null;#u=!1;#c=0;#f=new Set;#l=new Set;#a=null;constructor(t={}){if(this.#e={mode:t.mode||"history",basePath:Sr(t.basePath||""),caseSensitive:!!t.caseSensitive,trailingSlash:t.trailingSlash||"ignore",maxRedirects:t.maxRedirects??8,scrollRestoration:t.scrollRestoration??!0,transition:t.transition||null,errorPage:t.errorPage||null},this.#e.mode==="memory"){let e=t.initialUrl||"/";this.#a={stack:[this.#m(e)],index:0}}}add(t,e,n={}){let s=null;if(typeof t=="string")s={path:t,page:e,...n};else if(dt(t)){let i=t.route||t.path||null;i&&typeof i=="object"?s={...i,page:t,...n}:s={path:i,page:t,...n}}else t&&typeof t=="object"&&(s={...t});if(!s||s.path==null)throw new Error("Router.add: invalid route config");return this.#p(s,null)}#p(t,e){let n=Array.isArray(t.children)&&t.children.length>0,s=!!t.page||!!t.load||!!t.redirect;if(!s&&!n&&!t.layout)throw new Error(`Router.add: route "${t.path}" must provide page, load, redirect, layout, or children`);let i=Le(e?e.path:"",t.path),o={id:`${++this.#n}_${Math.random().toString(36).slice(2)}`,name:t.name||null,path:i,rawPath:t.path,parent:e||null,meta:t.meta||null,redirect:t.redirect||null,loader:t.loader||null,guards:t.guards||null,beforeEnter:t.beforeEnter||null,beforeLeave:t.beforeLeave||null,props:t.props||null,reuse:t.reuse??null,transition:t.transition||null,errorPage:t.errorPage||null,load:t.load||null,page:t.page||null,layout:t.layout||null,children:[]};if(s){let u=xr(o.path,this.#e);o.regex=u.regex,o.keys=u.keys,o.score=u.score,this.#t.push(o),this.#t.sort((a,f)=>f.score-a.score)}if(n)for(let u of t.children){let a=this.#p(u,o);a&&o.children.push(a)}return o}beforeEach(t){return this.#f.add(t),()=>this.#f.delete(t)}afterEach(t){return this.#l.add(t),()=>this.#l.delete(t)}mount(t){let e=Er(t);if(!e)throw new Error("Router.mount: target not found");this.#s||(this.#s=e,this.#r=P("zb:route:start","router"),this.#o=P("zb:route:end","router"),e.appendChild(this.#r),e.appendChild(this.#o),this.start())}unmount(){this.stop(),this.#i&&(this.#P(),this.#i=null),this.#r&&this.#o&&(M(this.#r,this.#o),this.#r.remove(),this.#o.remove()),this.#r=null,this.#o=null,this.#s=null}start(){this.#u||(this.#u=!0,this.#e.mode==="history"?window.addEventListener("popstate",this.#d):this.#e.mode==="hash"&&(window.addEventListener("hashchange",this.#d),window.addEventListener("popstate",this.#d)),this.#b({source:"start"}))}stop(){this.#u&&(this.#u=!1,window.removeEventListener("popstate",this.#d),window.removeEventListener("hashchange",this.#d))}navigate(t,e={}){return this.#g(t,{...e,replace:!1})}replace(t,e={}){return this.#g(t,{...e,replace:!0})}back(){if(this.#e.mode==="memory"){this.#w();return}history.back()}forward(){if(this.#e.mode==="memory"){this.#x();return}history.forward()}go(t){if(this.#e.mode==="memory"){this.#y(t);return}history.go(t)}resolve(t){if(typeof t=="string"){let u=new URL(t,window.location.origin),a=Y(u.pathname,this.#e.trailingSlash),f=this.#e.basePath;return f&&!a.startsWith(f)&&(a=`${f}${a}`),`${a}${u.search||""}${u.hash||""}`}let e=Y(t.pathname||"/",this.#e.trailingSlash),n=t.search||ht(t.query),s=t.hash||"",i=this.#e.basePath;return`${i&&!e.startsWith(i)?`${i}${e}`:e}${n}${s}`}parse(t){let e=this.#m(t),n=this.#v(e.pathname);return n?{location:e,match:n}:{location:e,match:null}}get current(){return this.#i}async checkGuards(){if(!this.#i)return!0;let t={router:this,route:this.#i.route,chain:this.#i.chain,params:this.#i.params,query:this.#i.query,location:this.#i.location,state:this.#i.location?.state??null,source:"revalidate"},e=new Set;return await this.#E(this.#i.chain,t,e)}queryParameters(t={}){let e=t.replace??!0,n=t.preserveHash??!0,s=I(this.#h()?.query||{}),i=ht(s.get()),o=!1,u=c=>{let l=c?.query||{},h=ht(l);h!==i&&(i=h,s.set(l))},a=this.afterEach(({location:c})=>{if(o){o=!1;return}u(c)}),f=$(s).change(c=>{let l=ht(c);if(l===i)return;i=l,o=!0;let h=this.#h(),d=h?.pathname||"/",b=n&&h?.hash||"",g={pathname:d,query:c,hash:b};e?this.replace(g):this.navigate(g)});return Object.defineProperty(s,"dispose",{value:()=>{typeof a=="function"&&a(),typeof f=="function"&&f()},enumerable:!1}),s}#d=()=>{this.#b({source:"pop"})};#h(){if(this.#e.mode==="memory")return this.#a.stack[this.#a.index];if(this.#e.mode==="hash"){let t=window.location.hash?window.location.hash.slice(1):"/";return this.#m(t)}return this.#m(window.location.href)}#m(t){let e=window.location.origin,n=new URL(t,e),s=Y(n.pathname,this.#e.trailingSlash),i=this.#e.basePath,o=i&&s.startsWith(i)?s.slice(i.length)||"/":s;return{pathname:Y(o,this.#e.trailingSlash),search:n.search||"",hash:n.hash||"",query:vr(n.search),state:history.state??null,url:Ar({pathname:n.pathname,search:n.search,hash:n.hash})}}#w(){this.#a.index<=0||(this.#a.index-=1,this.#b({source:"pop"}))}#x(){this.#a.index>=this.#a.stack.length-1||(this.#a.index+=1,this.#b({source:"pop"}))}#y(t){let e=this.#a.index+t;e<0||e>=this.#a.stack.length||(this.#a.index=e,this.#b({source:"pop"}))}async#g(t,{replace:e,state:n,redirectChain:s}={}){let i=typeof t=="string"?t:this.resolve(t),o=this.#m(i);o.state=n??null;let u=++this.#c;if(!await this.#A(o,{token:u,source:"navigate",redirectChain:s}))return;if(this.#e.mode==="memory"){e?this.#a.stack[this.#a.index]={...o,state:n??null}:(this.#a.stack=this.#a.stack.slice(0,this.#a.index+1),this.#a.stack.push({...o,state:n??null}),this.#a.index=this.#a.stack.length-1);return}let f=this.resolve(o.pathname)+(o.search||"")+(o.hash||"");if(this.#e.mode==="hash"){let c=`#${f}`;history[e?"replaceState":"pushState"](n??null,"",c)}else history[e?"replaceState":"pushState"](n??null,"",f)}async#b({source:t,redirectChain:e}={}){if(!this.#s||!this.#r||!this.#o)return;let n=++this.#c,s=this.#h(),i=e||new Set;await this.#A(s,{token:n,source:t,redirectChain:i})}#v(t){for(let e of this.#t){let n=e.regex.exec(t);if(!n)continue;let s={};for(let u=0;u<e.keys.length;u++){let a=e.keys[u];s[a]=n[u+1]?decodeURIComponent(n[u+1]):void 0}let i=[],o=e;for(;o;)i.unshift(o),o=o.parent;return{route:e,params:s,chain:i}}return null}async#A(t,{token:e,source:n,redirectChain:s}){if(e!==this.#c)return;let i=this.#v(t.pathname);if(!i)return!1;let{route:o,params:u,chain:a}=i,f=this.#i&&this.#i.route===o,c=o.reuse??o.page?.reuse??!0,l=o.transition||o.page?.transition||this.#e.transition,h={router:this,route:o,chain:a,params:u,query:t.query||{},location:t,state:t.state??null,source:n};try{if(await this.#S(a,h,s))return!1;if(!await this.#E(a,h,s))return n==="pop"&&this.#$(),!1;let g=await this.#L(a,h);if(e!==this.#c)return!1;if(h.data=g?.leaf??g,h.routeData=g?.map??{},f&&this.#i?.page&&c)return this.#O(h),!0;let p=await this.#B(o,h);return e!==this.#c||!p?!1:(await this.#z(p,h,l),!0)}catch(d){return await this.#I(d,h,l)}}async#S(t,e,n){for(let s of t){let i=null;if(typeof s.redirect=="string"&&(i=s.redirect),typeof s.redirect=="function"&&(i=s.redirect({...e,route:s})),typeof i=="string")return this.#k(i,n);if(Be(i)){let o=await i;if(typeof o=="string")return this.#k(o,n)}}return!1}async#E(t,e,n){for(let s of this.#f){let i=await s(e);if(await this.#R(i,n))return!1}for(let s of t){let i=[];Array.isArray(s.guards)&&i.push(...s.guards),typeof s.guards=="function"&&i.push(s.guards),typeof s.beforeEnter=="function"&&i.push(s.beforeEnter),typeof s.page?.guards=="function"&&i.push(s.page.guards),Array.isArray(s.page?.guards)&&i.push(...s.page.guards),typeof s.page?.beforeEnter=="function"&&i.push(s.page.beforeEnter);for(let o of i){let u=await o({...e,route:s});if(await this.#R(u,n))return!1}}return!0}async#R(t,e){if(t===!1)return!0;if(typeof t=="string")return this.#k(t,e);if(t&&typeof t=="object"&&typeof t.redirect=="string")return this.#k(t.redirect,e);if(Be(t)){let n=await t;return this.#R(n,e)}return!1}async#L(t,e){let n={},s;for(let i of t){let o=i.loader||i.page?.loader;if(typeof o!="function")continue;let u=await o({...e,route:i});n[i.id]=u,i===t[t.length-1]&&(s=u)}return{map:n,leaf:s}}async#B(t,e){if(t.page&&dt(t.page))return t.page;if(typeof t.load=="function"){let n=await t.load(e);if(n?.default&&dt(n.default))return n.default;if(dt(n))return n}return null}async#z(t,e,n){let s={params:e.params,query:e.query,location:e.location,data:e.data,state:e.state,router:this,route:e.route,...typeof e.route.props=="function"?e.route.props(e):{}},i,o=!1;if(t.prototype&&t.prototype.constructor===t&&!t.__zbFactory)try{i=new t(s),o=!0}catch{i=t(s)}else i=t(s);o&&i&&typeof i=="object"&&(i.router=this,i.route=e.route,i.params=e.params,i.query=e.query,i.location=e.location,i.data=e.data,i.state=e.state);let u=this.#i;if(u?.page){let c={...e,from:u};u.page.emitBefore?.("routeLeave",c,{router:this,page:u.page}),u.page.emitAfter?.("routeLeave",c,{router:this,page:u.page})}i.emitBefore?.("routeEnter",e,{router:this,page:i});let a=this.#j(i,e),f=m.normalize(a);for(let c of f)m.isRenderable(c)?c.mountInto(this.#s,this.#o):m.isDomNode(c)&&this.#o.parentNode.insertBefore(c,this.#o);i.emitAfter?.("routeEnter",e,{router:this,page:i}),u&&this.#P(),this.#i={route:e.route,chain:e.chain,page:i,mounted:f,params:e.params,query:e.query,location:e.location,data:e.data,routeData:e.routeData};for(let c of this.#l)c({...e,page:i});this.#T(e)}#O(t){let e=this.#i;if(e?.page){e.chain=t.chain,e.params=t.params,e.query=t.query,e.location=t.location,e.data=t.data,e.page.params=t.params,e.page.query=t.query,e.page.location=t.location,e.page.data=t.data,e.page.state=t.state,e.page.emitBefore?.("routeUpdate",t,{router:this,page:e.page}),e.page.emitAfter?.("routeUpdate",t,{router:this,page:e.page});for(let n of this.#l)n({...t,page:e.page});this.#T(t)}}async#M(t,e,n){if(!n||!t)return;let s=n.enterClass||"zb-route-enter",i=n.enterActiveClass||"zb-route-enter-active",o=n.exitClass||"zb-route-exit",u=n.exitActiveClass||"zb-route-exit-active",a=n.duration??180;e.classList.add(s),t.classList.add(o),await new Promise(f=>requestAnimationFrame(f)),e.classList.add(i),t.classList.add(u),await new Promise(f=>setTimeout(f,a)),e.classList.remove(s,i),t.classList.remove(o,u)}#P(){let t=this.#i;if(t&&Array.isArray(t.mounted))for(let e of t.mounted)m.unmount(e)}#j(t,e){let n=t,s=e.chain||[];for(let i=s.length-1;i>=0;i--){let o=s[i];typeof o.layout=="function"&&(n=o.layout(n,{...e,route:o}))}return n}async#k(t,e){if(e.size>=this.#e.maxRedirects)throw new Error("Router: too many redirects");if(e.has(t))throw new Error(`Router: redirect loop to "${t}"`);return e.add(t),await this.#g(t,{replace:!0,redirectChain:e}),!0}async#I(t,e,n){let s=e.route.errorPage||this.#e.errorPage;if(!s)throw t;let i={...e,error:t};await this.#z(s,i,n);let o=this.#i?.page;return o&&(o.emitBefore("routeError",i,{router:this,page:o}),o.emitAfter("routeError",i,{router:this,page:o})),!0}#T(t){if(!this.#e.scrollRestoration)return;let e=t.location?.hash;if(e&&e.length>1){let n=e.slice(1),s=document.getElementById(n);if(s){s.scrollIntoView();return}}window.scrollTo(0,0)}#$(){let t=this.#i?.location;if(!t)return;let e=this.resolve(t.pathname)+(t.search||"")+(t.hash||"");if(this.#e.mode==="hash"){history.replaceState(t.state??null,"",`#${e}`);return}history.replaceState(t.state??null,"",e)}};function Oe(r){let t=new Q(r);if(r?.routes&&Array.isArray(r.routes))for(let e of r.routes)t.add(e);return t}var je=new Q;var Ct=class extends T{#t;#n;#e;#s;#r=[];#o=!1;constructor(t,e,n,s){super(),this.#t=t,this.#n=e,this.#e=n,this.#s=s}mountInto(t,e){if(!this.#o){this.#o=!0;for(let n of this.#e)n._connect(this.#n);this.#s.push({signal:this.#n,consumers:this.#r}),this.#t.mountInto(t,e),this.#s.pop()}}unmount(){if(this.#o){this.#o=!1,this.#t.unmount();for(let t of this.#e)t._disconnect();for(let t of this.#r)t._disconnect();this.#r=[]}}renderToString(t){for(let n of this.#e)n._connect(this.#n);this.#s.push({signal:this.#n,consumers:this.#r});let e=t(this.#t);return this.#s.pop(),e}};function kr(r){let t=q(r),e=new Set,n=null,s=null,i=null,o=(...c)=>{for(let l of e)l(...c)};i=L(t,o);let u=()=>n||t,a={kind:"state",get:()=>A(u()),set:c=>F(u(),c,!0),subscribe:c=>(e.add(c),()=>e.delete(c)),before:t.before};return{state:G(a),_connect(c){n=c,i&&(i(),i=null),s=L(c,o);let l=A(c),h=A(t);l!==h&&o(l,h)},_disconnect(){s&&(s(),s=null),n=null,i=L(t,o)}}}function Ie(r){let t=[],e=[];return{scope:i=>{let o=q(i!==void 0?i:r),u={kind:"state",get:()=>A(o),set:c=>F(o,c,!0),subscribe:c=>L(o,c),before:o.before},a=G(u),f=c=>{let l=t.splice(0,t.length);return new Ct(c,o,l,e)};return new Proxy(a,{get(c,l){return l==="serve"?f:Reflect.get(c,l)}})},state:()=>{let i=kr(r);if(e.length>0){let o=e[e.length-1];i._connect(o.signal),o.consumers.push(i)}else t.push(i);return i.state}}}var Rr=["html","head","title","base","link","meta","style","body","article","section","nav","aside","h1","h2","h3","h4","h5","h6","hgroup","header","footer","address","main","search","p","hr","pre","blockquote","ol","ul","li","dl","dt","dd","figure","figcaption","div","menu","a","em","strong","small","s","cite","q","dfn","abbr","ruby","rt","rp","data","time","code","var","samp","kbd","sub","sup","i","b","u","mark","bdi","bdo","span","br","wbr","ins","del","picture","source","img","iframe","embed","object","param","video","audio","track","map","area","table","caption","colgroup","col","tbody","thead","tfoot","tr","td","th","form","label","input","button","select","datalist","optgroup","option","textarea","output","progress","meter","fieldset","legend","details","summary","dialog","script","noscript","template","slot","canvas"];function zr(r){let t=r.charAt(0).toUpperCase()+r.slice(1);return t in globalThis&&(t=`Html${t}`),t}function Pr(r){return(...t)=>{let e={},n=[],s=i=>!!i&&typeof i=="object"&&!Array.isArray(i)&&!m.isRenderable(i)&&!m.isDomNode(i)&&!j(i)&&!v(i)&&!w(i)&&!x(i)&&!C(i);for(let i of t)s(i)?Object.assign(e,i):n.push(i);return new J(r,e,n)}}var Dt={};for(let r of Rr){let t=zr(r);Dt[t]=Pr(r)}var $e=Object.freeze(Dt),{Html:Ls,Head:Bs,Title:Os,Base:js,Link:Is,Meta:$s,Style:Ms,Body:Cs,Article:Ds,Section:Ns,Nav:qs,Aside:Fs,H1:Ws,H2:Hs,H3:Us,H4:Vs,H5:_s,H6:Gs,Hgroup:Js,Header:Qs,Footer:Zs,Address:Ks,Main:Xs,Search:Ys,P:ti,Hr:ei,Pre:ri,Blockquote:ni,Ol:si,Ul:ii,Li:oi,Dl:ui,Dt:ai,Dd:ci,Figure:fi,Figcaption:li,Div:hi,Menu:di,A:mi,Em:pi,Strong:yi,Small:gi,S:bi,Cite:Si,Q:wi,Dfn:xi,Abbr:vi,Ruby:Ai,Rt:Ei,Rp:ki,Data:Ri,Time:zi,Code:Pi,Var:Ti,Samp:Li,Kbd:Bi,Sub:Oi,Sup:ji,I:Ii,B:$i,U:Mi,Mark:Ci,Bdi:Di,Bdo:Ni,Span:qi,Br:Fi,Wbr:Wi,Ins:Hi,Del:Ui,Picture:Vi,Source:_i,Img:Gi,Iframe:Ji,Embed:Qi,HtmlObject:Zi,Param:Ki,Video:Xi,Audio:Yi,Track:to,Map:eo,Area:ro,Table:no,Caption:so,Colgroup:io,Col:oo,Tbody:uo,Thead:ao,Tfoot:co,Tr:fo,Td:lo,Th:ho,Form:mo,Label:po,Input:yo,Button:go,Select:bo,Datalist:So,Optgroup:wo,Option:xo,Textarea:vo,Output:Ao,Progress:Eo,Meter:ko,Fieldset:Ro,Legend:zo,Details:Po,Summary:To,Dialog:Lo,Script:Bo,Noscript:Oo,Template:jo,Slot:Io,Canvas:$o}=Dt;export{mi as A,vi as Abbr,Ks as Address,ro as Area,Ds as Article,Fs as Aside,Yi as Audio,$i as B,js as Base,Di as Bdi,Ni as Bdo,ni as Blockquote,Cs as Body,Fi as Br,go as Button,$o as Canvas,so as Caption,Si as Cite,Pi as Code,oo as Col,io as Colgroup,Ri as Data,So as Datalist,ci as Dd,Ui as Del,Po as Details,xi as Dfn,Lo as Dialog,hi as Div,ui as Dl,ai as Dt,$e as Elements,pi as Em,Qi as Embed,be as ErrorBoundary,H as EventHub,Ro as Fieldset,li as Figcaption,fi as Figure,Zs as Footer,mo as Form,Ws as H1,Hs as H2,Us as H3,Vs as H4,_s as H5,Gs as H6,Bs as Head,Qs as Header,Js as Hgroup,ei as Hr,Ls as Html,Zi as HtmlObject,Ii as I,Ji as Iframe,Gi as Img,yo as Input,Hi as Ins,Bi as Kbd,po as Label,zo as Legend,oi as Li,Is as Link,Xs as Main,eo as Map,Ci as Mark,di as Menu,$s as Meta,ko as Meter,qs as Nav,Oo as Noscript,si as Ol,wo as Optgroup,xo as Option,Ao as Output,ti as P,Ki as Param,Vi as Picture,ri as Pre,Eo as Progress,wi as Q,lt as QueryClient,T as Renderable,m as Renderer,Q as Router,ki as Rp,Ei as Rt,Ai as Ruby,bi as S,Li as Samp,Bo as Script,Ys as Search,Ns as Section,bo as Select,Io as Slot,gi as Small,_i as Source,qi as Span,yi as Strong,Ms as Style,Oi as Sub,To as Summary,ji as Sup,no as Table,uo as Tbody,lo as Td,jo as Template,vo as Textarea,co as Tfoot,ho as Th,ao as Thead,zi as Time,Os as Title,fo as Tr,to as Track,Mi as U,ii as Ul,Ti as Var,Xi as Video,Wi as Wbr,X as WebSocketClient,$ as after,ie as before,qt as bootstrap,Ut as component,ae as computed,fe as concat,Ie as context,Oe as createRouter,ve as createWebSocket,de as form,Pe as hydrate,C as isComputed,v as isSignal,w as isState,x as isStatePath,me as list,Ht as observableArray,he as persist,xe as portal,A as readSignal,ze as renderToString,Z as resolve,je as router,oe as set,F as setSignal,q as signal,I as state,ue as subscribe,we as virtualList,ye as when};
2
+ //# sourceMappingURL=granular.min.js.map