diff --git a/src/main.ts b/src/main.ts index 3af53fe..d946ebb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2090,6 +2090,7 @@ export default class ExcalidrawPlugin extends Plugin { } onunload() { + this.stylesManager.unload(); this.removeEventLisnters.forEach((removeEventListener) => removeEventListener(), ); diff --git a/src/utils/StylesManager.ts b/src/utils/StylesManager.ts index cc590b4..279058f 100644 --- a/src/utils/StylesManager.ts +++ b/src/utils/StylesManager.ts @@ -31,7 +31,11 @@ export class StylesManager { plugin.registerEvent( plugin.app.workspace.on("window-open", (win: WorkspaceWindow, window: Window) => { - this.copyPropertiesToTheme(win.doc); + this.stylesMap.set(win.doc, { + light: document.head.querySelector(`style[id="excalidraw-embedded-light"]`), + dark: document.head.querySelector(`style[id="excalidraw-embedded-dark"]`) + }); + //this.copyPropertiesToTheme(win.doc); }), ) @@ -43,6 +47,13 @@ export class StylesManager { }); } + public unload() { + for (const [doc, styleTags] of this.stylesMap) { + doc.head.removeChild(styleTags.light); + doc.head.removeChild(styleTags.dark); + } + } + private async harvestStyles() { const body = document.body; const iframe:HTMLIFrameElement = document.createElement("iframe"); @@ -100,11 +111,13 @@ export class StylesManager { } else { const lightStyleTag = doc.createElement("style"); lightStyleTag.type = "text/css"; + lightStyleTag.setAttribute("id", "excalidraw-embedded-light"); lightStyleTag.innerHTML = `.${EXCALIDRAW_CONTAINER_CLASS} .theme-light {\n${this.styleLight}\n}`; doc.head.appendChild(lightStyleTag); const darkStyleTag = doc.createElement("style"); darkStyleTag.type = "text/css"; + darkStyleTag.setAttribute("id", "excalidraw-embedded-dark"); darkStyleTag.innerHTML = `.${EXCALIDRAW_CONTAINER_CLASS} .theme-dark {\n${this.styleDark}\n}`; doc.head.appendChild(darkStyleTag);