foldkit-mixins 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +472 -123
- package/dist/core-B86QnDhB.d.mts +40 -0
- package/dist/core-B86QnDhB.d.mts.map +1 -0
- package/dist/core-izIY2GSX.mjs +53 -0
- package/dist/core-izIY2GSX.mjs.map +1 -0
- package/dist/defaults.d.mts +27 -0
- package/dist/defaults.d.mts.map +1 -0
- package/dist/defaults.mjs +71 -0
- package/dist/defaults.mjs.map +1 -0
- package/dist/diagnostics-YJ7991-A.mjs +15 -0
- package/dist/diagnostics-YJ7991-A.mjs.map +1 -0
- package/dist/index.d.mts +264 -86
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +533 -247
- package/dist/index.mjs.map +1 -1
- package/dist/layers-CJS5d1i7.mjs +197 -0
- package/dist/layers-CJS5d1i7.mjs.map +1 -0
- package/dist/layers.d.mts +47 -0
- package/dist/layers.d.mts.map +1 -0
- package/dist/layers.mjs +2 -0
- package/dist/layout.d.mts +114 -0
- package/dist/layout.d.mts.map +1 -0
- package/dist/layout.mjs +154 -0
- package/dist/layout.mjs.map +1 -0
- package/dist/prose.d.mts +24 -0
- package/dist/prose.d.mts.map +1 -0
- package/dist/prose.mjs +57 -0
- package/dist/prose.mjs.map +1 -0
- package/dist/styleValue--iQMTcPn.mjs +242 -0
- package/dist/styleValue--iQMTcPn.mjs.map +1 -0
- package/dist/styleValue-C9vAKt7A.d.mts +77 -0
- package/dist/styleValue-C9vAKt7A.d.mts.map +1 -0
- package/dist/theme.d.mts +412 -0
- package/dist/theme.d.mts.map +1 -0
- package/dist/theme.mjs +278 -0
- package/dist/theme.mjs.map +1 -0
- package/package.json +32 -7
package/dist/theme.d.mts
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { a as StyleValue } from "./styleValue-C9vAKt7A.mjs";
|
|
2
|
+
import { a as compose, c as lightDark, i as VAR_PREFIX, l as ref, n as Theme$1, o as core_d_exports, r as ThemeTokens, s as define, t as Refs, u as variables } from "./core-B86QnDhB.mjs";
|
|
3
|
+
//#region src/theme/root.d.ts
|
|
4
|
+
interface RootOptions {
|
|
5
|
+
/** Tokens present in this theme are left out, so a scale shipped in another layer goes out once. */
|
|
6
|
+
readonly omit?: ThemeTokens;
|
|
7
|
+
/** Default `'light dark'`, so `lightDark` tokens resolve. */
|
|
8
|
+
readonly colorScheme?: 'light dark' | 'light' | 'dark';
|
|
9
|
+
}
|
|
10
|
+
export declare const root: (theme: ThemeTokens, options?: RootOptions) => StyleValue;
|
|
11
|
+
/** Some of a theme's tokens, by the theme's own group and token names. */
|
|
12
|
+
type Overrides<T extends ThemeTokens> = { readonly [G in keyof T]?: { readonly [N in keyof T[G]]?: string; }; };
|
|
13
|
+
/**
|
|
14
|
+
* Token overrides under `selector`: a named theme the Model selects with a
|
|
15
|
+
* root attribute (`:root[data-theme="ocean"]`), a scheme the user chose
|
|
16
|
+
* (`:root[data-color-scheme="dark"]`), or a subtree (`.marketing`). Which
|
|
17
|
+
* one is active is the Model's fact; this only says what it means.
|
|
18
|
+
*
|
|
19
|
+
* `theme` is the theme being overridden and is read only for its type, so a
|
|
20
|
+
* group or token it lacks is a type error rather than a variable nothing reads.
|
|
21
|
+
*/
|
|
22
|
+
export declare const scoped: <T extends ThemeTokens>(_theme: T, selector: string, overrides: Overrides<T>) => StyleValue;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/theme/tokens.d.ts
|
|
25
|
+
export declare const tokens: Readonly<{
|
|
26
|
+
knob: {
|
|
27
|
+
density: string;
|
|
28
|
+
'radius-factor': string;
|
|
29
|
+
};
|
|
30
|
+
space: {
|
|
31
|
+
'3xs': string;
|
|
32
|
+
'2xs': string;
|
|
33
|
+
xs: string;
|
|
34
|
+
sm: string;
|
|
35
|
+
md: string;
|
|
36
|
+
lg: string;
|
|
37
|
+
xl: string;
|
|
38
|
+
'2xl': string;
|
|
39
|
+
'3xl': string;
|
|
40
|
+
};
|
|
41
|
+
radius: {
|
|
42
|
+
xs: string;
|
|
43
|
+
sm: string;
|
|
44
|
+
md: string;
|
|
45
|
+
lg: string;
|
|
46
|
+
xl: string;
|
|
47
|
+
full: string;
|
|
48
|
+
};
|
|
49
|
+
font: {
|
|
50
|
+
body: string;
|
|
51
|
+
heading: string;
|
|
52
|
+
mono: string;
|
|
53
|
+
};
|
|
54
|
+
size: {
|
|
55
|
+
xs: string;
|
|
56
|
+
sm: string;
|
|
57
|
+
md: string;
|
|
58
|
+
lg: string;
|
|
59
|
+
xl: string;
|
|
60
|
+
'2xl': string;
|
|
61
|
+
'3xl': string;
|
|
62
|
+
'4xl': string;
|
|
63
|
+
};
|
|
64
|
+
leading: {
|
|
65
|
+
tight: string;
|
|
66
|
+
snug: string;
|
|
67
|
+
normal: string;
|
|
68
|
+
relaxed: string;
|
|
69
|
+
};
|
|
70
|
+
weight: {
|
|
71
|
+
normal: string;
|
|
72
|
+
medium: string;
|
|
73
|
+
semibold: string;
|
|
74
|
+
bold: string;
|
|
75
|
+
};
|
|
76
|
+
motion: {
|
|
77
|
+
fast: string;
|
|
78
|
+
normal: string;
|
|
79
|
+
ease: string;
|
|
80
|
+
};
|
|
81
|
+
border: {
|
|
82
|
+
thin: string;
|
|
83
|
+
thick: string;
|
|
84
|
+
heavy: string;
|
|
85
|
+
};
|
|
86
|
+
breakpoint: {
|
|
87
|
+
sm: string;
|
|
88
|
+
md: string;
|
|
89
|
+
lg: string;
|
|
90
|
+
xl: string;
|
|
91
|
+
};
|
|
92
|
+
}>;
|
|
93
|
+
type Tokens = typeof tokens;
|
|
94
|
+
/**
|
|
95
|
+
* Each breakpoint query's `min-width` in pixels (rem at 16), so CSS and the
|
|
96
|
+
* Model agree on what `md` means. A query that is not a plain `min-width`
|
|
97
|
+
* is refused: it has no single threshold.
|
|
98
|
+
*/
|
|
99
|
+
export declare const breakpointWidths: (theme: {
|
|
100
|
+
readonly breakpoint: {
|
|
101
|
+
readonly [name: string]: string;
|
|
102
|
+
};
|
|
103
|
+
}) => Readonly<Record<string, number>>;
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/theme/oklch.d.ts
|
|
106
|
+
interface OklchKnobs {
|
|
107
|
+
/** The brand color: hue in degrees, chroma 0–0.4, lightness as a percentage. */
|
|
108
|
+
readonly accent: {
|
|
109
|
+
readonly h: number;
|
|
110
|
+
readonly c: number;
|
|
111
|
+
readonly l: string;
|
|
112
|
+
/** Lighter and stronger on dark surfaces; defaults `70%` and `c + 0.03`. */
|
|
113
|
+
readonly dark?: {
|
|
114
|
+
readonly l?: string;
|
|
115
|
+
readonly c?: number;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
/** Degrees added to the accent hue for the secondary and tertiary families. */
|
|
119
|
+
readonly secondaryHueShift?: number;
|
|
120
|
+
readonly tertiaryHueShift?: number;
|
|
121
|
+
/** Chroma of neutral surfaces; 0 is gray. */
|
|
122
|
+
readonly surfaceSaturation?: number;
|
|
123
|
+
/** How far apart the surface steps are, 0–100%. */
|
|
124
|
+
readonly surfaceContrast?: string;
|
|
125
|
+
/** Multiplies text chroma. */
|
|
126
|
+
readonly contrastFactor?: number;
|
|
127
|
+
/** Hues of the feedback families. */
|
|
128
|
+
readonly feedback?: {
|
|
129
|
+
readonly success?: number;
|
|
130
|
+
readonly warning?: number;
|
|
131
|
+
readonly error?: number;
|
|
132
|
+
readonly info?: number;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export declare const oklch: (knobs: OklchKnobs) => Readonly<{
|
|
136
|
+
knob: {
|
|
137
|
+
'accent-h': string;
|
|
138
|
+
'accent-c': string;
|
|
139
|
+
'accent-l': string;
|
|
140
|
+
'accent-c-dark': string;
|
|
141
|
+
'accent-l-dark': string;
|
|
142
|
+
'secondary-shift': string;
|
|
143
|
+
'tertiary-shift': string;
|
|
144
|
+
'surface-c': string;
|
|
145
|
+
'surface-c-dark': string;
|
|
146
|
+
'surface-contrast': string;
|
|
147
|
+
'contrast-factor': string;
|
|
148
|
+
'base-l': string;
|
|
149
|
+
'base-l-dark': string;
|
|
150
|
+
'success-h': string;
|
|
151
|
+
'warning-h': string;
|
|
152
|
+
'error-h': string;
|
|
153
|
+
'info-h': string;
|
|
154
|
+
};
|
|
155
|
+
hue: {
|
|
156
|
+
accent: string;
|
|
157
|
+
secondary: string;
|
|
158
|
+
tertiary: string;
|
|
159
|
+
neutral: string;
|
|
160
|
+
};
|
|
161
|
+
surface: {
|
|
162
|
+
base: string;
|
|
163
|
+
muted: string;
|
|
164
|
+
subtle: string;
|
|
165
|
+
default: string;
|
|
166
|
+
overt: string;
|
|
167
|
+
bedrock: string;
|
|
168
|
+
};
|
|
169
|
+
text: {
|
|
170
|
+
default: string;
|
|
171
|
+
muted: string;
|
|
172
|
+
subtle: string;
|
|
173
|
+
overt: string;
|
|
174
|
+
'on-accent': string;
|
|
175
|
+
link: string;
|
|
176
|
+
'link-hover': string;
|
|
177
|
+
};
|
|
178
|
+
outline: {
|
|
179
|
+
subtle: string;
|
|
180
|
+
default: string;
|
|
181
|
+
overt: string;
|
|
182
|
+
focus: string;
|
|
183
|
+
};
|
|
184
|
+
accent: {
|
|
185
|
+
default: string;
|
|
186
|
+
hover: string;
|
|
187
|
+
active: string;
|
|
188
|
+
subtle: string;
|
|
189
|
+
text: string;
|
|
190
|
+
};
|
|
191
|
+
secondary: {
|
|
192
|
+
default: string;
|
|
193
|
+
hover: string;
|
|
194
|
+
active: string;
|
|
195
|
+
subtle: string;
|
|
196
|
+
text: string;
|
|
197
|
+
};
|
|
198
|
+
tertiary: {
|
|
199
|
+
default: string;
|
|
200
|
+
hover: string;
|
|
201
|
+
active: string;
|
|
202
|
+
subtle: string;
|
|
203
|
+
text: string;
|
|
204
|
+
};
|
|
205
|
+
success: {
|
|
206
|
+
default: string;
|
|
207
|
+
subtle: string;
|
|
208
|
+
text: string;
|
|
209
|
+
outline: string;
|
|
210
|
+
};
|
|
211
|
+
warning: {
|
|
212
|
+
default: string;
|
|
213
|
+
subtle: string;
|
|
214
|
+
text: string;
|
|
215
|
+
outline: string;
|
|
216
|
+
};
|
|
217
|
+
error: {
|
|
218
|
+
default: string;
|
|
219
|
+
subtle: string;
|
|
220
|
+
text: string;
|
|
221
|
+
outline: string;
|
|
222
|
+
};
|
|
223
|
+
info: {
|
|
224
|
+
default: string;
|
|
225
|
+
subtle: string;
|
|
226
|
+
text: string;
|
|
227
|
+
outline: string;
|
|
228
|
+
};
|
|
229
|
+
}>;
|
|
230
|
+
type OklchTheme = ReturnType<typeof oklch>;
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/theme.d.ts
|
|
233
|
+
export declare const Theme: {
|
|
234
|
+
readonly root: (theme: ThemeTokens, options?: RootOptions) => StyleValue;
|
|
235
|
+
readonly scoped: <T extends ThemeTokens>(_theme: T, selector: string, overrides: Overrides<T>) => StyleValue;
|
|
236
|
+
readonly tokens: Readonly<{
|
|
237
|
+
knob: {
|
|
238
|
+
density: string;
|
|
239
|
+
'radius-factor': string;
|
|
240
|
+
};
|
|
241
|
+
space: {
|
|
242
|
+
'3xs': string;
|
|
243
|
+
'2xs': string;
|
|
244
|
+
xs: string;
|
|
245
|
+
sm: string;
|
|
246
|
+
md: string;
|
|
247
|
+
lg: string;
|
|
248
|
+
xl: string;
|
|
249
|
+
'2xl': string;
|
|
250
|
+
'3xl': string;
|
|
251
|
+
};
|
|
252
|
+
radius: {
|
|
253
|
+
xs: string;
|
|
254
|
+
sm: string;
|
|
255
|
+
md: string;
|
|
256
|
+
lg: string;
|
|
257
|
+
xl: string;
|
|
258
|
+
full: string;
|
|
259
|
+
};
|
|
260
|
+
font: {
|
|
261
|
+
body: string;
|
|
262
|
+
heading: string;
|
|
263
|
+
mono: string;
|
|
264
|
+
};
|
|
265
|
+
size: {
|
|
266
|
+
xs: string;
|
|
267
|
+
sm: string;
|
|
268
|
+
md: string;
|
|
269
|
+
lg: string;
|
|
270
|
+
xl: string;
|
|
271
|
+
'2xl': string;
|
|
272
|
+
'3xl': string;
|
|
273
|
+
'4xl': string;
|
|
274
|
+
};
|
|
275
|
+
leading: {
|
|
276
|
+
tight: string;
|
|
277
|
+
snug: string;
|
|
278
|
+
normal: string;
|
|
279
|
+
relaxed: string;
|
|
280
|
+
};
|
|
281
|
+
weight: {
|
|
282
|
+
normal: string;
|
|
283
|
+
medium: string;
|
|
284
|
+
semibold: string;
|
|
285
|
+
bold: string;
|
|
286
|
+
};
|
|
287
|
+
motion: {
|
|
288
|
+
fast: string;
|
|
289
|
+
normal: string;
|
|
290
|
+
ease: string;
|
|
291
|
+
};
|
|
292
|
+
border: {
|
|
293
|
+
thin: string;
|
|
294
|
+
thick: string;
|
|
295
|
+
heavy: string;
|
|
296
|
+
};
|
|
297
|
+
breakpoint: {
|
|
298
|
+
sm: string;
|
|
299
|
+
md: string;
|
|
300
|
+
lg: string;
|
|
301
|
+
xl: string;
|
|
302
|
+
};
|
|
303
|
+
}>;
|
|
304
|
+
readonly breakpointWidths: (theme: {
|
|
305
|
+
readonly breakpoint: {
|
|
306
|
+
readonly [name: string]: string;
|
|
307
|
+
};
|
|
308
|
+
}) => Readonly<Record<string, number>>;
|
|
309
|
+
readonly oklch: (knobs: OklchKnobs) => Readonly<{
|
|
310
|
+
knob: {
|
|
311
|
+
'accent-h': string;
|
|
312
|
+
'accent-c': string;
|
|
313
|
+
'accent-l': string;
|
|
314
|
+
'accent-c-dark': string;
|
|
315
|
+
'accent-l-dark': string;
|
|
316
|
+
'secondary-shift': string;
|
|
317
|
+
'tertiary-shift': string;
|
|
318
|
+
'surface-c': string;
|
|
319
|
+
'surface-c-dark': string;
|
|
320
|
+
'surface-contrast': string;
|
|
321
|
+
'contrast-factor': string;
|
|
322
|
+
'base-l': string;
|
|
323
|
+
'base-l-dark': string;
|
|
324
|
+
'success-h': string;
|
|
325
|
+
'warning-h': string;
|
|
326
|
+
'error-h': string;
|
|
327
|
+
'info-h': string;
|
|
328
|
+
};
|
|
329
|
+
hue: {
|
|
330
|
+
accent: string;
|
|
331
|
+
secondary: string;
|
|
332
|
+
tertiary: string;
|
|
333
|
+
neutral: string;
|
|
334
|
+
};
|
|
335
|
+
surface: {
|
|
336
|
+
base: string;
|
|
337
|
+
muted: string;
|
|
338
|
+
subtle: string;
|
|
339
|
+
default: string;
|
|
340
|
+
overt: string;
|
|
341
|
+
bedrock: string;
|
|
342
|
+
};
|
|
343
|
+
text: {
|
|
344
|
+
default: string;
|
|
345
|
+
muted: string;
|
|
346
|
+
subtle: string;
|
|
347
|
+
overt: string;
|
|
348
|
+
'on-accent': string;
|
|
349
|
+
link: string;
|
|
350
|
+
'link-hover': string;
|
|
351
|
+
};
|
|
352
|
+
outline: {
|
|
353
|
+
subtle: string;
|
|
354
|
+
default: string;
|
|
355
|
+
overt: string;
|
|
356
|
+
focus: string;
|
|
357
|
+
};
|
|
358
|
+
accent: {
|
|
359
|
+
default: string;
|
|
360
|
+
hover: string;
|
|
361
|
+
active: string;
|
|
362
|
+
subtle: string;
|
|
363
|
+
text: string;
|
|
364
|
+
};
|
|
365
|
+
secondary: {
|
|
366
|
+
default: string;
|
|
367
|
+
hover: string;
|
|
368
|
+
active: string;
|
|
369
|
+
subtle: string;
|
|
370
|
+
text: string;
|
|
371
|
+
};
|
|
372
|
+
tertiary: {
|
|
373
|
+
default: string;
|
|
374
|
+
hover: string;
|
|
375
|
+
active: string;
|
|
376
|
+
subtle: string;
|
|
377
|
+
text: string;
|
|
378
|
+
};
|
|
379
|
+
success: {
|
|
380
|
+
default: string;
|
|
381
|
+
subtle: string;
|
|
382
|
+
text: string;
|
|
383
|
+
outline: string;
|
|
384
|
+
};
|
|
385
|
+
warning: {
|
|
386
|
+
default: string;
|
|
387
|
+
subtle: string;
|
|
388
|
+
text: string;
|
|
389
|
+
outline: string;
|
|
390
|
+
};
|
|
391
|
+
error: {
|
|
392
|
+
default: string;
|
|
393
|
+
subtle: string;
|
|
394
|
+
text: string;
|
|
395
|
+
outline: string;
|
|
396
|
+
};
|
|
397
|
+
info: {
|
|
398
|
+
default: string;
|
|
399
|
+
subtle: string;
|
|
400
|
+
text: string;
|
|
401
|
+
outline: string;
|
|
402
|
+
};
|
|
403
|
+
}>;
|
|
404
|
+
readonly define: <T extends ThemeTokens>(tokens: T) => Readonly<T>;
|
|
405
|
+
readonly ref: <T extends ThemeTokens>(theme: T) => Refs<T>;
|
|
406
|
+
readonly variables: <T extends ThemeTokens>(theme: T) => StyleValue;
|
|
407
|
+
readonly lightDark: (light: string, dark: string) => string;
|
|
408
|
+
readonly compose: <A extends ThemeTokens, B extends ThemeTokens>(base: A, over: B) => Readonly<{ readonly [G in keyof A | keyof B]: G extends keyof B ? G extends keyof A ? A[G] & B[G] : B[G] : G extends keyof A ? A[G] : never; }>;
|
|
409
|
+
};
|
|
410
|
+
//#endregion
|
|
411
|
+
export { type OklchKnobs, type OklchTheme, type Overrides, type Refs, type RootOptions, type ThemeTokens, type Theme$1 as ThemeValue, type Tokens, VAR_PREFIX, compose, define, lightDark, ref, variables };
|
|
412
|
+
//# sourceMappingURL=theme.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.mts","names":[],"sources":["../src/theme/root.ts","../src/theme/tokens.ts","../src/theme/oklch.ts","../src/theme.ts"],"mappings":";;;UAOiB;;WAEN,OAAO;;WAEP;;qBAkBE,OAAQ,OAAO,aAAa,UAAU,gBAAc;;KAMrD,UAAU,UAAU,2BACpB,WAAW,iBAAiB,WAAW,EAAE;;;;;;;;;;qBAYxC,SAAU,UAAU,aAC/B,QAAQ,GACR,kBACA,WAAW,UAAU,OACpB;;;qBCvCU,QAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4CP,gBAAgB;;;;;;qBASf,mBAAoB;WACtB;cAAwB;;MAC/B,SAAS;;;UC1DI;;WAEN;aACE;aACA;aACA;;aAEA;eAAkB;eAAqB;;;;WAGzC;WACA;;WAEA;;WAEA;;WAEA;;WAEA;aACE;aACA;aACA;aACA;;;qBAuEA,QAAS,OAAO,eAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4E3B,aAAa,kBAAkB;;;qBChK9B"}
|
package/dist/theme.mjs
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { t as DiagnosticError } from "./diagnostics-YJ7991-A.mjs";
|
|
2
|
+
import { s as global } from "./styleValue--iQMTcPn.mjs";
|
|
3
|
+
import { a as lightDark, i as define, n as VAR_PREFIX, o as ref, r as compose, s as variables, t as Theme$1 } from "./core-izIY2GSX.mjs";
|
|
4
|
+
//#region src/theme/oklch.ts
|
|
5
|
+
/**
|
|
6
|
+
* A whole palette from a few knobs, as css-tags derives it: every value
|
|
7
|
+
* except the knobs is a CSS expression over other tokens, so overriding a
|
|
8
|
+
* knob anywhere (a scoped theme, a subtree, an inline style) re-derives the
|
|
9
|
+
* rest in the browser. Where light and dark schemes need different numbers
|
|
10
|
+
* the value is a `light-dark()` pair, so one theme serves both and a user's
|
|
11
|
+
* choice is a `color-scheme` override.
|
|
12
|
+
*/
|
|
13
|
+
const v = (group, name) => `var(--fk-${group}-${name})`;
|
|
14
|
+
/** A computed knob without float noise: `0.02`, not `0.019999999999999997`. */
|
|
15
|
+
const num = (value) => String(Number(value.toFixed(4)));
|
|
16
|
+
const ld = (light, dark) => `light-dark(${light}, ${dark})`;
|
|
17
|
+
const offset = (amount) => `${amount < 0 ? "-" : "+"} ${Math.abs(amount)}`;
|
|
18
|
+
/** `oklch(from <color> …)` with the hue kept. */
|
|
19
|
+
const from = (color, l, c) => `oklch(from ${color} ${l} ${c} h)`;
|
|
20
|
+
const shift = (color, dl, dc) => from(color, `calc(l ${offset(dl)})`, `calc(c ${offset(dc)})`);
|
|
21
|
+
const scale = (color, dl, cx) => from(color, `calc(l ${offset(dl)})`, `calc(c * ${cx})`);
|
|
22
|
+
/** The same lightness and chroma as `color` on another hue. */
|
|
23
|
+
const rehue = (color, hue) => `oklch(from ${color} l c ${hue})`;
|
|
24
|
+
/** Near-black or near-white text over `color`. */
|
|
25
|
+
const contrast = (color) => `oklch(from ${color} clamp(0.1, (0.65 / l - 1) * 999, 0.98) min(c, 0.08) h)`;
|
|
26
|
+
/** `color` tinted onto the base surface, the same in both schemes. */
|
|
27
|
+
const tint = (color, percent) => `color-mix(in oklch, ${v("surface", "base")} ${percent}%, ${color})`;
|
|
28
|
+
/** The default text color at `percent` over the base surface. */
|
|
29
|
+
const line = (percent) => `color-mix(in oklch, ${v("text", "default")} ${percent}%, ${v("surface", "base")})`;
|
|
30
|
+
const neutral = v("hue", "neutral");
|
|
31
|
+
const base = v("surface", "base");
|
|
32
|
+
const surfaceC = v("knob", "surface-c");
|
|
33
|
+
const surfaceCDark = v("knob", "surface-c-dark");
|
|
34
|
+
const contrastFactor = v("knob", "contrast-factor");
|
|
35
|
+
/** A surface step: the base mixed toward a target by `surface-contrast`. */
|
|
36
|
+
const surfaceStep = (light, dark) => {
|
|
37
|
+
const amount = v("knob", "surface-contrast");
|
|
38
|
+
const target = ld(scale(base, light[0], light[1]), scale(base, dark[0], dark[1]));
|
|
39
|
+
return `color-mix(in oklch, ${base} calc(100% - ${amount}), ${target} ${amount})`;
|
|
40
|
+
};
|
|
41
|
+
/** A text color: fixed lightness, chroma scaled by surface saturation and the contrast factor. */
|
|
42
|
+
const text = (light, dark) => ld(`oklch(${light[0]}% calc(${surfaceC} * ${light[1]} * ${contrastFactor}) ${neutral})`, `oklch(${dark[0]}% calc(${surfaceCDark} * ${dark[1]} * ${contrastFactor}) ${neutral})`);
|
|
43
|
+
const family = (name, defaultValue) => {
|
|
44
|
+
const color = v(name, "default");
|
|
45
|
+
return {
|
|
46
|
+
default: defaultValue,
|
|
47
|
+
hover: shift(color, -.06, 0),
|
|
48
|
+
active: shift(color, -.1, .05),
|
|
49
|
+
subtle: tint(color, 85),
|
|
50
|
+
text: contrast(color)
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
const feedback = (name, l, c) => {
|
|
54
|
+
const color = v(name, "default");
|
|
55
|
+
return {
|
|
56
|
+
default: `oklch(${l}% ${c} ${v("knob", `${name}-h`)})`,
|
|
57
|
+
subtle: tint(color, 85),
|
|
58
|
+
text: contrast(color),
|
|
59
|
+
outline: shift(color, -.05, 0)
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
const oklch = (knobs) => {
|
|
63
|
+
const accent = v("accent", "default");
|
|
64
|
+
const surfaceSaturation = knobs.surfaceSaturation ?? .015;
|
|
65
|
+
return define({
|
|
66
|
+
knob: {
|
|
67
|
+
"accent-h": String(knobs.accent.h),
|
|
68
|
+
"accent-c": String(knobs.accent.c),
|
|
69
|
+
"accent-l": knobs.accent.l,
|
|
70
|
+
"accent-c-dark": num(knobs.accent.dark?.c ?? Math.min(.4, knobs.accent.c + .03)),
|
|
71
|
+
"accent-l-dark": knobs.accent.dark?.l ?? "70%",
|
|
72
|
+
"secondary-shift": String(knobs.secondaryHueShift ?? 60),
|
|
73
|
+
"tertiary-shift": String(knobs.tertiaryHueShift ?? -90),
|
|
74
|
+
"surface-c": String(surfaceSaturation),
|
|
75
|
+
"surface-c-dark": num(surfaceSaturation * (4 / 3)),
|
|
76
|
+
"surface-contrast": knobs.surfaceContrast ?? "65%",
|
|
77
|
+
"contrast-factor": String(knobs.contrastFactor ?? 1),
|
|
78
|
+
"base-l": "97.5%",
|
|
79
|
+
"base-l-dark": "22%",
|
|
80
|
+
"success-h": String(knobs.feedback?.success ?? 145),
|
|
81
|
+
"warning-h": String(knobs.feedback?.warning ?? 75),
|
|
82
|
+
"error-h": String(knobs.feedback?.error ?? 25),
|
|
83
|
+
"info-h": String(knobs.feedback?.info ?? 245)
|
|
84
|
+
},
|
|
85
|
+
hue: {
|
|
86
|
+
accent: v("knob", "accent-h"),
|
|
87
|
+
secondary: `calc(${v("knob", "accent-h")} + ${v("knob", "secondary-shift")})`,
|
|
88
|
+
tertiary: `calc(${v("knob", "accent-h")} + ${v("knob", "tertiary-shift")})`,
|
|
89
|
+
neutral: v("hue", "accent")
|
|
90
|
+
},
|
|
91
|
+
surface: {
|
|
92
|
+
base: ld(`oklch(${v("knob", "base-l")} calc(${surfaceC} * 0.9) ${neutral})`, `oklch(${v("knob", "base-l-dark")} calc(${surfaceCDark} * 0.9) ${neutral})`),
|
|
93
|
+
muted: surfaceStep([-.04, .8], [-.03, .5]),
|
|
94
|
+
subtle: surfaceStep([-.025, 1.05], [-.015, .7]),
|
|
95
|
+
default: surfaceStep([-.055, 1.2], [.045, 1]),
|
|
96
|
+
overt: surfaceStep([-.31, 2.25], [.125, 1.2]),
|
|
97
|
+
bedrock: ld(`oklch(8% calc(${surfaceC} * 1.2) ${neutral})`, `oklch(98% calc(${surfaceCDark} * 0.7) ${neutral})`)
|
|
98
|
+
},
|
|
99
|
+
text: {
|
|
100
|
+
default: text([20, 2], [88, .8]),
|
|
101
|
+
muted: text([45, 1.5], [65, 1.2]),
|
|
102
|
+
subtle: text([35, 1.8], [75, 1]),
|
|
103
|
+
overt: text([10, 2.2], [95, .6]),
|
|
104
|
+
"on-accent": contrast(accent),
|
|
105
|
+
link: shift(accent, .1, .05),
|
|
106
|
+
"link-hover": shift(v("text", "link"), -.1, 0)
|
|
107
|
+
},
|
|
108
|
+
outline: {
|
|
109
|
+
subtle: line(10),
|
|
110
|
+
default: line(18),
|
|
111
|
+
overt: line(35),
|
|
112
|
+
focus: shift(accent, -.1, .1)
|
|
113
|
+
},
|
|
114
|
+
accent: family("accent", ld(`oklch(${v("knob", "accent-l")} ${v("knob", "accent-c")} ${v("hue", "accent")})`, `oklch(${v("knob", "accent-l-dark")} ${v("knob", "accent-c-dark")} ${v("hue", "accent")})`)),
|
|
115
|
+
secondary: family("secondary", rehue(accent, v("hue", "secondary"))),
|
|
116
|
+
tertiary: family("tertiary", rehue(accent, v("hue", "tertiary"))),
|
|
117
|
+
success: feedback("success", 55, .15),
|
|
118
|
+
warning: feedback("warning", 70, .15),
|
|
119
|
+
error: feedback("error", 60, .2),
|
|
120
|
+
info: feedback("info", 65, .15)
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/theme/root.ts
|
|
125
|
+
/**
|
|
126
|
+
* A theme's tokens as `:root` custom properties, for the page stylesheet.
|
|
127
|
+
* Unlayered: the page decides which layer with `Layers.in`.
|
|
128
|
+
*/
|
|
129
|
+
/**
|
|
130
|
+
* Every token as `--fk-group-name:value`, in authored order. `omit` is
|
|
131
|
+
* matched token by token, not group by group: two themes can both carry a
|
|
132
|
+
* `knob` group (the scales' density beside a palette's hues) and only the
|
|
133
|
+
* names `omit` has are skipped.
|
|
134
|
+
*/
|
|
135
|
+
const declarations = (theme, omit) => Object.entries(theme).flatMap(([group, names]) => Object.entries(names).flatMap(([name, value]) => omit !== void 0 && Object.hasOwn(omit[group] ?? {}, name) ? [] : [`${VAR_PREFIX}-${group}-${name}:${value}`]));
|
|
136
|
+
const root = (theme, options) => global(`:root{${[...declarations(theme, options?.omit), `color-scheme:${options?.colorScheme ?? "light dark"}`].join(";")}}`);
|
|
137
|
+
/**
|
|
138
|
+
* Token overrides under `selector`: a named theme the Model selects with a
|
|
139
|
+
* root attribute (`:root[data-theme="ocean"]`), a scheme the user chose
|
|
140
|
+
* (`:root[data-color-scheme="dark"]`), or a subtree (`.marketing`). Which
|
|
141
|
+
* one is active is the Model's fact; this only says what it means.
|
|
142
|
+
*
|
|
143
|
+
* `theme` is the theme being overridden and is read only for its type, so a
|
|
144
|
+
* group or token it lacks is a type error rather than a variable nothing reads.
|
|
145
|
+
*/
|
|
146
|
+
const scoped = (_theme, selector, overrides) => {
|
|
147
|
+
const tokens = {};
|
|
148
|
+
for (const [group, names] of Object.entries(overrides)) {
|
|
149
|
+
const defined = {};
|
|
150
|
+
for (const [name, value] of Object.entries(names ?? {})) if (typeof value === "string") defined[name] = value;
|
|
151
|
+
tokens[group] = defined;
|
|
152
|
+
}
|
|
153
|
+
return global(`${selector}{${declarations(tokens).join(";")}}`);
|
|
154
|
+
};
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/theme/tokens.ts
|
|
157
|
+
/**
|
|
158
|
+
* The non-color scales a design system shares across themes. Space and
|
|
159
|
+
* radius multiply by the `density` and `radius-factor` knobs, so a compact
|
|
160
|
+
* or a rounder theme is one override. `breakpoint` is the record
|
|
161
|
+
* `Style.responsive` takes; `breakpointWidths` gives the same names as pixel
|
|
162
|
+
* thresholds for `foldkit-primitives/media` Breakpoints.
|
|
163
|
+
*/
|
|
164
|
+
const space = (rem) => `calc(${rem}rem * var(--fk-knob-density))`;
|
|
165
|
+
const radius = (px) => `calc(${px}px * var(--fk-knob-radius-factor))`;
|
|
166
|
+
const tokens = define({
|
|
167
|
+
knob: {
|
|
168
|
+
density: "1",
|
|
169
|
+
"radius-factor": "1"
|
|
170
|
+
},
|
|
171
|
+
space: {
|
|
172
|
+
"3xs": space(.125),
|
|
173
|
+
"2xs": space(.25),
|
|
174
|
+
xs: space(.5),
|
|
175
|
+
sm: space(.75),
|
|
176
|
+
md: space(1),
|
|
177
|
+
lg: space(1.5),
|
|
178
|
+
xl: space(2),
|
|
179
|
+
"2xl": space(3),
|
|
180
|
+
"3xl": space(4)
|
|
181
|
+
},
|
|
182
|
+
radius: {
|
|
183
|
+
xs: radius(2),
|
|
184
|
+
sm: radius(3),
|
|
185
|
+
md: radius(6),
|
|
186
|
+
lg: radius(8),
|
|
187
|
+
xl: radius(12),
|
|
188
|
+
full: "9999px"
|
|
189
|
+
},
|
|
190
|
+
font: {
|
|
191
|
+
body: "system-ui, sans-serif",
|
|
192
|
+
heading: "inherit",
|
|
193
|
+
mono: "ui-monospace, monospace"
|
|
194
|
+
},
|
|
195
|
+
size: {
|
|
196
|
+
xs: "0.75rem",
|
|
197
|
+
sm: "0.875rem",
|
|
198
|
+
md: "1rem",
|
|
199
|
+
lg: "1.125rem",
|
|
200
|
+
xl: "1.25rem",
|
|
201
|
+
"2xl": "1.5rem",
|
|
202
|
+
"3xl": "1.875rem",
|
|
203
|
+
"4xl": "2.25rem"
|
|
204
|
+
},
|
|
205
|
+
leading: {
|
|
206
|
+
tight: "1.2",
|
|
207
|
+
snug: "1.375",
|
|
208
|
+
normal: "1.5",
|
|
209
|
+
relaxed: "1.6"
|
|
210
|
+
},
|
|
211
|
+
weight: {
|
|
212
|
+
normal: "400",
|
|
213
|
+
medium: "500",
|
|
214
|
+
semibold: "600",
|
|
215
|
+
bold: "700"
|
|
216
|
+
},
|
|
217
|
+
motion: {
|
|
218
|
+
fast: "150ms",
|
|
219
|
+
normal: "250ms",
|
|
220
|
+
ease: "ease-out"
|
|
221
|
+
},
|
|
222
|
+
border: {
|
|
223
|
+
thin: "1px",
|
|
224
|
+
thick: "2px",
|
|
225
|
+
heavy: "3px"
|
|
226
|
+
},
|
|
227
|
+
breakpoint: {
|
|
228
|
+
sm: "(min-width: 40rem)",
|
|
229
|
+
md: "(min-width: 48rem)",
|
|
230
|
+
lg: "(min-width: 64rem)",
|
|
231
|
+
xl: "(min-width: 80rem)"
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
const MIN_WIDTH = /^\(min-width:\s*(\d+(?:\.\d+)?)(rem|px)\)$/;
|
|
235
|
+
/**
|
|
236
|
+
* Each breakpoint query's `min-width` in pixels (rem at 16), so CSS and the
|
|
237
|
+
* Model agree on what `md` means. A query that is not a plain `min-width`
|
|
238
|
+
* is refused: it has no single threshold.
|
|
239
|
+
*/
|
|
240
|
+
const breakpointWidths = (theme) => {
|
|
241
|
+
const widths = {};
|
|
242
|
+
for (const [name, query] of Object.entries(theme.breakpoint)) {
|
|
243
|
+
const match = MIN_WIDTH.exec(query);
|
|
244
|
+
if (match === null) throw new DiagnosticError({
|
|
245
|
+
source: "theme",
|
|
246
|
+
code: "theme:unparseable-breakpoint",
|
|
247
|
+
severity: "error",
|
|
248
|
+
message: `Breakpoint "${name}" is "${query}", not a "(min-width: <rem|px>)" query`,
|
|
249
|
+
details: {
|
|
250
|
+
name,
|
|
251
|
+
query
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
const amount = Number(match[1]);
|
|
255
|
+
widths[name] = match[2] === "rem" ? amount * 16 : amount;
|
|
256
|
+
}
|
|
257
|
+
return Object.freeze(widths);
|
|
258
|
+
};
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/theme.ts
|
|
261
|
+
/**
|
|
262
|
+
* `foldkit-mixins/theme`: the root export's `Theme` plus the page-level
|
|
263
|
+
* pieces. `root` and `scoped` turn tokens into unlayered `:root` and
|
|
264
|
+
* selector rules for `Style.stylesheet`; `tokens` is the shipped set of
|
|
265
|
+
* non-color scales; `oklch` derives a whole palette from a few knobs.
|
|
266
|
+
*/
|
|
267
|
+
const Theme = {
|
|
268
|
+
...Theme$1,
|
|
269
|
+
root,
|
|
270
|
+
scoped,
|
|
271
|
+
tokens,
|
|
272
|
+
breakpointWidths,
|
|
273
|
+
oklch
|
|
274
|
+
};
|
|
275
|
+
//#endregion
|
|
276
|
+
export { Theme, VAR_PREFIX, breakpointWidths, compose, define, lightDark, oklch, ref, root, scoped, tokens, variables };
|
|
277
|
+
|
|
278
|
+
//# sourceMappingURL=theme.mjs.map
|