@astryxdesign/cli 0.7.13 → 0.7.14-canary.108f354
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 +18 -18
- package/api/component/__fixtures__/resolutions/modules.txt +1 -1
- package/api/doctor/doctor.mjs +3 -7
- package/api/experimental.d.mts +2 -0
- package/api/experimental.mjs +12 -0
- package/api/icon/_adapter.d.mts +10 -0
- package/api/icon/_adapter.mjs +31 -2
- package/api/icon/_authoring.d.mts +2 -1
- package/api/icon/_authoring.mjs +91 -6
- package/api/icon/_options.mjs +1 -0
- package/api/icon/_records.d.mts +18 -0
- package/api/icon/_records.mjs +26 -0
- package/api/icon/add/add.mjs +7 -1
- package/api/icon/definitions/definitions.d.mts +12 -0
- package/api/icon/definitions/definitions.mjs +83 -0
- package/api/icon/icon.doc.mjs +5 -4
- package/api/icon/icon.mjs +5 -16
- package/api/icon/icon.type.d.mts +29 -2
- package/api/icon/icon.type.mjs +17 -3
- package/api/icon/iconAdd.doc.mjs +1 -1
- package/api/icon/iconMap.doc.mjs +2 -2
- package/api/icon/iconNewSet.doc.mjs +8 -2
- package/api/icon/map/map.mjs +21 -2
- package/api/icon/new-set/new-set.mjs +14 -2
- package/api/icon/search/search.mjs +2 -15
- package/api/icon/use/use.mjs +4 -3
- package/api/integration/validate-integration.mjs +6 -1
- package/api/integration/validate-integration.type.d.mts +12 -0
- package/api/integration/validate-integration.type.mjs +5 -0
- package/api/theme-edit/_adapter.d.mts +116 -0
- package/api/theme-edit/_adapter.mjs +1683 -0
- package/api/theme-edit/_catalog.d.mts +59 -0
- package/api/theme-edit/_catalog.mjs +564 -0
- package/api/theme-edit/_check.d.mts +49 -0
- package/api/theme-edit/_check.mjs +845 -0
- package/api/theme-edit/_color.d.mts +29 -0
- package/api/theme-edit/_color.mjs +300 -0
- package/api/theme-edit/_compiler.d.mts +61 -0
- package/api/theme-edit/_compiler.mjs +522 -0
- package/api/theme-edit/_css-properties.d.mts +10 -0
- package/api/theme-edit/_css-properties.mjs +556 -0
- package/api/theme-edit/_parts.d.mts +111 -0
- package/api/theme-edit/_parts.mjs +409 -0
- package/api/theme-edit/_png.d.mts +40 -0
- package/api/theme-edit/_png.mjs +187 -0
- package/api/theme-edit/_preview.d.mts +121 -0
- package/api/theme-edit/_preview.mjs +720 -0
- package/api/theme-edit/_project.d.mts +83 -0
- package/api/theme-edit/_project.mjs +289 -0
- package/api/theme-edit/_settings.d.mts +222 -0
- package/api/theme-edit/_settings.mjs +861 -0
- package/api/theme-edit/_tables.d.mts +132 -0
- package/api/theme-edit/_tables.mjs +700 -0
- package/api/theme-edit/theme-edit.d.mts +93 -0
- package/api/theme-edit/theme-edit.mjs +145 -0
- package/api/theme-edit/theme-edit.type.d.mts +413 -0
- package/api/theme-edit/theme-edit.type.mjs +233 -0
- package/api/theme-edit/themeEditHow.doc.d.mts +6 -0
- package/api/theme-edit/themeEditHow.doc.mjs +88 -0
- package/api/theme-edit/themeEditNew.doc.d.mts +6 -0
- package/api/theme-edit/themeEditNew.doc.mjs +89 -0
- package/api/theme-edit/themeEditPreviewAdd.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +100 -0
- package/api/theme-edit/themeEditPreviewApp.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +84 -0
- package/api/theme-edit/themeEditPreviewList.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewList.doc.mjs +53 -0
- package/api/theme-edit/themeEditPreviewRemove.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +66 -0
- package/api/theme-edit/themeEditSet.doc.d.mts +6 -0
- package/api/theme-edit/themeEditSet.doc.mjs +165 -0
- package/api/theme-edit/themeEditShow.doc.d.mts +6 -0
- package/api/theme-edit/themeEditShow.doc.mjs +86 -0
- package/api/theme-edit/themeEditUndo.doc.d.mts +6 -0
- package/api/theme-edit/themeEditUndo.doc.mjs +124 -0
- package/assets/docs/color.doc.mjs +5 -5
- package/assets/docs/tree/icon-sets.doc.mjs +6 -2
- package/assets/docs/tree/tokens-border.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +2 -2
- package/assets/docs/tree/tokens-data.doc.mjs +2 -2
- package/assets/docs/tree/tokens-duration.doc.mjs +1 -1
- package/assets/docs/tree/tokens-ease.doc.mjs +1 -1
- package/assets/docs/tree/tokens-focus.doc.mjs +1 -1
- package/assets/docs/tree/tokens-font-weight.doc.mjs +1 -1
- package/assets/docs/tree/tokens-radius.doc.mjs +1 -1
- package/assets/docs/tree/tokens-shadow.doc.mjs +1 -1
- package/assets/docs/tree/tokens-size.doc.mjs +1 -1
- package/assets/docs/tree/tokens-spacing.doc.mjs +1 -1
- package/assets/docs/tree/tokens-syntax.doc.mjs +1 -1
- package/assets/docs/tree/tokens-text-size.doc.mjs +1 -1
- package/assets/docs/tree/tokens-type-scale.doc.mjs +1 -1
- package/assets/docs/tree/tokens-typography.doc.mjs +1 -1
- package/assets/icons/definitions/bank.doc.mjs +1 -1
- package/assets/icons/definitions/save.doc.mjs +1 -1
- package/assets/preview-app/README.md +6 -0
- package/assets/preview-app/css.d.ts +5 -0
- package/assets/preview-app/gitignore +1 -0
- package/assets/preview-app/next.config.mjs +6 -0
- package/assets/preview-app/package.json +23 -0
- package/assets/preview-app/src/app/globals.css +5 -0
- package/assets/preview-app/src/app/layout.tsx +21 -0
- package/assets/preview-app/src/app/page.tsx +94 -0
- package/assets/preview-app/src/app/providers.tsx +16 -0
- package/assets/preview-app/tsconfig.json +27 -0
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.doc.mjs +2 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.doc.mjs +2 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider03RtlDirection.doc.mjs +2 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider04Calendar.doc.mjs +2 -1
- package/assets/templates/blocks/components/Text/useTruncationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Text/useTruncationHookUsage.tsx +112 -0
- package/authoring/doctypes/_schema.d.mts +1 -0
- package/authoring/doctypes/_schema.mjs +1 -0
- package/authoring/doctypes/command/command.doc.mjs +7 -0
- package/authoring/doctypes/command/type.ts +3 -0
- package/authoring/doctypes/icon-set/parse.d.mts +7 -0
- package/authoring/doctypes/icon-set/parse.mjs +18 -8
- package/clients/cli/commands/doctor.mjs +33 -3
- package/clients/cli/commands/experimental/icon.mjs +67 -14
- package/clients/cli/commands/experimental/index.mjs +2 -0
- package/clients/cli/commands/experimental/theme.mjs +684 -0
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +7 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +3 -2
- package/clients/cli/commands/experimental-theme-add.doc.mjs +78 -0
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +97 -0
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +84 -0
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +66 -0
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +121 -0
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +66 -0
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +104 -0
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +49 -0
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +71 -0
- package/clients/cli/commands/experimental-theme-list.doc.mjs +49 -0
- package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +73 -0
- package/clients/cli/commands/experimental-theme-palette.doc.mjs +37 -0
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +86 -0
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +66 -0
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +48 -0
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +59 -0
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +40 -0
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +55 -0
- package/clients/cli/commands/experimental-theme-targets.doc.mjs +61 -0
- package/clients/cli/commands/experimental-theme-template.doc.mjs +61 -0
- package/clients/cli/commands/experimental-theme-use.doc.mjs +55 -0
- package/clients/cli/commands/experimental-theme.doc.mjs +57 -0
- package/clients/cli/commands/experimental.doc.mjs +10 -3
- package/clients/cli/commands/theme.mjs +101 -34
- package/clients/cli/index.mjs +18 -0
- package/clients/cli/lib/define-command.mjs +3 -0
- package/foundation/discovery/icon-set-checks.d.mts +16 -1
- package/foundation/discovery/icon-set-checks.mjs +68 -7
- package/foundation/discovery/icon-set-discovery.d.mts +21 -6
- package/foundation/discovery/icon-set-discovery.mjs +17 -8
- package/foundation/discovery/template-icon-meanings.d.mts +39 -0
- package/foundation/discovery/template-icon-meanings.mjs +95 -0
- package/foundation/discovery/theming-targets.d.mts +6 -0
- package/foundation/discovery/theming-targets.mjs +33 -0
- package/foundation/response/error-codes.d.mts +12 -1
- package/foundation/response/error-codes.doc.mjs +66 -0
- package/foundation/response/error-codes.mjs +55 -0
- package/foundation/response/response-types.doc.mjs +55 -0
- package/foundation/text/template-meanings-line.d.mts +16 -0
- package/foundation/text/template-meanings-line.mjs +37 -0
- package/foundation/xle/browser.d.mts +2 -2
- package/package.json +6 -6
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The RGB of a hex, rgb() or named color, or null for anything else.
|
|
6
|
+
* @param {unknown} value
|
|
7
|
+
* @returns {Rgb | null}
|
|
8
|
+
*/
|
|
9
|
+
export function parseColor(value: unknown): Rgb | null;
|
|
10
|
+
/**
|
|
11
|
+
* The WCAG contrast ratio of two colors.
|
|
12
|
+
* @param {number[]} a
|
|
13
|
+
* @param {number[]} b
|
|
14
|
+
*/
|
|
15
|
+
export function ratio(a: number[], b: number[]): number;
|
|
16
|
+
/**
|
|
17
|
+
* The tokens one accent color sets. The color itself stays exact; accent
|
|
18
|
+
* text is darkened (light) or lightened (dark) until it reads at 4.5:1.
|
|
19
|
+
* A pair is `[light, dark]`.
|
|
20
|
+
* @param {string} value
|
|
21
|
+
* @returns {Record<string, string | [string, string]>}
|
|
22
|
+
*/
|
|
23
|
+
export function accentSet(value: string): Record<string, string | [string, string]>;
|
|
24
|
+
export function hex(rgb: number[]): string;
|
|
25
|
+
export function mix(a: number[], b: number[], t: number): Rgb;
|
|
26
|
+
export function isColorValue(v: unknown): boolean;
|
|
27
|
+
export function isSize(v: unknown): boolean;
|
|
28
|
+
export function isNumber(v: unknown): boolean;
|
|
29
|
+
export type Rgb = [number, number, number];
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Color math for `astryx experimental theme`: parse a CSS color to RGB,
|
|
5
|
+
* contrast ratios, mixing, value type checks, and the accent derivation.
|
|
6
|
+
* @position api/theme-edit — pure helpers
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** @typedef {[number, number, number]} Rgb */
|
|
10
|
+
|
|
11
|
+
/** The CSS named colors. */
|
|
12
|
+
const NAMED = /** @type {Record<string, string>} */ ({
|
|
13
|
+
aliceblue: '#f0f8ff',
|
|
14
|
+
antiquewhite: '#faebd7',
|
|
15
|
+
aqua: '#00ffff',
|
|
16
|
+
aquamarine: '#7fffd4',
|
|
17
|
+
azure: '#f0ffff',
|
|
18
|
+
beige: '#f5f5dc',
|
|
19
|
+
bisque: '#ffe4c4',
|
|
20
|
+
black: '#000000',
|
|
21
|
+
blanchedalmond: '#ffebcd',
|
|
22
|
+
blue: '#0000ff',
|
|
23
|
+
blueviolet: '#8a2be2',
|
|
24
|
+
brown: '#a52a2a',
|
|
25
|
+
burlywood: '#deb887',
|
|
26
|
+
cadetblue: '#5f9ea0',
|
|
27
|
+
chartreuse: '#7fff00',
|
|
28
|
+
chocolate: '#d2691e',
|
|
29
|
+
coral: '#ff7f50',
|
|
30
|
+
cornflowerblue: '#6495ed',
|
|
31
|
+
cornsilk: '#fff8dc',
|
|
32
|
+
crimson: '#dc143c',
|
|
33
|
+
cyan: '#00ffff',
|
|
34
|
+
darkblue: '#00008b',
|
|
35
|
+
darkcyan: '#008b8b',
|
|
36
|
+
darkgoldenrod: '#b8860b',
|
|
37
|
+
darkgray: '#a9a9a9',
|
|
38
|
+
darkgreen: '#006400',
|
|
39
|
+
darkgrey: '#a9a9a9',
|
|
40
|
+
darkkhaki: '#bdb76b',
|
|
41
|
+
darkmagenta: '#8b008b',
|
|
42
|
+
darkolivegreen: '#556b2f',
|
|
43
|
+
darkorange: '#ff8c00',
|
|
44
|
+
darkorchid: '#9932cc',
|
|
45
|
+
darkred: '#8b0000',
|
|
46
|
+
darksalmon: '#e9967a',
|
|
47
|
+
darkseagreen: '#8fbc8f',
|
|
48
|
+
darkslateblue: '#483d8b',
|
|
49
|
+
darkslategray: '#2f4f4f',
|
|
50
|
+
darkslategrey: '#2f4f4f',
|
|
51
|
+
darkturquoise: '#00ced1',
|
|
52
|
+
darkviolet: '#9400d3',
|
|
53
|
+
deeppink: '#ff1493',
|
|
54
|
+
deepskyblue: '#00bfff',
|
|
55
|
+
dimgray: '#696969',
|
|
56
|
+
dimgrey: '#696969',
|
|
57
|
+
dodgerblue: '#1e90ff',
|
|
58
|
+
firebrick: '#b22222',
|
|
59
|
+
floralwhite: '#fffaf0',
|
|
60
|
+
forestgreen: '#228b22',
|
|
61
|
+
fuchsia: '#ff00ff',
|
|
62
|
+
gainsboro: '#dcdcdc',
|
|
63
|
+
ghostwhite: '#f8f8ff',
|
|
64
|
+
gold: '#ffd700',
|
|
65
|
+
goldenrod: '#daa520',
|
|
66
|
+
gray: '#808080',
|
|
67
|
+
green: '#008000',
|
|
68
|
+
greenyellow: '#adff2f',
|
|
69
|
+
grey: '#808080',
|
|
70
|
+
honeydew: '#f0fff0',
|
|
71
|
+
hotpink: '#ff69b4',
|
|
72
|
+
indianred: '#cd5c5c',
|
|
73
|
+
indigo: '#4b0082',
|
|
74
|
+
ivory: '#fffff0',
|
|
75
|
+
khaki: '#f0e68c',
|
|
76
|
+
lavender: '#e6e6fa',
|
|
77
|
+
lavenderblush: '#fff0f5',
|
|
78
|
+
lawngreen: '#7cfc00',
|
|
79
|
+
lemonchiffon: '#fffacd',
|
|
80
|
+
lightblue: '#add8e6',
|
|
81
|
+
lightcoral: '#f08080',
|
|
82
|
+
lightcyan: '#e0ffff',
|
|
83
|
+
lightgoldenrodyellow: '#fafad2',
|
|
84
|
+
lightgray: '#d3d3d3',
|
|
85
|
+
lightgreen: '#90ee90',
|
|
86
|
+
lightgrey: '#d3d3d3',
|
|
87
|
+
lightpink: '#ffb6c1',
|
|
88
|
+
lightsalmon: '#ffa07a',
|
|
89
|
+
lightseagreen: '#20b2aa',
|
|
90
|
+
lightskyblue: '#87cefa',
|
|
91
|
+
lightslategray: '#778899',
|
|
92
|
+
lightslategrey: '#778899',
|
|
93
|
+
lightsteelblue: '#b0c4de',
|
|
94
|
+
lightyellow: '#ffffe0',
|
|
95
|
+
lime: '#00ff00',
|
|
96
|
+
limegreen: '#32cd32',
|
|
97
|
+
linen: '#faf0e6',
|
|
98
|
+
magenta: '#ff00ff',
|
|
99
|
+
maroon: '#800000',
|
|
100
|
+
mediumaquamarine: '#66cdaa',
|
|
101
|
+
mediumblue: '#0000cd',
|
|
102
|
+
mediumorchid: '#ba55d3',
|
|
103
|
+
mediumpurple: '#9370db',
|
|
104
|
+
mediumseagreen: '#3cb371',
|
|
105
|
+
mediumslateblue: '#7b68ee',
|
|
106
|
+
mediumspringgreen: '#00fa9a',
|
|
107
|
+
mediumturquoise: '#48d1cc',
|
|
108
|
+
mediumvioletred: '#c71585',
|
|
109
|
+
midnightblue: '#191970',
|
|
110
|
+
mintcream: '#f5fffa',
|
|
111
|
+
mistyrose: '#ffe4e1',
|
|
112
|
+
moccasin: '#ffe4b5',
|
|
113
|
+
navajowhite: '#ffdead',
|
|
114
|
+
navy: '#000080',
|
|
115
|
+
oldlace: '#fdf5e6',
|
|
116
|
+
olive: '#808000',
|
|
117
|
+
olivedrab: '#6b8e23',
|
|
118
|
+
orange: '#ffa500',
|
|
119
|
+
orangered: '#ff4500',
|
|
120
|
+
orchid: '#da70d6',
|
|
121
|
+
palegoldenrod: '#eee8aa',
|
|
122
|
+
palegreen: '#98fb98',
|
|
123
|
+
paleturquoise: '#afeeee',
|
|
124
|
+
palevioletred: '#db7093',
|
|
125
|
+
papayawhip: '#ffefd5',
|
|
126
|
+
peachpuff: '#ffdab9',
|
|
127
|
+
peru: '#cd853f',
|
|
128
|
+
pink: '#ffc0cb',
|
|
129
|
+
plum: '#dda0dd',
|
|
130
|
+
powderblue: '#b0e0e6',
|
|
131
|
+
purple: '#800080',
|
|
132
|
+
rebeccapurple: '#663399',
|
|
133
|
+
red: '#ff0000',
|
|
134
|
+
rosybrown: '#bc8f8f',
|
|
135
|
+
royalblue: '#4169e1',
|
|
136
|
+
saddlebrown: '#8b4513',
|
|
137
|
+
salmon: '#fa8072',
|
|
138
|
+
sandybrown: '#f4a460',
|
|
139
|
+
seagreen: '#2e8b57',
|
|
140
|
+
seashell: '#fff5ee',
|
|
141
|
+
sienna: '#a0522d',
|
|
142
|
+
silver: '#c0c0c0',
|
|
143
|
+
skyblue: '#87ceeb',
|
|
144
|
+
slateblue: '#6a5acd',
|
|
145
|
+
slategray: '#708090',
|
|
146
|
+
slategrey: '#708090',
|
|
147
|
+
snow: '#fffafa',
|
|
148
|
+
springgreen: '#00ff7f',
|
|
149
|
+
steelblue: '#4682b4',
|
|
150
|
+
tan: '#d2b48c',
|
|
151
|
+
teal: '#008080',
|
|
152
|
+
thistle: '#d8bfd8',
|
|
153
|
+
tomato: '#ff6347',
|
|
154
|
+
turquoise: '#40e0d0',
|
|
155
|
+
violet: '#ee82ee',
|
|
156
|
+
wheat: '#f5deb3',
|
|
157
|
+
white: '#ffffff',
|
|
158
|
+
whitesmoke: '#f5f5f5',
|
|
159
|
+
yellow: '#ffff00',
|
|
160
|
+
yellowgreen: '#9acd32',
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
/** Color keywords that are valid colors but have no fixed value. */
|
|
164
|
+
const KEYWORDS = [
|
|
165
|
+
'transparent',
|
|
166
|
+
'currentcolor',
|
|
167
|
+
'inherit',
|
|
168
|
+
'initial',
|
|
169
|
+
'unset',
|
|
170
|
+
'revert',
|
|
171
|
+
];
|
|
172
|
+
|
|
173
|
+
/** The CSS color functions. */
|
|
174
|
+
const FUNCTIONS =
|
|
175
|
+
/^(rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color|color-mix|light-dark)\(.+\)$/i;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The RGB of a hex, rgb() or named color, or null for anything else.
|
|
179
|
+
* @param {unknown} value
|
|
180
|
+
* @returns {Rgb | null}
|
|
181
|
+
*/
|
|
182
|
+
export function parseColor(value) {
|
|
183
|
+
const s = String(value ?? '').trim();
|
|
184
|
+
let m = /^#([0-9a-f]{3}|[0-9a-f]{6})([0-9a-f]{2})?$/i.exec(s);
|
|
185
|
+
if (m) {
|
|
186
|
+
let h = m[1];
|
|
187
|
+
if (h.length === 3) h = [...h].map(c => c + c).join('');
|
|
188
|
+
const n = parseInt(h, 16);
|
|
189
|
+
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
190
|
+
}
|
|
191
|
+
m = /^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/i.exec(s);
|
|
192
|
+
if (m) return [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
193
|
+
const named = NAMED[s.toLowerCase()];
|
|
194
|
+
return named ? parseColor(named) : null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** @param {number[]} rgb */
|
|
198
|
+
export const hex = rgb =>
|
|
199
|
+
`#${rgb
|
|
200
|
+
.slice(0, 3)
|
|
201
|
+
.map(x =>
|
|
202
|
+
Math.round(Math.max(0, Math.min(255, x)))
|
|
203
|
+
.toString(16)
|
|
204
|
+
.padStart(2, '0'),
|
|
205
|
+
)
|
|
206
|
+
.join('')}`;
|
|
207
|
+
|
|
208
|
+
/** @param {number[]} rgb */
|
|
209
|
+
const luminance = ([r, g, b]) => {
|
|
210
|
+
/** @param {number} c */
|
|
211
|
+
const f = c => {
|
|
212
|
+
const v = c / 255;
|
|
213
|
+
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
214
|
+
};
|
|
215
|
+
return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The WCAG contrast ratio of two colors.
|
|
220
|
+
* @param {number[]} a
|
|
221
|
+
* @param {number[]} b
|
|
222
|
+
*/
|
|
223
|
+
export function ratio(a, b) {
|
|
224
|
+
const [x, y] = [luminance(a), luminance(b)].sort((p, q) => q - p);
|
|
225
|
+
return (x + 0.05) / (y + 0.05);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @param {number[]} a
|
|
230
|
+
* @param {number[]} b
|
|
231
|
+
* @param {number} t 0 gives a, 1 gives b
|
|
232
|
+
* @returns {Rgb}
|
|
233
|
+
*/
|
|
234
|
+
export const mix = (a, b, t) => [
|
|
235
|
+
a[0] + (b[0] - a[0]) * t,
|
|
236
|
+
a[1] + (b[1] - a[1]) * t,
|
|
237
|
+
a[2] + (b[2] - a[2]) * t,
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Whether a value is one CSS color: a hex, a color function, a named color,
|
|
242
|
+
* a color keyword, or a variable.
|
|
243
|
+
* @param {unknown} v
|
|
244
|
+
*/
|
|
245
|
+
export const isColorValue = v => {
|
|
246
|
+
const s = String(v).trim();
|
|
247
|
+
return (
|
|
248
|
+
/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(s) ||
|
|
249
|
+
FUNCTIONS.test(s) ||
|
|
250
|
+
/^var\(--[a-z0-9-]+\)$/i.test(s) ||
|
|
251
|
+
Object.hasOwn(NAMED, s.toLowerCase()) ||
|
|
252
|
+
KEYWORDS.includes(s.toLowerCase())
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/** Whether a value reads as one CSS size. @param {unknown} v */
|
|
257
|
+
export const isSize = v =>
|
|
258
|
+
/^(-?\d*\.?\d+(px|rem|em|%|vh|vw)?|0|var\(--[a-z0-9-]+\)|calc\(.+\))$/i.test(
|
|
259
|
+
String(v).trim(),
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
/** Whether a value reads as a number. @param {unknown} v */
|
|
263
|
+
export const isNumber = v => /^-?\d*\.?\d+$|^var\(/.test(String(v).trim());
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* The tokens one accent color sets. The color itself stays exact; accent
|
|
267
|
+
* text is darkened (light) or lightened (dark) until it reads at 4.5:1.
|
|
268
|
+
* A pair is `[light, dark]`.
|
|
269
|
+
* @param {string} value
|
|
270
|
+
* @returns {Record<string, string | [string, string]>}
|
|
271
|
+
*/
|
|
272
|
+
export function accentSet(value) {
|
|
273
|
+
const c = parseColor(value);
|
|
274
|
+
if (!c)
|
|
275
|
+
return {
|
|
276
|
+
'--color-accent': value,
|
|
277
|
+
'--color-icon-accent': value,
|
|
278
|
+
'--color-text-accent': value,
|
|
279
|
+
};
|
|
280
|
+
/** @type {Rgb} */
|
|
281
|
+
const white = [255, 255, 255];
|
|
282
|
+
/** @type {Rgb} */
|
|
283
|
+
const black = [0, 0, 0];
|
|
284
|
+
/** @type {Rgb} */
|
|
285
|
+
const darkCard = [31, 31, 34];
|
|
286
|
+
let text = c;
|
|
287
|
+
for (let i = 0; i < 20 && ratio(text, white) < 4.5; i++)
|
|
288
|
+
text = mix(text, black, 0.08);
|
|
289
|
+
let darkText = c;
|
|
290
|
+
for (let i = 0; i < 20 && ratio(darkText, darkCard) < 4.5; i++)
|
|
291
|
+
darkText = mix(darkText, white, 0.08);
|
|
292
|
+
return {
|
|
293
|
+
'--color-accent': value,
|
|
294
|
+
'--color-text-accent': [hex(text), hex(darkText)],
|
|
295
|
+
'--color-icon-accent': [value, hex(darkText)],
|
|
296
|
+
'--color-accent-muted': [hex(mix(c, white, 0.85)), hex(mix(c, black, 0.7))],
|
|
297
|
+
'--color-on-accent':
|
|
298
|
+
ratio(c, white) >= ratio(c, [17, 17, 17]) ? '#ffffff' : '#111111',
|
|
299
|
+
};
|
|
300
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/** @typedef {{token: string, props: string[], when: string[]}} Read */
|
|
5
|
+
/** @typedef {{message: string, run: string[], also: string[], soft?: boolean}} CheckFailure */
|
|
6
|
+
/**
|
|
7
|
+
* @param {import('./_project.mjs').ThemeProject} project
|
|
8
|
+
* @param {import('./_parts.mjs').PartData} parts
|
|
9
|
+
*/
|
|
10
|
+
export function makeCompiler(project: import("./_project.mjs").ThemeProject, parts: import("./_parts.mjs").PartData): {
|
|
11
|
+
MAP: Record<string, import("./_parts.mjs").PartRecord>;
|
|
12
|
+
typeOf: (tok: string) => string;
|
|
13
|
+
feeds: (target: string, token: string) => Array<{
|
|
14
|
+
part: string;
|
|
15
|
+
prop: string;
|
|
16
|
+
when: string;
|
|
17
|
+
}>;
|
|
18
|
+
fmtFeeds: (list: ReturnType<(target: string, token: string) => Array<{
|
|
19
|
+
part: string;
|
|
20
|
+
prop: string;
|
|
21
|
+
when: string;
|
|
22
|
+
}>>) => string;
|
|
23
|
+
showsCorners: (target: string) => boolean;
|
|
24
|
+
groupOfToken: (t: string) => string | null;
|
|
25
|
+
groupOfProp: (p: string) => string | null;
|
|
26
|
+
partReads: (target: string, group: string | null) => Read[];
|
|
27
|
+
fmtWhen: (w: string[]) => string;
|
|
28
|
+
statusNote: (target: string, tok: string) => string;
|
|
29
|
+
allReads: (target: string) => Set<string>;
|
|
30
|
+
anyReader: (tok: string) => string[];
|
|
31
|
+
checkTokenOn: (theme: string, target: string, token: string, value: string, P: string) => CheckFailure | null;
|
|
32
|
+
checkTokenGlobal: (token: string, P: string) => CheckFailure | null;
|
|
33
|
+
variantValues: (target: string) => Record<string, string[]>;
|
|
34
|
+
explain: (target: string, P: string, theme?: string) => string[];
|
|
35
|
+
contrast: (value: (pair: import("./_parts.mjs").TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, baseValue: (pair: import("./_parts.mjs").TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, modes: string[], { parseColor, ratio }: {
|
|
36
|
+
parseColor: (v: unknown) => number[] | null;
|
|
37
|
+
ratio: (a: number[], b: number[]) => number;
|
|
38
|
+
}) => {
|
|
39
|
+
part: string;
|
|
40
|
+
mode: string;
|
|
41
|
+
ratio: number;
|
|
42
|
+
sample: string;
|
|
43
|
+
fg: string;
|
|
44
|
+
bgPart: string | null;
|
|
45
|
+
bg: string;
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
/** Only these token types may differ between light and dark. */
|
|
49
|
+
export const MODAL: Set<string>;
|
|
50
|
+
export type Read = {
|
|
51
|
+
token: string;
|
|
52
|
+
props: string[];
|
|
53
|
+
when: string[];
|
|
54
|
+
};
|
|
55
|
+
export type CheckFailure = {
|
|
56
|
+
message: string;
|
|
57
|
+
run: string[];
|
|
58
|
+
also: string[];
|
|
59
|
+
soft?: boolean;
|
|
60
|
+
};
|
|
61
|
+
export type Compiler = ReturnType<typeof makeCompiler>;
|