@tenphi/tasty 0.0.0-snapshot.06c8a41 → 0.0.0-snapshot.07ea4a0
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 +408 -385
- package/dist/babel-types-BKDTT4--.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-CW4k04_V.js +60 -0
- package/dist/chunks/build-config-CW4k04_V.js.map +1 -0
- package/dist/{collector-B3OsM252.js → chunks/collector-DKWQXEwN.js} +10 -127
- package/dist/chunks/collector-DKWQXEwN.js.map +1 -0
- package/dist/chunks/config-engine-DTglOA78.js +272 -0
- package/dist/chunks/config-engine-DTglOA78.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-_C7C-daI.js +910 -0
- package/dist/chunks/css-definitions-_C7C-daI.js.map +1 -0
- package/dist/{css-resources-Cyl_axbI.js → chunks/css-resources-P7IBUUZs.js} +2 -9
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/chunks/debug-BapJwy9w.js +502 -0
- package/dist/chunks/debug-BapJwy9w.js.map +1 -0
- package/dist/chunks/dsl-DYSJc1-T.js +1383 -0
- package/dist/chunks/dsl-DYSJc1-T.js.map +1 -0
- package/dist/chunks/hydration-TRcz5vnk.js +41 -0
- package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
- package/dist/chunks/react-runtime-DayjnPuC.js +689 -0
- package/dist/chunks/react-runtime-DayjnPuC.js.map +1 -0
- package/dist/chunks/runtime-engine-IwGbSMb4.js +2432 -0
- package/dist/chunks/runtime-engine-IwGbSMb4.js.map +1 -0
- package/dist/chunks/runtime-state-CVrL92zX.js +152 -0
- package/dist/chunks/runtime-state-CVrL92zX.js.map +1 -0
- package/dist/{merge-styles-DuoZEsm9.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-CVmNIjow.js +5521 -0
- package/dist/chunks/style-engine-CVmNIjow.js.map +1 -0
- package/dist/{css-writer-Bgowobbx.js → chunks/zero-engine-igHhzYM6.js} +65 -145
- package/dist/chunks/zero-engine-igHhzYM6.js.map +1 -0
- package/dist/{collector-BTVXj2hS.d.ts → collector-CTU-nl0g.d.ts} +6 -5
- package/dist/{config-LfIDmVHx.d.ts → config-CcxqSZI2.d.ts} +45 -40
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/{index-Bm9ltvdH.d.ts → index--GdqCPlp.d.ts} +271 -242
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -922
- package/dist/{merge-styles-BcLl1u_d.d.ts → merge-styles-DSkVc6CD.d.ts} +2 -3
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +1 -14
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +1 -2
- package/dist/ssr/astro-middleware-extract-static.js +1 -1
- package/dist/ssr/astro-middleware-extract.d.ts +1 -2
- package/dist/ssr/astro-middleware-extract.js +1 -1
- package/dist/ssr/astro-middleware-static.d.ts +1 -2
- package/dist/ssr/astro-middleware-static.js +1 -12
- package/dist/ssr/astro-middleware-static.js.map +1 -1
- package/dist/ssr/astro-middleware.d.ts +1 -2
- package/dist/ssr/astro-middleware.js +1 -13
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +8 -16
- package/dist/ssr/astro.js +220 -1
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +5 -25
- package/dist/ssr/index.js +5 -5
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +3 -5
- package/dist/ssr/next-config.js +43 -35
- package/dist/ssr/next-config.js.map +1 -1
- package/dist/ssr/next.d.ts +3 -9
- package/dist/ssr/next.js +7 -38
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -9
- package/dist/static/index.js +4 -22
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -2
- package/dist/{index-BmogEzTo.d.ts → types-DJEM_BOJ.d.ts} +852 -860
- package/dist/zero/babel.d.ts +67 -2
- package/dist/zero/babel.js +77 -140
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +62 -8
- package/dist/zero/index.js +24 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +3 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +4 -1
- package/docs/adoption.md +25 -17
- package/docs/ai-agents.md +66 -33
- package/docs/comparison.md +9 -8
- package/docs/configuration.md +192 -60
- package/docs/debug.md +5 -7
- package/docs/design-system.md +117 -15
- package/docs/dsl.md +204 -82
- package/docs/getting-started.md +81 -22
- package/docs/injector.md +41 -40
- package/docs/methodology.md +48 -23
- package/docs/migration-v3.md +3 -3
- package/docs/pipeline.md +54 -27
- package/docs/plugins.md +22 -42
- package/docs/react-api.md +72 -9
- package/docs/runtime-benchmarks.md +146 -91
- package/docs/ssr.md +92 -66
- package/docs/styles.md +117 -31
- package/docs/tasty-static.md +162 -58
- package/package.json +96 -38
- package/dist/astro-CeYENy2x.js +0 -301
- package/dist/astro-CeYENy2x.js.map +0 -1
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/babel-DWCsafYw.d.ts +0 -83
- package/dist/collector-B3OsM252.js.map +0 -1
- package/dist/config-B3gPdCqd.js +0 -12421
- package/dist/config-B3gPdCqd.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-DGm0CFHP.js +0 -1732
- package/dist/core-DGm0CFHP.js.map +0 -1
- package/dist/css-resources-Cyl_axbI.js.map +0 -1
- package/dist/css-writer-Bgowobbx.js.map +0 -1
- package/dist/format-global-rules-DklyaXv-.js +0 -22
- package/dist/format-global-rules-DklyaXv-.js.map +0 -1
- package/dist/format-rules-XRw9u7d4.js +0 -104
- package/dist/format-rules-XRw9u7d4.js.map +0 -1
- package/dist/hydrate-CNOmZprz.js +0 -37
- package/dist/hydrate-CNOmZprz.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-DE-OE76F.js +0 -535
- package/dist/keyframes-DE-OE76F.js.map +0 -1
- package/dist/merge-styles-DuoZEsm9.js.map +0 -1
- package/dist/resolve-recipes-H9NqOQuP.js +0 -144
- package/dist/resolve-recipes-H9NqOQuP.js.map +0 -1
- package/dist/ssr-collector-ref-COs_ioWl.js +0 -29
- package/dist/ssr-collector-ref-COs_ioWl.js.map +0 -1
package/docs/configuration.md
CHANGED
|
@@ -23,9 +23,8 @@ configure({
|
|
|
23
23
|
|
|
24
24
|
// Custom units (merged with built-in units)
|
|
25
25
|
units: {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
custom: (n) => `${n * 10}px`, // Function-based unit
|
|
26
|
+
gu: '4px', // `2gu` → `8px`
|
|
27
|
+
cols: (n) => `calc(${n} * var(--col-width))`, // function-based unit
|
|
29
28
|
},
|
|
30
29
|
|
|
31
30
|
// Custom functions — a single map for both flavors, discriminated by value type:
|
|
@@ -47,35 +46,35 @@ These docs use `data-schema="dark"` in examples. If your app already standardize
|
|
|
47
46
|
|
|
48
47
|
## Options
|
|
49
48
|
|
|
50
|
-
| Option | Type | Default
|
|
51
|
-
| -------------------- | ------------------------------------------------ |
|
|
52
|
-
| `nonce` | `string` | -
|
|
53
|
-
| `maxRulesPerSheet` | `number` | `8192`
|
|
54
|
-
| `forceTextInjection` | `boolean` |
|
|
55
|
-
| `devMode` | `boolean` | auto
|
|
56
|
-
| `states` | `Record<string, string>` | -
|
|
57
|
-
| `parserCacheSize` | `number` | `1000`
|
|
58
|
-
| `units` | `Record<string, string \| UnitHandler>` | Built-in
|
|
59
|
-
| `functions` | `Record<string, FunctionDefinition \| Function>` | -
|
|
60
|
-
| `handlers` | `Record<string, StyleHandlerDefinition>` | Built-in
|
|
61
|
-
| `propHandlers` | `Record<string, PropHandlerDefinition>` | -
|
|
62
|
-
| `baseStyleProps` | `readonly string[]` | -
|
|
63
|
-
| `tokens` | `Record<string, value \| stateMap>` | -
|
|
64
|
-
| `replaceTokens` | `Record<string, string \| number \| boolean>` |
|
|
65
|
-
| `keyframes` | `Record<string, KeyframesSteps>` | -
|
|
66
|
-
| `properties` | `Record<string, PropertyDefinition>` | -
|
|
67
|
-
| `fontFaces` | `Record<string, FontFaceInput>` | -
|
|
68
|
-
| `counterStyles` | `Record<string, CounterStyleDescriptors>` | -
|
|
69
|
-
| `polyfills` | `{ functions?: boolean }` | `{}`
|
|
70
|
-
| `autoPropertyTypes` | `boolean` | `true`
|
|
71
|
-
| `recipes` | `Record<string, RecipeStyles>` | -
|
|
72
|
-
| `presets` | `Record<string, TypographyPreset>` | -
|
|
73
|
-
| `globalStyles` | `Record<string, Styles>` | -
|
|
74
|
-
| `plugins` | `TastyPlugin[]` | -
|
|
75
|
-
| `gc` | `GCConfig` | -
|
|
76
|
-
| `batchInjection` | `boolean \| 'always'` | `false`
|
|
77
|
-
| `colorSpace` | `'rgb' \| 'hsl' \| 'oklch'` | -
|
|
78
|
-
| `namePrefix` | `string` | `'t'` (`tasty`) / `'ts'` (build-time)
|
|
49
|
+
| Option | Type | Default | Description |
|
|
50
|
+
| -------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
51
|
+
| `nonce` | `string` | - | CSP nonce for style elements |
|
|
52
|
+
| `maxRulesPerSheet` | `number` | `8192` | Maximum rules per injected stylesheet |
|
|
53
|
+
| `forceTextInjection` | `boolean` | `false` (`true` in test environments only while `configure()` has never been called) | Force text-node CSS injection instead of constructable stylesheets. Set it explicitly in test setup |
|
|
54
|
+
| `devMode` | `boolean` | auto | Enable development-mode features: performance metrics and debug info. Does not turn on dev warnings; those follow `NODE_ENV` (or `localStorage.TASTY_DEBUG = 'true'` in a browser) |
|
|
55
|
+
| `states` | `Record<string, string>` | - | Global state aliases for advanced state mapping |
|
|
56
|
+
| `parserCacheSize` | `number` | `1000` | Parser LRU cache size |
|
|
57
|
+
| `units` | `Record<string, string \| UnitHandler>` | Built-in | Custom units (merged with built-in). See [built-in units](dsl.md#built-in-units) |
|
|
58
|
+
| `functions` | `Record<string, FunctionDefinition \| Function>` | - | Custom functions (merged). Bare keys → parse functions; `$$name` keys → declarative CSS `@function` definitions |
|
|
59
|
+
| `handlers` | `Record<string, StyleHandlerDefinition>` | Built-in | Custom style handlers (replace built-in). See [Custom Style Handlers](#custom-style-handlers) |
|
|
60
|
+
| `propHandlers` | `Record<string, PropHandlerDefinition>` | - | Props middleware for every component — props in, props out. See [Props Middleware](#props-middleware) |
|
|
61
|
+
| `baseStyleProps` | `readonly string[]` | - | Style names exposed as props on **every** component. See [Base Style Props](#base-style-props) |
|
|
62
|
+
| `tokens` | `Record<string, value \| stateMap>` | - | Design tokens injected as `:root` CSS custom properties |
|
|
63
|
+
| `replaceTokens` | `Record<string, string \| number \| boolean>` | `{ '#clear': 'transparent' }` | Parse-time token substitution (inline replacement). `boolean` is allowed for `#` color tokens |
|
|
64
|
+
| `keyframes` | `Record<string, KeyframesSteps>` | - | Global keyframes for animations |
|
|
65
|
+
| `properties` | `Record<string, PropertyDefinition>` | - | Global CSS @property definitions |
|
|
66
|
+
| `fontFaces` | `Record<string, FontFaceInput>` | - | Global @font-face definitions |
|
|
67
|
+
| `counterStyles` | `Record<string, CounterStyleDescriptors>` | - | Global @counter-style definitions |
|
|
68
|
+
| `polyfills` | `{ functions?: boolean }` | `{}` | Opt-in polyfills for not-yet-baseline features. `functions: true` inlines `@function` calls into plain CSS at parse time |
|
|
69
|
+
| `autoPropertyTypes` | `boolean` | `true` | Auto-infer and register `@property` types from values |
|
|
70
|
+
| `recipes` | `Record<string, RecipeStyles>` | - | Predefined style recipes (named style bundles) |
|
|
71
|
+
| `presets` | `Record<string, TypographyPreset>` | - | Typography presets — shorthand for `generateTypographyTokens()` |
|
|
72
|
+
| `globalStyles` | `Record<string, Styles>` | - | Global Tasty styles keyed by CSS selector |
|
|
73
|
+
| `plugins` | `TastyPlugin[]` | - | Plugins that bundle `functions`, `units`, `states`, `handlers`, `propHandlers`, `baseStyleProps`, `tokens`, `replaceTokens`, `recipes`, `presets`, `globalStyles`, `properties`, `keyframes`, `fontFaces`, and `counterStyles` (processed in order; later override earlier, and direct config wins over all). See [Plugins](plugins.md) |
|
|
74
|
+
| `gc` | `GCConfig` | - | Turns on automatic collection of unused styles: `{ touchInterval?, capacity?, grace? }` (defaults `1000`, `1000`, `10000` ms). Without it nothing is collected automatically; call `gc()` yourself |
|
|
75
|
+
| `batchInjection` | `boolean \| 'always'` | `false` | Defer stylesheet writes and apply them in one batch. See [Batched injection](#batched-injection) |
|
|
76
|
+
| `colorSpace` | `'rgb' \| 'hsl' \| 'oklch'` | - | **Deprecated** — no longer has any effect. See [Color space](#color-space) |
|
|
77
|
+
| `namePrefix` | `string` | `'t'` (`tasty`) / `'ts'` (build-time) | Prefix prepended to every generated identifier (class, keyframe, counter-style names). Must match `^[a-zA-Z_][a-zA-Z0-9_-]{0,31}$`. See [Name prefix](#name-prefix). |
|
|
79
78
|
|
|
80
79
|
---
|
|
81
80
|
|
|
@@ -334,8 +333,7 @@ Tokens support state maps for responsive or theme-aware values:
|
|
|
334
333
|
```jsx
|
|
335
334
|
configure({
|
|
336
335
|
tokens: {
|
|
337
|
-
$
|
|
338
|
-
$radius: '6px',
|
|
336
|
+
'$sidebar-width': '280px',
|
|
339
337
|
'#primary': {
|
|
340
338
|
'': '#purple',
|
|
341
339
|
'@dark': '#light-purple',
|
|
@@ -350,9 +348,10 @@ configure({
|
|
|
350
348
|
|
|
351
349
|
- `$name` keys become `--name` CSS custom properties
|
|
352
350
|
- `#name` keys become `--name-color` custom properties
|
|
351
|
+
- Tokens do not change units: `2x` stays `16px` whatever `$gap` is. To drive a unit from a token, point the unit at it: `units: { x: 'var(--gap)' }` makes `2x` compile to `calc(2 * var(--gap))`
|
|
353
352
|
- Names keep their case, since CSS custom properties are case-sensitive: `$myVar` is `--myVar` and is referenced as `$myVar`. A leading capital is not supported and folds — `$Foo` and `#Purple` become `--foo` and `--purple-color` — so start names lowercase. Kebab-case (`$my-var`) remains the convention.
|
|
354
353
|
|
|
355
|
-
Tokens are
|
|
354
|
+
Tokens are emitted by the client injector, by the SSR collector (`TastyRegistry`, `tastyIntegration()`, `runWithCollector()`), by the `withTastyNext()` shared stylesheet, and by the Babel plugin. The inline React Server Component path without a collector does not emit them — see [Server-Side Rendering](ssr.md).
|
|
356
355
|
|
|
357
356
|
---
|
|
358
357
|
|
|
@@ -375,6 +374,17 @@ configure({
|
|
|
375
374
|
|
|
376
375
|
When a component uses `padding: '$card-padding'`, the parser replaces it with `'4x'` before generating CSS. When a component uses `fill: '#accent'`, it is replaced with `'#purple'`, which in turn resolves to `var(--purple-color)`.
|
|
377
376
|
|
|
377
|
+
Tasty includes `'#clear': 'transparent'` as a default replace token, available
|
|
378
|
+
without calling `configure()`. It survives `resetConfig()`, and explicit
|
|
379
|
+
`replaceTokens` entries can override it. A replace token resolving to the literal
|
|
380
|
+
`transparent` ignores numeric and custom-property opacity suffixes:
|
|
381
|
+
`#clear`, `#clear.5`, and `#clear.$opacity` all emit `transparent`.
|
|
382
|
+
|
|
383
|
+
`#clear` no longer reads `--clear-color`, and Tasty no longer registers that
|
|
384
|
+
property by default. If you previously customized `#clear` through `tokens`,
|
|
385
|
+
local token definitions, or CSS, use a different color token or explicitly
|
|
386
|
+
override `replaceTokens['#clear']` instead.
|
|
387
|
+
|
|
378
388
|
See [Replace Tokens](dsl.md#replace-tokens) in the Style DSL reference.
|
|
379
389
|
|
|
380
390
|
---
|
|
@@ -471,7 +481,7 @@ See [Functions (`@function`)](dsl.md#functions-function) for inline usage inside
|
|
|
471
481
|
|
|
472
482
|
### Custom color functions
|
|
473
483
|
|
|
474
|
-
A parse function whose output is an already-supported color (`rgb`, `hsl`, `#…`, `oklch`, …) is treated as a **color function**: it works everywhere a color is accepted — style values, `#token.alpha` opacity
|
|
484
|
+
A parse function whose output is an already-supported color (`rgb`, `hsl`, `#…`, `oklch`, …) is treated as a **color function**: it works everywhere a color is accepted — style values, `parseColor`, and the `#token.alpha` opacity suffix, which calls the function with a `/ alpha` part appended (read `groups[0].parts[1]`, as below) — with no extra registration. This is the same mechanism the built-in `okhsl`/`okhst` plugins use; they are ordinary plugins registered by default.
|
|
475
485
|
|
|
476
486
|
```ts
|
|
477
487
|
import { configure, createColorFunc } from '@tenphi/tasty';
|
|
@@ -482,8 +492,12 @@ const myColorPlugin = () => ({
|
|
|
482
492
|
functions: {
|
|
483
493
|
// Hand-written parse function:
|
|
484
494
|
mycolor: (groups) => {
|
|
485
|
-
|
|
486
|
-
|
|
495
|
+
// `mycolor(255 0 0 / .5)` and `#brand.5` both arrive as two parts
|
|
496
|
+
const [main, alpha] = groups[0].parts;
|
|
497
|
+
const [r, g, b] = main.all;
|
|
498
|
+
return alpha?.all.length
|
|
499
|
+
? `rgb(${r} ${g} ${b} / ${alpha.output})`
|
|
500
|
+
: `rgb(${r} ${g} ${b})`;
|
|
487
501
|
},
|
|
488
502
|
},
|
|
489
503
|
});
|
|
@@ -549,7 +563,23 @@ configure({
|
|
|
549
563
|
});
|
|
550
564
|
```
|
|
551
565
|
|
|
552
|
-
Recipe values are flat tasty styles (no sub-element keys). They may contain base styles, tokens, local states, `@keyframes`, and `@property`.
|
|
566
|
+
Recipe values are flat tasty styles (no sub-element keys). They may contain base styles, tokens, local states, `@keyframes`, and `@property`.
|
|
567
|
+
|
|
568
|
+
**Recipes cannot reference other recipes.** A `recipe` key inside a configured recipe's value is not recursively resolved:
|
|
569
|
+
|
|
570
|
+
```jsx
|
|
571
|
+
// Unsupported: applying 'elevatedCard' does not expand 'card elevated'.
|
|
572
|
+
configure({
|
|
573
|
+
recipes: {
|
|
574
|
+
elevatedCard: {
|
|
575
|
+
recipe: 'card elevated',
|
|
576
|
+
padding: '6x',
|
|
577
|
+
},
|
|
578
|
+
},
|
|
579
|
+
});
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
Instead, compose the names where you apply the styles: `styles: { recipe: 'card elevated', padding: '6x' }`. Recipe references are resolved on the component root and independently inside each sub-element's styles (for example, `styles: { Panel: { recipe: 'card elevated' } }`). This sub-element support does not allow one recipe definition to inherit another. Tasty warns in development when a recipe definition contains a `recipe` key.
|
|
553
583
|
|
|
554
584
|
For how to apply, compose, and override recipes in components, see [Recipes](dsl.md#recipes) in the Style DSL reference.
|
|
555
585
|
|
|
@@ -615,7 +645,7 @@ configure({
|
|
|
615
645
|
});
|
|
616
646
|
```
|
|
617
647
|
|
|
618
|
-
Each key is a CSS selector, and each value is a Tasty `Styles` object supporting the full style syntax including style properties, tokens, state maps, and selector-based sub-styling (e.g. `$: '> .app'` for elements outside React scope). Global styles are injected alongside `:root` tokens when the first style is rendered.
|
|
648
|
+
Each key is a CSS selector (a list such as `'.uni-checkbox, uni-checkbox'` styles every item), and each value is a Tasty `Styles` object supporting the full style syntax including style properties, tokens, state maps, `@keyframes`, and selector-based sub-styling (e.g. `$: '> .app'` for elements outside React scope). Global styles are injected alongside `:root` tokens when the first style is rendered.
|
|
619
649
|
|
|
620
650
|
Global styles are automatically emitted in all delivery modes: client rendering, server rendering, and build-time extraction with the Babel plugin. Plugins can also provide `globalStyles`; they are merged per selector with config global styles (config wins on conflict).
|
|
621
651
|
|
|
@@ -674,10 +704,16 @@ Override or extend the built-in style property handlers. A handler definition ca
|
|
|
674
704
|
| Single dep | `['styleName', handler]` | Triggered by the specified style property |
|
|
675
705
|
| Multi dep | `[['dep1', 'dep2', ...], handler]` | Triggered by any of the listed properties; receives all of them |
|
|
676
706
|
|
|
677
|
-
The multi-dep form is useful when output depends on several style properties together (e.g., `gap` needs to know `display` and `flow` to decide the CSS strategy). Use `defineHandler` for it and the dependency types are inferred from the dependency list, so a typo in the destructure is a type error instead of a silent `undefined`.
|
|
707
|
+
The multi-dep form is useful when output depends on several style properties together (e.g., `gap` needs to know `display` and `flow` to decide the CSS strategy). A handler whose dependencies include a built-in style takes over that style's whole group — see [Replacing a built-in handler](#replacing-a-built-in-handler). Use `defineHandler` for it and the dependency types are inferred from the dependency list, so a typo in the destructure is a type error instead of a silent `undefined`.
|
|
678
708
|
|
|
679
709
|
```jsx
|
|
680
|
-
import {
|
|
710
|
+
import {
|
|
711
|
+
configure,
|
|
712
|
+
defineHandler,
|
|
713
|
+
parseColor,
|
|
714
|
+
parseStyle,
|
|
715
|
+
styleHandlers,
|
|
716
|
+
} from '@tenphi/tasty';
|
|
681
717
|
|
|
682
718
|
configure({
|
|
683
719
|
handlers: {
|
|
@@ -701,6 +737,10 @@ configure({
|
|
|
701
737
|
'backgroundPosition',
|
|
702
738
|
'backgroundSize',
|
|
703
739
|
'backgroundRepeat',
|
|
740
|
+
'backgroundAttachment',
|
|
741
|
+
'backgroundOrigin',
|
|
742
|
+
'backgroundClip',
|
|
743
|
+
'background',
|
|
704
744
|
],
|
|
705
745
|
(props) => {
|
|
706
746
|
if (
|
|
@@ -713,12 +753,18 @@ configure({
|
|
|
713
753
|
},
|
|
714
754
|
),
|
|
715
755
|
|
|
716
|
-
// Multi dep —
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
756
|
+
// Multi dep — triggered by either name, receives both
|
|
757
|
+
stripe: defineHandler(
|
|
758
|
+
['stripe', 'stripeColor'],
|
|
759
|
+
({ stripe, stripeColor }) => {
|
|
760
|
+
if (!stripe) return;
|
|
761
|
+
const width = parseStyle(String(stripe)).output;
|
|
762
|
+
const color = stripeColor
|
|
763
|
+
? parseColor(String(stripeColor)).color
|
|
764
|
+
: 'currentcolor';
|
|
765
|
+
return { 'border-left': `${width} solid ${color}` };
|
|
766
|
+
},
|
|
767
|
+
),
|
|
722
768
|
},
|
|
723
769
|
});
|
|
724
770
|
```
|
|
@@ -729,6 +775,7 @@ A handler returns a `CSSMap`, an array of them, or nothing:
|
|
|
729
775
|
|
|
730
776
|
- Keys are **kebab-case** CSS property names (`'background-color'`, not `backgroundColor`) or `--custom-property` names. A camelCase key warns in development and is emitted verbatim, which the browser ignores.
|
|
731
777
|
- Values are stringified, so numbers are fine (`{ '-webkit-line-clamp': 3 }`).
|
|
778
|
+
- An array value emits one declaration per entry, in order, so the browser keeps the last one it supports: `{ width: ['-webkit-fill-available', '-moz-available', 'stretch'] }` emits three `width` declarations.
|
|
732
779
|
- The reserved `$` key is a **selector suffix**: `{ $: '& > *:not(:last-child)', 'margin-right': gap }` applies the declarations to a nested selector. It accepts an array to fan out over several.
|
|
733
780
|
- Return an array of maps to emit several declaration sets, each with its own `$`.
|
|
734
781
|
|
|
@@ -740,12 +787,17 @@ Built-in handlers are shared across several style names. Registering a handler f
|
|
|
740
787
|
|
|
741
788
|
The shared groups worth knowing:
|
|
742
789
|
|
|
743
|
-
| Registering a handler for
|
|
744
|
-
|
|
|
745
|
-
| `fill`
|
|
746
|
-
| `display`
|
|
747
|
-
| `
|
|
748
|
-
| `
|
|
790
|
+
| Registering a handler for | Also takes over |
|
|
791
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
792
|
+
| `fill` | `backgroundColor`, `image`, `backgroundImage`, `backgroundPosition`, `backgroundSize`, `backgroundRepeat`, `backgroundAttachment`, `backgroundOrigin`, `backgroundClip`, `background` |
|
|
793
|
+
| `display` | `hide`, `whiteSpace`, `textOverflow`, `flow`, `gap` |
|
|
794
|
+
| `flow` | `gap` |
|
|
795
|
+
| `preset` | `font`, `fontFamily`, `fontSize`, `fontWeight`, `fontStyle`, `lineHeight`, `letterSpacing`, `textTransform` |
|
|
796
|
+
| `padding` / `margin` | their `Top`/`Right`/`Bottom`/`Left` longhands (`paddingTop`, `marginLeft`, …) |
|
|
797
|
+
| `inset` | `top`, `right`, `bottom`, `left` |
|
|
798
|
+
| `width` / `height` | `minWidth`/`maxWidth`, `minHeight`/`maxHeight` |
|
|
799
|
+
|
|
800
|
+
A multi-dep handler takes over every group its dependencies touch: `defineHandler(['display', 'flow', 'gap'], …)` takes over `display`, `flow`, and `gap` together, so it must emit `display` and `flex-flow` itself.
|
|
749
801
|
|
|
750
802
|
Either declare the whole group and delegate the rest to `styleHandlers.*`, or pick a name that isn't shared.
|
|
751
803
|
|
|
@@ -806,18 +858,98 @@ Each name costs one property check per render of every component, and the effect
|
|
|
806
858
|
|
|
807
859
|
---
|
|
808
860
|
|
|
809
|
-
##
|
|
861
|
+
## TypeScript
|
|
810
862
|
|
|
811
|
-
|
|
863
|
+
Component props are typed from the `tasty()` definition with no setup. Module augmentation adds the names your design system defines and the extensions your plugins add.
|
|
864
|
+
|
|
865
|
+
### Component props
|
|
866
|
+
|
|
867
|
+
| In `tasty({ … })` | Adds the props |
|
|
868
|
+
| --------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
869
|
+
| `styleProps: ['gap', 'padding'] as const` | `gap`, `padding`, each typed like the style: a value or a state map |
|
|
870
|
+
| `modProps: { isLoading: Boolean, size: ['sm', 'md', 'lg'] as const }` | `isLoading?: boolean`, `size?: 'sm' \| 'md' \| 'lg'` (`String` gives `string`, `Number` gives `number`) |
|
|
871
|
+
| `modProps: ['isLoading'] as const` | `isLoading?: ModValue` |
|
|
872
|
+
| `tokenProps: ['progress', 'accentColor'] as const` | `progress?: TokenValue`, `accentColor?: TokenValue` |
|
|
873
|
+
| `variants: { default: {…}, danger: {…} }` | `variant?: 'default' \| 'danger'` |
|
|
874
|
+
| `elements: { Title: 'h3' }` | `Card.Title`, with the `h3` props plus `qa`, `qaVal`, `mods`, `tokens`, `isDisabled`, `isHidden`, `isChecked`, and a `ref` typed as `HTMLHeadingElement`; no `styles` |
|
|
875
|
+
| `as: SomeComponent` | `SomeComponent`'s own props, required ones still required |
|
|
876
|
+
|
|
877
|
+
Write the array forms with `as const`. Without it, `modProps: ['isLoading']` widens to `string[]` and every prop on the component is typed `ModValue`, so an `onClick` handler no longer type-checks. A `modProps` value list without `as const` widens to `string`.
|
|
878
|
+
|
|
879
|
+
`tasty(Base, { … })` keeps `Base`'s prop types and sub-elements, and adds the props and sub-elements its own options above declare. Its `variant` accepts both its own variant names and `Base`'s. See [Extend an existing component](react-api.md#extend-an-existing-component).
|
|
880
|
+
|
|
881
|
+
### Registering your names and extensions
|
|
882
|
+
|
|
883
|
+
```ts
|
|
884
|
+
// tasty.d.ts — keep the import: it makes this file a module, so the block
|
|
885
|
+
// below extends '@tenphi/tasty' instead of replacing it.
|
|
886
|
+
import '@tenphi/tasty';
|
|
812
887
|
|
|
813
|
-
```tsx
|
|
814
|
-
// tasty.d.ts
|
|
815
888
|
declare module '@tenphi/tasty' {
|
|
889
|
+
interface TastyNamedColors {
|
|
890
|
+
surface: true;
|
|
891
|
+
text: true;
|
|
892
|
+
primary: true;
|
|
893
|
+
}
|
|
894
|
+
interface TastyPresetNames {
|
|
895
|
+
h1: true;
|
|
896
|
+
t2: true;
|
|
897
|
+
}
|
|
898
|
+
interface TastyThemeNames {
|
|
899
|
+
danger: true;
|
|
900
|
+
success: true;
|
|
901
|
+
}
|
|
816
902
|
interface StylesInterface {
|
|
817
|
-
|
|
818
|
-
|
|
903
|
+
stripe?: string;
|
|
904
|
+
}
|
|
905
|
+
interface TastyCustomProps {
|
|
906
|
+
glaze: 'soft' | 'strong' | { tone: string; intensity?: number };
|
|
907
|
+
}
|
|
908
|
+
interface TastyBaseStylePropNames {
|
|
909
|
+
radius: true;
|
|
910
|
+
stripe: true;
|
|
819
911
|
}
|
|
820
912
|
}
|
|
821
913
|
```
|
|
822
914
|
|
|
915
|
+
| Interface | Register | What it types |
|
|
916
|
+
| ------------------------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------ |
|
|
917
|
+
| `TastyNamedColors` | Color token names from `tokens` and `replaceTokens`, without the `#` | Suggestions for `#name` and `#name.50` in `fill`, `color`, and `svgFill` |
|
|
918
|
+
| `TastyPresetNames` | `presets` names | The `preset` style and prop |
|
|
919
|
+
| `TastyThemeNames` | Theme names | The `theme` prop (rendered as `data-theme`) |
|
|
920
|
+
| `StylesInterface` | Style properties added with `handlers` | Their value type in `styles`, `styleProps`, and base style props |
|
|
921
|
+
| `TastyCustomProps` | Props added with `propHandlers` | An optional prop on every `tasty()` component (not on sub-elements) |
|
|
922
|
+
| `TastyBaseStylePropNames` | Names passed to `baseStyleProps` | A prop on every component, typed like the style it names |
|
|
923
|
+
|
|
924
|
+
- The first three add autocomplete, not checking: any other string still type-checks (`preset: 'h9'` compiles). The ESLint plugin is what reports unknown names.
|
|
925
|
+
- In `StylesInterface`, declare the plain value type (`stripe?: string`). Tasty adds state-map support itself, as it does for built-in styles.
|
|
926
|
+
- A custom style name in `styles` type-checks without augmentation, but `styleProps` and `TastyBaseStylePropNames` accept only names in `StylesInterface`. A base style prop name missing from it adds no prop.
|
|
927
|
+
- `TastyCustomProps` types the component prop, not the handler. A prop handler receives `Record<string, unknown>`, so cast inside it (`rest.styles as Styles`).
|
|
928
|
+
- State keys, `$` value tokens, units, and recipe names have no TypeScript types. The ESLint plugin checks them against `tasty.config.ts`.
|
|
929
|
+
|
|
930
|
+
### `tasty.config.ts`
|
|
931
|
+
|
|
932
|
+
TypeScript augmentation does not reach the linter or the editor. [`@tenphi/eslint-plugin-tasty`](https://github.com/tenphi/eslint-plugin-tasty) and the Tasty VS Code extension read a `tasty.config.ts` (or `.js`, `.json`) at the project root instead. It only lists names: it is not passed to `configure()`, and it is unrelated to the Babel plugin's `configFile` (such as `tasty-zero.config.ts`).
|
|
933
|
+
|
|
934
|
+
```ts
|
|
935
|
+
// tasty.config.ts
|
|
936
|
+
import type { TastyExtensionConfig } from '@tenphi/tasty';
|
|
937
|
+
import type { TastyValidationConfig } from '@tenphi/eslint-plugin-tasty';
|
|
938
|
+
|
|
939
|
+
export default {
|
|
940
|
+
tokens: ['#surface', '#text', '#primary', '$sidebar-width'],
|
|
941
|
+
units: ['cols'],
|
|
942
|
+
states: ['@mobile', '@dark'],
|
|
943
|
+
presets: ['h1', 't2'],
|
|
944
|
+
recipes: ['card', 'elevated'],
|
|
945
|
+
styles: ['stripe'],
|
|
946
|
+
importSources: ['@my-org/ui'],
|
|
947
|
+
presetDescriptions: { h1: 'Heading 1 (32px, bold)' },
|
|
948
|
+
} satisfies TastyExtensionConfig & TastyValidationConfig;
|
|
949
|
+
```
|
|
950
|
+
|
|
951
|
+
`TastyExtensionConfig` from `@tenphi/tasty` types the fields the VS Code extension reads: `extends`, `tokens`, `units`, `functions`, `states`, `presets`, `styles`, `presetDescriptions`, and `stateDescriptions`. It has no `recipes`, `importSources`, `ownedSources`, or `styleFunctions`, so annotating the file with it alone rejects those ESLint fields; intersect it with the plugin's `TastyValidationConfig`, as above. An omitted list is not checked; `tokens: false`, `units: false`, or `functions: false` turns a check off even when an `extends` parent sets it.
|
|
952
|
+
|
|
953
|
+
Keep it in step with `configure()`: token names with their `#` or `$`, custom units, parse-function names, state aliases, presets, recipes, and custom style names.
|
|
954
|
+
|
|
823
955
|
See [Style DSL](dsl.md) for state maps, tokens, units, and extending semantics, and [React API](react-api.md) for `tasty()`, style functions, and component props.
|
package/docs/debug.md
CHANGED
|
@@ -6,9 +6,7 @@ Runtime CSS inspection and diagnostics for the Tasty styling system. Inspect inj
|
|
|
6
6
|
|
|
7
7
|
## Overview
|
|
8
8
|
|
|
9
|
-
`tastyDebug` is a diagnostic object that exposes Tasty's runtime CSS state. It is designed for development use
|
|
10
|
-
|
|
11
|
-
In development mode (`isDevEnv()` returns `true`), `tastyDebug` is automatically installed on `window.tastyDebug`. In production, install it manually when needed.
|
|
9
|
+
`tastyDebug` is a diagnostic object that exposes Tasty's runtime CSS state. It is designed for development use and can be installed on `window` explicitly when needed.
|
|
12
10
|
|
|
13
11
|
All methods **log to the console by default**. Pass `{ raw: true }` to suppress logging and only return data.
|
|
14
12
|
|
|
@@ -19,7 +17,6 @@ All methods **log to the console by default**. Pass `{ raw: true }` to suppress
|
|
|
19
17
|
## Quick Start
|
|
20
18
|
|
|
21
19
|
```typescript
|
|
22
|
-
// Auto-installed in dev mode. Otherwise:
|
|
23
20
|
import { tastyDebug } from '@tenphi/tasty';
|
|
24
21
|
tastyDebug.install();
|
|
25
22
|
|
|
@@ -81,7 +78,7 @@ Retrieves CSS text for a given target. Logs the result with rule count and size.
|
|
|
81
78
|
|---|---|
|
|
82
79
|
| `'all'` | All tasty CSS (component + global + raw) |
|
|
83
80
|
| `'active'` | CSS for classes currently in the DOM |
|
|
84
|
-
| `'unused'` | CSS for
|
|
81
|
+
| `'unused'` | CSS for classes `gc({ force: true })` would delete now — not rendered, not pinned, past the `gc.grace` window |
|
|
85
82
|
| `'global'` | Only global CSS (from `injectGlobal`) |
|
|
86
83
|
| `'page'` | All CSS on the page (including non-tasty) |
|
|
87
84
|
| `'t3a5f'` | CSS for a specific tasty class (class names are `t` + base36 hash) |
|
|
@@ -157,7 +154,8 @@ One-shot overview of the entire Tasty CSS state. Logs a compact report.
|
|
|
157
154
|
```typescript
|
|
158
155
|
interface Summary {
|
|
159
156
|
activeClasses: string[];
|
|
160
|
-
unusedClasses: string[];
|
|
157
|
+
unusedClasses: string[]; // classes gc({ force: true }) would delete now
|
|
158
|
+
hotClasses: string[]; // not rendered, but pinned or inside gc.grace — not yet collectable
|
|
161
159
|
totalStyledClasses: string[];
|
|
162
160
|
|
|
163
161
|
activeCSSSize: number;
|
|
@@ -277,7 +275,7 @@ tastyDebug.help();
|
|
|
277
275
|
|
|
278
276
|
### `install(): void`
|
|
279
277
|
|
|
280
|
-
Attaches `tastyDebug` to `window.tastyDebug`.
|
|
278
|
+
Attaches `tastyDebug` to `window.tastyDebug`.
|
|
281
279
|
|
|
282
280
|
```typescript
|
|
283
281
|
import { tastyDebug } from '@tenphi/tasty';
|