@motionscript/math 0.0.0-stage → 0.1.0-alpha.5
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 +110 -0
- package/LICENSE +201 -0
- package/NOTICE +48 -0
- package/README.md +385 -3
- package/dist/annotate/angle-mark.d.ts +46 -0
- package/dist/annotate/angle-mark.d.ts.map +1 -0
- package/dist/annotate/angle-mark.js +132 -0
- package/dist/annotate/angle-mark.js.map +1 -0
- package/dist/annotate/curly-brace.d.ts +46 -0
- package/dist/annotate/curly-brace.d.ts.map +1 -0
- package/dist/annotate/curly-brace.js +114 -0
- package/dist/annotate/curly-brace.js.map +1 -0
- package/dist/annotate/emphasis-mark.d.ts +20 -0
- package/dist/annotate/emphasis-mark.d.ts.map +1 -0
- package/dist/annotate/emphasis-mark.js +81 -0
- package/dist/annotate/emphasis-mark.js.map +1 -0
- package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js +2 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +30 -0
- package/dist/browser/tex.js +2 -0
- package/dist/browser/tex.js.map +7 -0
- package/dist/engine.d.ts +64 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +42 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/brace.d.ts +8 -0
- package/dist/kit/brace.d.ts.map +1 -0
- package/dist/kit/brace.js +36 -0
- package/dist/kit/brace.js.map +1 -0
- package/dist/kit/cache.d.ts +30 -0
- package/dist/kit/cache.d.ts.map +1 -0
- package/dist/kit/cache.js +53 -0
- package/dist/kit/cache.js.map +1 -0
- package/dist/kit/contour.d.ts +8 -0
- package/dist/kit/contour.d.ts.map +1 -0
- package/dist/kit/contour.js +93 -0
- package/dist/kit/contour.js.map +1 -0
- package/dist/kit/coords.d.ts +69 -0
- package/dist/kit/coords.d.ts.map +1 -0
- package/dist/kit/coords.js +224 -0
- package/dist/kit/coords.js.map +1 -0
- package/dist/kit/curve.d.ts +17 -0
- package/dist/kit/curve.d.ts.map +1 -0
- package/dist/kit/curve.js +22 -0
- package/dist/kit/curve.js.map +1 -0
- package/dist/kit/equation.d.ts +61 -0
- package/dist/kit/equation.d.ts.map +1 -0
- package/dist/kit/equation.js +168 -0
- package/dist/kit/equation.js.map +1 -0
- package/dist/kit/equation3d.d.ts +50 -0
- package/dist/kit/equation3d.d.ts.map +1 -0
- package/dist/kit/equation3d.js +103 -0
- package/dist/kit/equation3d.js.map +1 -0
- package/dist/kit/expression.d.ts +35 -0
- package/dist/kit/expression.d.ts.map +1 -0
- package/dist/kit/expression.js +124 -0
- package/dist/kit/expression.js.map +1 -0
- package/dist/kit/field-mark.d.ts +58 -0
- package/dist/kit/field-mark.d.ts.map +1 -0
- package/dist/kit/field-mark.js +129 -0
- package/dist/kit/field-mark.js.map +1 -0
- package/dist/kit/field.d.ts +14 -0
- package/dist/kit/field.d.ts.map +1 -0
- package/dist/kit/field.js +46 -0
- package/dist/kit/field.js.map +1 -0
- package/dist/kit/follow.d.ts +71 -0
- package/dist/kit/follow.d.ts.map +1 -0
- package/dist/kit/follow.js +159 -0
- package/dist/kit/follow.js.map +1 -0
- package/dist/kit/furniture.d.ts +30 -0
- package/dist/kit/furniture.d.ts.map +1 -0
- package/dist/kit/furniture.js +87 -0
- package/dist/kit/furniture.js.map +1 -0
- package/dist/kit/geometry.d.ts +13 -0
- package/dist/kit/geometry.d.ts.map +1 -0
- package/dist/kit/geometry.js +54 -0
- package/dist/kit/geometry.js.map +1 -0
- package/dist/kit/mark.d.ts +47 -0
- package/dist/kit/mark.d.ts.map +1 -0
- package/dist/kit/mark.js +103 -0
- package/dist/kit/mark.js.map +1 -0
- package/dist/kit/part-fills.d.ts +23 -0
- package/dist/kit/part-fills.d.ts.map +1 -0
- package/dist/kit/part-fills.js +46 -0
- package/dist/kit/part-fills.js.map +1 -0
- package/dist/kit/place.d.ts +18 -0
- package/dist/kit/place.d.ts.map +1 -0
- package/dist/kit/place.js +68 -0
- package/dist/kit/place.js.map +1 -0
- package/dist/kit/placement.d.ts +8 -0
- package/dist/kit/placement.d.ts.map +1 -0
- package/dist/kit/placement.js +8 -0
- package/dist/kit/placement.js.map +1 -0
- package/dist/kit/sampler.d.ts +17 -0
- package/dist/kit/sampler.d.ts.map +1 -0
- package/dist/kit/sampler.js +250 -0
- package/dist/kit/sampler.js.map +1 -0
- package/dist/kit/scale.d.ts +12 -0
- package/dist/kit/scale.d.ts.map +1 -0
- package/dist/kit/scale.js +37 -0
- package/dist/kit/scale.js.map +1 -0
- package/dist/kit/source.d.ts +22 -0
- package/dist/kit/source.d.ts.map +1 -0
- package/dist/kit/source.js +45 -0
- package/dist/kit/source.js.map +1 -0
- package/dist/kit/system.d.ts +33 -0
- package/dist/kit/system.d.ts.map +1 -0
- package/dist/kit/system.js +67 -0
- package/dist/kit/system.js.map +1 -0
- package/dist/kit/ticks.d.ts +19 -0
- package/dist/kit/ticks.d.ts.map +1 -0
- package/dist/kit/ticks.js +78 -0
- package/dist/kit/ticks.js.map +1 -0
- package/dist/kit/withdrawn.d.ts +9 -0
- package/dist/kit/withdrawn.d.ts.map +1 -0
- package/dist/kit/withdrawn.js +9 -0
- package/dist/kit/withdrawn.js.map +1 -0
- package/dist/marks/curve-area.d.ts +32 -0
- package/dist/marks/curve-area.d.ts.map +1 -0
- package/dist/marks/curve-area.js +82 -0
- package/dist/marks/curve-area.js.map +1 -0
- package/dist/marks/drop-lines.d.ts +22 -0
- package/dist/marks/drop-lines.d.ts.map +1 -0
- package/dist/marks/drop-lines.js +58 -0
- package/dist/marks/drop-lines.js.map +1 -0
- package/dist/marks/plot-point.d.ts +35 -0
- package/dist/marks/plot-point.d.ts.map +1 -0
- package/dist/marks/plot-point.js +97 -0
- package/dist/marks/plot-point.js.map +1 -0
- package/dist/marks/riemann-sum.d.ts +37 -0
- package/dist/marks/riemann-sum.d.ts.map +1 -0
- package/dist/marks/riemann-sum.js +91 -0
- package/dist/marks/riemann-sum.js.map +1 -0
- package/dist/marks/tangent-line.d.ts +27 -0
- package/dist/marks/tangent-line.d.ts.map +1 -0
- package/dist/marks/tangent-line.js +103 -0
- package/dist/marks/tangent-line.js.map +1 -0
- package/dist/marks/vector-arrow.d.ts +32 -0
- package/dist/marks/vector-arrow.d.ts.map +1 -0
- package/dist/marks/vector-arrow.js +87 -0
- package/dist/marks/vector-arrow.js.map +1 -0
- package/dist/nodes.d.ts +35 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +63 -0
- package/dist/nodes.js.map +1 -0
- package/dist/plots/function-plot.d.ts +67 -0
- package/dist/plots/function-plot.d.ts.map +1 -0
- package/dist/plots/function-plot.js +215 -0
- package/dist/plots/function-plot.js.map +1 -0
- package/dist/plots/points-plot.d.ts +28 -0
- package/dist/plots/points-plot.d.ts.map +1 -0
- package/dist/plots/points-plot.js +99 -0
- package/dist/plots/points-plot.js.map +1 -0
- package/dist/plots/stream-lines.d.ts +35 -0
- package/dist/plots/stream-lines.d.ts.map +1 -0
- package/dist/plots/stream-lines.js +141 -0
- package/dist/plots/stream-lines.js.map +1 -0
- package/dist/plots/traced-path.d.ts +31 -0
- package/dist/plots/traced-path.d.ts.map +1 -0
- package/dist/plots/traced-path.js +56 -0
- package/dist/plots/traced-path.js.map +1 -0
- package/dist/plots/vector-field.d.ts +23 -0
- package/dist/plots/vector-field.d.ts.map +1 -0
- package/dist/plots/vector-field.js +91 -0
- package/dist/plots/vector-field.js.map +1 -0
- package/dist/structures/graph-layout.d.ts +11 -0
- package/dist/structures/graph-layout.d.ts.map +1 -0
- package/dist/structures/graph-layout.js +135 -0
- package/dist/structures/graph-layout.js.map +1 -0
- package/dist/structures/network-graph.d.ts +83 -0
- package/dist/structures/network-graph.d.ts.map +1 -0
- package/dist/structures/network-graph.js +289 -0
- package/dist/structures/network-graph.js.map +1 -0
- package/dist/structures/sample-space.d.ts +62 -0
- package/dist/structures/sample-space.d.ts.map +1 -0
- package/dist/structures/sample-space.js +199 -0
- package/dist/structures/sample-space.js.map +1 -0
- package/dist/systems/axes2d.d.ts +75 -0
- package/dist/systems/axes2d.d.ts.map +1 -0
- package/dist/systems/axes2d.js +193 -0
- package/dist/systems/axes2d.js.map +1 -0
- package/dist/systems/number-line.d.ts +49 -0
- package/dist/systems/number-line.d.ts.map +1 -0
- package/dist/systems/number-line.js +127 -0
- package/dist/systems/number-line.js.map +1 -0
- package/dist/systems/number-plane.d.ts +59 -0
- package/dist/systems/number-plane.d.ts.map +1 -0
- package/dist/systems/number-plane.js +193 -0
- package/dist/systems/number-plane.js.map +1 -0
- package/dist/systems/polar-plane.d.ts +48 -0
- package/dist/systems/polar-plane.d.ts.map +1 -0
- package/dist/systems/polar-plane.js +165 -0
- package/dist/systems/polar-plane.js.map +1 -0
- package/dist/tex/geometry.d.ts +85 -0
- package/dist/tex/geometry.d.ts.map +1 -0
- package/dist/tex/geometry.js +632 -0
- package/dist/tex/geometry.js.map +1 -0
- package/dist/tex/index.d.ts +11 -0
- package/dist/tex/index.d.ts.map +1 -0
- package/dist/tex/index.js +9 -0
- package/dist/tex/index.js.map +1 -0
- package/dist/tex/mathjax.d.ts +33 -0
- package/dist/tex/mathjax.d.ts.map +1 -0
- package/dist/tex/mathjax.js +74 -0
- package/dist/tex/mathjax.js.map +1 -0
- package/dist/tex/matrix.d.ts +31 -0
- package/dist/tex/matrix.d.ts.map +1 -0
- package/dist/tex/matrix.js +73 -0
- package/dist/tex/matrix.js.map +1 -0
- package/dist/tex/node.d.ts +215 -0
- package/dist/tex/node.d.ts.map +1 -0
- package/dist/tex/node.js +595 -0
- package/dist/tex/node.js.map +1 -0
- package/dist/tex/tween.d.ts +50 -0
- package/dist/tex/tween.d.ts.map +1 -0
- package/dist/tex/tween.js +253 -0
- package/dist/tex/tween.js.map +1 -0
- package/dist/three/axes3d.d.ts +87 -0
- package/dist/three/axes3d.d.ts.map +1 -0
- package/dist/three/axes3d.js +228 -0
- package/dist/three/axes3d.js.map +1 -0
- package/dist/three/curve-plot3d.d.ts +60 -0
- package/dist/three/curve-plot3d.d.ts.map +1 -0
- package/dist/three/curve-plot3d.js +143 -0
- package/dist/three/curve-plot3d.js.map +1 -0
- package/dist/three/label3d.d.ts +11 -0
- package/dist/three/label3d.d.ts.map +1 -0
- package/dist/three/label3d.js +40 -0
- package/dist/three/label3d.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +26 -0
- package/dist/three/plot-point3d.d.ts.map +1 -0
- package/dist/three/plot-point3d.js +60 -0
- package/dist/three/plot-point3d.js.map +1 -0
- package/dist/three/space.d.ts +28 -0
- package/dist/three/space.d.ts.map +1 -0
- package/dist/three/space.js +47 -0
- package/dist/three/space.js.map +1 -0
- package/dist/three/surface-plot3d.d.ts +80 -0
- package/dist/three/surface-plot3d.d.ts.map +1 -0
- package/dist/three/surface-plot3d.js +290 -0
- package/dist/three/surface-plot3d.js.map +1 -0
- package/dist/three/vector-arrow3d.d.ts +25 -0
- package/dist/three/vector-arrow3d.d.ts.map +1 -0
- package/dist/three/vector-arrow3d.js +72 -0
- package/dist/three/vector-arrow3d.js.map +1 -0
- package/package.json +79 -3
- package/registry.json +251 -0
- package/src/annotate/angle-mark.ts +147 -0
- package/src/annotate/curly-brace.ts +126 -0
- package/src/annotate/emphasis-mark.ts +89 -0
- package/src/engine.ts +72 -0
- package/src/index.ts +29 -0
- package/src/kit/brace.ts +37 -0
- package/src/kit/cache.ts +61 -0
- package/src/kit/contour.ts +94 -0
- package/src/kit/coords.ts +278 -0
- package/src/kit/curve.ts +29 -0
- package/src/kit/equation.ts +181 -0
- package/src/kit/equation3d.ts +137 -0
- package/src/kit/expression.ts +159 -0
- package/src/kit/field-mark.ts +155 -0
- package/src/kit/field.ts +50 -0
- package/src/kit/follow.ts +203 -0
- package/src/kit/furniture.ts +108 -0
- package/src/kit/geometry.ts +49 -0
- package/src/kit/mark.ts +131 -0
- package/src/kit/part-fills.ts +61 -0
- package/src/kit/place.ts +101 -0
- package/src/kit/placement.ts +8 -0
- package/src/kit/sampler.ts +281 -0
- package/src/kit/scale.ts +39 -0
- package/src/kit/source.ts +57 -0
- package/src/kit/system.ts +99 -0
- package/src/kit/ticks.ts +85 -0
- package/src/kit/withdrawn.ts +8 -0
- package/src/marks/curve-area.ts +89 -0
- package/src/marks/drop-lines.ts +63 -0
- package/src/marks/plot-point.ts +107 -0
- package/src/marks/riemann-sum.ts +98 -0
- package/src/marks/tangent-line.ts +103 -0
- package/src/marks/vector-arrow.ts +98 -0
- package/src/nodes.ts +63 -0
- package/src/plots/function-plot.ts +236 -0
- package/src/plots/points-plot.ts +107 -0
- package/src/plots/stream-lines.ts +151 -0
- package/src/plots/traced-path.ts +52 -0
- package/src/plots/vector-field.ts +88 -0
- package/src/structures/graph-layout.ts +145 -0
- package/src/structures/network-graph.ts +308 -0
- package/src/structures/sample-space.ts +209 -0
- package/src/systems/axes2d.ts +217 -0
- package/src/systems/number-line.ts +131 -0
- package/src/systems/number-plane.ts +203 -0
- package/src/systems/polar-plane.ts +176 -0
- package/src/tex/geometry.ts +703 -0
- package/src/tex/index.ts +14 -0
- package/src/tex/mathjax.ts +82 -0
- package/src/tex/matrix.ts +75 -0
- package/src/tex/node.ts +641 -0
- package/src/tex/tween.ts +308 -0
- package/src/three/axes3d.ts +240 -0
- package/src/three/curve-plot3d.ts +147 -0
- package/src/three/label3d.ts +50 -0
- package/src/three/plot-point3d.ts +66 -0
- package/src/three/space.ts +67 -0
- package/src/three/surface-plot3d.ts +323 -0
- package/src/three/vector-arrow3d.ts +77 -0
package/src/tex/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
export const TEX_NODES = [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,75 @@
|
|
|
1
|
+
import { command, node, property, type Command, type CommandArgs, type NodeConfig } from "@motionscript/sdk";
|
|
2
|
+
import { Latex, type LatexProps } from "./node";
|
|
3
|
+
|
|
4
|
+
export type MatrixBrackets = "square" | "round" | "bar" | "double" | "curly" | "none";
|
|
5
|
+
|
|
6
|
+
export interface LatexMatrixProps extends LatexProps {
|
|
7
|
+
entries: string[][];
|
|
8
|
+
brackets: MatrixBrackets;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ENVIRONMENT: Record<MatrixBrackets, string> = {
|
|
12
|
+
square: "bmatrix",
|
|
13
|
+
round: "pmatrix",
|
|
14
|
+
bar: "vmatrix",
|
|
15
|
+
double: "Vmatrix",
|
|
16
|
+
curly: "Bmatrix",
|
|
17
|
+
none: "matrix",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** The LaTeX a matrix of `entries` is typeset from; empty for one with no entries. */
|
|
21
|
+
export function matrixSource(entries: readonly (readonly string[])[], brackets: MatrixBrackets = "square"): string {
|
|
22
|
+
const rows = entries.filter((row) => Array.isArray(row) && row.length > 0);
|
|
23
|
+
if (rows.length === 0) return "";
|
|
24
|
+
const environment = ENVIRONMENT[brackets] ?? ENVIRONMENT.square;
|
|
25
|
+
return `\\begin{${environment}} ${rows.map((row) => row.join(" & ")).join(" \\\\ ")} \\end{${environment}}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// A list of rows is a whole value: it changes at the end of a tween, and the morph draws the way there.
|
|
29
|
+
// (A function, not a generic arrow: a copied component is compiled as TSX, where `<T>(` opens an element.)
|
|
30
|
+
function atTheEnd<T>(from: T, to: T, t: number): T {
|
|
31
|
+
return t < 1 ? from : to;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type MatrixNext = Partial<LatexMatrixProps>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A matrix typeset from its entries, row by row, inside the brackets it is
|
|
38
|
+
* given. Each entry is a piece of LaTeX and is one of the formula's parts, so
|
|
39
|
+
* it can be painted, boxed or braced by its own source.
|
|
40
|
+
*/
|
|
41
|
+
@node({
|
|
42
|
+
key: "latexMatrix",
|
|
43
|
+
parentKey: "latex",
|
|
44
|
+
forkable: true,
|
|
45
|
+
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: true },
|
|
46
|
+
seed: { fill: [{ type: "solid", color: [0.412, 0.565, 0.867, 1], opacity: 1, enabled: true }] },
|
|
47
|
+
})
|
|
48
|
+
export class LatexMatrix extends Latex {
|
|
49
|
+
@property({ default: [["a", "b"], ["c", "d"]], tween: atTheEnd }) declare entries: string[][];
|
|
50
|
+
@property({ default: "square", options: ["square", "round", "bar", "double", "curly", "none"], animatable: false })
|
|
51
|
+
declare brackets: MatrixBrackets;
|
|
52
|
+
|
|
53
|
+
constructor(props?: NodeConfig<LatexMatrix, LatexMatrixProps>) {
|
|
54
|
+
super(props as never);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Change the entries: the ones both matrices write travel, the rest fade. */
|
|
58
|
+
@command({ args: ["entries"] })
|
|
59
|
+
entriesTo(args: CommandArgs<{ entries: string[][] }> & { duration: number }): Command<LatexProps> {
|
|
60
|
+
const entries = args.data?.entries;
|
|
61
|
+
return this.to({ data: (entries === undefined ? {} : { entries }) as Partial<LatexProps>, duration: args.duration, easing: args.easing });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
override _source(next: MatrixNext = {}): string {
|
|
65
|
+
return matrixSource(next.entries ?? this.entries, next.brackets ?? this.brackets);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
override _sourceProps(next: MatrixNext = {}): Partial<LatexProps> {
|
|
69
|
+
return { entries: next.entries ?? this.entries, brackets: next.brackets ?? this.brackets } as Partial<LatexProps>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
override _resets(next: MatrixNext): boolean {
|
|
73
|
+
return next.entries !== undefined || next.brackets !== undefined || next.fontSize !== undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|