@motionscript/math 0.1.0-alpha.5 → 0.1.0-alpha.6
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/CHANGELOG.md +22 -0
- package/README.md +39 -33
- package/dist/annotate/angle-mark.d.ts +52 -27
- package/dist/annotate/angle-mark.d.ts.map +1 -1
- package/dist/annotate/angle-mark.js +80 -115
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +59 -25
- package/dist/annotate/curly-brace.d.ts.map +1 -1
- package/dist/annotate/curly-brace.js +85 -100
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +43 -9
- package/dist/annotate/emphasis-mark.d.ts.map +1 -1
- package/dist/annotate/emphasis-mark.js +33 -34
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/chunk-ABYBW64J.js +2 -0
- package/dist/browser/chunks/chunk-ABYBW64J.js.map +7 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js +2 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/tex.js +1 -1
- package/dist/browser/tex.js.map +2 -2
- package/dist/engine.d.ts +26 -19
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +17 -14
- package/dist/engine.js.map +1 -1
- package/dist/kit/component.d.ts +51 -0
- package/dist/kit/component.d.ts.map +1 -0
- package/dist/kit/component.js +30 -0
- package/dist/kit/component.js.map +1 -0
- package/dist/kit/curve.d.ts +22 -11
- package/dist/kit/curve.d.ts.map +1 -1
- package/dist/kit/curve.js +25 -18
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/field-mark.d.ts +58 -35
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js +100 -120
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/follow.d.ts +67 -29
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js +114 -110
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.d.ts +3 -1
- package/dist/kit/furniture.d.ts.map +1 -1
- package/dist/kit/furniture.js +5 -0
- package/dist/kit/furniture.js.map +1 -1
- package/dist/kit/graph.d.ts +46 -0
- package/dist/kit/graph.d.ts.map +1 -0
- package/dist/kit/graph.js +90 -0
- package/dist/kit/graph.js.map +1 -0
- package/dist/kit/mark.d.ts +64 -39
- package/dist/kit/mark.d.ts.map +1 -1
- package/dist/kit/mark.js +80 -96
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/place.d.ts +10 -8
- package/dist/kit/place.d.ts.map +1 -1
- package/dist/kit/place.js +28 -30
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/system.d.ts +27 -29
- package/dist/kit/system.d.ts.map +1 -1
- package/dist/kit/system.js +62 -58
- package/dist/kit/system.js.map +1 -1
- package/dist/kit/withdrawn.d.ts +3 -3
- package/dist/kit/withdrawn.js +3 -3
- package/dist/kit/withdrawn.js.map +1 -1
- package/dist/marks/curve-area.d.ts +24 -18
- package/dist/marks/curve-area.d.ts.map +1 -1
- package/dist/marks/curve-area.js +50 -73
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +28 -10
- package/dist/marks/drop-lines.d.ts.map +1 -1
- package/dist/marks/drop-lines.js +37 -52
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +37 -20
- package/dist/marks/plot-point.d.ts.map +1 -1
- package/dist/marks/plot-point.js +65 -91
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +30 -26
- package/dist/marks/riemann-sum.d.ts.map +1 -1
- package/dist/marks/riemann-sum.js +57 -85
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +38 -14
- package/dist/marks/tangent-line.d.ts.map +1 -1
- package/dist/marks/tangent-line.js +73 -87
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +30 -20
- package/dist/marks/vector-arrow.d.ts.map +1 -1
- package/dist/marks/vector-arrow.js +58 -78
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.d.ts +13 -5
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -6
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +107 -43
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js +146 -177
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.d.ts +34 -19
- package/dist/plots/points-plot.d.ts.map +1 -1
- package/dist/plots/points-plot.js +31 -58
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.d.ts +38 -19
- package/dist/plots/stream-lines.d.ts.map +1 -1
- package/dist/plots/stream-lines.js +60 -79
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.d.ts +34 -15
- package/dist/plots/traced-path.d.ts.map +1 -1
- package/dist/plots/traced-path.js +33 -48
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.d.ts +31 -11
- package/dist/plots/vector-field.d.ts.map +1 -1
- package/dist/plots/vector-field.js +50 -64
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/network-graph.d.ts +99 -49
- package/dist/structures/network-graph.d.ts.map +1 -1
- package/dist/structures/network-graph.js +168 -217
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.d.ts +69 -38
- package/dist/structures/sample-space.d.ts.map +1 -1
- package/dist/structures/sample-space.js +132 -170
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts +126 -37
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js +147 -183
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.d.ts +51 -28
- package/dist/systems/number-line.d.ts.map +1 -1
- package/dist/systems/number-line.js +82 -118
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.d.ts +92 -31
- package/dist/systems/number-plane.d.ts.map +1 -1
- package/dist/systems/number-plane.js +142 -149
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.d.ts +47 -26
- package/dist/systems/polar-plane.d.ts.map +1 -1
- package/dist/systems/polar-plane.js +107 -133
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/index.d.ts.map +1 -1
- package/dist/tex/index.js +1 -0
- package/dist/tex/index.js.map +1 -1
- package/dist/tex/matrix.d.ts +56 -18
- package/dist/tex/matrix.d.ts.map +1 -1
- package/dist/tex/matrix.js +33 -50
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/node.d.ts +55 -201
- package/dist/tex/node.d.ts.map +1 -1
- package/dist/tex/node.js +23 -593
- package/dist/tex/node.js.map +1 -1
- package/dist/tex/typeset.d.ts +133 -0
- package/dist/tex/typeset.d.ts.map +1 -0
- package/dist/tex/typeset.js +403 -0
- package/dist/tex/typeset.js.map +1 -0
- package/dist/three/axes3d.d.ts +140 -54
- package/dist/three/axes3d.d.ts.map +1 -1
- package/dist/three/axes3d.js +159 -204
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +70 -42
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js +97 -132
- package/dist/three/curve-plot3d.js.map +1 -1
- package/dist/three/entries.d.ts +17 -0
- package/dist/three/entries.d.ts.map +1 -0
- package/dist/three/entries.js +15 -0
- package/dist/three/entries.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +57 -12
- package/dist/three/plot-point3d.d.ts.map +1 -1
- package/dist/three/plot-point3d.js +27 -53
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.d.ts +17 -2
- package/dist/three/space.d.ts.map +1 -1
- package/dist/three/space.js +19 -8
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +131 -49
- package/dist/three/surface-plot3d.d.ts.map +1 -1
- package/dist/three/surface-plot3d.js +227 -261
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +58 -16
- package/dist/three/vector-arrow3d.d.ts.map +1 -1
- package/dist/three/vector-arrow3d.js +48 -67
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +4 -4
- package/src/annotate/angle-mark.ts +95 -105
- package/src/annotate/curly-brace.ts +107 -85
- package/src/annotate/emphasis-mark.ts +55 -26
- package/src/engine.ts +35 -21
- package/src/kit/component.ts +57 -0
- package/src/kit/curve.ts +38 -20
- package/src/kit/field-mark.ts +124 -108
- package/src/kit/follow.ts +146 -120
- package/src/kit/furniture.ts +6 -1
- package/src/kit/graph.ts +116 -0
- package/src/kit/mark.ts +135 -114
- package/src/kit/place.ts +32 -56
- package/src/kit/system.ts +77 -71
- package/src/kit/withdrawn.ts +3 -3
- package/src/marks/curve-area.ts +65 -65
- package/src/marks/drop-lines.ts +50 -42
- package/src/marks/plot-point.ts +77 -82
- package/src/marks/riemann-sum.ts +73 -72
- package/src/marks/tangent-line.ts +87 -71
- package/src/marks/vector-arrow.ts +73 -73
- package/src/nodes.ts +41 -5
- package/src/plots/function-plot.ts +155 -171
- package/src/plots/points-plot.ts +46 -50
- package/src/plots/stream-lines.ts +75 -66
- package/src/plots/traced-path.ts +51 -33
- package/src/plots/vector-field.ts +68 -49
- package/src/structures/network-graph.ts +168 -185
- package/src/structures/sample-space.ts +149 -148
- package/src/systems/axes2d.ts +165 -156
- package/src/systems/number-line.ts +91 -92
- package/src/systems/number-plane.ts +149 -120
- package/src/systems/polar-plane.ts +117 -116
- package/src/tex/index.ts +2 -1
- package/src/tex/matrix.ts +62 -40
- package/src/tex/node.ts +54 -621
- package/src/tex/typeset.ts +461 -0
- package/src/three/axes3d.ts +182 -161
- package/src/three/curve-plot3d.ts +107 -110
- package/src/three/entries.ts +42 -0
- package/src/three/plot-point3d.ts +42 -45
- package/src/three/space.ts +34 -9
- package/src/three/surface-plot3d.ts +312 -323
- package/src/three/vector-arrow3d.ts +65 -54
- package/dist/browser/chunks/chunk-3GJB6AVO.js +0 -2
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +0 -7
- package/dist/browser/chunks/chunk-D5WHCVBC.js +0 -2
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +0 -7
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +0 -2
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +0 -7
- package/src/kit/placement.ts +0 -8
package/dist/kit/follow.js
CHANGED
|
@@ -1,41 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
import { command, findNode2D, frameIn, Graphics2D, PaintNode, pathOps, property, withdraw, } from "@motionscript/sdk";
|
|
8
|
-
import { FILL_PAINT } from "./withdrawn.js";
|
|
1
|
+
import { commandsFor, pathOps, Types, } from "@motionscript/sdk";
|
|
2
|
+
import { omit, PAINT, PAINT_COMMANDS } from "./component.js";
|
|
3
|
+
import { LatexMatrix } from "../tex/matrix.js";
|
|
4
|
+
import { Latex } from "../tex/node.js";
|
|
5
|
+
import { isFormula, latexPartBounds } from "../tex/typeset.js";
|
|
6
|
+
import { refId } from "./graph.js";
|
|
9
7
|
function isParted(node) {
|
|
10
|
-
return typeof node.partBounds === "function";
|
|
8
|
+
return typeof node.partBounds === "function" || isFormula(node);
|
|
9
|
+
}
|
|
10
|
+
/** The box of `part` in `node`: its own `partBounds` answer, or a formula component's by its source. */
|
|
11
|
+
function partBoundsOf(node, part, occurrence) {
|
|
12
|
+
if (typeof node.partBounds === "function")
|
|
13
|
+
return node.partBounds(part, occurrence);
|
|
14
|
+
return latexPartBounds(node, part, occurrence) ?? null;
|
|
15
|
+
}
|
|
16
|
+
const restOf = ({ on, part, occurrence }) => ({ on, part, occurrence });
|
|
17
|
+
function lerpRetarget(from, to, t) {
|
|
18
|
+
if (t <= 0 || !to)
|
|
19
|
+
return t < 1 ? from : to;
|
|
20
|
+
return { ...restOf(to), from: from ? restOf(from) : null, t };
|
|
11
21
|
}
|
|
22
|
+
const REF = Types.custom("", { kind: "nodeRef", animatable: false });
|
|
23
|
+
const HELD_REF = Types.custom("", { kind: "nodeRef", private: true });
|
|
12
24
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
25
|
+
* A mark drawn on another node, or on one part of a formula: a brace, a box,
|
|
26
|
+
* an underline. It has no size of its own and takes no place in a layout; it
|
|
27
|
+
* is drawn where its target is, wherever the two are in the tree, and its
|
|
28
|
+
* selection box is its ink. Its entries, and what it draws on.
|
|
16
29
|
*/
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
30
|
+
export const FOLLOW_STATE = {
|
|
31
|
+
// It is only an outline.
|
|
32
|
+
...omit(PAINT, "fill"),
|
|
33
|
+
/** The node this mark is drawn on, by id. Left empty, it is the formula the mark sits inside. */
|
|
34
|
+
on: REF,
|
|
35
|
+
/** One part of that node, by its source, where it has parts: `x^2` of a formula. */
|
|
36
|
+
part: Types.text("", { animatable: false }),
|
|
37
|
+
/** Which of the places the part is written, counted from 1. */
|
|
38
|
+
occurrence: Types.number(1, { min: 1, step: 1, animatable: false }),
|
|
39
|
+
/** Where a `retargetTo` has taken the mark, and how far along it is. Not an author's to state. */
|
|
40
|
+
retarget: Types.custom(null, { lerp: lerpRetarget }),
|
|
41
|
+
/** The nodes the retarget names, there and where it set out from, read as nodes. */
|
|
42
|
+
retargetOn: HELD_REF,
|
|
43
|
+
retargetFrom: HELD_REF,
|
|
44
|
+
};
|
|
45
|
+
export const FOLLOW_COMMANDS = {
|
|
46
|
+
...omit(PAINT_COMMANDS, "fillTo"),
|
|
47
|
+
...commandsFor(FOLLOW_STATE, {
|
|
48
|
+
/** Move the mark onto another node, or another part. */
|
|
49
|
+
retargetTo: {
|
|
50
|
+
// No defaults for the node and the part: one left out keeps the mark's own.
|
|
51
|
+
args: {
|
|
52
|
+
on: Types.custom(undefined, { kind: "nodeRef" }),
|
|
53
|
+
part: Types.custom(undefined, { kind: "text" }),
|
|
54
|
+
occurrence: Types.number(1, { min: 1, step: 1 }),
|
|
55
|
+
},
|
|
56
|
+
run: (timeline, s) => {
|
|
57
|
+
const next = timeline.args;
|
|
58
|
+
const held = s.retarget ?? restingOf(s);
|
|
59
|
+
const to = {
|
|
60
|
+
on: next.on ?? held.on,
|
|
61
|
+
part: next.part ?? (next.on ? "" : held.part),
|
|
62
|
+
occurrence: next.occurrence ?? 1,
|
|
63
|
+
t: 1,
|
|
64
|
+
};
|
|
65
|
+
const from = s.retarget;
|
|
66
|
+
return timeline.animate((t) => {
|
|
67
|
+
const retarget = lerpRetarget(from, to, t);
|
|
68
|
+
return { retarget, retargetOn: retarget?.on ?? "", retargetFrom: retarget?.from?.on ?? "" };
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
function restingOf(s) {
|
|
75
|
+
return { on: refId(s.on), part: s.part, occurrence: s.occurrence };
|
|
27
76
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
77
|
+
const containers = new WeakMap();
|
|
78
|
+
/**
|
|
79
|
+
* The formula a follow mark sits in, as its render last found it: what a mark
|
|
80
|
+
* naming no node is drawn on. Its bounds and handles read it from there, where
|
|
81
|
+
* there is no context to ask.
|
|
82
|
+
*/
|
|
83
|
+
export function container(ctx, s) {
|
|
84
|
+
if (!ctx)
|
|
85
|
+
return containers.get(s) ?? null;
|
|
86
|
+
const found = ctx.ancestor(Latex) ?? ctx.ancestor(LatexMatrix);
|
|
87
|
+
const parted = found && isParted(found.state) ? found : null;
|
|
88
|
+
containers.set(s, parted);
|
|
89
|
+
return parted;
|
|
90
|
+
}
|
|
91
|
+
/** The node the mark rests on: the one `on` names, or the formula it sits in. */
|
|
92
|
+
export function resting(s, parted) {
|
|
93
|
+
return s.on ?? parted;
|
|
94
|
+
}
|
|
95
|
+
/** The target's corners now: its resting one, or part-way to where a `retargetTo` is taking it. */
|
|
96
|
+
export function followedQuad(s, parted) {
|
|
97
|
+
const state = s.retarget;
|
|
98
|
+
const rest = () => quadOf(resting(s, parted), s);
|
|
99
|
+
if (!state)
|
|
100
|
+
return rest();
|
|
101
|
+
const to = quadOf(state.on === "" ? parted : s.retargetOn, state);
|
|
102
|
+
const from = state.from ? quadOf(state.from.on === "" ? parted : s.retargetFrom, state.from) : rest();
|
|
103
|
+
if (!from || !to || state.t >= 1)
|
|
104
|
+
return to ?? from;
|
|
105
|
+
return lerpQuad(from, to, state.t);
|
|
106
|
+
}
|
|
107
|
+
/** Where `target` is, as the mark sees it; `null` when it names no node or part. */
|
|
108
|
+
function quadOf(node, target) {
|
|
31
109
|
if (!node)
|
|
32
110
|
return null;
|
|
33
|
-
const box = target.part && isParted(node)
|
|
34
|
-
? node.
|
|
35
|
-
: { x: 0, y: 0, width: node.
|
|
111
|
+
const box = target.part && isParted(node.state)
|
|
112
|
+
? partBoundsOf(node.state, target.part, target.occurrence || 1)
|
|
113
|
+
: { x: 0, y: 0, width: node.size.width, height: node.size.height };
|
|
36
114
|
if (!box)
|
|
37
115
|
return null;
|
|
38
|
-
const frame =
|
|
116
|
+
const frame = node.frame;
|
|
39
117
|
const turn = (frame.rotation * Math.PI) / 180;
|
|
40
118
|
const cos = Math.cos(turn);
|
|
41
119
|
const sin = Math.sin(turn);
|
|
@@ -51,89 +129,15 @@ export function quadOf(mark, target) {
|
|
|
51
129
|
function lerpQuad(a, b, t) {
|
|
52
130
|
return a.map((from, i) => ({ x: from.x + (b[i].x - from.x) * t, y: from.y + (b[i].y - from.y) * t }));
|
|
53
131
|
}
|
|
54
|
-
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
132
|
+
/** The box of an outline, as a follow mark's bounds: it has no size of its own, so its ink is what is selected. */
|
|
133
|
+
export function outlineBounds(outline) {
|
|
134
|
+
const ink = pathOps.bounds(outline);
|
|
135
|
+
if (!ink)
|
|
136
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
137
|
+
return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };
|
|
59
138
|
}
|
|
60
139
|
/** Every drawn point's centre frame: the mark's own centre, so its outline is where it says. */
|
|
61
|
-
const OWN_FRAME = [-1, -1, 1, 1];
|
|
62
|
-
/**
|
|
63
|
-
* A mark drawn on another node, or on one part of a formula: a brace, a box,
|
|
64
|
-
* an underline. It has no size of its own and takes no place in a layout; it
|
|
65
|
-
* is drawn where its target is, wherever the two are in the tree, and its
|
|
66
|
-
* selection box is its ink.
|
|
67
|
-
*/
|
|
68
|
-
let FollowMark = class FollowMark extends PaintNode {
|
|
69
|
-
/** Move the mark onto another node, or another part. */
|
|
70
|
-
retargetTo(args) {
|
|
71
|
-
const next = args.data ?? {};
|
|
72
|
-
const held = this.retarget ?? this;
|
|
73
|
-
const to = {
|
|
74
|
-
on: next.on ?? held.on,
|
|
75
|
-
part: next.part ?? (next.on ? "" : held.part),
|
|
76
|
-
occurrence: next.occurrence ?? 1,
|
|
77
|
-
t: 1,
|
|
78
|
-
};
|
|
79
|
-
return this.to({ data: { retarget: to }, duration: args.duration, easing: args.easing });
|
|
80
|
-
}
|
|
81
|
-
/** The target's corners now: its resting one, or part-way to where a `retargetTo` is taking it. */
|
|
82
|
-
quad() {
|
|
83
|
-
const state = this.retarget;
|
|
84
|
-
if (!state)
|
|
85
|
-
return quadOf(this, this);
|
|
86
|
-
const to = quadOf(this, state);
|
|
87
|
-
const from = quadOf(this, state.from ?? this);
|
|
88
|
-
if (!from || !to || state.t >= 1)
|
|
89
|
-
return to ?? from;
|
|
90
|
-
return lerpQuad(from, to, state.t);
|
|
91
|
-
}
|
|
92
|
-
measure() {
|
|
93
|
-
return { width: 0, height: 0 };
|
|
94
|
-
}
|
|
95
|
-
shapeGraphics() {
|
|
96
|
-
const data = this._outline();
|
|
97
|
-
if (data.length === 0)
|
|
98
|
-
return null;
|
|
99
|
-
return new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: this.start, end: this.end });
|
|
100
|
-
}
|
|
101
|
-
_localBounds() {
|
|
102
|
-
const ink = pathOps.bounds(this._outline());
|
|
103
|
-
if (!ink)
|
|
104
|
-
return { x: 0, y: 0, width: 0, height: 0 };
|
|
105
|
-
return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };
|
|
106
|
-
}
|
|
107
|
-
_outline() {
|
|
108
|
-
const quad = this.quad();
|
|
109
|
-
return quad ? this.outline(quad) : [];
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
__decorate([
|
|
113
|
-
property({ default: "", kind: "nodeRef", animatable: false })
|
|
114
|
-
], FollowMark.prototype, "on", void 0);
|
|
115
|
-
__decorate([
|
|
116
|
-
property({ default: "", animatable: false })
|
|
117
|
-
], FollowMark.prototype, "part", void 0);
|
|
118
|
-
__decorate([
|
|
119
|
-
property({ default: 1, min: 1, step: 1, animatable: false })
|
|
120
|
-
], FollowMark.prototype, "occurrence", void 0);
|
|
121
|
-
__decorate([
|
|
122
|
-
property({ default: null, tween: lerpRetarget })
|
|
123
|
-
], FollowMark.prototype, "retarget", void 0);
|
|
124
|
-
__decorate([
|
|
125
|
-
command({
|
|
126
|
-
args: [
|
|
127
|
-
{ key: "on", kind: "nodeRef" },
|
|
128
|
-
{ key: "part", kind: "text", default: "" },
|
|
129
|
-
{ key: "occurrence", kind: "number", min: 1, step: 1, default: 1 },
|
|
130
|
-
],
|
|
131
|
-
})
|
|
132
|
-
], FollowMark.prototype, "retargetTo", null);
|
|
133
|
-
FollowMark = __decorate([
|
|
134
|
-
withdraw(...FILL_PAINT)
|
|
135
|
-
], FollowMark);
|
|
136
|
-
export { FollowMark };
|
|
140
|
+
export const OWN_FRAME = [-1, -1, 1, 1];
|
|
137
141
|
// --- Geometry the marks share ---
|
|
138
142
|
export const add = (a, b, k = 1) => ({ x: a.x + b.x * k, y: a.y + b.y * k });
|
|
139
143
|
export const between = (a, b, t = 0.5) => ({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });
|
package/dist/kit/follow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"follow.js","sourceRoot":"","sources":["../../src/kit/follow.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,OAAO,EACP,UAAU,EACV,OAAO,EACP,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,EACR,QAAQ,GASX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQzC,SAAS,QAAQ,CAAC,IAAY;IAC1B,OAAO,OAAQ,IAAwB,CAAC,UAAU,KAAK,UAAU,CAAC;AACtE,CAAC;AAkBD;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,EAAU;IAC7C,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAClC,OAAO,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/C,CAAC;IACD,KAAK,IAAI,EAAE,GAAkB,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;QAC3D,IAAI,QAAQ,CAAC,EAAE,CAAC;YAAE,OAAO,EAAE,CAAC;IAChC,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,MAAM,CA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9B,MAAM,MAAM,GAAG,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC;IACpC,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC;IAChC,OAAO;QACH,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;QACjC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;QAChC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;QACjC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;KACrC,CAAC;AACN,CAAC","sourcesContent":["import {\r\n command,\r\n findNode2D,\r\n frameIn,\r\n Graphics2D,\r\n PaintNode,\r\n pathOps,\r\n property,\r\n withdraw,\r\n type BoxBounds,\r\n type Command,\r\n type CommandArgs,\r\n type Node2D,\r\n type PaintProps,\r\n type PathCommand,\r\n type Size2D,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport { FILL_PAINT } from \"./withdrawn\";\r\n\r\n/** A node with parts that can be pointed at by name: a formula's terms. */\r\nexport interface Parted {\r\n /** The box of `part`, y-up from the node's centre, or `null` when it has no such part. */\r\n partBounds(part: string, occurrence?: number): BoxBounds | null;\r\n}\r\n\r\nfunction isParted(node: object): node is Parted {\r\n return typeof (node as Partial<Parted>).partBounds === \"function\";\r\n}\r\n\r\n/** What a mark is drawn on: a node by id, and one part of it where it has parts. */\r\nexport interface Target {\r\n on: string;\r\n part?: string;\r\n occurrence?: number;\r\n}\r\n\r\n/** A target on its way to another: `t` of the way from `from`, or from the mark's resting target. */\r\nexport interface Retarget extends Target {\r\n from?: Target | null;\r\n t: number;\r\n}\r\n\r\n/** A target's four corners in its mark's own frame, y-up: top left, top right, bottom right, bottom left. */\r\nexport type Quad = [Vector2, Vector2, Vector2, Vector2];\r\n\r\n/**\r\n * The node a mark is drawn on: the one `on` names, or, naming none, the nearest\r\n * node with parts the mark sits inside. Putting a box in a formula is how it is\r\n * told which.\r\n */\r\nexport function followed(mark: Node2D, on: string): Node2D | null {\r\n if (on !== \"\") {\r\n const node = findNode2D(mark, on);\r\n return node && node !== mark ? node : null;\r\n }\r\n for (let at: Node2D | null = mark.parent; at; at = at.parent) {\r\n if (isParted(at)) return at;\r\n }\r\n return null;\r\n}\r\n\r\n/** Where `target` is, as `mark` sees it; `null` when it names no node or part. */\r\nexport function quadOf(mark: Node2D, target: Target): Quad | null {\r\n const node = followed(mark, target.on);\r\n if (!node) return null;\r\n const box: BoxBounds | null =\r\n target.part && isParted(node)\r\n ? node.partBounds(target.part, target.occurrence || 1)\r\n : { x: 0, y: 0, width: node.layoutBounds.width, height: node.layoutBounds.height };\r\n if (!box) return null;\r\n const frame = frameIn(mark, node);\r\n const turn = (frame.rotation * Math.PI) / 180;\r\n const cos = Math.cos(turn);\r\n const sin = Math.sin(turn);\r\n // The engine's turn is clockwise, in a y-up frame.\r\n const place = (x: number, y: number): Vector2 => ({\r\n x: frame.x + (cos * x + sin * y) * frame.scale,\r\n y: frame.y + (-sin * x + cos * y) * frame.scale,\r\n });\r\n const w = box.width / 2;\r\n const h = box.height / 2;\r\n return [place(box.x - w, box.y + h), place(box.x + w, box.y + h), place(box.x + w, box.y - h), place(box.x - w, box.y - h)];\r\n}\r\n\r\nfunction lerpQuad(a: Quad, b: Quad, t: number): Quad {\r\n return a.map((from, i) => ({ x: from.x + (b[i].x - from.x) * t, y: from.y + (b[i].y - from.y) * t })) as Quad;\r\n}\r\n\r\nconst restOf = ({ on, part, occurrence }: Target): Target => ({ on, part, occurrence });\r\n\r\nfunction lerpRetarget(from: Retarget | null, to: Retarget | null, t: number): Retarget | null {\r\n if (t <= 0 || !to) return t < 1 ? from : to;\r\n return { ...restOf(to), from: from ? restOf(from) : null, t };\r\n}\r\n\r\nexport interface FollowProps extends PaintProps {\r\n on?: string;\r\n part?: string;\r\n occurrence?: number;\r\n retarget?: Retarget | null;\r\n}\r\n\r\n/** Every drawn point's centre frame: the mark's own centre, so its outline is where it says. */\r\nconst OWN_FRAME: [number, number, number, number] = [-1, -1, 1, 1];\r\n\r\n/**\r\n * A mark drawn on another node, or on one part of a formula: a brace, a box,\r\n * an underline. It has no size of its own and takes no place in a layout; it\r\n * is drawn where its target is, wherever the two are in the tree, and its\r\n * selection box is its ink.\r\n */\r\n@withdraw(...FILL_PAINT)\r\nexport abstract class FollowMark<P extends FollowProps = FollowProps> extends PaintNode<P> {\r\n /** The node this mark is drawn on, by id. Left empty, it is the formula the mark sits inside. */\r\n @property({ default: \"\", kind: \"nodeRef\", animatable: false }) declare on: string;\r\n /** One part of that node, by its source, where it has parts: `x^2` of a formula. */\r\n @property({ default: \"\", animatable: false }) declare part: string;\r\n /** Which of the places the part is written, counted from 1. */\r\n @property({ default: 1, min: 1, step: 1, animatable: false }) declare occurrence: number;\r\n /** Where a `retargetTo` has taken the mark, and how far along it is. Not an author's to state. */\r\n @property({ default: null, tween: lerpRetarget }) declare retarget: Retarget | null;\r\n\r\n /** Move the mark onto another node, or another part. */\r\n @command({\r\n args: [\r\n { key: \"on\", kind: \"nodeRef\" },\r\n { key: \"part\", kind: \"text\", default: \"\" },\r\n { key: \"occurrence\", kind: \"number\", min: 1, step: 1, default: 1 },\r\n ],\r\n })\r\n retargetTo(args: CommandArgs<Partial<Target>> & { duration: number }): Command<P> {\r\n const next = args.data ?? {};\r\n const held = this.retarget ?? this;\r\n const to: Retarget = {\r\n on: next.on ?? held.on,\r\n part: next.part ?? (next.on ? \"\" : held.part),\r\n occurrence: next.occurrence ?? 1,\r\n t: 1,\r\n };\r\n return this.to({ data: { retarget: to } as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** The outline to draw around `quad`, in the mark's own frame, y-up. */\r\n protected abstract outline(quad: Quad): PathCommand[];\r\n\r\n /** The target's corners now: its resting one, or part-way to where a `retargetTo` is taking it. */\r\n protected quad(): Quad | null {\r\n const state = this.retarget;\r\n if (!state) return quadOf(this, this);\r\n const to = quadOf(this, state);\r\n const from = quadOf(this, state.from ?? this);\r\n if (!from || !to || state.t >= 1) return to ?? from;\r\n return lerpQuad(from, to, state.t);\r\n }\r\n\r\n override measure(): Partial<Size2D> {\r\n return { width: 0, height: 0 };\r\n }\r\n\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const data = this._outline();\r\n if (data.length === 0) return null;\r\n return new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: this.start, end: this.end });\r\n }\r\n\r\n override _localBounds(): BoxBounds {\r\n const ink = pathOps.bounds(this._outline());\r\n if (!ink) return { x: 0, y: 0, width: 0, height: 0 };\r\n return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };\r\n }\r\n\r\n private _outline(): PathCommand[] {\r\n const quad = this.quad();\r\n return quad ? this.outline(quad) : [];\r\n }\r\n}\r\n\r\n// --- Geometry the marks share ---\r\n\r\nexport const add = (a: Vector2, b: Vector2, k = 1): Vector2 => ({ x: a.x + b.x * k, y: a.y + b.y * k });\r\nexport const between = (a: Vector2, b: Vector2, t = 0.5): Vector2 => ({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });\r\n\r\n/** The unit vector from `a` to `b`, and its length; a zero one points right. */\r\nexport function heading(a: Vector2, b: Vector2): { unit: Vector2; length: number } {\r\n const dx = b.x - a.x;\r\n const dy = b.y - a.y;\r\n const length = Math.hypot(dx, dy);\r\n return { unit: length === 0 ? { x: 1, y: 0 } : { x: dx / length, y: dy / length }, length };\r\n}\r\n\r\n/** A quad grown by `by` pixels on every side, along its own edges. */\r\nexport function grown(quad: Quad, by: number): Quad {\r\n const [tl, tr, br, bl] = quad;\r\n const across = heading(tl, tr).unit;\r\n const up = heading(bl, tl).unit;\r\n return [\r\n add(add(tl, across, -by), up, by),\r\n add(add(tr, across, by), up, by),\r\n add(add(br, across, by), up, -by),\r\n add(add(bl, across, -by), up, -by),\r\n ];\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"follow.js","sourceRoot":"","sources":["../../src/kit/follow.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,OAAO,EACP,KAAK,GAYR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAQhC,SAAS,QAAQ,CAAC,IAAY;IAC1B,OAAO,OAAQ,IAAwB,CAAC,UAAU,KAAK,UAAU,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;AACzF,CAAC;AAED,wGAAwG;AACxG,SAAS,YAAY,CAAC,IAAY,EAAE,IAAY,EAAE,UAAkB;IAChE,IAAI,OAAQ,IAAwB,CAAC,UAAU,KAAK,UAAU;QAAE,OAAQ,IAAe,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACrH,OAAO,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,CAAC;AAC3D,CAAC;AAyBD,MAAM,MAAM,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAU,EAAU,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;AAExF,SAAS,YAAY,CAAC,IAAqB,EAAE,EAAmB,EAAE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,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;QACjC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;QAChC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;QACjC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;KACrC,CAAC;AACN,CAAC","sourcesContent":["import {\r\n commandsFor,\r\n pathOps,\r\n Types,\r\n type BoxBounds,\r\n type NodeView,\r\n type PaintProps,\r\n type PathCommand,\r\n type RenderContext,\r\n type Vector2,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport { omit, PAINT, PAINT_COMMANDS } from \"./component\";\r\nimport { LatexMatrix } from \"../tex/matrix\";\r\nimport { Latex } from \"../tex/node\";\r\nimport { isFormula, latexPartBounds } from \"../tex/typeset\";\r\nimport { refId } from \"./graph\";\r\n\r\n/** A node with parts that can be pointed at by name: a formula's terms. */\r\nexport interface Parted {\r\n /** The box of `part`, y-up from the node's centre, or `null` when it has no such part. */\r\n partBounds(part: string, occurrence?: number): BoxBounds | null;\r\n}\r\n\r\nfunction isParted(node: object): boolean {\r\n return typeof (node as Partial<Parted>).partBounds === \"function\" || isFormula(node);\r\n}\r\n\r\n/** The box of `part` in `node`: its own `partBounds` answer, or a formula component's by its source. */\r\nfunction partBoundsOf(node: object, part: string, occurrence: number): BoxBounds | null {\r\n if (typeof (node as Partial<Parted>).partBounds === \"function\") return (node as Parted).partBounds(part, occurrence);\r\n return latexPartBounds(node, part, occurrence) ?? null;\r\n}\r\n\r\n/** What a mark is drawn on: a node by id, and one part of it where it has parts. */\r\nexport interface Target {\r\n on: string;\r\n part?: string;\r\n occurrence?: number;\r\n}\r\n\r\n/** A target on its way to another: `t` of the way from `from`, or from the mark's resting target. */\r\nexport interface Retarget extends Target {\r\n from?: Target | null;\r\n t: number;\r\n}\r\n\r\nexport interface FollowProps extends PaintProps {\r\n on?: string;\r\n part?: string;\r\n occurrence?: number;\r\n retarget?: Retarget | null;\r\n}\r\n\r\n/** A target's four corners in its mark's own frame, y-up: top left, top right, bottom right, bottom left. */\r\nexport type Quad = [Vector2, Vector2, Vector2, Vector2];\r\n\r\nconst restOf = ({ on, part, occurrence }: Target): Target => ({ on, part, occurrence });\r\n\r\nfunction lerpRetarget(from: Retarget | null, to: Retarget | null, t: number): Retarget | null {\r\n if (t <= 0 || !to) return t < 1 ? from : to;\r\n return { ...restOf(to), from: from ? restOf(from) : null, t };\r\n}\r\n\r\nconst REF = Types.custom<string, NodeView | null>(\"\", { kind: \"nodeRef\", animatable: false });\r\nconst HELD_REF = Types.custom<string, NodeView | null, { readonly private: true }>(\"\", { kind: \"nodeRef\", private: true });\r\n\r\n/**\r\n * A mark drawn on another node, or on one part of a formula: a brace, a box,\r\n * an underline. It has no size of its own and takes no place in a layout; it\r\n * is drawn where its target is, wherever the two are in the tree, and its\r\n * selection box is its ink. Its entries, and what it draws on.\r\n */\r\nexport const FOLLOW_STATE = {\r\n // It is only an outline.\r\n ...omit(PAINT, \"fill\"),\r\n /** The node this mark is drawn on, by id. Left empty, it is the formula the mark sits inside. */\r\n on: REF,\r\n /** One part of that node, by its source, where it has parts: `x^2` of a formula. */\r\n part: Types.text(\"\", { animatable: false }),\r\n /** Which of the places the part is written, counted from 1. */\r\n occurrence: Types.number(1, { min: 1, step: 1, animatable: false }),\r\n /** Where a `retargetTo` has taken the mark, and how far along it is. Not an author's to state. */\r\n retarget: Types.custom<Retarget | null>(null, { lerp: lerpRetarget }),\r\n /** The nodes the retarget names, there and where it set out from, read as nodes. */\r\n retargetOn: HELD_REF,\r\n retargetFrom: HELD_REF,\r\n};\r\n\r\nexport const FOLLOW_COMMANDS = {\r\n ...omit(PAINT_COMMANDS, \"fillTo\"),\r\n ...commandsFor(FOLLOW_STATE, {\r\n /** Move the mark onto another node, or another part. */\r\n retargetTo: {\r\n // No defaults for the node and the part: one left out keeps the mark's own.\r\n args: {\r\n on: Types.custom<string | undefined>(undefined, { kind: \"nodeRef\" }),\r\n part: Types.custom<string | undefined>(undefined, { kind: \"text\" }),\r\n occurrence: Types.number(1, { min: 1, step: 1 }),\r\n },\r\n run: (timeline, s) => {\r\n const next = timeline.args;\r\n const held = s.retarget ?? restingOf(s);\r\n const to: Retarget = {\r\n on: next.on ?? held.on,\r\n part: next.part ?? (next.on ? \"\" : held.part),\r\n occurrence: next.occurrence ?? 1,\r\n t: 1,\r\n };\r\n const from = s.retarget;\r\n return timeline.animate((t) => {\r\n const retarget = lerpRetarget(from, to, t);\r\n return { retarget, retargetOn: retarget?.on ?? \"\", retargetFrom: retarget?.from?.on ?? \"\" };\r\n });\r\n },\r\n },\r\n }),\r\n};\r\n\r\n/** What a follow mark reads of its state. */\r\nexport interface FollowValues {\r\n readonly on: NodeView | null;\r\n readonly part: string;\r\n readonly occurrence: number;\r\n readonly retarget: Retarget | null;\r\n readonly retargetOn: NodeView | null;\r\n readonly retargetFrom: NodeView | null;\r\n}\r\n\r\nfunction restingOf(s: FollowValues): Target {\r\n return { on: refId(s.on), part: s.part, occurrence: s.occurrence };\r\n}\r\n\r\nconst containers = new WeakMap<object, NodeView | null>();\r\n\r\n/**\r\n * The formula a follow mark sits in, as its render last found it: what a mark\r\n * naming no node is drawn on. Its bounds and handles read it from there, where\r\n * there is no context to ask.\r\n */\r\nexport function container(ctx: RenderContext | null, s: object): NodeView | null {\r\n if (!ctx) return containers.get(s) ?? null;\r\n const found = ctx.ancestor(Latex) ?? ctx.ancestor(LatexMatrix);\r\n const parted = found && isParted(found.state) ? found : null;\r\n containers.set(s, parted);\r\n return parted;\r\n}\r\n\r\n/** The node the mark rests on: the one `on` names, or the formula it sits in. */\r\nexport function resting(s: FollowValues, parted: NodeView | null): NodeView | null {\r\n return s.on ?? parted;\r\n}\r\n\r\n/** The target's corners now: its resting one, or part-way to where a `retargetTo` is taking it. */\r\nexport function followedQuad(s: FollowValues, parted: NodeView | null): Quad | null {\r\n const state = s.retarget;\r\n const rest = (): Quad | null => quadOf(resting(s, parted), s);\r\n if (!state) return rest();\r\n const to = quadOf(state.on === \"\" ? parted : s.retargetOn, state);\r\n const from = state.from ? quadOf(state.from.on === \"\" ? parted : s.retargetFrom, state.from) : rest();\r\n if (!from || !to || state.t >= 1) return to ?? from;\r\n return lerpQuad(from, to, state.t);\r\n}\r\n\r\n/** Where `target` is, as the mark sees it; `null` when it names no node or part. */\r\nfunction quadOf(node: NodeView | null, target: Omit<Target, \"on\">): Quad | null {\r\n if (!node) return null;\r\n const box: BoxBounds | null =\r\n target.part && isParted(node.state)\r\n ? partBoundsOf(node.state, target.part, target.occurrence || 1)\r\n : { x: 0, y: 0, width: node.size.width, height: node.size.height };\r\n if (!box) return null;\r\n const frame = node.frame;\r\n const turn = (frame.rotation * Math.PI) / 180;\r\n const cos = Math.cos(turn);\r\n const sin = Math.sin(turn);\r\n // The engine's turn is clockwise, in a y-up frame.\r\n const place = (x: number, y: number): Vector2 => ({\r\n x: frame.x + (cos * x + sin * y) * frame.scale,\r\n y: frame.y + (-sin * x + cos * y) * frame.scale,\r\n });\r\n const w = box.width / 2;\r\n const h = box.height / 2;\r\n return [place(box.x - w, box.y + h), place(box.x + w, box.y + h), place(box.x + w, box.y - h), place(box.x - w, box.y - h)];\r\n}\r\n\r\nfunction lerpQuad(a: Quad, b: Quad, t: number): Quad {\r\n return a.map((from, i) => ({ x: from.x + (b[i].x - from.x) * t, y: from.y + (b[i].y - from.y) * t })) as Quad;\r\n}\r\n\r\n/** The box of an outline, as a follow mark's bounds: it has no size of its own, so its ink is what is selected. */\r\nexport function outlineBounds(outline: readonly PathCommand[]): BoxBounds {\r\n const ink = pathOps.bounds(outline as PathCommand[]);\r\n if (!ink) return { x: 0, y: 0, width: 0, height: 0 };\r\n return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };\r\n}\r\n\r\n/** Every drawn point's centre frame: the mark's own centre, so its outline is where it says. */\r\nexport const OWN_FRAME: [number, number, number, number] = [-1, -1, 1, 1];\r\n\r\n// --- Geometry the marks share ---\r\n\r\nexport const add = (a: Vector2, b: Vector2, k = 1): Vector2 => ({ x: a.x + b.x * k, y: a.y + b.y * k });\r\nexport const between = (a: Vector2, b: Vector2, t = 0.5): Vector2 => ({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });\r\n\r\n/** The unit vector from `a` to `b`, and its length; a zero one points right. */\r\nexport function heading(a: Vector2, b: Vector2): { unit: Vector2; length: number } {\r\n const dx = b.x - a.x;\r\n const dy = b.y - a.y;\r\n const length = Math.hypot(dx, dy);\r\n return { unit: length === 0 ? { x: 1, y: 0 } : { x: dx / length, y: dy / length }, length };\r\n}\r\n\r\n/** A quad grown by `by` pixels on every side, along its own edges. */\r\nexport function grown(quad: Quad, by: number): Quad {\r\n const [tl, tr, br, bl] = quad;\r\n const across = heading(tl, tr).unit;\r\n const up = heading(bl, tl).unit;\r\n return [\r\n add(add(tl, across, -by), up, by),\r\n add(add(tr, across, by), up, by),\r\n add(add(br, across, by), up, -by),\r\n add(add(bl, across, -by), up, -by),\r\n ];\r\n}\r\n"]}
|
package/dist/kit/furniture.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Graphics2D, type AssetScope, type Color, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
|
|
1
|
+
import { Graphics2D, type AssetScope, type Color, type Loader, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
|
|
2
2
|
import type { Interval } from "./coords.js";
|
|
3
3
|
/** Shared drawing for the systems' own furniture: axis lines, tick marks and their numbers. */
|
|
4
4
|
/** What a system draws its axes and numbers in, and a plot its curve, until told otherwise. */
|
|
@@ -19,6 +19,8 @@ export interface Label {
|
|
|
19
19
|
}
|
|
20
20
|
/** Ask the host for MathJax when any of `texts` is a formula, so it is there before the node is laid out. */
|
|
21
21
|
export declare function declareFormulas(assets: AssetScope, texts: readonly string[]): void;
|
|
22
|
+
/** {@link declareFormulas}, for a component's `load`. */
|
|
23
|
+
export declare function loadFormulas(loader: Loader, texts: readonly string[]): void;
|
|
22
24
|
/** What draws `labels`: text in the scene's face, and a typeset formula for each one written as such. */
|
|
23
25
|
export declare function drawLabels(labels: readonly Label[], style: LabelStyle): Graphics2D[];
|
|
24
26
|
/** Whether a mark `u` of the way along an axis is inside the part of it drawn so far. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"furniture.d.ts","sourceRoot":"","sources":["../../src/kit/furniture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAgB,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"furniture.d.ts","sourceRoot":"","sources":["../../src/kit/furniture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAgB,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjJ,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,+FAA+F;AAE/F,+FAA+F;AAC/F,eAAO,MAAM,UAAU,YAAY,CAAC;AACpC,eAAO,MAAM,UAAU,YAAY,CAAC;AAEpC,2EAA2E;AAC3E,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAEtE;AA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ader(MATHJAX_LOADER, loadMathJax, { gate: "layout" });
|
|
19
19
|
}
|
|
20
|
+
/** {@link declareFormulas}, for a component's `load`. */
|
|
21
|
+
export function loadFormulas(loader, texts) {
|
|
22
|
+
if (texts.some((text) => FORMULA.test(text.trim())))
|
|
23
|
+
loader.task(MATHJAX_LOADER, loadMathJax, { before: "layout" });
|
|
24
|
+
}
|
|
20
25
|
/** What draws `labels`: text in the scene's face, and a typeset formula for each one written as such. */
|
|
21
26
|
export function drawLabels(labels, style) {
|
|
22
27
|
const out = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"furniture.js","sourceRoot":"","sources":["../../src/kit/furniture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAkE,MAAM,mBAAmB,CAAC;AACpI,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAG9F,+FAA+F;AAE/F,+FAA+F;AAC/F,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AACpC,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AAEpC,2EAA2E;AAC3E,MAAM,UAAU,WAAW,CAAC,MAAwB;IAChD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;AACzF,CAAC;AAeD,oGAAoG;AACpG,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,8EAA8E;AAC9E,MAAM,OAAO,GAAG,iBAAiB,CAAC;AAElC,6GAA6G;AAC7G,MAAM,UAAU,eAAe,CAAC,MAAkB,EAAE,KAAwB;IACxE,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IA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AAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAA2B,EAAE,QAAmB;IACzE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { Fills, Graphics2D, toPathString, type AssetScope, type Color, type StrokeResolved, type Vector2 } from \"@motionscript/sdk\";\r\nimport { buildLatexPath, LatexNotLoaded, loadMathJax, MATHJAX_LOADER } from \"../tex/geometry\";\r\nimport type { Interval } from \"./coords\";\r\n\r\n/** Shared drawing for the systems' own furniture: axis lines, tick marks and their numbers. */\r\n\r\n/** What a system draws its axes and numbers in, and a plot its curve, until told otherwise. */\r\nexport const AXIS_COLOR = \"#9ca3af\";\r\nexport const PLOT_COLOR = \"#58a6ff\";\r\n\r\n/** A stroke without end markers: an axis wears a tip, its ticks do not. */\r\nexport function withoutTips(stroke: StrokeResolved[]): StrokeResolved[] {\r\n return stroke.map((layer) => ({ ...layer, startCap: undefined, endCap: undefined }));\r\n}\r\n\r\nexport interface LabelStyle {\r\n fontSize: number;\r\n fontFamily: string;\r\n color: Color;\r\n}\r\n\r\nexport interface Label {\r\n text: string;\r\n /** Where the label's box is anchored, in pixels. */\r\n at: Vector2;\r\n align: \"left\" | \"center\" | \"right\";\r\n}\r\n\r\n/** How wide a label's box is, in ems: room for a long number, so alignment is by the box's edge. */\r\nconst LABEL_BOX_EM = 8;\r\n\r\n/** A label written between dollar signs is a formula: `$\\\\frac{\\\\pi}{2}$`. */\r\nconst FORMULA = /^\\$([\\s\\S]+)\\$$/;\r\n\r\n/** Ask the host for MathJax when any of `texts` is a formula, so it is there before the node is laid out. */\r\nexport function declareFormulas(assets: AssetScope, texts: readonly string[]): void {\r\n if (texts.some((text) => FORMULA.test(text.trim()))) assets.loader(MATHJAX_LOADER, loadMathJax, { gate: \"layout\" });\r\n}\r\n\r\n/** What draws `labels`: text in the scene's face, and a typeset formula for each one written as such. */\r\nexport function drawLabels(labels: readonly Label[], style: LabelStyle): Graphics2D[] {\r\n const out: Graphics2D[] = [];\r\n const fill = Fills.color(style.color);\r\n const text = new Graphics2D();\r\n const width = style.fontSize * LABEL_BOX_EM;\r\n let written = false;\r\n for (const label of labels) {\r\n const formula = FORMULA.exec(label.text.trim());\r\n const glyphs = formula ? typeset(formula[1], label, style.fontSize) : null;\r\n if (glyphs) {\r\n for (const glyph of glyphs) out.push(glyph.fill(fill));\r\n continue;\r\n }\r\n const { at, align } = label;\r\n written = true;\r\n text.text({\r\n text: label.text,\r\n fontSize: style.fontSize,\r\n // An empty family is left out, so the label takes the scene's own face.\r\n ...(style.fontFamily === \"\" ? {} : { fontFamily: style.fontFamily }),\r\n wrap: false,\r\n width,\r\n textAlign: align,\r\n x: align === \"center\" ? at.x : align === \"right\" ? at.x - width / 2 : at.x + width / 2,\r\n y: at.y,\r\n });\r\n }\r\n if (written) out.push(text.fill(fill));\r\n return out;\r\n}\r\n\r\n// A formula's glyphs with its box anchored at the label's point; `null` for one that will not typeset, which is then\r\n// drawn as written, and nothing at all while MathJax is still on its way: its source is not a stand-in for it.\r\nfunction typeset(source: string, { at, align }: Label, fontSize: number): Graphics2D[] | null {\r\n let formula: ReturnType<typeof buildLatexPath>;\r\n try {\r\n formula = buildLatexPath(source, fontSize);\r\n } catch (error) {\r\n return error instanceof LatexNotLoaded ? [] : null;\r\n }\r\n const [minX, minY, maxX, maxY] = formula.bounds;\r\n const dx = at.x + (align === \"left\" ? formula.width / 2 : align === \"right\" ? -formula.width / 2 : 0);\r\n // Glyph paths are y-down; the frame whose centre lands on the node's is shifted the other way.\r\n const frame: [number, number, number, number] = [minX - dx, minY + at.y, maxX - dx, maxY + at.y];\r\n return formula.tokens.map((token) => new Graphics2D().path({ data: toPathString(token.path), centerBounds: frame }));\r\n}\r\n\r\n/** Whether a mark `u` of the way along an axis is inside the part of it drawn so far. */\r\nexport function drawn(u: number, start: number, end: number): boolean {\r\n return u >= start - 1e-9 && u <= end + 1e-9;\r\n}\r\n\r\n/** How far along `range` a value is, 0 to 1, by pixel distance. */\r\nexport function along(at: Vector2, from: Vector2, to: Vector2): number {\r\n const dx = to.x - from.x;\r\n const dy = to.y - from.y;\r\n const length = dx * dx + dy * dy;\r\n return length === 0 ? 0 : ((at.x - from.x) * dx + (at.y - from.y) * dy) / length;\r\n}\r\n\r\nexport function lerpInterval(from: Interval, to: Interval, t: number): Interval {\r\n return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];\r\n}\r\n\r\nexport function readInterval(value: Interval | undefined, previous?: Interval): Interval {\r\n const [min, max] = Array.isArray(value) ? value : (previous ?? [0, 1]);\r\n return [Number(min), Number(max)];\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"furniture.js","sourceRoot":"","sources":["../../src/kit/furniture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAA+E,MAAM,mBAAmB,CAAC;AACjJ,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAG9F,+FAA+F;AAE/F,+FAA+F;AAC/F,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AACpC,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AAEpC,2EAA2E;AAC3E,MAAM,UAAU,WAAW,CAAC,MAAwB;IAChD,OAAO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AG,CAAC,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { Fills, Graphics2D, toPathString, type AssetScope, type Color, type Loader, type StrokeResolved, type Vector2 } from \"@motionscript/sdk\";\r\nimport { buildLatexPath, LatexNotLoaded, loadMathJax, MATHJAX_LOADER } from \"../tex/geometry\";\r\nimport type { Interval } from \"./coords\";\r\n\r\n/** Shared drawing for the systems' own furniture: axis lines, tick marks and their numbers. */\r\n\r\n/** What a system draws its axes and numbers in, and a plot its curve, until told otherwise. */\r\nexport const AXIS_COLOR = \"#9ca3af\";\r\nexport const PLOT_COLOR = \"#58a6ff\";\r\n\r\n/** A stroke without end markers: an axis wears a tip, its ticks do not. */\r\nexport function withoutTips(stroke: StrokeResolved[]): StrokeResolved[] {\r\n return stroke.map((layer) => ({ ...layer, startCap: undefined, endCap: undefined }));\r\n}\r\n\r\nexport interface LabelStyle {\r\n fontSize: number;\r\n fontFamily: string;\r\n color: Color;\r\n}\r\n\r\nexport interface Label {\r\n text: string;\r\n /** Where the label's box is anchored, in pixels. */\r\n at: Vector2;\r\n align: \"left\" | \"center\" | \"right\";\r\n}\r\n\r\n/** How wide a label's box is, in ems: room for a long number, so alignment is by the box's edge. */\r\nconst LABEL_BOX_EM = 8;\r\n\r\n/** A label written between dollar signs is a formula: `$\\\\frac{\\\\pi}{2}$`. */\r\nconst FORMULA = /^\\$([\\s\\S]+)\\$$/;\r\n\r\n/** Ask the host for MathJax when any of `texts` is a formula, so it is there before the node is laid out. */\r\nexport function declareFormulas(assets: AssetScope, texts: readonly string[]): void {\r\n if (texts.some((text) => FORMULA.test(text.trim()))) assets.loader(MATHJAX_LOADER, loadMathJax, { gate: \"layout\" });\r\n}\r\n\r\n/** {@link declareFormulas}, for a component's `load`. */\r\nexport function loadFormulas(loader: Loader, texts: readonly string[]): void {\r\n if (texts.some((text) => FORMULA.test(text.trim()))) loader.task(MATHJAX_LOADER, loadMathJax, { before: \"layout\" });\r\n}\r\n\r\n/** What draws `labels`: text in the scene's face, and a typeset formula for each one written as such. */\r\nexport function drawLabels(labels: readonly Label[], style: LabelStyle): Graphics2D[] {\r\n const out: Graphics2D[] = [];\r\n const fill = Fills.color(style.color);\r\n const text = new Graphics2D();\r\n const width = style.fontSize * LABEL_BOX_EM;\r\n let written = false;\r\n for (const label of labels) {\r\n const formula = FORMULA.exec(label.text.trim());\r\n const glyphs = formula ? typeset(formula[1], label, style.fontSize) : null;\r\n if (glyphs) {\r\n for (const glyph of glyphs) out.push(glyph.fill(fill));\r\n continue;\r\n }\r\n const { at, align } = label;\r\n written = true;\r\n text.text({\r\n text: label.text,\r\n fontSize: style.fontSize,\r\n // An empty family is left out, so the label takes the scene's own face.\r\n ...(style.fontFamily === \"\" ? {} : { fontFamily: style.fontFamily }),\r\n wrap: false,\r\n width,\r\n textAlign: align,\r\n x: align === \"center\" ? at.x : align === \"right\" ? at.x - width / 2 : at.x + width / 2,\r\n y: at.y,\r\n });\r\n }\r\n if (written) out.push(text.fill(fill));\r\n return out;\r\n}\r\n\r\n// A formula's glyphs with its box anchored at the label's point; `null` for one that will not typeset, which is then\r\n// drawn as written, and nothing at all while MathJax is still on its way: its source is not a stand-in for it.\r\nfunction typeset(source: string, { at, align }: Label, fontSize: number): Graphics2D[] | null {\r\n let formula: ReturnType<typeof buildLatexPath>;\r\n try {\r\n formula = buildLatexPath(source, fontSize);\r\n } catch (error) {\r\n return error instanceof LatexNotLoaded ? [] : null;\r\n }\r\n const [minX, minY, maxX, maxY] = formula.bounds;\r\n const dx = at.x + (align === \"left\" ? formula.width / 2 : align === \"right\" ? -formula.width / 2 : 0);\r\n // Glyph paths are y-down; the frame whose centre lands on the node's is shifted the other way.\r\n const frame: [number, number, number, number] = [minX - dx, minY + at.y, maxX - dx, maxY + at.y];\r\n return formula.tokens.map((token) => new Graphics2D().path({ data: toPathString(token.path), centerBounds: frame }));\r\n}\r\n\r\n/** Whether a mark `u` of the way along an axis is inside the part of it drawn so far. */\r\nexport function drawn(u: number, start: number, end: number): boolean {\r\n return u >= start - 1e-9 && u <= end + 1e-9;\r\n}\r\n\r\n/** How far along `range` a value is, 0 to 1, by pixel distance. */\r\nexport function along(at: Vector2, from: Vector2, to: Vector2): number {\r\n const dx = to.x - from.x;\r\n const dy = to.y - from.y;\r\n const length = dx * dx + dy * dy;\r\n return length === 0 ? 0 : ((at.x - from.x) * dx + (at.y - from.y) * dy) / length;\r\n}\r\n\r\nexport function lerpInterval(from: Interval, to: Interval, t: number): Interval {\r\n return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];\r\n}\r\n\r\nexport function readInterval(value: Interval | undefined, previous?: Interval): Interval {\r\n const [min, max] = Array.isArray(value) ? value : (previous ?? [0, 1]);\r\n return [Number(min), Number(max)];\r\n}\r\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ChildView, type NodeView, type Context as _Context } from "@motionscript/sdk";
|
|
2
|
+
import { type CoordinateMap } from "./coords.js";
|
|
3
|
+
import { type CurveValues } from "./curve.js";
|
|
4
|
+
/**
|
|
5
|
+
* What a coordinate system hands the plots and marks inside it: the map it was
|
|
6
|
+
* last laid out on, the curves it holds by id, and, under a plot, that plot.
|
|
7
|
+
* Inherited once, so it is a live object the system's layout keeps current.
|
|
8
|
+
*/
|
|
9
|
+
export interface GraphPlane {
|
|
10
|
+
readonly map: CoordinateMap;
|
|
11
|
+
readonly curves: ReadonlyMap<string, CurveValues>;
|
|
12
|
+
/** The curve a mark rides when it names none: the plot it sits in. */
|
|
13
|
+
readonly enclosing: CurveValues | null;
|
|
14
|
+
}
|
|
15
|
+
/** The plane of the nearest coordinate system: what a plot is laid out on. */
|
|
16
|
+
export declare const SYSTEM: _Context<GraphPlane | null>;
|
|
17
|
+
/** The plane under a plot: the system's, riding that plot. */
|
|
18
|
+
export declare const PLOT: _Context<GraphPlane | null>;
|
|
19
|
+
/** A plot's plane: the system it sits in, `null` outside one. */
|
|
20
|
+
export declare const SYSTEM_ENTRY: import("@motionscript/sdk").Type<GraphPlane | null, GraphPlane | null, true>;
|
|
21
|
+
/** A mark's plane: the plot or the system that lays it out, `null` outside both. */
|
|
22
|
+
export declare const PLANE_ENTRY: import("@motionscript/sdk").Type<GraphPlane | null, GraphPlane | null, true>;
|
|
23
|
+
/** A reference to the plot a mark reads, by id: a host offers the plots. */
|
|
24
|
+
export declare const PLOT_REF: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
25
|
+
declare class SystemPlane implements GraphPlane {
|
|
26
|
+
map: CoordinateMap;
|
|
27
|
+
curves: ReadonlyMap<string, CurveValues>;
|
|
28
|
+
readonly enclosing: null;
|
|
29
|
+
}
|
|
30
|
+
/** The plane a system provides, one per system: its `layout` writes the map and the curves into it. */
|
|
31
|
+
export declare function systemPlane(state: object): SystemPlane;
|
|
32
|
+
/** Lay `plane` out on `map`, holding the curves among `children`. */
|
|
33
|
+
export declare function settle(plane: SystemPlane, map: CoordinateMap, children: readonly ChildView[]): void;
|
|
34
|
+
/** The plane a plot provides the marks inside it, one per plot and system. */
|
|
35
|
+
export declare function plotPlane(plot: CurveValues, parent: GraphPlane | null): GraphPlane;
|
|
36
|
+
/**
|
|
37
|
+
* The curve a mark reads: the one `on` names in its system, or, naming none or
|
|
38
|
+
* one the system does not hold, the plot it sits in. `on` as the mark's own
|
|
39
|
+
* fields read a reference (a view) or its holder's layout does (an id). Outside
|
|
40
|
+
* any system a named curve is read wherever it is.
|
|
41
|
+
*/
|
|
42
|
+
export declare function curveFor(plane: GraphPlane | null, on: unknown, enclosing?: boolean): CurveValues | null;
|
|
43
|
+
/** The id a reference holds, read as an id or as a view of the node. */
|
|
44
|
+
export declare function refId(on: unknown): string;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/kit/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAA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CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,SAAS,UAAO,GAAG,WAAW,GAAG,IAAI,CAIpG;AAED,wEAAwE;AACxE,wBAAgB,KAAK,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,CAIzC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createContext, Types, } from "@motionscript/sdk";
|
|
2
|
+
import { PIXEL_MAP } from "./coords.js";
|
|
3
|
+
import { CURVE_KEYS, isCurve } from "./curve.js";
|
|
4
|
+
/** The plane of the nearest coordinate system: what a plot is laid out on. */
|
|
5
|
+
export const SYSTEM = createContext(null, "mathSystem");
|
|
6
|
+
/** The plane under a plot: the system's, riding that plot. */
|
|
7
|
+
export const PLOT = createContext(null, "mathPlot");
|
|
8
|
+
/** A plot's plane: the system it sits in, `null` outside one. */
|
|
9
|
+
export const SYSTEM_ENTRY = Types.custom(null, {
|
|
10
|
+
private: true,
|
|
11
|
+
inherit: (use) => use(SYSTEM),
|
|
12
|
+
});
|
|
13
|
+
/** A mark's plane: the plot or the system that lays it out, `null` outside both. */
|
|
14
|
+
export const PLANE_ENTRY = Types.custom(null, {
|
|
15
|
+
private: true,
|
|
16
|
+
inherit: (use) => use(PLOT) ?? use(SYSTEM),
|
|
17
|
+
});
|
|
18
|
+
/** A reference to the plot a mark reads, by id: a host offers the plots. */
|
|
19
|
+
export const PLOT_REF = Types.custom("", { kind: "nodeRef", nodeTypes: ["functionPlot"], animatable: false });
|
|
20
|
+
const NO_CURVES = new Map();
|
|
21
|
+
class SystemPlane {
|
|
22
|
+
map = PIXEL_MAP;
|
|
23
|
+
curves = NO_CURVES;
|
|
24
|
+
enclosing = null;
|
|
25
|
+
}
|
|
26
|
+
class PlotPlane {
|
|
27
|
+
parent;
|
|
28
|
+
enclosing;
|
|
29
|
+
constructor(parent, enclosing) {
|
|
30
|
+
this.parent = parent;
|
|
31
|
+
this.enclosing = enclosing;
|
|
32
|
+
}
|
|
33
|
+
get map() {
|
|
34
|
+
return this.parent?.map ?? PIXEL_MAP;
|
|
35
|
+
}
|
|
36
|
+
get curves() {
|
|
37
|
+
return this.parent?.curves ?? NO_CURVES;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const systems = new WeakMap();
|
|
41
|
+
const plots = new WeakMap();
|
|
42
|
+
/** The plane a system provides, one per system: its `layout` writes the map and the curves into it. */
|
|
43
|
+
export function systemPlane(state) {
|
|
44
|
+
let plane = systems.get(state);
|
|
45
|
+
if (!plane)
|
|
46
|
+
systems.set(state, (plane = new SystemPlane()));
|
|
47
|
+
return plane;
|
|
48
|
+
}
|
|
49
|
+
/** Lay `plane` out on `map`, holding the curves among `children`. */
|
|
50
|
+
export function settle(plane, map, children) {
|
|
51
|
+
plane.map = map;
|
|
52
|
+
const curves = new Map();
|
|
53
|
+
collectCurves(children, curves);
|
|
54
|
+
plane.curves = curves;
|
|
55
|
+
}
|
|
56
|
+
/** The plane a plot provides the marks inside it, one per plot and system. */
|
|
57
|
+
export function plotPlane(plot, parent) {
|
|
58
|
+
let plane = plots.get(plot);
|
|
59
|
+
if (!plane || plane.parent !== parent)
|
|
60
|
+
plots.set(plot, (plane = new PlotPlane(parent, plot)));
|
|
61
|
+
return plane;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The curve a mark reads: the one `on` names in its system, or, naming none or
|
|
65
|
+
* one the system does not hold, the plot it sits in. `on` as the mark's own
|
|
66
|
+
* fields read a reference (a view) or its holder's layout does (an id). Outside
|
|
67
|
+
* any system a named curve is read wherever it is.
|
|
68
|
+
*/
|
|
69
|
+
export function curveFor(plane, on, enclosing = true) {
|
|
70
|
+
if (!plane)
|
|
71
|
+
return isCurve(on) ? on.state : null;
|
|
72
|
+
const id = refId(on);
|
|
73
|
+
return (id === "" ? undefined : plane.curves.get(id)) ?? (enclosing ? plane.enclosing : null);
|
|
74
|
+
}
|
|
75
|
+
/** The id a reference holds, read as an id or as a view of the node. */
|
|
76
|
+
export function refId(on) {
|
|
77
|
+
if (typeof on === "string")
|
|
78
|
+
return on;
|
|
79
|
+
if (typeof on === "object" && on !== null && typeof on.id === "string")
|
|
80
|
+
return on.id;
|
|
81
|
+
return "";
|
|
82
|
+
}
|
|
83
|
+
function collectCurves(children, into) {
|
|
84
|
+
for (const child of children) {
|
|
85
|
+
if (child.id !== "" && CURVE_KEYS.includes(child.key))
|
|
86
|
+
into.set(child.id, child.state);
|
|
87
|
+
collectCurves(child.children, into);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/kit/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,KAAK,GAMR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAsB,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAoB,MAAM,SAAS,CAAC;AAchE,8EAA8E;AAC9E,MAAM,CAAC,MAAM,MAAM,GAAG,aAAa,CAAoB,IAAI,EAAE,YAAY,CAAC,CAAC;AAC3E,8DAA8D;AAC9D,MAAM,CAAC,MAAM,IAAI,GAAG,aAAa,CAAoB,IAAI,EAAE,UAAU,CAAC,CAAC;AAIvE,iEAAiE;AACjE,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAkD,IAAI,EAAE;IAC5F,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC;CAChC,CAAC,CAAC;AAEH,oFAAoF;AACpF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAkD,IAAI,EAAE;IAC3F,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAA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CAAC,EAAE,CAAC;IAC/H,OAAO,EAAE,CAAC;AACd,CAAC;AAED,SAAS,aAAa,CAAC,QAA8B,EAAE,IAA8B;IACjF,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,KAA+B,CAAC,CAAC;QACjH,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;AACL,CAAC","sourcesContent":["import {\r\n createContext,\r\n Types,\r\n type ChildView,\r\n type EntryOptions,\r\n type NodeView,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Context as _Context,\r\n} from \"@motionscript/sdk\";\r\nimport { PIXEL_MAP, type CoordinateMap } from \"./coords\";\r\nimport { CURVE_KEYS, isCurve, type CurveValues } from \"./curve\";\r\n\r\n/**\r\n * What a coordinate system hands the plots and marks inside it: the map it was\r\n * last laid out on, the curves it holds by id, and, under a plot, that plot.\r\n * Inherited once, so it is a live object the system's layout keeps current.\r\n */\r\nexport interface GraphPlane {\r\n readonly map: CoordinateMap;\r\n readonly curves: ReadonlyMap<string, CurveValues>;\r\n /** The curve a mark rides when it names none: the plot it sits in. */\r\n readonly enclosing: CurveValues | null;\r\n}\r\n\r\n/** The plane of the nearest coordinate system: what a plot is laid out on. */\r\nexport const SYSTEM = createContext<GraphPlane | null>(null, \"mathSystem\");\r\n/** The plane under a plot: the system's, riding that plot. */\r\nexport const PLOT = createContext<GraphPlane | null>(null, \"mathPlot\");\r\n\r\ntype Inherited = { readonly private: true };\r\n\r\n/** A plot's plane: the system it sits in, `null` outside one. */\r\nexport const SYSTEM_ENTRY = Types.custom<GraphPlane | null, GraphPlane | null, Inherited>(null, {\r\n private: true,\r\n inherit: (use) => use(SYSTEM),\r\n});\r\n\r\n/** A mark's plane: the plot or the system that lays it out, `null` outside both. */\r\nexport const PLANE_ENTRY = Types.custom<GraphPlane | null, GraphPlane | null, Inherited>(null, {\r\n private: true,\r\n inherit: (use) => use(PLOT) ?? use(SYSTEM),\r\n});\r\n\r\n/** A reference to the plot a mark reads, by id: a host offers the plots. */\r\nexport const PLOT_REF = Types.custom<string, NodeView | null, EntryOptions & { readonly nodeTypes: readonly string[] }>(\"\", { kind: \"nodeRef\", nodeTypes: [\"functionPlot\"], animatable: false });\r\n\r\nconst NO_CURVES: ReadonlyMap<string, CurveValues> = new Map();\r\n\r\nclass SystemPlane implements GraphPlane {\r\n map: CoordinateMap = PIXEL_MAP;\r\n curves: ReadonlyMap<string, CurveValues> = NO_CURVES;\r\n readonly enclosing = null;\r\n}\r\n\r\nclass PlotPlane implements GraphPlane {\r\n constructor(readonly parent: GraphPlane | null, readonly enclosing: CurveValues) { }\r\n\r\n get map(): CoordinateMap {\r\n return this.parent?.map ?? PIXEL_MAP;\r\n }\r\n\r\n get curves(): ReadonlyMap<string, CurveValues> {\r\n return this.parent?.curves ?? NO_CURVES;\r\n }\r\n}\r\n\r\nconst systems = new WeakMap<object, SystemPlane>();\r\nconst plots = new WeakMap<object, PlotPlane>();\r\n\r\n/** The plane a system provides, one per system: its `layout` writes the map and the curves into it. */\r\nexport function systemPlane(state: object): SystemPlane {\r\n let plane = systems.get(state);\r\n if (!plane) systems.set(state, (plane = new SystemPlane()));\r\n return plane;\r\n}\r\n\r\n/** Lay `plane` out on `map`, holding the curves among `children`. */\r\nexport function settle(plane: SystemPlane, map: CoordinateMap, children: readonly ChildView[]): void {\r\n plane.map = map;\r\n const curves = new Map<string, CurveValues>();\r\n collectCurves(children, curves);\r\n plane.curves = curves;\r\n}\r\n\r\n/** The plane a plot provides the marks inside it, one per plot and system. */\r\nexport function plotPlane(plot: CurveValues, parent: GraphPlane | null): GraphPlane {\r\n let plane = plots.get(plot);\r\n if (!plane || plane.parent !== parent) plots.set(plot, (plane = new PlotPlane(parent, plot)));\r\n return plane;\r\n}\r\n\r\n/**\r\n * The curve a mark reads: the one `on` names in its system, or, naming none or\r\n * one the system does not hold, the plot it sits in. `on` as the mark's own\r\n * fields read a reference (a view) or its holder's layout does (an id). Outside\r\n * any system a named curve is read wherever it is.\r\n */\r\nexport function curveFor(plane: GraphPlane | null, on: unknown, enclosing = true): CurveValues | null {\r\n if (!plane) return isCurve(on) ? on.state : null;\r\n const id = refId(on);\r\n return (id === \"\" ? undefined : plane.curves.get(id)) ?? (enclosing ? plane.enclosing : null);\r\n}\r\n\r\n/** The id a reference holds, read as an id or as a view of the node. */\r\nexport function refId(on: unknown): string {\r\n if (typeof on === \"string\") return on;\r\n if (typeof on === \"object\" && on !== null && typeof (on as { id?: unknown }).id === \"string\") return (on as { id: string }).id;\r\n return \"\";\r\n}\r\n\r\nfunction collectCurves(children: readonly ChildView[], into: Map<string, CurveValues>): void {\r\n for (const child of children) {\r\n if (child.id !== \"\" && CURVE_KEYS.includes(child.key)) into.set(child.id, child.state as unknown as CurveValues);\r\n collectCurves(child.children, into);\r\n }\r\n}\r\n"]}
|