Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
eb39aa1
feat(themes): add a theme creator on a labelled mock of the current app
nolight132 Nov 29, 2026
febd105
fix(themes): show the creator's labels at once and restyle its sliders
nolight132 Nov 29, 2026
5b493b4
feat(themes): refuse unreadable themes from the creator and the submi…
nolight132 Nov 29, 2026
627d7c3
fix(themes): explain disabled creator buttons in a tooltip instead of…
nolight132 Nov 29, 2026
ee780d3
fix(themes): refuse only unreadable text, not faint icons
nolight132 Nov 29, 2026
b594273
feat(themes): show menus, dialogs, toasts and row states under the cr…
nolight132 Nov 29, 2026
b4b187c
fix(themes): start the creator without labels, copy links over http too
nolight132 Nov 29, 2026
760c5fc
fix(themes): keep the creator in plain dark or light and drop the moc…
nolight132 Nov 29, 2026
cbe80ac
feat(themes): lead from the gallery to the theme creator
nolight132 Nov 29, 2026
6289e0d
feat(themes): show every colour the creator edits and find it on click
nolight132 Nov 29, 2026
347fb1f
fix(themes): centre the colour the creator finds
nolight132 Nov 29, 2026
825e731
fix(themes): keep the creator's colour list still while readability c…
nolight132 Nov 29, 2026
31871cf
fix(themes): draw the creator's play and like marks as centred icons
nolight132 Nov 29, 2026
36b4068
fix(themes): start the creator with labels on
nolight132 Nov 29, 2026
209b528
fix(themes): check button hovers on dialogs too
nolight132 Nov 29, 2026
842cfdf
feat(themes): lay the creator out as a panel and a canvas that scroll…
nolight132 Nov 29, 2026
7645803
feat(themes): label the creator's extra parts like the mock and keep …
nolight132 Nov 29, 2026
f36ef7a
feat(themes): edit colours in a floating vanilla-colorful picker besi…
nolight132 Nov 29, 2026
6b339c3
fix(themes): keep the colour editor still while contrast changes
nolight132 Nov 29, 2026
582f336
fix(themes): check muted text on every tinted fill sonora draws it on
nolight132 Nov 29, 2026
708b794
style(themes): draw scheme menu swatches as split circles
nolight132 Nov 29, 2026
c30b7a0
feat(mock): open the window on quiet hours with promenade playing
nolight132 Nov 29, 2026
a2334d7
fix(themes): answer the creator review and start without labels
nolight132 Nov 29, 2026
944f050
fix(themes): keep linked themes on reload and typed colours exact
nolight132 Nov 29, 2026
b502c74
fix(themes): fold the sliders in whenever a typed colour cannot come …
nolight132 Nov 29, 2026
2fb61e3
fix(themes): show the colour that lands in the hex field
nolight132 Nov 29, 2026
ff7dd4d
fix(mock): stop the opening loop once repeat or shuffle is touched
nolight132 Nov 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"wrangler": "^4.130.0"
},
"dependencies": {
"flag-icons": "^7.5.0"
"flag-icons": "^7.5.0",
"vanilla-colorful": "0.7.2"
}
}
13 changes: 9 additions & 4 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
root.classList.add('js');

try {
const scheme = localStorage.getItem('scheme');
// the theme creator wears plain Dark or Light, so the site never competes with the theme
const plain = location.pathname.startsWith('/themes/creator');
const scheme = localStorage.getItem('scheme') ?? (plain ? 'Dark' : null);
if (scheme) {
const slug = scheme
.toLowerCase()
Expand All @@ -30,14 +32,17 @@
'rose-pine-dawn',
'solarized-light'
];
root.dataset.scheme = slug;
root.dataset.theme = light.includes(slug) ? 'light' : 'dark';
const bright = light.includes(slug);
root.dataset.scheme = plain ? (bright ? 'light' : 'dark') : slug;
root.dataset.theme = bright ? 'light' : 'dark';
}
} catch {}

try {
const nav = performance.getEntriesByType('navigation')[0];
if (location.hash && (!nav || nav.type === 'reload')) {
const shared =
location.pathname.startsWith('/themes/creator') && location.hash.startsWith('#theme=');
if (location.hash && !shared && (!nav || nav.type === 'reload')) {
history.replaceState(history.state, '', location.pathname + location.search);
}
} catch {}
Expand Down
180 changes: 180 additions & 0 deletions src/lib/color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/** 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(Math.max(0, (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));
}
73 changes: 73 additions & 0 deletions src/lib/components/Checkbox.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<script lang="ts">
import type { Snippet } from 'svelte';

/** A checkbox drawn the way shadcn/ui draws one, with its label beside it. */
let { checked = $bindable(false), children }: { checked?: boolean; children?: Snippet } =
$props();
</script>

<label class="checkbox">
<button
type="button"
role="checkbox"
aria-checked={checked}
class="box"
onclick={() => (checked = !checked)}
>
{#if checked}
<svg
width="12"
height="12"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="3"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"><path d="M20 6 9 17l-5-5" /></svg
>
{/if}
</button>
{@render children?.()}
</label>

<style>
.checkbox {
display: inline-flex;
align-items: center;
gap: 8px;
font-size: 14px;
font-weight: 500;
line-height: 1;
color: var(--fg);
cursor: pointer;
user-select: none;
}

.box {
display: grid;
place-items: center;
flex: none;
width: 16px;
height: 16px;
padding: 0;
border: 1px solid var(--border);
border-radius: 4px;
background: transparent;
color: var(--primary-fg);
box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
transition:
background-color 0.15s ease,
border-color 0.15s ease;
}

.box[aria-checked='true'] {
border-color: var(--primary);
background: var(--primary);
}

.box:focus-visible {
outline: none;
box-shadow: 0 0 0 3px color-mix(in srgb, var(--fg) 25%, transparent);
}
</style>
66 changes: 66 additions & 0 deletions src/lib/components/ColorPicker.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<script lang="ts">
import { onMount } from 'svelte';
import { normal } from '$lib/color';

/**
* A colour picker with an alpha slider, the `<hex-alpha-color-picker>` element of
* vanilla-colorful. The element is loaded in the browser only, since it defines itself on
* `customElements`.
*/
let {
value,
onchange
}: {
/** The colour shown, as theme file hex. */
value: string;
/** Called with every colour the visitor picks, as theme file hex. */
onchange: (value: string) => void;
} = $props();

let element = $state<HTMLElement & { color: string }>();
let ready = $state(false);

onMount(() => {
import('vanilla-colorful/hex-alpha-color-picker.js').then(() => (ready = true));
});

$effect(() => {
const picker = element;
if (!picker || !ready) return;
const picked = (event: Event) =>
onchange(normal((event as CustomEvent<{ value: string }>).detail.value));
picker.addEventListener('color-changed', picked);
return () => picker.removeEventListener('color-changed', picked);
});

$effect(() => {
if (element && ready && normal(element.color ?? '') !== value) element.color = value;
});
</script>

<hex-alpha-color-picker bind:this={element} class="picker"></hex-alpha-color-picker>

<style>
.picker {
width: 100%;
height: 190px;
}

.picker::part(saturation) {
border-radius: 8px 8px 0 0;
}

.picker::part(hue),
.picker::part(alpha) {
flex-basis: 14px;
margin-top: 10px;
border-radius: 7px;
}

.picker::part(hue-pointer),
.picker::part(alpha-pointer),
.picker::part(saturation-pointer) {
width: 16px;
height: 16px;
}
</style>
5 changes: 2 additions & 3 deletions src/lib/components/Preview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
.frame {
width: max-content;
max-width: 100%;
border: 1px solid var(--border);
border-radius: 12px;
overflow: hidden;
background: var(--bg);
Expand All @@ -101,8 +100,8 @@

.ghost {
display: none;
width: 1172px;
height: 732px;
width: 1170px;
height: 730px;
}

@media (min-width: 1280px) {
Expand Down
Loading