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.
- package/LICENSE +21 -0
- package/README.md +81 -0
- package/dist/animation/anim.d.ts +57 -0
- package/dist/animation/anim.js +318 -0
- package/dist/animation/combinators.d.ts +39 -0
- package/dist/animation/combinators.js +113 -0
- package/dist/animation/easings.d.ts +5 -0
- package/dist/animation/easings.js +5 -0
- package/dist/animation/index.d.ts +3 -0
- package/dist/animation/index.js +3 -0
- package/dist/assert/algebra.d.ts +20 -0
- package/dist/assert/algebra.js +79 -0
- package/dist/assert/claim.d.ts +40 -0
- package/dist/assert/claim.js +129 -0
- package/dist/assert/index.d.ts +7 -0
- package/dist/assert/index.js +19 -0
- package/dist/assert/predicates.d.ts +18 -0
- package/dist/assert/predicates.js +43 -0
- package/dist/assert/record.d.ts +20 -0
- package/dist/assert/record.js +78 -0
- package/dist/assert/scope.d.ts +42 -0
- package/dist/assert/scope.js +233 -0
- package/dist/assert/span.d.ts +37 -0
- package/dist/assert/span.js +68 -0
- package/dist/assert/tree.d.ts +22 -0
- package/dist/assert/tree.js +65 -0
- package/dist/code/code.d.ts +70 -0
- package/dist/code/code.js +361 -0
- package/dist/code/index.d.ts +2 -0
- package/dist/code/index.js +9 -0
- package/dist/code/morph.d.ts +5 -0
- package/dist/code/morph.js +194 -0
- package/dist/code/tokenize.d.ts +8 -0
- package/dist/code/tokenize.js +51 -0
- package/dist/constraints/cluster.d.ts +83 -0
- package/dist/constraints/cluster.js +213 -0
- package/dist/constraints/drivers.d.ts +15 -0
- package/dist/constraints/drivers.js +40 -0
- package/dist/constraints/factories.d.ts +73 -0
- package/dist/constraints/factories.js +248 -0
- package/dist/constraints/index.d.ts +11 -0
- package/dist/constraints/index.js +39 -0
- package/dist/constraints/interaction.d.ts +21 -0
- package/dist/constraints/interaction.js +148 -0
- package/dist/constraints/linalg.d.ts +18 -0
- package/dist/constraints/linalg.js +141 -0
- package/dist/constraints/phases.d.ts +21 -0
- package/dist/constraints/phases.js +60 -0
- package/dist/constraints/physics.d.ts +34 -0
- package/dist/constraints/physics.js +128 -0
- package/dist/constraints/rigid.d.ts +210 -0
- package/dist/constraints/rigid.js +835 -0
- package/dist/constraints/solver.d.ts +107 -0
- package/dist/constraints/solver.js +510 -0
- package/dist/constraints/term.d.ts +50 -0
- package/dist/constraints/term.js +80 -0
- package/dist/constraints/terms.d.ts +80 -0
- package/dist/constraints/terms.js +302 -0
- package/dist/constraints/world.d.ts +31 -0
- package/dist/constraints/world.js +245 -0
- package/dist/core/aggregates.d.ts +64 -0
- package/dist/core/aggregates.js +198 -0
- package/dist/core/anim.d.ts +84 -0
- package/dist/core/anim.js +301 -0
- package/dist/core/index.d.ts +38 -0
- package/dist/core/index.js +38 -0
- package/dist/core/introspect.d.ts +5 -0
- package/dist/core/introspect.js +31 -0
- package/dist/core/lenses/closed-form-policies.d.ts +64 -0
- package/dist/core/lenses/closed-form-policies.js +452 -0
- package/dist/core/lenses/domain-aggregates.d.ts +54 -0
- package/dist/core/lenses/domain-aggregates.js +259 -0
- package/dist/core/lenses/factor-lens.d.ts +42 -0
- package/dist/core/lenses/factor-lens.js +419 -0
- package/dist/core/lenses/index.d.ts +5 -0
- package/dist/core/lenses/index.js +16 -0
- package/dist/core/lenses/memory.d.ts +47 -0
- package/dist/core/lenses/memory.js +102 -0
- package/dist/core/lenses/typed-factor.d.ts +45 -0
- package/dist/core/lenses/typed-factor.js +376 -0
- package/dist/core/network-utils.d.ts +14 -0
- package/dist/core/network-utils.js +62 -0
- package/dist/core/new-primitives.d.ts +33 -0
- package/dist/core/new-primitives.js +113 -0
- package/dist/core/signal.d.ts +254 -0
- package/dist/core/signal.js +1349 -0
- package/dist/core/traits.d.ts +61 -0
- package/dist/core/traits.js +56 -0
- package/dist/core/tree.d.ts +23 -0
- package/dist/core/tree.js +62 -0
- package/dist/core/values/anchor.d.ts +23 -0
- package/dist/core/values/anchor.js +23 -0
- package/dist/core/values/audio.d.ts +33 -0
- package/dist/core/values/audio.js +107 -0
- package/dist/core/values/bool.d.ts +37 -0
- package/dist/core/values/bool.js +75 -0
- package/dist/core/values/box.d.ts +77 -0
- package/dist/core/values/box.js +211 -0
- package/dist/core/values/canvas.d.ts +71 -0
- package/dist/core/values/canvas.js +495 -0
- package/dist/core/values/color.d.ts +49 -0
- package/dist/core/values/color.js +106 -0
- package/dist/core/values/flags.d.ts +18 -0
- package/dist/core/values/flags.js +50 -0
- package/dist/core/values/gpu.d.ts +74 -0
- package/dist/core/values/gpu.js +426 -0
- package/dist/core/values/matrix.d.ts +53 -0
- package/dist/core/values/matrix.js +140 -0
- package/dist/core/values/num.d.ts +62 -0
- package/dist/core/values/num.js +166 -0
- package/dist/core/values/pose.d.ts +31 -0
- package/dist/core/values/pose.js +83 -0
- package/dist/core/values/range.d.ts +83 -0
- package/dist/core/values/range.js +167 -0
- package/dist/core/values/str.d.ts +76 -0
- package/dist/core/values/str.js +346 -0
- package/dist/core/values/template.d.ts +49 -0
- package/dist/core/values/template.js +148 -0
- package/dist/core/values/transform.d.ts +49 -0
- package/dist/core/values/transform.js +115 -0
- package/dist/core/values/tri.d.ts +31 -0
- package/dist/core/values/tri.js +95 -0
- package/dist/core/values/vec.d.ts +72 -0
- package/dist/core/values/vec.js +219 -0
- package/dist/core/writable.d.ts +15 -0
- package/dist/core/writable.js +29 -0
- package/dist/ext/events.d.ts +10 -0
- package/dist/ext/events.js +31 -0
- package/dist/ext/index.d.ts +4 -0
- package/dist/ext/index.js +4 -0
- package/dist/ext/snapshot.d.ts +8 -0
- package/dist/ext/snapshot.js +29 -0
- package/dist/ext/timeline.d.ts +56 -0
- package/dist/ext/timeline.js +94 -0
- package/dist/ext/waapi.d.ts +25 -0
- package/dist/ext/waapi.js +198 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +10 -0
- package/dist/propagators/index.d.ts +6 -0
- package/dist/propagators/index.js +6 -0
- package/dist/propagators/layout.d.ts +68 -0
- package/dist/propagators/layout.js +336 -0
- package/dist/propagators/network.d.ts +52 -0
- package/dist/propagators/network.js +185 -0
- package/dist/propagators/propagator.d.ts +12 -0
- package/dist/propagators/propagator.js +16 -0
- package/dist/propagators/range.d.ts +45 -0
- package/dist/propagators/range.js +147 -0
- package/dist/propagators/relations.d.ts +60 -0
- package/dist/propagators/relations.js +343 -0
- package/dist/shapes/annular-sector.d.ts +15 -0
- package/dist/shapes/annular-sector.js +64 -0
- package/dist/shapes/button.d.ts +14 -0
- package/dist/shapes/button.js +31 -0
- package/dist/shapes/choreographers.d.ts +22 -0
- package/dist/shapes/choreographers.js +69 -0
- package/dist/shapes/circle.d.ts +17 -0
- package/dist/shapes/circle.js +57 -0
- package/dist/shapes/clip.d.ts +5 -0
- package/dist/shapes/clip.js +31 -0
- package/dist/shapes/connect.d.ts +16 -0
- package/dist/shapes/connect.js +70 -0
- package/dist/shapes/curve.d.ts +60 -0
- package/dist/shapes/curve.js +285 -0
- package/dist/shapes/dashed.d.ts +16 -0
- package/dist/shapes/dashed.js +142 -0
- package/dist/shapes/debug.d.ts +43 -0
- package/dist/shapes/debug.js +97 -0
- package/dist/shapes/group.d.ts +5 -0
- package/dist/shapes/group.js +10 -0
- package/dist/shapes/handle.d.ts +32 -0
- package/dist/shapes/handle.js +88 -0
- package/dist/shapes/index.d.ts +23 -0
- package/dist/shapes/index.js +23 -0
- package/dist/shapes/interaction.d.ts +32 -0
- package/dist/shapes/interaction.js +187 -0
- package/dist/shapes/label.d.ts +20 -0
- package/dist/shapes/label.js +42 -0
- package/dist/shapes/layout.d.ts +29 -0
- package/dist/shapes/layout.js +74 -0
- package/dist/shapes/line.d.ts +21 -0
- package/dist/shapes/line.js +79 -0
- package/dist/shapes/list.d.ts +18 -0
- package/dist/shapes/list.js +51 -0
- package/dist/shapes/mount.d.ts +7 -0
- package/dist/shapes/mount.js +10 -0
- package/dist/shapes/path.d.ts +77 -0
- package/dist/shapes/path.js +227 -0
- package/dist/shapes/rect.d.ts +30 -0
- package/dist/shapes/rect.js +131 -0
- package/dist/shapes/shape.d.ts +132 -0
- package/dist/shapes/shape.js +306 -0
- package/dist/shapes/text.d.ts +24 -0
- package/dist/shapes/text.js +53 -0
- package/dist/shapes/tokens.d.ts +28 -0
- package/dist/shapes/tokens.js +27 -0
- package/dist/shapes/transitions.d.ts +23 -0
- package/dist/shapes/transitions.js +62 -0
- package/dist/tex/decorations.d.ts +26 -0
- package/dist/tex/decorations.js +116 -0
- package/dist/tex/index.d.ts +5 -0
- package/dist/tex/index.js +5 -0
- package/dist/tex/marker.d.ts +17 -0
- package/dist/tex/marker.js +63 -0
- package/dist/tex/motion.d.ts +43 -0
- package/dist/tex/motion.js +290 -0
- package/dist/tex/parts.d.ts +65 -0
- package/dist/tex/parts.js +149 -0
- package/dist/tex/tex.d.ts +45 -0
- package/dist/tex/tex.js +244 -0
- package/dist/web/attr.d.ts +16 -0
- package/dist/web/attr.js +98 -0
- package/dist/web/diagram.d.ts +49 -0
- package/dist/web/diagram.js +260 -0
- package/dist/web/index.d.ts +6 -0
- package/dist/web/index.js +6 -0
- package/dist/web/md-marker.d.ts +6 -0
- package/dist/web/md-marker.js +39 -0
- package/dist/web/md-tex.d.ts +6 -0
- package/dist/web/md-tex.js +61 -0
- package/dist/web/raf.d.ts +6 -0
- package/dist/web/raf.js +24 -0
- package/dist/web/viewport.d.ts +7 -0
- package/dist/web/viewport.js +13 -0
- 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 {};
|