sprae 1.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/.github/workflows/node.js.yml +30 -0
- package/examples/todomvc.html +100 -0
- package/package.json +8 -2
- package/plan.md +28 -6
- package/r&d.md +104 -9
- package/readme.md +148 -77
- package/sprae.js +676 -253
- package/sprae.js.map +7 -0
- package/sprae.min.js +1 -1
- package/src/core.js +37 -101
- package/src/directives.js +259 -0
- package/src/index.js +2 -2
- package/test/index.html +5 -2
- package/test/test.js +191 -72
- package/src/directives/aria.js +0 -10
- package/src/directives/common.js +0 -15
- package/src/directives/data.js +0 -10
- package/src/directives/each.js +0 -53
- package/src/directives/if.js +0 -31
- package/src/directives/index.js +0 -11
- package/src/directives/on.js +0 -12
- package/src/directives/prop.js +0 -10
- package/src/directives/text.js +0 -10
- package/src/directives/value.js +0 -26
- package/src/directives/with.js +0 -21
package/sprae.js
CHANGED
|
@@ -1,146 +1,585 @@
|
|
|
1
|
+
// node_modules/@preact/signals-core/dist/signals-core.module.js
|
|
2
|
+
function i() {
|
|
3
|
+
throw new Error("Cycle detected");
|
|
4
|
+
}
|
|
5
|
+
function t() {
|
|
6
|
+
if (!(n > 1)) {
|
|
7
|
+
var i2, t2 = false;
|
|
8
|
+
while (void 0 !== r) {
|
|
9
|
+
var h2 = r;
|
|
10
|
+
r = void 0;
|
|
11
|
+
s++;
|
|
12
|
+
while (void 0 !== h2) {
|
|
13
|
+
var o2 = h2.o;
|
|
14
|
+
h2.o = void 0;
|
|
15
|
+
h2.f &= -3;
|
|
16
|
+
if (!(8 & h2.f) && d(h2))
|
|
17
|
+
try {
|
|
18
|
+
h2.c();
|
|
19
|
+
} catch (h3) {
|
|
20
|
+
if (!t2) {
|
|
21
|
+
i2 = h3;
|
|
22
|
+
t2 = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
h2 = o2;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
s = 0;
|
|
29
|
+
n--;
|
|
30
|
+
if (t2)
|
|
31
|
+
throw i2;
|
|
32
|
+
} else
|
|
33
|
+
n--;
|
|
34
|
+
}
|
|
35
|
+
function h(i2) {
|
|
36
|
+
if (n > 0)
|
|
37
|
+
return i2();
|
|
38
|
+
n++;
|
|
39
|
+
try {
|
|
40
|
+
return i2();
|
|
41
|
+
} finally {
|
|
42
|
+
t();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
var o = void 0;
|
|
46
|
+
var r = void 0;
|
|
47
|
+
var n = 0;
|
|
48
|
+
var s = 0;
|
|
49
|
+
var f = 0;
|
|
50
|
+
function v(i2) {
|
|
51
|
+
if (void 0 !== o) {
|
|
52
|
+
var t2 = i2.n;
|
|
53
|
+
if (void 0 === t2 || t2.t !== o) {
|
|
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
|
+
if (32 & o.f)
|
|
57
|
+
i2.S(t2);
|
|
58
|
+
return t2;
|
|
59
|
+
} else if (-1 === t2.i) {
|
|
60
|
+
t2.i = 0;
|
|
61
|
+
if (void 0 !== t2.p) {
|
|
62
|
+
t2.p.n = t2.n;
|
|
63
|
+
if (void 0 !== t2.n)
|
|
64
|
+
t2.n.p = t2.p;
|
|
65
|
+
t2.p = void 0;
|
|
66
|
+
t2.n = o.s;
|
|
67
|
+
o.s.p = t2;
|
|
68
|
+
o.s = t2;
|
|
69
|
+
}
|
|
70
|
+
return t2;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function e(i2) {
|
|
75
|
+
this.v = i2;
|
|
76
|
+
this.i = 0;
|
|
77
|
+
this.n = void 0;
|
|
78
|
+
this.t = void 0;
|
|
79
|
+
}
|
|
80
|
+
e.prototype.h = function() {
|
|
81
|
+
return true;
|
|
82
|
+
};
|
|
83
|
+
e.prototype.S = function(i2) {
|
|
84
|
+
if (this.t !== i2 && void 0 === i2.e) {
|
|
85
|
+
i2.x = this.t;
|
|
86
|
+
if (void 0 !== this.t)
|
|
87
|
+
this.t.e = i2;
|
|
88
|
+
this.t = i2;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
e.prototype.U = function(i2) {
|
|
92
|
+
var t2 = i2.e, h2 = i2.x;
|
|
93
|
+
if (void 0 !== t2) {
|
|
94
|
+
t2.x = h2;
|
|
95
|
+
i2.e = void 0;
|
|
96
|
+
}
|
|
97
|
+
if (void 0 !== h2) {
|
|
98
|
+
h2.e = t2;
|
|
99
|
+
i2.x = void 0;
|
|
100
|
+
}
|
|
101
|
+
if (i2 === this.t)
|
|
102
|
+
this.t = h2;
|
|
103
|
+
};
|
|
104
|
+
e.prototype.subscribe = function(i2) {
|
|
105
|
+
var t2 = this;
|
|
106
|
+
return b(function() {
|
|
107
|
+
var h2 = t2.value, o2 = 32 & this.f;
|
|
108
|
+
this.f &= -33;
|
|
109
|
+
try {
|
|
110
|
+
i2(h2);
|
|
111
|
+
} finally {
|
|
112
|
+
this.f |= o2;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
e.prototype.valueOf = function() {
|
|
117
|
+
return this.value;
|
|
118
|
+
};
|
|
119
|
+
e.prototype.toString = function() {
|
|
120
|
+
return this.value + "";
|
|
121
|
+
};
|
|
122
|
+
e.prototype.peek = function() {
|
|
123
|
+
return this.v;
|
|
124
|
+
};
|
|
125
|
+
Object.defineProperty(e.prototype, "value", { get: function() {
|
|
126
|
+
var i2 = v(this);
|
|
127
|
+
if (void 0 !== i2)
|
|
128
|
+
i2.i = this.i;
|
|
129
|
+
return this.v;
|
|
130
|
+
}, set: function(h2) {
|
|
131
|
+
if (h2 !== this.v) {
|
|
132
|
+
if (s > 100)
|
|
133
|
+
i();
|
|
134
|
+
this.v = h2;
|
|
135
|
+
this.i++;
|
|
136
|
+
f++;
|
|
137
|
+
n++;
|
|
138
|
+
try {
|
|
139
|
+
for (var o2 = this.t; void 0 !== o2; o2 = o2.x)
|
|
140
|
+
o2.t.N();
|
|
141
|
+
} finally {
|
|
142
|
+
t();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} });
|
|
146
|
+
function u(i2) {
|
|
147
|
+
return new e(i2);
|
|
148
|
+
}
|
|
149
|
+
function d(i2) {
|
|
150
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n)
|
|
151
|
+
if (t2.S.i !== t2.i || !t2.S.h() || t2.S.i !== t2.i)
|
|
152
|
+
return true;
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
function c(i2) {
|
|
156
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n) {
|
|
157
|
+
var h2 = t2.S.n;
|
|
158
|
+
if (void 0 !== h2)
|
|
159
|
+
t2.r = h2;
|
|
160
|
+
t2.S.n = t2;
|
|
161
|
+
t2.i = -1;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function a(i2) {
|
|
165
|
+
var t2 = i2.s, h2 = void 0;
|
|
166
|
+
while (void 0 !== t2) {
|
|
167
|
+
var o2 = t2.n;
|
|
168
|
+
if (-1 === t2.i) {
|
|
169
|
+
t2.S.U(t2);
|
|
170
|
+
t2.n = void 0;
|
|
171
|
+
} else {
|
|
172
|
+
if (void 0 !== h2)
|
|
173
|
+
h2.p = t2;
|
|
174
|
+
t2.p = void 0;
|
|
175
|
+
t2.n = h2;
|
|
176
|
+
h2 = t2;
|
|
177
|
+
}
|
|
178
|
+
t2.S.n = t2.r;
|
|
179
|
+
if (void 0 !== t2.r)
|
|
180
|
+
t2.r = void 0;
|
|
181
|
+
t2 = o2;
|
|
182
|
+
}
|
|
183
|
+
i2.s = h2;
|
|
184
|
+
}
|
|
185
|
+
function l(i2) {
|
|
186
|
+
e.call(this, void 0);
|
|
187
|
+
this.x = i2;
|
|
188
|
+
this.s = void 0;
|
|
189
|
+
this.g = f - 1;
|
|
190
|
+
this.f = 4;
|
|
191
|
+
}
|
|
192
|
+
(l.prototype = new e()).h = function() {
|
|
193
|
+
this.f &= -3;
|
|
194
|
+
if (1 & this.f)
|
|
195
|
+
return false;
|
|
196
|
+
if (32 == (36 & this.f))
|
|
197
|
+
return true;
|
|
198
|
+
this.f &= -5;
|
|
199
|
+
if (this.g === f)
|
|
200
|
+
return true;
|
|
201
|
+
this.g = f;
|
|
202
|
+
this.f |= 1;
|
|
203
|
+
if (this.i > 0 && !d(this)) {
|
|
204
|
+
this.f &= -2;
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
var i2 = o;
|
|
208
|
+
try {
|
|
209
|
+
c(this);
|
|
210
|
+
o = this;
|
|
211
|
+
var t2 = this.x();
|
|
212
|
+
if (16 & this.f || this.v !== t2 || 0 === this.i) {
|
|
213
|
+
this.v = t2;
|
|
214
|
+
this.f &= -17;
|
|
215
|
+
this.i++;
|
|
216
|
+
}
|
|
217
|
+
} catch (i3) {
|
|
218
|
+
this.v = i3;
|
|
219
|
+
this.f |= 16;
|
|
220
|
+
this.i++;
|
|
221
|
+
}
|
|
222
|
+
o = i2;
|
|
223
|
+
a(this);
|
|
224
|
+
this.f &= -2;
|
|
225
|
+
return true;
|
|
226
|
+
};
|
|
227
|
+
l.prototype.S = function(i2) {
|
|
228
|
+
if (void 0 === this.t) {
|
|
229
|
+
this.f |= 36;
|
|
230
|
+
for (var t2 = this.s; void 0 !== t2; t2 = t2.n)
|
|
231
|
+
t2.S.S(t2);
|
|
232
|
+
}
|
|
233
|
+
e.prototype.S.call(this, i2);
|
|
234
|
+
};
|
|
235
|
+
l.prototype.U = function(i2) {
|
|
236
|
+
e.prototype.U.call(this, i2);
|
|
237
|
+
if (void 0 === this.t) {
|
|
238
|
+
this.f &= -33;
|
|
239
|
+
for (var t2 = this.s; void 0 !== t2; t2 = t2.n)
|
|
240
|
+
t2.S.U(t2);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
l.prototype.N = function() {
|
|
244
|
+
if (!(2 & this.f)) {
|
|
245
|
+
this.f |= 6;
|
|
246
|
+
for (var i2 = this.t; void 0 !== i2; i2 = i2.x)
|
|
247
|
+
i2.t.N();
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
l.prototype.peek = function() {
|
|
251
|
+
if (!this.h())
|
|
252
|
+
i();
|
|
253
|
+
if (16 & this.f)
|
|
254
|
+
throw this.v;
|
|
255
|
+
return this.v;
|
|
256
|
+
};
|
|
257
|
+
Object.defineProperty(l.prototype, "value", { get: function() {
|
|
258
|
+
if (1 & this.f)
|
|
259
|
+
i();
|
|
260
|
+
var t2 = v(this);
|
|
261
|
+
this.h();
|
|
262
|
+
if (void 0 !== t2)
|
|
263
|
+
t2.i = this.i;
|
|
264
|
+
if (16 & this.f)
|
|
265
|
+
throw this.v;
|
|
266
|
+
return this.v;
|
|
267
|
+
} });
|
|
268
|
+
function w(i2) {
|
|
269
|
+
return new l(i2);
|
|
270
|
+
}
|
|
271
|
+
function y(i2) {
|
|
272
|
+
var h2 = i2.u;
|
|
273
|
+
i2.u = void 0;
|
|
274
|
+
if ("function" == typeof h2) {
|
|
275
|
+
n++;
|
|
276
|
+
var r2 = o;
|
|
277
|
+
o = void 0;
|
|
278
|
+
try {
|
|
279
|
+
h2();
|
|
280
|
+
} catch (t2) {
|
|
281
|
+
i2.f &= -2;
|
|
282
|
+
i2.f |= 8;
|
|
283
|
+
_(i2);
|
|
284
|
+
throw t2;
|
|
285
|
+
} finally {
|
|
286
|
+
o = r2;
|
|
287
|
+
t();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function _(i2) {
|
|
292
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n)
|
|
293
|
+
t2.S.U(t2);
|
|
294
|
+
i2.x = void 0;
|
|
295
|
+
i2.s = void 0;
|
|
296
|
+
y(i2);
|
|
297
|
+
}
|
|
298
|
+
function g(i2) {
|
|
299
|
+
if (o !== this)
|
|
300
|
+
throw new Error("Out-of-order effect");
|
|
301
|
+
a(this);
|
|
302
|
+
o = i2;
|
|
303
|
+
this.f &= -2;
|
|
304
|
+
if (8 & this.f)
|
|
305
|
+
_(this);
|
|
306
|
+
t();
|
|
307
|
+
}
|
|
308
|
+
function p(i2) {
|
|
309
|
+
this.x = i2;
|
|
310
|
+
this.u = void 0;
|
|
311
|
+
this.s = void 0;
|
|
312
|
+
this.o = void 0;
|
|
313
|
+
this.f = 32;
|
|
314
|
+
}
|
|
315
|
+
p.prototype.c = function() {
|
|
316
|
+
var i2 = this.S();
|
|
317
|
+
try {
|
|
318
|
+
if (!(8 & this.f) && void 0 !== this.x)
|
|
319
|
+
this.u = this.x();
|
|
320
|
+
} finally {
|
|
321
|
+
i2();
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
p.prototype.S = function() {
|
|
325
|
+
if (1 & this.f)
|
|
326
|
+
i();
|
|
327
|
+
this.f |= 1;
|
|
328
|
+
this.f &= -9;
|
|
329
|
+
y(this);
|
|
330
|
+
c(this);
|
|
331
|
+
n++;
|
|
332
|
+
var t2 = o;
|
|
333
|
+
o = this;
|
|
334
|
+
return g.bind(this, t2);
|
|
335
|
+
};
|
|
336
|
+
p.prototype.N = function() {
|
|
337
|
+
if (!(2 & this.f)) {
|
|
338
|
+
this.f |= 2;
|
|
339
|
+
this.o = r;
|
|
340
|
+
r = this;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
p.prototype.d = function() {
|
|
344
|
+
this.f |= 8;
|
|
345
|
+
if (!(1 & this.f))
|
|
346
|
+
_(this);
|
|
347
|
+
};
|
|
348
|
+
function b(i2) {
|
|
349
|
+
var t2 = new p(i2);
|
|
350
|
+
t2.c();
|
|
351
|
+
return t2.d.bind(t2);
|
|
352
|
+
}
|
|
353
|
+
|
|
1
354
|
// node_modules/sube/sube.js
|
|
2
355
|
Symbol.observable ||= Symbol("observable");
|
|
3
356
|
var observable = (arg) => arg && !!(arg[Symbol.observable] || arg[Symbol.asyncIterator] || arg.call && arg.set || arg.subscribe || arg.then);
|
|
4
357
|
var registry = new FinalizationRegistry((unsub) => unsub.call?.());
|
|
5
358
|
var unsubr = (sub) => sub && (() => sub.unsubscribe?.());
|
|
6
|
-
var sube_default = (target, next, error, complete, stop, unsub) => target && (unsub = unsubr((target[Symbol.observable]?.() || target).subscribe?.(next, error, complete)) || target.set && target.call?.(stop, next) || (target.then?.((
|
|
359
|
+
var sube_default = (target, next, error, complete, stop, unsub) => target && (unsub = unsubr((target[Symbol.observable]?.() || target).subscribe?.(next, error, complete)) || target.set && target.call?.(stop, next) || (target.then?.((v2) => (!stop && next(v2), complete?.()), error) || (async (v2) => {
|
|
7
360
|
try {
|
|
8
|
-
for await (
|
|
361
|
+
for await (v2 of target) {
|
|
9
362
|
if (stop)
|
|
10
363
|
return;
|
|
11
|
-
next(
|
|
364
|
+
next(v2);
|
|
12
365
|
}
|
|
13
366
|
complete?.();
|
|
14
367
|
} catch (err) {
|
|
15
368
|
error?.(err);
|
|
16
369
|
}
|
|
17
|
-
})()) && ((
|
|
370
|
+
})()) && ((_2) => stop = 1), registry.register(target, unsub), unsub);
|
|
18
371
|
|
|
19
|
-
//
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
else if (v?.constructor === Object)
|
|
35
|
-
values2[k] = rsube(v);
|
|
36
|
-
else
|
|
37
|
-
values2[k] = v;
|
|
38
|
-
}
|
|
39
|
-
return values2;
|
|
40
|
-
};
|
|
41
|
-
const values = rsube(initScope);
|
|
42
|
-
ready = true;
|
|
43
|
-
for (let name in directives) {
|
|
44
|
-
const sel = `[${name.replace(":", "\\:")}]`, initDirective = directives[name];
|
|
45
|
-
const els = [...el2.querySelectorAll(sel)];
|
|
46
|
-
if (el2.matches?.(sel))
|
|
47
|
-
els.unshift(el2);
|
|
48
|
-
let update2;
|
|
49
|
-
for (let el3 of els)
|
|
50
|
-
if (update2 = initDirective(el3, values))
|
|
51
|
-
updates.push(update2);
|
|
372
|
+
// node_modules/signal-struct/signal-struct.js
|
|
373
|
+
var isSignal = (v2) => v2 && v2.peek;
|
|
374
|
+
var isStruct = (v2) => v2 && v2[_struct];
|
|
375
|
+
var _struct = Symbol("signal-struct");
|
|
376
|
+
function SignalStruct(values) {
|
|
377
|
+
if (isStruct(values))
|
|
378
|
+
return values;
|
|
379
|
+
let state, signals;
|
|
380
|
+
if (isObject(values)) {
|
|
381
|
+
state = {}, signals = {};
|
|
382
|
+
for (let key in values)
|
|
383
|
+
signals[key] = defineSignal(state, key, values[key]);
|
|
384
|
+
Object.defineProperty(state, _struct, { configurable: false, enumerable: false, value: true });
|
|
385
|
+
Object.seal(state);
|
|
386
|
+
return state;
|
|
52
387
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
388
|
+
if (Array.isArray(values)) {
|
|
389
|
+
return values.map((v2) => SignalStruct(v2));
|
|
390
|
+
}
|
|
391
|
+
return values;
|
|
392
|
+
}
|
|
393
|
+
function defineSignal(state, key, value) {
|
|
394
|
+
let isObservable, s2 = isSignal(value) ? value : isObject(value) || Array.isArray(value) ? u(SignalStruct(value)) : u((isObservable = observable(value)) ? void 0 : value);
|
|
395
|
+
if (isObservable)
|
|
396
|
+
sube_default(value, (v2) => s2.value = v2);
|
|
397
|
+
Object.defineProperty(state, key, {
|
|
398
|
+
get() {
|
|
399
|
+
return s2.value;
|
|
400
|
+
},
|
|
401
|
+
set: !isSignal(value) && isObject(value) ? (v2) => v2 ? Object.assign(s2.value, v2) : s2.value = SignalStruct(v2) : (v2) => s2.value = SignalStruct(v2),
|
|
402
|
+
enumerable: true,
|
|
403
|
+
configurable: false
|
|
62
404
|
});
|
|
63
|
-
return
|
|
405
|
+
return s2;
|
|
64
406
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const className = name.replace(":", "\u2234");
|
|
68
|
-
return directives[name] = (el2, initValues) => {
|
|
69
|
-
if (el2.classList.contains(className))
|
|
70
|
-
return;
|
|
71
|
-
el2.classList.add(className);
|
|
72
|
-
let expr = el2.getAttribute(name);
|
|
73
|
-
el2.removeAttribute(name);
|
|
74
|
-
return initializer(el2, expr, initValues);
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
var registry2 = new FinalizationRegistry((unsub) => unsub?.call?.());
|
|
78
|
-
var evaluatorMemo = {};
|
|
79
|
-
function parseExpr(expression) {
|
|
80
|
-
if (evaluatorMemo[expression])
|
|
81
|
-
return evaluatorMemo[expression];
|
|
82
|
-
let rightSideSafeExpression = /^[\n\s]*if.*\(.*\)/.test(expression) || /^(let|const)\s/.test(expression) ? `(() => { ${expression} })()` : expression;
|
|
83
|
-
const safeFunction = () => {
|
|
84
|
-
try {
|
|
85
|
-
return new Function(["scope"], `let result; with (scope) { result = ${rightSideSafeExpression} }; return result;`);
|
|
86
|
-
} catch (e) {
|
|
87
|
-
return exprError(e, expression);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
return evaluatorMemo[expression] = safeFunction();
|
|
407
|
+
function isObject(v2) {
|
|
408
|
+
return v2 && v2.constructor === Object;
|
|
91
409
|
}
|
|
92
|
-
function exprError(error, expression) {
|
|
93
|
-
Object.assign(error, { expression });
|
|
94
|
-
console.warn(`\u2234 ${error.message}
|
|
95
410
|
|
|
96
|
-
|
|
411
|
+
// node_modules/element-props/element-props.js
|
|
412
|
+
var prop = (el2, k, v2) => {
|
|
413
|
+
if (k.startsWith("on"))
|
|
414
|
+
k = k.toLowerCase();
|
|
415
|
+
if (el2[k] !== v2) {
|
|
416
|
+
el2[k] = v2;
|
|
417
|
+
}
|
|
418
|
+
if (v2 === false || v2 == null)
|
|
419
|
+
el2.removeAttribute(k);
|
|
420
|
+
else if (typeof v2 !== "function")
|
|
421
|
+
el2.setAttribute(
|
|
422
|
+
dashcase(k),
|
|
423
|
+
v2 === true ? "" : typeof v2 === "number" || typeof v2 === "string" ? v2 : k === "class" ? (Array.isArray(v2) ? v2 : Object.entries(v2).map(([k2, v3]) => v3 ? k2 : "")).filter(Boolean).join(" ") : k === "style" ? Object.entries(v2).map(([k2, v3]) => `${k2}: ${v3}`).join(";") : ""
|
|
424
|
+
);
|
|
425
|
+
};
|
|
426
|
+
var input = (el2) => [
|
|
427
|
+
el2.type === "checkbox" ? () => el2.checked : () => el2.value,
|
|
428
|
+
el2.type === "text" || el2.type === "" ? (value) => el2.value = value == null ? "" : value : el2.type === "checkbox" ? (value) => (el2.value = value ? "on" : "", prop(el2, "checked", value)) : el2.type === "select-one" ? (value) => ([...el2.options].map((el3) => el3.removeAttribute("selected")), el2.value = value, el2.selectedOptions[0]?.setAttribute("selected", "")) : (value) => el2.value = value
|
|
429
|
+
];
|
|
430
|
+
var el = document.createElement("div");
|
|
431
|
+
var dashcase = (str) => {
|
|
432
|
+
el.dataset[str] = "";
|
|
433
|
+
let dashStr = el.attributes[0].name.slice(5);
|
|
434
|
+
delete el.dataset[str];
|
|
435
|
+
return dashStr;
|
|
436
|
+
};
|
|
97
437
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
438
|
+
// node_modules/swapdom/swap-inflate.js
|
|
439
|
+
var swap = (parent, a2, b2, end = null) => {
|
|
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]))
|
|
444
|
+
end = b2[--m, --n2];
|
|
445
|
+
if (i2 == m)
|
|
446
|
+
while (i2 < n2)
|
|
447
|
+
insert(end, b2[i2++], parent);
|
|
448
|
+
else {
|
|
449
|
+
cur = a2[i2];
|
|
450
|
+
while (i2 < n2) {
|
|
451
|
+
bi = b2[i2++], next = cur ? cur.nextSibling : end;
|
|
452
|
+
if (same(cur, bi))
|
|
453
|
+
cur = next;
|
|
454
|
+
else if (i2 < n2 && same(b2[i2], next))
|
|
455
|
+
replace(cur, bi, parent), cur = next;
|
|
456
|
+
else
|
|
457
|
+
insert(cur, bi, parent);
|
|
458
|
+
}
|
|
459
|
+
while (!same(cur, end))
|
|
460
|
+
next = cur.nextSibling, remove(cur, parent), cur = next;
|
|
461
|
+
}
|
|
462
|
+
return b2;
|
|
463
|
+
};
|
|
464
|
+
swap.same = (a2, b2) => a2 == b2;
|
|
465
|
+
swap.replace = (a2, b2, parent) => parent.replaceChild(b2, a2);
|
|
466
|
+
swap.insert = (a2, b2, parent) => parent.insertBefore(b2, a2);
|
|
467
|
+
swap.remove = (a2, parent) => parent.removeChild(a2);
|
|
468
|
+
var swap_inflate_default = swap;
|
|
104
469
|
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
470
|
+
// node_modules/primitive-pool/index.js
|
|
471
|
+
var cache = {};
|
|
472
|
+
var nullObj = {};
|
|
473
|
+
var undefinedObj = {};
|
|
474
|
+
var primitive_pool_default = (key) => {
|
|
475
|
+
if (key === null)
|
|
476
|
+
return nullObj;
|
|
477
|
+
if (key === void 0)
|
|
478
|
+
return undefinedObj;
|
|
479
|
+
if (typeof key === "number" || key instanceof Number)
|
|
480
|
+
return cache[key] || (cache[key] = new Number(key));
|
|
481
|
+
if (typeof key === "string" || key instanceof String)
|
|
482
|
+
return cache[key] || (cache[key] = new String(key));
|
|
483
|
+
if (typeof key === "boolean" || key instanceof Boolean)
|
|
484
|
+
return cache[key] || (cache[key] = new Boolean(key));
|
|
485
|
+
return key;
|
|
486
|
+
};
|
|
116
487
|
|
|
117
|
-
// src/directives
|
|
118
|
-
|
|
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");
|
|
497
|
+
directives[":with"] = (el2, expr, rootState) => {
|
|
498
|
+
let evaluate = parseExpr(expr, "with", rootState);
|
|
499
|
+
const params = w(() => Object.assign({}, rootState, evaluate(rootState)));
|
|
500
|
+
let state = sprae(el2, params.value);
|
|
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;
|
|
509
|
+
};
|
|
510
|
+
directives[":if"] = (el2, expr, state) => {
|
|
511
|
+
let holder = document.createTextNode(""), clauses = [parseExpr(expr, ":if", state)], els = [el2], cur = el2;
|
|
512
|
+
while (cur = el2.nextElementSibling) {
|
|
513
|
+
if (cur.hasAttribute(":else")) {
|
|
514
|
+
cur.removeAttribute(":else");
|
|
515
|
+
if (expr = cur.getAttribute(":if")) {
|
|
516
|
+
cur.removeAttribute(":if"), cur.remove();
|
|
517
|
+
els.push(cur);
|
|
518
|
+
clauses.push(parseExpr(expr, ":else :if", state));
|
|
519
|
+
} else {
|
|
520
|
+
cur.remove();
|
|
521
|
+
els.push(cur);
|
|
522
|
+
clauses.push(() => 1);
|
|
523
|
+
}
|
|
524
|
+
} else
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
el2.replaceWith(cur = holder);
|
|
528
|
+
let idx = w(() => clauses.findIndex((f2) => f2(state)));
|
|
529
|
+
b((i2 = idx.value) => els[i2] != cur && ((cur[_each] || cur).replaceWith(cur = els[i2] || holder), sprae(cur, state)));
|
|
530
|
+
return false;
|
|
531
|
+
};
|
|
532
|
+
directives[":each"] = (tpl, expr, state) => {
|
|
119
533
|
let each = parseForExpression(expr);
|
|
120
534
|
if (!each)
|
|
121
535
|
return exprError(new Error(), expr);
|
|
122
|
-
const getItems = parseExpr(each.items);
|
|
123
|
-
const holder =
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
536
|
+
const getItems = parseExpr(each.items, ":each", state);
|
|
537
|
+
const holder = tpl[_each] = document.createTextNode("");
|
|
538
|
+
tpl.replaceWith(holder);
|
|
539
|
+
const items = w(() => {
|
|
540
|
+
let list = getItems(state);
|
|
541
|
+
if (!list)
|
|
542
|
+
return [];
|
|
543
|
+
if (typeof list === "number")
|
|
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);
|
|
550
|
+
});
|
|
551
|
+
const scopes = /* @__PURE__ */ new WeakMap();
|
|
552
|
+
const itemEls = /* @__PURE__ */ new WeakMap();
|
|
553
|
+
let curEls = [];
|
|
554
|
+
b((list = items.value) => {
|
|
555
|
+
let newEls = [], elScopes = [];
|
|
556
|
+
for (let [idx, item] of list) {
|
|
557
|
+
let itemKey = primitive_pool_default(item);
|
|
558
|
+
let el2 = itemEls.get(itemKey);
|
|
559
|
+
if (!el2) {
|
|
560
|
+
el2 = tpl.cloneNode(true);
|
|
561
|
+
itemEls.set(itemKey, el2);
|
|
562
|
+
}
|
|
563
|
+
newEls.push(el2);
|
|
564
|
+
if (!scopes.has(itemKey)) {
|
|
565
|
+
let scope = Object.create(state);
|
|
566
|
+
scope[each.item] = item;
|
|
567
|
+
if (each.index)
|
|
568
|
+
scope[each.index] = idx;
|
|
569
|
+
if (tpl[_ref])
|
|
570
|
+
scope[tpl[_ref]] = el2;
|
|
571
|
+
scopes.set(itemKey, scope);
|
|
572
|
+
}
|
|
573
|
+
elScopes.push(scopes.get(itemKey));
|
|
574
|
+
}
|
|
575
|
+
swap_inflate_default(holder.parentNode, curEls, newEls, holder);
|
|
576
|
+
curEls = newEls;
|
|
577
|
+
for (let i2 = 0; i2 < newEls.length; i2++) {
|
|
578
|
+
sprae(newEls[i2], elScopes[i2]);
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
return false;
|
|
582
|
+
};
|
|
144
583
|
function parseForExpression(expression) {
|
|
145
584
|
let forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
|
|
146
585
|
let stripParensRE = /^\s*\(|\)\s*$/g;
|
|
@@ -160,158 +599,142 @@ function parseForExpression(expression) {
|
|
|
160
599
|
}
|
|
161
600
|
return res;
|
|
162
601
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
602
|
+
directives[":id"] = (el2, expr, state) => {
|
|
603
|
+
let evaluate = parseExpr(expr, ":id", state);
|
|
604
|
+
const update = (v2) => el2.id = v2 || v2 === 0 ? v2 : "";
|
|
605
|
+
b(() => update(evaluate(state)));
|
|
606
|
+
};
|
|
607
|
+
directives[":"] = (el2, expr, state) => {
|
|
608
|
+
let evaluate = parseExpr(expr, ":", state);
|
|
609
|
+
const update = (value) => {
|
|
610
|
+
if (!value)
|
|
611
|
+
return;
|
|
612
|
+
for (let key in value)
|
|
613
|
+
prop(el2, key, value[key]);
|
|
614
|
+
};
|
|
615
|
+
b(() => update(evaluate(state)));
|
|
616
|
+
};
|
|
617
|
+
directives[":text"] = (el2, expr, state) => {
|
|
618
|
+
let evaluate = parseExpr(expr, ":text", state);
|
|
619
|
+
const update = (value) => {
|
|
169
620
|
el2.textContent = value == null ? "" : value;
|
|
170
621
|
};
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
let
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
cur.classList.add("\u2234else-if");
|
|
180
|
-
cur.remove();
|
|
181
|
-
els.push(cur);
|
|
182
|
-
clauses.push(parseExpr(expr));
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
if (cur.hasAttribute(":else")) {
|
|
186
|
-
cur.removeAttribute(":else");
|
|
187
|
-
cur.classList.add("\u2234else");
|
|
188
|
-
cur.remove();
|
|
189
|
-
els.push(cur);
|
|
190
|
-
clauses.push(() => 1);
|
|
191
|
-
}
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
cur = els[0];
|
|
195
|
-
return (state) => {
|
|
196
|
-
let idx = clauses.findIndex((match) => match(state));
|
|
197
|
-
if (idx >= 0)
|
|
198
|
-
cur.replaceWith(cur = els[idx]);
|
|
199
|
-
else
|
|
200
|
-
cur.replaceWith(cur = holder);
|
|
622
|
+
b(() => update(evaluate(state)));
|
|
623
|
+
};
|
|
624
|
+
directives[":value"] = (el2, expr, state) => {
|
|
625
|
+
let evaluate = parseExpr(expr, ":in", state);
|
|
626
|
+
let [get, set] = input(el2);
|
|
627
|
+
const update = (value) => {
|
|
628
|
+
prop(el2, "value", value);
|
|
629
|
+
set(value);
|
|
201
630
|
};
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// node_modules/element-props/element-props.js
|
|
205
|
-
var prop = (el2, k, v) => {
|
|
206
|
-
if (k.startsWith("on"))
|
|
207
|
-
k = k.toLowerCase();
|
|
208
|
-
if (el2[k] !== v) {
|
|
209
|
-
el2[k] = v;
|
|
210
|
-
}
|
|
211
|
-
if (v === false || v == null)
|
|
212
|
-
el2.removeAttribute(k);
|
|
213
|
-
else if (typeof v !== "function")
|
|
214
|
-
el2.setAttribute(
|
|
215
|
-
dashcase(k),
|
|
216
|
-
v === true ? "" : typeof v === "number" || typeof v === "string" ? v : k === "class" ? (Array.isArray(v) ? v : Object.entries(v).map(([k2, v2]) => v2 ? k2 : "")).filter(Boolean).join(" ") : k === "style" ? Object.entries(v).map(([k2, v2]) => `${k2}: ${v2}`).join(";") : ""
|
|
217
|
-
);
|
|
631
|
+
b(() => update(evaluate(state)));
|
|
218
632
|
};
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
+
});
|
|
229
644
|
};
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return (state) => {
|
|
237
|
-
let value = evaluate(state);
|
|
238
|
-
prop(el2, name, value);
|
|
239
|
-
};
|
|
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];
|
|
240
651
|
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
let evaluate = parseExpr(expr);
|
|
246
|
-
return (state) => {
|
|
247
|
-
let value = evaluate(state);
|
|
652
|
+
};
|
|
653
|
+
directives[":aria"] = (el2, expr, state) => {
|
|
654
|
+
let evaluate = parseExpr(expr, ":aria", state);
|
|
655
|
+
const update = (value) => {
|
|
248
656
|
for (let key in value)
|
|
249
|
-
prop(el2, key, value[key]);
|
|
657
|
+
prop(el2, "aria" + key[0].toUpperCase() + key.slice(1), value[key] == null ? null : value[key] + "");
|
|
250
658
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
659
|
+
b(() => update(evaluate(state)));
|
|
660
|
+
};
|
|
661
|
+
var evaluatorMemo = {};
|
|
662
|
+
function parseExpr(expression, dir, scope) {
|
|
663
|
+
if (evaluatorMemo[expression])
|
|
664
|
+
return evaluatorMemo[expression];
|
|
665
|
+
let rightSideSafeExpression = /^[\n\s]*if.*\(.*\)/.test(expression) || /^(let|const)\s/.test(expression) ? `(() => { ${expression} })()` : expression;
|
|
666
|
+
let evaluate;
|
|
667
|
+
try {
|
|
668
|
+
evaluate = new Function(`let result; with (arguments[0]) { result = (${rightSideSafeExpression}) }; return result;`);
|
|
669
|
+
} catch (e2) {
|
|
670
|
+
return exprError(e2, expression, dir, scope);
|
|
671
|
+
}
|
|
672
|
+
return evaluatorMemo[expression] = (state) => {
|
|
673
|
+
let result;
|
|
674
|
+
try {
|
|
675
|
+
result = evaluate(state);
|
|
676
|
+
} catch (e2) {
|
|
677
|
+
return exprError(e2, expression, dir, scope);
|
|
678
|
+
}
|
|
679
|
+
return result;
|
|
260
680
|
};
|
|
261
|
-
}
|
|
681
|
+
}
|
|
682
|
+
function exprError(error, expression, dir, scope) {
|
|
683
|
+
Object.assign(error, { expression });
|
|
684
|
+
console.warn(`\u2234sprae: ${error.message}
|
|
262
685
|
|
|
263
|
-
|
|
264
|
-
directive(":aria", (el2, expr) => {
|
|
265
|
-
let evaluate = parseExpr(expr);
|
|
266
|
-
return (state) => {
|
|
267
|
-
let value = evaluate(state);
|
|
268
|
-
for (let key in value)
|
|
269
|
-
prop(el2, "aria" + key[0].toUpperCase() + key.slice(1), value[key]);
|
|
270
|
-
};
|
|
271
|
-
});
|
|
686
|
+
${dir}=${expression ? `"${expression}"
|
|
272
687
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
let evaluateSet = parseSetter(expr);
|
|
278
|
-
let curState, onchange = (e) => evaluateSet(curState, get(el2));
|
|
279
|
-
el2.addEventListener("input", onchange);
|
|
280
|
-
el2.addEventListener("change", onchange);
|
|
281
|
-
return (state) => {
|
|
282
|
-
let value = evaluateGet(curState = state);
|
|
283
|
-
prop(el2, "value", value);
|
|
284
|
-
set(value);
|
|
285
|
-
};
|
|
286
|
-
});
|
|
287
|
-
var memo = {};
|
|
288
|
-
function parseSetter(expr) {
|
|
289
|
-
if (memo[expr])
|
|
290
|
-
return memo[expr];
|
|
291
|
-
return memo[expr] = new Function(
|
|
292
|
-
["scope", "value"],
|
|
293
|
-
`with (scope) { ${expr} = value };`
|
|
294
|
-
);
|
|
688
|
+
` : ""}`, scope);
|
|
689
|
+
setTimeout(() => {
|
|
690
|
+
throw error;
|
|
691
|
+
}, 0);
|
|
295
692
|
}
|
|
296
693
|
|
|
297
|
-
// src/
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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);
|
|
307
726
|
};
|
|
308
|
-
|
|
727
|
+
init(container);
|
|
728
|
+
memo.set(container, state);
|
|
729
|
+
return state;
|
|
730
|
+
}
|
|
309
731
|
|
|
310
732
|
// src/index.js
|
|
311
733
|
var src_default = sprae;
|
|
312
734
|
export {
|
|
735
|
+
h as batch,
|
|
736
|
+
w as computed,
|
|
313
737
|
src_default as default,
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
parseExpr
|
|
738
|
+
b as effect,
|
|
739
|
+
u as signal
|
|
317
740
|
};
|