@motionscript/math 0.0.0-stage → 0.1.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +48 -0
  4. package/README.md +385 -3
  5. package/dist/annotate/angle-mark.d.ts +46 -0
  6. package/dist/annotate/angle-mark.d.ts.map +1 -0
  7. package/dist/annotate/angle-mark.js +132 -0
  8. package/dist/annotate/angle-mark.js.map +1 -0
  9. package/dist/annotate/curly-brace.d.ts +46 -0
  10. package/dist/annotate/curly-brace.d.ts.map +1 -0
  11. package/dist/annotate/curly-brace.js +114 -0
  12. package/dist/annotate/curly-brace.js.map +1 -0
  13. package/dist/annotate/emphasis-mark.d.ts +20 -0
  14. package/dist/annotate/emphasis-mark.d.ts.map +1 -0
  15. package/dist/annotate/emphasis-mark.js +81 -0
  16. package/dist/annotate/emphasis-mark.js.map +1 -0
  17. package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
  18. package/dist/browser/chunks/chunk-3GJB6AVO.js +2 -0
  19. package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
  20. package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
  21. package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
  22. package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
  23. package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
  24. package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
  25. package/dist/browser/chunks/mathjax-DNP3YRES.js.map +7 -0
  26. package/dist/browser/index.js +2 -0
  27. package/dist/browser/index.js.map +7 -0
  28. package/dist/browser/kit.js +2 -0
  29. package/dist/browser/kit.js.map +7 -0
  30. package/dist/browser/manifest.json +30 -0
  31. package/dist/browser/tex.js +2 -0
  32. package/dist/browser/tex.js.map +7 -0
  33. package/dist/engine.d.ts +64 -0
  34. package/dist/engine.d.ts.map +1 -0
  35. package/dist/engine.js +42 -0
  36. package/dist/engine.js.map +1 -0
  37. package/dist/index.d.ts +30 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +30 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/kit/brace.d.ts +8 -0
  42. package/dist/kit/brace.d.ts.map +1 -0
  43. package/dist/kit/brace.js +36 -0
  44. package/dist/kit/brace.js.map +1 -0
  45. package/dist/kit/cache.d.ts +30 -0
  46. package/dist/kit/cache.d.ts.map +1 -0
  47. package/dist/kit/cache.js +53 -0
  48. package/dist/kit/cache.js.map +1 -0
  49. package/dist/kit/contour.d.ts +8 -0
  50. package/dist/kit/contour.d.ts.map +1 -0
  51. package/dist/kit/contour.js +93 -0
  52. package/dist/kit/contour.js.map +1 -0
  53. package/dist/kit/coords.d.ts +69 -0
  54. package/dist/kit/coords.d.ts.map +1 -0
  55. package/dist/kit/coords.js +224 -0
  56. package/dist/kit/coords.js.map +1 -0
  57. package/dist/kit/curve.d.ts +17 -0
  58. package/dist/kit/curve.d.ts.map +1 -0
  59. package/dist/kit/curve.js +22 -0
  60. package/dist/kit/curve.js.map +1 -0
  61. package/dist/kit/equation.d.ts +61 -0
  62. package/dist/kit/equation.d.ts.map +1 -0
  63. package/dist/kit/equation.js +168 -0
  64. package/dist/kit/equation.js.map +1 -0
  65. package/dist/kit/equation3d.d.ts +50 -0
  66. package/dist/kit/equation3d.d.ts.map +1 -0
  67. package/dist/kit/equation3d.js +103 -0
  68. package/dist/kit/equation3d.js.map +1 -0
  69. package/dist/kit/expression.d.ts +35 -0
  70. package/dist/kit/expression.d.ts.map +1 -0
  71. package/dist/kit/expression.js +124 -0
  72. package/dist/kit/expression.js.map +1 -0
  73. package/dist/kit/field-mark.d.ts +58 -0
  74. package/dist/kit/field-mark.d.ts.map +1 -0
  75. package/dist/kit/field-mark.js +129 -0
  76. package/dist/kit/field-mark.js.map +1 -0
  77. package/dist/kit/field.d.ts +14 -0
  78. package/dist/kit/field.d.ts.map +1 -0
  79. package/dist/kit/field.js +46 -0
  80. package/dist/kit/field.js.map +1 -0
  81. package/dist/kit/follow.d.ts +71 -0
  82. package/dist/kit/follow.d.ts.map +1 -0
  83. package/dist/kit/follow.js +159 -0
  84. package/dist/kit/follow.js.map +1 -0
  85. package/dist/kit/furniture.d.ts +30 -0
  86. package/dist/kit/furniture.d.ts.map +1 -0
  87. package/dist/kit/furniture.js +87 -0
  88. package/dist/kit/furniture.js.map +1 -0
  89. package/dist/kit/geometry.d.ts +13 -0
  90. package/dist/kit/geometry.d.ts.map +1 -0
  91. package/dist/kit/geometry.js +54 -0
  92. package/dist/kit/geometry.js.map +1 -0
  93. package/dist/kit/mark.d.ts +47 -0
  94. package/dist/kit/mark.d.ts.map +1 -0
  95. package/dist/kit/mark.js +103 -0
  96. package/dist/kit/mark.js.map +1 -0
  97. package/dist/kit/part-fills.d.ts +23 -0
  98. package/dist/kit/part-fills.d.ts.map +1 -0
  99. package/dist/kit/part-fills.js +46 -0
  100. package/dist/kit/part-fills.js.map +1 -0
  101. package/dist/kit/place.d.ts +18 -0
  102. package/dist/kit/place.d.ts.map +1 -0
  103. package/dist/kit/place.js +68 -0
  104. package/dist/kit/place.js.map +1 -0
  105. package/dist/kit/placement.d.ts +8 -0
  106. package/dist/kit/placement.d.ts.map +1 -0
  107. package/dist/kit/placement.js +8 -0
  108. package/dist/kit/placement.js.map +1 -0
  109. package/dist/kit/sampler.d.ts +17 -0
  110. package/dist/kit/sampler.d.ts.map +1 -0
  111. package/dist/kit/sampler.js +250 -0
  112. package/dist/kit/sampler.js.map +1 -0
  113. package/dist/kit/scale.d.ts +12 -0
  114. package/dist/kit/scale.d.ts.map +1 -0
  115. package/dist/kit/scale.js +37 -0
  116. package/dist/kit/scale.js.map +1 -0
  117. package/dist/kit/source.d.ts +22 -0
  118. package/dist/kit/source.d.ts.map +1 -0
  119. package/dist/kit/source.js +45 -0
  120. package/dist/kit/source.js.map +1 -0
  121. package/dist/kit/system.d.ts +33 -0
  122. package/dist/kit/system.d.ts.map +1 -0
  123. package/dist/kit/system.js +67 -0
  124. package/dist/kit/system.js.map +1 -0
  125. package/dist/kit/ticks.d.ts +19 -0
  126. package/dist/kit/ticks.d.ts.map +1 -0
  127. package/dist/kit/ticks.js +78 -0
  128. package/dist/kit/ticks.js.map +1 -0
  129. package/dist/kit/withdrawn.d.ts +9 -0
  130. package/dist/kit/withdrawn.d.ts.map +1 -0
  131. package/dist/kit/withdrawn.js +9 -0
  132. package/dist/kit/withdrawn.js.map +1 -0
  133. package/dist/marks/curve-area.d.ts +32 -0
  134. package/dist/marks/curve-area.d.ts.map +1 -0
  135. package/dist/marks/curve-area.js +82 -0
  136. package/dist/marks/curve-area.js.map +1 -0
  137. package/dist/marks/drop-lines.d.ts +22 -0
  138. package/dist/marks/drop-lines.d.ts.map +1 -0
  139. package/dist/marks/drop-lines.js +58 -0
  140. package/dist/marks/drop-lines.js.map +1 -0
  141. package/dist/marks/plot-point.d.ts +35 -0
  142. package/dist/marks/plot-point.d.ts.map +1 -0
  143. package/dist/marks/plot-point.js +97 -0
  144. package/dist/marks/plot-point.js.map +1 -0
  145. package/dist/marks/riemann-sum.d.ts +37 -0
  146. package/dist/marks/riemann-sum.d.ts.map +1 -0
  147. package/dist/marks/riemann-sum.js +91 -0
  148. package/dist/marks/riemann-sum.js.map +1 -0
  149. package/dist/marks/tangent-line.d.ts +27 -0
  150. package/dist/marks/tangent-line.d.ts.map +1 -0
  151. package/dist/marks/tangent-line.js +103 -0
  152. package/dist/marks/tangent-line.js.map +1 -0
  153. package/dist/marks/vector-arrow.d.ts +32 -0
  154. package/dist/marks/vector-arrow.d.ts.map +1 -0
  155. package/dist/marks/vector-arrow.js +87 -0
  156. package/dist/marks/vector-arrow.js.map +1 -0
  157. package/dist/nodes.d.ts +35 -0
  158. package/dist/nodes.d.ts.map +1 -0
  159. package/dist/nodes.js +63 -0
  160. package/dist/nodes.js.map +1 -0
  161. package/dist/plots/function-plot.d.ts +67 -0
  162. package/dist/plots/function-plot.d.ts.map +1 -0
  163. package/dist/plots/function-plot.js +215 -0
  164. package/dist/plots/function-plot.js.map +1 -0
  165. package/dist/plots/points-plot.d.ts +28 -0
  166. package/dist/plots/points-plot.d.ts.map +1 -0
  167. package/dist/plots/points-plot.js +99 -0
  168. package/dist/plots/points-plot.js.map +1 -0
  169. package/dist/plots/stream-lines.d.ts +35 -0
  170. package/dist/plots/stream-lines.d.ts.map +1 -0
  171. package/dist/plots/stream-lines.js +141 -0
  172. package/dist/plots/stream-lines.js.map +1 -0
  173. package/dist/plots/traced-path.d.ts +31 -0
  174. package/dist/plots/traced-path.d.ts.map +1 -0
  175. package/dist/plots/traced-path.js +56 -0
  176. package/dist/plots/traced-path.js.map +1 -0
  177. package/dist/plots/vector-field.d.ts +23 -0
  178. package/dist/plots/vector-field.d.ts.map +1 -0
  179. package/dist/plots/vector-field.js +91 -0
  180. package/dist/plots/vector-field.js.map +1 -0
  181. package/dist/structures/graph-layout.d.ts +11 -0
  182. package/dist/structures/graph-layout.d.ts.map +1 -0
  183. package/dist/structures/graph-layout.js +135 -0
  184. package/dist/structures/graph-layout.js.map +1 -0
  185. package/dist/structures/network-graph.d.ts +83 -0
  186. package/dist/structures/network-graph.d.ts.map +1 -0
  187. package/dist/structures/network-graph.js +289 -0
  188. package/dist/structures/network-graph.js.map +1 -0
  189. package/dist/structures/sample-space.d.ts +62 -0
  190. package/dist/structures/sample-space.d.ts.map +1 -0
  191. package/dist/structures/sample-space.js +199 -0
  192. package/dist/structures/sample-space.js.map +1 -0
  193. package/dist/systems/axes2d.d.ts +75 -0
  194. package/dist/systems/axes2d.d.ts.map +1 -0
  195. package/dist/systems/axes2d.js +193 -0
  196. package/dist/systems/axes2d.js.map +1 -0
  197. package/dist/systems/number-line.d.ts +49 -0
  198. package/dist/systems/number-line.d.ts.map +1 -0
  199. package/dist/systems/number-line.js +127 -0
  200. package/dist/systems/number-line.js.map +1 -0
  201. package/dist/systems/number-plane.d.ts +59 -0
  202. package/dist/systems/number-plane.d.ts.map +1 -0
  203. package/dist/systems/number-plane.js +193 -0
  204. package/dist/systems/number-plane.js.map +1 -0
  205. package/dist/systems/polar-plane.d.ts +48 -0
  206. package/dist/systems/polar-plane.d.ts.map +1 -0
  207. package/dist/systems/polar-plane.js +165 -0
  208. package/dist/systems/polar-plane.js.map +1 -0
  209. package/dist/tex/geometry.d.ts +85 -0
  210. package/dist/tex/geometry.d.ts.map +1 -0
  211. package/dist/tex/geometry.js +632 -0
  212. package/dist/tex/geometry.js.map +1 -0
  213. package/dist/tex/index.d.ts +11 -0
  214. package/dist/tex/index.d.ts.map +1 -0
  215. package/dist/tex/index.js +9 -0
  216. package/dist/tex/index.js.map +1 -0
  217. package/dist/tex/mathjax.d.ts +33 -0
  218. package/dist/tex/mathjax.d.ts.map +1 -0
  219. package/dist/tex/mathjax.js +74 -0
  220. package/dist/tex/mathjax.js.map +1 -0
  221. package/dist/tex/matrix.d.ts +31 -0
  222. package/dist/tex/matrix.d.ts.map +1 -0
  223. package/dist/tex/matrix.js +73 -0
  224. package/dist/tex/matrix.js.map +1 -0
  225. package/dist/tex/node.d.ts +215 -0
  226. package/dist/tex/node.d.ts.map +1 -0
  227. package/dist/tex/node.js +595 -0
  228. package/dist/tex/node.js.map +1 -0
  229. package/dist/tex/tween.d.ts +50 -0
  230. package/dist/tex/tween.d.ts.map +1 -0
  231. package/dist/tex/tween.js +253 -0
  232. package/dist/tex/tween.js.map +1 -0
  233. package/dist/three/axes3d.d.ts +87 -0
  234. package/dist/three/axes3d.d.ts.map +1 -0
  235. package/dist/three/axes3d.js +228 -0
  236. package/dist/three/axes3d.js.map +1 -0
  237. package/dist/three/curve-plot3d.d.ts +60 -0
  238. package/dist/three/curve-plot3d.d.ts.map +1 -0
  239. package/dist/three/curve-plot3d.js +143 -0
  240. package/dist/three/curve-plot3d.js.map +1 -0
  241. package/dist/three/label3d.d.ts +11 -0
  242. package/dist/three/label3d.d.ts.map +1 -0
  243. package/dist/three/label3d.js +40 -0
  244. package/dist/three/label3d.js.map +1 -0
  245. package/dist/three/plot-point3d.d.ts +26 -0
  246. package/dist/three/plot-point3d.d.ts.map +1 -0
  247. package/dist/three/plot-point3d.js +60 -0
  248. package/dist/three/plot-point3d.js.map +1 -0
  249. package/dist/three/space.d.ts +28 -0
  250. package/dist/three/space.d.ts.map +1 -0
  251. package/dist/three/space.js +47 -0
  252. package/dist/three/space.js.map +1 -0
  253. package/dist/three/surface-plot3d.d.ts +80 -0
  254. package/dist/three/surface-plot3d.d.ts.map +1 -0
  255. package/dist/three/surface-plot3d.js +290 -0
  256. package/dist/three/surface-plot3d.js.map +1 -0
  257. package/dist/three/vector-arrow3d.d.ts +25 -0
  258. package/dist/three/vector-arrow3d.d.ts.map +1 -0
  259. package/dist/three/vector-arrow3d.js +72 -0
  260. package/dist/three/vector-arrow3d.js.map +1 -0
  261. package/package.json +79 -3
  262. package/registry.json +251 -0
  263. package/src/annotate/angle-mark.ts +147 -0
  264. package/src/annotate/curly-brace.ts +126 -0
  265. package/src/annotate/emphasis-mark.ts +89 -0
  266. package/src/engine.ts +72 -0
  267. package/src/index.ts +29 -0
  268. package/src/kit/brace.ts +37 -0
  269. package/src/kit/cache.ts +61 -0
  270. package/src/kit/contour.ts +94 -0
  271. package/src/kit/coords.ts +278 -0
  272. package/src/kit/curve.ts +29 -0
  273. package/src/kit/equation.ts +181 -0
  274. package/src/kit/equation3d.ts +137 -0
  275. package/src/kit/expression.ts +159 -0
  276. package/src/kit/field-mark.ts +155 -0
  277. package/src/kit/field.ts +50 -0
  278. package/src/kit/follow.ts +203 -0
  279. package/src/kit/furniture.ts +108 -0
  280. package/src/kit/geometry.ts +49 -0
  281. package/src/kit/mark.ts +131 -0
  282. package/src/kit/part-fills.ts +61 -0
  283. package/src/kit/place.ts +101 -0
  284. package/src/kit/placement.ts +8 -0
  285. package/src/kit/sampler.ts +281 -0
  286. package/src/kit/scale.ts +39 -0
  287. package/src/kit/source.ts +57 -0
  288. package/src/kit/system.ts +99 -0
  289. package/src/kit/ticks.ts +85 -0
  290. package/src/kit/withdrawn.ts +8 -0
  291. package/src/marks/curve-area.ts +89 -0
  292. package/src/marks/drop-lines.ts +63 -0
  293. package/src/marks/plot-point.ts +107 -0
  294. package/src/marks/riemann-sum.ts +98 -0
  295. package/src/marks/tangent-line.ts +103 -0
  296. package/src/marks/vector-arrow.ts +98 -0
  297. package/src/nodes.ts +63 -0
  298. package/src/plots/function-plot.ts +236 -0
  299. package/src/plots/points-plot.ts +107 -0
  300. package/src/plots/stream-lines.ts +151 -0
  301. package/src/plots/traced-path.ts +52 -0
  302. package/src/plots/vector-field.ts +88 -0
  303. package/src/structures/graph-layout.ts +145 -0
  304. package/src/structures/network-graph.ts +308 -0
  305. package/src/structures/sample-space.ts +209 -0
  306. package/src/systems/axes2d.ts +217 -0
  307. package/src/systems/number-line.ts +131 -0
  308. package/src/systems/number-plane.ts +203 -0
  309. package/src/systems/polar-plane.ts +176 -0
  310. package/src/tex/geometry.ts +703 -0
  311. package/src/tex/index.ts +14 -0
  312. package/src/tex/mathjax.ts +82 -0
  313. package/src/tex/matrix.ts +75 -0
  314. package/src/tex/node.ts +641 -0
  315. package/src/tex/tween.ts +308 -0
  316. package/src/three/axes3d.ts +240 -0
  317. package/src/three/curve-plot3d.ts +147 -0
  318. package/src/three/label3d.ts +50 -0
  319. package/src/three/plot-point3d.ts +66 -0
  320. package/src/three/space.ts +67 -0
  321. package/src/three/surface-plot3d.ts +323 -0
  322. package/src/three/vector-arrow3d.ts +77 -0
@@ -0,0 +1,641 @@
1
+ import {
2
+ RenderContext2D, Graphics2D, EasingFunction, command, node, lerpNumber, NodeConfig, pathOps, ShapeNode, ShapeProps,
3
+ InsetsProps, Size2D, SizeConstraints, toPathString, InsetsResolved, property, insetsProperty, FillResolved, ShadowResolved,
4
+ StrokeResolved, driveCommand, fillOps, withdraw, type AssetScope, type BoxBounds, type Command, type CommandArgs, type Fill,
5
+ type TweenStepper,
6
+ } from "@motionscript/sdk";
7
+ // From each module, never the `../engine` barrel: it re-exports this file, so a
8
+ // load that enters through the barrel runs this class's decorators before
9
+ // `OUTLINE_TRIM` exists and the kit fails to import.
10
+ import {
11
+ blankLatex, buildLatexPath, findLatexParts, LatexNotLoaded, loadMathJax, MATHJAX_LOADER,
12
+ type LatexPart, type LatexToken,
13
+ } from "./geometry";
14
+ import { defaultLatexMorph, type AnimatedToken, type LatexMorphStrategy } from "./tween";
15
+ import {
16
+ lerpPartFills, partPaint, readPartFills, withPartFill, type PartFill, type PartFillResolved,
17
+ } from "../kit/part-fills";
18
+ import { OUTLINE_TRIM } from "../kit/withdrawn";
19
+
20
+ export interface LatexProps extends ShapeProps {
21
+ latex: string;
22
+ fontSize: number;
23
+ padding: InsetsProps;
24
+ partFills: PartFill[];
25
+ written: number;
26
+ }
27
+
28
+ /** How much of one glyph's writing overlaps the next one's. */
29
+ const WRITE_OVERLAP = 0.6;
30
+ /** The outline a glyph is written with, as a share of the type size. */
31
+ const WRITE_STROKE = 1 / 32;
32
+
33
+ /**
34
+ * Construction-time-only options: pluggable engine behavior, set once when
35
+ * the node is created. Deliberately *not* part of {@link LatexProps} — every
36
+ * `@property` field accepts either a value or a zero-arg reactive binding
37
+ * (`value | (() => value)`, see `PropInputs`), and the node's own reactive
38
+ * write path (`_writeProp`) treats any function value as the latter. A
39
+ * strategy *is* a function, so it can't be told apart from a binding that
40
+ * computes one — it has to stay outside the reactive prop system entirely.
41
+ */
42
+ export interface LatexStrategies {
43
+ /** How the node morphs between two formulas. Defaults to `defaultLatexMorph`. */
44
+ morph?: LatexMorphStrategy;
45
+ }
46
+
47
+ @node({
48
+ key: "latex",
49
+ parentKey: "shape",
50
+ forkable: true,
51
+ layout: {
52
+ children: "freeform",
53
+ defaultWidthMode: "hug",
54
+ defaultHeightMode: "hug",
55
+ acceptsChildren: true,
56
+ },
57
+ seed: {
58
+ fill: [
59
+ {
60
+ type: "solid",
61
+ color: [
62
+ 0.412,
63
+ 0.565,
64
+ 0.867,
65
+ 1,
66
+ ],
67
+ opacity: 1,
68
+ enabled: true,
69
+ },
70
+ ],
71
+ },
72
+ })
73
+ @withdraw(...OUTLINE_TRIM)
74
+ export class Latex extends ShapeNode<LatexProps> {
75
+ @property({ default: "" }) declare readonly latex: string;
76
+ @property({ default: 16 }) declare readonly fontSize: number;
77
+ @insetsProperty() declare readonly padding: InsetsResolved;
78
+
79
+ /** Paints for parts of the formula, named by their source. Later entries win where two name a glyph. */
80
+ @property({ default: [], mapper: readPartFills, tween: lerpPartFills, kind: "vector" }) declare partFills: PartFill[];
81
+
82
+ /**
83
+ * How much of the formula is written, 0 to 1: its glyphs are drawn one after
84
+ * another, each outlined and then filled.
85
+ */
86
+ @property({ default: 1, min: 0, max: 1, step: 0.01 }) declare written: number;
87
+
88
+ /**
89
+ * How this node morphs between two formulas. Construction-time-only (see
90
+ * {@link LatexStrategies}) — resolved once here rather than left as
91
+ * `?? defaultLatexMorph` at every call site.
92
+ */
93
+ private readonly morph: LatexMorphStrategy;
94
+
95
+ private _intrinsicWidth: number = 0;
96
+ private _intrinsicHeight: number = 0;
97
+
98
+ /**
99
+ * Shared center frame for all current tokens, [minX, minY, maxX, maxY] in
100
+ * token space. Passed to every per-token path so glyphs keep their relative
101
+ * layout instead of each centering on its own bbox.
102
+ */
103
+ private _bounds: [number, number, number, number] = [0, 0, 0, 0];
104
+
105
+ /** Current tokens to render. Each has its own opacity for tween transitions. */
106
+ private _tokens: AnimatedToken[] = [];
107
+
108
+ /** The parts of the formula `_tokens` was built from; empty while a morph holds the tokens. */
109
+ private _parts: LatexPart[] = [];
110
+
111
+ /** While a morph holds the tokens: each end's colours by token, and how far between them it is. */
112
+ private _morphFills: { from: TokenFills; to: TokenFills; t: number } | null = null;
113
+
114
+ /**
115
+ * How far through a morph the playhead is, in `(0, 1)` while one is
116
+ * driving frames and `0` otherwise: the node's own signal, not a prop an
117
+ * author states.
118
+ *
119
+ * A prop rather than a field because it is the one thing the timeline
120
+ * restores. The morph writes the tokens, the box and the intrinsic size
121
+ * straight onto the node, so nothing else says whether what is on screen is
122
+ * a morph frame; and a seek from inside a morph to a time before it
123
+ * evaluates no command at all. Restored to `0` with every other prop, this
124
+ * is how the node learns the playhead has left the morph.
125
+ */
126
+ @property({ default: 0, animatable: false }) declare morphProgress: number;
127
+
128
+ /** Suppresses retokenization while a custom to() is driving frames. */
129
+ private _animating: boolean = false;
130
+
131
+ /** The `fontSize|latex` the live tokens were built from. See {@link _ensureTokens}. */
132
+ private _tokenizedFrom: string | null = null;
133
+
134
+ constructor(props?: NodeConfig<Latex, LatexProps> & LatexStrategies) {
135
+ super(props);
136
+ this.morph = props?.morph ?? defaultLatexMorph;
137
+ this.applyProp("width", props?.width ?? "hug");
138
+ this.applyProp("height", props?.height ?? "hug");
139
+
140
+ this._ensureTokens();
141
+ }
142
+
143
+ /**
144
+ * Rebuild the token list when the formula or size has moved since it last
145
+ * was built.
146
+ *
147
+ * Pulled from every reader rather than pushed from a prop write, because
148
+ * `latex` can be a binding — and a binding has no write to hang a
149
+ * subscription on. The key is what the current tokens were built from;
150
+ * `_animating` hands ownership to the morph command for its open interval.
151
+ */
152
+ private _ensureTokens(): void {
153
+ if (this._animating) {
154
+ if (this.morphProgress > 0 && this.morphProgress < 1) return;
155
+ // The playhead left the morph without it committing either end (a seek
156
+ // back to before it evaluates no command), so what is held is a stale
157
+ // morph frame. Hand the tokens back to the props.
158
+ this._animating = false;
159
+ this._morphFills = null;
160
+ this._tokenizedFrom = null;
161
+ }
162
+ const key = `${this.fontSize}|${this._source()}`;
163
+ if (key === this._tokenizedFrom) return;
164
+ // Recorded once the tokens are built, so a formula that cannot be
165
+ // typeset fails on every read instead of the first and then reads as
166
+ // blank. Before MathJax is here the node is blank, and is asked again.
167
+ try {
168
+ this._updateTokens();
169
+ } catch (error) {
170
+ if (!(error instanceof LatexNotLoaded)) throw error;
171
+ this._clearTokens();
172
+ return;
173
+ }
174
+ this._tokenizedFrom = key;
175
+ }
176
+
177
+ /** MathJax, before this node is laid out: a scene with no formula in it never loads it. */
178
+ override declareAssets(assets: AssetScope): void {
179
+ super.declareAssets(assets);
180
+ assets.loader(MATHJAX_LOADER, loadMathJax, { gate: "layout" });
181
+ }
182
+
183
+ /** @internal The formula typeset once `next` is laid over the node's own props: `latex` here, a subclass's own props there. */
184
+ _source(next: Partial<LatexProps> = {}): string {
185
+ return next.latex ?? this.latex;
186
+ }
187
+
188
+ /** @internal The props that state the formula, as `next` leaves them: what a morph commits at its end. */
189
+ _sourceProps(next: Partial<LatexProps> = {}): Partial<LatexProps> {
190
+ return { latex: this._source(next) };
191
+ }
192
+
193
+ /** @internal Whether `next` re-sets the glyphs, and so is a morph rather than an ordinary tween. */
194
+ _resets(next: Partial<LatexProps>): boolean {
195
+ return next.latex !== undefined || next.fontSize !== undefined;
196
+ }
197
+
198
+ private _updateTokens() {
199
+ const source = this._source();
200
+ if (source) {
201
+ const result = buildLatexPath(source, this.fontSize);
202
+ this._intrinsicWidth = result.width;
203
+ this._intrinsicHeight = result.height;
204
+ this._bounds = result.bounds;
205
+ this._parts = result.parts;
206
+ this._tokens = result.tokens.map(t => ({
207
+ token: t.token,
208
+ path: t.path,
209
+ term: t.term,
210
+ opacity: 1,
211
+ x: 0,
212
+ y: 0,
213
+ }));
214
+ } else {
215
+ this._clearTokens();
216
+ }
217
+ }
218
+
219
+ private _clearTokens(): void {
220
+ this._tokens = [];
221
+ this._parts = [];
222
+ this._intrinsicWidth = 0;
223
+ this._intrinsicHeight = 0;
224
+ this._bounds = [0, 0, 0, 0];
225
+ }
226
+
227
+ override measure(constraints: SizeConstraints): Partial<Size2D> {
228
+ this._ensureTokens();
229
+ const pad = this.padding;
230
+ const wm = this.width;
231
+ const hm = this.height;
232
+
233
+ const resolvedW = typeof wm === "number"
234
+ ? wm
235
+ : wm === "hug"
236
+ ? this._intrinsicWidth + pad.left + pad.right
237
+ : constraints.maxWidth ?? 0;
238
+
239
+ const resolvedH = typeof hm === "number"
240
+ ? hm
241
+ : hm === "hug"
242
+ ? this._intrinsicHeight + pad.top + pad.bottom
243
+ : constraints.maxHeight ?? 0;
244
+
245
+ return { width: resolvedW, height: resolvedH };
246
+ }
247
+
248
+ /**
249
+ * A LaTeX morph — one {@link Command}, like every other `to()`.
250
+ *
251
+ * Sequence two of them with `sequence(...)` rather than chaining: the chain
252
+ * builder this used to return existed only so `latexRef().to(a, 1).to(b, 1)`
253
+ * would read as two steps, and it could not compose with anything that was
254
+ * not another Latex morph.
255
+ */
256
+ override to<D extends Partial<LatexProps> = Partial<LatexProps>>(args: CommandArgs<D> & { duration: number }): Command<LatexProps> {
257
+ const data: Partial<LatexProps> = args.data ?? {};
258
+ // Only a new formula or size re-sets the glyphs; anything else is an ordinary tween.
259
+ if (!this._resets(data)) return super.to(args) as Command<LatexProps>;
260
+ return this._buildMorph(data, args.duration, args.easing);
261
+ }
262
+
263
+ /**
264
+ * Morph this formula into another — a document-facing name for {@link to},
265
+ * which already routes through {@link _buildMorph}.
266
+ */
267
+ @command({ args: [{ key: "latex", kind: "text", multiline: true }] })
268
+ morphTo(args: CommandArgs<{ latex: string }> & { duration: number }): Command<LatexProps> {
269
+ return this.to({ data: { latex: args.data?.latex } as Partial<LatexProps>, duration: args.duration, easing: args.easing });
270
+ }
271
+
272
+ /** Write the formula on, or off: its glyphs one after another, each outlined and then filled. */
273
+ @command({ args: ["written"] })
274
+ writeTo(args: CommandArgs<{ written: number }> & { duration: number }): Command<LatexProps> {
275
+ const written = args.data?.written;
276
+ return super.to({ data: written === undefined ? {} : { written }, duration: args.duration, easing: args.easing });
277
+ }
278
+
279
+ /** Paint one part of the formula, leaving the rest as it is. */
280
+ @command({
281
+ args: [
282
+ { key: "part", kind: "text", default: "" },
283
+ { key: "fill", kind: "fills", default: "#facc15" },
284
+ { key: "occurrence", kind: "number", min: 0, step: 1, default: 0 },
285
+ ],
286
+ })
287
+ partFillTo(args: CommandArgs<{ part: string; fill: Fill; occurrence?: number }> & { duration: number }): Command<LatexProps> {
288
+ const { part, fill, occurrence = 0 } = args.data ?? {};
289
+ if (!part || fill == null) return super.to({ data: {}, duration: args.duration, easing: args.easing });
290
+ const partFills = withPartFill(this.partFills as unknown as PartFillResolved[], { part, fill, occurrence });
291
+ return super.to({ data: { partFills }, duration: args.duration, easing: args.easing });
292
+ }
293
+
294
+ /**
295
+ * The box around one part of the formula, centred on the node's own centre
296
+ * and y-up, or `null` when the formula does not write `part`. `occurrence`
297
+ * counts from 1.
298
+ */
299
+ partBounds(part: string, occurrence = 1): BoxBounds | null {
300
+ this._ensureTokens();
301
+ const span = findLatexParts(this._parts, part)[Math.max(1, Math.round(occurrence)) - 1];
302
+ if (!span) return null;
303
+ const box = pathOps.bounds(this._tokens.slice(span[0], span[1]).flatMap((token) => token.path));
304
+ if (!box) return null;
305
+ const [minX, minY, maxX, maxY] = this._bounds;
306
+ const cx = (minX + maxX) / 2;
307
+ const cy = (minY + maxY) / 2;
308
+ return {
309
+ x: (box.minX + box.maxX) / 2 - cx,
310
+ y: cy - (box.minY + box.maxY) / 2,
311
+ width: box.maxX - box.minX,
312
+ height: box.maxY - box.minY,
313
+ };
314
+ }
315
+
316
+ /**
317
+ * Build a single LaTeX morph as a {@link Command}: every ordinary
318
+ * `ShapeProps` field (via the inherited `_prepareStep`), plus the
319
+ * intrinsic size, shared center frame and per-glyph token list — state a
320
+ * plain `set()` can't reach — driven together by one eased `t`, matching
321
+ * the concurrent `parallel` the generator version ran.
322
+ *
323
+ * The "from" snapshot (`fromTokens`, `fromLatex`, …) is captured
324
+ * **lazily, on the command's first evaluation**, not when this is called.
325
+ * That is what lets two morphs be sequenced: `commandSequence` settles each
326
+ * prior step before evaluating the next, so a second morph's "from" reads
327
+ * the first one's end state rather than whatever the node held before either
328
+ * of them ran.
329
+ *
330
+ * `_animating` suppresses {@link _ensureTokens} for the open interval, and
331
+ * both ends commit: `t === 1`
332
+ * lands on the target formula, `t === 0` restores the source one — the same
333
+ * "membership for the open interval, commit at either end" shape
334
+ * `packages/components/code`'s `runTransition` uses, so seeking into either
335
+ * side of the morph (not just running it forward) shows the right thing.
336
+ *
337
+ * `@internal` — the entry point for authors is {@link to}.
338
+ */
339
+ _buildMorph(to: Partial<LatexProps>, duration: number, easing?: EasingFunction): Command<LatexProps> {
340
+ // Not in a tree: no box, no timeline. The command keeps its length and
341
+ // writes nothing, as every command built through `Node` does.
342
+ if (!this.mounted) return driveCommand(duration, () => { }) as Command<LatexProps>;
343
+ let setupDone = false;
344
+ let fromAnimTokens: AnimatedToken[] = [];
345
+ let fromLatex = "";
346
+ let fromProps: Partial<LatexProps> = {};
347
+ let fromFontSize = 0;
348
+ let fromWidth = 0;
349
+ let fromHeight = 0;
350
+ let fromBounds: [number, number, number, number] = [0, 0, 0, 0];
351
+ let fromParts: LatexPart[] = [];
352
+ let fromFills: TokenFills = [];
353
+ let toFills: TokenFills = [];
354
+ let toFontSize = 0;
355
+ let toLatex = "";
356
+ let toResult: ReturnType<typeof buildLatexPath>;
357
+ let propStep: TweenStepper;
358
+ let latexFrame: (t: number) => AnimatedToken[];
359
+
360
+ const setup = (): void => {
361
+ setupDone = true;
362
+ this._ensureTokens();
363
+ const fromTokens: LatexToken[] = this._tokens.map(t => ({ token: t.token, path: t.path, term: t.term }));
364
+ fromAnimTokens = this._tokens.map(t => ({ ...t }));
365
+ fromLatex = this._source();
366
+ fromProps = this._sourceProps();
367
+ fromFontSize = this.fontSize;
368
+ fromWidth = this._intrinsicWidth;
369
+ fromHeight = this._intrinsicHeight;
370
+ fromBounds = this._bounds;
371
+ fromParts = this._parts;
372
+
373
+ toFontSize = to.fontSize !== undefined ? to.fontSize : this.fontSize;
374
+ toLatex = this._source(to);
375
+ try {
376
+ toResult = buildLatexPath(toLatex, toFontSize);
377
+ } catch (error) {
378
+ if (!(error instanceof LatexNotLoaded)) throw error;
379
+ toResult = blankLatex();
380
+ }
381
+
382
+ propStep = this._prepareStep(to, duration);
383
+ latexFrame = this.morph(fromTokens, toResult.tokens);
384
+ const partFills = this.partFills as unknown as PartFillResolved[];
385
+ fromFills = fillsByToken(partFills, fromParts, fromTokens.length);
386
+ toFills = fillsByToken(partFills, toResult.parts, toResult.tokens.length);
387
+ };
388
+
389
+ return driveCommand(duration, (t) => {
390
+ if (!setupDone) setup();
391
+ const toBounds = toResult.bounds;
392
+
393
+ this._animating = true;
394
+ this.morphProgress = t;
395
+ propStep.seek(t * duration);
396
+ this.set({ fontSize: lerpNumber(fromFontSize, toFontSize, t) });
397
+ // Track the measured size so a hugging box grows/shrinks smoothly
398
+ // across the morph rather than jumping when the end commits.
399
+ this._intrinsicWidth = lerpNumber(fromWidth, toResult.width, t);
400
+ this._intrinsicHeight = lerpNumber(fromHeight, toResult.height, t);
401
+ // Interpolate the shared center frame in lockstep so glyphs stay
402
+ // centered within the resizing box.
403
+ this._bounds = [
404
+ lerpNumber(fromBounds[0], toBounds[0], t),
405
+ lerpNumber(fromBounds[1], toBounds[1], t),
406
+ lerpNumber(fromBounds[2], toBounds[2], t),
407
+ lerpNumber(fromBounds[3], toBounds[3], t),
408
+ ];
409
+ this._tokens = latexFrame(t);
410
+ this._parts = [];
411
+ this._morphFills = { from: fromFills, to: toFills, t };
412
+
413
+ if (t >= 1) {
414
+ this.set({ ...this._sourceProps(to), fontSize: toFontSize });
415
+ this._parts = toResult.parts;
416
+ this._tokens = toResult.tokens.map(tok => ({ token: tok.token, path: tok.path, term: tok.term, opacity: 1, x: 0, y: 0 }));
417
+ this._intrinsicWidth = toResult.width;
418
+ this._intrinsicHeight = toResult.height;
419
+ this._bounds = toResult.bounds;
420
+ this._animating = false;
421
+ this._morphFills = null;
422
+ this.morphProgress = 0;
423
+ this._tokenizedFrom = `${toFontSize}|${toLatex}`;
424
+ } else if (t <= 0) {
425
+ this.set({ ...fromProps, fontSize: fromFontSize });
426
+ this._parts = fromParts;
427
+ this._tokens = fromAnimTokens;
428
+ this._intrinsicWidth = fromWidth;
429
+ this._intrinsicHeight = fromHeight;
430
+ this._bounds = fromBounds;
431
+ this._animating = false;
432
+ this._morphFills = null;
433
+ this.morphProgress = 0;
434
+ this._tokenizedFrom = `${fromFontSize}|${fromLatex}`;
435
+ }
436
+ }, easing) as Command<LatexProps>;
437
+ }
438
+
439
+ /**
440
+ * The shadow op comes **first**, as it does on every other painted node.
441
+ *
442
+ * The renderer does not draw a shadow when it sees one: `.shadow()` stores
443
+ * it pending and the *next* fill or stroke op casts it (`_shadow` →
444
+ * `storePendingShadows`, `_fill`/`_stroke` → `takePendingShadows`). Appended
445
+ * last, it was stored by every token and then thrown away by the reset at
446
+ * the end of the draw — a shadow set on a LaTeX node simply never appeared,
447
+ * with no error to say why. Same failure {@link PaintedNode.renderStroke}
448
+ * documents for a fill-less stroked shape, and the same one-op fix.
449
+ *
450
+ * Order also carries the fill-less case for free: an empty fill returns
451
+ * before it takes the pending shadow, so the stroke below casts it from the
452
+ * glyph outlines instead — which is what `castsShadowFromStroke` arranges on
453
+ * a plain shape.
454
+ */
455
+ protected renderSelf(ctx: RenderContext2D): void {
456
+ const fills = this.fill as FillResolved[];
457
+ const shadows = this.shadow as ShadowResolved[];
458
+ const partOf = this._tokenFills();
459
+ const writing = this._writing();
460
+ this.eachToken(ctx, (graphics, opacity, index, token) => {
461
+ const fill = partPaint(fills, partOf(index, token));
462
+ const pen = writing?.(index);
463
+ if (!pen) {
464
+ return graphics
465
+ .shadow(scaleShadowOpacity(shadows, opacity))
466
+ .fill(scaleFillopacity(fill, opacity))
467
+ .stroke(this.stroke);
468
+ }
469
+ if (pen.filled <= 0) return null;
470
+ return graphics
471
+ .shadow(scaleShadowOpacity(shadows, opacity * pen.filled))
472
+ .fill(scaleFillopacity(fill, opacity * pen.filled))
473
+ .stroke(this.stroke);
474
+ });
475
+ if (!writing) return;
476
+ // The pen's line: each glyph's outline, in its own colour, ahead of its fill.
477
+ const own = this.stroke as StrokeResolved[];
478
+ this.eachToken(ctx, (graphics, opacity, index, token) => {
479
+ const pen = writing(index);
480
+ if (!pen || pen.filled >= 1 || pen.outlined <= 0) return null;
481
+ const fill = scaleFillopacity(partPaint(fills, partOf(index, token)), opacity * (1 - pen.filled));
482
+ return graphics.stroke(own.length > 0 ? own : penStroke(this.fontSize * WRITE_STROKE, fill));
483
+ }, (index) => writing(index)?.outlined ?? 1);
484
+ }
485
+
486
+ /** Each token's part fill: by its place in the formula at rest, by both ends' mid-morph. */
487
+ private _tokenFills(): (index: number, token: AnimatedToken) => PartFillResolved | undefined {
488
+ const morph = this._morphFills;
489
+ if (morph) {
490
+ return (_index, token) => {
491
+ const a = token.from === undefined ? undefined : morph.from[token.from];
492
+ const b = token.to === undefined ? undefined : morph.to[token.to];
493
+ if (a && b) return { ...b, fill: fillOps.lerp(a.fill, b.fill, morph.t), mix: lerpNumber(a.mix, b.mix, morph.t) };
494
+ if (a) return token.to === undefined ? a : { ...a, mix: a.mix * (1 - morph.t) };
495
+ if (b) return token.from === undefined ? b : { ...b, mix: b.mix * morph.t };
496
+ return undefined;
497
+ };
498
+ }
499
+ const partFills = this.partFills as unknown as PartFillResolved[];
500
+ if (partFills.length === 0) return () => undefined;
501
+ const byToken = fillsByToken(partFills, this._parts, this._tokens.length);
502
+ return (index) => byToken[index];
503
+ }
504
+
505
+ /**
506
+ * How far each glyph is written at the node's `written`: its outline first,
507
+ * then its fill, each glyph starting before the one ahead of it is done.
508
+ * `null` once the whole formula is.
509
+ */
510
+ private _writing(): ((index: number) => { outlined: number; filled: number }) | null {
511
+ const written = this.written;
512
+ if (written >= 1) return null;
513
+ const count = this._tokens.length;
514
+ const lead = 1 - WRITE_OVERLAP;
515
+ const span = 1 / (1 + Math.max(0, count - 1) * lead);
516
+ return (index) => {
517
+ const p = Math.min(1, Math.max(0, (written - index * span * lead) / span));
518
+ return { outlined: Math.min(1, p * 2), filled: Math.max(0, p * 2 - 1) };
519
+ };
520
+ }
521
+
522
+ /**
523
+ * The overlay, painted *through* the glyphs.
524
+ *
525
+ * `ShapeNode`'s inherited overlay pass fills whatever {@link
526
+ * ShapeNode.shapeGraphics} describes, and this node describes nothing there:
527
+ * a formula has no single fillable silhouette — its silhouette *is* the list
528
+ * of token paths, which is why `renderSelf` is overridden rather than a
529
+ * `shapeGraphics` supplied. So the generic pass drew nothing and an overlay
530
+ * set on a LaTeX node simply never appeared, with no error to say why.
531
+ *
532
+ * Painted the same way the fill is: one `Graphics2D` per token, all sharing the
533
+ * centre frame, each scaled by its token's animated opacity — so a morph
534
+ * carries the overlay along with the glyph it is laid over instead of leaving
535
+ * a wash hanging over glyphs that have faded out.
536
+ *
537
+ * The stroke is *not* re-drawn here. `renderSelf` already strokes each token
538
+ * (there is no silhouette for the deferred {@link ShapeNode.renderStroke} to
539
+ * outline), so it is painted under the overlay rather than over it — the one
540
+ * place this node's draw order differs from a plain shape's, and the price of
541
+ * a stroke that follows glyphs rather than a box.
542
+ */
543
+ protected override renderOverlay(ctx: RenderContext2D): void {
544
+ const overlay = this.overlay as FillResolved[];
545
+ if (overlay.length === 0) return;
546
+ const writing = this._writing();
547
+ this.eachToken(ctx, (graphics, opacity, index) => {
548
+ const filled = writing?.(index).filled ?? 1;
549
+ return filled <= 0 ? null : graphics.fill(scaleFillopacity(overlay, opacity * filled));
550
+ });
551
+ }
552
+
553
+ /**
554
+ * Draws every visible token's path once, handing each one to `paint` to have
555
+ * its paint ops appended.
556
+ *
557
+ * A fresh `Graphics2D` per token per pass, because `.fill()`/`.stroke()` push
558
+ * onto one op list and return `this` — a silhouette shared between the fill
559
+ * pass and the overlay pass would accumulate both.
560
+ */
561
+ private eachToken(
562
+ ctx: RenderContext2D,
563
+ paint: (graphics: Graphics2D, opacity: number, index: number, token: AnimatedToken) => Graphics2D | null,
564
+ drawn: (index: number) => number = () => 1,
565
+ ): void {
566
+ // The one funnel every paint pass goes through, so the tokens a frame
567
+ // draws cannot be older than the formula it holds.
568
+ this._ensureTokens();
569
+ this._tokens.forEach((token, index) => {
570
+ if (token.opacity <= 0) return;
571
+
572
+ // Translate the path by token's interpolated position offset
573
+ const pathStr = token.x !== 0 || token.y !== 0
574
+ ? toPathString(offsetPath(token.path, token.x, token.y))
575
+ : toPathString(token.path);
576
+
577
+ const painted = paint(new Graphics2D()
578
+ .path({
579
+ data: pathStr,
580
+ start: this.start,
581
+ end: this.end * drawn(index),
582
+ // All tokens share one center frame so they keep their relative
583
+ // layout — without this each glyph centers on its own bbox and
584
+ // they all stack on the origin.
585
+ centerBounds: this._bounds,
586
+ }), token.opacity, index, token);
587
+ if (painted) ctx.draw(painted);
588
+ });
589
+ }
590
+
591
+ }
592
+
593
+ function penStroke(weight: number, fill: FillResolved[]): StrokeResolved[] {
594
+ return [{ weight, fill, dashOffset: 0, align: 0, cap: "round", capScale: 4, join: "round", miterLimit: 4 }];
595
+ }
596
+
597
+ /** One part fill per token, or none: the last entry that names it. */
598
+ type TokenFills = (PartFillResolved | undefined)[];
599
+
600
+ function fillsByToken(partFills: readonly PartFillResolved[], parts: readonly LatexPart[], count: number): TokenFills {
601
+ const out: TokenFills = new Array(count);
602
+ for (const entry of partFills) {
603
+ if (entry.part.trim() === "") continue;
604
+ const spans = findLatexParts(parts, entry.part);
605
+ for (const [from, to] of entry.occurrence > 0 ? spans.slice(entry.occurrence - 1, entry.occurrence) : spans) {
606
+ for (let i = from; i < to && i < count; i++) out[i] = entry;
607
+ }
608
+ }
609
+ return out;
610
+ }
611
+
612
+ function scaleFillopacity(fills: FillResolved[], opacity: number): FillResolved[] {
613
+ if (opacity >= 1) return fills;
614
+ return fills.map(f => ({ ...f, opacity: (f.opacity ?? 1) * opacity }));
615
+ }
616
+
617
+ /**
618
+ * A morphing token fades, and its shadow has to fade with it — the paints are
619
+ * scaled the same way the fill's are, so a half-faded glyph casts a half-strength
620
+ * shadow rather than sitting over a shadow at full weight.
621
+ */
622
+ function scaleShadowOpacity(shadows: ShadowResolved[], opacity: number): ShadowResolved[] {
623
+ if (opacity >= 1) return shadows;
624
+ return shadows.map(s => ({ ...s, fill: scaleFillopacity(s.fill, opacity) }));
625
+ }
626
+
627
+ function offsetPath(
628
+ path: LatexToken["path"],
629
+ dx: number,
630
+ dy: number,
631
+ ): LatexToken["path"] {
632
+ return path.map(cmd => {
633
+ const c = cmd as any;
634
+ const shifted: any = { ...c };
635
+ if ("x" in c) shifted.x = c.x + dx;
636
+ if ("y" in c) shifted.y = c.y + dy;
637
+ if ("x1" in c) { shifted.x1 = c.x1 + dx; shifted.y1 = c.y1 + dy; }
638
+ if ("x2" in c) { shifted.x2 = c.x2 + dx; shifted.y2 = c.y2 + dy; }
639
+ return shifted;
640
+ });
641
+ }