@passui/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 +7 -2
- package/package.json +57 -5
- package/src/accent.ts +166 -0
- package/src/color.ts +113 -0
- package/src/index.ts +6 -0
- package/src/layout.ts +34 -0
- package/src/motion.ts +31 -0
- package/src/theme-css.ts +127 -0
- package/src/typography.ts +99 -0
- package/styles/base.css +78 -0
- package/styles/styles.css +59 -0
- package/styles/typeset.css +726 -0
- package/styles/utilities.css +263 -0
- package/theme.css +316 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pherus
|
|
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,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @passui/tokens
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared Passui colors, typography, layout, motion and generated theme CSS.
|
|
4
|
+
No React or SolidJS runtime is required. Import tokens from `@passui/tokens`
|
|
5
|
+
and styles from `@passui/tokens/theme.css`. Framework packages compose the
|
|
6
|
+
shared styles and register their own Tailwind source files.
|
|
7
|
+
|
|
8
|
+
Run `bun run generate` after changing token values.
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@passui/tokens",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Framework independent Passui design tokens and shared styles.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/phe-rus/passui.git",
|
|
10
|
+
"directory": "packages/tokens"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://passui.pherus.org",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public",
|
|
15
|
+
"registry": "https://registry.npmjs.org"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"src",
|
|
19
|
+
"styles",
|
|
20
|
+
"theme.css",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./src/index.ts",
|
|
26
|
+
"./theme.css": "./theme.css",
|
|
27
|
+
"./base.css": "./styles/base.css",
|
|
28
|
+
"./utilities.css": "./styles/utilities.css",
|
|
29
|
+
"./typeset.css": "./styles/typeset.css",
|
|
30
|
+
"./styles.css": "./styles/styles.css",
|
|
31
|
+
"./accent": "./src/accent.ts",
|
|
32
|
+
"./color": "./src/color.ts",
|
|
33
|
+
"./layout": "./src/layout.ts",
|
|
34
|
+
"./motion": "./src/motion.ts",
|
|
35
|
+
"./theme-css": "./src/theme-css.ts",
|
|
36
|
+
"./typography": "./src/typography.ts"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"generate": "bun scripts/generate-css.ts",
|
|
40
|
+
"build": "bun run generate",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"publish:check": "bun pm pack --dry-run"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"tw-animate-css": "^1.4.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"tailwindcss": "^4.3.3"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"typescript": "^7.0.2",
|
|
53
|
+
"@types/node": "^26.6.3",
|
|
54
|
+
"tailwindcss": "^4.3.3",
|
|
55
|
+
"vite": "8.3.5",
|
|
56
|
+
"vitest": "5.0.5"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/accent.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accent colors people can choose. Blush, the soft pink of the iPhone 15,
|
|
3
|
+
* is the default and Passui's own color; the others are calm, slightly
|
|
4
|
+
* muted tones that sit well on warm paper.
|
|
5
|
+
* Each sets the four accent roles for light and dark schemes.
|
|
6
|
+
*/
|
|
7
|
+
export interface AccentColors {
|
|
8
|
+
accent: string
|
|
9
|
+
onAccent: string
|
|
10
|
+
accentText: string
|
|
11
|
+
accentSoft: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type AccentId =
|
|
15
|
+
| "blush"
|
|
16
|
+
| "honey"
|
|
17
|
+
| "sage"
|
|
18
|
+
| "ocean"
|
|
19
|
+
| "lavender"
|
|
20
|
+
| "rose"
|
|
21
|
+
| "graphite"
|
|
22
|
+
|
|
23
|
+
export interface Accent {
|
|
24
|
+
id: AccentId
|
|
25
|
+
name: string
|
|
26
|
+
/**
|
|
27
|
+
* The color that stands for this accent in pickers and on the brand. Usually
|
|
28
|
+
* the fill itself; Blush keeps its soft pink here while controls use a
|
|
29
|
+
* deeper shade that can be seen against white.
|
|
30
|
+
*/
|
|
31
|
+
swatch: string
|
|
32
|
+
light: AccentColors
|
|
33
|
+
dark: AccentColors
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const accents: Record<AccentId, Accent> = {
|
|
37
|
+
blush: {
|
|
38
|
+
id: "blush",
|
|
39
|
+
name: "Blush",
|
|
40
|
+
swatch: "#f2d4d7",
|
|
41
|
+
// The soft pink is too pale for a switched-on toggle (1.4:1); rose pink
|
|
42
|
+
// reaches 3:1 on every light ground, the warm sidebar included.
|
|
43
|
+
light: {
|
|
44
|
+
accent: "#d16988",
|
|
45
|
+
onAccent: "#1c1c1e",
|
|
46
|
+
accentText: "#9e3b4f",
|
|
47
|
+
accentSoft: "#fbeff0",
|
|
48
|
+
},
|
|
49
|
+
dark: {
|
|
50
|
+
accent: "#e8b4bb",
|
|
51
|
+
onAccent: "#22131a",
|
|
52
|
+
accentText: "#efb3bc",
|
|
53
|
+
accentSoft: "#36242a",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
honey: {
|
|
57
|
+
id: "honey",
|
|
58
|
+
name: "Honey",
|
|
59
|
+
swatch: "#efbd52",
|
|
60
|
+
light: {
|
|
61
|
+
accent: "#efbd52",
|
|
62
|
+
onAccent: "#1c1c1e",
|
|
63
|
+
accentText: "#835608",
|
|
64
|
+
accentSoft: "#f8eed6",
|
|
65
|
+
},
|
|
66
|
+
dark: {
|
|
67
|
+
accent: "#e2b04f",
|
|
68
|
+
onAccent: "#1c1c1e",
|
|
69
|
+
accentText: "#e8bf6c",
|
|
70
|
+
accentSoft: "#342b1a",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
sage: {
|
|
74
|
+
id: "sage",
|
|
75
|
+
name: "Sage",
|
|
76
|
+
swatch: "#a9c29b",
|
|
77
|
+
light: {
|
|
78
|
+
accent: "#a9c29b",
|
|
79
|
+
onAccent: "#1c1c1e",
|
|
80
|
+
accentText: "#46653b",
|
|
81
|
+
accentSoft: "#e6ede0",
|
|
82
|
+
},
|
|
83
|
+
dark: {
|
|
84
|
+
accent: "#93b285",
|
|
85
|
+
onAccent: "#141812",
|
|
86
|
+
accentText: "#a9c79c",
|
|
87
|
+
accentSoft: "#232b20",
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
ocean: {
|
|
91
|
+
id: "ocean",
|
|
92
|
+
name: "Ocean",
|
|
93
|
+
swatch: "#9cc3e6",
|
|
94
|
+
light: {
|
|
95
|
+
accent: "#9cc3e6",
|
|
96
|
+
onAccent: "#1c1c1e",
|
|
97
|
+
accentText: "#2c6193",
|
|
98
|
+
accentSoft: "#e2ecf6",
|
|
99
|
+
},
|
|
100
|
+
dark: {
|
|
101
|
+
accent: "#79acdb",
|
|
102
|
+
onAccent: "#0f1720",
|
|
103
|
+
accentText: "#93bde4",
|
|
104
|
+
accentSoft: "#1d2834",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
lavender: {
|
|
108
|
+
id: "lavender",
|
|
109
|
+
name: "Lavender",
|
|
110
|
+
swatch: "#c3b8ea",
|
|
111
|
+
light: {
|
|
112
|
+
accent: "#c3b8ea",
|
|
113
|
+
onAccent: "#1c1c1e",
|
|
114
|
+
accentText: "#5d4f9e",
|
|
115
|
+
accentSoft: "#ece8f7",
|
|
116
|
+
},
|
|
117
|
+
dark: {
|
|
118
|
+
accent: "#a99cdf",
|
|
119
|
+
onAccent: "#16131f",
|
|
120
|
+
accentText: "#bdb3ea",
|
|
121
|
+
accentSoft: "#282435",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
rose: {
|
|
125
|
+
id: "rose",
|
|
126
|
+
name: "Rose",
|
|
127
|
+
swatch: "#efb3bb",
|
|
128
|
+
light: {
|
|
129
|
+
accent: "#efb3bb",
|
|
130
|
+
onAccent: "#1c1c1e",
|
|
131
|
+
accentText: "#a23f51",
|
|
132
|
+
accentSoft: "#f8e6e9",
|
|
133
|
+
},
|
|
134
|
+
dark: {
|
|
135
|
+
accent: "#e5949f",
|
|
136
|
+
onAccent: "#22131a",
|
|
137
|
+
accentText: "#efadb6",
|
|
138
|
+
accentSoft: "#36232a",
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
graphite: {
|
|
142
|
+
id: "graphite",
|
|
143
|
+
name: "Graphite",
|
|
144
|
+
swatch: "#3a3936",
|
|
145
|
+
light: {
|
|
146
|
+
accent: "#3a3936",
|
|
147
|
+
onAccent: "#ffffff",
|
|
148
|
+
accentText: "#4a4844",
|
|
149
|
+
accentSoft: "#ebe8e2",
|
|
150
|
+
},
|
|
151
|
+
dark: {
|
|
152
|
+
accent: "#d6d2ca",
|
|
153
|
+
onAccent: "#151413",
|
|
154
|
+
accentText: "#cfcbc3",
|
|
155
|
+
accentSoft: "#2e2c29",
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export const defaultAccent: AccentId = "blush"
|
|
161
|
+
|
|
162
|
+
export function isAccentId(
|
|
163
|
+
value: unknown
|
|
164
|
+
): value is AccentId {
|
|
165
|
+
return typeof value === "string" && value in accents
|
|
166
|
+
}
|
package/src/color.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { accents, defaultAccent } from "./accent"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Semantic color roles. Warm "paper" neutrals with a blush accent: the feel
|
|
5
|
+
* of a well-made notebook, tuned to sit naturally beside Apple's system UI.
|
|
6
|
+
*/
|
|
7
|
+
export interface ColorScheme {
|
|
8
|
+
/** Window background. */
|
|
9
|
+
background: string
|
|
10
|
+
/** Sidebar and toolbars. */
|
|
11
|
+
sidebar: string
|
|
12
|
+
/** Lists and secondary panes. */
|
|
13
|
+
surface: string
|
|
14
|
+
/** Writing and reading surface. */
|
|
15
|
+
paper: string
|
|
16
|
+
/** Cards, popovers and sheets. */
|
|
17
|
+
elevated: string
|
|
18
|
+
/** Inputs, chips and pressed states. */
|
|
19
|
+
fill: string
|
|
20
|
+
separator: string
|
|
21
|
+
label: string
|
|
22
|
+
labelSecondary: string
|
|
23
|
+
labelTertiary: string
|
|
24
|
+
/** Body text on paper. */
|
|
25
|
+
ink: string
|
|
26
|
+
/** Selection, active items and primary fills. */
|
|
27
|
+
accent: string
|
|
28
|
+
/** Text and icons placed on `accent`. */
|
|
29
|
+
onAccent: string
|
|
30
|
+
/** Accent-colored text and icons on neutral backgrounds (AA contrast). */
|
|
31
|
+
accentText: string
|
|
32
|
+
/** Subtle accent tint for selected rows. */
|
|
33
|
+
accentSoft: string
|
|
34
|
+
highlight: string
|
|
35
|
+
heart: string
|
|
36
|
+
/** Floating toolbars and primary buttons. */
|
|
37
|
+
inverse: string
|
|
38
|
+
onInverse: string
|
|
39
|
+
success: string
|
|
40
|
+
warning: string
|
|
41
|
+
danger: string
|
|
42
|
+
/** Glass materials: the lit top edge and the hairline rim. */
|
|
43
|
+
glassHighlight: string
|
|
44
|
+
glassRim: string
|
|
45
|
+
/** Clear glass: its faint tint, the specular edge light and the sheen across it. */
|
|
46
|
+
glassTint: string
|
|
47
|
+
glassSpecular: string
|
|
48
|
+
glassSheen: string
|
|
49
|
+
/** Shadows under floating glass, and the deeper one under menus. */
|
|
50
|
+
shadowFloating: string
|
|
51
|
+
shadowMenu: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const light: ColorScheme = {
|
|
55
|
+
background: "#ffffff",
|
|
56
|
+
sidebar: "#f3efe6",
|
|
57
|
+
surface: "#fdfcf9",
|
|
58
|
+
paper: "#fffdf8",
|
|
59
|
+
elevated: "#ffffff",
|
|
60
|
+
fill: "#efebe2",
|
|
61
|
+
separator: "#e3dccb",
|
|
62
|
+
label: "#1c1c1e",
|
|
63
|
+
labelSecondary: "#6b6458",
|
|
64
|
+
labelTertiary: "#8b8478",
|
|
65
|
+
ink: "#24221f",
|
|
66
|
+
...accents[defaultAccent].light,
|
|
67
|
+
highlight: "#ffe58a",
|
|
68
|
+
heart: "#ff375f",
|
|
69
|
+
inverse: "#1c1c1e",
|
|
70
|
+
onInverse: "#ffffff",
|
|
71
|
+
success: "#248a3d",
|
|
72
|
+
warning: "#c93400",
|
|
73
|
+
danger: "#d70015",
|
|
74
|
+
glassHighlight: "rgb(255 255 255 / 0.55)",
|
|
75
|
+
glassRim: "rgb(118 108 92 / 0.22)",
|
|
76
|
+
// Clear, but in the sidebar's own warm paper, so it belongs to the app.
|
|
77
|
+
glassTint: "rgb(243 239 230 / 0.42)",
|
|
78
|
+
glassSpecular: "rgb(255 255 255 / 0.85)",
|
|
79
|
+
glassSheen: "rgb(255 255 255 / 0.32)",
|
|
80
|
+
shadowFloating: "rgb(40 30 0 / 0.18)",
|
|
81
|
+
shadowMenu: "rgb(40 30 0 / 0.24)",
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const dark: ColorScheme = {
|
|
85
|
+
background: "#121110",
|
|
86
|
+
sidebar: "#1a1917",
|
|
87
|
+
surface: "#161514",
|
|
88
|
+
paper: "#1a1917",
|
|
89
|
+
elevated: "#24221f",
|
|
90
|
+
fill: "#2c2a26",
|
|
91
|
+
separator: "#3a3732",
|
|
92
|
+
label: "#f5f2ec",
|
|
93
|
+
labelSecondary: "#b5aea2",
|
|
94
|
+
labelTertiary: "#8f887b",
|
|
95
|
+
ink: "#ece6da",
|
|
96
|
+
...accents[defaultAccent].dark,
|
|
97
|
+
highlight: "#7a5c00",
|
|
98
|
+
heart: "#ff375f",
|
|
99
|
+
inverse: "#f5f2ec",
|
|
100
|
+
onInverse: "#1c1c1e",
|
|
101
|
+
success: "#30d158",
|
|
102
|
+
warning: "#ff9f0a",
|
|
103
|
+
danger: "#ff453a",
|
|
104
|
+
glassHighlight: "rgb(255 255 255 / 0.1)",
|
|
105
|
+
glassRim: "rgb(255 250 240 / 0.06)",
|
|
106
|
+
glassTint: "rgb(26 25 23 / 0.5)",
|
|
107
|
+
glassSpecular: "rgb(255 250 240 / 0.12)",
|
|
108
|
+
glassSheen: "rgb(255 255 255 / 0.1)",
|
|
109
|
+
shadowFloating: "rgb(0 0 0 / 0.5)",
|
|
110
|
+
shadowMenu: "rgb(0 0 0 / 0.55)",
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const colors = { light, dark } as const
|
package/src/index.ts
ADDED
package/src/layout.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** 4-point spacing grid. */
|
|
2
|
+
export const space = {
|
|
3
|
+
0: 0,
|
|
4
|
+
1: 4,
|
|
5
|
+
2: 8,
|
|
6
|
+
3: 12,
|
|
7
|
+
4: 16,
|
|
8
|
+
5: 20,
|
|
9
|
+
6: 24,
|
|
10
|
+
8: 32,
|
|
11
|
+
10: 40,
|
|
12
|
+
12: 48,
|
|
13
|
+
16: 64,
|
|
14
|
+
} as const
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Corner radii, in 2 px steps while small (the eye notices every pixel
|
|
18
|
+
* there) and 4 px steps beyond. Nested shapes stay concentric: an inner
|
|
19
|
+
* radius is the outer radius minus the padding between them. Pair with
|
|
20
|
+
* `borderCurve: "continuous"` on iOS.
|
|
21
|
+
*/
|
|
22
|
+
export const radius = {
|
|
23
|
+
xs: 4,
|
|
24
|
+
sm: 6,
|
|
25
|
+
md: 8,
|
|
26
|
+
lg: 10,
|
|
27
|
+
xl: 12,
|
|
28
|
+
"2xl": 14,
|
|
29
|
+
"3xl": 16,
|
|
30
|
+
"4xl": 20,
|
|
31
|
+
"5xl": 24,
|
|
32
|
+
sheet: 28,
|
|
33
|
+
full: 9999,
|
|
34
|
+
} as const
|
package/src/motion.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spring presets shared by motion/react and CSS so interactions feel the
|
|
3
|
+
* same on every platform. Values follow SwiftUI's defaults.
|
|
4
|
+
*/
|
|
5
|
+
export interface Spring {
|
|
6
|
+
damping: number
|
|
7
|
+
stiffness: number
|
|
8
|
+
mass: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const springs = {
|
|
12
|
+
/** Default UI transitions. */
|
|
13
|
+
smooth: { damping: 26, stiffness: 240, mass: 1 },
|
|
14
|
+
/** Buttons, toggles and small feedback. */
|
|
15
|
+
snappy: { damping: 22, stiffness: 380, mass: 1 },
|
|
16
|
+
/** Sheets, cards and playful moments. */
|
|
17
|
+
bouncy: { damping: 14, stiffness: 220, mass: 1 },
|
|
18
|
+
} as const satisfies Record<string, Spring>
|
|
19
|
+
|
|
20
|
+
export const duration = {
|
|
21
|
+
instant: 100,
|
|
22
|
+
fast: 200,
|
|
23
|
+
normal: 300,
|
|
24
|
+
slow: 450,
|
|
25
|
+
} as const
|
|
26
|
+
|
|
27
|
+
/** CSS easing approximating the `smooth` spring for non-spring contexts. */
|
|
28
|
+
export const easing = {
|
|
29
|
+
standard: "cubic-bezier(0.2, 0.8, 0.2, 1)",
|
|
30
|
+
emphasized: "cubic-bezier(0.3, 1.3, 0.4, 1)",
|
|
31
|
+
} as const
|
package/src/theme-css.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AccentColors,
|
|
3
|
+
accents,
|
|
4
|
+
defaultAccent,
|
|
5
|
+
} from "./accent"
|
|
6
|
+
import { type ColorScheme, dark, light } from "./color"
|
|
7
|
+
import { radius, space } from "./layout"
|
|
8
|
+
import { duration, easing } from "./motion"
|
|
9
|
+
import {
|
|
10
|
+
fontFamily,
|
|
11
|
+
minimumTextSize,
|
|
12
|
+
textStyles,
|
|
13
|
+
} from "./typography"
|
|
14
|
+
|
|
15
|
+
const kebab = (key: string) =>
|
|
16
|
+
key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Text styles scale together with `--type-scale` (set from the reader's text
|
|
20
|
+
* size), never below the smallest style. Line heights are separate
|
|
21
|
+
* `leading-*` utilities, so adopting a size never moves existing leading.
|
|
22
|
+
*/
|
|
23
|
+
function textStyleVars(): string[] {
|
|
24
|
+
return Object.entries(textStyles).flatMap(
|
|
25
|
+
([name, style]) => {
|
|
26
|
+
const scaled = (px: number) =>
|
|
27
|
+
`max(${Math.min(px, minimumTextSize)}px, calc(${px}px * var(--type-scale, 1)))`
|
|
28
|
+
return [
|
|
29
|
+
` --text-${kebab(name)}: ${scaled(style.size)};`,
|
|
30
|
+
` --leading-${kebab(name)}: ${scaled(style.lineHeight)};`,
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function colorVars(
|
|
37
|
+
scheme: ColorScheme | AccentColors,
|
|
38
|
+
backgroundShare = 0
|
|
39
|
+
): string {
|
|
40
|
+
return Object.entries(scheme)
|
|
41
|
+
.map(([key, value]) => {
|
|
42
|
+
// The window ground keeps a whisper of the accent's own tint,
|
|
43
|
+
// so each choice colors the whole app the way iOS's does. The
|
|
44
|
+
// reference resolves per element, so `data-accent` retints it.
|
|
45
|
+
if (key === "background" && backgroundShare) {
|
|
46
|
+
return ` --color-background: color-mix(in srgb, var(--color-accent-soft) ${backgroundShare}%, ${value});`
|
|
47
|
+
}
|
|
48
|
+
return ` --color-${kebab(key)}: ${value};`
|
|
49
|
+
})
|
|
50
|
+
.join("\n")
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Renders the tokens as a Tailwind v4 compatible stylesheet. Light values
|
|
55
|
+
* live in `@theme`; dark values apply with the system's dark appearance, or
|
|
56
|
+
* through `data-theme`. Like SwiftUI's `colorScheme` environment,
|
|
57
|
+
* `data-theme="dark"` or `"light"` works on any element, not only the root,
|
|
58
|
+
* so one part of a screen can keep its own appearance (an always-dark
|
|
59
|
+
* recorder, an always-white invoice). Accents other than the default apply
|
|
60
|
+
* through `data-accent` on the root element.
|
|
61
|
+
*/
|
|
62
|
+
export function renderThemeCss(): string {
|
|
63
|
+
const others = Object.values(accents).filter(
|
|
64
|
+
(accent) => accent.id !== defaultAccent
|
|
65
|
+
)
|
|
66
|
+
const lines = [
|
|
67
|
+
"/* Generated by @passui/tokens. Do not edit by hand. */",
|
|
68
|
+
"@theme static {",
|
|
69
|
+
colorVars(light, 6),
|
|
70
|
+
...Object.entries(fontFamily).map(
|
|
71
|
+
([k, v]) => ` --font-${k}: ${v};`
|
|
72
|
+
),
|
|
73
|
+
...textStyleVars(),
|
|
74
|
+
...Object.entries(radius).map(
|
|
75
|
+
([k, v]) => ` --radius-${k}: ${v}px;`
|
|
76
|
+
),
|
|
77
|
+
...Object.entries(space).map(
|
|
78
|
+
([k, v]) => ` --space-${k}: ${v}px;`
|
|
79
|
+
),
|
|
80
|
+
...Object.entries(duration).map(
|
|
81
|
+
([k, v]) => ` --duration-${k}: ${v}ms;`
|
|
82
|
+
),
|
|
83
|
+
...Object.entries(easing).map(
|
|
84
|
+
([k, v]) => ` --ease-${k}: ${v};`
|
|
85
|
+
),
|
|
86
|
+
"}",
|
|
87
|
+
"",
|
|
88
|
+
// Native controls, scrollbars and form fills follow the same appearance.
|
|
89
|
+
":root { color-scheme: light dark; }",
|
|
90
|
+
'[data-theme="light"] { color-scheme: light; }',
|
|
91
|
+
'[data-theme="dark"] { color-scheme: dark; }',
|
|
92
|
+
"",
|
|
93
|
+
"@media (prefers-color-scheme: dark) {",
|
|
94
|
+
' :root:not([data-theme="light"]) {',
|
|
95
|
+
colorVars(dark, 4).replace(/^/gm, " "),
|
|
96
|
+
" }",
|
|
97
|
+
"}",
|
|
98
|
+
"",
|
|
99
|
+
'[data-theme="dark"] {',
|
|
100
|
+
colorVars(dark, 4),
|
|
101
|
+
"}",
|
|
102
|
+
"",
|
|
103
|
+
// A light part inside a dark screen needs the light values back.
|
|
104
|
+
':root [data-theme="light"] {',
|
|
105
|
+
colorVars(light, 6),
|
|
106
|
+
"}",
|
|
107
|
+
"",
|
|
108
|
+
...others.flatMap((accent) => {
|
|
109
|
+
const root = `:root[data-accent="${accent.id}"]`
|
|
110
|
+
return [
|
|
111
|
+
`${root}, ${root} [data-theme="light"] {`,
|
|
112
|
+
colorVars(accent.light),
|
|
113
|
+
"}",
|
|
114
|
+
"@media (prefers-color-scheme: dark) {",
|
|
115
|
+
` ${root}:not([data-theme="light"]) {`,
|
|
116
|
+
colorVars(accent.dark).replace(/^/gm, " "),
|
|
117
|
+
" }",
|
|
118
|
+
"}",
|
|
119
|
+
`${root}[data-theme="dark"], ${root} [data-theme="dark"] {`,
|
|
120
|
+
colorVars(accent.dark),
|
|
121
|
+
"}",
|
|
122
|
+
"",
|
|
123
|
+
]
|
|
124
|
+
}),
|
|
125
|
+
]
|
|
126
|
+
return lines.join("\n")
|
|
127
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export const fontFamily = {
|
|
2
|
+
sans: '-apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif',
|
|
3
|
+
display:
|
|
4
|
+
'-apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif',
|
|
5
|
+
/** Reading and writing. Newsreader is bundled; New York is used where present. */
|
|
6
|
+
serif: '"Newsreader", "New York", "Iowan Old Style", Georgia, serif',
|
|
7
|
+
/** Handwriting, for notes and books written in a script hand. */
|
|
8
|
+
script: '"Caveat Variable", "Caveat", "Bradley Hand", "Segoe Print", cursive',
|
|
9
|
+
/** Neat printed handwriting. */
|
|
10
|
+
print: '"Patrick Hand", "Chalkboard SE", "Segoe Print", cursive',
|
|
11
|
+
mono: 'ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace',
|
|
12
|
+
} as const
|
|
13
|
+
|
|
14
|
+
export interface TextStyle {
|
|
15
|
+
size: number
|
|
16
|
+
lineHeight: number
|
|
17
|
+
weight: 400 | 600
|
|
18
|
+
tracking: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The text styles of Apple's Dynamic Type at its default ("Large") size, in
|
|
23
|
+
* points, which are CSS pixels. Names follow SwiftUI's `Font.TextStyle`.
|
|
24
|
+
* In CSS each is a `text-*` utility (`text-footnote`) with a matching
|
|
25
|
+
* `leading-*`, and all of them grow and shrink with `--type-scale`.
|
|
26
|
+
*/
|
|
27
|
+
export const textStyles = {
|
|
28
|
+
largeTitle: {
|
|
29
|
+
size: 34,
|
|
30
|
+
lineHeight: 41,
|
|
31
|
+
weight: 400,
|
|
32
|
+
tracking: 0.4,
|
|
33
|
+
},
|
|
34
|
+
title: {
|
|
35
|
+
size: 28,
|
|
36
|
+
lineHeight: 34,
|
|
37
|
+
weight: 400,
|
|
38
|
+
tracking: 0.38,
|
|
39
|
+
},
|
|
40
|
+
title2: {
|
|
41
|
+
size: 22,
|
|
42
|
+
lineHeight: 28,
|
|
43
|
+
weight: 400,
|
|
44
|
+
tracking: -0.26,
|
|
45
|
+
},
|
|
46
|
+
title3: {
|
|
47
|
+
size: 20,
|
|
48
|
+
lineHeight: 25,
|
|
49
|
+
weight: 400,
|
|
50
|
+
tracking: -0.45,
|
|
51
|
+
},
|
|
52
|
+
headline: {
|
|
53
|
+
size: 17,
|
|
54
|
+
lineHeight: 22,
|
|
55
|
+
weight: 600,
|
|
56
|
+
tracking: -0.43,
|
|
57
|
+
},
|
|
58
|
+
body: {
|
|
59
|
+
size: 17,
|
|
60
|
+
lineHeight: 22,
|
|
61
|
+
weight: 400,
|
|
62
|
+
tracking: -0.43,
|
|
63
|
+
},
|
|
64
|
+
callout: {
|
|
65
|
+
size: 16,
|
|
66
|
+
lineHeight: 21,
|
|
67
|
+
weight: 400,
|
|
68
|
+
tracking: -0.31,
|
|
69
|
+
},
|
|
70
|
+
subheadline: {
|
|
71
|
+
size: 15,
|
|
72
|
+
lineHeight: 20,
|
|
73
|
+
weight: 400,
|
|
74
|
+
tracking: -0.23,
|
|
75
|
+
},
|
|
76
|
+
footnote: {
|
|
77
|
+
size: 13,
|
|
78
|
+
lineHeight: 18,
|
|
79
|
+
weight: 400,
|
|
80
|
+
tracking: -0.08,
|
|
81
|
+
},
|
|
82
|
+
caption: {
|
|
83
|
+
size: 12,
|
|
84
|
+
lineHeight: 16,
|
|
85
|
+
weight: 400,
|
|
86
|
+
tracking: 0,
|
|
87
|
+
},
|
|
88
|
+
caption2: {
|
|
89
|
+
size: 11,
|
|
90
|
+
lineHeight: 13,
|
|
91
|
+
weight: 400,
|
|
92
|
+
tracking: 0.06,
|
|
93
|
+
},
|
|
94
|
+
} as const satisfies Record<string, TextStyle>
|
|
95
|
+
|
|
96
|
+
export type TextStyleName = keyof typeof textStyles
|
|
97
|
+
|
|
98
|
+
/** Like Dynamic Type, scaled text never drops below the smallest style. */
|
|
99
|
+
export const minimumTextSize = textStyles.caption2.size
|