bireactive 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +81 -0
  3. package/dist/animation/anim.d.ts +57 -0
  4. package/dist/animation/anim.js +318 -0
  5. package/dist/animation/combinators.d.ts +39 -0
  6. package/dist/animation/combinators.js +113 -0
  7. package/dist/animation/easings.d.ts +5 -0
  8. package/dist/animation/easings.js +5 -0
  9. package/dist/animation/index.d.ts +3 -0
  10. package/dist/animation/index.js +3 -0
  11. package/dist/assert/algebra.d.ts +20 -0
  12. package/dist/assert/algebra.js +79 -0
  13. package/dist/assert/claim.d.ts +40 -0
  14. package/dist/assert/claim.js +129 -0
  15. package/dist/assert/index.d.ts +7 -0
  16. package/dist/assert/index.js +19 -0
  17. package/dist/assert/predicates.d.ts +18 -0
  18. package/dist/assert/predicates.js +43 -0
  19. package/dist/assert/record.d.ts +20 -0
  20. package/dist/assert/record.js +78 -0
  21. package/dist/assert/scope.d.ts +42 -0
  22. package/dist/assert/scope.js +233 -0
  23. package/dist/assert/span.d.ts +37 -0
  24. package/dist/assert/span.js +68 -0
  25. package/dist/assert/tree.d.ts +22 -0
  26. package/dist/assert/tree.js +65 -0
  27. package/dist/code/code.d.ts +70 -0
  28. package/dist/code/code.js +361 -0
  29. package/dist/code/index.d.ts +2 -0
  30. package/dist/code/index.js +9 -0
  31. package/dist/code/morph.d.ts +5 -0
  32. package/dist/code/morph.js +194 -0
  33. package/dist/code/tokenize.d.ts +8 -0
  34. package/dist/code/tokenize.js +51 -0
  35. package/dist/constraints/cluster.d.ts +83 -0
  36. package/dist/constraints/cluster.js +213 -0
  37. package/dist/constraints/drivers.d.ts +15 -0
  38. package/dist/constraints/drivers.js +40 -0
  39. package/dist/constraints/factories.d.ts +73 -0
  40. package/dist/constraints/factories.js +248 -0
  41. package/dist/constraints/index.d.ts +11 -0
  42. package/dist/constraints/index.js +39 -0
  43. package/dist/constraints/interaction.d.ts +21 -0
  44. package/dist/constraints/interaction.js +148 -0
  45. package/dist/constraints/linalg.d.ts +18 -0
  46. package/dist/constraints/linalg.js +141 -0
  47. package/dist/constraints/phases.d.ts +21 -0
  48. package/dist/constraints/phases.js +60 -0
  49. package/dist/constraints/physics.d.ts +34 -0
  50. package/dist/constraints/physics.js +128 -0
  51. package/dist/constraints/rigid.d.ts +210 -0
  52. package/dist/constraints/rigid.js +835 -0
  53. package/dist/constraints/solver.d.ts +107 -0
  54. package/dist/constraints/solver.js +510 -0
  55. package/dist/constraints/term.d.ts +50 -0
  56. package/dist/constraints/term.js +80 -0
  57. package/dist/constraints/terms.d.ts +80 -0
  58. package/dist/constraints/terms.js +302 -0
  59. package/dist/constraints/world.d.ts +31 -0
  60. package/dist/constraints/world.js +245 -0
  61. package/dist/core/aggregates.d.ts +64 -0
  62. package/dist/core/aggregates.js +198 -0
  63. package/dist/core/anim.d.ts +84 -0
  64. package/dist/core/anim.js +301 -0
  65. package/dist/core/index.d.ts +38 -0
  66. package/dist/core/index.js +38 -0
  67. package/dist/core/introspect.d.ts +5 -0
  68. package/dist/core/introspect.js +31 -0
  69. package/dist/core/lenses/closed-form-policies.d.ts +64 -0
  70. package/dist/core/lenses/closed-form-policies.js +452 -0
  71. package/dist/core/lenses/domain-aggregates.d.ts +54 -0
  72. package/dist/core/lenses/domain-aggregates.js +259 -0
  73. package/dist/core/lenses/factor-lens.d.ts +42 -0
  74. package/dist/core/lenses/factor-lens.js +419 -0
  75. package/dist/core/lenses/index.d.ts +5 -0
  76. package/dist/core/lenses/index.js +16 -0
  77. package/dist/core/lenses/memory.d.ts +47 -0
  78. package/dist/core/lenses/memory.js +102 -0
  79. package/dist/core/lenses/typed-factor.d.ts +45 -0
  80. package/dist/core/lenses/typed-factor.js +376 -0
  81. package/dist/core/network-utils.d.ts +14 -0
  82. package/dist/core/network-utils.js +62 -0
  83. package/dist/core/new-primitives.d.ts +33 -0
  84. package/dist/core/new-primitives.js +113 -0
  85. package/dist/core/signal.d.ts +254 -0
  86. package/dist/core/signal.js +1349 -0
  87. package/dist/core/traits.d.ts +61 -0
  88. package/dist/core/traits.js +56 -0
  89. package/dist/core/tree.d.ts +23 -0
  90. package/dist/core/tree.js +62 -0
  91. package/dist/core/values/anchor.d.ts +23 -0
  92. package/dist/core/values/anchor.js +23 -0
  93. package/dist/core/values/audio.d.ts +33 -0
  94. package/dist/core/values/audio.js +107 -0
  95. package/dist/core/values/bool.d.ts +37 -0
  96. package/dist/core/values/bool.js +75 -0
  97. package/dist/core/values/box.d.ts +77 -0
  98. package/dist/core/values/box.js +211 -0
  99. package/dist/core/values/canvas.d.ts +71 -0
  100. package/dist/core/values/canvas.js +495 -0
  101. package/dist/core/values/color.d.ts +49 -0
  102. package/dist/core/values/color.js +106 -0
  103. package/dist/core/values/flags.d.ts +18 -0
  104. package/dist/core/values/flags.js +50 -0
  105. package/dist/core/values/gpu.d.ts +74 -0
  106. package/dist/core/values/gpu.js +426 -0
  107. package/dist/core/values/matrix.d.ts +53 -0
  108. package/dist/core/values/matrix.js +140 -0
  109. package/dist/core/values/num.d.ts +62 -0
  110. package/dist/core/values/num.js +166 -0
  111. package/dist/core/values/pose.d.ts +31 -0
  112. package/dist/core/values/pose.js +83 -0
  113. package/dist/core/values/range.d.ts +83 -0
  114. package/dist/core/values/range.js +167 -0
  115. package/dist/core/values/str.d.ts +76 -0
  116. package/dist/core/values/str.js +346 -0
  117. package/dist/core/values/template.d.ts +49 -0
  118. package/dist/core/values/template.js +148 -0
  119. package/dist/core/values/transform.d.ts +49 -0
  120. package/dist/core/values/transform.js +115 -0
  121. package/dist/core/values/tri.d.ts +31 -0
  122. package/dist/core/values/tri.js +95 -0
  123. package/dist/core/values/vec.d.ts +72 -0
  124. package/dist/core/values/vec.js +219 -0
  125. package/dist/core/writable.d.ts +15 -0
  126. package/dist/core/writable.js +29 -0
  127. package/dist/ext/events.d.ts +10 -0
  128. package/dist/ext/events.js +31 -0
  129. package/dist/ext/index.d.ts +4 -0
  130. package/dist/ext/index.js +4 -0
  131. package/dist/ext/snapshot.d.ts +8 -0
  132. package/dist/ext/snapshot.js +29 -0
  133. package/dist/ext/timeline.d.ts +56 -0
  134. package/dist/ext/timeline.js +94 -0
  135. package/dist/ext/waapi.d.ts +25 -0
  136. package/dist/ext/waapi.js +198 -0
  137. package/dist/index.d.ts +8 -0
  138. package/dist/index.js +10 -0
  139. package/dist/propagators/index.d.ts +6 -0
  140. package/dist/propagators/index.js +6 -0
  141. package/dist/propagators/layout.d.ts +68 -0
  142. package/dist/propagators/layout.js +336 -0
  143. package/dist/propagators/network.d.ts +52 -0
  144. package/dist/propagators/network.js +185 -0
  145. package/dist/propagators/propagator.d.ts +12 -0
  146. package/dist/propagators/propagator.js +16 -0
  147. package/dist/propagators/range.d.ts +45 -0
  148. package/dist/propagators/range.js +147 -0
  149. package/dist/propagators/relations.d.ts +60 -0
  150. package/dist/propagators/relations.js +343 -0
  151. package/dist/shapes/annular-sector.d.ts +15 -0
  152. package/dist/shapes/annular-sector.js +64 -0
  153. package/dist/shapes/button.d.ts +14 -0
  154. package/dist/shapes/button.js +31 -0
  155. package/dist/shapes/choreographers.d.ts +22 -0
  156. package/dist/shapes/choreographers.js +69 -0
  157. package/dist/shapes/circle.d.ts +17 -0
  158. package/dist/shapes/circle.js +57 -0
  159. package/dist/shapes/clip.d.ts +5 -0
  160. package/dist/shapes/clip.js +31 -0
  161. package/dist/shapes/connect.d.ts +16 -0
  162. package/dist/shapes/connect.js +70 -0
  163. package/dist/shapes/curve.d.ts +60 -0
  164. package/dist/shapes/curve.js +285 -0
  165. package/dist/shapes/dashed.d.ts +16 -0
  166. package/dist/shapes/dashed.js +142 -0
  167. package/dist/shapes/debug.d.ts +43 -0
  168. package/dist/shapes/debug.js +97 -0
  169. package/dist/shapes/group.d.ts +5 -0
  170. package/dist/shapes/group.js +10 -0
  171. package/dist/shapes/handle.d.ts +32 -0
  172. package/dist/shapes/handle.js +88 -0
  173. package/dist/shapes/index.d.ts +23 -0
  174. package/dist/shapes/index.js +23 -0
  175. package/dist/shapes/interaction.d.ts +32 -0
  176. package/dist/shapes/interaction.js +187 -0
  177. package/dist/shapes/label.d.ts +20 -0
  178. package/dist/shapes/label.js +42 -0
  179. package/dist/shapes/layout.d.ts +29 -0
  180. package/dist/shapes/layout.js +74 -0
  181. package/dist/shapes/line.d.ts +21 -0
  182. package/dist/shapes/line.js +79 -0
  183. package/dist/shapes/list.d.ts +18 -0
  184. package/dist/shapes/list.js +51 -0
  185. package/dist/shapes/mount.d.ts +7 -0
  186. package/dist/shapes/mount.js +10 -0
  187. package/dist/shapes/path.d.ts +77 -0
  188. package/dist/shapes/path.js +227 -0
  189. package/dist/shapes/rect.d.ts +30 -0
  190. package/dist/shapes/rect.js +131 -0
  191. package/dist/shapes/shape.d.ts +132 -0
  192. package/dist/shapes/shape.js +306 -0
  193. package/dist/shapes/text.d.ts +24 -0
  194. package/dist/shapes/text.js +53 -0
  195. package/dist/shapes/tokens.d.ts +28 -0
  196. package/dist/shapes/tokens.js +27 -0
  197. package/dist/shapes/transitions.d.ts +23 -0
  198. package/dist/shapes/transitions.js +62 -0
  199. package/dist/tex/decorations.d.ts +26 -0
  200. package/dist/tex/decorations.js +116 -0
  201. package/dist/tex/index.d.ts +5 -0
  202. package/dist/tex/index.js +5 -0
  203. package/dist/tex/marker.d.ts +17 -0
  204. package/dist/tex/marker.js +63 -0
  205. package/dist/tex/motion.d.ts +43 -0
  206. package/dist/tex/motion.js +290 -0
  207. package/dist/tex/parts.d.ts +65 -0
  208. package/dist/tex/parts.js +149 -0
  209. package/dist/tex/tex.d.ts +45 -0
  210. package/dist/tex/tex.js +244 -0
  211. package/dist/web/attr.d.ts +16 -0
  212. package/dist/web/attr.js +98 -0
  213. package/dist/web/diagram.d.ts +49 -0
  214. package/dist/web/diagram.js +260 -0
  215. package/dist/web/index.d.ts +6 -0
  216. package/dist/web/index.js +6 -0
  217. package/dist/web/md-marker.d.ts +6 -0
  218. package/dist/web/md-marker.js +39 -0
  219. package/dist/web/md-tex.d.ts +6 -0
  220. package/dist/web/md-tex.js +61 -0
  221. package/dist/web/raf.d.ts +6 -0
  222. package/dist/web/raf.js +24 -0
  223. package/dist/web/viewport.d.ts +7 -0
  224. package/dist/web/viewport.js +13 -0
  225. package/package.json +87 -0
@@ -0,0 +1,210 @@
1
+ import { Num, type Pose, Vec, type Writable } from "../core/index.js";
2
+ import type { Constraints, Relation } from "./cluster.js";
3
+ import type { Solver } from "./solver.js";
4
+ import { Term } from "./term.js";
5
+ export interface BodyOpts {
6
+ /** Box width (x extent) and height (y extent). */
7
+ size: {
8
+ w: number;
9
+ h: number;
10
+ };
11
+ /** Mass per unit area. `0` makes the body static (pinned, infinite
12
+ * mass). Default `1`. */
13
+ density?: number;
14
+ /** Friction coefficient. Two bodies' coefficients combine as the
15
+ * geometric mean. Default `0.5`. */
16
+ friction?: number;
17
+ }
18
+ export interface BodyInit {
19
+ x: number;
20
+ y: number;
21
+ theta?: number;
22
+ }
23
+ /** A 2D rigid body (a `Relation`; add via `world.add(body)`).
24
+ *
25
+ * Pose is one `Pose` signal; `position` (Vec) and `angle` (Num) are
26
+ * lenses on it for consumers wanting a narrower view. `cellId` is the
27
+ * solver cell after `bind` (-1 before). */
28
+ export declare class Body implements Relation {
29
+ readonly w: number;
30
+ readonly h: number;
31
+ readonly mass: number;
32
+ readonly moment: number;
33
+ readonly friction: number;
34
+ /** Bounding radius for the broadphase. */
35
+ readonly radius: number;
36
+ /** Reactive pose — single source of truth, updated each tick. */
37
+ readonly pose: Writable<Pose>;
38
+ /** Vec lens on `pose` (xy); writes propagate back through `pose`. */
39
+ readonly position: Writable<Vec>;
40
+ /** Num lens on `pose` (theta). */
41
+ readonly angle: Writable<Num>;
42
+ /** Solver cell id; -1 until `bind` runs. */
43
+ cellId: number;
44
+ /** @internal — set on bind so force code can read solver state. */
45
+ _solver?: Solver;
46
+ constructor(opts: BodyOpts, init: BodyInit);
47
+ bind(c: Constraints): () => void;
48
+ /** Relation that pins this body (mass → 0, kinematic) while
49
+ * attached; restores `(m, m, I)` on detach. Composes with
50
+ * `addWhile` for drag. The pose still updates from
51
+ * `body.position` / `body.angle` writes. */
52
+ pin(): Relation;
53
+ }
54
+ /** Create a rigid body (add via `world.add`). `density: 0` is static
55
+ * (mass 0, kinematic cell). */
56
+ export declare function body(opts: BodyOpts, init: BodyInit): Body;
57
+ interface Contact {
58
+ /** Penetration anchor on body A in A's local frame. */
59
+ rAx: number;
60
+ rAy: number;
61
+ /** Penetration anchor on body B in B's local frame. */
62
+ rBx: number;
63
+ rBy: number;
64
+ /** World-frame contact normal pointing A → B. */
65
+ nx: number;
66
+ ny: number;
67
+ /** Feature-pair (edge IDs) for warm-starting across frames. */
68
+ fp: number;
69
+ /** Whether the contact was sticking (static friction) last frame. */
70
+ stick: boolean;
71
+ }
72
+ /** Up to 2 contacts × (normal + tangent) = 4 rows. Coulomb friction
73
+ * via clamping tangential `λ` to the cone `±μ·|λ_normal|` (updated
74
+ * per iteration). Truncated Taylor at `x⁻` (paper §4), so `J` is
75
+ * precomputed in `initialize` and copied out by `computeDerivatives`. */
76
+ export declare class BoxContact extends Term {
77
+ bodyA: Body;
78
+ bodyB: Body;
79
+ numContacts: number;
80
+ contacts: Contact[];
81
+ private JAn;
82
+ private JBn;
83
+ private JAt;
84
+ private JBt;
85
+ private C0n;
86
+ private C0t;
87
+ private friction;
88
+ private _poseA;
89
+ private _poseB;
90
+ constructor(solver: Solver, bodyA: Body, bodyB: Body);
91
+ initialize(): boolean;
92
+ computeConstraint(alpha: number): void;
93
+ computeDerivatives(cellIdx: number): void;
94
+ }
95
+ export interface JointStiffness {
96
+ /** Stiffness for the X position row. `Infinity` = hard. Default `Infinity`. */
97
+ x?: number;
98
+ /** Stiffness for the Y position row. `Infinity` = hard. Default `Infinity`. */
99
+ y?: number;
100
+ /** Stiffness for the angle row. `0` = free (revolute joint, the
101
+ * rope/chain default). `Infinity` = rigid weld. Default `0`. */
102
+ angle?: number;
103
+ }
104
+ /** Internal term for a revolute joint (anchors `rA` on `bodyA`, `rB`
105
+ * on `bodyB`). Default: hard position rows, free angle (hinge);
106
+ * override via `JointStiffness`. Port of the AVBD 2D `Joint`. User
107
+ * code uses the `Joint` Relation via `world.add(joint(...))`. */
108
+ export declare class JointTerm extends Term {
109
+ readonly bodyA: Body;
110
+ readonly bodyB: Body;
111
+ rAx: number;
112
+ rAy: number;
113
+ rBx: number;
114
+ rBy: number;
115
+ readonly torqueArm: number;
116
+ readonly restAngle: number;
117
+ private _Cn;
118
+ private _C0Cache;
119
+ private _poseA;
120
+ private _poseB;
121
+ constructor(solver: Solver, bodyA: Body, bodyB: Body, rA: {
122
+ x: number;
123
+ y: number;
124
+ }, rB: {
125
+ x: number;
126
+ y: number;
127
+ }, opts?: JointStiffness);
128
+ initialize(): boolean;
129
+ computeConstraint(alpha: number): void;
130
+ computeDerivatives(cellIdx: number): void;
131
+ }
132
+ /** @internal — soft 2-row term pulling a body's translation toward
133
+ * `target` with finite `stiffness` (angle DOF left free). Backs the
134
+ * `BodyAnchor` relation; see `bodyAnchor`. */
135
+ export declare class BodyAnchorTerm extends Term {
136
+ readonly body: Body;
137
+ /** World-space target signal (mutable). */
138
+ readonly target: Writable<Vec>;
139
+ /** Mutable stiffness signal — refreshed each `initialize()`. */
140
+ readonly stiffnessSig: Writable<Num>;
141
+ constructor(solver: Solver, body: Body, target: Writable<Vec>, stiffness: Writable<Num>);
142
+ initialize(): boolean;
143
+ computeConstraint(_alpha: number): void;
144
+ computeDerivatives(_cellIdx: number): void;
145
+ }
146
+ /** Revolute or weld joint between two bodies (add via `world.add`).
147
+ * Default: hard position rows, free angle (hinge). `{ angle: Infinity }`
148
+ * welds; finite `{ x, y }` softens. `world` skips broadphase contacts
149
+ * between jointed pairs. */
150
+ export declare class Joint implements Relation {
151
+ readonly bodyA: Body;
152
+ readonly bodyB: Body;
153
+ readonly rA: {
154
+ x: number;
155
+ y: number;
156
+ };
157
+ readonly rB: {
158
+ x: number;
159
+ y: number;
160
+ };
161
+ readonly opts?: JointStiffness | undefined;
162
+ constructor(bodyA: Body, bodyB: Body, rA: {
163
+ x: number;
164
+ y: number;
165
+ }, rB: {
166
+ x: number;
167
+ y: number;
168
+ }, opts?: JointStiffness | undefined);
169
+ bind(c: Constraints): () => void;
170
+ }
171
+ export declare function joint(a: Body, b: Body, rA: {
172
+ x: number;
173
+ y: number;
174
+ }, rB: {
175
+ x: number;
176
+ y: number;
177
+ }, opts?: JointStiffness): Joint;
178
+ /** Rigid weld — a joint with all rows hard; fuses two bodies while
179
+ * keeping their independent inertias. */
180
+ export declare function weld(a: Body, b: Body, rA: {
181
+ x: number;
182
+ y: number;
183
+ }, rB: {
184
+ x: number;
185
+ y: number;
186
+ }): Joint;
187
+ /** Soft "drag" handle: pulls a body's translation toward `target`
188
+ * with finite stiffness. The body keeps its mass and reacts to
189
+ * contacts, so it lags behind the cursor when blocked rather than
190
+ * punching through. `target` and `stiffness` are mutable signals.
191
+ *
192
+ * const a = bodyAnchor(body, body.position.value, 5e4);
193
+ * world.addWhile(dragging, a);
194
+ * onPointerMove(p => a.target.value = p);
195
+ */
196
+ export declare class BodyAnchor implements Relation {
197
+ readonly body: Body;
198
+ readonly target: Writable<Vec>;
199
+ readonly stiffness: Writable<Num>;
200
+ constructor(body: Body, target: Writable<Vec> | {
201
+ x: number;
202
+ y: number;
203
+ }, stiffness: Writable<Num> | number);
204
+ bind(c: Constraints): () => void;
205
+ }
206
+ export declare function bodyAnchor(body: Body, target: Writable<Vec> | {
207
+ x: number;
208
+ y: number;
209
+ }, stiffness?: Writable<Num> | number): BodyAnchor;
210
+ export {};