Fixes for math element dimensions before/upon loading MathJax.
This commit is contained in:
parent
38b3d90fa6
commit
3fbed86d3e
@ -250,6 +250,10 @@ const loadMathJax = async () => {
|
|||||||
|
|
||||||
// Finalize loading MathJax
|
// Finalize loading MathJax
|
||||||
mathJaxLoaded = true;
|
mathJaxLoaded = true;
|
||||||
|
|
||||||
|
// Clear any caches from before loading MathJax
|
||||||
|
clearCaches();
|
||||||
|
|
||||||
if (mathJaxLoadedCallback !== undefined) {
|
if (mathJaxLoadedCallback !== undefined) {
|
||||||
mathJaxLoadedCallback(isMathElement);
|
mathJaxLoadedCallback(isMathElement);
|
||||||
}
|
}
|
||||||
@ -394,6 +398,29 @@ const metricsCache = {} as {
|
|||||||
const svgCache = {} as { [key: string]: string };
|
const svgCache = {} as { [key: string]: string };
|
||||||
// Cache the rendered MathJax images for renderMathElement()
|
// Cache the rendered MathJax images for renderMathElement()
|
||||||
const imageCache = {} as { [key: string]: HTMLImageElement };
|
const imageCache = {} as { [key: string]: HTMLImageElement };
|
||||||
|
// Cache the MathJax-wrapped text strings for wrapMathElement()
|
||||||
|
const wrappedMathCache: { [key: string]: string } = {};
|
||||||
|
|
||||||
|
const clearCaches = () => {
|
||||||
|
for (const key in mathJaxSvgCacheAM) {
|
||||||
|
delete mathJaxSvgCacheAM[key];
|
||||||
|
}
|
||||||
|
for (const key in mathJaxSvgCacheTex) {
|
||||||
|
delete mathJaxSvgCacheTex[key];
|
||||||
|
}
|
||||||
|
for (const key in metricsCache) {
|
||||||
|
delete metricsCache[key];
|
||||||
|
}
|
||||||
|
for (const key in svgCache) {
|
||||||
|
delete svgCache[key];
|
||||||
|
}
|
||||||
|
for (const key in imageCache) {
|
||||||
|
delete imageCache[key];
|
||||||
|
}
|
||||||
|
for (const key in wrappedMathCache) {
|
||||||
|
delete wrappedMathCache[key];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const textAsMjxContainer = (
|
const textAsMjxContainer = (
|
||||||
text: string,
|
text: string,
|
||||||
@ -852,6 +879,10 @@ const cleanMathElementUpdate = function (updates) {
|
|||||||
const measureMathElement = function (element, next) {
|
const measureMathElement = function (element, next) {
|
||||||
ensureMathElement(element);
|
ensureMathElement(element);
|
||||||
const isMathJaxLoaded = mathJaxLoaded;
|
const isMathJaxLoaded = mathJaxLoaded;
|
||||||
|
if (!isMathJaxLoaded && isMathElement(element as ExcalidrawElement)) {
|
||||||
|
const { width, height } = element as ExcalidrawMathElement;
|
||||||
|
return { width, height };
|
||||||
|
}
|
||||||
const fontSize = next?.fontSize ?? element.fontSize;
|
const fontSize = next?.fontSize ?? element.fontSize;
|
||||||
const text = next?.text ?? element.text;
|
const text = next?.text ?? element.text;
|
||||||
const customData = next?.customData ?? element.customData;
|
const customData = next?.customData ?? element.customData;
|
||||||
@ -1135,8 +1166,6 @@ const renderSvgMathElement = function (svgRoot, root, element, opt) {
|
|||||||
root.appendChild(node);
|
root.appendChild(node);
|
||||||
} as SubtypeMethods["renderSvg"];
|
} as SubtypeMethods["renderSvg"];
|
||||||
|
|
||||||
const wrappedMathCache: { [key: string]: string } = {};
|
|
||||||
|
|
||||||
const wrapMathElement = function (element, containerWidth, next) {
|
const wrapMathElement = function (element, containerWidth, next) {
|
||||||
ensureMathElement(element);
|
ensureMathElement(element);
|
||||||
const isMathJaxLoaded = mathJaxLoaded;
|
const isMathJaxLoaded = mathJaxLoaded;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user