@hollis-labs/surface-theme 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -2
- package/dist/check.d.ts +18 -0
- package/dist/check.js +36 -0
- package/dist/color.d.ts +19 -0
- package/dist/color.js +64 -0
- package/dist/import.d.ts +12 -0
- package/dist/import.js +128 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/palette.d.ts +44 -0
- package/dist/palette.js +55 -0
- package/dist/palettes.d.ts +9 -0
- package/dist/palettes.js +242 -0
- package/package.json +36 -4
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @hollis-labs/surface-theme
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The palettes behind the Surface theme. A palette is what a Linux theme says about colour, in one shape:
|
|
4
|
+
background, foreground, accent, selection and the terminal's red, green, yellow, blue, magenta and cyan.
|
|
5
|
+
The theme (`registry/theme/surface.css`) derives every UI token from those, in the browser, so a palette
|
|
6
|
+
is all a theme needs.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { applyPalette, checkPalette, PALETTES, paletteById, parseTheme } from "@hollis-labs/surface-theme"
|
|
10
|
+
|
|
11
|
+
applyPalette(paletteById("tokyo-night")!) // the page follows: surfaces, borders, primary, states
|
|
12
|
+
applyPalette(parseTheme(text, "Mine"), el, "mono") // an Omarchy colors.toml, base16 YAML or pywal JSON
|
|
13
|
+
checkPalette(p) // WCAG contrast of the pairs the theme draws with
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- **Shipped:** Blade Runner (the default), Aura, Moodpeak and Cyberphunk (Basalisk's), and Omarchy's
|
|
17
|
+
Tokyo Night, Catppuccin, Gruvbox, Nord, Kanagawa, Everforest, Matte Black, Hackerman and Retro 82.
|
|
18
|
+
- **Read:** Omarchy `colors.toml` (named keys or `color0`..`color15`), base16 / tinted-theming schemes
|
|
19
|
+
(`base00`..`base0F`), pywal / wallust `colors.json`.
|
|
20
|
+
- **Type:** `applyPalette(p, el, "mono")` sets everything in the mono font; `"mixed"` keeps mono chrome over
|
|
21
|
+
a sans body.
|
package/dist/check.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Palette } from "./palette.ts";
|
|
2
|
+
export interface ContrastResult {
|
|
3
|
+
pair: string;
|
|
4
|
+
ratio: number;
|
|
5
|
+
/** What it must reach: 4.5 for text, 3 for large text and marks (borders, rings, icons). */
|
|
6
|
+
min: number;
|
|
7
|
+
ok: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** The derived colours the check looks at, as surface.css derives them. */
|
|
10
|
+
export declare function derived(p: Palette): {
|
|
11
|
+
background: string;
|
|
12
|
+
card: string;
|
|
13
|
+
muted: string;
|
|
14
|
+
mutedForeground: string;
|
|
15
|
+
primary: string;
|
|
16
|
+
primaryForeground: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function checkPalette(p: Palette): ContrastResult[];
|
package/dist/check.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a palette reads: the pairs the theme draws text and marks with, measured on the colours the
|
|
3
|
+
* theme derives (the same mixes surface.css makes), against WCAG's thresholds.
|
|
4
|
+
*/
|
|
5
|
+
import { contrast, mix } from "./color.js";
|
|
6
|
+
/** The derived colours the check looks at, as surface.css derives them. */
|
|
7
|
+
export function derived(p) {
|
|
8
|
+
const card = mix(p.background, p.foreground, 0.045);
|
|
9
|
+
return {
|
|
10
|
+
background: p.background,
|
|
11
|
+
card,
|
|
12
|
+
muted: mix(p.background, p.foreground, 0.1),
|
|
13
|
+
mutedForeground: mix(p.foreground, p.background, 0.28),
|
|
14
|
+
primary: p.accent,
|
|
15
|
+
// Button text is the background colour: the rice look, a dark label on a bright accent.
|
|
16
|
+
primaryForeground: p.background,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function checkPalette(p) {
|
|
20
|
+
const d = derived(p);
|
|
21
|
+
const pairs = [
|
|
22
|
+
["text on background", p.foreground, d.background, 4.5],
|
|
23
|
+
["text on card", p.foreground, d.card, 4.5],
|
|
24
|
+
["muted text on background", d.mutedForeground, d.background, 4.5],
|
|
25
|
+
["muted text on card", d.mutedForeground, d.card, 4.5],
|
|
26
|
+
["button text on primary", d.primaryForeground, d.primary, 4.5],
|
|
27
|
+
["accent mark on background", p.accent, d.background, 3],
|
|
28
|
+
["error on card", p.red, d.card, 3],
|
|
29
|
+
["success on card", p.green, d.card, 3],
|
|
30
|
+
["warning on card", p.yellow, d.card, 3],
|
|
31
|
+
];
|
|
32
|
+
return pairs.map(([pair, a, b, min]) => {
|
|
33
|
+
const ratio = Math.round(contrast(a, b) * 100) / 100;
|
|
34
|
+
return { pair, ratio, min, ok: ratio >= min };
|
|
35
|
+
});
|
|
36
|
+
}
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Colour arithmetic the theme check needs: hex <-> sRGB, OKLab mixing (what CSS color-mix in oklch
|
|
2
|
+
* does), relative luminance and WCAG contrast. */
|
|
3
|
+
export type RGB = [number, number, number];
|
|
4
|
+
/** "#rgb", "#rrggbb" or "rrggbb" to sRGB in 0..1; undefined when it is not a colour. */
|
|
5
|
+
export declare function parseHex(s: string): RGB | undefined;
|
|
6
|
+
/** A colour as "#rrggbb" (lower case), or undefined when it is not one. */
|
|
7
|
+
export declare function normalizeHex(s: string | undefined): string | undefined;
|
|
8
|
+
export declare function toHex(c: RGB): string;
|
|
9
|
+
/** sRGB to OKLab. */
|
|
10
|
+
export declare function toOklab([r, g, b]: RGB): RGB;
|
|
11
|
+
/** OKLab to sRGB (clamped). */
|
|
12
|
+
export declare function fromOklab([L, a, b]: RGB): RGB;
|
|
13
|
+
/** color-mix(in oklab, a, b weight): weight is b's share, 0..1. Close to the theme's oklch mixes for
|
|
14
|
+
* the near-neutral surfaces it builds, and exact for lightness, which is what contrast depends on. */
|
|
15
|
+
export declare function mix(a: string, b: string, weight: number): string;
|
|
16
|
+
/** WCAG relative luminance. */
|
|
17
|
+
export declare function luminance(hex: string): number;
|
|
18
|
+
/** WCAG contrast ratio, 1..21. */
|
|
19
|
+
export declare function contrast(a: string, b: string): number;
|
package/dist/color.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Colour arithmetic the theme check needs: hex <-> sRGB, OKLab mixing (what CSS color-mix in oklch
|
|
2
|
+
* does), relative luminance and WCAG contrast. */
|
|
3
|
+
/** "#rgb", "#rrggbb" or "rrggbb" to sRGB in 0..1; undefined when it is not a colour. */
|
|
4
|
+
export function parseHex(s) {
|
|
5
|
+
let h = s.trim().replace(/^#/, "");
|
|
6
|
+
if (/^[0-9a-f]{3}$/i.test(h))
|
|
7
|
+
h = [...h].map((c) => c + c).join("");
|
|
8
|
+
if (!/^[0-9a-f]{6}([0-9a-f]{2})?$/i.test(h))
|
|
9
|
+
return undefined;
|
|
10
|
+
return [0, 2, 4].map((i) => Number.parseInt(h.slice(i, i + 2), 16) / 255);
|
|
11
|
+
}
|
|
12
|
+
/** A colour as "#rrggbb" (lower case), or undefined when it is not one. */
|
|
13
|
+
export function normalizeHex(s) {
|
|
14
|
+
const c = s === undefined ? undefined : parseHex(s);
|
|
15
|
+
return c ? toHex(c) : undefined;
|
|
16
|
+
}
|
|
17
|
+
export function toHex(c) {
|
|
18
|
+
return `#${c
|
|
19
|
+
.map((v) => Math.round(Math.min(1, Math.max(0, v)) * 255)
|
|
20
|
+
.toString(16)
|
|
21
|
+
.padStart(2, "0"))
|
|
22
|
+
.join("")}`;
|
|
23
|
+
}
|
|
24
|
+
const lin = (v) => (v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);
|
|
25
|
+
const gam = (v) => (v <= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055);
|
|
26
|
+
/** sRGB to OKLab. */
|
|
27
|
+
export function toOklab([r, g, b]) {
|
|
28
|
+
const [R, G, B] = [lin(r), lin(g), lin(b)];
|
|
29
|
+
const l = Math.cbrt(0.4122214708 * R + 0.5363325363 * G + 0.0514459929 * B);
|
|
30
|
+
const m = Math.cbrt(0.2119034982 * R + 0.6806995451 * G + 0.1073969566 * B);
|
|
31
|
+
const s = Math.cbrt(0.0883024619 * R + 0.2817188376 * G + 0.6299787005 * B);
|
|
32
|
+
return [
|
|
33
|
+
0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
|
34
|
+
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
|
35
|
+
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
/** OKLab to sRGB (clamped). */
|
|
39
|
+
export function fromOklab([L, a, b]) {
|
|
40
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
41
|
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
42
|
+
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
43
|
+
const R = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s;
|
|
44
|
+
const G = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s;
|
|
45
|
+
const B = -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s;
|
|
46
|
+
return [R, G, B].map((v) => Math.min(1, Math.max(0, gam(v))));
|
|
47
|
+
}
|
|
48
|
+
/** color-mix(in oklab, a, b weight): weight is b's share, 0..1. Close to the theme's oklch mixes for
|
|
49
|
+
* the near-neutral surfaces it builds, and exact for lightness, which is what contrast depends on. */
|
|
50
|
+
export function mix(a, b, weight) {
|
|
51
|
+
const A = toOklab(parseHex(a) ?? [0, 0, 0]);
|
|
52
|
+
const B = toOklab(parseHex(b) ?? [0, 0, 0]);
|
|
53
|
+
return toHex(fromOklab(A.map((v, i) => v * (1 - weight) + (B[i] ?? 0) * weight)));
|
|
54
|
+
}
|
|
55
|
+
/** WCAG relative luminance. */
|
|
56
|
+
export function luminance(hex) {
|
|
57
|
+
const [r, g, b] = (parseHex(hex) ?? [0, 0, 0]).map(lin);
|
|
58
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
59
|
+
}
|
|
60
|
+
/** WCAG contrast ratio, 1..21. */
|
|
61
|
+
export function contrast(a, b) {
|
|
62
|
+
const [x, y] = [luminance(a), luminance(b)].sort((p, q) => q - p);
|
|
63
|
+
return (x + 0.05) / (y + 0.05);
|
|
64
|
+
}
|
package/dist/import.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Palette } from "./palette.ts";
|
|
2
|
+
export type ThemeFormat = "omarchy" | "base16" | "pywal";
|
|
3
|
+
/** Omarchy's colors.toml. */
|
|
4
|
+
export declare function parseOmarchy(text: string, name?: string): Palette;
|
|
5
|
+
/** A base16 / tinted-theming scheme. */
|
|
6
|
+
export declare function parseBase16(text: string, fallbackName?: string): Palette;
|
|
7
|
+
/** pywal's (or wallust's) colors.json. */
|
|
8
|
+
export declare function parsePywal(text: string, name?: string): Palette;
|
|
9
|
+
/** Which format a theme file is in. */
|
|
10
|
+
export declare function detectFormat(text: string): ThemeFormat;
|
|
11
|
+
/** Any supported theme file to a Palette. */
|
|
12
|
+
export declare function parseTheme(text: string, name?: string): Palette;
|
package/dist/import.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading the common Linux theme formats into a Palette:
|
|
3
|
+
* - Omarchy's colors.toml (named keys: background, foreground, accent, red..., or color0..color15),
|
|
4
|
+
* - base16 / tinted-theming schemes (YAML: base00..base0F, flat or under palette:),
|
|
5
|
+
* - pywal / wallust colors.json (special.background/foreground, colors.color0..color15).
|
|
6
|
+
* parseTheme picks the format from the text.
|
|
7
|
+
*/
|
|
8
|
+
import { luminance, mix, normalizeHex } from "./color.js";
|
|
9
|
+
const slug = (s) => s
|
|
10
|
+
.toLowerCase()
|
|
11
|
+
.normalize("NFKD")
|
|
12
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
13
|
+
.replace(/^-|-$/g, "") || "imported";
|
|
14
|
+
const modeOf = (bg) => (luminance(bg) < 0.25 ? "dark" : "light");
|
|
15
|
+
function need(v, what, format) {
|
|
16
|
+
if (!v)
|
|
17
|
+
throw new Error(`${format}: no ${what} in the theme`);
|
|
18
|
+
return v;
|
|
19
|
+
}
|
|
20
|
+
/** Omarchy's colors.toml. */
|
|
21
|
+
export function parseOmarchy(text, name = "Imported") {
|
|
22
|
+
const kv = {};
|
|
23
|
+
for (const m of text.matchAll(/^\s*([a-z0-9_]+)\s*=\s*["']?([^"'\n#]*?#?[0-9a-z]+)["']?\s*(?:#.*)?$/gim)) {
|
|
24
|
+
kv[(m[1] ?? "").toLowerCase()] = m[2] ?? "";
|
|
25
|
+
}
|
|
26
|
+
const c = (...keys) => {
|
|
27
|
+
for (const k of keys) {
|
|
28
|
+
const v = normalizeHex(kv[k]);
|
|
29
|
+
if (v)
|
|
30
|
+
return v;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
};
|
|
34
|
+
const background = need(c("background", "color0"), "background", "omarchy");
|
|
35
|
+
const foreground = need(c("foreground", "color7", "color15"), "foreground", "omarchy");
|
|
36
|
+
const blue = need(c("blue", "color4"), "blue", "omarchy");
|
|
37
|
+
return {
|
|
38
|
+
id: slug(name),
|
|
39
|
+
name,
|
|
40
|
+
mode: kv.mode === "light" ? "light" : kv.mode === "dark" ? "dark" : modeOf(background),
|
|
41
|
+
source: "Omarchy colors.toml",
|
|
42
|
+
background,
|
|
43
|
+
foreground,
|
|
44
|
+
muted: c("muted", "dark_foreground", "color8"),
|
|
45
|
+
accent: c("accent") ?? blue,
|
|
46
|
+
selection: c("selection", "selection_background"),
|
|
47
|
+
red: need(c("red", "color1"), "red", "omarchy"),
|
|
48
|
+
green: need(c("green", "color2"), "green", "omarchy"),
|
|
49
|
+
yellow: need(c("yellow", "color3"), "yellow", "omarchy"),
|
|
50
|
+
blue,
|
|
51
|
+
magenta: need(c("magenta", "color5"), "magenta", "omarchy"),
|
|
52
|
+
cyan: need(c("cyan", "color6"), "cyan", "omarchy"),
|
|
53
|
+
orange: c("orange"),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** A base16 / tinted-theming scheme. */
|
|
57
|
+
export function parseBase16(text, fallbackName = "Imported") {
|
|
58
|
+
const b = {};
|
|
59
|
+
for (const m of text.matchAll(/\bbase0([0-9a-f])\s*:\s*["']?#?([0-9a-f]{6})["']?/gi)) {
|
|
60
|
+
b[(m[1] ?? "").toUpperCase()] = `#${(m[2] ?? "").toLowerCase()}`;
|
|
61
|
+
}
|
|
62
|
+
const name = text.match(/^\s*(?:name|scheme)\s*:\s*["']?([^"'\n]+?)["']?\s*$/im)?.[1] ?? fallbackName;
|
|
63
|
+
const variant = text.match(/^\s*variant\s*:\s*["']?(dark|light)["']?\s*$/im)?.[1];
|
|
64
|
+
const g = (k) => need(b[k], `base0${k}`, "base16");
|
|
65
|
+
const background = g("0");
|
|
66
|
+
return {
|
|
67
|
+
id: slug(name),
|
|
68
|
+
name,
|
|
69
|
+
mode: variant ?? modeOf(background),
|
|
70
|
+
source: "base16",
|
|
71
|
+
background,
|
|
72
|
+
foreground: g("5"),
|
|
73
|
+
muted: g("3"),
|
|
74
|
+
accent: g("D"),
|
|
75
|
+
selection: g("2"),
|
|
76
|
+
red: g("8"),
|
|
77
|
+
orange: b["9"],
|
|
78
|
+
yellow: g("A"),
|
|
79
|
+
green: g("B"),
|
|
80
|
+
cyan: g("C"),
|
|
81
|
+
blue: g("D"),
|
|
82
|
+
magenta: g("E"),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** pywal's (or wallust's) colors.json. */
|
|
86
|
+
export function parsePywal(text, name = "Imported") {
|
|
87
|
+
const j = JSON.parse(text);
|
|
88
|
+
const col = (n) => normalizeHex(j.colors?.[`color${n}`]);
|
|
89
|
+
const background = need(normalizeHex(j.special?.background) ?? col(0), "background", "pywal");
|
|
90
|
+
const foreground = need(normalizeHex(j.special?.foreground) ?? col(7), "foreground", "pywal");
|
|
91
|
+
const blue = need(col(4), "color4", "pywal");
|
|
92
|
+
return {
|
|
93
|
+
id: slug(name),
|
|
94
|
+
name,
|
|
95
|
+
mode: modeOf(background),
|
|
96
|
+
source: "pywal",
|
|
97
|
+
background,
|
|
98
|
+
foreground,
|
|
99
|
+
muted: col(8) ?? mix(foreground, background, 0.45),
|
|
100
|
+
accent: blue,
|
|
101
|
+
red: need(col(1), "color1", "pywal"),
|
|
102
|
+
green: need(col(2), "color2", "pywal"),
|
|
103
|
+
yellow: need(col(3), "color3", "pywal"),
|
|
104
|
+
blue,
|
|
105
|
+
magenta: need(col(5), "color5", "pywal"),
|
|
106
|
+
cyan: need(col(6), "color6", "pywal"),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** Which format a theme file is in. */
|
|
110
|
+
export function detectFormat(text) {
|
|
111
|
+
const t = text.trim();
|
|
112
|
+
if (t.startsWith("{"))
|
|
113
|
+
return "pywal";
|
|
114
|
+
if (/\bbase0[0-9a-f]\s*:/i.test(t))
|
|
115
|
+
return "base16";
|
|
116
|
+
return "omarchy";
|
|
117
|
+
}
|
|
118
|
+
/** Any supported theme file to a Palette. */
|
|
119
|
+
export function parseTheme(text, name) {
|
|
120
|
+
switch (detectFormat(text)) {
|
|
121
|
+
case "pywal":
|
|
122
|
+
return parsePywal(text, name);
|
|
123
|
+
case "base16":
|
|
124
|
+
return parseBase16(text, name);
|
|
125
|
+
default:
|
|
126
|
+
return parseOmarchy(text, name);
|
|
127
|
+
}
|
|
128
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type ContrastResult, checkPalette, derived } from "./check.ts";
|
|
2
|
+
export { contrast, luminance, mix, normalizeHex, parseHex } from "./color.ts";
|
|
3
|
+
export { detectFormat, parseBase16, parseOmarchy, parsePywal, parseTheme, type ThemeFormat } from "./import.ts";
|
|
4
|
+
export { applyPalette, PALETTE_VARS, type Palette, paletteCSS, type TypeStyle } from "./palette.ts";
|
|
5
|
+
export { DEFAULT_PALETTE, PALETTES, paletteById } from "./palettes.ts";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { checkPalette, derived } from "./check.js";
|
|
2
|
+
export { contrast, luminance, mix, normalizeHex, parseHex } from "./color.js";
|
|
3
|
+
export { detectFormat, parseBase16, parseOmarchy, parsePywal, parseTheme } from "./import.js";
|
|
4
|
+
export { applyPalette, PALETTE_VARS, paletteCSS } from "./palette.js";
|
|
5
|
+
export { DEFAULT_PALETTE, PALETTES, paletteById } from "./palettes.js";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A palette: what a Linux theme says about colour, in one shape. Every theme format reduces to this
|
|
3
|
+
* (Omarchy's colors.toml, base16 / tinted-theming, pywal / wallust, a terminal's 16 colours), and
|
|
4
|
+
* the Surface theme derives every UI token from it in CSS: surfaces, borders, primary, ring,
|
|
5
|
+
* success / warning / error / info, charts.
|
|
6
|
+
*/
|
|
7
|
+
export interface Palette {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
mode: "dark" | "light";
|
|
11
|
+
/** Where it came from, in a few words. */
|
|
12
|
+
source?: string;
|
|
13
|
+
background: string;
|
|
14
|
+
foreground: string;
|
|
15
|
+
/** Quiet text and lines; derived from foreground and background when absent. */
|
|
16
|
+
muted?: string;
|
|
17
|
+
/** The one colour that says "this": primary buttons, the focus ring, selection marks. */
|
|
18
|
+
accent: string;
|
|
19
|
+
/** A second accent for highlights and the far end of a gradient border; cyan when absent. */
|
|
20
|
+
accent2?: string;
|
|
21
|
+
/** Selected text and selected rows. */
|
|
22
|
+
selection?: string;
|
|
23
|
+
red: string;
|
|
24
|
+
green: string;
|
|
25
|
+
yellow: string;
|
|
26
|
+
blue: string;
|
|
27
|
+
magenta: string;
|
|
28
|
+
cyan: string;
|
|
29
|
+
orange?: string;
|
|
30
|
+
}
|
|
31
|
+
/** The CSS custom properties a palette sets (the theme's --p-* inputs), by palette field. */
|
|
32
|
+
export declare const PALETTE_VARS: Record<Exclude<keyof Palette, "id" | "name" | "mode" | "source">, string>;
|
|
33
|
+
/** The CSS a palette is: its --p-* properties, for a stylesheet or an element's style. The optional
|
|
34
|
+
* colours a palette leaves out come from its own (never from the default palette's): the second
|
|
35
|
+
* accent is its cyan, selection its background a quarter toward the accent, muted its foreground
|
|
36
|
+
* halfway to the background, orange between its red and yellow. */
|
|
37
|
+
export declare function paletteCSS(p: Palette): Record<string, string>;
|
|
38
|
+
/** The type style: mono chrome over sans body ("mixed"), or mono everywhere ("mono"). */
|
|
39
|
+
export type TypeStyle = "mixed" | "mono";
|
|
40
|
+
/**
|
|
41
|
+
* Applies a palette (and, when given, a type style) to an element, the page's root by default. Fields
|
|
42
|
+
* the palette leaves out fall back to the theme's derivation. Returns a function that removes them.
|
|
43
|
+
*/
|
|
44
|
+
export declare function applyPalette(p: Palette, el?: HTMLElement, type?: TypeStyle): () => void;
|
package/dist/palette.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { mix } from "./color.js";
|
|
2
|
+
/** The CSS custom properties a palette sets (the theme's --p-* inputs), by palette field. */
|
|
3
|
+
export const PALETTE_VARS = {
|
|
4
|
+
background: "--p-bg",
|
|
5
|
+
foreground: "--p-fg",
|
|
6
|
+
muted: "--p-muted",
|
|
7
|
+
accent: "--p-accent",
|
|
8
|
+
accent2: "--p-accent-2",
|
|
9
|
+
selection: "--p-selection",
|
|
10
|
+
red: "--p-red",
|
|
11
|
+
green: "--p-green",
|
|
12
|
+
yellow: "--p-yellow",
|
|
13
|
+
blue: "--p-blue",
|
|
14
|
+
magenta: "--p-magenta",
|
|
15
|
+
cyan: "--p-cyan",
|
|
16
|
+
orange: "--p-orange",
|
|
17
|
+
};
|
|
18
|
+
/** The CSS a palette is: its --p-* properties, for a stylesheet or an element's style. The optional
|
|
19
|
+
* colours a palette leaves out come from its own (never from the default palette's): the second
|
|
20
|
+
* accent is its cyan, selection its background a quarter toward the accent, muted its foreground
|
|
21
|
+
* halfway to the background, orange between its red and yellow. */
|
|
22
|
+
export function paletteCSS(p) {
|
|
23
|
+
const full = {
|
|
24
|
+
...p,
|
|
25
|
+
accent2: p.accent2 ?? p.cyan,
|
|
26
|
+
selection: p.selection ?? mix(p.background, p.accent, 0.25),
|
|
27
|
+
muted: p.muted ?? mix(p.foreground, p.background, 0.45),
|
|
28
|
+
orange: p.orange ?? mix(p.red, p.yellow, 0.5),
|
|
29
|
+
};
|
|
30
|
+
const out = {};
|
|
31
|
+
for (const [field, name] of Object.entries(PALETTE_VARS))
|
|
32
|
+
out[name] = full[field];
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Applies a palette (and, when given, a type style) to an element, the page's root by default. Fields
|
|
37
|
+
* the palette leaves out fall back to the theme's derivation. Returns a function that removes them.
|
|
38
|
+
*/
|
|
39
|
+
export function applyPalette(p, el = document.documentElement, type) {
|
|
40
|
+
const css = paletteCSS(p);
|
|
41
|
+
for (const name of Object.values(PALETTE_VARS))
|
|
42
|
+
el.style.removeProperty(name);
|
|
43
|
+
for (const [name, v] of Object.entries(css))
|
|
44
|
+
el.style.setProperty(name, v);
|
|
45
|
+
el.dataset.palette = p.id;
|
|
46
|
+
el.classList.toggle("dark", p.mode === "dark");
|
|
47
|
+
el.style.colorScheme = p.mode;
|
|
48
|
+
if (type)
|
|
49
|
+
el.dataset.type = type;
|
|
50
|
+
return () => {
|
|
51
|
+
for (const name of Object.values(PALETTE_VARS))
|
|
52
|
+
el.style.removeProperty(name);
|
|
53
|
+
delete el.dataset.palette;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The palettes Surface ships. Blade Runner is the default (the theme's CSS carries it too). Generated from
|
|
2
|
+
* Basalisk's themes (frontend/src/desktop/themes.ts) and Omarchy's colors.toml files (github.com/basecamp/omarchy,
|
|
3
|
+
* themes/<name>/colors.toml); dark ones only for now. */
|
|
4
|
+
import type { Palette } from "./palette.ts";
|
|
5
|
+
export declare const PALETTES: Palette[];
|
|
6
|
+
/** The default palette. */
|
|
7
|
+
export declare const DEFAULT_PALETTE: Palette;
|
|
8
|
+
/** A shipped palette by id. */
|
|
9
|
+
export declare function paletteById(id: string): Palette | undefined;
|
package/dist/palettes.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
export const PALETTES = [
|
|
2
|
+
{
|
|
3
|
+
id: "blade-runner",
|
|
4
|
+
name: "Blade Runner",
|
|
5
|
+
mode: "dark",
|
|
6
|
+
source: "Basalisk (Omarchy community theme)",
|
|
7
|
+
background: "#0e1417",
|
|
8
|
+
foreground: "#c6d2d2",
|
|
9
|
+
muted: "#68797e",
|
|
10
|
+
accent: "#e0a062",
|
|
11
|
+
accent2: "#7ecfd4",
|
|
12
|
+
selection: "#223038",
|
|
13
|
+
red: "#e05c52",
|
|
14
|
+
green: "#7fa66a",
|
|
15
|
+
yellow: "#d9a441",
|
|
16
|
+
blue: "#6aa7c4",
|
|
17
|
+
magenta: "#c07fa8",
|
|
18
|
+
cyan: "#7ecfd4",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "aura",
|
|
22
|
+
name: "Aura",
|
|
23
|
+
mode: "dark",
|
|
24
|
+
source: "Basalisk (Omarchy community theme)",
|
|
25
|
+
background: "#15141b",
|
|
26
|
+
foreground: "#edecee",
|
|
27
|
+
muted: "#6d6d6d",
|
|
28
|
+
accent: "#a277ff",
|
|
29
|
+
accent2: "#61ffca",
|
|
30
|
+
selection: "#29263c",
|
|
31
|
+
red: "#ff6767",
|
|
32
|
+
green: "#61ffca",
|
|
33
|
+
yellow: "#ffca85",
|
|
34
|
+
blue: "#a277ff",
|
|
35
|
+
magenta: "#f694ff",
|
|
36
|
+
cyan: "#82e2ff",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "moodpeak",
|
|
40
|
+
name: "Moodpeak",
|
|
41
|
+
mode: "dark",
|
|
42
|
+
source: "Basalisk (Omarchy community theme)",
|
|
43
|
+
background: "#181c22",
|
|
44
|
+
foreground: "#e0e6ed",
|
|
45
|
+
muted: "#7b8599",
|
|
46
|
+
accent: "#4ecdc4",
|
|
47
|
+
accent2: "#b388eb",
|
|
48
|
+
selection: "#2c3444",
|
|
49
|
+
red: "#ff7b92",
|
|
50
|
+
green: "#4ecdc4",
|
|
51
|
+
yellow: "#82eeff",
|
|
52
|
+
blue: "#6a85ff",
|
|
53
|
+
magenta: "#b388eb",
|
|
54
|
+
cyan: "#c9aff0",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "cyberphunk",
|
|
58
|
+
name: "Cyberphunk",
|
|
59
|
+
mode: "dark",
|
|
60
|
+
source: "Basalisk (Omarchy community theme)",
|
|
61
|
+
background: "#060a14",
|
|
62
|
+
foreground: "#e8fcff",
|
|
63
|
+
muted: "#4a6b82",
|
|
64
|
+
accent: "#22e4ff",
|
|
65
|
+
accent2: "#ff6bd6",
|
|
66
|
+
selection: "#14294a",
|
|
67
|
+
red: "#ff3b6b",
|
|
68
|
+
green: "#44ffaa",
|
|
69
|
+
yellow: "#ffaa33",
|
|
70
|
+
blue: "#3ac8ff",
|
|
71
|
+
magenta: "#ff6bd6",
|
|
72
|
+
cyan: "#22e4ff",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: "tokyo-night",
|
|
76
|
+
name: "Tokyo Night",
|
|
77
|
+
mode: "dark",
|
|
78
|
+
source: "Omarchy",
|
|
79
|
+
background: "#1a1b26",
|
|
80
|
+
foreground: "#a9b1d6",
|
|
81
|
+
muted: "#414868",
|
|
82
|
+
accent: "#7aa2f7",
|
|
83
|
+
selection: "#292e42",
|
|
84
|
+
red: "#f7768e",
|
|
85
|
+
green: "#9ece6a",
|
|
86
|
+
yellow: "#e0af68",
|
|
87
|
+
blue: "#7aa2f7",
|
|
88
|
+
magenta: "#ad8ee6",
|
|
89
|
+
cyan: "#449dab",
|
|
90
|
+
orange: "#eb927b",
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: "catppuccin",
|
|
94
|
+
name: "Catppuccin",
|
|
95
|
+
mode: "dark",
|
|
96
|
+
source: "Omarchy",
|
|
97
|
+
background: "#1e1e2e",
|
|
98
|
+
foreground: "#cdd6f4",
|
|
99
|
+
muted: "#585b70",
|
|
100
|
+
accent: "#89b4fa",
|
|
101
|
+
selection: "#45475a",
|
|
102
|
+
red: "#f38ba8",
|
|
103
|
+
green: "#a6e3a1",
|
|
104
|
+
yellow: "#f9e2af",
|
|
105
|
+
blue: "#89b4fa",
|
|
106
|
+
magenta: "#f5c2e7",
|
|
107
|
+
cyan: "#94e2d5",
|
|
108
|
+
orange: "#f6b6ab",
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: "gruvbox",
|
|
112
|
+
name: "Gruvbox",
|
|
113
|
+
mode: "dark",
|
|
114
|
+
source: "Omarchy",
|
|
115
|
+
background: "#282828",
|
|
116
|
+
foreground: "#d4be98",
|
|
117
|
+
muted: "#665c54",
|
|
118
|
+
accent: "#7daea3",
|
|
119
|
+
selection: "#504945",
|
|
120
|
+
red: "#ea6962",
|
|
121
|
+
green: "#a9b665",
|
|
122
|
+
yellow: "#d8a657",
|
|
123
|
+
blue: "#7daea3",
|
|
124
|
+
magenta: "#d3869b",
|
|
125
|
+
cyan: "#89b482",
|
|
126
|
+
orange: "#e1875c",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: "nord",
|
|
130
|
+
name: "Nord",
|
|
131
|
+
mode: "dark",
|
|
132
|
+
source: "Omarchy",
|
|
133
|
+
background: "#2e3440",
|
|
134
|
+
foreground: "#d8dee9",
|
|
135
|
+
muted: "#4c566a",
|
|
136
|
+
accent: "#81a1c1",
|
|
137
|
+
selection: "#434c5e",
|
|
138
|
+
red: "#bf616a",
|
|
139
|
+
green: "#a3be8c",
|
|
140
|
+
yellow: "#ebcb8b",
|
|
141
|
+
blue: "#81a1c1",
|
|
142
|
+
magenta: "#b48ead",
|
|
143
|
+
cyan: "#88c0d0",
|
|
144
|
+
orange: "#d5967a",
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
id: "kanagawa",
|
|
148
|
+
name: "Kanagawa",
|
|
149
|
+
mode: "dark",
|
|
150
|
+
source: "Omarchy",
|
|
151
|
+
background: "#1f1f28",
|
|
152
|
+
foreground: "#dcd7ba",
|
|
153
|
+
muted: "#54546d",
|
|
154
|
+
accent: "#dcd7ba",
|
|
155
|
+
selection: "#363646",
|
|
156
|
+
red: "#c34043",
|
|
157
|
+
green: "#76946a",
|
|
158
|
+
yellow: "#c0a36e",
|
|
159
|
+
blue: "#7e9cd8",
|
|
160
|
+
magenta: "#957fb8",
|
|
161
|
+
cyan: "#6a9589",
|
|
162
|
+
orange: "#c17158",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: "everforest",
|
|
166
|
+
name: "Everforest",
|
|
167
|
+
mode: "dark",
|
|
168
|
+
source: "Omarchy",
|
|
169
|
+
background: "#2d353b",
|
|
170
|
+
foreground: "#d3c6aa",
|
|
171
|
+
muted: "#475258",
|
|
172
|
+
accent: "#7fbbb3",
|
|
173
|
+
selection: "#3d484d",
|
|
174
|
+
red: "#e67e80",
|
|
175
|
+
green: "#a7c080",
|
|
176
|
+
yellow: "#dbbc7f",
|
|
177
|
+
blue: "#7fbbb3",
|
|
178
|
+
magenta: "#d699b6",
|
|
179
|
+
cyan: "#83c092",
|
|
180
|
+
orange: "#e09d7f",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
id: "matte-black",
|
|
184
|
+
name: "Matte Black",
|
|
185
|
+
mode: "dark",
|
|
186
|
+
source: "Omarchy",
|
|
187
|
+
background: "#121212",
|
|
188
|
+
foreground: "#bebebe",
|
|
189
|
+
muted: "#333333",
|
|
190
|
+
accent: "#e68e0d",
|
|
191
|
+
selection: "#2a2a2a",
|
|
192
|
+
red: "#d35f5f",
|
|
193
|
+
green: "#ffc107",
|
|
194
|
+
yellow: "#b91c1c",
|
|
195
|
+
blue: "#e68e0d",
|
|
196
|
+
magenta: "#d35f5f",
|
|
197
|
+
cyan: "#bebebe",
|
|
198
|
+
orange: "#c63d3d",
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: "hackerman",
|
|
202
|
+
name: "Hackerman",
|
|
203
|
+
mode: "dark",
|
|
204
|
+
source: "Omarchy",
|
|
205
|
+
background: "#0b0c16",
|
|
206
|
+
foreground: "#ddf7ff",
|
|
207
|
+
muted: "#2d3450",
|
|
208
|
+
accent: "#82fb9c",
|
|
209
|
+
selection: "#1f253a",
|
|
210
|
+
red: "#50f872",
|
|
211
|
+
green: "#4fe88f",
|
|
212
|
+
yellow: "#50f7d4",
|
|
213
|
+
blue: "#829dd4",
|
|
214
|
+
magenta: "#86a7df",
|
|
215
|
+
cyan: "#7cf8f7",
|
|
216
|
+
orange: "#50f7a3",
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: "retro-82",
|
|
220
|
+
name: "Retro 82",
|
|
221
|
+
mode: "dark",
|
|
222
|
+
source: "Omarchy",
|
|
223
|
+
background: "#05182e",
|
|
224
|
+
foreground: "#f6dcac",
|
|
225
|
+
muted: "#2a6b78",
|
|
226
|
+
accent: "#faa968",
|
|
227
|
+
selection: "#134e5a",
|
|
228
|
+
red: "#f85525",
|
|
229
|
+
green: "#028391",
|
|
230
|
+
yellow: "#e97b3c",
|
|
231
|
+
blue: "#3f8f8a",
|
|
232
|
+
magenta: "#3f8f8a",
|
|
233
|
+
cyan: "#8cbfb8",
|
|
234
|
+
orange: "#faa968",
|
|
235
|
+
},
|
|
236
|
+
];
|
|
237
|
+
/** The default palette. */
|
|
238
|
+
export const DEFAULT_PALETTE = PALETTES[0];
|
|
239
|
+
/** A shipped palette by id. */
|
|
240
|
+
export function paletteById(id) {
|
|
241
|
+
return PALETTES.find((p) => p.id === id);
|
|
242
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hollis-labs/surface-theme",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Surface's palettes: the shape a Linux theme reduces to, the palettes Surface ships (Blade Runner, Basalisk's, Omarchy's), readers for Omarchy colors.toml, base16 and pywal, a contrast check, and applyPalette, which sets the theme's --p-* properties so every token follows.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/hollis-labs/surface.git",
|
|
9
|
+
"directory": "packages/theme"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/hollis-labs/surface/tree/main/packages/theme#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/hollis-labs/surface/issues"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"registry": "https://registry.npmjs.org/"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
36
|
+
"prepack": "npm run build"
|
|
37
|
+
}
|
|
38
|
+
}
|