fluorokit 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +181 -2
- package/bin/fluorokit.mjs +50 -0
- package/dist/base.css +201 -0
- package/dist/enter.d.ts +8 -0
- package/dist/enter.js +83 -0
- package/dist/fonts/selawik/LICENSE.txt +91 -0
- package/dist/fonts/selawik/selawk.woff2 +0 -0
- package/dist/fonts/selawik/selawkb.woff2 +0 -0
- package/dist/fonts/selawik/selawkl.woff2 +0 -0
- package/dist/fonts/selawik/selawksb.woff2 +0 -0
- package/dist/fonts/selawik/selawksl.woff2 +0 -0
- package/dist/fonts/selawik.css +38 -0
- package/dist/shiki/blueberry-dark.json +157 -0
- package/dist/shiki/blueberry-light.json +157 -0
- package/dist/shiki/cobalt-dark.json +157 -0
- package/dist/shiki/cobalt-light.json +157 -0
- package/dist/shiki/ink-dark.json +157 -0
- package/dist/shiki/ink-light.json +157 -0
- package/dist/shiki/twilight-dark.json +157 -0
- package/dist/shiki/twilight-light.json +157 -0
- package/dist/structure.css +48 -0
- package/dist/svelte/Pivot.svelte +45 -0
- package/dist/tailwind.css +52 -0
- package/dist/themes/blueberry.css +185 -0
- package/dist/themes/blueberry.scoped.css +274 -0
- package/dist/themes/blueberry.shadcn.css +274 -0
- package/dist/themes/catppuccin.css +155 -0
- package/dist/themes/catppuccin.scoped.css +244 -0
- package/dist/themes/catppuccin.shadcn.css +244 -0
- package/dist/themes/cobalt.css +185 -0
- package/dist/themes/cobalt.scoped.css +274 -0
- package/dist/themes/cobalt.shadcn.css +274 -0
- package/dist/themes/ink.css +185 -0
- package/dist/themes/ink.scoped.css +274 -0
- package/dist/themes/ink.shadcn.css +274 -0
- package/dist/themes/twilight.css +185 -0
- package/dist/themes/twilight.scoped.css +274 -0
- package/dist/themes/twilight.shadcn.css +274 -0
- package/dist/themes/zune.css +76 -0
- package/dist/themes/zune.scoped.css +125 -0
- package/dist/themes/zune.shadcn.css +125 -0
- package/dist/themes.json +855 -0
- package/dist/tools/color.mjs +51 -0
- package/dist/tools/fluoro.mjs +207 -0
- package/dist/tools/presets.mjs +87 -0
- package/dist/tools/theme-css.mjs +133 -0
- package/package.json +70 -4
- package/tokens/structure.json +51 -0
- package/tokens/themes/blueberry.json +157 -0
- package/tokens/themes/catppuccin.json +133 -0
- package/tokens/themes/cobalt.json +157 -0
- package/tokens/themes/ink.json +157 -0
- package/tokens/themes/twilight.json +157 -0
- package/tokens/themes/zune.json +92 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// OKLCH color math for the theme recipes.
|
|
2
|
+
|
|
3
|
+
// ---- color math: OKLCH to sRGB hex, with the chroma reduced to fit sRGB ----
|
|
4
|
+
const toLinear = (L, C, h) => {
|
|
5
|
+
const a = C * Math.cos((h * Math.PI) / 180);
|
|
6
|
+
const b = C * Math.sin((h * Math.PI) / 180);
|
|
7
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
8
|
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
9
|
+
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
10
|
+
return [
|
|
11
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
12
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
13
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,
|
|
14
|
+
];
|
|
15
|
+
};
|
|
16
|
+
const inGamut = (rgb) => rgb.every((v) => v >= -0.0005 && v <= 1.0005);
|
|
17
|
+
export const hex = (L, C, h) => {
|
|
18
|
+
let c = C;
|
|
19
|
+
while (c > 0 && !inGamut(toLinear(L, c, h))) c -= 0.002;
|
|
20
|
+
return (
|
|
21
|
+
'#' +
|
|
22
|
+
toLinear(L, Math.max(c, 0), h)
|
|
23
|
+
.map((v) => {
|
|
24
|
+
const x = Math.min(1, Math.max(0, v));
|
|
25
|
+
const g = x <= 0.0031308 ? 12.92 * x : 1.055 * x ** (1 / 2.4) - 0.055;
|
|
26
|
+
return Math.round(g * 255).toString(16).padStart(2, '0');
|
|
27
|
+
})
|
|
28
|
+
.join('')
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
const luminance = (h) => {
|
|
32
|
+
const [r, g, b] = [1, 3, 5].map((i) => {
|
|
33
|
+
const v = parseInt(h.slice(i, i + 2), 16) / 255;
|
|
34
|
+
return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
35
|
+
});
|
|
36
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
37
|
+
};
|
|
38
|
+
export const contrast = (a, b) => {
|
|
39
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
40
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// The lightest color of a hue, at or below `from`, that has `min` contrast
|
|
44
|
+
// with `against`. Equal OKLCH lightness is not equal contrast (a yellow is
|
|
45
|
+
// brighter than a blue), so the fills are solved, not set.
|
|
46
|
+
export const fit = (from, C, h, against, min) => {
|
|
47
|
+
let L = from;
|
|
48
|
+
while (L > 0.3 && contrast(hex(L, C, h), against) < min) L -= 0.002;
|
|
49
|
+
return hex(L, C, h);
|
|
50
|
+
};
|
|
51
|
+
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// The recipe of the fluoro family: a theme from a few numbers. It reads no
|
|
2
|
+
// files, so that a page can use it in the browser. scripts/make-fluoro.mjs
|
|
3
|
+
// writes the members of the family with it.
|
|
4
|
+
import { contrast, fit, hex } from './color.mjs';
|
|
5
|
+
|
|
6
|
+
// ---- the recipe ----
|
|
7
|
+
// The defaults of a member. A recipe can change them.
|
|
8
|
+
export const DEFAULTS = { accentH: 350, secondH: 232, tileMin: 3.5, sans: 'IBM Plex Sans' };
|
|
9
|
+
const HUES = { error: 20, warn: 90, ok: 160, blue: 262, mauve: 320 };
|
|
10
|
+
|
|
11
|
+
// Each member: the hue, chroma and lightness of the dark base, the hue and
|
|
12
|
+
// chroma of the dark text, then the chroma of the light base and the
|
|
13
|
+
// lightness and chroma of the light text.
|
|
14
|
+
export const MEMBERS = {
|
|
15
|
+
ink: {
|
|
16
|
+
about: 'almost black with a hint of blue',
|
|
17
|
+
dark: { h: 270, c: 0.02, L: 0.19, textH: 340, textC: 0.015 },
|
|
18
|
+
light: { c: 0.004, textL: 0.27, textC: 0.03 },
|
|
19
|
+
},
|
|
20
|
+
blueberry: {
|
|
21
|
+
about: 'a saturated blue',
|
|
22
|
+
dark: { h: 268, c: 0.075, L: 0.25, textH: 340, textC: 0.02 },
|
|
23
|
+
light: { c: 0.01, textL: 0.38, textC: 0.1 },
|
|
24
|
+
},
|
|
25
|
+
twilight: {
|
|
26
|
+
about: 'a rich violet, the nearest to Catppuccin Mocha',
|
|
27
|
+
dark: { h: 288, c: 0.07, L: 0.25, textH: 320, textC: 0.025 },
|
|
28
|
+
light: { c: 0.01, textL: 0.38, textC: 0.09 },
|
|
29
|
+
},
|
|
30
|
+
cobalt: {
|
|
31
|
+
about: 'a brighter blue, the nearest to a Windows 8 Start screen',
|
|
32
|
+
dark: { h: 262, c: 0.11, L: 0.3, textH: 340, textC: 0.02 },
|
|
33
|
+
light: { c: 0.016, textL: 0.36, textC: 0.13 },
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Tile fills: strong and flat, the same in each mode, with white text. Each
|
|
38
|
+
// is the lightest color of its hue that gives the text `min` contrast. The
|
|
39
|
+
// names are the Catppuccin accent names; pink and sky follow the accents.
|
|
40
|
+
const TILE_TEXT = '#ffffff';
|
|
41
|
+
const tileFills = (PINK, SKY, min) => {
|
|
42
|
+
const hues = {
|
|
43
|
+
rosewater: [15, 0.1], flamingo: [5, 0.14], pink: [PINK, 0.19], mauve: [310, 0.19],
|
|
44
|
+
red: [20, 0.21], maroon: [0, 0.18], peach: [45, 0.17], yellow: [80, 0.14],
|
|
45
|
+
green: [150, 0.16], teal: [200, 0.11], sky: [SKY, 0.14], sapphire: [245, 0.16],
|
|
46
|
+
blue: [258, 0.2], lavender: [280, 0.17],
|
|
47
|
+
};
|
|
48
|
+
return Object.fromEntries(Object.entries(hues).map(([name, [h, c]]) => [name, fit(0.75, c, h, TILE_TEXT, min)]));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Make a theme of the family from a recipe.
|
|
53
|
+
* @param {string} name
|
|
54
|
+
* @param {object} recipe { about, dark: { h, c, L, textH, textC }, light: { c, textL, textC }, accentH?, secondH?, tileMin?, sans? }
|
|
55
|
+
*/
|
|
56
|
+
export function makeTheme(name, recipe) {
|
|
57
|
+
const { about = 'a member of the fluoro family', dark: d, light: l } = recipe;
|
|
58
|
+
const { accentH: PINK, secondH: SKY, tileMin, sans } = { ...DEFAULTS, ...recipe };
|
|
59
|
+
const tiles = tileFills(PINK, SKY, tileMin);
|
|
60
|
+
// Freon: the dark mode and the default. The surfaces are steps of
|
|
61
|
+
// lightness from the base.
|
|
62
|
+
const freon = {
|
|
63
|
+
base: hex(d.L, d.c, d.h),
|
|
64
|
+
mantle: hex(d.L - 0.03, d.c * 0.93, d.h),
|
|
65
|
+
deep: hex(d.L - 0.06, d.c * 0.85, d.h),
|
|
66
|
+
raised: hex(d.L + 0.08, d.c * 1.13, d.h),
|
|
67
|
+
line: hex(d.L + 0.16, d.c * 1.13, d.h),
|
|
68
|
+
overlay: hex(d.L + 0.32, d.c, d.h),
|
|
69
|
+
text: hex(0.94, d.textC, d.textH),
|
|
70
|
+
muted: hex(0.8, Math.min(d.c * 0.7, 0.05), d.h + 7),
|
|
71
|
+
accent: hex(0.86, 0.08, PINK),
|
|
72
|
+
'bar-start': hex(0.84, 0.08, SKY),
|
|
73
|
+
'control-border': hex(Math.max(d.L + 0.39, 0.64), Math.min(d.c, 0.07), d.h),
|
|
74
|
+
'status-error': hex(0.76, 0.13, HUES.error),
|
|
75
|
+
'status-warn': hex(0.9, 0.1, HUES.warn),
|
|
76
|
+
'status-ok': hex(0.87, 0.1, HUES.ok),
|
|
77
|
+
'status-info': hex(0.84, 0.08, SKY),
|
|
78
|
+
'chart-1': hex(0.78, 0.1, HUES.blue),
|
|
79
|
+
'chart-2': hex(0.78, 0.11, HUES.mauve),
|
|
80
|
+
'chart-3': hex(0.7, Math.min(d.c, 0.04), d.h),
|
|
81
|
+
};
|
|
82
|
+
// Teflon: the light mode.
|
|
83
|
+
const base = hex(0.972, l.c, d.h);
|
|
84
|
+
// A fill on the light base must have 3:1 with it (the status square, the
|
|
85
|
+
// underline).
|
|
86
|
+
const onLight = (L, C, h) => fit(L, C, h, base, 3.05);
|
|
87
|
+
const teflon = {
|
|
88
|
+
base,
|
|
89
|
+
mantle: hex(0.945, l.c * 1.2, d.h),
|
|
90
|
+
deep: hex(0.92, l.c * 1.6, d.h),
|
|
91
|
+
raised: hex(0.875, l.c * 2, d.h),
|
|
92
|
+
line: hex(0.825, l.c * 2.4, d.h),
|
|
93
|
+
overlay: hex(0.71, l.c * 3, d.h),
|
|
94
|
+
text: hex(l.textL, l.textC, d.h),
|
|
95
|
+
muted: hex(l.textL + 0.09, l.textC * 0.8, d.h),
|
|
96
|
+
accent: onLight(0.72, 0.15, PINK),
|
|
97
|
+
'bar-start': hex(0.74, 0.12, SKY),
|
|
98
|
+
'control-border': hex(0.58, Math.min(l.c * 4.5, 0.045), d.h),
|
|
99
|
+
'status-error': hex(0.56, 0.2, HUES.error),
|
|
100
|
+
'status-warn': onLight(0.74, 0.14, 80),
|
|
101
|
+
'status-ok': onLight(0.66, 0.13, HUES.ok),
|
|
102
|
+
'status-info': onLight(0.66, 0.13, SKY),
|
|
103
|
+
'chart-1': hex(0.56, 0.19, HUES.blue),
|
|
104
|
+
'chart-2': hex(0.56, 0.19, HUES.mauve),
|
|
105
|
+
'chart-3': hex(0.58, Math.min(l.c * 4.5, 0.045), d.h),
|
|
106
|
+
};
|
|
107
|
+
// Syntax colors for code, which sits on mantle. Pink keywords, mint
|
|
108
|
+
// strings, light blue functions: the accents of the family.
|
|
109
|
+
const freonSyntax = {
|
|
110
|
+
comment: hex(0.7, Math.min(d.c, 0.03), d.h),
|
|
111
|
+
punctuation: freon.muted,
|
|
112
|
+
keyword: hex(0.82, 0.11, PINK),
|
|
113
|
+
string: hex(0.86, 0.1, HUES.ok),
|
|
114
|
+
number: hex(0.84, 0.1, 60),
|
|
115
|
+
constant: hex(0.8, 0.11, 310),
|
|
116
|
+
function: hex(0.82, 0.09, SKY),
|
|
117
|
+
type: hex(0.89, 0.09, HUES.warn),
|
|
118
|
+
tag: hex(0.82, 0.11, PINK),
|
|
119
|
+
attribute: hex(0.82, 0.09, SKY),
|
|
120
|
+
};
|
|
121
|
+
const onMantle = (L, C, h) => fit(L, C, h, teflon.mantle, 4.6);
|
|
122
|
+
const teflonSyntax = {
|
|
123
|
+
comment: onMantle(0.56, Math.min(l.c * 4.5, 0.03), d.h),
|
|
124
|
+
punctuation: teflon.muted,
|
|
125
|
+
keyword: onMantle(0.58, 0.19, PINK),
|
|
126
|
+
string: onMantle(0.58, 0.14, 155),
|
|
127
|
+
number: onMantle(0.6, 0.16, 50),
|
|
128
|
+
constant: onMantle(0.56, 0.2, 310),
|
|
129
|
+
function: onMantle(0.56, 0.16, 245),
|
|
130
|
+
type: onMantle(0.62, 0.13, 80),
|
|
131
|
+
tag: onMantle(0.58, 0.19, PINK),
|
|
132
|
+
attribute: onMantle(0.56, 0.16, 245),
|
|
133
|
+
};
|
|
134
|
+
const INK = hex(0.16, Math.min(d.c, 0.03), d.h); // text on a pastel or a bright fill
|
|
135
|
+
const mode = (colorScheme, c, extra, syntax) => ({
|
|
136
|
+
colorScheme,
|
|
137
|
+
...(syntax && { syntax }),
|
|
138
|
+
colors: {
|
|
139
|
+
base: c.base, mantle: c.mantle, deep: c.deep, raised: c.raised, line: c.line, overlay: c.overlay,
|
|
140
|
+
text: c.text, muted: c.muted,
|
|
141
|
+
accent: c.accent, 'on-accent': INK,
|
|
142
|
+
'link-underline': 'var(--fk-accent)',
|
|
143
|
+
'bar-start': c['bar-start'], 'bar-end': 'var(--fk-accent)',
|
|
144
|
+
focus: c.text, 'control-border': c['control-border'],
|
|
145
|
+
hover: c.deep, selection: c.deep, disabled: c['control-border'],
|
|
146
|
+
'status-error': c['status-error'], 'on-error': INK,
|
|
147
|
+
'status-warn': c['status-warn'], 'on-warn': INK,
|
|
148
|
+
'status-ok': c['status-ok'], 'on-ok': INK,
|
|
149
|
+
'status-info': c['status-info'], 'on-info': INK,
|
|
150
|
+
'chart-1': c['chart-1'], 'chart-2': c['chart-2'], 'chart-3': c['chart-3'],
|
|
151
|
+
...extra,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
name,
|
|
156
|
+
description: `The fluoro family, ${name}: ${about}. Light pink and light blue accents, strong tiles with white text. Generated by scripts/make-fluoro.mjs.`,
|
|
157
|
+
default: 'freon',
|
|
158
|
+
followSystem: true,
|
|
159
|
+
print: 'paper',
|
|
160
|
+
fonts: {
|
|
161
|
+
'font-sans': sans === 'system' ? 'system-ui, sans-serif' : `"${sans}", system-ui, sans-serif`,
|
|
162
|
+
'font-serif': '"IBM Plex Serif", Georgia, serif',
|
|
163
|
+
'font-mono': '"IBM Plex Mono", ui-monospace, monospace',
|
|
164
|
+
},
|
|
165
|
+
tiles,
|
|
166
|
+
tileText: TILE_TEXT,
|
|
167
|
+
tileMin,
|
|
168
|
+
modes: {
|
|
169
|
+
freon: mode('dark', freon, { focus: freon['bar-start'], hover: freon.line, selection: freon.line }, freonSyntax),
|
|
170
|
+
teflon: mode('light', teflon, { 'on-error': teflon.base }, teflonSyntax),
|
|
171
|
+
paper: mode('light', teflon, { text: INK, muted: hex(0.4, Math.min(d.c, 0.03), d.h), focus: INK, 'on-error': teflon.base }),
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The contrast of each text and fill pair of a theme.
|
|
178
|
+
* @returns {{ mode: string, label: string, ratio: number, min: number, ok: boolean }[]}
|
|
179
|
+
*/
|
|
180
|
+
export function contrastReport(theme) {
|
|
181
|
+
const rows = [];
|
|
182
|
+
for (const [mode, m] of Object.entries(theme.modes)) {
|
|
183
|
+
const c = m.colors;
|
|
184
|
+
const row = (label, fg, bg, min) => {
|
|
185
|
+
const ratio = contrast(fg, bg);
|
|
186
|
+
rows.push({ mode, label, ratio, min, ok: ratio >= min });
|
|
187
|
+
};
|
|
188
|
+
for (const bg of ['base', 'mantle', 'deep']) {
|
|
189
|
+
row(`text on ${bg}`, c.text, c[bg], 4.5);
|
|
190
|
+
row(`muted on ${bg}`, c.muted, c[bg], 4.5);
|
|
191
|
+
}
|
|
192
|
+
row('text on raised', c.text, c.raised, 4.5);
|
|
193
|
+
row('text on hover', c.text, c.hover, 4.5);
|
|
194
|
+
row('control-border on base', c['control-border'], c.base, 3);
|
|
195
|
+
row('accent (underline) on base', c.accent, c.base, 3);
|
|
196
|
+
row('focus on base', c.focus, c.base, 3);
|
|
197
|
+
for (const [token, color] of Object.entries(m.syntax ?? {})) row(`code ${token} on mantle`, color, c.mantle, 4.5);
|
|
198
|
+
for (const s of ['error', 'warn', 'ok', 'info']) {
|
|
199
|
+
row(`on-${s} on status-${s}`, c[`on-${s}`], c[`status-${s}`], 4.5);
|
|
200
|
+
row(`status-${s} (square) on base`, c[`status-${s}`], c.base, 3);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
for (const [name, fill] of Object.entries(theme.tiles ?? {})) {
|
|
204
|
+
rows.push({ mode: 'tiles', label: `white text on ${name}`, ratio: contrast(theme.tileText, fill), min: theme.tileMin ?? 3.5, ok: contrast(theme.tileText, fill) >= (theme.tileMin ?? 3.5) - 0.005 });
|
|
205
|
+
}
|
|
206
|
+
return rows;
|
|
207
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Presets: a theme of the fluoro family from six named choices, and a short
|
|
2
|
+
// code for the set of choices. The create page of the site and the
|
|
3
|
+
// fluorokit command both use this. It reads no files.
|
|
4
|
+
import { hex } from './color.mjs';
|
|
5
|
+
import { DEFAULTS, MEMBERS, makeTheme } from './fluoro.mjs';
|
|
6
|
+
|
|
7
|
+
const HUES = [
|
|
8
|
+
['pink', 'Pink', 350], ['rose', 'Rose', 10], ['red', 'Red', 25], ['orange', 'Orange', 50],
|
|
9
|
+
['amber', 'Amber', 80], ['lime', 'Lime', 125], ['green', 'Green', 150], ['mint', 'Mint', 170],
|
|
10
|
+
['teal', 'Teal', 195], ['sky', 'Sky', 232], ['blue', 'Blue', 258], ['indigo', 'Indigo', 278],
|
|
11
|
+
['violet', 'Violet', 300], ['fuchsia', 'Fuchsia', 325],
|
|
12
|
+
].map(([id, name, h]) => ({ id, name, h, swatch: hex(0.74, 0.14, h) }));
|
|
13
|
+
|
|
14
|
+
const base = (id, name, recipe) => ({ id, name, recipe, swatch: hex(recipe.dark.L + 0.08, recipe.dark.c * 1.13, recipe.dark.h) });
|
|
15
|
+
|
|
16
|
+
// The choices, in the order of the code. Add new options at the end of a
|
|
17
|
+
// list, so that old codes keep their meaning.
|
|
18
|
+
export const OPTIONS = {
|
|
19
|
+
base: [
|
|
20
|
+
base('ink', 'Ink', MEMBERS.ink),
|
|
21
|
+
base('blueberry', 'Blueberry', MEMBERS.blueberry),
|
|
22
|
+
base('twilight', 'Twilight', MEMBERS.twilight),
|
|
23
|
+
base('cobalt', 'Cobalt', MEMBERS.cobalt),
|
|
24
|
+
base('graphite', 'Graphite', { dark: { h: 270, c: 0.004, L: 0.2, textH: 270, textC: 0.004 }, light: { c: 0.001, textL: 0.25, textC: 0.005 } }),
|
|
25
|
+
base('moss', 'Moss', { dark: { h: 155, c: 0.035, L: 0.22, textH: 120, textC: 0.015 }, light: { c: 0.008, textL: 0.3, textC: 0.05 } }),
|
|
26
|
+
base('cocoa', 'Cocoa', { dark: { h: 50, c: 0.03, L: 0.22, textH: 70, textC: 0.02 }, light: { c: 0.01, textL: 0.3, textC: 0.04 } }),
|
|
27
|
+
base('plum', 'Plum', { dark: { h: 335, c: 0.035, L: 0.23, textH: 340, textC: 0.02 }, light: { c: 0.008, textL: 0.33, textC: 0.06 } }),
|
|
28
|
+
],
|
|
29
|
+
accent: HUES,
|
|
30
|
+
second: HUES,
|
|
31
|
+
text: [
|
|
32
|
+
{ id: 'base', name: 'From the base', tint: null },
|
|
33
|
+
{ id: 'pink', name: 'Pink white', tint: { textH: 340, textC: 0.02 } },
|
|
34
|
+
{ id: 'warm', name: 'Warm white', tint: { textH: 75, textC: 0.02 } },
|
|
35
|
+
{ id: 'cool', name: 'Cool white', tint: { textH: 240, textC: 0.02 } },
|
|
36
|
+
{ id: 'plain', name: 'Plain white', tint: { textH: 0, textC: 0 } },
|
|
37
|
+
],
|
|
38
|
+
tiles: [
|
|
39
|
+
{ id: 'bright', name: 'Bright', min: 3.5 },
|
|
40
|
+
{ id: 'balanced', name: 'Balanced', min: 4.5 },
|
|
41
|
+
{ id: 'deep', name: 'Deep', min: 7 },
|
|
42
|
+
],
|
|
43
|
+
font: [
|
|
44
|
+
{ id: 'plex', name: 'IBM Plex Sans', sans: 'IBM Plex Sans' },
|
|
45
|
+
{ id: 'selawik', name: 'Selawik', sans: 'Selawik' },
|
|
46
|
+
{ id: 'system', name: 'System', sans: 'system' },
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
export const KEYS = ['base', 'accent', 'second', 'text', 'tiles', 'font'];
|
|
50
|
+
export const DEFAULT = { base: 'ink', accent: 'pink', second: 'sky', text: 'base', tiles: 'bright', font: 'plex' };
|
|
51
|
+
|
|
52
|
+
const find = (key, id) => OPTIONS[key].find((o) => o.id === id) ?? OPTIONS[key][0];
|
|
53
|
+
|
|
54
|
+
/** The recipe (for makeTheme) of a set of choices. */
|
|
55
|
+
export function recipeOf(choice) {
|
|
56
|
+
const b = find('base', choice.base).recipe;
|
|
57
|
+
const tint = find('text', choice.text).tint;
|
|
58
|
+
return {
|
|
59
|
+
about: `preset ${encodePreset(choice)}`,
|
|
60
|
+
dark: { ...b.dark, ...(tint ?? {}) },
|
|
61
|
+
light: { ...b.light },
|
|
62
|
+
accentH: find('accent', choice.accent).h,
|
|
63
|
+
secondH: find('second', choice.second).h,
|
|
64
|
+
tileMin: find('tiles', choice.tiles).min,
|
|
65
|
+
sans: find('font', choice.font).sans ?? DEFAULTS.sans,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The theme of a set of choices. */
|
|
70
|
+
export const themeOf = (choice, name = 'custom') => makeTheme(name, recipeOf(choice));
|
|
71
|
+
|
|
72
|
+
// The code: "f", then one base-36 digit for each choice, in the order of KEYS.
|
|
73
|
+
export function encodePreset(choice) {
|
|
74
|
+
return 'f' + KEYS.map((key) => Math.max(0, OPTIONS[key].findIndex((o) => o.id === choice[key])).toString(36)).join('');
|
|
75
|
+
}
|
|
76
|
+
/** The choices of a code, or null if the code is not a preset. */
|
|
77
|
+
export function decodePreset(code) {
|
|
78
|
+
const text = String(code ?? '').trim().replace(/^--preset\s+/, '').toLowerCase();
|
|
79
|
+
if (!/^f[0-9a-z]+$/.test(text) || text.length !== KEYS.length + 1) return null;
|
|
80
|
+
const choice = {};
|
|
81
|
+
for (const [i, key] of KEYS.entries()) {
|
|
82
|
+
const option = OPTIONS[key][parseInt(text[i + 1], 36)];
|
|
83
|
+
if (!option) return null;
|
|
84
|
+
choice[key] = option.id;
|
|
85
|
+
}
|
|
86
|
+
return choice;
|
|
87
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Turns a theme (the JSON in tokens/themes) into CSS and into a Shiki syntax
|
|
2
|
+
// theme. It reads no files, so that a page can use it in the browser.
|
|
3
|
+
|
|
4
|
+
const banner = (what) =>
|
|
5
|
+
`/* fluorokit: ${what}. Generated by scripts/build.mjs. Do not edit by hand. */\n\n`;
|
|
6
|
+
|
|
7
|
+
// shadcn name -> fluorokit color token. A mode can replace any entry with a
|
|
8
|
+
// literal value in its "shadcn" object.
|
|
9
|
+
export const SHADCN = {
|
|
10
|
+
background: 'base',
|
|
11
|
+
foreground: 'text',
|
|
12
|
+
card: 'mantle',
|
|
13
|
+
'card-foreground': 'text',
|
|
14
|
+
popover: 'mantle',
|
|
15
|
+
'popover-foreground': 'text',
|
|
16
|
+
primary: 'accent',
|
|
17
|
+
'primary-foreground': 'on-accent',
|
|
18
|
+
secondary: 'raised',
|
|
19
|
+
'secondary-foreground': 'text',
|
|
20
|
+
muted: 'deep',
|
|
21
|
+
'muted-foreground': 'muted',
|
|
22
|
+
accent: 'hover',
|
|
23
|
+
'accent-foreground': 'text',
|
|
24
|
+
destructive: 'status-error',
|
|
25
|
+
border: 'line',
|
|
26
|
+
input: 'control-border',
|
|
27
|
+
ring: 'focus',
|
|
28
|
+
'chart-1': 'chart-1',
|
|
29
|
+
'chart-2': 'chart-2',
|
|
30
|
+
'chart-3': 'chart-3',
|
|
31
|
+
'chart-4': 'chart-4',
|
|
32
|
+
'chart-5': 'chart-5',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const REQUIRED = [
|
|
36
|
+
'base', 'mantle', 'deep', 'raised', 'line', 'overlay', 'text', 'muted',
|
|
37
|
+
'accent', 'on-accent', 'link-underline', 'bar-start', 'bar-end', 'focus',
|
|
38
|
+
'control-border', 'hover', 'selection', 'disabled',
|
|
39
|
+
'status-error', 'on-error', 'status-warn', 'on-warn',
|
|
40
|
+
'status-ok', 'on-ok', 'status-info', 'on-info',
|
|
41
|
+
'chart-1', 'chart-2', 'chart-3',
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
export const decls = (vars, indent, prefix = '--fk-') =>
|
|
45
|
+
Object.entries(vars)
|
|
46
|
+
.map(([key, value]) => `${indent}${prefix}${key}: ${value};\n`)
|
|
47
|
+
.join('');
|
|
48
|
+
|
|
49
|
+
function modeBody(mode, indent, withShadcn) {
|
|
50
|
+
let out = decls(mode.colors, indent) + `${indent}color-scheme: ${mode.colorScheme};\n`;
|
|
51
|
+
// Syntax colors for code, as variables, so that a page can color code
|
|
52
|
+
// with the theme that is active.
|
|
53
|
+
if (mode.syntax) out += decls(mode.syntax, indent, '--fk-syntax-');
|
|
54
|
+
if (withShadcn) {
|
|
55
|
+
const bridge = {};
|
|
56
|
+
for (const [name, token] of Object.entries(SHADCN)) {
|
|
57
|
+
if (mode.shadcn?.[name]) bridge[name] = mode.shadcn[name];
|
|
58
|
+
else if (token in mode.colors) bridge[name] = `var(--fk-${token})`;
|
|
59
|
+
}
|
|
60
|
+
out += '\n' + decls(bridge, indent, '--');
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// `scoped` writes the theme under [data-fk-theme="<name>"] and not under
|
|
66
|
+
// :root. A page can then load many themes and change between them, or show
|
|
67
|
+
// one theme inside an element.
|
|
68
|
+
export function themeCss(theme, withShadcn, scoped = false) {
|
|
69
|
+
const { name, modes, fonts } = theme;
|
|
70
|
+
const def = modes[theme.default];
|
|
71
|
+
const body = (mode, indent) => modeBody(mode, indent, withShadcn);
|
|
72
|
+
const root = scoped ? `[data-fk-theme="${name}"]` : ':root';
|
|
73
|
+
const at = scoped ? root : '';
|
|
74
|
+
// A mode is selected with data-theme="<mode>". Dark and light modes also
|
|
75
|
+
// answer to the .dark and .light classes that shadcn projects use.
|
|
76
|
+
const selectors = (key) => {
|
|
77
|
+
const list = [`${at}[data-theme="${key}"]`];
|
|
78
|
+
if (key !== theme.print) list.push(`${at}.${modes[key].colorScheme}`);
|
|
79
|
+
return list.join(', ');
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
let css = banner(`the ${name} theme${withShadcn ? ' with shadcn variable names' : ''}${scoped ? `, under [data-fk-theme="${name}"]` : ''}`);
|
|
83
|
+
css += `${root} {\n${decls(fonts, ' ')}`;
|
|
84
|
+
// Tile fills are the same in each mode.
|
|
85
|
+
if (theme.tiles) css += decls(theme.tiles, ' ', '--fk-tile-');
|
|
86
|
+
if (theme.tileText) css += ` --fk-tile-text: ${theme.tileText};\n`;
|
|
87
|
+
if (withShadcn) css += ' --radius: 0rem;\n';
|
|
88
|
+
css += '}\n\n';
|
|
89
|
+
css += `${root}, ${selectors(theme.default)} {\n${body(def, ' ')}}\n`;
|
|
90
|
+
|
|
91
|
+
for (const [key, mode] of Object.entries(modes)) {
|
|
92
|
+
if (key === theme.default || key === theme.print) continue;
|
|
93
|
+
if (theme.followSystem && mode.colorScheme !== def.colorScheme) {
|
|
94
|
+
css += `@media (prefers-color-scheme: ${mode.colorScheme}) {\n`;
|
|
95
|
+
css += ` ${root}:not([data-theme]):not(.${def.colorScheme}) {\n${body(mode, ' ')} }\n}\n`;
|
|
96
|
+
}
|
|
97
|
+
css += `${selectors(key)} {\n${body(mode, ' ')}}\n`;
|
|
98
|
+
}
|
|
99
|
+
if (theme.print) {
|
|
100
|
+
const all = scoped ? root : ':root, [data-theme], .dark, .light';
|
|
101
|
+
css += `@media print {\n ${all} {\n${body(modes[theme.print], ' ')} }\n}\n`;
|
|
102
|
+
}
|
|
103
|
+
return css;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// A Shiki (TextMate) theme for code blocks, from a mode's "syntax" colors.
|
|
107
|
+
// The background is not set: the page gives the code block its fill.
|
|
108
|
+
export function shikiTheme(theme, key) {
|
|
109
|
+
const mode = theme.modes[key];
|
|
110
|
+
const s = mode.syntax;
|
|
111
|
+
const rule = (scope, foreground, fontStyle) => ({ scope, settings: { foreground, ...(fontStyle && { fontStyle }) } });
|
|
112
|
+
return {
|
|
113
|
+
name: `fluorokit-${theme.name}-${mode.colorScheme}`,
|
|
114
|
+
type: mode.colorScheme,
|
|
115
|
+
colors: { 'editor.foreground': mode.colors.text, 'editor.background': mode.colors.mantle },
|
|
116
|
+
tokenColors: [
|
|
117
|
+
{ settings: { foreground: mode.colors.text } },
|
|
118
|
+
rule(['comment', 'punctuation.definition.comment'], s.comment, 'italic'),
|
|
119
|
+
rule(['punctuation', 'meta.brace', 'keyword.operator', 'meta.embedded punctuation'], s.punctuation),
|
|
120
|
+
rule(['keyword', 'storage', 'storage.type', 'storage.modifier', 'keyword.operator.new', 'keyword.operator.expression', 'keyword.operator.logical.python', 'variable.language'], s.keyword),
|
|
121
|
+
rule(['string', 'punctuation.definition.string', 'markup.inline.raw', 'markup.inserted'], s.string),
|
|
122
|
+
rule(['constant.numeric', 'constant.language', 'markup.deleted'], s.number),
|
|
123
|
+
rule(['constant.other', 'constant.character', 'variable.other.constant', 'support.constant', 'variable.other.enummember'], s.constant),
|
|
124
|
+
rule(['entity.name.function', 'support.function', 'meta.function-call entity.name', 'markup.heading'], s.function),
|
|
125
|
+
rule(['entity.name.type', 'entity.name.class', 'entity.name.namespace', 'support.type', 'support.class', 'entity.other.inherited-class'], s.type),
|
|
126
|
+
rule(['entity.name.tag', 'punctuation.definition.tag'], s.tag),
|
|
127
|
+
rule(['entity.other.attribute-name', 'support.type.property-name', 'meta.object-literal.key', 'entity.name.tag.yaml', 'variable.other.property'], s.attribute),
|
|
128
|
+
rule(['variable', 'variable.parameter', 'variable.other.readwrite'], mode.colors.text),
|
|
129
|
+
rule(['markup.bold'], mode.colors.text, 'bold'),
|
|
130
|
+
rule(['markup.italic'], mode.colors.text, 'italic'),
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fluorokit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A Metro theme for shadcn-svelte: tokens, themes and base CSS, plus tiles, a pivot and a theme CLI.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"shadcn-svelte",
|
|
7
|
+
"shadcn",
|
|
8
|
+
"svelte",
|
|
9
|
+
"theme",
|
|
10
|
+
"metro",
|
|
11
|
+
"windows-phone",
|
|
12
|
+
"tailwindcss",
|
|
13
|
+
"design-tokens",
|
|
14
|
+
"css"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "Abby Bigaouette",
|
|
18
|
+
"homepage": "https://fluorokit.bigaouette.com/",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/abbyfluoroethane/fluorokit.git"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"files": [
|
|
25
|
+
"bin",
|
|
26
|
+
"dist",
|
|
27
|
+
"tokens",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"exports": {
|
|
32
|
+
"./structure.css": "./dist/structure.css",
|
|
33
|
+
"./base.css": "./dist/base.css",
|
|
34
|
+
"./tailwind.css": "./dist/tailwind.css",
|
|
35
|
+
"./themes/*": "./dist/themes/*",
|
|
36
|
+
"./themes.json": "./dist/themes.json",
|
|
37
|
+
"./fonts/*": "./dist/fonts/*",
|
|
38
|
+
"./tools/*": "./dist/tools/*",
|
|
39
|
+
"./shiki/*": "./dist/shiki/*",
|
|
40
|
+
"./enter": {
|
|
41
|
+
"types": "./dist/enter.d.ts",
|
|
42
|
+
"default": "./dist/enter.js"
|
|
43
|
+
},
|
|
44
|
+
"./svelte/*": {
|
|
45
|
+
"svelte": "./dist/svelte/*",
|
|
46
|
+
"default": "./dist/svelte/*"
|
|
47
|
+
},
|
|
48
|
+
"./tokens/*": "./tokens/*",
|
|
49
|
+
"./package.json": "./package.json"
|
|
50
|
+
},
|
|
51
|
+
"sideEffects": [
|
|
52
|
+
"*.css"
|
|
53
|
+
],
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "node scripts/build.mjs",
|
|
56
|
+
"prepare": "node scripts/build.mjs"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=22"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"svelte": "^5.0.0"
|
|
63
|
+
},
|
|
64
|
+
"peerDependenciesMeta": {
|
|
65
|
+
"svelte": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"bin": {
|
|
70
|
+
"fluorokit": "bin/fluorokit.mjs"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"space": {
|
|
3
|
+
"space-1": "4px",
|
|
4
|
+
"space-2": "8px",
|
|
5
|
+
"space-3": "12px",
|
|
6
|
+
"space-4": "16px",
|
|
7
|
+
"space-6": "24px",
|
|
8
|
+
"space-8": "32px",
|
|
9
|
+
"space-12": "48px",
|
|
10
|
+
"space-16": "64px",
|
|
11
|
+
"page-margin": "120px"
|
|
12
|
+
},
|
|
13
|
+
"shape": {
|
|
14
|
+
"radius": "0",
|
|
15
|
+
"tile-1": "152px",
|
|
16
|
+
"tile-2": "312px",
|
|
17
|
+
"tile-gap": "var(--fk-space-2)",
|
|
18
|
+
"bar-edge": "6px",
|
|
19
|
+
"bar-field": "12px",
|
|
20
|
+
"touch-target": "40px"
|
|
21
|
+
},
|
|
22
|
+
"type": {
|
|
23
|
+
"hero-size": "clamp(3.5rem, 11vw, 6rem)",
|
|
24
|
+
"hero-leading": "0.917",
|
|
25
|
+
"title-size": "clamp(2.5rem, 6vw, 3.5rem)",
|
|
26
|
+
"title-leading": "1.071",
|
|
27
|
+
"heading-size": "1.5rem",
|
|
28
|
+
"heading-leading": "1.333",
|
|
29
|
+
"subheading-size": "1.125rem",
|
|
30
|
+
"subheading-leading": "1.333",
|
|
31
|
+
"body-size": "1rem",
|
|
32
|
+
"body-leading": "1.5",
|
|
33
|
+
"small-size": "0.875rem",
|
|
34
|
+
"small-leading": "1.429",
|
|
35
|
+
"label-size": "0.75rem",
|
|
36
|
+
"label-leading": "1.333",
|
|
37
|
+
"overline-size": "0.75rem",
|
|
38
|
+
"overline-leading": "1.333",
|
|
39
|
+
"data-size": "0.875rem",
|
|
40
|
+
"data-leading": "1.429",
|
|
41
|
+
"pivot-size": "2.6rem",
|
|
42
|
+
"pivot-leading": "1",
|
|
43
|
+
"subpivot-size": "1.15rem"
|
|
44
|
+
},
|
|
45
|
+
"motion": {
|
|
46
|
+
"ease-metro": "cubic-bezier(0.1, 0.9, 0.2, 1)",
|
|
47
|
+
"enter-offset": "80px",
|
|
48
|
+
"enter-duration": "0.7s",
|
|
49
|
+
"enter-stagger": "60ms"
|
|
50
|
+
}
|
|
51
|
+
}
|