@haiyue/extensions 0.1.0 → 0.2.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 (269) hide show
  1. package/README.md +25 -0
  2. package/dist/animation/Animation2DComponent.d.ts +18 -0
  3. package/dist/animation/Animation2DExtensionRegistry.d.ts +7 -0
  4. package/dist/animation/Animation2DRenderSystem.d.ts +6 -0
  5. package/dist/animation/Animation2DRuntime.d.ts +6 -2
  6. package/dist/animation/AnimationTextRasterizer.d.ts +4 -0
  7. package/dist/animation/AnimationVisual2D.d.ts +58 -2
  8. package/dist/animation/interaction/InteractionRuntime.d.ts +83 -0
  9. package/dist/animation/interaction/runtime-types.d.ts +257 -0
  10. package/dist/animation.d.ts +3 -1
  11. package/dist/animation.js +551 -59
  12. package/dist/animation3d.js +1 -1
  13. package/dist/canvas-text.js +1 -1
  14. package/dist/chunks/2d-ui-animation-2d.generated-FpziAeGJ.js +4 -0
  15. package/dist/chunks/2d-ui-indexed-sprite.generated-DmKR0CC3.js +4 -0
  16. package/dist/chunks/Animation2DStateMachine-BHcA6Cu3.js +18212 -0
  17. package/dist/chunks/{AnimationStateMachineController-BIcAh-sT.js → AnimationStateMachineController-4sKaqh9E.js} +2 -2
  18. package/dist/chunks/AnimationVisual2D-8y3qp0_U.js +230 -0
  19. package/dist/chunks/{RenderSystem2DBase-DDT61dAu.js → RenderSystem2DBase-CF2s00vg.js} +2 -2
  20. package/dist/controls/VirtualJoystickControls.d.ts +46 -0
  21. package/dist/controls/contracts.d.ts +91 -0
  22. package/dist/controls.d.ts +2 -0
  23. package/dist/controls.js +358 -0
  24. package/dist/deformable-animation/runtime/DeformableMesh2DRuntimeExtension.d.ts +11 -0
  25. package/dist/deformable-animation/runtime/DeformableMesh2DSampler.d.ts +11 -0
  26. package/dist/deformable-animation.d.ts +5 -0
  27. package/dist/deformable-animation.js +316 -0
  28. package/dist/experimental-indexed-sprite.d.ts +5 -0
  29. package/dist/experimental-indexed-sprite.js +482 -0
  30. package/dist/gltf-worker-runtime.js +9 -9
  31. package/dist/hya-state-machine.js +3 -2
  32. package/dist/index.js +1 -1
  33. package/dist/indexed-sprite/AtlasLayout.d.ts +2 -0
  34. package/dist/indexed-sprite/IndexedSpriteRenderer.d.ts +23 -0
  35. package/dist/indexed-sprite/contracts.d.ts +89 -0
  36. package/dist/internal/2d-ui-shader-artifact.js +232 -23
  37. package/dist/ray-tracing/acceleration/bvh.d.ts +37 -0
  38. package/dist/ray-tracing/acceleration/index.d.ts +6 -0
  39. package/dist/ray-tracing/acceleration/pack.d.ts +152 -0
  40. package/dist/ray-tracing/acceleration/query.d.ts +4 -0
  41. package/dist/ray-tracing/acceleration/runtime.d.ts +30 -0
  42. package/dist/ray-tracing/acceleration/tlas.d.ts +4 -0
  43. package/dist/ray-tracing/acceleration/types.d.ts +165 -0
  44. package/dist/ray-tracing/denoise/index.d.ts +3 -0
  45. package/dist/ray-tracing/denoise/layout.d.ts +9 -0
  46. package/dist/ray-tracing/denoise/runtime.d.ts +23 -0
  47. package/dist/ray-tracing/denoise/types.d.ts +28 -0
  48. package/dist/ray-tracing/hybrid/contract.d.ts +2 -0
  49. package/dist/ray-tracing/hybrid/index.d.ts +5 -0
  50. package/dist/ray-tracing/hybrid/layout.d.ts +17 -0
  51. package/dist/ray-tracing/hybrid/plan.d.ts +2 -0
  52. package/dist/ray-tracing/hybrid/runtime.d.ts +31 -0
  53. package/dist/ray-tracing/hybrid/shaders/hybrid-artifact.generated.d.ts +625 -0
  54. package/dist/ray-tracing/hybrid/types.d.ts +144 -0
  55. package/dist/ray-tracing/lifecycle/device-recovery.d.ts +31 -0
  56. package/dist/ray-tracing/lifecycle/index.d.ts +2 -0
  57. package/dist/ray-tracing/lifecycle/types.d.ts +37 -0
  58. package/dist/ray-tracing/material/index.d.ts +2 -0
  59. package/dist/ray-tracing/material/pack.d.ts +5 -0
  60. package/dist/ray-tracing/material/types.d.ts +63 -0
  61. package/dist/ray-tracing/reference/index.d.ts +122 -0
  62. package/dist/ray-tracing/renderer/index.d.ts +7 -0
  63. package/dist/ray-tracing/renderer/layout.d.ts +20 -0
  64. package/dist/ray-tracing/renderer/plan.d.ts +2 -0
  65. package/dist/ray-tracing/renderer/reference.d.ts +17 -0
  66. package/dist/ray-tracing/renderer/runtime.d.ts +39 -0
  67. package/dist/ray-tracing/renderer/scene.d.ts +4 -0
  68. package/dist/ray-tracing/renderer/types.d.ts +115 -0
  69. package/dist/ray-tracing/sampling/index.d.ts +8 -0
  70. package/dist/ray-tracing/sampling/layout.d.ts +12 -0
  71. package/dist/ray-tracing/sampling/plan.d.ts +5 -0
  72. package/dist/ray-tracing/sampling/revision.d.ts +15 -0
  73. package/dist/ray-tracing/sampling/runtime.d.ts +44 -0
  74. package/dist/ray-tracing/sampling/sequence.d.ts +2 -0
  75. package/dist/ray-tracing/sampling/types.d.ts +96 -0
  76. package/dist/ray-tracing/scene/index.d.ts +41 -0
  77. package/dist/ray-tracing/traversal/index.d.ts +4 -0
  78. package/dist/ray-tracing/traversal/layout.d.ts +16 -0
  79. package/dist/ray-tracing/traversal/plan.d.ts +2 -0
  80. package/dist/ray-tracing/traversal/runtime.d.ts +25 -0
  81. package/dist/ray-tracing/traversal/types.d.ts +79 -0
  82. package/dist/ray-tracing/worker/client.d.ts +25 -0
  83. package/dist/ray-tracing/worker/index.d.ts +5 -0
  84. package/dist/ray-tracing/worker/runtime.d.ts +11 -0
  85. package/dist/ray-tracing/worker/serialization.d.ts +16 -0
  86. package/dist/ray-tracing/worker/source.d.ts +1 -0
  87. package/dist/ray-tracing/worker/types.d.ts +91 -0
  88. package/dist/ray-tracing.d.ts +17 -0
  89. package/dist/ray-tracing.js +7666 -0
  90. package/dist/spine.js +1 -1
  91. package/dist/tilemap.js +1 -1
  92. package/package.json +26 -23
  93. package/dist/animation/Animation2DStateMachineVisualRuntime.d.ts +0 -27
  94. package/dist/animation/Particle2DDescriptorAdapter.d.ts +0 -5
  95. package/dist/animation3d/Animation3DResource.d.ts +0 -28
  96. package/dist/animation3d/hya/HyaAnimation3DStateMachineRuntime.d.ts +0 -65
  97. package/dist/animation3d/hya/index.d.ts +0 -4
  98. package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.d.ts +0 -81
  99. package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.d.ts +0 -39
  100. package/dist/animation3d/runtime/integration/index.d.ts +0 -2
  101. package/dist/animation3d/runtime/mixer/Action.d.ts +0 -150
  102. package/dist/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.d.ts +0 -6
  103. package/dist/animation3d/runtime/mixer/Mixer.d.ts +0 -59
  104. package/dist/animation3d/runtime/mixer/PoseBuffer.d.ts +0 -1
  105. package/dist/animation3d/runtime/mixer/TrackSampler.d.ts +0 -24
  106. package/dist/animation3d/runtime/mixer/index.d.ts +0 -4
  107. package/dist/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.d.ts +0 -1
  108. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.d.ts +0 -1
  109. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineController.d.ts +0 -1
  110. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.d.ts +0 -1
  111. package/dist/animation3d/runtime/state-machine/index.d.ts +0 -6
  112. package/dist/benchmark.d.ts +0 -30
  113. package/dist/chunks/2d-ui-animation-2d.generated-D4aHzFU2.js +0 -4
  114. package/dist/chunks/Animation2DStateMachine-9IonguNa.js +0 -3245
  115. package/dist/gltf/GltfAccessorReader.d.ts +0 -7
  116. package/dist/gltf/GltfDracoDecoder.d.ts +0 -4
  117. package/dist/gltf/GltfLoaderErrors.d.ts +0 -4
  118. package/dist/gltf/GltfMaterialDescriptor.d.ts +0 -23
  119. package/dist/gltf/GltfMaterialLoader.d.ts +0 -6
  120. package/dist/gltf-worker-runtime.d.ts +0 -7
  121. package/dist/plugins/pluginUtils.d.ts +0 -20
  122. package/dist/plugins.d.ts +0 -6
  123. package/dist/shaders/generated/2d-ui-artifact.generated.d.ts +0 -658
  124. package/dist/spine/Spine2DGpuRenderer.d.ts +0 -65
  125. package/dist/spine/Spine2DRuntime.d.ts +0 -103
  126. package/dist/spine/SpineAnimationBoneTimelines.d.ts +0 -8
  127. package/dist/spine/SpineFloatBuilder.d.ts +0 -15
  128. package/dist/spine/SpinePathConstraintSolver.d.ts +0 -32
  129. package/dist/spine/SpineSkeletonRuntime.d.ts +0 -185
  130. package/dist/spine/SpineSlotAnimation.d.ts +0 -17
  131. package/dist/spine/SpineTimelineRuntime.d.ts +0 -25
  132. package/dist/spine/SpineVertexBuilder.d.ts +0 -61
  133. package/dist/tilemap/Tilemap2DRenderer.d.ts +0 -24
  134. package/dist/utils/arrayAccess.d.ts +0 -4
  135. package/dist/utils/camera2d.d.ts +0 -12
  136. package/src/animation/Animation2DComponent.ts +0 -135
  137. package/src/animation/Animation2DExtensionRegistry.ts +0 -52
  138. package/src/animation/Animation2DRenderSystem.ts +0 -1026
  139. package/src/animation/Animation2DRuntime.ts +0 -1326
  140. package/src/animation/Animation2DStateMachine.ts +0 -39
  141. package/src/animation/Animation2DStateMachineComponent.ts +0 -228
  142. package/src/animation/Animation2DStateMachineRuntime.ts +0 -141
  143. package/src/animation/Animation2DStateMachineSystem.ts +0 -60
  144. package/src/animation/Animation2DStateMachineVisualRuntime.ts +0 -282
  145. package/src/animation/Animation2DSystem.ts +0 -72
  146. package/src/animation/AnimationAssetLoader.ts +0 -84
  147. package/src/animation/AnimationAudioClip.ts +0 -140
  148. package/src/animation/AnimationPathTessellator.ts +0 -691
  149. package/src/animation/AnimationTextRasterizer.ts +0 -340
  150. package/src/animation/AnimationVisual2D.ts +0 -153
  151. package/src/animation/HyaAnimation2DClipAdapter.ts +0 -845
  152. package/src/animation/Particle2DDescriptorAdapter.ts +0 -35
  153. package/src/animation/runtime/mixer/Action.ts +0 -876
  154. package/src/animation/runtime/mixer/Mixer.ts +0 -505
  155. package/src/animation/runtime/mixer/PoseBuffer.ts +0 -105
  156. package/src/animation/runtime/mixer/Sampler.ts +0 -252
  157. package/src/animation/runtime/mixer/Types.ts +0 -138
  158. package/src/animation/runtime/mixer/index.ts +0 -31
  159. package/src/animation-state-machine/AnimationStateMachine.ts +0 -146
  160. package/src/animation-state-machine/AnimationStateMachineChannels.ts +0 -116
  161. package/src/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.ts +0 -197
  162. package/src/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.ts +0 -503
  163. package/src/animation-state-machine/runtime/AnimationStateMachineCompiler.ts +0 -763
  164. package/src/animation-state-machine/runtime/AnimationStateMachineController.ts +0 -987
  165. package/src/animation-state-machine/runtime/AnimationStateMachineMixerPort.ts +0 -54
  166. package/src/animation-state-machine/runtime/index.ts +0 -47
  167. package/src/animation.ts +0 -33
  168. package/src/animation3d/Animation3DAction.ts +0 -73
  169. package/src/animation3d/Animation3DBinding.ts +0 -116
  170. package/src/animation3d/Animation3DClip.ts +0 -22
  171. package/src/animation3d/Animation3DError.ts +0 -34
  172. package/src/animation3d/Animation3DMixer.ts +0 -82
  173. package/src/animation3d/Animation3DPose.ts +0 -100
  174. package/src/animation3d/Animation3DPoseBuffer.ts +0 -85
  175. package/src/animation3d/Animation3DResource.ts +0 -49
  176. package/src/animation3d/Animation3DStateMachine.ts +0 -126
  177. package/src/animation3d/Animation3DStateMachineRuntime.ts +0 -191
  178. package/src/animation3d/Animation3DTrack.ts +0 -29
  179. package/src/animation3d/hya/HyaAnimation3DRuntime.ts +0 -756
  180. package/src/animation3d/hya/HyaAnimation3DStateMachineRuntime.ts +0 -618
  181. package/src/animation3d/hya/HyaAnimation3DTypes.ts +0 -168
  182. package/src/animation3d/hya/index.ts +0 -10
  183. package/src/animation3d/index.ts +0 -76
  184. package/src/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.ts +0 -325
  185. package/src/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.ts +0 -158
  186. package/src/animation3d/runtime/integration/index.ts +0 -9
  187. package/src/animation3d/runtime/mixer/Action.ts +0 -833
  188. package/src/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.ts +0 -26
  189. package/src/animation3d/runtime/mixer/Mixer.ts +0 -562
  190. package/src/animation3d/runtime/mixer/PoseBuffer.ts +0 -1
  191. package/src/animation3d/runtime/mixer/TrackSampler.ts +0 -399
  192. package/src/animation3d/runtime/mixer/index.ts +0 -8
  193. package/src/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.ts +0 -4
  194. package/src/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.ts +0 -1
  195. package/src/animation3d/runtime/state-machine/Animation3DStateMachineController.ts +0 -1
  196. package/src/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.ts +0 -1
  197. package/src/animation3d/runtime/state-machine/index.ts +0 -45
  198. package/src/animation3d.ts +0 -5
  199. package/src/benchmark.ts +0 -168
  200. package/src/canvas-text/CanvasText2DRenderSystem.ts +0 -292
  201. package/src/canvas-text/CanvasTextComponent.ts +0 -47
  202. package/src/canvas-text.ts +0 -4
  203. package/src/experimental-gltf-worker.ts +0 -18
  204. package/src/experimental-spine-worker.ts +0 -9
  205. package/src/gltf/GltfAccessorReader.ts +0 -271
  206. package/src/gltf/GltfAnimation3DAdapter.ts +0 -680
  207. package/src/gltf/GltfAnimationRuntime.ts +0 -392
  208. package/src/gltf/GltfAssetWorkerClient.ts +0 -136
  209. package/src/gltf/GltfCompatibilityReport.ts +0 -214
  210. package/src/gltf/GltfConservativeBounds.ts +0 -219
  211. package/src/gltf/GltfDracoDecoder.ts +0 -251
  212. package/src/gltf/GltfExtensionAdapter.ts +0 -340
  213. package/src/gltf/GltfLoaderContract.ts +0 -333
  214. package/src/gltf/GltfLoaderErrors.ts +0 -59
  215. package/src/gltf/GltfMaterialDescriptor.ts +0 -134
  216. package/src/gltf/GltfMaterialEncoder.ts +0 -173
  217. package/src/gltf/GltfMaterialLoader.ts +0 -293
  218. package/src/gltf/GltfModelComponent.ts +0 -115
  219. package/src/gltf/GltfModelSystem.ts +0 -208
  220. package/src/gltf/GltfPlugin.ts +0 -84
  221. package/src/gltf/GltfSchema.ts +0 -229
  222. package/src/gltf/GltfUvSemanticPlanner.ts +0 -166
  223. package/src/gltf/gltfLoader.ts +0 -910
  224. package/src/gltf-animation3d.ts +0 -10
  225. package/src/gltf-worker-runtime.ts +0 -10
  226. package/src/gltf.ts +0 -56
  227. package/src/grid/Grid2DComponent.ts +0 -69
  228. package/src/grid.ts +0 -2
  229. package/src/hya-state-machine.ts +0 -19
  230. package/src/index.ts +0 -2
  231. package/src/plugins/pluginUtils.ts +0 -50
  232. package/src/plugins.ts +0 -6
  233. package/src/shaders/generated/2d-ui-animation-2d.generated.wgsl +0 -242
  234. package/src/shaders/generated/2d-ui-artifact.generated.ts +0 -867
  235. package/src/shaders/generated/2d-ui-canvas-text-2d.generated.wgsl +0 -38
  236. package/src/shaders/generated/2d-ui-spine2d.generated.wgsl +0 -41
  237. package/src/shaders/generated/2d-ui-tilemap2d.generated.wgsl +0 -36
  238. package/src/spine/Spine2DComponent.ts +0 -168
  239. package/src/spine/Spine2DGpuRenderer.ts +0 -449
  240. package/src/spine/Spine2DRenderSystem.ts +0 -199
  241. package/src/spine/Spine2DRuntime.ts +0 -1529
  242. package/src/spine/SpineAnimationBoneTimelines.ts +0 -30
  243. package/src/spine/SpineAssetParser.ts +0 -20
  244. package/src/spine/SpineAssetWorkerClient.ts +0 -112
  245. package/src/spine/SpineAssetWorkerContract.ts +0 -4
  246. package/src/spine/SpineAtlasParser.ts +0 -127
  247. package/src/spine/SpineFloatBuilder.ts +0 -66
  248. package/src/spine/SpinePathConstraintSolver.ts +0 -582
  249. package/src/spine/SpinePlugin.ts +0 -76
  250. package/src/spine/SpineSkeletonRuntime.ts +0 -521
  251. package/src/spine/SpineSlotAnimation.ts +0 -195
  252. package/src/spine/SpineTimelineRuntime.ts +0 -453
  253. package/src/spine/SpineVertexBuilder.ts +0 -686
  254. package/src/spine.ts +0 -7
  255. package/src/tilemap/Tilemap2DComponent.ts +0 -232
  256. package/src/tilemap/Tilemap2DRenderSystem.ts +0 -58
  257. package/src/tilemap/Tilemap2DRenderer.ts +0 -289
  258. package/src/tilemap/TilemapPlugin.ts +0 -75
  259. package/src/tilemap.ts +0 -6
  260. package/src/tween/Tween2DComponent.ts +0 -83
  261. package/src/tween/Tween2DSystem.ts +0 -78
  262. package/src/tween.ts +0 -4
  263. package/src/types/earcut.d.ts +0 -7
  264. package/src/types/wgsl.d.ts +0 -4
  265. package/src/utils/RenderSystem2DBase.ts +0 -164
  266. package/src/utils/arrayAccess.ts +0 -17
  267. package/src/utils/camera2d.ts +0 -68
  268. package/src/utils/render2dGpu.ts +0 -132
  269. package/test/fixtures/gltf/animation-characterization.gltf +0 -344
@@ -0,0 +1,358 @@
1
+ import { System } from '@haiyue/engine/ecs';
2
+ import { CartesianTransform3D, Transform2D } from '@haiyue/engine/components';
3
+ import { EventEmitter } from '@haiyue/engine/core';
4
+ import { GuiElement } from '@haiyue/engine/gui';
5
+
6
+ class Disc extends GuiElement {
7
+ constructor(style) { super({ disabled: true, style }); }
8
+ layout() { }
9
+ place(x, y, radius) {
10
+ if (this.rect.x === x - radius && this.rect.y === y - radius && this.rect.width === radius * 2)
11
+ return;
12
+ this.rect = { x: x - radius, y: y - radius, width: radius * 2, height: radius * 2 };
13
+ this.markDirty(2 /* GuiDirtyFlags.Visual */);
14
+ }
15
+ }
16
+ /** Presentation only: never intercepts pointers or creates another render loop. */
17
+ class JoystickView {
18
+ base;
19
+ knob;
20
+ constructor(root, baseStyle, knobStyle) {
21
+ this.base = root.add(new Disc({ backgroundColor: '#18334b99', borderColor: '#6aadd5aa', ...baseStyle }));
22
+ this.knob = root.add(new Disc({ backgroundColor: '#82d9f4dd', borderColor: '#d9f6ff', ...knobStyle }));
23
+ }
24
+ update(state, maxDistance, knobRadius, visible) {
25
+ this.base.setVisible(visible);
26
+ this.knob.setVisible(visible);
27
+ this.base.style.radius = maxDistance + knobRadius;
28
+ this.knob.style.radius = knobRadius;
29
+ this.base.place(state.center.x, state.center.y, maxDistance + knobRadius);
30
+ this.knob.place(state.center.x + state.offset.x, state.center.y + state.offset.y, knobRadius);
31
+ }
32
+ destroy() {
33
+ this.base.parent?.remove(this.base);
34
+ this.knob.parent?.remove(this.knob);
35
+ }
36
+ }
37
+
38
+ const DEFAULT_CENTER = ({ width, height }) => ({
39
+ x: Math.min(110, width / 4), y: height - Math.min(110, height / 4),
40
+ });
41
+ const DEFAULT_REGION = ({ width, height }) => ({
42
+ x: 0, y: height / 2, width: width / 2, height: height / 2,
43
+ });
44
+ /**
45
+ * Single-owner multitouch joystick. Add as a non-render System, or call step(dtMs)
46
+ * exactly once per frame. Set touch-action:none on the browser input surface.
47
+ * The supplied target is moved in parent-local coordinates without collision solving.
48
+ */
49
+ class VirtualJoystickControls extends System {
50
+ events = new EventEmitter();
51
+ surface;
52
+ document;
53
+ window;
54
+ options;
55
+ view = null;
56
+ pointerId = null;
57
+ center = { x: 0, y: 0 };
58
+ point = { x: 0, y: 0 };
59
+ bounds = '';
60
+ disposed = false;
61
+ constructor(surface, options = {}) {
62
+ super(() => false);
63
+ this.name = 'VirtualJoystickControls';
64
+ this.priority = -100;
65
+ this.surface = surface;
66
+ this.document = surface.ownerDocument ?? null;
67
+ this.window = this.document?.defaultView ?? null;
68
+ this.options = normalize(options);
69
+ this.refreshLayout();
70
+ this.createView();
71
+ surface.addEventListener('pointerdown', this.onDown, { passive: false });
72
+ surface.addEventListener('pointermove', this.onMove, { passive: false });
73
+ surface.addEventListener('pointerup', this.onUp);
74
+ surface.addEventListener('pointercancel', this.onCancel);
75
+ surface.addEventListener('lostpointercapture', this.onCancel);
76
+ this.window?.addEventListener('blur', this.onBlur);
77
+ // Also handles a release outside a surface without native pointer capture.
78
+ this.window?.addEventListener('pointerup', this.onUp);
79
+ this.window?.addEventListener('pointercancel', this.onCancel);
80
+ this.document?.addEventListener('visibilitychange', this.onVisibility);
81
+ }
82
+ get disabled() { return super.disabled; }
83
+ set disabled(value) {
84
+ super.disabled = value;
85
+ // System's constructor invokes this setter before subclass fields exist.
86
+ if (this.surface) {
87
+ if (value)
88
+ this.cancel();
89
+ this.updateView();
90
+ }
91
+ }
92
+ /** Retainable immutable snapshot; caller mutation cannot alter future movement. */
93
+ get state() {
94
+ const active = this.pointerId !== null;
95
+ const dx = active ? this.point.x - this.center.x : 0;
96
+ const dy = active ? this.point.y - this.center.y : 0;
97
+ const rawDistance = Math.hypot(dx, dy);
98
+ const distance = Math.min(rawDistance, this.options.maxDistance);
99
+ const ratio = distance / this.options.maxDistance;
100
+ const strength = Math.max(0, (ratio - this.options.deadZone) / (1 - this.options.deadZone));
101
+ const unitX = rawDistance > 0 ? dx / rawDistance : 0;
102
+ const unitY = rawDistance > 0 ? dy / rawDistance : 0;
103
+ return Object.freeze({
104
+ active, pointerId: this.pointerId, center: Object.freeze({ ...this.center }),
105
+ direction: Object.freeze({ x: strength > 0 ? unitX : 0, y: strength > 0 ? unitY : 0 }),
106
+ offset: Object.freeze({ x: unitX * distance, y: unitY * distance }),
107
+ rawDistance, distance, strength, angle: strength > 0 ? Math.atan2(dy, dx) : 0,
108
+ });
109
+ }
110
+ /** Atomic parameter update. A valid update cancels the current gesture. */
111
+ configure(options) {
112
+ if (this.disposed)
113
+ return this;
114
+ const next = normalize({ ...this.options, ...options });
115
+ const viewport = this.surface.getBoundingClientRect();
116
+ resolvePoint(next.center, viewport);
117
+ resolveRegion(next.region, viewport);
118
+ this.cancel();
119
+ this.options = next;
120
+ this.refreshLayout();
121
+ this.createView();
122
+ return this;
123
+ }
124
+ /** Cancel from native suspend/unload hooks; idempotent, returns thumb to center. */
125
+ cancel() { this.finish('cancel'); return this; }
126
+ /** Delta is milliseconds, matching World.update(). No internal RAF or timer. */
127
+ step(deltaMilliseconds) {
128
+ nonNegative(deltaMilliseconds, 'deltaMilliseconds');
129
+ if (this.disposed || this.disabled)
130
+ return this;
131
+ this.refreshLayout();
132
+ const state = this.state;
133
+ const deltaSeconds = deltaMilliseconds / 1000;
134
+ const movementDeltaSeconds = Math.min(deltaMilliseconds, this.options.maxDeltaMilliseconds) / 1000;
135
+ this.moveTarget(state, movementDeltaSeconds);
136
+ this.updateView(state);
137
+ this.events.emit('frame', { detail: Object.freeze({ ...state, deltaMilliseconds, deltaSeconds, movementDeltaSeconds }) });
138
+ return this;
139
+ }
140
+ update(_world, _time, delta) {
141
+ // The first RAF timestamp can precede FrameLoop.start()'s performance.now().
142
+ // A clock-origin adjustment must never abort rendering or move a character backwards.
143
+ return this.step(Math.max(0, delta));
144
+ }
145
+ destroy() {
146
+ if (this.disposed)
147
+ return this;
148
+ this.disposed = true;
149
+ // Teardown is completed even if a consumer's cancel callback throws.
150
+ try {
151
+ this.cancel();
152
+ }
153
+ finally {
154
+ this.surface.removeEventListener('pointerdown', this.onDown);
155
+ this.surface.removeEventListener('pointermove', this.onMove);
156
+ this.surface.removeEventListener('pointerup', this.onUp);
157
+ this.surface.removeEventListener('pointercancel', this.onCancel);
158
+ this.surface.removeEventListener('lostpointercapture', this.onCancel);
159
+ this.window?.removeEventListener('blur', this.onBlur);
160
+ this.window?.removeEventListener('pointerup', this.onUp);
161
+ this.window?.removeEventListener('pointercancel', this.onCancel);
162
+ this.document?.removeEventListener('visibilitychange', this.onVisibility);
163
+ this.view?.destroy();
164
+ this.view = null;
165
+ this.events.removeAllListeners();
166
+ super.destroy();
167
+ }
168
+ return this;
169
+ }
170
+ refreshLayout() {
171
+ const rect = this.surface.getBoundingClientRect();
172
+ const key = `${rect.left}:${rect.top}:${rect.width}:${rect.height}`;
173
+ if (this.bounds && this.bounds !== key)
174
+ this.cancel();
175
+ this.bounds = key;
176
+ if (this.pointerId === null) {
177
+ const viewport = { width: rect.width, height: rect.height };
178
+ this.center = resolvePoint(this.options.center, viewport);
179
+ }
180
+ }
181
+ createView() {
182
+ this.view?.destroy();
183
+ this.view = this.options.guiRoot
184
+ ? new JoystickView(this.options.guiRoot, this.options.baseStyle, this.options.knobStyle) : null;
185
+ this.updateView();
186
+ }
187
+ updateView(state = this.state) {
188
+ this.view?.update(state, this.options.maxDistance, this.options.knobRadius, !this.disabled && !this.disposed && (state.active || (this.options.mode === 'fixed' && this.options.showIdle)));
189
+ }
190
+ local(event) {
191
+ if (!Number.isFinite(event.clientX) || !Number.isFinite(event.clientY))
192
+ return null;
193
+ const rect = this.surface.getBoundingClientRect();
194
+ return { x: event.clientX - rect.left, y: event.clientY - rect.top };
195
+ }
196
+ onDown = (native) => {
197
+ const event = native;
198
+ // GuiSystem prevents browser scrolling on all canvas pointers. That is not an
199
+ // input-ownership claim: use region/shouldActivate to arbitrate game input.
200
+ if (this.disposed || this.disabled || this.pointerId !== null
201
+ || (event.button !== undefined && event.button !== 0))
202
+ return;
203
+ this.refreshLayout();
204
+ const point = this.local(event);
205
+ if (!point || !Number.isFinite(event.pointerId))
206
+ return;
207
+ const rect = this.surface.getBoundingClientRect();
208
+ const region = resolveRegion(this.options.region, rect);
209
+ if (point.x < 0 || point.y < 0 || point.x > rect.width || point.y > rect.height
210
+ || point.x < region.x || point.y < region.y || point.x > region.x + region.width || point.y > region.y + region.height)
211
+ return;
212
+ if (this.options.mode === 'fixed' && Math.hypot(point.x - this.center.x, point.y - this.center.y)
213
+ > (this.options.activationRadius ?? this.options.maxDistance + this.options.knobRadius))
214
+ return;
215
+ if (this.options.shouldActivate?.(point, event) === false)
216
+ return;
217
+ if (this.options.mode === 'floating')
218
+ this.center = { ...point };
219
+ this.point = point;
220
+ this.pointerId = event.pointerId;
221
+ try {
222
+ this.surface.setPointerCapture?.(event.pointerId);
223
+ }
224
+ catch { /* Synthetic/host pointers may not support capture. */ }
225
+ event.preventDefault();
226
+ this.updateView();
227
+ this.events.emit('start', { detail: this.state });
228
+ };
229
+ onMove = (native) => {
230
+ const event = native;
231
+ if (this.pointerId === null || event.pointerId !== this.pointerId)
232
+ return;
233
+ this.refreshLayout();
234
+ if (this.pointerId === null)
235
+ return;
236
+ const point = this.local(event);
237
+ if (point)
238
+ this.point = point;
239
+ event.preventDefault();
240
+ };
241
+ onUp = (event) => {
242
+ if (this.pointerId !== null && event.pointerId === this.pointerId)
243
+ this.finish('end');
244
+ };
245
+ onCancel = (event) => {
246
+ if (this.pointerId !== null && event.pointerId === this.pointerId)
247
+ this.cancel();
248
+ };
249
+ onBlur = () => { this.cancel(); };
250
+ onVisibility = () => { if (this.document?.hidden)
251
+ this.cancel(); };
252
+ finish(type) {
253
+ const id = this.pointerId;
254
+ if (id === null)
255
+ return;
256
+ this.pointerId = null;
257
+ this.point = { ...this.center };
258
+ try {
259
+ this.surface.releasePointerCapture?.(id);
260
+ }
261
+ catch { /* Capture may already be lost. */ }
262
+ this.updateView();
263
+ this.events.emit(type, { detail: this.state });
264
+ }
265
+ moveTarget(state, dt) {
266
+ const { target, plane, moveSpeed, analog, rotateToDirection, rotationOffset, turnSpeed, movementRotation } = this.options;
267
+ if (!target || target.destroyed || target.disabled || state.strength === 0 || dt === 0)
268
+ return;
269
+ const c = Math.cos(movementRotation), s = Math.sin(movementRotation);
270
+ const dx = state.direction.x, dy = state.direction.y;
271
+ const amount = moveSpeed * dt * (analog ? state.strength : 1);
272
+ if (plane === 'xz') {
273
+ const transform = target.getComponent(CartesianTransform3D);
274
+ if (!transform || transform.disabled)
275
+ return;
276
+ const x = c * dx + s * dy, z = -s * dx + c * dy;
277
+ const p = transform.position, r = transform.rotation;
278
+ transform.setPosition(p[0] + x * amount, p[1], p[2] + z * amount);
279
+ if (rotateToDirection)
280
+ transform.setRotation(r[0], turn(r[1], Math.atan2(-x, -z) + rotationOffset, turnSpeed * dt), r[2]);
281
+ }
282
+ else {
283
+ const transform = target.getComponent(Transform2D);
284
+ if (!transform || transform.disabled)
285
+ return;
286
+ const x = c * dx + s * dy, y = s * dx - c * dy;
287
+ transform.setPosition(transform.x + x * amount, transform.y + y * amount);
288
+ if (rotateToDirection)
289
+ transform.rotation = turn(transform.rotation, Math.atan2(y, x) + rotationOffset, turnSpeed * dt);
290
+ }
291
+ }
292
+ }
293
+ function turn(current, desired, max) {
294
+ const difference = Math.atan2(Math.sin(desired - current), Math.cos(desired - current));
295
+ return current + Math.max(-max, Math.min(max, difference));
296
+ }
297
+ function nonNegative(value, name) {
298
+ if (!Number.isFinite(value) || value < 0)
299
+ throw new RangeError(`VirtualJoystickControls ${name} must be finite and non-negative.`);
300
+ return value;
301
+ }
302
+ function positive(value, name) {
303
+ nonNegative(value, name);
304
+ if (value === 0)
305
+ throw new RangeError(`VirtualJoystickControls ${name} must be positive.`);
306
+ return value;
307
+ }
308
+ function finite(value, name) {
309
+ if (!Number.isFinite(value))
310
+ throw new RangeError(`VirtualJoystickControls ${name} must be finite.`);
311
+ return value;
312
+ }
313
+ function resolvePoint(value, viewport) {
314
+ const p = typeof value === 'function' ? value(viewport) : value;
315
+ return { x: finite(p.x, 'center.x'), y: finite(p.y, 'center.y') };
316
+ }
317
+ function resolveRegion(value, viewport) {
318
+ const r = typeof value === 'function' ? value(viewport) : value;
319
+ return { x: finite(r.x, 'region.x'), y: finite(r.y, 'region.y'),
320
+ width: nonNegative(r.width, 'region.width'), height: nonNegative(r.height, 'region.height') };
321
+ }
322
+ function normalize(input) {
323
+ const mode = input.mode ?? 'floating', plane = input.plane ?? 'xz';
324
+ if (mode !== 'fixed' && mode !== 'floating')
325
+ throw new RangeError('VirtualJoystickControls invalid mode.');
326
+ if (plane !== 'xz' && plane !== 'xy')
327
+ throw new RangeError('VirtualJoystickControls invalid plane.');
328
+ const deadZone = nonNegative(input.deadZone ?? 0.1, 'deadZone');
329
+ if (deadZone >= 1)
330
+ throw new RangeError('VirtualJoystickControls deadZone must be less than 1.');
331
+ const target = input.target ?? null;
332
+ if (target && (target.destroyed || !(plane === 'xz' ? target.getComponent(CartesianTransform3D) : target.getComponent(Transform2D)))) {
333
+ throw new TypeError(`VirtualJoystickControls target requires a live ${plane === 'xz' ? 'CartesianTransform3D' : 'Transform2D'}.`);
334
+ }
335
+ const center = input.center ?? DEFAULT_CENTER, region = input.region ?? DEFAULT_REGION;
336
+ if (typeof center !== 'function')
337
+ resolvePoint(center, { width: 0, height: 0 });
338
+ if (typeof region !== 'function')
339
+ resolveRegion(region, { width: 0, height: 0 });
340
+ return {
341
+ mode, plane, target, center: typeof center === 'function' ? center : { ...center },
342
+ region: typeof region === 'function' ? region : { ...region }, deadZone,
343
+ maxDistance: positive(input.maxDistance ?? 64, 'maxDistance'),
344
+ activationRadius: input.activationRadius == null ? null : positive(input.activationRadius, 'activationRadius'),
345
+ moveSpeed: nonNegative(input.moveSpeed ?? 4, 'moveSpeed'), analog: input.analog ?? true,
346
+ rotateToDirection: input.rotateToDirection ?? true,
347
+ turnSpeed: input.turnSpeed === Infinity || input.turnSpeed === undefined ? Infinity : nonNegative(input.turnSpeed, 'turnSpeed'),
348
+ rotationOffset: finite(input.rotationOffset ?? 0, 'rotationOffset'),
349
+ movementRotation: finite(input.movementRotation ?? 0, 'movementRotation'),
350
+ maxDeltaMilliseconds: positive(input.maxDeltaMilliseconds ?? 100, 'maxDeltaMilliseconds'),
351
+ guiRoot: input.guiRoot ?? null, knobRadius: positive(input.knobRadius ?? 24, 'knobRadius'),
352
+ showIdle: input.showIdle ?? true, baseStyle: { ...input.baseStyle }, knobStyle: { ...input.knobStyle },
353
+ ...(input.shouldActivate ? { shouldActivate: input.shouldActivate } : {}),
354
+ };
355
+ }
356
+
357
+ export { VirtualJoystickControls };
358
+ //# sourceMappingURL=controls.js.map
@@ -0,0 +1,11 @@
1
+ import type { Animation2DExtensionHandler } from '../../animation/Animation2DExtensionRegistry';
2
+ export type DeformableMesh2DRuntimeState = 'loading' | 'ready' | 'error' | 'destroyed';
3
+ export interface DeformableMesh2DRuntimeStatus {
4
+ readonly state: DeformableMesh2DRuntimeState;
5
+ readonly drawableCount: number;
6
+ readonly error?: string;
7
+ }
8
+ export interface DeformableMesh2DRuntimeExtensionOptions {
9
+ readonly onStatus?: (status: DeformableMesh2DRuntimeStatus) => void;
10
+ }
11
+ export declare function createDeformableMesh2DRuntimeExtension(options?: DeformableMesh2DRuntimeExtensionOptions): Animation2DExtensionHandler;
@@ -0,0 +1,11 @@
1
+ import type { ParsedDeformableMesh2DDrawable } from '@haiyue/animation-spec/deformable2d';
2
+ export interface DeformableMesh2DSample {
3
+ readonly opacity: number;
4
+ readonly renderOrder: number;
5
+ readonly frame: number;
6
+ readonly nextFrame: number;
7
+ readonly progress: number;
8
+ }
9
+ export declare function sampleDeformableMesh2DDrawable(times: Float32Array, drawable: ParsedDeformableMesh2DDrawable, time: number, targetRuntimePositions: Float32Array): DeformableMesh2DSample;
10
+ /** Samples optional HYDM 1.2 RGBA tracks into caller-owned pose storage without allocating. */
11
+ export declare function sampleDeformableMesh2DDrawableColors(drawable: ParsedDeformableMesh2DDrawable, sample: DeformableMesh2DSample, targetMultiplyColors: Float32Array, targetScreenColors: Float32Array, targetOffset?: number): void;
@@ -0,0 +1,5 @@
1
+ export { createDeformableMesh2DRuntimeExtension } from './deformable-animation/runtime/DeformableMesh2DRuntimeExtension';
2
+ export type { DeformableMesh2DRuntimeExtensionOptions, DeformableMesh2DRuntimeState, DeformableMesh2DRuntimeStatus, } from './deformable-animation/runtime/DeformableMesh2DRuntimeExtension';
3
+ /** Low-level geometry/opacity sampler; drawable colors are populated by the reusable pose port. */
4
+ export { sampleDeformableMesh2DDrawable } from './deformable-animation/runtime/DeformableMesh2DSampler';
5
+ export type { DeformableMesh2DSample } from './deformable-animation/runtime/DeformableMesh2DSampler';