mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
fix(canvas): loading of fonts under dev mode
This commit is contained in:
parent
65f9b1c4ef
commit
89d32db601
2
apps/client/src/types-assets.d.ts
vendored
2
apps/client/src/types-assets.d.ts
vendored
@ -3,7 +3,7 @@ declare module "*.png" {
|
||||
export default path;
|
||||
}
|
||||
|
||||
declare module "@triliumnext/ckeditor5/emoji_definitions/en.json?url" {
|
||||
declare module "*?url" {
|
||||
var path: string;
|
||||
export default path;
|
||||
}
|
||||
|
2
apps/client/src/types.d.ts
vendored
2
apps/client/src/types.d.ts
vendored
@ -57,6 +57,8 @@ declare global {
|
||||
|
||||
process?: ElectronProcess;
|
||||
glob?: CustomGlobals;
|
||||
|
||||
EXCALIDRAW_ASSET_PATH?: string;
|
||||
}
|
||||
|
||||
interface AutoCompleteConfig {
|
||||
|
@ -113,10 +113,6 @@ export default class ExcalidrawTypeWidget extends TypeWidget {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
// currently required by excalidraw, in order to allows self-hosting fonts locally.
|
||||
// this avoids making excalidraw load the fonts from an external CDN.
|
||||
(window as any).EXCALIDRAW_ASSET_PATH = `${window.location.pathname}/node_modules/@excalidraw/excalidraw/dist/prod`;
|
||||
|
||||
// temporary vars
|
||||
this.currentNoteId = "";
|
||||
|
||||
@ -187,6 +183,8 @@ export default class ExcalidrawTypeWidget extends TypeWidget {
|
||||
this.saveData();
|
||||
},
|
||||
});
|
||||
|
||||
await setupFonts();
|
||||
this.canvasInstance.renderCanvas(renderElement);
|
||||
}
|
||||
|
||||
@ -377,3 +375,22 @@ export default class ExcalidrawTypeWidget extends TypeWidget {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function setupFonts() {
|
||||
if (window.EXCALIDRAW_ASSET_PATH) {
|
||||
return;
|
||||
}
|
||||
|
||||
// currently required by excalidraw, in order to allows self-hosting fonts locally.
|
||||
// this avoids making excalidraw load the fonts from an external CDN.
|
||||
let path: string;
|
||||
if (!glob.isDev) {
|
||||
path = `${window.location.pathname}/node_modules/@excalidraw/excalidraw/dist/prod`;
|
||||
} else {
|
||||
path = (await import("../../../node_modules/@excalidraw/excalidraw/dist/prod/fonts/Excalifont/Excalifont-Regular-a88b72a24fb54c9f94e3b5fdaa7481c9.woff2?url")).default;
|
||||
let pathComponents = path.split("/");
|
||||
path = pathComponents.slice(0, pathComponents.length - 2).join("/");
|
||||
}
|
||||
|
||||
window.EXCALIDRAW_ASSET_PATH = path;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user