@solidjs/web 2.0.0-rc.2 → 2.0.0-rc.21

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