@tetsustudio/tokens 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 +68 -2
- package/bin/validate-theme.mjs +18 -0
- package/dist/contract.d.ts +25 -0
- package/dist/contract.js +108 -0
- package/dist/css/base.css +78 -0
- package/dist/css/index.css +3 -0
- package/dist/css/palettes.css +101 -0
- package/dist/css/styles.css +213 -0
- package/dist/css/tailwind.css +85 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/palette.d.ts +17 -0
- package/dist/palette.js +45 -0
- package/dist/styles.d.ts +39 -0
- package/dist/styles.js +168 -0
- package/package.json +29 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tetsu Studio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tetsustudio/tokens
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Tetsu design-token contract: plain CSS custom properties, the visual styles
|
|
4
|
+
(`data-style`), their palettes, and a validator for new themes.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm install @tetsustudio/tokens
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Use
|
|
11
|
+
|
|
12
|
+
```css
|
|
13
|
+
/* Any app */
|
|
14
|
+
@import '@tetsustudio/tokens/css';
|
|
15
|
+
|
|
16
|
+
/* Tailwind v4 apps, after tailwindcss */
|
|
17
|
+
@import 'tailwindcss';
|
|
18
|
+
@import '@tetsustudio/tokens/css';
|
|
19
|
+
@import '@tetsustudio/tokens/tailwind.css';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<html data-style="tetsu" class="dark">
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Styles: `original`, `recto`, `papel`, `bloque`, `caramelo`, `tetsu`, `vidrio`.
|
|
27
|
+
Each one ships a default light and dark palette; `class="dark"` switches mode.
|
|
28
|
+
|
|
29
|
+
## The contract
|
|
30
|
+
|
|
31
|
+
A theme sets five variables, in light and in dark:
|
|
32
|
+
|
|
33
|
+
| Variable | Role |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `--background` | Page ground |
|
|
36
|
+
| `--surface` | Raised areas: inputs, popovers, muted blocks |
|
|
37
|
+
| `--foreground` | Text |
|
|
38
|
+
| `--brand` | Accent, focus ring, primary button in most styles |
|
|
39
|
+
| `--brand-foreground` | Text on `--brand` |
|
|
40
|
+
|
|
41
|
+
Everything else (`--border`, `--muted-foreground`, `--primary`, the shadcn
|
|
42
|
+
variables, sidebar and chart colors) derives from them with `color-mix()`. A
|
|
43
|
+
theme may also override shape (`--radius`, `--shape-full`, `--shape-lg`,
|
|
44
|
+
`--style-border`), type (`--font-sans`, `--font-heading`, `--font-mono`) and
|
|
45
|
+
status colors (`--destructive`, `--success`, `--warning`, `--info` and their
|
|
46
|
+
`-foreground`).
|
|
47
|
+
|
|
48
|
+
Fonts are not bundled: load them in the app and set `--font-inter`,
|
|
49
|
+
`--font-nunito`, `--font-jetbrains`, `--font-newsreader`, `--font-archivo`,
|
|
50
|
+
`--font-archivo-black` or `--font-fredoka` as needed; without them each style
|
|
51
|
+
falls back to a system stack.
|
|
52
|
+
|
|
53
|
+
## Validate a theme
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
npx tetsu-validate-theme theme.css my-style
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Fails when a required variable is missing (light or dark) or when contrast is
|
|
60
|
+
below AA: text on background and surface 4.5, text on brand 4.5, brand on
|
|
61
|
+
surface 3. The same checks are exported as `parseThemeCss` and `validateTheme`.
|
|
62
|
+
|
|
63
|
+
## JavaScript
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { STYLE_IDS, VISUAL_STYLES, COLOR_THEME_PRESETS, applyPalette } from '@tetsustudio/tokens'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
MIT © Tetsu Studio
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Usage: tetsu-validate-theme <theme.css> <style-id>
|
|
3
|
+
// Exits 1 and lists the problems when the theme breaks the token contract.
|
|
4
|
+
import { readFileSync } from 'node:fs'
|
|
5
|
+
import { parseThemeCss, validateTheme } from '../dist/index.js'
|
|
6
|
+
|
|
7
|
+
const [file, styleId] = process.argv.slice(2)
|
|
8
|
+
if (!file || !styleId) {
|
|
9
|
+
console.error('Usage: tetsu-validate-theme <theme.css> <style-id>')
|
|
10
|
+
process.exit(2)
|
|
11
|
+
}
|
|
12
|
+
const problems = validateTheme(parseThemeCss(readFileSync(file, 'utf8'), styleId))
|
|
13
|
+
if (problems.length === 0) {
|
|
14
|
+
console.log(`${styleId}: theme OK`)
|
|
15
|
+
} else {
|
|
16
|
+
for (const p of problems) console.error(`${styleId} (${p.mode}): ${p.message}`)
|
|
17
|
+
process.exit(1)
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Variables every theme must set, in light and in dark. */
|
|
2
|
+
export declare const REQUIRED_THEME_VARIABLES: readonly ["--background", "--surface", "--foreground", "--brand", "--brand-foreground"];
|
|
3
|
+
/** Variables a theme may override; everything else derives from the required five. */
|
|
4
|
+
export declare const OPTIONAL_THEME_VARIABLES: readonly ["--radius", "--shape-full", "--shape-lg", "--style-border", "--muted-foreground", "--border", "--input", "--primary", "--primary-foreground", "--destructive", "--destructive-foreground", "--success", "--success-foreground", "--warning", "--warning-foreground", "--info", "--info-foreground", "--font-sans", "--font-heading", "--font-mono"];
|
|
5
|
+
/** WCAG AA for normal text. */
|
|
6
|
+
export declare const MIN_TEXT_CONTRAST = 4.5;
|
|
7
|
+
/** WCAG AA for large text and UI parts, used for brand on surface. */
|
|
8
|
+
export declare const MIN_UI_CONTRAST = 3;
|
|
9
|
+
export type ThemeVariables = Record<string, string>;
|
|
10
|
+
export interface ParsedTheme {
|
|
11
|
+
light: ThemeVariables;
|
|
12
|
+
dark: ThemeVariables;
|
|
13
|
+
}
|
|
14
|
+
export interface ThemeProblem {
|
|
15
|
+
mode: 'light' | 'dark';
|
|
16
|
+
message: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads the light and dark variables of one style from a theme.css. Light is
|
|
20
|
+
* every rule whose selector names `[data-style='<id>']` without `.dark`; dark is
|
|
21
|
+
* every rule that names both.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseThemeCss(css: string, styleId: string): ParsedTheme;
|
|
24
|
+
/** Checks a theme against the contract: required variables and contrast. */
|
|
25
|
+
export declare function validateTheme(theme: ParsedTheme): ThemeProblem[];
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { contrastRatio } from './styles.js';
|
|
2
|
+
/** Variables every theme must set, in light and in dark. */
|
|
3
|
+
export const REQUIRED_THEME_VARIABLES = [
|
|
4
|
+
'--background',
|
|
5
|
+
'--surface',
|
|
6
|
+
'--foreground',
|
|
7
|
+
'--brand',
|
|
8
|
+
'--brand-foreground',
|
|
9
|
+
];
|
|
10
|
+
/** Variables a theme may override; everything else derives from the required five. */
|
|
11
|
+
export const OPTIONAL_THEME_VARIABLES = [
|
|
12
|
+
'--radius',
|
|
13
|
+
'--shape-full',
|
|
14
|
+
'--shape-lg',
|
|
15
|
+
'--style-border',
|
|
16
|
+
'--muted-foreground',
|
|
17
|
+
'--border',
|
|
18
|
+
'--input',
|
|
19
|
+
'--primary',
|
|
20
|
+
'--primary-foreground',
|
|
21
|
+
'--destructive',
|
|
22
|
+
'--destructive-foreground',
|
|
23
|
+
'--success',
|
|
24
|
+
'--success-foreground',
|
|
25
|
+
'--warning',
|
|
26
|
+
'--warning-foreground',
|
|
27
|
+
'--info',
|
|
28
|
+
'--info-foreground',
|
|
29
|
+
'--font-sans',
|
|
30
|
+
'--font-heading',
|
|
31
|
+
'--font-mono',
|
|
32
|
+
];
|
|
33
|
+
/** WCAG AA for normal text. */
|
|
34
|
+
export const MIN_TEXT_CONTRAST = 4.5;
|
|
35
|
+
/** WCAG AA for large text and UI parts, used for brand on surface. */
|
|
36
|
+
export const MIN_UI_CONTRAST = 3;
|
|
37
|
+
const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
38
|
+
function normalizeHex(value) {
|
|
39
|
+
const hex = value.trim().toLowerCase();
|
|
40
|
+
if (!HEX.test(hex))
|
|
41
|
+
return null;
|
|
42
|
+
if (hex.length === 4)
|
|
43
|
+
return `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}`;
|
|
44
|
+
return hex;
|
|
45
|
+
}
|
|
46
|
+
function declarations(body) {
|
|
47
|
+
const result = {};
|
|
48
|
+
for (const match of body.matchAll(/(--[\w-]+)\s*:\s*([^;]+);/g)) {
|
|
49
|
+
result[match[1]] = match[2].trim();
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Reads the light and dark variables of one style from a theme.css. Light is
|
|
55
|
+
* every rule whose selector names `[data-style='<id>']` without `.dark`; dark is
|
|
56
|
+
* every rule that names both.
|
|
57
|
+
*/
|
|
58
|
+
export function parseThemeCss(css, styleId) {
|
|
59
|
+
const light = {};
|
|
60
|
+
const dark = {};
|
|
61
|
+
const withoutComments = css.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
62
|
+
for (const match of withoutComments.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
|
|
63
|
+
const selector = match[1].replace(/\s+/g, ' ');
|
|
64
|
+
const names = new RegExp(`data-style=['"]?${styleId}['"]?\\]`).test(selector);
|
|
65
|
+
if (!names)
|
|
66
|
+
continue;
|
|
67
|
+
Object.assign(selector.includes('.dark') ? dark : light, declarations(match[2]));
|
|
68
|
+
}
|
|
69
|
+
return { light, dark };
|
|
70
|
+
}
|
|
71
|
+
/** Checks a theme against the contract: required variables and contrast. */
|
|
72
|
+
export function validateTheme(theme) {
|
|
73
|
+
const problems = [];
|
|
74
|
+
for (const mode of ['light', 'dark']) {
|
|
75
|
+
// Dark inherits whatever the light block set and dark does not override.
|
|
76
|
+
const vars = mode === 'light' ? theme.light : { ...theme.light, ...theme.dark };
|
|
77
|
+
for (const name of REQUIRED_THEME_VARIABLES) {
|
|
78
|
+
if (!vars[name])
|
|
79
|
+
problems.push({ mode, message: `missing ${name}` });
|
|
80
|
+
}
|
|
81
|
+
if (mode === 'dark' && Object.keys(theme.dark).length === 0) {
|
|
82
|
+
problems.push({ mode, message: 'no dark block (selector with .dark and the style id)' });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const pair = (a, b, min) => {
|
|
86
|
+
const x = vars[a] && normalizeHex(vars[a]);
|
|
87
|
+
const y = vars[b] && normalizeHex(vars[b]);
|
|
88
|
+
if (!vars[a] || !vars[b])
|
|
89
|
+
return;
|
|
90
|
+
if (!x || !y) {
|
|
91
|
+
problems.push({ mode, message: `${a} and ${b} must be hex colors to check contrast` });
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const ratio = contrastRatio(x, y);
|
|
95
|
+
if (ratio < min) {
|
|
96
|
+
problems.push({
|
|
97
|
+
mode,
|
|
98
|
+
message: `${a} on ${b} contrast ${ratio.toFixed(2)} is below ${min}`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
pair('--foreground', '--background', MIN_TEXT_CONTRAST);
|
|
103
|
+
pair('--foreground', '--surface', MIN_TEXT_CONTRAST);
|
|
104
|
+
pair('--brand-foreground', '--brand', MIN_TEXT_CONTRAST);
|
|
105
|
+
pair('--brand', '--surface', MIN_UI_CONTRAST);
|
|
106
|
+
}
|
|
107
|
+
return problems;
|
|
108
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/* Tetsu token contract. A theme sets four tones (--background, --surface,
|
|
2
|
+
--foreground, --brand) plus --brand-foreground; every other color derives
|
|
3
|
+
from them with color-mix(), so applying a theme only overrides those five.
|
|
4
|
+
Shape and type come from the style (css/styles.css). Everything is plain CSS
|
|
5
|
+
custom properties: it works with or without Tailwind. */
|
|
6
|
+
|
|
7
|
+
@layer base {
|
|
8
|
+
:root {
|
|
9
|
+
--background: #ffffff;
|
|
10
|
+
--surface: #fafafa;
|
|
11
|
+
--foreground: #000000;
|
|
12
|
+
--brand: #3b82f6;
|
|
13
|
+
--brand-foreground: #ffffff;
|
|
14
|
+
|
|
15
|
+
--card: var(--background);
|
|
16
|
+
--card-foreground: var(--foreground);
|
|
17
|
+
--popover: var(--surface);
|
|
18
|
+
--popover-foreground: var(--foreground);
|
|
19
|
+
--primary: var(--foreground);
|
|
20
|
+
--primary-foreground: var(--background);
|
|
21
|
+
--secondary: var(--surface);
|
|
22
|
+
--secondary-foreground: var(--foreground);
|
|
23
|
+
--muted: var(--surface);
|
|
24
|
+
--muted-foreground: color-mix(in srgb, var(--foreground) 55%, var(--background));
|
|
25
|
+
--accent: color-mix(in srgb, var(--foreground) 6%, var(--background));
|
|
26
|
+
--accent-foreground: var(--foreground);
|
|
27
|
+
--border: color-mix(in srgb, var(--foreground) 12%, var(--background));
|
|
28
|
+
--input: color-mix(in srgb, var(--foreground) 12%, var(--background));
|
|
29
|
+
--ring: var(--brand);
|
|
30
|
+
|
|
31
|
+
/* Status colors. Text on them uses the matching -foreground. */
|
|
32
|
+
--destructive: #ef4444;
|
|
33
|
+
--destructive-foreground: #ffffff;
|
|
34
|
+
--success: #16a34a;
|
|
35
|
+
--success-foreground: #ffffff;
|
|
36
|
+
--warning: #d97706;
|
|
37
|
+
--warning-foreground: #ffffff;
|
|
38
|
+
--info: #2563eb;
|
|
39
|
+
--info-foreground: #ffffff;
|
|
40
|
+
|
|
41
|
+
--sidebar: var(--background);
|
|
42
|
+
--sidebar-foreground: var(--foreground);
|
|
43
|
+
--sidebar-primary: var(--primary);
|
|
44
|
+
--sidebar-primary-foreground: var(--primary-foreground);
|
|
45
|
+
--sidebar-accent: var(--accent);
|
|
46
|
+
--sidebar-accent-foreground: var(--accent-foreground);
|
|
47
|
+
--sidebar-border: var(--border);
|
|
48
|
+
--sidebar-ring: var(--ring);
|
|
49
|
+
|
|
50
|
+
--chart-1: oklch(0.87 0 0);
|
|
51
|
+
--chart-2: oklch(0.556 0 0);
|
|
52
|
+
--chart-3: oklch(0.439 0 0);
|
|
53
|
+
--chart-4: oklch(0.371 0 0);
|
|
54
|
+
--chart-5: oklch(0.269 0 0);
|
|
55
|
+
|
|
56
|
+
--radius: 0.75rem;
|
|
57
|
+
|
|
58
|
+
/* Fonts: apps that load their own fonts (next/font, @font-face) set
|
|
59
|
+
--font-inter and friends; without them the system stack is used. */
|
|
60
|
+
--font-sans: var(--font-inter, ui-sans-serif, system-ui, sans-serif);
|
|
61
|
+
--font-heading: var(--font-nunito, ui-sans-serif, system-ui, sans-serif);
|
|
62
|
+
--font-mono: var(--font-jetbrains, ui-monospace, SFMono-Regular, Menlo, monospace);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.dark {
|
|
66
|
+
--background: #090909;
|
|
67
|
+
--surface: #171717;
|
|
68
|
+
--foreground: #ffffff;
|
|
69
|
+
--destructive: #f87171;
|
|
70
|
+
--destructive-foreground: #111111;
|
|
71
|
+
--success: #4ade80;
|
|
72
|
+
--success-foreground: #111111;
|
|
73
|
+
--warning: #fbbf24;
|
|
74
|
+
--warning-foreground: #111111;
|
|
75
|
+
--info: #60a5fa;
|
|
76
|
+
--info-foreground: #111111;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/* Generated by scripts/build-css.mjs from src/styles.ts. Do not edit. */
|
|
2
|
+
@layer base {
|
|
3
|
+
html[data-style='original'] {
|
|
4
|
+
--background: #ffffff;
|
|
5
|
+
--surface: #fafafa;
|
|
6
|
+
--foreground: #000000;
|
|
7
|
+
--brand: #3b82f6;
|
|
8
|
+
--brand-foreground: #111111;
|
|
9
|
+
}
|
|
10
|
+
html[data-style='original'].dark {
|
|
11
|
+
--background: #090909;
|
|
12
|
+
--surface: #171717;
|
|
13
|
+
--foreground: #ffffff;
|
|
14
|
+
--brand: #3b82f6;
|
|
15
|
+
--brand-foreground: #111111;
|
|
16
|
+
}
|
|
17
|
+
html[data-style='recto'] {
|
|
18
|
+
--background: #ffffff;
|
|
19
|
+
--surface: #f4f4f5;
|
|
20
|
+
--foreground: #0a0a0a;
|
|
21
|
+
--brand: #0a0a0a;
|
|
22
|
+
--brand-foreground: #ffffff;
|
|
23
|
+
}
|
|
24
|
+
html[data-style='recto'].dark {
|
|
25
|
+
--background: #0a0a0a;
|
|
26
|
+
--surface: #171717;
|
|
27
|
+
--foreground: #fafafa;
|
|
28
|
+
--brand: #fafafa;
|
|
29
|
+
--brand-foreground: #111111;
|
|
30
|
+
}
|
|
31
|
+
html[data-style='papel'] {
|
|
32
|
+
--background: #eef0ea;
|
|
33
|
+
--surface: #f9faf6;
|
|
34
|
+
--foreground: #14213a;
|
|
35
|
+
--brand: #2740b0;
|
|
36
|
+
--brand-foreground: #ffffff;
|
|
37
|
+
}
|
|
38
|
+
html[data-style='papel'].dark {
|
|
39
|
+
--background: #10182a;
|
|
40
|
+
--surface: #1a2439;
|
|
41
|
+
--foreground: #e9edf2;
|
|
42
|
+
--brand: #8ea6ff;
|
|
43
|
+
--brand-foreground: #111111;
|
|
44
|
+
}
|
|
45
|
+
html[data-style='bloque'] {
|
|
46
|
+
--background: #ffe34d;
|
|
47
|
+
--surface: #fffdf0;
|
|
48
|
+
--foreground: #111111;
|
|
49
|
+
--brand: #d81b63;
|
|
50
|
+
--brand-foreground: #ffffff;
|
|
51
|
+
}
|
|
52
|
+
html[data-style='bloque'].dark {
|
|
53
|
+
--background: #141414;
|
|
54
|
+
--surface: #232323;
|
|
55
|
+
--foreground: #f6f5ee;
|
|
56
|
+
--brand: #d9ff3f;
|
|
57
|
+
--brand-foreground: #111111;
|
|
58
|
+
}
|
|
59
|
+
html[data-style='caramelo'] {
|
|
60
|
+
--background: #f5efff;
|
|
61
|
+
--surface: #ffffff;
|
|
62
|
+
--foreground: #2a1a4a;
|
|
63
|
+
--brand: #7235e0;
|
|
64
|
+
--brand-foreground: #ffffff;
|
|
65
|
+
}
|
|
66
|
+
html[data-style='caramelo'].dark {
|
|
67
|
+
--background: #1a1230;
|
|
68
|
+
--surface: #271c44;
|
|
69
|
+
--foreground: #f1eaff;
|
|
70
|
+
--brand: #b999ff;
|
|
71
|
+
--brand-foreground: #111111;
|
|
72
|
+
}
|
|
73
|
+
html[data-style='tetsu'] {
|
|
74
|
+
--background: #ffffff;
|
|
75
|
+
--surface: #f4f4f2;
|
|
76
|
+
--foreground: #0b0b0c;
|
|
77
|
+
--brand: #e2470f;
|
|
78
|
+
--brand-foreground: #111111;
|
|
79
|
+
}
|
|
80
|
+
html[data-style='tetsu'].dark {
|
|
81
|
+
--background: #070708;
|
|
82
|
+
--surface: #0e0f11;
|
|
83
|
+
--foreground: #f2f2ee;
|
|
84
|
+
--brand: #ff5a1f;
|
|
85
|
+
--brand-foreground: #111111;
|
|
86
|
+
}
|
|
87
|
+
html[data-style='vidrio'] {
|
|
88
|
+
--background: #f3f4f1;
|
|
89
|
+
--surface: #ffffff;
|
|
90
|
+
--foreground: #16191d;
|
|
91
|
+
--brand: #1747ff;
|
|
92
|
+
--brand-foreground: #ffffff;
|
|
93
|
+
}
|
|
94
|
+
html[data-style='vidrio'].dark {
|
|
95
|
+
--background: #0e1013;
|
|
96
|
+
--surface: #15181c;
|
|
97
|
+
--foreground: #eceeef;
|
|
98
|
+
--brand: #6e8bff;
|
|
99
|
+
--brand-foreground: #111111;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/* Visual styles: shape and type per <html data-style="...">. Tokens go in @layer
|
|
2
|
+
base; rules that must beat Tailwind utilities (heading weight, button
|
|
3
|
+
shadows) stay unlayered. Original has no block: it is the :root default. */
|
|
4
|
+
|
|
5
|
+
@layer base {
|
|
6
|
+
:root {
|
|
7
|
+
/* rounded-full, rounded-lg and border read these variables (see @theme in
|
|
8
|
+
tailwind.css). For a true circle in any style: rounded-[50%]. */
|
|
9
|
+
--shape-full: 9999px;
|
|
10
|
+
--shape-lg: 12px;
|
|
11
|
+
--style-border: 1px;
|
|
12
|
+
--switch-thumb-on: #ffffff;
|
|
13
|
+
--switch-thumb-off: #ffffff;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
html[data-style='recto'],
|
|
17
|
+
html[data-style='papel'],
|
|
18
|
+
html[data-style='bloque'],
|
|
19
|
+
html[data-style='caramelo'],
|
|
20
|
+
html[data-style='vidrio'] {
|
|
21
|
+
--primary: var(--brand);
|
|
22
|
+
--primary-foreground: var(--brand-foreground);
|
|
23
|
+
--switch-thumb-on: var(--brand-foreground);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
html[data-style='recto'] {
|
|
27
|
+
--radius: 0rem;
|
|
28
|
+
--shape-full: 0px;
|
|
29
|
+
--shape-lg: 0px;
|
|
30
|
+
--muted-foreground: color-mix(in srgb, var(--foreground) 62%, var(--background));
|
|
31
|
+
--font-heading: var(--font-inter, ui-sans-serif, system-ui, sans-serif);
|
|
32
|
+
font-size: 93.75%;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
html[data-style='papel'] {
|
|
36
|
+
--radius: 0.1875rem;
|
|
37
|
+
--shape-full: 3px;
|
|
38
|
+
--shape-lg: 4px;
|
|
39
|
+
--muted-foreground: color-mix(in srgb, var(--foreground) 72%, var(--background));
|
|
40
|
+
--input: color-mix(in srgb, var(--foreground) 40%, var(--background));
|
|
41
|
+
--font-sans: var(--font-newsreader, Georgia, serif);
|
|
42
|
+
--font-heading: var(--font-newsreader, Georgia, serif);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
html[data-style='bloque'] {
|
|
46
|
+
--radius: 0rem;
|
|
47
|
+
--shape-full: 0px;
|
|
48
|
+
--shape-lg: 0px;
|
|
49
|
+
--style-border: 2px;
|
|
50
|
+
--border: var(--foreground);
|
|
51
|
+
--input: var(--foreground);
|
|
52
|
+
--switch-thumb-off: var(--background);
|
|
53
|
+
--muted-foreground: color-mix(in srgb, var(--foreground) 82%, var(--background));
|
|
54
|
+
--font-sans: var(--font-archivo, ui-sans-serif, sans-serif);
|
|
55
|
+
--font-heading: var(--font-archivo-black, Impact, sans-serif);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
html[data-style='caramelo'] {
|
|
59
|
+
--radius: 1.25rem;
|
|
60
|
+
--shape-lg: 20px;
|
|
61
|
+
--muted-foreground: color-mix(in srgb, var(--foreground) 72%, var(--background));
|
|
62
|
+
--border: color-mix(in srgb, var(--foreground) 14%, var(--background));
|
|
63
|
+
--font-sans: var(--font-nunito, ui-rounded, sans-serif);
|
|
64
|
+
--font-heading: var(--font-fredoka, ui-rounded, sans-serif);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* Tetsu (style.tetsustudio.com/s/tetsu): controls 4px, buttons stay pills,
|
|
68
|
+
Inter for headings too. The primary stays inverted like Original, so the
|
|
69
|
+
switch thumb takes the ground color, readable on every ember/steel accent. */
|
|
70
|
+
html[data-style='tetsu'] {
|
|
71
|
+
--radius: 0.25rem;
|
|
72
|
+
--shape-lg: 4px;
|
|
73
|
+
--muted-foreground: color-mix(in srgb, var(--foreground) 62%, var(--background));
|
|
74
|
+
--switch-thumb-on: var(--background);
|
|
75
|
+
--font-heading: var(--font-inter, ui-sans-serif, system-ui, sans-serif);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* Vidrio (style.tetsustudio.com/s/vidrio): 6px controls, 2px panels, Funnel
|
|
79
|
+
loaded at runtime (googleFonts in lib/visual-styles.ts). */
|
|
80
|
+
html[data-style='vidrio'] {
|
|
81
|
+
--radius: 0.125rem;
|
|
82
|
+
--shape-full: 6px;
|
|
83
|
+
--shape-lg: 2px;
|
|
84
|
+
--muted-foreground: color-mix(in srgb, var(--foreground) 68%, var(--background));
|
|
85
|
+
--font-sans: 'Funnel Sans', var(--font-inter, ui-sans-serif, system-ui, sans-serif);
|
|
86
|
+
--font-heading: 'Funnel Display', 'Funnel Sans', var(--font-inter, ui-sans-serif, system-ui, sans-serif);
|
|
87
|
+
--font-mono: 'Martian Mono', var(--font-jetbrains, ui-monospace, monospace);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* In light mode a white thumb barely shows on the track; in dark it does. */
|
|
91
|
+
html[data-style='recto']:not(.dark),
|
|
92
|
+
html[data-style='caramelo']:not(.dark),
|
|
93
|
+
html[data-style='tetsu']:not(.dark),
|
|
94
|
+
html[data-style='vidrio']:not(.dark) {
|
|
95
|
+
--switch-thumb-off: var(--muted-foreground);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
html[data-style='papel']:not(.dark) {
|
|
99
|
+
--switch-thumb-off: var(--foreground);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
html[data-style='recto'] [data-slot='table-head'] {
|
|
104
|
+
font-family: var(--font-mono);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
html[data-style='papel'] :is(h1, h2, h3) {
|
|
108
|
+
font-family: var(--font-heading);
|
|
109
|
+
font-weight: 500;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
html[data-style='bloque'] :is(h1, h2, h3) {
|
|
113
|
+
font-family: var(--font-heading);
|
|
114
|
+
font-weight: 400;
|
|
115
|
+
text-transform: uppercase;
|
|
116
|
+
letter-spacing: -0.01em;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* A trigger (menu, popover) has its own data-slot; when it looks like a button it has data-variant. */
|
|
120
|
+
html[data-style='bloque']
|
|
121
|
+
:is([data-slot='button'], [data-slot$='-trigger']):is(
|
|
122
|
+
[data-variant='default'],
|
|
123
|
+
[data-variant='outline'],
|
|
124
|
+
[data-variant='secondary']
|
|
125
|
+
) {
|
|
126
|
+
border-color: var(--foreground);
|
|
127
|
+
box-shadow: 3px 3px 0 var(--foreground);
|
|
128
|
+
font-weight: 700;
|
|
129
|
+
letter-spacing: 0.03em;
|
|
130
|
+
text-transform: uppercase;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
html[data-style='bloque']
|
|
134
|
+
:is([data-slot='button'], [data-slot$='-trigger']):is(
|
|
135
|
+
[data-variant='default'],
|
|
136
|
+
[data-variant='outline'],
|
|
137
|
+
[data-variant='secondary']
|
|
138
|
+
):hover {
|
|
139
|
+
box-shadow: 5px 5px 0 var(--foreground);
|
|
140
|
+
transform: translate(-2px, -2px);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
html[data-style='bloque']
|
|
144
|
+
:is(
|
|
145
|
+
[data-slot='dialog-content'],
|
|
146
|
+
[data-slot='popover-content'],
|
|
147
|
+
[data-slot='select-content'],
|
|
148
|
+
[data-slot='dropdown-menu-content']
|
|
149
|
+
) {
|
|
150
|
+
border: 2px solid var(--foreground);
|
|
151
|
+
box-shadow: 6px 6px 0 var(--foreground);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
html[data-style='caramelo'] :is(h1, h2, h3) {
|
|
155
|
+
font-family: var(--font-heading);
|
|
156
|
+
font-weight: 600;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
html[data-style='caramelo']
|
|
160
|
+
:is([data-slot='button'], [data-slot$='-trigger']):is(
|
|
161
|
+
[data-variant='default'],
|
|
162
|
+
[data-variant='secondary']
|
|
163
|
+
) {
|
|
164
|
+
box-shadow: 0 2px 8px color-mix(in srgb, var(--brand) 24%, transparent);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
html[data-style='caramelo']
|
|
168
|
+
:is([data-slot='button'], [data-slot$='-trigger']):is(
|
|
169
|
+
[data-variant='default'],
|
|
170
|
+
[data-variant='secondary']
|
|
171
|
+
):hover {
|
|
172
|
+
box-shadow: 0 6px 16px color-mix(in srgb, var(--brand) 34%, transparent);
|
|
173
|
+
transform: translateY(-1px);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
html[data-style='tetsu'] :is(h1, h2, h3) {
|
|
177
|
+
font-family: var(--font-heading);
|
|
178
|
+
font-weight: 600;
|
|
179
|
+
letter-spacing: -0.03em;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
html[data-style='tetsu'] [data-slot='table-head'] {
|
|
183
|
+
font-family: var(--font-mono);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
html[data-style='vidrio'] :is(h1, h2) {
|
|
187
|
+
font-family: var(--font-heading);
|
|
188
|
+
font-weight: 300;
|
|
189
|
+
letter-spacing: -0.01em;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
html[data-style='vidrio'] h3 {
|
|
193
|
+
font-family: var(--font-heading);
|
|
194
|
+
font-weight: 500;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
html[data-style='vidrio']
|
|
198
|
+
:is(
|
|
199
|
+
[data-slot='dialog-content'],
|
|
200
|
+
[data-slot='popover-content'],
|
|
201
|
+
[data-slot='select-content'],
|
|
202
|
+
[data-slot='dropdown-menu-content']
|
|
203
|
+
) {
|
|
204
|
+
box-shadow:
|
|
205
|
+
0 1px 0 var(--border),
|
|
206
|
+
0 12px 32px -12px rgb(22 25 29 / 0.18);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@media (prefers-reduced-motion: reduce) {
|
|
210
|
+
html[data-style] :is([data-slot='button'], [data-slot$='-trigger'])[data-variant]:hover {
|
|
211
|
+
transform: none !important;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/* Tailwind v4 mapping of the Tetsu token contract. Import it after
|
|
2
|
+
'tailwindcss' and '@tetsustudio/tokens/css' in an app that uses Tailwind:
|
|
3
|
+
|
|
4
|
+
@import 'tailwindcss';
|
|
5
|
+
@import '@tetsustudio/tokens/css';
|
|
6
|
+
@import '@tetsustudio/tokens/tailwind.css';
|
|
7
|
+
|
|
8
|
+
Apps without Tailwind only need '@tetsustudio/tokens/css'. */
|
|
9
|
+
|
|
10
|
+
@custom-variant dark (&:where(.dark, .dark *));
|
|
11
|
+
|
|
12
|
+
@theme inline {
|
|
13
|
+
--color-background: var(--background);
|
|
14
|
+
--color-surface: var(--surface);
|
|
15
|
+
--color-foreground: var(--foreground);
|
|
16
|
+
--color-brand: var(--brand);
|
|
17
|
+
--color-brand-foreground: var(--brand-foreground);
|
|
18
|
+
|
|
19
|
+
--color-card: var(--card);
|
|
20
|
+
--color-card-foreground: var(--card-foreground);
|
|
21
|
+
--color-popover: var(--popover);
|
|
22
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
23
|
+
--color-primary: var(--primary);
|
|
24
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
25
|
+
--color-secondary: var(--secondary);
|
|
26
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
27
|
+
--color-muted: var(--muted);
|
|
28
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
29
|
+
--color-accent: var(--accent);
|
|
30
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
31
|
+
--color-border: var(--border);
|
|
32
|
+
--color-input: var(--input);
|
|
33
|
+
--color-ring: var(--ring);
|
|
34
|
+
|
|
35
|
+
--color-destructive: var(--destructive);
|
|
36
|
+
--color-destructive-foreground: var(--destructive-foreground);
|
|
37
|
+
--color-success: var(--success);
|
|
38
|
+
--color-success-foreground: var(--success-foreground);
|
|
39
|
+
--color-warning: var(--warning);
|
|
40
|
+
--color-warning-foreground: var(--warning-foreground);
|
|
41
|
+
--color-info: var(--info);
|
|
42
|
+
--color-info-foreground: var(--info-foreground);
|
|
43
|
+
|
|
44
|
+
--color-sidebar: var(--sidebar);
|
|
45
|
+
--color-sidebar-foreground: var(--sidebar-foreground);
|
|
46
|
+
--color-sidebar-primary: var(--sidebar-primary);
|
|
47
|
+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
|
48
|
+
--color-sidebar-accent: var(--sidebar-accent);
|
|
49
|
+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
|
50
|
+
--color-sidebar-border: var(--sidebar-border);
|
|
51
|
+
--color-sidebar-ring: var(--sidebar-ring);
|
|
52
|
+
|
|
53
|
+
--color-chart-1: var(--chart-1);
|
|
54
|
+
--color-chart-2: var(--chart-2);
|
|
55
|
+
--color-chart-3: var(--chart-3);
|
|
56
|
+
--color-chart-4: var(--chart-4);
|
|
57
|
+
--color-chart-5: var(--chart-5);
|
|
58
|
+
|
|
59
|
+
--radius: var(--radius);
|
|
60
|
+
--radius-full: var(--shape-full);
|
|
61
|
+
--radius-lg: var(--shape-lg);
|
|
62
|
+
--radius-sm: calc(var(--radius) * 0.6);
|
|
63
|
+
--radius-md: calc(var(--radius) * 0.8);
|
|
64
|
+
--radius-xl: calc(var(--radius) * 1.4);
|
|
65
|
+
--radius-2xl: calc(var(--radius) * 1.8);
|
|
66
|
+
--radius-3xl: calc(var(--radius) * 2.2);
|
|
67
|
+
--radius-4xl: calc(var(--radius) * 2.6);
|
|
68
|
+
--default-border-width: var(--style-border);
|
|
69
|
+
|
|
70
|
+
--font-sans: var(--font-sans);
|
|
71
|
+
--font-heading: var(--font-heading);
|
|
72
|
+
--font-mono: var(--font-mono);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@layer base {
|
|
76
|
+
/* In v4 the default border is currentColor: without this every bare
|
|
77
|
+
`border` would take the text color instead of the theme separator. */
|
|
78
|
+
*,
|
|
79
|
+
::after,
|
|
80
|
+
::before,
|
|
81
|
+
::backdrop,
|
|
82
|
+
::file-selector-button {
|
|
83
|
+
border-color: var(--color-border);
|
|
84
|
+
}
|
|
85
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ColorTheme } from './styles.js';
|
|
2
|
+
/** CSS variables that paint one palette. */
|
|
3
|
+
export declare function paletteVariables(theme: ColorTheme): Record<string, string>;
|
|
4
|
+
interface StyleTarget {
|
|
5
|
+
style: {
|
|
6
|
+
setProperty(name: string, value: string): void;
|
|
7
|
+
};
|
|
8
|
+
classList: {
|
|
9
|
+
toggle(name: string, force?: boolean): unknown;
|
|
10
|
+
};
|
|
11
|
+
setAttribute(name: string, value: string): void;
|
|
12
|
+
}
|
|
13
|
+
/** Applies a palette to an element (usually document.documentElement). */
|
|
14
|
+
export declare function applyPalette(theme: ColorTheme, target: StyleTarget): void;
|
|
15
|
+
/** CSS for every style's default palette, light under the style and dark under `.dark`. */
|
|
16
|
+
export declare function palettesCss(themes: readonly ColorTheme[], defaults: Record<string, string>): string;
|
|
17
|
+
export {};
|
package/dist/palette.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readableOn } from './styles.js';
|
|
2
|
+
/** CSS variables that paint one palette. */
|
|
3
|
+
export function paletteVariables(theme) {
|
|
4
|
+
const vars = {
|
|
5
|
+
'--background': theme.background,
|
|
6
|
+
'--surface': theme.surface,
|
|
7
|
+
'--foreground': theme.foreground,
|
|
8
|
+
'--brand': theme.accent,
|
|
9
|
+
'--brand-foreground': readableOn(theme.accent),
|
|
10
|
+
};
|
|
11
|
+
if (theme.mutedMix) {
|
|
12
|
+
vars['--muted-foreground'] =
|
|
13
|
+
`color-mix(in srgb, var(--foreground) ${theme.mutedMix}%, var(--background))`;
|
|
14
|
+
}
|
|
15
|
+
return vars;
|
|
16
|
+
}
|
|
17
|
+
/** Applies a palette to an element (usually document.documentElement). */
|
|
18
|
+
export function applyPalette(theme, target) {
|
|
19
|
+
target.setAttribute('data-style', theme.style);
|
|
20
|
+
target.classList.toggle('dark', theme.mode === 'dark');
|
|
21
|
+
for (const [name, value] of Object.entries(paletteVariables(theme))) {
|
|
22
|
+
target.style.setProperty(name, value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** CSS for every style's default palette, light under the style and dark under `.dark`. */
|
|
26
|
+
export function palettesCss(themes, defaults) {
|
|
27
|
+
const blocks = [
|
|
28
|
+
'/* Generated by scripts/build-css.mjs from src/styles.ts. Do not edit. */',
|
|
29
|
+
'@layer base {',
|
|
30
|
+
];
|
|
31
|
+
for (const [style, family] of Object.entries(defaults)) {
|
|
32
|
+
for (const mode of ['light', 'dark']) {
|
|
33
|
+
const theme = themes.find((t) => t.style === style && t.id === `${family}-${mode}`);
|
|
34
|
+
if (!theme)
|
|
35
|
+
continue;
|
|
36
|
+
const selector = mode === 'light' ? `html[data-style='${style}']` : `html[data-style='${style}'].dark`;
|
|
37
|
+
const body = Object.entries(paletteVariables(theme))
|
|
38
|
+
.map(([name, value]) => ` ${name}: ${value};`)
|
|
39
|
+
.join('\n');
|
|
40
|
+
blocks.push(` ${selector} {\n${body}\n }`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
blocks.push('}', '');
|
|
44
|
+
return blocks.join('\n');
|
|
45
|
+
}
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface LocalizedText {
|
|
2
|
+
es: string;
|
|
3
|
+
en: string;
|
|
4
|
+
}
|
|
5
|
+
export type ThemeMode = 'light' | 'dark';
|
|
6
|
+
export declare const STYLE_IDS: readonly ["original", "recto", "papel", "bloque", "caramelo", "tetsu", "vidrio"];
|
|
7
|
+
export type StyleId = (typeof STYLE_IDS)[number];
|
|
8
|
+
export declare function isStyleId(value: unknown): value is StyleId;
|
|
9
|
+
export declare const STYLE_STORAGE_KEY = "visual-style";
|
|
10
|
+
export interface VisualStyle {
|
|
11
|
+
label: LocalizedText;
|
|
12
|
+
description: LocalizedText;
|
|
13
|
+
defaultFamily: string;
|
|
14
|
+
defaultMode: ThemeMode;
|
|
15
|
+
accentIsPrimary: boolean;
|
|
16
|
+
googleFonts?: readonly string[];
|
|
17
|
+
sample: {
|
|
18
|
+
font: string;
|
|
19
|
+
radius: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare const VISUAL_STYLES: Record<StyleId, VisualStyle>;
|
|
23
|
+
export interface ColorTheme {
|
|
24
|
+
id: string;
|
|
25
|
+
style: StyleId;
|
|
26
|
+
label: LocalizedText;
|
|
27
|
+
mode: ThemeMode;
|
|
28
|
+
background: string;
|
|
29
|
+
surface: string;
|
|
30
|
+
foreground: string;
|
|
31
|
+
accent: string;
|
|
32
|
+
mutedMix?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare const COLOR_THEME_PRESETS: ColorTheme[];
|
|
35
|
+
export declare function stylePalettes(style: StyleId): ColorTheme[];
|
|
36
|
+
export declare function resolveColorTheme(style: StyleId, savedThemeId: string | null, savedMode: string | null): ColorTheme;
|
|
37
|
+
export declare function isManualAccent(style: StyleId, themeId: string, mode: ThemeMode, accent: string): boolean;
|
|
38
|
+
export declare function contrastRatio(a: string, b: string): number;
|
|
39
|
+
export declare function readableOn(hex: string): "#ffffff" | "#111111";
|
package/dist/styles.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
export const STYLE_IDS = [
|
|
2
|
+
'original',
|
|
3
|
+
'recto',
|
|
4
|
+
'papel',
|
|
5
|
+
'bloque',
|
|
6
|
+
'caramelo',
|
|
7
|
+
'tetsu',
|
|
8
|
+
'vidrio',
|
|
9
|
+
];
|
|
10
|
+
export function isStyleId(value) {
|
|
11
|
+
return typeof value === 'string' && STYLE_IDS.includes(value);
|
|
12
|
+
}
|
|
13
|
+
// localStorage key of the style the user picked; without one, the app's default.
|
|
14
|
+
export const STYLE_STORAGE_KEY = 'visual-style';
|
|
15
|
+
export const VISUAL_STYLES = {
|
|
16
|
+
original: {
|
|
17
|
+
label: { es: 'Original', en: 'Original' },
|
|
18
|
+
description: {
|
|
19
|
+
es: 'Píldoras, sin tarjetas y botón principal invertido.',
|
|
20
|
+
en: 'Pills, no cards and an inverted primary button.',
|
|
21
|
+
},
|
|
22
|
+
defaultFamily: 'mono',
|
|
23
|
+
defaultMode: 'dark',
|
|
24
|
+
accentIsPrimary: false,
|
|
25
|
+
sample: { font: 'var(--font-nunito)', radius: '9999px' },
|
|
26
|
+
},
|
|
27
|
+
recto: {
|
|
28
|
+
label: { es: 'Recto', en: 'Straight' },
|
|
29
|
+
description: {
|
|
30
|
+
es: 'Esquinas rectas, línea fina y más densidad.',
|
|
31
|
+
en: 'Square corners, thin lines and more density.',
|
|
32
|
+
},
|
|
33
|
+
defaultFamily: 'graphite',
|
|
34
|
+
defaultMode: 'dark',
|
|
35
|
+
accentIsPrimary: true,
|
|
36
|
+
sample: { font: 'var(--font-inter)', radius: '0px' },
|
|
37
|
+
},
|
|
38
|
+
papel: {
|
|
39
|
+
label: { es: 'Papel', en: 'Paper' },
|
|
40
|
+
description: {
|
|
41
|
+
es: 'Editorial, con serif y casi sin radios.',
|
|
42
|
+
en: 'Editorial, with serif type and barely any radius.',
|
|
43
|
+
},
|
|
44
|
+
defaultFamily: 'ink',
|
|
45
|
+
defaultMode: 'light',
|
|
46
|
+
accentIsPrimary: true,
|
|
47
|
+
sample: { font: 'var(--font-newsreader)', radius: '3px' },
|
|
48
|
+
},
|
|
49
|
+
bloque: {
|
|
50
|
+
label: { es: 'Bloque', en: 'Block' },
|
|
51
|
+
description: {
|
|
52
|
+
es: 'Bordes gruesos, sombras duras y color fuerte.',
|
|
53
|
+
en: 'Thick borders, hard shadows and strong color.',
|
|
54
|
+
},
|
|
55
|
+
defaultFamily: 'lemon',
|
|
56
|
+
defaultMode: 'light',
|
|
57
|
+
accentIsPrimary: true,
|
|
58
|
+
sample: { font: 'var(--font-archivo-black)', radius: '0px' },
|
|
59
|
+
},
|
|
60
|
+
caramelo: {
|
|
61
|
+
label: { es: 'Caramelo', en: 'Candy' },
|
|
62
|
+
description: {
|
|
63
|
+
es: 'Formas redondas y superficies tintadas.',
|
|
64
|
+
en: 'Round shapes and tinted surfaces.',
|
|
65
|
+
},
|
|
66
|
+
defaultFamily: 'grape',
|
|
67
|
+
defaultMode: 'light',
|
|
68
|
+
accentIsPrimary: true,
|
|
69
|
+
sample: { font: 'var(--font-fredoka)', radius: '20px' },
|
|
70
|
+
},
|
|
71
|
+
// From style.tetsustudio.com/s/tetsu/tokens.json: ember on near-black, the
|
|
72
|
+
// primary button stays inverted (ember marks heat and state, not buttons).
|
|
73
|
+
tetsu: {
|
|
74
|
+
label: { es: 'Tetsu', en: 'Tetsu' },
|
|
75
|
+
description: {
|
|
76
|
+
es: 'Casi negro con brasa, Inter apretada y botón principal invertido.',
|
|
77
|
+
en: 'Near-black with ember, tight Inter and an inverted primary button.',
|
|
78
|
+
},
|
|
79
|
+
defaultFamily: 'brasa',
|
|
80
|
+
defaultMode: 'dark',
|
|
81
|
+
accentIsPrimary: false,
|
|
82
|
+
sample: { font: 'var(--font-inter)', radius: '4px' },
|
|
83
|
+
},
|
|
84
|
+
// From style.tetsustudio.com/s/vidrio/tokens.json.
|
|
85
|
+
vidrio: {
|
|
86
|
+
label: { es: 'Vidrio', en: 'Glass' },
|
|
87
|
+
description: {
|
|
88
|
+
es: 'Claro y técnico: Funnel, un solo cobalto y radios chicos.',
|
|
89
|
+
en: 'Light and technical: Funnel type, a single cobalt and small radii.',
|
|
90
|
+
},
|
|
91
|
+
defaultFamily: 'cobalto',
|
|
92
|
+
defaultMode: 'light',
|
|
93
|
+
accentIsPrimary: true,
|
|
94
|
+
sample: { font: "'Funnel Display', var(--font-inter)", radius: '6px' },
|
|
95
|
+
googleFonts: ['funnel-sans', 'funnel-display', 'martian-mono'],
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
function palette(style, family, label, light, dark) {
|
|
99
|
+
return ['light', 'dark'].map((mode) => {
|
|
100
|
+
const [background, surface, foreground, accent, mutedMix] = mode === 'light' ? light : dark;
|
|
101
|
+
return {
|
|
102
|
+
id: `${family}-${mode}`,
|
|
103
|
+
style,
|
|
104
|
+
label,
|
|
105
|
+
mode,
|
|
106
|
+
background,
|
|
107
|
+
surface,
|
|
108
|
+
foreground,
|
|
109
|
+
accent,
|
|
110
|
+
...(mutedMix ? { mutedMix } : {}),
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// prettier-ignore
|
|
115
|
+
export const COLOR_THEME_PRESETS = [
|
|
116
|
+
...palette('original', 'mono', { es: 'Monocromo', en: 'Monochrome' }, ['#ffffff', '#fafafa', '#000000', '#3b82f6'], ['#090909', '#171717', '#ffffff', '#3b82f6']),
|
|
117
|
+
...palette('original', 'midnight', { es: 'Medianoche', en: 'Midnight' }, ['#fffffe', '#f2f4f6', '#00214d', '#1d5fd6', 65], ['#001534', '#00214d', '#fffffe', '#6ab0ff']),
|
|
118
|
+
...palette('recto', 'graphite', { es: 'Grafito', en: 'Graphite' }, ['#ffffff', '#f4f4f5', '#0a0a0a', '#0a0a0a'], ['#0a0a0a', '#171717', '#fafafa', '#fafafa']),
|
|
119
|
+
...palette('recto', 'blue', { es: 'Azul', en: 'Blue' }, ['#ffffff', '#f4f4f5', '#0a0a0a', '#1d4ed8'], ['#0a0a0a', '#171717', '#fafafa', '#60a5fa']),
|
|
120
|
+
...palette('recto', 'red', { es: 'Rojo', en: 'Red' }, ['#ffffff', '#f4f4f5', '#0a0a0a', '#c81e1e'], ['#0a0a0a', '#171717', '#fafafa', '#f87171']),
|
|
121
|
+
...palette('papel', 'ink', { es: 'Tinta', en: 'Ink' }, ['#eef0ea', '#f9faf6', '#14213a', '#2740b0'], ['#10182a', '#1a2439', '#e9edf2', '#8ea6ff']),
|
|
122
|
+
...palette('papel', 'olive', { es: 'Oliva', en: 'Olive' }, ['#eeecdd', '#f8f7ee', '#23261a', '#56672a'], ['#181a12', '#23261a', '#ecebd9', '#b5c46a']),
|
|
123
|
+
...palette('papel', 'wine', { es: 'Vino', en: 'Wine' }, ['#f3ecec', '#fbf7f6', '#2a1216', '#8a1c32'], ['#1c0f12', '#2a181c', '#f5e7e8', '#f0909f']),
|
|
124
|
+
...palette('bloque', 'lemon', { es: 'Limón', en: 'Lemon' }, ['#ffe34d', '#fffdf0', '#111111', '#d81b63'], ['#141414', '#232323', '#f6f5ee', '#d9ff3f']),
|
|
125
|
+
...palette('bloque', 'mint', { es: 'Menta', en: 'Mint' }, ['#b4f0cf', '#f6fff9', '#0d1f17', '#5b2be0'], ['#0d1f17', '#173026', '#effbf4', '#7dffb8']),
|
|
126
|
+
...palette('bloque', 'salmon', { es: 'Salmón', en: 'Salmon' }, ['#ffb39b', '#fff6f2', '#1c0f0b', '#1c3fe0'], ['#1c0f0b', '#2e1b15', '#fff1ea', '#ff9470']),
|
|
127
|
+
...palette('caramelo', 'grape', { es: 'Uva', en: 'Grape' }, ['#f5efff', '#ffffff', '#2a1a4a', '#7235e0'], ['#1a1230', '#271c44', '#f1eaff', '#b999ff']),
|
|
128
|
+
...palette('caramelo', 'peach', { es: 'Durazno', en: 'Peach' }, ['#fff0e6', '#ffffff', '#43210f', '#c2410c'], ['#241208', '#351d10', '#ffeadc', '#ff9a66']),
|
|
129
|
+
...palette('caramelo', 'lagoon', { es: 'Laguna', en: 'Lagoon' }, ['#e6f7f4', '#ffffff', '#0e3638', '#0b7f76'], ['#0a2526', '#123537', '#dcf7f3', '#4fd6c8']),
|
|
130
|
+
...palette('tetsu', 'brasa', { es: 'Brasa', en: 'Ember' }, ['#ffffff', '#f4f4f2', '#0b0b0c', '#e2470f'], ['#070708', '#0e0f11', '#f2f2ee', '#ff5a1f']),
|
|
131
|
+
...palette('tetsu', 'acero', { es: 'Acero', en: 'Steel' }, ['#ffffff', '#f4f4f2', '#0b0b0c', '#5e6167'], ['#070708', '#0e0f11', '#f2f2ee', '#9aa3ae']),
|
|
132
|
+
...palette('vidrio', 'cobalto', { es: 'Cobalto', en: 'Cobalt' }, ['#f3f4f1', '#ffffff', '#16191d', '#1747ff'], ['#0e1013', '#15181c', '#eceeef', '#6e8bff']),
|
|
133
|
+
...palette('vidrio', 'grafito', { es: 'Grafito', en: 'Graphite' }, ['#f3f4f1', '#ffffff', '#16191d', '#16191d'], ['#0e1013', '#15181c', '#eceeef', '#eceeef']),
|
|
134
|
+
];
|
|
135
|
+
export function stylePalettes(style) {
|
|
136
|
+
return COLOR_THEME_PRESETS.filter((preset) => preset.style === style);
|
|
137
|
+
}
|
|
138
|
+
// A saved palette wins over the style. A palette that no longer exists, or that
|
|
139
|
+
// belongs to another style, falls back to the style's default with the saved mode.
|
|
140
|
+
export function resolveColorTheme(style, savedThemeId, savedMode) {
|
|
141
|
+
const palettes = stylePalettes(style);
|
|
142
|
+
const saved = palettes.find((preset) => preset.id === savedThemeId);
|
|
143
|
+
if (saved)
|
|
144
|
+
return saved;
|
|
145
|
+
const { defaultFamily, defaultMode } = VISUAL_STYLES[style];
|
|
146
|
+
const mode = savedMode === 'light' || savedMode === 'dark' ? savedMode : defaultMode;
|
|
147
|
+
return palettes.find((preset) => preset.id === `${defaultFamily}-${mode}`);
|
|
148
|
+
}
|
|
149
|
+
// An exported theme always carries the current accent. When it is the
|
|
150
|
+
// palette's own, the user did not pick it and it must follow the palette.
|
|
151
|
+
export function isManualAccent(style, themeId, mode, accent) {
|
|
152
|
+
return resolveColorTheme(style, themeId, mode).accent !== accent.toLowerCase();
|
|
153
|
+
}
|
|
154
|
+
function luminance(hex) {
|
|
155
|
+
const channel = (start) => {
|
|
156
|
+
const value = parseInt(hex.slice(start, start + 2), 16) / 255;
|
|
157
|
+
return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
158
|
+
};
|
|
159
|
+
return 0.2126 * channel(1) + 0.7152 * channel(3) + 0.0722 * channel(5);
|
|
160
|
+
}
|
|
161
|
+
export function contrastRatio(a, b) {
|
|
162
|
+
const [x, y] = [luminance(a), luminance(b)];
|
|
163
|
+
return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);
|
|
164
|
+
}
|
|
165
|
+
// Readable text color on top of a color.
|
|
166
|
+
export function readableOn(hex) {
|
|
167
|
+
return contrastRatio('#ffffff', hex) >= contrastRatio('#111111', hex) ? '#ffffff' : '#111111';
|
|
168
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tetsustudio/tokens",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tetsu design tokens: the CSS variable contract, visual styles, palettes and a theme validator.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": { "type": "git", "url": "git+https://github.com/tetsustudio/library.git", "directory": "packages/tokens" },
|
|
8
|
+
"homepage": "https://library.tetsustudio.com",
|
|
9
|
+
"sideEffects": ["*.css"],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
|
|
12
|
+
"./css": "./dist/css/index.css",
|
|
13
|
+
"./base.css": "./dist/css/base.css",
|
|
14
|
+
"./styles.css": "./dist/css/styles.css",
|
|
15
|
+
"./palettes.css": "./dist/css/palettes.css",
|
|
16
|
+
"./tailwind.css": "./dist/css/tailwind.css",
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"bin": { "tetsu-validate-theme": "./bin/validate-theme.mjs" },
|
|
21
|
+
"files": ["dist", "bin", "README.md"],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && node scripts/build-css.mjs",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"test": "npm run build && node --test test/*.test.mjs"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.9.3"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": { "access": "public", "provenance": true }
|
|
31
|
+
}
|