From 2b86ba21289bd0fdbb85bda45a90c2aa4d1ff97a Mon Sep 17 00:00:00 2001 From: zsviczian Date: Mon, 20 May 2024 09:37:14 +0200 Subject: [PATCH] 2.2.1 --- manifest.json | 2 +- package.json | 2 +- src/EmbeddedFileLoader.ts | 6 ++++-- src/ExcalidrawData.ts | 25 +++++++++++++++++++++++-- src/dialogs/Messages.ts | 7 +++++++ src/lang/locale/en.ts | 4 ++++ src/main.ts | 4 ++-- src/settings.ts | 17 +++++++++++++++++ src/utils/ImageCache.ts | 4 ++-- 9 files changed, 61 insertions(+), 10 deletions(-) diff --git a/manifest.json b/manifest.json index 1a087c0..6b4b466 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "2.2.0", + "version": "2.2.1", "minAppVersion": "1.1.6", "description": "An Obsidian plugin to edit and view Excalidraw drawings", "author": "Zsolt Viczian", diff --git a/package.json b/package.json index 0c24970..6bcb772 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "license": "MIT", "dependencies": { "@popperjs/core": "^2.11.8", - "@zsviczian/excalidraw": "0.17.1-obsidian-22", + "@zsviczian/excalidraw": "0.17.1-obsidian-23", "chroma-js": "^2.4.2", "clsx": "^2.0.0", "colormaster": "^1.2.1", diff --git a/src/EmbeddedFileLoader.ts b/src/EmbeddedFileLoader.ts index f335c25..462ebff 100644 --- a/src/EmbeddedFileLoader.ts +++ b/src/EmbeddedFileLoader.ts @@ -361,7 +361,7 @@ export class EmbeddedFilesLoader { isMask, }; - const shouldUseCache = file && imageCache.isReady(); + const shouldUseCache = this.plugin.settings.allowImageCacheInScene && file && imageCache.isReady(); const cacheKey:ImageKey = { filepath: file.path, blockref: null, @@ -380,7 +380,9 @@ export class EmbeddedFilesLoader { linkpartAlias: null, } - const maybeSVG = await imageCache.getImageFromCache(cacheKey); + const maybeSVG = shouldUseCache + ? await imageCache.getImageFromCache(cacheKey) + : undefined; const svg = (maybeSVG && (maybeSVG instanceof SVGSVGElement)) ? maybeSVG diff --git a/src/ExcalidrawData.ts b/src/ExcalidrawData.ts index d075f7f..88839bd 100644 --- a/src/ExcalidrawData.ts +++ b/src/ExcalidrawData.ts @@ -262,7 +262,7 @@ const RE_TEXTELEMENTS_FALLBACK_1 = new RegExp(`(.*)%%\n##? Text Elements(?:\n|$) const RE_TEXTELEMENTS_FALLBACK_2 = new RegExp(`(.*)##? Text Elements(?:\n|$)`, "m"); -const RE_DRAWING = new RegExp(`(%%\n)?##? Drawing\n`); +const RE_DRAWING = new RegExp(`^(%%\n)?##? Drawing\n`, "m"); export const getExcalidrawMarkdownHeaderSection = (data:string, keys?:[string,string][]):string => { //The base case scenario is at the top, continued with fallbacks in order of likelihood and file structure @@ -274,6 +274,13 @@ export const getExcalidrawMarkdownHeaderSection = (data:string, keys?:[string,st %% # Excalidraw Data */ + + //trimming the json because in legacy excalidraw files the JSON was a single string resulting in very slow regexp parsing + const drawingTrimLocation = data.search(RE_DRAWING); + if(drawingTrimLocation>0) { + data = data.substring(0, drawingTrimLocation); + } + let trimLocation = data.search(RE_EXCALIDRAWDATA_WITHSECTION_OK); let shouldFixTrailingHashtag = false; if(trimLocation > 0) { @@ -386,7 +393,9 @@ export const getExcalidrawMarkdownHeaderSection = (data:string, keys?:[string,st # Drawing */ if (trimLocation === -1) { - trimLocation = data.search(RE_DRAWING); + if (drawingTrimLocation > 0) { + trimLocation = drawingTrimLocation; + } } if (trimLocation === -1) { return data.endsWith("\n") ? data : (data + "\n"); @@ -515,6 +524,18 @@ export class ExcalidrawData { if (el.fontSize === null) { el.fontSize = 20; } + + if (el.type === "text" && !el.hasOwnProperty("autoResize")) { + el.autoResize = true; + } + + if (el.type === "text" && !el.hasOwnProperty("lineHeight")) { + el.lineHeight = getDefaultLineHeight(el.fontFamily); + } + + if (el.type === "image" && !el.hasOwnProperty("roundness")) { + el.roundness = null; + } } //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/569 diff --git a/src/dialogs/Messages.ts b/src/dialogs/Messages.ts index 4bdfdba..210d35e 100644 --- a/src/dialogs/Messages.ts +++ b/src/dialogs/Messages.ts @@ -17,6 +17,13 @@ I develop this plugin as a hobby, spending my free time doing this. If you find
`, +"2.2.1":` +## Fixed +- Text height becomes unreadable after 2.2.0 update [#1784](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/1784) +- Images are loaded with a rounded border when loading old Excalidraw files +- Embedded Excalidraw images cache gets stuck with old version of the image +- Extremely long loading times with legacy (3+ years old) Excalidraw files +`, "2.2.0":`
diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index 367e41f..6178aec 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -489,6 +489,10 @@ FILENAME_HEAD: "Filename", EMBED_IMAGE_CACHE_NAME: "Cache images for embedding in markdown", EMBED_IMAGE_CACHE_DESC: "Cache images for embedding in markdown. This will speed up the embedding process, but in case you compose images of several sub-component drawings, " + "the embedded image in Markdown won't update until you open the drawing and save it to trigger an update of the cache.", + SCENE_IMAGE_CACHE_NAME: "Cache nested Excalidraws in Scene", + SCENE_IMAGE_CACHE_DESC: "Cache nested Excalidraws in the Scene for faster scene rendering. This will speed up the rendering process, especially if you have deeply nested Excalidraws in your scene. " + + "Excalidraw will try to intelligently identify if any children of a nested Excalidraw have changed and will update the cache accordingly. " + + "You may want to turn this off, in case you are suspecting that the cache is not updating properly.", EMBED_IMAGE_CACHE_CLEAR: "Purge Cache", BACKUP_CACHE_CLEAR: "Purge Backups", BACKUP_CACHE_CLEAR_CONFIRMATION: "This action will delete all Excalidraw drawing backups. Backups are used as a safety measure in case your drawing file gets damaged. Each time you open Obsidian the plugin automatically deletes backups for files that no longer exist in your Vault. Are you sure you want to clear all backups?", diff --git a/src/main.ts b/src/main.ts index 058d95e..cba68ac 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2964,10 +2964,10 @@ export default class ExcalidrawPlugin extends Plugin { const excalidrawLeaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW); excalidrawLeaves.forEach(async (leaf) => { const ev: ExcalidrawView = leaf.view as ExcalidrawView; - console.log(ev.file.name, ev.semaphores.dirty); + //console.log(ev.file.name, ev.semaphores.dirty); await this.setMarkdownView(leaf); //@ts-ignore - console.log(leaf?.view?.file); + //console.log(leaf?.view?.file); }); document.body.removeChild(this.textMeasureDiv); diff --git a/src/settings.ts b/src/settings.ts index 99b16d3..e9430b5 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -61,6 +61,7 @@ export interface ExcalidrawSettings { displaySVGInPreview: boolean; //No longer used since 1.9.13 previewImageType: PreviewImageType; //Introduced with 1.9.13 allowImageCache: boolean; + allowImageCacheInScene: boolean; displayExportedImageIfAvailable: boolean; previewMatchObsidianTheme: boolean; width: string; @@ -220,6 +221,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = { displaySVGInPreview: undefined, previewImageType: undefined, allowImageCache: true, + allowImageCacheInScene: true, displayExportedImageIfAvailable: false, previewMatchObsidianTheme: false, width: "400", @@ -1720,6 +1722,19 @@ export class ExcalidrawSettingTab extends PluginSettingTab { this.applySettingsUpdate(); }) ) + new Setting(detailsEl) + .setName(t("SCENE_IMAGE_CACHE_NAME")) + .setDesc(fragWithHTML(t("SCENE_IMAGE_CACHE_DESC"))) + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.allowImageCacheInScene) + .onChange((value) => { + this.plugin.settings.allowImageCacheInScene = value; + this.applySettingsUpdate(); + }) + ) + new Setting(detailsEl) + .setName(t("EMBED_IMAGE_CACHE_CLEAR")) .addButton((button) => button .setButtonText(t("EMBED_IMAGE_CACHE_CLEAR")) @@ -1727,6 +1742,8 @@ export class ExcalidrawSettingTab extends PluginSettingTab { imageCache.clearImageCache(); }) ) + new Setting(detailsEl) + .setName(t("BACKUP_CACHE_CLEAR")) .addButton((button) => button .setButtonText(t("BACKUP_CACHE_CLEAR")) diff --git a/src/utils/ImageCache.ts b/src/utils/ImageCache.ts index a169795..e7d1303 100644 --- a/src/utils/ImageCache.ts +++ b/src/utils/ImageCache.ts @@ -156,7 +156,7 @@ class ImageCache { const filepath = key.split("#")[0]; const fileExists = files.some((f: TFile) => f.path === filepath); const file = fileExists ? files.find((f: TFile) => f.path === filepath) : null; - if (isLegacyKey || !file || (file && file.stat.mtime > cursor.value.mtime) || (!cursor.value.blob && !cursor.value.svg)) { + if (isLegacyKey || !file || (file && (file.stat.mtime > cursor.value.mtime)) || (!cursor.value.blob && !cursor.value.svg)) { deletePromises.push( new Promise((innerResolve, innerReject) => { const deleteRequest = store.delete(cursor.primaryKey); @@ -293,7 +293,7 @@ class ImageCache { const file = this.app.vault.getAbstractFileByPath(key_.filepath.split("#")[0]); if (!file || !(file instanceof TFile)) return undefined; - if (cachedData && cachedData.mtime >= file.stat.mtime) { + if (cachedData && (cachedData.mtime >= file.stat.mtime)) { if(hasExcalidrawEmbeddedImagesTreeChanged(file, cachedData.mtime, this.plugin)) { return undefined; }