mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2026-11-27 06:32:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d881fe418 | ||
|
|
66c119a9e8 | ||
|
|
2195c9bb98 | ||
|
|
03d4965976 | ||
|
|
3077d88e57 |
No files matched your search
@@ -1,3 +1,4 @@
|
||||
export const TAG_PDFEXPORT = "PDFExport";
|
||||
export const TAG_MDREADINGMODE = "MDReadingMode";
|
||||
export const TAG_AUTOEXPORT = "Autoexport";
|
||||
export const TAG_AUTOEXPORT = "Autoexport";
|
||||
export const TAG_IMAGECACHE = "ResetImageCache";
|
||||
@@ -214,7 +214,7 @@ export const ROUNDNESS = { //should at one point publish @zsviczian/excalidraw/t
|
||||
PROPORTIONAL_RADIUS: 2,
|
||||
ADAPTIVE_RADIUS: 3,
|
||||
} as const;
|
||||
export const THEME_FILTER = "invert(100%) hue-rotate(180deg) saturate(1.25)";
|
||||
export const THEME_FILTER = "invert(93%) hue-rotate(180deg) saturate(1.25)";
|
||||
export const GITHUB_RELEASES = "https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/";
|
||||
export const URLFETCHTIMEOUT = 3000;
|
||||
export const PLUGIN_ID = "obsidian-excalidraw-plugin";
|
||||
|
||||
+69
-3
@@ -2,6 +2,7 @@ import {
|
||||
App,
|
||||
ButtonComponent,
|
||||
DropdownComponent,
|
||||
ExtraButtonComponent,
|
||||
getIcon,
|
||||
Modifier,
|
||||
normalizePath,
|
||||
@@ -10,7 +11,7 @@ import {
|
||||
TextComponent,
|
||||
TFile,
|
||||
} from "obsidian";
|
||||
import { GITHUB_RELEASES, setRootElementSize } from "src/constants/constants";
|
||||
import { GITHUB_RELEASES, setRootElementSize, THEME_FILTER } from "src/constants/constants";
|
||||
import { t } from "src/lang/helpers";
|
||||
import type ExcalidrawPlugin from "src/core/main";
|
||||
import { PenStyle } from "src/types/penTypes";
|
||||
@@ -38,7 +39,7 @@ import { ANNOTATED_PREFIX, CROPPED_PREFIX } from "src/utils/carveout";
|
||||
import { EDITOR_FADEOUT } from "src/core/editor/EditorHandler";
|
||||
import { setDebugging } from "src/utils/debugHelper";
|
||||
import { Rank } from "src/constants/actionIcons";
|
||||
import { TAG_AUTOEXPORT, TAG_MDREADINGMODE, TAG_PDFEXPORT } from "src/constants/constSettingsTags";
|
||||
import { TAG_AUTOEXPORT, TAG_IMAGECACHE, TAG_MDREADINGMODE, TAG_PDFEXPORT } from "src/constants/constSettingsTags";
|
||||
import { HotkeyEditor } from "src/shared/Dialogs/HotkeyEditor";
|
||||
import { getExcalidrawViews } from "src/utils/obsidianUtils";
|
||||
import { createSliderWithText } from "src/utils/sliderUtils";
|
||||
@@ -48,6 +49,9 @@ import { UIMode, UIModeSettingsComponent } from "src/shared/Dialogs/UIModeSettin
|
||||
import { ScriptSettingValue } from "src/types/excalidrawAutomateTypes";
|
||||
|
||||
export interface ExcalidrawSettings {
|
||||
invertSVGforDarkMode: boolean;
|
||||
invertBitmapforDarkMode: boolean;
|
||||
themeFilter: string;
|
||||
copyLinkToElemenetAnchorTo100: boolean;
|
||||
copyFrameLinkByName: boolean;
|
||||
disableDoubleClickTextEditing: boolean;
|
||||
@@ -239,6 +243,9 @@ export interface ExcalidrawSettings {
|
||||
declare const PLUGIN_VERSION:string;
|
||||
|
||||
export const DEFAULT_SETTINGS: ExcalidrawSettings = {
|
||||
invertSVGforDarkMode: true,
|
||||
invertBitmapforDarkMode: false,
|
||||
themeFilter: THEME_FILTER,
|
||||
copyLinkToElemenetAnchorTo100: false,
|
||||
copyFrameLinkByName: false,
|
||||
disableDoubleClickTextEditing: false,
|
||||
@@ -2223,7 +2230,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
}
|
||||
});
|
||||
|
||||
new Setting(detailsEl)
|
||||
const embedImageCacheSetting = new Setting(detailsEl)
|
||||
.setName(t("EMBED_IMAGE_CACHE_NAME"))
|
||||
.setDesc(fragWithHTML(t("EMBED_IMAGE_CACHE_DESC")))
|
||||
.addToggle((toggle) =>
|
||||
@@ -2234,6 +2241,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
this.applySettingsUpdate();
|
||||
})
|
||||
)
|
||||
embedImageCacheSetting.controlEl.setAttribute("id",TAG_IMAGECACHE);
|
||||
new Setting(detailsEl)
|
||||
.setName(t("SCENE_IMAGE_CACHE_NAME"))
|
||||
.setDesc(fragWithHTML(t("SCENE_IMAGE_CACHE_DESC")))
|
||||
@@ -2416,6 +2424,64 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
|
||||
this.applySettingsUpdate();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(detailsEl)
|
||||
.setName(t("EMBED_INVERT_SVG"))
|
||||
.setDesc(fragWithHTML(t("EMBED_INVERT_SVG_DESC")))
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.invertSVGforDarkMode)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.invertSVGforDarkMode = value;
|
||||
this.applySettingsUpdate();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(detailsEl)
|
||||
.setName(t("EMBED_INVERT_BITMAP"))
|
||||
.setDesc(fragWithHTML(t("EMBED_INVERT_BITMAP_DESC")))
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.invertBitmapforDarkMode)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.invertBitmapforDarkMode = value;
|
||||
this.applySettingsUpdate();
|
||||
}),
|
||||
);
|
||||
|
||||
let themeFilterSettingText:TextComponent;
|
||||
let themeFilterResetButton:ExtraButtonComponent;
|
||||
new Setting(detailsEl)
|
||||
.setName(t("EMBED_THEME_FILTER_NAME"))
|
||||
.setDesc(fragWithHTML(t("EMBED_THEME_FILTER_DESC")))
|
||||
.addText((text) => {
|
||||
themeFilterSettingText = text;
|
||||
text
|
||||
.setPlaceholder("e.g.: brightness(0.9) contrast(1.2)")
|
||||
.setValue(this.plugin.settings.themeFilter)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.themeFilter = value;
|
||||
this.applySettingsUpdate();
|
||||
if (value !== THEME_FILTER) {
|
||||
themeFilterResetButton.extraSettingsEl.style.display = "";
|
||||
}
|
||||
})
|
||||
})
|
||||
.addExtraButton((btn) => {
|
||||
themeFilterResetButton = btn;
|
||||
btn
|
||||
.setIcon("rotate-ccw")
|
||||
.setTooltip(t("RESET")!)
|
||||
.onClick(() => {
|
||||
themeFilterSettingText.setValue(THEME_FILTER);
|
||||
this.plugin.settings.themeFilter = THEME_FILTER;
|
||||
themeFilterResetButton.extraSettingsEl.style.display = "none";
|
||||
this.applySettingsUpdate();
|
||||
})
|
||||
});
|
||||
if(this.plugin.settings.themeFilter === THEME_FILTER) {
|
||||
themeFilterResetButton.extraSettingsEl.style.display = "none";
|
||||
}
|
||||
|
||||
detailsEl = exportDetailsEl.createEl("details");
|
||||
detailsEl.createEl("summary", {
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
FRONTMATTER_KEYS,
|
||||
CJK_FONTS,
|
||||
} from "src/constants/constants";
|
||||
import { TAG_AUTOEXPORT, TAG_MDREADINGMODE, TAG_PDFEXPORT } from "src/constants/constSettingsTags";
|
||||
import { TAG_AUTOEXPORT, TAG_IMAGECACHE, TAG_MDREADINGMODE, TAG_PDFEXPORT } from "src/constants/constSettingsTags";
|
||||
import { labelALT, labelCTRL, labelMETA, labelSHIFT } from "src/utils/modifierkeyHelper";
|
||||
|
||||
declare const PLUGIN_VERSION:string;
|
||||
@@ -689,6 +689,13 @@ export default {
|
||||
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.",
|
||||
EMBED_INVERT_SVG: "Invert embedded Excalidraw drawings and SVG images in dark mode",
|
||||
EMBED_INVERT_SVG_DESC: "The change will only take affect when you reopen your drawing. When changing this setting, you may need to clear the <a href='#"+TAG_IMAGECACHE+"'>image cache</a>. This is the default for all images; set colorMap.invertInDarkMode to override per image.",
|
||||
EMBED_INVERT_BITMAP: "Invert embedded bitmap images in dark mode",
|
||||
EMBED_INVERT_BITMAP_DESC: "The change will only take affect when you reopen your drawing. When changing this setting, you may need to clear the <a href='#"+TAG_IMAGECACHE+"'>image cache</a>. This is the default for all images; set colorMap.invertInDarkMode to override per image.",
|
||||
EMBED_THEME_FILTER_NAME: "Theme filter for color inversion",
|
||||
EMBED_THEME_FILTER_DESC: "Modify this only if you know what you are doing. The change will only take affect when you reopen your drawing. When changing this setting, you may need to clear the <a href='#"+TAG_IMAGECACHE+"'>image cache</a>.",
|
||||
RESET: "Reset to default",
|
||||
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. " +
|
||||
|
||||
@@ -17,6 +17,12 @@ I build this plugin in my free time, as a labor of love. Curious about the philo
|
||||
|
||||
<div class="ex-coffee-div"><a href="https://ko-fi.com/zsolt"><img src="https://storage.ko-fi.com/cdn/kofi6.png?v=6" border="0" alt="Buy Me a Coffee at ko-fi.com" height=45></a></div>
|
||||
`,
|
||||
"2.20.0":`
|
||||
## New
|
||||
- Dark theme from Excalidraw.com [#10578](https://github.com/excalidraw/excalidraw/pull/10578)
|
||||
- New setting in Excalidraw plugin settings under "Embedding Excalidraw/Export Settings/Image Theme". You can now choose to invert embedded SVG/Excalidraw and Bitmap images in dark mode.
|
||||
- New Easter Egg feature, by adding {invertColors: true/false} after the embedded file in Excalidraw markdown view, you can control whether the embedded image inverts colors in dark mode or not, regardless of the global setting.
|
||||
`,
|
||||
"2.19.2":`
|
||||
## Fixed
|
||||
- Minor fixes to the link autocomplete functionality:
|
||||
@@ -39,7 +45,6 @@ I build this plugin in my free time, as a labor of love. Curious about the philo
|
||||
|
||||
## New in ExcalidrawAutomate
|
||||
- Added PDF++ image link support to the \`addImage()\` function.
|
||||
|
||||
`,
|
||||
"2.19.0":`
|
||||
<div class="excalidraw-videoWrapper">
|
||||
|
||||
@@ -422,7 +422,8 @@ export const EXCALIDRAW_AUTOMATE_INFO: SuggesterInfo[] = [
|
||||
"Set scale to false if you want to embed the image at 100% of its original size. Default is true which will insert a scaled image.\n"+
|
||||
"anchor will only be evaluated if scale is false. anchor true will add |100% to the end of the filename, resulting in an image that will always pop back to 100% when the source file is updated or when the Excalidraw file is reopened.\n"+
|
||||
"colorMap is only used for SVG images and nested Excalidraw images. See the Shade Master script and the Deconstruct Selected Elements script for examples using colorMap.\n"+
|
||||
"type ColorMap = { [color: string]: string; }",
|
||||
"Set colorMap.invertInDarkMode to force or disable dark-mode inversion for that image.\n"+
|
||||
"type ColorMap = { [color: string]: string; invertInDarkMode?: boolean; }",
|
||||
after: "",
|
||||
},
|
||||
{
|
||||
@@ -561,7 +562,7 @@ export const EXCALIDRAW_AUTOMATE_INFO: SuggesterInfo[] = [
|
||||
desc: 'Updates the color map of an SVG image element in the view. If a ColorMap is provided, it will be used directly. If an SVGColorInfo is provided, it will be converted to a ColorMap. The view will be marked as dirty (i.e. will be saved at next scheduled time) and the image will be reset using the color map.\n'+
|
||||
'See "Shade Master" scritp in Script Library for an example of using this function.\n\n' +
|
||||
'type SVGColorInfo = Map<string, { mappedTo: string; fill: boolean; stroke: boolean; }>\n' +
|
||||
'type ColorMap = { [color: string]: string; }',
|
||||
'type ColorMap = { [color: string]: string; invertInDarkMode?: boolean; }',
|
||||
after: "",
|
||||
},
|
||||
{
|
||||
@@ -569,7 +570,7 @@ export const EXCALIDRAW_AUTOMATE_INFO: SuggesterInfo[] = [
|
||||
code: "getColorMapForImageElement(el: ExcalidrawElement): ColorMap",
|
||||
desc: 'Retrieves the color map for an image element. The color map contains information about the mapping of colors used in the image. If the element already has a color map, it will be returned. The colorMap does not include all colors in the image, only those that have been mapped.\n' +
|
||||
'See "Shade Master" scritp in Script Library for an example of using this function.\n\n' +
|
||||
'type ColorMap = { [color: string]: string; }',
|
||||
'type ColorMap = { [color: string]: string; invertInDarkMode?: boolean; }',
|
||||
after: "",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
FRONTMATTER_KEYS,
|
||||
getCSSFontDefinition,
|
||||
} from "../constants/constants";
|
||||
import { createSVG } from "src/utils/excalidrawAutomateUtils";
|
||||
import { createSVG, normalizeColorMap } from "src/utils/excalidrawAutomateUtils";
|
||||
import { ExcalidrawData, getTransclusion } from "./ExcalidrawData";
|
||||
import { t } from "../lang/helpers";
|
||||
import { tex2dataURL } from "./LaTeX";
|
||||
@@ -54,8 +54,6 @@ import { ExportSettings } from "src/types/exportUtilTypes";
|
||||
//and getObsidianImage is aborted if the file is already in the Watchdog stack
|
||||
const markdownRendererRecursionWatcthdog = new Set<TFile>();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Function takes an SVG and replaces all fill and stroke colors with the ones in the colorMap
|
||||
* @param svg: SVGSVGElement
|
||||
@@ -63,13 +61,17 @@ const markdownRendererRecursionWatcthdog = new Set<TFile>();
|
||||
* @returns svg with colors replaced
|
||||
*/
|
||||
const replaceSVGColors = (svg: SVGSVGElement | string, colorMap: ColorMap | null): SVGSVGElement | string => {
|
||||
if(!colorMap) {
|
||||
const normalizedColorMap = normalizeColorMap(colorMap);
|
||||
if(!normalizedColorMap) {
|
||||
return svg;
|
||||
}
|
||||
|
||||
if(typeof svg === 'string') {
|
||||
// Replace colors in the SVG string
|
||||
for (const [oldColor, newColor] of Object.entries(colorMap)) {
|
||||
for (const [oldColor, newColor] of Object.entries(normalizedColorMap)) {
|
||||
if(typeof newColor !== "string" || oldColor === "invertInDarkMode") {
|
||||
continue;
|
||||
}
|
||||
if(oldColor === "stroke" || oldColor === "fill") {
|
||||
const [svgTag, prefix, suffix] = (svg.match(/(<svg[^>]*)(>)/i) || []) as string[];
|
||||
if (!svgTag) continue;
|
||||
@@ -102,11 +104,11 @@ const replaceSVGColors = (svg: SVGSVGElement | string, colorMap: ColorMap | null
|
||||
const oldFill = node.getAttribute('fill')?.toLocaleLowerCase();
|
||||
const oldStroke = node.getAttribute('stroke')?.toLocaleLowerCase();
|
||||
|
||||
if (oldFill && colorMap[oldFill]) {
|
||||
node.setAttribute('fill', colorMap[oldFill]);
|
||||
if (oldFill && typeof normalizedColorMap[oldFill] === "string") {
|
||||
node.setAttribute('fill', normalizedColorMap[oldFill] as string);
|
||||
}
|
||||
if (oldStroke && colorMap[oldStroke]) {
|
||||
node.setAttribute('stroke', colorMap[oldStroke]);
|
||||
if (oldStroke && typeof normalizedColorMap[oldStroke] === "string") {
|
||||
node.setAttribute('stroke', normalizedColorMap[oldStroke] as string);
|
||||
}
|
||||
}
|
||||
for(const child of node.childNodes) {
|
||||
@@ -114,8 +116,8 @@ const replaceSVGColors = (svg: SVGSVGElement | string, colorMap: ColorMap | null
|
||||
}
|
||||
}
|
||||
|
||||
if("fill" in colorMap) svg.setAttribute("fill", colorMap.fill);
|
||||
if("stroke" in colorMap) svg.setAttribute("stroke", colorMap.stroke);
|
||||
if(typeof normalizedColorMap.fill === "string") svg.setAttribute("fill", normalizedColorMap.fill);
|
||||
if(typeof normalizedColorMap.stroke === "string") svg.setAttribute("stroke", normalizedColorMap.stroke);
|
||||
for (const child of svg.childNodes) {
|
||||
childNodes(child);
|
||||
}
|
||||
@@ -123,6 +125,38 @@ const replaceSVGColors = (svg: SVGSVGElement | string, colorMap: ColorMap | null
|
||||
return svg;
|
||||
}
|
||||
|
||||
const getInvertPreference = (colorMap: ColorMap | null | undefined, fallback: boolean): boolean =>
|
||||
typeof colorMap?.invertInDarkMode === "boolean" ? colorMap.invertInDarkMode : fallback;
|
||||
|
||||
const applyThemeFilterToBitmapDataURL = async (
|
||||
dataURL: DataURL,
|
||||
mimeType: MimeType,
|
||||
themeFilter: string,
|
||||
): Promise<DataURL> =>
|
||||
new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
try {
|
||||
const canvas = createEl("canvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
if(!ctx) {
|
||||
reject(new Error("Canvas 2D context unavailable"));
|
||||
return;
|
||||
}
|
||||
|
||||
canvas.width = img.naturalWidth || img.width;
|
||||
canvas.height = img.naturalHeight || img.height;
|
||||
ctx.filter = themeFilter || THEME_FILTER;
|
||||
ctx.drawImage(img, 0, 0);
|
||||
resolve(canvas.toDataURL(mimeType) as DataURL);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
};
|
||||
img.onerror = (e) => reject(e);
|
||||
img.src = dataURL;
|
||||
});
|
||||
|
||||
export class EmbeddedFile {
|
||||
public file: TFile = null;
|
||||
public isSVGwithBitmap: boolean = false;
|
||||
@@ -145,9 +179,10 @@ export class EmbeddedFile {
|
||||
constructor(plugin: ExcalidrawPlugin, hostPath: string, imgPath: string, colorMapJSON?: string) {
|
||||
this.plugin = plugin;
|
||||
this.resetImage(hostPath, imgPath);
|
||||
if(this.file && (this.plugin.isExcalidrawFile(this.file) || this.file.extension.toLowerCase() === "svg")) {
|
||||
if(this.file) { // && (this.plugin.isExcalidrawFile(this.file) || this.file.extension.toLowerCase() === "svg")) {
|
||||
try {
|
||||
this.colorMap = colorMapJSON ? JSON.parse(colorMapJSON.toLocaleLowerCase()) : null;
|
||||
const parsedColorMap = colorMapJSON ? JSON.parse(colorMapJSON) : null;
|
||||
this.colorMap = normalizeColorMap(parsedColorMap);
|
||||
} catch (error) {
|
||||
this.colorMap = null;
|
||||
}
|
||||
@@ -155,7 +190,17 @@ export class EmbeddedFile {
|
||||
}
|
||||
|
||||
get hasSeparateDarkAndLightVersion(): boolean {
|
||||
return this.isSVGwithBitmap || (this.file && this.file.extension.toLowerCase() === "pdf");
|
||||
const isPDF = this.file && this.file.extension.toLowerCase() === "pdf";
|
||||
const mime = this.mimeType?.toLowerCase?.();
|
||||
const isBitmap = mime?.startsWith("image/") && mime !== "image/svg+xml";
|
||||
const invertPreference = getInvertPreference(this.colorMap, !!this.plugin?.settings?.invertBitmapforDarkMode);
|
||||
const needsBitmapInversion =
|
||||
invertPreference &&
|
||||
isBitmap &&
|
||||
!isPDF;
|
||||
const needsPDFInversion = invertPreference && isPDF;
|
||||
|
||||
return needsBitmapInversion || needsPDFInversion || this.isSVGwithBitmap;
|
||||
}
|
||||
|
||||
public resetImage(hostPath: string, imgPath: string) {
|
||||
@@ -352,7 +397,10 @@ export class EmbeddedFilesLoader {
|
||||
skipInliningFonts: false,
|
||||
};
|
||||
|
||||
const hasColorMap = Boolean(inFile instanceof EmbeddedFile ? inFile.colorMap : null);
|
||||
const colorMap = inFile instanceof EmbeddedFile ? inFile.colorMap : null;
|
||||
const invertBitmapInDarkMode = getInvertPreference(colorMap, this.plugin.settings.invertBitmapforDarkMode);
|
||||
const invertSVGInDarkMode = getInvertPreference(colorMap, this.plugin.settings.invertSVGforDarkMode);
|
||||
const hasColorMap = Boolean(colorMap);
|
||||
const shouldUseCache = !hasColorMap && this.plugin.settings.allowImageCacheInScene && file && imageCache.isReady();
|
||||
const hasFilenameParts = Boolean((inFile instanceof EmbeddedFile) && inFile.filenameparts);
|
||||
const filenameParts = hasFilenameParts ? (inFile as EmbeddedFile).filenameparts : null;
|
||||
@@ -409,7 +457,7 @@ export class EmbeddedFilesLoader {
|
||||
depth+1,
|
||||
getExportPadding(this.plugin, file),
|
||||
),
|
||||
inFile instanceof EmbeddedFile ? inFile.colorMap : null
|
||||
colorMap
|
||||
) as SVGSVGElement;
|
||||
|
||||
//https://stackoverflow.com/questions/51154171/remove-css-filter-on-child-elements
|
||||
@@ -420,14 +468,21 @@ export class EmbeddedFilesLoader {
|
||||
hasSVGwithBitmap = true;
|
||||
}
|
||||
|
||||
if (hasSVGwithBitmap && isDark && !Boolean(maybeSVG)) {
|
||||
if (isDark && invertSVGInDarkMode) {
|
||||
svg.setAttribute("filter", this.plugin.settings.themeFilter);
|
||||
}
|
||||
if (isDark && hasSVGwithBitmap && !Boolean(maybeSVG) && (
|
||||
(!invertBitmapInDarkMode && invertSVGInDarkMode) ||
|
||||
(invertBitmapInDarkMode && !invertSVGInDarkMode)
|
||||
)) {
|
||||
imageList.forEach((i) => {
|
||||
const id = i.parentElement?.id;
|
||||
svg.querySelectorAll(`use[href='#${id}']`).forEach((u) => {
|
||||
u.setAttribute("filter", THEME_FILTER);
|
||||
u.setAttribute("filter", this.plugin.settings.themeFilter);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (!hasSVGwithBitmap && svg.getAttribute("hasbitmap")) {
|
||||
hasSVGwithBitmap = true;
|
||||
}
|
||||
@@ -468,6 +523,10 @@ export class EmbeddedFilesLoader {
|
||||
const isHyperLink = inFile instanceof EmbeddedFile ? inFile.isHyperLink : false;
|
||||
const isLocalLink = inFile instanceof EmbeddedFile ? inFile.isLocalLink : false;
|
||||
const hyperlink = inFile instanceof EmbeddedFile ? inFile.hyperlink : "";
|
||||
const normalizedColorMap = inFile instanceof EmbeddedFile ? normalizeColorMap(inFile.colorMap) : null;
|
||||
if (inFile instanceof EmbeddedFile) {
|
||||
inFile.colorMap = normalizedColorMap;
|
||||
}
|
||||
const file: TFile = inFile instanceof EmbeddedFile ? inFile.file : inFile;
|
||||
if(file && markdownRendererRecursionWatcthdog.has(file)) {
|
||||
new Notice(`Loading of ${file.path}. Please check if there is an inifinite loop of one file embedded in the other.`);
|
||||
@@ -492,6 +551,7 @@ export class EmbeddedFilesLoader {
|
||||
let hasSVGwithBitmap = false;
|
||||
const isExcalidrawFile = !isHyperLink && !isLocalLink && this.plugin.isExcalidrawFile(file);
|
||||
const isPDF = !isHyperLink && !isLocalLink && file.extension.toLowerCase() === "pdf";
|
||||
const invertBitmapInDarkMode = getInvertPreference(normalizedColorMap, isPDF || this.plugin.settings.invertBitmapforDarkMode);
|
||||
|
||||
if (
|
||||
!isHyperLink && !isPDF && !isLocalLink &&
|
||||
@@ -548,7 +608,7 @@ export class EmbeddedFilesLoader {
|
||||
)
|
||||
: excalidrawSVG ?? pdfDataURL ??
|
||||
(file?.extension === "svg"
|
||||
? await getSVGData(app, file, inFile instanceof EmbeddedFile ? inFile.colorMap : null)
|
||||
? await getSVGData(app, file, normalizedColorMap)
|
||||
: file?.extension === "md"
|
||||
? null
|
||||
: await getDataURL(ab, mimeType));
|
||||
@@ -560,6 +620,24 @@ export class EmbeddedFilesLoader {
|
||||
dataURL = result.dataURL;
|
||||
hasSVGwithBitmap = result.hasSVGwithBitmap;
|
||||
}
|
||||
|
||||
if (
|
||||
this.isDark &&
|
||||
invertBitmapInDarkMode &&
|
||||
dataURL &&
|
||||
mimeType?.startsWith("image/") &&
|
||||
mimeType !== "image/svg+xml"
|
||||
) {
|
||||
try {
|
||||
dataURL = await applyThemeFilterToBitmapDataURL(
|
||||
dataURL,
|
||||
mimeType,
|
||||
this.plugin.settings.themeFilter,
|
||||
);
|
||||
} catch (error) {
|
||||
errorlog({ where: "EmbeddedFileLoader._getObsidianImage", error });
|
||||
}
|
||||
}
|
||||
try{
|
||||
const size = isPDF ? pdfSize : await getImageSize(dataURL);
|
||||
return {
|
||||
@@ -890,26 +968,6 @@ export class EmbeddedFilesLoader {
|
||||
|
||||
const canvas = await renderPage(pageNum);
|
||||
if(canvas) {
|
||||
// NEW: invert colors for dark theme (keep alpha unchanged)
|
||||
if (this.isDark) {
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (ctx) {
|
||||
try {
|
||||
const img = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
const data = img.data;
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
data[i] = 255 - data[i]; // R
|
||||
data[i + 1] = 255 - data[i+1]; // G
|
||||
data[i + 2] = 255 - data[i+2]; // B
|
||||
// alpha channel (data[i+3]) remains unchanged
|
||||
}
|
||||
ctx.putImageData(img, 0, 0);
|
||||
} catch (e) {
|
||||
// If reading pixel data fails, silently fallback to non-inverted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const result: [DataURL,Size, PDFPageViewProps] = [`data:image/png;base64,${await new Promise((resolve, reject) => {
|
||||
canvas.toBlob(async (blob) => {
|
||||
const dataURL = await blobToBase64(blob);
|
||||
@@ -1153,7 +1211,11 @@ export class EmbeddedFilesLoader {
|
||||
if (imageList.length > 0) {
|
||||
hasSVGwithBitmap = true;
|
||||
}
|
||||
if (hasSVGwithBitmap && this.isDark) {
|
||||
|
||||
if (this.isDark && hasSVGwithBitmap && (
|
||||
(!this.plugin.settings.invertBitmapforDarkMode && this.plugin.settings.invertSVGforDarkMode) ||
|
||||
(this.plugin.settings.invertBitmapforDarkMode && !this.plugin.settings.invertSVGforDarkMode)
|
||||
)) {
|
||||
imageList.forEach(img => {
|
||||
if(img instanceof HTMLImageElement) {
|
||||
img.style.filter = THEME_FILTER;
|
||||
@@ -1161,15 +1223,29 @@ export class EmbeddedFilesLoader {
|
||||
});
|
||||
}
|
||||
|
||||
/*if (hasSVGwithBitmap && this.isDark) {
|
||||
imageList.forEach(img => {
|
||||
if(img instanceof HTMLImageElement) {
|
||||
img.style.filter = THEME_FILTER;
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
const xml = new XMLSerializer().serializeToString(mdDIV);
|
||||
const finalSVG = svg(xml, '<div class="excalidraw-md-footer"></div>', style);
|
||||
plugin.ea.mostRecentMarkdownSVG = parser.parseFromString(
|
||||
finalSVG,
|
||||
"image/svg+xml",
|
||||
).firstElementChild as SVGSVGElement;
|
||||
|
||||
if (this.isDark && this.plugin.settings.invertSVGforDarkMode) {
|
||||
plugin.ea.mostRecentMarkdownSVG.setAttribute("filter", this.plugin.settings.themeFilter);
|
||||
}
|
||||
|
||||
return {
|
||||
dataURL: svgToBase64(finalSVG) as DataURL,
|
||||
hasSVGwithBitmap
|
||||
//dataURL: svgToBase64(finalSVG) as DataURL,
|
||||
dataURL: svgToBase64(plugin.ea.mostRecentMarkdownSVG.outerHTML) as DataURL,
|
||||
hasSVGwithBitmap: hasSVGwithBitmap || !!mdDIV.querySelector(".excalidraw-svg"),
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ import { log } from "../utils/debugHelper";
|
||||
import { ExcalidrawLib } from "../types/excalidrawLib";
|
||||
import { GlobalPoint } from "@zsviczian/excalidraw/types/math/src/types";
|
||||
import { AddImageOptions, ImageInfo, KeyBlocker, ScriptSettingValue, SVGColorInfo } from "src/types/excalidrawAutomateTypes";
|
||||
import { _measureText, cloneElement, createPNG, createSVG, ensureActiveScriptSettingsObject, errorMessage, filterColorMap, getEmbeddedFileForImageElment, getLastActiveExcalidrawView, getLineBox, getTemplate, isColorStringTransparent, isSVGColorInfo, mergeColorMapIntoSVGColorInfo, normalizeBindMode, normalizeFixedPoint, normalizeLinePoints, repositionElementsToCursor, svgColorInfoToColorMap, updateOrAddSVGColorInfo, verifyMinimumPluginVersion } from "src/utils/excalidrawAutomateUtils";
|
||||
import { _measureText, cloneElement, createPNG, createSVG, ensureActiveScriptSettingsObject, errorMessage, filterColorMap, getEmbeddedFileForImageElment, getLastActiveExcalidrawView, getLineBox, getTemplate, isColorStringTransparent, isSVGColorInfo, mergeColorMapIntoSVGColorInfo, normalizeBindMode, normalizeColorMap, normalizeFixedPoint, normalizeLinePoints, repositionElementsToCursor, svgColorInfoToColorMap, updateOrAddSVGColorInfo, verifyMinimumPluginVersion } from "src/utils/excalidrawAutomateUtils";
|
||||
import { exportToPDF, getMarginValue, getPageDimensions } from "src/utils/exportUtils";
|
||||
import { PageDimensions, PageOrientation, PageSize, PDFExportScale, PDFPageProperties, ExportSettings} from "src/types/exportUtilTypes";
|
||||
import { FrameRenderingOptions } from "src/types/utilTypes";
|
||||
@@ -708,6 +708,9 @@ export class ExcalidrawAutomate {
|
||||
*/
|
||||
public getAPI(view?:ExcalidrawView):ExcalidrawAutomate {
|
||||
const ea = new ExcalidrawAutomate(this.plugin, view);
|
||||
if(view && view.excalidrawAPI) {
|
||||
ea.setTheme(view.excalidrawAPI.getAppState().theme);
|
||||
}
|
||||
this.plugin.eaInstances.push(ea);
|
||||
return ea;
|
||||
}
|
||||
@@ -2176,7 +2179,7 @@ export class ExcalidrawAutomate {
|
||||
anchor: boolean = true, //only has effect if scale is false. If anchor is true the image path will include |100%, if false the image will be inserted at 100%, but if resized by the user it won't pop back to 100% the next time Excalidraw is opened.
|
||||
): Promise<string> {
|
||||
|
||||
let colorMap: ColorMap;
|
||||
let colorMap: ColorMap | null = null;
|
||||
let topX: number;
|
||||
if(typeof topXOrOpts === "number") {
|
||||
topX = topXOrOpts;
|
||||
@@ -2186,7 +2189,7 @@ export class ExcalidrawAutomate {
|
||||
imageFile = topXOrOpts.imageFile;
|
||||
scale = topXOrOpts.scale ?? true;
|
||||
anchor = topXOrOpts.anchor ?? true;
|
||||
colorMap = topXOrOpts.colorMap;
|
||||
colorMap = normalizeColorMap(topXOrOpts.colorMap);
|
||||
}
|
||||
|
||||
const pdfLinkRegex = /^[^#]*#page=\d*(&\w*=[^&]+){0,}&rect=\d*,\d*,\d*,\d*/;
|
||||
@@ -2228,7 +2231,7 @@ export class ExcalidrawAutomate {
|
||||
height: image.size.height,
|
||||
width: image.size.width,
|
||||
},
|
||||
colorMap,
|
||||
colorMap: colorMap ?? undefined,
|
||||
pdfPageViewProps: image.pdfPageViewProps,
|
||||
};
|
||||
if (scale && (Math.max(image.size.width, image.size.height) > MAX_IMAGE_SIZE)) {
|
||||
@@ -2600,6 +2603,9 @@ export class ExcalidrawAutomate {
|
||||
this.targetView.leaf,
|
||||
);
|
||||
}
|
||||
if (this.targetView && this.targetView.excalidrawAPI) {
|
||||
this.setTheme(this.targetView.excalidrawAPI.getAppState().theme);
|
||||
}
|
||||
return this.targetView;
|
||||
};
|
||||
|
||||
@@ -2708,10 +2714,11 @@ export class ExcalidrawAutomate {
|
||||
*/
|
||||
getColorMapForImageElement(el: ExcalidrawElement): ColorMap {
|
||||
const cm = getEmbeddedFileForImageElment(this,el)?.colorMap
|
||||
if(!cm) {
|
||||
const normalized = normalizeColorMap(cm);
|
||||
if(!normalized) {
|
||||
return {};
|
||||
}
|
||||
return cm;
|
||||
return normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2749,7 +2756,9 @@ export class ExcalidrawAutomate {
|
||||
errorMessage("Must provide an image element and a colorMap as input", "updateViewSVGImageColorMap()");
|
||||
continue;
|
||||
}
|
||||
if (!colorMap || typeof colorMap !== 'object' || Object.keys(colorMap).length === 0) {
|
||||
const hasColorEntries = Object.keys(colorMap).some(key => key.toLocaleLowerCase() !== "invertindarkmode");
|
||||
const hasInvertPreference = typeof (colorMap as Record<string, unknown>).invertInDarkMode === "boolean";
|
||||
if (!colorMap || typeof colorMap !== 'object' || (!hasColorEntries && !hasInvertPreference)) {
|
||||
ef.colorMap = null;
|
||||
} else {
|
||||
ef.colorMap = colorMap;
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
arrayToMap,
|
||||
compressAsync,
|
||||
} from "../utils/utils";
|
||||
import { ColorMap } from "../types/embeddedFileLoaderTypes";
|
||||
import { cleanBlockRef, cleanSectionHeading, getAttachmentsFolderAndFilePath, isObsidianThemeDark } from "../utils/obsidianUtils";
|
||||
import {
|
||||
ExcalidrawElement,
|
||||
@@ -146,6 +147,31 @@ export const REGEX_LINK = {
|
||||
},
|
||||
};
|
||||
|
||||
const COLOR_MAP_INVERT_KEY = "invertindarkmode";
|
||||
const isReservedColorMapKey = (key: string) => key.toLocaleLowerCase() === COLOR_MAP_INVERT_KEY;
|
||||
const normalizeColorMapLocal = (colorMap?: ColorMap | null): ColorMap | null => {
|
||||
if (!colorMap || typeof colorMap !== "object") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const normalized: ColorMap = {};
|
||||
const invert = (colorMap as Record<string, unknown>).invertInDarkMode ?? (colorMap as Record<string, unknown>)[COLOR_MAP_INVERT_KEY];
|
||||
if (typeof invert === "boolean") {
|
||||
normalized.invertInDarkMode = invert;
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(colorMap)) {
|
||||
if (isReservedColorMapKey(key) || typeof value !== "string") {
|
||||
continue;
|
||||
}
|
||||
const normalizedKey = key.toLocaleLowerCase();
|
||||
const normalizedValue = value.toLocaleLowerCase();
|
||||
normalized[normalizedKey] = normalizedValue;
|
||||
}
|
||||
|
||||
return normalized;
|
||||
};
|
||||
|
||||
//added \n at and of DRAWING_REG: https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/357
|
||||
const DRAWING_REG = /\n##? Drawing\n[^`]*(```json\n)([\s\S]*?)```\n/gm; //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/182
|
||||
const DRAWING_REG_FALLBACK = /\n##? Drawing\n(```json\n)?(.*)(```)?(%%)?/gm;
|
||||
@@ -1497,7 +1523,8 @@ export class ExcalidrawData {
|
||||
const path = ef.file
|
||||
? ef.linkParts.original.replace(PATHREG,this.app.metadataCache.fileToLinktext(ef.file,this.file.path))
|
||||
: ef.linkParts.original;
|
||||
const colorMap = ef.colorMap ? " " + JSON.stringify(ef.colorMap) : "";
|
||||
const normalizedColorMap = normalizeColorMapLocal(ef.colorMap);
|
||||
const colorMap = normalizedColorMap ? " " + JSON.stringify(normalizedColorMap) : "";
|
||||
outString += `${key}: [[${path}]]${colorMap}\n\n`;
|
||||
}
|
||||
}
|
||||
@@ -2014,6 +2041,7 @@ export class ExcalidrawData {
|
||||
}
|
||||
|
||||
const parts = data.linkParts.original.split("#");
|
||||
const normalizedColorMap = normalizeColorMapLocal(data.colorMap);
|
||||
this.plugin.filesMaster.set(fileId, {
|
||||
isHyperLink: false,
|
||||
isLocalLink: false,
|
||||
@@ -2022,7 +2050,7 @@ export class ExcalidrawData {
|
||||
? null
|
||||
: parts[1],
|
||||
hasSVGwithBitmap: data.isSVGwithBitmap,
|
||||
colorMapJSON: data.colorMap ? JSON.stringify(data.colorMap) : null,
|
||||
colorMapJSON: normalizedColorMap ? JSON.stringify(normalizedColorMap) : null,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -48,5 +48,6 @@ export type Size = {
|
||||
};
|
||||
|
||||
export interface ColorMap {
|
||||
[color: string]: string;
|
||||
invertInDarkMode?: boolean;
|
||||
[color: string]: string | boolean | undefined;
|
||||
};
|
||||
@@ -67,4 +67,5 @@ export interface ViewSemaphores {
|
||||
saving: boolean;
|
||||
hoverSleep: boolean; //flag with timer to prevent hover preview from being triggered dozens of times
|
||||
wheelTimeout:number; //used to avoid hover preview while zooming
|
||||
shouldSaveImportedImage: boolean; //forceSave after image import via the Excalidraw Image Tool or by way of paste
|
||||
}
|
||||
@@ -59,15 +59,48 @@ export function isSVGColorInfo(obj: ColorMap | SVGColorInfo): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
const COLOR_MAP_INVERT_KEY = "invertindarkmode";
|
||||
const isReservedColorMapKey = (key: string) => key.toLocaleLowerCase() === COLOR_MAP_INVERT_KEY;
|
||||
|
||||
//Normalize color maps and lift the invertInDarkMode flag out of color entries
|
||||
export function normalizeColorMap(colorMap?: ColorMap | null): ColorMap | null {
|
||||
if (!colorMap || typeof colorMap !== "object") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const normalized: ColorMap = {};
|
||||
const invert = (colorMap as Record<string, unknown>).invertInDarkMode ?? (colorMap as Record<string, unknown>)[COLOR_MAP_INVERT_KEY];
|
||||
if (typeof invert === "boolean") {
|
||||
normalized.invertInDarkMode = invert;
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(colorMap)) {
|
||||
if (isReservedColorMapKey(key) || typeof value !== "string") {
|
||||
continue;
|
||||
}
|
||||
const normalizedKey = key.toLocaleLowerCase();
|
||||
const normalizedValue = value.toLocaleLowerCase();
|
||||
normalized[normalizedKey] = normalizedValue;
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function mergeColorMapIntoSVGColorInfo(
|
||||
colorMap: ColorMap,
|
||||
svgColorInfo: SVGColorInfo
|
||||
): SVGColorInfo {
|
||||
if(colorMap) {
|
||||
for(const key of Object.keys(colorMap)) {
|
||||
if(svgColorInfo.has(key)) {
|
||||
svgColorInfo.get(key).mappedTo = colorMap[key];
|
||||
const normalized = normalizeColorMap(colorMap);
|
||||
if(normalized) {
|
||||
for(const key of Object.keys(normalized)) {
|
||||
if(isReservedColorMapKey(key)) {
|
||||
continue;
|
||||
}
|
||||
const mappedTo = normalized[key];
|
||||
if(!svgColorInfo.has(key) || typeof mappedTo !== "string") {
|
||||
continue;
|
||||
}
|
||||
svgColorInfo.get(key).mappedTo = mappedTo;
|
||||
}
|
||||
}
|
||||
return svgColorInfo;
|
||||
@@ -84,9 +117,23 @@ export function svgColorInfoToColorMap(svgColorInfo: SVGColorInfo): ColorMap {
|
||||
|
||||
//Remove identical key-value pairs from a ColorMap
|
||||
export function filterColorMap(colorMap: ColorMap): ColorMap {
|
||||
return Object.fromEntries(
|
||||
Object.entries(colorMap).filter(([key, value]) => key.toLocaleLowerCase() !== value?.toLocaleLowerCase())
|
||||
);
|
||||
const normalized = normalizeColorMap(colorMap) ?? {};
|
||||
const filtered: ColorMap = {};
|
||||
|
||||
if (typeof normalized.invertInDarkMode === "boolean") {
|
||||
filtered.invertInDarkMode = normalized.invertInDarkMode;
|
||||
}
|
||||
|
||||
Object.entries(normalized).forEach(([key, value]) => {
|
||||
if (isReservedColorMapKey(key) || typeof value !== "string") {
|
||||
return;
|
||||
}
|
||||
if (key.toLocaleLowerCase() !== value.toLocaleLowerCase()) {
|
||||
filtered[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
export function updateOrAddSVGColorInfo(
|
||||
|
||||
+33
-13
@@ -117,7 +117,7 @@ import {
|
||||
import { cleanBlockRef, cleanSectionHeading, closeLeafView, getAttachmentsFolderAndFilePath, getExcalidraAndMarkdowViewsForFile, getLeaf, getParentOfClass, obsidianPDFQuoteWithRef, openLeaf, setExcalidrawView } from "../utils/obsidianUtils";
|
||||
import { splitFolderAndFilename } from "../utils/fileUtils";
|
||||
import { GenericInputPrompt, LaTexPrompt, MultiOptionConfirmationPrompt, NewFileActions, Prompt, linkPrompt } from "../shared/Dialogs/Prompt";
|
||||
import { ClipboardData } from "@zsviczian/excalidraw/types/excalidraw/clipboard";
|
||||
import { ClipboardData, ParsedDataTransferFile } from "@zsviczian/excalidraw/types/excalidraw/clipboard";
|
||||
import { updateEquation } from "../shared/LaTeX";
|
||||
import {
|
||||
EmbeddedFile,
|
||||
@@ -328,6 +328,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
forceSaving: false,
|
||||
hoverSleep: false,
|
||||
wheelTimeout: null,
|
||||
shouldSaveImportedImage: false,
|
||||
};
|
||||
|
||||
public _plugin: ExcalidrawPlugin;
|
||||
@@ -2204,6 +2205,10 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
this.semaphores.viewunload = true;
|
||||
this.semaphores.popoutUnload = (this.ownerDocument !== document) && (this.ownerDocument.body.querySelectorAll(".workspace-tab-header").length === 0);
|
||||
|
||||
if(this.shouldSaveImportedImageTimer) {
|
||||
window.clearTimeout(this.shouldSaveImportedImageTimer);
|
||||
}
|
||||
|
||||
if(this.getHookServer().onViewUnloadHook) {
|
||||
try {
|
||||
this.getHookServer().onViewUnloadHook(this);
|
||||
@@ -2638,7 +2643,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
if(imageCache.isReady() && this.excalidrawData.scene && this.excalidrawData.scene.elements && this.excalidrawData.scene.elements.length === 0) {
|
||||
const backup = await imageCache.getBAKFromCache(this.file.path);
|
||||
if(backup && backup.length > data.length) {
|
||||
setTimeout(async () => {
|
||||
window.setTimeout(async () => {
|
||||
const confirmationPrompt = new MultiOptionConfirmationPrompt(
|
||||
this.plugin,
|
||||
t("BACKUP_SAVE_AS_FILE"),
|
||||
@@ -4232,21 +4237,22 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
}
|
||||
}
|
||||
|
||||
private shouldSaveImportedImage: boolean = false;
|
||||
private onChange (et: ExcalidrawElement[], st: AppState) {
|
||||
private onChange (et: ExcalidrawElement[], st: AppState, files: BinaryFileData[]) {
|
||||
if(st.activeTool?.type) {
|
||||
if(st.activeTool.type === "image") {
|
||||
if(st.selectedElementIds && Object.keys(st.selectedElementIds).length === 1) {
|
||||
const selectedElement = et.filter(el=>el.id === Object.keys(st.selectedElementIds)[0])[0];
|
||||
if(selectedElement && selectedElement.type === "image") {
|
||||
this.shouldSaveImportedImage = true;
|
||||
this.setShouldSaveImportedImageFlag();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(st.activeTool.type === "selection" && this.shouldSaveImportedImage) {
|
||||
this.shouldSaveImportedImage = false;
|
||||
setTimeout(()=>this.save(true, true),100); //image is being added to the scene
|
||||
}
|
||||
}
|
||||
if(
|
||||
this.semaphores.shouldSaveImportedImage &&
|
||||
Object.values(files).some(file=> !file.hasOwnProperty("hasSVGwithBitmap"))
|
||||
) {
|
||||
window.setTimeout(()=>this.forceSave(true)); //image is being added to the scene
|
||||
}
|
||||
|
||||
if(st.newElement?.type === "freedraw") {
|
||||
@@ -4320,10 +4326,24 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
})();
|
||||
}
|
||||
|
||||
private onPaste (data: ClipboardData, event: ClipboardEvent | null) {
|
||||
private shouldSaveImportedImageTimer: number = null;
|
||||
private setShouldSaveImportedImageFlag() {
|
||||
this.semaphores.shouldSaveImportedImage = true;
|
||||
if(this.shouldSaveImportedImageTimer) {
|
||||
window.clearTimeout(this.shouldSaveImportedImageTimer);
|
||||
}
|
||||
this.shouldSaveImportedImageTimer = window.setTimeout(()=>this.semaphores.shouldSaveImportedImage = false, 3000);
|
||||
}
|
||||
|
||||
private onPaste (data: ClipboardData, event: ClipboardEvent | null, files: ParsedDataTransferFile[]) {
|
||||
(process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.onPaste, "ExcalidrawView.onPaste", data, event);
|
||||
const api = this.excalidrawAPI as ExcalidrawImperativeAPI;
|
||||
const ea = this.getHookServer();
|
||||
|
||||
if (files?.length || (data?.mixedContent && data.mixedContent.some(d=>d.type==="imageUrl"))) {
|
||||
this.setShouldSaveImportedImageFlag();
|
||||
}
|
||||
|
||||
if(data?.elements) {
|
||||
data.elements
|
||||
.filter(el=>el.type==="text" && !el.hasOwnProperty("rawText"))
|
||||
@@ -5218,9 +5238,9 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
() => {
|
||||
const markerEnabled = !(frameRendering.markerEnabled && frameRendering.enabled && frameRendering.outline);
|
||||
if(markerEnabled) {
|
||||
setTimeout(() => this.updateScene({appState: {frameRendering: {...frameRendering, enabled: true, outline: true, markerEnabled}}, captureUpdate: CaptureUpdateAction.NEVER}));
|
||||
window.setTimeout(() => this.updateScene({appState: {frameRendering: {...frameRendering, enabled: true, outline: true, markerEnabled}}, captureUpdate: CaptureUpdateAction.NEVER}));
|
||||
} else {
|
||||
setTimeout(() => this.updateScene({appState: {frameRendering: {...frameRendering, markerEnabled}}, captureUpdate: CaptureUpdateAction.NEVER}));
|
||||
window.setTimeout(() => this.updateScene({appState: {frameRendering: {...frameRendering, markerEnabled}}, captureUpdate: CaptureUpdateAction.NEVER}));
|
||||
}
|
||||
},
|
||||
onClose
|
||||
@@ -5234,7 +5254,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
? t("MARKER_FRAME_TITLE_HIDE")
|
||||
: t("MARKER_FRAME_TITLE_SHOW"),
|
||||
() => {
|
||||
setTimeout(() => this.updateScene({appState: {frameRendering: {...frameRendering, markerName: !frameRendering.markerName}}, captureUpdate: CaptureUpdateAction.NEVER}));
|
||||
window.setTimeout(() => this.updateScene({appState: {frameRendering: {...frameRendering, markerName: !frameRendering.markerName}}, captureUpdate: CaptureUpdateAction.NEVER}));
|
||||
},
|
||||
onClose
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user