@solidjs/web 2.0.0-rc.5 → 2.0.0-rc.7

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 (52) hide show
  1. package/dist/server.cjs +122 -38
  2. package/dist/server.dev.cjs +3794 -0
  3. package/dist/server.dev.js +3627 -0
  4. package/dist/server.js +123 -39
  5. package/dist/web.cjs +102 -366
  6. package/dist/{dev.cjs → web.dev.cjs} +153 -376
  7. package/dist/{dev.js → web.dev.js} +155 -374
  8. package/dist/web.js +104 -364
  9. package/frames/dist/client.cjs +11 -3
  10. package/frames/dist/client.dev.cjs +11 -3
  11. package/frames/dist/client.dev.js +11 -3
  12. package/frames/dist/client.js +11 -3
  13. package/frames/dist/server.cjs +320 -53
  14. package/frames/dist/server.dev.cjs +4584 -0
  15. package/frames/dist/server.dev.js +4571 -0
  16. package/frames/dist/server.js +320 -53
  17. package/frames/package.json +10 -0
  18. package/package.json +78 -8
  19. package/serialization/dist/decode.cjs +18 -4
  20. package/serialization/dist/decode.js +18 -4
  21. package/serialization/dist/serialization.cjs +18 -4
  22. package/serialization/dist/serialization.js +18 -4
  23. package/server-functions/dist/client.cjs +27 -16
  24. package/server-functions/dist/client.js +27 -16
  25. package/server-functions/dist/server.cjs +529 -131
  26. package/server-functions/dist/server.dev.cjs +536 -130
  27. package/server-functions/dist/server.dev.js +536 -130
  28. package/server-functions/dist/server.js +529 -131
  29. package/types/client.d.ts +1 -3
  30. package/types/constants.d.ts +3 -1
  31. package/types/frames/frame-client.d.ts +1 -1
  32. package/types/head.d.ts +3 -0
  33. package/types/index.d.ts +18 -7
  34. package/types/index.server.d.ts +31 -9
  35. package/types/render.d.ts +3 -1
  36. package/types/server-functions/flash.d.ts +12 -3
  37. package/types/server-functions/server.d.ts +100 -5
  38. package/types/server-mock.d.ts +43 -7
  39. package/types/server.d.ts +47 -5
  40. package/types-cjs/client.d.cts +1 -3
  41. package/types-cjs/constants.d.cts +3 -1
  42. package/types-cjs/frames/frame-client.d.cts +1 -1
  43. package/types-cjs/head.d.cts +3 -0
  44. package/types-cjs/index.d.cts +18 -7
  45. package/types-cjs/index.server.d.cts +31 -9
  46. package/types-cjs/render.d.cts +3 -1
  47. package/types-cjs/server-functions/flash.d.cts +12 -3
  48. package/types-cjs/server-functions/server.d.cts +100 -5
  49. package/types-cjs/server-mock.d.cts +43 -7
  50. package/types-cjs/server.d.cts +47 -5
  51. package/types/patch-driver.d.ts +0 -3
  52. package/types-cjs/patch-driver.d.cts +0 -3
@@ -0,0 +1,3627 @@
1
+ import { createRenderEffect, getOwner, createMemo, sharedConfig, createRoot, inServerComponentScope, ssrHandleError, creationStamp, runWithOwner, createComponent, omit, getNextChildId, NotReadyError, onCleanup, getProjectionTrace } from 'solid-js';
2
+ export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps, ssrScope as scope, sharedConfig, untrack } from 'solid-js';
3
+ import { Feature, createStream, Serializer, getCrossReferenceHeader } from 'seroval';
4
+ import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
5
+
6
+ const DOMWithState = {
7
+ INPUT: {
8
+ value: 1,
9
+ defaultValue: 2,
10
+ checked: 1,
11
+ defaultChecked: 2
12
+ },
13
+ SELECT: {
14
+ value: 1
15
+ },
16
+ OPTION: {
17
+ value: 1,
18
+ selected: 1,
19
+ defaultSelected: 2
20
+ },
21
+ TEXTAREA: {
22
+ value: 1,
23
+ defaultValue: 2
24
+ },
25
+ VIDEO: {
26
+ muted: 1,
27
+ defaultMuted: 2
28
+ },
29
+ AUDIO: {
30
+ muted: 1,
31
+ defaultMuted: 2
32
+ }
33
+ };
34
+ const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]);
35
+ 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"]);
36
+ const SVGElements = /*#__PURE__*/new Set([
37
+ "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",
38
+ "set", "stop",
39
+ "svg", "switch", "symbol", "text", "textPath",
40
+ "tref", "tspan", "use", "view", "vkern"]);
41
+ 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"]);
42
+ const Namespaces = {
43
+ svg: "http://www.w3.org/2000/svg",
44
+ mathml: "http://www.w3.org/1998/Math/MathML",
45
+ xlink: "http://www.w3.org/1999/xlink",
46
+ xml: "http://www.w3.org/XML/1998/namespace"
47
+ };
48
+ const VoidElements = /*#__PURE__*/new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
49
+ const RawTextElements = /*#__PURE__*/new Set(["style", "script", "noscript", "template", "textarea", "title"]);
50
+ 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(","));
51
+ const COMPOSED_BODY_FRAMING = /*#__PURE__*/new Set(["content-length", "content-encoding", "transfer-encoding"]);
52
+ function isHttpNavigationTarget(target) {
53
+ try {
54
+ const protocol = new URL(target, "http://base.invalid").protocol;
55
+ return protocol === "http:" || protocol === "https:";
56
+ } catch {
57
+ return false;
58
+ }
59
+ }
60
+
61
+ const transparentOptions = {
62
+ transparent: true,
63
+ sync: true
64
+ };
65
+ const syncOptions = {
66
+ sync: true
67
+ };
68
+ function effect(fn, effectFn, options) {
69
+ const nodeOptions = options ? {
70
+ sync: true,
71
+ ...options,
72
+ transparent: !options.scope
73
+ } : transparentOptions;
74
+ {
75
+ createRenderEffect(prev => {
76
+ getOwner();
77
+ return fn(prev);
78
+ }, (value, prev) => {
79
+ try {
80
+ return effectFn(value, prev);
81
+ } finally {
82
+ }
83
+ }, nodeOptions);
84
+ return;
85
+ }
86
+ }
87
+ function memo(fn) {
88
+ return createMemo(() => fn(), syncOptions);
89
+ }
90
+
91
+ const STATE = Symbol.for("solid.container-trace-state");
92
+ const state = globalThis[STATE] || (globalThis[STATE] = {
93
+ materialized: new WeakMap(),
94
+ materializedValues: new WeakSet()
95
+ });
96
+ function setContainerTraceResolver(fn) {
97
+ state.resolveTrace = fn;
98
+ }
99
+ function setContainerTraceStreamMint(fn) {
100
+ state.streamOf = fn;
101
+ }
102
+ const TRACE = Symbol.for("solid.container-trace");
103
+ function materialize(marker) {
104
+ let value = state.materialized.get(marker.$tr);
105
+ if (value === undefined) {
106
+ value = state.materializeTrace(marker);
107
+ state.materialized.set(marker.$tr, value);
108
+ if (value !== null && typeof value === "object") state.materializedValues.add(value);
109
+ }
110
+ return value;
111
+ }
112
+ function parseTrace(value, ctx) {
113
+ const trace = value[TRACE];
114
+ const sub = trace.subscribe();
115
+ return {
116
+ a: trace.array ? 1 : 0,
117
+ i: ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
118
+ };
119
+ }
120
+ const ContainerTracePlugin = {
121
+ tag: "solid/container-trace",
122
+ test(value) {
123
+ return value != null && typeof value === "object" && TRACE in value;
124
+ },
125
+ parse: {
126
+ sync() {
127
+ throw new Error("A reactive container can only be serialized by a streaming serializer.");
128
+ },
129
+ async async(value, ctx) {
130
+ const trace = value[TRACE];
131
+ const sub = trace.subscribe();
132
+ return {
133
+ a: trace.array ? 1 : 0,
134
+ i: await ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
135
+ };
136
+ },
137
+ stream: parseTrace
138
+ },
139
+ serialize(node, ctx) {
140
+ return "{$tr:" + ctx.serialize(node.i) + ",$ta:" + node.a + "}";
141
+ },
142
+ deserialize(node, ctx) {
143
+ const iterable = ctx.deserialize(node.i);
144
+ const marker = {
145
+ $tr: iterable,
146
+ $ta: node.a
147
+ };
148
+ return state.materializeTrace ? materialize(marker) : marker;
149
+ }
150
+ };
151
+
152
+ setContainerTraceStreamMint(iterable => {
153
+ const stream = createStream();
154
+ (async () => {
155
+ try {
156
+ for await (const value of iterable) stream.next(value);
157
+ stream.return(undefined);
158
+ } catch (error) {
159
+ stream.throw(error);
160
+ }
161
+ })();
162
+ return stream;
163
+ });
164
+ const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
165
+ CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
166
+ FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
167
+ ContainerTracePlugin]);
168
+ function resolveSerializerPlugins(customPlugins) {
169
+ return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
170
+ }
171
+ Feature.RegExp;
172
+
173
+ const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
174
+ const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
175
+ const HYDRATION_GLOBAL = "_$HY.r";
176
+ function createSerializer(options) {
177
+ return new Serializer({
178
+ ...options,
179
+ plugins: resolveSerializerPlugins(options.plugins),
180
+ disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures(options.serializeErrorStacks)
181
+ });
182
+ }
183
+ function createHydrationSerializer({
184
+ onData,
185
+ onDone,
186
+ scopeId,
187
+ onError,
188
+ plugins
189
+ }) {
190
+ return createSerializer({
191
+ scopeId,
192
+ plugins,
193
+ globalIdentifier: HYDRATION_GLOBAL,
194
+ onData,
195
+ onDone,
196
+ onError
197
+ });
198
+ }
199
+ function getLocalHeaderScript(id) {
200
+ return getCrossReferenceHeader(id) + ";";
201
+ }
202
+
203
+ const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
204
+ // PURE-annotated factory (same convention as solid's MockPromise): the brand
205
+ const ResponseEnvelope = /* @__PURE__ */(() => {
206
+ class ResponseEnvelope {
207
+ constructor(response, value) {
208
+ this.response = response;
209
+ this.value = value;
210
+ }
211
+ }
212
+ ResponseEnvelope.prototype[ENVELOPE] = true;
213
+ return ResponseEnvelope;
214
+ })();
215
+ function isResponseEnvelope(value) {
216
+ return !!(value && typeof value === "object" && value[ENVELOPE]);
217
+ }
218
+ const HREF = Symbol.for("solid.Href");
219
+ function isHref(value) {
220
+ return !!(value && (typeof value === "object" || typeof value === "function") && value[HREF]);
221
+ }
222
+ const SAFE_ERROR = Symbol.for("solid.SafeError");
223
+ function markSafeError(error) {
224
+ if (error && (typeof error === "object" || typeof error === "function")) {
225
+ Object.defineProperty(error, SAFE_ERROR, {
226
+ value: true,
227
+ enumerable: false,
228
+ configurable: true
229
+ });
230
+ }
231
+ return error;
232
+ }
233
+ function isSafeError(value) {
234
+ return !!(value && (typeof value === "object" || typeof value === "function") && value[SAFE_ERROR]);
235
+ }
236
+ const REVALIDATE_HEADER = "X-Revalidate";
237
+ const RESPONSE_HEADER_VALUE_LIMIT = 4096;
238
+ function initWithRevalidate(init = {}) {
239
+ const resolved = typeof init === "number" ? {
240
+ status: init
241
+ } : init;
242
+ const {
243
+ revalidate,
244
+ ...responseInit
245
+ } = resolved;
246
+ let headers;
247
+ if (responseInit.headers && responseInit.headers.getSetCookie) {
248
+ headers = new Headers();
249
+ responseInit.headers.forEach((value, key) => {
250
+ if (key !== "set-cookie") headers.append(key, value);
251
+ });
252
+ for (const cookie of responseInit.headers.getSetCookie()) {
253
+ headers.append("Set-Cookie", cookie);
254
+ }
255
+ } else {
256
+ headers = new Headers(responseInit.headers);
257
+ }
258
+ if (revalidate !== undefined) {
259
+ const keys = revalidate.toString();
260
+ if (keys.length > RESPONSE_HEADER_VALUE_LIMIT) {
261
+ 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.`);
262
+ }
263
+ headers.set(REVALIDATE_HEADER, keys);
264
+ }
265
+ return {
266
+ responseInit,
267
+ headers
268
+ };
269
+ }
270
+ function redirect(url, init = 302) {
271
+ if (typeof url !== "string" && !isHref(url)) {
272
+ throw new TypeError("redirect() expects a string URL or an Href-branded value (Symbol.for('solid.Href')).");
273
+ }
274
+ const {
275
+ responseInit,
276
+ headers
277
+ } = initWithRevalidate(init);
278
+ if (responseInit.status === undefined) {
279
+ responseInit.status = 302;
280
+ }
281
+ const target = typeof url === "string" ? url : url[HREF];
282
+ const location = typeof target === "string" ? target : String(url);
283
+ const encoded = location.replace(/[^\x00-\x7f]/gu, encodeURIComponent);
284
+ if (encoded.length > RESPONSE_HEADER_VALUE_LIMIT) {
285
+ 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.`);
286
+ }
287
+ headers.set("Location", encoded);
288
+ return new Response(null, {
289
+ ...responseInit,
290
+ headers
291
+ });
292
+ }
293
+ function reload(init = {}) {
294
+ const {
295
+ responseInit,
296
+ headers
297
+ } = initWithRevalidate(init);
298
+ return new Response(null, {
299
+ ...responseInit,
300
+ headers
301
+ });
302
+ }
303
+ const NULL_BODY_STATUSES = new Set([204, 205, 304]);
304
+ function respond(value, init = {}) {
305
+ const {
306
+ responseInit,
307
+ headers
308
+ } = initWithRevalidate(init);
309
+ for (const header of COMPOSED_BODY_FRAMING) headers.delete(header);
310
+ if (NULL_BODY_STATUSES.has(responseInit.status)) {
311
+ return new ResponseEnvelope(new Response(null, {
312
+ ...responseInit,
313
+ headers
314
+ }), value);
315
+ }
316
+ headers.set("Content-Type", "application/json");
317
+ return new ResponseEnvelope(new Response(JSON.stringify(value), {
318
+ ...responseInit,
319
+ headers
320
+ }), value);
321
+ }
322
+
323
+ const SERVER_FUNCTION_METADATA = Symbol.for("solid.ServerFunctionMetadata");
324
+ function getServerFunctionMetadata(fn) {
325
+ if (typeof fn !== "function") return undefined;
326
+ return fn[SERVER_FUNCTION_METADATA] || undefined;
327
+ }
328
+ function isServerFunction(fn) {
329
+ return typeof fn === "function" && !!fn[SERVER_FUNCTION_METADATA];
330
+ }
331
+ const SERVER_FUNCTION_RPC = Symbol.for("solid.ServerFunctionRPC");
332
+ function getServerFunctionRPC() {
333
+ return globalThis[SERVER_FUNCTION_RPC];
334
+ }
335
+
336
+ function parseCookieHeader(header) {
337
+ const cookies = {};
338
+ if (!header) return cookies;
339
+ for (const part of header.split(";")) {
340
+ const eq = part.indexOf("=");
341
+ if (eq < 0) continue;
342
+ const name = decodeSafe(part.slice(0, eq).trim());
343
+ let value = part.slice(eq + 1).trim();
344
+ if (value.length > 1 && value[0] === '"' && value[value.length - 1] === '"') {
345
+ value = value.slice(1, -1);
346
+ }
347
+ cookies[name] = decodeSafe(value);
348
+ }
349
+ return cookies;
350
+ }
351
+ function decodeSafe(text) {
352
+ try {
353
+ return decodeURIComponent(text);
354
+ } catch {
355
+ return text;
356
+ }
357
+ }
358
+ function serializeCookie(name, value, options = {}) {
359
+ assertServableCookie(name, options);
360
+ let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
361
+ cookie += `; Path=${options.path === undefined ? "/" : options.path}`;
362
+ if (options.domain) cookie += `; Domain=${options.domain}`;
363
+ if (options.maxAge !== undefined) cookie += `; Max-Age=${Math.trunc(options.maxAge)}`;
364
+ if (options.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
365
+ if (options.httpOnly) cookie += "; HttpOnly";
366
+ if (options.secure) cookie += "; Secure";
367
+ if (options.partitioned) cookie += "; Partitioned";
368
+ if (options.sameSite) {
369
+ const sameSite = options.sameSite.toLowerCase();
370
+ cookie += `; SameSite=${sameSite === "none" ? "None" : sameSite === "strict" ? "Strict" : "Lax"}`;
371
+ }
372
+ return cookie;
373
+ }
374
+ function assertServableCookie(name, options) {
375
+ const reject = reason => {
376
+ throw new Error(`serializeCookie: every browser silently rejects this cookie — ${reason}. ` + `It would never come back on a request, with no error anywhere.`);
377
+ };
378
+ const lower = name.toLowerCase();
379
+ if (lower.startsWith("__host-")) {
380
+ if (!options.secure) reject(`the __Host- prefix on \`${name}\` requires \`secure: true\``);
381
+ 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`);
382
+ if (options.domain) reject(`the __Host- prefix on \`${name}\` forbids \`Domain\` (got \`${options.domain}\`)`);
383
+ } else if (lower.startsWith("__secure-") && !options.secure) {
384
+ reject(`the __Secure- prefix on \`${name}\` requires \`secure: true\``);
385
+ }
386
+ if (options.sameSite && options.sameSite.toLowerCase() === "none" && !options.secure) {
387
+ reject("`SameSite=None` requires `secure: true`");
388
+ }
389
+ if (options.partitioned && !options.secure) {
390
+ reject("`Partitioned` requires `secure: true`");
391
+ }
392
+ }
393
+ const FLASH_COOKIE = "flash";
394
+ const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
395
+ function hasFlashCookie(cookieHeader) {
396
+ return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
397
+ }
398
+ function clearFlashCookie() {
399
+ return `${FLASH_COOKIE}=; Max-Age=0; Path=/`;
400
+ }
401
+
402
+ const ERROR_HEADER = "X-Server-Function-Error";
403
+ const BODY_FORMAT_HEADER = "X-Server-Function-Format";
404
+ const REDIRECT_HEADER = "X-Server-Function-Redirect";
405
+ const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
406
+
407
+ const HEAD_ELIGIBLE_TAGS = new Set(["title", "meta", "link", "style", "script", "base"]);
408
+ const HEAD_ATTR_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;
409
+ const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "stylesheet"]);
410
+ const RESOURCE_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
411
+ const STYLESHEET_FETCH_META = new Set(["crossorigin", "integrity", "referrerpolicy", "fetchpriority"]);
412
+ function evalHeadValue(v) {
413
+ return typeof v === "function" ? v() : v;
414
+ }
415
+ function evalHeadProps(props, presets) {
416
+ const out = {};
417
+ for (const name in props) out[name] = presets && name in presets ? presets[name] : evalHeadValue(props[name]);
418
+ return out;
419
+ }
420
+ function classifyHeadTag(desc) {
421
+ const tag = desc.tag;
422
+ if (tag === "link") {
423
+ const rel = evalHeadValue(desc.props && desc.props.rel);
424
+ return {
425
+ resource: RESOURCE_LINK_RELS.has(rel),
426
+ rel
427
+ };
428
+ }
429
+ if (tag === "style") return {
430
+ resource: !!(desc.props && "href" in desc.props)
431
+ };
432
+ if (tag === "script") return {
433
+ resource: !!(desc.props && "src" in desc.props)
434
+ };
435
+ return {
436
+ resource: false
437
+ };
438
+ }
439
+ function qualifierValue(name, value) {
440
+ if (value == null || value === false) return null;
441
+ if (name === "imagesrcset" || name === "imagesizes") return typeof value === "string" && value !== "" ? value : null;
442
+ const v = value === true ? "" : String(value);
443
+ if (name === "as") return asciiLowerCase(v);
444
+ if (name !== "crossorigin") return v;
445
+ return v.length === 15 && v.toLowerCase() === "use-credentials" ? v.toLowerCase() : "anonymous";
446
+ }
447
+ function asciiLowerCase(value) {
448
+ return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
449
+ }
450
+ function resourceIdentity(tag, props) {
451
+ const url = String(props.href || props.src || "");
452
+ let id = "res:" + tag + ":" + (props.rel || "") + ":" + url.length + ":" + url;
453
+ for (let i = 0; i < RESOURCE_QUALIFIERS.length; i++) {
454
+ const q = RESOURCE_QUALIFIERS[i];
455
+ const value = qualifierValue(q, props[q]);
456
+ if (value !== null) id += ":" + q + "=" + value.length + ":" + value;
457
+ }
458
+ return id;
459
+ }
460
+ function replaceableIdentity(tag, props, key, unique) {
461
+ if (tag === "title") return "title";
462
+ if (tag === "base") return "base";
463
+ if (tag === "meta" && props.charset != null) return "charset";
464
+ if (key != null) return tag + ":key:" + key;
465
+ if (tag === "meta") {
466
+ for (const ns of ["name", "property", "http-equiv"]) if (props[ns] != null) return "meta:" + ns + ":" + props[ns] + (props.media != null ? ":media=" + props.media : "");
467
+ return unique;
468
+ }
469
+ if (tag === "link") {
470
+ const rel = props.rel || "";
471
+ if (rel === "icon" || rel === "apple-touch-icon") return "link:" + rel + (props.sizes != null ? ":sizes=" + props.sizes : "") + (props.type != null ? ":type=" + props.type : "");
472
+ return "link:" + rel + ":" + (props.href || "");
473
+ }
474
+ return unique;
475
+ }
476
+ function resolveHead(groups) {
477
+ const winners = new Map();
478
+ const sorted = groups.slice().sort((a, b) => a.seq - b.seq);
479
+ for (let i = 0; i < sorted.length; i++) {
480
+ const group = sorted[i];
481
+ const byIdentity = new Map();
482
+ for (let j = 0; j < group.tags.length; j++) {
483
+ const t = group.tags[j];
484
+ let list = byIdentity.get(t.identity);
485
+ if (!list) byIdentity.set(t.identity, list = []);
486
+ list.push(t);
487
+ }
488
+ for (const [identity, tags] of byIdentity) {
489
+ if (identity === "title") {
490
+ if (tags.length > 1) console.warn("Multiple <title> tags in one head group; the last one wins.");
491
+ winners.set(identity, {
492
+ seq: group.seq,
493
+ tags: [tags[tags.length - 1]]
494
+ });
495
+ } else {
496
+ winners.set(identity, {
497
+ seq: group.seq,
498
+ tags
499
+ });
500
+ }
501
+ }
502
+ }
503
+ return winners;
504
+ }
505
+
506
+ function joinAssetPath(base, file) {
507
+ if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(file)) return file;
508
+ if (typeof base !== "string" || !base) base = "/";
509
+ if (base[base.length - 1] !== "/") base += "/";
510
+ return base + (file[0] === "/" ? file.slice(1) : file);
511
+ }
512
+ function eachCandidate(srcset, visit) {
513
+ let i = 0;
514
+ const n = srcset.length;
515
+ while (i < n) {
516
+ while (i < n && /[\s,]/.test(srcset[i])) i++;
517
+ const start = i;
518
+ while (i < n && !/\s/.test(srcset[i])) i++;
519
+ if (i === start) return false;
520
+ const raw = srcset.slice(start, i);
521
+ const url = raw.replace(/,+$/, "");
522
+ let descriptors = "";
523
+ if (url === raw) {
524
+ const from = i;
525
+ while (i < n && srcset[i] !== ",") i++;
526
+ descriptors = srcset.slice(from, i);
527
+ }
528
+ if (url && visit(url, descriptors)) return true;
529
+ }
530
+ return false;
531
+ }
532
+ function hasRelativeCandidate(srcset) {
533
+ return eachCandidate(srcset, url => !/^(?:[a-zA-Z][a-zA-Z0-9+.-]*:|\/)/.test(url));
534
+ }
535
+ function hasWidthDescriptor(srcset) {
536
+ return eachCandidate(srcset, (_, descriptors) => /(?:^|\s)\d+(?:\.\d+)?w(?=\s|$)/.test(descriptors));
537
+ }
538
+ function resolveAssets(moduleUrl, manifest) {
539
+ if (!manifest) return null;
540
+ const base = manifest._base;
541
+ const entry = manifest[moduleUrl];
542
+ if (!entry) return null;
543
+ const css = [];
544
+ const js = [];
545
+ let preloads;
546
+ const visited = new Set();
547
+ const walk = key => {
548
+ if (visited.has(key)) return;
549
+ visited.add(key);
550
+ const e = manifest[key];
551
+ if (!e) return;
552
+ js.push(joinAssetPath(base, e.file));
553
+ if (e.css) for (let i = 0; i < e.css.length; i++) css.push(joinAssetPath(base, e.css[i]));
554
+ if (e.preloads) {
555
+ for (let i = 0; i < e.preloads.length; i++) {
556
+ const link = e.preloads[i];
557
+ const href = link && typeof link.href === "string" && link.href;
558
+ const srcset = link && typeof link.imagesrcset === "string" && link.imagesrcset;
559
+ if (!href && !srcset) continue;
560
+ if (!preloads) preloads = [];
561
+ if (href) preloads.push({
562
+ ...link,
563
+ href: joinAssetPath(base, href)
564
+ });else {
565
+ const {
566
+ href: bad,
567
+ ...rest
568
+ } = link;
569
+ if (bad !== undefined) console.warn("Preload href must be a non-empty string; dropping it.", bad);
570
+ preloads.push(rest);
571
+ }
572
+ if (srcset && hasRelativeCandidate(srcset)) console.warn("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);
573
+ }
574
+ }
575
+ if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
576
+ };
577
+ walk(moduleUrl);
578
+ const assets = {
579
+ js,
580
+ css
581
+ };
582
+ if (preloads) assets.preloads = preloads;
583
+ return assets;
584
+ }
585
+ function registerEntryAssets(manifest) {
586
+ if (!manifest || typeof manifest === "function" || typeof manifest.resolve === "function") return;
587
+ const ctx = sharedConfig.context;
588
+ if (!ctx?.registerAsset) return;
589
+ for (const key in manifest) {
590
+ if (manifest[key].isEntry) {
591
+ const assets = resolveAssets(key, manifest);
592
+ if (assets) {
593
+ if (assets.preloads) for (let i = 0; i < assets.preloads.length; i++) ctx.registerAsset("preload", assets.preloads[i]);
594
+ for (let i = 0; i < assets.css.length; i++) ctx.registerAsset("style", assets.css[i]);
595
+ for (let i = 1; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i]);
596
+ }
597
+ return;
598
+ }
599
+ }
600
+ }
601
+ function createAssetTracking() {
602
+ const boundaryModules = new Map();
603
+ const boundaryStyles = new Map();
604
+ const emittedAssets = new Set();
605
+ const inlineStyles = new Map();
606
+ let currentBoundaryId = null;
607
+ return {
608
+ boundaryModules,
609
+ boundaryStyles,
610
+ emittedAssets,
611
+ inlineStyles,
612
+ preloadLinks: null,
613
+ registerInlineStyle(desc) {
614
+ let entry = inlineStyles.get(desc.id);
615
+ if (!entry) {
616
+ entry = {
617
+ id: desc.id,
618
+ content: desc.content || "",
619
+ attrs: desc.attrs,
620
+ emitted: false
621
+ };
622
+ inlineStyles.set(desc.id, entry);
623
+ }
624
+ if (currentBoundaryId) {
625
+ let styles = boundaryStyles.get(currentBoundaryId);
626
+ if (!styles) {
627
+ styles = new Set();
628
+ boundaryStyles.set(currentBoundaryId, styles);
629
+ }
630
+ styles.add(entry);
631
+ }
632
+ return entry;
633
+ },
634
+ get currentBoundaryId() {
635
+ return currentBoundaryId;
636
+ },
637
+ set currentBoundaryId(v) {
638
+ currentBoundaryId = v;
639
+ },
640
+ registerModule(key, entryUrl) {
641
+ const id = currentBoundaryId || "";
642
+ let map = boundaryModules.get(id);
643
+ if (!map) {
644
+ map = {};
645
+ boundaryModules.set(id, map);
646
+ }
647
+ map[key] = entryUrl;
648
+ },
649
+ getBoundaryModules(id) {
650
+ return boundaryModules.get(id) || null;
651
+ },
652
+ getBoundaryStyles(id) {
653
+ return boundaryStyles.get(id) || null;
654
+ }
655
+ };
656
+ }
657
+ function warnUnresolvedModuleAssets(moduleUrl, warned) {
658
+ if (warned.has(moduleUrl)) return;
659
+ warned.add(moduleUrl);
660
+ 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.");
661
+ }
662
+ function guardResolvedAssets(moduleUrl, result, warned) {
663
+ if (result && typeof result.then === "function") {
664
+ return result.then(assets => {
665
+ if (!assets || !assets.js || !assets.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
666
+ return assets;
667
+ });
668
+ }
669
+ if (!result || !result.js || !result.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
670
+ return result;
671
+ }
672
+ function applyAssetTracking(context, tracking, manifest, noScripts) {
673
+ const warned = new Set();
674
+ const guard = noScripts ? resolve => resolve : resolve => moduleUrl => guardResolvedAssets(moduleUrl, resolve(moduleUrl), warned);
675
+ Object.defineProperty(context, "_currentBoundaryId", {
676
+ get() {
677
+ return tracking.currentBoundaryId;
678
+ },
679
+ set(v) {
680
+ tracking.currentBoundaryId = v;
681
+ },
682
+ configurable: true,
683
+ enumerable: true
684
+ });
685
+ context.registerModule = tracking.registerModule;
686
+ context.getBoundaryModules = tracking.getBoundaryModules;
687
+ if (typeof manifest === "function") {
688
+ context.resolveAssets = guard(manifest);
689
+ } else if (manifest && typeof manifest.resolve === "function") {
690
+ context.resolveAssets = guard(key => manifest.resolve(key));
691
+ if (typeof manifest.resolveSync === "function") {
692
+ context.resolveAssetsSync = key => manifest.resolveSync(key);
693
+ }
694
+ } else if (manifest) {
695
+ const resolve = moduleUrl => resolveAssets(moduleUrl, manifest);
696
+ context.resolveAssets = guard(resolve);
697
+ context.resolveAssetsSync = resolve;
698
+ }
699
+ }
700
+ function isCssUrl(url) {
701
+ const q = url.search(/[?#]/);
702
+ return (q === -1 ? url : url.slice(0, q)).endsWith(".css");
703
+ }
704
+ const RESPONSIVE_ATTRIBUTES = ["imagesrcset", "imagesizes"];
705
+ function isSetAttr(value) {
706
+ return value != null && value !== false && value !== "";
707
+ }
708
+ const PRELOAD_LINK_ATTRIBUTES = ["type", "crossorigin", "integrity", "referrerpolicy", "fetchpriority", "media", "imagesrcset", "imagesizes"];
709
+ function registerPreloadLink(tracking, headRegistry, link, nonce) {
710
+ if (!link || typeof link !== "object") {
711
+ console.warn('registerAsset("preload") requires a descriptor object.', link);
712
+ return null;
713
+ }
714
+ if (typeof link.as !== "string") {
715
+ console.warn('registerAsset("preload") requires an as destination.');
716
+ return null;
717
+ }
718
+ const as = asciiLowerCase(link.as);
719
+ let destination = null;
720
+ switch (as) {
721
+ case "script":
722
+ case "style":
723
+ destination = as;
724
+ break;
725
+ case "fetch":
726
+ case "font":
727
+ case "image":
728
+ case "track":
729
+ break;
730
+ default:
731
+ console.warn(`registerAsset("preload") received an unsupported as destination "${link.as}".`);
732
+ return null;
733
+ }
734
+ const responsive = as === "image";
735
+ if (!responsive && (isSetAttr(link.imagesrcset) || isSetAttr(link.imagesizes))) console.warn('registerAsset("preload") only supports imagesrcset and imagesizes with as="image".');
736
+ let srcset = null;
737
+ let sizes = null;
738
+ if (responsive) {
739
+ for (const name of RESPONSIVE_ATTRIBUTES) {
740
+ const value = link[name];
741
+ if (!isSetAttr(value)) continue;
742
+ if (typeof value !== "string") {
743
+ console.warn(`registerAsset("preload") expects a string ${name}.`);
744
+ continue;
745
+ }
746
+ if (name === "imagesrcset") srcset = value;else sizes = value;
747
+ }
748
+ }
749
+ const href = typeof link.href === "string" && link.href ? link.href : null;
750
+ if (!href && link.href != null && link.href !== false) console.warn("Preload href must be a non-empty string; dropping it.", link.href);
751
+ if (!href && !srcset) {
752
+ console.warn('registerAsset("preload") requires a non-empty string href or imagesrcset.');
753
+ return null;
754
+ }
755
+ if (srcset && !sizes && hasWidthDescriptor(srcset)) console.warn("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);
756
+ const props = {
757
+ rel: "preload"
758
+ };
759
+ if (href) props.href = href;
760
+ props.as = as;
761
+ for (let i = 0; i < PRELOAD_LINK_ATTRIBUTES.length; i++) {
762
+ const name = PRELOAD_LINK_ATTRIBUTES[i];
763
+ if (RESPONSIVE_ATTRIBUTES.indexOf(name) !== -1) {
764
+ const value = name === "imagesrcset" ? srcset : sizes;
765
+ if (value !== null) props[name] = value;
766
+ continue;
767
+ }
768
+ const value = link[name];
769
+ if (value == null || value === false) continue;
770
+ props[name] = value === true ? "" : String(value);
771
+ }
772
+ const identity = resourceIdentity("link", props);
773
+ if (headRegistry.resources.has(identity)) return null;
774
+ if (props.crossorigin == null && (as === "font" || as === "fetch")) console.warn(`registerAsset("preload") with as="${as}" has no crossorigin and may not match the eventual request.`);
775
+ const attrs = headAttrRecord(props);
776
+ const nonceValue = destination && nonce && nonce[destination];
777
+ if (typeof nonceValue === "string" && nonceValue) attrs.nonce = nonceValue;
778
+ const entry = {
779
+ href: props.href,
780
+ attrs,
781
+ attrHtml: renderHeadAttrHtml(props) + nonceAttr(nonce, destination)
782
+ };
783
+ headRegistry.resources.add(identity);
784
+ let links = tracking.preloadLinks;
785
+ if (!links) tracking.preloadLinks = links = [];
786
+ links.push(entry);
787
+ return entry;
788
+ }
789
+ function createHeadRegistry() {
790
+ return {
791
+ pending: [],
792
+ committed: [],
793
+ seq: 0,
794
+ uniq: 0,
795
+ resources: new Set(),
796
+ eagerHtml: "",
797
+ flushed: null,
798
+ shellFlushed: false,
799
+ parkedResources: []
800
+ };
801
+ }
802
+ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags) {
803
+ const boundary = context._currentBoundaryId || "";
804
+ if (typeof tags === "function") {
805
+ registry.pending.push({
806
+ boundary,
807
+ list: tags,
808
+ resource: (desc, rel) => emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel)
809
+ });
810
+ return;
811
+ }
812
+ if (!Array.isArray(tags)) tags = [tags];
813
+ const probe = sharedConfig.context && sharedConfig.context._loadingPhase;
814
+ let replaceable = null;
815
+ for (let i = 0; i < tags.length; i++) {
816
+ const desc = tags[i];
817
+ if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
818
+ console.warn(`useHead: ignoring non-head tag`, desc);
819
+ continue;
820
+ }
821
+ const cls = classifyHeadTag(desc);
822
+ if (probe && !cls.resource) {
823
+ try {
824
+ evalHeadProps(desc.props || {}, cls.rel !== undefined ? {
825
+ rel: cls.rel
826
+ } : undefined);
827
+ evalHeadValue(desc.key);
828
+ } catch (err) {
829
+ if (ssrHandleError(err)) throw err;
830
+ }
831
+ }
832
+ if (cls.resource) {
833
+ emitHeadResource(registry, context, tracking, emitResource, nonce, desc, cls.rel);
834
+ } else {
835
+ (replaceable || (replaceable = [])).push(cls.rel !== undefined ? {
836
+ tag: desc.tag,
837
+ props: desc.props,
838
+ key: desc.key,
839
+ rel: cls.rel
840
+ } : desc);
841
+ }
842
+ }
843
+ if (replaceable) registry.pending.push({
844
+ boundary,
845
+ tags: replaceable
846
+ });
847
+ }
848
+ function headShellReady(registry, block) {
849
+ let ready = true;
850
+ const pends = err => {
851
+ const source = ssrHandleError(err, true);
852
+ if (!source) return false;
853
+ block(source);
854
+ ready = false;
855
+ return true;
856
+ };
857
+ const parked = registry.parkedResources;
858
+ for (let i = parked.length - 1; i >= 0; i--) {
859
+ const {
860
+ desc,
861
+ rel,
862
+ emit
863
+ } = parked[i];
864
+ try {
865
+ evalHeadProps(desc.props || {}, rel !== undefined ? {
866
+ rel
867
+ } : undefined);
868
+ } catch (err) {
869
+ if (pends(err)) continue;
870
+ console.warn(`useHead: error evaluating resource tag props`, err);
871
+ parked.splice(i, 1);
872
+ continue;
873
+ }
874
+ parked.splice(i, 1);
875
+ emit();
876
+ }
877
+ for (let i = 0; i < registry.pending.length; i++) {
878
+ const reg = registry.pending[i];
879
+ if (reg.boundary !== "" || reg.list) continue;
880
+ for (let j = 0; j < reg.tags.length; j++) {
881
+ const desc = reg.tags[j];
882
+ try {
883
+ evalHeadProps(desc.props || {}, desc.rel !== undefined ? {
884
+ rel: desc.rel
885
+ } : undefined);
886
+ evalHeadValue(desc.key);
887
+ } catch (err) {
888
+ pends(err);
889
+ }
890
+ }
891
+ }
892
+ return ready;
893
+ }
894
+ function emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel) {
895
+ let props;
896
+ try {
897
+ props = evalHeadProps(desc.props || {}, rel !== undefined ? {
898
+ rel
899
+ } : undefined);
900
+ } catch (err) {
901
+ const loadingPhase = sharedConfig.context && sharedConfig.context._loadingPhase;
902
+ if (loadingPhase && ssrHandleError(err)) throw err;
903
+ if (!loadingPhase && !context._currentBoundaryId && !registry.shellFlushed && typeof context.block === "function" && ssrHandleError(err, true)) {
904
+ registry.parkedResources.push({
905
+ desc,
906
+ rel,
907
+ emit: () => emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel)
908
+ });
909
+ return;
910
+ }
911
+ console.warn(`useHead: error evaluating resource tag props`, err);
912
+ return;
913
+ }
914
+ const identity = resourceIdentity(desc.tag, props);
915
+ if (registry.resources.has(identity)) return;
916
+ registry.resources.add(identity);
917
+ if (desc.tag === "link" && (rel === "stylesheet" || rel === "modulepreload")) {
918
+ let plain = true;
919
+ let gateable = rel === "stylesheet";
920
+ for (const name in props) {
921
+ if (name === "rel" || name === "href") continue;
922
+ plain = false;
923
+ if (!STYLESHEET_FETCH_META.has(name)) gateable = false;
924
+ }
925
+ if (plain && props.href != null) {
926
+ const isCss = isCssUrl(props.href);
927
+ if (rel === "stylesheet" ? isCss : !isCss) {
928
+ context.registerAsset(rel === "stylesheet" ? "style" : "module", props.href);
929
+ return;
930
+ }
931
+ }
932
+ if (gateable && props.href != null) {
933
+ const attrHtml = renderHeadAttrHtml(props);
934
+ const entry = {
935
+ href: props.href,
936
+ attrHtml,
937
+ attrs: headAttrRecord(props)
938
+ };
939
+ if (tracking.currentBoundaryId) {
940
+ let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
941
+ if (!styles) tracking.boundaryStyles.set(tracking.currentBoundaryId, styles = new Set());
942
+ styles.add(entry);
943
+ }
944
+ const markup = `<link${attrHtml}${nonceAttr(nonce, "style")}>`;
945
+ if (emitResource) emitResource(markup, entry);else {
946
+ registry.eagerHtml += markup;
947
+ entry.emitted = true;
948
+ }
949
+ return;
950
+ }
951
+ }
952
+ const url = props.href || props.src;
953
+ if (url != null && tracking.emittedAssets.has(url)) return;
954
+ const markup = renderHeadTagMarkup(desc.tag, props, null, nonce);
955
+ if (emitResource) emitResource(markup);else registry.eagerHtml += markup;
956
+ }
957
+ function commitHeadBoundary(registry, boundary, isPendingFragment) {
958
+ const keep = [];
959
+ const groups = [];
960
+ for (let i = 0; i < registry.pending.length; i++) {
961
+ const reg = registry.pending[i];
962
+ const mine = boundary === "" ? !(isPendingFragment && reg.boundary !== "" && isPendingFragment(reg.boundary)) : reg.boundary === boundary;
963
+ if (!mine) {
964
+ keep.push(reg);
965
+ continue;
966
+ }
967
+ let descs = reg.tags;
968
+ if (reg.list) {
969
+ let resolved;
970
+ try {
971
+ resolved = reg.list();
972
+ } catch (err) {
973
+ console.warn(`useHead: error evaluating head group membership`, err);
974
+ continue;
975
+ }
976
+ if (!Array.isArray(resolved)) resolved = [resolved];
977
+ descs = [];
978
+ for (let j = 0; j < resolved.length; j++) {
979
+ const desc = resolved[j];
980
+ if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
981
+ console.warn(`useHead: ignoring non-head tag`, desc);
982
+ continue;
983
+ }
984
+ const cls = classifyHeadTag(desc);
985
+ if (cls.resource) {
986
+ reg.resource(desc, cls.rel);
987
+ } else {
988
+ descs.push(cls.rel !== undefined ? {
989
+ tag: desc.tag,
990
+ props: desc.props,
991
+ key: desc.key,
992
+ rel: cls.rel
993
+ } : desc);
994
+ }
995
+ }
996
+ }
997
+ const tags = [];
998
+ for (let j = 0; j < descs.length; j++) {
999
+ const desc = descs[j];
1000
+ let props, key;
1001
+ try {
1002
+ props = evalHeadProps(desc.props || {}, desc.rel !== undefined ? {
1003
+ rel: desc.rel
1004
+ } : undefined);
1005
+ key = evalHeadValue(desc.key);
1006
+ } catch (err) {
1007
+ console.warn(`useHead: error evaluating tag props`, err);
1008
+ continue;
1009
+ }
1010
+ const identity = replaceableIdentity(desc.tag, props, key, "u:" + registry.uniq++);
1011
+ if ((identity === "base" || identity === "charset") && registry.shellFlushed) {
1012
+ console.warn(`useHead: <${desc.tag}> (${identity}) registered after shell flush is ignored`);
1013
+ continue;
1014
+ }
1015
+ tags.push({
1016
+ tag: desc.tag,
1017
+ props,
1018
+ identity
1019
+ });
1020
+ }
1021
+ if (tags.length) groups.push({
1022
+ seq: registry.seq++,
1023
+ tags
1024
+ });
1025
+ }
1026
+ registry.pending = keep;
1027
+ for (let i = 0; i < groups.length; i++) registry.committed.push(groups[i]);
1028
+ return groups;
1029
+ }
1030
+ function adoptHeadBoundary(registry, childKey, parentKey) {
1031
+ for (let i = 0; i < registry.pending.length; i++) {
1032
+ if (registry.pending[i].boundary === childKey) registry.pending[i].boundary = parentKey;
1033
+ }
1034
+ }
1035
+ function dropHeadBoundary(registry, boundary) {
1036
+ registry.pending = registry.pending.filter(reg => reg.boundary !== boundary);
1037
+ }
1038
+ function headGroupSignature(winner) {
1039
+ let sig = "" + winner.seq;
1040
+ for (let i = 0; i < winner.tags.length; i++) {
1041
+ const t = winner.tags[i];
1042
+ sig += "|" + t.tag + JSON.stringify(t.props);
1043
+ }
1044
+ return sig;
1045
+ }
1046
+ function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
1047
+ commitHeadBoundary(registry, "", isPendingFragment);
1048
+ registry.shellFlushed = true;
1049
+ const winners = resolveHead(registry.committed);
1050
+ registry.flushed = new Map();
1051
+ let prelude = "";
1052
+ let links = "";
1053
+ let metas = "";
1054
+ let others = "";
1055
+ let scripts = "";
1056
+ let title = null;
1057
+ for (const [identity, winner] of winners) {
1058
+ registry.flushed.set(identity, headGroupSignature(winner));
1059
+ if (identity === "title") {
1060
+ const children = winner.tags[0].props.children;
1061
+ title = children == null ? "" : String(children);
1062
+ continue;
1063
+ }
1064
+ for (let i = 0; i < winner.tags.length; i++) {
1065
+ const t = winner.tags[i];
1066
+ const markup = renderHeadTagMarkup(t.tag, t.props, identity, nonce);
1067
+ 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;
1068
+ }
1069
+ }
1070
+ return {
1071
+ prelude,
1072
+ html: registry.eagerHtml + links + metas + others + scripts,
1073
+ title,
1074
+ noScripts
1075
+ };
1076
+ }
1077
+ function flushHeadFragment(registry, boundary, nonce) {
1078
+ const groups = commitHeadBoundary(registry, boundary);
1079
+ if (!groups.length) return null;
1080
+ const winners = resolveHead(registry.committed);
1081
+ const affected = new Set();
1082
+ 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);
1083
+ const ops = [];
1084
+ for (const identity of affected) {
1085
+ const winner = winners.get(identity);
1086
+ const sig = headGroupSignature(winner);
1087
+ if (registry.flushed.get(identity) === sig) continue;
1088
+ const existed = registry.flushed.has(identity);
1089
+ registry.flushed.set(identity, sig);
1090
+ if (identity === "title") {
1091
+ const children = winner.tags[0].props.children;
1092
+ ops.push(["t", children == null ? "" : String(children)]);
1093
+ continue;
1094
+ }
1095
+ if (existed) ops.push(["r", identity]);
1096
+ for (let i = 0; i < winner.tags.length; i++) {
1097
+ const t = winner.tags[i];
1098
+ const attrs = {};
1099
+ for (const name in t.props) {
1100
+ if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
1101
+ if (!HEAD_ATTR_NAME.test(name)) {
1102
+ console.warn(`useHead: ignoring invalid attribute name "${name}"`);
1103
+ continue;
1104
+ }
1105
+ const v = t.props[name];
1106
+ if (v == null || v === false) continue;
1107
+ attrs[name] = v === true ? "" : String(v);
1108
+ }
1109
+ if (nonce && !hasNonceProp(t.props)) {
1110
+ const destination = nonceDestination(t.tag, t.props);
1111
+ const value = destination && nonce[destination];
1112
+ if (value) attrs.nonce = String(value);
1113
+ }
1114
+ const children = t.props.children;
1115
+ ops.push(["a", identity, t.tag, attrs, children == null ? null : String(children)]);
1116
+ }
1117
+ }
1118
+ return ops.length ? ops : null;
1119
+ }
1120
+ function normalizeNonce(nonce) {
1121
+ if (nonce == null) return undefined;
1122
+ if (typeof nonce === "string") {
1123
+ const attr = nonce ? ` nonce="${escape(nonce, true)}"` : "";
1124
+ return {
1125
+ script: nonce,
1126
+ style: nonce,
1127
+ scriptAttr: attr,
1128
+ styleAttr: attr
1129
+ };
1130
+ }
1131
+ const script = nonce.script;
1132
+ const style = nonce.style;
1133
+ if (!script && !style) return undefined;
1134
+ return {
1135
+ script,
1136
+ style,
1137
+ scriptAttr: typeof script === "string" && script ? ` nonce="${escape(script, true)}"` : "",
1138
+ styleAttr: typeof style === "string" && style ? ` nonce="${escape(style, true)}"` : ""
1139
+ };
1140
+ }
1141
+ function destinationNonce(nonce, destination) {
1142
+ if (nonce == null) return undefined;
1143
+ if (typeof nonce === "string") return nonce || undefined;
1144
+ const value = nonce[destination];
1145
+ return typeof value === "string" && value ? value : undefined;
1146
+ }
1147
+ function scriptNonce(nonce) {
1148
+ return destinationNonce(nonce, "script");
1149
+ }
1150
+ function styleNonce(nonce) {
1151
+ return destinationNonce(nonce, "style");
1152
+ }
1153
+ function hasNonceProp(props) {
1154
+ for (const name in props) if (name.length === 5 && asciiLowerCase(name) === "nonce" && props[name] != null) return true;
1155
+ return false;
1156
+ }
1157
+ function nonceDestination(tag, props) {
1158
+ if (tag === "script") return "script";
1159
+ if (tag === "style") return "style";
1160
+ if (tag !== "link") return null;
1161
+ const rel = props.rel;
1162
+ if (typeof rel !== "string") return null;
1163
+ const rels = asciiLowerCase(rel).split(/[\t\n\f\r ]+/);
1164
+ if (rels.includes("stylesheet")) return "style";
1165
+ const isModulePreload = rels.includes("modulepreload");
1166
+ if (!isModulePreload && !rels.includes("preload")) return null;
1167
+ const as = typeof props.as === "string" ? asciiLowerCase(props.as) : "";
1168
+ if (as === "style") return "style";
1169
+ if (as === "script") return "script";
1170
+ if (!isModulePreload) return null;
1171
+ switch (as) {
1172
+ case "fetch":
1173
+ case "font":
1174
+ case "image":
1175
+ case "json":
1176
+ case "text":
1177
+ case "track":
1178
+ return null;
1179
+ default:
1180
+ return "script";
1181
+ }
1182
+ }
1183
+ function nonceAttr(nonce, destination) {
1184
+ if (!nonce || !destination) return "";
1185
+ return destination === "script" ? nonce.scriptAttr : nonce.styleAttr;
1186
+ }
1187
+ function renderHeadAttrHtml(props) {
1188
+ let attrs = "";
1189
+ for (const name in props) {
1190
+ if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
1191
+ if (!HEAD_ATTR_NAME.test(name)) {
1192
+ console.warn(`useHead: ignoring invalid attribute name "${name}"`);
1193
+ continue;
1194
+ }
1195
+ const v = props[name];
1196
+ if (v == null || v === false) continue;
1197
+ attrs += v === true ? ` ${name}` : ` ${name}="${escape(String(v), true)}"`;
1198
+ }
1199
+ return attrs;
1200
+ }
1201
+ function headAttrRecord(props, skipRelHref) {
1202
+ let attrs = null;
1203
+ for (const name in props) {
1204
+ if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
1205
+ if ((name === "rel" || name === "href")) continue;
1206
+ if (!HEAD_ATTR_NAME.test(name)) continue;
1207
+ const v = props[name];
1208
+ if (v == null || v === false) continue;
1209
+ (attrs || (attrs = {}))[name] = v === true ? "" : String(v);
1210
+ }
1211
+ return attrs;
1212
+ }
1213
+ function renderHeadTagMarkup(tag, props, identity, nonce) {
1214
+ let attrs = renderHeadAttrHtml(props);
1215
+ if (identity != null) attrs += ` data-dh="${escape(identity, true)}"`;
1216
+ if (nonce && !hasNonceProp(props)) attrs += nonceAttr(nonce, nonceDestination(tag, props));
1217
+ if (tag === "meta" || tag === "link" || tag === "base") return `<${tag}${attrs}>`;
1218
+ let body = props.children == null ? "" : String(props.children);
1219
+ if (tag === "script") body = body.replace(/<\/(script)/gi, "<\\/$1");else if (tag === "style") body = escapeStyleContent(body);else body = escape(body);
1220
+ return `<${tag}${attrs}>${body}</${tag}>`;
1221
+ }
1222
+ function useHead(tags) {
1223
+ const ctx = sharedConfig.context;
1224
+ if (!ctx || !ctx.registerHeadTags) {
1225
+ console.warn("useHead() called outside of a server render; registration ignored.");
1226
+ return;
1227
+ }
1228
+ ctx.registerHeadTags(tags);
1229
+ }
1230
+ const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
1231
+ 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])}`;
1232
+ 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)}`;
1233
+ function renderToString(code, options = {}) {
1234
+ const {
1235
+ renderId = "",
1236
+ noScripts,
1237
+ manifest,
1238
+ onHead
1239
+ } = options;
1240
+ const nonce = normalizeNonce(options.nonce);
1241
+ let scripts = "";
1242
+ const serializer = createHydrationSerializer({
1243
+ scopeId: renderId,
1244
+ plugins: options.plugins,
1245
+ onData(script) {
1246
+ if (noScripts) return;
1247
+ if (!scripts) {
1248
+ scripts = getLocalHeaderScript(renderId);
1249
+ }
1250
+ scripts += script + ";";
1251
+ },
1252
+ onError: options.onError
1253
+ });
1254
+ const tracking = createAssetTracking();
1255
+ const headRegistry = createHeadRegistry();
1256
+ sharedConfig.context = {
1257
+ nonce: options.nonce,
1258
+ escape: escape,
1259
+ resolve: resolveSSRNode,
1260
+ ssr: ssr,
1261
+ registerHeadTags(tags) {
1262
+ registerHeadTags(headRegistry, sharedConfig.context, tracking, null, nonce, tags);
1263
+ },
1264
+ serialize(id, p) {
1265
+ if (sharedConfig.context.noHydrate) return;
1266
+ if (p != null && typeof p === "object" && (typeof p.then === "function" || typeof p[Symbol.asyncIterator] === "function")) {
1267
+ throw new Error("Cannot serialize async value in renderToString (id: " + id + "). " + "Use renderToStream for async data.");
1268
+ }
1269
+ serializer.write(id, p);
1270
+ },
1271
+ registerAsset(type, value) {
1272
+ if (type === "preload") {
1273
+ registerPreloadLink(tracking, headRegistry, value, nonce);
1274
+ return;
1275
+ }
1276
+ if (type === "inline-style") {
1277
+ tracking.registerInlineStyle(value);
1278
+ return;
1279
+ }
1280
+ if (tracking.currentBoundaryId && type === "style") {
1281
+ let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
1282
+ if (!styles) {
1283
+ styles = new Set();
1284
+ tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
1285
+ }
1286
+ styles.add(value);
1287
+ }
1288
+ tracking.emittedAssets.add(value);
1289
+ }
1290
+ };
1291
+ applyAssetTracking(sharedConfig.context, tracking, manifest, noScripts);
1292
+ registerEntryAssets(manifest);
1293
+ let html = createRoot(d => {
1294
+ setTimeout(d);
1295
+ return resolveSSRSync(escape(code()));
1296
+ }, {
1297
+ id: renderId
1298
+ });
1299
+ serializeFragmentAssets("", tracking.boundaryModules, sharedConfig.context, renderId);
1300
+ sharedConfig.context.noHydrate = true;
1301
+ serializer.close();
1302
+ const head = renderShellHead(headRegistry, nonce, null, noScripts);
1303
+ return assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead);
1304
+ }
1305
+ function renderToStream(code, options = {}) {
1306
+ let {
1307
+ onCompleteShell,
1308
+ onCompleteAll,
1309
+ renderId = "",
1310
+ noScripts,
1311
+ manifest,
1312
+ onHead
1313
+ } = options;
1314
+ const nonce = normalizeNonce(options.nonce);
1315
+ const requestEvent = peekRequestEvent();
1316
+ let dispose;
1317
+ let dead = false;
1318
+ const abandon = () => {
1319
+ if (dead) return;
1320
+ dead = true;
1321
+ completed = true;
1322
+ buffer = {
1323
+ write() {}
1324
+ };
1325
+ writable = {
1326
+ end() {}
1327
+ };
1328
+ if (dispose) {
1329
+ const d = dispose;
1330
+ dispose = () => {};
1331
+ d();
1332
+ }
1333
+ };
1334
+ const failRender = err => {
1335
+ try {
1336
+ options.onError ? options.onError(err) : console.error(err);
1337
+ } catch (_) {}
1338
+ abandon();
1339
+ };
1340
+ const coalesceWrites = (writeRaw, endRaw) => {
1341
+ let buf = "";
1342
+ let scheduled = false;
1343
+ const flush = () => {
1344
+ scheduled = false;
1345
+ if (!buf) return;
1346
+ const out = buf;
1347
+ buf = "";
1348
+ writeRaw(out);
1349
+ };
1350
+ return {
1351
+ write(payload) {
1352
+ buf += payload;
1353
+ if (buf.length >= 16384) return flush();
1354
+ if (!scheduled) {
1355
+ scheduled = true;
1356
+ deferFlush(flush);
1357
+ }
1358
+ },
1359
+ flush,
1360
+ end() {
1361
+ flush();
1362
+ endRaw();
1363
+ }
1364
+ };
1365
+ };
1366
+ const guardSink = w => ({
1367
+ write(payload) {
1368
+ if (dead) return;
1369
+ try {
1370
+ w.write(payload);
1371
+ } catch (_) {
1372
+ abandon();
1373
+ }
1374
+ },
1375
+ end() {
1376
+ if (dead) return;
1377
+ try {
1378
+ w.end();
1379
+ } catch (_) {
1380
+ abandon();
1381
+ }
1382
+ }
1383
+ });
1384
+ const blockingPromises = new Set();
1385
+ const canBatchStubs = !options.serializer && !options.sink;
1386
+ let stubBatch = null;
1387
+ const STUB_BATCH_KEY = "$B";
1388
+ const flushStubBatch = () => {
1389
+ if (!stubBatch) return;
1390
+ const batch = stubBatch;
1391
+ stubBatch = null;
1392
+ if (batch.size === 1) {
1393
+ const [id, p] = batch.entries().next().value;
1394
+ serializer.write(id, p);
1395
+ return;
1396
+ }
1397
+ const obj = {};
1398
+ for (const [id, p] of batch) obj[id] = p;
1399
+ serializer.write(STUB_BATCH_KEY, obj);
1400
+ pushTask(`(b=>{for(var k in b)_$HY.r[k]=b[k];delete _$HY.r["${STUB_BATCH_KEY}"]})(_$HY.r["${STUB_BATCH_KEY}"])`);
1401
+ };
1402
+ let headerEmitted = false;
1403
+ const pushTask = task => {
1404
+ if (noScripts) return;
1405
+ if (!headerEmitted) {
1406
+ headerEmitted = true;
1407
+ tasks += getLocalHeaderScript(renderId);
1408
+ }
1409
+ tasks += task + ";";
1410
+ if (!timer && firstFlushed) {
1411
+ timer = true;
1412
+ queue(() => queue(writeTasks));
1413
+ }
1414
+ };
1415
+ const onDone = () => {
1416
+ writeTasks();
1417
+ lastBlockingSize = blockingPromises.size;
1418
+ doShell();
1419
+ onCompleteAll && onCompleteAll({
1420
+ write(v) {
1421
+ !completed && buffer.write(v);
1422
+ }
1423
+ });
1424
+ writable && writable.end();
1425
+ completed = true;
1426
+ if (firstFlushed) dispose();
1427
+ };
1428
+ const sink = {
1429
+ data(payload) {
1430
+ pushTask(payload);
1431
+ },
1432
+ fragment(key, value, meta) {
1433
+ const deferActivation = !!meta.revealGroup;
1434
+ const styles = meta.styles;
1435
+ for (let i = 0; i < styles.inline.length; i++) {
1436
+ buffer.write(renderInlineStyle(styles.inline[i], nonce));
1437
+ }
1438
+ if (styles.links.length) {
1439
+ const styleAttr = nonceAttr(nonce, "style");
1440
+ emitTask(`$dfs("${key}",${styles.links.length},${deferActivation ? 1 : 0})`);
1441
+ writeTasks();
1442
+ for (const entry of styles.links) {
1443
+ 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}')">`);
1444
+ }
1445
+ buffer.write(`<template id="${key}">${value}</template>`);
1446
+ } else {
1447
+ buffer.write(`<template id="${key}">${value}</template>`);
1448
+ if (!deferActivation) {
1449
+ emitTask(`$df("${key}")`);
1450
+ }
1451
+ }
1452
+ },
1453
+ reveal(keys, meta) {
1454
+ emitTask(`${meta.fallback ? "$dflj" : "$dfj"}(${JSON.stringify(keys)})`);
1455
+ },
1456
+ asset(type, value) {
1457
+ if (type === "module") {
1458
+ buffer.write(`<link rel="modulepreload" href="${value}"${nonceAttr(nonce, "script")}>`);
1459
+ } else if (type === "preload") {
1460
+ buffer.write(`<link${value.attrHtml}>`);
1461
+ } else if (type === "inline-style") {
1462
+ buffer.write(renderInlineStyle(value, nonce));
1463
+ } else if (type === "head-tag") {
1464
+ buffer.write(value);
1465
+ }
1466
+ },
1467
+ shell(shellHtml, meta) {
1468
+ buffer.write(assembleDocument(shellHtml, meta.preloads, meta.preloadLinks, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead));
1469
+ },
1470
+ ...options.sink
1471
+ };
1472
+ const serializer = (options.serializer || createHydrationSerializer)({
1473
+ scopeId: options.renderId,
1474
+ plugins: options.plugins,
1475
+ onData: payload => sink.data(payload),
1476
+ onDone,
1477
+ onError: options.onError
1478
+ });
1479
+ let rootAssetsSerialized = false;
1480
+ const serializeRootAssets = () => {
1481
+ if (rootAssetsSerialized) return;
1482
+ rootAssetsSerialized = true;
1483
+ serializeFragmentAssets("", tracking.boundaryModules, context, renderId);
1484
+ };
1485
+ let holds = 0;
1486
+ const flushEnd = () => {
1487
+ if (!registry.size && !holds) {
1488
+ serializeRootAssets();
1489
+ queue(() => queue(() => {
1490
+ if (context.live.end) {
1491
+ const end = context.live.end;
1492
+ context.live.end = null;
1493
+ end();
1494
+ }
1495
+ flushStubBatch();
1496
+ serializer.flush();
1497
+ }));
1498
+ }
1499
+ };
1500
+ const registry = new Map();
1501
+ const pendingSerialized = new Map();
1502
+ const trackSerialized = (id, p) => {
1503
+ let settle;
1504
+ const raced = Promise.race([p, new Promise(r => settle = r)]);
1505
+ pendingSerialized.set(id, settle);
1506
+ const drop = () => pendingSerialized.delete(id);
1507
+ p.then(drop, drop);
1508
+ return raced;
1509
+ };
1510
+ const abandonSubtree = key => {
1511
+ for (const [k, entry] of registry) {
1512
+ if (k.length > key.length && k.startsWith(key)) {
1513
+ registry.delete(k);
1514
+ entry.resolve();
1515
+ }
1516
+ }
1517
+ for (const [id, settle] of pendingSerialized) {
1518
+ if (id.startsWith(key)) {
1519
+ pendingSerialized.delete(id);
1520
+ settle();
1521
+ }
1522
+ }
1523
+ };
1524
+ const writeTasks = () => {
1525
+ if (tasks.length && !completed && firstFlushed) {
1526
+ buffer.write(`<script${nonceAttr(nonce, "script")}>${tasks}</script>`);
1527
+ tasks = "";
1528
+ }
1529
+ timer = null;
1530
+ };
1531
+ let context;
1532
+ let writable;
1533
+ let tmp = "";
1534
+ let tasks = "";
1535
+ let firstFlushed = false;
1536
+ let completed = false;
1537
+ let shellCompleted = false;
1538
+ let scriptFlushed = false;
1539
+ let headStyles;
1540
+ const revealGroups = new Map();
1541
+ let timer = null;
1542
+ const emitTask = task => {
1543
+ pushTask(`${task}${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
1544
+ scriptFlushed = true;
1545
+ };
1546
+ function resolveRevealKeys(groupOrKeys, release, consume) {
1547
+ if (Array.isArray(groupOrKeys)) return groupOrKeys.slice();
1548
+ let group = revealGroups.get(groupOrKeys);
1549
+ if (!group) {
1550
+ if (!release) return;
1551
+ group = {
1552
+ order: [],
1553
+ keys: new Set(),
1554
+ released: true
1555
+ };
1556
+ revealGroups.set(groupOrKeys, group);
1557
+ } else if (release) group.released = true;
1558
+ if (!group.order.length) return;
1559
+ const keys = group.order.slice();
1560
+ if (consume) revealGroups.delete(groupOrKeys);
1561
+ return keys;
1562
+ }
1563
+ let rootHoles = null;
1564
+ let nextHoleId = 0;
1565
+ let buffer = {
1566
+ write(payload) {
1567
+ tmp += payload;
1568
+ }
1569
+ };
1570
+ const tracking = createAssetTracking();
1571
+ const headRegistry = createHeadRegistry();
1572
+ let headScriptFlushed = false;
1573
+ const emitHeadOps = (key, ops) => {
1574
+ const payload = JSON.stringify(ops).replace(/</g, "\\u003C");
1575
+ emitTask(`${!headScriptFlushed ? HEAD_SCRIPT : ""}(_$HY.hp=_$HY.hp||{})[${JSON.stringify(key)}]=${payload}`);
1576
+ headScriptFlushed = true;
1577
+ };
1578
+ sharedConfig.context = context = {
1579
+ async: true,
1580
+ nonce: options.nonce,
1581
+ live: {},
1582
+ registerHeadTags(tags) {
1583
+ registerHeadTags(headRegistry, context, tracking,
1584
+ (markup, gateEntry) => {
1585
+ if (!firstFlushed) {
1586
+ headRegistry.eagerHtml += markup;
1587
+ if (gateEntry) gateEntry.emitted = true;
1588
+ } else if (!gateEntry || !tracking.currentBoundaryId) {
1589
+ sink.asset("head-tag", markup);
1590
+ }
1591
+ }, nonce, tags);
1592
+ },
1593
+ registerAsset(type, value) {
1594
+ if (type === "preload") {
1595
+ const entry = registerPreloadLink(tracking, headRegistry, value, nonce);
1596
+ if (entry && firstFlushed) sink.asset("preload", entry);
1597
+ return;
1598
+ }
1599
+ if (type === "inline-style") {
1600
+ const entry = tracking.registerInlineStyle(value);
1601
+ if (firstFlushed && !tracking.currentBoundaryId && !entry.emitted) {
1602
+ entry.emitted = true;
1603
+ sink.asset("inline-style", entry);
1604
+ }
1605
+ return;
1606
+ }
1607
+ if (tracking.currentBoundaryId && type === "style") {
1608
+ let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
1609
+ if (!styles) {
1610
+ styles = new Set();
1611
+ tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
1612
+ }
1613
+ styles.add(value);
1614
+ }
1615
+ if (!tracking.emittedAssets.has(value)) {
1616
+ tracking.emittedAssets.add(value);
1617
+ if (firstFlushed) sink.asset(type, value);
1618
+ }
1619
+ },
1620
+ block(p) {
1621
+ if (!firstFlushed) blockingPromises.add(p);
1622
+ },
1623
+ hold() {
1624
+ holds++;
1625
+ let released = false;
1626
+ return () => {
1627
+ if (released) return;
1628
+ released = true;
1629
+ holds--;
1630
+ if (!holds) queue(flushEnd);
1631
+ };
1632
+ },
1633
+ replace(id, payloadFn) {
1634
+ if (firstFlushed) return;
1635
+ const placeholder = `<!--!$${id}-->`;
1636
+ const first = html.indexOf(placeholder);
1637
+ if (first === -1) return;
1638
+ const last = html.indexOf(`<!--!$/${id}-->`, first + placeholder.length);
1639
+ html = html.slice(0, first) + resolveSSRSync(escape(payloadFn())) + html.slice(last + placeholder.length + 1);
1640
+ },
1641
+ serialize(id, p, deferStream) {
1642
+ if (sharedConfig.context.noHydrate) return;
1643
+ if (p && typeof p === "object" && typeof p.then === "function") {
1644
+ if (!firstFlushed && deferStream) {
1645
+ blockingPromises.add(p);
1646
+ p.then(d => serializer.write(id, d)).catch(e => serializer.write(id, e));
1647
+ return;
1648
+ }
1649
+ p = trackSerialized(id, p);
1650
+ if (!firstFlushed && canBatchStubs && !shellCompleted) {
1651
+ (stubBatch ||= new Map()).set(id, p);
1652
+ return;
1653
+ }
1654
+ }
1655
+ serializer.write(id, p);
1656
+ },
1657
+ escape: escape,
1658
+ resolve: resolveSSRNode,
1659
+ ssr: ssr,
1660
+ registerFragment(key, options) {
1661
+ const revealGroup = options && options.revealGroup;
1662
+ if (revealGroup) {
1663
+ let group = revealGroups.get(revealGroup);
1664
+ if (!group) {
1665
+ group = {
1666
+ order: [],
1667
+ keys: new Set(),
1668
+ released: false
1669
+ };
1670
+ revealGroups.set(revealGroup, group);
1671
+ }
1672
+ if (!group.keys.has(key)) {
1673
+ group.keys.add(key);
1674
+ group.order.push(key);
1675
+ }
1676
+ if (group.released) {
1677
+ throw new Error("registerFragment() for reveal group '" + revealGroup + "' was called after revealFragments(). Ensure template payload is emitted before grouped reveal.");
1678
+ }
1679
+ }
1680
+ if (!registry.has(key)) {
1681
+ let resolve, reject;
1682
+ const p = new Promise((r, rej) => (resolve = r, reject = rej));
1683
+ registry.set(key, {
1684
+ resolve: err => queue(() => queue(() => {
1685
+ err ? reject(err) : resolve(true);
1686
+ queue(flushEnd);
1687
+ }))
1688
+ });
1689
+ if (canBatchStubs && !shellCompleted) (stubBatch ||= new Map()).set(key + "_fr", p);else serializer.write(key + "_fr", p);
1690
+ }
1691
+ return (value, error) => {
1692
+ if (registry.has(key)) {
1693
+ const item = registry.get(key);
1694
+ registry.delete(key);
1695
+ if (error) abandonSubtree(key);
1696
+ if (item.children) {
1697
+ for (const k in item.children) {
1698
+ value = replacePlaceholder(value, k, item.children[k]);
1699
+ }
1700
+ }
1701
+ const parentKey = waitForFragments(registry, key);
1702
+ if (parentKey) {
1703
+ const parent = registry.get(parentKey);
1704
+ parent.children ||= {};
1705
+ parent.children[key] = value !== undefined ? value : "";
1706
+ serializeFragmentAssets(key, tracking.boundaryModules, context);
1707
+ propagateBoundaryStyles(key, parentKey, tracking);
1708
+ adoptHeadBoundary(headRegistry, key, parentKey);
1709
+ item.resolve();
1710
+ return;
1711
+ }
1712
+ if (!completed) {
1713
+ if (error) dropHeadBoundary(headRegistry, key);
1714
+ if (!firstFlushed) {
1715
+ queue(() => html = replacePlaceholder(html, key, value !== undefined ? value : ""));
1716
+ serializeFragmentAssets(key, tracking.boundaryModules, context);
1717
+ item.resolve(error);
1718
+ } else {
1719
+ serializeFragmentAssets(key, tracking.boundaryModules, context);
1720
+ const styles = collectStreamStyles(key, tracking, headStyles);
1721
+ const headOps = error ? null : flushHeadFragment(headRegistry, key, nonce);
1722
+ if (headOps) emitHeadOps(key, headOps);
1723
+ sink.fragment(key, resolveSSRSelectValues(value !== undefined ? value : " "), {
1724
+ styles,
1725
+ revealGroup,
1726
+ error
1727
+ });
1728
+ item.resolve(error);
1729
+ }
1730
+ }
1731
+ }
1732
+ return firstFlushed;
1733
+ };
1734
+ },
1735
+ revealFragments(groupOrKeys) {
1736
+ const keys = resolveRevealKeys(groupOrKeys, true, true);
1737
+ if (!keys) return;
1738
+ sink.reveal(keys, {
1739
+ fallback: false
1740
+ });
1741
+ },
1742
+ revealFallbacks(groupOrKeys) {
1743
+ const keys = resolveRevealKeys(groupOrKeys, false, false);
1744
+ if (!keys) return;
1745
+ sink.reveal(keys, {
1746
+ fallback: true
1747
+ });
1748
+ }
1749
+ };
1750
+ applyAssetTracking(context, tracking, manifest, noScripts);
1751
+ context.failRender = failRender;
1752
+ registerEntryAssets(manifest);
1753
+ let html = createRoot(d => {
1754
+ dispose = d;
1755
+ const res = resolveSSRNode(escape(code()));
1756
+ if (!res.h.length) return res.t[0];
1757
+ rootHoles = [];
1758
+ let out = res.t[0];
1759
+ for (let i = 0; i < res.h.length; i++) {
1760
+ const id = nextHoleId++;
1761
+ rootHoles.push({
1762
+ id,
1763
+ fn: res.h[i]
1764
+ });
1765
+ out += `<!--rh${id}-->` + res.t[i + 1];
1766
+ }
1767
+ for (const p of res.p) blockingPromises.add(p);
1768
+ return out;
1769
+ }, {
1770
+ id: renderId
1771
+ });
1772
+ function resolveRootHoles() {
1773
+ if (!rootHoles) return true;
1774
+ const pending = [];
1775
+ for (const {
1776
+ id,
1777
+ fn
1778
+ } of rootHoles) {
1779
+ const marker = `<!--rh${id}-->`;
1780
+ const res = resolveSSRNode(fn);
1781
+ if (!res.h.length) {
1782
+ html = html.replace(marker, res.t[0]);
1783
+ } else {
1784
+ let out = res.t[0];
1785
+ for (let j = 0; j < res.h.length; j++) {
1786
+ const newId = nextHoleId++;
1787
+ pending.push({
1788
+ id: newId,
1789
+ fn: res.h[j]
1790
+ });
1791
+ out += `<!--rh${newId}-->` + res.t[j + 1];
1792
+ }
1793
+ html = html.replace(marker, out);
1794
+ for (const p of res.p) blockingPromises.add(p);
1795
+ }
1796
+ }
1797
+ if (pending.length) {
1798
+ rootHoles = pending;
1799
+ return false;
1800
+ }
1801
+ rootHoles = null;
1802
+ return true;
1803
+ }
1804
+ function doShell() {
1805
+ if (shellCompleted) return;
1806
+ sharedConfig.context = context;
1807
+ if (blockingPromises.size !== lastBlockingSize) return;
1808
+ if (!resolveRootHoles()) return;
1809
+ if (blockingPromises.size !== lastBlockingSize) return;
1810
+ if (!headShellReady(headRegistry, p => blockingPromises.add(p))) return;
1811
+ headStyles = new Set();
1812
+ for (const url of tracking.emittedAssets) {
1813
+ if (isCssUrl(url)) headStyles.add(url);
1814
+ }
1815
+ serializeRootAssets();
1816
+ flushStubBatch();
1817
+ const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts);
1818
+ sink.shell(resolveSSRSelectValues(html), {
1819
+ preloads: tracking.emittedAssets,
1820
+ preloadLinks: tracking.preloadLinks,
1821
+ inlineStyles: tracking.inlineStyles,
1822
+ tasks,
1823
+ head
1824
+ });
1825
+ tasks = "";
1826
+ onCompleteShell && onCompleteShell({
1827
+ write(v) {
1828
+ !completed && buffer.write(v);
1829
+ }
1830
+ });
1831
+ shellCompleted = true;
1832
+ }
1833
+ const MIN_DRAIN_TURNS = 8;
1834
+ let lastBlockingSize = -1;
1835
+ let lastRegistrySize = -1;
1836
+ let drainTurn = 0;
1837
+ const scheduleFlush = (fn, awaited) => {
1838
+ const attempt = () => {
1839
+ flushStubBatch();
1840
+ if (registry.size !== lastRegistrySize || drainTurn++ < MIN_DRAIN_TURNS) {
1841
+ if (registry.size !== lastRegistrySize) drainTurn = 0;
1842
+ lastRegistrySize = registry.size;
1843
+ queue(attempt);
1844
+ return;
1845
+ }
1846
+ fn();
1847
+ };
1848
+ const progressed = awaited !== lastBlockingSize;
1849
+ lastBlockingSize = awaited;
1850
+ lastRegistrySize = -1;
1851
+ drainTurn = 0;
1852
+ progressed ? queue(attempt) : setTimeout(attempt);
1853
+ };
1854
+ let cachedReadable;
1855
+ let consumer;
1856
+ const claimConsumer = name => {
1857
+ if (consumer && consumer !== name) {
1858
+ throw new Error(`renderToStream result was already consumed via \`${consumer}\`; cannot also consume it via \`${name}\`. Use exactly one of \`pipe\`, \`pipeTo\`, or \`readable\`.`);
1859
+ }
1860
+ consumer = name;
1861
+ };
1862
+ const pipeToImpl = w => {
1863
+ let resolve;
1864
+ const p = new Promise(r => resolve = r);
1865
+ function flush() {
1866
+ allSettled(blockingPromises).then(awaited => {
1867
+ scheduleFlush(() => {
1868
+ if (dead) return resolve();
1869
+ try {
1870
+ doShell();
1871
+ } catch (err) {
1872
+ failRender(err);
1873
+ return resolve();
1874
+ }
1875
+ if (!shellCompleted) return flush();
1876
+ const encoder = new TextEncoder();
1877
+ const writer = w.getWriter();
1878
+ let pendingWrites = Promise.resolve();
1879
+ let ended = false;
1880
+ const failed = () => {
1881
+ if (!ended) {
1882
+ abandon();
1883
+ resolve();
1884
+ }
1885
+ };
1886
+ writer.closed && writer.closed.catch(failed);
1887
+ buffer = writable = coalesceWrites(payload => {
1888
+ pendingWrites = pendingWrites.then(() => writer.write(encoder.encode(payload))).catch(failed);
1889
+ }, () => {
1890
+ pendingWrites.then(() => {
1891
+ ended = true;
1892
+ writer.releaseLock();
1893
+ w.close().catch(() => {});
1894
+ resolve();
1895
+ });
1896
+ });
1897
+ buffer.write(tmp);
1898
+ buffer.flush();
1899
+ firstFlushed = true;
1900
+ if (completed) {
1901
+ dispose();
1902
+ writable.end();
1903
+ } else flushEnd();
1904
+ }, awaited);
1905
+ });
1906
+ }
1907
+ flush();
1908
+ return p;
1909
+ };
1910
+ return {
1911
+ then(onFulfilled, onRejected) {
1912
+ const freezeHead = () => {
1913
+ if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response);
1914
+ };
1915
+ const p = new Promise(resolve => {
1916
+ function complete() {
1917
+ freezeHead();
1918
+ dispose();
1919
+ resolve(tmp);
1920
+ }
1921
+ if (onCompleteAll) {
1922
+ let ogComplete = onCompleteAll;
1923
+ onCompleteAll = options => {
1924
+ ogComplete(options);
1925
+ complete();
1926
+ };
1927
+ } else onCompleteAll = complete;
1928
+ function flush() {
1929
+ allSettled(blockingPromises).then(awaited => {
1930
+ scheduleFlush(() => {
1931
+ try {
1932
+ if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
1933
+ } catch (err) {
1934
+ failRender(err);
1935
+ return resolve(tmp);
1936
+ }
1937
+ queue(flushEnd);
1938
+ }, awaited);
1939
+ });
1940
+ }
1941
+ flush();
1942
+ });
1943
+ return p.then(onFulfilled, onRejected);
1944
+ },
1945
+ pipe(w) {
1946
+ claimConsumer("pipe");
1947
+ function flush() {
1948
+ allSettled(blockingPromises).then(awaited => {
1949
+ scheduleFlush(() => {
1950
+ if (dead) return;
1951
+ try {
1952
+ doShell();
1953
+ } catch (err) {
1954
+ failRender(err);
1955
+ try {
1956
+ w.end();
1957
+ } catch (_) {}
1958
+ return;
1959
+ }
1960
+ if (!shellCompleted) return flush();
1961
+ const sink = guardSink(w);
1962
+ buffer = writable = coalesceWrites(sink.write, sink.end);
1963
+ buffer.write(tmp);
1964
+ buffer.flush();
1965
+ firstFlushed = true;
1966
+ if (completed) {
1967
+ dispose();
1968
+ writable.end();
1969
+ } else flushEnd();
1970
+ }, awaited);
1971
+ });
1972
+ }
1973
+ flush();
1974
+ },
1975
+ pipeTo(w) {
1976
+ claimConsumer("pipeTo");
1977
+ return pipeToImpl(w);
1978
+ },
1979
+ get readable() {
1980
+ claimConsumer("readable");
1981
+ if (!cachedReadable) {
1982
+ const t = new TransformStream();
1983
+ pipeToImpl(t.writable);
1984
+ cachedReadable = t.readable;
1985
+ }
1986
+ return cachedReadable;
1987
+ }
1988
+ };
1989
+ }
1990
+ function HydrationScript(props) {
1991
+ const nonce = scriptNonce(sharedConfig.context && sharedConfig.context.nonce);
1992
+ return ssr(generateHydrationScript({
1993
+ nonce,
1994
+ ...props
1995
+ }));
1996
+ }
1997
+ function ssrGroup(fn, n) {
1998
+ fn.$g = n;
1999
+ return fn;
2000
+ }
2001
+ function buildAsyncWrap(err, node) {
2002
+ const p = ssrHandleError(err);
2003
+ if (!p) return null;
2004
+ if (node.$rw) return {
2005
+ fn: node,
2006
+ p
2007
+ };
2008
+ const owner = getOwner();
2009
+ const live = sharedConfig.context && sharedConfig.context.liveHoles;
2010
+ const suppress = node.$lhSuppress || live && (live.suppressed || live.sweeping);
2011
+ if (!owner) {
2012
+ if (suppress) node.$lhSuppress = true;
2013
+ return {
2014
+ fn: node,
2015
+ p
2016
+ };
2017
+ }
2018
+ const fn = () => runWithOwner(owner, node);
2019
+ fn.$rw = true;
2020
+ if (suppress) fn.$lhSuppress = true;
2021
+ if (node.$lhSkip) fn.$lhSkip = true;
2022
+ if (node.$lhBinding) fn.$lhBinding = node.$lhBinding;
2023
+ return {
2024
+ fn,
2025
+ p
2026
+ };
2027
+ }
2028
+ function ssrFirstGroupHit(hole) {
2029
+ try {
2030
+ return hole();
2031
+ } catch (err) {
2032
+ return buildAsyncWrap(err, hole);
2033
+ }
2034
+ }
2035
+ function tryResolveFunctionHole(hole) {
2036
+ let value;
2037
+ try {
2038
+ value = hole();
2039
+ } catch (err) {
2040
+ return buildAsyncWrap(err, hole) || "";
2041
+ }
2042
+ const t = typeof value;
2043
+ if (t === "string") return value;
2044
+ if (t === "number") return "" + value;
2045
+ if (value == null || t === "boolean") return "";
2046
+ return tryResolveString(value);
2047
+ }
2048
+ function mergeTemplateInto(result, node) {
2049
+ result.t[result.t.length - 1] += node.t[0];
2050
+ if (node.t.length > 1) {
2051
+ result.t.push(...node.t.slice(1));
2052
+ result.h.push(...node.h);
2053
+ result.p.push(...node.p);
2054
+ }
2055
+ }
2056
+ function appendResolvedNode(result, node) {
2057
+ if (node.fn !== undefined) {
2058
+ result.h.push(node.fn);
2059
+ result.p.push(node.p);
2060
+ result.t.push("");
2061
+ } else if (node.merge !== undefined) mergeTemplateInto(result, node.merge);else resolveSSRNode(node.bail, result);
2062
+ }
2063
+ let _lastGroupFn = null;
2064
+ let _lastGroupArr = null;
2065
+ let _lastGroupErr = null;
2066
+ function ssrGroupSlot(fn, idx) {
2067
+ return () => {
2068
+ if (idx > 0 && _lastGroupFn === fn) {
2069
+ if (_lastGroupArr !== null) return _lastGroupArr[idx];
2070
+ throw _lastGroupErr;
2071
+ }
2072
+ _lastGroupFn = fn;
2073
+ _lastGroupArr = null;
2074
+ _lastGroupErr = null;
2075
+ try {
2076
+ _lastGroupArr = fn();
2077
+ return _lastGroupArr[idx];
2078
+ } catch (err) {
2079
+ _lastGroupErr = err;
2080
+ throw err;
2081
+ }
2082
+ };
2083
+ }
2084
+ const holePositionCache = new WeakMap();
2085
+ function holeContentPositions(t) {
2086
+ let cached = holePositionCache.get(t);
2087
+ if (cached) return cached;
2088
+ const pos = [];
2089
+ const openOff = [];
2090
+ const closeOff = [];
2091
+ let inTag = false;
2092
+ let quote = "";
2093
+ let curOpen = null;
2094
+ let scanningName = false;
2095
+ for (let i = 0; i < t.length; i++) {
2096
+ const seg = t[i];
2097
+ let close = -1;
2098
+ const openAtStart = inTag;
2099
+ let reopened = false;
2100
+ for (let j = 0; j < seg.length; j++) {
2101
+ const ch = seg[j];
2102
+ if (quote) {
2103
+ if (ch === quote) quote = "";
2104
+ } else if (inTag) {
2105
+ if (scanningName && (ch === " " || ch === "\t" || ch === "\n" || ch === ">" || ch === "/")) {
2106
+ scanningName = false;
2107
+ curOpen = {
2108
+ seg: i,
2109
+ off: j
2110
+ };
2111
+ }
2112
+ if (ch === '"' || ch === "'") quote = ch;else if (ch === ">") {
2113
+ inTag = false;
2114
+ if (openAtStart && !reopened && close === -1) close = j;
2115
+ curOpen = null;
2116
+ }
2117
+ } else if (ch === "<") {
2118
+ inTag = true;
2119
+ scanningName = true;
2120
+ reopened = true;
2121
+ curOpen = null;
2122
+ }
2123
+ }
2124
+ if (inTag && scanningName) {
2125
+ scanningName = false;
2126
+ curOpen = {
2127
+ seg: i,
2128
+ off: seg.length
2129
+ };
2130
+ }
2131
+ closeOff.push(close);
2132
+ openOff.push(inTag && curOpen && curOpen.seg === i ? curOpen.off : -1);
2133
+ if (i < t.length - 1) pos.push(!inTag);
2134
+ }
2135
+ cached = {
2136
+ pos,
2137
+ openOff,
2138
+ closeOff
2139
+ };
2140
+ holePositionCache.set(t, cached);
2141
+ return cached;
2142
+ }
2143
+ function createLiveHoles(sink, scoped) {
2144
+ let nextId = 0;
2145
+ const stamp = typeof creationStamp === "function" ? creationStamp : () => 0;
2146
+ const inScope = scoped && typeof inServerComponentScope === "function" ? inServerComponentScope : null;
2147
+ const stripMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
2148
+ const swept = (owner, ctx, fn) => {
2149
+ const prev = sharedConfig.context;
2150
+ sharedConfig.context = ctx;
2151
+ try {
2152
+ return owner ? runWithOwner(owner, fn) : fn();
2153
+ } finally {
2154
+ sharedConfig.context = prev;
2155
+ }
2156
+ };
2157
+ function resolveHoleValue(hole) {
2158
+ const result = {
2159
+ t: [""],
2160
+ h: [],
2161
+ p: []
2162
+ };
2163
+ try {
2164
+ resolveSSRNode(hole(), result);
2165
+ } catch (err) {
2166
+ const wrap = buildAsyncWrap(err, hole);
2167
+ if (!wrap) throw err;
2168
+ result.h.push(wrap.fn);
2169
+ result.p.push(wrap.p);
2170
+ result.t.push("");
2171
+ }
2172
+ return result;
2173
+ }
2174
+ function closeChildren(b) {
2175
+ for (const c of b.children) {
2176
+ c.closed = true;
2177
+ if (c.key) sink.closeBinding(c.key);
2178
+ closeChildren(c);
2179
+ }
2180
+ b.children.length = 0;
2181
+ }
2182
+ const engine = {
2183
+ suppressed: 0,
2184
+ sweeping: false,
2185
+ parent: null,
2186
+ recordStamp: 0,
2187
+ gateHit: false,
2188
+ content(hole) {
2189
+ if (hole.$lhSuppress) {
2190
+ const r = {
2191
+ t: [""],
2192
+ h: [],
2193
+ p: []
2194
+ };
2195
+ engine.suppressed++;
2196
+ try {
2197
+ try {
2198
+ resolveSSRNode(hole(), r);
2199
+ } catch (err) {
2200
+ const wrap = buildAsyncWrap(err, hole);
2201
+ if (wrap) {
2202
+ r.h.push(wrap.fn);
2203
+ r.p.push(wrap.p);
2204
+ r.t.push("");
2205
+ }
2206
+ }
2207
+ } finally {
2208
+ engine.suppressed--;
2209
+ }
2210
+ const b = hole.$lhBinding;
2211
+ if (b && !b.closed && !r.h.length && !engine.sweeping) {
2212
+ b.last = stripMarkers(r.t[0]);
2213
+ }
2214
+ return r.h.length ? r : r.t[0];
2215
+ }
2216
+ if (engine.suppressed || engine.sweeping) return null;
2217
+ if (hole.$lhSkip) return null;
2218
+ if (inScope && !inScope()) return null;
2219
+ const recordsBefore = engine.recordStamp;
2220
+ const ownersBefore = stamp();
2221
+ const owner = getOwner();
2222
+ const holeCtx = sharedConfig.context;
2223
+ const b = {
2224
+ key: null,
2225
+ children: [],
2226
+ last: null,
2227
+ closed: false,
2228
+ sweep() {
2229
+ if (b.closed) return;
2230
+ const prevSweeping = engine.sweeping;
2231
+ engine.sweeping = true;
2232
+ engine.gateHit = false;
2233
+ const sweepOwnersBefore = stamp();
2234
+ let res;
2235
+ try {
2236
+ res = swept(owner, holeCtx, () => resolveHoleValue(hole));
2237
+ } catch (err) {
2238
+ b.closed = true;
2239
+ sink.closeBinding(b.key);
2240
+ sink.error(b.key, String(err && err.message || err));
2241
+ return;
2242
+ } finally {
2243
+ engine.sweeping = prevSweeping;
2244
+ }
2245
+ if (engine.gateHit || stamp() !== sweepOwnersBefore) {
2246
+ b.closed = true;
2247
+ sink.closeBinding(b.key);
2248
+ return;
2249
+ }
2250
+ if (res.h.length) return;
2251
+ const html = res.t[0];
2252
+ if (b.last === null || html === b.last) return;
2253
+ b.last = html;
2254
+ closeChildren(b);
2255
+ sink.hole(b.key, html);
2256
+ }
2257
+ };
2258
+ if (engine.parent) engine.parent.children.push(b);
2259
+ const prevParent = engine.parent;
2260
+ engine.parent = b;
2261
+ let value;
2262
+ let escalated = null;
2263
+ try {
2264
+ value = hole();
2265
+ } catch (err) {
2266
+ const wrap = buildAsyncWrap(err, hole);
2267
+ if (!wrap) {
2268
+ engine.parent = prevParent;
2269
+ closeChildren(b);
2270
+ return "";
2271
+ }
2272
+ escalated = wrap;
2273
+ }
2274
+ if (!escalated && (typeof value === "function" && value.$lhSkip || value !== null && typeof value === "object" && value.$slot)) {
2275
+ engine.parent = prevParent;
2276
+ const r = {
2277
+ t: [""],
2278
+ h: [],
2279
+ p: []
2280
+ };
2281
+ engine.suppressed++;
2282
+ try {
2283
+ resolveSSRNode(value, r);
2284
+ } finally {
2285
+ engine.suppressed--;
2286
+ }
2287
+ return r.h.length ? r : r.t[0];
2288
+ }
2289
+ let res;
2290
+ if (escalated) {
2291
+ closeChildren(b);
2292
+ escalated.fn.$lhSuppress = true;
2293
+ escalated.fn.$lhBinding = b;
2294
+ res = {
2295
+ t: ["", ""],
2296
+ h: [escalated.fn],
2297
+ p: [escalated.p]
2298
+ };
2299
+ } else {
2300
+ res = {
2301
+ t: [""],
2302
+ h: [],
2303
+ p: []
2304
+ };
2305
+ try {
2306
+ resolveSSRNode(value, res);
2307
+ } catch (_) {
2308
+ engine.parent = prevParent;
2309
+ closeChildren(b);
2310
+ return "";
2311
+ }
2312
+ }
2313
+ engine.parent = prevParent;
2314
+ if (engine.recordStamp !== recordsBefore || stamp() !== ownersBefore) {
2315
+ return res.h.length ? res : res.t[0];
2316
+ }
2317
+ const id = nextId++;
2318
+ const key = b.key = "lh:" + id;
2319
+ const open = `<!--lh:${id}-->`;
2320
+ const close = `<!--lh:/${id}-->`;
2321
+ if (!res.h.length) {
2322
+ b.last = stripMarkers(res.t[0]);
2323
+ sink.openBinding(key, b);
2324
+ return open + res.t[0] + close;
2325
+ }
2326
+ const t = res.t.slice();
2327
+ t[0] = open + t[0];
2328
+ t[t.length - 1] += close;
2329
+ sink.openBinding(key, b);
2330
+ return {
2331
+ t,
2332
+ h: res.h,
2333
+ p: res.p
2334
+ };
2335
+ },
2336
+ mint() {
2337
+ return nextId++;
2338
+ },
2339
+ active() {
2340
+ return !inScope || inScope();
2341
+ },
2342
+ attr(cap) {
2343
+ const owner = getOwner();
2344
+ const holeCtx = sharedConfig.context;
2345
+ const b = {
2346
+ key: "lha:" + cap.id,
2347
+ children: [],
2348
+ last: cap.base,
2349
+ closed: false,
2350
+ sweep() {
2351
+ if (b.closed) return;
2352
+ const prevSweeping = engine.sweeping;
2353
+ engine.sweeping = true;
2354
+ engine.gateHit = false;
2355
+ const sweepOwnersBefore = stamp();
2356
+ let html = "";
2357
+ try {
2358
+ let group = null;
2359
+ let groupVal = null;
2360
+ const run = () => {
2361
+ for (const part of cap.parts) {
2362
+ if (typeof part === "string") {
2363
+ html += part;
2364
+ continue;
2365
+ }
2366
+ let v;
2367
+ if (part.g) {
2368
+ if (group !== part.g) {
2369
+ group = part.g;
2370
+ groupVal = part.g();
2371
+ }
2372
+ v = groupVal[part.i];
2373
+ } else {
2374
+ v = part.f();
2375
+ }
2376
+ const vt = typeof v;
2377
+ if (vt === "string" || vt === "number") html += v;
2378
+ }
2379
+ };
2380
+ swept(owner, holeCtx, run);
2381
+ } catch (err) {
2382
+ if (ssrHandleError(err, true)) return;
2383
+ b.closed = true;
2384
+ sink.closeBinding(b.key);
2385
+ sink.error("lha:" + cap.id, String(err && err.message || err));
2386
+ return;
2387
+ } finally {
2388
+ engine.sweeping = prevSweeping;
2389
+ }
2390
+ if (engine.gateHit || stamp() !== sweepOwnersBefore) {
2391
+ b.closed = true;
2392
+ sink.closeBinding(b.key);
2393
+ return;
2394
+ }
2395
+ if (html === b.last) return;
2396
+ const before = attrNames(b.last);
2397
+ const after = attrNames(html);
2398
+ const removed = before.filter(n => !after.includes(n));
2399
+ b.last = html;
2400
+ sink.attr(String(cap.id), html, removed);
2401
+ }
2402
+ };
2403
+ sink.openBinding(b.key, b);
2404
+ }
2405
+ };
2406
+ return engine;
2407
+ }
2408
+ function attrNames(text) {
2409
+ const names = [];
2410
+ const re = /(?:^|\s)([^\s=/>"']+)(?:="[^"]*")?/g;
2411
+ let m;
2412
+ while (m = re.exec(text)) names.push(m[1]);
2413
+ return names;
2414
+ }
2415
+ function ssr(t) {
2416
+ const len = arguments.length;
2417
+ if (len === 1) return {
2418
+ t
2419
+ };
2420
+ let s = t[0];
2421
+ let result = null;
2422
+ let lastGroup = null;
2423
+ let lastGroupVal = null;
2424
+ let lastGroupIdx = 0;
2425
+ const live = sharedConfig.context && sharedConfig.context.liveHoles;
2426
+ const hp = live ? holeContentPositions(t) : null;
2427
+ let lastOpen = null;
2428
+ let cap = null;
2429
+ if (live && hp.openOff[0] >= 0) lastOpen = {
2430
+ r: null,
2431
+ seg: -1,
2432
+ off: hp.openOff[0]
2433
+ };
2434
+ const captureStart = () => {
2435
+ if (cap) return true;
2436
+ if (!lastOpen || live.suppressed || live.sweeping || !live.active()) return false;
2437
+ if (lastOpen.r !== result || result !== null && lastOpen.seg !== result.t.length - 1) {
2438
+ return false;
2439
+ }
2440
+ const id = live.mint();
2441
+ const inject = ` data-lha="${id}"`;
2442
+ let prefix;
2443
+ if (result === null) {
2444
+ s = s.slice(0, lastOpen.off) + inject + s.slice(lastOpen.off);
2445
+ prefix = s.slice(lastOpen.off + inject.length);
2446
+ } else {
2447
+ const seg = result.t[lastOpen.seg];
2448
+ result.t[lastOpen.seg] = seg.slice(0, lastOpen.off) + inject + seg.slice(lastOpen.off);
2449
+ prefix = result.t[lastOpen.seg].slice(lastOpen.off + inject.length);
2450
+ }
2451
+ cap = {
2452
+ id,
2453
+ parts: [prefix],
2454
+ base: prefix
2455
+ };
2456
+ return true;
2457
+ };
2458
+ for (let i = 1; i < len; i++) {
2459
+ const hole = arguments[i];
2460
+ const ht = typeof hole;
2461
+ if (ht === "string") {
2462
+ if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
2463
+ if (cap) {
2464
+ cap.parts.push(hole);
2465
+ cap.base += hole;
2466
+ }
2467
+ } else if (ht === "number") {
2468
+ if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
2469
+ if (cap) {
2470
+ cap.parts.push("" + hole);
2471
+ cap.base += hole;
2472
+ }
2473
+ } else if (hole == null || ht === "boolean") ; else if (ht === "function" && hole.$g) {
2474
+ let value;
2475
+ let hasValue = false;
2476
+ if (lastGroup !== hole) {
2477
+ const r = ssrFirstGroupHit(hole);
2478
+ if (r !== null) {
2479
+ lastGroup = hole;
2480
+ lastGroupVal = r;
2481
+ lastGroupIdx = 0;
2482
+ if (!Array.isArray(r) && result === null) {
2483
+ result = {
2484
+ t: [s],
2485
+ h: [],
2486
+ p: []
2487
+ };
2488
+ s = "";
2489
+ }
2490
+ }
2491
+ }
2492
+ if (lastGroup === hole) {
2493
+ if (Array.isArray(lastGroupVal)) {
2494
+ value = lastGroupVal[lastGroupIdx++];
2495
+ hasValue = true;
2496
+ if (live && !hp.pos[i - 1] && captureStart()) {
2497
+ cap.parts.push({
2498
+ g: hole,
2499
+ i: lastGroupIdx - 1
2500
+ });
2501
+ }
2502
+ } else {
2503
+ cap = null;
2504
+ result.h.push(ssrGroupSlot(lastGroupVal.fn, lastGroupIdx++));
2505
+ result.p.push(lastGroupVal.p);
2506
+ result.t.push("");
2507
+ }
2508
+ }
2509
+ if (hasValue) {
2510
+ const vt = typeof value;
2511
+ if (vt === "string" || vt === "number") {
2512
+ if (result === null) s += value;else result.t[result.t.length - 1] += value;
2513
+ if (cap && !hp.pos[i - 1]) cap.base += value;
2514
+ } else if (value == null || vt === "boolean") ; else if (result !== null) {
2515
+ resolveSSRNode(value, result);
2516
+ } else {
2517
+ const rs = tryResolveString(value);
2518
+ if (typeof rs === "string") {
2519
+ s += rs;
2520
+ } else {
2521
+ result = {
2522
+ t: [s],
2523
+ h: [],
2524
+ p: []
2525
+ };
2526
+ s = "";
2527
+ if (rs.merge !== undefined) mergeTemplateInto(result, rs.merge);else resolveSSRNode(rs.bail, result);
2528
+ }
2529
+ }
2530
+ }
2531
+ } else if (ht === "function") {
2532
+ let liveNode = null;
2533
+ if (live && hp.pos[i - 1] && (liveNode = live.content(hole)) !== null) {
2534
+ if (typeof liveNode === "string") {
2535
+ if (result === null) s += liveNode;else result.t[result.t.length - 1] += liveNode;
2536
+ } else {
2537
+ if (result === null) {
2538
+ result = {
2539
+ t: [s],
2540
+ h: [],
2541
+ p: []
2542
+ };
2543
+ s = "";
2544
+ }
2545
+ resolveSSRNode(liveNode, result);
2546
+ }
2547
+ } else if (result !== null) {
2548
+ const inTag = live && !hp.pos[i - 1];
2549
+ const capturing = inTag && captureStart();
2550
+ const li = capturing ? result.t.length - 1 : 0;
2551
+ const before = capturing ? result.t[li].length : 0;
2552
+ if (live) live.suppressed++;
2553
+ try {
2554
+ resolveSSRNode(hole, result);
2555
+ } finally {
2556
+ if (live) live.suppressed--;
2557
+ }
2558
+ if (capturing) {
2559
+ if (result.t.length - 1 === li) {
2560
+ cap.base += result.t[li].slice(before);
2561
+ cap.parts.push({
2562
+ f: hole
2563
+ });
2564
+ } else {
2565
+ cap = null;
2566
+ }
2567
+ }
2568
+ } else {
2569
+ const capturing = live && !hp.pos[i - 1] && captureStart();
2570
+ const r = tryResolveFunctionHole(hole);
2571
+ if (typeof r === "string") {
2572
+ s += r;
2573
+ if (capturing) {
2574
+ cap.base += r;
2575
+ cap.parts.push({
2576
+ f: hole
2577
+ });
2578
+ }
2579
+ } else {
2580
+ if (capturing) cap = null;
2581
+ result = {
2582
+ t: [s],
2583
+ h: [],
2584
+ p: []
2585
+ };
2586
+ s = "";
2587
+ appendResolvedNode(result, r);
2588
+ }
2589
+ }
2590
+ } else if (result !== null) {
2591
+ resolveSSRNode(hole, result);
2592
+ } else {
2593
+ const r = tryResolveString(hole);
2594
+ if (typeof r === "string") {
2595
+ s += r;
2596
+ } else {
2597
+ result = {
2598
+ t: [s],
2599
+ h: [],
2600
+ p: []
2601
+ };
2602
+ s = "";
2603
+ appendResolvedNode(result, r);
2604
+ }
2605
+ }
2606
+ const next = t[i];
2607
+ if (live) {
2608
+ if (cap) {
2609
+ const co = hp.closeOff[i];
2610
+ if (co >= 0) {
2611
+ const tail = next.slice(0, co);
2612
+ cap.parts.push(tail);
2613
+ cap.base += tail;
2614
+ live.attr(cap);
2615
+ cap = null;
2616
+ } else {
2617
+ cap.parts.push(next);
2618
+ cap.base += next;
2619
+ }
2620
+ }
2621
+ if (hp.openOff[i] >= 0) {
2622
+ lastOpen = result === null ? {
2623
+ r: null,
2624
+ seg: -1,
2625
+ off: s.length + hp.openOff[i]
2626
+ } : {
2627
+ r: result,
2628
+ seg: result.t.length - 1,
2629
+ off: result.t[result.t.length - 1].length + hp.openOff[i]
2630
+ };
2631
+ }
2632
+ }
2633
+ if (result === null) s += next;else result.t[result.t.length - 1] += next;
2634
+ }
2635
+ if (result === null) return {
2636
+ t: s
2637
+ };
2638
+ return result;
2639
+ }
2640
+ function ssrClassName(value) {
2641
+ if (typeof value === "number") return "" + value;
2642
+ if (!value) return "";
2643
+ if (typeof value === "string") return escape(value, true);
2644
+ value = classListToObject(value);
2645
+ let classKeys = Object.keys(value),
2646
+ result = "";
2647
+ for (let i = 0, len = classKeys.length; i < len; i++) {
2648
+ const key = classKeys[i],
2649
+ classValue = !!value[key];
2650
+ if (!key || key === "undefined" || !classValue) continue;
2651
+ i && (result += " ");
2652
+ result += escape(key, true);
2653
+ }
2654
+ return result;
2655
+ }
2656
+ function ssrStyle(value) {
2657
+ if (!value) return "";
2658
+ if (typeof value === "string") return escape(value, true);
2659
+ let result = "";
2660
+ const k = Object.keys(value);
2661
+ for (let i = 0; i < k.length; i++) {
2662
+ const s = escape(k[i], true);
2663
+ const v = value[k[i]];
2664
+ if (v != undefined) {
2665
+ if (i) result += ";";
2666
+ const r = escape(v, true);
2667
+ if (r != undefined && r !== "undefined") {
2668
+ result += `${s}:${r}`;
2669
+ }
2670
+ }
2671
+ }
2672
+ return result;
2673
+ }
2674
+ function ssrStyleProperty(name, value) {
2675
+ return value != null ? name + value : "";
2676
+ }
2677
+ function ssrElement(tag, props, children, needsId) {
2678
+ const hk = needsId ? ssrHydrationKey() : "";
2679
+ if (typeof props === "function") props = props();
2680
+ if (props == null) props = {};
2681
+ const skipChildren = VOID_ELEMENTS.test(tag);
2682
+ const keys = Object.keys(props);
2683
+ let result = `<${tag}${hk} `;
2684
+ for (let i = 0; i < keys.length; i++) {
2685
+ const prop = keys[i];
2686
+ const value = props[prop];
2687
+ if (tag === "textarea" && (prop === "value" || prop === "defaultValue")) {
2688
+ if (value !== null) children = escape(value);
2689
+ continue;
2690
+ }
2691
+ if (ChildProperties.has(prop)) {
2692
+ if (children === undefined && !skipChildren) children = tag === "script" || tag === "style" || prop === "innerHTML" ? props[prop] : escape(props[prop]);
2693
+ continue;
2694
+ }
2695
+ if (prop === "style") {
2696
+ result += `style="${ssrStyle(value)}"`;
2697
+ } else if (prop === "class") {
2698
+ result += `class="${ssrClassName(value)}"`;
2699
+ } else if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on" || prop.slice(0, 5) === "prop:") {
2700
+ if (typeof value === "function" && value[CLAIM_PROP] !== undefined && (prop === "ref" || prop.slice(0, 2) === "on")) {
2701
+ console.warn(`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])}}\`.`);
2702
+ }
2703
+ continue;
2704
+ } else if (typeof value === "boolean") {
2705
+ if (!value) continue;
2706
+ result += escape(prop);
2707
+ } else {
2708
+ result += value === "" ? escape(prop) : `${escape(prop)}="${escape(value, true)}"`;
2709
+ }
2710
+ if (i !== keys.length - 1) result += " ";
2711
+ }
2712
+ if (skipChildren) return {
2713
+ t: result + "/>"
2714
+ };
2715
+ if (typeof children === "function") children = children();
2716
+ return ssr([result + ">", `</${tag}>`], resolveSSRNode(children, undefined, true));
2717
+ }
2718
+ function ssrAttribute(key, value) {
2719
+ return value == null || value === false ? "" : value === true ? ` ${key}` : ` ${key}="${value}"`;
2720
+ }
2721
+ function ssrHydrationKey() {
2722
+ const hk = getHydrationKey();
2723
+ return hk ? ` _hk=${hk}` : "";
2724
+ }
2725
+ const CLAIM_PROP = /*#__PURE__*/Symbol.for("solid.claim-prop");
2726
+ const CLAIMS_STREAM = 1;
2727
+ const CLAIMS_DOCUMENT = 2;
2728
+ const CLAIM_UNSAFE = /[^A-Za-z0-9_.!~*'()-]/g;
2729
+ function encodeClaimKey(key) {
2730
+ return String(key).replace(CLAIM_UNSAFE, c => encodeURIComponent(c));
2731
+ }
2732
+ function ssrClaim(map) {
2733
+ const mode = sharedConfig.context && sharedConfig.context.claims;
2734
+ if (!mode || mode === CLAIMS_DOCUMENT && !(typeof inServerComponentScope === "function" && inServerComponentScope())) {
2735
+ return "";
2736
+ }
2737
+ let out = "";
2738
+ for (const pos in map) {
2739
+ const value = map[pos];
2740
+ const list = Array.isArray(value) ? value : [value];
2741
+ for (const fn of list) {
2742
+ const prop = typeof fn === "function" && fn[CLAIM_PROP] || undefined;
2743
+ if (prop === undefined) {
2744
+ {
2745
+ console.warn(`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=\`.`);
2746
+ }
2747
+ continue;
2748
+ }
2749
+ out += `${out ? "," : ""}${pos}=${encodeClaimKey(prop)}`;
2750
+ }
2751
+ }
2752
+ return out ? ` _bnd="${out}"` : "";
2753
+ }
2754
+ function decodeSSREntities(s) {
2755
+ return s.indexOf("&") < 0 ? s : s.replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&amp;/g, "&");
2756
+ }
2757
+ const SELECT_VALUE_ATTR = /\svalue(?:="([^"]*)")?(?=[\s>]|$)/;
2758
+ function tagEnd(html, i) {
2759
+ for (let j = i + 1; j < html.length; j++) {
2760
+ const c = html.charCodeAt(j);
2761
+ if (c === 34) {
2762
+ j = html.indexOf('"', j + 1);
2763
+ if (j < 0) return -1;
2764
+ } else if (c === 62) return j;
2765
+ }
2766
+ return -1;
2767
+ }
2768
+ function optionText(html, from) {
2769
+ let t = "";
2770
+ let i = from;
2771
+ for (;;) {
2772
+ const lt = html.indexOf("<", i);
2773
+ if (lt < 0) return t + html.slice(i);
2774
+ t += html.slice(i, lt);
2775
+ if (!html.startsWith("<!--", lt)) return t;
2776
+ const ce = html.indexOf("-->", lt);
2777
+ if (ce < 0) return t;
2778
+ i = ce + 3;
2779
+ }
2780
+ }
2781
+ function tagIs(html, i, name) {
2782
+ if (!html.startsWith(name, i + 1)) return false;
2783
+ const c = html.charCodeAt(i + 1 + name.length);
2784
+ return c === 32 || c === 62 || c === 9 || c === 10 || c === 13;
2785
+ }
2786
+ let selectValuesActive = false;
2787
+ function ssrSelectValues() {
2788
+ selectValuesActive = true;
2789
+ }
2790
+ function resolveSSRSelectValues(html) {
2791
+ if (!selectValuesActive) return html;
2792
+ let cand = html.indexOf("<select");
2793
+ if (cand < 0) return html;
2794
+ let out = "";
2795
+ let idx = 0;
2796
+ while (cand >= 0) {
2797
+ if (!tagIs(html, cand, "select")) {
2798
+ cand = html.indexOf("<select", cand + 7);
2799
+ continue;
2800
+ }
2801
+ const e0 = tagEnd(html, cand);
2802
+ if (e0 < 0) break;
2803
+ const open = html.slice(cand, e0 + 1);
2804
+ const m = SELECT_VALUE_ATTR.exec(open);
2805
+ if (!m) {
2806
+ cand = html.indexOf("<select", e0 + 1);
2807
+ continue;
2808
+ }
2809
+ const bound = decodeSSREntities(m[1] ?? "");
2810
+ const sel = {
2811
+ values: /\smultiple(?=[\s>=])/.test(open) ? bound.split(",") : [bound],
2812
+ strip: cand + m.index,
2813
+ stripEnd: cand + m.index + m[0].length,
2814
+ body: e0 + 1,
2815
+ marks: [],
2816
+ defaulted: false
2817
+ };
2818
+ let committed = false;
2819
+ let i = html.indexOf("<", e0 + 1);
2820
+ while (i >= 0) {
2821
+ let e;
2822
+ if (html.charCodeAt(i + 1) === 33) {
2823
+ e = html.charCodeAt(i + 2) === 45 ? html.indexOf("-->", i) : html.indexOf(">", i);
2824
+ if (e < 0) break;
2825
+ if (html.charCodeAt(i + 2) === 45) e += 2;
2826
+ } else {
2827
+ e = tagEnd(html, i);
2828
+ if (e < 0) break;
2829
+ if (html.startsWith("</select>", i)) {
2830
+ out += html.slice(idx, sel.strip) + html.slice(sel.stripEnd, sel.body);
2831
+ let seg = sel.body;
2832
+ if (!sel.defaulted) {
2833
+ for (let k = 0; k < sel.marks.length; k++) {
2834
+ out += html.slice(seg, sel.marks[k]) + " selected";
2835
+ seg = sel.marks[k];
2836
+ }
2837
+ }
2838
+ out += html.slice(seg, i);
2839
+ idx = i;
2840
+ committed = true;
2841
+ break;
2842
+ } else if (tagIs(html, i, "option")) {
2843
+ const attrs = html.slice(i + 7, e);
2844
+ if (/\sselected(?=[\s=]|$)/.test(attrs)) sel.defaulted = true;else {
2845
+ const vm = SELECT_VALUE_ATTR.exec(attrs);
2846
+ const value = vm ? decodeSSREntities(vm[1] ?? "") : decodeSSREntities(optionText(html, e + 1)).replace(/\s+/g, " ").trim();
2847
+ if (sel.values.includes(value)) sel.marks.push(e);
2848
+ }
2849
+ }
2850
+ }
2851
+ i = html.indexOf("<", e + 1);
2852
+ }
2853
+ if (!committed) break;
2854
+ cand = html.indexOf("<select", idx);
2855
+ }
2856
+ if (idx === 0) return html;
2857
+ return out + html.slice(idx);
2858
+ }
2859
+ function escape(s, attr) {
2860
+ const t = typeof s;
2861
+ if (t !== "string") {
2862
+ if (!attr && Array.isArray(s)) {
2863
+ const joined = tryJoinPlainSSRArray(s);
2864
+ if (joined !== undefined) return joined;
2865
+ s = s.slice();
2866
+ for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
2867
+ return s;
2868
+ }
2869
+ if (attr) {
2870
+ if (s == null || t === "boolean" || t === "number") return s;
2871
+ return escape(String(s), attr);
2872
+ }
2873
+ return s;
2874
+ }
2875
+ const i = s.search(attr ? ESCAPE_ATTR : ESCAPE_CONTENT);
2876
+ if (i < 0) return s;
2877
+ return escapeSlow(s, attr, i);
2878
+ }
2879
+ const ESCAPE_CONTENT = /[&<]/;
2880
+ const ESCAPE_ATTR = /[&"<]/;
2881
+ function escapeSlow(s, attr, start) {
2882
+ if (attr) return escapeAttrSlow(s, start);
2883
+ const c0 = s.charCodeAt(start);
2884
+ let iDelim = c0 === 60 ? start : s.indexOf("<", start);
2885
+ let iAmp = c0 === 38 ? start : s.indexOf("&", start);
2886
+ let left = 0,
2887
+ out = "";
2888
+ while (iDelim >= 0 && iAmp >= 0) {
2889
+ if (iDelim < iAmp) {
2890
+ if (left < iDelim) out += s.substring(left, iDelim);
2891
+ out += "&lt;";
2892
+ left = iDelim + 1;
2893
+ iDelim = s.indexOf("<", left);
2894
+ } else {
2895
+ if (left < iAmp) out += s.substring(left, iAmp);
2896
+ out += "&amp;";
2897
+ left = iAmp + 1;
2898
+ iAmp = s.indexOf("&", left);
2899
+ }
2900
+ }
2901
+ if (iDelim >= 0) {
2902
+ do {
2903
+ if (left < iDelim) out += s.substring(left, iDelim);
2904
+ out += "&lt;";
2905
+ left = iDelim + 1;
2906
+ iDelim = s.indexOf("<", left);
2907
+ } while (iDelim >= 0);
2908
+ } else while (iAmp >= 0) {
2909
+ if (left < iAmp) out += s.substring(left, iAmp);
2910
+ out += "&amp;";
2911
+ left = iAmp + 1;
2912
+ iAmp = s.indexOf("&", left);
2913
+ }
2914
+ return left < s.length ? out + s.substring(left) : out;
2915
+ }
2916
+ function escapeAttrSlow(s, start) {
2917
+ const c0 = s.charCodeAt(start);
2918
+ let iQuot = c0 === 34 ? start : s.indexOf('"', start);
2919
+ let iAmp = c0 === 38 ? start : s.indexOf("&", start);
2920
+ let iLt = c0 === 60 ? start : s.indexOf("<", start);
2921
+ let left = 0,
2922
+ out = "";
2923
+ for (;;) {
2924
+ let i = -1,
2925
+ ent;
2926
+ if (iQuot >= 0) {
2927
+ i = iQuot;
2928
+ ent = "&quot;";
2929
+ }
2930
+ if (iAmp >= 0 && (i < 0 || iAmp < i)) {
2931
+ i = iAmp;
2932
+ ent = "&amp;";
2933
+ }
2934
+ if (iLt >= 0 && (i < 0 || iLt < i)) {
2935
+ i = iLt;
2936
+ ent = "&lt;";
2937
+ }
2938
+ if (i < 0) break;
2939
+ if (left < i) out += s.substring(left, i);
2940
+ out += ent;
2941
+ left = i + 1;
2942
+ if (i === iQuot) iQuot = s.indexOf('"', left);else if (i === iAmp) iAmp = s.indexOf("&", left);else iLt = s.indexOf("<", left);
2943
+ }
2944
+ return left < s.length ? out + s.substring(left) : out;
2945
+ }
2946
+ function tryJoinPlainSSRArray(nodes) {
2947
+ if (nodes.length === 0) return undefined;
2948
+ let out = "";
2949
+ for (let i = 0, len = nodes.length; i < len; i++) {
2950
+ const node = nodes[i];
2951
+ if (node == null || typeof node !== "object" || node.h || typeof node.t !== "string") {
2952
+ return undefined;
2953
+ }
2954
+ out += node.t;
2955
+ }
2956
+ return out;
2957
+ }
2958
+ function getHydrationKey() {
2959
+ const hydrate = sharedConfig.context;
2960
+ return hydrate && sharedConfig.getNextContextId();
2961
+ }
2962
+ function applyRef(r, element) {
2963
+ Array.isArray(r) ? r.flat(Infinity).forEach(f => f && f(element)) : r(element);
2964
+ }
2965
+ function generateHydrationScript({
2966
+ eventNames = ["click", "input"],
2967
+ nonce
2968
+ } = {}) {
2969
+ 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-->`;
2970
+ }
2971
+ function queue(fn) {
2972
+ return Promise.resolve().then(fn);
2973
+ }
2974
+ const deferFlush = typeof setImmediate === "function" ? setImmediate : fn => setTimeout(fn, 0);
2975
+ function allSettled(promises) {
2976
+ let size = promises.size;
2977
+ return Promise.allSettled(promises).then(() => {
2978
+ if (promises.size !== size) return allSettled(promises);
2979
+ return size;
2980
+ });
2981
+ }
2982
+ function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead) {
2983
+ const scriptTag = scripts ? `<script${nonceAttr(nonce, "script")}>${scripts}</script>` : "";
2984
+ const title = headTags ? headTags.title : null;
2985
+ let headTagsHtml = headTags ? headTags.html : "";
2986
+ const headPrelude = headTags ? headTags.prelude : "";
2987
+ if (!onHead && title == null && !headTagsHtml && !headPrelude && !(emittedAssets && emittedAssets.size) && !preloadLinks && !(inlineStyles && inlineStyles.size)) {
2988
+ if (!scriptTag) return html;
2989
+ const xs = html.indexOf("<!--xs-->");
2990
+ return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
2991
+ }
2992
+ if (headPrelude) {
2993
+ const open = html.match(/<head(?:\s[^>]*)?>/);
2994
+ if (open) {
2995
+ const at = open.index + open[0].length;
2996
+ html = html.slice(0, at) + headPrelude + html.slice(at);
2997
+ }
2998
+ }
2999
+ let headIdx = html.indexOf("</head>");
3000
+ if (headIdx === -1) {
3001
+ if (onHead) {
3002
+ let titleHtml = "";
3003
+ if (title != null) {
3004
+ 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>`;
3005
+ }
3006
+ onHead(headPrelude + headTagsHtml + titleHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce));
3007
+ }
3008
+ if (!scriptTag) return html;
3009
+ const xs = html.indexOf("<!--xs-->");
3010
+ return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
3011
+ }
3012
+ if (title != null) {
3013
+ const winner = escape(title);
3014
+ const open = html.match(/<head(?:\s[^>]*)?>/);
3015
+ const from = open ? open.index + open[0].length : 0;
3016
+ const m = /<title(\s[^>]*)?>([\s\S]*?)<\/title>/.exec(html.slice(from, headIdx));
3017
+ if (m) {
3018
+ const at = from + m.index;
3019
+ const stash = m[2].replace(/"/g, "&quot;");
3020
+ html = html.slice(0, at) + `<title${m[1] || ""} data-dh="title" data-dhf="${stash}">${winner}</title>` + html.slice(at + m[0].length);
3021
+ headIdx = html.indexOf("</head>");
3022
+ } else {
3023
+ headTagsHtml = `<title data-dh="title">${winner}</title>` + headTagsHtml;
3024
+ }
3025
+ }
3026
+ const head = headTagsHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce);
3027
+ if (!scriptTag) return html.slice(0, headIdx) + head + html.slice(headIdx);
3028
+ const xsIdx = html.indexOf("<!--xs-->");
3029
+ if (xsIdx === -1) return html.slice(0, headIdx) + head + html.slice(headIdx) + scriptTag;
3030
+ 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);
3031
+ }
3032
+ function renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce) {
3033
+ let head = "";
3034
+ const styleAttr = nonceAttr(nonce, "style");
3035
+ const scriptAttr = nonceAttr(nonce, "script");
3036
+ if (emittedAssets && emittedAssets.size) {
3037
+ for (const url of emittedAssets) {
3038
+ head += isCssUrl(url) ? `<link rel="stylesheet" href="${url}"${styleAttr}>` : `<link rel="modulepreload" href="${url}"${scriptAttr}>`;
3039
+ }
3040
+ }
3041
+ if (preloadLinks) {
3042
+ for (const entry of preloadLinks) head += `<link${entry.attrHtml}>`;
3043
+ }
3044
+ if (inlineStyles && inlineStyles.size) {
3045
+ for (const entry of inlineStyles.values()) {
3046
+ if (entry.emitted) continue;
3047
+ entry.emitted = true;
3048
+ head += renderInlineStyle(entry, nonce);
3049
+ }
3050
+ }
3051
+ return head;
3052
+ }
3053
+ function serializeFragmentAssets(key, boundaryModules, context, name = key) {
3054
+ const map = boundaryModules.get(key);
3055
+ if (!map || !Object.keys(map).length) return;
3056
+ context.serialize(name + "_assets", {
3057
+ ...map
3058
+ });
3059
+ }
3060
+ function propagateBoundaryStyles(childKey, parentKey, tracking) {
3061
+ const childStyles = tracking.getBoundaryStyles(childKey);
3062
+ if (!childStyles) return;
3063
+ let parentStyles = tracking.boundaryStyles.get(parentKey);
3064
+ if (!parentStyles) {
3065
+ parentStyles = new Set();
3066
+ tracking.boundaryStyles.set(parentKey, parentStyles);
3067
+ }
3068
+ for (const url of childStyles) {
3069
+ parentStyles.add(url);
3070
+ }
3071
+ }
3072
+ function collectStreamStyles(key, tracking, headStyles) {
3073
+ const styles = tracking.getBoundaryStyles(key);
3074
+ const links = [];
3075
+ const inline = [];
3076
+ if (!styles) return {
3077
+ links,
3078
+ inline
3079
+ };
3080
+ for (const entry of styles) {
3081
+ if (typeof entry === "string") {
3082
+ if (!headStyles || !headStyles.has(entry)) links.push(entry);
3083
+ } else if (entry.emitted) {
3084
+ continue;
3085
+ } else if (entry.attrHtml !== undefined) {
3086
+ entry.emitted = true;
3087
+ links.push(entry);
3088
+ } else {
3089
+ entry.emitted = true;
3090
+ inline.push(entry);
3091
+ }
3092
+ }
3093
+ return {
3094
+ links,
3095
+ inline
3096
+ };
3097
+ }
3098
+ function escapeStyleContent(content) {
3099
+ return content.replace(/<\/(style)/gi, "<\\/$1");
3100
+ }
3101
+ function renderInlineStyle(entry, nonce) {
3102
+ let attrs = "";
3103
+ let hasNonce = false;
3104
+ if (entry.attrs) {
3105
+ for (const name in entry.attrs) {
3106
+ if (name.length === 5 && asciiLowerCase(name) === "nonce") hasNonce = true;
3107
+ attrs += ` ${name}="${escape(String(entry.attrs[name]), true)}"`;
3108
+ }
3109
+ }
3110
+ const nonceHtml = hasNonce ? "" : nonceAttr(nonce, "style");
3111
+ return `<style${nonceHtml} data-asset="${escape(entry.id, true)}"${attrs}>${escapeStyleContent(entry.content)}</style>`;
3112
+ }
3113
+ function waitForFragments(registry, key) {
3114
+ for (const k of [...registry.keys()].reverse()) {
3115
+ if (key.startsWith(k)) return k;
3116
+ }
3117
+ return false;
3118
+ }
3119
+ function replacePlaceholder(html, key, value) {
3120
+ const marker = `<template id="pl-${key}">`;
3121
+ const close = `<!--pl-${key}-->`;
3122
+ const first = html.indexOf(marker);
3123
+ if (first === -1) return html;
3124
+ const last = html.indexOf(close, first + marker.length);
3125
+ return html.slice(0, first) + value + html.slice(last + close.length);
3126
+ }
3127
+ function classListToObject(classList) {
3128
+ if (Array.isArray(classList)) {
3129
+ const result = {};
3130
+ flattenClassList(classList, result);
3131
+ return result;
3132
+ }
3133
+ return classList;
3134
+ }
3135
+ function flattenClassList(list, result) {
3136
+ for (let i = 0, len = list.length; i < len; i++) {
3137
+ const item = list[i];
3138
+ if (Array.isArray(item)) flattenClassList(item, result);else if (typeof item === "object" && item != null) Object.assign(result, item);
3139
+ else if (typeof item !== "boolean" && (item || item === 0)) result[item] = true;
3140
+ }
3141
+ }
3142
+ function tryResolveString(node) {
3143
+ const t = typeof node;
3144
+ if (t === "string") return node;
3145
+ if (t === "number") return "" + node;
3146
+ if (node == null || t === "boolean") return "";
3147
+ if (t === "object") {
3148
+ if (Array.isArray(node)) {
3149
+ const joined = tryJoinPlainSSRArray(node);
3150
+ if (joined !== undefined) return joined;
3151
+ let s = "";
3152
+ let prevNonObj = false;
3153
+ for (let i = 0, len = node.length; i < len; i++) {
3154
+ const item = node[i];
3155
+ const itemNonObj = item !== null && typeof item !== "object";
3156
+ if (prevNonObj && itemNonObj) s += "<!--!$-->";
3157
+ prevNonObj = itemNonObj;
3158
+ const r = tryResolveString(item);
3159
+ if (typeof r !== "string") return {
3160
+ bail: node
3161
+ };
3162
+ s += r;
3163
+ }
3164
+ return s;
3165
+ }
3166
+ if (node.h && node.h.length > 0) return {
3167
+ merge: node
3168
+ };
3169
+ if (node.t === undefined) {
3170
+ console.warn(`Unrecognized value. Skipped inserting`, node);
3171
+ return "";
3172
+ }
3173
+ return Array.isArray(node.t) ? node.t[0] : node.t;
3174
+ }
3175
+ if (t === "function") {
3176
+ let v;
3177
+ try {
3178
+ v = node();
3179
+ } catch (err) {
3180
+ return buildAsyncWrap(err, node) || "";
3181
+ }
3182
+ return tryResolveString(v);
3183
+ }
3184
+ return "";
3185
+ }
3186
+ function resolveSSRNode(node, result = {
3187
+ t: [""],
3188
+ h: [],
3189
+ p: []
3190
+ }, top) {
3191
+ const t = typeof node;
3192
+ if (t === "string" || t === "number") {
3193
+ result.t[result.t.length - 1] += node;
3194
+ } else if (node == null || t === "boolean") ; else if (Array.isArray(node)) {
3195
+ const slotLive = node.$slot && sharedConfig.context && sharedConfig.context.liveHoles;
3196
+ if (slotLive) slotLive.suppressed++;
3197
+ try {
3198
+ let prevNonObj = false;
3199
+ for (let i = 0, len = node.length; i < len; i++) {
3200
+ const item = node[i];
3201
+ const itemNonObj = item !== null && typeof item !== "object";
3202
+ if (!top && prevNonObj && itemNonObj) result.t[result.t.length - 1] += `<!--!$-->`;
3203
+ prevNonObj = itemNonObj;
3204
+ resolveSSRNode(item, result);
3205
+ }
3206
+ } finally {
3207
+ if (slotLive) slotLive.suppressed--;
3208
+ }
3209
+ } else if (t === "object") {
3210
+ if (node.h) {
3211
+ result.t[result.t.length - 1] += node.t[0];
3212
+ if (node.t.length > 1) {
3213
+ result.t.push(...node.t.slice(1));
3214
+ result.h.push(...node.h);
3215
+ result.p.push(...node.p);
3216
+ }
3217
+ } else if (node.t !== undefined) {
3218
+ result.t[result.t.length - 1] += node.t;
3219
+ } else console.warn(`Unrecognized value. Skipped inserting`, node);
3220
+ } else if (t === "function") {
3221
+ const live = sharedConfig.context && sharedConfig.context.liveHoles;
3222
+ let liveNode = null;
3223
+ if (live && (liveNode = live.content(node)) !== null) {
3224
+ if (typeof liveNode === "string") result.t[result.t.length - 1] += liveNode;else resolveSSRNode(liveNode, result);
3225
+ } else {
3226
+ try {
3227
+ resolveSSRNode(node(), result);
3228
+ } catch (err) {
3229
+ const wrap = buildAsyncWrap(err, node);
3230
+ if (wrap) {
3231
+ result.h.push(wrap.fn);
3232
+ result.p.push(wrap.p);
3233
+ result.t.push("");
3234
+ }
3235
+ }
3236
+ }
3237
+ }
3238
+ return result;
3239
+ }
3240
+ function resolveSSRSync(node) {
3241
+ const res = resolveSSRNode(node);
3242
+ if (!res.h.length) return res.t[0];
3243
+ throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
3244
+ }
3245
+ const RequestContext = Symbol.for("solid.RequestContext");
3246
+ function getRequestEvent() {
3247
+ 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;
3248
+ }
3249
+ function peekRequestEvent() {
3250
+ const store = globalThis[RequestContext];
3251
+ return store ? store.getStore() : undefined;
3252
+ }
3253
+ function createResponseStub() {
3254
+ return {
3255
+ status: undefined,
3256
+ statusText: undefined,
3257
+ headers: new Headers(),
3258
+ committed: false
3259
+ };
3260
+ }
3261
+ function createRequestEvent(request, init) {
3262
+ return {
3263
+ request,
3264
+ locals: {},
3265
+ response: createResponseStub(),
3266
+ ...init
3267
+ };
3268
+ }
3269
+ function reportLostHeaderWrite(method, name) {
3270
+ const message = `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).";
3271
+ throw new Error(message);
3272
+ }
3273
+ function commitResponseStub(stub, {
3274
+ allowLateLocation = false
3275
+ } = {}) {
3276
+ if (!stub || stub.committed) return stub;
3277
+ stub.committed = true;
3278
+ const headers = stub.headers;
3279
+ if (!headers || typeof headers.set !== "function") return stub;
3280
+ for (const method of ["set", "append", "delete"]) {
3281
+ const original = headers[method].bind(headers);
3282
+ headers[method] = function (name, ...rest) {
3283
+ if (allowLateLocation && method === "set" && String(name).toLowerCase() === "location") {
3284
+ return original(name, ...rest);
3285
+ }
3286
+ reportLostHeaderWrite(method, name);
3287
+ };
3288
+ }
3289
+ return stub;
3290
+ }
3291
+ const validRedirectStatuses = /*#__PURE__*/new Set([301, 302, 303, 307, 308]);
3292
+ function getExpectedRedirectStatus(response) {
3293
+ if (response.status && validRedirectStatuses.has(response.status)) return response.status;
3294
+ return 302;
3295
+ }
3296
+ function mergeStubHeaders(target, stub) {
3297
+ if (!stub) return target;
3298
+ stub.headers.forEach((value, key) => {
3299
+ if (key !== "set-cookie") target.set(key, value);
3300
+ });
3301
+ const setCookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
3302
+ for (const cookie of setCookies) target.append("set-cookie", cookie);
3303
+ return target;
3304
+ }
3305
+ function copyInitHeaders(init) {
3306
+ if (!init || !init.getSetCookie) return new Headers(init);
3307
+ const headers = new Headers();
3308
+ init.forEach((value, key) => {
3309
+ if (key !== "set-cookie") headers.append(key, value);
3310
+ });
3311
+ for (const cookie of init.getSetCookie()) headers.append("Set-Cookie", cookie);
3312
+ return headers;
3313
+ }
3314
+ const STUB_GAP_FILL_EXCLUDED = /*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location",
3315
+ ...COMPOSED_BODY_FRAMING].map(header => header.toLowerCase()));
3316
+ function fillsStubGap(key, headers, response) {
3317
+ if (key === "set-cookie" || STUB_GAP_FILL_EXCLUDED.has(key)) return false;
3318
+ if (response.body === null && (key === "content-type" || key === "content-length")) return false;
3319
+ return !headers.has(key);
3320
+ }
3321
+ function commitEventResponse(response, event = getRequestEvent()) {
3322
+ const stub = event && event.response;
3323
+ if (!stub || !stub.headers || stub.committed) return response;
3324
+ const cookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
3325
+ commitResponseStub(stub);
3326
+ let hasGaps = false;
3327
+ stub.headers.forEach((value, key) => {
3328
+ if (fillsStubGap(key, response.headers, response)) hasGaps = true;
3329
+ });
3330
+ if (!cookies.length && !hasGaps) return response;
3331
+ const headers = copyInitHeaders(response.headers);
3332
+ for (const cookie of cookies) headers.append("Set-Cookie", cookie);
3333
+ stub.headers.forEach((value, key) => {
3334
+ if (fillsStubGap(key, headers, response)) headers.set(key, value);
3335
+ });
3336
+ return new Response(response.body, {
3337
+ status: response.status,
3338
+ statusText: response.statusText,
3339
+ headers
3340
+ });
3341
+ }
3342
+ function deriveHead(stub, responseInit = {}) {
3343
+ const headers = mergeStubHeaders(copyInitHeaders(responseInit.headers), stub);
3344
+ for (const header of COMPOSED_BODY_FRAMING) headers.delete(header);
3345
+ const status = stub && stub.status || responseInit.status || 200;
3346
+ const statusText = stub && stub.statusText || responseInit.statusText || undefined;
3347
+ return {
3348
+ status,
3349
+ statusText,
3350
+ headers
3351
+ };
3352
+ }
3353
+ function createSSRResponse(result, event, options = {}) {
3354
+ const stub = event && event.response;
3355
+ const {
3356
+ responseInit,
3357
+ transformChunk
3358
+ } = options;
3359
+ const nonce = normalizeNonce(options.nonce);
3360
+ if (typeof result === "string") {
3361
+ if (stub) commitResponseStub(stub);
3362
+ const head = deriveHead(stub, responseInit);
3363
+ if (stub && stub.headers.get("Location")) {
3364
+ return new Response(null, {
3365
+ status: getExpectedRedirectStatus(stub),
3366
+ headers: head.headers
3367
+ });
3368
+ }
3369
+ if (!head.headers.has("content-type")) {
3370
+ head.headers.set("content-type", "text/html; charset=utf-8");
3371
+ }
3372
+ return new Response(transformChunk ? transformChunk(result) : result, {
3373
+ status: head.status,
3374
+ statusText: head.statusText,
3375
+ headers: head.headers
3376
+ });
3377
+ }
3378
+ const encoder = new TextEncoder();
3379
+ return new Promise(resolve => {
3380
+ let controller;
3381
+ let closed = false;
3382
+ let flushed = false;
3383
+ const enqueue = value => {
3384
+ if (closed || !controller) return;
3385
+ try {
3386
+ controller.enqueue(encoder.encode(value));
3387
+ } catch {
3388
+ closed = true;
3389
+ }
3390
+ };
3391
+ result.pipe({
3392
+ write(chunk) {
3393
+ if (!flushed) {
3394
+ flushed = true;
3395
+ if (stub) commitResponseStub(stub, {
3396
+ allowLateLocation: true
3397
+ });
3398
+ const head = deriveHead(stub, responseInit);
3399
+ if (stub && stub.headers.get("Location")) {
3400
+ closed = true;
3401
+ resolve(new Response(null, {
3402
+ status: getExpectedRedirectStatus(stub),
3403
+ headers: head.headers
3404
+ }));
3405
+ return;
3406
+ }
3407
+ if (!head.headers.has("content-type")) {
3408
+ head.headers.set("content-type", "text/html; charset=utf-8");
3409
+ }
3410
+ resolve(new Response(new ReadableStream({
3411
+ start(c) {
3412
+ controller = c;
3413
+ },
3414
+ cancel() {
3415
+ closed = true;
3416
+ }
3417
+ }), {
3418
+ status: head.status,
3419
+ statusText: head.statusText,
3420
+ headers: head.headers
3421
+ }));
3422
+ }
3423
+ enqueue(transformChunk ? transformChunk(chunk) : chunk);
3424
+ },
3425
+ end() {
3426
+ if (closed || !controller) return;
3427
+ const location = stub && stub.headers.get("Location");
3428
+ if (location && isHttpNavigationTarget(location)) {
3429
+ const attr = nonceAttr(nonce, "script");
3430
+ enqueue(`<script${attr}>window.location=${JSON.stringify(location).replace(/</g, "\\u003c")}</script>`);
3431
+ }
3432
+ closed = true;
3433
+ try {
3434
+ controller.close();
3435
+ } catch {}
3436
+ }
3437
+ });
3438
+ });
3439
+ }
3440
+ function composeMiddleware(middlewares) {
3441
+ return function run(request, next) {
3442
+ let index = -1;
3443
+ function dispatch(i, req) {
3444
+ if (i <= index) return Promise.reject(new Error("next() called multiple times"));
3445
+ index = i;
3446
+ if (i === middlewares.length) return Promise.resolve(next(req));
3447
+ return Promise.resolve(middlewares[i](req, override => dispatch(i + 1, override || req)));
3448
+ }
3449
+ return dispatch(0, request);
3450
+ };
3451
+ }
3452
+ function registerElementClaim() {
3453
+ return noopCleanup;
3454
+ }
3455
+ function noopCleanup() {}
3456
+ function claimElement(node) {
3457
+ return node;
3458
+ }
3459
+ function claimElementTree(root) {
3460
+ return root;
3461
+ }
3462
+ function notSup() {
3463
+ 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>.");
3464
+ }
3465
+
3466
+ setContainerTraceResolver(getProjectionTrace);
3467
+ const isServer = true;
3468
+ const isDev = true;
3469
+ function dynamic(source, options) {
3470
+ const cached = createMemo(source, {
3471
+ serialize: false
3472
+ });
3473
+ const deferStream = !!options?.deferStream;
3474
+ return props => {
3475
+ const ctx = sharedConfig.context;
3476
+ let gated = !deferStream || !ctx?.async;
3477
+ return createMemo(() => {
3478
+ let c;
3479
+ try {
3480
+ c = cached();
3481
+ } catch (err) {
3482
+ if (!gated && err instanceof NotReadyError) {
3483
+ gated = true;
3484
+ ctx.block(Promise.resolve(err.source).then(() => {}, () => {}));
3485
+ }
3486
+ throw err;
3487
+ }
3488
+ if (c) {
3489
+ if (typeof c === "function") return c(props);
3490
+ if (typeof c === "string") {
3491
+ return ssrElement(c, props, undefined, true);
3492
+ }
3493
+ }
3494
+ }, {
3495
+ sync: true
3496
+ });
3497
+ };
3498
+ }
3499
+ function Dynamic(props) {
3500
+ const Comp = dynamic(() => props.component);
3501
+ return createComponent(Comp, omit(props, "component"));
3502
+ }
3503
+ function Portal(props) {
3504
+ const o = getOwner();
3505
+ if (o?.id != null) getNextChildId(o);
3506
+ return undefined;
3507
+ }
3508
+ function registerClientOnlyPreload(moduleUrl) {
3509
+ const ctx = sharedConfig.context;
3510
+ if (!ctx?.registerAsset || !ctx.resolveAssets) return;
3511
+ const registerAsset = ctx.registerAsset;
3512
+ const resolve = ctx.resolveAssets;
3513
+ const apply = assets => {
3514
+ if (!assets) return;
3515
+ for (let i = 0; i < assets.css.length; i++) {
3516
+ const css = assets.css[i];
3517
+ if (typeof css === "string") registerAsset("style", css);else registerAsset("inline-style", css);
3518
+ }
3519
+ if (assets.preloads) {
3520
+ for (let i = 0; i < assets.preloads.length; i++) {
3521
+ registerAsset("preload", assets.preloads[i]);
3522
+ }
3523
+ }
3524
+ for (let i = 0; i < assets.js.length; i++) registerAsset("module", assets.js[i]);
3525
+ };
3526
+ const assets = resolve(moduleUrl);
3527
+ if (assets && typeof assets.then === "function") {
3528
+ const boundary = ctx._currentBoundaryId;
3529
+ assets.then(resolved => {
3530
+ const current = ctx._currentBoundaryId;
3531
+ ctx._currentBoundaryId = boundary;
3532
+ try {
3533
+ apply(resolved);
3534
+ } finally {
3535
+ ctx._currentBoundaryId = current;
3536
+ }
3537
+ },
3538
+ () => {});
3539
+ } else {
3540
+ apply(assets);
3541
+ }
3542
+ }
3543
+ function clientOnly(_fn, _options = {}, moduleUrl) {
3544
+ return props => {
3545
+ if (moduleUrl) registerClientOnlyPreload(moduleUrl);
3546
+ return createMemo(() => props.fallback);
3547
+ };
3548
+ }
3549
+ const statusLedgers = /* @__PURE__ */new WeakMap();
3550
+ const headerLedgers = /* @__PURE__ */new WeakMap();
3551
+ function httpStatus(code, text) {
3552
+ const event = getRequestEvent();
3553
+ const response = event && event.response;
3554
+ if (response && !response.committed) {
3555
+ let ledger = statusLedgers.get(response);
3556
+ if (!ledger) {
3557
+ ledger = {
3558
+ base: {
3559
+ status: response.status,
3560
+ statusText: response.statusText
3561
+ },
3562
+ live: []
3563
+ };
3564
+ statusLedgers.set(response, ledger);
3565
+ }
3566
+ const declaration = {
3567
+ status: code,
3568
+ statusText: text
3569
+ };
3570
+ ledger.live.push(declaration);
3571
+ response.status = code;
3572
+ response.statusText = text;
3573
+ onCleanup(() => {
3574
+ if (response.committed) return;
3575
+ const index = ledger.live.indexOf(declaration);
3576
+ if (index < 0) return;
3577
+ ledger.live.splice(index, 1);
3578
+ const effective = ledger.live.length ? ledger.live[ledger.live.length - 1] : ledger.base;
3579
+ response.status = effective.status;
3580
+ response.statusText = effective.statusText;
3581
+ if (!ledger.live.length) statusLedgers.delete(response);
3582
+ });
3583
+ }
3584
+ }
3585
+ function httpHeader(name, value, options) {
3586
+ const event = getRequestEvent();
3587
+ const response = event && event.response;
3588
+ if (response && !response.committed) {
3589
+ const headers = response.headers;
3590
+ const key = name.toLowerCase();
3591
+ const setCookie = key === "set-cookie";
3592
+ let ledgers = headerLedgers.get(response);
3593
+ if (!ledgers) headerLedgers.set(response, ledgers = new Map());
3594
+ let ledger = ledgers.get(key);
3595
+ if (!ledger) {
3596
+ ledger = {
3597
+ base: setCookie ? headers.getSetCookie() : headers.get(name),
3598
+ live: []
3599
+ };
3600
+ ledgers.set(key, ledger);
3601
+ }
3602
+ const declaration = {
3603
+ value,
3604
+ append: !!(options && options.append)
3605
+ };
3606
+ ledger.live.push(declaration);
3607
+ if (declaration.append) headers.append(name, value);else headers.set(name, value);
3608
+ onCleanup(() => {
3609
+ if (response.committed) return;
3610
+ const index = ledger.live.indexOf(declaration);
3611
+ if (index < 0) return;
3612
+ ledger.live.splice(index, 1);
3613
+ headers.delete(name);
3614
+ if (setCookie) {
3615
+ for (const cookie of ledger.base) headers.append(name, cookie);
3616
+ } else if (ledger.base !== null) {
3617
+ headers.set(name, ledger.base);
3618
+ }
3619
+ for (const d of ledger.live) {
3620
+ if (d.append) headers.append(name, d.value);else headers.set(name, d.value);
3621
+ }
3622
+ if (!ledger.live.length) ledgers.delete(key);
3623
+ });
3624
+ }
3625
+ }
3626
+
3627
+ 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_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, 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, hasFlashCookie, httpHeader, httpStatus, notSup as hydrate, notSup as insert, isDev, isHref, isResponseEnvelope, isSafeError, isServer, isServerFunction, markSafeError, memo, parseCookieHeader, 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, ssrGroup, ssrHydrationKey, ssrSelectValues, ssrStyle, ssrStyleProperty, notSup as style, styleNonce, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useHead };