Skip to content

💭 Dream window: gradient-style — SDR fallback follows oklab/oklch interpolation (longer hue too) + snippet really falls back - #139

Merged
argyleink merged 4 commits into
mainfrom
dream-gs-1125
Nov 25, 2026
Merged

argyleink merged 4 commits into
mainfrom
dream-gs-1125

Conversation

@argyleink

Copy link
Copy Markdown
Owner

Problem

The classic (SDR) gradient copied the stops 1:1 as hex. A browser without in <colorspace> support (and the HDR-off preview, and any tool that only does sRGB) interpolates those in sRGB, so it drew a different gradient:

  • in oklab lost its bright midpoints (blue to yellow went through gray)
  • in oklch longer hue from red to red was solid red (the Huey preset), which is why the HDR toggle was hidden for longer
  • Pixel diff vs the modern gradient across the 18 presets averaged 25.3/255, Huey 157, Chlorophyll 76, Tri Dye 67

The copied snippet also only ever applied var(--hdr-gradient). Custom properties accept anything, so where in <space> is unsupported that declaration is invalid at computed-value time and the element got no background at all; --sdr-gradient was defined but never used.

Solution

  • New src/utils/fallbackStops.ts: reads the stops back out of the modern string (exactly what the browser renders), resolves them per CSS Images 4 §3.5.3 (default ends, fixup against earlier stops and hints, even spacing), then samples the real interpolation (chosen space + hue mode, premultiplied alpha, transition-hint curve) and adaptively adds sRGB stops wherever plain sRGB lerp would drift more than ~half a JND (deltaE OK 0.02). Hard stops and repeating periods stay intact, a span is written as one double-position stop, and the list is capped at about 100 stops for long stop lists. Out-of-gamut colors clip the way Chrome draws them on an sRGB screen. Length positions (10px) fall back to the old 1:1 copy.
  • srgb gradients are untouched (byte-identical output).
  • Snippet: starts from --sdr-gradient and upgrades to --hdr-gradient under @supports (background: linear-gradient(in oklch, red, red)), grain included.
  • HDR toggle now shows for longer hue too, and its hint copy explains what the classic preview is.

Impact

  • Average error vs the modern gradient across all 18 presets: 25.3 to 1.6 /255 (Chromium pixel diff of the app's own --user-modern vs --user-classic), and no preset got worse. Huey 157 to 5, Chlorophyll 76 to 1.3, LearnUI 53 to 2.2.
  • "Copy classic CSS" and the snippet now give you a fallback that actually looks like what you built, and it actually falls back.
  • Verified in Chromium at 1440 and at 390 with reduced motion (HDR off on Huey + Chlorophyll), no page errors. npm test (119, 8 new) and npm run lint pass. svelte-check already reported 650 errors on main and isn't part of CI.

🤖 Generated with Claude Code

argyleink and others added 2 commits November 25, 2026 03:45
…tually falls back

The classic gradient copied stops 1:1 as hex, so browsers without `in <space>`
support (and the HDR-off preview) drew sRGB interpolation: oklab lost its bright
midpoints and `oklch longer hue` red->red was solid red. The classic now bakes
the real interpolation (space, hue mode, premultiplied alpha, transition hints,
CSS stop fixup) into adaptive sRGB stops read back from the modern string.

The copied snippet only ever applied --hdr-gradient, which leaves no background
at all where `in <space>` is unsupported; it now starts from --sdr-gradient and
upgrades under @supports. The HDR toggle is no longer hidden for longer hue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g stop lists

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for hd-gradients ready!

Name Link
🔨 Latest commit b61bc65
🔍 Latest deploy log https://app.netlify.com/projects/hd-gradients/deploys/6b06cdf9ac5e6bccd2554bf3
😎 Deploy Preview https://deploy-preview-139--hd-gradients.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

argyleink added a commit that referenced this pull request Nov 25, 2026
argyleink added a commit that referenced this pull request Nov 25, 2026
@argyleink

Copy link
Copy Markdown
Owner Author

Screenshots

strips.png

app-1440-sdr.png

app-390-sdr-rm.png

argyleink added a commit that referenced this pull request Nov 25, 2026
argyleink and others added 2 commits November 25, 2026 03:59
…ltiply hue, never one stop

- colorjs 0.5 keeps parsed values as Number objects, so Number.isFinite() read a typed alpha
  as opaque and `color(srgb ...)` coords as 0 (black) on the first stop and hard stops
- stops are now pushed from their segment's own interpolation, so a `none` component borrows
  from the neighbour it blends with (a jump at the stop when the two sides differ, like browsers)
- own CSS Color 4 interpolation instead of Color.range(): colorjs premultiplies the hue too,
  which put hsl/oklch fades between two hues on the wrong hue
- a solid gradient keeps two stops; `linear-gradient(#f00)` is invalid in the browsers that
  actually use this fallback

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@argyleink
argyleink merged commit 71e72ca into main Nov 25, 2026
5 checks passed
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.

1 participant