@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,522 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The type checker behind `astryx experimental theme`: the type of
|
|
5
|
+
* every token (from Core's own token groups), what each part reads (from the
|
|
6
|
+
* part data), and the checks that refuse a change that cannot take effect.
|
|
7
|
+
* Also `how` lookups, and contrast problems the theme caused versus its base.
|
|
8
|
+
*
|
|
9
|
+
* @position api/theme-edit — compile-time knowledge over the part data
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import {DIRECT, GROUPS, HOW} from './_tables.mjs';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Whether a color is see-through: its contrast depends on what is under it,
|
|
16
|
+
* so it is not judged alone.
|
|
17
|
+
* @param {unknown} v
|
|
18
|
+
*/
|
|
19
|
+
function hasAlpha(v) {
|
|
20
|
+
const s = String(v ?? '').trim();
|
|
21
|
+
const h = /^#(?:[0-9a-f]{4}|[0-9a-f]{8})$/i.exec(s);
|
|
22
|
+
if (h) return s.length === 5 ? !/f$/i.test(s) : !/ff$/i.test(s);
|
|
23
|
+
const m = /\/\s*([\d.]+%?)\s*\)$|^rgba\([^)]*,\s*([\d.]+)\s*\)$/i.exec(s);
|
|
24
|
+
if (!m) return /^transparent$/i.test(s);
|
|
25
|
+
const a = m[1] ?? m[2];
|
|
26
|
+
return a.endsWith('%') ? parseFloat(a) < 100 : parseFloat(a) < 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Only these token types may differ between light and dark. */
|
|
30
|
+
export const MODAL = new Set(['color', 'shadow']);
|
|
31
|
+
|
|
32
|
+
/** Tokens a component may read only in some states: never refused globally. */
|
|
33
|
+
const SOFT = /^--(color-data|syntax|duration|ease|z-|layer|breakpoint)/;
|
|
34
|
+
|
|
35
|
+
/** @typedef {{token: string, props: string[], when: string[]}} Read */
|
|
36
|
+
/** @typedef {{message: string, run: string[], also: string[], soft?: boolean}} CheckFailure */
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {import('./_project.mjs').ThemeProject} project
|
|
40
|
+
* @param {import('./_parts.mjs').PartData} parts
|
|
41
|
+
*/
|
|
42
|
+
export function makeCompiler(project, parts) {
|
|
43
|
+
const {core} = project;
|
|
44
|
+
const MAP = parts.map;
|
|
45
|
+
const TARGET = project.target;
|
|
46
|
+
|
|
47
|
+
/** @type {Record<string, string>} */
|
|
48
|
+
const TYPE = {};
|
|
49
|
+
/** @param {unknown} obj */
|
|
50
|
+
const groupVars = obj =>
|
|
51
|
+
Object.values(/** @type {Record<string, unknown>} */ (obj ?? {}))
|
|
52
|
+
.map(v => /var\((--[a-zA-Z0-9-]+)/.exec(String(v))?.[1])
|
|
53
|
+
.filter(/** @returns {v is string} */ v => Boolean(v));
|
|
54
|
+
/** @param {string[]} list @param {string} type */
|
|
55
|
+
const put = (list, type) => {
|
|
56
|
+
for (const k of list) TYPE[k] ??= type;
|
|
57
|
+
};
|
|
58
|
+
put(groupVars(core.colorVars), 'color');
|
|
59
|
+
put(groupVars(core.shadowVars), 'shadow');
|
|
60
|
+
put(groupVars(core.radiusVars), 'size');
|
|
61
|
+
put(groupVars(core.spacingVars), 'size');
|
|
62
|
+
put(groupVars(core.sizeVars), 'size');
|
|
63
|
+
put(groupVars(core.textSizeVars), 'size');
|
|
64
|
+
put(groupVars(core.borderVars), 'size');
|
|
65
|
+
put(groupVars(core.fontWeightVars), 'number');
|
|
66
|
+
put(groupVars(core.durationVars), 'time');
|
|
67
|
+
put(groupVars(core.easeVars), 'easing');
|
|
68
|
+
for (const k of Object.keys(core.tokenDefaults ?? {})) {
|
|
69
|
+
if (TYPE[k]) continue;
|
|
70
|
+
if (/^--color-|^--syntax-/.test(k)) TYPE[k] = 'color';
|
|
71
|
+
else if (/^--font-family/.test(k)) TYPE[k] = 'font';
|
|
72
|
+
else if (/^--font-weight/.test(k)) TYPE[k] = 'number';
|
|
73
|
+
else if (/^--shadow/.test(k)) TYPE[k] = 'shadow';
|
|
74
|
+
else if (/^--focus-outline-color/.test(k)) TYPE[k] = 'color';
|
|
75
|
+
else if (
|
|
76
|
+
/^--(radius|spacing|size|text-.*-size|border-width|focus-outline-(width|offset))/.test(
|
|
77
|
+
k,
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
TYPE[k] = 'size';
|
|
81
|
+
else if (/leading|line-height/.test(k)) TYPE[k] = 'number';
|
|
82
|
+
else TYPE[k] = 'other';
|
|
83
|
+
}
|
|
84
|
+
/** @param {string} tok */
|
|
85
|
+
const typeOf = tok => TYPE[tok] ?? 'other';
|
|
86
|
+
|
|
87
|
+
/** @param {string} p */
|
|
88
|
+
const groupOfProp = p =>
|
|
89
|
+
Object.entries(GROUPS).find(([, ps]) => ps.includes(p))?.[0] ?? null;
|
|
90
|
+
|
|
91
|
+
/** @param {string} t @returns {string | null} */
|
|
92
|
+
function groupOfToken(t) {
|
|
93
|
+
if (/^--color-(text|on|icon)-/.test(t) || t === '--color-on-accent')
|
|
94
|
+
return 'text';
|
|
95
|
+
if (/^--color-border/.test(t)) return 'border';
|
|
96
|
+
if (/^--color-shadow$|^--shadow-/.test(t)) return 'shadow';
|
|
97
|
+
if (/^--color-/.test(t)) return 'background';
|
|
98
|
+
if (/^--radius-/.test(t)) return 'corners';
|
|
99
|
+
if (/^--spacing-/.test(t)) return 'spacing';
|
|
100
|
+
if (/^--(font|text)-/.test(t)) return 'font';
|
|
101
|
+
if (/^--size-/.test(t)) return 'size';
|
|
102
|
+
if (/^--border-width/.test(t)) return 'border';
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** A condition, kept to what a person can act on. @param {string} target @param {string} cond */
|
|
107
|
+
function shortCond(target, cond) {
|
|
108
|
+
if (cond === 'always') return '';
|
|
109
|
+
const attrs = MAP[target]?.attrs ?? {};
|
|
110
|
+
const [attrPart, ...css] = cond.split(' ');
|
|
111
|
+
const kept = (attrPart.includes('=') ? attrPart.split(',') : []).filter(
|
|
112
|
+
kv => {
|
|
113
|
+
const [k] = kv.split('=');
|
|
114
|
+
return (
|
|
115
|
+
k === 'selected' ||
|
|
116
|
+
(['variant', 'status', 'tone', 'color'].includes(k) &&
|
|
117
|
+
(attrs[k]?.length ?? 0) > 1)
|
|
118
|
+
);
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
const cssPart = (attrPart.includes('=') ? css : [attrPart, ...css])
|
|
122
|
+
.join(' ')
|
|
123
|
+
.replace(/\[data-astryx-press="[a-z]+"\]/g, ':active')
|
|
124
|
+
.trim();
|
|
125
|
+
return [...kept, cssPart].filter(Boolean).join(' ');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The tokens a part reads for one aspect (or every aspect), each with the
|
|
130
|
+
* properties and conditions it applies under; unconditional reads first.
|
|
131
|
+
* @param {string} target
|
|
132
|
+
* @param {string | null} group
|
|
133
|
+
* @returns {Read[]}
|
|
134
|
+
*/
|
|
135
|
+
function partReads(target, group) {
|
|
136
|
+
const own = MAP[target]?.own ?? {};
|
|
137
|
+
/** @type {Map<string, {token: string, props: Set<string>, when: Set<string>}>} */
|
|
138
|
+
const out = new Map();
|
|
139
|
+
for (const [prop, v] of Object.entries(own)) {
|
|
140
|
+
if (group && groupOfProp(prop) !== group) continue;
|
|
141
|
+
for (const [tok, conds] of Object.entries(v.tokens)) {
|
|
142
|
+
const e = out.get(tok) ?? {
|
|
143
|
+
token: tok,
|
|
144
|
+
props: new Set(),
|
|
145
|
+
when: new Set(),
|
|
146
|
+
};
|
|
147
|
+
e.props.add(prop);
|
|
148
|
+
for (const c of conds) e.when.add(shortCond(target, c));
|
|
149
|
+
out.set(tok, e);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return [...out.values()]
|
|
153
|
+
.map(e => ({token: e.token, props: [...e.props], when: [...e.when]}))
|
|
154
|
+
.sort(
|
|
155
|
+
(a, b) => (b.when.includes('') ? 1 : 0) - (a.when.includes('') ? 1 : 0),
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const STATUS = /-(info|success|warning|error)(-|$)/;
|
|
160
|
+
/** @param {string} target @param {string} tok */
|
|
161
|
+
const statusNote = (target, tok) =>
|
|
162
|
+
STATUS.test(tok) && (TARGET.get(target)?.props ?? []).includes('status')
|
|
163
|
+
? ` [status ${tok.match(STATUS)?.[1]}; other statuses: same name with success|warning|error]`
|
|
164
|
+
: '';
|
|
165
|
+
/** @param {string[]} w */
|
|
166
|
+
const fmtWhen = w =>
|
|
167
|
+
w.includes('') || !w.length
|
|
168
|
+
? ''
|
|
169
|
+
: ` (when ${w.filter(Boolean).slice(0, 3).join(' | ')}${w.length > 3 ? ' | ...' : ''})`;
|
|
170
|
+
|
|
171
|
+
/** Every token the part or anything inside it reads. @param {string} target */
|
|
172
|
+
function allReads(target) {
|
|
173
|
+
/** @type {Set<string>} */
|
|
174
|
+
const s = new Set();
|
|
175
|
+
/** @param {string} t */
|
|
176
|
+
const add = t => {
|
|
177
|
+
for (const v of Object.values(MAP[t]?.own ?? {}))
|
|
178
|
+
for (const k of Object.keys(v.tokens)) s.add(k);
|
|
179
|
+
for (const k of Object.keys(MAP[t]?.inside ?? {})) s.add(k);
|
|
180
|
+
};
|
|
181
|
+
add(target);
|
|
182
|
+
for (const c of MAP[target]?.contains ?? []) add(c);
|
|
183
|
+
return s;
|
|
184
|
+
}
|
|
185
|
+
/** @type {Map<string, string[]>} */
|
|
186
|
+
const readersCache = new Map();
|
|
187
|
+
/** The parts that read a token anywhere. @param {string} tok */
|
|
188
|
+
const anyReader = tok => {
|
|
189
|
+
let r = readersCache.get(tok);
|
|
190
|
+
if (!r) {
|
|
191
|
+
r = Object.keys(MAP).filter(
|
|
192
|
+
t =>
|
|
193
|
+
Object.values(MAP[t].own).some(v => tok in v.tokens) ||
|
|
194
|
+
tok in (MAP[t].inside ?? {}),
|
|
195
|
+
);
|
|
196
|
+
readersCache.set(tok, r);
|
|
197
|
+
}
|
|
198
|
+
return r;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Where a token feeds a part: each property of the part (or of an element
|
|
203
|
+
* or part inside it) that reads it, with its condition.
|
|
204
|
+
* @param {string} target
|
|
205
|
+
* @param {string} token
|
|
206
|
+
* @returns {Array<{part: string, prop: string, when: string}>}
|
|
207
|
+
*/
|
|
208
|
+
function feeds(target, token) {
|
|
209
|
+
/** @type {Array<{part: string, prop: string, when: string}>} */
|
|
210
|
+
const out = [];
|
|
211
|
+
for (const t of [target, ...(MAP[target]?.contains ?? [])]) {
|
|
212
|
+
for (const [prop, v] of Object.entries(MAP[t]?.own ?? {})) {
|
|
213
|
+
for (const c of v.tokens[token] ?? [])
|
|
214
|
+
out.push({part: t, prop, when: shortCond(t, c)});
|
|
215
|
+
}
|
|
216
|
+
for (const prop of MAP[t]?.inside?.[token] ?? [])
|
|
217
|
+
out.push({part: t, prop, when: ''});
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** One line for where a token feeds. @param {ReturnType<typeof feeds>} list */
|
|
223
|
+
const fmtFeeds = list =>
|
|
224
|
+
[
|
|
225
|
+
...new Set(
|
|
226
|
+
list.map(
|
|
227
|
+
f =>
|
|
228
|
+
`${f.prop}${f.part ? ` on ${f.part}` : ''}${f.when ? ` (when ${f.when})` : ''}`,
|
|
229
|
+
),
|
|
230
|
+
),
|
|
231
|
+
]
|
|
232
|
+
.slice(0, 4)
|
|
233
|
+
.join(', ');
|
|
234
|
+
|
|
235
|
+
/** @param {string} v */
|
|
236
|
+
const quote = v => (/[\s"#(]/.test(v) ? `"${v.replace(/"/g, '\\"')}"` : v);
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Whether a token set on a part can take effect there: the part, or a part
|
|
240
|
+
* inside it, must read it. A part with no record is checked through the
|
|
241
|
+
* parts that contain it, else reported unchecked (soft).
|
|
242
|
+
* @param {string} theme
|
|
243
|
+
* @param {string} target
|
|
244
|
+
* @param {string} token
|
|
245
|
+
* @param {string} value
|
|
246
|
+
* @param {string} P
|
|
247
|
+
* @returns {CheckFailure | null}
|
|
248
|
+
*/
|
|
249
|
+
function checkTokenOn(theme, target, token, value, P) {
|
|
250
|
+
if (!MAP[target]) {
|
|
251
|
+
return {
|
|
252
|
+
soft: true,
|
|
253
|
+
message: `There is no compiled record of what ${target} reads (it did not render in the catalog), so this change could not be checked.`,
|
|
254
|
+
run: [],
|
|
255
|
+
also: [],
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
const g = groupOfToken(token);
|
|
259
|
+
if (allReads(target).has(token)) {
|
|
260
|
+
// Read, but maybe only for another property: an error color that feeds
|
|
261
|
+
// only the focus outline does not paint the background.
|
|
262
|
+
const fed = feeds(target, token);
|
|
263
|
+
const wanted =
|
|
264
|
+
g === 'text'
|
|
265
|
+
? ['color', 'fill']
|
|
266
|
+
: g === 'background'
|
|
267
|
+
? ['background-color', 'background', 'background-image']
|
|
268
|
+
: null;
|
|
269
|
+
if (!wanted || !fed.length || fed.some(f => wanted.includes(f.prop)))
|
|
270
|
+
return null;
|
|
271
|
+
const direct = g === 'text' ? 'color' : 'background-color';
|
|
272
|
+
return {
|
|
273
|
+
message: `${target} reads ${token} only for ${fmtFeeds(fed)}, not for its ${g}, so this would not change what you expect.`,
|
|
274
|
+
run: [
|
|
275
|
+
`${P} set ${theme} ${direct} ${quote(value)} --on ${target} # sets its ${g} directly`,
|
|
276
|
+
`${HOW} ${target}`,
|
|
277
|
+
],
|
|
278
|
+
also: [],
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
const reads = g ? partReads(target, g) : [];
|
|
282
|
+
const v = quote(value);
|
|
283
|
+
/** @type {string[]} */
|
|
284
|
+
const run = [];
|
|
285
|
+
if (reads.length)
|
|
286
|
+
run.push(
|
|
287
|
+
...reads
|
|
288
|
+
.slice(0, 3)
|
|
289
|
+
.map(
|
|
290
|
+
r =>
|
|
291
|
+
`${P} set ${theme} ${r.token} ${v} --on ${target}${fmtWhen(r.when) ? ` #${fmtWhen(r.when)}` : ''}`,
|
|
292
|
+
),
|
|
293
|
+
);
|
|
294
|
+
if (g && DIRECT[g])
|
|
295
|
+
run.push(
|
|
296
|
+
`${P} set ${theme} ${DIRECT[g]} ${v} --on ${target} # sets it directly, whatever token it uses`,
|
|
297
|
+
);
|
|
298
|
+
const kids = g
|
|
299
|
+
? (MAP[target]?.contains ?? [])
|
|
300
|
+
.filter(c => partReads(c, g).length)
|
|
301
|
+
.slice(0, 4)
|
|
302
|
+
: [];
|
|
303
|
+
const what = g
|
|
304
|
+
? `${target}'s ${g} comes from ${
|
|
305
|
+
reads.length
|
|
306
|
+
? reads
|
|
307
|
+
.slice(0, 4)
|
|
308
|
+
.map(
|
|
309
|
+
r => r.token + fmtWhen(r.when) + statusNote(target, r.token),
|
|
310
|
+
)
|
|
311
|
+
.join(', ')
|
|
312
|
+
: 'no token, so set the property directly'
|
|
313
|
+
}`
|
|
314
|
+
: `${target} reads: ${[...allReads(target)].slice(0, 8).join(', ')}`;
|
|
315
|
+
return {
|
|
316
|
+
message: `${target} never reads ${token}. ${what}.`,
|
|
317
|
+
run,
|
|
318
|
+
also: kids.length
|
|
319
|
+
? [
|
|
320
|
+
`parts inside ${target} with their own ${g}: ${kids.join(', ')} (${HOW} ${kids[0]})`,
|
|
321
|
+
]
|
|
322
|
+
: [],
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Whether a whole-theme token is read by any part.
|
|
328
|
+
* @param {string} token
|
|
329
|
+
* @param {string} P
|
|
330
|
+
* @returns {CheckFailure | null}
|
|
331
|
+
*/
|
|
332
|
+
function checkTokenGlobal(token, P) {
|
|
333
|
+
if (anyReader(token).length || SOFT.test(token)) return null;
|
|
334
|
+
const g = groupOfToken(token);
|
|
335
|
+
const near = g
|
|
336
|
+
? Object.keys(MAP)
|
|
337
|
+
.flatMap(t => partReads(t, g).map(r => r.token))
|
|
338
|
+
.filter((x, i, a) => a.indexOf(x) === i && groupOfToken(x) === g)
|
|
339
|
+
.slice(0, 6)
|
|
340
|
+
: [];
|
|
341
|
+
return {
|
|
342
|
+
message: `No component reads ${token}, so setting it changes nothing.${near.length ? ` Tokens components do read for ${g}: ${near.join(', ')}.` : ''}`,
|
|
343
|
+
run: near.length
|
|
344
|
+
? near.slice(0, 3).map(t => `${P} set <theme> ${t} <value>`)
|
|
345
|
+
: [`${HOW} "<what you want>"`],
|
|
346
|
+
also:
|
|
347
|
+
g === 'shadow'
|
|
348
|
+
? [
|
|
349
|
+
`shadows are set per part: ${P} set <theme> box-shadow "0 2px 6px rgb(0 0 0 / 0.3)" --on card`,
|
|
350
|
+
]
|
|
351
|
+
: [],
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Each visual prop of a part and its values: from the component doc, else
|
|
357
|
+
* the values seen in the catalog.
|
|
358
|
+
* @param {string} target
|
|
359
|
+
* @returns {Record<string, string[]>}
|
|
360
|
+
*/
|
|
361
|
+
function variantValues(target) {
|
|
362
|
+
const comp = TARGET.get(target)?.component;
|
|
363
|
+
const info = comp ? project.components[comp] : undefined;
|
|
364
|
+
const t =
|
|
365
|
+
info?.targets.find(x => x.className === `astryx-${target}`) ??
|
|
366
|
+
info?.targets[0];
|
|
367
|
+
const fromDocs = t?.values ?? {};
|
|
368
|
+
const seen = MAP[target]?.attrs ?? {};
|
|
369
|
+
/** @type {Record<string, string[]>} */
|
|
370
|
+
const out = {};
|
|
371
|
+
for (const p of TARGET.get(target)?.props ?? [])
|
|
372
|
+
out[p] = fromDocs[p]?.length ? fromDocs[p] : (seen[p] ?? []);
|
|
373
|
+
return out;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* What a part reads, one line per aspect.
|
|
378
|
+
* @param {string} target
|
|
379
|
+
* @param {string} P
|
|
380
|
+
* @param {string} [theme]
|
|
381
|
+
*/
|
|
382
|
+
function explain(target, P, theme = '<theme>') {
|
|
383
|
+
const t = TARGET.get(target);
|
|
384
|
+
const lines = [`${target} (part of ${t?.component ?? '?'})`];
|
|
385
|
+
for (const [p, vals] of Object.entries(variantValues(target)))
|
|
386
|
+
lines.push(` --when ${p}:${vals.length ? vals.join('|') : '<value>'}`);
|
|
387
|
+
if (t?.states?.length)
|
|
388
|
+
lines.push(
|
|
389
|
+
` --state ${t.states.join('|')} (also hover, active, focus-visible)`,
|
|
390
|
+
);
|
|
391
|
+
if (!MAP[target]) {
|
|
392
|
+
lines.push(
|
|
393
|
+
' (no compiled record of what it reads: it did not render in the catalog)',
|
|
394
|
+
);
|
|
395
|
+
return lines;
|
|
396
|
+
}
|
|
397
|
+
for (const g of Object.keys(GROUPS)) {
|
|
398
|
+
const r = partReads(target, g);
|
|
399
|
+
if (!r.length) continue;
|
|
400
|
+
lines.push(
|
|
401
|
+
` ${g.padEnd(10)} ${r
|
|
402
|
+
.slice(0, 5)
|
|
403
|
+
.map(x => x.token + fmtWhen(x.when) + statusNote(target, x.token))
|
|
404
|
+
.join(', ')}${r.length > 5 ? `, ... (${r.length - 5} more)` : ''}`,
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
const kids = MAP[target].contains ?? [];
|
|
408
|
+
if (kids.length)
|
|
409
|
+
lines.push(
|
|
410
|
+
` contains ${kids.slice(0, 10).join(', ')} (tokens set --on ${target} reach these too)`,
|
|
411
|
+
);
|
|
412
|
+
lines.push(
|
|
413
|
+
` any CSS property works directly, e.g. ${P} set ${theme} background "#fafafa" --on ${target}`,
|
|
414
|
+
);
|
|
415
|
+
return lines;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Text that this theme made unreadable: every real text-on-background pair,
|
|
420
|
+
* in each mode, below 4.5:1 now but not as low in the base theme.
|
|
421
|
+
* @param {(pair: import('./_parts.mjs').TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} value
|
|
422
|
+
* @param {(pair: import('./_parts.mjs').TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} baseValue
|
|
423
|
+
* @param {string[]} modes
|
|
424
|
+
* @param {{parseColor: (v: unknown) => number[] | null, ratio: (a: number[], b: number[]) => number}} helpers
|
|
425
|
+
*/
|
|
426
|
+
function contrast(value, baseValue, modes, {parseColor, ratio}) {
|
|
427
|
+
/** @type {Array<{part: string, mode: string, ratio: number, sample: string, fg: string, bgPart: string | null, bg: string}>} */
|
|
428
|
+
const out = [];
|
|
429
|
+
const seen = new Set();
|
|
430
|
+
for (const p of parts.pairs) {
|
|
431
|
+
if (
|
|
432
|
+
p.fg.target !== p.bg.target &&
|
|
433
|
+
p.bg.target &&
|
|
434
|
+
partReads(p.bg.target, 'text').length
|
|
435
|
+
)
|
|
436
|
+
continue;
|
|
437
|
+
for (const m of modes) {
|
|
438
|
+
const fg = value(p, 'fg', m);
|
|
439
|
+
const bg = value(p, 'bg', m);
|
|
440
|
+
if (/gradient|url\(/.test(String(bg))) continue;
|
|
441
|
+
if (hasAlpha(fg) || hasAlpha(bg)) continue;
|
|
442
|
+
const a = parseColor(fg);
|
|
443
|
+
const b = parseColor(bg);
|
|
444
|
+
if (!a || !b) continue;
|
|
445
|
+
const r = ratio(a, b);
|
|
446
|
+
if (r >= 4.5) continue;
|
|
447
|
+
const a0 = parseColor(baseValue(p, 'fg', m));
|
|
448
|
+
const b0 = parseColor(baseValue(p, 'bg', m));
|
|
449
|
+
if (a0 && b0 && ratio(a0, b0) <= r + 0.05) continue;
|
|
450
|
+
const key = `${p.text}|${fg}|${bg}|${m}`;
|
|
451
|
+
if (seen.has(key)) continue;
|
|
452
|
+
seen.add(key);
|
|
453
|
+
out.push({
|
|
454
|
+
part: p.text,
|
|
455
|
+
mode: m,
|
|
456
|
+
ratio: Number(r.toFixed(2)),
|
|
457
|
+
sample: p.sample,
|
|
458
|
+
fg: p.fg.tokens[0] ?? String(fg),
|
|
459
|
+
bgPart: p.bg.target,
|
|
460
|
+
bg: p.bg.tokens[0] ?? String(bg),
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return out.slice(0, 8);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Whether a part shows its corners: it sets a radius, a background, a
|
|
469
|
+
* border or a shadow. A radius on anything else changes nothing you see.
|
|
470
|
+
* @param {string} target
|
|
471
|
+
*/
|
|
472
|
+
function showsCorners(target) {
|
|
473
|
+
const own = MAP[target]?.own;
|
|
474
|
+
if (!own) return true;
|
|
475
|
+
for (const [p, v] of Object.entries(own)) {
|
|
476
|
+
if (GROUPS.corners.includes(p) || p === 'box-shadow') return true;
|
|
477
|
+
if (
|
|
478
|
+
/^border(-(top|right|bottom|left|block|inline))?(-width)?$/.test(p) &&
|
|
479
|
+
v.values.some(x => !/^(0|0px|none)$/.test(x))
|
|
480
|
+
)
|
|
481
|
+
return true;
|
|
482
|
+
if (
|
|
483
|
+
p === 'background-color' ||
|
|
484
|
+
p === 'background' ||
|
|
485
|
+
p === 'background-image'
|
|
486
|
+
) {
|
|
487
|
+
// A background the same as the page behind it shows no edge.
|
|
488
|
+
const always = Object.entries(v.tokens).some(
|
|
489
|
+
([tok, conds]) =>
|
|
490
|
+
tok !== '--color-background-body' && conds.includes('always'),
|
|
491
|
+
);
|
|
492
|
+
const raw = v.values.some(
|
|
493
|
+
x => !/var\(|transparent|inherit|none/.test(x),
|
|
494
|
+
);
|
|
495
|
+
if (always || raw) return true;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
return {
|
|
502
|
+
MAP,
|
|
503
|
+
typeOf,
|
|
504
|
+
feeds,
|
|
505
|
+
fmtFeeds,
|
|
506
|
+
showsCorners,
|
|
507
|
+
groupOfToken,
|
|
508
|
+
groupOfProp,
|
|
509
|
+
partReads,
|
|
510
|
+
fmtWhen,
|
|
511
|
+
statusNote,
|
|
512
|
+
allReads,
|
|
513
|
+
anyReader,
|
|
514
|
+
checkTokenOn,
|
|
515
|
+
checkTokenGlobal,
|
|
516
|
+
variantValues,
|
|
517
|
+
explain,
|
|
518
|
+
contrast,
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/** @typedef {ReturnType<typeof makeCompiler>} Compiler */
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
* @file The standard CSS property names a theme may set on a part. A name
|
|
6
|
+
* outside this list is not a CSS property, so the command refuses it.
|
|
7
|
+
* @position api/theme-edit — data
|
|
8
|
+
*/
|
|
9
|
+
/** @type {ReadonlySet<string>} */
|
|
10
|
+
export const CSS_PROPERTIES: ReadonlySet<string>;
|