@askrjs/askr 0.0.1 → 0.0.3

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/README.md +18 -10
  2. package/dist/chunk-2ONGHQ7Z.js +3115 -0
  3. package/dist/chunk-2ONGHQ7Z.js.map +1 -0
  4. package/dist/{chunk-UUM5W2RM.js → chunk-H3NSVHA7.js} +2 -6
  5. package/dist/chunk-H3NSVHA7.js.map +1 -0
  6. package/dist/chunk-JHOGWTAW.js +16 -0
  7. package/dist/chunk-JHOGWTAW.js.map +1 -0
  8. package/dist/chunk-OFW6DFBM.js +716 -0
  9. package/dist/chunk-OFW6DFBM.js.map +1 -0
  10. package/dist/chunk-SALJX5PZ.js +26 -0
  11. package/dist/chunk-SALJX5PZ.js.map +1 -0
  12. package/dist/index.cjs +2785 -2327
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +100 -45
  15. package/dist/index.d.ts +100 -45
  16. package/dist/index.js +430 -84
  17. package/dist/index.js.map +1 -1
  18. package/dist/jsx/jsx-dev-runtime.cjs +9 -3
  19. package/dist/jsx/jsx-dev-runtime.cjs.map +1 -1
  20. package/dist/jsx/jsx-dev-runtime.d.cts +4 -9
  21. package/dist/jsx/jsx-dev-runtime.d.ts +4 -9
  22. package/dist/jsx/jsx-dev-runtime.js +7 -4
  23. package/dist/jsx/jsx-dev-runtime.js.map +1 -1
  24. package/dist/jsx/jsx-runtime.cjs +14 -5
  25. package/dist/jsx/jsx-runtime.cjs.map +1 -1
  26. package/dist/jsx/jsx-runtime.d.cts +9 -6
  27. package/dist/jsx/jsx-runtime.d.ts +9 -6
  28. package/dist/jsx/jsx-runtime.js +6 -4
  29. package/dist/{navigate-NLQOZQGM.js → navigate-CZEUXFPM.js} +5 -5
  30. package/dist/{route-TVYWYCEJ.js → route-USEXGOBT.js} +4 -4
  31. package/dist/{ssr-4ELUFK65.js → ssr-QJ5NTQR6.js} +9 -5
  32. package/dist/{types-DUDmnzD8.d.cts → types-DLTViI21.d.cts} +15 -3
  33. package/dist/{types-DUDmnzD8.d.ts → types-DLTViI21.d.ts} +15 -3
  34. package/package.json +7 -4
  35. package/src/jsx/index.ts +4 -0
  36. package/src/jsx/jsx-dev-runtime.ts +7 -10
  37. package/src/jsx/jsx-runtime.ts +23 -11
  38. package/src/jsx/types.ts +22 -3
  39. package/src/jsx/utils.ts +19 -0
  40. package/dist/chunk-4CV4JOE5.js +0 -27
  41. package/dist/chunk-HIWJVOS4.js +0 -503
  42. package/dist/chunk-HIWJVOS4.js.map +0 -1
  43. package/dist/chunk-L7RL4LYV.js +0 -3442
  44. package/dist/chunk-L7RL4LYV.js.map +0 -1
  45. package/dist/chunk-UUM5W2RM.js.map +0 -1
  46. package/dist/chunk-YNH3D4KW.js +0 -29
  47. package/dist/chunk-YNH3D4KW.js.map +0 -1
  48. package/dist/ssr-4ELUFK65.js.map +0 -1
  49. package/src/jsx/react-jsx-runtime.d.ts +0 -0
  50. /package/dist/{chunk-4CV4JOE5.js.map → navigate-CZEUXFPM.js.map} +0 -0
  51. /package/dist/{navigate-NLQOZQGM.js.map → route-USEXGOBT.js.map} +0 -0
  52. /package/dist/{route-TVYWYCEJ.js.map → ssr-QJ5NTQR6.js.map} +0 -0
@@ -0,0 +1,716 @@
1
+ import {
2
+ createComponentInstance,
3
+ getCurrentComponentInstance,
4
+ logger,
5
+ route_exports,
6
+ setCurrentComponentInstance
7
+ } from "./chunk-2ONGHQ7Z.js";
8
+ import {
9
+ ELEMENT_TYPE,
10
+ Fragment
11
+ } from "./chunk-JHOGWTAW.js";
12
+
13
+ // src/jsx/utils.ts
14
+ function isElement(value) {
15
+ return typeof value === "object" && value !== null && value.$$typeof === ELEMENT_TYPE;
16
+ }
17
+ function cloneElement(element, props) {
18
+ return {
19
+ ...element,
20
+ props: { ...element.props, ...props }
21
+ };
22
+ }
23
+
24
+ // src/foundations/portal.tsx
25
+ function definePortal() {
26
+ if (typeof createPortalSlot !== "function") {
27
+ let HostFallback2 = function() {
28
+ hosts = hosts.filter((h) => h.mounted !== false);
29
+ const inst = getCurrentComponentInstance();
30
+ if (inst && !hosts.includes(inst)) hosts.push(inst);
31
+ const owner = hosts.find((h) => h.mounted === true) || null;
32
+ const mountedHosts = hosts.filter((h) => h.mounted === true);
33
+ if (mountedHosts.length > 1) {
34
+ logger.warn(
35
+ "[Portal] multiple hosts are mounted for same portal; first mounted host will be owner"
36
+ );
37
+ }
38
+ if (inst && owner && owner !== inst) {
39
+ logger.debug(
40
+ "[Portal] non-owner reader detected; only owner renders portal content"
41
+ );
42
+ }
43
+ if (process.env.NODE_ENV !== "production") {
44
+ const ns = globalThis.__ASKR__ || (globalThis.__ASKR__ = {});
45
+ ns.__PORTAL_READS = (ns.__PORTAL_READS || 0) + 1;
46
+ }
47
+ if (process.env.NODE_ENV !== "production" && inst && owner && inst === owner) {
48
+ logger.debug("[Portal] owner read ->", inst.id, "pending=", pending);
49
+ const ns = globalThis.__ASKR__ || (globalThis.__ASKR__ = {});
50
+ ns.__PORTAL_HOST_ATTACHED = !!(inst && inst.target);
51
+ ns.__PORTAL_HOST_ID = inst ? inst.id : void 0;
52
+ }
53
+ return inst === owner ? pending : void 0;
54
+ };
55
+ var HostFallback = HostFallback2;
56
+ let hosts = [];
57
+ let pending;
58
+ HostFallback2.render = function RenderFallback(props) {
59
+ hosts = hosts.filter((h) => h.mounted !== false);
60
+ const owner = hosts.find((h) => h.mounted === true) || null;
61
+ if (!owner) {
62
+ logger.debug(
63
+ "[Portal] fallback.write dropped -> no owner or not mounted",
64
+ props?.children
65
+ );
66
+ return null;
67
+ }
68
+ pending = props.children;
69
+ logger.debug("[Portal] fallback.write ->", pending, "owner=", owner.id);
70
+ if (process.env.NODE_ENV !== "production") {
71
+ const ns = globalThis.__ASKR__ || (globalThis.__ASKR__ = {});
72
+ ns.__PORTAL_WRITES = (ns.__PORTAL_WRITES || 0) + 1;
73
+ }
74
+ if (owner && owner.notifyUpdate) {
75
+ if (process.env.NODE_ENV !== "production")
76
+ logger.debug(
77
+ "[Portal] fallback.write notify ->",
78
+ owner.id,
79
+ !!owner.notifyUpdate
80
+ );
81
+ owner.notifyUpdate();
82
+ }
83
+ return null;
84
+ };
85
+ return HostFallback2;
86
+ }
87
+ const slot = createPortalSlot();
88
+ function PortalHost() {
89
+ return slot.read();
90
+ }
91
+ PortalHost.render = function PortalRender(props) {
92
+ logger.debug("[Portal] write ->", props?.children);
93
+ if (process.env.NODE_ENV !== "production") {
94
+ const ns = globalThis.__ASKR__ || (globalThis.__ASKR__ = {});
95
+ ns.__PORTAL_WRITES = (ns.__PORTAL_WRITES || 0) + 1;
96
+ }
97
+ slot.write(props.children);
98
+ return null;
99
+ };
100
+ return PortalHost;
101
+ }
102
+ var _defaultPortal;
103
+ var _defaultPortalIsFallback = false;
104
+ function _resetDefaultPortal() {
105
+ _defaultPortal = void 0;
106
+ _defaultPortalIsFallback = false;
107
+ }
108
+ function ensureDefaultPortal() {
109
+ logger.debug(
110
+ "[DefaultPortal] ensureDefaultPortal _defaultPortalIsFallback=",
111
+ _defaultPortalIsFallback,
112
+ "createPortalSlot=",
113
+ typeof createPortalSlot === "function"
114
+ );
115
+ if (!_defaultPortal) {
116
+ if (typeof createPortalSlot === "function") {
117
+ _defaultPortal = definePortal();
118
+ _defaultPortalIsFallback = false;
119
+ logger.debug("[DefaultPortal] created real portal");
120
+ } else {
121
+ _defaultPortal = definePortal();
122
+ _defaultPortalIsFallback = true;
123
+ logger.debug("[DefaultPortal] created fallback portal");
124
+ }
125
+ return _defaultPortal;
126
+ }
127
+ if (_defaultPortalIsFallback && typeof createPortalSlot === "function") {
128
+ const real = definePortal();
129
+ _defaultPortal = real;
130
+ _defaultPortalIsFallback = false;
131
+ }
132
+ if (!_defaultPortalIsFallback && typeof createPortalSlot !== "function") {
133
+ const fallback = definePortal();
134
+ _defaultPortal = fallback;
135
+ _defaultPortalIsFallback = true;
136
+ logger.debug("[DefaultPortal] reverted to fallback portal");
137
+ }
138
+ return _defaultPortal;
139
+ }
140
+ var DefaultPortal = (() => {
141
+ function Host() {
142
+ const v = ensureDefaultPortal()();
143
+ return v === void 0 ? null : v;
144
+ }
145
+ Host.render = function Render(props) {
146
+ ensureDefaultPortal().render(props);
147
+ return null;
148
+ };
149
+ return Host;
150
+ })();
151
+
152
+ // src/ssr/errors.ts
153
+ var SSRDataMissingError = class _SSRDataMissingError extends Error {
154
+ constructor(message = "Server-side rendering requires all data to be available synchronously. This component attempted to use async data during SSR.") {
155
+ super(message);
156
+ this.code = "SSR_DATA_MISSING";
157
+ this.name = "SSRDataMissingError";
158
+ Object.setPrototypeOf(this, _SSRDataMissingError.prototype);
159
+ }
160
+ };
161
+
162
+ // src/ssr/context.ts
163
+ var current = null;
164
+ function withSSRContext(ctx, fn) {
165
+ const prev = current;
166
+ current = ctx;
167
+ try {
168
+ return fn();
169
+ } finally {
170
+ current = prev;
171
+ }
172
+ }
173
+ function createRenderContext(seed = 12345) {
174
+ return { seed };
175
+ }
176
+ var currentSSRContext = null;
177
+ function getCurrentSSRContext() {
178
+ return currentSSRContext;
179
+ }
180
+ function runWithSSRContext(ctx, fn) {
181
+ const prev = currentSSRContext;
182
+ currentSSRContext = ctx;
183
+ try {
184
+ return fn();
185
+ } finally {
186
+ currentSSRContext = prev;
187
+ }
188
+ }
189
+ function throwSSRDataMissing() {
190
+ throw new SSRDataMissingError();
191
+ }
192
+
193
+ // src/ssr/escape.ts
194
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
195
+ "area",
196
+ "base",
197
+ "br",
198
+ "col",
199
+ "embed",
200
+ "hr",
201
+ "img",
202
+ "input",
203
+ "link",
204
+ "meta",
205
+ "param",
206
+ "source",
207
+ "track",
208
+ "wbr"
209
+ ]);
210
+ var escapeCache = /* @__PURE__ */ new Map();
211
+ var MAX_CACHE_SIZE = 256;
212
+ function escapeText(text) {
213
+ const useCache = text.length <= 64;
214
+ if (useCache) {
215
+ const cached = escapeCache.get(text);
216
+ if (cached !== void 0) return cached;
217
+ }
218
+ const str = String(text);
219
+ if (!str.includes("&") && !str.includes("<") && !str.includes(">")) {
220
+ if (useCache && escapeCache.size < MAX_CACHE_SIZE) {
221
+ escapeCache.set(text, str);
222
+ }
223
+ return str;
224
+ }
225
+ const result = str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
226
+ if (useCache && escapeCache.size < MAX_CACHE_SIZE) {
227
+ escapeCache.set(text, result);
228
+ }
229
+ return result;
230
+ }
231
+ function escapeAttr(value) {
232
+ const str = String(value);
233
+ if (!str.includes("&") && !str.includes('"') && !str.includes("'") && !str.includes("<") && !str.includes(">")) {
234
+ return str;
235
+ }
236
+ return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
237
+ }
238
+ function escapeCssValue(value) {
239
+ const str = String(value);
240
+ if (/(?:url|expression|javascript)\s*\(/i.test(str)) {
241
+ return "";
242
+ }
243
+ return str.replace(/[{}<>\\]/g, "");
244
+ }
245
+ function styleObjToCss(value) {
246
+ if (!value || typeof value !== "object") return null;
247
+ const entries = Object.entries(value);
248
+ if (entries.length === 0) return "";
249
+ let out = "";
250
+ for (const [k, v] of entries) {
251
+ if (v === null || v === void 0 || v === false) continue;
252
+ const prop = k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
253
+ const safeValue = escapeCssValue(String(v));
254
+ if (safeValue) {
255
+ out += `${prop}:${safeValue};`;
256
+ }
257
+ }
258
+ return out;
259
+ }
260
+
261
+ // src/ssr/attrs.ts
262
+ function renderAttrs(props, opts) {
263
+ if (!props || typeof props !== "object") {
264
+ return opts?.returnDangerousHtml ? { attrs: "" } : "";
265
+ }
266
+ let result = "";
267
+ let dangerousHtml;
268
+ for (const [key, value] of Object.entries(props)) {
269
+ if (key === "children") continue;
270
+ if (key === "dangerouslySetInnerHTML") {
271
+ if (value && typeof value === "object" && "__html" in value) {
272
+ dangerousHtml = String(value.__html);
273
+ }
274
+ continue;
275
+ }
276
+ if (key.length >= 3 && key[0] === "o" && key[1] === "n" && key[2] >= "A" && key[2] <= "Z") {
277
+ continue;
278
+ }
279
+ if (key.startsWith("_")) continue;
280
+ const attrName = key === "class" || key === "className" ? "class" : key;
281
+ if (attrName === "style") {
282
+ const css = typeof value === "string" ? value : styleObjToCss(value);
283
+ if (css === null || css === "") continue;
284
+ result += ` style="${escapeAttr(css)}"`;
285
+ continue;
286
+ }
287
+ if (value === true) {
288
+ result += ` ${attrName}`;
289
+ } else if (value === false || value === null || value === void 0) {
290
+ continue;
291
+ } else {
292
+ result += ` ${attrName}="${escapeAttr(String(value))}"`;
293
+ }
294
+ }
295
+ if (opts?.returnDangerousHtml) {
296
+ return { attrs: result, dangerousHtml };
297
+ }
298
+ return result;
299
+ }
300
+
301
+ // src/ssr/sink.ts
302
+ var StringSink = class {
303
+ constructor() {
304
+ this.chunks = [];
305
+ }
306
+ write(html) {
307
+ if (html) this.chunks.push(html);
308
+ }
309
+ end() {
310
+ }
311
+ toString() {
312
+ return this.chunks.join("");
313
+ }
314
+ };
315
+ var StreamSink = class {
316
+ constructor(onChunk, onComplete) {
317
+ this.onChunk = onChunk;
318
+ this.onComplete = onComplete;
319
+ }
320
+ write(html) {
321
+ if (html) this.onChunk(html);
322
+ }
323
+ end() {
324
+ this.onComplete();
325
+ }
326
+ };
327
+
328
+ // src/ssr/stream-render.ts
329
+ function isVNodeLike(x) {
330
+ return !!x && typeof x === "object" && "type" in x;
331
+ }
332
+ function normalizeChildren(node) {
333
+ const n = node;
334
+ const direct = Array.isArray(n?.children) ? n?.children : null;
335
+ const fromProps = n?.props?.children;
336
+ const raw = direct ?? fromProps;
337
+ if (raw === null || raw === void 0 || raw === false) return [];
338
+ if (Array.isArray(raw)) return raw;
339
+ return [raw];
340
+ }
341
+ function renderChildrenToSink(children, sink, ctx) {
342
+ for (const c of children)
343
+ renderNodeToSink(
344
+ c,
345
+ sink,
346
+ ctx
347
+ );
348
+ }
349
+ function isPromiseLike(x) {
350
+ if (!x || typeof x !== "object") return false;
351
+ const then = x.then;
352
+ return typeof then === "function";
353
+ }
354
+ function executeComponent(type, props, ctx) {
355
+ const res = type(props ?? {}, { signal: ctx.signal });
356
+ if (isPromiseLike(res)) {
357
+ throwSSRDataMissing();
358
+ }
359
+ return res;
360
+ }
361
+ function renderNodeToSink(node, sink, ctx) {
362
+ if (node === null || node === void 0) return;
363
+ if (typeof node === "string") {
364
+ sink.write(escapeText(node));
365
+ return;
366
+ }
367
+ if (typeof node === "number") {
368
+ sink.write(escapeText(String(node)));
369
+ return;
370
+ }
371
+ if (!isVNodeLike(node)) return;
372
+ const { type, props } = node;
373
+ if (typeof type === "symbol" && (type === Fragment || String(type) === "Symbol(Fragment)")) {
374
+ const children = normalizeChildren(node);
375
+ renderChildrenToSink(children, sink, ctx);
376
+ return;
377
+ }
378
+ if (typeof type === "function") {
379
+ const out = withSSRContext(
380
+ ctx,
381
+ () => executeComponent(type, props, ctx)
382
+ );
383
+ renderNodeToSink(
384
+ out,
385
+ sink,
386
+ ctx
387
+ );
388
+ return;
389
+ }
390
+ const tag = String(type);
391
+ const { attrs, dangerousHtml } = renderAttrs(props, {
392
+ returnDangerousHtml: true
393
+ });
394
+ if (VOID_ELEMENTS.has(tag)) {
395
+ sink.write(`<${tag}${attrs} />`);
396
+ return;
397
+ }
398
+ sink.write(`<${tag}${attrs}>`);
399
+ if (dangerousHtml !== void 0) {
400
+ sink.write(dangerousHtml);
401
+ } else {
402
+ const children = normalizeChildren(node);
403
+ renderChildrenToSink(children, sink, ctx);
404
+ }
405
+ sink.write(`</${tag}>`);
406
+ }
407
+
408
+ // src/ssr/render-keys.ts
409
+ var keyCounter = 0;
410
+ var currentRenderData = null;
411
+ function getCurrentRenderData() {
412
+ return currentRenderData;
413
+ }
414
+ function resetKeyCounter() {
415
+ keyCounter = 0;
416
+ }
417
+ function getNextKey() {
418
+ return `r:${keyCounter++}`;
419
+ }
420
+ function startRenderPhase(data) {
421
+ currentRenderData = data ?? null;
422
+ resetKeyCounter();
423
+ }
424
+ function stopRenderPhase() {
425
+ currentRenderData = null;
426
+ resetKeyCounter();
427
+ }
428
+ var PREPASS_REMOVED_MSG = "SSR collection/prepass is removed: SSR is strictly synchronous";
429
+ async function resolvePlan(_plan) {
430
+ throw new Error(
431
+ `${PREPASS_REMOVED_MSG}; async resource plans are not supported`
432
+ );
433
+ }
434
+ function collectResources(_opts) {
435
+ throw new Error(`${PREPASS_REMOVED_MSG}; collectResources is disabled`);
436
+ }
437
+ var resolveResources = resolvePlan;
438
+
439
+ // src/ssr/index.ts
440
+ var __ssrGuardStack = [];
441
+ function pushSSRStrictPurityGuard() {
442
+ if (process.env.NODE_ENV === "production") return;
443
+ __ssrGuardStack.push({
444
+ random: Reflect.get(Math, "random"),
445
+ now: Reflect.get(Date, "now")
446
+ });
447
+ Reflect.set(Math, "random", () => {
448
+ throw new Error(
449
+ "SSR Strict Purity: Math.random is not allowed during synchronous SSR. Use the provided `ssr` context RNG instead."
450
+ );
451
+ });
452
+ Reflect.set(Date, "now", () => {
453
+ throw new Error(
454
+ "SSR Strict Purity: Date.now is not allowed during synchronous SSR. Pass timestamps explicitly or use deterministic helpers."
455
+ );
456
+ });
457
+ }
458
+ function popSSRStrictPurityGuard() {
459
+ if (process.env.NODE_ENV === "production") return;
460
+ const prev = __ssrGuardStack.pop();
461
+ if (prev) {
462
+ Reflect.set(Math, "random", prev.random);
463
+ Reflect.set(Date, "now", prev.now);
464
+ }
465
+ }
466
+ function renderChildSync(child, ctx) {
467
+ if (typeof child === "string") return escapeText(child);
468
+ if (typeof child === "number") return escapeText(String(child));
469
+ if (child === null || child === void 0 || child === false) return "";
470
+ if (typeof child === "object" && child !== null && "type" in child) {
471
+ return renderNodeSync(child, ctx);
472
+ }
473
+ return "";
474
+ }
475
+ function renderChildrenSync(children, ctx) {
476
+ if (!children || !Array.isArray(children) || children.length === 0) return "";
477
+ let result = "";
478
+ for (const child of children) result += renderChildSync(child, ctx);
479
+ return result;
480
+ }
481
+ function renderNodeSync(node, ctx) {
482
+ const { type, props } = node;
483
+ if (process.env.NODE_ENV !== "production") {
484
+ try {
485
+ logger.warn("[SSR] renderNodeSync type:", typeof type, type);
486
+ } catch {
487
+ }
488
+ }
489
+ if (typeof type === "function") {
490
+ const result = executeComponentSync(type, props, ctx);
491
+ if (result instanceof Promise) {
492
+ throwSSRDataMissing();
493
+ }
494
+ return renderNodeSync(result, ctx);
495
+ }
496
+ if (typeof type === "symbol") {
497
+ if (type === Fragment) {
498
+ const childrenArr = Array.isArray(node.children) ? node.children : Array.isArray(props?.children) ? props?.children : void 0;
499
+ if (process.env.NODE_ENV !== "production") {
500
+ try {
501
+ logger.warn("[SSR] fragment children length:", childrenArr?.length);
502
+ } catch {
503
+ }
504
+ }
505
+ return renderChildrenSync(childrenArr, ctx);
506
+ }
507
+ throw new Error(
508
+ `renderNodeSync: unsupported VNode symbol type: ${String(type)}`
509
+ );
510
+ }
511
+ const typeStr = type;
512
+ if (VOID_ELEMENTS.has(typeStr)) {
513
+ const attrs2 = renderAttrs(props);
514
+ return `<${typeStr}${attrs2} />`;
515
+ }
516
+ const { attrs, dangerousHtml } = renderAttrs(props, {
517
+ returnDangerousHtml: true
518
+ });
519
+ if (dangerousHtml !== void 0) {
520
+ return `<${typeStr}${attrs}>${dangerousHtml}</${typeStr}>`;
521
+ }
522
+ const children = node.children;
523
+ const childrenHtml = renderChildrenSync(children, ctx);
524
+ return `<${typeStr}${attrs}>${childrenHtml}</${typeStr}>`;
525
+ }
526
+ function executeComponentSync(component, props, ctx) {
527
+ try {
528
+ if (process.env.NODE_ENV !== "production") {
529
+ pushSSRStrictPurityGuard();
530
+ }
531
+ const prev = getCurrentComponentInstance();
532
+ const temp = createComponentInstance(
533
+ "ssr-temp",
534
+ component,
535
+ props || {},
536
+ null
537
+ );
538
+ temp.ssr = true;
539
+ setCurrentComponentInstance(temp);
540
+ try {
541
+ return runWithSSRContext(ctx, () => {
542
+ const result = component(props || {}, { ssr: ctx });
543
+ if (result instanceof Promise) {
544
+ throwSSRDataMissing();
545
+ }
546
+ if (typeof result === "string" || typeof result === "number" || typeof result === "boolean" || result === null || result === void 0) {
547
+ const inner = result === null || result === void 0 || result === false ? "" : String(result);
548
+ return {
549
+ $$typeof: ELEMENT_TYPE,
550
+ type: Fragment,
551
+ props: { children: inner ? [inner] : [] }
552
+ };
553
+ }
554
+ return result;
555
+ });
556
+ } finally {
557
+ setCurrentComponentInstance(prev);
558
+ }
559
+ } finally {
560
+ if (process.env.NODE_ENV !== "production") popSSRStrictPurityGuard();
561
+ }
562
+ }
563
+ function renderToStringSync(component, props, options) {
564
+ const seed = options?.seed ?? 12345;
565
+ const ctx = createRenderContext(seed);
566
+ startRenderPhase(options?.data ?? null);
567
+ try {
568
+ const wrapped = (p, c) => {
569
+ const out = component(p ?? {}, c);
570
+ const portalVNode = {
571
+ $$typeof: ELEMENT_TYPE,
572
+ type: DefaultPortal,
573
+ props: {},
574
+ key: "__default_portal"
575
+ };
576
+ if (out == null) {
577
+ return {
578
+ $$typeof: ELEMENT_TYPE,
579
+ type: Fragment,
580
+ props: { children: [portalVNode] }
581
+ };
582
+ }
583
+ return {
584
+ $$typeof: ELEMENT_TYPE,
585
+ type: Fragment,
586
+ props: { children: [out, portalVNode] }
587
+ };
588
+ };
589
+ const node = executeComponentSync(wrapped, props || {}, ctx);
590
+ if (!node) {
591
+ throw new Error("renderToStringSync: wrapped component returned empty");
592
+ }
593
+ return renderNodeSync(node, ctx);
594
+ } finally {
595
+ stopRenderPhase();
596
+ }
597
+ }
598
+ function renderToStringSyncForUrl(opts) {
599
+ const { url, routes, options } = opts;
600
+ const {
601
+ clearRoutes,
602
+ route,
603
+ setServerLocation,
604
+ lockRouteRegistration,
605
+ resolveRoute
606
+ } = route_exports;
607
+ clearRoutes();
608
+ for (const r of routes) {
609
+ route(r.path, r.handler, r.namespace);
610
+ }
611
+ setServerLocation(url);
612
+ if (process.env.NODE_ENV === "production") lockRouteRegistration();
613
+ const resolved = resolveRoute(url);
614
+ if (!resolved)
615
+ throw new Error(`renderToStringSync: no route found for url: ${url}`);
616
+ const seed = options?.seed ?? 12345;
617
+ const ctx = createRenderContext(seed);
618
+ startRenderPhase(options?.data ?? null);
619
+ try {
620
+ const wrapped = (p, c) => {
621
+ const out = resolved.handler(p ?? {}, c);
622
+ const portalVNode = {
623
+ $$typeof: ELEMENT_TYPE,
624
+ type: DefaultPortal,
625
+ props: {},
626
+ key: "__default_portal"
627
+ };
628
+ if (out == null) {
629
+ return {
630
+ $$typeof: ELEMENT_TYPE,
631
+ type: Fragment,
632
+ props: { children: [portalVNode] }
633
+ };
634
+ }
635
+ return {
636
+ $$typeof: ELEMENT_TYPE,
637
+ type: Fragment,
638
+ props: { children: [out, portalVNode] }
639
+ };
640
+ };
641
+ const node = executeComponentSync(wrapped, resolved.params || {}, ctx);
642
+ return renderNodeSync(node, ctx);
643
+ } finally {
644
+ stopRenderPhase();
645
+ }
646
+ }
647
+ function renderToString(arg) {
648
+ if (typeof arg === "function") {
649
+ return renderToStringSync(
650
+ arg
651
+ );
652
+ }
653
+ const opts = arg;
654
+ const sink = new StringSink();
655
+ renderToSinkInternal({ ...opts, sink });
656
+ sink.end();
657
+ return sink.toString();
658
+ }
659
+ function renderToStream(opts) {
660
+ const sink = new StreamSink(opts.onChunk, opts.onComplete);
661
+ renderToSinkInternal({ ...opts, sink });
662
+ sink.end();
663
+ }
664
+ function renderToSinkInternal(opts) {
665
+ const { url, routes, seed = 12345, data, sink } = opts;
666
+ const {
667
+ clearRoutes,
668
+ route,
669
+ setServerLocation,
670
+ lockRouteRegistration,
671
+ resolveRoute
672
+ } = route_exports;
673
+ clearRoutes();
674
+ for (const r of routes) route(r.path, r.handler, r.namespace);
675
+ setServerLocation(url);
676
+ if (process.env.NODE_ENV === "production") lockRouteRegistration();
677
+ const resolved = resolveRoute(url);
678
+ if (!resolved) throw new Error(`SSR: no route found for url: ${url}`);
679
+ const ctx = {
680
+ url,
681
+ seed,
682
+ data,
683
+ params: resolved.params,
684
+ signal: void 0
685
+ };
686
+ const node = resolved.handler(resolved.params);
687
+ startRenderPhase(data || null);
688
+ try {
689
+ renderNodeToSink(node, sink, ctx);
690
+ } finally {
691
+ stopRenderPhase();
692
+ }
693
+ }
694
+
695
+ export {
696
+ SSRDataMissingError,
697
+ getCurrentSSRContext,
698
+ throwSSRDataMissing,
699
+ getCurrentRenderData,
700
+ getNextKey,
701
+ resolvePlan,
702
+ collectResources,
703
+ resolveResources,
704
+ isElement,
705
+ cloneElement,
706
+ definePortal,
707
+ _resetDefaultPortal,
708
+ DefaultPortal,
709
+ pushSSRStrictPurityGuard,
710
+ popSSRStrictPurityGuard,
711
+ renderToStringSync,
712
+ renderToStringSyncForUrl,
713
+ renderToString,
714
+ renderToStream
715
+ };
716
+ //# sourceMappingURL=chunk-OFW6DFBM.js.map