motionary 10.5.0 → 10.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/AGENTS.md +2 -0
  2. package/CHANGELOG.md +28 -0
  3. package/README.md +95 -1
  4. package/bin/motionary-mcp.mjs +160 -11
  5. package/dist/chunks/{anim-image-DuxvYhq6.cjs → anim-image-CFGpUX7t.cjs} +2 -2
  6. package/dist/chunks/{anim-image-DuxvYhq6.cjs.map → anim-image-CFGpUX7t.cjs.map} +1 -1
  7. package/dist/chunks/{anim-image-BlNPv4JG.js → anim-image-CXDD19FH.js} +2 -2
  8. package/dist/chunks/{anim-image-BlNPv4JG.js.map → anim-image-CXDD19FH.js.map} +1 -1
  9. package/dist/chunks/{keyframes-Ce1s05n3.cjs → keyframes-DdwGY1gr.cjs} +2 -2
  10. package/dist/chunks/{keyframes-Ce1s05n3.cjs.map → keyframes-DdwGY1gr.cjs.map} +1 -1
  11. package/dist/chunks/{keyframes-B8ITIAVa.js → keyframes-DwR6GPej.js} +2 -2
  12. package/dist/chunks/{keyframes-B8ITIAVa.js.map → keyframes-DwR6GPej.js.map} +1 -1
  13. package/dist/chunks/{registry-DXdFb2fJ.js → registry-D87dP_aR.js} +3 -3
  14. package/dist/chunks/{registry-DXdFb2fJ.js.map → registry-D87dP_aR.js.map} +1 -1
  15. package/dist/chunks/{registry-VhfPSI0v.cjs → registry-DhKZCitb.cjs} +2 -2
  16. package/dist/chunks/{registry-VhfPSI0v.cjs.map → registry-DhKZCitb.cjs.map} +1 -1
  17. package/dist/chunks/{ticker-C5RMHMW7.js → ticker-CJYI5Pxc.js} +2 -2
  18. package/dist/chunks/{ticker-C5RMHMW7.js.map → ticker-CJYI5Pxc.js.map} +1 -1
  19. package/dist/chunks/{ticker-DvmC6WLS.cjs → ticker-jD9_A9Rh.cjs} +2 -2
  20. package/dist/chunks/{ticker-DvmC6WLS.cjs.map → ticker-jD9_A9Rh.cjs.map} +1 -1
  21. package/dist/chunks/{tween-_BGIl6hK.cjs → tween-Dk0QmNe9.cjs} +2 -2
  22. package/dist/chunks/{tween-_BGIl6hK.cjs.map → tween-Dk0QmNe9.cjs.map} +1 -1
  23. package/dist/chunks/{tween-CPtm-EdT.js → tween-_Lld1MsF.js} +2 -2
  24. package/dist/chunks/{tween-CPtm-EdT.js.map → tween-_Lld1MsF.js.map} +1 -1
  25. package/dist/components/ai.cjs +314 -0
  26. package/dist/components/ai.cjs.map +1 -0
  27. package/dist/components/ai.d.cts +58 -0
  28. package/dist/components/ai.d.ts +58 -0
  29. package/dist/components/ai.js +311 -0
  30. package/dist/components/ai.js.map +1 -0
  31. package/dist/components/lite.cjs +179 -0
  32. package/dist/components/lite.cjs.map +1 -1
  33. package/dist/components/lite.js +176 -1
  34. package/dist/components/lite.js.map +1 -1
  35. package/dist/components/tokens.cjs +179 -0
  36. package/dist/components/tokens.cjs.map +1 -1
  37. package/dist/components/tokens.d.cts +36 -1
  38. package/dist/components/tokens.d.ts +36 -1
  39. package/dist/components/tokens.js +176 -1
  40. package/dist/components/tokens.js.map +1 -1
  41. package/dist/components/widgets.cjs +985 -221
  42. package/dist/components/widgets.cjs.map +1 -1
  43. package/dist/components/widgets.d.cts +606 -4
  44. package/dist/components/widgets.d.ts +606 -4
  45. package/dist/components/widgets.js +976 -222
  46. package/dist/components/widgets.js.map +1 -1
  47. package/dist/components.cjs +4 -0
  48. package/dist/components.cjs.map +1 -1
  49. package/dist/components.d.cts +36 -1
  50. package/dist/components.d.ts +36 -1
  51. package/dist/components.js +1 -1
  52. package/dist/components.umd.js +2 -2
  53. package/dist/components.umd.js.map +1 -1
  54. package/dist/index.umd.js.map +1 -1
  55. package/dist/llms-full.txt +221 -1
  56. package/dist/llms.txt +11 -2
  57. package/dist/manifest.json +580 -1
  58. package/dist/runtime/format-apng.cjs +4 -4
  59. package/dist/runtime/format-apng.js +4 -4
  60. package/dist/runtime/format-css.cjs +4 -4
  61. package/dist/runtime/format-css.js +4 -4
  62. package/dist/runtime/format-gif.cjs +4 -4
  63. package/dist/runtime/format-gif.js +4 -4
  64. package/dist/runtime/format-gltf.cjs +1 -1
  65. package/dist/runtime/format-gltf.js +1 -1
  66. package/dist/runtime/format-motion.cjs +4 -4
  67. package/dist/runtime/format-motion.js +4 -4
  68. package/dist/runtime/format-obj.cjs +1 -1
  69. package/dist/runtime/format-obj.js +1 -1
  70. package/dist/runtime/format-scene.cjs +241 -0
  71. package/dist/runtime/format-scene.cjs.map +1 -0
  72. package/dist/runtime/format-scene.d.cts +349 -0
  73. package/dist/runtime/format-scene.d.ts +349 -0
  74. package/dist/runtime/format-scene.iife.js +2 -0
  75. package/dist/runtime/format-scene.iife.js.map +1 -0
  76. package/dist/runtime/format-scene.js +233 -0
  77. package/dist/runtime/format-scene.js.map +1 -0
  78. package/dist/runtime/format-sprite.cjs +3 -3
  79. package/dist/runtime/format-sprite.js +3 -3
  80. package/dist/runtime/format-svg.cjs +3 -3
  81. package/dist/runtime/format-svg.js +3 -3
  82. package/dist/runtime/format-webp.cjs +4 -4
  83. package/dist/runtime/format-webp.js +4 -4
  84. package/dist/runtime/gl.cjs +1 -1
  85. package/dist/runtime/gl.js +1 -1
  86. package/dist/runtime/physics.cjs +739 -0
  87. package/dist/runtime/physics.cjs.map +1 -0
  88. package/dist/runtime/physics.d.cts +250 -0
  89. package/dist/runtime/physics.d.ts +250 -0
  90. package/dist/runtime/physics.iife.js +2 -0
  91. package/dist/runtime/physics.iife.js.map +1 -0
  92. package/dist/runtime/physics.js +731 -0
  93. package/dist/runtime/physics.js.map +1 -0
  94. package/dist/runtime/scroll.cjs +2 -2
  95. package/dist/runtime/scroll.js +2 -2
  96. package/dist/runtime/smooth.cjs +1 -1
  97. package/dist/runtime/smooth.js +1 -1
  98. package/dist/runtime/text.cjs +1 -1
  99. package/dist/runtime/text.js +1 -1
  100. package/dist/runtime/vector.cjs +704 -0
  101. package/dist/runtime/vector.cjs.map +1 -0
  102. package/dist/runtime/vector.d.cts +306 -0
  103. package/dist/runtime/vector.d.ts +306 -0
  104. package/dist/runtime/vector.iife.js +2 -0
  105. package/dist/runtime/vector.iife.js.map +1 -0
  106. package/dist/runtime/vector.js +692 -0
  107. package/dist/runtime/vector.js.map +1 -0
  108. package/dist/runtime.cjs +3 -3
  109. package/dist/runtime.d.cts +1 -1
  110. package/dist/runtime.d.ts +1 -1
  111. package/dist/runtime.iife.js +1 -1
  112. package/dist/runtime.iife.js.map +1 -1
  113. package/dist/runtime.js +5 -5
  114. package/dist/widgets.umd.js +1 -1
  115. package/dist/widgets.umd.js.map +1 -1
  116. package/docs/ROADMAP.md +2 -2
  117. package/docs/components/README.md +6 -1
  118. package/docs/components/usa-lottie-player.md +60 -0
  119. package/docs/components/usa-motion-prompt.md +32 -0
  120. package/docs/components/usa-physics-playground.md +63 -0
  121. package/docs/components/usa-rive.md +57 -0
  122. package/docs/components/usa-token-editor.md +32 -0
  123. package/docs/components.md +116 -0
  124. package/docs/runtime/format-scene.md +59 -0
  125. package/docs/runtime/physics.md +61 -0
  126. package/docs/runtime/rive.md +55 -0
  127. package/docs/runtime/vector.md +67 -0
  128. package/package.json +46 -2
@@ -0,0 +1,349 @@
1
+ /** A runtime module: `{ id, version, api }`, registered with `use()`. */
2
+ interface RuntimeModule<A = unknown> {
3
+ /** Module id: 'core', 'format-css', 'scroll', … (import path `motionary/runtime/<id>`). */
4
+ id: string;
5
+ version: string;
6
+ /** Other modules this one needs (registered first by `use()` callers). */
7
+ requires?: string[];
8
+ /** The module's public API (what `requireModule(id)` returns). */
9
+ api: A;
10
+ /** Optional one-time setup, called on first registration. */
11
+ setup?(registry: RuntimeRegistry): void;
12
+ }
13
+ interface RuntimeRegistry {
14
+ version: string;
15
+ modules: Map<string, RuntimeModule>;
16
+ /** Shared per-page state slots (the ticker lives here). */
17
+ slots: Record<string, unknown>;
18
+ }
19
+
20
+ /**
21
+ * `motionary/runtime/physics` (10.7) — a small 2D rigid-body engine written
22
+ * for Motionary (own implementation and API; no Matter.js / Box2D code):
23
+ *
24
+ * - bodies: circles, boxes and convex polygons (static, dynamic or
25
+ * kinematic), density → mass + moment of inertia, restitution, friction,
26
+ * sensors, collision groups / masks, sleeping;
27
+ * - collisions: sort-and-sweep broad phase, separating-axis narrow phase
28
+ * with clipped contact manifolds (up to 2 points), sequential, accumulated and
29
+ * clamped impulses (normal + Coulomb friction) with a Baumgarte position bias;
30
+ * - constraints: `distance` (rigid or a spring with `stiffness` /
31
+ * `damping`), `pin` (a body point to a world point — also the pointer
32
+ * drag constraint) and `weld`-like stiff distance pairs;
33
+ * - a fixed time step (default 1/60 s) with an accumulator, so results are
34
+ * the same at any frame rate; `world.run()` drives it from the shared
35
+ * runtime ticker (pauses while the ticker sleeps).
36
+ *
37
+ * Pure maths — no DOM: safe in SSR and workers. Units are up to you (the
38
+ * defaults assume pixels: gravity 980 px/s²).
39
+ */
40
+
41
+ type Num$1 = number;
42
+ interface Vec2 {
43
+ x: Num$1;
44
+ y: Num$1;
45
+ }
46
+ type ShapeKind = 'circle' | 'box' | 'polygon';
47
+ interface BodyOptions {
48
+ shape?: ShapeKind;
49
+ x?: Num$1;
50
+ y?: Num$1;
51
+ angle?: Num$1;
52
+ /** circle */
53
+ radius?: Num$1;
54
+ /** box */
55
+ width?: Num$1;
56
+ height?: Num$1;
57
+ /** polygon: local vertices (any winding; made convex-ccw) */
58
+ vertices?: [Num$1, Num$1][];
59
+ /** 'dynamic' (default), 'static' (never moves) or 'kinematic' (moves by its velocity, ignores forces / collisions). */
60
+ type?: 'dynamic' | 'static' | 'kinematic';
61
+ /** Mass per unit area (default 0.001 → a 40 px box weighs 1.6). */
62
+ density?: Num$1;
63
+ /** Overrides density. */
64
+ mass?: Num$1;
65
+ restitution?: Num$1;
66
+ friction?: Num$1;
67
+ vx?: Num$1;
68
+ vy?: Num$1;
69
+ angularVelocity?: Num$1;
70
+ /** Linear / angular damping per second (0–1). */
71
+ damping?: Num$1;
72
+ angularDamping?: Num$1;
73
+ /** Collides with nothing, reports overlaps only. */
74
+ sensor?: boolean;
75
+ /** Collision filtering: bodies collide when (a.category & b.mask) && (b.category & a.mask). */
76
+ category?: Num$1;
77
+ mask?: Num$1;
78
+ /** No rotation (infinite inertia). */
79
+ fixedRotation?: boolean;
80
+ label?: string;
81
+ /** Anything (e.g. a fill colour for your renderer). */
82
+ data?: unknown;
83
+ }
84
+ declare class Body {
85
+ readonly id: number;
86
+ label: string;
87
+ shape: ShapeKind;
88
+ type: 'dynamic' | 'static' | 'kinematic';
89
+ position: Vec2;
90
+ velocity: Vec2;
91
+ angle: Num$1;
92
+ angularVelocity: Num$1;
93
+ force: Vec2;
94
+ torque: number;
95
+ radius: number;
96
+ /** Local convex vertices (counter-clockwise) for boxes / polygons. */
97
+ verts: Vec2[];
98
+ normals: Vec2[];
99
+ mass: number;
100
+ invMass: number;
101
+ inertia: number;
102
+ invInertia: number;
103
+ restitution: Num$1;
104
+ friction: Num$1;
105
+ damping: Num$1;
106
+ angularDamping: Num$1;
107
+ sensor: boolean;
108
+ category: Num$1;
109
+ mask: Num$1;
110
+ sleeping: boolean;
111
+ sleepTime: number;
112
+ data: unknown;
113
+ /** Bounding box, refreshed every step. */
114
+ aabb: {
115
+ minX: number;
116
+ minY: number;
117
+ maxX: number;
118
+ maxY: number;
119
+ };
120
+ private wv;
121
+ private wvAngle;
122
+ private wvPos;
123
+ constructor(o?: BodyOptions);
124
+ get isStatic(): boolean;
125
+ /** Vertices in world space (cached per pose). */
126
+ worldVerts(): Vec2[];
127
+ worldNormal(i: Num$1): Vec2;
128
+ updateAabb(): void;
129
+ applyImpulse(j: Vec2, at?: Vec2): void;
130
+ applyForce(f: Vec2, at?: Vec2): void;
131
+ wake(): void;
132
+ /** Is the world point inside this body? */
133
+ contains(x: Num$1, y: Num$1): boolean;
134
+ }
135
+ interface Contact {
136
+ point: Vec2;
137
+ depth: Num$1;
138
+ }
139
+ interface Manifold {
140
+ a: Body;
141
+ b: Body;
142
+ normal: Vec2;
143
+ contacts: Contact[];
144
+ }
145
+ interface ConstraintOptions {
146
+ type: 'distance' | 'pin';
147
+ a: Body;
148
+ /** distance: the other body; pin: omitted. */
149
+ b?: Body;
150
+ /** Anchor on a / b in body-local coordinates (default the centre). */
151
+ anchorA?: [Num$1, Num$1];
152
+ anchorB?: [Num$1, Num$1];
153
+ /** pin: the world point. */
154
+ point?: [Num$1, Num$1];
155
+ /** Rest length (default: the current distance). */
156
+ length?: Num$1;
157
+ /** 1 = rigid; < 1 = spring (fraction of the error corrected per step). */
158
+ stiffness?: Num$1;
159
+ /** Spring damping (0–1). */
160
+ damping?: Num$1;
161
+ label?: string;
162
+ }
163
+ declare class Constraint {
164
+ type: 'distance' | 'pin';
165
+ a: Body;
166
+ b: Body | null;
167
+ anchorA: Vec2;
168
+ anchorB: Vec2;
169
+ point: Vec2;
170
+ length: Num$1;
171
+ stiffness: Num$1;
172
+ damping: Num$1;
173
+ label: string;
174
+ constructor(o: ConstraintOptions);
175
+ worldA(): Vec2;
176
+ worldB(): Vec2;
177
+ /** One velocity iteration (impulse along the constraint axis, with a position bias). */
178
+ solve(h: Num$1): void;
179
+ }
180
+ interface WorldOptions {
181
+ gravity?: [Num$1, Num$1];
182
+ /** Velocity iterations per step (default 10). */
183
+ iterations?: Num$1;
184
+ /** Fixed step in seconds (default 1/60). */
185
+ step?: Num$1;
186
+ /** Let resting bodies sleep (default true). */
187
+ sleeping?: boolean;
188
+ }
189
+ type CollisionListener = (m: Manifold) => void;
190
+ declare class World {
191
+ gravity: Vec2;
192
+ iterations: Num$1;
193
+ fixedStep: Num$1;
194
+ sleeping: boolean;
195
+ bodies: Body[];
196
+ constraints: Constraint[];
197
+ /** Manifolds of the last step (incl. sensor overlaps, which have no response). */
198
+ contacts: Manifold[];
199
+ time: number;
200
+ steps: number;
201
+ private acc;
202
+ private warm;
203
+ private listeners;
204
+ private stop;
205
+ constructor(o?: WorldOptions);
206
+ add<T extends Body | Constraint>(...items: T[]): T;
207
+ body(o: BodyOptions): Body;
208
+ constraint(o: ConstraintOptions): Constraint;
209
+ remove(...items: (Body | Constraint)[]): void;
210
+ clear(): void;
211
+ /** Static walls around a w × h box (thickness t outside it). */
212
+ bounds(w: Num$1, h: Num$1, t?: number, o?: {
213
+ top?: boolean;
214
+ }): Body[];
215
+ onCollision(fn: CollisionListener): () => void;
216
+ /** Bodies under a world point (topmost = last added first). */
217
+ query(x: Num$1, y: Num$1): Body[];
218
+ /** Advance by `seconds` of real time in fixed steps (max 8 steps per call). */
219
+ update(seconds: Num$1): Num$1;
220
+ /** One fixed step of h seconds. */
221
+ step(h?: Num$1): void;
222
+ /** Drive the world from the shared runtime ticker (needs the core). Returns a stopper. */
223
+ run(): () => void;
224
+ get running(): boolean;
225
+ /** Total kinetic energy (handy for tests / "settled" checks). */
226
+ energy(): Num$1;
227
+ }
228
+
229
+ /**
230
+ * `motionary/runtime/format-scene` (10.7) — the versioned scene format
231
+ * `motionary-scene@1`: a JSON description of a 2D physics scene (world,
232
+ * named materials, bodies, constraints, per-body style) that
233
+ * `<usa-physics-playground>` and your own code can load, validate,
234
+ * migrate and save.
235
+ *
236
+ * ```json
237
+ * { "format": "motionary-scene@1",
238
+ * "world": { "width": 600, "height": 360, "gravity": [0, 980], "walls": true },
239
+ * "materials": { "rubber": { "restitution": 0.8, "friction": 0.6, "density": 0.001 } },
240
+ * "bodies": [
241
+ * { "id": "ball", "shape": "circle", "radius": 20, "position": [120, 40], "material": "rubber", "style": { "fill": "#f472b6" } },
242
+ * { "id": "floor-plank", "shape": "box", "size": [300, 16], "position": [300, 300], "angle": 0.1, "static": true }
243
+ * ],
244
+ * "constraints": [ { "type": "distance", "a": "ball", "b": "floor-plank", "length": 120, "stiffness": 0.3 } ] }
245
+ * ```
246
+ *
247
+ * - `validateScene(json)` lists problems (never throws);
248
+ * - `migrateScene(json)` upgrades older shapes (an unversioned scene, the
249
+ * `motionary-scene@0` draft) to `@1` and reports what it changed;
250
+ * - `parseScene(json)` = migrate + validate, throws on errors;
251
+ * - `sceneToWorld(scene)` builds a `motionary/runtime/physics` world
252
+ * (bodies by id); `worldToScene(world)` saves one back.
253
+ *
254
+ * Needs `motionary/runtime/physics` registered for `sceneToWorld` /
255
+ * `worldToScene`; validation and migration are pure.
256
+ */
257
+
258
+ type Num = number;
259
+ declare const SCENE_FORMAT = "motionary-scene@1";
260
+ interface SceneMaterial {
261
+ restitution?: Num;
262
+ friction?: Num;
263
+ density?: Num;
264
+ }
265
+ interface SceneBody {
266
+ id: string;
267
+ shape: 'circle' | 'box' | 'polygon';
268
+ position: [Num, Num];
269
+ angle?: Num;
270
+ radius?: Num;
271
+ size?: [Num, Num];
272
+ vertices?: [Num, Num][];
273
+ static?: boolean;
274
+ kinematic?: boolean;
275
+ material?: string;
276
+ restitution?: Num;
277
+ friction?: Num;
278
+ density?: Num;
279
+ velocity?: [Num, Num];
280
+ angularVelocity?: Num;
281
+ sensor?: boolean;
282
+ style?: {
283
+ fill?: string;
284
+ stroke?: string;
285
+ label?: string;
286
+ };
287
+ }
288
+ interface SceneConstraint {
289
+ type: 'distance' | 'pin';
290
+ a: string;
291
+ b?: string;
292
+ point?: [Num, Num];
293
+ anchorA?: [Num, Num];
294
+ anchorB?: [Num, Num];
295
+ length?: Num;
296
+ stiffness?: Num;
297
+ damping?: Num;
298
+ }
299
+ interface Scene {
300
+ format: typeof SCENE_FORMAT;
301
+ name?: string;
302
+ world: {
303
+ width: Num;
304
+ height: Num;
305
+ gravity?: [Num, Num];
306
+ walls?: boolean | {
307
+ top?: boolean;
308
+ };
309
+ iterations?: Num;
310
+ };
311
+ materials?: Record<string, SceneMaterial>;
312
+ bodies: SceneBody[];
313
+ constraints?: SceneConstraint[];
314
+ }
315
+ /** Upgrade older scene shapes to `motionary-scene@1`. Returns the scene and what changed. */
316
+ declare function migrateScene(input: unknown): {
317
+ scene: any;
318
+ changes: string[];
319
+ };
320
+ /** Problems in a `motionary-scene@1` document (after migration). Never throws. */
321
+ declare function validateScene(input: unknown): string[];
322
+ /** Migrate + validate; throws one error listing every problem. */
323
+ declare function parseScene(input: unknown): Scene;
324
+ /** Build a physics world from a scene (needs `use(physics)`). */
325
+ declare function sceneToWorld(input: Scene | unknown): {
326
+ world: World;
327
+ bodies: Record<string, Body>;
328
+ scene: Scene;
329
+ };
330
+ /** Save the current state of a world as a scene (walls made by `bounds()` are left out; `w` / `h` give the world size). */
331
+ declare function worldToScene(world: World, o?: {
332
+ width: Num;
333
+ height: Num;
334
+ name?: string;
335
+ walls?: boolean;
336
+ }): Scene;
337
+ interface FormatSceneApi {
338
+ SCENE_FORMAT: typeof SCENE_FORMAT;
339
+ migrateScene: typeof migrateScene;
340
+ validateScene: typeof validateScene;
341
+ parseScene: typeof parseScene;
342
+ sceneToWorld: typeof sceneToWorld;
343
+ worldToScene: typeof worldToScene;
344
+ }
345
+ /** The module object for `use(formatScene)` (needs `physics`). */
346
+ declare const formatScene: RuntimeModule<FormatSceneApi>;
347
+
348
+ export { SCENE_FORMAT, formatScene, migrateScene, parseScene, sceneToWorld, validateScene, worldToScene };
349
+ export type { FormatSceneApi, Scene, SceneBody, SceneConstraint, SceneMaterial };
@@ -0,0 +1,349 @@
1
+ /** A runtime module: `{ id, version, api }`, registered with `use()`. */
2
+ interface RuntimeModule<A = unknown> {
3
+ /** Module id: 'core', 'format-css', 'scroll', … (import path `motionary/runtime/<id>`). */
4
+ id: string;
5
+ version: string;
6
+ /** Other modules this one needs (registered first by `use()` callers). */
7
+ requires?: string[];
8
+ /** The module's public API (what `requireModule(id)` returns). */
9
+ api: A;
10
+ /** Optional one-time setup, called on first registration. */
11
+ setup?(registry: RuntimeRegistry): void;
12
+ }
13
+ interface RuntimeRegistry {
14
+ version: string;
15
+ modules: Map<string, RuntimeModule>;
16
+ /** Shared per-page state slots (the ticker lives here). */
17
+ slots: Record<string, unknown>;
18
+ }
19
+
20
+ /**
21
+ * `motionary/runtime/physics` (10.7) — a small 2D rigid-body engine written
22
+ * for Motionary (own implementation and API; no Matter.js / Box2D code):
23
+ *
24
+ * - bodies: circles, boxes and convex polygons (static, dynamic or
25
+ * kinematic), density → mass + moment of inertia, restitution, friction,
26
+ * sensors, collision groups / masks, sleeping;
27
+ * - collisions: sort-and-sweep broad phase, separating-axis narrow phase
28
+ * with clipped contact manifolds (up to 2 points), sequential, accumulated and
29
+ * clamped impulses (normal + Coulomb friction) with a Baumgarte position bias;
30
+ * - constraints: `distance` (rigid or a spring with `stiffness` /
31
+ * `damping`), `pin` (a body point to a world point — also the pointer
32
+ * drag constraint) and `weld`-like stiff distance pairs;
33
+ * - a fixed time step (default 1/60 s) with an accumulator, so results are
34
+ * the same at any frame rate; `world.run()` drives it from the shared
35
+ * runtime ticker (pauses while the ticker sleeps).
36
+ *
37
+ * Pure maths — no DOM: safe in SSR and workers. Units are up to you (the
38
+ * defaults assume pixels: gravity 980 px/s²).
39
+ */
40
+
41
+ type Num$1 = number;
42
+ interface Vec2 {
43
+ x: Num$1;
44
+ y: Num$1;
45
+ }
46
+ type ShapeKind = 'circle' | 'box' | 'polygon';
47
+ interface BodyOptions {
48
+ shape?: ShapeKind;
49
+ x?: Num$1;
50
+ y?: Num$1;
51
+ angle?: Num$1;
52
+ /** circle */
53
+ radius?: Num$1;
54
+ /** box */
55
+ width?: Num$1;
56
+ height?: Num$1;
57
+ /** polygon: local vertices (any winding; made convex-ccw) */
58
+ vertices?: [Num$1, Num$1][];
59
+ /** 'dynamic' (default), 'static' (never moves) or 'kinematic' (moves by its velocity, ignores forces / collisions). */
60
+ type?: 'dynamic' | 'static' | 'kinematic';
61
+ /** Mass per unit area (default 0.001 → a 40 px box weighs 1.6). */
62
+ density?: Num$1;
63
+ /** Overrides density. */
64
+ mass?: Num$1;
65
+ restitution?: Num$1;
66
+ friction?: Num$1;
67
+ vx?: Num$1;
68
+ vy?: Num$1;
69
+ angularVelocity?: Num$1;
70
+ /** Linear / angular damping per second (0–1). */
71
+ damping?: Num$1;
72
+ angularDamping?: Num$1;
73
+ /** Collides with nothing, reports overlaps only. */
74
+ sensor?: boolean;
75
+ /** Collision filtering: bodies collide when (a.category & b.mask) && (b.category & a.mask). */
76
+ category?: Num$1;
77
+ mask?: Num$1;
78
+ /** No rotation (infinite inertia). */
79
+ fixedRotation?: boolean;
80
+ label?: string;
81
+ /** Anything (e.g. a fill colour for your renderer). */
82
+ data?: unknown;
83
+ }
84
+ declare class Body {
85
+ readonly id: number;
86
+ label: string;
87
+ shape: ShapeKind;
88
+ type: 'dynamic' | 'static' | 'kinematic';
89
+ position: Vec2;
90
+ velocity: Vec2;
91
+ angle: Num$1;
92
+ angularVelocity: Num$1;
93
+ force: Vec2;
94
+ torque: number;
95
+ radius: number;
96
+ /** Local convex vertices (counter-clockwise) for boxes / polygons. */
97
+ verts: Vec2[];
98
+ normals: Vec2[];
99
+ mass: number;
100
+ invMass: number;
101
+ inertia: number;
102
+ invInertia: number;
103
+ restitution: Num$1;
104
+ friction: Num$1;
105
+ damping: Num$1;
106
+ angularDamping: Num$1;
107
+ sensor: boolean;
108
+ category: Num$1;
109
+ mask: Num$1;
110
+ sleeping: boolean;
111
+ sleepTime: number;
112
+ data: unknown;
113
+ /** Bounding box, refreshed every step. */
114
+ aabb: {
115
+ minX: number;
116
+ minY: number;
117
+ maxX: number;
118
+ maxY: number;
119
+ };
120
+ private wv;
121
+ private wvAngle;
122
+ private wvPos;
123
+ constructor(o?: BodyOptions);
124
+ get isStatic(): boolean;
125
+ /** Vertices in world space (cached per pose). */
126
+ worldVerts(): Vec2[];
127
+ worldNormal(i: Num$1): Vec2;
128
+ updateAabb(): void;
129
+ applyImpulse(j: Vec2, at?: Vec2): void;
130
+ applyForce(f: Vec2, at?: Vec2): void;
131
+ wake(): void;
132
+ /** Is the world point inside this body? */
133
+ contains(x: Num$1, y: Num$1): boolean;
134
+ }
135
+ interface Contact {
136
+ point: Vec2;
137
+ depth: Num$1;
138
+ }
139
+ interface Manifold {
140
+ a: Body;
141
+ b: Body;
142
+ normal: Vec2;
143
+ contacts: Contact[];
144
+ }
145
+ interface ConstraintOptions {
146
+ type: 'distance' | 'pin';
147
+ a: Body;
148
+ /** distance: the other body; pin: omitted. */
149
+ b?: Body;
150
+ /** Anchor on a / b in body-local coordinates (default the centre). */
151
+ anchorA?: [Num$1, Num$1];
152
+ anchorB?: [Num$1, Num$1];
153
+ /** pin: the world point. */
154
+ point?: [Num$1, Num$1];
155
+ /** Rest length (default: the current distance). */
156
+ length?: Num$1;
157
+ /** 1 = rigid; < 1 = spring (fraction of the error corrected per step). */
158
+ stiffness?: Num$1;
159
+ /** Spring damping (0–1). */
160
+ damping?: Num$1;
161
+ label?: string;
162
+ }
163
+ declare class Constraint {
164
+ type: 'distance' | 'pin';
165
+ a: Body;
166
+ b: Body | null;
167
+ anchorA: Vec2;
168
+ anchorB: Vec2;
169
+ point: Vec2;
170
+ length: Num$1;
171
+ stiffness: Num$1;
172
+ damping: Num$1;
173
+ label: string;
174
+ constructor(o: ConstraintOptions);
175
+ worldA(): Vec2;
176
+ worldB(): Vec2;
177
+ /** One velocity iteration (impulse along the constraint axis, with a position bias). */
178
+ solve(h: Num$1): void;
179
+ }
180
+ interface WorldOptions {
181
+ gravity?: [Num$1, Num$1];
182
+ /** Velocity iterations per step (default 10). */
183
+ iterations?: Num$1;
184
+ /** Fixed step in seconds (default 1/60). */
185
+ step?: Num$1;
186
+ /** Let resting bodies sleep (default true). */
187
+ sleeping?: boolean;
188
+ }
189
+ type CollisionListener = (m: Manifold) => void;
190
+ declare class World {
191
+ gravity: Vec2;
192
+ iterations: Num$1;
193
+ fixedStep: Num$1;
194
+ sleeping: boolean;
195
+ bodies: Body[];
196
+ constraints: Constraint[];
197
+ /** Manifolds of the last step (incl. sensor overlaps, which have no response). */
198
+ contacts: Manifold[];
199
+ time: number;
200
+ steps: number;
201
+ private acc;
202
+ private warm;
203
+ private listeners;
204
+ private stop;
205
+ constructor(o?: WorldOptions);
206
+ add<T extends Body | Constraint>(...items: T[]): T;
207
+ body(o: BodyOptions): Body;
208
+ constraint(o: ConstraintOptions): Constraint;
209
+ remove(...items: (Body | Constraint)[]): void;
210
+ clear(): void;
211
+ /** Static walls around a w × h box (thickness t outside it). */
212
+ bounds(w: Num$1, h: Num$1, t?: number, o?: {
213
+ top?: boolean;
214
+ }): Body[];
215
+ onCollision(fn: CollisionListener): () => void;
216
+ /** Bodies under a world point (topmost = last added first). */
217
+ query(x: Num$1, y: Num$1): Body[];
218
+ /** Advance by `seconds` of real time in fixed steps (max 8 steps per call). */
219
+ update(seconds: Num$1): Num$1;
220
+ /** One fixed step of h seconds. */
221
+ step(h?: Num$1): void;
222
+ /** Drive the world from the shared runtime ticker (needs the core). Returns a stopper. */
223
+ run(): () => void;
224
+ get running(): boolean;
225
+ /** Total kinetic energy (handy for tests / "settled" checks). */
226
+ energy(): Num$1;
227
+ }
228
+
229
+ /**
230
+ * `motionary/runtime/format-scene` (10.7) — the versioned scene format
231
+ * `motionary-scene@1`: a JSON description of a 2D physics scene (world,
232
+ * named materials, bodies, constraints, per-body style) that
233
+ * `<usa-physics-playground>` and your own code can load, validate,
234
+ * migrate and save.
235
+ *
236
+ * ```json
237
+ * { "format": "motionary-scene@1",
238
+ * "world": { "width": 600, "height": 360, "gravity": [0, 980], "walls": true },
239
+ * "materials": { "rubber": { "restitution": 0.8, "friction": 0.6, "density": 0.001 } },
240
+ * "bodies": [
241
+ * { "id": "ball", "shape": "circle", "radius": 20, "position": [120, 40], "material": "rubber", "style": { "fill": "#f472b6" } },
242
+ * { "id": "floor-plank", "shape": "box", "size": [300, 16], "position": [300, 300], "angle": 0.1, "static": true }
243
+ * ],
244
+ * "constraints": [ { "type": "distance", "a": "ball", "b": "floor-plank", "length": 120, "stiffness": 0.3 } ] }
245
+ * ```
246
+ *
247
+ * - `validateScene(json)` lists problems (never throws);
248
+ * - `migrateScene(json)` upgrades older shapes (an unversioned scene, the
249
+ * `motionary-scene@0` draft) to `@1` and reports what it changed;
250
+ * - `parseScene(json)` = migrate + validate, throws on errors;
251
+ * - `sceneToWorld(scene)` builds a `motionary/runtime/physics` world
252
+ * (bodies by id); `worldToScene(world)` saves one back.
253
+ *
254
+ * Needs `motionary/runtime/physics` registered for `sceneToWorld` /
255
+ * `worldToScene`; validation and migration are pure.
256
+ */
257
+
258
+ type Num = number;
259
+ declare const SCENE_FORMAT = "motionary-scene@1";
260
+ interface SceneMaterial {
261
+ restitution?: Num;
262
+ friction?: Num;
263
+ density?: Num;
264
+ }
265
+ interface SceneBody {
266
+ id: string;
267
+ shape: 'circle' | 'box' | 'polygon';
268
+ position: [Num, Num];
269
+ angle?: Num;
270
+ radius?: Num;
271
+ size?: [Num, Num];
272
+ vertices?: [Num, Num][];
273
+ static?: boolean;
274
+ kinematic?: boolean;
275
+ material?: string;
276
+ restitution?: Num;
277
+ friction?: Num;
278
+ density?: Num;
279
+ velocity?: [Num, Num];
280
+ angularVelocity?: Num;
281
+ sensor?: boolean;
282
+ style?: {
283
+ fill?: string;
284
+ stroke?: string;
285
+ label?: string;
286
+ };
287
+ }
288
+ interface SceneConstraint {
289
+ type: 'distance' | 'pin';
290
+ a: string;
291
+ b?: string;
292
+ point?: [Num, Num];
293
+ anchorA?: [Num, Num];
294
+ anchorB?: [Num, Num];
295
+ length?: Num;
296
+ stiffness?: Num;
297
+ damping?: Num;
298
+ }
299
+ interface Scene {
300
+ format: typeof SCENE_FORMAT;
301
+ name?: string;
302
+ world: {
303
+ width: Num;
304
+ height: Num;
305
+ gravity?: [Num, Num];
306
+ walls?: boolean | {
307
+ top?: boolean;
308
+ };
309
+ iterations?: Num;
310
+ };
311
+ materials?: Record<string, SceneMaterial>;
312
+ bodies: SceneBody[];
313
+ constraints?: SceneConstraint[];
314
+ }
315
+ /** Upgrade older scene shapes to `motionary-scene@1`. Returns the scene and what changed. */
316
+ declare function migrateScene(input: unknown): {
317
+ scene: any;
318
+ changes: string[];
319
+ };
320
+ /** Problems in a `motionary-scene@1` document (after migration). Never throws. */
321
+ declare function validateScene(input: unknown): string[];
322
+ /** Migrate + validate; throws one error listing every problem. */
323
+ declare function parseScene(input: unknown): Scene;
324
+ /** Build a physics world from a scene (needs `use(physics)`). */
325
+ declare function sceneToWorld(input: Scene | unknown): {
326
+ world: World;
327
+ bodies: Record<string, Body>;
328
+ scene: Scene;
329
+ };
330
+ /** Save the current state of a world as a scene (walls made by `bounds()` are left out; `w` / `h` give the world size). */
331
+ declare function worldToScene(world: World, o?: {
332
+ width: Num;
333
+ height: Num;
334
+ name?: string;
335
+ walls?: boolean;
336
+ }): Scene;
337
+ interface FormatSceneApi {
338
+ SCENE_FORMAT: typeof SCENE_FORMAT;
339
+ migrateScene: typeof migrateScene;
340
+ validateScene: typeof validateScene;
341
+ parseScene: typeof parseScene;
342
+ sceneToWorld: typeof sceneToWorld;
343
+ worldToScene: typeof worldToScene;
344
+ }
345
+ /** The module object for `use(formatScene)` (needs `physics`). */
346
+ declare const formatScene: RuntimeModule<FormatSceneApi>;
347
+
348
+ export { SCENE_FORMAT, formatScene, migrateScene, parseScene, sceneToWorld, validateScene, worldToScene };
349
+ export type { FormatSceneApi, Scene, SceneBody, SceneConstraint, SceneMaterial };