sprae 6.1.2 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -5
- package/readme.md +75 -13
- package/sprae.auto.js +682 -327
- package/sprae.auto.min.js +1 -1
- package/sprae.js +682 -327
- package/sprae.min.js +1 -1
- package/src/core.js +24 -25
- package/src/directives.js +109 -83
- package/src/domdiff.js +10 -7
- package/src/{state.js → state.proxy.js} +40 -17
- package/src/state.signals-proxy.js +133 -0
- package/src/state.signals.js +82 -0
package/sprae.auto.js
CHANGED
|
@@ -1,202 +1,522 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
// node_modules/@preact/signals-core/dist/signals-core.module.js
|
|
3
|
+
function i() {
|
|
4
|
+
throw new Error("Cycle detected");
|
|
5
|
+
}
|
|
6
|
+
var t = Symbol.for("preact-signals");
|
|
7
|
+
function r() {
|
|
8
|
+
if (!(v > 1)) {
|
|
9
|
+
var i2, t2 = false;
|
|
10
|
+
while (void 0 !== f) {
|
|
11
|
+
var r2 = f;
|
|
12
|
+
f = void 0;
|
|
13
|
+
e++;
|
|
14
|
+
while (void 0 !== r2) {
|
|
15
|
+
var n2 = r2.o;
|
|
16
|
+
r2.o = void 0;
|
|
17
|
+
r2.f &= -3;
|
|
18
|
+
if (!(8 & r2.f) && l(r2))
|
|
19
|
+
try {
|
|
20
|
+
r2.c();
|
|
21
|
+
} catch (r3) {
|
|
22
|
+
if (!t2) {
|
|
23
|
+
i2 = r3;
|
|
24
|
+
t2 = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
r2 = n2;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
e = 0;
|
|
31
|
+
v--;
|
|
32
|
+
if (t2)
|
|
33
|
+
throw i2;
|
|
34
|
+
} else
|
|
35
|
+
v--;
|
|
36
|
+
}
|
|
37
|
+
function n(i2) {
|
|
38
|
+
if (v > 0)
|
|
39
|
+
return i2();
|
|
40
|
+
v++;
|
|
41
|
+
try {
|
|
42
|
+
return i2();
|
|
43
|
+
} finally {
|
|
44
|
+
r();
|
|
15
45
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
46
|
+
}
|
|
47
|
+
var o = void 0;
|
|
48
|
+
var h = 0;
|
|
49
|
+
function s(i2) {
|
|
50
|
+
if (h > 0)
|
|
51
|
+
return i2();
|
|
52
|
+
var t2 = o;
|
|
53
|
+
o = void 0;
|
|
54
|
+
h++;
|
|
55
|
+
try {
|
|
56
|
+
return i2();
|
|
57
|
+
} finally {
|
|
58
|
+
h--;
|
|
59
|
+
o = t2;
|
|
20
60
|
}
|
|
21
|
-
|
|
22
|
-
|
|
61
|
+
}
|
|
62
|
+
var f = void 0;
|
|
63
|
+
var v = 0;
|
|
64
|
+
var e = 0;
|
|
65
|
+
var u = 0;
|
|
66
|
+
function c(i2) {
|
|
67
|
+
if (void 0 !== o) {
|
|
68
|
+
var t2 = i2.n;
|
|
69
|
+
if (void 0 === t2 || t2.t !== o) {
|
|
70
|
+
t2 = { i: 0, S: i2, p: o.s, n: void 0, t: o, e: void 0, x: void 0, r: t2 };
|
|
71
|
+
if (void 0 !== o.s)
|
|
72
|
+
o.s.n = t2;
|
|
73
|
+
o.s = t2;
|
|
74
|
+
i2.n = t2;
|
|
75
|
+
if (32 & o.f)
|
|
76
|
+
i2.S(t2);
|
|
77
|
+
return t2;
|
|
78
|
+
} else if (-1 === t2.i) {
|
|
79
|
+
t2.i = 0;
|
|
80
|
+
if (void 0 !== t2.n) {
|
|
81
|
+
t2.n.p = t2.p;
|
|
82
|
+
if (void 0 !== t2.p)
|
|
83
|
+
t2.p.n = t2.n;
|
|
84
|
+
t2.p = o.s;
|
|
85
|
+
t2.n = void 0;
|
|
86
|
+
o.s.n = t2;
|
|
87
|
+
o.s = t2;
|
|
88
|
+
}
|
|
89
|
+
return t2;
|
|
90
|
+
}
|
|
23
91
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
92
|
+
}
|
|
93
|
+
function d(i2) {
|
|
94
|
+
this.v = i2;
|
|
95
|
+
this.i = 0;
|
|
96
|
+
this.n = void 0;
|
|
97
|
+
this.t = void 0;
|
|
98
|
+
}
|
|
99
|
+
d.prototype.brand = t;
|
|
100
|
+
d.prototype.h = function() {
|
|
101
|
+
return true;
|
|
102
|
+
};
|
|
103
|
+
d.prototype.S = function(i2) {
|
|
104
|
+
if (this.t !== i2 && void 0 === i2.e) {
|
|
105
|
+
i2.x = this.t;
|
|
106
|
+
if (void 0 !== this.t)
|
|
107
|
+
this.t.e = i2;
|
|
108
|
+
this.t = i2;
|
|
31
109
|
}
|
|
32
110
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Boolean,
|
|
48
|
-
Date,
|
|
49
|
-
console,
|
|
50
|
-
window,
|
|
51
|
-
document,
|
|
52
|
-
history,
|
|
53
|
-
location
|
|
111
|
+
d.prototype.U = function(i2) {
|
|
112
|
+
if (void 0 !== this.t) {
|
|
113
|
+
var t2 = i2.e, r2 = i2.x;
|
|
114
|
+
if (void 0 !== t2) {
|
|
115
|
+
t2.x = r2;
|
|
116
|
+
i2.e = void 0;
|
|
117
|
+
}
|
|
118
|
+
if (void 0 !== r2) {
|
|
119
|
+
r2.e = t2;
|
|
120
|
+
i2.x = void 0;
|
|
121
|
+
}
|
|
122
|
+
if (i2 === this.t)
|
|
123
|
+
this.t = r2;
|
|
124
|
+
}
|
|
54
125
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (prop in Object.prototype || Array.isArray(target) && prop in Array.prototype && prop !== "length")
|
|
65
|
-
return target[prop];
|
|
66
|
-
let value = target[prop];
|
|
67
|
-
if (currentFx) {
|
|
68
|
-
let propFxs = targetFxs.get(target);
|
|
69
|
-
if (!propFxs)
|
|
70
|
-
targetFxs.set(target, propFxs = {});
|
|
71
|
-
if (!propFxs[prop])
|
|
72
|
-
propFxs[prop] = [currentFx];
|
|
73
|
-
else if (!propFxs[prop].includes(currentFx))
|
|
74
|
-
propFxs[prop].push(currentFx);
|
|
126
|
+
d.prototype.subscribe = function(i2) {
|
|
127
|
+
var t2 = this;
|
|
128
|
+
return O(function() {
|
|
129
|
+
var r2 = t2.value, n2 = 32 & this.f;
|
|
130
|
+
this.f &= -33;
|
|
131
|
+
try {
|
|
132
|
+
i2(r2);
|
|
133
|
+
} finally {
|
|
134
|
+
this.f |= n2;
|
|
75
135
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
d.prototype.valueOf = function() {
|
|
139
|
+
return this.value;
|
|
140
|
+
};
|
|
141
|
+
d.prototype.toString = function() {
|
|
142
|
+
return this.value + "";
|
|
143
|
+
};
|
|
144
|
+
d.prototype.toJSON = function() {
|
|
145
|
+
return this.value;
|
|
146
|
+
};
|
|
147
|
+
d.prototype.peek = function() {
|
|
148
|
+
return this.v;
|
|
149
|
+
};
|
|
150
|
+
Object.defineProperty(d.prototype, "value", { get: function() {
|
|
151
|
+
var i2 = c(this);
|
|
152
|
+
if (void 0 !== i2)
|
|
153
|
+
i2.i = this.i;
|
|
154
|
+
return this.v;
|
|
155
|
+
}, set: function(t2) {
|
|
156
|
+
if (o instanceof _)
|
|
157
|
+
!function() {
|
|
158
|
+
throw new Error("Computed cannot have side-effects");
|
|
159
|
+
}();
|
|
160
|
+
if (t2 !== this.v) {
|
|
161
|
+
if (e > 100)
|
|
162
|
+
i();
|
|
163
|
+
this.v = t2;
|
|
164
|
+
this.i++;
|
|
165
|
+
u++;
|
|
166
|
+
v++;
|
|
167
|
+
try {
|
|
168
|
+
for (var n2 = this.t; void 0 !== n2; n2 = n2.x)
|
|
169
|
+
n2.t.N();
|
|
170
|
+
} finally {
|
|
171
|
+
r();
|
|
81
172
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
173
|
+
}
|
|
174
|
+
} });
|
|
175
|
+
function a(i2) {
|
|
176
|
+
return new d(i2);
|
|
177
|
+
}
|
|
178
|
+
function l(i2) {
|
|
179
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n)
|
|
180
|
+
if (t2.S.i !== t2.i || !t2.S.h() || t2.S.i !== t2.i)
|
|
88
181
|
return true;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
function y(i2) {
|
|
185
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n) {
|
|
186
|
+
var r2 = t2.S.n;
|
|
187
|
+
if (void 0 !== r2)
|
|
188
|
+
t2.r = r2;
|
|
189
|
+
t2.S.n = t2;
|
|
190
|
+
t2.i = -1;
|
|
191
|
+
if (void 0 === t2.n) {
|
|
192
|
+
i2.s = t2;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function w(i2) {
|
|
198
|
+
var t2 = i2.s, r2 = void 0;
|
|
199
|
+
while (void 0 !== t2) {
|
|
200
|
+
var n2 = t2.p;
|
|
201
|
+
if (-1 === t2.i) {
|
|
202
|
+
t2.S.U(t2);
|
|
203
|
+
if (void 0 !== n2)
|
|
204
|
+
n2.n = t2.n;
|
|
205
|
+
if (void 0 !== t2.n)
|
|
206
|
+
t2.n.p = n2;
|
|
207
|
+
} else
|
|
208
|
+
r2 = t2;
|
|
209
|
+
t2.S.n = t2.r;
|
|
210
|
+
if (void 0 !== t2.r)
|
|
211
|
+
t2.r = void 0;
|
|
212
|
+
t2 = n2;
|
|
213
|
+
}
|
|
214
|
+
i2.s = r2;
|
|
215
|
+
}
|
|
216
|
+
function _(i2) {
|
|
217
|
+
d.call(this, void 0);
|
|
218
|
+
this.x = i2;
|
|
219
|
+
this.s = void 0;
|
|
220
|
+
this.g = u - 1;
|
|
221
|
+
this.f = 4;
|
|
222
|
+
}
|
|
223
|
+
(_.prototype = new d()).h = function() {
|
|
224
|
+
this.f &= -3;
|
|
225
|
+
if (1 & this.f)
|
|
226
|
+
return false;
|
|
227
|
+
if (32 == (36 & this.f))
|
|
95
228
|
return true;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
229
|
+
this.f &= -5;
|
|
230
|
+
if (this.g === u)
|
|
231
|
+
return true;
|
|
232
|
+
this.g = u;
|
|
233
|
+
this.f |= 1;
|
|
234
|
+
if (this.i > 0 && !l(this)) {
|
|
235
|
+
this.f &= -2;
|
|
100
236
|
return true;
|
|
101
237
|
}
|
|
238
|
+
var i2 = o;
|
|
239
|
+
try {
|
|
240
|
+
y(this);
|
|
241
|
+
o = this;
|
|
242
|
+
var t2 = this.x();
|
|
243
|
+
if (16 & this.f || this.v !== t2 || 0 === this.i) {
|
|
244
|
+
this.v = t2;
|
|
245
|
+
this.f &= -17;
|
|
246
|
+
this.i++;
|
|
247
|
+
}
|
|
248
|
+
} catch (i3) {
|
|
249
|
+
this.v = i3;
|
|
250
|
+
this.f |= 16;
|
|
251
|
+
this.i++;
|
|
252
|
+
}
|
|
253
|
+
o = i2;
|
|
254
|
+
w(this);
|
|
255
|
+
this.f &= -2;
|
|
256
|
+
return true;
|
|
102
257
|
};
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
258
|
+
_.prototype.S = function(i2) {
|
|
259
|
+
if (void 0 === this.t) {
|
|
260
|
+
this.f |= 36;
|
|
261
|
+
for (var t2 = this.s; void 0 !== t2; t2 = t2.n)
|
|
262
|
+
t2.S.S(t2);
|
|
263
|
+
}
|
|
264
|
+
d.prototype.S.call(this, i2);
|
|
265
|
+
};
|
|
266
|
+
_.prototype.U = function(i2) {
|
|
267
|
+
if (void 0 !== this.t) {
|
|
268
|
+
d.prototype.U.call(this, i2);
|
|
269
|
+
if (void 0 === this.t) {
|
|
270
|
+
this.f &= -33;
|
|
271
|
+
for (var t2 = this.s; void 0 !== t2; t2 = t2.n)
|
|
272
|
+
t2.S.U(t2);
|
|
117
273
|
}
|
|
118
274
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
currentFx = call;
|
|
126
|
-
fn();
|
|
127
|
-
currentFx = prev;
|
|
128
|
-
};
|
|
129
|
-
call();
|
|
130
|
-
return call;
|
|
131
|
-
};
|
|
132
|
-
var planUpdate = () => {
|
|
133
|
-
if (!pendingUpdate) {
|
|
134
|
-
pendingUpdate = true;
|
|
135
|
-
queueMicrotask(() => {
|
|
136
|
-
for (let fx2 of batch)
|
|
137
|
-
fx2.call();
|
|
138
|
-
batch.clear();
|
|
139
|
-
pendingUpdate = false;
|
|
140
|
-
});
|
|
275
|
+
};
|
|
276
|
+
_.prototype.N = function() {
|
|
277
|
+
if (!(2 & this.f)) {
|
|
278
|
+
this.f |= 6;
|
|
279
|
+
for (var i2 = this.t; void 0 !== i2; i2 = i2.x)
|
|
280
|
+
i2.t.N();
|
|
141
281
|
}
|
|
142
282
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
283
|
+
_.prototype.peek = function() {
|
|
284
|
+
if (!this.h())
|
|
285
|
+
i();
|
|
286
|
+
if (16 & this.f)
|
|
287
|
+
throw this.v;
|
|
288
|
+
return this.v;
|
|
289
|
+
};
|
|
290
|
+
Object.defineProperty(_.prototype, "value", { get: function() {
|
|
291
|
+
if (1 & this.f)
|
|
292
|
+
i();
|
|
293
|
+
var t2 = c(this);
|
|
294
|
+
this.h();
|
|
295
|
+
if (void 0 !== t2)
|
|
296
|
+
t2.i = this.i;
|
|
297
|
+
if (16 & this.f)
|
|
298
|
+
throw this.v;
|
|
299
|
+
return this.v;
|
|
300
|
+
} });
|
|
301
|
+
function p(i2) {
|
|
302
|
+
return new _(i2);
|
|
303
|
+
}
|
|
304
|
+
function g(i2) {
|
|
305
|
+
var t2 = i2.u;
|
|
306
|
+
i2.u = void 0;
|
|
307
|
+
if ("function" == typeof t2) {
|
|
308
|
+
v++;
|
|
309
|
+
var n2 = o;
|
|
310
|
+
o = void 0;
|
|
311
|
+
try {
|
|
312
|
+
t2();
|
|
313
|
+
} catch (t3) {
|
|
314
|
+
i2.f &= -2;
|
|
315
|
+
i2.f |= 8;
|
|
316
|
+
b(i2);
|
|
317
|
+
throw t3;
|
|
318
|
+
} finally {
|
|
319
|
+
o = n2;
|
|
320
|
+
r();
|
|
321
|
+
}
|
|
152
322
|
}
|
|
153
|
-
|
|
154
|
-
|
|
323
|
+
}
|
|
324
|
+
function b(i2) {
|
|
325
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n)
|
|
326
|
+
t2.S.U(t2);
|
|
327
|
+
i2.x = void 0;
|
|
328
|
+
i2.s = void 0;
|
|
329
|
+
g(i2);
|
|
330
|
+
}
|
|
331
|
+
function x(i2) {
|
|
332
|
+
if (o !== this)
|
|
333
|
+
throw new Error("Out-of-order effect");
|
|
334
|
+
w(this);
|
|
335
|
+
o = i2;
|
|
336
|
+
this.f &= -2;
|
|
337
|
+
if (8 & this.f)
|
|
338
|
+
b(this);
|
|
339
|
+
r();
|
|
340
|
+
}
|
|
341
|
+
function E(i2) {
|
|
342
|
+
this.x = i2;
|
|
343
|
+
this.u = void 0;
|
|
344
|
+
this.s = void 0;
|
|
345
|
+
this.o = void 0;
|
|
346
|
+
this.f = 32;
|
|
347
|
+
}
|
|
348
|
+
E.prototype.c = function() {
|
|
349
|
+
var i2 = this.S();
|
|
350
|
+
try {
|
|
351
|
+
if (8 & this.f)
|
|
352
|
+
return;
|
|
353
|
+
if (void 0 === this.x)
|
|
354
|
+
return;
|
|
355
|
+
var t2 = this.x();
|
|
356
|
+
if ("function" == typeof t2)
|
|
357
|
+
this.u = t2;
|
|
358
|
+
} finally {
|
|
359
|
+
i2();
|
|
155
360
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
361
|
+
};
|
|
362
|
+
E.prototype.S = function() {
|
|
363
|
+
if (1 & this.f)
|
|
364
|
+
i();
|
|
365
|
+
this.f |= 1;
|
|
366
|
+
this.f &= -9;
|
|
367
|
+
g(this);
|
|
368
|
+
y(this);
|
|
369
|
+
v++;
|
|
370
|
+
var t2 = o;
|
|
371
|
+
o = this;
|
|
372
|
+
return x.bind(this, t2);
|
|
373
|
+
};
|
|
374
|
+
E.prototype.N = function() {
|
|
375
|
+
if (!(2 & this.f)) {
|
|
376
|
+
this.f |= 2;
|
|
377
|
+
this.o = f;
|
|
378
|
+
f = this;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
E.prototype.d = function() {
|
|
382
|
+
this.f |= 8;
|
|
383
|
+
if (!(1 & this.f))
|
|
384
|
+
b(this);
|
|
385
|
+
};
|
|
386
|
+
function O(i2) {
|
|
387
|
+
var t2 = new E(i2);
|
|
388
|
+
try {
|
|
389
|
+
t2.c();
|
|
390
|
+
} catch (i3) {
|
|
391
|
+
t2.d();
|
|
392
|
+
throw i3;
|
|
393
|
+
}
|
|
394
|
+
return t2.d.bind(t2);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/state.signals-proxy.js
|
|
398
|
+
var _dispose = Symbol.dispose ||= Symbol("dispose");
|
|
399
|
+
var _signals = Symbol("signals");
|
|
400
|
+
var sandbox = {
|
|
401
|
+
Array,
|
|
402
|
+
Object,
|
|
403
|
+
Number,
|
|
404
|
+
String,
|
|
405
|
+
Boolean,
|
|
406
|
+
Date,
|
|
407
|
+
console,
|
|
408
|
+
window,
|
|
409
|
+
document,
|
|
410
|
+
history,
|
|
411
|
+
navigator,
|
|
412
|
+
location,
|
|
413
|
+
screen,
|
|
414
|
+
localStorage,
|
|
415
|
+
sessionStorage,
|
|
416
|
+
alert,
|
|
417
|
+
prompt,
|
|
418
|
+
confirm,
|
|
419
|
+
fetch,
|
|
420
|
+
performance,
|
|
421
|
+
setTimeout,
|
|
422
|
+
setInterval,
|
|
423
|
+
requestAnimationFrame
|
|
424
|
+
};
|
|
425
|
+
var isObject = (v2) => v2?.constructor === Object;
|
|
426
|
+
var lastProp;
|
|
427
|
+
function createState(values, parent) {
|
|
428
|
+
if (!isObject(values) && !Array.isArray(values))
|
|
429
|
+
return values;
|
|
430
|
+
if (values[_signals] && !parent)
|
|
431
|
+
return values;
|
|
432
|
+
const initSignals = values[_signals];
|
|
433
|
+
const _len = Array.isArray(values) && a((initSignals || values).length), signals = parent ? Object.create((parent = createState(parent))[_signals]) : Array.isArray(values) ? [] : {}, proto = signals.constructor.prototype;
|
|
434
|
+
const state = new Proxy(values, {
|
|
435
|
+
has() {
|
|
436
|
+
return true;
|
|
437
|
+
},
|
|
438
|
+
get(values2, key) {
|
|
439
|
+
if (_len)
|
|
440
|
+
if (key === "length")
|
|
441
|
+
return proto[lastProp] ? _len.peek() : _len.value;
|
|
442
|
+
else
|
|
443
|
+
lastProp = key;
|
|
444
|
+
if (proto[key])
|
|
445
|
+
return proto[key];
|
|
446
|
+
if (key === _signals)
|
|
447
|
+
return signals;
|
|
448
|
+
const s2 = signals[key] || initSignal(key);
|
|
449
|
+
if (s2)
|
|
450
|
+
return s2.value;
|
|
451
|
+
if (parent)
|
|
452
|
+
return parent[key];
|
|
453
|
+
if (sandbox.hasOwnProperty(key))
|
|
454
|
+
return sandbox[key];
|
|
455
|
+
},
|
|
456
|
+
set(values2, key, v2) {
|
|
457
|
+
if (_len) {
|
|
458
|
+
if (key === "length") {
|
|
459
|
+
n(() => {
|
|
460
|
+
for (let i2 = v2, l2 = signals.length; i2 < l2; i2++)
|
|
461
|
+
delete state[i2];
|
|
462
|
+
for (let i2 = signals.length; i2 < v2; i2++)
|
|
463
|
+
state[i2] = null;
|
|
464
|
+
_len.value = signals.length = values2.length = v2;
|
|
465
|
+
});
|
|
466
|
+
return true;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
const s2 = signals[key] || initSignal(key, v2) || a();
|
|
470
|
+
const cur = s2.peek();
|
|
471
|
+
if (v2 === cur)
|
|
472
|
+
;
|
|
473
|
+
else if (s2._set)
|
|
474
|
+
s2._set(v2);
|
|
475
|
+
else if (Array.isArray(v2) && Array.isArray(cur)) {
|
|
476
|
+
s(() => n(() => {
|
|
477
|
+
let i2 = 0, l2 = v2.length;
|
|
478
|
+
for (; i2 < l2; i2++)
|
|
479
|
+
cur[i2] = values2[key][i2] = v2[i2];
|
|
480
|
+
cur.length = l2;
|
|
481
|
+
s2.value = null, s2.value = cur;
|
|
482
|
+
}));
|
|
181
483
|
} else {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
);
|
|
186
|
-
a[wantedElmInOld] = null;
|
|
187
|
-
if (wantedElmInOld > i + 1)
|
|
188
|
-
i++;
|
|
189
|
-
j++;
|
|
484
|
+
if (Array.isArray(cur))
|
|
485
|
+
cur.length = 0;
|
|
486
|
+
s2.value = createState(values2[key] = v2);
|
|
190
487
|
}
|
|
488
|
+
if (_len && key >= _len.peek())
|
|
489
|
+
_len.value = signals.length = values2.length = Number(key) + 1;
|
|
490
|
+
return true;
|
|
491
|
+
},
|
|
492
|
+
deleteProperty(values2, key) {
|
|
493
|
+
if (key in signals)
|
|
494
|
+
signals[key]._del?.(), delete signals[key], delete values2[key];
|
|
495
|
+
return true;
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
for (let key in values)
|
|
499
|
+
values[key], signals[key] = initSignals?.[key] ?? null;
|
|
500
|
+
function initSignal(key) {
|
|
501
|
+
if (values.hasOwnProperty(key)) {
|
|
502
|
+
const desc = Object.getOwnPropertyDescriptor(values, key);
|
|
503
|
+
if (desc?.get) {
|
|
504
|
+
(signals[key] = p(desc.get.bind(state)))._set = desc.set?.bind(state);
|
|
505
|
+
return signals[key];
|
|
506
|
+
}
|
|
507
|
+
return signals[key] = desc.value?.peek ? desc.value : a(createState(desc.value));
|
|
191
508
|
}
|
|
192
509
|
}
|
|
193
|
-
return
|
|
510
|
+
return state;
|
|
194
511
|
}
|
|
195
512
|
|
|
513
|
+
// src/util.js
|
|
514
|
+
var queueMicrotask = Promise.prototype.then.bind(Promise.resolve());
|
|
515
|
+
|
|
196
516
|
// src/directives.js
|
|
197
517
|
var primary = {};
|
|
198
518
|
var secondary = {};
|
|
199
|
-
primary["if"] = (el, expr) => {
|
|
519
|
+
primary["if"] = (el, expr, state) => {
|
|
200
520
|
let holder = document.createTextNode(""), clauses = [parseExpr(el, expr, ":if")], els = [el], cur = el;
|
|
201
521
|
while (cur = el.nextElementSibling) {
|
|
202
522
|
if (cur.hasAttribute(":else")) {
|
|
@@ -214,73 +534,95 @@
|
|
|
214
534
|
break;
|
|
215
535
|
}
|
|
216
536
|
el.replaceWith(cur = holder);
|
|
217
|
-
|
|
218
|
-
let
|
|
219
|
-
if (els[
|
|
537
|
+
const dispose = O(() => {
|
|
538
|
+
let i2 = clauses.findIndex((f2) => f2(state));
|
|
539
|
+
if (els[i2] != cur) {
|
|
220
540
|
;
|
|
221
|
-
(cur[_each] || cur).replaceWith(cur = els[
|
|
222
|
-
sprae(cur,
|
|
541
|
+
(cur[_each] || cur).replaceWith(cur = els[i2] || holder);
|
|
542
|
+
sprae(cur, state);
|
|
223
543
|
}
|
|
544
|
+
});
|
|
545
|
+
return () => {
|
|
546
|
+
for (const el2 of els)
|
|
547
|
+
el2[_dispose]?.();
|
|
548
|
+
dispose();
|
|
224
549
|
};
|
|
225
550
|
};
|
|
226
551
|
var _each = Symbol(":each");
|
|
227
|
-
primary["each"] = (tpl, expr) => {
|
|
552
|
+
primary["each"] = (tpl, expr, state) => {
|
|
228
553
|
let each = parseForExpression(expr);
|
|
229
554
|
if (!each)
|
|
230
555
|
return exprError(new Error(), tpl, expr, ":each");
|
|
556
|
+
const [itemVar, idxVar, itemsExpr] = each;
|
|
231
557
|
const holder = tpl[_each] = document.createTextNode("");
|
|
232
558
|
tpl.replaceWith(holder);
|
|
233
|
-
const evaluate = parseExpr(tpl,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
list = list.map((item, i) => [i + 1, item]);
|
|
249
|
-
else if (typeof list === "object")
|
|
250
|
-
list = Object.entries(list);
|
|
251
|
-
else
|
|
252
|
-
exprError(Error("Bad list value"), tpl, expr, ":each", list);
|
|
253
|
-
let newEls = [], elScopes = [];
|
|
254
|
-
for (let [idx, item] of list) {
|
|
255
|
-
let el, scope, key = itemKey?.({ [each[0]]: item, [each[1]]: idx });
|
|
256
|
-
if (key == null)
|
|
257
|
-
el = tpl.cloneNode(true);
|
|
258
|
-
else
|
|
259
|
-
(el = itemEls.get(key)) || itemEls.set(key, el = tpl.cloneNode(true));
|
|
260
|
-
newEls.push(el);
|
|
261
|
-
if (key == null || !(scope = scopes.get(key))) {
|
|
262
|
-
scope = state({ [each[0]]: item, [refExpr || ""]: null, [each[1]]: idx }, state2);
|
|
263
|
-
if (key != null)
|
|
264
|
-
scopes.set(key, scope);
|
|
265
|
-
} else
|
|
266
|
-
scope[each[0]] = item;
|
|
267
|
-
elScopes.push(scope);
|
|
268
|
-
}
|
|
269
|
-
domdiff_default(holder.parentNode, curEls, newEls, holder);
|
|
270
|
-
curEls = newEls;
|
|
271
|
-
for (let i = 0; i < newEls.length; i++) {
|
|
272
|
-
sprae(newEls[i], elScopes[i]);
|
|
559
|
+
const evaluate = parseExpr(tpl, itemsExpr, ":each");
|
|
560
|
+
let items, prevl = 0, keys2;
|
|
561
|
+
O(() => {
|
|
562
|
+
let newItems = evaluate(state);
|
|
563
|
+
if (!newItems)
|
|
564
|
+
newItems = [];
|
|
565
|
+
else if (typeof newItems === "number") {
|
|
566
|
+
newItems = Array.from({ length: newItems }, (_2, i2) => i2);
|
|
567
|
+
} else if (Array.isArray(newItems))
|
|
568
|
+
;
|
|
569
|
+
else if (typeof newItems === "object") {
|
|
570
|
+
keys2 = Object.keys(newItems);
|
|
571
|
+
newItems = Object.values(newItems);
|
|
572
|
+
} else {
|
|
573
|
+
exprError(Error("Bad items value"), tpl, expr, ":each", newItems);
|
|
273
574
|
}
|
|
274
|
-
|
|
575
|
+
s(() => n(() => {
|
|
576
|
+
if (!items?.[_signals][0]?.peek) {
|
|
577
|
+
for (let i2 = 0, signals = items?.[_signals]; i2 < prevl; i2++)
|
|
578
|
+
signals[i2]?._del();
|
|
579
|
+
items = newItems, items[_signals] ||= {};
|
|
580
|
+
} else {
|
|
581
|
+
let newl = newItems.length, i2 = 0;
|
|
582
|
+
for (; i2 < newl; i2++)
|
|
583
|
+
items[i2] = newItems[i2];
|
|
584
|
+
items.length = newl;
|
|
585
|
+
}
|
|
586
|
+
}));
|
|
587
|
+
return O(() => {
|
|
588
|
+
let newl = newItems.length;
|
|
589
|
+
if (prevl !== newl)
|
|
590
|
+
s(() => n(() => {
|
|
591
|
+
const signals = items[_signals];
|
|
592
|
+
for (let i2 = prevl; i2 < newl; i2++) {
|
|
593
|
+
items[i2];
|
|
594
|
+
const el = tpl.cloneNode(true), scope = createState({
|
|
595
|
+
[itemVar]: signals[i2] ?? items[i2],
|
|
596
|
+
[idxVar]: keys2?.[i2] ?? i2
|
|
597
|
+
}, state);
|
|
598
|
+
holder.before(el);
|
|
599
|
+
sprae(el, scope);
|
|
600
|
+
const { _del } = signals[i2] ||= {};
|
|
601
|
+
signals[i2]._del = () => {
|
|
602
|
+
delete signals[i2];
|
|
603
|
+
_del?.();
|
|
604
|
+
el[_dispose](), el.remove(), delete items[i2];
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
prevl = newl;
|
|
608
|
+
}));
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
return () => n(() => {
|
|
612
|
+
for (let _i of items[_signals])
|
|
613
|
+
_i?._del();
|
|
614
|
+
items.length = 0;
|
|
615
|
+
});
|
|
275
616
|
};
|
|
276
617
|
primary["with"] = (el, expr, rootState) => {
|
|
277
618
|
let evaluate = parseExpr(el, expr, ":with");
|
|
278
619
|
const localState = evaluate(rootState);
|
|
279
|
-
let
|
|
280
|
-
sprae(el,
|
|
620
|
+
let state = createState(localState, rootState);
|
|
621
|
+
sprae(el, state);
|
|
622
|
+
return el[_dispose];
|
|
281
623
|
};
|
|
282
|
-
primary["ref"] = (el, expr,
|
|
283
|
-
|
|
624
|
+
primary["ref"] = (el, expr, state) => {
|
|
625
|
+
state[expr] = el;
|
|
284
626
|
};
|
|
285
627
|
function parseForExpression(expression) {
|
|
286
628
|
let forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
|
|
@@ -300,72 +642,76 @@
|
|
|
300
642
|
];
|
|
301
643
|
return [item, "", items];
|
|
302
644
|
}
|
|
303
|
-
secondary["render"] = (el, expr,
|
|
304
|
-
let evaluate = parseExpr(el, expr, ":render"), tpl = evaluate(
|
|
645
|
+
secondary["render"] = (el, expr, state) => {
|
|
646
|
+
let evaluate = parseExpr(el, expr, ":render"), tpl = evaluate(state);
|
|
305
647
|
if (!tpl)
|
|
306
648
|
exprError(new Error("Template not found"), el, expr, ":render");
|
|
307
649
|
let content = tpl.content.cloneNode(true);
|
|
308
650
|
el.replaceChildren(content);
|
|
309
|
-
sprae(el,
|
|
651
|
+
sprae(el, state);
|
|
652
|
+
return el[_dispose];
|
|
310
653
|
};
|
|
311
|
-
secondary["id"] = (el, expr) => {
|
|
654
|
+
secondary["id"] = (el, expr, state) => {
|
|
312
655
|
let evaluate = parseExpr(el, expr, ":id");
|
|
313
|
-
const update = (
|
|
314
|
-
return (
|
|
656
|
+
const update = (v2) => el.id = v2 || v2 === 0 ? v2 : "";
|
|
657
|
+
return O(() => update(evaluate(state)));
|
|
315
658
|
};
|
|
316
|
-
secondary["class"] = (el, expr) => {
|
|
659
|
+
secondary["class"] = (el, expr, state) => {
|
|
317
660
|
let evaluate = parseExpr(el, expr, ":class");
|
|
318
661
|
let initClassName = el.getAttribute("class");
|
|
319
|
-
return (
|
|
320
|
-
let
|
|
662
|
+
return O(() => {
|
|
663
|
+
let v2 = evaluate(state);
|
|
321
664
|
let className = [initClassName];
|
|
322
|
-
if (
|
|
323
|
-
if (typeof
|
|
324
|
-
className.push(
|
|
325
|
-
else if (Array.isArray(
|
|
326
|
-
className.push(...
|
|
665
|
+
if (v2) {
|
|
666
|
+
if (typeof v2 === "string")
|
|
667
|
+
className.push(v2);
|
|
668
|
+
else if (Array.isArray(v2))
|
|
669
|
+
className.push(...v2);
|
|
327
670
|
else
|
|
328
|
-
className.push(...Object.entries(
|
|
671
|
+
className.push(...Object.entries(v2).map(([k, v3]) => v3 ? k : ""));
|
|
329
672
|
}
|
|
330
673
|
if (className = className.filter(Boolean).join(" "))
|
|
331
674
|
el.setAttribute("class", className);
|
|
332
675
|
else
|
|
333
676
|
el.removeAttribute("class");
|
|
334
|
-
};
|
|
677
|
+
});
|
|
335
678
|
};
|
|
336
|
-
secondary["style"] = (el, expr) => {
|
|
679
|
+
secondary["style"] = (el, expr, state) => {
|
|
337
680
|
let evaluate = parseExpr(el, expr, ":style");
|
|
338
681
|
let initStyle = el.getAttribute("style") || "";
|
|
339
682
|
if (!initStyle.endsWith(";"))
|
|
340
683
|
initStyle += "; ";
|
|
341
|
-
return (
|
|
342
|
-
let
|
|
343
|
-
if (typeof
|
|
344
|
-
el.setAttribute("style", initStyle +
|
|
684
|
+
return O(() => {
|
|
685
|
+
let v2 = evaluate(state);
|
|
686
|
+
if (typeof v2 === "string")
|
|
687
|
+
el.setAttribute("style", initStyle + v2);
|
|
345
688
|
else {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
689
|
+
s(() => {
|
|
690
|
+
el.setAttribute("style", initStyle);
|
|
691
|
+
for (let k in v2)
|
|
692
|
+
if (typeof v2[k] !== "symbol")
|
|
693
|
+
el.style.setProperty(k, v2[k]);
|
|
694
|
+
});
|
|
349
695
|
}
|
|
350
|
-
};
|
|
696
|
+
});
|
|
351
697
|
};
|
|
352
|
-
secondary["text"] = (el, expr) => {
|
|
698
|
+
secondary["text"] = (el, expr, state) => {
|
|
353
699
|
let evaluate = parseExpr(el, expr, ":text");
|
|
354
|
-
return (
|
|
355
|
-
let value = evaluate(
|
|
700
|
+
return O(() => {
|
|
701
|
+
let value = evaluate(state);
|
|
356
702
|
el.textContent = value == null ? "" : value;
|
|
357
|
-
};
|
|
703
|
+
});
|
|
358
704
|
};
|
|
359
|
-
secondary[""] = (el, expr) => {
|
|
705
|
+
secondary[""] = (el, expr, state) => {
|
|
360
706
|
let evaluate = parseExpr(el, expr, ":");
|
|
361
707
|
if (evaluate)
|
|
362
|
-
return (
|
|
363
|
-
let value = evaluate(
|
|
708
|
+
return O(() => {
|
|
709
|
+
let value = evaluate(state);
|
|
364
710
|
for (let key in value)
|
|
365
711
|
attr(el, dashcase(key), value[key]);
|
|
366
|
-
};
|
|
712
|
+
});
|
|
367
713
|
};
|
|
368
|
-
secondary["value"] = (el, expr) => {
|
|
714
|
+
secondary["value"] = (el, expr, state) => {
|
|
369
715
|
let evaluate = parseExpr(el, expr, ":value");
|
|
370
716
|
let from, to;
|
|
371
717
|
let update = el.type === "text" || el.type === "" ? (value) => el.setAttribute("value", el.value = value == null ? "" : value) : el.tagName === "TEXTAREA" || el.type === "text" || el.type === "" ? (value) => (from = el.selectionStart, to = el.selectionEnd, el.setAttribute("value", el.value = value == null ? "" : value), from && el.setSelectionRange(from, to)) : el.type === "checkbox" ? (value) => (el.value = value ? "on" : "", attr(el, "checked", value)) : el.type === "select-one" ? (value) => {
|
|
@@ -374,33 +720,41 @@
|
|
|
374
720
|
el.value = value;
|
|
375
721
|
el.selectedOptions[0]?.setAttribute("selected", "");
|
|
376
722
|
} : (value) => el.value = value;
|
|
377
|
-
return (
|
|
723
|
+
return O(() => {
|
|
724
|
+
update(evaluate(state));
|
|
725
|
+
});
|
|
378
726
|
};
|
|
379
|
-
var directives_default = (el, expr,
|
|
727
|
+
var directives_default = (el, expr, state, name) => {
|
|
380
728
|
let evt = name.startsWith("on") && name.slice(2);
|
|
381
729
|
let evaluate = parseExpr(el, expr, ":" + name);
|
|
382
730
|
if (!evaluate)
|
|
383
731
|
return;
|
|
384
|
-
if (evt)
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
732
|
+
if (evt) {
|
|
733
|
+
let off, dispose = O(() => {
|
|
734
|
+
if (off)
|
|
735
|
+
off(), off = null;
|
|
736
|
+
let value = evaluate(state);
|
|
737
|
+
if (value)
|
|
738
|
+
off = on(el, evt, value);
|
|
739
|
+
});
|
|
740
|
+
return () => (off?.(), dispose());
|
|
741
|
+
}
|
|
742
|
+
return O(() => {
|
|
743
|
+
attr(el, name, evaluate(state));
|
|
744
|
+
});
|
|
391
745
|
};
|
|
392
|
-
var on = (el,
|
|
746
|
+
var on = (el, e2, fn) => {
|
|
393
747
|
if (!fn)
|
|
394
748
|
return;
|
|
395
749
|
const ctx = { evt: "", target: el, test: () => true };
|
|
396
|
-
ctx.evt = (
|
|
750
|
+
ctx.evt = (e2.startsWith("on") ? e2.slice(2) : e2).replace(
|
|
397
751
|
/\.(\w+)?-?([-\w]+)?/g,
|
|
398
752
|
(match, mod, param = "") => (ctx.test = mods[mod]?.(ctx, ...param.split("-")) || ctx.test, "")
|
|
399
753
|
);
|
|
400
754
|
const { evt, target, test, defer, stop, prevent, ...opts } = ctx;
|
|
401
755
|
if (defer)
|
|
402
756
|
fn = defer(fn);
|
|
403
|
-
const cb = (
|
|
757
|
+
const cb = (e3) => test(e3) && (stop && e3.stopPropagation(), prevent && e3.preventDefault(), fn.call(target, e3));
|
|
404
758
|
target.addEventListener(evt, cb, opts);
|
|
405
759
|
return () => target.removeEventListener(evt, cb, opts);
|
|
406
760
|
};
|
|
@@ -432,21 +786,21 @@
|
|
|
432
786
|
debounce(ctx, wait) {
|
|
433
787
|
ctx.defer = (fn) => debounce(fn, wait ? Number(wait) || 0 : 108);
|
|
434
788
|
},
|
|
435
|
-
outside: (ctx) => (
|
|
789
|
+
outside: (ctx) => (e2) => {
|
|
436
790
|
let target = ctx.target;
|
|
437
|
-
if (target.contains(
|
|
791
|
+
if (target.contains(e2.target))
|
|
438
792
|
return false;
|
|
439
|
-
if (
|
|
793
|
+
if (e2.target.isConnected === false)
|
|
440
794
|
return false;
|
|
441
795
|
if (target.offsetWidth < 1 && target.offsetHeight < 1)
|
|
442
796
|
return false;
|
|
443
797
|
return true;
|
|
444
798
|
},
|
|
445
|
-
self: (ctx) => (
|
|
446
|
-
ctrl: (ctx, ...param) => (
|
|
447
|
-
shift: (ctx, ...param) => (
|
|
448
|
-
alt: (ctx, ...param) => (
|
|
449
|
-
meta: (ctx, ...param) => (
|
|
799
|
+
self: (ctx) => (e2) => e2.target === ctx.target,
|
|
800
|
+
ctrl: (ctx, ...param) => (e2) => keys.ctrl(e2) && param.every((p2) => keys[p2] ? keys[p2](e2) : e2.key === p2),
|
|
801
|
+
shift: (ctx, ...param) => (e2) => keys.shift(e2) && param.every((p2) => keys[p2] ? keys[p2](e2) : e2.key === p2),
|
|
802
|
+
alt: (ctx, ...param) => (e2) => keys.alt(e2) && param.every((p2) => keys[p2] ? keys[p2](e2) : e2.key === p2),
|
|
803
|
+
meta: (ctx, ...param) => (e2) => keys.meta(e2) && param.every((p2) => keys[p2] ? keys[p2](e2) : e2.key === p2),
|
|
450
804
|
arrow: (ctx) => keys.arrow,
|
|
451
805
|
enter: (ctx) => keys.enter,
|
|
452
806
|
escape: (ctx) => keys.escape,
|
|
@@ -459,69 +813,69 @@
|
|
|
459
813
|
character: (ctx) => keys.character
|
|
460
814
|
};
|
|
461
815
|
var keys = {
|
|
462
|
-
ctrl: (
|
|
463
|
-
shift: (
|
|
464
|
-
alt: (
|
|
465
|
-
meta: (
|
|
466
|
-
arrow: (
|
|
467
|
-
enter: (
|
|
468
|
-
escape: (
|
|
469
|
-
tab: (
|
|
470
|
-
space: (
|
|
471
|
-
backspace: (
|
|
472
|
-
delete: (
|
|
473
|
-
digit: (
|
|
474
|
-
letter: (
|
|
475
|
-
character: (
|
|
816
|
+
ctrl: (e2) => e2.ctrlKey || e2.key === "Control" || e2.key === "Ctrl",
|
|
817
|
+
shift: (e2) => e2.shiftKey || e2.key === "Shift",
|
|
818
|
+
alt: (e2) => e2.altKey || e2.key === "Alt",
|
|
819
|
+
meta: (e2) => e2.metaKey || e2.key === "Meta" || e2.key === "Command",
|
|
820
|
+
arrow: (e2) => e2.key.startsWith("Arrow"),
|
|
821
|
+
enter: (e2) => e2.key === "Enter",
|
|
822
|
+
escape: (e2) => e2.key.startsWith("Esc"),
|
|
823
|
+
tab: (e2) => e2.key === "Tab",
|
|
824
|
+
space: (e2) => e2.key === "\xA0" || e2.key === "Space" || e2.key === " ",
|
|
825
|
+
backspace: (e2) => e2.key === "Backspace",
|
|
826
|
+
delete: (e2) => e2.key === "Delete",
|
|
827
|
+
digit: (e2) => /^\d$/.test(e2.key),
|
|
828
|
+
letter: (e2) => /^[a-zA-Z]$/.test(e2.key),
|
|
829
|
+
character: (e2) => /^\S$/.test(e2.key)
|
|
476
830
|
};
|
|
477
831
|
var throttle = (fn, limit) => {
|
|
478
|
-
let pause, planned, block = (
|
|
832
|
+
let pause, planned, block = (e2) => {
|
|
479
833
|
pause = true;
|
|
480
834
|
setTimeout(() => {
|
|
481
835
|
pause = false;
|
|
482
836
|
if (planned)
|
|
483
|
-
return planned = false, block(
|
|
837
|
+
return planned = false, block(e2), fn(e2);
|
|
484
838
|
}, limit);
|
|
485
839
|
};
|
|
486
|
-
return (
|
|
840
|
+
return (e2) => {
|
|
487
841
|
if (pause)
|
|
488
842
|
return planned = true;
|
|
489
|
-
block(
|
|
490
|
-
return fn(
|
|
843
|
+
block(e2);
|
|
844
|
+
return fn(e2);
|
|
491
845
|
};
|
|
492
846
|
};
|
|
493
847
|
var debounce = (fn, wait) => {
|
|
494
848
|
let timeout;
|
|
495
|
-
return (
|
|
849
|
+
return (e2) => {
|
|
496
850
|
clearTimeout(timeout);
|
|
497
851
|
timeout = setTimeout(() => {
|
|
498
852
|
timeout = null;
|
|
499
|
-
fn(
|
|
853
|
+
fn(e2);
|
|
500
854
|
}, wait);
|
|
501
855
|
};
|
|
502
856
|
};
|
|
503
|
-
var attr = (el, name,
|
|
504
|
-
if (
|
|
857
|
+
var attr = (el, name, v2) => {
|
|
858
|
+
if (v2 == null || v2 === false)
|
|
505
859
|
el.removeAttribute(name);
|
|
506
860
|
else
|
|
507
|
-
el.setAttribute(name,
|
|
861
|
+
el.setAttribute(name, v2 === true ? "" : typeof v2 === "number" || typeof v2 === "string" ? v2 : "");
|
|
508
862
|
};
|
|
509
863
|
var evaluatorMemo = {};
|
|
510
864
|
function parseExpr(el, expression, dir) {
|
|
511
865
|
let evaluate = evaluatorMemo[expression];
|
|
512
866
|
if (!evaluate) {
|
|
513
867
|
try {
|
|
514
|
-
evaluate = evaluatorMemo[expression] = new Function(`__scope`, `with (__scope) { return ${expression.trim()} };`);
|
|
515
|
-
} catch (
|
|
516
|
-
return exprError(
|
|
868
|
+
evaluate = evaluatorMemo[expression] = new Function(`__scope`, `with (__scope) { let __; return ${expression.trim()} };`);
|
|
869
|
+
} catch (e2) {
|
|
870
|
+
return exprError(e2, el, expression, dir);
|
|
517
871
|
}
|
|
518
872
|
}
|
|
519
|
-
return (
|
|
873
|
+
return (state) => {
|
|
520
874
|
let result;
|
|
521
875
|
try {
|
|
522
|
-
result = evaluate.call(el,
|
|
523
|
-
} catch (
|
|
524
|
-
return exprError(
|
|
876
|
+
result = evaluate.call(el, state);
|
|
877
|
+
} catch (e2) {
|
|
878
|
+
return exprError(e2, el, expression, dir);
|
|
525
879
|
}
|
|
526
880
|
return result;
|
|
527
881
|
};
|
|
@@ -548,16 +902,16 @@ ${directive}=${expression ? `"${expression}"
|
|
|
548
902
|
if (!container.children)
|
|
549
903
|
return;
|
|
550
904
|
if (memo.has(container))
|
|
551
|
-
return Object.assign(memo.get(container), values);
|
|
552
|
-
const
|
|
553
|
-
const
|
|
905
|
+
return n(() => Object.assign(memo.get(container), values));
|
|
906
|
+
const state = createState(values || {});
|
|
907
|
+
const disposes = [];
|
|
554
908
|
const init = (el, parent = el.parentNode) => {
|
|
555
909
|
for (let name in primary) {
|
|
556
910
|
let attrName = ":" + name;
|
|
557
911
|
if (el.hasAttribute?.(attrName)) {
|
|
558
912
|
let expr = el.getAttribute(attrName);
|
|
559
913
|
el.removeAttribute(attrName);
|
|
560
|
-
|
|
914
|
+
disposes.push(primary[name](el, expr, state, name));
|
|
561
915
|
if (memo.has(el))
|
|
562
916
|
return;
|
|
563
917
|
if (el.parentNode !== parent)
|
|
@@ -565,8 +919,8 @@ ${directive}=${expression ? `"${expression}"
|
|
|
565
919
|
}
|
|
566
920
|
}
|
|
567
921
|
if (el.attributes) {
|
|
568
|
-
for (let
|
|
569
|
-
let attr2 = el.attributes[
|
|
922
|
+
for (let i2 = 0; i2 < el.attributes.length; ) {
|
|
923
|
+
let attr2 = el.attributes[i2], prefix = attr2.name[0];
|
|
570
924
|
if (prefix === ":" || prefix === "@") {
|
|
571
925
|
el.removeAttribute(attr2.name);
|
|
572
926
|
let expr = prefix === "@" ? `${attr2.value.includes("await") ? "async" : ""} event=>{${attr2.value}}` : attr2.value, names = attr2.name.slice(1).split(prefix);
|
|
@@ -574,29 +928,30 @@ ${directive}=${expression ? `"${expression}"
|
|
|
574
928
|
if (prefix === "@")
|
|
575
929
|
name = `on` + name;
|
|
576
930
|
let dir = secondary[name] || directives_default;
|
|
577
|
-
|
|
931
|
+
disposes.push(dir(el, expr, state, name));
|
|
578
932
|
}
|
|
579
933
|
} else
|
|
580
|
-
|
|
934
|
+
i2++;
|
|
581
935
|
}
|
|
582
936
|
}
|
|
583
|
-
for (let
|
|
937
|
+
for (let i2 = 0, child; child = el.children[i2]; i2++) {
|
|
584
938
|
if (init(child, el) === false)
|
|
585
|
-
|
|
939
|
+
i2--;
|
|
586
940
|
}
|
|
587
941
|
};
|
|
588
942
|
init(container);
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
943
|
+
if (memo.has(container))
|
|
944
|
+
return state;
|
|
945
|
+
memo.set(container, state);
|
|
946
|
+
if (disposes.length)
|
|
947
|
+
Object.defineProperty(container, _dispose, {
|
|
948
|
+
value: () => {
|
|
949
|
+
while (disposes.length)
|
|
950
|
+
disposes.shift()?.();
|
|
951
|
+
memo.delete(container);
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
return state;
|
|
600
955
|
}
|
|
601
956
|
|
|
602
957
|
// src/index.js
|