@multiplatform.one/theme 9.1.0 → 9.3.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 +23 -0
- package/dist/cjs/index.gnome.cjs +9 -0
- package/dist/cjs/index.gnome.native.js +9 -0
- package/dist/cjs/index.gnome.native.js.map +1 -1
- package/dist/cjs/menuRow.cjs +4 -0
- package/dist/cjs/menuRow.native.js +4 -0
- package/dist/cjs/menuRow.native.js.map +1 -1
- package/dist/cjs/theme/accentHue.cjs +71 -0
- package/dist/cjs/theme/accentHue.native.js +82 -0
- package/dist/cjs/theme/accentHue.native.js.map +1 -0
- package/dist/cjs/theme/chartPalette.cjs +50 -29
- package/dist/cjs/theme/chartPalette.native.js +60 -33
- package/dist/cjs/theme/chartPalette.native.js.map +1 -1
- package/dist/cjs/theme/createDefaultThemeConfig.cjs +14 -1
- package/dist/cjs/theme/createDefaultThemeConfig.native.js +14 -1
- package/dist/cjs/theme/createDefaultThemeConfig.native.js.map +1 -1
- package/dist/cjs/theme/createThemes.cjs +84 -40
- package/dist/cjs/theme/createThemes.native.js +112 -39
- package/dist/cjs/theme/createThemes.native.js.map +1 -1
- package/dist/cjs/theme/defaults/builderOptions.cjs +30 -5
- package/dist/cjs/theme/defaults/builderOptions.native.js +34 -6
- package/dist/cjs/theme/defaults/builderOptions.native.js.map +1 -1
- package/dist/cjs/theme/index.cjs +1 -0
- package/dist/cjs/theme/index.native.js +1 -0
- package/dist/cjs/theme/index.native.js.map +1 -1
- package/dist/cjs/theme/overlaySurfaces.cjs +53 -4
- package/dist/cjs/theme/overlaySurfaces.native.js +53 -4
- package/dist/cjs/theme/overlaySurfaces.native.js.map +1 -1
- package/dist/cjs/theme/pageGutter.cjs +27 -2
- package/dist/cjs/theme/pageGutter.native.js +52 -2
- package/dist/cjs/theme/pageGutter.native.js.map +1 -1
- package/dist/cjs/theme/resolveKnobs.cjs +12 -0
- package/dist/cjs/theme/resolveKnobs.native.js +12 -0
- package/dist/cjs/theme/resolveKnobs.native.js.map +1 -1
- package/dist/cjs/theme/tintHues.cjs +8 -2
- package/dist/cjs/theme/tintHues.native.js +7 -1
- package/dist/cjs/theme/tintHues.native.js.map +1 -1
- package/dist/cjs/theme/v3TokenRoles.cjs +2 -2
- package/dist/cjs/theme/v3TokenRoles.native.js +2 -2
- package/dist/cjs/theme/v3TokenRoles.native.js.map +1 -1
- package/dist/esm/index.gnome.mjs +4 -4
- package/dist/esm/index.gnome.mjs.map +1 -1
- package/dist/esm/index.gnome.native.js +4 -4
- package/dist/esm/index.gnome.native.js.map +1 -1
- package/dist/esm/menuRow.mjs +4 -1
- package/dist/esm/menuRow.mjs.map +1 -1
- package/dist/esm/menuRow.native.js +4 -1
- package/dist/esm/menuRow.native.js.map +1 -1
- package/dist/esm/theme/accentHue.mjs +42 -0
- package/dist/esm/theme/accentHue.mjs.map +1 -0
- package/dist/esm/theme/accentHue.native.js +50 -0
- package/dist/esm/theme/accentHue.native.js.map +1 -0
- package/dist/esm/theme/chartPalette.mjs +51 -30
- package/dist/esm/theme/chartPalette.mjs.map +1 -1
- package/dist/esm/theme/chartPalette.native.js +61 -34
- package/dist/esm/theme/chartPalette.native.js.map +1 -1
- package/dist/esm/theme/createDefaultThemeConfig.mjs +14 -1
- package/dist/esm/theme/createDefaultThemeConfig.mjs.map +1 -1
- package/dist/esm/theme/createDefaultThemeConfig.native.js +14 -1
- package/dist/esm/theme/createDefaultThemeConfig.native.js.map +1 -1
- package/dist/esm/theme/createThemes.mjs +85 -42
- package/dist/esm/theme/createThemes.mjs.map +1 -1
- package/dist/esm/theme/createThemes.native.js +113 -41
- package/dist/esm/theme/createThemes.native.js.map +1 -1
- package/dist/esm/theme/defaults/builderOptions.mjs +31 -6
- package/dist/esm/theme/defaults/builderOptions.mjs.map +1 -1
- package/dist/esm/theme/defaults/builderOptions.native.js +35 -7
- package/dist/esm/theme/defaults/builderOptions.native.js.map +1 -1
- package/dist/esm/theme/index.mjs +1 -0
- package/dist/esm/theme/index.mjs.map +1 -1
- package/dist/esm/theme/index.native.js +1 -0
- package/dist/esm/theme/index.native.js.map +1 -1
- package/dist/esm/theme/overlaySurfaces.mjs +47 -4
- package/dist/esm/theme/overlaySurfaces.mjs.map +1 -1
- package/dist/esm/theme/overlaySurfaces.native.js +47 -4
- package/dist/esm/theme/overlaySurfaces.native.js.map +1 -1
- package/dist/esm/theme/pageGutter.mjs +27 -4
- package/dist/esm/theme/pageGutter.mjs.map +1 -1
- package/dist/esm/theme/pageGutter.native.js +52 -4
- package/dist/esm/theme/pageGutter.native.js.map +1 -1
- package/dist/esm/theme/resolveKnobs.mjs +12 -0
- package/dist/esm/theme/resolveKnobs.mjs.map +1 -1
- package/dist/esm/theme/resolveKnobs.native.js +12 -0
- package/dist/esm/theme/resolveKnobs.native.js.map +1 -1
- package/dist/esm/theme/tintHues.mjs +6 -1
- package/dist/esm/theme/tintHues.mjs.map +1 -1
- package/dist/esm/theme/tintHues.native.js +6 -1
- package/dist/esm/theme/tintHues.native.js.map +1 -1
- package/dist/esm/theme/v3TokenRoles.mjs +2 -2
- package/dist/esm/theme/v3TokenRoles.native.js +2 -2
- package/package.json +5 -5
- package/src/figma/figmaTokens.spec.ts +2 -2
- package/src/index.gnome.ts +9 -0
- package/src/menuRow.palette.spec.ts +26 -1
- package/src/menuRow.spec.ts +17 -1
- package/src/menuRow.ts +12 -0
- package/src/theme/accentHue.spec.ts +252 -0
- package/src/theme/accentHue.ts +73 -0
- package/src/theme/chartCategoricalSeverity.spec.ts +190 -0
- package/src/theme/chartPalette.spec.ts +37 -34
- package/src/theme/chartPalette.ts +90 -39
- package/src/theme/colorRules.spec.ts +3 -3
- package/src/theme/createDefaultThemeConfig.spec.ts +71 -2
- package/src/theme/createDefaultThemeConfig.ts +47 -5
- package/src/theme/createThemes.ts +167 -59
- package/src/theme/defaults/builderOptions.ts +41 -9
- package/src/theme/defaults/secondaryInk.spec.ts +71 -0
- package/src/theme/index.ts +1 -0
- package/src/theme/intentFill.spec.ts +8 -3
- package/src/theme/overlaySurfaces.tsx +75 -6
- package/src/theme/pageGutter.spec.tsx +2 -2
- package/src/theme/pageGutter.tsx +55 -2
- package/src/theme/rampRoles.spec.ts +60 -0
- package/src/theme/recipes.ts +2 -0
- package/src/theme/resolveKnobs.spec.ts +17 -0
- package/src/theme/resolveKnobs.ts +12 -0
- package/src/theme/severityChannel.spec.ts +202 -0
- package/src/theme/sheetHandle.spec.ts +54 -0
- package/src/theme/tintHues.ts +10 -0
- package/src/theme/v3TokenRoles.ts +2 -2
- package/types/index.gnome.d.ts +3 -3
- package/types/index.gnome.d.ts.map +1 -1
- package/types/menuRow.d.ts +9 -0
- package/types/menuRow.d.ts.map +1 -1
- package/types/theme/accentHue.d.ts +20 -0
- package/types/theme/accentHue.d.ts.map +1 -0
- package/types/theme/chartPalette.d.ts +2 -2
- package/types/theme/chartPalette.d.ts.map +1 -1
- package/types/theme/createDefaultThemeConfig.d.ts +12 -10
- package/types/theme/createDefaultThemeConfig.d.ts.map +1 -1
- package/types/theme/createThemes.d.ts +17 -2
- package/types/theme/createThemes.d.ts.map +1 -1
- package/types/theme/defaults/builderOptions.d.ts.map +1 -1
- package/types/theme/index.d.ts +1 -0
- package/types/theme/index.d.ts.map +1 -1
- package/types/theme/overlaySurfaces.d.ts +61 -3
- package/types/theme/overlaySurfaces.d.ts.map +1 -1
- package/types/theme/pageGutter.d.ts +26 -1
- package/types/theme/pageGutter.d.ts.map +1 -1
- package/types/theme/recipes.d.ts +4 -0
- package/types/theme/recipes.d.ts.map +1 -1
- package/types/theme/resolveKnobs.d.ts.map +1 -1
- package/types/theme/tintHues.d.ts +5 -0
- package/types/theme/tintHues.d.ts.map +1 -1
- package/types/theme/v3TokenRoles.d.ts +2 -2
|
@@ -2,7 +2,7 @@ import * as Colors from "@tamagui/colors";
|
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { useTheme as useTamaguiTheme, useThemeName } from "tamagui";
|
|
4
4
|
import { contrastRatio, minContrastRatio, normalizeToHex, relativeLuminance } from "./colorRules";
|
|
5
|
-
import { tintHueNames } from "./createThemes";
|
|
5
|
+
import { intentInkFloor, tintHueNames } from "./createThemes";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Chart palette contract (SB-D-07 / SB-D-25 GAP closure).
|
|
@@ -19,10 +19,10 @@ import { tintHueNames } from "./createThemes";
|
|
|
19
19
|
* fills the rest, dropping hues indistinguishable from the identity so
|
|
20
20
|
* adjacent series stay tellable-apart under every tint.
|
|
21
21
|
* - `semantic` — error/success/warning series solids from the sanctioned
|
|
22
|
-
* semantic ramps ($red/$green
|
|
22
|
+
* semantic ramps ($red/$green, amber warning), tint-independent, scheme-aware.
|
|
23
23
|
*
|
|
24
24
|
* Values resolve from the same Radix scales the theme builder splats into the
|
|
25
|
-
* base themes, so `categorical[1]` under `light` equals `$
|
|
25
|
+
* base themes, so `categorical[1]` under `light` equals `$blue9`, and they
|
|
26
26
|
* stay resolvable on native and under tint sub-themes (which only carry the
|
|
27
27
|
* re-ramped neutral family).
|
|
28
28
|
*/
|
|
@@ -64,21 +64,22 @@ export interface ResolveChartPaletteInput {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* Fixed categorical
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
67
|
+
* Fixed categorical cycle (LC-27, LC-288): Radix solids at least 0.08 OKLab
|
|
68
|
+
* from every severity mark and ink step, so no category reads as error,
|
|
69
|
+
* warning or success. A warm hue may share a severity's band when its
|
|
70
|
+
* lightness sets it well apart (yellow12, brown, gold). Steps are chosen so
|
|
71
|
+
* six series stay apart under deuteranopia and protanopia and each clears
|
|
72
|
+
* 3:1 on every reference and tinted Card surface.
|
|
72
73
|
*/
|
|
73
74
|
const categoricalHueCycle = [
|
|
74
|
-
{ family: "blue", light: Colors.blue.
|
|
75
|
-
{ family: "
|
|
76
|
-
{ family: "
|
|
77
|
-
{ family: "
|
|
78
|
-
{ family: "pink", light: Colors.pink.pink9, dark: Colors.pinkDark.pink9 },
|
|
79
|
-
{ family: "teal", light: Colors.teal.teal11, dark: Colors.tealDark.teal9 },
|
|
75
|
+
{ family: "blue", light: Colors.blue.blue9, dark: Colors.blueDark.blue9 },
|
|
76
|
+
{ family: "yellow", light: Colors.yellow.yellow12, dark: Colors.yellowDark.yellow10 },
|
|
77
|
+
{ family: "pink", light: Colors.pink.pink11, dark: Colors.pinkDark.pink9 },
|
|
78
|
+
{ family: "sky", light: Colors.sky.sky12, dark: Colors.skyDark.sky9 },
|
|
80
79
|
{ family: "violet", light: Colors.violet.violet9, dark: Colors.violetDark.violet11 },
|
|
81
|
-
{ family: "
|
|
80
|
+
{ family: "brown", light: Colors.brown.brown9, dark: Colors.brownDark.brown11 },
|
|
81
|
+
{ family: "gold", light: Colors.gold.gold12, dark: Colors.goldDark.gold10 },
|
|
82
|
+
{ family: "indigo", light: Colors.indigo.indigo10, dark: Colors.indigoDark.indigo11 },
|
|
82
83
|
] as const;
|
|
83
84
|
|
|
84
85
|
// The rendered audit still owns custom consumer backgrounds and elevation
|
|
@@ -108,21 +109,20 @@ function readableIdentity(
|
|
|
108
109
|
|
|
109
110
|
/**
|
|
110
111
|
* Semantic series solids. Light success deepens to green10 for the mark floor.
|
|
111
|
-
* Error and dark success use step 9. Warning
|
|
112
|
-
* the
|
|
113
|
-
*
|
|
114
|
-
* step while dark keeps the bright yellow9 (13:1 on dark surfaces).
|
|
112
|
+
* Error and dark success use step 9. Warning is amber (LC-288): light takes
|
|
113
|
+
* the warning scope's own ink floor, because amber9 is too pale for a mark on
|
|
114
|
+
* a light card, and dark keeps amber9.
|
|
115
115
|
*/
|
|
116
116
|
const semanticSeries = {
|
|
117
117
|
light: {
|
|
118
118
|
error: Colors.red.red9,
|
|
119
119
|
success: Colors.green.green10,
|
|
120
|
-
warning:
|
|
120
|
+
warning: intentInkFloor.warning,
|
|
121
121
|
},
|
|
122
122
|
dark: {
|
|
123
123
|
error: Colors.redDark.red9,
|
|
124
124
|
success: Colors.greenDark.green9,
|
|
125
|
-
warning: Colors.
|
|
125
|
+
warning: Colors.amberDark.amber9,
|
|
126
126
|
},
|
|
127
127
|
} as const;
|
|
128
128
|
|
|
@@ -175,22 +175,77 @@ function hueDistance(a: number, b: number): number {
|
|
|
175
175
|
return d > 180 ? 360 - d : d;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/** A cycle entry closer than this to the identity under simulated CVD is dropped (LC-27). */
|
|
179
|
+
const minSimulatedDistance = 0.06;
|
|
180
|
+
|
|
181
|
+
/** Machado 2009 full-severity deuteranopia and protanopia, on linear sRGB. */
|
|
182
|
+
const cvdMatrices = [
|
|
183
|
+
[
|
|
184
|
+
[0.367322, 0.860646, -0.227968],
|
|
185
|
+
[0.280085, 0.672501, 0.047413],
|
|
186
|
+
[-0.01182, 0.04294, 0.968881],
|
|
187
|
+
],
|
|
188
|
+
[
|
|
189
|
+
[0.152286, 1.052583, -0.204868],
|
|
190
|
+
[0.114503, 0.786281, 0.099216],
|
|
191
|
+
[-0.003882, -0.048116, 1.051998],
|
|
192
|
+
],
|
|
193
|
+
] as const;
|
|
194
|
+
|
|
195
|
+
const toLinear = (c: number) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
|
|
196
|
+
const toSrgb8 = (v: number) =>
|
|
197
|
+
Math.round((v <= 0.0031308 ? v * 12.92 : 1.055 * v ** (1 / 2.4) - 0.055) * 255) / 255;
|
|
198
|
+
|
|
199
|
+
/** OKLab of `hex` as seen through `matrix`, quantised back to 8-bit sRGB like a screen. */
|
|
200
|
+
function simulatedOklab(hex: string, matrix: (typeof cvdMatrices)[number]): number[] {
|
|
201
|
+
const rgb = [1, 3, 5].map((i) => toLinear(Number.parseInt(hex.slice(i, i + 2), 16) / 255));
|
|
202
|
+
const [r, g, b] = matrix.map((row) =>
|
|
203
|
+
toLinear(
|
|
204
|
+
toSrgb8(Math.min(1, Math.max(0, row[0] * rgb[0] + row[1] * rgb[1] + row[2] * rgb[2]))),
|
|
205
|
+
),
|
|
206
|
+
) as [number, number, number];
|
|
207
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
208
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
209
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787405 * b);
|
|
210
|
+
return [
|
|
211
|
+
0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
|
212
|
+
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
|
213
|
+
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** True when deuteranopia and protanopia both still tell `a` from `b`. */
|
|
218
|
+
function apartUnderCvd(a: string, b: string): boolean {
|
|
219
|
+
const x = normalizeToHex(a);
|
|
220
|
+
const y = normalizeToHex(b);
|
|
221
|
+
if (!x || !y) return true;
|
|
222
|
+
return cvdMatrices.every((matrix) => {
|
|
223
|
+
const p = simulatedOklab(x, matrix);
|
|
224
|
+
const q = simulatedOklab(y, matrix);
|
|
225
|
+
return Math.hypot(p[0] - q[0], p[1] - q[1], p[2] - q[2]) >= minSimulatedDistance;
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** LC-27: any one of hue, saturation or luminance can distinguish a pair. */
|
|
230
|
+
function distinguishable(a: string, b: string): boolean {
|
|
231
|
+
const x = colorToHsl(a) as Hsl;
|
|
232
|
+
const y = colorToHsl(b) as Hsl;
|
|
233
|
+
return (
|
|
234
|
+
(x.s >= neutralSaturationFloor &&
|
|
235
|
+
y.s >= neutralSaturationFloor &&
|
|
236
|
+
hueDistance(x.h, y.h) >= hueDedupeThresholdDeg) ||
|
|
237
|
+
Math.abs(x.s - y.s) >= 0.5 ||
|
|
238
|
+
contrastRatio(
|
|
239
|
+
relativeLuminance(normalizeToHex(a) as string),
|
|
240
|
+
relativeLuminance(normalizeToHex(b) as string),
|
|
241
|
+
) >= 1.5
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
178
245
|
/** Keep every solid after dedupe, moving only an invalid adjacent sequence. */
|
|
179
246
|
function orderCategoricalCycle(identity: string, cycle: string[]): string[] {
|
|
180
247
|
const colors = [identity, ...cycle];
|
|
181
|
-
const
|
|
182
|
-
const luminance = colors.map((color) => relativeLuminance(normalizeToHex(color) as string));
|
|
183
|
-
// LC-27: any one of hue, saturation or luminance can distinguish a pair.
|
|
184
|
-
const compatible = hsl.map((a, i) =>
|
|
185
|
-
hsl.map(
|
|
186
|
-
(b, j) =>
|
|
187
|
-
(a.s >= neutralSaturationFloor &&
|
|
188
|
-
b.s >= neutralSaturationFloor &&
|
|
189
|
-
hueDistance(a.h, b.h) >= hueDedupeThresholdDeg) ||
|
|
190
|
-
Math.abs(a.s - b.s) >= 0.5 ||
|
|
191
|
-
contrastRatio(luminance[i], luminance[j]) >= 1.5,
|
|
192
|
-
),
|
|
193
|
-
);
|
|
248
|
+
const compatible = colors.map((a) => colors.map((b) => distinguishable(a, b)));
|
|
194
249
|
const indices = cycle.map((_, i) => i + 1);
|
|
195
250
|
if (indices.every((i) => compatible[i - 1][i]) && compatible[colors.length - 1][0]) {
|
|
196
251
|
return cycle;
|
|
@@ -242,11 +297,7 @@ export function resolveChartPalette(input: ResolveChartPaletteInput): ChartPalet
|
|
|
242
297
|
const deduped =
|
|
243
298
|
identityHsl.s < neutralSaturationFloor
|
|
244
299
|
? cycle
|
|
245
|
-
: cycle.filter((value) =>
|
|
246
|
-
const hsl = colorToHsl(value);
|
|
247
|
-
if (!hsl) return true;
|
|
248
|
-
return hueDistance(hsl.h, identityHsl.h) >= hueDedupeThresholdDeg;
|
|
249
|
-
});
|
|
300
|
+
: cycle.filter((value) => distinguishable(value, single) && apartUnderCvd(value, single));
|
|
250
301
|
|
|
251
302
|
return {
|
|
252
303
|
scheme,
|
|
@@ -490,7 +490,7 @@ describe("intent color11 on the base page surfaces (MPO-40)", () => {
|
|
|
490
490
|
})),
|
|
491
491
|
);
|
|
492
492
|
expect(reports.map((report) => report.ratio)).toEqual([
|
|
493
|
-
expect.closeTo(4.
|
|
493
|
+
expect.closeTo(4.7, 2),
|
|
494
494
|
expect.closeTo(4.53, 2),
|
|
495
495
|
]);
|
|
496
496
|
});
|
|
@@ -506,8 +506,8 @@ describe("intent color11 on the base page surfaces (MPO-40)", () => {
|
|
|
506
506
|
),
|
|
507
507
|
);
|
|
508
508
|
expect(reports.map((report) => report.ratio)).toEqual([
|
|
509
|
-
expect.closeTo(4.
|
|
510
|
-
expect.closeTo(
|
|
509
|
+
expect.closeTo(4.7, 2),
|
|
510
|
+
expect.closeTo(5.03, 2),
|
|
511
511
|
expect.closeTo(4.53, 2),
|
|
512
512
|
expect.closeTo(4.85, 2),
|
|
513
513
|
]);
|
|
@@ -33,8 +33,16 @@ import { generateScale } from "./scale/generateScale";
|
|
|
33
33
|
import { defaultScaleInputs, v5ScaleInputs } from "./scale/scaleInputs";
|
|
34
34
|
import { DEFAULT_SCALE_ID } from "./scale/themeScales";
|
|
35
35
|
import { createTamagui } from "tamagui";
|
|
36
|
-
import {
|
|
37
|
-
|
|
36
|
+
import {
|
|
37
|
+
boldPreset,
|
|
38
|
+
consolePreset,
|
|
39
|
+
defaultPreset,
|
|
40
|
+
densePreset,
|
|
41
|
+
heroPreset,
|
|
42
|
+
roomyPreset,
|
|
43
|
+
storefrontPreset,
|
|
44
|
+
} from "./presets";
|
|
45
|
+
import { createThemesBuilder, tintHueNames, type GetThemeProps } from "./createThemes";
|
|
38
46
|
import { defaultBaseTheme, defaultAccentTheme } from "./defaults";
|
|
39
47
|
import { darkHairlineContrast } from "./defaults/builderOptions";
|
|
40
48
|
import { setSizeRecipeInputs } from "./sizeRecipes";
|
|
@@ -218,6 +226,67 @@ function tokenGroupValues(tokens: RawTokens, group: string): Record<string, unkn
|
|
|
218
226
|
return out;
|
|
219
227
|
}
|
|
220
228
|
|
|
229
|
+
describe("a consumer getTheme's textMuted survives a tint (FZ-11178)", () => {
|
|
230
|
+
afterEach(() => {
|
|
231
|
+
setSizeRecipeInputs();
|
|
232
|
+
});
|
|
233
|
+
const ink = { light: "#5c5c5c", dark: "#a3a3a3" } as const;
|
|
234
|
+
const config = createDefaultThemeConfig({
|
|
235
|
+
builderOptions: {
|
|
236
|
+
getTheme: ({ scheme }: GetThemeProps) => (scheme ? { textMuted: ink[scheme] } : {}),
|
|
237
|
+
},
|
|
238
|
+
}) as unknown as { tamagui: { themes: RawThemes } };
|
|
239
|
+
const themes = config.tamagui.themes;
|
|
240
|
+
const presets = {
|
|
241
|
+
defaultPreset,
|
|
242
|
+
boldPreset,
|
|
243
|
+
heroPreset,
|
|
244
|
+
densePreset,
|
|
245
|
+
roomyPreset,
|
|
246
|
+
consolePreset,
|
|
247
|
+
storefrontPreset,
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
for (const scheme of ["light", "dark"] as const) {
|
|
251
|
+
for (const name of [scheme, `${scheme}_purple`]) {
|
|
252
|
+
it(`${name} keeps the consumer's ${ink[scheme]}`, () => {
|
|
253
|
+
expect(resolveThemeThroughParents(themes, name).textMuted).toBe(ink[scheme]);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
for (const [presetName, preset] of Object.entries(presets)) {
|
|
258
|
+
it(`${scheme} under ${presetName} keeps the consumer's ink on the preset's theme`, () => {
|
|
259
|
+
const name = preset.theme ? `${scheme}_${preset.theme}` : scheme;
|
|
260
|
+
expect(themes[name], name).toBeTruthy();
|
|
261
|
+
expect(resolveThemeThroughParents(themes, name).textMuted, name).toBe(ink[scheme]);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
it(`${scheme}: every tint hue keeps the consumer's ink`, () => {
|
|
266
|
+
let tints = 0;
|
|
267
|
+
for (const hue of tintHueNames) {
|
|
268
|
+
const name = `${scheme}_${hue}`;
|
|
269
|
+
if (!themes[name]) continue;
|
|
270
|
+
tints += 1;
|
|
271
|
+
expect(resolveThemeThroughParents(themes, name).textMuted, name).toBe(ink[scheme]);
|
|
272
|
+
}
|
|
273
|
+
expect(tints).toBeGreaterThan(0);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
it("with no consumer textMuted, a tint still takes the neutral pick", () => {
|
|
278
|
+
const stock = (createDefaultThemeConfig() as unknown as { tamagui: { themes: RawThemes } })
|
|
279
|
+
.tamagui.themes;
|
|
280
|
+
for (const scheme of ["light", "dark"] as const) {
|
|
281
|
+
const tint = resolveThemeThroughParents(stock, `${scheme}_purple`);
|
|
282
|
+
const root = resolveThemeThroughParents(stock, scheme);
|
|
283
|
+
expect(tint.textMuted).toBeTruthy();
|
|
284
|
+
expect(Object.values(root)).toContain(tint.textMuted);
|
|
285
|
+
expect(tint.textMuted).not.toBe(tint.color);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
221
290
|
describe("createDefaultThemeConfig — Tamagui era pin (MPO-19 X13 / W0-era-pin)", () => {
|
|
222
291
|
const config = createDefaultThemeConfig() as unknown as {
|
|
223
292
|
tamagui: {
|
|
@@ -2,6 +2,12 @@ import { defaultConfig, mediaQueryDefaultActive } from "@tamagui/config/v5";
|
|
|
2
2
|
import { shorthands } from "@tamagui/shorthands";
|
|
3
3
|
import type { CreateTamaguiProps, GenericFont } from "tamagui";
|
|
4
4
|
import { animations } from "./animations/index";
|
|
5
|
+
import {
|
|
6
|
+
type AccentHue,
|
|
7
|
+
accentHues,
|
|
8
|
+
assertAccentHueClearsSeverities,
|
|
9
|
+
isAccentHue,
|
|
10
|
+
} from "./accentHue";
|
|
5
11
|
import {
|
|
6
12
|
type BaseThemeBuilderDefinition,
|
|
7
13
|
type CreateThemesBuilderOptions,
|
|
@@ -48,6 +54,17 @@ export interface CreateDefaultThemeConfigOptions {
|
|
|
48
54
|
base?: BaseThemeBuilderDefinition;
|
|
49
55
|
/** Accent theme palette (defaults to the built-in accent ramps) */
|
|
50
56
|
accent?: ThemeBuilderDefinition;
|
|
57
|
+
/**
|
|
58
|
+
* FZ-11155, LC-172. The colour theme the scheme root's accent comes from:
|
|
59
|
+
* its fill, ink, selected pair, identity ink, focus ring and the
|
|
60
|
+
* `theme="accent"` solid. The base palette, `getTheme` tokens and every
|
|
61
|
+
* surface stay the app's own, as macOS's accent colour leaves window chrome
|
|
62
|
+
* grey. Defaults to `"blue"`. Reach for this, not a preset's `theme`, when
|
|
63
|
+
* only the accent should change: a preset's `theme` enters the hue's scope
|
|
64
|
+
* and brings its tinted surfaces and inks too. Only hues that clear LC-288's
|
|
65
|
+
* 30° from every severity are accepted. Not combinable with `accent`.
|
|
66
|
+
*/
|
|
67
|
+
accentHue?: AccentHue;
|
|
51
68
|
/** Map of extra named themes with their palettes */
|
|
52
69
|
additionalThemes?: Record<string, ThemeBuilderDefinition>;
|
|
53
70
|
/** Font definitions (merged over the default heading/body and category fonts) */
|
|
@@ -143,22 +160,47 @@ export function assertNoPrebuiltThemes(options: CreateDefaultThemeConfigOptions)
|
|
|
143
160
|
* COMPOSES with the default (consumer keys win; framework derivations like
|
|
144
161
|
* the solid `$outlineColor` focus ring survive partial overrides).
|
|
145
162
|
*/
|
|
163
|
+
function assertAccentHueOption(options: CreateDefaultThemeConfigOptions): void {
|
|
164
|
+
const hue: unknown = options.accentHue;
|
|
165
|
+
if (hue === undefined) return;
|
|
166
|
+
if (!isAccentHue(hue)) {
|
|
167
|
+
throw new Error(
|
|
168
|
+
`createDefaultThemeConfig: accentHue "${String(hue)}" is not an accent hue. ` +
|
|
169
|
+
`Red, orange, yellow and green sit under 30° from a severity (LC-288 SEVERITY-CHANNEL); ` +
|
|
170
|
+
`name one of ${accentHues.join(", ")}.`,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
if (options.accent) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
"createDefaultThemeConfig: pass `accentHue` or `accent`, not both. " +
|
|
176
|
+
"`accentHue` replaces the root's accent ramp with the named colour theme's.",
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
146
181
|
export function createDefaultThemeConfig(
|
|
147
182
|
options: CreateDefaultThemeConfigOptions = {},
|
|
148
183
|
): ThemeConfig {
|
|
149
184
|
assertNoPrebuiltThemes(options);
|
|
185
|
+
assertAccentHueOption(options);
|
|
150
186
|
setSizeRecipeInputs(options.recipeInputs ?? {});
|
|
151
187
|
const scale = generateScale(defaultScaleInputs);
|
|
152
188
|
const base = options.base ?? defaultBaseTheme;
|
|
153
189
|
const accent = options.accent ?? defaultAccentTheme;
|
|
154
|
-
const themesBuilder = createThemesBuilder(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
190
|
+
const themesBuilder = createThemesBuilder(
|
|
191
|
+
base,
|
|
192
|
+
accent,
|
|
193
|
+
{
|
|
194
|
+
...defaultBuilderOptions,
|
|
195
|
+
...options.builderOptions,
|
|
196
|
+
getTheme: composeGetTheme(options.builderOptions?.getTheme),
|
|
197
|
+
},
|
|
198
|
+
options.accentHue,
|
|
199
|
+
);
|
|
159
200
|
const builtThemes: Record<string, Record<string, string>> = {
|
|
160
201
|
...themesBuilder.themes(),
|
|
161
202
|
};
|
|
203
|
+
if (options.accentHue) assertAccentHueClearsSeverities(builtThemes, options.accentHue);
|
|
162
204
|
if (options.additionalThemes) {
|
|
163
205
|
for (const [name, palette] of Object.entries(options.additionalThemes)) {
|
|
164
206
|
Object.assign(builtThemes, themesBuilder.addTheme(name, palette));
|