tina4js 1.1.1 → 1.2.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.
@@ -1 +1 @@
1
- "use strict";const p=require("./signal.cjs.js");let r=null,n=null;function u(h,t){r=h,n=t}const e=class e extends HTMLElement{constructor(){super(),this._props={},this._rendered=!1;const t=this.constructor;this._root=t.shadow?this.attachShadow({mode:"open"}):this;for(const[o,s]of Object.entries(t.props))this._props[o]=p.signal(this._coerce(this.getAttribute(o),s))}static get observedAttributes(){return Object.keys(this.props)}connectedCallback(){if(this._rendered)return;this._rendered=!0;const t=this.constructor;if(t.styles&&t.shadow&&this._root instanceof ShadowRoot){const s=document.createElement("style");s.textContent=t.styles,this._root.appendChild(s)}const o=this.render();o&&this._root.appendChild(o),this.onMount(),r&&r(this)}disconnectedCallback(){this.onUnmount(),n&&n(this)}attributeChangedCallback(t,o,s){const c=this.constructor.props[t];c&&this._props[t]&&(this._props[t].value=this._coerce(s,c))}prop(t){if(!this._props[t])throw new Error(`[tina4] Prop '${t}' not declared in static props of <${this.tagName.toLowerCase()}>`);return this._props[t]}emit(t,o){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,...o}))}onMount(){}onUnmount(){}_coerce(t,o){return o===Boolean?t!==null:o===Number?t!==null?Number(t):0:t??""}};e.props={},e.styles="",e.shadow=!0;let i=e;exports.Tina4Element=i;exports.__setDebugComponentHooks=u;
1
+ "use strict";const r=require("./signal.cjs.js");let c=null,h=null;function _(p,t){c=p,h=t}const i=class i extends HTMLElement{constructor(){super(),this._props={},this._rendered=!1,this._disposeRender=null,this._innerDisposers=[];const t=this.constructor;this._root=t.shadow?this.attachShadow({mode:"open"}):this;for(const[s,o]of Object.entries(t.props))this._props[s]=r.signal(this._coerce(this.getAttribute(s),o))}static get observedAttributes(){return Object.keys(this.props)}connectedCallback(){if(this._rendered)return;this._rendered=!0;const t=this.constructor;let s=null;if(t.styles&&t.shadow&&this._root instanceof ShadowRoot){const o=document.createElement("style");o.textContent=t.styles,this._root.appendChild(o),s=o}this._disposeRender=r.effect(()=>{for(const n of this._innerDisposers)n();this._innerDisposers=[];const o=[],d=r._getEffectCollector();r._setEffectCollector(o);const e=this.render();r._setEffectCollector(d),this._innerDisposers=o;const u=Array.from(this._root.childNodes);for(const n of u)n!==s&&this._root.removeChild(n);e&&this._root.appendChild(e)}),this.onMount(),c&&c(this)}disconnectedCallback(){this._disposeRender&&(this._disposeRender(),this._disposeRender=null);for(const t of this._innerDisposers)t();this._innerDisposers=[],this.onUnmount(),h&&h(this)}attributeChangedCallback(t,s,o){const e=this.constructor.props[t];e&&this._props[t]&&(this._props[t].value=this._coerce(o,e))}prop(t){if(!this._props[t])throw new Error(`[tina4] Prop '${t}' not declared in static props of <${this.tagName.toLowerCase()}>`);return this._props[t]}emit(t,s){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,...s}))}onMount(){}onUnmount(){}_coerce(t,s){return s===Boolean?t!==null:s===Number?t!==null?Number(t):0:t??""}};i.props={},i.styles="",i.shadow=!0;let l=i;exports.Tina4Element=l;exports.__setDebugComponentHooks=_;
@@ -1,15 +1,15 @@
1
- import { s as p } from "./signal.es.js";
2
- let r = null, n = null;
3
- function a(h, t) {
4
- r = h, n = t;
1
+ import { s as _, e as a, _ as f, a as p } from "./signal.es.js";
2
+ let n = null, c = null;
3
+ function C(l, t) {
4
+ n = l, c = t;
5
5
  }
6
- const e = class e extends HTMLElement {
6
+ const r = class r extends HTMLElement {
7
7
  constructor() {
8
- super(), this._props = {}, this._rendered = !1;
8
+ super(), this._props = {}, this._rendered = !1, this._disposeRender = null, this._innerDisposers = [];
9
9
  const t = this.constructor;
10
10
  this._root = t.shadow ? this.attachShadow({ mode: "open" }) : this;
11
- for (const [o, s] of Object.entries(t.props))
12
- this._props[o] = p(this._coerce(this.getAttribute(o), s));
11
+ for (const [s, o] of Object.entries(t.props))
12
+ this._props[s] = _(this._coerce(this.getAttribute(s), o));
13
13
  }
14
14
  static get observedAttributes() {
15
15
  return Object.keys(this.props);
@@ -18,19 +18,32 @@ const e = class e extends HTMLElement {
18
18
  if (this._rendered) return;
19
19
  this._rendered = !0;
20
20
  const t = this.constructor;
21
+ let s = null;
21
22
  if (t.styles && t.shadow && this._root instanceof ShadowRoot) {
22
- const s = document.createElement("style");
23
- s.textContent = t.styles, this._root.appendChild(s);
23
+ const o = document.createElement("style");
24
+ o.textContent = t.styles, this._root.appendChild(o), s = o;
24
25
  }
25
- const o = this.render();
26
- o && this._root.appendChild(o), this.onMount(), r && r(this);
26
+ this._disposeRender = a(() => {
27
+ for (const i of this._innerDisposers) i();
28
+ this._innerDisposers = [];
29
+ const o = [], h = f();
30
+ p(o);
31
+ const e = this.render();
32
+ p(h), this._innerDisposers = o;
33
+ const u = Array.from(this._root.childNodes);
34
+ for (const i of u)
35
+ i !== s && this._root.removeChild(i);
36
+ e && this._root.appendChild(e);
37
+ }), this.onMount(), n && n(this);
27
38
  }
28
39
  disconnectedCallback() {
29
- this.onUnmount(), n && n(this);
40
+ this._disposeRender && (this._disposeRender(), this._disposeRender = null);
41
+ for (const t of this._innerDisposers) t();
42
+ this._innerDisposers = [], this.onUnmount(), c && c(this);
30
43
  }
31
- attributeChangedCallback(t, o, s) {
32
- const i = this.constructor.props[t];
33
- i && this._props[t] && (this._props[t].value = this._coerce(s, i));
44
+ attributeChangedCallback(t, s, o) {
45
+ const e = this.constructor.props[t];
46
+ e && this._props[t] && (this._props[t].value = this._coerce(o, e));
34
47
  }
35
48
  /**
36
49
  * Get a reactive signal for a declared prop.
@@ -53,12 +66,12 @@ const e = class e extends HTMLElement {
53
66
  * this.emit('activate', { detail: 42 });
54
67
  * ```
55
68
  */
56
- emit(t, o) {
69
+ emit(t, s) {
57
70
  this.dispatchEvent(new CustomEvent(t, {
58
71
  bubbles: !0,
59
72
  composed: !0,
60
73
  // crosses shadow DOM boundary
61
- ...o
74
+ ...s
62
75
  }));
63
76
  }
64
77
  // ── Lifecycle hooks (override in subclass) ──────────────────────
@@ -69,13 +82,13 @@ const e = class e extends HTMLElement {
69
82
  onUnmount() {
70
83
  }
71
84
  // ── Private ─────────────────────────────────────────────────────
72
- _coerce(t, o) {
73
- return o === Boolean ? t !== null : o === Number ? t !== null ? Number(t) : 0 : t ?? "";
85
+ _coerce(t, s) {
86
+ return s === Boolean ? t !== null : s === Number ? t !== null ? Number(t) : 0 : t ?? "";
74
87
  }
75
88
  };
76
- e.props = {}, e.styles = "", e.shadow = !0;
77
- let c = e;
89
+ r.props = {}, r.styles = "", r.shadow = !0;
90
+ let d = r;
78
91
  export {
79
- c as T,
80
- a as _
92
+ d as T,
93
+ C as _
81
94
  };
@@ -25,6 +25,10 @@ export declare abstract class Tina4Element extends HTMLElement {
25
25
  private _root;
26
26
  /** Track if we've rendered. */
27
27
  private _rendered;
28
+ /** Dispose function for the reactive render effect. */
29
+ private _disposeRender;
30
+ /** Disposers for inner effects created by html`` during render. */
31
+ private _innerDisposers;
28
32
  static get observedAttributes(): string[];
29
33
  constructor();
30
34
  connectedCallback(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/core/component.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAI/C,oEAAoE;AACpE,eAAO,IAAI,qBAAqB,EAAE,CAAC,CAAC,EAAE,EAAE,YAAY,KAAK,IAAI,CAAC,GAAG,IAAW,CAAC;AAC7E,yEAAyE;AACzE,eAAO,IAAI,uBAAuB,EAAE,CAAC,CAAC,EAAE,EAAE,YAAY,KAAK,IAAI,CAAC,GAAG,IAAW,CAAC;AAC/E,qCAAqC;AACrC,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,OAAO,qBAAqB,EACrC,SAAS,EAAE,OAAO,uBAAuB,QAI1C;AAED,MAAM,MAAM,QAAQ,GAAG,OAAO,MAAM,GAAG,OAAO,MAAM,GAAG,OAAO,OAAO,CAA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,EAAE,eAAe,GAAG,IAAI;IAUhD,iCAAiC;IACjC,OAAO,IAAI,IAAI;IAEf,oCAAoC;IACpC,SAAS,IAAI,IAAI;IAEjB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,IAAI,gBAAgB,GAAG,IAAI,GAAG,IAAI;IAIjD,OAAO,CAAC,OAAO;CAKhB"}
package/dist/core.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as u, e as d, a as C, d as A, b as y } from "./signal.es.js";
1
+ import { i as u, e as d, _ as C, a as A, b as y } from "./signal.es.js";
2
2
  import { c as M, s as R } from "./signal.es.js";
3
3
  import { T as F } from "./component.es.js";
4
4
  const N = /* @__PURE__ */ new WeakMap(), p = "t4:";
package/dist/debug.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as C } from "./signal.es.js";
1
+ import { d as C } from "./signal.es.js";
2
2
  import { _ as S } from "./component.es.js";
3
3
  import { _ as R, a as A } from "./index.es.js";
4
4
  import { api as x } from "./api.es.js";
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { d as y } from "./signal.es.js";
1
+ import { a as y } from "./signal.es.js";
2
2
  let p = [], a = null, u = "history";
3
3
  const c = [];
4
4
  let l = [], w = 0;
package/dist/pwa/pwa.d.ts CHANGED
@@ -13,6 +13,8 @@ export interface PWAConfig {
13
13
  cacheStrategy?: 'cache-first' | 'network-first' | 'stale-while-revalidate';
14
14
  precache?: string[];
15
15
  offlineRoute?: string;
16
+ /** URL to a pre-built service worker file (e.g. "/sw.js"). When provided, blob: registration is skipped. */
17
+ swUrl?: string;
16
18
  }
17
19
  export declare const pwa: {
18
20
  register(config: PWAConfig): void;
@@ -1 +1 @@
1
- {"version":3,"file":"pwa.d.ts","sourceRoot":"","sources":["../../src/pwa/pwa.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAA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object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function a(e){const t=e.cacheStrategy??"network-first",r=JSON.stringify(e.precache??[]),n=e.offlineRoute?`'${e.offlineRoute}'`:"null";return`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e){const t=e.cacheStrategy??"network-first",c=JSON.stringify(e.precache??[]),n=e.offlineRoute?`'${e.offlineRoute}'`:"null";return`
2
2
  const CACHE = 'tina4-v1';
3
- const PRECACHE = ${r};
3
+ const PRECACHE = ${c};
4
4
  const OFFLINE = ${n};
5
5
 
6
6
  self.addEventListener('install', (e) => {
@@ -44,4 +44,4 @@ self.addEventListener('fetch', (e) => {
44
44
  ))
45
45
  );`}
46
46
  });
47
- `.trim()}function s(e){const t={name:e.name,short_name:e.shortName??e.name,start_url:"/",display:e.display??"standalone",background_color:e.backgroundColor??"#ffffff",theme_color:e.themeColor??"#000000"};return e.icon&&(t.icons=[{src:e.icon,sizes:"192x192",type:"image/png"},{src:e.icon,sizes:"512x512",type:"image/png"}]),t}const d={register(e){const t=s(e),r=new Blob([JSON.stringify(t)],{type:"application/json"}),n=document.createElement("link");n.rel="manifest",n.href=URL.createObjectURL(r),document.head.appendChild(n);let c=document.querySelector('meta[name="theme-color"]');if(c||(c=document.createElement("meta"),c.name="theme-color",document.head.appendChild(c)),c.content=e.themeColor??"#000000","serviceWorker"in navigator){const o=a(e),h=new Blob([o],{type:"text/javascript"}),i=URL.createObjectURL(h);navigator.serviceWorker.register(i).catch(l=>{console.warn("[tina4] Service worker registration failed:",l)})}},generateServiceWorker(e){return a(e)},generateManifest(e){return s(e)}};exports.pwa=d;
47
+ `.trim()}function s(e){const t={name:e.name,short_name:e.shortName??e.name,start_url:"/",display:e.display??"standalone",background_color:e.backgroundColor??"#ffffff",theme_color:e.themeColor??"#000000"};return e.icon&&(t.icons=[{src:e.icon,sizes:"192x192",type:"image/png"},{src:e.icon,sizes:"512x512",type:"image/png"}]),t}const i={register(e){const t=s(e),c=new Blob([JSON.stringify(t)],{type:"application/json"}),n=document.createElement("link");n.rel="manifest",n.href=URL.createObjectURL(c),document.head.appendChild(n);let r=document.querySelector('meta[name="theme-color"]');r||(r=document.createElement("meta"),r.name="theme-color",document.head.appendChild(r)),r.content=e.themeColor??"#000000","serviceWorker"in navigator&&(e.swUrl?navigator.serviceWorker.register(e.swUrl).catch(a=>{console.warn("[tina4] Service worker registration failed:",a)}):navigator.serviceWorker.register("/sw.js").catch(()=>{console.info("[tina4] No service worker at /sw.js. Use pwa.generateServiceWorker() to create one, or pass swUrl in config.")}))},generateServiceWorker(e){return o(e)},generateManifest(e){return s(e)}};exports.pwa=i;
package/dist/pwa.es.js CHANGED
@@ -1,8 +1,8 @@
1
- function a(e) {
2
- const t = e.cacheStrategy ?? "network-first", r = JSON.stringify(e.precache ?? []), n = e.offlineRoute ? `'${e.offlineRoute}'` : "null";
1
+ function o(e) {
2
+ const t = e.cacheStrategy ?? "network-first", c = JSON.stringify(e.precache ?? []), n = e.offlineRoute ? `'${e.offlineRoute}'` : "null";
3
3
  return `
4
4
  const CACHE = 'tina4-v1';
5
- const PRECACHE = ${r};
5
+ const PRECACHE = ${c};
6
6
  const OFFLINE = ${n};
7
7
 
8
8
  self.addEventListener('install', (e) => {
@@ -62,21 +62,20 @@ function s(e) {
62
62
  { src: e.icon, sizes: "512x512", type: "image/png" }
63
63
  ]), t;
64
64
  }
65
- const d = {
65
+ const i = {
66
66
  register(e) {
67
- const t = s(e), r = new Blob([JSON.stringify(t)], { type: "application/json" }), n = document.createElement("link");
68
- n.rel = "manifest", n.href = URL.createObjectURL(r), document.head.appendChild(n);
69
- let c = document.querySelector('meta[name="theme-color"]');
70
- if (c || (c = document.createElement("meta"), c.name = "theme-color", document.head.appendChild(c)), c.content = e.themeColor ?? "#000000", "serviceWorker" in navigator) {
71
- const o = a(e), h = new Blob([o], { type: "text/javascript" }), i = URL.createObjectURL(h);
72
- navigator.serviceWorker.register(i).catch((l) => {
73
- console.warn("[tina4] Service worker registration failed:", l);
74
- });
75
- }
67
+ const t = s(e), c = new Blob([JSON.stringify(t)], { type: "application/json" }), n = document.createElement("link");
68
+ n.rel = "manifest", n.href = URL.createObjectURL(c), document.head.appendChild(n);
69
+ let r = document.querySelector('meta[name="theme-color"]');
70
+ r || (r = document.createElement("meta"), r.name = "theme-color", document.head.appendChild(r)), r.content = e.themeColor ?? "#000000", "serviceWorker" in navigator && (e.swUrl ? navigator.serviceWorker.register(e.swUrl).catch((a) => {
71
+ console.warn("[tina4] Service worker registration failed:", a);
72
+ }) : navigator.serviceWorker.register("/sw.js").catch(() => {
73
+ console.info("[tina4] No service worker at /sw.js. Use pwa.generateServiceWorker() to create one, or pass swUrl in config.");
74
+ }));
76
75
  },
77
76
  /** Generate SW code as a string (for build tools that write sw.js to disk). */
78
77
  generateServiceWorker(e) {
79
- return a(e);
78
+ return o(e);
80
79
  },
81
80
  /** Generate manifest object (for build tools that write manifest.json to disk). */
82
81
  generateManifest(e) {
@@ -84,5 +83,5 @@ const d = {
84
83
  }
85
84
  };
86
85
  export {
87
- d as pwa
86
+ i as pwa
88
87
  };
package/dist/signal.es.js CHANGED
@@ -114,11 +114,11 @@ function k(t) {
114
114
  return t !== null && typeof t == "object" && t._t4 === !0;
115
115
  }
116
116
  export {
117
- w as _,
118
- C as a,
117
+ C as _,
118
+ y as a,
119
119
  S as b,
120
120
  E as c,
121
- y as d,
121
+ w as d,
122
122
  h as e,
123
123
  k as i,
124
124
  v as s
@@ -1,4 +1,4 @@
1
- "use strict";var Tina4=(()=>{var J=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var Ne=(t,n)=>{for(var e in n)J(t,e,{get:n[e],enumerable:!0})},He=(t,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Oe(n))!Ie.call(t,r)&&r!==e&&J(t,r,{get:()=>n[r],enumerable:!(o=qe(n,r))||o.enumerable});return t};var De=t=>He(J({},"__esModule",{value:!0}),t);var Je={};Ne(Je,{Tina4Element:()=>R,api:()=>ke,batch:()=>U,computed:()=>ce,effect:()=>k,html:()=>ue,isSignal:()=>x,navigate:()=>$,pwa:()=>Te,route:()=>he,router:()=>ve,signal:()=>v,sse:()=>Ce,ws:()=>Ee});var O=null,H=null,F=null;function _(t){F=t}function ie(){return F}var se=null,ae=null;var j=0,V=new Set;function v(t,n){let e=t,o=new Set,r={_t4:!0,get value(){if(O&&(o.add(O),H)){let s=O;H.push(()=>o.delete(s))}return e},set value(s){if(Object.is(s,e))return;let i=e;if(e=s,r._debugInfo&&r._debugInfo.updateCount++,ae&&ae(r,i,s),j>0)for(let a of o)V.add(a);else{let a;for(let l of[...o])try{l()}catch(c){a===void 0&&(a=c)}if(a!==void 0)throw a}},_subscribe(s){return o.add(s),()=>{o.delete(s)}},peek(){return e}};return se&&(r._debugInfo={label:n,createdAt:Date.now(),updateCount:0,subs:o},se(r,n)),r}function ce(t){let n=v(void 0);return k(()=>{n.value=t()}),{_t4:!0,get value(){return n.value},set value(e){throw new Error("[tina4] computed signals are read-only")},_subscribe(e){return n._subscribe(e)},peek(){return n.peek()}}}function k(t){let n=!1,e=[],o=()=>{if(n)return;for(let a of e)a();e=[];let s=O,i=H;O=o,H=e;try{t()}finally{O=s,H=i}};o();let r=()=>{n=!0;for(let s of e)s();e=[]};return F&&F.push(r),r}function U(t){j++;try{t()}finally{if(j--,j===0){let n=[...V];V.clear();let e;for(let o of n)try{o()}catch(r){e===void 0&&(e=r)}if(e!==void 0)throw e}}}function x(t){return t!==null&&typeof t=="object"&&t._t4===!0}var le=new WeakMap,z="t4:";function ue(t,...n){let e=le.get(t);if(!e){e=document.createElement("template");let i="";for(let a=0;a<t.length;a++)i+=t[a],a<n.length&&(Fe(i)?i+=`__t4_${a}__`:i+=`<!--${z}${a}-->`);e.innerHTML=i,le.set(t,e)}let o=e.content.cloneNode(!0),r=Le(o);for(let{marker:i,index:a}of r)Ke(i,n[a]);let s=Pe(o);for(let i of s)je(i,n);return o}function Le(t){let n=[];return X(t,e=>{if(e.nodeType===8){let o=e.data;if(o&&o.startsWith(z)){let r=parseInt(o.slice(z.length),10);n.push({marker:e,index:r})}}}),n}function Pe(t){let n=[];return X(t,e=>{e.nodeType===1&&n.push(e)}),n}function X(t,n){let e=t.childNodes;for(let o=0;o<e.length;o++){let r=e[o];n(r),X(r,n)}}function Ke(t,n){let e=t.parentNode;if(e)if(x(n)){let o=document.createTextNode("");e.replaceChild(o,t),k(()=>{o.data=String(n.value??"")})}else if(typeof n=="function"){let o=document.createComment("");e.replaceChild(o,t);let r=[],s=[];k(()=>{for(let u of s)u();s=[];let i=[],a=ie();_(i);let l=n();_(a),s=i;for(let u of r)u.parentNode?.removeChild(u);r=[];let c=Q(l),d=o.parentNode;if(d)for(let u of c)d.insertBefore(u,o),r.push(u)})}else if(de(n))e.replaceChild(n,t);else if(n instanceof Node)e.replaceChild(n,t);else if(Array.isArray(n)){let o=document.createDocumentFragment();for(let r of n){let s=Q(r);for(let i of s)o.appendChild(i)}e.replaceChild(o,t)}else{let o=document.createTextNode(String(n??""));e.replaceChild(o,t)}}function je(t,n){let e=[];for(let o of Array.from(t.attributes)){let r=o.name,s=o.value;if(r.startsWith("@")){let a=r.slice(1),l=s.match(/__t4_(\d+)__/);if(l){let c=n[parseInt(l[1],10)];typeof c=="function"&&t.addEventListener(a,d=>U(()=>c(d)))}e.push(r);continue}if(r.startsWith("?")){let a=r.slice(1),l=s.match(/__t4_(\d+)__/);if(l){let c=n[parseInt(l[1],10)];if(x(c)){let d=c;k(()=>{d.value?t.setAttribute(a,""):t.removeAttribute(a)})}else typeof c=="function"?k(()=>{c()?t.setAttribute(a,""):t.removeAttribute(a)}):c&&t.setAttribute(a,"")}e.push(r);continue}if(r.startsWith(".")){let a=r.slice(1),l=s.match(/__t4_(\d+)__/);if(l){let c=n[parseInt(l[1],10)];x(c)?k(()=>{t[a]=c.value}):t[a]=c}e.push(r);continue}let i=s.match(/__t4_(\d+)__/);if(i){let a=n[parseInt(i[1],10)];if(x(a)){let l=a;k(()=>{t.setAttribute(r,String(l.value??""))})}else typeof a=="function"?k(()=>{t.setAttribute(r,String(a()??""))}):t.setAttribute(r,String(a??""))}}for(let o of e)t.removeAttribute(o)}function Q(t){if(t==null||t===!1)return[];if(de(t))return Array.from(t.childNodes);if(t instanceof Node)return[t];if(Array.isArray(t)){let n=[];for(let e of t)n.push(...Q(e));return n}return[document.createTextNode(String(t))]}function de(t){return t!=null&&typeof t=="object"&&t.nodeType===11}function Fe(t){let n=!1,e=!1,o=!1;for(let r=0;r<t.length;r++){let s=t[r];s==="<"&&!n&&!e&&(o=!0),s===">"&&!n&&!e&&(o=!1),o&&(s==='"'&&!n&&(e=!e),s==="'"&&!e&&(n=!n))}return o}var fe=null,pe=null;var R=class extends HTMLElement{constructor(){super();this._props={};this._rendered=!1;let e=this.constructor;this._root=e.shadow?this.attachShadow({mode:"open"}):this;for(let[o,r]of Object.entries(e.props))this._props[o]=v(this._coerce(this.getAttribute(o),r))}static get observedAttributes(){return Object.keys(this.props)}connectedCallback(){if(this._rendered)return;this._rendered=!0;let e=this.constructor;if(e.styles&&e.shadow&&this._root instanceof ShadowRoot){let r=document.createElement("style");r.textContent=e.styles,this._root.appendChild(r)}let o=this.render();o&&this._root.appendChild(o),this.onMount(),fe&&fe(this)}disconnectedCallback(){this.onUnmount(),pe&&pe(this)}attributeChangedCallback(e,o,r){let i=this.constructor.props[e];i&&this._props[e]&&(this._props[e].value=this._coerce(r,i))}prop(e){if(!this._props[e])throw new Error(`[tina4] Prop '${e}' not declared in static props of <${this.tagName.toLowerCase()}>`);return this._props[e]}emit(e,o){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,...o}))}onMount(){}onUnmount(){}_coerce(e,o){return o===Boolean?e!==null:o===Number?e!==null?Number(e):0:e??""}};R.props={},R.styles="",R.shadow=!0;var Y=[],I=null,D="history",Ue=!1,L=[],W=[],ge=0;function he(t,n){let e=[],o;t==="*"?o=".*":o=t.replace(/\{(\w+)\}/g,(s,i)=>(e.push(i),"([^/]+)"));let r=new RegExp(`^${o}$`);typeof n=="function"?Y.push({pattern:t,regex:r,paramNames:e,handler:n}):Y.push({pattern:t,regex:r,paramNames:e,handler:n.handler,guard:n.guard})}function $(t,n){if(D==="hash")if(n?.replace){let e=new URL(location.href);e.hash="#"+t,history.replaceState(null,"",e.toString()),P()}else location.hash="#"+t;else n?.replace?history.replaceState(null,"",t):history.pushState(null,"",t),P()}function P(){if(!I)return;let t=performance.now(),n=++ge,e=D==="hash"?location.hash.slice(1)||"/":location.pathname;for(let o of Y){let r=e.match(o.regex);if(!r)continue;let s={};if(o.paramNames.forEach((l,c)=>{s[l]=decodeURIComponent(r[c+1])}),o.guard){let l=o.guard();if(l===!1)return;if(typeof l=="string"){$(l,{replace:!0});return}}for(let l of W)l();W=[],I.innerHTML="";let i=[];_(i);let a=o.handler(s);if(a instanceof Promise)a.then(l=>{if(_(null),n!==ge){for(let d of i)d();return}me(I,l),W=i;let c=performance.now()-t;for(let d of L)d({path:e,params:s,pattern:o.pattern,durationMs:c})});else{_(null),me(I,a),W=i;let l=performance.now()-t;for(let c of L)c({path:e,params:s,pattern:o.pattern,durationMs:l})}return}}function me(t,n){n instanceof DocumentFragment||n instanceof Node?t.replaceChildren(n):typeof n=="string"?t.innerHTML=n:n!=null&&t.replaceChildren(document.createTextNode(String(n)))}var ve={start(t){if(I=document.querySelector(t.target),!I)throw new Error(`[tina4] Router target '${t.target}' not found in DOM`);D=t.mode??"history",Ue=!0,window.addEventListener("popstate",P),D==="hash"&&window.addEventListener("hashchange",P),document.addEventListener("click",n=>{if(n.metaKey||n.ctrlKey||n.shiftKey||n.altKey)return;let e=n.target.closest("a[href]");if(!e||e.origin!==location.origin||e.hasAttribute("target")||e.hasAttribute("download")||e.getAttribute("rel")?.includes("external"))return;n.preventDefault();let o=D==="hash"?e.getAttribute("href"):e.pathname;$(o)}),P()},on(t,n){return L.push(n),()=>{let e=L.indexOf(n);e>=0&&L.splice(e,1)}}};var y={baseUrl:"",auth:!1,tokenKey:"tina4_token",headers:{}},G=[],B=[],ye=0;function Z(){try{return localStorage.getItem(y.tokenKey)}catch{return null}}function be(t){try{localStorage.setItem(y.tokenKey,t)}catch{}}async function N(t,n,e,o){let r={method:t,headers:{"Content-Type":"application/json",...y.headers}};if(y.auth){let u=Z();u&&(r.headers.Authorization=`Bearer ${u}`)}if(e!==void 0&&t!=="GET"){let u=typeof e=="object"&&e!==null?{...e}:e;if(y.auth&&typeof u=="object"&&u!==null){let g=Z();g&&(u.formToken=g)}r.body=JSON.stringify(u)}if(o?.headers&&Object.assign(r.headers,o.headers),o?.params){let u=Object.entries(o.params).map(([g,b])=>`${encodeURIComponent(g)}=${encodeURIComponent(String(b))}`).join("&");n+=(n.includes("?")?"&":"?")+u}let s=y.baseUrl+n;r._url=s,r._requestId=++ye;for(let u of G){let g=u(r);g&&(r=g)}let i=await fetch(s,r),a=i.headers.get("FreshToken");a&&be(a);let l=i.headers.get("Content-Type")??"",c;l.includes("json")?c=await i.json():c=await i.text();let d={status:i.status,data:c,ok:i.ok,headers:i.headers,_requestId:r._requestId};for(let u of B){let g=u(d);g&&(d=g)}if(!i.ok)throw d;return d.data}var ke={configure(t){Object.assign(y,t)},get(t,n){return N("GET",t,void 0,n)},post(t,n,e){return N("POST",t,n,e)},put(t,n,e){return N("PUT",t,n,e)},patch(t,n,e){return N("PATCH",t,n,e)},delete(t,n){return N("DELETE",t,void 0,n)},async graphql(t,n,e,o){return N("POST",t,{query:n,variables:e||{}},o)},async upload(t,n,e){let o={method:"POST",headers:{...y.headers},body:n};if(delete o.headers["Content-Type"],delete o.headers["content-type"],y.auth){let d=Z();d&&(o.headers.Authorization=`Bearer ${d}`)}if(e?.headers&&Object.assign(o.headers,e.headers),e?.params){let d=Object.entries(e.params).map(([u,g])=>`${encodeURIComponent(u)}=${encodeURIComponent(String(g))}`).join("&");t+=(t.includes("?")?"&":"?")+d}let r=y.baseUrl+t;o._url=r,o._requestId=++ye;for(let d of G){let u=d(o);u&&(o=u)}let s=await fetch(r,o),i=s.headers.get("FreshToken");i&&be(i);let a=s.headers.get("Content-Type")??"",l;a.includes("json")?l=await s.json():l=await s.text();let c={status:s.status,data:l,ok:s.ok,headers:s.headers,_requestId:o._requestId};for(let d of B){let u=d(c);u&&(c=u)}if(!s.ok)throw c;return c.data},intercept(t,n){t==="request"?G.push(n):B.push(n)},_reset(){y.baseUrl="",y.auth=!1,y.tokenKey="tina4_token",y.headers={},G.length=0,B.length=0}};function we(t){let n=t.cacheStrategy??"network-first",e=JSON.stringify(t.precache??[]),o=t.offlineRoute?`'${t.offlineRoute}'`:"null";return`
1
+ "use strict";var Tina4=(()=>{var B=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ne=Object.prototype.hasOwnProperty;var Oe=(t,n)=>{for(var e in n)B(t,e,{get:n[e],enumerable:!0})},Ie=(t,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of qe(n))!Ne.call(t,r)&&r!==e&&B(t,r,{get:()=>n[r],enumerable:!(o=Me(n,r))||o.enumerable});return t};var De=t=>Ie(B({},"__esModule",{value:!0}),t);var Ve={};Oe(Ve,{Tina4Element:()=>W,api:()=>we,batch:()=>F,computed:()=>ce,effect:()=>b,html:()=>ue,isSignal:()=>R,navigate:()=>G,pwa:()=>Se,route:()=>me,router:()=>ve,signal:()=>v,sse:()=>Te,ws:()=>Ee});var q=null,I=null,j=null;function S(t){j=t}function U(){return j}var ae=null,ie=null;var K=0,z=new Set;function v(t,n){let e=t,o=new Set,r={_t4:!0,get value(){if(q&&(o.add(q),I)){let s=q;I.push(()=>o.delete(s))}return e},set value(s){if(Object.is(s,e))return;let i=e;if(e=s,r._debugInfo&&r._debugInfo.updateCount++,ie&&ie(r,i,s),K>0)for(let a of o)z.add(a);else{let a;for(let c of[...o])try{c()}catch(l){a===void 0&&(a=l)}if(a!==void 0)throw a}},_subscribe(s){return o.add(s),()=>{o.delete(s)}},peek(){return e}};return ae&&(r._debugInfo={label:n,createdAt:Date.now(),updateCount:0,subs:o},ae(r,n)),r}function ce(t){let n=v(void 0);return b(()=>{n.value=t()}),{_t4:!0,get value(){return n.value},set value(e){throw new Error("[tina4] computed signals are read-only")},_subscribe(e){return n._subscribe(e)},peek(){return n.peek()}}}function b(t){let n=!1,e=[],o=()=>{if(n)return;for(let a of e)a();e=[];let s=q,i=I;q=o,I=e;try{t()}finally{q=s,I=i}};o();let r=()=>{n=!0;for(let s of e)s();e=[]};return j&&j.push(r),r}function F(t){K++;try{t()}finally{if(K--,K===0){let n=[...z];z.clear();let e;for(let o of n)try{o()}catch(r){e===void 0&&(e=r)}if(e!==void 0)throw e}}}function R(t){return t!==null&&typeof t=="object"&&t._t4===!0}var le=new WeakMap,Q="t4:";function ue(t,...n){let e=le.get(t);if(!e){e=document.createElement("template");let i="";for(let a=0;a<t.length;a++)i+=t[a],a<n.length&&(je(i)?i+=`__t4_${a}__`:i+=`<!--${Q}${a}-->`);e.innerHTML=i,le.set(t,e)}let o=e.content.cloneNode(!0),r=He(o);for(let{marker:i,index:a}of r)Pe(i,n[a]);let s=Le(o);for(let i of s)Ke(i,n);return o}function He(t){let n=[];return Y(t,e=>{if(e.nodeType===8){let o=e.data;if(o&&o.startsWith(Q)){let r=parseInt(o.slice(Q.length),10);n.push({marker:e,index:r})}}}),n}function Le(t){let n=[];return Y(t,e=>{e.nodeType===1&&n.push(e)}),n}function Y(t,n){let e=t.childNodes;for(let o=0;o<e.length;o++){let r=e[o];n(r),Y(r,n)}}function Pe(t,n){let e=t.parentNode;if(e)if(R(n)){let o=document.createTextNode("");e.replaceChild(o,t),b(()=>{o.data=String(n.value??"")})}else if(typeof n=="function"){let o=document.createComment("");e.replaceChild(o,t);let r=[],s=[];b(()=>{for(let u of s)u();s=[];let i=[],a=U();S(i);let c=n();S(a),s=i;for(let u of r)u.parentNode?.removeChild(u);r=[];let l=X(c),d=o.parentNode;if(d)for(let u of l)d.insertBefore(u,o),r.push(u)})}else if(de(n))e.replaceChild(n,t);else if(n instanceof Node)e.replaceChild(n,t);else if(Array.isArray(n)){let o=document.createDocumentFragment();for(let r of n){let s=X(r);for(let i of s)o.appendChild(i)}e.replaceChild(o,t)}else{let o=document.createTextNode(String(n??""));e.replaceChild(o,t)}}function Ke(t,n){let e=[];for(let o of Array.from(t.attributes)){let r=o.name,s=o.value;if(r.startsWith("@")){let a=r.slice(1),c=s.match(/__t4_(\d+)__/);if(c){let l=n[parseInt(c[1],10)];typeof l=="function"&&t.addEventListener(a,d=>F(()=>l(d)))}e.push(r);continue}if(r.startsWith("?")){let a=r.slice(1),c=s.match(/__t4_(\d+)__/);if(c){let l=n[parseInt(c[1],10)];if(R(l)){let d=l;b(()=>{d.value?t.setAttribute(a,""):t.removeAttribute(a)})}else typeof l=="function"?b(()=>{l()?t.setAttribute(a,""):t.removeAttribute(a)}):l&&t.setAttribute(a,"")}e.push(r);continue}if(r.startsWith(".")){let a=r.slice(1),c=s.match(/__t4_(\d+)__/);if(c){let l=n[parseInt(c[1],10)];R(l)?b(()=>{t[a]=l.value}):t[a]=l}e.push(r);continue}let i=s.match(/__t4_(\d+)__/);if(i){let a=n[parseInt(i[1],10)];if(R(a)){let c=a;b(()=>{t.setAttribute(r,String(c.value??""))})}else typeof a=="function"?b(()=>{t.setAttribute(r,String(a()??""))}):t.setAttribute(r,String(a??""))}}for(let o of e)t.removeAttribute(o)}function X(t){if(t==null||t===!1)return[];if(de(t))return Array.from(t.childNodes);if(t instanceof Node)return[t];if(Array.isArray(t)){let n=[];for(let e of t)n.push(...X(e));return n}return[document.createTextNode(String(t))]}function de(t){return t!=null&&typeof t=="object"&&t.nodeType===11}function je(t){let n=!1,e=!1,o=!1;for(let r=0;r<t.length;r++){let s=t[r];s==="<"&&!n&&!e&&(o=!0),s===">"&&!n&&!e&&(o=!1),o&&(s==='"'&&!n&&(e=!e),s==="'"&&!e&&(n=!n))}return o}var fe=null,pe=null;var W=class extends HTMLElement{constructor(){super();this._props={};this._rendered=!1;this._disposeRender=null;this._innerDisposers=[];let e=this.constructor;this._root=e.shadow?this.attachShadow({mode:"open"}):this;for(let[o,r]of Object.entries(e.props))this._props[o]=v(this._coerce(this.getAttribute(o),r))}static{this.props={}}static{this.styles=""}static{this.shadow=!0}static get observedAttributes(){return Object.keys(this.props)}connectedCallback(){if(this._rendered)return;this._rendered=!0;let e=this.constructor,o=null;if(e.styles&&e.shadow&&this._root instanceof ShadowRoot){let r=document.createElement("style");r.textContent=e.styles,this._root.appendChild(r),o=r}this._disposeRender=b(()=>{for(let c of this._innerDisposers)c();this._innerDisposers=[];let r=[],s=U();S(r);let i=this.render();S(s),this._innerDisposers=r;let a=Array.from(this._root.childNodes);for(let c of a)c!==o&&this._root.removeChild(c);i&&this._root.appendChild(i)}),this.onMount(),fe&&fe(this)}disconnectedCallback(){this._disposeRender&&(this._disposeRender(),this._disposeRender=null);for(let e of this._innerDisposers)e();this._innerDisposers=[],this.onUnmount(),pe&&pe(this)}attributeChangedCallback(e,o,r){let i=this.constructor.props[e];i&&this._props[e]&&(this._props[e].value=this._coerce(r,i))}prop(e){if(!this._props[e])throw new Error(`[tina4] Prop '${e}' not declared in static props of <${this.tagName.toLowerCase()}>`);return this._props[e]}emit(e,o){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,...o}))}onMount(){}onUnmount(){}_coerce(e,o){return o===Boolean?e!==null:o===Number?e!==null?Number(e):0:e??""}};var Z=[],N=null,D="history",Ue=!1,H=[],$=[],ge=0;function me(t,n){let e=[],o;t==="*"?o=".*":o=t.replace(/\{(\w+)\}/g,(s,i)=>(e.push(i),"([^/]+)"));let r=new RegExp(`^${o}$`);typeof n=="function"?Z.push({pattern:t,regex:r,paramNames:e,handler:n}):Z.push({pattern:t,regex:r,paramNames:e,handler:n.handler,guard:n.guard})}function G(t,n){if(D==="hash")if(n?.replace){let e=new URL(location.href);e.hash="#"+t,history.replaceState(null,"",e.toString()),L()}else location.hash="#"+t;else n?.replace?history.replaceState(null,"",t):history.pushState(null,"",t),L()}function L(){if(!N)return;let t=performance.now(),n=++ge,e=D==="hash"?location.hash.slice(1)||"/":location.pathname;for(let o of Z){let r=e.match(o.regex);if(!r)continue;let s={};if(o.paramNames.forEach((c,l)=>{s[c]=decodeURIComponent(r[l+1])}),o.guard){let c=o.guard();if(c===!1)return;if(typeof c=="string"){G(c,{replace:!0});return}}for(let c of $)c();$=[],N.innerHTML="";let i=[];S(i);let a=o.handler(s);if(a instanceof Promise)a.then(c=>{if(S(null),n!==ge){for(let d of i)d();return}he(N,c),$=i;let l=performance.now()-t;for(let d of H)d({path:e,params:s,pattern:o.pattern,durationMs:l})});else{S(null),he(N,a),$=i;let c=performance.now()-t;for(let l of H)l({path:e,params:s,pattern:o.pattern,durationMs:c})}return}}function he(t,n){n instanceof DocumentFragment||n instanceof Node?t.replaceChildren(n):typeof n=="string"?t.innerHTML=n:n!=null&&t.replaceChildren(document.createTextNode(String(n)))}var ve={start(t){if(N=document.querySelector(t.target),!N)throw new Error(`[tina4] Router target '${t.target}' not found in DOM`);D=t.mode??"history",Ue=!0,window.addEventListener("popstate",L),D==="hash"&&window.addEventListener("hashchange",L),document.addEventListener("click",n=>{if(n.metaKey||n.ctrlKey||n.shiftKey||n.altKey)return;let e=n.target.closest("a[href]");if(!e||e.origin!==location.origin||e.hasAttribute("target")||e.hasAttribute("download")||e.getAttribute("rel")?.includes("external"))return;n.preventDefault();let o=D==="hash"?e.getAttribute("href"):e.pathname;G(o)}),L()},on(t,n){return H.push(n),()=>{let e=H.indexOf(n);e>=0&&H.splice(e,1)}}};var y={baseUrl:"",auth:!1,tokenKey:"tina4_token",headers:{}},J=[],V=[],ye=0;function ee(){try{return localStorage.getItem(y.tokenKey)}catch{return null}}function be(t){try{localStorage.setItem(y.tokenKey,t)}catch{}}async function O(t,n,e,o){let r={method:t,headers:{"Content-Type":"application/json",...y.headers}};if(y.auth){let u=ee();u&&(r.headers.Authorization=`Bearer ${u}`)}if(e!==void 0&&t!=="GET"){let u=typeof e=="object"&&e!==null?{...e}:e;if(y.auth&&typeof u=="object"&&u!==null){let g=ee();g&&(u.formToken=g)}r.body=JSON.stringify(u)}if(o?.headers&&Object.assign(r.headers,o.headers),o?.params){let u=Object.entries(o.params).map(([g,w])=>`${encodeURIComponent(g)}=${encodeURIComponent(String(w))}`).join("&");n+=(n.includes("?")?"&":"?")+u}let s=y.baseUrl+n;r._url=s,r._requestId=++ye;for(let u of J){let g=u(r);g&&(r=g)}let i=await fetch(s,r),a=i.headers.get("FreshToken");a&&be(a);let c=i.headers.get("Content-Type")??"",l;c.includes("json")?l=await i.json():l=await i.text();let d={status:i.status,data:l,ok:i.ok,headers:i.headers,_requestId:r._requestId};for(let u of V){let g=u(d);g&&(d=g)}if(!i.ok)throw d;return d.data}var we={configure(t){Object.assign(y,t)},get(t,n){return O("GET",t,void 0,n)},post(t,n,e){return O("POST",t,n,e)},put(t,n,e){return O("PUT",t,n,e)},patch(t,n,e){return O("PATCH",t,n,e)},delete(t,n){return O("DELETE",t,void 0,n)},async graphql(t,n,e,o){return O("POST",t,{query:n,variables:e||{}},o)},async upload(t,n,e){let o={method:"POST",headers:{...y.headers},body:n};if(delete o.headers["Content-Type"],delete o.headers["content-type"],y.auth){let d=ee();d&&(o.headers.Authorization=`Bearer ${d}`)}if(e?.headers&&Object.assign(o.headers,e.headers),e?.params){let d=Object.entries(e.params).map(([u,g])=>`${encodeURIComponent(u)}=${encodeURIComponent(String(g))}`).join("&");t+=(t.includes("?")?"&":"?")+d}let r=y.baseUrl+t;o._url=r,o._requestId=++ye;for(let d of J){let u=d(o);u&&(o=u)}let s=await fetch(r,o),i=s.headers.get("FreshToken");i&&be(i);let a=s.headers.get("Content-Type")??"",c;a.includes("json")?c=await s.json():c=await s.text();let l={status:s.status,data:c,ok:s.ok,headers:s.headers,_requestId:o._requestId};for(let d of V){let u=d(l);u&&(l=u)}if(!s.ok)throw l;return l.data},intercept(t,n){t==="request"?J.push(n):V.push(n)},_reset(){y.baseUrl="",y.auth=!1,y.tokenKey="tina4_token",y.headers={},J.length=0,V.length=0}};function Fe(t){let n=t.cacheStrategy??"network-first",e=JSON.stringify(t.precache??[]),o=t.offlineRoute?`'${t.offlineRoute}'`:"null";return`
2
2
  const CACHE = 'tina4-v1';
3
3
  const PRECACHE = ${e};
4
4
  const OFFLINE = ${o};
@@ -44,5 +44,5 @@ self.addEventListener('fetch', (e) => {
44
44
  ))
45
45
  );`}
46
46
  });
47
- `.trim()}function Se(t){let n={name:t.name,short_name:t.shortName??t.name,start_url:"/",display:t.display??"standalone",background_color:t.backgroundColor??"#ffffff",theme_color:t.themeColor??"#000000"};return t.icon&&(n.icons=[{src:t.icon,sizes:"192x192",type:"image/png"},{src:t.icon,sizes:"512x512",type:"image/png"}]),n}var Te={register(t){let n=Se(t),e=new Blob([JSON.stringify(n)],{type:"application/json"}),o=document.createElement("link");o.rel="manifest",o.href=URL.createObjectURL(e),document.head.appendChild(o);let r=document.querySelector('meta[name="theme-color"]');if(r||(r=document.createElement("meta"),r.name="theme-color",document.head.appendChild(r)),r.content=t.themeColor??"#000000","serviceWorker"in navigator){let s=we(t),i=new Blob([s],{type:"text/javascript"}),a=URL.createObjectURL(i);navigator.serviceWorker.register(a).catch(l=>{console.warn("[tina4] Service worker registration failed:",l)})}},generateServiceWorker(t){return we(t)},generateManifest(t){return Se(t)}};var We={reconnect:!0,reconnectDelay:1e3,reconnectMaxDelay:3e4,reconnectAttempts:1/0,protocols:[]};function $e(t,n={}){let e={...We,...n},o=v("connecting"),r=v(!1),s=v(null),i=v(null),a=v(0),l={message:[],open:[],close:[],error:[]},c=null,d=!1,u=e.reconnectDelay,g=null,b=0;function E(p){if(typeof p!="string")return p;try{return JSON.parse(p)}catch{return p}}function S(){o.value=b>0?"reconnecting":"connecting";try{c=new WebSocket(t,e.protocols)}catch{o.value="closed",r.value=!1;return}c.onopen=()=>{o.value="open",r.value=!0,i.value=null,b=0,u=e.reconnectDelay,a.value=0;for(let p of l.open)p()},c.onmessage=p=>{let m=E(p.data);s.value=m;for(let w of l.message)w(m)},c.onclose=p=>{o.value="closed",r.value=!1;for(let m of l.close)m(p.code,p.reason);!d&&e.reconnect&&b<e.reconnectAttempts&&A()},c.onerror=p=>{i.value=p;for(let m of l.error)m(p)}}function A(){b++,a.value=b,o.value="reconnecting",g=setTimeout(()=>{g=null,S()},u),u=Math.min(u*2,e.reconnectMaxDelay)}let C={status:o,connected:r,lastMessage:s,error:i,reconnectCount:a,send(p){if(!c||c.readyState!==WebSocket.OPEN)throw new Error("[tina4] WebSocket is not connected");let m=typeof p=="string"?p:JSON.stringify(p);c.send(m)},on(p,m){return l[p].push(m),()=>{let w=l[p],M=w.indexOf(m);M>=0&&w.splice(M,1)}},pipe(p,m){let w=M=>{p.value=m(M,p.value)};return C.on("message",w)},close(p,m){d=!0,g&&(clearTimeout(g),g=null),c&&c.close(p??1e3,m??""),o.value="closed",r.value=!1}};return S(),C}var Ee={connect:$e};var Ge={mode:"eventsource",method:"GET",headers:{},body:void 0,reconnect:!0,reconnectDelay:1e3,reconnectMaxDelay:3e4,reconnectAttempts:1/0,events:[],json:!0};function Be(t,n={}){let e={...Ge,...n},o=v("connecting"),r=v(!1),s=v(null),i=v(null),a=v(null),l=v(0),c={message:[],open:[],close:[],error:[]},d=null,u=null,g=!1,b=e.reconnectDelay,E=null,S=0;function A(f){if(!e.json||typeof f!="string")return f;try{return JSON.parse(f)}catch{return f}}function C(f,h){s.value=f,i.value=h;for(let T of c.message)T(f,h??void 0)}function p(){o.value="open",r.value=!0,a.value=null,S=0,b=e.reconnectDelay,l.value=0;for(let f of c.open)f()}function m(){o.value="closed",r.value=!1;for(let f of c.close)f();!g&&e.reconnect&&S<e.reconnectAttempts&&xe()}function w(f){a.value=f;for(let h of c.error)h(f)}function M(){o.value=S>0?"reconnecting":"connecting";try{d=new EventSource(t)}catch{o.value="closed",r.value=!1;return}d.onopen=()=>p(),d.onmessage=f=>{C(A(f.data),null)};for(let f of e.events)d.addEventListener(f,h=>{C(A(h.data),f)});d.onerror=f=>{w(f),d&&d.readyState===2&&(d=null,m())}}function _e(){o.value=S>0?"reconnecting":"connecting",u=new AbortController;let f={method:e.method,headers:e.headers,signal:u.signal};e.body!==void 0&&(f.body=typeof e.body=="string"?e.body:JSON.stringify(e.body)),fetch(t,f).then(async h=>{if(!h.ok){w(new Error(`[tina4] SSE fetch ${h.status}`)),m();return}p();let T=h.body.getReader(),q=new TextDecoder,K="";for(;;){let{done:Re,value:Ae}=await T.read();if(Re)break;K+=q.decode(Ae,{stream:!0});let oe=K.split(`
48
- `);K=oe.pop();for(let Me of oe){let re=Me.trim();re&&C(A(re),null)}}let ne=K.trim();ne&&C(A(ne),null),u=null,m()}).catch(h=>{h.name!=="AbortError"&&(u=null,w(h),m())})}function xe(){S++,l.value=S,o.value="reconnecting",E=setTimeout(()=>{E=null,ee()},b),b=Math.min(b*2,e.reconnectMaxDelay)}function ee(){e.mode==="fetch"?_e():M()}let te={status:o,connected:r,lastMessage:s,lastEvent:i,error:a,reconnectCount:l,on(f,h){return c[f].push(h),()=>{let T=c[f],q=T.indexOf(h);q>=0&&T.splice(q,1)}},pipe(f,h){let T=q=>{f.value=h(q,f.value)};return te.on("message",T)},close(){g=!0,E&&(clearTimeout(E),E=null),d&&(d.close(),d=null),u&&(u.abort(),u=null),o.value="closed",r.value=!1}};return ee(),te}var Ce={connect:Be};return De(Je);})();
47
+ `.trim()}function ke(t){let n={name:t.name,short_name:t.shortName??t.name,start_url:"/",display:t.display??"standalone",background_color:t.backgroundColor??"#ffffff",theme_color:t.themeColor??"#000000"};return t.icon&&(n.icons=[{src:t.icon,sizes:"192x192",type:"image/png"},{src:t.icon,sizes:"512x512",type:"image/png"}]),n}var Se={register(t){let n=ke(t),e=new Blob([JSON.stringify(n)],{type:"application/json"}),o=document.createElement("link");o.rel="manifest",o.href=URL.createObjectURL(e),document.head.appendChild(o);let r=document.querySelector('meta[name="theme-color"]');r||(r=document.createElement("meta"),r.name="theme-color",document.head.appendChild(r)),r.content=t.themeColor??"#000000","serviceWorker"in navigator&&(t.swUrl?navigator.serviceWorker.register(t.swUrl).catch(s=>{console.warn("[tina4] Service worker registration failed:",s)}):navigator.serviceWorker.register("/sw.js").catch(()=>{console.info("[tina4] No service worker at /sw.js. Use pwa.generateServiceWorker() to create one, or pass swUrl in config.")}))},generateServiceWorker(t){return Fe(t)},generateManifest(t){return ke(t)}};var We={reconnect:!0,reconnectDelay:1e3,reconnectMaxDelay:3e4,reconnectAttempts:1/0,protocols:[]};function $e(t,n={}){let e={...We,...n},o=v("connecting"),r=v(!1),s=v(null),i=v(null),a=v(0),c={message:[],open:[],close:[],error:[]},l=null,d=!1,u=e.reconnectDelay,g=null,w=0;function C(p){if(typeof p!="string")return p;try{return JSON.parse(p)}catch{return p}}function E(){o.value=w>0?"reconnecting":"connecting";try{l=new WebSocket(t,e.protocols)}catch{o.value="closed",r.value=!1;return}l.onopen=()=>{o.value="open",r.value=!0,i.value=null,w=0,u=e.reconnectDelay,a.value=0;for(let p of c.open)p()},l.onmessage=p=>{let h=C(p.data);s.value=h;for(let k of c.message)k(h)},l.onclose=p=>{o.value="closed",r.value=!1;for(let h of c.close)h(p.code,p.reason);!d&&e.reconnect&&w<e.reconnectAttempts&&x()},l.onerror=p=>{i.value=p;for(let h of c.error)h(p)}}function x(){w++,a.value=w,o.value="reconnecting",g=setTimeout(()=>{g=null,E()},u),u=Math.min(u*2,e.reconnectMaxDelay)}let _={status:o,connected:r,lastMessage:s,error:i,reconnectCount:a,send(p){if(!l||l.readyState!==WebSocket.OPEN)throw new Error("[tina4] WebSocket is not connected");let h=typeof p=="string"?p:JSON.stringify(p);l.send(h)},on(p,h){return c[p].push(h),()=>{let k=c[p],A=k.indexOf(h);A>=0&&k.splice(A,1)}},pipe(p,h){let k=A=>{p.value=h(A,p.value)};return _.on("message",k)},close(p,h){d=!0,g&&(clearTimeout(g),g=null),l&&l.close(p??1e3,h??""),o.value="closed",r.value=!1}};return E(),_}var Ee={connect:$e};var Ge={mode:"eventsource",method:"GET",headers:{},body:void 0,reconnect:!0,reconnectDelay:1e3,reconnectMaxDelay:3e4,reconnectAttempts:1/0,events:[],json:!0};function Je(t,n={}){let e={...Ge,...n},o=v("connecting"),r=v(!1),s=v(null),i=v(null),a=v(null),c=v(0),l={message:[],open:[],close:[],error:[]},d=null,u=null,g=!1,w=e.reconnectDelay,C=null,E=0;function x(f){if(!e.json||typeof f!="string")return f;try{return JSON.parse(f)}catch{return f}}function _(f,m){s.value=f,i.value=m;for(let T of l.message)T(f,m??void 0)}function p(){o.value="open",r.value=!0,a.value=null,E=0,w=e.reconnectDelay,c.value=0;for(let f of l.open)f()}function h(){o.value="closed",r.value=!1;for(let f of l.close)f();!g&&e.reconnect&&E<e.reconnectAttempts&&_e()}function k(f){a.value=f;for(let m of l.error)m(f)}function A(){o.value=E>0?"reconnecting":"connecting";try{d=new EventSource(t)}catch{o.value="closed",r.value=!1;return}d.onopen=()=>p(),d.onmessage=f=>{_(x(f.data),null)};for(let f of e.events)d.addEventListener(f,m=>{_(x(m.data),f)});d.onerror=f=>{k(f),d&&d.readyState===2&&(d=null,h())}}function Ce(){o.value=E>0?"reconnecting":"connecting",u=new AbortController;let f={method:e.method,headers:e.headers,signal:u.signal};e.body!==void 0&&(f.body=typeof e.body=="string"?e.body:JSON.stringify(e.body)),fetch(t,f).then(async m=>{if(!m.ok){k(new Error(`[tina4] SSE fetch ${m.status}`)),h();return}p();let T=m.body.getReader(),M=new TextDecoder,P="";for(;;){let{done:Re,value:xe}=await T.read();if(Re)break;P+=M.decode(xe,{stream:!0});let re=P.split(`
48
+ `);P=re.pop();for(let Ae of re){let se=Ae.trim();se&&_(x(se),null)}}let oe=P.trim();oe&&_(x(oe),null),u=null,h()}).catch(m=>{m.name!=="AbortError"&&(u=null,k(m),h())})}function _e(){E++,c.value=E,o.value="reconnecting",C=setTimeout(()=>{C=null,te()},w),w=Math.min(w*2,e.reconnectMaxDelay)}function te(){e.mode==="fetch"?Ce():A()}let ne={status:o,connected:r,lastMessage:s,lastEvent:i,error:a,reconnectCount:c,on(f,m){return l[f].push(m),()=>{let T=l[f],M=T.indexOf(m);M>=0&&T.splice(M,1)}},pipe(f,m){let T=M=>{f.value=m(M,f.value)};return ne.on("message",T)},close(){g=!0,C&&(clearTimeout(C),C=null),d&&(d.close(),d=null),u&&(u.abort(),u=null),o.value="closed",r.value=!1}};return te(),ne}var Te={connect:Je};return De(Ve);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tina4js",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "1.5KB core gzipped, reactive framework — signals, web components, routing, PWA",
5
5
  "type": "module",
6
6
  "main": "dist/tina4.cjs.js",