Merge branch 'master' into mtolmacs/feat/freedraw-research-1

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs
2026-06-04 16:34:58 +00:00
10 changed files with 56 additions and 45 deletions
+5 -1
View File
@@ -80,7 +80,11 @@ const cssInvert = (
return { r: invertedR, g: invertedG, b: invertedB };
};
export const applyDarkModeFilter = (color: string): string => {
export const applyDarkModeFilter = (color: string, enable = true): string => {
if (!enable) {
return color;
}
const cached = DARK_MODE_COLORS_CACHE?.get(color);
if (cached) {
return cached;
+8 -8
View File
@@ -554,10 +554,10 @@ const drawElementOnCanvas = (
context.canvas.setAttribute("dir", rtl ? "rtl" : "ltr");
context.save();
context.font = getFontString(element);
context.fillStyle =
renderConfig.theme === THEME.DARK
? applyDarkModeFilter(element.strokeColor)
: element.strokeColor;
context.fillStyle = applyDarkModeFilter(
element.strokeColor,
renderConfig.theme === THEME.DARK,
);
context.textAlign = element.textAlign as CanvasTextAlign;
// Canvas does not support multiline text by default
@@ -851,10 +851,10 @@ export const renderElement = (
context.fillStyle = "rgba(0, 0, 200, 0.04)";
context.lineWidth = FRAME_STYLE.strokeWidth / appState.zoom.value;
context.strokeStyle =
appState.theme === THEME.DARK
? applyDarkModeFilter(FRAME_STYLE.strokeColor)
: FRAME_STYLE.strokeColor;
context.strokeStyle = applyDarkModeFilter(
FRAME_STYLE.strokeColor,
appState.theme === THEME.DARK,
);
// TODO change later to only affect AI frames
if (isMagicFrameElement(element)) {
+4 -1
View File
@@ -163,7 +163,10 @@ export const drawFreeDrawSegments = (
? applyDarkModeFilter(element.strokeColor)
: element.strokeColor;
context.fillStyle = strokeColor;
context.fillStyle = applyDarkModeFilter(
strokeColor,
renderConfig.theme === THEME.DARK,
);
const baseRadius = (element.strokeWidth * 1.25) / 2;
+8 -15
View File
@@ -218,9 +218,7 @@ export const generateRoughOptions = (
fillWeight: element.strokeWidth / 2,
hachureGap: element.strokeWidth * 4,
roughness: adjustRoughness(element),
stroke: isDarkMode
? applyDarkModeFilter(element.strokeColor)
: element.strokeColor,
stroke: applyDarkModeFilter(element.strokeColor, isDarkMode),
preserveVertices:
continuousPath || element.roughness < ROUGHNESS.cartoonist,
};
@@ -234,9 +232,7 @@ export const generateRoughOptions = (
options.fillStyle = element.fillStyle;
options.fill = isTransparent(element.backgroundColor)
? undefined
: isDarkMode
? applyDarkModeFilter(element.backgroundColor)
: element.backgroundColor;
: applyDarkModeFilter(element.backgroundColor, isDarkMode);
if (element.type === "ellipse") {
options.curveFitting = 1;
}
@@ -249,9 +245,7 @@ export const generateRoughOptions = (
options.fill =
element.backgroundColor === "transparent"
? undefined
: isDarkMode
? applyDarkModeFilter(element.backgroundColor)
: element.backgroundColor;
: applyDarkModeFilter(element.backgroundColor, isDarkMode);
}
return options;
}
@@ -386,12 +380,11 @@ const getArrowheadShapes = (
return [];
}
const strokeColor = isDarkMode
? applyDarkModeFilter(element.strokeColor)
: element.strokeColor;
const backgroundFillColor = isDarkMode
? applyDarkModeFilter(canvasBackgroundColor)
: canvasBackgroundColor;
const strokeColor = applyDarkModeFilter(element.strokeColor, isDarkMode);
const backgroundFillColor = applyDarkModeFilter(
canvasBackgroundColor,
isDarkMode,
);
const cardinalityOneOrManyOffset = -0.25;
const cardinalityZeroCircleScale = 0.8;
+4 -3
View File
@@ -1995,9 +1995,10 @@ class App extends React.Component<AppProps, AppState> {
}
}}
style={{
background: isDarkTheme
? applyDarkModeFilter(this.state.viewBackgroundColor)
: this.state.viewBackgroundColor,
background: applyDarkModeFilter(
this.state.viewBackgroundColor,
isDarkTheme,
),
zIndex: 2,
border: "none",
display: "block",
+3
View File
@@ -7,6 +7,7 @@ import React, {
} from "react";
import {
applyDarkModeFilter,
DEFAULT_IMAGE_OPTIONS,
DEFAULT_UI_OPTIONS,
isShallowEqual,
@@ -450,3 +451,5 @@ export function useExcalidrawStateValue(
// -----------------------------------------------------------------------------
export { _useOnAppStateChange as useOnExcalidrawStateChange };
export { applyDarkModeFilter };
+4 -4
View File
@@ -62,10 +62,10 @@ export const bootstrapCanvas = ({
context.clearRect(0, 0, normalizedWidth, normalizedHeight);
}
context.save();
context.fillStyle =
theme === THEME.DARK
? applyDarkModeFilter(viewBackgroundColor)
: viewBackgroundColor;
context.fillStyle = applyDarkModeFilter(
viewBackgroundColor,
theme === THEME.DARK,
);
context.fillRect(0, 0, normalizedWidth, normalizedHeight);
context.restore();
} else {
+15 -6
View File
@@ -392,6 +392,13 @@ const renderElementToSvg = (
if (typeof shape === "string") {
// stroke (SVGPathString) — fill inherited from wrapper <g>
const path = svgRoot.ownerDocument.createElementNS(SVG_NS, "path");
path.setAttribute(
"fill",
applyDarkModeFilter(
element.strokeColor,
renderConfig.theme === THEME.DARK,
),
);
path.setAttribute("d", shape);
wrapper.appendChild(path);
} else {
@@ -623,9 +630,10 @@ const renderElementToSvg = (
rect.setAttribute("fill", "none");
rect.setAttribute(
"stroke",
renderConfig.theme === THEME.DARK
? applyDarkModeFilter(FRAME_STYLE.strokeColor)
: FRAME_STYLE.strokeColor,
applyDarkModeFilter(
FRAME_STYLE.strokeColor,
renderConfig.theme === THEME.DARK,
),
);
rect.setAttribute("stroke-width", FRAME_STYLE.strokeWidth.toString());
@@ -679,9 +687,10 @@ const renderElementToSvg = (
text.setAttribute("font-size", `${element.fontSize}px`);
text.setAttribute(
"fill",
renderConfig.theme === THEME.DARK
? applyDarkModeFilter(element.strokeColor)
: element.strokeColor,
applyDarkModeFilter(
element.strokeColor,
renderConfig.theme === THEME.DARK,
),
);
text.setAttribute("text-anchor", textAnchor);
text.setAttribute("style", "white-space: pre;");
+1 -3
View File
@@ -459,9 +459,7 @@ export const exportToSvg = async (
rect.setAttribute("height", `${height}`);
rect.setAttribute(
"fill",
exportWithDarkMode
? applyDarkModeFilter(viewBackgroundColor)
: viewBackgroundColor,
applyDarkModeFilter(viewBackgroundColor, exportWithDarkMode),
);
svgRoot.appendChild(rect);
}
+4 -4
View File
@@ -392,10 +392,10 @@ export const textWysiwyg = ({
),
textAlign,
verticalAlign,
color:
appState.theme === THEME.DARK
? applyDarkModeFilter(updatedTextElement.strokeColor)
: updatedTextElement.strokeColor,
color: applyDarkModeFilter(
updatedTextElement.strokeColor,
appState.theme === THEME.DARK,
),
opacity: updatedTextElement.opacity / 100,
maxHeight: `${editorMaxHeight}px`,
});