@sigil-dev/grimoire 0.9.20 → 0.9.22
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/README.md +83 -83
- package/index.ts +50 -48
- package/package.json +16 -5
- package/public/__grimoire__/grimoire-client.js +12 -0
- package/public/__grimoire__/runtime.js +1241 -0
- package/server.ts +22 -20
- package/src/adapters/bun.ts +17 -0
- package/src/adapters/static.ts +41 -0
- package/src/adapters/types.ts +36 -0
- package/src/base.ts +91 -0
- package/src/client/csrf.ts +47 -47
- package/src/client/deferred.ts +179 -179
- package/src/client/enhance.ts +160 -160
- package/src/client/router.ts +870 -833
- package/src/dev/compile-module.ts +211 -211
- package/src/dev/loader.ts +141 -141
- package/src/dev/resolve.ts +70 -70
- package/src/dev/runtime-bundle.ts +51 -51
- package/src/env/modules.ts +62 -62
- package/src/env/required.ts +42 -0
- package/src/env/typegen.ts +61 -61
- package/src/headers.ts +105 -114
- package/src/logger/transports.ts +117 -117
- package/src/rendering/head.ts +49 -49
- package/src/rendering/hydrate.ts +161 -161
- package/src/rendering/images.ts +43 -43
- package/src/rendering/index.ts +755 -745
- package/src/rendering/preload.ts +101 -95
- package/src/rendering/ssrPlugin.ts +108 -108
- package/src/rendering/timing.ts +40 -40
- package/src/routing/router.ts +186 -186
- package/src/routing/scanner.ts +225 -196
- package/src/routing/transform-routes.ts +102 -102
- package/src/server/after-response.ts +206 -194
- package/src/server/asset-cache.ts +57 -55
- package/src/server/build.ts +262 -249
- package/src/server/cached.ts +114 -114
- package/src/server/client-address.ts +82 -82
- package/src/server/client-dir.ts +57 -57
- package/src/server/client-entry.ts +44 -0
- package/src/server/cookie-utils.ts +80 -80
- package/src/server/coordinator.ts +476 -471
- package/src/server/hooks.ts +122 -122
- package/src/server/index.ts +1138 -1022
- package/src/server/plugins.ts +172 -172
- package/src/server/prerender.ts +444 -0
- package/src/server/reserved.ts +17 -0
- package/src/server/resolver.ts +98 -98
- package/src/server/rewrite.ts +28 -0
- package/src/server/warm.ts +91 -91
- package/src/server/with-headers.ts +27 -0
- package/src/server/worker.ts +74 -72
- package/src/testing/dom.ts +73 -0
- package/src/testing/index.ts +169 -0
- package/src/testing/server.ts +162 -0
- package/src/typegen/index.ts +450 -450
- package/src/types.ts +501 -432
- package/test/after-response.test.ts +132 -113
- package/test/asset-cache-policy.test.ts +96 -96
- package/test/base.test.ts +134 -0
- package/test/cached.test.ts +126 -126
- package/test/client-address.test.ts +78 -78
- package/test/client-csrf.test.ts +61 -61
- package/test/client-dir.test.ts +101 -69
- package/test/client-router.test.ts +789 -734
- package/test/coordinator.test.ts +96 -94
- package/test/deferred.test.ts +256 -256
- package/test/dev-loader.test.ts +30 -30
- package/test/env.test.ts +168 -168
- package/test/force-production.test.ts +44 -0
- package/test/images.test.ts +49 -49
- package/test/locals-header.test.ts +61 -0
- package/test/middleware.test.ts +243 -243
- package/test/parser-plugins.test.ts +92 -92
- package/test/plugin-handle.test.ts +62 -62
- package/test/plugin-services-context.test.ts +97 -97
- package/test/preload.test.ts +48 -48
- package/test/prerender.test.ts +353 -0
- package/test/rendering.test.ts +798 -798
- package/test/required-env.test.ts +32 -0
- package/test/rewrite-html.test.ts +90 -0
- package/test/scanning.test.ts +349 -314
- package/test/server.test.ts +640 -619
- package/test/services.test.ts +90 -90
- package/test/streaming.test.ts +378 -378
- package/test/testing-helpers.test.ts +166 -0
- package/test/typegen.test.ts +805 -799
- package/test/warm.test.ts +96 -96
- package/test/worker-context.test.ts +59 -59
- package/test/workspace-files.test.ts +149 -146
- package/test/workspace-versions.test.ts +131 -131
- package/.grimoire/_routes.ts +0 -4
- package/public/__grimoire__/client.js +0 -55
- package/public/__grimoire__/hydrate.js +0 -63
|
@@ -0,0 +1,1241 @@
|
|
|
1
|
+
// ../runtime/async-boundary.ts
|
|
2
|
+
function __asyncBoundary(factory, Loading, Err) {
|
|
3
|
+
const container = document.createElement("div");
|
|
4
|
+
container.dataset.asyncBoundary = "1";
|
|
5
|
+
if (Loading) {
|
|
6
|
+
const node = Loading();
|
|
7
|
+
if (node)
|
|
8
|
+
container.appendChild(node);
|
|
9
|
+
}
|
|
10
|
+
factory().then((node) => {
|
|
11
|
+
if (node)
|
|
12
|
+
container.replaceChildren(node);
|
|
13
|
+
else
|
|
14
|
+
container.replaceChildren();
|
|
15
|
+
}).catch((err) => {
|
|
16
|
+
if (Err) {
|
|
17
|
+
const errNode = Err({ error: err });
|
|
18
|
+
if (errNode)
|
|
19
|
+
container.replaceChildren(errNode);
|
|
20
|
+
} else {
|
|
21
|
+
console.error("[sigil] async component error:", err);
|
|
22
|
+
container.replaceChildren();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return container;
|
|
26
|
+
}
|
|
27
|
+
// ../runtime/boundary.ts
|
|
28
|
+
function Boundary(props) {
|
|
29
|
+
const error = createSignal(null);
|
|
30
|
+
const reset = () => error.set(null);
|
|
31
|
+
if (error()) {
|
|
32
|
+
return props.fallbackError ? props.fallbackError({ error: error(), reset }) : null;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return props.children;
|
|
36
|
+
} catch (e) {
|
|
37
|
+
props.onError?.(e);
|
|
38
|
+
error.set(e);
|
|
39
|
+
return props.fallbackError ? props.fallbackError({ error: e, reset }) : null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// ../runtime/easing.ts
|
|
43
|
+
function linear(t) {
|
|
44
|
+
return t;
|
|
45
|
+
}
|
|
46
|
+
function easeInQuad(t) {
|
|
47
|
+
return t * t;
|
|
48
|
+
}
|
|
49
|
+
function easeOutQuad(t) {
|
|
50
|
+
return t * (2 - t);
|
|
51
|
+
}
|
|
52
|
+
function easeInOutQuad(t) {
|
|
53
|
+
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
54
|
+
}
|
|
55
|
+
function easeInCubic(t) {
|
|
56
|
+
return t * t * t;
|
|
57
|
+
}
|
|
58
|
+
function easeOutCubic(t) {
|
|
59
|
+
return --t * t * t + 1;
|
|
60
|
+
}
|
|
61
|
+
function easeInOutCubic(t) {
|
|
62
|
+
return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
|
|
63
|
+
}
|
|
64
|
+
function easeInQuart(t) {
|
|
65
|
+
return t * t * t * t;
|
|
66
|
+
}
|
|
67
|
+
function easeOutQuart(t) {
|
|
68
|
+
return 1 - --t * t * t * t;
|
|
69
|
+
}
|
|
70
|
+
function easeInOutQuart(t) {
|
|
71
|
+
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
|
|
72
|
+
}
|
|
73
|
+
function easeInQuint(t) {
|
|
74
|
+
return t * t * t * t * t;
|
|
75
|
+
}
|
|
76
|
+
function easeOutQuint(t) {
|
|
77
|
+
return 1 + --t * t * t * t * t;
|
|
78
|
+
}
|
|
79
|
+
function easeInOutQuint(t) {
|
|
80
|
+
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
|
|
81
|
+
}
|
|
82
|
+
function easeInSine(t) {
|
|
83
|
+
return 1 - Math.cos(t * Math.PI / 2);
|
|
84
|
+
}
|
|
85
|
+
function easeOutSine(t) {
|
|
86
|
+
return Math.sin(t * Math.PI / 2);
|
|
87
|
+
}
|
|
88
|
+
function easeInOutSine(t) {
|
|
89
|
+
return -(Math.cos(Math.PI * t) - 1) / 2;
|
|
90
|
+
}
|
|
91
|
+
// ../runtime/reactivity/map.ts
|
|
92
|
+
class ReactiveMap extends Map {
|
|
93
|
+
#keyVersions = new Map;
|
|
94
|
+
#structVersion;
|
|
95
|
+
#structVal = 0;
|
|
96
|
+
#getKeyVersion(key) {
|
|
97
|
+
let sig = this.#keyVersions.get(key);
|
|
98
|
+
if (!sig) {
|
|
99
|
+
const inner = createSignal(0);
|
|
100
|
+
this.#keyVersions.set(key, inner);
|
|
101
|
+
sig = inner;
|
|
102
|
+
}
|
|
103
|
+
return sig;
|
|
104
|
+
}
|
|
105
|
+
#bumpKey(key) {
|
|
106
|
+
const sig = this.#keyVersions.get(key);
|
|
107
|
+
if (sig) {
|
|
108
|
+
const v = sig.peek() + 1;
|
|
109
|
+
sig.set(v);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
#bumpStruct() {
|
|
113
|
+
this.#structVal++;
|
|
114
|
+
this.#structVersion.set(this.#structVal);
|
|
115
|
+
}
|
|
116
|
+
constructor(entries) {
|
|
117
|
+
super(entries);
|
|
118
|
+
this.#structVersion = createSignal(0);
|
|
119
|
+
if (entries) {
|
|
120
|
+
for (const [k] of entries)
|
|
121
|
+
this.#getKeyVersion(k);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
get(key) {
|
|
125
|
+
this.#getKeyVersion(key)();
|
|
126
|
+
return super.get(key);
|
|
127
|
+
}
|
|
128
|
+
set(key, value) {
|
|
129
|
+
const existed = super.has(key);
|
|
130
|
+
super.set(key, value);
|
|
131
|
+
this.#bumpKey(key);
|
|
132
|
+
if (!existed)
|
|
133
|
+
this.#bumpStruct();
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
delete(key) {
|
|
137
|
+
const result = super.delete(key);
|
|
138
|
+
if (result) {
|
|
139
|
+
this.#bumpKey(key);
|
|
140
|
+
this.#bumpStruct();
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
clear() {
|
|
145
|
+
if (this.size > 0) {
|
|
146
|
+
for (const key of this.keys())
|
|
147
|
+
this.#bumpKey(key);
|
|
148
|
+
super.clear();
|
|
149
|
+
this.#bumpStruct();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
forEach(callbackfn, thisArg) {
|
|
153
|
+
this.#structVersion();
|
|
154
|
+
super.forEach(callbackfn, thisArg);
|
|
155
|
+
}
|
|
156
|
+
get size() {
|
|
157
|
+
this.#structVersion();
|
|
158
|
+
return super.size;
|
|
159
|
+
}
|
|
160
|
+
entries() {
|
|
161
|
+
this.#structVersion();
|
|
162
|
+
return super.entries();
|
|
163
|
+
}
|
|
164
|
+
keys() {
|
|
165
|
+
this.#structVersion();
|
|
166
|
+
return super.keys();
|
|
167
|
+
}
|
|
168
|
+
values() {
|
|
169
|
+
this.#structVersion();
|
|
170
|
+
return super.values();
|
|
171
|
+
}
|
|
172
|
+
[Symbol.iterator]() {
|
|
173
|
+
this.#structVersion();
|
|
174
|
+
return super[Symbol.iterator]();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// ../runtime/reactivity/set.ts
|
|
178
|
+
class ReactiveSet extends Set {
|
|
179
|
+
#version;
|
|
180
|
+
#versionVal = 0;
|
|
181
|
+
constructor(values) {
|
|
182
|
+
super(values);
|
|
183
|
+
this.#version = createSignal(0);
|
|
184
|
+
}
|
|
185
|
+
#bump() {
|
|
186
|
+
this.#versionVal++;
|
|
187
|
+
this.#version.set(this.#versionVal);
|
|
188
|
+
}
|
|
189
|
+
has(value) {
|
|
190
|
+
this.#version();
|
|
191
|
+
return super.has(value);
|
|
192
|
+
}
|
|
193
|
+
add(value) {
|
|
194
|
+
const sizeBefore = super.size;
|
|
195
|
+
super.add(value);
|
|
196
|
+
if (super.size !== sizeBefore)
|
|
197
|
+
this.#bump();
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
delete(value) {
|
|
201
|
+
const result = super.delete(value);
|
|
202
|
+
if (result)
|
|
203
|
+
this.#bump();
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
clear() {
|
|
207
|
+
if (this.size > 0) {
|
|
208
|
+
super.clear();
|
|
209
|
+
this.#bump();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
forEach(callbackfn, thisArg) {
|
|
213
|
+
this.#version();
|
|
214
|
+
super.forEach(callbackfn, thisArg);
|
|
215
|
+
}
|
|
216
|
+
get size() {
|
|
217
|
+
this.#version();
|
|
218
|
+
return super.size;
|
|
219
|
+
}
|
|
220
|
+
entries() {
|
|
221
|
+
this.#version();
|
|
222
|
+
return super.entries();
|
|
223
|
+
}
|
|
224
|
+
keys() {
|
|
225
|
+
this.#version();
|
|
226
|
+
return super.keys();
|
|
227
|
+
}
|
|
228
|
+
values() {
|
|
229
|
+
this.#version();
|
|
230
|
+
return super.values();
|
|
231
|
+
}
|
|
232
|
+
[Symbol.iterator]() {
|
|
233
|
+
this.#version();
|
|
234
|
+
return super[Symbol.iterator]();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// ../runtime/transition.ts
|
|
238
|
+
var outRegistry = new WeakMap;
|
|
239
|
+
function mountTransition(el, spec, kind) {
|
|
240
|
+
const [fn, params] = Array.isArray(spec) ? spec : [spec, undefined];
|
|
241
|
+
if (kind === "in" || kind === "transition") {
|
|
242
|
+
fn(el, params, "in");
|
|
243
|
+
}
|
|
244
|
+
if (kind === "out" || kind === "transition") {
|
|
245
|
+
outRegistry.set(el, { fn, params });
|
|
246
|
+
}
|
|
247
|
+
return () => {
|
|
248
|
+
outRegistry.delete(el);
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function removeAnimated(node) {
|
|
252
|
+
if (!(node instanceof Element)) {
|
|
253
|
+
node.remove();
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const entry = outRegistry.get(node);
|
|
257
|
+
if (!entry) {
|
|
258
|
+
node.remove();
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const animation = entry.fn(node, entry.params, "out");
|
|
262
|
+
if (animation?.finished && typeof animation.finished.finally === "function") {
|
|
263
|
+
animation.finished.finally(() => {
|
|
264
|
+
node.remove();
|
|
265
|
+
}).catch(() => {
|
|
266
|
+
node.remove();
|
|
267
|
+
});
|
|
268
|
+
} else {
|
|
269
|
+
node.remove();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ../runtime/index.ts
|
|
274
|
+
var SIGIL_SAFE = Symbol.for("sigil.safe");
|
|
275
|
+
|
|
276
|
+
class SafeHtml {
|
|
277
|
+
v;
|
|
278
|
+
[SIGIL_SAFE] = true;
|
|
279
|
+
constructor(v) {
|
|
280
|
+
this.v = v;
|
|
281
|
+
}
|
|
282
|
+
toString() {
|
|
283
|
+
return this.v;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
var currentEffect = null;
|
|
287
|
+
var currentDeps = null;
|
|
288
|
+
var batchDepth = 0;
|
|
289
|
+
var scheduledFlush = false;
|
|
290
|
+
var pendingEffects = new Set;
|
|
291
|
+
var pendingPreEffects = new Set;
|
|
292
|
+
function flush() {
|
|
293
|
+
scheduledFlush = false;
|
|
294
|
+
pendingPreEffects.forEach((e) => e());
|
|
295
|
+
pendingPreEffects.clear();
|
|
296
|
+
pendingEffects.forEach((e) => e());
|
|
297
|
+
pendingEffects.clear();
|
|
298
|
+
}
|
|
299
|
+
function scheduleEffect(fn) {
|
|
300
|
+
const target = fn.__sigil_pre ? pendingPreEffects : pendingEffects;
|
|
301
|
+
target.add(fn);
|
|
302
|
+
if (batchDepth === 0 && !scheduledFlush) {
|
|
303
|
+
scheduledFlush = true;
|
|
304
|
+
queueMicrotask(flush);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
var targetDepsMap = new WeakMap;
|
|
308
|
+
function getDeps(target, key) {
|
|
309
|
+
let deps = targetDepsMap.get(target);
|
|
310
|
+
if (!deps) {
|
|
311
|
+
deps = new Map;
|
|
312
|
+
targetDepsMap.set(target, deps);
|
|
313
|
+
}
|
|
314
|
+
let set = deps.get(key);
|
|
315
|
+
if (!set) {
|
|
316
|
+
set = new Set;
|
|
317
|
+
deps.set(key, set);
|
|
318
|
+
}
|
|
319
|
+
return set;
|
|
320
|
+
}
|
|
321
|
+
function track(target, key) {
|
|
322
|
+
if (currentEffect && currentDeps) {
|
|
323
|
+
const deps = getDeps(target, key);
|
|
324
|
+
deps.add(currentEffect);
|
|
325
|
+
currentDeps.add(deps);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function trigger(target, key) {
|
|
329
|
+
const deps = targetDepsMap.get(target);
|
|
330
|
+
if (!deps)
|
|
331
|
+
return;
|
|
332
|
+
const set = deps.get(key);
|
|
333
|
+
if (!set)
|
|
334
|
+
return;
|
|
335
|
+
for (const fn of [...set]) {
|
|
336
|
+
scheduleEffect(fn);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
var proxyCache = new WeakMap;
|
|
340
|
+
var proxyToTarget = new WeakMap;
|
|
341
|
+
var reactiveTargets = new WeakSet;
|
|
342
|
+
var ARRAY_MUTATORS = new Set([
|
|
343
|
+
"push",
|
|
344
|
+
"pop",
|
|
345
|
+
"shift",
|
|
346
|
+
"unshift",
|
|
347
|
+
"splice",
|
|
348
|
+
"sort",
|
|
349
|
+
"reverse",
|
|
350
|
+
"fill"
|
|
351
|
+
]);
|
|
352
|
+
function createReactiveProxy(target) {
|
|
353
|
+
const existing = proxyCache.get(target);
|
|
354
|
+
if (existing)
|
|
355
|
+
return existing;
|
|
356
|
+
const proxy = new Proxy(target, {
|
|
357
|
+
get(target, key, receiver) {
|
|
358
|
+
if (Array.isArray(target) && typeof key === "string" && ARRAY_MUTATORS.has(key)) {
|
|
359
|
+
return (...args) => {
|
|
360
|
+
const result = target[key](...args);
|
|
361
|
+
trigger(target, "length");
|
|
362
|
+
return result;
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
if (key === "set") {
|
|
366
|
+
return (newValue) => {
|
|
367
|
+
const oldKeys = new Set(Object.keys(target));
|
|
368
|
+
const newKeys = new Set(Object.keys(newValue));
|
|
369
|
+
for (const k of oldKeys) {
|
|
370
|
+
if (!newKeys.has(k)) {
|
|
371
|
+
delete target[k];
|
|
372
|
+
trigger(target, k);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
for (const k of newKeys) {
|
|
376
|
+
target[k] = newValue[k];
|
|
377
|
+
trigger(target, k);
|
|
378
|
+
}
|
|
379
|
+
if (Array.isArray(target)) {
|
|
380
|
+
target.length = newValue.length;
|
|
381
|
+
trigger(target, "length");
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
if (key === "peek") {
|
|
386
|
+
return () => target;
|
|
387
|
+
}
|
|
388
|
+
if (typeof key === "symbol") {
|
|
389
|
+
return Reflect.get(target, key, receiver);
|
|
390
|
+
}
|
|
391
|
+
track(target, key);
|
|
392
|
+
const value = target[key];
|
|
393
|
+
if (typeof value === "object" && value !== null) {
|
|
394
|
+
return createReactiveProxy(value);
|
|
395
|
+
}
|
|
396
|
+
return value;
|
|
397
|
+
},
|
|
398
|
+
set(target, key, newValue, receiver) {
|
|
399
|
+
const oldValue = target[key];
|
|
400
|
+
const result = Reflect.set(target, key, newValue, receiver);
|
|
401
|
+
if (oldValue !== newValue) {
|
|
402
|
+
trigger(target, key);
|
|
403
|
+
if (Array.isArray(target) && typeof key === "string" && !Number.isNaN(Number(key))) {
|
|
404
|
+
trigger(target, "length");
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return result;
|
|
408
|
+
},
|
|
409
|
+
deleteProperty(target, key) {
|
|
410
|
+
const result = Reflect.deleteProperty(target, key);
|
|
411
|
+
trigger(target, key);
|
|
412
|
+
return result;
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
proxyCache.set(target, proxy);
|
|
416
|
+
proxyToTarget.set(proxy, target);
|
|
417
|
+
reactiveTargets.add(target);
|
|
418
|
+
return proxy;
|
|
419
|
+
}
|
|
420
|
+
function batch(fn) {
|
|
421
|
+
batchDepth++;
|
|
422
|
+
fn();
|
|
423
|
+
batchDepth--;
|
|
424
|
+
if (batchDepth === 0) {
|
|
425
|
+
scheduledFlush = false;
|
|
426
|
+
flush();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
function tick() {
|
|
430
|
+
return new Promise((resolve) => queueMicrotask(resolve));
|
|
431
|
+
}
|
|
432
|
+
var primitiveSignals = new WeakSet;
|
|
433
|
+
function createPrimitiveSignal(initial) {
|
|
434
|
+
const subs = new Set;
|
|
435
|
+
let value = initial;
|
|
436
|
+
const getter = () => {
|
|
437
|
+
if (currentEffect && currentDeps) {
|
|
438
|
+
subs.add(currentEffect);
|
|
439
|
+
currentDeps.add(subs);
|
|
440
|
+
}
|
|
441
|
+
return value;
|
|
442
|
+
};
|
|
443
|
+
getter.set = (next) => {
|
|
444
|
+
value = next;
|
|
445
|
+
for (const fn of [...subs]) {
|
|
446
|
+
scheduleEffect(fn);
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
getter.peek = () => value;
|
|
450
|
+
primitiveSignals.add(getter);
|
|
451
|
+
return getter;
|
|
452
|
+
}
|
|
453
|
+
function readStore(value) {
|
|
454
|
+
return typeof value === "function" && primitiveSignals.has(value) ? value() : value;
|
|
455
|
+
}
|
|
456
|
+
var storeGetters = new WeakMap;
|
|
457
|
+
function createSignal(initial) {
|
|
458
|
+
if (typeof initial === "object" && initial !== null) {
|
|
459
|
+
const proxy = createReactiveProxy(initial);
|
|
460
|
+
const getter = () => {
|
|
461
|
+
if (Array.isArray(initial)) {
|
|
462
|
+
track(initial, "length");
|
|
463
|
+
}
|
|
464
|
+
return proxy;
|
|
465
|
+
};
|
|
466
|
+
getter.set = (next) => proxy.set(next);
|
|
467
|
+
getter.peek = () => initial;
|
|
468
|
+
const forwarded = new Proxy(getter, {
|
|
469
|
+
get: (fn, key) => key === "set" || key === "peek" ? Reflect.get(fn, key) : Reflect.get(proxy, key),
|
|
470
|
+
set: (_fn, key, value) => Reflect.set(proxy, key, value),
|
|
471
|
+
has: (_fn, key) => (key in proxy),
|
|
472
|
+
deleteProperty: (_fn, key) => Reflect.deleteProperty(proxy, key),
|
|
473
|
+
ownKeys: () => Reflect.ownKeys(proxy),
|
|
474
|
+
getOwnPropertyDescriptor: (_fn, key) => {
|
|
475
|
+
const d = Reflect.getOwnPropertyDescriptor(proxy, key);
|
|
476
|
+
return d && { ...d, configurable: true };
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
storeGetters.set(forwarded, proxy);
|
|
480
|
+
return forwarded;
|
|
481
|
+
}
|
|
482
|
+
return createPrimitiveSignal(initial);
|
|
483
|
+
}
|
|
484
|
+
function createRawSignal(initial) {
|
|
485
|
+
return createPrimitiveSignal(initial);
|
|
486
|
+
}
|
|
487
|
+
function deepUnproxy(value) {
|
|
488
|
+
if (typeof value === "function" && storeGetters.has(value))
|
|
489
|
+
return deepUnproxy(storeGetters.get(value));
|
|
490
|
+
if (typeof value !== "object" || value === null)
|
|
491
|
+
return value;
|
|
492
|
+
const raw = proxyToTarget.get(value);
|
|
493
|
+
if (!raw)
|
|
494
|
+
return value;
|
|
495
|
+
if (Array.isArray(raw)) {
|
|
496
|
+
return raw.map(deepUnproxy);
|
|
497
|
+
}
|
|
498
|
+
const result = {};
|
|
499
|
+
for (const key of Object.keys(raw)) {
|
|
500
|
+
result[key] = deepUnproxy(raw[key]);
|
|
501
|
+
}
|
|
502
|
+
return result;
|
|
503
|
+
}
|
|
504
|
+
function snapshot(value) {
|
|
505
|
+
return deepUnproxy(value);
|
|
506
|
+
}
|
|
507
|
+
function tracking() {
|
|
508
|
+
return currentEffect !== null;
|
|
509
|
+
}
|
|
510
|
+
function untrack(fn) {
|
|
511
|
+
const prevEffect = currentEffect;
|
|
512
|
+
const prevDeps = currentDeps;
|
|
513
|
+
currentEffect = null;
|
|
514
|
+
currentDeps = null;
|
|
515
|
+
try {
|
|
516
|
+
return fn();
|
|
517
|
+
} finally {
|
|
518
|
+
currentEffect = prevEffect;
|
|
519
|
+
currentDeps = prevDeps;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
function createInspectEffect(getValues, cb) {
|
|
523
|
+
if (typeof process !== "undefined" && false)
|
|
524
|
+
;
|
|
525
|
+
createEffect(() => {
|
|
526
|
+
const vals = getValues();
|
|
527
|
+
if (cb)
|
|
528
|
+
cb(vals);
|
|
529
|
+
else
|
|
530
|
+
console.log(...vals);
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
function createEffectPre(fn) {
|
|
534
|
+
let cleanup;
|
|
535
|
+
const ownDeps = new Set;
|
|
536
|
+
const effect = () => {
|
|
537
|
+
if (cleanup)
|
|
538
|
+
cleanup();
|
|
539
|
+
for (const depSet of ownDeps)
|
|
540
|
+
depSet.delete(effect);
|
|
541
|
+
ownDeps.clear();
|
|
542
|
+
const prevEffect = currentEffect;
|
|
543
|
+
const prevDeps = currentDeps;
|
|
544
|
+
currentEffect = effect;
|
|
545
|
+
currentDeps = ownDeps;
|
|
546
|
+
try {
|
|
547
|
+
cleanup = fn();
|
|
548
|
+
} finally {
|
|
549
|
+
currentEffect = prevEffect;
|
|
550
|
+
currentDeps = prevDeps;
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
effect.__sigil_pre = true;
|
|
554
|
+
effect();
|
|
555
|
+
const dispose = () => {
|
|
556
|
+
for (const depSet of ownDeps)
|
|
557
|
+
depSet.delete(effect);
|
|
558
|
+
ownDeps.clear();
|
|
559
|
+
if (cleanup)
|
|
560
|
+
cleanup();
|
|
561
|
+
};
|
|
562
|
+
globalThis.__sigilEffectScope?.push(dispose);
|
|
563
|
+
return dispose;
|
|
564
|
+
}
|
|
565
|
+
function createProfilerEffect(_name, fn) {
|
|
566
|
+
return createEffect(() => {
|
|
567
|
+
if (typeof process !== "undefined" && false) {}
|
|
568
|
+
const _start = performance.now();
|
|
569
|
+
const cleanup = fn();
|
|
570
|
+
const _end = performance.now();
|
|
571
|
+
return cleanup;
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
var deferredEffectQueue = [];
|
|
575
|
+
function flushDeferredEffects() {
|
|
576
|
+
const pending = deferredEffectQueue.splice(0);
|
|
577
|
+
for (const run of pending)
|
|
578
|
+
run();
|
|
579
|
+
}
|
|
580
|
+
var activeProbe = null;
|
|
581
|
+
function createEffect(fn) {
|
|
582
|
+
let cleanup;
|
|
583
|
+
const ownDeps = new Set;
|
|
584
|
+
const effect = () => {
|
|
585
|
+
if (cleanup)
|
|
586
|
+
cleanup();
|
|
587
|
+
for (const depSet of ownDeps)
|
|
588
|
+
depSet.delete(effect);
|
|
589
|
+
ownDeps.clear();
|
|
590
|
+
const prevEffect = currentEffect;
|
|
591
|
+
const prevDeps = currentDeps;
|
|
592
|
+
currentEffect = effect;
|
|
593
|
+
currentDeps = ownDeps;
|
|
594
|
+
try {
|
|
595
|
+
cleanup = fn();
|
|
596
|
+
} finally {
|
|
597
|
+
currentEffect = prevEffect;
|
|
598
|
+
currentDeps = prevDeps;
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
if (globalThis.__sigilDeferEffects) {
|
|
602
|
+
deferredEffectQueue.push(() => effect());
|
|
603
|
+
} else {
|
|
604
|
+
effect();
|
|
605
|
+
if (activeProbe && ownDeps.size > 0)
|
|
606
|
+
activeProbe.live++;
|
|
607
|
+
}
|
|
608
|
+
const dispose = () => {
|
|
609
|
+
for (const depSet of ownDeps)
|
|
610
|
+
depSet.delete(effect);
|
|
611
|
+
ownDeps.clear();
|
|
612
|
+
if (cleanup)
|
|
613
|
+
cleanup();
|
|
614
|
+
};
|
|
615
|
+
globalThis.__sigilEffectScope?.push(dispose);
|
|
616
|
+
return dispose;
|
|
617
|
+
}
|
|
618
|
+
function withEffectScope(fn) {
|
|
619
|
+
const prev = globalThis.__sigilEffectScope;
|
|
620
|
+
const disposers = [];
|
|
621
|
+
globalThis.__sigilEffectScope = disposers;
|
|
622
|
+
try {
|
|
623
|
+
fn();
|
|
624
|
+
} finally {
|
|
625
|
+
globalThis.__sigilEffectScope = prev;
|
|
626
|
+
}
|
|
627
|
+
return () => {
|
|
628
|
+
for (const d of disposers)
|
|
629
|
+
d();
|
|
630
|
+
disposers.length = 0;
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
function createRoot(fn) {
|
|
634
|
+
const g = globalThis;
|
|
635
|
+
const prev = g.__sigilEffectScope;
|
|
636
|
+
const disposers = [];
|
|
637
|
+
g.__sigilEffectScope = disposers;
|
|
638
|
+
const dispose = () => {
|
|
639
|
+
for (const d of disposers.splice(0))
|
|
640
|
+
d();
|
|
641
|
+
};
|
|
642
|
+
try {
|
|
643
|
+
return fn(dispose);
|
|
644
|
+
} finally {
|
|
645
|
+
g.__sigilEffectScope = prev;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function createResource(fetcher, source) {
|
|
649
|
+
const data = createSignal(undefined);
|
|
650
|
+
const loading = createSignal(true);
|
|
651
|
+
const error = createSignal(undefined);
|
|
652
|
+
const version = createSignal(0);
|
|
653
|
+
let requestCount = 0;
|
|
654
|
+
let versionCounter = 0;
|
|
655
|
+
const refetch = () => {
|
|
656
|
+
versionCounter++;
|
|
657
|
+
version.set(versionCounter);
|
|
658
|
+
};
|
|
659
|
+
createEffect(() => {
|
|
660
|
+
const src = source?.();
|
|
661
|
+
version();
|
|
662
|
+
const id = ++requestCount;
|
|
663
|
+
loading.set(true);
|
|
664
|
+
error.set(undefined);
|
|
665
|
+
fetcher(src, { refetch }).then((result) => {
|
|
666
|
+
if (id !== requestCount)
|
|
667
|
+
return;
|
|
668
|
+
data.set(result);
|
|
669
|
+
loading.set(false);
|
|
670
|
+
}, (err) => {
|
|
671
|
+
if (id !== requestCount)
|
|
672
|
+
return;
|
|
673
|
+
error.set(err instanceof Error ? err : new Error(String(err)));
|
|
674
|
+
loading.set(false);
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
return { data, loading, error, refetch };
|
|
678
|
+
}
|
|
679
|
+
function createMemo(fn) {
|
|
680
|
+
const inner = createSignal(undefined);
|
|
681
|
+
createEffect(() => inner.set(fn()));
|
|
682
|
+
return inner;
|
|
683
|
+
}
|
|
684
|
+
var lastItemFor = new WeakMap;
|
|
685
|
+
function reconcile(anchor, keyMap, newItems, getKey, createNode) {
|
|
686
|
+
const newKeys = new Set(newItems.map((item, i) => getKey(item, i)));
|
|
687
|
+
for (const [key, node] of keyMap) {
|
|
688
|
+
if (!newKeys.has(key)) {
|
|
689
|
+
node.parentNode?.removeChild(node);
|
|
690
|
+
keyMap.delete(key);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
for (let i = 0;i < newItems.length; i++) {
|
|
694
|
+
const item = newItems[i];
|
|
695
|
+
const key = getKey(item, i);
|
|
696
|
+
let node = keyMap.get(key);
|
|
697
|
+
if (node && lastItemFor.has(node) && !Object.is(lastItemFor.get(node), item)) {
|
|
698
|
+
node.parentNode?.removeChild(node);
|
|
699
|
+
keyMap.delete(key);
|
|
700
|
+
node = undefined;
|
|
701
|
+
}
|
|
702
|
+
if (!node) {
|
|
703
|
+
node = createNode(item);
|
|
704
|
+
lastItemFor.set(node, item);
|
|
705
|
+
keyMap.set(key, node);
|
|
706
|
+
}
|
|
707
|
+
anchor.before?.(node);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
711
|
+
var claimedNodes = new WeakSet;
|
|
712
|
+
function isClaimed(el) {
|
|
713
|
+
return claimedNodes.has(el);
|
|
714
|
+
}
|
|
715
|
+
function claim(nodes, tag, parent) {
|
|
716
|
+
for (let i = 0;i < nodes.length; i++) {
|
|
717
|
+
const node = nodes[i];
|
|
718
|
+
if (node instanceof Element && node.tagName.toLowerCase() === tag.toLowerCase()) {
|
|
719
|
+
if (tag.toLowerCase() === "input" && node.hasAttribute("data-grimoire-csrf")) {
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
nodes.splice(i, 1);
|
|
723
|
+
claimedNodes.add(node);
|
|
724
|
+
return node;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
const el = tag.toLowerCase() === "svg" || parent?.namespaceURI === SVG_NS ? document.createElementNS(SVG_NS, tag) : document.createElement(tag);
|
|
728
|
+
if (parent)
|
|
729
|
+
parent.appendChild(el);
|
|
730
|
+
return el;
|
|
731
|
+
}
|
|
732
|
+
var SVG_PROP_ONLY = new Set(["textContent", "innerHTML", "outerHTML"]);
|
|
733
|
+
var writableCache = new WeakMap;
|
|
734
|
+
function isWritableProp(el, name) {
|
|
735
|
+
const proto = Object.getPrototypeOf(el);
|
|
736
|
+
let cache = writableCache.get(proto);
|
|
737
|
+
if (!cache)
|
|
738
|
+
writableCache.set(proto, cache = new Map);
|
|
739
|
+
let writable = cache.get(name);
|
|
740
|
+
if (writable === undefined) {
|
|
741
|
+
writable = false;
|
|
742
|
+
for (let o = proto;o; o = Object.getPrototypeOf(o)) {
|
|
743
|
+
const d = Object.getOwnPropertyDescriptor(o, name);
|
|
744
|
+
if (d) {
|
|
745
|
+
writable = !!(d.set || d.writable);
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
cache.set(name, writable);
|
|
750
|
+
}
|
|
751
|
+
return writable || Object.hasOwn(el, name);
|
|
752
|
+
}
|
|
753
|
+
var PROP_ATTR = {
|
|
754
|
+
className: "class",
|
|
755
|
+
htmlFor: "for"
|
|
756
|
+
};
|
|
757
|
+
function setAttr(el, attr, value) {
|
|
758
|
+
if (value == null)
|
|
759
|
+
el.removeAttribute(attr);
|
|
760
|
+
else if (typeof value === "boolean" && !attr.includes("-")) {
|
|
761
|
+
if (value)
|
|
762
|
+
el.setAttribute(attr, "");
|
|
763
|
+
else
|
|
764
|
+
el.removeAttribute(attr);
|
|
765
|
+
} else
|
|
766
|
+
el.setAttribute(attr, String(value));
|
|
767
|
+
}
|
|
768
|
+
function clearProp(el, name) {
|
|
769
|
+
const rec = el;
|
|
770
|
+
if (typeof rec[name] === "boolean")
|
|
771
|
+
rec[name] = false;
|
|
772
|
+
else if (name === "value" || name === "innerHTML" || name === "textContent" || name === "innerText")
|
|
773
|
+
rec[name] = "";
|
|
774
|
+
else
|
|
775
|
+
el.removeAttribute(PROP_ATTR[name] ?? name.toLowerCase());
|
|
776
|
+
}
|
|
777
|
+
var UNITLESS = new Set([
|
|
778
|
+
"animation-iteration-count",
|
|
779
|
+
"aspect-ratio",
|
|
780
|
+
"border-image-outset",
|
|
781
|
+
"border-image-slice",
|
|
782
|
+
"border-image-width",
|
|
783
|
+
"column-count",
|
|
784
|
+
"columns",
|
|
785
|
+
"fill-opacity",
|
|
786
|
+
"flex",
|
|
787
|
+
"flex-grow",
|
|
788
|
+
"flex-shrink",
|
|
789
|
+
"flood-opacity",
|
|
790
|
+
"font-weight",
|
|
791
|
+
"grid-area",
|
|
792
|
+
"grid-column",
|
|
793
|
+
"grid-column-end",
|
|
794
|
+
"grid-column-start",
|
|
795
|
+
"grid-row",
|
|
796
|
+
"grid-row-end",
|
|
797
|
+
"grid-row-start",
|
|
798
|
+
"line-clamp",
|
|
799
|
+
"line-height",
|
|
800
|
+
"opacity",
|
|
801
|
+
"order",
|
|
802
|
+
"orphans",
|
|
803
|
+
"scale",
|
|
804
|
+
"stop-opacity",
|
|
805
|
+
"stroke-dasharray",
|
|
806
|
+
"stroke-dashoffset",
|
|
807
|
+
"stroke-miterlimit",
|
|
808
|
+
"stroke-opacity",
|
|
809
|
+
"stroke-width",
|
|
810
|
+
"tab-size",
|
|
811
|
+
"widows",
|
|
812
|
+
"z-index",
|
|
813
|
+
"zoom"
|
|
814
|
+
]);
|
|
815
|
+
function cssName(key) {
|
|
816
|
+
if (key.startsWith("--"))
|
|
817
|
+
return key;
|
|
818
|
+
const kebab = key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
819
|
+
return kebab.startsWith("ms-") ? `-${kebab}` : kebab;
|
|
820
|
+
}
|
|
821
|
+
function cssValue(name, value) {
|
|
822
|
+
if (value == null || value === false || value === "")
|
|
823
|
+
return null;
|
|
824
|
+
if (typeof value === "number" && value !== 0 && !name.startsWith("--") && !UNITLESS.has(name))
|
|
825
|
+
return `${value}px`;
|
|
826
|
+
return String(value);
|
|
827
|
+
}
|
|
828
|
+
function setStyleProp(el, key, value) {
|
|
829
|
+
const style = el.style;
|
|
830
|
+
const name = cssName(key);
|
|
831
|
+
const v = cssValue(name, value);
|
|
832
|
+
if (v === null)
|
|
833
|
+
style.removeProperty(name);
|
|
834
|
+
else
|
|
835
|
+
style.setProperty(name, v);
|
|
836
|
+
}
|
|
837
|
+
function setStyle(el, value) {
|
|
838
|
+
if (value == null || value === false)
|
|
839
|
+
el.removeAttribute("style");
|
|
840
|
+
else if (typeof value === "object") {
|
|
841
|
+
el.removeAttribute("style");
|
|
842
|
+
for (const [k, v] of Object.entries(value))
|
|
843
|
+
setStyleProp(el, k, v);
|
|
844
|
+
} else
|
|
845
|
+
el.setAttribute("style", String(value));
|
|
846
|
+
}
|
|
847
|
+
function setProp(el, name, value) {
|
|
848
|
+
if (name === "style")
|
|
849
|
+
setStyle(el, value);
|
|
850
|
+
else if (el.namespaceURI === SVG_NS) {
|
|
851
|
+
if (SVG_PROP_ONLY.has(name))
|
|
852
|
+
el[name] = value;
|
|
853
|
+
else
|
|
854
|
+
setAttr(el, PROP_ATTR[name] ?? name, value);
|
|
855
|
+
} else if (!name.includes("-") && isWritableProp(el, name)) {
|
|
856
|
+
if (value == null)
|
|
857
|
+
clearProp(el, name);
|
|
858
|
+
else
|
|
859
|
+
el[name] = value;
|
|
860
|
+
} else {
|
|
861
|
+
setAttr(el, PROP_ATTR[name] ?? name, value);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
var SPREAD_PROP = {
|
|
865
|
+
class: "className",
|
|
866
|
+
for: "htmlFor"
|
|
867
|
+
};
|
|
868
|
+
function spread(el, props, attrs = true) {
|
|
869
|
+
if (!props)
|
|
870
|
+
return;
|
|
871
|
+
for (const [key, value] of Object.entries(props)) {
|
|
872
|
+
if (/^on[A-Z]/.test(key) && typeof value === "function") {
|
|
873
|
+
el.addEventListener(key.slice(2).toLowerCase(), value);
|
|
874
|
+
} else if (attrs && key !== "children" && key !== "key") {
|
|
875
|
+
setProp(el, SPREAD_PROP[key] ?? key, value);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
function claimText(nodes, parent) {
|
|
880
|
+
for (let i = 0;i < nodes.length; i++) {
|
|
881
|
+
const node = nodes[i];
|
|
882
|
+
if (node instanceof Text) {
|
|
883
|
+
nodes.splice(i, 1);
|
|
884
|
+
return node;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
const text = document.createTextNode("");
|
|
888
|
+
if (parent)
|
|
889
|
+
parent.appendChild(text);
|
|
890
|
+
return text;
|
|
891
|
+
}
|
|
892
|
+
function claimComment(nodes, text = "", parent) {
|
|
893
|
+
for (let i = 0;i < nodes.length; i++) {
|
|
894
|
+
const node = nodes[i];
|
|
895
|
+
if (node instanceof Comment && node.data === text) {
|
|
896
|
+
nodes.splice(i, 1);
|
|
897
|
+
return node;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
const comment = document.createComment(text);
|
|
901
|
+
if (parent)
|
|
902
|
+
parent.appendChild(comment);
|
|
903
|
+
return comment;
|
|
904
|
+
}
|
|
905
|
+
function skipStatic(nodes) {
|
|
906
|
+
let open = -1;
|
|
907
|
+
for (let i = 0;i < nodes.length; i++) {
|
|
908
|
+
const node = nodes[i];
|
|
909
|
+
if (node instanceof Comment && node.data === "s") {
|
|
910
|
+
open = i;
|
|
911
|
+
break;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
if (open === -1)
|
|
915
|
+
return null;
|
|
916
|
+
let close = open + 1;
|
|
917
|
+
let depth = 0;
|
|
918
|
+
for (;close < nodes.length; close++) {
|
|
919
|
+
const node = nodes[close];
|
|
920
|
+
if (!(node instanceof Comment))
|
|
921
|
+
continue;
|
|
922
|
+
if (node.data === "s")
|
|
923
|
+
depth++;
|
|
924
|
+
else if (node.data === "/s" && depth-- === 0)
|
|
925
|
+
break;
|
|
926
|
+
}
|
|
927
|
+
if (close >= nodes.length)
|
|
928
|
+
return null;
|
|
929
|
+
const run = nodes.splice(open, close - open + 1);
|
|
930
|
+
for (const node of run)
|
|
931
|
+
claimedNodes.add(node);
|
|
932
|
+
return run.find((n) => !(n instanceof Comment)) ?? run[0] ?? null;
|
|
933
|
+
}
|
|
934
|
+
function probeStatic(name, render) {
|
|
935
|
+
const g = globalThis;
|
|
936
|
+
const probe = { live: 0, listeners: 0 };
|
|
937
|
+
const prevProbe = activeProbe;
|
|
938
|
+
const prevDefer = g.__sigilDeferEffects;
|
|
939
|
+
let proto = Node.prototype;
|
|
940
|
+
while (proto && !Object.hasOwn(proto, "addEventListener")) {
|
|
941
|
+
proto = Object.getPrototypeOf(proto);
|
|
942
|
+
}
|
|
943
|
+
const add = proto.addEventListener;
|
|
944
|
+
activeProbe = probe;
|
|
945
|
+
g.__sigilDeferEffects = false;
|
|
946
|
+
proto.addEventListener = function(...args) {
|
|
947
|
+
probe.listeners++;
|
|
948
|
+
return add.apply(this, args);
|
|
949
|
+
};
|
|
950
|
+
let dispose;
|
|
951
|
+
pushHydrationNodes([]);
|
|
952
|
+
try {
|
|
953
|
+
dispose = withEffectScope(() => {
|
|
954
|
+
render();
|
|
955
|
+
});
|
|
956
|
+
} finally {
|
|
957
|
+
popHydrationNodes();
|
|
958
|
+
proto.addEventListener = add;
|
|
959
|
+
activeProbe = prevProbe;
|
|
960
|
+
g.__sigilDeferEffects = prevDefer;
|
|
961
|
+
dispose?.();
|
|
962
|
+
}
|
|
963
|
+
if (probe.live || probe.listeners) {
|
|
964
|
+
throw new Error(`[sigil] <${name}> was compiled as static and skipped during hydration, but rendering it created ${probe.live} live effect(s) and ${probe.listeners} event listener(s). ` + `The compiler's analysis missed something; add static={false} to this use to hydrate it, and run \`sigil explain\` to see how it was judged.`);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
function hydrateKeyedList(nodesVar, signalItems, getKey, createNode, parent) {
|
|
968
|
+
const keyMap = new Map;
|
|
969
|
+
const isMarker = (n, data) => n instanceof Comment && n.data === data;
|
|
970
|
+
const start = nodesVar.findIndex((n) => isMarker(n, "g"));
|
|
971
|
+
if (start === -1) {
|
|
972
|
+
const anchor = claimComment(nodesVar, "g", parent);
|
|
973
|
+
reconcile(anchor, keyMap, signalItems, getKey, createNode);
|
|
974
|
+
return { anchor, keyMap };
|
|
975
|
+
}
|
|
976
|
+
const anchor = nodesVar[start];
|
|
977
|
+
let end = nodesVar.findIndex((n, i) => i > start && isMarker(n, "/g"));
|
|
978
|
+
if (end === -1)
|
|
979
|
+
end = nodesVar.length;
|
|
980
|
+
const all = nodesVar.splice(0, nodesVar.length, ...nodesVar.slice(start + 1, end));
|
|
981
|
+
for (let i = 0;i < signalItems.length; i++) {
|
|
982
|
+
const item = signalItems[i];
|
|
983
|
+
const node = createNode(item);
|
|
984
|
+
lastItemFor.set(node, item);
|
|
985
|
+
keyMap.set(getKey(item, i), node);
|
|
986
|
+
}
|
|
987
|
+
for (const leftover of nodesVar)
|
|
988
|
+
leftover.remove();
|
|
989
|
+
all[end]?.remove();
|
|
990
|
+
nodesVar.splice(0, nodesVar.length, ...all.slice(0, start), ...all.slice(end + 1));
|
|
991
|
+
reconcile(anchor, keyMap, signalItems, getKey, createNode);
|
|
992
|
+
return { anchor, keyMap };
|
|
993
|
+
}
|
|
994
|
+
function insert(parent, value) {
|
|
995
|
+
if (value === false || value === null || value === undefined)
|
|
996
|
+
return;
|
|
997
|
+
if (typeof value === "function") {
|
|
998
|
+
insert(parent, value());
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
if (Array.isArray(value)) {
|
|
1002
|
+
for (const item of value)
|
|
1003
|
+
insert(parent, item);
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
if (value instanceof Node) {
|
|
1007
|
+
parent.appendChild(value);
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
parent.append(String(value));
|
|
1011
|
+
}
|
|
1012
|
+
function hydrateSlot(nodes, parent, value) {
|
|
1013
|
+
let open = -1;
|
|
1014
|
+
for (let i = 0;i < nodes.length; i++) {
|
|
1015
|
+
const node = nodes[i];
|
|
1016
|
+
if (node instanceof Comment && node.data === "g") {
|
|
1017
|
+
open = i;
|
|
1018
|
+
break;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if (open === -1) {
|
|
1022
|
+
insert(parent, value);
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
let close = open + 1;
|
|
1026
|
+
for (let depth = 0;close < nodes.length; close++) {
|
|
1027
|
+
const node = nodes[close];
|
|
1028
|
+
if (!(node instanceof Comment))
|
|
1029
|
+
continue;
|
|
1030
|
+
if (node.data === "g")
|
|
1031
|
+
depth++;
|
|
1032
|
+
else if (node.data === "/g" && depth-- === 0)
|
|
1033
|
+
break;
|
|
1034
|
+
}
|
|
1035
|
+
const inner = nodes.slice(open + 1, close);
|
|
1036
|
+
nodes.splice(open, close - open + 1);
|
|
1037
|
+
pushHydrationNodes(inner);
|
|
1038
|
+
try {
|
|
1039
|
+
attachHydrated(parent, value);
|
|
1040
|
+
} finally {
|
|
1041
|
+
popHydrationNodes();
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
function liveSlot(nodes, parent, read) {
|
|
1045
|
+
let start;
|
|
1046
|
+
let end;
|
|
1047
|
+
let inner = null;
|
|
1048
|
+
const open = nodes.findIndex((n) => n instanceof Comment && n.data === "g");
|
|
1049
|
+
if (open !== -1) {
|
|
1050
|
+
let close = open + 1;
|
|
1051
|
+
for (let depth = 0;close < nodes.length; close++) {
|
|
1052
|
+
const node = nodes[close];
|
|
1053
|
+
if (!(node instanceof Comment))
|
|
1054
|
+
continue;
|
|
1055
|
+
if (node.data === "g")
|
|
1056
|
+
depth++;
|
|
1057
|
+
else if (node.data === "/g" && depth-- === 0)
|
|
1058
|
+
break;
|
|
1059
|
+
}
|
|
1060
|
+
if (close < nodes.length) {
|
|
1061
|
+
start = nodes[open];
|
|
1062
|
+
end = nodes[close];
|
|
1063
|
+
inner = nodes.slice(open + 1, close);
|
|
1064
|
+
nodes.splice(open, close - open + 1);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
if (!start || !end) {
|
|
1068
|
+
start = document.createComment("g");
|
|
1069
|
+
end = document.createComment("/g");
|
|
1070
|
+
parent.appendChild(start);
|
|
1071
|
+
parent.appendChild(end);
|
|
1072
|
+
}
|
|
1073
|
+
let first = true;
|
|
1074
|
+
createEffect(() => {
|
|
1075
|
+
const value = read();
|
|
1076
|
+
untrack(() => {
|
|
1077
|
+
if (first) {
|
|
1078
|
+
first = false;
|
|
1079
|
+
if (inner) {
|
|
1080
|
+
pushHydrationNodes(inner);
|
|
1081
|
+
try {
|
|
1082
|
+
attachHydrated(parent, value);
|
|
1083
|
+
} finally {
|
|
1084
|
+
popHydrationNodes();
|
|
1085
|
+
}
|
|
1086
|
+
} else {
|
|
1087
|
+
mountBefore(end, value);
|
|
1088
|
+
}
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
const between = [];
|
|
1092
|
+
for (let n = start.nextSibling;n && n !== end; n = n.nextSibling) {
|
|
1093
|
+
between.push(n);
|
|
1094
|
+
}
|
|
1095
|
+
const primitive = value === null || value === undefined || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
1096
|
+
if (primitive && between.length === 1 && between[0] instanceof Text) {
|
|
1097
|
+
between[0].data = value === null || value === undefined || value === false ? "" : String(value);
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
for (const n of between)
|
|
1101
|
+
n.remove();
|
|
1102
|
+
mountBefore(end, value);
|
|
1103
|
+
});
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
function mountBefore(marker, value) {
|
|
1107
|
+
if (value === null || value === undefined || value === false)
|
|
1108
|
+
return;
|
|
1109
|
+
if (typeof value === "function") {
|
|
1110
|
+
pushHydrationNodes([]);
|
|
1111
|
+
try {
|
|
1112
|
+
mountBefore(marker, value());
|
|
1113
|
+
} finally {
|
|
1114
|
+
popHydrationNodes();
|
|
1115
|
+
}
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
if (Array.isArray(value)) {
|
|
1119
|
+
for (const item of value)
|
|
1120
|
+
mountBefore(marker, item);
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1123
|
+
marker.before(value instanceof Node ? value : document.createTextNode(String(value)));
|
|
1124
|
+
}
|
|
1125
|
+
function attachHydrated(parent, value) {
|
|
1126
|
+
if (typeof value === "function") {
|
|
1127
|
+
attachHydrated(parent, value());
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
if (Array.isArray(value)) {
|
|
1131
|
+
for (const item of value)
|
|
1132
|
+
attachHydrated(parent, item);
|
|
1133
|
+
return;
|
|
1134
|
+
}
|
|
1135
|
+
if (value instanceof Node) {
|
|
1136
|
+
if (parent.childNodes.length > 0 || value.parentNode)
|
|
1137
|
+
return;
|
|
1138
|
+
parent.appendChild(value);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
function applyDirective(node, directive) {
|
|
1142
|
+
const [fn, params] = Array.isArray(directive) ? directive : [directive, undefined];
|
|
1143
|
+
const cleanup = fn(node, params);
|
|
1144
|
+
if (typeof cleanup === "function") {
|
|
1145
|
+
createEffect(() => () => cleanup());
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
var clientContextStore = new Map;
|
|
1149
|
+
var storeProvider = null;
|
|
1150
|
+
function __setStoreProvider(fn) {
|
|
1151
|
+
storeProvider = fn;
|
|
1152
|
+
}
|
|
1153
|
+
function getStore() {
|
|
1154
|
+
return storeProvider?.() ?? clientContextStore;
|
|
1155
|
+
}
|
|
1156
|
+
function createContext() {
|
|
1157
|
+
return Symbol();
|
|
1158
|
+
}
|
|
1159
|
+
function setContext(key, value) {
|
|
1160
|
+
getStore().set(key, value);
|
|
1161
|
+
}
|
|
1162
|
+
function getContext(key) {
|
|
1163
|
+
return getStore().get(key);
|
|
1164
|
+
}
|
|
1165
|
+
var _hydrationStack = [];
|
|
1166
|
+
function pushHydrationNodes(nodes) {
|
|
1167
|
+
_hydrationStack.push(nodes);
|
|
1168
|
+
}
|
|
1169
|
+
function popHydrationNodes() {
|
|
1170
|
+
_hydrationStack.pop();
|
|
1171
|
+
}
|
|
1172
|
+
function getHydrationNodes() {
|
|
1173
|
+
return _hydrationStack[_hydrationStack.length - 1] ?? [];
|
|
1174
|
+
}
|
|
1175
|
+
export {
|
|
1176
|
+
Boundary,
|
|
1177
|
+
ReactiveMap,
|
|
1178
|
+
ReactiveSet,
|
|
1179
|
+
SIGIL_SAFE,
|
|
1180
|
+
SafeHtml,
|
|
1181
|
+
__asyncBoundary,
|
|
1182
|
+
__setStoreProvider,
|
|
1183
|
+
applyDirective,
|
|
1184
|
+
batch,
|
|
1185
|
+
claim,
|
|
1186
|
+
claimComment,
|
|
1187
|
+
claimText,
|
|
1188
|
+
createContext,
|
|
1189
|
+
createEffect,
|
|
1190
|
+
createEffectPre,
|
|
1191
|
+
createInspectEffect,
|
|
1192
|
+
createMemo,
|
|
1193
|
+
createProfilerEffect,
|
|
1194
|
+
createRawSignal,
|
|
1195
|
+
createResource,
|
|
1196
|
+
createRoot,
|
|
1197
|
+
createSignal,
|
|
1198
|
+
cssName,
|
|
1199
|
+
cssValue,
|
|
1200
|
+
easeInCubic,
|
|
1201
|
+
easeInOutCubic,
|
|
1202
|
+
easeInOutQuad,
|
|
1203
|
+
easeInOutQuart,
|
|
1204
|
+
easeInOutQuint,
|
|
1205
|
+
easeInOutSine,
|
|
1206
|
+
easeInQuad,
|
|
1207
|
+
easeInQuart,
|
|
1208
|
+
easeInQuint,
|
|
1209
|
+
easeInSine,
|
|
1210
|
+
easeOutCubic,
|
|
1211
|
+
easeOutQuad,
|
|
1212
|
+
easeOutQuart,
|
|
1213
|
+
easeOutQuint,
|
|
1214
|
+
easeOutSine,
|
|
1215
|
+
flushDeferredEffects,
|
|
1216
|
+
getContext,
|
|
1217
|
+
getHydrationNodes,
|
|
1218
|
+
hydrateKeyedList,
|
|
1219
|
+
hydrateSlot,
|
|
1220
|
+
insert,
|
|
1221
|
+
isClaimed,
|
|
1222
|
+
linear,
|
|
1223
|
+
liveSlot,
|
|
1224
|
+
mountTransition,
|
|
1225
|
+
popHydrationNodes,
|
|
1226
|
+
probeStatic,
|
|
1227
|
+
pushHydrationNodes,
|
|
1228
|
+
readStore,
|
|
1229
|
+
reconcile,
|
|
1230
|
+
removeAnimated,
|
|
1231
|
+
setContext,
|
|
1232
|
+
setProp,
|
|
1233
|
+
setStyleProp,
|
|
1234
|
+
skipStatic,
|
|
1235
|
+
snapshot,
|
|
1236
|
+
spread,
|
|
1237
|
+
tick,
|
|
1238
|
+
tracking,
|
|
1239
|
+
untrack,
|
|
1240
|
+
withEffectScope
|
|
1241
|
+
};
|