From eb39aa10938260f20020bf1821501a812c2a8790 Mon Sep 17 00:00:00 2001 From: nolight132 Date: Sun, 29 Nov 2026 13:28:14 +0100 Subject: [PATCH 01/27] feat(themes): add a theme creator on a labelled mock of the current app --- src/lib/color.ts | 179 ++++ src/lib/components/ThemePreview.svelte | 7 + src/lib/components/TokenMap.svelte | 557 +++++++++++ src/lib/components/mock/AppMock.svelte | 125 ++- src/lib/components/mock/Aside.svelte | 5 +- src/lib/components/mock/Members.svelte | 4 +- src/lib/components/mock/PlayerBar.svelte | 10 +- src/lib/components/mock/Sidebar.svelte | 1 - src/lib/components/mock/TitleBar.svelte | 4 +- src/lib/creator.ts | 176 ++++ src/lib/data/themes.ts | 2 +- src/lib/mock/theme.ts | 40 +- src/lib/theme-tokens.ts | 90 ++ src/routes/docs/themes/+page.svelte | 59 +- src/routes/themes/+page.svelte | 3 +- src/routes/themes/creator/+page.svelte | 1135 ++++++++++++++++++++++ src/routes/themes/submit/+page.svelte | 12 + 17 files changed, 2293 insertions(+), 116 deletions(-) create mode 100644 src/lib/color.ts create mode 100644 src/lib/components/TokenMap.svelte create mode 100644 src/lib/creator.ts create mode 100644 src/lib/theme-tokens.ts create mode 100644 src/routes/themes/creator/+page.svelte diff --git a/src/lib/color.ts b/src/lib/color.ts new file mode 100644 index 0000000..eac654d --- /dev/null +++ b/src/lib/color.ts @@ -0,0 +1,179 @@ +/** A colour as red, green and blue from 0 to 255 and alpha from 0 to 1. */ +export type Rgba = { r: number; g: number; b: number; a: number }; + +/** A colour as hue in degrees and saturation, lightness and alpha from 0 to 1. */ +export type Hsla = { h: number; s: number; l: number; a: number }; + +/** How far each of the theme creator's sliders moves every colour, from -100 to 100, hue in degrees. */ +export type Shift = { hue: number; saturation: number; lightness: number }; + +const HEX = /^#?([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i; + +const clamp = (value: number, low = 0, high = 1) => Math.min(Math.max(value, low), high); + +/** + * Reads a hex colour of 3, 4, 6 or 8 digits, with or without `#`, or CSS `rgb(r g b / a)`. + * Returns null for anything else. + */ +export function parse(value: string): Rgba | null { + const text = value.trim(); + const hex = text.match(HEX)?.[1]; + if (hex) { + const digits = hex.length <= 4 ? [...hex].map((digit) => digit + digit).join('') : hex; + const [r, g, b, a = 255] = (digits.match(/../g) ?? []).map((pair) => parseInt(pair, 16)); + return { r, g, b, a: a / 255 }; + } + const rgb = text.match(/^rgba?\(([^)]+)\)$/i)?.[1]; + if (!rgb) return null; + const [r, g, b, a = 1] = rgb + .split(/[\s,/]+/) + .filter(Boolean) + .map(Number); + if ([r, g, b, a].some(Number.isNaN)) return null; + return { r, g, b, a }; +} + +/** Whether `value` is a colour a theme file accepts: hex of 6 or 8 digits. */ +export function valid(value: string): boolean { + return /^#?(?:[0-9a-f]{6}|[0-9a-f]{8})$/i.test(value.trim()); +} + +/** A colour as lowercase `#rrggbb`, or `#rrggbbaa` when it is not opaque. */ +export function hex({ r, g, b, a }: Rgba): string { + const byte = (value: number) => + Math.round(clamp(value, 0, 255)) + .toString(16) + .padStart(2, '0'); + const alpha = Math.round(clamp(a) * 255); + return `#${byte(r)}${byte(g)}${byte(b)}${alpha < 255 ? byte(alpha) : ''}`; +} + +/** Any colour `parse` reads, written the way a theme file stores it. */ +export function normal(value: string): string { + const color = parse(value); + return color ? hex(color) : value; +} + +export function toHsl({ r, g, b, a }: Rgba): Hsla { + const red = r / 255; + const green = g / 255; + const blue = b / 255; + const top = Math.max(red, green, blue); + const low = Math.min(red, green, blue); + const l = (top + low) / 2; + const span = top - low; + if (span === 0) return { h: 0, s: 0, l, a }; + const s = span / (1 - Math.abs(2 * l - 1)); + const h = + top === red + ? ((green - blue) / span + (green < blue ? 6 : 0)) * 60 + : top === green + ? ((blue - red) / span + 2) * 60 + : ((red - green) / span + 4) * 60; + return { h, s, l, a }; +} + +export function fromHsl({ h, s, l, a }: Hsla): Rgba { + const chroma = (1 - Math.abs(2 * l - 1)) * s; + const turn = (((h % 360) + 360) % 360) / 60; + const second = chroma * (1 - Math.abs((turn % 2) - 1)); + const [red, green, blue] = + turn < 1 + ? [chroma, second, 0] + : turn < 2 + ? [second, chroma, 0] + : turn < 3 + ? [0, chroma, second] + : turn < 4 + ? [0, second, chroma] + : turn < 5 + ? [second, 0, chroma] + : [chroma, 0, second]; + const lift = l - chroma / 2; + return { r: (red + lift) * 255, g: (green + lift) * 255, b: (blue + lift) * 255, a }; +} + +/** + * Moves `value` by `shift`. Hue turns the colour wheel, saturation scales towards grey or full + * colour, and lightness moves towards black or white, so a grey stays grey and alpha stays put. + */ +export function adjust(value: string, shift: Shift): string { + const color = parse(value); + if (!color || (!shift.hue && !shift.saturation && !shift.lightness)) return value; + const { h, s, l, a } = toHsl(color); + return hex( + fromHsl({ + h: h + shift.hue, + s: scale(s, shift.saturation / 100), + l: towards(l, shift.lightness / 100), + a + }) + ); +} + +/** + * The colour that `adjust` turns into `value` under `shift`, so an edit made while the sliders + * are moved survives moving them again. It is exact except where a slider at its end has pinned + * every colour to the same saturation or lightness. + */ +export function unadjust(value: string, shift: Shift): string { + const color = parse(value); + if (!color || (!shift.hue && !shift.saturation && !shift.lightness)) return value; + const { h, s, l, a } = toHsl(color); + return hex( + fromHsl({ + h: h - shift.hue, + s: unscale(s, shift.saturation / 100), + l: untowards(l, shift.lightness / 100), + a + }) + ); +} + +/** Relative luminance as WCAG defines it. */ +export function luminance({ r, g, b }: Rgba): number { + const linear = (channel: number) => { + const value = channel / 255; + return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4; + }; + return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b); +} + +/** `top` painted over the opaque `bottom`. The result is opaque. */ +export function over(top: Rgba, bottom: Rgba): Rgba { + const mix = (upper: number, lower: number) => upper * top.a + lower * (1 - top.a); + return { r: mix(top.r, bottom.r), g: mix(top.g, bottom.g), b: mix(top.b, bottom.b), a: 1 }; +} + +/** The WCAG contrast ratio between two opaque colours, from 1 to 21. */ +export function contrast(first: Rgba, second: Rgba): number { + const [light, dark] = [luminance(first), luminance(second)].sort((a, b) => b - a); + return (light + 0.05) / (dark + 0.05); +} + +/** Whether text on `value` should be light rather than dark. */ +export function dark(value: string): boolean { + const color = parse(value); + return !!color && luminance(color) < 0.18; +} + +function scale(value: number, amount: number): number { + return clamp(amount >= 0 ? value + (1 - value) * amount * value : value * (1 + amount)); +} + +function unscale(value: number, amount: number): number { + if (amount < 0) return amount === -1 ? value : clamp(value / (1 + amount)); + if (!amount) return value; + // solves value = x + (1 - x) * amount * x for x in 0..1 + const root = (1 + amount - Math.sqrt((1 + amount) ** 2 - 4 * amount * value)) / (2 * amount); + return clamp(root); +} + +function towards(value: number, amount: number): number { + return clamp(amount >= 0 ? value + (1 - value) * amount : value * (1 + amount)); +} + +function untowards(value: number, amount: number): number { + if (amount >= 1 || amount <= -1) return value; + return clamp(amount >= 0 ? (value - amount) / (1 - amount) : value / (1 + amount)); +} diff --git a/src/lib/components/ThemePreview.svelte b/src/lib/components/ThemePreview.svelte index d99b548..fc4e464 100644 --- a/src/lib/components/ThemePreview.svelte +++ b/src/lib/components/ThemePreview.svelte @@ -99,6 +99,12 @@ {/each} {/if} + {#if chosen} + Edit + {/if} {/if} @@ -203,6 +209,7 @@ box-shadow: inset 0 0 0 1px rgb(127 127 127 / 0.3); } + .edit, .close { flex: none; height: 32px; diff --git a/src/lib/components/TokenMap.svelte b/src/lib/components/TokenMap.svelte new file mode 100644 index 0000000..457fec2 --- /dev/null +++ b/src/lib/components/TokenMap.svelte @@ -0,0 +1,557 @@ + + +
+
+ +
+ + + + {#each placed as label (label.token)} + + {/each} +
+ + diff --git a/src/lib/components/mock/AppMock.svelte b/src/lib/components/mock/AppMock.svelte index dd1a9dc..ce28176 100644 --- a/src/lib/components/mock/AppMock.svelte +++ b/src/lib/components/mock/AppMock.svelte @@ -4,6 +4,7 @@ import { player } from '$lib/mock/player.svelte'; import { reach } from '$lib/mock/packs.svelte'; import { dim, palette } from '$lib/mock/theme'; + import { dark as isDark } from '$lib/color'; import { route } from '$lib/mock/route.svelte'; import { radius, settings } from '$lib/mock/settings.svelte'; import { ADAPTIVE, scheme as siteScheme } from '$lib/scheme.svelte'; @@ -31,12 +32,21 @@ import Sidebar from './Sidebar.svelte'; import TitleBar from './TitleBar.svelte'; - /** Whether the panes stay still under the wheel until the visitor clicks in, for a window laid inline in a page the visitor is scrolling. */ - let { hold = false }: { hold?: boolean } = $props(); + let { + hold = false, + colors, + floor = 0.62 + }: { + /** Whether the panes stay still under the wheel until the visitor clicks in, for a window laid inline in a page the visitor is scrolling. */ + hold?: boolean; + /** Every colour token by name, which the window wears instead of the theme picked in its settings. */ + colors?: Record; + /** The least the window shrinks to before its stage scrolls sideways instead. */ + floor?: number; + } = $props(); const WIDTH = 1170; const HEIGHT = 730; - const FLOOR = 0.62; const FADE = 320; /** The sidebars' limits, as the desktop's, and the least the page between them keeps. */ const LEFT_MIN = 160; @@ -62,13 +72,27 @@ const at = $derived(route.now); - const scale = $derived(Math.min(Math.max(room / WIDTH, FLOOR), 1)); + const scale = $derived(Math.min(Math.max(room / WIDTH, floor), 1)); /** The adaptive theme wears the site's colour, so the window and the page around it always match. */ const tint = $derived(site.tint); - const tokens = $derived(palette(tint, settings.adaptive, settings.theme)); + const tokens = $derived( + colors + ? Object.fromEntries( + Object.entries(colors).map(([name, value]) => [`--m-${name.replaceAll('_', '-')}`, value]) + ) + : palette(tint, settings.adaptive, settings.theme) + ); const scheme = $derived( - settings.theme === 'System' ? undefined : dim(settings.theme) ? 'dark' : 'light' + colors + ? isDark(colors.background) + ? 'dark' + : 'light' + : settings.theme === 'System' + ? undefined + : dim(settings.theme) + ? 'dark' + : 'light' ); const style = $derived( Object.entries(tokens) @@ -225,29 +249,36 @@ {#if docked} {/if} - {#if at.screen === 'home'} - - {:else if at.screen === 'search'} - - {:else if at.screen === 'library'} - - {:else if at.screen === 'history'} - - {:else if at.screen === 'settings'} - route.go({ screen: 'equalizer' })} - /> - {:else if at.screen === 'equalizer'} - - {:else if at.screen === 'artist'} - - {:else if at.screen === 'playlist'} - - {:else} - - {/if} +
+ {#if at.screen === 'home'} + + {:else if at.screen === 'search'} + + {:else if at.screen === 'library'} + + {:else if at.screen === 'history'} + + {:else if at.screen === 'settings'} + route.go({ screen: 'equalizer' })} + /> + {:else if at.screen === 'equalizer'} + + {:else if at.screen === 'artist'} + + {:else if at.screen === 'playlist'} + + {:else} + + {/if} +
{#if right && tab === 'members'} {:else if right} @@ -324,6 +355,42 @@ display: flex; flex: 1; min-height: 0; + background: var(--m-sidebar); + } + + /* the page lies on the chrome as a sheet, edged and rounded wherever a sidebar or an opaque player bar meets it, square against the window */ + .sheet { + --corner: calc(min(var(--m-radius), 10px) * 1.5); + position: relative; + display: flex; + flex: 1; + min-width: 0; + min-height: 0; + overflow: hidden; + background: var(--m-background); + border-top: 1px solid var(--m-sidebar-border); + } + + .sheet.left { + border-left: 1px solid var(--m-sidebar-border); + border-top-left-radius: var(--corner); + } + + .sheet.right { + border-right: 1px solid var(--m-sidebar-border); + border-top-right-radius: var(--corner); + } + + .sheet.footed { + border-bottom: 1px solid var(--m-sidebar-border); + } + + .sheet.footed.left { + border-bottom-left-radius: var(--corner); + } + + .sheet.footed.right { + border-bottom-right-radius: var(--corner); } .dismiss { diff --git a/src/lib/components/mock/Aside.svelte b/src/lib/components/mock/Aside.svelte index 43144eb..320eb2f 100644 --- a/src/lib/components/mock/Aside.svelte +++ b/src/lib/components/mock/Aside.svelte @@ -377,8 +377,7 @@ flex-direction: column; width: var(--m-right, 254px); overflow: hidden; - background: var(--m-background); - border-left: 1px solid var(--m-border); + background: var(--m-sidebar); } .aside.stripped { @@ -388,7 +387,6 @@ min-height: 0; height: 100%; background: none; - border-left: 0; } .head { @@ -399,7 +397,6 @@ gap: 7px; height: 32px; padding: 0 7px; - border-bottom: 1px solid var(--m-border); } .eyebrow { diff --git a/src/lib/components/mock/Members.svelte b/src/lib/components/mock/Members.svelte index cba1783..726643a 100644 --- a/src/lib/components/mock/Members.svelte +++ b/src/lib/components/mock/Members.svelte @@ -78,8 +78,7 @@ flex-direction: column; width: var(--m-right, 254px); overflow: hidden; - background: var(--m-background); - border-left: 1px solid var(--m-border); + background: var(--m-sidebar); } .head { @@ -88,7 +87,6 @@ align-items: center; height: 32px; padding: 0 7px; - border-bottom: 1px solid var(--m-border); } .eyebrow { diff --git a/src/lib/components/mock/PlayerBar.svelte b/src/lib/components/mock/PlayerBar.svelte index 1f17d11..708e0b4 100644 --- a/src/lib/components/mock/PlayerBar.svelte +++ b/src/lib/components/mock/PlayerBar.svelte @@ -146,8 +146,8 @@ gap: 14px; height: 76px; padding: 0 17.5px; - background: var(--m-secondary); - border-top: 1px solid var(--m-border); + background: var(--m-sidebar); + border-top: 1px solid transparent; } .now { @@ -236,9 +236,11 @@ gap: 7px; } + /* glass over the page, the popover colour at 70% under a wide saturated blur, parted from the page by its own edge */ .frosted { - background: color-mix(in srgb, var(--m-secondary) 72%, transparent); - backdrop-filter: blur(24px) saturate(1.4); + background: color-mix(in srgb, var(--m-popover) 70%, transparent); + backdrop-filter: blur(18px) saturate(1.8); + border-top-color: var(--m-border); } .bar.compact { diff --git a/src/lib/components/mock/Sidebar.svelte b/src/lib/components/mock/Sidebar.svelte index 31cb989..bece4f5 100644 --- a/src/lib/components/mock/Sidebar.svelte +++ b/src/lib/components/mock/Sidebar.svelte @@ -92,7 +92,6 @@ scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--m-muted-foreground) 45%, transparent) transparent; background: var(--m-sidebar); - border-right: 1px solid var(--m-sidebar-border); } .row { diff --git a/src/lib/components/mock/TitleBar.svelte b/src/lib/components/mock/TitleBar.svelte index 5971bc8..d732b12 100644 --- a/src/lib/components/mock/TitleBar.svelte +++ b/src/lib/components/mock/TitleBar.svelte @@ -157,8 +157,8 @@ flex: none; align-items: center; height: 36px; - background: var(--m-background); - border-bottom: 1px solid var(--m-title-bar-border); + background: var(--m-sidebar); + border-bottom: 1px solid transparent; } /* the sidebar toggle sits as close to the history buttons as they sit to each other */ diff --git a/src/lib/creator.ts b/src/lib/creator.ts new file mode 100644 index 0000000..6cf0086 --- /dev/null +++ b/src/lib/creator.ts @@ -0,0 +1,176 @@ +import { normal } from './color'; +import { themes as community, zip } from './data/themes'; +import { colorsOf, darkColors, FIELDS, themes as builtIn } from './mock/theme'; +import { + base64, + bytes, + check, + family, + format, + link, + read, + slug, + type Canonical +} from './theme-file'; + +/** A palette the theme creator can start from. */ +export type Source = { + id: string; + group: 'Built in' | 'Community'; + title: string; + /** Every token as theme file hex. */ + colors: Record; +}; + +/** One variant of a theme as the creator exports it, `label` being its part of the title. */ +export type Draft = { label: string; colors: Record }; + +/** A theme the visitor brought in, every variant with its colours filled in. */ +export type Imported = { name: string; author: string; variants: Draft[] }; + +/** A checked theme ready to save: its id and its files, sorted the way Sonora lists them. */ +export type Packed = { id: string; files: [string | null, Canonical][] }; + +const LINK = 'sonora://theme/'; +const UNREADABLE = 'This is neither a theme file nor a theme link.'; + +/** Sonora's own themes, then every variant in the community gallery. */ +export const sources: Source[] = [ + ...builtIn + .filter((title) => title !== 'System') + .map((title) => ({ + id: `built-in/${slug(title)}`, + group: 'Built in' as const, + title, + colors: hexes(colorsOf(title)) + })), + ...community.flatMap((theme) => + theme.variants.map((variant) => ({ + id: `community/${theme.id}/${variant.id}`, + group: 'Community' as const, + title: variant.title, + colors: hexes(variant.colors) + })) + ) +]; + +/** The palette the creator opens with. */ +export const DEFAULT_SOURCE = 'built-in/dark'; + +/** + * Reads a theme the visitor pasted: the text of a theme file, a `sonora://theme/` link or the + * part of one after it. A link that carries a family brings every variant. Throws with a reason + * the page can show. + */ +export function bring(text: string): Imported { + const trimmed = text.trim(); + let json = trimmed; + if (!trimmed.startsWith('{')) { + const payload = trimmed.startsWith(LINK) ? trimmed.slice(LINK.length) : trimmed; + try { + json = unbase64(payload); + } catch { + throw new Error(UNREADABLE); + } + } + let parsed: unknown; + try { + parsed = JSON.parse(json); + } catch { + throw new Error(UNREADABLE); + } + const fail = (reason: string): never => { + throw new Error(`${reason[0].toUpperCase()}${reason.slice(1)}.`); + }; + const variants = (parsed as { variants?: Record }).variants; + const files = (variants ? Object.values(variants) : [parsed]).map((one) => + read(JSON.stringify(one), fail) + ); + if (!files.length) fail('the link carries no theme'); + const named = + files.length > 1 + ? family( + 'theme', + files.map((one) => one.name) + ) + : { name: files[0].name, variants: [''] }; + return { + name: named.name, + author: files[0].author, + variants: files.map((one, index) => ({ + label: named.variants[index], + colors: Object.fromEntries( + FIELDS.map((token) => [token, normal(one.theme[token] ?? darkColors[token])]) + ) + })) + }; +} + +/** + * Checks the theme the way Sonora checks a link and returns its files. Every variant is titled + * with the theme's name and then its own label, which is how Sonora names a family back. Throws + * with a reason the page can show. + */ +export function pack(name: string, author: string, drafts: Draft[]): Packed { + const id = slug(name) || 'theme'; + const single = drafts.length === 1; + const entries = drafts.map((draft, index): [string | null, string] => { + const title = single ? name : `${name.trim()} ${draft.label.trim()}`; + const theme: Canonical = { + name: title.trim(), + author: author.trim(), + version: 1, + theme: Object.fromEntries(FIELDS.map((token) => [token, normal(draft.colors[token])])) + }; + const stem = single ? null : slug(draft.label) || `variant-${index + 1}`; + return [stem, JSON.stringify(theme)]; + }); + const files = check(id, entries, (reason) => { + throw new Error(`${reason[0].toUpperCase()}${reason.slice(1)}.`); + }); + return { id, files }; +} + +/** The `sonora://theme/` link that installs a packed theme, or null when it is too long. */ +export function install({ id, files }: Packed): string | null { + try { + return link(id, files, (reason) => { + throw new Error(reason); + }); + } catch { + return null; + } +} + +/** What a theme link carries after `sonora://theme/`, which the creator's own link carries too. */ +export function payload({ id, files }: Packed): string { + const body = + files[0][0] === null ? files[0][1] : { family: id, variants: Object.fromEntries(files) }; + return base64(bytes(JSON.stringify(body))) + .replace(/\+/g, '-') + .replace(/\//g, '_') + .replace(/=+$/, ''); +} + +/** The file to save: the theme file itself, or a zip of the folder for a family. */ +export function archive({ id, files }: Packed): { name: string; blob: Blob } { + if (files[0][0] === null) { + return { + name: `${id}.json`, + blob: new Blob([format(files[0][1])], { type: 'application/json' }) + }; + } + const data = zip(files.map(([stem, file]) => [`${id}/${stem}.json`, format(file)])); + return { name: `${id}.zip`, blob: new Blob([data as BlobPart], { type: 'application/zip' }) }; +} + +/** Every token of `colors` as theme file hex. */ +function hexes(colors: Record): Record { + return Object.fromEntries(FIELDS.map((token) => [token, normal(colors[token])])); +} + +function unbase64(text: string): string { + const padded = text.replace(/-/g, '+').replace(/_/g, '/'); + const binary = atob(padded + '='.repeat((4 - (padded.length % 4)) % 4)); + return new TextDecoder().decode(Uint8Array.from(binary, (char) => char.charCodeAt(0))); +} diff --git a/src/lib/data/themes.ts b/src/lib/data/themes.ts index d8fdf9a..ad7800e 100644 --- a/src/lib/data/themes.ts +++ b/src/lib/data/themes.ts @@ -160,7 +160,7 @@ function css(hex: string): string { } /** A zip archive that stores `entries`, each a path and its text, without compressing them. */ -function zip(entries: [string, string][]): Uint8Array { +export function zip(entries: [string, string][]): Uint8Array { const parts: Uint8Array[] = []; const directory: Uint8Array[] = []; let offset = 0; diff --git a/src/lib/mock/theme.ts b/src/lib/mock/theme.ts index e109a8b..b803b0d 100644 --- a/src/lib/mock/theme.ts +++ b/src/lib/mock/theme.ts @@ -36,7 +36,11 @@ export const FIELDS = [ 'table_row_border', 'table_hover', 'table_active', - 'table_active_border' + 'table_active_border', + 'status_error', + 'status_success', + 'status_warning', + 'status_info' ]; const SURFACES = new Set([ @@ -62,38 +66,38 @@ const TEXTS = new Set([ ]); const palettes: Record = { - dark: '0a0a0a fafafa 50505066 262626 0000008c fafafa 909090 171717 36363666 4d4d4d66 fafafa 171717 e5e5e5b3 7f1d1d fef2f2 8b2020b3 141414 fafafa f5f5f5 1d4ed8 0a0a0a 50505066 262626 262626 171717cc 8a8a8a 262626b3 50505033 1e40af33 1d4ed8', + dark: '0b0b0b fafafa 50505066 262626 0000008c fafafa 909090 171717 36363666 4d4d4d66 fafafa 171717 e5e5e5b3 7f1d1d fef2f2 8b2020b3 141414 fafafa f5f5f5 1d4ed8 070707 50505066 181818 262626 171717cc 8a8a8a 262626b3 50505033 1e40af33 1d4ed8 ff6369 4ade80 fbbf24 60a5fa', light: - 'fafafa 171717 9b9b9b66 e5e5e5 0000008c fafafa 606060 f5f5f5 d5d5d566 b7b7b766 171717 fafafa 262626b3 b91c1c fef2f2 991b1bb3 ffffff 171717 262626 2563eb f5f5f5 cdcdcd66 d4d4d4 d4d4d4 f5f5f5e6 666666 d4d4d4b3 cdcdcd33 2563eb1f 2563eb', + 'fafafa 171717 9b9b9b66 e5e5e5 0000008c fafafa 606060 f5f5f5 d5d5d566 b7b7b766 171717 fafafa 262626b3 b91c1c fef2f2 991b1bb3 ffffff 171717 262626 2563eb ededed cdcdcd66 e4e4e4 d4d4d4 f5f5f5e6 666666 d4d4d4b3 cdcdcd33 2563eb1f 2563eb dc2626 16a34a d97706 2563eb', 'catppuccin-latte': - 'eff1f5 4c4f69 acb0be66 ccd0da 0000008c eff1f5 6c6f85 e6e9ef ccd0da66 bcc0cc66 8839ef eff1f5 7430cbb3 d20f39 eff1f5 b20d30b3 eff1f5 4c4f69 8839ef 8839ef eff1f5 bcc0cc66 ccd0da ccd0da e6e9efe6 6c6f85 ccd0dab3 ccd0da66 8839ef33 8839ef', + 'eff1f5 4c4f69 acb0be66 ccd0da 0000008c eff1f5 6c6f85 e6e9ef ccd0da66 bcc0cc66 8839ef eff1f5 7430cbb3 d20f39 eff1f5 b20d30b3 eff1f5 4c4f69 8839ef 8839ef e6e9ef bcc0cc66 ccd0da ccd0da e6e9efe6 6c6f85 ccd0dab3 ccd0da66 8839ef33 8839ef ff6369 4ade80 fbbf24 60a5fa', 'catppuccin-frappe': - '303446 c6d0f5 62688066 51576d 0000008c c6d0f5 a5adce 414559 51576d66 62688066 ca9ee6 232634 d7b6ecb3 e78284 232634 eda1a3b3 292c3c c6d0f5 ca9ee6 ca9ee6 303446 62688066 414559 414559 292c3ce6 949cbb 414559b3 51576d66 ca9ee633 ca9ee6', + '303446 c6d0f5 62688066 51576d 0000008c c6d0f5 a5adce 414559 51576d66 62688066 ca9ee6 232634 d7b6ecb3 e78284 232634 eda1a3b3 292c3c c6d0f5 ca9ee6 ca9ee6 292c3c 62688066 414559 414559 292c3ce6 949cbb 414559b3 51576d66 ca9ee633 ca9ee6 ff6369 4ade80 fbbf24 60a5fa', 'catppuccin-macchiato': - '24273a cad3f5 5b607866 494d64 0000008c cad3f5 a5adcb 363a4f 494d6466 5b607866 c6a0f6 181926 d4b8f8b3 ed8796 181926 f2a5b0b3 1e2030 cad3f5 c6a0f6 c6a0f6 24273a 5b607866 363a4f 363a4f 1e2030e6 939ab7 363a4fb3 494d6466 c6a0f633 c6a0f6', + '24273a cad3f5 5b607866 494d64 0000008c cad3f5 a5adcb 363a4f 494d6466 5b607866 c6a0f6 181926 d4b8f8b3 ed8796 181926 f2a5b0b3 1e2030 cad3f5 c6a0f6 c6a0f6 1e2030 5b607866 363a4f 363a4f 1e2030e6 939ab7 363a4fb3 494d6466 c6a0f633 c6a0f6 ff6369 4ade80 fbbf24 60a5fa', 'catppuccin-mocha': - '1e1e2e cdd6f4 585b7066 45475a 0000008c cdd6f4 a6adc8 313244 45475a66 585b7066 cba6f7 11111b d8bcf9b3 f38ba8 11111b f6a8beb3 181825 cdd6f4 cba6f7 cba6f7 1e1e2e 585b7066 313244 313244 181825e6 9399b2 313244b3 45475a66 cba6f733 cba6f7', + '1e1e2e cdd6f4 585b7066 45475a 0000008c cdd6f4 a6adc8 313244 45475a66 585b7066 cba6f7 11111b d8bcf9b3 f38ba8 11111b f6a8beb3 181825 cdd6f4 cba6f7 cba6f7 181825 585b7066 313244 313244 181825e6 9399b2 313244b3 45475a66 cba6f733 cba6f7 ff6369 4ade80 fbbf24 60a5fa', dracula: - '282a36 f8f8f2 6272a466 44475a 0000008c f8f8f2 b4bccf 343746 44475a66 6272a466 bd93f9 282a36 ceaefab3 ff5555 282a36 ff8080b3 21222c f8f8f2 bd93f9 bd93f9 282a36 6272a466 343746 343746 21222ce6 b4bccf 343746b3 44475a66 bd93f933 bd93f9', + '282a36 f8f8f2 6272a466 44475a 0000008c f8f8f2 b4bccf 343746 44475a66 6272a466 bd93f9 282a36 ceaefab3 ff5555 282a36 ff8080b3 21222c f8f8f2 bd93f9 bd93f9 21222c 6272a466 343746 343746 21222ce6 b4bccf 343746b3 44475a66 bd93f933 bd93f9 ff6369 4ade80 fbbf24 60a5fa', 'gruvbox-dark': - '282828 ebdbb2 665c5466 3c3836 0000008c ebdbb2 a89984 32302f 50494566 665c5466 fe8019 282828 fea052b3 fb4934 282828 fc7667b3 32302f ebdbb2 fe8019 fe8019 282828 665c5466 3c3836 3c3836 282828e6 928374 3c3836b3 50494566 fe801933 fe8019', + '282828 ebdbb2 665c5466 3c3836 0000008c ebdbb2 a89984 32302f 50494566 665c5466 fe8019 282828 fea052b3 fb4934 282828 fc7667b3 32302f ebdbb2 fe8019 fe8019 1d2021 665c5466 3c3836 3c3836 282828e6 928374 3c3836b3 50494566 fe801933 fe8019 ff6369 4ade80 fbbf24 60a5fa', 'gruvbox-dark-hard': - '1d2021 ebdbb2 665c5466 3c3836 0000008c ebdbb2 a89984 282828 50494566 665c5466 fe8019 1d2021 fea052b3 fb4934 1d2021 fc7667b3 282828 ebdbb2 fe8019 fe8019 1d2021 665c5466 3c3836 3c3836 1d2021e6 928374 3c3836b3 50494566 fe801933 fe8019', + '1d2021 ebdbb2 665c5466 3c3836 0000008c ebdbb2 a89984 282828 50494566 665c5466 fe8019 1d2021 fea052b3 fb4934 1d2021 fc7667b3 282828 ebdbb2 fe8019 fe8019 141617 665c5466 3c3836 3c3836 1d2021e6 928374 3c3836b3 50494566 fe801933 fe8019 ff6369 4ade80 fbbf24 60a5fa', 'gruvbox-light': - 'fbf1c7 3c3836 a8998466 ebdbb2 0000008c ebdbb2 7c6f64 f2e5bc d5c4a166 bdae9366 af3a03 fbf1c7 953103b3 9d0006 fbf1c7 850005b3 fbf1c7 3c3836 af3a03 af3a03 fbf1c7 bdae9366 d5c4a1 d5c4a1 f2e5bce6 7c6f64 d5c4a1b3 d5c4a166 af3a0333 af3a03', + 'fbf1c7 3c3836 a8998466 ebdbb2 0000008c ebdbb2 7c6f64 f2e5bc d5c4a166 bdae9366 af3a03 fbf1c7 953103b3 9d0006 fbf1c7 850005b3 fbf1c7 3c3836 af3a03 af3a03 f2e5bc bdae9366 d5c4a1 d5c4a1 f2e5bce6 7c6f64 d5c4a1b3 d5c4a166 af3a0333 af3a03 ff6369 4ade80 fbbf24 60a5fa', 'gruvbox-light-hard': - 'f9f5d7 3c3836 a8998466 ebdbb2 0000008c ebdbb2 7c6f64 f2e5bc d5c4a166 bdae9366 af3a03 f9f5d7 953103b3 9d0006 f9f5d7 850005b3 f9f5d7 3c3836 af3a03 af3a03 f9f5d7 bdae9366 d5c4a1 d5c4a1 f2e5bce6 7c6f64 d5c4a1b3 d5c4a166 af3a0333 af3a03', - nord: '2e3440 d8dee9 4c566a66 434c5e 0000008c eceff4 a0a8b6 3b4252 4c566a66 616a7d66 88c0d0 2e3440 a6d0dcb3 bf616a eceff4 cf888fb3 3b4252 d8dee9 88c0d0 88c0d0 2e3440 4c566a66 3b4252 3b4252 2e3440e6 a0a8b6 3b4252b3 4c566a66 88c0d033 88c0d0', + 'f9f5d7 3c3836 a8998466 ebdbb2 0000008c ebdbb2 7c6f64 f2e5bc d5c4a166 bdae9366 af3a03 f9f5d7 953103b3 9d0006 f9f5d7 850005b3 f9f5d7 3c3836 af3a03 af3a03 f2e5bc bdae9366 d5c4a1 d5c4a1 f2e5bce6 7c6f64 d5c4a1b3 d5c4a166 af3a0333 af3a03 ff6369 4ade80 fbbf24 60a5fa', + nord: '2e3440 d8dee9 4c566a66 434c5e 0000008c eceff4 a0a8b6 3b4252 4c566a66 616a7d66 88c0d0 2e3440 a6d0dcb3 bf616a eceff4 cf888fb3 3b4252 d8dee9 88c0d0 88c0d0 272c36 4c566a66 3b4252 3b4252 2e3440e6 a0a8b6 3b4252b3 4c566a66 88c0d033 88c0d0 ff6369 4ade80 fbbf24 60a5fa', 'rose-pine-main': - '191724 e0def4 524f6766 403d52 0000008c e0def4 908caa 1f1d2e 403d5266 524f6766 c4a7e7 191724 d3bdedb3 eb6f92 191724 f093adb3 26233a e0def4 c4a7e7 c4a7e7 191724 524f6766 403d52 403d52 1f1d2ee6 908caa 403d52b3 403d5266 c4a7e733 c4a7e7', + '191724 e0def4 524f6766 403d52 0000008c e0def4 908caa 1f1d2e 403d5266 524f6766 c4a7e7 191724 d3bdedb3 eb6f92 191724 f093adb3 26233a e0def4 c4a7e7 c4a7e7 16141f 524f6766 403d52 403d52 1f1d2ee6 908caa 403d52b3 403d5266 c4a7e733 c4a7e7 ff6369 4ade80 fbbf24 60a5fa', 'rose-pine-moon': - '232136 e0def4 56526e66 44415a 0000008c e0def4 908caa 2a273f 44415a66 56526e66 c4a7e7 232136 d3bdedb3 eb6f92 232136 f093adb3 393552 e0def4 c4a7e7 c4a7e7 232136 56526e66 44415a 44415a 2a273fe6 908caa 44415ab3 44415a66 c4a7e733 c4a7e7', + '232136 e0def4 56526e66 44415a 0000008c e0def4 908caa 2a273f 44415a66 56526e66 c4a7e7 232136 d3bdedb3 eb6f92 232136 f093adb3 393552 e0def4 c4a7e7 c4a7e7 1f1d30 56526e66 44415a 44415a 2a273fe6 908caa 44415ab3 44415a66 c4a7e733 c4a7e7 ff6369 4ade80 fbbf24 60a5fa', 'rose-pine-dawn': - 'faf4ed 575279 cecacd66 dfdad9 0000008c faf4ed 797593 fffaf3 dfdad966 cecacd66 907aa9 fffaf3 7a6890b3 b4637a fffaf3 995468b3 f2e9e1 575279 907aa9 907aa9 faf4ed cecacd66 dfdad9 dfdad9 fffaf3e6 797593 dfdad9b3 dfdad966 907aa933 907aa9', + 'faf4ed 575279 cecacd66 dfdad9 0000008c faf4ed 797593 fffaf3 dfdad966 cecacd66 907aa9 fffaf3 7a6890b3 b4637a fffaf3 995468b3 f2e9e1 575279 907aa9 907aa9 f2e9e1 cecacd66 dfdad9 dfdad9 fffaf3e6 797593 dfdad9b3 dfdad966 907aa933 907aa9 ff6369 4ade80 fbbf24 60a5fa', 'solarized-dark': - '002b36 93a1a1 586e7566 1f4751 0000008c eee8d5 839496 073642 586e7566 657b8366 268bd2 002b36 5ca8ddb3 dc322f fdf6e3 e56563b3 073642 93a1a1 268bd2 268bd2 002b36 586e7566 073642 073642 002b36e6 839496 073642b3 586e7566 268bd233 268bd2', + '002b36 93a1a1 586e7566 1f4751 0000008c eee8d5 839496 073642 586e7566 657b8366 268bd2 002b36 5ca8ddb3 dc322f fdf6e3 e56563b3 073642 93a1a1 268bd2 268bd2 00212b 586e7566 073642 073642 002b36e6 839496 073642b3 586e7566 268bd233 268bd2 ff6369 4ade80 fbbf24 60a5fa', 'solarized-light': - 'fdf6e3 586e75 93a1a166 d3d3c5 0000008c fdf6e3 657b83 eee8d5 93a1a166 83949666 268bd2 fdf6e3 2076b2b3 dc322f fdf6e3 bb2a28b3 fdf6e3 586e75 268bd2 268bd2 fdf6e3 93a1a166 eee8d5 eee8d5 eee8d5e6 657b83 eee8d5b3 93a1a166 268bd233 268bd2' + 'fdf6e3 586e75 93a1a166 d3d3c5 0000008c fdf6e3 657b83 eee8d5 93a1a166 83949666 268bd2 fdf6e3 2076b2b3 dc322f fdf6e3 bb2a28b3 fdf6e3 586e75 268bd2 268bd2 eee8d5 93a1a166 e4ddc8 eee8d5 eee8d5e6 657b83 eee8d5b3 93a1a166 268bd233 268bd2 ff6369 4ade80 fbbf24 60a5fa' }; const kinds: Record = { diff --git a/src/lib/theme-tokens.ts b/src/lib/theme-tokens.ts new file mode 100644 index 0000000..f4b7db8 --- /dev/null +++ b/src/lib/theme-tokens.ts @@ -0,0 +1,90 @@ +/** A group of colour tokens that paint one part of the window. */ +export type TokenGroup = { area: string; tokens: string[] }; + +/** + * A pair of colours Sonora draws one on the other. `over` is the opaque colour under a + * translucent `on`. `text` pairs need 4.5:1 to read, graphic ones 3:1 to be seen. + */ +export type Pairing = { front: string; on: string; over?: string; kind: 'text' | 'graphic' }; + +/** Every colour token, grouped the way the docs and the theme creator list them. */ +export const groups: TokenGroup[] = [ + { + area: 'Page and text', + tokens: ['background', 'foreground', 'muted_foreground', 'muted', 'border'] + }, + { + area: 'Buttons', + tokens: [ + 'secondary', + 'secondary_hover', + 'secondary_active', + 'primary', + 'primary_foreground', + 'primary_hover', + 'danger', + 'danger_foreground', + 'danger_hover' + ] + }, + { + area: 'Chrome', + tokens: ['sidebar', 'sidebar_accent', 'sidebar_border', 'title_bar_border'] + }, + { + area: 'Menus and overlays', + tokens: ['popover', 'popover_foreground', 'overlay', 'overlay_foreground'] + }, + { + area: 'Lists and tables', + tokens: [ + 'table_head', + 'table_head_foreground', + 'table_row_border', + 'table_hover', + 'table_active', + 'table_active_border' + ] + }, + { + area: 'Accents', + tokens: [ + 'progress_bar', + 'selection', + 'status_error', + 'status_success', + 'status_warning', + 'status_info' + ] + } +]; + +/** The colour pairs Sonora draws one on the other, which a theme has to keep apart. */ +export const pairings: Pairing[] = [ + { front: 'foreground', on: 'background', kind: 'text' }, + { front: 'muted_foreground', on: 'background', kind: 'text' }, + { front: 'foreground', on: 'sidebar', kind: 'text' }, + { front: 'muted_foreground', on: 'sidebar', kind: 'text' }, + { front: 'foreground', on: 'sidebar_accent', over: 'sidebar', kind: 'text' }, + { front: 'foreground', on: 'secondary', over: 'background', kind: 'text' }, + { front: 'foreground', on: 'secondary_hover', over: 'background', kind: 'text' }, + { front: 'foreground', on: 'secondary_active', over: 'background', kind: 'text' }, + { front: 'muted_foreground', on: 'secondary_active', over: 'background', kind: 'text' }, + { front: 'popover_foreground', on: 'secondary_active', over: 'popover', kind: 'text' }, + { front: 'foreground', on: 'muted', over: 'background', kind: 'text' }, + { front: 'foreground', on: 'table_hover', over: 'background', kind: 'text' }, + { front: 'foreground', on: 'table_active', over: 'background', kind: 'text' }, + { front: 'table_head_foreground', on: 'table_head', over: 'background', kind: 'text' }, + { front: 'primary_foreground', on: 'primary', over: 'background', kind: 'text' }, + { front: 'primary_foreground', on: 'primary_hover', over: 'background', kind: 'text' }, + { front: 'danger_foreground', on: 'danger', over: 'background', kind: 'text' }, + { front: 'danger_foreground', on: 'danger_hover', over: 'background', kind: 'text' }, + { front: 'popover_foreground', on: 'popover', over: 'background', kind: 'text' }, + { front: 'popover_foreground', on: 'secondary_hover', over: 'popover', kind: 'text' }, + { front: 'primary', on: 'background', kind: 'graphic' }, + { front: 'progress_bar', on: 'sidebar', kind: 'graphic' }, + { front: 'status_error', on: 'popover', kind: 'graphic' }, + { front: 'status_success', on: 'popover', kind: 'graphic' }, + { front: 'status_warning', on: 'popover', kind: 'graphic' }, + { front: 'status_info', on: 'popover', kind: 'graphic' } +]; diff --git a/src/routes/docs/themes/+page.svelte b/src/routes/docs/themes/+page.svelte index bc8b086..6d17dde 100644 --- a/src/routes/docs/themes/+page.svelte +++ b/src/routes/docs/themes/+page.svelte @@ -1,6 +1,7 @@ @@ -119,7 +71,8 @@

- To share your theme, submit it. + The theme creator shows where each color goes. To share your theme, + submit it.

Variants

@@ -138,12 +91,12 @@

Color tokens

- {#each tokens as group (group.area)} + {#each groups as group (group.area)} diff --git a/src/routes/themes/+page.svelte b/src/routes/themes/+page.svelte index a8d7273..89c2f57 100644 --- a/src/routes/themes/+page.svelte +++ b/src/routes/themes/+page.svelte @@ -90,7 +90,8 @@ Themes

Community themes

- Want to contribute? Write a theme, then + Want to contribute? Make one in the theme creator or + write it by hand, then submit it.

diff --git a/src/routes/themes/creator/+page.svelte b/src/routes/themes/creator/+page.svelte new file mode 100644 index 0000000..1f0d9ce --- /dev/null +++ b/src/routes/themes/creator/+page.svelte @@ -0,0 +1,1135 @@ + + + + Theme creator · Sonora + + + +
+
+
+ Themes +

Theme creator

+
+
+ {#if link} + Open in Sonora + {:else} + + {/if} + + + +
+ {#if 'problem' in packed} +

{packed.problem}

+ {:else if notice} +

{notice}

+ {/if} +
+ +
+
+
+ + {shown.length} of {FIELDS.length} on this screen +
+ +
+ + +
+
+ + diff --git a/src/routes/themes/submit/+page.svelte b/src/routes/themes/submit/+page.svelte index 539b955..186f948 100644 --- a/src/routes/themes/submit/+page.svelte +++ b/src/routes/themes/submit/+page.svelte @@ -20,6 +20,8 @@ const TEST_KEY = '1x00000000000000000000AA'; const SITE_KEY: string = import.meta.env.VITE_TURNSTILE_SITE_KEY || TEST_KEY; const taken = new Set(themes.map((theme) => theme.id)); + /** Where the theme creator leaves the files it hands this form. */ + const HANDOFF = 'sonora-theme-creator-handoff'; let added: Added[] = $state([]); let pasting = $state(false); @@ -79,6 +81,16 @@ const ready = $derived('variants' in result && tested && rights && !!token && !sending); onMount(() => { + if (new URLSearchParams(location.search).has('from')) { + try { + const handed = JSON.parse(sessionStorage.getItem(HANDOFF) ?? '[]') as { + stem: string; + text: string; + }[]; + sessionStorage.removeItem(HANDOFF); + if (!added.length) for (const file of handed) add(file.stem, 'Theme creator', file.text); + } catch {} + } const render = () => { widgetId = window.turnstile!.render(widget!, { sitekey: SITE_KEY, From febd10512c08f3e7c9f249f15e26edfc2f84d949 Mon Sep 17 00:00:00 2001 From: nolight132 Date: Sun, 29 Nov 2026 13:43:21 +0100 Subject: [PATCH 02/27] fix(themes): show the creator's labels at once and restyle its sliders --- src/lib/components/TokenMap.svelte | 119 ++++++++++++++++--------- src/routes/themes/creator/+page.svelte | 96 ++++++++++++-------- 2 files changed, 134 insertions(+), 81 deletions(-) diff --git a/src/lib/components/TokenMap.svelte b/src/lib/components/TokenMap.svelte index 457fec2..e6e36ab 100644 --- a/src/lib/components/TokenMap.svelte +++ b/src/lib/components/TokenMap.svelte @@ -74,6 +74,8 @@ let placed = $state([]); let outlines = $state([]); let probing = $state(false); + /** Whether the mock has taken its measured size, before which it stays hidden. */ + let ready = $state(false); /** Every use of each token the last scan found. Not reactive, since only positions are drawn. */ let uses = new Map(); @@ -91,7 +93,10 @@ resized.observe(root); const scrolled = () => place(); root.addEventListener('scroll', scrolled, true); - later(); + requestAnimationFrame(() => { + ready = true; + scan(); + }); return () => { watch.disconnect(); resized.disconnect(); @@ -115,47 +120,71 @@ } /** - * Repaints each token with a marker colour, one per frame, and records the elements whose - * painted colours change. A frame never paints with a marker on, since each one is set and put - * back within a single task. + * Finds which token paints each colour of every element by group testing. Each pass repaints + * the tokens whose number has one bit set with a marker colour, so the passes a colour changes + * in spell out the number of the token behind it. A colour mixed from two tokens reads as + * their numbers combined, which no mock colour does. Every pass sets its markers and puts them + * back within one task, so no frame ever paints them. */ async function scan() { const app = frame?.querySelector('.app'); if (!app) return; const run = ++scanning; const elements = [app, ...app.querySelectorAll('*')]; - const found = new Map(); + const names = FIELDS.map((token) => `--m-${token.replaceAll('_', '-')}`); probing = true; await tick(); - for (const token of FIELDS) { + if (run !== scanning) return; + const base = read(elements); + const masks = base.map(() => new Array(PROPS.length).fill(0)); + for (let bit = 0; 1 << bit <= FIELDS.length; bit++) { if (run !== scanning) return; - const name = `--m-${token.replaceAll('_', '-')}`; - const before = app.style.getPropertyValue(name); - const sentinel = SENTINELS.find((value) => value !== before) ?? SENTINELS[0]; - const base = read(elements); - app.style.setProperty(name, sentinel); + const picked = names.filter((_, index) => ((index + 1) >> bit) & 1); + const before = picked.map((name) => app.style.getPropertyValue(name)); + picked.forEach((name, at) => + app.style.setProperty( + name, + SENTINELS.find((value) => value !== before[at])! + ) + ); const marked = read(elements); - app.style.setProperty(name, before); - const list: Use[] = []; - elements.forEach((element, index) => { - const was = base[index]; - const now = marked[index]; - if (was[0] !== now[0] || was[1] !== now[1] || was[2] !== now[2]) { - list.push({ element, kind: 'fill' }); + picked.forEach((name, at) => app.style.setProperty(name, before[at])); + marked.forEach((now, index) => { + for (let prop = 0; prop < PROPS.length; prop++) { + if (now[prop] !== base[index][prop]) masks[index][prop] |= 1 << bit; } - if ((was[3] !== now[3] || was[8] !== now[8] || was[9] !== now[9]) && inked(element)) { - list.push({ element, kind: 'text' }); - } - SIDES.forEach((side, at) => { - if (was[4 + at] !== now[4 + at] && was[10 + at] !== '0px') { - list.push({ element, kind: 'edge', side }); - } - }); }); - if (list.length) found.set(token, list); await tick(); } if (run !== scanning) return; + + const found = new Map(); + const add = (mask: number, use: Use) => { + const token = FIELDS[mask - 1]; + if (!token) return; + const list = found.get(token) ?? []; + if ( + !list.some( + (other) => + other.element === use.element && other.kind === use.kind && other.side === use.side + ) + ) { + list.push(use); + } + found.set(token, list); + }; + elements.forEach((element, index) => { + const mask = masks[index]; + for (const prop of [0, 1, 2]) if (mask[prop]) add(mask[prop], { element, kind: 'fill' }); + if (inked(element)) { + for (const prop of [3, 8, 9]) if (mask[prop]) add(mask[prop], { element, kind: 'text' }); + } + SIDES.forEach((side, at) => { + if (mask[4 + at] && base[index][10 + at] !== '0px') { + add(mask[4 + at], { element, kind: 'edge', side }); + } + }); + }); probing = false; uses = found; place(); @@ -383,6 +412,7 @@ class="map" class:labelled={labels} class:probing + class:ready bind:this={frame} bind:clientWidth={width} bind:clientHeight={height} @@ -440,6 +470,24 @@ .map { position: relative; padding-inline: var(--margin); + opacity: 0; + transition: opacity 0.2s ease; + } + + .map.ready { + opacity: 1; + } + + path, + circle, + .label { + animation: appear 0.2s ease; + } + + @keyframes appear { + from { + opacity: 0; + } } .probing :global(*) { @@ -487,18 +535,7 @@ border-radius: 2px; outline: 2px solid #ff2bd6; outline-offset: -1px; - box-shadow: 0 0 0 9999px rgb(0 0 0 / 0); background: rgb(255 43 214 / 0.12); - animation: pulse 1.2s ease-in-out infinite alternate; - } - - @keyframes pulse { - from { - outline-color: #ff2bd6; - } - to { - outline-color: #ffd60a; - } } .label { @@ -548,10 +585,4 @@ overflow: hidden; text-overflow: ellipsis; } - - @media (prefers-reduced-motion: reduce) { - .outline { - animation: none; - } - } diff --git a/src/routes/themes/creator/+page.svelte b/src/routes/themes/creator/+page.svelte index 1f0d9ce..1cfb4a1 100644 --- a/src/routes/themes/creator/+page.svelte +++ b/src/routes/themes/creator/+page.svelte @@ -11,6 +11,7 @@ normal, over, parse, + toHsl, unadjust, valid, type Rgba, @@ -55,6 +56,8 @@ const HANDOFF = 'sonora-theme-creator-handoff'; const IMPORTED = 'imported'; const BLACK: Rgba = { r: 0, g: 0, b: 0, a: 1 }; + /** A checkerboard under a translucent track, so its alpha shows. */ + const CHECKS = 'repeating-conic-gradient(#999 0% 25%, #ddd 0% 50%) 0 0 / 8px 8px'; const NO_SHIFT: Shift = { hue: 0, saturation: 0, lightness: 0 }; const SLIDERS: { key: keyof Shift; label: string; min: number; max: number; unit: string }[] = [ { key: 'hue', label: 'Hue', min: -180, max: 180, unit: '°' }, @@ -89,7 +92,7 @@ /** The theme checked and packed for saving, or why it cannot be yet. */ const packed = $derived.by((): Packed | { problem: string } => { - if (!name.trim() || !author.trim()) return { problem: 'Add a name and an author to save.' }; + if (!name.trim() || !author.trim()) return { problem: '' }; try { return pack( name, @@ -100,6 +103,21 @@ return { problem: (error as Error).message }; } }); + /** The hue of a primary colour, or a blue when the primary is grey and has none. */ + const hueOf = (value: string) => { + const { h, s } = toHsl(parse(value) ?? BLACK); + return s < 0.1 ? 220 : Math.round(h); + }; + /** The hue of the primary on show, which the saturation and lightness tracks are drawn in. */ + const hue = $derived(hueOf(colors.primary)); + /** The primary's hue before the shift, so the hue track under the thumb shows where it lands. */ + const from = $derived(hueOf(current.base.primary)); + /** What each slider's track shows: the wheel, grey to full colour, and black to white. */ + const tracks = $derived({ + hue: `linear-gradient(90deg in hsl longer hue, hsl(${from - 180} 85% 60%), hsl(${from + 180} 85% 60%))`, + saturation: `linear-gradient(90deg, hsl(${hue} 0% 55%), hsl(${hue} 95% 55%))`, + lightness: `linear-gradient(90deg, #000, hsl(${hue} 60% 50%), #fff)` + }); const ready = $derived('files' in packed ? packed : null); const link = $derived(ready ? install(ready) : null); @@ -362,7 +380,7 @@ Submit - {#if 'problem' in packed} + {#if 'problem' in packed && packed.problem}

{packed.problem}

{:else if notice}

{notice}

@@ -494,7 +512,7 @@ min={slider.min} max={slider.max} bind:value={current.shift[slider.key]} - class={slider.key} + style:--track={tracks[slider.key]} /> {current.shift[slider.key] > 0 ? '+' : ''}{current.shift[slider.key]}{slider.unit} @@ -599,6 +617,10 @@ min="0" max="100" value={alpha(token)} + style:--track="linear-gradient(90deg, transparent, {colors[token].slice( + 0, + 7 + )}), {CHECKS}" oninput={(event) => opacity(token, +event.currentTarget.value)} /> {alpha(token)}% @@ -814,6 +836,7 @@ .variants { display: flex; flex-wrap: wrap; + align-items: center; gap: 6px; } @@ -827,8 +850,7 @@ color: var(--muted-fg); } - .variant > button:first-child, - .variant.add { + .variant > button:first-child { height: 100%; padding: 0 12px; } @@ -841,6 +863,7 @@ .variant.add { gap: 6px; + padding: 0 12px; border-style: dashed; } @@ -894,49 +917,48 @@ } .slider input { - width: 100%; - accent-color: var(--primary); - } - - .slider output { - font-size: 12px; - font-variant-numeric: tabular-nums; - text-align: right; - color: var(--muted-fg); - } - - .slider .hue { appearance: none; - height: 6px; - border-radius: 3px; - background: linear-gradient( - 90deg, - hsl(180 80% 55%), - hsl(240 80% 60%), - hsl(300 80% 60%), - hsl(360 80% 60%), - hsl(60 80% 55%), - hsl(120 80% 50%), - hsl(180 80% 55%) - ); + width: 100%; + height: 8px; + margin: 0; + border-radius: 4px; + background: var(--track); + box-shadow: inset 0 0 0 1px rgb(127 127 127 / 0.25); + cursor: pointer; } - .slider .hue::-webkit-slider-thumb { + .slider input::-webkit-slider-thumb { appearance: none; - width: 14px; - height: 14px; + width: 16px; + height: 16px; border-radius: 50%; background: #fff; - box-shadow: 0 0 0 1px rgb(0 0 0 / 0.35); + box-shadow: + 0 0 0 1px rgb(0 0 0 / 0.2), + 0 1px 4px rgb(0 0 0 / 0.45); } - .slider .hue::-moz-range-thumb { - width: 14px; - height: 14px; + .slider input::-moz-range-thumb { + width: 16px; + height: 16px; border: 0; border-radius: 50%; background: #fff; - box-shadow: 0 0 0 1px rgb(0 0 0 / 0.35); + box-shadow: + 0 0 0 1px rgb(0 0 0 / 0.2), + 0 1px 4px rgb(0 0 0 / 0.45); + } + + .slider input:focus-visible { + outline: 2px solid var(--fg); + outline-offset: 4px; + } + + .slider output { + font-size: 12px; + font-variant-numeric: tabular-nums; + text-align: right; + color: var(--muted-fg); } .verdict { From 5b493b455c8a78049aace3d31721ca11f43fe986 Mon Sep 17 00:00:00 2001 From: nolight132 Date: Sun, 29 Nov 2026 13:48:13 +0100 Subject: [PATCH 03/27] feat(themes): refuse unreadable themes from the creator and the submit form --- src/lib/components/TokenMap.svelte | 39 ++++++++------ src/lib/readability.ts | 58 +++++++++++++++++++++ src/routes/themes/creator/+page.svelte | 70 +++++++++++++------------- src/routes/themes/submit/+page.svelte | 5 ++ worker/submit.ts | 5 ++ 5 files changed, 127 insertions(+), 50 deletions(-) create mode 100644 src/lib/readability.ts diff --git a/src/lib/components/TokenMap.svelte b/src/lib/components/TokenMap.svelte index e6e36ab..4b37111 100644 --- a/src/lib/components/TokenMap.svelte +++ b/src/lib/components/TokenMap.svelte @@ -32,6 +32,8 @@ /** One element painting a token, as fill, text or one edge of its border. */ type Use = { element: Element; kind: Kind; side?: Side }; type Box = { x: number; y: number; width: number; height: number }; + /** A point a label may point at: one of the points a use offers, by its place in that list. */ + type Spot = { use: Use; index: number; x: number; y: number; weight: number }; /** Where a label sits in its margin and the spot its line points at. */ type Label = { token: string; left: boolean; x: number; y: number; at: number }; @@ -79,6 +81,8 @@ /** Every use of each token the last scan found. Not reactive, since only positions are drawn. */ let uses = new Map(); + /** The spot each label points at, kept while it stays in view so labels hold still on scroll. */ + let anchors = new Map(); let scanning = 0; let settle = 0; let queued = 0; @@ -228,17 +232,19 @@ const clips = new Map(); const clip = (element: Element): Box | null => visible(element, app, bounds, clips); - const spots = new Map(); + const spots = new Map(); for (const [token, list] of uses) { - const found: { x: number; y: number; weight: number }[] = []; + const found: Spot[] = []; for (const use of list) { if (found.length >= CANDIDATES) break; const box = clip(use.element); if (!box) continue; let taken = 0; - for (const point of points(use, box)) { + for (const [index, point] of points(use, box).entries()) { if (!hits(use, point.tx ?? point.x, point.ty ?? point.y)) continue; found.push({ + use, + index, x: point.x - origin.left, y: point.y - origin.top, weight: Math.log2(1 + box.width * box.height) / 4 @@ -254,10 +260,15 @@ const start = bounds.left - origin.left; const end = bounds.right - origin.left; const order = [...spots.keys()].sort((a, b) => spots.get(a)!.length - spots.get(b)!.length); + const kept = new Map(); for (const token of order) { - let best = spots.get(token)![0]; - let score = -Infinity; - for (const spot of spots.get(token)!) { + const before = anchors.get(token); + const same = spots + .get(token)! + .find((spot) => spot.use === before?.use && spot.index === before.index); + let best = same ?? spots.get(token)![0]; + let score = same ? Infinity : -Infinity; + for (const spot of same ? [] : spots.get(token)!) { const near = chosen.reduce( (least, other) => Math.min(least, Math.hypot(other.x - spot.x, other.at - spot.y)), SPREAD @@ -269,9 +280,11 @@ best = spot; } } + kept.set(token, best); const middle = (start + end) / 2; chosen.push({ token, left: best.x < middle, x: best.x, y: best.y, at: best.y }); } + anchors = kept; placed = labels ? stack(chosen, bounds.top - origin.top, bounds.bottom - origin.top) : []; const list = focus ? (uses.get(focus) ?? []) : []; @@ -478,16 +491,10 @@ opacity: 1; } - path, - circle, - .label { - animation: appear 0.2s ease; - } - - @keyframes appear { - from { - opacity: 0; - } + /* the window has the rounded corners of a desktop window, edged like one */ + .window :global(.sizer) { + border-radius: 12px; + box-shadow: 0 0 0 1px var(--border); } .probing :global(*) { diff --git a/src/lib/readability.ts b/src/lib/readability.ts new file mode 100644 index 0000000..cd6979d --- /dev/null +++ b/src/lib/readability.ts @@ -0,0 +1,58 @@ +import { contrast, over, parse, type Rgba } from './color'; +import { darkColors } from './mock/theme'; +import { pairings, type Pairing } from './theme-tokens'; + +/** + * How well theme colours read where Sonora draws them, shared by the theme creator, the submit + * form and the worker that files submissions. It imports nothing through `$lib`, since the + * worker bundles it on its own. + */ + +/** A pairing as it reads with one theme's colours. */ +export type Reading = Pairing & { ratio: number; level: 'good' | 'low' | 'bad' }; + +/** Below this nothing reads, text or shape. A theme with such a pair is refused. */ +export const UNREADABLE = 3; +/** What text needs to read comfortably. */ +const TEXT = 4.5; + +const BLACK: Rgba = { r: 0, g: 0, b: 0, a: 1 }; + +/** + * Every pairing of `colors` with its contrast, worst first. Tokens the theme leaves out come + * from the Dark theme, as they do in Sonora, and translucent colours are laid over what they + * cover before they are measured. + */ +export function readings(colors: Record): Reading[] { + const color = (token: string): Rgba => parse(colors[token] ?? darkColors[token]) ?? BLACK; + const flat = (token: string): Rgba => + token === 'background' ? over(color(token), BLACK) : over(color(token), flat('background')); + return pairings + .map((pairing): Reading => { + const ground = pairing.over ? over(color(pairing.on), flat(pairing.over)) : flat(pairing.on); + const ratio = contrast(over(color(pairing.front), ground), ground); + const need = pairing.kind === 'text' ? TEXT : UNREADABLE; + const level = ratio >= need ? 'good' : ratio >= UNREADABLE ? 'low' : 'bad'; + return { ...pairing, ratio, level }; + }) + .toSorted((a, b) => a.ratio - b.ratio); +} + +/** The pairings of `colors` that do not read at all. */ +export function unreadable(colors: Record): Reading[] { + return readings(colors).filter((reading) => reading.level === 'bad'); +} + +/** A contrast ratio as people write it, such as `2.25:1`. */ +export function ratio(value: number): string { + return `${value < 10 ? value.toFixed(2).replace(/\.?0+$/, '') : Math.round(value)}:1`; +} + +/** Why a theme is refused, naming its worst pair, or null when every pair reads. */ +export function refusal(name: string, colors: Record): string | null { + const bad = unreadable(colors); + if (!bad.length) return null; + const [worst] = bad; + const more = bad.length > 1 ? ` and ${bad.length - 1} more` : ''; + return `${name} is unreadable: ${worst.front} on ${worst.on} is ${ratio(worst.ratio)}${more}. Every pair needs at least ${UNREADABLE}:1`; +} diff --git a/src/routes/themes/creator/+page.svelte b/src/routes/themes/creator/+page.svelte index 1cfb4a1..62edccc 100644 --- a/src/routes/themes/creator/+page.svelte +++ b/src/routes/themes/creator/+page.svelte @@ -5,11 +5,9 @@ import TokenMap from '$lib/components/TokenMap.svelte'; import { adjust, - contrast, dark as isDark, hex, normal, - over, parse, toHsl, unadjust, @@ -30,7 +28,8 @@ } from '$lib/creator'; import { FIELDS } from '$lib/mock/theme'; import { format, VARIANT_LIMIT } from '$lib/theme-file'; - import { groups, pairings, type Pairing } from '$lib/theme-tokens'; + import { ratio, readings as readingsOf, refusal, type Reading } from '$lib/readability'; + import { groups } from '$lib/theme-tokens'; /** * One variant being made. Edits land in `base`, undone by the sliders' `shift`, so the @@ -48,9 +47,6 @@ /** What the page keeps in the visitor's browser between visits. */ type Saved = { name: string; author: string; variants: Variant[]; active: number }; - /** A pairing as it reads with the colours on show. */ - type Reading = Pairing & { ratio: number; level: 'good' | 'low' | 'bad' }; - const STORE = 'sonora-theme-creator'; /** Where the submit page picks up the files the creator hands it. */ const HANDOFF = 'sonora-theme-creator-handoff'; @@ -122,27 +118,22 @@ const link = $derived(ready ? install(ready) : null); /** Every pairing with the colours on show, worst first. */ - const readings = $derived.by(() => { - const flat = (token: string): Rgba => { - const color = parse(colors[token]) ?? BLACK; - if (token === 'background') return over(color, BLACK); - return over(color, flat('background')); - }; - return pairings - .map((pairing): Reading => { - const ground = pairing.over - ? over(parse(colors[pairing.on]) ?? BLACK, flat(pairing.over)) - : flat(pairing.on); - const front = over(parse(colors[pairing.front]) ?? BLACK, ground); - const ratio = contrast(front, ground); - const need = pairing.kind === 'text' ? 4.5 : 3; - const level = - ratio >= need ? 'good' : ratio >= 3 && pairing.kind === 'text' ? 'low' : 'bad'; - return { ...pairing, ratio, level }; - }) - .toSorted((a, b) => a.ratio - b.ratio); - }); + const readings = $derived(readingsOf(colors)); const failing = $derived(readings.filter((reading) => reading.level !== 'good')); + const broken = $derived(failing.filter((reading) => reading.level === 'bad').length); + /** Why the theme cannot go to the gallery: the first variant with a pair that does not read. */ + const refused = $derived( + variants + .map((variant, index) => + refusal( + variants.length > 1 + ? variant.label.trim() || `Variant ${index + 1}` + : name.trim() || 'The theme', + paint(variant) + ) + ) + .find(Boolean) ?? null + ); onMount(() => { labels = matchMedia('(min-width: 1100px)').matches; @@ -324,7 +315,7 @@ } function submit() { - if (!ready) return; + if (!ready || refused) return; try { sessionStorage.setItem( HANDOFF, @@ -341,10 +332,6 @@ return readings.find((reading) => reading.front === token || reading.on === token); } - function ratio(value: number) { - return `${value < 10 ? value.toFixed(2).replace(/0$/, '') : Math.round(value)}:1`; - } - function alpha(token: string) { return Math.round((parse(colors[token])?.a ?? 1) * 100); } @@ -376,12 +363,19 @@ - {#if 'problem' in packed && packed.problem}

{packed.problem}

+ {:else if ready && refused} +

{refused}. Fix it to submit.

{:else if notice}

{notice}

{/if} @@ -524,8 +518,12 @@

Readability

- - {failing.length ? `${failing.length} to fix` : 'All readable'} + + {broken + ? `${broken} unreadable` + : failing.length + ? `${failing.length} to fix` + : 'All readable'}
{#if failing.length} @@ -971,6 +969,10 @@ color: var(--muted-fg); } + .verdict.broken { + color: #f87171; + } + .readings, .colours ul { display: flex; diff --git a/src/routes/themes/submit/+page.svelte b/src/routes/themes/submit/+page.svelte index 186f948..290b4ae 100644 --- a/src/routes/themes/submit/+page.svelte +++ b/src/routes/themes/submit/+page.svelte @@ -2,6 +2,7 @@ import Glyph from '$lib/components/Glyph.svelte'; import ThemeCard from '$lib/components/ThemeCard.svelte'; import { names, submit as manual, themes, variant, type ThemeVariant } from '$lib/data/themes'; + import { refusal } from '$lib/readability'; import { check, family, read, slug, slugged, VARIANT_LIMIT } from '$lib/theme-file'; import { onMount } from 'svelte'; @@ -71,6 +72,10 @@ fail ); const variants = files.map(([stem, file]) => variant(stem ?? id, file)); + for (const one of variants) { + const reason = refusal(one.title, one.colors); + if (reason) return { problem: `${reason}.` }; + } const name = single ? variants[0].name : names(id, variants); return { variants, name }; } catch (error) { diff --git a/worker/submit.ts b/worker/submit.ts index ca5c82a..472ba34 100644 --- a/worker/submit.ts +++ b/worker/submit.ts @@ -1,4 +1,5 @@ import { DurableObject } from 'cloudflare:workers'; +import { refusal } from '../src/lib/readability'; import { githubProfile } from '../src/lib/theme-submitter'; import { check, @@ -164,6 +165,10 @@ function validate(submission: Submission): [string | null, Canonical][] { submission.files.map((file) => [file.name, file.text]), fail ); + for (const [, file] of files) { + const reason = refusal(file.name, file.theme); + if (reason) fail(reason); + } link(submission.id, files, fail); return files; } From 627d7c3893a7b875fdc992a88eff85eb32ce8093 Mon Sep 17 00:00:00 2001 From: nolight132 Date: Sun, 29 Nov 2026 13:50:10 +0100 Subject: [PATCH 04/27] fix(themes): explain disabled creator buttons in a tooltip instead of a line that shifts the page --- src/routes/themes/creator/+page.svelte | 96 +++++++++++++++----------- 1 file changed, 57 insertions(+), 39 deletions(-) diff --git a/src/routes/themes/creator/+page.svelte b/src/routes/themes/creator/+page.svelte index 62edccc..67ac252 100644 --- a/src/routes/themes/creator/+page.svelte +++ b/src/routes/themes/creator/+page.svelte @@ -115,6 +115,8 @@ lightness: `linear-gradient(90deg, #000, hsl(${hue} 60% 50%), #fff)` }); const ready = $derived('files' in packed ? packed : null); + /** Why nothing can be saved yet, shown over the disabled buttons. */ + const blocked = $derived('problem' in packed && packed.problem ? packed.problem : undefined); const link = $derived(ready ? install(ready) : null); /** Every pairing with the colours on show, worst first. */ @@ -308,9 +310,9 @@ const url = `${location.origin}${location.pathname}#theme=${payload(ready)}`; try { await navigator.clipboard.writeText(url); - say('Link copied'); + say('Copied'); } catch { - say('Copying is blocked in this browser'); + say('Copying is blocked'); } } @@ -352,33 +354,34 @@

Theme creator

- {#if link} - Open in Sonora - {:else} - - {/if} - - - + + {#if link} + Open in Sonora + {:else} + + {/if} + + + + + + + + + +
- {#if 'problem' in packed && packed.problem} -

{packed.problem}

- {:else if ready && refused} -

{refused}. Fix it to submit.

- {:else if notice} -

{notice}

- {/if}
@@ -685,7 +688,33 @@ gap: 8px; } + /* a reason why the button inside is off, shown the moment the pointer is over it */ + .tip { + position: relative; + display: inline-flex; + } + + .tip[data-tip]:hover::after { + content: attr(data-tip); + position: absolute; + top: calc(100% + 8px); + right: 0; + z-index: 20; + width: max-content; + max-width: 320px; + padding: 8px 10px; + border: 1px solid var(--border); + border-radius: 8px; + background: var(--popover); + color: var(--fg); + font-size: 12px; + line-height: 1.45; + box-shadow: var(--shadow); + pointer-events: none; + } + .btn:disabled { + pointer-events: none; opacity: 0.45; cursor: default; } @@ -696,13 +725,6 @@ font-size: 13px; } - .hint { - flex-basis: 100%; - font-size: 13px; - color: var(--muted-fg); - text-align: right; - } - .workspace { display: grid; grid-template-columns: minmax(0, 1fr) 380px; @@ -1151,9 +1173,5 @@ .fields { grid-template-columns: 1fr; } - - .hint { - text-align: left; - } } From ee780d398a6741d4b965aa5e228042b74ffcba6d Mon Sep 17 00:00:00 2001 From: nolight132 Date: Sun, 29 Nov 2026 13:50:27 +0100 Subject: [PATCH 05/27] fix(themes): refuse only unreadable text, not faint icons --- src/lib/readability.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/readability.ts b/src/lib/readability.ts index cd6979d..fe65ff2 100644 --- a/src/lib/readability.ts +++ b/src/lib/readability.ts @@ -11,7 +11,7 @@ import { pairings, type Pairing } from './theme-tokens'; /** A pairing as it reads with one theme's colours. */ export type Reading = Pairing & { ratio: number; level: 'good' | 'low' | 'bad' }; -/** Below this nothing reads, text or shape. A theme with such a pair is refused. */ +/** Below this text does not read. A theme with such text is refused, while shapes only warn. */ export const UNREADABLE = 3; /** What text needs to read comfortably. */ const TEXT = 4.5; @@ -32,13 +32,14 @@ export function readings(colors: Record): Reading[] { const ground = pairing.over ? over(color(pairing.on), flat(pairing.over)) : flat(pairing.on); const ratio = contrast(over(color(pairing.front), ground), ground); const need = pairing.kind === 'text' ? TEXT : UNREADABLE; - const level = ratio >= need ? 'good' : ratio >= UNREADABLE ? 'low' : 'bad'; + const level = + ratio >= need ? 'good' : ratio >= UNREADABLE || pairing.kind === 'graphic' ? 'low' : 'bad'; return { ...pairing, ratio, level }; }) .toSorted((a, b) => a.ratio - b.ratio); } -/** The pairings of `colors` that do not read at all. */ +/** The text pairings of `colors` that do not read at all. */ export function unreadable(colors: Record): Reading[] { return readings(colors).filter((reading) => reading.level === 'bad'); } @@ -54,5 +55,5 @@ export function refusal(name: string, colors: Record): string | if (!bad.length) return null; const [worst] = bad; const more = bad.length > 1 ? ` and ${bad.length - 1} more` : ''; - return `${name} is unreadable: ${worst.front} on ${worst.on} is ${ratio(worst.ratio)}${more}. Every pair needs at least ${UNREADABLE}:1`; + return `${name} is unreadable: ${worst.front} on ${worst.on} is ${ratio(worst.ratio)}${more}. Text needs at least ${UNREADABLE}:1`; } From b594273c998e9d28d8e4890a32b8abc2b38a2643 Mon Sep 17 00:00:00 2001 From: nolight132 Date: Sun, 29 Nov 2026 13:55:08 +0100 Subject: [PATCH 06/27] feat(themes): show menus, dialogs, toasts and row states under the creator's mock --- src/lib/components/Specimens.svelte | 542 +++++++++++++++++++++++++ src/lib/components/TokenMap.svelte | 62 ++- src/routes/themes/creator/+page.svelte | 13 +- 3 files changed, 592 insertions(+), 25 deletions(-) create mode 100644 src/lib/components/Specimens.svelte diff --git a/src/lib/components/Specimens.svelte b/src/lib/components/Specimens.svelte new file mode 100644 index 0000000..4430527 --- /dev/null +++ b/src/lib/components/Specimens.svelte @@ -0,0 +1,542 @@ + + +{#snippet tag(token: string)} + +{/snippet} + +
+
+
+ +
+ {@render tag('popover')} + {@render tag('popover_foreground')} + {@render tag('secondary_hover')} + {@render tag('secondary_active')} + {@render tag('border')} +
+
+
+ +
+
+
+ {#each STATUS as status (status.token)} +
+ {@html status.icon} + {status.text} +
+ {/each} +
+ ♥ + Like +
+
+
+ {#each STATUS as status (status.token)}{@render tag(status.token)}{/each} + {@render tag('popover')} +
+
+
+ +
+
+
+
+ +
+
+
+ Delete playlist? + + Cancel + Delete + +
+
+
+ {@render tag('overlay')} + {@render tag('secondary')} + {@render tag('danger')} + {@render tag('danger_foreground')} +
+
+
+ + Play + Play + Delete + +
+ {@render tag('primary_hover')} + {@render tag('danger_hover')} +
+
+
+ +
+
+
+ 1 · The Water Is Wide + 2 · Wild Mountain Thyme + 3 · Loch Lomond + 4 · The Lark in the Clear Air +
+
+ {@render tag('table_row_border')} + {@render tag('table_hover')} + {@render tag('table_active')} + {@render tag('muted')} +
+
+
+
+ Search songs + + + + Home + +
+
+ {@render tag('selection')} + {@render tag('sidebar_accent')} +
+
+
+
+ + diff --git a/src/lib/components/TokenMap.svelte b/src/lib/components/TokenMap.svelte index 4b37111..0011c49 100644 --- a/src/lib/components/TokenMap.svelte +++ b/src/lib/components/TokenMap.svelte @@ -1,5 +1,6 @@ + + + + diff --git a/src/routes/themes/creator/+page.svelte b/src/routes/themes/creator/+page.svelte index 603c0b2..62f909a 100644 --- a/src/routes/themes/creator/+page.svelte +++ b/src/routes/themes/creator/+page.svelte @@ -1,6 +1,7 @@ -{#snippet tag(token: string)} - -{/snippet} - -
+
-
@@ -93,10 +56,9 @@
{#each STATUS as status (status.token)} -
+
- Like + Like
-
- {#each STATUS as status (status.token)}{@render tag(status.token)}{/each} - {@render tag('popover')} -
-
+
-
-
+
+
Delete playlist? - Cancel - Delete + Cancel + Delete
-
- {@render tag('overlay')} - {@render tag('secondary')} - {@render tag('danger')} - {@render tag('danger_foreground')} -
+
+ +
- Play - Play - Delete + Play + Play + Delete -
- {@render tag('primary_hover')} - {@render tag('danger_hover')} -
-
- 1 · The Water Is Wide - 2 · Wild Mountain Thyme - 3 · Loch Lomond - 4 · The Lark in the Clear Air -
-
- {@render tag('table_row_border')} - {@render tag('table_hover')} - {@render tag('table_active')} - {@render tag('muted')} +
+ 1 · The Water Is Wide + 2 · Wild Mountain Thyme + 3 · Loch Lomond + 4 · The Lark in the Clear Air
+
+ +
- Search songs - - - - Home + Search songs + + + + Home
-
- {@render tag('selection')} - {@render tag('sidebar_accent')} -
-
+
-
-
+
+
Airs and Ballads Traditional
-
-
- +
+
+ +
+
+
+ Sign in to Sonora
-
- {@render tag('overlay_foreground')} - {@render tag('title_bar_border')} -
@@ -230,36 +171,26 @@ diff --git a/src/routes/themes/creator/+page.svelte b/src/routes/themes/creator/+page.svelte index 9b916e6..d91e957 100644 --- a/src/routes/themes/creator/+page.svelte +++ b/src/routes/themes/creator/+page.svelte @@ -1,9 +1,9 @@ @@ -420,7 +456,6 @@
{group.area} - {#each group.names as name, index (name)}{name}{index < - group.names.length - 1 + {#each group.tokens as name, index (name)}{name}{index < + group.tokens.length - 1 ? ' ' : ''}{/each}