Skip to content

Commit fa15240

Browse files
committed
wip2
1 parent f38961d commit fa15240

File tree

13 files changed

+508
-421
lines changed

13 files changed

+508
-421
lines changed

excalidraw-app/App.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ const ExcalidrawWrapper = () => {
391391

392392
const editorInterface = useEditorInterface();
393393

394+
useEffect(() => {
395+
document.documentElement.classList.remove("dark");
396+
}, []);
397+
394398
// initial state
395399
// ---------------------------------------------------------------------------
396400

packages/common/src/colors.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
applyDarkModeFilter,
3+
COLOR_CHARCOAL_BLACK,
34
COLOR_PALETTE,
45
rgbToHex,
56
} from "@excalidraw/common";
@@ -95,7 +96,7 @@ describe("applyDarkModeFilter", () => {
9596
describe("COLOR_PALETTE regression tests", () => {
9697
it("transforms black from palette", () => {
9798
// COLOR_PALETTE.black is #1e1e1e (not pure black)
98-
const result = applyDarkModeFilter(COLOR_PALETTE.black);
99+
const result = applyDarkModeFilter(COLOR_CHARCOAL_BLACK);
99100
expect(result).toBe("#d3d3d3");
100101
});
101102

@@ -169,7 +170,7 @@ describe("applyDarkModeFilter", () => {
169170
it("matches snapshot for all palette colors", () => {
170171
const transformedPalette: Record<string, string | string[]> = {};
171172

172-
transformedPalette.black = applyDarkModeFilter(COLOR_PALETTE.black);
173+
transformedPalette.black = applyDarkModeFilter(COLOR_CHARCOAL_BLACK);
173174
transformedPalette.white = applyDarkModeFilter(COLOR_PALETTE.white);
174175
transformedPalette.transparent = applyDarkModeFilter(
175176
COLOR_PALETTE.transparent,

packages/element/src/renderElement.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ const generateElementCanvas = (
321321
return {
322322
element,
323323
canvas,
324-
theme: appState.theme,
324+
theme: renderConfig.theme,
325325
scale,
326326
zoomValue: zoom.value,
327327
canvasOffsetX,
@@ -538,7 +538,6 @@ export let elementWithCanvasCache = new WeakMap<
538538

539539
export const clearRenderCache = () => {
540540
elementWithCanvasCache = new WeakMap();
541-
pathsCache = new WeakMap();
542541
};
543542

544543
const generateElementWithCanvas = (
@@ -567,7 +566,7 @@ const generateElementWithCanvas = (
567566
if (
568567
!prevElementWithCanvas ||
569568
shouldRegenerateBecauseZoom ||
570-
prevElementWithCanvas.theme !== appState.theme ||
569+
prevElementWithCanvas.theme !== renderConfig.theme ||
571570
prevElementWithCanvas.boundTextElementVersion !== boundTextElementVersion ||
572571
prevElementWithCanvas.imageCrop !== imageCrop ||
573572
prevElementWithCanvas.containingFrameOpacity !== containingFrameOpacity ||
@@ -748,14 +747,14 @@ export const renderElement = (
748747

749748
context.lineWidth = FRAME_STYLE.strokeWidth / appState.zoom.value;
750749
context.strokeStyle =
751-
appState.theme === THEME.DARK
750+
renderConfig.theme === THEME.DARK
752751
? applyDarkModeFilter(FRAME_STYLE.strokeColor)
753752
: FRAME_STYLE.strokeColor;
754753

755754
// TODO change later to only affect AI frames
756755
if (isMagicFrameElement(element)) {
757756
context.strokeStyle =
758-
appState.theme === THEME.LIGHT
757+
renderConfig.theme === THEME.LIGHT
759758
? "#7affd7"
760759
: applyDarkModeFilter("#1d8264");
761760
}

packages/element/src/shape.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ import type { GlobalPoint } from "@excalidraw/math";
3232

3333
import type { Mutable } from "@excalidraw/common/utility-types";
3434

35-
import type { EmbedsValidationStatus } from "@excalidraw/excalidraw/types";
35+
import type {
36+
AppState,
37+
EmbedsValidationStatus,
38+
} from "@excalidraw/excalidraw/types";
3639
import type {
3740
ElementShape,
3841
ElementShapes,
3942
SVGPathString,
40-
StaticCanvasRenderConfig,
4143
} from "@excalidraw/excalidraw/scene/types";
4244

4345
import { elementWithCanvasCache } from "./renderElement";
@@ -119,7 +121,7 @@ export class ShapeCache {
119121
element: T,
120122
renderConfig: {
121123
isExporting: boolean;
122-
canvasBackgroundColor: StaticCanvasRenderConfig["canvasBackgroundColor"];
124+
canvasBackgroundColor: AppState["viewBackgroundColor"];
123125
embedsValidationStatus: EmbedsValidationStatus;
124126
theme: AppState["theme"];
125127
} | null,
@@ -637,7 +639,7 @@ const _generateElementShape = (
637639
theme,
638640
}: {
639641
isExporting: boolean;
640-
canvasBackgroundColor: string | null;
642+
canvasBackgroundColor: string;
641643
embedsValidationStatus: EmbedsValidationStatus | null;
642644
theme?: AppState["theme"];
643645
},

packages/excalidraw/components/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,10 +2792,10 @@ class App extends React.Component<AppProps, AppState> {
27922792
this.resetStore();
27932793

27942794
if (initialData?.scrollX != null) {
2795-
scene.appState.scrollX = initialData.scrollX;
2795+
restoredAppState.scrollX = initialData.scrollX;
27962796
}
27972797
if (initialData?.scrollY != null) {
2798-
scene.appState.scrollY = initialData.scrollY;
2798+
restoredAppState.scrollY = initialData.scrollY;
27992799
}
28002800

28012801
this.resetHistory();

packages/excalidraw/components/ExportDialog.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222

2323
&.theme--dark .ExportDialog__preview canvas {
24-
filter: none;
24+
// filter: none;
2525
}
2626

2727
.ExportDialog__actions {

packages/excalidraw/components/TTDDialog/common.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
88
import { EditorLocalStorage } from "../../data/EditorLocalStorage";
99
import { canvasToBlob } from "../../data/blob";
1010
import { t } from "../../i18n";
11-
import { convertToExcalidrawElements, exportToCanvas } from "../../index";
11+
import {
12+
convertToExcalidrawElements,
13+
exportToCanvas,
14+
THEME,
15+
} from "../../index";
1216

1317
import type { AppClassProperties, BinaryFiles } from "../../types";
1418

@@ -95,17 +99,21 @@ export const convertMermaidToExcalidraw = async ({
9599
};
96100

97101
const canvas = await exportToCanvas({
98-
elements: data.current.elements,
99-
files: data.current.files,
100-
exportPadding: DEFAULT_EXPORT_PADDING,
101-
maxWidthOrHeight:
102-
Math.max(parent.offsetWidth, parent.offsetHeight) *
103-
window.devicePixelRatio,
104-
appState: {
102+
data: {
103+
elements: data.current.elements,
104+
files: data.current.files,
105+
},
106+
config: {
105107
// TODO hack (will be refactored in TTD v2)
106-
exportWithDarkMode: document
108+
theme: document
107109
.querySelector(".excalidraw-container")
108-
?.classList.contains("theme--dark"),
110+
?.classList.contains("theme--dark")
111+
? THEME.DARK
112+
: THEME.LIGHT,
113+
padding: DEFAULT_EXPORT_PADDING,
114+
maxWidthOrHeight:
115+
Math.max(parent.offsetWidth, parent.offsetHeight) *
116+
window.devicePixelRatio,
109117
},
110118
});
111119
// if converting to blob fails, there's some problem that will

packages/excalidraw/renderer/staticScene.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ const _renderStaticScene = ({
253253
scale,
254254
normalizedWidth,
255255
normalizedHeight,
256-
theme: appState.theme,
256+
theme: renderConfig.theme,
257257
isExporting,
258258
canvasBackgroundColor: renderConfig.canvasBackgroundColor,
259259
});

packages/excalidraw/scene/export.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,16 +627,13 @@ export const exportToCanvas = async ({
627627
scrollX: -x + normalizedPadding,
628628
scrollY: -y + normalizedPadding,
629629
zoom: { value: DEFAULT_ZOOM_VALUE },
630-
631630
shouldCacheIgnoreZoom: false,
632-
theme: cfg.theme || THEME.LIGHT,
633631
},
634632
scale: canvasScale,
635633
renderConfig: {
636634
canvasBackgroundColor:
637635
cfg.canvasBackgroundColor === false
638-
? // null indicates transparent background
639-
null
636+
? "transparent"
640637
: cfg.canvasBackgroundColor ||
641638
appState.viewBackgroundColor ||
642639
COLOR_WHITE,
@@ -647,7 +644,7 @@ export const exportToCanvas = async ({
647644
embedsValidationStatus: new Map(),
648645
elementsPendingErasure: new Set(),
649646
pendingFlowchartNodes: null,
650-
theme: appState.exportWithDarkMode ? THEME.DARK : THEME.LIGHT,
647+
theme: cfg.theme || THEME.LIGHT,
651648
},
652649
});
653650

packages/excalidraw/scene/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ export type StaticCanvasRenderConfig = {
3232
/** when exporting the behavior is slightly different (e.g. we can't use
3333
CSS filters), and we disable render optimizations for best output */
3434
isExporting: boolean;
35-
/** null indicates transparent bg */
36-
canvasBackgroundColor: string | null;
35+
canvasBackgroundColor: string;
3736
embedsValidationStatus: EmbedsValidationStatus;
3837
elementsPendingErasure: ElementsPendingErasure;
3938
pendingFlowchartNodes: PendingExcalidrawElements | null;

0 commit comments

Comments
 (0)