tina4js 1.1.1 → 1.2.2

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
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/api/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,CAAC,CAAC;IACR,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,WAAW,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,KAAK,CAAC,WAAW,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAC,GAAG,IAAI,CAAC;AAC3J,MAAM,MAAM,mBAAmB,GAAG,CAAC,QAAQ,EAAE,WAAW,KAAK,WAAW,GAAG,IAAI,CAAC;AA+BhF,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CACpD;AA+FD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,GAAG;IACd;;;;;;;;;;OAUG;iBACU,OAAO,CAAC,S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,CAAC,kBAAkB,MAAM,SAAS,OAAO,YAAY,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAItF,mBAAmB;WACZ,CAAC,kBAAkB,MAAM,YAAY,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAIvE;;;;;;;;;;;;;;;;;;;;;OAqBG;YACW,CAAC,kBAAkB,MAAM,SAAS,MAAM,cAAc,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,cAAc,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;QAAC,MAAM,CAAC,EAAE,KAAK,CAAC;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC;IAIxL;;;;;;;;;;;;;;;;OAgBG;WACU,CAAC,kBAAkB,MAAM,YAAY,QAAQ,YAAY,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAiFjG;;;;;;;;;;;;;OAaG;oBACa,SAAS,GAAG,UAAU,MAAM,kBAAkB,GAAG,mBAAmB,GAAG,IAAI;IAQ3F,yCAAyC;cAC/B,IAAI;CAQf,CAAC"}
package/dist/api.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a={baseUrl:"",auth:!1,tokenKey:"tina4_token",headers:{}},k=[],T=[];let j=0;function y(){try{return localStorage.getItem(a.tokenKey)}catch{return null}}function q(e){try{localStorage.setItem(a.tokenKey,e)}catch{}}async function i(e,s,t,r){let c={method:e,headers:{"Content-Type":"application/json",...a.headers}};if(a.auth){const n=y();n&&(c.headers.Authorization=`Bearer ${n}`)}if(t!==void 0&&e!=="GET"){let n=typeof t=="object"&&t!==null?{...t}:t;if(a.auth&&typeof n=="object"&&n!==null){const u=y();u&&(n.formToken=u)}c.body=JSON.stringify(n)}if(r!=null&&r.headers&&Object.assign(c.headers,r.headers),r!=null&&r.params){const n=Object.entries(r.params).map(([u,I])=>`${encodeURIComponent(u)}=${encodeURIComponent(String(I))}`).join("&");s+=(s.includes("?")?"&":"?")+n}const d=a.baseUrl+s;c._url=d,c._requestId=++j;for(const n of k){const u=n(c);u&&(c=u)}const l=await fetch(d,c),g=l.headers.get("FreshToken");g&&q(g);const h=l.headers.get("Content-Type")??"";let f;h.includes("json")?f=await l.json():f=await l.text();let o={status:l.status,data:f,ok:l.ok,headers:l.headers,_requestId:c._requestId};for(const n of T){const u=n(o);u&&(o=u)}if(!l.ok)throw o;return o.data}const m={configure(e){Object.assign(a,e)},get(e,s){return i("GET",e,void 0,s)},post(e,s,t){return i("POST",e,s,t)},put(e,s,t){return i("PUT",e,s,t)},patch(e,s,t){return i("PATCH",e,s,t)},delete(e,s){return i("DELETE",e,void 0,s)},async graphql(e,s,t,r){return i("POST",e,{query:s,variables:t||{}},r)},async upload(e,s,t){let r={method:"POST",headers:{...a.headers},body:s};if(delete r.headers["Content-Type"],delete r.headers["content-type"],a.auth){const o=y();o&&(r.headers.Authorization=`Bearer ${o}`)}if(t!=null&&t.headers&&Object.assign(r.headers,t.headers),t!=null&&t.params){const o=Object.entries(t.params).map(([n,u])=>`${encodeURIComponent(n)}=${encodeURIComponent(String(u))}`).join("&");e+=(e.includes("?")?"&":"?")+o}const c=a.baseUrl+e;r._url=c,r._requestId=++j;for(const o of k){const n=o(r);n&&(r=n)}const d=await fetch(c,r),l=d.headers.get("FreshToken");l&&q(l);const g=d.headers.get("Content-Type")??"";let h;g.includes("json")?h=await d.json():h=await d.text();let f={status:d.status,data:h,ok:d.ok,headers:d.headers,_requestId:r._requestId};for(const o of T){const n=o(f);n&&(f=n)}if(!d.ok)throw f;return f.data},intercept(e,s){e==="request"?k.push(s):T.push(s)},_reset(){a.baseUrl="",a.auth=!1,a.tokenKey="tina4_token",a.headers={},k.length=0,T.length=0}};exports.api=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a={baseUrl:"",auth:!1,tokenKey:"tina4_token",headers:{}},k=[],T=[];let j=0;function y(){try{return localStorage.getItem(a.tokenKey)}catch{return null}}function m(e){try{localStorage.setItem(a.tokenKey,e)}catch{}}async function i(e,s,t,r){let c={method:e,credentials:"same-origin",headers:{"Content-Type":"application/json",...a.headers}};if(a.auth){const n=y();n&&(c.headers.Authorization=`Bearer ${n}`)}if(t!==void 0&&e!=="GET"){let n=typeof t=="object"&&t!==null?{...t}:t;if(a.auth&&typeof n=="object"&&n!==null){const u=y();u&&(n.formToken=u)}c.body=JSON.stringify(n)}if(r!=null&&r.headers&&Object.assign(c.headers,r.headers),r!=null&&r.params){const n=Object.entries(r.params).map(([u,q])=>`${encodeURIComponent(u)}=${encodeURIComponent(String(q))}`).join("&");s+=(s.includes("?")?"&":"?")+n}const d=a.baseUrl+s;c._url=d,c._requestId=++j;for(const n of k){const u=n(c);u&&(c=u)}const l=await fetch(d,c),g=l.headers.get("FreshToken");g&&m(g);const h=l.headers.get("Content-Type")??"";let f;h.includes("json")?f=await l.json():f=await l.text();let o={status:l.status,data:f,ok:l.ok,headers:l.headers,_requestId:c._requestId};for(const n of T){const u=n(o);u&&(o=u)}if(!l.ok)throw o;return o.data}const I={configure(e){Object.assign(a,e)},get(e,s){return i("GET",e,void 0,s)},post(e,s,t){return i("POST",e,s,t)},put(e,s,t){return i("PUT",e,s,t)},patch(e,s,t){return i("PATCH",e,s,t)},delete(e,s){return i("DELETE",e,void 0,s)},async graphql(e,s,t,r){return i("POST",e,{query:s,variables:t||{}},r)},async upload(e,s,t){let r={method:"POST",headers:{...a.headers},body:s};if(delete r.headers["Content-Type"],delete r.headers["content-type"],a.auth){const o=y();o&&(r.headers.Authorization=`Bearer ${o}`)}if(t!=null&&t.headers&&Object.assign(r.headers,t.headers),t!=null&&t.params){const o=Object.entries(t.params).map(([n,u])=>`${encodeURIComponent(n)}=${encodeURIComponent(String(u))}`).join("&");e+=(e.includes("?")?"&":"?")+o}const c=a.baseUrl+e;r._url=c,r._requestId=++j;for(const o of k){const n=o(r);n&&(r=n)}const d=await fetch(c,r),l=d.headers.get("FreshToken");l&&m(l);const g=d.headers.get("Content-Type")??"";let h;g.includes("json")?h=await d.json():h=await d.text();let f={status:d.status,data:h,ok:d.ok,headers:d.headers,_requestId:r._requestId};for(const o of T){const n=o(f);n&&(f=n)}if(!d.ok)throw f;return f.data},intercept(e,s){e==="request"?k.push(s):T.push(s)},_reset(){a.baseUrl="",a.auth=!1,a.tokenKey="tina4_token",a.headers={},k.length=0,T.length=0}};exports.api=I;
package/dist/api.es.js CHANGED
@@ -21,6 +21,7 @@ function I(e) {
21
21
  async function i(e, s, t, r) {
22
22
  let c = {
23
23
  method: e,
24
+ credentials: "same-origin",
24
25
  headers: {
25
26
  "Content-Type": "application/json",
26
27
  ...a.headers
@@ -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,IAA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AgDzB,oBAAoB,IAAI,IAAI;IAa5B,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAQvF;;;;;;;;OAQG;IACH,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;IAO1C;;;;;;OAMG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,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.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./signal.cjs.js"),b=require("./component.cjs.js"),_=new WeakMap,m="t4:";function N(t,...e){let n=_.get(t);if(!n){n=document.createElement("template");let f="";for(let c=0;c<t.length;c++)f+=t[c],c<e.length&&(E(f)?f+=`__t4_${c}__`:f+=`<!--${m}${c}-->`);n.innerHTML=f,_.set(t,n)}const o=n.content.cloneNode(!0),i=y(o);for(const{marker:f,index:c}of i)S(f,e[c]);const r=C(o);for(const f of r)T(f,e);return o}function y(t){const e=[];return p(t,n=>{if(n.nodeType===8){const o=n.data;if(o&&o.startsWith(m)){const i=parseInt(o.slice(m.length),10);e.push({marker:n,index:i})}}}),e}function C(t){const e=[];return p(t,n=>{n.nodeType===1&&e.push(n)}),e}function p(t,e){const n=t.childNodes;for(let o=0;o<n.length;o++){const i=n[o];e(i),p(i,e)}}function S(t,e){const n=t.parentNode;if(n)if(s.isSignal(e)){const o=document.createTextNode("");n.replaceChild(o,t),s.effect(()=>{o.data=String(e.value??"")})}else if(typeof e=="function"){const o=document.createComment("");n.replaceChild(o,t);let i=[],r=[];s.effect(()=>{var g;for(const d of r)d();r=[];const f=[],c=s._getEffectCollector();s._setEffectCollector(f);const a=e();s._setEffectCollector(c),r=f;for(const d of i)(g=d.parentNode)==null||g.removeChild(d);i=[];const l=h(a),u=o.parentNode;if(u)for(const d of l)u.insertBefore(d,o),i.push(d)})}else if(A(e))n.replaceChild(e,t);else if(e instanceof Node)n.replaceChild(e,t);else if(Array.isArray(e)){const o=document.createDocumentFragment();for(const i of e){const r=h(i);for(const f of r)o.appendChild(f)}n.replaceChild(o,t)}else{const o=document.createTextNode(String(e??""));n.replaceChild(o,t)}}function T(t,e){const n=[];for(const o of Array.from(t.attributes)){const i=o.name,r=o.value;if(i.startsWith("@")){const c=i.slice(1),a=r.match(/__t4_(\d+)__/);if(a){const l=e[parseInt(a[1],10)];typeof l=="function"&&t.addEventListener(c,u=>s.batch(()=>l(u)))}n.push(i);continue}if(i.startsWith("?")){const c=i.slice(1),a=r.match(/__t4_(\d+)__/);if(a){const l=e[parseInt(a[1],10)];if(s.isSignal(l)){const u=l;s.effect(()=>{u.value?t.setAttribute(c,""):t.removeAttribute(c)})}else typeof l=="function"?s.effect(()=>{l()?t.setAttribute(c,""):t.removeAttribute(c)}):l&&t.setAttribute(c,"")}n.push(i);continue}if(i.startsWith(".")){const c=i.slice(1),a=r.match(/__t4_(\d+)__/);if(a){const l=e[parseInt(a[1],10)];s.isSignal(l)?s.effect(()=>{t[c]=l.value}):t[c]=l}n.push(i);continue}const f=r.match(/__t4_(\d+)__/);if(f){const c=e[parseInt(f[1],10)];if(s.isSignal(c)){const a=c;s.effect(()=>{t.setAttribute(i,String(a.value??""))})}else typeof c=="function"?s.effect(()=>{t.setAttribute(i,String(c()??""))}):t.setAttribute(i,String(c??""))}}for(const o of n)t.removeAttribute(o)}function h(t){if(t==null||t===!1)return[];if(A(t))return Array.from(t.childNodes);if(t instanceof Node)return[t];if(Array.isArray(t)){const e=[];for(const n of t)e.push(...h(n));return e}return[document.createTextNode(String(t))]}function A(t){return t!=null&&typeof t=="object"&&t.nodeType===11}function E(t){let e=!1,n=!1,o=!1;for(let i=0;i<t.length;i++){const r=t[i];r==="<"&&!e&&!n&&(o=!0),r===">"&&!e&&!n&&(o=!1),o&&(r==='"'&&!e&&(n=!n),r==="'"&&!n&&(e=!e))}return o}exports.batch=s.batch;exports.computed=s.computed;exports.effect=s.effect;exports.isSignal=s.isSignal;exports.signal=s.signal;exports.Tina4Element=b.Tina4Element;exports.html=N;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./signal.cjs.js"),b=require("./component.cjs.js"),_=new WeakMap,m="t4:";function y(t,...e){let n=_.get(t);if(!n){n=document.createElement("template");let f="";for(let c=0;c<t.length;c++)f+=t[c],c<e.length&&(E(f)?f+=`__t4_${c}__`:f+=`<!--${m}${c}-->`);n.innerHTML=f,_.set(t,n)}const o=n.content.cloneNode(!0),i=N(o);for(const{marker:f,index:c}of i)S(f,e[c]);const r=C(o);for(const f of r)T(f,e);return o}function N(t){const e=[];return p(t,n=>{if(n.nodeType===8){const o=n.data;if(o&&o.startsWith(m)){const i=parseInt(o.slice(m.length),10);e.push({marker:n,index:i})}}}),e}function C(t){const e=[];return p(t,n=>{n.nodeType===1&&e.push(n)}),e}function p(t,e){const n=t.childNodes;for(let o=0;o<n.length;o++){const i=n[o];e(i),p(i,e)}}function S(t,e){const n=t.parentNode;if(n)if(s.isSignal(e)){const o=document.createTextNode("");n.replaceChild(o,t),s.effect(()=>{o.data=String(e.value??"")})}else if(typeof e=="function"){const o=document.createComment("");n.replaceChild(o,t);let i=[],r=[];s.effect(()=>{var g;for(const d of r)d();r=[];const f=[],c=s._getEffectCollector();s._setEffectCollector(f);const a=e();s._setEffectCollector(c),r=f;for(const d of i)(g=d.parentNode)==null||g.removeChild(d);i=[];const l=h(a),u=o.parentNode;if(u)for(const d of l)u.insertBefore(d,o),i.push(d)})}else if(A(e))n.replaceChild(e,t);else if(e instanceof Node)n.replaceChild(e,t);else if(Array.isArray(e)){const o=document.createDocumentFragment();for(const i of e){const r=h(i);for(const f of r)o.appendChild(f)}n.replaceChild(o,t)}else{const o=document.createTextNode(String(e??""));n.replaceChild(o,t)}}function T(t,e){const n=[];for(const o of Array.from(t.attributes)){const i=o.name,r=o.value;if(i.startsWith("@")){const c=i.slice(1),a=r.match(/__t4_(\d+)__/);if(a){const l=e[parseInt(a[1],10)];typeof l=="function"&&t.addEventListener(c,u=>s.batch(()=>l(u)))}n.push(i);continue}if(i.startsWith("?")){const c=i.slice(1),a=r.match(/__t4_(\d+)__/);if(a){const l=e[parseInt(a[1],10)];if(s.isSignal(l)){const u=l;s.effect(()=>{u.value?t.setAttribute(c,""):t.removeAttribute(c)})}else typeof l=="function"?s.effect(()=>{l()?t.setAttribute(c,""):t.removeAttribute(c)}):l&&t.setAttribute(c,"")}n.push(i);continue}if(i.startsWith(".")){const c=i.slice(1),a=r.match(/__t4_(\d+)__/);if(a){const l=e[parseInt(a[1],10)];s.isSignal(l)?s.effect(()=>{t[c]=l.value}):typeof l=="function"?s.effect(()=>{t[c]=l()??""}):t[c]=l}n.push(i);continue}const f=r.match(/__t4_(\d+)__/);if(f){const c=e[parseInt(f[1],10)];if(s.isSignal(c)){const a=c;s.effect(()=>{t.setAttribute(i,String(a.value??""))})}else typeof c=="function"?s.effect(()=>{t.setAttribute(i,String(c()??""))}):t.setAttribute(i,String(c??""))}}for(const o of n)t.removeAttribute(o)}function h(t){if(t==null||t===!1)return[];if(A(t))return Array.from(t.childNodes);if(t instanceof Node)return[t];if(Array.isArray(t)){const e=[];for(const n of t)e.push(...h(n));return e}return[document.createTextNode(String(t))]}function A(t){return t!=null&&typeof t=="object"&&t.nodeType===11}function E(t){let e=!1,n=!1,o=!1;for(let i=0;i<t.length;i++){const r=t[i];r==="<"&&!e&&!n&&(o=!0),r===">"&&!e&&!n&&(o=!1),o&&(r==='"'&&!e&&(n=!n),r==="'"&&!n&&(e=!e))}return o}exports.batch=s.batch;exports.computed=s.computed;exports.effect=s.effect;exports.isSignal=s.isSignal;exports.signal=s.signal;exports.Tina4Element=b.Tina4Element;exports.html=y;
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 l, _ as y, a as A, b as C } 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:";
@@ -7,15 +7,15 @@ function D(t, ...e) {
7
7
  if (!n) {
8
8
  n = document.createElement("template");
9
9
  let c = "";
10
- for (let r = 0; r < t.length; r++)
11
- c += t[r], r < e.length && (I(c) ? c += `__t4_${r}__` : c += `<!--${p}${r}-->`);
10
+ for (let i = 0; i < t.length; i++)
11
+ c += t[i], i < e.length && (I(c) ? c += `__t4_${i}__` : c += `<!--${p}${i}-->`);
12
12
  n.innerHTML = c, N.set(t, n);
13
13
  }
14
14
  const o = n.content.cloneNode(!0), s = T(o);
15
- for (const { marker: c, index: r } of s)
16
- E(c, e[r]);
17
- const i = x(o);
18
- for (const c of i)
15
+ for (const { marker: c, index: i } of s)
16
+ E(c, e[i]);
17
+ const r = x(o);
18
+ for (const c of r)
19
19
  S(c, e);
20
20
  return o;
21
21
  }
@@ -49,27 +49,27 @@ function E(t, e) {
49
49
  if (n)
50
50
  if (u(e)) {
51
51
  const o = document.createTextNode("");
52
- n.replaceChild(o, t), d(() => {
52
+ n.replaceChild(o, t), l(() => {
53
53
  o.data = String(e.value ?? "");
54
54
  });
55
55
  } else if (typeof e == "function") {
56
56
  const o = document.createComment("");
57
57
  n.replaceChild(o, t);
58
- let s = [], i = [];
59
- d(() => {
58
+ let s = [], r = [];
59
+ l(() => {
60
60
  var g;
61
- for (const l of i) l();
62
- i = [];
63
- const c = [], r = C();
61
+ for (const d of r) d();
62
+ r = [];
63
+ const c = [], i = y();
64
64
  A(c);
65
65
  const a = e();
66
- A(r), i = c;
67
- for (const l of s) (g = l.parentNode) == null || g.removeChild(l);
66
+ A(i), r = c;
67
+ for (const d of s) (g = d.parentNode) == null || g.removeChild(d);
68
68
  s = [];
69
69
  const f = h(a), m = o.parentNode;
70
70
  if (m)
71
- for (const l of f)
72
- m.insertBefore(l, o), s.push(l);
71
+ for (const d of f)
72
+ m.insertBefore(d, o), s.push(d);
73
73
  });
74
74
  } else if (b(e))
75
75
  n.replaceChild(e, t);
@@ -78,8 +78,8 @@ function E(t, e) {
78
78
  else if (Array.isArray(e)) {
79
79
  const o = document.createDocumentFragment();
80
80
  for (const s of e) {
81
- const i = h(s);
82
- for (const c of i) o.appendChild(c);
81
+ const r = h(s);
82
+ for (const c of r) o.appendChild(c);
83
83
  }
84
84
  n.replaceChild(o, t);
85
85
  } else {
@@ -90,54 +90,56 @@ function E(t, e) {
90
90
  function S(t, e) {
91
91
  const n = [];
92
92
  for (const o of Array.from(t.attributes)) {
93
- const s = o.name, i = o.value;
93
+ const s = o.name, r = o.value;
94
94
  if (s.startsWith("@")) {
95
- const r = s.slice(1), a = i.match(/__t4_(\d+)__/);
95
+ const i = s.slice(1), a = r.match(/__t4_(\d+)__/);
96
96
  if (a) {
97
97
  const f = e[parseInt(a[1], 10)];
98
- typeof f == "function" && t.addEventListener(r, (m) => y(() => f(m)));
98
+ typeof f == "function" && t.addEventListener(i, (m) => C(() => f(m)));
99
99
  }
100
100
  n.push(s);
101
101
  continue;
102
102
  }
103
103
  if (s.startsWith("?")) {
104
- const r = s.slice(1), a = i.match(/__t4_(\d+)__/);
104
+ const i = s.slice(1), a = r.match(/__t4_(\d+)__/);
105
105
  if (a) {
106
106
  const f = e[parseInt(a[1], 10)];
107
107
  if (u(f)) {
108
108
  const m = f;
109
- d(() => {
110
- m.value ? t.setAttribute(r, "") : t.removeAttribute(r);
109
+ l(() => {
110
+ m.value ? t.setAttribute(i, "") : t.removeAttribute(i);
111
111
  });
112
- } else typeof f == "function" ? d(() => {
113
- f() ? t.setAttribute(r, "") : t.removeAttribute(r);
114
- }) : f && t.setAttribute(r, "");
112
+ } else typeof f == "function" ? l(() => {
113
+ f() ? t.setAttribute(i, "") : t.removeAttribute(i);
114
+ }) : f && t.setAttribute(i, "");
115
115
  }
116
116
  n.push(s);
117
117
  continue;
118
118
  }
119
119
  if (s.startsWith(".")) {
120
- const r = s.slice(1), a = i.match(/__t4_(\d+)__/);
120
+ const i = s.slice(1), a = r.match(/__t4_(\d+)__/);
121
121
  if (a) {
122
122
  const f = e[parseInt(a[1], 10)];
123
- u(f) ? d(() => {
124
- t[r] = f.value;
125
- }) : t[r] = f;
123
+ u(f) ? l(() => {
124
+ t[i] = f.value;
125
+ }) : typeof f == "function" ? l(() => {
126
+ t[i] = f() ?? "";
127
+ }) : t[i] = f;
126
128
  }
127
129
  n.push(s);
128
130
  continue;
129
131
  }
130
- const c = i.match(/__t4_(\d+)__/);
132
+ const c = r.match(/__t4_(\d+)__/);
131
133
  if (c) {
132
- const r = e[parseInt(c[1], 10)];
133
- if (u(r)) {
134
- const a = r;
135
- d(() => {
134
+ const i = e[parseInt(c[1], 10)];
135
+ if (u(i)) {
136
+ const a = i;
137
+ l(() => {
136
138
  t.setAttribute(s, String(a.value ?? ""));
137
139
  });
138
- } else typeof r == "function" ? d(() => {
139
- t.setAttribute(s, String(r() ?? ""));
140
- }) : t.setAttribute(s, String(r ?? ""));
140
+ } else typeof i == "function" ? l(() => {
141
+ t.setAttribute(s, String(i() ?? ""));
142
+ }) : t.setAttribute(s, String(i ?? ""));
141
143
  }
142
144
  }
143
145
  for (const o of n) t.removeAttribute(o);
@@ -159,16 +161,16 @@ function b(t) {
159
161
  function I(t) {
160
162
  let e = !1, n = !1, o = !1;
161
163
  for (let s = 0; s < t.length; s++) {
162
- const i = t[s];
163
- i === "<" && !e && !n && (o = !0), i === ">" && !e && !n && (o = !1), o && (i === '"' && !e && (n = !n), i === "'" && !n && (e = !e));
164
+ const r = t[s];
165
+ r === "<" && !e && !n && (o = !0), r === ">" && !e && !n && (o = !1), o && (r === '"' && !e && (n = !n), r === "'" && !n && (e = !e));
164
166
  }
165
167
  return o;
166
168
  }
167
169
  export {
168
170
  F as Tina4Element,
169
- y as batch,
171
+ C as batch,
170
172
  M as computed,
171
- d as effect,
173
+ l as effect,
172
174
  D as html,
173
175
  u as isSignal,
174
176
  R as signal
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,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,YAAY,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,CAAC;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,aAAa,GAAG,eAAe,GAAG,wBAAwB,CAAC;IAC3E,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAkFD,eAAO,MAAM,GAAG;qBACG,SAAS,GAAG,IAAI;IA6BjC,+EAA+E;kCACjD,SAAS,GAAG,MAAM;IAIhD,mFAAmF;6BAC1D,SAAS,GAAG,MAAM;CAG5C,CAAC"}
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,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,YAAY,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,CAAC;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,aAAa,GAAG,eAAe,GAAG,wBAAwB,CAAC;IAC3E,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4GAA4G;IAC5G,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAkFD,eAAO,MAAM,GAAG;qBACG,SAAS,GAAG,IAAI;IAkCjC,+EAA+E;kCACjD,SAAS,GAAG,MAAM;IAIhD,mFAAmF;6BAC1D,SAAS,GAAG,MAAM;CAG5C,CAAC"}
package/dist/pwa.cjs.js CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tina4js",
3
- "version": "1.1.1",
3
+ "version": "1.2.2",
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",
package/readme.md CHANGED
@@ -6,13 +6,13 @@
6
6
  <h3 align="center">The Intelligent Native Application 4ramework</h3>
7
7
 
8
8
  <p align="center">
9
- Sub-3KB core, reactive frontend. Signals. Web Components. Zero dependencies.
9
+ 1.5KB core gzipped. Reactive frontend. Signals. Web Components. Zero dependencies.
10
10
  </p>
11
11
 
12
12
  <p align="center">
13
13
  <a href="https://www.npmjs.com/package/tina4js"><img src="https://img.shields.io/npm/v/tina4js?color=7b1fa2&label=npm" alt="npm"></a>
14
- <img src="https://img.shields.io/badge/tests-238%20passing-brightgreen" alt="Tests">
15
- <img src="https://img.shields.io/badge/size-%3C3KB-blue" alt="Size">
14
+ <img src="https://img.shields.io/badge/tests-265%20passing-brightgreen" alt="Tests">
15
+ <img src="https://img.shields.io/badge/core-1.5KB%20gzipped-blue" alt="Core size">
16
16
  <img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="Zero Deps">
17
17
  <a href="https://tina4.com/js"><img src="https://img.shields.io/badge/docs-tina4.com%2Fjs-7b1fa2" alt="Docs"></a>
18
18
  </p>
@@ -1,48 +0,0 @@
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`
2
- const CACHE = 'tina4-v1';
3
- const PRECACHE = ${e};
4
- const OFFLINE = ${o};
5
-
6
- self.addEventListener('install', (e) => {
7
- e.waitUntil(
8
- caches.open(CACHE).then((c) => c.addAll(PRECACHE)).then(() => self.skipWaiting())
9
- );
10
- });
11
-
12
- self.addEventListener('activate', (e) => {
13
- e.waitUntil(self.clients.claim());
14
- });
15
-
16
- self.addEventListener('fetch', (e) => {
17
- const req = e.request;
18
- if (req.method !== 'GET') return;
19
-
20
- ${n==="cache-first"?`
21
- e.respondWith(
22
- caches.match(req).then((cached) => cached || fetch(req).then((res) => {
23
- const clone = res.clone();
24
- caches.open(CACHE).then((c) => c.put(req, clone));
25
- return res;
26
- })).catch(() => OFFLINE ? caches.match(OFFLINE) : new Response('Offline', { status: 503 }))
27
- );`:n==="stale-while-revalidate"?`
28
- e.respondWith(
29
- caches.match(req).then((cached) => {
30
- const fetched = fetch(req).then((res) => {
31
- caches.open(CACHE).then((c) => c.put(req, res.clone()));
32
- return res;
33
- });
34
- return cached || fetched;
35
- }).catch(() => OFFLINE ? caches.match(OFFLINE) : new Response('Offline', { status: 503 }))
36
- );`:`
37
- e.respondWith(
38
- fetch(req).then((res) => {
39
- const clone = res.clone();
40
- caches.open(CACHE).then((c) => c.put(req, clone));
41
- return res;
42
- }).catch(() => caches.match(req).then((cached) =>
43
- cached || (OFFLINE ? caches.match(OFFLINE) : new Response('Offline', { status: 503 }))
44
- ))
45
- );`}
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);})();