sprae 9.1.0 → 10.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/dist/sprae.js CHANGED
@@ -4,50 +4,223 @@ 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);
7
+ // signal.js
8
+ var signal;
9
+ var effect;
10
+ var untracked;
11
+ var batch;
12
+ var computed;
13
+ function use(s) {
14
+ signal = s.signal;
15
+ effect = s.effect;
16
+ computed = s.computed;
17
+ batch = s.batch || ((fn) => fn());
18
+ untracked = s.untracked || batch;
19
+ }
20
+
21
+ // store.js
22
+ var _signals = Symbol("signals");
23
+ var _change = Symbol("length");
24
+ function store(values, signals) {
25
+ if (!values)
26
+ return values;
27
+ if (values[_signals] && !signals)
28
+ return values;
29
+ if (Array.isArray(values))
30
+ return list(values);
31
+ if (values.constructor !== Object)
32
+ return values;
33
+ let _len = signal(Object.values(values).length);
34
+ signals ||= {};
35
+ const state = new Proxy(signals, {
36
+ get: (_, key) => key === _change ? _len : key === _signals ? signals : signals[key]?.valueOf(),
37
+ set: (_, key, v, s) => (s = signals[key], set(signals, key, v), s || ++_len.value),
38
+ deleteProperty: (_, key) => del(signals, key) && _len.value--,
39
+ ownKeys() {
40
+ _len.value;
41
+ return Reflect.ownKeys(signals);
42
+ }
43
+ });
44
+ if (values[_signals])
45
+ for (let key in values)
46
+ signals[key] = values[_signals][key];
47
+ else
48
+ for (let key in values) {
49
+ const desc = Object.getOwnPropertyDescriptor(values, key);
50
+ if (desc?.get) {
51
+ (signals[key] = computed(desc.get.bind(state)))._set = desc.set?.bind(state);
52
+ } else {
53
+ signals[key] = null;
54
+ set(signals, key, values[key]);
55
+ }
27
56
  }
28
- while (!same(cur2, end))
29
- next2 = cur2.nextSibling, remove(cur2, parent), cur2 = next2;
57
+ return state;
58
+ }
59
+ function list(values) {
60
+ let lastProp;
61
+ if (values[_signals])
62
+ return values;
63
+ let _len = signal(values.length), signals = Array(values.length).fill(null);
64
+ const state = new Proxy(signals, {
65
+ get(_, key) {
66
+ if (key === _change)
67
+ return _len;
68
+ if (key === _signals)
69
+ return signals;
70
+ if (key === "length")
71
+ return Array.prototype[lastProp] ? _len.peek() : _len.value;
72
+ lastProp = key;
73
+ if (signals[key])
74
+ return signals[key].valueOf();
75
+ if (key < signals.length)
76
+ return (signals[key] = signal(store(values[key]))).value;
77
+ },
78
+ set(_, key, v) {
79
+ if (key === "length") {
80
+ for (let i = v, l = signals.length; i < l; i++)
81
+ delete state[i];
82
+ _len.value = signals.length = v;
83
+ return true;
84
+ }
85
+ set(signals, key, v);
86
+ if (key >= _len.peek())
87
+ _len.value = signals.length = Number(key) + 1;
88
+ return true;
89
+ },
90
+ deleteProperty: (_, key) => (del(signals, key), true)
91
+ });
92
+ return state;
93
+ }
94
+ function set(signals, key, v) {
95
+ let s = signals[key];
96
+ if (!s) {
97
+ signals[key] = s = v?.peek ? v : signal(store(v));
98
+ } else if (v === s.peek())
99
+ ;
100
+ else if (s._set)
101
+ s._set(v);
102
+ else if (Array.isArray(v) && Array.isArray(s.peek())) {
103
+ const cur = s.peek();
104
+ if (cur[_change])
105
+ untracked(() => {
106
+ batch(() => {
107
+ let i = 0, l = v.length;
108
+ for (; i < l; i++)
109
+ cur[i] = v[i];
110
+ cur.length = l;
111
+ });
112
+ });
113
+ else {
114
+ s.value = v;
115
+ }
116
+ } else {
117
+ s.value = store(v);
30
118
  }
31
- return b;
119
+ }
120
+ function del(signals, key) {
121
+ const s = signals[key];
122
+ if (s) {
123
+ const del2 = s[Symbol.dispose];
124
+ if (del2)
125
+ delete s[Symbol.dispose];
126
+ delete signals[key];
127
+ del2?.();
128
+ return true;
129
+ }
130
+ }
131
+
132
+ // core.js
133
+ var _dispose = Symbol.dispose ||= Symbol("dispose");
134
+ var SPRAE = `\u2234`;
135
+ var directive = {};
136
+ var memo = /* @__PURE__ */ new WeakMap();
137
+ function sprae(els, values) {
138
+ let state;
139
+ if (!els?.[Symbol.iterator])
140
+ els = [els];
141
+ for (let el of els) {
142
+ if (el?.children) {
143
+ if (memo.has(el)) {
144
+ Object.assign(memo.get(el), values);
145
+ } else {
146
+ state ||= store(values || {});
147
+ init(el, state);
148
+ if (!memo.has(el))
149
+ memo.set(el, state);
150
+ }
151
+ }
152
+ }
153
+ ;
154
+ return state;
155
+ }
156
+ function init(el, state, parent = el.parentNode, effects = []) {
157
+ if (el.attributes) {
158
+ for (let i = 0; i < el.attributes.length; ) {
159
+ let attr2 = el.attributes[i];
160
+ if (attr2.name[0] === ":") {
161
+ el.removeAttribute(attr2.name);
162
+ let names = attr2.name.slice(1).split(":");
163
+ for (let name of names) {
164
+ let dir = directive[name] || directive.default;
165
+ let evaluate = (dir.parse || parse)(attr2.value, parse);
166
+ let dispose = dir(el, evaluate, state, name);
167
+ if (dispose)
168
+ effects.push(dispose);
169
+ }
170
+ if (memo.has(el))
171
+ return;
172
+ if (el.parentNode !== parent)
173
+ return;
174
+ } else
175
+ i++;
176
+ }
177
+ }
178
+ for (let child of [...el.children])
179
+ init(child, state, el);
180
+ el.classList?.add(SPRAE);
181
+ el[_dispose] = () => {
182
+ while (effects.length)
183
+ effects.pop()();
184
+ el.classList.remove(SPRAE);
185
+ memo.delete(el);
186
+ let els = el.getElementsByClassName(SPRAE);
187
+ while (els.length)
188
+ els[0][_dispose]?.();
189
+ };
190
+ }
191
+ var evalMemo = {};
192
+ var parse = (expr, dir, fn) => {
193
+ if (fn = evalMemo[expr = expr.trim()])
194
+ return fn;
195
+ try {
196
+ fn = compile(expr);
197
+ } catch (e) {
198
+ throw Object.assign(e, { message: `\u2234 ${e.message}
199
+
200
+ ${dir}${expr ? `="${expr}"
201
+
202
+ ` : ""}`, expr });
203
+ }
204
+ return evalMemo[expr] = fn;
205
+ };
206
+ var compile;
207
+ sprae.use = (s) => {
208
+ s.signal && use(s);
209
+ s.compile && (compile = s.compile);
32
210
  };
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
211
 
39
212
  // node_modules/ulive/dist/ulive.es.js
40
213
  var ulive_es_exports = {};
41
214
  __export(ulive_es_exports, {
42
- batch: () => batch,
43
- computed: () => computed,
44
- current: () => current,
45
- effect: () => effect,
46
- signal: () => signal,
47
- untracked: () => untracked
215
+ batch: () => batch2,
216
+ computed: () => computed2,
217
+ effect: () => effect2,
218
+ signal: () => signal2,
219
+ untracked: () => untracked2
48
220
  });
49
221
  var current;
50
- var signal = (v, s, obs = /* @__PURE__ */ new Set()) => (s = {
222
+ var batched;
223
+ var signal2 = (v, s, obs = /* @__PURE__ */ new Set()) => (s = {
51
224
  get value() {
52
225
  current?.deps.push(obs.add(current));
53
226
  return v;
@@ -57,549 +230,187 @@ var signal = (v, s, obs = /* @__PURE__ */ new Set()) => (s = {
57
230
  return;
58
231
  v = val;
59
232
  for (let sub of obs)
60
- sub(val);
233
+ batched ? batched.add(sub) : sub();
61
234
  },
62
235
  peek() {
63
236
  return v;
64
237
  }
65
238
  }, s.toJSON = s.then = s.toString = s.valueOf = () => s.value, s);
66
- var effect = (fn, teardown, run, deps) => (run = (prev) => {
239
+ var effect2 = (fn, teardown, fx, deps) => (fx = (prev) => {
67
240
  teardown?.call?.();
68
- prev = current, current = run;
241
+ prev = current, current = fx;
69
242
  try {
70
243
  teardown = fn();
71
244
  } finally {
72
245
  current = prev;
73
246
  }
74
- }, deps = run.deps = [], run(), (dep) => {
247
+ }, deps = fx.deps = [], fx(), (dep) => {
75
248
  teardown?.call?.();
76
249
  while (dep = deps.pop())
77
- dep.delete(run);
250
+ dep.delete(fx);
78
251
  });
79
- var computed = (fn, s = signal(), c, e) => (c = {
252
+ var computed2 = (fn, s = signal2(), c, e) => (c = {
80
253
  get value() {
81
- e ||= effect(() => s.value = fn());
254
+ e ||= effect2(() => s.value = fn());
82
255
  return s.value;
83
256
  },
84
257
  peek: s.peek
85
258
  }, 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
- // core.js
341
- var _dispose = Symbol.dispose ||= Symbol("dispose");
342
- var SPRAE = `\u2234`;
343
- var { signal: signal2, effect: effect2, batch: batch2, computed: computed2, untracked: untracked2 } = ulive_es_exports;
344
- var directive = {};
345
- var memo = /* @__PURE__ */ new WeakMap();
346
- function sprae(container, values) {
347
- if (!container.children)
348
- return;
349
- if (memo.has(container)) {
350
- const [state2, effects2] = memo.get(container);
351
- for (let k in values) {
352
- state2[k] = values[k];
353
- }
354
- untracked2(() => {
355
- for (let fx of effects2)
259
+ var batch2 = (fn) => {
260
+ let fxs = batched;
261
+ if (!fxs)
262
+ batched = /* @__PURE__ */ new Set();
263
+ try {
264
+ fn();
265
+ } finally {
266
+ if (!fxs) {
267
+ fxs = batched;
268
+ batched = null;
269
+ for (const fx of fxs)
356
270
  fx();
357
- });
358
- }
359
- const state = values || {};
360
- const effects = [];
361
- const init = (el, parent = el.parentNode) => {
362
- if (el.attributes) {
363
- for (let i = 0; i < el.attributes.length; ) {
364
- let attr2 = el.attributes[i];
365
- if (attr2.name[0] === ":") {
366
- el.removeAttribute(attr2.name);
367
- let names = attr2.name.slice(1).split(":");
368
- for (let name of names) {
369
- let update = (directive[name] || directive.default)(el, attr2.value, state, name);
370
- if (update) {
371
- update[_dispose] = effect2(update);
372
- effects.push(update);
373
- }
374
- }
375
- if (memo.has(el))
376
- return;
377
- if (el.parentNode !== parent)
378
- return false;
379
- } else
380
- i++;
381
- }
382
271
  }
383
- for (let i = 0, child; child = el.children[i]; i++) {
384
- if (init(child, el) === false)
385
- i--;
386
- }
387
- };
388
- init(container);
389
- if (memo.has(container))
390
- return state;
391
- memo.set(container, [state, effects]);
392
- container.classList?.add(SPRAE);
393
- container[_dispose] = () => {
394
- while (effects.length)
395
- effects.pop()[_dispose]();
396
- container.classList.remove(SPRAE);
397
- memo.delete(container);
398
- let els = container.getElementsByClassName(SPRAE);
399
- while (els.length)
400
- els[0][_dispose]?.();
401
- };
402
- return state;
403
- }
404
- var evalMemo = {};
405
- var compile2 = (expr2, dir, evaluate) => {
406
- if (evaluate = evalMemo[expr2 = expr2.trim()])
407
- return evaluate;
408
- try {
409
- evaluate = justin_default(expr2);
410
- } catch (e) {
411
- throw Object.assign(e, { message: `${SPRAE} ${e.message}
412
-
413
- ${dir}${expr2 ? `="${expr2}"
414
-
415
- ` : ""}`, expr: expr2 });
416
272
  }
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;
422
273
  };
423
- 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);
274
+ var untracked2 = (fn, prev, v) => (prev = current, current = null, v = fn(), current = prev, v);
275
+
276
+ // node_modules/swapdom/deflate.js
277
+ var swap = (parent, a, b, end = null, { remove, insert } = swap) => {
278
+ let i = 0, cur, next, bi, bidx = new Set(b);
279
+ while (bi = a[i++])
280
+ !bidx.has(bi) ? remove(bi, parent) : cur = cur || bi;
281
+ cur = cur || end, i = 0;
282
+ while (bi = b[i++]) {
283
+ next = cur ? cur.nextSibling : end;
284
+ if (cur === bi)
285
+ cur = next;
286
+ else {
287
+ if (b[i] === next)
288
+ cur = next;
289
+ insert(bi, cur, parent);
290
+ }
291
+ }
292
+ return b;
426
293
  };
294
+ swap.insert = (a, b, parent) => parent.insertBefore(a, b);
295
+ swap.remove = (a, parent) => parent.removeChild(a);
296
+ var deflate_default = swap;
427
297
 
428
298
  // directive/each.js
429
299
  var _each = Symbol(":each");
430
- 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*/);
300
+ directive.each = (tpl, [itemVar, idxVar, evaluate], state) => {
434
301
  const holder = tpl[_each] = document.createTextNode("");
435
302
  tpl.replaceWith(holder);
436
- const evaluate = compile2(itemsExpr, name);
437
- const memo2 = /* @__PURE__ */ new WeakMap();
438
- tpl.removeAttribute(":key");
439
- let cur2 = [];
440
- return () => {
441
- let items = evaluate(state)?.valueOf(), els = [];
442
- if (typeof items === "number")
443
- 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 } });
448
- 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);
303
+ let cur, keys2, prevl = 0;
304
+ const items = computed(() => {
305
+ keys2 = null;
306
+ let items2 = evaluate(state);
307
+ if (typeof items2 === "number")
308
+ items2 = Array.from({ length: items2 }, (_, i) => i + 1);
309
+ if (items2?.constructor === Object)
310
+ keys2 = Object.keys(items2), items2 = Object.values(items2);
311
+ return items2 || [];
312
+ });
313
+ const update = () => {
314
+ untracked(() => {
315
+ let i = 0, newItems = items.value, newl = newItems.length;
316
+ if (cur && !cur[_change]) {
317
+ for (let s of cur[_signals] || []) {
318
+ s[Symbol.dispose]();
319
+ }
320
+ cur = null, prevl = 0;
321
+ }
322
+ if (newl < prevl) {
323
+ cur.length = newl;
324
+ } else {
325
+ if (!cur) {
326
+ cur = newItems;
457
327
  } else {
458
- count.add(key);
459
- el = memo2.get(key) || memo2.set(key, tpl.cloneNode(true)).get(key);
328
+ for (; i < prevl; i++) {
329
+ cur[i] = newItems[i];
330
+ }
331
+ }
332
+ for (; i < newl; i++) {
333
+ cur[i] = newItems[i];
334
+ let idx = i, scope = Object.create(state, {
335
+ [itemVar]: { get() {
336
+ return cur[idx];
337
+ } },
338
+ [idxVar]: { value: keys2 ? keys2[idx] : idx }
339
+ }), el = (tpl.content || tpl).cloneNode(true), els = tpl.content ? [...el.childNodes] : [el];
340
+ holder.before(el);
341
+ sprae(els, scope);
342
+ ((cur[_signals] ||= [])[i] ||= {})[Symbol.dispose] = () => {
343
+ for (let el2 of els)
344
+ el2[Symbol.dispose](), el2.remove();
345
+ };
460
346
  }
461
347
  }
462
- if (el.content)
463
- el = el.content.cloneNode(true);
464
- sprae(el, substate);
465
- if (el.nodeType === 11)
466
- els.push(...el.childNodes);
467
- else
468
- els.push(el);
469
- }
470
- swap2(holder.parentNode, cur2, cur2 = els, holder);
348
+ prevl = newl;
349
+ });
471
350
  };
351
+ let planned = 0;
352
+ return effect(() => {
353
+ if (!cur)
354
+ items.value[_change]?.value;
355
+ if (!planned) {
356
+ update();
357
+ queueMicrotask(() => (planned && update(), planned = 0));
358
+ } else
359
+ planned++;
360
+ });
361
+ };
362
+ directive.each.parse = (expr, parse2) => {
363
+ let [leftSide, itemsExpr] = expr.split(/\s+in\s+/);
364
+ let [itemVar, idxVar = "$"] = leftSide.split(/\s*,\s*/);
365
+ return [itemVar, idxVar, parse2(itemsExpr)];
472
366
  };
473
367
 
474
368
  // directive/if.js
475
369
  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 = [];
370
+ directive.if = (ifEl, evaluate, state) => {
371
+ let parent = ifEl.parentNode, next = ifEl.nextElementSibling, holder = document.createTextNode(""), cur, ifs, elses, none = [];
478
372
  ifEl.after(holder);
479
373
  if (ifEl.content)
480
- cur2 = none, ifEl.remove(), ifs = [...ifEl.content.childNodes];
374
+ cur = none, ifEl.remove(), ifs = [...ifEl.content.childNodes];
481
375
  else
482
- ifs = cur2 = [ifEl];
483
- if (next2?.hasAttribute(":else")) {
484
- next2.removeAttribute(":else");
485
- if (next2.hasAttribute(":if"))
376
+ ifs = cur = [ifEl];
377
+ if (next?.hasAttribute(":else")) {
378
+ next.removeAttribute(":else");
379
+ if (next.hasAttribute(":if"))
486
380
  elses = none;
487
381
  else
488
- next2.remove(), elses = next2.content ? [...next2.content.childNodes] : [next2];
382
+ next.remove(), elses = next.content ? [...next.content.childNodes] : [next];
489
383
  } else
490
384
  elses = none;
491
- return () => {
492
- 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)
500
- sprae(el, state);
385
+ return effect(() => {
386
+ const newEls = evaluate(state) ? ifs : ifEl[_prevIf] ? none : elses;
387
+ if (next)
388
+ next[_prevIf] = newEls === ifs;
389
+ if (cur != newEls) {
390
+ if (cur[0]?.[_each])
391
+ cur = [cur[0][_each]];
392
+ for (let el of cur)
393
+ el.remove();
394
+ cur = newEls;
395
+ for (let el of cur)
396
+ parent.insertBefore(el, holder), sprae(el, state);
501
397
  }
502
- };
503
- };
504
-
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
- };
398
+ });
542
399
  };
543
400
 
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));
401
+ // directive/default.js
402
+ directive.default = (el, evaluate, state, name) => {
403
+ let evt = name.startsWith("on") && name.slice(2), off;
404
+ return effect(
405
+ evt ? () => (off?.(), off = on(el, evt, evaluate(state))) : () => {
406
+ let value = evaluate(state);
407
+ if (name)
408
+ attr(el, name, ipol(value, state));
556
409
  else
557
- Object.entries(v).map(([k, v2]) => v2?.valueOf?.() && clsx.add(k));
410
+ for (let key in value)
411
+ attr(el, dashcase(key), ipol(value[key], state));
558
412
  }
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
- // directive/default.js
588
- directive.default = (el, expr2, state, name) => {
589
- let evt = name.startsWith("on") && name.slice(2);
590
- let evaluate = compile2(expr2, name);
591
- if (evt) {
592
- let off;
593
- return () => (off?.(), off = on(el, evt, evaluate(state)));
594
- }
595
- return () => {
596
- let value = evaluate(state)?.valueOf();
597
- if (name)
598
- attr(el, name, ipol(value, state));
599
- else
600
- for (let key in value)
601
- attr(el, dashcase(key), ipol(value[key], state));
602
- };
413
+ );
603
414
  };
604
415
  var on = (el, e, fn = () => {
605
416
  }) => {
@@ -654,22 +465,22 @@ var mods = {
654
465
  return true;
655
466
  },
656
467
  self: (ctx) => (e) => e.target === ctx.target,
657
- ctrl: (_, ...param) => (e) => keys2.ctrl(e) && param.every((p) => keys2[p] ? keys2[p](e) : e.key === p),
658
- shift: (_, ...param) => (e) => keys2.shift(e) && param.every((p) => keys2[p] ? keys2[p](e) : e.key === p),
659
- alt: (_, ...param) => (e) => keys2.alt(e) && param.every((p) => keys2[p] ? keys2[p](e) : e.key === p),
660
- meta: (_, ...param) => (e) => keys2.meta(e) && param.every((p) => keys2[p] ? keys2[p](e) : e.key === p),
661
- arrow: () => keys2.arrow,
662
- enter: () => keys2.enter,
663
- escape: () => keys2.escape,
664
- tab: () => keys2.tab,
665
- space: () => keys2.space,
666
- backspace: () => keys2.backspace,
667
- delete: () => keys2.delete,
668
- digit: () => keys2.digit,
669
- letter: () => keys2.letter,
670
- character: () => keys2.character
468
+ ctrl: (_, ...param) => (e) => keys.ctrl(e) && param.every((p) => keys[p] ? keys[p](e) : e.key === p),
469
+ shift: (_, ...param) => (e) => keys.shift(e) && param.every((p) => keys[p] ? keys[p](e) : e.key === p),
470
+ alt: (_, ...param) => (e) => keys.alt(e) && param.every((p) => keys[p] ? keys[p](e) : e.key === p),
471
+ meta: (_, ...param) => (e) => keys.meta(e) && param.every((p) => keys[p] ? keys[p](e) : e.key === p),
472
+ arrow: () => keys.arrow,
473
+ enter: () => keys.enter,
474
+ escape: () => keys.escape,
475
+ tab: () => keys.tab,
476
+ space: () => keys.space,
477
+ backspace: () => keys.backspace,
478
+ delete: () => keys.delete,
479
+ digit: () => keys.digit,
480
+ letter: () => keys.letter,
481
+ character: () => keys.character
671
482
  };
672
- var keys2 = {
483
+ var keys = {
673
484
  ctrl: (e) => e.ctrlKey || e.key === "Control" || e.key === "Ctrl",
674
485
  shift: (e) => e.shiftKey || e.key === "Shift",
675
486
  alt: (e) => e.altKey || e.key === "Alt",
@@ -720,10 +531,94 @@ var debounce = (fn, wait) => {
720
531
  var dashcase = (str) => {
721
532
  return str.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (match) => "-" + match.toLowerCase());
722
533
  };
534
+ var ipol = (v, state) => {
535
+ return v?.replace ? v.replace(/\$<([^>]+)>/g, (match, field) => state[field] ?? "") : v;
536
+ };
537
+
538
+ // directive/ref.js
539
+ directive.ref = (el, expr, state) => {
540
+ Object.defineProperty(state, ipol(expr, state), { value: el });
541
+ };
542
+ directive.ref.parse = (expr) => expr;
543
+
544
+ // directive/with.js
545
+ directive.with = (el, evaluate, rootState) => {
546
+ let state, values;
547
+ return effect(() => {
548
+ values = evaluate(rootState);
549
+ Object.assign(state ||= sprae(
550
+ el,
551
+ store(
552
+ values,
553
+ Object.create(rootState[_signals])
554
+ )
555
+ ), values);
556
+ });
557
+ };
558
+
559
+ // directive/html.js
560
+ directive.html = (el, evaluate, state) => {
561
+ let tpl = evaluate(state);
562
+ if (!tpl)
563
+ return;
564
+ let content = (tpl.content || tpl).cloneNode(true);
565
+ el.replaceChildren(content);
566
+ sprae(el, state);
567
+ };
568
+
569
+ // directive/text.js
570
+ directive.text = (el, evaluate, state) => {
571
+ if (el.content)
572
+ el.replaceWith(el = document.createTextNode(""));
573
+ return effect(() => {
574
+ let value = evaluate(state);
575
+ el.textContent = value == null ? "" : value;
576
+ });
577
+ };
578
+
579
+ // directive/class.js
580
+ directive.class = (el, evaluate, state) => {
581
+ let cur = /* @__PURE__ */ new Set();
582
+ return effect(() => {
583
+ let v = evaluate(state);
584
+ let clsx = /* @__PURE__ */ new Set();
585
+ if (v) {
586
+ if (typeof v === "string")
587
+ ipol(v, state).split(" ").map((cls) => clsx.add(cls));
588
+ else if (Array.isArray(v))
589
+ v.map((v2) => (v2 = ipol(v2, state)) && clsx.add(v2));
590
+ else
591
+ Object.entries(v).map(([k, v2]) => v2 && clsx.add(k));
592
+ }
593
+ for (let cls of cur)
594
+ if (clsx.has(cls))
595
+ clsx.delete(cls);
596
+ else
597
+ el.classList.remove(cls);
598
+ for (let cls of cur = clsx)
599
+ el.classList.add(cls);
600
+ });
601
+ };
602
+
603
+ // directive/style.js
604
+ directive.style = (el, evaluate, state) => {
605
+ let initStyle = el.getAttribute("style") || "";
606
+ if (!initStyle.endsWith(";"))
607
+ initStyle += "; ";
608
+ return effect(() => {
609
+ let v = evaluate(state);
610
+ if (typeof v === "string")
611
+ el.setAttribute("style", initStyle + ipol(v, state));
612
+ else {
613
+ el.setAttribute("style", initStyle);
614
+ for (let k in v)
615
+ el.style.setProperty(k, ipol(v[k], state));
616
+ }
617
+ });
618
+ };
723
619
 
724
620
  // directive/value.js
725
- directive.value = (el, expr2, state) => {
726
- let evaluate = compile2(expr2, "value");
621
+ directive.value = (el, evaluate, state) => {
727
622
  let from, to;
728
623
  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
624
  for (let option in el.options)
@@ -731,23 +626,19 @@ directive.value = (el, expr2, state) => {
731
626
  el.value = value;
732
627
  el.selectedOptions[0]?.setAttribute("selected", "");
733
628
  } : (value) => el.value = value;
734
- return () => update(evaluate(state)?.valueOf?.());
629
+ return effect(() => update(evaluate(state)));
735
630
  };
736
631
 
737
632
  // directive/fx.js
738
- directive.fx = (el, expr2, state, name) => {
739
- let evaluate = compile2(expr2, name);
740
- return () => evaluate(state);
633
+ directive.fx = (el, evaluate, state) => {
634
+ return effect(() => evaluate(state));
741
635
  };
636
+
637
+ // sprae.js
638
+ sprae.use(ulive_es_exports);
639
+ sprae.use({ compile: (expr) => sprae.constructor(`__scope`, `with (__scope) { return ${expr} };`) });
640
+ sprae.use({ swap: deflate_default });
641
+ var sprae_default = sprae;
742
642
  export {
743
- batch2 as batch,
744
- compile2 as compile,
745
- computed2 as computed,
746
- sprae as default,
747
- directive,
748
- effect2 as effect,
749
- ipol,
750
- signal2 as signal,
751
- swap2 as swap,
752
- untracked2 as untracked
643
+ sprae_default as default
753
644
  };