forge
Explore
Log in

Don't you dare go Hollow

Colour settings get OKLCH hue and vividness sliders and a hex box for accent and background, and dragging no longer flickers

Browse files at this commit

d9edf011a78359f26c5cf5a3576cddc689e8e654Ahmet Kaan GümüşParent: fb9a426
  • feat
    • colour settings get OKLCH hue and vividness sliders and a hex box for accent and background, and dragging no longer flickers
Show full message
✨ feat: colour settings get OKLCH hue and vividness sliders and a hex box for accent and background, and dragging no longer flickers
crates/forge-web/assets/nav.jsmodified+226 -53
@@ -513,15 +513,22 @@
513 // A `theme` event carries the signed-in user's appearance as `name=value` pairs joined by `;`513 // A `theme` event carries the signed-in user's appearance as `name=value` pairs joined by `;`
514 // (the `<html>` attributes). An empty value removes the attribute. Only data-* names are applied.514 // (the `<html>` attributes). An empty value removes the attribute. Only data-* names are applied.
515 function applyAppearance(data) {515 function applyAppearance(data) {
516+ var colours = null, sheet = null;
516 String(data).split(';').forEach(function (pair) {517 String(data).split(';').forEach(function (pair) {
517 var i = pair.indexOf('=');518 var i = pair.indexOf('=');
518 if (i < 0) { return; }519 if (i < 0) { return; }
519 var name = pair.slice(0, i), value = pair.slice(i + 1);520 var name = pair.slice(0, i), value = pair.slice(i + 1);
520 // The custom colour sheet's href, or empty when no colour is a custom hue.521 // The custom colour sheet's href, or empty when no colour is a custom hue.
521- if (name === 'custom_css') { setCustomCss(value); return; }522+ if (name === 'custom_css') { sheet = value; return; }
522 if (name.indexOf('data-') !== 0) { return; }523 if (name.indexOf('data-') !== 0) { return; }
524+ if (COLOUR_ATTRS.indexOf(name) >= 0) { colours = colours || {}; colours[name] = value; return; }
523 if (value) { root.setAttribute(name, value); } else { root.removeAttribute(name); }525 if (value) { root.setAttribute(name, value); } else { root.removeAttribute(name); }
524 });526 });
527+ if (colours) {
528+ var current = colourState(), next = {};
529+ COLOUR_ATTRS.forEach(function (n) { next[n] = n in colours ? colours[n] : current[n]; });
530+ showColours(next, sheet);
531+ }
525 }532 }
526 // A `language` event means the page text changed for this user: the page is re-rendered in place533 // A `language` event means the page text changed for this user: the page is re-rendered in place
527 // (typed text, focus and scroll kept), as for any live change, even on a page with no stream.534 // (typed text, focus and scroll kept), as for any live change, even on a page with no stream.
@@ -773,50 +780,218 @@
773 // The attributes match what the shell renders: theme `auto` has no data-theme, `dark` is dark, else light.780 // The attributes match what the shell renders: theme `auto` has no data-theme, `dark` is dark, else light.
774 var PREVIEW_ATTR = { accent_light: 'data-accent-light', accent_dark: 'data-accent-dark', base_light: 'data-base-light', base_dark: 'data-base-dark', sidebar_side: 'data-sidebar' };781 var PREVIEW_ATTR = { accent_light: 'data-accent-light', accent_dark: 'data-accent-dark', base_light: 'data-base-light', base_dark: 'data-base-dark', sidebar_side: 'data-sidebar' };
775 782
776- // The custom stylesheet sets the colours of the hue choices (`hue-N`). Its link follows the four783+ // The colour attributes a colour choice sets on <html>, and the stylesheet that styles the hue choices
777- // colour attributes on <html>: it is added when one of them is a hue, its href is kept in step,784+ // (`hue-H` and `hue-H-vV`). That sheet is a <link> whose href never changes once it is live. A new href
778- // and it is removed when none is.785+ // gets a new link: its colours go on <html> when it has loaded, and the live link stays until then, so a
779- // An empty href removes the link. The server sends the href in the live payload (`custom_css`).786+ // drag never paints the defaults. A request that a newer one overtakes before it loads is dropped.
780- function setCustomCss(href) {787+ var COLOUR_ATTRS = ['data-accent-light', 'data-accent-dark', 'data-base-light', 'data-base-dark'];
781- var link = document.head.querySelector('link[rel="stylesheet"][href^="/theme/custom.css"]');788+ var colourWanted = null; // the colour attributes the page should show: the latest asked for
789+ var colourLink = null; // the live sheet this script added (the server's is found in the head)
790+ var pendingLink = null; // a sheet that is still loading
791+ var colourSeq = 0; // bumps on every request; a load for an older request is dropped
792+ var colourFrame = 0;
793+
794+ function liveLink() {
795+ if (!colourLink || !colourLink.isConnected) {
796+ colourLink = document.head.querySelector('link[rel="stylesheet"][href^="/theme/custom.css"]');
797+ }
798+ return colourLink;
799+ }
800+
801+ // The colour attributes the page should show now, read from <html> the first time.
802+ function colourState() {
803+ if (!colourWanted) {
804+ colourWanted = {};
805+ COLOUR_ATTRS.forEach(function (name) { colourWanted[name] = root.getAttribute(name) || ''; });
806+ }
807+ return colourWanted;
808+ }
809+
810+ // The stylesheet href the four colours need, or '' when none of them is a hue. The server builds the same href.
811+ function sheetHref(attrs) {
812+ var vals = COLOUR_ATTRS.map(function (name) { return attrs[name] || ''; });
813+ if (!vals.some(function (v) { return /^hue-/.test(v); })) { return ''; }
814+ return '/theme/custom.css?al=' + encodeURIComponent(vals[0]) + '&ad=' + encodeURIComponent(vals[1]) +
815+ '&bl=' + encodeURIComponent(vals[2]) + '&bd=' + encodeURIComponent(vals[3]);
816+ }
817+
818+ function setColourAttrs(attrs) {
819+ COLOUR_ATTRS.forEach(function (name) {
820+ if (attrs[name]) { root.setAttribute(name, attrs[name]); } else { root.removeAttribute(name); }
821+ });
822+ }
823+
824+ // Shows a colour state. `href` is the sheet the server gave for it (a live payload), or null to build it here.
825+ function showColours(attrs, href) {
826+ colourWanted = attrs;
827+ var seq = ++colourSeq;
828+ if (href === null || href === undefined) { href = sheetHref(attrs); }
829+ if (pendingLink) { pendingLink.remove(); pendingLink = null; }
830+ var live = liveLink();
831+ var liveHref = live ? live.getAttribute('href') : '';
832+ if (href === liveHref) { setColourAttrs(attrs); return; }
782 if (!href) {833 if (!href) {
783- if (link) { link.remove(); }834+ setColourAttrs(attrs);
835+ if (live) { live.remove(); }
836+ colourLink = null;
784 return;837 return;
785 }838 }
786- if (!link) {839+ var link = document.createElement('link');
787- link = document.createElement('link');840+ link.rel = 'stylesheet';
788- link.rel = 'stylesheet';841+ link.setAttribute('href', href);
789- document.head.appendChild(link);842+ link.onload = function () {
843+ if (pendingLink === link) { pendingLink = null; }
844+ if (seq !== colourSeq) { link.remove(); return; }
845+ setColourAttrs(attrs);
846+ var old = liveLink();
847+ if (old && old !== link) { old.remove(); }
848+ colourLink = link;
849+ };
850+ link.onerror = function () {
851+ if (pendingLink === link) { pendingLink = null; }
852+ link.remove();
853+ };
854+ pendingLink = link;
855+ document.head.appendChild(link);
856+ }
857+
858+ // A colour change sets one attribute. The request is made at most once a frame, however many events it takes.
859+ function wantColour(name, value) {
860+ var current = colourState();
861+ var next = {};
862+ COLOUR_ATTRS.forEach(function (n) { next[n] = current[n]; });
863+ next[name] = value;
864+ colourWanted = next;
865+ if (!colourFrame) {
866+ colourFrame = requestAnimationFrame(function () { colourFrame = 0; showColours(colourWanted, null); });
790 }867 }
791- if (link.getAttribute('href') !== href) { link.setAttribute('href', href); }
792 }868 }
793 869
794- // Builds the custom sheet's href from the four colour attributes on <html> while a drag or a870+ function clamp(v, lo, hi) { return Math.min(hi, Math.max(lo, v)); }
795- // preset pick is shown before the save returns. The server builds the same href on the next load.871+
796- function syncCustomCss() {872+ // OKLCH and sRGB, as in the stylesheet's colours. A colour outside sRGB loses chroma, not lightness or hue.
797- var slots = ['data-accent-light', 'data-accent-dark', 'data-base-light', 'data-base-dark'];873+ function srgbEncode(v) {
798- var vals = slots.map(function (name) { return root.getAttribute(name) || ''; });874+ v = clamp(v, 0, 1);
799- var custom = vals.some(function (v) { return /^hue-\d+$/.test(v); });875+ return v <= 0.0031308 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
800- if (!custom) { setCustomCss(''); return; }876+ }
801- setCustomCss('/theme/custom.css?al=' + encodeURIComponent(vals[0]) + '&ad=' + encodeURIComponent(vals[1]) +877+ function srgbDecode(v) { return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); }
802- '&bl=' + encodeURIComponent(vals[2]) + '&bd=' + encodeURIComponent(vals[3]));878+ function oklabToLinear(L, a, b) {
879+ var l = L + 0.3963377774 * a + 0.2158037573 * b;
880+ var m = L - 0.1055613458 * a - 0.0638541728 * b;
881+ var s = L - 0.0894841775 * a - 1.2914855480 * b;
882+ l = l * l * l; m = m * m * m; s = s * s * s;
883+ return [
884+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
885+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
886+ -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s
887+ ];
888+ }
889+ function oklchToLinear(L, C, h) {
890+ var rad = h * Math.PI / 180;
891+ return oklabToLinear(L, C * Math.cos(rad), C * Math.sin(rad));
892+ }
893+ function inGamut(lin) { return lin.every(function (v) { return v >= -1e-4 && v <= 1 + 1e-4; }); }
894+ function hexOfOklch(L, C, h) {
895+ var lin = oklchToLinear(L, C, h);
896+ if (!inGamut(lin)) {
897+ var lo = 0, hi = C;
898+ for (var i = 0; i < 24; i++) {
899+ var mid = (lo + hi) / 2;
900+ if (inGamut(oklchToLinear(L, mid, h))) { lo = mid; } else { hi = mid; }
901+ }
902+ lin = oklchToLinear(L, lo, h);
903+ }
904+ return '#' + lin.map(function (v) {
905+ var byte = Math.round(srgbEncode(v) * 255);
906+ return (byte < 16 ? '0' : '') + byte.toString(16);
907+ }).join('').toUpperCase();
908+ }
909+ function oklchOfHex(digits) {
910+ var lin = [0, 2, 4].map(function (i) { return srgbDecode(parseInt(digits.substr(i, 2), 16) / 255); });
911+ var r = lin[0], g = lin[1], b = lin[2];
912+ var l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
913+ var m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
914+ var s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
915+ var L = 0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s;
916+ var a = 1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s;
917+ var bb = 0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s;
918+ var h = Math.atan2(bb, a) * 180 / Math.PI;
919+ return { l: L, c: Math.sqrt(a * a + bb * bb), h: h < 0 ? h + 360 : h };
920+ }
921+
922+ // The chroma a row's vividness stands for: the background's is small, as the stylesheet draws it.
923+ function rowChroma(kind, vivid) {
924+ return kind === 'base' ? 0.0004 * vivid : 0.03 + 0.16 * vivid / 100;
925+ }
926+
927+ function rowHue(row) { return parseInt(row.querySelector('input[data-hue-stripe]').value, 10) || 0; }
928+ function rowVivid(row) { return parseInt(row.querySelector('input[data-vivid-stripe]').value, 10) || 0; }
929+
930+ // Sets a row's sliders, its Custom value, and the row properties the tracks and knob read. The hex box
931+ // shows the colour of the sliders when `fillHex` is set; otherwise it keeps what was typed.
932+ function setRow(row, hue, vivid, fillHex) {
933+ var hueSlider = row.querySelector('input[data-hue-stripe]');
934+ var vividSlider = row.querySelector('input[data-vivid-stripe]');
935+ var custom = row.querySelector('input[data-hue-custom]');
936+ var hex = row.querySelector('input[data-hex-input]');
937+ hueSlider.value = String(hue);
938+ vividSlider.value = String(vivid);
939+ vividSlider.setAttribute('aria-valuetext', vividSlider.getAttribute('data-vivid-label') + ' ' + vivid + '%');
940+ // Set through the CSSOM because the CSP forbids inline style attributes from the server.
941+ row.style.setProperty('--hue', String(hue));
942+ row.style.setProperty('--v', String(vivid / 100));
943+ if (custom) { custom.value = 'hue-' + hue + '-v' + vivid; }
944+ if (fillHex && hex) {
945+ hex.value = hexOfOklch(parseFloat(row.getAttribute('data-lightness')), rowChroma(row.getAttribute('data-kind'), vivid), hue);
946+ hex.removeAttribute('aria-invalid');
947+ }
803 }948 }
804 949
805- // A drag moves the stylesheet at most once a frame, however many input events it sends.950+ function clearNote(row) {
806- var previewFrame = 0;951+ var note = row.querySelector('[data-hex-note]');
807- function previewLater() {952+ if (note) { note.textContent = ''; }
808- if (previewFrame) { return; }
809- previewFrame = requestAnimationFrame(function () { previewFrame = 0; syncCustomCss(); });
810 }953 }
811 954
812- // Moves a row's stripe knob to a hue, and makes the row's Custom choice that hue (the value a save posts).955+ // A preset pick moves its row's knob to the preset's hue, without choosing Custom.
813- // The hue is also set on the row as `--hue`, which the stripe's knob and the Custom swatch read.
814 function setKnob(row, hue) {956 function setKnob(row, hue) {
815- var range = row.querySelector('input[data-hue-stripe]');957+ setRow(row, hue, rowVivid(row), true);
958+ clearNote(row);
959+ }
960+
961+ // A hue or vividness slider: the row's Custom choice takes the new colour, and the colour shows on
962+ // <html> once its sheet has loaded. The save waits for the release (the change event).
963+ function sliderMoved(el) {
964+ var row = el.closest('[data-colour-row]');
965+ var custom = row ? row.querySelector('input[data-hue-custom]') : null;
966+ if (!row || !custom) { return; }
967+ setRow(row, rowHue(row), rowVivid(row), true);
968+ clearNote(row);
969+ custom.checked = true;
970+ wantColour(PREVIEW_ATTR[custom.name], custom.value);
971+ }
972+
973+ // A typed hex: a valid one becomes the row's colour (its hue, and the vividness that its chroma gives),
974+ // and the sliders follow. An invalid one is outlined and the last good colour stays.
975+ function typedHex(el) {
976+ var row = el.closest('[data-colour-row]');
977+ if (!row) { return; }
978+ var match = /^#?([0-9a-fA-F]{6})$/.exec(el.value.trim());
979+ if (!match) { el.setAttribute('aria-invalid', 'true'); return; }
980+ el.removeAttribute('aria-invalid');
981+ var lch = oklchOfHex(match[1]);
982+ var kind = row.getAttribute('data-kind');
983+ var hue = Math.round(lch.h) % 360;
984+ var vivid = kind === 'base' ? Math.round(lch.c / 0.0004) : Math.round((lch.c - 0.03) / 0.16 * 100);
985+ vivid = clamp(vivid, 0, 100);
986+ var note = row.querySelector('[data-hex-note]');
987+ if (note) {
988+ var lightness = parseFloat(row.getAttribute('data-lightness'));
989+ note.textContent = Math.abs(lch.l - lightness) > 0.08 ? note.getAttribute('data-message') : '';
990+ }
991+ setRow(row, hue, vivid, false);
816 var custom = row.querySelector('input[data-hue-custom]');992 var custom = row.querySelector('input[data-hue-custom]');
817- if (range) { range.value = String(hue); }993+ custom.checked = true;
818- row.style.setProperty('--hue', String(hue));994+ wantColour(PREVIEW_ATTR[custom.name], custom.value);
819- if (custom) { custom.value = 'hue-' + hue; }
820 }995 }
821 996
822 document.addEventListener('change', function (e) {997 document.addEventListener('change', function (e) {
@@ -833,29 +1008,27 @@
833 return;1008 return;
834 }1009 }
835 if (el.type === 'radio' && Object.prototype.hasOwnProperty.call(PREVIEW_ATTR, el.name)) {1010 if (el.type === 'radio' && Object.prototype.hasOwnProperty.call(PREVIEW_ATTR, el.name)) {
836- root.setAttribute(PREVIEW_ATTR[el.name], el.value);1011+ var attr = PREVIEW_ATTR[el.name];
837- // A preset moves its row's knob to the preset's hue, without choosing Custom.1012+ if (COLOUR_ATTRS.indexOf(attr) >= 0) {
838- var row = el.closest('[data-colour-row]');1013+ var row = el.closest('[data-colour-row]');
839- var hue = el.getAttribute('data-hue');1014+ var hue = el.getAttribute('data-hue');
840- if (row && hue) { setKnob(row, hue); }1015+ if (row && hue) { setKnob(row, parseInt(hue, 10)); }
841- syncCustomCss();1016+ wantColour(attr, el.value);
1017+ } else {
1018+ root.setAttribute(attr, el.value);
1019+ }
842 }1020 }
843 }, false);1021 }, false);
844 1022
845- // Dragging a stripe selects its Custom choice and shows the hue on <html> while the drag lasts.1023+ // Dragging a slider or typing a hex shows the colour as it goes. Both need a form that autosaves.
846- // The save waits for the release (the change event), which the autosubmit handler sends.
847 document.addEventListener('input', function (e) {1024 document.addEventListener('input', function (e) {
848 var el = e.target;1025 var el = e.target;
849- if (!el || el.type !== 'range' || !el.hasAttribute('data-hue-stripe') || !el.form || !el.form.hasAttribute('data-appearance')) { return; }1026+ if (!el || !el.form || !el.form.hasAttribute('data-appearance')) { return; }
850- var row = el.closest('[data-colour-row]');1027+ if (el.type === 'range' && (el.hasAttribute('data-hue-stripe') || el.hasAttribute('data-vivid-stripe'))) {
851- var custom = row ? row.querySelector('input[data-hue-custom]') : null;1028+ sliderMoved(el);
852- if (!custom) { return; }1029+ } else if (el.hasAttribute('data-hex-input')) {
853- setKnob(row, el.value);1030+ typedHex(el);
854- custom.checked = true;
855- if (Object.prototype.hasOwnProperty.call(PREVIEW_ATTR, custom.name)) {
856- root.setAttribute(PREVIEW_ATTR[custom.name], custom.value);
857 }1031 }
858- previewLater();
859 }, false);1032 }, false);
860 1033
861 // The theme the viewer sees: `dark` or `light` on <html>, else the system's setting.1034 // The theme the viewer sees: `dark` or `light` on <html>, else the system's setting.
@@ -873,9 +1046,9 @@
873 // The server renders each stripe's stored hue as the range value only, so the row's `--hue` (which1046 // The server renders each stripe's stored hue as the range value only, so the row's `--hue` (which
874 // the Custom swatch reads) is set here from that value. Each row is set through the CSSOM because1047 // the Custom swatch reads) is set here from that value. Each row is set through the CSSOM because
875 // the CSP forbids inline style attributes from the server.1048 // the CSP forbids inline style attributes from the server.
876- document.querySelectorAll('.hue-row').forEach(function (row) {1049+ document.querySelectorAll('[data-colour-row]').forEach(function (row) {
877- var range = row.querySelector('input[data-hue-stripe]');1050+ row.style.setProperty('--hue', String(rowHue(row)));
878- if (range) { row.style.setProperty('--hue', range.value); }1051+ row.style.setProperty('--v', String(rowVivid(row) / 100));
879 });1052 });
880 document.querySelectorAll('[data-colour-group]').forEach(function (group) {1053 document.querySelectorAll('[data-colour-group]').forEach(function (group) {
881 var tabs = group.querySelectorAll('input[data-colour-tab]');1054 var tabs = group.querySelectorAll('input[data-colour-tab]');
crates/forge-web/src/accent.rsmodified+0 -1
@@ -76,7 +76,6 @@ pub fn custom_of(id: &str, default_vivid: u8) -> Option<(u16, u8)> {
76 }76 }
77 77
78 /// The stored id of a custom accent or base in the `hue-H-vV` form, which `custom_of` reads back.78 /// The stored id of a custom accent or base in the `hue-H-vV` form, which `custom_of` reads back.
79-#[allow(dead_code)] // The settings picker writes its custom ids with this.
80 pub fn custom_id(hue: u16, vivid: u8) -> String {79 pub fn custom_id(hue: u16, vivid: u8) -> String {
81 format!("hue-{hue}-v{vivid}")80 format!("hue-{hue}-v{vivid}")
82 }81 }
crates/forge-web/src/i18n/misc.rsmodified+12 -0
@@ -32,6 +32,9 @@ pub enum K {
32 AccentRowLabel,32 AccentRowLabel,
33 CustomLabel,33 CustomLabel,
34 HueLabel,34 HueLabel,
35+ VividnessLabel,
36+ HexLabel,
37+ LightnessNote,
35 BackgroundLabel,38 BackgroundLabel,
36 ChooseBase,39 ChooseBase,
37 // Appearance: which side the shell sidebar sits on.40 // Appearance: which side the shell sidebar sits on.
@@ -184,6 +187,9 @@ const ALL: &[K] = &[
184 K::AccentRowLabel,187 K::AccentRowLabel,
185 K::CustomLabel,188 K::CustomLabel,
186 K::HueLabel,189 K::HueLabel,
190+ K::VividnessLabel,
191+ K::HexLabel,
192+ K::LightnessNote,
187 K::BackgroundLabel,193 K::BackgroundLabel,
188 K::ChooseBase,194 K::ChooseBase,
189 K::SidebarLabel,195 K::SidebarLabel,
@@ -346,6 +352,12 @@ pub fn t(lang: Lang, key: K) -> &'static str {
346 (CustomLabel, Tr) => "Özel",352 (CustomLabel, Tr) => "Özel",
347 (HueLabel, En) => "Hue",353 (HueLabel, En) => "Hue",
348 (HueLabel, Tr) => "Ton",354 (HueLabel, Tr) => "Ton",
355+ (VividnessLabel, En) => "Vividness",
356+ (VividnessLabel, Tr) => "Canlılık",
357+ (HexLabel, En) => "Hex",
358+ (HexLabel, Tr) => "Hex",
359+ (LightnessNote, En) => "Lightness is adjusted to keep text readable.",
360+ (LightnessNote, Tr) => "Metnin okunur kalması için açıklık ayarlandı.",
349 (BackgroundLabel, En) => "Background",361 (BackgroundLabel, En) => "Background",
350 (BackgroundLabel, Tr) => "Arka plan",362 (BackgroundLabel, Tr) => "Arka plan",
351 (ChooseBase, En) => "Choose a background from the list.",363 (ChooseBase, En) => "Choose a background from the list.",
crates/forge-web/src/pages/settings_appearance.rsmodified+197 -68
@@ -15,9 +15,10 @@ use topcoat::router::error::{SeeOther, see_other};
15 use topcoat::router::{page, route};15 use topcoat::router::{page, route};
16 use topcoat::view::{View, component, view};16 use topcoat::view::{View, component, view};
17 17
18-use crate::accent::{self, hue_of, preset_accent_hue, preset_base_hue};18+use crate::accent::{self, custom_id, custom_of, hue_of, preset_accent_hue, preset_base_hue};
19 use crate::audit::{self, Actor, Target};19 use crate::audit::{self, Actor, Target};
20 use crate::auth::{require_csrf, require_user};20 use crate::auth::{require_csrf, require_user};
21+use crate::custom_colour;
21 use crate::i18n::accents::{accent_name, base_name};22 use crate::i18n::accents::{accent_name, base_name};
22 use crate::i18n::misc::{self as g, K};23 use crate::i18n::misc::{self as g, K};
23 use crate::i18n::{self, Lang};24 use crate::i18n::{self, Lang};
@@ -76,27 +77,76 @@ struct Choice {
76 hue: String,77 hue: String,
77 }78 }
78 79
79-/// Where a hue stripe's knob sits. `custom` says the stored choice is that hue, rather than a80+/// Where a row's sliders sit: the hue, the vividness, and the hex box's colour. `custom` says the
80-/// preset whose hue the knob was moved to.81+/// stored choice is that colour, rather than a preset whose hue the knob was moved to.
81 struct Stripe {82 struct Stripe {
82 hue: u16,83 hue: u16,
84+ vivid: u8,
83 custom: bool,85 custom: bool,
86+ hex: String,
84 }87 }
85 88
86-/// The colour choices of one theme: a background and an accent, each a row of presets and a hue89+/// The vividness a row starts at when its stored id gives none (a legacy `hue-N`): 50 for an accent,
87-/// stripe. `dark` picks the field names and the swatch attributes that belong to the dark theme.90+/// 30 for a background. These are the defaults of `accent::custom_of`.
91+const ACCENT_VIVID: u8 = 50;
92+const BASE_VIVID: u8 = 30;
93+
94+/// The lightness a row's hex box and its note use, in one theme: the accent's, or the background's.
95+fn row_lightness(base: bool, dark: bool) -> f64 {
96+ match (base, dark) {
97+ (false, true) => 0.75,
98+ (false, false) => 0.52,
99+ (true, true) => 0.19,
100+ (true, false) => 0.972,
101+ }
102+}
103+
104+/// The `#RRGGBB` a row's hex box shows for a hue and vividness: the colour the sliders stand for,
105+/// at the row's lightness. The chroma is the one the stylesheet gives that vividness.
106+fn picker_hex(hue: u16, vivid: u8, base: bool, dark: bool) -> String {
107+ let v = f64::from(vivid);
108+ let chroma = if base {
109+ 0.0004 * v
110+ } else {
111+ 0.03 + 0.16 * v / 100.0
112+ };
113+ custom_colour::colour(row_lightness(base, dark), chroma, f64::from(hue))
114+}
115+
116+/// The colour choices of one theme: a background and an accent, each a row of presets and the hue,
117+/// vividness and hex controls. `dark` picks the field names and the swatch attributes that belong to
118+/// the dark theme.
88 struct ColourGroup {119 struct ColourGroup {
89 dark: bool,120 dark: bool,
90 background: &'static str,121 background: &'static str,
91 accent: &'static str,122 accent: &'static str,
92 custom: &'static str,123 custom: &'static str,
93 hue: &'static str,124 hue: &'static str,
125+ vividness: &'static str,
126+ hex: &'static str,
127+ note: &'static str,
94 bases: Vec<Choice>,128 bases: Vec<Choice>,
95 accents: Vec<Choice>,129 accents: Vec<Choice>,
96 base_stripe: Stripe,130 base_stripe: Stripe,
97 accent_stripe: Stripe,131 accent_stripe: Stripe,
98 }132 }
99 133
134+/// One row of a colour panel: its presets, then the Custom choice beside the hue, vividness and hex
135+/// controls. `base` picks the background's chips and the accent's when false.
136+struct ColourRow {
137+ dark: bool,
138+ base: bool,
139+ legend: &'static str,
140+ field: &'static str,
141+ choices: Vec<Choice>,
142+ stripe: Stripe,
143+ custom_label: &'static str,
144+ hue_label: &'static str,
145+ vivid_label: &'static str,
146+ hex_label: &'static str,
147+ note: &'static str,
148+}
149+
100 struct AppearancePage {150 struct AppearancePage {
101 lang: Lang,151 lang: Lang,
102 csrf: String,152 csrf: String,
@@ -185,15 +235,20 @@ fn shown<'a>(stored: &'a str, resolved: &'static str) -> &'a str {
185 }235 }
186 }236 }
187 237
188-/// The stripe of one row. A stored custom hue puts the knob on it; a preset puts the knob on the238+/// The sliders of one row. A stored custom id (`hue-H-vV`, or the legacy `hue-H`) sets the hue and
189-/// preset's hue, and nothing is selected as custom.239+/// vividness; a preset puts the hue knob on the preset's hue at the default vividness, and nothing
190-fn stripe(stored: &str, preset: Option<u16>) -> Stripe {240+/// is selected as custom.
191- match hue_of(stored) {241+fn stripe(stored: &str, preset: Option<u16>, base: bool, dark: bool) -> Stripe {
192- Some(hue) => Stripe { hue, custom: true },242+ let default_vivid = if base { BASE_VIVID } else { ACCENT_VIVID };
193- None => Stripe {243+ let (hue, vivid, custom) = match custom_of(stored, default_vivid) {
194- hue: preset.unwrap_or(0),244+ Some((hue, vivid)) => (hue, vivid, true),
195- custom: false,245+ None => (preset.unwrap_or(0), default_vivid, false),
196- },246+ };
247+ Stripe {
248+ hue,
249+ vivid,
250+ custom,
251+ hex: picker_hex(hue, vivid, base, dark),
197 }252 }
198 }253 }
199 254
@@ -209,6 +264,9 @@ fn colour_group(lang: Lang, dark: bool, base: &str, accent_id: &str) -> ColourGr
209 accent: g::t(lang, K::AccentRowLabel),264 accent: g::t(lang, K::AccentRowLabel),
210 custom: g::t(lang, K::CustomLabel),265 custom: g::t(lang, K::CustomLabel),
211 hue: g::t(lang, K::HueLabel),266 hue: g::t(lang, K::HueLabel),
267+ vividness: g::t(lang, K::VividnessLabel),
268+ hex: g::t(lang, K::HexLabel),
269+ note: g::t(lang, K::LightnessNote),
212 bases: with_hues(270 bases: with_hues(
213 choices(&base_codes, base_shown, |id| base_name(lang, id)),271 choices(&base_codes, base_shown, |id| base_name(lang, id)),
214 preset_base_hue,272 preset_base_hue,
@@ -217,13 +275,84 @@ fn colour_group(lang: Lang, dark: bool, base: &str, accent_id: &str) -> ColourGr
217 choices(&accent_codes, accent_shown, |id| accent_name(lang, id)),275 choices(&accent_codes, accent_shown, |id| accent_name(lang, id)),
218 preset_accent_hue,276 preset_accent_hue,
219 ),277 ),
220- base_stripe: stripe(base, preset_base_hue(base_shown)),278+ base_stripe: stripe(base, preset_base_hue(base_shown), true, dark),
221- accent_stripe: stripe(accent_id, preset_accent_hue(accent_shown)),279+ accent_stripe: stripe(accent_id, preset_accent_hue(accent_shown), false, dark),
222 }280 }
223 }281 }
224 282
225-/// One theme's panel: a Background row and an Accent row. Each row is its presets as round283+/// One row of a colour panel: its presets as round radios, then the Custom choice, a hue slider, a
226-/// radios, then a hue stripe whose Custom radio carries the `hue-N` value.284+/// vividness slider and a hex box. The Custom radio carries `hue-H-vV`, and nav.js keeps it, the
285+/// sliders and the hex box in step while the row is used.
286+#[component]
287+async fn colour_row(row: ColourRow) -> Result<impl View> {
288+ let ColourRow {
289+ dark,
290+ base,
291+ legend,
292+ field,
293+ choices,
294+ stripe,
295+ custom_label,
296+ hue_label,
297+ vivid_label,
298+ hex_label,
299+ note,
300+ } = row;
301+ let value = custom_id(stripe.hue, stripe.vivid);
302+ let hue_value = stripe.hue.to_string();
303+ let vivid_value = stripe.vivid.to_string();
304+ let vivid_text = format!("{vivid_label} {}%", stripe.vivid);
305+ let lightness = format!("{:.3}", row_lightness(base, dark));
306+ let kind = if base { "base" } else { "accent" };
307+ let custom_swatch = if base {
308+ "base-swatch hue-swatch"
309+ } else {
310+ "accent-swatch hue-swatch"
311+ };
312+ Ok(view! {
313+ <fieldset class="colour-picker" data-colour-row="true" data-kind=(kind) data-lightness=(lightness.as_str())>
314+ <legend>(legend)</legend>
315+ <div class="colour-choices">
316+ for choice in choices.into_iter() {
317+ <label class="colour-choice">
318+ <input type="radio" name=(field) value=(choice.value) checked=(choice.selected) data-hue=(choice.hue.as_str()) data-autosubmit="true">
319+ if base {
320+ if dark {
321+ <span class="base-swatch" data-base-dark-swatch=(choice.value) aria-hidden="true"></span>
322+ } else {
323+ <span class="base-swatch" data-base-light-swatch=(choice.value) aria-hidden="true"></span>
324+ }
325+ } else {
326+ if dark {
327+ <span class="accent-swatch" data-accent-dark-swatch=(choice.value) aria-hidden="true"></span>
328+ } else {
329+ <span class="accent-swatch" data-accent-light-swatch=(choice.value) aria-hidden="true"></span>
330+ }
331+ }
332+ <span>(choice.label)</span>
333+ </label>
334+ }
335+ </div>
336+ <div class="hue-row">
337+ <label class="colour-choice">
338+ <input type="radio" name=(field) value=(value.as_str()) checked=(stripe.custom) data-hue-custom="true" data-autosubmit="true">
339+ <span class=(custom_swatch) aria-hidden="true"></span>
340+ <span>(custom_label)</span>
341+ </label>
342+ <div class="tune">
343+ <input type="range" class="hue-stripe" min="0" max="359" value=(hue_value.as_str()) aria-label=(hue_label) data-hue-stripe="true" data-autosubmit="true">
344+ <div class="tune-row">
345+ <input type="range" class="vivid-stripe" min="0" max="100" value=(vivid_value.as_str()) aria-label=(vivid_label) aria-valuetext=(vivid_text.as_str()) data-vivid-stripe="true" data-vivid-label=(vivid_label) data-autosubmit="true">
346+ <input type="text" class="hex-input" maxlength="7" value=(stripe.hex.as_str()) aria-label=(hex_label) title=(hex_label) spellcheck="false" autocomplete="off" data-hex-input="true" data-autosubmit="true">
347+ </div>
348+ <small class="hex-note" data-hex-note="true" data-message=(note)></small>
349+ </div>
350+ </div>
351+ </fieldset>
352+ })
353+}
354+
355+/// One theme's panel: a Background row and an Accent row.
227 #[component]356 #[component]
228 async fn colour_panel(group: ColourGroup) -> Result<impl View> {357 async fn colour_panel(group: ColourGroup) -> Result<impl View> {
229 let ColourGroup {358 let ColourGroup {
@@ -232,6 +361,9 @@ async fn colour_panel(group: ColourGroup) -> Result<impl View> {
232 accent,361 accent,
233 custom,362 custom,
234 hue,363 hue,
364+ vividness,
365+ hex,
366+ note,
235 bases,367 bases,
236 accents,368 accents,
237 base_stripe,369 base_stripe,
@@ -240,58 +372,36 @@ async fn colour_panel(group: ColourGroup) -> Result<impl View> {
240 let base_field = if dark { "base_dark" } else { "base_light" };372 let base_field = if dark { "base_dark" } else { "base_light" };
241 let accent_field = if dark { "accent_dark" } else { "accent_light" };373 let accent_field = if dark { "accent_dark" } else { "accent_light" };
242 let panel = if dark { "dark" } else { "light" };374 let panel = if dark { "dark" } else { "light" };
243- let base_custom = format!("hue-{}", base_stripe.hue);375+ let base_row = ColourRow {
244- let accent_custom = format!("hue-{}", accent_stripe.hue);376+ dark,
377+ base: true,
378+ legend: background,
379+ field: base_field,
380+ choices: bases,
381+ stripe: base_stripe,
382+ custom_label: custom,
383+ hue_label: hue,
384+ vivid_label: vividness,
385+ hex_label: hex,
386+ note,
387+ };
388+ let accent_row = ColourRow {
389+ dark,
390+ base: false,
391+ legend: accent,
392+ field: accent_field,
393+ choices: accents,
394+ stripe: accent_stripe,
395+ custom_label: custom,
396+ hue_label: hue,
397+ vivid_label: vividness,
398+ hex_label: hex,
399+ note,
400+ };
245 Ok(view! {401 Ok(view! {
246 <div class="colour-panel" data-colour-panel=(panel)>402 <div class="colour-panel" data-colour-panel=(panel)>
247- <fieldset class="colour-picker" data-colour-row="true">403+ colour_row(row: base_row)
248- <legend>(background)</legend>404+ colour_row(row: accent_row)
249- <div class="colour-choices">
250- for choice in bases.into_iter() {
251- <label class="colour-choice">
252- <input type="radio" name=(base_field) value=(choice.value) checked=(choice.selected) data-hue=(choice.hue.as_str()) data-autosubmit="true">
253- if dark {
254- <span class="base-swatch" data-base-dark-swatch=(choice.value) aria-hidden="true"></span>
255- } else {
256- <span class="base-swatch" data-base-light-swatch=(choice.value) aria-hidden="true"></span>
257- }
258- <span>(choice.label)</span>
259- </label>
260- }
261- </div>
262- <div class="hue-row">
263- <label class="colour-choice">
264- <input type="radio" name=(base_field) value=(base_custom.as_str()) checked=(base_stripe.custom) data-hue-custom="true" data-autosubmit="true">
265- <span class="base-swatch hue-swatch" aria-hidden="true"></span>
266- <span>(custom)</span>
267- </label>
268- <input type="range" class="hue-stripe hue-stripe-base" min="0" max="359" value=(base_stripe.hue) aria-label=(hue) data-hue-stripe="true" data-autosubmit="true">
269- </div>
270- </fieldset>
271- <fieldset class="colour-picker" data-colour-row="true">
272- <legend>(accent)</legend>
273- <div class="colour-choices">
274- for choice in accents.into_iter() {
275- <label class="colour-choice">
276- <input type="radio" name=(accent_field) value=(choice.value) checked=(choice.selected) data-hue=(choice.hue.as_str()) data-autosubmit="true">
277- if dark {
278- <span class="accent-swatch" data-accent-dark-swatch=(choice.value) aria-hidden="true"></span>
279- } else {
280- <span class="accent-swatch" data-accent-light-swatch=(choice.value) aria-hidden="true"></span>
281- }
282- <span>(choice.label)</span>
283- </label>
284- }
285- </div>
286- <div class="hue-row">
287- <label class="colour-choice">
288- <input type="radio" name=(accent_field) value=(accent_custom.as_str()) checked=(accent_stripe.custom) data-hue-custom="true" data-autosubmit="true">
289- <span class="accent-swatch hue-swatch" aria-hidden="true"></span>
290- <span>(custom)</span>
291- </label>
292- <input type="range" class="hue-stripe" min="0" max="359" value=(accent_stripe.hue) aria-label=(hue) data-hue-stripe="true" data-autosubmit="true">
293- </div>
294- </fieldset>
295 </div>405 </div>
296 })406 })
297 }407 }
@@ -709,6 +819,25 @@ mod tests {
709 assert_eq!(hue_of("sage"), None, "hue: preset id");819 assert_eq!(hue_of("sage"), None, "hue: preset id");
710 }820 }
711 821
822+ /// A stored `hue-95-v80` fills the hue and vividness sliders, and the Custom value is that id again.
823+ #[test]
824+ fn a_stored_hue_and_vividness_fill_the_sliders() {
825+ let group = colour_group(Lang::En, true, "hue-95-v80", "hue-95-v80");
826+ let accent = &group.accent_stripe;
827+ assert_eq!((accent.hue, accent.vivid), (95, 80), "accent: sliders");
828+ assert!(accent.custom, "accent: custom");
829+ assert_eq!(
830+ custom_id(accent.hue, accent.vivid),
831+ "hue-95-v80",
832+ "accent: value"
833+ );
834+ assert_eq!(
835+ (group.base_stripe.hue, group.base_stripe.vivid),
836+ (95, 80),
837+ "base: sliders"
838+ );
839+ }
840+
712 #[test]841 #[test]
713 fn labels_follow_the_page_language() {842 fn labels_follow_the_page_language() {
714 assert_eq!(theme_label(Lang::En, "dark"), "Dark");843 assert_eq!(theme_label(Lang::En, "dark"), "Dark");
crates/forge-web/tests/e2e/ui_prefs_e2e.rsmodified+3 -1
@@ -308,8 +308,10 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() {
308 .await;308 .await;
309 assert_eq!(saved.status, 303, "save: {}", saved.body);309 assert_eq!(saved.status, 303, "save: {}", saved.body);
310 let page = env.http.get("/settings/appearance", Some(&session)).await;310 let page = env.http.get("/settings/appearance", Some(&session)).await;
311+ // The Custom radio carries the hue at the default vividness; the stored id stays `hue-200`.
312+ let checked = ["hue-200-v50", "gold", "spark", "dusk"].map(str::to_owned);
313+ assert_eq!(checked_colours(&page.body), checked.map(Some));
311 let chosen = ["hue-200", "gold", "spark", "dusk"].map(str::to_owned);314 let chosen = ["hue-200", "gold", "spark", "dusk"].map(str::to_owned);
312- assert_eq!(checked_colours(&page.body), chosen.clone().map(Some));
313 assert_eq!(html_colours(&page.body), chosen.map(Some));315 assert_eq!(html_colours(&page.body), chosen.map(Some));
314 316
315 // The newest accents and backgrounds save and show the same way.317 // The newest accents and backgrounds save and show the same way.
style/main.scssmodified+86 -30
@@ -2504,28 +2504,61 @@ code {
2504 min-width: 0;2504 min-width: 0;
2505 }2505 }
2506 2506
2507-// The hue stripe: a range input whose track is a rainbow, with a round knob. The background stripe2507+// Each row's colour is drawn with oklch() from custom properties on the row. nav.js sets --hue (the
2508-// is a pale, low-saturation band so it reads as a tint. nav.js sets --hue on the row: the knob and the2508+// hue) and --v (the vividness, 0..1) on the row; the panel sets the lightness, and the kind of row
2509-// Custom swatch take their colour from it.2509+// sets the chroma range. The background rows are drawn a little stronger than their real tint, so
2510+// the hue shows on a pale page. The knob and the Custom swatch take the same colour as the track.
2510 [data-colour-row] {2511 [data-colour-row] {
2511 --hue: 0;2512 --hue: 0;
2513+ --v: 0.5;
2514+ --c-min: 0.03;
2515+ --c-span: 0.16;
2516+ --track-l: 0.75;
2517+ --track-c: calc(var(--c-min) + var(--c-span) * var(--v));
2518+}
2519+
2520+[data-colour-row][data-kind="base"] {
2521+ --v: 0.3;
2522+ --c-min: 0.02;
2523+ --c-span: 0.06;
2524+ --track-l: 0.8;
2525+}
2526+
2527+[data-colour-panel="light"] [data-colour-row][data-kind="accent"] {
2528+ --track-l: 0.52;
2512 }2529 }
2513 2530
2514 .hue-row {2531 .hue-row {
2515- display: flex;2532+ display: grid;
2516- align-items: center;2533+ grid-template-columns: 4.5rem minmax(0, 1fr);
2517- gap: 12px;2534+ align-items: start;
2535+ gap: 8px 12px;
2518 min-width: 0;2536 min-width: 0;
2519 2537
2520- // The Custom choice takes the width of one preset, so the stripe lines up with the presets' row.2538+ // The Custom choice takes the width of one preset, so the sliders line up beside the presets.
2521 > .colour-choice {2539 > .colour-choice {
2522- flex: none;
2523 width: 4.5rem;2540 width: 4.5rem;
2524 }2541 }
2525 }2542 }
2526 2543
2527-.hue-stripe {2544+// The sliders stack: the hue slider full width, then the vividness slider and the hex box on one line,
2528- --track: linear-gradient(to right, hsl(0 85% 55%), hsl(60 90% 52%), hsl(120 65% 45%), hsl(180 70% 42%), hsl(240 80% 58%), hsl(300 75% 55%), hsl(360 85% 55%));2545+// then a note that shows only when a typed hex was lightened to keep text readable.
2546+.tune {
2547+ display: grid;
2548+ gap: 6px;
2549+ min-width: 0;
2550+}
2551+
2552+.tune-row {
2553+ display: flex;
2554+ align-items: center;
2555+ gap: 8px;
2556+ min-width: 0;
2557+}
2558+
2559+// The hue and vividness tracks and knobs. Both are drawn from the row's custom properties.
2560+.hue-stripe,
2561+.vivid-stripe {
2529 -webkit-appearance: none;2562 -webkit-appearance: none;
2530 appearance: none;2563 appearance: none;
2531 flex: 1 1 auto;2564 flex: 1 1 auto;
@@ -2538,10 +2571,6 @@ code {
2538 background: transparent;2571 background: transparent;
2539 cursor: pointer;2572 cursor: pointer;
2540 2573
2541- &.hue-stripe-base {
2542- --track: linear-gradient(to right, hsl(0 45% 84%), hsl(60 45% 84%), hsl(120 35% 81%), hsl(180 35% 81%), hsl(240 40% 85%), hsl(300 35% 83%), hsl(360 45% 84%));
2543- }
2544-
2545 &::-webkit-slider-runnable-track {2574 &::-webkit-slider-runnable-track {
2546 height: 14px;2575 height: 14px;
2547 border-radius: var(--radius-full);2576 border-radius: var(--radius-full);
@@ -2563,7 +2592,7 @@ code {
2563 margin-top: -4px;2592 margin-top: -4px;
2564 border-radius: 50%;2593 border-radius: 50%;
2565 border: 3px solid var(--surface);2594 border: 3px solid var(--surface);
2566- background: hsl(var(--hue) 80% 50%);2595+ background: oklch(var(--track-l) var(--track-c) var(--hue));
2567 box-shadow: 0 0 0 1px var(--border-strong);2596 box-shadow: 0 0 0 1px var(--border-strong);
2568 }2597 }
2569 2598
@@ -2573,32 +2602,59 @@ code {
2573 height: 22px;2602 height: 22px;
2574 border-radius: 50%;2603 border-radius: 50%;
2575 border: 3px solid var(--surface);2604 border: 3px solid var(--surface);
2576- background: hsl(var(--hue) 80% 50%);2605+ background: oklch(var(--track-l) var(--track-c) var(--hue));
2577 box-shadow: 0 0 0 1px var(--border-strong);2606 box-shadow: 0 0 0 1px var(--border-strong);
2578 }2607 }
2579 2608
2580- &.hue-stripe-base::-webkit-slider-thumb {
2581- background: hsl(var(--hue) 40% 62%);
2582- }
2583-
2584- &.hue-stripe-base::-moz-range-thumb {
2585- background: hsl(var(--hue) 40% 62%);
2586- }
2587-
2588 &:focus-visible {2609 &:focus-visible {
2589 outline: 2px solid var(--focus);2610 outline: 2px solid var(--focus);
2590 outline-offset: 3px;2611 outline-offset: 3px;
2591 }2612 }
2592 }2613 }
2593 2614
2594-// The Custom swatch shows the hue the stripe is on. The accent one is saturated, the background2615+// The hue track: the row's lightness and chroma, every 30 degrees around the wheel.
2595-// one pale, like the presets beside it.2616+.hue-stripe {
2596-.hue-swatch {2617+ --track: linear-gradient(to right, oklch(var(--track-l) var(--track-c) 0), oklch(var(--track-l) var(--track-c) 30), oklch(var(--track-l) var(--track-c) 60), oklch(var(--track-l) var(--track-c) 90), oklch(var(--track-l) var(--track-c) 120), oklch(var(--track-l) var(--track-c) 150), oklch(var(--track-l) var(--track-c) 180), oklch(var(--track-l) var(--track-c) 210), oklch(var(--track-l) var(--track-c) 240), oklch(var(--track-l) var(--track-c) 270), oklch(var(--track-l) var(--track-c) 300), oklch(var(--track-l) var(--track-c) 330), oklch(var(--track-l) var(--track-c) 360));
2597- background: hsl(var(--hue) 75% 50%);
2598 }2618 }
2599 2619
2600-.base-swatch.hue-swatch {2620+// The vividness track: from no colour to full, at the current hue.
2601- background: hsl(var(--hue) 40% 82%);2621+.vivid-stripe {
2622+ --track: linear-gradient(to right, oklch(var(--track-l) var(--c-min) var(--hue)), oklch(var(--track-l) calc(var(--c-min) + var(--c-span)) var(--hue)));
2623+}
2624+
2625+// The hex box. A typed value that is not a colour is outlined in red and keeps the last good colour.
2626+.hex-input {
2627+ flex: none;
2628+ box-sizing: border-box;
2629+ width: 96px;
2630+ height: 28px;
2631+ padding: 2px 8px;
2632+ border: 1px solid var(--border-strong);
2633+ border-radius: var(--radius-sm);
2634+ background: var(--surface);
2635+ color: var(--text);
2636+ font-family: var(--mono);
2637+ font-size: 0.8125rem;
2638+
2639+ &[aria-invalid="true"] {
2640+ outline: 2px solid var(--danger);
2641+ outline-offset: 0;
2642+ }
2643+}
2644+
2645+// The lightness note is empty, and so hidden, unless a typed colour was lightened.
2646+.hex-note {
2647+ font-size: 0.75rem;
2648+ color: var(--muted);
2649+
2650+ &:empty {
2651+ display: none;
2652+ }
2653+}
2654+
2655+// The Custom swatch shows the colour its row's sliders stand for.
2656+.hue-swatch {
2657+ background: oklch(var(--track-l) var(--track-c) var(--hue));
2602 }2658 }
2603 2659
2604 .colour-group {2660 .colour-group {