sprae 9.0.1 → 9.1.1

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/dist/sprae.js CHANGED
@@ -4,343 +4,14 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
- // node_modules/swapdom/swap-inflate.js
8
- var swap = (parent, a, b, end = null) => {
9
- let i = 0, cur2, next2, bi, n = b.length, m = a.length, { remove, same, insert, replace } = swap;
10
- while (i < n && i < m && same(a[i], b[i]))
11
- i++;
12
- while (i < n && i < m && same(b[n - 1], a[m - 1]))
13
- end = b[--m, --n];
14
- if (i == m)
15
- while (i < n)
16
- insert(end, b[i++], parent);
17
- else {
18
- cur2 = a[i];
19
- while (i < n) {
20
- bi = b[i++], next2 = cur2 ? cur2.nextSibling : end;
21
- if (same(cur2, bi))
22
- cur2 = next2;
23
- else if (i < n && same(b[i], next2))
24
- replace(cur2, bi, parent), cur2 = next2;
25
- else
26
- insert(cur2, bi, parent);
27
- }
28
- while (!same(cur2, end))
29
- next2 = cur2.nextSibling, remove(cur2, parent), cur2 = next2;
30
- }
31
- return b;
32
- };
33
- swap.same = (a, b) => a == b;
34
- swap.replace = (a, b, parent) => parent.replaceChild(b, a);
35
- swap.insert = (a, b, parent) => parent.insertBefore(b, a);
36
- swap.remove = (a, parent) => parent.removeChild(a);
37
- var swap_inflate_default = swap;
38
-
39
- // node_modules/ulive/dist/ulive.es.js
40
- var ulive_es_exports = {};
41
- __export(ulive_es_exports, {
42
- batch: () => batch,
43
- computed: () => computed,
44
- current: () => current,
45
- effect: () => effect,
46
- signal: () => signal,
47
- untracked: () => untracked
48
- });
49
- var current;
50
- var signal = (v, s, obs = /* @__PURE__ */ new Set()) => (s = {
51
- get value() {
52
- current?.deps.push(obs.add(current));
53
- return v;
54
- },
55
- set value(val) {
56
- if (val === v)
57
- return;
58
- v = val;
59
- for (let sub of obs)
60
- sub(val);
61
- },
62
- peek() {
63
- return v;
64
- }
65
- }, s.toJSON = s.then = s.toString = s.valueOf = () => s.value, s);
66
- var effect = (fn, teardown, run, deps) => (run = (prev) => {
67
- teardown?.call?.();
68
- prev = current, current = run;
69
- try {
70
- teardown = fn();
71
- } finally {
72
- current = prev;
73
- }
74
- }, deps = run.deps = [], run(), (dep) => {
75
- teardown?.call?.();
76
- while (dep = deps.pop())
77
- dep.delete(run);
78
- });
79
- var computed = (fn, s = signal(), c, e) => (c = {
80
- get value() {
81
- e ||= effect(() => s.value = fn());
82
- return s.value;
83
- },
84
- peek: s.peek
85
- }, c.toJSON = c.then = c.toString = c.valueOf = () => c.value, c);
86
- var batch = (fn) => fn();
87
- var untracked = (fn, prev, v) => (prev = current, current = null, v = fn(), current = prev, v);
88
-
89
- // node_modules/subscript/src/const.js
90
- var PERIOD = 46;
91
- var SPACE = 32;
92
- var COLON = 58;
93
- var DQUOTE = 34;
94
- var QUOTE = 39;
95
- var _0 = 48;
96
- var _9 = 57;
97
- var _E = 69;
98
- var _e = 101;
99
- var BSLASH = 92;
100
- var STAR = 42;
101
- var PREC_SEQ = 1;
102
- var PREC_ASSIGN = 2;
103
- var PREC_LOR = 3;
104
- var PREC_LAND = 4;
105
- var PREC_OR = 5;
106
- var PREC_XOR = 6;
107
- var PREC_AND = 7;
108
- var PREC_EQ = 8;
109
- var PREC_COMP = 9;
110
- var PREC_SHIFT = 10;
111
- var PREC_ADD = 11;
112
- var PREC_MULT = 12;
113
- var PREC_EXP = 13;
114
- var PREC_PREFIX = 14;
115
- var PREC_POSTFIX = 15;
116
- var PREC_ACCESS = 17;
117
- var PREC_TOKEN = 20;
118
-
119
- // node_modules/subscript/src/parse.js
120
- var idx;
121
- var cur;
122
- var parse = (s) => (idx = 0, cur = s, s = expr(), cur[idx] ? err2() : s || "");
123
- var err2 = (msg = "Bad syntax", lines = cur.slice(0, idx).split("\n"), last2 = lines.pop()) => {
124
- let before = cur.slice(idx - 108, idx).split("\n").pop();
125
- let after = cur.slice(idx, idx + 108).split("\n").shift();
126
- throw EvalError(`${msg} at ${lines.length}:${last2.length} \`${idx >= 108 ? "\u2026" : ""}${before}\u2503${after}\``, "font-weight: bold");
127
- };
128
- var next = (is, from = idx, l) => {
129
- while (l = is(cur.charCodeAt(idx)))
130
- idx += l;
131
- return cur.slice(from, idx);
132
- };
133
- var skip = (n = 1, from = idx) => (idx += n, cur.slice(from, idx));
134
- var expr = (prec = 0, end, cc, token2, newNode, fn) => {
135
- while ((cc = parse.space()) && (newNode = ((fn = lookup[cc]) && fn(token2, prec)) ?? (!token2 && next(parse.id))))
136
- token2 = newNode;
137
- if (end)
138
- cc == end ? idx++ : err2();
139
- return token2;
140
- };
141
- var id = parse.id = (c) => c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122 || c == 36 || c == 95 || c >= 192 && c != 215 && c != 247;
142
- var space = parse.space = (cc) => {
143
- while ((cc = cur.charCodeAt(idx)) <= SPACE)
144
- idx++;
145
- return cc;
146
- };
147
- var lookup = [];
148
- var token = (op, prec = SPACE, map, c = op.charCodeAt(0), l = op.length, prev = lookup[c], word = op.toUpperCase() !== op) => lookup[c] = (a, curPrec, from = idx) => curPrec < prec && (l < 2 || cur.substr(idx, l) == op) && (!word || !parse.id(cur.charCodeAt(idx + l))) && (idx += l, map(a, curPrec)) || (idx = from, prev?.(a, curPrec));
149
- var binary = (op, prec, right = false) => token(op, prec, (a, b) => a && (b = expr(prec - (right ? 0.5 : 0))) && [op, a, b]);
150
- var unary = (op, prec, post) => token(op, prec, (a) => post ? a && [op, a] : !a && (a = expr(prec - 0.5)) && [op, a]);
151
- var nary = (op, prec) => {
152
- token(
153
- op,
154
- prec,
155
- (a, b) => (b = expr(prec), (!a || a[0] !== op) && (a = [op, a]), a.push(b), a)
156
- );
157
- };
158
- var group = (op, prec) => token(op[0], prec, (a) => !a && [op, expr(0, op.charCodeAt(1))]);
159
- var access = (op, prec) => token(op[0], prec, (a) => a && [op[0], a, expr(0, op.charCodeAt(1))]);
160
- var parse_default = parse;
161
-
162
- // node_modules/subscript/src/compile.js
163
- var compile = (node) => !Array.isArray(node) ? compile.id(node) : !node[0] ? () => node[1] : operators[node[0]](...node.slice(1));
164
- var id2 = compile.id = (name) => (ctx) => ctx?.[name];
165
- var operators = {};
166
- var operator = (op, fn, prev = operators[op]) => operators[op] = (...args) => fn(...args) || prev && prev(...args);
167
- var prop = (a, fn, generic, obj, path) => a[0] === "()" ? prop(a[1], fn, generic) : typeof a === "string" ? (ctx) => fn(ctx, a, ctx) : a[0] === "." ? (obj = compile(a[1]), path = a[2], (ctx) => fn(obj(ctx), path, ctx)) : a[0] === "[" ? (obj = compile(a[1]), path = compile(a[2]), (ctx) => fn(obj(ctx), path(ctx), ctx)) : generic ? (a = compile(a), (ctx) => fn([a(ctx)], 0, ctx)) : () => err2("Bad left value");
168
- var compile_default = compile;
169
-
170
- // node_modules/subscript/feature/number.js
171
- var num = (a, _) => [, (a = +next((c) => c === PERIOD || c >= _0 && c <= _9 || (c === _E || c === _e ? 2 : 0))) != a ? err2() : a];
172
- lookup[PERIOD] = (a) => !a && num();
173
- for (let i = _0; i <= _9; i++)
174
- lookup[i] = (a) => a ? err2() : num();
175
-
176
- // node_modules/subscript/feature/string.js
177
- var escape = { n: "\n", r: "\r", t: " ", b: "\b", f: "\f", v: "\v" };
178
- var string = (q) => (qc, c, str = "") => {
179
- qc && err2("Unexpected string");
180
- skip();
181
- while (c = cur.charCodeAt(idx), c - q) {
182
- if (c === BSLASH)
183
- skip(), c = skip(), str += escape[c] || c;
184
- else
185
- str += skip();
186
- }
187
- skip() || err2("Bad string");
188
- return [, str];
189
- };
190
- lookup[DQUOTE] = string(DQUOTE);
191
- lookup[QUOTE] = string(QUOTE);
192
-
193
- // node_modules/subscript/feature/call.js
194
- access("()", PREC_ACCESS);
195
- operator(
196
- "(",
197
- (a, b, args) => (args = !b ? () => [] : b[0] === "," ? (b = b.slice(1).map((b2) => !b2 ? err() : compile(b2)), (ctx) => b.map((arg) => arg(ctx))) : (b = compile(b), (ctx) => [b(ctx)]), prop(a, (obj, path, ctx) => obj[path](...args(ctx)), true))
198
- );
199
-
200
- // node_modules/subscript/feature/access.js
201
- access("[]", PREC_ACCESS);
202
- operator("[", (a, b) => !b ? err() : (a = compile(a), b = compile(b), (ctx) => a(ctx)[b(ctx)]));
203
- binary(".", PREC_ACCESS);
204
- operator(".", (a, b) => (a = compile(a), b = !b[0] ? b[1] : b, (ctx) => a(ctx)[b]));
205
-
206
- // node_modules/subscript/feature/group.js
207
- group("()", PREC_ACCESS);
208
- operator("()", (a) => (!a && err2("Empty ()"), compile(a)));
209
- var last = (...args) => (args = args.map(compile), (ctx) => args.map((arg) => arg(ctx)).pop());
210
- nary(",", PREC_SEQ), operator(",", last);
211
- nary(";", PREC_SEQ, true), operator(";", last);
212
-
213
- // node_modules/subscript/feature/mult.js
214
- binary("*", PREC_MULT), operator("*", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) * b(ctx)));
215
- binary("/", PREC_MULT), operator("/", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) / b(ctx)));
216
- binary("%", PREC_MULT), operator("%", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) % b(ctx)));
217
- binary("*=", PREC_ASSIGN, true);
218
- operator("*=", (a, b) => (b = compile(b), prop(a, (container, path, ctx) => container[path] *= b(ctx))));
219
- binary("/=", PREC_ASSIGN, true);
220
- operator("/=", (a, b) => (b = compile(b), prop(a, (container, path, ctx) => container[path] /= b(ctx))));
221
- binary("%=", PREC_ASSIGN, true);
222
- operator("%=", (a, b) => (b = compile(b), prop(a, (container, path, ctx) => container[path] %= b(ctx))));
223
-
224
- // node_modules/subscript/feature/add.js
225
- unary("+", PREC_PREFIX), operator("+", (a, b) => !b && (a = compile(a), (ctx) => +a(ctx)));
226
- unary("-", PREC_PREFIX), operator("-", (a, b) => !b && (a = compile(a), (ctx) => -a(ctx)));
227
- binary("+", PREC_ADD), operator("+", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) + b(ctx)));
228
- binary("-", PREC_ADD), operator("-", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) - b(ctx)));
229
- binary("+=", PREC_ASSIGN, true);
230
- operator("+=", (a, b) => (b = compile(b), prop(a, (container, path, ctx) => container[path] += b(ctx))));
231
- binary("-=", PREC_ASSIGN, true);
232
- operator("-=", (a, b) => (b = compile(b), prop(a, (container, path, ctx) => container[path] -= b(ctx))));
233
-
234
- // node_modules/subscript/feature/increment.js
235
- var inc;
236
- var dec;
237
- token("++", PREC_POSTFIX, (a) => a ? ["++-", a] : ["++", expr(PREC_POSTFIX - 1)]);
238
- operator("++", inc = (a) => prop(a, (obj, path, ctx) => ++obj[path]));
239
- operator("++-", inc = (a) => prop(a, (obj, path, ctx) => obj[path]++));
240
- token("--", PREC_POSTFIX, (a) => a ? ["--+", a] : ["--", expr(PREC_POSTFIX - 1)]);
241
- operator("--", dec = (a) => prop(a, (obj, path, ctx) => --obj[path]));
242
- operator("--+", dec = (a) => prop(a, (obj, path, ctx) => obj[path]--));
243
-
244
- // node_modules/subscript/feature/bitwise.js
245
- unary("~", PREC_PREFIX), operator("~", (a, b) => !b && (a = compile(a), (ctx) => ~a(ctx)));
246
- binary("|", PREC_OR), operator("|", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) | b(ctx)));
247
- binary("&", PREC_AND), operator("&", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) & b(ctx)));
248
- binary("^", PREC_XOR), operator("^", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) ^ b(ctx)));
249
- binary(">>", PREC_SHIFT), operator(">>", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) >> b(ctx)));
250
- binary("<<", PREC_SHIFT), operator("<<", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) << b(ctx)));
251
-
252
- // node_modules/subscript/feature/compare.js
253
- binary("==", PREC_EQ), operator("==", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) == b(ctx)));
254
- binary("!=", PREC_EQ), operator("!=", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) != b(ctx)));
255
- binary(">", PREC_COMP), operator(">", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) > b(ctx)));
256
- binary("<", PREC_COMP), operator("<", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) < b(ctx)));
257
- binary(">=", PREC_COMP), operator(">=", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) >= b(ctx)));
258
- binary("<=", PREC_COMP), operator("<=", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) <= b(ctx)));
259
-
260
- // node_modules/subscript/feature/logic.js
261
- unary("!", PREC_PREFIX), operator("!", (a, b) => !b && (a = compile(a), (ctx) => !a(ctx)));
262
- binary("||", PREC_LOR);
263
- operator("||", (a, b) => (a = compile(a), b = compile(b), (ctx) => a(ctx) || b(ctx)));
264
- binary("&&", PREC_LAND);
265
- operator("&&", (a, b) => (a = compile(a), b = compile(b), (ctx) => a(ctx) && b(ctx)));
266
-
267
- // node_modules/subscript/feature/assign.js
268
- binary("=", PREC_ASSIGN, true);
269
- operator("=", (a, b) => (b = compile(b), prop(a, (container, path, ctx) => container[path] = b(ctx))));
270
-
271
- // node_modules/subscript/subscript.js
272
- var subscript_default = (s) => compile_default(parse_default(s));
273
-
274
- // node_modules/subscript/feature/comment.js
275
- token("/*", PREC_TOKEN, (a, prec) => (next((c) => c !== STAR && cur.charCodeAt(idx + 1) !== 47), skip(2), a || expr(prec) || []));
276
- token("//", PREC_TOKEN, (a, prec) => (next((c) => c >= SPACE), a || expr(prec) || [""]));
277
-
278
- // node_modules/subscript/feature/pow.js
279
- binary("**", PREC_EXP, true), operator("**", (a, b) => b && (a = compile(a), b = compile(b), (ctx) => a(ctx) ** b(ctx)));
280
-
281
- // node_modules/subscript/feature/ternary.js
282
- token("?", PREC_ASSIGN, (a, b, c) => a && (b = expr(PREC_ASSIGN - 0.5, COLON)) && (c = expr(PREC_ASSIGN - 0.5), ["?", a, b, c]));
283
- operator("?", (a, b, c) => (a = compile(a), b = compile(b), c = compile(c), (ctx) => a(ctx) ? b(ctx) : c(ctx)));
284
-
285
- // node_modules/subscript/feature/bool.js
286
- token("true", PREC_TOKEN, (a) => a ? err() : [, true]);
287
- token("false", PREC_TOKEN, (a) => a ? err() : [, false]);
288
-
289
- // node_modules/subscript/feature/array.js
290
- group("[]", PREC_TOKEN);
291
- operator(
292
- "[]",
293
- (a, b) => (a = !a ? [] : a[0] === "," ? a.slice(1) : [a], a = a.map((a2) => a2[0] === "..." ? (a2 = compile(a2[1]), (ctx) => a2(ctx)) : (a2 = compile(a2), (ctx) => [a2(ctx)])), (ctx) => a.flatMap((a2) => a2(ctx)))
294
- );
295
-
296
- // node_modules/subscript/feature/object.js
297
- group("{}", PREC_TOKEN);
298
- operator("{}", (a, b) => (a = !a ? [] : a[0] !== "," ? [a] : a.slice(1), a = a.map((p) => compile(typeof p === "string" ? [":", p, p] : p)), (ctx) => Object.fromEntries(a.flatMap((frag) => frag(ctx)))));
299
- binary(":", PREC_ASSIGN - 0.5, true);
300
- operator(":", (a, b) => (b = compile(b), Array.isArray(a) ? (a = compile(a), (ctx) => [[a(ctx), b(ctx)]]) : (ctx) => [[a, b(ctx)]]));
301
-
302
- // node_modules/subscript/feature/arrow.js
303
- binary("=>", PREC_ASSIGN, true);
304
- operator(
305
- "=>",
306
- (a, b) => (a = a[0] === "()" ? a[1] : a, a = !a ? [] : a[0] === "," ? a = a.slice(1) : a = [a], b = compile(b[0] === "{}" ? b[1] : b), (ctx = null) => (ctx = Object.create(ctx), (...args) => (a.map((a2, i) => ctx[a2] = args[i]), b(ctx))))
307
- );
308
- binary("");
309
-
310
- // node_modules/subscript/feature/optional.js
311
- token("?.", PREC_ACCESS, (a) => a && ["?.", a]);
312
- operator("?.", (a) => (a = compile(a), (ctx) => a(ctx) || (() => {
313
- })));
314
- token("?.", PREC_ACCESS, (a, b) => a && (b = expr(PREC_ACCESS), !b?.map) && ["?.", a, b]);
315
- operator("?.", (a, b) => b && (a = compile(a), (ctx) => a(ctx)?.[b]));
316
- operator("(", (a, b, container, args, path, optional) => a[0] === "?." && (a[2] || Array.isArray(a[1])) && (args = !b ? () => [] : b[0] === "," ? (b = b.slice(1).map(compile), (ctx) => b.map((a2) => a2(ctx))) : (b = compile(b), (ctx) => [b(ctx)]), !a[2] && (optional = true, a = a[1]), a[0] === "[" ? path = compile(a[2]) : path = () => a[2], container = compile(a[1]), optional ? (ctx) => container(ctx)?.[path(ctx)]?.(...args(ctx)) : (ctx) => container(ctx)?.[path(ctx)](...args(ctx))));
317
-
318
- // node_modules/subscript/feature/spread.js
319
- unary("...", PREC_PREFIX);
320
- operator("...", (a) => (a = compile(a), (ctx) => Object.entries(a(ctx))));
321
-
322
- // node_modules/subscript/justin.js
323
- binary("in", PREC_COMP), operator("in", (a, b) => b && (a = compile_default(a), b = compile_default(b), (ctx) => a(ctx) in b(ctx)));
324
- binary("===", PREC_EQ), binary("!==", 9);
325
- operator("===", (a, b) => (a = compile_default(a), b = compile_default(b), (ctx) => a(ctx) === b(ctx)));
326
- operator("!==", (a, b) => (a = compile_default(a), b = compile_default(b), (ctx) => a(ctx) !== b(ctx)));
327
- binary("??", PREC_LOR);
328
- operator("??", (a, b) => b && (a = compile_default(a), b = compile_default(b), (ctx) => a(ctx) ?? b(ctx)));
329
- binary("??=", PREC_ASSIGN, true);
330
- operator("??=", (a, b) => (b = compile_default(b), prop(a, (obj, path, ctx) => obj[path] ??= b(ctx))));
331
- binary("||=", PREC_ASSIGN, true);
332
- operator("||=", (a, b) => (b = compile_default(b), prop(a, (obj, path, ctx) => obj[path] ||= b(ctx))));
333
- binary("&&=", PREC_ASSIGN, true);
334
- operator("&&=", (a, b) => (b = compile_default(b), prop(a, (obj, path, ctx) => obj[path] &&= b(ctx))));
335
- token("undefined", 20, (a) => a ? err2() : [, void 0]);
336
- token("NaN", 20, (a) => a ? err2() : [, NaN]);
337
- token("null", 20, (a) => a ? err2() : [, null]);
338
- var justin_default = subscript_default;
339
-
340
7
  // core.js
341
8
  var _dispose = Symbol.dispose ||= Symbol("dispose");
342
9
  var SPRAE = `\u2234`;
343
- var { signal: signal2, effect: effect2, batch: batch2, computed: computed2, untracked: untracked2 } = ulive_es_exports;
10
+ var signal;
11
+ var effect;
12
+ var batch;
13
+ var computed;
14
+ var untracked;
344
15
  var directive = {};
345
16
  var memo = /* @__PURE__ */ new WeakMap();
346
17
  function sprae(container, values) {
@@ -351,7 +22,7 @@ function sprae(container, values) {
351
22
  for (let k in values) {
352
23
  state2[k] = values[k];
353
24
  }
354
- untracked2(() => {
25
+ untracked(() => {
355
26
  for (let fx of effects2)
356
27
  fx();
357
28
  });
@@ -366,9 +37,11 @@ function sprae(container, values) {
366
37
  el.removeAttribute(attr2.name);
367
38
  let names = attr2.name.slice(1).split(":");
368
39
  for (let name of names) {
369
- let update = (directive[name] || directive.default)(el, attr2.value, state, name);
40
+ let dir = directive[name] || directive.default;
41
+ let evaluate = (dir.parse || parse)(attr2.value, parse);
42
+ let update = dir(el, evaluate, state, name);
370
43
  if (update) {
371
- update[_dispose] = effect2(update);
44
+ update[_dispose] = effect(update);
372
45
  effects.push(update);
373
46
  }
374
47
  }
@@ -402,195 +75,183 @@ function sprae(container, values) {
402
75
  return state;
403
76
  }
404
77
  var evalMemo = {};
405
- var compile2 = (expr2, dir, evaluate) => {
406
- if (evaluate = evalMemo[expr2 = expr2.trim()])
407
- return evaluate;
78
+ var parse = (expr, dir, fn) => {
79
+ if (fn = evalMemo[expr = expr.trim()])
80
+ return fn;
408
81
  try {
409
- evaluate = justin_default(expr2);
82
+ fn = compile(expr);
410
83
  } catch (e) {
411
- throw Object.assign(e, { message: `${SPRAE} ${e.message}
84
+ throw Object.assign(e, { message: `\u2234 ${e.message}
412
85
 
413
- ${dir}${expr2 ? `="${expr2}"
86
+ ${dir}${expr ? `="${expr}"
414
87
 
415
- ` : ""}`, expr: expr2 });
88
+ ` : ""}`, expr });
416
89
  }
417
- return evalMemo[expr2] = evaluate;
418
- };
419
- var swap2 = swap_inflate_default;
420
- var ipol = (v, state) => {
421
- return v?.replace ? v.replace(/\$<([^>]+)>/g, (match, field) => state[field]?.valueOf?.() ?? "") : v;
90
+ fn.expr = expr;
91
+ return evalMemo[expr] = fn;
422
92
  };
93
+ var compile;
94
+ var swap;
423
95
  sprae.use = (s) => {
424
- s.signal && (signal2 = s.signal, effect2 = s.effect, computed2 = s.computed, batch2 = s.batch || ((fn) => fn()), untracked2 = s.untracked || batch2);
425
- s.swap && (swap2 = s.swap);
96
+ s.signal && (signal = s.signal, effect = s.effect, computed = s.computed, batch = s.batch || ((fn) => fn()), untracked = s.untracked || batch);
97
+ s.swap && (swap = s.swap);
98
+ s.compile && (compile = s.compile);
426
99
  };
427
100
 
101
+ // signal.js
102
+ var signal_exports = {};
103
+ __export(signal_exports, {
104
+ batch: () => batch2,
105
+ computed: () => computed2,
106
+ effect: () => effect2,
107
+ signal: () => signal2,
108
+ untracked: () => untracked2
109
+ });
110
+ var current;
111
+ var signal2 = (v, s, obs = /* @__PURE__ */ new Set()) => (s = {
112
+ get value() {
113
+ current?.deps.push(obs.add(current));
114
+ return v;
115
+ },
116
+ set value(val) {
117
+ if (val === v)
118
+ return;
119
+ v = val;
120
+ for (let sub of obs)
121
+ sub(val);
122
+ },
123
+ peek() {
124
+ return v;
125
+ }
126
+ }, s.toJSON = s.then = s.toString = s.valueOf = () => s.value, s);
127
+ var effect2 = (fn, teardown, run, deps) => (run = (prev) => {
128
+ teardown?.call?.();
129
+ prev = current, current = run;
130
+ try {
131
+ teardown = fn();
132
+ } finally {
133
+ current = prev;
134
+ }
135
+ }, deps = run.deps = [], run(), (dep) => {
136
+ teardown?.call?.();
137
+ while (dep = deps.pop())
138
+ dep.delete(run);
139
+ });
140
+ var computed2 = (fn, s = signal2(), c, e) => (c = {
141
+ get value() {
142
+ e ||= effect2(() => s.value = fn());
143
+ return s.value;
144
+ },
145
+ peek: s.peek
146
+ }, c.toJSON = c.then = c.toString = c.valueOf = () => c.value, c);
147
+ var batch2 = (fn) => fn();
148
+ var untracked2 = (fn, prev, v) => (prev = current, current = null, v = fn(), current = prev, v);
149
+
150
+ // node_modules/swapdom/deflate.js
151
+ var swap2 = (parent, a, b, end = null, { remove, insert } = swap2) => {
152
+ let i = 0, cur, next, bi, bidx = new Set(b);
153
+ while (bi = a[i++])
154
+ !bidx.has(bi) ? remove(bi, parent) : cur = cur || bi;
155
+ cur = cur || end, i = 0;
156
+ while (bi = b[i++]) {
157
+ next = cur ? cur.nextSibling : end;
158
+ if (cur === bi)
159
+ cur = next;
160
+ else {
161
+ if (b[i] === next)
162
+ cur = next;
163
+ insert(bi, cur, parent);
164
+ }
165
+ }
166
+ return b;
167
+ };
168
+ swap2.insert = (a, b, parent) => parent.insertBefore(a, b);
169
+ swap2.remove = (a, parent) => parent.removeChild(a);
170
+ var deflate_default = swap2;
171
+
428
172
  // directive/each.js
429
173
  var _each = Symbol(":each");
430
174
  var keys = {};
431
- directive.each = (tpl, expr2, state, name) => {
432
- let [leftSide, itemsExpr] = expr2.split(/\s+in\s+/);
433
- let [itemVar, idxVar = "_$"] = leftSide.split(/\s*,\s*/);
434
- const holder = tpl[_each] = document.createTextNode("");
175
+ var _key = Symbol("key");
176
+ (directive.each = (tpl, [itemVar, idxVar, evaluate], state) => {
177
+ const holder = tpl[_each] = document.createTextNode(""), parent = tpl.parentNode;
435
178
  tpl.replaceWith(holder);
436
- const evaluate = compile2(itemsExpr, name);
437
- const memo2 = /* @__PURE__ */ new WeakMap();
438
- tpl.removeAttribute(":key");
439
- let cur2 = [];
179
+ const elCache = /* @__PURE__ */ new WeakMap(), stateCache = /* @__PURE__ */ new WeakMap();
180
+ let cur = [];
181
+ const remove = (el) => {
182
+ el.remove();
183
+ el[Symbol.dispose]?.();
184
+ if (el[_key]) {
185
+ elCache.delete(el[_key]);
186
+ stateCache.delete(el[_key]);
187
+ }
188
+ }, { insert, replace } = swap;
189
+ const options = { remove, insert, replace };
440
190
  return () => {
441
191
  let items = evaluate(state)?.valueOf(), els = [];
442
192
  if (typeof items === "number")
443
193
  items = Array.from({ length: items }, (_, i) => i);
444
- const count = /* @__PURE__ */ new WeakSet();
445
- for (let idx2 in items) {
446
- let item = items[idx2];
447
- let substate = Object.create(state, { [idxVar]: { value: idx2 } });
194
+ const count = /* @__PURE__ */ new WeakMap();
195
+ for (let idx in items) {
196
+ let el, item = items[idx], key = item?.key ?? item?.id ?? item ?? idx;
197
+ key = Object(key) !== key ? keys[key] ||= Object(key) : item;
198
+ if (key == null || count.has(key) || tpl.content)
199
+ el = (tpl.content || tpl).cloneNode(true);
200
+ else
201
+ count.set(key, 1), (el = elCache.get(key) || (elCache.set(key, tpl.cloneNode(true)), elCache.get(key)))[_key] = key;
202
+ let substate = stateCache.get(key) || (stateCache.set(key, Object.create(state, { [idxVar]: { value: idx } })), stateCache.get(key));
448
203
  substate[itemVar] = item;
449
- let el, key = item.key ?? item.id ?? item;
450
- if (key == null)
451
- el = tpl.cloneNode(true);
452
- else {
453
- if (Object(key) !== key)
454
- key = keys[key] ||= Object(key);
455
- if (count.has(key)) {
456
- console.warn("Duplicate key", key), el = tpl.cloneNode(true);
457
- } else {
458
- count.add(key);
459
- el = memo2.get(key) || memo2.set(key, tpl.cloneNode(true)).get(key);
460
- }
461
- }
462
- if (el.content)
463
- el = el.content.cloneNode(true);
464
204
  sprae(el, substate);
465
205
  if (el.nodeType === 11)
466
206
  els.push(...el.childNodes);
467
207
  else
468
208
  els.push(el);
469
209
  }
470
- swap2(holder.parentNode, cur2, cur2 = els, holder);
210
+ swap(parent, cur, cur = els, holder, options);
471
211
  };
212
+ }).parse = (expr, parse2) => {
213
+ let [leftSide, itemsExpr] = expr.split(/\s+in\s+/);
214
+ let [itemVar, idxVar = "$"] = leftSide.split(/\s*,\s*/);
215
+ return [itemVar, idxVar, parse2(itemsExpr)];
472
216
  };
473
217
 
474
218
  // directive/if.js
475
219
  var _prevIf = Symbol("if");
476
- directive.if = (ifEl, expr2, state, name) => {
477
- let parent = ifEl.parentNode, next2 = ifEl.nextElementSibling, holder = document.createTextNode(""), evaluate = compile2(expr2, name), cur2, ifs, elses, none = [];
220
+ directive.if = (ifEl, evaluate, state) => {
221
+ let parent = ifEl.parentNode, next = ifEl.nextElementSibling, holder = document.createTextNode(""), cur, ifs, elses, none = [];
478
222
  ifEl.after(holder);
479
223
  if (ifEl.content)
480
- cur2 = none, ifEl.remove(), ifs = [...ifEl.content.childNodes];
224
+ cur = none, ifEl.remove(), ifs = [...ifEl.content.childNodes];
481
225
  else
482
- ifs = cur2 = [ifEl];
483
- if (next2?.hasAttribute(":else")) {
484
- next2.removeAttribute(":else");
485
- if (next2.hasAttribute(":if"))
226
+ ifs = cur = [ifEl];
227
+ if (next?.hasAttribute(":else")) {
228
+ next.removeAttribute(":else");
229
+ if (next.hasAttribute(":if"))
486
230
  elses = none;
487
231
  else
488
- next2.remove(), elses = next2.content ? [...next2.content.childNodes] : [next2];
232
+ next.remove(), elses = next.content ? [...next.content.childNodes] : [next];
489
233
  } else
490
234
  elses = none;
491
235
  return () => {
492
236
  const newEls = evaluate(state)?.valueOf() ? ifs : ifEl[_prevIf] ? none : elses;
493
- if (next2)
494
- next2[_prevIf] = newEls === ifs;
495
- if (cur2 != newEls) {
496
- if (cur2[0]?.[_each])
497
- cur2 = [cur2[0][_each]];
498
- swap2(parent, cur2, cur2 = newEls, holder);
499
- for (let el of cur2)
237
+ if (next)
238
+ next[_prevIf] = newEls === ifs;
239
+ if (cur != newEls) {
240
+ if (cur[0]?.[_each])
241
+ cur = [cur[0][_each]];
242
+ swap(parent, cur, cur = newEls, holder);
243
+ for (let el of cur)
500
244
  sprae(el, state);
501
245
  }
502
246
  };
503
247
  };
504
248
 
505
- // directive/ref.js
506
- directive.ref = (el, expr2, state) => {
507
- let prev;
508
- return () => {
509
- if (prev)
510
- delete state[prev];
511
- state[prev = ipol(expr2, state)] = el;
512
- };
513
- };
514
-
515
- // directive/scope.js
516
- directive.scope = (el, expr2, rootState, name) => {
517
- let evaluate = compile2(expr2, name);
518
- return () => {
519
- sprae(el, { ...rootState, ...evaluate(rootState)?.valueOf?.() || {} });
520
- };
521
- };
522
-
523
- // directive/html.js
524
- directive.html = (el, expr2, state, name) => {
525
- let evaluate = compile2(expr2, name), tpl = evaluate(state);
526
- if (!tpl)
527
- return;
528
- let content = (tpl.content || tpl).cloneNode(true);
529
- el.replaceChildren(content);
530
- sprae(el, state);
531
- };
532
-
533
- // directive/text.js
534
- directive.text = (el, expr2, state) => {
535
- let evaluate = compile2(expr2, "text");
536
- if (el.content)
537
- el.replaceWith(el = document.createTextNode(""));
538
- return () => {
539
- let value = evaluate(state)?.valueOf();
540
- el.textContent = value == null ? "" : value;
541
- };
542
- };
543
-
544
- // directive/class.js
545
- directive.class = (el, expr2, state) => {
546
- let evaluate = compile2(expr2, "class");
547
- let cur2 = /* @__PURE__ */ new Set();
548
- return () => {
549
- let v = evaluate(state);
550
- let clsx = /* @__PURE__ */ new Set();
551
- if (v) {
552
- if (typeof v === "string")
553
- ipol(v?.valueOf?.(), state).split(" ").map((cls) => clsx.add(cls));
554
- else if (Array.isArray(v))
555
- v.map((v2) => (v2 = ipol(v2?.valueOf?.(), state)) && clsx.add(v2));
556
- else
557
- Object.entries(v).map(([k, v2]) => v2?.valueOf?.() && clsx.add(k));
558
- }
559
- for (let cls of cur2)
560
- if (clsx.has(cls))
561
- clsx.delete(cls);
562
- else
563
- el.classList.remove(cls);
564
- for (let cls of cur2 = clsx)
565
- el.classList.add(cls);
566
- };
567
- };
568
-
569
- // directive/style.js
570
- directive.style = (el, expr2, state) => {
571
- let evaluate = compile2(expr2, "style");
572
- let initStyle = el.getAttribute("style") || "";
573
- if (!initStyle.endsWith(";"))
574
- initStyle += "; ";
575
- return () => {
576
- let v = evaluate(state)?.valueOf();
577
- if (typeof v === "string")
578
- el.setAttribute("style", initStyle + ipol(v, state));
579
- else {
580
- el.setAttribute("style", initStyle);
581
- for (let k in v)
582
- el.style.setProperty(k, ipol(v[k], state));
583
- }
584
- };
585
- };
586
-
587
249
  // directive/default.js
588
- directive.default = (el, expr2, state, name) => {
250
+ directive.default = (el, evaluate, state, name) => {
589
251
  let evt = name.startsWith("on") && name.slice(2);
590
- let evaluate = compile2(expr2, name);
591
252
  if (evt) {
592
253
  let off;
593
- return () => (off?.(), off = on(el, evt, evaluate(state)));
254
+ return () => (off?.(), off = on(el, evt, evaluate(state)?.valueOf()));
594
255
  }
595
256
  return () => {
596
257
  let value = evaluate(state)?.valueOf();
@@ -720,10 +381,90 @@ var debounce = (fn, wait) => {
720
381
  var dashcase = (str) => {
721
382
  return str.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (match) => "-" + match.toLowerCase());
722
383
  };
384
+ var ipol = (v, state) => {
385
+ return v?.replace ? v.replace(/\$<([^>]+)>/g, (match, field) => state[field]?.valueOf?.() ?? "") : v;
386
+ };
387
+
388
+ // directive/ref.js
389
+ (directive.ref = (el, expr, state) => {
390
+ let prev;
391
+ return () => {
392
+ if (prev)
393
+ delete state[prev];
394
+ state[prev = ipol(expr, state)] = el;
395
+ };
396
+ }).parse = (expr) => expr;
397
+
398
+ // directive/scope.js
399
+ directive.scope = (el, evaluate, rootState) => {
400
+ return () => {
401
+ sprae(el, { ...rootState, ...evaluate(rootState)?.valueOf?.() || {} });
402
+ };
403
+ };
404
+
405
+ // directive/html.js
406
+ directive.html = (el, evaluate, state) => {
407
+ let tpl = evaluate(state);
408
+ if (!tpl)
409
+ return;
410
+ let content = (tpl.content || tpl).cloneNode(true);
411
+ el.replaceChildren(content);
412
+ sprae(el, state);
413
+ };
414
+
415
+ // directive/text.js
416
+ directive.text = (el, evaluate, state) => {
417
+ if (el.content)
418
+ el.replaceWith(el = document.createTextNode(""));
419
+ return () => {
420
+ let value = evaluate(state)?.valueOf();
421
+ el.textContent = value == null ? "" : value;
422
+ };
423
+ };
424
+
425
+ // directive/class.js
426
+ directive.class = (el, evaluate, state) => {
427
+ let cur = /* @__PURE__ */ new Set();
428
+ return () => {
429
+ let v = evaluate(state);
430
+ let clsx = /* @__PURE__ */ new Set();
431
+ if (v) {
432
+ if (typeof v === "string")
433
+ ipol(v?.valueOf?.(), state).split(" ").map((cls) => clsx.add(cls));
434
+ else if (Array.isArray(v))
435
+ v.map((v2) => (v2 = ipol(v2?.valueOf?.(), state)) && clsx.add(v2));
436
+ else
437
+ Object.entries(v).map(([k, v2]) => v2?.valueOf?.() && clsx.add(k));
438
+ }
439
+ for (let cls of cur)
440
+ if (clsx.has(cls))
441
+ clsx.delete(cls);
442
+ else
443
+ el.classList.remove(cls);
444
+ for (let cls of cur = clsx)
445
+ el.classList.add(cls);
446
+ };
447
+ };
448
+
449
+ // directive/style.js
450
+ directive.style = (el, evaluate, state) => {
451
+ let initStyle = el.getAttribute("style") || "";
452
+ if (!initStyle.endsWith(";"))
453
+ initStyle += "; ";
454
+ return () => {
455
+ let v = evaluate(state)?.valueOf();
456
+ if (typeof v === "string")
457
+ el.setAttribute("style", initStyle + ipol(v, state));
458
+ else {
459
+ el.setAttribute("style", initStyle);
460
+ for (let k in v)
461
+ el.style.setProperty(k, ipol(v[k], state));
462
+ }
463
+ };
464
+ };
723
465
 
724
466
  // directive/value.js
725
- directive.value = (el, expr2, state) => {
726
- let evaluate = compile2(expr2, "value");
467
+ directive.value = (el, evaluate, state) => {
727
468
  let from, to;
728
469
  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.checked = value, attr(el, "checked", value)) : el.type === "select-one" ? (value) => {
729
470
  for (let option in el.options)
@@ -735,19 +476,23 @@ directive.value = (el, expr2, state) => {
735
476
  };
736
477
 
737
478
  // directive/fx.js
738
- directive.fx = (el, expr2, state, name) => {
739
- let evaluate = compile2(expr2, name);
479
+ directive.fx = (el, evaluate, state) => {
740
480
  return () => evaluate(state);
741
481
  };
482
+
483
+ // sprae.js
484
+ sprae.use(signal_exports);
485
+ sprae.use({ compile: (expr) => sprae.constructor(`__scope`, `with (__scope) { return ${expr} };`) });
486
+ sprae.use({ swap: deflate_default });
487
+ var sprae_default = sprae;
742
488
  export {
743
- batch2 as batch,
744
- compile2 as compile,
745
- computed2 as computed,
746
- sprae as default,
489
+ batch,
490
+ compile,
491
+ computed,
492
+ sprae_default as default,
747
493
  directive,
748
- effect2 as effect,
749
- ipol,
750
- signal2 as signal,
751
- swap2 as swap,
752
- untracked2 as untracked
494
+ effect,
495
+ signal,
496
+ swap,
497
+ untracked
753
498
  };