sprae 2.0.0 → 2.1.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/examples/todomvc.html +100 -0
- package/package.json +3 -2
- package/plan.md +9 -1
- package/r&d.md +51 -7
- package/readme.md +38 -16
- package/sprae.js +208 -177
- package/sprae.js.map +7 -0
- package/sprae.min.js +1 -1
- package/src/core.js +16 -8
- package/src/directives.js +76 -52
- package/src/index.js +1 -1
- package/test/index.html +1 -1
- package/test/test.js +46 -4
- package/src/directives/each.js +0 -53
package/sprae.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// node_modules/@preact/signals-core/dist/signals-core.module.js
|
|
2
|
-
function
|
|
2
|
+
function i() {
|
|
3
3
|
throw new Error("Cycle detected");
|
|
4
4
|
}
|
|
5
5
|
function t() {
|
|
6
6
|
if (!(n > 1)) {
|
|
7
|
-
var
|
|
7
|
+
var i2, t2 = false;
|
|
8
8
|
while (void 0 !== r) {
|
|
9
9
|
var h2 = r;
|
|
10
10
|
r = void 0;
|
|
@@ -18,7 +18,7 @@ function t() {
|
|
|
18
18
|
h2.c();
|
|
19
19
|
} catch (h3) {
|
|
20
20
|
if (!t2) {
|
|
21
|
-
|
|
21
|
+
i2 = h3;
|
|
22
22
|
t2 = true;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -28,16 +28,16 @@ function t() {
|
|
|
28
28
|
s = 0;
|
|
29
29
|
n--;
|
|
30
30
|
if (t2)
|
|
31
|
-
throw
|
|
31
|
+
throw i2;
|
|
32
32
|
} else
|
|
33
33
|
n--;
|
|
34
34
|
}
|
|
35
|
-
function h(
|
|
35
|
+
function h(i2) {
|
|
36
36
|
if (n > 0)
|
|
37
|
-
return
|
|
37
|
+
return i2();
|
|
38
38
|
n++;
|
|
39
39
|
try {
|
|
40
|
-
return
|
|
40
|
+
return i2();
|
|
41
41
|
} finally {
|
|
42
42
|
t();
|
|
43
43
|
}
|
|
@@ -47,14 +47,14 @@ var r = void 0;
|
|
|
47
47
|
var n = 0;
|
|
48
48
|
var s = 0;
|
|
49
49
|
var f = 0;
|
|
50
|
-
function v(
|
|
50
|
+
function v(i2) {
|
|
51
51
|
if (void 0 !== o) {
|
|
52
|
-
var t2 =
|
|
52
|
+
var t2 = i2.n;
|
|
53
53
|
if (void 0 === t2 || t2.t !== o) {
|
|
54
|
-
o.s = t2 = { i: 0, S:
|
|
55
|
-
|
|
54
|
+
o.s = t2 = { i: 0, S: i2, p: void 0, n: o.s, t: o, e: void 0, x: void 0, r: t2 };
|
|
55
|
+
i2.n = t2;
|
|
56
56
|
if (32 & o.f)
|
|
57
|
-
|
|
57
|
+
i2.S(t2);
|
|
58
58
|
return t2;
|
|
59
59
|
} else if (-1 === t2.i) {
|
|
60
60
|
t2.i = 0;
|
|
@@ -71,8 +71,8 @@ function v(i3) {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
function e(
|
|
75
|
-
this.v =
|
|
74
|
+
function e(i2) {
|
|
75
|
+
this.v = i2;
|
|
76
76
|
this.i = 0;
|
|
77
77
|
this.n = void 0;
|
|
78
78
|
this.t = void 0;
|
|
@@ -80,34 +80,34 @@ function e(i3) {
|
|
|
80
80
|
e.prototype.h = function() {
|
|
81
81
|
return true;
|
|
82
82
|
};
|
|
83
|
-
e.prototype.S = function(
|
|
84
|
-
if (this.t !==
|
|
85
|
-
|
|
83
|
+
e.prototype.S = function(i2) {
|
|
84
|
+
if (this.t !== i2 && void 0 === i2.e) {
|
|
85
|
+
i2.x = this.t;
|
|
86
86
|
if (void 0 !== this.t)
|
|
87
|
-
this.t.e =
|
|
88
|
-
this.t =
|
|
87
|
+
this.t.e = i2;
|
|
88
|
+
this.t = i2;
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
|
-
e.prototype.U = function(
|
|
92
|
-
var t2 =
|
|
91
|
+
e.prototype.U = function(i2) {
|
|
92
|
+
var t2 = i2.e, h2 = i2.x;
|
|
93
93
|
if (void 0 !== t2) {
|
|
94
94
|
t2.x = h2;
|
|
95
|
-
|
|
95
|
+
i2.e = void 0;
|
|
96
96
|
}
|
|
97
97
|
if (void 0 !== h2) {
|
|
98
98
|
h2.e = t2;
|
|
99
|
-
|
|
99
|
+
i2.x = void 0;
|
|
100
100
|
}
|
|
101
|
-
if (
|
|
101
|
+
if (i2 === this.t)
|
|
102
102
|
this.t = h2;
|
|
103
103
|
};
|
|
104
|
-
e.prototype.subscribe = function(
|
|
104
|
+
e.prototype.subscribe = function(i2) {
|
|
105
105
|
var t2 = this;
|
|
106
106
|
return b(function() {
|
|
107
107
|
var h2 = t2.value, o2 = 32 & this.f;
|
|
108
108
|
this.f &= -33;
|
|
109
109
|
try {
|
|
110
|
-
|
|
110
|
+
i2(h2);
|
|
111
111
|
} finally {
|
|
112
112
|
this.f |= o2;
|
|
113
113
|
}
|
|
@@ -123,14 +123,14 @@ e.prototype.peek = function() {
|
|
|
123
123
|
return this.v;
|
|
124
124
|
};
|
|
125
125
|
Object.defineProperty(e.prototype, "value", { get: function() {
|
|
126
|
-
var
|
|
127
|
-
if (void 0 !==
|
|
128
|
-
|
|
126
|
+
var i2 = v(this);
|
|
127
|
+
if (void 0 !== i2)
|
|
128
|
+
i2.i = this.i;
|
|
129
129
|
return this.v;
|
|
130
130
|
}, set: function(h2) {
|
|
131
131
|
if (h2 !== this.v) {
|
|
132
132
|
if (s > 100)
|
|
133
|
-
|
|
133
|
+
i();
|
|
134
134
|
this.v = h2;
|
|
135
135
|
this.i++;
|
|
136
136
|
f++;
|
|
@@ -143,17 +143,17 @@ Object.defineProperty(e.prototype, "value", { get: function() {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
} });
|
|
146
|
-
function u(
|
|
147
|
-
return new e(
|
|
146
|
+
function u(i2) {
|
|
147
|
+
return new e(i2);
|
|
148
148
|
}
|
|
149
|
-
function d(
|
|
150
|
-
for (var t2 =
|
|
149
|
+
function d(i2) {
|
|
150
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n)
|
|
151
151
|
if (t2.S.i !== t2.i || !t2.S.h() || t2.S.i !== t2.i)
|
|
152
152
|
return true;
|
|
153
153
|
return false;
|
|
154
154
|
}
|
|
155
|
-
function c(
|
|
156
|
-
for (var t2 =
|
|
155
|
+
function c(i2) {
|
|
156
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n) {
|
|
157
157
|
var h2 = t2.S.n;
|
|
158
158
|
if (void 0 !== h2)
|
|
159
159
|
t2.r = h2;
|
|
@@ -161,8 +161,8 @@ function c(i3) {
|
|
|
161
161
|
t2.i = -1;
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
function a(
|
|
165
|
-
var t2 =
|
|
164
|
+
function a(i2) {
|
|
165
|
+
var t2 = i2.s, h2 = void 0;
|
|
166
166
|
while (void 0 !== t2) {
|
|
167
167
|
var o2 = t2.n;
|
|
168
168
|
if (-1 === t2.i) {
|
|
@@ -180,11 +180,11 @@ function a(i3) {
|
|
|
180
180
|
t2.r = void 0;
|
|
181
181
|
t2 = o2;
|
|
182
182
|
}
|
|
183
|
-
|
|
183
|
+
i2.s = h2;
|
|
184
184
|
}
|
|
185
|
-
function l(
|
|
185
|
+
function l(i2) {
|
|
186
186
|
e.call(this, void 0);
|
|
187
|
-
this.x =
|
|
187
|
+
this.x = i2;
|
|
188
188
|
this.s = void 0;
|
|
189
189
|
this.g = f - 1;
|
|
190
190
|
this.f = 4;
|
|
@@ -204,7 +204,7 @@ function l(i3) {
|
|
|
204
204
|
this.f &= -2;
|
|
205
205
|
return true;
|
|
206
206
|
}
|
|
207
|
-
var
|
|
207
|
+
var i2 = o;
|
|
208
208
|
try {
|
|
209
209
|
c(this);
|
|
210
210
|
o = this;
|
|
@@ -214,26 +214,26 @@ function l(i3) {
|
|
|
214
214
|
this.f &= -17;
|
|
215
215
|
this.i++;
|
|
216
216
|
}
|
|
217
|
-
} catch (
|
|
218
|
-
this.v =
|
|
217
|
+
} catch (i3) {
|
|
218
|
+
this.v = i3;
|
|
219
219
|
this.f |= 16;
|
|
220
220
|
this.i++;
|
|
221
221
|
}
|
|
222
|
-
o =
|
|
222
|
+
o = i2;
|
|
223
223
|
a(this);
|
|
224
224
|
this.f &= -2;
|
|
225
225
|
return true;
|
|
226
226
|
};
|
|
227
|
-
l.prototype.S = function(
|
|
227
|
+
l.prototype.S = function(i2) {
|
|
228
228
|
if (void 0 === this.t) {
|
|
229
229
|
this.f |= 36;
|
|
230
230
|
for (var t2 = this.s; void 0 !== t2; t2 = t2.n)
|
|
231
231
|
t2.S.S(t2);
|
|
232
232
|
}
|
|
233
|
-
e.prototype.S.call(this,
|
|
233
|
+
e.prototype.S.call(this, i2);
|
|
234
234
|
};
|
|
235
|
-
l.prototype.U = function(
|
|
236
|
-
e.prototype.U.call(this,
|
|
235
|
+
l.prototype.U = function(i2) {
|
|
236
|
+
e.prototype.U.call(this, i2);
|
|
237
237
|
if (void 0 === this.t) {
|
|
238
238
|
this.f &= -33;
|
|
239
239
|
for (var t2 = this.s; void 0 !== t2; t2 = t2.n)
|
|
@@ -243,20 +243,20 @@ l.prototype.U = function(i3) {
|
|
|
243
243
|
l.prototype.N = function() {
|
|
244
244
|
if (!(2 & this.f)) {
|
|
245
245
|
this.f |= 6;
|
|
246
|
-
for (var
|
|
247
|
-
|
|
246
|
+
for (var i2 = this.t; void 0 !== i2; i2 = i2.x)
|
|
247
|
+
i2.t.N();
|
|
248
248
|
}
|
|
249
249
|
};
|
|
250
250
|
l.prototype.peek = function() {
|
|
251
251
|
if (!this.h())
|
|
252
|
-
|
|
252
|
+
i();
|
|
253
253
|
if (16 & this.f)
|
|
254
254
|
throw this.v;
|
|
255
255
|
return this.v;
|
|
256
256
|
};
|
|
257
257
|
Object.defineProperty(l.prototype, "value", { get: function() {
|
|
258
258
|
if (1 & this.f)
|
|
259
|
-
|
|
259
|
+
i();
|
|
260
260
|
var t2 = v(this);
|
|
261
261
|
this.h();
|
|
262
262
|
if (void 0 !== t2)
|
|
@@ -265,12 +265,12 @@ Object.defineProperty(l.prototype, "value", { get: function() {
|
|
|
265
265
|
throw this.v;
|
|
266
266
|
return this.v;
|
|
267
267
|
} });
|
|
268
|
-
function w(
|
|
269
|
-
return new l(
|
|
268
|
+
function w(i2) {
|
|
269
|
+
return new l(i2);
|
|
270
270
|
}
|
|
271
|
-
function y(
|
|
272
|
-
var h2 =
|
|
273
|
-
|
|
271
|
+
function y(i2) {
|
|
272
|
+
var h2 = i2.u;
|
|
273
|
+
i2.u = void 0;
|
|
274
274
|
if ("function" == typeof h2) {
|
|
275
275
|
n++;
|
|
276
276
|
var r2 = o;
|
|
@@ -278,9 +278,9 @@ function y(i3) {
|
|
|
278
278
|
try {
|
|
279
279
|
h2();
|
|
280
280
|
} catch (t2) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
_(
|
|
281
|
+
i2.f &= -2;
|
|
282
|
+
i2.f |= 8;
|
|
283
|
+
_(i2);
|
|
284
284
|
throw t2;
|
|
285
285
|
} finally {
|
|
286
286
|
o = r2;
|
|
@@ -288,42 +288,42 @@ function y(i3) {
|
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
|
-
function _(
|
|
292
|
-
for (var t2 =
|
|
291
|
+
function _(i2) {
|
|
292
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n)
|
|
293
293
|
t2.S.U(t2);
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
y(
|
|
294
|
+
i2.x = void 0;
|
|
295
|
+
i2.s = void 0;
|
|
296
|
+
y(i2);
|
|
297
297
|
}
|
|
298
|
-
function g(
|
|
298
|
+
function g(i2) {
|
|
299
299
|
if (o !== this)
|
|
300
300
|
throw new Error("Out-of-order effect");
|
|
301
301
|
a(this);
|
|
302
|
-
o =
|
|
302
|
+
o = i2;
|
|
303
303
|
this.f &= -2;
|
|
304
304
|
if (8 & this.f)
|
|
305
305
|
_(this);
|
|
306
306
|
t();
|
|
307
307
|
}
|
|
308
|
-
function p(
|
|
309
|
-
this.x =
|
|
308
|
+
function p(i2) {
|
|
309
|
+
this.x = i2;
|
|
310
310
|
this.u = void 0;
|
|
311
311
|
this.s = void 0;
|
|
312
312
|
this.o = void 0;
|
|
313
313
|
this.f = 32;
|
|
314
314
|
}
|
|
315
315
|
p.prototype.c = function() {
|
|
316
|
-
var
|
|
316
|
+
var i2 = this.S();
|
|
317
317
|
try {
|
|
318
318
|
if (!(8 & this.f) && void 0 !== this.x)
|
|
319
319
|
this.u = this.x();
|
|
320
320
|
} finally {
|
|
321
|
-
|
|
321
|
+
i2();
|
|
322
322
|
}
|
|
323
323
|
};
|
|
324
324
|
p.prototype.S = function() {
|
|
325
325
|
if (1 & this.f)
|
|
326
|
-
|
|
326
|
+
i();
|
|
327
327
|
this.f |= 1;
|
|
328
328
|
this.f &= -9;
|
|
329
329
|
y(this);
|
|
@@ -345,8 +345,8 @@ p.prototype.d = function() {
|
|
|
345
345
|
if (!(1 & this.f))
|
|
346
346
|
_(this);
|
|
347
347
|
};
|
|
348
|
-
function b(
|
|
349
|
-
var t2 = new p(
|
|
348
|
+
function b(i2) {
|
|
349
|
+
var t2 = new p(i2);
|
|
350
350
|
t2.c();
|
|
351
351
|
return t2.d.bind(t2);
|
|
352
352
|
}
|
|
@@ -371,7 +371,7 @@ var sube_default = (target, next, error, complete, stop, unsub) => target && (un
|
|
|
371
371
|
|
|
372
372
|
// node_modules/signal-struct/signal-struct.js
|
|
373
373
|
var isSignal = (v2) => v2 && v2.peek;
|
|
374
|
-
var isStruct = (v2) => v2[_struct];
|
|
374
|
+
var isStruct = (v2) => v2 && v2[_struct];
|
|
375
375
|
var _struct = Symbol("signal-struct");
|
|
376
376
|
function SignalStruct(values) {
|
|
377
377
|
if (isStruct(values))
|
|
@@ -381,21 +381,24 @@ function SignalStruct(values) {
|
|
|
381
381
|
state = {}, signals = {};
|
|
382
382
|
for (let key in values)
|
|
383
383
|
signals[key] = defineSignal(state, key, values[key]);
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
384
|
+
Object.defineProperty(state, _struct, { configurable: false, enumerable: false, value: true });
|
|
385
|
+
Object.seal(state);
|
|
386
|
+
return state;
|
|
387
|
+
}
|
|
388
|
+
if (Array.isArray(values)) {
|
|
389
|
+
return values.map((v2) => SignalStruct(v2));
|
|
390
|
+
}
|
|
391
|
+
return values;
|
|
389
392
|
}
|
|
390
393
|
function defineSignal(state, key, value) {
|
|
391
|
-
let isObservable, s2 = isSignal(value) ? value : isObject(value) ? u(SignalStruct(value)) : u((isObservable = observable(value)) ? void 0 : value);
|
|
394
|
+
let isObservable, s2 = isSignal(value) ? value : isObject(value) || Array.isArray(value) ? u(SignalStruct(value)) : u((isObservable = observable(value)) ? void 0 : value);
|
|
392
395
|
if (isObservable)
|
|
393
396
|
sube_default(value, (v2) => s2.value = v2);
|
|
394
397
|
Object.defineProperty(state, key, {
|
|
395
398
|
get() {
|
|
396
399
|
return s2.value;
|
|
397
400
|
},
|
|
398
|
-
set: isSignal(value)
|
|
401
|
+
set: !isSignal(value) && isObject(value) ? (v2) => v2 ? Object.assign(s2.value, v2) : s2.value = SignalStruct(v2) : (v2) => s2.value = SignalStruct(v2),
|
|
399
402
|
enumerable: true,
|
|
400
403
|
configurable: false
|
|
401
404
|
});
|
|
@@ -405,39 +408,6 @@ function isObject(v2) {
|
|
|
405
408
|
return v2 && v2.constructor === Object;
|
|
406
409
|
}
|
|
407
410
|
|
|
408
|
-
// src/core.js
|
|
409
|
-
var memo = /* @__PURE__ */ new WeakMap();
|
|
410
|
-
function sprae(container, values) {
|
|
411
|
-
if (!container.children)
|
|
412
|
-
return;
|
|
413
|
-
if (memo.has(container))
|
|
414
|
-
return memo.get(container);
|
|
415
|
-
values ||= {};
|
|
416
|
-
const state = SignalStruct(values);
|
|
417
|
-
const init = (el2) => {
|
|
418
|
-
let dir, stop;
|
|
419
|
-
if (el2.attributes) {
|
|
420
|
-
for (let i3 = 0; i3 < el2.attributes.length; ) {
|
|
421
|
-
let attr = el2.attributes[i3];
|
|
422
|
-
if (attr.name[0] === ":") {
|
|
423
|
-
dir = directives[attr.name] || directives.default;
|
|
424
|
-
el2.removeAttribute(attr.name);
|
|
425
|
-
if (stop = dir(el2, attr.value, state, attr.name.slice(1)) === false)
|
|
426
|
-
break;
|
|
427
|
-
} else
|
|
428
|
-
i3++;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
if (!stop)
|
|
432
|
-
for (let child of el2.children)
|
|
433
|
-
init(child);
|
|
434
|
-
};
|
|
435
|
-
init(container);
|
|
436
|
-
memo.set(container, state);
|
|
437
|
-
return state;
|
|
438
|
-
}
|
|
439
|
-
var directives = {};
|
|
440
|
-
|
|
441
411
|
// node_modules/element-props/element-props.js
|
|
442
412
|
var prop = (el2, k, v2) => {
|
|
443
413
|
if (k.startsWith("on"))
|
|
@@ -467,21 +437,21 @@ var dashcase = (str) => {
|
|
|
467
437
|
|
|
468
438
|
// node_modules/swapdom/swap-inflate.js
|
|
469
439
|
var swap = (parent, a2, b2, end = null) => {
|
|
470
|
-
let
|
|
471
|
-
while (
|
|
472
|
-
|
|
473
|
-
while (
|
|
440
|
+
let i2 = 0, cur, next, bi, n2 = b2.length, m = a2.length, { remove, same, insert, replace } = swap;
|
|
441
|
+
while (i2 < n2 && i2 < m && same(a2[i2], b2[i2]))
|
|
442
|
+
i2++;
|
|
443
|
+
while (i2 < n2 && i2 < m && same(b2[n2 - 1], a2[m - 1]))
|
|
474
444
|
end = b2[--m, --n2];
|
|
475
|
-
if (
|
|
476
|
-
while (
|
|
477
|
-
insert(end, b2[
|
|
445
|
+
if (i2 == m)
|
|
446
|
+
while (i2 < n2)
|
|
447
|
+
insert(end, b2[i2++], parent);
|
|
478
448
|
else {
|
|
479
|
-
cur = a2[
|
|
480
|
-
while (
|
|
481
|
-
bi = b2[
|
|
449
|
+
cur = a2[i2];
|
|
450
|
+
while (i2 < n2) {
|
|
451
|
+
bi = b2[i2++], next = cur ? cur.nextSibling : end;
|
|
482
452
|
if (same(cur, bi))
|
|
483
453
|
cur = next;
|
|
484
|
-
else if (
|
|
454
|
+
else if (i2 < n2 && same(b2[i2], next))
|
|
485
455
|
replace(cur, bi, parent), cur = next;
|
|
486
456
|
else
|
|
487
457
|
insert(cur, bi, parent);
|
|
@@ -516,11 +486,26 @@ var primitive_pool_default = (key) => {
|
|
|
516
486
|
};
|
|
517
487
|
|
|
518
488
|
// src/directives.js
|
|
489
|
+
var directives_default = (el2, expr, state, name) => {
|
|
490
|
+
let evaluate = parseExpr(expr, ":" + name, state);
|
|
491
|
+
const update = (value) => prop(el2, name, value);
|
|
492
|
+
b(() => update(evaluate(state)));
|
|
493
|
+
};
|
|
494
|
+
var directives = {};
|
|
495
|
+
var _each = Symbol(":each");
|
|
496
|
+
var _ref = Symbol(":ref");
|
|
519
497
|
directives[":with"] = (el2, expr, rootState) => {
|
|
520
498
|
let evaluate = parseExpr(expr, "with", rootState);
|
|
521
499
|
const params = w(() => Object.assign({}, rootState, evaluate(rootState)));
|
|
522
500
|
let state = sprae(el2, params.value);
|
|
523
501
|
b((values = params.value) => h(() => Object.assign(state, values)));
|
|
502
|
+
return false;
|
|
503
|
+
};
|
|
504
|
+
directives[":ref"] = (el2, expr, state) => {
|
|
505
|
+
if (el2.hasAttribute(":each"))
|
|
506
|
+
return el2[_ref] = expr;
|
|
507
|
+
sprae(el2, Object.assign(Object.create(state), { [expr]: el2 }));
|
|
508
|
+
return false;
|
|
524
509
|
};
|
|
525
510
|
directives[":if"] = (el2, expr, state) => {
|
|
526
511
|
let holder = document.createTextNode(""), clauses = [parseExpr(expr, ":if", state)], els = [el2], cur = el2;
|
|
@@ -541,51 +526,56 @@ directives[":if"] = (el2, expr, state) => {
|
|
|
541
526
|
}
|
|
542
527
|
el2.replaceWith(cur = holder);
|
|
543
528
|
let idx = w(() => clauses.findIndex((f2) => f2(state)));
|
|
544
|
-
b((
|
|
529
|
+
b((i2 = idx.value) => els[i2] != cur && ((cur[_each] || cur).replaceWith(cur = els[i2] || holder), sprae(cur, state)));
|
|
545
530
|
return false;
|
|
546
531
|
};
|
|
547
|
-
var _eachHolder = Symbol(":each");
|
|
548
532
|
directives[":each"] = (tpl, expr, state) => {
|
|
549
533
|
let each = parseForExpression(expr);
|
|
550
534
|
if (!each)
|
|
551
535
|
return exprError(new Error(), expr);
|
|
552
536
|
const getItems = parseExpr(each.items, ":each", state);
|
|
553
|
-
const holder = tpl[
|
|
537
|
+
const holder = tpl[_each] = document.createTextNode("");
|
|
554
538
|
tpl.replaceWith(holder);
|
|
555
539
|
const items = w(() => {
|
|
556
540
|
let list = getItems(state);
|
|
541
|
+
if (!list)
|
|
542
|
+
return [];
|
|
557
543
|
if (typeof list === "number")
|
|
558
|
-
return Array.from({ length: list }, (_2,
|
|
559
|
-
|
|
544
|
+
return Array.from({ length: list }, (_2, i2) => [i2, i2 + 1]);
|
|
545
|
+
if (list.constructor === Object)
|
|
546
|
+
return Object.entries(list);
|
|
547
|
+
if (Array.isArray(list))
|
|
548
|
+
return list.map((item, i2) => [i2 + 1, item]);
|
|
549
|
+
exprError(Error("Bad list value"), each.items, ":each", list);
|
|
560
550
|
});
|
|
561
551
|
const scopes = /* @__PURE__ */ new WeakMap();
|
|
562
552
|
const itemEls = /* @__PURE__ */ new WeakMap();
|
|
563
553
|
let curEls = [];
|
|
564
554
|
b((list = items.value) => {
|
|
565
|
-
if (!list)
|
|
566
|
-
list = [];
|
|
567
555
|
let newEls = [], elScopes = [];
|
|
568
|
-
for (let item of list) {
|
|
569
|
-
let
|
|
570
|
-
let el2 = itemEls.get(
|
|
556
|
+
for (let [idx, item] of list) {
|
|
557
|
+
let itemKey = primitive_pool_default(item);
|
|
558
|
+
let el2 = itemEls.get(itemKey);
|
|
571
559
|
if (!el2) {
|
|
572
560
|
el2 = tpl.cloneNode(true);
|
|
573
|
-
itemEls.set(
|
|
561
|
+
itemEls.set(itemKey, el2);
|
|
574
562
|
}
|
|
575
563
|
newEls.push(el2);
|
|
576
|
-
if (!scopes.has(
|
|
564
|
+
if (!scopes.has(itemKey)) {
|
|
577
565
|
let scope = Object.create(state);
|
|
578
566
|
scope[each.item] = item;
|
|
579
567
|
if (each.index)
|
|
580
|
-
scope[each.index] =
|
|
581
|
-
|
|
568
|
+
scope[each.index] = idx;
|
|
569
|
+
if (tpl[_ref])
|
|
570
|
+
scope[tpl[_ref]] = el2;
|
|
571
|
+
scopes.set(itemKey, scope);
|
|
582
572
|
}
|
|
583
|
-
elScopes.push(scopes.get(
|
|
573
|
+
elScopes.push(scopes.get(itemKey));
|
|
584
574
|
}
|
|
585
575
|
swap_inflate_default(holder.parentNode, curEls, newEls, holder);
|
|
586
576
|
curEls = newEls;
|
|
587
|
-
for (let
|
|
588
|
-
sprae(newEls[
|
|
577
|
+
for (let i2 = 0; i2 < newEls.length; i2++) {
|
|
578
|
+
sprae(newEls[i2], elScopes[i2]);
|
|
589
579
|
}
|
|
590
580
|
});
|
|
591
581
|
return false;
|
|
@@ -609,39 +599,11 @@ function parseForExpression(expression) {
|
|
|
609
599
|
}
|
|
610
600
|
return res;
|
|
611
601
|
}
|
|
612
|
-
directives["
|
|
613
|
-
let evaluate = parseExpr(expr, ":"
|
|
614
|
-
const update = (
|
|
602
|
+
directives[":id"] = (el2, expr, state) => {
|
|
603
|
+
let evaluate = parseExpr(expr, ":id", state);
|
|
604
|
+
const update = (v2) => el2.id = v2 || v2 === 0 ? v2 : "";
|
|
615
605
|
b(() => update(evaluate(state)));
|
|
616
606
|
};
|
|
617
|
-
directives[":aria"] = (el2, expr, state) => {
|
|
618
|
-
let evaluate = parseExpr(expr, ":aria", state);
|
|
619
|
-
const update = (value) => {
|
|
620
|
-
for (let key in value)
|
|
621
|
-
prop(el2, "aria" + key[0].toUpperCase() + key.slice(1), value[key] == null ? null : value[key] + "");
|
|
622
|
-
};
|
|
623
|
-
b(() => update(evaluate(state)));
|
|
624
|
-
};
|
|
625
|
-
directives[":data"] = (el2, expr, state) => {
|
|
626
|
-
let evaluate = parseExpr(expr, ":data", state);
|
|
627
|
-
const value = w(() => evaluate(state));
|
|
628
|
-
b((v2 = value.value) => {
|
|
629
|
-
for (let key in v2)
|
|
630
|
-
el2.dataset[key] = v2[key];
|
|
631
|
-
});
|
|
632
|
-
};
|
|
633
|
-
directives[":on"] = (el2, expr, state) => {
|
|
634
|
-
let evaluate = parseExpr(expr, ":on", state);
|
|
635
|
-
let listeners = w(() => evaluate(state));
|
|
636
|
-
let prevListeners;
|
|
637
|
-
b((values = listeners.value) => {
|
|
638
|
-
for (let evt in prevListeners)
|
|
639
|
-
el2.removeEventListener(evt, prevListeners[evt]);
|
|
640
|
-
prevListeners = values;
|
|
641
|
-
for (let evt in prevListeners)
|
|
642
|
-
el2.addEventListener(evt, prevListeners[evt]);
|
|
643
|
-
});
|
|
644
|
-
};
|
|
645
607
|
directives[":"] = (el2, expr, state) => {
|
|
646
608
|
let evaluate = parseExpr(expr, ":", state);
|
|
647
609
|
const update = (value) => {
|
|
@@ -668,6 +630,34 @@ directives[":value"] = (el2, expr, state) => {
|
|
|
668
630
|
};
|
|
669
631
|
b(() => update(evaluate(state)));
|
|
670
632
|
};
|
|
633
|
+
directives[":on"] = (el2, expr, state) => {
|
|
634
|
+
let evaluate = parseExpr(expr, ":on", state);
|
|
635
|
+
let listeners = w(() => evaluate(state));
|
|
636
|
+
let prevListeners;
|
|
637
|
+
b((values = listeners.value) => {
|
|
638
|
+
for (let evt in prevListeners)
|
|
639
|
+
el2.removeEventListener(evt, prevListeners[evt]);
|
|
640
|
+
prevListeners = values;
|
|
641
|
+
for (let evt in prevListeners)
|
|
642
|
+
el2.addEventListener(evt, prevListeners[evt]);
|
|
643
|
+
});
|
|
644
|
+
};
|
|
645
|
+
directives[":data"] = (el2, expr, state) => {
|
|
646
|
+
let evaluate = parseExpr(expr, ":data", state);
|
|
647
|
+
const value = w(() => evaluate(state));
|
|
648
|
+
b((v2 = value.value) => {
|
|
649
|
+
for (let key in v2)
|
|
650
|
+
el2.dataset[key] = v2[key];
|
|
651
|
+
});
|
|
652
|
+
};
|
|
653
|
+
directives[":aria"] = (el2, expr, state) => {
|
|
654
|
+
let evaluate = parseExpr(expr, ":aria", state);
|
|
655
|
+
const update = (value) => {
|
|
656
|
+
for (let key in value)
|
|
657
|
+
prop(el2, "aria" + key[0].toUpperCase() + key.slice(1), value[key] == null ? null : value[key] + "");
|
|
658
|
+
};
|
|
659
|
+
b(() => update(evaluate(state)));
|
|
660
|
+
};
|
|
671
661
|
var evaluatorMemo = {};
|
|
672
662
|
function parseExpr(expression, dir, scope) {
|
|
673
663
|
if (evaluatorMemo[expression])
|
|
@@ -675,7 +665,7 @@ function parseExpr(expression, dir, scope) {
|
|
|
675
665
|
let rightSideSafeExpression = /^[\n\s]*if.*\(.*\)/.test(expression) || /^(let|const)\s/.test(expression) ? `(() => { ${expression} })()` : expression;
|
|
676
666
|
let evaluate;
|
|
677
667
|
try {
|
|
678
|
-
evaluate = new Function(
|
|
668
|
+
evaluate = new Function(`let result; with (arguments[0]) { result = (${rightSideSafeExpression}) }; return result;`);
|
|
679
669
|
} catch (e2) {
|
|
680
670
|
return exprError(e2, expression, dir, scope);
|
|
681
671
|
}
|
|
@@ -701,9 +691,50 @@ ${dir}=${expression ? `"${expression}"
|
|
|
701
691
|
}, 0);
|
|
702
692
|
}
|
|
703
693
|
|
|
694
|
+
// src/core.js
|
|
695
|
+
var memo = /* @__PURE__ */ new WeakMap();
|
|
696
|
+
function sprae(container, values) {
|
|
697
|
+
if (!container.children)
|
|
698
|
+
return;
|
|
699
|
+
if (memo.has(container))
|
|
700
|
+
return memo.get(container);
|
|
701
|
+
values ||= {};
|
|
702
|
+
const state = SignalStruct(values);
|
|
703
|
+
const init = (el2) => {
|
|
704
|
+
let dir, attr;
|
|
705
|
+
if (el2.attributes) {
|
|
706
|
+
for (let name in directives) {
|
|
707
|
+
if (attr = el2.attributes[name]) {
|
|
708
|
+
dir = directives[name];
|
|
709
|
+
el2.removeAttribute(name);
|
|
710
|
+
if (dir(el2, attr.value, state) === false)
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
for (let i2 = 0; i2 < el2.attributes.length; ) {
|
|
715
|
+
let attr2 = el2.attributes[i2];
|
|
716
|
+
if (attr2.name[0] === ":") {
|
|
717
|
+
el2.removeAttribute(attr2.name);
|
|
718
|
+
if (directives_default(el2, attr2.value, state, attr2.name.slice(1)) === false)
|
|
719
|
+
return;
|
|
720
|
+
} else
|
|
721
|
+
i2++;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
for (let child of el2.children)
|
|
725
|
+
init(child);
|
|
726
|
+
};
|
|
727
|
+
init(container);
|
|
728
|
+
memo.set(container, state);
|
|
729
|
+
return state;
|
|
730
|
+
}
|
|
731
|
+
|
|
704
732
|
// src/index.js
|
|
705
733
|
var src_default = sprae;
|
|
706
734
|
export {
|
|
735
|
+
h as batch,
|
|
736
|
+
w as computed,
|
|
707
737
|
src_default as default,
|
|
708
|
-
|
|
738
|
+
b as effect,
|
|
739
|
+
u as signal
|
|
709
740
|
};
|