@motionscript/math 0.1.0 → 0.1.1-alpha.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/CHANGELOG.md +19 -0
- package/dist/annotate/angle-mark.d.ts +4 -14
- package/dist/annotate/angle-mark.d.ts.map +1 -1
- package/dist/annotate/angle-mark.js +2 -1
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +4 -16
- package/dist/annotate/curly-brace.d.ts.map +1 -1
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +0 -5
- package/dist/annotate/emphasis-mark.d.ts.map +1 -1
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/chunk-FZ2YBTPL.js +2 -0
- package/dist/browser/chunks/chunk-FZ2YBTPL.js.map +7 -0
- package/dist/browser/chunks/chunk-T42HWKBC.js +2 -0
- package/dist/browser/chunks/chunk-T42HWKBC.js.map +7 -0
- package/dist/browser/chunks/{mathjax-WV55AC2P.js → mathjax-SOM6RSPV.js} +1 -1
- package/dist/browser/chunks/{mathjax-WV55AC2P.js.map → mathjax-SOM6RSPV.js.map} +2 -2
- 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/engine.d.ts +3 -4
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +3 -4
- package/dist/engine.js.map +1 -1
- package/dist/kit/cache.d.ts +10 -21
- package/dist/kit/cache.d.ts.map +1 -1
- package/dist/kit/cache.js +33 -24
- package/dist/kit/cache.js.map +1 -1
- package/dist/kit/component.d.ts +5 -14
- package/dist/kit/component.d.ts.map +1 -1
- package/dist/kit/component.js +1 -8
- package/dist/kit/component.js.map +1 -1
- package/dist/kit/coords.d.ts +1 -1
- package/dist/kit/coords.d.ts.map +1 -1
- package/dist/kit/coords.js +2 -1
- package/dist/kit/coords.js.map +1 -1
- package/dist/kit/curve.d.ts +1 -5
- package/dist/kit/curve.d.ts.map +1 -1
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/equation.d.ts +10 -30
- package/dist/kit/equation.d.ts.map +1 -1
- package/dist/kit/equation.js +9 -44
- package/dist/kit/equation.js.map +1 -1
- package/dist/kit/equation3d.d.ts +3 -3
- package/dist/kit/equation3d.d.ts.map +1 -1
- package/dist/kit/equation3d.js +27 -59
- package/dist/kit/equation3d.js.map +1 -1
- package/dist/kit/expression.d.ts +7 -7
- package/dist/kit/expression.d.ts.map +1 -1
- package/dist/kit/expression.js +18 -17
- package/dist/kit/expression.js.map +1 -1
- package/dist/kit/field-mark.d.ts +0 -7
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/field.d.ts +2 -2
- package/dist/kit/field.d.ts.map +1 -1
- package/dist/kit/field.js +11 -31
- package/dist/kit/field.js.map +1 -1
- package/dist/kit/follow.d.ts +3 -10
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js +5 -11
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.d.ts +2 -1
- package/dist/kit/furniture.d.ts.map +1 -1
- package/dist/kit/furniture.js +6 -3
- package/dist/kit/furniture.js.map +1 -1
- package/dist/kit/geometry.d.ts +1 -0
- package/dist/kit/geometry.d.ts.map +1 -1
- package/dist/kit/geometry.js +3 -0
- package/dist/kit/geometry.js.map +1 -1
- package/dist/kit/mark.d.ts +4 -10
- package/dist/kit/mark.d.ts.map +1 -1
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/place.d.ts +3 -5
- package/dist/kit/place.d.ts.map +1 -1
- package/dist/kit/place.js +3 -5
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/sampler.d.ts +0 -5
- package/dist/kit/sampler.d.ts.map +1 -1
- package/dist/kit/sampler.js.map +1 -1
- package/dist/kit/system.d.ts +0 -1
- package/dist/kit/system.d.ts.map +1 -1
- package/dist/kit/system.js +3 -10
- package/dist/kit/system.js.map +1 -1
- package/dist/marks/curve-area.d.ts +2 -12
- package/dist/marks/curve-area.d.ts.map +1 -1
- package/dist/marks/curve-area.js +4 -9
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +1 -5
- package/dist/marks/drop-lines.d.ts.map +1 -1
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +4 -13
- package/dist/marks/plot-point.d.ts.map +1 -1
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +1 -7
- package/dist/marks/riemann-sum.d.ts.map +1 -1
- package/dist/marks/riemann-sum.js +2 -2
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +2 -12
- package/dist/marks/tangent-line.d.ts.map +1 -1
- package/dist/marks/tangent-line.js +1 -5
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +2 -11
- package/dist/marks/vector-arrow.d.ts.map +1 -1
- package/dist/marks/vector-arrow.js +3 -6
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.d.ts +1 -12
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +1 -6
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js +1 -5
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.d.ts +1 -6
- package/dist/plots/points-plot.d.ts.map +1 -1
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.d.ts +0 -7
- package/dist/plots/stream-lines.d.ts.map +1 -1
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.d.ts +1 -12
- package/dist/plots/traced-path.d.ts.map +1 -1
- package/dist/plots/traced-path.js +1 -6
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.d.ts +1 -10
- package/dist/plots/vector-field.d.ts.map +1 -1
- package/dist/plots/vector-field.js +3 -6
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/network-graph.d.ts +15 -34
- package/dist/structures/network-graph.d.ts.map +1 -1
- package/dist/structures/network-graph.js +2 -5
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.d.ts +8 -22
- package/dist/structures/sample-space.d.ts.map +1 -1
- package/dist/structures/sample-space.js +3 -5
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts +0 -1
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js +3 -4
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.d.ts +7 -22
- package/dist/systems/number-line.d.ts.map +1 -1
- package/dist/systems/number-line.js +2 -2
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.d.ts +12 -27
- package/dist/systems/number-plane.d.ts.map +1 -1
- package/dist/systems/number-plane.js +1 -7
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.d.ts +11 -26
- package/dist/systems/polar-plane.d.ts.map +1 -1
- package/dist/systems/polar-plane.js +7 -10
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/geometry.d.ts +5 -24
- package/dist/tex/geometry.d.ts.map +1 -1
- package/dist/tex/geometry.js +19 -90
- package/dist/tex/geometry.js.map +1 -1
- package/dist/tex/mathjax.d.ts +0 -13
- package/dist/tex/mathjax.d.ts.map +1 -1
- package/dist/tex/mathjax.js +4 -24
- package/dist/tex/mathjax.js.map +1 -1
- package/dist/tex/matrix.d.ts +1 -10
- package/dist/tex/matrix.d.ts.map +1 -1
- package/dist/tex/matrix.js +1 -5
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/tween.d.ts +9 -30
- package/dist/tex/tween.d.ts.map +1 -1
- package/dist/tex/tween.js +19 -67
- package/dist/tex/tween.js.map +1 -1
- package/dist/tex/typeset.d.ts +2 -23
- package/dist/tex/typeset.d.ts.map +1 -1
- package/dist/tex/typeset.js +4 -30
- package/dist/tex/typeset.js.map +1 -1
- package/dist/three/axes3d.d.ts +32 -62
- package/dist/three/axes3d.d.ts.map +1 -1
- package/dist/three/axes3d.js +5 -13
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +4 -15
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js.map +1 -1
- package/dist/three/plot-point3d.d.ts +7 -14
- package/dist/three/plot-point3d.d.ts.map +1 -1
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.d.ts +3 -8
- package/dist/three/space.d.ts.map +1 -1
- package/dist/three/space.js +1 -8
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +9 -23
- package/dist/three/surface-plot3d.d.ts.map +1 -1
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +1 -7
- package/dist/three/vector-arrow3d.d.ts.map +1 -1
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +4 -4
- package/src/annotate/angle-mark.ts +4 -14
- package/src/annotate/curly-brace.ts +2 -14
- package/src/annotate/emphasis-mark.ts +1 -6
- package/src/engine.ts +3 -4
- package/src/kit/cache.ts +33 -25
- package/src/kit/component.ts +5 -19
- package/src/kit/coords.ts +2 -2
- package/src/kit/curve.ts +1 -5
- package/src/kit/equation.ts +12 -50
- package/src/kit/equation3d.ts +23 -59
- package/src/kit/expression.ts +18 -23
- package/src/kit/field-mark.ts +1 -7
- package/src/kit/field.ts +10 -26
- package/src/kit/follow.ts +5 -13
- package/src/kit/furniture.ts +7 -4
- package/src/kit/geometry.ts +4 -0
- package/src/kit/mark.ts +4 -11
- package/src/kit/place.ts +3 -5
- package/src/kit/sampler.ts +0 -6
- package/src/kit/system.ts +3 -12
- package/src/marks/curve-area.ts +3 -16
- package/src/marks/drop-lines.ts +0 -6
- package/src/marks/plot-point.ts +2 -12
- package/src/marks/riemann-sum.ts +2 -10
- package/src/marks/tangent-line.ts +1 -13
- package/src/marks/vector-arrow.ts +3 -13
- package/src/nodes.ts +1 -12
- package/src/plots/function-plot.ts +1 -6
- package/src/plots/points-plot.ts +0 -7
- package/src/plots/stream-lines.ts +1 -8
- package/src/plots/traced-path.ts +2 -13
- package/src/plots/vector-field.ts +4 -12
- package/src/structures/network-graph.ts +6 -25
- package/src/structures/sample-space.ts +5 -20
- package/src/systems/axes2d.ts +3 -6
- package/src/systems/number-line.ts +4 -20
- package/src/systems/number-plane.ts +4 -19
- package/src/systems/polar-plane.ts +11 -25
- package/src/tex/geometry.ts +24 -126
- package/src/tex/mathjax.ts +4 -26
- package/src/tex/matrix.ts +1 -11
- package/src/tex/tween.ts +21 -75
- package/src/tex/typeset.ts +4 -37
- package/src/three/axes3d.ts +7 -42
- package/src/three/curve-plot3d.ts +0 -12
- package/src/three/plot-point3d.ts +0 -10
- package/src/three/space.ts +2 -11
- package/src/three/surface-plot3d.ts +0 -15
- package/src/three/vector-arrow3d.ts +0 -8
- package/dist/browser/chunks/chunk-IRZCG6PM.js +0 -2
- package/dist/browser/chunks/chunk-IRZCG6PM.js.map +0 -7
- package/dist/browser/chunks/chunk-WMVW6ZIV.js +0 -2
- package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +0 -7
- package/dist/kit/withdrawn.d.ts +0 -9
- package/dist/kit/withdrawn.d.ts.map +0 -1
- package/dist/kit/withdrawn.js +0 -9
- package/dist/kit/withdrawn.js.map +0 -1
- package/src/kit/withdrawn.ts +0 -8
package/dist/tex/tween.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { lerpNumber } from "@motionscript/sdk";
|
|
2
|
-
/** The coordinate pairs a `PathCommand` can carry, as (x, y) field names. */
|
|
3
2
|
const POINT_FIELDS = [["x", "y"], ["x1", "y1"], ["x2", "y2"]];
|
|
4
|
-
/**
|
|
5
|
-
* Compute the centroid of a token's path for position-based interpolation.
|
|
6
|
-
*/
|
|
7
3
|
function centroid(path) {
|
|
8
4
|
let sx = 0, sy = 0, n = 0;
|
|
9
5
|
for (const cmd of path) {
|
|
@@ -15,13 +11,7 @@ function centroid(path) {
|
|
|
15
11
|
}
|
|
16
12
|
return n > 0 ? { x: sx / n, y: sy / n } : { x: 0, y: 0 };
|
|
17
13
|
}
|
|
18
|
-
/**
|
|
19
|
-
* A glyph's on-screen extent, as the diagonal of its control-point bbox.
|
|
20
|
-
*
|
|
21
|
-
* Only ever used as a *ratio* between the two ends of a match, so the fact that
|
|
22
|
-
* control points overshoot the true outline doesn't matter: both ends overshoot
|
|
23
|
-
* by the same proportion, because they are the same outline.
|
|
24
|
-
*/
|
|
14
|
+
/** The diagonal of a path's control-point bbox: only ever a ratio between the two ends of a match, so the control-point overshoot cancels. */
|
|
25
15
|
function extent(path) {
|
|
26
16
|
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
27
17
|
for (const cmd of path) {
|
|
@@ -44,14 +34,9 @@ function extent(path) {
|
|
|
44
34
|
return Math.hypot(maxX - minX, maxY - minY);
|
|
45
35
|
}
|
|
46
36
|
/**
|
|
47
|
-
* Whether two paths
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* For a matched pair this is the overwhelmingly common case, and not by luck.
|
|
51
|
-
* Tokens are matched on the character their MathJax glyph id decodes to, and
|
|
52
|
-
* that id *is* the key into the `<defs>` dictionary — so the same character in
|
|
53
|
-
* two formulas is the same outline, emitted twice under two different
|
|
54
|
-
* transforms. Same commands, different numbers.
|
|
37
|
+
* Whether two paths share command count and types. A matched pair almost always
|
|
38
|
+
* does: a character's glyph id keys one outline in `<defs>`, emitted under two
|
|
39
|
+
* transforms.
|
|
55
40
|
*/
|
|
56
41
|
function isPointwiseCompatible(from, to) {
|
|
57
42
|
if (from.length !== to.length)
|
|
@@ -63,13 +48,9 @@ function isPointwiseCompatible(from, to) {
|
|
|
63
48
|
return true;
|
|
64
49
|
}
|
|
65
50
|
/**
|
|
66
|
-
* Lerp two structurally identical paths point by point.
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* what a matched glyph is — this is exact at both ends *and* correct in
|
|
70
|
-
* between: `(1-t)·A·q + t·B·q = ((1-t)A + tB)·q`, and a blend of two
|
|
71
|
-
* uniform-scale-plus-translate transforms is another one. The intermediate is a
|
|
72
|
-
* properly formed glyph at an intermediate size, not a smeared one.
|
|
51
|
+
* Lerp two structurally identical paths point by point. Matched glyphs are one
|
|
52
|
+
* outline under two uniform-scale-plus-translate transforms, and a blend of
|
|
53
|
+
* those is another, so the in-between is a well-formed glyph at an in-between size.
|
|
73
54
|
*/
|
|
74
55
|
function lerpPath(from, to, t) {
|
|
75
56
|
const out = new Array(from.length);
|
|
@@ -88,14 +69,9 @@ function lerpPath(from, to, t) {
|
|
|
88
69
|
return out;
|
|
89
70
|
}
|
|
90
71
|
/**
|
|
91
|
-
* Scale a path
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* a stretchy delimiter assembled from a different number of pieces at the two
|
|
95
|
-
* sizes, say. Point-by-point lerping is impossible there, so the target outline
|
|
96
|
-
* is shrunk to the source's size instead and grown back over the morph: the
|
|
97
|
-
* size still changes continuously, which is the whole point, at the cost of
|
|
98
|
-
* showing the target's shape from the start.
|
|
72
|
+
* Scale a path about (cx, cy), then translate by (dx, dy). The fallback for a
|
|
73
|
+
* matched pair whose paths differ in structure (a stretchy delimiter built from
|
|
74
|
+
* different pieces): the target outline starts at the source's size and grows back.
|
|
99
75
|
*/
|
|
100
76
|
function scaleAbout(path, cx, cy, s, dx, dy) {
|
|
101
77
|
return path.map(cmd => {
|
|
@@ -114,7 +90,6 @@ function scaleAbout(path, cx, cy, s, dx, dy) {
|
|
|
114
90
|
* write first: the `x^2` of `x^2 + 1` travels to the `x^2` of `y = x^2` as
|
|
115
91
|
* one, instead of lending its `2` to whichever `2` comes first. What is left
|
|
116
92
|
* is matched greedily by character alone.
|
|
117
|
-
* Returns three lists: matched pairs, deleted tokens (only in from), added tokens (only in to).
|
|
118
93
|
*/
|
|
119
94
|
function matchTokens(from, to) {
|
|
120
95
|
const remaining = [...to];
|
|
@@ -146,34 +121,17 @@ function matchTokens(from, to) {
|
|
|
146
121
|
return { matched, deleted, added: remaining };
|
|
147
122
|
}
|
|
148
123
|
/**
|
|
149
|
-
* Precompute a formula-change morph
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* - Matched tokens are interpolated — place *and* size — across the full range
|
|
153
|
-
* of `t`.
|
|
154
|
-
* - Added tokens fade in over the second half of `t`.
|
|
155
|
-
*
|
|
156
|
-
* A matched glyph is rarely the same size at both ends: the `2` of `b^2` is set
|
|
157
|
-
* at script size and the `2` of `2a` at full size, and a `\frac`'s arguments
|
|
158
|
-
* come back a step smaller than the same symbols on a baseline. So the
|
|
159
|
-
* interpolation has to carry the glyph's *geometry*, not just where it sits.
|
|
160
|
-
* Sliding the target outline from one centroid to the other — which is all this
|
|
161
|
-
* used to do — put the whole size change between the last static frame and the
|
|
162
|
-
* morph's first one: a snap to the new size, then a smooth glide to the new
|
|
163
|
-
* place. Point-by-point lerping (see {@link lerpPath}) is that same
|
|
164
|
-
* interpolation generalised from a glyph's average point to all of them, and it
|
|
165
|
-
* costs nothing extra — the path was already being rebuilt every frame to apply
|
|
166
|
-
* the slide.
|
|
124
|
+
* Precompute a formula-change morph as a pure `t -> tokens` frame function:
|
|
125
|
+
* deleted tokens fade out over the first half, matched tokens interpolate place
|
|
126
|
+
* and size across the whole range, added tokens fade in over the second half.
|
|
167
127
|
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
128
|
+
* Size must be interpolated with place: a matched glyph is rarely the same size
|
|
129
|
+
* at both ends (the `2` of `b^2` against the `2` of `2a`), and sliding only the
|
|
130
|
+
* centroid would snap to the new size before the glide. `t` is already eased.
|
|
171
131
|
*/
|
|
172
|
-
export function
|
|
132
|
+
export function defaultLatexMorph(from, to) {
|
|
173
133
|
const { matched, deleted, added } = matchTokens(from, to);
|
|
174
|
-
//
|
|
175
|
-
// and extents behind the fallback, are properties of the pair rather than
|
|
176
|
-
// of `t`, so they are settled once here instead of at every frame.
|
|
134
|
+
// Properties of the pair rather than of `t`, settled once.
|
|
177
135
|
const fromIndex = new Map(from.map((token, i) => [token, i]));
|
|
178
136
|
const toIndex = new Map(to.map((token, i) => [token, i]));
|
|
179
137
|
const matchedData = matched.map(({ from: f, to: t }) => {
|
|
@@ -187,21 +145,18 @@ export function prepareLatexTween(from, to) {
|
|
|
187
145
|
token: t.token,
|
|
188
146
|
fromCenter: centroid(f.path),
|
|
189
147
|
toCenter: centroid(t.path),
|
|
190
|
-
/** Only the fallback needs it, and only as a ratio. */
|
|
191
148
|
fromScale: toExtent > 0 ? extent(f.path) / toExtent : 1,
|
|
192
149
|
};
|
|
193
150
|
});
|
|
194
151
|
return (t) => {
|
|
195
152
|
const tokens = [];
|
|
196
|
-
// Matched tokens: interpolate place and size across the full duration.
|
|
197
153
|
for (const m of matchedData) {
|
|
198
154
|
if (m.pointwise) {
|
|
199
155
|
tokens.push({
|
|
200
156
|
token: m.token,
|
|
201
157
|
path: lerpPath(m.fromPath, m.toPath, t),
|
|
202
158
|
opacity: 1,
|
|
203
|
-
//
|
|
204
|
-
// which includes where the glyph sits.
|
|
159
|
+
// The lerp already carries where the glyph sits.
|
|
205
160
|
x: 0,
|
|
206
161
|
y: 0,
|
|
207
162
|
from: m.from,
|
|
@@ -222,7 +177,6 @@ export function prepareLatexTween(from, to) {
|
|
|
222
177
|
to: m.to,
|
|
223
178
|
});
|
|
224
179
|
}
|
|
225
|
-
// Deleted tokens: fade out over the first half, gone by t=0.5
|
|
226
180
|
for (const d of deleted) {
|
|
227
181
|
const fadeT = Math.min(t * 2, 1);
|
|
228
182
|
tokens.push({
|
|
@@ -234,7 +188,6 @@ export function prepareLatexTween(from, to) {
|
|
|
234
188
|
from: fromIndex.get(d),
|
|
235
189
|
});
|
|
236
190
|
}
|
|
237
|
-
// Added tokens: fade in over the second half, starting at t=0.5
|
|
238
191
|
for (const a of added) {
|
|
239
192
|
const fadeT = Math.max(t * 2 - 1, 0);
|
|
240
193
|
tokens.push({
|
|
@@ -249,5 +202,4 @@ export function prepareLatexTween(from, to) {
|
|
|
249
202
|
return tokens;
|
|
250
203
|
};
|
|
251
204
|
}
|
|
252
|
-
export { prepareLatexTween as defaultLatexMorph };
|
|
253
205
|
//# sourceMappingURL=tween.js.map
|
package/dist/tex/tween.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tween.js","sourceRoot":"","sources":["../../src/tex/tween.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAoB,MAAM,mBAAmB,CAAC;AA2BjE,6EAA6E;AAC7E,MAAM,YAAY,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAU,CAAC;AAEvE;;GAEG;AACH,SAAS,QAAQ,CAAC,IAAwB;IACtC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACrB,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;YAC3B,EAAE,IAAK,GAAW,CAAC,CAAC,CAAC;YACrB,EAAE,IAAK,GAAW,CAAC,CAAC,CAAC;YACrB,CAAC,EAAE,CAAC;QACR,CAAC;IACL,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,SAAS,MAAM,CAAC,IA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GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC;gBACR,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,OAAO,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC;gBAChC,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,CAAC;gBACJ,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;aACzB,CAAC,CAAC;QACP,CAAC;QAED,gEAAgE;QAChE,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;YACrC,MAAM,CAAC,IAAI,CAAC;gBACR,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,OAAO,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC;gBAChC,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,CAAC;gBACJ,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;aACrB,CAAC,CAAC;QACP,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;AACN,CAAC;AAED,OAAO,EAAE,iBAAiB,IAAI,iBAAiB,EAAE,CAAC","sourcesContent":["import { lerpNumber, type PathCommand } from \"@motionscript/sdk\";\nimport type { LatexToken } from \"./geometry\";\n\nexport interface AnimatedToken {\n token: string;\n path: LatexToken[\"path\"];\n /** The top-level term it belongs to at rest; a morph matches on it. */\n term?: string;\n /** 0 = invisible, 1 = fully visible */\n opacity: number;\n /** Interpolated position offset applied during morph (x, y in formula space). */\n x: number;\n y: number;\n /** Mid-morph: the index of the token it was in the formula left, and of the one it becomes. */\n from?: number;\n to?: number;\n}\n\n/**\n * How a `Latex` node interpolates between two formulas: given the tokens it\n * currently holds and the tokens the target formula resolves to, return a\n * pure `t → AnimatedToken[]` frame function. `prepareLatexTween` below is the\n * default implementation (exported as `defaultLatexMorph`) — pass a `morph`\n * of this shape to `<Latex>` to replace it with your own.\n */\nexport type LatexMorphStrategy = (from: LatexToken[], to: LatexToken[]) => (t: number) => AnimatedToken[];\n\n/** The coordinate pairs a `PathCommand` can carry, as (x, y) field names. */\nconst POINT_FIELDS = [[\"x\", \"y\"], [\"x1\", \"y1\"], [\"x2\", \"y2\"]] as const;\n\n/**\n * Compute the centroid of a token's path for position-based interpolation.\n */\nfunction centroid(path: LatexToken[\"path\"]): { x: number; y: number } {\n let sx = 0, sy = 0, n = 0;\n for (const cmd of path) {\n if (\"x\" in cmd && \"y\" in cmd) {\n sx += (cmd as any).x;\n sy += (cmd as any).y;\n n++;\n }\n }\n return n > 0 ? { x: sx / n, y: sy / n } : { x: 0, y: 0 };\n}\n\n/**\n * A glyph's on-screen extent, as the diagonal of its control-point bbox.\n *\n * Only ever used as a *ratio* between the two ends of a match, so the fact that\n * control points overshoot the true outline doesn't matter: both ends overshoot\n * by the same proportion, because they are the same outline.\n */\nfunction extent(path: LatexToken[\"path\"]): number {\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const cmd of path) {\n const c = cmd as any;\n for (const [kx, ky] of POINT_FIELDS) {\n if (kx in c) {\n if (c[kx] < minX) minX = c[kx];\n if (c[kx] > maxX) maxX = c[kx];\n if (c[ky] < minY) minY = c[ky];\n if (c[ky] > maxY) maxY = c[ky];\n }\n }\n }\n if (minX > maxX) return 0;\n return Math.hypot(maxX - minX, maxY - minY);\n}\n\n/**\n * Whether two paths can be interpolated point by point: same command count,\n * same command types in the same order.\n *\n * For a matched pair this is the overwhelmingly common case, and not by luck.\n * Tokens are matched on the character their MathJax glyph id decodes to, and\n * that id *is* the key into the `<defs>` dictionary — so the same character in\n * two formulas is the same outline, emitted twice under two different\n * transforms. Same commands, different numbers.\n */\nfunction isPointwiseCompatible(from: PathCommand[], to: PathCommand[]): boolean {\n if (from.length !== to.length) return false;\n for (let i = 0; i < from.length; i++) {\n if (from[i].type !== to[i].type) return false;\n }\n return true;\n}\n\n/**\n * Lerp two structurally identical paths point by point.\n *\n * When the two ends are the same outline under two affine transforms — which is\n * what a matched glyph is — this is exact at both ends *and* correct in\n * between: `(1-t)·A·q + t·B·q = ((1-t)A + tB)·q`, and a blend of two\n * uniform-scale-plus-translate transforms is another one. The intermediate is a\n * properly formed glyph at an intermediate size, not a smeared one.\n */\nfunction lerpPath(from: PathCommand[], to: PathCommand[], t: number): PathCommand[] {\n const out: PathCommand[] = new Array(from.length);\n for (let i = 0; i < from.length; i++) {\n const f = from[i] as any;\n const g = to[i] as any;\n const c: any = { ...g };\n for (const [kx, ky] of POINT_FIELDS) {\n if (kx in g && kx in f) {\n c[kx] = lerpNumber(f[kx], g[kx], t);\n c[ky] = lerpNumber(f[ky], g[ky], t);\n }\n }\n out[i] = c as PathCommand;\n }\n return out;\n}\n\n/**\n * Scale a path uniformly about (cx, cy), then translate by (dx, dy).\n *\n * The fallback for a matched pair whose paths *aren't* structurally identical —\n * a stretchy delimiter assembled from a different number of pieces at the two\n * sizes, say. Point-by-point lerping is impossible there, so the target outline\n * is shrunk to the source's size instead and grown back over the morph: the\n * size still changes continuously, which is the whole point, at the cost of\n * showing the target's shape from the start.\n */\nfunction scaleAbout(\n path: PathCommand[],\n cx: number,\n cy: number,\n s: number,\n dx: number,\n dy: number,\n): PathCommand[] {\n return path.map(cmd => {\n const c: any = { ...(cmd as any) };\n for (const [kx, ky] of POINT_FIELDS) {\n if (kx in c) {\n c[kx] = cx + (c[kx] - cx) * s + dx;\n c[ky] = cy + (c[ky] - cy) * s + dy;\n }\n }\n return c as PathCommand;\n });\n}\n\n/**\n * Match tokens from `from` to `to` by character key, a term that both formulas\n * write first: the `x^2` of `x^2 + 1` travels to the `x^2` of `y = x^2` as\n * one, instead of lending its `2` to whichever `2` comes first. What is left\n * is matched greedily by character alone.\n * Returns three lists: matched pairs, deleted tokens (only in from), added tokens (only in to).\n */\nfunction matchTokens(\n from: LatexToken[],\n to: LatexToken[],\n): {\n matched: Array<{ from: LatexToken; to: LatexToken }>;\n deleted: LatexToken[];\n added: LatexToken[];\n} {\n const remaining = [...to];\n const partner = new Map<LatexToken, LatexToken>();\n // Synthetic shapes (rects/paths) have no natural token key.\n const keyed = (t: LatexToken) => !t.token.startsWith(\"__\");\n const pair = (same: (f: LatexToken, t: LatexToken) => boolean) => {\n for (const ft of from) {\n if (!keyed(ft) || partner.has(ft)) continue;\n const idx = remaining.findIndex(t => keyed(t) && same(ft, t));\n if (idx === -1) continue;\n partner.set(ft, remaining[idx]);\n remaining.splice(idx, 1);\n }\n };\n pair((f, t) => f.token === t.token && f.term !== undefined && f.term === t.term);\n pair((f, t) => f.token === t.token);\n\n const matched: Array<{ from: LatexToken; to: LatexToken }> = [];\n const deleted: LatexToken[] = [];\n for (const ft of from) {\n const tt = partner.get(ft);\n if (tt) matched.push({ from: ft, to: tt });\n else deleted.push(ft);\n }\n\n return { matched, deleted, added: remaining };\n}\n\n/**\n * Precompute a formula-change morph and return a pure `t → AnimatedToken[]`\n * frame function:\n * - Deleted tokens fade out over the first half of `t`.\n * - Matched tokens are interpolated — place *and* size — across the full range\n * of `t`.\n * - Added tokens fade in over the second half of `t`.\n *\n * A matched glyph is rarely the same size at both ends: the `2` of `b^2` is set\n * at script size and the `2` of `2a` at full size, and a `\\frac`'s arguments\n * come back a step smaller than the same symbols on a baseline. So the\n * interpolation has to carry the glyph's *geometry*, not just where it sits.\n * Sliding the target outline from one centroid to the other — which is all this\n * used to do — put the whole size change between the last static frame and the\n * morph's first one: a snap to the new size, then a smooth glide to the new\n * place. Point-by-point lerping (see {@link lerpPath}) is that same\n * interpolation generalised from a glyph's average point to all of them, and it\n * costs nothing extra — the path was already being rebuilt every frame to apply\n * the slide.\n *\n * `t` is normalized `[0, 1]` and already eased — the caller (a `Command`'s\n * `at`) applies easing once, up front, the same eased value driving every\n * concurrent aspect of the morph (props, intrinsic size, tokens) in lockstep.\n */\nexport function prepareLatexTween(\n from: LatexToken[],\n to: LatexToken[],\n): (t: number) => AnimatedToken[] {\n const { matched, deleted, added } = matchTokens(from, to);\n\n // Per-match interpolation data. Structure compatibility, and the centroids\n // and extents behind the fallback, are properties of the pair rather than\n // of `t`, so they are settled once here instead of at every frame.\n const fromIndex = new Map(from.map((token, i) => [token, i]));\n const toIndex = new Map(to.map((token, i) => [token, i]));\n const matchedData = matched.map(({ from: f, to: t }) => {\n const toExtent = extent(t.path);\n return {\n from: fromIndex.get(f),\n to: toIndex.get(t),\n pointwise: isPointwiseCompatible(f.path, t.path),\n fromPath: f.path,\n toPath: t.path,\n token: t.token,\n fromCenter: centroid(f.path),\n toCenter: centroid(t.path),\n /** Only the fallback needs it, and only as a ratio. */\n fromScale: toExtent > 0 ? extent(f.path) / toExtent : 1,\n };\n });\n\n return (t: number): AnimatedToken[] => {\n const tokens: AnimatedToken[] = [];\n\n // Matched tokens: interpolate place and size across the full duration.\n for (const m of matchedData) {\n if (m.pointwise) {\n tokens.push({\n token: m.token,\n path: lerpPath(m.fromPath, m.toPath, t),\n opacity: 1,\n // Baked into the path above: the lerp carries every point,\n // which includes where the glyph sits.\n x: 0,\n y: 0,\n from: m.from,\n to: m.to,\n });\n continue;\n }\n\n const s = lerpNumber(m.fromScale, 1, t);\n const cx = lerpNumber(m.fromCenter.x, m.toCenter.x, t);\n const cy = lerpNumber(m.fromCenter.y, m.toCenter.y, t);\n tokens.push({\n token: m.token,\n path: scaleAbout(\n m.toPath,\n m.toCenter.x,\n m.toCenter.y,\n s,\n cx - m.toCenter.x,\n cy - m.toCenter.y,\n ),\n opacity: 1,\n x: 0,\n y: 0,\n from: m.from,\n to: m.to,\n });\n }\n\n // Deleted tokens: fade out over the first half, gone by t=0.5\n for (const d of deleted) {\n const fadeT = Math.min(t * 2, 1);\n tokens.push({\n token: d.token,\n path: d.path,\n opacity: lerpNumber(1, 0, fadeT),\n x: 0,\n y: 0,\n from: fromIndex.get(d),\n });\n }\n\n // Added tokens: fade in over the second half, starting at t=0.5\n for (const a of added) {\n const fadeT = Math.max(t * 2 - 1, 0);\n tokens.push({\n token: a.token,\n path: a.path,\n opacity: lerpNumber(0, 1, fadeT),\n x: 0,\n y: 0,\n to: toIndex.get(a),\n });\n }\n\n return tokens;\n };\n}\n\nexport { prepareLatexTween as defaultLatexMorph };\n"]}
|
|
1
|
+
{"version":3,"file":"tween.js","sourceRoot":"","sources":["../../src/tex/tween.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAoB,MAAM,mBAAmB,CAAC;AAsBjE,MAAM,YAAY,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAU,CAAC;AAEvE,SAAS,QAAQ,CAAC,IAAwB;IACtC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACrB,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;YAC3B,EAAE,IAAK,GAAW,CAAC,CAAC,CAAC;YACrB,EAAE,IAAK,GAAW,CAAC,CAAC,CAAC;YACrB,CAAC,EAAE,CAAC;QACR,CAAC;IACL,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAC7D,CAAC;AAED,8IAA8I;AAC9I,SAAS,MAAM,CAAC,IAAwB;IACpC,IAAI,IAAI,GAAG,QAAQ,EAAE,IA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AAC,EAAE,CAAC,EAAE,KAAK,CAAC;gBAChC,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,CAAC;gBACJ,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;aACzB,CAAC,CAAC;QACP,CAAC;QAED,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;YACrC,MAAM,CAAC,IAAI,CAAC;gBACR,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,OAAO,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC;gBAChC,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,CAAC;gBACJ,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;aACrB,CAAC,CAAC;QACP,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;AACN,CAAC","sourcesContent":["import { lerpNumber, type PathCommand } from \"@motionscript/sdk\";\nimport type { LatexToken } from \"./geometry\";\n\nexport interface AnimatedToken {\n token: string;\n path: LatexToken[\"path\"];\n /** The top-level term it belongs to at rest; a morph matches on it. */\n term?: string;\n opacity: number;\n x: number;\n y: number;\n /** Mid-morph: the index of the token it was in the formula left, and of the one it becomes. */\n from?: number;\n to?: number;\n}\n\n/**\n * How a `Latex` node interpolates between two formulas: a pure `t -> tokens`\n * frame function. {@link defaultLatexMorph} is the default; pass a `morph` to replace it.\n */\nexport type LatexMorphStrategy = (from: LatexToken[], to: LatexToken[]) => (t: number) => AnimatedToken[];\n\nconst POINT_FIELDS = [[\"x\", \"y\"], [\"x1\", \"y1\"], [\"x2\", \"y2\"]] as const;\n\nfunction centroid(path: LatexToken[\"path\"]): { x: number; y: number } {\n let sx = 0, sy = 0, n = 0;\n for (const cmd of path) {\n if (\"x\" in cmd && \"y\" in cmd) {\n sx += (cmd as any).x;\n sy += (cmd as any).y;\n n++;\n }\n }\n return n > 0 ? { x: sx / n, y: sy / n } : { x: 0, y: 0 };\n}\n\n/** The diagonal of a path's control-point bbox: only ever a ratio between the two ends of a match, so the control-point overshoot cancels. */\nfunction extent(path: LatexToken[\"path\"]): number {\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const cmd of path) {\n const c = cmd as any;\n for (const [kx, ky] of POINT_FIELDS) {\n if (kx in c) {\n if (c[kx] < minX) minX = c[kx];\n if (c[kx] > maxX) maxX = c[kx];\n if (c[ky] < minY) minY = c[ky];\n if (c[ky] > maxY) maxY = c[ky];\n }\n }\n }\n if (minX > maxX) return 0;\n return Math.hypot(maxX - minX, maxY - minY);\n}\n\n/**\n * Whether two paths share command count and types. A matched pair almost always\n * does: a character's glyph id keys one outline in `<defs>`, emitted under two\n * transforms.\n */\nfunction isPointwiseCompatible(from: PathCommand[], to: PathCommand[]): boolean {\n if (from.length !== to.length) return false;\n for (let i = 0; i < from.length; i++) {\n if (from[i].type !== to[i].type) return false;\n }\n return true;\n}\n\n/**\n * Lerp two structurally identical paths point by point. Matched glyphs are one\n * outline under two uniform-scale-plus-translate transforms, and a blend of\n * those is another, so the in-between is a well-formed glyph at an in-between size.\n */\nfunction lerpPath(from: PathCommand[], to: PathCommand[], t: number): PathCommand[] {\n const out: PathCommand[] = new Array(from.length);\n for (let i = 0; i < from.length; i++) {\n const f = from[i] as any;\n const g = to[i] as any;\n const c: any = { ...g };\n for (const [kx, ky] of POINT_FIELDS) {\n if (kx in g && kx in f) {\n c[kx] = lerpNumber(f[kx], g[kx], t);\n c[ky] = lerpNumber(f[ky], g[ky], t);\n }\n }\n out[i] = c as PathCommand;\n }\n return out;\n}\n\n/**\n * Scale a path about (cx, cy), then translate by (dx, dy). The fallback for a\n * matched pair whose paths differ in structure (a stretchy delimiter built from\n * different pieces): the target outline starts at the source's size and grows back.\n */\nfunction scaleAbout(\n path: PathCommand[],\n cx: number,\n cy: number,\n s: number,\n dx: number,\n dy: number,\n): PathCommand[] {\n return path.map(cmd => {\n const c: any = { ...(cmd as any) };\n for (const [kx, ky] of POINT_FIELDS) {\n if (kx in c) {\n c[kx] = cx + (c[kx] - cx) * s + dx;\n c[ky] = cy + (c[ky] - cy) * s + dy;\n }\n }\n return c as PathCommand;\n });\n}\n\n/**\n * Match tokens from `from` to `to` by character key, a term that both formulas\n * write first: the `x^2` of `x^2 + 1` travels to the `x^2` of `y = x^2` as\n * one, instead of lending its `2` to whichever `2` comes first. What is left\n * is matched greedily by character alone.\n */\nfunction matchTokens(\n from: LatexToken[],\n to: LatexToken[],\n): {\n matched: Array<{ from: LatexToken; to: LatexToken }>;\n deleted: LatexToken[];\n added: LatexToken[];\n} {\n const remaining = [...to];\n const partner = new Map<LatexToken, LatexToken>();\n // Synthetic shapes (rects/paths) have no natural token key.\n const keyed = (t: LatexToken) => !t.token.startsWith(\"__\");\n const pair = (same: (f: LatexToken, t: LatexToken) => boolean) => {\n for (const ft of from) {\n if (!keyed(ft) || partner.has(ft)) continue;\n const idx = remaining.findIndex(t => keyed(t) && same(ft, t));\n if (idx === -1) continue;\n partner.set(ft, remaining[idx]);\n remaining.splice(idx, 1);\n }\n };\n pair((f, t) => f.token === t.token && f.term !== undefined && f.term === t.term);\n pair((f, t) => f.token === t.token);\n\n const matched: Array<{ from: LatexToken; to: LatexToken }> = [];\n const deleted: LatexToken[] = [];\n for (const ft of from) {\n const tt = partner.get(ft);\n if (tt) matched.push({ from: ft, to: tt });\n else deleted.push(ft);\n }\n\n return { matched, deleted, added: remaining };\n}\n\n/**\n * Precompute a formula-change morph as a pure `t -> tokens` frame function:\n * deleted tokens fade out over the first half, matched tokens interpolate place\n * and size across the whole range, added tokens fade in over the second half.\n *\n * Size must be interpolated with place: a matched glyph is rarely the same size\n * at both ends (the `2` of `b^2` against the `2` of `2a`), and sliding only the\n * centroid would snap to the new size before the glide. `t` is already eased.\n */\nexport function defaultLatexMorph(\n from: LatexToken[],\n to: LatexToken[],\n): (t: number) => AnimatedToken[] {\n const { matched, deleted, added } = matchTokens(from, to);\n\n // Properties of the pair rather than of `t`, settled once.\n const fromIndex = new Map(from.map((token, i) => [token, i]));\n const toIndex = new Map(to.map((token, i) => [token, i]));\n const matchedData = matched.map(({ from: f, to: t }) => {\n const toExtent = extent(t.path);\n return {\n from: fromIndex.get(f),\n to: toIndex.get(t),\n pointwise: isPointwiseCompatible(f.path, t.path),\n fromPath: f.path,\n toPath: t.path,\n token: t.token,\n fromCenter: centroid(f.path),\n toCenter: centroid(t.path),\n fromScale: toExtent > 0 ? extent(f.path) / toExtent : 1,\n };\n });\n\n return (t: number): AnimatedToken[] => {\n const tokens: AnimatedToken[] = [];\n\n for (const m of matchedData) {\n if (m.pointwise) {\n tokens.push({\n token: m.token,\n path: lerpPath(m.fromPath, m.toPath, t),\n opacity: 1,\n // The lerp already carries where the glyph sits.\n x: 0,\n y: 0,\n from: m.from,\n to: m.to,\n });\n continue;\n }\n\n const s = lerpNumber(m.fromScale, 1, t);\n const cx = lerpNumber(m.fromCenter.x, m.toCenter.x, t);\n const cy = lerpNumber(m.fromCenter.y, m.toCenter.y, t);\n tokens.push({\n token: m.token,\n path: scaleAbout(\n m.toPath,\n m.toCenter.x,\n m.toCenter.y,\n s,\n cx - m.toCenter.x,\n cy - m.toCenter.y,\n ),\n opacity: 1,\n x: 0,\n y: 0,\n from: m.from,\n to: m.to,\n });\n }\n\n for (const d of deleted) {\n const fadeT = Math.min(t * 2, 1);\n tokens.push({\n token: d.token,\n path: d.path,\n opacity: lerpNumber(1, 0, fadeT),\n x: 0,\n y: 0,\n from: fromIndex.get(d),\n });\n }\n\n for (const a of added) {\n const fadeT = Math.max(t * 2 - 1, 0);\n tokens.push({\n token: a.token,\n path: a.path,\n opacity: lerpNumber(0, 1, fadeT),\n x: 0,\n y: 0,\n to: toIndex.get(a),\n });\n }\n\n return tokens;\n };\n}\n"]}
|
package/dist/tex/typeset.d.ts
CHANGED
|
@@ -2,16 +2,6 @@ import { Flow, type BoxBounds, type ChildView, type Fill, type FillResolved, typ
|
|
|
2
2
|
import { type LatexPart } from "./geometry.js";
|
|
3
3
|
import { type AnimatedToken, type LatexMorphStrategy } from "./tween.js";
|
|
4
4
|
import { type PartFill, type PartFillResolved } from "../kit/part-fills.js";
|
|
5
|
-
/**
|
|
6
|
-
* A formula typeset to glyph paths: what `latex` and `latexMatrix` share. A
|
|
7
|
-
* node says where its formula comes from (`formula`); this lays it out, draws
|
|
8
|
-
* it, writes it on, paints its parts, and morphs it into another.
|
|
9
|
-
*
|
|
10
|
-
* A morph is held by the entries the formula is written from: mid-tween each
|
|
11
|
-
* holds both ends ({@link Morph}), so a seek to any time draws the morph there
|
|
12
|
-
* from the node's own state, and a plain `to({ latex })` morphs as `morphTo` does.
|
|
13
|
-
*/
|
|
14
|
-
/** A value on its way to another: what an entry the formula is written from holds mid-tween. */
|
|
15
5
|
export declare class Morph<T> {
|
|
16
6
|
readonly from: T;
|
|
17
7
|
readonly to: T;
|
|
@@ -24,15 +14,10 @@ export declare function settled<T>(value: Morphing<T>): T;
|
|
|
24
14
|
export declare function lerpMorph<T>(from: Morphing<T>, to: Morphing<T>, t: number): Morphing<T>;
|
|
25
15
|
/** `parts` combined into one value at each end, when any of them is on its way: a matrix's source from its entries and brackets. */
|
|
26
16
|
export declare function morphOf<T>(parts: readonly Morphing<unknown>[], combine: (ends: readonly unknown[]) => T): Morphing<T>;
|
|
27
|
-
/** What every formula has: the glyphs' paint, the flow its children are laid out in, its size, its part fills and how much of it is written. */
|
|
28
17
|
export declare const TYPESET: {
|
|
29
18
|
fontSize: number;
|
|
30
19
|
/** Paints for parts of the formula, named by their source. Later entries win where two name a glyph. */
|
|
31
20
|
partFills: import("@motionscript/sdk").Type<PartFill[], PartFillResolved[], false>;
|
|
32
|
-
/**
|
|
33
|
-
* How much of the formula is written, 0 to 1: its glyphs are drawn one after
|
|
34
|
-
* another, each outlined and then filled.
|
|
35
|
-
*/
|
|
36
21
|
written: import("@motionscript/sdk").Type<number, number, false>;
|
|
37
22
|
/** Reported for a host that read it; the morph is held by the formula's own entries. */
|
|
38
23
|
morphProgress: import("@motionscript/sdk").Type<number, number, false>;
|
|
@@ -78,7 +63,6 @@ export declare const TYPESET_COMMANDS: {
|
|
|
78
63
|
};
|
|
79
64
|
};
|
|
80
65
|
type TypesetValues = Values<typeof TYPESET>;
|
|
81
|
-
/** What is drawn of a formula now: its glyphs, its parts, its centre frame and size, and mid-morph each end's part fills. */
|
|
82
66
|
export interface FormulaFrame {
|
|
83
67
|
readonly tokens: readonly AnimatedToken[];
|
|
84
68
|
readonly parts: readonly LatexPart[];
|
|
@@ -95,21 +79,16 @@ export interface FormulaFrame {
|
|
|
95
79
|
type TokenFills = (PartFillResolved | undefined)[];
|
|
96
80
|
/** The formula drawn now, from where it comes from: at rest, or `t` of the way through a morph. */
|
|
97
81
|
export declare function formulaFrame(source: Morphing<string>, fontSize: number, partFills: readonly PartFillResolved[], morph?: LatexMorphStrategy): FormulaFrame;
|
|
98
|
-
/**
|
|
82
|
+
/** Hugging size; the factory applies a set or filling one. */
|
|
99
83
|
export declare function measureFormula(frame: FormulaFrame, s: {
|
|
100
84
|
readonly padding: InsetsResolved;
|
|
101
85
|
}): Size2D;
|
|
102
|
-
/** Its children, laid out in its box clear of its stroke, as a shape lays out its own. */
|
|
103
86
|
export declare function layoutFormula(box: BoxBounds, s: Flow.FlowState & {
|
|
104
87
|
readonly stroke: StrokeResolved[];
|
|
105
88
|
}, children: readonly ChildView<any>[]): readonly Placement2D[];
|
|
106
89
|
/** MathJax, before this node is laid out: a scene with no formula in it never loads it. */
|
|
107
90
|
export declare function loadFormula(loader: Loader): void;
|
|
108
|
-
/**
|
|
109
|
-
* The glyphs, in a node's paint order: each one's shadow, fill and stroke
|
|
110
|
-
* (the shadow op first, so the paint after it casts it), the pen's line while
|
|
111
|
-
* it is being written, then the children, then the overlay through the glyphs.
|
|
112
|
-
*/
|
|
91
|
+
/** Glyphs (shadow, fill, stroke, then the pen's line while written), then children, then the overlay through the glyphs. */
|
|
113
92
|
export declare function drawFormula(ctx: RenderContext, s: TypesetValues, frame: FormulaFrame): void;
|
|
114
93
|
/**
|
|
115
94
|
* The box around one part of the formula, centred on the node's own centre and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeset.d.ts","sourceRoot":"","sources":["../../src/tex/typeset.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,IAAI,EAOJ,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,MAAM,EAEX,KAAK,SAAS,IAAI,UAAU,EAC5B,KAAK,QAAQ,IAAI,SAAS,EAC1B,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,OAAO,IAAI,QAAQ,EAC3B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAA2F,KAAK,SAAS,EAAyC,MAAM,YAAY,CAAC;AAC5K,OAAO,EAAqB,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGzF,OAAO,EAAyD,KAAK,QAAQ,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"typeset.d.ts","sourceRoot":"","sources":["../../src/tex/typeset.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,IAAI,EAOJ,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAA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yCD,YAAY,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/tex/typeset.js
CHANGED
|
@@ -5,16 +5,7 @@ import { defaultLatexMorph } from "./tween.js";
|
|
|
5
5
|
import { createBoundedCache } from "../kit/cache.js";
|
|
6
6
|
import { omit } from "../kit/component.js";
|
|
7
7
|
import { lerpPartFills, partPaint, readPartFills, withPartFill } from "../kit/part-fills.js";
|
|
8
|
-
|
|
9
|
-
* A formula typeset to glyph paths: what `latex` and `latexMatrix` share. A
|
|
10
|
-
* node says where its formula comes from (`formula`); this lays it out, draws
|
|
11
|
-
* it, writes it on, paints its parts, and morphs it into another.
|
|
12
|
-
*
|
|
13
|
-
* A morph is held by the entries the formula is written from: mid-tween each
|
|
14
|
-
* holds both ends ({@link Morph}), so a seek to any time draws the morph there
|
|
15
|
-
* from the node's own state, and a plain `to({ latex })` morphs as `morphTo` does.
|
|
16
|
-
*/
|
|
17
|
-
/** A value on its way to another: what an entry the formula is written from holds mid-tween. */
|
|
8
|
+
// Mid-morph an entry holds both ends (Morph), so a seek draws the morph from the node's own state.
|
|
18
9
|
export class Morph {
|
|
19
10
|
from;
|
|
20
11
|
to;
|
|
@@ -45,7 +36,6 @@ export function morphOf(parts, combine) {
|
|
|
45
36
|
return moving ? new Morph(end("from"), end("to"), moving.t) : end("to");
|
|
46
37
|
}
|
|
47
38
|
const { start: _start, end: _end, ...glyphPaint } = Paint.state;
|
|
48
|
-
/** What every formula has: the glyphs' paint, the flow its children are laid out in, its size, its part fills and how much of it is written. */
|
|
49
39
|
export const TYPESET = {
|
|
50
40
|
// A formula writes itself on (`written`), so it trims no outline.
|
|
51
41
|
...glyphPaint,
|
|
@@ -53,10 +43,6 @@ export const TYPESET = {
|
|
|
53
43
|
fontSize: 16,
|
|
54
44
|
/** Paints for parts of the formula, named by their source. Later entries win where two name a glyph. */
|
|
55
45
|
partFills: Types.custom([], { resolve: readPartFills, lerp: lerpPartFills, kind: "vector" }),
|
|
56
|
-
/**
|
|
57
|
-
* How much of the formula is written, 0 to 1: its glyphs are drawn one after
|
|
58
|
-
* another, each outlined and then filled.
|
|
59
|
-
*/
|
|
60
46
|
written: Types.number(1, { min: 0, max: 1, step: 0.01 }),
|
|
61
47
|
/** Reported for a host that read it; the morph is held by the formula's own entries. */
|
|
62
48
|
morphProgress: Types.number(0, { animatable: false }),
|
|
@@ -64,9 +50,7 @@ export const TYPESET = {
|
|
|
64
50
|
export const TYPESET_COMMANDS = {
|
|
65
51
|
...omit(Paint.commands, "progressTo", "flash"),
|
|
66
52
|
...commandsFor(TYPESET, {
|
|
67
|
-
/** Write the formula on, or off: its glyphs one after another, each outlined and then filled. */
|
|
68
53
|
writeTo: { args: ["written"] },
|
|
69
|
-
/** Paint one part of the formula, leaving the rest as it is. */
|
|
70
54
|
partFillTo: {
|
|
71
55
|
args: {
|
|
72
56
|
part: Types.text(""),
|
|
@@ -100,7 +84,6 @@ function atRest(source, fontSize) {
|
|
|
100
84
|
}
|
|
101
85
|
const resting = new WeakMap();
|
|
102
86
|
function restingFrame(result) {
|
|
103
|
-
// The typeset result is shared by every reader of the formula; its tokens wrapped once.
|
|
104
87
|
let frame = resting.get(result.tokens);
|
|
105
88
|
if (!frame) {
|
|
106
89
|
frame = {
|
|
@@ -165,13 +148,11 @@ export function formulaFrame(source, fontSize, partFills, morph = defaultLatexMo
|
|
|
165
148
|
},
|
|
166
149
|
};
|
|
167
150
|
}
|
|
168
|
-
|
|
169
|
-
/** Its formula's size and its padding, hugging; the factory applies a set or filling size. */
|
|
151
|
+
/** Hugging size; the factory applies a set or filling one. */
|
|
170
152
|
export function measureFormula(frame, s) {
|
|
171
153
|
const pad = s.padding;
|
|
172
154
|
return { width: frame.width + pad.left + pad.right, height: frame.height + pad.top + pad.bottom };
|
|
173
155
|
}
|
|
174
|
-
/** Its children, laid out in its box clear of its stroke, as a shape lays out its own. */
|
|
175
156
|
export function layoutFormula(box, s, children) {
|
|
176
157
|
return Flow.layout(box, s, children, strokeInset(s.stroke));
|
|
177
158
|
}
|
|
@@ -188,16 +169,11 @@ function strokeInset(stroke) {
|
|
|
188
169
|
export function loadFormula(loader) {
|
|
189
170
|
loader.task(MATHJAX_LOADER, loadMathJax, { before: "layout" });
|
|
190
171
|
}
|
|
191
|
-
|
|
192
|
-
/** How much of one glyph's writing overlaps the next one's. */
|
|
172
|
+
/** The share of one glyph's writing that overlaps the next one's. */
|
|
193
173
|
const WRITE_OVERLAP = 0.6;
|
|
194
174
|
/** The outline a glyph is written with, as a share of the type size. */
|
|
195
175
|
const WRITE_STROKE = 1 / 32;
|
|
196
|
-
/**
|
|
197
|
-
* The glyphs, in a node's paint order: each one's shadow, fill and stroke
|
|
198
|
-
* (the shadow op first, so the paint after it casts it), the pen's line while
|
|
199
|
-
* it is being written, then the children, then the overlay through the glyphs.
|
|
200
|
-
*/
|
|
176
|
+
/** Glyphs (shadow, fill, stroke, then the pen's line while written), then children, then the overlay through the glyphs. */
|
|
201
177
|
export function drawFormula(ctx, s, frame) {
|
|
202
178
|
ctx.inFront(() => drawGlyphs(ctx, s, frame));
|
|
203
179
|
ctx.children();
|
|
@@ -307,7 +283,6 @@ function eachToken(ctx, frame, paint, drawn = () => 1) {
|
|
|
307
283
|
ctx.draw(painted);
|
|
308
284
|
});
|
|
309
285
|
}
|
|
310
|
-
// ---- parts --------------------------------------------------------------------
|
|
311
286
|
/**
|
|
312
287
|
* The box around one part of the formula, centred on the node's own centre and
|
|
313
288
|
* y-up, or `null` when the formula does not write `part` (or is mid-morph).
|
|
@@ -353,7 +328,6 @@ export function latexPartBounds(node, part, occurrence = 1) {
|
|
|
353
328
|
const frame = formulaOf(node);
|
|
354
329
|
return frame ? partBoundsIn(frame, part, occurrence) : undefined;
|
|
355
330
|
}
|
|
356
|
-
// ---- paint helpers ------------------------------------------------------------
|
|
357
331
|
function fillsByToken(partFills, parts, count) {
|
|
358
332
|
const out = new Array(count);
|
|
359
333
|
for (const entry of partFills) {
|
package/dist/tex/typeset.js.map
CHANGED
|
@@ -1 +1 @@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AAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;QAAC,CAAC;QAClE,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;YAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;YAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;QAAC,CAAC;QAClE,OAAO,OAAO,CAAC;IACnB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import {\n commandsFor,\n fillOps,\n Flow,\n Graphics2D,\n lerpNumber,\n Paint,\n pathOps,\n toPathString,\n Types,\n type BoxBounds,\n type ChildView,\n type Fill,\n type FillResolved,\n type InsetsResolved,\n type Loader,\n type Placement2D,\n type RenderContext,\n type ShadowResolved,\n type Size2D,\n type StrokeResolved,\n type Values,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Shadow as _Shadow,\n type Stroke as _Stroke,\n type Vector2 as _Vector2,\n} from \"@motionscript/sdk\";\n// From each module, never the `../engine` barrel: it re-exports this file.\nimport { blankLatex, buildLatexPath, findLatexParts, LatexNotLoaded, loadMathJax, MATHJAX_LOADER, type LatexPart, type LatexPathResult, type LatexToken } from \"./geometry\";\nimport { defaultLatexMorph, type AnimatedToken, type LatexMorphStrategy } from \"./tween\";\nimport { createBoundedCache } from \"../kit/cache\";\nimport { omit } from \"../kit/component\";\nimport { lerpPartFills, partPaint, readPartFills, withPartFill, type PartFill, type PartFillResolved } from \"../kit/part-fills\";\n\n/**\n * A formula typeset to glyph paths: what `latex` and `latexMatrix` share. A\n * node says where its formula comes from (`formula`); this lays it out, draws\n * it, writes it on, paints its parts, and morphs it into another.\n *\n * A morph is held by the entries the formula is written from: mid-tween each\n * holds both ends ({@link Morph}), so a seek to any time draws the morph there\n * from the node's own state, and a plain `to({ latex })` morphs as `morphTo` does.\n */\n\n/** A value on its way to another: what an entry the formula is written from holds mid-tween. */\nexport class Morph<T> {\n constructor(readonly from: T, readonly to: T, readonly t: number) { }\n}\n\nexport type Morphing<T> = T | Morph<T>;\n\n/** The end a value rests at, or is nearer to mid-tween: where a tween that starts from it starts. */\nexport function settled<T>(value: Morphing<T>): T {\n return value instanceof Morph ? (value.t < 0.5 ? value.from : value.to) : value;\n}\n\n// A whole value has nothing between its ends: mid-way it holds both, and the drawing morphs between them.\n// (A function, not a generic arrow: a copied component is compiled as TSX, where `<T>(` opens an element.)\nexport function lerpMorph<T>(from: Morphing<T>, to: Morphing<T>, t: number): Morphing<T> {\n if (t <= 0) return from;\n if (t >= 1) return to;\n return new Morph(settled(from), settled(to), t);\n}\n\n/** `parts` combined into one value at each end, when any of them is on its way: a matrix's source from its entries and brackets. */\nexport function morphOf<T>(parts: readonly Morphing<unknown>[], combine: (ends: readonly unknown[]) => T): Morphing<T> {\n const moving = parts.find((part): part is Morph<unknown> => part instanceof Morph);\n const end = (which: \"from\" | \"to\") => combine(parts.map((part) => (part instanceof Morph ? part[which] : part)));\n return moving ? new Morph(end(\"from\"), end(\"to\"), moving.t) : end(\"to\");\n}\n\nconst { start: _start, end: _end, ...glyphPaint } = Paint.state;\n\n/** What every formula has: the glyphs' paint, the flow its children are laid out in, its size, its part fills and how much of it is written. */\nexport const TYPESET = {\n // A formula writes itself on (`written`), so it trims no outline.\n ...glyphPaint,\n ...Flow.state,\n fontSize: 16,\n /** Paints for parts of the formula, named by their source. Later entries win where two name a glyph. */\n partFills: Types.custom<PartFill[], PartFillResolved[]>([], { resolve: readPartFills, lerp: lerpPartFills, kind: \"vector\" }),\n /**\n * How much of the formula is written, 0 to 1: its glyphs are drawn one after\n * another, each outlined and then filled.\n */\n written: Types.number(1, { min: 0, max: 1, step: 0.01 }),\n /** Reported for a host that read it; the morph is held by the formula's own entries. */\n morphProgress: Types.number(0, { animatable: false }),\n};\n\nexport const TYPESET_COMMANDS = {\n ...omit(Paint.commands, \"progressTo\", \"flash\"),\n ...commandsFor(TYPESET, {\n /** Write the formula on, or off: its glyphs one after another, each outlined and then filled. */\n writeTo: { args: [\"written\"] },\n /** Paint one part of the formula, leaving the rest as it is. */\n partFillTo: {\n args: {\n part: Types.text(\"\"),\n fill: Types.custom<Fill>(\"#facc15\", { kind: \"fills\" }),\n occurrence: Types.number(0, { min: 0, step: 1 }),\n },\n run: (timeline, s) => {\n const { part, fill, occurrence } = timeline.args;\n if (!part || fill == null) return timeline.tween({});\n return timeline.tween({ partFills: withPartFill(s.partFills, { part, fill, occurrence }) });\n },\n },\n }),\n};\n\ntype TypesetValues = Values<typeof TYPESET>;\n\n// ---- the formula at a moment ------------------------------------------------\n\n/** What is drawn of a formula now: its glyphs, its parts, its centre frame and size, and mid-morph each end's part fills. */\nexport interface FormulaFrame {\n readonly tokens: readonly AnimatedToken[];\n readonly parts: readonly LatexPart[];\n readonly bounds: [number, number, number, number];\n readonly width: number;\n readonly height: number;\n readonly morph: { readonly from: TokenFills; readonly to: TokenFills; readonly t: number } | null;\n}\n\n/** One part fill per token, or none: the last entry that names it. */\ntype TokenFills = (PartFillResolved | undefined)[];\n\nconst EMPTY: FormulaFrame = { tokens: [], parts: [], bounds: [0, 0, 0, 0], width: 0, height: 0, morph: null };\n\n/** A formula at rest: blank while MathJax is on its way, and asked again next time. A malformed one throws, every time. */\nfunction atRest(source: string, fontSize: number): FormulaFrame {\n if (!source) return EMPTY;\n let result: LatexPathResult;\n try {\n result = buildLatexPath(source, fontSize);\n } catch (error) {\n if (error instanceof LatexNotLoaded) return EMPTY;\n throw error;\n }\n return restingFrame(result);\n}\n\nconst resting = new WeakMap<LatexToken[], FormulaFrame>();\n\nfunction restingFrame(result: LatexPathResult): FormulaFrame {\n // The typeset result is shared by every reader of the formula; its tokens wrapped once.\n let frame = resting.get(result.tokens);\n if (!frame) {\n frame = {\n tokens: result.tokens.map((t) => ({ token: t.token, path: t.path, term: t.term, opacity: 1, x: 0, y: 0 })),\n parts: result.parts,\n bounds: result.bounds,\n width: result.width,\n height: result.height,\n morph: null,\n };\n resting.set(result.tokens, frame);\n }\n return frame;\n}\n\n/** Where a morph goes: typeset even when empty, and blank before MathJax. */\nfunction target(source: string, fontSize: number): LatexPathResult {\n try {\n return buildLatexPath(source, fontSize);\n } catch (error) {\n if (!(error instanceof LatexNotLoaded)) throw error;\n return blankLatex();\n }\n}\n\nconst NUL = String.fromCharCode(0);\nconst morphs = createBoundedCache<(t: number) => AnimatedToken[]>(16);\nlet lastMorph: { key: string; t: number; tokens: AnimatedToken[] } | null = null;\n\n/** The formula drawn now, from where it comes from: at rest, or `t` of the way through a morph. */\nexport function formulaFrame(\n source: Morphing<string>,\n fontSize: number,\n partFills: readonly PartFillResolved[],\n morph: LatexMorphStrategy = defaultLatexMorph,\n): FormulaFrame {\n if (!(source instanceof Morph)) return atRest(source, fontSize);\n const from = atRest(source.from, fontSize);\n const to = target(source.to, fontSize);\n const { t } = source;\n const key = `${fontSize}${NUL}${source.from}${NUL}${source.to}`;\n let frame = morph === defaultLatexMorph ? morphs.get(key) : undefined;\n if (!frame) {\n frame = morph(from.tokens.map((token) => ({ token: token.token, path: token.path, term: token.term })), to.tokens);\n if (morph === defaultLatexMorph) morphs.set(key, frame);\n }\n // Measured and drawn in one frame: the glyphs are worked out once.\n const tokens = lastMorph && lastMorph.key === key && lastMorph.t === t && morph === defaultLatexMorph ? lastMorph.tokens : frame(t);\n if (morph === defaultLatexMorph) lastMorph = { key, t, tokens };\n return {\n tokens,\n parts: [],\n bounds: [\n lerpNumber(from.bounds[0], to.bounds[0], t),\n lerpNumber(from.bounds[1], to.bounds[1], t),\n lerpNumber(from.bounds[2], to.bounds[2], t),\n lerpNumber(from.bounds[3], to.bounds[3], t),\n ],\n width: lerpNumber(from.width, to.width, t),\n height: lerpNumber(from.height, to.height, t),\n morph: {\n from: fillsByToken(partFills, from.parts, from.tokens.length),\n to: fillsByToken(partFills, to.parts, to.tokens.length),\n t,\n },\n };\n}\n\n// ---- measuring, laying out, loading -----------------------------------------\n\n/** Its formula's size and its padding, hugging; the factory applies a set or filling size. */\nexport function measureFormula(frame: FormulaFrame, s: { readonly padding: InsetsResolved }): Size2D {\n const pad = s.padding;\n return { width: frame.width + pad.left + pad.right, height: frame.height + pad.top + pad.bottom };\n}\n\n/** Its children, laid out in its box clear of its stroke, as a shape lays out its own. */\nexport function layoutFormula(box: BoxBounds, s: Flow.FlowState & { readonly stroke: StrokeResolved[] }, children: readonly ChildView<any>[]): readonly Placement2D[] {\n return Flow.layout(box, s, children, strokeInset(s.stroke));\n}\n\nfunction strokeInset(stroke: readonly StrokeResolved[]) {\n let extra = 0;\n for (const layer of stroke) {\n const intrusion = layer.weight * (1 - layer.align) / 2;\n if (intrusion > extra) extra = intrusion;\n }\n return { left: extra, right: extra, top: extra, bottom: extra };\n}\n\n/** MathJax, before this node is laid out: a scene with no formula in it never loads it. */\nexport function loadFormula(loader: Loader): void {\n loader.task(MATHJAX_LOADER, loadMathJax, { before: \"layout\" });\n}\n\n// ---- drawing ------------------------------------------------------------------\n\n/** How much of one glyph's writing overlaps the next one's. */\nconst WRITE_OVERLAP = 0.6;\n/** The outline a glyph is written with, as a share of the type size. */\nconst WRITE_STROKE = 1 / 32;\n\n/**\n * The glyphs, in a node's paint order: each one's shadow, fill and stroke\n * (the shadow op first, so the paint after it casts it), the pen's line while\n * it is being written, then the children, then the overlay through the glyphs.\n */\nexport function drawFormula(ctx: RenderContext, s: TypesetValues, frame: FormulaFrame): void {\n ctx.inFront(() => drawGlyphs(ctx, s, frame));\n ctx.children();\n ctx.inFront(() => drawOverlay(ctx, s, frame));\n}\n\nfunction drawGlyphs(ctx: RenderContext, s: TypesetValues, frame: FormulaFrame): void {\n const fills = s.fill as FillResolved[];\n const shadows = s.shadow as ShadowResolved[];\n const stroke = s.stroke as StrokeResolved[];\n const partOf = tokenFills(frame, s.partFills);\n const writing = writingOf(s.written, frame.tokens.length);\n eachToken(ctx, frame, (graphics, opacity, index, token) => {\n const fill = partPaint(fills, partOf(index, token));\n const pen = writing?.(index);\n if (!pen) {\n return graphics\n .shadow(scaleShadowOpacity(shadows, opacity))\n .fill(scaleFillopacity(fill, opacity))\n .stroke(stroke);\n }\n if (pen.filled <= 0) return null;\n return graphics\n .shadow(scaleShadowOpacity(shadows, opacity * pen.filled))\n .fill(scaleFillopacity(fill, opacity * pen.filled))\n .stroke(stroke);\n });\n if (!writing) return;\n // The pen's line: each glyph's outline, in its own colour, ahead of its fill.\n eachToken(ctx, frame, (graphics, opacity, index, token) => {\n const pen = writing(index);\n if (!pen || pen.filled >= 1 || pen.outlined <= 0) return null;\n const fill = scaleFillopacity(partPaint(fills, partOf(index, token)), opacity * (1 - pen.filled));\n return graphics.stroke(stroke.length > 0 ? stroke : penStroke(s.fontSize * WRITE_STROKE, fill));\n }, (index) => writing(index)?.outlined ?? 1);\n}\n\n/** The overlay, painted through the glyphs: a formula has no one silhouette to fill. */\nfunction drawOverlay(ctx: RenderContext, s: TypesetValues, frame: FormulaFrame): void {\n const overlay = s.overlay as FillResolved[];\n if (overlay.length === 0) return;\n const writing = writingOf(s.written, frame.tokens.length);\n eachToken(ctx, frame, (graphics, opacity, index) => {\n const filled = writing?.(index).filled ?? 1;\n return filled <= 0 ? null : graphics.fill(scaleFillopacity(overlay, opacity * filled));\n });\n}\n\n/** Each token's part fill: by its place in the formula at rest, by both ends' mid-morph. */\nfunction tokenFills(frame: FormulaFrame, partFills: readonly PartFillResolved[]): (index: number, token: AnimatedToken) => PartFillResolved | undefined {\n const morph = frame.morph;\n if (morph) {\n return (_index, token) => {\n const a = token.from === undefined ? undefined : morph.from[token.from];\n const b = token.to === undefined ? undefined : morph.to[token.to];\n if (a && b) return { ...b, fill: fillOps.lerp(a.fill, b.fill, morph.t), mix: lerpNumber(a.mix, b.mix, morph.t) };\n if (a) return token.to === undefined ? a : { ...a, mix: a.mix * (1 - morph.t) };\n if (b) return token.from === undefined ? b : { ...b, mix: b.mix * morph.t };\n return undefined;\n };\n }\n if (partFills.length === 0) return () => undefined;\n const byToken = fillsByToken(partFills, frame.parts, frame.tokens.length);\n return (index) => byToken[index];\n}\n\n/**\n * How far each glyph is written at `written`: its outline first, then its fill,\n * each glyph starting before the one ahead of it is done. `null` once the whole\n * formula is.\n */\nfunction writingOf(written: number, count: number): ((index: number) => { outlined: number; filled: number }) | null {\n if (written >= 1) return null;\n const lead = 1 - WRITE_OVERLAP;\n const span = 1 / (1 + Math.max(0, count - 1) * lead);\n return (index) => {\n const p = Math.min(1, Math.max(0, (written - index * span * lead) / span));\n return { outlined: Math.min(1, p * 2), filled: Math.max(0, p * 2 - 1) };\n };\n}\n\n/**\n * Every visible token's path once, each handed to `paint` to have its paint\n * ops appended: a fresh `Graphics2D` per token per pass, since paint ops\n * accumulate on the one they are added to.\n */\nfunction eachToken(\n ctx: RenderContext,\n frame: FormulaFrame,\n paint: (graphics: Graphics2D, opacity: number, index: number, token: AnimatedToken) => Graphics2D | null,\n drawn: (index: number) => number = () => 1,\n): void {\n frame.tokens.forEach((token, index) => {\n if (token.opacity <= 0) return;\n const pathStr = token.x !== 0 || token.y !== 0\n ? toPathString(offsetPath(token.path, token.x, token.y))\n : toPathString(token.path);\n const painted = paint(new Graphics2D()\n .path({\n data: pathStr,\n start: 0,\n end: 1 * drawn(index),\n // All tokens share one centre frame, so they keep their relative layout.\n centerBounds: frame.bounds,\n }), token.opacity, index, token);\n if (painted) ctx.draw(painted);\n });\n}\n\n// ---- parts --------------------------------------------------------------------\n\n/**\n * The box around one part of the formula, centred on the node's own centre and\n * y-up, or `null` when the formula does not write `part` (or is mid-morph).\n * `occurrence` counts from 1.\n */\nexport function partBoundsIn(frame: FormulaFrame, part: string, occurrence = 1): BoxBounds | null {\n const span = findLatexParts(frame.parts, part)[Math.max(1, Math.round(occurrence)) - 1];\n if (!span) return null;\n const box = pathOps.bounds(frame.tokens.slice(span[0], span[1]).flatMap((token) => token.path));\n if (!box) return null;\n const [minX, minY, maxX, maxY] = frame.bounds;\n const cx = (minX + maxX) / 2;\n const cy = (minY + maxY) / 2;\n return {\n x: (box.minX + box.maxX) / 2 - cx,\n y: cy - (box.minY + box.maxY) / 2,\n width: box.maxX - box.minX,\n height: box.maxY - box.minY,\n };\n}\n\n/** Where a node's formula comes from, by the class its component generated. */\ntype SourceOf = (values: never) => Morphing<string>;\nconst sources = new WeakMap<object, SourceOf>();\n\n/** Declare `component` a formula written from `source`: a mark can then point at its parts. */\nexport function formula<C extends { readonly node: object }>(component: C, source: SourceOf): C {\n sources.set(component.node, source);\n return component;\n}\n\n/** Whether `node` draws a formula, and so has parts a mark can point at. */\nexport function isFormula(node: object): boolean {\n return sources.has((node as { constructor: object }).constructor);\n}\n\n/** The formula `node` draws now, or `null` when it is no formula. */\nexport function formulaOf(node: object): FormulaFrame | null {\n const source = sources.get((node as { constructor: object }).constructor);\n if (!source) return null;\n const values = node as unknown as TypesetValues;\n return formulaFrame(source(values as never), values.fontSize, values.partFills);\n}\n\n/** The box around a part of the formula `node` draws (see {@link partBoundsIn}); `undefined` when it is no formula. */\nexport function latexPartBounds(node: object, part: string, occurrence = 1): BoxBounds | null | undefined {\n const frame = formulaOf(node);\n return frame ? partBoundsIn(frame, part, occurrence) : undefined;\n}\n\n// ---- paint helpers ------------------------------------------------------------\n\nfunction fillsByToken(partFills: readonly PartFillResolved[], parts: readonly LatexPart[], count: number): TokenFills {\n const out: TokenFills = new Array(count);\n for (const entry of partFills) {\n if (entry.part.trim() === \"\") continue;\n const spans = findLatexParts(parts, entry.part);\n for (const [from, to] of entry.occurrence > 0 ? spans.slice(entry.occurrence - 1, entry.occurrence) : spans) {\n for (let i = from; i < to && i < count; i++) out[i] = entry;\n }\n }\n return out;\n}\n\nfunction penStroke(weight: number, fill: FillResolved[]): StrokeResolved[] {\n return [{ weight, fill, dashOffset: 0, align: 0, cap: \"round\", capScale: 4, join: \"round\", miterLimit: 4 }];\n}\n\nfunction scaleFillopacity(fills: FillResolved[], opacity: number): FillResolved[] {\n if (opacity >= 1) return fills;\n return fills.map((f) => ({ ...f, opacity: (f.opacity ?? 1) * opacity }));\n}\n\n/** A fading token's shadow fades with it, as its fill does. */\nfunction scaleShadowOpacity(shadows: ShadowResolved[], opacity: number): ShadowResolved[] {\n if (opacity >= 1) return shadows;\n return shadows.map((s) => ({ ...s, fill: scaleFillopacity(s.fill, opacity) }));\n}\n\nfunction offsetPath(path: LatexToken[\"path\"], dx: number, dy: number): LatexToken[\"path\"] {\n return path.map((cmd) => {\n const c = cmd as any;\n const shifted: any = { ...c };\n if (\"x\" in c) shifted.x = c.x + dx;\n if (\"y\" in c) shifted.y = c.y + dy;\n if (\"x1\" in c) { shifted.x1 = c.x1 + dx; shifted.y1 = c.y1 + dy; }\n if (\"x2\" in c) { shifted.x2 = c.x2 + dx; shifted.y2 = c.y2 + dy; }\n return shifted;\n });\n}\n\nexport type { TypesetValues };\n"]}
|
|
1
|
+
{"version":3,"file":"typeset.js","sourceRoot":"","sources":["../../src/tex/typeset.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,OAAO,EACP,IAAI,EACJ,UAAU,EACV,UAAU,EACV,KAAK,EACL,OAAO,EACP,YAAY,EACZ,KAAK,GAqBR,MAAM,mBAAmB,CAAC;AAC3B,2EAA2E;AAC3E,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAyD,MAAM,YAAY,CAAC;AAC5K,OAAO,EAAE,iBAAiB,EAA+C,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAwC,MAAM,mBAAmB,CAAC;AAEhI,mGAAmG;AAEnG,MAAM,OAAO,KAAK;IACO;IAAkB;IAAgB;IAAvD,YAAqB,IAAO,EAAW,EAAK,EAAW,CAAS;QAA3C,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AAO,GAAQ,EAAE,GAAG,CAAC,EAAE,CAAC;QAC9B,IAAI,GAAG,IAAI,CAAC;YAAE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QACnC,IAAI,GAAG,IAAI,CAAC;YAAE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QACnC,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;YAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;YAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;QAAC,CAAC;QAClE,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;YAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;YAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;QAAC,CAAC;QAClE,OAAO,OAAO,CAAC;IACnB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import {\n commandsFor,\n fillOps,\n Flow,\n Graphics2D,\n lerpNumber,\n Paint,\n pathOps,\n toPathString,\n Types,\n type BoxBounds,\n type ChildView,\n type Fill,\n type FillResolved,\n type InsetsResolved,\n type Loader,\n type Placement2D,\n type RenderContext,\n type ShadowResolved,\n type Size2D,\n type StrokeResolved,\n type Values,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Shadow as _Shadow,\n type Stroke as _Stroke,\n type Vector2 as _Vector2,\n} from \"@motionscript/sdk\";\n// From each module, never the `../engine` barrel: it re-exports this file.\nimport { blankLatex, buildLatexPath, findLatexParts, LatexNotLoaded, loadMathJax, MATHJAX_LOADER, type LatexPart, type LatexPathResult, type LatexToken } from \"./geometry\";\nimport { defaultLatexMorph, type AnimatedToken, type LatexMorphStrategy } from \"./tween\";\nimport { createBoundedCache } from \"../kit/cache\";\nimport { omit } from \"../kit/component\";\nimport { lerpPartFills, partPaint, readPartFills, withPartFill, type PartFill, type PartFillResolved } from \"../kit/part-fills\";\n\n// Mid-morph an entry holds both ends (Morph), so a seek draws the morph from the node's own state.\n\nexport class Morph<T> {\n constructor(readonly from: T, readonly to: T, readonly t: number) { }\n}\n\nexport type Morphing<T> = T | Morph<T>;\n\n/** The end a value rests at, or is nearer to mid-tween: where a tween that starts from it starts. */\nexport function settled<T>(value: Morphing<T>): T {\n return value instanceof Morph ? (value.t < 0.5 ? value.from : value.to) : value;\n}\n\n// A whole value has nothing between its ends: mid-way it holds both, and the drawing morphs between them.\n// (A function, not a generic arrow: a copied component is compiled as TSX, where `<T>(` opens an element.)\nexport function lerpMorph<T>(from: Morphing<T>, to: Morphing<T>, t: number): Morphing<T> {\n if (t <= 0) return from;\n if (t >= 1) return to;\n return new Morph(settled(from), settled(to), t);\n}\n\n/** `parts` combined into one value at each end, when any of them is on its way: a matrix's source from its entries and brackets. */\nexport function morphOf<T>(parts: readonly Morphing<unknown>[], combine: (ends: readonly unknown[]) => T): Morphing<T> {\n const moving = parts.find((part): part is Morph<unknown> => part instanceof Morph);\n const end = (which: \"from\" | \"to\") => combine(parts.map((part) => (part instanceof Morph ? part[which] : part)));\n return moving ? new Morph(end(\"from\"), end(\"to\"), moving.t) : end(\"to\");\n}\n\nconst { start: _start, end: _end, ...glyphPaint } = Paint.state;\n\nexport const TYPESET = {\n // A formula writes itself on (`written`), so it trims no outline.\n ...glyphPaint,\n ...Flow.state,\n fontSize: 16,\n /** Paints for parts of the formula, named by their source. Later entries win where two name a glyph. */\n partFills: Types.custom<PartFill[], PartFillResolved[]>([], { resolve: readPartFills, lerp: lerpPartFills, kind: \"vector\" }),\n written: Types.number(1, { min: 0, max: 1, step: 0.01 }),\n /** Reported for a host that read it; the morph is held by the formula's own entries. */\n morphProgress: Types.number(0, { animatable: false }),\n};\n\nexport const TYPESET_COMMANDS = {\n ...omit(Paint.commands, \"progressTo\", \"flash\"),\n ...commandsFor(TYPESET, {\n writeTo: { args: [\"written\"] },\n partFillTo: {\n args: {\n part: Types.text(\"\"),\n fill: Types.custom<Fill>(\"#facc15\", { kind: \"fills\" }),\n occurrence: Types.number(0, { min: 0, step: 1 }),\n },\n run: (timeline, s) => {\n const { part, fill, occurrence } = timeline.args;\n if (!part || fill == null) return timeline.tween({});\n return timeline.tween({ partFills: withPartFill(s.partFills, { part, fill, occurrence }) });\n },\n },\n }),\n};\n\ntype TypesetValues = Values<typeof TYPESET>;\n\nexport interface FormulaFrame {\n readonly tokens: readonly AnimatedToken[];\n readonly parts: readonly LatexPart[];\n readonly bounds: [number, number, number, number];\n readonly width: number;\n readonly height: number;\n readonly morph: { readonly from: TokenFills; readonly to: TokenFills; readonly t: number } | null;\n}\n\n/** One part fill per token, or none: the last entry that names it. */\ntype TokenFills = (PartFillResolved | undefined)[];\n\nconst EMPTY: FormulaFrame = { tokens: [], parts: [], bounds: [0, 0, 0, 0], width: 0, height: 0, morph: null };\n\n/** A formula at rest: blank while MathJax is on its way, and asked again next time. A malformed one throws, every time. */\nfunction atRest(source: string, fontSize: number): FormulaFrame {\n if (!source) return EMPTY;\n let result: LatexPathResult;\n try {\n result = buildLatexPath(source, fontSize);\n } catch (error) {\n if (error instanceof LatexNotLoaded) return EMPTY;\n throw error;\n }\n return restingFrame(result);\n}\n\nconst resting = new WeakMap<LatexToken[], FormulaFrame>();\n\nfunction restingFrame(result: LatexPathResult): FormulaFrame {\n let frame = resting.get(result.tokens);\n if (!frame) {\n frame = {\n tokens: result.tokens.map((t) => ({ token: t.token, path: t.path, term: t.term, opacity: 1, x: 0, y: 0 })),\n parts: result.parts,\n bounds: result.bounds,\n width: result.width,\n height: result.height,\n morph: null,\n };\n resting.set(result.tokens, frame);\n }\n return frame;\n}\n\n/** Where a morph goes: typeset even when empty, and blank before MathJax. */\nfunction target(source: string, fontSize: number): LatexPathResult {\n try {\n return buildLatexPath(source, fontSize);\n } catch (error) {\n if (!(error instanceof LatexNotLoaded)) throw error;\n return blankLatex();\n }\n}\n\nconst NUL = String.fromCharCode(0);\nconst morphs = createBoundedCache<(t: number) => AnimatedToken[]>(16);\nlet lastMorph: { key: string; t: number; tokens: AnimatedToken[] } | null = null;\n\n/** The formula drawn now, from where it comes from: at rest, or `t` of the way through a morph. */\nexport function formulaFrame(\n source: Morphing<string>,\n fontSize: number,\n partFills: readonly PartFillResolved[],\n morph: LatexMorphStrategy = defaultLatexMorph,\n): FormulaFrame {\n if (!(source instanceof Morph)) return atRest(source, fontSize);\n const from = atRest(source.from, fontSize);\n const to = target(source.to, fontSize);\n const { t } = source;\n const key = `${fontSize}${NUL}${source.from}${NUL}${source.to}`;\n let frame = morph === defaultLatexMorph ? morphs.get(key) : undefined;\n if (!frame) {\n frame = morph(from.tokens.map((token) => ({ token: token.token, path: token.path, term: token.term })), to.tokens);\n if (morph === defaultLatexMorph) morphs.set(key, frame);\n }\n // Measured and drawn in one frame: the glyphs are worked out once.\n const tokens = lastMorph && lastMorph.key === key && lastMorph.t === t && morph === defaultLatexMorph ? lastMorph.tokens : frame(t);\n if (morph === defaultLatexMorph) lastMorph = { key, t, tokens };\n return {\n tokens,\n parts: [],\n bounds: [\n lerpNumber(from.bounds[0], to.bounds[0], t),\n lerpNumber(from.bounds[1], to.bounds[1], t),\n lerpNumber(from.bounds[2], to.bounds[2], t),\n lerpNumber(from.bounds[3], to.bounds[3], t),\n ],\n width: lerpNumber(from.width, to.width, t),\n height: lerpNumber(from.height, to.height, t),\n morph: {\n from: fillsByToken(partFills, from.parts, from.tokens.length),\n to: fillsByToken(partFills, to.parts, to.tokens.length),\n t,\n },\n };\n}\n\n/** Hugging size; the factory applies a set or filling one. */\nexport function measureFormula(frame: FormulaFrame, s: { readonly padding: InsetsResolved }): Size2D {\n const pad = s.padding;\n return { width: frame.width + pad.left + pad.right, height: frame.height + pad.top + pad.bottom };\n}\n\nexport function layoutFormula(box: BoxBounds, s: Flow.FlowState & { readonly stroke: StrokeResolved[] }, children: readonly ChildView<any>[]): readonly Placement2D[] {\n return Flow.layout(box, s, children, strokeInset(s.stroke));\n}\n\nfunction strokeInset(stroke: readonly StrokeResolved[]) {\n let extra = 0;\n for (const layer of stroke) {\n const intrusion = layer.weight * (1 - layer.align) / 2;\n if (intrusion > extra) extra = intrusion;\n }\n return { left: extra, right: extra, top: extra, bottom: extra };\n}\n\n/** MathJax, before this node is laid out: a scene with no formula in it never loads it. */\nexport function loadFormula(loader: Loader): void {\n loader.task(MATHJAX_LOADER, loadMathJax, { before: \"layout\" });\n}\n\n/** The share of one glyph's writing that overlaps the next one's. */\nconst WRITE_OVERLAP = 0.6;\n/** The outline a glyph is written with, as a share of the type size. */\nconst WRITE_STROKE = 1 / 32;\n\n/** Glyphs (shadow, fill, stroke, then the pen's line while written), then children, then the overlay through the glyphs. */\nexport function drawFormula(ctx: RenderContext, s: TypesetValues, frame: FormulaFrame): void {\n ctx.inFront(() => drawGlyphs(ctx, s, frame));\n ctx.children();\n ctx.inFront(() => drawOverlay(ctx, s, frame));\n}\n\nfunction drawGlyphs(ctx: RenderContext, s: TypesetValues, frame: FormulaFrame): void {\n const fills = s.fill as FillResolved[];\n const shadows = s.shadow as ShadowResolved[];\n const stroke = s.stroke as StrokeResolved[];\n const partOf = tokenFills(frame, s.partFills);\n const writing = writingOf(s.written, frame.tokens.length);\n eachToken(ctx, frame, (graphics, opacity, index, token) => {\n const fill = partPaint(fills, partOf(index, token));\n const pen = writing?.(index);\n if (!pen) {\n return graphics\n .shadow(scaleShadowOpacity(shadows, opacity))\n .fill(scaleFillopacity(fill, opacity))\n .stroke(stroke);\n }\n if (pen.filled <= 0) return null;\n return graphics\n .shadow(scaleShadowOpacity(shadows, opacity * pen.filled))\n .fill(scaleFillopacity(fill, opacity * pen.filled))\n .stroke(stroke);\n });\n if (!writing) return;\n // The pen's line: each glyph's outline, in its own colour, ahead of its fill.\n eachToken(ctx, frame, (graphics, opacity, index, token) => {\n const pen = writing(index);\n if (!pen || pen.filled >= 1 || pen.outlined <= 0) return null;\n const fill = scaleFillopacity(partPaint(fills, partOf(index, token)), opacity * (1 - pen.filled));\n return graphics.stroke(stroke.length > 0 ? stroke : penStroke(s.fontSize * WRITE_STROKE, fill));\n }, (index) => writing(index)?.outlined ?? 1);\n}\n\n/** The overlay, painted through the glyphs: a formula has no one silhouette to fill. */\nfunction drawOverlay(ctx: RenderContext, s: TypesetValues, frame: FormulaFrame): void {\n const overlay = s.overlay as FillResolved[];\n if (overlay.length === 0) return;\n const writing = writingOf(s.written, frame.tokens.length);\n eachToken(ctx, frame, (graphics, opacity, index) => {\n const filled = writing?.(index).filled ?? 1;\n return filled <= 0 ? null : graphics.fill(scaleFillopacity(overlay, opacity * filled));\n });\n}\n\n/** Each token's part fill: by its place in the formula at rest, by both ends' mid-morph. */\nfunction tokenFills(frame: FormulaFrame, partFills: readonly PartFillResolved[]): (index: number, token: AnimatedToken) => PartFillResolved | undefined {\n const morph = frame.morph;\n if (morph) {\n return (_index, token) => {\n const a = token.from === undefined ? undefined : morph.from[token.from];\n const b = token.to === undefined ? undefined : morph.to[token.to];\n if (a && b) return { ...b, fill: fillOps.lerp(a.fill, b.fill, morph.t), mix: lerpNumber(a.mix, b.mix, morph.t) };\n if (a) return token.to === undefined ? a : { ...a, mix: a.mix * (1 - morph.t) };\n if (b) return token.from === undefined ? b : { ...b, mix: b.mix * morph.t };\n return undefined;\n };\n }\n if (partFills.length === 0) return () => undefined;\n const byToken = fillsByToken(partFills, frame.parts, frame.tokens.length);\n return (index) => byToken[index];\n}\n\n/**\n * How far each glyph is written at `written`: its outline first, then its fill,\n * each glyph starting before the one ahead of it is done. `null` once the whole\n * formula is.\n */\nfunction writingOf(written: number, count: number): ((index: number) => { outlined: number; filled: number }) | null {\n if (written >= 1) return null;\n const lead = 1 - WRITE_OVERLAP;\n const span = 1 / (1 + Math.max(0, count - 1) * lead);\n return (index) => {\n const p = Math.min(1, Math.max(0, (written - index * span * lead) / span));\n return { outlined: Math.min(1, p * 2), filled: Math.max(0, p * 2 - 1) };\n };\n}\n\n/**\n * Every visible token's path once, each handed to `paint` to have its paint\n * ops appended: a fresh `Graphics2D` per token per pass, since paint ops\n * accumulate on the one they are added to.\n */\nfunction eachToken(\n ctx: RenderContext,\n frame: FormulaFrame,\n paint: (graphics: Graphics2D, opacity: number, index: number, token: AnimatedToken) => Graphics2D | null,\n drawn: (index: number) => number = () => 1,\n): void {\n frame.tokens.forEach((token, index) => {\n if (token.opacity <= 0) return;\n const pathStr = token.x !== 0 || token.y !== 0\n ? toPathString(offsetPath(token.path, token.x, token.y))\n : toPathString(token.path);\n const painted = paint(new Graphics2D()\n .path({\n data: pathStr,\n start: 0,\n end: 1 * drawn(index),\n // All tokens share one centre frame, so they keep their relative layout.\n centerBounds: frame.bounds,\n }), token.opacity, index, token);\n if (painted) ctx.draw(painted);\n });\n}\n\n/**\n * The box around one part of the formula, centred on the node's own centre and\n * y-up, or `null` when the formula does not write `part` (or is mid-morph).\n * `occurrence` counts from 1.\n */\nexport function partBoundsIn(frame: FormulaFrame, part: string, occurrence = 1): BoxBounds | null {\n const span = findLatexParts(frame.parts, part)[Math.max(1, Math.round(occurrence)) - 1];\n if (!span) return null;\n const box = pathOps.bounds(frame.tokens.slice(span[0], span[1]).flatMap((token) => token.path));\n if (!box) return null;\n const [minX, minY, maxX, maxY] = frame.bounds;\n const cx = (minX + maxX) / 2;\n const cy = (minY + maxY) / 2;\n return {\n x: (box.minX + box.maxX) / 2 - cx,\n y: cy - (box.minY + box.maxY) / 2,\n width: box.maxX - box.minX,\n height: box.maxY - box.minY,\n };\n}\n\n/** Where a node's formula comes from, by the class its component generated. */\ntype SourceOf = (values: never) => Morphing<string>;\nconst sources = new WeakMap<object, SourceOf>();\n\n/** Declare `component` a formula written from `source`: a mark can then point at its parts. */\nexport function formula<C extends { readonly node: object }>(component: C, source: SourceOf): C {\n sources.set(component.node, source);\n return component;\n}\n\n/** Whether `node` draws a formula, and so has parts a mark can point at. */\nexport function isFormula(node: object): boolean {\n return sources.has((node as { constructor: object }).constructor);\n}\n\n/** The formula `node` draws now, or `null` when it is no formula. */\nexport function formulaOf(node: object): FormulaFrame | null {\n const source = sources.get((node as { constructor: object }).constructor);\n if (!source) return null;\n const values = node as unknown as TypesetValues;\n return formulaFrame(source(values as never), values.fontSize, values.partFills);\n}\n\n/** The box around a part of the formula `node` draws (see {@link partBoundsIn}); `undefined` when it is no formula. */\nexport function latexPartBounds(node: object, part: string, occurrence = 1): BoxBounds | null | undefined {\n const frame = formulaOf(node);\n return frame ? partBoundsIn(frame, part, occurrence) : undefined;\n}\n\nfunction fillsByToken(partFills: readonly PartFillResolved[], parts: readonly LatexPart[], count: number): TokenFills {\n const out: TokenFills = new Array(count);\n for (const entry of partFills) {\n if (entry.part.trim() === \"\") continue;\n const spans = findLatexParts(parts, entry.part);\n for (const [from, to] of entry.occurrence > 0 ? spans.slice(entry.occurrence - 1, entry.occurrence) : spans) {\n for (let i = from; i < to && i < count; i++) out[i] = entry;\n }\n }\n return out;\n}\n\nfunction penStroke(weight: number, fill: FillResolved[]): StrokeResolved[] {\n return [{ weight, fill, dashOffset: 0, align: 0, cap: \"round\", capScale: 4, join: \"round\", miterLimit: 4 }];\n}\n\nfunction scaleFillopacity(fills: FillResolved[], opacity: number): FillResolved[] {\n if (opacity >= 1) return fills;\n return fills.map((f) => ({ ...f, opacity: (f.opacity ?? 1) * opacity }));\n}\n\n/** A fading token's shadow fades with it, as its fill does. */\nfunction scaleShadowOpacity(shadows: ShadowResolved[], opacity: number): ShadowResolved[] {\n if (opacity >= 1) return shadows;\n return shadows.map((s) => ({ ...s, fill: scaleFillopacity(s.fill, opacity) }));\n}\n\nfunction offsetPath(path: LatexToken[\"path\"], dx: number, dy: number): LatexToken[\"path\"] {\n return path.map((cmd) => {\n const c = cmd as any;\n const shifted: any = { ...c };\n if (\"x\" in c) shifted.x = c.x + dx;\n if (\"y\" in c) shifted.y = c.y + dy;\n if (\"x1\" in c) { shifted.x1 = c.x1 + dx; shifted.y1 = c.y1 + dy; }\n if (\"x2\" in c) { shifted.x2 = c.x2 + dx; shifted.y2 = c.y2 + dy; }\n return shifted;\n });\n}\n\nexport type { TypesetValues };\n"]}
|