@absolutejs/absolute 0.7.0 → 0.8.1

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.
package/dist/index.js CHANGED
@@ -9821,9 +9821,94 @@ import { join as join3 } from "path";
9821
9821
  import { cwd, exit } from "process";
9822
9822
  var {$, build: bunBuild } = globalThis.Bun;
9823
9823
 
9824
- // src/build/compileSvelte.ts
9825
- import { mkdir } from "fs/promises";
9824
+ // src/build/generateManifest.ts
9825
+ var generateManifest = (outputs, buildDirectoryAbsolute) => {
9826
+ const manifest = outputs.reduce((accumulator, artifact) => {
9827
+ let relativePath = artifact.path.startsWith(buildDirectoryAbsolute) ? artifact.path.slice(buildDirectoryAbsolute.length) : artifact.path;
9828
+ relativePath = relativePath.replace(/^\/+/, "");
9829
+ const segments = relativePath.split("/");
9830
+ const fileWithHash = segments[segments.length - 1];
9831
+ if (!fileWithHash)
9832
+ return accumulator;
9833
+ const [baseName] = fileWithHash.split(`.${artifact.hash}.`);
9834
+ if (relativePath.includes("svelte/pages")) {
9835
+ accumulator[baseName] = artifact.path;
9836
+ } else if (relativePath.includes("svelte/indexes")) {
9837
+ accumulator[`${baseName}Index`] = `/${relativePath}`;
9838
+ } else {
9839
+ accumulator[baseName] = `/${relativePath}`;
9840
+ }
9841
+ return accumulator;
9842
+ }, {});
9843
+ return manifest;
9844
+ };
9845
+
9846
+ // src/build/generateReactIndexes.ts
9847
+ import { mkdir, rm, writeFile } from "fs/promises";
9826
9848
  import { basename, join } from "path";
9849
+ var {Glob } = globalThis.Bun;
9850
+ var generateReactIndexFiles = async (reactPagesDirectory, reactIndexesDirectory) => {
9851
+ await rm(reactIndexesDirectory, { force: true, recursive: true });
9852
+ await mkdir(reactIndexesDirectory);
9853
+ const pagesGlob = new Glob("*.*");
9854
+ const files = [];
9855
+ for await (const file of pagesGlob.scan({ cwd: reactPagesDirectory })) {
9856
+ files.push(file);
9857
+ }
9858
+ const promises = files.map(async (file) => {
9859
+ const fileName = basename(file);
9860
+ const [componentName] = fileName.split(".");
9861
+ const content = [
9862
+ `import { hydrateRoot } from 'react-dom/client';`,
9863
+ `import type { ComponentType } from 'react'`,
9864
+ `import { ${componentName} } from '../pages/${componentName}';
9865
+ `,
9866
+ `type PropsOf<C> = C extends ComponentType<infer P> ? P : never;
9867
+ `,
9868
+ `declare global {`,
9869
+ ` interface Window {`,
9870
+ ` __INITIAL_PROPS__: PropsOf<typeof ${componentName}>`,
9871
+ ` }`,
9872
+ `}
9873
+ `,
9874
+ `hydrateRoot(document, <${componentName} {...window.__INITIAL_PROPS__} />);`
9875
+ ].join(`
9876
+ `);
9877
+ return writeFile(join(reactIndexesDirectory, `${componentName}Index.tsx`), content);
9878
+ });
9879
+ await Promise.all(promises);
9880
+ };
9881
+
9882
+ // src/build/scanEntryPoints.ts
9883
+ var {Glob: Glob2 } = globalThis.Bun;
9884
+ var scanEntryPoints = async (dir, pattern) => {
9885
+ const entryPaths = [];
9886
+ const glob = new Glob2(pattern);
9887
+ for await (const file of glob.scan({ absolute: true, cwd: dir })) {
9888
+ entryPaths.push(file);
9889
+ }
9890
+ return entryPaths;
9891
+ };
9892
+
9893
+ // src/build/updateScriptTags.ts
9894
+ import { readFile, writeFile as writeFile2 } from "fs/promises";
9895
+ var updateScriptTags = async (manifest, htmlDir) => {
9896
+ const htmlFiles = await scanEntryPoints(htmlDir, "*.html");
9897
+ const tasks = htmlFiles.map(async (filePath) => {
9898
+ const original = await readFile(filePath, "utf8");
9899
+ const updated = Object.entries(manifest).reduce((html, [scriptName, newPath]) => {
9900
+ const esc = scriptName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9901
+ const regex = new RegExp(`(<script[^>]+src=["'])(/?(?:.*/)?${esc})(?:\\.[^."'/]+)?(\\.js)(["'][^>]*>)`, "g");
9902
+ return html.replace(regex, (_, prefix, __, ___, suffix) => `${prefix}${newPath}${suffix}`);
9903
+ }, original);
9904
+ await writeFile2(filePath, updated, "utf8");
9905
+ });
9906
+ await Promise.all(tasks);
9907
+ };
9908
+
9909
+ // src/svelte/compileSvelte.ts
9910
+ import { mkdir as mkdir2 } from "fs/promises";
9911
+ import { basename as basename2, join as join2 } from "path";
9827
9912
  import { env } from "process";
9828
9913
  var {write, file } = globalThis.Bun;
9829
9914
 
@@ -11104,8 +11189,8 @@ function svelte_element_invalid_this(node) {
11104
11189
  w(node, "svelte_element_invalid_this", `\`this\` should be an \`{expression}\`. Using a string attribute value will cause an error in future versions of Svelte
11105
11190
  https://svelte.dev/e/svelte_element_invalid_this`);
11106
11191
  }
11107
- function svelte_self_deprecated(node, name, basename) {
11108
- w(node, "svelte_self_deprecated", `\`<svelte:self>\` is deprecated \u2014 use self-imports (e.g. \`import ${name} from './${basename}'\`) instead
11192
+ function svelte_self_deprecated(node, name, basename2) {
11193
+ w(node, "svelte_self_deprecated", `\`<svelte:self>\` is deprecated \u2014 use self-imports (e.g. \`import ${name} from './${basename2}'\`) instead
11109
11194
  https://svelte.dev/e/svelte_self_deprecated`);
11110
11195
  }
11111
11196
 
@@ -33132,8 +33217,8 @@ function SvelteSelf(node, context) {
33132
33217
  }
33133
33218
  if (context.state.analysis.runes) {
33134
33219
  const name = filename === "(unknown)" ? "Self" : context.state.analysis.name;
33135
- const basename = filename === "(unknown)" ? "Self.svelte" : filename.split(/[/\\]/).pop();
33136
- svelte_self_deprecated(node, name, basename);
33220
+ const basename2 = filename === "(unknown)" ? "Self.svelte" : filename.split(/[/\\]/).pop();
33221
+ svelte_self_deprecated(node, name, basename2);
33137
33222
  }
33138
33223
  visit_component(node, context);
33139
33224
  }
@@ -33430,9 +33515,9 @@ function js(script, root, allow_reactive_declarations, parent) {
33430
33515
  }
33431
33516
  function get_component_name(filename2) {
33432
33517
  const parts = filename2.split(/[/\\]/);
33433
- const basename = parts.pop();
33518
+ const basename2 = parts.pop();
33434
33519
  const last_dir = parts.at(-1);
33435
- let name = basename.replace(".svelte", "");
33520
+ let name = basename2.replace(".svelte", "");
33436
33521
  if (name === "index" && last_dir && last_dir !== "src") {
33437
33522
  name = last_dir;
33438
33523
  }
@@ -34086,13 +34171,13 @@ var handle_body = (nodes, state) => {
34086
34171
  var handle_var_declaration = (node, state) => {
34087
34172
  const index = state.commands.length;
34088
34173
  const open2 = create_sequence();
34089
- const join = create_sequence();
34174
+ const join2 = create_sequence();
34090
34175
  const child_state = { ...state, multiline: false };
34091
34176
  state.commands.push(`${node.kind} `, open2);
34092
34177
  let first = true;
34093
34178
  for (const d of node.declarations) {
34094
34179
  if (!first)
34095
- state.commands.push(join);
34180
+ state.commands.push(join2);
34096
34181
  first = false;
34097
34182
  handle(d, child_state);
34098
34183
  }
@@ -34101,11 +34186,11 @@ var handle_var_declaration = (node, state) => {
34101
34186
  state.multiline = true;
34102
34187
  if (node.declarations.length > 1)
34103
34188
  open2.push(indent);
34104
- join.push(",", newline);
34189
+ join2.push(",", newline);
34105
34190
  if (node.declarations.length > 1)
34106
34191
  state.commands.push(dedent);
34107
34192
  } else {
34108
- join.push(", ");
34193
+ join2.push(", ");
34109
34194
  }
34110
34195
  };
34111
34196
  function sequence2(nodes, state, spaces, fn, separator = ",") {
@@ -34113,7 +34198,7 @@ function sequence2(nodes, state, spaces, fn, separator = ",") {
34113
34198
  return;
34114
34199
  const index = state.commands.length;
34115
34200
  const open2 = create_sequence();
34116
- const join = create_sequence();
34201
+ const join2 = create_sequence();
34117
34202
  const close2 = create_sequence();
34118
34203
  state.commands.push(open2);
34119
34204
  const child_state = { ...state, multiline: false };
@@ -34124,7 +34209,7 @@ function sequence2(nodes, state, spaces, fn, separator = ",") {
34124
34209
  const is_last = i2 === nodes.length - 1;
34125
34210
  if (node) {
34126
34211
  if (!is_first && !prev) {
34127
- state.commands.push(join);
34212
+ state.commands.push(join2);
34128
34213
  }
34129
34214
  fn(node, child_state);
34130
34215
  if (!is_last) {
@@ -34136,12 +34221,12 @@ function sequence2(nodes, state, spaces, fn, separator = ",") {
34136
34221
  const comment = state.comments.shift();
34137
34222
  state.commands.push({ type: "Comment", comment });
34138
34223
  if (!is_last)
34139
- state.commands.push(join);
34224
+ state.commands.push(join2);
34140
34225
  }
34141
34226
  child_state.multiline = true;
34142
34227
  } else {
34143
34228
  if (!is_last)
34144
- state.commands.push(join);
34229
+ state.commands.push(join2);
34145
34230
  }
34146
34231
  } else {
34147
34232
  state.commands.push(separator);
@@ -34153,12 +34238,12 @@ function sequence2(nodes, state, spaces, fn, separator = ",") {
34153
34238
  if (multiline) {
34154
34239
  state.multiline = true;
34155
34240
  open2.push(indent, newline);
34156
- join.push(newline);
34241
+ join2.push(newline);
34157
34242
  close2.push(dedent, newline);
34158
34243
  } else {
34159
34244
  if (spaces)
34160
34245
  open2.push(" ");
34161
- join.push(" ");
34246
+ join2.push(" ");
34162
34247
  if (spaces)
34163
34248
  close2.push(" ");
34164
34249
  }
@@ -34384,7 +34469,7 @@ var shared = {
34384
34469
  if (node.typeArguments)
34385
34470
  handle_type_annotation(node.typeArguments, state);
34386
34471
  const open2 = create_sequence();
34387
- const join = create_sequence();
34472
+ const join2 = create_sequence();
34388
34473
  const close2 = create_sequence();
34389
34474
  state.commands.push("(", open2);
34390
34475
  const child_state = { ...state, multiline: false };
@@ -34404,7 +34489,7 @@ var shared = {
34404
34489
  }
34405
34490
  }
34406
34491
  } else {
34407
- state.commands.push(join);
34492
+ state.commands.push(join2);
34408
34493
  }
34409
34494
  }
34410
34495
  const p = node.arguments[i2];
@@ -34417,10 +34502,10 @@ var shared = {
34417
34502
  }
34418
34503
  if (multiline) {
34419
34504
  open2.push(indent, newline);
34420
- join.push(",", newline);
34505
+ join2.push(",", newline);
34421
34506
  close2.push(dedent, newline);
34422
34507
  } else {
34423
- join.push(", ");
34508
+ join2.push(", ");
34424
34509
  }
34425
34510
  },
34426
34511
  "ClassDeclaration|ClassExpression": (node, state) => {
@@ -42856,39 +42941,38 @@ function remove_bom(source2) {
42856
42941
  return source2;
42857
42942
  }
42858
42943
 
42859
- // src/build/compileSvelte.ts
42944
+ // src/svelte/compileSvelte.ts
42860
42945
  var compileSvelte = async (entryPoints, outputDirectory) => {
42861
- const pagesDir = join(outputDirectory, "pages");
42862
- const clientDir = join(outputDirectory, "client");
42863
- const indexesDir = join(outputDirectory, "indexes");
42946
+ const pagesDir = join2(outputDirectory, "pages");
42947
+ const clientDir = join2(outputDirectory, "client");
42948
+ const indexesDir = join2(outputDirectory, "indexes");
42864
42949
  await Promise.all([
42865
- mkdir(pagesDir, { recursive: true }),
42866
- mkdir(clientDir, { recursive: true }),
42867
- mkdir(indexesDir, { recursive: true })
42950
+ mkdir2(clientDir, { recursive: true }),
42951
+ mkdir2(indexesDir, { recursive: true })
42868
42952
  ]);
42869
42953
  const isDev = env.NODE_ENV === "development";
42870
42954
  const builds = await Promise.all(entryPoints.map(async (entry) => {
42871
42955
  const source2 = await file(entry).text();
42872
42956
  const { code: pre } = await preprocess(source2, {});
42873
- const name = basename(entry, ".svelte");
42957
+ const name = basename2(entry, ".svelte");
42874
42958
  const { js: ssrJs } = compile(pre, {
42875
42959
  css: "injected",
42876
42960
  dev: isDev,
42877
42961
  filename: entry,
42878
42962
  generate: "server"
42879
42963
  });
42880
- const ssrPath = join(pagesDir, `${name}.js`);
42964
+ const ssrPath = join2(pagesDir, `${name}.js`);
42881
42965
  const { js: clientJs } = compile(pre, {
42882
42966
  css: "injected",
42883
42967
  dev: isDev,
42884
42968
  filename: entry,
42885
42969
  generate: "client"
42886
42970
  });
42887
- const clientComponentPath = join(clientDir, `${name}.js`);
42971
+ const clientComponentPath = join2(clientDir, `${name}.js`);
42888
42972
  const bootstrap = `import Component from "../client/${name}.js";
42889
42973
  import { hydrate } from "svelte";
42890
42974
  hydrate(Component,{target:document.body,props:window.__INITIAL_PROPS__??{}});`;
42891
- const clientIndexPath = join(indexesDir, `${name}.js`);
42975
+ const clientIndexPath = join2(indexesDir, `${name}.js`);
42892
42976
  await Promise.all([
42893
42977
  write(ssrPath, ssrJs.code),
42894
42978
  write(clientComponentPath, clientJs.code),
@@ -42902,109 +42986,6 @@ hydrate(Component,{target:document.body,props:window.__INITIAL_PROPS__??{}});`;
42902
42986
  };
42903
42987
  };
42904
42988
 
42905
- // src/build/generateManifest.ts
42906
- var generateManifest = (outputs, buildDirectoryAbsolute) => {
42907
- const manifest = outputs.reduce((accumulator, artifact) => {
42908
- let relativePath = artifact.path.startsWith(buildDirectoryAbsolute) ? artifact.path.slice(buildDirectoryAbsolute.length) : artifact.path;
42909
- relativePath = relativePath.replace(/^\/+/, "");
42910
- if (relativePath.includes("svelte/pages")) {
42911
- const segments2 = relativePath.split("/");
42912
- const fileWithHash2 = segments2[segments2.length - 1];
42913
- if (!fileWithHash2)
42914
- return accumulator;
42915
- const [baseName2] = fileWithHash2.split(`.${artifact.hash}.`);
42916
- accumulator[`${baseName2}/page`] = artifact.path;
42917
- return accumulator;
42918
- }
42919
- if (relativePath.includes("svelte/indexes")) {
42920
- const segments2 = relativePath.split("/");
42921
- const fileWithHash2 = segments2[segments2.length - 1];
42922
- if (!fileWithHash2)
42923
- return accumulator;
42924
- const [baseName2] = fileWithHash2.split(`.${artifact.hash}.`);
42925
- accumulator[`${baseName2}/index`] = `/${relativePath}`;
42926
- return accumulator;
42927
- }
42928
- const segments = relativePath.split("/");
42929
- const fileWithHash = segments[segments.length - 1];
42930
- if (!fileWithHash)
42931
- return accumulator;
42932
- const [baseName] = fileWithHash.split(`.${artifact.hash}.`);
42933
- accumulator[baseName] = `/${relativePath}`;
42934
- return accumulator;
42935
- }, {});
42936
- return manifest;
42937
- };
42938
-
42939
- // src/build/generateReactIndexes.ts
42940
- import { mkdir as mkdir2, rm, writeFile } from "fs/promises";
42941
- import { basename as basename2, join as join2 } from "path";
42942
- var {Glob } = globalThis.Bun;
42943
- var generateReactIndexFiles = async (reactPagesDirectory, reactIndexesDirectory) => {
42944
- await rm(reactIndexesDirectory, { force: true, recursive: true });
42945
- await mkdir2(reactIndexesDirectory);
42946
- const pagesGlob = new Glob("*.*");
42947
- const files = [];
42948
- for await (const file2 of pagesGlob.scan({ cwd: reactPagesDirectory })) {
42949
- files.push(file2);
42950
- }
42951
- const promises = files.map(async (file2) => {
42952
- const fileName = basename2(file2);
42953
- const [componentName] = fileName.split(".");
42954
- const content = [
42955
- `import { hydrateRoot } from 'react-dom/client';`,
42956
- `import type { ComponentType } from 'react'`,
42957
- `import { ${componentName} } from '../pages/${componentName}';
42958
- `,
42959
- `type PropsOf<C> = C extends ComponentType<infer P> ? P : never;
42960
- `,
42961
- `declare global {`,
42962
- ` interface Window {`,
42963
- ` __INITIAL_PROPS__: PropsOf<typeof ${componentName}>`,
42964
- ` }`,
42965
- `}
42966
- `,
42967
- `hydrateRoot(document, <${componentName} {...window.__INITIAL_PROPS__} />);`
42968
- ].join(`
42969
- `);
42970
- return writeFile(join2(reactIndexesDirectory, `${componentName}Index.tsx`), content);
42971
- });
42972
- await Promise.all(promises);
42973
- };
42974
-
42975
- // src/build/scanEntryPoints.ts
42976
- var {Glob: Glob2 } = globalThis.Bun;
42977
- var scanEntryPoints = async (dir, pattern) => {
42978
- const entryPaths = [];
42979
- const glob = new Glob2(pattern);
42980
- for await (const file2 of glob.scan({ absolute: true, cwd: dir })) {
42981
- entryPaths.push(file2);
42982
- }
42983
- return entryPaths;
42984
- };
42985
-
42986
- // src/build/updateScriptTags.ts
42987
- import { readFile, writeFile as writeFile2 } from "fs/promises";
42988
- var {Glob: Glob3 } = globalThis.Bun;
42989
- var updateScriptTags = async (manifest, htmlDir) => {
42990
- const glob = new Glob3("*.html");
42991
- const htmlFiles = [];
42992
- const fileIterator = glob.scan({ absolute: true, cwd: htmlDir });
42993
- for await (const filePath of fileIterator) {
42994
- htmlFiles.push(filePath);
42995
- }
42996
- const tasks = htmlFiles.map(async (filePath) => {
42997
- const original = await readFile(filePath, "utf8");
42998
- const updated = Object.entries(manifest).reduce((html, [scriptName, newPath]) => {
42999
- const esc = scriptName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
43000
- const regex = new RegExp(`(<script[^>]+src=["'])(/?(?:.*/)?${esc})(?:\\.[^."'/]+)?(\\.js)(["'][^>]*>)`, "g");
43001
- return html.replace(regex, (_, prefix, __, ___, suffix) => `${prefix}${newPath}${suffix}`);
43002
- }, original);
43003
- await writeFile2(filePath, updated, "utf8");
43004
- });
43005
- await Promise.all(tasks);
43006
- };
43007
-
43008
42989
  // src/utils/getDurationString.ts
43009
42990
  var getDurationString = (duration) => {
43010
42991
  let durationString;
@@ -43114,6 +43095,9 @@ var build2 = async ({
43114
43095
  await rm2(path, { force: true });
43115
43096
  });
43116
43097
  }
43098
+ if (reactIndexesPath) {
43099
+ await rm2(reactIndexesPath, { force: true, recursive: true });
43100
+ }
43117
43101
  const buildDuration = performance.now() - buildStart;
43118
43102
  console.log(`Build completed in ${getDurationString(buildDuration)}`);
43119
43103
  return manifest;
@@ -43121,7 +43105,7 @@ var build2 = async ({
43121
43105
  // src/core/pageHandlers.ts
43122
43106
  var {file: file2 } = globalThis.Bun;
43123
43107
  import { createElement } from "react";
43124
- import { renderToReadableStream } from "react-dom/server";
43108
+ import { renderToReadableStream as renderReactToReadableStream } from "react-dom/server";
43125
43109
  // node_modules/svelte/src/internal/shared/attributes.js
43126
43110
  var replacements2 = {
43127
43111
  translate: new Map([
@@ -45376,11 +45360,65 @@ function render(component2, options = {}) {
45376
45360
  body: payload.out
45377
45361
  };
45378
45362
  }
45363
+ // src/utils/escapeScriptContent.ts
45364
+ var ESCAPE_LOOKUP = {
45365
+ "\u2028": "\\u2028",
45366
+ "\u2029": "\\u2029",
45367
+ "&": "\\u0026",
45368
+ "<": "\\u003C",
45369
+ ">": "\\u003E"
45370
+ };
45371
+ var ESCAPE_REGEX = /[&><\u2028\u2029]/g;
45372
+ var escapeScriptContent = (content) => content.replace(ESCAPE_REGEX, (char) => ESCAPE_LOOKUP[char]);
45373
+
45374
+ // src/svelte/renderToReadableStream.ts
45375
+ var DEFAULT_CHUNK_SIZE = 16384;
45376
+ var renderToReadableStream = async (component2, props, {
45377
+ bootstrapScriptContent,
45378
+ bootstrapScripts = [],
45379
+ bootstrapModules = [],
45380
+ nonce,
45381
+ onError = console.error,
45382
+ progressiveChunkSize = DEFAULT_CHUNK_SIZE,
45383
+ signal
45384
+ } = {}) => {
45385
+ try {
45386
+ const { head: head2, body } = render(component2, { props });
45387
+ const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
45388
+ const scripts = (bootstrapScriptContent ? `<script${nonceAttr}>${escapeScriptContent(bootstrapScriptContent)}</script>` : "") + bootstrapScripts.map((src) => `<script${nonceAttr} src="${src}"></script>`).join("") + bootstrapModules.map((src) => `<script${nonceAttr} type="module" src="${src}"></script>`).join("");
45389
+ const encoder = new TextEncoder;
45390
+ const full = encoder.encode(`<!DOCTYPE html><html lang="en"><head>${head2}</head><body>${body}${scripts}</body></html>`);
45391
+ let offset2 = 0;
45392
+ return new ReadableStream({
45393
+ type: "bytes",
45394
+ cancel(reason) {
45395
+ onError?.(reason);
45396
+ },
45397
+ pull(controller) {
45398
+ if (signal?.aborted) {
45399
+ controller.close();
45400
+ return;
45401
+ }
45402
+ if (offset2 >= full.length) {
45403
+ controller.close();
45404
+ return;
45405
+ }
45406
+ const end = Math.min(offset2 + progressiveChunkSize, full.length);
45407
+ controller.enqueue(full.subarray(offset2, end));
45408
+ offset2 = end;
45409
+ }
45410
+ });
45411
+ } catch (error) {
45412
+ onError?.(error);
45413
+ throw error;
45414
+ }
45415
+ };
45416
+
45379
45417
  // src/core/pageHandlers.ts
45380
45418
  var handleReactPageRequest = async (pageComponent, index2, ...props) => {
45381
45419
  const [maybeProps] = props;
45382
45420
  const element3 = maybeProps !== undefined ? createElement(pageComponent, maybeProps) : createElement(pageComponent);
45383
- const stream = await renderToReadableStream(element3, {
45421
+ const stream = await renderReactToReadableStream(element3, {
45384
45422
  bootstrapModules: [index2],
45385
45423
  bootstrapScriptContent: maybeProps ? `window.__INITIAL_PROPS__=${JSON.stringify(maybeProps)}` : undefined
45386
45424
  });
@@ -45388,21 +45426,19 @@ var handleReactPageRequest = async (pageComponent, index2, ...props) => {
45388
45426
  headers: { "Content-Type": "text/html" }
45389
45427
  });
45390
45428
  };
45391
- var handleSveltePageRequest = (pageComponent, index2, props) => {
45392
- const serializedProps = JSON.stringify(props).replace(/</g, "\\u003c");
45393
- const { body, head: head2 } = render(pageComponent, { props });
45394
- const html3 = `<!DOCTYPE html>
45395
- <html lang="en">
45396
- <head>
45397
- ${head2}
45398
- </head>
45399
- <body>
45400
- ${body}
45401
- <script>window.__INITIAL_PROPS__=${serializedProps};</script>
45402
- <script type="module" src="${index2}"></script>
45403
- </body>
45404
- </html>`;
45405
- return new Response(html3, {
45429
+ var handleSveltePageRequest = async (PageComponent, manifest, props) => {
45430
+ const componentPath = PageComponent.toString();
45431
+ const pathSegments = componentPath.split("/");
45432
+ const lastSegment = pathSegments[pathSegments.length - 1] ?? "";
45433
+ const componentName = lastSegment.replace(/\.svelte$/, "");
45434
+ const pagePath = manifest[componentName];
45435
+ const indexPath = manifest[`${componentName}Index`];
45436
+ const { default: ImportedPageComponent } = await import(pagePath);
45437
+ const stream = await renderToReadableStream(ImportedPageComponent, props, {
45438
+ bootstrapModules: [indexPath],
45439
+ bootstrapScriptContent: `window.__INITIAL_PROPS__=${JSON.stringify(props)}`
45440
+ });
45441
+ return new Response(stream, {
45406
45442
  headers: { "Content-Type": "text/html" }
45407
45443
  });
45408
45444
  };
@@ -45468,5 +45504,5 @@ export {
45468
45504
  DEFAULT_PORT
45469
45505
  };
45470
45506
 
45471
- //# debugId=8FCA506732B7087964756E2164756E21
45507
+ //# debugId=CEB32816B046E97E64756E2164756E21
45472
45508
  //# sourceMappingURL=index.js.map