@qwik.dev/core 2.0.0-beta.13 → 2.0.0-beta.14

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/backpatch/package.json +1 -1
  2. package/dist/build/package.json +1 -1
  3. package/dist/cli.mjs +5633 -0
  4. package/dist/core-internal.d.ts +76 -50
  5. package/dist/core.min.mjs +1 -1
  6. package/dist/core.mjs +179 -82
  7. package/dist/core.mjs.map +1 -1
  8. package/dist/core.prod.mjs +125 -71
  9. package/dist/loader/index.mjs +2 -2
  10. package/dist/loader/package.json +1 -1
  11. package/dist/optimizer.mjs +1283 -1280
  12. package/dist/qwikloader.debug.js +5 -0
  13. package/dist/qwikloader.js +1 -1
  14. package/dist/server.mjs +4 -4
  15. package/dist/starters/adapters/aws-lambda/package.json +2 -1
  16. package/dist/starters/adapters/azure-swa/package.json +2 -1
  17. package/dist/starters/adapters/bun/package.json +2 -1
  18. package/dist/starters/adapters/cloud-run/package.json +2 -1
  19. package/dist/starters/adapters/cloudflare-pages/package.json +2 -1
  20. package/dist/starters/adapters/deno/package.json +2 -1
  21. package/dist/starters/adapters/express/package.json +2 -1
  22. package/dist/starters/adapters/fastify/package.json +2 -1
  23. package/dist/starters/adapters/firebase/package.json +2 -1
  24. package/dist/starters/adapters/netlify-edge/package.json +2 -1
  25. package/dist/starters/adapters/node-server/package.json +2 -1
  26. package/dist/starters/adapters/ssg/package.json +2 -1
  27. package/dist/starters/adapters/vercel-edge/package.json +2 -1
  28. package/dist/starters/features/storybook/.storybook/tsconfig.json +0 -1
  29. package/dist/starters/features/styled-vanilla-extract/package.json +2 -1
  30. package/dist/testing/index.d.ts +2 -3
  31. package/dist/testing/index.mjs +188 -82
  32. package/dist/testing/package.json +1 -1
  33. package/package.json +14 -48
  34. package/{qwik-cli.cjs → qwik-cli.mjs} +1 -1
  35. package/dist/backpatch/index.cjs +0 -6
  36. package/dist/build/index.cjs +0 -35
  37. package/dist/build/index.cjs.map +0 -7
  38. package/dist/build/index.dev.cjs +0 -37
  39. package/dist/build/index.dev.cjs.map +0 -7
  40. package/dist/build/index.prod.cjs +0 -37
  41. package/dist/build/index.prod.cjs.map +0 -7
  42. package/dist/cli.cjs +0 -12956
  43. package/dist/core.cjs +0 -13036
  44. package/dist/core.cjs.map +0 -1
  45. package/dist/core.prod.cjs +0 -6377
  46. package/dist/insights/index.qwik.cjs +0 -1
  47. package/dist/insights/vite/index.cjs +0 -1
  48. package/dist/loader/index.cjs +0 -4
  49. package/dist/optimizer.cjs +0 -217
  50. package/dist/preloader.cjs +0 -266
  51. package/dist/server.cjs +0 -3294
  52. package/dist/testing/index.cjs +0 -36225
package/dist/server.cjs DELETED
@@ -1,3294 +0,0 @@
1
- /**
2
- * @license
3
- * @qwik.dev/core/server 2.0.0-beta.13-dev+cb19ff7
4
- * Copyright QwikDev. All Rights Reserved.
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://github.com/QwikDev/qwik/blob/main/LICENSE
7
- */
8
- globalThis.qwikServer = (function (module) {
9
-
10
- if (typeof require !== 'function' && typeof location !== 'undefined' && typeof navigator !== 'undefined') {
11
- // shim cjs require() for core.cjs within a browser
12
- globalThis.require = function(path) {
13
- if (path === './core.cjs' || path === '@qwik.dev/core') {
14
- if (!self.qwikCore) {
15
- throw new Error('Qwik Core global, "globalThis.qwikCore", must already be loaded for the Qwik Server to be used within a browser.');
16
- }
17
- return self.qwikCore;
18
- }
19
- if (path === '@qwik.dev/core/build') {
20
- if (!self.qwikBuild) {
21
- throw new Error('Qwik Build global, "globalThis.qwikBuild", must already be loaded for the Qwik Server to be used within a browser.');
22
- }
23
- return self.qwikBuild;
24
- }
25
- if (path === '@qwik-client-manifest') {
26
- return {};
27
- }
28
- throw new Error('Unable to require() path "' + path + '" from a browser environment.');
29
- };
30
- }
31
- "use strict";
32
- var __defProp = Object.defineProperty;
33
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
34
- var __getOwnPropNames = Object.getOwnPropertyNames;
35
- var __hasOwnProp = Object.prototype.hasOwnProperty;
36
- var __export = (target, all) => {
37
- for (var name in all)
38
- __defProp(target, name, { get: all[name], enumerable: true });
39
- };
40
- var __copyProps = (to, from, except, desc) => {
41
- if (from && typeof from === "object" || typeof from === "function") {
42
- for (let key of __getOwnPropNames(from))
43
- if (!__hasOwnProp.call(to, key) && key !== except)
44
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
45
- }
46
- return to;
47
- };
48
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
49
-
50
- // packages/qwik/src/server/index.ts
51
- var index_exports = {};
52
- __export(index_exports, {
53
- getQwikBackpatchExecutorScript: () => getQwikBackpatchExecutorScript,
54
- getQwikLoaderScript: () => getQwikLoaderScript,
55
- getQwikPrefetchWorkerScript: () => getQwikPrefetchWorkerScript,
56
- renderToStream: () => renderToStream,
57
- renderToString: () => renderToString,
58
- resolveManifest: () => resolveManifest,
59
- setServerPlatform: () => setServerPlatform2,
60
- versions: () => versions
61
- });
62
- module.exports = __toCommonJS(index_exports);
63
- var import_core3 = require("@qwik.dev/core");
64
-
65
- // packages/qwik/src/server/platform.ts
66
- var import_core = require("@qwik.dev/core");
67
- var import_build6 = require("@qwik.dev/core/build");
68
-
69
- // packages/qwik/src/core/shared/utils/qdev.ts
70
- var qDev = globalThis.qDev !== false;
71
- var qInspector = globalThis.qInspector === true;
72
- var qSerialize = globalThis.qSerialize !== false;
73
- var qDynamicPlatform = globalThis.qDynamicPlatform !== false;
74
- var qTest = globalThis.qTest === true;
75
- var qRuntimeQrl = globalThis.qRuntimeQrl === true;
76
-
77
- // packages/qwik/src/core/shared/utils/log.ts
78
- var STYLE = qDev ? `background: #564CE0; color: white; padding: 2px 3px; border-radius: 2px; font-size: 0.8em;` : "";
79
- var throwErrorAndStop = (message, ...optionalParams) => {
80
- const error = createAndLogError(false, message, ...optionalParams);
81
- debugger;
82
- throw error;
83
- };
84
- var logErrorAndStop = (message, ...optionalParams) => {
85
- const err = createAndLogError(qDev, message, ...optionalParams);
86
- debugger;
87
- return err;
88
- };
89
- var createAndLogError = (asyncThrow, message, ...optionalParams) => {
90
- const err = message instanceof Error ? message : new Error(message);
91
- !qTest && console.error("%cQWIK ERROR", STYLE, err.message, ...optionalParams, err.stack);
92
- asyncThrow && !qTest && setTimeout(() => {
93
- throw err;
94
- }, 0);
95
- return err;
96
- };
97
-
98
- // packages/qwik/src/core/shared/error/assert.ts
99
- var ASSERT_DISCLAIMER = "Internal assert, this is likely caused by a bug in Qwik: ";
100
- function assertTrue(value1, text, ...parts) {
101
- if (qDev) {
102
- if (value1 === true) {
103
- return;
104
- }
105
- throwErrorAndStop(ASSERT_DISCLAIMER + text, ...parts);
106
- }
107
- }
108
-
109
- // packages/qwik/src/core/client/util-mapArray.ts
110
- var mapApp_findIndx = (array, key, start) => {
111
- assertTrue(start % 2 === 0, "Expecting even number.");
112
- let bottom = start >> 1;
113
- let top = array.length - 2 >> 1;
114
- while (bottom <= top) {
115
- const mid = bottom + (top - bottom >> 1);
116
- const midKey = array[mid << 1];
117
- if (midKey === key) {
118
- return mid << 1;
119
- }
120
- if (midKey < key) {
121
- bottom = mid + 1;
122
- } else {
123
- top = mid - 1;
124
- }
125
- }
126
- return bottom << 1 ^ -1;
127
- };
128
- var mapArray_set = (array, key, value, start, allowNullValue = false) => {
129
- const indx = mapApp_findIndx(array, key, start);
130
- if (indx >= 0) {
131
- if (value == null && !allowNullValue) {
132
- array.splice(indx, 2);
133
- } else {
134
- array[indx + 1] = value;
135
- }
136
- } else if (value != null || allowNullValue) {
137
- array.splice(indx ^ -1, 0, key, value);
138
- }
139
- };
140
- var mapApp_remove = (array, key, start) => {
141
- const indx = mapApp_findIndx(array, key, start);
142
- let value = null;
143
- if (indx >= 0) {
144
- value = array[indx + 1];
145
- array.splice(indx, 2);
146
- return value;
147
- }
148
- return value;
149
- };
150
- var mapArray_get = (array, key, start) => {
151
- const indx = mapApp_findIndx(array, key, start);
152
- if (indx >= 0) {
153
- return array[indx + 1];
154
- } else {
155
- return null;
156
- }
157
- };
158
- var mapArray_has = (array, key, start) => {
159
- return mapApp_findIndx(array, key, start) >= 0;
160
- };
161
-
162
- // packages/qwik/src/core/shared/utils/types.ts
163
- var isObject = (v) => {
164
- return typeof v === "object" && v !== null;
165
- };
166
- var isArray = (v) => {
167
- return Array.isArray(v);
168
- };
169
- var isString = (v) => {
170
- return typeof v === "string";
171
- };
172
-
173
- // packages/qwik/src/core/shared/error/error.ts
174
- var codeToText = (code, ...parts) => {
175
- if (qDev) {
176
- const MAP = [
177
- "Error while serializing class or style attributes",
178
- // 0
179
- "Scheduler not found",
180
- // 1
181
- "track() received object, without prop to track",
182
- // 2
183
- "Only primitive and object literals can be serialized. {{0}}",
184
- // 3
185
- "You can render over a existing q:container. Skipping render().",
186
- // 4
187
- "QRL is not a function",
188
- // 5
189
- "Dynamic import not found",
190
- // 6
191
- "Unknown type argument",
192
- // 7
193
- `Actual value for useContext({{0}}) can not be found, make sure some ancestor component has set a value using useContextProvider(). In the browser make sure that the context was used during SSR so its state was serialized.`,
194
- // 8
195
- "Invoking 'use*()' method outside of invocation context.",
196
- // 9
197
- `Calling a 'use*()' method outside 'component$(() => { HERE })' is not allowed. 'use*()' methods provide hooks to the 'component$' state and lifecycle, ie 'use' hooks can only be called synchronously within the 'component$' function or another 'use' method.
198
- See https://qwik.dev/docs/core/tasks/#use-method-rules`,
199
- // 10
200
- 'The provided Context reference "{{0}}" is not a valid context created by createContextId()',
201
- // 11
202
- "SsrError(tag): {{0}}",
203
- // 12
204
- "QRLs can not be resolved because it does not have an attached container. This means that the QRL does not know where it belongs inside the DOM, so it cant dynamically import() from a relative path.",
205
- // 13
206
- "QRLs can not be dynamically resolved, because it does not have a chunk path",
207
- // 14
208
- "{{0}}\nThe JSX ref attribute must be a Signal",
209
- // 15
210
- "Serialization Error: Deserialization of data type {{0}} is not implemented",
211
- // 16
212
- "Serialization Error: Expected vnode for ref prop, but got {{0}}",
213
- // 17
214
- "Serialization Error: Cannot allocate data type {{0}}",
215
- // 18
216
- "Serialization Error: Missing root id for {{0}}",
217
- // 19
218
- "Serialization Error: Serialization of data type {{0}} is not implemented",
219
- // 20
220
- "Serialization Error: Unvisited {{0}}",
221
- // 21
222
- "Serialization Error: Missing QRL chunk for {{0}}",
223
- // 22
224
- "{{0}}\nThe value of the textarea must be a string found {{1}}",
225
- // 23
226
- "Unable to find q:container",
227
- // 24
228
- "Element must have 'q:container' attribute.",
229
- // 25
230
- "Unknown vnode type {{0}}.",
231
- // 26
232
- "Materialize error: missing element: {{0}} {{1}} {{2}}",
233
- // 27
234
- "Cannot coerce a Signal, use `.value` instead",
235
- // 28
236
- "useComputed$ QRL {{0}} {{1}} cannot return a Promise",
237
- // 29
238
- "ComputedSignal is read-only",
239
- // 30
240
- "WrappedSignal is read-only",
241
- // 31
242
- "Attribute value is unsafe for SSR",
243
- // 32
244
- "SerializerSymbol function returned rejected promise",
245
- // 33
246
- "Serialization Error: Cannot serialize function: {{0}}"
247
- // 34
248
- ];
249
- let text = MAP[code] ?? "";
250
- if (parts.length) {
251
- text = text.replaceAll(/{{(\d+)}}/g, (_, index) => {
252
- let v = parts[index];
253
- if (v && isObject(v) && v.constructor === Object) {
254
- v = JSON.stringify(v).slice(0, 50);
255
- }
256
- return v;
257
- });
258
- }
259
- return `Code(Q${code}): ${text}`;
260
- } else {
261
- return `Code(Q${code}) https://github.com/QwikDev/qwik/blob/main/packages/qwik/src/core/error/error.ts#L${8 + code}`;
262
- }
263
- };
264
- var qError = (code, errorMessageArgs = []) => {
265
- const text = codeToText(code, ...errorMessageArgs);
266
- return logErrorAndStop(text, ...errorMessageArgs);
267
- };
268
-
269
- // packages/qwik/src/core/shared/qrl/qrl-utils.ts
270
- var import_build = require("@qwik.dev/core/build");
271
- var SYNC_QRL = "<sync>";
272
-
273
- // packages/qwik/src/core/shared/types.ts
274
- var DEBUG_TYPE = "q:type";
275
-
276
- // packages/qwik/src/core/shared/utils/character-escaping.ts
277
- function escapeHTML(html) {
278
- let escapedHTML = "";
279
- const length = html.length;
280
- let idx = 0;
281
- let lastIdx = idx;
282
- for (; idx < length; idx++) {
283
- const ch = html.charCodeAt(idx);
284
- if (ch === 60) {
285
- escapedHTML += html.substring(lastIdx, idx) + "&lt;";
286
- } else if (ch === 62) {
287
- escapedHTML += html.substring(lastIdx, idx) + "&gt;";
288
- } else if (ch === 38) {
289
- escapedHTML += html.substring(lastIdx, idx) + "&amp;";
290
- } else if (ch === 34) {
291
- escapedHTML += html.substring(lastIdx, idx) + "&quot;";
292
- } else if (ch === 39) {
293
- escapedHTML += html.substring(lastIdx, idx) + "&#39;";
294
- } else {
295
- continue;
296
- }
297
- lastIdx = idx + 1;
298
- }
299
- if (lastIdx === 0) {
300
- return html;
301
- } else {
302
- return escapedHTML + html.substring(lastIdx);
303
- }
304
- }
305
-
306
- // packages/qwik/src/core/shared/utils/markers.ts
307
- var OnRenderProp = "q:renderFn";
308
- var QSlot = "q:slot";
309
- var QSlotParent = "q:sparent";
310
- var QStyle = "q:style";
311
- var QStyleSelector = "style[q\\:style]";
312
- var QStyleSSelector = "style[q\\:sstyle]";
313
- var QStylesAllSelector = QStyleSelector + "," + QStyleSSelector;
314
- var QScopedStyle = "q:sstyle";
315
- var QCtxAttr = "q:ctx";
316
- var QBackRefs = "q:brefs";
317
- var QRenderAttr = "q:render";
318
- var QRuntimeAttr = "q:runtime";
319
- var QVersionAttr = "q:version";
320
- var QBaseAttr = "q:base";
321
- var QLocaleAttr = "q:locale";
322
- var QManifestHashAttr = "q:manifest-hash";
323
- var QInstanceAttr = "q:instance";
324
- var QContainerIsland = "q:container-island";
325
- var QContainerIslandEnd = "/" + QContainerIsland;
326
- var QIgnore = "q:ignore";
327
- var QIgnoreEnd = "/" + QIgnore;
328
- var QContainerAttr = "q:container";
329
- var QContainerAttrEnd = "/" + QContainerAttr;
330
- var QTemplate = "q:template";
331
- var QContainerSelector = "[q\\:container]:not([q\\:container=" + "html" /* HTML */ + "]):not([q\\:container=" + "text" /* TEXT */ + "])";
332
- var QDefaultSlot = "";
333
- var ELEMENT_ID = "q:id";
334
- var ELEMENT_KEY = "q:key";
335
- var ELEMENT_PROPS = "q:props";
336
- var ELEMENT_SEQ = "q:seq";
337
- var ELEMENT_SEQ_IDX = "q:seqIdx";
338
- var ELEMENT_BACKPATCH_DATA = "qwik/backpatch";
339
- var NON_SERIALIZABLE_MARKER_PREFIX = ":";
340
- var USE_ON_LOCAL = NON_SERIALIZABLE_MARKER_PREFIX + "on";
341
- var USE_ON_LOCAL_SEQ_IDX = NON_SERIALIZABLE_MARKER_PREFIX + "onIdx";
342
- var USE_ON_LOCAL_FLAGS = NON_SERIALIZABLE_MARKER_PREFIX + "onFlags";
343
- var FLUSH_COMMENT = "qkssr-f";
344
- var STREAM_BLOCK_START_COMMENT = "qkssr-pu";
345
- var STREAM_BLOCK_END_COMMENT = "qkssr-po";
346
- var Q_PROPS_SEPARATOR = ":";
347
- var dangerouslySetInnerHTML = "dangerouslySetInnerHTML";
348
-
349
- // packages/qwik/src/core/shared/utils/promises.ts
350
- var import_build2 = require("@qwik.dev/core/build");
351
- var MAX_RETRY_ON_PROMISE_COUNT = 100;
352
- var isPromise = (value) => {
353
- return !!value && typeof value == "object" && typeof value.then === "function";
354
- };
355
- var maybeThen = (valueOrPromise, thenFn) => {
356
- return isPromise(valueOrPromise) ? valueOrPromise.then(thenFn, shouldNotError) : thenFn(valueOrPromise);
357
- };
358
- var shouldNotError = (reason) => {
359
- throwErrorAndStop(reason);
360
- };
361
- function retryOnPromise(fn, retryCount = 0) {
362
- const retryOrThrow = (e) => {
363
- if (isPromise(e) && retryCount < MAX_RETRY_ON_PROMISE_COUNT) {
364
- return e.then(retryOnPromise.bind(null, fn, retryCount++));
365
- }
366
- throw e;
367
- };
368
- try {
369
- const result = fn();
370
- if (isPromise(result)) {
371
- return result.catch((e) => retryOrThrow(e));
372
- }
373
- return result;
374
- } catch (e) {
375
- if (import_build2.isDev && import_build2.isServer && e instanceof ReferenceError && e.message.includes("window")) {
376
- e.message = 'It seems like you forgot to add "if (isBrowser) {...}" here:' + e.message;
377
- throw e;
378
- }
379
- return retryOrThrow(e);
380
- }
381
- }
382
-
383
- // packages/qwik/src/core/shared/utils/scoped-styles.ts
384
- function isClassAttr(key) {
385
- return key === "class" || key === "className";
386
- }
387
- function convertStyleIdsToString(scopedStyleIds) {
388
- return Array.from(scopedStyleIds).join(" ");
389
- }
390
-
391
- // packages/qwik/src/core/shared/utils/event-names.ts
392
- function isPreventDefault(key) {
393
- return key.startsWith("preventdefault:");
394
- }
395
-
396
- // packages/qwik/src/core/shared/utils/unitless_number.ts
397
- var unitlessNumbers = /* @__PURE__ */ new Set([
398
- "animationIterationCount",
399
- "aspectRatio",
400
- "borderImageOutset",
401
- "borderImageSlice",
402
- "borderImageWidth",
403
- "boxFlex",
404
- "boxFlexGroup",
405
- "boxOrdinalGroup",
406
- "columnCount",
407
- "columns",
408
- "flex",
409
- "flexGrow",
410
- "flexShrink",
411
- "gridArea",
412
- "gridRow",
413
- "gridRowEnd",
414
- "gridRowStart",
415
- "gridColumn",
416
- "gridColumnEnd",
417
- "gridColumnStart",
418
- "fontWeight",
419
- "lineClamp",
420
- "lineHeight",
421
- "opacity",
422
- "order",
423
- "orphans",
424
- "scale",
425
- "tabSize",
426
- "widows",
427
- "zIndex",
428
- "zoom",
429
- "MozAnimationIterationCount",
430
- // Known Prefixed Properties
431
- "MozBoxFlex",
432
- // TODO: Remove these since they shouldn't be used in modern code
433
- "msFlex",
434
- "msFlexPositive",
435
- "WebkitAnimationIterationCount",
436
- "WebkitBoxFlex",
437
- "WebkitBoxOrdinalGroup",
438
- "WebkitColumnCount",
439
- "WebkitColumns",
440
- "WebkitFlex",
441
- "WebkitFlexGrow",
442
- "WebkitFlexShrink",
443
- "WebkitLineClamp"
444
- ]);
445
- var isUnitlessNumber = (name) => {
446
- return unitlessNumbers.has(name);
447
- };
448
-
449
- // packages/qwik/src/core/shared/utils/styles.ts
450
- var serializeClass = (obj) => {
451
- if (!obj) {
452
- return "";
453
- }
454
- if (isString(obj)) {
455
- return obj.trim();
456
- }
457
- const classes = [];
458
- if (isArray(obj)) {
459
- for (const o of obj) {
460
- const classList = serializeClass(o);
461
- if (classList) {
462
- classes.push(classList);
463
- }
464
- }
465
- } else {
466
- for (const [key, value] of Object.entries(obj)) {
467
- if (value) {
468
- classes.push(key.trim());
469
- }
470
- }
471
- }
472
- return classes.join(" ");
473
- };
474
- var fromCamelToKebabCaseWithDash = (text) => {
475
- return text.replace(/([A-Z])/g, "-$1").toLowerCase();
476
- };
477
- var stringifyStyle = (obj) => {
478
- if (obj == null) {
479
- return "";
480
- }
481
- if (typeof obj == "object") {
482
- if (isArray(obj)) {
483
- throw qError(0 /* stringifyClassOrStyle */, [obj, "style"]);
484
- } else {
485
- const chunks = [];
486
- for (const key in obj) {
487
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
488
- const value = obj[key];
489
- if (value != null && typeof value !== "function") {
490
- if (key.startsWith("--")) {
491
- chunks.push(key + ":" + value);
492
- } else {
493
- chunks.push(fromCamelToKebabCaseWithDash(key) + ":" + setValueForStyle(key, value));
494
- }
495
- }
496
- }
497
- }
498
- return chunks.join(";");
499
- }
500
- }
501
- return String(obj);
502
- };
503
- var serializeBooleanOrNumberAttribute = (value) => {
504
- return value != null ? String(value) : null;
505
- };
506
- function serializeAttribute(key, value, styleScopedId) {
507
- if (isClassAttr(key)) {
508
- const serializedClass = serializeClass(value);
509
- value = styleScopedId ? styleScopedId + (serializedClass.length ? " " + serializedClass : serializedClass) : serializedClass;
510
- } else if (key === "style") {
511
- value = stringifyStyle(value);
512
- } else if (isEnumeratedBooleanAttribute(key) || typeof value === "number") {
513
- value = serializeBooleanOrNumberAttribute(value);
514
- } else if (value === false || value == null) {
515
- value = null;
516
- } else if (value === true && isPreventDefault(key)) {
517
- value = "";
518
- }
519
- return value;
520
- }
521
- function isEnumeratedBooleanAttribute(key) {
522
- return isAriaAttribute(key) || ["spellcheck", "draggable", "contenteditable"].includes(key);
523
- }
524
- var setValueForStyle = (styleName, value) => {
525
- if (typeof value === "number" && value !== 0 && !isUnitlessNumber(styleName)) {
526
- return value + "px";
527
- }
528
- return value;
529
- };
530
- function isAriaAttribute(prop) {
531
- return prop.startsWith("aria-");
532
- }
533
-
534
- // packages/qwik/src/core/shared/vnode-data-types.ts
535
- var VNodeDataSeparator = {
536
- REFERENCE_CH: (
537
- /* ***** */
538
- `~`
539
- ),
540
- // `~` is a reference to the node. Save it.
541
- REFERENCE: (
542
- /* ******** */
543
- 126
544
- ),
545
- // `~` is a reference to the node. Save it.
546
- ADVANCE_1_CH: (
547
- /* ***** */
548
- `!`
549
- ),
550
- // `!` is vNodeData separator skipping 0. (ie next vNode)
551
- ADVANCE_1: (
552
- /* ********* */
553
- 33
554
- ),
555
- // `!` is vNodeData separator skipping 0. (ie next vNode)
556
- ADVANCE_2_CH: (
557
- /* ***** */
558
- `"`
559
- ),
560
- // `"` is vNodeData separator skipping 1.
561
- ADVANCE_2: (
562
- /* ********* */
563
- 34
564
- ),
565
- // `"` is vNodeData separator skipping 1.
566
- ADVANCE_4_CH: (
567
- /* ***** */
568
- `#`
569
- ),
570
- // `#` is vNodeData separator skipping 2.
571
- ADVANCE_4: (
572
- /* ********* */
573
- 35
574
- ),
575
- // `#` is vNodeData separator skipping 2.
576
- ADVANCE_8_CH: (
577
- /* ***** */
578
- `$`
579
- ),
580
- // `$` is vNodeData separator skipping 4.
581
- ADVANCE_8: (
582
- /* ********* */
583
- 36
584
- ),
585
- // `$` is vNodeData separator skipping 4.
586
- ADVANCE_16_CH: (
587
- /* **** */
588
- `%`
589
- ),
590
- // `%` is vNodeData separator skipping 8.
591
- ADVANCE_16: (
592
- /* ******** */
593
- 37
594
- ),
595
- // `%` is vNodeData separator skipping 8.
596
- ADVANCE_32_CH: (
597
- /* **** */
598
- `&`
599
- ),
600
- // `&` is vNodeData separator skipping 16.
601
- ADVANCE_32: (
602
- /* ******** */
603
- 38
604
- ),
605
- // `&` is vNodeData separator skipping 16.
606
- ADVANCE_64_CH: (
607
- /* **** */
608
- `'`
609
- ),
610
- // `'` is vNodeData separator skipping 32.
611
- ADVANCE_64: (
612
- /* ******** */
613
- 39
614
- ),
615
- // `'` is vNodeData separator skipping 32.
616
- ADVANCE_128_CH: (
617
- /* *** */
618
- `(`
619
- ),
620
- // `(` is vNodeData separator skipping 64.
621
- ADVANCE_128: (
622
- /* ******* */
623
- 40
624
- ),
625
- // `(` is vNodeData separator skipping 64.
626
- ADVANCE_256_CH: (
627
- /* *** */
628
- `)`
629
- ),
630
- // `)` is vNodeData separator skipping 128.
631
- ADVANCE_256: (
632
- /* ******* */
633
- 41
634
- ),
635
- // `)` is vNodeData separator skipping 128.
636
- ADVANCE_512_CH: (
637
- /* *** */
638
- `*`
639
- ),
640
- // `*` is vNodeData separator skipping 256.
641
- ADVANCE_512: (
642
- /* ******* */
643
- 42
644
- ),
645
- // `*` is vNodeData separator skipping 256.
646
- ADVANCE_1024_CH: (
647
- /* ** */
648
- `+`
649
- ),
650
- // `+` is vNodeData separator skipping 512.
651
- ADVANCE_1024: (
652
- /* ****** */
653
- 43
654
- ),
655
- // `+` is vNodeData separator skipping 512.
656
- ADVANCE_2048_CH: (
657
- /* * */
658
- ","
659
- ),
660
- // ',' is vNodeData separator skipping 1024.
661
- ADVANCE_2048: (
662
- /* ****** */
663
- 44
664
- ),
665
- // ',' is vNodeData separator skipping 1024.
666
- ADVANCE_4096_CH: (
667
- /* * */
668
- `-`
669
- ),
670
- // `-` is vNodeData separator skipping 2048.
671
- ADVANCE_4096: (
672
- /* ****** */
673
- 45
674
- ),
675
- // `-` is vNodeData separator skipping 2048.
676
- ADVANCE_8192_CH: (
677
- /* * */
678
- `.`
679
- ),
680
- // `.` is vNodeData separator skipping 4096.
681
- ADVANCE_8192: (
682
- /* ****** */
683
- 46
684
- )
685
- // `.` is vNodeData separator skipping 4096.
686
- };
687
- var VNodeDataChar = {
688
- OPEN: (
689
- /* ************** */
690
- 123
691
- ),
692
- // `{` is the start of the VNodeData for a virtual element.
693
- OPEN_CHAR: (
694
- /* ****** */
695
- "{"
696
- ),
697
- CLOSE: (
698
- /* ************* */
699
- 125
700
- ),
701
- // `}` is the end of the VNodeData for a virtual element.
702
- CLOSE_CHAR: (
703
- /* ***** */
704
- "}"
705
- ),
706
- SCOPED_STYLE: (
707
- /* ******* */
708
- 59
709
- ),
710
- // `;` - `q:sstyle` - Style attribute.
711
- SCOPED_STYLE_CHAR: (
712
- /* */
713
- ";"
714
- ),
715
- RENDER_FN: (
716
- /* ********** */
717
- 60
718
- ),
719
- // `<` - `q:renderFn' - Component QRL render function (body)
720
- RENDER_FN_CHAR: (
721
- /* ** */
722
- "<"
723
- ),
724
- ID: (
725
- /* ***************** */
726
- 61
727
- ),
728
- // `=` - `q:id` - ID of the element.
729
- ID_CHAR: (
730
- /* ********* */
731
- "="
732
- ),
733
- PROPS: (
734
- /* ************** */
735
- 62
736
- ),
737
- // `>` - `q:props' - Component Props
738
- PROPS_CHAR: (
739
- /* ****** */
740
- ">"
741
- ),
742
- SLOT_PARENT: (
743
- /* ******** */
744
- 63
745
- ),
746
- // `?` - `q:sparent` - Slot parent.
747
- SLOT_PARENT_CHAR: (
748
- /* */
749
- "?"
750
- ),
751
- KEY: (
752
- /* **************** */
753
- 64
754
- ),
755
- // `@` - `q:key` - Element key.
756
- KEY_CHAR: (
757
- /* ******** */
758
- "@"
759
- ),
760
- SEQ: (
761
- /* **************** */
762
- 91
763
- ),
764
- // `[` - `q:seq' - Seq value from `useSequentialScope()`
765
- SEQ_CHAR: (
766
- /* ******** */
767
- "["
768
- ),
769
- DON_T_USE: (
770
- /* ********** */
771
- 92
772
- ),
773
- // `\` - SKIP because `\` is used as escaping
774
- DON_T_USE_CHAR: "\\",
775
- CONTEXT: (
776
- /* ************ */
777
- 93
778
- ),
779
- // `]` - `q:ctx' - Component context/props
780
- CONTEXT_CHAR: (
781
- /* **** */
782
- "]"
783
- ),
784
- SEQ_IDX: (
785
- /* ************ */
786
- 94
787
- ),
788
- // `^` - `q:seqIdx' - Sequential scope id
789
- SEQ_IDX_CHAR: (
790
- /* **** */
791
- "^"
792
- ),
793
- BACK_REFS: (
794
- /* ********** */
795
- 96
796
- ),
797
- // '`' - `q:brefs' - Effect dependencies/subscriptions
798
- BACK_REFS_CHAR: (
799
- /* ** */
800
- "`"
801
- ),
802
- SEPARATOR: (
803
- /* ********* */
804
- 124
805
- ),
806
- // `|` - Separator char to encode any key/value pairs.
807
- SEPARATOR_CHAR: (
808
- /* ** */
809
- "|"
810
- ),
811
- SLOT: (
812
- /* ************** */
813
- 126
814
- ),
815
- // `~` - `q:slot' - Slot name
816
- SLOT_CHAR: (
817
- /* ******* */
818
- "~"
819
- )
820
- };
821
-
822
- // packages/qwik/src/core/preloader/queue.ts
823
- var import_build5 = require("@qwik.dev/core/build");
824
-
825
- // packages/qwik/src/core/preloader/bundle-graph.ts
826
- var import_build4 = require("@qwik.dev/core/build");
827
-
828
- // packages/qwik/src/core/preloader/constants.ts
829
- var import_build3 = require("@qwik.dev/core/build");
830
- var doc = import_build3.isBrowser ? document : void 0;
831
- var config = {
832
- $DEBUG$: false,
833
- $maxIdlePreloads$: 25,
834
- $invPreloadProbability$: 0.65
835
- };
836
- var rel = import_build3.isBrowser && doc.createElement("link").relList.supports("modulepreload") ? "modulePreload" : "preload";
837
- var loadStart = Date.now();
838
- var isJSRegex = /\.[mc]?js$/;
839
-
840
- // packages/qwik/src/core/preloader/types.ts
841
- var BundleImportState_None = 0;
842
- var BundleImportState_Queued = 1;
843
- var BundleImportState_Preload = 2;
844
- var BundleImportState_Alias = 3;
845
- var BundleImportState_Loaded = 4;
846
-
847
- // packages/qwik/src/core/preloader/bundle-graph.ts
848
- var base;
849
- var graph;
850
- var makeBundle = (name, deps) => {
851
- return {
852
- $name$: name,
853
- $state$: isJSRegex.test(name) ? BundleImportState_None : BundleImportState_Alias,
854
- $deps$: shouldResetFactor ? deps == null ? void 0 : deps.map((d) => ({ ...d, $factor$: 1 })) : deps,
855
- $inverseProbability$: 1,
856
- $createdTs$: Date.now(),
857
- $waitedMs$: 0,
858
- $loadedMs$: 0
859
- };
860
- };
861
- var parseBundleGraph = (serialized) => {
862
- const graph2 = /* @__PURE__ */ new Map();
863
- let i = 0;
864
- while (i < serialized.length) {
865
- const name = serialized[i++];
866
- const deps = [];
867
- let idx;
868
- let probability = 1;
869
- while (idx = serialized[i], typeof idx === "number") {
870
- if (idx < 0) {
871
- probability = -idx / 10;
872
- } else {
873
- deps.push({
874
- $name$: serialized[idx],
875
- $importProbability$: probability,
876
- $factor$: 1
877
- });
878
- }
879
- i++;
880
- }
881
- graph2.set(name, deps);
882
- }
883
- return graph2;
884
- };
885
- var getBundle = (name) => {
886
- let bundle = bundles.get(name);
887
- if (!bundle) {
888
- let deps;
889
- if (graph) {
890
- deps = graph.get(name);
891
- if (!deps) {
892
- return;
893
- }
894
- if (!deps.length) {
895
- deps = void 0;
896
- }
897
- }
898
- bundle = makeBundle(name, deps);
899
- bundles.set(name, bundle);
900
- }
901
- return bundle;
902
- };
903
- var initPreloader = (serializedBundleGraph, opts) => {
904
- if (opts) {
905
- if ("debug" in opts) {
906
- config.$DEBUG$ = !!opts.debug;
907
- }
908
- if (typeof opts.preloadProbability === "number") {
909
- config.$invPreloadProbability$ = 1 - opts.preloadProbability;
910
- }
911
- }
912
- if (base != null || !serializedBundleGraph) {
913
- return;
914
- }
915
- base = "";
916
- graph = parseBundleGraph(serializedBundleGraph);
917
- };
918
-
919
- // packages/qwik/src/core/preloader/queue.ts
920
- var bundles = /* @__PURE__ */ new Map();
921
- var shouldResetFactor;
922
- var queueDirty;
923
- var preloadCount = 0;
924
- var queue = [];
925
- var log = (...args) => {
926
- console.log(
927
- `Preloader ${Date.now() - loadStart}ms ${preloadCount}/${queue.length} queued>`,
928
- ...args
929
- );
930
- };
931
- var resetQueue = () => {
932
- bundles.clear();
933
- queueDirty = false;
934
- shouldResetFactor = true;
935
- preloadCount = 0;
936
- queue.length = 0;
937
- };
938
- var sortQueue = () => {
939
- if (queueDirty) {
940
- queue.sort((a, b) => a.$inverseProbability$ - b.$inverseProbability$);
941
- queueDirty = false;
942
- }
943
- };
944
- var getQueue = () => {
945
- sortQueue();
946
- let probability = 0.4;
947
- const result = [];
948
- for (const b of queue) {
949
- const nextProbability = Math.round((1 - b.$inverseProbability$) * 10);
950
- if (nextProbability !== probability) {
951
- probability = nextProbability;
952
- result.push(probability);
953
- }
954
- result.push(b.$name$);
955
- }
956
- return result;
957
- };
958
- var trigger = () => {
959
- if (!queue.length) {
960
- return;
961
- }
962
- sortQueue();
963
- while (queue.length) {
964
- const bundle = queue[0];
965
- const inverseProbability = bundle.$inverseProbability$;
966
- const probability = 1 - inverseProbability;
967
- const allowedPreloads = graph ? config.$maxIdlePreloads$ : (
968
- // While the graph is not available, we limit to 5 preloads
969
- 5
970
- );
971
- if (probability >= 0.99 || preloadCount < allowedPreloads) {
972
- queue.shift();
973
- preloadOne(bundle);
974
- } else {
975
- break;
976
- }
977
- }
978
- if (config.$DEBUG$ && !queue.length) {
979
- const loaded = [...bundles.values()].filter((b) => b.$state$ > BundleImportState_None);
980
- const waitTime = loaded.reduce((acc, b) => acc + b.$waitedMs$, 0);
981
- const loadTime = loaded.reduce((acc, b) => acc + b.$loadedMs$, 0);
982
- log(
983
- `>>>> done ${loaded.length}/${bundles.size} total: ${waitTime}ms waited, ${loadTime}ms loaded`
984
- );
985
- }
986
- };
987
- var preloadOne = (bundle) => {
988
- if (bundle.$state$ >= BundleImportState_Preload) {
989
- return;
990
- }
991
- preloadCount++;
992
- const start = Date.now();
993
- bundle.$waitedMs$ = start - bundle.$createdTs$;
994
- bundle.$state$ = BundleImportState_Preload;
995
- config.$DEBUG$ && log(
996
- `<< load ${Math.round((1 - bundle.$inverseProbability$) * 100)}% after ${`${bundle.$waitedMs$}ms`}`,
997
- bundle.$name$
998
- );
999
- const link = doc.createElement("link");
1000
- link.href = new URL(`${base}${bundle.$name$}`, doc.baseURI).toString();
1001
- link.rel = rel;
1002
- link.as = "script";
1003
- link.onload = link.onerror = () => {
1004
- preloadCount--;
1005
- const end = Date.now();
1006
- bundle.$loadedMs$ = end - start;
1007
- bundle.$state$ = BundleImportState_Loaded;
1008
- config.$DEBUG$ && log(`>> done after ${bundle.$loadedMs$}ms`, bundle.$name$);
1009
- link.remove();
1010
- trigger();
1011
- };
1012
- doc.head.appendChild(link);
1013
- };
1014
- var adjustProbabilities = (bundle, newInverseProbability, seen) => {
1015
- if (seen == null ? void 0 : seen.has(bundle)) {
1016
- return;
1017
- }
1018
- const previousInverseProbability = bundle.$inverseProbability$;
1019
- bundle.$inverseProbability$ = newInverseProbability;
1020
- if (previousInverseProbability - bundle.$inverseProbability$ < 0.01) {
1021
- return;
1022
- }
1023
- if (
1024
- // don't queue until we have initialized the preloader
1025
- base != null && bundle.$state$ < BundleImportState_Preload
1026
- ) {
1027
- if (bundle.$state$ === BundleImportState_None) {
1028
- bundle.$state$ = BundleImportState_Queued;
1029
- queue.push(bundle);
1030
- config.$DEBUG$ && log(`queued ${Math.round((1 - bundle.$inverseProbability$) * 100)}%`, bundle.$name$);
1031
- }
1032
- queueDirty = true;
1033
- }
1034
- if (bundle.$deps$) {
1035
- seen ||= /* @__PURE__ */ new Set();
1036
- seen.add(bundle);
1037
- const probability = 1 - bundle.$inverseProbability$;
1038
- for (const dep of bundle.$deps$) {
1039
- const depBundle = getBundle(dep.$name$);
1040
- if (depBundle.$inverseProbability$ === 0) {
1041
- continue;
1042
- }
1043
- let newInverseProbability2;
1044
- if (probability === 1 || probability >= 0.99 && depsCount < 100) {
1045
- depsCount++;
1046
- newInverseProbability2 = Math.min(0.01, 1 - dep.$importProbability$);
1047
- } else {
1048
- const newInverseImportProbability = 1 - dep.$importProbability$ * probability;
1049
- const prevAdjust = dep.$factor$;
1050
- const factor = newInverseImportProbability / prevAdjust;
1051
- newInverseProbability2 = Math.max(0.02, depBundle.$inverseProbability$ * factor);
1052
- dep.$factor$ = factor;
1053
- }
1054
- adjustProbabilities(depBundle, newInverseProbability2, seen);
1055
- }
1056
- }
1057
- };
1058
- var handleBundle = (name, inverseProbability) => {
1059
- const bundle = getBundle(name);
1060
- if (bundle && bundle.$inverseProbability$ > inverseProbability) {
1061
- adjustProbabilities(bundle, inverseProbability);
1062
- }
1063
- };
1064
- var depsCount;
1065
- var preload = (name, probability) => {
1066
- if (!(name == null ? void 0 : name.length)) {
1067
- return;
1068
- }
1069
- depsCount = 0;
1070
- let inverseProbability = probability ? 1 - probability : 0.4;
1071
- if (Array.isArray(name)) {
1072
- for (let i = name.length - 1; i >= 0; i--) {
1073
- const item = name[i];
1074
- if (typeof item === "number") {
1075
- inverseProbability = 1 - item / 10;
1076
- } else {
1077
- handleBundle(item, inverseProbability);
1078
- }
1079
- }
1080
- } else {
1081
- handleBundle(name, inverseProbability);
1082
- }
1083
- if (import_build5.isBrowser) {
1084
- trigger();
1085
- }
1086
- };
1087
- if (import_build5.isBrowser) {
1088
- document.addEventListener("qsymbol", (ev) => {
1089
- const { symbol, href } = ev.detail;
1090
- if (href) {
1091
- const hash2 = symbol.slice(symbol.lastIndexOf("_") + 1);
1092
- preload(hash2, 1);
1093
- }
1094
- });
1095
- }
1096
-
1097
- // packages/qwik/src/server/platform.ts
1098
- var import_meta = {};
1099
- var getDevSegmentPath = (mapper, hash2, symbolName, parent) => {
1100
- const existing = mapper == null ? void 0 : mapper[hash2];
1101
- if (existing) {
1102
- return existing;
1103
- }
1104
- if (symbolName === SYNC_QRL) {
1105
- return [symbolName, ""];
1106
- }
1107
- if (!parent) {
1108
- if (symbolName.startsWith("_") && symbolName.length < 6) {
1109
- return [symbolName, `${globalThis.BASE_URL}@qwik-handlers`];
1110
- }
1111
- console.error("qwik symbolMapper: unknown qrl requested without parent:", symbolName);
1112
- return [symbolName, `${globalThis.BASE_URL}${symbolName}.js`];
1113
- }
1114
- const qrlFile = `${globalThis.BASE_URL}${parent.startsWith("/") ? parent.slice(1) : parent}_${symbolName}.js`;
1115
- return [symbolName, qrlFile];
1116
- };
1117
- function createPlatform(opts, resolvedManifest) {
1118
- const mapper = resolvedManifest == null ? void 0 : resolvedManifest.mapper;
1119
- const mapperFn = opts.symbolMapper ? opts.symbolMapper : (symbolName, _chunk, parent) => {
1120
- var _a;
1121
- if (mapper || import_build6.isDev && import_meta.env.MODE !== "test") {
1122
- const hash2 = getSymbolHash(symbolName);
1123
- const result = !import_build6.isDev ? mapper[hash2] : getDevSegmentPath(mapper, hash2, symbolName, parent);
1124
- if (!result) {
1125
- if (hash2 === SYNC_QRL) {
1126
- return [hash2, ""];
1127
- }
1128
- const isRegistered = (_a = globalThis.__qwik_reg_symbols) == null ? void 0 : _a.has(hash2);
1129
- if (isRegistered) {
1130
- return [symbolName, "_"];
1131
- }
1132
- console.error("Cannot resolve symbol", symbolName, "in", mapper, parent);
1133
- }
1134
- return result;
1135
- }
1136
- };
1137
- const serverPlatform = {
1138
- isServer: true,
1139
- async importSymbol(_containerEl, url, symbolName) {
1140
- var _a;
1141
- const hash2 = getSymbolHash(symbolName);
1142
- const regSym = (_a = globalThis.__qwik_reg_symbols) == null ? void 0 : _a.get(hash2);
1143
- if (regSym) {
1144
- return regSym;
1145
- }
1146
- let modulePath = String(url);
1147
- if (!modulePath.endsWith(".js")) {
1148
- modulePath += ".js";
1149
- }
1150
- const module2 = require(modulePath);
1151
- if (!(symbolName in module2)) {
1152
- throw new Error(`Q-ERROR: missing symbol '${symbolName}' in module '${modulePath}'.`);
1153
- }
1154
- return module2[symbolName];
1155
- },
1156
- raf: () => {
1157
- console.error("server can not rerender");
1158
- return Promise.resolve();
1159
- },
1160
- chunkForSymbol(symbolName, _chunk, parent) {
1161
- return mapperFn(symbolName, mapper, parent);
1162
- }
1163
- };
1164
- return serverPlatform;
1165
- }
1166
- async function setServerPlatform(opts, manifest) {
1167
- const platform = createPlatform(opts, manifest);
1168
- (0, import_core.setPlatform)(platform);
1169
- }
1170
- var getSymbolHash = (symbolName) => {
1171
- const index = symbolName.lastIndexOf("_");
1172
- if (index > -1) {
1173
- return symbolName.slice(index + 1);
1174
- }
1175
- return symbolName;
1176
- };
1177
-
1178
- // packages/qwik/src/server/utils.ts
1179
- function createTimer() {
1180
- if (typeof performance === "undefined") {
1181
- return () => 0;
1182
- }
1183
- const start = performance.now();
1184
- return () => {
1185
- const end = performance.now();
1186
- const delta = end - start;
1187
- return delta / 1e6;
1188
- };
1189
- }
1190
- function getBuildBase(opts) {
1191
- let base2 = opts.base;
1192
- if (typeof opts.base === "function") {
1193
- base2 = opts.base(opts);
1194
- }
1195
- if (typeof base2 === "string") {
1196
- if (!base2.endsWith("/")) {
1197
- base2 += "/";
1198
- }
1199
- return base2;
1200
- }
1201
- return `${globalThis.BASE_URL || "/"}build/`;
1202
- }
1203
- var versions = {
1204
- qwik: "2.0.0-beta.13-dev+cb19ff7",
1205
- qwikDom: "2.1.19"
1206
- };
1207
-
1208
- // packages/qwik/src/server/ssr-container.ts
1209
- var import_build8 = require("@qwik.dev/core/build");
1210
- var import_internal2 = require("@qwik.dev/core/internal");
1211
-
1212
- // packages/qwik/src/server/preload-strategy.ts
1213
- var import_core2 = require("@qwik.dev/core");
1214
-
1215
- // packages/qwik/src/server/preload-utils.ts
1216
- function flattenPrefetchResources(prefetchResources) {
1217
- const urls = [];
1218
- const addPrefetchResource = (prefetchResources2) => {
1219
- if (prefetchResources2) {
1220
- for (const prefetchResource of prefetchResources2) {
1221
- if (!urls.includes(prefetchResource.url)) {
1222
- urls.push(prefetchResource.url);
1223
- if (prefetchResource.imports) {
1224
- addPrefetchResource(prefetchResource.imports);
1225
- }
1226
- }
1227
- }
1228
- }
1229
- };
1230
- addPrefetchResource(prefetchResources);
1231
- return urls;
1232
- }
1233
-
1234
- // packages/qwik/src/server/preload-strategy.ts
1235
- var getBundles = (qrls) => {
1236
- const platform = (0, import_core2.getPlatform)();
1237
- return qrls == null ? void 0 : qrls.map((qrl) => {
1238
- var _a;
1239
- const symbol = qrl.$symbol$;
1240
- const chunk = qrl.$chunk$;
1241
- const result = platform.chunkForSymbol(symbol, chunk, (_a = qrl.dev) == null ? void 0 : _a.file);
1242
- if (result) {
1243
- return result[1];
1244
- }
1245
- return chunk;
1246
- }).filter(Boolean);
1247
- };
1248
- function getPreloadPaths(qrls, opts, resolvedManifest) {
1249
- const prefetchStrategy = opts.prefetchStrategy;
1250
- if (prefetchStrategy === null) {
1251
- return [];
1252
- }
1253
- if (!(resolvedManifest == null ? void 0 : resolvedManifest.manifest.bundleGraph)) {
1254
- return getBundles(qrls);
1255
- }
1256
- if (typeof (prefetchStrategy == null ? void 0 : prefetchStrategy.symbolsToPrefetch) === "function") {
1257
- try {
1258
- const prefetchResources = prefetchStrategy.symbolsToPrefetch({
1259
- manifest: resolvedManifest.manifest
1260
- });
1261
- return flattenPrefetchResources(prefetchResources);
1262
- } catch (e) {
1263
- console.error("getPrefetchUrls, symbolsToPrefetch()", e);
1264
- }
1265
- }
1266
- const symbols = /* @__PURE__ */ new Set();
1267
- for (const qrl of qrls) {
1268
- const symbol = getSymbolHash(qrl.$symbol$);
1269
- if (symbol && symbol.length >= 10) {
1270
- symbols.add(symbol);
1271
- }
1272
- }
1273
- return [...symbols];
1274
- }
1275
- var expandBundles = (names, resolvedManifest) => {
1276
- if (!(resolvedManifest == null ? void 0 : resolvedManifest.manifest.bundleGraph)) {
1277
- return [...new Set(names)];
1278
- }
1279
- resetQueue();
1280
- let probability = 0.99;
1281
- for (const name of names) {
1282
- preload(name, probability);
1283
- probability *= 0.95;
1284
- }
1285
- return getQueue();
1286
- };
1287
-
1288
- // packages/qwik/src/server/preload-impl.ts
1289
- var simplifyPath = (base2, path) => {
1290
- if (path == null) {
1291
- return null;
1292
- }
1293
- const segments = `${base2}${path}`.split("/");
1294
- const simplified = [];
1295
- for (const segment of segments) {
1296
- if (segment === ".." && simplified.length > 0) {
1297
- simplified.pop();
1298
- } else {
1299
- simplified.push(segment);
1300
- }
1301
- }
1302
- return simplified.join("/");
1303
- };
1304
- var getBase = (container) => {
1305
- let base2 = container.$buildBase$;
1306
- if (false) {
1307
- base2 = globalThis.BASE_URL;
1308
- }
1309
- return base2;
1310
- };
1311
- var preloaderPre = (container, options, nonce) => {
1312
- var _a, _b;
1313
- const { resolvedManifest } = container;
1314
- const base2 = getBase(container);
1315
- const preloaderBundle = simplifyPath(base2, (_a = resolvedManifest == null ? void 0 : resolvedManifest.manifest) == null ? void 0 : _a.preloader);
1316
- let bundleGraphPath = resolvedManifest == null ? void 0 : resolvedManifest.manifest.bundleGraphAsset;
1317
- if (bundleGraphPath) {
1318
- bundleGraphPath = (globalThis.BASE_URL || "/") + bundleGraphPath;
1319
- }
1320
- if (preloaderBundle && bundleGraphPath && options !== false) {
1321
- const preloaderOpts = typeof options === "object" ? {
1322
- debug: options.debug,
1323
- preloadProbability: options.ssrPreloadProbability
1324
- } : void 0;
1325
- const bundleGraph = (_b = container.resolvedManifest) == null ? void 0 : _b.manifest.bundleGraph;
1326
- initPreloader(bundleGraph, preloaderOpts);
1327
- const opts = [];
1328
- if (options) {
1329
- if (options.debug) {
1330
- opts.push("d:1");
1331
- }
1332
- if (options.maxIdlePreloads) {
1333
- opts.push(`P:${options.maxIdlePreloads}`);
1334
- }
1335
- if (options.preloadProbability) {
1336
- opts.push(`Q:${options.preloadProbability}`);
1337
- }
1338
- }
1339
- const optsStr = opts.length ? `,{${opts.join(",")}}` : "";
1340
- const preloaderLinkAttrs = ["rel", "modulepreload", "href", preloaderBundle];
1341
- if (nonce) {
1342
- preloaderLinkAttrs.push("nonce", nonce);
1343
- }
1344
- container.openElement("link", null, preloaderLinkAttrs);
1345
- container.closeElement();
1346
- container.openElement("link", null, [
1347
- "rel",
1348
- "preload",
1349
- "href",
1350
- bundleGraphPath,
1351
- "as",
1352
- "fetch",
1353
- "crossorigin",
1354
- "anonymous"
1355
- ]);
1356
- container.closeElement();
1357
- const script = `let b=fetch("${bundleGraphPath}");import("${preloaderBundle}").then(({l})=>l(${JSON.stringify(base2)},b${optsStr}));`;
1358
- const scriptAttrs = ["type", "module", "async", true];
1359
- if (nonce) {
1360
- scriptAttrs.push("nonce", nonce);
1361
- }
1362
- container.openElement("script", null, scriptAttrs);
1363
- container.write(script);
1364
- container.closeElement();
1365
- }
1366
- const corePath = simplifyPath(base2, resolvedManifest == null ? void 0 : resolvedManifest.manifest.core);
1367
- if (corePath) {
1368
- const linkAttrs = ["rel", "modulepreload", "href", corePath];
1369
- if (nonce) {
1370
- linkAttrs.push("nonce", nonce);
1371
- }
1372
- container.openElement("link", null, linkAttrs);
1373
- container.closeElement();
1374
- }
1375
- };
1376
- var includePreloader = (container, options, referencedBundles, nonce) => {
1377
- if (referencedBundles.length === 0 || options === false) {
1378
- return null;
1379
- }
1380
- const { ssrPreloads, ssrPreloadProbability } = normalizePreLoaderOptions(
1381
- typeof options === "boolean" ? void 0 : options
1382
- );
1383
- let allowed = ssrPreloads;
1384
- const base2 = getBase(container);
1385
- const links = [];
1386
- const { resolvedManifest } = container;
1387
- if (allowed) {
1388
- const preloaderBundle2 = resolvedManifest == null ? void 0 : resolvedManifest.manifest.preloader;
1389
- const coreBundle = resolvedManifest == null ? void 0 : resolvedManifest.manifest.core;
1390
- const expandedBundles = expandBundles(referencedBundles, resolvedManifest);
1391
- let probability = 4;
1392
- const tenXMinProbability = ssrPreloadProbability * 10;
1393
- for (const hrefOrProbability of expandedBundles) {
1394
- if (typeof hrefOrProbability === "string") {
1395
- if (probability < tenXMinProbability) {
1396
- break;
1397
- }
1398
- if (hrefOrProbability === preloaderBundle2 || hrefOrProbability === coreBundle) {
1399
- continue;
1400
- }
1401
- links.push(hrefOrProbability);
1402
- if (--allowed === 0) {
1403
- break;
1404
- }
1405
- } else {
1406
- probability = hrefOrProbability;
1407
- }
1408
- }
1409
- }
1410
- const preloaderBundle = simplifyPath(base2, resolvedManifest == null ? void 0 : resolvedManifest.manifest.preloader);
1411
- const insertLinks = links.length ? (
1412
- /**
1413
- * We only use modulepreload links because they behave best. Older browsers can rely on the
1414
- * preloader which does feature detection and which will be available soon after inserting these
1415
- * links.
1416
- */
1417
- `${JSON.stringify(links)}.map((l,e)=>{e=document.createElement('link');e.rel='modulepreload';e.href=${JSON.stringify(base2)}+l;document.head.appendChild(e)});`
1418
- ) : "";
1419
- let script = insertLinks;
1420
- if (preloaderBundle) {
1421
- script += `window.addEventListener('load',f=>{f=_=>import("${preloaderBundle}").then(({p})=>p(${JSON.stringify(referencedBundles)}));try{requestIdleCallback(f,{timeout:2000})}catch(e){setTimeout(f,200)}})`;
1422
- }
1423
- if (script) {
1424
- const attrs = ["type", "module", "async", true, "q:type", "preload"];
1425
- if (nonce) {
1426
- attrs.push("nonce", nonce);
1427
- }
1428
- container.openElement("script", null, attrs);
1429
- container.write(script);
1430
- container.closeElement();
1431
- }
1432
- return null;
1433
- };
1434
- var preloaderPost = (ssrContainer, opts, nonce) => {
1435
- if (opts.preloader !== false) {
1436
- const qrls = Array.from(ssrContainer.serializationCtx.$eventQrls$);
1437
- const preloadBundles = getPreloadPaths(qrls, opts, ssrContainer.resolvedManifest);
1438
- if (preloadBundles.length > 0) {
1439
- includePreloader(ssrContainer, opts.preloader, preloadBundles, nonce);
1440
- }
1441
- }
1442
- };
1443
- function normalizePreLoaderOptions(input) {
1444
- return { ...preLoaderOptionsDefault, ...input };
1445
- }
1446
- var preLoaderOptionsDefault = {
1447
- ssrPreloads: 7,
1448
- ssrPreloadProbability: 0.5,
1449
- debug: false,
1450
- maxIdlePreloads: 25,
1451
- preloadProbability: 0.35
1452
- // deprecated
1453
- };
1454
-
1455
- // packages/qwik/src/server/scripts.ts
1456
- var QWIK_LOADER_DEFAULT_MINIFIED = 'const t=document,e=window,n=new Set,o=new Set([t]);let r;const s=(t,e)=>Array.from(t.querySelectorAll(e)),a=t=>{const e=[];return o.forEach(n=>e.push(...s(n,t))),e},i=t=>{m(t),s(t,"[q\\\\:shadowroot]").forEach(t=>{const e=t.shadowRoot;e&&i(e)})},c=t=>t&&"function"==typeof t.then,l=(t,e,n=e.type)=>{a("[on"+t+"\\\\:"+n+"]").forEach(o=>{u(o,t,e,n)})},f=e=>{if(void 0===e._qwikjson_){let n=(e===t.documentElement?t.body:e).lastElementChild;for(;n;){if("SCRIPT"===n.tagName&&"qwik/json"===n.getAttribute("type")){e._qwikjson_=JSON.parse(n.textContent.replace(/\\\\x3C(\\/?script)/gi,"<$1"));break}n=n.previousElementSibling}}},p=(t,e)=>new CustomEvent(t,{detail:e}),u=async(e,n,o,r=o.type)=>{const s="on"+n+":"+r;e.hasAttribute("preventdefault:"+r)&&o.preventDefault(),e.hasAttribute("stoppropagation:"+r)&&o.stopPropagation();const a=e._qc_,i=a&&a.li.filter(t=>t[0]===s);if(i&&i.length>0){for(const t of i){const n=t[1].getFn([e,o],()=>e.isConnected)(o,e),r=o.cancelBubble;c(n)&&await n,r&&o.stopPropagation()}return}const l=e.getAttribute(s),p=e.qDispatchEvent;if(p)return p(o,n);if(l){const n=e.closest("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])"),r=n.getAttribute("q:base"),s=n.getAttribute("q:version")||"unknown",a=n.getAttribute("q:manifest-hash")||"dev",i=new URL(r,t.baseURI);for(const p of l.split("\\n")){const l=new URL(p,i),u=l.href,q=l.hash.replace(/^#?([^?[|]*).*$/,"$1")||"default",h=performance.now();let _,d,y;const g=p.startsWith("#"),m={qBase:r,qManifest:a,qVersion:s,href:u,symbol:q,element:e,reqTime:h};if(g){const e=n.getAttribute("q:instance");_=(t["qFuncs_"+e]||[])[Number.parseInt(q)],_||(d="sync",y=Error("sym:"+q))}else{b("qsymbol",m);const t=l.href.split("#")[0];try{const e=import(t);f(n),_=(await e)[q],_||(d="no-symbol",y=Error(`${q} not in ${t}`))}catch(t){d||(d="async"),y=t}}if(!_){b("qerror",{importError:d,error:y,...m}),console.error(y);break}const w=t.__q_context__;if(e.isConnected)try{t.__q_context__=[e,o,l];const n=_(o,e);c(n)&&await n}catch(t){b("qerror",{error:t,...m})}finally{t.__q_context__=w}}}},b=(e,n)=>{t.dispatchEvent(p(e,n))},q=t=>t.replace(/([A-Z-])/g,t=>"-"+t.toLowerCase()),h=async t=>{let e=q(t.type),n=t.target;for(l("-document",t,e);n&&n.getAttribute;){const o=u(n,"",t,e);let r=t.cancelBubble;c(o)&&await o,r||(r=r||t.cancelBubble||n.hasAttribute("stoppropagation:"+t.type)),n=t.bubbles&&!0!==r?n.parentElement:null}},_=t=>{l("-window",t,q(t.type))},d=()=>{const s=t.readyState;if(!r&&("interactive"==s||"complete"==s)&&(o.forEach(i),r=1,b("qinit"),(e.requestIdleCallback??e.setTimeout).bind(e)(()=>b("qidle")),n.has("qvisible"))){const t=a("[on\\\\:qvisible]"),e=new IntersectionObserver(t=>{for(const n of t)n.isIntersecting&&(e.unobserve(n.target),u(n.target,"",p("qvisible",n)))});t.forEach(t=>e.observe(t))}},y=(t,e,n,o=!1)=>{t.addEventListener(e,n,{capture:o,passive:!1})},g=t=>t.replace(/-./g,t=>t[1].toUpperCase()),m=(...t)=>{for(const r of t)if("string"==typeof r){if(!n.has(r)){n.add(r);const t=g(r);o.forEach(e=>y(e,t,h,!0)),y(e,t,_,!0)}}else o.has(r)||(n.forEach(t=>{const e=g(t);y(r,e,h,!0)}),o.add(r))};if(!("__q_context__"in t)){t.__q_context__=0;const r=e.qwikevents;r&&(Array.isArray(r)?m(...r):m("click","input")),e.qwikevents={events:n,roots:o,push:m},y(t,"readystatechange",d),d()}';
1457
- var QWIK_LOADER_DEFAULT_DEBUG = 'const doc = document;\nconst win = window;\nconst events = /* @__PURE__ */ new Set();\nconst roots = /* @__PURE__ */ new Set([doc]);\nlet hasInitialized;\nconst nativeQuerySelectorAll = (root, selector) => Array.from(root.querySelectorAll(selector));\nconst querySelectorAll = (query) => {\n const elements = [];\n roots.forEach((root) => elements.push(...nativeQuerySelectorAll(root, query)));\n return elements;\n};\nconst findShadowRoots = (fragment) => {\n processEventOrNode(fragment);\n nativeQuerySelectorAll(fragment, "[q\\\\:shadowroot]").forEach((parent) => {\n const shadowRoot = parent.shadowRoot;\n shadowRoot && findShadowRoots(shadowRoot);\n });\n};\nconst isPromise = (promise) => promise && typeof promise.then === "function";\nconst broadcast = (infix, ev, type = ev.type) => {\n querySelectorAll("[on" + infix + "\\\\:" + type + "]").forEach((el) => {\n dispatch(el, infix, ev, type);\n });\n};\nconst resolveContainer = (containerEl) => {\n if (containerEl._qwikjson_ === void 0) {\n const parentJSON = containerEl === doc.documentElement ? doc.body : containerEl;\n let script = parentJSON.lastElementChild;\n while (script) {\n if (script.tagName === "SCRIPT" && script.getAttribute("type") === "qwik/json") {\n containerEl._qwikjson_ = JSON.parse(\n script.textContent.replace(/\\\\x3C(\\/?script)/gi, "<$1")\n );\n break;\n }\n script = script.previousElementSibling;\n }\n }\n};\nconst createEvent = (eventName, detail) => new CustomEvent(eventName, {\n detail\n});\nconst dispatch = async (element, scope, ev, eventName = ev.type) => {\n const attrName = "on" + scope + ":" + eventName;\n if (element.hasAttribute("preventdefault:" + eventName)) {\n ev.preventDefault();\n }\n if (element.hasAttribute("stoppropagation:" + eventName)) {\n ev.stopPropagation();\n }\n const ctx = element._qc_;\n const relevantListeners = ctx && ctx.li.filter((li) => li[0] === attrName);\n if (relevantListeners && relevantListeners.length > 0) {\n for (const listener of relevantListeners) {\n const results = listener[1].getFn([element, ev], () => element.isConnected)(ev, element);\n const cancelBubble = ev.cancelBubble;\n if (isPromise(results)) {\n await results;\n }\n if (cancelBubble) {\n ev.stopPropagation();\n }\n }\n return;\n }\n const attrValue = element.getAttribute(attrName);\n const qDispatchEvent = element.qDispatchEvent;\n if (qDispatchEvent) {\n return qDispatchEvent(ev, scope);\n }\n if (attrValue) {\n const container = element.closest(\n "[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])"\n );\n const qBase = container.getAttribute("q:base");\n const qVersion = container.getAttribute("q:version") || "unknown";\n const qManifest = container.getAttribute("q:manifest-hash") || "dev";\n const base = new URL(qBase, doc.baseURI);\n for (const qrl of attrValue.split("\\n")) {\n const url = new URL(qrl, base);\n const href = url.href;\n const symbol = url.hash.replace(/^#?([^?[|]*).*$/, "$1") || "default";\n const reqTime = performance.now();\n let handler;\n let importError;\n let error;\n const isSync = qrl.startsWith("#");\n const eventData = {\n qBase,\n qManifest,\n qVersion,\n href,\n symbol,\n element,\n reqTime\n };\n if (isSync) {\n const hash = container.getAttribute("q:instance");\n handler = (doc["qFuncs_" + hash] || [])[Number.parseInt(symbol)];\n if (!handler) {\n importError = "sync";\n error = new Error("sym:" + symbol);\n }\n } else {\n emitEvent("qsymbol", eventData);\n const uri = url.href.split("#")[0];\n try {\n const module = import(\n uri\n );\n resolveContainer(container);\n handler = (await module)[symbol];\n if (!handler) {\n importError = "no-symbol";\n error = new Error(`${symbol} not in ${uri}`);\n }\n } catch (err) {\n importError || (importError = "async");\n error = err;\n }\n }\n if (!handler) {\n emitEvent("qerror", {\n importError,\n error,\n ...eventData\n });\n console.error(error);\n break;\n }\n const previousCtx = doc.__q_context__;\n if (element.isConnected) {\n try {\n doc.__q_context__ = [element, ev, url];\n const results = handler(ev, element);\n if (isPromise(results)) {\n await results;\n }\n } catch (error2) {\n emitEvent("qerror", { error: error2, ...eventData });\n } finally {\n doc.__q_context__ = previousCtx;\n }\n }\n }\n }\n};\nconst emitEvent = (eventName, detail) => {\n doc.dispatchEvent(createEvent(eventName, detail));\n};\nconst camelToKebab = (str) => str.replace(/([A-Z-])/g, (a) => "-" + a.toLowerCase());\nconst processDocumentEvent = async (ev) => {\n let type = camelToKebab(ev.type);\n let element = ev.target;\n broadcast("-document", ev, type);\n while (element && element.getAttribute) {\n const results = dispatch(element, "", ev, type);\n let cancelBubble = ev.cancelBubble;\n if (isPromise(results)) {\n await results;\n }\n cancelBubble || (cancelBubble = cancelBubble || ev.cancelBubble || element.hasAttribute("stoppropagation:" + ev.type));\n element = ev.bubbles && cancelBubble !== true ? element.parentElement : null;\n }\n};\nconst processWindowEvent = (ev) => {\n broadcast("-window", ev, camelToKebab(ev.type));\n};\nconst processReadyStateChange = () => {\n const readyState = doc.readyState;\n if (!hasInitialized && (readyState == "interactive" || readyState == "complete")) {\n roots.forEach(findShadowRoots);\n hasInitialized = 1;\n emitEvent("qinit");\n const riC = win.requestIdleCallback ?? win.setTimeout;\n riC.bind(win)(() => emitEvent("qidle"));\n if (events.has("qvisible")) {\n const results = querySelectorAll("[on\\\\:qvisible]");\n const observer = new IntersectionObserver((entries) => {\n for (const entry of entries) {\n if (entry.isIntersecting) {\n observer.unobserve(entry.target);\n dispatch(entry.target, "", createEvent("qvisible", entry));\n }\n }\n });\n results.forEach((el) => observer.observe(el));\n }\n }\n};\nconst addEventListener = (el, eventName, handler, capture = false) => {\n el.addEventListener(eventName, handler, { capture, passive: false });\n};\nconst kebabToCamel = (eventName) => eventName.replace(/-./g, (a) => a[1].toUpperCase());\nconst processEventOrNode = (...eventNames) => {\n for (const eventNameOrNode of eventNames) {\n if (typeof eventNameOrNode === "string") {\n if (!events.has(eventNameOrNode)) {\n events.add(eventNameOrNode);\n const eventName = kebabToCamel(eventNameOrNode);\n roots.forEach((root) => addEventListener(root, eventName, processDocumentEvent, true));\n addEventListener(win, eventName, processWindowEvent, true);\n }\n } else {\n if (!roots.has(eventNameOrNode)) {\n events.forEach((kebabEventName) => {\n const eventName = kebabToCamel(kebabEventName);\n addEventListener(eventNameOrNode, eventName, processDocumentEvent, true);\n });\n roots.add(eventNameOrNode);\n }\n }\n }\n};\nif (!("__q_context__" in doc)) {\n doc.__q_context__ = 0;\n const qwikevents = win.qwikevents;\n if (qwikevents) {\n if (Array.isArray(qwikevents)) {\n processEventOrNode(...qwikevents);\n } else {\n processEventOrNode("click", "input");\n }\n }\n win.qwikevents = {\n events,\n roots,\n push: processEventOrNode\n };\n addEventListener(doc, "readystatechange", processReadyStateChange);\n processReadyStateChange();\n}';
1458
- var QWIK_BACKPATCH_EXECUTOR_MINIFIED = `const t='script[type="qwik/backpatch"]',e=document.currentScript;if(e){const o=e.closest("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])");if(o){const e=o.querySelector(t);if(e){const t=JSON.parse(e.textContent||"[]"),n=document.createTreeWalker(o,NodeFilter.SHOW_ELEMENT);let r=n.currentNode,c=r.hasAttribute(":")?0:-1;for(let e=0;e<t.length;e+=3){const o=t[e],i=t[e+1];let s=t[e+2];for(;c<o&&(r=n.nextNode(),r);)r.hasAttribute(":")&&c++;const l=r;null==s||!1===s?l.removeAttribute(i):("boolean"==typeof s&&(s=""),l.setAttribute(i,s))}}}}`;
1459
- var QWIK_BACKPATCH_EXECUTOR_DEBUG = `const BACKPATCH_DATA_SELECTOR = 'script[type="qwik/backpatch"]';
1460
- const executorScript = document.currentScript;
1461
- if (executorScript) {
1462
- const container = executorScript.closest(
1463
- "[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])"
1464
- );
1465
- if (container) {
1466
- const script = container.querySelector(BACKPATCH_DATA_SELECTOR);
1467
- if (script) {
1468
- const data = JSON.parse(script.textContent || "[]");
1469
- const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT);
1470
- let currentNode = walker.currentNode;
1471
- let currentNodeIdx = currentNode.hasAttribute(":") ? 0 : -1;
1472
- for (let i = 0; i < data.length; i += 3) {
1473
- const elementIdx = data[i];
1474
- const attrName = data[i + 1];
1475
- let value = data[i + 2];
1476
- while (currentNodeIdx < elementIdx) {
1477
- currentNode = walker.nextNode();
1478
- if (!currentNode) {
1479
- break;
1480
- }
1481
- if (currentNode.hasAttribute(":")) {
1482
- currentNodeIdx++;
1483
- }
1484
- }
1485
- const element = currentNode;
1486
- if (value == null || value === false) {
1487
- element.removeAttribute(attrName);
1488
- } else {
1489
- if (typeof value === "boolean") {
1490
- value = "";
1491
- }
1492
- element.setAttribute(attrName, value);
1493
- }
1494
- }
1495
- }
1496
- }
1497
- }`;
1498
- function getQwikLoaderScript(opts = {}) {
1499
- return opts.debug ? QWIK_LOADER_DEFAULT_DEBUG : QWIK_LOADER_DEFAULT_MINIFIED;
1500
- }
1501
- var QWIK_PREFETCH_MINIFIED = globalThis.QWIK_PREFETCH_MINIFIED;
1502
- var QWIK_PREFETCH_DEBUG = globalThis.QWIK_PREFETCH_DEBUG;
1503
- function getQwikPrefetchWorkerScript(opts = {}) {
1504
- return opts.debug ? QWIK_PREFETCH_DEBUG : QWIK_PREFETCH_MINIFIED;
1505
- }
1506
- function getQwikBackpatchExecutorScript(opts = {}) {
1507
- return opts.debug ? QWIK_BACKPATCH_EXECUTOR_DEBUG : QWIK_BACKPATCH_EXECUTOR_MINIFIED;
1508
- }
1509
-
1510
- // packages/qwik/src/server/ssr-node.ts
1511
- var import_internal = require("@qwik.dev/core/internal");
1512
- var import_build7 = require("@qwik.dev/core/build");
1513
- var SsrNode = class {
1514
- constructor(parentComponent, id, attributesIndex, cleanupQueue, vnodeData, currentFile) {
1515
- this.parentComponent = parentComponent;
1516
- this.attributesIndex = attributesIndex;
1517
- this.cleanupQueue = cleanupQueue;
1518
- this.vnodeData = vnodeData;
1519
- this.currentFile = currentFile;
1520
- var _a;
1521
- this.id = id;
1522
- this.flags = 1 /* Updatable */;
1523
- this.attrs = this.attributesIndex >= 0 ? this.vnodeData[this.attributesIndex] : import_internal._EMPTY_ARRAY;
1524
- (_a = this.parentComponent) == null ? void 0 : _a.addChild(this);
1525
- if (import_build7.isDev && id.indexOf("undefined") != -1) {
1526
- throw new Error(`Invalid SSR node id: ${id}`);
1527
- }
1528
- }
1529
- __brand__ = "SsrNode";
1530
- /**
1531
- * ID which the deserialize will use to retrieve the node.
1532
- *
1533
- * @param id - Unique id for the node.
1534
- */
1535
- id;
1536
- flags;
1537
- children = null;
1538
- attrs;
1539
- /** Local props which don't serialize; */
1540
- localProps = null;
1541
- get [import_internal._EFFECT_BACK_REF]() {
1542
- return this.getProp(QBackRefs);
1543
- }
1544
- setProp(name, value) {
1545
- if (this.attrs === import_internal._EMPTY_ARRAY) {
1546
- this.setEmptyArrayAsVNodeDataAttributes();
1547
- }
1548
- if (name.startsWith(NON_SERIALIZABLE_MARKER_PREFIX)) {
1549
- mapArray_set(this.localProps || (this.localProps = []), name, value, 0);
1550
- } else {
1551
- mapArray_set(this.attrs, name, value, 0);
1552
- }
1553
- if (name == ELEMENT_SEQ && value) {
1554
- this.cleanupQueue.push(value);
1555
- }
1556
- }
1557
- setEmptyArrayAsVNodeDataAttributes() {
1558
- if (this.attributesIndex >= 0) {
1559
- this.vnodeData[this.attributesIndex] = [];
1560
- this.attrs = this.vnodeData[this.attributesIndex];
1561
- } else {
1562
- const newAttributesIndex = this.vnodeData.length > 1 ? 1 : 0;
1563
- this.vnodeData.splice(newAttributesIndex, 0, []);
1564
- this.attributesIndex = newAttributesIndex;
1565
- this.attrs = this.vnodeData[this.attributesIndex];
1566
- }
1567
- }
1568
- getProp(name) {
1569
- if (name.startsWith(NON_SERIALIZABLE_MARKER_PREFIX)) {
1570
- return this.localProps ? mapArray_get(this.localProps, name, 0) : null;
1571
- } else {
1572
- return mapArray_get(this.attrs, name, 0);
1573
- }
1574
- }
1575
- removeProp(name) {
1576
- if (name.startsWith(NON_SERIALIZABLE_MARKER_PREFIX)) {
1577
- if (this.localProps) {
1578
- mapApp_remove(this.localProps, name, 0);
1579
- }
1580
- } else {
1581
- mapApp_remove(this.attrs, name, 0);
1582
- }
1583
- }
1584
- addChild(child) {
1585
- if (!this.children) {
1586
- this.children = [];
1587
- }
1588
- this.children.push(child);
1589
- }
1590
- setTreeNonUpdatable() {
1591
- if (this.flags & 1 /* Updatable */) {
1592
- this.flags &= ~1 /* Updatable */;
1593
- if (this.children) {
1594
- for (const child of this.children) {
1595
- child.setTreeNonUpdatable();
1596
- }
1597
- }
1598
- }
1599
- }
1600
- toString() {
1601
- if (import_build7.isDev) {
1602
- let stringifiedAttrs = "";
1603
- for (let i = 0; i < this.attrs.length; i += 2) {
1604
- const key = this.attrs[i];
1605
- const value = this.attrs[i + 1];
1606
- stringifiedAttrs += `${key}=`;
1607
- stringifiedAttrs += `${typeof value === "string" || typeof value === "number" ? JSON.stringify(value) : "*"}`;
1608
- if (i < this.attrs.length - 2) {
1609
- stringifiedAttrs += ", ";
1610
- }
1611
- }
1612
- return `<SSRNode id="${this.id}" ${stringifiedAttrs} />`;
1613
- } else {
1614
- return `<SSRNode id="${this.id}" />`;
1615
- }
1616
- }
1617
- };
1618
- var DomRef = class {
1619
- constructor($ssrNode$) {
1620
- this.$ssrNode$ = $ssrNode$;
1621
- }
1622
- __brand__ = "DomRef";
1623
- };
1624
- var SsrComponentFrame = class {
1625
- constructor(componentNode) {
1626
- this.componentNode = componentNode;
1627
- }
1628
- slots = [];
1629
- projectionDepth = 0;
1630
- scopedStyleIds = /* @__PURE__ */ new Set();
1631
- projectionScopedStyle = null;
1632
- projectionComponentFrame = null;
1633
- distributeChildrenIntoSlots(children, projectionScopedStyle, projectionComponentFrame) {
1634
- this.projectionScopedStyle = projectionScopedStyle;
1635
- this.projectionComponentFrame = projectionComponentFrame;
1636
- if ((0, import_internal._isJSXNode)(children)) {
1637
- const slotName = this.getSlotName(children);
1638
- mapArray_set(this.slots, slotName, children, 0);
1639
- } else if (Array.isArray(children) && children.length > 0) {
1640
- const defaultSlot = [];
1641
- for (let i = 0; i < children.length; i++) {
1642
- const child = children[i];
1643
- if ((0, import_internal._isJSXNode)(child)) {
1644
- const slotName = this.getSlotName(child);
1645
- if (slotName === QDefaultSlot) {
1646
- defaultSlot.push(child);
1647
- } else {
1648
- this.updateSlot(slotName, child);
1649
- }
1650
- } else {
1651
- defaultSlot.push(child);
1652
- }
1653
- }
1654
- defaultSlot.length > 0 && mapArray_set(this.slots, QDefaultSlot, defaultSlot, 0);
1655
- } else {
1656
- mapArray_set(this.slots, QDefaultSlot, children, 0);
1657
- }
1658
- }
1659
- updateSlot(slotName, child) {
1660
- let existingSlots = mapArray_get(this.slots, slotName, 0);
1661
- if (existingSlots === null) {
1662
- existingSlots = child;
1663
- } else if (Array.isArray(existingSlots)) {
1664
- existingSlots.push(child);
1665
- } else {
1666
- existingSlots = [existingSlots, child];
1667
- }
1668
- mapArray_set(this.slots, slotName, existingSlots, 0);
1669
- }
1670
- getSlotName(jsx) {
1671
- if (jsx.props[QSlot]) {
1672
- return jsx.props[QSlot];
1673
- }
1674
- return QDefaultSlot;
1675
- }
1676
- hasSlot(slotName) {
1677
- return mapArray_has(this.slots, slotName, 0);
1678
- }
1679
- consumeChildrenForSlot(projectionNode, slotName) {
1680
- const children = mapApp_remove(this.slots, slotName, 0);
1681
- this.componentNode.setProp(slotName, projectionNode.id);
1682
- projectionNode.setProp(QSlotParent, this.componentNode.id);
1683
- return children;
1684
- }
1685
- releaseUnclaimedProjections(unclaimedProjections) {
1686
- if (this.slots.length) {
1687
- unclaimedProjections.push(this);
1688
- unclaimedProjections.push(this.projectionScopedStyle);
1689
- unclaimedProjections.push.apply(unclaimedProjections, this.slots);
1690
- }
1691
- }
1692
- };
1693
-
1694
- // packages/qwik/src/server/tag-nesting.ts
1695
- var allowedContent = (state) => {
1696
- switch (state) {
1697
- case 2 /* TEXT */:
1698
- return ["text content", null];
1699
- case 0 /* NOT_ALLOWED */:
1700
- return ["no content", null];
1701
- case 32 /* HTML */:
1702
- return ["html content", "<head>, <body>"];
1703
- case 64 /* HEAD */:
1704
- return [
1705
- "head content",
1706
- "<title>, <script>, <noscript>, <style>, <meta>, <link>, <base>, <template>"
1707
- ];
1708
- case 130 /* BODY */:
1709
- return ["body content", "all tags allowed here"];
1710
- case 4 /* EMPTY */:
1711
- return ["no-content element", null];
1712
- case 10 /* ANYTHING */:
1713
- return ["any content", null];
1714
- case 4096 /* TABLE */:
1715
- return ["table", "<caption>, <colgroup>, <tbody>, <thead>, <tfoot>"];
1716
- case 8192 /* TABLE_BODY */:
1717
- return ["table body", "<tr>"];
1718
- case 16384 /* TABLE_ROW */:
1719
- return ["table row", "<td>, <th>"];
1720
- case 32768 /* TABLE_COLGROUP */:
1721
- return ["table column group", "<col>"];
1722
- case 258 /* PHRASING_ANY */:
1723
- case 514 /* PHRASING_INSIDE_INPUT */:
1724
- case 1026 /* PHRASING_CONTAINER */:
1725
- return ["phrasing content", "<a>, <b>, <img>, <input> ... (no <div>, <p> ...)"];
1726
- case 2050 /* PICTURE */:
1727
- return ["picture content", "<source>, <img>"];
1728
- case 4098 /* BUTTON */:
1729
- return ["button content", "phrasing content except interactive elements"];
1730
- case 1 /* DOCUMENT */:
1731
- return ["document", "<html>"];
1732
- }
1733
- };
1734
- var initialTag = (tag) => {
1735
- switch (tag) {
1736
- case "html":
1737
- return 32 /* HTML */;
1738
- case "head":
1739
- return 64 /* HEAD */;
1740
- case "body":
1741
- return 130 /* BODY */;
1742
- default:
1743
- return isTagAllowed(10 /* ANYTHING */, tag);
1744
- }
1745
- };
1746
- function isTagAllowed(state, tag) {
1747
- switch (state) {
1748
- case 2 /* TEXT */:
1749
- case 0 /* NOT_ALLOWED */:
1750
- return 0 /* NOT_ALLOWED */;
1751
- case 32 /* HTML */:
1752
- return isInHtml(tag);
1753
- case 64 /* HEAD */:
1754
- return isInHead(tag);
1755
- case 130 /* BODY */:
1756
- case 10 /* ANYTHING */:
1757
- case 1026 /* PHRASING_CONTAINER */:
1758
- return isInAnything(tag);
1759
- case 4096 /* TABLE */:
1760
- return isInTable(tag);
1761
- case 8192 /* TABLE_BODY */:
1762
- return isInTableBody(tag);
1763
- case 16384 /* TABLE_ROW */:
1764
- return isInTableRow(tag);
1765
- case 32768 /* TABLE_COLGROUP */:
1766
- return isInTableColGroup(tag);
1767
- case 258 /* PHRASING_ANY */:
1768
- return isInPhrasing(tag, true);
1769
- case 514 /* PHRASING_INSIDE_INPUT */:
1770
- return isInPhrasing(tag, false);
1771
- case 2050 /* PICTURE */:
1772
- return isInPicture(tag);
1773
- case 4098 /* BUTTON */:
1774
- return isInButton(tag);
1775
- case 1 /* DOCUMENT */:
1776
- if (tag === "html") {
1777
- return 32 /* HTML */;
1778
- }
1779
- }
1780
- return 0 /* NOT_ALLOWED */;
1781
- }
1782
- function isInHtml(text) {
1783
- switch (text) {
1784
- case "head":
1785
- return 64 /* HEAD */;
1786
- case "body":
1787
- return 130 /* BODY */;
1788
- default:
1789
- return 0 /* NOT_ALLOWED */;
1790
- }
1791
- }
1792
- function isInHead(text) {
1793
- switch (text) {
1794
- case "title":
1795
- case "script":
1796
- case "noscript":
1797
- case "style":
1798
- return 2 /* TEXT */;
1799
- case "meta":
1800
- case "link":
1801
- case "base":
1802
- return 4 /* EMPTY */;
1803
- case "template":
1804
- return 10 /* ANYTHING */;
1805
- default:
1806
- return 0 /* NOT_ALLOWED */;
1807
- }
1808
- }
1809
- function isSelfClosingTag(text) {
1810
- switch (text) {
1811
- case "area":
1812
- case "base":
1813
- case "basefont":
1814
- case "bgsound":
1815
- case "br":
1816
- case "col":
1817
- case "embed":
1818
- case "frame":
1819
- case "hr":
1820
- case "img":
1821
- case "input":
1822
- case "keygen":
1823
- case "link":
1824
- case "meta":
1825
- case "param":
1826
- case "source":
1827
- case "track":
1828
- case "wbr":
1829
- return true;
1830
- default:
1831
- return false;
1832
- }
1833
- }
1834
- function isInAnything(text) {
1835
- if (isSelfClosingTag(text)) {
1836
- return 4 /* EMPTY */;
1837
- }
1838
- switch (text) {
1839
- case "script":
1840
- case "style":
1841
- case "noscript":
1842
- case "noframes":
1843
- return 2 /* TEXT */;
1844
- case "p":
1845
- case "pre":
1846
- return 258 /* PHRASING_ANY */;
1847
- case "table":
1848
- return 4096 /* TABLE */;
1849
- case "html":
1850
- case "head":
1851
- case "body":
1852
- return 0 /* NOT_ALLOWED */;
1853
- case "button":
1854
- return 4098 /* BUTTON */;
1855
- case "input":
1856
- case "textarea":
1857
- return 514 /* PHRASING_INSIDE_INPUT */;
1858
- case "picture":
1859
- return 2050 /* PICTURE */;
1860
- default:
1861
- return 10 /* ANYTHING */;
1862
- }
1863
- }
1864
- function isInTable(text) {
1865
- switch (text) {
1866
- case "caption":
1867
- return 10 /* ANYTHING */;
1868
- case "colgroup":
1869
- return 32768 /* TABLE_COLGROUP */;
1870
- case "thead":
1871
- case "tbody":
1872
- case "tfoot":
1873
- return 8192 /* TABLE_BODY */;
1874
- case "script":
1875
- return 2 /* TEXT */;
1876
- default:
1877
- return 0 /* NOT_ALLOWED */;
1878
- }
1879
- }
1880
- function isInTableBody(text) {
1881
- switch (text) {
1882
- case "tr":
1883
- return 16384 /* TABLE_ROW */;
1884
- case "script":
1885
- return 2 /* TEXT */;
1886
- default:
1887
- return 0 /* NOT_ALLOWED */;
1888
- }
1889
- }
1890
- function isInTableRow(text) {
1891
- switch (text) {
1892
- case "td":
1893
- case "th":
1894
- return 10 /* ANYTHING */;
1895
- case "script":
1896
- return 2 /* TEXT */;
1897
- default:
1898
- return 0 /* NOT_ALLOWED */;
1899
- }
1900
- }
1901
- function isInTableColGroup(text) {
1902
- switch (text) {
1903
- case "col":
1904
- return 4 /* EMPTY */;
1905
- case "script":
1906
- return 2 /* TEXT */;
1907
- default:
1908
- return 0 /* NOT_ALLOWED */;
1909
- }
1910
- }
1911
- function isInPicture(text) {
1912
- switch (text) {
1913
- case "source":
1914
- return 4 /* EMPTY */;
1915
- case "img":
1916
- return 4 /* EMPTY */;
1917
- case "script":
1918
- return 2 /* TEXT */;
1919
- default:
1920
- return 0 /* NOT_ALLOWED */;
1921
- }
1922
- }
1923
- function isInButton(text) {
1924
- switch (text) {
1925
- case "button":
1926
- case "input":
1927
- case "textarea":
1928
- case "select":
1929
- case "a":
1930
- return 0 /* NOT_ALLOWED */;
1931
- case "picture":
1932
- return 2050 /* PICTURE */;
1933
- default:
1934
- return isInPhrasing(text, false);
1935
- }
1936
- }
1937
- function isInPhrasing(text, allowInput) {
1938
- switch (text) {
1939
- case "svg":
1940
- case "math":
1941
- return 1026 /* PHRASING_CONTAINER */;
1942
- case "input":
1943
- case "textarea":
1944
- return allowInput ? 514 /* PHRASING_INSIDE_INPUT */ : 0 /* NOT_ALLOWED */;
1945
- case "a":
1946
- case "abbr":
1947
- case "area":
1948
- case "audio":
1949
- case "b":
1950
- case "bdi":
1951
- case "bdo":
1952
- case "br":
1953
- case "button":
1954
- case "canvas":
1955
- case "cite":
1956
- case "code":
1957
- case "command":
1958
- case "data":
1959
- case "datalist":
1960
- case "del":
1961
- case "dfn":
1962
- case "em":
1963
- case "embed":
1964
- case "i":
1965
- case "iframe":
1966
- case "img":
1967
- case "ins":
1968
- case "itemprop":
1969
- case "kbd":
1970
- case "keygen":
1971
- case "label":
1972
- case "link":
1973
- case "map":
1974
- case "mark":
1975
- case "meta":
1976
- case "meter":
1977
- case "noscript":
1978
- case "object":
1979
- case "option":
1980
- case "output":
1981
- case "progress":
1982
- case "q":
1983
- case "ruby":
1984
- case "s":
1985
- case "samp":
1986
- case "select":
1987
- case "slot":
1988
- case "small":
1989
- case "span":
1990
- case "strong":
1991
- case "sub":
1992
- case "sup":
1993
- case "template":
1994
- case "time":
1995
- case "u":
1996
- case "var":
1997
- case "video":
1998
- case "wbr":
1999
- return allowInput ? 258 /* PHRASING_ANY */ : 514 /* PHRASING_INSIDE_INPUT */;
2000
- case "script":
2001
- case "style":
2002
- return 2 /* TEXT */;
2003
- case "picture":
2004
- return 2050 /* PICTURE */;
2005
- default:
2006
- return 0 /* NOT_ALLOWED */;
2007
- }
2008
- }
2009
-
2010
- // packages/qwik/src/server/vnode-data.ts
2011
- var OPEN_FRAGMENT = Number.MAX_SAFE_INTEGER;
2012
- var CLOSE_FRAGMENT = Number.MAX_SAFE_INTEGER - 1;
2013
- var WRITE_ELEMENT_ATTRS = Number.MAX_SAFE_INTEGER - 2;
2014
- function vNodeData_incrementElementCount(vNodeData) {
2015
- const length = vNodeData.length;
2016
- const lastValue = length > 1 ? vNodeData[length - 1] : 0;
2017
- if (lastValue >= 0) {
2018
- vNodeData.push(-1);
2019
- } else {
2020
- vNodeData[length - 1] = lastValue - 1;
2021
- }
2022
- }
2023
- function vNodeData_addTextSize(vNodeData, size) {
2024
- const length = vNodeData.length;
2025
- const lastValue = length > 1 ? vNodeData[length - 1] : 0;
2026
- if (length > 1 && lastValue >= 0) {
2027
- vNodeData[0] |= 1 /* TEXT_DATA */;
2028
- }
2029
- vNodeData.push(size);
2030
- if (size == 0) {
2031
- vNodeData[0] |= 1 /* TEXT_DATA */;
2032
- }
2033
- }
2034
- function vNodeData_openFragment(vNodeData, attrs) {
2035
- vNodeData.push(attrs, OPEN_FRAGMENT);
2036
- vNodeData[0] |= 2 /* VIRTUAL_NODE */;
2037
- }
2038
- function vNodeData_closeFragment(vNodeData) {
2039
- vNodeData.push(CLOSE_FRAGMENT);
2040
- }
2041
- function vNodeData_openElement(vNodeData) {
2042
- vNodeData.push([], WRITE_ELEMENT_ATTRS);
2043
- vNodeData[0] |= 4 /* ELEMENT_NODE */;
2044
- }
2045
- function vNodeData_createSsrNodeReference(currentComponentNode, vNodeData, depthFirstElementIdx, cleanupQueue, currentFile) {
2046
- vNodeData[0] |= 8 /* REFERENCE */;
2047
- const stack = [-1];
2048
- let attributesIndex = -1;
2049
- for (let i = 1; i < vNodeData.length; i++) {
2050
- const value = vNodeData[i];
2051
- if (Array.isArray(value)) {
2052
- attributesIndex = i;
2053
- i++;
2054
- if (vNodeData[i] !== WRITE_ELEMENT_ATTRS) {
2055
- stack[stack.length - 1]++;
2056
- stack.push(-1);
2057
- }
2058
- } else if (value === CLOSE_FRAGMENT) {
2059
- stack.pop();
2060
- } else if (value < 0) {
2061
- const numberOfElements = 0 - value;
2062
- stack[stack.length - 1] += numberOfElements;
2063
- } else {
2064
- stack[stack.length - 1]++;
2065
- }
2066
- }
2067
- let refId = String(depthFirstElementIdx);
2068
- if (vNodeData[0] & (2 /* VIRTUAL_NODE */ | 1 /* TEXT_DATA */)) {
2069
- for (let i = 0; i < stack.length; i++) {
2070
- const childCount = stack[i];
2071
- if (childCount >= 0) {
2072
- refId += encodeAsAlphanumeric(childCount);
2073
- }
2074
- }
2075
- }
2076
- return new SsrNode(
2077
- currentComponentNode,
2078
- refId,
2079
- attributesIndex,
2080
- cleanupQueue,
2081
- vNodeData,
2082
- currentFile
2083
- );
2084
- }
2085
- var ALPHANUMERIC = [];
2086
- function encodeAsAlphanumeric(value) {
2087
- while (ALPHANUMERIC.length <= value) {
2088
- let value2 = ALPHANUMERIC.length;
2089
- let text = "";
2090
- do {
2091
- text = String.fromCharCode(
2092
- (text.length === 0 ? 65 : 97) + value2 % 26
2093
- /* A-Z */
2094
- ) + text;
2095
- value2 = Math.floor(
2096
- value2 / 26
2097
- /* A-Z */
2098
- );
2099
- } while (value2 !== 0);
2100
- ALPHANUMERIC.push(text);
2101
- }
2102
- return ALPHANUMERIC[value];
2103
- }
2104
-
2105
- // packages/qwik/src/server/ssr-container.ts
2106
- function ssrCreateContainer(opts) {
2107
- opts.renderOptions ||= {};
2108
- return new SSRContainer({
2109
- tagName: opts.tagName || "div",
2110
- writer: opts.writer || new StringBufferWriter(),
2111
- locale: opts.locale || "",
2112
- timing: opts.timing || {
2113
- firstFlush: 0,
2114
- render: 0,
2115
- snapshot: 0
2116
- },
2117
- buildBase: opts.buildBase || "/build/",
2118
- resolvedManifest: opts.resolvedManifest || {
2119
- mapper: {},
2120
- manifest: {
2121
- manifestHash: "dev",
2122
- mapping: {}
2123
- }
2124
- },
2125
- renderOptions: opts.renderOptions
2126
- });
2127
- }
2128
- var StringBufferWriter = class {
2129
- buffer = [];
2130
- write(text) {
2131
- this.buffer.push(text);
2132
- }
2133
- toString() {
2134
- return this.buffer.join("");
2135
- }
2136
- };
2137
- var EMPTY_OBJ = {};
2138
- var SSRContainer = class extends import_internal2._SharedContainer {
2139
- tag;
2140
- isHtml;
2141
- writer;
2142
- timing;
2143
- size = 0;
2144
- resolvedManifest;
2145
- symbolToChunkResolver;
2146
- renderOptions;
2147
- serializationCtx;
2148
- /**
2149
- * We use this to append additional nodes in the head node
2150
- *
2151
- * - From manifest injections
2152
- * - From useStyles and useScopedStyles hooks
2153
- */
2154
- additionalHeadNodes = new Array();
2155
- /**
2156
- * We use this to append additional nodes in the body node
2157
- *
2158
- * - From manifest injections
2159
- */
2160
- additionalBodyNodes = new Array();
2161
- lastNode = null;
2162
- currentComponentNode = null;
2163
- styleIds = /* @__PURE__ */ new Set();
2164
- isBackpatchExecutorEmitted = false;
2165
- backpatchMap = /* @__PURE__ */ new Map();
2166
- currentElementFrame = null;
2167
- renderTimer;
2168
- /**
2169
- * Current element index.
2170
- *
2171
- * This number must match the depth-first traversal of the DOM elements as returned by the
2172
- * https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
2173
- */
2174
- depthFirstElementCount = -1;
2175
- vNodeDatas = [];
2176
- componentStack = [];
2177
- unclaimedProjections = [];
2178
- unclaimedProjectionComponentFrameQueue = [];
2179
- cleanupQueue = [];
2180
- $instanceHash$ = hash();
2181
- // Temporary flag to find missing roots after the state was serialized
2182
- $noMoreRoots$ = false;
2183
- qlInclude;
2184
- promiseAttributes = null;
2185
- constructor(opts) {
2186
- var _a;
2187
- super(() => null, opts.renderOptions.serverData ?? EMPTY_OBJ, opts.locale);
2188
- this.symbolToChunkResolver = (symbol) => {
2189
- const idx = symbol.lastIndexOf("_");
2190
- const chunk = this.resolvedManifest.mapper[idx == -1 ? symbol : symbol.substring(idx + 1)];
2191
- return chunk ? chunk[1] : "";
2192
- };
2193
- this.serializationCtx = this.serializationCtxFactory(
2194
- SsrNode,
2195
- DomRef,
2196
- this.symbolToChunkResolver,
2197
- opts.writer
2198
- );
2199
- this.renderTimer = createTimer();
2200
- this.tag = opts.tagName;
2201
- this.isHtml = opts.tagName === "html";
2202
- this.writer = opts.writer;
2203
- this.timing = opts.timing;
2204
- this.$buildBase$ = opts.buildBase;
2205
- this.resolvedManifest = opts.resolvedManifest;
2206
- this.renderOptions = opts.renderOptions;
2207
- this.$currentUniqueId$ = 1e5;
2208
- const qlOpt = this.renderOptions.qwikLoader;
2209
- this.qlInclude = qlOpt ? typeof qlOpt === "object" ? qlOpt.include === "never" ? 2 /* Done */ : 0 /* Module */ : qlOpt === "inline" ? 1 /* Inline */ : qlOpt === "never" ? 2 /* Done */ : 0 /* Module */ : 0 /* Module */;
2210
- if (this.qlInclude === 0 /* Module */) {
2211
- const qwikLoaderChunk = (_a = this.resolvedManifest) == null ? void 0 : _a.manifest.qwikLoader;
2212
- if (!qwikLoaderChunk) {
2213
- this.qlInclude = 1 /* Inline */;
2214
- }
2215
- }
2216
- this.$processInjectionsFromManifest$();
2217
- }
2218
- ensureProjectionResolved(_host) {
2219
- }
2220
- handleError(err, _$host$) {
2221
- throw err;
2222
- }
2223
- addBackpatchEntry(ssrNodeId, attrName, serializedValue) {
2224
- const elementIndex = parseInt(ssrNodeId, 10);
2225
- const entry = {
2226
- attrName,
2227
- value: serializedValue
2228
- };
2229
- const entries = this.backpatchMap.get(elementIndex) || [];
2230
- entries.push(entry);
2231
- this.backpatchMap.set(elementIndex, entries);
2232
- }
2233
- async render(jsx) {
2234
- this.openContainer();
2235
- await (0, import_internal2._walkJSX)(this, jsx, {
2236
- currentStyleScoped: null,
2237
- parentComponentFrame: this.getComponentFrame()
2238
- });
2239
- await this.closeContainer();
2240
- }
2241
- setContext(host, context, value) {
2242
- const ssrNode = host;
2243
- let ctx = ssrNode.getProp(QCtxAttr);
2244
- if (ctx == null) {
2245
- ssrNode.setProp(QCtxAttr, ctx = []);
2246
- }
2247
- mapArray_set(ctx, context.id, value, 0, true);
2248
- this.addRoot(ssrNode);
2249
- }
2250
- resolveContext(host, contextId) {
2251
- let ssrNode = host;
2252
- while (ssrNode) {
2253
- const ctx = ssrNode.getProp(QCtxAttr);
2254
- if (ctx != null && mapArray_has(ctx, contextId.id, 0)) {
2255
- return mapArray_get(ctx, contextId.id, 0);
2256
- }
2257
- ssrNode = ssrNode.parentComponent;
2258
- }
2259
- return void 0;
2260
- }
2261
- getParentHost(host) {
2262
- const ssrNode = host;
2263
- return ssrNode.parentComponent;
2264
- }
2265
- setHostProp(host, name, value) {
2266
- const ssrNode = host;
2267
- return ssrNode.setProp(name, value);
2268
- }
2269
- getHostProp(host, name) {
2270
- const ssrNode = host;
2271
- return ssrNode.getProp(name);
2272
- }
2273
- /**
2274
- * Renders opening tag for container. It could be a html tag for regular apps or custom element
2275
- * for micro-frontends
2276
- */
2277
- openContainer() {
2278
- if (this.tag == "html") {
2279
- this.write("<!DOCTYPE html>");
2280
- }
2281
- const containerAttributes = this.renderOptions.containerAttributes || {};
2282
- const qRender = containerAttributes[QRenderAttr];
2283
- containerAttributes[QContainerAttr] = "paused" /* PAUSED */;
2284
- containerAttributes[QRuntimeAttr] = "2";
2285
- containerAttributes[QVersionAttr] = this.$version$ ?? "dev";
2286
- containerAttributes[QRenderAttr] = (qRender ? qRender + "-" : "") + (import_build8.isDev ? "ssr-dev" : "ssr");
2287
- containerAttributes[QBaseAttr] = this.$buildBase$ || "";
2288
- containerAttributes[QLocaleAttr] = this.$locale$;
2289
- containerAttributes[QManifestHashAttr] = this.resolvedManifest.manifest.manifestHash;
2290
- containerAttributes[QInstanceAttr] = this.$instanceHash$;
2291
- this.$serverData$.containerAttributes = containerAttributes;
2292
- const containerAttributeArray = Object.entries(containerAttributes).reduce(
2293
- (acc, [key, value]) => {
2294
- acc.push(key, value);
2295
- return acc;
2296
- },
2297
- []
2298
- );
2299
- this.openElement(this.tag, containerAttributeArray);
2300
- }
2301
- /** Renders closing tag for current container */
2302
- closeContainer() {
2303
- return this.closeElement();
2304
- }
2305
- $noScriptHere$ = 0;
2306
- /** Renders opening tag for DOM element */
2307
- openElement(elementName, varAttrs, constAttrs, currentFile) {
2308
- const isQwikStyle = isQwikStyleElement(elementName, varAttrs) || isQwikStyleElement(elementName, constAttrs);
2309
- if (
2310
- // don't append qwik loader before qwik style elements
2311
- // it will confuse the resuming, because styles are expected to be the first nodes in subtree
2312
- !isQwikStyle && this.qlInclude === 1 /* Inline */
2313
- ) {
2314
- if (this.$noScriptHere$ === 0 && this.size > 30 * 1024 && elementName !== "body") {
2315
- this.emitQwikLoaderInline();
2316
- } else if (elementName === "noscript" || elementName === "template") {
2317
- this.$noScriptHere$++;
2318
- }
2319
- }
2320
- let innerHTML = void 0;
2321
- this.lastNode = null;
2322
- if (!isQwikStyle && this.currentElementFrame) {
2323
- vNodeData_incrementElementCount(this.currentElementFrame.vNodeData);
2324
- }
2325
- this.createAndPushFrame(elementName, this.depthFirstElementCount++, currentFile);
2326
- vNodeData_openElement(this.currentElementFrame.vNodeData);
2327
- this.write("<");
2328
- this.write(elementName);
2329
- const lastNode = this.getOrCreateLastNode();
2330
- if (varAttrs) {
2331
- innerHTML = this.writeAttrs(elementName, varAttrs, false, currentFile);
2332
- }
2333
- this.write(" " + Q_PROPS_SEPARATOR);
2334
- import_build8.isDev && this.write('=""');
2335
- if (constAttrs && constAttrs.length) {
2336
- innerHTML = this.writeAttrs(elementName, constAttrs, true, currentFile) || innerHTML;
2337
- }
2338
- this.write(">");
2339
- if (lastNode) {
2340
- lastNode.setTreeNonUpdatable();
2341
- }
2342
- return innerHTML;
2343
- }
2344
- /** Renders closing tag for DOM element */
2345
- closeElement() {
2346
- if (this.shouldEmitDataBeforeClosingElement()) {
2347
- this.onRenderDone();
2348
- const snapshotTimer = createTimer();
2349
- return maybeThen(
2350
- maybeThen(this.emitContainerData(), () => this._closeElement()),
2351
- () => {
2352
- this.timing.snapshot = snapshotTimer();
2353
- }
2354
- );
2355
- }
2356
- this._closeElement();
2357
- }
2358
- shouldEmitDataBeforeClosingElement() {
2359
- const currentFrame = this.currentElementFrame;
2360
- return (
2361
- /**
2362
- * - Micro-frontends don't have html tag, emit data before closing custom element
2363
- * - Regular applications should emit data inside body
2364
- */
2365
- currentFrame.parent === null && currentFrame.elementName !== "html" || currentFrame.elementName === "body"
2366
- );
2367
- }
2368
- onRenderDone() {
2369
- this.drainCleanupQueue();
2370
- this.timing.render = this.renderTimer();
2371
- }
2372
- /** Drain cleanup queue and cleanup tasks etc. */
2373
- drainCleanupQueue() {
2374
- let sequences = this.cleanupQueue.pop();
2375
- while (sequences) {
2376
- for (let j = 0; j < sequences.length; j++) {
2377
- const item = sequences[j];
2378
- if (hasDestroy(item)) {
2379
- item.$destroy$();
2380
- }
2381
- }
2382
- sequences = this.cleanupQueue.pop();
2383
- }
2384
- }
2385
- _closeElement() {
2386
- const currentFrame = this.popFrame();
2387
- const elementName = currentFrame.elementName;
2388
- if (!isSelfClosingTag(elementName)) {
2389
- this.write("</");
2390
- this.write(elementName);
2391
- this.write(">");
2392
- }
2393
- this.lastNode = null;
2394
- if (this.qlInclude === 1 /* Inline */) {
2395
- if (elementName === "noscript" || elementName === "template") {
2396
- this.$noScriptHere$--;
2397
- }
2398
- }
2399
- }
2400
- /** Writes opening data to vNodeData for fragment boundaries */
2401
- openFragment(attrs) {
2402
- this.lastNode = null;
2403
- vNodeData_openFragment(this.currentElementFrame.vNodeData, attrs);
2404
- this.getOrCreateLastNode();
2405
- }
2406
- /** Writes closing data to vNodeData for fragment boundaries */
2407
- closeFragment() {
2408
- vNodeData_closeFragment(this.currentElementFrame.vNodeData);
2409
- if (this.currentComponentNode) {
2410
- this.currentComponentNode.setTreeNonUpdatable();
2411
- }
2412
- this.lastNode = null;
2413
- }
2414
- openProjection(attrs) {
2415
- this.openFragment(attrs);
2416
- const componentFrame = this.getComponentFrame();
2417
- if (componentFrame) {
2418
- this.serializationCtx.$addRoot$(componentFrame.componentNode);
2419
- componentFrame.projectionDepth++;
2420
- }
2421
- }
2422
- closeProjection() {
2423
- const componentFrame = this.getComponentFrame();
2424
- if (componentFrame) {
2425
- componentFrame.projectionDepth--;
2426
- }
2427
- this.closeFragment();
2428
- }
2429
- /** Writes opening data to vNodeData for component boundaries */
2430
- openComponent(attrs) {
2431
- this.openFragment(attrs);
2432
- this.currentComponentNode = this.getOrCreateLastNode();
2433
- this.componentStack.push(new SsrComponentFrame(this.currentComponentNode));
2434
- }
2435
- /**
2436
- * Returns the current component frame.
2437
- *
2438
- * @param projectionDepth - How many levels of projection to skip. This is needed when projections
2439
- * are nested inside other projections we need to have a way to read from a frame above.
2440
- * @returns
2441
- */
2442
- getComponentFrame(projectionDepth = 0) {
2443
- const length = this.componentStack.length;
2444
- const idx = length - projectionDepth - 1;
2445
- return idx >= 0 ? this.componentStack[idx] : null;
2446
- }
2447
- getParentComponentFrame() {
2448
- var _a;
2449
- const localProjectionDepth = ((_a = this.getComponentFrame()) == null ? void 0 : _a.projectionDepth) || 0;
2450
- return this.getComponentFrame(localProjectionDepth);
2451
- }
2452
- /** Writes closing data to vNodeData for component boundaries and mark unclaimed projections */
2453
- closeComponent() {
2454
- var _a;
2455
- const componentFrame = this.componentStack.pop();
2456
- componentFrame.releaseUnclaimedProjections(this.unclaimedProjections);
2457
- this.closeFragment();
2458
- this.currentComponentNode = ((_a = this.currentComponentNode) == null ? void 0 : _a.parentComponent) || null;
2459
- }
2460
- /** Write a text node with correct escaping. Save the length of the text node in the vNodeData. */
2461
- textNode(text) {
2462
- this.write(escapeHTML(text));
2463
- vNodeData_addTextSize(this.currentElementFrame.vNodeData, text.length);
2464
- this.lastNode = null;
2465
- }
2466
- htmlNode(rawHtml) {
2467
- this.write(rawHtml);
2468
- }
2469
- commentNode(text) {
2470
- this.write("<!--" + text + "-->");
2471
- }
2472
- addRoot(obj) {
2473
- if (this.$noMoreRoots$) {
2474
- return this.serializationCtx.$hasRootId$(obj);
2475
- }
2476
- return this.serializationCtx.$addRoot$(obj);
2477
- }
2478
- getOrCreateLastNode() {
2479
- if (!this.lastNode) {
2480
- this.lastNode = vNodeData_createSsrNodeReference(
2481
- this.currentComponentNode,
2482
- this.currentElementFrame.vNodeData,
2483
- // we start at -1, so we need to add +1
2484
- this.currentElementFrame.depthFirstElementIdx + 1,
2485
- this.cleanupQueue,
2486
- this.currentElementFrame.currentFile
2487
- );
2488
- }
2489
- return this.lastNode;
2490
- }
2491
- addUnclaimedProjection(frame, name, children) {
2492
- this.unclaimedProjections.push(frame, null, name, children);
2493
- }
2494
- $processInjectionsFromManifest$() {
2495
- const injections = this.resolvedManifest.manifest.injections;
2496
- if (!injections) {
2497
- return;
2498
- }
2499
- for (let i = 0; i < injections.length; i++) {
2500
- const injection = injections[i];
2501
- const jsxNode = (0, import_internal2._jsxSplit)(injection.tag, null, injection.attributes || {}, null, 0, null);
2502
- if (injection.location === "head") {
2503
- this.additionalHeadNodes.push(jsxNode);
2504
- } else {
2505
- this.additionalBodyNodes.push(jsxNode);
2506
- }
2507
- }
2508
- }
2509
- $appendStyle$(content, styleId, host, scoped) {
2510
- var _a;
2511
- if (scoped) {
2512
- const componentFrame = this.getComponentFrame(0);
2513
- componentFrame.scopedStyleIds.add(styleId);
2514
- const scopedStyleIds = convertStyleIdsToString(componentFrame.scopedStyleIds);
2515
- this.setHostProp(host, QScopedStyle, scopedStyleIds);
2516
- }
2517
- if (!this.styleIds.has(styleId)) {
2518
- this.styleIds.add(styleId);
2519
- if (((_a = this.currentElementFrame) == null ? void 0 : _a.elementName) === "html") {
2520
- this.additionalHeadNodes.push(
2521
- (0, import_internal2._jsxSorted)(
2522
- "style",
2523
- null,
2524
- { dangerouslySetInnerHTML: content, [QStyle]: styleId },
2525
- null,
2526
- 0,
2527
- styleId
2528
- )
2529
- );
2530
- } else {
2531
- this._styleNode(styleId, content);
2532
- }
2533
- }
2534
- }
2535
- _styleNode(styleId, content) {
2536
- this.openElement("style", [QStyle, styleId]);
2537
- this.write(content);
2538
- this.closeElement();
2539
- }
2540
- ////////////////////////////////////
2541
- emitContainerData() {
2542
- return maybeThen(
2543
- this.resolvePromiseAttributes(),
2544
- () => maybeThen(
2545
- this.emitUnclaimedProjection(),
2546
- () => maybeThen(this.emitStateData(), () => {
2547
- var _a;
2548
- this.$noMoreRoots$ = true;
2549
- this.emitVNodeData();
2550
- preloaderPost(this, this.renderOptions, (_a = this.$serverData$) == null ? void 0 : _a.nonce);
2551
- this.emitSyncFnsData();
2552
- this.emitPatchDataIfNeeded();
2553
- this.emitExecutorIfNeeded();
2554
- this.emitQwikLoaderAtBottomIfNeeded();
2555
- })
2556
- )
2557
- );
2558
- }
2559
- /**
2560
- * Serialize the vNodeData into a string and emit it as a script tag.
2561
- *
2562
- * ## Encoding:
2563
- *
2564
- * - Alphabetical characters are text node lengths.
2565
- * - Numbers are element counts.
2566
- * - `{` is start of virtual node.
2567
- * - `}` is end of virtual node.
2568
- * - `~` Store as reference for data deserialization.
2569
- * - `!"#$%&'()*+'-./` are separators (sequential characters in ASCII table)
2570
- *
2571
- * Attribute and separators encoding described here:
2572
- * `packages/qwik/src/core/v2/shared/vnode-data-types.ts`
2573
- *
2574
- * NOTE: Not every element will need vNodeData. So we need to encode how many elements should be
2575
- * skipped. By choosing different separators we can encode different numbers of elements to skip.
2576
- */
2577
- emitVNodeData() {
2578
- if (!this.serializationCtx.$roots$.length) {
2579
- return;
2580
- }
2581
- this.openElement("script", ["type", "qwik/vnode"]);
2582
- const vNodeAttrsStack = [];
2583
- const vNodeData = this.vNodeDatas;
2584
- let lastSerializedIdx = 0;
2585
- for (let elementIdx = 0; elementIdx < vNodeData.length; elementIdx++) {
2586
- const vNode = vNodeData[elementIdx];
2587
- const flag = vNode[0];
2588
- if (flag & 16 /* SERIALIZE */) {
2589
- lastSerializedIdx = this.emitVNodeSeparators(lastSerializedIdx, elementIdx);
2590
- if (flag & 8 /* REFERENCE */) {
2591
- this.write(VNodeDataSeparator.REFERENCE_CH);
2592
- }
2593
- if (flag & (1 /* TEXT_DATA */ | 2 /* VIRTUAL_NODE */ | 4 /* ELEMENT_NODE */)) {
2594
- let fragmentAttrs = null;
2595
- let depth = 0;
2596
- for (let i = 1; i < vNode.length; i++) {
2597
- const value = vNode[i];
2598
- if (Array.isArray(value)) {
2599
- vNodeAttrsStack.push(fragmentAttrs);
2600
- fragmentAttrs = value;
2601
- } else if (value === OPEN_FRAGMENT) {
2602
- depth++;
2603
- this.write(VNodeDataChar.OPEN_CHAR);
2604
- } else if (value === CLOSE_FRAGMENT) {
2605
- if (fragmentAttrs) {
2606
- this.writeFragmentAttrs(fragmentAttrs);
2607
- fragmentAttrs = vNodeAttrsStack.pop();
2608
- }
2609
- depth--;
2610
- this.write(VNodeDataChar.CLOSE_CHAR);
2611
- } else if (value === WRITE_ELEMENT_ATTRS) {
2612
- if (fragmentAttrs && fragmentAttrs.length) {
2613
- this.write(VNodeDataChar.SEPARATOR_CHAR);
2614
- this.writeFragmentAttrs(fragmentAttrs);
2615
- this.write(VNodeDataChar.SEPARATOR_CHAR);
2616
- fragmentAttrs = vNodeAttrsStack.pop();
2617
- }
2618
- } else if (value >= 0) {
2619
- this.write(encodeAsAlphanumeric(value));
2620
- } else {
2621
- this.write(String(0 - value));
2622
- }
2623
- }
2624
- while (depth-- > 0) {
2625
- if (fragmentAttrs) {
2626
- this.writeFragmentAttrs(fragmentAttrs);
2627
- fragmentAttrs = vNodeAttrsStack.pop();
2628
- }
2629
- this.write(VNodeDataChar.CLOSE_CHAR);
2630
- }
2631
- }
2632
- }
2633
- }
2634
- this.closeElement();
2635
- }
2636
- writeFragmentAttrs(fragmentAttrs) {
2637
- for (let i = 0; i < fragmentAttrs.length; ) {
2638
- const key = fragmentAttrs[i++];
2639
- let value = fragmentAttrs[i++];
2640
- let encodeValue = false;
2641
- if (typeof value !== "string") {
2642
- const rootId = this.addRoot(value);
2643
- if (rootId === void 0) {
2644
- continue;
2645
- }
2646
- value = String(rootId);
2647
- }
2648
- switch (key) {
2649
- case QScopedStyle:
2650
- this.write(VNodeDataChar.SCOPED_STYLE_CHAR);
2651
- break;
2652
- case OnRenderProp:
2653
- this.write(VNodeDataChar.RENDER_FN_CHAR);
2654
- break;
2655
- case ELEMENT_ID:
2656
- this.write(VNodeDataChar.ID_CHAR);
2657
- break;
2658
- case ELEMENT_PROPS:
2659
- this.write(VNodeDataChar.PROPS_CHAR);
2660
- break;
2661
- case ELEMENT_KEY:
2662
- encodeValue = true;
2663
- this.write(VNodeDataChar.KEY_CHAR);
2664
- break;
2665
- case ELEMENT_SEQ:
2666
- this.write(VNodeDataChar.SEQ_CHAR);
2667
- break;
2668
- case ELEMENT_SEQ_IDX:
2669
- this.write(VNodeDataChar.SEQ_IDX_CHAR);
2670
- break;
2671
- case QBackRefs:
2672
- this.write(VNodeDataChar.BACK_REFS_CHAR);
2673
- break;
2674
- case QSlotParent:
2675
- this.write(VNodeDataChar.SLOT_PARENT_CHAR);
2676
- break;
2677
- // Skipping `\` character for now because it is used for escaping.
2678
- case QCtxAttr:
2679
- this.write(VNodeDataChar.CONTEXT_CHAR);
2680
- break;
2681
- case QSlot:
2682
- this.write(VNodeDataChar.SLOT_CHAR);
2683
- break;
2684
- default:
2685
- this.write(VNodeDataChar.SEPARATOR_CHAR);
2686
- this.write(key);
2687
- this.write(VNodeDataChar.SEPARATOR_CHAR);
2688
- }
2689
- const encodedValue = encodeValue ? encodeURI(value) : value;
2690
- const isEncoded = encodeValue ? encodedValue !== value : false;
2691
- if (isEncoded) {
2692
- this.write(VNodeDataChar.SEPARATOR_CHAR);
2693
- this.write(encodedValue);
2694
- this.write(VNodeDataChar.SEPARATOR_CHAR);
2695
- } else {
2696
- this.write(value);
2697
- }
2698
- }
2699
- }
2700
- emitStateData() {
2701
- if (!this.serializationCtx.$roots$.length) {
2702
- return;
2703
- }
2704
- this.openElement("script", ["type", "qwik/state"]);
2705
- return maybeThen(this.serializationCtx.$serialize$(), () => {
2706
- this.closeElement();
2707
- });
2708
- }
2709
- emitSyncFnsData() {
2710
- var _a;
2711
- const fns = this.serializationCtx.$syncFns$;
2712
- if (fns.length) {
2713
- const scriptAttrs = ["q:func", "qwik/json"];
2714
- if ((_a = this.renderOptions.serverData) == null ? void 0 : _a.nonce) {
2715
- scriptAttrs.push("nonce", this.renderOptions.serverData.nonce);
2716
- }
2717
- this.openElement("script", scriptAttrs);
2718
- this.write(Q_FUNCS_PREFIX.replace("HASH", this.$instanceHash$));
2719
- this.write("[");
2720
- this.writeArray(fns, ",");
2721
- this.write("]");
2722
- this.closeElement();
2723
- }
2724
- }
2725
- emitPatchDataIfNeeded() {
2726
- var _a;
2727
- const patches = [];
2728
- for (const [elementIndex, backpatchEntries] of this.backpatchMap) {
2729
- for (const backpatchEntry of backpatchEntries) {
2730
- patches.push(elementIndex, backpatchEntry.attrName, backpatchEntry.value);
2731
- }
2732
- }
2733
- this.backpatchMap.clear();
2734
- if (patches.length > 0) {
2735
- this.isBackpatchExecutorEmitted = true;
2736
- const scriptAttrs = ["type", ELEMENT_BACKPATCH_DATA];
2737
- if ((_a = this.renderOptions.serverData) == null ? void 0 : _a.nonce) {
2738
- scriptAttrs.push("nonce", this.renderOptions.serverData.nonce);
2739
- }
2740
- this.openElement("script", scriptAttrs);
2741
- this.write(JSON.stringify(patches));
2742
- this.closeElement();
2743
- }
2744
- }
2745
- emitExecutorIfNeeded() {
2746
- var _a;
2747
- if (!this.isBackpatchExecutorEmitted) {
2748
- return;
2749
- }
2750
- const scriptAttrs = ["type", "text/javascript"];
2751
- if ((_a = this.renderOptions.serverData) == null ? void 0 : _a.nonce) {
2752
- scriptAttrs.push("nonce", this.renderOptions.serverData.nonce);
2753
- }
2754
- this.openElement("script", scriptAttrs);
2755
- const backpatchScript = getQwikBackpatchExecutorScript({ debug: import_build8.isDev });
2756
- this.write(backpatchScript);
2757
- this.closeElement();
2758
- }
2759
- emitPreloaderPre() {
2760
- var _a;
2761
- preloaderPre(this, this.renderOptions.preloader, (_a = this.renderOptions.serverData) == null ? void 0 : _a.nonce);
2762
- }
2763
- isStatic() {
2764
- return this.serializationCtx.$eventQrls$.size === 0;
2765
- }
2766
- emitQwikLoaderAtTopIfNeeded() {
2767
- var _a;
2768
- if (this.qlInclude === 0 /* Module */) {
2769
- this.qlInclude = 2 /* Done */;
2770
- const qwikLoaderBundle = this.$buildBase$ + this.resolvedManifest.manifest.qwikLoader;
2771
- const linkAttrs = ["rel", "modulepreload", "href", qwikLoaderBundle];
2772
- const nonce = (_a = this.renderOptions.serverData) == null ? void 0 : _a.nonce;
2773
- if (nonce) {
2774
- linkAttrs.push("nonce", nonce);
2775
- }
2776
- this.openElement("link", linkAttrs);
2777
- this.closeElement();
2778
- const scriptAttrs = ["async", true, "type", "module", "src", qwikLoaderBundle];
2779
- if (nonce) {
2780
- scriptAttrs.push("nonce", nonce);
2781
- }
2782
- this.openElement("script", scriptAttrs);
2783
- this.closeElement();
2784
- }
2785
- }
2786
- emitQwikLoaderInline() {
2787
- var _a;
2788
- this.qlInclude = 2 /* Done */;
2789
- const qwikLoaderScript = getQwikLoaderScript({ debug: this.renderOptions.debug });
2790
- const scriptAttrs = ["id", "qwikloader", "async", true, "type", "module"];
2791
- if ((_a = this.renderOptions.serverData) == null ? void 0 : _a.nonce) {
2792
- scriptAttrs.push("nonce", this.renderOptions.serverData.nonce);
2793
- }
2794
- this.openElement("script", scriptAttrs);
2795
- this.write(qwikLoaderScript);
2796
- this.closeElement();
2797
- }
2798
- emitQwikLoaderAtBottomIfNeeded() {
2799
- if (!this.isStatic()) {
2800
- if (this.qlInclude !== 2 /* Done */) {
2801
- this.emitQwikLoaderInline();
2802
- }
2803
- this.emitQwikEvents(Array.from(this.serializationCtx.$eventNames$, (s) => JSON.stringify(s)));
2804
- }
2805
- }
2806
- emitQwikEvents(eventNames) {
2807
- var _a;
2808
- if (eventNames.length > 0) {
2809
- const scriptAttrs = [];
2810
- const nonce = (_a = this.renderOptions.serverData) == null ? void 0 : _a.nonce;
2811
- if (nonce) {
2812
- scriptAttrs.push("nonce", nonce);
2813
- }
2814
- this.openElement("script", scriptAttrs);
2815
- this.write(`(window.qwikevents||(window.qwikevents=[])).push(`);
2816
- this.writeArray(eventNames, ", ");
2817
- this.write(")");
2818
- this.closeElement();
2819
- }
2820
- }
2821
- async emitUnclaimedProjection() {
2822
- const unclaimedProjections = this.unclaimedProjections;
2823
- if (unclaimedProjections.length) {
2824
- const previousCurrentComponentNode = this.currentComponentNode;
2825
- try {
2826
- this.openElement(QTemplate, ["hidden", true, "aria-hidden", "true"], null);
2827
- let idx = 0;
2828
- let ssrComponentNode = null;
2829
- let ssrComponentFrame = null;
2830
- let scopedStyleId = null;
2831
- for (let i = 0; i < unclaimedProjections.length; i += 4) {
2832
- this.unclaimedProjectionComponentFrameQueue.push(
2833
- unclaimedProjections[i]
2834
- );
2835
- }
2836
- while (idx < unclaimedProjections.length) {
2837
- const value = unclaimedProjections[idx++];
2838
- if (value instanceof SsrComponentFrame) {
2839
- ssrComponentNode = this.currentComponentNode = value.componentNode;
2840
- ssrComponentFrame = value;
2841
- scopedStyleId = unclaimedProjections[idx++];
2842
- } else if (typeof value === "string") {
2843
- const children = unclaimedProjections[idx++];
2844
- if (!(ssrComponentFrame == null ? void 0 : ssrComponentFrame.hasSlot(value))) {
2845
- ssrComponentFrame && ssrComponentFrame.componentNode.removeProp(value);
2846
- continue;
2847
- }
2848
- this.unclaimedProjectionComponentFrameQueue.shift();
2849
- this.openFragment(
2850
- import_build8.isDev ? [DEBUG_TYPE, "P" /* Projection */, QSlotParent, ssrComponentNode.id] : [QSlotParent, ssrComponentNode.id]
2851
- );
2852
- const lastNode = this.getOrCreateLastNode();
2853
- if (lastNode.vnodeData) {
2854
- lastNode.vnodeData[0] |= 16 /* SERIALIZE */;
2855
- }
2856
- ssrComponentNode == null ? void 0 : ssrComponentNode.setProp(value, lastNode.id);
2857
- await (0, import_internal2._walkJSX)(this, children, {
2858
- currentStyleScoped: scopedStyleId,
2859
- parentComponentFrame: null
2860
- });
2861
- this.closeFragment();
2862
- } else {
2863
- throw Error();
2864
- }
2865
- }
2866
- this.closeElement();
2867
- } finally {
2868
- this.currentComponentNode = previousCurrentComponentNode;
2869
- }
2870
- }
2871
- }
2872
- // Keep in sync with process-vnode-data.unit.ts
2873
- emitVNodeSeparators(lastSerializedIdx, elementIdx) {
2874
- let skipCount = elementIdx - lastSerializedIdx;
2875
- while (skipCount != 0) {
2876
- if (skipCount >= 8192) {
2877
- this.write(VNodeDataSeparator.ADVANCE_8192_CH);
2878
- skipCount -= 8192;
2879
- } else {
2880
- skipCount & 4096 && this.write(VNodeDataSeparator.ADVANCE_4096_CH);
2881
- skipCount & 2048 && this.write(VNodeDataSeparator.ADVANCE_2048_CH);
2882
- skipCount & 1024 && this.write(VNodeDataSeparator.ADVANCE_1024_CH);
2883
- skipCount & 512 && this.write(VNodeDataSeparator.ADVANCE_512_CH);
2884
- skipCount & 256 && this.write(VNodeDataSeparator.ADVANCE_256_CH);
2885
- skipCount & 128 && this.write(VNodeDataSeparator.ADVANCE_128_CH);
2886
- skipCount & 64 && this.write(VNodeDataSeparator.ADVANCE_64_CH);
2887
- skipCount & 32 && this.write(VNodeDataSeparator.ADVANCE_32_CH);
2888
- skipCount & 16 && this.write(VNodeDataSeparator.ADVANCE_16_CH);
2889
- skipCount & 8 && this.write(VNodeDataSeparator.ADVANCE_8_CH);
2890
- skipCount & 4 && this.write(VNodeDataSeparator.ADVANCE_4_CH);
2891
- skipCount & 2 && this.write(VNodeDataSeparator.ADVANCE_2_CH);
2892
- skipCount & 1 && this.write(VNodeDataSeparator.ADVANCE_1_CH);
2893
- skipCount = 0;
2894
- }
2895
- }
2896
- return elementIdx;
2897
- }
2898
- createAndPushFrame(elementName, depthFirstElementIdx, currentFile) {
2899
- let tagNesting = 10 /* ANYTHING */;
2900
- if (import_build8.isDev) {
2901
- if (!this.currentElementFrame) {
2902
- tagNesting = initialTag(elementName);
2903
- } else {
2904
- let frame2 = this.currentElementFrame;
2905
- const previousTagNesting = frame2.tagNesting;
2906
- tagNesting = isTagAllowed(previousTagNesting, elementName);
2907
- if (tagNesting === 0 /* NOT_ALLOWED */) {
2908
- const frames = [];
2909
- while (frame2) {
2910
- frames.unshift(frame2);
2911
- frame2 = frame2.parent;
2912
- }
2913
- const text = [];
2914
- if (currentFile) {
2915
- text.push(`Error found in file: ${currentFile}`);
2916
- }
2917
- text.push(
2918
- `HTML rules do not allow '<${elementName}>' at this location.`,
2919
- ` (The HTML parser will try to recover by auto-closing or inserting additional tags which will confuse Qwik when it resumes.)`,
2920
- ` Offending tag: <${elementName}>`,
2921
- ` Existing tag context:`
2922
- );
2923
- let indent = " ";
2924
- let lastName = "";
2925
- for (const frame3 of frames) {
2926
- const [name, example] = allowedContent(frame3.tagNesting);
2927
- text.push(
2928
- `${indent}<${frame3.elementName}>${lastName !== name ? ` [${name}]${example ? ` -> ${example}` : ""}` : ""}`
2929
- );
2930
- lastName = name;
2931
- indent += " ";
2932
- }
2933
- text.push(
2934
- `${indent}<${elementName}> <= is not allowed as a child of ${allowedContent(previousTagNesting)[0]}.`
2935
- );
2936
- throw newTagError(text.join("\n"));
2937
- }
2938
- }
2939
- }
2940
- const frame = {
2941
- tagNesting,
2942
- parent: this.currentElementFrame,
2943
- elementName,
2944
- depthFirstElementIdx,
2945
- vNodeData: [0 /* NONE */],
2946
- currentFile: import_build8.isDev ? currentFile || null : null
2947
- };
2948
- this.currentElementFrame = frame;
2949
- this.vNodeDatas.push(frame.vNodeData);
2950
- }
2951
- popFrame() {
2952
- const closingFrame = this.currentElementFrame;
2953
- this.currentElementFrame = closingFrame.parent;
2954
- return closingFrame;
2955
- }
2956
- ////////////////////////////////////
2957
- write(text) {
2958
- this.size += text.length;
2959
- this.writer.write(text);
2960
- }
2961
- writeArray(array, separator) {
2962
- for (let i = 0; i < array.length; i++) {
2963
- const element = array[i];
2964
- if (i > 0) {
2965
- this.write(separator);
2966
- }
2967
- this.write(element);
2968
- }
2969
- }
2970
- writeAttrs(tag, attrs, isConst, currentFile) {
2971
- let innerHTML = void 0;
2972
- if (attrs.length) {
2973
- for (let i = 0; i < attrs.length; i++) {
2974
- let key = attrs[i++];
2975
- let value = attrs[i];
2976
- let styleScopedId = null;
2977
- if (isSSRUnsafeAttr(key)) {
2978
- if (import_build8.isDev) {
2979
- throw qError(32 /* unsafeAttr */);
2980
- }
2981
- continue;
2982
- }
2983
- if (key === "class" && Array.isArray(value)) {
2984
- const [signalValue, styleId] = value;
2985
- value = signalValue;
2986
- styleScopedId = styleId;
2987
- }
2988
- if (key === "ref") {
2989
- const lastNode = this.getOrCreateLastNode();
2990
- if ((0, import_internal2.isSignal)(value)) {
2991
- value.$untrackedValue$ = new DomRef(lastNode);
2992
- continue;
2993
- } else if (typeof value === "function") {
2994
- value(new DomRef(lastNode));
2995
- continue;
2996
- } else if (value == null) {
2997
- continue;
2998
- } else {
2999
- throw qError(15 /* invalidRefValue */, [currentFile]);
3000
- }
3001
- }
3002
- if ((0, import_internal2.isSignal)(value)) {
3003
- const lastNode = this.getOrCreateLastNode();
3004
- const signalData = new import_internal2._SubscriptionData({
3005
- $scopedStyleIdPrefix$: styleScopedId,
3006
- $isConst$: isConst
3007
- });
3008
- const signal = value;
3009
- value = retryOnPromise(
3010
- () => this.trackSignalValue(signal, lastNode, key, signalData)
3011
- );
3012
- }
3013
- if (isPromise(value)) {
3014
- const lastNode = this.getOrCreateLastNode();
3015
- this.addPromiseAttribute(value);
3016
- value.then((resolvedValue) => {
3017
- this.addBackpatchEntry(lastNode.id, key, resolvedValue);
3018
- });
3019
- continue;
3020
- }
3021
- if (key === dangerouslySetInnerHTML) {
3022
- if (value) {
3023
- innerHTML = String(value);
3024
- key = QContainerAttr;
3025
- value = "html" /* HTML */;
3026
- }
3027
- if (tag === "style") {
3028
- continue;
3029
- }
3030
- }
3031
- if (tag === "textarea" && key === "value") {
3032
- if (value && typeof value !== "string") {
3033
- if (import_build8.isDev) {
3034
- throw qError(23 /* wrongTextareaValue */, [currentFile, value]);
3035
- }
3036
- continue;
3037
- }
3038
- innerHTML = escapeHTML(value || "");
3039
- key = QContainerAttr;
3040
- value = "text" /* TEXT */;
3041
- }
3042
- const serializedValue = serializeAttribute(key, value, styleScopedId);
3043
- if (serializedValue != null && serializedValue !== false) {
3044
- this.write(" ");
3045
- this.write(key);
3046
- if (serializedValue !== true) {
3047
- this.write('="');
3048
- const strValue = escapeHTML(String(serializedValue));
3049
- this.write(strValue);
3050
- this.write('"');
3051
- }
3052
- }
3053
- }
3054
- }
3055
- return innerHTML;
3056
- }
3057
- addPromiseAttribute(promise) {
3058
- this.promiseAttributes ||= [];
3059
- this.promiseAttributes.push(promise);
3060
- }
3061
- async resolvePromiseAttributes() {
3062
- if (this.promiseAttributes) {
3063
- await Promise.all(this.promiseAttributes);
3064
- this.promiseAttributes = null;
3065
- }
3066
- }
3067
- };
3068
- var isQwikStyleElement = (tag, attrs) => {
3069
- if (tag === "style" && attrs != null) {
3070
- for (let i = 0; i < attrs.length; i = i + 2) {
3071
- const attr = attrs[i];
3072
- if (attr === QStyle || attr === QScopedStyle) {
3073
- return true;
3074
- }
3075
- }
3076
- }
3077
- return false;
3078
- };
3079
- function newTagError(text) {
3080
- return qError(12 /* tagError */, [text]);
3081
- }
3082
- function hasDestroy(obj) {
3083
- return obj && typeof obj === "object" && typeof obj.$destroy$ === "function";
3084
- }
3085
- function isSSRUnsafeAttr(name) {
3086
- for (let idx = 0; idx < name.length; idx++) {
3087
- const ch = name.charCodeAt(idx);
3088
- if (ch === 62 || ch === 47 || ch === 61 || ch === 34 || ch === 39 || ch === 9 || ch === 10 || ch === 12 || ch === 32) {
3089
- return true;
3090
- }
3091
- }
3092
- return false;
3093
- }
3094
- function hash() {
3095
- return Math.random().toString(36).slice(2);
3096
- }
3097
-
3098
- // packages/qwik/src/server/ssr-render.ts
3099
- var import_qwik_client_manifest = require("@qwik-client-manifest");
3100
- var renderToString = async (jsx, opts = {}) => {
3101
- const chunks = [];
3102
- const stream = {
3103
- write(chunk) {
3104
- chunks.push(chunk);
3105
- }
3106
- };
3107
- const result = await renderToStream(jsx, { ...opts, stream });
3108
- return {
3109
- isStatic: result.isStatic,
3110
- timing: result.timing,
3111
- manifest: result.manifest,
3112
- snapshotResult: result.snapshotResult,
3113
- html: chunks.join("")
3114
- };
3115
- };
3116
- var renderToStream = async (jsx, opts) => {
3117
- var _a, _b;
3118
- const timing = {
3119
- firstFlush: 0,
3120
- render: 0,
3121
- snapshot: 0
3122
- };
3123
- const containerTagName = opts.containerTagName ?? "html";
3124
- const buildBase = getBuildBase(opts);
3125
- const resolvedManifest = resolveManifest(opts.manifest);
3126
- const locale = typeof opts.locale === "function" ? opts.locale(opts) : ((_a = opts.serverData) == null ? void 0 : _a.locale) || opts.locale || ((_b = opts.containerAttributes) == null ? void 0 : _b.locale) || "";
3127
- const { stream, flush, networkFlushes } = handleStreaming(opts, timing);
3128
- const ssrContainer = ssrCreateContainer({
3129
- tagName: containerTagName,
3130
- locale,
3131
- writer: stream,
3132
- timing,
3133
- buildBase,
3134
- resolvedManifest,
3135
- renderOptions: opts
3136
- });
3137
- await setServerPlatform(opts, resolvedManifest);
3138
- await ssrContainer.render(jsx);
3139
- await ssrContainer.$scheduler$(255 /* WAIT_FOR_QUEUE */).$returnValue$;
3140
- flush();
3141
- const snapshotResult = getSnapshotResult(ssrContainer);
3142
- const isDynamic = snapshotResult.resources.some((r) => r._cache !== Infinity);
3143
- const result = {
3144
- snapshotResult,
3145
- flushes: networkFlushes,
3146
- manifest: resolvedManifest == null ? void 0 : resolvedManifest.manifest,
3147
- size: ssrContainer.size,
3148
- isStatic: !isDynamic,
3149
- timing
3150
- };
3151
- return result;
3152
- };
3153
- function getSnapshotResult(ssrContainer) {
3154
- const hasListeners = !ssrContainer.isStatic();
3155
- const canRender = false;
3156
- return hasListeners ? {
3157
- funcs: Array.from(ssrContainer.serializationCtx.$syncFns$),
3158
- mode: canRender ? "render" : "listeners",
3159
- qrls: Array.from(ssrContainer.serializationCtx.$eventQrls$),
3160
- resources: Array.from(ssrContainer.serializationCtx.$resources$)
3161
- } : {
3162
- funcs: [],
3163
- mode: "static",
3164
- qrls: [],
3165
- resources: Array.from(ssrContainer.serializationCtx.$resources$)
3166
- };
3167
- }
3168
- function handleStreaming(opts, timing) {
3169
- var _a;
3170
- const firstFlushTimer = createTimer();
3171
- let stream = opts.stream;
3172
- let bufferSize = 0;
3173
- let buffer = "";
3174
- let networkFlushes = 0;
3175
- const inOrderStreaming = ((_a = opts.streaming) == null ? void 0 : _a.inOrder) ?? {
3176
- strategy: "auto",
3177
- maximumInitialChunk: 2e4,
3178
- maximumChunk: 1e4
3179
- };
3180
- const nativeStream = stream;
3181
- function flush() {
3182
- if (buffer) {
3183
- nativeStream.write(buffer);
3184
- buffer = "";
3185
- bufferSize = 0;
3186
- networkFlushes++;
3187
- if (networkFlushes === 1) {
3188
- timing.firstFlush = firstFlushTimer();
3189
- }
3190
- }
3191
- }
3192
- function enqueue(chunk) {
3193
- const len = chunk.length;
3194
- bufferSize += len;
3195
- buffer += chunk;
3196
- }
3197
- switch (inOrderStreaming.strategy) {
3198
- case "disabled":
3199
- stream = {
3200
- write(chunk) {
3201
- if (shouldSkipChunk(chunk)) {
3202
- return;
3203
- }
3204
- enqueue(chunk);
3205
- }
3206
- };
3207
- break;
3208
- case "direct":
3209
- stream = {
3210
- write(chunk) {
3211
- if (shouldSkipChunk(chunk)) {
3212
- return;
3213
- }
3214
- nativeStream.write(chunk);
3215
- }
3216
- };
3217
- break;
3218
- case "auto":
3219
- let openedSSRStreamBlocks = 0;
3220
- let forceFlush = false;
3221
- const minimumChunkSize = inOrderStreaming.maximumChunk ?? 0;
3222
- const initialChunkSize = inOrderStreaming.maximumInitialChunk ?? 0;
3223
- stream = {
3224
- write(chunk) {
3225
- if (chunk === void 0 || chunk === null) {
3226
- return;
3227
- }
3228
- if (chunk === "<!--" + FLUSH_COMMENT + "-->") {
3229
- forceFlush = true;
3230
- } else if (chunk === "<!--" + STREAM_BLOCK_START_COMMENT + "-->") {
3231
- openedSSRStreamBlocks++;
3232
- } else if (chunk === "<!--" + STREAM_BLOCK_END_COMMENT + "-->") {
3233
- openedSSRStreamBlocks--;
3234
- if (openedSSRStreamBlocks === 0) {
3235
- forceFlush = true;
3236
- }
3237
- } else {
3238
- enqueue(chunk);
3239
- }
3240
- const maxBufferSize = networkFlushes === 0 ? initialChunkSize : minimumChunkSize;
3241
- if (openedSSRStreamBlocks === 0 && (forceFlush || bufferSize >= maxBufferSize)) {
3242
- forceFlush = false;
3243
- flush();
3244
- }
3245
- }
3246
- };
3247
- break;
3248
- }
3249
- return {
3250
- stream,
3251
- flush,
3252
- networkFlushes
3253
- };
3254
- }
3255
- function shouldSkipChunk(chunk) {
3256
- return chunk === void 0 || chunk === null || chunk === "<!--" + FLUSH_COMMENT + "-->" || chunk === "<!--" + STREAM_BLOCK_START_COMMENT + "-->" || chunk === "<!--" + STREAM_BLOCK_END_COMMENT + "-->";
3257
- }
3258
- function resolveManifest(manifest) {
3259
- const mergedManifest = manifest ? { ...import_qwik_client_manifest.manifest, ...manifest } : import_qwik_client_manifest.manifest;
3260
- if (!mergedManifest || "mapper" in mergedManifest) {
3261
- return mergedManifest;
3262
- }
3263
- if (mergedManifest.mapping) {
3264
- const mapper = {};
3265
- Object.entries(mergedManifest.mapping).forEach(([symbol, bundleFilename]) => {
3266
- mapper[getSymbolHash(symbol)] = [symbol, bundleFilename];
3267
- });
3268
- return {
3269
- mapper,
3270
- manifest: mergedManifest,
3271
- injections: mergedManifest.injections || []
3272
- };
3273
- }
3274
- return void 0;
3275
- }
3276
- var Q_FUNCS_PREFIX = 'document["qFuncs_HASH"]=';
3277
-
3278
- // packages/qwik/src/server/index.ts
3279
- async function setServerPlatform2(manifest) {
3280
- const platform = createPlatform({ manifest }, resolveManifest(manifest));
3281
- (0, import_core3.setPlatform)(platform);
3282
- }
3283
- // Annotate the CommonJS export names for ESM import in node:
3284
- 0 && (module.exports = {
3285
- getQwikBackpatchExecutorScript,
3286
- getQwikLoaderScript,
3287
- getQwikPrefetchWorkerScript,
3288
- renderToStream,
3289
- renderToString,
3290
- resolveManifest,
3291
- setServerPlatform,
3292
- versions
3293
- });
3294
- return module.exports; })(typeof module === 'object' && module.exports ? module : { exports: {} });