@revideo/2d 0.10.4 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revideo/2d",
3
- "version": "0.10.4",
3
+ "version": "0.10.5-alpha.1129+6e28dee0",
4
4
  "description": "A 2D renderer for revideo",
5
5
  "author": "revideo",
6
6
  "homepage": "https://re.video/",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "devDependencies": {
31
31
  "@preact/signals": "^1.2.1",
32
- "@revideo/ui": "0.10.4",
32
+ "@revideo/ui": "^0.10.5-alpha.1129+6e28dee0",
33
33
  "@rollup/plugin-node-resolve": "^15.2.4",
34
34
  "@rollup/plugin-typescript": "^12.1.0",
35
35
  "clsx": "^2.0.0",
@@ -41,7 +41,7 @@
41
41
  "@codemirror/language": "^6.10.1",
42
42
  "@lezer/common": "^1.2.1",
43
43
  "@lezer/highlight": "^1.2.0",
44
- "@revideo/core": "0.10.4",
44
+ "@revideo/core": "^0.10.5-alpha.1129+6e28dee0",
45
45
  "@rive-app/canvas-advanced": "2.7.3",
46
46
  "code-fns": "^0.8.2",
47
47
  "hls.js": "^1.5.11",
@@ -49,5 +49,5 @@
49
49
  "mp4box": "^0.5.2",
50
50
  "parse-svg-path": "^0.1.2"
51
51
  },
52
- "gitHead": "160fc155c2c757622bb46c91673f878ab48ed9cf"
52
+ "gitHead": "6e28dee0914521ae74fc783d2e4b4ededa7d7c61"
53
53
  }
@@ -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 = Adaptor.innerHTML(JaxDocument.convert(tex, this.options()));
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) {