@zephyr3d/scene 0.9.22 → 0.9.23
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/animation/joint_dynamics/collision.js +1 -7
- package/dist/animation/joint_dynamics/collision.js.map +1 -1
- package/dist/animation/joint_dynamics/constraints.js +2 -17
- package/dist/animation/joint_dynamics/constraints.js.map +1 -1
- package/dist/animation/joint_dynamics/controller.js +2 -20
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/joint_dynamics_system.js +1 -3
- package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +14 -60
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics/types.js +3 -3
- package/dist/animation/joint_dynamics/types.js.map +1 -1
- package/dist/app/app.js +23 -0
- package/dist/app/app.js.map +1 -1
- package/dist/app/scriptregistry.js +16 -53
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +2 -0
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +22 -0
- package/dist/asset/model.js.map +1 -1
- package/dist/blitter/bilateralblur.js +3 -1
- package/dist/blitter/bilateralblur.js.map +1 -1
- package/dist/blitter/blitter.js +3 -3
- package/dist/blitter/blitter.js.map +1 -1
- package/dist/camera/camera.js +398 -45
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/perspectivecamera.js +69 -2
- package/dist/camera/perspectivecamera.js.map +1 -1
- package/dist/index.d.ts +9113 -8734
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +1 -1
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +3 -3
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +8 -5
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +17 -10
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +1 -1
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +21 -6
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +33 -11
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/brdf.js +44 -12
- package/dist/material/mixins/pbr/brdf.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +149 -14
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mtoon.js +7 -4
- package/dist/material/mtoon.js.map +1 -1
- package/dist/material/pbrblueprint.js +5 -1
- package/dist/material/pbrblueprint.js.map +1 -1
- package/dist/material/pbrmr.js +1 -1
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +1 -1
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +186 -11
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/skin.js +2 -2
- package/dist/material/skin.js.map +1 -1
- package/dist/material/terrain-cm.js +5 -5
- package/dist/material/terrain-cm.js.map +1 -1
- package/dist/material/water.js +6 -4
- package/dist/material/water.js.map +1 -1
- package/dist/posteffect/bloom.js +54 -4
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +41 -0
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/posteffect.js +35 -0
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/sao.js +7 -6
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/skinsss.js +3 -3
- package/dist/posteffect/skinsss.js.map +1 -1
- package/dist/posteffect/ssgi.js +988 -436
- package/dist/posteffect/ssgi.js.map +1 -1
- package/dist/posteffect/ssr.js +83 -45
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +18 -15
- package/dist/posteffect/sss.js.map +1 -1
- package/dist/posteffect/taa.js +5 -4
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/posteffect/tonemap.js +15 -3
- package/dist/posteffect/tonemap.js.map +1 -1
- package/dist/render/abuffer_oit.js +2 -2
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/cluster_light.js +12 -6
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/drawable_mixin.js +8 -5
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/dualdepthpeeling_oit.js +10 -5
- package/dist/render/dualdepthpeeling_oit.js.map +1 -1
- package/dist/render/envlight.js +298 -5
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/gpu_picking.js +7 -5
- package/dist/render/gpu_picking.js.map +1 -1
- package/dist/render/hzb.js +28 -19
- package/dist/render/hzb.js.map +1 -1
- package/dist/render/lightpass.js +18 -4
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/render_queue.js +37 -4
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +8 -3
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/blackboard.js +20 -48
- package/dist/render/rendergraph/blackboard.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +18 -58
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/executor.js +89 -115
- package/dist/render/rendergraph/executor.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +1003 -715
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/frame_graph_context.js +1 -1
- package/dist/render/rendergraph/frame_graph_context.js.map +1 -1
- package/dist/render/rendergraph/frame_resource_requirements.js +14 -0
- package/dist/render/rendergraph/frame_resource_requirements.js.map +1 -0
- package/dist/render/rendergraph/history_resource_manager.js +74 -140
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +7 -5
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- package/dist/render/rendergraph/render_context.js +19 -0
- package/dist/render/rendergraph/render_context.js.map +1 -0
- package/dist/render/rendergraph/render_pipeline.js +315 -0
- package/dist/render/rendergraph/render_pipeline.js.map +1 -0
- package/dist/render/rendergraph/rendergraph.js +158 -141
- package/dist/render/rendergraph/rendergraph.js.map +1 -1
- package/dist/render/rendergraph/scene_render_context.js +267 -0
- package/dist/render/rendergraph/scene_render_context.js.map +1 -0
- package/dist/render/rendergraph/texture_affinity_cache.js +19 -0
- package/dist/render/rendergraph/texture_affinity_cache.js.map +1 -0
- package/dist/render/rendergraph/types.js +19 -31
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/renderpass.js +3 -3
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadow_mask_pass.js +7 -6
- package/dist/render/shadow_mask_pass.js.map +1 -1
- package/dist/render/sky.js +197 -35
- package/dist/render/sky.js.map +1 -1
- package/dist/render/weightedblended_oit.js +4 -3
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/basesprite.js +2 -0
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +10 -0
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +61 -2
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +178 -10
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/meshdrawable.js +89 -2
- package/dist/scene/meshdrawable.js.map +1 -1
- package/dist/scene/msdftext.js +2 -0
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +2 -0
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +2 -0
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene.js +34 -1
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +2 -1
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +2 -0
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +2 -0
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/atmosphere.js +5 -4
- package/dist/shaders/atmosphere.js.map +1 -1
- package/dist/shaders/fog.js +10 -3
- package/dist/shaders/fog.js.map +1 -1
- package/dist/shaders/shadow.js +96 -29
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shaders/ssgi_reprojection.js +118 -0
- package/dist/shaders/ssgi_reprojection.js.map +1 -0
- package/dist/shaders/ssr.js +322 -154
- package/dist/shaders/ssr.js.map +1 -1
- package/dist/shadow/esm.js +10 -7
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +12 -12
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +12 -12
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/pcss.js +15 -11
- package/dist/shadow/pcss.js.map +1 -1
- package/dist/shadow/shadow_impl.js +20 -2
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadowmapper.js +5 -2
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/ssm.js +13 -13
- package/dist/shadow/ssm.js.map +1 -1
- package/dist/shadow/vsm.js +7 -7
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/physical.js +74 -0
- package/dist/utility/physical.js.map +1 -0
- package/dist/utility/rendermipmap.js +2 -2
- package/dist/utility/rendermipmap.js.map +1 -1
- package/dist/utility/serialization/manager.js +3 -1
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +3 -1
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +3 -1
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +598 -2
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +180 -9
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +43 -3
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +3 -1
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +3 -1
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +3 -1
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +2 -0
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +70 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +3 -1
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +3 -1
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +3 -0
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +3 -1
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/values.js +2 -3
- package/dist/values.js.map +1 -1
- package/package.json +3 -3
package/dist/app/app.js
CHANGED
|
@@ -144,6 +144,29 @@ import { getApp, setApp } from './api.js';
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
|
+
* Advances exactly one frame outside the run loop.
|
|
148
|
+
*
|
|
149
|
+
* @remarks
|
|
150
|
+
* Uses the same `beginFrame()`/`frame()`/`endFrame()` sequence as the run
|
|
151
|
+
* loop, so per-frame non-idempotent state (history buffer ping-pong, frame
|
|
152
|
+
* counter, motion vector matrices) advances exactly once. Must not be called
|
|
153
|
+
* while the run loop started by {@link Application.run} is active.
|
|
154
|
+
*
|
|
155
|
+
* @returns true if the frame was rendered; false if the device skipped it
|
|
156
|
+
* (e.g. the rendering context is lost).
|
|
157
|
+
*/ stepFrame() {
|
|
158
|
+
if (this.device.isRendering) {
|
|
159
|
+
console.error('Application.stepFrame(): can not be called while the run loop is active');
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
if (this.device.beginFrame()) {
|
|
163
|
+
this.frame();
|
|
164
|
+
this.device.endFrame();
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
147
170
|
* Start the application's render loop.
|
|
148
171
|
*
|
|
149
172
|
* Uses the device's internal scheduling (`device.runLoop`) to repeatedly call `frame()`.
|
package/dist/app/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sources":["../../src/app/app.ts"],"sourcesContent":["import type { Nullable, RequireOptionals, VFS } from '@zephyr3d/base';\r\nimport { Observable, flushPendingDisposals } from '@zephyr3d/base';\r\nimport type { AbstractDevice, DeviceBackend } from '@zephyr3d/device';\r\nimport { InputManager } from './inputmgr';\r\nimport { Engine } from './engine';\r\nimport { getApp, setApp } from './api';\r\nimport type { ScreenConfig } from './screen';\r\n\r\ntype appEventMap = {\r\n /**\r\n * Emitted when the drawing surface (canvas/device) is resized.\r\n *\r\n * @param width - New drawable width in device pixels.\r\n * @param height - New drawable height in device pixels.\r\n */\r\n resize: [width: number, height: number];\r\n /**\r\n * Emitted every frame with timing information.\r\n *\r\n * @param deltaTimeMs - Elapsed time since last frame in milliseconds.\r\n * @param elapsedTimeMs - Elapsed time since app start in milliseconds.\r\n */\r\n tick: [deltaTimeMs: number, elapsedTimeMs: number];\r\n /** Pointer/mouse and keyboard input events forwarded by the Application. */\r\n click: [evt: PointerEvent];\r\n dblclick: [evt: PointerEvent];\r\n pointerdown: [evt: PointerEvent];\r\n pointerup: [evt: PointerEvent];\r\n pointermove: [evt: PointerEvent];\r\n pointercancel: [evt: PointerEvent];\r\n pointerenter: [evt: PointerEvent];\r\n pointerleave: [evt: PointerEvent];\r\n pointerover: [evt: PointerEvent];\r\n pointerout: [evt: PointerEvent];\r\n wheel: [evt: WheelEvent];\r\n keydown: [evt: KeyboardEvent];\r\n keyup: [evt: KeyboardEvent];\r\n keypress: [evt: KeyboardEvent];\r\n drag: [evt: DragEvent];\r\n dragenter: [evt: DragEvent];\r\n dragleave: [evt: DragEvent];\r\n dragover: [evt: DragEvent];\r\n dragstart: [evt: DragEvent];\r\n dragend: [evt: DragEvent];\r\n drop: [evt: DragEvent];\r\n};\r\n\r\n/**\r\n * Application editor/runtime mode.\r\n *\r\n * @public\r\n */\r\nexport type EditorMode = 'editor' | 'editor-preview' | 'none';\r\n\r\n/**\r\n * Options for Application.\r\n *\r\n * @public\r\n */\r\nexport interface AppOptions {\r\n /**\r\n * Target canvas element to attach the rendering device to.\r\n */\r\n canvas: HTMLCanvasElement;\r\n /**\r\n * Device backend implementation to use for GPU creation (e.g., WebGL/WebGPU backend).\r\n */\r\n backend: DeviceBackend;\r\n /**\r\n * Whether to enable multi-sample anti-aliasing (MSAA) if supported by the backend.\r\n * Defaults to false.\r\n */\r\n enableMSAA?: boolean;\r\n /**\r\n * Device pixel ratio used when creating the device. Defaults to `window.devicePixelRatio` or `1`.\r\n */\r\n pixelRatio?: number;\r\n}\r\n\r\n/**\r\n * Creation options for Application.\r\n *\r\n * Provides the canvas, device backend, and optional runtime and device configuration.\r\n * @public\r\n */\r\nexport interface AppCreationOptions extends AppOptions {\r\n /**\r\n * Options for the runtime scripting system.\r\n */\r\n runtimeOptions?: {\r\n /**\r\n * Virtual file system used to load scripts. Defaults to HttpFS at '.' if not provided.\r\n */\r\n VFS?: VFS;\r\n /**\r\n * Root directory for script files. Defaults to '/'.\r\n */\r\n scriptsRoot?: string;\r\n /**\r\n * Whether the application is running in editor mode. Should be true for user applications.\r\n */\r\n editorMode?: EditorMode;\r\n /**\r\n * Whether the runtime scripting system is enabled. Should be true for user applications.\r\n */\r\n enabled?: boolean;\r\n /**\r\n * Screen configuration\r\n */\r\n screen?: ScreenConfig;\r\n };\r\n}\r\n\r\n/**\r\n * Log severity levels.\r\n * @public\r\n */\r\nexport type LogMode = 'info' | 'warn' | 'error' | 'debug';\r\n\r\n/**\r\n * Application\r\n *\r\n * Entry-point and lifecycle coordinator for the engine. Responsible for:\r\n * - Creating and owning the rendering device from a chosen backend.\r\n * - Managing the per-frame loop, including timing and viewport setup.\r\n * - Forwarding device/DOM input events via an observable event map.\r\n * - Hosting the runtime scripting system and input manager.\r\n *\r\n * Singleton:\r\n * - Only one instance may exist at a time. Access via `{@link getApp}`.\r\n *\r\n * Events:\r\n * - See `appEventMap` for all emitted events (resize, tick, pointer/keyboard/drag).\r\n *\r\n * Usage:\r\n * - Construct with `AppOptions`, await `ready()`, then call `run()` to start the loop.\r\n *\r\n * @public\r\n */\r\nexport class Application extends Observable<appEventMap> {\r\n private readonly _options: RequireOptionals<AppOptions>;\r\n private _device: Nullable<AbstractDevice>;\r\n private readonly _inputManager: InputManager;\r\n private readonly _engine: Engine;\r\n private readonly _editorMode: EditorMode;\r\n private _ready: boolean;\r\n /**\r\n * Construct the Application singleton with the provided options.\r\n *\r\n * Throws if an instance already exists.\r\n *\r\n * @param opt - Application creation options (canvas, backend, and optional runtime/device settings).\r\n */\r\n constructor(opt: AppCreationOptions) {\r\n super();\r\n if (getApp()) {\r\n throw new Error('It is not allowed to have multiple Application instances');\r\n }\r\n setApp(this);\r\n\r\n this._options = {\r\n backend: opt.backend,\r\n enableMSAA: opt.enableMSAA ?? false,\r\n pixelRatio: opt.pixelRatio ?? window.devicePixelRatio ?? 1,\r\n canvas: opt.canvas\r\n };\r\n this._inputManager = new InputManager(this);\r\n this._engine = new Engine(\r\n opt.runtimeOptions?.VFS,\r\n opt.runtimeOptions?.scriptsRoot,\r\n opt.runtimeOptions?.enabled\r\n );\r\n if (opt.runtimeOptions?.screen) {\r\n this._engine.screen.config = opt.runtimeOptions.screen;\r\n }\r\n this._editorMode = opt.runtimeOptions?.editorMode ?? 'none';\r\n this._device = null;\r\n this._ready = false;\r\n }\r\n /**\r\n * Editor mode\r\n */\r\n get editorMode() {\r\n return this._editorMode;\r\n }\r\n /**\r\n * The input manager instance handling pointer/keyboard event routing.\r\n */\r\n get inputManager() {\r\n return this._inputManager;\r\n }\r\n /**\r\n * Get the instanceof {@link Engine}.\r\n */\r\n get engine() {\r\n return this._engine;\r\n }\r\n /**\r\n * The (sanitized) options used to create this application.\r\n *\r\n * Note: Defaults are applied for `enableMSAA` and `pixelRatio` if omitted.\r\n */\r\n get options() {\r\n return this._options;\r\n }\r\n /**\r\n * The initialized rendering device.\r\n *\r\n * Available after `await ready()`.\r\n */\r\n get device() {\r\n return this._device!;\r\n }\r\n /**\r\n * Convenience accessor for the device type name provided by the backend.\r\n */\r\n get deviceType() {\r\n return this._options.backend.typeName();\r\n }\r\n /**\r\n * Set keyboard focus to the device's canvas element.\r\n */\r\n focus() {\r\n this._device!.canvas.focus();\r\n }\r\n /**\r\n * Initialize the rendering device and start input processing.\r\n *\r\n * @throws If device creation fails.\r\n */\r\n async ready() {\r\n if (!this._ready) {\r\n this._device = await this._options.backend.createDevice(this._options.canvas, {\r\n dpr: this._options.pixelRatio,\r\n msaa: !!this._options.enableMSAA\r\n });\r\n if (!this._device) {\r\n throw new Error('App.init(): create device failed');\r\n }\r\n this._device.canvas.focus();\r\n await this._engine.init();\r\n this._inputManager.start();\r\n this._device.on('resize', (width, height) => {\r\n this._engine.screen.resolveViewport();\r\n this.dispatchEvent('resize', width, height);\r\n });\r\n this._ready = true;\r\n }\r\n }\r\n /**\r\n * Render a single frame.\r\n *\r\n * Steps:\r\n * - Flushes pending disposals from the previous frame.\r\n * - Clears device state (framebuffer, viewport, scissor).\r\n * - Queries frame timing from the device (`elapsedFrame`, `elapsedOverall`).\r\n * - Updates the runtime manager (scripting/behaviors).\r\n * - Emits `tick` with delta/elapsed times.\r\n *\r\n * Safe to call manually; also used by the run loop.\r\n */\r\n frame() {\r\n // Processes all pending disposals from the previous frame.\r\n flushPendingDisposals();\r\n if (this._ready) {\r\n this.device.setFramebuffer(null);\r\n this.device.setViewport(null);\r\n this.device.setScissor(null);\r\n const dt = this.device.frameInfo.elapsedFrame;\r\n const elapsed = this.device.frameInfo.elapsedOverall;\r\n this.dispatchEvent('tick', dt, elapsed);\r\n this._engine.update(dt * 0.001, elapsed * 0.001);\r\n this._engine.render();\r\n }\r\n }\r\n /**\r\n * Start the application's render loop.\r\n *\r\n * Uses the device's internal scheduling (`device.runLoop`) to repeatedly call `frame()`.\r\n */\r\n run() {\r\n this.device.runLoop(() => {\r\n this.frame();\r\n });\r\n }\r\n /**\r\n * Stop the application's render loop.\r\n *\r\n * Uses `device.exitLoop()` to end the scheduling started by `run()`.\r\n */\r\n stop() {\r\n this.device.exitLoop();\r\n }\r\n}\r\n"],"names":["Application","Observable","_options","_device","_inputManager","_engine","_editorMode","_ready","opt","getApp","Error","setApp","backend","enableMSAA","pixelRatio","window","devicePixelRatio","canvas","InputManager","Engine","runtimeOptions","VFS","scriptsRoot","enabled","screen","config","editorMode","inputManager","engine","options","device","deviceType","typeName","focus","ready","createDevice","dpr","msaa","init","start","on","width","height","resolveViewport","dispatchEvent","frame","flushPendingDisposals","setFramebuffer","setViewport","setScissor","dt","frameInfo","elapsedFrame","elapsed","elapsedOverall","update","render","run","runLoop","stop","exitLoop"],"mappings":";;;;;AAuHA;;;;;;;;;;;;;;;;;;;IAoBO,MAAMA,WAAoBC,SAAAA,UAAAA,CAAAA;IACdC,QAAuC;IAChDC,OAAkC;IACzBC,aAA4B;IAC5BC,OAAgB;IAChBC,WAAwB;IACjCC,MAAgB;AACxB;;;;;;MAOA,WAAA,CAAYC,GAAuB,CAAE;QACnC,KAAK,EAAA;AACL,QAAA,IAAIC,MAAU,EAAA,EAAA;AACZ,YAAA,MAAM,IAAIC,KAAM,CAAA,0DAAA,CAAA;AAClB;AACAC,QAAAA,MAAAA,CAAO,IAAI,CA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E;AACf,YAAA,IAAI,CAACuB,MAAM,CAACiB,cAAc,CAAC,IAAA,CAAA;AAC3B,YAAA,IAAI,CAACjB,MAAM,CAACkB,WAAW,CAAC,IAAA,CAAA;AACxB,YAAA,IAAI,CAAClB,MAAM,CAACmB,UAAU,CAAC,IAAA,CAAA;AACvB,YAAA,MAAMC,KAAK,IAAI,CAACpB,MAAM,CAACqB,SAAS,CAACC,YAAY;AAC7C,YAAA,MAAMC,UAAU,IAAI,CAACvB,MAAM,CAACqB,SAAS,CAACG,cAAc;AACpD,YAAA,IAAI,CAACV,aAAa,CAAC,MAAA,EAAQM,EAAIG,EAAAA,OAAAA,CAAAA;AAC/B,YAAA,IAAI,CAAChD,OAAO,CAACkD,MAAM,CAACL,EAAAA,GAAK,OAAOG,OAAU,GAAA,KAAA,CAAA;YAC1C,IAAI,CAAChD,OAAO,CAACmD,MAAM,EAAA;AACrB;AACF;AACA;;;;AAIC,MACDC,GAAM,GAAA;AACJ,QAAA,IAAI,CAAC3B,MAAM,CAAC4B,OAAO,CAAC,IAAA;AAClB,YAAA,IAAI,CAACb,KAAK,EAAA;AACZ,SAAA,CAAA;AACF;AACA;;;;AAIC,MACDc,IAAO,GAAA;QACL,IAAI,CAAC7B,MAAM,CAAC8B,QAAQ,EAAA;AACtB;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"app.js","sources":["../../src/app/app.ts"],"sourcesContent":["import type { Nullable, RequireOptionals, VFS } from '@zephyr3d/base';\r\nimport { Observable, flushPendingDisposals } from '@zephyr3d/base';\r\nimport type { AbstractDevice, DeviceBackend } from '@zephyr3d/device';\r\nimport { InputManager } from './inputmgr';\r\nimport { Engine } from './engine';\r\nimport { getApp, setApp } from './api';\r\nimport type { ScreenConfig } from './screen';\r\n\r\ntype appEventMap = {\r\n /**\r\n * Emitted when the drawing surface (canvas/device) is resized.\r\n *\r\n * @param width - New drawable width in device pixels.\r\n * @param height - New drawable height in device pixels.\r\n */\r\n resize: [width: number, height: number];\r\n /**\r\n * Emitted every frame with timing information.\r\n *\r\n * @param deltaTimeMs - Elapsed time since last frame in milliseconds.\r\n * @param elapsedTimeMs - Elapsed time since app start in milliseconds.\r\n */\r\n tick: [deltaTimeMs: number, elapsedTimeMs: number];\r\n /** Pointer/mouse and keyboard input events forwarded by the Application. */\r\n click: [evt: PointerEvent];\r\n dblclick: [evt: PointerEvent];\r\n pointerdown: [evt: PointerEvent];\r\n pointerup: [evt: PointerEvent];\r\n pointermove: [evt: PointerEvent];\r\n pointercancel: [evt: PointerEvent];\r\n pointerenter: [evt: PointerEvent];\r\n pointerleave: [evt: PointerEvent];\r\n pointerover: [evt: PointerEvent];\r\n pointerout: [evt: PointerEvent];\r\n wheel: [evt: WheelEvent];\r\n keydown: [evt: KeyboardEvent];\r\n keyup: [evt: KeyboardEvent];\r\n keypress: [evt: KeyboardEvent];\r\n drag: [evt: DragEvent];\r\n dragenter: [evt: DragEvent];\r\n dragleave: [evt: DragEvent];\r\n dragover: [evt: DragEvent];\r\n dragstart: [evt: DragEvent];\r\n dragend: [evt: DragEvent];\r\n drop: [evt: DragEvent];\r\n};\r\n\r\n/**\r\n * Application editor/runtime mode.\r\n *\r\n * @public\r\n */\r\nexport type EditorMode = 'editor' | 'editor-preview' | 'none';\r\n\r\n/**\r\n * Options for Application.\r\n *\r\n * @public\r\n */\r\nexport interface AppOptions {\r\n /**\r\n * Target canvas element to attach the rendering device to.\r\n */\r\n canvas: HTMLCanvasElement;\r\n /**\r\n * Device backend implementation to use for GPU creation (e.g., WebGL/WebGPU backend).\r\n */\r\n backend: DeviceBackend;\r\n /**\r\n * Whether to enable multi-sample anti-aliasing (MSAA) if supported by the backend.\r\n * Defaults to false.\r\n */\r\n enableMSAA?: boolean;\r\n /**\r\n * Device pixel ratio used when creating the device. Defaults to `window.devicePixelRatio` or `1`.\r\n */\r\n pixelRatio?: number;\r\n}\r\n\r\n/**\r\n * Creation options for Application.\r\n *\r\n * Provides the canvas, device backend, and optional runtime and device configuration.\r\n * @public\r\n */\r\nexport interface AppCreationOptions extends AppOptions {\r\n /**\r\n * Options for the runtime scripting system.\r\n */\r\n runtimeOptions?: {\r\n /**\r\n * Virtual file system used to load scripts. Defaults to HttpFS at '.' if not provided.\r\n */\r\n VFS?: VFS;\r\n /**\r\n * Root directory for script files. Defaults to '/'.\r\n */\r\n scriptsRoot?: string;\r\n /**\r\n * Whether the application is running in editor mode. Should be true for user applications.\r\n */\r\n editorMode?: EditorMode;\r\n /**\r\n * Whether the runtime scripting system is enabled. Should be true for user applications.\r\n */\r\n enabled?: boolean;\r\n /**\r\n * Screen configuration\r\n */\r\n screen?: ScreenConfig;\r\n };\r\n}\r\n\r\n/**\r\n * Log severity levels.\r\n * @public\r\n */\r\nexport type LogMode = 'info' | 'warn' | 'error' | 'debug';\r\n\r\n/**\r\n * Application\r\n *\r\n * Entry-point and lifecycle coordinator for the engine. Responsible for:\r\n * - Creating and owning the rendering device from a chosen backend.\r\n * - Managing the per-frame loop, including timing and viewport setup.\r\n * - Forwarding device/DOM input events via an observable event map.\r\n * - Hosting the runtime scripting system and input manager.\r\n *\r\n * Singleton:\r\n * - Only one instance may exist at a time. Access via `{@link getApp}`.\r\n *\r\n * Events:\r\n * - See `appEventMap` for all emitted events (resize, tick, pointer/keyboard/drag).\r\n *\r\n * Usage:\r\n * - Construct with `AppOptions`, await `ready()`, then call `run()` to start the loop.\r\n *\r\n * @public\r\n */\r\nexport class Application extends Observable<appEventMap> {\r\n private readonly _options: RequireOptionals<AppOptions>;\r\n private _device: Nullable<AbstractDevice>;\r\n private readonly _inputManager: InputManager;\r\n private readonly _engine: Engine;\r\n private readonly _editorMode: EditorMode;\r\n private _ready: boolean;\r\n /**\r\n * Construct the Application singleton with the provided options.\r\n *\r\n * Throws if an instance already exists.\r\n *\r\n * @param opt - Application creation options (canvas, backend, and optional runtime/device settings).\r\n */\r\n constructor(opt: AppCreationOptions) {\r\n super();\r\n if (getApp()) {\r\n throw new Error('It is not allowed to have multiple Application instances');\r\n }\r\n setApp(this);\r\n\r\n this._options = {\r\n backend: opt.backend,\r\n enableMSAA: opt.enableMSAA ?? false,\r\n pixelRatio: opt.pixelRatio ?? window.devicePixelRatio ?? 1,\r\n canvas: opt.canvas\r\n };\r\n this._inputManager = new InputManager(this);\r\n this._engine = new Engine(\r\n opt.runtimeOptions?.VFS,\r\n opt.runtimeOptions?.scriptsRoot,\r\n opt.runtimeOptions?.enabled\r\n );\r\n if (opt.runtimeOptions?.screen) {\r\n this._engine.screen.config = opt.runtimeOptions.screen;\r\n }\r\n this._editorMode = opt.runtimeOptions?.editorMode ?? 'none';\r\n this._device = null;\r\n this._ready = false;\r\n }\r\n /**\r\n * Editor mode\r\n */\r\n get editorMode() {\r\n return this._editorMode;\r\n }\r\n /**\r\n * The input manager instance handling pointer/keyboard event routing.\r\n */\r\n get inputManager() {\r\n return this._inputManager;\r\n }\r\n /**\r\n * Get the instanceof {@link Engine}.\r\n */\r\n get engine() {\r\n return this._engine;\r\n }\r\n /**\r\n * The (sanitized) options used to create this application.\r\n *\r\n * Note: Defaults are applied for `enableMSAA` and `pixelRatio` if omitted.\r\n */\r\n get options() {\r\n return this._options;\r\n }\r\n /**\r\n * The initialized rendering device.\r\n *\r\n * Available after `await ready()`.\r\n */\r\n get device() {\r\n return this._device!;\r\n }\r\n /**\r\n * Convenience accessor for the device type name provided by the backend.\r\n */\r\n get deviceType() {\r\n return this._options.backend.typeName();\r\n }\r\n /**\r\n * Set keyboard focus to the device's canvas element.\r\n */\r\n focus() {\r\n this._device!.canvas.focus();\r\n }\r\n /**\r\n * Initialize the rendering device and start input processing.\r\n *\r\n * @throws If device creation fails.\r\n */\r\n async ready() {\r\n if (!this._ready) {\r\n this._device = await this._options.backend.createDevice(this._options.canvas, {\r\n dpr: this._options.pixelRatio,\r\n msaa: !!this._options.enableMSAA\r\n });\r\n if (!this._device) {\r\n throw new Error('App.init(): create device failed');\r\n }\r\n this._device.canvas.focus();\r\n await this._engine.init();\r\n this._inputManager.start();\r\n this._device.on('resize', (width, height) => {\r\n this._engine.screen.resolveViewport();\r\n this.dispatchEvent('resize', width, height);\r\n });\r\n this._ready = true;\r\n }\r\n }\r\n /**\r\n * Render a single frame.\r\n *\r\n * Steps:\r\n * - Flushes pending disposals from the previous frame.\r\n * - Clears device state (framebuffer, viewport, scissor).\r\n * - Queries frame timing from the device (`elapsedFrame`, `elapsedOverall`).\r\n * - Updates the runtime manager (scripting/behaviors).\r\n * - Emits `tick` with delta/elapsed times.\r\n *\r\n * Safe to call manually; also used by the run loop.\r\n */\r\n frame() {\r\n // Processes all pending disposals from the previous frame.\r\n flushPendingDisposals();\r\n if (this._ready) {\r\n this.device.setFramebuffer(null);\r\n this.device.setViewport(null);\r\n this.device.setScissor(null);\r\n const dt = this.device.frameInfo.elapsedFrame;\r\n const elapsed = this.device.frameInfo.elapsedOverall;\r\n this.dispatchEvent('tick', dt, elapsed);\r\n this._engine.update(dt * 0.001, elapsed * 0.001);\r\n this._engine.render();\r\n }\r\n }\r\n /**\r\n * Advances exactly one frame outside the run loop.\r\n *\r\n * @remarks\r\n * Uses the same `beginFrame()`/`frame()`/`endFrame()` sequence as the run\r\n * loop, so per-frame non-idempotent state (history buffer ping-pong, frame\r\n * counter, motion vector matrices) advances exactly once. Must not be called\r\n * while the run loop started by {@link Application.run} is active.\r\n *\r\n * @returns true if the frame was rendered; false if the device skipped it\r\n * (e.g. the rendering context is lost).\r\n */\r\n stepFrame(): boolean {\r\n if (this.device.isRendering) {\r\n console.error('Application.stepFrame(): can not be called while the run loop is active');\r\n return false;\r\n }\r\n if (this.device.beginFrame()) {\r\n this.frame();\r\n this.device.endFrame();\r\n return true;\r\n }\r\n return false;\r\n }\r\n /**\r\n * Start the application's render loop.\r\n *\r\n * Uses the device's internal scheduling (`device.runLoop`) to repeatedly call `frame()`.\r\n */\r\n run() {\r\n this.device.runLoop(() => {\r\n this.frame();\r\n });\r\n }\r\n /**\r\n * Stop the application's render loop.\r\n *\r\n * Uses `device.exitLoop()` to end the scheduling started by `run()`.\r\n */\r\n stop() {\r\n this.device.exitLoop();\r\n }\r\n}\r\n"],"names":["Application","Observable","_options","_device","_inputManager","_engine","_editorMode","_ready","opt","getApp","Error","setApp","backend","enableMSAA","pixelRatio","window","devicePixelRatio","canvas","InputManager","Engine","runtimeOptions","VFS","scriptsRoot","enabled","screen","config","editorMode","inputManager","engine","options","device","deviceType","typeName","focus","ready","createDevice","dpr","msaa","init","start","on","width","height","resolveViewport","dispatchEvent","frame","flushPendingDisposals","setFramebuffer","setViewport","setScissor","dt","frameInfo","elapsedFrame","elapsed","elapsedOverall","update","render","stepFrame","isRendering","console","error","beginFrame","endFrame","run","runLoop","stop","exitLoop"],"mappings":";;;;;AAuHA;;;;;;;;;;;;;;;;;;;IAoBO,MAAMA,WAAoBC,SAAAA,UAAAA,CAAAA;IACdC,QAAuC;IAChDC,OAAkC;IACzBC,aAA4B;IAC5BC,OAAgB;IAChBC,WAAwB;IACjCC,MAAgB;AACxB;;;;;;MAOA,WAAA,CAAYC,GAAuB,CAAE;QACnC,KAAK,EAAA;AACL,QAAA,IAAIC,MAAU,EAAA,EAAA;AACZ,YAAA,MAAM,IAAIC,KAAM,CAAA,0DAAA,CAAA;AAClB;AACAC,QAAAA,MAAAA,CAAO,IAAI,CAAA;QAEX,IAAI,CAACT,QAAQ,GAAG;AACdU,YAAAA,OAAAA,EAASJ,IAAII,OAAO;YACpBC,UAAYL,EAAAA,GAAAA,CAAIK,UAAU,IAAI,KAAA;AAC9BC,YAAAA,UAAAA,EAAYN,GAAIM,CAAAA,UAAU,IAAIC,MAAAA,CAAOC,gBAAgB,IAAI,CAAA;AACzDC,YAAAA,MAAAA,EAAQT,IAAIS;AACd,SAAA;AACA,QAAA,IAAI,CAACb,aAAa,GAAG,IAAIc,aAAa,IAAI,CAAA;AAC1C,QAAA,IAAI,CAACb,OAAO,GAAG,IAAIc,OACjBX,GAAIY,CAAAA,cAAc,EAAEC,GAAAA,EACpBb,IAAIY,cAAc,EAAEE,WACpBd,EAA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,CAACL,EAAAA,GAAK,OAAOG,OAAU,GAAA,KAAA,CAAA;YAC1C,IAAI,CAAChD,OAAO,CAACmD,MAAM,EAAA;AACrB;AACF;AACA;;;;;;;;;;;AAWC,MACDC,SAAqB,GAAA;AACnB,QAAA,IAAI,IAAI,CAAC3B,MAAM,CAAC4B,WAAW,EAAE;AAC3BC,YAAAA,OAAAA,CAAQC,KAAK,CAAC,yEAAA,CAAA;YACd,OAAO,KAAA;AACT;AACA,QAAA,IAAI,IAAI,CAAC9B,MAAM,CAAC+B,UAAU,EAAI,EAAA;AAC5B,YAAA,IAAI,CAAChB,KAAK,EAAA;YACV,IAAI,CAACf,MAAM,CAACgC,QAAQ,EAAA;YACpB,OAAO,IAAA;AACT;QACA,OAAO,KAAA;AACT;AACA;;;;AAIC,MACDC,GAAM,GAAA;AACJ,QAAA,IAAI,CAACjC,MAAM,CAACkC,OAAO,CAAC,IAAA;AAClB,YAAA,IAAI,CAACnB,KAAK,EAAA;AACZ,SAAA,CAAA;AACF;AACA;;;;AAIC,MACDoB,IAAO,GAAA;QACL,IAAI,CAACnC,MAAM,CAACoC,QAAQ,EAAA;AACtB;AACF;;;;"}
|
|
@@ -59,10 +59,8 @@ function hasRawQuery(spec) {
|
|
|
59
59
|
return query.split('&').some((part)=>part.trim() === 'raw');
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Realm-global
|
|
63
|
-
* registry
|
|
64
|
-
* module registry so a module evaluates once and its exports (including
|
|
65
|
-
* module-level singletons) are identical across entry bundles.
|
|
62
|
+
* Realm-global key for per-registry module stores. Modules evaluate once per
|
|
63
|
+
* registry, preserving shared exports and singletons across entry bundles.
|
|
66
64
|
* @internal
|
|
67
65
|
*/ const SCRIPT_MODULES_GLOBAL_KEY = '__z3dScriptModules';
|
|
68
66
|
let scriptRegistryNamespaceCounter = 0;
|
|
@@ -70,16 +68,11 @@ function nextScriptRegistryNamespace() {
|
|
|
70
68
|
return `z3d-scripts:${++scriptRegistryNamespaceCounter}`;
|
|
71
69
|
}
|
|
72
70
|
/**
|
|
73
|
-
*
|
|
74
|
-
* to ignore registrations coming from bundles older than the one that already
|
|
75
|
-
* registered a module, so late imports of stale bundles cannot downgrade a
|
|
76
|
-
* module record.
|
|
71
|
+
* Build serial preventing stale bundles from replacing newer module records.
|
|
77
72
|
* @internal
|
|
78
73
|
*/ let scriptBuildSerialCounter = 0;
|
|
79
74
|
/**
|
|
80
|
-
* FNV-1a
|
|
81
|
-
* Rebuilding an unchanged module keeps its already-evaluated instance;
|
|
82
|
-
* changed content replaces the record so the next load re-evaluates.
|
|
75
|
+
* FNV-1a content version for shared module records.
|
|
83
76
|
* @internal
|
|
84
77
|
*/ function hashModuleCode(text) {
|
|
85
78
|
let h = 0x811c9dc5;
|
|
@@ -90,27 +83,10 @@ function nextScriptRegistryNamespace() {
|
|
|
90
83
|
return (h >>> 0).toString(36);
|
|
91
84
|
}
|
|
92
85
|
/**
|
|
93
|
-
* Resolves
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* - In editor mode, bundle local script modules into a single data URL after transpile.
|
|
98
|
-
* - Transpile TypeScript to JavaScript on the fly (requires `window.ts` TypeScript runtime).
|
|
99
|
-
* - Gather static and dynamic import dependencies for tooling.
|
|
100
|
-
*
|
|
101
|
-
* Modes:
|
|
102
|
-
* - Editor mode (`editorMode === true`): local script graphs are bundled to data URLs.
|
|
103
|
-
* - Runtime mode (`editorMode === false`): returns .js/.mjs URLs directly (with .ts -\> .js mapping).
|
|
104
|
-
*
|
|
105
|
-
* Caching:
|
|
106
|
-
* - Built bundles are memoized in `_built` map keyed by canonical source path.
|
|
107
|
-
* - At runtime, all bundles built by the same registry share one realm-global
|
|
108
|
-
* module registry (keyed by a per-registry namespace): a local module is
|
|
109
|
-
* evaluated once no matter how many entry bundles inline it, so module-level
|
|
110
|
-
* singletons are identical across entries. Module records are versioned by a
|
|
111
|
-
* content hash — rebuilding an unchanged module reuses its evaluated
|
|
112
|
-
* instance, while changed content replaces the record so the next load
|
|
113
|
-
* re-evaluates the new code.
|
|
86
|
+
* Resolves and builds VFS scripts. Editor mode transpiles TypeScript and bundles
|
|
87
|
+
* local graphs into data URLs; runtime mode returns script URLs directly. Bundles
|
|
88
|
+
* from one registry share module instances, while content-derived versions
|
|
89
|
+
* preserve unchanged instances and invalidate changed dependency graphs.
|
|
114
90
|
*
|
|
115
91
|
* @public
|
|
116
92
|
*/ class ScriptRegistry {
|
|
@@ -144,8 +120,7 @@ function nextScriptRegistryNamespace() {
|
|
|
144
120
|
this._built.clear();
|
|
145
121
|
this._building.clear();
|
|
146
122
|
this._builtDeps.clear();
|
|
147
|
-
//
|
|
148
|
-
// must not be reused as instances for same-named modules of the new VFS.
|
|
123
|
+
// A new VFS must not reuse same-named module instances from the old VFS.
|
|
149
124
|
const root = globalThis[SCRIPT_MODULES_GLOBAL_KEY];
|
|
150
125
|
root?.delete(this._namespace);
|
|
151
126
|
this._namespace = nextScriptRegistryNamespace();
|
|
@@ -363,9 +338,7 @@ function nextScriptRegistryNamespace() {
|
|
|
363
338
|
if (!entry) {
|
|
364
339
|
return '';
|
|
365
340
|
}
|
|
366
|
-
//
|
|
367
|
-
// module whose (transitive) dependencies changed is re-registered and
|
|
368
|
-
// re-evaluated even when its own source is unchanged.
|
|
341
|
+
// Include transitive dependencies in versions so their changes trigger re-evaluation.
|
|
369
342
|
this.applyEffectiveVersions(modules);
|
|
370
343
|
const serial = ++scriptBuildSerialCounter;
|
|
371
344
|
const chunks = [
|
|
@@ -482,7 +455,7 @@ function nextScriptRegistryNamespace() {
|
|
|
482
455
|
const res = ts.transpileModule(code, {
|
|
483
456
|
compilerOptions: {
|
|
484
457
|
allowJs: true,
|
|
485
|
-
//
|
|
458
|
+
// Preserve syntax supported by the runtime.
|
|
486
459
|
target: ts.ScriptTarget.ES2022,
|
|
487
460
|
module: ts.ModuleKind.System,
|
|
488
461
|
esModuleInterop: true,
|
|
@@ -506,30 +479,25 @@ function nextScriptRegistryNamespace() {
|
|
|
506
479
|
let out = '';
|
|
507
480
|
let last = 0;
|
|
508
481
|
for (const im of list){
|
|
509
|
-
//
|
|
510
|
-
// Their "specifier" span points to the whole "import.meta" expression,
|
|
511
|
-
// which must remain untouched.
|
|
482
|
+
// es-module-lexer reports import.meta spans, which must not be rewritten.
|
|
512
483
|
if (im.d === -2) {
|
|
513
484
|
continue;
|
|
514
485
|
}
|
|
515
|
-
// must have quotes
|
|
516
486
|
const hasQuote = im.ss != null && im.se != null;
|
|
517
487
|
if (!hasQuote || im.se <= im.ss) {
|
|
518
488
|
continue;
|
|
519
489
|
}
|
|
520
|
-
// must have contents
|
|
521
490
|
if (im.e <= im.s) {
|
|
522
491
|
continue;
|
|
523
492
|
}
|
|
524
|
-
// append [last, s)
|
|
525
493
|
out += code.slice(last, im.s);
|
|
526
|
-
const spec = code.slice(im.s, im.e);
|
|
494
|
+
const spec = code.slice(im.s, im.e);
|
|
527
495
|
const resolved = await this.resolveImportTarget(spec, String(fromId));
|
|
528
496
|
const replacement = resolved.id ?? spec;
|
|
529
497
|
if (resolved.id) {
|
|
530
498
|
deps.add(resolved.id);
|
|
531
499
|
}
|
|
532
|
-
out += replacement;
|
|
500
|
+
out += replacement;
|
|
533
501
|
last = im.e;
|
|
534
502
|
}
|
|
535
503
|
out += code.slice(last);
|
|
@@ -587,11 +555,7 @@ const System = {
|
|
|
587
555
|
}
|
|
588
556
|
};
|
|
589
557
|
function __z3dRegister(id, version, serial, factory) {
|
|
590
|
-
//
|
|
591
|
-
// by another bundle with the same effective version is reused (so
|
|
592
|
-
// module-level singletons stay unique), while changed content replaces the
|
|
593
|
-
// record so the next load re-evaluates the new code. A record from a newer
|
|
594
|
-
// build or one that is currently executing is never replaced.
|
|
558
|
+
// Reuse matching modules; replace changed ones unless newer or executing.
|
|
595
559
|
const existing = __z3dRegistry.get(id);
|
|
596
560
|
if (existing && (existing.version === version || existing.state === 1 || existing.serial > serial)) {
|
|
597
561
|
if (serial > existing.serial) {
|
|
@@ -702,8 +666,7 @@ async function __z3dLoad(spec, parentId = '') {
|
|
|
702
666
|
} else if (baseSpec.startsWith('/')) {
|
|
703
667
|
return `${baseSpec.replace(/^\/+/, '/')}${suffix}`;
|
|
704
668
|
} else if (getApp().editorMode !== 'none') {
|
|
705
|
-
const libRoot = '/';
|
|
706
|
-
// naked module, checking if it is a installed module in editor mode
|
|
669
|
+
const libRoot = '/';
|
|
707
670
|
let depsLockPath = this._vfs.normalizePath(this._vfs.join(libRoot, 'libs/deps.lock.json'));
|
|
708
671
|
let depsExists = await this._vfs.exists(depsLockPath);
|
|
709
672
|
if (depsExists) {
|
|
@@ -1 +1 @@
|
|
|
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\n/**\r\n * Realm-global storage for shared script module registries, keyed by\r\n * registry namespace. Bundles built by the same `ScriptRegistry` share one\r\n * module registry so a module evaluates once and its exports (including\r\n * module-level singletons) are identical across entry bundles.\r\n * @internal\r\n */\r\nconst SCRIPT_MODULES_GLOBAL_KEY = '__z3dScriptModules';\r\n\r\nlet scriptRegistryNamespaceCounter = 0;\r\n\r\nfunction nextScriptRegistryNamespace() {\r\n return `z3d-scripts:${++scriptRegistryNamespaceCounter}`;\r\n}\r\n\r\n/**\r\n * Monotonic serial stamped into each built bundle. The shared runtime uses it\r\n * to ignore registrations coming from bundles older than the one that already\r\n * registered a module, so late imports of stale bundles cannot downgrade a\r\n * module record.\r\n * @internal\r\n */\r\nlet scriptBuildSerialCounter = 0;\r\n\r\n/**\r\n * FNV-1a hash of module code, used to version shared module records.\r\n * Rebuilding an unchanged module keeps its already-evaluated instance;\r\n * changed content replaces the record so the next load re-evaluates.\r\n * @internal\r\n */\r\nfunction hashModuleCode(text: string) {\r\n let h = 0x811c9dc5;\r\n for (let i = 0; i < text.length; i++) {\r\n h ^= text.charCodeAt(i);\r\n h = Math.imul(h, 0x01000193);\r\n }\r\n return (h >>> 0).toString(36);\r\n}\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 version: 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 * - At runtime, all bundles built by the same registry share one realm-global\r\n * module registry (keyed by a per-registry namespace): a local module is\r\n * evaluated once no matter how many entry bundles inline it, so module-level\r\n * singletons are identical across entries. Module records are versioned by a\r\n * content hash — rebuilding an unchanged module reuses its evaluated\r\n * instance, while changed content replaces the record so the next load\r\n * re-evaluates the new code.\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 private _namespace: 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 this._namespace = nextScriptRegistryNamespace();\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 // Rotate the shared module registry namespace: modules from the old VFS\r\n // must not be reused as instances for same-named modules of the new VFS.\r\n const root = (globalThis as Record<string, unknown>)[SCRIPT_MODULES_GLOBAL_KEY] as\r\n | Map<string, unknown>\r\n | undefined;\r\n root?.delete(this._namespace);\r\n this._namespace = nextScriptRegistryNamespace();\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 // Replace content hashes with Merkle-style effective versions so that a\r\n // module whose (transitive) dependencies changed is re-registered and\r\n // re-evaluated even when its own source is unchanged.\r\n this.applyEffectiveVersions(modules);\r\n\r\n const serial = ++scriptBuildSerialCounter;\r\n const chunks = [this.getSystemBundleRuntime()];\r\n for (const module of modules.values()) {\r\n chunks.push(\r\n `__z3dRegister(${JSON.stringify(module.id)}, ${JSON.stringify(\r\n module.version\r\n )}, ${serial}, () => {\\n${module.systemCode}\\n});`\r\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 module.version = hashModuleCode(module.systemCode);\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 /**\r\n * Rewrites each collected module's version to a Merkle-style hash combining\r\n * its own content hash with the effective versions of its local\r\n * dependencies. Cycles fall back to the plain content hash, which is\r\n * deterministic on both sides of the cycle.\r\n */\r\n private applyEffectiveVersions(modules: Map<string, ScriptModuleInfo>) {\r\n const effective = new Map<string, string>();\r\n const visiting = new Set<string>();\r\n const visit = (id: string): string => {\r\n const cached = effective.get(id);\r\n if (cached !== undefined) {\r\n return cached;\r\n }\r\n const module = modules.get(id);\r\n if (!module) {\r\n return '';\r\n }\r\n if (visiting.has(id)) {\r\n return module.version;\r\n }\r\n visiting.add(id);\r\n let acc = module.version;\r\n for (const dep of module.deps) {\r\n if (modules.has(dep)) {\r\n acc = hashModuleCode(`${acc}:${dep}:${visit(dep)}`);\r\n }\r\n }\r\n visiting.delete(id);\r\n effective.set(id, acc);\r\n return acc;\r\n };\r\n for (const module of modules.values()) {\r\n module.version = visit(module.id);\r\n }\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 version: ''\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 = (() => {\r\n const root = (globalThis.${SCRIPT_MODULES_GLOBAL_KEY} ??= new Map());\r\n const ns = ${JSON.stringify(this._namespace)};\r\n let registry = root.get(ns);\r\n if (!registry) {\r\n registry = new Map();\r\n root.set(ns, registry);\r\n }\r\n return registry;\r\n})();\r\nlet __z3dCurrentId = '';\r\nlet __z3dCurrentVersion = '';\r\nlet __z3dCurrentSerial = 0;\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 version: __z3dCurrentVersion,\r\n serial: __z3dCurrentSerial,\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, version, serial, factory) {\r\n // The module registry is shared across bundles: a module already registered\r\n // by another bundle with the same effective version is reused (so\r\n // module-level singletons stay unique), while changed content replaces the\r\n // record so the next load re-evaluates the new code. A record from a newer\r\n // build or one that is currently executing is never replaced.\r\n const existing = __z3dRegistry.get(id);\r\n if (existing && (existing.version === version || existing.state === 1 || existing.serial > serial)) {\r\n if (serial > existing.serial) {\r\n existing.serial = serial;\r\n }\r\n return;\r\n }\r\n const prevId = __z3dCurrentId;\r\n const prevVersion = __z3dCurrentVersion;\r\n const prevSerial = __z3dCurrentSerial;\r\n __z3dCurrentId = id;\r\n __z3dCurrentVersion = version;\r\n __z3dCurrentSerial = serial;\r\n try {\r\n factory();\r\n } finally {\r\n __z3dCurrentId = prevId;\r\n __z3dCurrentVersion = prevVersion;\r\n __z3dCurrentSerial = prevSerial;\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","SCRIPT_MODULES_GLOBAL_KEY","scriptRegistryNamespaceCounter","nextScriptRegistryNamespace","scriptBuildSerialCounter","hashModuleCode","text","h","i","length","charCodeAt","imul","toString","ScriptRegistry","_vfs","_scriptsRoot","_built","_building","_builtDeps","_namespace","vfs","scriptsRoot","Map","VFS","clear","root","globalThis","delete","invalidate","moduleId","normalized","variants","Set","endsWith","add","key","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","applyEffectiveVersions","serial","chunks","getSystemBundleRuntime","module","values","push","JSON","stringify","version","systemCode","join","keys","source","esmCode","transpileToESModule","rewritten","rewriteImportsToLogicalIds","transpileToSystemModule","dep","effective","visiting","visit","acc","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,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,IAAKO,CAAAA,OAAO,CAAC,GAAA,CAAA;IAC/B,MAAMC,UAAAA,GAAaR,IAAKO,CAAAA,OAAO,CAAC,GAAA,CAAA;AAChC,IAAA,MAAME,QACJD,GAAAA,UAAAA,IAAc,CAAKF,IAAAA,SAAAA,IAAa,CAC5BI,GAAAA,IAAAA,CAAKC,GAAG,CAACH,UAAYF,EAAAA,SAAAA,CAAAA,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,CAAClC,IAAI,CAAC8B,IAAI,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;YAAMlD,IAAMmD,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\n/**\r\n * Realm-global key for per-registry module stores. Modules evaluate once per\r\n * registry, preserving shared exports and singletons across entry bundles.\r\n * @internal\r\n */\r\nconst SCRIPT_MODULES_GLOBAL_KEY = '__z3dScriptModules';\r\n\r\nlet scriptRegistryNamespaceCounter = 0;\r\n\r\nfunction nextScriptRegistryNamespace() {\r\n return `z3d-scripts:${++scriptRegistryNamespaceCounter}`;\r\n}\r\n\r\n/**\r\n * Build serial preventing stale bundles from replacing newer module records.\r\n * @internal\r\n */\r\nlet scriptBuildSerialCounter = 0;\r\n\r\n/**\r\n * FNV-1a content version for shared module records.\r\n * @internal\r\n */\r\nfunction hashModuleCode(text: string) {\r\n let h = 0x811c9dc5;\r\n for (let i = 0; i < text.length; i++) {\r\n h ^= text.charCodeAt(i);\r\n h = Math.imul(h, 0x01000193);\r\n }\r\n return (h >>> 0).toString(36);\r\n}\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 version: string;\r\n};\r\n\r\n/**\r\n * Resolves and builds VFS scripts. Editor mode transpiles TypeScript and bundles\r\n * local graphs into data URLs; runtime mode returns script URLs directly. Bundles\r\n * from one registry share module instances, while content-derived versions\r\n * preserve unchanged instances and invalidate changed dependency graphs.\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>;\r\n private _building: Map<string, Promise<string>>;\r\n private _builtDeps: Map<string, Set<string>>;\r\n private _namespace: 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 this._namespace = nextScriptRegistryNamespace();\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 // A new VFS must not reuse same-named module instances from the old VFS.\r\n const root = (globalThis as Record<string, unknown>)[SCRIPT_MODULES_GLOBAL_KEY] as\r\n | Map<string, unknown>\r\n | undefined;\r\n root?.delete(this._namespace);\r\n this._namespace = nextScriptRegistryNamespace();\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 // Include transitive dependencies in versions so their changes trigger re-evaluation.\r\n this.applyEffectiveVersions(modules);\r\n\r\n const serial = ++scriptBuildSerialCounter;\r\n const chunks = [this.getSystemBundleRuntime()];\r\n for (const module of modules.values()) {\r\n chunks.push(\r\n `__z3dRegister(${JSON.stringify(module.id)}, ${JSON.stringify(\r\n module.version\r\n )}, ${serial}, () => {\\n${module.systemCode}\\n});`\r\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 module.version = hashModuleCode(module.systemCode);\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 /**\r\n * Rewrites each collected module's version to a Merkle-style hash combining\r\n * its own content hash with the effective versions of its local\r\n * dependencies. Cycles fall back to the plain content hash, which is\r\n * deterministic on both sides of the cycle.\r\n */\r\n private applyEffectiveVersions(modules: Map<string, ScriptModuleInfo>) {\r\n const effective = new Map<string, string>();\r\n const visiting = new Set<string>();\r\n const visit = (id: string): string => {\r\n const cached = effective.get(id);\r\n if (cached !== undefined) {\r\n return cached;\r\n }\r\n const module = modules.get(id);\r\n if (!module) {\r\n return '';\r\n }\r\n if (visiting.has(id)) {\r\n return module.version;\r\n }\r\n visiting.add(id);\r\n let acc = module.version;\r\n for (const dep of module.deps) {\r\n if (modules.has(dep)) {\r\n acc = hashModuleCode(`${acc}:${dep}:${visit(dep)}`);\r\n }\r\n }\r\n visiting.delete(id);\r\n effective.set(id, acc);\r\n return acc;\r\n };\r\n for (const module of modules.values()) {\r\n module.version = visit(module.id);\r\n }\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 version: ''\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 // Preserve syntax supported by the runtime.\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 // es-module-lexer reports import.meta spans, which must not be rewritten.\r\n if (im.d === -2) {\r\n continue;\r\n }\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 if (im.e <= im.s) {\r\n continue;\r\n }\r\n out += code.slice(last, im.s);\r\n\r\n const spec = code.slice(im.s, im.e);\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;\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 = (() => {\r\n const root = (globalThis.${SCRIPT_MODULES_GLOBAL_KEY} ??= new Map());\r\n const ns = ${JSON.stringify(this._namespace)};\r\n let registry = root.get(ns);\r\n if (!registry) {\r\n registry = new Map();\r\n root.set(ns, registry);\r\n }\r\n return registry;\r\n})();\r\nlet __z3dCurrentId = '';\r\nlet __z3dCurrentVersion = '';\r\nlet __z3dCurrentSerial = 0;\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 version: __z3dCurrentVersion,\r\n serial: __z3dCurrentSerial,\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, version, serial, factory) {\r\n // Reuse matching modules; replace changed ones unless newer or executing.\r\n const existing = __z3dRegistry.get(id);\r\n if (existing && (existing.version === version || existing.state === 1 || existing.serial > serial)) {\r\n if (serial > existing.serial) {\r\n existing.serial = serial;\r\n }\r\n return;\r\n }\r\n const prevId = __z3dCurrentId;\r\n const prevVersion = __z3dCurrentVersion;\r\n const prevSerial = __z3dCurrentSerial;\r\n __z3dCurrentId = id;\r\n __z3dCurrentVersion = version;\r\n __z3dCurrentSerial = serial;\r\n try {\r\n factory();\r\n } finally {\r\n __z3dCurrentId = prevId;\r\n __z3dCurrentVersion = prevVersion;\r\n __z3dCurrentSerial = prevSerial;\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 = '/';\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","SCRIPT_MODULES_GLOBAL_KEY","scriptRegistryNamespaceCounter","nextScriptRegistryNamespace","scriptBuildSerialCounter","hashModuleCode","text","h","i","length","charCodeAt","imul","toString","ScriptRegistry","_vfs","_scriptsRoot","_built","_building","_builtDeps","_namespace","vfs","scriptsRoot","Map","VFS","clear","root","globalThis","delete","invalidate","moduleId","normalized","variants","Set","endsWith","add","key","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","applyEffectiveVersions","serial","chunks","getSystemBundleRuntime","module","values","push","JSON","stringify","version","systemCode","join","keys","source","esmCode","transpileToESModule","rewritten","rewriteImportsToLogicalIds","transpileToSystemModule","dep","effective","visiting","visit","acc","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,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,IAAKO,CAAAA,OAAO,CAAC,GAAA,CAAA;IAC/B,MAAMC,UAAAA,GAAaR,IAAKO,CAAAA,OAAO,CAAC,GAAA,CAAA;AAChC,IAAA,MAAME,QACJD,GAAAA,UAA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;AACV,oBAAA,MAAMK,QAAQ,MAAM,IAAI,CAAClC,IAAI,CAAC8B,IAAI,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;YAAMlD,IAAMmD,EAAAA;SAAgB,GAAA,IAAA;AAC9C;AACF;;;;"}
|
|
@@ -34,8 +34,10 @@ import '../render/rendergraph/forward_plus_builder.js';
|
|
|
34
34
|
import '../render/lightpass.js';
|
|
35
35
|
import '../render/sky.js';
|
|
36
36
|
import '../render/clipmap.js';
|
|
37
|
+
import '../render/envlight.js';
|
|
37
38
|
import '../render/dualdepthpeeling_oit.js';
|
|
38
39
|
import '../shaders/atmosphere.js';
|
|
40
|
+
import '../render/rendergraph/scene_render_context.js';
|
|
39
41
|
import { FontAsset } from '../text/font/font_asset.js';
|
|
40
42
|
|
|
41
43
|
/**
|