@egret/engine 0.0.0-stage → 7.0.1-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (575) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +21 -0
  3. package/README.md +101 -2
  4. package/README.zh-CN.md +102 -0
  5. package/dist/Engine.d.ts +77 -0
  6. package/dist/Engine.js +464 -0
  7. package/dist/animation/index.d.ts +6 -0
  8. package/dist/animation/index.js +5 -0
  9. package/dist/animation/sequenceController.d.ts +22 -0
  10. package/dist/animation/sequenceController.js +618 -0
  11. package/dist/animation/sequenceCoordinator.d.ts +26 -0
  12. package/dist/animation/sequenceCoordinator.js +161 -0
  13. package/dist/animation/sequenceInput.d.ts +25 -0
  14. package/dist/animation/sequenceInput.js +108 -0
  15. package/dist/animation/sequenceMath.d.ts +35 -0
  16. package/dist/animation/sequenceMath.js +164 -0
  17. package/dist/animation/sequenceResetSlot.d.ts +7 -0
  18. package/dist/animation/sequenceResetSlot.js +367 -0
  19. package/dist/animation/sequenceResetTypes.d.ts +42 -0
  20. package/dist/animation/sequenceResetTypes.js +2 -0
  21. package/dist/animation/types.d.ts +69 -0
  22. package/dist/animation/types.js +2 -0
  23. package/dist/assetBundle.d.ts +52 -0
  24. package/dist/assetBundle.js +173 -0
  25. package/dist/assetGroup.d.ts +17 -0
  26. package/dist/assetGroup.js +332 -0
  27. package/dist/assetGroupTypes.d.ts +15 -0
  28. package/dist/assetGroupTypes.js +2 -0
  29. package/dist/audio.d.ts +4 -0
  30. package/dist/audio.js +4 -0
  31. package/dist/audioCues.d.ts +43 -0
  32. package/dist/audioCues.js +127 -0
  33. package/dist/audioMixer.d.ts +7 -0
  34. package/dist/audioMixer.js +785 -0
  35. package/dist/audioTypes.d.ts +233 -0
  36. package/dist/audioTypes.js +3 -0
  37. package/dist/bitmapBindingTicket.d.ts +24 -0
  38. package/dist/bitmapBindingTicket.js +215 -0
  39. package/dist/bitmapButton.d.ts +4 -0
  40. package/dist/bitmapButton.js +407 -0
  41. package/dist/bitmapButtonTypes.d.ts +29 -0
  42. package/dist/bitmapButtonTypes.js +2 -0
  43. package/dist/bitmapFontParse.d.ts +10 -0
  44. package/dist/bitmapFontParse.js +246 -0
  45. package/dist/bitmapFontTypes.d.ts +109 -0
  46. package/dist/bitmapFontTypes.js +2 -0
  47. package/dist/bitmapResourceSlot.d.ts +25 -0
  48. package/dist/bitmapResourceSlot.js +340 -0
  49. package/dist/bitmapText.d.ts +6 -0
  50. package/dist/bitmapText.js +320 -0
  51. package/dist/bitmapfont.d.ts +5 -0
  52. package/dist/bitmapfont.js +5 -0
  53. package/dist/camera.d.ts +4 -0
  54. package/dist/camera.js +4 -0
  55. package/dist/camera2d.d.ts +7 -0
  56. package/dist/camera2d.js +411 -0
  57. package/dist/cameraTypes.d.ts +114 -0
  58. package/dist/cameraTypes.js +2 -0
  59. package/dist/closeHost.d.ts +4 -0
  60. package/dist/closeHost.js +66 -0
  61. package/dist/contentArtifacts.d.ts +12 -0
  62. package/dist/contentArtifacts.js +153 -0
  63. package/dist/contentAtlasPages.d.ts +13 -0
  64. package/dist/contentAtlasPages.js +117 -0
  65. package/dist/contentLoader.d.ts +6 -0
  66. package/dist/contentLoader.js +327 -0
  67. package/dist/contentTypes.d.ts +33 -0
  68. package/dist/contentTypes.js +2 -0
  69. package/dist/createEngine.d.ts +7 -0
  70. package/dist/createEngine.js +25 -0
  71. package/dist/createEngineForProfile.d.ts +5 -0
  72. package/dist/createEngineForProfile.js +42 -0
  73. package/dist/displaySubtreeTicket.d.ts +25 -0
  74. package/dist/displaySubtreeTicket.js +76 -0
  75. package/dist/fontContentLoader.d.ts +6 -0
  76. package/dist/fontContentLoader.js +298 -0
  77. package/dist/fontContentTypes.d.ts +34 -0
  78. package/dist/fontContentTypes.js +2 -0
  79. package/dist/gameClock.d.ts +24 -0
  80. package/dist/gameClock.js +246 -0
  81. package/dist/gameClockTypes.d.ts +31 -0
  82. package/dist/gameClockTypes.js +2 -0
  83. package/dist/gameRun.d.ts +50 -0
  84. package/dist/gameRun.js +97 -0
  85. package/dist/gamepad.d.ts +5 -0
  86. package/dist/gamepad.js +5 -0
  87. package/dist/gamepadInput.d.ts +4 -0
  88. package/dist/gamepadInput.js +281 -0
  89. package/dist/gamepadKeys.d.ts +4 -0
  90. package/dist/gamepadKeys.js +205 -0
  91. package/dist/gamepadTypes.d.ts +134 -0
  92. package/dist/gamepadTypes.js +3 -0
  93. package/dist/hover.d.ts +4 -0
  94. package/dist/hover.js +4 -0
  95. package/dist/hoverInput.d.ts +8 -0
  96. package/dist/hoverInput.js +503 -0
  97. package/dist/hoverInputTypes.d.ts +119 -0
  98. package/dist/hoverInputTypes.js +2 -0
  99. package/dist/index.d.ts +49 -0
  100. package/dist/index.js +20 -0
  101. package/dist/input.d.ts +6 -0
  102. package/dist/input.js +5 -0
  103. package/dist/inputActions.d.ts +81 -0
  104. package/dist/inputActions.js +330 -0
  105. package/dist/internal/contentFactoryState.d.ts +19 -0
  106. package/dist/internal/contentFactoryState.js +42 -0
  107. package/dist/internal/mouseInputFactoryState.d.ts +57 -0
  108. package/dist/internal/mouseInputFactoryState.js +125 -0
  109. package/dist/internal/sequenceControllerFactoryState.d.ts +42 -0
  110. package/dist/internal/sequenceControllerFactoryState.js +98 -0
  111. package/dist/internal/textFieldFactoryState.d.ts +11 -0
  112. package/dist/internal/textFieldFactoryState.js +32 -0
  113. package/dist/internal/texturedFrameState.d.ts +4 -0
  114. package/dist/internal/texturedFrameState.js +12 -0
  115. package/dist/internal/uiFactoryState.d.ts +64 -0
  116. package/dist/internal/uiFactoryState.js +157 -0
  117. package/dist/internal/uiRootState.d.ts +67 -0
  118. package/dist/internal/uiRootState.js +103 -0
  119. package/dist/keyboardInput.d.ts +12 -0
  120. package/dist/keyboardInput.js +578 -0
  121. package/dist/keyboardInputTypes.d.ts +81 -0
  122. package/dist/keyboardInputTypes.js +2 -0
  123. package/dist/kit.d.ts +14 -0
  124. package/dist/kit.js +9 -0
  125. package/dist/layout.d.ts +5 -0
  126. package/dist/layout.js +132 -0
  127. package/dist/layoutTypes.d.ts +28 -0
  128. package/dist/layoutTypes.js +2 -0
  129. package/dist/manifestAssetGroup.d.ts +10 -0
  130. package/dist/manifestAssetGroup.js +477 -0
  131. package/dist/manifestResourceState.d.ts +16 -0
  132. package/dist/manifestResourceState.js +57 -0
  133. package/dist/manifestResourceTypes.d.ts +25 -0
  134. package/dist/manifestResourceTypes.js +2 -0
  135. package/dist/motion.d.ts +33 -0
  136. package/dist/motion.js +206 -0
  137. package/dist/mouseInput.d.ts +102 -0
  138. package/dist/mouseInput.js +562 -0
  139. package/dist/mouseInputTypes.d.ts +37 -0
  140. package/dist/mouseInputTypes.js +2 -0
  141. package/dist/paragraph.d.ts +8 -0
  142. package/dist/paragraph.js +7 -0
  143. package/dist/particleEmitter.d.ts +4 -0
  144. package/dist/particleEmitter.js +292 -0
  145. package/dist/particleTypes.d.ts +107 -0
  146. package/dist/particleTypes.js +2 -0
  147. package/dist/particles.d.ts +4 -0
  148. package/dist/particles.js +4 -0
  149. package/dist/physics2d.d.ts +4 -0
  150. package/dist/physics2d.js +4 -0
  151. package/dist/physics2dGeometry.d.ts +39 -0
  152. package/dist/physics2dGeometry.js +230 -0
  153. package/dist/physics2dTypes.d.ts +167 -0
  154. package/dist/physics2dTypes.js +2 -0
  155. package/dist/physics2dWorld.d.ts +4 -0
  156. package/dist/physics2dWorld.js +623 -0
  157. package/dist/pointerInput.d.ts +11 -0
  158. package/dist/pointerInput.js +299 -0
  159. package/dist/pointerInputTypes.d.ts +38 -0
  160. package/dist/pointerInputTypes.js +2 -0
  161. package/dist/random.d.ts +29 -0
  162. package/dist/random.js +131 -0
  163. package/dist/rendering/ownedPreparationFailure2D.d.ts +5 -0
  164. package/dist/rendering/ownedPreparationFailure2D.js +33 -0
  165. package/dist/rendering/packSharedDraws2D.d.ts +50 -0
  166. package/dist/rendering/packSharedDraws2D.js +331 -0
  167. package/dist/rendering/packedOrientation.d.ts +4 -0
  168. package/dist/rendering/packedOrientation.js +7 -0
  169. package/dist/rendering/prepareRectangles2D.d.ts +92 -0
  170. package/dist/rendering/prepareRectangles2D.js +481 -0
  171. package/dist/rendering/prepareSharedDraws2D.d.ts +88 -0
  172. package/dist/rendering/prepareSharedDraws2D.js +652 -0
  173. package/dist/rendering/preparedBatches2D.d.ts +17 -0
  174. package/dist/rendering/preparedBatches2D.js +30 -0
  175. package/dist/rendering/preparedSharedBatches2D.d.ts +44 -0
  176. package/dist/rendering/preparedSharedBatches2D.js +247 -0
  177. package/dist/rendering/sharedColor2D.d.ts +18 -0
  178. package/dist/rendering/sharedColor2D.js +68 -0
  179. package/dist/rendering/sharedEffects2D.d.ts +23 -0
  180. package/dist/rendering/sharedEffects2D.js +118 -0
  181. package/dist/rendering/sharedPreparationRetention2D.d.ts +120 -0
  182. package/dist/rendering/sharedPreparationRetention2D.js +357 -0
  183. package/dist/rendering/srgbBytes.d.ts +3 -0
  184. package/dist/rendering/srgbBytes.js +64 -0
  185. package/dist/rendering/texturedPreparationBudget2D.d.ts +31 -0
  186. package/dist/rendering/texturedPreparationBudget2D.js +81 -0
  187. package/dist/rendering/world3d/Animation3D.d.ts +95 -0
  188. package/dist/rendering/world3d/Animation3D.js +380 -0
  189. package/dist/rendering/world3d/AnimationTexture3D.d.ts +157 -0
  190. package/dist/rendering/world3d/AnimationTexture3D.js +601 -0
  191. package/dist/rendering/world3d/Batch3D.d.ts +71 -0
  192. package/dist/rendering/world3d/Batch3D.js +329 -0
  193. package/dist/rendering/world3d/Camera3D.d.ts +57 -0
  194. package/dist/rendering/world3d/Camera3D.js +129 -0
  195. package/dist/rendering/world3d/Character3D.d.ts +123 -0
  196. package/dist/rendering/world3d/Character3D.js +303 -0
  197. package/dist/rendering/world3d/Cloth3D.d.ts +115 -0
  198. package/dist/rendering/world3d/Cloth3D.js +498 -0
  199. package/dist/rendering/world3d/Compression3D.d.ts +21 -0
  200. package/dist/rendering/world3d/Compression3D.js +702 -0
  201. package/dist/rendering/world3d/Curves3D.d.ts +111 -0
  202. package/dist/rendering/world3d/Curves3D.js +455 -0
  203. package/dist/rendering/world3d/Decal3D.d.ts +41 -0
  204. package/dist/rendering/world3d/Decal3D.js +241 -0
  205. package/dist/rendering/world3d/Geometry3D.d.ts +85 -0
  206. package/dist/rendering/world3d/Geometry3D.js +326 -0
  207. package/dist/rendering/world3d/GeometryBuilder3D.d.ts +51 -0
  208. package/dist/rendering/world3d/GeometryBuilder3D.js +196 -0
  209. package/dist/rendering/world3d/Gizmo3D.d.ts +75 -0
  210. package/dist/rendering/world3d/Gizmo3D.js +512 -0
  211. package/dist/rendering/world3d/Gltf3D.d.ts +67 -0
  212. package/dist/rendering/world3d/Gltf3D.js +976 -0
  213. package/dist/rendering/world3d/GpuParticles3D.d.ts +107 -0
  214. package/dist/rendering/world3d/GpuParticles3D.js +400 -0
  215. package/dist/rendering/world3d/Hdr3D.d.ts +33 -0
  216. package/dist/rendering/world3d/Hdr3D.js +190 -0
  217. package/dist/rendering/world3d/Jelly3D.d.ts +75 -0
  218. package/dist/rendering/world3d/Jelly3D.js +266 -0
  219. package/dist/rendering/world3d/Ktx23D.d.ts +27 -0
  220. package/dist/rendering/world3d/Ktx23D.js +112 -0
  221. package/dist/rendering/world3d/Light3D.d.ts +75 -0
  222. package/dist/rendering/world3d/Light3D.js +93 -0
  223. package/dist/rendering/world3d/Material3D.d.ts +243 -0
  224. package/dist/rendering/world3d/Material3D.js +267 -0
  225. package/dist/rendering/world3d/Mesh3D.d.ts +108 -0
  226. package/dist/rendering/world3d/Mesh3D.js +323 -0
  227. package/dist/rendering/world3d/Meshopt3D.d.ts +12 -0
  228. package/dist/rendering/world3d/Meshopt3D.js +275 -0
  229. package/dist/rendering/world3d/Navigation3D.d.ts +173 -0
  230. package/dist/rendering/world3d/Navigation3D.js +971 -0
  231. package/dist/rendering/world3d/Object3D.d.ts +107 -0
  232. package/dist/rendering/world3d/Object3D.js +305 -0
  233. package/dist/rendering/world3d/Particles3D.d.ts +85 -0
  234. package/dist/rendering/world3d/Particles3D.js +274 -0
  235. package/dist/rendering/world3d/Physics3D.d.ts +416 -0
  236. package/dist/rendering/world3d/Physics3D.js +2835 -0
  237. package/dist/rendering/world3d/PhysicsHull3D.d.ts +35 -0
  238. package/dist/rendering/world3d/PhysicsHull3D.js +227 -0
  239. package/dist/rendering/world3d/PhysicsMesh3D.d.ts +39 -0
  240. package/dist/rendering/world3d/PhysicsMesh3D.js +338 -0
  241. package/dist/rendering/world3d/PhysicsQueries3D.d.ts +24 -0
  242. package/dist/rendering/world3d/PhysicsQueries3D.js +323 -0
  243. package/dist/rendering/world3d/PhysicsRemote3D.d.ts +174 -0
  244. package/dist/rendering/world3d/PhysicsRemote3D.js +534 -0
  245. package/dist/rendering/world3d/Ragdoll3D.d.ts +69 -0
  246. package/dist/rendering/world3d/Ragdoll3D.js +200 -0
  247. package/dist/rendering/world3d/Raycast3D.d.ts +37 -0
  248. package/dist/rendering/world3d/Raycast3D.js +246 -0
  249. package/dist/rendering/world3d/RenderList3D.d.ts +88 -0
  250. package/dist/rendering/world3d/RenderList3D.js +490 -0
  251. package/dist/rendering/world3d/Retarget3D.d.ts +20 -0
  252. package/dist/rendering/world3d/Retarget3D.js +185 -0
  253. package/dist/rendering/world3d/Serialize3D.d.ts +49 -0
  254. package/dist/rendering/world3d/Serialize3D.js +607 -0
  255. package/dist/rendering/world3d/StateMachine3D.d.ts +78 -0
  256. package/dist/rendering/world3d/StateMachine3D.js +277 -0
  257. package/dist/rendering/world3d/Terrain3D.d.ts +227 -0
  258. package/dist/rendering/world3d/Terrain3D.js +803 -0
  259. package/dist/rendering/world3d/Text3D.d.ts +90 -0
  260. package/dist/rendering/world3d/Text3D.js +558 -0
  261. package/dist/rendering/world3d/Texture3D.d.ts +133 -0
  262. package/dist/rendering/world3d/Texture3D.js +252 -0
  263. package/dist/rendering/world3d/Trail3D.d.ts +59 -0
  264. package/dist/rendering/world3d/Trail3D.js +193 -0
  265. package/dist/rendering/world3d/Vehicle3D.d.ts +97 -0
  266. package/dist/rendering/world3d/Vehicle3D.js +226 -0
  267. package/dist/rendering/world3d/VolumetricFog3D.d.ts +55 -0
  268. package/dist/rendering/world3d/VolumetricFog3D.js +229 -0
  269. package/dist/rendering/world3d/Water3D.d.ts +163 -0
  270. package/dist/rendering/world3d/Water3D.js +606 -0
  271. package/dist/rendering/world3d/core3D.d.ts +34 -0
  272. package/dist/rendering/world3d/core3D.js +99 -0
  273. package/dist/rendering/world3d/debug3D.d.ts +64 -0
  274. package/dist/rendering/world3d/debug3D.js +257 -0
  275. package/dist/rendering/world3d/decoders3D.d.ts +42 -0
  276. package/dist/rendering/world3d/decoders3D.js +133 -0
  277. package/dist/rendering/world3d/geometries3D.d.ts +99 -0
  278. package/dist/rendering/world3d/geometries3D.js +605 -0
  279. package/dist/rendering/world3d/helpers3D.d.ts +65 -0
  280. package/dist/rendering/world3d/helpers3D.js +177 -0
  281. package/dist/rendering/world3d/index.d.ts +91 -0
  282. package/dist/rendering/world3d/index.js +56 -0
  283. package/dist/rendering/world3d/math3D.d.ts +78 -0
  284. package/dist/rendering/world3d/math3D.js +640 -0
  285. package/dist/rendering/world3d/primitives3D.d.ts +60 -0
  286. package/dist/rendering/world3d/primitives3D.js +196 -0
  287. package/dist/resources.d.ts +8 -0
  288. package/dist/resources.js +6 -0
  289. package/dist/saveStore.d.ts +56 -0
  290. package/dist/saveStore.js +163 -0
  291. package/dist/semanticList.d.ts +122 -0
  292. package/dist/semanticList.js +174 -0
  293. package/dist/semanticTree.d.ts +10 -0
  294. package/dist/semanticTree.js +532 -0
  295. package/dist/semanticTypes.d.ts +167 -0
  296. package/dist/semanticTypes.js +2 -0
  297. package/dist/semantics.d.ts +6 -0
  298. package/dist/semantics.js +5 -0
  299. package/dist/sequencePlayback.d.ts +19 -0
  300. package/dist/sequencePlayback.js +391 -0
  301. package/dist/sequencePlaybackTypes.d.ts +21 -0
  302. package/dist/sequencePlaybackTypes.js +2 -0
  303. package/dist/sequenceTargetClaims.d.ts +10 -0
  304. package/dist/sequenceTargetClaims.js +31 -0
  305. package/dist/srgbBytes.d.ts +3 -0
  306. package/dist/srgbBytes.js +64 -0
  307. package/dist/startEngine.d.ts +5 -0
  308. package/dist/startEngine.js +31 -0
  309. package/dist/surfaceOwnership.d.ts +3 -0
  310. package/dist/surfaceOwnership.js +15 -0
  311. package/dist/text.d.ts +23 -0
  312. package/dist/text.js +4 -0
  313. package/dist/textField.d.ts +6 -0
  314. package/dist/textField.js +6 -0
  315. package/dist/tileMapDraw.d.ts +7 -0
  316. package/dist/tileMapDraw.js +310 -0
  317. package/dist/tiledImport.d.ts +9 -0
  318. package/dist/tiledImport.js +357 -0
  319. package/dist/tilemap.d.ts +5 -0
  320. package/dist/tilemap.js +5 -0
  321. package/dist/tilemapTypes.d.ts +169 -0
  322. package/dist/tilemapTypes.js +2 -0
  323. package/dist/tween.d.ts +15 -0
  324. package/dist/tween.js +329 -0
  325. package/dist/tweenTypes.d.ts +27 -0
  326. package/dist/tweenTypes.js +2 -0
  327. package/dist/ui/controlKeys.d.ts +109 -0
  328. package/dist/ui/controlKeys.js +249 -0
  329. package/dist/ui/controls.d.ts +52 -0
  330. package/dist/ui/controls.js +288 -0
  331. package/dist/ui/editing.d.ts +3 -0
  332. package/dist/ui/editing.js +3 -0
  333. package/dist/ui/index.d.ts +19 -0
  334. package/dist/ui/index.js +11 -0
  335. package/dist/ui/keyboardFocus.d.ts +32 -0
  336. package/dist/ui/keyboardFocus.js +146 -0
  337. package/dist/ui/layerTypes.d.ts +91 -0
  338. package/dist/ui/layerTypes.js +2 -0
  339. package/dist/ui/layers.d.ts +4 -0
  340. package/dist/ui/layers.js +586 -0
  341. package/dist/ui/leafContent.d.ts +21 -0
  342. package/dist/ui/leafContent.js +136 -0
  343. package/dist/ui/rangeControl.d.ts +50 -0
  344. package/dist/ui/rangeControl.js +167 -0
  345. package/dist/ui/scrollControl.d.ts +72 -0
  346. package/dist/ui/scrollControl.js +218 -0
  347. package/dist/ui/stateControls.d.ts +82 -0
  348. package/dist/ui/stateControls.js +328 -0
  349. package/dist/ui/textEditor.d.ts +53 -0
  350. package/dist/ui/textEditor.js +370 -0
  351. package/dist/ui/textEditorTypes.d.ts +78 -0
  352. package/dist/ui/textEditorTypes.js +2 -0
  353. package/dist/ui/textFieldControl.d.ts +96 -0
  354. package/dist/ui/textFieldControl.js +259 -0
  355. package/dist/ui/theme.d.ts +59 -0
  356. package/dist/ui/theme.js +165 -0
  357. package/dist/ui/types.d.ts +265 -0
  358. package/dist/ui/types.js +2 -0
  359. package/dist/ui/uiRoot.d.ts +4 -0
  360. package/dist/ui/uiRoot.js +1497 -0
  361. package/dist/ui/uiRootDisplay.d.ts +46 -0
  362. package/dist/ui/uiRootDisplay.js +148 -0
  363. package/dist/ui/uiRootModel.d.ts +112 -0
  364. package/dist/ui/uiRootModel.js +60 -0
  365. package/dist/ui/virtualList.d.ts +20 -0
  366. package/dist/ui/virtualList.js +105 -0
  367. package/dist/video.d.ts +4 -0
  368. package/dist/video.js +4 -0
  369. package/dist/videoPlayer.d.ts +4 -0
  370. package/dist/videoPlayer.js +215 -0
  371. package/dist/videoTypes.d.ts +74 -0
  372. package/dist/videoTypes.js +2 -0
  373. package/dist/web/BrowserAssetBundle.d.ts +39 -0
  374. package/dist/web/BrowserAssetBundle.js +136 -0
  375. package/dist/web/BrowserAudio.d.ts +41 -0
  376. package/dist/web/BrowserAudio.js +473 -0
  377. package/dist/web/BrowserFrameLoop.d.ts +65 -0
  378. package/dist/web/BrowserFrameLoop.js +125 -0
  379. package/dist/web/BrowserGame.d.ts +112 -0
  380. package/dist/web/BrowserGame.js +352 -0
  381. package/dist/web/BrowserGamepadInput.d.ts +35 -0
  382. package/dist/web/BrowserGamepadInput.js +134 -0
  383. package/dist/web/BrowserHoverInput.d.ts +24 -0
  384. package/dist/web/BrowserHoverInput.js +266 -0
  385. package/dist/web/BrowserImageTextures.d.ts +66 -0
  386. package/dist/web/BrowserImageTextures.js +169 -0
  387. package/dist/web/BrowserInputActions.d.ts +53 -0
  388. package/dist/web/BrowserInputActions.js +342 -0
  389. package/dist/web/BrowserKeyboardInput.d.ts +4 -0
  390. package/dist/web/BrowserKeyboardInput.js +223 -0
  391. package/dist/web/BrowserPlay.d.ts +289 -0
  392. package/dist/web/BrowserPlay.js +1301 -0
  393. package/dist/web/BrowserPointerInput.d.ts +4 -0
  394. package/dist/web/BrowserPointerInput.js +511 -0
  395. package/dist/web/BrowserSemantics.d.ts +34 -0
  396. package/dist/web/BrowserSemantics.js +418 -0
  397. package/dist/web/BrowserStatsPanel.d.ts +46 -0
  398. package/dist/web/BrowserStatsPanel.js +137 -0
  399. package/dist/web/BrowserStorage.d.ts +33 -0
  400. package/dist/web/BrowserStorage.js +132 -0
  401. package/dist/web/BrowserTextEditor.d.ts +49 -0
  402. package/dist/web/BrowserTextEditor.js +839 -0
  403. package/dist/web/BrowserTextInput.d.ts +83 -0
  404. package/dist/web/BrowserTextInput.js +524 -0
  405. package/dist/web/BrowserTextureProvider.d.ts +52 -0
  406. package/dist/web/BrowserTextureProvider.js +935 -0
  407. package/dist/web/BrowserVideo.d.ts +28 -0
  408. package/dist/web/BrowserVideo.js +211 -0
  409. package/dist/web/CanvasKitFontSetProvider.d.ts +29 -0
  410. package/dist/web/CanvasKitFontSetProvider.js +215 -0
  411. package/dist/web/CanvasKitParagraphProvider.d.ts +169 -0
  412. package/dist/web/CanvasKitParagraphProvider.js +691 -0
  413. package/dist/web/CanvasTextRasterProvider.d.ts +4 -0
  414. package/dist/web/CanvasTextRasterProvider.js +312 -0
  415. package/dist/web/ManifestByteSource.d.ts +147 -0
  416. package/dist/web/ManifestByteSource.js +974 -0
  417. package/dist/web/ManifestFontContentLoader.d.ts +12 -0
  418. package/dist/web/ManifestFontContentLoader.js +30 -0
  419. package/dist/web/MouseInput.d.ts +4 -0
  420. package/dist/web/MouseInput.js +218 -0
  421. package/dist/web/WebGL2Host.d.ts +5 -0
  422. package/dist/web/WebGL2Host.js +2672 -0
  423. package/dist/web/WebGPUHost.d.ts +87 -0
  424. package/dist/web/WebGPUHost.js +3349 -0
  425. package/dist/web/audio.d.ts +3 -0
  426. package/dist/web/audio.js +4 -0
  427. package/dist/web/canvasKitParagraphGeometry.d.ts +27 -0
  428. package/dist/web/canvasKitParagraphGeometry.js +83 -0
  429. package/dist/web/editing.d.ts +5 -0
  430. package/dist/web/editing.js +4 -0
  431. package/dist/web/editorFonts.d.ts +50 -0
  432. package/dist/web/editorFonts.js +297 -0
  433. package/dist/web/game.d.ts +5 -0
  434. package/dist/web/game.js +6 -0
  435. package/dist/web/gamepad.d.ts +3 -0
  436. package/dist/web/gamepad.js +4 -0
  437. package/dist/web/hover.d.ts +3 -0
  438. package/dist/web/hover.js +4 -0
  439. package/dist/web/image.d.ts +4 -0
  440. package/dist/web/image.js +4 -0
  441. package/dist/web/imageProjections2D.d.ts +14 -0
  442. package/dist/web/imageProjections2D.js +2 -0
  443. package/dist/web/input.d.ts +6 -0
  444. package/dist/web/input.js +4 -0
  445. package/dist/web/keyboard.d.ts +3 -0
  446. package/dist/web/keyboard.js +3 -0
  447. package/dist/web/kit.d.ts +10 -0
  448. package/dist/web/kit.js +7 -0
  449. package/dist/web/loop.d.ts +3 -0
  450. package/dist/web/loop.js +4 -0
  451. package/dist/web/paragraph.d.ts +6 -0
  452. package/dist/web/paragraph.js +4 -0
  453. package/dist/web/play.d.ts +5 -0
  454. package/dist/web/play.js +6 -0
  455. package/dist/web/playSfx.d.ts +36 -0
  456. package/dist/web/playSfx.js +112 -0
  457. package/dist/web/pointer.d.ts +3 -0
  458. package/dist/web/pointer.js +3 -0
  459. package/dist/web/prepareSharedSubmission2D.d.ts +27 -0
  460. package/dist/web/prepareSharedSubmission2D.js +57 -0
  461. package/dist/web/resources.d.ts +27 -0
  462. package/dist/web/resources.js +96 -0
  463. package/dist/web/semantics.d.ts +3 -0
  464. package/dist/web/semantics.js +4 -0
  465. package/dist/web/sharedDeviceSession.d.ts +64 -0
  466. package/dist/web/sharedDeviceSession.js +2 -0
  467. package/dist/web/sharedEffectShaders.d.ts +9 -0
  468. package/dist/web/sharedEffectShaders.js +165 -0
  469. package/dist/web/sharedFrameUpload.d.ts +25 -0
  470. package/dist/web/sharedFrameUpload.js +2 -0
  471. package/dist/web/sharedHostDeferred.d.ts +7 -0
  472. package/dist/web/sharedHostDeferred.js +12 -0
  473. package/dist/web/sharedRetentionLedger.d.ts +85 -0
  474. package/dist/web/sharedRetentionLedger.js +391 -0
  475. package/dist/web/sharedSubmissionStorage2D.d.ts +56 -0
  476. package/dist/web/sharedSubmissionStorage2D.js +73 -0
  477. package/dist/web/sharedWebGL2Arena.d.ts +40 -0
  478. package/dist/web/sharedWebGL2Arena.js +77 -0
  479. package/dist/web/sharedWebGL2Options.d.ts +30 -0
  480. package/dist/web/sharedWebGL2Options.js +96 -0
  481. package/dist/web/sharedWebGL2Shaders.d.ts +20 -0
  482. package/dist/web/sharedWebGL2Shaders.js +314 -0
  483. package/dist/web/sharedWebGPUOptions.d.ts +37 -0
  484. package/dist/web/sharedWebGPUOptions.js +126 -0
  485. package/dist/web/text.d.ts +3 -0
  486. package/dist/web/text.js +3 -0
  487. package/dist/web/textInput.d.ts +3 -0
  488. package/dist/web/textInput.js +3 -0
  489. package/dist/web/video.d.ts +3 -0
  490. package/dist/web/video.js +4 -0
  491. package/dist/web/webgl2.d.ts +7 -0
  492. package/dist/web/webgl2.js +4 -0
  493. package/dist/web/webgl2LayerState.d.ts +50 -0
  494. package/dist/web/webgl2LayerState.js +102 -0
  495. package/dist/web/webgl2Native.d.ts +70 -0
  496. package/dist/web/webgl2Native.js +568 -0
  497. package/dist/web/webgl2Types.d.ts +132 -0
  498. package/dist/web/webgl2Types.js +2 -0
  499. package/dist/web/webgpu.d.ts +6 -0
  500. package/dist/web/webgpu.js +2 -0
  501. package/dist/web/webgpuBindingCache.d.ts +26 -0
  502. package/dist/web/webgpuBindingCache.js +223 -0
  503. package/dist/web/webgpuBufferPool.d.ts +51 -0
  504. package/dist/web/webgpuBufferPool.js +58 -0
  505. package/dist/web/webgpuImageResidency.d.ts +53 -0
  506. package/dist/web/webgpuImageResidency.js +61 -0
  507. package/dist/web/webgpuLifetime.d.ts +45 -0
  508. package/dist/web/webgpuLifetime.js +64 -0
  509. package/dist/web/webgpuRetentionPool.d.ts +66 -0
  510. package/dist/web/webgpuRetentionPool.js +84 -0
  511. package/dist/web/webgpuSharedPass.d.ts +7 -0
  512. package/dist/web/webgpuSharedPass.js +211 -0
  513. package/dist/web/webgpuSharedResolvePass.d.ts +3 -0
  514. package/dist/web/webgpuSharedResolvePass.js +29 -0
  515. package/dist/web/world3d/Audio3D.d.ts +68 -0
  516. package/dist/web/world3d/Audio3D.js +212 -0
  517. package/dist/web/world3d/BrowserPlay3D.d.ts +182 -0
  518. package/dist/web/world3d/BrowserPlay3D.js +851 -0
  519. package/dist/web/world3d/FlyControls3D.d.ts +55 -0
  520. package/dist/web/world3d/FlyControls3D.js +160 -0
  521. package/dist/web/world3d/FollowControls3D.d.ts +28 -0
  522. package/dist/web/world3d/FollowControls3D.js +117 -0
  523. package/dist/web/world3d/OrbitControls3D.d.ts +55 -0
  524. package/dist/web/world3d/OrbitControls3D.js +187 -0
  525. package/dist/web/world3d/TransformControls3D.d.ts +34 -0
  526. package/dist/web/world3d/TransformControls3D.js +125 -0
  527. package/dist/web/world3d/WebGL2Renderer3D.d.ts +133 -0
  528. package/dist/web/world3d/WebGL2Renderer3D.js +1173 -0
  529. package/dist/web/world3d/WebGPURenderer3D.d.ts +110 -0
  530. package/dist/web/world3d/WebGPURenderer3D.js +1915 -0
  531. package/dist/web/world3d/World3DView.d.ts +51 -0
  532. package/dist/web/world3d/World3DView.js +77 -0
  533. package/dist/web/world3d/app3D.d.ts +136 -0
  534. package/dist/web/world3d/app3D.js +304 -0
  535. package/dist/web/world3d/assets3D.d.ts +38 -0
  536. package/dist/web/world3d/assets3D.js +112 -0
  537. package/dist/web/world3d/atmosphere3D.d.ts +47 -0
  538. package/dist/web/world3d/atmosphere3D.js +178 -0
  539. package/dist/web/world3d/frame3D.d.ts +142 -0
  540. package/dist/web/world3d/frame3D.js +388 -0
  541. package/dist/web/world3d/gpuResources3D.d.ts +98 -0
  542. package/dist/web/world3d/gpuResources3D.js +901 -0
  543. package/dist/web/world3d/host3D.d.ts +23 -0
  544. package/dist/web/world3d/host3D.js +61 -0
  545. package/dist/web/world3d/index.d.ts +38 -0
  546. package/dist/web/world3d/index.js +23 -0
  547. package/dist/web/world3d/loaders3D.d.ts +26 -0
  548. package/dist/web/world3d/loaders3D.js +138 -0
  549. package/dist/web/world3d/markers3D.d.ts +49 -0
  550. package/dist/web/world3d/markers3D.js +130 -0
  551. package/dist/web/world3d/materialWebGL23D.d.ts +34 -0
  552. package/dist/web/world3d/materialWebGL23D.js +218 -0
  553. package/dist/web/world3d/overlay3D.d.ts +28 -0
  554. package/dist/web/world3d/overlay3D.js +170 -0
  555. package/dist/web/world3d/post3D.d.ts +112 -0
  556. package/dist/web/world3d/post3D.js +459 -0
  557. package/dist/web/world3d/postWebGL23D.d.ts +24 -0
  558. package/dist/web/world3d/postWebGL23D.js +237 -0
  559. package/dist/web/world3d/postWebGPU3D.d.ts +23 -0
  560. package/dist/web/world3d/postWebGPU3D.js +255 -0
  561. package/dist/web/world3d/probe3D.d.ts +14 -0
  562. package/dist/web/world3d/probe3D.js +66 -0
  563. package/dist/web/world3d/shaders3D.d.ts +43 -0
  564. package/dist/web/world3d/shaders3D.js +851 -0
  565. package/dist/web/world3d/stats3D.d.ts +31 -0
  566. package/dist/web/world3d/stats3D.js +80 -0
  567. package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +66 -0
  568. package/dist/web/world3d/webGL2FrameMetrics3D.js +185 -0
  569. package/dist/web/world3d/webgpu.d.ts +35 -0
  570. package/dist/web/world3d/webgpu.js +22 -0
  571. package/dist/web/world3d/webgpuPacking3D.d.ts +13 -0
  572. package/dist/web/world3d/webgpuPacking3D.js +85 -0
  573. package/dist/web/world3d/wgsl3D.d.ts +68 -0
  574. package/dist/web/world3d/wgsl3D.js +781 -0
  575. package/package.json +220 -4
@@ -0,0 +1,785 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { EgretError } from '@egret/runtime';
3
+ const MIB = 1024 * 1024;
4
+ const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
5
+ const within = (value, least, most) => typeof value === 'number' && value >= least && value <= most;
6
+ const whole = (value, least, most) => Number.isSafeInteger(value) && within(value, least, most);
7
+ const named = (value) => typeof value === 'string' && value.length > 0 && value.length <= 32;
8
+ const callable = (value, keys) => record(value) && keys.every(key => typeof value[key] === 'function');
9
+ /**
10
+ * Volumes, voices and one music over a backend that makes the sound. It keeps no clock of its own
11
+ * and starts no work: a fade is a line the backend follows, and the end of a voice is told by it.
12
+ */
13
+ export function createAudioMixer(options) {
14
+ if (!record(options))
15
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
16
+ const { backend, buses: busOptions = ['music', 'effects'], volume = 1, muted = false, locked: startLocked = false, maxVoices = 32, maxSounds = 256, maxDecodedBytes = 128 * MIB } = options;
17
+ if (!callable(backend, ['decode', 'createBus', 'start', 'suspend', 'resume', 'close']) ||
18
+ !Array.isArray(busOptions) ||
19
+ busOptions.length < 1 ||
20
+ busOptions.length > 16 ||
21
+ !within(volume, 0, 1) ||
22
+ typeof muted !== 'boolean' ||
23
+ typeof startLocked !== 'boolean' ||
24
+ !whole(maxVoices, 1, 256) ||
25
+ !whole(maxSounds, 1, 4096) ||
26
+ !whole(maxDecodedBytes, 1, Number.MAX_SAFE_INTEGER))
27
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
28
+ const wanted = [];
29
+ for (const item of busOptions) {
30
+ const bus = typeof item === 'string' ? { name: item } : item;
31
+ if (!record(bus))
32
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
33
+ const { name, volume: level = 1, muted: quiet = false } = bus;
34
+ if (!named(name) ||
35
+ name === 'master' ||
36
+ wanted.some(other => other.name === name) ||
37
+ !within(level, 0, 1) ||
38
+ typeof quiet !== 'boolean')
39
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
40
+ wanted.push({ name, volume: level, muted: quiet });
41
+ }
42
+ /** The backend is the host's: what it throws is told as one code, with the cause kept. */
43
+ function guard(action) {
44
+ try {
45
+ return action();
46
+ }
47
+ catch (cause) {
48
+ throw new EgretError('AUDIO_BACKEND_FAILED', { cause });
49
+ }
50
+ }
51
+ function now() {
52
+ const value = guard(() => backend.time);
53
+ if (!within(value, 0, Number.MAX_VALUE))
54
+ throw new EgretError('AUDIO_BACKEND_FAILED');
55
+ return value;
56
+ }
57
+ function fadeOf(value) {
58
+ if (value === undefined)
59
+ return 0;
60
+ if (!record(value))
61
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
62
+ const fade = value['fade'] ?? 0;
63
+ if (!within(fade, 0, 60))
64
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
65
+ return fade;
66
+ }
67
+ const voices = new Set();
68
+ const sounds = new Set();
69
+ const known = new WeakMap();
70
+ const listeners = new Set();
71
+ const suspendedBy = [];
72
+ const dropped = { silent: 0, limit: 0, stolen: 0 };
73
+ let closed = false, locked = startLocked, decoding = 0, decodedBytes = 0, started = 0, ids = 0;
74
+ let music;
75
+ function makeBus(name, level, quiet, parent) {
76
+ const raw = guard(() => backend.createBus(parent));
77
+ if (!callable(raw, ['setGain', 'release']))
78
+ throw new EgretError('AUDIO_BACKEND_FAILED');
79
+ const apply = (seconds) => {
80
+ guard(() => raw.setGain(bus.muted ? 0 : bus.volume, seconds));
81
+ };
82
+ const bus = {
83
+ name,
84
+ volume: level,
85
+ muted: quiet,
86
+ voices: 0,
87
+ backend: raw,
88
+ face: Object.freeze({
89
+ name,
90
+ get volume() {
91
+ return bus.volume;
92
+ },
93
+ get muted() {
94
+ return bus.muted;
95
+ },
96
+ get voices() {
97
+ return name === 'master' ? voices.size : bus.voices;
98
+ },
99
+ setVolume(value, fade) {
100
+ const seconds = fadeOf(fade);
101
+ if (!within(value, 0, 1))
102
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
103
+ if (closed)
104
+ return;
105
+ bus.volume = value;
106
+ apply(seconds);
107
+ },
108
+ setMuted(value) {
109
+ if (typeof value !== 'boolean')
110
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
111
+ if (closed)
112
+ return;
113
+ bus.muted = value;
114
+ apply(0);
115
+ }
116
+ })
117
+ };
118
+ try {
119
+ apply(0);
120
+ }
121
+ catch (cause) {
122
+ try {
123
+ raw.release();
124
+ }
125
+ catch {
126
+ /* the first failure is the one told */
127
+ }
128
+ throw cause;
129
+ }
130
+ return bus;
131
+ }
132
+ const master = makeBus('master', volume, muted, undefined);
133
+ const buses = [];
134
+ try {
135
+ for (const bus of wanted)
136
+ buses.push(makeBus(bus.name, bus.volume, bus.muted, master.backend));
137
+ }
138
+ catch (cause) {
139
+ for (const bus of [...buses, master])
140
+ try {
141
+ bus.backend.release();
142
+ }
143
+ catch {
144
+ /* the first failure is the one told */
145
+ }
146
+ throw cause;
147
+ }
148
+ const faces = Object.freeze(buses.map(bus => bus.face));
149
+ const fallback = (name) => buses.find(bus => bus.name === name) ?? buses[0];
150
+ const effects = fallback('effects'), melody = fallback('music');
151
+ function busOf(name) {
152
+ const bus = buses.find(candidate => candidate.name === name);
153
+ if (bus === undefined)
154
+ throw new EgretError('AUDIO_BUS_UNKNOWN');
155
+ return bus;
156
+ }
157
+ let told = current();
158
+ function current() {
159
+ return closed ? 'closed' : locked ? 'locked' : suspendedBy.length > 0 ? 'suspended' : 'running';
160
+ }
161
+ /** Every listener is told, whatever an earlier one did. The first failure is thrown afterwards. */
162
+ function announce() {
163
+ const next = current();
164
+ if (next === told)
165
+ return;
166
+ told = next;
167
+ const failures = [];
168
+ for (const listener of [...listeners]) {
169
+ if (!listeners.has(listener))
170
+ continue;
171
+ try {
172
+ listener(next);
173
+ }
174
+ catch (cause) {
175
+ failures.push(cause);
176
+ }
177
+ }
178
+ if (failures.length > 0)
179
+ throw new EgretError('AUDIO_LISTENER_FAILED', { cause: failures[0], cleanupErrors: failures.slice(1) });
180
+ }
181
+ function open() {
182
+ if (closed)
183
+ throw new EgretError('AUDIO_CLOSED');
184
+ }
185
+ function positionOf(voice) {
186
+ const raw = voice.backend;
187
+ if (raw === undefined)
188
+ return voice.anchorPosition;
189
+ const duration = voice.sound.backend.duration;
190
+ if (typeof raw.position === 'function') {
191
+ // A host that reads the sound as it plays knows the place itself.
192
+ const place = guard(() => raw.position());
193
+ if (!within(place, 0, Number.MAX_VALUE))
194
+ throw new EgretError('AUDIO_BACKEND_FAILED');
195
+ return Math.min(place, duration);
196
+ }
197
+ const place = voice.anchorPosition + Math.max(0, now() - voice.anchorTime) * voice.rate;
198
+ return voice.loop ? place % duration : Math.min(place, duration);
199
+ }
200
+ /** The one place a voice ends. The host is asked to silence it only after the mixer has let go of it. */
201
+ function end(voice, reason, halt) {
202
+ if (voice.state === 'ended')
203
+ return;
204
+ const raw = voice.backend;
205
+ if (reason === 'finished')
206
+ voice.anchorPosition = voice.sound.backend.duration;
207
+ else
208
+ try {
209
+ voice.anchorPosition = positionOf(voice);
210
+ }
211
+ catch {
212
+ /* the last position known stays */
213
+ }
214
+ voice.state = 'ended';
215
+ voice.reason = reason;
216
+ voice.backend = undefined;
217
+ voice.token = undefined;
218
+ if (voices.delete(voice)) {
219
+ voice.sound.voices.delete(voice);
220
+ voice.bus.voices--;
221
+ }
222
+ if (music === voice)
223
+ music = undefined;
224
+ if (reason === 'silent' || reason === 'limit' || reason === 'stolen')
225
+ dropped[reason]++;
226
+ const settle = voice.settle;
227
+ voice.settle = undefined;
228
+ settle?.(reason);
229
+ if (halt && raw !== undefined)
230
+ guard(() => {
231
+ raw.stop(0);
232
+ });
233
+ }
234
+ function launch(voice, offset, fadeIn) {
235
+ const at = now(), token = {};
236
+ voice.token = token;
237
+ let raw;
238
+ try {
239
+ raw = guard(() => backend.start(Object.freeze({
240
+ sound: voice.sound.backend,
241
+ bus: voice.bus.backend,
242
+ offset,
243
+ loop: voice.loop,
244
+ rate: voice.rate,
245
+ gain: voice.volume,
246
+ pan: voice.pan,
247
+ fadeIn
248
+ }), () => {
249
+ if (voice.token === token)
250
+ end(voice, voice.state === 'stopping' ? 'stopped' : 'finished', false);
251
+ }));
252
+ if (!callable(raw, ['setGain', 'setRate', 'setPan', 'stop']))
253
+ throw new EgretError('AUDIO_BACKEND_FAILED');
254
+ }
255
+ catch (cause) {
256
+ if (voice.token === token)
257
+ voice.token = undefined;
258
+ throw cause;
259
+ }
260
+ // A host that told the end before it returned has nothing left to stop.
261
+ if (voice.token !== token)
262
+ return;
263
+ voice.backend = raw;
264
+ voice.anchorTime = at;
265
+ voice.anchorPosition = offset;
266
+ }
267
+ function stopVoice(voice, fade) {
268
+ if (voice.state === 'ended')
269
+ return;
270
+ const raw = voice.backend;
271
+ if (fade === 0 || raw === undefined) {
272
+ end(voice, 'stopped', true);
273
+ return;
274
+ }
275
+ if (voice.state === 'stopping')
276
+ return;
277
+ voice.state = 'stopping';
278
+ if (music === voice)
279
+ music = undefined;
280
+ try {
281
+ guard(() => {
282
+ raw.setGain(0, fade);
283
+ raw.stop(fade);
284
+ });
285
+ }
286
+ catch (cause) {
287
+ // A host that could not fade is not waited for.
288
+ try {
289
+ end(voice, 'stopped', true);
290
+ }
291
+ catch {
292
+ /* the first failure is the one told */
293
+ }
294
+ throw cause;
295
+ }
296
+ }
297
+ function faceOf(voice) {
298
+ return Object.freeze({
299
+ id: voice.id,
300
+ sound: voice.sound.face,
301
+ bus: voice.bus.name,
302
+ loop: voice.loop,
303
+ get state() {
304
+ return voice.state;
305
+ },
306
+ get endReason() {
307
+ return voice.reason;
308
+ },
309
+ get volume() {
310
+ return voice.volume;
311
+ },
312
+ get rate() {
313
+ return voice.rate;
314
+ },
315
+ get pan() {
316
+ return voice.pan;
317
+ },
318
+ get position() {
319
+ return positionOf(voice);
320
+ },
321
+ get ended() {
322
+ voice.promise ??=
323
+ voice.reason !== undefined
324
+ ? Promise.resolve(voice.reason)
325
+ : new Promise(resolve => {
326
+ voice.settle = resolve;
327
+ });
328
+ return voice.promise;
329
+ },
330
+ setVolume(value, fade) {
331
+ const seconds = fadeOf(fade);
332
+ if (!within(value, 0, 1))
333
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
334
+ if (voice.state === 'ended')
335
+ return;
336
+ voice.volume = value;
337
+ const raw = voice.backend;
338
+ if (raw !== undefined && voice.state === 'playing')
339
+ guard(() => {
340
+ raw.setGain(value, seconds);
341
+ });
342
+ },
343
+ setRate(value) {
344
+ if (!within(value, 0.25, 4))
345
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
346
+ if (voice.state === 'ended')
347
+ return;
348
+ const raw = voice.backend;
349
+ if (raw !== undefined) {
350
+ const position = positionOf(voice), at = now();
351
+ guard(() => {
352
+ raw.setRate(value);
353
+ });
354
+ voice.anchorPosition = position;
355
+ voice.anchorTime = at;
356
+ }
357
+ voice.rate = value;
358
+ },
359
+ setPan(value) {
360
+ if (!within(value, -1, 1))
361
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
362
+ if (voice.state === 'ended')
363
+ return;
364
+ const raw = voice.backend;
365
+ if (raw !== undefined)
366
+ guard(() => {
367
+ raw.setPan(value);
368
+ });
369
+ voice.pan = value;
370
+ },
371
+ pause() {
372
+ const raw = voice.backend;
373
+ if (voice.state !== 'playing' || raw === undefined)
374
+ return;
375
+ const position = positionOf(voice);
376
+ if (!voice.loop && position >= voice.sound.backend.duration) {
377
+ end(voice, 'finished', true);
378
+ return;
379
+ }
380
+ voice.state = 'paused';
381
+ voice.backend = undefined;
382
+ voice.token = undefined;
383
+ voice.anchorPosition = position;
384
+ guard(() => {
385
+ raw.stop(0);
386
+ });
387
+ },
388
+ resume() {
389
+ if (voice.state !== 'paused')
390
+ return;
391
+ launch(voice, voice.anchorPosition, 0);
392
+ if (voice.backend !== undefined)
393
+ voice.state = 'playing';
394
+ },
395
+ stop(fade) {
396
+ stopVoice(voice, fadeOf(fade));
397
+ }
398
+ });
399
+ }
400
+ function soundOf(value) {
401
+ const sound = record(value) ? known.get(value) : undefined;
402
+ if (sound === undefined)
403
+ throw new EgretError('AUDIO_SOUND_INVALID');
404
+ if (sound.released)
405
+ throw new EgretError('AUDIO_SOUND_RELEASED');
406
+ return sound;
407
+ }
408
+ function startOf(sound, value, forMusic) {
409
+ if (value !== undefined && !record(value))
410
+ throw new EgretError('AUDIO_PLAY_OPTIONS');
411
+ const given = value ?? {};
412
+ const pick = (key, otherwise) => (given[key] === undefined ? otherwise : given[key]);
413
+ const bus = given['bus'], level = pick('volume', 1), loop = pick('loop', forMusic), offset = pick('offset', 0), fadeIn = pick(forMusic ? 'fade' : 'fadeIn', 0);
414
+ // Music is one voice at its own speed in the middle; it waits for the output instead of being dropped.
415
+ const rate = forMusic ? 1 : pick('rate', 1), pan = forMusic ? 0 : pick('pan', 0), maxInstances = forMusic ? undefined : given['maxInstances'];
416
+ const whileSilent = forMusic ? 'start' : pick('whileSilent', 'drop'), restart = forMusic ? given['restart'] : undefined;
417
+ if ((bus !== undefined && typeof bus !== 'string') ||
418
+ !within(level, 0, 1) ||
419
+ !within(rate, 0.25, 4) ||
420
+ !within(pan, -1, 1) ||
421
+ typeof loop !== 'boolean' ||
422
+ !within(offset, 0, sound.backend.duration) ||
423
+ offset === sound.backend.duration ||
424
+ !within(fadeIn, 0, 60) ||
425
+ (maxInstances !== undefined && !whole(maxInstances, 1, 256)) ||
426
+ (whileSilent !== 'drop' && whileSilent !== 'start') ||
427
+ (restart !== undefined && typeof restart !== 'boolean'))
428
+ throw new EgretError('AUDIO_PLAY_OPTIONS');
429
+ return { bus, volume: level, rate, pan, loop, offset, fadeIn, maxInstances, whileSilent };
430
+ }
431
+ function start(sound, request, forMusic) {
432
+ const bus = request.bus === undefined ? (forMusic ? melody : effects) : busOf(request.bus);
433
+ const voice = {
434
+ id: ++ids,
435
+ sound,
436
+ bus,
437
+ loop: request.loop,
438
+ music: forMusic,
439
+ state: 'playing',
440
+ reason: undefined,
441
+ volume: request.volume,
442
+ rate: request.rate,
443
+ pan: request.pan,
444
+ backend: undefined,
445
+ token: undefined,
446
+ anchorTime: 0,
447
+ anchorPosition: request.offset,
448
+ promise: undefined,
449
+ settle: undefined,
450
+ face: undefined
451
+ };
452
+ voice.face = faceOf(voice);
453
+ if (request.whileSilent === 'drop' && current() !== 'running') {
454
+ end(voice, 'silent', false);
455
+ return voice;
456
+ }
457
+ // The oldest voice that may give its place: never the music, and a loop only to its own sound.
458
+ const victims = [];
459
+ // A stream has one place: whatever plays it gives way, the music too.
460
+ if (sound.backend.streamed === true)
461
+ victims.push(...sound.voices);
462
+ else if (request.maxInstances !== undefined) {
463
+ const own = [...sound.voices].filter(other => !other.music);
464
+ if (sound.voices.size >= request.maxInstances) {
465
+ const surplus = sound.voices.size - request.maxInstances + 1;
466
+ if (own.length < surplus) {
467
+ end(voice, 'limit', false);
468
+ return voice;
469
+ }
470
+ victims.push(...own.slice(0, surplus));
471
+ }
472
+ }
473
+ if (voices.size - victims.length >= maxVoices) {
474
+ const victim = [...voices].find(other => !other.music && !other.loop && !victims.includes(other));
475
+ if (victim === undefined) {
476
+ end(voice, 'limit', false);
477
+ return voice;
478
+ }
479
+ victims.push(victim);
480
+ }
481
+ const failures = [];
482
+ for (const victim of victims)
483
+ try {
484
+ end(victim, 'stolen', true);
485
+ }
486
+ catch (cause) {
487
+ failures.push(cause);
488
+ }
489
+ voices.add(voice);
490
+ sound.voices.add(voice);
491
+ bus.voices++;
492
+ try {
493
+ launch(voice, request.offset, request.fadeIn);
494
+ if (failures.length > 0)
495
+ throw failures[0];
496
+ }
497
+ catch (cause) {
498
+ // Nothing was started for the caller: the voice is not told as one that was dropped.
499
+ const raw = voice.backend;
500
+ voice.state = 'ended';
501
+ voice.reason = 'stopped';
502
+ voice.backend = undefined;
503
+ voice.token = undefined;
504
+ voices.delete(voice);
505
+ sound.voices.delete(voice);
506
+ bus.voices--;
507
+ if (raw !== undefined)
508
+ try {
509
+ raw.stop(0);
510
+ }
511
+ catch {
512
+ /* the first failure is the one told */
513
+ }
514
+ throw cause;
515
+ }
516
+ started++;
517
+ return voice;
518
+ }
519
+ /** What the backend gave is checked, counted and made a sound, or given back. */
520
+ function adopt(raw, streamed) {
521
+ const discard = (code) => {
522
+ const cleanupErrors = [];
523
+ if (record(raw) && typeof raw.release === 'function')
524
+ try {
525
+ raw.release();
526
+ }
527
+ catch (cause) {
528
+ cleanupErrors.push(cause);
529
+ }
530
+ throw new EgretError(code, { cleanupErrors });
531
+ };
532
+ if (!record(raw) ||
533
+ typeof raw.release !== 'function' ||
534
+ !within(raw.duration, Number.MIN_VALUE, 86400) ||
535
+ !whole(raw.channels, 1, 32) ||
536
+ !within(raw.sampleRate, 1, 768000) ||
537
+ (raw.streamed === true) !== streamed)
538
+ return discard('AUDIO_BACKEND_FAILED');
539
+ const size = streamed ? 0 : Math.ceil(raw.duration * raw.sampleRate) * raw.channels * 4;
540
+ if (closed)
541
+ return discard('AUDIO_CLOSED');
542
+ if (decodedBytes + size > maxDecodedBytes)
543
+ return discard('AUDIO_BUDGET');
544
+ const sound = {
545
+ backend: raw,
546
+ bytes: size,
547
+ voices: new Set(),
548
+ released: false,
549
+ face: Object.freeze({
550
+ duration: raw.duration,
551
+ channels: raw.channels,
552
+ sampleRate: raw.sampleRate,
553
+ decodedBytes: size,
554
+ streamed,
555
+ get state() {
556
+ return sound.released ? 'released' : 'ready';
557
+ },
558
+ release() {
559
+ if (sound.released)
560
+ return;
561
+ const failures = retire(sound, 'released');
562
+ if (failures.length > 0)
563
+ throw new EgretError('AUDIO_BACKEND_FAILED', { cause: failures[0], cleanupErrors: failures.slice(1) });
564
+ }
565
+ })
566
+ };
567
+ sounds.add(sound);
568
+ known.set(sound.face, sound);
569
+ decodedBytes += size;
570
+ return sound.face;
571
+ }
572
+ async function decode(bytes) {
573
+ open();
574
+ const view = bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes;
575
+ if (!(view instanceof Uint8Array) || view.byteLength === 0)
576
+ throw new EgretError('AUDIO_BYTES_INVALID');
577
+ if (sounds.size + decoding >= maxSounds)
578
+ throw new EgretError('AUDIO_SOUND_LIMIT');
579
+ decoding++;
580
+ let raw;
581
+ try {
582
+ raw = await backend.decode(view);
583
+ }
584
+ catch (cause) {
585
+ throw new EgretError('AUDIO_DECODE_FAILED', { cause });
586
+ }
587
+ finally {
588
+ decoding--;
589
+ }
590
+ return adopt(raw, false);
591
+ }
592
+ async function stream(url) {
593
+ open();
594
+ if (typeof url !== 'string' || url.length === 0 || url.length > 4096)
595
+ throw new EgretError('AUDIO_URL_INVALID');
596
+ if (typeof backend.openStream !== 'function')
597
+ throw new EgretError('AUDIO_STREAM_UNSUPPORTED');
598
+ if (sounds.size + decoding >= maxSounds)
599
+ throw new EgretError('AUDIO_SOUND_LIMIT');
600
+ decoding++;
601
+ let raw;
602
+ try {
603
+ raw = await backend.openStream(url);
604
+ }
605
+ catch (cause) {
606
+ throw new EgretError('AUDIO_STREAM_FAILED', { cause });
607
+ }
608
+ finally {
609
+ decoding--;
610
+ }
611
+ return adopt(raw, true);
612
+ }
613
+ /** Ends the voices of a sound and gives its samples back. What failed is returned, not thrown. */
614
+ function retire(sound, reason) {
615
+ const failures = [];
616
+ sound.released = true;
617
+ for (const voice of [...sound.voices])
618
+ try {
619
+ end(voice, reason, true);
620
+ }
621
+ catch (cause) {
622
+ failures.push(cause);
623
+ }
624
+ sounds.delete(sound);
625
+ decodedBytes -= sound.bytes;
626
+ try {
627
+ sound.backend.release();
628
+ }
629
+ catch (cause) {
630
+ failures.push(cause);
631
+ }
632
+ return failures;
633
+ }
634
+ const picture = (bus) => Object.freeze({ name: bus.name, volume: bus.volume, muted: bus.muted, voices: bus.face.voices });
635
+ return Object.freeze({
636
+ get state() {
637
+ return current();
638
+ },
639
+ master: master.face,
640
+ buses: faces,
641
+ get music() {
642
+ return music?.face;
643
+ },
644
+ bus: (name) => busOf(name).face,
645
+ decode,
646
+ stream,
647
+ play(sound, playOptions) {
648
+ open();
649
+ const entry = soundOf(sound);
650
+ return start(entry, startOf(entry, playOptions, false), false).face;
651
+ },
652
+ playMusic(sound, musicOptions) {
653
+ open();
654
+ const entry = soundOf(sound), request = startOf(entry, musicOptions, true), before = music;
655
+ if (request.bus !== undefined)
656
+ busOf(request.bus);
657
+ if (before !== undefined && before.sound === entry && musicOptions?.restart !== true) {
658
+ if (musicOptions?.volume !== undefined)
659
+ before.face.setVolume(request.volume, { fade: request.fadeIn });
660
+ return before.face;
661
+ }
662
+ const next = start(entry, request, true);
663
+ if (next.state === 'ended')
664
+ return next.face;
665
+ music = next;
666
+ if (before !== undefined)
667
+ stopVoice(before, request.fadeIn);
668
+ return next.face;
669
+ },
670
+ stopMusic(fade) {
671
+ const seconds = fadeOf(fade);
672
+ if (music !== undefined)
673
+ stopVoice(music, seconds);
674
+ },
675
+ stopAll(stopOptions) {
676
+ const seconds = fadeOf(stopOptions), only = stopOptions?.bus === undefined ? undefined : busOf(stopOptions.bus);
677
+ const failures = [];
678
+ for (const voice of [...voices])
679
+ if (only === undefined || voice.bus === only)
680
+ try {
681
+ stopVoice(voice, seconds);
682
+ }
683
+ catch (cause) {
684
+ failures.push(cause);
685
+ }
686
+ if (failures.length > 0)
687
+ throw new EgretError('AUDIO_BACKEND_FAILED', { cause: failures[0], cleanupErrors: failures.slice(1) });
688
+ },
689
+ suspend(reason = 'game') {
690
+ if (!named(reason))
691
+ throw new EgretError('AUDIO_REASON_INVALID');
692
+ if (closed || suspendedBy.includes(reason))
693
+ return;
694
+ if (suspendedBy.length >= 8)
695
+ throw new EgretError('AUDIO_REASON_LIMIT');
696
+ if (suspendedBy.length === 0)
697
+ guard(() => {
698
+ backend.suspend();
699
+ });
700
+ suspendedBy.push(reason);
701
+ announce();
702
+ },
703
+ resume(reason = 'game') {
704
+ if (!named(reason))
705
+ throw new EgretError('AUDIO_REASON_INVALID');
706
+ const index = suspendedBy.indexOf(reason);
707
+ if (closed || index < 0)
708
+ return;
709
+ if (suspendedBy.length === 1)
710
+ guard(() => {
711
+ backend.resume();
712
+ });
713
+ suspendedBy.splice(index, 1);
714
+ announce();
715
+ },
716
+ setLocked(value) {
717
+ if (typeof value !== 'boolean')
718
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
719
+ if (closed)
720
+ return;
721
+ locked = value;
722
+ announce();
723
+ },
724
+ subscribe(listener) {
725
+ if (typeof listener !== 'function')
726
+ throw new EgretError('AUDIO_OPTIONS_INVALID');
727
+ open();
728
+ listeners.add(listener);
729
+ return () => {
730
+ listeners.delete(listener);
731
+ };
732
+ },
733
+ snapshot: () => Object.freeze({
734
+ state: current(),
735
+ locked,
736
+ suspendedBy: Object.freeze([...suspendedBy]),
737
+ master: picture(master),
738
+ buses: Object.freeze(buses.map(picture)),
739
+ voices: voices.size,
740
+ sounds: sounds.size,
741
+ decodedBytes,
742
+ music: music?.id,
743
+ started,
744
+ dropped: Object.freeze({ ...dropped })
745
+ }),
746
+ dispose() {
747
+ if (closed)
748
+ return;
749
+ closed = true;
750
+ const failures = [];
751
+ for (const voice of [...voices])
752
+ try {
753
+ end(voice, 'closed', true);
754
+ }
755
+ catch (cause) {
756
+ failures.push(cause);
757
+ }
758
+ for (const sound of [...sounds])
759
+ failures.push(...retire(sound, 'closed'));
760
+ for (const bus of [...buses, master])
761
+ try {
762
+ bus.backend.release();
763
+ }
764
+ catch (cause) {
765
+ failures.push(cause);
766
+ }
767
+ try {
768
+ backend.close();
769
+ }
770
+ catch (cause) {
771
+ failures.push(cause);
772
+ }
773
+ try {
774
+ announce();
775
+ }
776
+ catch (cause) {
777
+ failures.push(cause);
778
+ }
779
+ listeners.clear();
780
+ if (failures.length > 0)
781
+ throw new EgretError('AUDIO_CLEANUP_FAILED', { cause: failures[0], cleanupErrors: failures.slice(1) });
782
+ }
783
+ });
784
+ }
785
+ //# sourceMappingURL=audioMixer.js.map