@tenphi/tasty 0.0.0-snapshot.1f1c00a → 0.0.0-snapshot.1feecc6
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-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-D9Iq8QQm.js +60 -0
- package/dist/chunks/build-config-D9Iq8QQm.js.map +1 -0
- package/dist/chunks/{collector-D2ARGT2L.js → collector-Cb8ah2JF.js} +8 -6
- package/dist/chunks/collector-Cb8ah2JF.js.map +1 -0
- package/dist/chunks/{config-engine-DEmmPPdp.js → config-engine-CMYFZYQh.js} +5 -5
- package/dist/chunks/config-engine-CMYFZYQh.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-DotDkIXt.js → css-definitions-B4aWBkH3.js} +130 -96
- package/dist/chunks/css-definitions-B4aWBkH3.js.map +1 -0
- package/dist/chunks/{debug-D8pg9RGI.js → debug-D2Pu7Xhy.js} +6 -6
- package/dist/chunks/{debug-D8pg9RGI.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-BpxlOTbO.js → react-runtime-DHiopXCu.js} +193 -64
- package/dist/chunks/react-runtime-DHiopXCu.js.map +1 -0
- package/dist/chunks/{runtime-engine-CKFXUH-A.js → runtime-engine-NGCofNXy.js} +72 -53
- package/dist/chunks/runtime-engine-NGCofNXy.js.map +1 -0
- package/dist/chunks/{runtime-state-BxaLhVdP.js → runtime-state-lZjMbvwV.js} +28 -3
- package/dist/chunks/runtime-state-lZjMbvwV.js.map +1 -0
- package/dist/chunks/{style-engine-BBbBuSkT.js → style-engine-DnkV_4Jg.js} +488 -146
- package/dist/chunks/style-engine-DnkV_4Jg.js.map +1 -0
- package/dist/chunks/{zero-engine-gJrKBRiw.js → zero-engine-DcwaCvFs.js} +62 -27
- package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
- package/dist/{collector-w4mBj5gd.d.ts → collector-D2OT6I2G.d.ts} +2 -2
- package/dist/{config-CZWCzBr6.d.ts → config-C4ftFxgI.d.ts} +41 -23
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +7 -7
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/{index-G9JuwM9p.d.ts → index-DxQNRj50.d.ts} +65 -21
- package/dist/index.d.ts +5 -5
- package/dist/index.js +8 -8
- package/dist/{merge-styles-VXwJ0Frr.d.ts → merge-styles-D39qBtox.d.ts} +2 -2
- package/dist/ssr/astro.js +4 -4
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +3 -22
- package/dist/ssr/index.js +4 -4
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +1 -1
- package/dist/ssr/next-config.js +13 -18
- package/dist/ssr/next-config.js.map +1 -1
- 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-JEY8PVYP.d.ts → types-CYQIhUg1.d.ts} +10 -8
- package/dist/zero/babel.d.ts +73 -2
- package/dist/zero/babel.js +51 -48
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +59 -3
- package/dist/zero/index.js +25 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +2 -1
- package/dist/zero/next.js +3 -7
- package/dist/zero/next.js.map +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 +187 -69
- package/docs/debug.md +3 -2
- package/docs/design-system.md +117 -15
- package/docs/dsl.md +262 -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 +22 -19
- package/docs/plugins.md +21 -41
- package/docs/react-api.md +74 -11
- package/docs/runtime-benchmarks.md +11 -11
- package/docs/ssr.md +92 -66
- package/docs/styles.md +85 -19
- package/docs/tasty-static.md +175 -57
- package/package.json +45 -32
- package/tasty.config.ts +1 -0
- package/dist/babel-rZcEwPLM.d.ts +0 -82
- package/dist/chunks/async-storage-CG5HnUT5.js +0 -20
- package/dist/chunks/async-storage-CG5HnUT5.js.map +0 -1
- package/dist/chunks/build-config-CL4eRu2z.js +0 -42
- package/dist/chunks/build-config-CL4eRu2z.js.map +0 -1
- package/dist/chunks/collector-D2ARGT2L.js.map +0 -1
- package/dist/chunks/config-engine-DEmmPPdp.js.map +0 -1
- package/dist/chunks/css-definitions-DotDkIXt.js.map +0 -1
- package/dist/chunks/dsl-DRhFWQzo.js.map +0 -1
- package/dist/chunks/react-runtime-BpxlOTbO.js.map +0 -1
- package/dist/chunks/runtime-engine-CKFXUH-A.js.map +0 -1
- package/dist/chunks/runtime-state-BxaLhVdP.js.map +0 -1
- package/dist/chunks/style-engine-BBbBuSkT.js.map +0 -1
- package/dist/chunks/zero-engine-gJrKBRiw.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
|
|
@@ -105,6 +115,8 @@ tastyStatic('body', {
|
|
|
105
115
|
});
|
|
106
116
|
```
|
|
107
117
|
|
|
118
|
+
The selector can be a list (`'.uni-checkbox, uni-checkbox'`): every item gets the states and sub-elements. Local `@keyframes` and `@starting` states work as in `tastyStatic(styles)`.
|
|
119
|
+
|
|
108
120
|
---
|
|
109
121
|
|
|
110
122
|
## StaticStyle Object
|
|
@@ -166,7 +178,7 @@ module.exports = {
|
|
|
166
178
|
| -------------------------- | ------------------------------------------------ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
167
179
|
| `output` | `string` | `'tasty.css'` | Path for generated CSS file |
|
|
168
180
|
| `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS (see [Inject Mode](#inject-mode)) |
|
|
169
|
-
| `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. |
|
|
170
182
|
| `config` | `TastyZeroConfig \| () => TastyZeroConfig` | `{}` | Inline config object or factory function. Takes precedence over `configFile`. |
|
|
171
183
|
| `configDeps` | `string[]` | `[]` | Absolute file paths that affect config (for cache invalidation) |
|
|
172
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. |
|
|
@@ -178,7 +190,8 @@ module.exports = {
|
|
|
178
190
|
| `config.keyframes` | `Record<string, KeyframesSteps>` | — | Global `@keyframes` definitions available to all `tastyStatic` calls |
|
|
179
191
|
| `config.fontFaces` | `Record<string, FontFaceInput>` | — | Global `@font-face` definitions |
|
|
180
192
|
| `config.counterStyles` | `Record<string, CounterStyleDescriptors>` | — | Global `@counter-style` definitions |
|
|
181
|
-
| `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 |
|
|
182
195
|
| `config.functions` | `Record<string, FunctionDefinition \| Function>` | — | Custom functions (merged). Bare keys → parse functions; `$$name` keys → declarative CSS `@function` definitions |
|
|
183
196
|
| `config.polyfills` | `{ functions?: boolean }` | `{}` | Opt-in polyfills. `functions: true` inlines `@function` calls into plain CSS at build time |
|
|
184
197
|
| `config.plugins` | `TastyPlugin[]` | — | Plugins that extend tasty with custom functions, units, states, and handlers |
|
|
@@ -242,7 +255,7 @@ const card = tastyStatic({
|
|
|
242
255
|
color: '#text',
|
|
243
256
|
});
|
|
244
257
|
|
|
245
|
-
<div className={card}>Styled card</div>;
|
|
258
|
+
<div className={card.className}>Styled card</div>;
|
|
246
259
|
```
|
|
247
260
|
|
|
248
261
|
---
|
|
@@ -279,12 +292,12 @@ export default withTastyZero({
|
|
|
279
292
|
|
|
280
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.
|
|
281
294
|
|
|
282
|
-
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.
|
|
283
296
|
|
|
284
|
-
**Requirements**: `babel-loader` must be installed in your project:
|
|
297
|
+
**Requirements**: `babel-loader` must be installed in your project (see [Requirements](#requirements)):
|
|
285
298
|
|
|
286
299
|
```bash
|
|
287
|
-
pnpm add babel-loader
|
|
300
|
+
pnpm add -D babel-loader
|
|
288
301
|
```
|
|
289
302
|
|
|
290
303
|
### CSS Injection
|
|
@@ -299,34 +312,107 @@ public/tasty.css
|
|
|
299
312
|
|
|
300
313
|
---
|
|
301
314
|
|
|
315
|
+
## Programmatic API
|
|
316
|
+
|
|
317
|
+
`@tenphi/tasty/zero` turns styles into CSS in Node without Babel or React — for build scripts, or CSS shipped to other frameworks:
|
|
318
|
+
|
|
319
|
+
```ts
|
|
320
|
+
import {
|
|
321
|
+
configure,
|
|
322
|
+
extractStylesForSelector,
|
|
323
|
+
extractStylesWithChunks,
|
|
324
|
+
} from '@tenphi/tasty/zero';
|
|
325
|
+
|
|
326
|
+
configure({
|
|
327
|
+
units: { u: 'var(--unit)' },
|
|
328
|
+
states: { '@dark': '@root(schema=dark)' },
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
extractStylesForSelector('.card', { padding: '2u', fill: '#surface' }).css;
|
|
332
|
+
// → '.card { padding: calc(2 * var(--unit)); background-color: … }'
|
|
333
|
+
|
|
334
|
+
extractStylesWithChunks({ display: 'flex', gap: '1u' });
|
|
335
|
+
// → [{ className: 'ts…', css: '.ts….ts… { … }' }]
|
|
336
|
+
```
|
|
337
|
+
|
|
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.
|
|
341
|
+
|
|
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.
|
|
343
|
+
|
|
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.
|
|
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
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
302
382
|
## Vite Integration
|
|
303
383
|
|
|
384
|
+
`@vitejs/plugin-react` 6 no longer runs Babel; add it with `@rolldown/plugin-babel` (`pnpm add -D @rolldown/plugin-babel`):
|
|
385
|
+
|
|
304
386
|
```typescript
|
|
305
387
|
// vite.config.ts
|
|
306
388
|
import { defineConfig } from 'vite';
|
|
307
389
|
import react from '@vitejs/plugin-react';
|
|
390
|
+
import babel from '@rolldown/plugin-babel';
|
|
308
391
|
|
|
309
392
|
export default defineConfig({
|
|
310
393
|
plugins: [
|
|
311
|
-
react(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
},
|
|
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)' },
|
|
321
403
|
},
|
|
322
|
-
|
|
404
|
+
},
|
|
323
405
|
],
|
|
324
|
-
|
|
406
|
+
],
|
|
325
407
|
}),
|
|
326
408
|
],
|
|
327
409
|
});
|
|
328
410
|
```
|
|
329
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
|
+
|
|
330
416
|
---
|
|
331
417
|
|
|
332
418
|
## Build Transformation
|
|
@@ -344,44 +430,67 @@ const button = tastyStatic({
|
|
|
344
430
|
|
|
345
431
|
tastyStatic('.heading', { preset: 'h1' });
|
|
346
432
|
|
|
347
|
-
export const Button = () => <button className={button}>Click</button>;
|
|
433
|
+
export const Button = () => <button className={button.className}>Click</button>;
|
|
348
434
|
```
|
|
349
435
|
|
|
350
436
|
### After (Production Build)
|
|
351
437
|
|
|
352
438
|
```tsx
|
|
439
|
+
import './tasty.css';
|
|
440
|
+
|
|
353
441
|
const button = {
|
|
354
|
-
className: '
|
|
442
|
+
className: 'ts3f783b ts070801',
|
|
355
443
|
styles: { padding: '2x 4x', fill: '#purple', color: '#white' },
|
|
356
444
|
toString() {
|
|
357
445
|
return this.className;
|
|
358
446
|
},
|
|
359
447
|
};
|
|
360
448
|
|
|
361
|
-
export const Button = () => <button className={button}>Click</button>;
|
|
449
|
+
export const Button = () => <button className={button.className}>Click</button>;
|
|
362
450
|
```
|
|
363
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
|
+
|
|
364
454
|
### Generated CSS (tasty.css)
|
|
365
455
|
|
|
366
456
|
```css
|
|
367
457
|
/* Generated by @tenphi/tasty/zero - DO NOT EDIT */
|
|
368
458
|
|
|
369
|
-
|
|
370
|
-
|
|
459
|
+
@property --tasty-second-fill-color {
|
|
460
|
+
syntax: '<color>';
|
|
461
|
+
inherits: false;
|
|
462
|
+
initial-value: transparent;
|
|
371
463
|
}
|
|
372
464
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
465
|
+
@property --current-color {
|
|
466
|
+
syntax: '<color>';
|
|
467
|
+
inherits: true;
|
|
468
|
+
initial-value: currentcolor;
|
|
376
469
|
}
|
|
377
470
|
|
|
378
|
-
.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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 */
|
|
382
489
|
}
|
|
383
490
|
```
|
|
384
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
|
+
|
|
385
494
|
---
|
|
386
495
|
|
|
387
496
|
## Inject Mode
|
|
@@ -452,22 +561,29 @@ tastyStatic('.heading', { preset: 'h1' });
|
|
|
452
561
|
```tsx
|
|
453
562
|
import { injectCSS as _$i } from '@tenphi/tasty/static/inject';
|
|
454
563
|
|
|
564
|
+
_$i(
|
|
565
|
+
'@property',
|
|
566
|
+
'@property --tasty-second-fill-color { … }\n@property --current-color { … }\n…',
|
|
567
|
+
);
|
|
568
|
+
|
|
455
569
|
const button =
|
|
456
570
|
(_$i(
|
|
457
|
-
'
|
|
458
|
-
'.
|
|
571
|
+
'tsa903d6 ts070801',
|
|
572
|
+
'.tsa903d6.tsa903d6 { background-color: var(--purple-color); }\n.ts070801.ts070801 { padding: 16px 32px; }',
|
|
459
573
|
),
|
|
460
574
|
{
|
|
461
|
-
className: '
|
|
575
|
+
className: 'tsa903d6 ts070801',
|
|
462
576
|
styles: { padding: '2x 4x', fill: '#purple' },
|
|
463
577
|
toString() {
|
|
464
578
|
return this.className;
|
|
465
579
|
},
|
|
466
580
|
});
|
|
467
581
|
|
|
468
|
-
_$i('.heading', '.heading{font-size:
|
|
582
|
+
_$i('.heading', '.heading { font-size: var(--h1-font-size, …); … }');
|
|
469
583
|
```
|
|
470
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
|
+
|
|
471
587
|
### Dev Mode / HMR
|
|
472
588
|
|
|
473
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.
|
|
@@ -525,7 +641,7 @@ const card = tastyStatic({
|
|
|
525
641
|
|
|
526
642
|
## Extending Style Types (TypeScript)
|
|
527
643
|
|
|
528
|
-
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.
|
|
529
645
|
|
|
530
646
|
---
|
|
531
647
|
|
|
@@ -547,10 +663,12 @@ const card = tastyStatic({
|
|
|
547
663
|
});
|
|
548
664
|
|
|
549
665
|
<div
|
|
550
|
-
className={card}
|
|
551
|
-
style={
|
|
552
|
-
|
|
553
|
-
|
|
666
|
+
className={card.className}
|
|
667
|
+
style={
|
|
668
|
+
{
|
|
669
|
+
'--card-bg': isActive ? 'var(--purple-color)' : 'var(--white-color)',
|
|
670
|
+
} as React.CSSProperties
|
|
671
|
+
}
|
|
554
672
|
/>;
|
|
555
673
|
```
|
|
556
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.1feecc6",
|
|
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",
|
|
@@ -62,6 +62,11 @@
|
|
|
62
62
|
"import": "./dist/ssr/astro.js",
|
|
63
63
|
"default": "./dist/ssr/astro.js"
|
|
64
64
|
},
|
|
65
|
+
"./ssr/client": {
|
|
66
|
+
"types": "./dist/ssr/client.d.ts",
|
|
67
|
+
"import": "./dist/ssr/client.js",
|
|
68
|
+
"default": "./dist/ssr/client.js"
|
|
69
|
+
},
|
|
65
70
|
"./ssr/astro-client": {
|
|
66
71
|
"types": "./dist/ssr/astro-client.d.ts",
|
|
67
72
|
"import": "./dist/ssr/astro-client.js",
|
|
@@ -121,11 +126,12 @@
|
|
|
121
126
|
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
122
127
|
"format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
|
|
123
128
|
"size": "size-limit",
|
|
124
|
-
"bench": "vitest bench --project node",
|
|
125
|
-
"bench:browser": "vitest bench --project browser",
|
|
129
|
+
"bench": "vitest bench --project \"node (bench)\"",
|
|
130
|
+
"bench:browser": "vitest bench --project \"browser (chromium) (bench)\"",
|
|
126
131
|
"bench:overhead": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-overhead.bench.tsx",
|
|
127
132
|
"bench:injection": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-injection.bench.ts",
|
|
128
133
|
"bench:interaction": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-interaction.bench.tsx",
|
|
134
|
+
"bench:tree": "vitest bench --config vitest.production-browser-bench.config.ts src/tasty-tree.bench.tsx",
|
|
129
135
|
"bench:cold-start": "node scripts/cold-start/index.mjs",
|
|
130
136
|
"prepublishOnly": "pnpm run build",
|
|
131
137
|
"changeset": "changeset",
|
|
@@ -134,6 +140,7 @@
|
|
|
134
140
|
"knip": "knip",
|
|
135
141
|
"check:build": "node scripts/check-built-entries.mjs",
|
|
136
142
|
"check:react-compat": "node scripts/check-react-compat.mjs",
|
|
143
|
+
"check:babel-compat": "node scripts/check-babel-compat.mjs",
|
|
137
144
|
"check:test-only": "node scripts/check-test-only-code.mjs",
|
|
138
145
|
"hygiene": "pnpm lint && pnpm format:check && pnpm typecheck",
|
|
139
146
|
"hygiene:fix": "pnpm lint:fix && pnpm format && pnpm typecheck"
|
|
@@ -160,9 +167,9 @@
|
|
|
160
167
|
},
|
|
161
168
|
"homepage": "https://github.com/tenphi/tasty#readme",
|
|
162
169
|
"peerDependencies": {
|
|
163
|
-
"@babel/core": "^7.24.0",
|
|
164
|
-
"@babel/helper-plugin-utils": "^7.24.0",
|
|
165
|
-
"@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",
|
|
166
173
|
"jiti": "^2.6.1",
|
|
167
174
|
"next": ">=14.0.0",
|
|
168
175
|
"react": "^18.0.0 || ^19.0.0"
|
|
@@ -191,39 +198,37 @@
|
|
|
191
198
|
"csstype": "^3.1.0"
|
|
192
199
|
},
|
|
193
200
|
"devDependencies": {
|
|
194
|
-
"@astrojs/react": "^7.0.
|
|
195
|
-
"@babel/core": "^
|
|
196
|
-
"@babel/helper-plugin-utils": "^
|
|
197
|
-
"@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",
|
|
198
205
|
"@changesets/changelog-github": "^1.0.1",
|
|
199
206
|
"@changesets/cli": "^3.0.3",
|
|
200
207
|
"@eslint/js": "^10.0.1",
|
|
201
|
-
"@size-limit/esbuild": "^14.
|
|
202
|
-
"@size-limit/file": "^14.
|
|
203
|
-
"@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",
|
|
204
211
|
"@testing-library/jest-dom": "^7.0.1",
|
|
205
212
|
"@testing-library/react": "^16.3.3",
|
|
206
|
-
"@types/
|
|
207
|
-
"@types/babel__helper-plugin-utils": "^7.10.3",
|
|
208
|
-
"@types/node": "^24.13.6",
|
|
213
|
+
"@types/node": "^24.19.1",
|
|
209
214
|
"@types/react": "^19.3.0",
|
|
210
215
|
"@types/react-dom": "^19.3.0",
|
|
211
216
|
"@vitest/browser-playwright": "^5.0.3",
|
|
212
|
-
"astro": "^7.3.
|
|
217
|
+
"astro": "^7.3.6",
|
|
213
218
|
"esbuild": "^0.28.2",
|
|
214
|
-
"eslint": "^10.
|
|
219
|
+
"eslint": "^10.12.0",
|
|
215
220
|
"eslint-config-prettier": "^10.1.8",
|
|
216
221
|
"jiti": "^2.7.0",
|
|
217
|
-
"knip": "^6.
|
|
218
|
-
"next": "^16.
|
|
222
|
+
"knip": "^6.40.0",
|
|
223
|
+
"next": "^16.4.0",
|
|
219
224
|
"playwright": "^1.63.0",
|
|
220
225
|
"prettier": "^3.9.9",
|
|
221
226
|
"react": "^19.3.0",
|
|
222
227
|
"react-dom": "^19.3.0",
|
|
223
|
-
"size-limit": "^14.
|
|
228
|
+
"size-limit": "^14.1.0",
|
|
224
229
|
"tsdown": "^0.23.0",
|
|
225
230
|
"typescript": "^6.0.3",
|
|
226
|
-
"typescript-eslint": "^8.
|
|
231
|
+
"typescript-eslint": "^8.71.1",
|
|
227
232
|
"vitest": "^5.0.3"
|
|
228
233
|
},
|
|
229
234
|
"packageManager": "pnpm@11.27.1",
|
|
@@ -232,37 +237,37 @@
|
|
|
232
237
|
"name": "main (import *)",
|
|
233
238
|
"path": "dist/index.js",
|
|
234
239
|
"import": "*",
|
|
235
|
-
"limit": "
|
|
240
|
+
"limit": "62.08 kB"
|
|
236
241
|
},
|
|
237
242
|
{
|
|
238
243
|
"name": "main (tasty)",
|
|
239
244
|
"path": "dist/index.js",
|
|
240
245
|
"import": "{ tasty }",
|
|
241
|
-
"limit": "
|
|
246
|
+
"limit": "54.99 kB"
|
|
242
247
|
},
|
|
243
248
|
{
|
|
244
249
|
"name": "main (StyleParser)",
|
|
245
250
|
"path": "dist/index.js",
|
|
246
251
|
"import": "{ StyleParser }",
|
|
247
|
-
"limit": "
|
|
252
|
+
"limit": "8 kB"
|
|
248
253
|
},
|
|
249
254
|
{
|
|
250
255
|
"name": "main (parseColor)",
|
|
251
256
|
"path": "dist/index.js",
|
|
252
257
|
"import": "{ parseColor }",
|
|
253
|
-
"limit": "
|
|
258
|
+
"limit": "8.67 kB"
|
|
254
259
|
},
|
|
255
260
|
{
|
|
256
261
|
"name": "main (useRawCSS)",
|
|
257
262
|
"path": "dist/index.js",
|
|
258
263
|
"import": "{ useRawCSS }",
|
|
259
|
-
"limit": "
|
|
264
|
+
"limit": "33.63 kB"
|
|
260
265
|
},
|
|
261
266
|
{
|
|
262
267
|
"name": "core (import *)",
|
|
263
268
|
"path": "dist/core/index.js",
|
|
264
269
|
"import": "*",
|
|
265
|
-
"limit": "
|
|
270
|
+
"limit": "57.38 kB"
|
|
266
271
|
},
|
|
267
272
|
{
|
|
268
273
|
"name": "static",
|
|
@@ -279,7 +284,7 @@
|
|
|
279
284
|
"path",
|
|
280
285
|
"crypto"
|
|
281
286
|
],
|
|
282
|
-
"limit": "
|
|
287
|
+
"limit": "41.3 kB"
|
|
283
288
|
},
|
|
284
289
|
{
|
|
285
290
|
"name": "babel-plugin",
|
|
@@ -288,9 +293,11 @@
|
|
|
288
293
|
"ignore": [
|
|
289
294
|
"fs",
|
|
290
295
|
"path",
|
|
291
|
-
"crypto"
|
|
296
|
+
"crypto",
|
|
297
|
+
"node:module",
|
|
298
|
+
"node:path"
|
|
292
299
|
],
|
|
293
|
-
"limit": "
|
|
300
|
+
"limit": "45.95 kB"
|
|
294
301
|
},
|
|
295
302
|
{
|
|
296
303
|
"name": "astro client",
|
|
@@ -298,6 +305,12 @@
|
|
|
298
305
|
"import": "*",
|
|
299
306
|
"limit": "0.5 kB"
|
|
300
307
|
},
|
|
308
|
+
{
|
|
309
|
+
"name": "ssr client",
|
|
310
|
+
"path": "dist/ssr/client.js",
|
|
311
|
+
"import": "{ hydrateTastyClasses }",
|
|
312
|
+
"limit": "0.5 kB"
|
|
313
|
+
},
|
|
301
314
|
{
|
|
302
315
|
"name": "Next.js config",
|
|
303
316
|
"path": "dist/ssr/next-config.js",
|
|
@@ -308,7 +321,7 @@
|
|
|
308
321
|
"node:module",
|
|
309
322
|
"node:path"
|
|
310
323
|
],
|
|
311
|
-
"limit": "
|
|
324
|
+
"limit": "41.48 kB"
|
|
312
325
|
}
|
|
313
326
|
]
|
|
314
327
|
}
|