@tenphi/tasty 0.0.0-snapshot.b49ed29 → 0.0.0-snapshot.b4e384c
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 +403 -380
- package/dist/{babel-types-DpUCD2L_.d.ts → babel-types-Dc5zghyE.d.ts} +2 -2
- package/dist/chunks/{build-config-DQHNt7oV.js → build-config-D9Iq8QQm.js} +5 -5
- package/dist/chunks/{build-config-DQHNt7oV.js.map → build-config-D9Iq8QQm.js.map} +1 -1
- package/dist/chunks/{collector-CLJMa9_d.js → collector-Cb8ah2JF.js} +4 -4
- package/dist/chunks/{collector-CLJMa9_d.js.map → collector-Cb8ah2JF.js.map} +1 -1
- package/dist/chunks/{config-engine-DQTnjS4S.js → config-engine-CMYFZYQh.js} +5 -5
- package/dist/chunks/config-engine-CMYFZYQh.js.map +1 -0
- package/dist/chunks/{css-definitions-gzJPklRN.js → css-definitions-B4aWBkH3.js} +88 -78
- package/dist/chunks/css-definitions-B4aWBkH3.js.map +1 -0
- package/dist/chunks/{debug-XlLKYbjU.js → debug-D2Pu7Xhy.js} +4 -4
- package/dist/chunks/{debug-XlLKYbjU.js.map → debug-D2Pu7Xhy.js.map} +1 -1
- package/dist/chunks/{dsl-DRhFWQzo.js → dsl-CsFl9LGn.js} +132 -52
- package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
- package/dist/chunks/{react-runtime-CxMPs43X.js → react-runtime-DHiopXCu.js} +8 -6
- package/dist/chunks/react-runtime-DHiopXCu.js.map +1 -0
- package/dist/chunks/{runtime-engine-8qIHnb-B.js → runtime-engine-NGCofNXy.js} +11 -7
- package/dist/chunks/runtime-engine-NGCofNXy.js.map +1 -0
- package/dist/chunks/{runtime-state-BaSL1KZU.js → runtime-state-lZjMbvwV.js} +14 -3
- package/dist/chunks/runtime-state-lZjMbvwV.js.map +1 -0
- package/dist/chunks/{style-engine-DgP6pNeS.js → style-engine-DnkV_4Jg.js} +256 -95
- package/dist/chunks/style-engine-DnkV_4Jg.js.map +1 -0
- package/dist/chunks/{zero-engine-DvCd7ZUf.js → zero-engine-DcwaCvFs.js} +6 -6
- package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
- package/dist/{collector-D4POJ53X.d.ts → collector-D2OT6I2G.d.ts} +2 -2
- package/dist/{config-DvPUj4cw.d.ts → config-C4ftFxgI.d.ts} +13 -10
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +7 -7
- package/dist/{index-DC4q-xDq.d.ts → index-DxQNRj50.d.ts} +34 -16
- package/dist/index.d.ts +5 -5
- package/dist/index.js +8 -8
- package/dist/{merge-styles-Jb5iZ-Jf.d.ts → merge-styles-D39qBtox.d.ts} +2 -2
- package/dist/ssr/astro.js +2 -2
- package/dist/ssr/index.d.ts +1 -1
- package/dist/ssr/index.js +2 -2
- package/dist/ssr/next-config.d.ts +1 -1
- package/dist/ssr/next-config.js +3 -3
- package/dist/ssr/next.d.ts +1 -1
- package/dist/ssr/next.js +3 -3
- package/dist/static/index.d.ts +2 -2
- package/dist/{types-ZbF2_6LV.d.ts → types-CYQIhUg1.d.ts} +9 -7
- package/dist/zero/babel.d.ts +9 -3
- package/dist/zero/babel.js +8 -8
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +25 -6
- package/dist/zero/index.js +5 -4
- package/dist/zero/index.js.map +1 -1
- package/dist/zero/next.d.ts +1 -1
- package/docs/README.md +4 -1
- package/docs/adoption.md +25 -17
- package/docs/ai-agents.md +43 -34
- package/docs/comparison.md +9 -8
- package/docs/configuration.md +186 -68
- package/docs/debug.md +3 -2
- package/docs/design-system.md +117 -15
- package/docs/dsl.md +258 -116
- package/docs/getting-started.md +81 -24
- package/docs/injector.md +41 -40
- package/docs/methodology.md +46 -21
- package/docs/migration-v3.md +3 -3
- package/docs/pipeline.md +19 -16
- package/docs/plugins.md +21 -41
- package/docs/react-api.md +70 -14
- package/docs/runtime-benchmarks.md +4 -4
- package/docs/ssr.md +92 -66
- package/docs/styles.md +82 -16
- package/docs/tasty-static.md +143 -58
- package/package.json +32 -33
- package/dist/chunks/config-engine-DQTnjS4S.js.map +0 -1
- package/dist/chunks/css-definitions-gzJPklRN.js.map +0 -1
- package/dist/chunks/dsl-DRhFWQzo.js.map +0 -1
- package/dist/chunks/react-runtime-CxMPs43X.js.map +0 -1
- package/dist/chunks/runtime-engine-8qIHnb-B.js.map +0 -1
- package/dist/chunks/runtime-state-BaSL1KZU.js.map +0 -1
- package/dist/chunks/style-engine-DgP6pNeS.js.map +0 -1
- package/dist/chunks/zero-engine-DvCd7ZUf.js.map +0 -1
package/docs/tasty-static.md
CHANGED
|
@@ -8,30 +8,38 @@ Choose `tastyStatic` specifically when styles must be generated during the build
|
|
|
8
8
|
|
|
9
9
|
## When to Use
|
|
10
10
|
|
|
11
|
-
- **
|
|
12
|
-
- **No
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
11
|
+
- **CSS that must exist before anything renders** — static sites, landing pages, and HTML served from a CDN get one stylesheet generated at build time
|
|
12
|
+
- **No React at runtime** — `tastyStatic` returns class names, so plain DOM code or any templating that sets `class` can use them; the [Programmatic API](#programmatic-api) covers frameworks Babel does not process
|
|
13
|
+
- **Class-name objects instead of components** — extend them with `tastyStatic(base, styles)` and pass them wherever a `className` goes
|
|
14
|
+
- **Self-contained packages** — [inject mode](#inject-mode) embeds the CSS in the JavaScript, so consumers have no stylesheet to wire up
|
|
15
|
+
|
|
16
|
+
If the styles depend on props, keep `tasty()`: rendered only on the server, it also ships no styling runtime (see [Server-Side Rendering](ssr.md)).
|
|
15
17
|
|
|
16
18
|
## Requirements
|
|
17
19
|
|
|
18
20
|
Build-time extraction is part of the main `@tenphi/tasty` package but requires additional peer dependencies depending on your setup:
|
|
19
21
|
|
|
20
|
-
| Dependency | Version
|
|
21
|
-
| ---------------------------- |
|
|
22
|
-
| `@babel/core` |
|
|
23
|
-
| `@babel/helper-plugin-utils` |
|
|
24
|
-
| `@babel/types` |
|
|
25
|
-
| `jiti` | >= 2.6
|
|
22
|
+
| Dependency | Version | Required for |
|
|
23
|
+
| ---------------------------- | ---------------------- | ---------------------------------------------------- |
|
|
24
|
+
| `@babel/core` | 7.24+ or 8 | Babel plugin (`@tenphi/tasty/babel-plugin`) |
|
|
25
|
+
| `@babel/helper-plugin-utils` | 7.24+ or 8 | Babel plugin |
|
|
26
|
+
| `@babel/types` | 7.24+ or 8 | Babel plugin |
|
|
27
|
+
| `jiti` | >= 2.6 | `configFile` only (Babel plugin and Next.js wrapper) |
|
|
28
|
+
| `babel-loader` | any (10+ with Babel 8) | Next.js wrapper (`@tenphi/tasty/zero/next`) |
|
|
29
|
+
|
|
30
|
+
Install the three Babel packages from the same major. Babel 8 itself needs Node 22.18+ or 24.11+, and `babel-loader` accepts it from version 10.
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
The Babel packages and `jiti` are optional peer dependencies of `@tenphi/tasty`; `babel-loader` is resolved from your project. `jiti` is loaded only to read a `configFile`, so a setup that passes `config` directly does not need it; without it, `configFile` fails with an error that says to install it. Install what your setup requires:
|
|
28
33
|
|
|
29
34
|
```bash
|
|
30
|
-
#
|
|
35
|
+
# Any Babel-based setup (Vite, custom Babel config, etc.)
|
|
31
36
|
pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types
|
|
32
37
|
|
|
33
|
-
#
|
|
34
|
-
pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types
|
|
38
|
+
# Next.js
|
|
39
|
+
pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types babel-loader
|
|
40
|
+
|
|
41
|
+
# Either, with configFile
|
|
42
|
+
pnpm add -D jiti
|
|
35
43
|
```
|
|
36
44
|
|
|
37
45
|
---
|
|
@@ -52,13 +60,15 @@ const button = tastyStatic({
|
|
|
52
60
|
radius: '1r',
|
|
53
61
|
});
|
|
54
62
|
|
|
55
|
-
// Use in JSX
|
|
56
|
-
<button className={button}>Click me</button
|
|
63
|
+
// Use in JSX
|
|
64
|
+
<button className={button.className}>Click me</button>;
|
|
57
65
|
|
|
58
|
-
//
|
|
59
|
-
|
|
66
|
+
// toString() returns the class name, for template strings and plain JS
|
|
67
|
+
element.className = `${button} is-active`;
|
|
60
68
|
```
|
|
61
69
|
|
|
70
|
+
In TSX, pass `button.className`: React types `className` as `string`, so passing the `StaticStyle` object fails type-checking even though it works at runtime.
|
|
71
|
+
|
|
62
72
|
---
|
|
63
73
|
|
|
64
74
|
## API Reference
|
|
@@ -168,7 +178,7 @@ module.exports = {
|
|
|
168
178
|
| -------------------------- | ------------------------------------------------ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
169
179
|
| `output` | `string` | `'tasty.css'` | Path for generated CSS file |
|
|
170
180
|
| `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS (see [Inject Mode](#inject-mode)) |
|
|
171
|
-
| `configFile` | `string` | — | Absolute path to a TS/JS module that default-exports a `TastyZeroConfig` object. JSON-serializable alternative to `config` — required for Turbopack.
|
|
181
|
+
| `configFile` | `string` | — | Absolute path to a TS/JS module that default-exports a `TastyZeroConfig` object. JSON-serializable alternative to `config` — required for Turbopack. Loaded with the optional `jiti` peer. |
|
|
172
182
|
| `config` | `TastyZeroConfig \| () => TastyZeroConfig` | `{}` | Inline config object or factory function. Takes precedence over `configFile`. |
|
|
173
183
|
| `configDeps` | `string[]` | `[]` | Absolute file paths that affect config (for cache invalidation) |
|
|
174
184
|
| `injectImport` | `boolean` | `true` | Replace `@tenphi/tasty/static` imports with an import of the generated CSS file. Set to `false` to manage CSS imports manually. |
|
|
@@ -180,7 +190,8 @@ module.exports = {
|
|
|
180
190
|
| `config.keyframes` | `Record<string, KeyframesSteps>` | — | Global `@keyframes` definitions available to all `tastyStatic` calls |
|
|
181
191
|
| `config.fontFaces` | `Record<string, FontFaceInput>` | — | Global `@font-face` definitions |
|
|
182
192
|
| `config.counterStyles` | `Record<string, CounterStyleDescriptors>` | — | Global `@counter-style` definitions |
|
|
183
|
-
| `config.
|
|
193
|
+
| `config.properties` | `Record<string, PropertyDefinition>` | — | Global `@property` definitions, written with Tasty's [default properties](dsl.md#default-properties) |
|
|
194
|
+
| `config.units` | `Record<string, string \| UnitHandler>` | — | Custom units for the style parser (merged with built-ins). E.g. `{ u: 'var(--u)' }` makes `2u` compile to `calc(2 * var(--u))`. Native CSS units need no entry |
|
|
184
195
|
| `config.functions` | `Record<string, FunctionDefinition \| Function>` | — | Custom functions (merged). Bare keys → parse functions; `$$name` keys → declarative CSS `@function` definitions |
|
|
185
196
|
| `config.polyfills` | `{ functions?: boolean }` | `{}` | Opt-in polyfills. `functions: true` inlines `@function` calls into plain CSS at build time |
|
|
186
197
|
| `config.plugins` | `TastyPlugin[]` | — | Plugins that extend tasty with custom functions, units, states, and handlers |
|
|
@@ -244,7 +255,7 @@ const card = tastyStatic({
|
|
|
244
255
|
color: '#text',
|
|
245
256
|
});
|
|
246
257
|
|
|
247
|
-
<div className={card}>Styled card</div>;
|
|
258
|
+
<div className={card.className}>Styled card</div>;
|
|
248
259
|
```
|
|
249
260
|
|
|
250
261
|
---
|
|
@@ -281,12 +292,12 @@ export default withTastyZero({
|
|
|
281
292
|
|
|
282
293
|
Starting with Next.js 16, Turbopack is the default bundler. `withTastyZero` supports it out of the box by injecting `turbopack.rules` with `babel-loader` and JSON-serializable options.
|
|
283
294
|
|
|
284
|
-
The `configFile` option is key for Turbopack — it passes a file path (JSON-serializable) instead of a function, and the Babel plugin loads the config internally via jiti.
|
|
295
|
+
The `configFile` option is key for Turbopack — it passes a file path (JSON-serializable) instead of a function, and the Babel plugin loads the config internally via `jiti`, which must be installed.
|
|
285
296
|
|
|
286
|
-
**Requirements**: `babel-loader` must be installed in your project:
|
|
297
|
+
**Requirements**: `babel-loader` must be installed in your project (see [Requirements](#requirements)):
|
|
287
298
|
|
|
288
299
|
```bash
|
|
289
|
-
pnpm add babel-loader
|
|
300
|
+
pnpm add -D babel-loader
|
|
290
301
|
```
|
|
291
302
|
|
|
292
303
|
### CSS Injection
|
|
@@ -324,42 +335,84 @@ extractStylesWithChunks({ display: 'flex', gap: '1u' });
|
|
|
324
335
|
// → [{ className: 'ts…', css: '.ts….ts… { … }' }]
|
|
325
336
|
```
|
|
326
337
|
|
|
327
|
-
`configure()` takes the same options as the Babel plugin's `config` (see [Plugin Options](#plugin-options)) and replaces the previous configuration on each call; `resetConfig()` returns to the defaults. Options that shape the extracted rules apply — `states`, `units`, parse `functions`, `handlers`, `replaceTokens`, `recipes`, `plugins`, `namePrefix`. Definitions that become at-rules or global CSS of their own are not emitted: `tokens`, `globalStyles`, `fontFaces`, `counterStyles`, `properties` and `$$` `@function` definitions. Render tokens and global styles with `extractStylesForSelector(':root', tokens)` and `extractStylesForSelector(selector, styles)`.
|
|
338
|
+
`configure()` takes the same options as the Babel plugin's `config` (see [Plugin Options](#plugin-options)) and replaces the previous configuration on each call; `resetConfig()` returns to the defaults. Options that shape the extracted rules apply — `states`, `units`, parse `functions`, `handlers`, `replaceTokens`, `recipes`, `plugins`, `namePrefix`. Definitions that become at-rules or global CSS of their own are not emitted with the rules: `tokens`, `globalStyles`, `fontFaces`, `counterStyles`, `properties` and `$$` `@function` definitions. Render tokens and global styles with `extractStylesForSelector(':root', tokens)` and `extractStylesForSelector(selector, styles)`.
|
|
339
|
+
|
|
340
|
+
`extractConfigProperties()` returns the `@property` rules the Babel plugin writes at the top of its output: Tasty's [default set](dsl.md#default-properties) (`#border`, `#outline`, `$gap`, `$radius`, `$transition`, …) overlaid with the configured `properties`, or with the `properties` map you pass it. Emit them once per stylesheet. Style handlers read several of these tokens with no fallback of their own (`border: true` reads `#border`, `transition` reads `$transition`), so without them those declarations resolve to nothing.
|
|
328
341
|
|
|
329
342
|
The configuration is process-wide and shared with the Babel plugin and the runtime `configure()` from `@tenphi/tasty`. The extractors re-apply their own configuration when the Babel plugin replaced it, but not after a runtime `configure()` — don't mix the runtime and build-time configuration in one process.
|
|
330
343
|
|
|
331
344
|
`extractStylesForSelector()` output starts with the `@keyframes` its rules animate — local `@keyframes` and configured `keyframes` — under hashed names the `animation` declarations are rewritten to. `extractStylesWithChunks()` returns class rules only.
|
|
332
345
|
|
|
346
|
+
`mergeStyles()` merges style objects with the rules `tasty(Base, { styles })` extends by — state maps with and without a `''` key, `null`, `false`, `'@inherit'` and sub-elements (see [Extending vs. Replacing State Maps](dsl.md#extending-vs-replacing-state-maps)) — so a build script can layer overrides onto source styles before extracting them, without React:
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
import { extractStylesForSelector, mergeStyles } from '@tenphi/tasty/zero';
|
|
350
|
+
|
|
351
|
+
const styles = mergeStyles(checkboxStyles, {
|
|
352
|
+
Indicator: { radius: '0.5r' },
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
extractStylesForSelector('.checkbox', styles).css;
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
To write the results to a file the way the Babel plugin does, use `createCSSWriter()`. It deduplicates blocks by key and prepends the generated-file header:
|
|
359
|
+
|
|
360
|
+
```ts
|
|
361
|
+
import {
|
|
362
|
+
createCSSWriter,
|
|
363
|
+
extractConfigProperties,
|
|
364
|
+
extractStylesWithChunks,
|
|
365
|
+
} from '@tenphi/tasty/zero';
|
|
366
|
+
|
|
367
|
+
const writer = createCSSWriter('dist/tasty.css', { devMode: true });
|
|
368
|
+
|
|
369
|
+
for (const prop of extractConfigProperties()) {
|
|
370
|
+
writer.add(`@property:${prop.name}`, prop.css);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
for (const chunk of extractStylesWithChunks({ display: 'flex', gap: '1u' })) {
|
|
374
|
+
writer.add(chunk.className, chunk.css, 'src/card.ts'); // source is a devMode comment
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
writer.write(); // also: has(key), getCSS(), clear(), getOutputPath()
|
|
378
|
+
```
|
|
379
|
+
|
|
333
380
|
---
|
|
334
381
|
|
|
335
382
|
## Vite Integration
|
|
336
383
|
|
|
384
|
+
`@vitejs/plugin-react` 6 no longer runs Babel; add it with `@rolldown/plugin-babel` (`pnpm add -D @rolldown/plugin-babel`):
|
|
385
|
+
|
|
337
386
|
```typescript
|
|
338
387
|
// vite.config.ts
|
|
339
388
|
import { defineConfig } from 'vite';
|
|
340
389
|
import react from '@vitejs/plugin-react';
|
|
390
|
+
import babel from '@rolldown/plugin-babel';
|
|
341
391
|
|
|
342
392
|
export default defineConfig({
|
|
343
393
|
plugins: [
|
|
344
|
-
react(
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
},
|
|
394
|
+
react(),
|
|
395
|
+
babel({
|
|
396
|
+
plugins: [
|
|
397
|
+
[
|
|
398
|
+
'@tenphi/tasty/babel-plugin',
|
|
399
|
+
{
|
|
400
|
+
output: 'src/tasty.css',
|
|
401
|
+
config: {
|
|
402
|
+
states: { '@mobile': '@media(w < 768px)' },
|
|
354
403
|
},
|
|
355
|
-
|
|
404
|
+
},
|
|
356
405
|
],
|
|
357
|
-
|
|
406
|
+
],
|
|
358
407
|
}),
|
|
359
408
|
],
|
|
360
409
|
});
|
|
361
410
|
```
|
|
362
411
|
|
|
412
|
+
With `@vitejs/plugin-react` 5 or older, pass the same `plugins` array to `react({ babel: { plugins } })` instead.
|
|
413
|
+
|
|
414
|
+
Keep `output` outside `public/`: the plugin replaces each `@tenphi/tasty/static` import with an import of the generated file, and Vite does not let JavaScript import files from `public/`. Vite then bundles the CSS like any other stylesheet.
|
|
415
|
+
|
|
363
416
|
---
|
|
364
417
|
|
|
365
418
|
## Build Transformation
|
|
@@ -377,44 +430,67 @@ const button = tastyStatic({
|
|
|
377
430
|
|
|
378
431
|
tastyStatic('.heading', { preset: 'h1' });
|
|
379
432
|
|
|
380
|
-
export const Button = () => <button className={button}>Click</button>;
|
|
433
|
+
export const Button = () => <button className={button.className}>Click</button>;
|
|
381
434
|
```
|
|
382
435
|
|
|
383
436
|
### After (Production Build)
|
|
384
437
|
|
|
385
438
|
```tsx
|
|
439
|
+
import './tasty.css';
|
|
440
|
+
|
|
386
441
|
const button = {
|
|
387
|
-
className: '
|
|
442
|
+
className: 'ts3f783b ts070801',
|
|
388
443
|
styles: { padding: '2x 4x', fill: '#purple', color: '#white' },
|
|
389
444
|
toString() {
|
|
390
445
|
return this.className;
|
|
391
446
|
},
|
|
392
447
|
};
|
|
393
448
|
|
|
394
|
-
export const Button = () => <button className={button}>Click</button>;
|
|
449
|
+
export const Button = () => <button className={button.className}>Click</button>;
|
|
395
450
|
```
|
|
396
451
|
|
|
452
|
+
The `@tenphi/tasty/static` import becomes an import of the generated file (relative to the source file), and the selector-mode call is removed.
|
|
453
|
+
|
|
397
454
|
### Generated CSS (tasty.css)
|
|
398
455
|
|
|
399
456
|
```css
|
|
400
457
|
/* Generated by @tenphi/tasty/zero - DO NOT EDIT */
|
|
401
458
|
|
|
402
|
-
|
|
403
|
-
|
|
459
|
+
@property --tasty-second-fill-color {
|
|
460
|
+
syntax: '<color>';
|
|
461
|
+
inherits: false;
|
|
462
|
+
initial-value: transparent;
|
|
404
463
|
}
|
|
405
464
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
465
|
+
@property --current-color {
|
|
466
|
+
syntax: '<color>';
|
|
467
|
+
inherits: true;
|
|
468
|
+
initial-value: currentcolor;
|
|
409
469
|
}
|
|
410
470
|
|
|
411
|
-
.
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
471
|
+
/* …the rest of Tasty's default @property rules (--white-color, --border-color, --gap, --transition, …), then config.properties */
|
|
472
|
+
|
|
473
|
+
.ts3f783b.ts3f783b {
|
|
474
|
+
color: var(--white-color);
|
|
475
|
+
--current-color: var(--white-color);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
.ts3f783b.ts3f783b {
|
|
479
|
+
background-color: var(--purple-color);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
.ts070801.ts070801 {
|
|
483
|
+
padding: 16px 32px;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
.heading {
|
|
487
|
+
font-size: var(--h1-font-size, var(--default-font-size));
|
|
488
|
+
/* …line-height, letter-spacing, font-weight, and the rest of the h1 preset */
|
|
415
489
|
}
|
|
416
490
|
```
|
|
417
491
|
|
|
492
|
+
The file starts with Tasty's [default `@property` rules](dsl.md#default-properties) and your `config.properties`, written once. Styles are split into chunks (here appearance and spacing), each with its own class. Color tokens compile to custom properties: `#purple` becomes `var(--purple-color)`. Define it in `config.tokens` and the plugin writes it to `:root` at the top of the same file. Units are literal (`2x` is `16px`). Selector-mode rules use the selector as written, without the doubled specificity of class rules.
|
|
493
|
+
|
|
418
494
|
---
|
|
419
495
|
|
|
420
496
|
## Inject Mode
|
|
@@ -485,22 +561,29 @@ tastyStatic('.heading', { preset: 'h1' });
|
|
|
485
561
|
```tsx
|
|
486
562
|
import { injectCSS as _$i } from '@tenphi/tasty/static/inject';
|
|
487
563
|
|
|
564
|
+
_$i(
|
|
565
|
+
'@property',
|
|
566
|
+
'@property --tasty-second-fill-color { … }\n@property --current-color { … }\n…',
|
|
567
|
+
);
|
|
568
|
+
|
|
488
569
|
const button =
|
|
489
570
|
(_$i(
|
|
490
|
-
'
|
|
491
|
-
'.
|
|
571
|
+
'tsa903d6 ts070801',
|
|
572
|
+
'.tsa903d6.tsa903d6 { background-color: var(--purple-color); }\n.ts070801.ts070801 { padding: 16px 32px; }',
|
|
492
573
|
),
|
|
493
574
|
{
|
|
494
|
-
className: '
|
|
575
|
+
className: 'tsa903d6 ts070801',
|
|
495
576
|
styles: { padding: '2x 4x', fill: '#purple' },
|
|
496
577
|
toString() {
|
|
497
578
|
return this.className;
|
|
498
579
|
},
|
|
499
580
|
});
|
|
500
581
|
|
|
501
|
-
_$i('.heading', '.heading{font-size:
|
|
582
|
+
_$i('.heading', '.heading { font-size: var(--h1-font-size, …); … }');
|
|
502
583
|
```
|
|
503
584
|
|
|
585
|
+
Each file that calls `tastyStatic()` starts by injecting Tasty's default `@property` rules and your `config.properties` under the `@property` id. `injectCSS()` skips an id it has already injected, so the page gets them once.
|
|
586
|
+
|
|
504
587
|
### Dev Mode / HMR
|
|
505
588
|
|
|
506
589
|
Class names are content-hashed (`ts` + MD5). When styles change, a new hash produces a new `_$i` call that injects fresh CSS. The injector deduplicates by id, so unchanged styles are skipped. Old CSS stays in the DOM but is harmless since no elements reference those class names.
|
|
@@ -558,7 +641,7 @@ const card = tastyStatic({
|
|
|
558
641
|
|
|
559
642
|
## Extending Style Types (TypeScript)
|
|
560
643
|
|
|
561
|
-
If you add custom style properties, use module augmentation so `tastyStatic` recognizes them too. See [
|
|
644
|
+
If you add custom style properties, use module augmentation so `tastyStatic` recognizes them too. See [TypeScript](configuration.md#typescript) in the configuration docs.
|
|
562
645
|
|
|
563
646
|
---
|
|
564
647
|
|
|
@@ -580,10 +663,12 @@ const card = tastyStatic({
|
|
|
580
663
|
});
|
|
581
664
|
|
|
582
665
|
<div
|
|
583
|
-
className={card}
|
|
584
|
-
style={
|
|
585
|
-
|
|
586
|
-
|
|
666
|
+
className={card.className}
|
|
667
|
+
style={
|
|
668
|
+
{
|
|
669
|
+
'--card-bg': isActive ? 'var(--purple-color)' : 'var(--white-color)',
|
|
670
|
+
} as React.CSSProperties
|
|
671
|
+
}
|
|
587
672
|
/>;
|
|
588
673
|
```
|
|
589
674
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tenphi/tasty",
|
|
3
|
-
"version": "0.0.0-snapshot.
|
|
3
|
+
"version": "0.0.0-snapshot.b4e384c",
|
|
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",
|
|
@@ -126,8 +126,8 @@
|
|
|
126
126
|
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
127
127
|
"format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
|
|
128
128
|
"size": "size-limit",
|
|
129
|
-
"bench": "vitest bench --project node",
|
|
130
|
-
"bench:browser": "vitest bench --project browser",
|
|
129
|
+
"bench": "vitest bench --project \"node (bench)\"",
|
|
130
|
+
"bench:browser": "vitest bench --project \"browser (chromium) (bench)\"",
|
|
131
131
|
"bench:overhead": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-overhead.bench.tsx",
|
|
132
132
|
"bench:injection": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-injection.bench.ts",
|
|
133
133
|
"bench:interaction": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-interaction.bench.tsx",
|
|
@@ -140,6 +140,7 @@
|
|
|
140
140
|
"knip": "knip",
|
|
141
141
|
"check:build": "node scripts/check-built-entries.mjs",
|
|
142
142
|
"check:react-compat": "node scripts/check-react-compat.mjs",
|
|
143
|
+
"check:babel-compat": "node scripts/check-babel-compat.mjs",
|
|
143
144
|
"check:test-only": "node scripts/check-test-only-code.mjs",
|
|
144
145
|
"hygiene": "pnpm lint && pnpm format:check && pnpm typecheck",
|
|
145
146
|
"hygiene:fix": "pnpm lint:fix && pnpm format && pnpm typecheck"
|
|
@@ -166,9 +167,9 @@
|
|
|
166
167
|
},
|
|
167
168
|
"homepage": "https://github.com/tenphi/tasty#readme",
|
|
168
169
|
"peerDependencies": {
|
|
169
|
-
"@babel/core": "^7.24.0",
|
|
170
|
-
"@babel/helper-plugin-utils": "^7.24.0",
|
|
171
|
-
"@babel/types": "^7.24.0",
|
|
170
|
+
"@babel/core": "^7.24.0 || ^8.0.0",
|
|
171
|
+
"@babel/helper-plugin-utils": "^7.24.0 || ^8.0.0",
|
|
172
|
+
"@babel/types": "^7.24.0 || ^8.0.0",
|
|
172
173
|
"jiti": "^2.6.1",
|
|
173
174
|
"next": ">=14.0.0",
|
|
174
175
|
"react": "^18.0.0 || ^19.0.0"
|
|
@@ -197,40 +198,38 @@
|
|
|
197
198
|
"csstype": "^3.1.0"
|
|
198
199
|
},
|
|
199
200
|
"devDependencies": {
|
|
200
|
-
"@astrojs/react": "^7.0.
|
|
201
|
-
"@babel/core": "^
|
|
202
|
-
"@babel/helper-plugin-utils": "^
|
|
203
|
-
"@babel/types": "^
|
|
201
|
+
"@astrojs/react": "^7.0.1",
|
|
202
|
+
"@babel/core": "^8.0.6",
|
|
203
|
+
"@babel/helper-plugin-utils": "^8.0.1",
|
|
204
|
+
"@babel/types": "^8.0.6",
|
|
204
205
|
"@changesets/changelog-github": "^1.0.1",
|
|
205
206
|
"@changesets/cli": "^3.0.3",
|
|
206
207
|
"@eslint/js": "^10.0.1",
|
|
207
|
-
"@size-limit/esbuild": "^14.
|
|
208
|
-
"@size-limit/file": "^14.
|
|
209
|
-
"@tenphi/eslint-plugin-tasty": "^1.
|
|
208
|
+
"@size-limit/esbuild": "^14.1.0",
|
|
209
|
+
"@size-limit/file": "^14.1.0",
|
|
210
|
+
"@tenphi/eslint-plugin-tasty": "^1.15.0",
|
|
210
211
|
"@testing-library/jest-dom": "^7.0.1",
|
|
211
212
|
"@testing-library/react": "^16.3.3",
|
|
212
|
-
"@types/
|
|
213
|
-
"@types/babel__helper-plugin-utils": "^7.10.3",
|
|
214
|
-
"@types/node": "^24.13.6",
|
|
213
|
+
"@types/node": "^24.19.1",
|
|
215
214
|
"@types/react": "^19.3.0",
|
|
216
215
|
"@types/react-dom": "^19.3.0",
|
|
217
|
-
"@vitest/browser-playwright": "^
|
|
218
|
-
"astro": "^7.3.
|
|
216
|
+
"@vitest/browser-playwright": "^5.0.3",
|
|
217
|
+
"astro": "^7.3.6",
|
|
219
218
|
"esbuild": "^0.28.2",
|
|
220
|
-
"eslint": "^10.
|
|
219
|
+
"eslint": "^10.12.0",
|
|
221
220
|
"eslint-config-prettier": "^10.1.8",
|
|
222
221
|
"jiti": "^2.7.0",
|
|
223
|
-
"knip": "^6.
|
|
224
|
-
"next": "^16.
|
|
222
|
+
"knip": "^6.40.0",
|
|
223
|
+
"next": "^16.4.0",
|
|
225
224
|
"playwright": "^1.63.0",
|
|
226
225
|
"prettier": "^3.9.9",
|
|
227
226
|
"react": "^19.3.0",
|
|
228
227
|
"react-dom": "^19.3.0",
|
|
229
|
-
"size-limit": "^14.
|
|
228
|
+
"size-limit": "^14.1.0",
|
|
230
229
|
"tsdown": "^0.23.0",
|
|
231
230
|
"typescript": "^6.0.3",
|
|
232
|
-
"typescript-eslint": "^8.
|
|
233
|
-
"vitest": "^
|
|
231
|
+
"typescript-eslint": "^8.71.1",
|
|
232
|
+
"vitest": "^5.0.3"
|
|
234
233
|
},
|
|
235
234
|
"packageManager": "pnpm@11.27.1",
|
|
236
235
|
"size-limit": [
|
|
@@ -238,37 +237,37 @@
|
|
|
238
237
|
"name": "main (import *)",
|
|
239
238
|
"path": "dist/index.js",
|
|
240
239
|
"import": "*",
|
|
241
|
-
"limit": "
|
|
240
|
+
"limit": "62.08 kB"
|
|
242
241
|
},
|
|
243
242
|
{
|
|
244
243
|
"name": "main (tasty)",
|
|
245
244
|
"path": "dist/index.js",
|
|
246
245
|
"import": "{ tasty }",
|
|
247
|
-
"limit": "
|
|
246
|
+
"limit": "54.99 kB"
|
|
248
247
|
},
|
|
249
248
|
{
|
|
250
249
|
"name": "main (StyleParser)",
|
|
251
250
|
"path": "dist/index.js",
|
|
252
251
|
"import": "{ StyleParser }",
|
|
253
|
-
"limit": "
|
|
252
|
+
"limit": "8 kB"
|
|
254
253
|
},
|
|
255
254
|
{
|
|
256
255
|
"name": "main (parseColor)",
|
|
257
256
|
"path": "dist/index.js",
|
|
258
257
|
"import": "{ parseColor }",
|
|
259
|
-
"limit": "
|
|
258
|
+
"limit": "8.67 kB"
|
|
260
259
|
},
|
|
261
260
|
{
|
|
262
261
|
"name": "main (useRawCSS)",
|
|
263
262
|
"path": "dist/index.js",
|
|
264
263
|
"import": "{ useRawCSS }",
|
|
265
|
-
"limit": "
|
|
264
|
+
"limit": "33.63 kB"
|
|
266
265
|
},
|
|
267
266
|
{
|
|
268
267
|
"name": "core (import *)",
|
|
269
268
|
"path": "dist/core/index.js",
|
|
270
269
|
"import": "*",
|
|
271
|
-
"limit": "
|
|
270
|
+
"limit": "57.38 kB"
|
|
272
271
|
},
|
|
273
272
|
{
|
|
274
273
|
"name": "static",
|
|
@@ -285,7 +284,7 @@
|
|
|
285
284
|
"path",
|
|
286
285
|
"crypto"
|
|
287
286
|
],
|
|
288
|
-
"limit": "
|
|
287
|
+
"limit": "41.3 kB"
|
|
289
288
|
},
|
|
290
289
|
{
|
|
291
290
|
"name": "babel-plugin",
|
|
@@ -298,7 +297,7 @@
|
|
|
298
297
|
"node:module",
|
|
299
298
|
"node:path"
|
|
300
299
|
],
|
|
301
|
-
"limit": "
|
|
300
|
+
"limit": "45.95 kB"
|
|
302
301
|
},
|
|
303
302
|
{
|
|
304
303
|
"name": "astro client",
|
|
@@ -322,7 +321,7 @@
|
|
|
322
321
|
"node:module",
|
|
323
322
|
"node:path"
|
|
324
323
|
],
|
|
325
|
-
"limit": "
|
|
324
|
+
"limit": "41.48 kB"
|
|
326
325
|
}
|
|
327
326
|
]
|
|
328
327
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-engine-DQTnjS4S.js","names":[],"sources":["../../src/utils/typography.ts","../../src/config-normalize.ts","../../src/utils/resolve-recipes-core.ts"],"sourcesContent":["import type { ConfigTokens } from '../styles/types';\n\nconst RESERVED_PRESET_NAMES = new Set([\n 'strong',\n 'bold',\n 'italic',\n 'icon',\n 'tight',\n]);\n\n/**\n * A typography token value: plain value or a state map for responsive/theme-aware presets.\n *\n * @example\n * // Plain value\n * fontWeight: '400'\n * // State map\n * fontWeight: { '': '400', '@dark': '300' }\n */\nexport type TypographyTokenValue =\n | string\n | number\n | Record<string, string | number | undefined | null | '@inherit'>;\n\n/**\n * Typography preset configuration.\n * Each preset defines font properties that get expanded into CSS custom properties.\n * All fields accept plain values or state maps for responsive/theme-aware tokens.\n *\n * Use with `generateTypographyTokens()` to create typography tokens for your design system.\n */\nexport interface TypographyPreset {\n fontSize: TypographyTokenValue;\n lineHeight: TypographyTokenValue;\n letterSpacing?: TypographyTokenValue;\n fontWeight: TypographyTokenValue;\n boldFontWeight?: TypographyTokenValue;\n iconSize?: TypographyTokenValue;\n textTransform?: TypographyTokenValue;\n fontFamily?: TypographyTokenValue;\n fontStyle?: TypographyTokenValue;\n}\n\n/**\n * Generate typography tokens with $ prefix for CSS custom properties.\n *\n * Each preset generates the following CSS custom properties:\n * - `${name}-font-size`\n * - `${name}-line-height`\n * - `${name}-letter-spacing`\n * - `${name}-font-weight`\n * - `${name}-bold-font-weight` (if defined)\n * - `${name}-icon-size` (if defined)\n * - `${name}-text-transform` (if defined)\n * - `${name}-font-family` (if defined)\n * - `${name}-font-style` (if defined)\n *\n * @param presets - Typography presets object\n * @returns ConfigTokens object with $ prefixed keys\n *\n * @example\n * const customTokens = generateTypographyTokens({\n * myHeading: { fontSize: '24px', lineHeight: '32px', fontWeight: '700' },\n * body: { fontSize: '16px', lineHeight: '24px', fontWeight: '400' },\n * });\n */\nexport function generateTypographyTokens(\n presets: Record<string, TypographyPreset>,\n): ConfigTokens {\n const tokens: ConfigTokens = {} as ConfigTokens;\n\n for (const [name, preset] of Object.entries(presets)) {\n if (RESERVED_PRESET_NAMES.has(name)) {\n throw new Error(\n `Invalid typography preset name \"${name}\". This name is reserved as a preset modifier.`,\n );\n }\n\n tokens[`$${name}-font-size`] = preset.fontSize;\n tokens[`$${name}-line-height`] = preset.lineHeight;\n tokens[`$${name}-letter-spacing`] = preset.letterSpacing ?? 'normal';\n tokens[`$${name}-font-weight`] = preset.fontWeight;\n\n if (preset.boldFontWeight !== undefined) {\n tokens[`$${name}-bold-font-weight`] = preset.boldFontWeight;\n }\n\n if (preset.iconSize !== undefined) {\n tokens[`$${name}-icon-size`] = preset.iconSize;\n }\n\n if (preset.textTransform !== undefined) {\n tokens[`$${name}-text-transform`] = preset.textTransform;\n }\n\n if (preset.fontFamily !== undefined) {\n tokens[`$${name}-font-family`] = preset.fontFamily;\n }\n\n if (preset.fontStyle !== undefined) {\n tokens[`$${name}-font-style`] = preset.fontStyle;\n }\n }\n\n return tokens;\n}\n","/**\n * Configuration processing shared by runtime and build-time paths.\n *\n * Plugins are folded first and direct configuration wins. Keeping this step\n * independent from the DOM injector lets zero-runtime tooling reuse the exact\n * same precedence and style-engine setup without loading browser infrastructure.\n */\n\nimport { registerFunctionPolyfill, splitFunctions } from './functions';\nimport {\n isFunctionsPolyfillEnabled,\n setGlobalPolyfillsState,\n} from './config-state';\nimport { setGlobalPredefinedStates } from './states';\nimport {\n normalizeHandlerDefinition,\n registerHandler,\n} from './styles/predefined';\nimport {\n CUSTOM_UNITS,\n getGlobalParseFunctions,\n getGlobalParser,\n normalizeColorTokenValue,\n setGlobalPredefinedTokens,\n} from './utils/styles';\nimport { generateTypographyTokens } from './utils/typography';\n\nimport type { TastyConfig } from './config';\nimport type { FunctionsConfig } from './functions';\nimport type {\n CounterStyleDescriptors,\n FontFaceInput,\n FunctionDefinition,\n KeyframesSteps,\n PropertyDefinition,\n} from './injector/types';\nimport type { UnitHandler } from './parser/types';\nimport type { PropHandlerDefinition } from './prop-handlers';\nimport type { ConfigTokens, RecipeStyles, Styles } from './styles/types';\nimport type { StyleHandlerDefinition } from './utils/styles';\nimport type { TypographyPreset } from './utils/typography';\n\nexport interface NormalizedConfig {\n states: Record<string, string>;\n units: Record<string, string | UnitHandler>;\n functions: FunctionsConfig;\n handlers: Record<string, StyleHandlerDefinition>;\n handlerSources: Map<string, string>;\n propHandlers: Record<string, PropHandlerDefinition>;\n propHandlerSources: Map<string, string>;\n baseStyleProps: string[];\n properties: Record<string, PropertyDefinition>;\n keyframes: Record<string, KeyframesSteps>;\n fontFaces: Record<string, FontFaceInput>;\n counterStyles: Record<string, CounterStyleDescriptors>;\n replaceTokens: Record<string, string | number | boolean>;\n tokens: ConfigTokens;\n recipes: Record<string, RecipeStyles>;\n globalStyles: Record<string, Styles>;\n}\n\ntype WarnOnce = (key: string, message: string) => void;\n\n/** Apply parser and style-engine configuration shared by every renderer. */\nexport function applyStyleConfig(\n config: Partial<TastyConfig>,\n normalized: NormalizedConfig,\n warnOnce: WarnOnce,\n): Record<string, FunctionDefinition> {\n const tokenKeys = new Set(Object.keys(normalized.tokens));\n for (const key of Object.keys(normalized.replaceTokens)) {\n if (tokenKeys.has(key)) {\n warnOnce(\n `token-conflict-${key}`,\n `[Tasty] Token \"${key}\" is defined in both \\`tokens\\` and \\`replaceTokens\\`. ` +\n `\\`replaceTokens\\` performs parse-time substitution, so the \\`tokens\\` ` +\n `CSS custom property will be injected but never used by Tasty styles. ` +\n `Remove it from one of the two.`,\n );\n }\n }\n\n if (config.colorSpace) {\n warnOnce(\n 'colorSpace-deprecated',\n '[Tasty] configure({ colorSpace }) no longer has any effect and will be ' +\n 'removed in the next major. Colors are emitted as authored, and opacity ' +\n \"is applied with relative color syntax, which reads a color's channels \" +\n 'in the browser. To address channels yourself, write ' +\n '`oklch(from var(--name-color) l c h)` against the token.',\n );\n }\n\n if (Object.keys(normalized.states).length > 0) {\n setGlobalPredefinedStates(normalized.states);\n }\n\n const parser = getGlobalParser();\n if (config.parserCacheSize !== undefined) {\n parser.updateOptions({ cacheSize: config.parserCacheSize });\n }\n if (Object.keys(normalized.units).length > 0) {\n const currentUnits = parser.getUnits() ?? CUSTOM_UNITS;\n parser.setUnits({ ...currentUnits, ...normalized.units });\n }\n\n if (config.polyfills) setGlobalPolyfillsState(config.polyfills);\n\n const { parseFuncs, functionDefs } = splitFunctions(\n normalized.functions,\n (key, kind) => {\n warnOnce(\n `functions-mismatch-${key}`,\n kind === 'expected-definition'\n ? `[Tasty] functions[\"${key}\"]: a \"$$\"-prefixed key denotes a CSS @function ` +\n `and expects a definition object, but received a function. Entry ignored.`\n : `[Tasty] functions[\"${key}\"]: a bare key denotes a parse function and ` +\n `expects a function value, but received an object. ` +\n `Did you mean \"$$${key}\"? Entry ignored.`,\n );\n },\n );\n\n if (Object.keys(parseFuncs).length > 0) {\n const currentFuncs = getGlobalParseFunctions();\n parser.setFunctions({ ...currentFuncs, ...parseFuncs });\n Object.assign(currentFuncs, parseFuncs);\n }\n\n if (isFunctionsPolyfillEnabled()) {\n for (const [name, definition] of Object.entries(functionDefs)) {\n registerFunctionPolyfill(name, definition);\n }\n }\n\n for (const [name, definition] of Object.entries(normalized.handlers)) {\n const handler = normalizeHandlerDefinition(name, definition);\n registerHandler(handler, {\n key: name,\n source: normalized.handlerSources.get(name),\n });\n }\n\n if (Object.keys(normalized.replaceTokens).length > 0) {\n const processedTokens: Record<string, string> = {};\n for (const [key, value] of Object.entries(normalized.replaceTokens)) {\n if (key.startsWith('#')) {\n const normalizedValue = normalizeColorTokenValue(value);\n if (normalizedValue === null) continue;\n processedTokens[key] = String(normalizedValue);\n } else if (value !== false) {\n processedTokens[key] = String(value);\n }\n }\n setGlobalPredefinedTokens(processedTokens);\n }\n\n return functionDefs;\n}\n\n/** Merge an optional configuration record into an accumulated record. */\nfunction mergeRecord<T extends object>(target: T, source?: Partial<T>): T {\n return source ? { ...target, ...source } : target;\n}\n\n/** Merge a named extension record and retain where each winning entry came from. */\nfunction mergeSourcedRecord<T>(\n target: Record<string, T>,\n source: Record<string, T> | undefined,\n sources: Map<string, string>,\n pluginName?: string,\n): Record<string, T> {\n if (!source) return target;\n\n const label =\n pluginName === undefined ? 'configure()' : `plugin \"${pluginName}\"`;\n for (const key of Object.keys(source)) sources.set(key, label);\n\n return { ...target, ...source };\n}\n\nexport function normalizeConfig(\n config: Partial<TastyConfig>,\n): NormalizedConfig {\n let states: Record<string, string> = {};\n let units: Record<string, string | UnitHandler> = {};\n let functions: FunctionsConfig = {};\n let handlers: Record<string, StyleHandlerDefinition> = {};\n const handlerSources = new Map<string, string>();\n let propHandlers: Record<string, PropHandlerDefinition> = {};\n const propHandlerSources = new Map<string, string>();\n const baseStyleProps: string[] = [];\n let properties: Record<string, PropertyDefinition> = {};\n let keyframes: Record<string, KeyframesSteps> = {};\n let fontFaces: Record<string, FontFaceInput> = {};\n let counterStyles: Record<string, CounterStyleDescriptors> = {};\n let replaceTokens: Record<string, string | number | boolean> = {};\n let tokens: ConfigTokens = {} as ConfigTokens;\n let recipes: Record<string, RecipeStyles> = {};\n let presets: Record<string, TypographyPreset> = {};\n const globalStyles: Record<string, Styles> = {};\n\n for (const plugin of config.plugins ?? []) {\n states = mergeRecord(states, plugin.states);\n units = mergeRecord(units, plugin.units);\n functions = mergeRecord(functions, plugin.functions);\n handlers = mergeSourcedRecord(\n handlers,\n plugin.handlers,\n handlerSources,\n plugin.name,\n );\n propHandlers = mergeSourcedRecord(\n propHandlers,\n plugin.propHandlers,\n propHandlerSources,\n plugin.name,\n );\n if (plugin.baseStyleProps) baseStyleProps.push(...plugin.baseStyleProps);\n properties = mergeRecord(properties, plugin.properties);\n keyframes = mergeRecord(keyframes, plugin.keyframes);\n fontFaces = mergeRecord(fontFaces, plugin.fontFaces);\n counterStyles = mergeRecord(counterStyles, plugin.counterStyles);\n replaceTokens = mergeRecord(replaceTokens, plugin.replaceTokens);\n tokens = mergeRecord(tokens, plugin.tokens);\n recipes = mergeRecord(recipes, plugin.recipes);\n presets = mergeRecord(presets, plugin.presets);\n mergeGlobalStyles(globalStyles, plugin.globalStyles);\n }\n\n states = mergeRecord(states, config.states);\n units = mergeRecord(units, config.units);\n functions = mergeRecord(functions, config.functions);\n handlers = mergeSourcedRecord(handlers, config.handlers, handlerSources);\n propHandlers = mergeSourcedRecord(\n propHandlers,\n config.propHandlers,\n propHandlerSources,\n );\n if (config.baseStyleProps) baseStyleProps.push(...config.baseStyleProps);\n properties = mergeRecord(properties, config.properties);\n keyframes = mergeRecord(keyframes, config.keyframes);\n fontFaces = mergeRecord(fontFaces, config.fontFaces);\n counterStyles = mergeRecord(counterStyles, config.counterStyles);\n replaceTokens = mergeRecord(replaceTokens, config.replaceTokens);\n presets = mergeRecord(presets, config.presets);\n\n if (Object.keys(presets).length > 0) {\n tokens = { ...generateTypographyTokens(presets), ...tokens };\n }\n\n tokens = mergeRecord(tokens, config.tokens);\n recipes = mergeRecord(recipes, config.recipes);\n mergeGlobalStyles(globalStyles, config.globalStyles);\n\n return {\n states,\n units,\n functions,\n handlers,\n handlerSources,\n propHandlers,\n propHandlerSources,\n baseStyleProps,\n properties,\n keyframes,\n fontFaces,\n counterStyles,\n replaceTokens,\n tokens,\n recipes,\n globalStyles,\n };\n}\n\nfunction mergeGlobalStyles(\n target: Record<string, Styles>,\n source?: Record<string, Styles>,\n): void {\n if (!source) return;\n\n for (const [selector, styles] of Object.entries(source)) {\n target[selector] = target[selector]\n ? { ...target[selector], ...styles }\n : styles;\n }\n}\n","/**\n * Recipe resolution utility.\n *\n * Resolves `recipe` style properties by looking up predefined recipe styles\n * from global configuration and merging them with the component's own styles.\n *\n * Resolution order per level (top-level and each sub-element independently):\n * base_recipe_1 base_recipe_2 → component styles → post_recipe_1 post_recipe_2\n *\n * The `/` separator splits base recipes (before component styles)\n * from post recipes (after component styles). All merges use mergeStyles\n * semantics: primitives and state maps with '' key fully replace;\n * state maps without '' key extend the existing value.\n *\n * Returns the same object reference if no recipes are present (zero overhead).\n */\n\nimport type { RecipeStyles, Styles } from '../styles/types';\n\nimport { isDevEnv } from './is-dev-env';\nimport { isSelector } from './is-selector';\nimport { mergeStyles } from './merge-styles';\n\nconst devMode = isDevEnv();\n\ninterface ParsedRecipeGroups {\n base: string[] | null;\n post: string[] | null;\n}\n\n/**\n * Parse a recipe string into base and post recipe name groups.\n *\n * Syntax: `'base1 base2 / post1 post2'`\n * - Names are space-separated within each group\n * - `/` separates base (before component) from post (after component) groups\n * - `/` is optional; if absent, all names are base\n * - `none` as the sole base value means \"no base recipes\"\n *\n * Returns `{ base: null, post: null }` if the string is empty or invalid.\n */\nfunction parseRecipeNames(value: unknown): ParsedRecipeGroups {\n const empty: ParsedRecipeGroups = { base: null, post: null };\n\n if (typeof value !== 'string') return empty;\n const trimmed = value.trim();\n if (trimmed === '') return empty;\n\n const slashIndex = trimmed.indexOf('/');\n\n if (slashIndex === -1) {\n if (trimmed === 'none') return empty;\n const names = splitNames(trimmed);\n return { base: names, post: null };\n }\n\n const basePart = trimmed.slice(0, slashIndex);\n const postPart = trimmed.slice(slashIndex + 1);\n\n return {\n base: basePart.trim() === 'none' ? null : splitNames(basePart),\n post: splitNames(postPart),\n };\n}\n\nfunction splitNames(s: string): string[] | null {\n const names = s.split(/\\s+/).filter(Boolean);\n return names.length > 0 ? names : null;\n}\n\n/**\n * Collect merged styles for a list of recipe names.\n * Each recipe is flat-spread on top of the previous.\n */\nfunction collectRecipeStyles(\n names: string[],\n recipes: Record<string, RecipeStyles>,\n): Record<string, unknown> {\n let merged: Record<string, unknown> = {};\n\n for (const name of names) {\n const recipeStyles = recipes[name];\n\n if (!recipeStyles) {\n if (devMode) {\n console.warn(\n `[Tasty] Recipe \"${name}\" not found. ` +\n `Make sure it is defined in configure({ recipes: { ... } }).`,\n );\n }\n continue;\n }\n\n merged = { ...merged, ...(recipeStyles as Record<string, unknown>) };\n }\n\n return merged;\n}\n\n/**\n * Resolve recipe references in a flat styles object (no sub-elements).\n * Returns null if no `recipe` key is present.\n *\n * Resolution: base recipes → component styles → post recipes (all via mergeStyles)\n */\nfunction resolveRecipesForLevel(\n styles: Record<string, unknown>,\n recipes: Record<string, RecipeStyles>,\n): Record<string, unknown> | null {\n if (!('recipe' in styles)) return null;\n\n const { base, post } = parseRecipeNames(styles.recipe);\n\n // Separate selector keys (sub-elements) from flat style properties.\n // mergeStyles handles selectors with its own semantics (e.g. false = delete),\n // but at this level we only want recipe merging on flat properties.\n\n const { recipe: _recipe, ...allRest } = styles;\n const flatStyles: Record<string, unknown> = {};\n const selectorStyles: Record<string, unknown> = {};\n\n for (const key of Object.keys(allRest)) {\n if (isSelector(key)) {\n selectorStyles[key] = allRest[key];\n } else {\n flatStyles[key] = allRest[key];\n }\n }\n\n if (!base && !post) {\n return allRest;\n }\n\n // 1. Merge base recipes, then component styles on top (via mergeStyles)\n let result: Record<string, unknown>;\n\n if (base) {\n const baseStyles = collectRecipeStyles(base, recipes);\n result = mergeStyles(baseStyles as Styles, flatStyles as Styles) as Record<\n string,\n unknown\n >;\n } else {\n result = { ...flatStyles };\n }\n\n // 2. Apply post recipes via mergeStyles (state map extend semantics)\n if (post) {\n const postStyles = collectRecipeStyles(post, recipes);\n result = mergeStyles(result as Styles, postStyles as Styles) as Record<\n string,\n unknown\n >;\n }\n\n // Re-attach selector keys unchanged\n for (const key of Object.keys(selectorStyles)) {\n result[key] = selectorStyles[key];\n }\n\n return result;\n}\n\n/**\n * Resolve all `recipe` style properties in a styles object.\n *\n * Handles both top-level and sub-element recipe references.\n * Returns the same object reference if no recipes are present anywhere\n * (zero overhead for the common case).\n *\n * @param styles - The styles object potentially containing `recipe` keys\n * @returns Resolved styles with recipe values merged in, or the original object if unchanged\n */\nexport function resolveRecipesWith(\n styles: Styles,\n recipes: Record<string, RecipeStyles> | null,\n): Styles {\n // Fast path: no recipes configured\n if (!recipes) return styles;\n\n let changed = false;\n\n // Resolve top-level recipe\n const topResolved = resolveRecipesForLevel(\n styles as Record<string, unknown>,\n recipes,\n );\n\n let result: Record<string, unknown>;\n\n if (topResolved) {\n changed = true;\n result = topResolved;\n } else {\n // Keep reference; a shallow copy is deferred until a sub-element actually changes\n result = styles as Record<string, unknown>;\n }\n\n // Resolve sub-element recipes\n const keys = Object.keys(result);\n\n for (const key of keys) {\n if (!isSelector(key)) continue;\n\n const subStyles = result[key];\n\n if (\n !subStyles ||\n typeof subStyles !== 'object' ||\n Array.isArray(subStyles)\n ) {\n continue;\n }\n\n const subRecord = subStyles as Record<string, unknown>;\n\n if (!('recipe' in subRecord)) continue;\n\n const subResolved = resolveRecipesForLevel(subRecord, recipes);\n\n if (subResolved) {\n if (!changed) {\n // First change in sub-elements -- need to shallow-copy the top level\n changed = true;\n result = { ...(styles as Record<string, unknown>) };\n }\n // Define an own data property so even an untrusted key cannot invoke an\n // inherited setter such as Object.prototype.__proto__.\n Object.defineProperty(result, key, {\n configurable: true,\n enumerable: true,\n value: subResolved,\n writable: true,\n });\n }\n }\n\n return changed ? (result as Styles) : styles;\n}\n"],"mappings":";;;;;AAEA,MAAM,wCAAwB,IAAI,IAAI;CACpC;CACA;CACA;CACA;CACA;AACF,CAAC;AA0DD,SAAgB,yBACd,SACc;CACd,MAAM,SAAuB,CAAC;CAE9B,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,OAAO,GAAG;EACpD,IAAI,sBAAsB,IAAI,IAAI,GAChC,MAAM,IAAI,MACR,mCAAmC,KAAK,+CAC1C;EAGF,OAAO,IAAI,KAAK,eAAe,OAAO;EACtC,OAAO,IAAI,KAAK,iBAAiB,OAAO;EACxC,OAAO,IAAI,KAAK,oBAAoB,OAAO,iBAAiB;EAC5D,OAAO,IAAI,KAAK,iBAAiB,OAAO;EAExC,IAAI,OAAO,mBAAmB,KAAA,GAC5B,OAAO,IAAI,KAAK,sBAAsB,OAAO;EAG/C,IAAI,OAAO,aAAa,KAAA,GACtB,OAAO,IAAI,KAAK,eAAe,OAAO;EAGxC,IAAI,OAAO,kBAAkB,KAAA,GAC3B,OAAO,IAAI,KAAK,oBAAoB,OAAO;EAG7C,IAAI,OAAO,eAAe,KAAA,GACxB,OAAO,IAAI,KAAK,iBAAiB,OAAO;EAG1C,IAAI,OAAO,cAAc,KAAA,GACvB,OAAO,IAAI,KAAK,gBAAgB,OAAO;CAE3C;CAEA,OAAO;AACT;;;ACzCA,SAAgB,iBACd,QACA,YACA,UACoC;CACpC,MAAM,YAAY,IAAI,IAAI,OAAO,KAAK,WAAW,MAAM,CAAC;CACxD,KAAK,MAAM,OAAO,OAAO,KAAK,WAAW,aAAa,GACpD,IAAI,UAAU,IAAI,GAAG,GACnB,SACE,kBAAkB,OAClB,kBAAkB,IAAI,iOAIxB;CAIJ,IAAI,OAAO,YACT,SACE,yBACA,kUAKF;CAGF,IAAI,OAAO,KAAK,WAAW,MAAM,CAAC,CAAC,SAAS,GAC1C,0BAA0B,W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