2.18.0-beta-4, 0.18.0-58

This commit is contained in:
zsviczian committed 2025-11-29 14:42:21 +01:00
1 parent 686f462716
commit ba5d1aa6d6
6 files changed
+59 -9

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"id": "obsidian-excalidraw-plugin",
"name": "Excalidraw",
"version": "2.18.0-beta-3",
"version": "2.18.0-beta-4",
"minAppVersion": "1.5.7",
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
"author": "Zsolt Viczian",
+1 -1
View File
@@ -24,7 +24,7 @@
"license": "MIT",
"dependencies": {
"@popperjs/core": "^2.11.8",
"@zsviczian/excalidraw": "0.18.0-56",
"@zsviczian/excalidraw": "0.18.0-58",
"chroma-js": "^3.1.2",
"clsx": "^2.0.0",
"@zsviczian/colormaster": "^1.2.2",
+6
View File
@@ -90,6 +90,8 @@ import { CommandManager } from "./managers/CommandManager";
import { EventManager } from "./managers/EventManager";
import { UniversalInsertFileModal } from "src/shared/Dialogs/UniversalInsertFileModal";
import en from "src/lang/locale/en";
import { get } from "http";
import { getHighlightColor } from "src/utils/dynamicStyling";
declare const PLUGIN_VERSION:string;
declare const INITIAL_TIMESTAMP: number;
@@ -1486,4 +1488,8 @@ export default class ExcalidrawPlugin extends Plugin {
public getObsidianDevice(): DeviceType {
return DEVICE;
}
public getHighlightColor(color: string, sceneBgColor: string, opacity: number = 1): string {
return getHighlightColor(this.ea, color, sceneBgColor, opacity);
}
}
+1 -2
View File
@@ -509,8 +509,7 @@ export default {
"<b><u>Toggle ON:</u></b>Change grid color to match the canvas color<br><b><u>Toggle OFF:</u></b>Use the color below as the grid color",
GRID_COLOR_NAME: "Grid color",
GRID_OPACITY_NAME: "Grid opacity",
GRID_OPACITY_DESC: "Grid opacity will also control the opacity of the binding box when binding an arrow to an element.<br>" +
"Set the opacity of the grid. 0 is transparent, 100 is opaque.",
GRID_OPACITY_DESC: "Sets the opacity of the grid. 0 is transparent, 100 is opaque.",
GRID_DIRECTION_NAME: "Grid direction",
GRID_DIRECTION_DESC: "The first toggle shows/hides the horizontal grid, the second toggle shows/hides the vertical grid.",
GRID_HORIZONTAL: "Render horizontal grid",
+42 -2
View File
@@ -1,5 +1,5 @@
import { ExcalidrawImperativeAPI } from "@zsviczian/excalidraw/types/excalidraw/types";
import { ColorMaster } from "@zsviczian/colormaster";
import CM, { ColorMaster } from "@zsviczian/colormaster";
import { ExcalidrawAutomate } from "src/shared/ExcalidrawAutomate";
import ExcalidrawView from "src/view/ExcalidrawView";
import { DynamicStyle } from "src/types/types";
@@ -190,4 +190,44 @@ export const setDynamicStyle = (
color = null;
dynamicStyle = null;
});
}
}
const colorsCache: Map<string,ColorMaster> = new Map();
export function getHighlightColor(
ea: ExcalidrawAutomate,
strokeColor: string,
sceneBgColor: string,
opacity:number = 1
): string {
strokeColor = strokeColor === "transparent"
? (sceneBgColor==="transparent" ? "#ffffff": sceneBgColor)
: strokeColor;
let contrasted = colorsCache.get(strokeColor);
if(!contrasted) {
const bg = ea.getCM(strokeColor);
const bgMix = ea.getCM(strokeColor);
const isDark = bg.isDark();
const step = 15;
const candidates = [
CM((isDark ? bg.lighterBy(step) : bg.darkerBy(step)).stringHEX()),
CM((isDark ? bg.lighterBy(step) : bg.darkerBy(step)).stringHEX()),
isDark ? bg.lighterBy(step) : bg.darkerBy(step),
// Vibrancy boost by mixing toward the opposite theme color
bgMix.mix({color: ea.getCM(isDark ? "#ffffff" : "#000000"), ratio:0.35}),
ea.getCM(isDark ? "#ffffff" : "#000000"),
ea.getCM(isDark ? "#000000" : "#ffffff"),
];
const desiredContrast = 2.5;
contrasted = candidates.find(color =>
color.contrast({bgColor: strokeColor, ratio:false}) as number >= desiredContrast) ??
candidates.reduce((best, color) => (color.contrast({bgColor: strokeColor, ratio: false}) > best.contrast({bgColor: strokeColor, ratio:false}) ? color : best)
);
colorsCache.set(strokeColor, contrasted);
}
contrasted.alphaTo(opacity);
return contrasted.stringRGB({alpha:true});
}
+8 -3
View File
@@ -2586,7 +2586,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
const opacity = this.plugin.settings.gridSettings.OPACITY/100;
if (this.plugin.settings.gridSettings.DYNAMIC_COLOR) {
// Dynamic color: concatenate opacity to the HEX string
// Dynamic color: concatenate opacity to the RGB string !!! Excalidraw expects an RGBA string !!!
Regular = (isDark ? cm.lighterBy(10) : cm.darkerBy(10)).alphaTo(opacity).stringRGB({ alpha: true });
Bold = (isDark ? cm.lighterBy(5) : cm.darkerBy(5)).alphaTo(opacity).stringRGB({ alpha: true });
} else {
@@ -2597,7 +2597,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
// Regular uses the custom color directly
Regular = customCM.alphaTo(opacity).stringRGB({ alpha: true });
// Bold is 7 shades lighter or darker based on the custom color's darkness
// Bold is 10 shades lighter or darker based on the custom color's darkness
Bold = (customIsDark ? customCM.lighterBy(10) : customCM.darkerBy(10)).alphaTo(opacity).stringRGB({ alpha: true });
}
@@ -4049,7 +4049,12 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
st = (this.excalidrawAPI as ExcalidrawImperativeAPI).getAppState();
canvasColor = canvasColor ?? st.viewBackgroundColor === "transparent" ? "white" : st.viewBackgroundColor;
}
window.setTimeout(()=>this.updateScene({appState:{gridColor: this.getGridColor(canvasColor, st)}, captureUpdate: CaptureUpdateAction.NEVER}));
window.setTimeout(()=>this.updateScene(
{
appState:{
gridColor: this.getGridColor(canvasColor, st),
},
captureUpdate: CaptureUpdateAction.NEVER}));
}
public updateGridDirection(gridDirection: {horizontal: boolean, vertical: boolean}) {