lecodes-sdk 0.19.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 (367) hide show
  1. package/README.md +114 -0
  2. package/dist/global.d.ts +503 -0
  3. package/dist/host.d.ts +61 -0
  4. package/dist/inject.js +4730 -0
  5. package/dist/types/animate/animate.d.ts +20 -0
  6. package/dist/types/animate/bezier.d.ts +2 -0
  7. package/dist/types/animate/easings.d.ts +21 -0
  8. package/dist/types/canvas/Canvas.d.ts +168 -0
  9. package/dist/types/core/Aspect.d.ts +171 -0
  10. package/dist/types/core/InspectorUI.d.ts +88 -0
  11. package/dist/types/core/StateMachine.d.ts +81 -0
  12. package/dist/types/core/color.d.ts +13 -0
  13. package/dist/types/core/compWrite.d.ts +11 -0
  14. package/dist/types/core/events.d.ts +11 -0
  15. package/dist/types/core/fields.d.ts +58 -0
  16. package/dist/types/core/registry.d.ts +7 -0
  17. package/dist/types/core/signals.d.ts +29 -0
  18. package/dist/types/core/time.d.ts +31 -0
  19. package/dist/types/g2/Camera2D.d.ts +19 -0
  20. package/dist/types/g2/CharacterController2D.d.ts +134 -0
  21. package/dist/types/g2/Node2D.d.ts +91 -0
  22. package/dist/types/g2/OneWay2D.d.ts +24 -0
  23. package/dist/types/g2/Physics2D.d.ts +147 -0
  24. package/dist/types/g2/Scene2D.d.ts +72 -0
  25. package/dist/types/g2/Shape2D.d.ts +58 -0
  26. package/dist/types/g2/Sprite.d.ts +51 -0
  27. package/dist/types/g2/SpriteAnimation.d.ts +50 -0
  28. package/dist/types/g2/SpriteSheet.d.ts +69 -0
  29. package/dist/types/g2/Texture2D.d.ts +16 -0
  30. package/dist/types/g2/Tilemap.d.ts +20 -0
  31. package/dist/types/g2/Tileset.d.ts +32 -0
  32. package/dist/types/g2/Trigger2D.d.ts +20 -0
  33. package/dist/types/g2/autotile.d.ts +133 -0
  34. package/dist/types/g2/cells.d.ts +14 -0
  35. package/dist/types/g2/defineScene2d.d.ts +141 -0
  36. package/dist/types/g2/groups2d.d.ts +16 -0
  37. package/dist/types/g2/loop.d.ts +4 -0
  38. package/dist/types/g2/scenarios2d.d.ts +30 -0
  39. package/dist/types/g2/touch.d.ts +2 -0
  40. package/dist/types/gl/Camera.d.ts +79 -0
  41. package/dist/types/gl/CameraPlace.d.ts +26 -0
  42. package/dist/types/gl/CharacterController.d.ts +98 -0
  43. package/dist/types/gl/Gearbox.d.ts +86 -0
  44. package/dist/types/gl/Geometry.d.ts +39 -0
  45. package/dist/types/gl/IK.d.ts +53 -0
  46. package/dist/types/gl/InstancedMesh.d.ts +46 -0
  47. package/dist/types/gl/Light.d.ts +73 -0
  48. package/dist/types/gl/Lightmap.d.ts +85 -0
  49. package/dist/types/gl/Locomotion.d.ts +279 -0
  50. package/dist/types/gl/Material.d.ts +100 -0
  51. package/dist/types/gl/Mesh.d.ts +33 -0
  52. package/dist/types/gl/Model.d.ts +53 -0
  53. package/dist/types/gl/NavAgent.d.ts +99 -0
  54. package/dist/types/gl/NavMesh.d.ts +169 -0
  55. package/dist/types/gl/Node.d.ts +99 -0
  56. package/dist/types/gl/Noise.d.ts +20 -0
  57. package/dist/types/gl/Particles.d.ts +277 -0
  58. package/dist/types/gl/Physics.d.ts +91 -0
  59. package/dist/types/gl/Plane.d.ts +19 -0
  60. package/dist/types/gl/Ragdoll.d.ts +86 -0
  61. package/dist/types/gl/Ray.d.ts +8 -0
  62. package/dist/types/gl/Scene.d.ts +221 -0
  63. package/dist/types/gl/Shape.d.ts +122 -0
  64. package/dist/types/gl/Terrain.d.ts +280 -0
  65. package/dist/types/gl/Texture.d.ts +27 -0
  66. package/dist/types/gl/Trigger.d.ts +10 -0
  67. package/dist/types/gl/Vehicle.d.ts +191 -0
  68. package/dist/types/gl/Wheel.d.ts +95 -0
  69. package/dist/types/gl/animation/AnimationClip.d.ts +60 -0
  70. package/dist/types/gl/animation/Animator.d.ts +219 -0
  71. package/dist/types/gl/animation/Layer.d.ts +31 -0
  72. package/dist/types/gl/animation/Loop.d.ts +17 -0
  73. package/dist/types/gl/animation/Playback.d.ts +36 -0
  74. package/dist/types/gl/animation/core.d.ts +367 -0
  75. package/dist/types/gl/controls.d.ts +19 -0
  76. package/dist/types/gl/physicsEvents.d.ts +1 -0
  77. package/dist/types/gl/scenarios.d.ts +98 -0
  78. package/dist/types/gl/state.d.ts +5 -0
  79. package/dist/types/gl/terrainMesh.d.ts +46 -0
  80. package/dist/types/gl/touch.d.ts +2 -0
  81. package/dist/types/inject.d.ts +123 -0
  82. package/dist/types/math/Mathf.d.ts +39 -0
  83. package/dist/types/math/mat4.d.ts +66 -0
  84. package/dist/types/math/quat.d.ts +53 -0
  85. package/dist/types/math/vec.d.ts +129 -0
  86. package/dist/types/net/codec.d.ts +25 -0
  87. package/dist/types/net/core.d.ts +106 -0
  88. package/dist/types/net/index.d.ts +80 -0
  89. package/dist/types/net/replication.d.ts +101 -0
  90. package/dist/types/plugins/camera.d.ts +25 -0
  91. package/dist/types/plugins/geolocation.d.ts +39 -0
  92. package/dist/types/plugins/oauth.d.ts +25 -0
  93. package/dist/types/plugins/permission.d.ts +1 -0
  94. package/dist/types/plugins/push.d.ts +46 -0
  95. package/dist/types/plugins/qr.d.ts +21 -0
  96. package/dist/types/plugins/service.d.ts +33 -0
  97. package/dist/types/runtime/app.d.ts +67 -0
  98. package/dist/types/runtime/appEvents.d.ts +7 -0
  99. package/dist/types/runtime/channel.d.ts +1 -0
  100. package/dist/types/runtime/clipboard.d.ts +7 -0
  101. package/dist/types/runtime/datetime.d.ts +80 -0
  102. package/dist/types/runtime/device.d.ts +126 -0
  103. package/dist/types/runtime/fetch.d.ts +31 -0
  104. package/dist/types/runtime/files.d.ts +33 -0
  105. package/dist/types/runtime/input.d.ts +121 -0
  106. package/dist/types/runtime/media.d.ts +46 -0
  107. package/dist/types/runtime/misc.d.ts +11 -0
  108. package/dist/types/runtime/net.d.ts +15 -0
  109. package/dist/types/runtime/rpc.d.ts +44 -0
  110. package/dist/types/runtime/service.d.ts +1 -0
  111. package/dist/types/runtime/share.d.ts +2 -0
  112. package/dist/types/runtime/storage.d.ts +5 -0
  113. package/dist/types/runtime/touch.d.ts +56 -0
  114. package/dist/types/scene/defineScene.d.ts +296 -0
  115. package/dist/types/scene/editorPlugins.d.ts +82 -0
  116. package/dist/types/scene/gizmos.d.ts +56 -0
  117. package/dist/types/scene/grammar.d.ts +56 -0
  118. package/dist/types/scene/level.d.ts +98 -0
  119. package/dist/types/scene/material.d.ts +76 -0
  120. package/dist/types/server/auth/appConfig.d.ts +16 -0
  121. package/dist/types/server/auth/global.d.ts +56 -0
  122. package/dist/types/server/auth/models.d.ts +164 -0
  123. package/dist/types/server/auth/types.d.ts +56 -0
  124. package/dist/types/server/channel.d.ts +28 -0
  125. package/dist/types/server/context.d.ts +27 -0
  126. package/dist/types/server/db/defineDb.d.ts +36 -0
  127. package/dist/types/server/db/fields.d.ts +146 -0
  128. package/dist/types/server/db/index.d.ts +6 -0
  129. package/dist/types/server/db/marci/query.d.ts +326 -0
  130. package/dist/types/server/db/types.d.ts +163 -0
  131. package/dist/types/server/errors.d.ts +8 -0
  132. package/dist/types/server/inject.d.ts +5 -0
  133. package/dist/types/ui/NativeView.d.ts +38 -0
  134. package/dist/types/ui/UI.d.ts +27 -0
  135. package/dist/types/ui/UIBottomSheet.d.ts +71 -0
  136. package/dist/types/ui/UIButton.d.ts +30 -0
  137. package/dist/types/ui/UIContainer.d.ts +33 -0
  138. package/dist/types/ui/UIImage.d.ts +35 -0
  139. package/dist/types/ui/UIInput.d.ts +110 -0
  140. package/dist/types/ui/UIModal.d.ts +70 -0
  141. package/dist/types/ui/UINode.d.ts +363 -0
  142. package/dist/types/ui/UIPager.d.ts +123 -0
  143. package/dist/types/ui/UIPopover.d.ts +39 -0
  144. package/dist/types/ui/UIScreen.d.ts +57 -0
  145. package/dist/types/ui/UIScrollable.d.ts +40 -0
  146. package/dist/types/ui/UISpacer.d.ts +9 -0
  147. package/dist/types/ui/UITabs.d.ts +96 -0
  148. package/dist/types/ui/UIText.d.ts +19 -0
  149. package/dist/types/ui/UIVideo.d.ts +28 -0
  150. package/dist/types/ui/UIVirtualizedList.d.ts +97 -0
  151. package/dist/types/ui/UIWidget.d.ts +65 -0
  152. package/dist/types/ui/fonts.d.ts +9 -0
  153. package/dist/types/ui/presentable.d.ts +68 -0
  154. package/dist/types/ui/router.d.ts +40 -0
  155. package/dist/types/ui/theme.d.ts +26 -0
  156. package/dist/types.json +1 -0
  157. package/package.json +46 -0
  158. package/prompts/2d.md +395 -0
  159. package/prompts/3d-scene-files.md +113 -0
  160. package/prompts/3d-scene.md +119 -0
  161. package/prompts/3d.md +303 -0
  162. package/prompts/README.md +142 -0
  163. package/prompts/ar.md +109 -0
  164. package/prompts/canvas.md +27 -0
  165. package/prompts/compose.ts +46 -0
  166. package/prompts/concept.md +49 -0
  167. package/prompts/core-design.md +75 -0
  168. package/prompts/core.md +264 -0
  169. package/prompts/design.md +218 -0
  170. package/prompts/dist/2d-game.md +1530 -0
  171. package/prompts/dist/3d-app.md +1672 -0
  172. package/prompts/dist/ar-app.md +1548 -0
  173. package/prompts/dist/concept.md +49 -0
  174. package/prompts/dist/design.md +498 -0
  175. package/prompts/dist/ui-app.md +1134 -0
  176. package/prompts/index.md +37 -0
  177. package/prompts/intake-prompt.md +33 -0
  178. package/prompts/namer-prompt.md +12 -0
  179. package/prompts/router-prompt.md +50 -0
  180. package/prompts/select.ts +111 -0
  181. package/prompts/ui-design.md +203 -0
  182. package/prompts/ui.md +803 -0
  183. package/src/animate/animate.ts +238 -0
  184. package/src/animate/bezier.ts +138 -0
  185. package/src/animate/easings.ts +126 -0
  186. package/src/bridges.d.ts +1345 -0
  187. package/src/canvas/Canvas.ts +305 -0
  188. package/src/compile/__tests__/assetIconMacro.test.ts +219 -0
  189. package/src/compile/__tests__/assetMacro.test.ts +74 -0
  190. package/src/compile/__tests__/assetName.test.ts +55 -0
  191. package/src/compile/__tests__/compile.test.ts +287 -0
  192. package/src/compile/__tests__/detectEntry.test.ts +132 -0
  193. package/src/compile/__tests__/fontMacro.test.ts +199 -0
  194. package/src/compile/aspectMacro.ts +86 -0
  195. package/src/compile/assetIconMacro.ts +384 -0
  196. package/src/compile/assetMacro.ts +146 -0
  197. package/src/compile/assetName.ts +50 -0
  198. package/src/compile/bundler.ts +287 -0
  199. package/src/compile/compileProject.ts +127 -0
  200. package/src/compile/detectEntry.ts +128 -0
  201. package/src/compile/fontMacro.ts +459 -0
  202. package/src/compile/fontRegistry.ts +78 -0
  203. package/src/compile/header.ts +67 -0
  204. package/src/compile/index.ts +100 -0
  205. package/src/compile/libraryImports.ts +52 -0
  206. package/src/compile/liteMaterial.ts +247 -0
  207. package/src/compile/sceneEditor.ts +88 -0
  208. package/src/compile/serverSplit.ts +233 -0
  209. package/src/compile/serverTypes.ts +227 -0
  210. package/src/compile/sfnt.ts +98 -0
  211. package/src/compile/shaderSchema.ts +202 -0
  212. package/src/compile/shaderTargets.ts +77 -0
  213. package/src/compile/sourcemap.ts +25 -0
  214. package/src/core/Aspect.ts +568 -0
  215. package/src/core/InspectorUI.ts +212 -0
  216. package/src/core/StateMachine.ts +308 -0
  217. package/src/core/__tests__/stateMachine.test.ts +132 -0
  218. package/src/core/color.ts +66 -0
  219. package/src/core/compWrite.ts +42 -0
  220. package/src/core/events.ts +38 -0
  221. package/src/core/fields.ts +120 -0
  222. package/src/core/registry.ts +23 -0
  223. package/src/core/signals.ts +277 -0
  224. package/src/core/time.ts +84 -0
  225. package/src/g2/Camera2D.ts +40 -0
  226. package/src/g2/CharacterController2D.ts +276 -0
  227. package/src/g2/Node2D.ts +267 -0
  228. package/src/g2/OneWay2D.ts +66 -0
  229. package/src/g2/Physics2D.ts +346 -0
  230. package/src/g2/Scene2D.ts +209 -0
  231. package/src/g2/Shape2D.ts +259 -0
  232. package/src/g2/Sprite.ts +89 -0
  233. package/src/g2/SpriteAnimation.ts +171 -0
  234. package/src/g2/SpriteSheet.ts +166 -0
  235. package/src/g2/Texture2D.ts +47 -0
  236. package/src/g2/Tilemap.ts +41 -0
  237. package/src/g2/Tileset.ts +71 -0
  238. package/src/g2/Trigger2D.ts +77 -0
  239. package/src/g2/autotile.ts +433 -0
  240. package/src/g2/cells.ts +91 -0
  241. package/src/g2/defineScene2d.ts +381 -0
  242. package/src/g2/groups2d.ts +106 -0
  243. package/src/g2/loop.ts +50 -0
  244. package/src/g2/scenarios2d.ts +69 -0
  245. package/src/g2/touch.ts +83 -0
  246. package/src/gl/Camera.ts +160 -0
  247. package/src/gl/CameraPlace.ts +52 -0
  248. package/src/gl/CharacterController.ts +238 -0
  249. package/src/gl/Gearbox.ts +212 -0
  250. package/src/gl/Geometry.ts +279 -0
  251. package/src/gl/IK.ts +193 -0
  252. package/src/gl/InstancedMesh.ts +132 -0
  253. package/src/gl/Light.ts +135 -0
  254. package/src/gl/Lightmap.ts +402 -0
  255. package/src/gl/Locomotion.ts +498 -0
  256. package/src/gl/Material.ts +279 -0
  257. package/src/gl/Mesh.ts +83 -0
  258. package/src/gl/Model.ts +124 -0
  259. package/src/gl/NavAgent.ts +337 -0
  260. package/src/gl/NavMesh.ts +397 -0
  261. package/src/gl/Node.ts +350 -0
  262. package/src/gl/Noise.ts +30 -0
  263. package/src/gl/Particles.ts +676 -0
  264. package/src/gl/Physics.ts +222 -0
  265. package/src/gl/Plane.ts +53 -0
  266. package/src/gl/Ragdoll.ts +270 -0
  267. package/src/gl/Ray.ts +16 -0
  268. package/src/gl/Scene.ts +505 -0
  269. package/src/gl/Shape.ts +409 -0
  270. package/src/gl/Terrain.ts +1092 -0
  271. package/src/gl/Texture.ts +63 -0
  272. package/src/gl/Trigger.ts +45 -0
  273. package/src/gl/Vehicle.ts +473 -0
  274. package/src/gl/Wheel.ts +240 -0
  275. package/src/gl/animation/AnimationClip.ts +204 -0
  276. package/src/gl/animation/Animator.ts +329 -0
  277. package/src/gl/animation/Layer.ts +39 -0
  278. package/src/gl/animation/Loop.ts +31 -0
  279. package/src/gl/animation/Playback.ts +52 -0
  280. package/src/gl/animation/core.ts +670 -0
  281. package/src/gl/controls.ts +95 -0
  282. package/src/gl/physicsEvents.ts +20 -0
  283. package/src/gl/scenarios.ts +291 -0
  284. package/src/gl/state.ts +6 -0
  285. package/src/gl/terrainMesh.ts +219 -0
  286. package/src/gl/touch.ts +68 -0
  287. package/src/host.d.ts +61 -0
  288. package/src/inject.ts +203 -0
  289. package/src/math/Mathf.ts +118 -0
  290. package/src/math/mat4.ts +278 -0
  291. package/src/math/quat.ts +232 -0
  292. package/src/math/vec.ts +255 -0
  293. package/src/net/codec.ts +119 -0
  294. package/src/net/core.ts +384 -0
  295. package/src/net/index.ts +181 -0
  296. package/src/net/replication.ts +622 -0
  297. package/src/plugins/camera.ts +81 -0
  298. package/src/plugins/geolocation.ts +123 -0
  299. package/src/plugins/oauth.ts +61 -0
  300. package/src/plugins/permission.ts +7 -0
  301. package/src/plugins/push.ts +132 -0
  302. package/src/plugins/qr.ts +73 -0
  303. package/src/plugins/service.ts +47 -0
  304. package/src/runtime/app.ts +101 -0
  305. package/src/runtime/appEvents.ts +54 -0
  306. package/src/runtime/channel.ts +61 -0
  307. package/src/runtime/clipboard.ts +20 -0
  308. package/src/runtime/datetime.ts +329 -0
  309. package/src/runtime/device.ts +293 -0
  310. package/src/runtime/fetch.ts +77 -0
  311. package/src/runtime/files.ts +108 -0
  312. package/src/runtime/input.ts +175 -0
  313. package/src/runtime/media.ts +111 -0
  314. package/src/runtime/misc.ts +16 -0
  315. package/src/runtime/net.ts +36 -0
  316. package/src/runtime/rpc.ts +218 -0
  317. package/src/runtime/service.ts +83 -0
  318. package/src/runtime/share.ts +9 -0
  319. package/src/runtime/storage.ts +13 -0
  320. package/src/runtime/touch.ts +76 -0
  321. package/src/scene/defineScene.ts +1396 -0
  322. package/src/scene/editorPlugins.ts +110 -0
  323. package/src/scene/gizmos.ts +148 -0
  324. package/src/scene/grammar.ts +120 -0
  325. package/src/scene/level.ts +296 -0
  326. package/src/scene/material.ts +188 -0
  327. package/src/server/auth/appConfig.ts +12 -0
  328. package/src/server/auth/global.ts +80 -0
  329. package/src/server/auth/host.ts +318 -0
  330. package/src/server/auth/models.ts +83 -0
  331. package/src/server/auth/types.ts +50 -0
  332. package/src/server/channel.ts +56 -0
  333. package/src/server/context.ts +36 -0
  334. package/src/server/db/defineDb.ts +237 -0
  335. package/src/server/db/fields.ts +132 -0
  336. package/src/server/db/httpTransport.ts +93 -0
  337. package/src/server/db/index.ts +7 -0
  338. package/src/server/db/marci/query.ts +412 -0
  339. package/src/server/db/types.ts +202 -0
  340. package/src/server/errors.ts +12 -0
  341. package/src/server/host.ts +74 -0
  342. package/src/server/inject.ts +13 -0
  343. package/src/server/runtime.ts +133 -0
  344. package/src/server/validate.ts +87 -0
  345. package/src/ui/NativeView.ts +142 -0
  346. package/src/ui/UI.ts +39 -0
  347. package/src/ui/UIBottomSheet.ts +139 -0
  348. package/src/ui/UIButton.ts +101 -0
  349. package/src/ui/UIContainer.ts +60 -0
  350. package/src/ui/UIImage.ts +83 -0
  351. package/src/ui/UIInput.ts +185 -0
  352. package/src/ui/UIModal.ts +139 -0
  353. package/src/ui/UINode.ts +830 -0
  354. package/src/ui/UIPager.ts +362 -0
  355. package/src/ui/UIPopover.ts +100 -0
  356. package/src/ui/UIScreen.ts +123 -0
  357. package/src/ui/UIScrollable.ts +87 -0
  358. package/src/ui/UISpacer.ts +14 -0
  359. package/src/ui/UITabs.ts +236 -0
  360. package/src/ui/UIText.ts +51 -0
  361. package/src/ui/UIVideo.ts +88 -0
  362. package/src/ui/UIVirtualizedList.ts +241 -0
  363. package/src/ui/UIWidget.ts +127 -0
  364. package/src/ui/fonts.ts +13 -0
  365. package/src/ui/presentable.ts +117 -0
  366. package/src/ui/router.ts +132 -0
  367. package/src/ui/theme.ts +84 -0
@@ -0,0 +1,20 @@
1
+ type mat4 = Float32Array | number[];
2
+ type quat = Float32Array | number[];
3
+ type vec2 = Float32Array | number[];
4
+ type vec3 = Float32Array | number[];
5
+ import type { Easing } from "./easings";
6
+ type AnimateProps = number | string | vec2 | vec3 | quat;
7
+ export type AnimateOptions<T> = {
8
+ from: T;
9
+ to: T;
10
+ duration: number;
11
+ onUpdate(val: T): void;
12
+ onComplete?(): void;
13
+ easing?: Easing;
14
+ };
15
+ export declare const animate: <T extends AnimateProps>(options: AnimateOptions<T>) => number;
16
+ export declare const stopAnimation: (id: number) => void;
17
+ export declare const pauseAnimation: (id: number) => void;
18
+ export declare const resumeAnimation: (id: number) => void;
19
+ export declare const animateMat4: (options: AnimateOptions<mat4>) => number;
20
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Easing } from "./easings";
2
+ export declare function cubicBezier(mX1: number, mY1: number, mX2: number, mY2: number): Easing;
@@ -0,0 +1,21 @@
1
+ export type Easing = (v: number) => number;
2
+ export type EasingModifier = (easing: Easing) => Easing;
3
+ export declare function linear(p: number): number;
4
+ export declare function bounceOut(p: number): number;
5
+ export declare function bounceInOut(p: number): number;
6
+ export declare function reverseEasing(easing: Easing): Easing;
7
+ export declare function mirrorEasing(easing: Easing): Easing;
8
+ export declare function createExpoIn(power: number): Easing;
9
+ export declare function createBackIn(power: number): Easing;
10
+ export declare function createAnticipate(power: number): Easing;
11
+ export declare function bounceIn(p: number): number;
12
+ export declare function easeIn(p: number): number;
13
+ export declare function easeOut(p: number): number;
14
+ export declare function easeInOut(p: number): number;
15
+ export declare function circIn(p: number): number;
16
+ export declare function circOut(p: number): number;
17
+ export declare function circInOut(p: number): number;
18
+ export declare function backIn(p: number): number;
19
+ export declare function backOut(p: number): number;
20
+ export declare function backInOut(p: number): number;
21
+ export declare function anticipate(p: number): number;
@@ -0,0 +1,168 @@
1
+ import { Texture2D } from "../g2/Texture2D";
2
+ import { File, type FetchResponse } from "../runtime/fetch";
3
+ import type { SvgSourceValue } from "../runtime/misc";
4
+ declare const ALIGN: {
5
+ readonly left: 0;
6
+ readonly center: 1;
7
+ readonly right: 2;
8
+ readonly start: 3;
9
+ readonly end: 4;
10
+ };
11
+ declare const BASELINE: {
12
+ readonly alphabetic: 0;
13
+ readonly top: 1;
14
+ readonly middle: 2;
15
+ readonly bottom: 3;
16
+ readonly hanging: 4;
17
+ readonly ideographic: 5;
18
+ };
19
+ declare const JOIN: {
20
+ readonly miter: 0;
21
+ readonly round: 1;
22
+ readonly bevel: 2;
23
+ };
24
+ declare const CAP: {
25
+ readonly butt: 0;
26
+ readonly round: 1;
27
+ readonly square: 2;
28
+ };
29
+ export type TextAlign = keyof typeof ALIGN;
30
+ export type TextBaseline = keyof typeof BASELINE;
31
+ export type LineJoin = keyof typeof JOIN;
32
+ export type LineCap = keyof typeof CAP;
33
+ export interface CanvasTextMetrics {
34
+ width: number;
35
+ ascent: number;
36
+ descent: number;
37
+ }
38
+ export declare class Canvas {
39
+ /** Brand so `Sprite`/`UIImage`/`Material` can accept a Canvas anywhere a texture source is expected. */
40
+ readonly __canvas: true;
41
+ width: number;
42
+ height: number;
43
+ /** Device-pixel multiplier (draw at 2 for crisp retina text). Applied by the backend. */
44
+ pixelRatio: number;
45
+ private _cmd;
46
+ private _refs;
47
+ private _globalAlpha;
48
+ private _fillStyle;
49
+ private _strokeStyle;
50
+ private _lineWidth;
51
+ private _lineJoin;
52
+ private _lineCap;
53
+ private _font;
54
+ private _textAlign;
55
+ private _textBaseline;
56
+ private _surfaceId;
57
+ private _tex2d?;
58
+ private _uiBound;
59
+ constructor(width: number, height: number, opts?: {
60
+ pixelRatio?: number;
61
+ });
62
+ private _ref;
63
+ /** Discard the recorded drawing to start a new one (for dynamic canvases). */
64
+ reset(): this;
65
+ /** Change the surface size; takes effect on the next bake. */
66
+ resize(width: number, height: number): this;
67
+ save(): this;
68
+ restore(): this;
69
+ translate(x: number, y: number): this;
70
+ scale(sx: number, sy: number): this;
71
+ rotate(rad: number): this;
72
+ get globalAlpha(): number;
73
+ set globalAlpha(a: number);
74
+ get fillStyle(): string;
75
+ set fillStyle(color: string);
76
+ get strokeStyle(): string;
77
+ set strokeStyle(color: string);
78
+ get lineWidth(): number;
79
+ set lineWidth(w: number);
80
+ get lineJoin(): LineJoin;
81
+ set lineJoin(j: LineJoin);
82
+ get lineCap(): LineCap;
83
+ set lineCap(c: LineCap);
84
+ get font(): string;
85
+ set font(f: string);
86
+ get textAlign(): TextAlign;
87
+ set textAlign(a: TextAlign);
88
+ get textBaseline(): TextBaseline;
89
+ set textBaseline(b: TextBaseline);
90
+ beginPath(): this;
91
+ closePath(): this;
92
+ moveTo(x: number, y: number): this;
93
+ lineTo(x: number, y: number): this;
94
+ quadraticCurveTo(cx: number, cy: number, x: number, y: number): this;
95
+ bezierCurveTo(c1x: number, c1y: number, c2x: number, c2y: number, x: number, y: number): this;
96
+ arc(x: number, y: number, r: number, a0: number, a1: number, ccw?: boolean): this;
97
+ rect(x: number, y: number, w: number, h: number): this;
98
+ roundRect(x: number, y: number, w: number, h: number, r: number): this;
99
+ fill(evenOdd?: boolean): this;
100
+ stroke(): this;
101
+ fillRect(x: number, y: number, w: number, h: number): this;
102
+ strokeRect(x: number, y: number, w: number, h: number): this;
103
+ clearRect(x: number, y: number, w: number, h: number): this;
104
+ fillText(text: string, x: number, y: number, maxWidth?: number): this;
105
+ strokeText(text: string, x: number, y: number, maxWidth?: number): this;
106
+ /** Blit a `Bitmap` (a snapshot from `toBitmap()`) onto this canvas. All coordinates are LOGICAL —
107
+ * including the source sub-rect in the 9-arg form (it's scaled by the bitmap's pixelRatio here).
108
+ * Records a DRAW_IMAGE op, so the blit runs at bake time: keep the Bitmap alive until the next
109
+ * `update()`/`toBitmap()`/`texture()`. Three browser-style forms:
110
+ * drawImage(bmp, dx, dy) — whole bitmap at its natural size
111
+ * drawImage(bmp, dx, dy, dw, dh) — whole bitmap, scaled into dw×dh
112
+ * drawImage(bmp, sx, sy, sw, sh, dx, dy, dw, dh) — a sub-rect of the bitmap, scaled into dw×dh */
113
+ drawImage(img: Bitmap, dx: number, dy: number): this;
114
+ drawImage(img: Bitmap, dx: number, dy: number, dw: number, dh: number): this;
115
+ drawImage(img: Bitmap, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): this;
116
+ /** Decode an image source into a standalone `Bitmap` you can blit with `drawImage()` — either an
117
+ * `SvgSource(...)` (rasterized) or a `FetchResponse` holding already-fetched image bytes (decoded).
118
+ * This is async because turning SVG markup / encoded bytes into pixels needs a decode step (on the
119
+ * web, `createImageBitmap` / an `<img>` load); `await` it ONCE, then `drawImage(bitmap, …)` is
120
+ * synchronous and the Bitmap is reusable. The returned Bitmap owns a native surface at the image's
121
+ * natural pixel size (`pixelRatio` 1) — `destroy()` it when done. Typical use:
122
+ * const logo = await canvas.loadImage(SvgSource(svg)) // or: await fetch(url) → the response
123
+ * canvas.drawImage(logo, 0, 0) // sync, blit as often as you like */
124
+ loadImage(source: SvgSourceValue | FetchResponse): Promise<Bitmap>;
125
+ /** Measure `text` in the current font on THIS platform. The one synchronous round-trip. */
126
+ measureText(text: string): CanvasTextMetrics;
127
+ /** Bake and return the 2D texture (created once, then cached). */
128
+ texture(): Texture2D;
129
+ /** Re-rasterize and re-upload to every texture this canvas produced (call after redrawing) — the
130
+ * cached 2D and/or 3D texture, whichever engines this canvas was baked into. */
131
+ update(): this;
132
+ /** Copy the current pixels into a standalone, immutable `Bitmap` — independent of this canvas, so
133
+ * later drawing/`reset()` never touches it. Draw it back with `drawImage()`, export it with
134
+ * `toDataURL()`, or use it to "flatten" an ever-growing drawing so re-bakes stay O(1):
135
+ * const snap = canvas.toBitmap()
136
+ * canvas.reset(); canvas.drawImage(snap, 0, 0) // one op replaces the whole history
137
+ * // …keep drawing on top; snap.destroy() once it's been drawn in. */
138
+ toBitmap(): Bitmap;
139
+ /** Encode the current pixels to an image `File` — 'image/png' (default) or 'image/jpeg'. The File
140
+ * is an opaque host buffer handle (`name`/`size` only): append it to a FormData to upload, load it
141
+ * as a texture (`Texture2D.load(file)`), or hand it to a share/save sheet. */
142
+ toFile(name?: string, type?: string): Promise<File>;
143
+ destroy(): void;
144
+ }
145
+ /** Duck-type guard so consumers can accept a Canvas anywhere a texture source is expected. */
146
+ export declare const isCanvas: (v: unknown) => v is Canvas;
147
+ /** An immutable RGBA8 snapshot of a canvas, produced by `Canvas.toBitmap()`. It owns its own baked
148
+ * surface (a copy), so the source canvas can keep drawing or `reset()` without affecting it. Use it
149
+ * to stamp/blit back (`canvas.drawImage(bitmap, …)`), to export (`bitmap.toDataURL()`), or as a
150
+ * cheap "layer" you composite. Call `destroy()` when done — it holds a native surface. */
151
+ export declare class Bitmap {
152
+ readonly __bitmap: true;
153
+ /** Logical width, matching the Canvas it was captured from (pixelRatio is crispness, not size). */
154
+ readonly width: number;
155
+ readonly height: number;
156
+ readonly pixelRatio: number;
157
+ constructor(surfaceId: number, width: number, height: number, pixelRatio: number);
158
+ /** Device-pixel dimensions of the stored bitmap (`width * pixelRatio`, rounded). */
159
+ get pixelWidth(): number;
160
+ get pixelHeight(): number;
161
+ /** Encode to an image `File` — 'image/png' (default) or 'image/jpeg'. See `Canvas.toFile`. */
162
+ toFile(name?: string, type?: string): Promise<File>;
163
+ /** Free the native surface. The bitmap must not be drawn or encoded afterwards. */
164
+ destroy(): void;
165
+ }
166
+ /** Duck-type guard for a Bitmap (see `isCanvas`). */
167
+ export declare const isBitmap: (v: unknown) => v is Bitmap;
168
+ export {};
@@ -0,0 +1,171 @@
1
+ import type { Scene } from "../gl/Scene";
2
+ import { Emitter, type EventMap } from "./events";
3
+ import type { InspectorUI } from "./InspectorUI";
4
+ import type { Node } from "../gl/Node";
5
+ /** The class object of an aspect — accepted even when its constructor is protected/abstract. */
6
+ export type AspectCtor<A extends Aspect<any, any, any>> = abstract new () => A;
7
+ /** The accessor name carried in the aspect's generic. */
8
+ export type KeyOf<A> = A extends Aspect<infer K, any, any> ? K : never;
9
+ /** The node kind an aspect targets (the scene kind for a System). */
10
+ export type TargetOf<A> = A extends Aspect<any, infer P, any> ? P : never;
11
+ /** `{ name: Aspect }` — the field an aspect contributes to its node. */
12
+ export type FieldOf<A extends Aspect<any, any, any>> = {
13
+ [P in KeyOf<A>]: A;
14
+ };
15
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
16
+ /**
17
+ * A variable typed as a node KNOWN to carry the given aspect(s). Union, not a tuple — reads as
18
+ * English and mirrors the runtime guard `node.has(Health)`:
19
+ * let boss: With<Sprite, Health | Physics>
20
+ */
21
+ export type With<N, A extends Aspect<any, any, any>> = N & UnionToIntersection<A extends any ? FieldOf<A> : never>;
22
+ /**
23
+ * Base for anything that can carry aspects. Extends Emitter, so node kinds get events too. Provides
24
+ * the four verbs; the named accessor (node.physics, node.health, …) is set as an own property at
25
+ * attach time, keyed by the aspect class's runtime `aspect` name.
26
+ */
27
+ export declare abstract class AspectHost<E extends EventMap = EventMap> extends Emitter<E> {
28
+ /** Attach (and configure) an aspect, or reconfigure it if already present. Returns the node typed
29
+ * as now-having that aspect (so no guard/`?.` is needed afterwards). Rejects a wrong target node. */
30
+ aspect<Self extends TargetOf<A>, A extends Aspect<any, any, any>>(this: Self, ctor: AspectCtor<A>, opts?: Partial<A>): Self & FieldOf<A>;
31
+ /** Safe access — undefined if the aspect isn't attached. */
32
+ get<A extends Aspect<any, any, any>>(ctor: AspectCtor<A>): A | undefined;
33
+ /** Existence check AND type guard: inside `if (node.has(Physics))`, `node.physics` is present. */
34
+ has<A extends Aspect<any, any, any>>(ctor: AspectCtor<A>): this is this & FieldOf<A>;
35
+ /** Detach an aspect (runs its onDetach). Named `removeAspect` so it never collides with the
36
+ * child-management `add`/`remove` semantics some node kinds expose. */
37
+ removeAspect<A extends Aspect<any, any, any>>(ctor: AspectCtor<A>): this;
38
+ }
39
+ /**
40
+ * Base for everything you attach. `K` = accessor name (extracted by chisel for the runtime). `P` =
41
+ * the target node kind: `this.node` is typed to it, AND attaching to a wrong node is a compile error.
42
+ * `E` = the events this aspect emits (`{ explode: (b: Barrel) => void }`): `this.emit('explode', …)`
43
+ * inside, `node.barrel.on('explode', fn)` outside.
44
+ * Initialize in `onAttach` (the node is set by then) — not a constructor; aspects are created by the
45
+ * engine via `node.aspect()`, never `new`.
46
+ */
47
+ export declare abstract class Aspect<K extends string, P = Node, E extends EventMap = {}> {
48
+ /**
49
+ * Opt this aspect class into EDITOR-RUN mode (generators): while a scene is edited, the scene
50
+ * loader constructs the instance (refs resolved, `node`/`generated` set — never `onAttach`) and
51
+ * calls `rebuild()` — again on inspector prop edits and when a `ref()`-referenced node moves.
52
+ * `static editor = { rebuild: true }`.
53
+ */
54
+ static editor?: {
55
+ rebuild?: boolean;
56
+ };
57
+ /**
58
+ * Custom inspector card for this aspect in the scene editor (immediate-mode — see
59
+ * core/InspectorUI.ts): re-runs on every edit/event and emits a widget list. Without it, the
60
+ * editor shows the inferred fields; `ui.auto()` emits those same fields, so a custom inspector
61
+ * usually starts with `ui.auto()` and appends status lines / buttons / dynamic dropdowns:
62
+ *
63
+ * static inspector(ui: InspectorUI, self: MyAspect) {
64
+ * ui.auto()
65
+ * if (ui.button('Randomize')) self.rebuild()
66
+ * }
67
+ */
68
+ static inspector?: (ui: InspectorUI, aspect: any) => void;
69
+ /** Tick AFTER these classes within the same phase (`static after = [Controls]`). A constraint
70
+ * always beats the numeric `updateOrder`. Classes absent from the phase are ignored. */
71
+ static after?: Function[];
72
+ /** Tick BEFORE these classes within the same phase (`static before = [Camera]`). */
73
+ static before?: Function[];
74
+ /** Every live instance of an aspect/system class, in attach order — the registry a game used to
75
+ * hand-roll as `static all[]`. Live, read-only: copy it (`[...Aspect.all(Barrel)]`) before a loop
76
+ * that detaches. Empty in the scene editor (aspects are inert data there). */
77
+ static all<A extends Aspect<any, any, any>>(ctor: AspectCtor<A>): readonly A[];
78
+ /** The node this aspect is attached to (set at attach time). For a System: the scene. */
79
+ readonly node: P;
80
+ /**
81
+ * GENERATOR aspects (`static editor = { rebuild: true }`, attached through a scene file): a
82
+ * scene-added container child for the aspect's generated output — `rebuild()` clears and refills
83
+ * it. Provided by the scene loader before `onAttach`/`rebuild` run; nodes `add()`ed to it join
84
+ * the scene's draw set automatically (membership is separate from parenting). Undefined for
85
+ * aspects attached by hand outside scene files. See docs/3d/scene-files.md.
86
+ */
87
+ readonly generated: Node & {
88
+ clear(): void;
89
+ readonly version: number;
90
+ };
91
+ /**
92
+ * GENERATOR aspects attached through a scene file: the `Scene` the host node was built into —
93
+ * what `handle.instantiate({ scene })` / `scene.add()` need inside `rebuild()`. Set by the scene
94
+ * loader (edit AND play mode); undefined for aspects attached by hand. 3D only (2D aspects own
95
+ * their `scene` field). For a System: always set — the scene it is attached to.
96
+ */
97
+ readonly scene: P extends Node ? Scene : P extends SystemHost ? P : unknown;
98
+ protected readonly __key__?: K;
99
+ protected readonly __events__?: E;
100
+ private _listeners?;
101
+ /** The node (or scene) is set — initialize here, not in a constructor. */
102
+ protected onAttach?(): void;
103
+ /** Release what onAttach acquired. */
104
+ protected onDetach?(): void;
105
+ /** Called after `node.aspect(Ctor, opts)` re-assigns options on an ALREADY attached aspect (a
106
+ * pre-attached one like `model.anim`): rebuild whatever was derived from the options at attach. */
107
+ protected onReconfigure?(): void;
108
+ /**
109
+ * GENERATOR aspects: (re)build the derived output under `this.generated` — must be idempotent
110
+ * (clear, then create). Call it from `onAttach()` for play mode; a class opting in with
111
+ * `static editor = { rebuild: true }` ALSO runs it while a scene is being edited: once at load,
112
+ * and again whenever an inspector prop changes or a `ref()`-referenced node moves.
113
+ */
114
+ rebuild?(): void;
115
+ /**
116
+ * LATE phase — every frame while attached, after the physics step + transform sync + animators,
117
+ * right before the frame draws: reads of `node.worldPosition` are the final drawn position
118
+ * (cameras/followers have no 1-frame lag) and what you write to a plain node is what this frame
119
+ * shows. The default home for game logic. `dt` = GAME seconds since the last frame (`Time.scale`
120
+ * applied; 0 while paused — see `updateWhilePaused`).
121
+ */
122
+ protected update?(dt: number): void;
123
+ /**
124
+ * EARLY phase — every frame BEFORE the physics step, so what you feed the simulation (velocity,
125
+ * `controller.move()`, forces, kinematic transforms) is consumed by this same frame's step: zero
126
+ * input latency. Use it only when you FEED the simulation. Reads here see last frame's settled
127
+ * state. A class rarely needs both phases — that is two aspects on one node.
128
+ */
129
+ protected updateBefore?(dt: number): void;
130
+ /**
131
+ * FIXED phase - once per physics substep, BEFORE that substep's Jolt step, with `dt = Time.fixedDt`
132
+ * (1/60) exactly, on every machine: under `Time.scale` the NUMBER of steps per frame changes, never
133
+ * the dt (0-4 calls per frame). The home of simulation that must match another machine's - a
134
+ * multiplayer player sim, dt-dependent motion that may not drift with the frame rate. `controller.move()`
135
+ * / velocity writes here feed the same step; between steps the world is consistent, so `Physics.raycast`
136
+ * is fine. Anything that looks at the screen (cameras, HUD, FX) stays in `updateBefore` / `update`.
137
+ */
138
+ protected updateFixed?(dt: number): void;
139
+ /** Tick order within a phase and rank — ascending; default 0, ties keep attach order. A declared
140
+ * `static after` / `static before` constraint always beats this number. Read once, at attach —
141
+ * set it as a class field. */
142
+ protected updateOrder: number;
143
+ /** Keep ticking while `Time.paused` (a HUD fade, the pause menu). `dt` is still 0 then — read
144
+ * `Time.unscaledDt` for wall-clock motion. Checked every frame; may be toggled at any time. */
145
+ protected updateWhilePaused: boolean;
146
+ /** Opt-in: only run update(dt) while the node is on-screen. NOOP for now — visibility culling isn't
147
+ * wired yet, so every updater ticks regardless; declared so aspects can opt in ahead of it. */
148
+ protected updateWhenVisible: boolean;
149
+ /** Listen to one of this aspect's events. Chainable. Cleared on detach. */
150
+ on<C extends keyof E & string>(channel: C, callback: E[C]): this;
151
+ /** Remove a listener added with `on` (same function reference). */
152
+ off<C extends keyof E & string>(channel: C, callback: E[C]): this;
153
+ /** Fire one of this aspect's events. Protected: only the aspect itself emits. */
154
+ protected emit<C extends keyof E & string>(channel: C, ...args: Parameters<E[C]>): void;
155
+ }
156
+ /**
157
+ * An aspect of a SCENE: game logic with no single node to live on — input mapping, the FX pools, the
158
+ * HUD, the game mode. Same lifecycle (`onAttach`/`onDetach`), same phases (`updateFixed` / `updateBefore` /
159
+ * `update`), same ordering (`updateOrder`, `static after`) and events as a node aspect; `this.scene` is the
160
+ * scene it was attached to. `S` = the scene kind (`Scene` by default, `Scene2D` for 2D games).
161
+ *
162
+ * class Hud extends System<'hud'> {
163
+ * static after = [Player]
164
+ * update(dt: number) { … }
165
+ * }
166
+ * scene.system(Hud) // attach
167
+ * scene.hud // the typed accessor
168
+ */
169
+ export declare abstract class System<K extends string, S extends SystemHost = Scene, E extends EventMap = {}> extends Aspect<K, S, E> {
170
+ }
171
+ export {};
@@ -0,0 +1,88 @@
1
+ import type { FieldEditor } from "./fields";
2
+ /** One user interaction coming back from the editor panel: the widget's id (+ value for fields). */
3
+ export type InspectorEvent = {
4
+ id: string;
5
+ value?: unknown;
6
+ };
7
+ export type InspectorFieldWidget = {
8
+ kind: "field";
9
+ id: string;
10
+ /** The bound key — an aspect field (doc-bound) or an editor-state key. */
11
+ key: string;
12
+ label: string;
13
+ editor: FieldEditor | undefined;
14
+ value: unknown;
15
+ /** True = persisted to the scene file by the editor; false = transient editor state. */
16
+ doc: boolean;
17
+ /** True = emitted by `ui.auto()` — the editor may overlay its syntactic hints (options/node). */
18
+ auto?: boolean;
19
+ min?: number;
20
+ max?: number;
21
+ step?: number;
22
+ options?: readonly (string | number)[];
23
+ };
24
+ export type InspectorWidget = InspectorFieldWidget | {
25
+ kind: "button";
26
+ id: string;
27
+ label: string;
28
+ } | {
29
+ kind: "toolButton";
30
+ id: string;
31
+ label: string;
32
+ tool: string;
33
+ } | {
34
+ kind: "header";
35
+ id: string;
36
+ label: string;
37
+ } | {
38
+ kind: "info" | "warn";
39
+ id: string;
40
+ text: string;
41
+ };
42
+ type FieldOpts = {
43
+ label?: string;
44
+ min?: number;
45
+ max?: number;
46
+ step?: number;
47
+ /** Default for EDITOR-STATE keys (doc keys default from the class field). */
48
+ value?: unknown;
49
+ };
50
+ /**
51
+ * The widget builder handed to `static inspector(ui, aspect)` (and to editor windows/tools later).
52
+ * One instance lives per card and persists across runs — it carries the card's editor state.
53
+ */
54
+ export declare class InspectorUI {
55
+ /** Numeric field (min/max/step render as a slider-style scrub range). */
56
+ number(key: string, opts?: FieldOpts): number;
57
+ /** Alias of `number` — give it min/max/step and the editor renders a scrubable range. */
58
+ slider(key: string, opts?: FieldOpts): number;
59
+ text(key: string, opts?: FieldOpts): string;
60
+ color(key: string, opts?: FieldOpts): string;
61
+ switch(key: string, opts?: FieldOpts): boolean;
62
+ /** Dropdown — `options` may be computed fresh every run (dynamic lists come free). */
63
+ select(key: string, options: readonly (string | number)[], opts?: FieldOpts): string | number;
64
+ vec2(key: string, opts?: FieldOpts): [number, number];
65
+ vec3(key: string, opts?: FieldOpts): [number, number, number];
66
+ vec4(key: string, opts?: FieldOpts): [number, number, number, number];
67
+ /** Scene-node reference (`ref()` fields): name dropdown + pick-in-viewport. Returns the RAW doc
68
+ * value (`{ $ref }` marker or null) — read the resolved live node off the aspect instance. */
69
+ node(key: string, opts?: FieldOpts): unknown;
70
+ /** Project-asset path (the editor renders a dropdown of the project's GLBs). "" = none picked. */
71
+ asset(key: string, opts?: FieldOpts): string;
72
+ /** True on the run that consumes this button's click — do the action right there. */
73
+ button(label: string, opts?: {
74
+ id?: string;
75
+ }): boolean;
76
+ /** A toggle that activates/deactivates the named viewport tool (`registerEditorTool`). The
77
+ * editor owns the active-tool state — the click never round-trips into the scene world. */
78
+ toolButton(label: string, tool: string): void;
79
+ header(label: string): void;
80
+ info(text: string): void;
81
+ warn(text: string): void;
82
+ /** Emit the inferred field widgets (all declared aspect fields, or just the named ones) — the
83
+ * zero-ceremony baseline; append custom widgets around it. */
84
+ auto(...keys: string[]): void;
85
+ private _vec;
86
+ private _field;
87
+ }
88
+ export {};
@@ -0,0 +1,81 @@
1
+ export type StateGuard<C> = (ctx: C, t: number) => boolean;
2
+ export type StateHandler<C> = (ctx: C, ...args: any[]) => string | void;
3
+ export interface StateDef<C> {
4
+ /** The child entered by default when this (compound) state is entered. */
5
+ initial?: string;
6
+ /** Child states — this becomes a compound state; only a leaf is ever "the" state. */
7
+ states?: Record<string, StateDef<C>>;
8
+ /** Entered (from = the previous leaf's path, '' at start). */
9
+ enter?: (ctx: C, from: string) => void;
10
+ /** Left (to = the next leaf's path). */
11
+ exit?: (ctx: C, to: string) => void;
12
+ /** Every step while active, outer states first; `t` = seconds in this state. Return a state name
13
+ * to transition. */
14
+ update?: (ctx: C, dt: number, t: number) => string | void;
15
+ /** Guarded transitions, tested every step before `update` — key = target, first true wins. */
16
+ to?: Record<string, StateGuard<C>>;
17
+ /** Leave for `target` after `seconds` in this state. */
18
+ after?: [seconds: number, target: string];
19
+ /** Event handlers for `send(name, …args)`: a target name, or a function returning one (or nothing). */
20
+ on?: Record<string, string | StateHandler<C>>;
21
+ }
22
+ export interface StatesDef<C> {
23
+ initial: string;
24
+ states: Record<string, StateDef<C>>;
25
+ /** Any-state guards — tested first, in every state. */
26
+ to?: Record<string, StateGuard<C>>;
27
+ /** Any-state event handlers — the fallback when no active state handles the event. */
28
+ on?: Record<string, string | StateHandler<C>>;
29
+ /** Any-state update, runs before the active states' own. */
30
+ update?: (ctx: C, dt: number, t: number) => string | void;
31
+ }
32
+ export type StateMachineEvents = {
33
+ /** After a transition completed (both are leaf paths; `from` = '' for the initial entry). */
34
+ change: (to: string, from: string) => void;
35
+ };
36
+ /** Identity helper — names the context type once so every callback is typed. */
37
+ export declare const defineStates: <C>(def: StatesDef<C>) => StatesDef<C>;
38
+ export declare class StateMachine<C> {
39
+ readonly ctx: C;
40
+ private readonly root;
41
+ private readonly byPath;
42
+ /** the active branch, root's child (index 0) → leaf */
43
+ private chain;
44
+ private prev;
45
+ private listeners;
46
+ private changed;
47
+ constructor(def: StatesDef<C>, ctx: C);
48
+ /** The active leaf's path ('combat.shoot'). */
49
+ get state(): string;
50
+ /** The leaf we came from ('' before the first transition). */
51
+ get previous(): string;
52
+ /** Seconds in the active leaf. */
53
+ get time(): number;
54
+ /** Every active state's path, outermost first. */
55
+ get branch(): string[];
56
+ /** Is `name` (a state name or dotted path) active — as the leaf OR as one of its ancestors? */
57
+ is(name: string): boolean;
58
+ /** Seconds in the named active state (0 when it is not active). */
59
+ timeIn(name: string): number;
60
+ /** Force a transition (a spawn, a reset from outside the table). */
61
+ go(name: string): void;
62
+ /** Deliver an event. Innermost active state first, the root's `on` last. True if handled. */
63
+ send(event: string, ...args: unknown[]): boolean;
64
+ /** One tick: clocks, guards (outer first, chained), then updates (outer first). */
65
+ step(dt: number): void;
66
+ /** Listen for transitions. */
67
+ on(event: "change", fn: StateMachineEvents["change"]): this;
68
+ off(event: "change", fn: StateMachineEvents["change"]): this;
69
+ private build;
70
+ private link;
71
+ private resolveStrict;
72
+ /** Relative first (siblings of `from`, then of each ancestor), then a dotted path from the root. */
73
+ private resolve;
74
+ /** Guards never re-enter a state that is already active (a `dead` guard staying true does not
75
+ * re-enter `dead` every step) — only an explicit `go()` / event does that. */
76
+ private findTransition;
77
+ private active;
78
+ private leafOf;
79
+ private transition;
80
+ private enterBranch;
81
+ }
@@ -0,0 +1,13 @@
1
+ export type ColorInput = string | number | readonly [number, number, number] | readonly [number, number, number, number];
2
+ export declare const Color: {
3
+ /** [r,g,b] in 0..1 — for the 2D engine's float color setters. */
4
+ toRgb01(c: ColorInput): [number, number, number];
5
+ /** [r,g,b,a] in 0..1. */
6
+ toRgba01(c: ColorInput): [number, number, number, number];
7
+ /** 0xRRGGBB packed int — for the 3D engine's color uniforms / skybox. */
8
+ toPackedRgb(c: ColorInput): number;
9
+ /** 0xRRGGBBAA packed int (unsigned). */
10
+ toPackedRgba(c: ColorInput): number;
11
+ /** '#rrggbb' (or '#rrggbbaa' when alpha < 1) — for the 3D material color uniforms. */
12
+ toHexString(c: ColorInput): string;
13
+ };
@@ -0,0 +1,11 @@
1
+ export type CompAxis = "x" | "y" | "z" | "w";
2
+ /** Implemented by a class whose vector getters accept component writes (see above). The class also
3
+ * carries `static _comps: string[]` naming those getters — compile-time data, absent at runtime. */
4
+ export interface CompWriter {
5
+ _writeComp(prop: string, axis: CompAxis, value: number): void;
6
+ }
7
+ /** `<o>.<prop>.<axis> = value`, routed to the owner when it has the hook. Returns the value. */
8
+ export declare const __compWrite: (o: any, prop: string, axis: CompAxis, value: number) => number;
9
+ /** `<o>.<prop>.<axis> op= v` — `op`: 0 `+=`, 1 `-=`, 2 `*=`, 3 `/=`. The current component is read
10
+ * through the normal getter (one fresh vector), the result written like `__compWrite`. */
11
+ export declare const __compOp: (o: any, prop: string, axis: CompAxis, op: number, v: number) => number;
@@ -0,0 +1,11 @@
1
+ export type EventMap = Record<string, (...args: any[]) => void>;
2
+ export declare class Emitter<E extends EventMap> {
3
+ private _listeners;
4
+ addEventListener<K extends keyof E>(channel: K, callback: E[K]): void;
5
+ removeEventListener<K extends keyof E>(channel: K, callback: E[K]): void;
6
+ /** Fire all listeners on a channel. Protected: only the owning class emits. */
7
+ protected dispatch<K extends keyof E>(channel: K, ...args: Parameters<E[K]>): void;
8
+ protected hasListeners<K extends keyof E>(channel: K): boolean;
9
+ /** Drop every listener on every channel (used when the owning object is disposed). */
10
+ protected clearListeners(): void;
11
+ }
@@ -0,0 +1,58 @@
1
+ /** Editor widget kinds the inspector knows how to render. `"node"` = a scene-node reference
2
+ * (`ref('name')` in the file, name dropdown + pick-in-viewport in the inspector) — declare it via
3
+ * `static fields` on fields typed `Node | null`; a `Node | null` type annotation is also picked
4
+ * up syntactically by the editor's source scan. `"asset"` = a project-asset path (the editor
5
+ * fills the dropdown with the project's GLBs — `ui.asset()` in windows/tools/cards). */
6
+ export type FieldEditor = "number" | "text" | "color" | "switch" | "select" | "vec2" | "vec3" | "vec4" | "node" | "asset";
7
+ export type FieldMetaEntry = {
8
+ /** Inspector label (default: the field name). */
9
+ label?: string;
10
+ min?: number;
11
+ max?: number;
12
+ step?: number;
13
+ /** Allowed values — renders a dropdown (editor "select"). */
14
+ options?: readonly (string | number)[];
15
+ /** Override the editor inferred from the default value. */
16
+ editor?: FieldEditor;
17
+ /** Exclude the field from the inspector. */
18
+ hidden?: boolean;
19
+ };
20
+ /** Declared on an aspect class as `static fields: FieldMeta<MyAspect> = { … }`. All optional. */
21
+ export type FieldMeta<T = unknown> = {
22
+ [K in Extract<keyof T, string>]?: FieldMetaEntry;
23
+ };
24
+ /** One editable field: key + default value + resolved editor + merged metadata. */
25
+ export type FieldDescriptor = {
26
+ key: string;
27
+ label: string;
28
+ /** The default value (from a freshly constructed instance; undefined if only declared in meta). */
29
+ value: unknown;
30
+ /** Resolved editor kind; undefined = no editor known (inspector shows it read-only). */
31
+ editor: FieldEditor | undefined;
32
+ min?: number;
33
+ max?: number;
34
+ step?: number;
35
+ options?: readonly (string | number)[];
36
+ };
37
+ export type AspectClassInfo = {
38
+ /** The accessor name (`static aspect`, injected by chisel for user aspects). */
39
+ name: string;
40
+ className: string;
41
+ fields: FieldDescriptor[];
42
+ /** True for editor-run classes (`static editor` — generators). The editor routes their
43
+ * structural changes through a re-run instead of a live patch. */
44
+ editor?: boolean;
45
+ /** True when the class declares a custom `static inspector(ui, aspect)` card. */
46
+ inspector?: boolean;
47
+ };
48
+ /** Infer the editor widget from a default value's shape. */
49
+ export declare const inferFieldEditor: (value: unknown) => FieldEditor | undefined;
50
+ /**
51
+ * Enumerate the editable fields of a class: construct a default instance, take its own enumerable
52
+ * non-underscore fields (minus the Aspect base plumbing), infer editors from the default values, and
53
+ * merge the class's optional `static fields` metadata (which can also add keys that have no runtime
54
+ * default, e.g. fields declared without an initializer).
55
+ */
56
+ export declare const describeFields: (ctor: abstract new () => unknown) => FieldDescriptor[];
57
+ /** Describe an aspect class for the inspector: accessor name + class name + editable fields. */
58
+ export declare const describeAspect: (ctor: abstract new () => unknown) => AspectClassInfo;