@tenphi/tasty 0.0.0-snapshot.dffd134 → 0.0.0-snapshot.e01a0ee
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 +436 -394
- 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-DlxpZKk_.js +60 -0
- package/dist/chunks/build-config-DlxpZKk_.js.map +1 -0
- package/dist/{collector-UWhVKseF.js → chunks/collector-B4-yqFEs.js} +25 -119
- package/dist/chunks/collector-B4-yqFEs.js.map +1 -0
- package/dist/chunks/config-engine-DJsb5WYu.js +272 -0
- package/dist/chunks/config-engine-DJsb5WYu.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-DW1TGGiy.js +910 -0
- package/dist/chunks/css-definitions-DW1TGGiy.js.map +1 -0
- package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/chunks/debug-DMMwe1rY.js +502 -0
- package/dist/chunks/debug-DMMwe1rY.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-DhPtFlZs.js +689 -0
- package/dist/chunks/react-runtime-DhPtFlZs.js.map +1 -0
- package/dist/chunks/runtime-engine-BlrVXv8l.js +2432 -0
- package/dist/chunks/runtime-engine-BlrVXv8l.js.map +1 -0
- package/dist/chunks/runtime-state-BLyMRYFF.js +152 -0
- package/dist/chunks/runtime-state-BLyMRYFF.js.map +1 -0
- package/dist/{merge-styles-CVCZ4hgD.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-of5Xbc27.js +5571 -0
- package/dist/chunks/style-engine-of5Xbc27.js.map +1 -0
- package/dist/{css-writer-DEkJuPH6.js → chunks/zero-engine-D2jPSpWA.js} +65 -145
- package/dist/chunks/zero-engine-D2jPSpWA.js.map +1 -0
- package/dist/{collector-BPzZezAG.d.ts → collector-CTU-nl0g.d.ts} +23 -4
- package/dist/{config-D2INrjr_.d.ts → config-CcxqSZI2.d.ts} +274 -78
- 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-BAAbdfRs.d.ts → index--GdqCPlp.d.ts} +366 -257
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -867
- package/dist/{merge-styles-NEvqayL_.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 +10 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +3 -2
- package/dist/ssr/astro-middleware-static.js +0 -11
- package/dist/ssr/astro-middleware-static.js.map +1 -1
- package/dist/ssr/astro-middleware.d.ts +3 -2
- package/dist/ssr/astro-middleware.js +0 -12
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -6
- package/dist/ssr/astro.js +157 -93
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +5 -25
- package/dist/ssr/index.js +5 -5
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +123 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -8
- package/dist/ssr/next.js +29 -43
- 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-l_NdJSUS.d.ts → types-DJEM_BOJ.d.ts} +751 -590
- 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 +16 -8
- package/docs/adoption.md +69 -36
- package/docs/ai-agents.md +122 -85
- package/docs/comparison.md +77 -47
- package/docs/configuration.md +435 -108
- package/docs/debug.md +21 -8
- package/docs/design-system.md +152 -31
- package/docs/dsl.md +497 -211
- package/docs/getting-started.md +130 -50
- package/docs/injector.md +117 -68
- package/docs/methodology.md +81 -50
- package/docs/migration-v3.md +52 -52
- package/docs/pipeline.md +55 -31
- package/docs/plugins.md +59 -75
- package/docs/react-api.md +139 -53
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +285 -101
- package/docs/styles.md +128 -33
- package/docs/tasty-static.md +272 -135
- package/package.json +119 -39
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/babel-HlEpSZrj.d.ts +0 -83
- package/dist/collector-UWhVKseF.js.map +0 -1
- package/dist/config-BCuFlC1I.js +0 -12180
- package/dist/config-BCuFlC1I.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-CbMYIizf.js +0 -1550
- package/dist/core-CbMYIizf.js.map +0 -1
- package/dist/css-writer-DEkJuPH6.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-D2J4PbR5.js +0 -143
- package/dist/format-rules-D2J4PbR5.js.map +0 -1
- package/dist/hydrate-lZeNoz_w.js +0 -37
- package/dist/hydrate-lZeNoz_w.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-BUMyAa-Q.js +0 -424
- package/dist/keyframes-BUMyAa-Q.js.map +0 -1
- package/dist/merge-styles-CVCZ4hgD.js.map +0 -1
- package/dist/resolve-recipes-BnMC1WW1.js +0 -144
- package/dist/resolve-recipes-BnMC1WW1.js.map +0 -1
package/docs/configuration.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Configuration
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Tasty works without upfront configuration. Use `configure()` when your app or design system is ready to define shared tokens, state aliases, units, recipes, presets, or extension points.
|
|
4
|
+
|
|
5
|
+
Call it **before any styles are generated** (before first render). For a guided setup, see [Getting Started](getting-started.md). For the higher-level docs map, see the [Docs Hub](README.md).
|
|
4
6
|
|
|
5
7
|
```jsx
|
|
6
8
|
import { configure } from '@tenphi/tasty';
|
|
@@ -21,9 +23,8 @@ configure({
|
|
|
21
23
|
|
|
22
24
|
// Custom units (merged with built-in units)
|
|
23
25
|
units: {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
custom: (n) => `${n * 10}px`, // Function-based unit
|
|
26
|
+
gu: '4px', // `2gu` → `8px`
|
|
27
|
+
cols: (n) => `calc(${n} * var(--col-width))`, // function-based unit
|
|
27
28
|
},
|
|
28
29
|
|
|
29
30
|
// Custom functions — a single map for both flavors, discriminated by value type:
|
|
@@ -45,60 +46,244 @@ These docs use `data-schema="dark"` in examples. If your app already standardize
|
|
|
45
46
|
|
|
46
47
|
## Options
|
|
47
48
|
|
|
48
|
-
| Option
|
|
49
|
-
|
|
50
|
-
| `nonce`
|
|
51
|
-
| `maxRulesPerSheet`
|
|
52
|
-
| `forceTextInjection` | `boolean`
|
|
53
|
-
| `devMode`
|
|
54
|
-
| `states`
|
|
55
|
-
| `parserCacheSize`
|
|
56
|
-
| `units`
|
|
57
|
-
| `functions`
|
|
58
|
-
| `handlers`
|
|
59
|
-
| `propHandlers`
|
|
60
|
-
| `baseStyleProps`
|
|
61
|
-
| `tokens`
|
|
62
|
-
| `replaceTokens`
|
|
63
|
-
| `keyframes`
|
|
64
|
-
| `properties`
|
|
65
|
-
| `fontFaces`
|
|
66
|
-
| `counterStyles`
|
|
67
|
-
| `polyfills`
|
|
68
|
-
| `autoPropertyTypes`
|
|
69
|
-
| `recipes`
|
|
70
|
-
| `presets`
|
|
71
|
-
| `globalStyles`
|
|
72
|
-
| `plugins`
|
|
73
|
-
| `gc`
|
|
74
|
-
| `
|
|
75
|
-
| `
|
|
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). |
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Batched Injection
|
|
82
|
+
|
|
83
|
+
Every `insertRule()` on a live stylesheet invalidates style for that sheet's
|
|
84
|
+
scope. Components inject during React's render phase, and if anything else reads
|
|
85
|
+
layout in the same pass, the two interleave:
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
inject -> read (forced style recalc) -> inject -> read (forced recalc) -> ...
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
A UI kit that measures during render — popovers, autosizing inputs, virtualized
|
|
92
|
+
lists — can turn one mount into a dozen full-tree recalculations. `batchInjection`
|
|
93
|
+
queues the writes instead and applies them together, so the tree is invalidated
|
|
94
|
+
once per flush.
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import { configure, TastyBatchProvider } from '@tenphi/tasty';
|
|
98
|
+
|
|
99
|
+
configure({ batchInjection: true });
|
|
100
|
+
|
|
101
|
+
createRoot(el).render(
|
|
102
|
+
<TastyBatchProvider>
|
|
103
|
+
<App />
|
|
104
|
+
</TastyBatchProvider>,
|
|
105
|
+
);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Why the provider is required
|
|
109
|
+
|
|
110
|
+
Deferring a write past React's layout phase would let a `useLayoutEffect`
|
|
111
|
+
measure an element whose rules are not in the sheet yet and read its _unstyled_
|
|
112
|
+
box — a wrong number, not a stale one, so it never self-corrects.
|
|
113
|
+
|
|
114
|
+
`TastyBatchProvider` closes that hole. It opens a _batch window_ during its
|
|
115
|
+
render and closes it — flushing — in `useInsertionEffect`, which React runs in
|
|
116
|
+
the mutation phase, before any layout effect:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
provider renders -> window OPEN
|
|
120
|
+
children render -> injections queued
|
|
121
|
+
provider insertionEffect -> FLUSH, window CLOSED
|
|
122
|
+
layout effects run -> rules are in the sheet
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
With `batchInjection: true` a write is only ever queued inside such a window, so
|
|
126
|
+
turning the flag on can make injection cheaper but can never make a measurement
|
|
127
|
+
wrong. Injections outside a window are written straight through, exactly as with
|
|
128
|
+
batching off:
|
|
129
|
+
|
|
130
|
+
- a deep update that did not re-render the provider
|
|
131
|
+
- an injection from a layout effect, an event handler or an async callback
|
|
132
|
+
- SSR and RSC, where there is no live sheet at all
|
|
133
|
+
|
|
134
|
+
Mount the provider as high in the tree as you can: batching applies to the
|
|
135
|
+
commits it takes part in.
|
|
136
|
+
|
|
137
|
+
### Modes
|
|
138
|
+
|
|
139
|
+
| Value | Behaviour |
|
|
140
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
141
|
+
| `false` (default) | One `insertRule()` per component, synchronously. |
|
|
142
|
+
| `true` | Batch inside a provider window only. Cannot affect measurement. Without the provider nothing is batched, and dev mode says so once. |
|
|
143
|
+
| `'always'` | Batch every injection, flushing on a microtask when no window is open. Covers more commits; a `useLayoutEffect` measuring a freshly mounted element can read its unstyled box. Paint is unaffected — microtasks always drain before the browser paints. |
|
|
144
|
+
|
|
145
|
+
### Ordering
|
|
146
|
+
|
|
147
|
+
All writes share one FIFO queue — component rules, global rules, raw CSS,
|
|
148
|
+
`@property`, `@keyframes`, `@font-face`, `@counter-style` and `@function`.
|
|
149
|
+
Draining it in insertion order keeps the sheet byte-identical to unbatched
|
|
150
|
+
output, which matters because equal-specificity rules resolve by document order.
|
|
151
|
+
|
|
152
|
+
### Client rendering, server rendering, and build-time extraction
|
|
153
|
+
|
|
154
|
+
**Server render — nothing to batch, safe to leave enabled.** SSR and RSC collect
|
|
155
|
+
CSS as text through `ServerStyleCollector`; the runtime injector never runs
|
|
156
|
+
there, so `batchInjection` changes nothing either way. `<TastyBatchProvider>`
|
|
157
|
+
renders its children and does nothing else: the window it opens is a no-op
|
|
158
|
+
without a `document`, and the `useInsertionEffect` that would close it never
|
|
159
|
+
fires on the server. Configure the flag once in shared code — no environment
|
|
160
|
+
branching needed.
|
|
161
|
+
|
|
162
|
+
**Hydration — the better your SSR coverage, the less there is to batch.**
|
|
163
|
+
`hydrateTastyClasses()` (wired up for you by `@tenphi/tasty/ssr/next` and the
|
|
164
|
+
Astro integration) pre-populates the injector from `window.__TASTY__`, so
|
|
165
|
+
hydrating a server-rendered class is a cache hit that produces no sheet write at
|
|
166
|
+
all. Batching pays off on what SSR could not cover: client-only routes, styles
|
|
167
|
+
that first appear after hydration (a `styles` prop that changes on interaction, a
|
|
168
|
+
modal or popover mounting), and dynamic tokens.
|
|
169
|
+
|
|
170
|
+
**Astro islands — one provider per island, or `'always'`.** Every island is its
|
|
171
|
+
own React root, so a provider inside one island does not open a window for
|
|
172
|
+
another. With `batchInjection: true`, wrap each island root that renders enough
|
|
173
|
+
tasty components to be worth it. `'always'` needs no provider and covers every
|
|
174
|
+
island, at the cost of the measurement hazard above. Either way, an island that
|
|
175
|
+
only re-hydrates server-rendered classes has nothing to batch.
|
|
176
|
+
|
|
177
|
+
**Build-time extraction (`tastyStatic`) — unaffected.** The Babel plugin never
|
|
178
|
+
touches the injector: the babel plugin emits either a CSS file import or an
|
|
179
|
+
`injectCSS()` call from `@tenphi/tasty/static/inject`, which appends text to a
|
|
180
|
+
single `<style data-tasty-static>` element. `batchInjection` only defers CSSOM
|
|
181
|
+
writes made by the browser injector, so extracted styles are unchanged. In an app
|
|
182
|
+
that mixes both, it still applies to the `tasty()` half.
|
|
183
|
+
|
|
184
|
+
### `flushStyles()`
|
|
185
|
+
|
|
186
|
+
Applies every pending write immediately. Every injector read API calls it for
|
|
187
|
+
you — `getCSSText`, `getCSSTextForClasses`, `getCSSTextForNode`,
|
|
188
|
+
`getRawCSSText`, `isPropertyDefined`, `getMetrics`, `cleanup`, `gc` and
|
|
189
|
+
`destroy` — so a read never observes a partial sheet.
|
|
190
|
+
Call it directly before measuring in code that runs outside a batch window under
|
|
191
|
+
`'always'`:
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
import { flushStyles } from '@tenphi/tasty';
|
|
195
|
+
|
|
196
|
+
useLayoutEffect(() => {
|
|
197
|
+
flushStyles();
|
|
198
|
+
const { width } = ref.current.getBoundingClientRect();
|
|
199
|
+
}, []);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
`hasPendingStyleWrites()` reports whether anything is queued, and
|
|
203
|
+
`resetStyleBatch()` drops the queue without applying it (tests only).
|
|
76
204
|
|
|
77
205
|
---
|
|
78
206
|
|
|
79
207
|
## Color Space
|
|
80
208
|
|
|
81
|
-
|
|
209
|
+
> **Deprecated.** `configure({ colorSpace })` no longer has any effect and will
|
|
210
|
+
> be removed in the next major. Setting it warns in development.
|
|
211
|
+
|
|
212
|
+
A `#name` token's value used to be rewritten into a configured color space, so
|
|
213
|
+
`#brand: '#ff8800'` declared `--brand-color: oklch(0.75 0.16 55)`. That existed
|
|
214
|
+
to serve the opacity suffix, which needed numeric channels to write an alpha
|
|
215
|
+
into. Opacity now uses CSS relative color syntax —
|
|
216
|
+
`oklch(from var(--brand-color) l c h / .5)` — which has the browser read the
|
|
217
|
+
channels, so there is nothing left for the setting to decide.
|
|
218
|
+
|
|
219
|
+
A color is emitted exactly as authored:
|
|
82
220
|
|
|
83
221
|
```jsx
|
|
84
|
-
configure({
|
|
85
|
-
|
|
86
|
-
});
|
|
222
|
+
configure({ tokens: { '#brand': '#ff8800' } });
|
|
223
|
+
// → --brand-color: #ff8800
|
|
87
224
|
```
|
|
88
225
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
226
|
+
That holds for every form: a hex literal, a native color function, a bare CSS
|
|
227
|
+
color name, a `color-mix()`, a `light-dark()`, a fallback chain. A `#token`
|
|
228
|
+
reference still resolves to its `var()` chain, and a plugin color function such
|
|
229
|
+
as `okhsl()` is still resolved by the parser to the color it denotes.
|
|
230
|
+
|
|
231
|
+
To address a token's channels, use relative color syntax against the token:
|
|
232
|
+
|
|
233
|
+
```css
|
|
234
|
+
background: oklch(from var(--brand-color) calc(l * 1.2) c h);
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
This works on any `<color>`, including the ones no build-time conversion could
|
|
238
|
+
have evaluated — and it is what the [opacity suffix](dsl.md#color-tokens--opacity)
|
|
239
|
+
itself uses. Its space is always `oklch`, which is unbounded, so a wide-gamut
|
|
240
|
+
color survives a round trip a narrower space would clamp.
|
|
241
|
+
|
|
242
|
+
### Migrating off `colorSpace`
|
|
243
|
+
|
|
244
|
+
Drop the option. If you relied on the uniform output format, nothing in Tasty
|
|
245
|
+
needs it — author your tokens in the space you want them emitted in, since the
|
|
246
|
+
value now passes through untouched:
|
|
247
|
+
|
|
248
|
+
```jsx
|
|
249
|
+
// before: any input, normalized to the configured space on the way out
|
|
250
|
+
configure({ colorSpace: 'oklch', tokens: { '#brand': '#ff8800' } });
|
|
251
|
+
|
|
252
|
+
// after: author it in the space you want
|
|
253
|
+
configure({ tokens: { '#brand': 'oklch(0.75 0.16 55)' } });
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Migrating off the channel companions
|
|
257
|
+
|
|
258
|
+
A `#name` token used to declare a second variable beside `--name-color` holding
|
|
259
|
+
its channels decomposed, suffixed with the configured space —
|
|
260
|
+
`--brand-color-oklch: 0.75 0.16 55` — and a `color` style emitted
|
|
261
|
+
`--current-color-{space}` beside `--current-color`. Both are gone, for the same
|
|
262
|
+
reason: they existed so an opacity suffix had channels to write an alpha into.
|
|
94
263
|
|
|
95
|
-
|
|
264
|
+
These were never part of the public API, but they were visible in the emitted
|
|
265
|
+
CSS, so hand-authored CSS may reference one. Address the token itself instead:
|
|
266
|
+
|
|
267
|
+
```css
|
|
268
|
+
/* before */
|
|
269
|
+
color: oklch(var(--brand-color-oklch) / 0.5);
|
|
270
|
+
background: oklch(var(--brand-color-oklch));
|
|
271
|
+
|
|
272
|
+
/* after */
|
|
273
|
+
color: oklch(from var(--brand-color) l c h / 0.5);
|
|
274
|
+
background: var(--brand-color);
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
The replacement is strictly more capable — the companion could only be
|
|
278
|
+
decomposed for a color the engine could evaluate at build time, while relative
|
|
279
|
+
color syntax works on every `<color>`, including a `color-mix()`, a
|
|
280
|
+
`light-dark()`, and a variable Tasty never defined.
|
|
96
281
|
|
|
97
282
|
---
|
|
98
283
|
|
|
99
284
|
## Name Prefix
|
|
100
285
|
|
|
101
|
-
Every identifier Tasty generates — class names, keyframe names, counter-style names — starts with a configurable prefix. The
|
|
286
|
+
Every identifier Tasty generates — class names, keyframe names, counter-style names — starts with a configurable prefix. The `tasty()` client, SSR, and RSC paths default to `'t'`; the build-time extraction path (`tastyStatic` via the Babel plugin) defaults to `'ts'` so extracted classes can never collide with `tasty()` classes when both are loaded on the same page.
|
|
102
287
|
|
|
103
288
|
```jsx
|
|
104
289
|
configure({
|
|
@@ -108,12 +293,12 @@ configure({
|
|
|
108
293
|
|
|
109
294
|
The prefix is prepended verbatim to the hash, so include any separator inside the prefix string itself:
|
|
110
295
|
|
|
111
|
-
| Setting
|
|
112
|
-
|
|
113
|
-
| `'t'` (
|
|
114
|
-
| `'ts'` (
|
|
115
|
-
| `'mb'`
|
|
116
|
-
| `'myapp-'`
|
|
296
|
+
| Setting | Class | Keyframe | Counter-style |
|
|
297
|
+
| --------------------------- | ------------- | -------------- | -------------- |
|
|
298
|
+
| `'t'` (`tasty` default) | `t1a2b3` | `tk1a2b3` | `tc1a2b3` |
|
|
299
|
+
| `'ts'` (build-time default) | `ts1a2b3` | `tsk1a2b3` | `tsc1a2b3` |
|
|
300
|
+
| `'mb'` | `mb1a2b3` | `mbk1a2b3` | `mbc1a2b3` |
|
|
301
|
+
| `'myapp-'` | `myapp-1a2b3` | `myapp-k1a2b3` | `myapp-c1a2b3` |
|
|
117
302
|
|
|
118
303
|
The single-letter discriminators (`k` for keyframes, `c` for counter-styles) keep the three kinds visually distinct in devtools — they are not required for correctness because CSS keeps these in separate namespaces.
|
|
119
304
|
|
|
@@ -123,12 +308,12 @@ The single-letter discriminators (`k` for keyframes, `c` for counter-styles) kee
|
|
|
123
308
|
- Validated at `configure()` time; an invalid prefix throws synchronously rather than silently producing broken hydration.
|
|
124
309
|
- Locked once styles have been generated, like all other config.
|
|
125
310
|
|
|
126
|
-
### Coexistence with
|
|
311
|
+
### Coexistence with build-time extraction
|
|
127
312
|
|
|
128
|
-
The
|
|
313
|
+
The `tasty()` and `tastyStatic()` paths **must use different prefixes** when both are loaded on the same page. Defaults already guarantee this; if you customize one, customize the other accordingly:
|
|
129
314
|
|
|
130
315
|
```jsx
|
|
131
|
-
// app config (
|
|
316
|
+
// app config (client / SSR / RSC)
|
|
132
317
|
configure({ namePrefix: 'mb' });
|
|
133
318
|
|
|
134
319
|
// tasty-zero.config.ts (Babel plugin)
|
|
@@ -148,8 +333,7 @@ Tokens support state maps for responsive or theme-aware values:
|
|
|
148
333
|
```jsx
|
|
149
334
|
configure({
|
|
150
335
|
tokens: {
|
|
151
|
-
'$
|
|
152
|
-
'$radius': '6px',
|
|
336
|
+
'$sidebar-width': '280px',
|
|
153
337
|
'#primary': {
|
|
154
338
|
'': '#purple',
|
|
155
339
|
'@dark': '#light-purple',
|
|
@@ -163,9 +347,11 @@ configure({
|
|
|
163
347
|
```
|
|
164
348
|
|
|
165
349
|
- `$name` keys become `--name` CSS custom properties
|
|
166
|
-
- `#name` keys become `--name-color`
|
|
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))`
|
|
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.
|
|
167
353
|
|
|
168
|
-
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).
|
|
169
355
|
|
|
170
356
|
---
|
|
171
357
|
|
|
@@ -188,6 +374,17 @@ configure({
|
|
|
188
374
|
|
|
189
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)`.
|
|
190
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
|
+
|
|
191
388
|
See [Replace Tokens](dsl.md#replace-tokens) in the Style DSL reference.
|
|
192
389
|
|
|
193
390
|
---
|
|
@@ -219,7 +416,7 @@ configure({
|
|
|
219
416
|
});
|
|
220
417
|
```
|
|
221
418
|
|
|
222
|
-
Now any component can use `
|
|
419
|
+
Now any component can use `font: '"Brand Sans", sans-serif'` and the browser will already have the `@font-face` rules in the stylesheet.
|
|
223
420
|
|
|
224
421
|
See [Font Face (`@font-face`)](dsl.md#font-face-font-face) for inline usage inside component styles and the full list of supported descriptors.
|
|
225
422
|
|
|
@@ -276,7 +473,7 @@ configure({
|
|
|
276
473
|
});
|
|
277
474
|
```
|
|
278
475
|
|
|
279
|
-
Components then invoke parse functions as `double(...)` and CSS functions with the `$$name(...)` sugar, e.g. `
|
|
476
|
+
Components then invoke parse functions as `double(...)` and CSS functions with the `$$name(...)` sugar, e.g. `margin: '$$negative(10px) top'`.
|
|
280
477
|
|
|
281
478
|
> A key whose prefix doesn't match its value type (an object under a bare key, or a function under a `$$` key) is **ignored with a dev-mode warning**.
|
|
282
479
|
|
|
@@ -284,7 +481,7 @@ See [Functions (`@function`)](dsl.md#functions-function) for inline usage inside
|
|
|
284
481
|
|
|
285
482
|
### Custom color functions
|
|
286
483
|
|
|
287
|
-
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.
|
|
288
485
|
|
|
289
486
|
```ts
|
|
290
487
|
import { configure, createColorFunc } from '@tenphi/tasty';
|
|
@@ -295,8 +492,12 @@ const myColorPlugin = () => ({
|
|
|
295
492
|
functions: {
|
|
296
493
|
// Hand-written parse function:
|
|
297
494
|
mycolor: (groups) => {
|
|
298
|
-
|
|
299
|
-
|
|
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})`;
|
|
300
501
|
},
|
|
301
502
|
},
|
|
302
503
|
});
|
|
@@ -326,7 +527,7 @@ configure({
|
|
|
326
527
|
},
|
|
327
528
|
});
|
|
328
529
|
|
|
329
|
-
// Now `
|
|
530
|
+
// Now `margin: '$$negative(10px) top'` renders `margin: calc(-1 * 10px) 0 0 0`
|
|
330
531
|
// — no native @function rule is emitted.
|
|
331
532
|
```
|
|
332
533
|
|
|
@@ -362,7 +563,23 @@ configure({
|
|
|
362
563
|
});
|
|
363
564
|
```
|
|
364
565
|
|
|
365
|
-
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.
|
|
366
583
|
|
|
367
584
|
For how to apply, compose, and override recipes in components, see [Recipes](dsl.md#recipes) in the Style DSL reference.
|
|
368
585
|
|
|
@@ -419,7 +636,7 @@ configure({
|
|
|
419
636
|
color: '#text',
|
|
420
637
|
preset: 't2',
|
|
421
638
|
margin: 0,
|
|
422
|
-
|
|
639
|
+
font: 'system-ui, sans-serif',
|
|
423
640
|
},
|
|
424
641
|
html: {
|
|
425
642
|
overflow: 'hidden',
|
|
@@ -428,9 +645,9 @@ configure({
|
|
|
428
645
|
});
|
|
429
646
|
```
|
|
430
647
|
|
|
431
|
-
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.
|
|
432
649
|
|
|
433
|
-
Global styles are automatically emitted in all
|
|
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).
|
|
434
651
|
|
|
435
652
|
---
|
|
436
653
|
|
|
@@ -438,18 +655,18 @@ Global styles are automatically emitted in all rendering modes: runtime (client)
|
|
|
438
655
|
|
|
439
656
|
CSS cannot transition or animate custom properties unless their type is declared via [`@property`](https://developer.mozilla.org/en-US/docs/Web/CSS/@property). Tasty handles this automatically — when a custom property is assigned a concrete value (e.g. `'$scale': 1`, `'$gap': '10px'`, `'#accent': 'purple'`), the type is inferred and a `@property` rule is registered.
|
|
440
657
|
|
|
441
|
-
This works across all declaration contexts: component styles, `@keyframes`, global config, and the
|
|
658
|
+
This works across all declaration contexts: component styles, `@keyframes`, global config, and build-time extraction with the Babel plugin. It also resolves `var()` chains — if `$a` references `var(--b)`, the type propagates once `--b` is resolved.
|
|
442
659
|
|
|
443
660
|
Supported types:
|
|
444
661
|
|
|
445
|
-
| Detection
|
|
446
|
-
|
|
447
|
-
| `1`, `0.5`, `-3` (bare numbers)
|
|
448
|
-
| `10px`, `2rem`, `100vw` (length units) | `<length>`
|
|
449
|
-
| `50%`
|
|
450
|
-
| `45deg`, `0.5turn` (angle units)
|
|
451
|
-
| `300ms`, `1s` (time units)
|
|
452
|
-
| `#name` tokens (by naming convention)
|
|
662
|
+
| Detection | Inferred syntax |
|
|
663
|
+
| -------------------------------------- | --------------- |
|
|
664
|
+
| `1`, `0.5`, `-3` (bare numbers) | `<number>` |
|
|
665
|
+
| `10px`, `2rem`, `100vw` (length units) | `<length>` |
|
|
666
|
+
| `50%` | `<percentage>` |
|
|
667
|
+
| `45deg`, `0.5turn` (angle units) | `<angle>` |
|
|
668
|
+
| `300ms`, `1s` (time units) | `<time>` |
|
|
669
|
+
| `#name` tokens (by naming convention) | `<color>` |
|
|
453
670
|
|
|
454
671
|
Auto-inferred properties use `inherits: true` (the CSS default). Use explicit `@property` when you need different settings:
|
|
455
672
|
|
|
@@ -481,16 +698,22 @@ configure({ autoPropertyTypes: false });
|
|
|
481
698
|
|
|
482
699
|
Override or extend the built-in style property handlers. A handler definition can take three forms:
|
|
483
700
|
|
|
484
|
-
| Form
|
|
485
|
-
|
|
486
|
-
| Function only | `handler`
|
|
487
|
-
| Single dep
|
|
488
|
-
| Multi dep
|
|
701
|
+
| Form | Syntax | Description |
|
|
702
|
+
| ------------- | ---------------------------------- | --------------------------------------------------------------- |
|
|
703
|
+
| Function only | `handler` | Triggered by its key name; receives only that property |
|
|
704
|
+
| Single dep | `['styleName', handler]` | Triggered by the specified style property |
|
|
705
|
+
| Multi dep | `[['dep1', 'dep2', ...], handler]` | Triggered by any of the listed properties; receives all of them |
|
|
489
706
|
|
|
490
|
-
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`.
|
|
491
708
|
|
|
492
709
|
```jsx
|
|
493
|
-
import {
|
|
710
|
+
import {
|
|
711
|
+
configure,
|
|
712
|
+
defineHandler,
|
|
713
|
+
parseColor,
|
|
714
|
+
parseStyle,
|
|
715
|
+
styleHandlers,
|
|
716
|
+
} from '@tenphi/tasty';
|
|
494
717
|
|
|
495
718
|
configure({
|
|
496
719
|
handlers: {
|
|
@@ -507,23 +730,41 @@ configure({
|
|
|
507
730
|
// them all through, or the ones you leave out stop working (see below).
|
|
508
731
|
fill: defineHandler(
|
|
509
732
|
[
|
|
510
|
-
'fill',
|
|
511
|
-
'
|
|
733
|
+
'fill',
|
|
734
|
+
'backgroundColor',
|
|
735
|
+
'image',
|
|
736
|
+
'backgroundImage',
|
|
737
|
+
'backgroundPosition',
|
|
738
|
+
'backgroundSize',
|
|
739
|
+
'backgroundRepeat',
|
|
740
|
+
'backgroundAttachment',
|
|
741
|
+
'backgroundOrigin',
|
|
742
|
+
'backgroundClip',
|
|
743
|
+
'background',
|
|
512
744
|
],
|
|
513
745
|
(props) => {
|
|
514
|
-
if (
|
|
746
|
+
if (
|
|
747
|
+
typeof props.fill === 'string' &&
|
|
748
|
+
props.fill.startsWith('gradient:')
|
|
749
|
+
) {
|
|
515
750
|
return { background: props.fill.slice(9) };
|
|
516
751
|
}
|
|
517
752
|
return styleHandlers.fill(props);
|
|
518
753
|
},
|
|
519
754
|
),
|
|
520
755
|
|
|
521
|
-
// Multi dep —
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
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
|
+
),
|
|
527
768
|
},
|
|
528
769
|
});
|
|
529
770
|
```
|
|
@@ -534,6 +775,7 @@ A handler returns a `CSSMap`, an array of them, or nothing:
|
|
|
534
775
|
|
|
535
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.
|
|
536
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.
|
|
537
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.
|
|
538
780
|
- Return an array of maps to emit several declaration sets, each with its own `$`.
|
|
539
781
|
|
|
@@ -545,18 +787,23 @@ Built-in handlers are shared across several style names. Registering a handler f
|
|
|
545
787
|
|
|
546
788
|
The shared groups worth knowing:
|
|
547
789
|
|
|
548
|
-
| Registering a handler for | Also takes over
|
|
549
|
-
|
|
550
|
-
| `fill`
|
|
551
|
-
| `display`
|
|
552
|
-
| `
|
|
553
|
-
| `
|
|
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.
|
|
554
801
|
|
|
555
802
|
Either declare the whole group and delegate the rest to `styleHandlers.*`, or pick a name that isn't shared.
|
|
556
803
|
|
|
557
804
|
### Chunk membership
|
|
558
805
|
|
|
559
|
-
Tasty renders and caches CSS in independent chunks, and a chunk's cache key covers only its own style values. All of a handler's dependencies must therefore live in one chunk. Custom style names are pulled into their handler's chunk automatically at registration; a handler whose dependencies span two
|
|
806
|
+
Tasty renders and caches CSS in independent chunks, and a chunk's cache key covers only its own style values. All of a handler's dependencies must therefore live in one chunk. Custom style names are pulled into their handler's chunk automatically at registration; a handler whose dependencies span two _built-in_ chunks (say `fill` and `padding`) warns, because it would be invoked once per chunk with a subset of its inputs.
|
|
560
807
|
|
|
561
808
|
`configure({ handlers })` must run before the first render, like every other config option.
|
|
562
809
|
|
|
@@ -564,7 +811,7 @@ Tasty renders and caches CSS in independent chunks, and a chunk's cache key cove
|
|
|
564
811
|
|
|
565
812
|
## Props Middleware
|
|
566
813
|
|
|
567
|
-
`propHandlers` are middleware over a component's props — props in, props out. Where a style
|
|
814
|
+
`propHandlers` are middleware over a component's props — props in, props out. Where a style _handler_ turns a style property into CSS declarations, a prop handler turns a **component prop** into other props, including `styles`. It is the extension point for props whose value isn't a style value.
|
|
568
815
|
|
|
569
816
|
```jsx
|
|
570
817
|
import { configure, mergeStyles } from '@tenphi/tasty';
|
|
@@ -580,7 +827,7 @@ configure({
|
|
|
580
827
|
},
|
|
581
828
|
});
|
|
582
829
|
|
|
583
|
-
<Element glaze="purple"
|
|
830
|
+
<Element glaze="purple" />;
|
|
584
831
|
```
|
|
585
832
|
|
|
586
833
|
The map key is the handler's name and, by default, the prop that triggers it, so an absent prop costs one property check rather than a call. A tuple overrides that: `['glaze', fn]`, `[['glaze', 'tint'], fn]`, or `['*', fn]` for unconditional.
|
|
@@ -589,7 +836,7 @@ Handlers run at the very top of every component's render, before any prop is des
|
|
|
589
836
|
|
|
590
837
|
Handlers must be **pure** and must not mutate their input, and should memoize the styles they build per input value: style values are cached by object identity, so mutating one in place yields stale CSS, and a reference-stable object avoids re-serializing on every render.
|
|
591
838
|
|
|
592
|
-
Injected styles occupy the `styles` slot, so they beat a component's own default styles and lose to a style prop at the call site. Prop handlers do not apply to sub-elements or to
|
|
839
|
+
Injected styles occupy the `styles` slot, so they beat a component's own default styles and lose to a style prop at the call site. Prop handlers do not apply to sub-elements or to build-time `tastyStatic()`, which has no props.
|
|
593
840
|
|
|
594
841
|
See [Plugins → Props middleware](plugins.md#props-middleware) for the full contract and a worked example.
|
|
595
842
|
|
|
@@ -602,7 +849,7 @@ See [Plugins → Props middleware](plugins.md#props-middleware) for the full con
|
|
|
602
849
|
```jsx
|
|
603
850
|
configure({ baseStyleProps: ['radius', 'shadow'] });
|
|
604
851
|
|
|
605
|
-
<Card radius="1r" shadow
|
|
852
|
+
<Card radius="1r" shadow />;
|
|
606
853
|
```
|
|
607
854
|
|
|
608
855
|
`configure()` may run after your components are defined — each factory resolves its prop list lazily.
|
|
@@ -611,18 +858,98 @@ Each name costs one property check per render of every component, and the effect
|
|
|
611
858
|
|
|
612
859
|
---
|
|
613
860
|
|
|
614
|
-
##
|
|
861
|
+
## TypeScript
|
|
615
862
|
|
|
616
|
-
|
|
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';
|
|
617
887
|
|
|
618
|
-
```tsx
|
|
619
|
-
// tasty.d.ts
|
|
620
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
|
+
}
|
|
621
902
|
interface StylesInterface {
|
|
622
|
-
|
|
623
|
-
|
|
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;
|
|
624
911
|
}
|
|
625
912
|
}
|
|
626
913
|
```
|
|
627
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
|
+
|
|
628
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.
|