sprae 0.1.0 → 2.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/.github/workflows/node.js.yml +30 -0
- package/package.json +13 -5
- package/plan.md +20 -0
- package/r&d.md +115 -4
- package/readme.md +140 -58
- package/sprae.js +709 -0
- package/sprae.min.js +1 -0
- package/src/core.js +30 -102
- package/src/directives/each.js +2 -5
- package/src/directives.js +235 -0
- package/src/index.js +12 -2
- package/test/index.html +6 -3
- package/test/test.js +242 -45
- package/src/directives/hidden.js +0 -14
- package/src/directives/if.js +0 -34
- package/src/directives/index.js +0 -5
- package/src/directives/text.js +0 -13
package/sprae.js
ADDED
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
// node_modules/@preact/signals-core/dist/signals-core.module.js
|
|
2
|
+
function i2() {
|
|
3
|
+
throw new Error("Cycle detected");
|
|
4
|
+
}
|
|
5
|
+
function t() {
|
|
6
|
+
if (!(n > 1)) {
|
|
7
|
+
var i3, 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
|
+
i3 = h3;
|
|
22
|
+
t2 = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
h2 = o2;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
s = 0;
|
|
29
|
+
n--;
|
|
30
|
+
if (t2)
|
|
31
|
+
throw i3;
|
|
32
|
+
} else
|
|
33
|
+
n--;
|
|
34
|
+
}
|
|
35
|
+
function h(i3) {
|
|
36
|
+
if (n > 0)
|
|
37
|
+
return i3();
|
|
38
|
+
n++;
|
|
39
|
+
try {
|
|
40
|
+
return i3();
|
|
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(i3) {
|
|
51
|
+
if (void 0 !== o) {
|
|
52
|
+
var t2 = i3.n;
|
|
53
|
+
if (void 0 === t2 || t2.t !== o) {
|
|
54
|
+
o.s = t2 = { i: 0, S: i3, p: void 0, n: o.s, t: o, e: void 0, x: void 0, r: t2 };
|
|
55
|
+
i3.n = t2;
|
|
56
|
+
if (32 & o.f)
|
|
57
|
+
i3.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(i3) {
|
|
75
|
+
this.v = i3;
|
|
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(i3) {
|
|
84
|
+
if (this.t !== i3 && void 0 === i3.e) {
|
|
85
|
+
i3.x = this.t;
|
|
86
|
+
if (void 0 !== this.t)
|
|
87
|
+
this.t.e = i3;
|
|
88
|
+
this.t = i3;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
e.prototype.U = function(i3) {
|
|
92
|
+
var t2 = i3.e, h2 = i3.x;
|
|
93
|
+
if (void 0 !== t2) {
|
|
94
|
+
t2.x = h2;
|
|
95
|
+
i3.e = void 0;
|
|
96
|
+
}
|
|
97
|
+
if (void 0 !== h2) {
|
|
98
|
+
h2.e = t2;
|
|
99
|
+
i3.x = void 0;
|
|
100
|
+
}
|
|
101
|
+
if (i3 === this.t)
|
|
102
|
+
this.t = h2;
|
|
103
|
+
};
|
|
104
|
+
e.prototype.subscribe = function(i3) {
|
|
105
|
+
var t2 = this;
|
|
106
|
+
return b(function() {
|
|
107
|
+
var h2 = t2.value, o2 = 32 & this.f;
|
|
108
|
+
this.f &= -33;
|
|
109
|
+
try {
|
|
110
|
+
i3(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 i3 = v(this);
|
|
127
|
+
if (void 0 !== i3)
|
|
128
|
+
i3.i = this.i;
|
|
129
|
+
return this.v;
|
|
130
|
+
}, set: function(h2) {
|
|
131
|
+
if (h2 !== this.v) {
|
|
132
|
+
if (s > 100)
|
|
133
|
+
i2();
|
|
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(i3) {
|
|
147
|
+
return new e(i3);
|
|
148
|
+
}
|
|
149
|
+
function d(i3) {
|
|
150
|
+
for (var t2 = i3.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(i3) {
|
|
156
|
+
for (var t2 = i3.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(i3) {
|
|
165
|
+
var t2 = i3.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
|
+
i3.s = h2;
|
|
184
|
+
}
|
|
185
|
+
function l(i3) {
|
|
186
|
+
e.call(this, void 0);
|
|
187
|
+
this.x = i3;
|
|
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 i3 = 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 (i4) {
|
|
218
|
+
this.v = i4;
|
|
219
|
+
this.f |= 16;
|
|
220
|
+
this.i++;
|
|
221
|
+
}
|
|
222
|
+
o = i3;
|
|
223
|
+
a(this);
|
|
224
|
+
this.f &= -2;
|
|
225
|
+
return true;
|
|
226
|
+
};
|
|
227
|
+
l.prototype.S = function(i3) {
|
|
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, i3);
|
|
234
|
+
};
|
|
235
|
+
l.prototype.U = function(i3) {
|
|
236
|
+
e.prototype.U.call(this, i3);
|
|
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 i3 = this.t; void 0 !== i3; i3 = i3.x)
|
|
247
|
+
i3.t.N();
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
l.prototype.peek = function() {
|
|
251
|
+
if (!this.h())
|
|
252
|
+
i2();
|
|
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
|
+
i2();
|
|
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(i3) {
|
|
269
|
+
return new l(i3);
|
|
270
|
+
}
|
|
271
|
+
function y(i3) {
|
|
272
|
+
var h2 = i3.u;
|
|
273
|
+
i3.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
|
+
i3.f &= -2;
|
|
282
|
+
i3.f |= 8;
|
|
283
|
+
_(i3);
|
|
284
|
+
throw t2;
|
|
285
|
+
} finally {
|
|
286
|
+
o = r2;
|
|
287
|
+
t();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function _(i3) {
|
|
292
|
+
for (var t2 = i3.s; void 0 !== t2; t2 = t2.n)
|
|
293
|
+
t2.S.U(t2);
|
|
294
|
+
i3.x = void 0;
|
|
295
|
+
i3.s = void 0;
|
|
296
|
+
y(i3);
|
|
297
|
+
}
|
|
298
|
+
function g(i3) {
|
|
299
|
+
if (o !== this)
|
|
300
|
+
throw new Error("Out-of-order effect");
|
|
301
|
+
a(this);
|
|
302
|
+
o = i3;
|
|
303
|
+
this.f &= -2;
|
|
304
|
+
if (8 & this.f)
|
|
305
|
+
_(this);
|
|
306
|
+
t();
|
|
307
|
+
}
|
|
308
|
+
function p(i3) {
|
|
309
|
+
this.x = i3;
|
|
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 i3 = this.S();
|
|
317
|
+
try {
|
|
318
|
+
if (!(8 & this.f) && void 0 !== this.x)
|
|
319
|
+
this.u = this.x();
|
|
320
|
+
} finally {
|
|
321
|
+
i3();
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
p.prototype.S = function() {
|
|
325
|
+
if (1 & this.f)
|
|
326
|
+
i2();
|
|
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(i3) {
|
|
349
|
+
var t2 = new p(i3);
|
|
350
|
+
t2.c();
|
|
351
|
+
return t2.d.bind(t2);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// node_modules/sube/sube.js
|
|
355
|
+
Symbol.observable ||= Symbol("observable");
|
|
356
|
+
var observable = (arg) => arg && !!(arg[Symbol.observable] || arg[Symbol.asyncIterator] || arg.call && arg.set || arg.subscribe || arg.then);
|
|
357
|
+
var registry = new FinalizationRegistry((unsub) => unsub.call?.());
|
|
358
|
+
var unsubr = (sub) => sub && (() => sub.unsubscribe?.());
|
|
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) => {
|
|
360
|
+
try {
|
|
361
|
+
for await (v2 of target) {
|
|
362
|
+
if (stop)
|
|
363
|
+
return;
|
|
364
|
+
next(v2);
|
|
365
|
+
}
|
|
366
|
+
complete?.();
|
|
367
|
+
} catch (err) {
|
|
368
|
+
error?.(err);
|
|
369
|
+
}
|
|
370
|
+
})()) && ((_2) => stop = 1), registry.register(target, unsub), unsub);
|
|
371
|
+
|
|
372
|
+
// node_modules/signal-struct/signal-struct.js
|
|
373
|
+
var isSignal = (v2) => v2 && v2.peek;
|
|
374
|
+
var isStruct = (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
|
+
} else
|
|
385
|
+
throw Error("Only array or object states are supported");
|
|
386
|
+
Object.defineProperty(state, _struct, { configurable: false, enumerable: false, value: true });
|
|
387
|
+
Object.seal(state);
|
|
388
|
+
return state;
|
|
389
|
+
}
|
|
390
|
+
function defineSignal(state, key, value) {
|
|
391
|
+
let isObservable, s2 = isSignal(value) ? value : isObject(value) ? u(SignalStruct(value)) : u((isObservable = observable(value)) ? void 0 : value);
|
|
392
|
+
if (isObservable)
|
|
393
|
+
sube_default(value, (v2) => s2.value = v2);
|
|
394
|
+
Object.defineProperty(state, key, {
|
|
395
|
+
get() {
|
|
396
|
+
return s2.value;
|
|
397
|
+
},
|
|
398
|
+
set: isSignal(value) ? (v2) => s2.value = v2 : isObject(value) ? (v2) => v2 ? Object.assign(s2.value, v2) : s2.value = v2 : (v2) => s2.value = v2,
|
|
399
|
+
enumerable: true,
|
|
400
|
+
configurable: false
|
|
401
|
+
});
|
|
402
|
+
return s2;
|
|
403
|
+
}
|
|
404
|
+
function isObject(v2) {
|
|
405
|
+
return v2 && v2.constructor === Object;
|
|
406
|
+
}
|
|
407
|
+
|
|
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
|
+
// node_modules/element-props/element-props.js
|
|
442
|
+
var prop = (el2, k, v2) => {
|
|
443
|
+
if (k.startsWith("on"))
|
|
444
|
+
k = k.toLowerCase();
|
|
445
|
+
if (el2[k] !== v2) {
|
|
446
|
+
el2[k] = v2;
|
|
447
|
+
}
|
|
448
|
+
if (v2 === false || v2 == null)
|
|
449
|
+
el2.removeAttribute(k);
|
|
450
|
+
else if (typeof v2 !== "function")
|
|
451
|
+
el2.setAttribute(
|
|
452
|
+
dashcase(k),
|
|
453
|
+
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(";") : ""
|
|
454
|
+
);
|
|
455
|
+
};
|
|
456
|
+
var input = (el2) => [
|
|
457
|
+
el2.type === "checkbox" ? () => el2.checked : () => el2.value,
|
|
458
|
+
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
|
|
459
|
+
];
|
|
460
|
+
var el = document.createElement("div");
|
|
461
|
+
var dashcase = (str) => {
|
|
462
|
+
el.dataset[str] = "";
|
|
463
|
+
let dashStr = el.attributes[0].name.slice(5);
|
|
464
|
+
delete el.dataset[str];
|
|
465
|
+
return dashStr;
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
// node_modules/swapdom/swap-inflate.js
|
|
469
|
+
var swap = (parent, a2, b2, end = null) => {
|
|
470
|
+
let i3 = 0, cur, next, bi, n2 = b2.length, m = a2.length, { remove, same, insert, replace } = swap;
|
|
471
|
+
while (i3 < n2 && i3 < m && same(a2[i3], b2[i3]))
|
|
472
|
+
i3++;
|
|
473
|
+
while (i3 < n2 && i3 < m && same(b2[n2 - 1], a2[m - 1]))
|
|
474
|
+
end = b2[--m, --n2];
|
|
475
|
+
if (i3 == m)
|
|
476
|
+
while (i3 < n2)
|
|
477
|
+
insert(end, b2[i3++], parent);
|
|
478
|
+
else {
|
|
479
|
+
cur = a2[i3];
|
|
480
|
+
while (i3 < n2) {
|
|
481
|
+
bi = b2[i3++], next = cur ? cur.nextSibling : end;
|
|
482
|
+
if (same(cur, bi))
|
|
483
|
+
cur = next;
|
|
484
|
+
else if (i3 < n2 && same(b2[i3], next))
|
|
485
|
+
replace(cur, bi, parent), cur = next;
|
|
486
|
+
else
|
|
487
|
+
insert(cur, bi, parent);
|
|
488
|
+
}
|
|
489
|
+
while (!same(cur, end))
|
|
490
|
+
next = cur.nextSibling, remove(cur, parent), cur = next;
|
|
491
|
+
}
|
|
492
|
+
return b2;
|
|
493
|
+
};
|
|
494
|
+
swap.same = (a2, b2) => a2 == b2;
|
|
495
|
+
swap.replace = (a2, b2, parent) => parent.replaceChild(b2, a2);
|
|
496
|
+
swap.insert = (a2, b2, parent) => parent.insertBefore(b2, a2);
|
|
497
|
+
swap.remove = (a2, parent) => parent.removeChild(a2);
|
|
498
|
+
var swap_inflate_default = swap;
|
|
499
|
+
|
|
500
|
+
// node_modules/primitive-pool/index.js
|
|
501
|
+
var cache = {};
|
|
502
|
+
var nullObj = {};
|
|
503
|
+
var undefinedObj = {};
|
|
504
|
+
var primitive_pool_default = (key) => {
|
|
505
|
+
if (key === null)
|
|
506
|
+
return nullObj;
|
|
507
|
+
if (key === void 0)
|
|
508
|
+
return undefinedObj;
|
|
509
|
+
if (typeof key === "number" || key instanceof Number)
|
|
510
|
+
return cache[key] || (cache[key] = new Number(key));
|
|
511
|
+
if (typeof key === "string" || key instanceof String)
|
|
512
|
+
return cache[key] || (cache[key] = new String(key));
|
|
513
|
+
if (typeof key === "boolean" || key instanceof Boolean)
|
|
514
|
+
return cache[key] || (cache[key] = new Boolean(key));
|
|
515
|
+
return key;
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
// src/directives.js
|
|
519
|
+
directives[":with"] = (el2, expr, rootState) => {
|
|
520
|
+
let evaluate = parseExpr(expr, "with", rootState);
|
|
521
|
+
const params = w(() => Object.assign({}, rootState, evaluate(rootState)));
|
|
522
|
+
let state = sprae(el2, params.value);
|
|
523
|
+
b((values = params.value) => h(() => Object.assign(state, values)));
|
|
524
|
+
};
|
|
525
|
+
directives[":if"] = (el2, expr, state) => {
|
|
526
|
+
let holder = document.createTextNode(""), clauses = [parseExpr(expr, ":if", state)], els = [el2], cur = el2;
|
|
527
|
+
while (cur = el2.nextElementSibling) {
|
|
528
|
+
if (cur.hasAttribute(":else")) {
|
|
529
|
+
cur.removeAttribute(":else");
|
|
530
|
+
if (expr = cur.getAttribute(":if")) {
|
|
531
|
+
cur.removeAttribute(":if"), cur.remove();
|
|
532
|
+
els.push(cur);
|
|
533
|
+
clauses.push(parseExpr(expr, ":else :if", state));
|
|
534
|
+
} else {
|
|
535
|
+
cur.remove();
|
|
536
|
+
els.push(cur);
|
|
537
|
+
clauses.push(() => 1);
|
|
538
|
+
}
|
|
539
|
+
} else
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
el2.replaceWith(cur = holder);
|
|
543
|
+
let idx = w(() => clauses.findIndex((f2) => f2(state)));
|
|
544
|
+
b((i3 = idx.value) => els[i3] != cur && ((cur[_eachHolder] || cur).replaceWith(cur = els[i3] || holder), sprae(cur, state)));
|
|
545
|
+
return false;
|
|
546
|
+
};
|
|
547
|
+
var _eachHolder = Symbol(":each");
|
|
548
|
+
directives[":each"] = (tpl, expr, state) => {
|
|
549
|
+
let each = parseForExpression(expr);
|
|
550
|
+
if (!each)
|
|
551
|
+
return exprError(new Error(), expr);
|
|
552
|
+
const getItems = parseExpr(each.items, ":each", state);
|
|
553
|
+
const holder = tpl[_eachHolder] = document.createTextNode("");
|
|
554
|
+
tpl.replaceWith(holder);
|
|
555
|
+
const items = w(() => {
|
|
556
|
+
let list = getItems(state);
|
|
557
|
+
if (typeof list === "number")
|
|
558
|
+
return Array.from({ length: list }, (_2, i3) => i3 + 1);
|
|
559
|
+
return list;
|
|
560
|
+
});
|
|
561
|
+
const scopes = /* @__PURE__ */ new WeakMap();
|
|
562
|
+
const itemEls = /* @__PURE__ */ new WeakMap();
|
|
563
|
+
let curEls = [];
|
|
564
|
+
b((list = items.value) => {
|
|
565
|
+
if (!list)
|
|
566
|
+
list = [];
|
|
567
|
+
let newEls = [], elScopes = [];
|
|
568
|
+
for (let item of list) {
|
|
569
|
+
let key = primitive_pool_default(item);
|
|
570
|
+
let el2 = itemEls.get(key);
|
|
571
|
+
if (!el2) {
|
|
572
|
+
el2 = tpl.cloneNode(true);
|
|
573
|
+
itemEls.set(key, el2);
|
|
574
|
+
}
|
|
575
|
+
newEls.push(el2);
|
|
576
|
+
if (!scopes.has(key)) {
|
|
577
|
+
let scope = Object.create(state);
|
|
578
|
+
scope[each.item] = item;
|
|
579
|
+
if (each.index)
|
|
580
|
+
scope[each.index] = i;
|
|
581
|
+
scopes.set(key, scope);
|
|
582
|
+
}
|
|
583
|
+
elScopes.push(scopes.get(key));
|
|
584
|
+
}
|
|
585
|
+
swap_inflate_default(holder.parentNode, curEls, newEls, holder);
|
|
586
|
+
curEls = newEls;
|
|
587
|
+
for (let i3 = 0; i3 < newEls.length; i3++) {
|
|
588
|
+
sprae(newEls[i3], elScopes[i3]);
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
return false;
|
|
592
|
+
};
|
|
593
|
+
function parseForExpression(expression) {
|
|
594
|
+
let forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
|
|
595
|
+
let stripParensRE = /^\s*\(|\)\s*$/g;
|
|
596
|
+
let forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
|
|
597
|
+
let inMatch = expression.match(forAliasRE);
|
|
598
|
+
if (!inMatch)
|
|
599
|
+
return;
|
|
600
|
+
let res = {};
|
|
601
|
+
res.items = inMatch[2].trim();
|
|
602
|
+
let item = inMatch[1].replace(stripParensRE, "").trim();
|
|
603
|
+
let iteratorMatch = item.match(forIteratorRE);
|
|
604
|
+
if (iteratorMatch) {
|
|
605
|
+
res.item = item.replace(forIteratorRE, "").trim();
|
|
606
|
+
res.index = iteratorMatch[1].trim();
|
|
607
|
+
} else {
|
|
608
|
+
res.item = item;
|
|
609
|
+
}
|
|
610
|
+
return res;
|
|
611
|
+
}
|
|
612
|
+
directives["default"] = (el2, expr, state, name) => {
|
|
613
|
+
let evaluate = parseExpr(expr, ":" + name, state);
|
|
614
|
+
const update = (value) => prop(el2, name, value);
|
|
615
|
+
b(() => update(evaluate(state)));
|
|
616
|
+
};
|
|
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
|
+
directives[":"] = (el2, expr, state) => {
|
|
646
|
+
let evaluate = parseExpr(expr, ":", state);
|
|
647
|
+
const update = (value) => {
|
|
648
|
+
if (!value)
|
|
649
|
+
return;
|
|
650
|
+
for (let key in value)
|
|
651
|
+
prop(el2, key, value[key]);
|
|
652
|
+
};
|
|
653
|
+
b(() => update(evaluate(state)));
|
|
654
|
+
};
|
|
655
|
+
directives[":text"] = (el2, expr, state) => {
|
|
656
|
+
let evaluate = parseExpr(expr, ":text", state);
|
|
657
|
+
const update = (value) => {
|
|
658
|
+
el2.textContent = value == null ? "" : value;
|
|
659
|
+
};
|
|
660
|
+
b(() => update(evaluate(state)));
|
|
661
|
+
};
|
|
662
|
+
directives[":value"] = (el2, expr, state) => {
|
|
663
|
+
let evaluate = parseExpr(expr, ":in", state);
|
|
664
|
+
let [get, set] = input(el2);
|
|
665
|
+
const update = (value) => {
|
|
666
|
+
prop(el2, "value", value);
|
|
667
|
+
set(value);
|
|
668
|
+
};
|
|
669
|
+
b(() => update(evaluate(state)));
|
|
670
|
+
};
|
|
671
|
+
var evaluatorMemo = {};
|
|
672
|
+
function parseExpr(expression, dir, scope) {
|
|
673
|
+
if (evaluatorMemo[expression])
|
|
674
|
+
return evaluatorMemo[expression];
|
|
675
|
+
let rightSideSafeExpression = /^[\n\s]*if.*\(.*\)/.test(expression) || /^(let|const)\s/.test(expression) ? `(() => { ${expression} })()` : expression;
|
|
676
|
+
let evaluate;
|
|
677
|
+
try {
|
|
678
|
+
evaluate = new Function(["scope"], `let result; with (scope) { result = ${rightSideSafeExpression} }; return result;`);
|
|
679
|
+
} catch (e2) {
|
|
680
|
+
return exprError(e2, expression, dir, scope);
|
|
681
|
+
}
|
|
682
|
+
return evaluatorMemo[expression] = (state) => {
|
|
683
|
+
let result;
|
|
684
|
+
try {
|
|
685
|
+
result = evaluate(state);
|
|
686
|
+
} catch (e2) {
|
|
687
|
+
return exprError(e2, expression, dir, scope);
|
|
688
|
+
}
|
|
689
|
+
return result;
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
function exprError(error, expression, dir, scope) {
|
|
693
|
+
Object.assign(error, { expression });
|
|
694
|
+
console.warn(`\u2234sprae: ${error.message}
|
|
695
|
+
|
|
696
|
+
${dir}=${expression ? `"${expression}"
|
|
697
|
+
|
|
698
|
+
` : ""}`, scope);
|
|
699
|
+
setTimeout(() => {
|
|
700
|
+
throw error;
|
|
701
|
+
}, 0);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// src/index.js
|
|
705
|
+
var src_default = sprae;
|
|
706
|
+
export {
|
|
707
|
+
src_default as default,
|
|
708
|
+
directives
|
|
709
|
+
};
|