Skip to content

fix(studio): parse modern CSS colors in the inspector and gradient editor - #3752

Open
dkryaklin wants to merge 1 commit into
heygen-com:mainfrom
dkryaklin:fix/studio-modern-css-color-parsing
Open

fix(studio): parse modern CSS colors in the inspector and gradient editor#3752
dkryaklin wants to merge 1 commit into
heygen-com:mainfrom
dkryaklin:fix/studio-modern-css-color-parsing

Conversation

@dkryaklin

@dkryaklin dkryaklin commented Sep 7, 2026

Copy link
Copy Markdown

Problem

Select an element styled with color: oklch(0.7 0.15 200) in Studio. The inspector swatch shows black. Drag the picker and the element turns black.

parseCssColor in packages/studio/src/components/editor/colorValue.ts only read hex and comma-separated rgb(). That is not what reaches it:

  • getComputedStyle keeps oklch(), oklab() and lab() as written, and turns color-mix() into color(srgb ...).
  • Gradient stops are read from the authored background-image, so white, #0f172acc or rgb(255 0 0 / 50%) are common there.

All of these returned null. The inspector fell back to black. In the gradient editor a stop inserted between two named stops copied its left neighbour instead of blending.

Fix

  • parseCssColor parses with @colordx/core plus its named-color plugin. It covers CSS Color 4, has no dependencies, is 8.4 KB gzipped, and is the fastest parser in its class.
  • gradientValue.ts drops its own parser and uses parseCssColor.
  • InlineTextToolbar.tsx drops its canvas fallback, which only existed for named colors.

Verification

  • colorValue.test.ts: modern computed colors, named colors, 8-digit hex, gamut clipping, rejected input, picker hex conversion.
  • gradientValue.test.ts: interpolation across named stops and across 8-digit hex stops with alpha.
  • bun run --cwd packages/studio test: 428 files, 4786 passed.
  • oxlint, oxfmt --check, tsc --noEmit clean. bun install --frozen-lockfile accepts the lockfile.

@dkryaklin
dkryaklin force-pushed the fix/studio-modern-css-color-parsing branch 9 times, most recently from f572ad7 to 9e1ac13 Compare September 7, 2026 22:02
@dkryaklin
dkryaklin marked this pull request as ready for review September 7, 2026 22:04
@miguel-heygen
miguel-heygen self-requested a review September 7, 2026 22:04
@miguel-heygen
miguel-heygen enabled auto-merge (squash) September 7, 2026 22:05
@miguel-heygen

Copy link
Copy Markdown
Collaborator

@dkryaklin sign the commit to merge it pls

…itor

parseCssColor only read hex and comma-separated rgb(). Computed styles
arrive as oklch(), oklab() or color(srgb ...), and gradient stops as
whatever the author wrote, so the inspector showed black for all of them
and committing wrote black over the author's color.

Parse with @colordx/core, which covers CSS Color 4. The gradient editor
and the inline text toolbar share the same parser.
auto-merge was automatically disabled September 8, 2026 07:41

Head branch was pushed to by a user without write access

@dkryaklin
dkryaklin force-pushed the fix/studio-modern-css-color-parsing branch from 9e1ac13 to cf60aa5 Compare September 8, 2026 07:41
@dkryaklin

Copy link
Copy Markdown
Author

@dkryaklin sign the commit to merge it pls

Done 👍

@miga-heygen
miga-heygen enabled auto-merge (squash) September 8, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants