MCPcopy
hub / github.com/midrender/revideo / image

Method image

packages/2d/src/lib/components/Latex.ts:63–108  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61 }
62
63 protected override image(): HTMLImageElement {
64 // Render props may change the look of the TeX, so we need to cache both
65 // source and render props together.
66 const src = `${this.tex()}::${JSON.stringify(this.options())}`;
67 if (Latex.svgContentsPool[src]) {
68 this.imageElement.src = Latex.svgContentsPool[src];
69 if (!this.imageElement.complete) {
70 DependencyContext.collectPromise(
71 new Promise((resolve, reject) => {
72 this.imageElement.addEventListener('load', resolve);
73 this.imageElement.addEventListener('error', reject);
74 }),
75 );
76 }
77 return this.imageElement;
78 }
79
80 // Convert to TeX, look for any errors
81 const tex = this.tex();
82 const svg = Adaptor.innerHTML(JaxDocument.convert(tex, this.options()));
83 if (svg.includes('data-mjx-error')) {
84 const errors = svg.match(/data-mjx-error="(.*?)"/);
85 if (errors && errors.length > 0) {
86 useLogger().error(`Invalid MathJax: ${errors[1]}`);
87 }
88 }
89
90 // Encode to raw base64 image format
91 const text = `data:image/svg+xml;base64,${btoa(
92 `<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n${svg}`,
93 )}`;
94 Latex.svgContentsPool[src] = text;
95 const image = document.createElement('img');
96 image.src = text;
97 image.src = text;
98 if (!image.complete) {
99 DependencyContext.collectPromise(
100 new Promise((resolve, reject) => {
101 image.addEventListener('load', resolve);
102 image.addEventListener('error', reject);
103 }),
104 );
105 }
106
107 return image;
108 }
109}

Callers

nothing calls this directly

Calls 4

useLoggerFunction · 0.90
collectPromiseMethod · 0.80
includesMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected