@solidjs/web 2.0.0-rc.8 → 2.0.0-rc.9

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.
Files changed (36) hide show
  1. package/dist/server.dev.js +626 -125
  2. package/dist/server.js +433 -95
  3. package/dist/server.observe.js +3980 -0
  4. package/dist/web.dev.js +208 -60
  5. package/dist/web.js +175 -58
  6. package/dist/web.observe.js +175 -58
  7. package/frames/dist/client.dev.js +103 -4
  8. package/frames/dist/client.js +5 -2
  9. package/frames/dist/client.observe.js +2123 -0
  10. package/frames/dist/server.dev.js +521 -79
  11. package/frames/dist/server.js +352 -52
  12. package/frames/dist/server.observe.js +4946 -0
  13. package/frames/package.json +12 -0
  14. package/package.json +87 -3
  15. package/server-functions/dist/client.dev.js +1102 -0
  16. package/server-functions/dist/client.js +74 -69
  17. package/server-functions/dist/client.observe.js +1102 -0
  18. package/server-functions/dist/server.dev.js +402 -31
  19. package/server-functions/dist/server.js +339 -30
  20. package/server-functions/dist/server.observe.js +2726 -0
  21. package/server-functions/package.json +12 -0
  22. package/types/client.d.ts +22 -1
  23. package/types/diagnostics.d.ts +24 -0
  24. package/types/frames/frame-transport.d.ts +1 -1
  25. package/types/index.d.ts +25 -15
  26. package/types/index.server.d.ts +35 -8
  27. package/types/jsx.d.ts +15 -4
  28. package/types/observe.d.ts +294 -0
  29. package/types/response.d.ts +18 -0
  30. package/types/server-functions/client.d.ts +32 -22
  31. package/types/server-functions/server.d.ts +28 -37
  32. package/types/server-functions/shared.d.ts +39 -9
  33. package/types/server-mock.d.ts +26 -4
  34. package/types/server-observe.d.ts +39 -0
  35. package/types/server.d.ts +104 -5
  36. package/types/trace.d.ts +79 -0
@@ -0,0 +1,2123 @@
1
+ import * as core from 'solid-js';
2
+ import { getOwner, onCleanup, createMemo, runWithOwner, createSignal, createRenderEffect, createLoadingBoundary, createOwner, sharedConfig } from 'solid-js';
3
+ import { delegateEvents, insert } from '@solidjs/web';
4
+ import { frameAddress, SINGLE_FLIGHT_HEADER, deserializeStream, getServerFunctionsCodec, createChunk, getFlightDataConsumer, ERROR_HEADER, REVALIDATE_HEADER, ChunkReader, configureServerFunctionsClient } from '@solidjs/web/server-functions/client';
5
+
6
+ const ELEMENT_NODE = 1;
7
+ const TEXT_NODE = 3;
8
+ const COMMENT_NODE = 8;
9
+ const CLAIM_SEAM = Symbol.for("solid.element-claims");
10
+ const CLAIMED_ELEMENTS = "a[href], form[action]";
11
+ function claimHandlers() {
12
+ const handlers = globalThis[CLAIM_SEAM];
13
+ return handlers !== undefined && handlers.length !== 0 ? handlers : undefined;
14
+ }
15
+ function claimNode(handlers, el) {
16
+ for (let i = 0; i < handlers.length; i++) handlers[i](el);
17
+ }
18
+ const claimedAttr = name => name === "href" || name === "action";
19
+ const BOUND_SEAM = Symbol.for("solid.bnd");
20
+ const boundSeam = globalThis[BOUND_SEAM] || (globalThis[BOUND_SEAM] = {});
21
+ const BND_ATTR = "_bnd";
22
+ const BND_SELECTOR = "[_bnd]";
23
+ function bndMap(el) {
24
+ const s = el.getAttribute(BND_ATTR);
25
+ if (!s) return undefined;
26
+ const map = {};
27
+ for (const entry of s.split(",")) {
28
+ const eq = entry.indexOf("=");
29
+ if (eq < 1) continue;
30
+ const pos = entry.slice(0, eq);
31
+ const prop = decodeURIComponent(entry.slice(eq + 1));
32
+ const prev = map[pos];
33
+ if (prev === undefined) map[pos] = prop;else if (Array.isArray(prev)) prev.push(prop);else map[pos] = [prev, prop];
34
+ }
35
+ return map;
36
+ }
37
+ boundSeam.resolve = (el, type) => {
38
+ const frame = el._$bndFrame;
39
+ if (!frame) return undefined;
40
+ const map = bndMap(el);
41
+ const prop = map && map[type];
42
+ if (typeof prop !== "string") return undefined;
43
+ return claimFn(frame, type, prop);
44
+ };
45
+ function claimFn(frame, pos, prop) {
46
+ const fn = frame.clientProp(prop);
47
+ if (typeof fn === "function") return fn;
48
+ return undefined;
49
+ }
50
+ function sweepBound(root, frame, delegate, scope) {
51
+ const isElement = root.nodeType === ELEMENT_NODE;
52
+ if (!isElement && root.nodeType !== 11 ) return;
53
+ let els;
54
+ if (isElement && root.hasAttribute(BND_ATTR)) (els = []).push(root);
55
+ const found = root.querySelectorAll(BND_SELECTOR);
56
+ if (found.length) {
57
+ els || (els = []);
58
+ for (let i = 0; i < found.length; i++) els.push(found[i]);
59
+ }
60
+ if (!els) return;
61
+ const run = () => {
62
+ let types;
63
+ for (const el of els) {
64
+ el._$bndFrame = frame;
65
+ const map = bndMap(el);
66
+ if (!map) continue;
67
+ for (const pos in map) {
68
+ if (pos === "ref") fireRefs(frame, el, map.ref);else (types || (types = [])).push(pos);
69
+ }
70
+ }
71
+ if (types && delegate) delegate(types);
72
+ };
73
+ scope ? scope(run) : run();
74
+ }
75
+ function fireRefs(frame, el, prop) {
76
+ const fired = el._$bndFired || (el._$bndFired = new Set());
77
+ for (const p of Array.isArray(prop) ? prop : [prop]) {
78
+ if (fired.has(p)) continue;
79
+ fired.add(p);
80
+ const fn = claimFn(frame, "ref", p);
81
+ if (fn) fn(el);
82
+ }
83
+ }
84
+ function claimTree(handlers, root) {
85
+ const isElement = root.nodeType === ELEMENT_NODE;
86
+ if (!isElement && root.nodeType !== 11 ) return;
87
+ if (isElement && root.matches(CLAIMED_ELEMENTS)) claimNode(handlers, root);
88
+ const found = root.querySelectorAll(CLAIMED_ELEMENTS);
89
+ for (let i = 0; i < found.length; i++) claimNode(handlers, found[i]);
90
+ }
91
+ const placeholderId = name => `pl-${name}`;
92
+ const SLOT_START = /^slot:(.+):start$/;
93
+ const SLOT_END = /^slot:(.+):end$/;
94
+ const slotEnd = id => `slot:${id}:end`;
95
+ function chunkToRecords(chunk) {
96
+ switch (chunk.type) {
97
+ case "start":
98
+ case "data":
99
+ return {};
100
+ case "html":
101
+ return {
102
+ "": {
103
+ kind: "html",
104
+ value: chunk.html
105
+ }
106
+ };
107
+ case "fragment":
108
+ return {
109
+ [`seg:${chunk.key}`]: {
110
+ kind: "html",
111
+ value: chunk.html
112
+ }
113
+ };
114
+ case "reveal":
115
+ {
116
+ const records = {};
117
+ const gate = chunk.fallback ? "fallback" : "reveal";
118
+ for (const key of chunk.keys) records[`seg:${key}:${gate}`] = true;
119
+ return records;
120
+ }
121
+ case "assets":
122
+ return {
123
+ [`seg:${chunk.key}:assets`]: chunk
124
+ };
125
+ case "slot":
126
+ return {
127
+ [`slot:${chunk.key}`]: {
128
+ kind: "slot",
129
+ args: chunk.args
130
+ }
131
+ };
132
+ case "hole":
133
+ return {
134
+ [`hole:${chunk.key}`]: {
135
+ kind: "html",
136
+ value: chunk.html
137
+ }
138
+ };
139
+ case "attr":
140
+ return {
141
+ [`attr:${chunk.key}`]: {
142
+ kind: "attrs",
143
+ value: chunk.attrs,
144
+ removed: chunk.removed
145
+ }
146
+ };
147
+ case "complete":
148
+ return {
149
+ ":complete": true
150
+ };
151
+ case "error":
152
+ if (!chunk.key) return {
153
+ ":error": chunk.error
154
+ };
155
+ return {
156
+ [`${/^lha?:/.test(chunk.key) ? "hole" : "seg"}:${chunk.key}:error`]: chunk.error
157
+ };
158
+ default:
159
+ return {};
160
+ }
161
+ }
162
+ function createFrameHost(options = {}) {
163
+ const frames = new Map();
164
+ const stores = new Map();
165
+ const storeFor = id => {
166
+ let store = stores.get(id);
167
+ if (!store) stores.set(id, store = {
168
+ version: undefined,
169
+ records: {}
170
+ });
171
+ return store;
172
+ };
173
+ const write = (store, version, records) => {
174
+ if (store.version !== undefined && version < store.version) return false;
175
+ if (store.version === undefined || version > store.version) {
176
+ store.version = version;
177
+ clearStreamRecords(store.records);
178
+ }
179
+ const assets = records["seg::assets"];
180
+ const previous = assets && store.records["seg::assets"];
181
+ if (!previous || previous === assets) {
182
+ Object.assign(store.records, records);
183
+ } else {
184
+ for (const name in assets) {
185
+ const values = assets[name];
186
+ if (Array.isArray(values)) {
187
+ previous[name] ? previous[name].push(...values) : previous[name] = values;
188
+ }
189
+ }
190
+ }
191
+ return true;
192
+ };
193
+ return {
194
+ delegate: options.delegate,
195
+ register(id, frame) {
196
+ let set = frames.get(id);
197
+ if (!set) frames.set(id, set = new Set());
198
+ set.add(frame);
199
+ const store = stores.get(id);
200
+ if (store && store.version !== undefined) {
201
+ frame.apply({
202
+ version: store.version,
203
+ r: store.records
204
+ });
205
+ frame.rebase && frame.rebase();
206
+ }
207
+ },
208
+ unregister(id, frame) {
209
+ const set = frames.get(id);
210
+ if (set && frame) set.delete(frame);
211
+ if (!set || !frame || !set.size) {
212
+ frames.delete(id);
213
+ if (frame && frame.contentHTML) {
214
+ const store = storeFor(id);
215
+ if (!store.records[""]) {
216
+ const html = frame.contentHTML();
217
+ if (html != null) {
218
+ store.records[""] = {
219
+ kind: "html",
220
+ value: html
221
+ };
222
+ if (store.version === undefined) store.version = 0;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ if (!frame) stores.delete(id);
228
+ },
229
+ apply(chunk) {
230
+ if (chunk.type === "data") {
231
+ options.applyData && options.applyData(chunk);
232
+ return;
233
+ }
234
+ const records = chunkToRecords(chunk);
235
+ if (!write(storeFor(chunk.id), chunk.version, records)) return;
236
+ const set = frames.get(chunk.id);
237
+ if (set) {
238
+ for (const frame of set) frame.apply({
239
+ version: chunk.version,
240
+ r: records
241
+ });
242
+ }
243
+ },
244
+ get(id) {
245
+ const set = frames.get(id);
246
+ return set && set.values().next().value;
247
+ },
248
+ serialize(value) {
249
+ if (!options.serialize) throw new Error("host has no serializer");
250
+ return options.serialize(value);
251
+ },
252
+ resolve(ref, frameId) {
253
+ return options.resolve ? options.resolve(ref, frameId) : undefined;
254
+ },
255
+ revive: options.revive,
256
+ isContainer: options.isContainer,
257
+ prepareData: options.prepareData
258
+ };
259
+ }
260
+ const FRAME_APPLIED_EVENT = "frame:applied";
261
+ class FrameImpl {
262
+ #element;
263
+ #start;
264
+ #end;
265
+ #options;
266
+ #version;
267
+ #store = Object.create(null);
268
+ #appliedRootValue;
269
+ #hasContent = false;
270
+ #errorNotified = false;
271
+ #revealed = new Set();
272
+ #fallbackShown = new Set();
273
+ #appliedHoles = new Map();
274
+ #slots;
275
+ #mountedSlots = new Set();
276
+ #slotCleanups = new Map();
277
+ #slotArgs = new Map();
278
+ #slotUpdaters = new Map();
279
+ #slotRegions = new Map();
280
+ #slotResolvedRefs = new Map();
281
+ #slotNodes = new Map();
282
+ #processedAssets = new WeakSet();
283
+ #recordRefresh = null;
284
+ #disposed = false;
285
+ #styleFlush = () => {
286
+ if (!this.#disposed) this.#flush();
287
+ };
288
+ #claimTree = (node, direct) => {
289
+ if (!direct && node.nodeType !== TEXT_NODE && node.nodeType !== COMMENT_NODE) {
290
+ const o = this.#options;
291
+ sweepBound(node, this, o.delegate || o.host && o.host.delegate, o.ownerScope);
292
+ }
293
+ const handlers = claimHandlers();
294
+ if (!handlers) return;
295
+ this.#scoped(() => direct ? claimNode(handlers, node) : claimTree(handlers, node));
296
+ };
297
+ clientProp(name) {
298
+ const props = this.#options.props;
299
+ return props ? props[name] : undefined;
300
+ }
301
+ #scoped(fn) {
302
+ const scope = this.#options.ownerScope;
303
+ return scope ? scope(fn) : fn();
304
+ }
305
+ constructor(element, start, end, options = {}) {
306
+ this.#element = element;
307
+ this.#start = start;
308
+ this.#end = end;
309
+ this.#options = options;
310
+ this.#slots = options.slots;
311
+ if (options.adopt) {
312
+ this.#hasContent = true;
313
+ this.#claimContent();
314
+ }
315
+ if (options.host && options.id !== undefined) {
316
+ options.host.register(options.id, this);
317
+ }
318
+ if (options.adopt && this.#version === undefined) this.#syncSlots();
319
+ }
320
+ #parent() {
321
+ return this.#element ?? this.#start.parentNode;
322
+ }
323
+ #applied(version, reason) {
324
+ this.#options.onApply?.({
325
+ version,
326
+ reason
327
+ });
328
+ const parent = this.#parent();
329
+ const Ev = parent && (parent.ownerDocument || parent).defaultView?.CustomEvent;
330
+ if (Ev) {
331
+ parent.dispatchEvent(new Ev(FRAME_APPLIED_EVENT, {
332
+ bubbles: true,
333
+ detail: {
334
+ id: this.#options.id,
335
+ version,
336
+ reason
337
+ }
338
+ }));
339
+ }
340
+ }
341
+ #firstContent() {
342
+ return this.#start ? this.#start.nextSibling : this.#parent().firstChild;
343
+ }
344
+ get version() {
345
+ return this.#version;
346
+ }
347
+ get store() {
348
+ return this.#store;
349
+ }
350
+ isRevealed(segment) {
351
+ return this.#revealed.has(segment);
352
+ }
353
+ get error() {
354
+ return this.#store[":error"];
355
+ }
356
+ apply(write) {
357
+ if (this.#disposed) return;
358
+ const v = write.version;
359
+ if (this.#version === undefined) {
360
+ this.#version = v;
361
+ } else if (v < this.#version) {
362
+ return;
363
+ } else if (v > this.#version) {
364
+ this.#version = v;
365
+ this.#resetStreamState();
366
+ }
367
+ for (const key in write.r) {
368
+ const incoming = write.r[key];
369
+ if (incoming && incoming.kind === "slot" && key.charCodeAt(0) === 115 && key.startsWith("slot:")) {
370
+ const existing = this.#store[key];
371
+ if (existing && existing.kind === "slot" && argsEquivalent(existing.args, incoming.args)) {
372
+ continue;
373
+ }
374
+ }
375
+ this.#store[key] = incoming;
376
+ }
377
+ this.#flush();
378
+ }
379
+ #resetStreamState(root) {
380
+ this.#revealed.clear();
381
+ this.#fallbackShown.clear();
382
+ this.#appliedHoles.clear();
383
+ this.#processedAssets = new WeakSet();
384
+ this.#errorNotified = false;
385
+ clearStreamRecords(this.#store, root);
386
+ }
387
+ #flush() {
388
+ if (this.#disposed) return;
389
+ const version = this.#version;
390
+ const root = this.#store[""];
391
+ if (root && root.kind === "html" && root.value !== this.#appliedRootValue) {
392
+ const reason = this.#hasContent ? "morph" : "materialize";
393
+ this.#applyRoot(root.value);
394
+ this.#appliedRootValue = root.value;
395
+ this.#applied(version, reason);
396
+ }
397
+ if (this.#store[":error"] && !this.#errorNotified) {
398
+ this.#errorNotified = true;
399
+ this.#applied(version, "error");
400
+ }
401
+ let progressed = true;
402
+ while (progressed) {
403
+ progressed = false;
404
+ for (const key in this.#store) {
405
+ const name = segmentName(key);
406
+ if (name === null || this.#revealed.has(name)) continue;
407
+ if (this.#segmentReady(name)) {
408
+ this.#revealSegment(name);
409
+ this.#applied(version, "reveal");
410
+ progressed = true;
411
+ }
412
+ }
413
+ for (const key in this.#store) {
414
+ const m = /^seg:([^:]+):fallback$/.exec(key);
415
+ if (!m) continue;
416
+ const name = m[1];
417
+ if (this.#revealed.has(name) || this.#fallbackShown.has(name)) continue;
418
+ if (this.#showFallback(name)) {
419
+ this.#fallbackShown.add(name);
420
+ this.#applied(version, "reveal");
421
+ progressed = true;
422
+ }
423
+ }
424
+ }
425
+ for (const key in this.#store) {
426
+ const record = this.#store[key];
427
+ if (!record || this.#appliedHoles.get(key) === record) continue;
428
+ if (key.startsWith("hole:")) {
429
+ if (key.endsWith(":error")) {
430
+ this.#appliedHoles.set(key, record);
431
+ } else if (this.#applyHole(key.slice(5), record.value)) {
432
+ this.#appliedHoles.set(key, record);
433
+ this.#applied(version, "morph");
434
+ }
435
+ } else if (key.startsWith("attr:")) {
436
+ if (this.#applyAttrs(key.slice(5), record.value, record.removed)) {
437
+ this.#appliedHoles.set(key, record);
438
+ this.#applied(version, "morph");
439
+ }
440
+ }
441
+ }
442
+ for (const key in this.#store) {
443
+ const record = this.#store[key];
444
+ if (!key.endsWith(":assets") || !record || this.#processedAssets.has(record)) {
445
+ continue;
446
+ }
447
+ this.#processedAssets.add(record);
448
+ if (record.modules) {
449
+ for (const href of record.modules) ensureModulePreload(href);
450
+ }
451
+ if (record.preloads) {
452
+ for (const entry of record.preloads) ensurePreload(entry);
453
+ }
454
+ }
455
+ this.#syncSlots();
456
+ }
457
+ #resolveSlot(prop) {
458
+ return this.#slots?.[prop] ?? this.#options.resolveSlot?.(prop);
459
+ }
460
+ #resolveSlotRecord(occurrence) {
461
+ const record = this.#store[`slot:${occurrence}`];
462
+ if (record !== undefined) return record;
463
+ return this.#options.resolveSlotRecord?.(occurrence);
464
+ }
465
+ #removeSlotRecord(occurrence) {
466
+ const key = `slot:${occurrence}`;
467
+ if (key in this.#store) {
468
+ if (!this.#mountedSlots.has(occurrence)) delete this.#store[key];
469
+ } else this.#options.removeSlotRecord?.(occurrence);
470
+ }
471
+ #syncSlots(root) {
472
+ if (!this.#slots && !this.#options.resolveSlot) return;
473
+ const found = new Map();
474
+ if (root) collectSlots(root.firstChild, null, found);else this.#collectSlots(found);
475
+ for (const [occurrence, start] of found) {
476
+ const callback = this.#resolveSlot(propOf(occurrence));
477
+ if (!callback) continue;
478
+ const record = this.#resolveSlotRecord(occurrence);
479
+ if (record && record.kind === "slot" && this.#refsUnresolved(record.args)) continue;
480
+ const prev = this.#slotNodes.get(occurrence);
481
+ const prevFirst = Array.isArray(prev) ? prev[0] : prev;
482
+ const zombie = this.#mountedSlots.has(occurrence) && prevFirst && !prevFirst.parentNode;
483
+ if (zombie) {
484
+ this.#mountedSlots.delete(occurrence);
485
+ this.#runSlotCleanups(occurrence);
486
+ }
487
+ if (!this.#mountedSlots.has(occurrence)) {
488
+ if (record === undefined && !root && this.#options.adopt && this.#options.recordsPending?.()) {
489
+ this.#recordRefresh ??= setTimeout(() => {
490
+ this.#recordRefresh = null;
491
+ if (this.#disposed) return;
492
+ this.#options.drainRecords?.();
493
+ this.#syncSlots();
494
+ });
495
+ continue;
496
+ }
497
+ if (this.#options.adopt) this.#discoverRegions(occurrence, start);
498
+ const nodes = this.#invokeSlot(occurrence, callback, record, start, this.#options.adopt);
499
+ if (nodes) this.#replaceRange(occurrence, start, nodes);
500
+ this.#slotNodes.set(occurrence, nodes);
501
+ this.#mountedSlots.add(occurrence);
502
+ if (!this.#options.adopt || nodes) this.#discoverRegions(occurrence, start);
503
+ this.#bindRegions(occurrence);
504
+ } else if (record !== this.#slotArgs.get(occurrence)) {
505
+ if (this.#refArgsUnchanged(occurrence, record)) {
506
+ this.#slotArgs.set(occurrence, record);
507
+ this.#reconcileRegions(occurrence, record);
508
+ continue;
509
+ }
510
+ const update = this.#slotUpdaters.get(occurrence);
511
+ if (update) {
512
+ const props = this.#resolveArgs(occurrence, record.args);
513
+ this.#slotArgs.set(occurrence, record);
514
+ update(props);
515
+ this.#bindRegions(occurrence);
516
+ continue;
517
+ }
518
+ const nodes = this.#invokeSlot(occurrence, callback, record, start);
519
+ if (nodes) this.#replaceRange(occurrence, start, nodes);
520
+ this.#slotNodes.set(occurrence, nodes);
521
+ this.#bindRegions(occurrence);
522
+ }
523
+ }
524
+ if (!root) {
525
+ for (const occurrence of [...this.#mountedSlots]) {
526
+ if (!found.has(occurrence)) this.#unmountSlot(occurrence);
527
+ }
528
+ }
529
+ }
530
+ #invokeSlot(occurrence, callback, record, start, adopted) {
531
+ this.#slotUpdaters.delete(occurrence);
532
+ const cleanups = this.#slotCleanups.get(occurrence) ?? [];
533
+ let existing = [];
534
+ let end = null;
535
+ if (start) end = eachInRange(start, occurrence, n => existing.push(n));
536
+ const ctx = {
537
+ frame: this.#options.claimScope ?? this.#options.id,
538
+ key: occurrence,
539
+ adopted: !!adopted,
540
+ invoked: !!(record && record.kind === "slot"),
541
+ onCleanup: fn => cleanups.push(fn),
542
+ onUpdate: fn => this.#slotUpdaters.set(occurrence, fn),
543
+ existing,
544
+ range: end ? {
545
+ start,
546
+ end
547
+ } : undefined
548
+ };
549
+ const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record.args) : {};
550
+ const content = this.#scoped(() => callback(props, ctx));
551
+ this.#slotArgs.set(occurrence, record);
552
+ if (cleanups.length) this.#slotCleanups.set(occurrence, cleanups);
553
+ if (content == null) return null;
554
+ return Array.isArray(content) ? content : [content];
555
+ }
556
+ #replaceRange(key, start, nodes) {
557
+ const parent = start.parentNode;
558
+ const end = eachInRange(start, key, n => parent.removeChild(n));
559
+ for (const node of nodes) parent.insertBefore(node, end);
560
+ }
561
+ #unmountSlot(key) {
562
+ this.#mountedSlots.delete(key);
563
+ this.#slotNodes.delete(key);
564
+ this.#slotArgs.delete(key);
565
+ this.#slotUpdaters.delete(key);
566
+ this.#slotResolvedRefs.delete(key);
567
+ this.#removeSlotRecord(key);
568
+ this.#runSlotCleanups(key);
569
+ const regions = this.#slotRegions.get(key);
570
+ if (regions) {
571
+ disposeRegions(regions);
572
+ this.#slotRegions.delete(key);
573
+ }
574
+ }
575
+ #runSlotCleanups(key) {
576
+ const cleanups = this.#slotCleanups.get(key);
577
+ if (!cleanups) return;
578
+ this.#slotCleanups.delete(key);
579
+ for (const fn of cleanups) fn();
580
+ }
581
+ #refsUnresolved(args) {
582
+ const {
583
+ host,
584
+ id
585
+ } = this.#options;
586
+ if (host) for (const key in args) {
587
+ if (isDataRef(args[key]) && host.resolve(args[key], id) === undefined) return true;
588
+ }
589
+ return false;
590
+ }
591
+ #regionsFor(slotKey) {
592
+ let regions = this.#slotRegions.get(slotKey);
593
+ if (!regions) this.#slotRegions.set(slotKey, regions = new Map());
594
+ return regions;
595
+ }
596
+ #resolveArgs(slotKey, args) {
597
+ const host = this.#options.host;
598
+ const regions = this.#regionsFor(slotKey);
599
+ const props = {};
600
+ for (const key in args) {
601
+ const value = args[key];
602
+ if (isDataRef(value)) {
603
+ const resolved = host ? host.resolve(value, this.#options.id) : undefined;
604
+ let cache = this.#slotResolvedRefs.get(slotKey);
605
+ if (!cache) this.#slotResolvedRefs.set(slotKey, cache = {});
606
+ cache[key] = resolved;
607
+ props[key] = resolved;
608
+ } else if (isFrameRef(value)) {
609
+ let entry = regions.get(key);
610
+ if (!entry) {
611
+ const element = makeFrameElement(value.$frame);
612
+ entry = {
613
+ childId: value.$frame,
614
+ element,
615
+ frame: undefined
616
+ };
617
+ regions.set(key, entry);
618
+ } else if (entry.childId !== value.$frame) {
619
+ renameRegion(entry, value.$frame);
620
+ }
621
+ props[key] = entry.element;
622
+ } else {
623
+ props[key] = host && host.revive ? host.revive(value) : value;
624
+ }
625
+ }
626
+ return props;
627
+ }
628
+ #discoverRegions(slotKey, start) {
629
+ if (!start) return;
630
+ const regions = this.#regionsFor(slotKey);
631
+ eachInRange(start, slotKey, n => collectRegionElements(n, regions));
632
+ }
633
+ #refArgsUnchanged(occurrence, record) {
634
+ const old = this.#slotArgs.get(occurrence);
635
+ if (!record || record.kind !== "slot") return false;
636
+ if (old && old.kind !== "slot") return false;
637
+ const a = old && old.args || {};
638
+ const b = record.args || {};
639
+ const ka = Object.keys(a);
640
+ const kb = Object.keys(b);
641
+ if (kb.length !== ka.length) return false;
642
+ const cache = this.#slotResolvedRefs.get(occurrence);
643
+ for (const key of ka) {
644
+ const va = a[key];
645
+ const vb = b[key];
646
+ if (va === vb) continue;
647
+ if (isFrameRef(va) && isFrameRef(vb)) continue;
648
+ if (isDataRef(va) && isDataRef(vb) && cache && key in cache) {
649
+ const host = this.#options.host;
650
+ const next = host ? host.resolve(vb, this.#options.id) : undefined;
651
+ if (host && host.isContainer && (host.isContainer(next) || host.isContainer(cache[key]))) {
652
+ if (next === cache[key]) continue;
653
+ return false;
654
+ }
655
+ if (isAsyncLike(next) || isAsyncLike(cache[key])) return false;
656
+ try {
657
+ if (JSON.stringify(next) === JSON.stringify(cache[key])) continue;
658
+ } catch (e) {
659
+ return false;
660
+ }
661
+ }
662
+ return false;
663
+ }
664
+ return true;
665
+ }
666
+ #reconcileRegions(occurrence, record) {
667
+ const args = record && record.args;
668
+ if (!args) return;
669
+ const regions = this.#slotRegions.get(occurrence);
670
+ if (!regions) return;
671
+ for (const key in args) {
672
+ const value = args[key];
673
+ if (!isFrameRef(value)) continue;
674
+ const entry = regions.get(key);
675
+ if (entry && entry.childId !== value.$frame) renameRegion(entry, value.$frame);
676
+ }
677
+ }
678
+ #bindRegions(slotKey) {
679
+ const regions = this.#slotRegions.get(slotKey);
680
+ if (!regions) return;
681
+ for (const entry of regions.values()) {
682
+ if (!entry.frame) {
683
+ entry.frame = new FrameImpl(entry.element, null, null, {
684
+ id: entry.childId,
685
+ host: this.#options.host,
686
+ adopt: entry.adopt,
687
+ claimScope: this.#options.claimScope ?? this.#options.id,
688
+ ownerScope: this.#options.ownerScope,
689
+ resolveSlot: prop => this.#resolveSlot(prop),
690
+ resolveSlotRecord: occurrence => this.#resolveSlotRecord(occurrence),
691
+ removeSlotRecord: occurrence => this.#removeSlotRecord(occurrence)
692
+ });
693
+ }
694
+ }
695
+ }
696
+ #collectSlots(found) {
697
+ collectSlots(this.#firstContent(), this.#end, found);
698
+ }
699
+ #findPlaceholder(name) {
700
+ return findPlaceholder(this.#firstContent(), this.#end, placeholderId(name));
701
+ }
702
+ contentHTML() {
703
+ if (this.#disposed || !this.#element || !this.#hasContent) return null;
704
+ return this.#element.innerHTML;
705
+ }
706
+ rebind(id) {
707
+ if (this.#disposed || id === this.#options.id) return;
708
+ const {
709
+ host,
710
+ id: oldId
711
+ } = this.#options;
712
+ if (host && oldId !== undefined) host.unregister(oldId, this);
713
+ this.#options = {
714
+ ...this.#options,
715
+ id
716
+ };
717
+ if (this.#element && this.#element.nodeType === ELEMENT_NODE) {
718
+ this.#element.setAttribute(FRAME_ID_ATTR, id);
719
+ }
720
+ this.#version = undefined;
721
+ this.#appliedRootValue = undefined;
722
+ this.#resetStreamState(true);
723
+ if (host) host.register(id, this);
724
+ }
725
+ rebase() {
726
+ this.#version = undefined;
727
+ }
728
+ dispose() {
729
+ if (this.#disposed) return;
730
+ const {
731
+ host,
732
+ id
733
+ } = this.#options;
734
+ if (host && id !== undefined) host.unregister(id, this);
735
+ this.#disposed = true;
736
+ if (this.#recordRefresh) {
737
+ clearTimeout(this.#recordRefresh);
738
+ this.#recordRefresh = null;
739
+ }
740
+ for (const key of [...this.#slotCleanups.keys()]) this.#runSlotCleanups(key);
741
+ for (const key of this.#mountedSlots) this.#removeSlotRecord(key);
742
+ for (const regions of this.#slotRegions.values()) disposeRegions(regions);
743
+ this.#slotRegions.clear();
744
+ this.#mountedSlots.clear();
745
+ }
746
+ #applyRoot(html) {
747
+ const fragment = parseFragment(html);
748
+ const parent = this.#parent();
749
+ if (!this.#hasContent) {
750
+ this.#clearContent();
751
+ this.#claimTree(fragment);
752
+ parent.insertBefore(fragment, this.#end);
753
+ this.#hasContent = true;
754
+ } else {
755
+ const claim = this.#claimTree;
756
+ const ranges = new Map();
757
+ this.#collectSlots(ranges);
758
+ const grafts = [];
759
+ reconcileChildren(parent, fragment, this.#start, this.#end, claim, ranges, grafts);
760
+ if (ranges.size) for (const root of grafts) flushGrafts(root, ranges);
761
+ }
762
+ }
763
+ #applyHole(marker, html) {
764
+ if (!this.#hasContent) return false;
765
+ const open = findLiveTarget(this.#firstContent(), this.#end, n => n.nodeType === COMMENT_NODE && n.data === marker);
766
+ if (!open) return false;
767
+ const close = rangeClose(open, "lh:/" + marker.slice(3));
768
+ if (!close) {
769
+ return false;
770
+ }
771
+ reconcileChildren(open.parentNode, parseFragment(html), open, close, this.#claimTree);
772
+ return true;
773
+ }
774
+ #applyAttrs(addr, text, removed) {
775
+ if (!this.#hasContent) return false;
776
+ const el = findLiveTarget(this.#firstContent(), this.#end, n => n.nodeType === ELEMENT_NODE && n.getAttribute("data-lha") === addr);
777
+ if (!el) return false;
778
+ const parsed = parseFragment(`<i${text}></i>`).firstChild;
779
+ if (parsed) {
780
+ for (let i = 0; i < parsed.attributes.length; i++) {
781
+ const {
782
+ name,
783
+ value
784
+ } = parsed.attributes[i];
785
+ if (el.getAttribute(name) !== value) el.setAttribute(name, value);
786
+ }
787
+ }
788
+ if (removed) for (const name of removed) el.removeAttribute(name);
789
+ return true;
790
+ }
791
+ #clearContent() {
792
+ removeUntil(this.#parent(), this.#firstContent(), this.#end);
793
+ }
794
+ #claimContent() {
795
+ let n = this.#firstContent();
796
+ while (n && n !== this.#end) {
797
+ this.#claimTree(n);
798
+ n = n.nextSibling;
799
+ }
800
+ }
801
+ #segmentReady(name) {
802
+ const content = this.#store[`seg:${name}`];
803
+ if (!content || content.kind !== "html") return false;
804
+ if (!this.#store[`seg:${name}:reveal`]) return false;
805
+ const assets = this.#store[`seg:${name}:assets`];
806
+ if (assets && assets.styles) {
807
+ let ready = true;
808
+ for (const entry of assets.styles) ready = ensureStylesheet(entry, this.#styleFlush) && ready;
809
+ if (!ready) return false;
810
+ }
811
+ if (!this.#findPlaceholder(name)) return false;
812
+ return true;
813
+ }
814
+ #revealSegment(name) {
815
+ const tpl = this.#findPlaceholder(name);
816
+ if (!tpl) return;
817
+ const assets = this.#store[`seg:${name}:assets`];
818
+ if (assets && assets.inlineStyles) applyInlineStyles(assets.inlineStyles);
819
+ const content = this.#store[`seg:${name}`];
820
+ const closing = rangeClose(tpl, placeholderId(name));
821
+ const parent = tpl.parentNode;
822
+ removeUntil(parent, tpl.nextSibling, closing);
823
+ if (this.#options.reveal) {
824
+ const fallbackFrag = tpl.content.cloneNode(true);
825
+ this.#claimTree(fallbackFrag);
826
+ this.#options.reveal({
827
+ before: closing,
828
+ fallback: [...fallbackFrag.childNodes],
829
+ content: () => {
830
+ const materialized = this.#materialize(content);
831
+ this.#syncSlots(materialized);
832
+ this.#claimTree(materialized);
833
+ return materialized;
834
+ }
835
+ });
836
+ tpl.remove();
837
+ this.#revealed.add(name);
838
+ return;
839
+ }
840
+ const materialized = this.#materialize(content);
841
+ this.#claimTree(materialized);
842
+ parent.insertBefore(materialized, closing);
843
+ tpl.remove();
844
+ closing && closing.remove();
845
+ this.#revealed.add(name);
846
+ }
847
+ #showFallback(name) {
848
+ const tpl = this.#findPlaceholder(name);
849
+ if (!tpl) return false;
850
+ const closing = rangeClose(tpl, placeholderId(name));
851
+ if (!closing) return false;
852
+ const fallback = tpl.content.cloneNode(true);
853
+ this.#claimTree(fallback);
854
+ closing.parentNode.insertBefore(fallback, closing);
855
+ return true;
856
+ }
857
+ #materialize(record) {
858
+ return record.kind === "html" ? parseFragment(record.value) : parseFragment("");
859
+ }
860
+ }
861
+ function createFrame(boundary, options) {
862
+ return new FrameImpl(boundary, null, null, options);
863
+ }
864
+ const FRAME_TAG = "solid-frame";
865
+ const FRAME_ID_ATTR = "data-fid";
866
+ function createFrameElement(options) {
867
+ const el = makeFrameElement(options.id);
868
+ const frame = new FrameImpl(el, null, null, options);
869
+ return {
870
+ element: el,
871
+ frame,
872
+ dispose() {
873
+ frame.dispose();
874
+ el.remove();
875
+ }
876
+ };
877
+ }
878
+ function makeFrameElement(id) {
879
+ const el = document.createElement(FRAME_TAG);
880
+ el.style.display = "contents";
881
+ if (id !== undefined) el.setAttribute(FRAME_ID_ATTR, id);
882
+ return el;
883
+ }
884
+ function isFrameElement(node) {
885
+ return node.nodeType === ELEMENT_NODE && node.hasAttribute(FRAME_ID_ATTR);
886
+ }
887
+ function segmentName(key) {
888
+ const m = /^seg:([^:]+)$/.exec(key);
889
+ return m ? m[1] : null;
890
+ }
891
+ function isAsyncLike(v) {
892
+ return !!v && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
893
+ }
894
+ function propOf(occurrence) {
895
+ const hash = occurrence.indexOf("#");
896
+ return hash === -1 ? occurrence : occurrence.slice(0, hash);
897
+ }
898
+ function isDataRef(value) {
899
+ return !!value && typeof value.$ref === "string";
900
+ }
901
+ function isFrameRef(value) {
902
+ return !!value && typeof value.$frame === "string";
903
+ }
904
+ function disposeRegions(regions) {
905
+ for (const {
906
+ frame
907
+ } of regions.values()) frame?.dispose();
908
+ }
909
+ function removeUntil(parent, n, stop) {
910
+ while (n && n !== stop) {
911
+ const next = n.nextSibling;
912
+ parent.removeChild(n);
913
+ n = next;
914
+ }
915
+ }
916
+ function parseFragment(html) {
917
+ const template = document.createElement("template");
918
+ template.innerHTML = html;
919
+ return template.content;
920
+ }
921
+ const PRELOAD_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
922
+ function qualifierValue(name, value) {
923
+ if (value == null) return null;
924
+ if (name === "imagesrcset" || name === "imagesizes") return value === "" ? null : value;
925
+ if (name === "as") return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
926
+ if (name !== "crossorigin") return value;
927
+ return value.length === 15 && value.toLowerCase() === "use-credentials" ? "use-credentials" : "anonymous";
928
+ }
929
+ function findHeadElement(selector, attr, value, qualifiers) {
930
+ candidate: for (const node of document.head.querySelectorAll(selector)) {
931
+ if (node.getAttribute(attr) !== value) continue;
932
+ if (!qualifiers) return node;
933
+ for (let i = 0; i < PRELOAD_QUALIFIERS.length; i++) {
934
+ const name = PRELOAD_QUALIFIERS[i];
935
+ if (qualifierValue(name, node.getAttribute(name)) !== qualifierValue(name, qualifiers[name] ?? null)) continue candidate;
936
+ }
937
+ return node;
938
+ }
939
+ return null;
940
+ }
941
+ function ensurePreload(entry) {
942
+ const attrs = entry.attrs;
943
+ const href = entry.href;
944
+ if (findHeadElement('link[rel="preload"]', "href", href || null, attrs)) return;
945
+ const link = document.createElement("link");
946
+ link.rel = "preload";
947
+ for (const name in attrs) link.setAttribute(name, attrs[name]);
948
+ if (href) link.setAttribute("href", href);
949
+ document.head.appendChild(link);
950
+ }
951
+ function ensureStylesheet(entry, onSettle) {
952
+ const href = typeof entry === "string" ? entry : entry.href;
953
+ let link = findHeadElement('link[rel="stylesheet"]', "href", href);
954
+ if (!link) {
955
+ link = document.createElement("link");
956
+ link.rel = "stylesheet";
957
+ if (typeof entry !== "string" && entry.attrs) {
958
+ for (const name in entry.attrs) link.setAttribute(name, entry.attrs[name]);
959
+ }
960
+ link.href = href;
961
+ const waiters = new Set();
962
+ link._$frWaiters = waiters;
963
+ const settle = () => {
964
+ link._$frWaiters = null;
965
+ for (const fn of waiters) fn();
966
+ };
967
+ link.addEventListener("load", settle);
968
+ link.addEventListener("error", settle);
969
+ document.head.appendChild(link);
970
+ }
971
+ const waiters = link._$frWaiters;
972
+ if (waiters == null) return true;
973
+ waiters.add(onSettle);
974
+ return false;
975
+ }
976
+ function ensureModulePreload(href) {
977
+ if (findHeadElement('link[rel="modulepreload"]', "href", href)) return;
978
+ const link = document.createElement("link");
979
+ link.rel = "modulepreload";
980
+ link.href = href;
981
+ document.head.appendChild(link);
982
+ }
983
+ function applyInlineStyles(inlineStyles) {
984
+ for (const entry of inlineStyles) {
985
+ if (findHeadElement("style[data-asset]", "data-asset", entry.id)) continue;
986
+ const el = document.createElement("style");
987
+ el.setAttribute("data-asset", entry.id);
988
+ if (entry.attrs) {
989
+ for (const name in entry.attrs) el.setAttribute(name, entry.attrs[name]);
990
+ }
991
+ el.textContent = entry.content || "";
992
+ document.head.appendChild(el);
993
+ }
994
+ }
995
+ function isPlaceholderStart(node, id) {
996
+ return node.tagName === "TEMPLATE" && node.id === id;
997
+ }
998
+ function rangeClose(start, id) {
999
+ let n = start.nextSibling;
1000
+ while (n) {
1001
+ if (n.nodeType === COMMENT_NODE && n.data === id) return n;
1002
+ n = n.nextSibling;
1003
+ }
1004
+ return null;
1005
+ }
1006
+ function findLiveTarget(n, end, test) {
1007
+ while (n && n !== end) {
1008
+ if (n.nodeType === ELEMENT_NODE) {
1009
+ const fid = isFrameElement(n) ? n.getAttribute(FRAME_ID_ATTR) : null;
1010
+ if (fid === null || fid.includes(".")) {
1011
+ if (test(n)) return n;
1012
+ const found = findLiveTarget(n.firstChild, null, test);
1013
+ if (found) return found;
1014
+ }
1015
+ } else if (test(n)) return n;
1016
+ n = n.nextSibling;
1017
+ }
1018
+ return null;
1019
+ }
1020
+ function findPlaceholder(n, end, id) {
1021
+ while (n && n !== end) {
1022
+ if (isPlaceholderStart(n, id)) return n;
1023
+ if (n.nodeType === ELEMENT_NODE) {
1024
+ const found = findPlaceholder(n.firstChild, null, id);
1025
+ if (found) return found;
1026
+ }
1027
+ n = n.nextSibling;
1028
+ }
1029
+ return null;
1030
+ }
1031
+ function collectSlots(n, end, out) {
1032
+ while (n && n !== end) {
1033
+ const id = slotStartId(n);
1034
+ if (id !== null) {
1035
+ if (!out.has(id)) out.set(id, n);
1036
+ n = afterRange(n, id);
1037
+ continue;
1038
+ }
1039
+ if (n.nodeType === ELEMENT_NODE && !isFrameElement(n)) collectSlots(n.firstChild, null, out);
1040
+ n = n.nextSibling;
1041
+ }
1042
+ }
1043
+ function collectRegionElements(node, regions) {
1044
+ if (node.nodeType !== ELEMENT_NODE) return;
1045
+ if (isFrameElement(node)) {
1046
+ const childId = node.getAttribute(FRAME_ID_ATTR);
1047
+ if (childId && childId.includes(".")) {
1048
+ const argKey = childId.slice(childId.lastIndexOf(".") + 1);
1049
+ if (!regions.has(argKey)) {
1050
+ regions.set(argKey, {
1051
+ childId,
1052
+ element: node,
1053
+ frame: undefined,
1054
+ adopt: true
1055
+ });
1056
+ }
1057
+ }
1058
+ return;
1059
+ }
1060
+ for (let c = node.firstChild; c; c = c.nextSibling) collectRegionElements(c, regions);
1061
+ }
1062
+ function renameRegion(entry, childId) {
1063
+ entry.childId = childId;
1064
+ if (entry.frame) entry.frame.rebind(childId);else entry.element.setAttribute(FRAME_ID_ATTR, childId);
1065
+ }
1066
+ function eachInRange(start, key, cb) {
1067
+ const end = slotEnd(key);
1068
+ let n = start.nextSibling;
1069
+ while (n && !(n.nodeType === COMMENT_NODE && n.data === end)) {
1070
+ const next = n.nextSibling;
1071
+ cb(n);
1072
+ n = next;
1073
+ }
1074
+ return n;
1075
+ }
1076
+ function clearStreamRecords(records, root) {
1077
+ for (const key in records) {
1078
+ if (/^(seg|hole|attr):/.test(key) || key === ":error" || root && key === "") {
1079
+ delete records[key];
1080
+ }
1081
+ }
1082
+ }
1083
+ function argsEquivalent(a, b) {
1084
+ if (a === b) return true;
1085
+ if (!a || !b) return false;
1086
+ const ka = Object.keys(a);
1087
+ const kb = Object.keys(b);
1088
+ if (ka.length !== kb.length) return false;
1089
+ for (const key of ka) {
1090
+ const va = a[key];
1091
+ const vb = b[key];
1092
+ if (va === vb) continue;
1093
+ if (isFrameRef(va) && va.$frame === vb?.$frame) continue;
1094
+ return false;
1095
+ }
1096
+ return true;
1097
+ }
1098
+ function slotStartId(node) {
1099
+ if (node.nodeType !== COMMENT_NODE) return null;
1100
+ const m = SLOT_START.exec(node.data);
1101
+ return m ? m[1] : null;
1102
+ }
1103
+ function isSlotMarker(node) {
1104
+ if (node.nodeType !== COMMENT_NODE) return false;
1105
+ const data = node.data;
1106
+ return SLOT_START.test(data) || SLOT_END.test(data);
1107
+ }
1108
+ function compatible(a, b) {
1109
+ if (a.nodeType !== b.nodeType) return false;
1110
+ if (a.nodeType === ELEMENT_NODE) return a.nodeName === b.nodeName && a.getAttribute("_key") === b.getAttribute("_key");
1111
+ return a.nodeType === TEXT_NODE || a.nodeType === COMMENT_NODE;
1112
+ }
1113
+ function preservesOpen(el) {
1114
+ const t = el.tagName;
1115
+ return t === "DETAILS" || t === "DIALOG";
1116
+ }
1117
+ function morphAttributes(oldEl, newEl, claim) {
1118
+ let reclaim = false;
1119
+ let changed = false;
1120
+ const keepOpen = preservesOpen(oldEl);
1121
+ const oldAttrs = oldEl.attributes;
1122
+ for (let i = oldAttrs.length - 1; i >= 0; i--) {
1123
+ const name = oldAttrs[i].name;
1124
+ if (keepOpen && name === "open") continue;
1125
+ if (!newEl.hasAttribute(name)) {
1126
+ oldEl.removeAttribute(name);
1127
+ changed = true;
1128
+ reclaim ||= claimedAttr(name);
1129
+ }
1130
+ }
1131
+ const newAttrs = newEl.attributes;
1132
+ for (let i = 0; i < newAttrs.length; i++) {
1133
+ const attr = newAttrs[i];
1134
+ if (keepOpen && attr.name === "open") continue;
1135
+ if (oldEl.getAttribute(attr.name) !== attr.value) {
1136
+ oldEl.setAttribute(attr.name, attr.value);
1137
+ changed = true;
1138
+ reclaim ||= claimedAttr(attr.name);
1139
+ }
1140
+ }
1141
+ if (claim && (reclaim || changed && oldEl.matches(CLAIMED_ELEMENTS))) claim(oldEl, true);
1142
+ }
1143
+ function morphNode(oldNode, newNode, claim, ranges, grafts) {
1144
+ if (oldNode.nodeType === ELEMENT_NODE) {
1145
+ if (oldNode.hasAttribute("data-preserve")) return;
1146
+ morphAttributes(oldNode, newNode, claim);
1147
+ reconcileChildren(oldNode, newNode, null, null, claim, ranges, grafts);
1148
+ } else if (oldNode.data !== newNode.data) {
1149
+ oldNode.data = newNode.data;
1150
+ }
1151
+ }
1152
+ function afterRange(start, id) {
1153
+ const end = slotEnd(id);
1154
+ let n = start.nextSibling;
1155
+ while (n) {
1156
+ if (n.nodeType === COMMENT_NODE && n.data === end) return n.nextSibling;
1157
+ n = n.nextSibling;
1158
+ }
1159
+ return null;
1160
+ }
1161
+ function findRangeStart(from, id, bound) {
1162
+ const target = `slot:${id}:start`;
1163
+ let n = from;
1164
+ while (n && n !== bound) {
1165
+ if (n.nodeType === COMMENT_NODE && n.data === target) return n;
1166
+ n = n.nextSibling;
1167
+ }
1168
+ return null;
1169
+ }
1170
+ function moveRangeBefore(parent, start, id, ref) {
1171
+ const end = slotEnd(id);
1172
+ let n = start;
1173
+ while (n) {
1174
+ const next = n.nextSibling;
1175
+ const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
1176
+ parent.insertBefore(n, ref);
1177
+ if (isEnd) break;
1178
+ n = next;
1179
+ }
1180
+ }
1181
+ function placeRange(parent, range, id, ref) {
1182
+ if (range.nodeType === 11 ) {
1183
+ parent.insertBefore(range, ref);
1184
+ } else {
1185
+ moveRangeBefore(parent, range, id, ref);
1186
+ }
1187
+ }
1188
+ function adoptRange(parent, start, id, ref, claim) {
1189
+ const end = slotEnd(id);
1190
+ let n = start;
1191
+ let after = null;
1192
+ while (n) {
1193
+ const next = n.nextSibling;
1194
+ const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
1195
+ parent.insertBefore(n, ref);
1196
+ if (claim) claim(n);
1197
+ if (isEnd) {
1198
+ after = next;
1199
+ break;
1200
+ }
1201
+ n = next;
1202
+ }
1203
+ return after;
1204
+ }
1205
+ function reconcileChildren(parent, source, boundStart = null, boundEnd = null, claim = null, ranges = null, grafts = null) {
1206
+ let oldChild = boundStart ? boundStart.nextSibling : parent.firstChild;
1207
+ let newChild = source.firstChild;
1208
+ while (newChild) {
1209
+ const nextNew = newChild.nextSibling;
1210
+ const pid = slotStartId(newChild);
1211
+ const old = oldChild === boundEnd ? null : oldChild;
1212
+ if (pid !== null) {
1213
+ if (old && slotStartId(old) === pid) {
1214
+ oldChild = afterRange(old, pid);
1215
+ newChild = afterRange(newChild, pid);
1216
+ } else {
1217
+ const displaced = ranges && ranges.get(pid);
1218
+ const existing = displaced || findRangeStart(old, pid, boundEnd);
1219
+ if (existing) {
1220
+ if (ranges) ranges.delete(pid);
1221
+ placeRange(parent, existing, pid, old ?? boundEnd);
1222
+ newChild = afterRange(newChild, pid);
1223
+ } else {
1224
+ newChild = adoptRange(parent, newChild, pid, old ?? boundEnd, claim);
1225
+ }
1226
+ }
1227
+ continue;
1228
+ }
1229
+ if (!old) {
1230
+ parent.insertBefore(newChild, boundEnd);
1231
+ if (claim) claim(newChild);
1232
+ if (grafts) grafts.push(newChild);
1233
+ newChild = nextNew;
1234
+ continue;
1235
+ }
1236
+ if (isSlotMarker(old)) {
1237
+ parent.insertBefore(newChild, old);
1238
+ if (claim) claim(newChild);
1239
+ if (grafts) grafts.push(newChild);
1240
+ newChild = nextNew;
1241
+ continue;
1242
+ }
1243
+ if (compatible(old, newChild)) {
1244
+ morphNode(old, newChild, claim, ranges, grafts);
1245
+ oldChild = old.nextSibling;
1246
+ newChild = nextNew;
1247
+ continue;
1248
+ }
1249
+ if (newChild.nodeType === 1) {
1250
+ let ahead = old.nextSibling;
1251
+ while (ahead && ahead !== boundEnd && !compatible(ahead, newChild)) {
1252
+ const aheadPid = slotStartId(ahead);
1253
+ ahead = aheadPid !== null ? afterRange(ahead, aheadPid) : ahead.nextSibling;
1254
+ }
1255
+ if (ahead && ahead !== boundEnd) {
1256
+ parent.insertBefore(ahead, old);
1257
+ morphNode(ahead, newChild, claim, ranges, grafts);
1258
+ newChild = nextNew;
1259
+ continue;
1260
+ }
1261
+ }
1262
+ parent.insertBefore(newChild, old);
1263
+ if (claim) claim(newChild);
1264
+ if (grafts) grafts.push(newChild);
1265
+ newChild = nextNew;
1266
+ }
1267
+ while (oldChild && oldChild !== boundEnd) {
1268
+ const next = oldChild.nextSibling;
1269
+ const pid = ranges ? slotStartId(oldChild) : null;
1270
+ if (pid !== null && ranges.get(pid) === oldChild) {
1271
+ const frag = document.createDocumentFragment();
1272
+ const after = stashRange(frag, oldChild, pid);
1273
+ ranges.set(pid, frag);
1274
+ oldChild = after;
1275
+ continue;
1276
+ }
1277
+ parent.removeChild(oldChild);
1278
+ oldChild = next;
1279
+ }
1280
+ }
1281
+ function flushGrafts(node, ranges) {
1282
+ if (node.nodeType !== ELEMENT_NODE || isFrameElement(node)) return;
1283
+ let n = node.firstChild;
1284
+ while (n) {
1285
+ const id = slotStartId(n);
1286
+ if (id !== null) {
1287
+ const next = afterRange(n, id);
1288
+ const displaced = ranges.get(id);
1289
+ if (displaced) {
1290
+ ranges.delete(id);
1291
+ placeRange(node, displaced, id, n);
1292
+ stashRange(document.createDocumentFragment(), n, id);
1293
+ }
1294
+ n = next;
1295
+ continue;
1296
+ }
1297
+ flushGrafts(n, ranges);
1298
+ n = n.nextSibling;
1299
+ }
1300
+ }
1301
+ function stashRange(frag, start, id) {
1302
+ const end = slotEnd(id);
1303
+ let n = start;
1304
+ while (n) {
1305
+ const next = n.nextSibling;
1306
+ const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
1307
+ frag.appendChild(n);
1308
+ if (isEnd) return next;
1309
+ n = next;
1310
+ }
1311
+ return null;
1312
+ }
1313
+
1314
+ const RECORDS = Symbol.for("@solidjs/signals/observe/records");
1315
+ function records() {
1316
+ return globalThis[RECORDS];
1317
+ }
1318
+ function frameCensus(event, type, own) {
1319
+ event.chunks++;
1320
+ switch (type) {
1321
+ case "html":
1322
+ if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
1323
+ break;
1324
+ case "fragment":
1325
+ event.fragments++;
1326
+ break;
1327
+ case "slot":
1328
+ event.slots++;
1329
+ break;
1330
+ case "error":
1331
+ event.errors++;
1332
+ break;
1333
+ }
1334
+ }
1335
+ function observeFrameApply(response) {
1336
+ const channel = records();
1337
+ if (channel === undefined || !channel.observed("frame")) return undefined;
1338
+ let current;
1339
+ const close = (outcome, error) => {
1340
+ const open = current;
1341
+ current = undefined;
1342
+ open.event.durationMs = performance.now() - open.event.at;
1343
+ open.event.outcome = outcome;
1344
+ const live = {
1345
+ response
1346
+ };
1347
+ if (error !== undefined) live.error = error;
1348
+ channel.emit("frame", open.event, live);
1349
+ };
1350
+ return {
1351
+ chunk(chunk, wireId) {
1352
+ if (chunk.type === "start") {
1353
+ if (current !== undefined) close("truncated");
1354
+ const event = {
1355
+ side: "client",
1356
+ id: wireId,
1357
+ version: chunk.version,
1358
+ at: performance.now(),
1359
+ durationMs: 0,
1360
+ outcome: "complete",
1361
+ chunks: 0,
1362
+ fragments: 0,
1363
+ slots: 0,
1364
+ regions: 0,
1365
+ errors: 0
1366
+ };
1367
+ if (chunk.id !== wireId) event.address = chunk.id;
1368
+ current = {
1369
+ event,
1370
+ applied: chunk.id
1371
+ };
1372
+ return;
1373
+ }
1374
+ if (current === undefined) return;
1375
+ if (chunk.type === "complete") {
1376
+ if (chunk.id === current.applied) close("complete");
1377
+ return;
1378
+ }
1379
+ frameCensus(current.event, chunk.type, chunk.id === current.applied);
1380
+ },
1381
+ end(error) {
1382
+ if (current !== undefined) close(error !== undefined ? "error" : "truncated", error);
1383
+ }
1384
+ };
1385
+ }
1386
+
1387
+ const FRAME_STREAM_HEADER = "X-Frame-Stream";
1388
+ function isFrameStreamResponse(response) {
1389
+ return response.headers.has(FRAME_STREAM_HEADER);
1390
+ }
1391
+ const applyFrameResponse = observedApplyFrameResponse ;
1392
+ async function observedApplyFrameResponse(response, host, options = {}) {
1393
+ const observation = observeFrameApply(response);
1394
+ if (!observation) return applyFrames(response, host, options);
1395
+ let applied;
1396
+ try {
1397
+ applied = await applyFrames(response, host, options, observation);
1398
+ } catch (error) {
1399
+ observation.end(error);
1400
+ throw error;
1401
+ }
1402
+ observation.end();
1403
+ return applied;
1404
+ }
1405
+ async function applyFrames(response, host, options = {}, observation) {
1406
+ const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
1407
+ const as = options.as;
1408
+ const version = options.version;
1409
+ const perFrame = typeof version === "function" ? new Map() : null;
1410
+ const reader = new ChunkReader(response.body);
1411
+ let result = await reader.next();
1412
+ while (!result.done) {
1413
+ const chunk = JSON.parse(result.value);
1414
+ if (chunk.type === "outcome") {
1415
+ if (options.onOutcome) options.onOutcome(chunk.payload);
1416
+ } else {
1417
+ const wireId = chunk.id;
1418
+ if (as !== undefined && chunk.id === rootId) chunk.id = as;
1419
+ if (perFrame) {
1420
+ let v = perFrame.get(chunk.id);
1421
+ if (v === undefined) perFrame.set(chunk.id, v = version(chunk.id));
1422
+ chunk.version = v;
1423
+ } else if (version !== undefined) chunk.version = version;
1424
+ if (observation) observation.chunk(chunk, wireId);
1425
+ if (chunk.type === "data" && host.prepareData) await host.prepareData();
1426
+ host.apply(chunk);
1427
+ }
1428
+ result = await reader.next();
1429
+ }
1430
+ return as !== undefined ? as : rootId;
1431
+ }
1432
+ const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("solid.server-component");
1433
+ const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("solid.server-component-address");
1434
+ const COMPONENT_BINDING = /*#__PURE__*/Symbol.for("solid.component-binding");
1435
+ let resolveServerComponent;
1436
+ function parseServerComponent(value, ctx) {
1437
+ return {
1438
+ id: ctx.parse(value[SERVER_COMPONENT]),
1439
+ address: ctx.parse(value[SERVER_COMPONENT_ADDRESS])
1440
+ };
1441
+ }
1442
+ const ServerComponentPlugin = {
1443
+ tag: "solid/server-component",
1444
+ test(value) {
1445
+ return typeof value === "function" && SERVER_COMPONENT in value;
1446
+ },
1447
+ parse: {
1448
+ sync: parseServerComponent,
1449
+ async async(value, ctx) {
1450
+ return {
1451
+ id: await ctx.parse(value[SERVER_COMPONENT]),
1452
+ address: await ctx.parse(value[SERVER_COMPONENT_ADDRESS])
1453
+ };
1454
+ },
1455
+ stream: parseServerComponent
1456
+ },
1457
+ serialize(node, ctx) {
1458
+ const registry = "self._$SC";
1459
+ return registry + ".r(" + ctx.serialize(node.id) + "," + ctx.serialize(node.address) + ")";
1460
+ },
1461
+ deserialize(node, ctx) {
1462
+ const id = ctx.deserialize(node.id);
1463
+ const address = ctx.deserialize(node.address);
1464
+ if (address !== undefined && resolveServerComponent) {
1465
+ return resolveServerComponent(id, address);
1466
+ }
1467
+ return globalThis._$SC.r(id);
1468
+ }
1469
+ };
1470
+ function flightCodec(codec) {
1471
+ const plugins = codec && codec.plugins || [];
1472
+ if (plugins.some(plugin => plugin && plugin.tag === ServerComponentPlugin.tag)) return codec;
1473
+ return {
1474
+ ...codec,
1475
+ plugins: [...plugins, ServerComponentPlugin]
1476
+ };
1477
+ }
1478
+ function createServerComponentHandler({
1479
+ host,
1480
+ component,
1481
+ onStream,
1482
+ intercept,
1483
+ consumer = getFlightDataConsumer,
1484
+ codec = getServerFunctionsCodec
1485
+ }) {
1486
+ const byFn = new Map();
1487
+ const componentFor = fnId => {
1488
+ let comp = byFn.get(fnId);
1489
+ if (comp === undefined) byFn.set(fnId, comp = component(fnId));
1490
+ return comp;
1491
+ };
1492
+ const byAddress = new Map();
1493
+ const bindingFor = (address, fnId) => {
1494
+ let binding = byAddress.get(address);
1495
+ if (!binding) {
1496
+ const comp = componentFor(fnId);
1497
+ binding = props => comp(props, () => address);
1498
+ binding[COMPONENT_BINDING] = {
1499
+ component: comp,
1500
+ address
1501
+ };
1502
+ byAddress.set(address, binding);
1503
+ }
1504
+ return binding;
1505
+ };
1506
+ resolveServerComponent = (id, address) => bindingFor(address, id);
1507
+ const versions = new Map();
1508
+ const bump = address => {
1509
+ const version = (versions.get(address) || 0) + 1;
1510
+ versions.set(address, version);
1511
+ return version;
1512
+ };
1513
+ return {
1514
+ intercept: intercept && (info => {
1515
+ const hit = intercept(info);
1516
+ if (hit === undefined) return undefined;
1517
+ return bindingFor(frameAddress(info.id, info.args), info.id);
1518
+ }),
1519
+ handle(response, ctx) {
1520
+ if (!isFrameStreamResponse(response)) return undefined;
1521
+ const address = frameAddress(ctx.id, ctx.args);
1522
+ const binding = bindingFor(address, ctx.id);
1523
+ if (response.headers.has(SINGLE_FLIGHT_HEADER)) {
1524
+ return applyFlightResponse(response, address, binding);
1525
+ }
1526
+ const version = bump(address);
1527
+ if (onStream) onStream(address, version, response);
1528
+ applyFrameResponse(response, host, {
1529
+ as: address,
1530
+ version
1531
+ }).catch(err => host.apply({
1532
+ type: "error",
1533
+ id: address,
1534
+ version,
1535
+ error: {
1536
+ message: String(err && err.message)
1537
+ }
1538
+ }));
1539
+ return binding;
1540
+ },
1541
+ showing(address, functionId) {
1542
+ bindingFor(address, functionId);
1543
+ const comp = componentFor(functionId);
1544
+ if (comp && (typeof comp === "function" || typeof comp === "object") && !comp[COMPONENT_BINDING]) {
1545
+ comp[COMPONENT_BINDING] = {
1546
+ component: comp,
1547
+ address
1548
+ };
1549
+ }
1550
+ }
1551
+ };
1552
+ async function applyFlightResponse(response, address, binding) {
1553
+ const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
1554
+ const as = rootId ? address : undefined;
1555
+ let feed;
1556
+ const source = new ReadableStream({
1557
+ start(controller) {
1558
+ feed = controller;
1559
+ }
1560
+ });
1561
+ const payload = deserializeStream(new Response(source), flightCodec(codec()));
1562
+ let carried = false;
1563
+ await applyFrameResponse(response, host, {
1564
+ as,
1565
+ version: frameId => {
1566
+ const version = bump(frameId);
1567
+ if (onStream) onStream(frameId, version, response);
1568
+ return version;
1569
+ },
1570
+ onOutcome: text => {
1571
+ carried = true;
1572
+ feed.enqueue(createChunk(text));
1573
+ }
1574
+ });
1575
+ feed.close();
1576
+ if (!carried) throw new Error("Single-flight frame response carried no outcome");
1577
+ const envelope = await payload;
1578
+ const deliver = consumer();
1579
+ if (deliver) await deliver(envelope.data, {
1580
+ response
1581
+ });
1582
+ if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has(REVALIDATE_HEADER)) {
1583
+ throw envelope.value;
1584
+ }
1585
+ return rootId ? binding : envelope.value;
1586
+ }
1587
+ }
1588
+
1589
+ const STATE = Symbol.for("solid.container-trace-state");
1590
+ const state = globalThis[STATE] || (globalThis[STATE] = {
1591
+ materialized: new WeakMap(),
1592
+ materializedValues: new WeakSet()
1593
+ });
1594
+ function setContainerTraceMaterializer(fn) {
1595
+ state.materializeTrace = fn;
1596
+ }
1597
+ function materialize(marker) {
1598
+ let value = state.materialized.get(marker.$tr);
1599
+ if (value === undefined) {
1600
+ value = state.materializeTrace(marker);
1601
+ state.materialized.set(marker.$tr, value);
1602
+ if (value !== null && typeof value === "object") state.materializedValues.add(value);
1603
+ }
1604
+ return value;
1605
+ }
1606
+ function isMaterializedContainer(value) {
1607
+ return value !== null && typeof value === "object" && state.materializedValues.has(value);
1608
+ }
1609
+ function isContainerTraceMarker(value) {
1610
+ if (value == null || typeof value !== "object" || value.$tr == null) return false;
1611
+ const tr = value.$tr;
1612
+ return tr.__SEROVAL_STREAM__ === true || typeof tr[Symbol.asyncIterator] === "function";
1613
+ }
1614
+ function reviveContainerTraces(value) {
1615
+ if (!state.materializeTrace || value == null || typeof value !== "object") return value;
1616
+ if (isContainerTraceMarker(value)) return materialize(value);
1617
+ if (Array.isArray(value)) {
1618
+ for (let i = 0; i < value.length; i++) value[i] = reviveContainerTraces(value[i]);
1619
+ } else if (Object.getPrototypeOf(value) === Object.prototype) {
1620
+ for (const key of Object.keys(value)) value[key] = reviveContainerTraces(value[key]);
1621
+ }
1622
+ return value;
1623
+ }
1624
+
1625
+ const materializeContainerTrace = core.materializeContainerTrace;
1626
+
1627
+ setContainerTraceMaterializer(materializeContainerTrace);
1628
+ function asyncArg(value) {
1629
+ return value;
1630
+ }
1631
+ let sharedHost;
1632
+ let codec;
1633
+ let codecLoading;
1634
+ function loadCodec() {
1635
+ return codecLoading ??= import('@solidjs/web/serialization/decode').then(m => {
1636
+ codec = m;
1637
+ });
1638
+ }
1639
+ const tables = new Map();
1640
+ function ensureTable(root) {
1641
+ let table = tables.get(root);
1642
+ if (!table && codec) tables.set(root, table = codec.createJSONDataTable());
1643
+ return table;
1644
+ }
1645
+ function tableFor(id) {
1646
+ if (tables.has(id)) return ensureTable(id);
1647
+ for (const root of tables.keys()) if (id.startsWith(root + ".")) return ensureTable(root);
1648
+ return undefined;
1649
+ }
1650
+ function beginStream(frameId) {
1651
+ tables.set(frameId, undefined);
1652
+ }
1653
+ function getFrameHost() {
1654
+ if (!sharedHost) {
1655
+ sharedHost = createFrameHost({
1656
+ prepareData: loadCodec,
1657
+ applyData: c => tableFor(c.id)?.apply(c),
1658
+ resolve: (ref, id) => tableFor(id)?.resolve(ref),
1659
+ revive: reviveContainerTraces,
1660
+ isContainer: isMaterializedContainer,
1661
+ delegate: delegateEvents
1662
+ });
1663
+ }
1664
+ return sharedHost;
1665
+ }
1666
+ function normalizeSlotContent(value) {
1667
+ while (typeof value === "function") value = value();
1668
+ if (Array.isArray(value)) {
1669
+ const out = [];
1670
+ for (const v of value) {
1671
+ const n = normalizeSlotContent(v);
1672
+ Array.isArray(n) ? out.push(...n) : out.push(n);
1673
+ }
1674
+ return out;
1675
+ }
1676
+ if (value == null || typeof value === "boolean") return document.createTextNode("");
1677
+ return value instanceof Node ? value : document.createTextNode(String(value));
1678
+ }
1679
+ function gatherClaims(el, registry) {
1680
+ if (el.hasAttribute("_hk")) registry.set(el.getAttribute("_hk"), el);
1681
+ if (el.hasAttribute(FRAME_ID_ATTR)) return;
1682
+ for (let c = el.firstElementChild; c; c = c.nextElementSibling) gatherClaims(c, registry);
1683
+ }
1684
+ function hasPendingFragment(existing) {
1685
+ for (const n of existing) {
1686
+ if (n.nodeType !== 1) continue;
1687
+ const el = n;
1688
+ if (el.tagName === "TEMPLATE" && el.id.startsWith("pl-")) return true;
1689
+ if (el.querySelector?.('template[id^="pl-"]')) return true;
1690
+ }
1691
+ return false;
1692
+ }
1693
+ function claimRender(prefix, existing, render) {
1694
+ const sc = sharedConfig;
1695
+ if (!sc.getNextContextId) return render();
1696
+ const registry = new Map();
1697
+ for (const n of existing) {
1698
+ if (n.nodeType !== 1) continue;
1699
+ gatherClaims(n, registry);
1700
+ }
1701
+ if (!registry.size && !hasPendingFragment(existing)) return render();
1702
+ const prevRegistry = sc.registry;
1703
+ const prevHydrating = sc.hydrating;
1704
+ const prevClaimRoots = sc.claimRoots;
1705
+ if (prevRegistry) for (const key of registry.keys()) prevRegistry.delete(key);
1706
+ sc.registry = registry;
1707
+ sc.hydrating = true;
1708
+ sc.claimRoots = existing;
1709
+ try {
1710
+ return runWithOwner(createOwner({
1711
+ id: prefix
1712
+ }), render);
1713
+ } finally {
1714
+ sc.registry = prevRegistry;
1715
+ sc.hydrating = prevHydrating;
1716
+ sc.claimRoots = prevClaimRoots;
1717
+ }
1718
+ }
1719
+ function liveSlotProps(initial, ctx) {
1720
+ const [args, setArgs] = createSignal(initial);
1721
+ ctx.onUpdate(next => setArgs(() => next));
1722
+ return slotArgsProxy(args);
1723
+ }
1724
+ function isAsyncValue(v) {
1725
+ return v !== null && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
1726
+ }
1727
+ function slotArgsProxy(args) {
1728
+ const owner = getOwner();
1729
+ const asyncReads = new Map();
1730
+ return new Proxy({}, {
1731
+ get: (_, key) => {
1732
+ const v = args()[key];
1733
+ if (isMaterializedContainer(v)) return v;
1734
+ if (!isAsyncValue(v)) return v;
1735
+ let read = asyncReads.get(key);
1736
+ if (!read) {
1737
+ const make = () => createMemo(() => {
1738
+ const raw = args()[key];
1739
+ if (raw != null && typeof raw.then === "function") {
1740
+ if (raw.s === 1) return raw.v;
1741
+ if (raw.s === 2) throw raw.v;
1742
+ }
1743
+ return raw;
1744
+ }, {
1745
+ transparent: true
1746
+ });
1747
+ read = owner ? runWithOwner(owner, make) : make();
1748
+ asyncReads.set(key, read);
1749
+ }
1750
+ return read();
1751
+ },
1752
+ has: (_, key) => key in args(),
1753
+ ownKeys: () => Reflect.ownKeys(args()),
1754
+ getOwnPropertyDescriptor: (_, key) => key in args() ? {
1755
+ enumerable: true,
1756
+ configurable: true
1757
+ } : undefined
1758
+ });
1759
+ }
1760
+ function isReactiveContent(value) {
1761
+ if (typeof value === "function") return true;
1762
+ if (Array.isArray(value)) {
1763
+ for (const v of value) if (isReactiveContent(v)) return true;
1764
+ }
1765
+ return false;
1766
+ }
1767
+ function slotsFor(props) {
1768
+ const bindings = new Map();
1769
+ const fillScopes = new Map();
1770
+ return new Proxy({}, {
1771
+ get(_, prop) {
1772
+ if (typeof prop !== "string" || !(prop in props)) return undefined;
1773
+ return (slotProps, ctx) => {
1774
+ const key = ctx && ctx.key;
1775
+ const prev = key !== undefined && bindings.get(key);
1776
+ if (prev) {
1777
+ bindings.delete(key);
1778
+ prev.dispose();
1779
+ }
1780
+ const prevFill = key !== undefined && fillScopes.get(key);
1781
+ if (prevFill) {
1782
+ fillScopes.delete(key);
1783
+ prevFill.dispose();
1784
+ }
1785
+ const fillOwner = streamInvoke ? createOwner() : null;
1786
+ if (fillOwner && key !== undefined && ctx) {
1787
+ fillScopes.set(key, fillOwner);
1788
+ ctx.onCleanup(() => {
1789
+ if (fillScopes.get(key) === fillOwner) fillScopes.delete(key);
1790
+ fillOwner.dispose();
1791
+ });
1792
+ }
1793
+ const settle = out => {
1794
+ const existing = ctx && ctx.existing || [];
1795
+ if (existing.length) {
1796
+ const list = Array.isArray(out) ? out : [out];
1797
+ const inPlace = list.every(n => existing.some(e => e === n || e.nodeType === 1 && e.contains(n)));
1798
+ if (inPlace) return undefined;
1799
+ }
1800
+ return out;
1801
+ };
1802
+ const evaluate = () => {
1803
+ const v = props[prop];
1804
+ if (typeof v === "function" && ctx && ctx.invoked) {
1805
+ return v(ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotArgsProxy(() => slotProps));
1806
+ }
1807
+ return v;
1808
+ };
1809
+ const adopted = !!(ctx && ctx.frame && ctx.adopted && ctx.existing && ctx.existing.length);
1810
+ const prefix = ctx && ctx.frame ? `sc-${ctx.frame}-${ctx.key}-` : "";
1811
+ const value = fillOwner ? runWithOwner(fillOwner, () => adopted ? claimRender(prefix, ctx.existing, evaluate) : evaluate()) : adopted ? claimRender(prefix, ctx.existing, evaluate) : evaluate();
1812
+ if (!isReactiveContent(value)) {
1813
+ return settle(normalizeSlotContent(value));
1814
+ }
1815
+ if (ctx && ctx.range) {
1816
+ const source = value;
1817
+ const owner = createOwner();
1818
+ bindings.set(key, owner);
1819
+ ctx.onCleanup(() => {
1820
+ if (bindings.get(key) === owner) bindings.delete(key);
1821
+ owner.dispose();
1822
+ });
1823
+ const end = ctx.range.end;
1824
+ const bind = () => insert(end.parentNode, () => typeof source === "function" ? source() : source, end, [...ctx.existing]);
1825
+ runWithOwner(owner, () => adopted ? claimRender(prefix, ctx.existing, bind) : bind());
1826
+ return undefined;
1827
+ }
1828
+ return settle(normalizeSlotContent(value));
1829
+ };
1830
+ }
1831
+ });
1832
+ }
1833
+ function revealSeam(owner) {
1834
+ return seam => runWithOwner(owner, () => insert(seam.before.parentNode, createLoadingBoundary(() => seam.content(), () => seam.fallback), seam.before));
1835
+ }
1836
+ let streamInvoke = false;
1837
+ function boundaryScope(owner) {
1838
+ return fn => {
1839
+ if (getOwner()) return fn();
1840
+ streamInvoke = true;
1841
+ try {
1842
+ return runWithOwner(owner, fn);
1843
+ } finally {
1844
+ streamInvoke = false;
1845
+ }
1846
+ };
1847
+ }
1848
+ function boundaryComponent(host, fnId) {
1849
+ return (props, binding) => {
1850
+ const owner = getOwner();
1851
+ const id = binding ? binding() : fnId;
1852
+ let applied = !tables.has(id);
1853
+ let release;
1854
+ const arm = () => new Promise(r => release = r);
1855
+ const mountGate = applied ? undefined : arm();
1856
+ let setGate;
1857
+ const {
1858
+ element,
1859
+ frame,
1860
+ dispose
1861
+ } = createFrameElement({
1862
+ host,
1863
+ id,
1864
+ slots: slotsFor(props),
1865
+ props,
1866
+ ownerScope: boundaryScope(owner),
1867
+ reveal: revealSeam(owner),
1868
+ onApply: () => {
1869
+ applied = true;
1870
+ if (release) {
1871
+ release();
1872
+ release = undefined;
1873
+ }
1874
+ setGate && setGate(undefined);
1875
+ }
1876
+ });
1877
+ const [gatePromise, setGatePromise] = createSignal(applied ? undefined : mountGate);
1878
+ setGate = setGatePromise;
1879
+ if (binding) {
1880
+ createRenderEffect(binding, (address, prev) => {
1881
+ if (prev !== undefined && address !== prev && tables.has(address)) {
1882
+ applied = false;
1883
+ setGatePromise(arm());
1884
+ }
1885
+ frame.rebind(address);
1886
+ });
1887
+ }
1888
+ onCleanup(dispose);
1889
+ if (applied && !binding) return element;
1890
+ const gate = createMemo(() => gatePromise());
1891
+ return createMemo(() => (gate(), element));
1892
+ };
1893
+ }
1894
+ const claimedBoundaries = new Set();
1895
+ const liveOps = new Map();
1896
+ const liveAppliers = new Set();
1897
+ let livePumped = null;
1898
+ function pumpLiveChannel() {
1899
+ const stream = globalThis._$HY?.r?.["sc:live"];
1900
+ if (!stream || stream === livePumped || typeof stream.getReader !== "function") return;
1901
+ livePumped = stream;
1902
+ const reader = stream.getReader();
1903
+ const pump = () => reader.read().then(r => {
1904
+ if (r.done) return;
1905
+ const op = r.value;
1906
+ liveOps.set(`${op.type}:${op.fid || ""}:${op.key || ""}`, op);
1907
+ for (const apply of liveAppliers) apply(op);
1908
+ return pump();
1909
+ });
1910
+ pump().catch(() => {
1911
+ });
1912
+ }
1913
+ let boundaryIndex = null;
1914
+ const isBoundaryId = id => !id.includes(".");
1915
+ function indexBoundaries(root) {
1916
+ root.querySelectorAll(`[${FRAME_ID_ATTR}]`).forEach(el => {
1917
+ const key = el.getAttribute(FRAME_ID_ATTR);
1918
+ if (key && isBoundaryId(key) && !boundaryIndex.has(key)) boundaryIndex.set(key, el);
1919
+ });
1920
+ }
1921
+ function findBoundaryElement(id) {
1922
+ if (!boundaryIndex) {
1923
+ boundaryIndex = new Map();
1924
+ if (typeof document !== "undefined" && document.body) indexBoundaries(document.body);
1925
+ }
1926
+ return boundaryIndex.get(id);
1927
+ }
1928
+ const boundaryWaiters = new Map();
1929
+ function boundaryMayArrive() {
1930
+ const hy = globalThis._$HY;
1931
+ if (!hy) return false;
1932
+ return !hy.done || !!(hy.fr && hy.fr.pending());
1933
+ }
1934
+ function installRevealHook() {
1935
+ const hy = globalThis._$HY;
1936
+ if (!hy || hy.$sc || !hy.fr) return;
1937
+ hy.$sc = true;
1938
+ hy.fr.subscribe((_id, parent) => {
1939
+ if (!boundaryIndex) return;
1940
+ const root = parent || (typeof document !== "undefined" ? document.body : null);
1941
+ if (root) indexBoundaries(root);
1942
+ if (!boundaryWaiters.size) return;
1943
+ const exhausted = hy.done && !hy.fr.pending();
1944
+ for (const [id, notify] of boundaryWaiters) {
1945
+ const el = boundaryIndex && boundaryIndex.get(id);
1946
+ if (!el && !exhausted) continue;
1947
+ boundaryWaiters.delete(id);
1948
+ notify(el);
1949
+ }
1950
+ });
1951
+ }
1952
+ function documentBoundary(host, id, props, binding) {
1953
+ installRevealHook();
1954
+ const claimed = claimedBoundaries.has(id);
1955
+ const el = !claimed ? findBoundaryElement(id) : undefined;
1956
+ if (el) return adoptBoundary(host, id, el, props, binding);
1957
+ if (!claimed && !boundaryWaiters.has(id) && boundaryMayArrive()) {
1958
+ const owner = getOwner();
1959
+ const arrival = new Promise(resolve => boundaryWaiters.set(id, resolve));
1960
+ onCleanup(() => boundaryWaiters.delete(id));
1961
+ return createMemo(() => arrival.then(node => runWithOwner(owner, () =>
1962
+ node ? adoptBoundary(host, id, node, props, binding) : boundaryComponent(host, id)(props, binding))));
1963
+ }
1964
+ return boundaryComponent(host, id)(props, binding);
1965
+ }
1966
+ function documentAddress(id) {
1967
+ const records = globalThis._$SC?.a;
1968
+ if (records) {
1969
+ for (const address in records) if (records[address] === id) return address;
1970
+ }
1971
+ return id;
1972
+ }
1973
+ function adoptBoundary(host, id, el, props, binding) {
1974
+ claimedBoundaries.add(id);
1975
+ const address = binding ? binding() : documentAddress(id);
1976
+ const appliedRecords = new Set();
1977
+ const claimedFragments = new Set();
1978
+ const claimRegionFragments = root => {
1979
+ const fr = globalThis._$HY?.fr;
1980
+ if (!fr || !fr.claim) return;
1981
+ root.querySelectorAll('template[id^="pl-"]').forEach(tpl => {
1982
+ const fragId = tpl.id.slice(3);
1983
+ if (claimedFragments.has(fragId)) return;
1984
+ claimedFragments.add(fragId);
1985
+ fr.claim(fragId);
1986
+ });
1987
+ };
1988
+ const drainRecords = () => {
1989
+ const hy = globalThis._$HY;
1990
+ if (!hy || !hy.r) return;
1991
+ pumpLiveChannel();
1992
+ const slotPrefix = `sc:slot:${id}:`;
1993
+ for (const key of Object.keys(hy.r)) {
1994
+ if (appliedRecords.has(key)) continue;
1995
+ if (key.startsWith(slotPrefix)) {
1996
+ appliedRecords.add(key);
1997
+ host.apply({
1998
+ type: "slot",
1999
+ id: address,
2000
+ version: 0,
2001
+ key: key.slice(slotPrefix.length),
2002
+ args: hy.r[key]
2003
+ });
2004
+ } else if (key.startsWith("sc:region:")) {
2005
+ const childId = key.slice("sc:region:".length);
2006
+ if (childId.startsWith(id + ".")) {
2007
+ appliedRecords.add(key);
2008
+ const val = hy.r[key];
2009
+ const apply = html => host.apply({
2010
+ type: "html",
2011
+ id: childId,
2012
+ version: 0,
2013
+ html
2014
+ });
2015
+ val && typeof val.then === "function" ? val.then(apply) : apply(val);
2016
+ }
2017
+ }
2018
+ }
2019
+ };
2020
+ claimRegionFragments(el);
2021
+ const fr = globalThis._$HY?.fr;
2022
+ const unsubscribe = fr ? fr.subscribe((_fragId, parent) => {
2023
+ if (fr.claim && parent && el.contains(parent)) claimRegionFragments(parent);
2024
+ drainRecords();
2025
+ }) : undefined;
2026
+ const applyLiveOp = op => {
2027
+ if (op.type === "slot" && op.fid !== id) return;
2028
+ host.apply({
2029
+ ...op,
2030
+ id: address,
2031
+ version: 0
2032
+ });
2033
+ };
2034
+ liveAppliers.add(applyLiveOp);
2035
+ onCleanup(() => {
2036
+ liveAppliers.delete(applyLiveOp);
2037
+ unsubscribe && unsubscribe();
2038
+ if (fr && fr.release) for (const fragId of claimedFragments) fr.release(fragId);
2039
+ });
2040
+ drainRecords();
2041
+ for (const op of liveOps.values()) applyLiveOp(op);
2042
+ const owner = getOwner();
2043
+ let release;
2044
+ let setGate;
2045
+ const frame = createFrame(el, {
2046
+ adopt: true,
2047
+ host,
2048
+ id: address,
2049
+ slots: slotsFor(props),
2050
+ props,
2051
+ ownerScope: boundaryScope(owner),
2052
+ reveal: revealSeam(owner),
2053
+ onApply: () => {
2054
+ if (release) {
2055
+ release();
2056
+ release = undefined;
2057
+ }
2058
+ setGate && setGate(undefined);
2059
+ },
2060
+ ...{
2061
+ recordsPending: () => {
2062
+ if (document.readyState === "loading") return true;
2063
+ const hy = globalThis._$HY;
2064
+ return !!(hy && hy.fr && hy.fr.pending());
2065
+ },
2066
+ drainRecords,
2067
+ claimScope: id
2068
+ }
2069
+ });
2070
+ if (binding) {
2071
+ const arm = () => new Promise(r => release = r);
2072
+ const [gatePromise, setGatePromise] = createSignal(undefined);
2073
+ setGate = setGatePromise;
2074
+ const gate = createMemo(() => gatePromise());
2075
+ createRenderEffect(binding, (address, prev) => {
2076
+ if (prev !== undefined && address !== prev && tables.has(address)) {
2077
+ setGatePromise(arm());
2078
+ }
2079
+ frame.rebind(address);
2080
+ });
2081
+ createRenderEffect(() => (gate(), undefined), () => {});
2082
+ }
2083
+ onCleanup(() => frame.dispose());
2084
+ return el;
2085
+ }
2086
+ function installServerComponents(host = getFrameHost()) {
2087
+ const g = globalThis;
2088
+ if (!g._$SC) {
2089
+ g._$SC = {
2090
+ c: {},
2091
+ a: {},
2092
+ r(i, a) {
2093
+ if (a) {
2094
+ g._$SC.a[a] = i;
2095
+ g._$SC.reg && g._$SC.reg(a, i);
2096
+ }
2097
+ return g._$SC.c[i] || (g._$SC.c[i] = (p, b) => g._$SC.impl(i, p, b));
2098
+ }
2099
+ };
2100
+ }
2101
+ g._$SC.impl = (id, props, binding) => documentBoundary(host, id, props, binding);
2102
+ installRevealHook();
2103
+ const handler = createServerComponentHandler({
2104
+ host,
2105
+ component: fnId => g._$SC.r(fnId),
2106
+ onStream: address => beginStream(address),
2107
+ intercept: ({
2108
+ id
2109
+ }) => {
2110
+ if (claimedBoundaries.has(id) || !findBoundaryElement(id)) return undefined;
2111
+ return g._$SC.r(id);
2112
+ }
2113
+ });
2114
+ const showing = (address, id) => handler.showing(address, id);
2115
+ const records = g._$SC.a || (g._$SC.a = {});
2116
+ for (const address in records) showing(address, records[address]);
2117
+ g._$SC.reg = showing;
2118
+ configureServerFunctionsClient({
2119
+ responseHandler: handler
2120
+ });
2121
+ }
2122
+
2123
+ export { FRAME_APPLIED_EVENT, FRAME_STREAM_HEADER, applyFrameResponse, asyncArg, createFrame, createFrameElement, createFrameHost, createServerComponentHandler, getFrameHost, installServerComponents, isFrameStreamResponse };