@solidjs/web 2.0.0-rc.1 → 2.0.0-rc.11

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 (107) hide show
  1. package/dist/server.dev.js +4472 -0
  2. package/dist/server.js +1301 -251
  3. package/dist/{server.cjs → server.observe.js} +1501 -452
  4. package/dist/{dev.cjs → web.dev.js} +699 -360
  5. package/dist/web.js +454 -139
  6. package/dist/{dev.js → web.observe.js} +505 -211
  7. package/frames/dist/client.dev.js +463 -71
  8. package/frames/dist/client.js +363 -70
  9. package/frames/dist/{client.dev.cjs → client.observe.js} +486 -133
  10. package/frames/dist/server.dev.js +1713 -0
  11. package/frames/dist/server.js +552 -2583
  12. package/frames/dist/server.observe.js +1713 -0
  13. package/frames/package.json +2 -25
  14. package/package.json +214 -255
  15. package/performance-tracks/dist/performance-tracks.dev.js +678 -0
  16. package/performance-tracks/dist/performance-tracks.js +6 -0
  17. package/performance-tracks/dist/performance-tracks.observe.js +666 -0
  18. package/performance-tracks/package.json +7 -0
  19. package/performance-tracks/types/index.d.ts +67 -0
  20. package/serialization/decode/package.json +2 -15
  21. package/serialization/dist/decode.js +92 -15
  22. package/serialization/dist/serialization.js +103 -23
  23. package/serialization/package.json +2 -15
  24. package/serialization/types/index.d.ts +76 -157
  25. package/serialization/types/serializer-decode.d.ts +149 -112
  26. package/serialization/types/serializer.d.ts +101 -0
  27. package/server-functions/dist/client.dev.js +1364 -0
  28. package/server-functions/dist/client.js +611 -97
  29. package/server-functions/dist/client.observe.js +1343 -0
  30. package/server-functions/dist/server.dev.js +2138 -202
  31. package/server-functions/dist/server.js +2042 -199
  32. package/server-functions/dist/server.observe.js +3043 -0
  33. package/server-functions/package.json +2 -35
  34. package/server-functions/rich-args/package.json +2 -15
  35. package/storage/package.json +2 -15
  36. package/types/client.d.ts +193 -288
  37. package/types/constants.d.ts +20 -0
  38. package/types/cookies.d.ts +32 -84
  39. package/types/diagnostics.d.ts +56 -0
  40. package/types/frames/client.d.ts +1 -1
  41. package/types/frames/frame-client.d.ts +323 -259
  42. package/types/frames/frame-container-plugin.d.ts +72 -0
  43. package/types/frames/frame-sink.d.ts +101 -158
  44. package/types/frames/frame-transport.d.ts +192 -190
  45. package/types/frames/serializer-decode.d.ts +219 -0
  46. package/types/frames/serializer.d.ts +76 -157
  47. package/types/frames/server.d.ts +1 -1
  48. package/types/head.d.ts +19 -0
  49. package/types/index.d.ts +52 -80
  50. package/types/index.server.d.ts +174 -0
  51. package/types/jsx.d.ts +33 -35
  52. package/types/observe.d.ts +358 -0
  53. package/types/reconcile.d.ts +1 -0
  54. package/types/render.d.ts +9 -0
  55. package/types/response.d.ts +75 -150
  56. package/types/serializer-decode.d.ts +149 -112
  57. package/types/serializer.d.ts +76 -157
  58. package/types/server-functions/client.d.ts +192 -194
  59. package/types/server-functions/flash.d.ts +28 -30
  60. package/types/server-functions/registry.d.ts +102 -0
  61. package/types/server-functions/rich-args.d.ts +1 -10
  62. package/types/server-functions/server.d.ts +511 -475
  63. package/types/server-functions/shared.d.ts +366 -425
  64. package/types/server-mock.d.ts +110 -13
  65. package/types/server-observe.d.ts +77 -0
  66. package/types/server.d.ts +425 -425
  67. package/types/trace.d.ts +127 -0
  68. package/LICENSE +0 -21
  69. package/dist/web.cjs +0 -2008
  70. package/frames/dist/client.cjs +0 -1916
  71. package/frames/dist/server.cjs +0 -3756
  72. package/serialization/dist/decode.cjs +0 -122
  73. package/serialization/dist/serialization.cjs +0 -244
  74. package/serialization/types-cjs/index.d.cts +0 -182
  75. package/serialization/types-cjs/package.json +0 -3
  76. package/serialization/types-cjs/serializer-decode.d.cts +0 -182
  77. package/server-functions/dist/client.cjs +0 -793
  78. package/server-functions/dist/rich-args.cjs +0 -11
  79. package/server-functions/dist/server.cjs +0 -1171
  80. package/server-functions/dist/server.dev.cjs +0 -1171
  81. package/storage/dist/storage.cjs +0 -12
  82. package/storage/types-cjs/index.d.cts +0 -28
  83. package/storage/types-cjs/package.json +0 -3
  84. package/types/core.d.ts +0 -6
  85. package/types-cjs/client.d.cts +0 -337
  86. package/types-cjs/cookies.d.cts +0 -93
  87. package/types-cjs/core.d.cts +0 -6
  88. package/types-cjs/frames/client.d.cts +0 -36
  89. package/types-cjs/frames/frame-client.d.cts +0 -338
  90. package/types-cjs/frames/frame-sink.d.cts +0 -194
  91. package/types-cjs/frames/frame-transport.d.cts +0 -222
  92. package/types-cjs/frames/serializer.d.cts +0 -182
  93. package/types-cjs/frames/server.d.cts +0 -52
  94. package/types-cjs/index.d.cts +0 -244
  95. package/types-cjs/jsx-properties.d.cts +0 -93
  96. package/types-cjs/jsx.d.cts +0 -4159
  97. package/types-cjs/package.json +0 -3
  98. package/types-cjs/response.d.cts +0 -174
  99. package/types-cjs/serializer-decode.d.cts +0 -182
  100. package/types-cjs/serializer.d.cts +0 -182
  101. package/types-cjs/server-functions/client.d.cts +0 -231
  102. package/types-cjs/server-functions/flash.d.cts +0 -38
  103. package/types-cjs/server-functions/rich-args.d.cts +0 -10
  104. package/types-cjs/server-functions/server.d.cts +0 -616
  105. package/types-cjs/server-functions/shared.d.cts +0 -523
  106. package/types-cjs/server-mock.d.cts +0 -277
  107. package/types-cjs/server.d.cts +0 -523
@@ -0,0 +1,4472 @@
1
+ import { createRenderEffect, getOwner, createMemo, OBSERVE, DEV, sharedConfig, createRoot, $PROXY, runWithOwner, createComponent, omit, getNextChildId, untrack, NotReadyError, onCleanup } from 'solid-js';
2
+ export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps, sharedConfig, untrack } from 'solid-js';
3
+ import { inServerComponentScope, sourceOwners, viewOf, reportServerError, ssrHandleError, creationStamp, ssrSanitizeError, getProjectionTrace, shareAsyncIterable } from 'solid-js/internal';
4
+ export { ssrScope as scope } from 'solid-js/internal';
5
+ import { Feature, createStream, Serializer, getCrossReferenceHeader } from 'seroval';
6
+ import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
7
+
8
+ const DOMWithState = {
9
+ INPUT: {
10
+ value: 1,
11
+ defaultValue: 2,
12
+ checked: 1,
13
+ defaultChecked: 2
14
+ },
15
+ SELECT: {
16
+ value: 1
17
+ },
18
+ OPTION: {
19
+ value: 1,
20
+ selected: 1,
21
+ defaultSelected: 2
22
+ },
23
+ TEXTAREA: {
24
+ value: 1,
25
+ defaultValue: 2
26
+ },
27
+ VIDEO: {
28
+ muted: 1,
29
+ defaultMuted: 2
30
+ },
31
+ AUDIO: {
32
+ muted: 1,
33
+ defaultMuted: 2
34
+ }
35
+ };
36
+ const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]);
37
+ const DelegatedEvents = /*#__PURE__*/new Set(["beforeinput", "click", "dblclick", "contextmenu", "focusin", "focusout", "input", "keydown", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "pointerdown", "pointermove", "pointerout", "pointerover", "pointerup", "touchend", "touchmove", "touchstart"]);
38
+ const SVGElements = /*#__PURE__*/new Set([
39
+ "altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignObject", "g", "glyph", "glyphRef", "hkern", "image", "line", "linearGradient", "marker", "mask", "metadata", "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect",
40
+ "set", "stop",
41
+ "svg", "switch", "symbol", "text", "textPath",
42
+ "tref", "tspan", "use", "view", "vkern"]);
43
+ const MathMLElements = /*#__PURE__*/new Set(["annotation", "annotation-xml", "maction", "math", "menclose", "merror", "mfenced", "mfrac", "mi", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mprescripts", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msubsup", "msup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "semantics"]);
44
+ const Namespaces = {
45
+ svg: "http://www.w3.org/2000/svg",
46
+ mathml: "http://www.w3.org/1998/Math/MathML",
47
+ xlink: "http://www.w3.org/1999/xlink",
48
+ xml: "http://www.w3.org/XML/1998/namespace"
49
+ };
50
+ const VoidElements = /*#__PURE__*/new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
51
+ const RawTextElements = /*#__PURE__*/new Set(["style", "script", "noscript", "template", "textarea", "title"]);
52
+ const DOMElements = /*#__PURE__*/new Set(/*#__PURE__*/"a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,bgsound,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,content,data,datalist,dd,del,details,dfn,dialog,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,image,img,input,ins,isindex,kbd,keygen,label,legend,li,link,listing,main,map,mark,marquee,math,menu,menuitem,meta,meter,multicol,nav,nextid,nobr,noembed,noframes,noindex,noscript,object,ol,optgroup,option,output,p,param,picture,plaintext,portal,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,search,section,select,shadow,slot,small,source,spacer,span,strike,strong,style,sub,summary,sup,svg,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,var,video,wbr,webview,xmp".split(","));
53
+ const COMPOSED_BODY_FRAMING = /*#__PURE__*/new Set(["content-length", "content-encoding", "transfer-encoding"]);
54
+ function isHttpNavigationTarget(target) {
55
+ try {
56
+ const protocol = new URL(target, "http://base.invalid").protocol;
57
+ return protocol === "http:" || protocol === "https:";
58
+ } catch {
59
+ return false;
60
+ }
61
+ }
62
+
63
+ const transparentOptions = {
64
+ transparent: true,
65
+ sync: true
66
+ };
67
+ const syncOptions = {
68
+ sync: true
69
+ };
70
+ function effect(fn, effectFn, options) {
71
+ const nodeOptions = options ? {
72
+ sync: true,
73
+ ...options,
74
+ transparent: !options.scope
75
+ } : transparentOptions;
76
+ {
77
+ createRenderEffect(prev => {
78
+ getOwner();
79
+ return fn(prev);
80
+ }, (value, prev) => {
81
+ try {
82
+ return effectFn(value, prev);
83
+ } finally {
84
+ }
85
+ }, nodeOptions);
86
+ return;
87
+ }
88
+ }
89
+ function memo(fn) {
90
+ return createMemo(() => fn(), syncOptions);
91
+ }
92
+
93
+ const PROVIDER = Symbol.for("solid-js/observe/server/provider");
94
+ function currentProvider() {
95
+ if (OBSERVE === undefined) return undefined;
96
+ const slot = OBSERVE.server.trace;
97
+ return slot && slot[PROVIDER];
98
+ }
99
+ const TRACEPARENT = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/;
100
+ const ZERO_TRACE = "00000000000000000000000000000000";
101
+ const ZERO_SPAN = "0000000000000000";
102
+ function parseTraceparent(value) {
103
+ if (!value) return undefined;
104
+ const m = TRACEPARENT.exec(value.trim());
105
+ if (!m) return undefined;
106
+ const [, version, traceId, parentId, flags, rest] = m;
107
+ if (version === "ff") return undefined;
108
+ if (version === "00" && rest !== undefined) return undefined;
109
+ if (traceId === ZERO_TRACE || parentId === ZERO_SPAN) return undefined;
110
+ return {
111
+ traceId,
112
+ parentId,
113
+ sampled: (parseInt(flags, 16) & 1) === 1
114
+ };
115
+ }
116
+ function randomHex(bytes) {
117
+ const buffer = new Uint8Array(bytes);
118
+ crypto.getRandomValues(buffer);
119
+ let out = "";
120
+ for (let i = 0; i < buffer.length; i++) out += (buffer[i] < 16 ? "0" : "") + buffer[i].toString(16);
121
+ return out;
122
+ }
123
+ function randomTraceId() {
124
+ let id = randomHex(16);
125
+ while (id === ZERO_TRACE) id = randomHex(16);
126
+ return id;
127
+ }
128
+ function randomSpanId() {
129
+ let id = randomHex(8);
130
+ while (id === ZERO_SPAN) id = randomHex(8);
131
+ return id;
132
+ }
133
+ function formatTraceparent(context) {
134
+ return `00-${context.traceId}-${context.spanId}-${context.sampled === true ? "01" : "00"}`;
135
+ }
136
+ const RECORDS_KEY = Symbol.for("@solidjs/web/trace/records");
137
+ function records$1() {
138
+ const g = globalThis;
139
+ return g[RECORDS_KEY] || (g[RECORDS_KEY] = new WeakMap());
140
+ }
141
+ function traceFor(key, request) {
142
+ const store = records$1();
143
+ let record = store.get(key);
144
+ if (record) return record;
145
+ const headers = request ? request.headers : undefined;
146
+ const incoming = headers ? parseTraceparent(headers.get("traceparent")) : undefined;
147
+ const context = {
148
+ traceId: incoming ? incoming.traceId : randomTraceId(),
149
+ spanId: randomSpanId(),
150
+ entries: {}
151
+ };
152
+ if (incoming) {
153
+ context.parentId = incoming.parentId;
154
+ context.sampled = incoming.sampled;
155
+ }
156
+ if (headers) {
157
+ const state = headers.get("tracestate");
158
+ if (state) context.state = state;
159
+ const baggage = headers.get("baggage");
160
+ if (baggage) context.baggage = baggage;
161
+ }
162
+ let answered = false;
163
+ let providedEntries;
164
+ {
165
+ const provider = currentProvider();
166
+ if (provider) {
167
+ let answer;
168
+ try {
169
+ answer = provider(request);
170
+ } catch (error) {
171
+ console.error(error);
172
+ }
173
+ if (answer !== undefined && answer !== null) {
174
+ answered = true;
175
+ if (answer.traceId !== undefined) context.traceId = answer.traceId;
176
+ if (answer.spanId !== undefined) context.spanId = answer.spanId;
177
+ if (answer.parentId !== undefined) context.parentId = answer.parentId;
178
+ if (answer.sampled !== undefined) context.sampled = answer.sampled;
179
+ if (answer.state !== undefined) context.state = answer.state;
180
+ if (answer.baggage !== undefined) context.baggage = answer.baggage;
181
+ providedEntries = answer.entries;
182
+ }
183
+ }
184
+ }
185
+ context.entries.traceparent = formatTraceparent(context);
186
+ if (providedEntries) Object.assign(context.entries, providedEntries);
187
+ record = {
188
+ context,
189
+ emit: incoming !== undefined && incoming.sampled || answered,
190
+ timing: []
191
+ };
192
+ store.set(key, record);
193
+ return record;
194
+ }
195
+ function traceForEvent(event) {
196
+ return traceFor(event.request || event, event.request);
197
+ }
198
+ const TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
199
+ function splitServerTiming(value) {
200
+ const entries = [];
201
+ let start = 0;
202
+ let quoted = false;
203
+ for (let i = 0; i < value.length; i++) {
204
+ const c = value[i];
205
+ if (quoted) {
206
+ if (c === "\\") i++;else if (c === '"') quoted = false;
207
+ } else if (c === '"') quoted = true;else if (c === ",") {
208
+ entries.push(value.slice(start, i));
209
+ start = i + 1;
210
+ }
211
+ }
212
+ entries.push(value.slice(start));
213
+ return entries;
214
+ }
215
+ function metricName(entry) {
216
+ return entry.split(";")[0].trim().toLowerCase();
217
+ }
218
+ function namesOnServerTiming(headers) {
219
+ const names = new Set();
220
+ const existing = headers.get("server-timing");
221
+ if (existing) {
222
+ for (const entry of splitServerTiming(existing)) {
223
+ const name = metricName(entry);
224
+ if (name) names.add(name);
225
+ }
226
+ }
227
+ return names;
228
+ }
229
+ function quoteDesc(value) {
230
+ return value.replace(/[\x00-\x1f\x7f]/g, "").replace(/[^\x20-\x7e]/g, "?").replace(/[\\"]/g, m => "\\" + m);
231
+ }
232
+ function shellMs(record) {
233
+ return record.render !== undefined ? record.render.shellMs : undefined;
234
+ }
235
+ function hasServerTiming(record) {
236
+ return record.emit || record.timing.length > 0 || shellMs(record) !== undefined;
237
+ }
238
+ function appendTraceServerTiming(headers, record) {
239
+ if (record.emit) {
240
+ const entries = record.context.entries;
241
+ let present;
242
+ for (const name in entries) {
243
+ if (!TOKEN.test(name)) continue;
244
+ if (!present) present = namesOnServerTiming(headers);
245
+ if (present.has(name.toLowerCase())) continue;
246
+ headers.append("Server-Timing", `${name};desc="${quoteDesc(entries[name])}"`);
247
+ present.add(name.toLowerCase());
248
+ }
249
+ }
250
+ const shell = shellMs(record);
251
+ if (shell !== undefined) headers.append("Server-Timing", formatMetric("solid-shell", shell));
252
+ for (const work of record.timing) headers.append("Server-Timing", metricOf(work));
253
+ }
254
+ function metricOf(work) {
255
+ if (work.type === "invocation") return formatMetric("solid-invocation", work.event.durationMs, work.event.id);
256
+ const boundary = work.event;
257
+ return formatMetric("solid-boundary", boundary.durationMs, boundary.ownerPath !== undefined ? boundary.ownerPath.join(" > ") : boundary.id);
258
+ }
259
+ function formatMetric(name, dur, desc) {
260
+ let out = `${name};dur=${Math.round(dur * 10) / 10}`;
261
+ if (desc) out += `;desc="${quoteDesc(desc)}"`;
262
+ return out;
263
+ }
264
+ function mergeServerTiming(target, value) {
265
+ const present = namesOnServerTiming(target);
266
+ for (const entry of splitServerTiming(value)) {
267
+ const trimmed = entry.trim();
268
+ const name = metricName(trimmed);
269
+ if (!name || present.has(name)) continue;
270
+ target.append("Server-Timing", trimmed);
271
+ }
272
+ }
273
+ function escapeAttr(value) {
274
+ return value.replace(/[&"<>]/g, c => c === "&" ? "&amp;" : c === '"' ? "&quot;" : c === "<" ? "&lt;" : "&gt;");
275
+ }
276
+ function traceMetaMarkup(record) {
277
+ if (!record.emit) return "";
278
+ let markup = "";
279
+ const entries = record.context.entries;
280
+ for (const name in entries) {
281
+ if (!TOKEN.test(name)) continue;
282
+ markup += `<meta name="${name}" content="${escapeAttr(entries[name])}">`;
283
+ }
284
+ return markup;
285
+ }
286
+
287
+ const RECORDS = Symbol.for("@solidjs/signals/observe/records");
288
+ function records() {
289
+ return globalThis[RECORDS];
290
+ }
291
+
292
+ const IS_DEV = true;
293
+ function timesServerWork(type) {
294
+ const channel = records();
295
+ if (channel === undefined) return false;
296
+ return IS_DEV;
297
+ }
298
+ function observeRender(trace, mode, event) {
299
+ if (!timesServerWork()) return undefined;
300
+ const record = {
301
+ mode,
302
+ at: performance.now(),
303
+ durationMs: 0,
304
+ boundaries: 0,
305
+ outcome: "complete"
306
+ };
307
+ trace.render = record;
308
+ let settled = false;
309
+ return {
310
+ shell() {
311
+ if (!settled && record.shellMs === undefined) record.shellMs = performance.now() - record.at;
312
+ },
313
+ boundary() {
314
+ if (!settled) record.boundaries++;
315
+ },
316
+ settle(outcome) {
317
+ if (settled) return;
318
+ settled = true;
319
+ record.durationMs = performance.now() - record.at;
320
+ record.outcome = outcome;
321
+ const channel = records();
322
+ if (!channel.observed("render")) return;
323
+ const live = {
324
+ trace: trace.context
325
+ };
326
+ if (event !== undefined) live.event = event;
327
+ channel.emit("render", record, live);
328
+ }
329
+ };
330
+ }
331
+
332
+ const STATE = Symbol.for("solid.container-trace-state");
333
+ const state = globalThis[STATE] || (globalThis[STATE] = {
334
+ materialized: new WeakMap(),
335
+ materializedValues: new WeakSet()
336
+ });
337
+ function setContainerTraceResolver(fn) {
338
+ state.resolveTrace = fn;
339
+ }
340
+ function setAsyncIterableSharer(fn) {
341
+ state.shareIterable = fn;
342
+ }
343
+ function setContainerTraceStreamMint(fn) {
344
+ state.streamOf = fn;
345
+ }
346
+ const TRACE = Symbol.for("solid.container-trace");
347
+ function toBorderForm(value, envelopeContainers) {
348
+ if (value == null || typeof value !== "object") return value;
349
+ const share = state.shareIterable;
350
+ if (!share) return value;
351
+ if (share && isShareableIterable(value)) return share(value);
352
+ if (Array.isArray(value)) {
353
+ let out = value;
354
+ for (let i = 0; i < value.length; i++) {
355
+ const next = toBorderForm(value[i]);
356
+ if (next !== value[i]) {
357
+ if (out === value) out = value.slice();
358
+ out[i] = next;
359
+ }
360
+ }
361
+ return out;
362
+ }
363
+ if (Object.getPrototypeOf(value) === Object.prototype) {
364
+ let out = value;
365
+ for (const key of Object.keys(value)) {
366
+ const next = toBorderForm(value[key]);
367
+ if (next !== value[key]) {
368
+ if (out === value) out = {
369
+ ...value
370
+ };
371
+ out[key] = next;
372
+ }
373
+ }
374
+ return out;
375
+ }
376
+ return value;
377
+ }
378
+ function isShareableIterable(value) {
379
+ try {
380
+ if (value.__SEROVAL_STREAM__ === true) return false;
381
+ if (typeof ReadableStream !== "undefined" && value instanceof ReadableStream) return false;
382
+ return typeof value[Symbol.asyncIterator] === "function";
383
+ } catch {
384
+ return false;
385
+ }
386
+ }
387
+ function materialize(marker) {
388
+ let value = state.materialized.get(marker.$tr);
389
+ if (value === undefined) {
390
+ value = state.materializeTrace(marker);
391
+ state.materialized.set(marker.$tr, value);
392
+ if (value !== null && typeof value === "object") state.materializedValues.add(value);
393
+ }
394
+ return value;
395
+ }
396
+ function parseTrace(value, ctx) {
397
+ const trace = value[TRACE];
398
+ const sub = trace.subscribe();
399
+ return {
400
+ a: trace.array ? 1 : 0,
401
+ i: ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
402
+ };
403
+ }
404
+ const ContainerTracePlugin = {
405
+ tag: "solid/container-trace",
406
+ test(value) {
407
+ return value != null && typeof value === "object" && TRACE in value;
408
+ },
409
+ parse: {
410
+ sync() {
411
+ throw new Error("A reactive container can only be serialized by a streaming serializer.");
412
+ },
413
+ async async(value, ctx) {
414
+ const trace = value[TRACE];
415
+ const sub = trace.subscribe();
416
+ return {
417
+ a: trace.array ? 1 : 0,
418
+ i: await ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
419
+ };
420
+ },
421
+ stream: parseTrace
422
+ },
423
+ serialize(node, ctx) {
424
+ return "{$tr:" + ctx.serialize(node.i) + ",$ta:" + node.a + "}";
425
+ },
426
+ deserialize(node, ctx) {
427
+ const iterable = ctx.deserialize(node.i);
428
+ const marker = {
429
+ $tr: iterable,
430
+ $ta: node.a
431
+ };
432
+ return state.materializeTrace ? materialize(marker) : marker;
433
+ }
434
+ };
435
+
436
+ setContainerTraceStreamMint(iterable => {
437
+ const stream = createStream();
438
+ (async () => {
439
+ try {
440
+ for await (const value of iterable) stream.next(value);
441
+ stream.return(undefined);
442
+ } catch (error) {
443
+ stream.throw(error);
444
+ }
445
+ })();
446
+ return stream;
447
+ });
448
+ const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
449
+ CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
450
+ FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
451
+ ContainerTracePlugin]);
452
+ function resolveSerializerPlugins(customPlugins) {
453
+ return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
454
+ }
455
+ Feature.RegExp;
456
+
457
+ const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
458
+ const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
459
+ const HYDRATION_GLOBAL = "_$HY.r";
460
+ function createSerializer(options) {
461
+ return new Serializer({
462
+ ...options,
463
+ plugins: resolveSerializerPlugins(options.plugins),
464
+ disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures(options.serializeErrorStacks)
465
+ });
466
+ }
467
+ function createHydrationSerializer({
468
+ onData,
469
+ onDone,
470
+ scopeId,
471
+ onError,
472
+ plugins
473
+ }) {
474
+ return createSerializer({
475
+ scopeId,
476
+ plugins,
477
+ globalIdentifier: HYDRATION_GLOBAL,
478
+ onData,
479
+ onDone,
480
+ onError
481
+ });
482
+ }
483
+ function getLocalHeaderScript(id) {
484
+ return getCrossReferenceHeader(id) + ";";
485
+ }
486
+
487
+ const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
488
+ // PURE-annotated factory (same convention as solid's MockPromise): the brand
489
+ const ResponseEnvelope = /* @__PURE__ */(() => {
490
+ class ResponseEnvelope {
491
+ constructor(response, value) {
492
+ this.response = response;
493
+ this.value = value;
494
+ }
495
+ }
496
+ ResponseEnvelope.prototype[ENVELOPE] = true;
497
+ return ResponseEnvelope;
498
+ })();
499
+ function isResponseEnvelope(value) {
500
+ return !!(value && typeof value === "object" && value[ENVELOPE]);
501
+ }
502
+ const HREF = Symbol.for("solid.Href");
503
+ function isHref(value) {
504
+ return !!(value && (typeof value === "object" || typeof value === "function") && value[HREF]);
505
+ }
506
+ const SAFE_ERROR = Symbol.for("solid.SafeError");
507
+ function markSafeError(error) {
508
+ if (error && (typeof error === "object" || typeof error === "function")) {
509
+ Object.defineProperty(error, SAFE_ERROR, {
510
+ value: true,
511
+ enumerable: false,
512
+ configurable: true
513
+ });
514
+ }
515
+ return error;
516
+ }
517
+ function isSafeError(value) {
518
+ return !!(value && (typeof value === "object" || typeof value === "function") && value[SAFE_ERROR]);
519
+ }
520
+ const REVALIDATE_HEADER = "X-Revalidate";
521
+ const REVALIDATE_ALL = "*";
522
+ const RESPONSE_HEADER_VALUE_LIMIT = 4096;
523
+ function initWithRevalidate(init = {}) {
524
+ const resolved = typeof init === "number" ? {
525
+ status: init
526
+ } : init;
527
+ const {
528
+ revalidate,
529
+ ...responseInit
530
+ } = resolved;
531
+ let headers;
532
+ if (responseInit.headers && responseInit.headers.getSetCookie) {
533
+ headers = new Headers();
534
+ responseInit.headers.forEach((value, key) => {
535
+ if (key !== "set-cookie") headers.append(key, value);
536
+ });
537
+ for (const cookie of responseInit.headers.getSetCookie()) {
538
+ headers.append("Set-Cookie", cookie);
539
+ }
540
+ } else {
541
+ headers = new Headers(responseInit.headers);
542
+ }
543
+ if (revalidate !== undefined) {
544
+ const list = Array.isArray(revalidate) ? revalidate : [revalidate];
545
+ if (list.length > 1 && list.includes(REVALIDATE_ALL)) {
546
+ throw new TypeError(`revalidate names "${REVALIDATE_ALL}" alongside other keys; "${REVALIDATE_ALL}" already ` + `means every entry and stands alone — pass revalidate: "${REVALIDATE_ALL}" or the named keys.`);
547
+ }
548
+ const keys = list.join(",");
549
+ if (keys.length > RESPONSE_HEADER_VALUE_LIMIT) {
550
+ throw new TypeError(`revalidate names ${keys.length} characters of cache keys; past ` + `${RESPONSE_HEADER_VALUE_LIMIT} the ${REVALIDATE_HEADER} header would overflow ` + `receivers (an 8 KiB proxy buffer holds the whole header block) and the response ` + `dies at the socket after the mutation committed. Split the invalidation across ` + `calls or use coarser keys — a dropped key would be a silently stale cache, so ` + `the runtime refuses rather than trims.`);
551
+ }
552
+ headers.set(REVALIDATE_HEADER, keys);
553
+ }
554
+ return {
555
+ responseInit,
556
+ headers
557
+ };
558
+ }
559
+ function redirect(url, init = 302) {
560
+ if (typeof url !== "string" && !isHref(url)) {
561
+ throw new TypeError("redirect() expects a string URL or an Href-branded value (Symbol.for('solid.Href')).");
562
+ }
563
+ const {
564
+ responseInit,
565
+ headers
566
+ } = initWithRevalidate(init);
567
+ if (responseInit.status === undefined) {
568
+ responseInit.status = 302;
569
+ }
570
+ const target = typeof url === "string" ? url : url[HREF];
571
+ const location = typeof target === "string" ? target : String(url);
572
+ const encoded = location.replace(/[^\x00-\x7f]/gu, encodeURIComponent);
573
+ if (encoded.length > RESPONSE_HEADER_VALUE_LIMIT) {
574
+ throw new TypeError(`redirect() target is ${encoded.length} characters; past ` + `${RESPONSE_HEADER_VALUE_LIMIT} the Location header (and the scripted transport's ` + `redirect header) would overflow receivers and the response dies at the socket. ` + `A target this size is usually unbounded input echoed into the url — carry the ` + `state server-side instead. Refused rather than trimmed: a cut target is a ` + `different address.`);
575
+ }
576
+ headers.set("Location", encoded);
577
+ return new Response(null, {
578
+ ...responseInit,
579
+ headers
580
+ });
581
+ }
582
+ function reload(init = {}) {
583
+ const {
584
+ responseInit,
585
+ headers
586
+ } = initWithRevalidate(init);
587
+ return new Response(null, {
588
+ ...responseInit,
589
+ headers
590
+ });
591
+ }
592
+ const NULL_BODY_STATUSES = new Set([204, 205, 304]);
593
+ function respond(value, init = {}) {
594
+ const {
595
+ responseInit,
596
+ headers
597
+ } = initWithRevalidate(init);
598
+ for (const header of COMPOSED_BODY_FRAMING) headers.delete(header);
599
+ if (NULL_BODY_STATUSES.has(responseInit.status)) {
600
+ return new ResponseEnvelope(new Response(null, {
601
+ ...responseInit,
602
+ headers
603
+ }), value);
604
+ }
605
+ headers.set("Content-Type", "application/json");
606
+ return new ResponseEnvelope(new Response(JSON.stringify(value), {
607
+ ...responseInit,
608
+ headers
609
+ }), value);
610
+ }
611
+
612
+ const SERVER_FUNCTION_METADATA = Symbol.for("solid.ServerFunctionMetadata");
613
+ function getServerFunctionMetadata(fn) {
614
+ if (typeof fn !== "function") return undefined;
615
+ return fn[SERVER_FUNCTION_METADATA] || undefined;
616
+ }
617
+ function isServerFunction(fn) {
618
+ return typeof fn === "function" && !!fn[SERVER_FUNCTION_METADATA];
619
+ }
620
+ const SERVER_FUNCTION_RPC = Symbol.for("solid.ServerFunctionRPC");
621
+ function getServerFunctionRPC() {
622
+ return globalThis[SERVER_FUNCTION_RPC];
623
+ }
624
+
625
+ function parseCookieHeader(header) {
626
+ const cookies = {};
627
+ if (!header) return cookies;
628
+ for (const part of header.split(";")) {
629
+ const eq = part.indexOf("=");
630
+ if (eq < 0) continue;
631
+ const name = decodeSafe(part.slice(0, eq).trim());
632
+ let value = part.slice(eq + 1).trim();
633
+ if (value.length > 1 && value[0] === '"' && value[value.length - 1] === '"') {
634
+ value = value.slice(1, -1);
635
+ }
636
+ cookies[name] = decodeSafe(value);
637
+ }
638
+ return cookies;
639
+ }
640
+ function decodeSafe(text) {
641
+ try {
642
+ return decodeURIComponent(text);
643
+ } catch {
644
+ return text;
645
+ }
646
+ }
647
+ function serializeCookie(name, value, options = {}) {
648
+ assertServableCookie(name, options);
649
+ let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
650
+ cookie += `; Path=${options.path === undefined ? "/" : options.path}`;
651
+ if (options.domain) cookie += `; Domain=${options.domain}`;
652
+ if (options.maxAge !== undefined) cookie += `; Max-Age=${Math.trunc(options.maxAge)}`;
653
+ if (options.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
654
+ if (options.httpOnly) cookie += "; HttpOnly";
655
+ if (options.secure) cookie += "; Secure";
656
+ if (options.partitioned) cookie += "; Partitioned";
657
+ if (options.sameSite) {
658
+ const sameSite = options.sameSite.toLowerCase();
659
+ cookie += `; SameSite=${sameSite === "none" ? "None" : sameSite === "strict" ? "Strict" : "Lax"}`;
660
+ }
661
+ return cookie;
662
+ }
663
+ function assertServableCookie(name, options) {
664
+ const reject = reason => {
665
+ throw new Error(`serializeCookie: every browser silently rejects this cookie — ${reason}. ` + `It would never come back on a request, with no error anywhere.`);
666
+ };
667
+ const lower = name.toLowerCase();
668
+ if (lower.startsWith("__host-")) {
669
+ if (!options.secure) reject(`the __Host- prefix on \`${name}\` requires \`secure: true\``);
670
+ if (options.path !== undefined && options.path !== "/") reject(`the __Host- prefix on \`${name}\` requires \`Path=/\` (got \`${options.path}\`) — ` + `host-locking is the prefix's whole contract, so it cannot be path-scoped`);
671
+ if (options.domain) reject(`the __Host- prefix on \`${name}\` forbids \`Domain\` (got \`${options.domain}\`)`);
672
+ } else if (lower.startsWith("__secure-") && !options.secure) {
673
+ reject(`the __Secure- prefix on \`${name}\` requires \`secure: true\``);
674
+ }
675
+ if (options.sameSite && options.sameSite.toLowerCase() === "none" && !options.secure) {
676
+ reject("`SameSite=None` requires `secure: true`");
677
+ }
678
+ if (options.partitioned && !options.secure) {
679
+ reject("`Partitioned` requires `secure: true`");
680
+ }
681
+ }
682
+ const FLASH_COOKIE = "flash";
683
+ const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
684
+ function hasFlashCookie(cookieHeader) {
685
+ return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
686
+ }
687
+ function clearFlashCookie() {
688
+ return `${FLASH_COOKIE}=; Max-Age=0; Path=/`;
689
+ }
690
+
691
+ const ERROR_HEADER = "X-Server-Function-Error";
692
+ const BODY_FORMAT_HEADER = "X-Server-Function-Format";
693
+ const REDIRECT_HEADER = "X-Server-Function-Redirect";
694
+ const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
695
+ new TextEncoder().encode(":\n\n");
696
+
697
+ function emitFinding(finding, subject = getOwner()) {
698
+ if (OBSERVE === undefined) return;
699
+ const entry = OBSERVE.diagnostics.emit(finding, subject);
700
+ if (DEV !== undefined) DEV.report(entry);
701
+ }
702
+ function recordFinding(finding, subject = getOwner()) {
703
+ if (OBSERVE !== undefined) OBSERVE.diagnostics.emit(finding, subject);
704
+ }
705
+ function devCheck(finding, subject) {
706
+ emitFinding(finding, subject);
707
+ }
708
+ function unscopedHoleAllocatedIds(before, after, site, subject) {
709
+ const fn = site.name ? `\`${site.name}\`` : "a function";
710
+ const where = site.registered !== undefined ? `the server evaluated it at ${before} (→ ${after}), after the scoped holes that follow it ` + `had reserved theirs, but it was registered at ${site.registered}, where the client builds ` + `it in place` : `the client built it in place at ${before} (→ ${after}) and its content missed its ` + `server-rendered keys, because the server evaluates it after the scoped holes that follow it`;
711
+ devCheck({
712
+ code: "UNSCOPED_HOLE_ALLOCATED_IDS",
713
+ kind: "render",
714
+ severity: "warn",
715
+ message: `[UNSCOPED_HOLE_ALLOCATED_IDS] A JSX hole received ${fn} instead of a value, and calling it ` + `built hydratable content. The hole is unscoped, so that content took ids from the enclosing ` + `scope's counter: ${where}. The hydration keys of this hole's content and of the holes after it ` + `permute between server and client. Pass the built value — call it at the hole ` + `(\`{${site.name || "render"}()}\`) or assign the result first — rather than the function; a ` + `function is not a JSX.Element, so this shape is reached only from JavaScript or through a cast.`,
716
+ data: {
717
+ before,
718
+ after,
719
+ ...site
720
+ }
721
+ }, subject);
722
+ }
723
+ function errorText(error) {
724
+ if (error instanceof Error) return error.message ? `${error.name}: ${error.message}` : error.name;
725
+ return String(error);
726
+ }
727
+
728
+ const HEAD_ELIGIBLE_TAGS = new Set(["title", "meta", "link", "style", "script", "base"]);
729
+ const HEAD_ATTR_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;
730
+ const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "stylesheet"]);
731
+ const RESOURCE_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
732
+ const STYLESHEET_FETCH_META = new Set(["crossorigin", "integrity", "referrerpolicy", "fetchpriority"]);
733
+ function evalHeadValue(v) {
734
+ return typeof v === "function" ? v() : v;
735
+ }
736
+ function evalHeadProps(props, presets) {
737
+ const out = {};
738
+ for (const name in props) out[name] = presets && name in presets ? presets[name] : evalHeadValue(props[name]);
739
+ return out;
740
+ }
741
+ function classifyHeadTag(desc) {
742
+ const tag = desc.tag;
743
+ if (tag === "link") {
744
+ const rel = evalHeadValue(desc.props && desc.props.rel);
745
+ return {
746
+ resource: RESOURCE_LINK_RELS.has(rel),
747
+ rel
748
+ };
749
+ }
750
+ if (tag === "style") return {
751
+ resource: !!(desc.props && "href" in desc.props)
752
+ };
753
+ if (tag === "script") return {
754
+ resource: !!(desc.props && "src" in desc.props)
755
+ };
756
+ return {
757
+ resource: false
758
+ };
759
+ }
760
+ function qualifierValue(name, value) {
761
+ if (value == null || value === false) return null;
762
+ if (name === "imagesrcset" || name === "imagesizes") return typeof value === "string" && value !== "" ? value : null;
763
+ const v = value === true ? "" : String(value);
764
+ if (name === "as") return asciiLowerCase(v);
765
+ if (name !== "crossorigin") return v;
766
+ return v.length === 15 && v.toLowerCase() === "use-credentials" ? v.toLowerCase() : "anonymous";
767
+ }
768
+ function asciiLowerCase(value) {
769
+ return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
770
+ }
771
+ function resourceIdentity(tag, props) {
772
+ const url = String(props.href || props.src || "");
773
+ let id = "res:" + tag + ":" + (props.rel || "") + ":" + url.length + ":" + url;
774
+ for (let i = 0; i < RESOURCE_QUALIFIERS.length; i++) {
775
+ const q = RESOURCE_QUALIFIERS[i];
776
+ const value = qualifierValue(q, props[q]);
777
+ if (value !== null) id += ":" + q + "=" + value.length + ":" + value;
778
+ }
779
+ return id;
780
+ }
781
+ function replaceableIdentity(tag, props, key, unique) {
782
+ if (tag === "title") return "title";
783
+ if (tag === "base") return "base";
784
+ if (tag === "meta" && props.charset != null) return "charset";
785
+ if (key != null) return tag + ":key:" + key;
786
+ if (tag === "meta") {
787
+ for (const ns of ["name", "property", "http-equiv"]) if (props[ns] != null) return "meta:" + ns + ":" + props[ns] + (props.media != null ? ":media=" + props.media : "");
788
+ return unique;
789
+ }
790
+ if (tag === "link") {
791
+ const rel = props.rel || "";
792
+ if (rel === "icon" || rel === "apple-touch-icon") return "link:" + rel + (props.sizes != null ? ":sizes=" + props.sizes : "") + (props.type != null ? ":type=" + props.type : "");
793
+ return "link:" + rel + ":" + (props.href || "");
794
+ }
795
+ return unique;
796
+ }
797
+ function resolveHead(groups) {
798
+ const winners = new Map();
799
+ const sorted = groups.slice().sort((a, b) => a.seq - b.seq);
800
+ for (let i = 0; i < sorted.length; i++) {
801
+ const group = sorted[i];
802
+ const byIdentity = new Map();
803
+ for (let j = 0; j < group.tags.length; j++) {
804
+ const t = group.tags[j];
805
+ let list = byIdentity.get(t.identity);
806
+ if (!list) byIdentity.set(t.identity, list = []);
807
+ list.push(t);
808
+ }
809
+ for (const [identity, tags] of byIdentity) {
810
+ if (identity === "title") {
811
+ if (tags.length > 1) devCheck({
812
+ code: "HEAD_TAG_INVALID",
813
+ kind: "head",
814
+ severity: "warn",
815
+ message: "[HEAD_TAG_INVALID] Multiple <title> tags in one head group; the last one wins.",
816
+ data: {
817
+ reason: "duplicate-title",
818
+ detail: tags.length
819
+ }
820
+ });
821
+ winners.set(identity, {
822
+ seq: group.seq,
823
+ tags: [tags[tags.length - 1]]
824
+ });
825
+ } else {
826
+ winners.set(identity, {
827
+ seq: group.seq,
828
+ tags
829
+ });
830
+ }
831
+ }
832
+ }
833
+ return winners;
834
+ }
835
+
836
+ function joinAssetPath(base, file) {
837
+ if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(file)) return file;
838
+ if (typeof base !== "string" || !base) base = "/";
839
+ if (base[base.length - 1] !== "/") base += "/";
840
+ return base + (file[0] === "/" ? file.slice(1) : file);
841
+ }
842
+ function eachCandidate(srcset, visit) {
843
+ let i = 0;
844
+ const n = srcset.length;
845
+ while (i < n) {
846
+ while (i < n && /[\s,]/.test(srcset[i])) i++;
847
+ const start = i;
848
+ while (i < n && !/\s/.test(srcset[i])) i++;
849
+ if (i === start) return false;
850
+ const raw = srcset.slice(start, i);
851
+ const url = raw.replace(/,+$/, "");
852
+ let descriptors = "";
853
+ if (url === raw) {
854
+ const from = i;
855
+ while (i < n && srcset[i] !== ",") i++;
856
+ descriptors = srcset.slice(from, i);
857
+ }
858
+ if (url && visit(url, descriptors)) return true;
859
+ }
860
+ return false;
861
+ }
862
+ function hasRelativeCandidate(srcset) {
863
+ return eachCandidate(srcset, url => !/^(?:[a-zA-Z][a-zA-Z0-9+.-]*:|\/)/.test(url));
864
+ }
865
+ function hasWidthDescriptor(srcset) {
866
+ return eachCandidate(srcset, (_, descriptors) => /(?:^|\s)\d+(?:\.\d+)?w(?=\s|$)/.test(descriptors));
867
+ }
868
+ function resolveAssets(moduleUrl, manifest) {
869
+ if (!manifest) return null;
870
+ const base = manifest._base;
871
+ const entry = manifest[moduleUrl];
872
+ if (!entry) return null;
873
+ const css = [];
874
+ const js = [];
875
+ let preloads;
876
+ const visited = new Set();
877
+ const walk = key => {
878
+ if (visited.has(key)) return;
879
+ visited.add(key);
880
+ const e = manifest[key];
881
+ if (!e) return;
882
+ js.push(joinAssetPath(base, e.file));
883
+ if (e.css) for (let i = 0; i < e.css.length; i++) css.push(joinAssetPath(base, e.css[i]));
884
+ if (e.preloads) {
885
+ for (let i = 0; i < e.preloads.length; i++) {
886
+ const link = e.preloads[i];
887
+ const href = link && typeof link.href === "string" && link.href;
888
+ const srcset = link && typeof link.imagesrcset === "string" && link.imagesrcset;
889
+ if (!href && !srcset) continue;
890
+ if (!preloads) preloads = [];
891
+ if (href) preloads.push({
892
+ ...link,
893
+ href: joinAssetPath(base, href)
894
+ });else {
895
+ const {
896
+ href: bad,
897
+ ...rest
898
+ } = link;
899
+ if (bad !== undefined) preloadInvalid("href", "Preload href must be a non-empty string; dropping it.", bad);
900
+ preloads.push(rest);
901
+ }
902
+ if (srcset && hasRelativeCandidate(srcset)) preloadInvalid("imagesrcset", "imagesrcset candidates are not joined with the manifest base — they resolve " + "against the document URL, so a relative candidate points somewhere else " + "than the joined href; the integration should emit resolved URLs.", srcset);
903
+ }
904
+ }
905
+ if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
906
+ };
907
+ walk(moduleUrl);
908
+ const assets = {
909
+ js,
910
+ css
911
+ };
912
+ if (preloads) assets.preloads = preloads;
913
+ return assets;
914
+ }
915
+ function registerEntryAssets(manifest) {
916
+ if (!manifest || typeof manifest === "function" || typeof manifest.resolve === "function") return;
917
+ const ctx = sharedConfig.context;
918
+ if (!ctx?.registerAsset) return;
919
+ for (const key in manifest) {
920
+ if (manifest[key].isEntry) {
921
+ const assets = resolveAssets(key, manifest);
922
+ if (assets) {
923
+ if (assets.preloads) for (let i = 0; i < assets.preloads.length; i++) ctx.registerAsset("preload", assets.preloads[i]);
924
+ for (let i = 0; i < assets.css.length; i++) ctx.registerAsset("style", assets.css[i]);
925
+ for (let i = 1; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i]);
926
+ }
927
+ return;
928
+ }
929
+ }
930
+ }
931
+ function createAssetTracking() {
932
+ const boundaryModules = new Map();
933
+ const boundaryStyles = new Map();
934
+ const emittedAssets = new Set();
935
+ const inlineStyles = new Map();
936
+ let currentBoundaryId = null;
937
+ return {
938
+ boundaryModules,
939
+ boundaryStyles,
940
+ emittedAssets,
941
+ inlineStyles,
942
+ preloadLinks: null,
943
+ registerInlineStyle(desc) {
944
+ let entry = inlineStyles.get(desc.id);
945
+ if (!entry) {
946
+ entry = {
947
+ id: desc.id,
948
+ content: desc.content || "",
949
+ attrs: desc.attrs,
950
+ emitted: false
951
+ };
952
+ inlineStyles.set(desc.id, entry);
953
+ }
954
+ if (currentBoundaryId) {
955
+ let styles = boundaryStyles.get(currentBoundaryId);
956
+ if (!styles) {
957
+ styles = new Set();
958
+ boundaryStyles.set(currentBoundaryId, styles);
959
+ }
960
+ styles.add(entry);
961
+ }
962
+ return entry;
963
+ },
964
+ get currentBoundaryId() {
965
+ return currentBoundaryId;
966
+ },
967
+ set currentBoundaryId(v) {
968
+ currentBoundaryId = v;
969
+ },
970
+ registerModule(key, entryUrl) {
971
+ const id = currentBoundaryId || "";
972
+ let map = boundaryModules.get(id);
973
+ if (!map) {
974
+ map = {};
975
+ boundaryModules.set(id, map);
976
+ }
977
+ map[key] = entryUrl;
978
+ },
979
+ getBoundaryModules(id) {
980
+ return boundaryModules.get(id) || null;
981
+ },
982
+ getBoundaryStyles(id) {
983
+ return boundaryStyles.get(id) || null;
984
+ }
985
+ };
986
+ }
987
+ function warnUnresolvedModuleAssets(moduleUrl, warned) {
988
+ if (warned.has(moduleUrl)) return;
989
+ warned.add(moduleUrl);
990
+ console.error(`Asset manifest returned no client assets for module "${moduleUrl}". ` + "If this module is a server-rendered lazy() component, its entry will be missing from " + "the serialized hydration asset map, the client will be unable to preload it, and " + "hydration will fail with 'lazy() module \"…\" was not preloaded before hydration'. " + "This means the integration's asset resolver (dev manifest bridge or build client " + "manifest) failed to answer for this module — check the integration's server logs, " + "restart the dev server, or verify the module is included in the client build.");
991
+ }
992
+ function guardResolvedAssets(moduleUrl, result, warned) {
993
+ if (result && typeof result.then === "function") {
994
+ return result.then(assets => {
995
+ if (!assets || !assets.js || !assets.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
996
+ return assets;
997
+ });
998
+ }
999
+ if (!result || !result.js || !result.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
1000
+ return result;
1001
+ }
1002
+ function applyAssetTracking(context, tracking, manifest, noScripts) {
1003
+ const warned = new Set();
1004
+ const guard = noScripts ? resolve => resolve : resolve => moduleUrl => guardResolvedAssets(moduleUrl, resolve(moduleUrl), warned);
1005
+ Object.defineProperty(context, "_currentBoundaryId", {
1006
+ get() {
1007
+ return tracking.currentBoundaryId;
1008
+ },
1009
+ set(v) {
1010
+ tracking.currentBoundaryId = v;
1011
+ },
1012
+ configurable: true,
1013
+ enumerable: true
1014
+ });
1015
+ context.registerModule = tracking.registerModule;
1016
+ context.getBoundaryModules = tracking.getBoundaryModules;
1017
+ if (typeof manifest === "function") {
1018
+ context.resolveAssets = guard(manifest);
1019
+ } else if (manifest && typeof manifest.resolve === "function") {
1020
+ context.resolveAssets = guard(key => manifest.resolve(key));
1021
+ if (typeof manifest.resolveSync === "function") {
1022
+ context.resolveAssetsSync = key => manifest.resolveSync(key);
1023
+ }
1024
+ } else if (manifest) {
1025
+ const resolve = moduleUrl => resolveAssets(moduleUrl, manifest);
1026
+ context.resolveAssets = guard(resolve);
1027
+ context.resolveAssetsSync = resolve;
1028
+ }
1029
+ }
1030
+ function isCssUrl(url) {
1031
+ const q = url.search(/[?#]/);
1032
+ return (q === -1 ? url : url.slice(0, q)).endsWith(".css");
1033
+ }
1034
+ const RESPONSIVE_ATTRIBUTES = ["imagesrcset", "imagesizes"];
1035
+ function isSetAttr(value) {
1036
+ return value != null && value !== false && value !== "";
1037
+ }
1038
+ const PRELOAD_LINK_ATTRIBUTES = ["type", "crossorigin", "integrity", "referrerpolicy", "fetchpriority", "media", "imagesrcset", "imagesizes"];
1039
+ function preloadInvalid(field, message, value) {
1040
+ devCheck({
1041
+ code: "PRELOAD_DESCRIPTOR_INVALID",
1042
+ kind: "head",
1043
+ severity: "warn",
1044
+ message: `[PRELOAD_DESCRIPTOR_INVALID] ${message}`,
1045
+ data: value === undefined ? {
1046
+ field
1047
+ } : {
1048
+ field,
1049
+ value
1050
+ }
1051
+ });
1052
+ }
1053
+ function unrecognizedInsert(node) {
1054
+ devCheck({
1055
+ code: "UNRECOGNIZED_INSERT_VALUE",
1056
+ kind: "render",
1057
+ severity: "warn",
1058
+ message: `[UNRECOGNIZED_INSERT_VALUE] Unrecognized value. Skipped inserting (${typeof node}).`,
1059
+ data: {
1060
+ type: typeof node,
1061
+ value: node
1062
+ }
1063
+ });
1064
+ }
1065
+ let reportedHoles;
1066
+ function devPeekId() {
1067
+ const peek = sharedConfig.devPeekNextContextId;
1068
+ return peek === undefined ? undefined : peek();
1069
+ }
1070
+ function checkUnscopedHole(before, template, index, hole) {
1071
+ if (hole.$reg === before) return;
1072
+ const after = devPeekId();
1073
+ if (after === before) return;
1074
+ let seen = (reportedHoles || (reportedHoles = new WeakMap())).get(template);
1075
+ if (seen === undefined) reportedHoles.set(template, seen = new Set());
1076
+ if (seen.has(index)) return;
1077
+ seen.add(index);
1078
+ const name = hole.$fn.name;
1079
+ const site = {
1080
+ hole: index,
1081
+ registered: hole.$reg
1082
+ };
1083
+ if (name) site.name = name;
1084
+ unscopedHoleAllocatedIds(before, after, site);
1085
+ }
1086
+ function headTagInvalid(reason, message, detail) {
1087
+ devCheck({
1088
+ code: "HEAD_TAG_INVALID",
1089
+ kind: "head",
1090
+ severity: "warn",
1091
+ message: `[HEAD_TAG_INVALID] ${message}`,
1092
+ data: detail === undefined ? {
1093
+ reason
1094
+ } : {
1095
+ reason,
1096
+ detail
1097
+ }
1098
+ });
1099
+ }
1100
+ function registerPreloadLink(tracking, headRegistry, link, nonce) {
1101
+ if (!link || typeof link !== "object") {
1102
+ preloadInvalid("descriptor", 'registerAsset("preload") requires a descriptor object.', link);
1103
+ return null;
1104
+ }
1105
+ if (typeof link.as !== "string") {
1106
+ preloadInvalid("as", 'registerAsset("preload") requires an as destination.');
1107
+ return null;
1108
+ }
1109
+ const as = asciiLowerCase(link.as);
1110
+ let destination = null;
1111
+ switch (as) {
1112
+ case "script":
1113
+ case "style":
1114
+ destination = as;
1115
+ break;
1116
+ case "fetch":
1117
+ case "font":
1118
+ case "image":
1119
+ case "track":
1120
+ break;
1121
+ default:
1122
+ preloadInvalid("as", `registerAsset("preload") received an unsupported as destination "${link.as}".`, link.as);
1123
+ return null;
1124
+ }
1125
+ const responsive = as === "image";
1126
+ if (!responsive && (isSetAttr(link.imagesrcset) || isSetAttr(link.imagesizes))) preloadInvalid(isSetAttr(link.imagesrcset) ? "imagesrcset" : "imagesizes", 'registerAsset("preload") only supports imagesrcset and imagesizes with as="image".');
1127
+ let srcset = null;
1128
+ let sizes = null;
1129
+ if (responsive) {
1130
+ for (const name of RESPONSIVE_ATTRIBUTES) {
1131
+ const value = link[name];
1132
+ if (!isSetAttr(value)) continue;
1133
+ if (typeof value !== "string") {
1134
+ preloadInvalid(name, `registerAsset("preload") expects a string ${name}.`, value);
1135
+ continue;
1136
+ }
1137
+ if (name === "imagesrcset") srcset = value;else sizes = value;
1138
+ }
1139
+ }
1140
+ const href = typeof link.href === "string" && link.href ? link.href : null;
1141
+ if (!href && link.href != null && link.href !== false) preloadInvalid("href", "Preload href must be a non-empty string; dropping it.", link.href);
1142
+ if (!href && !srcset) {
1143
+ preloadInvalid("href", 'registerAsset("preload") requires a non-empty string href or imagesrcset.');
1144
+ return null;
1145
+ }
1146
+ if (srcset && !sizes && hasWidthDescriptor(srcset)) preloadInvalid("imagesizes", "imagesrcset uses a width descriptor, so imagesizes is required; without it the " + "source size defaults to 100vw and the preload may not match the image.", srcset);
1147
+ const props = {
1148
+ rel: "preload"
1149
+ };
1150
+ if (href) props.href = href;
1151
+ props.as = as;
1152
+ for (let i = 0; i < PRELOAD_LINK_ATTRIBUTES.length; i++) {
1153
+ const name = PRELOAD_LINK_ATTRIBUTES[i];
1154
+ if (RESPONSIVE_ATTRIBUTES.indexOf(name) !== -1) {
1155
+ const value = name === "imagesrcset" ? srcset : sizes;
1156
+ if (value !== null) props[name] = value;
1157
+ continue;
1158
+ }
1159
+ const value = link[name];
1160
+ if (value == null || value === false) continue;
1161
+ props[name] = value === true ? "" : String(value);
1162
+ }
1163
+ const identity = resourceIdentity("link", props);
1164
+ if (headRegistry.resources.has(identity)) return null;
1165
+ if (props.crossorigin == null && (as === "font" || as === "fetch")) preloadInvalid("crossorigin", `registerAsset("preload") with as="${as}" has no crossorigin and may not match the eventual request.`);
1166
+ const attrs = headAttrRecord(props);
1167
+ const nonceValue = destination && nonce && nonce[destination];
1168
+ if (typeof nonceValue === "string" && nonceValue) attrs.nonce = nonceValue;
1169
+ const entry = {
1170
+ href: props.href,
1171
+ attrs,
1172
+ attrHtml: renderHeadAttrHtml(props) + nonceAttr(nonce, destination)
1173
+ };
1174
+ headRegistry.resources.add(identity);
1175
+ let links = tracking.preloadLinks;
1176
+ if (!links) tracking.preloadLinks = links = [];
1177
+ links.push(entry);
1178
+ return entry;
1179
+ }
1180
+ function createHeadRegistry() {
1181
+ return {
1182
+ pending: [],
1183
+ committed: [],
1184
+ seq: 0,
1185
+ uniq: 0,
1186
+ resources: new Set(),
1187
+ eagerHtml: "",
1188
+ flushed: null,
1189
+ shellFlushed: false,
1190
+ parkedResources: []
1191
+ };
1192
+ }
1193
+ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags) {
1194
+ const boundary = context._currentBoundaryId || "";
1195
+ if (typeof tags === "function") {
1196
+ registry.pending.push({
1197
+ boundary,
1198
+ list: tags,
1199
+ resource: (desc, rel) => emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel)
1200
+ });
1201
+ return;
1202
+ }
1203
+ if (!Array.isArray(tags)) tags = [tags];
1204
+ const probe = sharedConfig.context && sharedConfig.context._loadingPhase;
1205
+ let replaceable = null;
1206
+ for (let i = 0; i < tags.length; i++) {
1207
+ const desc = tags[i];
1208
+ if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
1209
+ headTagInvalid("non-head-tag", `useHead: ignoring non-head tag <${desc && desc.tag}>`, desc);
1210
+ continue;
1211
+ }
1212
+ const cls = classifyHeadTag(desc);
1213
+ if (probe && !cls.resource) {
1214
+ try {
1215
+ evalHeadProps(desc.props || {}, cls.rel !== undefined ? {
1216
+ rel: cls.rel
1217
+ } : undefined);
1218
+ evalHeadValue(desc.key);
1219
+ } catch (err) {
1220
+ if (ssrHandleError(err)) throw err;
1221
+ }
1222
+ }
1223
+ if (cls.resource) {
1224
+ emitHeadResource(registry, context, tracking, emitResource, nonce, desc, cls.rel);
1225
+ } else {
1226
+ (replaceable || (replaceable = [])).push(cls.rel !== undefined ? {
1227
+ tag: desc.tag,
1228
+ props: desc.props,
1229
+ key: desc.key,
1230
+ rel: cls.rel
1231
+ } : desc);
1232
+ }
1233
+ }
1234
+ if (replaceable) registry.pending.push({
1235
+ boundary,
1236
+ tags: replaceable
1237
+ });
1238
+ }
1239
+ function headShellReady(registry, block) {
1240
+ let ready = true;
1241
+ const pends = err => {
1242
+ const source = ssrHandleError(err, true);
1243
+ if (!source) return false;
1244
+ block(source);
1245
+ ready = false;
1246
+ return true;
1247
+ };
1248
+ const parked = registry.parkedResources;
1249
+ for (let i = parked.length - 1; i >= 0; i--) {
1250
+ const {
1251
+ desc,
1252
+ rel,
1253
+ emit
1254
+ } = parked[i];
1255
+ try {
1256
+ evalHeadProps(desc.props || {}, rel !== undefined ? {
1257
+ rel
1258
+ } : undefined);
1259
+ } catch (err) {
1260
+ if (pends(err)) continue;
1261
+ headTagInvalid("props-error", `useHead: error evaluating resource tag props: ${errorText(err)}`, err);
1262
+ parked.splice(i, 1);
1263
+ continue;
1264
+ }
1265
+ parked.splice(i, 1);
1266
+ emit();
1267
+ }
1268
+ for (let i = 0; i < registry.pending.length; i++) {
1269
+ const reg = registry.pending[i];
1270
+ if (reg.boundary !== "" || reg.list) continue;
1271
+ for (let j = 0; j < reg.tags.length; j++) {
1272
+ const desc = reg.tags[j];
1273
+ try {
1274
+ evalHeadProps(desc.props || {}, desc.rel !== undefined ? {
1275
+ rel: desc.rel
1276
+ } : undefined);
1277
+ evalHeadValue(desc.key);
1278
+ } catch (err) {
1279
+ pends(err);
1280
+ }
1281
+ }
1282
+ }
1283
+ return ready;
1284
+ }
1285
+ function emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel) {
1286
+ let props;
1287
+ try {
1288
+ props = evalHeadProps(desc.props || {}, rel !== undefined ? {
1289
+ rel
1290
+ } : undefined);
1291
+ } catch (err) {
1292
+ const loadingPhase = sharedConfig.context && sharedConfig.context._loadingPhase;
1293
+ if (loadingPhase && ssrHandleError(err)) throw err;
1294
+ if (!loadingPhase && !context._currentBoundaryId && !registry.shellFlushed && typeof context.block === "function" && ssrHandleError(err, true)) {
1295
+ registry.parkedResources.push({
1296
+ desc,
1297
+ rel,
1298
+ emit: () => emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel)
1299
+ });
1300
+ return;
1301
+ }
1302
+ headTagInvalid("props-error", `useHead: error evaluating resource tag props: ${errorText(err)}`, err);
1303
+ return;
1304
+ }
1305
+ const identity = resourceIdentity(desc.tag, props);
1306
+ if (registry.resources.has(identity)) return;
1307
+ registry.resources.add(identity);
1308
+ if (desc.tag === "link" && (rel === "stylesheet" || rel === "modulepreload")) {
1309
+ let plain = true;
1310
+ let gateable = rel === "stylesheet";
1311
+ for (const name in props) {
1312
+ if (name === "rel" || name === "href") continue;
1313
+ plain = false;
1314
+ if (!STYLESHEET_FETCH_META.has(name)) gateable = false;
1315
+ }
1316
+ if (plain && props.href != null) {
1317
+ const isCss = isCssUrl(props.href);
1318
+ if (rel === "stylesheet" ? isCss : !isCss) {
1319
+ context.registerAsset(rel === "stylesheet" ? "style" : "module", props.href);
1320
+ return;
1321
+ }
1322
+ }
1323
+ if (gateable && props.href != null) {
1324
+ const attrHtml = renderHeadAttrHtml(props);
1325
+ const entry = {
1326
+ href: props.href,
1327
+ attrHtml,
1328
+ attrs: headAttrRecord(props)
1329
+ };
1330
+ if (tracking.currentBoundaryId) {
1331
+ let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
1332
+ if (!styles) tracking.boundaryStyles.set(tracking.currentBoundaryId, styles = new Set());
1333
+ styles.add(entry);
1334
+ }
1335
+ const markup = `<link${attrHtml}${nonceAttr(nonce, "style")}>`;
1336
+ if (emitResource) emitResource(markup, entry);else {
1337
+ registry.eagerHtml += markup;
1338
+ entry.emitted = true;
1339
+ }
1340
+ return;
1341
+ }
1342
+ }
1343
+ const url = props.href || props.src;
1344
+ if (url != null && tracking.emittedAssets.has(url)) return;
1345
+ const markup = renderHeadTagMarkup(desc.tag, props, null, nonce);
1346
+ if (emitResource) emitResource(markup);else registry.eagerHtml += markup;
1347
+ }
1348
+ function commitHeadBoundary(registry, boundary, isPendingFragment) {
1349
+ const keep = [];
1350
+ const groups = [];
1351
+ for (let i = 0; i < registry.pending.length; i++) {
1352
+ const reg = registry.pending[i];
1353
+ const mine = boundary === "" ? !(isPendingFragment && reg.boundary !== "" && isPendingFragment(reg.boundary)) : reg.boundary === boundary;
1354
+ if (!mine) {
1355
+ keep.push(reg);
1356
+ continue;
1357
+ }
1358
+ let descs = reg.tags;
1359
+ if (reg.list) {
1360
+ let resolved;
1361
+ try {
1362
+ resolved = reg.list();
1363
+ } catch (err) {
1364
+ headTagInvalid("group-error", `useHead: error evaluating head group membership: ${errorText(err)}`, err);
1365
+ continue;
1366
+ }
1367
+ if (!Array.isArray(resolved)) resolved = [resolved];
1368
+ descs = [];
1369
+ for (let j = 0; j < resolved.length; j++) {
1370
+ const desc = resolved[j];
1371
+ if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
1372
+ headTagInvalid("non-head-tag", `useHead: ignoring non-head tag <${desc && desc.tag}>`, desc);
1373
+ continue;
1374
+ }
1375
+ const cls = classifyHeadTag(desc);
1376
+ if (cls.resource) {
1377
+ reg.resource(desc, cls.rel);
1378
+ } else {
1379
+ descs.push(cls.rel !== undefined ? {
1380
+ tag: desc.tag,
1381
+ props: desc.props,
1382
+ key: desc.key,
1383
+ rel: cls.rel
1384
+ } : desc);
1385
+ }
1386
+ }
1387
+ }
1388
+ const tags = [];
1389
+ for (let j = 0; j < descs.length; j++) {
1390
+ const desc = descs[j];
1391
+ let props, key;
1392
+ try {
1393
+ props = evalHeadProps(desc.props || {}, desc.rel !== undefined ? {
1394
+ rel: desc.rel
1395
+ } : undefined);
1396
+ key = evalHeadValue(desc.key);
1397
+ } catch (err) {
1398
+ headTagInvalid("props-error", `useHead: error evaluating tag props: ${errorText(err)}`, err);
1399
+ continue;
1400
+ }
1401
+ const identity = replaceableIdentity(desc.tag, props, key, "u:" + registry.uniq++);
1402
+ if ((identity === "base" || identity === "charset") && registry.shellFlushed) {
1403
+ headTagInvalid("after-shell-flush", `useHead: <${desc.tag}> (${identity}) registered after shell flush is ignored`, identity);
1404
+ continue;
1405
+ }
1406
+ tags.push({
1407
+ tag: desc.tag,
1408
+ props,
1409
+ identity
1410
+ });
1411
+ }
1412
+ if (tags.length) groups.push({
1413
+ seq: registry.seq++,
1414
+ tags
1415
+ });
1416
+ }
1417
+ registry.pending = keep;
1418
+ for (let i = 0; i < groups.length; i++) registry.committed.push(groups[i]);
1419
+ return groups;
1420
+ }
1421
+ function adoptHeadBoundary(registry, childKey, parentKey) {
1422
+ for (let i = 0; i < registry.pending.length; i++) {
1423
+ if (registry.pending[i].boundary === childKey) registry.pending[i].boundary = parentKey;
1424
+ }
1425
+ }
1426
+ function dropHeadBoundary(registry, boundary) {
1427
+ registry.pending = registry.pending.filter(reg => reg.boundary !== boundary);
1428
+ }
1429
+ function headGroupSignature(winner) {
1430
+ let sig = "" + winner.seq;
1431
+ for (let i = 0; i < winner.tags.length; i++) {
1432
+ const t = winner.tags[i];
1433
+ sig += "|" + t.tag + JSON.stringify(t.props);
1434
+ }
1435
+ return sig;
1436
+ }
1437
+ function renderShellHead(registry, nonce, isPendingFragment, noScripts, traceMetas = "") {
1438
+ commitHeadBoundary(registry, "", isPendingFragment);
1439
+ registry.shellFlushed = true;
1440
+ const winners = resolveHead(registry.committed);
1441
+ registry.flushed = new Map();
1442
+ let prelude = "";
1443
+ let links = "";
1444
+ let metas = "";
1445
+ let others = "";
1446
+ let scripts = "";
1447
+ let title = null;
1448
+ for (const [identity, winner] of winners) {
1449
+ registry.flushed.set(identity, headGroupSignature(winner));
1450
+ if (identity === "title") {
1451
+ const children = winner.tags[0].props.children;
1452
+ title = children == null ? "" : String(children);
1453
+ continue;
1454
+ }
1455
+ for (let i = 0; i < winner.tags.length; i++) {
1456
+ const t = winner.tags[i];
1457
+ const markup = renderHeadTagMarkup(t.tag, t.props, identity, nonce);
1458
+ if (identity === "charset" || identity === "base") prelude += markup;else if (t.tag === "link" || t.tag === "style") links += markup;else if (t.tag === "meta") metas += markup;else if (t.tag === "script") scripts += markup;else others += markup;
1459
+ }
1460
+ }
1461
+ return {
1462
+ prelude,
1463
+ html: registry.eagerHtml + links + metas + traceMetas + others + scripts,
1464
+ title,
1465
+ noScripts
1466
+ };
1467
+ }
1468
+ function flushHeadFragment(registry, boundary, nonce) {
1469
+ const groups = commitHeadBoundary(registry, boundary);
1470
+ if (!groups.length) return null;
1471
+ const winners = resolveHead(registry.committed);
1472
+ const affected = new Set();
1473
+ for (let i = 0; i < groups.length; i++) for (let j = 0; j < groups[i].tags.length; j++) affected.add(groups[i].tags[j].identity);
1474
+ const ops = [];
1475
+ for (const identity of affected) {
1476
+ const winner = winners.get(identity);
1477
+ const sig = headGroupSignature(winner);
1478
+ if (registry.flushed.get(identity) === sig) continue;
1479
+ const existed = registry.flushed.has(identity);
1480
+ registry.flushed.set(identity, sig);
1481
+ if (identity === "title") {
1482
+ const children = winner.tags[0].props.children;
1483
+ ops.push(["t", children == null ? "" : String(children)]);
1484
+ continue;
1485
+ }
1486
+ if (existed) ops.push(["r", identity]);
1487
+ for (let i = 0; i < winner.tags.length; i++) {
1488
+ const t = winner.tags[i];
1489
+ const attrs = {};
1490
+ for (const name in t.props) {
1491
+ if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
1492
+ if (!HEAD_ATTR_NAME.test(name)) {
1493
+ headTagInvalid("invalid-attribute", `useHead: ignoring invalid attribute name "${name}"`, name);
1494
+ continue;
1495
+ }
1496
+ const v = t.props[name];
1497
+ if (v == null || v === false) continue;
1498
+ attrs[name] = v === true ? "" : String(v);
1499
+ }
1500
+ if (nonce && !hasNonceProp(t.props)) {
1501
+ const destination = nonceDestination(t.tag, t.props);
1502
+ const value = destination && nonce[destination];
1503
+ if (value) attrs.nonce = String(value);
1504
+ }
1505
+ const children = t.props.children;
1506
+ ops.push(["a", identity, t.tag, attrs, children == null ? null : String(children)]);
1507
+ }
1508
+ }
1509
+ return ops.length ? ops : null;
1510
+ }
1511
+ function normalizeNonce(nonce) {
1512
+ if (nonce == null) return undefined;
1513
+ if (typeof nonce === "string") {
1514
+ const attr = nonce ? ` nonce="${escape(nonce, true)}"` : "";
1515
+ return {
1516
+ script: nonce,
1517
+ style: nonce,
1518
+ scriptAttr: attr,
1519
+ styleAttr: attr
1520
+ };
1521
+ }
1522
+ const script = nonce.script;
1523
+ const style = nonce.style;
1524
+ if (!script && !style) return undefined;
1525
+ return {
1526
+ script,
1527
+ style,
1528
+ scriptAttr: typeof script === "string" && script ? ` nonce="${escape(script, true)}"` : "",
1529
+ styleAttr: typeof style === "string" && style ? ` nonce="${escape(style, true)}"` : ""
1530
+ };
1531
+ }
1532
+ function destinationNonce(nonce, destination) {
1533
+ if (nonce == null) return undefined;
1534
+ if (typeof nonce === "string") return nonce || undefined;
1535
+ const value = nonce[destination];
1536
+ return typeof value === "string" && value ? value : undefined;
1537
+ }
1538
+ function scriptNonce(nonce) {
1539
+ return destinationNonce(nonce, "script");
1540
+ }
1541
+ function styleNonce(nonce) {
1542
+ return destinationNonce(nonce, "style");
1543
+ }
1544
+ function hasNonceProp(props) {
1545
+ for (const name in props) if (name.length === 5 && asciiLowerCase(name) === "nonce" && props[name] != null) return true;
1546
+ return false;
1547
+ }
1548
+ function nonceDestination(tag, props) {
1549
+ if (tag === "script") return "script";
1550
+ if (tag === "style") return "style";
1551
+ if (tag !== "link") return null;
1552
+ const rel = props.rel;
1553
+ if (typeof rel !== "string") return null;
1554
+ const rels = asciiLowerCase(rel).split(/[\t\n\f\r ]+/);
1555
+ if (rels.includes("stylesheet")) return "style";
1556
+ const isModulePreload = rels.includes("modulepreload");
1557
+ if (!isModulePreload && !rels.includes("preload")) return null;
1558
+ const as = typeof props.as === "string" ? asciiLowerCase(props.as) : "";
1559
+ if (as === "style") return "style";
1560
+ if (as === "script") return "script";
1561
+ if (!isModulePreload) return null;
1562
+ switch (as) {
1563
+ case "fetch":
1564
+ case "font":
1565
+ case "image":
1566
+ case "json":
1567
+ case "text":
1568
+ case "track":
1569
+ return null;
1570
+ default:
1571
+ return "script";
1572
+ }
1573
+ }
1574
+ function nonceAttr(nonce, destination) {
1575
+ if (!nonce || !destination) return "";
1576
+ return destination === "script" ? nonce.scriptAttr : nonce.styleAttr;
1577
+ }
1578
+ function renderHeadAttrHtml(props) {
1579
+ let attrs = "";
1580
+ for (const name in props) {
1581
+ if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
1582
+ if (!HEAD_ATTR_NAME.test(name)) {
1583
+ headTagInvalid("invalid-attribute", `useHead: ignoring invalid attribute name "${name}"`, name);
1584
+ continue;
1585
+ }
1586
+ const v = props[name];
1587
+ if (v == null || v === false) continue;
1588
+ attrs += v === true ? ` ${name}` : ` ${name}="${escape(String(v), true)}"`;
1589
+ }
1590
+ return attrs;
1591
+ }
1592
+ function headAttrRecord(props, skipRelHref) {
1593
+ let attrs = null;
1594
+ for (const name in props) {
1595
+ if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
1596
+ if ((name === "rel" || name === "href")) continue;
1597
+ if (!HEAD_ATTR_NAME.test(name)) continue;
1598
+ const v = props[name];
1599
+ if (v == null || v === false) continue;
1600
+ (attrs || (attrs = {}))[name] = v === true ? "" : String(v);
1601
+ }
1602
+ return attrs;
1603
+ }
1604
+ function renderHeadTagMarkup(tag, props, identity, nonce) {
1605
+ let attrs = renderHeadAttrHtml(props);
1606
+ if (identity != null) attrs += ` data-dh="${escape(identity, true)}"`;
1607
+ if (nonce && !hasNonceProp(props)) attrs += nonceAttr(nonce, nonceDestination(tag, props));
1608
+ if (tag === "meta" || tag === "link" || tag === "base") return `<${tag}${attrs}>`;
1609
+ let body = props.children == null ? "" : String(props.children);
1610
+ if (tag === "script") body = body.replace(/<\/(script)/gi, "<\\/$1");else if (tag === "style") body = escapeStyleContent(body);else body = escape(body);
1611
+ return `<${tag}${attrs}>${body}</${tag}>`;
1612
+ }
1613
+ function useHead(tags) {
1614
+ const ctx = sharedConfig.context;
1615
+ if (!ctx || !ctx.registerHeadTags) {
1616
+ headTagInvalid("outside-render", "useHead() called outside of a server render; registration ignored.");
1617
+ return;
1618
+ }
1619
+ ctx.registerHeadTags(tags);
1620
+ }
1621
+ const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
1622
+ const tagInfos = /*#__PURE__*/new Map();
1623
+ function tagInfo(tag) {
1624
+ let info = tagInfos.get(tag);
1625
+ if (info === undefined) {
1626
+ info = {
1627
+ open: "<" + tag,
1628
+ close: "</" + tag + ">",
1629
+ isVoid: VOID_ELEMENTS.test(tag),
1630
+ textarea: tag === "textarea",
1631
+ raw: tag === "script" || tag === "style"
1632
+ };
1633
+ if (tagInfos.size < 512) tagInfos.set(tag, info);
1634
+ }
1635
+ return info;
1636
+ }
1637
+ const safeAttrNames = /*#__PURE__*/new Set();
1638
+ function attrName(prop) {
1639
+ if (safeAttrNames.has(prop)) return prop;
1640
+ const escaped = escape(prop);
1641
+ if (escaped === prop && safeAttrNames.size < 512) safeAttrNames.add(prop);
1642
+ return escaped;
1643
+ }
1644
+ const REPLACE_SCRIPT = `function $df(e){return _$HY.f?_$HY.f(e):$dfr(e)}function $dfr(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById("pl-"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!=="pl-"+e);)t=o.nextSibling,o.remove(),o=t;t=o.parentNode,o.replaceWith(n.content),n.remove(),(_$HY.v=_$HY.v||{})[e]=1,_$HY.fe(e,t),_$HY.hp&&_$HY.hp[e]&&($dh(_$HY.hp[e]),delete _$HY.hp[e]),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById("pl-"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue==="pl-"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}`;
1645
+ const HEAD_SCRIPT = `function $dha(o,i,e,n){for(i=0;i<o.length;i++)e=o[i],"t"==e[0]?((n=document.querySelector("title"))?n.hasAttribute("data-dh")||n.setAttribute("data-dhf",n.textContent):(n=document.createElement("title"),document.head.appendChild(n)),n.textContent=e[1],n.setAttribute("data-dh","title")):"r"==e[0]?$dhr(e[1]):(n=document.createElement(e[2]),Object.keys(e[3]).forEach(function(a){n.setAttribute(a,e[3][a])}),null!=e[4]&&(n.textContent=e[4]),n.setAttribute("data-dh",e[1]),document.head.appendChild(n))}function $dhr(v,l,i){for(l=document.head.querySelectorAll("[data-dh]"),i=0;i<l.length;i++)l[i].getAttribute("data-dh")==v&&l[i].remove()}function $dh(o){_$HY.h?_$HY.h(o):$dha(o)}`;
1646
+ function renderToString(code, options = {}) {
1647
+ const {
1648
+ renderId = "",
1649
+ noScripts,
1650
+ manifest,
1651
+ onHead
1652
+ } = options;
1653
+ const nonce = normalizeNonce(options.nonce);
1654
+ let scripts = "";
1655
+ const serializer = createHydrationSerializer({
1656
+ scopeId: renderId,
1657
+ plugins: options.plugins,
1658
+ onData(script) {
1659
+ if (noScripts) return;
1660
+ if (!scripts) {
1661
+ scripts = getLocalHeaderScript(renderId);
1662
+ }
1663
+ scripts += script + ";";
1664
+ },
1665
+ onError: serializerErrorHook(options.onError)
1666
+ });
1667
+ const tracking = createAssetTracking();
1668
+ const headRegistry = createHeadRegistry();
1669
+ sharedConfig.context = {
1670
+ nonce: options.nonce,
1671
+ escape: escape,
1672
+ resolve: resolveSSRNode,
1673
+ ssr: ssr,
1674
+ errorPolicy: options.onError,
1675
+ registerHeadTags(tags) {
1676
+ registerHeadTags(headRegistry, sharedConfig.context, tracking, null, nonce, tags);
1677
+ },
1678
+ serialize(id, p) {
1679
+ if (sharedConfig.context.noHydrate) return;
1680
+ if (p != null && typeof p === "object" && (typeof p.then === "function" || typeof p[Symbol.asyncIterator] === "function")) {
1681
+ throw new Error("Cannot serialize async value in renderToString (id: " + id + "). " + "Use renderToStream for async data.");
1682
+ }
1683
+ serializer.write(id, p);
1684
+ },
1685
+ registerAsset(type, value) {
1686
+ if (type === "preload") {
1687
+ registerPreloadLink(tracking, headRegistry, value, nonce);
1688
+ return;
1689
+ }
1690
+ if (type === "inline-style") {
1691
+ tracking.registerInlineStyle(value);
1692
+ return;
1693
+ }
1694
+ if (tracking.currentBoundaryId && type === "style") {
1695
+ let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
1696
+ if (!styles) {
1697
+ styles = new Set();
1698
+ tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
1699
+ }
1700
+ styles.add(value);
1701
+ }
1702
+ tracking.emittedAssets.add(value);
1703
+ }
1704
+ };
1705
+ applyAssetTracking(sharedConfig.context, tracking, manifest, noScripts);
1706
+ registerEntryAssets(manifest);
1707
+ const context = sharedConfig.context;
1708
+ const requestEvent = peekRequestEvent();
1709
+ context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
1710
+ const render = timeDocument(context, context.trace, "string", requestEvent);
1711
+ let dispose;
1712
+ let rendered = false;
1713
+ try {
1714
+ const html = createRoot(d => {
1715
+ dispose = d;
1716
+ return resolveSSRSync(escape(code()));
1717
+ }, {
1718
+ id: renderId
1719
+ });
1720
+ serializeFragmentAssets("", tracking.boundaryModules, sharedConfig.context, renderId);
1721
+ sharedConfig.context.noHydrate = true;
1722
+ serializer.close();
1723
+ const head = renderShellHead(headRegistry, nonce, null, noScripts, traceMetaMarkup(context.trace));
1724
+ const document = assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead);
1725
+ if (render) render.shell();
1726
+ if (requestEvent && requestEvent.response) {
1727
+ commitResponseStub(requestEvent.response, {
1728
+ event: requestEvent
1729
+ });
1730
+ }
1731
+ rendered = true;
1732
+ return document;
1733
+ } finally {
1734
+ if (render) render.settle(rendered ? "complete" : "error");
1735
+ context.trace = undefined;
1736
+ if (dispose) dispose();
1737
+ }
1738
+ }
1739
+ function renderToStream(code, options = {}) {
1740
+ let {
1741
+ onCompleteShell,
1742
+ onCompleteAll,
1743
+ renderId = "",
1744
+ noScripts,
1745
+ manifest,
1746
+ onHead
1747
+ } = options;
1748
+ const nonce = normalizeNonce(options.nonce);
1749
+ const requestEvent = peekRequestEvent();
1750
+ let dispose;
1751
+ let dead = false;
1752
+ let render;
1753
+ let serializer;
1754
+ let disconnected = false;
1755
+ let failed = false;
1756
+ let onFailed;
1757
+ const defuse = p => {
1758
+ if (p && typeof p.then === "function") p.then(undefined, () => {});
1759
+ };
1760
+ const abandonedSerializer = {
1761
+ write(_, value) {
1762
+ defuse(value);
1763
+ },
1764
+ flush() {},
1765
+ close() {}
1766
+ };
1767
+ const onFailure = complete => {
1768
+ if (failed) return complete(undefined);
1769
+ const prev = onFailed;
1770
+ onFailed = prev ? sink => {
1771
+ prev(sink);
1772
+ complete(sink);
1773
+ } : complete;
1774
+ };
1775
+ const abandon = disconnect => {
1776
+ if (dead) return;
1777
+ if (disconnect) emitFinding({
1778
+ code: "SSR_STREAM_ABANDONED",
1779
+ kind: "ssr",
1780
+ severity: "warn",
1781
+ message: `[SSR_STREAM_ABANDONED] The response stream was abandoned mid-render (${disconnect}) ` + `with ${registry.size} fragment(s) still pending; the render was torn down.`,
1782
+ data: {
1783
+ reason: disconnect,
1784
+ shellFlushed: firstFlushed,
1785
+ pendingFragments: registry.size
1786
+ }
1787
+ }, null);
1788
+ dead = true;
1789
+ completed = true;
1790
+ if (disconnect) disconnected = true;
1791
+ if (render) render.settle(disconnect ? "abandoned" : "error");
1792
+ const sink = writable;
1793
+ buffer = {
1794
+ write() {}
1795
+ };
1796
+ writable = {
1797
+ end() {}
1798
+ };
1799
+ if (dispose) {
1800
+ const d = dispose;
1801
+ dispose = () => {};
1802
+ d();
1803
+ }
1804
+ if (serializer && typeof serializer.close === "function") {
1805
+ try {
1806
+ serializer.close();
1807
+ } catch (err) {
1808
+ reportServerError(err, {
1809
+ kind: "render",
1810
+ handling: "serialize"
1811
+ }, null, options.onError);
1812
+ }
1813
+ }
1814
+ serializer = abandonedSerializer;
1815
+ if (stubBatch) {
1816
+ for (const p of stubBatch.values()) defuse(p);
1817
+ stubBatch = null;
1818
+ }
1819
+ if (!disconnect) {
1820
+ failed = true;
1821
+ onFailed && onFailed(sink);
1822
+ }
1823
+ };
1824
+ const failRender = err => {
1825
+ reportServerError(err, {
1826
+ kind: "render",
1827
+ handling: "failed"
1828
+ }, null);
1829
+ if (!options.onError && ambientServerErrorHook() === undefined) console.error(err);
1830
+ abandon();
1831
+ };
1832
+ const failRootRender = err => {
1833
+ emitFinding({
1834
+ code: "SSR_RENDER_ERROR_CONTAINED",
1835
+ kind: "ssr",
1836
+ severity: "error",
1837
+ message: `[SSR_RENDER_ERROR_CONTAINED] Render error outside any boundary — the request failed: ` + errorText(err),
1838
+ data: {
1839
+ handling: "failed",
1840
+ error: err
1841
+ }
1842
+ }, null);
1843
+ failRender(err);
1844
+ };
1845
+ const coalesceWrites = (writeRaw, endRaw) => {
1846
+ let buf = "";
1847
+ let scheduled = false;
1848
+ const flush = () => {
1849
+ scheduled = false;
1850
+ if (!buf) return;
1851
+ const out = buf;
1852
+ buf = "";
1853
+ writeRaw(out);
1854
+ };
1855
+ return {
1856
+ write(payload) {
1857
+ buf += payload;
1858
+ if (buf.length >= 16384) return flush();
1859
+ if (!scheduled) {
1860
+ scheduled = true;
1861
+ deferFlush(flush);
1862
+ }
1863
+ },
1864
+ flush,
1865
+ end() {
1866
+ flush();
1867
+ endRaw();
1868
+ }
1869
+ };
1870
+ };
1871
+ const guardSink = w => ({
1872
+ write(payload) {
1873
+ if (disconnected) return;
1874
+ try {
1875
+ w.write(payload);
1876
+ } catch (_) {
1877
+ abandon("sink");
1878
+ }
1879
+ },
1880
+ end() {
1881
+ if (disconnected) return;
1882
+ try {
1883
+ w.end();
1884
+ } catch (_) {
1885
+ abandon("sink");
1886
+ }
1887
+ }
1888
+ });
1889
+ const blockingPromises = new Set();
1890
+ const canBatchStubs = !options.serializer && !options.sink;
1891
+ let stubBatch = null;
1892
+ const STUB_BATCH_KEY = "$B";
1893
+ const flushStubBatch = () => {
1894
+ if (!stubBatch) return;
1895
+ const batch = stubBatch;
1896
+ stubBatch = null;
1897
+ if (batch.size === 1) {
1898
+ const [id, p] = batch.entries().next().value;
1899
+ serializer.write(id, p);
1900
+ return;
1901
+ }
1902
+ const obj = {};
1903
+ for (const [id, p] of batch) obj[id] = p;
1904
+ serializer.write(STUB_BATCH_KEY, obj);
1905
+ pushTask(`(b=>{for(var k in b)_$HY.r[k]=b[k];delete _$HY.r["${STUB_BATCH_KEY}"]})(_$HY.r["${STUB_BATCH_KEY}"])`);
1906
+ };
1907
+ let headerEmitted = false;
1908
+ const pushTask = task => {
1909
+ if (noScripts) return;
1910
+ if (!headerEmitted) {
1911
+ headerEmitted = true;
1912
+ tasks += getLocalHeaderScript(renderId);
1913
+ }
1914
+ tasks += task + ";";
1915
+ if (!timer && firstFlushed) {
1916
+ timer = true;
1917
+ queue(() => queue(writeTasks));
1918
+ }
1919
+ };
1920
+ const onDone = () => {
1921
+ if (dead) return;
1922
+ writeTasks();
1923
+ lastBlockingSize = blockingPromises.size;
1924
+ doShell();
1925
+ onCompleteAll && onCompleteAll({
1926
+ write(v) {
1927
+ !completed && buffer.write(v);
1928
+ }
1929
+ });
1930
+ writable && writable.end();
1931
+ completed = true;
1932
+ if (render) render.settle("complete");
1933
+ if (firstFlushed) dispose();
1934
+ };
1935
+ const sink = {
1936
+ data(payload) {
1937
+ pushTask(payload);
1938
+ },
1939
+ fragment(key, value, meta) {
1940
+ const deferActivation = !!meta.revealGroup;
1941
+ const styles = meta.styles;
1942
+ for (let i = 0; i < styles.inline.length; i++) {
1943
+ buffer.write(renderInlineStyle(styles.inline[i], nonce));
1944
+ }
1945
+ if (styles.links.length) {
1946
+ const styleAttr = nonceAttr(nonce, "style");
1947
+ emitTask(`$dfs("${key}",${styles.links.length},${deferActivation ? 1 : 0})`);
1948
+ writeTasks();
1949
+ for (const entry of styles.links) {
1950
+ buffer.write(typeof entry === "string" ? `<link rel="stylesheet" href="${entry}"${styleAttr} onload="$dfc('${key}')" onerror="$dfc('${key}')">` : `<link${entry.attrHtml}${styleAttr} onload="$dfc('${key}')" onerror="$dfc('${key}')">`);
1951
+ }
1952
+ buffer.write(`<template id="${key}">${value}</template>`);
1953
+ } else {
1954
+ buffer.write(`<template id="${key}">${value}</template>`);
1955
+ if (!deferActivation) {
1956
+ emitTask(`$df("${key}")`);
1957
+ }
1958
+ }
1959
+ },
1960
+ reveal(keys, meta) {
1961
+ emitTask(`${meta.fallback ? "$dflj" : "$dfj"}(${JSON.stringify(keys)})`);
1962
+ },
1963
+ asset(type, value) {
1964
+ if (type === "module") {
1965
+ buffer.write(`<link rel="modulepreload" href="${value}"${nonceAttr(nonce, "script")}>`);
1966
+ } else if (type === "preload") {
1967
+ buffer.write(`<link${value.attrHtml}>`);
1968
+ } else if (type === "inline-style") {
1969
+ buffer.write(renderInlineStyle(value, nonce));
1970
+ } else if (type === "head-tag") {
1971
+ buffer.write(value);
1972
+ }
1973
+ },
1974
+ shell(shellHtml, meta) {
1975
+ buffer.write(assembleDocument(shellHtml, meta.preloads, meta.preloadLinks, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead));
1976
+ },
1977
+ ...options.sink
1978
+ };
1979
+ serializer = (options.serializer || createHydrationSerializer)({
1980
+ scopeId: options.renderId,
1981
+ plugins: options.plugins,
1982
+ onData: payload => sink.data(payload),
1983
+ onDone,
1984
+ onError: serializerErrorHook(options.onError)
1985
+ });
1986
+ let rootAssetsSerialized = false;
1987
+ const serializeRootAssets = () => {
1988
+ if (rootAssetsSerialized) return;
1989
+ rootAssetsSerialized = true;
1990
+ serializeFragmentAssets("", tracking.boundaryModules, context, renderId);
1991
+ };
1992
+ let holds = 0;
1993
+ const flushEnd = () => {
1994
+ if (!registry.size && !holds) {
1995
+ serializeRootAssets();
1996
+ queue(() => queue(() => {
1997
+ if (context.live.end) {
1998
+ const end = context.live.end;
1999
+ context.live.end = null;
2000
+ end();
2001
+ }
2002
+ flushStubBatch();
2003
+ serializer.flush();
2004
+ }));
2005
+ }
2006
+ };
2007
+ const registry = new Map();
2008
+ const pendingSerialized = new Map();
2009
+ const guardedChannels = new WeakMap();
2010
+ const verdictNow = error => {
2011
+ throw ssrSanitizeError(error, null);
2012
+ };
2013
+ const borderForm = value => toBorderForm(value);
2014
+ const guardIterable = iterable => ({
2015
+ [Symbol.asyncIterator]() {
2016
+ const iterator = iterable[Symbol.asyncIterator]();
2017
+ return {
2018
+ next: value => iterator.next(value).then(undefined, verdictNow),
2019
+ return: value => iterator.return ? iterator.return(value) : Promise.resolve({
2020
+ done: true,
2021
+ value
2022
+ }),
2023
+ throw: error => iterator.throw ? iterator.throw(error) : Promise.reject(error)
2024
+ };
2025
+ }
2026
+ });
2027
+ const guardStream = source => {
2028
+ const reader = source.getReader();
2029
+ return new ReadableStream({
2030
+ pull: c => reader.read().then(r => r.done ? c.close() : c.enqueue(r.value), e => {
2031
+ try {
2032
+ verdictNow(e);
2033
+ } catch (sanitized) {
2034
+ c.error(sanitized);
2035
+ }
2036
+ }),
2037
+ cancel: reason => reader.cancel(reason)
2038
+ });
2039
+ };
2040
+ const guardChannel = p => {
2041
+ if (!p || typeof p !== "object" || "__SEROVAL_STREAM__" in p) return p;
2042
+ let guarded = guardedChannels.get(p);
2043
+ if (guarded !== undefined) return guarded;
2044
+ if (typeof p.then === "function") {
2045
+ guarded = p.then(borderForm, verdictNow);
2046
+ } else if (typeof ReadableStream === "function" && p instanceof ReadableStream) {
2047
+ guarded = guardStream(p);
2048
+ } else {
2049
+ const border = borderForm(p);
2050
+ guarded = typeof border[Symbol.asyncIterator] === "function" ? guardIterable(border) : border;
2051
+ if (guarded === p) return p;
2052
+ }
2053
+ guardedChannels.set(p, guarded);
2054
+ return guarded;
2055
+ };
2056
+ const trackSerialized = (id, p) => {
2057
+ let settle;
2058
+ const raced = Promise.race([p, new Promise(r => settle = r)]);
2059
+ raced.catch(() => {});
2060
+ pendingSerialized.set(id, settle);
2061
+ const drop = () => pendingSerialized.delete(id);
2062
+ p.then(drop, drop);
2063
+ return raced;
2064
+ };
2065
+ const abandonSubtree = (key, error) => {
2066
+ let fragments = 0;
2067
+ let serialized = 0;
2068
+ for (const [k, entry] of registry) {
2069
+ if (k.length > key.length && k.startsWith(key)) {
2070
+ registry.delete(k);
2071
+ entry.resolve();
2072
+ fragments++;
2073
+ }
2074
+ }
2075
+ for (const [id, settle] of pendingSerialized) {
2076
+ if (id.startsWith(key)) {
2077
+ pendingSerialized.delete(id);
2078
+ settle();
2079
+ serialized++;
2080
+ }
2081
+ }
2082
+ if ((fragments || serialized)) emitFinding({
2083
+ code: "SSR_SUBTREE_ABANDONED",
2084
+ kind: "ssr",
2085
+ severity: "warn",
2086
+ message: `[SSR_SUBTREE_ABANDONED] Fragment '${key}' failed with ${fragments} nested fragment(s) and ` + `${serialized} serialized value(s) still pending; the subtree was discarded and the client ` + `renders it from scratch.`,
2087
+ data: {
2088
+ fragment: key,
2089
+ fragments,
2090
+ serialized,
2091
+ error
2092
+ }
2093
+ }, null);
2094
+ };
2095
+ const writeTasks = () => {
2096
+ if (tasks.length && !completed && firstFlushed) {
2097
+ buffer.write(`<script${nonceAttr(nonce, "script")}>${tasks}</script>`);
2098
+ tasks = "";
2099
+ }
2100
+ timer = null;
2101
+ };
2102
+ let context;
2103
+ let writable;
2104
+ let tmp = "";
2105
+ let tasks = "";
2106
+ let firstFlushed = false;
2107
+ let completed = false;
2108
+ let shellCompleted = false;
2109
+ let scriptFlushed = false;
2110
+ let headStyles;
2111
+ const revealGroups = new Map();
2112
+ let timer = null;
2113
+ const emitTask = task => {
2114
+ pushTask(`${task}${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
2115
+ scriptFlushed = true;
2116
+ };
2117
+ function resolveRevealKeys(groupOrKeys, release, consume) {
2118
+ if (Array.isArray(groupOrKeys)) return groupOrKeys.slice();
2119
+ let group = revealGroups.get(groupOrKeys);
2120
+ if (!group) {
2121
+ if (!release) return;
2122
+ group = {
2123
+ order: [],
2124
+ keys: new Set(),
2125
+ released: true
2126
+ };
2127
+ revealGroups.set(groupOrKeys, group);
2128
+ } else if (release) group.released = true;
2129
+ if (!group.order.length) return;
2130
+ const keys = group.order.slice();
2131
+ if (consume) revealGroups.delete(groupOrKeys);
2132
+ return keys;
2133
+ }
2134
+ let rootHoles = null;
2135
+ let nextHoleId = 0;
2136
+ let buffer = {
2137
+ write(payload) {
2138
+ tmp += payload;
2139
+ }
2140
+ };
2141
+ const tracking = createAssetTracking();
2142
+ const headRegistry = createHeadRegistry();
2143
+ let headScriptFlushed = false;
2144
+ const emitHeadOps = (key, ops) => {
2145
+ const payload = JSON.stringify(ops).replace(/</g, "\\u003C");
2146
+ emitTask(`${!headScriptFlushed ? HEAD_SCRIPT : ""}(_$HY.hp=_$HY.hp||{})[${JSON.stringify(key)}]=${payload}`);
2147
+ headScriptFlushed = true;
2148
+ };
2149
+ sharedConfig.context = context = {
2150
+ async: true,
2151
+ nonce: options.nonce,
2152
+ document: !options.sink,
2153
+ live: {},
2154
+ registerHeadTags(tags) {
2155
+ registerHeadTags(headRegistry, context, tracking,
2156
+ (markup, gateEntry) => {
2157
+ if (!firstFlushed) {
2158
+ headRegistry.eagerHtml += markup;
2159
+ if (gateEntry) gateEntry.emitted = true;
2160
+ } else if (!gateEntry || !tracking.currentBoundaryId) {
2161
+ sink.asset("head-tag", markup);
2162
+ }
2163
+ }, nonce, tags);
2164
+ },
2165
+ registerAsset(type, value) {
2166
+ if (type === "preload") {
2167
+ const entry = registerPreloadLink(tracking, headRegistry, value, nonce);
2168
+ if (entry && firstFlushed) sink.asset("preload", entry);
2169
+ return;
2170
+ }
2171
+ if (type === "inline-style") {
2172
+ const entry = tracking.registerInlineStyle(value);
2173
+ if (firstFlushed && !tracking.currentBoundaryId && !entry.emitted) {
2174
+ entry.emitted = true;
2175
+ sink.asset("inline-style", entry);
2176
+ }
2177
+ return;
2178
+ }
2179
+ if (tracking.currentBoundaryId && type === "style") {
2180
+ let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
2181
+ if (!styles) {
2182
+ styles = new Set();
2183
+ tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
2184
+ }
2185
+ styles.add(value);
2186
+ }
2187
+ if (!tracking.emittedAssets.has(value)) {
2188
+ tracking.emittedAssets.add(value);
2189
+ if (firstFlushed) sink.asset(type, value);
2190
+ }
2191
+ },
2192
+ block(p) {
2193
+ if (!firstFlushed) blockingPromises.add(p);
2194
+ },
2195
+ hold() {
2196
+ holds++;
2197
+ let released = false;
2198
+ return () => {
2199
+ if (released) return;
2200
+ released = true;
2201
+ holds--;
2202
+ if (!holds) queue(flushEnd);
2203
+ };
2204
+ },
2205
+ replace(id, payloadFn) {
2206
+ if (firstFlushed) return;
2207
+ const placeholder = `<!--!$${id}-->`;
2208
+ const first = html.indexOf(placeholder);
2209
+ if (first === -1) return;
2210
+ const last = html.indexOf(`<!--!$/${id}-->`, first + placeholder.length);
2211
+ html = html.slice(0, first) + resolveSSRSync(escape(payloadFn())) + html.slice(last + placeholder.length + 1);
2212
+ },
2213
+ serialize(id, p, deferStream) {
2214
+ if (sharedConfig.context.noHydrate) return;
2215
+ p = guardChannel(p);
2216
+ if (p && typeof p === "object" && typeof p.then === "function") {
2217
+ if (!firstFlushed && deferStream) {
2218
+ blockingPromises.add(p);
2219
+ p.then(d => serializer.write(id, d)).catch(e => serializer.write(id, e));
2220
+ return;
2221
+ }
2222
+ p = trackSerialized(id, p);
2223
+ if (!firstFlushed && canBatchStubs && !shellCompleted && !dead) {
2224
+ (stubBatch ||= new Map()).set(id, p);
2225
+ return;
2226
+ }
2227
+ }
2228
+ serializer.write(id, p);
2229
+ },
2230
+ escape: escape,
2231
+ resolve: resolveSSRNode,
2232
+ ssr: ssr,
2233
+ registerFragment(key, options) {
2234
+ const revealGroup = options && options.revealGroup;
2235
+ if (revealGroup) {
2236
+ let group = revealGroups.get(revealGroup);
2237
+ if (!group) {
2238
+ group = {
2239
+ order: [],
2240
+ keys: new Set(),
2241
+ released: false
2242
+ };
2243
+ revealGroups.set(revealGroup, group);
2244
+ }
2245
+ if (!group.keys.has(key)) {
2246
+ group.keys.add(key);
2247
+ group.order.push(key);
2248
+ }
2249
+ if (group.released) {
2250
+ throw new Error("registerFragment() for reveal group '" + revealGroup + "' was called after revealFragments(). Ensure template payload is emitted before grouped reveal.");
2251
+ }
2252
+ }
2253
+ if (!registry.has(key)) {
2254
+ let resolve, reject;
2255
+ const p = new Promise((r, rej) => (resolve = r, reject = rej));
2256
+ defuse(p);
2257
+ registry.set(key, {
2258
+ resolve: err => queue(() => queue(() => {
2259
+ err ? reject(ssrSanitizeError(err, null)) : resolve(true);
2260
+ queue(flushEnd);
2261
+ }))
2262
+ });
2263
+ if (canBatchStubs && !shellCompleted && !dead) (stubBatch ||= new Map()).set(key + "_fr", p);else serializer.write(key + "_fr", p);
2264
+ }
2265
+ return (value, error) => {
2266
+ if (registry.has(key)) {
2267
+ const item = registry.get(key);
2268
+ registry.delete(key);
2269
+ if (error) abandonSubtree(key, error);
2270
+ if (item.children && !error) {
2271
+ for (const k in item.children) {
2272
+ value = replacePlaceholder(value, k, item.children[k]);
2273
+ }
2274
+ }
2275
+ const parentKey = waitForFragments(registry, key);
2276
+ if (parentKey) {
2277
+ const parent = registry.get(parentKey);
2278
+ parent.children ||= {};
2279
+ parent.children[key] = value !== undefined ? value : "";
2280
+ serializeFragmentAssets(key, tracking.boundaryModules, context);
2281
+ propagateBoundaryStyles(key, parentKey, tracking);
2282
+ adoptHeadBoundary(headRegistry, key, parentKey);
2283
+ item.resolve();
2284
+ return;
2285
+ }
2286
+ if (!completed) {
2287
+ if (error) dropHeadBoundary(headRegistry, key);
2288
+ if (!firstFlushed) {
2289
+ queue(() => html = replacePlaceholder(html, key, value !== undefined ? value : ""));
2290
+ serializeFragmentAssets(key, tracking.boundaryModules, context);
2291
+ item.resolve(error);
2292
+ } else {
2293
+ serializeFragmentAssets(key, tracking.boundaryModules, context);
2294
+ const styles = collectStreamStyles(key, tracking, headStyles);
2295
+ const headOps = error ? null : flushHeadFragment(headRegistry, key, nonce);
2296
+ if (headOps) emitHeadOps(key, headOps);
2297
+ sink.fragment(key, resolveSSRSelectValues(value !== undefined ? value : " "), {
2298
+ styles,
2299
+ revealGroup,
2300
+ error: error ? ssrSanitizeError(error, null) : error
2301
+ });
2302
+ item.resolve(error);
2303
+ }
2304
+ }
2305
+ }
2306
+ return firstFlushed;
2307
+ };
2308
+ },
2309
+ revealFragments(groupOrKeys) {
2310
+ const keys = resolveRevealKeys(groupOrKeys, true, true);
2311
+ if (!keys) return;
2312
+ sink.reveal(keys, {
2313
+ fallback: false
2314
+ });
2315
+ },
2316
+ revealFallbacks(groupOrKeys) {
2317
+ const keys = resolveRevealKeys(groupOrKeys, false, false);
2318
+ if (!keys) return;
2319
+ sink.reveal(keys, {
2320
+ fallback: true
2321
+ });
2322
+ }
2323
+ };
2324
+ applyAssetTracking(context, tracking, manifest, noScripts);
2325
+ context.failRender = failRender;
2326
+ context.errorPolicy = options.onError;
2327
+ context.flushed = () => firstFlushed;
2328
+ context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
2329
+ render = timeDocument(context, context.trace, "stream", requestEvent);
2330
+ registerEntryAssets(manifest);
2331
+ const signal = options.signal;
2332
+ const onAbort = signal ? () => abandon("signal") : undefined;
2333
+ let html = createRoot(d => {
2334
+ dispose = () => {
2335
+ context.trace = undefined;
2336
+ if (onAbort) signal.removeEventListener("abort", onAbort);
2337
+ d();
2338
+ };
2339
+ const res = resolveSSRNode(escape(code()));
2340
+ if (!res.h.length) return res.t[0];
2341
+ rootHoles = [];
2342
+ let out = res.t[0];
2343
+ for (let i = 0; i < res.h.length; i++) {
2344
+ const id = nextHoleId++;
2345
+ rootHoles.push({
2346
+ id,
2347
+ fn: res.h[i]
2348
+ });
2349
+ out += `<!--rh${id}-->` + res.t[i + 1];
2350
+ }
2351
+ for (const p of res.p) blockingPromises.add(p);
2352
+ return out;
2353
+ }, {
2354
+ id: renderId
2355
+ });
2356
+ if (onAbort) {
2357
+ if (signal.aborted) onAbort();else signal.addEventListener("abort", onAbort, {
2358
+ once: true
2359
+ });
2360
+ }
2361
+ function resolveRootHoles() {
2362
+ if (!rootHoles) return true;
2363
+ const pending = [];
2364
+ for (const {
2365
+ id,
2366
+ fn
2367
+ } of rootHoles) {
2368
+ const marker = `<!--rh${id}-->`;
2369
+ const res = resolveSSRNode(fn);
2370
+ if (!res.h.length) {
2371
+ html = html.replace(marker, res.t[0]);
2372
+ } else {
2373
+ let out = res.t[0];
2374
+ for (let j = 0; j < res.h.length; j++) {
2375
+ const newId = nextHoleId++;
2376
+ pending.push({
2377
+ id: newId,
2378
+ fn: res.h[j]
2379
+ });
2380
+ out += `<!--rh${newId}-->` + res.t[j + 1];
2381
+ }
2382
+ html = html.replace(marker, out);
2383
+ for (const p of res.p) blockingPromises.add(p);
2384
+ }
2385
+ }
2386
+ if (pending.length) {
2387
+ rootHoles = pending;
2388
+ return false;
2389
+ }
2390
+ rootHoles = null;
2391
+ return true;
2392
+ }
2393
+ function doShell() {
2394
+ if (shellCompleted) return;
2395
+ sharedConfig.context = context;
2396
+ if (blockingPromises.size !== lastBlockingSize) return;
2397
+ if (!resolveRootHoles()) return;
2398
+ if (blockingPromises.size !== lastBlockingSize) return;
2399
+ if (!headShellReady(headRegistry, p => blockingPromises.add(p))) return;
2400
+ headStyles = new Set();
2401
+ for (const url of tracking.emittedAssets) {
2402
+ if (isCssUrl(url)) headStyles.add(url);
2403
+ }
2404
+ serializeRootAssets();
2405
+ flushStubBatch();
2406
+ const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts, traceMetaMarkup(context.trace));
2407
+ if (render) render.shell();
2408
+ sink.shell(resolveSSRSelectValues(html), {
2409
+ preloads: tracking.emittedAssets,
2410
+ preloadLinks: tracking.preloadLinks,
2411
+ inlineStyles: tracking.inlineStyles,
2412
+ tasks,
2413
+ head
2414
+ });
2415
+ tasks = "";
2416
+ onCompleteShell && onCompleteShell({
2417
+ write(v) {
2418
+ !completed && buffer.write(v);
2419
+ }
2420
+ });
2421
+ shellCompleted = true;
2422
+ }
2423
+ const MIN_DRAIN_TURNS = 8;
2424
+ let lastBlockingSize = -1;
2425
+ let lastRegistrySize = -1;
2426
+ let drainTurn = 0;
2427
+ const scheduleFlush = (fn, awaited) => {
2428
+ const attempt = () => {
2429
+ flushStubBatch();
2430
+ if (registry.size !== lastRegistrySize || drainTurn++ < MIN_DRAIN_TURNS) {
2431
+ if (registry.size !== lastRegistrySize) drainTurn = 0;
2432
+ lastRegistrySize = registry.size;
2433
+ queue(attempt);
2434
+ return;
2435
+ }
2436
+ fn();
2437
+ };
2438
+ const progressed = awaited !== lastBlockingSize;
2439
+ lastBlockingSize = awaited;
2440
+ lastRegistrySize = -1;
2441
+ drainTurn = 0;
2442
+ progressed ? queue(attempt) : setTimeout(attempt);
2443
+ };
2444
+ let cachedReadable;
2445
+ let consumer;
2446
+ const claimConsumer = name => {
2447
+ if (consumer && consumer !== name) {
2448
+ throw new Error(`renderToStream result was already consumed via \`${consumer}\`; cannot also consume it via \`${name}\`. Use exactly one of \`pipe\`, \`pipeTo\`, or \`readable\`.`);
2449
+ }
2450
+ consumer = name;
2451
+ };
2452
+ const pipeToImpl = w => {
2453
+ let resolve;
2454
+ const p = new Promise(r => resolve = r);
2455
+ onFailure(sink => {
2456
+ try {
2457
+ if (sink) sink.end();else w.close().catch(() => {});
2458
+ } catch (_) {}
2459
+ resolve();
2460
+ });
2461
+ function flush() {
2462
+ allSettled(blockingPromises).then(awaited => {
2463
+ scheduleFlush(() => {
2464
+ if (dead) return resolve();
2465
+ try {
2466
+ doShell();
2467
+ } catch (err) {
2468
+ failRootRender(err);
2469
+ return;
2470
+ }
2471
+ if (!shellCompleted) return flush();
2472
+ const encoder = new TextEncoder();
2473
+ const writer = w.getWriter();
2474
+ let pendingWrites = Promise.resolve();
2475
+ let ended = false;
2476
+ const failed = () => {
2477
+ if (!ended) {
2478
+ abandon("consumer");
2479
+ resolve();
2480
+ }
2481
+ };
2482
+ writer.closed && writer.closed.catch(failed);
2483
+ buffer = writable = coalesceWrites(payload => {
2484
+ pendingWrites = pendingWrites.then(() => writer.write(encoder.encode(payload))).catch(failed);
2485
+ }, () => {
2486
+ pendingWrites.then(() => {
2487
+ ended = true;
2488
+ writer.releaseLock();
2489
+ w.close().catch(() => {});
2490
+ resolve();
2491
+ });
2492
+ });
2493
+ buffer.write(tmp);
2494
+ buffer.flush();
2495
+ firstFlushed = true;
2496
+ if (completed) {
2497
+ dispose();
2498
+ writable.end();
2499
+ } else flushEnd();
2500
+ }, awaited);
2501
+ });
2502
+ }
2503
+ flush();
2504
+ return p;
2505
+ };
2506
+ return {
2507
+ then(onFulfilled, onRejected) {
2508
+ const freezeHead = () => {
2509
+ if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response, {
2510
+ event: requestEvent
2511
+ });
2512
+ };
2513
+ const p = new Promise(resolve => {
2514
+ function complete() {
2515
+ freezeHead();
2516
+ dispose();
2517
+ resolve(tmp);
2518
+ }
2519
+ if (onCompleteAll) {
2520
+ let ogComplete = onCompleteAll;
2521
+ onCompleteAll = options => {
2522
+ ogComplete(options);
2523
+ complete();
2524
+ };
2525
+ } else onCompleteAll = complete;
2526
+ onFailure(() => resolve(tmp));
2527
+ function flush() {
2528
+ allSettled(blockingPromises).then(awaited => {
2529
+ scheduleFlush(() => {
2530
+ if (dead) return;
2531
+ try {
2532
+ if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
2533
+ } catch (err) {
2534
+ failRootRender(err);
2535
+ return;
2536
+ }
2537
+ queue(flushEnd);
2538
+ }, awaited);
2539
+ });
2540
+ }
2541
+ flush();
2542
+ });
2543
+ return p.then(onFulfilled, onRejected);
2544
+ },
2545
+ pipe(w) {
2546
+ claimConsumer("pipe");
2547
+ onFailure(sink => {
2548
+ try {
2549
+ sink ? sink.end() : w.end();
2550
+ } catch (_) {}
2551
+ });
2552
+ function flush() {
2553
+ allSettled(blockingPromises).then(awaited => {
2554
+ scheduleFlush(() => {
2555
+ if (dead) return;
2556
+ try {
2557
+ doShell();
2558
+ } catch (err) {
2559
+ failRootRender(err);
2560
+ return;
2561
+ }
2562
+ if (!shellCompleted) return flush();
2563
+ const sink = guardSink(w);
2564
+ buffer = writable = coalesceWrites(sink.write, sink.end);
2565
+ buffer.write(tmp);
2566
+ buffer.flush();
2567
+ firstFlushed = true;
2568
+ if (completed) {
2569
+ dispose();
2570
+ writable.end();
2571
+ } else flushEnd();
2572
+ }, awaited);
2573
+ });
2574
+ }
2575
+ flush();
2576
+ },
2577
+ pipeTo(w) {
2578
+ claimConsumer("pipeTo");
2579
+ return pipeToImpl(w);
2580
+ },
2581
+ get readable() {
2582
+ claimConsumer("readable");
2583
+ if (!cachedReadable) {
2584
+ const t = new TransformStream();
2585
+ pipeToImpl(t.writable);
2586
+ cachedReadable = t.readable;
2587
+ }
2588
+ return cachedReadable;
2589
+ }
2590
+ };
2591
+ }
2592
+ function HydrationScript(props) {
2593
+ const nonce = scriptNonce(sharedConfig.context && sharedConfig.context.nonce);
2594
+ return ssr(generateHydrationScript({
2595
+ nonce,
2596
+ ...props
2597
+ }));
2598
+ }
2599
+ function ssrGroup(fn, n) {
2600
+ fn.$g = n;
2601
+ return fn;
2602
+ }
2603
+ function buildAsyncWrap(err, node) {
2604
+ const p = ssrHandleError(err);
2605
+ if (!p) return null;
2606
+ if (node.$rw) return {
2607
+ fn: node,
2608
+ p
2609
+ };
2610
+ const owner = getOwner();
2611
+ const live = sharedConfig.context && sharedConfig.context.liveHoles;
2612
+ const suppress = node.$lhSuppress || live && (live.suppressed || live.sweeping);
2613
+ if (!owner) {
2614
+ if (suppress) node.$lhSuppress = true;
2615
+ return {
2616
+ fn: node,
2617
+ p
2618
+ };
2619
+ }
2620
+ const fn = () => runWithOwner(owner, node);
2621
+ fn.$rw = true;
2622
+ if (suppress) fn.$lhSuppress = true;
2623
+ if (node.$lhSkip) fn.$lhSkip = true;
2624
+ if (node.$lhBinding) fn.$lhBinding = node.$lhBinding;
2625
+ return {
2626
+ fn,
2627
+ p
2628
+ };
2629
+ }
2630
+ function ssrFirstGroupHit(hole) {
2631
+ try {
2632
+ return hole();
2633
+ } catch (err) {
2634
+ return buildAsyncWrap(err, hole);
2635
+ }
2636
+ }
2637
+ function tryResolveFunctionHole(hole) {
2638
+ let value;
2639
+ try {
2640
+ value = hole();
2641
+ } catch (err) {
2642
+ return buildAsyncWrap(err, hole) || "";
2643
+ }
2644
+ const t = typeof value;
2645
+ if (t === "string") return value;
2646
+ if (t === "number") return "" + value;
2647
+ if (value == null || t === "boolean") return "";
2648
+ return tryResolveString(value);
2649
+ }
2650
+ function mergeTemplateInto(result, node) {
2651
+ result.t[result.t.length - 1] += node.t[0];
2652
+ if (node.t.length > 1) {
2653
+ result.t.push(...node.t.slice(1));
2654
+ result.h.push(...node.h);
2655
+ result.p.push(...node.p);
2656
+ }
2657
+ }
2658
+ function appendResolvedNode(result, node) {
2659
+ if (node.fn !== undefined) {
2660
+ result.h.push(node.fn);
2661
+ result.p.push(node.p);
2662
+ result.t.push("");
2663
+ } else if (node.merge !== undefined) mergeTemplateInto(result, node.merge);else resolveSSRNode(node.bail, result);
2664
+ }
2665
+ let _lastGroupFn = null;
2666
+ let _lastGroupArr = null;
2667
+ let _lastGroupErr = null;
2668
+ function ssrGroupSlot(fn, idx) {
2669
+ return () => {
2670
+ if (idx > 0 && _lastGroupFn === fn) {
2671
+ if (_lastGroupArr !== null) return _lastGroupArr[idx];
2672
+ throw _lastGroupErr;
2673
+ }
2674
+ _lastGroupFn = fn;
2675
+ _lastGroupArr = null;
2676
+ _lastGroupErr = null;
2677
+ try {
2678
+ _lastGroupArr = fn();
2679
+ return _lastGroupArr[idx];
2680
+ } catch (err) {
2681
+ _lastGroupErr = err;
2682
+ throw err;
2683
+ }
2684
+ };
2685
+ }
2686
+ function wireErrorMessage(err) {
2687
+ const wire = ssrSanitizeError(err, null);
2688
+ return String(wire && wire.message || wire);
2689
+ }
2690
+ const holePositionCache = new WeakMap();
2691
+ function holeContentPositions(t) {
2692
+ let cached = holePositionCache.get(t);
2693
+ if (cached) return cached;
2694
+ const pos = [];
2695
+ const openOff = [];
2696
+ const closeOff = [];
2697
+ let inTag = false;
2698
+ let quote = "";
2699
+ let curOpen = null;
2700
+ let scanningName = false;
2701
+ for (let i = 0; i < t.length; i++) {
2702
+ const seg = t[i];
2703
+ let close = -1;
2704
+ const openAtStart = inTag;
2705
+ let reopened = false;
2706
+ for (let j = 0; j < seg.length; j++) {
2707
+ const ch = seg[j];
2708
+ if (quote) {
2709
+ if (ch === quote) quote = "";
2710
+ } else if (inTag) {
2711
+ if (scanningName && (ch === " " || ch === "\t" || ch === "\n" || ch === ">" || ch === "/")) {
2712
+ scanningName = false;
2713
+ curOpen = {
2714
+ seg: i,
2715
+ off: j
2716
+ };
2717
+ }
2718
+ if (ch === '"' || ch === "'") quote = ch;else if (ch === ">") {
2719
+ inTag = false;
2720
+ if (openAtStart && !reopened && close === -1) close = j;
2721
+ curOpen = null;
2722
+ }
2723
+ } else if (ch === "<") {
2724
+ inTag = true;
2725
+ scanningName = true;
2726
+ reopened = true;
2727
+ curOpen = null;
2728
+ }
2729
+ }
2730
+ if (inTag && scanningName) {
2731
+ scanningName = false;
2732
+ curOpen = {
2733
+ seg: i,
2734
+ off: seg.length
2735
+ };
2736
+ }
2737
+ closeOff.push(close);
2738
+ openOff.push(inTag && curOpen && curOpen.seg === i ? curOpen.off : -1);
2739
+ if (i < t.length - 1) pos.push(!inTag);
2740
+ }
2741
+ cached = {
2742
+ pos,
2743
+ openOff,
2744
+ closeOff
2745
+ };
2746
+ holePositionCache.set(t, cached);
2747
+ return cached;
2748
+ }
2749
+ function createLiveHoles(sink, scoped) {
2750
+ let nextId = 0;
2751
+ const stamp = typeof creationStamp === "function" ? creationStamp : () => 0;
2752
+ const inScope = scoped && typeof inServerComponentScope === "function" ? inServerComponentScope : null;
2753
+ const stripMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
2754
+ const swept = (owner, ctx, fn) => {
2755
+ const prev = sharedConfig.context;
2756
+ sharedConfig.context = ctx;
2757
+ try {
2758
+ return owner ? runWithOwner(owner, fn) : fn();
2759
+ } finally {
2760
+ sharedConfig.context = prev;
2761
+ }
2762
+ };
2763
+ function resolveHoleValue(hole) {
2764
+ const result = {
2765
+ t: [""],
2766
+ h: [],
2767
+ p: []
2768
+ };
2769
+ try {
2770
+ resolveSSRNode(hole(), result);
2771
+ } catch (err) {
2772
+ const wrap = buildAsyncWrap(err, hole);
2773
+ if (!wrap) throw err;
2774
+ result.h.push(wrap.fn);
2775
+ result.p.push(wrap.p);
2776
+ result.t.push("");
2777
+ }
2778
+ return result;
2779
+ }
2780
+ function closeChildren(b) {
2781
+ for (const c of b.children) {
2782
+ c.closed = true;
2783
+ if (c.key) sink.closeBinding(c.key);
2784
+ closeChildren(c);
2785
+ }
2786
+ b.children.length = 0;
2787
+ }
2788
+ const engine = {
2789
+ suppressed: 0,
2790
+ sweeping: false,
2791
+ parent: null,
2792
+ recordStamp: 0,
2793
+ gateHit: false,
2794
+ content(hole) {
2795
+ if (hole.$lhSuppress) {
2796
+ const r = {
2797
+ t: [""],
2798
+ h: [],
2799
+ p: []
2800
+ };
2801
+ engine.suppressed++;
2802
+ try {
2803
+ try {
2804
+ resolveSSRNode(hole(), r);
2805
+ } catch (err) {
2806
+ const wrap = buildAsyncWrap(err, hole);
2807
+ if (wrap) {
2808
+ r.h.push(wrap.fn);
2809
+ r.p.push(wrap.p);
2810
+ r.t.push("");
2811
+ }
2812
+ }
2813
+ } finally {
2814
+ engine.suppressed--;
2815
+ }
2816
+ const b = hole.$lhBinding;
2817
+ if (b && !b.closed && !r.h.length && !engine.sweeping) {
2818
+ b.last = stripMarkers(r.t[0]);
2819
+ }
2820
+ return r.h.length ? r : r.t[0];
2821
+ }
2822
+ if (engine.suppressed || engine.sweeping) return null;
2823
+ if (hole.$lhSkip) return null;
2824
+ if (inScope && !inScope()) return null;
2825
+ const recordsBefore = engine.recordStamp;
2826
+ const ownersBefore = stamp();
2827
+ const owner = getOwner();
2828
+ const holeCtx = sharedConfig.context;
2829
+ const b = {
2830
+ key: null,
2831
+ children: [],
2832
+ last: null,
2833
+ closed: false,
2834
+ sweep() {
2835
+ if (b.closed) return;
2836
+ const prevSweeping = engine.sweeping;
2837
+ engine.sweeping = true;
2838
+ engine.gateHit = false;
2839
+ const sweepOwnersBefore = stamp();
2840
+ let res;
2841
+ try {
2842
+ res = swept(owner, holeCtx, () => resolveHoleValue(hole));
2843
+ } catch (err) {
2844
+ b.closed = true;
2845
+ sink.closeBinding(b.key);
2846
+ sink.error(b.key, wireErrorMessage(err));
2847
+ return;
2848
+ } finally {
2849
+ engine.sweeping = prevSweeping;
2850
+ }
2851
+ if (engine.gateHit || stamp() !== sweepOwnersBefore) {
2852
+ b.closed = true;
2853
+ sink.closeBinding(b.key);
2854
+ return;
2855
+ }
2856
+ if (res.h.length) return;
2857
+ const html = res.t[0];
2858
+ if (b.last === null || html === b.last) return;
2859
+ b.last = html;
2860
+ closeChildren(b);
2861
+ sink.hole(b.key, html);
2862
+ }
2863
+ };
2864
+ if (engine.parent) engine.parent.children.push(b);
2865
+ const prevParent = engine.parent;
2866
+ engine.parent = b;
2867
+ let value;
2868
+ let escalated = null;
2869
+ try {
2870
+ value = hole();
2871
+ } catch (err) {
2872
+ const wrap = buildAsyncWrap(err, hole);
2873
+ if (!wrap) {
2874
+ engine.parent = prevParent;
2875
+ closeChildren(b);
2876
+ return "";
2877
+ }
2878
+ escalated = wrap;
2879
+ }
2880
+ if (!escalated && (typeof value === "function" && value.$lhSkip || value !== null && typeof value === "object" && value.$slot)) {
2881
+ engine.parent = prevParent;
2882
+ const r = {
2883
+ t: [""],
2884
+ h: [],
2885
+ p: []
2886
+ };
2887
+ engine.suppressed++;
2888
+ try {
2889
+ resolveSSRNode(value, r);
2890
+ } finally {
2891
+ engine.suppressed--;
2892
+ }
2893
+ return r.h.length ? r : r.t[0];
2894
+ }
2895
+ let res;
2896
+ if (escalated) {
2897
+ closeChildren(b);
2898
+ escalated.fn.$lhSuppress = true;
2899
+ escalated.fn.$lhBinding = b;
2900
+ res = {
2901
+ t: ["", ""],
2902
+ h: [escalated.fn],
2903
+ p: [escalated.p]
2904
+ };
2905
+ } else {
2906
+ res = {
2907
+ t: [""],
2908
+ h: [],
2909
+ p: []
2910
+ };
2911
+ try {
2912
+ resolveSSRNode(value, res);
2913
+ } catch (_) {
2914
+ engine.parent = prevParent;
2915
+ closeChildren(b);
2916
+ return "";
2917
+ }
2918
+ }
2919
+ engine.parent = prevParent;
2920
+ if (engine.recordStamp !== recordsBefore || stamp() !== ownersBefore) {
2921
+ return res.h.length ? res : res.t[0];
2922
+ }
2923
+ const id = nextId++;
2924
+ const key = b.key = "lh:" + id;
2925
+ const open = `<!--lh:${id}-->`;
2926
+ const close = `<!--lh:/${id}-->`;
2927
+ if (!res.h.length) {
2928
+ b.last = stripMarkers(res.t[0]);
2929
+ sink.openBinding(key, b);
2930
+ return open + res.t[0] + close;
2931
+ }
2932
+ const t = res.t.slice();
2933
+ t[0] = open + t[0];
2934
+ t[t.length - 1] += close;
2935
+ sink.openBinding(key, b);
2936
+ return {
2937
+ t,
2938
+ h: res.h,
2939
+ p: res.p
2940
+ };
2941
+ },
2942
+ mint() {
2943
+ return nextId++;
2944
+ },
2945
+ active() {
2946
+ return !inScope || inScope();
2947
+ },
2948
+ attr(cap) {
2949
+ const owner = getOwner();
2950
+ const holeCtx = sharedConfig.context;
2951
+ const b = {
2952
+ key: "lha:" + cap.id,
2953
+ children: [],
2954
+ last: cap.base,
2955
+ closed: false,
2956
+ sweep() {
2957
+ if (b.closed) return;
2958
+ const prevSweeping = engine.sweeping;
2959
+ engine.sweeping = true;
2960
+ engine.gateHit = false;
2961
+ const sweepOwnersBefore = stamp();
2962
+ let html = "";
2963
+ try {
2964
+ let group = null;
2965
+ let groupVal = null;
2966
+ const run = () => {
2967
+ for (const part of cap.parts) {
2968
+ if (typeof part === "string") {
2969
+ html += part;
2970
+ continue;
2971
+ }
2972
+ let v;
2973
+ if (part.g) {
2974
+ if (group !== part.g) {
2975
+ group = part.g;
2976
+ groupVal = part.g();
2977
+ }
2978
+ v = groupVal[part.i];
2979
+ } else {
2980
+ v = part.f();
2981
+ }
2982
+ const vt = typeof v;
2983
+ if (vt === "string" || vt === "number") html += v;
2984
+ }
2985
+ };
2986
+ swept(owner, holeCtx, run);
2987
+ } catch (err) {
2988
+ if (ssrHandleError(err, true)) return;
2989
+ b.closed = true;
2990
+ sink.closeBinding(b.key);
2991
+ sink.error("lha:" + cap.id, wireErrorMessage(err));
2992
+ return;
2993
+ } finally {
2994
+ engine.sweeping = prevSweeping;
2995
+ }
2996
+ if (engine.gateHit || stamp() !== sweepOwnersBefore) {
2997
+ b.closed = true;
2998
+ sink.closeBinding(b.key);
2999
+ return;
3000
+ }
3001
+ if (html === b.last) return;
3002
+ const before = attrNames(b.last);
3003
+ const after = attrNames(html);
3004
+ const removed = before.filter(n => !after.includes(n));
3005
+ b.last = html;
3006
+ sink.attr(String(cap.id), html, removed);
3007
+ }
3008
+ };
3009
+ if (sink.attrBaseline) sink.attrBaseline(b.key, cap.base);
3010
+ sink.openBinding(b.key, b);
3011
+ }
3012
+ };
3013
+ return engine;
3014
+ }
3015
+ function attrNames(text) {
3016
+ const names = [];
3017
+ const re = /(?:^|\s)([^\s=/>"']+)(?:="[^"]*")?/g;
3018
+ let m;
3019
+ while (m = re.exec(text)) names.push(m[1]);
3020
+ return names;
3021
+ }
3022
+ function ssr(t) {
3023
+ const len = arguments.length;
3024
+ if (len === 1) return {
3025
+ t
3026
+ };
3027
+ let s = t[0];
3028
+ let result = null;
3029
+ let lastGroup = null;
3030
+ let lastGroupVal = null;
3031
+ let lastGroupIdx = 0;
3032
+ const live = sharedConfig.context && sharedConfig.context.liveHoles;
3033
+ const hp = live ? holeContentPositions(t) : null;
3034
+ let lastOpen = null;
3035
+ let cap = null;
3036
+ if (live && hp.openOff[0] >= 0) lastOpen = {
3037
+ r: null,
3038
+ seg: -1,
3039
+ off: hp.openOff[0]
3040
+ };
3041
+ const captureStart = () => {
3042
+ if (cap) return true;
3043
+ if (!lastOpen || live.suppressed || live.sweeping || !live.active()) return false;
3044
+ if (lastOpen.r !== result || result !== null && lastOpen.seg !== result.t.length - 1) {
3045
+ return false;
3046
+ }
3047
+ const id = live.mint();
3048
+ const inject = ` data-lha="${id}"`;
3049
+ let prefix;
3050
+ if (result === null) {
3051
+ s = s.slice(0, lastOpen.off) + inject + s.slice(lastOpen.off);
3052
+ prefix = s.slice(lastOpen.off + inject.length);
3053
+ } else {
3054
+ const seg = result.t[lastOpen.seg];
3055
+ result.t[lastOpen.seg] = seg.slice(0, lastOpen.off) + inject + seg.slice(lastOpen.off);
3056
+ prefix = result.t[lastOpen.seg].slice(lastOpen.off + inject.length);
3057
+ }
3058
+ cap = {
3059
+ id,
3060
+ parts: [prefix],
3061
+ base: prefix
3062
+ };
3063
+ return true;
3064
+ };
3065
+ for (let i = 1; i < len; i++) {
3066
+ const hole = arguments[i];
3067
+ const ht = typeof hole;
3068
+ if (ht === "string") {
3069
+ if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
3070
+ if (cap) {
3071
+ cap.parts.push(hole);
3072
+ cap.base += hole;
3073
+ }
3074
+ } else if (ht === "number") {
3075
+ if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
3076
+ if (cap) {
3077
+ cap.parts.push("" + hole);
3078
+ cap.base += hole;
3079
+ }
3080
+ } else if (hole == null || ht === "boolean") ; else if (ht === "function" && hole.$g) {
3081
+ let value;
3082
+ let hasValue = false;
3083
+ if (lastGroup !== hole) {
3084
+ const r = ssrFirstGroupHit(hole);
3085
+ if (r !== null) {
3086
+ lastGroup = hole;
3087
+ lastGroupVal = r;
3088
+ lastGroupIdx = 0;
3089
+ if (!Array.isArray(r) && result === null) {
3090
+ result = {
3091
+ t: [s],
3092
+ h: [],
3093
+ p: []
3094
+ };
3095
+ s = "";
3096
+ }
3097
+ }
3098
+ }
3099
+ if (lastGroup === hole) {
3100
+ if (Array.isArray(lastGroupVal)) {
3101
+ value = lastGroupVal[lastGroupIdx++];
3102
+ hasValue = true;
3103
+ if (live && !hp.pos[i - 1] && captureStart()) {
3104
+ cap.parts.push({
3105
+ g: hole,
3106
+ i: lastGroupIdx - 1
3107
+ });
3108
+ }
3109
+ } else {
3110
+ cap = null;
3111
+ result.h.push(ssrGroupSlot(lastGroupVal.fn, lastGroupIdx++));
3112
+ result.p.push(lastGroupVal.p);
3113
+ result.t.push("");
3114
+ }
3115
+ }
3116
+ if (hasValue) {
3117
+ const vt = typeof value;
3118
+ if (vt === "string" || vt === "number") {
3119
+ if (result === null) s += value;else result.t[result.t.length - 1] += value;
3120
+ if (cap && !hp.pos[i - 1]) cap.base += value;
3121
+ } else if (value == null || vt === "boolean") ; else if (result !== null) {
3122
+ resolveSSRNode(value, result);
3123
+ } else {
3124
+ const rs = tryResolveString(value);
3125
+ if (typeof rs === "string") {
3126
+ s += rs;
3127
+ } else {
3128
+ result = {
3129
+ t: [s],
3130
+ h: [],
3131
+ p: []
3132
+ };
3133
+ s = "";
3134
+ if (rs.merge !== undefined) mergeTemplateInto(result, rs.merge);else resolveSSRNode(rs.bail, result);
3135
+ }
3136
+ }
3137
+ }
3138
+ } else if (ht === "function") {
3139
+ const devNext = hole.$reg !== undefined ? devPeekId() : undefined;
3140
+ let liveNode = null;
3141
+ if (live && hp.pos[i - 1] && (liveNode = live.content(hole)) !== null) {
3142
+ if (typeof liveNode === "string") {
3143
+ if (result === null) s += liveNode;else result.t[result.t.length - 1] += liveNode;
3144
+ } else {
3145
+ if (result === null) {
3146
+ result = {
3147
+ t: [s],
3148
+ h: [],
3149
+ p: []
3150
+ };
3151
+ s = "";
3152
+ }
3153
+ resolveSSRNode(liveNode, result);
3154
+ }
3155
+ } else if (result !== null) {
3156
+ const inTag = live && !hp.pos[i - 1];
3157
+ const capturing = inTag && captureStart();
3158
+ const li = capturing ? result.t.length - 1 : 0;
3159
+ const before = capturing ? result.t[li].length : 0;
3160
+ if (live) live.suppressed++;
3161
+ try {
3162
+ resolveSSRNode(hole, result);
3163
+ } finally {
3164
+ if (live) live.suppressed--;
3165
+ }
3166
+ if (capturing) {
3167
+ if (result.t.length - 1 === li) {
3168
+ cap.base += result.t[li].slice(before);
3169
+ cap.parts.push({
3170
+ f: hole
3171
+ });
3172
+ } else {
3173
+ cap = null;
3174
+ }
3175
+ }
3176
+ } else {
3177
+ const capturing = live && !hp.pos[i - 1] && captureStart();
3178
+ const r = tryResolveFunctionHole(hole);
3179
+ if (typeof r === "string") {
3180
+ s += r;
3181
+ if (capturing) {
3182
+ cap.base += r;
3183
+ cap.parts.push({
3184
+ f: hole
3185
+ });
3186
+ }
3187
+ } else {
3188
+ if (capturing) cap = null;
3189
+ result = {
3190
+ t: [s],
3191
+ h: [],
3192
+ p: []
3193
+ };
3194
+ s = "";
3195
+ appendResolvedNode(result, r);
3196
+ }
3197
+ }
3198
+ if (devNext !== undefined) checkUnscopedHole(devNext, t, i - 1, hole);
3199
+ } else if (result !== null) {
3200
+ resolveSSRNode(hole, result);
3201
+ } else {
3202
+ const r = tryResolveString(hole);
3203
+ if (typeof r === "string") {
3204
+ s += r;
3205
+ } else {
3206
+ result = {
3207
+ t: [s],
3208
+ h: [],
3209
+ p: []
3210
+ };
3211
+ s = "";
3212
+ appendResolvedNode(result, r);
3213
+ }
3214
+ }
3215
+ const next = t[i];
3216
+ if (live) {
3217
+ if (cap) {
3218
+ const co = hp.closeOff[i];
3219
+ if (co >= 0) {
3220
+ const tail = next.slice(0, co);
3221
+ cap.parts.push(tail);
3222
+ cap.base += tail;
3223
+ live.attr(cap);
3224
+ cap = null;
3225
+ } else {
3226
+ cap.parts.push(next);
3227
+ cap.base += next;
3228
+ }
3229
+ }
3230
+ if (hp.openOff[i] >= 0) {
3231
+ lastOpen = result === null ? {
3232
+ r: null,
3233
+ seg: -1,
3234
+ off: s.length + hp.openOff[i]
3235
+ } : {
3236
+ r: result,
3237
+ seg: result.t.length - 1,
3238
+ off: result.t[result.t.length - 1].length + hp.openOff[i]
3239
+ };
3240
+ }
3241
+ }
3242
+ if (result === null) s += next;else result.t[result.t.length - 1] += next;
3243
+ }
3244
+ if (result === null) return {
3245
+ t: s
3246
+ };
3247
+ return result;
3248
+ }
3249
+ function ssrClassName(value) {
3250
+ if (typeof value === "number") return "" + value;
3251
+ if (!value) return "";
3252
+ if (typeof value === "string") return escape(value, true);
3253
+ value = classListToObject(value);
3254
+ let classKeys = Object.keys(value),
3255
+ result = "";
3256
+ for (let i = 0, len = classKeys.length; i < len; i++) {
3257
+ const key = classKeys[i],
3258
+ classValue = !!value[key];
3259
+ if (!key || key === "undefined" || !classValue) continue;
3260
+ i && (result += " ");
3261
+ result += escape(key, true);
3262
+ }
3263
+ return result;
3264
+ }
3265
+ function ssrStyle(value) {
3266
+ if (!value) return "";
3267
+ if (typeof value === "string") return escape(value, true);
3268
+ let result = "";
3269
+ const k = Object.keys(value);
3270
+ for (let i = 0; i < k.length; i++) {
3271
+ const s = escape(k[i], true);
3272
+ const v = value[k[i]];
3273
+ if (v != undefined) {
3274
+ if (i) result += ";";
3275
+ const r = escape(v, true);
3276
+ if (r != undefined && r !== "undefined") {
3277
+ result += `${s}:${r}`;
3278
+ }
3279
+ }
3280
+ }
3281
+ return result;
3282
+ }
3283
+ function ssrStyleProperty(name, value) {
3284
+ return value != null ? name + value : "";
3285
+ }
3286
+ function ssrElement(tag, props, children, needsId, skip, attrs) {
3287
+ const hk = needsId ? ssrHydrationKey() : "";
3288
+ if (typeof props === "function") props = props();
3289
+ let sources = null;
3290
+ let proxy = false;
3291
+ let viewKeys = null;
3292
+ let owners = null;
3293
+ if (Array.isArray(props)) {
3294
+ let i = 0;
3295
+ for (; i < props.length; i++) {
3296
+ const s = props[i];
3297
+ if (s == null || typeof s === "function" || $PROXY in s) break;
3298
+ }
3299
+ if (i === props.length) sources = props;else {
3300
+ viewKeys = [];
3301
+ owners = [];
3302
+ for (let i = 0; i < props.length; i++) {
3303
+ let s = props[i];
3304
+ if (typeof s === "function") s = s();
3305
+ if (s != null) sourceOwners(s, viewKeys, owners);
3306
+ }
3307
+ }
3308
+ } else if (props == null) {
3309
+ props = {};
3310
+ } else if ($PROXY in props) {
3311
+ if (viewOf(props) !== undefined) {
3312
+ viewKeys = [];
3313
+ owners = [];
3314
+ sourceOwners(props, viewKeys, owners);
3315
+ } else proxy = true;
3316
+ }
3317
+ const info = tagInfo(tag);
3318
+ const skipChildren = info.isVoid;
3319
+ let result = info.open + hk;
3320
+ const last = sources === null ? 0 : sources.length - 1;
3321
+ let keysOf = null;
3322
+ if (sources !== null) {
3323
+ keysOf = new Array(last + 1);
3324
+ for (let s = 0; s <= last; s++) keysOf[s] = Object.keys(sources[s]);
3325
+ }
3326
+ for (let s = 0; s <= last; s++) {
3327
+ const keys = owners !== null ? viewKeys : keysOf !== null ? keysOf[s] : proxy ? Reflect.ownKeys(props) : Object.keys(props);
3328
+ if (sources !== null) props = sources[s];
3329
+ nextKey: for (let i = 0; i < keys.length; i++) {
3330
+ const prop = keys[i];
3331
+ if (typeof prop !== "string" || skip !== undefined && skip(prop)) continue;
3332
+ if (owners !== null) props = owners[i];
3333
+ for (let j = s + 1; j <= last; j++) {
3334
+ if (keysOf[j].includes(prop)) continue nextKey;
3335
+ }
3336
+ if (info.textarea && (prop === "value" || prop === "defaultValue")) {
3337
+ const value = props[prop];
3338
+ if (value !== null) children = escape(value);
3339
+ continue;
3340
+ }
3341
+ if (ChildProperties.has(prop)) {
3342
+ if (children === undefined && !skipChildren) children = info.raw || prop === "innerHTML" ? props[prop] : escape(props[prop]);
3343
+ continue;
3344
+ }
3345
+ const value = props[prop];
3346
+ if (value == undefined || prop === "ref" || prop.startsWith("on") || prop.startsWith("prop:")) {
3347
+ if (typeof value === "function" && value[CLAIM_PROP] !== undefined && (prop === "ref" || prop.slice(0, 2) === "on")) {
3348
+ devCheck({
3349
+ code: "BEHAVIOR_CLAIM_DROPPED",
3350
+ kind: "ssr",
3351
+ severity: "warn",
3352
+ message: `[BEHAVIOR_CLAIM_DROPPED] A spread on a server-rendered <${tag}> carries \`${prop}\` from client props — ` + `spreads don't participate in behavior claims, so this drops. ` + `Write the position out: \`${prop}={props.${String(value[CLAIM_PROP])}}\`.`,
3353
+ data: {
3354
+ reason: "spread",
3355
+ tag,
3356
+ position: prop,
3357
+ prop: String(value[CLAIM_PROP])
3358
+ }
3359
+ });
3360
+ }
3361
+ continue;
3362
+ } else if (prop === "style") {
3363
+ result += ` style="${ssrStyle(value)}"`;
3364
+ } else if (prop === "class") {
3365
+ result += ` class="${ssrClassName(value)}"`;
3366
+ } else if (typeof value === "boolean") {
3367
+ if (!value) continue;
3368
+ result += ` ${attrName(prop)}`;
3369
+ } else {
3370
+ result += value === "" ? ` ${attrName(prop)}` : ` ${attrName(prop)}="${escape(value, true)}"`;
3371
+ }
3372
+ }
3373
+ }
3374
+ if (attrs !== undefined) result += typeof attrs === "function" ? attrs() : attrs;
3375
+ if (skipChildren) return {
3376
+ t: result + " />"
3377
+ };
3378
+ if (typeof children === "function") children = children();
3379
+ const ct = typeof children;
3380
+ if (ct === "string" || ct === "number") return {
3381
+ t: result + ">" + children + info.close
3382
+ };
3383
+ if (children == null || ct === "boolean") return {
3384
+ t: result + ">" + info.close
3385
+ };
3386
+ if (ct === "object" && !children.h && typeof children.t === "string") return {
3387
+ t: result + ">" + children.t + info.close
3388
+ };
3389
+ return ssr([result + ">", info.close], resolveSSRNode(children, undefined, true));
3390
+ }
3391
+ function ssrElementAttribute(key, value) {
3392
+ if (value == undefined) return "";
3393
+ if (key === "style") return ` style="${ssrStyle(value)}"`;
3394
+ if (key === "class") return ` class="${ssrClassName(value)}"`;
3395
+ if (typeof value === "boolean") return value ? ` ${key}` : "";
3396
+ return value === "" ? ` ${key}` : ` ${key}="${escape(value, true)}"`;
3397
+ }
3398
+ function ssrAttribute(key, value) {
3399
+ return value == null || value === false ? "" : value === true ? ` ${key}` : ` ${key}="${value}"`;
3400
+ }
3401
+ function ssrHydrationKey() {
3402
+ const hk = getHydrationKey();
3403
+ return hk ? ` _hk=${hk}` : "";
3404
+ }
3405
+ const CLAIM_PROP = /*#__PURE__*/Symbol.for("solid.claim-prop");
3406
+ const CLAIMS_STREAM = 1;
3407
+ const CLAIMS_DOCUMENT = 2;
3408
+ const CLAIM_UNSAFE = /[^A-Za-z0-9_.!~*'()-]/g;
3409
+ function encodeClaimKey(key) {
3410
+ return String(key).replace(CLAIM_UNSAFE, c => encodeURIComponent(c));
3411
+ }
3412
+ function ssrClaim(map) {
3413
+ const mode = sharedConfig.context && sharedConfig.context.claims;
3414
+ if (!mode || mode === CLAIMS_DOCUMENT && !(typeof inServerComponentScope === "function" && inServerComponentScope())) {
3415
+ return "";
3416
+ }
3417
+ let out = "";
3418
+ for (const pos in map) {
3419
+ const value = map[pos];
3420
+ const list = Array.isArray(value) ? value : [value];
3421
+ for (const fn of list) {
3422
+ const prop = typeof fn === "function" && fn[CLAIM_PROP] || undefined;
3423
+ if (prop === undefined) {
3424
+ {
3425
+ devCheck({
3426
+ code: "BEHAVIOR_CLAIM_DROPPED",
3427
+ kind: "ssr",
3428
+ severity: "warn",
3429
+ message: `[BEHAVIOR_CLAIM_DROPPED] A \`${pos}\` position on a server-rendered element received a server-local ` + `${typeof fn} — this handler can never run. Pass the function through the ` + `server component's props from the client (compose on the client before ` + `passing), or bind a mutation to \`action=\`.`,
3430
+ data: {
3431
+ reason: "server-local",
3432
+ position: pos,
3433
+ received: typeof fn
3434
+ }
3435
+ });
3436
+ }
3437
+ continue;
3438
+ }
3439
+ out += `${out ? "," : ""}${pos}=${encodeClaimKey(prop)}`;
3440
+ }
3441
+ }
3442
+ return out ? ` _bnd="${out}"` : "";
3443
+ }
3444
+ function decodeSSREntities(s) {
3445
+ return s.indexOf("&") < 0 ? s : s.replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&amp;/g, "&");
3446
+ }
3447
+ const SELECT_VALUE_ATTR = /\svalue(?:="([^"]*)")?(?=[\s>]|$)/;
3448
+ function tagEnd(html, i) {
3449
+ for (let j = i + 1; j < html.length; j++) {
3450
+ const c = html.charCodeAt(j);
3451
+ if (c === 34) {
3452
+ j = html.indexOf('"', j + 1);
3453
+ if (j < 0) return -1;
3454
+ } else if (c === 62) return j;
3455
+ }
3456
+ return -1;
3457
+ }
3458
+ function optionText(html, from) {
3459
+ let t = "";
3460
+ let i = from;
3461
+ for (;;) {
3462
+ const lt = html.indexOf("<", i);
3463
+ if (lt < 0) return t + html.slice(i);
3464
+ t += html.slice(i, lt);
3465
+ if (!html.startsWith("<!--", lt)) return t;
3466
+ const ce = html.indexOf("-->", lt);
3467
+ if (ce < 0) return t;
3468
+ i = ce + 3;
3469
+ }
3470
+ }
3471
+ function tagIs(html, i, name) {
3472
+ if (!html.startsWith(name, i + 1)) return false;
3473
+ const c = html.charCodeAt(i + 1 + name.length);
3474
+ return c === 32 || c === 62 || c === 9 || c === 10 || c === 13;
3475
+ }
3476
+ let selectValuesActive = false;
3477
+ function ssrSelectValues() {
3478
+ selectValuesActive = true;
3479
+ }
3480
+ function resolveSSRSelectValues(html) {
3481
+ if (!selectValuesActive) return html;
3482
+ let cand = html.indexOf("<select");
3483
+ if (cand < 0) return html;
3484
+ let out = "";
3485
+ let idx = 0;
3486
+ while (cand >= 0) {
3487
+ if (!tagIs(html, cand, "select")) {
3488
+ cand = html.indexOf("<select", cand + 7);
3489
+ continue;
3490
+ }
3491
+ const e0 = tagEnd(html, cand);
3492
+ if (e0 < 0) break;
3493
+ const open = html.slice(cand, e0 + 1);
3494
+ const m = SELECT_VALUE_ATTR.exec(open);
3495
+ if (!m) {
3496
+ cand = html.indexOf("<select", e0 + 1);
3497
+ continue;
3498
+ }
3499
+ const bound = decodeSSREntities(m[1] ?? "");
3500
+ const sel = {
3501
+ values: /\smultiple(?=[\s>=])/.test(open) ? bound.split(",") : [bound],
3502
+ strip: cand + m.index,
3503
+ stripEnd: cand + m.index + m[0].length,
3504
+ body: e0 + 1,
3505
+ marks: [],
3506
+ defaulted: false
3507
+ };
3508
+ let committed = false;
3509
+ let i = html.indexOf("<", e0 + 1);
3510
+ while (i >= 0) {
3511
+ let e;
3512
+ if (html.charCodeAt(i + 1) === 33) {
3513
+ e = html.charCodeAt(i + 2) === 45 ? html.indexOf("-->", i) : html.indexOf(">", i);
3514
+ if (e < 0) break;
3515
+ if (html.charCodeAt(i + 2) === 45) e += 2;
3516
+ } else {
3517
+ e = tagEnd(html, i);
3518
+ if (e < 0) break;
3519
+ if (html.startsWith("</select>", i)) {
3520
+ out += html.slice(idx, sel.strip) + html.slice(sel.stripEnd, sel.body);
3521
+ let seg = sel.body;
3522
+ if (!sel.defaulted) {
3523
+ for (let k = 0; k < sel.marks.length; k++) {
3524
+ out += html.slice(seg, sel.marks[k]) + " selected";
3525
+ seg = sel.marks[k];
3526
+ }
3527
+ }
3528
+ out += html.slice(seg, i);
3529
+ idx = i;
3530
+ committed = true;
3531
+ break;
3532
+ } else if (tagIs(html, i, "option")) {
3533
+ const attrs = html.slice(i + 7, e);
3534
+ if (/\sselected(?=[\s=]|$)/.test(attrs)) sel.defaulted = true;else {
3535
+ const vm = SELECT_VALUE_ATTR.exec(attrs);
3536
+ const value = vm ? decodeSSREntities(vm[1] ?? "") : decodeSSREntities(optionText(html, e + 1)).replace(/\s+/g, " ").trim();
3537
+ if (sel.values.includes(value)) sel.marks.push(e);
3538
+ }
3539
+ }
3540
+ }
3541
+ i = html.indexOf("<", e + 1);
3542
+ }
3543
+ if (!committed) break;
3544
+ cand = html.indexOf("<select", idx);
3545
+ }
3546
+ if (idx === 0) return html;
3547
+ return out + html.slice(idx);
3548
+ }
3549
+ function escape(s, attr) {
3550
+ const t = typeof s;
3551
+ if (t !== "string") {
3552
+ if (!attr && Array.isArray(s)) {
3553
+ const joined = tryJoinPlainSSRArray(s);
3554
+ if (joined !== undefined) return joined;
3555
+ const src = s;
3556
+ s = s.slice();
3557
+ for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
3558
+ if (src.$slot) s.$slot = true;
3559
+ return s;
3560
+ }
3561
+ if (!attr && t === "function") return escapeLate(s);
3562
+ if (attr) {
3563
+ if (s == null || t === "boolean" || t === "number") return s;
3564
+ return escape(String(s), attr);
3565
+ }
3566
+ return s;
3567
+ }
3568
+ const i = s.search(attr ? ESCAPE_ATTR : ESCAPE_CONTENT);
3569
+ if (i < 0) return s;
3570
+ return escapeSlow(s, attr, i);
3571
+ }
3572
+ function escapeLate(fn) {
3573
+ if (fn.$esc) return fn;
3574
+ const w = () => escape(fn());
3575
+ w.$esc = true;
3576
+ {
3577
+ w.$fn = fn;
3578
+ w.$reg = devPeekId();
3579
+ }
3580
+ if (fn.$lhSkip) w.$lhSkip = true;
3581
+ if (fn.$lhSuppress) w.$lhSuppress = true;
3582
+ if (fn.$lhBinding) w.$lhBinding = fn.$lhBinding;
3583
+ return w;
3584
+ }
3585
+ const ESCAPE_CONTENT = /[&<]/;
3586
+ const ESCAPE_ATTR = /[&"<]/;
3587
+ function escapeSlow(s, attr, start) {
3588
+ if (attr) return escapeAttrSlow(s, start);
3589
+ const c0 = s.charCodeAt(start);
3590
+ let iDelim = c0 === 60 ? start : s.indexOf("<", start);
3591
+ let iAmp = c0 === 38 ? start : s.indexOf("&", start);
3592
+ let left = 0,
3593
+ out = "";
3594
+ while (iDelim >= 0 && iAmp >= 0) {
3595
+ if (iDelim < iAmp) {
3596
+ if (left < iDelim) out += s.substring(left, iDelim);
3597
+ out += "&lt;";
3598
+ left = iDelim + 1;
3599
+ iDelim = s.indexOf("<", left);
3600
+ } else {
3601
+ if (left < iAmp) out += s.substring(left, iAmp);
3602
+ out += "&amp;";
3603
+ left = iAmp + 1;
3604
+ iAmp = s.indexOf("&", left);
3605
+ }
3606
+ }
3607
+ if (iDelim >= 0) {
3608
+ do {
3609
+ if (left < iDelim) out += s.substring(left, iDelim);
3610
+ out += "&lt;";
3611
+ left = iDelim + 1;
3612
+ iDelim = s.indexOf("<", left);
3613
+ } while (iDelim >= 0);
3614
+ } else while (iAmp >= 0) {
3615
+ if (left < iAmp) out += s.substring(left, iAmp);
3616
+ out += "&amp;";
3617
+ left = iAmp + 1;
3618
+ iAmp = s.indexOf("&", left);
3619
+ }
3620
+ return left < s.length ? out + s.substring(left) : out;
3621
+ }
3622
+ function escapeAttrSlow(s, start) {
3623
+ const c0 = s.charCodeAt(start);
3624
+ let iQuot = c0 === 34 ? start : s.indexOf('"', start);
3625
+ let iAmp = c0 === 38 ? start : s.indexOf("&", start);
3626
+ let iLt = c0 === 60 ? start : s.indexOf("<", start);
3627
+ let left = 0,
3628
+ out = "";
3629
+ for (;;) {
3630
+ let i = -1,
3631
+ ent;
3632
+ if (iQuot >= 0) {
3633
+ i = iQuot;
3634
+ ent = "&quot;";
3635
+ }
3636
+ if (iAmp >= 0 && (i < 0 || iAmp < i)) {
3637
+ i = iAmp;
3638
+ ent = "&amp;";
3639
+ }
3640
+ if (iLt >= 0 && (i < 0 || iLt < i)) {
3641
+ i = iLt;
3642
+ ent = "&lt;";
3643
+ }
3644
+ if (i < 0) break;
3645
+ if (left < i) out += s.substring(left, i);
3646
+ out += ent;
3647
+ left = i + 1;
3648
+ if (i === iQuot) iQuot = s.indexOf('"', left);else if (i === iAmp) iAmp = s.indexOf("&", left);else iLt = s.indexOf("<", left);
3649
+ }
3650
+ return left < s.length ? out + s.substring(left) : out;
3651
+ }
3652
+ function tryJoinPlainSSRArray(nodes) {
3653
+ if (nodes.length === 0) return undefined;
3654
+ let out = "";
3655
+ for (let i = 0, len = nodes.length; i < len; i++) {
3656
+ const node = nodes[i];
3657
+ if (node == null || typeof node !== "object" || node.h || typeof node.t !== "string") {
3658
+ return undefined;
3659
+ }
3660
+ out += node.t;
3661
+ }
3662
+ return out;
3663
+ }
3664
+ function getHydrationKey() {
3665
+ const hydrate = sharedConfig.context;
3666
+ return hydrate && sharedConfig.getNextContextId();
3667
+ }
3668
+ function applyRef(r, element) {
3669
+ Array.isArray(r) ? r.flat(Infinity).forEach(f => f && f(element)) : r(element);
3670
+ }
3671
+ function generateHydrationScript({
3672
+ eventNames = ["click", "input"],
3673
+ nonce
3674
+ } = {}) {
3675
+ return `<script${nonce ? ` nonce="${escape(String(nonce), true)}"` : ""}>window._$HY||(e=>{let t=e=>e&&e.hasAttribute&&(e.hasAttribute("_hk")?e:t(e.host&&e.host.nodeType?e.host:e.parentNode));["${eventNames.join('","')}"].forEach((o=>document.addEventListener(o,(o=>{if(!e.events)return;let s=t(o.composedPath&&o.composedPath()[0]||o.target);s&&!e.completed.has(s)&&e.events.push([s,o])}))))})(_$HY={events:[],completed:new WeakSet,r:{},fe(){}});</script><!--xs-->`;
3676
+ }
3677
+ function queue(fn) {
3678
+ return Promise.resolve().then(fn);
3679
+ }
3680
+ const deferFlush = typeof setImmediate === "function" ? setImmediate : fn => setTimeout(fn, 0);
3681
+ function allSettled(promises) {
3682
+ let size = promises.size;
3683
+ return Promise.allSettled(promises).then(() => {
3684
+ if (promises.size !== size) return allSettled(promises);
3685
+ return size;
3686
+ });
3687
+ }
3688
+ function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead) {
3689
+ const scriptTag = scripts ? `<script${nonceAttr(nonce, "script")}>${scripts}</script>` : "";
3690
+ const title = headTags ? headTags.title : null;
3691
+ let headTagsHtml = headTags ? headTags.html : "";
3692
+ const headPrelude = headTags ? headTags.prelude : "";
3693
+ if (!onHead && title == null && !headTagsHtml && !headPrelude && !(emittedAssets && emittedAssets.size) && !preloadLinks && !(inlineStyles && inlineStyles.size)) {
3694
+ if (!scriptTag) return html;
3695
+ const xs = html.indexOf("<!--xs-->");
3696
+ return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
3697
+ }
3698
+ if (headPrelude) {
3699
+ const open = html.match(/<head(?:\s[^>]*)?>/);
3700
+ if (open) {
3701
+ const at = open.index + open[0].length;
3702
+ html = html.slice(0, at) + headPrelude + html.slice(at);
3703
+ }
3704
+ }
3705
+ let headIdx = html.indexOf("</head>");
3706
+ if (headIdx === -1) {
3707
+ if (onHead) {
3708
+ let titleHtml = "";
3709
+ if (title != null) {
3710
+ titleHtml = headTags.noScripts ? `<title data-dh="title">${escape(title)}</title>` : `<script${nonceAttr(nonce, "script")}>(function(x,t){(t=document.querySelector("title"))?(t.hasAttribute("data-dh")||t.setAttribute("data-dhf",t.textContent),t.textContent=x):(document.title=x,t=document.querySelector("title"));t&&t.setAttribute("data-dh","title")})(${JSON.stringify(title).replace(/</g, "\\u003C")})</script>`;
3711
+ }
3712
+ onHead(headPrelude + headTagsHtml + titleHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce));
3713
+ }
3714
+ if (!scriptTag) return html;
3715
+ const xs = html.indexOf("<!--xs-->");
3716
+ return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
3717
+ }
3718
+ if (title != null) {
3719
+ const winner = escape(title);
3720
+ const open = html.match(/<head(?:\s[^>]*)?>/);
3721
+ const from = open ? open.index + open[0].length : 0;
3722
+ const m = /<title(\s[^>]*)?>([\s\S]*?)<\/title>/.exec(html.slice(from, headIdx));
3723
+ if (m) {
3724
+ const at = from + m.index;
3725
+ const stash = m[2].replace(/"/g, "&quot;");
3726
+ html = html.slice(0, at) + `<title${m[1] || ""} data-dh="title" data-dhf="${stash}">${winner}</title>` + html.slice(at + m[0].length);
3727
+ headIdx = html.indexOf("</head>");
3728
+ } else {
3729
+ headTagsHtml = `<title data-dh="title">${winner}</title>` + headTagsHtml;
3730
+ }
3731
+ }
3732
+ const head = headTagsHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce);
3733
+ if (!scriptTag) return html.slice(0, headIdx) + head + html.slice(headIdx);
3734
+ const xsIdx = html.indexOf("<!--xs-->");
3735
+ if (xsIdx === -1) return html.slice(0, headIdx) + head + html.slice(headIdx) + scriptTag;
3736
+ return xsIdx < headIdx ? html.slice(0, xsIdx) + scriptTag + html.slice(xsIdx, headIdx) + head + html.slice(headIdx) : html.slice(0, headIdx) + head + html.slice(headIdx, xsIdx) + scriptTag + html.slice(xsIdx);
3737
+ }
3738
+ function renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce) {
3739
+ let head = "";
3740
+ const styleAttr = nonceAttr(nonce, "style");
3741
+ const scriptAttr = nonceAttr(nonce, "script");
3742
+ if (emittedAssets && emittedAssets.size) {
3743
+ for (const url of emittedAssets) {
3744
+ head += isCssUrl(url) ? `<link rel="stylesheet" href="${url}"${styleAttr}>` : `<link rel="modulepreload" href="${url}"${scriptAttr}>`;
3745
+ }
3746
+ }
3747
+ if (preloadLinks) {
3748
+ for (const entry of preloadLinks) head += `<link${entry.attrHtml}>`;
3749
+ }
3750
+ if (inlineStyles && inlineStyles.size) {
3751
+ for (const entry of inlineStyles.values()) {
3752
+ if (entry.emitted) continue;
3753
+ entry.emitted = true;
3754
+ head += renderInlineStyle(entry, nonce);
3755
+ }
3756
+ }
3757
+ return head;
3758
+ }
3759
+ function serializeFragmentAssets(key, boundaryModules, context, name = key) {
3760
+ const map = boundaryModules.get(key);
3761
+ if (!map || !Object.keys(map).length) return;
3762
+ context.serialize(name + "_assets", {
3763
+ ...map
3764
+ });
3765
+ }
3766
+ function propagateBoundaryStyles(childKey, parentKey, tracking) {
3767
+ const childStyles = tracking.getBoundaryStyles(childKey);
3768
+ if (!childStyles) return;
3769
+ let parentStyles = tracking.boundaryStyles.get(parentKey);
3770
+ if (!parentStyles) {
3771
+ parentStyles = new Set();
3772
+ tracking.boundaryStyles.set(parentKey, parentStyles);
3773
+ }
3774
+ for (const url of childStyles) {
3775
+ parentStyles.add(url);
3776
+ }
3777
+ }
3778
+ function collectStreamStyles(key, tracking, headStyles) {
3779
+ const styles = tracking.getBoundaryStyles(key);
3780
+ const links = [];
3781
+ const inline = [];
3782
+ if (!styles) return {
3783
+ links,
3784
+ inline
3785
+ };
3786
+ for (const entry of styles) {
3787
+ if (typeof entry === "string") {
3788
+ if (!headStyles || !headStyles.has(entry)) links.push(entry);
3789
+ } else if (entry.emitted) {
3790
+ continue;
3791
+ } else if (entry.attrHtml !== undefined) {
3792
+ entry.emitted = true;
3793
+ links.push(entry);
3794
+ } else {
3795
+ entry.emitted = true;
3796
+ inline.push(entry);
3797
+ }
3798
+ }
3799
+ return {
3800
+ links,
3801
+ inline
3802
+ };
3803
+ }
3804
+ function escapeStyleContent(content) {
3805
+ return content.replace(/<\/(style)/gi, "<\\/$1");
3806
+ }
3807
+ function renderInlineStyle(entry, nonce) {
3808
+ let attrs = "";
3809
+ let hasNonce = false;
3810
+ if (entry.attrs) {
3811
+ for (const name in entry.attrs) {
3812
+ if (name.length === 5 && asciiLowerCase(name) === "nonce") hasNonce = true;
3813
+ attrs += ` ${name}="${escape(String(entry.attrs[name]), true)}"`;
3814
+ }
3815
+ }
3816
+ const nonceHtml = hasNonce ? "" : nonceAttr(nonce, "style");
3817
+ return `<style${nonceHtml} data-asset="${escape(entry.id, true)}"${attrs}>${escapeStyleContent(entry.content)}</style>`;
3818
+ }
3819
+ function waitForFragments(registry, key) {
3820
+ for (const k of [...registry.keys()].reverse()) {
3821
+ if (key.startsWith(k)) return k;
3822
+ }
3823
+ return false;
3824
+ }
3825
+ function replacePlaceholder(html, key, value) {
3826
+ const marker = `<template id="pl-${key}">`;
3827
+ const close = `<!--pl-${key}-->`;
3828
+ const first = html.indexOf(marker);
3829
+ if (first === -1) return html;
3830
+ const last = html.indexOf(close, first + marker.length);
3831
+ return html.slice(0, first) + value + html.slice(last + close.length);
3832
+ }
3833
+ function classListToObject(classList) {
3834
+ if (Array.isArray(classList)) {
3835
+ const result = {};
3836
+ flattenClassList(classList, result);
3837
+ return result;
3838
+ }
3839
+ return classList;
3840
+ }
3841
+ function flattenClassList(list, result) {
3842
+ for (let i = 0, len = list.length; i < len; i++) {
3843
+ const item = list[i];
3844
+ if (Array.isArray(item)) flattenClassList(item, result);else if (typeof item === "object" && item != null) Object.assign(result, item);
3845
+ else if (typeof item !== "boolean" && (item || item === 0)) result[item] = true;
3846
+ }
3847
+ }
3848
+ let ssrTextTail = false;
3849
+ function tryResolveString(node, nested) {
3850
+ if (!nested) ssrTextTail = false;
3851
+ const t = typeof node;
3852
+ if (t === "string" || t === "number") {
3853
+ const s = ssrTextTail ? "<!--!$-->" + node : "" + node;
3854
+ ssrTextTail = true;
3855
+ return s;
3856
+ }
3857
+ if (node == null || t === "boolean") return "";
3858
+ if (t === "object") {
3859
+ if (Array.isArray(node)) {
3860
+ const joined = tryJoinPlainSSRArray(node);
3861
+ if (joined !== undefined) {
3862
+ ssrTextTail = false;
3863
+ return joined;
3864
+ }
3865
+ let s = "";
3866
+ for (let i = 0, len = node.length; i < len; i++) {
3867
+ const r = tryResolveString(node[i], true);
3868
+ if (typeof r !== "string") return {
3869
+ bail: node
3870
+ };
3871
+ s += r;
3872
+ }
3873
+ return s;
3874
+ }
3875
+ if (node.h && node.h.length > 0) return {
3876
+ merge: node
3877
+ };
3878
+ if (node.t === undefined) {
3879
+ unrecognizedInsert(node);
3880
+ return "";
3881
+ }
3882
+ ssrTextTail = false;
3883
+ return Array.isArray(node.t) ? node.t[0] : node.t;
3884
+ }
3885
+ if (t === "function") {
3886
+ let v;
3887
+ try {
3888
+ v = node();
3889
+ } catch (err) {
3890
+ const wrap = buildAsyncWrap(err, node);
3891
+ if (wrap) ssrTextTail = true;
3892
+ return wrap || "";
3893
+ }
3894
+ return tryResolveString(v, true);
3895
+ }
3896
+ return "";
3897
+ }
3898
+ function resolveSSRNode(node, result = {
3899
+ t: [""],
3900
+ h: [],
3901
+ p: []
3902
+ }, top, nested) {
3903
+ if (!nested) ssrTextTail = false;
3904
+ const t = typeof node;
3905
+ if (t === "string" || t === "number") {
3906
+ result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + node : node;
3907
+ ssrTextTail = true;
3908
+ } else if (node == null || t === "boolean") ; else if (Array.isArray(node)) {
3909
+ const slotLive = node.$slot && sharedConfig.context && sharedConfig.context.liveHoles;
3910
+ if (slotLive) slotLive.suppressed++;
3911
+ try {
3912
+ for (let i = 0, len = node.length; i < len; i++) {
3913
+ if (top) ssrTextTail = false;
3914
+ resolveSSRNode(node[i], result, false, true);
3915
+ }
3916
+ } finally {
3917
+ if (slotLive) slotLive.suppressed--;
3918
+ }
3919
+ } else if (t === "object") {
3920
+ if (node.h) {
3921
+ result.t[result.t.length - 1] += node.t[0];
3922
+ if (node.t.length > 1) {
3923
+ result.t.push(...node.t.slice(1));
3924
+ result.h.push(...node.h);
3925
+ result.p.push(...node.p);
3926
+ }
3927
+ ssrTextTail = false;
3928
+ } else if (node.t !== undefined) {
3929
+ result.t[result.t.length - 1] += node.t;
3930
+ ssrTextTail = false;
3931
+ } else unrecognizedInsert(node);
3932
+ } else if (t === "function") {
3933
+ const live = sharedConfig.context && sharedConfig.context.liveHoles;
3934
+ let liveNode = null;
3935
+ if (live && (liveNode = live.content(node)) !== null) {
3936
+ if (typeof liveNode === "string") {
3937
+ result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + liveNode : liveNode;
3938
+ ssrTextTail = true;
3939
+ } else resolveSSRNode(liveNode, result, false, true);
3940
+ } else {
3941
+ try {
3942
+ resolveSSRNode(node(), result, false, true);
3943
+ } catch (err) {
3944
+ const wrap = buildAsyncWrap(err, node);
3945
+ if (wrap) {
3946
+ if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
3947
+ result.h.push(wrap.fn);
3948
+ result.p.push(wrap.p);
3949
+ result.t.push("");
3950
+ ssrTextTail = true;
3951
+ }
3952
+ }
3953
+ }
3954
+ }
3955
+ return result;
3956
+ }
3957
+ function resolveSSRSync(node) {
3958
+ const res = resolveSSRNode(node);
3959
+ if (!res.h.length) return res.t[0];
3960
+ throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
3961
+ }
3962
+ const RequestContext = Symbol.for("solid.RequestContext");
3963
+ const ServerErrors = Symbol.for("solid-js/server/errors");
3964
+ function serializerErrorHook(hook) {
3965
+ return hook === undefined ? undefined : err => {
3966
+ reportServerError(err, {
3967
+ kind: "render",
3968
+ handling: "serialize"
3969
+ }, null);
3970
+ };
3971
+ }
3972
+ function ambientServerErrorHook() {
3973
+ const slot = globalThis[ServerErrors];
3974
+ return slot === undefined ? undefined : slot.hook;
3975
+ }
3976
+ function configureServerErrors(config) {
3977
+ const g = globalThis;
3978
+ if (config && config.onError !== undefined && typeof config.onError !== "function") {
3979
+ throw new TypeError(`Invalid onError: expected a function, received ${typeof config.onError}.`);
3980
+ }
3981
+ (g[ServerErrors] ||= {}).hook = config ? config.onError : undefined;
3982
+ }
3983
+ function getRequestEvent() {
3984
+ return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || sharedConfig.context && sharedConfig.context.event || console.warn("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.") : undefined;
3985
+ }
3986
+ function peekRequestEvent() {
3987
+ const store = globalThis[RequestContext];
3988
+ return store ? store.getStore() : undefined;
3989
+ }
3990
+ function timeDocument(context, trace, mode, requestEvent) {
3991
+ if (records() === undefined) return undefined;
3992
+ const render = observeRender(trace, mode, requestEvent);
3993
+ if (timesServerWork()) {
3994
+ context._recordBoundary = event => {
3995
+ trace.timing.push({
3996
+ type: "boundary",
3997
+ event
3998
+ });
3999
+ if (render) render.boundary();
4000
+ };
4001
+ }
4002
+ return render;
4003
+ }
4004
+ function getTraceContext() {
4005
+ const event = peekRequestEvent();
4006
+ if (event) return traceForEvent(event).context;
4007
+ const ctx = sharedConfig.context;
4008
+ return ctx && ctx.trace ? ctx.trace.context : undefined;
4009
+ }
4010
+ function traceForStub(stub, event) {
4011
+ if (!event) {
4012
+ event = peekRequestEvent();
4013
+ if (!event || event.response !== stub) return undefined;
4014
+ }
4015
+ return traceForEvent(event);
4016
+ }
4017
+ function createResponseStub() {
4018
+ return {
4019
+ status: undefined,
4020
+ statusText: undefined,
4021
+ headers: new Headers(),
4022
+ committed: false
4023
+ };
4024
+ }
4025
+ function createRequestEvent(request, init) {
4026
+ return {
4027
+ request,
4028
+ locals: {},
4029
+ response: createResponseStub(),
4030
+ ...init
4031
+ };
4032
+ }
4033
+ function reportLostHeaderWrite(method, name) {
4034
+ const message = `[LATE_HEADER_WRITE] Response header write dropped: headers.${method}(${JSON.stringify(String(name))}) ` + "ran after the response head was sent. Write headers before the shell flushes " + "(or before the handler returns).";
4035
+ recordFinding({
4036
+ code: "LATE_HEADER_WRITE",
4037
+ kind: "head",
4038
+ severity: "error",
4039
+ message,
4040
+ data: {
4041
+ method,
4042
+ name: String(name)
4043
+ }
4044
+ });
4045
+ throw new Error(message);
4046
+ }
4047
+ function commitResponseStub(stub, {
4048
+ allowLateLocation = false,
4049
+ event
4050
+ } = {}) {
4051
+ if (!stub || stub.committed) return stub;
4052
+ const headers = stub.headers;
4053
+ if (headers && typeof headers.append === "function") {
4054
+ const trace = traceForStub(stub, event);
4055
+ if (trace) appendTraceServerTiming(headers, trace);
4056
+ }
4057
+ stub.committed = true;
4058
+ if (!headers || typeof headers.set !== "function") return stub;
4059
+ for (const method of ["set", "append", "delete"]) {
4060
+ const original = headers[method].bind(headers);
4061
+ headers[method] = function (name, ...rest) {
4062
+ if (allowLateLocation && method === "set" && String(name).toLowerCase() === "location") {
4063
+ return original(name, ...rest);
4064
+ }
4065
+ reportLostHeaderWrite(method, name);
4066
+ };
4067
+ }
4068
+ return stub;
4069
+ }
4070
+ const validRedirectStatuses = /*#__PURE__*/new Set([301, 302, 303, 307, 308]);
4071
+ function getExpectedRedirectStatus(response) {
4072
+ if (response.status && validRedirectStatuses.has(response.status)) return response.status;
4073
+ return 302;
4074
+ }
4075
+ function mergeStubHeaders(target, stub) {
4076
+ if (!stub) return target;
4077
+ stub.headers.forEach((value, key) => {
4078
+ if (key === "server-timing") mergeServerTiming(target, value);else if (key !== "set-cookie") target.set(key, value);
4079
+ });
4080
+ const setCookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
4081
+ for (const cookie of setCookies) target.append("set-cookie", cookie);
4082
+ return target;
4083
+ }
4084
+ function copyInitHeaders(init) {
4085
+ if (!init || !init.getSetCookie) return new Headers(init);
4086
+ const headers = new Headers();
4087
+ init.forEach((value, key) => {
4088
+ if (key !== "set-cookie") headers.append(key, value);
4089
+ });
4090
+ for (const cookie of init.getSetCookie()) headers.append("Set-Cookie", cookie);
4091
+ return headers;
4092
+ }
4093
+ const STUB_GAP_FILL_EXCLUDED = /*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location",
4094
+ ...COMPOSED_BODY_FRAMING].map(header => header.toLowerCase()));
4095
+ function fillsStubGap(key, headers, response) {
4096
+ if (key === "set-cookie" || STUB_GAP_FILL_EXCLUDED.has(key)) return false;
4097
+ if (response.body === null && (key === "content-type" || key === "content-length")) return false;
4098
+ return !headers.has(key);
4099
+ }
4100
+ function commitEventResponse(response, event = getRequestEvent()) {
4101
+ const stub = event && event.response;
4102
+ if (!stub || !stub.headers || stub.committed) {
4103
+ if (!event || stub) return response;
4104
+ const trace = traceForEvent(event);
4105
+ if (!hasServerTiming(trace)) return response;
4106
+ const headers = copyInitHeaders(response.headers);
4107
+ appendTraceServerTiming(headers, trace);
4108
+ return new Response(response.body, {
4109
+ status: response.status,
4110
+ statusText: response.statusText,
4111
+ headers
4112
+ });
4113
+ }
4114
+ const cookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
4115
+ commitResponseStub(stub, {
4116
+ event
4117
+ });
4118
+ let hasGaps = false;
4119
+ stub.headers.forEach((value, key) => {
4120
+ if (fillsStubGap(key, response.headers, response)) hasGaps = true;
4121
+ });
4122
+ const timing = stub.headers.get("server-timing");
4123
+ const mergesTiming = timing !== null && response.headers.has("server-timing");
4124
+ if (!cookies.length && !hasGaps && !mergesTiming) return response;
4125
+ const headers = copyInitHeaders(response.headers);
4126
+ for (const cookie of cookies) headers.append("Set-Cookie", cookie);
4127
+ stub.headers.forEach((value, key) => {
4128
+ if (fillsStubGap(key, headers, response)) headers.set(key, value);
4129
+ });
4130
+ if (mergesTiming) mergeServerTiming(headers, timing);
4131
+ return new Response(response.body, {
4132
+ status: response.status,
4133
+ statusText: response.statusText,
4134
+ headers
4135
+ });
4136
+ }
4137
+ function deriveHead(stub, responseInit = {}) {
4138
+ const headers = mergeStubHeaders(copyInitHeaders(responseInit.headers), stub);
4139
+ for (const header of COMPOSED_BODY_FRAMING) headers.delete(header);
4140
+ const status = stub && stub.status || responseInit.status || 200;
4141
+ const statusText = stub && stub.statusText || responseInit.statusText || undefined;
4142
+ return {
4143
+ status,
4144
+ statusText,
4145
+ headers
4146
+ };
4147
+ }
4148
+ function createSSRResponse(result, event, options = {}) {
4149
+ const stub = event && event.response;
4150
+ const {
4151
+ responseInit,
4152
+ transformChunk
4153
+ } = options;
4154
+ const nonce = normalizeNonce(options.nonce);
4155
+ if (typeof result === "string") {
4156
+ if (stub) commitResponseStub(stub, {
4157
+ event
4158
+ });
4159
+ const head = deriveHead(stub, responseInit);
4160
+ if (stub && stub.headers.get("Location")) {
4161
+ return new Response(null, {
4162
+ status: getExpectedRedirectStatus(stub),
4163
+ headers: head.headers
4164
+ });
4165
+ }
4166
+ if (!head.headers.has("content-type")) {
4167
+ head.headers.set("content-type", "text/html; charset=utf-8");
4168
+ }
4169
+ return new Response(transformChunk ? transformChunk(result) : result, {
4170
+ status: head.status,
4171
+ statusText: head.statusText,
4172
+ headers: head.headers
4173
+ });
4174
+ }
4175
+ const encoder = new TextEncoder();
4176
+ return new Promise(resolve => {
4177
+ let controller;
4178
+ let closed = false;
4179
+ let flushed = false;
4180
+ const enqueue = value => {
4181
+ if (closed || !controller) return;
4182
+ try {
4183
+ controller.enqueue(encoder.encode(value));
4184
+ } catch {
4185
+ closed = true;
4186
+ }
4187
+ };
4188
+ result.pipe({
4189
+ write(chunk) {
4190
+ if (!flushed) {
4191
+ flushed = true;
4192
+ if (stub) commitResponseStub(stub, {
4193
+ allowLateLocation: true,
4194
+ event
4195
+ });
4196
+ const head = deriveHead(stub, responseInit);
4197
+ if (stub && stub.headers.get("Location")) {
4198
+ closed = true;
4199
+ resolve(new Response(null, {
4200
+ status: getExpectedRedirectStatus(stub),
4201
+ headers: head.headers
4202
+ }));
4203
+ return;
4204
+ }
4205
+ if (!head.headers.has("content-type")) {
4206
+ head.headers.set("content-type", "text/html; charset=utf-8");
4207
+ }
4208
+ resolve(new Response(new ReadableStream({
4209
+ start(c) {
4210
+ controller = c;
4211
+ },
4212
+ cancel() {
4213
+ closed = true;
4214
+ }
4215
+ }), {
4216
+ status: head.status,
4217
+ statusText: head.statusText,
4218
+ headers: head.headers
4219
+ }));
4220
+ }
4221
+ enqueue(transformChunk ? transformChunk(chunk) : chunk);
4222
+ },
4223
+ end() {
4224
+ if (closed || !controller) return;
4225
+ const location = stub && stub.headers.get("Location");
4226
+ if (location && isHttpNavigationTarget(location)) {
4227
+ const attr = nonceAttr(nonce, "script");
4228
+ enqueue(`<script${attr}>window.location=${JSON.stringify(location).replace(/</g, "\\u003c")}</script>`);
4229
+ }
4230
+ closed = true;
4231
+ try {
4232
+ controller.close();
4233
+ } catch {}
4234
+ }
4235
+ });
4236
+ });
4237
+ }
4238
+ function composeMiddleware(middlewares) {
4239
+ return function run(request, next) {
4240
+ let index = -1;
4241
+ function dispatch(i, req) {
4242
+ if (i <= index) return Promise.reject(new Error("next() called multiple times"));
4243
+ index = i;
4244
+ if (i === middlewares.length) return Promise.resolve(next(req));
4245
+ return Promise.resolve(middlewares[i](req, override => dispatch(i + 1, override || req)));
4246
+ }
4247
+ return dispatch(0, request);
4248
+ };
4249
+ }
4250
+ function registerElementClaim() {
4251
+ return noopCleanup;
4252
+ }
4253
+ function noopCleanup() {}
4254
+ function claimElement(node) {
4255
+ return node;
4256
+ }
4257
+ function claimElementTree(root) {
4258
+ return root;
4259
+ }
4260
+ function notSup() {
4261
+ throw new Error("Client-only API called on the server side. Run client-only code in onMount, or conditionally run client-only component with <Show>.");
4262
+ }
4263
+
4264
+ setContainerTraceResolver(getProjectionTrace);
4265
+ setAsyncIterableSharer(shareAsyncIterable);
4266
+ const isServer = true;
4267
+ const isDev = true;
4268
+ function dynamic(source, options) {
4269
+ if (options?.static) {
4270
+ const component = untrack(source);
4271
+ if (component && typeof component.then === "function") throw new Error("dynamic(): a static source must resolve synchronously, not to a promise");
4272
+ if (typeof component === "function") return props => component(props);
4273
+ if (typeof component === "string") return props => ssrElement(component, props, undefined, true);
4274
+ return () => undefined;
4275
+ }
4276
+ const cached = createMemo(() => {
4277
+ const next = source();
4278
+ if (!next || typeof next.then !== "function") return next;
4279
+ return {
4280
+ [FLIGHT]: next
4281
+ };
4282
+ });
4283
+ const deferStream = !!options?.deferStream;
4284
+ return props => {
4285
+ const ctx = sharedConfig.context;
4286
+ let gated = !deferStream || !ctx?.async;
4287
+ const value = createMemo(() => {
4288
+ let c;
4289
+ try {
4290
+ c = cached();
4291
+ } catch (err) {
4292
+ if (!gated && err instanceof NotReadyError && !err.source?.$clientHole) {
4293
+ gated = true;
4294
+ ctx.block(Promise.resolve(err.source).then(() => {}, () => {}));
4295
+ }
4296
+ throw err;
4297
+ }
4298
+ if (!c || !c[FLIGHT]) return c;
4299
+ const next = c[FLIGHT];
4300
+ return {
4301
+ then: (onFulfilled, onRejected) => next.then(resolved => {
4302
+ let landed;
4303
+ try {
4304
+ landed = classifyLanding(resolved);
4305
+ } catch (err) {
4306
+ if (onRejected) return onRejected(err);
4307
+ throw err;
4308
+ }
4309
+ return onFulfilled ? onFulfilled(landed) : landed;
4310
+ }, onRejected)
4311
+ };
4312
+ }, {
4313
+ deferStream
4314
+ });
4315
+ return createMemo(() => {
4316
+ const c = value();
4317
+ if (c) {
4318
+ if (typeof c === "function") return c(props);
4319
+ if (typeof c === "string") {
4320
+ return ssrElement(c, props, undefined, true);
4321
+ }
4322
+ }
4323
+ }, {
4324
+ sync: true
4325
+ });
4326
+ };
4327
+ }
4328
+ const FLIGHT = Symbol("solid.dynamic-flight");
4329
+ const SERVER_COMPONENT = Symbol.for("solid.server-component");
4330
+ function classifyLanding(resolved) {
4331
+ if (typeof resolved !== "function" || SERVER_COMPONENT in resolved) return resolved;
4332
+ const message = "[DYNAMIC_ASYNC_COMPONENT] An async dynamic() source resolved to a client component " + "function, which cannot be serialized for hydration: the client would re-run the source " + "and wait on it while hydrating, committing the enclosing <Loading> to a fallback the " + "server never rendered. Resolve the async upstream — a createAsync()/createMemo() the " + "source reads synchronously (`dynamic(() => page() ? Editor : Viewer)`) — or use lazy() " + "for a code-split component. A source may stay async when it resolves to a server " + "component or a serializable value (a tag name)." ;
4333
+ recordFinding({
4334
+ code: "DYNAMIC_ASYNC_COMPONENT",
4335
+ kind: "ssr",
4336
+ severity: "error",
4337
+ message,
4338
+ data: {
4339
+ component: resolved.name || undefined
4340
+ }
4341
+ }, null);
4342
+ throw new Error(message);
4343
+ }
4344
+ function Dynamic(props) {
4345
+ const Comp = dynamic(() => props.component);
4346
+ return createComponent(Comp, omit(props, "component"));
4347
+ }
4348
+ function Portal(props) {
4349
+ const o = getOwner();
4350
+ if (o?.id != null) getNextChildId(o);
4351
+ return undefined;
4352
+ }
4353
+ function registerClientOnlyPreload(moduleUrl) {
4354
+ const ctx = sharedConfig.context;
4355
+ if (!ctx?.registerAsset || !ctx.resolveAssets) return;
4356
+ const registerAsset = ctx.registerAsset;
4357
+ const resolve = ctx.resolveAssets;
4358
+ const apply = assets => {
4359
+ if (!assets) return;
4360
+ for (let i = 0; i < assets.css.length; i++) {
4361
+ const css = assets.css[i];
4362
+ if (typeof css === "string") registerAsset("style", css);else registerAsset("inline-style", css);
4363
+ }
4364
+ if (assets.preloads) {
4365
+ for (let i = 0; i < assets.preloads.length; i++) {
4366
+ registerAsset("preload", assets.preloads[i]);
4367
+ }
4368
+ }
4369
+ for (let i = 0; i < assets.js.length; i++) registerAsset("module", assets.js[i]);
4370
+ };
4371
+ const assets = resolve(moduleUrl);
4372
+ if (assets && typeof assets.then === "function") {
4373
+ const boundary = ctx._currentBoundaryId;
4374
+ assets.then(resolved => {
4375
+ const current = ctx._currentBoundaryId;
4376
+ ctx._currentBoundaryId = boundary;
4377
+ try {
4378
+ apply(resolved);
4379
+ } finally {
4380
+ ctx._currentBoundaryId = current;
4381
+ }
4382
+ },
4383
+ () => {});
4384
+ } else {
4385
+ apply(assets);
4386
+ }
4387
+ }
4388
+ function clientOnly(_fn, _options = {}, moduleUrl) {
4389
+ return props => {
4390
+ if (moduleUrl) registerClientOnlyPreload(moduleUrl);
4391
+ return createMemo(() => props.fallback);
4392
+ };
4393
+ }
4394
+ const statusLedgers = /* @__PURE__ */new WeakMap();
4395
+ const headerLedgers = /* @__PURE__ */new WeakMap();
4396
+ function httpStatus(code, text) {
4397
+ const event = getRequestEvent();
4398
+ const response = event && event.response;
4399
+ if (response && !response.committed) {
4400
+ let ledger = statusLedgers.get(response);
4401
+ if (!ledger) {
4402
+ ledger = {
4403
+ base: {
4404
+ status: response.status,
4405
+ statusText: response.statusText
4406
+ },
4407
+ live: []
4408
+ };
4409
+ statusLedgers.set(response, ledger);
4410
+ }
4411
+ const declaration = {
4412
+ status: code,
4413
+ statusText: text
4414
+ };
4415
+ ledger.live.push(declaration);
4416
+ response.status = code;
4417
+ response.statusText = text;
4418
+ onCleanup(() => {
4419
+ if (response.committed) return;
4420
+ const index = ledger.live.indexOf(declaration);
4421
+ if (index < 0) return;
4422
+ ledger.live.splice(index, 1);
4423
+ const effective = ledger.live.length ? ledger.live[ledger.live.length - 1] : ledger.base;
4424
+ response.status = effective.status;
4425
+ response.statusText = effective.statusText;
4426
+ if (!ledger.live.length) statusLedgers.delete(response);
4427
+ });
4428
+ }
4429
+ }
4430
+ function httpHeader(name, value, options) {
4431
+ const event = getRequestEvent();
4432
+ const response = event && event.response;
4433
+ if (response && !response.committed) {
4434
+ const headers = response.headers;
4435
+ const key = name.toLowerCase();
4436
+ const setCookie = key === "set-cookie";
4437
+ let ledgers = headerLedgers.get(response);
4438
+ if (!ledgers) headerLedgers.set(response, ledgers = new Map());
4439
+ let ledger = ledgers.get(key);
4440
+ if (!ledger) {
4441
+ ledger = {
4442
+ base: setCookie ? headers.getSetCookie() : headers.get(name),
4443
+ live: []
4444
+ };
4445
+ ledgers.set(key, ledger);
4446
+ }
4447
+ const declaration = {
4448
+ value,
4449
+ append: !!(options && options.append)
4450
+ };
4451
+ ledger.live.push(declaration);
4452
+ if (declaration.append) headers.append(name, value);else headers.set(name, value);
4453
+ onCleanup(() => {
4454
+ if (response.committed) return;
4455
+ const index = ledger.live.indexOf(declaration);
4456
+ if (index < 0) return;
4457
+ ledger.live.splice(index, 1);
4458
+ headers.delete(name);
4459
+ if (setCookie) {
4460
+ for (const cookie of ledger.base) headers.append(name, cookie);
4461
+ } else if (ledger.base !== null) {
4462
+ headers.set(name, ledger.base);
4463
+ }
4464
+ for (const d of ledger.live) {
4465
+ if (d.append) headers.append(name, d.value);else headers.set(name, d.value);
4466
+ }
4467
+ if (!ledger.live.length) ledgers.delete(key);
4468
+ });
4469
+ }
4470
+ }
4471
+
4472
+ export { CLAIMS_DOCUMENT, CLAIMS_STREAM, CLAIM_PROP, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HREF, HydrationScript, MathMLElements, NULL_BODY_STATUSES, Namespaces, Portal, RESPONSE_HEADER_VALUE_LIMIT, REVALIDATE_ALL, REVALIDATE_HEADER, RawTextElements, RequestContext, ResponseEnvelope, SAFE_ERROR, SVGElements, VoidElements, notSup as acquireAsset, notSup as addEvent, applyRef, notSup as assign, claimElement, claimElementTree, notSup as className, clearFlashCookie, clientOnly, commitEventResponse, commitResponseStub, composeMiddleware, configureServerErrors, createLiveHoles, createRequestEvent, createResponseStub, createSSRResponse, notSup as delegateEvents, dynamic, notSup as dynamicProperty, effect, escape, generateHydrationScript, notSup as getDelegatedRoot, getExpectedRedirectStatus, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getRequestEvent, getServerFunctionMetadata, getServerFunctionRPC, getTraceContext, hasFlashCookie, httpHeader, httpStatus, notSup as hydrate, notSup as insert, isDev, isHref, isResponseEnvelope, isSafeError, isServer, isServerFunction, markSafeError, memo, parseCookieHeader, notSup as readShallow, redirect, notSup as ref, notSup as registerDelegatedContainer, notSup as registerDelegatedRoot, registerElementClaim, reload, notSup as render, renderToStream, renderToString, resolveSSRNode, resolveSSRSelectValues, respond, notSup as runHydrationEvents, scriptNonce, serializeCookie, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as setStyleProperty, notSup as spread, ssr, ssrAttribute, ssrClaim, ssrClassName, ssrElement, ssrElementAttribute, ssrGroup, ssrHydrationKey, ssrSelectValues, ssrStyle, ssrStyleProperty, notSup as style, styleNonce, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useHead };