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

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 (335) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +49 -0
  4. package/README.md +389 -2
  5. package/dist/annotate/angle-mark.d.ts +96 -0
  6. package/dist/annotate/angle-mark.d.ts.map +1 -0
  7. package/dist/annotate/angle-mark.js +97 -0
  8. package/dist/annotate/angle-mark.js.map +1 -0
  9. package/dist/annotate/curly-brace.d.ts +115 -0
  10. package/dist/annotate/curly-brace.d.ts.map +1 -0
  11. package/dist/annotate/curly-brace.js +99 -0
  12. package/dist/annotate/curly-brace.js.map +1 -0
  13. package/dist/annotate/emphasis-mark.d.ts +80 -0
  14. package/dist/annotate/emphasis-mark.d.ts.map +1 -0
  15. package/dist/annotate/emphasis-mark.js +80 -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-IRZCG6PM.js +2 -0
  19. package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
  20. package/dist/browser/chunks/chunk-WMVW6ZIV.js +2 -0
  21. package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
  22. package/dist/browser/chunks/mathjax-WV55AC2P.js +61 -0
  23. package/dist/browser/chunks/mathjax-WV55AC2P.js.map +7 -0
  24. package/dist/browser/index.js +2 -0
  25. package/dist/browser/index.js.map +7 -0
  26. package/dist/browser/kit.js +2 -0
  27. package/dist/browser/kit.js.map +7 -0
  28. package/dist/browser/manifest.json +30 -0
  29. package/dist/browser/tex.js +2 -0
  30. package/dist/browser/tex.js.map +7 -0
  31. package/dist/engine.d.ts +71 -0
  32. package/dist/engine.d.ts.map +1 -0
  33. package/dist/engine.js +45 -0
  34. package/dist/engine.js.map +1 -0
  35. package/dist/index.d.ts +30 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +30 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/kit/brace.d.ts +8 -0
  40. package/dist/kit/brace.d.ts.map +1 -0
  41. package/dist/kit/brace.js +36 -0
  42. package/dist/kit/brace.js.map +1 -0
  43. package/dist/kit/cache.d.ts +30 -0
  44. package/dist/kit/cache.d.ts.map +1 -0
  45. package/dist/kit/cache.js +53 -0
  46. package/dist/kit/cache.js.map +1 -0
  47. package/dist/kit/component.d.ts +51 -0
  48. package/dist/kit/component.d.ts.map +1 -0
  49. package/dist/kit/component.js +30 -0
  50. package/dist/kit/component.js.map +1 -0
  51. package/dist/kit/contour.d.ts +8 -0
  52. package/dist/kit/contour.d.ts.map +1 -0
  53. package/dist/kit/contour.js +93 -0
  54. package/dist/kit/contour.js.map +1 -0
  55. package/dist/kit/coords.d.ts +69 -0
  56. package/dist/kit/coords.d.ts.map +1 -0
  57. package/dist/kit/coords.js +224 -0
  58. package/dist/kit/coords.js.map +1 -0
  59. package/dist/kit/curve.d.ts +28 -0
  60. package/dist/kit/curve.d.ts.map +1 -0
  61. package/dist/kit/curve.js +29 -0
  62. package/dist/kit/curve.js.map +1 -0
  63. package/dist/kit/equation.d.ts +61 -0
  64. package/dist/kit/equation.d.ts.map +1 -0
  65. package/dist/kit/equation.js +168 -0
  66. package/dist/kit/equation.js.map +1 -0
  67. package/dist/kit/equation3d.d.ts +50 -0
  68. package/dist/kit/equation3d.d.ts.map +1 -0
  69. package/dist/kit/equation3d.js +103 -0
  70. package/dist/kit/equation3d.js.map +1 -0
  71. package/dist/kit/expression.d.ts +35 -0
  72. package/dist/kit/expression.d.ts.map +1 -0
  73. package/dist/kit/expression.js +124 -0
  74. package/dist/kit/expression.js.map +1 -0
  75. package/dist/kit/field-mark.d.ts +79 -0
  76. package/dist/kit/field-mark.d.ts.map +1 -0
  77. package/dist/kit/field-mark.js +109 -0
  78. package/dist/kit/field-mark.js.map +1 -0
  79. package/dist/kit/field.d.ts +14 -0
  80. package/dist/kit/field.d.ts.map +1 -0
  81. package/dist/kit/field.js +46 -0
  82. package/dist/kit/field.js.map +1 -0
  83. package/dist/kit/follow.d.ts +109 -0
  84. package/dist/kit/follow.d.ts.map +1 -0
  85. package/dist/kit/follow.js +163 -0
  86. package/dist/kit/follow.js.map +1 -0
  87. package/dist/kit/furniture.d.ts +32 -0
  88. package/dist/kit/furniture.d.ts.map +1 -0
  89. package/dist/kit/furniture.js +92 -0
  90. package/dist/kit/furniture.js.map +1 -0
  91. package/dist/kit/geometry.d.ts +13 -0
  92. package/dist/kit/geometry.d.ts.map +1 -0
  93. package/dist/kit/geometry.js +54 -0
  94. package/dist/kit/geometry.js.map +1 -0
  95. package/dist/kit/graph.d.ts +46 -0
  96. package/dist/kit/graph.d.ts.map +1 -0
  97. package/dist/kit/graph.js +90 -0
  98. package/dist/kit/graph.js.map +1 -0
  99. package/dist/kit/mark.d.ts +72 -0
  100. package/dist/kit/mark.d.ts.map +1 -0
  101. package/dist/kit/mark.js +87 -0
  102. package/dist/kit/mark.js.map +1 -0
  103. package/dist/kit/part-fills.d.ts +23 -0
  104. package/dist/kit/part-fills.d.ts.map +1 -0
  105. package/dist/kit/part-fills.js +46 -0
  106. package/dist/kit/part-fills.js.map +1 -0
  107. package/dist/kit/place.d.ts +20 -0
  108. package/dist/kit/place.d.ts.map +1 -0
  109. package/dist/kit/place.js +66 -0
  110. package/dist/kit/place.js.map +1 -0
  111. package/dist/kit/sampler.d.ts +17 -0
  112. package/dist/kit/sampler.d.ts.map +1 -0
  113. package/dist/kit/sampler.js +250 -0
  114. package/dist/kit/sampler.js.map +1 -0
  115. package/dist/kit/scale.d.ts +12 -0
  116. package/dist/kit/scale.d.ts.map +1 -0
  117. package/dist/kit/scale.js +37 -0
  118. package/dist/kit/scale.js.map +1 -0
  119. package/dist/kit/source.d.ts +22 -0
  120. package/dist/kit/source.d.ts.map +1 -0
  121. package/dist/kit/source.js +45 -0
  122. package/dist/kit/source.js.map +1 -0
  123. package/dist/kit/system.d.ts +31 -0
  124. package/dist/kit/system.d.ts.map +1 -0
  125. package/dist/kit/system.js +71 -0
  126. package/dist/kit/system.js.map +1 -0
  127. package/dist/kit/ticks.d.ts +19 -0
  128. package/dist/kit/ticks.d.ts.map +1 -0
  129. package/dist/kit/ticks.js +78 -0
  130. package/dist/kit/ticks.js.map +1 -0
  131. package/dist/kit/withdrawn.d.ts +9 -0
  132. package/dist/kit/withdrawn.d.ts.map +1 -0
  133. package/dist/kit/withdrawn.js +9 -0
  134. package/dist/kit/withdrawn.js.map +1 -0
  135. package/dist/marks/curve-area.d.ts +51 -0
  136. package/dist/marks/curve-area.d.ts.map +1 -0
  137. package/dist/marks/curve-area.js +59 -0
  138. package/dist/marks/curve-area.js.map +1 -0
  139. package/dist/marks/drop-lines.d.ts +57 -0
  140. package/dist/marks/drop-lines.d.ts.map +1 -0
  141. package/dist/marks/drop-lines.js +43 -0
  142. package/dist/marks/drop-lines.js.map +1 -0
  143. package/dist/marks/plot-point.d.ts +71 -0
  144. package/dist/marks/plot-point.d.ts.map +1 -0
  145. package/dist/marks/plot-point.js +71 -0
  146. package/dist/marks/plot-point.js.map +1 -0
  147. package/dist/marks/riemann-sum.d.ts +58 -0
  148. package/dist/marks/riemann-sum.d.ts.map +1 -0
  149. package/dist/marks/riemann-sum.js +63 -0
  150. package/dist/marks/riemann-sum.js.map +1 -0
  151. package/dist/marks/tangent-line.d.ts +71 -0
  152. package/dist/marks/tangent-line.d.ts.map +1 -0
  153. package/dist/marks/tangent-line.js +89 -0
  154. package/dist/marks/tangent-line.js.map +1 -0
  155. package/dist/marks/vector-arrow.d.ts +60 -0
  156. package/dist/marks/vector-arrow.d.ts.map +1 -0
  157. package/dist/marks/vector-arrow.js +67 -0
  158. package/dist/marks/vector-arrow.js.map +1 -0
  159. package/dist/nodes.d.ts +43 -0
  160. package/dist/nodes.d.ts.map +1 -0
  161. package/dist/nodes.js +57 -0
  162. package/dist/nodes.js.map +1 -0
  163. package/dist/plots/function-plot.d.ts +159 -0
  164. package/dist/plots/function-plot.d.ts.map +1 -0
  165. package/dist/plots/function-plot.js +184 -0
  166. package/dist/plots/function-plot.js.map +1 -0
  167. package/dist/plots/points-plot.d.ts +64 -0
  168. package/dist/plots/points-plot.d.ts.map +1 -0
  169. package/dist/plots/points-plot.js +72 -0
  170. package/dist/plots/points-plot.js.map +1 -0
  171. package/dist/plots/stream-lines.d.ts +76 -0
  172. package/dist/plots/stream-lines.d.ts.map +1 -0
  173. package/dist/plots/stream-lines.js +122 -0
  174. package/dist/plots/stream-lines.js.map +1 -0
  175. package/dist/plots/traced-path.d.ts +70 -0
  176. package/dist/plots/traced-path.d.ts.map +1 -0
  177. package/dist/plots/traced-path.js +41 -0
  178. package/dist/plots/traced-path.js.map +1 -0
  179. package/dist/plots/vector-field.d.ts +60 -0
  180. package/dist/plots/vector-field.d.ts.map +1 -0
  181. package/dist/plots/vector-field.js +77 -0
  182. package/dist/plots/vector-field.js.map +1 -0
  183. package/dist/structures/graph-layout.d.ts +11 -0
  184. package/dist/structures/graph-layout.d.ts.map +1 -0
  185. package/dist/structures/graph-layout.js +135 -0
  186. package/dist/structures/graph-layout.js.map +1 -0
  187. package/dist/structures/network-graph.d.ts +174 -0
  188. package/dist/structures/network-graph.d.ts.map +1 -0
  189. package/dist/structures/network-graph.js +240 -0
  190. package/dist/structures/network-graph.js.map +1 -0
  191. package/dist/structures/sample-space.d.ts +114 -0
  192. package/dist/structures/sample-space.d.ts.map +1 -0
  193. package/dist/structures/sample-space.js +161 -0
  194. package/dist/structures/sample-space.js.map +1 -0
  195. package/dist/systems/axes2d.d.ts +197 -0
  196. package/dist/systems/axes2d.d.ts.map +1 -0
  197. package/dist/systems/axes2d.js +157 -0
  198. package/dist/systems/axes2d.js.map +1 -0
  199. package/dist/systems/number-line.d.ts +101 -0
  200. package/dist/systems/number-line.d.ts.map +1 -0
  201. package/dist/systems/number-line.js +91 -0
  202. package/dist/systems/number-line.js.map +1 -0
  203. package/dist/systems/number-plane.d.ts +168 -0
  204. package/dist/systems/number-plane.d.ts.map +1 -0
  205. package/dist/systems/number-plane.js +186 -0
  206. package/dist/systems/number-plane.js.map +1 -0
  207. package/dist/systems/polar-plane.d.ts +98 -0
  208. package/dist/systems/polar-plane.d.ts.map +1 -0
  209. package/dist/systems/polar-plane.js +139 -0
  210. package/dist/systems/polar-plane.js.map +1 -0
  211. package/dist/tex/geometry.d.ts +85 -0
  212. package/dist/tex/geometry.d.ts.map +1 -0
  213. package/dist/tex/geometry.js +632 -0
  214. package/dist/tex/geometry.js.map +1 -0
  215. package/dist/tex/index.d.ts +11 -0
  216. package/dist/tex/index.d.ts.map +1 -0
  217. package/dist/tex/index.js +10 -0
  218. package/dist/tex/index.js.map +1 -0
  219. package/dist/tex/mathjax.d.ts +33 -0
  220. package/dist/tex/mathjax.d.ts.map +1 -0
  221. package/dist/tex/mathjax.js +74 -0
  222. package/dist/tex/mathjax.js.map +1 -0
  223. package/dist/tex/matrix.d.ts +101 -0
  224. package/dist/tex/matrix.d.ts.map +1 -0
  225. package/dist/tex/matrix.js +56 -0
  226. package/dist/tex/matrix.js.map +1 -0
  227. package/dist/tex/node.d.ts +98 -0
  228. package/dist/tex/node.d.ts.map +1 -0
  229. package/dist/tex/node.js +25 -0
  230. package/dist/tex/node.js.map +1 -0
  231. package/dist/tex/tween.d.ts +50 -0
  232. package/dist/tex/tween.d.ts.map +1 -0
  233. package/dist/tex/tween.js +253 -0
  234. package/dist/tex/tween.js.map +1 -0
  235. package/dist/tex/typeset.d.ts +133 -0
  236. package/dist/tex/typeset.d.ts.map +1 -0
  237. package/dist/tex/typeset.js +403 -0
  238. package/dist/tex/typeset.js.map +1 -0
  239. package/dist/three/axes3d.d.ts +247 -0
  240. package/dist/three/axes3d.d.ts.map +1 -0
  241. package/dist/three/axes3d.js +187 -0
  242. package/dist/three/axes3d.js.map +1 -0
  243. package/dist/three/curve-plot3d.d.ts +126 -0
  244. package/dist/three/curve-plot3d.d.ts.map +1 -0
  245. package/dist/three/curve-plot3d.js +109 -0
  246. package/dist/three/curve-plot3d.js.map +1 -0
  247. package/dist/three/entries.d.ts +17 -0
  248. package/dist/three/entries.d.ts.map +1 -0
  249. package/dist/three/entries.js +15 -0
  250. package/dist/three/entries.js.map +1 -0
  251. package/dist/three/label3d.d.ts +11 -0
  252. package/dist/three/label3d.d.ts.map +1 -0
  253. package/dist/three/label3d.js +42 -0
  254. package/dist/three/label3d.js.map +1 -0
  255. package/dist/three/plot-point3d.d.ts +99 -0
  256. package/dist/three/plot-point3d.d.ts.map +1 -0
  257. package/dist/three/plot-point3d.js +34 -0
  258. package/dist/three/plot-point3d.js.map +1 -0
  259. package/dist/three/space.d.ts +43 -0
  260. package/dist/three/space.d.ts.map +1 -0
  261. package/dist/three/space.js +58 -0
  262. package/dist/three/space.js.map +1 -0
  263. package/dist/three/surface-plot3d.d.ts +207 -0
  264. package/dist/three/surface-plot3d.d.ts.map +1 -0
  265. package/dist/three/surface-plot3d.js +261 -0
  266. package/dist/three/surface-plot3d.js.map +1 -0
  267. package/dist/three/vector-arrow3d.d.ts +96 -0
  268. package/dist/three/vector-arrow3d.d.ts.map +1 -0
  269. package/dist/three/vector-arrow3d.js +53 -0
  270. package/dist/three/vector-arrow3d.js.map +1 -0
  271. package/package.json +80 -3
  272. package/registry.json +251 -0
  273. package/src/annotate/angle-mark.ts +137 -0
  274. package/src/annotate/curly-brace.ts +148 -0
  275. package/src/annotate/emphasis-mark.ts +118 -0
  276. package/src/engine.ts +86 -0
  277. package/src/index.ts +29 -0
  278. package/src/kit/brace.ts +37 -0
  279. package/src/kit/cache.ts +61 -0
  280. package/src/kit/component.ts +57 -0
  281. package/src/kit/contour.ts +94 -0
  282. package/src/kit/coords.ts +278 -0
  283. package/src/kit/curve.ts +47 -0
  284. package/src/kit/equation.ts +181 -0
  285. package/src/kit/equation3d.ts +137 -0
  286. package/src/kit/expression.ts +159 -0
  287. package/src/kit/field-mark.ts +171 -0
  288. package/src/kit/field.ts +50 -0
  289. package/src/kit/follow.ts +229 -0
  290. package/src/kit/furniture.ts +113 -0
  291. package/src/kit/geometry.ts +49 -0
  292. package/src/kit/graph.ts +116 -0
  293. package/src/kit/mark.ts +152 -0
  294. package/src/kit/part-fills.ts +61 -0
  295. package/src/kit/place.ts +77 -0
  296. package/src/kit/sampler.ts +281 -0
  297. package/src/kit/scale.ts +39 -0
  298. package/src/kit/source.ts +57 -0
  299. package/src/kit/system.ts +105 -0
  300. package/src/kit/ticks.ts +85 -0
  301. package/src/kit/withdrawn.ts +8 -0
  302. package/src/marks/curve-area.ts +89 -0
  303. package/src/marks/drop-lines.ts +71 -0
  304. package/src/marks/plot-point.ts +102 -0
  305. package/src/marks/riemann-sum.ts +99 -0
  306. package/src/marks/tangent-line.ts +119 -0
  307. package/src/marks/vector-arrow.ts +98 -0
  308. package/src/nodes.ts +99 -0
  309. package/src/plots/function-plot.ts +220 -0
  310. package/src/plots/points-plot.ts +103 -0
  311. package/src/plots/stream-lines.ts +160 -0
  312. package/src/plots/traced-path.ts +70 -0
  313. package/src/plots/vector-field.ts +107 -0
  314. package/src/structures/graph-layout.ts +145 -0
  315. package/src/structures/network-graph.ts +291 -0
  316. package/src/structures/sample-space.ts +210 -0
  317. package/src/systems/axes2d.ts +226 -0
  318. package/src/systems/number-line.ts +130 -0
  319. package/src/systems/number-plane.ts +232 -0
  320. package/src/systems/polar-plane.ts +177 -0
  321. package/src/tex/geometry.ts +703 -0
  322. package/src/tex/index.ts +15 -0
  323. package/src/tex/mathjax.ts +82 -0
  324. package/src/tex/matrix.ts +97 -0
  325. package/src/tex/node.ts +74 -0
  326. package/src/tex/tween.ts +308 -0
  327. package/src/tex/typeset.ts +461 -0
  328. package/src/three/axes3d.ts +267 -0
  329. package/src/three/curve-plot3d.ts +146 -0
  330. package/src/three/entries.ts +42 -0
  331. package/src/three/label3d.ts +52 -0
  332. package/src/three/plot-point3d.ts +63 -0
  333. package/src/three/space.ts +92 -0
  334. package/src/three/surface-plot3d.ts +318 -0
  335. package/src/three/vector-arrow3d.ts +88 -0
@@ -0,0 +1,15 @@
1
+ import { LatexMatrix } from './matrix';
2
+ import { Latex } from './node';
3
+
4
+ export * from './node';
5
+ export * from './matrix';
6
+ export {
7
+ blankLatex, buildLatexPath, findLatexParts, latexPartNames, LatexError, LatexNotLoaded, loadMathJax, mathJaxLoaded, MATHJAX_LOADER,
8
+ } from './geometry';
9
+ export type { LatexPart, LatexToken, LatexPathResult } from './geometry';
10
+ export { defaultLatexMorph } from './tween';
11
+ export type { AnimatedToken, LatexMorphStrategy } from './tween';
12
+
13
+ /** The typeset-math node types, for a host that registers only these. */
14
+ // Typed by name, so the declaration names each component rather than spelling out its type through core.
15
+ export const TEX_NODES: (typeof Latex | typeof LatexMatrix)[] = [Latex, LatexMatrix];
@@ -0,0 +1,82 @@
1
+ import { mathjax } from '@mathjax/src/js/mathjax.js';
2
+ import { TeX } from '@mathjax/src/js/input/tex.js';
3
+ import { SVG } from '@mathjax/src/js/output/svg.js';
4
+ import { browserAdaptor } from '@mathjax/src/js/adaptors/browserAdaptor.js';
5
+ import { liteAdaptor } from '@mathjax/src/js/adaptors/liteAdaptor.js';
6
+ import { RegisterHTMLHandler } from '@mathjax/src/js/handlers/html.js';
7
+
8
+ import '@mathjax/src/js/input/tex/base/BaseConfiguration.js';
9
+ import '@mathjax/src/js/input/tex/ams/AmsConfiguration.js';
10
+ import '@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js';
11
+ import '@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js';
12
+ import '@mathjax/src/js/input/tex/cancel/CancelConfiguration.js';
13
+ import '@mathjax/src/js/input/tex/color/ColorConfiguration.js';
14
+ import '@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js';
15
+ import '@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js';
16
+ import '@mathjax/src/js/input/tex/bbox/BboxConfiguration.js';
17
+ import '@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js';
18
+ import type { DynamicFileList } from '@mathjax/src/js/output/common/FontData.js';
19
+ import { MathJaxNewcmFont } from '@mathjax/mathjax-newcm-font/js/svg.js';
20
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/calligraphic.js';
21
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/double-struck.js';
22
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/fraktur.js';
23
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/monospace.js';
24
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif.js';
25
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/script.js';
26
+
27
+ /**
28
+ * MathJax, set up: the one module that imports it, loaded on demand by
29
+ * `loadMathJax` so a scene with no formula in it never downloads or parses it.
30
+ */
31
+
32
+
33
+ /**
34
+ * MathJax needs a DOM to build its output in, and there isn't always one.
35
+ *
36
+ * `browserAdaptor()` reads `window` **as it is constructed**, at module scope —
37
+ * so importing this file at all threw in Node, and a project with one LaTeX
38
+ * scene could not be rendered headlessly no matter which scene was asked for.
39
+ * `liteAdaptor` is MathJax's own DOM-free implementation and produces the same
40
+ * SVG; we only ever read paths back out of it, never attach it to a page.
41
+ */
42
+ // The two adaptors are structurally different (a `LiteElement` tree vs. a real
43
+ // one) and MathJax's generics track that, but nothing here touches an element
44
+ // except through the adaptor's own accessors — so the element type is genuinely
45
+ // opaque to us, and pinning it to either concrete one would be a lie.
46
+ export const adaptor: any = typeof window === 'undefined' && typeof document === 'undefined'
47
+ ? liteAdaptor()
48
+ : browserAdaptor();
49
+ RegisterHTMLHandler(adaptor);
50
+
51
+ const texJax = new TeX({
52
+ packages: [
53
+ 'base', 'ams', 'boldsymbol', 'newcommand',
54
+ 'cancel', 'color', 'mhchem', 'physics',
55
+ 'bbox', 'mathtools',
56
+ ],
57
+ });
58
+
59
+ /**
60
+ * The font files behind `\mathcal`, `\mathbb`, `\mathfrak`, `\mathsf`, `\mathtt`
61
+ * and `\mathscr`, imported above. MathJax fetches these asynchronously the first
62
+ * time a formula needs one, which a synchronous typesetter cannot wait for, so
63
+ * they are bundled and set up on the font before anything is typeset. The font
64
+ * class is passed explicitly so the one they register on is the one in use.
65
+ */
66
+ const BUNDLED_FONT_FILES = ['calligraphic', 'double-struck', 'fraktur', 'monospace', 'sans-serif', 'script'];
67
+
68
+ const svgJax = new SVG({ fontCache: 'local', fontData: MathJaxNewcmFont });
69
+ const fontFiles = (MathJaxNewcmFont as unknown as { dynamicFiles: DynamicFileList }).dynamicFiles;
70
+ for (const file of BUNDLED_FONT_FILES) fontFiles[file].setup(svgJax.font);
71
+
72
+ const mjDoc = mathjax.document('', { InputJax: texJax, OutputJax: svgJax });
73
+
74
+ /** Typeset `text` as display math and hand back MathJax's container, read through {@link adaptor}. */
75
+ export function convert(text: string): unknown {
76
+ return mjDoc.convert(text, {
77
+ display: true,
78
+ em: 16,
79
+ ex: 8,
80
+ containerWidth: 80 * 16,
81
+ });
82
+ }
@@ -0,0 +1,97 @@
1
+ import {
2
+ component2d,
3
+ Types,
4
+ type EntryOptions,
5
+ type NodeOf,
6
+ // Named so the emitted declaration reaches these through the sdk, not core.
7
+ type Alignment as _Alignment,
8
+ type Fill as _Fill,
9
+ type FillResolved as _FillResolved,
10
+ type FlowMode as _FlowMode,
11
+ type FlowResolved as _FlowResolved,
12
+ type GapSize as _GapSize,
13
+ type Node2D as _Node2D,
14
+ type Node2DProps as _Node2DProps,
15
+ type Shadow as _Shadow,
16
+ type ShadowResolved as _ShadowResolved,
17
+ type Stroke as _Stroke,
18
+ type StrokeResolved as _StrokeResolved,
19
+ type Vector2 as _Vector2,
20
+ } from "@motionscript/sdk";
21
+ import type { LatexProps } from "./node";
22
+ import {
23
+ drawFormula, formula, formulaFrame, layoutFormula, lerpMorph, loadFormula, measureFormula, morphOf, TYPESET, TYPESET_COMMANDS,
24
+ type Morphing,
25
+ } from "./typeset";
26
+
27
+ export type MatrixBrackets = "square" | "round" | "bar" | "double" | "curly" | "none";
28
+
29
+ export interface LatexMatrixProps extends LatexProps {
30
+ entries: string[][];
31
+ brackets: MatrixBrackets;
32
+ }
33
+
34
+ const ENVIRONMENT: Record<MatrixBrackets, string> = {
35
+ square: "bmatrix",
36
+ round: "pmatrix",
37
+ bar: "vmatrix",
38
+ double: "Vmatrix",
39
+ curly: "Bmatrix",
40
+ none: "matrix",
41
+ };
42
+
43
+ const BRACKETS = ["square", "round", "bar", "double", "curly", "none"] as const;
44
+
45
+ /** The LaTeX a matrix of `entries` is typeset from; empty for one with no entries. */
46
+ export function matrixSource(entries: readonly (readonly string[])[], brackets: MatrixBrackets = "square"): string {
47
+ const rows = entries.filter((row) => Array.isArray(row) && row.length > 0);
48
+ if (rows.length === 0) return "";
49
+ const environment = ENVIRONMENT[brackets] ?? ENVIRONMENT.square;
50
+ return `\\begin{${environment}} ${rows.map((row) => row.join(" & ")).join(" \\\\ ")} \\end{${environment}}`;
51
+ }
52
+
53
+ interface MatrixValues {
54
+ readonly entries: Morphing<string[][]>;
55
+ readonly brackets: Morphing<MatrixBrackets>;
56
+ }
57
+
58
+ /** The matrix's source now: mid-tween of its entries or its brackets, both ends of it. */
59
+ function sourceOf(s: MatrixValues): Morphing<string> {
60
+ return morphOf([s.entries, s.brackets], ([entries, brackets]) => matrixSource(entries as string[][], brackets as MatrixBrackets));
61
+ }
62
+
63
+ const state = {
64
+ ...TYPESET,
65
+ // Unused by the matrix's own drawing: its entries say what it writes.
66
+ latex: Types.custom<string, Morphing<string>, EntryOptions & { readonly kind: "text"; readonly multiline: true }>("", {
67
+ kind: "text", multiline: true, lerp: lerpMorph,
68
+ }),
69
+ /** A list of rows is a whole value: mid-tween it holds both, and the morph draws the way there. */
70
+ entries: Types.custom<string[][], Morphing<string[][]>>([["a", "b"], ["c", "d"]], { lerp: lerpMorph }),
71
+ brackets: Types.custom<MatrixBrackets, Morphing<MatrixBrackets>, EntryOptions & { readonly options: typeof BRACKETS }>("square", {
72
+ options: BRACKETS, animatable: false, lerp: lerpMorph,
73
+ }),
74
+ };
75
+
76
+ /**
77
+ * A matrix typeset from its entries, row by row, inside the brackets it is
78
+ * given. Each entry is a piece of LaTeX and is one of the formula's parts, so
79
+ * it can be painted, boxed or braced by its own source.
80
+ */
81
+ export const LatexMatrix = formula(component2d({
82
+ key: "latexMatrix",
83
+ state,
84
+ defaults: { width: "hug", height: "hug" },
85
+ load: (loader) => loadFormula(loader),
86
+ commands: {
87
+ ...TYPESET_COMMANDS,
88
+ morphTo: { args: ["latex"] },
89
+ /** Change the entries: the ones both matrices write travel, the rest fade. */
90
+ entriesTo: { args: ["entries"] },
91
+ },
92
+ measure: (_measurer, s) => measureFormula(formulaFrame(sourceOf(s), s.fontSize, s.partFills), s),
93
+ layout: (box, s, children) => layoutFormula(box, s, children),
94
+ render: (ctx, s) => drawFormula(ctx, s, formulaFrame(sourceOf(s), s.fontSize, s.partFills)),
95
+ }), sourceOf);
96
+
97
+ export type LatexMatrix = NodeOf<typeof LatexMatrix>;
@@ -0,0 +1,74 @@
1
+ import {
2
+ component2d,
3
+ Types,
4
+ type EntryOptions,
5
+ type InsetsProps,
6
+ type NodeOf,
7
+ type ShapeProps,
8
+ // Named so the emitted declaration reaches these through the sdk, not core.
9
+ type Alignment as _Alignment,
10
+ type Fill as _Fill,
11
+ type FillResolved as _FillResolved,
12
+ type FlowMode as _FlowMode,
13
+ type FlowResolved as _FlowResolved,
14
+ type GapSize as _GapSize,
15
+ type Node2D as _Node2D,
16
+ type Node2DProps as _Node2DProps,
17
+ type Shadow as _Shadow,
18
+ type ShadowResolved as _ShadowResolved,
19
+ type Stroke as _Stroke,
20
+ type StrokeResolved as _StrokeResolved,
21
+ type Vector2 as _Vector2,
22
+ } from "@motionscript/sdk";
23
+ // From each module, never the `../engine` barrel: it re-exports this file, so a
24
+ // load that enters through the barrel would build this component before the
25
+ // modules it spreads exist.
26
+ import type { PartFill } from "../kit/part-fills";
27
+ import {
28
+ drawFormula, formula, formulaFrame, layoutFormula, lerpMorph, loadFormula, measureFormula, TYPESET, TYPESET_COMMANDS,
29
+ type Morphing,
30
+ } from "./typeset";
31
+ import type { LatexMorphStrategy } from "./tween";
32
+
33
+ export interface LatexProps extends ShapeProps {
34
+ latex: string;
35
+ fontSize: number;
36
+ padding: InsetsProps;
37
+ partFills: PartFill[];
38
+ written: number;
39
+ }
40
+
41
+ /**
42
+ * How a formula morphs, for a node built on the `Typeset` helpers: they take it
43
+ * as an argument (`formulaFrame(source, fontSize, partFills, morph)`).
44
+ */
45
+ export interface LatexStrategies {
46
+ /** How the node morphs between two formulas. Defaults to `defaultLatexMorph`. */
47
+ morph?: LatexMorphStrategy;
48
+ }
49
+
50
+ const state = {
51
+ ...TYPESET,
52
+ /** The formula. Mid-tween it holds both ends, and the glyphs morph from the one into the other. */
53
+ latex: Types.custom<string, Morphing<string>, EntryOptions & { readonly kind: "text"; readonly multiline: true }>("", {
54
+ kind: "text", multiline: true, lerp: lerpMorph,
55
+ }),
56
+ };
57
+
58
+ /** A LaTeX formula drawn as glyph paths, morphing token by token between formulas. */
59
+ export const Latex = formula(component2d({
60
+ key: "latex",
61
+ state,
62
+ defaults: { width: "hug", height: "hug" },
63
+ load: (loader) => loadFormula(loader),
64
+ commands: {
65
+ ...TYPESET_COMMANDS,
66
+ /** Morph this formula into another, its glyphs travelling to their places in it. */
67
+ morphTo: { args: ["latex"] },
68
+ },
69
+ measure: (_measurer, s) => measureFormula(formulaFrame(s.latex, s.fontSize, s.partFills), s),
70
+ layout: (box, s, children) => layoutFormula(box, s, children),
71
+ render: (ctx, s) => drawFormula(ctx, s, formulaFrame(s.latex, s.fontSize, s.partFills)),
72
+ }), (s: { readonly latex: Morphing<string> }) => s.latex);
73
+
74
+ export type Latex = NodeOf<typeof Latex>;
@@ -0,0 +1,308 @@
1
+ import { lerpNumber, type PathCommand } from "@motionscript/sdk";
2
+ import type { LatexToken } from "./geometry";
3
+
4
+ export interface AnimatedToken {
5
+ token: string;
6
+ path: LatexToken["path"];
7
+ /** The top-level term it belongs to at rest; a morph matches on it. */
8
+ term?: string;
9
+ /** 0 = invisible, 1 = fully visible */
10
+ opacity: number;
11
+ /** Interpolated position offset applied during morph (x, y in formula space). */
12
+ x: number;
13
+ y: number;
14
+ /** Mid-morph: the index of the token it was in the formula left, and of the one it becomes. */
15
+ from?: number;
16
+ to?: number;
17
+ }
18
+
19
+ /**
20
+ * How a `Latex` node interpolates between two formulas: given the tokens it
21
+ * currently holds and the tokens the target formula resolves to, return a
22
+ * pure `t → AnimatedToken[]` frame function. `prepareLatexTween` below is the
23
+ * default implementation (exported as `defaultLatexMorph`) — pass a `morph`
24
+ * of this shape to `<Latex>` to replace it with your own.
25
+ */
26
+ export type LatexMorphStrategy = (from: LatexToken[], to: LatexToken[]) => (t: number) => AnimatedToken[];
27
+
28
+ /** The coordinate pairs a `PathCommand` can carry, as (x, y) field names. */
29
+ const POINT_FIELDS = [["x", "y"], ["x1", "y1"], ["x2", "y2"]] as const;
30
+
31
+ /**
32
+ * Compute the centroid of a token's path for position-based interpolation.
33
+ */
34
+ function centroid(path: LatexToken["path"]): { x: number; y: number } {
35
+ let sx = 0, sy = 0, n = 0;
36
+ for (const cmd of path) {
37
+ if ("x" in cmd && "y" in cmd) {
38
+ sx += (cmd as any).x;
39
+ sy += (cmd as any).y;
40
+ n++;
41
+ }
42
+ }
43
+ return n > 0 ? { x: sx / n, y: sy / n } : { x: 0, y: 0 };
44
+ }
45
+
46
+ /**
47
+ * A glyph's on-screen extent, as the diagonal of its control-point bbox.
48
+ *
49
+ * Only ever used as a *ratio* between the two ends of a match, so the fact that
50
+ * control points overshoot the true outline doesn't matter: both ends overshoot
51
+ * by the same proportion, because they are the same outline.
52
+ */
53
+ function extent(path: LatexToken["path"]): number {
54
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
55
+ for (const cmd of path) {
56
+ const c = cmd as any;
57
+ for (const [kx, ky] of POINT_FIELDS) {
58
+ if (kx in c) {
59
+ if (c[kx] < minX) minX = c[kx];
60
+ if (c[kx] > maxX) maxX = c[kx];
61
+ if (c[ky] < minY) minY = c[ky];
62
+ if (c[ky] > maxY) maxY = c[ky];
63
+ }
64
+ }
65
+ }
66
+ if (minX > maxX) return 0;
67
+ return Math.hypot(maxX - minX, maxY - minY);
68
+ }
69
+
70
+ /**
71
+ * Whether two paths can be interpolated point by point: same command count,
72
+ * same command types in the same order.
73
+ *
74
+ * For a matched pair this is the overwhelmingly common case, and not by luck.
75
+ * Tokens are matched on the character their MathJax glyph id decodes to, and
76
+ * that id *is* the key into the `<defs>` dictionary — so the same character in
77
+ * two formulas is the same outline, emitted twice under two different
78
+ * transforms. Same commands, different numbers.
79
+ */
80
+ function isPointwiseCompatible(from: PathCommand[], to: PathCommand[]): boolean {
81
+ if (from.length !== to.length) return false;
82
+ for (let i = 0; i < from.length; i++) {
83
+ if (from[i].type !== to[i].type) return false;
84
+ }
85
+ return true;
86
+ }
87
+
88
+ /**
89
+ * Lerp two structurally identical paths point by point.
90
+ *
91
+ * When the two ends are the same outline under two affine transforms — which is
92
+ * what a matched glyph is — this is exact at both ends *and* correct in
93
+ * between: `(1-t)·A·q + t·B·q = ((1-t)A + tB)·q`, and a blend of two
94
+ * uniform-scale-plus-translate transforms is another one. The intermediate is a
95
+ * properly formed glyph at an intermediate size, not a smeared one.
96
+ */
97
+ function lerpPath(from: PathCommand[], to: PathCommand[], t: number): PathCommand[] {
98
+ const out: PathCommand[] = new Array(from.length);
99
+ for (let i = 0; i < from.length; i++) {
100
+ const f = from[i] as any;
101
+ const g = to[i] as any;
102
+ const c: any = { ...g };
103
+ for (const [kx, ky] of POINT_FIELDS) {
104
+ if (kx in g && kx in f) {
105
+ c[kx] = lerpNumber(f[kx], g[kx], t);
106
+ c[ky] = lerpNumber(f[ky], g[ky], t);
107
+ }
108
+ }
109
+ out[i] = c as PathCommand;
110
+ }
111
+ return out;
112
+ }
113
+
114
+ /**
115
+ * Scale a path uniformly about (cx, cy), then translate by (dx, dy).
116
+ *
117
+ * The fallback for a matched pair whose paths *aren't* structurally identical —
118
+ * a stretchy delimiter assembled from a different number of pieces at the two
119
+ * sizes, say. Point-by-point lerping is impossible there, so the target outline
120
+ * is shrunk to the source's size instead and grown back over the morph: the
121
+ * size still changes continuously, which is the whole point, at the cost of
122
+ * showing the target's shape from the start.
123
+ */
124
+ function scaleAbout(
125
+ path: PathCommand[],
126
+ cx: number,
127
+ cy: number,
128
+ s: number,
129
+ dx: number,
130
+ dy: number,
131
+ ): PathCommand[] {
132
+ return path.map(cmd => {
133
+ const c: any = { ...(cmd as any) };
134
+ for (const [kx, ky] of POINT_FIELDS) {
135
+ if (kx in c) {
136
+ c[kx] = cx + (c[kx] - cx) * s + dx;
137
+ c[ky] = cy + (c[ky] - cy) * s + dy;
138
+ }
139
+ }
140
+ return c as PathCommand;
141
+ });
142
+ }
143
+
144
+ /**
145
+ * Match tokens from `from` to `to` by character key, a term that both formulas
146
+ * write first: the `x^2` of `x^2 + 1` travels to the `x^2` of `y = x^2` as
147
+ * one, instead of lending its `2` to whichever `2` comes first. What is left
148
+ * is matched greedily by character alone.
149
+ * Returns three lists: matched pairs, deleted tokens (only in from), added tokens (only in to).
150
+ */
151
+ function matchTokens(
152
+ from: LatexToken[],
153
+ to: LatexToken[],
154
+ ): {
155
+ matched: Array<{ from: LatexToken; to: LatexToken }>;
156
+ deleted: LatexToken[];
157
+ added: LatexToken[];
158
+ } {
159
+ const remaining = [...to];
160
+ const partner = new Map<LatexToken, LatexToken>();
161
+ // Synthetic shapes (rects/paths) have no natural token key.
162
+ const keyed = (t: LatexToken) => !t.token.startsWith("__");
163
+ const pair = (same: (f: LatexToken, t: LatexToken) => boolean) => {
164
+ for (const ft of from) {
165
+ if (!keyed(ft) || partner.has(ft)) continue;
166
+ const idx = remaining.findIndex(t => keyed(t) && same(ft, t));
167
+ if (idx === -1) continue;
168
+ partner.set(ft, remaining[idx]);
169
+ remaining.splice(idx, 1);
170
+ }
171
+ };
172
+ pair((f, t) => f.token === t.token && f.term !== undefined && f.term === t.term);
173
+ pair((f, t) => f.token === t.token);
174
+
175
+ const matched: Array<{ from: LatexToken; to: LatexToken }> = [];
176
+ const deleted: LatexToken[] = [];
177
+ for (const ft of from) {
178
+ const tt = partner.get(ft);
179
+ if (tt) matched.push({ from: ft, to: tt });
180
+ else deleted.push(ft);
181
+ }
182
+
183
+ return { matched, deleted, added: remaining };
184
+ }
185
+
186
+ /**
187
+ * Precompute a formula-change morph and return a pure `t → AnimatedToken[]`
188
+ * frame function:
189
+ * - Deleted tokens fade out over the first half of `t`.
190
+ * - Matched tokens are interpolated — place *and* size — across the full range
191
+ * of `t`.
192
+ * - Added tokens fade in over the second half of `t`.
193
+ *
194
+ * A matched glyph is rarely the same size at both ends: the `2` of `b^2` is set
195
+ * at script size and the `2` of `2a` at full size, and a `\frac`'s arguments
196
+ * come back a step smaller than the same symbols on a baseline. So the
197
+ * interpolation has to carry the glyph's *geometry*, not just where it sits.
198
+ * Sliding the target outline from one centroid to the other — which is all this
199
+ * used to do — put the whole size change between the last static frame and the
200
+ * morph's first one: a snap to the new size, then a smooth glide to the new
201
+ * place. Point-by-point lerping (see {@link lerpPath}) is that same
202
+ * interpolation generalised from a glyph's average point to all of them, and it
203
+ * costs nothing extra — the path was already being rebuilt every frame to apply
204
+ * the slide.
205
+ *
206
+ * `t` is normalized `[0, 1]` and already eased — the caller (a `Command`'s
207
+ * `at`) applies easing once, up front, the same eased value driving every
208
+ * concurrent aspect of the morph (props, intrinsic size, tokens) in lockstep.
209
+ */
210
+ export function prepareLatexTween(
211
+ from: LatexToken[],
212
+ to: LatexToken[],
213
+ ): (t: number) => AnimatedToken[] {
214
+ const { matched, deleted, added } = matchTokens(from, to);
215
+
216
+ // Per-match interpolation data. Structure compatibility, and the centroids
217
+ // and extents behind the fallback, are properties of the pair rather than
218
+ // of `t`, so they are settled once here instead of at every frame.
219
+ const fromIndex = new Map(from.map((token, i) => [token, i]));
220
+ const toIndex = new Map(to.map((token, i) => [token, i]));
221
+ const matchedData = matched.map(({ from: f, to: t }) => {
222
+ const toExtent = extent(t.path);
223
+ return {
224
+ from: fromIndex.get(f),
225
+ to: toIndex.get(t),
226
+ pointwise: isPointwiseCompatible(f.path, t.path),
227
+ fromPath: f.path,
228
+ toPath: t.path,
229
+ token: t.token,
230
+ fromCenter: centroid(f.path),
231
+ toCenter: centroid(t.path),
232
+ /** Only the fallback needs it, and only as a ratio. */
233
+ fromScale: toExtent > 0 ? extent(f.path) / toExtent : 1,
234
+ };
235
+ });
236
+
237
+ return (t: number): AnimatedToken[] => {
238
+ const tokens: AnimatedToken[] = [];
239
+
240
+ // Matched tokens: interpolate place and size across the full duration.
241
+ for (const m of matchedData) {
242
+ if (m.pointwise) {
243
+ tokens.push({
244
+ token: m.token,
245
+ path: lerpPath(m.fromPath, m.toPath, t),
246
+ opacity: 1,
247
+ // Baked into the path above: the lerp carries every point,
248
+ // which includes where the glyph sits.
249
+ x: 0,
250
+ y: 0,
251
+ from: m.from,
252
+ to: m.to,
253
+ });
254
+ continue;
255
+ }
256
+
257
+ const s = lerpNumber(m.fromScale, 1, t);
258
+ const cx = lerpNumber(m.fromCenter.x, m.toCenter.x, t);
259
+ const cy = lerpNumber(m.fromCenter.y, m.toCenter.y, t);
260
+ tokens.push({
261
+ token: m.token,
262
+ path: scaleAbout(
263
+ m.toPath,
264
+ m.toCenter.x,
265
+ m.toCenter.y,
266
+ s,
267
+ cx - m.toCenter.x,
268
+ cy - m.toCenter.y,
269
+ ),
270
+ opacity: 1,
271
+ x: 0,
272
+ y: 0,
273
+ from: m.from,
274
+ to: m.to,
275
+ });
276
+ }
277
+
278
+ // Deleted tokens: fade out over the first half, gone by t=0.5
279
+ for (const d of deleted) {
280
+ const fadeT = Math.min(t * 2, 1);
281
+ tokens.push({
282
+ token: d.token,
283
+ path: d.path,
284
+ opacity: lerpNumber(1, 0, fadeT),
285
+ x: 0,
286
+ y: 0,
287
+ from: fromIndex.get(d),
288
+ });
289
+ }
290
+
291
+ // Added tokens: fade in over the second half, starting at t=0.5
292
+ for (const a of added) {
293
+ const fadeT = Math.max(t * 2 - 1, 0);
294
+ tokens.push({
295
+ token: a.token,
296
+ path: a.path,
297
+ opacity: lerpNumber(0, 1, fadeT),
298
+ x: 0,
299
+ y: 0,
300
+ to: toIndex.get(a),
301
+ });
302
+ }
303
+
304
+ return tokens;
305
+ };
306
+ }
307
+
308
+ export { prepareLatexTween as defaultLatexMorph };