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,301 @@
1
+ // anim.ts — animator primitives over `Animatable<T, K>` (writable +
2
+ // nominal trait constraint), plus the signals↔generators bridge.
3
+ //
4
+ // Signatures read as a sentence ("spring takes a writable carrying T
5
+ // with linear+metric"), so misuse is a compile error: `spring(box, …)`
6
+ // (no metric), `spring(roVec, …)` (not writable).
7
+ import { drive, easeOut, isGenerator, race, suspend, } from "../animation/index.js";
8
+ import { Cell, derive, effect, reader } from "./signal.js";
9
+ import { requireLerp, requireLinear, requireMetric } from "./traits.js";
10
+ const defaultEase = easeOut;
11
+ /** Chainable Animator over a writable cell: `.to(...).to(...).from(start)`
12
+ * reads naturally. `.to`/`.from` are pure data — segments accumulate at
13
+ * construction; the executor generator runs them in order on iteration. */
14
+ export class Tween {
15
+ #sig;
16
+ #segs;
17
+ #gen;
18
+ /** @internal — use `tween(...)` or `sig.to(...)` to construct. */
19
+ constructor(sig, segs = []) {
20
+ this.#sig = sig;
21
+ this.#segs = segs;
22
+ this.#gen = (function* () {
23
+ for (const seg of segs) {
24
+ if (seg.kind === "pose") {
25
+ sig.value = seg.target;
26
+ continue;
27
+ }
28
+ yield* tweenStep(sig, seg.target, seg.dur, seg.ease);
29
+ }
30
+ })();
31
+ }
32
+ /** Append a tween segment from current value to `target` over `dur`. */
33
+ to(target, dur, ease) {
34
+ return new Tween(this.#sig, [...this.#segs, { kind: "to", target, dur, ease }]);
35
+ }
36
+ /** Pose `start` as the first step, then run the rest of the chain. */
37
+ from(start) {
38
+ return new Tween(this.#sig, [{ kind: "pose", target: start }, ...this.#segs]);
39
+ }
40
+ next(v) {
41
+ return this.#gen.next(v);
42
+ }
43
+ return(v) {
44
+ return this.#gen.return(v);
45
+ }
46
+ throw(e) {
47
+ return this.#gen.throw(e);
48
+ }
49
+ [Symbol.iterator]() {
50
+ return this;
51
+ }
52
+ }
53
+ /** Append-only tween segment over a writable reactive target. */
54
+ function* tweenStep(sig, target, dur, ease = defaultEase) {
55
+ const lerp = requireLerp(sig);
56
+ const start = sig.peek();
57
+ const D = reader(dur);
58
+ yield* drive((tick, t) => {
59
+ const total = D();
60
+ if (total <= 0 || t + tick.dt * 1e-3 >= total) {
61
+ sig.value = target;
62
+ return false;
63
+ }
64
+ sig.value = lerp(start, target, ease(t / total));
65
+ });
66
+ }
67
+ /** Free-fn form of one-shot tween — returns a chainable `Tween<T>`. */
68
+ export function tween(sig, target, dur, ease) {
69
+ return new Tween(sig, [{ kind: "to", target, dur, ease }]);
70
+ }
71
+ /** Second-order damped-spring pull. */
72
+ export function* spring(sig, target, opts = {}) {
73
+ const lin = requireLinear(sig);
74
+ const met = requireMetric(sig);
75
+ const omega = opts.omega ?? 13;
76
+ const zeta = opts.zeta ?? 1;
77
+ const eps = opts.precision ?? 1e-4;
78
+ const rate = opts.rate;
79
+ const project = opts.project;
80
+ const T = reader(target);
81
+ const zero = lin.scale(sig.peek(), 0);
82
+ let vel = zero;
83
+ yield* drive(tick => {
84
+ const dt = rate ? tick.dt * rate() : tick.dt;
85
+ const t = T();
86
+ const cur = sig.peek();
87
+ const e0 = lin.sub(cur, t);
88
+ const v0 = vel;
89
+ let e1, v1;
90
+ if (zeta < 1 - 1e-6) {
91
+ const zw = zeta * omega;
92
+ const wd = omega * Math.sqrt(1 - zeta * zeta);
93
+ const E = Math.exp(-zw * dt);
94
+ const c = Math.cos(wd * dt);
95
+ const s = Math.sin(wd * dt);
96
+ const B = lin.scale(lin.add(v0, lin.scale(e0, zw)), 1 / wd);
97
+ const inner = lin.add(lin.scale(e0, c), lin.scale(B, s));
98
+ e1 = lin.scale(inner, E);
99
+ const swing = lin.sub(lin.scale(B, c), lin.scale(e0, s));
100
+ v1 = lin.add(lin.scale(e1, -zw), lin.scale(swing, E * wd));
101
+ }
102
+ else if (zeta > 1 + 1e-6) {
103
+ const r = omega * Math.sqrt(zeta * zeta - 1);
104
+ const r1 = -zeta * omega + r;
105
+ const r2 = -zeta * omega - r;
106
+ const denom = r2 - r1;
107
+ const B = lin.scale(lin.sub(v0, lin.scale(e0, r1)), 1 / denom);
108
+ const A = lin.sub(e0, B);
109
+ const E1 = Math.exp(r1 * dt);
110
+ const E2 = Math.exp(r2 * dt);
111
+ e1 = lin.add(lin.scale(A, E1), lin.scale(B, E2));
112
+ v1 = lin.add(lin.scale(A, r1 * E1), lin.scale(B, r2 * E2));
113
+ }
114
+ else {
115
+ const E = Math.exp(-omega * dt);
116
+ const B = lin.add(v0, lin.scale(e0, omega));
117
+ const Bt = lin.scale(B, dt);
118
+ e1 = lin.scale(lin.add(e0, Bt), E);
119
+ v1 = lin.sub(lin.scale(B, E), lin.scale(e1, omega));
120
+ }
121
+ const raw = lin.add(t, e1);
122
+ const next = project ? project(raw) : raw;
123
+ if (project && met(next, raw) > 0) {
124
+ e1 = lin.sub(next, t);
125
+ v1 = zero;
126
+ }
127
+ vel = v1;
128
+ sig.value = next;
129
+ if (eps > 0 && met(e1, zero) < eps && met(v1, zero) < eps * omega) {
130
+ sig.value = t;
131
+ return false;
132
+ }
133
+ });
134
+ }
135
+ /** Constant-speed approach (units-of-T per second). Needs linear+metric. */
136
+ export function* toward(sig, target, speed) {
137
+ const lin = requireLinear(sig);
138
+ const met = requireMetric(sig);
139
+ const T = reader(target);
140
+ const S = reader(speed);
141
+ yield* drive(tick => {
142
+ const t = T();
143
+ const cur = sig.peek();
144
+ const dist = met(cur, t);
145
+ const step = S() * tick.dt;
146
+ if (dist <= step) {
147
+ sig.value = t;
148
+ return false;
149
+ }
150
+ const dir = lin.scale(lin.sub(t, cur), 1 / dist);
151
+ sig.value = lin.add(cur, lin.scale(dir, step));
152
+ });
153
+ }
154
+ /** Exponential pull toward `target` at rate `k`/s (no overshoot). Needs linear. */
155
+ export function* attract(sig, target, k = 1) {
156
+ const lin = requireLinear(sig);
157
+ const T = reader(target);
158
+ const K = reader(k);
159
+ yield* drive(tick => {
160
+ const cur = sig.peek();
161
+ const delta = lin.scale(lin.sub(T(), cur), K() * tick.dt);
162
+ sig.value = lin.add(cur, delta);
163
+ });
164
+ }
165
+ /** Drive `sig` per frame with a pure function `f(t, initial)`. */
166
+ export function* wave(sig, fn) {
167
+ const initial = sig.peek();
168
+ yield* drive((_tick, t) => {
169
+ sig.value = fn(t, initial);
170
+ });
171
+ }
172
+ /** Escape hatch: drive sig per frame with `step(dt, t, current)`.
173
+ * Return `false` to terminate. Use `wave` instead for pure `f(t)`. */
174
+ export function* driven(sig, step) {
175
+ yield* drive((tick, t) => {
176
+ const next = step(tick.dt, t, sig.peek());
177
+ if (next === false)
178
+ return false;
179
+ sig.value = next;
180
+ });
181
+ }
182
+ class PlayImpl {
183
+ g;
184
+ constructor(g) {
185
+ this.g = g;
186
+ }
187
+ next(v) {
188
+ return this.g.next(v);
189
+ }
190
+ return(v) {
191
+ return this.g.return(v);
192
+ }
193
+ throw(e) {
194
+ return this.g.throw(e);
195
+ }
196
+ [Symbol.iterator]() {
197
+ return this;
198
+ }
199
+ until(p) {
200
+ const trigger = playableGen(p);
201
+ const g = this.g;
202
+ return new PlayImpl((function* () {
203
+ const result = yield* race(g, trigger);
204
+ return result;
205
+ })());
206
+ }
207
+ then(next) {
208
+ const g = this.g;
209
+ return new PlayImpl((function* () {
210
+ yield* g;
211
+ yield* playableGen(next);
212
+ })());
213
+ }
214
+ }
215
+ export function play(p) {
216
+ if (p instanceof PlayImpl)
217
+ return p;
218
+ if (typeof p === "function" && p.length === 0) {
219
+ p = p();
220
+ }
221
+ return new PlayImpl(playableGen(p));
222
+ }
223
+ function* playableGen(p) {
224
+ if (p instanceof Cell) {
225
+ yield* when(p);
226
+ return undefined;
227
+ }
228
+ if (p === undefined || p === null)
229
+ return undefined;
230
+ if (typeof p === "object" && p.next) {
231
+ return yield* p;
232
+ }
233
+ yield p;
234
+ return undefined;
235
+ }
236
+ /** Wait until `sig.value` is truthy. Wakes immediately if already true. */
237
+ export function when(sig) {
238
+ return suspend(wake => {
239
+ let resolved = false;
240
+ return effect(() => {
241
+ if (resolved)
242
+ return;
243
+ if (sig.value) {
244
+ resolved = true;
245
+ wake();
246
+ }
247
+ });
248
+ });
249
+ }
250
+ /** Reactive boolean negation as a `Cell<boolean>` (RO). */
251
+ export function not(sig) {
252
+ return derive(() => !sig.value);
253
+ }
254
+ /** Wait until `sig` changes; resumes with the new value. */
255
+ export function untilChange(sig) {
256
+ return suspend(wake => {
257
+ const initial = sig.peek();
258
+ let resolved = false;
259
+ return effect(() => {
260
+ const v = sig.value;
261
+ if (resolved)
262
+ return;
263
+ if (v !== initial) {
264
+ resolved = true;
265
+ wake(v);
266
+ }
267
+ });
268
+ });
269
+ }
270
+ /** Repeat `factory()` forever; bound via `.until(sig)`. */
271
+ export function loop(factory) {
272
+ return play((function* () {
273
+ while (true) {
274
+ const y = factory();
275
+ if (isGenerator(y))
276
+ yield* y;
277
+ else
278
+ yield y;
279
+ }
280
+ })());
281
+ }
282
+ /** Run `fn` every `sec` seconds (drift-corrected, `sec` may be reactive). */
283
+ export function every(sec, fn) {
284
+ const getSec = reader(sec);
285
+ return play((function* () {
286
+ let tick = yield;
287
+ let nextAt = tick.elapsed + Math.max(0, getSec());
288
+ while (true) {
289
+ tick = yield;
290
+ const period = getSec();
291
+ if (period <= 0) {
292
+ nextAt = tick.elapsed;
293
+ continue;
294
+ }
295
+ while (tick.elapsed >= nextAt) {
296
+ fn();
297
+ nextAt += period;
298
+ }
299
+ }
300
+ })());
301
+ }
@@ -0,0 +1,38 @@
1
+ export { argminNum, argminVec, centroidLens, clampToDisc, meanLens, midpointLens, } from "./aggregates.js";
2
+ export { type Animatable, attract, driven, every, loop, not, type Play, play, type SpringOpts, spring, Tween, toward, tween, untilChange, wave, when, } from "./anim.js";
3
+ export { transitiveDeps } from "./introspect.js";
4
+ export * from "./lenses/index.js";
5
+ export { each, type Lifecycle } from "./network-utils.js";
6
+ export { reflectionLens } from "./new-primitives.js";
7
+ export { batch, Cell, type CellOptions, cell, derive, effect, type Init, type Inner, isCell, isComputed, isLens, lazy, lens, type Network, network, type Read, reader, readNow, type StatefulBwd, type StatefulLensSpec, setCellWriteHook, untracked, type Val, type Writable, type WritableBrand, } from "./signal.js";
8
+ export { type Equals, type Lerp, type Linear, type Metric, type Pack, type Pivotal, requireEquals, requireLerp, requireLinear, requireMetric, requirePack, requirePivotal, type TraitDict, type Traits, } from "./traits.js";
9
+ export { allNodes, atPath, isLeaf, leavesOf, node as treeNode, nodeCount, type TreeNode, walkTree, } from "./tree.js";
10
+ export { Anchor, Dir } from "./values/anchor.js";
11
+ export { Audio, type AudioClip, audio, stamp as audioStamp } from "./values/audio.js";
12
+ export * as BoolMath from "./values/bool.js";
13
+ export { Bool, bool } from "./values/bool.js";
14
+ export * as BoxMath from "./values/box.js";
15
+ export { Box, box, edgeFrom, union as boxUnion } from "./values/box.js";
16
+ export { Canvas, canvas, type Raster, stamp as canvasStamp } from "./values/canvas.js";
17
+ export * as ColorMath from "./values/color.js";
18
+ export { Color, rgb, rgba } from "./values/color.js";
19
+ export { Flags, flags } from "./values/flags.js";
20
+ export { blit as gpuBlit, brush as gpuBrush, copy as gpuCopy, newTex as gpuNewTex, Spring, scratch2 as gpuScratch2, type Tex, } from "./values/gpu.js";
21
+ export * as MatrixMath from "./values/matrix.js";
22
+ export { compose, determinant, fromRotate, fromScale, fromTranslate, identity, invert, isIdentity, Matrix, matrix, multiply, toMatrixString, transformBox, transformPoint, } from "./values/matrix.js";
23
+ export * as NumMath from "./values/num.js";
24
+ export { Num, num } from "./values/num.js";
25
+ export * as PoseMath from "./values/pose.js";
26
+ export { Pose, pose } from "./values/pose.js";
27
+ export * as RangeMath from "./values/range.js";
28
+ export { Range, range, span } from "./values/range.js";
29
+ export * as StrMath from "./values/str.js";
30
+ export { Str, str } from "./values/str.js";
31
+ export { type Codec, enumCodec, numCodec, route, type Slot, slot, strCodec, template, tpl, } from "./values/template.js";
32
+ export * as TransformMath from "./values/transform.js";
33
+ export { Transform, type TransformInit, transform } from "./values/transform.js";
34
+ export * as TriMath from "./values/tri.js";
35
+ export { Tri, tri } from "./values/tri.js";
36
+ export * as VecMath from "./values/vec.js";
37
+ export { type PolarPolicy, polar, tangentPoint, Vec, vec } from "./values/vec.js";
38
+ export { derived, field } from "./writable.js";
@@ -0,0 +1,38 @@
1
+ export { argminNum, argminVec, centroidLens, clampToDisc, meanLens, midpointLens, } from "./aggregates.js";
2
+ export { attract, driven, every, loop, not, play, spring, Tween, toward, tween, untilChange, wave, when, } from "./anim.js";
3
+ export { transitiveDeps } from "./introspect.js";
4
+ export * from "./lenses/index.js";
5
+ export { each } from "./network-utils.js";
6
+ export { reflectionLens } from "./new-primitives.js";
7
+ export { batch, Cell, cell, derive, effect, isCell, isComputed, isLens, lazy, lens, network, reader, readNow, setCellWriteHook, untracked, } from "./signal.js";
8
+ export { requireEquals, requireLerp, requireLinear, requireMetric, requirePack, requirePivotal, } from "./traits.js";
9
+ export { allNodes, atPath, isLeaf, leavesOf, node as treeNode, nodeCount, walkTree, } from "./tree.js";
10
+ export { Anchor, Dir } from "./values/anchor.js";
11
+ export { Audio, audio, stamp as audioStamp } from "./values/audio.js";
12
+ export * as BoolMath from "./values/bool.js";
13
+ export { Bool, bool } from "./values/bool.js";
14
+ export * as BoxMath from "./values/box.js";
15
+ export { Box, box, edgeFrom, union as boxUnion } from "./values/box.js";
16
+ export { Canvas, canvas, stamp as canvasStamp } from "./values/canvas.js";
17
+ export * as ColorMath from "./values/color.js";
18
+ export { Color, rgb, rgba } from "./values/color.js";
19
+ export { Flags, flags } from "./values/flags.js";
20
+ export { blit as gpuBlit, brush as gpuBrush, copy as gpuCopy, newTex as gpuNewTex, Spring, scratch2 as gpuScratch2, } from "./values/gpu.js";
21
+ export * as MatrixMath from "./values/matrix.js";
22
+ export { compose, determinant, fromRotate, fromScale, fromTranslate, identity, invert, isIdentity, Matrix, matrix, multiply, toMatrixString, transformBox, transformPoint, } from "./values/matrix.js";
23
+ export * as NumMath from "./values/num.js";
24
+ export { Num, num } from "./values/num.js";
25
+ export * as PoseMath from "./values/pose.js";
26
+ export { Pose, pose } from "./values/pose.js";
27
+ export * as RangeMath from "./values/range.js";
28
+ export { Range, range, span } from "./values/range.js";
29
+ export * as StrMath from "./values/str.js";
30
+ export { Str, str } from "./values/str.js";
31
+ export { enumCodec, numCodec, route, slot, strCodec, template, tpl, } from "./values/template.js";
32
+ export * as TransformMath from "./values/transform.js";
33
+ export { Transform, transform } from "./values/transform.js";
34
+ export * as TriMath from "./values/tri.js";
35
+ export { Tri, tri } from "./values/tri.js";
36
+ export * as VecMath from "./values/vec.js";
37
+ export { polar, tangentPoint, Vec, vec } from "./values/vec.js";
38
+ export { derived, field } from "./writable.js";
@@ -0,0 +1,5 @@
1
+ import type { Cell } from "./signal.js";
2
+ /** Every cell `s` transitively depends on, including itself. Raw cells
3
+ * return `{s}`; lens chains return the chain plus all parents. BFS,
4
+ * peeking each Computed to populate deps; the `seen` set breaks cycles. */
5
+ export declare function transitiveDeps(s: Cell<unknown>): Set<Cell<unknown>>;
@@ -0,0 +1,31 @@
1
+ // introspect.ts — read-only inspection of a cell's dependency graph.
2
+ //
3
+ // Used by `Propagators` to expand declared reads into their transitive
4
+ // parent set, so a propagator reading a lens chain reacts to writes that
5
+ // touch the chain's parents but not the chain's identity. Inspection is
6
+ // safe: it only reads engine state and peeks `.value` to populate deps
7
+ // for lazy Computeds (idempotent).
8
+ /** Every cell `s` transitively depends on, including itself. Raw cells
9
+ * return `{s}`; lens chains return the chain plus all parents. BFS,
10
+ * peeking each Computed to populate deps; the `seen` set breaks cycles. */
11
+ export function transitiveDeps(s) {
12
+ const seen = new Set();
13
+ const queue = [s];
14
+ while (queue.length > 0) {
15
+ const cur = queue.shift();
16
+ if (seen.has(cur))
17
+ continue;
18
+ seen.add(cur);
19
+ // Cast to reach engine fields the typed Cell<T> shape doesn't surface.
20
+ const c = cur;
21
+ if (c.getter !== undefined) {
22
+ void cur.value;
23
+ let l = c.deps;
24
+ while (l !== undefined) {
25
+ queue.push(l.dep);
26
+ l = l.nextDep;
27
+ }
28
+ }
29
+ }
30
+ return seen;
31
+ }
@@ -0,0 +1,64 @@
1
+ import { type Cell, Num, type Read, type Traits, Vec, type Writable } from "../index.js";
2
+ type V = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ /** Writable centroid; on write, translates every point by the delta.
7
+ * Alias of `centroidLens` under the "policy" naming. */
8
+ export declare function rigidTranslate(points: readonly Writable<Vec>[]): Writable<Vec>;
9
+ /** Writable angle from `pivot` to `points[0]`; write rotates every input
10
+ * about `pivot` by (target − current) via its `Pivotal` trait.
11
+ *
12
+ * Trait-generic: Vec rotates position; Pose rotates position AND
13
+ * orientation. Rotation-about-pivot fixes the pivot and preserves radial
14
+ * distances, so scale-about-pivot reads unchanged. `pivot` is reactive
15
+ * (re-read per write); pass `centroidLens(points)` for rotation about
16
+ * the cluster's own centroid. */
17
+ export declare function rotateAbout<T extends {
18
+ x: number;
19
+ y: number;
20
+ }>(points: readonly Writable<Traits<T, "pivotal"> & Cell<T>>[], pivot: Read<V>): Writable<Num>;
21
+ /** Writable radial distance from pivot to `points[0]`; write scales every
22
+ * input radially about `pivot` (negative target reflects). Exact
23
+ * cross-channel invariance with `rotateAbout`.
24
+ *
25
+ * Complement carries per-point offsets from the pivot at the last
26
+ * non-degenerate state, so a collapse onto the pivot (radius ≈ 0)
27
+ * reinflates from the stored shape. Pose `theta` survives the round-trip
28
+ * (only spatial offset is stored). */
29
+ export declare function scaleAbout<T extends {
30
+ x: number;
31
+ y: number;
32
+ }>(points: readonly Writable<Traits<T, "pivotal"> & Cell<T>>[], pivot: Read<V>): Writable<Num>;
33
+ /** Per-axis scale about a pivot. Vec-specific (Pivotal has no per-axis
34
+ * method yet). Complement carries per-point per-axis fractions of
35
+ * point 0's offset, so a per-axis collapse is recoverable (cf.
36
+ * `bboxLens.size`). */
37
+ export declare function scaleAboutXY(points: readonly Writable<Vec>[], pivot: Read<V>): Writable<Vec>;
38
+ /** Same semantics as `factor-lens.ts`'s `procrustesLens`, decomposed
39
+ * into three building-block lenses sharing a centroid. */
40
+ export declare function procrustesViaBuildingBlocks(points: readonly Writable<Vec>[]): {
41
+ centroid: Writable<Vec>;
42
+ rotation: Writable<Num>;
43
+ scale: Writable<Num>;
44
+ };
45
+ export declare function bestFitLineLens(points: readonly Writable<Vec>[]): {
46
+ point: Writable<Vec>;
47
+ direction: Writable<Num>;
48
+ };
49
+ export declare function bestFitCircleLens(points: readonly Writable<Vec>[]): {
50
+ center: Writable<Vec>;
51
+ radius: Writable<Num>;
52
+ };
53
+ export declare function pcaLens(points: readonly Writable<Vec>[]): {
54
+ mean: Writable<Vec>;
55
+ rotation: Writable<Num>;
56
+ majorLength: Writable<Num>;
57
+ minorLength: Writable<Num>;
58
+ };
59
+ /** Writable total over K parts; write scales all parts proportionally,
60
+ * preserving their ratios. A `remember` anchored at zero with a signed
61
+ * sum feature: a collapse to zero reinflates the stored ratios, seeded
62
+ * uniform so an all-zero start splits evenly. */
63
+ export declare function totalLens(parts: readonly Writable<Num>[]): Writable<Num>;
64
+ export {};