@tenphi/tasty 0.0.0-snapshot.da430e1 → 0.0.0-snapshot.db2ef70
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-Dc5zghyE.d.ts +18 -0
- package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
- package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
- package/dist/chunks/build-config-D9Iq8QQm.js +60 -0
- package/dist/chunks/build-config-D9Iq8QQm.js.map +1 -0
- package/dist/{collector-BevHh16N.js → chunks/collector-Cb8ah2JF.js} +10 -127
- package/dist/chunks/collector-Cb8ah2JF.js.map +1 -0
- package/dist/chunks/config-engine-CMYFZYQh.js +272 -0
- package/dist/chunks/config-engine-CMYFZYQh.js.map +1 -0
- package/dist/chunks/config-file-DlZXJMj8.js +25 -0
- package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
- package/dist/chunks/css-definitions-B4aWBkH3.js +910 -0
- package/dist/chunks/css-definitions-B4aWBkH3.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-D2Pu7Xhy.js +502 -0
- package/dist/chunks/debug-D2Pu7Xhy.js.map +1 -0
- package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
- package/dist/chunks/dsl-CsFl9LGn.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-DHiopXCu.js +691 -0
- package/dist/chunks/react-runtime-DHiopXCu.js.map +1 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js +2435 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js.map +1 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js +152 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js.map +1 -0
- package/dist/{merge-styles-BKfagXfV.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-DnkV_4Jg.js +5602 -0
- package/dist/chunks/style-engine-DnkV_4Jg.js.map +1 -0
- package/dist/{css-writer-BDPmetHV.js → chunks/zero-engine-DcwaCvFs.js} +65 -145
- package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
- package/dist/{collector-CLVr5_p3.d.ts → collector-D2OT6I2G.d.ts} +6 -5
- package/dist/{config-YsxGv4tq.d.ts → config-C4ftFxgI.d.ts} +181 -77
- 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-CBK778ne.d.ts → index-DxQNRj50.d.ts} +308 -255
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -922
- package/dist/{merge-styles-CU7JbEwg.d.ts → merge-styles-D39qBtox.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 +17 -17
- 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 +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-Cd45t5NM.d.ts → types-CYQIhUg1.d.ts} +868 -820
- package/dist/zero/babel.d.ts +73 -2
- package/dist/zero/babel.js +81 -144
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +63 -8
- package/dist/zero/index.js +25 -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 +68 -33
- package/docs/comparison.md +9 -8
- package/docs/configuration.md +204 -70
- package/docs/debug.md +21 -8
- package/docs/design-system.md +117 -15
- package/docs/dsl.md +307 -117
- package/docs/getting-started.md +81 -22
- package/docs/injector.md +105 -67
- 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 +76 -11
- package/docs/runtime-benchmarks.md +282 -110
- package/docs/ssr.md +226 -80
- package/docs/styles.md +169 -33
- package/docs/tasty-static.md +176 -58
- package/package.json +108 -44
- package/tasty.config.ts +1 -0
- package/dist/astro-C_by9qPq.js +0 -307
- package/dist/astro-C_by9qPq.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-BUQGeOXA.d.ts +0 -83
- package/dist/collector-BevHh16N.js.map +0 -1
- package/dist/config-NcdqU9PC.js +0 -12269
- package/dist/config-NcdqU9PC.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-D7s7u-k1.js +0 -1566
- package/dist/core-D7s7u-k1.js.map +0 -1
- package/dist/css-writer-BDPmetHV.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-BQCn7JZH.js +0 -130
- package/dist/format-rules-BQCn7JZH.js.map +0 -1
- package/dist/hydrate-C3cfqlaQ.js +0 -37
- package/dist/hydrate-C3cfqlaQ.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-ByhOtsXB.js +0 -493
- package/dist/keyframes-ByhOtsXB.js.map +0 -1
- package/dist/merge-styles-BKfagXfV.js.map +0 -1
- package/dist/resolve-recipes-vvygrWLw.js +0 -144
- package/dist/resolve-recipes-vvygrWLw.js.map +0 -1
package/docs/methodology.md
CHANGED
|
@@ -119,16 +119,17 @@ Style props accept state maps, so responsive values work through the same API:
|
|
|
119
119
|
|
|
120
120
|
Tasty exports predefined style prop lists that group properties by role. Use them instead of hand-picking arrays:
|
|
121
121
|
|
|
122
|
-
| Preset | Properties
|
|
123
|
-
| ------------------ |
|
|
124
|
-
| `FLOW_STYLES` | flow, gap, columnGap, rowGap, align, justify, placeItems, placeContent, alignItems, alignContent, justifyItems, justifyContent, gridColumns, gridRows, gridTemplate, gridAreas | Layout containers (`Space`, `Grid`) |
|
|
125
|
-
| `POSITION_STYLES` | gridArea, gridColumn, gridRow, order, placeSelf, alignSelf, justifySelf, zIndex, margin, inset, position
|
|
126
|
-
| `DIMENSION_STYLES` | width, height, flexBasis, flexGrow, flexShrink, flex
|
|
127
|
-
| `COLOR_STYLES` | color, fill, fade, image
|
|
128
|
-
| `BLOCK_STYLES` | padding,
|
|
129
|
-
| `
|
|
130
|
-
| `
|
|
131
|
-
| `
|
|
122
|
+
| Preset | Properties | Typical use |
|
|
123
|
+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
|
|
124
|
+
| `FLOW_STYLES` | flow, gap, columnGap, rowGap, align, justify, place, placeItems, placeContent, alignItems, alignContent, justifyItems, justifyContent, gridColumns, gridRows, gridTemplate, gridAreas | Layout containers (`Space`, `Grid`) |
|
|
125
|
+
| `POSITION_STYLES` | gridArea, gridColumn, gridRow, order, placeSelf, alignSelf, justifySelf, zIndex, physical/logical margin, inset, scroll margin/padding, position | Positioned elements (`Button`, `Badge`) |
|
|
126
|
+
| `DIMENSION_STYLES` | width, height, blockSize, inlineSize, flexBasis, flexGrow, flexShrink, flex | Sized elements |
|
|
127
|
+
| `COLOR_STYLES` | color, fill, fade, image | Color-customizable elements |
|
|
128
|
+
| `BLOCK_STYLES` | padding, blockPadding, inlinePadding, overflow, scrollbar, textAlign, border, blockBorder, inlineBorder, radius, shadow, outline | Block-level containers |
|
|
129
|
+
| `TEXT_STYLES` | textTransform, fontWeight, fontStyle | Text elements |
|
|
130
|
+
| `CONTAINER_STYLES` | All of the above combined (+ BASE_STYLES) | Fully flexible containers |
|
|
131
|
+
| `OUTER_STYLES` | POSITION_STYLES + DIMENSION_STYLES + block outer (border, radius, shadow, outline) | Components whose outer shell is customizable |
|
|
132
|
+
| `INNER_STYLES` | BASE_STYLES + COLOR_STYLES + block inner (padding, overflow, scrollbar) + FLOW_STYLES | Components whose inner layout is customizable |
|
|
132
133
|
|
|
133
134
|
```tsx
|
|
134
135
|
import { tasty, FLOW_STYLES, POSITION_STYLES } from '@tenphi/tasty';
|
|
@@ -156,7 +157,10 @@ Match the preset to the component's role:
|
|
|
156
157
|
|
|
157
158
|
- **Layout containers** (`Space`, `Box`, `Grid`) — `FLOW_STYLES`, optionally with `DIMENSION_STYLES`
|
|
158
159
|
- **Positioned elements** (`Button`, `Badge`) — `POSITION_STYLES`
|
|
159
|
-
- **Text elements** —
|
|
160
|
+
- **Text elements** — `['color', ...TEXT_STYLES]`
|
|
161
|
+
|
|
162
|
+
`BASE_STYLES` (`display`, `font`, `preset`, `hide`, `whiteSpace`, `opacity`, `transition`) are accepted as props on every component without being listed; extend that set app-wide with [`configure({ baseStyleProps })`](configuration.md#base-style-props).
|
|
163
|
+
|
|
160
164
|
- **Compound components** — typically none; styling happens via sub-elements and extension
|
|
161
165
|
|
|
162
166
|
### The governance trade-off
|
|
@@ -220,6 +224,26 @@ modProps: ['isLoading', 'isSelected'] as const,
|
|
|
220
224
|
|
|
221
225
|
For the full API reference, see [React API — Mod Props](react-api.md#mod-props).
|
|
222
226
|
|
|
227
|
+
### variants vs modProps
|
|
228
|
+
|
|
229
|
+
Use `variants` for looks that replace each other (primary, danger, ghost) and `modProps` for states that combine (`isLoading`, `size`):
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
const Button = tasty({
|
|
233
|
+
as: 'button',
|
|
234
|
+
modProps: { isLoading: Boolean, size: ['sm', 'md', 'lg'] as const },
|
|
235
|
+
styles: { padding: { '': '1.5x 3x', 'size=sm': '1x 2x' }, radius: '1r' },
|
|
236
|
+
variants: {
|
|
237
|
+
default: { fill: '#primary', color: '#on-primary' },
|
|
238
|
+
danger: { fill: '#danger', color: '#on-danger' },
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
<Button variant="danger" size="sm" isLoading />;
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
`variant` is typed from the variant keys, the `default` variant applies when no `variant` prop is passed (set the `variant` option, as in `variant: 'danger'`, to fall back to another one), and only variants that render emit CSS. See [React API — Variants](react-api.md#variants).
|
|
246
|
+
|
|
223
247
|
---
|
|
224
248
|
|
|
225
249
|
## tokens prop for dynamic values
|
|
@@ -236,7 +260,7 @@ const ProgressBar = tasty({
|
|
|
236
260
|
width: '$progress',
|
|
237
261
|
height: '100%',
|
|
238
262
|
fill: '#primary',
|
|
239
|
-
transition: 'width
|
|
263
|
+
transition: 'width',
|
|
240
264
|
},
|
|
241
265
|
},
|
|
242
266
|
elements: { Bar: 'div' },
|
|
@@ -335,10 +359,9 @@ const LargeCard = tasty(Card, {
|
|
|
335
359
|
|
|
336
360
|
Why? Styled wrappers are:
|
|
337
361
|
|
|
338
|
-
- **
|
|
339
|
-
- **Stable** — the style object is defined once, not recreated on every render
|
|
362
|
+
- **Stable** — the style object is defined once at module level, so Tasty merges and computes it once instead of on every render
|
|
340
363
|
- **Composable** — another engineer can extend `LargeCard` further
|
|
341
|
-
- **Inspectable** —
|
|
364
|
+
- **Inspectable** — give it a `qa` (`tasty(Card, { qa: 'LargeCard', styles })`) and it appears as `data-qa="LargeCard"` in the DOM; React DevTools shows it as `TastyWrappedComponent(…)` around the base's name
|
|
342
365
|
- **Lint-friendly** — the ESLint plugin's `no-styles-prop` rule flags direct usage
|
|
343
366
|
|
|
344
367
|
The `styles` prop exists as an escape hatch — for prototyping, one-off overrides during development, or cases where wrapping is impractical. It should not be the default way product engineers customize components.
|
|
@@ -359,7 +382,7 @@ See [Best practices](#best-practices) below for the full list of do's and don'ts
|
|
|
359
382
|
|
|
360
383
|
## Wrapping and extension
|
|
361
384
|
|
|
362
|
-
`tasty(Base, { styles })` is the primary extension mechanism. It creates a new component whose styles are merged with the base component's styles.
|
|
385
|
+
`tasty(Base, { styles })` is the primary extension mechanism. It creates a new component whose styles are merged with the base component's styles. The extension can also declare its own `styleProps`, `modProps`, `tokenProps`, `variants`, and `elements`, and it keeps the base's sub-elements — see [React API — Extend an existing component](react-api.md#extend-an-existing-component).
|
|
363
386
|
|
|
364
387
|
```tsx
|
|
365
388
|
import { Button } from 'my-ds';
|
|
@@ -453,11 +476,13 @@ const DangerCard = tasty(Card, {
|
|
|
453
476
|
|
|
454
477
|
This is preferred over `<Card styles={{ border: '1bw solid #danger' }}>` because:
|
|
455
478
|
|
|
456
|
-
1.
|
|
479
|
+
1. The styles live in one module-level definition instead of being rebuilt inside render
|
|
457
480
|
2. `DangerCard` can be extended further by others
|
|
458
|
-
3. It
|
|
481
|
+
3. It is searchable in code, and carries `data-qa` in the DOM once you give it a `qa`
|
|
459
482
|
4. The ESLint `no-styles-prop` rule encourages this pattern
|
|
460
483
|
|
|
484
|
+
A wrapper keeps the base's sub-element components, typed: `DangerCard.Title` is `Card.Title`, so `<DangerCard><DangerCard.Title>…</DangerCard.Title></DangerCard>` works. The wrapper's `Title` styles apply to it, because they target `[data-element="Title"]`.
|
|
485
|
+
|
|
461
486
|
---
|
|
462
487
|
|
|
463
488
|
## How configuration simplifies components
|
|
@@ -534,7 +559,7 @@ See [Configuration](configuration.md) for the full `configure()` API.
|
|
|
534
559
|
|
|
535
560
|
- **Create styled wrappers** instead of passing `styles` directly — faster, composable, inspectable
|
|
536
561
|
- **Use design tokens and custom units** (`#text`, `2x`, `1r`) instead of raw CSS values
|
|
537
|
-
- **Use semantic transition names** (`transition: 'theme
|
|
562
|
+
- **Use semantic transition names** (`transition: 'theme'`) instead of listing CSS properties; omit the duration to use the motion tokens
|
|
538
563
|
- **Use `elements` prop** to declare typed sub-components for compound components
|
|
539
564
|
- **Use `styleProps`** to define what product engineers can customize
|
|
540
565
|
- **Use `modProps`** to expose known modifier states as clean component props
|
|
@@ -554,7 +579,7 @@ fill: 'oklch(55% 0.25 265)',
|
|
|
554
579
|
fill: '#primary',
|
|
555
580
|
```
|
|
556
581
|
|
|
557
|
-
Tokens ensure consistency across components and make theme changes a one-line update.
|
|
582
|
+
Tokens ensure consistency across components and make theme changes a one-line update. The recommended lint config flags this with `tasty/no-raw-color-values` and `tasty/consistent-token-usage`.
|
|
558
583
|
|
|
559
584
|
### Using CSS property names when Tasty alternatives exist
|
|
560
585
|
|
|
@@ -570,7 +595,7 @@ radius: '1r',
|
|
|
570
595
|
flow: 'column',
|
|
571
596
|
```
|
|
572
597
|
|
|
573
|
-
Tasty's enhanced properties provide concise syntax, better composability, and simpler overrides. See [recommended props](styles.md#recommended-props) for the full mapping.
|
|
598
|
+
Tasty's enhanced properties provide concise syntax, better composability, and simpler overrides. See [recommended props](styles.md#recommended-props) for the full mapping. `tasty/prefer-shorthand-property` flags the native spellings.
|
|
574
599
|
|
|
575
600
|
### Changing styles prop at runtime
|
|
576
601
|
|
|
@@ -593,7 +618,7 @@ const Card = tasty({
|
|
|
593
618
|
});
|
|
594
619
|
```
|
|
595
620
|
|
|
596
|
-
Modifiers are compiled into exclusive selectors once.
|
|
621
|
+
Modifiers are compiled into exclusive selectors once. A `styles` object that stays the same between renders (a module-level constant or a memoized object) is merged and computed once, but a new object on every render is merged and computed on every render, and each new value generates and injects new CSS. `tasty/no-styles-prop` and `tasty/no-runtime-styles-mutation` flag these patterns.
|
|
597
622
|
|
|
598
623
|
### Overusing style prop
|
|
599
624
|
|
|
@@ -607,7 +632,7 @@ const DangerButton = tasty(Button, {
|
|
|
607
632
|
});
|
|
608
633
|
```
|
|
609
634
|
|
|
610
|
-
The `style` prop bypasses tokens, units, and state maps. It should only be used for third-party library integration.
|
|
635
|
+
The `style` prop bypasses tokens, units, and state maps. It should only be used for third-party library integration. `tasty/no-style-prop` flags it on Tasty components.
|
|
611
636
|
|
|
612
637
|
### Skipping elements for compound components
|
|
613
638
|
|
package/docs/migration-v3.md
CHANGED
|
@@ -188,8 +188,8 @@ A key whose prefix doesn't match its value type is ignored with a development wa
|
|
|
188
188
|
## 7. Moved subpath
|
|
189
189
|
|
|
190
190
|
```diff
|
|
191
|
-
- import {
|
|
192
|
-
+ import {
|
|
191
|
+
- import { withTastyZero } from '@tenphi/tasty/next';
|
|
192
|
+
+ import { withTastyZero } from '@tenphi/tasty/zero/next';
|
|
193
193
|
```
|
|
194
194
|
|
|
195
195
|
The build-time extraction Next.js wrapper already lived under the `zero` namespace internally; the top-level `/next` path collided confusingly with `@tenphi/tasty/ssr/next`, which is a different integration.
|
|
@@ -204,7 +204,7 @@ The build-time extraction Next.js wrapper already lived under the `zero` namespa
|
|
|
204
204
|
|
|
205
205
|
**The `theme` prop is now implemented.** It maps to a `data-theme` attribute on the rendered element; previously it fell through and was spread onto the DOM raw. Augment `TastyThemeNames` for autocomplete.
|
|
206
206
|
|
|
207
|
-
**`tasty(Component, options)` no longer leaks factory-only options.** `variants`, `elements`, `styleProps`, `modProps`, and `tokenProps` are stripped instead of being passed to the wrapped component as runtime props, matching the element factory.
|
|
207
|
+
**`tasty(Component, options)` no longer leaks factory-only options.** `variants`, `elements`, `styleProps`, `modProps`, and `tokenProps` are stripped instead of being passed to the wrapped component as runtime props, matching the element factory. Since 3.11 the extension form applies them as the element factory does; see [Extend an existing component](react-api.md#extend-an-existing-component).
|
|
208
208
|
|
|
209
209
|
**Replacing a built-in style handler now warns.** Built-in handlers are shared across style names, so `configure({ handlers: { fill } })` also takes over `image` and the whole `background-*` family, and `configure({ handlers: { display } })` takes down `flow`, `gap`, `hide`, `overflow`, `whiteSpace`, and `textOverflow`. This was always true; what's new is that a development-mode warning now names exactly what was displaced. If you see it, either declare the whole group and delegate the rest to `styleHandlers.*`, or pick a narrower name. See [Plugins](plugins.md#custom-style-handlers).
|
|
210
210
|
|
package/docs/pipeline.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This document describes the style rendering pipeline that transforms style objects into CSS rules. The pipeline ensures that each style value is applied to exactly one condition through exclusive condition building, boolean simplification, and intelligent CSS generation.
|
|
4
4
|
|
|
5
|
-
**Implementation:** [`src/pipeline/`](
|
|
5
|
+
**Implementation:** [`src/pipeline/`](https://github.com/tenphi/tasty/tree/main/src/pipeline) — TypeScript file names below are relative to that directory.
|
|
6
6
|
|
|
7
7
|
## Overview
|
|
8
8
|
|
|
@@ -76,7 +76,7 @@ Output: CSSRule[]
|
|
|
76
76
|
|
|
77
77
|
**Simplification** (`simplifyCondition` in `simplify.ts`) is not a separate numbered stage. It runs inside OR expansion, exclusive building, `expandExclusiveOrs` branch cleanup, combination ANDs, merge-by-value ORs, and materialization. Every call is cached by condition unique-id, so the repetition is cheap.
|
|
78
78
|
|
|
79
|
-
**Post-pass:** After `processStyles` collects rules from every handler, `runPipeline` (`index.ts`) filters duplicates using a key of `selector|declarations|atRules|rootPrefix|startingStyle`, then **stable-sorts rules by their cascade `order` hint (ascending source priority)** so lower-priority rules come first and higher-priority rules win, and finally emits every `@starting-style` rule **after** all normal rules.
|
|
79
|
+
**Post-pass:** After `processStyles` collects rules from every handler, `runPipeline` (`index.ts`) filters duplicates using a key of `selector|declarations|atRules|rootPrefix|startingStyle`, then **stable-sorts rules by their cascade `order` hint (ascending source priority)** so lower-priority rules come first and higher-priority rules win, and finally emits every `@starting-style` rule **after** all normal rules. Each Stage 4 snapshot takes the highest source priority among its entries as its `order` hint; when Stage 6 merges same-output rules, the merged rule keeps the lowest `order` of its group, so a rule carrying the `_` floor's value keeps the floor's early position (threaded `ComputedRule → CSSRule`). This ordering is cascade-critical because Stage 7 equalizes specificity with `:where()`: once every state selector carries zero specificity, source order alone decides which of two overlapping rules wins — most importantly the `_` fallback floor (low order, emitted first) versus the states layered over it, and `@starting-style` versus its normal counterpart. Mutually-exclusive rules are unaffected by ordering (they never both match), so reordering them is safe.
|
|
80
80
|
|
|
81
81
|
---
|
|
82
82
|
|
|
@@ -86,18 +86,22 @@ Output: CSSRule[]
|
|
|
86
86
|
|
|
87
87
|
### What It Does
|
|
88
88
|
|
|
89
|
-
Runs on each style's value map **before** any parsing
|
|
89
|
+
Runs on each style's value map **before** any parsing, when the map has at least three keys and one of them uses `&`. An atom is a **don't-care** when flipping it never changes which value the map resolves to; every key that mentions a don't-care atom is dropped.
|
|
90
90
|
|
|
91
91
|
### How It Works
|
|
92
92
|
|
|
93
|
-
1.
|
|
94
|
-
2.
|
|
95
|
-
3.
|
|
96
|
-
4. Drop
|
|
93
|
+
1. Split each key into its top-level `&` atoms. Keys containing `|`, `^`, or `,` at top level are a single opaque atom. The `_` floor (and a misused `_` key) is kept verbatim and left out of the analysis.
|
|
94
|
+
2. Treat the map as the cascade it is: the last authored key whose atoms all hold wins, and `''` is always the lowest priority.
|
|
95
|
+
3. An atom is a don't-care when, in every state, the cascade resolves to the same value with the atom present as with it absent. Only the states `(K₁ minus the atom) ∪ K₀`, for every key `K₁` that contains the atom and every key `K₀` that does not (or none), can tell the two apart, so the check is quadratic in the number of keys rather than exponential in atoms.
|
|
96
|
+
4. Drop every key that contains a don't-care atom. With the atom forced absent those keys never match, and by definition the result is unchanged.
|
|
97
|
+
|
|
98
|
+
The check is over the cascade, not over pairs of keys. In `{ '': A, checked: B, 'invalid & checked': C, disabled: A }`, `disabled` has the default's value, but it outranks `checked`: a checked, disabled element gets `A`, so `disabled` is not a don't-care. (An earlier pairwise rule — "every key with the atom has a same-value partner without it" — folded `disabled` into `''` here and lost that priority.)
|
|
99
|
+
|
|
100
|
+
Atoms are compared as strings and treated as independent. Real atoms can be related (`theme=dark` vs `theme=light`, nested media ranges); that only rules states out, so a don't-care over independent atoms is one for every real state too. Two guards keep the rewrite safe: a map with more than 32 distinct atoms is left unreduced, and a reduction that would leave the `_` floor alone with `''` (which means "use the floor", see Stage 1) is skipped.
|
|
97
101
|
|
|
98
102
|
### Why
|
|
99
103
|
|
|
100
|
-
Removing don't-care dimensions before parsing prevents combinatorial blowup in later stages. `mergeEntriesByValue`, `buildExclusiveConditions`, and materialization all see fewer entries and fewer spurious conditions.
|
|
104
|
+
Removing don't-care dimensions before parsing prevents combinatorial blowup in later stages. `mergeEntriesByValue`, `buildExclusiveConditions`, and materialization all see fewer entries and fewer spurious conditions.
|
|
101
105
|
|
|
102
106
|
### Example
|
|
103
107
|
|
|
@@ -193,10 +197,14 @@ Merging two same-value entries with conditions `C_h` (higher priority) and `C_l`
|
|
|
193
197
|
|
|
194
198
|
The merge is safe iff for every entry `e_m` strictly between them in priority with a different value,
|
|
195
199
|
|
|
196
|
-
|
|
200
|
+
```
|
|
201
|
+
simplify(C_m & C_l & !C_h) = FALSE
|
|
202
|
+
```
|
|
197
203
|
|
|
198
204
|
i.e. there is no scenario where the intermediate state could have matched, the lower same-value entry would also have matched, and the higher one would not. This is the only way the merge could leak through and shadow the intermediate state.
|
|
199
205
|
|
|
206
|
+
An intermediate whose condition always holds (a tautological key, or same-value keys that already merged into one, like `beta | !beta`) is checked like any other. Only the `''` default and the `_` floor are exempt from the check, and they are always the lowest priorities, so they are never intermediates.
|
|
207
|
+
|
|
200
208
|
### Why
|
|
201
209
|
|
|
202
210
|
Without this pass a value map like `{ '@dark': 'red', '@dark & @hc': 'red' }` would create two separate entries that later produce two CSS rules with identical output. Merging before exclusive building keeps the exclusive condition algebra small and avoids duplicate CSS. The safety check ensures we never break the cascade in service of this optimization.
|
|
@@ -293,7 +301,9 @@ B: B & !A (applies only when A doesn't)
|
|
|
293
301
|
C: C & !A & !B (applies only when neither A nor B)
|
|
294
302
|
```
|
|
295
303
|
|
|
296
|
-
Each exclusive condition is passed through `simplifyCondition`. Entries that simplify to `FALSE` (impossible) are filtered out.
|
|
304
|
+
Each exclusive condition is passed through `simplifyCondition`. Entries that simplify to `FALSE` (impossible) are filtered out.
|
|
305
|
+
|
|
306
|
+
Every entry is added to the "prior" list, including one whose condition is `TRUE`. That can be a tautological key, or same-value keys that merged into one in Stage 1b (`alpha: X, '!alpha': X` → `TRUE`). Such an entry always applies at its priority, so negating it correctly makes every lower entry `FALSE`. The bare `''` default is `TRUE` too, but it is always the lowest priority, so no entry comes after it.
|
|
297
307
|
|
|
298
308
|
### `_` fallback floor
|
|
299
309
|
|
|
@@ -354,7 +364,7 @@ This is the companion to **Stage 2a** (user-OR expansion). The split exists beca
|
|
|
354
364
|
|
|
355
365
|
| Stage | Runs on | Sees ORs from | Sorts branches? |
|
|
356
366
|
|---|---|---|---|
|
|
357
|
-
| 2a `expandOrConditions` | `ParsedStyleEntry.condition` | User-authored
|
|
367
|
+
| 2a `expandOrConditions` | `ParsedStyleEntry.condition` | User-authored `\|` in state keys | No — user order is stable |
|
|
358
368
|
| 3 `expandExclusiveOrs` | `ExclusiveStyleEntry.exclusiveCondition` | De Morgan negation inside `buildExclusiveConditions` | Yes — at-rule branches first |
|
|
359
369
|
|
|
360
370
|
### How It Works
|
|
@@ -383,7 +393,7 @@ The pre-build Stage 2a pass doesn't need this because user-authored ORs aren't p
|
|
|
383
393
|
|
|
384
394
|
### Example (conceptual)
|
|
385
395
|
|
|
386
|
-
See the comment block in `exclusive.ts
|
|
396
|
+
See the comment block on `expandExclusiveOrs` in `exclusive.ts`: a default value whose higher-priority sibling is `@supports(...) & :has(...)` gets an exclusive of `!@supports | !:has`. Expansion yields one branch under `@supports (not ...)` and another under `@supports (...) { :not(:has()) }` instead of a bare `:not(:has())` rule.
|
|
387
397
|
|
|
388
398
|
---
|
|
389
399
|
|
|
@@ -395,6 +405,8 @@ See the comment block in `exclusive.ts:500-523`: a default value whose higher-pr
|
|
|
395
405
|
|
|
396
406
|
Computes the Cartesian product of all style entries for a handler, creating snapshots of which value each style has for each possible state combination.
|
|
397
407
|
|
|
408
|
+
When every input is a direct value rather than a state map, the pipeline skips stages 0–4 and passes one unconditional snapshot directly to the handler. This avoids building exclusive entries and a Cartesian product for ordinary state-free styles.
|
|
409
|
+
|
|
398
410
|
### How It Works
|
|
399
411
|
|
|
400
412
|
1. Collect exclusive entries for each style the handler uses
|
|
@@ -454,6 +466,7 @@ Style handlers encapsulate the logic for translating design tokens (like `'2x'`)
|
|
|
454
466
|
### What It Does
|
|
455
467
|
|
|
456
468
|
Combines rules that have identical CSS output into a single rule with an OR condition.
|
|
469
|
+
Zero- and one-rule inputs return unchanged because no merge is possible.
|
|
457
470
|
|
|
458
471
|
### How It Works
|
|
459
472
|
|
|
@@ -509,9 +522,9 @@ Converts condition trees into actual CSS selectors and at-rules.
|
|
|
509
522
|
|
|
510
523
|
5. **`:where()` specificity equalization**: Every stateful part of the selector is wrapped in `:where(...)` so it contributes **zero specificity**:
|
|
511
524
|
- the flat root modifiers + pseudos and the root element's `:is()`/`:not()` groups are combined into one `:where(...)` (`buildSelectorFromVariant`);
|
|
512
|
-
- the sub-element (`@own`) groups are wrapped in a **separate** `:where(...)` so the sub-element's structural `[data-element="X"]` specificity is preserved while its states are zeroed;
|
|
525
|
+
- the sub-element (`@own`) groups are wrapped in a **separate** `:where(...)` so the sub-element's structural `[data-element="X"]` specificity is preserved while its states are zeroed. When the suffix ends in a pseudo-element, these are the pseudo-element's own states and stay after it (`a::before:where(:hover)`). States a pseudo-element can't have (attributes, modifiers, classes, tree-structural pseudo-classes) are dropped with a `PSEUDO_ELEMENT_STATE_IGNORED` warning before Stage 0, using the CSS language alone, never per-browser support (`pseudo-element-states.ts`). A direct selector that ends in a pseudo-element (`.card::before`) is rendered separately: its root states are checked the same way and go after the pseudo-element, its `@parent` segments before it, at the `pseudoElementAt` each `CSSRule` records;
|
|
513
526
|
- `@parent` ancestors (`parentGroupsToCSS`) become `:where(... *)` / `:where(:not(... *))`;
|
|
514
|
-
- the `@root` context prefix (`
|
|
527
|
+
- the `@root` context prefix (`rootStateToPrefix`) becomes `:where(:root...)` (zeroing the `:root` pseudo too). When a direct selector can only match the root itself (`:root`, `html`, `:where(:root)`), the state segment joins it instead — `:root:where([data-schema="dark"])` — since an ancestor prefix would ask for a `:root` inside the root.
|
|
515
528
|
|
|
516
529
|
The only specificity anchors that remain are the doubled component class (`.tXX.tXX`, added by the injector) and sub-element `[data-element]` attributes. Because Stage 2b already makes ordinary rules mutually exclusive, zeroing specificity never changes *which* rule matches — it only makes additive layering (`_` fallback floor, `@starting-style`) resolve deterministically by source order (see the post-pass). Canonical sorting/dedup/subsumption still run first; `:where()` is only the final wrapper, and both output paths (injector and direct-selector / SSR) consume the same wrapped fragments.
|
|
517
530
|
|
|
@@ -534,12 +547,13 @@ interface CSSRule {
|
|
|
534
547
|
declarations: string; // CSS declarations (e.g. 'color: red;')
|
|
535
548
|
atRules?: string[]; // Wrapping at-rules
|
|
536
549
|
rootPrefix?: string; // Root state prefix
|
|
550
|
+
rootState?: string; // Root-state segment without its :root anchor; lets a root selector take states directly
|
|
537
551
|
startingStyle?: boolean; // Wrap declarations in @starting-style
|
|
538
552
|
order?: number; // Internal cascade order hint (ascending source priority); stripped before injection
|
|
539
553
|
}
|
|
540
554
|
```
|
|
541
555
|
|
|
542
|
-
When `renderStyles` runs **without** a selector, returned rules include `needsClassName: true` (compatibility field for the injector); that flag is not part of `CSSRule`
|
|
556
|
+
When `renderStyles` runs **without** a selector, returned rules include `needsClassName: true` (compatibility field for the injector); that flag is not part of `CSSRule` (defined in `materialize-types.ts`).
|
|
543
557
|
|
|
544
558
|
---
|
|
545
559
|
|
|
@@ -607,7 +621,7 @@ Applies boolean algebra rules to reduce condition complexity and detect impossib
|
|
|
607
621
|
- `A & (A | B) = A`
|
|
608
622
|
- `A | (A & B) = A`
|
|
609
623
|
|
|
610
|
-
7. **Range intersection**: For **media and container** dimension queries, impossible ranges simplify to `FALSE` (e.g. `@media(w > 400px) & @media(w < 300px)`). Ranges with compatible bounds are also merged in place (`w >= 400 & w <= 800` → a single bounded range).
|
|
624
|
+
7. **Range intersection**: For **media and container** dimension queries, impossible ranges simplify to `FALSE` (e.g. `@media(w > 400px) & @media(w < 300px)`). Ranges with compatible bounds are also merged in place (`w >= 400 & w <= 800` → a single bounded range). Only bounds in the same unit are compared: `600px` and `40em` are never merged or found contradictory, because a query `em` follows the user's default font size. A bound with no numeric value (`calc(…)`) and a range whose two bounds use different units are left as they are.
|
|
611
625
|
|
|
612
626
|
8. **Container style queries**: Conflicting or redundant `@container` style conditions on the same property can be reduced (see `simplify.ts` around the container-style conflict pass).
|
|
613
627
|
|
|
@@ -631,7 +645,7 @@ LRU and small auxiliary caches:
|
|
|
631
645
|
| Cache | Size | Key | Purpose |
|
|
632
646
|
|-------|------|-----|---------|
|
|
633
647
|
| `pipelineCache` | 5000 | `pipelineCacheKey \|\| stringifyStyles(styles)` | Skip full pipeline for identical styles |
|
|
634
|
-
| `parseCache` | 5000 | `trimmedStateKey + '
|
|
648
|
+
| `parseCache` | 5000 | `trimmedStateKey + '\0' + (isSubElement ? '1' : '0') + '\0' + (localPredefinedStates non-empty ? JSON.stringify(localPredefinedStates) : '')` | Skip re-parsing identical state keys in context |
|
|
635
649
|
| `simplifyCache` | 5000 | `getConditionUniqueId(node)` | Skip re-simplifying identical conditions |
|
|
636
650
|
| `conditionCache` | 3000 | `getConditionUniqueId(node)` in `conditionToCSS` | Skip re-materializing identical conditions |
|
|
637
651
|
| `variantKeyCache` | — | `WeakMap<SelectorVariant, string>` | Stable string keys for variants during materialization |
|
|
@@ -691,24 +705,24 @@ Each snapshot yields distinct declarations; no merge.
|
|
|
691
705
|
|
|
692
706
|
### Stage 7: Materialize CSS
|
|
693
707
|
|
|
694
|
-
Using `renderStyles(styles, '.t1')
|
|
708
|
+
Using `renderStyles(styles, '.t1', { doubleSelector: true })`. The injector doubles the class the same way (`.t1.t1`) so Tasty owns specificity without `!important`, and every state is wrapped in `:where()` so it adds none. Rules come out in ascending priority:
|
|
695
709
|
|
|
696
710
|
```css
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
711
|
+
@media (not (prefers-color-scheme: dark)) {
|
|
712
|
+
.t1.t1:where(:not([data-hovered])) {
|
|
713
|
+
color: var(--white-color);
|
|
714
|
+
--current-color: var(--white-color);
|
|
715
|
+
}
|
|
700
716
|
}
|
|
701
717
|
@media (prefers-color-scheme: dark) {
|
|
702
|
-
.t1:not([data-hovered]) {
|
|
718
|
+
.t1.t1:where(:not([data-hovered])) {
|
|
703
719
|
color: var(--dark-color);
|
|
704
720
|
--current-color: var(--dark-color);
|
|
705
721
|
}
|
|
706
722
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
--current-color: var(--white-color);
|
|
711
|
-
}
|
|
723
|
+
.t1.t1:where([data-hovered]) {
|
|
724
|
+
color: var(--highlight-color);
|
|
725
|
+
--current-color: var(--highlight-color);
|
|
712
726
|
}
|
|
713
727
|
```
|
|
714
728
|
|
|
@@ -739,3 +753,16 @@ Impossible combinations are detected at multiple levels (simplification, variant
|
|
|
739
753
|
### 4. Aggressive Caching
|
|
740
754
|
|
|
741
755
|
Parse, simplify, condition-to-CSS, and full-pipeline results are cached independently, enabling fast re-rendering when only parts of the style object change.
|
|
756
|
+
|
|
757
|
+
Cache keys must respect key order where it carries meaning. A state map resolves by key order, so `{ '': A, checked: B, disabled: C }` and `{ '': A, disabled: C, checked: B }` are different styles and must get different keys (and classes). Only the style keys of a styles object, including a sub-element's, are order-insensitive, so they may be sorted. `stringifyStyles` (pipeline cache) and `generateChunkCacheKey` (class allocation) both follow this rule.
|
|
758
|
+
|
|
759
|
+
---
|
|
760
|
+
|
|
761
|
+
## Testing Priority
|
|
762
|
+
|
|
763
|
+
Every stage above is an optimization that must leave one thing unchanged: in any state, the value that applies is the value of the last authored key whose condition holds. `src/test/state-oracle.ts` states that rule directly, with none of the pipeline's machinery, and two suites compare the pipeline against it:
|
|
764
|
+
|
|
765
|
+
- `src/pipeline/exclusive.test.ts` (Node) evaluates the conditions after each of Stages 0–3 on thousands of generated maps, and names the stage that disagrees.
|
|
766
|
+
- `src/pipeline/state-priority.test.ts` (browser) renders hand-written, permuted, and generated maps to CSS, applies every combination of states (modifiers, value modifiers, `:has()`, `@root`, `@parent`, `@own`, media, supports), and compares what the browser computes against the oracle. It also checks that rules stay mutually exclusive, which a correct computed value alone can hide. It runs through the pipeline, the runtime injector, and the SSR collector, with all maps mounted at once so a cache-key collision shows up.
|
|
767
|
+
|
|
768
|
+
A change to any stage should keep both green. When a generated map fails, the message includes the map, the failing states, and the CSS; the map is usually worth adding to the hand-written cases once it is reduced.
|
package/docs/plugins.md
CHANGED
|
@@ -37,7 +37,7 @@ configure({ plugins: [spacingPlugin()] });
|
|
|
37
37
|
|
|
38
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
39
|
|
|
40
|
-
**Repeated `configure()` calls merge
|
|
40
|
+
**Repeated `configure()` calls merge.** Each call adds to what earlier calls registered, key by key, in every registry (`states`, `units`, `functions`, `handlers`, `propHandlers`, `baseStyleProps`, `tokens`, `replaceTokens`, `recipes`, `keyframes`, `properties`, `fontFaces`, `counterStyles`); `globalStyles` merges per selector. A later value for the same key wins.
|
|
41
41
|
|
|
42
42
|
---
|
|
43
43
|
|
|
@@ -69,7 +69,7 @@ Two distinctions do most of the work:
|
|
|
69
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
70
|
|
|
71
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.
|
|
72
|
+
- Return a `CSSMap` with **kebab-case** keys, an array of them, or nothing. `$` is a selector suffix, not a property. A property whose value is an array gets one declaration per entry, for fallback chains.
|
|
73
73
|
- Handlers must be pure and synchronous. They are called once per state combination and the results are cached.
|
|
74
74
|
- Use `defineHandler(deps, fn)` for multi-dependency handlers so the dependency types are inferred.
|
|
75
75
|
|
|
@@ -108,6 +108,7 @@ configure({
|
|
|
108
108
|
|
|
109
109
|
```ts
|
|
110
110
|
import { configure, mergeStyles } from '@tenphi/tasty';
|
|
111
|
+
import type { Styles } from '@tenphi/tasty';
|
|
111
112
|
|
|
112
113
|
configure({
|
|
113
114
|
propHandlers: {
|
|
@@ -115,7 +116,11 @@ configure({
|
|
|
115
116
|
const { glaze, ...rest } = props;
|
|
116
117
|
if (!glaze) return rest;
|
|
117
118
|
|
|
118
|
-
|
|
119
|
+
// glazeStyles: see the worked example below
|
|
120
|
+
return {
|
|
121
|
+
...rest,
|
|
122
|
+
styles: mergeStyles(glazeStyles(glaze), rest.styles as Styles),
|
|
123
|
+
};
|
|
119
124
|
},
|
|
120
125
|
},
|
|
121
126
|
});
|
|
@@ -159,7 +164,7 @@ configure({ baseStyleProps: ['radius', 'shadow'] });
|
|
|
159
164
|
<Card radius="1r" shadow />
|
|
160
165
|
```
|
|
161
166
|
|
|
162
|
-
Names must
|
|
167
|
+
Names must start with a lowercase letter and contain only letters and digits, and must not collide with a prop `tasty()` consumes itself (`as`, `styles`, `variant`, `mods`, `tokens`, …); invalid entries are dropped with a development warning. Names are not checked against the style registry, so a misspelled name is still harvested as a style prop.
|
|
163
168
|
|
|
164
169
|
`configure()` may run _after_ your components are defined — each factory resolves its prop list lazily and refreshes when the registry changes.
|
|
165
170
|
|
|
@@ -169,39 +174,9 @@ Names must be real style properties, must start with a lowercase letter, and mus
|
|
|
169
174
|
|
|
170
175
|
## Typing your extension
|
|
171
176
|
|
|
172
|
-
|
|
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
|
-
```
|
|
177
|
+
Every extension point has a matching augmentation interface: `StylesInterface` for `handlers`, `TastyCustomProps` for `propHandlers`, `TastyBaseStylePropNames` for `baseStyleProps`, and `TastyNamedColors`, `TastyPresetNames`, and `TastyThemeNames` for the names your `tokens` and `presets` define. [Configuration → TypeScript](configuration.md#typescript) covers all six and the rules that go with them.
|
|
201
178
|
|
|
202
|
-
|
|
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:
|
|
179
|
+
**Also update `tasty.config.ts`.** The ESLint plugin and VS Code extension validate style and token names against it, and neither reads the runtime registries or your augmentations:
|
|
205
180
|
|
|
206
181
|
```ts
|
|
207
182
|
// tasty.config.ts
|
|
@@ -246,7 +221,7 @@ function glazeStyles(value: GlazeValue): Styles {
|
|
|
246
221
|
styles = Object.freeze({
|
|
247
222
|
'#glaze-bg': `#${tone}.${intensity}`,
|
|
248
223
|
fill: '#glaze-bg',
|
|
249
|
-
transition: 'fill
|
|
224
|
+
transition: 'fill',
|
|
250
225
|
}) as Styles;
|
|
251
226
|
cache.set(key, styles);
|
|
252
227
|
}
|
|
@@ -299,6 +274,8 @@ configure({ plugins: [glazePlugin()] });
|
|
|
299
274
|
|
|
300
275
|
```ts
|
|
301
276
|
// tasty.d.ts
|
|
277
|
+
import '@tenphi/tasty';
|
|
278
|
+
|
|
302
279
|
declare module '@tenphi/tasty' {
|
|
303
280
|
interface TastyCustomProps {
|
|
304
281
|
glaze: import('./glaze-plugin').GlazeConfig | string;
|
|
@@ -327,17 +304,20 @@ The object value is unambiguous here precisely because `glaze` is a **prop**. A
|
|
|
327
304
|
## Testing a plugin
|
|
328
305
|
|
|
329
306
|
```ts
|
|
330
|
-
import {
|
|
307
|
+
import { resetConfig, renderStyles } from '@tenphi/tasty';
|
|
308
|
+
import type { PropHandler, Styles } from '@tenphi/tasty';
|
|
331
309
|
|
|
332
310
|
describe('glaze plugin', () => {
|
|
333
311
|
beforeEach(() => resetConfig());
|
|
334
312
|
afterEach(() => resetConfig());
|
|
335
313
|
|
|
336
|
-
it('
|
|
337
|
-
|
|
314
|
+
it('turns the glaze prop into styles', () => {
|
|
315
|
+
const glaze = glazePlugin().propHandlers!.glaze as PropHandler;
|
|
316
|
+
const out = glaze({ glaze: 'purple' })!;
|
|
338
317
|
|
|
339
|
-
|
|
318
|
+
expect(out).not.toHaveProperty('glaze');
|
|
340
319
|
|
|
320
|
+
const rules = renderStyles(out.styles as Styles, '.test');
|
|
341
321
|
expect(rules[0].declarations).toContain('--glaze-bg-color');
|
|
342
322
|
});
|
|
343
323
|
});
|
|
@@ -345,7 +325,7 @@ describe('glaze plugin', () => {
|
|
|
345
325
|
|
|
346
326
|
Two things to know:
|
|
347
327
|
|
|
348
|
-
- **Create components inside each test.** `resetConfig()` does not clear
|
|
328
|
+
- **Create components inside each test.** `resetConfig()` does not clear a component's own class-name cache, which `tasty()` keeps in DOM environments, so a module-scope component can keep returning a class whose CSS the reset removed.
|
|
349
329
|
- **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.
|
|
350
330
|
|
|
351
331
|
---
|