@tenphi/tasty 0.0.0-snapshot.047dfbb → 0.0.0-snapshot.04fb534
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 +452 -370
- package/dist/babel-types-Dc5zghyE.d.ts +18 -0
- package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
- package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
- package/dist/chunks/build-config--0qoqt_P.js +60 -0
- package/dist/chunks/build-config--0qoqt_P.js.map +1 -0
- package/dist/{collector-J6LwZR0N.js → chunks/collector-zp5BrLF0.js} +68 -101
- package/dist/chunks/collector-zp5BrLF0.js.map +1 -0
- package/dist/chunks/config-engine-BaLq8HrX.js +272 -0
- package/dist/chunks/config-engine-BaLq8HrX.js.map +1 -0
- package/dist/chunks/config-file-DlZXJMj8.js +25 -0
- package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
- package/dist/chunks/css-definitions-CfXZ3tU9.js +910 -0
- package/dist/chunks/css-definitions-CfXZ3tU9.js.map +1 -0
- package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/chunks/debug--OC-WA-Q.js +502 -0
- package/dist/chunks/debug--OC-WA-Q.js.map +1 -0
- package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
- package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
- package/dist/chunks/hydration-TRcz5vnk.js +41 -0
- package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
- package/dist/chunks/react-runtime-DnZ6M1Iv.js +691 -0
- package/dist/chunks/react-runtime-DnZ6M1Iv.js.map +1 -0
- package/dist/chunks/runtime-engine-J9X_h-Pw.js +2435 -0
- package/dist/chunks/runtime-engine-J9X_h-Pw.js.map +1 -0
- package/dist/chunks/runtime-state-o_v3Bj7b.js +152 -0
- package/dist/chunks/runtime-state-o_v3Bj7b.js.map +1 -0
- package/dist/{merge-styles-CAdKaHxh.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-D6lC3O3G.js +5626 -0
- package/dist/chunks/style-engine-D6lC3O3G.js.map +1 -0
- package/dist/{css-writer-IC7tdnIf.js → chunks/zero-engine-BnjoV04F.js} +95 -136
- package/dist/chunks/zero-engine-BnjoV04F.js.map +1 -0
- package/dist/{collector-CddJZDOr.d.ts → collector-D2OT6I2G.d.ts} +64 -8
- package/dist/{config-C3SKYuxY.d.ts → config-C4ftFxgI.d.ts} +514 -92
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/{index-ByBYTH9l.d.ts → index-DxQNRj50.d.ts} +586 -400
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -732
- package/dist/{merge-styles-CvUi7SOD.d.ts → merge-styles-D39qBtox.d.ts} +2 -3
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +1 -14
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +17 -0
- package/dist/ssr/astro-middleware-static.js +7 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +11 -8
- package/dist/ssr/astro-middleware.js +2 -14
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -10
- package/dist/ssr/astro.js +160 -86
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +5 -32
- package/dist/ssr/index.js +6 -6
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +123 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -8
- package/dist/ssr/next.js +29 -44
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -9
- package/dist/static/index.js +4 -22
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -2
- package/dist/{index-C5owZ15q.d.ts → types-CYQIhUg1.d.ts} +874 -598
- package/dist/zero/babel.d.ts +12 -19
- package/dist/zero/babel.js +97 -156
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +76 -7
- package/dist/zero/index.js +25 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +3 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +20 -9
- package/docs/adoption.md +69 -36
- package/docs/ai-agents.md +259 -0
- package/docs/comparison.md +77 -47
- package/docs/configuration.md +617 -98
- package/docs/debug.md +28 -15
- package/docs/design-system.md +166 -33
- package/docs/dsl.md +637 -205
- package/docs/getting-started.md +130 -50
- package/docs/injector.md +160 -69
- package/docs/llms.txt +31 -0
- package/docs/methodology.md +82 -51
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +57 -33
- package/docs/plugins.md +333 -0
- package/docs/react-api.md +215 -50
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +310 -118
- package/docs/styles.md +209 -41
- package/docs/tasty-static.md +289 -136
- package/harness/dev.harnesspm/rules/usage.md +12 -0
- package/harness/dev.harnesspm/scripts/render.mjs +441 -0
- package/harness/dev.harnesspm/scripts/styles.mjs +412 -0
- package/harness/plugin.json +20 -0
- package/package.json +148 -49
- package/tasty.config.ts +5 -0
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/collector-J6LwZR0N.js.map +0 -1
- package/dist/config-C3F4Ogo1.js +0 -10993
- package/dist/config-C3F4Ogo1.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-DxHmF6S9.js +0 -1598
- package/dist/core-DxHmF6S9.js.map +0 -1
- package/dist/css-writer-IC7tdnIf.js.map +0 -1
- package/dist/format-global-rules-DklyaXv-.js +0 -22
- package/dist/format-global-rules-DklyaXv-.js.map +0 -1
- package/dist/format-rules-DTLY39Hm.js +0 -143
- package/dist/format-rules-DTLY39Hm.js.map +0 -1
- package/dist/hydrate-8Zglgy_C.js +0 -45
- package/dist/hydrate-8Zglgy_C.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-DgGkipNK.js +0 -595
- package/dist/keyframes-DgGkipNK.js.map +0 -1
- package/dist/merge-styles-CAdKaHxh.js.map +0 -1
- package/dist/resolve-recipes-BQNdunBd.js +0 -144
- package/dist/resolve-recipes-BQNdunBd.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Tasty styles
|
|
2
|
+
|
|
3
|
+
## Writing styles
|
|
4
|
+
|
|
5
|
+
- Before you write or review styles, read `ai-agents.md` from the Tasty docs index.
|
|
6
|
+
- Use only the tokens, units, presets, recipes and states the project defines in `tasty.config.ts` or `configure()`.
|
|
7
|
+
- Style with `tasty()` and `styles`, not the `style` prop. Colors are `#tokens`, sizes are units (`2x`, `1r`): no hex, `rgb()` or `px`.
|
|
8
|
+
- One state map per property, `''` first. Sub-elements are capitalized keys, not nested selectors.
|
|
9
|
+
|
|
10
|
+
## Checking styles
|
|
11
|
+
|
|
12
|
+
- To see the CSS that styles produce, run `tasty:styles '<json>' --setup <module that calls configure()>`.
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `tasty:styles` computes. Every function that reads Tasty takes the
|
|
3
|
+
* Tasty module as its first argument: the tool passes the package's `dist/`
|
|
4
|
+
* build, and `src/harness.test.ts` passes the source, so the tests need no
|
|
5
|
+
* build.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** CSS units. A number with any other unit in the output stayed raw. */
|
|
9
|
+
const CSS_UNITS = new Set([
|
|
10
|
+
'px',
|
|
11
|
+
'em',
|
|
12
|
+
'rem',
|
|
13
|
+
'ex',
|
|
14
|
+
'rex',
|
|
15
|
+
'ch',
|
|
16
|
+
'rch',
|
|
17
|
+
'cap',
|
|
18
|
+
'rcap',
|
|
19
|
+
'ic',
|
|
20
|
+
'ric',
|
|
21
|
+
'lh',
|
|
22
|
+
'rlh',
|
|
23
|
+
'vw',
|
|
24
|
+
'vh',
|
|
25
|
+
'vi',
|
|
26
|
+
'vb',
|
|
27
|
+
'vmin',
|
|
28
|
+
'vmax',
|
|
29
|
+
'svw',
|
|
30
|
+
'svh',
|
|
31
|
+
'svi',
|
|
32
|
+
'svb',
|
|
33
|
+
'svmin',
|
|
34
|
+
'svmax',
|
|
35
|
+
'lvw',
|
|
36
|
+
'lvh',
|
|
37
|
+
'lvi',
|
|
38
|
+
'lvb',
|
|
39
|
+
'lvmin',
|
|
40
|
+
'lvmax',
|
|
41
|
+
'dvw',
|
|
42
|
+
'dvh',
|
|
43
|
+
'dvi',
|
|
44
|
+
'dvb',
|
|
45
|
+
'dvmin',
|
|
46
|
+
'dvmax',
|
|
47
|
+
'cqw',
|
|
48
|
+
'cqh',
|
|
49
|
+
'cqi',
|
|
50
|
+
'cqb',
|
|
51
|
+
'cqmin',
|
|
52
|
+
'cqmax',
|
|
53
|
+
'cm',
|
|
54
|
+
'mm',
|
|
55
|
+
'q',
|
|
56
|
+
'in',
|
|
57
|
+
'pt',
|
|
58
|
+
'pc',
|
|
59
|
+
'deg',
|
|
60
|
+
'grad',
|
|
61
|
+
'rad',
|
|
62
|
+
'turn',
|
|
63
|
+
's',
|
|
64
|
+
'ms',
|
|
65
|
+
'hz',
|
|
66
|
+
'khz',
|
|
67
|
+
'dpi',
|
|
68
|
+
'dpcm',
|
|
69
|
+
'dppx',
|
|
70
|
+
'x',
|
|
71
|
+
'fr',
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
/** Words in a `preset` value that are modifiers, not preset names. */
|
|
75
|
+
const PRESET_MODIFIERS = new Set([
|
|
76
|
+
'strong',
|
|
77
|
+
'bold',
|
|
78
|
+
'italic',
|
|
79
|
+
'icon',
|
|
80
|
+
'tight',
|
|
81
|
+
'normal',
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
// Tasty shares these configured resources across copies through globalThis.
|
|
85
|
+
const CONFIG_TOKENS_KEY = '__tasty_cfg_tokens__';
|
|
86
|
+
const CONFIG_PROPERTIES_KEY = '__tasty_cfg_properties__';
|
|
87
|
+
const CONFIG_GLOBAL_STYLES_KEY = '__tasty_cfg_global_styles__';
|
|
88
|
+
|
|
89
|
+
// The core entry point does not expose its default @property definitions.
|
|
90
|
+
const DEFAULT_PROPERTIES = [
|
|
91
|
+
'--tasty-second-fill-color',
|
|
92
|
+
'--current-color',
|
|
93
|
+
'--white-color',
|
|
94
|
+
'--black-color',
|
|
95
|
+
'--border-color',
|
|
96
|
+
'--outline-color',
|
|
97
|
+
'--gap',
|
|
98
|
+
'--radius',
|
|
99
|
+
'--border-width',
|
|
100
|
+
'--outline-width',
|
|
101
|
+
'--transition',
|
|
102
|
+
'--sharp-radius',
|
|
103
|
+
'--bold-font-weight',
|
|
104
|
+
'--font-sans-fallback',
|
|
105
|
+
'--font-mono-fallback',
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
/** The parts of the configuration that a setup module changes. */
|
|
109
|
+
export function configSummary(t) {
|
|
110
|
+
return {
|
|
111
|
+
units: { ...(t.getGlobalParser().getUnits() ?? {}) },
|
|
112
|
+
states: Object.keys(t.getGlobalPredefinedStates() ?? {}),
|
|
113
|
+
recipes: Object.keys(t.getGlobalRecipes() ?? {}),
|
|
114
|
+
tokens: Object.keys(globalThis[CONFIG_TOKENS_KEY] ?? {}),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The parts of the configuration that belong to one copy of Tasty. Tokens are
|
|
120
|
+
* left out: Tasty shares them between copies through `globalThis`.
|
|
121
|
+
*/
|
|
122
|
+
export function configFingerprint(t) {
|
|
123
|
+
const { units, states, recipes } = configSummary(t);
|
|
124
|
+
return { units, states, recipes };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Whether two `configSummary()` or `configFingerprint()` results differ. */
|
|
128
|
+
export function configChanged(before, after) {
|
|
129
|
+
return JSON.stringify(before) !== JSON.stringify(after);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The CSS Tasty generates for a styles object, through `computeStyles()`:
|
|
134
|
+
* the render core `tasty()` and `useStyles()` share. Recipes are resolved,
|
|
135
|
+
* each style chunk gets its own class, and keyframes get their final names.
|
|
136
|
+
*/
|
|
137
|
+
export function renderCss(t, styles) {
|
|
138
|
+
const { className, css } = t.computeStyles(styles);
|
|
139
|
+
return {
|
|
140
|
+
classNames: (className ?? '').split(' ').filter(Boolean),
|
|
141
|
+
css: css ?? '',
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Splits CSS text into a tree: `{ prelude, children }` for a block and
|
|
147
|
+
* `{ property, value }` for a declaration. Strings and parentheses are kept
|
|
148
|
+
* whole, so a `;` or `{` inside them does not split.
|
|
149
|
+
*/
|
|
150
|
+
export function parseCss(css) {
|
|
151
|
+
const root = { prelude: '', children: [] };
|
|
152
|
+
const stack = [root];
|
|
153
|
+
let buffer = '';
|
|
154
|
+
let quote = '';
|
|
155
|
+
let escaped = false;
|
|
156
|
+
let depth = 0;
|
|
157
|
+
|
|
158
|
+
const flush = () => {
|
|
159
|
+
const text = buffer.trim();
|
|
160
|
+
buffer = '';
|
|
161
|
+
if (!text) return;
|
|
162
|
+
const colon = text.indexOf(':');
|
|
163
|
+
const node =
|
|
164
|
+
colon > 0
|
|
165
|
+
? {
|
|
166
|
+
property: text.slice(0, colon).trim(),
|
|
167
|
+
value: text.slice(colon + 1).trim(),
|
|
168
|
+
}
|
|
169
|
+
: { property: '', value: text };
|
|
170
|
+
stack.at(-1).children.push(node);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
for (const char of css) {
|
|
174
|
+
if (quote) {
|
|
175
|
+
buffer += char;
|
|
176
|
+
if (escaped) escaped = false;
|
|
177
|
+
else if (char === '\\') escaped = true;
|
|
178
|
+
else if (char === quote) quote = '';
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (char === '"' || char === "'") {
|
|
182
|
+
quote = char;
|
|
183
|
+
buffer += char;
|
|
184
|
+
} else if (char === '(') {
|
|
185
|
+
depth++;
|
|
186
|
+
buffer += char;
|
|
187
|
+
} else if (char === ')') {
|
|
188
|
+
depth = Math.max(0, depth - 1);
|
|
189
|
+
buffer += char;
|
|
190
|
+
} else if (depth > 0) {
|
|
191
|
+
buffer += char;
|
|
192
|
+
} else if (char === '{') {
|
|
193
|
+
const block = { prelude: buffer.trim(), children: [] };
|
|
194
|
+
buffer = '';
|
|
195
|
+
stack.at(-1).children.push(block);
|
|
196
|
+
stack.push(block);
|
|
197
|
+
} else if (char === ';') {
|
|
198
|
+
flush();
|
|
199
|
+
} else if (char === '}') {
|
|
200
|
+
flush();
|
|
201
|
+
if (stack.length > 1) stack.pop();
|
|
202
|
+
} else {
|
|
203
|
+
buffer += char;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
flush();
|
|
207
|
+
return root.children;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** CSS text, one declaration per line, blocks indented. */
|
|
211
|
+
export function formatCss(css) {
|
|
212
|
+
const lines = [];
|
|
213
|
+
const write = (nodes, indent) => {
|
|
214
|
+
for (const node of nodes) {
|
|
215
|
+
if ('prelude' in node) {
|
|
216
|
+
if (indent === '' && lines.length > 0) lines.push('');
|
|
217
|
+
lines.push(`${indent}${node.prelude} {`);
|
|
218
|
+
write(node.children, `${indent} `);
|
|
219
|
+
lines.push(`${indent}}`);
|
|
220
|
+
} else if (node.property) {
|
|
221
|
+
lines.push(`${indent}${node.property}: ${node.value};`);
|
|
222
|
+
} else {
|
|
223
|
+
lines.push(`${indent}${node.value}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
write(parseCss(css), '');
|
|
228
|
+
return lines.join('\n');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Declarations and @property names at any depth. */
|
|
232
|
+
function inspectCss(css) {
|
|
233
|
+
const declarations = [];
|
|
234
|
+
const properties = new Set();
|
|
235
|
+
const walk = (nodes) => {
|
|
236
|
+
for (const node of nodes) {
|
|
237
|
+
if ('prelude' in node) {
|
|
238
|
+
const registration = /^@property\s+(--[\w-]+)$/.exec(node.prelude);
|
|
239
|
+
if (registration) properties.add(registration[1]);
|
|
240
|
+
walk(node.children);
|
|
241
|
+
} else if (node.property) {
|
|
242
|
+
declarations.push(node);
|
|
243
|
+
if (node.property.startsWith('--')) properties.add(node.property);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
walk(parseCss(css));
|
|
248
|
+
return { declarations, properties };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The string values of one style property in a styles object and its
|
|
253
|
+
* sub-elements, including each value of a state map.
|
|
254
|
+
*/
|
|
255
|
+
function valuesOf(styles, property) {
|
|
256
|
+
const found = [];
|
|
257
|
+
const collect = (value) => {
|
|
258
|
+
if (typeof value === 'string') found.push(value);
|
|
259
|
+
else if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
260
|
+
for (const inner of Object.values(value)) collect(inner);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const walk = (object) => {
|
|
264
|
+
for (const [key, value] of Object.entries(object)) {
|
|
265
|
+
if (key === property) collect(value);
|
|
266
|
+
else if (
|
|
267
|
+
/^[A-Z]/.test(key) &&
|
|
268
|
+
value &&
|
|
269
|
+
typeof value === 'object' &&
|
|
270
|
+
!Array.isArray(value)
|
|
271
|
+
) {
|
|
272
|
+
walk(value);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
walk(styles);
|
|
277
|
+
return found;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function cssNameOf(token, normalize = false) {
|
|
281
|
+
const sigil = token[0];
|
|
282
|
+
if (sigil !== '#' && sigil !== '$') {
|
|
283
|
+
return token.startsWith('--') ? token : `--${token}`;
|
|
284
|
+
}
|
|
285
|
+
const name = token.slice(1);
|
|
286
|
+
// The DSL folds the first letter. Registered CSS properties keep their name.
|
|
287
|
+
const cssName = normalize
|
|
288
|
+
? name.charAt(0).toLowerCase() + name.slice(1)
|
|
289
|
+
: name;
|
|
290
|
+
return `--${cssName}${sigil === '#' ? '-color' : ''}`;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function withoutLiterals(value) {
|
|
294
|
+
return value
|
|
295
|
+
.replace(
|
|
296
|
+
/\/\*[\s\S]*?\*\/|"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'/g,
|
|
297
|
+
' ',
|
|
298
|
+
)
|
|
299
|
+
.replace(/\burl\((?:\\[\s\S]|[^)\\])*\)/gi, ' ');
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Authored DSL references that survive rendering as a var() without a fallback. */
|
|
303
|
+
function findTokenIssues(t, styles, tokens, { declarations, properties }) {
|
|
304
|
+
const references = new Set();
|
|
305
|
+
for (const { value } of declarations) {
|
|
306
|
+
for (const [, name] of withoutLiterals(value).matchAll(
|
|
307
|
+
/(?<![\w-])var\(\s*(--[\w-]+)\s*\)/gi,
|
|
308
|
+
)) {
|
|
309
|
+
references.add(name);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (references.size === 0) return [];
|
|
313
|
+
|
|
314
|
+
const defined = new Set([
|
|
315
|
+
...DEFAULT_PROPERTIES,
|
|
316
|
+
...properties,
|
|
317
|
+
...tokens.map((token) => cssNameOf(token, true)),
|
|
318
|
+
...Object.keys(globalThis[CONFIG_PROPERTIES_KEY] ?? {}).map((name) =>
|
|
319
|
+
cssNameOf(name),
|
|
320
|
+
),
|
|
321
|
+
]);
|
|
322
|
+
const missing = new Map();
|
|
323
|
+
const walk = (value) => {
|
|
324
|
+
if (typeof value === 'string') {
|
|
325
|
+
for (const [token] of withoutLiterals(value).matchAll(
|
|
326
|
+
/(?<![#$\\])[#$][\w-]+/g,
|
|
327
|
+
)) {
|
|
328
|
+
const name = cssNameOf(token, true);
|
|
329
|
+
if (references.has(name) && !defined.has(name))
|
|
330
|
+
missing.set(token, name);
|
|
331
|
+
}
|
|
332
|
+
} else if (value && typeof value === 'object') {
|
|
333
|
+
for (const child of Object.values(value)) walk(child);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
walk(styles);
|
|
337
|
+
if (missing.size === 0) return [];
|
|
338
|
+
|
|
339
|
+
for (const [selector, globalStyles] of Object.entries(
|
|
340
|
+
globalThis[CONFIG_GLOBAL_STYLES_KEY] ?? {},
|
|
341
|
+
)) {
|
|
342
|
+
for (const rule of t.renderStyles(globalStyles, selector)) {
|
|
343
|
+
for (const property of inspectCss(rule.declarations).properties) {
|
|
344
|
+
defined.add(property);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return [...missing]
|
|
350
|
+
.filter(([, name]) => !defined.has(name))
|
|
351
|
+
.map(([token, name]) => {
|
|
352
|
+
const color = token.startsWith('#');
|
|
353
|
+
const known = tokens.filter((key) => key[0] === token[0]).slice(0, 8);
|
|
354
|
+
const example = known.length
|
|
355
|
+
? ` Known ${color ? 'colors' : 'tokens'} include ${known.join(', ')}.`
|
|
356
|
+
: '';
|
|
357
|
+
return `${color ? 'Color' : 'Token'} "${token}" is not in the loaded config. Its CSS variable var(${name}) needs a value from other CSS.${example}`;
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Values the CSS shows Tasty did not resolve, and names the loaded
|
|
363
|
+
* configuration does not define. Each issue is one sentence that says what to
|
|
364
|
+
* do. Tasty's own warnings are collected by the tool, not here.
|
|
365
|
+
*/
|
|
366
|
+
export function findIssues(t, styles, css) {
|
|
367
|
+
const issues = [];
|
|
368
|
+
|
|
369
|
+
// Once any recipe is configured, Tasty warns about an unknown one itself.
|
|
370
|
+
// With none configured, it drops every recipe silently.
|
|
371
|
+
if (!t.hasGlobalRecipes()) {
|
|
372
|
+
const names = new Set(
|
|
373
|
+
valuesOf(styles, 'recipe')
|
|
374
|
+
.flatMap((value) => value.split(/[\s/]+/))
|
|
375
|
+
.filter((name) => name && name !== 'none'),
|
|
376
|
+
);
|
|
377
|
+
for (const name of names) {
|
|
378
|
+
issues.push(
|
|
379
|
+
`Recipe "${name}" was dropped: no recipes are configured. Load the module that configures recipes with --setup.`,
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const tokens = Object.keys(globalThis[CONFIG_TOKENS_KEY] ?? {});
|
|
385
|
+
const presets = new Set(
|
|
386
|
+
tokens
|
|
387
|
+
.filter((token) => token.endsWith('-font-size'))
|
|
388
|
+
.map((token) => token.slice(1, -'-font-size'.length)),
|
|
389
|
+
);
|
|
390
|
+
// Without typography tokens in the config, presets come from CSS this tool
|
|
391
|
+
// cannot see, so their names are not checked.
|
|
392
|
+
if (presets.size > 0) {
|
|
393
|
+
const missingPresets = new Set();
|
|
394
|
+
for (const value of valuesOf(styles, 'preset')) {
|
|
395
|
+
const name = value
|
|
396
|
+
.split(/[\s/]+/)
|
|
397
|
+
.find((word) => word && !PRESET_MODIFIERS.has(word));
|
|
398
|
+
if (name && name !== 'inherit' && !presets.has(name)) {
|
|
399
|
+
missingPresets.add(name);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
for (const name of missingPresets) {
|
|
403
|
+
issues.push(
|
|
404
|
+
`Preset "${name}" is not in the loaded config, so its font falls back to the default preset. Known presets: ${[...presets].join(', ')}.`,
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const rendered = inspectCss(css);
|
|
410
|
+
if (tokens.length > 0) {
|
|
411
|
+
issues.push(...findTokenIssues(t, styles, tokens, rendered));
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const rawUnits = new Map();
|
|
415
|
+
for (const { property, value } of rendered.declarations) {
|
|
416
|
+
if (property.startsWith('--')) continue;
|
|
417
|
+
for (const match of value.matchAll(
|
|
418
|
+
/(?<![\w#.$-])(-?(?:\d+\.?\d*|\.\d+))([a-zA-Z]+)(?![\w(-])/g,
|
|
419
|
+
)) {
|
|
420
|
+
if (!CSS_UNITS.has(match[2].toLowerCase())) {
|
|
421
|
+
rawUnits.set(`${match[0]} ${property}`, [match[0], match[2], property]);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
for (const [value, unit, property] of rawUnits.values()) {
|
|
426
|
+
issues.push(
|
|
427
|
+
`"${value}" in ${property} reached the CSS unchanged: "${unit}" is not a Tasty or CSS unit. Check the unit, or load the module that configures units with --setup.`,
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return issues;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** How a unit list reads in the tool's header: `x = var(--gap), r = 6px`. */
|
|
435
|
+
export function describeUnits(units) {
|
|
436
|
+
return Object.entries(units)
|
|
437
|
+
.map(([name, value]) =>
|
|
438
|
+
typeof value === 'string' ? `${name} = ${value}` : `${name} = (function)`,
|
|
439
|
+
)
|
|
440
|
+
.join(', ');
|
|
441
|
+
}
|