diff --git a/src/EmbeddedFileLoader.ts b/src/EmbeddedFileLoader.ts index f3c8e15..86435f2 100644 --- a/src/EmbeddedFileLoader.ts +++ b/src/EmbeddedFileLoader.ts @@ -676,7 +676,7 @@ export class EmbeddedFilesLoader { } if (!excalidrawData.getEquation(id).isLoaded) { const latex = equation.latex; - const data = await tex2dataURL(latex); + const data = await tex2dataURL(latex, 4, this.plugin.app); if (data) { const fileData = { mimeType: data.mimeType, diff --git a/src/ExcalidrawAutomate.ts b/src/ExcalidrawAutomate.ts index 21c272e..1b2be1a 100644 --- a/src/ExcalidrawAutomate.ts +++ b/src/ExcalidrawAutomate.ts @@ -1605,7 +1605,7 @@ export class ExcalidrawAutomate { */ async addLaTex(topX: number, topY: number, tex: string): Promise { const id = nanoid(); - const image = await tex2dataURL(tex); + const image = await tex2dataURL(tex, 4, this.plugin.app); if (!image) { return null; } @@ -1648,7 +1648,7 @@ export class ExcalidrawAutomate { created: number; size: { height: number; width: number }; }> { - return await tex2dataURL(tex,scale); + return await tex2dataURL(tex,scale, this.plugin.app); }; /** diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index 27fec20..d752b1a 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -703,24 +703,24 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } } - public async setEmbeddableIsEditingSelf() { - (process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.setEmbeddableIsEditingSelf, "ExcalidrawView.setEmbeddableIsEditingSelf"); - this.clearEmbeddableIsEditingSelfTimer(); + public async setEmbeddableNodeIsEditing() { + (process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.setEmbeddableNodeIsEditing, "ExcalidrawView.setEmbeddableNodeIsEditing"); + this.clearEmbeddableNodeIsEditingTimer(); await this.forceSave(true); this.semaphores.embeddableIsEditingSelf = true; } - public clearEmbeddableIsEditingSelfTimer () { - (process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.clearEmbeddableIsEditingSelfTimer, "ExcalidrawView.clearEmbeddableIsEditingSelfTimer"); + public clearEmbeddableNodeIsEditingTimer () { + (process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.clearEmbeddableNodeIsEditingTimer, "ExcalidrawView.clearEmbeddableNodeIsEditingTimer"); if(this.editingSelfResetTimer) { window.clearTimeout(this.editingSelfResetTimer); this.editingSelfResetTimer = null; } } - public clearEmbeddableIsEditingSelf() { - (process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.clearEmbeddableIsEditingSelf, "ExcalidrawView.clearEmbeddableIsEditingSelf"); - this.clearEmbeddableIsEditingSelfTimer(); + public clearEmbeddableNodeIsEditing() { + (process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.clearEmbeddableNodeIsEditing, "ExcalidrawView.clearEmbeddableNodeIsEditing"); + this.clearEmbeddableNodeIsEditingTimer(); this.editingSelfResetTimer = window.setTimeout(()=>this.semaphores.embeddableIsEditingSelf = false,EMBEDDABLE_SEMAPHORE_TIMEOUT); } @@ -1938,7 +1938,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } this.clearPreventReloadTimer(); - this.clearEmbeddableIsEditingSelfTimer(); + this.clearEmbeddableNodeIsEditingTimer(); this.plugin.scriptEngine?.removeViewEAs(this); this.excalidrawAPI = null; if(this.draginfoDiv) { @@ -2048,7 +2048,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ if (this.semaphores.embeddableIsEditingSelf) { //console.log("reload - embeddable is editing") if(this.editingSelfResetTimer) { - this.clearEmbeddableIsEditingSelfTimer(); + this.clearEmbeddableNodeIsEditingTimer(); this.semaphores.embeddableIsEditingSelf = false; } if(loadOnModifyTrigger) { diff --git a/src/LaTeX.ts b/src/LaTeX.ts index 9a72e38..8d7bb96 100644 --- a/src/LaTeX.ts +++ b/src/LaTeX.ts @@ -3,19 +3,27 @@ import { DataURL } from "@zsviczian/excalidraw/types/excalidraw/types"; import ExcalidrawView from "./ExcalidrawView"; import { FileData, MimeType } from "./EmbeddedFileLoader"; import { FileId } from "@zsviczian/excalidraw/types/excalidraw/element/types"; +import { App } from "obsidian"; declare const loadMathjaxToSVG: Function; let mathjaxLoaded = false; let tex2dataURLExternal: Function; let clearVariables: Function; +let loadMathJaxPromise: Promise | null = null; + const loadMathJax = async () => { - if (!mathjaxLoaded) { - const module = await loadMathjaxToSVG(); - tex2dataURLExternal = module.tex2dataURL; - clearVariables = module.clearMathJaxVariables; - mathjaxLoaded = true; + if (!loadMathJaxPromise) { + loadMathJaxPromise = (async () => { + if (!mathjaxLoaded) { + const module = await loadMathjaxToSVG(); + tex2dataURLExternal = module.tex2dataURL; + clearVariables = module.clearMathJaxVariables; + mathjaxLoaded = true; + } + })(); } + return loadMathJaxPromise; }; export const updateEquation = async ( @@ -43,7 +51,8 @@ export const updateEquation = async ( export async function tex2dataURL( tex: string, - scale: number = 4 + scale: number = 4, + app: App, ): Promise<{ mimeType: MimeType; fileId: FileId; diff --git a/src/utils/CanvasNodeFactory.ts b/src/utils/CanvasNodeFactory.ts index fd3bd92..8ea50e9 100644 --- a/src/utils/CanvasNodeFactory.ts +++ b/src/utils/CanvasNodeFactory.ts @@ -115,9 +115,9 @@ export class CanvasNodeFactory { if (!this.initialized || !node) return; try { - if (node.file === this.view.file) { - await this.view.setEmbeddableIsEditingSelf(); - } + //if (node.file === this.view.file) { + await this.view.setEmbeddableNodeIsEditing(); + //} node.startEditing(); node.isEditing = true; @@ -141,9 +141,9 @@ export class CanvasNodeFactory { if (!this.initialized || !node || !node.isEditing) return; try { - if (node.file === this.view.file) { - this.view.clearEmbeddableIsEditingSelf(); - } + //if (node.file === this.view.file) { + this.view.clearEmbeddableNodeIsEditing(); + //} node.child.showPreview(); node.isEditing = false; this.observer?.disconnect();