tina4js 1.0.8 → 1.0.9
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/dist/core.cjs.js +1 -1
- package/dist/core.es.js +28 -28
- package/package.json +1 -1
package/dist/core.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./signal.cjs.js"),
|
|
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 i=0;i<t.length;i++)f+=t[i],i<e.length&&(E(f)?f+=`__t4_${i}__`:f+=`<!--${m}${i}-->`);n.innerHTML=f,_.set(t,n)}const o=n.content.cloneNode(!0),c=C(o);for(const{marker:f,index:i}of c)S(f,e[i]);const r=y(o);for(const f of r)T(f,e);return o}function C(t){const e=[];return p(t,n=>{if(n.nodeType===8){const o=n.data;if(o&&o.startsWith(m)){const c=parseInt(o.slice(m.length),10);e.push({marker:n,index:c})}}}),e}function y(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 c=n[o];e(c),p(c,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 c=[],r=[];s.effect(()=>{var g;for(const d of r)d();r=[];const f=[],i=s._getEffectCollector();s._setEffectCollector(f);const l=e();s._setEffectCollector(i),r=f;for(const d of c)(g=d.parentNode)==null||g.removeChild(d);c=[];const a=h(l),u=o.parentNode;if(u)for(const d of a)u.insertBefore(d,o),c.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 c of e){const r=h(c);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 c=o.name,r=o.value;if(c.startsWith("@")){const i=c.slice(1),l=r.match(/__t4_(\d+)__/);if(l){const a=e[parseInt(l[1],10)];typeof a=="function"&&t.addEventListener(i,u=>s.batch(()=>a(u)))}n.push(c);continue}if(c.startsWith("?")){const i=c.slice(1),l=r.match(/__t4_(\d+)__/);if(l){const a=e[parseInt(l[1],10)];if(s.isSignal(a)){const u=a;s.effect(()=>{u.value?t.setAttribute(i,""):t.removeAttribute(i)})}else a&&t.setAttribute(i,"")}n.push(c);continue}if(c.startsWith(".")){const i=c.slice(1),l=r.match(/__t4_(\d+)__/);if(l){const a=e[parseInt(l[1],10)];s.isSignal(a)?s.effect(()=>{t[i]=a.value}):t[i]=a}n.push(c);continue}const f=r.match(/__t4_(\d+)__/);if(f){const i=e[parseInt(f[1],10)];if(s.isSignal(i)){const l=i;s.effect(()=>{t.setAttribute(c,String(l.value??""))})}else typeof i=="function"?s.effect(()=>{t.setAttribute(c,String(i()??""))}):t.setAttribute(c,String(i??""))}}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 c=0;c<t.length;c++){const r=t[c];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;
|
package/dist/core.es.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { i as p, e as
|
|
2
|
-
import {
|
|
1
|
+
import { i as p, e as m, a as b, d as A, b as y } from "./signal.es.js";
|
|
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(), u = "t4:";
|
|
5
|
-
function
|
|
5
|
+
function D(t, ...e) {
|
|
6
6
|
let n = N.get(t);
|
|
7
7
|
if (!n) {
|
|
8
8
|
n = document.createElement("template");
|
|
9
9
|
let i = "";
|
|
10
10
|
for (let r = 0; r < t.length; r++)
|
|
11
|
-
i += t[r], r < e.length && (
|
|
11
|
+
i += t[r], r < e.length && (I(i) ? i += `__t4_${r}__` : i += `<!--${u}${r}-->`);
|
|
12
12
|
n.innerHTML = i, N.set(t, n);
|
|
13
13
|
}
|
|
14
|
-
const o = n.content.cloneNode(!0), s =
|
|
14
|
+
const o = n.content.cloneNode(!0), s = T(o);
|
|
15
15
|
for (const { marker: i, index: r } of s)
|
|
16
|
-
|
|
17
|
-
const c =
|
|
16
|
+
E(i, e[r]);
|
|
17
|
+
const c = x(o);
|
|
18
18
|
for (const i of c)
|
|
19
|
-
|
|
19
|
+
S(i, e);
|
|
20
20
|
return o;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function T(t) {
|
|
23
23
|
const e = [];
|
|
24
24
|
return _(t, (n) => {
|
|
25
25
|
if (n.nodeType === 8) {
|
|
@@ -31,7 +31,7 @@ function y(t) {
|
|
|
31
31
|
}
|
|
32
32
|
}), e;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function x(t) {
|
|
35
35
|
const e = [];
|
|
36
36
|
return _(t, (n) => {
|
|
37
37
|
n.nodeType === 1 && e.push(n);
|
|
@@ -44,19 +44,19 @@ function _(t, e) {
|
|
|
44
44
|
e(s), _(s, e);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function E(t, e) {
|
|
48
48
|
const n = t.parentNode;
|
|
49
49
|
if (n)
|
|
50
50
|
if (p(e)) {
|
|
51
51
|
const o = document.createTextNode("");
|
|
52
|
-
n.replaceChild(o, t),
|
|
52
|
+
n.replaceChild(o, t), m(() => {
|
|
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
58
|
let s = [], c = [];
|
|
59
|
-
|
|
59
|
+
m(() => {
|
|
60
60
|
var g;
|
|
61
61
|
for (const l of c) l();
|
|
62
62
|
c = [];
|
|
@@ -66,10 +66,10 @@ function x(t, e) {
|
|
|
66
66
|
A(r), c = i;
|
|
67
67
|
for (const l of s) (g = l.parentNode) == null || g.removeChild(l);
|
|
68
68
|
s = [];
|
|
69
|
-
const a = h(f),
|
|
70
|
-
if (
|
|
69
|
+
const a = h(f), d = o.parentNode;
|
|
70
|
+
if (d)
|
|
71
71
|
for (const l of a)
|
|
72
|
-
|
|
72
|
+
d.insertBefore(l, o), s.push(l);
|
|
73
73
|
});
|
|
74
74
|
} else if (C(e))
|
|
75
75
|
n.replaceChild(e, t);
|
|
@@ -87,7 +87,7 @@ function x(t, e) {
|
|
|
87
87
|
n.replaceChild(o, t);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function S(t, e) {
|
|
91
91
|
const n = [];
|
|
92
92
|
for (const o of Array.from(t.attributes)) {
|
|
93
93
|
const s = o.name, c = o.value;
|
|
@@ -95,7 +95,7 @@ function E(t, e) {
|
|
|
95
95
|
const r = s.slice(1), f = c.match(/__t4_(\d+)__/);
|
|
96
96
|
if (f) {
|
|
97
97
|
const a = e[parseInt(f[1], 10)];
|
|
98
|
-
typeof a == "function" && t.addEventListener(r, a);
|
|
98
|
+
typeof a == "function" && t.addEventListener(r, (d) => y(() => a(d)));
|
|
99
99
|
}
|
|
100
100
|
n.push(s);
|
|
101
101
|
continue;
|
|
@@ -105,9 +105,9 @@ function E(t, e) {
|
|
|
105
105
|
if (f) {
|
|
106
106
|
const a = e[parseInt(f[1], 10)];
|
|
107
107
|
if (p(a)) {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
const d = a;
|
|
109
|
+
m(() => {
|
|
110
|
+
d.value ? t.setAttribute(r, "") : t.removeAttribute(r);
|
|
111
111
|
});
|
|
112
112
|
} else
|
|
113
113
|
a && t.setAttribute(r, "");
|
|
@@ -119,7 +119,7 @@ function E(t, e) {
|
|
|
119
119
|
const r = s.slice(1), f = c.match(/__t4_(\d+)__/);
|
|
120
120
|
if (f) {
|
|
121
121
|
const a = e[parseInt(f[1], 10)];
|
|
122
|
-
p(a) ?
|
|
122
|
+
p(a) ? m(() => {
|
|
123
123
|
t[r] = a.value;
|
|
124
124
|
}) : t[r] = a;
|
|
125
125
|
}
|
|
@@ -131,10 +131,10 @@ function E(t, e) {
|
|
|
131
131
|
const r = e[parseInt(i[1], 10)];
|
|
132
132
|
if (p(r)) {
|
|
133
133
|
const f = r;
|
|
134
|
-
|
|
134
|
+
m(() => {
|
|
135
135
|
t.setAttribute(s, String(f.value ?? ""));
|
|
136
136
|
});
|
|
137
|
-
} else typeof r == "function" ?
|
|
137
|
+
} else typeof r == "function" ? m(() => {
|
|
138
138
|
t.setAttribute(s, String(r() ?? ""));
|
|
139
139
|
}) : t.setAttribute(s, String(r ?? ""));
|
|
140
140
|
}
|
|
@@ -155,7 +155,7 @@ function h(t) {
|
|
|
155
155
|
function C(t) {
|
|
156
156
|
return t != null && typeof t == "object" && t.nodeType === 11;
|
|
157
157
|
}
|
|
158
|
-
function
|
|
158
|
+
function I(t) {
|
|
159
159
|
let e = !1, n = !1, o = !1;
|
|
160
160
|
for (let s = 0; s < t.length; s++) {
|
|
161
161
|
const c = t[s];
|
|
@@ -165,10 +165,10 @@ function S(t) {
|
|
|
165
165
|
}
|
|
166
166
|
export {
|
|
167
167
|
F as Tina4Element,
|
|
168
|
-
|
|
168
|
+
y as batch,
|
|
169
169
|
M as computed,
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
m as effect,
|
|
171
|
+
D as html,
|
|
172
172
|
p as isSignal,
|
|
173
173
|
R as signal
|
|
174
174
|
};
|