@solidjs/web 2.0.0-beta.3 → 2.0.0-beta.30

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 (73) hide show
  1. package/README.md +27 -4
  2. package/dist/dev.cjs +1211 -205
  3. package/dist/dev.js +1175 -199
  4. package/dist/server.cjs +1342 -234
  5. package/dist/server.js +1304 -231
  6. package/dist/web.cjs +1195 -196
  7. package/dist/web.js +1159 -190
  8. package/frames/dist/client.cjs +1746 -0
  9. package/frames/dist/client.dev.cjs +1759 -0
  10. package/frames/dist/client.dev.js +1747 -0
  11. package/frames/dist/client.js +1734 -0
  12. package/frames/dist/server.cjs +2426 -0
  13. package/frames/dist/server.js +2414 -0
  14. package/frames/package.json +30 -0
  15. package/package.json +287 -38
  16. package/serialization/dist/serialization.cjs +169 -0
  17. package/serialization/dist/serialization.js +159 -0
  18. package/serialization/package.json +20 -0
  19. package/serialization/types/index.d.ts +157 -0
  20. package/serialization/types-cjs/index.d.cts +157 -0
  21. package/serialization/types-cjs/package.json +3 -0
  22. package/server-functions/dist/client.cjs +613 -0
  23. package/server-functions/dist/client.js +585 -0
  24. package/server-functions/dist/server.cjs +904 -0
  25. package/server-functions/dist/server.js +875 -0
  26. package/server-functions/package.json +30 -0
  27. package/storage/package.json +8 -3
  28. package/storage/types/index.d.ts +26 -0
  29. package/storage/types-cjs/index.d.cts +28 -0
  30. package/storage/types-cjs/package.json +3 -0
  31. package/types/client.d.ts +125 -21
  32. package/types/core.d.ts +4 -3
  33. package/types/frames/client.d.ts +20 -0
  34. package/types/frames/frame-client.d.ts +270 -0
  35. package/types/frames/frame-sink.d.ts +168 -0
  36. package/types/frames/frame-transport.d.ts +196 -0
  37. package/types/frames/serializer.d.ts +157 -0
  38. package/types/frames/server.d.ts +30 -0
  39. package/types/index.d.ts +211 -26
  40. package/types/jsx-properties.d.ts +93 -0
  41. package/types/jsx.d.ts +4150 -1
  42. package/types/response.d.ts +129 -0
  43. package/types/serializer.d.ts +157 -0
  44. package/types/server-functions/client.d.ts +200 -0
  45. package/types/server-functions/flash.d.ts +38 -0
  46. package/types/server-functions/server.d.ts +490 -0
  47. package/types/server-functions/shared.d.ts +445 -0
  48. package/types/server-mock.d.ts +93 -0
  49. package/types/server.d.ts +221 -28
  50. package/types-cjs/client.d.cts +192 -0
  51. package/types-cjs/core.d.cts +4 -0
  52. package/types-cjs/frames/client.d.cts +20 -0
  53. package/types-cjs/frames/frame-client.d.cts +270 -0
  54. package/types-cjs/frames/frame-sink.d.cts +168 -0
  55. package/types-cjs/frames/frame-transport.d.cts +196 -0
  56. package/types-cjs/frames/serializer.d.cts +157 -0
  57. package/types-cjs/frames/server.d.cts +30 -0
  58. package/types-cjs/index.d.cts +231 -0
  59. package/types-cjs/jsx-properties.d.cts +93 -0
  60. package/types-cjs/jsx.d.cts +4150 -0
  61. package/types-cjs/package.json +3 -0
  62. package/types-cjs/response.d.cts +129 -0
  63. package/types-cjs/serializer.d.cts +157 -0
  64. package/types-cjs/server-functions/client.d.cts +200 -0
  65. package/types-cjs/server-functions/flash.d.cts +38 -0
  66. package/types-cjs/server-functions/server.d.cts +490 -0
  67. package/types-cjs/server-functions/shared.d.cts +445 -0
  68. package/types-cjs/server-mock.d.cts +165 -0
  69. package/types-cjs/server.d.cts +349 -0
  70. package/storage/types/src/client.d.ts +0 -1
  71. package/storage/types/src/index.d.ts +0 -46
  72. package/storage/types/src/server-mock.d.ts +0 -72
  73. package/storage/types/storage/src/index.d.ts +0 -2
@@ -0,0 +1,1759 @@
1
+ 'use strict';
2
+
3
+ var solidJs = require('solid-js');
4
+ var web$1 = require('@solidjs/web');
5
+ var seroval = require('seroval');
6
+ var client = require('@solidjs/web/server-functions/client');
7
+ var web = require('seroval-plugins/web');
8
+
9
+ const ELEMENT_NODE = 1;
10
+ const TEXT_NODE = 3;
11
+ const COMMENT_NODE = 8;
12
+ const CLAIM_SEAM = Symbol.for("dom-expressions.element-claims");
13
+ const CLAIMED_ELEMENTS = "a[href], form[action]";
14
+ function claimHandlers() {
15
+ const handlers = globalThis[CLAIM_SEAM];
16
+ return handlers !== undefined && handlers.length !== 0 ? handlers : undefined;
17
+ }
18
+ function claimNode(handlers, el) {
19
+ for (let i = 0; i < handlers.length; i++) handlers[i](el);
20
+ }
21
+ const claimedAttr = name => name === "href" || name === "action";
22
+ function claimTree(handlers, root) {
23
+ const isElement = root.nodeType === ELEMENT_NODE;
24
+ if (!isElement && root.nodeType !== 11 ) return;
25
+ if (isElement && root.matches(CLAIMED_ELEMENTS)) claimNode(handlers, root);
26
+ const found = root.querySelectorAll(CLAIMED_ELEMENTS);
27
+ for (let i = 0; i < found.length; i++) claimNode(handlers, found[i]);
28
+ }
29
+ const placeholderId = name => `pl-${name}`;
30
+ const SLOT_START = /^slot:(.+):start$/;
31
+ const SLOT_END = /^slot:(.+):end$/;
32
+ const slotEnd = id => `slot:${id}:end`;
33
+ function chunkToRecords(chunk) {
34
+ switch (chunk.type) {
35
+ case "start":
36
+ case "data":
37
+ return {};
38
+ case "html":
39
+ return {
40
+ "": {
41
+ kind: "html",
42
+ value: chunk.html
43
+ }
44
+ };
45
+ case "fragment":
46
+ return {
47
+ [`seg:${chunk.key}`]: {
48
+ kind: "html",
49
+ value: chunk.html
50
+ }
51
+ };
52
+ case "reveal":
53
+ {
54
+ const records = {};
55
+ const gate = chunk.fallback ? "fallback" : "reveal";
56
+ for (const key of chunk.keys) records[`seg:${key}:${gate}`] = true;
57
+ return records;
58
+ }
59
+ case "assets":
60
+ return {
61
+ [`seg:${chunk.key}:assets`]: chunk
62
+ };
63
+ case "slot":
64
+ return {
65
+ [`slot:${chunk.key}`]: {
66
+ kind: "slot",
67
+ args: chunk.args
68
+ }
69
+ };
70
+ case "complete":
71
+ return {
72
+ ":complete": true
73
+ };
74
+ case "error":
75
+ return chunk.key ? {
76
+ [`seg:${chunk.key}:error`]: chunk.error
77
+ } : {
78
+ ":error": chunk.error
79
+ };
80
+ default:
81
+ return {};
82
+ }
83
+ }
84
+ function createFrameHost(options = {}) {
85
+ const frames = new Map();
86
+ const pending = new Map();
87
+ const retained = new Map();
88
+ const deliver = (frame, chunk) => {
89
+ if (chunk.type === "data") {
90
+ options.applyData && options.applyData(chunk);
91
+ return;
92
+ }
93
+ frame.apply({
94
+ version: chunk.version,
95
+ r: chunkToRecords(chunk)
96
+ });
97
+ };
98
+ return {
99
+ register(id, frame) {
100
+ let set = frames.get(id);
101
+ if (!set) frames.set(id, set = new Set());
102
+ const sibling = set.size ? set.values().next().value : undefined;
103
+ set.add(frame);
104
+ if (sibling) {
105
+ frame.apply({
106
+ version: sibling.version ?? 0,
107
+ r: sibling.store
108
+ });
109
+ if (sibling.version === undefined) frame.rebase && frame.rebase();
110
+ return;
111
+ }
112
+ const kept = retained.get(id);
113
+ if (kept) {
114
+ retained.delete(id);
115
+ frame.apply({
116
+ version: kept.version,
117
+ r: kept.records
118
+ });
119
+ frame.rebase && frame.rebase();
120
+ }
121
+ const buffered = pending.get(id);
122
+ if (buffered) {
123
+ pending.delete(id);
124
+ const records = {};
125
+ let version;
126
+ for (const chunk of buffered.chunks) {
127
+ if (chunk.type === "data") {
128
+ options.applyData && options.applyData(chunk);
129
+ continue;
130
+ }
131
+ version = chunk.version;
132
+ Object.assign(records, chunkToRecords(chunk));
133
+ }
134
+ if (version !== undefined) frame.apply({
135
+ version,
136
+ r: records
137
+ });
138
+ }
139
+ },
140
+ unregister(id, frame) {
141
+ const set = frames.get(id);
142
+ if (set && frame) set.delete(frame);
143
+ if (!set || !frame || !set.size) {
144
+ if (frame) {
145
+ const kept = frame.snapshot && frame.snapshot();
146
+ if (kept) retained.set(id, kept);
147
+ } else {
148
+ retained.delete(id);
149
+ }
150
+ frames.delete(id);
151
+ pending.delete(id);
152
+ }
153
+ },
154
+ apply(chunk) {
155
+ if (chunk.type === "data") {
156
+ options.applyData && options.applyData(chunk);
157
+ return;
158
+ }
159
+ const set = frames.get(chunk.id);
160
+ if (set && set.size) {
161
+ for (const frame of set) deliver(frame, chunk);
162
+ return;
163
+ }
164
+ const buffered = pending.get(chunk.id);
165
+ if (!buffered) {
166
+ pending.set(chunk.id, {
167
+ version: chunk.version,
168
+ chunks: [chunk]
169
+ });
170
+ return;
171
+ }
172
+ if (chunk.version < buffered.version) return;
173
+ if (chunk.version > buffered.version) {
174
+ buffered.version = chunk.version;
175
+ buffered.chunks.length = 0;
176
+ }
177
+ buffered.chunks.push(chunk);
178
+ },
179
+ get(id) {
180
+ const set = frames.get(id);
181
+ return set && set.values().next().value;
182
+ },
183
+ serialize(value) {
184
+ if (!options.serialize) throw new Error("host has no serializer");
185
+ return options.serialize(value);
186
+ },
187
+ resolve(ref, frameId) {
188
+ return options.resolve ? options.resolve(ref, frameId) : undefined;
189
+ }
190
+ };
191
+ }
192
+ const FRAME_APPLIED_EVENT = "frame:applied";
193
+ class FrameImpl {
194
+ #element;
195
+ #start;
196
+ #end;
197
+ #options;
198
+ #version;
199
+ #store = Object.create(null);
200
+ #appliedRootValue;
201
+ #hasContent = false;
202
+ #revealed = new Set();
203
+ #fallbackShown = new Set();
204
+ #slots;
205
+ #mountedSlots = new Set();
206
+ #slotCleanups = new Map();
207
+ #slotArgs = new Map();
208
+ #slotUpdaters = new Map();
209
+ #slotRegions = new Map();
210
+ #slotResolvedRefs = new Map();
211
+ #slotNodes = new Map();
212
+ #processedAssets = new Set();
213
+ #disposed = false;
214
+ #styleFlush = () => {
215
+ if (!this.#disposed) this.#flush();
216
+ };
217
+ #claimTree = (node, direct) => {
218
+ const handlers = claimHandlers();
219
+ if (!handlers) return;
220
+ const run = () => direct ? claimNode(handlers, node) : claimTree(handlers, node);
221
+ const scope = this.#options.ownerScope;
222
+ scope ? scope(run) : run();
223
+ };
224
+ constructor(element, start, end, options = {}) {
225
+ this.#element = element;
226
+ this.#start = start;
227
+ this.#end = end;
228
+ this.#options = options;
229
+ this.#slots = options.slots;
230
+ if (options.adopt) {
231
+ this.#hasContent = true;
232
+ this.#claimContent();
233
+ }
234
+ if (options.host && options.id !== undefined) {
235
+ options.host.register(options.id, this);
236
+ }
237
+ if (options.adopt && this.#version === undefined) this.#syncSlots();
238
+ }
239
+ #parent() {
240
+ return this.#element ?? this.#start.parentNode;
241
+ }
242
+ #applied(version, reason) {
243
+ this.#options.onApply?.({
244
+ version,
245
+ reason
246
+ });
247
+ const parent = this.#parent();
248
+ const Ev = parent && (parent.ownerDocument || parent).defaultView?.CustomEvent;
249
+ if (Ev) {
250
+ parent.dispatchEvent(new Ev(FRAME_APPLIED_EVENT, {
251
+ bubbles: true,
252
+ detail: {
253
+ id: this.#options.id,
254
+ version,
255
+ reason
256
+ }
257
+ }));
258
+ }
259
+ }
260
+ #firstContent() {
261
+ return this.#start ? this.#start.nextSibling : this.#parent().firstChild;
262
+ }
263
+ get version() {
264
+ return this.#version;
265
+ }
266
+ get store() {
267
+ return this.#store;
268
+ }
269
+ isRevealed(segment) {
270
+ return this.#revealed.has(segment);
271
+ }
272
+ get error() {
273
+ return this.#store[":error"];
274
+ }
275
+ apply(write) {
276
+ if (this.#disposed) return;
277
+ const v = write.version;
278
+ if (this.#version === undefined) {
279
+ this.#version = v;
280
+ } else if (v < this.#version) {
281
+ return;
282
+ } else if (v > this.#version) {
283
+ this.#version = v;
284
+ this.#revealed.clear();
285
+ this.#fallbackShown.clear();
286
+ for (const key of Object.keys(this.#store)) {
287
+ if (key.startsWith("seg:") || key === ":error") {
288
+ delete this.#store[key];
289
+ }
290
+ }
291
+ }
292
+ for (const key of Object.keys(write.r)) {
293
+ const incoming = write.r[key];
294
+ if (incoming && incoming.kind === "slot" && key.charCodeAt(0) === 115 && key.startsWith("slot:")) {
295
+ const existing = this.#store[key];
296
+ if (existing && existing.kind === "slot" && argsEquivalent(existing.args, incoming.args)) {
297
+ continue;
298
+ }
299
+ }
300
+ this.#store[key] = incoming;
301
+ }
302
+ this.#flush();
303
+ }
304
+ #flush() {
305
+ if (this.#disposed) return;
306
+ const version = this.#version;
307
+ const root = this.#store[""];
308
+ if (root && root.kind === "html" && root.value !== this.#appliedRootValue) {
309
+ const reason = this.#hasContent ? "morph" : "materialize";
310
+ this.#applyRoot(root.value);
311
+ this.#appliedRootValue = root.value;
312
+ this.#applied(version, reason);
313
+ }
314
+ let progressed = true;
315
+ while (progressed) {
316
+ progressed = false;
317
+ for (const key of Object.keys(this.#store)) {
318
+ const name = segmentName(key);
319
+ if (name === null || this.#revealed.has(name)) continue;
320
+ if (this.#segmentReady(name)) {
321
+ this.#revealSegment(name);
322
+ this.#applied(version, "reveal");
323
+ progressed = true;
324
+ }
325
+ }
326
+ for (const key of Object.keys(this.#store)) {
327
+ const m = /^seg:([^:]+):fallback$/.exec(key);
328
+ if (!m) continue;
329
+ const name = m[1];
330
+ if (this.#revealed.has(name) || this.#fallbackShown.has(name)) continue;
331
+ if (this.#showFallback(name)) {
332
+ this.#fallbackShown.add(name);
333
+ this.#applied(version, "reveal");
334
+ progressed = true;
335
+ }
336
+ }
337
+ }
338
+ for (const key of Object.keys(this.#store)) {
339
+ if (this.#processedAssets.has(key) || !key.endsWith(":assets")) continue;
340
+ this.#processedAssets.add(key);
341
+ const record = this.#store[key];
342
+ if (record && record.modules) {
343
+ for (const href of record.modules) ensureModulePreload(href);
344
+ }
345
+ }
346
+ this.#syncSlots();
347
+ }
348
+ #resolveSlot(prop) {
349
+ return this.#slots?.[prop] ?? this.#options.resolveSlot?.(prop);
350
+ }
351
+ #resolveSlotRecord(occurrence) {
352
+ const record = this.#store[`slot:${occurrence}`];
353
+ if (record !== undefined) return record;
354
+ return this.#options.resolveSlotRecord?.(occurrence);
355
+ }
356
+ #removeSlotRecord(occurrence) {
357
+ const key = `slot:${occurrence}`;
358
+ if (key in this.#store) delete this.#store[key];else this.#options.removeSlotRecord?.(occurrence);
359
+ }
360
+ #syncSlots(root) {
361
+ if (!this.#slots && !this.#options.resolveSlot) return;
362
+ const found = new Map();
363
+ if (root) collectSlots(root.firstChild, null, found);else this.#collectSlots(found);
364
+ for (const [occurrence, start] of found) {
365
+ const callback = this.#resolveSlot(propOf(occurrence));
366
+ if (!callback) continue;
367
+ const record = this.#resolveSlotRecord(occurrence);
368
+ const prev = this.#slotNodes.get(occurrence);
369
+ const prevFirst = Array.isArray(prev) ? prev[0] : prev;
370
+ const zombie = this.#mountedSlots.has(occurrence) && prevFirst && !prevFirst.parentNode;
371
+ if (zombie) {
372
+ this.#mountedSlots.delete(occurrence);
373
+ this.#runSlotCleanups(occurrence);
374
+ }
375
+ if (!this.#mountedSlots.has(occurrence)) {
376
+ if (this.#options.adopt) this.#discoverRegions(occurrence, start);
377
+ const nodes = this.#invokeSlot(occurrence, callback, record, start, this.#options.adopt);
378
+ if (nodes) this.#replaceRange(occurrence, start, nodes);
379
+ this.#slotNodes.set(occurrence, nodes);
380
+ this.#mountedSlots.add(occurrence);
381
+ if (!this.#options.adopt || nodes) this.#discoverRegions(occurrence, start);
382
+ this.#bindRegions(occurrence);
383
+ } else if (record !== this.#slotArgs.get(occurrence)) {
384
+ if (this.#refArgsUnchanged(occurrence, record)) {
385
+ this.#slotArgs.set(occurrence, record);
386
+ this.#reconcileRegions(occurrence, record);
387
+ continue;
388
+ }
389
+ const update = this.#slotUpdaters.get(occurrence);
390
+ if (update) {
391
+ const props = this.#resolveArgs(occurrence, record.args);
392
+ const regions = this.#slotRegions.get(occurrence);
393
+ if (regions) {
394
+ for (const [argKey, entry] of regions) {
395
+ if (!(argKey in props)) props[argKey] = entry.element;
396
+ }
397
+ }
398
+ this.#slotArgs.set(occurrence, record);
399
+ update(props);
400
+ this.#bindRegions(occurrence);
401
+ continue;
402
+ }
403
+ const nodes = this.#invokeSlot(occurrence, callback, record, start);
404
+ if (nodes) this.#replaceRange(occurrence, start, nodes);
405
+ this.#slotNodes.set(occurrence, nodes);
406
+ this.#bindRegions(occurrence);
407
+ }
408
+ }
409
+ if (!root) {
410
+ for (const occurrence of [...this.#mountedSlots]) {
411
+ if (!found.has(occurrence)) this.#unmountSlot(occurrence);
412
+ }
413
+ }
414
+ }
415
+ #invokeSlot(occurrence, callback, record, start, adopted) {
416
+ this.#slotUpdaters.delete(occurrence);
417
+ const cleanups = this.#slotCleanups.get(occurrence) ?? [];
418
+ let existing = [];
419
+ let end = null;
420
+ if (start) {
421
+ const endData = slotEnd(occurrence);
422
+ let n = start.nextSibling;
423
+ while (n && !(n.nodeType === COMMENT_NODE && n.data === endData)) {
424
+ existing.push(n);
425
+ n = n.nextSibling;
426
+ }
427
+ end = n;
428
+ }
429
+ const ctx = {
430
+ frame: this.#options.claimScope ?? this.#options.id,
431
+ key: occurrence,
432
+ adopted: !!adopted,
433
+ invoked: !!(record && record.kind === "slot"),
434
+ onCleanup: fn => cleanups.push(fn),
435
+ onUpdate: fn => this.#slotUpdaters.set(occurrence, fn),
436
+ existing,
437
+ range: end ? {
438
+ start,
439
+ end
440
+ } : undefined
441
+ };
442
+ const props = record && record.kind === "slot" ? this.#resolveArgs(occurrence, record.args) : {};
443
+ const regions = this.#slotRegions.get(occurrence);
444
+ if (regions) {
445
+ for (const [argKey, entry] of regions) {
446
+ if (!(argKey in props)) props[argKey] = entry.element;
447
+ }
448
+ }
449
+ const scope = this.#options.ownerScope;
450
+ const content = scope ? scope(() => callback(props, ctx)) : callback(props, ctx);
451
+ this.#slotArgs.set(occurrence, record);
452
+ if (cleanups.length) this.#slotCleanups.set(occurrence, cleanups);
453
+ if (content == null) return null;
454
+ return Array.isArray(content) ? content : [content];
455
+ }
456
+ #replaceRange(key, start, nodes) {
457
+ const end = slotEnd(key);
458
+ const parent = start.parentNode;
459
+ let n = start.nextSibling;
460
+ while (n && !(n.nodeType === COMMENT_NODE && n.data === end)) {
461
+ const next = n.nextSibling;
462
+ parent.removeChild(n);
463
+ n = next;
464
+ }
465
+ for (const node of nodes) parent.insertBefore(node, n);
466
+ }
467
+ #unmountSlot(key) {
468
+ this.#mountedSlots.delete(key);
469
+ this.#slotNodes.delete(key);
470
+ this.#slotArgs.delete(key);
471
+ this.#slotUpdaters.delete(key);
472
+ this.#slotResolvedRefs.delete(key);
473
+ this.#removeSlotRecord(key);
474
+ this.#runSlotCleanups(key);
475
+ const regions = this.#slotRegions.get(key);
476
+ if (regions) {
477
+ for (const {
478
+ frame
479
+ } of regions.values()) frame?.dispose();
480
+ this.#slotRegions.delete(key);
481
+ }
482
+ }
483
+ #runSlotCleanups(key) {
484
+ const cleanups = this.#slotCleanups.get(key);
485
+ if (!cleanups) return;
486
+ this.#slotCleanups.delete(key);
487
+ for (const fn of cleanups) fn();
488
+ }
489
+ #resolveArgs(slotKey, args) {
490
+ const host = this.#options.host;
491
+ let regions = this.#slotRegions.get(slotKey);
492
+ if (!regions) {
493
+ regions = new Map();
494
+ this.#slotRegions.set(slotKey, regions);
495
+ }
496
+ const props = {};
497
+ for (const key of Object.keys(args)) {
498
+ const value = args[key];
499
+ if (isDataRef(value)) {
500
+ const resolved = host ? host.resolve(value, this.#options.id) : undefined;
501
+ let cache = this.#slotResolvedRefs.get(slotKey);
502
+ if (!cache) this.#slotResolvedRefs.set(slotKey, cache = {});
503
+ cache[key] = resolved;
504
+ props[key] = resolved;
505
+ } else if (isFrameRef(value)) {
506
+ let entry = regions.get(key);
507
+ if (!entry) {
508
+ const element = makeFrameElement(value.$frame);
509
+ entry = {
510
+ childId: value.$frame,
511
+ element,
512
+ frame: undefined
513
+ };
514
+ regions.set(key, entry);
515
+ } else if (entry.childId !== value.$frame) {
516
+ renameRegion(entry, value.$frame);
517
+ }
518
+ props[key] = entry.element;
519
+ } else {
520
+ props[key] = value;
521
+ }
522
+ }
523
+ return props;
524
+ }
525
+ #discoverRegions(slotKey, start) {
526
+ if (!start) return;
527
+ let regions = this.#slotRegions.get(slotKey);
528
+ if (!regions) {
529
+ regions = new Map();
530
+ this.#slotRegions.set(slotKey, regions);
531
+ }
532
+ const endData = slotEnd(slotKey);
533
+ const prefix = `${this.#options.id}.`;
534
+ let n = start.nextSibling;
535
+ while (n && !(n.nodeType === COMMENT_NODE && n.data === endData)) {
536
+ collectRegionElements(n, regions, prefix);
537
+ n = n.nextSibling;
538
+ }
539
+ }
540
+ #refArgsUnchanged(occurrence, record) {
541
+ const old = this.#slotArgs.get(occurrence);
542
+ if (!record || record.kind !== "slot") return false;
543
+ if (old && old.kind !== "slot") return false;
544
+ const a = old && old.args || {};
545
+ const b = record.args || {};
546
+ const ka = Object.keys(a);
547
+ const kb = Object.keys(b);
548
+ if (kb.length < ka.length) return false;
549
+ if (kb.length !== ka.length) {
550
+ const regions = this.#slotRegions.get(occurrence);
551
+ for (const key of kb) {
552
+ if (key in a) continue;
553
+ const vb = b[key];
554
+ if (!vb || typeof vb !== "object" || typeof vb.$frame !== "string") return false;
555
+ if (!regions || !regions.has(key)) return false;
556
+ }
557
+ }
558
+ const cache = this.#slotResolvedRefs.get(occurrence);
559
+ for (const key of ka) {
560
+ const va = a[key];
561
+ const vb = b[key];
562
+ if (va === vb) continue;
563
+ if (!va || !vb || typeof va !== "object" || typeof vb !== "object") return false;
564
+ if (typeof va.$frame === "string" && typeof vb.$frame === "string") continue;
565
+ if (typeof va.$ref === "string" && typeof vb.$ref === "string" && cache && key in cache) {
566
+ const host = this.#options.host;
567
+ const next = host ? host.resolve(vb, this.#options.id) : undefined;
568
+ try {
569
+ if (JSON.stringify(next) === JSON.stringify(cache[key])) continue;
570
+ } catch (e) {
571
+ return false;
572
+ }
573
+ }
574
+ return false;
575
+ }
576
+ return true;
577
+ }
578
+ #reconcileRegions(occurrence, record) {
579
+ const args = record && record.args;
580
+ if (!args) return;
581
+ const regions = this.#slotRegions.get(occurrence);
582
+ if (!regions) return;
583
+ for (const key of Object.keys(args)) {
584
+ const value = args[key];
585
+ if (!isFrameRef(value)) continue;
586
+ const entry = regions.get(key);
587
+ if (entry && entry.childId !== value.$frame) renameRegion(entry, value.$frame);
588
+ }
589
+ }
590
+ #bindRegions(slotKey) {
591
+ const regions = this.#slotRegions.get(slotKey);
592
+ if (!regions) return;
593
+ for (const entry of regions.values()) {
594
+ if (!entry.frame) {
595
+ entry.frame = new FrameImpl(entry.element, null, null, {
596
+ id: entry.childId,
597
+ host: this.#options.host,
598
+ adopt: entry.adopt,
599
+ claimScope: this.#options.claimScope ?? this.#options.id,
600
+ ownerScope: this.#options.ownerScope,
601
+ resolveSlot: prop => this.#resolveSlot(prop),
602
+ resolveSlotRecord: occurrence => this.#resolveSlotRecord(occurrence),
603
+ removeSlotRecord: occurrence => this.#removeSlotRecord(occurrence)
604
+ });
605
+ }
606
+ }
607
+ }
608
+ #collectSlots(found) {
609
+ collectSlots(this.#firstContent(), this.#end, found);
610
+ }
611
+ #findPlaceholder(name) {
612
+ return findPlaceholder(this.#firstContent(), this.#end, placeholderId(name));
613
+ }
614
+ snapshot() {
615
+ if (this.#disposed) return null;
616
+ const records = {
617
+ ...this.#store
618
+ };
619
+ if (!records[""] && this.#element && this.#hasContent) {
620
+ records[""] = {
621
+ kind: "html",
622
+ value: this.#element.innerHTML
623
+ };
624
+ }
625
+ if (!records[""] && this.#version === undefined) return null;
626
+ return {
627
+ version: this.#version ?? 0,
628
+ records
629
+ };
630
+ }
631
+ rebind(id) {
632
+ if (this.#disposed || id === this.#options.id) return;
633
+ const {
634
+ host,
635
+ id: oldId
636
+ } = this.#options;
637
+ if (host && oldId !== undefined) host.unregister(oldId, this);
638
+ this.#options = {
639
+ ...this.#options,
640
+ id
641
+ };
642
+ if (this.#element && this.#element.nodeType === ELEMENT_NODE) {
643
+ this.#element.setAttribute(FRAME_ID_ATTR, id);
644
+ }
645
+ this.#version = undefined;
646
+ this.#revealed.clear();
647
+ this.#fallbackShown.clear();
648
+ for (const key of Object.keys(this.#store)) {
649
+ if (key.startsWith("seg:") || key === ":error") delete this.#store[key];
650
+ }
651
+ if (host) host.register(id, this);
652
+ }
653
+ rebase() {
654
+ this.#version = undefined;
655
+ }
656
+ dispose() {
657
+ if (this.#disposed) return;
658
+ const {
659
+ host,
660
+ id
661
+ } = this.#options;
662
+ if (host && id !== undefined) host.unregister(id, this);
663
+ this.#disposed = true;
664
+ for (const key of [...this.#slotCleanups.keys()]) this.#runSlotCleanups(key);
665
+ for (const key of this.#mountedSlots) this.#removeSlotRecord(key);
666
+ for (const regions of this.#slotRegions.values()) {
667
+ for (const {
668
+ frame
669
+ } of regions.values()) frame?.dispose();
670
+ }
671
+ this.#slotRegions.clear();
672
+ this.#mountedSlots.clear();
673
+ }
674
+ #applyRoot(html) {
675
+ const fragment = parseFragment(html);
676
+ const parent = this.#parent();
677
+ if (!this.#hasContent) {
678
+ this.#clearContent();
679
+ this.#claimTree(fragment);
680
+ parent.insertBefore(fragment, this.#end);
681
+ this.#hasContent = true;
682
+ } else {
683
+ const claim = claimHandlers() ? this.#claimTree : null;
684
+ const ranges = new Map();
685
+ this.#collectSlots(ranges);
686
+ reconcileChildren(parent, fragment, this.#start, this.#end, claim, ranges);
687
+ if (ranges.size) restoreDisplacedRanges(this.#firstContent(), this.#end, ranges);
688
+ }
689
+ }
690
+ #clearContent() {
691
+ const parent = this.#parent();
692
+ let n = this.#firstContent();
693
+ while (n && n !== this.#end) {
694
+ const next = n.nextSibling;
695
+ parent.removeChild(n);
696
+ n = next;
697
+ }
698
+ }
699
+ #claimContent() {
700
+ if (!claimHandlers()) return;
701
+ let n = this.#firstContent();
702
+ while (n && n !== this.#end) {
703
+ this.#claimTree(n);
704
+ n = n.nextSibling;
705
+ }
706
+ }
707
+ #segmentReady(name) {
708
+ const content = this.#store[`seg:${name}`];
709
+ if (!content || content.kind !== "html") return false;
710
+ if (!this.#store[`seg:${name}:reveal`]) return false;
711
+ const assets = this.#store[`seg:${name}:assets`];
712
+ if (assets && assets.styles) {
713
+ let ready = true;
714
+ for (const entry of assets.styles) {
715
+ if (!ensureStylesheet(entry, this.#styleFlush)) ready = false;
716
+ }
717
+ if (!ready) return false;
718
+ }
719
+ if (!this.#findPlaceholder(name)) return false;
720
+ return true;
721
+ }
722
+ #revealSegment(name) {
723
+ const tpl = this.#findPlaceholder(name);
724
+ if (!tpl) return;
725
+ const assets = this.#store[`seg:${name}:assets`];
726
+ if (assets && assets.inlineStyles) applyInlineStyles(assets.inlineStyles);
727
+ const content = this.#store[`seg:${name}`];
728
+ const closing = rangeClose(tpl, placeholderId(name));
729
+ if (!closing) {
730
+ console.error(`Frame fragment placeholder "${name}" is missing its closing comment ` + `(<!--${placeholderId(name)}-->); revealed content will be appended at the end of ` + `its parent instead of in place. Likely an HTML-rewriting layer stripped the ` + `comment, or invalid nesting split the placeholder range.`, tpl);
731
+ }
732
+ const parent = tpl.parentNode;
733
+ let n = tpl.nextSibling;
734
+ while (n && n !== closing) {
735
+ const next = n.nextSibling;
736
+ parent.removeChild(n);
737
+ n = next;
738
+ }
739
+ if (this.#options.reveal) {
740
+ const fallbackFrag = tpl.content.cloneNode(true);
741
+ this.#claimTree(fallbackFrag);
742
+ this.#options.reveal({
743
+ before: closing,
744
+ fallback: [...fallbackFrag.childNodes],
745
+ content: () => {
746
+ const materialized = this.#materialize(content);
747
+ this.#syncSlots(materialized);
748
+ this.#claimTree(materialized);
749
+ return materialized;
750
+ }
751
+ });
752
+ tpl.remove();
753
+ this.#revealed.add(name);
754
+ return;
755
+ }
756
+ const materialized = this.#materialize(content);
757
+ this.#claimTree(materialized);
758
+ parent.insertBefore(materialized, closing);
759
+ tpl.remove();
760
+ closing && closing.remove();
761
+ this.#revealed.add(name);
762
+ }
763
+ #showFallback(name) {
764
+ const tpl = this.#findPlaceholder(name);
765
+ if (!tpl) return false;
766
+ const closing = rangeClose(tpl, placeholderId(name));
767
+ if (!closing) return false;
768
+ const fallback = tpl.content.cloneNode(true);
769
+ this.#claimTree(fallback);
770
+ closing.parentNode.insertBefore(fallback, closing);
771
+ return true;
772
+ }
773
+ #materialize(record) {
774
+ return record.kind === "html" ? parseFragment(record.value) : parseFragment("");
775
+ }
776
+ }
777
+ function createFrame(boundary, options) {
778
+ return new FrameImpl(boundary, null, null, options);
779
+ }
780
+ const FRAME_TAG = "dx-frame";
781
+ const FRAME_ID_ATTR = "data-fid";
782
+ function createFrameElement(options) {
783
+ const el = makeFrameElement(options.id);
784
+ const frame = new FrameImpl(el, null, null, options);
785
+ return {
786
+ element: el,
787
+ get frame() {
788
+ return frame;
789
+ },
790
+ dispose() {
791
+ frame.dispose();
792
+ el.remove();
793
+ }
794
+ };
795
+ }
796
+ function makeFrameElement(id) {
797
+ const el = document.createElement(FRAME_TAG);
798
+ el.style.display = "contents";
799
+ if (id !== undefined) el.setAttribute(FRAME_ID_ATTR, id);
800
+ return el;
801
+ }
802
+ function isFrameElement(node) {
803
+ return node.nodeType === ELEMENT_NODE && node.hasAttribute(FRAME_ID_ATTR);
804
+ }
805
+ function segmentName(key) {
806
+ const m = /^seg:([^:]+)$/.exec(key);
807
+ return m ? m[1] : null;
808
+ }
809
+ function propOf(occurrence) {
810
+ const hash = occurrence.indexOf("#");
811
+ return hash === -1 ? occurrence : occurrence.slice(0, hash);
812
+ }
813
+ function isDataRef(value) {
814
+ return typeof value === "object" && value !== null && typeof value.$ref === "string";
815
+ }
816
+ function isFrameRef(value) {
817
+ return typeof value === "object" && value !== null && typeof value.$frame === "string";
818
+ }
819
+ function parseFragment(html) {
820
+ const template = document.createElement("template");
821
+ template.innerHTML = html;
822
+ return template.content;
823
+ }
824
+ function findHeadElement(selector, attr, value) {
825
+ const nodes = document.head.querySelectorAll(selector);
826
+ for (let i = 0; i < nodes.length; i++) {
827
+ if (nodes[i].getAttribute(attr) === value) return nodes[i];
828
+ }
829
+ return null;
830
+ }
831
+ function ensureStylesheet(entry, onSettle) {
832
+ const href = typeof entry === "string" ? entry : entry.href;
833
+ let link = findHeadElement('link[rel="stylesheet"]', "href", href);
834
+ if (!link) {
835
+ link = document.createElement("link");
836
+ link.rel = "stylesheet";
837
+ if (typeof entry !== "string" && entry.attrs) {
838
+ for (const name in entry.attrs) link.setAttribute(name, entry.attrs[name]);
839
+ }
840
+ link.href = href;
841
+ const waiters = new Set();
842
+ link._$frWaiters = waiters;
843
+ const settle = () => {
844
+ link._$frWaiters = null;
845
+ for (const fn of waiters) fn();
846
+ };
847
+ link.addEventListener("load", settle);
848
+ link.addEventListener("error", settle);
849
+ document.head.appendChild(link);
850
+ }
851
+ const waiters = link._$frWaiters;
852
+ if (waiters == null) return true;
853
+ waiters.add(onSettle);
854
+ return false;
855
+ }
856
+ function ensureModulePreload(href) {
857
+ if (findHeadElement('link[rel="modulepreload"]', "href", href)) return;
858
+ const link = document.createElement("link");
859
+ link.rel = "modulepreload";
860
+ link.href = href;
861
+ document.head.appendChild(link);
862
+ }
863
+ function applyInlineStyles(inlineStyles) {
864
+ for (const entry of inlineStyles) {
865
+ if (findHeadElement("style[data-asset]", "data-asset", entry.id)) continue;
866
+ const el = document.createElement("style");
867
+ el.setAttribute("data-asset", entry.id);
868
+ if (entry.attrs) {
869
+ for (const name in entry.attrs) el.setAttribute(name, entry.attrs[name]);
870
+ }
871
+ el.textContent = entry.content || "";
872
+ document.head.appendChild(el);
873
+ }
874
+ }
875
+ function isPlaceholderStart(node, id) {
876
+ return node.nodeType === ELEMENT_NODE && node.tagName === "TEMPLATE" && node.getAttribute("id") === id;
877
+ }
878
+ function rangeClose(start, id) {
879
+ let n = start.nextSibling;
880
+ while (n) {
881
+ if (n.nodeType === COMMENT_NODE && n.data === id) return n;
882
+ n = n.nextSibling;
883
+ }
884
+ return null;
885
+ }
886
+ function findPlaceholder(n, end, id) {
887
+ while (n && n !== end) {
888
+ if (isPlaceholderStart(n, id)) return n;
889
+ if (n.nodeType === ELEMENT_NODE) {
890
+ const found = findPlaceholder(n.firstChild, null, id);
891
+ if (found) return found;
892
+ }
893
+ n = n.nextSibling;
894
+ }
895
+ return null;
896
+ }
897
+ function collectSlots(n, end, out) {
898
+ while (n && n !== end) {
899
+ const id = slotStartId(n);
900
+ if (id !== null) {
901
+ devCheckRange(n, id);
902
+ if (!out.has(id)) out.set(id, n);
903
+ n = afterRange(n, id);
904
+ continue;
905
+ }
906
+ if (n.nodeType === ELEMENT_NODE && !isFrameElement(n)) collectSlots(n.firstChild, null, out);
907
+ n = n.nextSibling;
908
+ }
909
+ }
910
+ function collectRegionElements(node, regions, prefix) {
911
+ if (node.nodeType !== ELEMENT_NODE) return;
912
+ if (isFrameElement(node)) {
913
+ const childId = node.getAttribute(FRAME_ID_ATTR);
914
+ if (childId && childId.startsWith(prefix)) {
915
+ const argKey = childId.slice(childId.lastIndexOf(".") + 1);
916
+ if (!regions.has(argKey)) {
917
+ regions.set(argKey, {
918
+ childId,
919
+ element: node,
920
+ frame: undefined,
921
+ adopt: true
922
+ });
923
+ }
924
+ }
925
+ return;
926
+ }
927
+ for (let c = node.firstChild; c; c = c.nextSibling) collectRegionElements(c, regions, prefix);
928
+ }
929
+ function renameRegion(entry, childId) {
930
+ entry.childId = childId;
931
+ if (entry.frame) entry.frame.rebind(childId);else entry.element.setAttribute(FRAME_ID_ATTR, childId);
932
+ }
933
+ function argsEquivalent(a, b) {
934
+ if (a === b) return true;
935
+ if (!a || !b) return false;
936
+ const ka = Object.keys(a);
937
+ const kb = Object.keys(b);
938
+ if (ka.length !== kb.length) return false;
939
+ for (const key of ka) {
940
+ const va = a[key];
941
+ const vb = b[key];
942
+ if (va === vb) continue;
943
+ if (va && vb && typeof va === "object" && typeof vb === "object" && typeof va.$frame === "string" && va.$frame === vb.$frame) {
944
+ continue;
945
+ }
946
+ return false;
947
+ }
948
+ return true;
949
+ }
950
+ function slotStartId(node) {
951
+ if (node.nodeType !== COMMENT_NODE) return null;
952
+ const m = SLOT_START.exec(node.data);
953
+ return m ? m[1] : null;
954
+ }
955
+ function isSlotMarker(node) {
956
+ if (node.nodeType !== COMMENT_NODE) return false;
957
+ const data = node.data;
958
+ return SLOT_START.test(data) || SLOT_END.test(data);
959
+ }
960
+ function compatible(a, b) {
961
+ if (a.nodeType !== b.nodeType) return false;
962
+ if (a.nodeType === ELEMENT_NODE) return a.nodeName === b.nodeName;
963
+ return a.nodeType === TEXT_NODE || a.nodeType === COMMENT_NODE;
964
+ }
965
+ function preservesOpen(el) {
966
+ const t = el.tagName;
967
+ return t === "DETAILS" || t === "DIALOG";
968
+ }
969
+ function morphAttributes(oldEl, newEl, claim) {
970
+ let reclaim = false;
971
+ let changed = false;
972
+ const keepOpen = preservesOpen(oldEl);
973
+ const oldAttrs = oldEl.attributes;
974
+ for (let i = oldAttrs.length - 1; i >= 0; i--) {
975
+ const name = oldAttrs[i].name;
976
+ if (keepOpen && name === "open") continue;
977
+ if (!newEl.hasAttribute(name)) {
978
+ oldEl.removeAttribute(name);
979
+ changed = true;
980
+ reclaim ||= claimedAttr(name);
981
+ }
982
+ }
983
+ const newAttrs = newEl.attributes;
984
+ for (let i = 0; i < newAttrs.length; i++) {
985
+ const attr = newAttrs[i];
986
+ if (keepOpen && attr.name === "open") continue;
987
+ if (oldEl.getAttribute(attr.name) !== attr.value) {
988
+ oldEl.setAttribute(attr.name, attr.value);
989
+ changed = true;
990
+ reclaim ||= claimedAttr(attr.name);
991
+ }
992
+ }
993
+ if (claim && (reclaim || changed && oldEl.matches(CLAIMED_ELEMENTS))) claim(oldEl, true);
994
+ }
995
+ function morphNode(oldNode, newNode, claim, ranges) {
996
+ if (oldNode.nodeType === ELEMENT_NODE) {
997
+ if (oldNode.hasAttribute("data-preserve")) return;
998
+ morphAttributes(oldNode, newNode, claim);
999
+ reconcileChildren(oldNode, newNode, null, null, claim, ranges);
1000
+ } else if (oldNode.data !== newNode.data) {
1001
+ oldNode.data = newNode.data;
1002
+ }
1003
+ }
1004
+ function afterRange(start, id) {
1005
+ const end = slotEnd(id);
1006
+ let n = start.nextSibling;
1007
+ while (n) {
1008
+ if (n.nodeType === COMMENT_NODE && n.data === end) return n.nextSibling;
1009
+ n = n.nextSibling;
1010
+ }
1011
+ return null;
1012
+ }
1013
+ function devCheckRange(start, id) {
1014
+ const end = slotEnd(id);
1015
+ let n = start.nextSibling;
1016
+ while (n) {
1017
+ if (n.nodeType === COMMENT_NODE && n.data === end) return;
1018
+ n = n.nextSibling;
1019
+ }
1020
+ console.error(`Frame slot range "${id}" is missing its end marker (<!--${end}-->) among its start ` + `marker's siblings. Slots after it in this content cannot be discovered. Likely causes: ` + `invalid HTML nesting split the range during parsing (e.g. a block element inside <p>), ` + `or an HTML-rewriting layer (CDN/minifier/translator) removed or moved the comment — ` + `serve frame documents with Cache-Control: no-transform.`, start);
1021
+ }
1022
+ function findRangeStart(from, id, bound) {
1023
+ const target = `slot:${id}:start`;
1024
+ let n = from;
1025
+ while (n && n !== bound) {
1026
+ if (n.nodeType === COMMENT_NODE && n.data === target) return n;
1027
+ n = n.nextSibling;
1028
+ }
1029
+ return null;
1030
+ }
1031
+ function moveRangeBefore(parent, start, id, ref) {
1032
+ const end = slotEnd(id);
1033
+ let n = start;
1034
+ while (n) {
1035
+ const next = n.nextSibling;
1036
+ const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
1037
+ parent.insertBefore(n, ref);
1038
+ if (isEnd) break;
1039
+ n = next;
1040
+ }
1041
+ }
1042
+ function adoptRange(parent, start, id, ref, claim) {
1043
+ const end = slotEnd(id);
1044
+ let n = start;
1045
+ let after = null;
1046
+ while (n) {
1047
+ const next = n.nextSibling;
1048
+ const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
1049
+ parent.insertBefore(n, ref);
1050
+ if (claim) claim(n);
1051
+ if (isEnd) {
1052
+ after = next;
1053
+ break;
1054
+ }
1055
+ n = next;
1056
+ }
1057
+ return after;
1058
+ }
1059
+ function reconcileChildren(parent, source, boundStart = null, boundEnd = null, claim = null, ranges = null) {
1060
+ let oldChild = boundStart ? boundStart.nextSibling : parent.firstChild;
1061
+ let newChild = source.firstChild;
1062
+ while (newChild) {
1063
+ const nextNew = newChild.nextSibling;
1064
+ const pid = slotStartId(newChild);
1065
+ const old = oldChild === boundEnd ? null : oldChild;
1066
+ if (pid !== null) {
1067
+ if (old && slotStartId(old) === pid) {
1068
+ oldChild = afterRange(old, pid);
1069
+ newChild = afterRange(newChild, pid);
1070
+ } else {
1071
+ const displaced = ranges && ranges.get(pid);
1072
+ const existing = displaced || findRangeStart(old, pid, boundEnd);
1073
+ if (existing) {
1074
+ if (ranges) ranges.delete(pid);
1075
+ if (existing.nodeType === 11 ) {
1076
+ parent.insertBefore(existing, old ?? boundEnd);
1077
+ } else {
1078
+ moveRangeBefore(parent, existing, pid, old ?? boundEnd);
1079
+ }
1080
+ newChild = afterRange(newChild, pid);
1081
+ } else {
1082
+ newChild = adoptRange(parent, newChild, pid, old ?? boundEnd, claim);
1083
+ }
1084
+ }
1085
+ continue;
1086
+ }
1087
+ if (!old) {
1088
+ parent.insertBefore(newChild, boundEnd);
1089
+ if (claim) claim(newChild);
1090
+ newChild = nextNew;
1091
+ continue;
1092
+ }
1093
+ if (isSlotMarker(old)) {
1094
+ parent.insertBefore(newChild, old);
1095
+ if (claim) claim(newChild);
1096
+ newChild = nextNew;
1097
+ continue;
1098
+ }
1099
+ if (compatible(old, newChild)) {
1100
+ morphNode(old, newChild, claim, ranges);
1101
+ oldChild = old.nextSibling;
1102
+ newChild = nextNew;
1103
+ continue;
1104
+ }
1105
+ if (newChild.nodeType === 1) {
1106
+ let ahead = old.nextSibling;
1107
+ while (ahead && ahead !== boundEnd && !compatible(ahead, newChild)) {
1108
+ const aheadPid = slotStartId(ahead);
1109
+ ahead = aheadPid !== null ? afterRange(ahead, aheadPid) : ahead.nextSibling;
1110
+ }
1111
+ if (ahead && ahead !== boundEnd) {
1112
+ parent.insertBefore(ahead, old);
1113
+ morphNode(ahead, newChild, claim, ranges);
1114
+ newChild = nextNew;
1115
+ continue;
1116
+ }
1117
+ }
1118
+ parent.insertBefore(newChild, old);
1119
+ if (claim) claim(newChild);
1120
+ newChild = nextNew;
1121
+ }
1122
+ while (oldChild && oldChild !== boundEnd) {
1123
+ const next = oldChild.nextSibling;
1124
+ const pid = ranges ? slotStartId(oldChild) : null;
1125
+ if (pid !== null && ranges.get(pid) === oldChild) {
1126
+ const frag = document.createDocumentFragment();
1127
+ const after = stashRange(frag, oldChild, pid);
1128
+ ranges.set(pid, frag);
1129
+ oldChild = after;
1130
+ continue;
1131
+ }
1132
+ parent.removeChild(oldChild);
1133
+ oldChild = next;
1134
+ }
1135
+ }
1136
+ function restoreDisplacedRanges(first, end, ranges) {
1137
+ const found = new Map();
1138
+ collectSlots(first, end, found);
1139
+ for (const [id, start] of found) {
1140
+ const displaced = ranges.get(id);
1141
+ if (!displaced || displaced === start) continue;
1142
+ ranges.delete(id);
1143
+ const parent = start.parentNode;
1144
+ if (displaced.nodeType === 11 ) {
1145
+ parent.insertBefore(displaced, start);
1146
+ } else {
1147
+ moveRangeBefore(parent, displaced, id, start);
1148
+ }
1149
+ stashRange(document.createDocumentFragment(), start, id);
1150
+ }
1151
+ }
1152
+ function stashRange(frag, start, id) {
1153
+ const end = slotEnd(id);
1154
+ let n = start;
1155
+ while (n) {
1156
+ const next = n.nextSibling;
1157
+ const isEnd = n.nodeType === COMMENT_NODE && n.data === end;
1158
+ frag.appendChild(n);
1159
+ if (isEnd) return next;
1160
+ n = next;
1161
+ }
1162
+ return null;
1163
+ }
1164
+
1165
+ const FRAME_STREAM_HEADER = "X-Frame-Stream";
1166
+ function isFrameStreamResponse(response) {
1167
+ return response.headers.has(FRAME_STREAM_HEADER);
1168
+ }
1169
+ async function applyFrameResponse(response, host, options = {}) {
1170
+ const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
1171
+ const as = options.as;
1172
+ const version = options.version;
1173
+ const perFrame = typeof version === "function" ? new Map() : null;
1174
+ const reader = new client.ChunkReader(response.body);
1175
+ let result = await reader.next();
1176
+ while (!result.done) {
1177
+ const chunk = JSON.parse(result.value);
1178
+ if (chunk.type === "outcome") {
1179
+ if (options.onOutcome) options.onOutcome(chunk.payload);
1180
+ } else {
1181
+ if (as !== undefined && chunk.id === rootId) chunk.id = as;else if (options.route) chunk.id = options.route(chunk.id);
1182
+ if (perFrame) {
1183
+ let v = perFrame.get(chunk.id);
1184
+ if (v === undefined) perFrame.set(chunk.id, v = version(chunk.id));
1185
+ chunk.version = v;
1186
+ } else if (version !== undefined) chunk.version = version;
1187
+ host.apply(chunk);
1188
+ }
1189
+ result = await reader.next();
1190
+ }
1191
+ return as !== undefined ? as : rootId;
1192
+ }
1193
+ const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("dom-expressions.server-component");
1194
+ const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("dom-expressions.server-component-address");
1195
+ const COMPONENT_HANDOFF = /*#__PURE__*/Symbol.for("dom-expressions.component-handoff");
1196
+ let resolveServerComponent;
1197
+ function parseServerComponent(value, ctx) {
1198
+ return {
1199
+ id: ctx.parse(value[SERVER_COMPONENT]),
1200
+ address: ctx.parse(value[SERVER_COMPONENT_ADDRESS])
1201
+ };
1202
+ }
1203
+ const ServerComponentPlugin = /*#__PURE__*/seroval.createPlugin({
1204
+ tag: "dom-expressions/server-component",
1205
+ test(value) {
1206
+ return typeof value === "function" && SERVER_COMPONENT in value;
1207
+ },
1208
+ parse: {
1209
+ sync: parseServerComponent,
1210
+ async async(value, ctx) {
1211
+ return {
1212
+ id: await ctx.parse(value[SERVER_COMPONENT]),
1213
+ address: await ctx.parse(value[SERVER_COMPONENT_ADDRESS])
1214
+ };
1215
+ },
1216
+ stream: parseServerComponent
1217
+ },
1218
+ serialize(node, ctx) {
1219
+ return "self._$SC.r(" + ctx.serialize(node.id) + "," + ctx.serialize(node.address) + ")";
1220
+ },
1221
+ deserialize(node, ctx) {
1222
+ const id = ctx.deserialize(node.id);
1223
+ const address = ctx.deserialize(node.address);
1224
+ if (address !== undefined && resolveServerComponent) {
1225
+ return resolveServerComponent(id, address);
1226
+ }
1227
+ return globalThis._$SC.r(id);
1228
+ }
1229
+ });
1230
+ function flightCodec(codec) {
1231
+ const plugins = codec && codec.plugins || [];
1232
+ for (const plugin of plugins) {
1233
+ if (plugin && plugin.tag === "dom-expressions/server-component") return codec;
1234
+ }
1235
+ return {
1236
+ ...codec,
1237
+ plugins: [...plugins, ServerComponentPlugin]
1238
+ };
1239
+ }
1240
+ function createServerComponentHandler({
1241
+ host,
1242
+ component,
1243
+ onStream,
1244
+ documentComponent,
1245
+ intercept,
1246
+ consumer = client.getFlightDataConsumer,
1247
+ codec = client.getServerFunctionsCodec
1248
+ }) {
1249
+ const byAddress = new Map();
1250
+ const forwards = new Map();
1251
+ const brand = (comp, fnId, frameId) => {
1252
+ const brandable = typeof comp === "function" || typeof comp === "object" && comp !== null;
1253
+ if (brandable && !comp[COMPONENT_HANDOFF]) {
1254
+ comp[COMPONENT_HANDOFF] = {
1255
+ fnId,
1256
+ frameId,
1257
+ take(prev) {
1258
+ const meta = prev !== null && (typeof prev === "function" || typeof prev === "object") && prev[COMPONENT_HANDOFF];
1259
+ if (!meta || meta.fnId !== fnId) return false;
1260
+ const root = meta.frameId;
1261
+ let cur = forwards.get(root) ?? root;
1262
+ if (cur !== root && !host.get(cur)) {
1263
+ forwards.delete(root);
1264
+ cur = root;
1265
+ }
1266
+ if (cur === frameId) return true;
1267
+ let frame = host.get(cur);
1268
+ if (!frame) return false;
1269
+ while (frame) {
1270
+ frame.rebind(frameId);
1271
+ frame = host.get(cur);
1272
+ }
1273
+ if (frameId === root) forwards.delete(root);else forwards.set(root, frameId);
1274
+ return true;
1275
+ }
1276
+ };
1277
+ }
1278
+ return comp;
1279
+ };
1280
+ const boundaryFor = (address, fnId) => {
1281
+ let entry = byAddress.get(address);
1282
+ if (!entry) {
1283
+ entry = {
1284
+ frameId: address,
1285
+ component: brand(component(address), fnId, address)
1286
+ };
1287
+ byAddress.set(address, entry);
1288
+ }
1289
+ return entry;
1290
+ };
1291
+ const resolveAddress = (id, address) => boundaryFor(address, id).component;
1292
+ resolveServerComponent = resolveAddress;
1293
+ const versions = new Map();
1294
+ const bump = frameId => {
1295
+ const version = (versions.get(frameId) || 0) + 1;
1296
+ versions.set(frameId, version);
1297
+ return version;
1298
+ };
1299
+ return {
1300
+ intercept: intercept && (info => {
1301
+ const hit = intercept(info);
1302
+ if (hit !== undefined) {
1303
+ const address = client.frameAddress(info.id, info.args);
1304
+ byAddress.set(address, {
1305
+ frameId: info.id,
1306
+ component: brand(hit, info.id, info.id)
1307
+ });
1308
+ }
1309
+ return hit;
1310
+ }),
1311
+ handle(response, ctx) {
1312
+ if (!isFrameStreamResponse(response)) return undefined;
1313
+ const address = client.frameAddress(ctx.id, ctx.args);
1314
+ let entry = byAddress.get(address);
1315
+ if (!entry) {
1316
+ const adopted = documentComponent && documentComponent(ctx.id);
1317
+ if (adopted) {
1318
+ entry = {
1319
+ frameId: ctx.id,
1320
+ component: brand(adopted, ctx.id, ctx.id)
1321
+ };
1322
+ byAddress.set(address, entry);
1323
+ } else {
1324
+ entry = boundaryFor(address, ctx.id);
1325
+ }
1326
+ }
1327
+ if (response.headers.has(client.SINGLE_FLIGHT_HEADER)) {
1328
+ return applyFlightResponse(response, entry);
1329
+ }
1330
+ const version = bump(entry.frameId);
1331
+ if (onStream) onStream(entry.frameId, version, response);
1332
+ applyFrameResponse(response, host, {
1333
+ as: entry.frameId,
1334
+ version
1335
+ }).catch(err => host.apply({
1336
+ type: "error",
1337
+ id: entry.frameId,
1338
+ version,
1339
+ error: {
1340
+ message: String(err && err.message)
1341
+ }
1342
+ }));
1343
+ return entry.component;
1344
+ },
1345
+ showing(address, functionId, component) {
1346
+ if (!byAddress.has(address)) {
1347
+ byAddress.set(address, {
1348
+ frameId: functionId,
1349
+ component: brand(component, functionId, functionId),
1350
+ address
1351
+ });
1352
+ }
1353
+ }
1354
+ };
1355
+ async function applyFlightResponse(response, entry) {
1356
+ const rootId = response.headers.get(FRAME_STREAM_HEADER) ?? "";
1357
+ const as = rootId ? entry.frameId : undefined;
1358
+ let feed;
1359
+ const source = new ReadableStream({
1360
+ start(controller) {
1361
+ feed = controller;
1362
+ }
1363
+ });
1364
+ const payload = client.deserializeStream(new Response(source), flightCodec(codec()));
1365
+ let carried = false;
1366
+ await applyFrameResponse(response, host, {
1367
+ as,
1368
+ route: id => {
1369
+ const local = byAddress.get(id);
1370
+ return local ? local.frameId : id;
1371
+ },
1372
+ version: frameId => {
1373
+ const version = bump(frameId);
1374
+ if (onStream) onStream(frameId, version, response);
1375
+ return version;
1376
+ },
1377
+ onOutcome: text => {
1378
+ carried = true;
1379
+ feed.enqueue(client.createChunk(text));
1380
+ }
1381
+ });
1382
+ feed.close();
1383
+ if (!carried) throw new Error("Single-flight frame response carried no outcome");
1384
+ const envelope = await payload;
1385
+ const deliver = consumer();
1386
+ if (deliver) await deliver(envelope.data, {
1387
+ response
1388
+ });
1389
+ if (response.headers.has(client.ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has(client.REVALIDATE_HEADER)) {
1390
+ throw envelope.value;
1391
+ }
1392
+ return rootId ? entry.component : envelope.value;
1393
+ }
1394
+ }
1395
+
1396
+ seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
1397
+ const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
1398
+ web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
1399
+ web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin]);
1400
+ function resolveSerializerPlugins(customPlugins) {
1401
+ return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
1402
+ }
1403
+ const JSON_CODEC_DISABLED_FEATURES = seroval.Feature.RegExp;
1404
+ const JSON_CODEC_DEPTH_LIMIT = 64;
1405
+ function resolveCodecOptions({
1406
+ plugins,
1407
+ disabledFeatures,
1408
+ depthLimit
1409
+ } = {}) {
1410
+ return {
1411
+ plugins: resolveSerializerPlugins(plugins),
1412
+ disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
1413
+ depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
1414
+ };
1415
+ }
1416
+ function createJSONDeserializer(options) {
1417
+ const refs = new Map();
1418
+ const resolved = resolveCodecOptions(options);
1419
+ return function deserializeJSONChunk(node) {
1420
+ return seroval.fromCrossJSON(node, {
1421
+ refs,
1422
+ ...resolved
1423
+ });
1424
+ };
1425
+ }
1426
+ function createJSONDataTable(options) {
1427
+ const deserialize = createJSONDeserializer(options);
1428
+ const table = new Map();
1429
+ return {
1430
+ apply(record) {
1431
+ const value = deserialize(record.node);
1432
+ if (record.initial) table.set(record.key, value);
1433
+ },
1434
+ get(key) {
1435
+ return table.get(key);
1436
+ },
1437
+ resolve(ref) {
1438
+ return table.get(ref.$ref);
1439
+ }
1440
+ };
1441
+ }
1442
+
1443
+ let sharedHost;
1444
+ const tables = new Map();
1445
+ function tableFor(id) {
1446
+ const table = tables.get(id);
1447
+ if (table) return table;
1448
+ for (const [root, t] of tables) if (id.startsWith(root + ".")) return t;
1449
+ return undefined;
1450
+ }
1451
+ function beginStream(frameId) {
1452
+ tables.set(frameId, createJSONDataTable());
1453
+ }
1454
+ function getFrameHost() {
1455
+ if (!sharedHost) {
1456
+ sharedHost = createFrameHost({
1457
+ applyData: c => tableFor(c.id)?.apply(c),
1458
+ resolve: (ref, id) => tableFor(id)?.resolve(ref)
1459
+ });
1460
+ }
1461
+ return sharedHost;
1462
+ }
1463
+ function normalizeSlotContent(value) {
1464
+ while (typeof value === "function") value = value();
1465
+ if (Array.isArray(value)) {
1466
+ const out = [];
1467
+ for (const v of value) {
1468
+ const n = normalizeSlotContent(v);
1469
+ Array.isArray(n) ? out.push(...n) : out.push(n);
1470
+ }
1471
+ return out;
1472
+ }
1473
+ if (value == null || typeof value === "boolean") return document.createTextNode("");
1474
+ return value instanceof Node ? value : document.createTextNode(String(value));
1475
+ }
1476
+ function gatherClaims(el, registry) {
1477
+ if (el.hasAttribute("_hk")) registry.set(el.getAttribute("_hk"), el);
1478
+ if (el.hasAttribute(FRAME_ID_ATTR)) return;
1479
+ for (let c = el.firstElementChild; c; c = c.nextElementSibling) gatherClaims(c, registry);
1480
+ }
1481
+ function hasPendingFragment(existing) {
1482
+ for (const n of existing) {
1483
+ if (n.nodeType !== 1) continue;
1484
+ const el = n;
1485
+ if (el.tagName === "TEMPLATE" && el.id.startsWith("pl-")) return true;
1486
+ if (el.querySelector?.('template[id^="pl-"]')) return true;
1487
+ }
1488
+ return false;
1489
+ }
1490
+ function claimRender(prefix, existing, render) {
1491
+ const sc = solidJs.sharedConfig;
1492
+ if (!sc.getNextContextId) return render();
1493
+ const registry = new Map();
1494
+ for (const n of existing) {
1495
+ if (n.nodeType !== 1) continue;
1496
+ gatherClaims(n, registry);
1497
+ }
1498
+ if (!registry.size && !hasPendingFragment(existing)) return render();
1499
+ const prevRegistry = sc.registry;
1500
+ const prevHydrating = sc.hydrating;
1501
+ const prevClaimRoots = sc.claimRoots;
1502
+ if (prevRegistry) for (const key of registry.keys()) prevRegistry.delete(key);
1503
+ sc.registry = registry;
1504
+ sc.hydrating = true;
1505
+ sc.claimRoots = existing;
1506
+ try {
1507
+ return solidJs.runWithOwner(solidJs.createOwner({
1508
+ id: prefix
1509
+ }), render);
1510
+ } finally {
1511
+ sc.registry = prevRegistry;
1512
+ sc.hydrating = prevHydrating;
1513
+ sc.claimRoots = prevClaimRoots;
1514
+ }
1515
+ }
1516
+ function liveSlotProps(initial, ctx) {
1517
+ const [args, setArgs] = solidJs.createSignal(initial);
1518
+ ctx.onUpdate(next => setArgs(() => next));
1519
+ return new Proxy({}, {
1520
+ get: (_, key) => args()[key],
1521
+ has: (_, key) => key in args(),
1522
+ ownKeys: () => Reflect.ownKeys(args()),
1523
+ getOwnPropertyDescriptor: (_, key) => key in args() ? {
1524
+ enumerable: true,
1525
+ configurable: true
1526
+ } : undefined
1527
+ });
1528
+ }
1529
+ function isReactiveContent(value) {
1530
+ if (typeof value === "function") return true;
1531
+ if (Array.isArray(value)) {
1532
+ for (const v of value) if (isReactiveContent(v)) return true;
1533
+ }
1534
+ return false;
1535
+ }
1536
+ function slotsFor(props) {
1537
+ const bindings = new Map();
1538
+ return new Proxy({}, {
1539
+ get(_, prop) {
1540
+ if (typeof prop !== "string" || !(prop in props)) return undefined;
1541
+ return (slotProps, ctx) => {
1542
+ const key = ctx && ctx.key;
1543
+ const prev = key !== undefined && bindings.get(key);
1544
+ if (prev) {
1545
+ bindings.delete(key);
1546
+ prev.dispose();
1547
+ }
1548
+ const settle = out => {
1549
+ const existing = ctx && ctx.existing || [];
1550
+ if (existing.length) {
1551
+ const list = Array.isArray(out) ? out : [out];
1552
+ const inPlace = list.every(n => existing.some(e => e === n || e.nodeType === 1 && e.contains(n)));
1553
+ if (inPlace) return undefined;
1554
+ }
1555
+ return out;
1556
+ };
1557
+ const evaluate = () => {
1558
+ const v = props[prop];
1559
+ if (typeof v === "function" && ctx && ctx.invoked) {
1560
+ return v(ctx.onUpdate ? liveSlotProps(slotProps, ctx) : slotProps);
1561
+ }
1562
+ return v;
1563
+ };
1564
+ const adopted = !!(ctx && ctx.frame && ctx.adopted && ctx.existing && ctx.existing.length);
1565
+ const prefix = ctx && ctx.frame ? `sc-${ctx.frame}-${ctx.key}-` : "";
1566
+ const value = adopted ? claimRender(prefix, ctx.existing, evaluate) : evaluate();
1567
+ if (!isReactiveContent(value)) {
1568
+ return settle(normalizeSlotContent(value));
1569
+ }
1570
+ if (ctx && ctx.range) {
1571
+ let claim = adopted;
1572
+ const source = value;
1573
+ const accessor = () => {
1574
+ if (claim) {
1575
+ claim = false;
1576
+ return claimRender(prefix, ctx.existing, () => typeof source === "function" ? source() : source);
1577
+ }
1578
+ return typeof source === "function" ? source() : source;
1579
+ };
1580
+ const owner = solidJs.createOwner();
1581
+ bindings.set(key, owner);
1582
+ ctx.onCleanup(() => {
1583
+ if (bindings.get(key) === owner) bindings.delete(key);
1584
+ owner.dispose();
1585
+ });
1586
+ const end = ctx.range.end;
1587
+ solidJs.runWithOwner(owner, () => web$1.insert(end.parentNode, accessor, end, [...ctx.existing]));
1588
+ return undefined;
1589
+ }
1590
+ return settle(normalizeSlotContent(value));
1591
+ };
1592
+ }
1593
+ });
1594
+ }
1595
+ function revealSeam(owner) {
1596
+ return seam => solidJs.runWithOwner(owner, () => web$1.insert(seam.before.parentNode, solidJs.createLoadingBoundary(() => seam.content(), () => seam.fallback), seam.before));
1597
+ }
1598
+ function boundaryScope(owner) {
1599
+ return fn => solidJs.getOwner() ? fn() : solidJs.runWithOwner(owner, fn);
1600
+ }
1601
+ function boundaryComponent(host, id) {
1602
+ return props => {
1603
+ const owner = solidJs.getOwner();
1604
+ const {
1605
+ element,
1606
+ dispose
1607
+ } = createFrameElement({
1608
+ host,
1609
+ id,
1610
+ slots: slotsFor(props),
1611
+ ownerScope: boundaryScope(owner),
1612
+ reveal: revealSeam(owner)
1613
+ });
1614
+ solidJs.onCleanup(dispose);
1615
+ return element;
1616
+ };
1617
+ }
1618
+ const claimedBoundaries = new Set();
1619
+ let boundaryIndex = null;
1620
+ const isBoundaryId = id => !id.includes(".");
1621
+ function indexBoundaries(root) {
1622
+ root.querySelectorAll(`[${FRAME_ID_ATTR}]`).forEach(el => {
1623
+ const key = el.getAttribute(FRAME_ID_ATTR);
1624
+ if (key && isBoundaryId(key) && !boundaryIndex.has(key)) boundaryIndex.set(key, el);
1625
+ });
1626
+ }
1627
+ function findBoundaryElement(id) {
1628
+ if (!boundaryIndex) {
1629
+ boundaryIndex = new Map();
1630
+ if (typeof document !== "undefined" && document.body) indexBoundaries(document.body);
1631
+ }
1632
+ return boundaryIndex.get(id);
1633
+ }
1634
+ const boundaryWaiters = new Map();
1635
+ function documentStreaming() {
1636
+ const hy = globalThis._$HY;
1637
+ return !!hy && !hy.done;
1638
+ }
1639
+ function installRevealHook() {
1640
+ const hy = globalThis._$HY;
1641
+ if (!hy || hy.$sc) return;
1642
+ hy.$sc = true;
1643
+ const prev = hy.fe;
1644
+ hy.fe = (fragmentId, parent) => {
1645
+ if (prev) prev(fragmentId, parent);
1646
+ if (!boundaryIndex) return;
1647
+ const root = parent || (typeof document !== "undefined" ? document.body : null);
1648
+ if (!root) return;
1649
+ indexBoundaries(root);
1650
+ for (const [id, notify] of boundaryWaiters) {
1651
+ const el = boundaryIndex.get(id);
1652
+ if (!el) continue;
1653
+ boundaryWaiters.delete(id);
1654
+ notify(el);
1655
+ }
1656
+ };
1657
+ }
1658
+ function documentBoundary(host, id, props) {
1659
+ const claimed = claimedBoundaries.has(id);
1660
+ const el = !claimed ? findBoundaryElement(id) : undefined;
1661
+ if (el) return adoptBoundary(host, id, el, props);
1662
+ if (!claimed && !boundaryWaiters.has(id) && documentStreaming()) {
1663
+ const owner = solidJs.getOwner();
1664
+ const arrival = new Promise(resolve => boundaryWaiters.set(id, resolve));
1665
+ solidJs.onCleanup(() => boundaryWaiters.delete(id));
1666
+ return solidJs.createMemo(() => arrival.then(node => solidJs.runWithOwner(owner, () => adoptBoundary(host, id, node, props))));
1667
+ }
1668
+ return boundaryComponent(host, id)(props);
1669
+ }
1670
+ function adoptBoundary(host, id, el, props) {
1671
+ claimedBoundaries.add(id);
1672
+ const hy = globalThis._$HY;
1673
+ if (hy && hy.r) {
1674
+ const slotPrefix = `sc:slot:${id}:`;
1675
+ for (const key of Object.keys(hy.r)) {
1676
+ if (key.startsWith(slotPrefix)) {
1677
+ host.apply({
1678
+ type: "slot",
1679
+ id,
1680
+ version: 0,
1681
+ key: key.slice(slotPrefix.length),
1682
+ args: hy.r[key]
1683
+ });
1684
+ } else if (key.startsWith("sc:region:")) {
1685
+ const childId = key.slice("sc:region:".length);
1686
+ if (childId.startsWith(id + ".")) {
1687
+ const val = hy.r[key];
1688
+ const apply = html => host.apply({
1689
+ type: "html",
1690
+ id: childId,
1691
+ version: 0,
1692
+ html
1693
+ });
1694
+ val && typeof val.then === "function" ? val.then(apply) : apply(val);
1695
+ }
1696
+ }
1697
+ }
1698
+ }
1699
+ const owner = solidJs.getOwner();
1700
+ const frame = createFrame(el, {
1701
+ adopt: true,
1702
+ host,
1703
+ id,
1704
+ slots: slotsFor(props),
1705
+ ownerScope: boundaryScope(owner),
1706
+ reveal: revealSeam(owner)
1707
+ });
1708
+ solidJs.onCleanup(() => frame.dispose());
1709
+ return el;
1710
+ }
1711
+ function installServerComponents(host = getFrameHost()) {
1712
+ const g = globalThis;
1713
+ if (!g._$SC) {
1714
+ g._$SC = {
1715
+ c: {},
1716
+ a: {},
1717
+ r(i, a) {
1718
+ if (a) {
1719
+ g._$SC.a[a] = i;
1720
+ g._$SC.reg && g._$SC.reg(a, i);
1721
+ }
1722
+ return g._$SC.c[i] || (g._$SC.c[i] = p => g._$SC.impl(i, p));
1723
+ }
1724
+ };
1725
+ }
1726
+ g._$SC.impl = (id, props) => documentBoundary(host, id, props);
1727
+ installRevealHook();
1728
+ const handler = createServerComponentHandler({
1729
+ host,
1730
+ component: frameId => boundaryComponent(host, frameId),
1731
+ onStream: frameId => beginStream(frameId),
1732
+ documentComponent: functionId => claimedBoundaries.has(functionId) ? undefined : g._$SC.c[functionId],
1733
+ intercept: ({
1734
+ id
1735
+ }) => {
1736
+ if (claimedBoundaries.has(id) || !findBoundaryElement(id)) return undefined;
1737
+ return g._$SC.r(id);
1738
+ }
1739
+ });
1740
+ const showing = (address, id) => handler.showing(address, id, g._$SC.r(id));
1741
+ const records = g._$SC.a || (g._$SC.a = {});
1742
+ for (const address in records) showing(address, records[address]);
1743
+ g._$SC.reg = showing;
1744
+ client.configureServerFunctionsClient({
1745
+ responseHandler: handler
1746
+ });
1747
+ }
1748
+
1749
+ exports.FRAME_APPLIED_EVENT = FRAME_APPLIED_EVENT;
1750
+ exports.FRAME_STREAM_HEADER = FRAME_STREAM_HEADER;
1751
+ exports.applyFrameResponse = applyFrameResponse;
1752
+ exports.createFrame = createFrame;
1753
+ exports.createFrameElement = createFrameElement;
1754
+ exports.createFrameHost = createFrameHost;
1755
+ exports.createJSONDataTable = createJSONDataTable;
1756
+ exports.createServerComponentHandler = createServerComponentHandler;
1757
+ exports.getFrameHost = getFrameHost;
1758
+ exports.installServerComponents = installServerComponents;
1759
+ exports.isFrameStreamResponse = isFrameStreamResponse;