@tenphi/tasty 2.11.1 → 3.0.0

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.
Files changed (76) hide show
  1. package/README.md +32 -7
  2. package/dist/astro-B53trJyX.js +156 -0
  3. package/dist/astro-B53trJyX.js.map +1 -0
  4. package/dist/babel-HlEpSZrj.d.ts +83 -0
  5. package/dist/{collector-DYA5AOwr.d.ts → collector-BPzZezAG.d.ts} +44 -7
  6. package/dist/{collector-AHZaBSv8.js → collector-D14DcZx9.js} +75 -14
  7. package/dist/collector-D14DcZx9.js.map +1 -0
  8. package/dist/{config-YDAcLaVf.js → config-CCcE_tqx.js} +2312 -1131
  9. package/dist/config-CCcE_tqx.js.map +1 -0
  10. package/dist/{config-BtK9fUaz.d.ts → config-D2INrjr_.d.ts} +252 -25
  11. package/dist/core/index.d.ts +5 -5
  12. package/dist/core/index.js +6 -6
  13. package/dist/{core-CS4bzqGu.js → core-B5d0IPi2.js} +85 -133
  14. package/dist/core-B5d0IPi2.js.map +1 -0
  15. package/dist/{css-writer-BXSANVrq.js → css-writer-B5DBoxhf.js} +54 -15
  16. package/dist/css-writer-B5DBoxhf.js.map +1 -0
  17. package/dist/{format-rules-CYriCDwq.js → format-rules-BbKDjsfO.js} +2 -2
  18. package/dist/{format-rules-CYriCDwq.js.map → format-rules-BbKDjsfO.js.map} +1 -1
  19. package/dist/{hydrate-GVTorHpU.js → hydrate-CwALW3J9.js} +3 -11
  20. package/dist/{hydrate-GVTorHpU.js.map → hydrate-CwALW3J9.js.map} +1 -1
  21. package/dist/{index-BYtnj_gA.d.ts → index-BAAbdfRs.d.ts} +228 -153
  22. package/dist/{index-B9ih23uv.d.ts → index-l_NdJSUS.d.ts} +172 -61
  23. package/dist/index.d.ts +5 -5
  24. package/dist/index.js +191 -56
  25. package/dist/index.js.map +1 -1
  26. package/dist/{keyframes-CtcSlw4k.js → keyframes-B8M1FmtE.js} +10 -181
  27. package/dist/keyframes-B8M1FmtE.js.map +1 -0
  28. package/dist/{merge-styles-D4ITH4bc.js → merge-styles--1zOSFlS.js} +2 -2
  29. package/dist/{merge-styles-D4ITH4bc.js.map → merge-styles--1zOSFlS.js.map} +1 -1
  30. package/dist/{merge-styles-BZV-XAwX.d.ts → merge-styles-NEvqayL_.d.ts} +2 -2
  31. package/dist/{resolve-recipes-llr0COs8.js → resolve-recipes-Caix5NnH.js} +3 -3
  32. package/dist/{resolve-recipes-llr0COs8.js.map → resolve-recipes-Caix5NnH.js.map} +1 -1
  33. package/dist/ssr/astro-client.js +1 -1
  34. package/dist/ssr/astro-middleware.js +1 -1
  35. package/dist/ssr/astro-middleware.js.map +1 -1
  36. package/dist/ssr/astro.d.ts +1 -5
  37. package/dist/ssr/astro.js +2 -147
  38. package/dist/ssr/index.d.ts +2 -9
  39. package/dist/ssr/index.js +4 -4
  40. package/dist/ssr/index.js.map +1 -1
  41. package/dist/ssr/next.d.ts +1 -1
  42. package/dist/ssr/next.js +5 -6
  43. package/dist/ssr/next.js.map +1 -1
  44. package/dist/static/index.d.ts +2 -2
  45. package/dist/static/index.js +1 -1
  46. package/dist/zero/babel.d.ts +2 -80
  47. package/dist/zero/babel.js +27 -23
  48. package/dist/zero/babel.js.map +1 -1
  49. package/dist/zero/index.d.ts +16 -2
  50. package/dist/zero/index.js +2 -2
  51. package/dist/zero/next.d.ts +1 -1
  52. package/dist/zero/next.js +1 -1
  53. package/dist/zero/next.js.map +1 -1
  54. package/docs/README.md +3 -1
  55. package/docs/ai-agents.md +21 -7
  56. package/docs/configuration.md +220 -30
  57. package/docs/debug.md +7 -7
  58. package/docs/design-system.md +2 -2
  59. package/docs/dsl.md +68 -8
  60. package/docs/injector.md +46 -4
  61. package/docs/methodology.md +1 -1
  62. package/docs/migration-v3.md +285 -0
  63. package/docs/pipeline.md +3 -3
  64. package/docs/plugins.md +349 -0
  65. package/docs/react-api.md +82 -3
  66. package/docs/ssr.md +40 -33
  67. package/docs/styles.md +27 -9
  68. package/docs/tasty-static.md +8 -6
  69. package/package.json +7 -7
  70. package/tasty.config.ts +4 -0
  71. package/dist/collector-AHZaBSv8.js.map +0 -1
  72. package/dist/config-YDAcLaVf.js.map +0 -1
  73. package/dist/core-CS4bzqGu.js.map +0 -1
  74. package/dist/css-writer-BXSANVrq.js.map +0 -1
  75. package/dist/keyframes-CtcSlw4k.js.map +0 -1
  76. package/dist/ssr/astro.js.map +0 -1
@@ -0,0 +1,349 @@
1
+ # Plugins & Extension Points
2
+
3
+ How to extend Tasty: new value syntax, new units, new states, new style properties, new component props, and how to package any of it as a plugin.
4
+
5
+ - [What a plugin is](#what-a-plugin-is)
6
+ - [Choosing an extension point](#choosing-an-extension-point)
7
+ - [Custom style handlers](#custom-style-handlers)
8
+ - [Props middleware](#props-middleware)
9
+ - [Base style props](#base-style-props)
10
+ - [Typing your extension](#typing-your-extension)
11
+ - [Worked example: a `glaze` plugin](#worked-example-a-glaze-plugin)
12
+ - [Rendering modes and caveats](#rendering-modes-and-caveats)
13
+ - [Testing a plugin](#testing-a-plugin)
14
+
15
+ ---
16
+
17
+ ## What a plugin is
18
+
19
+ A plugin is a plain object with a `name` and any subset of the `configure()` options it is allowed to supply. There is no lifecycle and no init hook — a plugin is just pre-packaged configuration.
20
+
21
+ ```ts
22
+ import { configure } from '@tenphi/tasty';
23
+ import type { TastyPluginFactory } from '@tenphi/tasty';
24
+
25
+ const spacingPlugin: TastyPluginFactory = () => ({
26
+ name: 'spacing',
27
+ units: { gu: (n) => `calc(${n} * var(--grid-unit))` },
28
+ tokens: { '$grid-unit': '4px' },
29
+ });
30
+
31
+ configure({ plugins: [spacingPlugin()] });
32
+ ```
33
+
34
+ `TastyPluginFactory<TOptions>` types a factory that takes options; with no type argument it types a zero-argument factory.
35
+
36
+ **Ordering.** Plugins are applied in array order and merged key by key, so a later plugin overrides an earlier one for the same key. Options passed directly to `configure()` are applied last and win over every plugin.
37
+
38
+ **Configuration is locked after the first render.** `configure()` warns and does nothing once any style has been generated, so it must run before your first component renders — at module scope in your entry file, or in a design-system module every component imports. `resetConfig()` reopens it, but it exists for tests.
39
+
40
+ **Repeated `configure()` calls merge** for `tokens` and `globalStyles` (per selector). See [Configuration](configuration.md) for the current per-key semantics.
41
+
42
+ ---
43
+
44
+ ## Choosing an extension point
45
+
46
+ | You want to add | Use | Runs | Zero-runtime |
47
+ |---|---|---|---|
48
+ | New value syntax — `okhsl(…)`, `double(2x)` | `functions` (bare key) | parse time, per value | ✅ |
49
+ | A reusable CSS `@function` | `functions` (`$$name` key) | injected once, globally | ✅ |
50
+ | A new unit — `2gu` | `units` | parse time, per value | ✅ |
51
+ | A new state alias — `@mobile` | `states` | state-key parse | ✅ |
52
+ | A style property → **CSS declarations** | `handlers` | pipeline, per state snapshot | ✅ |
53
+ | A style property on every component | `baseStyleProps` | prop harvest | ✅ (styles only) |
54
+ | A **component prop** → anything | `propHandlers` | render, per component | ❌ (no props to run on) |
55
+ | A named bundle of styles | `recipes` | before chunking | ✅ |
56
+ | Typography scale tokens | `presets` | inject time | ✅ |
57
+ | `:root` variables | `tokens`, `replaceTokens` | inject time | ✅ |
58
+ | Global selector styles | `globalStyles` | inject time | ✅ |
59
+
60
+ Two distinctions do most of the work:
61
+
62
+ - **`handlers` vs `propHandlers`.** A handler turns a *style property* into CSS declarations and knows nothing about components. A prop handler turns a *component prop* into other props — including `styles`, which then flow through the normal handlers. Reach for `propHandlers` when the input isn't a style value (an options object, a domain concept) or when it should affect more than styles.
63
+ - **`recipes` vs `propHandlers`.** A recipe is a static named bundle. A prop handler computes its styles from a value.
64
+
65
+ ---
66
+
67
+ ## Custom style handlers
68
+
69
+ A handler receives a map of the style properties it declared and returns CSS declarations. See [Configuration → Custom Style Handlers](configuration.md#custom-style-handlers) for the definition forms, return shape, the shared-handler groups you must be careful of, and chunk membership. The essentials:
70
+
71
+ - Values arrive **state-resolved but unparsed** — the raw authored DSL string (`'2x'`, `'#purple.5'`, `true`, `4`). Call the exported `parseStyle()` / `parseColor()` yourself.
72
+ - Return a `CSSMap` with **kebab-case** keys, an array of them, or nothing. `$` is a selector suffix, not a property.
73
+ - Handlers must be pure and synchronous. They are called once per state combination and the results are cached.
74
+ - Use `defineHandler(deps, fn)` for multi-dependency handlers so the dependency types are inferred.
75
+
76
+ ```ts
77
+ import { configure, defineHandler, parseStyle } from '@tenphi/tasty';
78
+
79
+ configure({
80
+ handlers: {
81
+ // Every declaration set the handler returns can target its own selector.
82
+ stripe: defineHandler(['stripe'], ({ stripe }) => {
83
+ if (!stripe) return;
84
+
85
+ const { values } = parseStyle(String(stripe)).groups[0];
86
+
87
+ return [
88
+ { position: 'relative' },
89
+ {
90
+ $: '&::before',
91
+ content: '""',
92
+ position: 'absolute',
93
+ inset: '0 auto 0 0',
94
+ width: values[0],
95
+ background: 'var(--purple-color)',
96
+ },
97
+ ];
98
+ }),
99
+ },
100
+ });
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Props middleware
106
+
107
+ `propHandlers` are middleware over a component's props: props in, props out. They run at the very top of every tasty component's render, before any prop is destructured, so a handler can read and rewrite `styles`, `mods`, `tokens`, `variant`, `as`, `element`, and `qa`, and can strip its own props so they never reach the DOM.
108
+
109
+ ```ts
110
+ import { configure, mergeStyles } from '@tenphi/tasty';
111
+
112
+ configure({
113
+ propHandlers: {
114
+ glaze: (props) => {
115
+ const { glaze, ...rest } = props;
116
+ if (!glaze) return rest;
117
+
118
+ return { ...rest, styles: mergeStyles(glazeStyles(glaze), rest.styles) };
119
+ },
120
+ },
121
+ });
122
+ ```
123
+
124
+ **The key is the trigger.** By default a handler runs only when a prop matching its key is present, so an absent prop costs one property check rather than a call. Override that with a tuple:
125
+
126
+ | Definition | Runs when |
127
+ |---|---|
128
+ | `fn` | a prop named after the key is present |
129
+ | `['glaze', fn]` | `glaze` is present |
130
+ | `[['glaze', 'tint'], fn]` | either is present |
131
+ | `['*', fn]` | always |
132
+
133
+ **Chaining.** Handlers run in registration order — plugins first, then direct `configure()` — and each receives the previous one's output. Registering the same key twice replaces the handler in place, keeping its position.
134
+
135
+ **Returning nothing means unchanged**, with a development-mode warning, because that is almost always a forgotten `return props`. A non-object return is ignored with a warning.
136
+
137
+ ### Rules
138
+
139
+ - **Be pure. Never mutate the input.** Style values are cached by object identity, so mutating a value object in place yields a stale class name *and* stale CSS. Return fresh objects.
140
+ - **Memoize the styles you build, per input value.** A reference-stable (ideally frozen) styles object lets the cache key reuse its serialization instead of recomputing it on every render. This is the single highest-leverage thing you can do for performance.
141
+ - **Precedence is fixed** and not adjustable from a handler. Styles are merged as `factory defaults → styles → harvested style props`, and injected styles occupy the `styles` slot: they beat a component's own default styles and lose to a style prop passed at the call site. This matches how `recipe` already behaves.
142
+ - **Prefer returning `styles` over bare style props.** Returning `{ fill: '#red' }` only works if `fill` is harvestable on *that* component (in its `styleProps`, or promoted via `baseStyleProps`); otherwise it leaks to the DOM.
143
+
144
+ ### What it cannot do
145
+
146
+ - **`ref`** — `forwardRef` separates it from props, so it is out of reach.
147
+ - **Sub-elements** (`Card.Title`) — they have no `styles` prop and no style-prop harvest, so middleware does not run on them.
148
+ - **Zero-runtime mode** — see [Rendering modes](#rendering-modes-and-caveats).
149
+
150
+ ---
151
+
152
+ ## Base style props
153
+
154
+ A small set of style properties — `display`, `font`, `preset`, `hide`, `whiteSpace`, `opacity`, `transition` — are harvested as props on every `tasty()` component. `baseStyleProps` adds to that set globally:
155
+
156
+ ```ts
157
+ configure({ baseStyleProps: ['radius', 'shadow'] });
158
+
159
+ <Card radius="1r" shadow />
160
+ ```
161
+
162
+ Names must be real style properties, must start with a lowercase letter, and must not collide with a prop `tasty()` consumes itself (`as`, `styles`, `variant`, `mods`, `tokens`, …); invalid entries are dropped with a development warning.
163
+
164
+ `configure()` may run *after* your components are defined — each factory resolves its prop list lazily and refreshes when the registry changes.
165
+
166
+ **Costs and caveats.** Each name adds one property check per render of every component, forever, so keep the list short. The effect is app-global and cannot be scoped to a subtree — use a factory's own `styleProps` for that. Be wary of names that collide with real DOM or component props (`width`, `size`, `color`): promoting one means every component swallows it as a style, including when rendering `as={SomeThirdPartyComponent}`.
167
+
168
+ ---
169
+
170
+ ## Typing your extension
171
+
172
+ Four augmentation points, each matching a runtime registry:
173
+
174
+ ```ts
175
+ // tasty.d.ts
176
+ import type { StylePropValue } from '@tenphi/tasty';
177
+
178
+ declare module '@tenphi/tasty' {
179
+ // configure({ handlers }) — a new style property
180
+ interface StylesInterface {
181
+ stripe?: StylePropValue<string>;
182
+ }
183
+
184
+ // configure({ propHandlers }) — a new component prop
185
+ interface TastyCustomProps {
186
+ glaze: 'soft' | 'strong' | { tone: string; intensity?: number };
187
+ }
188
+
189
+ // configure({ baseStyleProps }) — promoted style names, typed like the style
190
+ interface TastyBaseStylePropNames {
191
+ radius: true;
192
+ shadow: true;
193
+ }
194
+
195
+ // configure({ tokens }) / recipes / presets — autocomplete for names
196
+ interface TastyNamedColors {
197
+ 'glaze-bg': true;
198
+ }
199
+ }
200
+ ```
201
+
202
+ `TastyCustomProps` keys become optional props on every component. `TastyBaseStylePropNames` entries are typed exactly like the style they name, so `radius="1r"` accepts the same values as `styles={{ radius: '1r' }}`.
203
+
204
+ **Also update `tasty.config.ts`.** The ESLint plugin and VS Code extension validate style and token names against it, and neither is derived from the runtime registries:
205
+
206
+ ```ts
207
+ // tasty.config.ts
208
+ export default {
209
+ styles: ['stripe'],
210
+ tokens: ['#glaze-bg'],
211
+ };
212
+ ```
213
+
214
+ `propHandlers` keys are JSX props rather than style keys, so they need no entry — but any *style* name or token a handler expands into does.
215
+
216
+ ---
217
+
218
+ ## Worked example: a `glaze` plugin
219
+
220
+ A `glaze` prop on every component that takes a configuration object and expands into color token declarations. This is the case `propHandlers` exists for: the value is an options object, not a style value, so it cannot be a style property.
221
+
222
+ ```ts
223
+ // glaze-plugin.ts
224
+ import { mergeStyles } from '@tenphi/tasty';
225
+ import type { Styles, TastyPluginFactory } from '@tenphi/tasty';
226
+
227
+ export interface GlazeConfig {
228
+ tone: string;
229
+ /** 0–100. Default 10. */
230
+ intensity?: number;
231
+ }
232
+
233
+ type GlazeValue = string | GlazeConfig;
234
+
235
+ // Memoized per value so the styles object is reference-stable across renders.
236
+ const cache = new Map<string, Styles>();
237
+
238
+ function glazeStyles(value: GlazeValue): Styles {
239
+ const { tone, intensity = 10 } =
240
+ typeof value === 'string' ? { tone: value } : value;
241
+ const key = `${tone}:${intensity}`;
242
+
243
+ let styles = cache.get(key);
244
+
245
+ if (!styles) {
246
+ styles = Object.freeze({
247
+ '#glaze-bg': `#${tone}.${intensity}`,
248
+ fill: '#glaze-bg',
249
+ transition: 'fill 0.2s',
250
+ }) as Styles;
251
+ cache.set(key, styles);
252
+ }
253
+
254
+ return styles;
255
+ }
256
+
257
+ export const glazePlugin: TastyPluginFactory = () => ({
258
+ name: 'glaze',
259
+
260
+ propHandlers: {
261
+ glaze: (props) => {
262
+ const { glaze, ...rest } = props;
263
+ if (!glaze) return rest;
264
+
265
+ return {
266
+ ...rest,
267
+ styles: mergeStyles(
268
+ glazeStyles(glaze as GlazeValue),
269
+ rest.styles as Styles,
270
+ ),
271
+ };
272
+ },
273
+ },
274
+
275
+ // Typed so `#glaze-bg` animates smoothly instead of snapping.
276
+ properties: {
277
+ '#glaze-bg': { syntax: '<color>', inherits: false, initialValue: 'transparent' },
278
+ },
279
+ });
280
+ ```
281
+
282
+ ```ts
283
+ // app entry, before the first render
284
+ import { configure } from '@tenphi/tasty';
285
+
286
+ import { glazePlugin } from './glaze-plugin';
287
+
288
+ configure({ plugins: [glazePlugin()] });
289
+ ```
290
+
291
+ ```tsx
292
+ <Element glaze="purple" />
293
+ <Element glaze={{ tone: 'success', intensity: 30 }} />
294
+ ```
295
+
296
+ ```ts
297
+ // tasty.d.ts
298
+ declare module '@tenphi/tasty' {
299
+ interface TastyCustomProps {
300
+ glaze: import('./glaze-plugin').GlazeConfig | string;
301
+ }
302
+ }
303
+ ```
304
+
305
+ The object value is unambiguous here precisely because `glaze` is a **prop**. A style *value* of the same shape would be indistinguishable from a state map (`{ tone: … }` looks exactly like `{ hovered: … }`), which is why this belongs in `propHandlers` rather than `handlers`.
306
+
307
+ ---
308
+
309
+ ## Rendering modes and caveats
310
+
311
+ | Mode | `functions` / `units` / `states` / `handlers` / `recipes` / `tokens` | `propHandlers` |
312
+ |---|---|---|
313
+ | Client | ✅ | ✅ |
314
+ | SSR / RSC | ✅ | ✅ |
315
+ | Zero-runtime (`tastyStatic`) | ✅ at build time | not applicable |
316
+
317
+ **Zero-runtime.** The Babel plugin transforms `tastyStatic()` calls, which take styles objects — there are no props in that pipeline, so there is nothing for props middleware to run on. Components you render through `tasty()` are untouched by the plugin and keep the runtime injector, so `propHandlers` work there exactly as in any client app; their CSS simply comes from the injector rather than the extracted stylesheet. Everything else runs at build time, which is why handlers, functions, and units must be pure functions of their input.
318
+
319
+ **Server and client must configure identically.** Class names are derived from resolved styles, so a handler or promoted prop registered on one side and not the other produces a hydration mismatch. This is the same requirement as `namePrefix` — see [SSR → Hydration mismatch warnings](ssr.md#hydration-mismatch-warnings).
320
+
321
+ ---
322
+
323
+ ## Testing a plugin
324
+
325
+ ```ts
326
+ import { configure, resetConfig, renderStyles } from '@tenphi/tasty';
327
+
328
+ describe('glaze plugin', () => {
329
+ beforeEach(() => resetConfig());
330
+ afterEach(() => resetConfig());
331
+
332
+ it('expands into a color token declaration', () => {
333
+ configure({ plugins: [glazePlugin()] });
334
+
335
+ const rules = renderStyles({ '#glaze-bg': '#purple.10' }, '.test');
336
+
337
+ expect(rules[0].declarations).toContain('--glaze-bg-color');
338
+ });
339
+ });
340
+ ```
341
+
342
+ Two things to know:
343
+
344
+ - **Create components inside each test.** `resetConfig()` does not clear the per-factory class-name cache or prop-list memo, so a module-scope component created in one test carries state into the next.
345
+ - **Dev-mode warnings may not fire.** `isDevEnv()` reports `false` for `NODE_ENV=test`. Warnings that check it lazily can be enabled with `vi.stubEnv('NODE_ENV', 'development')`; some older ones capture it at module load and cannot be triggered from a test at all.
346
+
347
+ ---
348
+
349
+ See [Configuration](configuration.md) for every option in detail, [Style DSL](dsl.md) for the value syntax your extensions produce, and [React API](react-api.md) for `tasty()`, `styleProps`, `modProps`, and `tokenProps`.
package/docs/react-api.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # React API
2
2
 
3
- The React-specific `tasty()` component factory, component props, and style functions. All Tasty style functions — `tasty()` components, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, and `useCounterStyle()` — are hook-free and compatible with React Server Components. No `'use client'` directive needed. For the shared style language (state maps, tokens, units, extending semantics), see [Style DSL](dsl.md). For global configuration, see [Configuration](configuration.md). For the broader docs map, see the [Docs Hub](README.md).
3
+ The React-specific `tasty()` component factory, component props, and style functions. All Tasty style functions — `tasty()` components, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, `useCounterStyle()`, and `useFunction()` — are hook-free and compatible with React Server Components. No `'use client'` directive needed. For the shared style language (state maps, tokens, units, extending semantics), see [Style DSL](dsl.md). For global configuration, see [Configuration](configuration.md). For the broader docs map, see the [Docs Hub](README.md).
4
4
 
5
5
  > **Note:** This file was previously named `runtime.md`. All functionality documented here works in both server and client contexts — "runtime" referred to style computation during React rendering, not to client-side JavaScript.
6
6
 
@@ -98,6 +98,26 @@ Style props accept state maps, so responsive values work through the same API:
98
98
 
99
99
  For predefined style prop lists (`FLOW_STYLES`, `POSITION_STYLES`, `DIMENSION_STYLES`, etc.) and guidance on which props to expose per component category, see [Methodology — styleProps as the public API](methodology.md#styleprops-as-the-public-api).
100
100
 
101
+ ### Always-available style props
102
+
103
+ A small set of style properties — `display`, `font`, `preset`, `hide`, `whiteSpace`, `opacity`, and `transition` — are always harvested as style props on every `tasty()` component, even when `styleProps` is omitted. This means you can pass `<Card display="grid" />` or `<Text preset="h1" />` without declaring them. When you do declare `styleProps`, these base props are unioned with your list (not replaced).
104
+
105
+ ---
106
+
107
+ ## `Element`
108
+
109
+ `Element` is the unstyled base component exported from the main entry — equivalent to `tasty({})` (a `div` with no default styles). It accepts all Tasty props (`styles`, `styleProps`, `mods`, `tokens`, `as`, `qa`, `theme`, the `is*` props, etc.) and is useful as a generic styled box or as a building block for layout primitives.
110
+
111
+ ```jsx
112
+ import { Element } from '@tenphi/tasty';
113
+
114
+ <Element as="section" padding="4x" fill="#surface">
115
+ Content
116
+ </Element>
117
+ ```
118
+
119
+ > Note: `Element` shadows the global DOM `Element` type when imported from `@tenphi/tasty`. In files that need the DOM type, alias the import: `import { Element as TastyElement } from '@tenphi/tasty'`.
120
+
101
121
  ---
102
122
 
103
123
  ## Mod Props
@@ -419,6 +439,15 @@ function ThemeStyles() {
419
439
  }
420
440
  ```
421
441
 
442
+ A slot — the `id`, or the selector when no `id` is given — holds exactly one
443
+ injection **per `root`**. So:
444
+
445
+ - Changing the styles replaces the previous CSS rather than adding to it.
446
+ - Passing styles that produce no CSS (for example `{}`) clears the slot.
447
+ - The same selector used in two shadow roots keeps a separate injection in each.
448
+ - Two independent call sites that share a selector share a slot, and the last
449
+ render wins. Give them distinct `id`s if they should coexist.
450
+
422
451
  ### useRawCSS
423
452
 
424
453
  Inject raw CSS strings. Accepts an optional `id` in the options for update tracking — when the CSS changes for the same id, the previous injection is replaced:
@@ -435,6 +464,9 @@ function GlobalReset() {
435
464
  }
436
465
  ```
437
466
 
467
+ An `id` slot holds one injection per `root`. Without an `id` the CSS is deduped
468
+ by content and permanent — there is nothing to replace it with later.
469
+
438
470
  ### useKeyframes
439
471
 
440
472
  Inject `@keyframes` rules and return the generated animation name:
@@ -455,7 +487,7 @@ function Spinner() {
455
487
  }
456
488
  ```
457
489
 
458
- `useKeyframes()` also supports a factory function. The deps array is accepted for backward compatibility but the factory is called on every invocation deduplication is handled internally by content hash:
490
+ `useKeyframes()` also supports a factory function. Without a `name` the factory runs on every invocation and deduplication is handled internally by content hash; with a `name`, matching deps skip the factory entirely:
459
491
 
460
492
  ```tsx
461
493
  function Pulse({ scale }: { scale: number }) {
@@ -464,13 +496,20 @@ function Pulse({ scale }: { scale: number }) {
464
496
  '0%': { transform: 'scale(1)' },
465
497
  '100%': { transform: `scale(${scale})` },
466
498
  }),
467
- [scale]
499
+ [scale],
500
+ { name: 'pulse' }
468
501
  );
469
502
 
470
503
  return <div style={{ animation: `${pulse} 500ms ease-in-out alternate infinite` }} />;
471
504
  }
472
505
  ```
473
506
 
507
+ Passing `name` claims a slot owned by that one call site, per `root` — much like
508
+ `id` in `useGlobalStyles()` and `useRawCSS()`. When the steps change the previous
509
+ `@keyframes` rule is disposed and the name is reused, so the rules don't
510
+ accumulate and the returned name stays stable. Anonymous keyframes are permanent
511
+ and shared by content.
512
+
474
513
  ### useProperty
475
514
 
476
515
  Register a CSS `@property` rule so a custom property can animate smoothly:
@@ -560,6 +599,46 @@ function useCounterStyle(
560
599
  ): string;
561
600
  ```
562
601
 
602
+ ### useFunction
603
+
604
+ Register a CSS `@function` (custom function). Permanent — no cleanup on unmount. Deduplicates by function name. The function name accepts `$$name` (matching the call site `$$name(...)`), `$name`, or `--name`.
605
+
606
+ ```tsx
607
+ import { tasty, useFunction } from '@tenphi/tasty';
608
+
609
+ const Box = tasty({ styles: { marginTop: '$$negative(10px)' } });
610
+
611
+ function Layout() {
612
+ useFunction('$$negative', { args: ['$value'], result: '(-1 * $value)' });
613
+ return <Box />;
614
+ }
615
+ ```
616
+
617
+ Call the function through the Tasty DSL rather than a raw `style` prop. An inline `style` value reaches the browser unparsed, so the `$$name(...)` sugar is never expanded — and under `configure({ polyfills: { functions: true } })` it silently does nothing, because the polyfill rewrites calls at parse time.
618
+
619
+ Inside a `tasty()` component you call functions with the same `$$name(...)` sugar:
620
+
621
+ ```tsx
622
+ const Box = tasty({
623
+ styles: {
624
+ '@function': { '$$negative': { args: ['$value'], result: '(-1 * $value)' } },
625
+ marginTop: '$$negative(10px)',
626
+ },
627
+ });
628
+ ```
629
+
630
+ Signature:
631
+
632
+ ```ts
633
+ function useFunction(
634
+ name: string,
635
+ definition: FunctionDefinition,
636
+ options?: { root?: Document | ShadowRoot },
637
+ ): void;
638
+ ```
639
+
640
+ See the [Functions section of the DSL reference](dsl.md#functions-function) for the full descriptor shape, token conventions, and value-sugar support. `@function` is an experimental CSS feature — unsupported browsers safely ignore the native rule, or enable the [`polyfills.functions`](configuration.md#polyfills) inline polyfill for full cross-browser support.
641
+
563
642
  ### Troubleshooting
564
643
 
565
644
  - Styles are not updating: make sure `configure()` runs before first render, and verify the generated class name or global rule with [Debug Utilities](debug.md).