diff --git a/docs/API/attributes_functions_overview.md b/docs/API/attributes_functions_overview.md index c030d69..68628b7 100644 --- a/docs/API/attributes_functions_overview.md +++ b/docs/API/attributes_functions_overview.md @@ -52,8 +52,20 @@ export interface ExcalidrawAutomate { } } ):Promise; - createSVG (templatePath?:string, embedFont?:boolean):Promise; - createPNG (templatePath?:string):Promise; + createSVG ( + templatePath?:string, + embedFont?:boolean, + exportSettings?:ExportSettings, //see ExcalidrawAutomate.getExportSettings(boolean,boolean) + loader?:EmbeddedFilesLoader, //see ExcalidrawAutomate.getEmbeddedFilesLoader(boolean?) + theme?:string + ):Promise; + createPNG ( + templatePath?:string, + scale?:number, + exportSettings?:ExportSettings, //see ExcalidrawAutomate.getExportSettings(boolean,boolean) + loader?:EmbeddedFilesLoader, //see ExcalidrawAutomate.getEmbeddedFilesLoader(boolean?) + theme?:string + ):Promise; wrapText (text:string, lineLen:number):string; addRect (topX:number, topY:number, width:number, height:number):string; addDiamond (topX:number, topY:number, width:number, height:number):string; @@ -84,7 +96,7 @@ export interface ExcalidrawAutomate { } ):string ; addImage(topX:number, topY:number, imageFile: TFile):Promise; - addLaTex(topX:number, topY:number, tex: string, color?:string):Promise; + addLaTex(topX:number, topY:number, tex: string):Promise; connectObjects ( objectA: string, connectionA: ConnectionPoint, @@ -134,6 +146,10 @@ export interface ExcalidrawAutomate { view: ExcalidrawView, //the excalidraw view receiving the drop pointerPosition: {x:number, y:number} //the pointer position on canvas at the time of drop }):boolean; + mostRecentMarkdownSVG:SVGSVGElement; //Markdown renderer will drop a copy of the most recent SVG here for debugging purposes + //utility functions to generate EmbeddedFilesLoaderand ExportSettings objects + getEmbeddedFilesLoader(isDark?:boolean):EmbeddedFilesLoader; + getExportSettings(withBackground:boolean,withTheme:boolean):ExportSettings; } ``` diff --git a/manifest.json b/manifest.json index 142eff0..eb1bd72 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "1.4.14", + "version": "1.4.15", "minAppVersion": "0.12.16", "description": "An Obsidian plugin to edit and view Excalidraw drawings", "author": "Zsolt Viczian", diff --git a/src/EmbeddedFileLoader.ts b/src/EmbeddedFileLoader.ts index ced0bf9..67ad552 100644 --- a/src/EmbeddedFileLoader.ts +++ b/src/EmbeddedFileLoader.ts @@ -312,7 +312,7 @@ const convertMarkdownToSVG = async (plugin: ExcalidrawPlugin, file: TFile, linkP } } - const fontColor = fileCache?.frontmatter ? fileCache.frontmatter[FRONTMATTER_KEY_FONTCOLOR] : plugin.settings.mdFontColor; + const fontColor = fileCache?.frontmatter ? fileCache.frontmatter[FRONTMATTER_KEY_FONTCOLOR]??plugin.settings.mdFontColor:plugin.settings.mdFontColor; let style = fileCache?.frontmatter ? (fileCache.frontmatter[FRONTMATTER_KEY_MD_STYLE]??"") : ""; let frontmatterCSSisAfile = false; @@ -355,7 +355,7 @@ const convertMarkdownToSVG = async (plugin: ExcalidrawPlugin, file: TFile, linkP mdDIV.style.fontFamily = fontName; mdDIV.style.overflow = "auto"; mdDIV.style.display = "block"; - if(fontColor) mdDIV.style.color = fontColor; + if(fontColor && fontColor!="") mdDIV.style.color = fontColor; await MarkdownRenderer.renderMarkdown(text,mdDIV,file.path,plugin); mdDIV.querySelectorAll(":scope > *[class^='frontmatter']").forEach((el)=>mdDIV.removeChild(el)); @@ -417,36 +417,6 @@ const convertMarkdownToSVG = async (plugin: ExcalidrawPlugin, file: TFile, linkP return svgToBase64(finalSVG) as DataURL; } -const styleSandbox = async (style:string,fontName:string,fontColor:string, text:string,path:string,plugin:ExcalidrawPlugin) => { - const host = document.body.createDiv(); - host.style.display = "none"; - const iframe = host.createEl("iframe"); - const doc = iframe.contentWindow.document; - if(style) { - const styleEl = doc.createElement("style"); - styleEl.type = "text/css"; - styleEl.innerHTML = style; - doc.head.appendChild(styleEl); - } - const div = createDiv("div"); - - doc.body.querySelectorAll("*").forEach((el:HTMLElement)=>{ - const elementStyle = el.style; - const computedStyle = window.getComputedStyle(el); - let style = ""; - for (const prop in elementStyle) { - if (elementStyle.hasOwnProperty(prop)) { - style += prop + ": " + computedStyle[prop] + ";"; - } - } - el.setAttribute("style",style); - }); - - const xml = (new XMLSerializer().serializeToString(div)) - document.body.removeChild(host); - return xml; -} - const getDataURL = async (file: ArrayBuffer,mimeType: string): Promise => { return new Promise((resolve, reject) => { const reader = new FileReader(); diff --git a/src/ExcalidrawAutomate.ts b/src/ExcalidrawAutomate.ts index e1e4de7..99660b2 100644 --- a/src/ExcalidrawAutomate.ts +++ b/src/ExcalidrawAutomate.ts @@ -18,7 +18,7 @@ import { VIEW_TYPE_EXCALIDRAW, MAX_IMAGE_SIZE, } from "./constants"; -import { debug, embedFontsInSVG, errorlog, getPNG, getSVG, scaleLoadedImage, wrapText } from "./Utils"; +import { debug, embedFontsInSVG, errorlog, getPNG, getSVG, isObsidianThemeDark, scaleLoadedImage, wrapText } from "./Utils"; import { AppState, DataURL } from "@zsviczian/excalidraw/types/types"; import { EmbeddedFilesLoader, FileData, MimeType } from "./EmbeddedFileLoader"; import { tex2dataURL } from "./LaTeX"; @@ -77,15 +77,15 @@ export interface ExcalidrawAutomate { createSVG ( templatePath?:string, embedFont?:boolean, - exportSettings?:ExportSettings, - loader?:EmbeddedFilesLoader, + exportSettings?:ExportSettings, //see ExcalidrawAutomate.getExportSettings(boolean,boolean) + loader?:EmbeddedFilesLoader, //see ExcalidrawAutomate.getEmbeddedFilesLoader(boolean?) theme?:string ):Promise; createPNG ( templatePath?:string, scale?:number, - exportSettings?:ExportSettings, - loader?:EmbeddedFilesLoader, + exportSettings?:ExportSettings, //see ExcalidrawAutomate.getExportSettings(boolean,boolean) + loader?:EmbeddedFilesLoader, //see ExcalidrawAutomate.getEmbeddedFilesLoader(boolean?) theme?:string ):Promise; wrapText (text:string, lineLen:number):string; @@ -169,6 +169,9 @@ export interface ExcalidrawAutomate { pointerPosition: {x:number, y:number} //the pointer position on canvas at the time of drop }):boolean; mostRecentMarkdownSVG:SVGSVGElement; //Markdown renderer will drop a copy of the most recent SVG here for debugging purposes + //utility functions to generate EmbeddedFilesLoaderand ExportSettings objects + getEmbeddedFilesLoader(isDark?:boolean):EmbeddedFilesLoader; + getExportSettings(withBackground:boolean,withTheme:boolean):ExportSettings; } declare let window: any; @@ -358,9 +361,26 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin):Promise { + if(!theme) { + theme = this.plugin.settings.previewMatchObsidianTheme + ? (isObsidianThemeDark() ? "dark" : "light") + : (!this.plugin.settings.exportWithTheme + ? "light" + : undefined); + } + if(theme && !exportSettings) { + exportSettings = { + withBackground: this.plugin.settings.exportBackground, + withTheme: true + } + } + if(!loader) { + const loader = new EmbeddedFilesLoader(this.plugin,theme?(theme==="dark"):undefined); + } + return await createSVG( templatePath, embedFont, @@ -377,9 +397,26 @@ export async function initExcalidrawAutomate(plugin: ExcalidrawPlugin):Promise { + if(!loader) loader = new EmbeddedFilesLoader(plugin); const template = templatePath ? (await getTemplate(plugin,templatePath,true,loader)) : null; let elements = template?.elements ?? []; elements = elements.concat(automateElements); diff --git a/src/main.ts b/src/main.ts index 6bf9167..b31b72a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -155,8 +155,8 @@ export default class ExcalidrawPlugin extends Plugin { const self = this; this.loadMathJax(); - process.env.REACT_APP_LIBRARY_URL = "https://libraries.excalidraw.com/"; - process.env.REACT_APP_LIBRARY_BACKEND = "https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries"; +// process.env.REACT_APP_LIBRARY_URL = "https://libraries.excalidraw.com/"; +// process.env.REACT_APP_LIBRARY_BACKEND = "https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries"; } private loadMathJax() { @@ -489,8 +489,11 @@ export default class ExcalidrawPlugin extends Plugin { private experimentalFileTypeDisplay() { const insertFiletype = (el: HTMLElement) => { if(el.childElementCount != 1) return; - //@ts-ignore - if(this.isExcalidrawFile(this.app.vault.getAbstractFileByPath(el.attributes["data-path"].value))) { + const filename = el.getAttribute("data-path"); + if(!filename) return; + const f = this.app.vault.getAbstractFileByPath(filename); + if(!f || !(f instanceof TFile)) return; + if(this.isExcalidrawFile(f)) { el.insertBefore(createDiv({cls:"nav-file-tag",text:this.settings.experimentalFileTag}),el.firstChild); } }; diff --git a/versions.json b/versions.json index d855f07..710bd53 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,4 @@ { - "1.4.14": "0.12.16", + "1.4.15": "0.12.16", "1.4.2": "0.11.13" }