Skip to content

Commit

Permalink
fix(excalidraw): cannot read properties of undefined (reading "skipIn…
Browse files Browse the repository at this point in the history
…liningFonts")
  • Loading branch information
Mara-Li committed Sep 22, 2024
1 parent 503bf7c commit 6fb1133
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/@types/ExcalidrawAutomate.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export declare class ExcalidrawAutomate {
/**
*
* @param templatePath
* @param embedFont
* @param exportSettings use ExcalidrawAutomate.getExportSettings(boolean,boolean)
* @param loader use ExcalidrawAutomate.getEmbeddedFilesLoader(boolean?)
* @param theme
* @param padding
* @returns
*/
createSVG(
templatePath?: string,
embedFont?: boolean,
exportSettings?: ExportSettings,
loader?: any,
theme?: string,
padding?: number
): Promise<SVGSVGElement>;

/**
* utility function to generate EmbeddedFilesLoader object
* @param isDark
* @returns
*/
getEmbeddedFilesLoader(isDark?: boolean): any;

/**
* utility function to generate ExportSettings object
* @param withBackground
* @param withTheme
* @returns
*/
getExportSettings(withBackground: boolean, withTheme: boolean): ExportSettings;
}

interface ExportSettings {
withBackground: boolean;
withTheme: boolean;
isMask: boolean;
frameRendering?: {
//optional, overrides relevant appState settings for rendering the frame
enabled: boolean;
name: boolean;
outline: boolean;
clip: boolean;
};
skipInliningFonts?: boolean;
}
11 changes: 9 additions & 2 deletions src/conversion/compiler/excalidraw.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import type { App, TFile } from "obsidian";
import type {ExcalidrawAutomate} from "../../@types/ExcalidrawAutomate";

/**
* @param file
* @param app
*/
export async function convertToHTMLSVG(file: TFile, app: App) {
try {
const excalidraw = app.plugins.getPlugin("obsidian-excalidraw-plugin");
if (!excalidraw) return null;
// @ts-ignore
const ea = excalidraw.ea;
const svg = await ea.createSVG(file.path, ea.getExportSettings(true, true));
const ea = excalidraw.ea as ExcalidrawAutomate;
const settings = ea.getExportSettings(true, true);
const embeddedFilesLoader = ea.getEmbeddedFilesLoader(true);
const svg = await ea.createSVG(file.path, true, settings, embeddedFilesLoader);
return svg.outerHTML as string;
} catch (e) {
console.error(e);
Expand Down

0 comments on commit 6fb1133

Please sign in to comment.