sprae 9.1.0 → 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/core.js +1 -6
- package/directive/class.js +2 -1
- package/directive/default.js +6 -1
- package/directive/ref.js +2 -1
- package/directive/style.js +2 -1
- package/dist/sprae.js +237 -492
- package/dist/sprae.min.js +1 -1
- package/package.json +2 -2
- package/readme.md +32 -16
- package/signal.js +43 -0
- package/sprae.js +2 -2
package/core.js
CHANGED
|
@@ -105,17 +105,12 @@ const parse = (expr, dir, fn) => {
|
|
|
105
105
|
return evalMemo[expr] = fn
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
//
|
|
108
|
+
// compiler
|
|
109
109
|
export let compile
|
|
110
110
|
|
|
111
111
|
// DOM swapper
|
|
112
112
|
export let swap
|
|
113
113
|
|
|
114
|
-
// interpolate a$<b> fields from context
|
|
115
|
-
export const ipol = (v, state) => {
|
|
116
|
-
return v?.replace ? v.replace(/\$<([^>]+)>/g, (match, field) => state[field]?.valueOf?.() ?? '') : v
|
|
117
|
-
};
|
|
118
|
-
|
|
119
114
|
// configure signals/compile/differ
|
|
120
115
|
// it's more compact than using sprae.signal = signal etc.
|
|
121
116
|
sprae.use = s => {
|
package/directive/class.js
CHANGED
package/directive/default.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { directive
|
|
1
|
+
import { directive } from "../core.js";
|
|
2
2
|
|
|
3
3
|
// set generic property directive
|
|
4
4
|
directive.default = (el, evaluate, state, name) => {
|
|
@@ -145,3 +145,8 @@ const debounce = (fn, wait) => {
|
|
|
145
145
|
export const dashcase = (str) => {
|
|
146
146
|
return str.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, (match) => "-" + match.toLowerCase());
|
|
147
147
|
}
|
|
148
|
+
|
|
149
|
+
// interpolate a$<b> fields from context
|
|
150
|
+
export const ipol = (v, state) => {
|
|
151
|
+
return v?.replace ? v.replace(/\$<([^>]+)>/g, (match, field) => state[field]?.valueOf?.() ?? '') : v
|
|
152
|
+
};
|
package/directive/ref.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { directive
|
|
1
|
+
import { directive } from "../core.js";
|
|
2
|
+
import { ipol } from './default.js';
|
|
2
3
|
|
|
3
4
|
// ref must be last within primaries, since that must be skipped by :each, but before secondaries
|
|
4
5
|
(directive.ref = (el, expr, state) => {
|
package/directive/style.js
CHANGED
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
|
|
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
|
-
|
|
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
|
|
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] =
|
|
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
|
|
406
|
-
if (
|
|
407
|
-
return
|
|
78
|
+
var parse = (expr, dir, fn) => {
|
|
79
|
+
if (fn = evalMemo[expr = expr.trim()])
|
|
80
|
+
return fn;
|
|
408
81
|
try {
|
|
409
|
-
|
|
82
|
+
fn = compile(expr);
|
|
410
83
|
} catch (e) {
|
|
411
|
-
throw Object.assign(e, { message:
|
|
84
|
+
throw Object.assign(e, { message: `\u2234 ${e.message}
|
|
412
85
|
|
|
413
|
-
${dir}${
|
|
86
|
+
${dir}${expr ? `="${expr}"
|
|
414
87
|
|
|
415
|
-
` : ""}`, expr
|
|
88
|
+
` : ""}`, expr });
|
|
416
89
|
}
|
|
417
|
-
|
|
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 && (
|
|
425
|
-
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
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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
|
|
445
|
-
for (let
|
|
446
|
-
let item = items[
|
|
447
|
-
|
|
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
|
-
|
|
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,
|
|
477
|
-
let parent = ifEl.parentNode,
|
|
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
|
-
|
|
224
|
+
cur = none, ifEl.remove(), ifs = [...ifEl.content.childNodes];
|
|
481
225
|
else
|
|
482
|
-
ifs =
|
|
483
|
-
if (
|
|
484
|
-
|
|
485
|
-
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
|
-
|
|
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 (
|
|
494
|
-
|
|
495
|
-
if (
|
|
496
|
-
if (
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
for (let el of
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
489
|
+
batch,
|
|
490
|
+
compile,
|
|
491
|
+
computed,
|
|
492
|
+
sprae_default as default,
|
|
747
493
|
directive,
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
untracked2 as untracked
|
|
494
|
+
effect,
|
|
495
|
+
signal,
|
|
496
|
+
swap,
|
|
497
|
+
untracked
|
|
753
498
|
};
|
package/dist/sprae.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=Object.defineProperty,t=(e,r,a,l=null)=>{let s,n,o,i=0,c=a.length,u=r.length,{remove:p,same:f,insert:d,replace:v}=t;for(;i<c&&i<u&&f(r[i],a[i]);)i++;for(;i<c&&i<u&&f(a[c-1],r[u-1]);)l=a[(--u,--c)];if(i==u)for(;i<c;)d(l,a[i++],e);else{for(s=r[i];i<c;)o=a[i++],n=s?s.nextSibling:l,f(s,o)?s=n:i<c&&f(a[i],n)?(v(s,o,e),s=n):d(s,o,e);for(;!f(s,l);)n=s.nextSibling,p(s,e),s=n}return a};t.same=(e,t)=>e==t,t.replace=(e,t,r)=>r.replaceChild(t,e),t.insert=(e,t,r)=>r.insertBefore(t,e),t.remove=(e,t)=>t.removeChild(e);var r,a=t,l={};((t,r)=>{for(var a in r)e(t,a,{get:r[a],enumerable:!0})})(l,{batch:()=>u,computed:()=>c,current:()=>r,effect:()=>i,signal:()=>o,untracked:()=>p});var s,n,o=(e,t,a=new Set)=>((t={get value(){return r?.deps.push(a.add(r)),e},set value(t){if(t!==e){e=t;for(let e of a)e(t)}},peek:()=>e}).toJSON=t.then=t.toString=t.valueOf=()=>t.value,t),i=(e,t,a,l)=>(l=(a=l=>{t?.call?.(),l=r,r=a;try{t=e()}finally{r=l}}).deps=[],a(),e=>{for(t?.call?.();e=l.pop();)e.delete(a)}),c=(e,t=o(),r,a)=>((r={get value(){return a||=i((()=>t.value=e())),t.value},peek:t.peek}).toJSON=r.then=r.toString=r.valueOf=()=>r.value,r),u=e=>e(),p=(e,t,a)=>(t=r,r=null,a=e(),r=t,a),f=e=>(s=0,n=e,e=h(),n[s]?d():e||""),d=(e="Bad syntax",t=n.slice(0,s).split("\n"),r=t.pop())=>{let a=n.slice(s-108,s).split("\n").pop(),l=n.slice(s,s+108).split("\n").shift();throw EvalError(`${e} at ${t.length}:${r.length} \`${s>=108?"…":""}${a}┃${l}\``,"font-weight: bold")},v=(e,t=s,r)=>{for(;r=e(n.charCodeAt(s));)s+=r;return n.slice(t,s)},y=(e=1,t=s)=>(s+=e,n.slice(t,s)),h=(e=0,t,r,a,l,n)=>{for(;(r=f.space())&&(l=((n=m[r])&&n(a,e))??(!a&&v(f.id)));)a=l;return t&&(r==t?s++:d()),a},m=(f.id=e=>e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||36==e||95==e||e>=192&&215!=e&&247!=e,f.space=e=>{for(;(e=n.charCodeAt(s))<=32;)s++;return e},[]),g=(e,t=32,r,a=e.charCodeAt(0),l=e.length,o=m[a],i=e.toUpperCase()!==e)=>m[a]=(a,c,u=s)=>c<t&&(l<2||n.substr(s,l)==e)&&(!i||!f.id(n.charCodeAt(s+l)))&&(s+=l,r(a,c))||(s=u,o?.(a,c)),b=(e,t,r=!1)=>g(e,t,((a,l)=>a&&(l=h(t-(r?.5:0)))&&[e,a,l])),k=(e,t,r)=>g(e,t,(a=>r?a&&[e,a]:!a&&(a=h(t-.5))&&[e,a])),A=(e,t)=>{g(e,t,((r,a)=>(a=h(t),(!r||r[0]!==e)&&(r=[e,r]),r.push(a),r)))},N=(e,t)=>g(e[0],t,(t=>!t&&[e,h(0,e.charCodeAt(1))])),O=(e,t)=>g(e[0],t,(t=>t&&[e[0],t,h(0,e.charCodeAt(1))])),w=f,C=e=>Array.isArray(e)?e[0]?S[e[0]](...e.slice(1)):()=>e[1]:C.id(e),S=(C.id=e=>t=>t?.[e],{}),x=(e,t,r=S[e])=>S[e]=(...e)=>t(...e)||r&&r(...e),$=(e,t,r,a,l)=>"()"===e[0]?$(e[1],t,r):"string"==typeof e?r=>t(r,e,r):"."===e[0]?(a=C(e[1]),l=e[2],e=>t(a(e),l,e)):"["===e[0]?(a=C(e[1]),l=C(e[2]),e=>t(a(e),l(e),e)):r?(e=C(e),r=>t([e(r)],0,r)):()=>d("Bad left value"),E=C,T=(e,t)=>[,(e=+v((e=>46===e||e>=48&&e<=57||(69===e||101===e?2:0))))!=e?d():e];m[46]=e=>!e&&T();for(let e=48;e<=57;e++)m[e]=e=>e?d():T();var W={n:"\n",r:"\r",t:"\t",b:"\b",f:"\f",v:"\v"},j=e=>(t,r,a="")=>{for(t&&d("Unexpected string"),y();(r=n.charCodeAt(s))-e;)92===r?(y(),r=y(),a+=W[r]||r):a+=y();return y()||d("Bad string"),[,a]};m[34]=j(34),m[39]=j(39),O("()",17),x("(",((e,t,r)=>(r=t?","===t[0]?(t=t.slice(1).map((e=>e?C(e):err())),e=>t.map((t=>t(e)))):(t=C(t),e=>[t(e)]):()=>[],$(e,((e,t,a)=>e[t](...r(a))),!0)))),O("[]",17),x("[",((e,t)=>t?(e=C(e),t=C(t),r=>e(r)[t(r)]):err())),b(".",17),x(".",((e,t)=>(e=C(e),t=t[0]?t:t[1],r=>e(r)[t]))),N("()",17),x("()",(e=>(!e&&d("Empty ()"),C(e))));var L=(...e)=>(e=e.map(C),t=>e.map((e=>e(t))).pop());A(",",1),x(",",L),A(";",1),x(";",L),b("*",12),x("*",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)*t(r)))),b("/",12),x("/",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)/t(r)))),b("%",12),x("%",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)%t(r)))),b("*=",2,!0),x("*=",((e,t)=>(t=C(t),$(e,((e,r,a)=>e[r]*=t(a)))))),b("/=",2,!0),x("/=",((e,t)=>(t=C(t),$(e,((e,r,a)=>e[r]/=t(a)))))),b("%=",2,!0),x("%=",((e,t)=>(t=C(t),$(e,((e,r,a)=>e[r]%=t(a)))))),k("+",14),x("+",((e,t)=>!t&&(e=C(e),t=>+e(t)))),k("-",14),x("-",((e,t)=>!t&&(e=C(e),t=>-e(t)))),b("+",11),x("+",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)+t(r)))),b("-",11),x("-",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)-t(r)))),b("+=",2,!0),x("+=",((e,t)=>(t=C(t),$(e,((e,r,a)=>e[r]+=t(a)))))),b("-=",2,!0),x("-=",((e,t)=>(t=C(t),$(e,((e,r,a)=>e[r]-=t(a)))))),g("++",15,(e=>e?["++-",e]:["++",h(14)])),x("++",(e=>$(e,((e,t,r)=>++e[t])))),x("++-",(e=>$(e,((e,t,r)=>e[t]++)))),g("--",15,(e=>e?["--+",e]:["--",h(14)])),x("--",(e=>$(e,((e,t,r)=>--e[t])))),x("--+",(e=>$(e,((e,t,r)=>e[t]--)))),k("~",14),x("~",((e,t)=>!t&&(e=C(e),t=>~e(t)))),b("|",5),x("|",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)|t(r)))),b("&",7),x("&",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)&t(r)))),b("^",6),x("^",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)^t(r)))),b(">>",10),x(">>",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)>>t(r)))),b("<<",10),x("<<",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)<<t(r)))),b("==",8),x("==",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)==t(r)))),b("!=",8),x("!=",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)!=t(r)))),b(">",9),x(">",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)>t(r)))),b("<",9),x("<",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)<t(r)))),b(">=",9),x(">=",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)>=t(r)))),b("<=",9),x("<=",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)<=t(r)))),k("!",14),x("!",((e,t)=>!t&&(e=C(e),t=>!e(t)))),b("||",3),x("||",((e,t)=>(e=C(e),t=C(t),r=>e(r)||t(r)))),b("&&",4),x("&&",((e,t)=>(e=C(e),t=C(t),r=>e(r)&&t(r)))),b("=",2,!0),x("=",((e,t)=>(t=C(t),$(e,((e,r,a)=>e[r]=t(a)))))),g("/*",20,((e,t)=>(v((e=>42!==e&&47!==n.charCodeAt(s+1))),y(2),e||h(t)||[]))),g("//",20,((e,t)=>(v((e=>e>=32)),e||h(t)||[""]))),b("**",13,!0),x("**",((e,t)=>t&&(e=C(e),t=C(t),r=>e(r)**t(r)))),g("?",2,((e,t,r)=>e&&(t=h(1.5,58))&&["?",e,t,h(1.5)])),x("?",((e,t,r)=>(e=C(e),t=C(t),r=C(r),a=>e(a)?t(a):r(a)))),g("true",20,(e=>e?err():[,!0])),g("false",20,(e=>e?err():[,!1])),N("[]",20),x("[]",((e,t)=>(e=(e=e?","===e[0]?e.slice(1):[e]:[]).map((e=>"..."===e[0]?(e=C(e[1]),t=>e(t)):(e=C(e),t=>[e(t)]))),t=>e.flatMap((e=>e(t)))))),N("{}",20),x("{}",((e,t)=>(e=(e=e?","!==e[0]?[e]:e.slice(1):[]).map((e=>C("string"==typeof e?[":",e,e]:e))),t=>Object.fromEntries(e.flatMap((e=>e(t))))))),b(":",1.5,!0),x(":",((e,t)=>(t=C(t),Array.isArray(e)?(e=C(e),r=>[[e(r),t(r)]]):r=>[[e,t(r)]]))),b("=>",2,!0),x("=>",((e,t)=>(e=(e="()"===e[0]?e[1]:e)?e=","===e[0]?e.slice(1):[e]:[],t=C("{}"===t[0]?t[1]:t),(r=null)=>(r=Object.create(r),(...a)=>(e.map(((e,t)=>r[e]=a[t])),t(r)))))),b(""),g("?.",17,(e=>e&&["?.",e])),x("?.",(e=>(e=C(e),t=>e(t)||(()=>{})))),g("?.",17,((e,t)=>e&&!(t=h(17))?.map&&["?.",e,t])),x("?.",((e,t)=>t&&(e=C(e),r=>e(r)?.[t]))),x("(",((e,t,r,a,l,s)=>"?."===e[0]&&(e[2]||Array.isArray(e[1]))&&(a=t?","===t[0]?(t=t.slice(1).map(C),e=>t.map((t=>t(e)))):(t=C(t),e=>[t(e)]):()=>[],!e[2]&&(e=e[1]),l="["===e[0]?C(e[2]):()=>e[2],r=C(e[1]),e=>r(e)?.[l(e)]?.(...a(e))))),k("...",14),x("...",(e=>(e=C(e),t=>Object.entries(e(t))))),b("in",9),x("in",((e,t)=>t&&(e=E(e),t=E(t),r=>e(r)in t(r)))),b("===",8),b("!==",9),x("===",((e,t)=>(e=E(e),t=E(t),r=>e(r)===t(r)))),x("!==",((e,t)=>(e=E(e),t=E(t),r=>e(r)!==t(r)))),b("??",3),x("??",((e,t)=>t&&(e=E(e),t=E(t),r=>e(r)??t(r)))),b("??=",2,!0),x("??=",((e,t)=>(t=E(t),$(e,((e,r,a)=>e[r]??=t(a)))))),b("||=",2,!0),x("||=",((e,t)=>(t=E(t),$(e,((e,r,a)=>e[r]||=t(a)))))),b("&&=",2,!0),x("&&=",((e,t)=>(t=E(t),$(e,((e,r,a)=>e[r]&&=t(a)))))),g("undefined",20,(e=>e?d():[,void 0])),g("NaN",20,(e=>e?d():[,NaN])),g("null",20,(e=>e?d():[,null]));var B=Symbol.dispose||=Symbol("dispose"),{signal:D,effect:M,batch:K,computed:P,untracked:J}=l,R={},U=new WeakMap;function Z(e,t){if(!e.children)return;if(U.has(e)){const[r,a]=U.get(e);for(let e in t)r[e]=t[e];J((()=>{for(let e of a)e()}))}const r=t||{},a=[],l=(e,t=e.parentNode)=>{if(e.attributes)for(let l=0;l<e.attributes.length;){let s=e.attributes[l];if(":"===s.name[0]){e.removeAttribute(s.name);let l=s.name.slice(1).split(":");for(let t of l){let l=(R[t]||R.default)(e,s.value,r,t);l&&(l[B]=M(l),a.push(l))}if(U.has(e))return;if(e.parentNode!==t)return!1}else l++}for(let t,r=0;t=e.children[r];r++)!1===l(t,e)&&r--};return l(e),U.has(e)||(U.set(e,[r,a]),e.classList?.add("∴"),e[B]=()=>{for(;a.length;)a.pop()[B]();e.classList.remove("∴"),U.delete(e);let t=e.getElementsByClassName("∴");for(;t.length;)t[0][B]?.()}),r}var z={},H=(e,t,r)=>{if(r=z[e=e.trim()])return r;try{r=E(w(e))}catch(r){throw Object.assign(r,{message:`∴ ${r.message}\n\n${t}${e?`="${e}"\n\n`:""}`,expr:e})}return z[e]=r},X=a,_=(e,t)=>e?.replace?e.replace(/\$<([^>]+)>/g,((e,r)=>t[r]?.valueOf?.()??"")):e;Z.use=e=>{e.signal&&(D=e.signal,M=e.effect,P=e.computed,K=e.batch||(e=>e()),J=e.untracked||K),e.swap&&(X=e.swap)};var q=Symbol(":each"),F={};R.each=(e,t,r,a)=>{let[l,s]=t.split(/\s+in\s+/),[n,o="_$"]=l.split(/\s*,\s*/);const i=e[q]=document.createTextNode("");e.replaceWith(i);const c=H(s,a),u=new WeakMap;e.removeAttribute(":key");let p=[];return()=>{let t=c(r)?.valueOf(),a=[];"number"==typeof t&&(t=Array.from({length:t},((e,t)=>t)));const l=new WeakSet;for(let s in t){let i=t[s],c=Object.create(r,{[o]:{value:s}});c[n]=i;let p,f=i.key??i.id??i;null==f?p=e.cloneNode(!0):(Object(f)!==f&&(f=F[f]||=Object(f)),l.has(f)?(console.warn("Duplicate key",f),p=e.cloneNode(!0)):(l.add(f),p=u.get(f)||u.set(f,e.cloneNode(!0)).get(f))),p.content&&(p=p.content.cloneNode(!0)),Z(p,c),11===p.nodeType?a.push(...p.childNodes):a.push(p)}X(i.parentNode,p,p=a,i)}};var G=Symbol("if");R.if=(e,t,r,a)=>{let l,s,n,o=e.parentNode,i=e.nextElementSibling,c=document.createTextNode(""),u=H(t,a),p=[];return e.after(c),e.content?(l=p,e.remove(),s=[...e.content.childNodes]):s=l=[e],i?.hasAttribute(":else")?(i.removeAttribute(":else"),i.hasAttribute(":if")?n=p:(i.remove(),n=i.content?[...i.content.childNodes]:[i])):n=p,()=>{const t=u(r)?.valueOf()?s:e[G]?p:n;if(i&&(i[G]=t===s),l!=t){l[0]?.[q]&&(l=[l[0][q]]),X(o,l,l=t,c);for(let e of l)Z(e,r)}}},R.ref=(e,t,r)=>{let a;return()=>{a&&delete r[a],r[a=_(t,r)]=e}},R.scope=(e,t,r,a)=>{let l=H(t,a);return()=>{Z(e,{...r,...l(r)?.valueOf?.()||{}})}},R.html=(e,t,r,a)=>{let l=H(t,a)(r);if(!l)return;let s=(l.content||l).cloneNode(!0);e.replaceChildren(s),Z(e,r)},R.text=(e,t,r)=>{let a=H(t,"text");return e.content&&e.replaceWith(e=document.createTextNode("")),()=>{let t=a(r)?.valueOf();e.textContent=null==t?"":t}},R.class=(e,t,r)=>{let a=H(t,"class"),l=new Set;return()=>{let t=a(r),s=new Set;t&&("string"==typeof t?_(t?.valueOf?.(),r).split(" ").map((e=>s.add(e))):Array.isArray(t)?t.map((e=>(e=_(e?.valueOf?.(),r))&&s.add(e))):Object.entries(t).map((([e,t])=>t?.valueOf?.()&&s.add(e))));for(let t of l)s.has(t)?s.delete(t):e.classList.remove(t);for(let t of l=s)e.classList.add(t)}},R.style=(e,t,r)=>{let a=H(t,"style"),l=e.getAttribute("style")||"";return l.endsWith(";")||(l+="; "),()=>{let t=a(r)?.valueOf();if("string"==typeof t)e.setAttribute("style",l+_(t,r));else{e.setAttribute("style",l);for(let a in t)e.style.setProperty(a,_(t[a],r))}}},R.default=(e,t,r,a)=>{let l=a.startsWith("on")&&a.slice(2),s=H(t,a);if(l){let t;return()=>(t?.(),t=I(e,l,s(r)))}return()=>{let t=s(r)?.valueOf();if(a)Y(e,a,_(t,r));else for(let a in t)Y(e,re(a),_(t[a],r))}};var I=(e,t,r=(()=>{}))=>{const a={evt:"",target:e,test:()=>!0};a.evt=t.replace(/\.(\w+)?-?([-\w]+)?/g,((e,t,r="")=>(a.test=Q[t]?.(a,...r.split("-"))||a.test,"")));const{evt:l,target:s,test:n,defer:o,stop:i,prevent:c,...u}=a;o&&(r=o(r));const p=e=>n(e)&&(i&&e.stopPropagation(),c&&e.preventDefault(),r.call(s,e));return s.addEventListener(l,p,u),()=>s.removeEventListener(l,p,u)},Q={prevent(e){e.prevent=!0},stop(e){e.stop=!0},once(e){e.once=!0},passive(e){e.passive=!0},capture(e){e.capture=!0},window(e){e.target=window},document(e){e.target=document},throttle(e,t){e.defer=e=>ee(e,t?Number(t)||0:108)},debounce(e,t){e.defer=e=>te(e,t?Number(t)||0:108)},outside:e=>t=>{let r=e.target;return!(r.contains(t.target)||!1===t.target.isConnected||r.offsetWidth<1&&r.offsetHeight<1)},self:e=>t=>t.target===e.target,ctrl:(e,...t)=>e=>V.ctrl(e)&&t.every((t=>V[t]?V[t](e):e.key===t)),shift:(e,...t)=>e=>V.shift(e)&&t.every((t=>V[t]?V[t](e):e.key===t)),alt:(e,...t)=>e=>V.alt(e)&&t.every((t=>V[t]?V[t](e):e.key===t)),meta:(e,...t)=>e=>V.meta(e)&&t.every((t=>V[t]?V[t](e):e.key===t)),arrow:()=>V.arrow,enter:()=>V.enter,escape:()=>V.escape,tab:()=>V.tab,space:()=>V.space,backspace:()=>V.backspace,delete:()=>V.delete,digit:()=>V.digit,letter:()=>V.letter,character:()=>V.character},V={ctrl:e=>e.ctrlKey||"Control"===e.key||"Ctrl"===e.key,shift:e=>e.shiftKey||"Shift"===e.key,alt:e=>e.altKey||"Alt"===e.key,meta:e=>e.metaKey||"Meta"===e.key||"Command"===e.key,arrow:e=>e.key.startsWith("Arrow"),enter:e=>"Enter"===e.key,escape:e=>e.key.startsWith("Esc"),tab:e=>"Tab"===e.key,space:e=>" "===e.key||"Space"===e.key||" "===e.key,backspace:e=>"Backspace"===e.key,delete:e=>"Delete"===e.key,digit:e=>/^\d$/.test(e.key),letter:e=>/^[a-zA-Z]$/.test(e.key),character:e=>/^\S$/.test(e.key)},Y=(e,t,r)=>{null==r||!1===r?e.removeAttribute(t):e.setAttribute(t,!0===r?"":"number"==typeof r||"string"==typeof r?r:"")},ee=(e,t)=>{let r,a,l=s=>{r=!0,setTimeout((()=>{if(r=!1,a)return a=!1,l(s),e(s)}),t)};return t=>r?a=!0:(l(t),e(t))},te=(e,t)=>{let r;return a=>{clearTimeout(r),r=setTimeout((()=>{r=null,e(a)}),t)}},re=e=>e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(e=>"-"+e.toLowerCase()));R.value=(e,t,r)=>{let a,l,s=H(t,"value"),n="text"===e.type||""===e.type?t=>e.setAttribute("value",e.value=null==t?"":t):"TEXTAREA"===e.tagName||"text"===e.type||""===e.type?t=>(a=e.selectionStart,l=e.selectionEnd,e.setAttribute("value",e.value=null==t?"":t),a&&e.setSelectionRange(a,l)):"checkbox"===e.type?t=>(e.checked=t,Y(e,"checked",t)):"select-one"===e.type?t=>{for(let t in e.options)t.removeAttribute("selected");e.value=t,e.selectedOptions[0]?.setAttribute("selected","")}:t=>e.value=t;return()=>n(s(r)?.valueOf?.())},R.fx=(e,t,r,a)=>{let l=H(t,a);return()=>l(r)};export{K as batch,H as compile,P as computed,Z as default,R as directive,M as effect,_ as ipol,D as signal,X as swap,J as untracked};
|
|
1
|
+
var e,t,r,l,a,s=Object.defineProperty,n=Symbol.dispose||=Symbol("dispose"),o={},c=new WeakMap;function i(e,r){if(!e.children)return;if(c.has(e)){const[t,l]=c.get(e);for(let e in r)t[e]=r[e];a((()=>{for(let e of l)e()}))}const l=r||{},s=[],i=(e,r=e.parentNode)=>{if(e.attributes)for(let a=0;a<e.attributes.length;){let i=e.attributes[a];if(":"===i.name[0]){e.removeAttribute(i.name);let a=i.name.slice(1).split(":");for(let r of a){let a=o[r]||o.default,c=a(e,(a.parse||d)(i.value,d),l,r);c&&(c[n]=t(c),s.push(c))}if(c.has(e))return;if(e.parentNode!==r)return!1}else a++}for(let t,r=0;t=e.children[r];r++)!1===i(t,e)&&r--};return i(e),c.has(e)||(c.set(e,[l,s]),e.classList?.add("∴"),e[n]=()=>{for(;s.length;)s.pop()[n]();e.classList.remove("∴"),c.delete(e);let t=e.getElementsByClassName("∴");for(;t.length;)t[0][n]?.()}),l}var u,p,f={},d=(e,t,r)=>{if(r=f[e=e.trim()])return r;try{r=u(e)}catch(r){throw Object.assign(r,{message:`∴ ${r.message}\n\n${t}${e?`="${e}"\n\n`:""}`,expr:e})}return r.expr=e,f[e]=r};i.use=s=>{s.signal&&(e=s.signal,t=s.effect,l=s.computed,r=s.batch||(e=>e()),a=s.untracked||r),s.swap&&(p=s.swap),s.compile&&(u=s.compile)};var v,y={};((e,t)=>{for(var r in t)s(e,r,{get:t[r],enumerable:!0})})(y,{batch:()=>g,computed:()=>b,effect:()=>h,signal:()=>m,untracked:()=>k});var m=(e,t,r=new Set)=>((t={get value(){return v?.deps.push(r.add(v)),e},set value(t){if(t!==e){e=t;for(let e of r)e(t)}},peek:()=>e}).toJSON=t.then=t.toString=t.valueOf=()=>t.value,t),h=(e,t,r,l)=>(l=(r=l=>{t?.call?.(),l=v,v=r;try{t=e()}finally{v=l}}).deps=[],r(),e=>{for(t?.call?.();e=l.pop();)e.delete(r)}),b=(e,t=m(),r,l)=>((r={get value(){return l||=h((()=>t.value=e())),t.value},peek:t.peek}).toJSON=r.then=r.toString=r.valueOf=()=>r.value,r),g=e=>e(),k=(e,t,r)=>(t=v,v=null,r=e(),v=t,r),w=(e,t,r,l=null,{remove:a,insert:s}=w)=>{let n,o,c,i=0,u=new Set(r);for(;c=t[i++];)u.has(c)?n=n||c:a(c,e);for(n=n||l,i=0;c=r[i++];)o=n?n.nextSibling:l,n===c?n=o:(r[i]===o&&(n=o),s(c,n,e));return r};w.insert=(e,t,r)=>r.insertBefore(e,t),w.remove=(e,t)=>t.removeChild(e);var O=w,A=Symbol(":each"),S={},N=Symbol("key");(o.each=(e,[t,r,l],a)=>{const s=e[A]=document.createTextNode(""),n=e.parentNode;e.replaceWith(s);const o=new WeakMap,c=new WeakMap;let u=[];const{insert:f,replace:d}=p,v={remove:e=>{e.remove(),e[Symbol.dispose]?.(),e[N]&&(o.delete(e[N]),c.delete(e[N]))},insert:f,replace:d};return()=>{let f=l(a)?.valueOf(),d=[];"number"==typeof f&&(f=Array.from({length:f},((e,t)=>t)));const y=new WeakMap;for(let l in f){let s,n=f[l],u=n?.key??n?.id??n??l;u=Object(u)!==u?S[u]||=Object(u):n,null==u||y.has(u)||e.content?s=(e.content||e).cloneNode(!0):(y.set(u,1),(s=o.get(u)||(o.set(u,e.cloneNode(!0)),o.get(u)))[N]=u);let p=c.get(u)||(c.set(u,Object.create(a,{[r]:{value:l}})),c.get(u));p[t]=n,i(s,p),11===s.nodeType?d.push(...s.childNodes):d.push(s)}p(n,u,u=d,s,v)}}).parse=(e,t)=>{let[r,l]=e.split(/\s+in\s+/),[a,s="$"]=r.split(/\s*,\s*/);return[a,s,t(l)]};var x=Symbol("if");o.if=(e,t,r)=>{let l,a,s,n=e.parentNode,o=e.nextElementSibling,c=document.createTextNode(""),u=[];return e.after(c),e.content?(l=u,e.remove(),a=[...e.content.childNodes]):a=l=[e],o?.hasAttribute(":else")?(o.removeAttribute(":else"),o.hasAttribute(":if")?s=u:(o.remove(),s=o.content?[...o.content.childNodes]:[o])):s=u,()=>{const f=t(r)?.valueOf()?a:e[x]?u:s;if(o&&(o[x]=f===a),l!=f){l[0]?.[A]&&(l=[l[0][A]]),p(n,l,l=f,c);for(let e of l)i(e,r)}}},o.default=(e,t,r,l)=>{let a=l.startsWith("on")&&l.slice(2);if(a){let l;return()=>(l?.(),l=W(e,a,t(r)?.valueOf()))}return()=>{let a=t(r)?.valueOf();if(l)T(e,l,D(a,r));else for(let t in a)T(e,j(t),D(a[t],r))}};var W=(e,t,r=(()=>{}))=>{const l={evt:"",target:e,test:()=>!0};l.evt=t.replace(/\.(\w+)?-?([-\w]+)?/g,((e,t,r="")=>(l.test=C[t]?.(l,...r.split("-"))||l.test,"")));const{evt:a,target:s,test:n,defer:o,stop:c,prevent:i,...u}=l;o&&(r=o(r));const p=e=>n(e)&&(c&&e.stopPropagation(),i&&e.preventDefault(),r.call(s,e));return s.addEventListener(a,p,u),()=>s.removeEventListener(a,p,u)},C={prevent(e){e.prevent=!0},stop(e){e.stop=!0},once(e){e.once=!0},passive(e){e.passive=!0},capture(e){e.capture=!0},window(e){e.target=window},document(e){e.target=document},throttle(e,t){e.defer=e=>$(e,t?Number(t)||0:108)},debounce(e,t){e.defer=e=>L(e,t?Number(t)||0:108)},outside:e=>t=>{let r=e.target;return!(r.contains(t.target)||!1===t.target.isConnected||r.offsetWidth<1&&r.offsetHeight<1)},self:e=>t=>t.target===e.target,ctrl:(e,...t)=>e=>E.ctrl(e)&&t.every((t=>E[t]?E[t](e):e.key===t)),shift:(e,...t)=>e=>E.shift(e)&&t.every((t=>E[t]?E[t](e):e.key===t)),alt:(e,...t)=>e=>E.alt(e)&&t.every((t=>E[t]?E[t](e):e.key===t)),meta:(e,...t)=>e=>E.meta(e)&&t.every((t=>E[t]?E[t](e):e.key===t)),arrow:()=>E.arrow,enter:()=>E.enter,escape:()=>E.escape,tab:()=>E.tab,space:()=>E.space,backspace:()=>E.backspace,delete:()=>E.delete,digit:()=>E.digit,letter:()=>E.letter,character:()=>E.character},E={ctrl:e=>e.ctrlKey||"Control"===e.key||"Ctrl"===e.key,shift:e=>e.shiftKey||"Shift"===e.key,alt:e=>e.altKey||"Alt"===e.key,meta:e=>e.metaKey||"Meta"===e.key||"Command"===e.key,arrow:e=>e.key.startsWith("Arrow"),enter:e=>"Enter"===e.key,escape:e=>e.key.startsWith("Esc"),tab:e=>"Tab"===e.key,space:e=>" "===e.key||"Space"===e.key||" "===e.key,backspace:e=>"Backspace"===e.key,delete:e=>"Delete"===e.key,digit:e=>/^\d$/.test(e.key),letter:e=>/^[a-zA-Z]$/.test(e.key),character:e=>/^\S$/.test(e.key)},T=(e,t,r)=>{null==r||!1===r?e.removeAttribute(t):e.setAttribute(t,!0===r?"":"number"==typeof r||"string"==typeof r?r:"")},$=(e,t)=>{let r,l,a=s=>{r=!0,setTimeout((()=>{if(r=!1,l)return l=!1,a(s),e(s)}),t)};return t=>r?l=!0:(a(t),e(t))},L=(e,t)=>{let r;return l=>{clearTimeout(r),r=setTimeout((()=>{r=null,e(l)}),t)}},j=e=>e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(e=>"-"+e.toLowerCase())),D=(e,t)=>e?.replace?e.replace(/\$<([^>]+)>/g,((e,r)=>t[r]?.valueOf?.()??"")):e;(o.ref=(e,t,r)=>{let l;return()=>{l&&delete r[l],r[l=D(t,r)]=e}}).parse=e=>e,o.scope=(e,t,r)=>()=>{i(e,{...r,...t(r)?.valueOf?.()||{}})},o.html=(e,t,r)=>{let l=t(r);if(!l)return;let a=(l.content||l).cloneNode(!0);e.replaceChildren(a),i(e,r)},o.text=(e,t,r)=>(e.content&&e.replaceWith(e=document.createTextNode("")),()=>{let l=t(r)?.valueOf();e.textContent=null==l?"":l}),o.class=(e,t,r)=>{let l=new Set;return()=>{let a=t(r),s=new Set;a&&("string"==typeof a?D(a?.valueOf?.(),r).split(" ").map((e=>s.add(e))):Array.isArray(a)?a.map((e=>(e=D(e?.valueOf?.(),r))&&s.add(e))):Object.entries(a).map((([e,t])=>t?.valueOf?.()&&s.add(e))));for(let t of l)s.has(t)?s.delete(t):e.classList.remove(t);for(let t of l=s)e.classList.add(t)}},o.style=(e,t,r)=>{let l=e.getAttribute("style")||"";return l.endsWith(";")||(l+="; "),()=>{let a=t(r)?.valueOf();if("string"==typeof a)e.setAttribute("style",l+D(a,r));else{e.setAttribute("style",l);for(let t in a)e.style.setProperty(t,D(a[t],r))}}},o.value=(e,t,r)=>{let l,a,s="text"===e.type||""===e.type?t=>e.setAttribute("value",e.value=null==t?"":t):"TEXTAREA"===e.tagName||"text"===e.type||""===e.type?t=>(l=e.selectionStart,a=e.selectionEnd,e.setAttribute("value",e.value=null==t?"":t),l&&e.setSelectionRange(l,a)):"checkbox"===e.type?t=>(e.checked=t,T(e,"checked",t)):"select-one"===e.type?t=>{for(let t in e.options)t.removeAttribute("selected");e.value=t,e.selectedOptions[0]?.setAttribute("selected","")}:t=>e.value=t;return()=>s(t(r)?.valueOf?.())},o.fx=(e,t,r)=>()=>t(r),i.use(y),i.use({compile:e=>i.constructor("__scope",`with (__scope) { return ${e} };`)}),i.use({swap:O});var M=i;export{r as batch,u as compile,l as computed,M as default,o as directive,t as effect,e as signal,p as swap,a as untracked};
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sprae",
|
|
3
3
|
"description": "DOM microhydration.",
|
|
4
|
-
"version": "9.1.
|
|
4
|
+
"version": "9.1.1",
|
|
5
5
|
"main": "./sprae.js",
|
|
6
6
|
"module": "./sprae.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"files": [
|
|
9
9
|
"core.js",
|
|
10
10
|
"sprae.js",
|
|
11
|
+
"signal.js",
|
|
11
12
|
"directive",
|
|
12
13
|
"dist"
|
|
13
14
|
],
|
|
14
15
|
"dependencies": {
|
|
15
|
-
"signal-polyfill": "^0.1.0",
|
|
16
16
|
"swapdom": "^1.2.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
package/readme.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
> DOM tree microhydration
|
|
4
4
|
|
|
5
5
|
_Sprae_ is a compact & ergonomic progressive enhancement framework.<br/>
|
|
6
|
-
It provides `:`-attributes for inline markup logic with
|
|
7
|
-
Perfect for small-scale websites, prototypes, or lightweight UI.<br/>
|
|
6
|
+
It provides `:`-attributes for inline markup logic with signals reactivity.<br/>
|
|
7
|
+
Perfect for small-scale websites, static pages, landings, prototypes, or lightweight UI.<br/>
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
## Usage
|
|
@@ -265,13 +265,9 @@ Trigger when element is connected / disconnected from DOM.
|
|
|
265
265
|
```
|
|
266
266
|
-->
|
|
267
267
|
|
|
268
|
-
##
|
|
268
|
+
## Signals
|
|
269
269
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
### Signals
|
|
273
|
-
|
|
274
|
-
Sprae uses [standard signals](https://github.com/proposal-signals/proposal-signals) for reactivity, but can be switched to any preact-flavored signals library:
|
|
270
|
+
Sprae uses signals for reactivity (see [_sprae/signal.js_](./signal.js)). It can be switched to any alternative preact-flavored signals for compatibility or performance:
|
|
275
271
|
|
|
276
272
|
```js
|
|
277
273
|
import sprae, { signal, computed, effect, batch, untracked } from 'sprae';
|
|
@@ -288,11 +284,12 @@ Provider | Size | Feature
|
|
|
288
284
|
[`@webreflection/signal`](https://ghib.io/@webreflection/signal) | 531b | Class-based, better performance, good for small-medium states
|
|
289
285
|
[`usignal`](https://ghib.io/usignal) | 850b | Class-based with optimizations, good for medium states
|
|
290
286
|
[`@preact/signals-core`](https://ghub.io/@preact/signals-core) | 1.47kb | Best performance, good for any states
|
|
287
|
+
[`signal-polyfill`](https://github.com/tc39/proposal-signals) | 2.5kb | Standard signals, slowest performance. Use via [adapter](https://gist.github.com/dy/bbac687464ccf5322ab0e2fd0680dc4d).
|
|
291
288
|
|
|
292
289
|
|
|
293
|
-
|
|
290
|
+
## Evaluator
|
|
294
291
|
|
|
295
|
-
Expressions use _new Function_ as default evaluator, which is fast & compact way, but violates "unsafe-eval" CSP. To make eval stricter & safer, an alternative evaluator can be configured, eg. _justin_:
|
|
292
|
+
Expressions use _new Function_ as default evaluator, which is fast & compact way, but violates "unsafe-eval" CSP. To make eval stricter & safer, as well as sandbox expressions, an alternative evaluator can be configured, eg. _justin_:
|
|
296
293
|
|
|
297
294
|
```js
|
|
298
295
|
import sprae from 'sprae'
|
|
@@ -318,22 +315,41 @@ sprae.use({compile: justin}) // set up justin as default compiler
|
|
|
318
315
|
|
|
319
316
|
## Directives
|
|
320
317
|
|
|
321
|
-
|
|
318
|
+
Custom directives can be added as:
|
|
322
319
|
|
|
323
320
|
```js
|
|
324
321
|
import sprae, { directive } from 'sprae/core.js'
|
|
325
322
|
|
|
326
|
-
// include directives
|
|
327
|
-
import 'sprae/directive/if.js'
|
|
328
|
-
import 'sprae/directive/text.js'
|
|
329
|
-
|
|
330
323
|
// define custom directive
|
|
331
324
|
directive.id = (el, evaluate, state) => {
|
|
332
325
|
return () => el.id = evaluate(state) // return update function
|
|
333
326
|
}
|
|
334
327
|
```
|
|
335
328
|
|
|
336
|
-
|
|
329
|
+
## Custom build
|
|
330
|
+
|
|
331
|
+
_Sprae_ can be tailored to project needs via `sprae/core` for performance, size or compatibility purposes:
|
|
332
|
+
|
|
333
|
+
```js
|
|
334
|
+
// sprae.custom.js
|
|
335
|
+
import sprae, { directive } from 'sprae/core.js'
|
|
336
|
+
import * as signals from '@preact/signals'
|
|
337
|
+
import compile from 'subscript'
|
|
338
|
+
import diff from 'udomdiff
|
|
339
|
+
|
|
340
|
+
// include directives
|
|
341
|
+
import 'sprae/directive/if.js'
|
|
342
|
+
import 'sprae/directive/text.js'
|
|
343
|
+
|
|
344
|
+
// configure signals
|
|
345
|
+
sprae.use(signals)
|
|
346
|
+
|
|
347
|
+
// configure compiler
|
|
348
|
+
sprae.use({ compile })
|
|
349
|
+
|
|
350
|
+
// configure dom differ
|
|
351
|
+
sprae.use({ swap: (parent, from, to, before) => udomdiff(parent, from, to, node=>node, before) })
|
|
352
|
+
```
|
|
337
353
|
|
|
338
354
|
<!--
|
|
339
355
|
### DOM diffing
|
package/signal.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// ulive minimal signal impl (decoupled from ulive to keep internal dep adjustable easily)
|
|
2
|
+
let current
|
|
3
|
+
|
|
4
|
+
export const signal = (v, s, obs = new Set) => (
|
|
5
|
+
s = {
|
|
6
|
+
get value() {
|
|
7
|
+
current?.deps.push(obs.add(current));
|
|
8
|
+
return v
|
|
9
|
+
},
|
|
10
|
+
set value(val) {
|
|
11
|
+
if (val === v) return
|
|
12
|
+
v = val;
|
|
13
|
+
for (let sub of obs) sub(val); // notify effects
|
|
14
|
+
},
|
|
15
|
+
peek() { return v },
|
|
16
|
+
},
|
|
17
|
+
s.toJSON = s.then = s.toString = s.valueOf = () => s.value,
|
|
18
|
+
s
|
|
19
|
+
),
|
|
20
|
+
effect = (fn, teardown, run, deps) => (
|
|
21
|
+
run = (prev) => {
|
|
22
|
+
teardown?.call?.();
|
|
23
|
+
prev = current, current = run;
|
|
24
|
+
try { teardown = fn(); } finally { current = prev; }
|
|
25
|
+
},
|
|
26
|
+
deps = run.deps = [],
|
|
27
|
+
|
|
28
|
+
run(),
|
|
29
|
+
(dep) => { teardown?.call?.(); while (dep = deps.pop()) dep.delete(run); }
|
|
30
|
+
),
|
|
31
|
+
computed = (fn, s = signal(), c, e) => (
|
|
32
|
+
c = {
|
|
33
|
+
get value() {
|
|
34
|
+
e ||= effect(() => s.value = fn());
|
|
35
|
+
return s.value
|
|
36
|
+
},
|
|
37
|
+
peek: s.peek
|
|
38
|
+
},
|
|
39
|
+
c.toJSON = c.then = c.toString = c.valueOf = () => c.value,
|
|
40
|
+
c
|
|
41
|
+
),
|
|
42
|
+
batch = (fn) => fn(),
|
|
43
|
+
untracked = (fn, prev, v) => (prev = current, current = null, v = fn(), current = prev, v);
|
package/sprae.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import sprae from './core.js'
|
|
2
2
|
|
|
3
3
|
import * as signals from './signal.js'
|
|
4
|
-
import swap from 'swapdom/
|
|
4
|
+
import swap from 'swapdom/deflate'
|
|
5
5
|
|
|
6
6
|
// default directives
|
|
7
7
|
import './directive/if.js'
|
|
@@ -26,4 +26,4 @@ sprae.use({ compile: expr => sprae.constructor(`__scope`, `with (__scope) { retu
|
|
|
26
26
|
sprae.use({ swap })
|
|
27
27
|
|
|
28
28
|
export default sprae
|
|
29
|
-
export
|
|
29
|
+
export * from './core.js'
|