@tenphi/tasty 3.19.1 → 3.19.2
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
CHANGED
|
@@ -585,7 +585,7 @@ See [Debug Utilities](docs/debug.md).
|
|
|
585
585
|
|
|
586
586
|
Style definitions are declarative and fully typed, so agents can read and write them reliably. [Style Rules for AI Agents](docs/ai-agents.md) is a one-page brief to add to an agent's context.
|
|
587
587
|
|
|
588
|
-
The package also ships a harness for coding agents such as Claude Code and Codex, in [`harness/`](harness). With [harnesspm](https://www.npmjs.com/package/@tenphi/harnesspm), a project that depends on Tasty gets:
|
|
588
|
+
The package also ships a harness for coding agents such as Claude Code and Codex, in [`harness/`](https://github.com/tenphi/tasty/tree/main/harness). With [harnesspm](https://www.npmjs.com/package/@tenphi/harnesspm), a project that depends on Tasty gets:
|
|
589
589
|
|
|
590
590
|
- a short rule: read the brief and the project's config first, use tokens and units, write state maps right;
|
|
591
591
|
- the docs index, so an agent reads the pages in `docs/` of the installed version;
|
|
@@ -81,13 +81,29 @@ const PRESET_MODIFIERS = new Set([
|
|
|
81
81
|
'normal',
|
|
82
82
|
]);
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
* Where `configure()` keeps its `tokens` (and the typography tokens that
|
|
86
|
-
* `presets` generate). Tasty shares them through `globalThis` so that every
|
|
87
|
-
* copy of the engine sees them; the tool reads them only to check preset
|
|
88
|
-
* names. `src/harness.test.ts` fails if the key changes.
|
|
89
|
-
*/
|
|
84
|
+
// Tasty shares these configured resources across copies through globalThis.
|
|
90
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
|
+
];
|
|
91
107
|
|
|
92
108
|
/** The parts of the configuration that a setup module changes. */
|
|
93
109
|
export function configSummary(t) {
|
|
@@ -136,6 +152,7 @@ export function parseCss(css) {
|
|
|
136
152
|
const stack = [root];
|
|
137
153
|
let buffer = '';
|
|
138
154
|
let quote = '';
|
|
155
|
+
let escaped = false;
|
|
139
156
|
let depth = 0;
|
|
140
157
|
|
|
141
158
|
const flush = () => {
|
|
@@ -156,7 +173,9 @@ export function parseCss(css) {
|
|
|
156
173
|
for (const char of css) {
|
|
157
174
|
if (quote) {
|
|
158
175
|
buffer += char;
|
|
159
|
-
if (
|
|
176
|
+
if (escaped) escaped = false;
|
|
177
|
+
else if (char === '\\') escaped = true;
|
|
178
|
+
else if (char === quote) quote = '';
|
|
160
179
|
continue;
|
|
161
180
|
}
|
|
162
181
|
if (char === '"' || char === "'") {
|
|
@@ -209,17 +228,24 @@ export function formatCss(css) {
|
|
|
209
228
|
return lines.join('\n');
|
|
210
229
|
}
|
|
211
230
|
|
|
212
|
-
/**
|
|
213
|
-
function
|
|
214
|
-
const
|
|
231
|
+
/** Declarations and @property names at any depth. */
|
|
232
|
+
function inspectCss(css) {
|
|
233
|
+
const declarations = [];
|
|
234
|
+
const properties = new Set();
|
|
215
235
|
const walk = (nodes) => {
|
|
216
236
|
for (const node of nodes) {
|
|
217
|
-
if ('prelude' in node)
|
|
218
|
-
|
|
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
|
+
}
|
|
219
245
|
}
|
|
220
246
|
};
|
|
221
247
|
walk(parseCss(css));
|
|
222
|
-
return
|
|
248
|
+
return { declarations, properties };
|
|
223
249
|
}
|
|
224
250
|
|
|
225
251
|
/**
|
|
@@ -251,6 +277,87 @@ function valuesOf(styles, property) {
|
|
|
251
277
|
return found;
|
|
252
278
|
}
|
|
253
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
|
+
|
|
254
361
|
/**
|
|
255
362
|
* Values the CSS shows Tasty did not resolve, and names the loaded
|
|
256
363
|
* configuration does not define. Each issue is one sentence that says what to
|
|
@@ -299,8 +406,13 @@ export function findIssues(t, styles, css) {
|
|
|
299
406
|
}
|
|
300
407
|
}
|
|
301
408
|
|
|
409
|
+
const rendered = inspectCss(css);
|
|
410
|
+
if (tokens.length > 0) {
|
|
411
|
+
issues.push(...findTokenIssues(t, styles, tokens, rendered));
|
|
412
|
+
}
|
|
413
|
+
|
|
302
414
|
const rawUnits = new Map();
|
|
303
|
-
for (const { property, value } of
|
|
415
|
+
for (const { property, value } of rendered.declarations) {
|
|
304
416
|
if (property.startsWith('--')) continue;
|
|
305
417
|
for (const match of value.matchAll(
|
|
306
418
|
/(?<![\w#.$-])(-?(?:\d+\.?\d*|\.\d+))([a-zA-Z]+)(?![\w(-])/g,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* tasty:styles — prints the CSS Tasty generates for a styles object, with the
|
|
3
|
-
* app's configuration loaded first, and
|
|
3
|
+
* app's configuration loaded first, and reports problems found during rendering.
|
|
4
4
|
*/
|
|
5
5
|
import {
|
|
6
6
|
existsSync,
|
|
@@ -41,6 +41,9 @@ Run it from the package whose styles you check. Package paths in --setup resolve
|
|
|
41
41
|
from there, and the CSS comes from the copy of @tenphi/tasty that the setup
|
|
42
42
|
modules configure, which in a monorepo can differ from package to package.
|
|
43
43
|
|
|
44
|
+
When the loaded config defines tokens, the tool warns about unknown #color
|
|
45
|
+
and $token references that still need a value in the generated CSS.
|
|
46
|
+
|
|
44
47
|
Without --setup, the CSS uses Tasty's defaults (x = 8px, r = 6px, ...) and none
|
|
45
48
|
of the app's units, presets, recipes or state aliases.`;
|
|
46
49
|
|
package/harness/plugin.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"styles": {
|
|
13
13
|
"file": "./dev.harnesspm/scripts/styles.mjs",
|
|
14
|
-
"description": "Print the CSS a Tasty styles object produces,
|
|
14
|
+
"description": "Print the CSS a Tasty styles object produces and report rendering warnings, including unknown token references when the --setup config defines tokens",
|
|
15
15
|
"allow": true
|
|
16
16
|
}
|
|
17
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tenphi/tasty",
|
|
3
|
-
"version": "3.19.
|
|
3
|
+
"version": "3.19.2",
|
|
4
4
|
"description": "A design-system-integrated styling system and DSL for concise, state-aware UI styling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -175,8 +175,8 @@
|
|
|
175
175
|
"@eslint/js": "^10.0.1",
|
|
176
176
|
"@size-limit/esbuild": "^14.1.0",
|
|
177
177
|
"@size-limit/file": "^14.1.0",
|
|
178
|
-
"@tenphi/eslint-plugin-tasty": "^1.
|
|
179
|
-
"@tenphi/harnesspm": "^0.
|
|
178
|
+
"@tenphi/eslint-plugin-tasty": "^1.21.1",
|
|
179
|
+
"@tenphi/harnesspm": "^0.3.0",
|
|
180
180
|
"@testing-library/jest-dom": "^7.0.1",
|
|
181
181
|
"@testing-library/react": "^16.3.3",
|
|
182
182
|
"@types/node": "^24.19.1",
|