@zephyr3d/editor 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/assets/{index-DlnbO59X.js → index-ySiLtSxz.js} +2 -2
  2. package/dist/assistant/zephyr-types-index.json +14215 -7892
  3. package/dist/index.html +1 -1
  4. package/dist/modules/zephyr3d_backend-webgl.js.map +1 -1
  5. package/dist/modules/zephyr3d_backend-webgpu.js.map +1 -1
  6. package/dist/modules/zephyr3d_base.js +152 -152
  7. package/dist/modules/zephyr3d_base.js.map +1 -1
  8. package/dist/modules/zephyr3d_imgui.js.map +1 -1
  9. package/dist/modules/zephyr3d_loaders.js +6 -6
  10. package/dist/modules/zephyr3d_loaders.js.map +1 -1
  11. package/dist/modules/zephyr3d_scene.js +2538 -348
  12. package/dist/modules/zephyr3d_scene.js.map +1 -1
  13. package/dist/vendor/zephyr3d/backend-webgl/dist/index.js.map +1 -1
  14. package/dist/vendor/zephyr3d/backend-webgpu/dist/index.js.map +1 -1
  15. package/dist/vendor/zephyr3d/base/dist/vfs/common.js +152 -152
  16. package/dist/vendor/zephyr3d/base/dist/vfs/common.js.map +1 -1
  17. package/dist/vendor/zephyr3d/imgui/dist/index.d.ts +7 -0
  18. package/dist/vendor/zephyr3d/imgui/dist/index.js.map +1 -1
  19. package/dist/vendor/zephyr3d/loaders/dist/gltf/gltf_importer.js +6 -6
  20. package/dist/vendor/zephyr3d/loaders/dist/gltf/gltf_importer.js.map +1 -1
  21. package/dist/vendor/zephyr3d/scene/dist/animation/animation.js +87 -0
  22. package/dist/vendor/zephyr3d/scene/dist/animation/animation.js.map +1 -1
  23. package/dist/vendor/zephyr3d/scene/dist/animation/animationcontroller.js +503 -0
  24. package/dist/vendor/zephyr3d/scene/dist/animation/animationcontroller.js.map +1 -0
  25. package/dist/vendor/zephyr3d/scene/dist/animation/animationset.js +782 -156
  26. package/dist/vendor/zephyr3d/scene/dist/animation/animationset.js.map +1 -1
  27. package/dist/vendor/zephyr3d/scene/dist/animation/animationtimeline.js +974 -0
  28. package/dist/vendor/zephyr3d/scene/dist/animation/animationtimeline.js.map +1 -0
  29. package/dist/vendor/zephyr3d/scene/dist/animation/joint_dynamics/convex_collider.js +320 -0
  30. package/dist/vendor/zephyr3d/scene/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
  31. package/dist/vendor/zephyr3d/scene/dist/app/scriptregistry.js +130 -125
  32. package/dist/vendor/zephyr3d/scene/dist/app/scriptregistry.js.map +1 -1
  33. package/dist/vendor/zephyr3d/scene/dist/asset/model.js +64 -63
  34. package/dist/vendor/zephyr3d/scene/dist/asset/model.js.map +1 -1
  35. package/dist/vendor/zephyr3d/scene/dist/index.d.ts +1270 -9
  36. package/dist/vendor/zephyr3d/scene/dist/index.js +3 -1
  37. package/dist/vendor/zephyr3d/scene/dist/index.js.map +1 -1
  38. package/dist/vendor/zephyr3d/scene/dist/material/mixins/lit.js +7 -3
  39. package/dist/vendor/zephyr3d/scene/dist/material/mixins/lit.js.map +1 -1
  40. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/manager.js +1 -0
  41. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/manager.js.map +1 -1
  42. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/animation.js +4 -3
  43. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/animation.js.map +1 -1
  44. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/camera.js +1 -1
  45. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/camera.js.map +1 -1
  46. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/node.js +3 -2
  47. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/node.js.map +1 -1
  48. package/package.json +8 -8
@@ -2,32 +2,32 @@ import { textToBase64 } from '@zephyr3d/base';
2
2
  import { init, parse } from '../node_modules/es-module-lexer/dist/lexer.js';
3
3
  import { getApp } from './api.js';
4
4
 
5
- /**
6
- * Converts JavaScript source to a data URL tied to a logical module id.
7
- *
8
- * @param js - The JavaScript source code to embed.
9
- * @param id - Logical module identifier (used only for sourceURL tagging).
10
- * @returns A `data:text/javascript;base64,...` URL with an encoded `#id` suffix.
11
- * @internal
5
+ /**
6
+ * Converts JavaScript source to a data URL tied to a logical module id.
7
+ *
8
+ * @param js - The JavaScript source code to embed.
9
+ * @param id - Logical module identifier (used only for sourceURL tagging).
10
+ * @returns A `data:text/javascript;base64,...` URL with an encoded `#id` suffix.
11
+ * @internal
12
12
  */ function toDataUrl(js, id) {
13
13
  const b64 = textToBase64(js);
14
14
  return `data:text/javascript;base64,${b64}#${encodeURIComponent(String(id))}`;
15
15
  }
16
- /**
17
- * Checks whether a specifier is an absolute HTTP(S) URL.
18
- * @internal
16
+ /**
17
+ * Checks whether a specifier is an absolute HTTP(S) URL.
18
+ * @internal
19
19
  */ function isAbsoluteUrl(spec) {
20
20
  return /^https?:\/\//i.test(spec);
21
21
  }
22
- /**
23
- * Checks whether a specifier is a special URL (data: or blob:).
24
- * @internal
22
+ /**
23
+ * Checks whether a specifier is a special URL (data: or blob:).
24
+ * @internal
25
25
  */ function isSpecialUrl(spec) {
26
26
  return /^(data|blob):/i.test(spec);
27
27
  }
28
- /**
29
- * Checks whether a specifier is a bare module (not starting with ./, ../, /, or #/).
30
- * @internal
28
+ /**
29
+ * Checks whether a specifier is a bare module (not starting with ./, ../, /, or #/).
30
+ * @internal
31
31
  */ function isBareModule(spec) {
32
32
  return !spec.startsWith('./') && !spec.startsWith('../') && !spec.startsWith('/') && !spec.startsWith('#/');
33
33
  }
@@ -58,32 +58,32 @@ function hasRawQuery(spec) {
58
58
  }
59
59
  return query.split('&').some((part)=>part.trim() === 'raw');
60
60
  }
61
- /**
62
- * Resolves, builds, and serves runtime modules using a VFS.
63
- *
64
- * Responsibilities:
65
- * - Resolve logical module IDs to physical paths or URLs.
66
- * - In editor mode, bundle local script modules into a single data URL after transpile.
67
- * - Transpile TypeScript to JavaScript on the fly (requires `window.ts` TypeScript runtime).
68
- * - Gather static and dynamic import dependencies for tooling.
69
- *
70
- * Modes:
71
- * - Editor mode (`editorMode === true`): local script graphs are bundled to data URLs.
72
- * - Runtime mode (`editorMode === false`): returns .js URLs directly (with .ts -\> .js mapping).
73
- *
74
- * Caching:
75
- * - Built bundles are memoized in `_built` map keyed by canonical source path.
76
- *
77
- * @public
61
+ /**
62
+ * Resolves, builds, and serves runtime modules using a VFS.
63
+ *
64
+ * Responsibilities:
65
+ * - Resolve logical module IDs to physical paths or URLs.
66
+ * - In editor mode, bundle local script modules into a single data URL after transpile.
67
+ * - Transpile TypeScript to JavaScript on the fly (requires `window.ts` TypeScript runtime).
68
+ * - Gather static and dynamic import dependencies for tooling.
69
+ *
70
+ * Modes:
71
+ * - Editor mode (`editorMode === true`): local script graphs are bundled to data URLs.
72
+ * - Runtime mode (`editorMode === false`): returns .js/.mjs URLs directly (with .ts -\> .js mapping).
73
+ *
74
+ * Caching:
75
+ * - Built bundles are memoized in `_built` map keyed by canonical source path.
76
+ *
77
+ * @public
78
78
  */ class ScriptRegistry {
79
79
  _vfs;
80
80
  _scriptsRoot;
81
81
  _built;
82
82
  _building;
83
83
  _builtDeps;
84
- /**
85
- * @param vfs - The virtual file system for existence checks, reads, and path ops.
86
- * @param scriptsRoot - Root directory for script resolution (used with `#/` specifiers).
84
+ /**
85
+ * @param vfs - The virtual file system for existence checks, reads, and path ops.
86
+ * @param scriptsRoot - Root directory for script resolution (used with `#/` specifiers).
87
87
  */ constructor(vfs, scriptsRoot){
88
88
  this._vfs = vfs;
89
89
  this._scriptsRoot = scriptsRoot;
@@ -91,10 +91,10 @@ function hasRawQuery(spec) {
91
91
  this._building = new Map();
92
92
  this._builtDeps = new Map();
93
93
  }
94
- /**
95
- * The active virtual file system.
96
- *
97
- * Assigning a new VFS clears the build cache.
94
+ /**
95
+ * The active virtual file system.
96
+ *
97
+ * Assigning a new VFS clears the build cache.
98
98
  */ get VFS() {
99
99
  return this._vfs;
100
100
  }
@@ -106,21 +106,21 @@ function hasRawQuery(spec) {
106
106
  this._builtDeps.clear();
107
107
  }
108
108
  }
109
- /**
110
- * The root path used by `#/` specifiers.
109
+ /**
110
+ * The root path used by `#/` specifiers.
111
111
  */ get scriptsRoot() {
112
112
  return this._scriptsRoot;
113
113
  }
114
114
  set scriptsRoot(path) {
115
115
  this._scriptsRoot = path;
116
116
  }
117
- /**
118
- * Invalidates cached built module output for one logical module id, or clears the full cache.
119
- *
120
- * Pass the same logical id shape that callers use with {@link ScriptRegistry.resolveRuntimeUrl},
121
- * for example `/assets/scripts/foo.ts`, `/assets/scripts/foo.js`, or `/assets/scripts/foo`.
122
- *
123
- * @param moduleId - Optional logical module id to invalidate. Omit to clear the entire build cache.
117
+ /**
118
+ * Invalidates cached built module output for one logical module id, or clears the full cache.
119
+ *
120
+ * Pass the same logical id shape that callers use with {@link ScriptRegistry.resolveRuntimeUrl},
121
+ * for example `/assets/scripts/foo.ts`, `/assets/scripts/foo.js`, or `/assets/scripts/foo`.
122
+ *
123
+ * @param moduleId - Optional logical module id to invalidate. Omit to clear the entire build cache.
124
124
  */ invalidate(moduleId) {
125
125
  if (!moduleId) {
126
126
  this._built.clear();
@@ -159,22 +159,22 @@ function hasRawQuery(spec) {
159
159
  }
160
160
  }
161
161
  }
162
- /**
163
- * Fetches raw source for a logical module id by probing known extensions.
164
- *
165
- * Search order:
166
- * - If `id` already ends with `.ts` or `.js` and is a file -\> return it.
167
- * - Else try `.id.ts`, then `.id.js`.
168
- *
169
- * @param id - Logical module identifier (absolute or logical path-like).
170
- * @returns Source code, resolved path, and type (`'js' | 'ts'`), or `undefined` if not found.
162
+ /**
163
+ * Fetches raw source for a logical module id by probing known extensions.
164
+ *
165
+ * Search order:
166
+ * - If `id` already ends with `.ts`, `.js`, or `.mjs` and is a file -\> return it.
167
+ * - Else try `.id.ts`, then `.id.js`, then `.id.mjs`.
168
+ *
169
+ * @param id - Logical module identifier (absolute or logical path-like).
170
+ * @returns Source code, resolved path, and type (`'js' | 'ts'`), or `undefined` if not found.
171
171
  */ async fetchSource(id) {
172
172
  let type = null;
173
173
  let pathWithExt = '';
174
174
  if (id.endsWith('.ts')) {
175
175
  pathWithExt = id;
176
176
  type = 'ts';
177
- } else if (id.endsWith('.js')) {
177
+ } else if (id.endsWith('.js') || id.endsWith('.mjs')) {
178
178
  pathWithExt = id;
179
179
  type = 'js';
180
180
  }
@@ -193,13 +193,16 @@ function hasRawQuery(spec) {
193
193
  'js'
194
194
  ];
195
195
  if (!type) {
196
- for (const t of types){
196
+ for (const t of [
197
+ ...types,
198
+ 'mjs'
199
+ ]){
197
200
  pathWithExt = `${id}.${t}`;
198
201
  const exists = await this._vfs.exists(pathWithExt);
199
202
  if (exists) {
200
203
  const stats = await this._vfs.stat(pathWithExt);
201
204
  if (stats.isFile) {
202
- type = t;
205
+ type = t === 'ts' ? 'ts' : 'js';
203
206
  break;
204
207
  }
205
208
  }
@@ -216,34 +219,35 @@ function hasRawQuery(spec) {
216
219
  };
217
220
  }
218
221
  }
219
- /**
220
- * Resolves a module entry to a URL suitable for dynamic import.
221
- *
222
- * Behavior:
223
- * - In editor mode, builds the module to a data URL.
224
- * - Otherwise, returns `.js` URL directly:
225
- * - If `id` ends with `.js`: return as-is.
226
- * - If `id` ends with `.ts`: map to `.js` (assumes pre-built file exists).
227
- * - Else: append `.js`.
228
- *
229
- * @param entryId - Entry module identifier (logical or path-like).
230
- * @returns A URL string that can be used in `import(...)`.
222
+ /**
223
+ * Resolves a module entry to a URL suitable for dynamic import.
224
+ *
225
+ * Behavior:
226
+ * - In editor mode, builds the module to a data URL.
227
+ * - Otherwise, returns `.js` or `.mjs` URL directly:
228
+ * - If `id` ends with `.js`: return as-is.
229
+ * - If `id` ends with `.mjs`: return as-is.
230
+ * - If `id` ends with `.ts`: map to `.js` (assumes pre-built file exists).
231
+ * - Else: append `.js`.
232
+ *
233
+ * @param entryId - Entry module identifier (logical or path-like).
234
+ * @returns A URL string that can be used in `import(...)`.
231
235
  */ async resolveRuntimeUrl(entryId) {
232
236
  const id = await this.resolveLogicalId(entryId);
233
237
  if (id.startsWith('/assets/@builtins/')) {
234
238
  return await this.build(String(id));
235
239
  }
236
- return getApp().editorMode !== 'none' ? await this.build(String(id)) : id.endsWith('.js') ? id : id.endsWith('.ts') ? `${id.slice(0, -3)}.js` : `${id}.js`;
240
+ return getApp().editorMode !== 'none' ? await this.build(String(id)) : id.endsWith('.js') || id.endsWith('.mjs') ? id : id.endsWith('.ts') ? `${id.slice(0, -3)}.js` : `${id}.js`;
237
241
  }
238
- /**
239
- * Recursively gathers direct static and dynamic import dependencies for a module.
240
- *
241
- * Only relative specifiers (`./` or `../`) are followed. Absolute, special, and bare
242
- * module specifiers are ignored here.
243
- *
244
- * @param entryId - The starting (possibly relative) specifier from `fromId`.
245
- * @param fromId - The logical id of the module containing `entryId`.
246
- * @param dependencies - Output map of `resolvedSourcePath -\> file contents`.
242
+ /**
243
+ * Recursively gathers direct static and dynamic import dependencies for a module.
244
+ *
245
+ * Only relative specifiers (`./` or `../`) are followed. Absolute, special, and bare
246
+ * module specifiers are ignored here.
247
+ *
248
+ * @param entryId - The starting (possibly relative) specifier from `fromId`.
249
+ * @param fromId - The logical id of the module containing `entryId`.
250
+ * @param dependencies - Output map of `resolvedSourcePath -\> file contents`.
247
251
  */ async getDependencies(entryId, fromId, dependencies) {
248
252
  const reStatic = /\b(?:import|export)\s+[^"']*?from\s+(['"])([^'"]+)\1/g;
249
253
  const reDynamic = /\bimport\s*\(\s*(['"])([^'"]+)\1\s*\)/g;
@@ -271,17 +275,17 @@ function hasRawQuery(spec) {
271
275
  await gather(code, reStatic);
272
276
  await gather(code, reDynamic);
273
277
  }
274
- /**
275
- * Builds a logical module id into a bundled data URL (editor mode pipeline).
276
- *
277
- * Steps:
278
- * - Resolve source path (.ts/.js) via {@link ScriptRegistry.resolveSourcePath}.
279
- * - Collect reachable local imports without recursively building data URLs.
280
- * - Transpile local modules to `System.register`.
281
- * - Emit a single `data:` URL with a small module loader and memoize it in `_built`.
282
- *
283
- * @param id - Logical module id to build.
284
- * @returns Data URL string for dynamic import, or empty string if not found.
278
+ /**
279
+ * Builds a logical module id into a bundled data URL (editor mode pipeline).
280
+ *
281
+ * Steps:
282
+ * - Resolve source path (.ts/.js) via {@link ScriptRegistry.resolveSourcePath}.
283
+ * - Collect reachable local imports without recursively building data URLs.
284
+ * - Transpile local modules to `System.register`.
285
+ * - Emit a single `data:` URL with a small module loader and memoize it in `_built`.
286
+ *
287
+ * @param id - Logical module id to build.
288
+ * @returns Data URL string for dynamic import, or empty string if not found.
285
289
  */ async build(id) {
286
290
  const entry = await this.resolveModuleInfo(String(id));
287
291
  if (!entry) {
@@ -376,7 +380,7 @@ function hasRawQuery(spec) {
376
380
  const ts = this.getTypeScriptRuntime();
377
381
  const res = ts.transpileModule(code, {
378
382
  compilerOptions: {
379
- target: ts.ScriptTarget.ES2015,
383
+ target: ts.ScriptTarget.ES2020,
380
384
  module: ts.ModuleKind.ESNext,
381
385
  experimentalDecorators: true,
382
386
  useDefineForClassFields: false
@@ -391,19 +395,20 @@ function hasRawQuery(spec) {
391
395
  const res = ts.transpileModule(code, {
392
396
  compilerOptions: {
393
397
  allowJs: true,
394
- target: ts.ScriptTarget.ES2015,
398
+ // Keep modern syntax such as async generators, class fields, and private fields intact.
399
+ target: ts.ScriptTarget.ES2022,
395
400
  module: ts.ModuleKind.System,
396
401
  esModuleInterop: true,
397
402
  experimentalDecorators: true,
398
- useDefineForClassFields: false
403
+ useDefineForClassFields: true
399
404
  },
400
405
  fileName: logicalId
401
406
  });
402
407
  return res.outputText || '';
403
408
  }
404
- /**
405
- * Rewrites local ESM specifiers to canonical source paths and records local deps.
406
- * External URLs and package imports are left for the native dynamic import path.
409
+ /**
410
+ * Rewrites local ESM specifiers to canonical source paths and records local deps.
411
+ * External URLs and package imports are left for the native dynamic import path.
407
412
  */ async rewriteImportsToLogicalIds(code, fromId) {
408
413
  await init;
409
414
  const [imports] = parse(code);
@@ -551,21 +556,21 @@ async function __z3dLoad(spec, parentId = '') {
551
556
  }
552
557
  `;
553
558
  }
554
- /**
555
- * Resolves a specifier to a logical id suitable for further processing.
556
- *
557
- * Resolution rules:
558
- * - `#/path`: resolved against `scriptsRoot` via VFS join/normalize.
559
- * - `./` or `../`: resolved relative to `fromId` directory (requires `fromId`).
560
- * - `/absolute`: treated as absolute from root (normalized).
561
- * - Bare module in editor mode: if `/deps.lock.json` exists and contains an entry,
562
- * map to the dependency's `entry` path; otherwise return as-is.
563
- * - Else (non-editor bare module): return `spec` unchanged (external).
564
- *
565
- * @param spec - Import specifier string.
566
- * @param fromId - Optional base logical id used for relative resolution.
567
- * @returns A normalized logical id or an external specifier string.
568
- * @throws If a relative import is provided without `fromId`.
559
+ /**
560
+ * Resolves a specifier to a logical id suitable for further processing.
561
+ *
562
+ * Resolution rules:
563
+ * - `#/path`: resolved against `scriptsRoot` via VFS join/normalize.
564
+ * - `./` or `../`: resolved relative to `fromId` directory (requires `fromId`).
565
+ * - `/absolute`: treated as absolute from root (normalized).
566
+ * - Bare module in editor mode: if `/deps.lock.json` exists and contains an entry,
567
+ * map to the dependency's `entry` path; otherwise return as-is.
568
+ * - Else (non-editor bare module): return `spec` unchanged (external).
569
+ *
570
+ * @param spec - Import specifier string.
571
+ * @param fromId - Optional base logical id used for relative resolution.
572
+ * @returns A normalized logical id or an external specifier string.
573
+ * @throws If a relative import is provided without `fromId`.
569
574
  */ async resolveLogicalId(spec, fromId) {
570
575
  const { path: baseSpec, suffix } = splitSpecifierQuery(spec);
571
576
  if (baseSpec.startsWith('#/')) {
@@ -595,16 +600,16 @@ async function __z3dLoad(spec, parentId = '') {
595
600
  }
596
601
  return spec;
597
602
  }
598
- /**
599
- * Resolves a logical id to a concrete source path and type by probing extensions.
600
- *
601
- * Rules:
602
- * - If `logicalId` ends with `.ts` or `.js`/`.mjs` and is a file, return it.
603
- * - Else probe `logicalId.ts`, `logicalId.js`, `logicalId.mjs` in that order.
604
- * - Maps `.mjs` to type `'js'`.
605
- *
606
- * @param logicalId - The normalized logical module id (path-like).
607
- * @returns `{ type, path }` or `null` if not found.
603
+ /**
604
+ * Resolves a logical id to a concrete source path and type by probing extensions.
605
+ *
606
+ * Rules:
607
+ * - If `logicalId` ends with `.ts` or `.js`/`.mjs` and is a file, return it.
608
+ * - Else probe `logicalId.ts`, `logicalId.js`, `logicalId.mjs` in that order.
609
+ * - Maps `.mjs` to type `'js'`.
610
+ *
611
+ * @param logicalId - The normalized logical module id (path-like).
612
+ * @returns `{ type, path }` or `null` if not found.
608
613
  */ async resolveSourcePath(logicalId) {
609
614
  const { path: normalizedLogicalId } = splitSpecifierQuery(logicalId);
610
615
  let type = null;
@@ -1 +1 @@
1
- {"version":3,"file":"scriptregistry.js","sources":["../../src/app/scriptregistry.ts"],"sourcesContent":["import type * as TS from 'typescript';\nimport type { Nullable, VFS } from '@zephyr3d/base';\nimport { textToBase64 } from '@zephyr3d/base';\nimport { init, parse } from 'es-module-lexer';\nimport { getApp } from './api';\n\n/**\n * Converts JavaScript source to a data URL tied to a logical module id.\n *\n * @param js - The JavaScript source code to embed.\n * @param id - Logical module identifier (used only for sourceURL tagging).\n * @returns A `data:text/javascript;base64,...` URL with an encoded `#id` suffix.\n * @internal\n */\nfunction toDataUrl(js: string, id: string) {\n const b64 = textToBase64(js);\n return `data:text/javascript;base64,${b64}#${encodeURIComponent(String(id))}`;\n}\n\n/**\n * Checks whether a specifier is an absolute HTTP(S) URL.\n * @internal\n */\nfunction isAbsoluteUrl(spec: string) {\n return /^https?:\\/\\//i.test(spec);\n}\n\n/**\n * Checks whether a specifier is a special URL (data: or blob:).\n * @internal\n */\nfunction isSpecialUrl(spec: string) {\n return /^(data|blob):/i.test(spec);\n}\n\n/**\n * Checks whether a specifier is a bare module (not starting with ./, ../, /, or #/).\n * @internal\n */\nfunction isBareModule(spec: string) {\n return !spec.startsWith('./') && !spec.startsWith('../') && !spec.startsWith('/') && !spec.startsWith('#/');\n}\n\nfunction splitSpecifierQuery(spec: string) {\n const hashIndex = spec.indexOf('#');\n const queryIndex = spec.indexOf('?');\n const cutIndex =\n queryIndex >= 0 && hashIndex >= 0\n ? Math.min(queryIndex, hashIndex)\n : queryIndex >= 0\n ? queryIndex\n : hashIndex;\n if (cutIndex < 0) {\n return {\n path: spec,\n suffix: ''\n };\n }\n return {\n path: spec.slice(0, cutIndex),\n suffix: spec.slice(cutIndex)\n };\n}\n\nfunction hasRawQuery(spec: string) {\n const { suffix } = splitSpecifierQuery(spec);\n if (!suffix || suffix[0] !== '?') {\n return false;\n }\n const queryEnd = suffix.indexOf('#');\n const query = (queryEnd >= 0 ? suffix.slice(1, queryEnd) : suffix.slice(1)).trim();\n if (!query) {\n return false;\n }\n return query.split('&').some((part) => part.trim() === 'raw');\n}\n\ntype ScriptModuleType = 'js' | 'ts';\n\ntype ScriptModuleInfo = {\n id: string;\n path: string;\n type: ScriptModuleType;\n deps: string[];\n systemCode: string;\n};\n\n/**\n * Resolves, builds, and serves runtime modules using a VFS.\n *\n * Responsibilities:\n * - Resolve logical module IDs to physical paths or URLs.\n * - In editor mode, bundle local script modules into a single data URL after transpile.\n * - Transpile TypeScript to JavaScript on the fly (requires `window.ts` TypeScript runtime).\n * - Gather static and dynamic import dependencies for tooling.\n *\n * Modes:\n * - Editor mode (`editorMode === true`): local script graphs are bundled to data URLs.\n * - Runtime mode (`editorMode === false`): returns .js URLs directly (with .ts -\\> .js mapping).\n *\n * Caching:\n * - Built bundles are memoized in `_built` map keyed by canonical source path.\n *\n * @public\n */\nexport class ScriptRegistry {\n private _vfs: VFS;\n private _scriptsRoot: string;\n private _built: Map<string, string>; // logicalId -> dataURL\n private _building: Map<string, Promise<string>>;\n private _builtDeps: Map<string, Set<string>>;\n\n /**\n * @param vfs - The virtual file system for existence checks, reads, and path ops.\n * @param scriptsRoot - Root directory for script resolution (used with `#/` specifiers).\n */\n constructor(vfs: VFS, scriptsRoot: string) {\n this._vfs = vfs;\n this._scriptsRoot = scriptsRoot;\n this._built = new Map();\n this._building = new Map();\n this._builtDeps = new Map();\n }\n\n /**\n * The active virtual file system.\n *\n * Assigning a new VFS clears the build cache.\n */\n get VFS() {\n return this._vfs;\n }\n set VFS(vfs: VFS) {\n if (vfs !== this._vfs) {\n this._vfs = vfs;\n this._built.clear();\n this._building.clear();\n this._builtDeps.clear();\n }\n }\n\n /**\n * The root path used by `#/` specifiers.\n */\n get scriptsRoot() {\n return this._scriptsRoot;\n }\n set scriptsRoot(path: string) {\n this._scriptsRoot = path;\n }\n\n /**\n * Invalidates cached built module output for one logical module id, or clears the full cache.\n *\n * Pass the same logical id shape that callers use with {@link ScriptRegistry.resolveRuntimeUrl},\n * for example `/assets/scripts/foo.ts`, `/assets/scripts/foo.js`, or `/assets/scripts/foo`.\n *\n * @param moduleId - Optional logical module id to invalidate. Omit to clear the entire build cache.\n */\n invalidate(moduleId?: string) {\n if (!moduleId) {\n this._built.clear();\n this._building.clear();\n this._builtDeps.clear();\n return;\n }\n const normalized = String(moduleId);\n const variants = new Set([normalized]);\n if (normalized.endsWith('.ts') || normalized.endsWith('.js')) {\n variants.add(normalized.slice(0, -3));\n } else if (normalized.endsWith('.mjs')) {\n variants.add(normalized.slice(0, -4));\n } else {\n variants.add(`${normalized}.ts`);\n variants.add(`${normalized}.js`);\n variants.add(`${normalized}.mjs`);\n }\n for (const key of variants) {\n this._built.delete(key);\n this._building.delete(key);\n this._builtDeps.delete(key);\n }\n for (const [entryId, deps] of [...this._builtDeps]) {\n for (const variant of variants) {\n if (deps.has(variant)) {\n this._built.delete(entryId);\n this._building.delete(entryId);\n this._builtDeps.delete(entryId);\n break;\n }\n }\n }\n }\n\n /**\n * Fetches raw source for a logical module id by probing known extensions.\n *\n * Search order:\n * - If `id` already ends with `.ts` or `.js` and is a file -\\> return it.\n * - Else try `.id.ts`, then `.id.js`.\n *\n * @param id - Logical module identifier (absolute or logical path-like).\n * @returns Source code, resolved path, and type (`'js' | 'ts'`), or `undefined` if not found.\n */\n protected async fetchSource(id: string) {\n let type: Nullable<'js' | 'ts'> = null;\n let pathWithExt = '';\n if (id.endsWith('.ts')) {\n pathWithExt = id;\n type = 'ts';\n } else if (id.endsWith('.js')) {\n pathWithExt = id;\n type = 'js';\n }\n if (type) {\n const exists = await this._vfs.exists(pathWithExt);\n if (!exists) {\n type = null;\n }\n const stat = await this._vfs.stat(pathWithExt);\n if (stat.isDirectory) {\n type = null;\n }\n }\n const types = ['ts', 'js'] as const;\n if (!type) {\n for (const t of types) {\n pathWithExt = `${id}.${t}`;\n const exists = await this._vfs.exists(pathWithExt);\n if (exists) {\n const stats = await this._vfs.stat(pathWithExt);\n if (stats.isFile) {\n type = t;\n break;\n }\n }\n }\n }\n if (type) {\n const code = (await this._vfs.readFile(pathWithExt, { encoding: 'utf8' })) as string;\n return { code, type, path: pathWithExt };\n }\n }\n\n /**\n * Resolves a module entry to a URL suitable for dynamic import.\n *\n * Behavior:\n * - In editor mode, builds the module to a data URL.\n * - Otherwise, returns `.js` URL directly:\n * - If `id` ends with `.js`: return as-is.\n * - If `id` ends with `.ts`: map to `.js` (assumes pre-built file exists).\n * - Else: append `.js`.\n *\n * @param entryId - Entry module identifier (logical or path-like).\n * @returns A URL string that can be used in `import(...)`.\n */\n async resolveRuntimeUrl(entryId: string) {\n const id = await this.resolveLogicalId(entryId);\n if (id.startsWith('/assets/@builtins/')) {\n return await this.build(String(id));\n }\n return getApp().editorMode !== 'none'\n ? await this.build(String(id))\n : id.endsWith('.js')\n ? id\n : id.endsWith('.ts')\n ? `${id.slice(0, -3)}.js`\n : `${id}.js`;\n }\n\n /**\n * Recursively gathers direct static and dynamic import dependencies for a module.\n *\n * Only relative specifiers (`./` or `../`) are followed. Absolute, special, and bare\n * module specifiers are ignored here.\n *\n * @param entryId - The starting (possibly relative) specifier from `fromId`.\n * @param fromId - The logical id of the module containing `entryId`.\n * @param dependencies - Output map of `resolvedSourcePath -\\> file contents`.\n */\n async getDependencies(entryId: string, fromId: string, dependencies: Record<string, string>) {\n const reStatic = /\\b(?:import|export)\\s+[^\"']*?from\\s+(['\"])([^'\"]+)\\1/g;\n const reDynamic = /\\bimport\\s*\\(\\s*(['\"])([^'\"]+)\\1\\s*\\)/g;\n\n const normalizedId = await this.resolveLogicalId(entryId, fromId);\n const srcPath = await this.resolveSourcePath(normalizedId);\n if (!srcPath || dependencies[srcPath.path] !== undefined) {\n return;\n }\n const code = (await this._vfs.readFile(srcPath.path, { encoding: 'utf8' })) as string;\n dependencies[srcPath.path] = code;\n\n const gather = async (input: string, re: RegExp) => {\n for (;;) {\n const m = re.exec(input);\n if (!m) {\n break;\n }\n\n const spec = m[2];\n\n if (spec.startsWith('./') || spec.startsWith('../')) {\n await this.getDependencies(spec, normalizedId, dependencies);\n }\n }\n };\n\n await gather(code, reStatic);\n await gather(code, reDynamic);\n }\n\n /**\n * Builds a logical module id into a bundled data URL (editor mode pipeline).\n *\n * Steps:\n * - Resolve source path (.ts/.js) via {@link ScriptRegistry.resolveSourcePath}.\n * - Collect reachable local imports without recursively building data URLs.\n * - Transpile local modules to `System.register`.\n * - Emit a single `data:` URL with a small module loader and memoize it in `_built`.\n *\n * @param id - Logical module id to build.\n * @returns Data URL string for dynamic import, or empty string if not found.\n */\n private async build(id: string) {\n const entry = await this.resolveModuleInfo(String(id));\n if (!entry) {\n return '';\n }\n\n const key = entry.id;\n const cached = this._built.get(key);\n if (cached) {\n return cached;\n }\n const pending = this._building.get(key);\n if (pending) {\n return await pending;\n }\n\n const task = this.buildBundle(key);\n this._building.set(key, task);\n try {\n const url = await task;\n if (url) {\n this._built.set(key, url);\n }\n return url;\n } finally {\n this._building.delete(key);\n }\n }\n\n private async buildBundle(entryId: string) {\n const modules = new Map<string, ScriptModuleInfo>();\n const entry = await this.collectModule(entryId, modules);\n if (!entry) {\n return '';\n }\n\n const chunks = [this.getSystemBundleRuntime()];\n for (const module of modules.values()) {\n chunks.push(`__z3dRegister(${JSON.stringify(module.id)}, () => {\\n${module.systemCode}\\n});`);\n }\n chunks.push(\n `const __z3dEntry = await __z3dLoad(${JSON.stringify(entry.id)});\\n` +\n `const plugin = __z3dEntry.plugin;\\n` +\n `const __z3dDefault = __z3dEntry.default ?? __z3dEntry.plugin ?? __z3dEntry;\\n` +\n `export { plugin };\\n` +\n `export default __z3dDefault;\\n` +\n `//# sourceURL=${entry.id}`\n );\n\n const url = toDataUrl(chunks.join('\\n'), entry.id);\n this._builtDeps.set(entry.id, new Set(modules.keys()));\n return url;\n }\n\n private async collectModule(id: string, modules: Map<string, ScriptModuleInfo>) {\n const module = await this.resolveModuleInfo(id);\n if (!module) {\n return null;\n }\n if (modules.has(module.id)) {\n return modules.get(module.id)!;\n }\n\n modules.set(module.id, module);\n\n const source = (await this._vfs.readFile(module.path, { encoding: 'utf8' })) as string;\n const esmCode = hasRawQuery(module.id)\n ? `export default ${JSON.stringify(source)};\\n`\n : await this.transpileToESModule(source, module.id, module.type);\n const rewritten = await this.rewriteImportsToLogicalIds(esmCode, module.id);\n module.deps = rewritten.deps;\n module.systemCode = await this.transpileToSystemModule(rewritten.code, module.id);\n\n for (const dep of module.deps) {\n await this.collectModule(dep, modules);\n }\n return module;\n }\n\n private async resolveModuleInfo(id: string): Promise<Nullable<ScriptModuleInfo>> {\n const srcPath = await this.resolveSourcePath(id);\n if (!srcPath) {\n return null;\n }\n const { suffix } = splitSpecifierQuery(String(id));\n const path = this._vfs.normalizePath(srcPath.path);\n return {\n id: `${path}${suffix}`,\n path,\n type: srcPath.type,\n deps: [],\n systemCode: ''\n };\n }\n\n private getTypeScriptRuntime() {\n const ts = (window as any).ts as typeof TS;\n if (!ts) {\n throw new Error('TypeScript runtime (window.ts) not found. Load typescript.js first.');\n }\n return ts;\n }\n\n private async transpileToESModule(code: string, _id: string, type: ScriptModuleType) {\n const logicalId = String(_id);\n\n if (type === 'js') {\n return code;\n }\n\n const ts = this.getTypeScriptRuntime();\n\n const res = ts.transpileModule(code, {\n compilerOptions: {\n target: ts.ScriptTarget.ES2015,\n module: ts.ModuleKind.ESNext,\n experimentalDecorators: true,\n useDefineForClassFields: false\n },\n fileName: logicalId\n });\n\n return res.outputText || '';\n }\n\n private async transpileToSystemModule(code: string, _id: string) {\n const logicalId = String(_id);\n const ts = this.getTypeScriptRuntime();\n const res = ts.transpileModule(code, {\n compilerOptions: {\n allowJs: true,\n target: ts.ScriptTarget.ES2015,\n module: ts.ModuleKind.System,\n esModuleInterop: true,\n experimentalDecorators: true,\n useDefineForClassFields: false\n },\n fileName: logicalId\n });\n return res.outputText || '';\n }\n\n /**\n * Rewrites local ESM specifiers to canonical source paths and records local deps.\n * External URLs and package imports are left for the native dynamic import path.\n */\n private async rewriteImportsToLogicalIds(code: string, fromId: string) {\n await init;\n const [imports] = parse(code);\n const list = [...imports].sort((a, b) => (a.s || 0) - (b.s || 0));\n const deps = new Set<string>();\n let out = '';\n let last = 0;\n\n for (const im of list) {\n // Skip import.meta entries reported by es-module-lexer.\n // Their \"specifier\" span points to the whole \"import.meta\" expression,\n // which must remain untouched.\n if (im.d === -2) {\n continue;\n }\n // must have quotes\n const hasQuote = im.ss != null && im.se != null;\n if (!hasQuote || im.se <= im.ss) {\n continue;\n }\n // must have contents\n if (im.e <= im.s) {\n continue;\n }\n // append [last, s)\n out += code.slice(last, im.s);\n\n const spec = code.slice(im.s, im.e); // original spec\n const resolved = await this.resolveImportTarget(spec, String(fromId));\n const replacement = resolved.id ?? spec;\n if (resolved.id) {\n deps.add(resolved.id);\n }\n out += replacement; // Do not wrap in quotes\n last = im.e;\n }\n out += code.slice(last);\n return { code: out, deps: [...deps] };\n }\n\n private async resolveImportTarget(spec: string, fromId: string) {\n if (isAbsoluteUrl(spec) || isSpecialUrl(spec) || spec.startsWith('@zephyr3d/')) {\n return { id: null };\n }\n\n const depId = await this.resolveLogicalId(spec, isBareModule(spec) ? undefined : fromId);\n const module = await this.resolveModuleInfo(depId);\n return { id: module?.id ?? null };\n }\n\n private getSystemBundleRuntime() {\n return `\nconst __z3dRegistry = new Map();\nlet __z3dCurrentId = '';\nconst System = {\n register(deps, declare) {\n if (!__z3dCurrentId) {\n throw new Error('System.register called without module id');\n }\n __z3dRegistry.set(__z3dCurrentId, {\n id: __z3dCurrentId,\n deps,\n declare,\n exports: Object.create(null),\n setters: [],\n execute: null,\n importers: [],\n state: 0\n });\n }\n};\nfunction __z3dRegister(id, factory) {\n const prev = __z3dCurrentId;\n __z3dCurrentId = id;\n try {\n factory();\n } finally {\n __z3dCurrentId = prev;\n }\n}\nfunction __z3dResolve(spec, parentId) {\n if (__z3dRegistry.has(spec)) {\n return spec;\n }\n if (spec.startsWith('./') || spec.startsWith('../')) {\n const base = parentId.slice(0, parentId.lastIndexOf('/') + 1);\n return new URL(spec, 'file://' + base).pathname;\n }\n return spec;\n}\nfunction __z3dExport(record, name, value) {\n if (name && typeof name === 'object') {\n for (const key of Object.keys(name)) {\n __z3dExport(record, key, name[key]);\n }\n return name;\n }\n record.exports[name] = value;\n for (const notify of record.importers) {\n notify(record.exports);\n }\n return value;\n}\nasync function __z3dLoad(spec, parentId = '') {\n const id = parentId ? __z3dResolve(spec, parentId) : spec;\n const record = __z3dRegistry.get(id);\n if (!record) {\n return await import(id);\n }\n if (record.state === 2 || record.state === 1) {\n return record.exports;\n }\n record.state = 1;\n const declaration = record.declare((name, value) => __z3dExport(record, name, value), {\n id,\n import: (dep) => __z3dLoad(dep, id),\n meta: { url: id }\n }) || {};\n record.setters = declaration.setters || [];\n record.execute = declaration.execute || (() => {});\n for (let i = 0; i < record.deps.length; i++) {\n const depId = __z3dResolve(record.deps[i], id);\n const depRecord = __z3dRegistry.get(depId);\n const depExports = depRecord ? await __z3dLoad(depId) : await import(depId);\n const setter = record.setters[i];\n if (typeof setter === 'function') {\n setter(depExports);\n if (depRecord) {\n depRecord.importers.push((exports) => setter(exports));\n }\n }\n }\n const result = record.execute();\n if (result && typeof result.then === 'function') {\n await result;\n }\n record.state = 2;\n return record.exports;\n}\n`;\n }\n\n /**\n * Resolves a specifier to a logical id suitable for further processing.\n *\n * Resolution rules:\n * - `#/path`: resolved against `scriptsRoot` via VFS join/normalize.\n * - `./` or `../`: resolved relative to `fromId` directory (requires `fromId`).\n * - `/absolute`: treated as absolute from root (normalized).\n * - Bare module in editor mode: if `/deps.lock.json` exists and contains an entry,\n * map to the dependency's `entry` path; otherwise return as-is.\n * - Else (non-editor bare module): return `spec` unchanged (external).\n *\n * @param spec - Import specifier string.\n * @param fromId - Optional base logical id used for relative resolution.\n * @returns A normalized logical id or an external specifier string.\n * @throws If a relative import is provided without `fromId`.\n */\n async resolveLogicalId(spec: string, fromId?: string) {\n const { path: baseSpec, suffix } = splitSpecifierQuery(spec);\n if (baseSpec.startsWith('#/')) {\n return `${this._vfs.normalizePath(this._vfs.join(this._scriptsRoot, baseSpec.slice(2)))}${suffix}`;\n } else if (baseSpec.startsWith('./') || baseSpec.startsWith('../')) {\n if (!fromId) {\n throw new Error(`Relative import \"${spec}\" requires fromId`);\n }\n const fromPath = splitSpecifierQuery(this._vfs.normalizePath(fromId)).path;\n return `${this._vfs.normalizePath(this._vfs.join(this._vfs.dirname(fromPath), baseSpec))}${suffix}`;\n } else if (baseSpec.startsWith('/')) {\n return `${baseSpec.replace(/^\\/+/, '/')}${suffix}`;\n } else if (getApp().editorMode !== 'none') {\n const libRoot = '/'; //this._vfs.normalizePath(this._scriptsRoot || '/');\n // naked module, checking if it is a installed module in editor mode\n let depsLockPath = this._vfs.normalizePath(this._vfs.join(libRoot, 'libs/deps.lock.json'));\n let depsExists = await this._vfs.exists(depsLockPath);\n if (depsExists) {\n const content = (await this._vfs.readFile(depsLockPath, { encoding: 'utf8' })) as string;\n const depsInfo = JSON.parse(content) as { dependencies: Record<string, { entry: string }> };\n if (depsInfo?.dependencies[baseSpec]) {\n return `${this._vfs.normalizePath(this._vfs.join(libRoot, depsInfo.dependencies[baseSpec].entry))}${suffix}`;\n }\n }\n }\n return spec;\n }\n\n /**\n * Resolves a logical id to a concrete source path and type by probing extensions.\n *\n * Rules:\n * - If `logicalId` ends with `.ts` or `.js`/`.mjs` and is a file, return it.\n * - Else probe `logicalId.ts`, `logicalId.js`, `logicalId.mjs` in that order.\n * - Maps `.mjs` to type `'js'`.\n *\n * @param logicalId - The normalized logical module id (path-like).\n * @returns `{ type, path }` or `null` if not found.\n */\n async resolveSourcePath(logicalId: string) {\n const { path: normalizedLogicalId } = splitSpecifierQuery(logicalId);\n let type: Nullable<'js' | 'ts'> = null;\n let pathWithExt = '';\n if (normalizedLogicalId.endsWith('.ts')) {\n pathWithExt = normalizedLogicalId;\n type = 'ts';\n } else if (normalizedLogicalId.endsWith('.js') || normalizedLogicalId.endsWith('.mjs')) {\n pathWithExt = normalizedLogicalId;\n type = 'js';\n }\n if (type) {\n const exists = await this._vfs.exists(pathWithExt);\n if (!exists) {\n type = null;\n }\n const stat = await this._vfs.stat(pathWithExt);\n if (stat.isDirectory) {\n type = null;\n }\n }\n const types = ['ts', 'js', 'mjs'] as const;\n if (!type) {\n for (const t of types) {\n pathWithExt = `${normalizedLogicalId}.${t}`;\n const exists = await this._vfs.exists(pathWithExt);\n if (exists) {\n const stats = await this._vfs.stat(pathWithExt);\n if (stats.isFile) {\n type = t === 'ts' ? 'ts' : 'js';\n break;\n }\n }\n }\n }\n return type ? { type, path: pathWithExt } : null;\n }\n}\n"],"names":["toDataUrl","js","id","b64","textToBase64","encodeURIComponent","String","isAbsoluteUrl","spec","test","isSpecialUrl","isBareModule","startsWith","splitSpecifierQuery","hashIndex","indexOf","queryIndex","cutIndex","Math","min","path","suffix","slice","hasRawQuery","queryEnd","query","trim","split","some","part","ScriptRegistry","_vfs","_scriptsRoot","_built","_building","_builtDeps","vfs","scriptsRoot","Map","VFS","clear","invalidate","moduleId","normalized","variants","Set","endsWith","add","key","delete","entryId","deps","variant","has","fetchSource","type","pathWithExt","exists","stat","isDirectory","types","t","stats","isFile","code","readFile","encoding","resolveRuntimeUrl","resolveLogicalId","build","getApp","editorMode","getDependencies","fromId","dependencies","reStatic","reDynamic","normalizedId","srcPath","resolveSourcePath","undefined","gather","input","re","m","exec","entry","resolveModuleInfo","cached","get","pending","task","buildBundle","set","url","modules","collectModule","chunks","getSystemBundleRuntime","module","values","push","JSON","stringify","systemCode","join","keys","source","esmCode","transpileToESModule","rewritten","rewriteImportsToLogicalIds","transpileToSystemModule","dep","normalizePath","getTypeScriptRuntime","ts","window","Error","_id","logicalId","res","transpileModule","compilerOptions","target","ScriptTarget","ES2015","ModuleKind","ESNext","experimentalDecorators","useDefineForClassFields","fileName","outputText","allowJs","System","esModuleInterop","init","imports","parse","list","sort","a","b","s","out","last","im","d","hasQuote","ss","se","e","resolved","resolveImportTarget","replacement","depId","baseSpec","fromPath","dirname","replace","libRoot","depsLockPath","depsExists","content","depsInfo","normalizedLogicalId"],"mappings":";;;;AAMA;;;;;;;AAOC,IACD,SAASA,SAAAA,CAAUC,EAAU,EAAEC,EAAU,EAAA;AACvC,IAAA,MAAMC,MAAMC,YAAaH,CAAAA,EAAAA,CAAAA;IACzB,OAAO,CAAC,4BAA4B,EAAEE,GAAAA,CAAI,CAAC,EAAEE,kBAAAA,CAAmBC,OAAOJ,EAAM,CAAA,CAAA,CAAA,CAAA;AAC/E;AAEA;;;IAIA,SAASK,cAAcC,IAAY,EAAA;IACjC,OAAO,eAAA,CAAgBC,IAAI,CAACD,IAAAA,CAAAA;AAC9B;AAEA;;;IAIA,SAASE,aAAaF,IAAY,EAAA;IAChC,OAAO,gBAAA,CAAiBC,IAAI,CAACD,IAAAA,CAAAA;AAC/B;AAEA;;;IAIA,SAASG,aAAaH,IAAY,EAAA;AAChC,IAAA,OAAO,CAACA,IAAKI,CAAAA,UAAU,CAAC,IAAS,CAAA,IAAA,CAACJ,KAAKI,UAAU,CAAC,KAAU,CAAA,IAAA,CAACJ,KAAKI,UAAU,CAAC,QAAQ,CAACJ,IAAAA,CAAKI,UAAU,CAAC,IAAA,CAAA;AACxG;AAEA,SAASC,oBAAoBL,IAAY,EAAA;IACvC,MAAMM,SAAAA,GAAYN,IAAK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AAI,CAACF,WAAAA,CAAAA;oBACnC,IAAIM,KAAAA,CAAMC,MAAM,EAAE;wBAChBR,IAAOM,GAAAA,CAAAA,KAAM,OAAO,IAAO,GAAA,IAAA;AAC3B,wBAAA;AACF;AACF;AACF;AACF;AACA,QAAA,OAAON,IAAO,GAAA;AAAEA,YAAAA,IAAAA;YAAMnC,IAAMoC,EAAAA;SAAgB,GAAA,IAAA;AAC9C;AACF;;;;"}
1
+ {"version":3,"file":"scriptregistry.js","sources":["../../src/app/scriptregistry.ts"],"sourcesContent":["import type * as TS from 'typescript';\r\nimport type { Nullable, VFS } from '@zephyr3d/base';\r\nimport { textToBase64 } from '@zephyr3d/base';\r\nimport { init, parse } from 'es-module-lexer';\r\nimport { getApp } from './api';\r\n\r\n/**\r\n * Converts JavaScript source to a data URL tied to a logical module id.\r\n *\r\n * @param js - The JavaScript source code to embed.\r\n * @param id - Logical module identifier (used only for sourceURL tagging).\r\n * @returns A `data:text/javascript;base64,...` URL with an encoded `#id` suffix.\r\n * @internal\r\n */\r\nfunction toDataUrl(js: string, id: string) {\r\n const b64 = textToBase64(js);\r\n return `data:text/javascript;base64,${b64}#${encodeURIComponent(String(id))}`;\r\n}\r\n\r\n/**\r\n * Checks whether a specifier is an absolute HTTP(S) URL.\r\n * @internal\r\n */\r\nfunction isAbsoluteUrl(spec: string) {\r\n return /^https?:\\/\\//i.test(spec);\r\n}\r\n\r\n/**\r\n * Checks whether a specifier is a special URL (data: or blob:).\r\n * @internal\r\n */\r\nfunction isSpecialUrl(spec: string) {\r\n return /^(data|blob):/i.test(spec);\r\n}\r\n\r\n/**\r\n * Checks whether a specifier is a bare module (not starting with ./, ../, /, or #/).\r\n * @internal\r\n */\r\nfunction isBareModule(spec: string) {\r\n return !spec.startsWith('./') && !spec.startsWith('../') && !spec.startsWith('/') && !spec.startsWith('#/');\r\n}\r\n\r\nfunction splitSpecifierQuery(spec: string) {\r\n const hashIndex = spec.indexOf('#');\r\n const queryIndex = spec.indexOf('?');\r\n const cutIndex =\r\n queryIndex >= 0 && hashIndex >= 0\r\n ? Math.min(queryIndex, hashIndex)\r\n : queryIndex >= 0\r\n ? queryIndex\r\n : hashIndex;\r\n if (cutIndex < 0) {\r\n return {\r\n path: spec,\r\n suffix: ''\r\n };\r\n }\r\n return {\r\n path: spec.slice(0, cutIndex),\r\n suffix: spec.slice(cutIndex)\r\n };\r\n}\r\n\r\nfunction hasRawQuery(spec: string) {\r\n const { suffix } = splitSpecifierQuery(spec);\r\n if (!suffix || suffix[0] !== '?') {\r\n return false;\r\n }\r\n const queryEnd = suffix.indexOf('#');\r\n const query = (queryEnd >= 0 ? suffix.slice(1, queryEnd) : suffix.slice(1)).trim();\r\n if (!query) {\r\n return false;\r\n }\r\n return query.split('&').some((part) => part.trim() === 'raw');\r\n}\r\n\r\ntype ScriptModuleType = 'js' | 'ts';\r\n\r\ntype ScriptModuleInfo = {\r\n id: string;\r\n path: string;\r\n type: ScriptModuleType;\r\n deps: string[];\r\n systemCode: string;\r\n};\r\n\r\n/**\r\n * Resolves, builds, and serves runtime modules using a VFS.\r\n *\r\n * Responsibilities:\r\n * - Resolve logical module IDs to physical paths or URLs.\r\n * - In editor mode, bundle local script modules into a single data URL after transpile.\r\n * - Transpile TypeScript to JavaScript on the fly (requires `window.ts` TypeScript runtime).\r\n * - Gather static and dynamic import dependencies for tooling.\r\n *\r\n * Modes:\r\n * - Editor mode (`editorMode === true`): local script graphs are bundled to data URLs.\r\n * - Runtime mode (`editorMode === false`): returns .js/.mjs URLs directly (with .ts -\\> .js mapping).\r\n *\r\n * Caching:\r\n * - Built bundles are memoized in `_built` map keyed by canonical source path.\r\n *\r\n * @public\r\n */\r\nexport class ScriptRegistry {\r\n private _vfs: VFS;\r\n private _scriptsRoot: string;\r\n private _built: Map<string, string>; // logicalId -> dataURL\r\n private _building: Map<string, Promise<string>>;\r\n private _builtDeps: Map<string, Set<string>>;\r\n\r\n /**\r\n * @param vfs - The virtual file system for existence checks, reads, and path ops.\r\n * @param scriptsRoot - Root directory for script resolution (used with `#/` specifiers).\r\n */\r\n constructor(vfs: VFS, scriptsRoot: string) {\r\n this._vfs = vfs;\r\n this._scriptsRoot = scriptsRoot;\r\n this._built = new Map();\r\n this._building = new Map();\r\n this._builtDeps = new Map();\r\n }\r\n\r\n /**\r\n * The active virtual file system.\r\n *\r\n * Assigning a new VFS clears the build cache.\r\n */\r\n get VFS() {\r\n return this._vfs;\r\n }\r\n set VFS(vfs: VFS) {\r\n if (vfs !== this._vfs) {\r\n this._vfs = vfs;\r\n this._built.clear();\r\n this._building.clear();\r\n this._builtDeps.clear();\r\n }\r\n }\r\n\r\n /**\r\n * The root path used by `#/` specifiers.\r\n */\r\n get scriptsRoot() {\r\n return this._scriptsRoot;\r\n }\r\n set scriptsRoot(path: string) {\r\n this._scriptsRoot = path;\r\n }\r\n\r\n /**\r\n * Invalidates cached built module output for one logical module id, or clears the full cache.\r\n *\r\n * Pass the same logical id shape that callers use with {@link ScriptRegistry.resolveRuntimeUrl},\r\n * for example `/assets/scripts/foo.ts`, `/assets/scripts/foo.js`, or `/assets/scripts/foo`.\r\n *\r\n * @param moduleId - Optional logical module id to invalidate. Omit to clear the entire build cache.\r\n */\r\n invalidate(moduleId?: string) {\r\n if (!moduleId) {\r\n this._built.clear();\r\n this._building.clear();\r\n this._builtDeps.clear();\r\n return;\r\n }\r\n const normalized = String(moduleId);\r\n const variants = new Set([normalized]);\r\n if (normalized.endsWith('.ts') || normalized.endsWith('.js')) {\r\n variants.add(normalized.slice(0, -3));\r\n } else if (normalized.endsWith('.mjs')) {\r\n variants.add(normalized.slice(0, -4));\r\n } else {\r\n variants.add(`${normalized}.ts`);\r\n variants.add(`${normalized}.js`);\r\n variants.add(`${normalized}.mjs`);\r\n }\r\n for (const key of variants) {\r\n this._built.delete(key);\r\n this._building.delete(key);\r\n this._builtDeps.delete(key);\r\n }\r\n for (const [entryId, deps] of [...this._builtDeps]) {\r\n for (const variant of variants) {\r\n if (deps.has(variant)) {\r\n this._built.delete(entryId);\r\n this._building.delete(entryId);\r\n this._builtDeps.delete(entryId);\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Fetches raw source for a logical module id by probing known extensions.\r\n *\r\n * Search order:\r\n * - If `id` already ends with `.ts`, `.js`, or `.mjs` and is a file -\\> return it.\r\n * - Else try `.id.ts`, then `.id.js`, then `.id.mjs`.\r\n *\r\n * @param id - Logical module identifier (absolute or logical path-like).\r\n * @returns Source code, resolved path, and type (`'js' | 'ts'`), or `undefined` if not found.\r\n */\r\n protected async fetchSource(id: string) {\r\n let type: Nullable<'js' | 'ts'> = null;\r\n let pathWithExt = '';\r\n if (id.endsWith('.ts')) {\r\n pathWithExt = id;\r\n type = 'ts';\r\n } else if (id.endsWith('.js') || id.endsWith('.mjs')) {\r\n pathWithExt = id;\r\n type = 'js';\r\n }\r\n if (type) {\r\n const exists = await this._vfs.exists(pathWithExt);\r\n if (!exists) {\r\n type = null;\r\n }\r\n const stat = await this._vfs.stat(pathWithExt);\r\n if (stat.isDirectory) {\r\n type = null;\r\n }\r\n }\r\n const types = ['ts', 'js'] as const;\r\n if (!type) {\r\n for (const t of [...types, 'mjs'] as const) {\r\n pathWithExt = `${id}.${t}`;\r\n const exists = await this._vfs.exists(pathWithExt);\r\n if (exists) {\r\n const stats = await this._vfs.stat(pathWithExt);\r\n if (stats.isFile) {\r\n type = t === 'ts' ? 'ts' : 'js';\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n if (type) {\r\n const code = (await this._vfs.readFile(pathWithExt, { encoding: 'utf8' })) as string;\r\n return { code, type, path: pathWithExt };\r\n }\r\n }\r\n\r\n /**\r\n * Resolves a module entry to a URL suitable for dynamic import.\r\n *\r\n * Behavior:\r\n * - In editor mode, builds the module to a data URL.\r\n * - Otherwise, returns `.js` or `.mjs` URL directly:\r\n * - If `id` ends with `.js`: return as-is.\r\n * - If `id` ends with `.mjs`: return as-is.\r\n * - If `id` ends with `.ts`: map to `.js` (assumes pre-built file exists).\r\n * - Else: append `.js`.\r\n *\r\n * @param entryId - Entry module identifier (logical or path-like).\r\n * @returns A URL string that can be used in `import(...)`.\r\n */\r\n async resolveRuntimeUrl(entryId: string) {\r\n const id = await this.resolveLogicalId(entryId);\r\n if (id.startsWith('/assets/@builtins/')) {\r\n return await this.build(String(id));\r\n }\r\n return getApp().editorMode !== 'none'\r\n ? await this.build(String(id))\r\n : id.endsWith('.js') || id.endsWith('.mjs')\r\n ? id\r\n : id.endsWith('.ts')\r\n ? `${id.slice(0, -3)}.js`\r\n : `${id}.js`;\r\n }\r\n\r\n /**\r\n * Recursively gathers direct static and dynamic import dependencies for a module.\r\n *\r\n * Only relative specifiers (`./` or `../`) are followed. Absolute, special, and bare\r\n * module specifiers are ignored here.\r\n *\r\n * @param entryId - The starting (possibly relative) specifier from `fromId`.\r\n * @param fromId - The logical id of the module containing `entryId`.\r\n * @param dependencies - Output map of `resolvedSourcePath -\\> file contents`.\r\n */\r\n async getDependencies(entryId: string, fromId: string, dependencies: Record<string, string>) {\r\n const reStatic = /\\b(?:import|export)\\s+[^\"']*?from\\s+(['\"])([^'\"]+)\\1/g;\r\n const reDynamic = /\\bimport\\s*\\(\\s*(['\"])([^'\"]+)\\1\\s*\\)/g;\r\n\r\n const normalizedId = await this.resolveLogicalId(entryId, fromId);\r\n const srcPath = await this.resolveSourcePath(normalizedId);\r\n if (!srcPath || dependencies[srcPath.path] !== undefined) {\r\n return;\r\n }\r\n const code = (await this._vfs.readFile(srcPath.path, { encoding: 'utf8' })) as string;\r\n dependencies[srcPath.path] = code;\r\n\r\n const gather = async (input: string, re: RegExp) => {\r\n for (;;) {\r\n const m = re.exec(input);\r\n if (!m) {\r\n break;\r\n }\r\n\r\n const spec = m[2];\r\n\r\n if (spec.startsWith('./') || spec.startsWith('../')) {\r\n await this.getDependencies(spec, normalizedId, dependencies);\r\n }\r\n }\r\n };\r\n\r\n await gather(code, reStatic);\r\n await gather(code, reDynamic);\r\n }\r\n\r\n /**\r\n * Builds a logical module id into a bundled data URL (editor mode pipeline).\r\n *\r\n * Steps:\r\n * - Resolve source path (.ts/.js) via {@link ScriptRegistry.resolveSourcePath}.\r\n * - Collect reachable local imports without recursively building data URLs.\r\n * - Transpile local modules to `System.register`.\r\n * - Emit a single `data:` URL with a small module loader and memoize it in `_built`.\r\n *\r\n * @param id - Logical module id to build.\r\n * @returns Data URL string for dynamic import, or empty string if not found.\r\n */\r\n private async build(id: string) {\r\n const entry = await this.resolveModuleInfo(String(id));\r\n if (!entry) {\r\n return '';\r\n }\r\n\r\n const key = entry.id;\r\n const cached = this._built.get(key);\r\n if (cached) {\r\n return cached;\r\n }\r\n const pending = this._building.get(key);\r\n if (pending) {\r\n return await pending;\r\n }\r\n\r\n const task = this.buildBundle(key);\r\n this._building.set(key, task);\r\n try {\r\n const url = await task;\r\n if (url) {\r\n this._built.set(key, url);\r\n }\r\n return url;\r\n } finally {\r\n this._building.delete(key);\r\n }\r\n }\r\n\r\n private async buildBundle(entryId: string) {\r\n const modules = new Map<string, ScriptModuleInfo>();\r\n const entry = await this.collectModule(entryId, modules);\r\n if (!entry) {\r\n return '';\r\n }\r\n\r\n const chunks = [this.getSystemBundleRuntime()];\r\n for (const module of modules.values()) {\r\n chunks.push(`__z3dRegister(${JSON.stringify(module.id)}, () => {\\n${module.systemCode}\\n});`);\r\n }\r\n chunks.push(\r\n `const __z3dEntry = await __z3dLoad(${JSON.stringify(entry.id)});\\n` +\r\n `const plugin = __z3dEntry.plugin;\\n` +\r\n `const __z3dDefault = __z3dEntry.default ?? __z3dEntry.plugin ?? __z3dEntry;\\n` +\r\n `export { plugin };\\n` +\r\n `export default __z3dDefault;\\n` +\r\n `//# sourceURL=${entry.id}`\r\n );\r\n\r\n const url = toDataUrl(chunks.join('\\n'), entry.id);\r\n this._builtDeps.set(entry.id, new Set(modules.keys()));\r\n return url;\r\n }\r\n\r\n private async collectModule(id: string, modules: Map<string, ScriptModuleInfo>) {\r\n const module = await this.resolveModuleInfo(id);\r\n if (!module) {\r\n return null;\r\n }\r\n if (modules.has(module.id)) {\r\n return modules.get(module.id)!;\r\n }\r\n\r\n modules.set(module.id, module);\r\n\r\n const source = (await this._vfs.readFile(module.path, { encoding: 'utf8' })) as string;\r\n const esmCode = hasRawQuery(module.id)\r\n ? `export default ${JSON.stringify(source)};\\n`\r\n : await this.transpileToESModule(source, module.id, module.type);\r\n const rewritten = await this.rewriteImportsToLogicalIds(esmCode, module.id);\r\n module.deps = rewritten.deps;\r\n module.systemCode = await this.transpileToSystemModule(rewritten.code, module.id);\r\n\r\n for (const dep of module.deps) {\r\n await this.collectModule(dep, modules);\r\n }\r\n return module;\r\n }\r\n\r\n private async resolveModuleInfo(id: string): Promise<Nullable<ScriptModuleInfo>> {\r\n const srcPath = await this.resolveSourcePath(id);\r\n if (!srcPath) {\r\n return null;\r\n }\r\n const { suffix } = splitSpecifierQuery(String(id));\r\n const path = this._vfs.normalizePath(srcPath.path);\r\n return {\r\n id: `${path}${suffix}`,\r\n path,\r\n type: srcPath.type,\r\n deps: [],\r\n systemCode: ''\r\n };\r\n }\r\n\r\n private getTypeScriptRuntime() {\r\n const ts = (window as any).ts as typeof TS;\r\n if (!ts) {\r\n throw new Error('TypeScript runtime (window.ts) not found. Load typescript.js first.');\r\n }\r\n return ts;\r\n }\r\n\r\n private async transpileToESModule(code: string, _id: string, type: ScriptModuleType) {\r\n const logicalId = String(_id);\r\n\r\n if (type === 'js') {\r\n return code;\r\n }\r\n\r\n const ts = this.getTypeScriptRuntime();\r\n\r\n const res = ts.transpileModule(code, {\r\n compilerOptions: {\r\n target: ts.ScriptTarget.ES2020,\r\n module: ts.ModuleKind.ESNext,\r\n experimentalDecorators: true,\r\n useDefineForClassFields: false\r\n },\r\n fileName: logicalId\r\n });\r\n\r\n return res.outputText || '';\r\n }\r\n\r\n private async transpileToSystemModule(code: string, _id: string) {\r\n const logicalId = String(_id);\r\n const ts = this.getTypeScriptRuntime();\r\n const res = ts.transpileModule(code, {\r\n compilerOptions: {\r\n allowJs: true,\r\n // Keep modern syntax such as async generators, class fields, and private fields intact.\r\n target: ts.ScriptTarget.ES2022,\r\n module: ts.ModuleKind.System,\r\n esModuleInterop: true,\r\n experimentalDecorators: true,\r\n useDefineForClassFields: true\r\n },\r\n fileName: logicalId\r\n });\r\n return res.outputText || '';\r\n }\r\n\r\n /**\r\n * Rewrites local ESM specifiers to canonical source paths and records local deps.\r\n * External URLs and package imports are left for the native dynamic import path.\r\n */\r\n private async rewriteImportsToLogicalIds(code: string, fromId: string) {\r\n await init;\r\n const [imports] = parse(code);\r\n const list = [...imports].sort((a, b) => (a.s || 0) - (b.s || 0));\r\n const deps = new Set<string>();\r\n let out = '';\r\n let last = 0;\r\n\r\n for (const im of list) {\r\n // Skip import.meta entries reported by es-module-lexer.\r\n // Their \"specifier\" span points to the whole \"import.meta\" expression,\r\n // which must remain untouched.\r\n if (im.d === -2) {\r\n continue;\r\n }\r\n // must have quotes\r\n const hasQuote = im.ss != null && im.se != null;\r\n if (!hasQuote || im.se <= im.ss) {\r\n continue;\r\n }\r\n // must have contents\r\n if (im.e <= im.s) {\r\n continue;\r\n }\r\n // append [last, s)\r\n out += code.slice(last, im.s);\r\n\r\n const spec = code.slice(im.s, im.e); // original spec\r\n const resolved = await this.resolveImportTarget(spec, String(fromId));\r\n const replacement = resolved.id ?? spec;\r\n if (resolved.id) {\r\n deps.add(resolved.id);\r\n }\r\n out += replacement; // Do not wrap in quotes\r\n last = im.e;\r\n }\r\n out += code.slice(last);\r\n return { code: out, deps: [...deps] };\r\n }\r\n\r\n private async resolveImportTarget(spec: string, fromId: string) {\r\n if (isAbsoluteUrl(spec) || isSpecialUrl(spec) || spec.startsWith('@zephyr3d/')) {\r\n return { id: null };\r\n }\r\n\r\n const depId = await this.resolveLogicalId(spec, isBareModule(spec) ? undefined : fromId);\r\n const module = await this.resolveModuleInfo(depId);\r\n return { id: module?.id ?? null };\r\n }\r\n\r\n private getSystemBundleRuntime() {\r\n return `\r\nconst __z3dRegistry = new Map();\r\nlet __z3dCurrentId = '';\r\nconst System = {\r\n register(deps, declare) {\r\n if (!__z3dCurrentId) {\r\n throw new Error('System.register called without module id');\r\n }\r\n __z3dRegistry.set(__z3dCurrentId, {\r\n id: __z3dCurrentId,\r\n deps,\r\n declare,\r\n exports: Object.create(null),\r\n setters: [],\r\n execute: null,\r\n importers: [],\r\n state: 0\r\n });\r\n }\r\n};\r\nfunction __z3dRegister(id, factory) {\r\n const prev = __z3dCurrentId;\r\n __z3dCurrentId = id;\r\n try {\r\n factory();\r\n } finally {\r\n __z3dCurrentId = prev;\r\n }\r\n}\r\nfunction __z3dResolve(spec, parentId) {\r\n if (__z3dRegistry.has(spec)) {\r\n return spec;\r\n }\r\n if (spec.startsWith('./') || spec.startsWith('../')) {\r\n const base = parentId.slice(0, parentId.lastIndexOf('/') + 1);\r\n return new URL(spec, 'file://' + base).pathname;\r\n }\r\n return spec;\r\n}\r\nfunction __z3dExport(record, name, value) {\r\n if (name && typeof name === 'object') {\r\n for (const key of Object.keys(name)) {\r\n __z3dExport(record, key, name[key]);\r\n }\r\n return name;\r\n }\r\n record.exports[name] = value;\r\n for (const notify of record.importers) {\r\n notify(record.exports);\r\n }\r\n return value;\r\n}\r\nasync function __z3dLoad(spec, parentId = '') {\r\n const id = parentId ? __z3dResolve(spec, parentId) : spec;\r\n const record = __z3dRegistry.get(id);\r\n if (!record) {\r\n return await import(id);\r\n }\r\n if (record.state === 2 || record.state === 1) {\r\n return record.exports;\r\n }\r\n record.state = 1;\r\n const declaration = record.declare((name, value) => __z3dExport(record, name, value), {\r\n id,\r\n import: (dep) => __z3dLoad(dep, id),\r\n meta: { url: id }\r\n }) || {};\r\n record.setters = declaration.setters || [];\r\n record.execute = declaration.execute || (() => {});\r\n for (let i = 0; i < record.deps.length; i++) {\r\n const depId = __z3dResolve(record.deps[i], id);\r\n const depRecord = __z3dRegistry.get(depId);\r\n const depExports = depRecord ? await __z3dLoad(depId) : await import(depId);\r\n const setter = record.setters[i];\r\n if (typeof setter === 'function') {\r\n setter(depExports);\r\n if (depRecord) {\r\n depRecord.importers.push((exports) => setter(exports));\r\n }\r\n }\r\n }\r\n const result = record.execute();\r\n if (result && typeof result.then === 'function') {\r\n await result;\r\n }\r\n record.state = 2;\r\n return record.exports;\r\n}\r\n`;\r\n }\r\n\r\n /**\r\n * Resolves a specifier to a logical id suitable for further processing.\r\n *\r\n * Resolution rules:\r\n * - `#/path`: resolved against `scriptsRoot` via VFS join/normalize.\r\n * - `./` or `../`: resolved relative to `fromId` directory (requires `fromId`).\r\n * - `/absolute`: treated as absolute from root (normalized).\r\n * - Bare module in editor mode: if `/deps.lock.json` exists and contains an entry,\r\n * map to the dependency's `entry` path; otherwise return as-is.\r\n * - Else (non-editor bare module): return `spec` unchanged (external).\r\n *\r\n * @param spec - Import specifier string.\r\n * @param fromId - Optional base logical id used for relative resolution.\r\n * @returns A normalized logical id or an external specifier string.\r\n * @throws If a relative import is provided without `fromId`.\r\n */\r\n async resolveLogicalId(spec: string, fromId?: string) {\r\n const { path: baseSpec, suffix } = splitSpecifierQuery(spec);\r\n if (baseSpec.startsWith('#/')) {\r\n return `${this._vfs.normalizePath(this._vfs.join(this._scriptsRoot, baseSpec.slice(2)))}${suffix}`;\r\n } else if (baseSpec.startsWith('./') || baseSpec.startsWith('../')) {\r\n if (!fromId) {\r\n throw new Error(`Relative import \"${spec}\" requires fromId`);\r\n }\r\n const fromPath = splitSpecifierQuery(this._vfs.normalizePath(fromId)).path;\r\n return `${this._vfs.normalizePath(this._vfs.join(this._vfs.dirname(fromPath), baseSpec))}${suffix}`;\r\n } else if (baseSpec.startsWith('/')) {\r\n return `${baseSpec.replace(/^\\/+/, '/')}${suffix}`;\r\n } else if (getApp().editorMode !== 'none') {\r\n const libRoot = '/'; //this._vfs.normalizePath(this._scriptsRoot || '/');\r\n // naked module, checking if it is a installed module in editor mode\r\n let depsLockPath = this._vfs.normalizePath(this._vfs.join(libRoot, 'libs/deps.lock.json'));\r\n let depsExists = await this._vfs.exists(depsLockPath);\r\n if (depsExists) {\r\n const content = (await this._vfs.readFile(depsLockPath, { encoding: 'utf8' })) as string;\r\n const depsInfo = JSON.parse(content) as { dependencies: Record<string, { entry: string }> };\r\n if (depsInfo?.dependencies[baseSpec]) {\r\n return `${this._vfs.normalizePath(this._vfs.join(libRoot, depsInfo.dependencies[baseSpec].entry))}${suffix}`;\r\n }\r\n }\r\n }\r\n return spec;\r\n }\r\n\r\n /**\r\n * Resolves a logical id to a concrete source path and type by probing extensions.\r\n *\r\n * Rules:\r\n * - If `logicalId` ends with `.ts` or `.js`/`.mjs` and is a file, return it.\r\n * - Else probe `logicalId.ts`, `logicalId.js`, `logicalId.mjs` in that order.\r\n * - Maps `.mjs` to type `'js'`.\r\n *\r\n * @param logicalId - The normalized logical module id (path-like).\r\n * @returns `{ type, path }` or `null` if not found.\r\n */\r\n async resolveSourcePath(logicalId: string) {\r\n const { path: normalizedLogicalId } = splitSpecifierQuery(logicalId);\r\n let type: Nullable<'js' | 'ts'> = null;\r\n let pathWithExt = '';\r\n if (normalizedLogicalId.endsWith('.ts')) {\r\n pathWithExt = normalizedLogicalId;\r\n type = 'ts';\r\n } else if (normalizedLogicalId.endsWith('.js') || normalizedLogicalId.endsWith('.mjs')) {\r\n pathWithExt = normalizedLogicalId;\r\n type = 'js';\r\n }\r\n if (type) {\r\n const exists = await this._vfs.exists(pathWithExt);\r\n if (!exists) {\r\n type = null;\r\n }\r\n const stat = await this._vfs.stat(pathWithExt);\r\n if (stat.isDirectory) {\r\n type = null;\r\n }\r\n }\r\n const types = ['ts', 'js', 'mjs'] as const;\r\n if (!type) {\r\n for (const t of types) {\r\n pathWithExt = `${normalizedLogicalId}.${t}`;\r\n const exists = await this._vfs.exists(pathWithExt);\r\n if (exists) {\r\n const stats = await this._vfs.stat(pathWithExt);\r\n if (stats.isFile) {\r\n type = t === 'ts' ? 'ts' : 'js';\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n return type ? { type, path: pathWithExt } : null;\r\n }\r\n}\r\n"],"names":["toDataUrl","js","id","b64","textToBase64","encodeURIComponent","String","isAbsoluteUrl","spec","test","isSpecialUrl","isBareModule","startsWith","splitSpecifierQuery","hashIndex","indexOf","queryIndex","cutIndex","Math","min","path","suffix","slice","hasRawQuery","queryEnd","query","trim","split","some","part","ScriptRegistry","_vfs","_scriptsRoot","_built","_building","_builtDeps","vfs","scriptsRoot","Map","VFS","clear","invalidate","moduleId","normalized","variants","Set","endsWith","add","key","delete","entryId","deps","variant","has","fetchSource","type","pathWithExt","exists","stat","isDirectory","types","t","stats","isFile","code","readFile","encoding","resolveRuntimeUrl","resolveLogicalId","build","getApp","editorMode","getDependencies","fromId","dependencies","reStatic","reDynamic","normalizedId","srcPath","resolveSourcePath","undefined","gather","input","re","m","exec","entry","resolveModuleInfo","cached","get","pending","task","buildBundle","set","url","modules","collectModule","chunks","getSystemBundleRuntime","module","values","push","JSON","stringify","systemCode","join","keys","source","esmCode","transpileToESModule","rewritten","rewriteImportsToLogicalIds","transpileToSystemModule","dep","normalizePath","getTypeScriptRuntime","ts","window","Error","_id","logicalId","res","transpileModule","compilerOptions","target","ScriptTarget","ES2020","ModuleKind","ESNext","experimentalDecorators","useDefineForClassFields","fileName","outputText","allowJs","ES2022","System","esModuleInterop","init","imports","parse","list","sort","a","b","s","out","last","im","d","hasQuote","ss","se","e","resolved","resolveImportTarget","replacement","depId","baseSpec","fromPath","dirname","replace","libRoot","depsLockPath","depsExists","content","depsInfo","normalizedLogicalId"],"mappings":";;;;AAMA;;;;;;;AAOC,IACD,SAASA,SAAAA,CAAUC,EAAU,EAAEC,EAAU,EAAA;AACvC,IAAA,MAAMC,MAAMC,YAAaH,CAAAA,EAAAA,CAAAA;IACzB,OAAO,CAAC,4BAA4B,EAAEE,GAAAA,CAAI,CAAC,EAAEE,kBAAAA,CAAmBC,OAAOJ,EAAM,CAAA,CAAA,CAAA,CAAA;AAC/E;AAEA;;;IAIA,SAASK,cAAcC,IAAY,EAAA;IACjC,OAAO,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