@zephyr3d/scene 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (722) hide show
  1. package/dist/animation/animation.js +149 -27
  2. package/dist/animation/animation.js.map +1 -1
  3. package/dist/animation/animationset.js +173 -73
  4. package/dist/animation/animationset.js.map +1 -1
  5. package/dist/animation/animationtrack.js +65 -10
  6. package/dist/animation/animationtrack.js.map +1 -1
  7. package/dist/animation/eulerrotationtrack.js +41 -20
  8. package/dist/animation/eulerrotationtrack.js.map +1 -1
  9. package/dist/animation/morphtarget.js +14 -38
  10. package/dist/animation/morphtarget.js.map +1 -1
  11. package/dist/animation/morphtrack.js +59 -22
  12. package/dist/animation/morphtrack.js.map +1 -1
  13. package/dist/animation/proptrack.js +190 -0
  14. package/dist/animation/proptrack.js.map +1 -0
  15. package/dist/animation/rotationtrack.js +29 -11
  16. package/dist/animation/rotationtrack.js.map +1 -1
  17. package/dist/animation/scaletrack.js +29 -11
  18. package/dist/animation/scaletrack.js.map +1 -1
  19. package/dist/animation/skeleton.js +241 -78
  20. package/dist/animation/skeleton.js.map +1 -1
  21. package/dist/animation/translationtrack.js +30 -11
  22. package/dist/animation/translationtrack.js.map +1 -1
  23. package/dist/app/api.js +43 -0
  24. package/dist/app/api.js.map +1 -0
  25. package/dist/app/app.js +153 -0
  26. package/dist/app/app.js.map +1 -0
  27. package/dist/app/engine.js +312 -0
  28. package/dist/app/engine.js.map +1 -0
  29. package/dist/app/inputmgr.js +351 -0
  30. package/dist/app/inputmgr.js.map +1 -0
  31. package/dist/app/runtimescript.js +62 -0
  32. package/dist/app/runtimescript.js.map +1 -0
  33. package/dist/app/scriptingsystem.js +220 -0
  34. package/dist/app/scriptingsystem.js.map +1 -0
  35. package/dist/app/scriptregistry.js +432 -0
  36. package/dist/app/scriptregistry.js.map +1 -0
  37. package/dist/asset/assetmanager.js +772 -291
  38. package/dist/asset/assetmanager.js.map +1 -1
  39. package/dist/asset/builtin.js +7 -43
  40. package/dist/asset/builtin.js.map +1 -1
  41. package/dist/asset/loaders/dds/dds.js +17 -93
  42. package/dist/asset/loaders/dds/dds.js.map +1 -1
  43. package/dist/asset/loaders/dds/dds_loader.js +8 -18
  44. package/dist/asset/loaders/dds/dds_loader.js.map +1 -1
  45. package/dist/asset/loaders/gltf/gltf_loader.js +36 -42
  46. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  47. package/dist/asset/loaders/gltf/helpers.js +27 -14
  48. package/dist/asset/loaders/gltf/helpers.js.map +1 -1
  49. package/dist/asset/loaders/hdr/hdr.js +17 -12
  50. package/dist/asset/loaders/hdr/hdr.js.map +1 -1
  51. package/dist/asset/loaders/image/tga_Loader.js +13 -16
  52. package/dist/asset/loaders/image/tga_Loader.js.map +1 -1
  53. package/dist/asset/loaders/image/webimage_loader.js +51 -50
  54. package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
  55. package/dist/asset/loaders/loader.js.map +1 -1
  56. package/dist/asset/model.js +158 -4
  57. package/dist/asset/model.js.map +1 -1
  58. package/dist/blitter/bilateralblur.js +0 -1
  59. package/dist/blitter/bilateralblur.js.map +1 -1
  60. package/dist/blitter/blitter.js +22 -23
  61. package/dist/blitter/blitter.js.map +1 -1
  62. package/dist/blitter/box.js.map +1 -1
  63. package/dist/blitter/copy.js.map +1 -1
  64. package/dist/blitter/gaussianblur.js +23 -23
  65. package/dist/blitter/gaussianblur.js.map +1 -1
  66. package/dist/camera/base.js +141 -34
  67. package/dist/camera/base.js.map +1 -1
  68. package/dist/camera/camera.js +653 -149
  69. package/dist/camera/camera.js.map +1 -1
  70. package/dist/camera/fps.js +2 -10
  71. package/dist/camera/fps.js.map +1 -1
  72. package/dist/camera/orbit.js +132 -59
  73. package/dist/camera/orbit.js.map +1 -1
  74. package/dist/camera/orthocamera.js +37 -12
  75. package/dist/camera/orthocamera.js.map +1 -1
  76. package/dist/camera/perspectivecamera.js +37 -20
  77. package/dist/camera/perspectivecamera.js.map +1 -1
  78. package/dist/index.d.ts +18268 -6982
  79. package/dist/index.js +49 -16
  80. package/dist/index.js.map +1 -1
  81. package/dist/material/blinn.js +5 -0
  82. package/dist/material/blinn.js.map +1 -1
  83. package/dist/material/grassmaterial.js +6 -1
  84. package/dist/material/grassmaterial.js.map +1 -1
  85. package/dist/material/lambert.js +6 -1
  86. package/dist/material/lambert.js.map +1 -1
  87. package/dist/material/material.js +346 -73
  88. package/dist/material/material.js.map +1 -1
  89. package/dist/material/meshmaterial.js +498 -156
  90. package/dist/material/meshmaterial.js.map +1 -1
  91. package/dist/material/mixins/albedocolor.js +5 -1
  92. package/dist/material/mixins/albedocolor.js.map +1 -1
  93. package/dist/material/mixins/foliage.js +3 -3
  94. package/dist/material/mixins/foliage.js.map +1 -1
  95. package/dist/material/mixins/lightmodel/blinnphong.js +18 -5
  96. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  97. package/dist/material/mixins/lightmodel/lambert.js +6 -6
  98. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  99. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +235 -0
  100. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -0
  101. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +52 -15
  102. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  103. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +27 -9
  104. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  105. package/dist/material/mixins/lit.js +16 -4
  106. package/dist/material/mixins/lit.js.map +1 -1
  107. package/dist/material/mixins/pbr/brdf.js +134 -0
  108. package/dist/material/mixins/pbr/brdf.js.map +1 -0
  109. package/dist/material/mixins/pbr/common.js +68 -85
  110. package/dist/material/mixins/pbr/common.js.map +1 -1
  111. package/dist/material/mixins/texture.js +98 -83
  112. package/dist/material/mixins/texture.js.map +1 -1
  113. package/dist/material/mixins/vertexcolor.js +6 -2
  114. package/dist/material/mixins/vertexcolor.js.map +1 -1
  115. package/dist/material/particle.js +272 -0
  116. package/dist/material/particle.js.map +1 -0
  117. package/dist/material/pbrblueprint.js +186 -0
  118. package/dist/material/pbrblueprint.js.map +1 -0
  119. package/dist/material/pbrmr.js +10 -0
  120. package/dist/material/pbrmr.js.map +1 -1
  121. package/dist/material/pbrsg.js +10 -0
  122. package/dist/material/pbrsg.js.map +1 -1
  123. package/dist/material/shader/helper.js +521 -287
  124. package/dist/material/shader/helper.js.map +1 -1
  125. package/dist/material/terrain-cm.js +607 -0
  126. package/dist/material/terrain-cm.js.map +1 -0
  127. package/dist/material/terrainmaterial.js +59 -54
  128. package/dist/material/terrainmaterial.js.map +1 -1
  129. package/dist/material/unlit.js +5 -0
  130. package/dist/material/unlit.js.map +1 -1
  131. package/dist/material/water.js +415 -0
  132. package/dist/material/water.js.map +1 -0
  133. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +38 -0
  134. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +1 -0
  135. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +10 -0
  136. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +1 -0
  137. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +127 -0
  138. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +1 -0
  139. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +263 -0
  140. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +1 -0
  141. package/dist/node_modules/es-module-lexer/dist/lexer.js +5 -0
  142. package/dist/node_modules/es-module-lexer/dist/lexer.js.map +1 -0
  143. package/dist/posteffect/bloom.js +39 -54
  144. package/dist/posteffect/bloom.js.map +1 -1
  145. package/dist/posteffect/compositor.js +95 -128
  146. package/dist/posteffect/compositor.js.map +1 -1
  147. package/dist/posteffect/fxaa.js +10 -18
  148. package/dist/posteffect/fxaa.js.map +1 -1
  149. package/dist/posteffect/grayscale.js +9 -17
  150. package/dist/posteffect/grayscale.js.map +1 -1
  151. package/dist/posteffect/motionblur.js +105 -0
  152. package/dist/posteffect/motionblur.js.map +1 -0
  153. package/dist/posteffect/posteffect.js +66 -35
  154. package/dist/posteffect/posteffect.js.map +1 -1
  155. package/dist/posteffect/sao.js +13 -21
  156. package/dist/posteffect/sao.js.map +1 -1
  157. package/dist/posteffect/ssr.js +60 -100
  158. package/dist/posteffect/ssr.js.map +1 -1
  159. package/dist/posteffect/taa.js +175 -0
  160. package/dist/posteffect/taa.js.map +1 -0
  161. package/dist/posteffect/tonemap.js +12 -20
  162. package/dist/posteffect/tonemap.js.map +1 -1
  163. package/dist/render/abuffer_oit.js +30 -19
  164. package/dist/render/abuffer_oit.js.map +1 -1
  165. package/dist/render/clipmap.js +429 -101
  166. package/dist/render/clipmap.js.map +1 -1
  167. package/dist/render/cluster_light.js +7 -5
  168. package/dist/render/cluster_light.js.map +1 -1
  169. package/dist/render/cull_visitor.js +43 -3
  170. package/dist/render/cull_visitor.js.map +1 -1
  171. package/dist/render/depthpass.js +14 -5
  172. package/dist/render/depthpass.js.map +1 -1
  173. package/dist/render/drawable_mixin.js +113 -40
  174. package/dist/render/drawable_mixin.js.map +1 -1
  175. package/dist/render/envlight.js +86 -141
  176. package/dist/render/envlight.js.map +1 -1
  177. package/dist/render/fbm_wavegenerator.js +234 -0
  178. package/dist/render/fbm_wavegenerator.js.map +1 -0
  179. package/dist/render/fft_wavegenerator.js +64 -50
  180. package/dist/render/fft_wavegenerator.js.map +1 -1
  181. package/dist/render/fullscreenquad.js +2 -2
  182. package/dist/render/fullscreenquad.js.map +1 -1
  183. package/dist/render/gerstner_wavegenerator.js +98 -48
  184. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  185. package/dist/render/globalbindgroup_allocator.js +4 -2
  186. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  187. package/dist/render/hzb.js +6 -3
  188. package/dist/render/hzb.js.map +1 -1
  189. package/dist/render/lightpass.js +19 -18
  190. package/dist/render/lightpass.js.map +1 -1
  191. package/dist/render/objectcolorpass.js +4 -4
  192. package/dist/render/objectcolorpass.js.map +1 -1
  193. package/dist/render/primitive.js +213 -104
  194. package/dist/render/primitive.js.map +1 -1
  195. package/dist/render/render_queue.js +40 -20
  196. package/dist/render/render_queue.js.map +1 -1
  197. package/dist/render/renderbundle_wrapper.js +65 -15
  198. package/dist/render/renderbundle_wrapper.js.map +1 -1
  199. package/dist/render/renderer.js +326 -185
  200. package/dist/render/renderer.js.map +1 -1
  201. package/dist/render/renderpass.js +20 -36
  202. package/dist/render/renderpass.js.map +1 -1
  203. package/dist/render/shadowmap_pass.js +3 -3
  204. package/dist/render/shadowmap_pass.js.map +1 -1
  205. package/dist/render/sky.js +864 -541
  206. package/dist/render/sky.js.map +1 -1
  207. package/dist/render/weightedblended_oit.js +13 -15
  208. package/dist/render/weightedblended_oit.js.map +1 -1
  209. package/dist/scene/batchgroup.js +18 -5
  210. package/dist/scene/batchgroup.js.map +1 -1
  211. package/dist/scene/environment.js +78 -48
  212. package/dist/scene/environment.js.map +1 -1
  213. package/dist/scene/graph_node.js +2 -3
  214. package/dist/scene/graph_node.js.map +1 -1
  215. package/dist/scene/light.js +28 -89
  216. package/dist/scene/light.js.map +1 -1
  217. package/dist/scene/mesh.js +218 -87
  218. package/dist/scene/mesh.js.map +1 -1
  219. package/dist/scene/octree.js +371 -162
  220. package/dist/scene/octree.js.map +1 -1
  221. package/dist/scene/particlesys.js +684 -0
  222. package/dist/scene/particlesys.js.map +1 -0
  223. package/dist/scene/raycast_visitor.js +34 -5
  224. package/dist/scene/raycast_visitor.js.map +1 -1
  225. package/dist/scene/scene.js +309 -85
  226. package/dist/scene/scene.js.map +1 -1
  227. package/dist/scene/scene_node.js +675 -102
  228. package/dist/scene/scene_node.js.map +1 -1
  229. package/dist/scene/terrain/grass.js +48 -49
  230. package/dist/scene/terrain/grass.js.map +1 -1
  231. package/dist/scene/terrain/heightfield.js +46 -44
  232. package/dist/scene/terrain/heightfield.js.map +1 -1
  233. package/dist/scene/terrain/patch.js +20 -29
  234. package/dist/scene/terrain/patch.js.map +1 -1
  235. package/dist/scene/terrain/quadtree.js +58 -27
  236. package/dist/scene/terrain/quadtree.js.map +1 -1
  237. package/dist/scene/terrain/terrain.js +31 -45
  238. package/dist/scene/terrain/terrain.js.map +1 -1
  239. package/dist/scene/terrain-cm/grass.js +603 -0
  240. package/dist/scene/terrain-cm/grass.js.map +1 -0
  241. package/dist/scene/terrain-cm/grassmaterial.js +160 -0
  242. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -0
  243. package/dist/scene/terrain-cm/terrain-cm.js +533 -0
  244. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -0
  245. package/dist/scene/water.js +378 -0
  246. package/dist/scene/water.js.map +1 -0
  247. package/dist/shaders/atmosphere.js +957 -0
  248. package/dist/shaders/atmosphere.js.map +1 -0
  249. package/dist/shaders/fog.js +116 -0
  250. package/dist/shaders/fog.js.map +1 -0
  251. package/dist/shaders/misc.js.map +1 -1
  252. package/dist/shaders/noise.js +217 -8
  253. package/dist/shaders/noise.js.map +1 -1
  254. package/dist/shaders/pbr.js.map +1 -1
  255. package/dist/shaders/shadow.js +8 -8
  256. package/dist/shaders/shadow.js.map +1 -1
  257. package/dist/shaders/ssr.js +87 -39
  258. package/dist/shaders/ssr.js.map +1 -1
  259. package/dist/shaders/temporal.js +216 -0
  260. package/dist/shaders/temporal.js.map +1 -0
  261. package/dist/shaders/water.js +42 -20
  262. package/dist/shaders/water.js.map +1 -1
  263. package/dist/shadow/esm.js +31 -13
  264. package/dist/shadow/esm.js.map +1 -1
  265. package/dist/shadow/pcf_opt.js +12 -13
  266. package/dist/shadow/pcf_opt.js.map +1 -1
  267. package/dist/shadow/pcf_pd.js +12 -13
  268. package/dist/shadow/pcf_pd.js.map +1 -1
  269. package/dist/shadow/shader.js +38 -0
  270. package/dist/shadow/shader.js.map +1 -0
  271. package/dist/shadow/shadow_impl.js.map +1 -1
  272. package/dist/shadow/shadowmapper.js +67 -26
  273. package/dist/shadow/shadowmapper.js.map +1 -1
  274. package/dist/shadow/ssm.js +15 -16
  275. package/dist/shadow/ssm.js.map +1 -1
  276. package/dist/shadow/vsm.js +33 -16
  277. package/dist/shadow/vsm.js.map +1 -1
  278. package/dist/shapes/box.js +181 -83
  279. package/dist/shapes/box.js.map +1 -1
  280. package/dist/shapes/cylinder.js +101 -43
  281. package/dist/shapes/cylinder.js.map +1 -1
  282. package/dist/shapes/plane.js +70 -29
  283. package/dist/shapes/plane.js.map +1 -1
  284. package/dist/shapes/shape.js +120 -17
  285. package/dist/shapes/shape.js.map +1 -1
  286. package/dist/shapes/sphere.js +78 -44
  287. package/dist/shapes/sphere.js.map +1 -1
  288. package/dist/shapes/tetrahedron.js +256 -0
  289. package/dist/shapes/tetrahedron.js.map +1 -0
  290. package/dist/shapes/torus.js +76 -55
  291. package/dist/shapes/torus.js.map +1 -1
  292. package/dist/src/animation/animation.js +127 -0
  293. package/dist/src/animation/animation.js.map +1 -0
  294. package/dist/src/animation/animationset.js +255 -0
  295. package/dist/src/animation/animationset.js.map +1 -0
  296. package/dist/src/animation/animationtrack.js +34 -0
  297. package/dist/src/animation/animationtrack.js.map +1 -0
  298. package/dist/src/animation/eulerrotationtrack.js +52 -0
  299. package/dist/src/animation/eulerrotationtrack.js.map +1 -0
  300. package/dist/src/animation/morphtarget.js +93 -0
  301. package/dist/src/animation/morphtarget.js.map +1 -0
  302. package/dist/src/animation/morphtrack.js +70 -0
  303. package/dist/src/animation/morphtrack.js.map +1 -0
  304. package/dist/src/animation/proptrack.js +161 -0
  305. package/dist/src/animation/proptrack.js.map +1 -0
  306. package/dist/src/animation/rotationtrack.js +51 -0
  307. package/dist/src/animation/rotationtrack.js.map +1 -0
  308. package/dist/src/animation/scaletrack.js +50 -0
  309. package/dist/src/animation/scaletrack.js.map +1 -0
  310. package/dist/src/animation/skeleton.js +204 -0
  311. package/dist/src/animation/skeleton.js.map +1 -0
  312. package/dist/src/animation/translationtrack.js +50 -0
  313. package/dist/src/animation/translationtrack.js.map +1 -0
  314. package/dist/{app.js → src/app/app.js} +18 -40
  315. package/dist/src/app/app.js.map +1 -0
  316. package/dist/{input → src/app}/inputmgr.js +41 -16
  317. package/dist/src/app/inputmgr.js.map +1 -0
  318. package/dist/src/asset/assetmanager.js +404 -0
  319. package/dist/src/asset/assetmanager.js.map +1 -0
  320. package/dist/src/asset/builtin.js +337 -0
  321. package/dist/src/asset/builtin.js.map +1 -0
  322. package/dist/src/asset/loaders/dds/dds.js +470 -0
  323. package/dist/src/asset/loaders/dds/dds.js.map +1 -0
  324. package/dist/src/asset/loaders/dds/dds_loader.js +28 -0
  325. package/dist/src/asset/loaders/dds/dds_loader.js.map +1 -0
  326. package/dist/src/asset/loaders/gltf/gltf_loader.js +1265 -0
  327. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +1 -0
  328. package/dist/src/asset/loaders/gltf/helpers.js +327 -0
  329. package/dist/src/asset/loaders/gltf/helpers.js.map +1 -0
  330. package/dist/src/asset/loaders/hdr/hdr.js +180 -0
  331. package/dist/src/asset/loaders/hdr/hdr.js.map +1 -0
  332. package/dist/src/asset/loaders/image/tga_Loader.js +116 -0
  333. package/dist/src/asset/loaders/image/tga_Loader.js.map +1 -0
  334. package/dist/src/asset/loaders/image/webimage_loader.js +63 -0
  335. package/dist/src/asset/loaders/image/webimage_loader.js.map +1 -0
  336. package/dist/src/asset/loaders/loader.js +45 -0
  337. package/dist/src/asset/loaders/loader.js.map +1 -0
  338. package/dist/src/asset/model.js +414 -0
  339. package/dist/src/asset/model.js.map +1 -0
  340. package/dist/{blitter/depthlimitedgaussion.js → src/blitter/bilateralblur.js} +1 -2
  341. package/dist/src/blitter/bilateralblur.js.map +1 -0
  342. package/dist/src/blitter/blitter.js +390 -0
  343. package/dist/src/blitter/blitter.js.map +1 -0
  344. package/dist/src/blitter/box.js +118 -0
  345. package/dist/src/blitter/box.js.map +1 -0
  346. package/dist/src/blitter/copy.js +22 -0
  347. package/dist/src/blitter/copy.js.map +1 -0
  348. package/dist/src/blitter/gaussianblur.js +228 -0
  349. package/dist/src/blitter/gaussianblur.js.map +1 -0
  350. package/dist/src/camera/base.js +92 -0
  351. package/dist/src/camera/base.js.map +1 -0
  352. package/dist/src/camera/camera.js +1005 -0
  353. package/dist/src/camera/camera.js.map +1 -0
  354. package/dist/src/camera/fps.js +238 -0
  355. package/dist/src/camera/fps.js.map +1 -0
  356. package/dist/src/camera/orbit.js +245 -0
  357. package/dist/src/camera/orbit.js.map +1 -0
  358. package/dist/src/camera/orthocamera.js +167 -0
  359. package/dist/src/camera/orthocamera.js.map +1 -0
  360. package/dist/src/camera/perspectivecamera.js +141 -0
  361. package/dist/src/camera/perspectivecamera.js.map +1 -0
  362. package/dist/src/index.js +120 -0
  363. package/dist/src/index.js.map +1 -0
  364. package/dist/src/material/blinn.js +81 -0
  365. package/dist/src/material/blinn.js.map +1 -0
  366. package/dist/src/material/grassmaterial.js +113 -0
  367. package/dist/src/material/grassmaterial.js.map +1 -0
  368. package/dist/src/material/lambert.js +92 -0
  369. package/dist/src/material/lambert.js.map +1 -0
  370. package/dist/src/material/material.js +301 -0
  371. package/dist/src/material/material.js.map +1 -0
  372. package/dist/src/material/meshmaterial.js +704 -0
  373. package/dist/src/material/meshmaterial.js.map +1 -0
  374. package/dist/src/material/mixins/albedocolor.js +76 -0
  375. package/dist/src/material/mixins/albedocolor.js.map +1 -0
  376. package/dist/src/material/mixins/foliage.js +47 -0
  377. package/dist/src/material/mixins/foliage.js.map +1 -0
  378. package/dist/src/material/mixins/lightmodel/blinnphong.js +112 -0
  379. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +1 -0
  380. package/dist/src/material/mixins/lightmodel/lambert.js +58 -0
  381. package/dist/src/material/mixins/lightmodel/lambert.js.map +1 -0
  382. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +178 -0
  383. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
  384. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +139 -0
  385. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
  386. package/dist/src/material/mixins/lit.js +476 -0
  387. package/dist/src/material/mixins/lit.js.map +1 -0
  388. package/dist/src/material/mixins/pbr/common.js +918 -0
  389. package/dist/src/material/mixins/pbr/common.js.map +1 -0
  390. package/dist/src/material/mixins/texture.js +172 -0
  391. package/dist/src/material/mixins/texture.js.map +1 -0
  392. package/dist/src/material/mixins/vertexcolor.js +56 -0
  393. package/dist/src/material/mixins/vertexcolor.js.map +1 -0
  394. package/dist/src/material/particle.js +178 -0
  395. package/dist/src/material/particle.js.map +1 -0
  396. package/dist/src/material/pbrmr.js +97 -0
  397. package/dist/src/material/pbrmr.js.map +1 -0
  398. package/dist/src/material/pbrsg.js +97 -0
  399. package/dist/src/material/pbrsg.js.map +1 -0
  400. package/dist/src/material/shader/helper.js +1209 -0
  401. package/dist/src/material/shader/helper.js.map +1 -0
  402. package/dist/src/material/terrain-cm.js +606 -0
  403. package/dist/src/material/terrain-cm.js.map +1 -0
  404. package/dist/src/material/terrainmaterial.js +375 -0
  405. package/dist/src/material/terrainmaterial.js.map +1 -0
  406. package/dist/src/material/unlit.js +41 -0
  407. package/dist/src/material/unlit.js.map +1 -0
  408. package/dist/src/material/water.js +417 -0
  409. package/dist/src/material/water.js.map +1 -0
  410. package/dist/src/posteffect/bloom.js +361 -0
  411. package/dist/src/posteffect/bloom.js.map +1 -0
  412. package/dist/src/posteffect/compositor.js +226 -0
  413. package/dist/src/posteffect/compositor.js.map +1 -0
  414. package/dist/src/posteffect/fxaa.js +273 -0
  415. package/dist/src/posteffect/fxaa.js.map +1 -0
  416. package/dist/src/posteffect/grayscale.js +69 -0
  417. package/dist/src/posteffect/grayscale.js.map +1 -0
  418. package/dist/src/posteffect/motionblur.js +96 -0
  419. package/dist/src/posteffect/motionblur.js.map +1 -0
  420. package/dist/src/posteffect/posteffect.js +126 -0
  421. package/dist/src/posteffect/posteffect.js.map +1 -0
  422. package/dist/src/posteffect/sao.js +324 -0
  423. package/dist/src/posteffect/sao.js.map +1 -0
  424. package/dist/src/posteffect/ssr.js +489 -0
  425. package/dist/src/posteffect/ssr.js.map +1 -0
  426. package/dist/src/posteffect/taa.js +172 -0
  427. package/dist/src/posteffect/taa.js.map +1 -0
  428. package/dist/src/posteffect/tonemap.js +94 -0
  429. package/dist/src/posteffect/tonemap.js.map +1 -0
  430. package/dist/src/render/abuffer_oit.js +361 -0
  431. package/dist/src/render/abuffer_oit.js.map +1 -0
  432. package/dist/src/render/clipmap.js +851 -0
  433. package/dist/src/render/clipmap.js.map +1 -0
  434. package/dist/src/render/cluster_light.js +333 -0
  435. package/dist/src/render/cluster_light.js.map +1 -0
  436. package/dist/src/render/cull_visitor.js +187 -0
  437. package/dist/src/render/cull_visitor.js.map +1 -0
  438. package/dist/src/render/depthpass.js +68 -0
  439. package/dist/src/render/depthpass.js.map +1 -0
  440. package/dist/src/render/drawable_mixin.js +227 -0
  441. package/dist/src/render/drawable_mixin.js.map +1 -0
  442. package/dist/src/render/envlight.js +463 -0
  443. package/dist/src/render/envlight.js.map +1 -0
  444. package/dist/src/render/fbm_wavegenerator.js +251 -0
  445. package/dist/src/render/fbm_wavegenerator.js.map +1 -0
  446. package/dist/src/render/fft_wavegenerator.js +1006 -0
  447. package/dist/src/render/fft_wavegenerator.js.map +1 -0
  448. package/dist/src/render/fullscreenquad.js +38 -0
  449. package/dist/src/render/fullscreenquad.js.map +1 -0
  450. package/dist/src/render/gerstner_wavegenerator.js +314 -0
  451. package/dist/src/render/gerstner_wavegenerator.js.map +1 -0
  452. package/dist/src/render/globalbindgroup_allocator.js +60 -0
  453. package/dist/src/render/globalbindgroup_allocator.js.map +1 -0
  454. package/dist/src/render/hzb.js +273 -0
  455. package/dist/src/render/hzb.js.map +1 -0
  456. package/dist/src/render/lightpass.js +172 -0
  457. package/dist/src/render/lightpass.js.map +1 -0
  458. package/dist/src/render/objectcolorpass.js +51 -0
  459. package/dist/src/render/objectcolorpass.js.map +1 -0
  460. package/dist/src/render/primitive.js +364 -0
  461. package/dist/src/render/primitive.js.map +1 -0
  462. package/dist/src/render/render_queue.js +467 -0
  463. package/dist/src/render/render_queue.js.map +1 -0
  464. package/dist/src/render/renderbundle_wrapper.js +152 -0
  465. package/dist/src/render/renderbundle_wrapper.js.map +1 -0
  466. package/dist/src/render/renderer.js +455 -0
  467. package/dist/src/render/renderer.js.map +1 -0
  468. package/dist/src/render/renderpass.js +200 -0
  469. package/dist/src/render/renderpass.js.map +1 -0
  470. package/dist/src/render/shadowmap_pass.js +56 -0
  471. package/dist/src/render/shadowmap_pass.js.map +1 -0
  472. package/dist/src/render/sky.js +1103 -0
  473. package/dist/src/render/sky.js.map +1 -0
  474. package/dist/src/render/weightedblended_oit.js +168 -0
  475. package/dist/src/render/weightedblended_oit.js.map +1 -0
  476. package/dist/src/scene/batchgroup.js +162 -0
  477. package/dist/src/scene/batchgroup.js.map +1 -0
  478. package/dist/src/scene/environment.js +209 -0
  479. package/dist/src/scene/environment.js.map +1 -0
  480. package/dist/src/scene/graph_node.js +72 -0
  481. package/dist/src/scene/graph_node.js.map +1 -0
  482. package/dist/src/scene/light.js +416 -0
  483. package/dist/src/scene/light.js.map +1 -0
  484. package/dist/src/scene/mesh.js +341 -0
  485. package/dist/src/scene/mesh.js.map +1 -0
  486. package/dist/src/scene/octree.js +649 -0
  487. package/dist/src/scene/octree.js.map +1 -0
  488. package/dist/src/scene/particlesys.js +738 -0
  489. package/dist/src/scene/particlesys.js.map +1 -0
  490. package/dist/src/scene/raycast_visitor.js +103 -0
  491. package/dist/src/scene/raycast_visitor.js.map +1 -0
  492. package/dist/src/scene/scene.js +284 -0
  493. package/dist/src/scene/scene.js.map +1 -0
  494. package/dist/src/scene/scene_node.js +732 -0
  495. package/dist/src/scene/scene_node.js.map +1 -0
  496. package/dist/src/scene/terrain/grass.js +278 -0
  497. package/dist/src/scene/terrain/grass.js.map +1 -0
  498. package/dist/src/scene/terrain/heightfield.js +475 -0
  499. package/dist/src/scene/terrain/heightfield.js.map +1 -0
  500. package/dist/src/scene/terrain/patch.js +530 -0
  501. package/dist/src/scene/terrain/patch.js.map +1 -0
  502. package/dist/src/scene/terrain/quadtree.js +461 -0
  503. package/dist/src/scene/terrain/quadtree.js.map +1 -0
  504. package/dist/src/scene/terrain/terrain.js +246 -0
  505. package/dist/src/scene/terrain/terrain.js.map +1 -0
  506. package/dist/src/scene/terrain-cm/grass.js +594 -0
  507. package/dist/src/scene/terrain-cm/grass.js.map +1 -0
  508. package/dist/src/scene/terrain-cm/grassmaterial.js +159 -0
  509. package/dist/src/scene/terrain-cm/grassmaterial.js.map +1 -0
  510. package/dist/src/scene/terrain-cm/terrain-cm.js +538 -0
  511. package/dist/src/scene/terrain-cm/terrain-cm.js.map +1 -0
  512. package/dist/src/scene/water.js +374 -0
  513. package/dist/src/scene/water.js.map +1 -0
  514. package/dist/src/shaders/atmosphere.js +957 -0
  515. package/dist/src/shaders/atmosphere.js.map +1 -0
  516. package/dist/src/shaders/fog.js +112 -0
  517. package/dist/src/shaders/fog.js.map +1 -0
  518. package/dist/src/shaders/misc.js +266 -0
  519. package/dist/src/shaders/misc.js.map +1 -0
  520. package/dist/src/shaders/noise.js +222 -0
  521. package/dist/src/shaders/noise.js.map +1 -0
  522. package/dist/src/shaders/pbr.js +51 -0
  523. package/dist/src/shaders/pbr.js.map +1 -0
  524. package/dist/src/shaders/shadow.js +636 -0
  525. package/dist/src/shaders/shadow.js.map +1 -0
  526. package/dist/src/shaders/ssr.js +490 -0
  527. package/dist/src/shaders/ssr.js.map +1 -0
  528. package/dist/src/shaders/temporal.js +215 -0
  529. package/dist/src/shaders/temporal.js.map +1 -0
  530. package/dist/src/shaders/water.js +756 -0
  531. package/dist/src/shaders/water.js.map +1 -0
  532. package/dist/src/shadow/esm.js +237 -0
  533. package/dist/src/shadow/esm.js.map +1 -0
  534. package/dist/src/shadow/pcf_opt.js +181 -0
  535. package/dist/src/shadow/pcf_opt.js.map +1 -0
  536. package/dist/src/shadow/pcf_pd.js +189 -0
  537. package/dist/src/shadow/pcf_pd.js.map +1 -0
  538. package/dist/src/shadow/shader.js +37 -0
  539. package/dist/src/shadow/shader.js.map +1 -0
  540. package/dist/src/shadow/shadow_impl.js +15 -0
  541. package/dist/src/shadow/shadow_impl.js.map +1 -0
  542. package/dist/src/shadow/shadowmapper.js +790 -0
  543. package/dist/src/shadow/shadowmapper.js.map +1 -0
  544. package/dist/src/shadow/ssm.js +159 -0
  545. package/dist/src/shadow/ssm.js.map +1 -0
  546. package/dist/src/shadow/vsm.js +297 -0
  547. package/dist/src/shadow/vsm.js.map +1 -0
  548. package/dist/src/shapes/box.js +386 -0
  549. package/dist/src/shapes/box.js.map +1 -0
  550. package/dist/src/shapes/cylinder.js +125 -0
  551. package/dist/src/shapes/cylinder.js.map +1 -0
  552. package/dist/src/shapes/plane.js +88 -0
  553. package/dist/src/shapes/plane.js.map +1 -0
  554. package/dist/src/shapes/shape.js +87 -0
  555. package/dist/src/shapes/shape.js.map +1 -0
  556. package/dist/src/shapes/sphere.js +114 -0
  557. package/dist/src/shapes/sphere.js.map +1 -0
  558. package/dist/src/shapes/tetrahedron.js +188 -0
  559. package/dist/src/shapes/tetrahedron.js.map +1 -0
  560. package/dist/src/shapes/torus.js +111 -0
  561. package/dist/src/shapes/torus.js.map +1 -0
  562. package/dist/src/utility/aabbtree.js +400 -0
  563. package/dist/src/utility/aabbtree.js.map +1 -0
  564. package/dist/src/utility/bounding_volume.js +29 -0
  565. package/dist/src/utility/bounding_volume.js.map +1 -0
  566. package/dist/src/utility/debug.js +28 -0
  567. package/dist/src/utility/debug.js.map +1 -0
  568. package/dist/src/utility/draco/decoder.js +116 -0
  569. package/dist/src/utility/draco/decoder.js.map +1 -0
  570. package/dist/src/utility/misc.js +105 -0
  571. package/dist/src/utility/misc.js.map +1 -0
  572. package/dist/src/utility/panorama.js +163 -0
  573. package/dist/src/utility/panorama.js.map +1 -0
  574. package/dist/src/utility/pmrem.js +354 -0
  575. package/dist/src/utility/pmrem.js.map +1 -0
  576. package/dist/src/utility/rendermipmap.js +115 -0
  577. package/dist/src/utility/rendermipmap.js.map +1 -0
  578. package/dist/src/utility/serialization/json.js +402 -0
  579. package/dist/src/utility/serialization/json.js.map +1 -0
  580. package/dist/src/utility/serialization/manager.js +623 -0
  581. package/dist/src/utility/serialization/manager.js.map +1 -0
  582. package/dist/src/utility/serialization/scene/animation.js +248 -0
  583. package/dist/src/utility/serialization/scene/animation.js.map +1 -0
  584. package/dist/src/utility/serialization/scene/batch.js +59 -0
  585. package/dist/src/utility/serialization/scene/batch.js.map +1 -0
  586. package/dist/src/utility/serialization/scene/camera.js +790 -0
  587. package/dist/src/utility/serialization/scene/camera.js.map +1 -0
  588. package/dist/src/utility/serialization/scene/common.js +222 -0
  589. package/dist/src/utility/serialization/scene/common.js.map +1 -0
  590. package/dist/src/utility/serialization/scene/light.js +575 -0
  591. package/dist/src/utility/serialization/scene/light.js.map +1 -0
  592. package/dist/src/utility/serialization/scene/material.js +1111 -0
  593. package/dist/src/utility/serialization/scene/material.js.map +1 -0
  594. package/dist/src/utility/serialization/scene/mesh.js +148 -0
  595. package/dist/src/utility/serialization/scene/mesh.js.map +1 -0
  596. package/dist/src/utility/serialization/scene/misc.js +39 -0
  597. package/dist/src/utility/serialization/scene/misc.js.map +1 -0
  598. package/dist/src/utility/serialization/scene/node.js +451 -0
  599. package/dist/src/utility/serialization/scene/node.js.map +1 -0
  600. package/dist/src/utility/serialization/scene/particle.js +425 -0
  601. package/dist/src/utility/serialization/scene/particle.js.map +1 -0
  602. package/dist/src/utility/serialization/scene/primitive.js +692 -0
  603. package/dist/src/utility/serialization/scene/primitive.js.map +1 -0
  604. package/dist/src/utility/serialization/scene/scene.js +704 -0
  605. package/dist/src/utility/serialization/scene/scene.js.map +1 -0
  606. package/dist/src/utility/serialization/scene/terrain.js +488 -0
  607. package/dist/src/utility/serialization/scene/terrain.js.map +1 -0
  608. package/dist/src/utility/serialization/scene/water.js +465 -0
  609. package/dist/src/utility/serialization/scene/water.js.map +1 -0
  610. package/dist/src/utility/shprojector.js +297 -0
  611. package/dist/src/utility/shprojector.js.map +1 -0
  612. package/dist/{material/mixins → src/utility/textures}/ggxlut.js +1 -1
  613. package/dist/src/utility/textures/ggxlut.js.map +1 -0
  614. package/dist/src/utility/textures/gradientnoise.js +62 -0
  615. package/dist/src/utility/textures/gradientnoise.js.map +1 -0
  616. package/dist/src/utility/textures/randomnoise.js +41 -0
  617. package/dist/src/utility/textures/randomnoise.js.map +1 -0
  618. package/dist/src/values.js +162 -0
  619. package/dist/src/values.js.map +1 -0
  620. package/dist/utility/aabbtree.js +15 -5
  621. package/dist/utility/aabbtree.js.map +1 -1
  622. package/dist/utility/blueprint/common/constants.js +851 -0
  623. package/dist/utility/blueprint/common/constants.js.map +1 -0
  624. package/dist/utility/blueprint/common/math.js +2045 -0
  625. package/dist/utility/blueprint/common/math.js.map +1 -0
  626. package/dist/utility/blueprint/common.js +7 -0
  627. package/dist/utility/blueprint/common.js.map +1 -0
  628. package/dist/utility/blueprint/material/common.js +7 -0
  629. package/dist/utility/blueprint/material/common.js.map +1 -0
  630. package/dist/utility/blueprint/material/func.js +521 -0
  631. package/dist/utility/blueprint/material/func.js.map +1 -0
  632. package/dist/utility/blueprint/material/inputs.js +1659 -0
  633. package/dist/utility/blueprint/material/inputs.js.map +1 -0
  634. package/dist/utility/blueprint/material/ir.js +1311 -0
  635. package/dist/utility/blueprint/material/ir.js.map +1 -0
  636. package/dist/utility/blueprint/material/pbr.js +362 -0
  637. package/dist/utility/blueprint/material/pbr.js.map +1 -0
  638. package/dist/utility/blueprint/material/texture.js +1099 -0
  639. package/dist/utility/blueprint/material/texture.js.map +1 -0
  640. package/dist/utility/blueprint/node.js +187 -0
  641. package/dist/utility/blueprint/node.js.map +1 -0
  642. package/dist/utility/bounding_volume.js +0 -1
  643. package/dist/utility/bounding_volume.js.map +1 -1
  644. package/dist/utility/debug.js +26 -0
  645. package/dist/utility/debug.js.map +1 -0
  646. package/dist/utility/draco/decoder.js +1 -1
  647. package/dist/utility/draco/decoder.js.map +1 -1
  648. package/dist/utility/misc.js +18 -6
  649. package/dist/utility/misc.js.map +1 -1
  650. package/dist/utility/panorama.js +8 -6
  651. package/dist/utility/panorama.js.map +1 -1
  652. package/dist/utility/pmrem.js +30 -18
  653. package/dist/utility/pmrem.js.map +1 -1
  654. package/dist/utility/rendermipmap.js +116 -0
  655. package/dist/utility/rendermipmap.js.map +1 -0
  656. package/dist/utility/serialization/blueprint/constants.js +255 -0
  657. package/dist/utility/serialization/blueprint/constants.js.map +1 -0
  658. package/dist/utility/serialization/blueprint/material/constants.js +203 -0
  659. package/dist/utility/serialization/blueprint/material/constants.js.map +1 -0
  660. package/dist/utility/serialization/blueprint/material/texture.js +165 -0
  661. package/dist/utility/serialization/blueprint/material/texture.js.map +1 -0
  662. package/dist/utility/serialization/json.js +402 -0
  663. package/dist/utility/serialization/json.js.map +1 -0
  664. package/dist/utility/serialization/manager.js +1176 -0
  665. package/dist/utility/serialization/manager.js.map +1 -0
  666. package/dist/utility/serialization/scene/animation.js +699 -0
  667. package/dist/utility/serialization/scene/animation.js.map +1 -0
  668. package/dist/utility/serialization/scene/batch.js +53 -0
  669. package/dist/utility/serialization/scene/batch.js.map +1 -0
  670. package/dist/utility/serialization/scene/camera.js +808 -0
  671. package/dist/utility/serialization/scene/camera.js.map +1 -0
  672. package/dist/utility/serialization/scene/common.js +224 -0
  673. package/dist/utility/serialization/scene/common.js.map +1 -0
  674. package/dist/utility/serialization/scene/light.js +589 -0
  675. package/dist/utility/serialization/scene/light.js.map +1 -0
  676. package/dist/utility/serialization/scene/material.js +942 -0
  677. package/dist/utility/serialization/scene/material.js.map +1 -0
  678. package/dist/utility/serialization/scene/mesh.js +374 -0
  679. package/dist/utility/serialization/scene/mesh.js.map +1 -0
  680. package/dist/utility/serialization/scene/misc.js +39 -0
  681. package/dist/utility/serialization/scene/misc.js.map +1 -0
  682. package/dist/utility/serialization/scene/node.js +391 -0
  683. package/dist/utility/serialization/scene/node.js.map +1 -0
  684. package/dist/utility/serialization/scene/particle.js +425 -0
  685. package/dist/utility/serialization/scene/particle.js.map +1 -0
  686. package/dist/utility/serialization/scene/primitive.js +582 -0
  687. package/dist/utility/serialization/scene/primitive.js.map +1 -0
  688. package/dist/utility/serialization/scene/scene.js +763 -0
  689. package/dist/utility/serialization/scene/scene.js.map +1 -0
  690. package/dist/utility/serialization/scene/terrain.js +495 -0
  691. package/dist/utility/serialization/scene/terrain.js.map +1 -0
  692. package/dist/utility/serialization/scene/water.js +465 -0
  693. package/dist/utility/serialization/scene/water.js.map +1 -0
  694. package/dist/utility/shprojector.js +313 -0
  695. package/dist/utility/shprojector.js.map +1 -0
  696. package/dist/utility/textures/ggxlut.js +4 -5
  697. package/dist/utility/textures/ggxlut.js.map +1 -1
  698. package/dist/utility/textures/gradientnoise.js +2 -1
  699. package/dist/utility/textures/gradientnoise.js.map +1 -1
  700. package/dist/utility/textures/randomnoise.js +1 -0
  701. package/dist/utility/textures/randomnoise.js.map +1 -1
  702. package/dist/values.js +91 -4
  703. package/dist/values.js.map +1 -1
  704. package/package.json +29 -15
  705. package/dist/app.js.map +0 -1
  706. package/dist/blitter/depthlimitedgaussion.js.map +0 -1
  707. package/dist/input/inputmgr.js.map +0 -1
  708. package/dist/material/mixins/ggxlut.js.map +0 -1
  709. package/dist/posteffect/water.js +0 -508
  710. package/dist/posteffect/water.js.map +0 -1
  711. package/dist/render/oit.js +0 -16
  712. package/dist/render/oit.js.map +0 -1
  713. package/dist/render/scatteringlut.js +0 -634
  714. package/dist/render/scatteringlut.js.map +0 -1
  715. package/dist/render/watermesh.js +0 -193
  716. package/dist/render/watermesh.js.map +0 -1
  717. package/dist/render/wavegenerator.js +0 -8
  718. package/dist/render/wavegenerator.js.map +0 -1
  719. package/dist/scene/xform.js +0 -247
  720. package/dist/scene/xform.js.map +0 -1
  721. package/dist/utility/shprojection.js +0 -442
  722. package/dist/utility/shprojection.js.map +0 -1
@@ -0,0 +1,220 @@
1
+ import { HttpFS } from '@zephyr3d/base';
2
+ import { ScriptRegistry } from './scriptregistry.js';
3
+ import { RuntimeScript } from './runtimescript.js';
4
+
5
+ /**
6
+ * Script system that resolves, loads, and manages lifecycle of runtime scripts.
7
+ *
8
+ * Responsibilities:
9
+ * - Resolves module IDs to URLs via {@link ScriptRegistry}
10
+ * - Dynamically imports modules and instantiates a `RuntimeScript` (default export)
11
+ * - Tracks attachments between hosts and script instances
12
+ * - Bridges script lifecycle hooks: `onCreated`, `onAttached`, `onDetached`, `onDestroy`, `onUpdate`
13
+ * - Auto-detaches scripts when a host is disposed
14
+ *
15
+ * Notes:
16
+ * - Multiple hosts can reference the same `RuntimeScript` instance; destruction
17
+ * occurs when the last host detaches.
18
+ * - Errors during load/attach/update are caught and logged; an optional
19
+ * `onLoadError` callback can be provided.
20
+ *
21
+ * @public
22
+ */ class ScriptingSystem {
23
+ _registry;
24
+ _hostScripts;
25
+ _scriptHosts;
26
+ _onLoadError;
27
+ _importComment;
28
+ /**
29
+ * Constructs a new scripting system.
30
+ *
31
+ * @param opts - Optional configuration.
32
+ */ constructor(opts = {}){
33
+ this._registry = new ScriptRegistry(opts.VFS ?? new HttpFS('./'), opts.scriptsRoot ?? '/', opts.editorMode ?? false);
34
+ this._hostScripts = new Map();
35
+ this._scriptHosts = new Map();
36
+ this._importComment = opts.importComment;
37
+ this._onLoadError = opts.onLoadError;
38
+ }
39
+ /**
40
+ * Accessor for the underlying script registry used for module resolution.
41
+ */ get registry() {
42
+ return this._registry;
43
+ }
44
+ /**
45
+ * Attaches a script to a host and returns the `RuntimeScript` instance.
46
+ *
47
+ * Process:
48
+ * 1. Resolve module ID to a runtime URL via the registry.
49
+ * 2. Dynamically import the module.
50
+ * 3. Instantiate the default export if it is a constructor.
51
+ * 4. If this is the first time the instance is seen, call `onCreated()`.
52
+ * 5. Link the instance to the host, and call `onAttached(host)`.
53
+ * 6. Subscribe to the host's `'dispose'` event to auto-detach.
54
+ *
55
+ * If the module cannot be resolved or does not export a default `RuntimeScript`
56
+ * subclass, a warning is logged and `null` is returned.
57
+ *
58
+ * @typeParam T - Host type.
59
+ * @param host - The host object to attach the script to.
60
+ * @param module - Module identifier used by the registry (logical ID or path).
61
+ * @returns The instantiated `RuntimeScript<T>` or `null` on failure.
62
+ */ async attachScript(host, module) {
63
+ try {
64
+ const url = await this._registry.resolveRuntimeUrl(module);
65
+ if (!url) {
66
+ return null;
67
+ }
68
+ const mod = await import(url + (this._importComment ?? ''));
69
+ let instance = null;
70
+ if (typeof mod?.default === 'function') {
71
+ // default export
72
+ instance = new mod.default();
73
+ if (instance instanceof RuntimeScript) {
74
+ if (!this._scriptHosts.has(instance)) {
75
+ const P = instance.onCreated();
76
+ if (P instanceof Promise) {
77
+ await P;
78
+ }
79
+ }
80
+ } else {
81
+ instance = null;
82
+ }
83
+ }
84
+ if (!instance) {
85
+ console.warn(`Script '${module}' does not have RuntimeScript class exported as default`);
86
+ return null;
87
+ }
88
+ let hostList = this._scriptHosts.get(instance);
89
+ if (!hostList) {
90
+ hostList = [];
91
+ this._scriptHosts.set(instance, hostList);
92
+ }
93
+ if (hostList.includes(host)) {
94
+ console.warn(`Script '${module}' already attached`);
95
+ return instance;
96
+ }
97
+ hostList.push(host);
98
+ const P = instance.onAttached(host);
99
+ if (P instanceof Promise) {
100
+ await P;
101
+ }
102
+ const attached = {
103
+ id: module,
104
+ url,
105
+ instance
106
+ };
107
+ let list = this._hostScripts.get(host);
108
+ if (!list) {
109
+ list = [];
110
+ this._hostScripts.set(host, list);
111
+ if (host) {
112
+ host.on('dispose', ()=>{
113
+ this.detachScript(host);
114
+ });
115
+ }
116
+ }
117
+ list.push(attached);
118
+ return attached.instance;
119
+ } catch (e) {
120
+ const moduleName = module ? String(module).slice(0, 64) : '';
121
+ console.error(`Load module '${moduleName}' failed: ${e}`);
122
+ this._onLoadError?.(e, module);
123
+ return null;
124
+ }
125
+ }
126
+ /**
127
+ * Detaches script(s) from a host.
128
+ *
129
+ * Behavior:
130
+ * - If `idOrInstance` is omitted, detaches all scripts from the host.
131
+ * - If a module ID is provided, detaches only the matching script.
132
+ * - If a `RuntimeScript` instance is provided, detaches that instance.
133
+ * - Invokes `onDetached(host)` on each detached instance.
134
+ * - If the instance has no remaining hosts, invokes `onDestroy()` and disposes tracking.
135
+ *
136
+ * @typeParam T - Host type.
137
+ * @param host - The host to detach from.
138
+ * @param idOrInstance - Optional module ID or script instance to target.
139
+ */ detachScript(host, idOrInstance) {
140
+ const list = this._hostScripts.get(host);
141
+ if (!list || list.length === 0) {
142
+ return;
143
+ }
144
+ for(let i = list.length - 1; i >= 0; i--){
145
+ const it = list[i];
146
+ const hit = !idOrInstance || typeof idOrInstance === 'string' ? it.id === idOrInstance : it.instance === idOrInstance;
147
+ if (hit) {
148
+ list.splice(i, 1);
149
+ try {
150
+ it.instance.onDetached(host);
151
+ } catch (err) {
152
+ console.error(`Error occured at onDetach() of module '${it.id}': ${err}`);
153
+ }
154
+ const hostList = this._scriptHosts.get(it.instance);
155
+ const index = hostList.indexOf(host);
156
+ if (index >= 0) {
157
+ hostList.splice(index, 1);
158
+ }
159
+ if (hostList.length === 0) {
160
+ try {
161
+ it.instance.onDestroy();
162
+ } catch (err) {
163
+ console.error(`Error occured at onDestroy() of module '${it.id}': ${err}`);
164
+ } finally{
165
+ this._scriptHosts.delete(it.instance);
166
+ }
167
+ }
168
+ }
169
+ }
170
+ if (list.length === 0) {
171
+ this._hostScripts.delete(host);
172
+ }
173
+ }
174
+ /**
175
+ * Get all script instances attached to a host.
176
+ *
177
+ * @typeParam T - Expected script type.
178
+ * @param host - The host whose scripts to retrieve.
179
+ * @returns Script instances attached to the host, or an empty array if none.
180
+ */ getScriptObjects(host) {
181
+ return this._hostScripts.get(host) || [];
182
+ }
183
+ /**
184
+ * Ticks all attached script instances.
185
+ *
186
+ * Calls `onUpdate(deltaTime, elapsedTime)` on every attached script instance
187
+ * across all hosts. Exceptions thrown by a script are caught and logged,
188
+ * allowing other scripts to continue updating.
189
+ *
190
+ * @param deltaTime - Time in seconds since last update.
191
+ * @param elapsedTime - Total time in seconds since start.
192
+ */ update(deltaTime, elapsedTime) {
193
+ if (this._hostScripts.size === 0) {
194
+ return;
195
+ }
196
+ for (const list of this._hostScripts.values()){
197
+ for (const s of list){
198
+ try {
199
+ s.instance.onUpdate(deltaTime, elapsedTime);
200
+ } catch (err) {
201
+ console.error(`Error occured at onUpdate() of module '${s.id}': ${err}`);
202
+ }
203
+ }
204
+ }
205
+ }
206
+ /**
207
+ * Detaches all scripts from all hosts.
208
+ *
209
+ * Iteratively calls {@link ScriptingSystem.detachScript} on each host until no attachments remain.
210
+ */ detachAllScripts() {
211
+ while(this._hostScripts.size > 0){
212
+ for (const entry of this._hostScripts){
213
+ this.detachScript(entry[0]);
214
+ }
215
+ }
216
+ }
217
+ }
218
+
219
+ export { ScriptingSystem };
220
+ //# sourceMappingURL=scriptingsystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scriptingsystem.js","sources":["../../src/app/scriptingsystem.ts"],"sourcesContent":["import type { IDisposable, VFS } from '@zephyr3d/base';\r\nimport { HttpFS } from '@zephyr3d/base';\r\nimport { ScriptRegistry } from './scriptregistry';\r\nimport { RuntimeScript } from './runtimescript';\r\n\r\n/**\r\n * A host object that supports disposal.\r\n *\r\n * Hosts are objects to which scripts can be attached. They are expected to\r\n * emit a `'dispose'` event compatible with `IDisposable` so that scripts\r\n * can be automatically detached when the host is destroyed.\r\n *\r\n * @public\r\n */\r\nexport type Host = IDisposable;\r\n\r\n/**\r\n * Options for configuring a `ScriptingSystem`.\r\n *\r\n * @public\r\n */\r\nexport type ScriptingSystemOptions = {\r\n /** Virtual file system used by the script registry. Defaults to `new HttpFS('./')`. */\r\n VFS?: VFS;\r\n /** Root path for scripts within the VFS. Defaults to `/`. */\r\n scriptsRoot?: string;\r\n /** If true, enables editor-oriented behaviors in the registry. Defaults to `false`. */\r\n editorMode?: boolean;\r\n /**\r\n * Optional string appended to dynamic import URLs (e.g., for cache busting).\r\n * Example: `'?v=' + Date.now()`\r\n */\r\n importComment?: string;\r\n /**\r\n * Optional callback invoked when a module fails to load.\r\n * @param e - The error that occurred.\r\n * @param id - The module ID that failed to load.\r\n */\r\n onLoadError?: (e: unknown, id: string) => void;\r\n};\r\n\r\n/**\r\n * Information about a script attached to a host.\r\n *\r\n * @public\r\n */\r\nexport interface IAttachedScript {\r\n /** The logical module identifier used to resolve the script. */\r\n id: string;\r\n /** The resolved runtime URL used for dynamic import. */\r\n url: string;\r\n /** The instantiated runtime script. */\r\n instance: RuntimeScript<any>;\r\n}\r\n\r\n/**\r\n * Script system that resolves, loads, and manages lifecycle of runtime scripts.\r\n *\r\n * Responsibilities:\r\n * - Resolves module IDs to URLs via {@link ScriptRegistry}\r\n * - Dynamically imports modules and instantiates a `RuntimeScript` (default export)\r\n * - Tracks attachments between hosts and script instances\r\n * - Bridges script lifecycle hooks: `onCreated`, `onAttached`, `onDetached`, `onDestroy`, `onUpdate`\r\n * - Auto-detaches scripts when a host is disposed\r\n *\r\n * Notes:\r\n * - Multiple hosts can reference the same `RuntimeScript` instance; destruction\r\n * occurs when the last host detaches.\r\n * - Errors during load/attach/update are caught and logged; an optional\r\n * `onLoadError` callback can be provided.\r\n *\r\n * @public\r\n */\r\nexport class ScriptingSystem {\r\n private _registry: ScriptRegistry;\r\n private _hostScripts: Map<Host, IAttachedScript[]>;\r\n private _scriptHosts: Map<RuntimeScript<any>, Host[]>;\r\n private _onLoadError?: (e: unknown, id: string) => void;\r\n private _importComment?: string;\r\n\r\n /**\r\n * Constructs a new scripting system.\r\n *\r\n * @param opts - Optional configuration.\r\n */\r\n constructor(opts: ScriptingSystemOptions = {}) {\r\n this._registry = new ScriptRegistry(\r\n opts.VFS ?? new HttpFS('./'),\r\n opts.scriptsRoot ?? '/',\r\n opts.editorMode ?? false\r\n );\r\n this._hostScripts = new Map();\r\n this._scriptHosts = new Map();\r\n this._importComment = opts.importComment;\r\n this._onLoadError = opts.onLoadError;\r\n }\r\n\r\n /**\r\n * Accessor for the underlying script registry used for module resolution.\r\n */\r\n get registry() {\r\n return this._registry;\r\n }\r\n\r\n /**\r\n * Attaches a script to a host and returns the `RuntimeScript` instance.\r\n *\r\n * Process:\r\n * 1. Resolve module ID to a runtime URL via the registry.\r\n * 2. Dynamically import the module.\r\n * 3. Instantiate the default export if it is a constructor.\r\n * 4. If this is the first time the instance is seen, call `onCreated()`.\r\n * 5. Link the instance to the host, and call `onAttached(host)`.\r\n * 6. Subscribe to the host's `'dispose'` event to auto-detach.\r\n *\r\n * If the module cannot be resolved or does not export a default `RuntimeScript`\r\n * subclass, a warning is logged and `null` is returned.\r\n *\r\n * @typeParam T - Host type.\r\n * @param host - The host object to attach the script to.\r\n * @param module - Module identifier used by the registry (logical ID or path).\r\n * @returns The instantiated `RuntimeScript<T>` or `null` on failure.\r\n */\r\n async attachScript<T extends Host>(host: T, module: string): Promise<RuntimeScript<T>> {\r\n try {\r\n const url = await this._registry.resolveRuntimeUrl(module);\r\n if (!url) {\r\n return null;\r\n }\r\n const mod = await import(url + (this._importComment ?? ''));\r\n let instance: RuntimeScript<T> = null;\r\n if (typeof mod?.default === 'function') {\r\n // default export\r\n instance = new mod.default();\r\n if (instance instanceof RuntimeScript) {\r\n if (!this._scriptHosts.has(instance)) {\r\n const P = instance.onCreated();\r\n if (P instanceof Promise) {\r\n await P;\r\n }\r\n }\r\n } else {\r\n instance = null;\r\n }\r\n }\r\n if (!instance) {\r\n console.warn(`Script '${module}' does not have RuntimeScript class exported as default`);\r\n return null;\r\n }\r\n\r\n let hostList = this._scriptHosts.get(instance);\r\n if (!hostList) {\r\n hostList = [];\r\n this._scriptHosts.set(instance, hostList);\r\n }\r\n if (hostList.includes(host)) {\r\n console.warn(`Script '${module}' already attached`);\r\n return instance;\r\n }\r\n hostList.push(host);\r\n\r\n const P = instance.onAttached(host);\r\n if (P instanceof Promise) {\r\n await P;\r\n }\r\n\r\n const attached: IAttachedScript = {\r\n id: module,\r\n url,\r\n instance\r\n };\r\n\r\n let list = this._hostScripts.get(host);\r\n if (!list) {\r\n list = [];\r\n this._hostScripts.set(host, list);\r\n if (host) {\r\n host.on('dispose', () => {\r\n this.detachScript(host);\r\n });\r\n }\r\n }\r\n list.push(attached);\r\n\r\n return attached.instance;\r\n } catch (e) {\r\n const moduleName = module ? String(module).slice(0, 64) : '';\r\n console.error(`Load module '${moduleName}' failed: ${e}`);\r\n this._onLoadError?.(e, module);\r\n return null;\r\n }\r\n }\r\n\r\n /**\r\n * Detaches script(s) from a host.\r\n *\r\n * Behavior:\r\n * - If `idOrInstance` is omitted, detaches all scripts from the host.\r\n * - If a module ID is provided, detaches only the matching script.\r\n * - If a `RuntimeScript` instance is provided, detaches that instance.\r\n * - Invokes `onDetached(host)` on each detached instance.\r\n * - If the instance has no remaining hosts, invokes `onDestroy()` and disposes tracking.\r\n *\r\n * @typeParam T - Host type.\r\n * @param host - The host to detach from.\r\n * @param idOrInstance - Optional module ID or script instance to target.\r\n */\r\n detachScript<T extends Host>(host: T, idOrInstance?: string | RuntimeScript<T>) {\r\n const list = this._hostScripts.get(host);\r\n if (!list || list.length === 0) {\r\n return;\r\n }\r\n for (let i = list.length - 1; i >= 0; i--) {\r\n const it = list[i];\r\n const hit =\r\n !idOrInstance || typeof idOrInstance === 'string'\r\n ? it.id === idOrInstance\r\n : it.instance === idOrInstance;\r\n if (hit) {\r\n list.splice(i, 1);\r\n try {\r\n it.instance.onDetached(host);\r\n } catch (err) {\r\n console.error(`Error occured at onDetach() of module '${it.id}': ${err}`);\r\n }\r\n\r\n const hostList = this._scriptHosts.get(it.instance);\r\n const index = hostList.indexOf(host);\r\n if (index >= 0) {\r\n hostList.splice(index, 1);\r\n }\r\n\r\n if (hostList.length === 0) {\r\n try {\r\n it.instance.onDestroy();\r\n } catch (err) {\r\n console.error(`Error occured at onDestroy() of module '${it.id}': ${err}`);\r\n } finally {\r\n this._scriptHosts.delete(it.instance);\r\n }\r\n }\r\n }\r\n }\r\n if (list.length === 0) {\r\n this._hostScripts.delete(host);\r\n }\r\n }\r\n\r\n /**\r\n * Get all script instances attached to a host.\r\n *\r\n * @typeParam T - Expected script type.\r\n * @param host - The host whose scripts to retrieve.\r\n * @returns Script instances attached to the host, or an empty array if none.\r\n */\r\n getScriptObjects<T extends RuntimeScript<any>>(host: unknown): T[] {\r\n return (this._hostScripts.get(host as Host) as unknown as T[]) || [];\r\n }\r\n\r\n /**\r\n * Ticks all attached script instances.\r\n *\r\n * Calls `onUpdate(deltaTime, elapsedTime)` on every attached script instance\r\n * across all hosts. Exceptions thrown by a script are caught and logged,\r\n * allowing other scripts to continue updating.\r\n *\r\n * @param deltaTime - Time in seconds since last update.\r\n * @param elapsedTime - Total time in seconds since start.\r\n */\r\n update(deltaTime: number, elapsedTime: number): void {\r\n if (this._hostScripts.size === 0) {\r\n return;\r\n }\r\n for (const list of this._hostScripts.values()) {\r\n for (const s of list) {\r\n try {\r\n s.instance.onUpdate(deltaTime, elapsedTime);\r\n } catch (err) {\r\n console.error(`Error occured at onUpdate() of module '${s.id}': ${err}`);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Detaches all scripts from all hosts.\r\n *\r\n * Iteratively calls {@link ScriptingSystem.detachScript} on each host until no attachments remain.\r\n */\r\n detachAllScripts() {\r\n while (this._hostScripts.size > 0) {\r\n for (const entry of this._hostScripts) {\r\n this.detachScript(entry[0]);\r\n }\r\n }\r\n }\r\n}\r\n"],"names":["ScriptingSystem","_registry","_hostScripts","_scriptHosts","_onLoadError","_importComment","opts","ScriptRegistry","VFS","HttpFS","scriptsRoot","editorMode","Map","importComment","onLoadError","registry","attachScript","host","module","url","resolveRuntimeUrl","mod","instance","default","RuntimeScript","has","P","onCreated","Promise","console","warn","hostList","get","set","includes","push","onAttached","attached","id","list","on","detachScript","e","moduleName","String","slice","error","idOrInstance","length","i","it","hit","splice","onDetached","err","index","indexOf","onDestroy","delete","getScriptObjects","update","deltaTime","elapsedTime","size","values","s","onUpdate","detachAllScripts","entry"],"mappings":";;;;AAuDA;;;;;;;;;;;;;;;;;AAiBC,IACM,MAAMA,eAAAA,CAAAA;IACHC,SAA0B;IAC1BC,YAA2C;IAC3CC,YAA8C;IAC9CC,YAAgD;IAChDC,cAAwB;AAEhC;;;;AAIC,MACD,WAAYC,CAAAA,IAAAA,GAA+B,EAAE,CAAE;AAC7C,QAAA,IAAI,CAACL,SAAS,GAAG,IAAIM,cAAAA,CACnBD,KAAKE,GAAG,IAAI,IAAIC,MAAAA,CAAO,OACvBH,IAAKI,CAAAA,WAAW,IAAI,GACpBJ,EAAAA,IAAAA,CAAKK,UAAU,IAAI,KAAA,CAAA;QAErB,IAAI,CAACT,YAAY,GAAG,IAAIU,GAAAA,EAAAA;QACxB,IAAI,CAACT,YAAY,GAAG,IAAIS,GAAAA,EAAAA;AACxB,QAAA,IAAI,CAACP,cAAc,GAAGC,IAAAA,CAAKO,aAAa;AACxC,QAAA,IAAI,CAACT,YAAY,GAAGE,IAAAA,CAAKQ,WAAW;AACtC;AAEA;;AAEC,MACD,IAAIC,QAAW,GAAA;QACb,OAAO,IAAI,CAACd,SAAS;AACvB;AAEA;;;;;;;;;;;;;;;;;;AAkBC,MACD,MAAMe,YAAAA,CAA6BC,IAAO,EAAEC,MAAc,EAA6B;QACrF,IAAI;AACF,YAAA,MAAMC,MAAM,MAAM,IAAI,CAAClB,SAAS,CAACmB,iBAAiB,CAACF,MAAAA,CAAAA;AACnD,YAAA,IAAI,CAACC,GAAK,EAAA;gBACR,OAAO,IAAA;AACT;YACA,MAAME,GAAAA,GAAM,MAAM,OAAOF,GAAAA,IAAO,IAAI,CAACd,cAAc,IAAI,EAAC,CAAA,CAAA;AACxD,YAAA,IAAIiB,QAA6B,GAAA,IAAA;YACjC,IAAI,OAAOD,GAAKE,EAAAA,OAAAA,KAAY,UAAY,EAAA;;gBAEtCD,QAAW,GAAA,IAAID,IAAIE,OAAO,EAAA;AAC1B,gBAAA,IAAID,oBAAoBE,aAAe,EAAA;AACrC,oBAAA,IAAI,CAAC,IAAI,CAACrB,YAAY,CAACsB,GAAG,CAACH,QAAW,CAAA,EAAA;wBACpC,MAAMI,CAAAA,GAAIJ,SAASK,SAAS,EAAA;AAC5B,wBAAA,IAAID,aAAaE,OAAS,EAAA;4BACxB,MAAMF,CAAAA;AACR;AACF;iBACK,MAAA;oBACLJ,QAAW,GAAA,IAAA;AACb;AACF;AACA,YAAA,IAAI,CAACA,QAAU,EAAA;AACbO,gBAAAA,OAAAA,CAAQC,IAAI,CAAC,CAAC,QAAQ,EAAEZ,MAAAA,CAAO,uDAAuD,CAAC,CAAA;gBACvF,OAAO,IAAA;AACT;AAEA,YAAA,IAAIa,WAAW,IAAI,CAAC5B,YAAY,CAAC6B,GAAG,CAACV,QAAAA,CAAAA;AACrC,YAAA,IAAI,CAACS,QAAU,EAAA;AACbA,gBAAAA,QAAAA,GAAW,EAAE;AACb,gBAAA,IAAI,CAAC5B,YAAY,CAAC8B,GAAG,CAACX,QAAUS,EAAAA,QAAAA,CAAAA;AAClC;YACA,IAAIA,QAAAA,CAASG,QAAQ,CAACjB,IAAO,CAAA,EAAA;AAC3BY,gBAAAA,OAAAA,CAAQC,IAAI,CAAC,CAAC,QAAQ,EAAEZ,MAAAA,CAAO,kBAAkB,CAAC,CAAA;gBAClD,OAAOI,QAAAA;AACT;AACAS,YAAAA,QAAAA,CAASI,IAAI,CAAClB,IAAAA,CAAAA;YAEd,MAAMS,CAAAA,GAAIJ,QAASc,CAAAA,UAAU,CAACnB,IAAAA,CAAAA;AAC9B,YAAA,IAAIS,aAAaE,OAAS,EAAA;gBACxB,MAAMF,CAAAA;AACR;AAEA,YAAA,MAAMW,QAA4B,GAAA;gBAChCC,EAAIpB,EAAAA,MAAAA;AACJC,gBAAAA,GAAAA;AACAG,gBAAAA;AACF,aAAA;AAEA,YAAA,IAAIiB,OAAO,IAAI,CAACrC,YAAY,CAAC8B,GAAG,CAACf,IAAAA,CAAAA;AACjC,YAAA,IAAI,CAACsB,IAAM,EAAA;AACTA,gBAAAA,IAAAA,GAAO,EAAE;AACT,gBAAA,IAAI,CAACrC,YAAY,CAAC+B,GAAG,CAAChB,IAAMsB,EAAAA,IAAAA,CAAAA;AAC5B,gBAAA,IAAItB,IAAM,EAAA;oBACRA,IAAKuB,CAAAA,EAAE,CAAC,SAAW,EAAA,IAAA;wBACjB,IAAI,CAACC,YAAY,CAACxB,IAAAA,CAAAA;AACpB,qBAAA,CAAA;AACF;AACF;AACAsB,YAAAA,IAAAA,CAAKJ,IAAI,CAACE,QAAAA,CAAAA;AAEV,YAAA,OAAOA,SAASf,QAAQ;AAC1B,SAAA,CAAE,OAAOoB,CAAG,EAAA;AACV,YAAA,MAAMC,aAAazB,MAAS0B,GAAAA,MAAAA,CAAO1B,QAAQ2B,KAAK,CAAC,GAAG,EAAM,CAAA,GAAA,EAAA;YAC1DhB,OAAQiB,CAAAA,KAAK,CAAC,CAAC,aAAa,EAAEH,UAAW,CAAA,UAAU,EAAED,CAAG,CAAA,CAAA,CAAA;YACxD,IAAI,CAACtC,YAAY,GAAGsC,CAAGxB,EAAAA,MAAAA,CAAAA;YACvB,OAAO,IAAA;AACT;AACF;AAEA;;;;;;;;;;;;;AAaC,MACDuB,YAA6BxB,CAAAA,IAAO,EAAE8B,YAAwC,EAAE;AAC9E,QAAA,MAAMR,OAAO,IAAI,CAACrC,YAAY,CAAC8B,GAAG,CAACf,IAAAA,CAAAA;AACnC,QAAA,IAAI,CAACsB,IAAAA,IAAQA,IAAKS,CAAAA,MAAM,KAAK,CAAG,EAAA;AAC9B,YAAA;AACF;QACA,IAAK,IAAIC,IAAIV,IAAKS,CAAAA,MAAM,GAAG,CAAGC,EAAAA,CAAAA,IAAK,GAAGA,CAAK,EAAA,CAAA;YACzC,MAAMC,EAAAA,GAAKX,IAAI,CAACU,CAAE,CAAA;AAClB,YAAA,MAAME,GACJ,GAAA,CAACJ,YAAgB,IAAA,OAAOA,YAAiB,KAAA,QAAA,GACrCG,EAAGZ,CAAAA,EAAE,KAAKS,YAAAA,GACVG,EAAG5B,CAAAA,QAAQ,KAAKyB,YAAAA;AACtB,YAAA,IAAII,GAAK,EAAA;gBACPZ,IAAKa,CAAAA,MAAM,CAACH,CAAG,EAAA,CAAA,CAAA;gBACf,IAAI;oBACFC,EAAG5B,CAAAA,QAAQ,CAAC+B,UAAU,CAACpC,IAAAA,CAAAA;AACzB,iBAAA,CAAE,OAAOqC,GAAK,EAAA;oBACZzB,OAAQiB,CAAAA,KAAK,CAAC,CAAC,uCAAuC,EAAEI,GAAGZ,EAAE,CAAC,GAAG,EAAEgB,GAAK,CAAA,CAAA,CAAA;AAC1E;gBAEA,MAAMvB,QAAAA,GAAW,IAAI,CAAC5B,YAAY,CAAC6B,GAAG,CAACkB,GAAG5B,QAAQ,CAAA;gBAClD,MAAMiC,KAAAA,GAAQxB,QAASyB,CAAAA,OAAO,CAACvC,IAAAA,CAAAA;AAC/B,gBAAA,IAAIsC,SAAS,CAAG,EAAA;oBACdxB,QAASqB,CAAAA,MAAM,CAACG,KAAO,EAAA,CAAA,CAAA;AACzB;gBAEA,IAAIxB,QAAAA,CAASiB,MAAM,KAAK,CAAG,EAAA;oBACzB,IAAI;wBACFE,EAAG5B,CAAAA,QAAQ,CAACmC,SAAS,EAAA;AACvB,qBAAA,CAAE,OAAOH,GAAK,EAAA;wBACZzB,OAAQiB,CAAAA,KAAK,CAAC,CAAC,wCAAwC,EAAEI,GAAGZ,EAAE,CAAC,GAAG,EAAEgB,GAAK,CAAA,CAAA,CAAA;qBACjE,QAAA;AACR,wBAAA,IAAI,CAACnD,YAAY,CAACuD,MAAM,CAACR,GAAG5B,QAAQ,CAAA;AACtC;AACF;AACF;AACF;QACA,IAAIiB,IAAAA,CAAKS,MAAM,KAAK,CAAG,EAAA;AACrB,YAAA,IAAI,CAAC9C,YAAY,CAACwD,MAAM,CAACzC,IAAAA,CAAAA;AAC3B;AACF;AAEA;;;;;;MAOA0C,gBAAAA,CAA+C1C,IAAa,EAAO;QACjE,OAAQ,IAAI,CAACf,YAAY,CAAC8B,GAAG,CAACf,SAAoC,EAAE;AACtE;AAEA;;;;;;;;;AASC,MACD2C,MAAOC,CAAAA,SAAiB,EAAEC,WAAmB,EAAQ;AACnD,QAAA,IAAI,IAAI,CAAC5D,YAAY,CAAC6D,IAAI,KAAK,CAAG,EAAA;AAChC,YAAA;AACF;AACA,QAAA,KAAK,MAAMxB,IAAQ,IAAA,IAAI,CAACrC,YAAY,CAAC8D,MAAM,EAAI,CAAA;YAC7C,KAAK,MAAMC,KAAK1B,IAAM,CAAA;gBACpB,IAAI;AACF0B,oBAAAA,CAAAA,CAAE3C,QAAQ,CAAC4C,QAAQ,CAACL,SAAWC,EAAAA,WAAAA,CAAAA;AACjC,iBAAA,CAAE,OAAOR,GAAK,EAAA;oBACZzB,OAAQiB,CAAAA,KAAK,CAAC,CAAC,uCAAuC,EAAEmB,EAAE3B,EAAE,CAAC,GAAG,EAAEgB,GAAK,CAAA,CAAA,CAAA;AACzE;AACF;AACF;AACF;AAEA;;;;AAIC,MACDa,gBAAmB,GAAA;AACjB,QAAA,MAAO,IAAI,CAACjE,YAAY,CAAC6D,IAAI,GAAG,CAAG,CAAA;AACjC,YAAA,KAAK,MAAMK,KAAAA,IAAS,IAAI,CAAClE,YAAY,CAAE;AACrC,gBAAA,IAAI,CAACuC,YAAY,CAAC2B,KAAK,CAAC,CAAE,CAAA,CAAA;AAC5B;AACF;AACF;AACF;;;;"}
@@ -0,0 +1,432 @@
1
+ import { textToBase64 } from '@zephyr3d/base';
2
+ import { init, parse } from '../node_modules/es-module-lexer/dist/lexer.js';
3
+
4
+ /**
5
+ * Converts JavaScript source to a data URL tied to a logical module id.
6
+ *
7
+ * @param js - The JavaScript source code to embed.
8
+ * @param id - Logical module identifier (used only for sourceURL tagging).
9
+ * @returns A `data:text/javascript;base64,...` URL with an encoded `#id` suffix.
10
+ * @internal
11
+ */ function toDataUrl(js, id) {
12
+ const b64 = textToBase64(js);
13
+ return `data:text/javascript;base64,${b64}#${encodeURIComponent(String(id))}`;
14
+ }
15
+ /**
16
+ * Checks whether a specifier is an absolute HTTP(S) URL.
17
+ * @internal
18
+ */ function isAbsoluteUrl(spec) {
19
+ return /^https?:\/\//i.test(spec);
20
+ }
21
+ /**
22
+ * Checks whether a specifier is a special URL (data: or blob:).
23
+ * @internal
24
+ */ function isSpecialUrl(spec) {
25
+ return /^(data|blob):/i.test(spec);
26
+ }
27
+ /**
28
+ * Checks whether a specifier is a bare module (not starting with ./, ../, /, or #/).
29
+ * @internal
30
+ */ function isBareModule(spec) {
31
+ return !spec.startsWith('./') && !spec.startsWith('../') && !spec.startsWith('/') && !spec.startsWith('#/');
32
+ }
33
+ /**
34
+ * Resolves, builds, and serves runtime modules using a VFS.
35
+ *
36
+ * Responsibilities:
37
+ * - Resolve logical module IDs to physical paths or URLs.
38
+ * - In editor mode, rewrite import specifiers and serve modules as data URLs after transpile.
39
+ * - Transpile TypeScript to JavaScript on the fly (requires `window.ts` TypeScript runtime).
40
+ * - Gather static and dynamic import dependencies for tooling.
41
+ *
42
+ * Modes:
43
+ * - Editor mode (`editorMode === true`): modules are rewritten to data URLs after transpile/build.
44
+ * - Runtime mode (`editorMode === false`): returns .js URLs directly (with .ts -\> .js mapping).
45
+ *
46
+ * Caching:
47
+ * - Built modules are memoized in `_built` map keyed by logical ID.
48
+ *
49
+ * @public
50
+ */ class ScriptRegistry {
51
+ _vfs;
52
+ _scriptsRoot;
53
+ _built = new Map();
54
+ _editorMode = false;
55
+ /**
56
+ * @param vfs - The virtual file system for existence checks, reads, and path ops.
57
+ * @param scriptsRoot - Root directory for script resolution (used with `#/` specifiers).
58
+ * @param editorMode - Whether to build modules to data URLs and rewrite imports.
59
+ */ constructor(vfs, scriptsRoot, editorMode){
60
+ this._vfs = vfs;
61
+ this._scriptsRoot = scriptsRoot;
62
+ this._editorMode = editorMode;
63
+ }
64
+ /**
65
+ * The active virtual file system.
66
+ *
67
+ * Assigning a new VFS clears the build cache.
68
+ */ get VFS() {
69
+ return this._vfs;
70
+ }
71
+ set VFS(vfs) {
72
+ if (vfs !== this._vfs) {
73
+ this._vfs = vfs;
74
+ this._built.clear();
75
+ }
76
+ }
77
+ /**
78
+ * Whether the registry operates in editor mode (rewrite/build to data URLs).
79
+ */ get editorMode() {
80
+ return this._editorMode;
81
+ }
82
+ set editorMode(val) {
83
+ this._editorMode = val;
84
+ }
85
+ /**
86
+ * The root path used by `#/` specifiers.
87
+ */ get scriptsRoot() {
88
+ return this._scriptsRoot;
89
+ }
90
+ set scriptsRoot(path) {
91
+ this._scriptsRoot = path;
92
+ }
93
+ /**
94
+ * Fetches raw source for a logical module id by probing known extensions.
95
+ *
96
+ * Search order:
97
+ * - If `id` already ends with `.ts` or `.js` and is a file -\> return it.
98
+ * - Else try `.id.ts`, then `.id.js`.
99
+ *
100
+ * @param id - Logical module identifier (absolute or logical path-like).
101
+ * @returns Source code, resolved path, and type (`'js' | 'ts'`), or `undefined` if not found.
102
+ */ async fetchSource(id) {
103
+ let type = null;
104
+ let pathWithExt = '';
105
+ if (id.endsWith('.ts')) {
106
+ pathWithExt = id;
107
+ type = 'ts';
108
+ } else if (id.endsWith('.js')) {
109
+ pathWithExt = id;
110
+ type = 'js';
111
+ }
112
+ if (type) {
113
+ const exists = await this._vfs.exists(pathWithExt);
114
+ if (!exists) {
115
+ type = null;
116
+ }
117
+ const stat = await this._vfs.stat(pathWithExt);
118
+ if (stat.isDirectory) {
119
+ type = null;
120
+ }
121
+ }
122
+ const types = [
123
+ 'ts',
124
+ 'js'
125
+ ];
126
+ if (!type) {
127
+ for (const t of types){
128
+ pathWithExt = `${id}.${t}`;
129
+ const exists = await this._vfs.exists(pathWithExt);
130
+ if (exists) {
131
+ const stats = await this._vfs.stat(pathWithExt);
132
+ if (stats.isFile) {
133
+ type = t;
134
+ break;
135
+ }
136
+ }
137
+ }
138
+ }
139
+ if (type) {
140
+ const code = await this._vfs.readFile(pathWithExt, {
141
+ encoding: 'utf8'
142
+ });
143
+ return {
144
+ code,
145
+ type,
146
+ path: pathWithExt
147
+ };
148
+ }
149
+ }
150
+ /**
151
+ * Resolves a module entry to a URL suitable for dynamic import.
152
+ *
153
+ * Behavior:
154
+ * - In editor mode, builds the module to a data URL.
155
+ * - Otherwise, returns `.js` URL directly:
156
+ * - If `id` ends with `.js`: return as-is.
157
+ * - If `id` ends with `.ts`: map to `.js` (assumes pre-built file exists).
158
+ * - Else: append `.js`.
159
+ *
160
+ * @param entryId - Entry module identifier (logical or path-like).
161
+ * @returns A URL string that can be used in `import(...)`.
162
+ */ async resolveRuntimeUrl(entryId) {
163
+ const id = await this.resolveLogicalId(entryId);
164
+ return this._editorMode ? await this.build(String(id)) : id.endsWith('.js') ? id : id.endsWith('.ts') ? `${id.slice(0, -3)}.js` : `${id}.js`;
165
+ }
166
+ /**
167
+ * Recursively gathers direct static and dynamic import dependencies for a module.
168
+ *
169
+ * Only relative specifiers (`./` or `../`) are followed. Absolute, special, and bare
170
+ * module specifiers are ignored here.
171
+ *
172
+ * @param entryId - The starting (possibly relative) specifier from `fromId`.
173
+ * @param fromId - The logical id of the module containing `entryId`.
174
+ * @param dependencies - Output map of `resolvedSourcePath -\> file contents`.
175
+ */ async getDependencies(entryId, fromId, dependencies) {
176
+ const reStatic = /\b(?:import|export)\s+[^"']*?from\s+(['"])([^'"]+)\1/g;
177
+ const reDynamic = /\bimport\s*\(\s*(['"])([^'"]+)\1\s*\)/g;
178
+ const normalizedId = await this.resolveLogicalId(entryId, fromId);
179
+ const srcPath = await this.resolveSourcePath(normalizedId);
180
+ if (!srcPath || dependencies[srcPath.path] !== undefined) {
181
+ return;
182
+ }
183
+ const code = await this._vfs.readFile(srcPath.path, {
184
+ encoding: 'utf8'
185
+ });
186
+ dependencies[srcPath.path] = code;
187
+ const gather = async (input, re)=>{
188
+ for(;;){
189
+ const m = re.exec(input);
190
+ if (!m) {
191
+ break;
192
+ }
193
+ const spec = m[2];
194
+ if (spec.startsWith('./') || spec.startsWith('../')) {
195
+ await this.getDependencies(spec, normalizedId, dependencies);
196
+ }
197
+ }
198
+ };
199
+ await gather(code, reStatic);
200
+ await gather(code, reDynamic);
201
+ }
202
+ /**
203
+ * Builds a logical module id into a data URL (editor mode pipeline).
204
+ *
205
+ * Steps:
206
+ * - Resolve source path (.ts/.js) via {@link ScriptRegistry.resolveSourcePath}.
207
+ * - Read source code.
208
+ * - Rewrite import specifiers via {@link ScriptRegistry.rewriteImports}.
209
+ * - Transpile TypeScript if needed via {@link ScriptRegistry.transpile}.
210
+ * - Convert to `data:` URL and memoize in `_built`.
211
+ *
212
+ * @param id - Logical module id to build.
213
+ * @returns Data URL string for dynamic import, or empty string if not found.
214
+ */ async build(id) {
215
+ const key = String(id);
216
+ const cached = this._built.get(key);
217
+ if (cached) {
218
+ return cached;
219
+ }
220
+ const srcPath = await this.resolveSourcePath(key);
221
+ if (!srcPath) {
222
+ return '';
223
+ }
224
+ const code = await this._vfs.readFile(srcPath.path, {
225
+ encoding: 'utf8'
226
+ });
227
+ const rewritten = await this.rewriteImports(code, key);
228
+ const js = await this.transpile(rewritten, key, srcPath.type);
229
+ const url = toDataUrl(js, key);
230
+ this._built.set(key, url);
231
+ return url;
232
+ }
233
+ /**
234
+ * Transpiles code to JavaScript and appends sourceURL/sourceMap hints.
235
+ *
236
+ * Behavior:
237
+ * - For `'js'`, returns code with `//# sourceURL=logicalId`.
238
+ * - For `'ts'`, requires `window.ts` (TypeScript compiler) to be present and
239
+ * transpiles to ES2015/ESNext module with inline source maps.
240
+ *
241
+ * @param code - Source code to transpile.
242
+ * @param _id - Logical module id (used for fileName/sourceURL).
243
+ * @param type - Source type (`'js' | 'ts'`).
244
+ * @returns Transpiled JavaScript source.
245
+ * @throws If TypeScript runtime is not found for TS input.
246
+ */ async transpile(code, _id, type) {
247
+ const logicalId = String(_id);
248
+ if (type === 'js') {
249
+ return `${code}\n//# sourceURL=${logicalId}`;
250
+ }
251
+ const ts = window.ts;
252
+ if (!ts) {
253
+ throw new Error('TypeScript runtime (window.ts) not found. Load typescript.js first.');
254
+ }
255
+ const res = ts.transpileModule(code, {
256
+ compilerOptions: {
257
+ target: ts.ScriptTarget.ES2015,
258
+ module: ts.ModuleKind.ESNext,
259
+ sourceMap: true,
260
+ inlineSources: true,
261
+ experimentalDecorators: true,
262
+ useDefineForClassFields: false
263
+ },
264
+ fileName: logicalId
265
+ });
266
+ let out = res.outputText || '';
267
+ if (res.sourceMapText) {
268
+ const mapBase64 = btoa(unescape(encodeURIComponent(res.sourceMapText)));
269
+ out += `\n//# sourceMappingURL=data:application/json;base64,${mapBase64}`;
270
+ }
271
+ out += `\n//# sourceURL=${logicalId}`;
272
+ return out;
273
+ }
274
+ /**
275
+ * Rewrites ESM import specifiers in `code` into runtime-loadable URLs.
276
+ *
277
+ * Parsing:
278
+ * - Uses `es-module-lexer` to find import spans; sorts them ascending by start.
279
+ *
280
+ * Replacement rules:
281
+ * - Skip invalid spans or ones without quoted specifiers.
282
+ * - If spec is absolute URL, special URL (data:, blob:), or bare module:
283
+ * - If it starts with `@zephyr3d/`, keep as-is (external).
284
+ * - Otherwise resolve to a logical id and attempt to `build` it (if available).
285
+ * - Else (relative spec), resolve from `fromId` and `build` recursively.
286
+ *
287
+ * Output:
288
+ * - Directly writes the replacement specifier without re-adding quotes,
289
+ * so replacements must themselves be quoted or be valid URLs/data URLs.
290
+ *
291
+ * @param code - Module source code to transform.
292
+ * @param fromId - The logical id of the current module (resolution base for relatives).
293
+ * @returns Transformed source with rewritten import specifiers.
294
+ */ async rewriteImports(code, fromId) {
295
+ await init;
296
+ const [imports] = parse(code);
297
+ const list = [
298
+ ...imports
299
+ ].sort((a, b)=>(a.s || 0) - (b.s || 0));
300
+ let out = '';
301
+ let last = 0;
302
+ for (const im of list){
303
+ // must have quotes
304
+ const hasQuote = im.ss != null && im.se != null;
305
+ if (!hasQuote || im.se <= im.ss) {
306
+ continue;
307
+ }
308
+ // must have contents
309
+ if (im.e <= im.s) {
310
+ continue;
311
+ }
312
+ // append [last, s)
313
+ out += code.slice(last, im.s);
314
+ const spec = code.slice(im.s, im.e); // original spec
315
+ let replacement = spec;
316
+ if (isAbsoluteUrl(spec) || isSpecialUrl(spec) || isBareModule(spec)) {
317
+ if (spec.startsWith('@zephyr3d/')) {
318
+ replacement = spec;
319
+ } else {
320
+ const depId = await this.resolveLogicalId(spec);
321
+ replacement = await this.build(depId); // try build as dependence
322
+ }
323
+ } else {
324
+ const depId = await this.resolveLogicalId(spec, String(fromId));
325
+ replacement = await this.build(depId); // recursively build as dataURL
326
+ }
327
+ out += replacement; // 不加引号
328
+ last = im.e;
329
+ }
330
+ out += code.slice(last);
331
+ return out;
332
+ }
333
+ /**
334
+ * Resolves a specifier to a logical id suitable for further processing.
335
+ *
336
+ * Resolution rules:
337
+ * - `#/path`: resolved against `scriptsRoot` via VFS join/normalize.
338
+ * - `./` or `../`: resolved relative to `fromId` directory (requires `fromId`).
339
+ * - `/absolute`: treated as absolute from root (normalized).
340
+ * - Bare module in editor mode: if `/deps.lock.json` exists and contains an entry,
341
+ * map to the dependency's `entry` path; otherwise return as-is.
342
+ * - Else (non-editor bare module): return `spec` unchanged (external).
343
+ *
344
+ * @param spec - Import specifier string.
345
+ * @param fromId - Optional base logical id used for relative resolution.
346
+ * @returns A normalized logical id or an external specifier string.
347
+ * @throws If a relative import is provided without `fromId`.
348
+ */ async resolveLogicalId(spec, fromId) {
349
+ let path;
350
+ if (spec.startsWith('#/')) {
351
+ path = this._vfs.normalizePath(this._vfs.join(this._scriptsRoot, spec.slice(2)));
352
+ } else if (spec.startsWith('./') || spec.startsWith('../')) {
353
+ if (!fromId) {
354
+ throw new Error(`Relative import "${spec}" requires fromId`);
355
+ }
356
+ path = this._vfs.normalizePath(this._vfs.join(this._vfs.dirname(this._vfs.normalizePath(fromId)), spec));
357
+ } else if (spec.startsWith('/')) {
358
+ path = spec.replace(/^\/+/, '/');
359
+ } else if (this._editorMode) {
360
+ // naked module, checking if it is a installed module in editor mode
361
+ const depsExists = await this._vfs.exists('/libs/deps.lock.json');
362
+ if (depsExists) {
363
+ const content = await this._vfs.readFile('/libs/deps.lock.json', {
364
+ encoding: 'utf8'
365
+ });
366
+ const depsInfo = JSON.parse(content);
367
+ if (depsInfo?.dependencies[spec]) {
368
+ path = this._vfs.normalizePath(depsInfo.dependencies[spec].entry);
369
+ }
370
+ }
371
+ } else {
372
+ return spec;
373
+ }
374
+ return path;
375
+ }
376
+ /**
377
+ * Resolves a logical id to a concrete source path and type by probing extensions.
378
+ *
379
+ * Rules:
380
+ * - If `logicalId` ends with `.ts` or `.js`/`.mjs` and is a file, return it.
381
+ * - Else probe `logicalId.ts`, `logicalId.js`, `logicalId.mjs` in that order.
382
+ * - Maps `.mjs` to type `'js'`.
383
+ *
384
+ * @param logicalId - The normalized logical module id (path-like).
385
+ * @returns `{ type, path }` or `null` if not found.
386
+ */ async resolveSourcePath(logicalId) {
387
+ let type = null;
388
+ let pathWithExt = '';
389
+ if (logicalId.endsWith('.ts')) {
390
+ pathWithExt = logicalId;
391
+ type = 'ts';
392
+ } else if (logicalId.endsWith('.js') || logicalId.endsWith('.mjs')) {
393
+ pathWithExt = logicalId;
394
+ type = 'js';
395
+ }
396
+ if (type) {
397
+ const exists = await this._vfs.exists(pathWithExt);
398
+ if (!exists) {
399
+ type = null;
400
+ }
401
+ const stat = await this._vfs.stat(pathWithExt);
402
+ if (stat.isDirectory) {
403
+ type = null;
404
+ }
405
+ }
406
+ const types = [
407
+ 'ts',
408
+ 'js',
409
+ 'mjs'
410
+ ];
411
+ if (!type) {
412
+ for (const t of types){
413
+ pathWithExt = `${logicalId}.${t}`;
414
+ const exists = await this._vfs.exists(pathWithExt);
415
+ if (exists) {
416
+ const stats = await this._vfs.stat(pathWithExt);
417
+ if (stats.isFile) {
418
+ type = t === 'ts' ? 'ts' : 'js';
419
+ break;
420
+ }
421
+ }
422
+ }
423
+ }
424
+ return type ? {
425
+ type,
426
+ path: pathWithExt
427
+ } : null;
428
+ }
429
+ }
430
+
431
+ export { ScriptRegistry };
432
+ //# sourceMappingURL=scriptregistry.js.map