@needle-tools/engine 4.14.0-beta → 4.14.0-next.52fdb13

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 (97) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/components.needle.json +1 -1
  3. package/dist/{needle-engine.bundle-BW2VusZV.min.js → needle-engine.bundle-BwfaInTa.min.js} +131 -123
  4. package/dist/{needle-engine.bundle-Cb5bKEqa.umd.cjs → needle-engine.bundle-DJE-Bjpa.umd.cjs} +124 -116
  5. package/dist/{needle-engine.bundle-D9VPvp5o.js → needle-engine.bundle-TmE5-_na.js} +3457 -3227
  6. package/dist/needle-engine.d.ts +430 -94
  7. package/dist/needle-engine.js +570 -569
  8. package/dist/needle-engine.min.js +1 -1
  9. package/dist/needle-engine.umd.cjs +1 -1
  10. package/dist/{postprocessing-CctM1XIO.min.js → postprocessing-06AXuvdv.min.js} +2 -2
  11. package/dist/{postprocessing-DGm6qJ-I.js → postprocessing-CI2x8Cln.js} +2 -2
  12. package/dist/{postprocessing-Dbl2PJpd.umd.cjs → postprocessing-CPDcA21P.umd.cjs} +2 -2
  13. package/lib/engine/api.d.ts +203 -18
  14. package/lib/engine/api.js +271 -18
  15. package/lib/engine/api.js.map +1 -1
  16. package/lib/engine/engine_accessibility.d.ts +58 -0
  17. package/lib/engine/engine_accessibility.js +143 -0
  18. package/lib/engine/engine_accessibility.js.map +1 -0
  19. package/lib/engine/engine_context.d.ts +2 -0
  20. package/lib/engine/engine_context.js +7 -0
  21. package/lib/engine/engine_context.js.map +1 -1
  22. package/lib/engine/engine_materialpropertyblock.d.ts +91 -5
  23. package/lib/engine/engine_materialpropertyblock.js +97 -7
  24. package/lib/engine/engine_materialpropertyblock.js.map +1 -1
  25. package/lib/engine/engine_math.d.ts +34 -1
  26. package/lib/engine/engine_math.js +34 -1
  27. package/lib/engine/engine_math.js.map +1 -1
  28. package/lib/engine/engine_networking.js +1 -1
  29. package/lib/engine/engine_networking.js.map +1 -1
  30. package/lib/engine/engine_types.d.ts +2 -0
  31. package/lib/engine/engine_types.js +2 -0
  32. package/lib/engine/engine_types.js.map +1 -1
  33. package/lib/engine/webcomponents/icons.js +3 -0
  34. package/lib/engine/webcomponents/icons.js.map +1 -1
  35. package/lib/engine/webcomponents/logo-element.d.ts +1 -0
  36. package/lib/engine/webcomponents/logo-element.js +3 -1
  37. package/lib/engine/webcomponents/logo-element.js.map +1 -1
  38. package/lib/engine/webcomponents/needle-button.d.ts +37 -11
  39. package/lib/engine/webcomponents/needle-button.js +42 -11
  40. package/lib/engine/webcomponents/needle-button.js.map +1 -1
  41. package/lib/engine/webcomponents/needle-engine.d.ts +10 -2
  42. package/lib/engine/webcomponents/needle-engine.js +13 -3
  43. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  44. package/lib/engine-components/Component.d.ts +1 -2
  45. package/lib/engine-components/Component.js +1 -2
  46. package/lib/engine-components/Component.js.map +1 -1
  47. package/lib/engine-components/DragControls.d.ts +1 -0
  48. package/lib/engine-components/DragControls.js +21 -0
  49. package/lib/engine-components/DragControls.js.map +1 -1
  50. package/lib/engine-components/GroundProjection.js.map +1 -1
  51. package/lib/engine-components/NeedleMenu.d.ts +2 -0
  52. package/lib/engine-components/NeedleMenu.js +2 -0
  53. package/lib/engine-components/NeedleMenu.js.map +1 -1
  54. package/lib/engine-components/Networking.d.ts +28 -3
  55. package/lib/engine-components/Networking.js +28 -3
  56. package/lib/engine-components/Networking.js.map +1 -1
  57. package/lib/engine-components/ReflectionProbe.d.ts +1 -0
  58. package/lib/engine-components/ReflectionProbe.js +21 -3
  59. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  60. package/lib/engine-components/RendererLightmap.js +1 -1
  61. package/lib/engine-components/RendererLightmap.js.map +1 -1
  62. package/lib/engine-components/SeeThrough.js +1 -1
  63. package/lib/engine-components/SeeThrough.js.map +1 -1
  64. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.d.ts +107 -13
  65. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js +167 -30
  66. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -1
  67. package/lib/engine-components/ui/Button.d.ts +1 -0
  68. package/lib/engine-components/ui/Button.js +11 -0
  69. package/lib/engine-components/ui/Button.js.map +1 -1
  70. package/lib/engine-components/ui/Text.d.ts +1 -0
  71. package/lib/engine-components/ui/Text.js +11 -0
  72. package/lib/engine-components/ui/Text.js.map +1 -1
  73. package/lib/engine-components/web/ViewBox.js.map +1 -1
  74. package/package.json +2 -2
  75. package/src/engine/api.ts +371 -19
  76. package/src/engine/engine_accessibility.ts +178 -0
  77. package/src/engine/engine_context.ts +9 -0
  78. package/src/engine/engine_materialpropertyblock.ts +103 -12
  79. package/src/engine/engine_math.ts +34 -1
  80. package/src/engine/engine_networking.ts +1 -1
  81. package/src/engine/engine_types.ts +5 -0
  82. package/src/engine/webcomponents/icons.ts +3 -0
  83. package/src/engine/webcomponents/logo-element.ts +4 -1
  84. package/src/engine/webcomponents/needle-button.ts +44 -13
  85. package/src/engine/webcomponents/needle-engine.ts +18 -7
  86. package/src/engine-components/Component.ts +1 -3
  87. package/src/engine-components/DragControls.ts +29 -4
  88. package/src/engine-components/GroundProjection.ts +1 -1
  89. package/src/engine-components/NeedleMenu.ts +5 -3
  90. package/src/engine-components/Networking.ts +29 -4
  91. package/src/engine-components/ReflectionProbe.ts +22 -3
  92. package/src/engine-components/RendererLightmap.ts +1 -1
  93. package/src/engine-components/SeeThrough.ts +1 -1
  94. package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +198 -65
  95. package/src/engine-components/ui/Button.ts +12 -0
  96. package/src/engine-components/ui/Text.ts +13 -0
  97. package/src/engine-components/web/ViewBox.ts +3 -3
package/src/engine/api.ts CHANGED
@@ -1,87 +1,439 @@
1
1
  /**
2
- * Contains core functionality for Needle Engine.
3
- * This includes
4
- * - Context Management
5
- * - Asset Loading
6
- * - Component Lifecycle
7
- * - Time Handling
8
- * - XR support
9
- * - Unified Input Handling
10
- * - Needle Menu
11
- * - Networking
12
- * - Physics, Collisions, Raycasting
13
- * - Math and Filtering Helpers
14
- * - Rendering Utilities
15
- * - Debugging Utilities, Gizmos
16
- * - User agent detection
17
- * - and more.
18
- *
2
+ * The Engine Core API is the main entry point for Needle Engine functionality.
3
+ * It provides a unified interface for building interactive 3D web experiences
4
+ * with features spanning rendering, physics, networking, XR, and more.
5
+ *
6
+ * ## Quick Start
7
+ * ```typescript
8
+ * import { Context, Behaviour, serializable } from "@needle-tools/engine";
9
+ *
10
+ * class MyComponent extends Behaviour {
11
+ * @serializable()
12
+ * speed: number = 1;
13
+ *
14
+ * update() {
15
+ * this.gameObject.rotateY(this.context.time.deltaTime * this.speed);
16
+ * }
17
+ * }
18
+ * ```
19
+ *
20
+ * ## Module Categories
21
+ *
22
+ * ### Context & Application
23
+ * The {@link Context} class is the central hub that manages the scene, renderer, camera,
24
+ * and all engine systems. Access it via `this.context` in any component.
25
+ * - {@link Context} - Main engine context managing scene, renderer, and systems
26
+ * - {@link ContextRegistry} - Registry for multiple engine contexts
27
+ * - {@link Application} - Application-level utilities and state
28
+ *
29
+ * ### Components & GameObjects
30
+ * Needle Engine uses a component-based architecture similar to Unity.
31
+ * Components are attached to three.js Object3D instances (GameObjects).
32
+ * - {@link addComponent}, {@link getComponent}, {@link removeComponent} - Component management
33
+ * - {@link findObjectOfType}, {@link findObjectsOfType} - Scene queries
34
+ * - {@link instantiate}, {@link destroy} - Object lifecycle
35
+ * @see {@link https://engine.needle.tools/docs/scripting.html | Scripting Documentation}
36
+ *
37
+ * ### Asset Loading
38
+ * Load glTF/GLB files, textures, and other assets at runtime.
39
+ * - {@link loadSync}, {@link parseSync} - Load glTF/GLB assets
40
+ * - {@link AssetDatabase} - Asset reference management
41
+ * - {@link Addressables} - Addressable asset system
42
+ * @see {@link https://engine.needle.tools/docs/addressables.html | Addressables Documentation}
43
+ *
44
+ * ### Input System
45
+ * Unified input handling for mouse, touch, keyboard, and XR controllers.
46
+ * Access via `this.context.input` in components.
47
+ * - {@link Input} - Unified input manager
48
+ * - {@link NEPointerEvent} - Cross-platform pointer events
49
+ * - {@link InputEvents} - Event types for input listeners
50
+ * @see {@link https://engine.needle.tools/docs/input.html | Input Documentation}
51
+ *
52
+ * ### Physics & Raycasting
53
+ * Rapier-based physics engine with collision detection and raycasting.
54
+ * - {@link Physics} - Physics world access and raycasting
55
+ * - {@link RaycastOptions} - Configure raycast behavior
56
+ * - {@link Collision}, {@link ContactPoint} - Collision data types
57
+ * @see {@link https://engine.needle.tools/docs/physics.html | Physics Documentation}
58
+ *
59
+ * ### Networking
60
+ * Real-time multiplayer networking with automatic state synchronization.
61
+ * - {@link NetworkConnection} - WebSocket connection management
62
+ * - {@link RoomEvents} - Room join/leave events
63
+ * - {@link syncField} - Decorator for automatic field synchronization
64
+ * - {@link PeerNetworking} - WebRTC peer-to-peer connections
65
+ * @see {@link https://engine.needle.tools/docs/networking.html | Networking Documentation}
66
+ *
67
+ * ### XR (AR/VR)
68
+ * WebXR support for augmented and virtual reality experiences.
69
+ * - {@link NeedleXRSession} - XR session management
70
+ * - {@link NeedleXRController} - XR controller input and tracking
71
+ * - {@link XRRig} - XR camera rig configuration
72
+ * @see {@link https://engine.needle.tools/docs/xr.html | XR Documentation}
73
+ *
74
+ * ### Time & Animation
75
+ * Frame timing and animation utilities.
76
+ * - {@link Time} - Delta time, frame count, time scale
77
+ * - {@link AnimationUtils} - Animation playback helpers
78
+ * - Coroutines via {@link startCoroutine} for async sequences
79
+ *
80
+ * ### Debugging & Gizmos
81
+ * Visual debugging tools for development.
82
+ * - {@link Gizmos} - Draw debug shapes (lines, spheres, boxes)
83
+ * - {@link showBalloonMessage}, {@link showBalloonWarning} - On-screen messages
84
+ * - {@link isDevEnvironment} - Check if running in development mode
85
+ *
86
+ * ### Utilities
87
+ * Helper functions for common operations.
88
+ * - {@link getParam} - URL parameter parsing
89
+ * - {@link delay} - Promise-based delay
90
+ * - {@link generateQRCode} - QR code generation
91
+ * - Math utilities: {@link Mathf}, vector operations
92
+ *
19
93
  * @module Engine Core
94
+ * @see {@link https://engine.needle.tools/docs/ | Needle Engine Documentation}
20
95
  */
21
96
 
97
+
98
+ // ============================================================================
99
+ // DEBUGGING & DEVELOPMENT
100
+ // Debugging utilities, gizmos, and development tools.
101
+ // ============================================================================
102
+
22
103
  export * from "./debug/index.js";
104
+
105
+
106
+ // ============================================================================
107
+ // ASSET LOADING & MANAGEMENT
108
+ // Systems for loading, managing, and referencing assets at runtime.
109
+ // ============================================================================
110
+
111
+ /** Addressable asset system for loading assets by address/label */
23
112
  export * from "./engine_addressables.js";
113
+
114
+ /** Animation playback and control utilities */
24
115
  export { AnimationUtils } from "./engine_animation.js";
116
+
117
+ /** Application-level state and utilities */
25
118
  export { Application } from "./engine_application.js";
119
+
120
+ /** Asset database for managing asset references */
26
121
  export * from "./engine_assetdatabase.js";
122
+
123
+
124
+ // ============================================================================
125
+ // CAMERA & RENDERING
126
+ // Camera control, rendering utilities, and visual effects.
127
+ // ============================================================================
128
+
129
+ /** Camera fitting utilities for framing objects */
27
130
  export * from "./engine_camera.fit.js";
131
+
132
+ /** Camera controller management and auto-fit configuration */
28
133
  export { getCameraController, setAutoFitEnabled, setCameraController, useForAutoFit } from "./engine_camera.js";
134
+
135
+
136
+ // ============================================================================
137
+ // COMPONENTS & GAMEOBJECTS
138
+ // Component-based architecture for building interactive 3D content.
139
+ // Functions for adding, removing, and querying components on objects.
140
+ // ============================================================================
141
+
142
+ /**
143
+ * Component management functions: addComponent, getComponent, removeComponent, etc.
144
+ * @see {@link https://engine.needle.tools/docs/scripting.html | Scripting Documentation}
145
+ */
29
146
  export * from "./engine_components.js";
147
+
148
+ /** Internal component lifecycle events and management */
30
149
  export * from "./engine_components_internal.js";
31
- export * from "./engine_components_internal.js";
150
+
151
+ /** Engine constants and configuration values */
32
152
  export * from "./engine_constants.js";
153
+
154
+
155
+ // ============================================================================
156
+ // CONTEXT & LIFECYCLE
157
+ // Core engine context and application lifecycle management.
158
+ // ============================================================================
159
+
160
+ /**
161
+ * Main engine context class - the central hub for all engine systems.
162
+ * Provides access to scene, renderer, camera, input, physics, networking, and more.
163
+ * @see {@link https://engine.needle.tools/docs/scripting.html#context | Context Documentation}
164
+ */
33
165
  export * from "./engine_context.js";
166
+
167
+ /** Registry for managing multiple engine contexts */
34
168
  export * from "./engine_context_registry.js";
169
+
170
+ /**
171
+ * Coroutine system for async sequences in components.
172
+ * Use startCoroutine() for frame-based async operations.
173
+ */
35
174
  export * from "./engine_coroutine.js"
175
+
176
+ /** Factory functions for creating primitives and objects */
36
177
  export * from "./engine_create_objects.js";
178
+
179
+ /** Feature flags for enabling/disabling engine features */
37
180
  export * from "./engine_feature_flags.js"
181
+
182
+ /**
183
+ * GameObject utilities: instantiate, destroy, find, traverse.
184
+ * @see {@link https://engine.needle.tools/docs/scripting.html#finding-objects | Finding Objects}
185
+ */
38
186
  export * from "./engine_gameobject.js";
187
+
188
+ /**
189
+ * Visual debugging with Gizmos - draw lines, spheres, boxes for debugging.
190
+ * @see {@link https://engine.needle.tools/docs/debugging.html | Debugging Documentation}
191
+ */
39
192
  export { Gizmos } from "./engine_gizmos.js"
193
+
194
+ /** glTF/GLB loader registration and management */
40
195
  export * from "./engine_gltf.js";
196
+
197
+ /** Hot reload support for development */
41
198
  export * from "./engine_hot_reload.js";
199
+
200
+
201
+ // ============================================================================
202
+ // INPUT SYSTEM
203
+ // Unified input handling for mouse, touch, keyboard, and XR controllers.
204
+ // ============================================================================
205
+
206
+ /**
207
+ * Unified input system supporting mouse, touch, keyboard, and XR controllers.
208
+ * Access via this.context.input in components.
209
+ * @see {@link https://engine.needle.tools/docs/input.html | Input Documentation}
210
+ */
42
211
  export * from "./engine_input.js";
212
+
213
+
214
+ // ============================================================================
215
+ // INSTANCING & PERFORMANCE
216
+ // GPU instancing and performance optimization utilities.
217
+ // ============================================================================
218
+
219
+ /** GPU instancing utilities for rendering many similar objects efficiently */
43
220
  export { InstancingUtil } from "./engine_instancing.js";
221
+
222
+ /** License checking utilities */
44
223
  export { hasCommercialLicense, hasIndieLicense, hasProLicense } from "./engine_license.js";
224
+
225
+
226
+ // ============================================================================
227
+ // LIFECYCLE & LOADING
228
+ // Component lifecycle hooks and asset loading systems.
229
+ // ============================================================================
230
+
231
+ /** Lifecycle API for registering global callbacks */
45
232
  export * from "./engine_lifecycle_api.js";
233
+
234
+ /** Model loader callbacks for customizing load behavior */
46
235
  export { NeedleEngineModelLoader } from "./engine_loaders.callbacks.js";
236
+
237
+ /**
238
+ * Asset loading functions: loadSync, parseSync for glTF/GLB files.
239
+ * @see {@link https://engine.needle.tools/docs/addressables.html | Loading Assets}
240
+ */
47
241
  export { loadAsset, loadSync, parseSync } from "./engine_loaders.js";
242
+
243
+
244
+ // ============================================================================
245
+ // MATERIALS & RENDERING
246
+ // Material utilities and rendering helpers.
247
+ // ============================================================================
248
+
249
+ /** MaterialPropertyBlock for efficient material property overrides per-instance */
250
+ export { MaterialPropertyBlock } from "./engine_materialpropertyblock.js"
251
+
252
+ /** Math utilities: Mathf, interpolation, easing functions */
48
253
  export * from "./engine_math.js";
254
+
255
+ /** Engine modules registry */
49
256
  export { MODULES as NEEDLE_ENGINE_MODULES } from "./engine_modules.js";
257
+
258
+
259
+ // ============================================================================
260
+ // NETWORKING
261
+ // Real-time multiplayer networking with WebSocket and WebRTC support.
262
+ // ============================================================================
263
+
264
+ /**
265
+ * Core networking: NetworkConnection, RoomEvents, OwnershipEvent.
266
+ * @see {@link https://engine.needle.tools/docs/networking.html | Networking Documentation}
267
+ */
50
268
  export * from "./engine_networking.js";
269
+
270
+ /**
271
+ * @syncField decorator for automatic field synchronization across clients.
272
+ * @see {@link https://engine.needle.tools/docs/networking.html#synced-variables | Synced Variables}
273
+ */
51
274
  export { syncField } from "./engine_networking_auto.js";
275
+
276
+ /** Blob/binary data transfer over network */
52
277
  export * from "./engine_networking_blob.js";
278
+
279
+ /** File transfer utilities for networking */
53
280
  export * from "./engine_networking_files.js";
281
+
282
+ /**
283
+ * Network instantiation for spawning synced objects.
284
+ * @see {@link https://engine.needle.tools/docs/networking.html#spawning-objects | Spawning Objects}
285
+ */
54
286
  export * from "./engine_networking_instantiate.js";
287
+
288
+ /** WebRTC peer-to-peer networking for direct client connections */
55
289
  export * from "./engine_networking_peer.js";
290
+
291
+ /** Media streaming utilities (audio/video) */
56
292
  export * from "./engine_networking_streams.js";
293
+
294
+ /** Networking type definitions and interfaces */
57
295
  export * from "./engine_networking_types.js";
296
+
297
+ /** Networking utility functions */
58
298
  export * from "./engine_networking_utils.js";
59
- export { MaterialPropertyBlock } from "./engine_materialpropertyblock.js"
299
+
300
+
301
+ // ============================================================================
302
+ // PHYSICS & RAYCASTING
303
+ // Rapier-based physics simulation and raycasting.
304
+ // ============================================================================
305
+
306
+ /** Object patching utilities */
60
307
  export * from "./engine_patcher.js";
308
+
309
+ /**
310
+ * Physics system: raycasting, collision queries, physics world access.
311
+ * @see {@link https://engine.needle.tools/docs/physics.html | Physics Documentation}
312
+ */
61
313
  export * from "./engine_physics.js";
314
+
315
+ /** Physics type definitions: RaycastOptions, Collision, ContactPoint */
62
316
  export * from "./engine_physics.types.js";
317
+
318
+ /** Rapier physics engine integration */
63
319
  export * from "./engine_physics_rapier.js";
320
+
321
+
322
+ // ============================================================================
323
+ // PLAYER & VIEW MANAGEMENT
324
+ // Multi-player view management and scene lighting.
325
+ // ============================================================================
326
+
327
+ /** Player view management for multi-user scenarios */
64
328
  export * from "./engine_playerview.js";
329
+
330
+ /** PMREM (Prefiltered Mipmapped Radiance Environment Map) loading */
65
331
  export { loadPMREM } from "./engine_pmrem.js";
332
+
333
+ /** Scene lighting data and environment configuration */
66
334
  export * from "./engine_scenelighting.js";
335
+
336
+
337
+ // ============================================================================
338
+ // SERIALIZATION
339
+ // Component serialization for saving/loading and networking.
340
+ // ============================================================================
341
+
342
+ /**
343
+ * Serialization utilities for components and objects.
344
+ * @see {@link https://engine.needle.tools/docs/scripting.html#serialization | Serialization Documentation}
345
+ */
67
346
  export * from "./engine_serialization.js";
347
+
348
+ /** Serialization core interfaces */
68
349
  export { type ISerializable } from "./engine_serialization_core.js";
350
+
351
+
352
+ // ============================================================================
353
+ // UTILITIES & HELPERS
354
+ // General-purpose utility functions and helpers.
355
+ // ============================================================================
356
+
357
+ /** Testing utilities for automated tests */
69
358
  export * from "./engine_test_utils.js";
359
+
360
+ /** Texture utilities and processing */
70
361
  export * from "./engine_texture.js";
362
+
363
+ /** Three.js helper utilities: getWorldPosition, getTempVector, etc. */
71
364
  export * from "./engine_three_utils.js";
365
+
366
+ /**
367
+ * Time class: deltaTime, time, frameCount, timeScale.
368
+ * Access via this.context.time in components.
369
+ */
72
370
  export * from "./engine_time.js";
371
+
372
+ /** Time-related utility functions */
73
373
  export * from "./engine_time_utils.js";
374
+
375
+ /** Core type definitions and interfaces */
74
376
  export * from "./engine_types.js";
377
+
378
+ /** Type registration for component discovery */
75
379
  export { registerType, TypeStore } from "./engine_typestore.js";
380
+
381
+ /** Decorator utilities: @prefix, @validate */
76
382
  export { prefix, validate } from "./engine_util_decorator.js";
383
+
384
+ /** General utilities: getParam, delay, DeviceUtilities, etc. */
77
385
  export * from "./engine_utils.js";
386
+
387
+ /** Formatting utilities for strings and numbers */
78
388
  export * from "./engine_utils_format.js";
389
+
390
+ /** QR code generation utility */
79
391
  export { generateQRCode } from "./engine_utils_qrcode.js";
392
+
393
+ /** Screenshot capture utilities */
80
394
  export * from "./engine_utils_screenshot.js";
395
+
396
+
397
+ // ============================================================================
398
+ // EXTENSIONS & INTEGRATIONS
399
+ // glTF extensions and JavaScript object extensions.
400
+ // ============================================================================
401
+
402
+ /** Export utilities and formats */
81
403
  export * from "./export/index.js";
404
+
405
+ /** glTF extension implementations (NEEDLE_components, etc.) */
82
406
  export * from "./extensions/index.js";
407
+
408
+ /** JavaScript object extensions for three.js objects */
83
409
  export * from "./js-extensions/index.js";
410
+
411
+
412
+ // ============================================================================
413
+ // WEB COMPONENTS
414
+ // Custom HTML elements for embedding Needle Engine.
415
+ // ============================================================================
416
+
417
+ /** Web component API utilities */
84
418
  export * from "./webcomponents/api.js"
419
+
420
+ /**
421
+ * <needle-engine> web component for embedding 3D scenes.
422
+ * @see {@link https://engine.needle.tools/docs/html.html | HTML Integration}
423
+ */
85
424
  export * from "./webcomponents/needle-engine.js";
425
+
426
+ /** Loading screen and progress indicators */
86
427
  export * from "./webcomponents/needle-engine.loading.js";
428
+
429
+
430
+ // ============================================================================
431
+ // XR (AR/VR)
432
+ // WebXR support for augmented and virtual reality experiences.
433
+ // ============================================================================
434
+
435
+ /**
436
+ * XR API: NeedleXRSession, NeedleXRController, XRRig.
437
+ * @see {@link https://engine.needle.tools/docs/xr.html | XR Documentation}
438
+ */
87
439
  export * from "./xr/api.js"
@@ -0,0 +1,178 @@
1
+ import { Object3D } from "three";
2
+ import type { Context } from "./engine_setup";
3
+ import { IComponent, isComponent } from "./engine_types";
4
+
5
+
6
+
7
+ /** Data describing the accessible semantics for a 3D object or component. */
8
+ type AccessibilityData = {
9
+ /** ARIA role (e.g. `"button"`, `"img"`, `"region"`). */
10
+ role: string;
11
+ /** Human-readable label announced by screen readers. */
12
+ label: string;
13
+ /** When `true`, the element is hidden from the accessibility tree. */
14
+ hidden?: boolean;
15
+ /** When `true`, indicates the element's content is being updated. */
16
+ busy?: boolean;
17
+ }
18
+
19
+ /**
20
+ * Manages an accessible, screen-reader-friendly overlay for a Needle Engine {@link Context}.
21
+ *
22
+ * The manager maintains a visually-hidden DOM tree that mirrors relevant 3D scene objects
23
+ * with appropriate ARIA roles and labels. It also provides a live region so that hover
24
+ * events in the 3D scene can be announced to assistive technology without stealing focus.
25
+ */
26
+ export class AccessibilityManager {
27
+
28
+ private static readonly _managers: WeakMap<object, AccessibilityManager> = new WeakMap();
29
+
30
+ /** Returns the {@link AccessibilityManager} associated with the given context or component. */
31
+ static get(obj: Context | IComponent) {
32
+ if (isComponent(obj)) {
33
+ return this._managers.get(obj.context);
34
+ }
35
+ else {
36
+ return this._managers.get(obj);
37
+ }
38
+ }
39
+
40
+ constructor(
41
+ private readonly context: Context
42
+ ) {
43
+ this.root.style.cssText = `
44
+ position: absolute;
45
+ width: 1px; height: 1px;
46
+ padding: 0; margin: -1px;
47
+ overflow: hidden;
48
+ clip: rect(0, 0, 0, 0);
49
+ white-space: nowrap;
50
+ border: 0;
51
+ `
52
+ this.root.setAttribute("role", "region");
53
+ this.root.setAttribute("aria-label", "3D Needle Engine scene");
54
+
55
+ // Live region for announcing hovered 3D elements without stealing focus
56
+ this.liveRegion.setAttribute("aria-live", "polite");
57
+ this.liveRegion.setAttribute("aria-atomic", "true");
58
+ this.liveRegion.setAttribute("role", "status");
59
+ this.root.appendChild(this.liveRegion);
60
+ this.enabled = true;
61
+ }
62
+
63
+ private _enabled!: boolean;
64
+ /** Enables or disables the accessibility overlay. When disabled, the overlay DOM is removed. */
65
+ set enabled(value: boolean) {
66
+ if (value === this._enabled) return;
67
+ this._enabled = value;
68
+ if (!value) {
69
+ this.root.remove();
70
+ }
71
+ else {
72
+ AccessibilityManager._managers.set(this.context, this);
73
+ const target = this.context.domElement.shadowRoot || this.context.domElement;
74
+ target.prepend(this.root);
75
+ }
76
+ }
77
+
78
+ /** Removes all tracked accessibility elements, keeping only the live region. */
79
+ clear() {
80
+ this.root.childNodes.forEach(child => child.remove());
81
+ this.root.appendChild(this.liveRegion);
82
+ }
83
+
84
+ /** Removes the overlay from the DOM and unregisters this manager from the context. */
85
+ dispose() {
86
+ this.root.remove();
87
+ AccessibilityManager._managers.delete(this.context);
88
+ }
89
+
90
+ private readonly root: HTMLElement = document.createElement("div");
91
+ private readonly liveRegion: HTMLElement = document.createElement("div");
92
+ private readonly treeElements = new WeakMap<object, HTMLElement>();
93
+
94
+ /**
95
+ * Creates or updates the accessible DOM element for a 3D object or component.
96
+ * @param obj - The scene object or component to represent.
97
+ * @param data - Partial accessibility data (role, label, hidden, busy) to apply.
98
+ */
99
+ updateElement<T extends Object3D | IComponent>(obj: T, data: Partial<AccessibilityData>) {
100
+ let el = this.treeElements.get(obj);
101
+ if (!el) {
102
+ el = document.createElement("div");
103
+ this.treeElements.set(obj, el);
104
+ this.root.appendChild(el);
105
+
106
+
107
+ let didSetRole = false;
108
+
109
+ if (typeof data === "object") {
110
+ if (data.role) {
111
+ didSetRole = true;
112
+ el.setAttribute("role", data.role);
113
+ }
114
+ if (data.label) {
115
+ el.setAttribute("aria-label", data.label);
116
+ }
117
+ if (data.hidden !== undefined) {
118
+ el.setAttribute("aria-hidden", String(data.hidden));
119
+ }
120
+ if (data.busy !== undefined) {
121
+ el.setAttribute("aria-busy", String(data.busy));
122
+ }
123
+ }
124
+
125
+
126
+ // if (didSetRole) {
127
+ // const role = el.getAttribute("role");
128
+ // if (role) {
129
+ // el.setAttribute("tabindex", "0");
130
+ // } else {
131
+ // el.removeAttribute("tabindex");
132
+ // }
133
+ // }
134
+
135
+ }
136
+ }
137
+
138
+ /** Moves keyboard focus to the accessible element representing the given object. */
139
+ focus<T extends Object3D | IComponent>(obj: T) {
140
+ const el = this.treeElements.get(obj);
141
+ if (el) {
142
+ // if (!el.hasAttribute("tabindex")) {
143
+ // el.setAttribute("tabindex", "0");
144
+ // }
145
+ el.focus();
146
+ }
147
+ }
148
+ /** Removes keyboard focus from the accessible element representing the given object. */
149
+ unfocus<T extends Object3D | IComponent>(obj: T) {
150
+ const el = this.treeElements.get(obj);
151
+ if (el) {
152
+ el.blur();
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Announces a hover event to screen readers via the ARIA live region.
158
+ * @param obj - The hovered object (used to look up its label if `text` is not provided).
159
+ * @param text - Optional text to announce. Falls back to the element's `aria-label`.
160
+ */
161
+ hover<T extends Object3D | IComponent>(obj: T, text?: string) {
162
+ const el = this.treeElements.get(obj);
163
+ // Update the live region text — screen reader announces this without stealing focus
164
+ this.liveRegion.textContent = text || el?.getAttribute("aria-label") || "";
165
+ }
166
+
167
+ /** Removes the accessible DOM element for the given object and stops tracking it. */
168
+ removeElement(obj: Object3D | IComponent) {
169
+ const el = this.treeElements.get(obj);
170
+ el?.remove();
171
+ this.treeElements.delete(obj);
172
+ }
173
+
174
+ private set liveRegionMode(mode: "polite" | "assertive") {
175
+ this.liveRegion.setAttribute("aria-live", mode);
176
+ }
177
+
178
+ }
@@ -44,6 +44,7 @@ import { deepClone, delay, DeviceUtilities, getParam } from './engine_utils.js';
44
44
  import type { INeedleXRSessionEventReceiver, NeedleXRSession } from './engine_xr.js';
45
45
  import { NeedleMenu } from './webcomponents/needle menu/needle-menu.js';
46
46
  import type { NeedleEngineWebComponent } from './webcomponents/needle-engine.js';
47
+ import { AccessibilityManager } from './engine_accessibility.js';
47
48
 
48
49
  const debug = getParam("debugcontext");
49
50
  const stats = getParam("stats");
@@ -522,6 +523,8 @@ export class Context implements IContext {
522
523
  /** Access the needle menu to add or remove buttons to the menu element */
523
524
  readonly menu: NeedleMenu;
524
525
 
526
+ readonly accessibility: AccessibilityManager;
527
+
525
528
  /**
526
529
  * Checks if the context is fully created and ready
527
530
  * @returns true if the context is fully created and ready
@@ -571,6 +574,7 @@ export class Context implements IContext {
571
574
  this.menu = new NeedleMenu(this);
572
575
  this.lodsManager = new LODsManager(this);
573
576
  this.animations = new AnimationsRegistry(this);
577
+ this.accessibility = new AccessibilityManager(this);
574
578
 
575
579
 
576
580
  const resizeCallback = () => this._needsUpdateSize = true;
@@ -614,6 +618,9 @@ export class Context implements IContext {
614
618
 
615
619
  this.renderer = new WebGLRenderer(params);
616
620
 
621
+ this.renderer.domElement.setAttribute("aria-label", "3D rendering");
622
+ this.renderer.domElement.setAttribute("role", "img");
623
+
617
624
  this.renderer.debug.checkShaderErrors = isDevEnvironment() || getParam("checkshadererrors") === true;
618
625
 
619
626
  // some tonemapping other than "NONE" is required for adjusting exposure with EXR environments
@@ -810,6 +817,7 @@ export class Context implements IContext {
810
817
  this.lightmaps?.clear();
811
818
  this.physics?.engine?.clearCaches();
812
819
  this.lodsManager.disable();
820
+ this.accessibility?.clear();
813
821
 
814
822
  this._onBeforeRenderListeners.clear();
815
823
  this._onAfterRenderListeners.clear();
@@ -831,6 +839,7 @@ export class Context implements IContext {
831
839
  */
832
840
  dispose() {
833
841
  this.internalOnDestroy();
842
+ this.accessibility.dispose();
834
843
  }
835
844
 
836
845
  /**@deprecated use dispose() */