bireactive 0.3.1 → 0.3.2

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 (89) hide show
  1. package/README.md +14 -7
  2. package/dist/core/_counts.js +5 -12
  3. package/dist/core/cell.d.ts +3 -3
  4. package/dist/core/cell.js +6 -7
  5. package/dist/core/derived-geometry.js +4 -7
  6. package/dist/core/index.d.ts +3 -1
  7. package/dist/core/index.js +3 -1
  8. package/dist/core/lenses/aggregates.d.ts +42 -52
  9. package/dist/core/lenses/aggregates.js +225 -116
  10. package/dist/core/lenses/geometry.d.ts +22 -4
  11. package/dist/core/lenses/geometry.js +59 -27
  12. package/dist/core/lenses/index.d.ts +5 -6
  13. package/dist/core/lenses/index.js +5 -6
  14. package/dist/core/lenses/memory.js +4 -17
  15. package/dist/core/lenses/numerical.d.ts +100 -0
  16. package/dist/core/lenses/{typed-factor.js → numerical.js} +136 -34
  17. package/dist/core/lenses/point-cloud.d.ts +67 -0
  18. package/dist/core/lenses/{closed-form-policies.js → point-cloud.js} +218 -81
  19. package/dist/core/lenses/snap.d.ts +1 -1
  20. package/dist/core/lenses/snap.js +3 -10
  21. package/dist/core/lenses/text.d.ts +40 -0
  22. package/dist/core/lenses/text.js +202 -0
  23. package/dist/core/lifecycle.js +3 -6
  24. package/dist/core/linalg.js +5 -11
  25. package/dist/core/optic.js +10 -15
  26. package/dist/core/optics.js +4 -8
  27. package/dist/core/store.d.ts +1 -2
  28. package/dist/core/store.js +7 -15
  29. package/dist/core/traits.d.ts +4 -7
  30. package/dist/core/traits.js +8 -12
  31. package/dist/core/values/anchor.js +0 -4
  32. package/dist/core/values/arr.d.ts +110 -0
  33. package/dist/core/values/arr.js +336 -0
  34. package/dist/core/values/audio.d.ts +8 -9
  35. package/dist/core/values/audio.js +7 -23
  36. package/dist/core/values/bool.d.ts +11 -11
  37. package/dist/core/values/bool.js +12 -22
  38. package/dist/core/values/box.d.ts +15 -20
  39. package/dist/core/values/box.js +20 -33
  40. package/dist/core/values/canvas.d.ts +18 -25
  41. package/dist/core/values/canvas.js +17 -48
  42. package/dist/core/values/color.d.ts +5 -7
  43. package/dist/core/values/color.js +5 -11
  44. package/dist/core/values/field.d.ts +6 -7
  45. package/dist/core/values/field.js +10 -35
  46. package/dist/core/values/flags.d.ts +1 -2
  47. package/dist/core/values/flags.js +1 -17
  48. package/dist/core/values/gpu.d.ts +6 -10
  49. package/dist/core/values/gpu.js +8 -22
  50. package/dist/core/values/matrix.d.ts +2 -4
  51. package/dist/core/values/matrix.js +2 -12
  52. package/dist/core/values/num.d.ts +19 -28
  53. package/dist/core/values/num.js +23 -41
  54. package/dist/core/values/pose.d.ts +2 -4
  55. package/dist/core/values/pose.js +3 -12
  56. package/dist/core/values/range.d.ts +18 -26
  57. package/dist/core/values/range.js +22 -39
  58. package/dist/core/values/reg/ambiguity.d.ts +8 -0
  59. package/dist/core/values/reg/ambiguity.js +131 -0
  60. package/dist/core/values/reg/engine.d.ts +91 -0
  61. package/dist/core/values/reg/engine.js +373 -0
  62. package/dist/core/values/reg/nfa.d.ts +42 -0
  63. package/dist/core/values/reg/nfa.js +391 -0
  64. package/dist/core/values/reg/regex.d.ts +7 -0
  65. package/dist/core/values/reg/regex.js +318 -0
  66. package/dist/core/values/reg/types.d.ts +60 -0
  67. package/dist/core/values/reg/types.js +3 -0
  68. package/dist/core/values/reg.d.ts +250 -0
  69. package/dist/core/values/reg.js +649 -0
  70. package/dist/core/values/str.d.ts +16 -60
  71. package/dist/core/values/str.js +133 -315
  72. package/dist/core/values/template.js +1 -24
  73. package/dist/core/values/transform.d.ts +3 -5
  74. package/dist/core/values/transform.js +3 -12
  75. package/dist/core/values/tri.d.ts +9 -10
  76. package/dist/core/values/tri.js +9 -15
  77. package/dist/core/values/vec.d.ts +9 -24
  78. package/dist/core/values/vec.js +9 -64
  79. package/dist/index.d.ts +0 -11
  80. package/dist/index.js +1 -11
  81. package/package.json +6 -7
  82. package/dist/coll.d.ts +0 -74
  83. package/dist/coll.js +0 -210
  84. package/dist/core/lenses/closed-form-policies.d.ts +0 -57
  85. package/dist/core/lenses/decompositions.d.ts +0 -14
  86. package/dist/core/lenses/decompositions.js +0 -224
  87. package/dist/core/lenses/domain-aggregates.d.ts +0 -42
  88. package/dist/core/lenses/domain-aggregates.js +0 -245
  89. package/dist/core/lenses/typed-factor.d.ts +0 -40
@@ -1,22 +1,7 @@
1
- // audio.ts — reactive audio clip (handle-as-value), the sound twin of canvas.ts.
2
- //
3
- // A Clip is context-free PCM: one Float32Array per channel plus a sample rate.
4
- // The graph transports only the tiny header {pcm, sampleRate, epoch} and compares
5
- // the monotonic epoch, so propagation never scans a sample and nothing is copied
6
- // across the bus (same handle-as-value rule as Canvas, minus the GL context — PCM
7
- // needs no ambient AudioContext, that only appears at the playback sink).
8
- //
9
- // Tiers mirror the rest of values/:
10
- // - pure isomorphisms (`reverse`) — one pass each way.
11
- // - reactive-param invertible (`gain(k)`) — reads `Val<number>`.
12
- // - complement projection (`normalize`) — the lossy view (peak-scaled) plus a
13
- // complement (the original peak) recovered on write-back, the audio analog of
14
- // str.lowercase()/canvas.grayscale().
15
- // - cross-type lens (`rms` → Num).
16
1
  import { Cell, reader } from "../cell.js";
17
2
  import { Num } from "./num.js";
18
3
  let EPOCH = 0;
19
- /** Stamp channel buffers with a fresh epoch — the only way to mint a value. */
4
+ /** Stamp buffers with a fresh epoch — the only way to mint a `Clip` value. */
20
5
  export const stamp = (pcm, sampleRate) => ({
21
6
  pcm,
22
7
  sampleRate,
@@ -55,7 +40,7 @@ export class Audio extends Cell {
55
40
  constructor(v = { pcm: [], sampleRate: 44100, epoch: 0 }) {
56
41
  super(v, { equals });
57
42
  }
58
- /** Time-reverse every channel. Involution. */
43
+ /** Time-reverse every channel. */
59
44
  reverse() {
60
45
  const run = (v) => stamp(v.pcm.map(ch => {
61
46
  const o = new Float32Array(ch.length);
@@ -65,14 +50,13 @@ export class Audio extends Cell {
65
50
  }), v.sampleRate);
66
51
  return this.lens(run, run);
67
52
  }
68
- /** Scalar gain. Invertible while k ≠ 0 — the audio twin of Canvas.brightness. */
53
+ /** Scalar gain. Invertible while k ≠ 0. */
69
54
  gain(k) {
70
55
  const kf = reader(k);
71
56
  return this.lens(v => scaled(v, kf()), n => scaled(n, 1 / kf()));
72
57
  }
73
- /** Peak-normalize to reactive `target` (default 1). The view alone can't
74
- * know the source's loudness, so the complement carries the original peak and
75
- * the backward pass restores it. The audio analog of str.lowercase(). */
58
+ /** Peak-normalize to `target` (default 1). The complement stores the original
59
+ * peak so a write-back restores it. */
76
60
  normalize(target = 1) {
77
61
  const tf = reader(target);
78
62
  const self = this;
@@ -97,8 +81,8 @@ export class Audio extends Cell {
97
81
  });
98
82
  }
99
83
  }
100
- /** Writable `Audio`. A `Clip` seeds a fresh cell; an existing `Writable<Audio>`
101
- * passes through by identity. */
84
+ /** Writable `Audio` from a `Clip` (new cell) or existing writable (passed
85
+ * through). */
102
86
  export function audio(v) {
103
87
  if (v instanceof Audio)
104
88
  return v;
@@ -13,25 +13,25 @@ export declare class Bool extends Cell<V> {
13
13
  };
14
14
  readonly _t: typeof Bool.traits;
15
15
  constructor(v?: V);
16
- /** Logical negation. Involution; chains compose. */
16
+ /** Logical negation. */
17
17
  not(): this;
18
- /** Symmetric difference / parity. Invertible:
19
- * `a ^ b = c ↔ a = c ^ b`. The F₂ analog of `Num#add`. */
18
+ /** True when exactly one side is true (XOR); its own inverse. */
20
19
  xor(b: Val<V>): this;
21
- /** `this && b`. RO: fan-in write-back isn't unique — use
22
- * `Bool.lens([a, b], ...)` with an explicit policy for a writable AND. */
20
+ /** True when both sides are true. Read-only — a write can't be split
21
+ * between the two inputs. */
23
22
  and(b: Val<V>): Bool;
23
+ /** True when either side is true. */
24
24
  or(b: Val<V>): Bool;
25
- /** `this b ¬this b`. */
25
+ /** True unless `this` is true and `b` is false (`this b`). */
26
26
  implies(b: Val<V>): Bool;
27
- /** Boolean equality XNOR. */
27
+ /** True when both sides match (XNOR). */
28
28
  eq(b: Val<V>): Bool;
29
+ /** True unless both sides are true (NAND). */
29
30
  nand(b: Val<V>): Bool;
31
+ /** True when both sides are false (NOR). */
30
32
  nor(b: Val<V>): Bool;
31
33
  }
32
- /** Writable `Bool`. Literal seeds a fresh cell; existing `Writable<Bool>`
33
- * passes through by identity. RO sources are rejected at the type level —
34
- * use `Bool.derive(...)` for reactive RO tracking, or `cell.value` to
35
- * snapshot. */
34
+ /** Writable `Bool` from a literal (new cell) or existing writable (passed
35
+ * through). For read-only sources use `Bool.derive`. */
36
36
  export declare function bool(v?: Init<Bool>): Writable<Bool>;
37
37
  export {};
@@ -1,20 +1,10 @@
1
- // bool.ts — reactive boolean.
2
- //
3
- // Invertibles ride the plain endo `.lens(fwd, bwd)`: `not()` (involution,
4
- // `.not().not()` round-trips to identity) and `xor(b)` (its own inverse;
5
- // `a ^ b = c ↔ a = c ^ b`). xor carries Bool's `linear` trait.
6
- //
7
- // `and` / `or` / `implies` / `eq` / `nand` / `nor` return bare RO `Bool`
8
- // — lossy fan-ins whose write-back is ambiguous. Lift to writable via
9
- // `Bool.lens([a, b], fwd, bwd)` with an explicit policy.
10
1
  import { Cell, reader } from "../cell.js";
11
2
  export const not = (a) => !a;
12
3
  export const and = (a, b) => a && b;
13
4
  export const or = (a, b) => a || b;
14
5
  export const xor = (a, b) => a !== b;
15
6
  export const equals = (a, b) => a === b;
16
- // F₂-linear structure: xor is both add and sub (a ^ a = false);
17
- // scale-by-integer collapses by parity (even k → false, odd k → a).
7
+ // F₂-linear: xor is both add and sub; scale collapses by parity.
18
8
  const linearImpl = {
19
9
  add: xor,
20
10
  sub: xor,
@@ -25,49 +15,49 @@ export class Bool extends Cell {
25
15
  constructor(v = false) {
26
16
  super(v, { equals });
27
17
  }
28
- /** Logical negation. Involution; chains compose. */
18
+ /** Logical negation. */
29
19
  not() {
30
20
  return this.lens(not, not);
31
21
  }
32
- /** Symmetric difference / parity. Invertible:
33
- * `a ^ b = c ↔ a = c ^ b`. The F₂ analog of `Num#add`. */
22
+ /** True when exactly one side is true (XOR); its own inverse. */
34
23
  xor(b) {
35
24
  const bf = reader(b);
36
25
  return this.lens(v => v !== bf(), n => n !== bf());
37
26
  }
38
- /** `this && b`. RO: fan-in write-back isn't unique — use
39
- * `Bool.lens([a, b], ...)` with an explicit policy for a writable AND. */
27
+ /** True when both sides are true. Read-only — a write can't be split
28
+ * between the two inputs. */
40
29
  and(b) {
41
30
  const bf = reader(b);
42
31
  return Bool.derive(() => this.value && bf());
43
32
  }
33
+ /** True when either side is true. */
44
34
  or(b) {
45
35
  const bf = reader(b);
46
36
  return Bool.derive(() => this.value || bf());
47
37
  }
48
- /** `this b ¬this b`. */
38
+ /** True unless `this` is true and `b` is false (`this b`). */
49
39
  implies(b) {
50
40
  const bf = reader(b);
51
41
  return Bool.derive(() => !this.value || bf());
52
42
  }
53
- /** Boolean equality XNOR. */
43
+ /** True when both sides match (XNOR). */
54
44
  eq(b) {
55
45
  const bf = reader(b);
56
46
  return Bool.derive(() => this.value === bf());
57
47
  }
48
+ /** True unless both sides are true (NAND). */
58
49
  nand(b) {
59
50
  const bf = reader(b);
60
51
  return Bool.derive(() => !(this.value && bf()));
61
52
  }
53
+ /** True when both sides are false (NOR). */
62
54
  nor(b) {
63
55
  const bf = reader(b);
64
56
  return Bool.derive(() => !(this.value || bf()));
65
57
  }
66
58
  }
67
- /** Writable `Bool`. Literal seeds a fresh cell; existing `Writable<Bool>`
68
- * passes through by identity. RO sources are rejected at the type level —
69
- * use `Bool.derive(...)` for reactive RO tracking, or `cell.value` to
70
- * snapshot. */
59
+ /** Writable `Bool` from a literal (new cell) or existing writable (passed
60
+ * through). For read-only sources use `Bool.derive`. */
71
61
  export function bool(v = false) {
72
62
  if (v instanceof Bool)
73
63
  return v;
@@ -15,20 +15,19 @@ export declare const sub: (a: V, b: V) => V;
15
15
  export declare const scale: (a: V, k: number) => V;
16
16
  export declare const lerp: (a: V, b: V, t: number) => V;
17
17
  export declare const equals: (a: V, b: V) => boolean;
18
- /** L2 distance over the flat (x, y, w, h) representation. */
18
+ /** Euclidean distance over (x, y, w, h). */
19
19
  export declare const metric: (a: V, b: V) => number;
20
20
  export declare const expand: (b: V, n: number) => V;
21
21
  export declare const contains: (b: V, p: Inner<Vec>) => boolean;
22
- /** Closest point inside `b` to `p`. Already-inside is identity; outside
23
- * snaps to the nearest boundary point. `Box#contains`'s true-side bwd. */
22
+ /** Closest point inside `b` to `p`; already-inside is identity, outside snaps
23
+ * to the nearest boundary point. */
24
24
  export declare const clampToBox: (p: Inner<Vec>, b: V) => Inner<Vec>;
25
- /** Closest point strictly outside `b` to `p`, displaced past the nearest
26
- * edge by `eps`. Already-outside is identity. `Box#contains`'s
27
- * false-side bwd. */
25
+ /** Closest point strictly outside `b` to `p`, displaced past the nearest edge
26
+ * by `eps`; already-outside is identity. */
28
27
  export declare const ejectFromBox: (p: Inner<Vec>, b: V, eps?: number) => Inner<Vec>;
29
28
  /** Bounding box around a set of boxes. */
30
29
  export declare function union(...bs: V[]): V;
31
- /** Perimeter point on a Box facing `toward`. Default `Shape.boundary`. */
30
+ /** Perimeter point on a box facing `toward`. */
32
31
  export declare function edgeFrom(b: V, toward: Inner<Vec>): Inner<Vec>;
33
32
  export declare class Box extends Cell<V> {
34
33
  static traits: {
@@ -45,32 +44,28 @@ export declare class Box extends Cell<V> {
45
44
  scale(k: Val<number>): this;
46
45
  expand(n: Val<number>): this;
47
46
  lerp(b: Val<V>, t: Val<number>): Box;
48
- /** Membership predicate. Conditional return type: a writable `Vec`
49
- * yields `Writable<Bool>` and flipping the view moves the source
50
- * `true` clamps to the nearest in-box point, `false` ejects past the
51
- * nearest edge by `eps`. Literal / RO inputs yield a bare RO `Bool`. */
47
+ /** True when `p` is inside the box. A writable `Vec` yields a `Writable<Bool>`:
48
+ * flipping it clamps `p` to the nearest in-box point (`true`) or ejects it
49
+ * past the nearest edge (`false`). Literal/RO inputs yield a read-only `Bool`. */
52
50
  contains<P extends Val<Inner<Vec>>>(p: P): P extends WritableBrand ? Writable<Bool> : Bool;
53
51
  get x(): this extends WritableBrand ? Writable<Num> : Num;
54
52
  get y(): this extends WritableBrand ? Writable<Num> : Num;
55
53
  get w(): this extends WritableBrand ? Writable<Num> : Num;
56
54
  get h(): this extends WritableBrand ? Writable<Num> : Num;
57
55
  get area(): Num;
58
- /** Vec at parametric (u, v) within `[0,1]²`. Not memoised (arbitrary
59
- * pairs would leak a cache entry each) use the named edge getters
60
- * (`.center`, `.top`, …) for stable identity. */
56
+ /** Vec at parametric `(u, v)` in `[0,1]²`. Not memoised; use the named edge
57
+ * getters (`.center`, `.top`, ) for stable identity. */
61
58
  at(u: number, v: number): Vec;
62
59
  get center(): Vec;
63
60
  get top(): Vec;
64
61
  get bottom(): Vec;
65
62
  get left(): Vec;
66
63
  get right(): Vec;
67
- /** Tween-builder, implied by the lerp trait. */
64
+ /** Tween-builder. */
68
65
  to(this: Writable<Box>, target: V, dur: Val<number>, ease?: Easing): Tween<V>;
69
66
  }
70
- /** Writable `Box` at `(x, y, w, h)`. Each component is a literal `number`
71
- * (lifted to a fresh seed) or an existing `Writable<Num>` (identity
72
- * passthrough). RO sources are rejected at the type level — use
73
- * `Box.derive(...)` for reactive RO tracking, or `cell.value` to
74
- * snapshot. Lock a component with `Num.pin(c)`. */
67
+ /** Writable `Box` at `(x, y, w, h)`. Each component is a literal (new cell) or
68
+ * existing writable (passed through); for read-only sources use `Box.derive`.
69
+ * Lock a component with `Num.pin`. */
75
70
  export declare function box(x?: Init<Num>, y?: Init<Num>, w?: Init<Num>, h?: Init<Num>): Writable<Box>;
76
71
  export {};
@@ -1,7 +1,3 @@
1
- // box.ts — reactive axis-aligned rectangle.
2
- //
3
- // Invertibles (`add`, `sub`, `scale`, `expand`) return `: this` and ride
4
- // on `Cell#lens(fwd, bwd)`. Chained calls compose into a lens chain.
5
1
  import { tween } from "../../animation/index.js";
6
2
  import { Cell, cachedDerive, fieldLens, isReadonly, lazy, reader, readNow, SKIP, } from "../cell.js";
7
3
  import { Bool } from "./bool.js";
@@ -17,7 +13,7 @@ export const lerp = (a, b, t) => ({
17
13
  h: a.h + (b.h - a.h) * t,
18
14
  });
19
15
  export const equals = (a, b) => a === b || (a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h);
20
- /** L2 distance over the flat (x, y, w, h) representation. */
16
+ /** Euclidean distance over (x, y, w, h). */
21
17
  export const metric = (a, b) => Math.hypot(a.x - b.x, a.y - b.y, a.w - b.w, a.h - b.h);
22
18
  export const expand = (b, n) => ({
23
19
  x: b.x - n,
@@ -26,15 +22,14 @@ export const expand = (b, n) => ({
26
22
  h: b.h + 2 * n,
27
23
  });
28
24
  export const contains = (b, p) => p.x >= b.x && p.x <= b.x + b.w && p.y >= b.y && p.y <= b.y + b.h;
29
- /** Closest point inside `b` to `p`. Already-inside is identity; outside
30
- * snaps to the nearest boundary point. `Box#contains`'s true-side bwd. */
25
+ /** Closest point inside `b` to `p`; already-inside is identity, outside snaps
26
+ * to the nearest boundary point. */
31
27
  export const clampToBox = (p, b) => ({
32
28
  x: Math.max(b.x, Math.min(b.x + b.w, p.x)),
33
29
  y: Math.max(b.y, Math.min(b.y + b.h, p.y)),
34
30
  });
35
- /** Closest point strictly outside `b` to `p`, displaced past the nearest
36
- * edge by `eps`. Already-outside is identity. `Box#contains`'s
37
- * false-side bwd. */
31
+ /** Closest point strictly outside `b` to `p`, displaced past the nearest edge
32
+ * by `eps`; already-outside is identity. */
38
33
  export const ejectFromBox = (p, b, eps = 1e-6) => {
39
34
  if (!contains(b, p))
40
35
  return p;
@@ -70,7 +65,7 @@ export function union(...bs) {
70
65
  }
71
66
  return { x: xMin, y: yMin, w: xMax - xMin, h: yMax - yMin };
72
67
  }
73
- /** Perimeter point on a Box facing `toward`. Default `Shape.boundary`. */
68
+ /** Perimeter point on a box facing `toward`. */
74
69
  export function edgeFrom(b, toward) {
75
70
  const cx = b.x + b.w / 2;
76
71
  const cy = b.y + b.h / 2;
@@ -122,18 +117,16 @@ export class Box extends Cell {
122
117
  lerp(b, t) {
123
118
  return Box.derive(() => lerp(this.value, readNow(b), readNow(t)));
124
119
  }
125
- /** Membership predicate. Conditional return type: a writable `Vec`
126
- * yields `Writable<Bool>` and flipping the view moves the source
127
- * `true` clamps to the nearest in-box point, `false` ejects past the
128
- * nearest edge by `eps`. Literal / RO inputs yield a bare RO `Bool`. */
120
+ /** True when `p` is inside the box. A writable `Vec` yields a `Writable<Bool>`:
121
+ * flipping it clamps `p` to the nearest in-box point (`true`) or ejects it
122
+ * past the nearest edge (`false`). Literal/RO inputs yield a read-only `Bool`. */
129
123
  contains(p) {
130
124
  if (p instanceof Vec) {
131
- // A read-only Vec has no backward path RO branch; sources and
132
- // writable lenses accept write-back.
125
+ // RO Vec has no backward path; only writable Vecs accept write-back.
133
126
  if (!isReadonly(p)) {
134
- // `.bind(Bool)` + cast steps past the generic overloads, whose
135
- // mapped-tuple inference over the full class types otherwise blows
136
- // the instantiation depth.
127
+ // `.bind(Bool)` + cast sidesteps the generic overloads, whose
128
+ // mapped-tuple inference over the full class types blows the
129
+ // instantiation depth.
137
130
  const mk = Bool.lens.bind(Bool);
138
131
  return mk([this, p], vals => contains(vals[0], vals[1]), (target, vals) => {
139
132
  const [b, v] = vals;
@@ -160,15 +153,12 @@ export class Box extends Cell {
160
153
  get area() {
161
154
  return cachedDerive(this, "area", Num, b => b.w * b.h);
162
155
  }
163
- /** Vec at parametric (u, v) within `[0,1]²`. Not memoised (arbitrary
164
- * pairs would leak a cache entry each) use the named edge getters
165
- * (`.center`, `.top`, …) for stable identity. */
156
+ /** Vec at parametric `(u, v)` in `[0,1]²`. Not memoised; use the named edge
157
+ * getters (`.center`, `.top`, ) for stable identity. */
166
158
  at(u, v) {
167
159
  return Vec.derive(this, b => ({ x: b.x + u * b.w, y: b.y + v * b.h }));
168
160
  }
169
- // Named edges RO views over `at(u, v)`, memoised under stable keys
170
- // so subscribers always see the same Vec. `lazy()` directly since
171
- // `at()` already returns a Vec.
161
+ // Named edges: memoised views over `at(u, v)` with stable identity.
172
162
  get center() {
173
163
  return lazy(this, "center", () => this.at(0.5, 0.5));
174
164
  }
@@ -184,16 +174,14 @@ export class Box extends Cell {
184
174
  get right() {
185
175
  return lazy(this, "right", () => this.at(1, 0.5));
186
176
  }
187
- /** Tween-builder, implied by the lerp trait. */
177
+ /** Tween-builder. */
188
178
  to(target, dur, ease) {
189
179
  return tween(this, target, dur, ease);
190
180
  }
191
181
  }
192
- /** Writable `Box` at `(x, y, w, h)`. Each component is a literal `number`
193
- * (lifted to a fresh seed) or an existing `Writable<Num>` (identity
194
- * passthrough). RO sources are rejected at the type level — use
195
- * `Box.derive(...)` for reactive RO tracking, or `cell.value` to
196
- * snapshot. Lock a component with `Num.pin(c)`. */
182
+ /** Writable `Box` at `(x, y, w, h)`. Each component is a literal (new cell) or
183
+ * existing writable (passed through); for read-only sources use `Box.derive`.
184
+ * Lock a component with `Num.pin`. */
197
185
  export function box(x = 0, y = 0, w = 0, h = 0) {
198
186
  if (typeof x === "number" &&
199
187
  typeof y === "number" &&
@@ -205,6 +193,5 @@ export function box(x = 0, y = 0, w = 0, h = 0) {
205
193
  const yN = num(y);
206
194
  const wN = num(w);
207
195
  const hN = num(h);
208
- // The view fully reconstructs all 4 axes (1-arg bwd ⇒ no source read).
209
196
  return Box.lens([xN, yN, wN, hN], ([bx, by, bw, bh]) => ({ x: bx, y: by, w: bw, h: bh }), v => [v.x, v.y, v.w, v.h]);
210
197
  }
@@ -3,8 +3,8 @@ import { Bool } from "./bool.js";
3
3
  import { Color } from "./color.js";
4
4
  import { Spring, type SpringOpts } from "./gpu.js";
5
5
  import { Vec } from "./vec.js";
6
- /** Raster header. The graph compares `epoch`; `tex` is an RGBA32F texture in
7
- * the shared GL context (channels 0–1, may overshoot mid-deconvolution). */
6
+ /** Raster header; the graph compares `epoch`. `tex` is an RGBA32F texture in
7
+ * the shared GL context. */
8
8
  export interface Raster {
9
9
  readonly tex: WebGLTexture;
10
10
  readonly w: number;
@@ -21,20 +21,18 @@ export declare class Canvas extends Cell<V> {
21
21
  };
22
22
  readonly _t: typeof Canvas.traits;
23
23
  constructor(v?: V);
24
- /** Per-channel invert (alpha preserved). Involution. */
24
+ /** Per-channel invert (alpha preserved). */
25
25
  invert(): this;
26
- /** Horizontal flip. Involution. */
26
+ /** Horizontal flip. */
27
27
  flipH(): this;
28
28
  /** Multiply RGB by reactive `k` (alpha preserved). Invertible while
29
29
  * k ≠ 0. */
30
30
  brightness(k: Val<number>): this;
31
- /** Grayscale (Rec.601 luma) view; complement is the per-pixel chroma
32
- * residual `(r−Y, g−Y, b−Y)`, so editing the gray view recolours the
33
- * source. The raster analog of `str.lowercase()`. */
31
+ /** Grayscale (Rec.601 luma) view; the complement is the per-pixel chroma
32
+ * residual `(r−Y, g−Y, b−Y)`, so editing the gray view recolours the source. */
34
33
  grayscale(): Writable<Canvas>;
35
- /** Chroma view (the dual of `grayscale`): `(r−Y, g−Y, b−Y)` on a mid-grey
36
- * base, complement is the luma `Y`. Editing the colour re-lights nothing —
37
- * it rewrites hue while keeping the original brightness. */
34
+ /** Chroma view: `(r−Y, g−Y, b−Y)` on a mid-grey base, complement is the luma
35
+ * `Y`. Editing it rewrites hue while keeping the original brightness. */
38
36
  chroma(): Writable<Canvas>;
39
37
  /** Sub-rectangle view (reactive `x,y,w,h`). Editing the crop composites
40
38
  * back into the source; the surround reads straight from the parent. */
@@ -43,26 +41,21 @@ export declare class Canvas extends Cell<V> {
43
41
  * Laplacian residual `source − up(down(source))`; editing the thumbnail
44
42
  * reconstructs full-res detail on top of the edit. */
45
43
  downsample(factor: number): Writable<Canvas>;
46
- /** Gaussian blur (reactive `radius`). Writable: the backward direction
47
- * runs an iterated Richardson–Lucy deconvolution seeded from the source.
48
- * Each step is `x ← x · H(target / H(x))`, non-negative and multiplicative,
49
- * so untouched regions stay fixed (their ratio is 1) while a stroke
50
- * back-solves to a sharp pre-image with far less ringing than an additive
51
- * solve. PutGet, not exact GetPut — the residual is the honest signature
52
- * of an ill-posed inverse. */
44
+ /** Gaussian blur (reactive `radius`). The backward pass runs an iterated
45
+ * Richardson–Lucy deconvolution seeded from the source
46
+ * (`x ← x · H(target / H(x))`), so untouched regions stay fixed. PutGet,
47
+ * not exact GetPut. */
53
48
  blur(radius: Val<number>): this;
54
- /** Mean colour (0–1) as a writable `Color`; the GPU reduces, the write
55
- * shifts every pixel by the delta (a rigid translate in RGB). */
49
+ /** Mean colour (0–1) as a writable `Color`; the GPU reduces, a write shifts
50
+ * every pixel by the delta. */
56
51
  meanColor(): Writable<Color>;
57
- /** Mean luma ≥ reactive `threshold` (0–1) as a writable `Bool`; flipping
58
- * the bit auto-exposes iterate the gain (clipping caps a single step)
59
- * until the mean crosses the line. */
52
+ /** Mean luma ≥ `threshold` (0–1) as a writable `Bool`; flipping the bit
53
+ * auto-exposes by iterating the gain until the mean crosses the threshold. */
60
54
  brighterThan(threshold: Val<number>): Writable<Bool>;
61
55
  /** Dimensions `(w, h)` as a read-only `Vec`. */
62
56
  get dimensions(): Vec;
63
- /** A GPU per-pixel spring driver seeded from this value's texture. The
64
- * host steps it and writes `current()` back into a root cell each frame;
65
- * settle is the GPU energy reduction. */
57
+ /** GPU per-pixel spring driver seeded from this value's texture. The host
58
+ * steps it and writes `current()` back each frame. */
66
59
  spring(opts?: SpringOpts): Spring;
67
60
  }
68
61
  /** Writable `Canvas` of size `w×h`. `painter` fills it pixel-by-pixel
@@ -1,25 +1,3 @@
1
- // canvas.ts — GPU-resident reactive raster (handle-as-value).
2
- //
3
- // Every Canvas value is a float texture in the shared WebGL2 context (see
4
- // gpu.ts); the reactive graph transports only a tiny HEADER {tex, w, h,
5
- // epoch}, comparing the monotonic epoch, so propagation never reads a pixel
6
- // and nothing is copied across the bus. Forward lenses render into a per-lens
7
- // scratch texture (reused across recomputes); the single ownership rule that
8
- // keeps no-copy safe is the same as on the CPU — a node writes only its own
9
- // texture, never one another live node still reads, which holds under the
10
- // engine's glitch-free flush.
11
- //
12
- // Tiers mirror the rest of values/:
13
- // - pure isomorphisms (`invert`, `flipH`) — one pointwise shader each way.
14
- // - reactive-param invertibles (`brightness(k)`) — read `Val<number>`.
15
- // - complement projections (`grayscale`, `downsample`) — the lossy view
16
- // plus a complement texture (chroma / Laplacian residual) recovered on
17
- // write-back, the raster analog of str.ts's case-preserving lenses.
18
- // - cross-type lenses (`meanColor` → Color, `brighterThan` → Bool).
19
- //
20
- // A backward pass that produces a ROOT cell's next value reads that root and
21
- // writes a result that becomes its value, so it uses `scratch2` (a feedback-
22
- // safe pair) to avoid reading and writing the same texture.
23
1
  import { Cell, cachedDerive, reader } from "../cell.js";
24
2
  import { Bool } from "./bool.js";
25
3
  import { Color } from "./color.js";
@@ -98,9 +76,7 @@ void main() {
98
76
  o = vec4(acc / wsum, a);
99
77
  }`;
100
78
  // Richardson–Lucy step. RL_RATIO forms target / blur(estimate) (guarded);
101
- // RL_MUL multiplies the estimate by blur(ratio) and clamps to [0,1]. Both
102
- // the non-negativity clamp and the multiplicative form keep ringing far
103
- // below an additive Van-Cittert iteration.
79
+ // RL_MUL multiplies the estimate by blur(ratio) and clamps to [0,1].
104
80
  const RL_RATIO = `${HEAD}
105
81
  uniform sampler2D u_t; uniform sampler2D u_est;
106
82
  void main() {
@@ -162,7 +138,7 @@ export class Canvas extends Cell {
162
138
  constructor(v = { tex: null, w: 0, h: 0, epoch: 0 }) {
163
139
  super(v, { equals });
164
140
  }
165
- /** Per-channel invert (alpha preserved). Involution. */
141
+ /** Per-channel invert (alpha preserved). */
166
142
  invert() {
167
143
  const sf = scratch();
168
144
  const sb = scratch();
@@ -173,7 +149,7 @@ export class Canvas extends Cell {
173
149
  };
174
150
  return this.lens(run(sf), run(sb));
175
151
  }
176
- /** Horizontal flip. Involution. */
152
+ /** Horizontal flip. */
177
153
  flipH() {
178
154
  const sf = scratch();
179
155
  const sb = scratch();
@@ -200,9 +176,8 @@ export class Canvas extends Cell {
200
176
  };
201
177
  return this.lens(run(sf, () => kf()), run(sb, () => 1 / kf()));
202
178
  }
203
- /** Grayscale (Rec.601 luma) view; complement is the per-pixel chroma
204
- * residual `(r−Y, g−Y, b−Y)`, so editing the gray view recolours the
205
- * source. The raster analog of `str.lowercase()`. */
179
+ /** Grayscale (Rec.601 luma) view; the complement is the per-pixel chroma
180
+ * residual `(r−Y, g−Y, b−Y)`, so editing the gray view recolours the source. */
206
181
  grayscale() {
207
182
  const sc = scratch();
208
183
  const sf = scratch();
@@ -230,9 +205,8 @@ export class Canvas extends Cell {
230
205
  },
231
206
  });
232
207
  }
233
- /** Chroma view (the dual of `grayscale`): `(r−Y, g−Y, b−Y)` on a mid-grey
234
- * base, complement is the luma `Y`. Editing the colour re-lights nothing —
235
- * it rewrites hue while keeping the original brightness. */
208
+ /** Chroma view: `(r−Y, g−Y, b−Y)` on a mid-grey base, complement is the luma
209
+ * `Y`. Editing it rewrites hue while keeping the original brightness. */
236
210
  chroma() {
237
211
  const sc = scratch();
238
212
  const sf = scratch();
@@ -352,13 +326,10 @@ export class Canvas extends Cell {
352
326
  },
353
327
  });
354
328
  }
355
- /** Gaussian blur (reactive `radius`). Writable: the backward direction
356
- * runs an iterated Richardson–Lucy deconvolution seeded from the source.
357
- * Each step is `x ← x · H(target / H(x))`, non-negative and multiplicative,
358
- * so untouched regions stay fixed (their ratio is 1) while a stroke
359
- * back-solves to a sharp pre-image with far less ringing than an additive
360
- * solve. PutGet, not exact GetPut — the residual is the honest signature
361
- * of an ill-posed inverse. */
329
+ /** Gaussian blur (reactive `radius`). The backward pass runs an iterated
330
+ * Richardson–Lucy deconvolution seeded from the source
331
+ * (`x ← x · H(target / H(x))`), so untouched regions stay fixed. PutGet,
332
+ * not exact GetPut. */
362
333
  blur(radius) {
363
334
  const rf = reader(radius);
364
335
  const fTmp = scratch();
@@ -402,8 +373,8 @@ export class Canvas extends Cell {
402
373
  return stamp(cur.tex, v.w, v.h);
403
374
  });
404
375
  }
405
- /** Mean colour (0–1) as a writable `Color`; the GPU reduces, the write
406
- * shifts every pixel by the delta (a rigid translate in RGB). */
376
+ /** Mean colour (0–1) as a writable `Color`; the GPU reduces, a write shifts
377
+ * every pixel by the delta. */
407
378
  meanColor() {
408
379
  const self = this;
409
380
  const sb = scratch2();
@@ -420,9 +391,8 @@ export class Canvas extends Cell {
420
391
  return stamp(out.tex, v.w, v.h);
421
392
  });
422
393
  }
423
- /** Mean luma ≥ reactive `threshold` (0–1) as a writable `Bool`; flipping
424
- * the bit auto-exposes iterate the gain (clipping caps a single step)
425
- * until the mean crosses the line. */
394
+ /** Mean luma ≥ `threshold` (0–1) as a writable `Bool`; flipping the bit
395
+ * auto-exposes by iterating the gain until the mean crosses the threshold. */
426
396
  brighterThan(threshold) {
427
397
  const tf = reader(threshold);
428
398
  const self = this;
@@ -462,9 +432,8 @@ export class Canvas extends Cell {
462
432
  get dimensions() {
463
433
  return cachedDerive(this, "dimensions", Vec, v => ({ x: v.w, y: v.h }));
464
434
  }
465
- /** A GPU per-pixel spring driver seeded from this value's texture. The
466
- * host steps it and writes `current()` back into a root cell each frame;
467
- * settle is the GPU energy reduction. */
435
+ /** GPU per-pixel spring driver seeded from this value's texture. The host
436
+ * steps it and writes `current()` back each frame. */
468
437
  spring(opts) {
469
438
  const s = new Spring(this.value.w, this.value.h, opts);
470
439
  s.seed(this.value.tex);
@@ -13,7 +13,7 @@ export declare const sub: (a: V, b: V) => V;
13
13
  export declare const scale: (a: V, k: number) => V;
14
14
  export declare const lerp: (a: V, b: V, t: number) => V;
15
15
  export declare const equals: (a: V, b: V) => boolean;
16
- /** L2 distance in RGBA-space. */
16
+ /** Euclidean distance in RGBA-space. */
17
17
  export declare const metric: (a: V, b: V) => number;
18
18
  export declare class Color extends Cell<V> {
19
19
  static traits: {
@@ -35,14 +35,12 @@ export declare class Color extends Cell<V> {
35
35
  get a(): this extends import("../index.js").WritableBrand ? Writable<Num> : Num;
36
36
  get luminance(): Num;
37
37
  get css(): Cell<string>;
38
- /** Tween-builder, implied by the lerp trait. */
38
+ /** Tween-builder. */
39
39
  to(this: Writable<Color>, target: V, dur: Val<number>, ease?: Easing): Tween<V>;
40
40
  }
41
- /** Writable `Color` from RGB channels (alpha = 1). Each channel is a
42
- * literal `number` (lifted to a fresh seed) or an existing `Writable<Num>`
43
- * (identity passthrough). All-literal inputs take a fast path; mixed
44
- * inputs build a lens so channel-writes round-trip to source. */
41
+ /** Writable `Color` from RGB channels (alpha = 1). Each channel is a literal
42
+ * or a `Writable<Num>`. */
45
43
  export declare function rgb(r: Init<Num>, g: Init<Num>, b: Init<Num>): Writable<Color>;
46
- /** Writable `Color` from RGBA channels. Same lift rule as `rgb`. */
44
+ /** Writable `Color` from RGBA channels. */
47
45
  export declare function rgba(r: Init<Num>, g: Init<Num>, b: Init<Num>, a: Init<Num>): Writable<Color>;
48
46
  export {};