@revideo/2d 0.10.5-alpha.1127 → 0.10.5-alpha.1129
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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type {SignalValue, SimpleSignal} from '@revideo/core';
|
|
2
2
|
import {DependencyContext, useLogger} from '@revideo/core';
|
|
3
|
+
import type {LiteAdaptor} from 'mathjax-full/js/adaptors/liteAdaptor';
|
|
3
4
|
import {liteAdaptor} from 'mathjax-full/js/adaptors/liteAdaptor';
|
|
5
|
+
import type {MathDocument} from 'mathjax-full/js/core/MathDocument';
|
|
4
6
|
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html';
|
|
5
7
|
import {TeX} from 'mathjax-full/js/input/tex';
|
|
6
8
|
import {AllPackages} from 'mathjax-full/js/input/tex/AllPackages';
|
|
@@ -11,16 +13,6 @@ import {initial, signal} from '../decorators';
|
|
|
11
13
|
import type {ImgProps} from './Img';
|
|
12
14
|
import {Img} from './Img';
|
|
13
15
|
|
|
14
|
-
const Adaptor = liteAdaptor();
|
|
15
|
-
RegisterHTMLHandler(Adaptor);
|
|
16
|
-
|
|
17
|
-
const JaxDocument = mathjax.document('', {
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
19
|
-
InputJax: new TeX({packages: AllPackages}),
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
21
|
-
OutputJax: new SVG({fontCache: 'local'}),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
16
|
export interface LatexProps extends ImgProps {
|
|
25
17
|
tex?: SignalValue<string>;
|
|
26
18
|
renderProps?: SignalValue<OptionList>;
|
|
@@ -46,6 +38,24 @@ export interface LatexProps extends ImgProps {
|
|
|
46
38
|
*/
|
|
47
39
|
export class Latex extends Img {
|
|
48
40
|
private static svgContentsPool: Record<string, string> = {};
|
|
41
|
+
private static mathJaxInitialized = false;
|
|
42
|
+
private static adaptor: LiteAdaptor;
|
|
43
|
+
private static jaxDocument: MathDocument<unknown, unknown, unknown>;
|
|
44
|
+
|
|
45
|
+
private static initializeMathJax() {
|
|
46
|
+
if (this.mathJaxInitialized) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.adaptor = liteAdaptor();
|
|
50
|
+
RegisterHTMLHandler(this.adaptor);
|
|
51
|
+
this.jaxDocument = mathjax.document('', {
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
53
|
+
InputJax: new TeX({packages: AllPackages}),
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
55
|
+
OutputJax: new SVG({fontCache: 'local'}),
|
|
56
|
+
});
|
|
57
|
+
this.mathJaxInitialized = true;
|
|
58
|
+
}
|
|
49
59
|
|
|
50
60
|
private readonly imageElement = document.createElement('img');
|
|
51
61
|
|
|
@@ -58,6 +68,7 @@ export class Latex extends Img {
|
|
|
58
68
|
|
|
59
69
|
public constructor(props: LatexProps) {
|
|
60
70
|
super({...props, src: null});
|
|
71
|
+
Latex.initializeMathJax();
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
protected override image(): HTMLImageElement {
|
|
@@ -79,7 +90,9 @@ export class Latex extends Img {
|
|
|
79
90
|
|
|
80
91
|
// Convert to TeX, look for any errors
|
|
81
92
|
const tex = this.tex();
|
|
82
|
-
const svg =
|
|
93
|
+
const svg = Latex.adaptor.innerHTML(
|
|
94
|
+
Latex.jaxDocument.convert(tex, this.options()) as any,
|
|
95
|
+
);
|
|
83
96
|
if (svg.includes('data-mjx-error')) {
|
|
84
97
|
const errors = svg.match(/data-mjx-error="(.*?)"/);
|
|
85
98
|
if (errors && errors.length > 0) {
|