AI-native design editor. Open-source Figma alternative.
feat(canvas): default canvas bg to dark on prefers-color-scheme: dark (#205)
Chris Gliddon0f875eee4679
diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.tsindex e49291079..23434a250 100644--- a/packages/core/src/constants.ts+++ b/packages/core/src/constants.ts@@ -11,6 +11,28 @@ export const SELECTION_COLOR = { r: 0.23, g: 0.51, b: 0.96, a: 1 } satisfies Colexport const COMPONENT_COLOR = { r: 0.592, g: 0.278, b: 1, a: 1 } satisfies Colorexport const SNAP_COLOR = { r: 1.0, g: 0.0, b: 0.56, a: 1 } satisfies Colorexport const CANVAS_BG_COLOR = { r: 0.96, g: 0.96, b: 0.96, a: 1 } satisfies Color+export const CANVAS_BG_COLOR_DARK = { r: 0.173, g: 0.173, b: 0.173, a: 1 } satisfies Color // #2c2c2c, Figma-ish dark canvas++/**+ * Returns the canvas background to initialize new pages with. Defers+ * to the OS `prefers-color-scheme` so users on a dark desktop don't+ * get a white flash every time they open a document.+ *+ * NOTE: this is deliberately the runtime/new-page path only. The+ * `.fig` serialization path continues to write the static light+ * `CANVAS_BG_COLOR` so files stay portable — a dark-theme user saving+ * a file must not force darkness on recipients.+ */+export function getDefaultCanvasBgColor(): Color {+ if (+ IS_BROWSER &&+ typeof window.matchMedia === 'function' &&+ window.matchMedia('(prefers-color-scheme: dark)').matches+ ) {+ return CANVAS_BG_COLOR_DARK+ }+ return CANVAS_BG_COLOR+}export const SNAP_THRESHOLD = 5diff --git a/packages/core/src/editor/create.ts b/packages/core/src/editor/create.tsindex 9e5d2fb53..658949099 100644--- a/packages/core/src/editor/create.ts+++ b/packages/core/src/editor/create.ts@@ -1,5 +1,5 @@import { prefetchFigmaSchema } from '../clipboard'-import { CANVAS_BG_COLOR, IS_BROWSER } from '../constants'+import { getDefaultCanvasBgColor, IS_BROWSER } from '../constants'import { computeAllLayouts, computeLayout, setTextMeasurer } from '../layout'import { SceneGraph } from '../scene-graph'import { UndoManager } from '../scene-graph/undo'@@ -42,7 +42,7 @@ export function createDefaultEditorState(pageId: string): EditorState {remoteCursors: [],documentName: 'Untitled',panX: 0,- pageColor: { ...CANVAS_BG_COLOR },+ pageColor: { ...getDefaultCanvasBgColor() },panY: 0,zoom: 1,renderVersion: 0,diff --git a/packages/core/src/editor/pages.ts b/packages/core/src/editor/pages.tsindex 71004c518..2e50c3073 100644--- a/packages/core/src/editor/pages.ts+++ b/packages/core/src/editor/pages.ts@@ -1,4 +1,4 @@-import { CANVAS_BG_COLOR } from '../constants'+import { getDefaultCanvasBgColor } from '../constants'import { computeAllLayouts } from '../layout'import { collectFontKeys } from '../text/fonts'@@ -40,7 +40,7 @@ export function createPageActions(ctx: EditorContext) {ctx.state.panX = 0ctx.state.panY = 0ctx.state.zoom = 1- ctx.state.pageColor = { ...CANVAS_BG_COLOR }+ ctx.state.pageColor = { ...getDefaultCanvasBgColor() }}const toLoad = collectFontKeys(