tina4js 1.2.0 → 1.2.4
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.
- package/bin/tina4.js +3 -1
- package/dist/api/fetch.d.ts.map +1 -1
- package/dist/api.cjs.js +1 -1
- package/dist/api.es.js +1 -0
- package/dist/core/signal.d.ts +1 -1
- package/dist/core/signal.d.ts.map +1 -1
- package/dist/core.cjs.js +1 -1
- package/dist/core.es.js +46 -44
- package/dist/debug.cjs.js +7 -7
- package/dist/debug.es.js +19 -19
- package/dist/signal.cjs.js +1 -1
- package/dist/signal.es.js +78 -62
- package/package.json +1 -1
- package/readme.md +3 -3
- package/dist/tina4js.min.js +0 -48
package/bin/tina4.js
CHANGED
|
@@ -163,7 +163,9 @@ export default defineConfig({
|
|
|
163
163
|
let mainTs = `import { signal, computed, html, route, router, navigate, api } from 'tina4js';
|
|
164
164
|
import './routes/index';
|
|
165
165
|
|
|
166
|
-
// Debug overlay in dev mode (Ctrl+Shift+D to toggle, tree-shaken from
|
|
166
|
+
// Debug overlay in dev mode (Ctrl+Shift+D to toggle, tree-shaken from
|
|
167
|
+
// production builds). Signals created before this dynamic import resolves —
|
|
168
|
+
// including module-level store signals — are buffered and still tracked.
|
|
167
169
|
if (import.meta.env.DEV) import('tina4js/debug');
|
|
168
170
|
`;
|
|
169
171
|
|
package/dist/api/fetch.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AAgGD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,GAAG;IACd;;;;;;;;;;OAUG;iBACU,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;IAItC;;;;;;OAMG;QACC,CAAC,kBAAkB,MAAM,YAAY,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAIpE;;;;;;;OAOG;SACE,CAAC,kBAAkB,MAAM,SAAS,OAAO,YAAY,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAIrF,+BAA+B;QAC3B,CAAC,kBAAkB,MAAM,SAAS,OAAO,YAAY,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAIpF,mCAAmC;UAC7B,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
|
|
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
package/dist/core/signal.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare function _getEffectCollector(): (() => void)[] | null;
|
|
|
14
14
|
export declare let __debugSignalCreate: ((s: Signal<unknown>, label?: string) => void) | null;
|
|
15
15
|
/** @internal Called when a signal value changes. */
|
|
16
16
|
export declare let __debugSignalUpdate: ((s: Signal<unknown>, oldVal: unknown, newVal: unknown) => void) | null;
|
|
17
|
-
/** @internal Set the debug hooks. */
|
|
17
|
+
/** @internal Set the debug hooks, then replay signals created before now. */
|
|
18
18
|
export declare function __setDebugSignalHooks(onCreate: typeof __debugSignalCreate, onUpdate: typeof __debugSignalUpdate): void;
|
|
19
19
|
export interface Signal<T> {
|
|
20
20
|
value: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/core/signal.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH,oEAAoE;AACpE,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,IAAI,GAAG,IAAI,CAE1E;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,IAAI,CAE3D;AAID,iDAAiD;AACjD,eAAO,IAAI,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAW,CAAC;AAC7F,oDAAoD;AACpD,eAAO,IAAI,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/core/signal.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH,oEAAoE;AACpE,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,IAAI,GAAG,IAAI,CAE1E;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,IAAI,CAE3D;AAID,iDAAiD;AACjD,eAAO,IAAI,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAW,CAAC;AAC7F,oDAAoD;AACpD,eAAO,IAAI,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAW,CAAC;AAqB/G,6EAA6E;AAC7E,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,OAAO,mBAAmB,EACpC,QAAQ,EAAE,OAAO,mBAAmB,QAqBrC;AAUD,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,KAAK,EAAE,CAAC,CAAC;IACT,gBAAgB;IAChB,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IACnB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IACvC,sCAAsC;IACtC,IAAI,IAAI,CAAC,CAAC;CACX;AAED,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,gBAAgB;IAChB,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IACnB,gBAAgB;IAChB,UAAU,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IACvC,IAAI,IAAI,CAAC,CAAC;CACX;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CA6D/D;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CA2B1D;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAgCjD;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAgB1C;AAID,0CAA0C;AAC1C,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,CAEjE"}
|
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
|
|
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
|
|
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
|
|
11
|
-
c += t[
|
|
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:
|
|
16
|
-
E(c, e[
|
|
17
|
-
const
|
|
18
|
-
for (const c of
|
|
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),
|
|
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 = [],
|
|
59
|
-
|
|
58
|
+
let s = [], r = [];
|
|
59
|
+
l(() => {
|
|
60
60
|
var g;
|
|
61
|
-
for (const
|
|
62
|
-
|
|
63
|
-
const 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(
|
|
67
|
-
for (const
|
|
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
|
|
72
|
-
m.insertBefore(
|
|
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
|
|
82
|
-
for (const c of
|
|
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,
|
|
93
|
+
const s = o.name, r = o.value;
|
|
94
94
|
if (s.startsWith("@")) {
|
|
95
|
-
const
|
|
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(
|
|
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
|
|
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
|
-
|
|
110
|
-
m.value ? t.setAttribute(
|
|
109
|
+
l(() => {
|
|
110
|
+
m.value ? t.setAttribute(i, "") : t.removeAttribute(i);
|
|
111
111
|
});
|
|
112
|
-
} else typeof f == "function" ?
|
|
113
|
-
f() ? t.setAttribute(
|
|
114
|
-
}) : f && t.setAttribute(
|
|
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
|
|
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) ?
|
|
124
|
-
t[
|
|
125
|
-
}) :
|
|
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 =
|
|
132
|
+
const c = r.match(/__t4_(\d+)__/);
|
|
131
133
|
if (c) {
|
|
132
|
-
const
|
|
133
|
-
if (u(
|
|
134
|
-
const a =
|
|
135
|
-
|
|
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
|
|
139
|
-
t.setAttribute(s, String(
|
|
140
|
-
}) : t.setAttribute(s, String(
|
|
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
|
|
163
|
-
|
|
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
|
-
|
|
171
|
+
C as batch,
|
|
170
172
|
M as computed,
|
|
171
|
-
|
|
173
|
+
l as effect,
|
|
172
174
|
D as html,
|
|
173
175
|
u as isSignal,
|
|
174
176
|
R as signal
|
package/dist/debug.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("./signal.cjs.js"),A=require("./component.cjs.js"),x=require("./index.cjs.js"),y=require("./api.cjs.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("./signal.cjs.js"),A=require("./component.cjs.js"),x=require("./index.cjs.js"),y=require("./api.cjs.js"),d=[],b={add(t,o){const e=t._debugInfo;d.push({ref:new WeakRef(t),label:o,createdAt:(e==null?void 0:e.createdAt)??Date.now(),updateCount:0,subs:new WeakRef((e==null?void 0:e.subs)??new Set)})},onUpdate(t){for(const o of d)if(o.ref.deref()===t){o.updateCount++;break}},getAll(){var o;const t=[];for(let e=d.length-1;e>=0;e--){const n=d[e],r=n.ref.deref();if(!r){d.splice(e,1);continue}const s=n.subs.deref();t.push({label:n.label,value:r.peek(),subscriberCount:s?s.size:0,updateCount:((o=r._debugInfo)==null?void 0:o.updateCount)??n.updateCount,alive:!0})}return t},get count(){return d.length}},a=[],h={onMount(t){a.push({ref:new WeakRef(t),tagName:t.tagName.toLowerCase(),mountedAt:Date.now()})},onUnmount(t){const o=a.findIndex(e=>e.ref.deref()===t);o>=0&&a.splice(o,1)},getAll(){const t=[];for(let o=a.length-1;o>=0;o--){const e=a[o],n=e.ref.deref();if(!n||!n.isConnected){a.splice(o,1);continue}const r={},s=n.constructor;if(s.props)for(const i of Object.keys(s.props))try{r[i]=n.prop(i).peek()}catch{}t.push({tagName:e.tagName,props:r,alive:!0})}return t},get count(){return a.length}},l=[],D=50;let f=null;const p={setGetRoutes(t){f=t},getRegisteredRoutes(){return f?f():[]},onNavigate(t){l.unshift({path:t.path,pattern:t.pattern,params:t.params,durationMs:t.durationMs,timestamp:Date.now()}),l.length>D&&l.pop()},getHistory(){return l},get count(){return l.length}};let M=0;const c=[],m=new Map,j=100,g={onRequest(t){var n;const o=t._requestId??++M,e={id:o,method:t.method??"GET",url:t._url??"",hasAuth:!!((n=t.headers)!=null&&n.Authorization),timestamp:Date.now(),pending:!0};m.set(o,e),c.unshift(e),c.length>j&&c.pop()},onResponse(t){const o=t._requestId,e=o!=null?m.get(o):void 0;e&&(e.status=t.status,e.durationMs=Date.now()-e.timestamp,e.pending=!1,t.ok||(e.error=`HTTP ${t.status}`),m.delete(o))},getLog(){return c},get count(){return c.length}},v=`
|
|
2
2
|
:host {
|
|
3
3
|
all: initial;
|
|
4
4
|
position: fixed;
|
|
@@ -204,7 +204,7 @@ tr:hover td { background: rgba(255,255,255,0.02); }
|
|
|
204
204
|
border-radius: 50%;
|
|
205
205
|
background: #66bb6a;
|
|
206
206
|
}
|
|
207
|
-
`;function E(t){if(t==null)return{text:String(t),cls:"val-null"};if(typeof t=="string")return{text:`"${t.length>30?t.slice(0,30)+"...":t}"`,cls:"val-string"};if(typeof t=="number")return{text:String(t),cls:"val-number"};if(typeof t=="boolean")return{text:String(t),cls:"val-boolean"};if(Array.isArray(t))return{text:`Array(${t.length})`,cls:"val-object"};if(typeof t=="object")try{return{text:JSON.stringify(t).slice(0,40),cls:"val-object"}}catch{}return{text:String(t),cls:"val-object"}}function L(){const t=b.getAll();if(t.length===0)return'<div class="t4-empty">No signals tracked yet.<br>
|
|
207
|
+
`;function E(t){if(t==null)return{text:String(t),cls:"val-null"};if(typeof t=="string")return{text:`"${t.length>30?t.slice(0,30)+"...":t}"`,cls:"val-string"};if(typeof t=="number")return{text:String(t),cls:"val-number"};if(typeof t=="boolean")return{text:String(t),cls:"val-boolean"};if(Array.isArray(t))return{text:`Array(${t.length})`,cls:"val-object"};if(typeof t=="object")try{return{text:JSON.stringify(t).slice(0,40),cls:"val-object"}}catch{}return{text:String(t),cls:"val-object"}}function L(){const t=b.getAll();if(t.length===0)return'<div class="t4-empty">No signals tracked yet.<br>Create a signal — it appears here, even ones made before the overlay loaded.</div>';let o="";for(let e=0;e<t.length;e++){const n=t[e],{text:r,cls:s}=E(n.value);o+=`<tr>
|
|
208
208
|
<td>${n.label||`signal_${e}`}</td>
|
|
209
209
|
<td><span class="${s}">${H(r)}</span></td>
|
|
210
210
|
<td>${n.subscriberCount}</td>
|
|
@@ -213,12 +213,12 @@ tr:hover td { background: rgba(255,255,255,0.02); }
|
|
|
213
213
|
<thead><tr><th>Label</th><th>Value</th><th>Subs</th><th>Updates</th></tr></thead>
|
|
214
214
|
<tbody>${o}</tbody>
|
|
215
215
|
</table>`}function H(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function z(){const t=h.getAll();if(t.length===0)return'<div class="t4-empty">No Tina4Elements mounted.<br>Custom elements extending Tina4Element will appear here.</div>';let o="";for(const e of t){const n=Object.keys(e.props).length>0?Object.entries(e.props).map(([r,s])=>`${r}=${JSON.stringify(s)??"null"}`).join(", "):"—";o+=`<tr>
|
|
216
|
-
<td><${
|
|
217
|
-
<td>${
|
|
216
|
+
<td><${w(e.tagName)}></td>
|
|
217
|
+
<td>${w(n.length>60?n.slice(0,60)+"...":n)}</td>
|
|
218
218
|
</tr>`}return`<table>
|
|
219
219
|
<thead><tr><th>Element</th><th>Props</th></tr></thead>
|
|
220
220
|
<tbody>${o}</tbody>
|
|
221
|
-
</table>`}function
|
|
221
|
+
</table>`}function w(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function q(t){const o=t<1?"<1ms":`${Math.round(t)}ms`,e=t<5?"duration fast":t<50?"duration":t<200?"duration slow":"duration very-slow";return{text:o,cls:e}}function I(t){return new Date(t).toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}function P(){const t=p.getRegisteredRoutes(),o=p.getHistory();let e="";if(t.length>0){let n="";for(const r of t)n+=`<tr>
|
|
222
222
|
<td><span class="route-pattern">${_(r.pattern)}</span></td>
|
|
223
223
|
<td>${r.hasGuard?"Yes":"—"}</td>
|
|
224
224
|
</tr>`;e+=`<table>
|
|
@@ -243,7 +243,7 @@ tr:hover td { background: rgba(255,255,255,0.02); }
|
|
|
243
243
|
<thead><tr><th>Time</th><th>Method</th><th>URL</th><th>Status</th><th>Duration</th><th>Auth</th></tr></thead>
|
|
244
244
|
<tbody>${o}</tbody>
|
|
245
245
|
</table>`}function B(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}class F extends HTMLElement{constructor(){super(),this._visible=!0,this._activeTab="signals",this._refreshTimer=null,this._shadow=this.attachShadow({mode:"open"})}connectedCallback(){this._render(),this._startAutoRefresh()}disconnectedCallback(){this._stopAutoRefresh()}toggle(){this._visible=!this._visible,this._render()}show(){this._visible=!0,this._render()}hide(){this._visible=!1,this._render()}_startAutoRefresh(){this._refreshTimer=window.setInterval(()=>{this._visible&&this._renderBody()},1e3)}_stopAutoRefresh(){this._refreshTimer!==null&&(clearInterval(this._refreshTimer),this._refreshTimer=null)}_switchTab(o){this._activeTab=o,this._render()}_getTabContent(){switch(this._activeTab){case"signals":return L();case"components":return z();case"routes":return P();case"api":return G()}}_renderBody(){const o=this._shadow.querySelector(".t4-body");o&&(o.innerHTML=this._getTabContent()),this._updateTabCounts()}_updateTabCounts(){const o={signals:b.count,components:h.count,routes:p.count,api:g.count};for(const[e,n]of Object.entries(o)){const r=this._shadow.querySelector(`[data-tab-count="${e}"]`);r&&(r.textContent=n>0?`(${n})`:"")}}_render(){var n,r;const o=[{id:"signals",label:"Signals"},{id:"components",label:"Components"},{id:"routes",label:"Routes"},{id:"api",label:"API"}];if(!this._visible){this._shadow.innerHTML=`
|
|
246
|
-
<style>${
|
|
246
|
+
<style>${v}</style>
|
|
247
247
|
<div class="t4-mini" id="t4-mini">
|
|
248
248
|
<span class="t4-mini-dot"></span>
|
|
249
249
|
Debug
|
|
@@ -251,7 +251,7 @@ tr:hover td { background: rgba(255,255,255,0.02); }
|
|
|
251
251
|
`,(n=this._shadow.getElementById("t4-mini"))==null||n.addEventListener("click",()=>this.show());return}const e=o.map(s=>`<button class="t4-tab${this._activeTab===s.id?" active":""}" data-tab="${s.id}">
|
|
252
252
|
${s.label}<span class="t4-tab-count" data-tab-count="${s.id}"></span>
|
|
253
253
|
</button>`).join("");this._shadow.innerHTML=`
|
|
254
|
-
<style>${
|
|
254
|
+
<style>${v}</style>
|
|
255
255
|
<div class="t4-debug">
|
|
256
256
|
<div class="t4-header">
|
|
257
257
|
<div>
|
package/dist/debug.es.js
CHANGED
|
@@ -2,7 +2,7 @@ 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";
|
|
5
|
-
const d = [],
|
|
5
|
+
const d = [], h = {
|
|
6
6
|
add(t, o) {
|
|
7
7
|
const e = t._debugInfo;
|
|
8
8
|
d.push({
|
|
@@ -43,7 +43,7 @@ const d = [], b = {
|
|
|
43
43
|
get count() {
|
|
44
44
|
return d.length;
|
|
45
45
|
}
|
|
46
|
-
}, a = [],
|
|
46
|
+
}, a = [], b = {
|
|
47
47
|
onMount(t) {
|
|
48
48
|
a.push({
|
|
49
49
|
ref: new WeakRef(t),
|
|
@@ -351,9 +351,9 @@ function L(t) {
|
|
|
351
351
|
return { text: String(t), cls: "val-object" };
|
|
352
352
|
}
|
|
353
353
|
function j() {
|
|
354
|
-
const t =
|
|
354
|
+
const t = h.getAll();
|
|
355
355
|
if (t.length === 0)
|
|
356
|
-
return '<div class="t4-empty">No signals tracked yet.<br>
|
|
356
|
+
return '<div class="t4-empty">No signals tracked yet.<br>Create a signal — it appears here, even ones made before the overlay loaded.</div>';
|
|
357
357
|
let o = "";
|
|
358
358
|
for (let e = 0; e < t.length; e++) {
|
|
359
359
|
const n = t[e], { text: r, cls: s } = L(n.value);
|
|
@@ -373,15 +373,15 @@ function H(t) {
|
|
|
373
373
|
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
374
374
|
}
|
|
375
375
|
function z() {
|
|
376
|
-
const t =
|
|
376
|
+
const t = b.getAll();
|
|
377
377
|
if (t.length === 0)
|
|
378
378
|
return '<div class="t4-empty">No Tina4Elements mounted.<br>Custom elements extending Tina4Element will appear here.</div>';
|
|
379
379
|
let o = "";
|
|
380
380
|
for (const e of t) {
|
|
381
381
|
const n = Object.keys(e.props).length > 0 ? Object.entries(e.props).map(([r, s]) => `${r}=${JSON.stringify(s) ?? "null"}`).join(", ") : "—";
|
|
382
382
|
o += `<tr>
|
|
383
|
-
<td><${
|
|
384
|
-
<td>${
|
|
383
|
+
<td><${v(e.tagName)}></td>
|
|
384
|
+
<td>${v(n.length > 60 ? n.slice(0, 60) + "..." : n)}</td>
|
|
385
385
|
</tr>`;
|
|
386
386
|
}
|
|
387
387
|
return `<table>
|
|
@@ -389,7 +389,7 @@ function z() {
|
|
|
389
389
|
<tbody>${o}</tbody>
|
|
390
390
|
</table>`;
|
|
391
391
|
}
|
|
392
|
-
function
|
|
392
|
+
function v(t) {
|
|
393
393
|
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
394
394
|
}
|
|
395
395
|
function I(t) {
|
|
@@ -406,7 +406,7 @@ function P() {
|
|
|
406
406
|
let n = "";
|
|
407
407
|
for (const r of t)
|
|
408
408
|
n += `<tr>
|
|
409
|
-
<td><span class="route-pattern">${
|
|
409
|
+
<td><span class="route-pattern">${w(r.pattern)}</span></td>
|
|
410
410
|
<td>${r.hasGuard ? "Yes" : "—"}</td>
|
|
411
411
|
</tr>`;
|
|
412
412
|
e += `<table>
|
|
@@ -421,7 +421,7 @@ function P() {
|
|
|
421
421
|
const { text: s, cls: i } = I(r.durationMs), $ = Object.keys(r.params).length > 0 ? Object.entries(r.params).map(([k, T]) => `<span class="route-param">${k}=${T}</span>`).join(" ") : "";
|
|
422
422
|
n += `<tr>
|
|
423
423
|
<td>${N(r.timestamp)}</td>
|
|
424
|
-
<td>${
|
|
424
|
+
<td>${w(r.path)}</td>
|
|
425
425
|
<td>${$ || "—"}</td>
|
|
426
426
|
<td><span class="${i}">${s}</span></td>
|
|
427
427
|
</tr>`;
|
|
@@ -433,7 +433,7 @@ function P() {
|
|
|
433
433
|
} else t.length === 0 && (e = '<div class="t4-empty">No routes registered yet.</div>');
|
|
434
434
|
return e;
|
|
435
435
|
}
|
|
436
|
-
function
|
|
436
|
+
function w(t) {
|
|
437
437
|
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
438
438
|
}
|
|
439
439
|
function O(t) {
|
|
@@ -519,8 +519,8 @@ class F extends HTMLElement {
|
|
|
519
519
|
}
|
|
520
520
|
_updateTabCounts() {
|
|
521
521
|
const o = {
|
|
522
|
-
signals:
|
|
523
|
-
components:
|
|
522
|
+
signals: h.count,
|
|
523
|
+
components: b.count,
|
|
524
524
|
routes: p.count,
|
|
525
525
|
api: g.count
|
|
526
526
|
};
|
|
@@ -578,14 +578,14 @@ class F extends HTMLElement {
|
|
|
578
578
|
function V() {
|
|
579
579
|
typeof customElements < "u" && !customElements.get("tina4-debug") && customElements.define("tina4-debug", F);
|
|
580
580
|
}
|
|
581
|
-
let u = null,
|
|
581
|
+
let u = null, _ = !1;
|
|
582
582
|
function W() {
|
|
583
|
-
|
|
584
|
-
(t, o) =>
|
|
585
|
-
(t) =>
|
|
583
|
+
_ || (_ = !0, C(
|
|
584
|
+
(t, o) => h.add(t, o),
|
|
585
|
+
(t) => h.onUpdate(t)
|
|
586
586
|
), S(
|
|
587
|
-
(t) =>
|
|
588
|
-
(t) =>
|
|
587
|
+
(t) => b.onMount(t),
|
|
588
|
+
(t) => b.onUnmount(t)
|
|
589
589
|
), p.setGetRoutes(R), A.on("change", (t) => {
|
|
590
590
|
p.onNavigate(t);
|
|
591
591
|
}), x.intercept("request", (t) => (g.onRequest(t), t)), x.intercept("response", (t) => (g.onResponse(t), t)), typeof document < "u" && (V(), u = document.createElement("tina4-debug"), document.body.appendChild(u), document.addEventListener("keydown", (t) => {
|
package/dist/signal.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";let
|
|
1
|
+
"use strict";let f=null,s=null,i=null;function S(n){i=n}function w(){return i}let _=null,b=null;const a=[],E=512;function y(n,o){if(_=n,b=o,n)for(const e of a){const t=e.ref.deref();t&&(t._debugInfo||(t._debugInfo={label:e.label,createdAt:e.createdAt,updateCount:0,subs:e.subs}),n(t,e.label))}a.length=0}let l=0;const g=new Set;function p(n,o){let e=n;const t=new Set,r={_t4:!0,get value(){if(f&&(t.add(f),s)){const u=f;s.push(()=>t.delete(u))}return e},set value(u){if(Object.is(u,e))return;const d=e;if(e=u,r._debugInfo&&r._debugInfo.updateCount++,b&&b(r,d,u),l>0)for(const c of t)g.add(c);else{let c;for(const v of[...t])try{v()}catch(C){c===void 0&&(c=C)}if(c!==void 0)throw c}},_subscribe(u){return t.add(u),()=>{t.delete(u)}},peek(){return e}};return _?(r._debugInfo={label:o,createdAt:Date.now(),updateCount:0,subs:t},_(r,o)):a.length<E&&a.push({ref:new WeakRef(r),label:o,createdAt:Date.now(),subs:t}),r}function I(n){const o=p(void 0);return h(()=>{o.value=n()}),{_t4:!0,get value(){return o.value},set value(e){throw new Error("[tina4] computed signals are read-only")},_subscribe(e){return o._subscribe(e)},peek(){return o.peek()}}}function h(n){let o=!1,e=[];const t=()=>{if(o)return;for(const c of e)c();e=[];const u=f,d=s;f=t,s=e;try{n()}finally{f=u,s=d}};t();const r=()=>{o=!0;for(const u of e)u();e=[]};return i&&i.push(r),r}function k(n){l++;try{n()}finally{if(l--,l===0){const o=[...g];g.clear();let e;for(const t of o)try{t()}catch(r){e===void 0&&(e=r)}if(e!==void 0)throw e}}}function A(n){return n!==null&&typeof n=="object"&&n._t4===!0}exports.__setDebugSignalHooks=y;exports._getEffectCollector=w;exports._setEffectCollector=S;exports.batch=k;exports.computed=I;exports.effect=h;exports.isSignal=A;exports.signal=p;
|
package/dist/signal.es.js
CHANGED
|
@@ -1,125 +1,141 @@
|
|
|
1
|
-
let
|
|
2
|
-
function
|
|
3
|
-
i =
|
|
1
|
+
let f = null, c = null, i = null;
|
|
2
|
+
function C(n) {
|
|
3
|
+
i = n;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function S() {
|
|
6
6
|
return i;
|
|
7
7
|
}
|
|
8
|
-
let
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
let b = null, _ = null;
|
|
9
|
+
const a = [], v = 512;
|
|
10
|
+
function E(n, o) {
|
|
11
|
+
if (b = n, _ = o, n)
|
|
12
|
+
for (const e of a) {
|
|
13
|
+
const t = e.ref.deref();
|
|
14
|
+
t && (t._debugInfo || (t._debugInfo = {
|
|
15
|
+
label: e.label,
|
|
16
|
+
createdAt: e.createdAt,
|
|
17
|
+
updateCount: 0,
|
|
18
|
+
subs: e.subs
|
|
19
|
+
}), n(t, e.label));
|
|
20
|
+
}
|
|
21
|
+
a.length = 0;
|
|
11
22
|
}
|
|
12
23
|
let l = 0;
|
|
13
24
|
const p = /* @__PURE__ */ new Set();
|
|
14
|
-
function
|
|
15
|
-
let e =
|
|
16
|
-
const
|
|
25
|
+
function w(n, o) {
|
|
26
|
+
let e = n;
|
|
27
|
+
const t = /* @__PURE__ */ new Set(), r = {
|
|
17
28
|
_t4: !0,
|
|
18
29
|
get value() {
|
|
19
|
-
if (
|
|
20
|
-
const
|
|
21
|
-
|
|
30
|
+
if (f && (t.add(f), c)) {
|
|
31
|
+
const u = f;
|
|
32
|
+
c.push(() => t.delete(u));
|
|
22
33
|
}
|
|
23
34
|
return e;
|
|
24
35
|
},
|
|
25
|
-
set value(
|
|
26
|
-
if (Object.is(
|
|
27
|
-
const
|
|
28
|
-
if (e =
|
|
29
|
-
for (const s of
|
|
36
|
+
set value(u) {
|
|
37
|
+
if (Object.is(u, e)) return;
|
|
38
|
+
const d = e;
|
|
39
|
+
if (e = u, r._debugInfo && r._debugInfo.updateCount++, _ && _(r, d, u), l > 0)
|
|
40
|
+
for (const s of t) p.add(s);
|
|
30
41
|
else {
|
|
31
42
|
let s;
|
|
32
|
-
for (const
|
|
43
|
+
for (const g of [...t])
|
|
33
44
|
try {
|
|
34
|
-
|
|
35
|
-
} catch (
|
|
36
|
-
s === void 0 && (s =
|
|
45
|
+
g();
|
|
46
|
+
} catch (h) {
|
|
47
|
+
s === void 0 && (s = h);
|
|
37
48
|
}
|
|
38
49
|
if (s !== void 0) throw s;
|
|
39
50
|
}
|
|
40
51
|
},
|
|
41
|
-
_subscribe(
|
|
42
|
-
return
|
|
43
|
-
|
|
52
|
+
_subscribe(u) {
|
|
53
|
+
return t.add(u), () => {
|
|
54
|
+
t.delete(u);
|
|
44
55
|
};
|
|
45
56
|
},
|
|
46
57
|
peek() {
|
|
47
58
|
return e;
|
|
48
59
|
}
|
|
49
60
|
};
|
|
50
|
-
return
|
|
61
|
+
return b ? (r._debugInfo = { label: o, createdAt: Date.now(), updateCount: 0, subs: t }, b(r, o)) : a.length < v && a.push({
|
|
62
|
+
ref: new WeakRef(r),
|
|
63
|
+
label: o,
|
|
64
|
+
createdAt: Date.now(),
|
|
65
|
+
subs: t
|
|
66
|
+
}), r;
|
|
51
67
|
}
|
|
52
|
-
function
|
|
53
|
-
const
|
|
54
|
-
return
|
|
55
|
-
|
|
68
|
+
function I(n) {
|
|
69
|
+
const o = w(void 0);
|
|
70
|
+
return y(() => {
|
|
71
|
+
o.value = n();
|
|
56
72
|
}), {
|
|
57
73
|
_t4: !0,
|
|
58
74
|
get value() {
|
|
59
|
-
return
|
|
75
|
+
return o.value;
|
|
60
76
|
},
|
|
61
77
|
set value(e) {
|
|
62
78
|
throw new Error("[tina4] computed signals are read-only");
|
|
63
79
|
},
|
|
64
80
|
_subscribe(e) {
|
|
65
|
-
return
|
|
81
|
+
return o._subscribe(e);
|
|
66
82
|
},
|
|
67
83
|
peek() {
|
|
68
|
-
return
|
|
84
|
+
return o.peek();
|
|
69
85
|
}
|
|
70
86
|
};
|
|
71
87
|
}
|
|
72
|
-
function
|
|
73
|
-
let
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
88
|
+
function y(n) {
|
|
89
|
+
let o = !1, e = [];
|
|
90
|
+
const t = () => {
|
|
91
|
+
if (o) return;
|
|
76
92
|
for (const s of e) s();
|
|
77
93
|
e = [];
|
|
78
|
-
const
|
|
79
|
-
|
|
94
|
+
const u = f, d = c;
|
|
95
|
+
f = t, c = e;
|
|
80
96
|
try {
|
|
81
|
-
|
|
97
|
+
n();
|
|
82
98
|
} finally {
|
|
83
|
-
|
|
99
|
+
f = u, c = d;
|
|
84
100
|
}
|
|
85
101
|
};
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
for (const
|
|
102
|
+
t();
|
|
103
|
+
const r = () => {
|
|
104
|
+
o = !0;
|
|
105
|
+
for (const u of e) u();
|
|
90
106
|
e = [];
|
|
91
107
|
};
|
|
92
|
-
return i && i.push(
|
|
108
|
+
return i && i.push(r), r;
|
|
93
109
|
}
|
|
94
|
-
function
|
|
110
|
+
function A(n) {
|
|
95
111
|
l++;
|
|
96
112
|
try {
|
|
97
|
-
|
|
113
|
+
n();
|
|
98
114
|
} finally {
|
|
99
115
|
if (l--, l === 0) {
|
|
100
|
-
const
|
|
116
|
+
const o = [...p];
|
|
101
117
|
p.clear();
|
|
102
118
|
let e;
|
|
103
|
-
for (const
|
|
119
|
+
for (const t of o)
|
|
104
120
|
try {
|
|
105
|
-
|
|
106
|
-
} catch (
|
|
107
|
-
e === void 0 && (e =
|
|
121
|
+
t();
|
|
122
|
+
} catch (r) {
|
|
123
|
+
e === void 0 && (e = r);
|
|
108
124
|
}
|
|
109
125
|
if (e !== void 0) throw e;
|
|
110
126
|
}
|
|
111
127
|
}
|
|
112
128
|
}
|
|
113
|
-
function k(
|
|
114
|
-
return
|
|
129
|
+
function k(n) {
|
|
130
|
+
return n !== null && typeof n == "object" && n._t4 === !0;
|
|
115
131
|
}
|
|
116
132
|
export {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
133
|
+
S as _,
|
|
134
|
+
C as a,
|
|
135
|
+
A as b,
|
|
136
|
+
I as c,
|
|
137
|
+
E as d,
|
|
138
|
+
y as e,
|
|
123
139
|
k as i,
|
|
124
|
-
|
|
140
|
+
w as s
|
|
125
141
|
};
|
package/package.json
CHANGED
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
|
-
|
|
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-
|
|
15
|
-
<img src="https://img.shields.io/badge/
|
|
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>
|
package/dist/tina4js.min.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
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 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);})();
|