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