styles manager improvements

This commit is contained in:
zsviczian
2023-08-08 20:00:37 +02:00
parent 23dd4883e3
commit 3bcf460ce4
2 changed files with 15 additions and 1 deletions

View File

@@ -2090,6 +2090,7 @@ export default class ExcalidrawPlugin extends Plugin {
}
onunload() {
this.stylesManager.unload();
this.removeEventLisnters.forEach((removeEventListener) =>
removeEventListener(),
);

View File

@@ -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);