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,254 @@
|
|
|
1
|
+
interface ReactiveNode {
|
|
2
|
+
flags: number;
|
|
3
|
+
deps: Link | undefined;
|
|
4
|
+
depsTail: Link | undefined;
|
|
5
|
+
subs: Link | undefined;
|
|
6
|
+
subsTail: Link | undefined;
|
|
7
|
+
_update(): boolean;
|
|
8
|
+
_notify(): void;
|
|
9
|
+
_unwatched(): void;
|
|
10
|
+
}
|
|
11
|
+
interface Link {
|
|
12
|
+
version: number;
|
|
13
|
+
dep: ReactiveNode;
|
|
14
|
+
sub: ReactiveNode;
|
|
15
|
+
prevSub: Link | undefined;
|
|
16
|
+
nextSub: Link | undefined;
|
|
17
|
+
prevDep: Link | undefined;
|
|
18
|
+
nextDep: Link | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** Install a hook fired on every source value-change; returns a restore fn. */
|
|
21
|
+
export declare function setCellWriteHook(fn: ((sig: Cell<unknown>) => void) | undefined): () => void;
|
|
22
|
+
export interface MergePolicy<T> {
|
|
23
|
+
readonly identity: T;
|
|
24
|
+
combine(acc: T, x: T): T;
|
|
25
|
+
/** Optional inverse for incremental fold. */
|
|
26
|
+
remove?(acc: T, x: T): T;
|
|
27
|
+
}
|
|
28
|
+
export declare const DIRECT_SLOT: unique symbol;
|
|
29
|
+
declare class MergeNode<T> {
|
|
30
|
+
readonly parent: Cell<T>;
|
|
31
|
+
readonly policy: MergePolicy<T>;
|
|
32
|
+
readonly slots: Map<unknown, T>;
|
|
33
|
+
readonly hasIncrementalAcc: boolean;
|
|
34
|
+
acc: T;
|
|
35
|
+
constructor(parent: Cell<T>, policy: MergePolicy<T>);
|
|
36
|
+
receive(slot: unknown, next: T): void;
|
|
37
|
+
fold(): T;
|
|
38
|
+
reset(): void;
|
|
39
|
+
}
|
|
40
|
+
declare class BwdSpec {
|
|
41
|
+
/** Backward target(s): one `Cell` (1→1 / merge) or `Cell[]` (multi-out). */
|
|
42
|
+
parent: Cell<unknown> | Cell<unknown>[] | undefined;
|
|
43
|
+
/** Lens `put` — backward derivation (dual of `getter`). Always called by
|
|
44
|
+
* the engine in 1-arg form `put(target)`; a source-reading lens bakes
|
|
45
|
+
* `settled(parent)` into this closure at build time. Multi-output:
|
|
46
|
+
* returns a per-parent update array. Stateful: the spec's `bwd`. */
|
|
47
|
+
put: ((target: any, current?: any) => any) | undefined;
|
|
48
|
+
/** Backward aggregation node; presence IS the merge-mode discriminant. */
|
|
49
|
+
merge: MergeNode<unknown> | undefined;
|
|
50
|
+
/** Complement machinery; presence IS the stateful-mode discriminant. */
|
|
51
|
+
stateful: StatefulCore | undefined;
|
|
52
|
+
/** Index in `bwdQueue` of this cell's latest push; the drain skips stale
|
|
53
|
+
* entries so each cell propagates backward once per flush, last-write. */
|
|
54
|
+
queueIdx: number;
|
|
55
|
+
}
|
|
56
|
+
/** Runtime state of a stateful (complement-carrying) lens — the rare
|
|
57
|
+
* backward mode, kept off `BwdSpec` so plain lenses don't carry its slots.
|
|
58
|
+
* `put` (the spec's `bwd`) and `parent` stay on `BwdSpec`; this holds the
|
|
59
|
+
* complement and the closures that project from / advance it. */
|
|
60
|
+
declare class StatefulCore {
|
|
61
|
+
/** Engine-owned memory the view discards. */
|
|
62
|
+
complement: unknown;
|
|
63
|
+
/** Forward projection `fwd(sources, complement) → view`. */
|
|
64
|
+
fwd: (sources: any, complement: any) => any;
|
|
65
|
+
/** Advance the complement: `step(sources, complement, external)`. */
|
|
66
|
+
step: (sources: any, complement: any, external: boolean) => any;
|
|
67
|
+
/** Source values last written back (own-vs-external test); `undefined`
|
|
68
|
+
* until the first back-write. */
|
|
69
|
+
lastBwd: unknown[] | undefined;
|
|
70
|
+
constructor(complement: unknown, fwd: (sources: any, complement: any) => any, step: (sources: any, complement: any, external: boolean) => any);
|
|
71
|
+
}
|
|
72
|
+
/** Plain T or any read-shape; snapshot via `readNow`, close via `reader`. */
|
|
73
|
+
export type Val<T> = T | Read<T>;
|
|
74
|
+
/** Covariant read-only surface. */
|
|
75
|
+
export interface Read<out T> {
|
|
76
|
+
readonly value: T;
|
|
77
|
+
peek(): T;
|
|
78
|
+
}
|
|
79
|
+
/** Brand discriminating writable receivers in conditional return types. */
|
|
80
|
+
declare const WRITABLE: unique symbol;
|
|
81
|
+
export interface WritableBrand {
|
|
82
|
+
readonly [WRITABLE]: never;
|
|
83
|
+
}
|
|
84
|
+
/** Value type carried by a reactive read shape. */
|
|
85
|
+
export type Inner<R> = R extends Cell<infer T> ? T : R extends Read<infer T> ? T : never;
|
|
86
|
+
/** The writable form of R: adds the brand + a settable `value`. */
|
|
87
|
+
export type Writable<R> = R & WritableBrand & {
|
|
88
|
+
value: Inner<R>;
|
|
89
|
+
};
|
|
90
|
+
/** Strict factory input: a literal, or an existing `Writable<Cls>`. */
|
|
91
|
+
export type Init<C extends Cell<any>> = Inner<C> | Writable<C>;
|
|
92
|
+
/** Snapshot a `Val<T>` to plain `T` (one-shot, no tracking). */
|
|
93
|
+
export declare function readNow<T>(v: Val<T>): T;
|
|
94
|
+
/** Resolve a `Val<T>` to a `() => T` closure that unwraps on each call. */
|
|
95
|
+
export declare function reader<T>(v: Val<T>): () => T;
|
|
96
|
+
/** Lazy getter: computes once, installs a non-enumerable own prop under
|
|
97
|
+
* `key` that shadows this getter on later reads. */
|
|
98
|
+
export declare function lazy<R>(self: object, key: string | symbol, make: () => R): R;
|
|
99
|
+
export declare const isCell: (v: unknown) => v is Cell<unknown>;
|
|
100
|
+
/** Lens mode: a derived cell that can be written back (has a backward sidecar). */
|
|
101
|
+
export declare const isLens: (v: unknown) => v is Cell<unknown>;
|
|
102
|
+
/** Computed mode: derived + read-only (no backward path). */
|
|
103
|
+
export declare const isComputed: (v: unknown) => v is Cell<unknown>;
|
|
104
|
+
export interface CellOptions<T = unknown> {
|
|
105
|
+
/** First subscriber attached; fired from `link`. */
|
|
106
|
+
watched?: () => void;
|
|
107
|
+
/** Last subscriber detached; fired from `_unwatched`. */
|
|
108
|
+
unwatched?: () => void;
|
|
109
|
+
/** Per-instance value equality; defaults to `Object.is`. */
|
|
110
|
+
equals?: (a: T, b: T) => boolean;
|
|
111
|
+
}
|
|
112
|
+
export declare class Cell<T = unknown> implements ReactiveNode {
|
|
113
|
+
flags: number;
|
|
114
|
+
subs: Link | undefined;
|
|
115
|
+
subsTail: Link | undefined;
|
|
116
|
+
deps: Link | undefined;
|
|
117
|
+
depsTail: Link | undefined;
|
|
118
|
+
/** Forward derivation (computed/lens/merge). `undefined` ⇒ source. */
|
|
119
|
+
getter: (() => T) | undefined;
|
|
120
|
+
/** Per-instance equality, always defined (defaults to `Object.is` at
|
|
121
|
+
* construction) so hot paths call it without an `undefined` branch. */
|
|
122
|
+
_equals: (a: T, b: T) => boolean;
|
|
123
|
+
/** First-subscriber / last-subscriber lifecycle hooks. */
|
|
124
|
+
_watched: (() => void) | undefined;
|
|
125
|
+
_unwatchedHook: (() => void) | undefined;
|
|
126
|
+
/** Source: `currentValue` = committed, `pendingValue` = staged write.
|
|
127
|
+
* Getter cell: `currentValue` = last derived cache, `pendingValue`
|
|
128
|
+
* reused as the deferred backward target (see `set value`). The two
|
|
129
|
+
* roles never coexist, so two fields suffice for four. */
|
|
130
|
+
currentValue: T;
|
|
131
|
+
pendingValue: T;
|
|
132
|
+
/** Backward sidecar: target(s) + lens closures + queue slot, or
|
|
133
|
+
* `undefined` for a read-only cell (source or computed). Allocated only
|
|
134
|
+
* for writable derived cells, keeping the common node lean. Writability
|
|
135
|
+
* is exactly `_bwd !== undefined`. See `BwdSpec`. */
|
|
136
|
+
_bwd: BwdSpec | undefined;
|
|
137
|
+
constructor(initial: T, opts?: CellOptions<T>);
|
|
138
|
+
readonly value: T;
|
|
139
|
+
_enqueueBwd(): void;
|
|
140
|
+
/** Source write (alien's signal setter). Self-excludes the active
|
|
141
|
+
* network so a body writing its own dep doesn't re-trigger itself. */
|
|
142
|
+
_writeSource(next: T): void;
|
|
143
|
+
_update(): boolean;
|
|
144
|
+
_notify(): void;
|
|
145
|
+
_unwatched(): void;
|
|
146
|
+
peek(): T;
|
|
147
|
+
/** Guard: silent coercion to string/number is almost always a bug. */
|
|
148
|
+
[Symbol.toPrimitive](hint: string): never;
|
|
149
|
+
/** Endomorphic lens. A 2-arg `bwd(view, current)` consults the current
|
|
150
|
+
* source; a 1-arg `bwd(view)` reconstructs it from the view alone. */
|
|
151
|
+
lens(this: Cell<T>, fwd: (v: T) => T, bwd: (target: T, current: T) => T): this;
|
|
152
|
+
/** Backward-aggregating node — bwd dual of computed. Forward, the
|
|
153
|
+
* identity view of its parent; backward, folds contributions from
|
|
154
|
+
* upstream lenses (slot-keyed) and direct writes (DIRECT_SLOT). */
|
|
155
|
+
merge(this: Cell<T>, policy: MergePolicy<T>): Cell<T>;
|
|
156
|
+
/** Read-only typed view. `Cls.derive(parent, fn)` (1-input),
|
|
157
|
+
* `Cls.derive(parents, fn)` (N-input), or `Cls.derive(fn)` (closure).
|
|
158
|
+
* Polymorphic-`this`: `Vec.derive(...)` → `Vec`. */
|
|
159
|
+
static derive<C extends new (...args: never[]) => Cell<any>, P>(this: C, parent: Read<P>, fn: (v: P) => Inner<InstanceType<C>>): InstanceType<C>;
|
|
160
|
+
static derive<C extends new (...args: never[]) => Cell<any>, P extends readonly Read<unknown>[]>(this: C, parents: P, fn: (vals: {
|
|
161
|
+
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
162
|
+
}) => Inner<InstanceType<C>>): InstanceType<C>;
|
|
163
|
+
static derive<C extends new (...args: never[]) => Cell<any>>(this: C, fn: () => Inner<InstanceType<C>>): InstanceType<C>;
|
|
164
|
+
/** Writable lens. `Cls.lens(parent, fwd, bwd)` for one input,
|
|
165
|
+
* `Cls.lens(parents, fwd, bwd)` for N; a 2-arg `bwd` reads the source,
|
|
166
|
+
* a 1-arg `bwd` reconstructs it. `Cls.lens(parent(s), spec)` builds a
|
|
167
|
+
* complement-carrying lens from `{ init, step, fwd, bwd }`. */
|
|
168
|
+
static lens<C extends new (...args: never[]) => Cell<any>, P>(this: C, parent: Read<P>, fwd: (v: P) => Inner<InstanceType<C>>, bwd: (target: Inner<InstanceType<C>>, v: P) => P): Writable<InstanceType<C>>;
|
|
169
|
+
static lens<C extends new (...args: never[]) => Cell<any>, P extends readonly Read<unknown>[]>(this: C, parents: P, fwd: (vals: {
|
|
170
|
+
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
171
|
+
}) => Inner<InstanceType<C>>, bwd: (target: Inner<InstanceType<C>>, vals: {
|
|
172
|
+
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
173
|
+
}) => {
|
|
174
|
+
[K in keyof P]?: P[K] extends Read<infer V> ? V : never;
|
|
175
|
+
}): Writable<InstanceType<C>>;
|
|
176
|
+
static lens<C extends new (...args: never[]) => Cell<any>, P, Cm>(this: C, parent: Read<P>, spec: StatefulLensSpec<readonly [P], Inner<InstanceType<C>>, Cm>): Writable<InstanceType<C>>;
|
|
177
|
+
static lens<C extends new (...args: never[]) => Cell<any>, P extends readonly Read<unknown>[], Cm>(this: C, parents: P, spec: StatefulLensSpec<{
|
|
178
|
+
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
179
|
+
}, Inner<InstanceType<C>>, Cm>): Writable<InstanceType<C>>;
|
|
180
|
+
/** Type predicate against this class: `Vec.is(x)` narrows `x` to `Vec`.
|
|
181
|
+
* Inherited static; works for any subclass via polymorphic `this`. */
|
|
182
|
+
static is<C extends new (...args: never[]) => Cell<any>>(this: C, v: unknown): v is InstanceType<C>;
|
|
183
|
+
/** Lift `Val<Inner<Cls>>` → `Cls`: instance → identity, RO cell →
|
|
184
|
+
* tracked `derive`, literal → fresh seed. */
|
|
185
|
+
static from<C extends new (...args: never[]) => Cell<any>>(this: C, v: Val<Inner<InstanceType<C>>>): InstanceType<C>;
|
|
186
|
+
/** Writable-shaped constant: always reads `v`, absorbs writes
|
|
187
|
+
* (parentless sink lens), for APIs demanding bidirectionality. */
|
|
188
|
+
static pin<C extends new (...args: never[]) => Cell<any>>(this: C, v: Inner<InstanceType<C>>): Writable<InstanceType<C>>;
|
|
189
|
+
/** Typed field lens onto `parent.value[key]`. A read-only computed
|
|
190
|
+
* parent yields a RO derive view; any writable parent yields a
|
|
191
|
+
* bidirectional field lens with spread-replace `put`. */
|
|
192
|
+
static fieldOf<C extends new (...args: never[]) => Cell<any>>(parent: Cell<any>, key: string | number | symbol, Cls: C): InstanceType<C>;
|
|
193
|
+
}
|
|
194
|
+
export interface StatefulBwd<S extends readonly unknown[], C> {
|
|
195
|
+
updates: {
|
|
196
|
+
readonly [K in keyof S]: S[K] | undefined;
|
|
197
|
+
};
|
|
198
|
+
complement: C;
|
|
199
|
+
}
|
|
200
|
+
export interface StatefulLensSpec<S extends readonly unknown[], V, C> {
|
|
201
|
+
init: (sources: S) => C;
|
|
202
|
+
step: (sources: S, complement: C, external: boolean) => C;
|
|
203
|
+
fwd: (sources: S, complement: C) => V;
|
|
204
|
+
bwd: (target: V, sources: S, complement: C) => StatefulBwd<S, C>;
|
|
205
|
+
}
|
|
206
|
+
/** Writable source; passes an existing `Writable` through (idempotent). */
|
|
207
|
+
export declare function cell<T>(initial: T | Writable<Cell<T>>, opts?: CellOptions<T>): Writable<Cell<T>>;
|
|
208
|
+
export declare function computed<T>(fn: () => T): Cell<T>;
|
|
209
|
+
/** Untyped read-only view: `derive(parent, fn)`, `derive(parents, fn)`,
|
|
210
|
+
* or `derive(fn)` (closure). */
|
|
211
|
+
export declare function derive<P, R>(parent: Read<P>, fn: (v: P) => R): Cell<R>;
|
|
212
|
+
export declare function derive<P extends readonly Read<unknown>[], R>(parents: P, fn: (vals: {
|
|
213
|
+
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
214
|
+
}) => R): Cell<R>;
|
|
215
|
+
export declare function derive<R>(fn: () => R): Cell<R>;
|
|
216
|
+
/** Untyped lens, inferring `R` from the closures. A 2-arg `bwd` reads the
|
|
217
|
+
* source, a 1-arg `bwd` reconstructs it; `lens(parent(s), spec)` builds a
|
|
218
|
+
* complement-carrying lens. */
|
|
219
|
+
export declare function lens<P, R>(parent: Read<P>, fwd: (v: P) => R, bwd: (target: R, v: P) => P): Writable<Cell<R>>;
|
|
220
|
+
export declare function lens<P extends readonly Read<unknown>[], R>(parents: P, fwd: (vals: {
|
|
221
|
+
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
222
|
+
}) => R, bwd: (target: R, vals: {
|
|
223
|
+
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
224
|
+
}) => {
|
|
225
|
+
[K in keyof P]?: P[K] extends Read<infer V> ? V : never;
|
|
226
|
+
}): Writable<Cell<R>>;
|
|
227
|
+
export declare function lens<P, R, C>(parent: Read<P>, spec: StatefulLensSpec<readonly [P], R, C>): Writable<Cell<R>>;
|
|
228
|
+
export declare function lens<P extends readonly Read<unknown>[], R, C>(parents: P, spec: StatefulLensSpec<{
|
|
229
|
+
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
230
|
+
}, R, C>): Writable<Cell<R>>;
|
|
231
|
+
export declare function effect(fn: () => (() => void) | void): () => void;
|
|
232
|
+
export declare function batch<R>(fn: () => R): R;
|
|
233
|
+
export declare function untracked<R>(fn: () => R): R;
|
|
234
|
+
/** Handle to a `network` invocation. */
|
|
235
|
+
export interface Network {
|
|
236
|
+
/** Tear down: unsubscribe from every cell, drop internal state. */
|
|
237
|
+
dispose(): void;
|
|
238
|
+
/** Run the body now (manual mode's only advance; no-op if unchanged). */
|
|
239
|
+
flush(): void;
|
|
240
|
+
/** Add cells to the topology (idempotent; does NOT fire the body). */
|
|
241
|
+
subscribe(...sigs: Cell<any>[]): void;
|
|
242
|
+
/** Remove cells from the topology (idempotent; does NOT fire). */
|
|
243
|
+
unsubscribe(...sigs: Cell<any>[]): void;
|
|
244
|
+
}
|
|
245
|
+
/** Build a reactive sub-DAG node with explicit topology. The body fires
|
|
246
|
+
* when any subscribed dep changes (`dirty` = the changed subset), runs
|
|
247
|
+
* inside `batch()`, and self-excludes its own writes. Topology is the
|
|
248
|
+
* deps array + later subscribe/unsubscribe (body reads add no deps).
|
|
249
|
+
* `flush()` from inside the body throws; `manual: true` defers
|
|
250
|
+
* auto-firing so only `flush()` advances. */
|
|
251
|
+
export declare function network(deps: readonly Cell<any>[], body: (dirty: ReadonlySet<Cell<unknown>>, handle: Network) => void, opts?: {
|
|
252
|
+
manual?: boolean;
|
|
253
|
+
}): Network;
|
|
254
|
+
export {};
|