Skip to content

AI-native design editor. Open-source Figma alternative.

feat(settings): choose the interface accent color (#1041)

Danila Poyarkov357a66e7078f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2359e0612..f6596d337 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,6 +42,7 @@
- `fetchIcon`, `fetchIcons`, `searchIcons`, `searchIconsBatch`, and `clearIconCache` are removed from `@open-pencil/core`. Icons come from an `IconProvider` instead: `iconify` is the default Iconify provider, `createIconifyProvider()` makes one with its own cache, and `placeIcon` places an icon that keeps its name. A custom provider also implements `previews()`, `collections()`, and `browse()`, which give pickers each icon's SVG markup, the sets, and a set's icons.
- The editor's view state has a required `cornerRadiusHover`, the selected rectangle whose corner radius handles the canvas shows; code that creates editor state itself must set it, as `createDefaultEditorViewState` does.
- `defineTool` from `@open-pencil/core/tools` takes its `input` as a `v.strictObject` instead of a `v.object`, and `ToolDef.input` is a strict object schema, so a tool rejects arguments it does not declare.
+- `RulerTheme` from `@open-pencil/core/canvas` no longer has `label`: ruler badges and size pills draw their text in the `foreground` of the editor state's new `selectionTheme`, which also sets the canvas selection color and defaults to the previous blue with white text.
### Added
@@ -104,6 +105,7 @@
- See how auto layout arranges layers, as in Figma: hovering a horizontal or vertical auto layout frame outlines its visible direct children with dotted lines, and selecting a single layer dots the border of its auto layout parent, in purple for components and instances. The outlines, and the padding and gap markers of a selected frame, hide while layers move, resize, or rotate.
- Join a shared room right away under a generated name such as *Teal Fox*, and set the one name every room shows in Settings or the share panel.
+- Choose an accent color in **Settings → General → Appearance**: one of eight presets or any custom color. Buttons, toggles, selected layers, focus rings, the active tool, and the canvas selection, handles, size labels, and ruler badges follow it in both themes, and text on accent surfaces turns dark when the color is too light for white. The CLI and MCP `settings` commands read and set it as `appearance.accent`.
### Changed
- Import SVG as editable layers, as pasting it into Figma does, from `import_svg`, dropped files, and pasted markup ([#734](https://github.com/open-pencil/open-pencil/issues/734)). Each `<g>` becomes a group, each shape its own vector, and each `<text>` a text layer with its fonts, `<tspan>` styles, alignment, and rotation, named after its `id`, element opacity is kept, and clipped content sits in a clip path group whose mask is drawn from the clip's shapes. The imported frame is white, clips its content, and is named after the root `<svg>` `id`; an SVG without a size imports as a group. Shapes are no longer merged into one multi-color vector.
diff --git a/packages/core/src/canvas/index.ts b/packages/core/src/canvas/index.ts
index 00895b086..18b1e032c 100644
--- a/packages/core/src/canvas/index.ts
+++ b/packages/core/src/canvas/index.ts
@@ -20,7 +20,13 @@ export { hitTestGuides, type GuideHit } from './guides/hit-test'
export type { GuideOverlayState, GuidePreview, GuideSelection } from './guides/types'
export { canvasLabelForeground } from './labels/color'
export type { ImagePreview, ImagePreviewDecoder } from './images/previews'
-export { SkiaRenderer, type PresenceCursor, type RenderOverlays, type RulerTheme } from './renderer'
+export {
+ SkiaRenderer,
+ type PresenceCursor,
+ type RenderOverlays,
+ type RulerTheme,
+ type SelectionTheme
+} from './renderer'
export {
hitTestIssueMarkers,
issueMarkerLabel,
diff --git a/packages/core/src/canvas/labels/selection.ts b/packages/core/src/canvas/labels/selection.ts
index 252f5b350..55920e181 100644
--- a/packages/core/src/canvas/labels/selection.ts
+++ b/packages/core/src/canvas/labels/selection.ts
@@ -42,7 +42,8 @@ function drawSizePill(
text: string,
x: number,
y: number,
- color: ReturnType<SkiaRenderer['selColor']>
+ color: ReturnType<SkiaRenderer['selColor']>,
+ textColor: ReturnType<SkiaRenderer['selColor']>
): void {
const pillW = measureGlyphWidth(sizeFont, text) + SIZE_PILL_PADDING_X * 2
const pillX = x - pillW / 2
@@ -55,7 +56,7 @@ function drawSizePill(
)
canvas.drawRRect(rrect, r.auxFill)
- r.auxFill.setColor(r.ck.WHITE)
+ r.auxFill.setColor(textColor)
canvas.drawText(
text,
pillX + SIZE_PILL_PADDING_X,
@@ -84,7 +85,8 @@ export function drawSingleSelectionSize(
canvas.save()
canvas.concat(labelScreenMatrix(transform, r))
- drawSizePill(r, canvas, sizeFont, sizeText, 0, 0, pillColor)
+ const textColor = r.outlineForegroundColor(node, graph)
+ drawSizePill(r, canvas, sizeFont, sizeText, 0, 0, pillColor, textColor)
canvas.restore()
}
function drawMultiSelectionSize(
@@ -105,8 +107,9 @@ function drawMultiSelectionSize(
const smx = (sx1 + sx2) / 2
const allComponents = nodes.length > 0 && nodes.every((n) => r.isInComponent(n, graph))
const pillColor = allComponents ? r.compColor() : r.selColor()
+ const textColor = allComponents ? r.ck.WHITE : r.selForegroundColor()
- drawSizePill(r, canvas, sizeFont, sizeText, smx, sy2, pillColor)
+ drawSizePill(r, canvas, sizeFont, sizeText, smx, sy2, pillColor, textColor)
}
export function drawSelectionLabels(
diff --git a/packages/core/src/canvas/overlays/feedback.ts b/packages/core/src/canvas/overlays/feedback.ts
index 1968a6ff2..490873ff0 100644
--- a/packages/core/src/canvas/overlays/feedback.ts
+++ b/packages/core/src/canvas/overlays/feedback.ts
@@ -10,7 +10,6 @@ import {
DROP_HIGHLIGHT_ALPHA,
DROP_HIGHLIGHT_STROKE,
FLASH_ATTACK_MS,
- FLASH_COLOR,
FLASH_HOLD_MS,
FLASH_OVERSHOOT,
FLASH_RELEASE_MS,
@@ -84,7 +83,17 @@ export function drawFlashes(r: SkiaRenderer, canvas: Canvas, graph: SceneGraph):
extraPad = 0
}
- if (!drawNodeHighlightRect(r, canvas, graph, flash.nodeId, FLASH_COLOR, opacity, extraPad)) {
+ if (
+ !drawNodeHighlightRect(
+ r,
+ canvas,
+ graph,
+ flash.nodeId,
+ r.selectionTheme.color,
+ opacity,
+ extraPad
+ )
+ ) {
r._flashes.splice(i, 1)
}
}
diff --git a/packages/core/src/canvas/overlays/text-edit.ts b/packages/core/src/canvas/overlays/text-edit.ts
index d1692500f..3e108bcba 100644
--- a/packages/core/src/canvas/overlays/text-edit.ts
+++ b/packages/core/src/canvas/overlays/text-edit.ts
@@ -3,7 +3,7 @@ import type { Canvas } from 'canvaskit-wasm'
import type { SceneNode } from '@open-pencil/scene-graph'
import type { SkiaRenderer } from '#core/canvas/renderer'
-import { TEXT_CARET_COLOR, TEXT_CARET_WIDTH, TEXT_SELECTION_COLOR } from '#core/constants'
+import { TEXT_CARET_COLOR, TEXT_CARET_WIDTH, TEXT_SELECTION_ALPHA } from '#core/constants'
import type { TextEditor } from '#core/text/editor'
import { withScreenStroke } from './outline'
@@ -30,14 +30,7 @@ export function drawTextEditOverlay(
const selRects = editor.getSelectionRects()
if (selRects.length > 0) {
- r.auxFill.setColor(
- r.ck.Color4f(
- TEXT_SELECTION_COLOR.r,
- TEXT_SELECTION_COLOR.g,
- TEXT_SELECTION_COLOR.b,
- TEXT_SELECTION_COLOR.a
- )
- )
+ r.auxFill.setColor(r.selColor(TEXT_SELECTION_ALPHA))
for (const sel of selRects) {
canvas.drawRect(r.ck.LTRBRect(sel.x, sel.y, sel.x + sel.width, sel.y + sel.height), r.auxFill)
}
diff --git a/packages/core/src/canvas/renderer.ts b/packages/core/src/canvas/renderer.ts
index 430a39c20..320216181 100644
--- a/packages/core/src/canvas/renderer.ts
+++ b/packages/core/src/canvas/renderer.ts
@@ -1,3 +1,4 @@
+import { isEqual } from 'es-toolkit'
import { toUint8Array } from 'js-base64'
import { slotPropertyId } from '@open-pencil/scene-graph'
@@ -8,7 +9,7 @@ import type { SnapGuide } from '@open-pencil/scene-graph/snap'
/* eslint-disable max-lines -- SkiaRenderer facade owns CanvasKit state and delegates domain drawing */
import {
- SELECTION_COLOR,
+ DEFAULT_SELECTION_THEME,
COMPONENT_COLOR,
SLOT_COLOR,
CANVAS_BG_COLOR,
@@ -33,14 +34,20 @@ import * as RenderColors from './renderer/colors'
import * as RendererFonts from './renderer/fonts'
import { destroyRenderer } from './renderer/lifecycle'
import { installRendererDomainMethods } from './renderer/methods'
-import { initializeRendererPaints } from './renderer/paints'
+import { initializeRendererPaints, initializeSelectionPaintColors } from './renderer/paints'
import * as RenderPipeline from './renderer/pipeline'
import type { SceneBacking, SceneBackingBuild } from './renderer/retained-backing/types'
import * as RendererState from './renderer/state'
import * as RenderText from './text'
import { createGlyphSilhouetteCache } from './text/derived'
import { TextPreparationCache } from './text/preparation-cache'
-export type { MeasurementMode, PresenceCursor, RenderOverlays, RulerTheme } from './renderer/types'
+export type {
+ MeasurementMode,
+ PresenceCursor,
+ RenderOverlays,
+ RulerTheme,
+ SelectionTheme
+} from './renderer/types'
import type {
Path,
CanvasKit,
@@ -74,7 +81,7 @@ import type { PlacedIssueMarker } from './issues/types'
import { EffectRasterCache } from './renderer/effect-raster-cache'
import { TiledSceneController } from './renderer/tiles'
import type { TransientCanvasPreview } from './renderer/transient-previews'
-import type { PresenceCursor, RenderOverlays, RulerTheme } from './renderer/types'
+import type { PresenceCursor, RenderOverlays, RulerTheme, SelectionTheme } from './renderer/types'
export class SkiaRenderer {
ck: CanvasKit
@@ -183,6 +190,8 @@ export class SkiaRenderer {
showRulers = true
pageColor = CANVAS_BG_COLOR
rulerTheme: RulerTheme | null = null
+ /** Selection chrome, set from editor state each frame through {@link setSelectionTheme}. */
+ selectionTheme: SelectionTheme = DEFAULT_SELECTION_THEME
pageId: string | null = null
/** Issue markers placed in the last overlay pass; hit testing reads the same layout. */
issueMarkers: PlacedIssueMarker[] = []
@@ -421,7 +430,20 @@ export class SkiaRenderer {
}
selColor(alpha = 1) {
- return this.ck.Color4f(SELECTION_COLOR.r, SELECTION_COLOR.g, SELECTION_COLOR.b, alpha)
+ const { r, g, b } = this.selectionTheme.color
+ return this.ck.Color4f(r, g, b, alpha)
+ }
+
+ selForegroundColor() {
+ const { r, g, b } = this.selectionTheme.foreground
+ return this.ck.Color4f(r, g, b, 1)
+ }
+
+ /** Switches selection chrome to `theme`, repainting the paints that keep it between frames. */
+ setSelectionTheme(theme: SelectionTheme = DEFAULT_SELECTION_THEME): void {
+ if (isEqual(theme, this.selectionTheme)) return
+ this.selectionTheme = { color: { ...theme.color }, foreground: { ...theme.foreground } }
+ initializeSelectionPaintColors(this)
}
compColor(alpha = 1) {
@@ -441,6 +463,12 @@ export class SkiaRenderer {
return this.isInComponent(node, graph) ? this.compColor() : this.selColor()
}
+ /** Text drawn on {@link outlineColor}: white on slot and component colors, else the selection foreground. */
+ outlineForegroundColor(node: SceneNode, graph: SceneGraph) {
+ if (slotPropertyId(node) || this.isInComponent(node, graph)) return this.ck.WHITE
+ return this.selForegroundColor()
+ }
+
/** A component, instance or set, or a layer inside one; content placed in a slot is not. */
isInComponent(node: SceneNode, graph: SceneGraph): boolean {
const owner = graph.closest(
diff --git a/packages/core/src/canvas/renderer/paints.ts b/packages/core/src/canvas/renderer/paints.ts
index 2953d89dd..55d1adffa 100644
--- a/packages/core/src/canvas/renderer/paints.ts
+++ b/packages/core/src/canvas/renderer/paints.ts
@@ -24,13 +24,11 @@ export function initializeRendererPaints(r: SkiaRenderer): void {
r.selectionPaint = new ck.Paint()
r.selectionPaint.setStyle(ck.PaintStyle.Stroke)
r.selectionPaint.setStrokeWidth(1)
- r.selectionPaint.setColor(r.selColor())
r.selectionPaint.setAntiAlias(true)
r.parentOutlinePaint = new ck.Paint()
r.parentOutlinePaint.setStyle(ck.PaintStyle.Stroke)
r.parentOutlinePaint.setStrokeWidth(1)
- r.parentOutlinePaint.setColor(r.selColor(PARENT_OUTLINE_ALPHA))
r.parentOutlinePaint.setAntiAlias(true)
r.parentOutlinePaint.setPathEffect(
ck.PathEffect.MakeDash([PARENT_OUTLINE_DASH, PARENT_OUTLINE_DASH], 0)
@@ -95,7 +93,6 @@ export function initializeRendererPaints(r: SkiaRenderer): void {
r.penHandlePaint = new ck.Paint()
r.penHandlePaint.setStyle(ck.PaintStyle.Stroke)
r.penHandlePaint.setStrokeWidth(1)
- r.penHandlePaint.setColor(r.selColor(PARENT_OUTLINE_ALPHA))
r.penHandlePaint.setAntiAlias(true)
r.penVertexFill = new ck.Paint()
@@ -106,6 +103,15 @@ export function initializeRendererPaints(r: SkiaRenderer): void {
r.penVertexStroke = new ck.Paint()
r.penVertexStroke.setStyle(ck.PaintStyle.Stroke)
r.penVertexStroke.setStrokeWidth(1)
- r.penVertexStroke.setColor(r.selColor())
r.penVertexStroke.setAntiAlias(true)
+
+ initializeSelectionPaintColors(r)
+}
+
+/** Colors the long-lived paints drawn in the selection color; rerun when that color changes. */
+export function initializeSelectionPaintColors(r: SkiaRenderer): void {
+ r.selectionPaint.setColor(r.selColor())
+ r.parentOutlinePaint.setColor(r.selColor(PARENT_OUTLINE_ALPHA))
+ r.penHandlePaint.setColor(r.selColor(PARENT_OUTLINE_ALPHA))
+ r.penVertexStroke.setColor(r.selColor())
}
diff --git a/packages/core/src/canvas/renderer/pipeline.ts b/packages/core/src/canvas/renderer/pipeline.ts
index 6e499b4ee..daa43715e 100644
--- a/packages/core/src/canvas/renderer/pipeline.ts
+++ b/packages/core/src/canvas/renderer/pipeline.ts
@@ -72,6 +72,7 @@ export function renderFromEditorState(
r.showRulers = showRulers
r.pageColor = state.pageColor
r.rulerTheme = state.rulerTheme ?? null
+ r.setSelectionTheme(state.selectionTheme)
r.pageId = state.currentPageId
r.navigationPhase = state.navigation.phase
r.navigationGeneration = state.navigation.generation
diff --git a/packages/core/src/canvas/renderer/types.ts b/packages/core/src/canvas/renderer/types.ts
index e23b18340..245609242 100644
--- a/packages/core/src/canvas/renderer/types.ts
+++ b/packages/core/src/canvas/renderer/types.ts
@@ -8,11 +8,16 @@ import type { CornerRadiusHover, GradientEdit } from '#core/editor/types'
import type { RotationPreview } from '#core/geometry'
import type { TextEditor } from '#core/text/editor'
+/** Selection chrome on the canvas and the text drawn on it, such as size pills and ruler badges. */
+export interface SelectionTheme {
+ color: Color
+ foreground: Color
+}
+
export interface RulerTheme {
background: Color
tick: Color
text: Color
- label: Color
}
export type MeasurementMode = 'off' | 'shallow' | 'deep'
diff --git a/packages/core/src/canvas/rulers.ts b/packages/core/src/canvas/rulers.ts
index 92b665dc4..310197a35 100644
--- a/packages/core/src/canvas/rulers.ts
+++ b/packages/core/src/canvas/rulers.ts
@@ -134,11 +134,10 @@ export function drawRulers(
if (vw === 0 || vh === 0) return
if (r.rulerTheme) {
- const { background, tick, text, label } = r.rulerTheme
+ const { background, tick, text } = r.rulerTheme
r.rulerBgPaint.setColor(r.ck.Color4f(background.r, background.g, background.b, background.a))
r.rulerTickPaint.setColor(r.ck.Color4f(tick.r, tick.g, tick.b, tick.a))
r.rulerTextPaint.setColor(r.ck.Color4f(text.r, text.g, text.b, text.a))
- r.rulerLabelPaint.setColor(r.ck.Color4f(label.r, label.g, label.b, label.a))
}
canvas.drawRect(r.ck.LTRBRect(0, 0, vw, R), r.rulerBgPaint)
@@ -313,6 +312,7 @@ export function drawRulerBadge(
const h = RULER_BADGE_HEIGHT
r.rulerBadgePaint.setColor(r.selColor())
+ r.rulerLabelPaint.setColor(r.selForegroundColor())
if (axis === 'horizontal') {
const bx = x - (textW + pad * 2) / 2
diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts
index 286bfc002..84d9324bb 100644
--- a/packages/core/src/constants.ts
+++ b/packages/core/src/constants.ts
@@ -1,6 +1,9 @@
import type { Fill, Stroke } from '@open-pencil/scene-graph'
+import { WHITE } from '@open-pencil/scene-graph/constants'
import type { Color } from '@open-pencil/scene-graph/primitives'
+import type { SelectionTheme } from '#core/canvas/renderer/types'
+
export const IS_BROWSER = typeof window !== 'undefined'
export const IS_TAURI = IS_BROWSER && '__TAURI_INTERNALS__' in window
@@ -8,6 +11,11 @@ export const BLACK: Color = { r: 0, g: 0, b: 0, a: 1 }
export const TRANSPARENT: Color = { r: 0, g: 0, b: 0, a: 0 }
export const DEFAULT_SHADOW_COLOR: Color = { r: 0, g: 0, b: 0, a: 0.25 }
export const SELECTION_COLOR = { r: 0.23, g: 0.51, b: 0.96, a: 1 } satisfies Color
+/** Selection chrome when the app sets no accent: the default blue with white text. */
+export const DEFAULT_SELECTION_THEME: Readonly<SelectionTheme> = {
+ color: SELECTION_COLOR,
+ foreground: WHITE
+}
export const COMPONENT_COLOR = { r: 0.592, g: 0.278, b: 1, a: 1 } satisfies Color
/** Slot frames and their outlines, `#f24bbc` like the app's `--color-slot`. */
export const SLOT_COLOR = { r: 0.949, g: 0.294, b: 0.737, a: 1 } satisfies Color
@@ -112,7 +120,6 @@ export const COMPONENT_LABEL_ICON_GAP = 4
export const RULER_TARGET_PIXEL_SPACING = 100
export const RULER_MAJOR_TOLERANCE = 0.01
-export const FLASH_COLOR = SELECTION_COLOR
export const FLASH_ATTACK_MS = 200
export const FLASH_HOLD_MS = 400
export const FLASH_RELEASE_MS = 300
@@ -147,7 +154,8 @@ export const AI_DONE_COLOR = { r: 0.16, g: 0.73, b: 0.36 }
export const AI_PULSE_PERIOD_MS = 1500
export const AI_DONE_DURATION_MS = 800
-export const TEXT_SELECTION_COLOR = { r: 0.26, g: 0.52, b: 0.96, a: 0.3 }
+/** Opacity of the selection color behind selected text while editing. */
+export const TEXT_SELECTION_ALPHA = 0.3
export const TEXT_CARET_COLOR = BLACK
export const TEXT_CARET_WIDTH = 1
diff --git a/packages/core/src/editor/state/shared.ts b/packages/core/src/editor/state/shared.ts
index 4993861a9..4870e0ee0 100644
--- a/packages/core/src/editor/state/shared.ts
+++ b/packages/core/src/editor/state/shared.ts
@@ -12,6 +12,7 @@ export function createDefaultEditorSharedState(): EditorSharedState {
designIssues: null,
codeFocusNodeId: null,
rulerTheme: undefined,
+ selectionTheme: undefined,
sceneVersion: 0,
canvasVersion: 0
}
diff --git a/packages/core/src/editor/types.ts b/packages/core/src/editor/types.ts
index 2b941cbe3..38c3cee5e 100644
--- a/packages/core/src/editor/types.ts
+++ b/packages/core/src/editor/types.ts
@@ -16,7 +16,12 @@ import type { UndoManager } from '@open-pencil/scene-graph/undo'
import type { GuideOverlayState } from '#core/canvas/guides/types'
import type { DesignIssueOverlay } from '#core/canvas/issues/types'
import type { RulerTheme, SkiaRenderer } from '#core/canvas/renderer'
-import type { MeasurementMode, PresenceCursor, RenderOverlays } from '#core/canvas/renderer/types'
+import type {
+ MeasurementMode,
+ PresenceCursor,
+ RenderOverlays,
+ SelectionTheme
+} from '#core/canvas/renderer/types'
import type { InterfaceTheme } from '#core/constants'
import type { PlayState } from '#core/editor/play/actions'
import type { SnappingPreferences } from '#core/editor/preferences'
@@ -74,6 +79,8 @@ export interface EditorSharedState {
/** The layer of the code element around the cursor in a code editor, shown in every pane. */
codeFocusNodeId: string | null
rulerTheme?: RulerTheme
+ /** Selection chrome on the canvas, following the interface accent; the default blue when unset. */
+ selectionTheme?: SelectionTheme
/** The interface theme new sections take their fill from; light when unset. */
theme?: InterfaceTheme
/** Bumped by every document change; views, saving, and recovery follow it. */
diff --git a/packages/core/tests/canvas/renderer/selection-theme.test.ts b/packages/core/tests/canvas/renderer/selection-theme.test.ts
new file mode 100644
index 000000000..043a7e196
--- /dev/null
+++ b/packages/core/tests/canvas/renderer/selection-theme.test.ts
@@ -0,0 +1,62 @@
+import { expect, test } from 'bun:test'
+
+import { SkiaRenderer } from '#core/canvas'
+import { DEFAULT_SELECTION_THEME } from '#core/constants'
+import { initCanvasKit } from '#core/io'
+
+import { expectDefined } from '#core-tests/helpers/assert'
+
+const ck = await initCanvasKit()
+
+function withRenderer(run: (renderer: SkiaRenderer) => void) {
+ const surface = expectDefined(ck.MakeSurface(64, 64), 'surface')
+ const renderer = new SkiaRenderer(ck, surface)
+ try {
+ run(renderer)
+ } finally {
+ renderer.destroy()
+ }
+}
+
+function rgb(color: Float32Array) {
+ return Array.from(color.slice(0, 3), (channel) => Math.round(channel * 255))
+}
+
+const GREEN_THEME = {
+ color: { r: 0.08, g: 0.5, b: 0.24, a: 1 },
+ foreground: { r: 0, g: 0, b: 0, a: 1 }
+}
+
+test('starts with the default blue and white text on it', () => {
+ withRenderer((renderer) => {
+ expect(renderer.selectionTheme).toEqual(DEFAULT_SELECTION_THEME)
+ expect(rgb(renderer.selForegroundColor())).toEqual([255, 255, 255])
+ })
+})
+
+test('long-lived selection paints and text follow a new selection theme', () => {
+ withRenderer((renderer) => {
+ renderer.setSelectionTheme(GREEN_THEME)
+ const { r, g, b } = GREEN_THEME.color
+ const expected = rgb(ck.Color4f(r, g, b, 1))
+ for (const paint of [
+ renderer.selectionPaint,
+ renderer.parentOutlinePaint,
+ renderer.penHandlePaint,
+ renderer.penVertexStroke
+ ]) {
+ expect(rgb(paint.getColor())).toEqual(expected)
+ }
+ expect(rgb(renderer.selColor())).toEqual(expected)
+ expect(rgb(renderer.selForegroundColor())).toEqual([0, 0, 0])
+ })
+})
+
+test('an unset theme returns to the default', () => {
+ withRenderer((renderer) => {
+ renderer.setSelectionTheme(GREEN_THEME)
+ renderer.setSelectionTheme(undefined)
+ expect(renderer.selectionTheme).toEqual(DEFAULT_SELECTION_THEME)
+ expect(rgb(renderer.selectionPaint.getColor())).toEqual(rgb(renderer.selColor()))
+ })
+})
diff --git a/packages/docs/programmable/cli/app-control.md b/packages/docs/programmable/cli/app-control.md
index 6ead078cd..6a076aeb8 100644
--- a/packages/docs/programmable/cli/app-control.md
+++ b/packages/docs/programmable/cli/app-control.md
@@ -76,6 +76,7 @@ Values are read as JSON when they parse (`false`, `100`, `"auto"`) and as plain
| `appearance.theme` | `dark`, `light`, `auto` |
| `appearance.language` | `en`, `de`, `es`, `fr`, `it`, `ja`, `pl`, `ru`, `zh-CN` |
| `appearance.animations` | `system`, `off` |
+| `appearance.accent` | JSON object: `{"kind":"preset","preset":"green"}` with `blue`, `purple`, `pink`, `red`, `orange`, `yellow`, `green`, `graphite`, or `{"kind":"custom","color":"#FF6600"}` |
| `editing.snapping.geometry` | `true`, `false` |
| `editing.snapping.objects` | `true`, `false` |
| `editing.snapping.pixelGrid` | `true`, `false` |
diff --git a/packages/mcp/src/tool/manifest.ts b/packages/mcp/src/tool/manifest.ts
index 589006a64..6391359ec 100644
--- a/packages/mcp/src/tool/manifest.ts
+++ b/packages/mcp/src/tool/manifest.ts
@@ -116,7 +116,7 @@ export function createToolDescriptors(filesystemEnabled: boolean): ToolDescripto
{
name: 'get_settings',
description:
- 'Read editor settings: appearance (theme, language, animations), snapping, canvas rendering, recovery, AI chat, and design check preferences.',
+ 'Read editor settings: appearance (theme, language, animations, accent color), snapping, canvas rendering, recovery, AI chat, and design check preferences.',
effect: 'read',
availability: 'default',
capabilities: ['settings:read'],
diff --git a/packages/vue/src/i18n/locales/de/settings.json b/packages/vue/src/i18n/locales/de/settings.json
index 8171db742..02c7fc840 100644
--- a/packages/vue/src/i18n/locales/de/settings.json
+++ b/packages/vue/src/i18n/locales/de/settings.json
@@ -25,6 +25,16 @@
"animations": "Animationen",
"animationsSystem": "Systemeinstellung",
"animationsOff": "Aus",
+ "accentColor": "Akzentfarbe",
+ "accentBlue": "Blau",
+ "accentPurple": "Lila",
+ "accentPink": "Pink",
+ "accentRed": "Rot",
+ "accentOrange": "Orange",
+ "accentYellow": "Gelb",
+ "accentGreen": "Grün",
+ "accentGraphite": "Graphit",
+ "accentCustom": "Eigene Farbe",
"discardChanges": "Änderungen verwerfen?",
"discardChangesDescription": "Deine ungespeicherten Änderungen gehen verloren.",
"keepEditing": "Weiter bearbeiten",
diff --git a/packages/vue/src/i18n/locales/es/settings.json b/packages/vue/src/i18n/locales/es/settings.json
index 50eb87858..ee4e03ea6 100644
--- a/packages/vue/src/i18n/locales/es/settings.json
+++ b/packages/vue/src/i18n/locales/es/settings.json
@@ -25,6 +25,16 @@
"animations": "Animaciones",
"animationsSystem": "Seguir al sistema",
"animationsOff": "Desactivadas",
+ "accentColor": "Color de acento",
+ "accentBlue": "Azul",
+ "accentPurple": "Morado",
+ "accentPink": "Rosa",
+ "accentRed": "Rojo",
+ "accentOrange": "Naranja",
+ "accentYellow": "Amarillo",
+ "accentGreen": "Verde",
+ "accentGraphite": "Grafito",
+ "accentCustom": "Color personalizado",
"discardChanges": "¿Descartar los cambios?",
"discardChangesDescription": "Se perderán los cambios sin guardar.",
"keepEditing": "Seguir editando",
diff --git a/packages/vue/src/i18n/locales/fr/settings.json b/packages/vue/src/i18n/locales/fr/settings.json
index 847c5229b..444be070a 100644
--- a/packages/vue/src/i18n/locales/fr/settings.json
+++ b/packages/vue/src/i18n/locales/fr/settings.json
@@ -25,6 +25,16 @@
"animations": "Animations",
"animationsSystem": "Suivre le système",
"animationsOff": "Désactivées",
+ "accentColor": "Couleur d’accentuation",
+ "accentBlue": "Bleu",
+ "accentPurple": "Violet",
+ "accentPink": "Rose",
+ "accentRed": "Rouge",
+ "accentOrange": "Orange",
+ "accentYellow": "Jaune",
+ "accentGreen": "Vert",
+ "accentGraphite": "Graphite",
+ "accentCustom": "Couleur personnalisée",
"discardChanges": "Abandonner les modifications ?",
"discardChangesDescription": "Vos modifications non enregistrées seront perdues.",
"keepEditing": "Continuer à modifier",
diff --git a/packages/vue/src/i18n/locales/it/settings.json b/packages/vue/src/i18n/locales/it/settings.json
index d9a4b32aa..4ca6e58ca 100644
--- a/packages/vue/src/i18n/locales/it/settings.json
+++ b/packages/vue/src/i18n/locales/it/settings.json
@@ -25,6 +25,16 @@
"animations": "Animazioni",
"animationsSystem": "Segui il sistema",
"animationsOff": "Disattivate",
+ "accentColor": "Colore di accento",
+ "accentBlue": "Blu",
+ "accentPurple": "Viola",
+ "accentPink": "Rosa",
+ "accentRed": "Rosso",
+ "accentOrange": "Arancione",
+ "accentYellow": "Giallo",
+ "accentGreen": "Verde",
+ "accentGraphite": "Grafite",
+ "accentCustom": "Colore personalizzato",
"discardChanges": "Scartare le modifiche?",
"discardChangesDescription": "Le modifiche non salvate andranno perse.",
"keepEditing": "Continua a modificare",
diff --git a/packages/vue/src/i18n/locales/ja/settings.json b/packages/vue/src/i18n/locales/ja/settings.json
index 227fdf333..96a50412b 100644
--- a/packages/vue/src/i18n/locales/ja/settings.json
+++ b/packages/vue/src/i18n/locales/ja/settings.json
@@ -25,6 +25,16 @@
"animations": "アニメーション",
"animationsSystem": "システム設定に従う",
"animationsOff": "オフ",
+ "accentColor": "アクセントカラー",
+ "accentBlue": "ブルー",
+ "accentPurple": "パープル",
+ "accentPink": "ピンク",
+ "accentRed": "レッド",
+ "accentOrange": "オレンジ",
+ "accentYellow": "イエロー",
+ "accentGreen": "グリーン",
+ "accentGraphite": "グラファイト",
+ "accentCustom": "カスタムカラー",
"discardChanges": "変更を破棄しますか?",
"discardChangesDescription": "保存されていない変更は失われます。",
"keepEditing": "編集を続ける",
diff --git a/packages/vue/src/i18n/locales/pl/settings.json b/packages/vue/src/i18n/locales/pl/settings.json
index 21851380d..56a1fc9df 100644
--- a/packages/vue/src/i18n/locales/pl/settings.json
+++ b/packages/vue/src/i18n/locales/pl/settings.json
@@ -25,6 +25,16 @@
"animations": "Animacje",
"animationsSystem": "Zgodnie z systemem",
"animationsOff": "Wyłączone",
+ "accentColor": "Kolor akcentu",
+ "accentBlue": "Niebieski",
+ "accentPurple": "Fioletowy",
+ "accentPink": "Różowy",
+ "accentRed": "Czerwony",
+ "accentOrange": "Pomarańczowy",
+ "accentYellow": "Żółty",
+ "accentGreen": "Zielony",
+ "accentGraphite": "Grafitowy",
+ "accentCustom": "Własny kolor",
"discardChanges": "Odrzucić zmiany?",
"discardChangesDescription": "Niezapisane zmiany zostaną utracone.",
"keepEditing": "Kontynuuj edycję",
diff --git a/packages/vue/src/i18n/locales/ru/settings.json b/packages/vue/src/i18n/locales/ru/settings.json
index 4f7736b29..d5d95f508 100644
--- a/packages/vue/src/i18n/locales/ru/settings.json
+++ b/packages/vue/src/i18n/locales/ru/settings.json
@@ -25,6 +25,16 @@
"animations": "Анимации",
"animationsSystem": "Как в системе",
"animationsOff": "Выключены",
+ "accentColor": "Акцентный цвет",
+ "accentBlue": "Синий",
+ "accentPurple": "Фиолетовый",
+ "accentPink": "Розовый",
+ "accentRed": "Красный",
+ "accentOrange": "Оранжевый",
+ "accentYellow": "Жёлтый",
+ "accentGreen": "Зелёный",
+ "accentGraphite": "Графит",
+ "accentCustom": "Свой цвет",
"discardChanges": "Отменить изменения?",
"discardChangesDescription": "Несохранённые изменения будут потеряны.",
"keepEditing": "Продолжить редактирование",
diff --git a/packages/vue/src/i18n/locales/zh-cn/settings.json b/packages/vue/src/i18n/locales/zh-cn/settings.json
index 1b3f0b56b..134d9d21d 100644
--- a/packages/vue/src/i18n/locales/zh-cn/settings.json
+++ b/packages/vue/src/i18n/locales/zh-cn/settings.json
@@ -25,6 +25,16 @@
"animations": "动画",
"animationsSystem": "跟随系统",
"animationsOff": "关闭",
+ "accentColor": "强调色",
+ "accentBlue": "蓝色",
+ "accentPurple": "紫色",
+ "accentPink": "粉色",
+ "accentRed": "红色",
+ "accentOrange": "橙色",
+ "accentYellow": "黄色",
+ "accentGreen": "绿色",
+ "accentGraphite": "石墨色",
+ "accentCustom": "自定义颜色",
"discardChanges": "放弃更改?",
"discardChangesDescription": "未保存的更改将丢失。",
"keepEditing": "继续编辑",
diff --git a/packages/vue/src/i18n/messages/settings.ts b/packages/vue/src/i18n/messages/settings.ts
index 5afb1f6cc..2925389db 100644
--- a/packages/vue/src/i18n/messages/settings.ts
+++ b/packages/vue/src/i18n/messages/settings.ts
@@ -5,6 +5,16 @@ export const settingsMessageDefaults = {
animations: 'Animations',
animationsSystem: 'Follow system',
animationsOff: 'Off',
+ accentColor: 'Accent color',
+ accentBlue: 'Blue',
+ accentPurple: 'Purple',
+ accentPink: 'Pink',
+ accentRed: 'Red',
+ accentOrange: 'Orange',
+ accentYellow: 'Yellow',
+ accentGreen: 'Green',
+ accentGraphite: 'Graphite',
+ accentCustom: 'Custom color',
title: 'Settings',
description: 'Manage integrations and app preferences.',
general: 'General',
diff --git a/src/app.css b/src/app.css
index 07ad7bc98..ee1bc73a4 100644
--- a/src/app.css
+++ b/src/app.css
@@ -58,7 +58,10 @@
--color-canvas: #1e1e1e;
--color-border: #3a3a3a;
--color-hover: #353535;
+ /* The accent family; src/app/shell/accent/palette.ts derives other accents from it. */
--color-accent: #2563eb;
+ --color-on-accent: #ffffff;
+ --color-on-primary: #1f2328;
--color-surface: #f0f0f0;
--color-muted: #a6a6a6;
--color-input: #1e1e1e;
@@ -89,7 +92,6 @@
--color-ruler-bg: rgb(36, 36, 36);
--color-ruler-tick: rgb(102, 102, 102);
--color-ruler-text: rgb(140, 140, 140);
- --color-ruler-label: rgb(255, 255, 255);
}
html[data-theme='light'] {
@@ -105,6 +107,7 @@ html[data-theme='light'] {
--color-hover: #eef1f5;
--color-accent: #2563eb;
--color-primary: #1d4ed8;
+ --color-on-primary: #ffffff;
--color-inverted: #ffffff;
--color-surface: #1f2328;
--color-muted: #5f6673;
@@ -134,7 +137,6 @@ html[data-theme='light'] {
--color-ruler-bg: rgb(250, 250, 251);
--color-ruler-tick: rgb(163, 171, 182);
--color-ruler-text: rgb(90, 99, 112);
- --color-ruler-label: rgb(255, 255, 255);
}
html,
diff --git a/src/app/settings/automation.ts b/src/app/settings/automation.ts
index cd44d9b32..e9da39476 100644
--- a/src/app/settings/automation.ts
+++ b/src/app/settings/automation.ts
@@ -15,6 +15,7 @@ import {
updateDesignCheckPreferences,
type AppPreferences
} from '@/app/settings/preferences/store'
+import { accentPreferenceSchema } from '@/app/shell/accent/palette'
import { APP_THEMES, getAppTheme, setAppTheme, type AppTheme } from '@/app/shell/theme'
/**
@@ -27,6 +28,7 @@ export interface AutomationSettings {
theme: AppTheme
language: Locale
animations: AppPreferences['appearance']['animations']
+ accent: AppPreferences['appearance']['accent']
}
editing: AppPreferences['editing']
rendering: AppPreferences['rendering']
@@ -42,7 +44,8 @@ export const automationSettingsPatchSchema = v.strictObject({
v.strictObject({
theme: v.optional(v.picklist(APP_THEMES)),
language: v.optional(v.picklist(AVAILABLE_LOCALES)),
- animations: v.optional(v.picklist(ANIMATION_PREFERENCES))
+ animations: v.optional(v.picklist(ANIMATION_PREFERENCES)),
+ accent: v.optional(accentPreferenceSchema)
})
),
editing: v.optional(
@@ -85,7 +88,8 @@ export function readAutomationSettings(): AutomationSettings {
appearance: {
theme: getAppTheme(),
language: locale.get(),
- animations: preferences.appearance.animations
+ animations: preferences.appearance.animations,
+ accent: { ...preferences.appearance.accent }
},
editing: { snapping: { ...preferences.editing.snapping } },
rendering: { ...preferences.rendering },
diff --git a/src/app/settings/preferences/store.ts b/src/app/settings/preferences/store.ts
index 7199ce1b4..2b03b40ce 100644
--- a/src/app/settings/preferences/store.ts
+++ b/src/app/settings/preferences/store.ts
@@ -5,6 +5,11 @@ import * as v from 'valibot'
import { DEFAULT_SNAPPING_PREFERENCES, type SnappingPreferences } from '@open-pencil/core/editor'
import { DEFAULT_AGENT_STEPS, resolveAgentStepLimit } from '@/app/ai/chat/step-limit'
+import {
+ accentPreferenceSchema,
+ DEFAULT_ACCENT,
+ type AccentPreference
+} from '@/app/shell/accent/palette'
export const ANIMATION_PREFERENCES = ['system', 'off'] as const
export type AnimationPreference = (typeof ANIMATION_PREFERENCES)[number]
@@ -35,7 +40,7 @@ export const AI_SETUP_STATES = ['pending', 'done'] as const
export type AISetupState = (typeof AI_SETUP_STATES)[number]
export interface AppPreferences {
- appearance: { animations: AnimationPreference }
+ appearance: { animations: AnimationPreference; accent: AccentPreference }
chat: {
reasoningDisplay: ReasoningDisplay
maxAgentSteps: number
@@ -60,7 +65,7 @@ export interface AppPreferences {
}
export const DEFAULT_APP_PREFERENCES: Readonly<AppPreferences> = {
- appearance: { animations: 'system' },
+ appearance: { animations: 'system', accent: { ...DEFAULT_ACCENT } },
chat: {
reasoningDisplay: 'collapsed',
maxAgentSteps: DEFAULT_AGENT_STEPS,
@@ -91,7 +96,8 @@ const snapping = defaults.editing.snapping
/** Stored preferences, read field by field so one bad value keeps the rest. */
const appPreferencesSchema = section({
appearance: section({
- animations: v.fallback(v.picklist(ANIMATION_PREFERENCES), defaults.appearance.animations)
+ animations: v.fallback(v.picklist(ANIMATION_PREFERENCES), defaults.appearance.animations),
+ accent: v.fallback(accentPreferenceSchema, () => ({ ...DEFAULT_ACCENT }))
}),
chat: section({
reasoningDisplay: v.fallback(v.picklist(REASONING_DISPLAYS), defaults.chat.reasoningDisplay),
@@ -145,7 +151,17 @@ export const appPreferences = useLocalStorage<AppPreferences>(
)
export function updateAnimationPreference(animations: AnimationPreference): void {
- appPreferences.value = { ...appPreferences.value, appearance: { animations } }
+ appPreferences.value = {
+ ...appPreferences.value,
+ appearance: { ...appPreferences.value.appearance, animations }
+ }
+}
+
+export function updateAccentPreference(accent: AccentPreference): void {
+ appPreferences.value = {
+ ...appPreferences.value,
+ appearance: { ...appPreferences.value.appearance, accent }
+ }
}
export function updateRecoveryEnabled(enabled: boolean): void {
diff --git a/src/app/shell/accent/index.ts b/src/app/shell/accent/index.ts
new file mode 100644
index 000000000..f80a9d969
--- /dev/null
+++ b/src/app/shell/accent/index.ts
@@ -0,0 +1,15 @@
+import { computed } from 'vue'
+
+import { appPreferences, updateAccentPreference } from '@/app/settings/preferences/store'
+
+import { accentBaseColor, deriveAccentPalette, type AccentTheme } from './palette'
+
+export const accentPreference = computed({
+ get: () => appPreferences.value.appearance.accent,
+ set: updateAccentPreference
+})
+
+/** The accent family for the resolved interface theme. */
+export function useAccentPalette(theme: () => AccentTheme) {
+ return computed(() => deriveAccentPalette(accentBaseColor(accentPreference.value), theme()))
+}
diff --git a/src/app/shell/accent/palette.ts b/src/app/shell/accent/palette.ts
new file mode 100644
index 000000000..c37587af8
--- /dev/null
+++ b/src/app/shell/accent/palette.ts
@@ -0,0 +1,200 @@
+import { maxBy } from 'es-toolkit'
+import * as v from 'valibot'
+
+import type { SelectionTheme } from '@open-pencil/core/canvas'
+import { SELECTION_COLOR } from '@open-pencil/core/constants'
+import {
+ colorToHex,
+ contrastRatio,
+ okhclToRGBA,
+ parseColor,
+ rgbaToOkHCL
+} from '@open-pencil/scene-graph/color'
+import { WHITE } from '@open-pencil/scene-graph/constants'
+import type { Color } from '@open-pencil/scene-graph/primitives'
+
+export const ACCENT_PRESETS = [
+ 'blue',
+ 'purple',
+ 'pink',
+ 'red',
+ 'orange',
+ 'yellow',
+ 'green',
+ 'graphite'
+] as const
+export type AccentPreset = (typeof ACCENT_PRESETS)[number]
+
+/** A named accent, or any color the user picked, stored as `#RRGGBB`. */
+export const accentPreferenceSchema = v.variant('kind', [
+ v.object({ kind: v.literal('preset'), preset: v.picklist(ACCENT_PRESETS) }),
+ v.object({
+ kind: v.literal('custom'),
+ color: v.pipe(v.string(), v.hexColor(), v.length(7), v.toUpperCase())
+ })
+])
+export type AccentPreference = v.InferOutput<typeof accentPreferenceSchema>
+
+export const DEFAULT_ACCENT: Readonly<AccentPreference> = { kind: 'preset', preset: 'blue' }
+
+/** Base colors dark enough that white text reads on every accent surface in both themes. */
+export const ACCENT_PRESET_COLORS: Readonly<Record<AccentPreset, string>> = {
+ blue: '#2563EB',
+ purple: '#9333EA',
+ pink: '#BE185D',
+ red: '#B91C1C',
+ orange: '#C2410C',
+ yellow: '#A16207',
+ green: '#15803D',
+ graphite: '#52525B'
+}
+
+export type AccentTheme = 'dark' | 'light'
+
+/** The interface tokens an accent recolors, by CSS custom property. */
+export const ACCENT_TOKENS = [
+ '--color-accent',
+ '--color-panel-focus',
+ '--color-panel-selected',
+ '--color-panel-selected-muted',
+ '--color-primary',
+ '--color-on-accent',
+ '--color-on-primary'
+] as const
+export type AccentToken = (typeof ACCENT_TOKENS)[number]
+
+type DerivedToken = Exclude<AccentToken, '--color-on-accent' | '--color-on-primary'>
+
+/**
+ * The default blue family as `src/app.css` defines it. Every other accent keeps each token's
+ * lightness, chroma and hue relation to the base, so a new accent looks like the default one.
+ */
+const REFERENCE_BASE = parseColor(ACCENT_PRESET_COLORS.blue)
+const REFERENCE_TOKENS: Readonly<Record<AccentTheme, Readonly<Record<DerivedToken, string>>>> = {
+ dark: {
+ '--color-accent': '#2563EB',
+ '--color-panel-focus': '#3B82F6',
+ '--color-panel-selected': '#2F6FDD',
+ '--color-panel-selected-muted': '#353B46',
+ '--color-primary': '#60A5FA'
+ },
+ light: {
+ '--color-accent': '#2563EB',
+ '--color-panel-focus': '#2563EB',
+ '--color-panel-selected': '#2563EB',
+ '--color-panel-selected-muted': '#E5E7EB',
+ '--color-primary': '#1D4ED8'
+ }
+}
+
+/** Lightness band a base is held in, so a near-black or near-white pick still shows its controls. */
+export const ACCENT_LIGHTNESS_RANGE = { min: 0.4, max: 0.75 } as const
+
+/** WCAG AA contrast for normal text, which every accent's text keeps against its surface. */
+export const ACCENT_TEXT_CONTRAST = 4.5
+
+/** Lightness steps tried, nearest first, when a color's text would fall short of that contrast. */
+const LIGHTNESS_SHIFTS = Array.from({ length: 61 }, (_, index) =>
+ index % 2 === 0 ? index / 2 / 200 : -(index + 1) / 2 / 200
+)
+
+/** The interface's dark text, `--color-inverted` in the dark theme and `--color-surface` in light. */
+const INK = parseColor('#1F2328')
+
+export interface AccentPalette {
+ /** Hex values for each recolored CSS custom property. */
+ tokens: Record<AccentToken, string>
+ /** Canvas selection chrome, the same in both themes, with the interface's accent text color. */
+ selection: SelectionTheme
+}
+
+export function accentBaseColor(preference: AccentPreference): Color {
+ if (preference.kind === 'preset') return parseColor(ACCENT_PRESET_COLORS[preference.preset])
+ return parseColor(preference.color)
+}
+
+function clampLightness(lightness: number): number {
+ return Math.min(ACCENT_LIGHTNESS_RANGE.max, Math.max(ACCENT_LIGHTNESS_RANGE.min, lightness))
+}
+
+/**
+ * Moves a reference token the way `base` differs from the default blue, in OkLCH, plus `shift`
+ * in lightness. A tint keeps its own lightness, since it is a shade of the panel behind it rather
+ * than of the accent.
+ */
+function relateTo(base: Color, shift: number): (reference: Color, tint?: boolean) => Color {
+ const from = rgbaToOkHCL(REFERENCE_BASE)
+ const to = rgbaToOkHCL(base)
+ const lightness = clampLightness(to.l) - from.l + shift
+ const chroma = to.c / from.c
+ const hue = to.h - from.h
+ return (reference, tint = false) => {
+ const color = rgbaToOkHCL(reference)
+ const related = okhclToRGBA({
+ l: tint ? color.l : color.l + lightness,
+ c: color.c * chroma,
+ h: color.h + hue,
+ a: 1
+ })
+ // Rounded to the hex the stylesheet receives, so contrast is checked on what is drawn.
+ return parseColor(colorToHex(related))
+ }
+}
+
+function worstContrast(text: Color, surfaces: Color[]): number {
+ return Math.min(...surfaces.map((surface) => contrastRatio(text, surface)))
+}
+
+/** White or ink, whichever reads worst-case better on every surface the text sits on. */
+function accentForeground(surfaces: Color[]): Color {
+ return maxBy([WHITE, INK], (text) => worstContrast(text, surfaces))
+}
+
+function surfaces(base: Color, theme: AccentTheme, shift: number) {
+ const relate = relateTo(base, shift)
+ const reference = REFERENCE_TOKENS[theme]
+ return {
+ relate,
+ reference,
+ accent: relate(parseColor(reference['--color-accent'])),
+ selected: relate(parseColor(reference['--color-panel-selected'])),
+ primary: relate(parseColor(reference['--color-primary']))
+ }
+}
+
+/** How readable a family's text is: the lower of its accent and primary text contrasts. */
+function textContrast({ accent, selected, primary }: ReturnType<typeof surfaces>): number {
+ const accentSurfaces = [accent, selected]
+ return Math.min(
+ worstContrast(accentForeground(accentSurfaces), accentSurfaces),
+ worstContrast(accentForeground([primary]), [primary])
+ )
+}
+
+/**
+ * The accent family for `theme`, derived from one base color. When its text would fall short of
+ * {@link ACCENT_TEXT_CONTRAST}, the family moves by the smallest lightness shift that reaches it.
+ */
+export function deriveAccentPalette(base: Color, theme: AccentTheme): AccentPalette {
+ const families = LIGHTNESS_SHIFTS.map((shift) => surfaces(base, theme, shift))
+ const family =
+ families.find((candidate) => textContrast(candidate) >= ACCENT_TEXT_CONTRAST) ??
+ maxBy(families, textContrast) ??
+ surfaces(base, theme, 0)
+ const { relate, reference, accent, selected, primary } = family
+ const foreground = accentForeground([accent, selected])
+ return {
+ tokens: {
+ '--color-accent': colorToHex(accent),
+ '--color-panel-focus': colorToHex(relate(parseColor(reference['--color-panel-focus']))),
+ '--color-panel-selected': colorToHex(selected),
+ '--color-panel-selected-muted': colorToHex(
+ relate(parseColor(reference['--color-panel-selected-muted']), true)
+ ),
+ '--color-primary': colorToHex(primary),
+ '--color-on-accent': colorToHex(foreground),
+ '--color-on-primary': colorToHex(accentForeground([primary]))
+ },
+ selection: { color: relate(SELECTION_COLOR), foreground }
+ }
+}
diff --git a/src/app/shell/theme.ts b/src/app/shell/theme.ts
index 21bb40d91..78c39145b 100644
--- a/src/app/shell/theme.ts
+++ b/src/app/shell/theme.ts
@@ -6,6 +6,8 @@ import { IS_BROWSER } from '@open-pencil/core/constants'
import { parseColor } from '@open-pencil/scene-graph/color'
import { getActiveEditorStoreOrNull, useActiveEditorStoreRef } from '@/app/editor/active-store'
+import { useAccentPalette } from '@/app/shell/accent'
+import { ACCENT_TOKENS, type AccentPalette } from '@/app/shell/accent/palette'
export const APP_THEMES = ['dark', 'light', 'auto'] as const
export type AppTheme = (typeof APP_THEMES)[number]
@@ -15,10 +17,12 @@ const DEFAULT_THEME: AppTheme = 'dark'
const theme = useLocalStorage<AppTheme>(THEME_STORAGE_KEY, DEFAULT_THEME)
const prefersDark = usePreferredDark()
+/** The theme in effect; a stored value that is not a theme reads as the default dark. */
export const resolvedAppTheme = computed<'dark' | 'light'>(() => {
if (theme.value === 'auto') return prefersDark.value ? 'dark' : 'light'
- return theme.value
+ return theme.value === 'light' ? 'light' : 'dark'
})
+const accentPalette = useAccentPalette(() => resolvedAppTheme.value)
function readRulerTheme(): RulerTheme | null {
if (!IS_BROWSER || !('document' in globalThis)) return null
@@ -26,8 +30,7 @@ function readRulerTheme(): RulerTheme | null {
return {
background: parseColor(style.getPropertyValue('--color-ruler-bg')),
tick: parseColor(style.getPropertyValue('--color-ruler-tick')),
- text: parseColor(style.getPropertyValue('--color-ruler-text')),
- label: parseColor(style.getPropertyValue('--color-ruler-label'))
+ text: parseColor(style.getPropertyValue('--color-ruler-text'))
}
}
@@ -37,6 +40,7 @@ function updateCanvasTheme(): void {
if (!store) return
store.state.rulerTheme = readRulerTheme() ?? undefined
store.state.theme = resolvedAppTheme.value
+ store.state.selectionTheme = accentPalette.value.selection
store.requestRepaint()
}
@@ -48,23 +52,33 @@ export function setAppTheme(value: AppTheme): void {
theme.value = value
}
+function applyAccent(palette: AccentPalette): void {
+ const style = document.documentElement.style
+ for (const token of ACCENT_TOKENS) style.setProperty(token, palette.tokens[token])
+}
+
function applyTheme(value: 'dark' | 'light', setting: AppTheme): void {
if (!IS_BROWSER || !('document' in globalThis)) return
document.documentElement.dataset.theme = value
document.documentElement.dataset.themeSetting = setting
document.documentElement.style.colorScheme = value
+ applyAccent(accentPalette.value)
updateCanvasTheme()
}
export function useAppTheme() {
- watch([resolvedAppTheme, theme], ([value, setting]) => applyTheme(value, setting), {
- immediate: true
- })
+ watch(
+ [resolvedAppTheme, theme, accentPalette],
+ ([value, setting]) => applyTheme(value, setting),
+ { immediate: true }
+ )
// Editors may mount after the theme was applied; push the canvas (ruler)
// theme whenever the active editor changes so rulers always match.
const activeStoreRef = useActiveEditorStoreRef()
- watch([activeStoreRef, resolvedAppTheme], () => updateCanvasTheme(), { flush: 'post' })
+ watch([activeStoreRef, resolvedAppTheme, accentPalette], () => updateCanvasTheme(), {
+ flush: 'post'
+ })
const isLight = computed(() => resolvedAppTheme.value === 'light')
diff --git a/src/components/assets-panel/AssetsPanel.vue b/src/components/assets-panel/AssetsPanel.vue
index 9a5645b64..bca1d6b9c 100644
--- a/src/components/assets-panel/AssetsPanel.vue
+++ b/src/components/assets-panel/AssetsPanel.vue
@@ -341,7 +341,7 @@ async function insertSelectedAsset() {
<icon-lucide-library class="size-3.5" />
<span
v-if="libraryUpdateCount > 0"
- class="absolute top-0.5 right-0.5 min-w-2.5 rounded-full bg-accent px-0.5 text-center text-[8px] leading-2.5 text-white"
+ class="absolute top-0.5 right-0.5 min-w-2.5 rounded-full bg-accent px-0.5 text-center text-[8px] leading-2.5 text-on-accent"
>
{{ libraryUpdateCount }}
</span>
diff --git a/src/components/chat/ACPPermissionDialog.vue b/src/components/chat/ACPPermissionDialog.vue
index 89eb6c241..a43d9a8d9 100644
--- a/src/components/chat/ACPPermissionDialog.vue
+++ b/src/components/chat/ACPPermissionDialog.vue
@@ -78,7 +78,7 @@ function handleDismiss() {
v-for="opt in allowOptions"
:key="opt.optionId"
v-test-id="acpPermissionOptionTestId(opt.kind)"
- class="w-full rounded bg-accent px-3 py-1.5 text-xs font-medium text-white hover:bg-accent/90"
+ class="w-full rounded bg-accent px-3 py-1.5 text-xs font-medium text-on-accent hover:bg-accent/90"
@click="respondToPermission(opt.optionId)"
>
{{ opt.name }}
diff --git a/src/components/chat/ChatComposer.vue b/src/components/chat/ChatComposer.vue
index c91950eae..a53f44611 100644
--- a/src/components/chat/ChatComposer.vue
+++ b/src/components/chat/ChatComposer.vue
@@ -97,7 +97,7 @@ defineExpose({ restoreDraft })
size="sm"
type="submit"
data-test-id="chat-send-button"
- class="bg-accent text-white hover:bg-accent/90 hover:text-white"
+ class="bg-accent text-on-accent hover:bg-accent/90 hover:text-on-accent"
:disabled="!input.trim()"
>
<icon-lucide-send class="size-3.5" />
diff --git a/src/components/chat/ChatMessage.vue b/src/components/chat/ChatMessage.vue
index 8f6fcd564..fba4e15cb 100644
--- a/src/components/chat/ChatMessage.vue
+++ b/src/components/chat/ChatMessage.vue
@@ -173,7 +173,7 @@ function groupKey(group: MessagePartGroup): string {
<div v-else class="group/request relative">
<div
data-test-id="chat-text-bubble"
- class="rounded-xl rounded-br-md bg-accent px-3 py-2 text-xs leading-relaxed whitespace-pre-wrap text-white"
+ class="rounded-xl rounded-br-md bg-accent px-3 py-2 text-xs leading-relaxed whitespace-pre-wrap text-on-accent"
>
{{ userText }}
</div>
diff --git a/src/components/font-picker/FontPicker.vue b/src/components/font-picker/FontPicker.vue
index 15eb51ae1..f9e962025 100644
--- a/src/components/font-picker/FontPicker.vue
+++ b/src/components/font-picker/FontPicker.vue
@@ -36,7 +36,8 @@ const ui = computed<FontPickerUI>(() => ({
search:
'w-full border-b border-border bg-transparent px-3 py-2 text-sm text-surface outline-none placeholder:text-muted',
empty: 'px-2 py-3 text-center text-xs text-muted',
- emptyAction: 'mt-2 rounded bg-accent px-2 py-1 text-xs font-medium text-white disabled:opacity-50'
+ emptyAction:
+ 'mt-2 rounded bg-accent px-2 py-1 text-xs font-medium text-on-accent disabled:opacity-50'
}))
const previewFontLoads = new Set<string>()
diff --git a/src/components/libraries/LibraryManagerDialog.vue b/src/components/libraries/LibraryManagerDialog.vue
index f4c201cb0..c2162ff83 100644
--- a/src/components/libraries/LibraryManagerDialog.vue
+++ b/src/components/libraries/LibraryManagerDialog.vue
@@ -90,7 +90,7 @@ function reviewUpdate(group: (typeof visibleUpdateGroups.value)[number]) {
<template #leading><icon-lucide-refresh-cw class="size-3.5" /></template>
{{ panels.libraryUpdates }}
<template v-if="visibleUpdateGroups.length" #trailing>
- <span class="rounded-full bg-accent px-1.5 text-[10px] text-white">{{
+ <span class="rounded-full bg-accent px-1.5 text-[10px] text-on-accent">{{
visibleUpdateGroups.length
}}</span>
</template>
diff --git a/src/components/settings/general/AccentColorPicker.stories.ts b/src/components/settings/general/AccentColorPicker.stories.ts
new file mode 100644
index 000000000..098bf49ef
--- /dev/null
+++ b/src/components/settings/general/AccentColorPicker.stories.ts
@@ -0,0 +1,49 @@
+import type { Meta, StoryObj } from '@storybook/vue3-vite'
+import { expect, userEvent, within } from 'storybook/test'
+import { onUnmounted } from 'vue'
+
+import { accentPreference } from '@/app/shell/accent'
+import { DEFAULT_ACCENT, type AccentPreference } from '@/app/shell/accent/palette'
+
+import AccentColorPicker from './AccentColorPicker.vue'
+
+type Args = { accent: AccentPreference }
+
+const meta = {
+ title: 'App/Settings/Accent Color',
+ args: { accent: { ...DEFAULT_ACCENT } },
+ render: (args) => ({
+ components: { AccentColorPicker },
+ setup() {
+ // The picker edits the app's stored accent; each story sets it and puts the default back.
+ accentPreference.value = { ...args.accent }
+ onUnmounted(() => {
+ accentPreference.value = { ...DEFAULT_ACCENT }
+ })
+ return {}
+ },
+ template: '<div class="flex max-w-lg justify-end bg-panel p-4"><AccentColorPicker /></div>'
+ })
+} satisfies Meta<Args>
+export default meta
+type Story = StoryObj<typeof meta>
+
+export const Preset: Story = {}
+
+export const Custom: Story = {
+ args: { accent: { kind: 'custom', color: '#0F766E' } }
+}
+
+export const ChoosingAPreset: Story = {
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement)
+ const presets = canvas.getByRole('radiogroup')
+ const [, second] = within(presets).getAllByRole('radio')
+ await userEvent.click(second)
+ await expect(second).toHaveAttribute('data-state', 'checked')
+ await expect(canvas.getByTestId('settings-accent-custom')).toHaveAttribute(
+ 'aria-pressed',
+ 'false'
+ )
+ }
+}
diff --git a/src/components/settings/general/AccentColorPicker.vue b/src/components/settings/general/AccentColorPicker.vue
new file mode 100644
index 000000000..fb9886d6d
--- /dev/null
+++ b/src/components/settings/general/AccentColorPicker.vue
@@ -0,0 +1,108 @@
+<script setup lang="ts">
+import { RadioGroupItem, RadioGroupRoot } from 'reka-ui'
+import { tv } from 'tailwind-variants'
+import { computed, shallowRef } from 'vue'
+
+import { colorToHex } from '@open-pencil/scene-graph/color'
+import type { Color } from '@open-pencil/scene-graph/primitives'
+import { useSettingsMessages } from '@open-pencil/vue'
+
+import { accentPreference } from '@/app/shell/accent'
+import {
+ ACCENT_PRESET_COLORS,
+ ACCENT_PRESETS,
+ accentBaseColor,
+ type AccentPreference,
+ type AccentPreset
+} from '@/app/shell/accent/palette'
+import ColorPicker from '@/components/ColorPicker/ColorPicker.vue'
+import Tip from '@/components/ui/overlay/Tip.vue'
+import theme from '@/theme/settings/accent'
+
+const messages = useSettingsMessages()
+const styles = tv(theme)()
+
+const presetLabels = computed<Record<AccentPreset, string>>(() => ({
+ blue: messages.value.accentBlue,
+ purple: messages.value.accentPurple,
+ pink: messages.value.accentPink,
+ red: messages.value.accentRed,
+ orange: messages.value.accentOrange,
+ yellow: messages.value.accentYellow,
+ green: messages.value.accentGreen,
+ graphite: messages.value.accentGraphite
+}))
+
+const selectedPreset = computed(() =>
+ accentPreference.value.kind === 'preset' ? accentPreference.value.preset : undefined
+)
+const custom = computed(() => accentPreference.value.kind === 'custom')
+const customBackground = computed(() =>
+ accentPreference.value.kind === 'custom' ? accentPreference.value.color : undefined
+)
+const customColor = computed(() => accentBaseColor(accentPreference.value))
+
+function selectPreset(value: unknown): void {
+ const preset = ACCENT_PRESETS.find((candidate) => candidate === value)
+ if (preset) accentPreference.value = { kind: 'preset', preset }
+}
+
+/** The accent before the custom picker opened, restored when the edit is cancelled. */
+const beforeEdit = shallowRef<AccentPreference | null>(null)
+
+function onPickerOpenChange(open: boolean): void {
+ if (open) beforeEdit.value = { ...accentPreference.value }
+ else beforeEdit.value = null
+}
+
+function onCustomColor(color: Color): void {
+ accentPreference.value = { kind: 'custom', color: colorToHex(color) }
+}
+
+function onCancel(): void {
+ if (beforeEdit.value) accentPreference.value = beforeEdit.value
+}
+</script>
+
+<template>
+ <div :class="styles.root()" data-test-id="settings-accent">
+ <RadioGroupRoot
+ :model-value="selectedPreset"
+ :aria-label="messages.accentColor"
+ orientation="horizontal"
+ :class="styles.presets()"
+ @update:model-value="selectPreset"
+ >
+ <Tip v-for="preset in ACCENT_PRESETS" :key="preset" as-child :label="presetLabels[preset]">
+ <RadioGroupItem
+ :value="preset"
+ :aria-label="presetLabels[preset]"
+ :data-test-id="`settings-accent-${preset}`"
+ :class="styles.swatch()"
+ :style="{ background: ACCENT_PRESET_COLORS[preset] }"
+ />
+ </Tip>
+ </RadioGroupRoot>
+
+ <Tip :label="messages.accentCustom">
+ <ColorPicker
+ :color="customColor"
+ @update="onCustomColor"
+ @open-change="onPickerOpenChange"
+ @cancel="onCancel"
+ >
+ <template #trigger>
+ <button
+ type="button"
+ :aria-label="messages.accentCustom"
+ :aria-pressed="custom"
+ :data-active="custom"
+ data-test-id="settings-accent-custom"
+ :class="styles.custom()"
+ :style="{ background: customBackground }"
+ />
+ </template>
+ </ColorPicker>
+ </Tip>
+ </div>
+</template>
diff --git a/src/components/settings/general/GeneralSettingsPanel.vue b/src/components/settings/general/GeneralSettingsPanel.vue
index c17e569b5..c7727b1f3 100644
--- a/src/components/settings/general/GeneralSettingsPanel.vue
+++ b/src/components/settings/general/GeneralSettingsPanel.vue
@@ -9,6 +9,7 @@ import { appPreferences } from '@/app/settings/preferences/store'
import { animationPreference } from '@/app/shell/motion'
import { useAppTheme } from '@/app/shell/theme'
import CredentialSettingsSection from '@/components/settings/credentials/CredentialSettingsSection.vue'
+import AccentColorPicker from '@/components/settings/general/AccentColorPicker.vue'
import CollaborationNameSection from '@/components/settings/general/CollaborationNameSection.vue'
import RenderingSettingsSection from '@/components/settings/general/RenderingSettingsSection.vue'
import SettingsGroup from '@/components/settings/layout/SettingsGroup.vue'
@@ -87,6 +88,10 @@ const snapToPixelGrid = computed({
:ui="selectUI"
/>
</label>
+ <div class="flex flex-wrap items-center justify-between gap-x-4 gap-y-2 px-3 py-2.5">
+ <span class="text-xs text-surface">{{ settings.accentColor }}</span>
+ <AccentColorPicker />
+ </div>
<label class="flex items-center justify-between gap-4 px-3 py-2.5">
<span class="text-xs text-surface">{{ settings.animations }}</span>
<AppSelect
diff --git a/src/components/ui/button/button.ts b/src/components/ui/button/button.ts
index 4e6effcd0..a65b77b9e 100644
--- a/src/components/ui/button/button.ts
+++ b/src/components/ui/button/button.ts
@@ -6,7 +6,7 @@ const button = tv({
variants: {
tone: {
ghost: 'bg-transparent text-muted hover:bg-hover hover:text-surface',
- accent: 'bg-accent text-white hover:bg-accent/90',
+ accent: 'bg-accent text-on-accent hover:bg-accent/90',
panel: 'bg-panel/70 text-surface backdrop-blur-xl',
panelAccent: 'border-accent/20 bg-panel/70 text-primary backdrop-blur-xl'
},
diff --git a/src/components/ui/toggle/AppCheckbox.vue b/src/components/ui/toggle/AppCheckbox.vue
index bbe17a632..c4ff1a560 100644
--- a/src/components/ui/toggle/AppCheckbox.vue
+++ b/src/components/ui/toggle/AppCheckbox.vue
@@ -29,7 +29,7 @@ const emit = defineEmits<{ 'update:modelValue': [value: boolean] }>()
:aria-labelledby="ariaLabelledby"
:aria-describedby="ariaDescribedby"
:disabled="disabled"
- class="flex size-4 shrink-0 items-center justify-center rounded border border-border bg-panel-field text-white outline-none transition-colors hover:border-accent/60 data-[state=checked]:border-accent data-[state=checked]:bg-accent data-[state=indeterminate]:border-accent data-[state=indeterminate]:bg-accent focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-50"
+ class="flex size-4 shrink-0 items-center justify-center rounded border border-border bg-panel-field text-on-accent outline-none transition-colors hover:border-accent/60 data-[state=checked]:border-accent data-[state=checked]:bg-accent data-[state=indeterminate]:border-accent data-[state=indeterminate]:bg-accent focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-50"
@update:model-value="(value) => emit('update:modelValue', value === true)"
>
<CheckboxIndicator class="flex items-center justify-center">
diff --git a/src/theme/button/button.ts b/src/theme/button/button.ts
index afb024a35..0b14cd4f3 100644
--- a/src/theme/button/button.ts
+++ b/src/theme/button/button.ts
@@ -69,7 +69,7 @@ const appButton = tv({
{
color: 'primary',
variant: 'solid',
- class: { base: 'bg-primary text-inverted hover:bg-primary/90' }
+ class: { base: 'bg-primary text-on-primary hover:bg-primary/90' }
},
{
color: 'primary',
diff --git a/src/theme/collaboration/share-button.ts b/src/theme/collaboration/share-button.ts
index e4e6acf4f..4a067ecd4 100644
--- a/src/theme/collaboration/share-button.ts
+++ b/src/theme/collaboration/share-button.ts
@@ -4,11 +4,11 @@ export const shareButton = tv({
base: 'flex h-7 cursor-pointer items-center gap-1.5 rounded border-none px-3 text-[11px] font-medium transition-colors outline-none focus-visible:ring-1 focus-visible:ring-panel-focus',
variants: {
connection: {
- idle: 'bg-accent text-white hover:bg-accent/90',
+ idle: 'bg-accent text-on-accent hover:bg-accent/90',
joining:
'animate-pulse motion-reduce:animate-none border border-[var(--color-warning-border)] bg-[var(--color-warning-bg)] text-[var(--color-warning-text)]',
// Still a share action when connected; your avatar shows the room is live.
- connected: 'bg-accent text-white hover:bg-accent/90'
+ connected: 'bg-accent text-on-accent hover:bg-accent/90'
}
},
defaultVariants: { connection: 'idle' }
diff --git a/src/theme/feedback/toast.ts b/src/theme/feedback/toast.ts
index b0a63dcf5..6400771ab 100644
--- a/src/theme/feedback/toast.ts
+++ b/src/theme/feedback/toast.ts
@@ -15,7 +15,7 @@ const toastTheme = {
},
variants: {
tone: {
- default: { root: 'bg-accent text-white', action: 'bg-black/20 hover:bg-black/30' },
+ default: { root: 'bg-accent text-on-accent', action: 'bg-black/20 hover:bg-black/30' },
warning: {
root: 'border border-[var(--color-warning-border)] bg-[var(--color-warning-bg)] text-[var(--color-warning-text)]',
action: 'bg-current/10 hover:bg-current/15'
diff --git a/src/theme/layer-tree.ts b/src/theme/layer-tree.ts
index 3790a807f..3c9de1c7f 100644
--- a/src/theme/layer-tree.ts
+++ b/src/theme/layer-tree.ts
@@ -19,7 +19,7 @@ const layerTreeTheme = {
},
variants: {
selected: {
- true: { row: 'bg-panel-selected text-white hover:bg-panel-selected' },
+ true: { row: 'bg-panel-selected text-on-accent hover:bg-panel-selected' },
false: { row: 'bg-transparent text-surface hover:bg-hover' }
},
focused: {
@@ -76,7 +76,7 @@ const layerTreeTheme = {
{
selected: true,
focused: true,
- class: { icon: 'text-white opacity-100' }
+ class: { icon: 'text-on-accent opacity-100' }
},
{
selected: true,
diff --git a/src/theme/settings/accent.ts b/src/theme/settings/accent.ts
new file mode 100644
index 000000000..bd8ec6706
--- /dev/null
+++ b/src/theme/settings/accent.ts
@@ -0,0 +1,11 @@
+/** Accent color swatches in Settings › General › Appearance. */
+export default {
+ slots: {
+ root: 'flex shrink-0 items-center gap-2',
+ presets: 'flex items-center gap-2',
+ swatch:
+ 'size-5 shrink-0 cursor-pointer rounded-full border border-black/15 p-0 outline-none ring-offset-2 ring-offset-panel transition-shadow focus-visible:ring-2 focus-visible:ring-panel-focus data-[state=checked]:ring-2 data-[state=checked]:ring-surface',
+ custom:
+ 'size-5 shrink-0 cursor-pointer rounded-full border border-black/15 p-0 outline-none ring-offset-2 ring-offset-panel transition-shadow focus-visible:ring-2 focus-visible:ring-panel-focus data-[active=true]:ring-2 data-[active=true]:ring-surface data-[active=false]:bg-[conic-gradient(from_180deg,#ef4444,#eab308,#22c55e,#06b6d4,#3b82f6,#a855f7,#ef4444)]'
+ }
+}
diff --git a/src/theme/toolbar.ts b/src/theme/toolbar.ts
index 2674c6eff..2b65518b3 100644
--- a/src/theme/toolbar.ts
+++ b/src/theme/toolbar.ts
@@ -22,7 +22,7 @@ const toolbarTheme = {
variants: {
active: {
true: {
- button: 'bg-accent text-white'
+ button: 'bg-accent text-on-accent'
},
false: {}
},
diff --git a/tests/app/settings/automation.test.ts b/tests/app/settings/automation.test.ts
index 37fef2f17..e3f0a6675 100644
--- a/tests/app/settings/automation.test.ts
+++ b/tests/app/settings/automation.test.ts
@@ -32,7 +32,8 @@ test('reads appearance from the theme and locale stores alongside app preference
expect(settings.appearance).toEqual({
theme: 'light',
language: 'de',
- animations: appPreferences.value.appearance.animations
+ animations: appPreferences.value.appearance.animations,
+ accent: appPreferences.value.appearance.accent
})
expect(settings.editing).toEqual(appPreferences.value.editing)
expect(settings).not.toHaveProperty('version')
@@ -81,3 +82,18 @@ test.each([
expect(() => updateAutomationSettings(patch)).toThrow(`Invalid settings at "${path}"`)
expect(readAutomationSettings()).toEqual(before)
})
+
+test('sets a preset or custom accent and rejects one that is not a color', () => {
+ expect(
+ updateAutomationSettings({ appearance: { accent: { kind: 'preset', preset: 'purple' } } })
+ .appearance.accent
+ ).toEqual({ kind: 'preset', preset: 'purple' })
+ expect(
+ updateAutomationSettings({ appearance: { accent: { kind: 'custom', color: '#ff6600' } } })
+ .appearance.accent
+ ).toEqual({ kind: 'custom', color: '#FF6600' })
+ expect(() =>
+ updateAutomationSettings({ appearance: { accent: { kind: 'custom', color: 'orange' } } })
+ ).toThrow('appearance.accent')
+ expect(appPreferences.value.appearance.accent).toEqual({ kind: 'custom', color: '#FF6600' })
+})
diff --git a/tests/app/settings/preferences/store.test.ts b/tests/app/settings/preferences/store.test.ts
index 64178efd8..093b85224 100644
--- a/tests/app/settings/preferences/store.test.ts
+++ b/tests/app/settings/preferences/store.test.ts
@@ -39,6 +39,26 @@ describe('parseAppPreferences', () => {
})
})
+ test('keeps a preset or a custom accent and falls back to blue for anything else', () => {
+ const accent = (value: unknown) =>
+ parseAppPreferences({ appearance: { accent: value } }).appearance.accent
+ expect(accent({ kind: 'preset', preset: 'green' })).toEqual({ kind: 'preset', preset: 'green' })
+ expect(accent({ kind: 'custom', color: '#ff6600' })).toEqual({
+ kind: 'custom',
+ color: '#FF6600'
+ })
+ for (const invalid of [
+ { kind: 'preset', preset: 'teal' },
+ { kind: 'custom', color: 'orange' },
+ { kind: 'custom', color: '#f60' },
+ '#ff6600'
+ ]) {
+ expect(accent(invalid)).toEqual(DEFAULT_APP_PREFERENCES.appearance.accent)
+ }
+ const preferences = parseAppPreferences({ appearance: { animations: 'off', accent: 'teal' } })
+ expect(preferences.appearance.animations).toBe('off')
+ })
+
test('remembers that guided AI setup was finished or skipped', () => {
expect(parseAppPreferences({ onboarding: { aiSetup: 'done' } }).onboarding.aiSetup).toBe('done')
expect(parseAppPreferences({ onboarding: { aiSetup: 'later' } }).onboarding.aiSetup).toBe(
diff --git a/tests/app/shell/accent/palette.test.ts b/tests/app/shell/accent/palette.test.ts
new file mode 100644
index 000000000..a4fe1ae8b
--- /dev/null
+++ b/tests/app/shell/accent/palette.test.ts
@@ -0,0 +1,108 @@
+import { describe, expect, test } from 'bun:test'
+
+import { SELECTION_COLOR } from '@open-pencil/core/constants'
+import { contrastRatio, parseColor, rgbaToOkHCL } from '@open-pencil/scene-graph/color'
+
+import {
+ ACCENT_LIGHTNESS_RANGE,
+ ACCENT_PRESETS,
+ accentBaseColor,
+ deriveAccentPalette,
+ type AccentTheme
+} from '@/app/shell/accent/palette'
+
+const THEMES: AccentTheme[] = ['dark', 'light']
+
+function palette(color: string, theme: AccentTheme) {
+ return deriveAccentPalette(accentBaseColor({ kind: 'custom', color }), theme)
+}
+
+describe('deriveAccentPalette', () => {
+ test('the default blue reproduces the interface tokens and canvas selection of the stylesheet', () => {
+ const blue = accentBaseColor({ kind: 'preset', preset: 'blue' })
+ expect(deriveAccentPalette(blue, 'dark').tokens).toEqual({
+ '--color-accent': '#2563EB',
+ '--color-panel-focus': '#3B82F6',
+ '--color-panel-selected': '#2F6FDD',
+ '--color-panel-selected-muted': '#353B46',
+ '--color-primary': '#60A5FA',
+ '--color-on-accent': '#FFFFFF',
+ '--color-on-primary': '#1F2328'
+ })
+ expect(deriveAccentPalette(blue, 'light').tokens).toEqual({
+ '--color-accent': '#2563EB',
+ '--color-panel-focus': '#2563EB',
+ '--color-panel-selected': '#2563EB',
+ '--color-panel-selected-muted': '#E5E7EB',
+ '--color-primary': '#1D4ED8',
+ '--color-on-accent': '#FFFFFF',
+ '--color-on-primary': '#FFFFFF'
+ })
+ const selection = deriveAccentPalette(blue, 'dark').selection
+ expect(selection.color.r).toBeCloseTo(SELECTION_COLOR.r, 2)
+ expect(selection.color.g).toBeCloseTo(SELECTION_COLOR.g, 2)
+ expect(selection.color.b).toBeCloseTo(SELECTION_COLOR.b, 2)
+ expect(selection.foreground).toEqual(parseColor('#FFFFFF'))
+ })
+
+ test('every preset keeps white text readable on its accent surfaces in both themes', () => {
+ for (const preset of ACCENT_PRESETS) {
+ for (const theme of THEMES) {
+ const { tokens } = deriveAccentPalette(accentBaseColor({ kind: 'preset', preset }), theme)
+ expect(tokens['--color-on-accent']).toBe('#FFFFFF')
+ const white = parseColor('#FFFFFF')
+ expect(contrastRatio(white, parseColor(tokens['--color-accent']))).toBeGreaterThan(4.5)
+ }
+ }
+ })
+
+ test('a light custom accent switches its text to dark ink, on the canvas too', () => {
+ for (const theme of THEMES) {
+ const { tokens, selection } = palette('#FFEE00', theme)
+ expect(tokens['--color-on-accent']).toBe('#1F2328')
+ expect(tokens['--color-on-primary']).toBe('#1F2328')
+ expect(selection.foreground).toEqual(parseColor('#1F2328'))
+ }
+ })
+
+ test('pulls near-black and near-white picks into a visible lightness', () => {
+ for (const color of ['#000000', '#FFFFFF']) {
+ const lightness = rgbaToOkHCL(parseColor(palette(color, 'dark').tokens['--color-accent'])).l
+ expect(lightness).toBeGreaterThan(ACCENT_LIGHTNESS_RANGE.min - 0.05)
+ expect(lightness).toBeLessThan(ACCENT_LIGHTNESS_RANGE.max + 0.05)
+ }
+ })
+
+ test('moves a custom accent until its text reaches AA contrast on accent and primary surfaces', () => {
+ for (const color of ['#808080', '#00A0A0', '#FF4FA0']) {
+ for (const theme of THEMES) {
+ const { tokens } = palette(color, theme)
+ const onAccent = parseColor(tokens['--color-on-accent'])
+ const onPrimary = parseColor(tokens['--color-on-primary'])
+ for (const surface of ['--color-accent', '--color-panel-selected'] as const) {
+ expect(contrastRatio(onAccent, parseColor(tokens[surface]))).toBeGreaterThanOrEqual(4.5)
+ }
+ expect(
+ contrastRatio(onPrimary, parseColor(tokens['--color-primary']))
+ ).toBeGreaterThanOrEqual(4.5)
+ }
+ }
+ })
+
+ test('the unfocused selection tint keeps the panel lightness and takes the accent hue', () => {
+ const reference = rgbaToOkHCL(parseColor('#353B46'))
+ const tint = rgbaToOkHCL(
+ parseColor(palette('#A16207', 'dark').tokens['--color-panel-selected-muted'])
+ )
+ expect(tint.l).toBeCloseTo(reference.l, 2)
+ const accentHue = rgbaToOkHCL(parseColor('#A16207')).h
+ expect(Math.abs(tint.h - accentHue)).toBeLessThan(10)
+ })
+
+ test('the canvas selection follows the accent hue but not the interface theme', () => {
+ const dark = palette('#15803D', 'dark').selection
+ expect(palette('#15803D', 'light').selection).toEqual(dark)
+ expect(dark.color.g).toBeGreaterThan(dark.color.b)
+ expect(dark.color.g).toBeGreaterThan(dark.color.r)
+ })
+})
diff --git a/tests/e2e/canvas/accent-selection.spec.ts b/tests/e2e/canvas/accent-selection.spec.ts
new file mode 100644
index 000000000..4570e1910
--- /dev/null
+++ b/tests/e2e/canvas/accent-selection.spec.ts
@@ -0,0 +1,22 @@
+import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
+
+const editor = useEditorSetupWithClear('/?test')
+
+test('selection chrome, size pill and ruler badges follow the accent color', async () => {
+ const { page, canvas } = editor
+ await page.getByTestId('app-settings-trigger').click()
+ await page
+ .getByRole('radiogroup', { name: 'Accent color', exact: true })
+ .getByRole('radio', { name: 'Green', exact: true })
+ .click()
+ await page.getByTestId('app-settings-done').click()
+ await expect(page.getByRole('dialog', { name: 'Settings' })).toBeHidden()
+
+ await canvas.drawRect(160, 140, 240, 160)
+ await canvas.waitForRender()
+ canvas.assertNoErrors()
+ expect(await canvas.screenshotCanvasRegion(560, 420)).toMatchSnapshot('green-selection.png', {
+ maxDiffPixelRatio: 0,
+ threshold: 0
+ })
+})
diff --git a/tests/e2e/canvas/accent-selection.spec.ts-snapshots/green-selection-openpencil-darwin.png b/tests/e2e/canvas/accent-selection.spec.ts-snapshots/green-selection-openpencil-darwin.png
new file mode 100644
index 000000000..64c99f5c1
Binary files /dev/null and b/tests/e2e/canvas/accent-selection.spec.ts-snapshots/green-selection-openpencil-darwin.png differ
diff --git a/tests/e2e/settings/theme.spec.ts b/tests/e2e/settings/theme.spec.ts
index 256a97ddd..45b884b20 100644
--- a/tests/e2e/settings/theme.spec.ts
+++ b/tests/e2e/settings/theme.spec.ts
@@ -33,3 +33,37 @@ test('Appearance groups theme and animation controls and uses the persisted app
await page.emulateMedia({ colorScheme: 'dark' })
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark')
})
+
+test('Accent color recolors the interface, persists, and a cancelled custom pick restores it', async ({
+ page
+}) => {
+ await page.goto('/?test')
+ const canvas = new CanvasHelper(page)
+ await canvas.waitForInit()
+ const accent = () =>
+ page.evaluate(() => document.documentElement.style.getPropertyValue('--color-accent'))
+ const initial = await accent()
+
+ await page.getByTestId('app-settings-trigger').click()
+ const presets = page.getByRole('radiogroup', { name: 'Accent color', exact: true })
+ const green = presets.getByRole('radio', { name: 'Green', exact: true })
+ await green.click()
+ await expect(green).toBeChecked()
+ await expect.poll(accent).not.toBe(initial)
+ const chosen = await accent()
+
+ await page.reload()
+ await canvas.waitForInit()
+ await expect.poll(accent).toBe(chosen)
+
+ await page.getByTestId('app-settings-trigger').click()
+ await page.getByTestId('settings-accent-custom').click()
+ const red = page.getByRole('spinbutton', { name: 'Red', exact: true })
+ await red.fill('0')
+ await red.press('Enter')
+ await expect(page.getByTestId('settings-accent-custom')).toHaveAttribute('aria-pressed', 'true')
+ await expect.poll(accent).not.toBe(chosen)
+ await page.keyboard.press('Escape')
+ await expect.poll(accent).toBe(chosen)
+ await expect(green).toBeChecked()
+})
diff --git a/tools/checks/i18n/translation-baseline.txt b/tools/checks/i18n/translation-baseline.txt
index ad8173a8d..a77ef6005 100644
--- a/tools/checks/i18n/translation-baseline.txt
+++ b/tools/checks/i18n/translation-baseline.txt
@@ -54,6 +54,8 @@ de:panels.behaviourMax
de:panels.behaviourStateHover
de:panels.behaviourText
de:settings.mcp
+de:settings.accentOrange
+de:settings.accentPink
de:storage.bucket
de:storage.providerAmazonS3
de:storage.providerBackblaze
@@ -163,6 +165,8 @@ fr:settings.animations
fr:settings.diagnostics
fr:settings.mcp
fr:settings.notifications
+fr:settings.accentGraphite
+fr:settings.accentOrange
fr:storage.bucket
fr:storage.providerAmazonS3
fr:storage.providerBackblaze