@motionscript/math 0.1.0-alpha.7 → 0.1.0-alpha.9
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 +4 -0
- package/LICENSE +201 -201
- package/NOTICE +49 -48
- package/README.md +390 -391
- package/dist/annotate/angle-mark.d.ts +6 -6
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +9 -9
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +9 -9
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/{chunk-ABYBW64J.js → chunk-IRZCG6PM.js} +2 -2
- package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
- package/dist/browser/chunks/{chunk-K77KLQX4.js → chunk-WMVW6ZIV.js} +2 -2
- package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
- package/dist/browser/chunks/{mathjax-DNP3YRES.js → mathjax-WV55AC2P.js} +1 -1
- package/dist/browser/chunks/{mathjax-DNP3YRES.js.map → mathjax-WV55AC2P.js.map} +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/tex.js +1 -1
- package/dist/browser/tex.js.map +1 -1
- package/dist/engine.d.ts +1 -1
- package/dist/engine.js +1 -1
- package/dist/engine.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kit/brace.js.map +1 -1
- package/dist/kit/cache.js.map +1 -1
- package/dist/kit/component.d.ts.map +1 -1
- package/dist/kit/component.js.map +1 -1
- package/dist/kit/contour.js.map +1 -1
- package/dist/kit/coords.js.map +1 -1
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/equation.js.map +1 -1
- package/dist/kit/equation3d.js.map +1 -1
- package/dist/kit/expression.js.map +1 -1
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/field.js.map +1 -1
- package/dist/kit/follow.d.ts +2 -2
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.js.map +1 -1
- package/dist/kit/geometry.js.map +1 -1
- package/dist/kit/graph.js.map +1 -1
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/part-fills.js.map +1 -1
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/sampler.js +1 -1
- package/dist/kit/sampler.js.map +1 -1
- package/dist/kit/scale.js.map +1 -1
- package/dist/kit/source.js.map +1 -1
- package/dist/kit/system.js.map +1 -1
- package/dist/kit/ticks.js.map +1 -1
- package/dist/kit/withdrawn.js.map +1 -1
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +6 -6
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +3 -3
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +3 -3
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +6 -6
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +6 -6
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +8 -8
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/graph-layout.js.map +1 -1
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/geometry.js.map +1 -1
- package/dist/tex/index.js.map +1 -1
- package/dist/tex/mathjax.js.map +1 -1
- package/dist/tex/matrix.d.ts +2 -2
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/node.d.ts +2 -2
- package/dist/tex/node.js.map +1 -1
- package/dist/tex/tween.js.map +1 -1
- package/dist/tex/typeset.d.ts +4 -4
- package/dist/tex/typeset.d.ts.map +1 -1
- package/dist/tex/typeset.js.map +1 -1
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +27 -27
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js +3 -2
- package/dist/three/curve-plot3d.js.map +1 -1
- package/dist/three/entries.js.map +1 -1
- package/dist/three/label3d.d.ts.map +1 -1
- package/dist/three/label3d.js +3 -1
- package/dist/three/label3d.js.map +1 -1
- package/dist/three/plot-point3d.d.ts +27 -27
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +36 -36
- package/dist/three/surface-plot3d.js +6 -1
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +27 -27
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +5 -4
- package/registry.json +251 -251
- package/src/annotate/angle-mark.ts +137 -137
- package/src/annotate/curly-brace.ts +148 -148
- package/src/annotate/emphasis-mark.ts +118 -118
- package/src/engine.ts +86 -86
- package/src/index.ts +29 -29
- package/src/kit/brace.ts +37 -37
- package/src/kit/cache.ts +61 -61
- package/src/kit/component.ts +57 -57
- package/src/kit/contour.ts +94 -94
- package/src/kit/coords.ts +278 -278
- package/src/kit/curve.ts +47 -47
- package/src/kit/equation.ts +181 -181
- package/src/kit/equation3d.ts +137 -137
- package/src/kit/expression.ts +159 -159
- package/src/kit/field-mark.ts +171 -171
- package/src/kit/field.ts +50 -50
- package/src/kit/follow.ts +229 -229
- package/src/kit/furniture.ts +113 -113
- package/src/kit/geometry.ts +49 -49
- package/src/kit/graph.ts +116 -116
- package/src/kit/mark.ts +152 -152
- package/src/kit/part-fills.ts +61 -61
- package/src/kit/place.ts +77 -77
- package/src/kit/sampler.ts +281 -281
- package/src/kit/scale.ts +39 -39
- package/src/kit/source.ts +57 -57
- package/src/kit/system.ts +105 -105
- package/src/kit/ticks.ts +85 -85
- package/src/kit/withdrawn.ts +8 -8
- package/src/marks/curve-area.ts +89 -89
- package/src/marks/drop-lines.ts +71 -71
- package/src/marks/plot-point.ts +102 -102
- package/src/marks/riemann-sum.ts +99 -99
- package/src/marks/tangent-line.ts +119 -119
- package/src/marks/vector-arrow.ts +98 -98
- package/src/nodes.ts +99 -99
- package/src/plots/function-plot.ts +220 -220
- package/src/plots/points-plot.ts +103 -103
- package/src/plots/stream-lines.ts +160 -160
- package/src/plots/traced-path.ts +70 -70
- package/src/plots/vector-field.ts +107 -107
- package/src/structures/graph-layout.ts +145 -145
- package/src/structures/network-graph.ts +291 -291
- package/src/structures/sample-space.ts +210 -210
- package/src/systems/axes2d.ts +226 -226
- package/src/systems/number-line.ts +130 -130
- package/src/systems/number-plane.ts +232 -232
- package/src/systems/polar-plane.ts +177 -177
- package/src/tex/geometry.ts +703 -703
- package/src/tex/index.ts +15 -15
- package/src/tex/mathjax.ts +82 -82
- package/src/tex/matrix.ts +97 -97
- package/src/tex/node.ts +74 -74
- package/src/tex/tween.ts +308 -308
- package/src/tex/typeset.ts +461 -461
- package/src/three/axes3d.ts +267 -267
- package/src/three/curve-plot3d.ts +146 -144
- package/src/three/entries.ts +42 -42
- package/src/three/label3d.ts +52 -50
- package/src/three/plot-point3d.ts +63 -63
- package/src/three/space.ts +92 -92
- package/src/three/surface-plot3d.ts +318 -312
- package/src/three/vector-arrow3d.ts +88 -88
- package/dist/browser/chunks/chunk-ABYBW64J.js.map +0 -7
- package/dist/browser/chunks/chunk-K77KLQX4.js.map +0 -7
- package/dist/kit/placement.d.ts +0 -8
- package/dist/kit/placement.d.ts.map +0 -1
- package/dist/kit/placement.js +0 -8
- package/dist/kit/placement.js.map +0 -1
package/src/tex/index.ts
CHANGED
|
@@ -1,15 +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];
|
|
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];
|
package/src/tex/mathjax.ts
CHANGED
|
@@ -1,82 +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
|
-
}
|
|
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
|
+
}
|
package/src/tex/matrix.ts
CHANGED
|
@@ -1,97 +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>;
|
|
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>;
|
package/src/tex/node.ts
CHANGED
|
@@ -1,74 +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>;
|
|
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>;
|