tina4js 1.2.0 → 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,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"}
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 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
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, _ as C, a 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tina4js",
3
- "version": "1.2.0",
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 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);})();