@tenphi/tasty 0.0.0-snapshot.ee431f7 → 0.0.0-snapshot.ef8cc29
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 +354 -53
- package/dist/chunks/cacheKey.js +16 -8
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.js +1 -2
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/renderChunk.js +31 -32
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/config.d.ts +53 -10
- package/dist/config.js +75 -13
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +9 -8
- package/dist/core/index.js +7 -6
- package/dist/debug.d.ts +26 -141
- package/dist/debug.js +356 -635
- package/dist/debug.js.map +1 -1
- package/dist/hooks/useGlobalStyles.d.ts +3 -0
- package/dist/hooks/useGlobalStyles.js +28 -1
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.js +18 -3
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.js +36 -13
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.js +13 -1
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +5 -0
- package/dist/hooks/useStyles.js +91 -11
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +9 -8
- package/dist/index.js +7 -6
- package/dist/injector/index.d.ts +9 -1
- package/dist/injector/index.js +9 -1
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +9 -0
- package/dist/injector/injector.js +58 -32
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +16 -7
- package/dist/injector/sheet-manager.js +24 -9
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +9 -0
- package/dist/parser/classify.js +2 -1
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/parser.js +1 -1
- package/dist/pipeline/index.d.ts +1 -1
- package/dist/pipeline/index.js +45 -24
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +380 -119
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +1 -1
- package/dist/pipeline/parseStateKey.js +20 -11
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/plugins/okhsl-plugin.js +2 -275
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +9 -2
- package/dist/properties/index.js +82 -17
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.d.ts +24 -0
- package/dist/properties/property-type-resolver.js +91 -0
- package/dist/properties/property-type-resolver.js.map +1 -0
- package/dist/ssr/astro.d.ts +29 -0
- package/dist/ssr/astro.js +65 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +35 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +40 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +85 -0
- package/dist/ssr/collector.js +183 -0
- package/dist/ssr/collector.js.map +1 -0
- package/dist/ssr/context.d.ts +8 -0
- package/dist/ssr/context.js +14 -0
- package/dist/ssr/context.js.map +1 -0
- package/dist/ssr/format-global-rules.js +22 -0
- package/dist/ssr/format-global-rules.js.map +1 -0
- package/dist/ssr/format-keyframes.js +70 -0
- package/dist/ssr/format-keyframes.js.map +1 -0
- package/dist/ssr/format-property.js +50 -0
- package/dist/ssr/format-property.js.map +1 -0
- package/dist/ssr/format-rules.js +70 -0
- package/dist/ssr/format-rules.js.map +1 -0
- package/dist/ssr/hydrate.d.ts +22 -0
- package/dist/ssr/hydrate.js +50 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/index.d.ts +5 -0
- package/dist/ssr/index.js +12 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +45 -0
- package/dist/ssr/next.js +71 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/ssr/ssr-collector-ref.js +12 -0
- package/dist/ssr/ssr-collector-ref.js.map +1 -0
- package/dist/states/index.js +10 -257
- package/dist/states/index.js.map +1 -1
- package/dist/styles/color.js +9 -5
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/createStyle.js +24 -21
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/fill.js +6 -5
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/index.js +1 -1
- package/dist/styles/predefined.d.ts +0 -2
- package/dist/styles/predefined.js +1 -4
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.js +1 -1
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/scrollbar.d.ts +9 -5
- package/dist/styles/scrollbar.js +25 -89
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/transition.js +1 -1
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +42 -17
- package/dist/tasty.d.ts +12 -13
- package/dist/tasty.js +40 -12
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/cache-wrapper.js +4 -8
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/color-math.d.ts +46 -0
- package/dist/utils/color-math.js +749 -0
- package/dist/utils/color-math.js.map +1 -0
- package/dist/utils/color-space.d.ts +5 -0
- package/dist/utils/color-space.js +229 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.js +3 -1
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/has-keys.js +13 -0
- package/dist/utils/has-keys.js.map +1 -0
- package/dist/utils/mod-attrs.js +2 -2
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +3 -13
- package/dist/utils/process-tokens.js +18 -98
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/styles.d.ts +2 -79
- package/dist/utils/styles.js +28 -395
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +24 -13
- package/dist/utils/typography.js +6 -16
- package/dist/utils/typography.js.map +1 -1
- package/dist/zero/babel.d.ts +53 -6
- package/dist/zero/babel.js +76 -12
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/extractor.js +66 -1
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/next.d.ts +44 -30
- package/dist/zero/next.js +102 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/PIPELINE.md +519 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +296 -0
- package/docs/comparison.md +420 -0
- package/docs/configuration.md +265 -0
- package/docs/debug.md +318 -0
- package/docs/design-system.md +401 -0
- package/docs/dsl.md +582 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +528 -0
- package/docs/methodology.md +503 -0
- package/docs/runtime.md +317 -0
- package/docs/ssr.md +382 -0
- package/docs/styles.md +574 -0
- package/docs/tasty-static.md +431 -0
- package/package.json +52 -31
- package/dist/styles/styledScrollbar.d.ts +0 -47
- package/dist/styles/styledScrollbar.js +0 -38
- package/dist/styles/styledScrollbar.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
package/README.md
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
<h1 align="center">Tasty</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
<strong>
|
|
9
|
-
|
|
8
|
+
<strong>Deterministic styling for stateful component systems.</strong><br>
|
|
9
|
+
A design-system styling engine that compiles component states into mutually exclusive selectors.
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
12
|
<p align="center">
|
|
@@ -17,22 +17,41 @@
|
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
Tasty is a styling engine for design systems that generates deterministic CSS for stateful components.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
It compiles state maps into **mutually exclusive selectors**, so for a given property and component state, one branch wins by construction instead of competing through cascade and specificity.
|
|
23
|
+
|
|
24
|
+
That is the core guarantee: component styling resolves from declared state logic, not from source-order accidents or specificity fights.
|
|
25
|
+
|
|
26
|
+
Tasty fits best when you are building a design system or component library with intersecting states, variants, tokens, sub-elements, responsive rules, and extension semantics that need to stay predictable over time.
|
|
27
|
+
|
|
28
|
+
On top of that foundation, Tasty gives teams a governed styling model: a CSS-like DSL, tokens, recipes, typed style props, sub-elements, and multiple rendering modes.
|
|
29
|
+
|
|
30
|
+
- **New here?** Start with [Comparison](docs/comparison.md) if you are evaluating fit.
|
|
31
|
+
- **Adopting Tasty?** Read the [Adoption Guide](docs/adoption.md).
|
|
32
|
+
- **Want the mechanism first?** Jump to [How It Actually Works](#how-it-actually-works).
|
|
33
|
+
- **Ready to build?** Go to [Getting Started](docs/getting-started.md).
|
|
23
34
|
|
|
24
35
|
## Why Tasty
|
|
25
36
|
|
|
26
|
-
- **Deterministic
|
|
27
|
-
- **
|
|
28
|
-
- **
|
|
29
|
-
- **
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
- **
|
|
34
|
-
- **
|
|
35
|
-
- **
|
|
37
|
+
- **Deterministic composition, not cascade fights** — Stateful styles resolve from the state map you declared, not from selector competition. See [How It Actually Works](#how-it-actually-works).
|
|
38
|
+
- **Built for design-system teams** — Best fit for reusable component systems with complex state interactions.
|
|
39
|
+
- **A governed styling model, not just syntax sugar** — Design-system authors define the styling language product teams consume.
|
|
40
|
+
- **DSL that still feels like CSS** — Familiar property names, less selector boilerplate. Start with the [Style DSL](docs/dsl.md), then use [Style Properties](docs/styles.md) as the handler reference.
|
|
41
|
+
|
|
42
|
+
### Supporting capabilities
|
|
43
|
+
|
|
44
|
+
- **Typed style props** — `styleProps` lets you expose selected styles as typed React props. Use `<Button placeSelf="end">` or `<Space flow="row" gap="2x">` without extra wrappers, utility classes, or `styles` overrides. The same props also accept state maps, so responsive values work with the same API. See [CSS properties as props](#css-properties-as-props).
|
|
45
|
+
- **Runtime, SSR, and zero-runtime options** — Use `tasty()` for runtime React components, add SSR integrations when your framework renders that runtime on the server, or use `tastyStatic()` when you specifically want build-time extraction instead of runtime styling.
|
|
46
|
+
- **Broad modern CSS coverage** — Media queries, container queries, `@supports`, `:has()`, `@starting-style`, `@property`, `@keyframes`, and more. Features that do not fit the component model (such as `@layer` and `!important`) are intentionally left out.
|
|
47
|
+
- **Performance and caching** — Runtime mode injects CSS on demand, reuses chunks aggressively, and relies on multi-level caching so large component systems stay practical.
|
|
48
|
+
- **TypeScript-first and AI-friendly** — Style definitions are declarative, structurally consistent, and fully typed, which helps both humans and tooling understand advanced stateful styles without hidden cascade logic.
|
|
49
|
+
|
|
50
|
+
## Why It Exists
|
|
51
|
+
|
|
52
|
+
Modern component styling becomes fragile when multiple selectors can still win for the same property. Hover, disabled, theme, breakpoint, parent state, and root state rules start competing through specificity and source order.
|
|
53
|
+
|
|
54
|
+
Tasty replaces that competition with explicit state-map resolution. Each property compiles into mutually exclusive branches, so component styling stays deterministic as systems grow. For the full mechanism, jump to [How It Actually Works](#how-it-actually-works).
|
|
36
55
|
|
|
37
56
|
## Installation
|
|
38
57
|
|
|
@@ -40,6 +59,30 @@ That guarantee unlocks a concise, CSS-like DSL where design tokens, custom units
|
|
|
40
59
|
pnpm add @tenphi/tasty
|
|
41
60
|
```
|
|
42
61
|
|
|
62
|
+
Requirements:
|
|
63
|
+
|
|
64
|
+
- Node.js 20+
|
|
65
|
+
- React 18+ (peer dependency for the React entry points)
|
|
66
|
+
- `pnpm`, `npm`, or `yarn`
|
|
67
|
+
|
|
68
|
+
Other package managers:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npm add @tenphi/tasty
|
|
72
|
+
yarn add @tenphi/tasty
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Start Here
|
|
76
|
+
|
|
77
|
+
For the fuller docs map beyond the quick routes above, start here:
|
|
78
|
+
|
|
79
|
+
- **[Comparison](docs/comparison.md)** — read this first if you are evaluating whether Tasty fits your team's styling model
|
|
80
|
+
- **[Adoption Guide](docs/adoption.md)** — understand who Tasty is for, where it fits, and how to introduce it incrementally
|
|
81
|
+
- **[Getting Started](docs/getting-started.md)** — the canonical onboarding path: install, first component, optional shared `configure()`, ESLint, editor tooling, and rendering mode selection
|
|
82
|
+
- **[Style rendering pipeline](docs/PIPELINE.md)** — see the selector model behind deterministic style resolution
|
|
83
|
+
- **[Docs Hub](docs/README.md)** — choose docs by role and task: runtime, zero-runtime, runtime SSR integration, design-system authoring, internals, and debugging
|
|
84
|
+
- **[Methodology](docs/methodology.md)** — the recommended component model and public API conventions for design-system code
|
|
85
|
+
|
|
43
86
|
## Quick Start
|
|
44
87
|
|
|
45
88
|
### Create a styled component
|
|
@@ -52,11 +95,12 @@ const Card = tasty({
|
|
|
52
95
|
styles: {
|
|
53
96
|
display: 'flex',
|
|
54
97
|
flow: 'column',
|
|
55
|
-
padding: '
|
|
56
|
-
gap: '
|
|
57
|
-
fill: '
|
|
58
|
-
|
|
59
|
-
|
|
98
|
+
padding: '24px',
|
|
99
|
+
gap: '12px',
|
|
100
|
+
fill: 'white',
|
|
101
|
+
color: '#222',
|
|
102
|
+
border: '1px solid #ddd',
|
|
103
|
+
radius: '12px',
|
|
60
104
|
},
|
|
61
105
|
});
|
|
62
106
|
|
|
@@ -64,7 +108,11 @@ const Card = tasty({
|
|
|
64
108
|
<Card>Hello World</Card>
|
|
65
109
|
```
|
|
66
110
|
|
|
67
|
-
Every value maps to CSS you'd recognize
|
|
111
|
+
Every value maps to CSS you'd recognize. This example is intentionally a simple first contact, not a tour of the whole DSL.
|
|
112
|
+
|
|
113
|
+
When you want a more design-system-shaped authoring model, Tasty also supports built-in units, tokens, recipes, state aliases, and color values such as `okhsl(...)` without extra runtime libraries.
|
|
114
|
+
|
|
115
|
+
Use `configure()` when you want to define shared tokens, state aliases, recipes, or other conventions for your app or design system. For a fuller onboarding path, follow [Getting Started](docs/getting-started.md).
|
|
68
116
|
|
|
69
117
|
### Add state-driven styles
|
|
70
118
|
|
|
@@ -111,7 +159,7 @@ const DangerButton = tasty(Button, {
|
|
|
111
159
|
|
|
112
160
|
Child styles merge with parent styles intelligently — state maps can extend or replace parent states per-property.
|
|
113
161
|
|
|
114
|
-
###
|
|
162
|
+
### Optional: configure shared conventions
|
|
115
163
|
|
|
116
164
|
```tsx
|
|
117
165
|
import { configure } from '@tenphi/tasty';
|
|
@@ -128,17 +176,96 @@ configure({
|
|
|
128
176
|
});
|
|
129
177
|
```
|
|
130
178
|
|
|
131
|
-
Predefined states turn complex selector logic into single tokens
|
|
179
|
+
Use `configure()` once when your app or design system needs shared aliases, tokens, recipes, or parser extensions. Predefined states turn complex selector logic into single tokens, so teams can write `@mobile` instead of repeating media query expressions in every component.
|
|
180
|
+
|
|
181
|
+
### CSS properties as props
|
|
182
|
+
|
|
183
|
+
Beyond state resolution, Tasty can also expose selected style controls as typed component props. That lets design systems keep layout and composition inside governed component APIs instead of pushing teams toward wrapper elements or ad hoc styling escapes.
|
|
184
|
+
|
|
185
|
+
With `styleProps`, a component can expose the styles you choose as normal typed props. You can adjust layout, spacing, alignment, or positioning where the component is used while staying inside a typed, design-system-aware API.
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
import { tasty, FLOW_STYLES, POSITION_STYLES } from '@tenphi/tasty';
|
|
189
|
+
|
|
190
|
+
const Space = tasty({
|
|
191
|
+
styles: {
|
|
192
|
+
display: 'flex',
|
|
193
|
+
flow: 'column',
|
|
194
|
+
gap: '1x',
|
|
195
|
+
},
|
|
196
|
+
styleProps: FLOW_STYLES,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const Button = tasty({
|
|
200
|
+
as: 'button',
|
|
201
|
+
styles: {
|
|
202
|
+
padding: '1.5x 3x',
|
|
203
|
+
fill: '#primary',
|
|
204
|
+
color: '#primary-text',
|
|
205
|
+
radius: true,
|
|
206
|
+
},
|
|
207
|
+
styleProps: POSITION_STYLES,
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Now you can compose layout and tweak component positioning directly in JSX:
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
<Space flow="row" gap="2x" placeItems="center">
|
|
215
|
+
<Title>Dashboard</Title>
|
|
216
|
+
<Button placeSelf="end">Add Item</Button>
|
|
217
|
+
</Space>
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
The same props also support state maps, so responsive values use the exact same API:
|
|
221
|
+
|
|
222
|
+
```tsx
|
|
223
|
+
<Space
|
|
224
|
+
flow={{ '': 'column', '@tablet': 'row' }}
|
|
225
|
+
gap={{ '': '2x', '@tablet': '4x' }}
|
|
226
|
+
>
|
|
227
|
+
<Sidebar />
|
|
228
|
+
<Content />
|
|
229
|
+
</Space>
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Layout components can expose flow props. Buttons can expose positioning props. Each component can offer only the style props that make sense for its role while keeping tokens, custom units, and state maps fully typed. This works in runtime `tasty()` components, not in `tastyStatic()`.
|
|
233
|
+
|
|
234
|
+
## Choose a Styling Approach
|
|
235
|
+
|
|
236
|
+
Once you understand the component model, pick the rendering mode that matches your app.
|
|
237
|
+
|
|
238
|
+
| Approach | Entry point | Best for | Trade-off |
|
|
239
|
+
|----------|-------------|----------|-----------|
|
|
240
|
+
| **Runtime** | `@tenphi/tasty` | Interactive apps with reusable stateful components and design systems | Full feature set; CSS is generated on demand at runtime |
|
|
241
|
+
| **Zero-runtime** | `@tenphi/tasty/static` | Static sites, SSG, landing pages | Requires the Babel plugin; no component-level `styleProps` or runtime-only APIs |
|
|
242
|
+
|
|
243
|
+
If your framework can execute runtime React code on the server, you can also add **SSR on top of runtime** with `@tenphi/tasty/ssr/*`. This uses the same `tasty()` pipeline, but collects CSS during server rendering and hydrates the cache on the client. That is the model for Next.js, generic React SSR, and Astro islands. See [Getting Started](docs/getting-started.md#choosing-a-rendering-mode), [Zero Runtime](docs/tasty-static.md), and [Server-Side Rendering](docs/ssr.md).
|
|
132
244
|
|
|
133
245
|
## How It Actually Works
|
|
134
246
|
|
|
135
247
|
This is the core idea that makes everything else possible.
|
|
136
248
|
|
|
137
|
-
|
|
249
|
+
For the end-to-end architecture — parsing state keys, building exclusive conditions, merging by output, and materializing selectors and at-rules — see **[Style rendering pipeline](docs/PIPELINE.md)**.
|
|
250
|
+
|
|
251
|
+
### The structural problem with normal CSS
|
|
138
252
|
|
|
139
253
|
First, the **cascade** resolves conflicts by specificity and source order: when multiple selectors match, the one with the highest specificity wins, or — if specificity is equal — the last one in source order wins. That makes styles inherently fragile. Reordering imports, adding a media query, or composing components from different libraries can silently break styling.
|
|
140
254
|
|
|
141
|
-
|
|
255
|
+
A small example makes this tangible. Two rules for a button's background:
|
|
256
|
+
|
|
257
|
+
```css
|
|
258
|
+
.btn:hover { background: dodgerblue; }
|
|
259
|
+
.btn[disabled] { background: gray; }
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Both selectors have specificity `(0, 1, 1)`. When the button is hovered **and** disabled, both match — and the last rule in source order wins. Swap the two lines and a hovered disabled button silently turns blue instead of gray. This class of bug is invisible in code review because the logic is correct; only the ordering is wrong.
|
|
263
|
+
|
|
264
|
+
### Why real state logic is hard to author by hand
|
|
265
|
+
|
|
266
|
+
Authoring selectors that capture real-world state logic is fundamentally hard. A single state like "dark mode" may depend on a root attribute, an OS preference, or both — each branch needing its own selector, proper negation of competing branches, and correct `@media` nesting. The example below shows the CSS you'd write by hand for just *one* property with *one* state. Scale that across dozens of properties, then add breakpoints and container queries, and the selector logic quickly becomes unmanageable.
|
|
267
|
+
|
|
268
|
+
### What Tasty generates instead
|
|
142
269
|
|
|
143
270
|
Tasty solves both problems at once: **every state mapping compiles into mutually exclusive selectors.**
|
|
144
271
|
|
|
@@ -157,7 +284,31 @@ const Text = tasty({
|
|
|
157
284
|
});
|
|
158
285
|
```
|
|
159
286
|
|
|
160
|
-
If `@dark` expands to `@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))`,
|
|
287
|
+
If `@dark` expands to `@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))`, try writing the CSS by hand. A first attempt might look like this:
|
|
288
|
+
|
|
289
|
+
```css
|
|
290
|
+
/* First attempt — the @media branch is too broad */
|
|
291
|
+
.t0 { color: var(--text-color); }
|
|
292
|
+
:root[data-schema="dark"] .t0 { color: var(--text-on-dark-color); }
|
|
293
|
+
@media (prefers-color-scheme: dark) {
|
|
294
|
+
.t0 { color: var(--text-on-dark-color); }
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
The `@media` branch fires even when `data-schema="light"` is explicitly set. Fix that:
|
|
299
|
+
|
|
300
|
+
```css
|
|
301
|
+
/* Second attempt — @media is scoped, but the default is still too broad */
|
|
302
|
+
.t0 { color: var(--text-color); }
|
|
303
|
+
:root[data-schema="dark"] .t0 { color: var(--text-on-dark-color); }
|
|
304
|
+
@media (prefers-color-scheme: dark) {
|
|
305
|
+
:root:not([data-schema]) .t0 { color: var(--text-on-dark-color); }
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Better — but the bare `.t0` default still matches unconditionally. It matches in dark mode, it matches when `data-schema="dark"` is set, and it can beat the attribute selector by source order if another rule re-declares it later. There is no selector that says "apply this default only when none of the dark branches win."
|
|
310
|
+
|
|
311
|
+
This is just *one* property with *one* state, and getting it right already takes multiple iterations. The correct selectors require negating every other branch — which is exactly what Tasty generates automatically:
|
|
161
312
|
|
|
162
313
|
```css
|
|
163
314
|
/* Branch 1: Explicit dark schema */
|
|
@@ -185,12 +336,18 @@ If `@dark` expands to `@root(schema=dark) | (!@root(schema) & @media(prefers-col
|
|
|
185
336
|
}
|
|
186
337
|
```
|
|
187
338
|
|
|
339
|
+
### What guarantee that gives you
|
|
340
|
+
|
|
188
341
|
Every rule is guarded by the negation of higher-priority rules. No two rules can match at the same time. No specificity arithmetic. No source-order dependence. Components compose and extend without collisions.
|
|
189
342
|
|
|
190
|
-
By absorbing selector complexity, Tasty makes advanced CSS patterns practical again — nested container queries, multi-condition `@supports` gates, and combined root-state/media branches. You stay in pure CSS instead of relying on JavaScript workarounds, so the browser can optimize layout, painting, and transitions natively. Tasty
|
|
343
|
+
By absorbing selector complexity, Tasty makes advanced CSS patterns practical again — nested container queries, multi-condition `@supports` gates, and combined root-state/media branches. You stay in pure CSS instead of relying on JavaScript workarounds, so the browser can optimize layout, painting, and transitions natively. Tasty keeps the solution in CSS while removing much of the selector bookkeeping that is hard to maintain by hand.
|
|
344
|
+
|
|
345
|
+
[Try it in the Cube UI Kit Storybook playground →](https://cube-ui-kit.vercel.app/?path=/story/getting-started-tasty-playground--playground)
|
|
191
346
|
|
|
192
347
|
## Capabilities
|
|
193
348
|
|
|
349
|
+
This section is a quick product tour. For the canonical guides and references, start from the [Docs Hub](docs/README.md).
|
|
350
|
+
|
|
194
351
|
### Design Tokens and Custom Units
|
|
195
352
|
|
|
196
353
|
Tokens are first-class. Colors use `#name` syntax. Spacing, radius, and border width use multiplier units tied to CSS custom properties:
|
|
@@ -226,7 +383,7 @@ Every style property accepts a state mapping object. Keys can be combined with b
|
|
|
226
383
|
| Class selector (supported) | `.is-active` | `.is-active` |
|
|
227
384
|
| Media query | `@media(w < 768px)` | `@media (width < 768px)` |
|
|
228
385
|
| Container query | `@(panel, w >= 300px)` | `@container panel (width >= 300px)` |
|
|
229
|
-
| Root state | `@root(
|
|
386
|
+
| Root state | `@root(schema=dark)` | `:root[data-schema="dark"]` |
|
|
230
387
|
| Parent state | `@parent(theme=danger)` | `:is([data-theme="danger"] *)` |
|
|
231
388
|
| Feature query | `@supports(display: grid)` | `@supports (display: grid)` |
|
|
232
389
|
| Entry animation | `@starting` | `@starting-style` |
|
|
@@ -310,22 +467,15 @@ const ProfileCard = tasty({
|
|
|
310
467
|
|
|
311
468
|
Use `/` to post-apply recipes after local styles when you need recipe states/styles to win the final merge order. Use `none` to skip base recipes: `recipe: 'none / disabled'`.
|
|
312
469
|
|
|
313
|
-
###
|
|
470
|
+
### Auto-Inferred `@property`
|
|
314
471
|
|
|
315
|
-
|
|
472
|
+
CSS custom properties do not animate smoothly by default because the browser does not know how to interpolate their values. The [`@property`](https://developer.mozilla.org/en-US/docs/Web/CSS/@property) at-rule fixes that by declaring a property's syntax, such as `<number>` or `<color>`.
|
|
316
473
|
|
|
317
|
-
|
|
474
|
+
In Tasty, you usually do not need to declare `@property` manually. When a custom property is assigned a concrete value, Tasty infers the syntax and registers the matching `@property` for you:
|
|
318
475
|
|
|
319
476
|
```tsx
|
|
320
477
|
const Pulse = tasty({
|
|
321
478
|
styles: {
|
|
322
|
-
'@properties': {
|
|
323
|
-
'$pulse-scale': {
|
|
324
|
-
syntax: '<number>',
|
|
325
|
-
inherits: false,
|
|
326
|
-
initialValue: 1,
|
|
327
|
-
},
|
|
328
|
-
},
|
|
329
479
|
animation: 'pulse 2s infinite',
|
|
330
480
|
transform: 'scale($pulse-scale)',
|
|
331
481
|
'@keyframes': {
|
|
@@ -338,6 +488,20 @@ const Pulse = tasty({
|
|
|
338
488
|
});
|
|
339
489
|
```
|
|
340
490
|
|
|
491
|
+
Here, `$pulse-scale: 1` is inferred as `<number>`, so Tasty injects `@property --pulse-scale` automatically before using it in the animation. Numeric types (`<number>`, `<length>`, `<percentage>`, `<angle>`, `<time>`) are inferred from values; `<color>` is inferred from the `#name` token convention.
|
|
492
|
+
|
|
493
|
+
If you prefer full manual control, disable auto-inference globally with `configure({ autoPropertyTypes: false })`.
|
|
494
|
+
|
|
495
|
+
### Explicit `@properties`
|
|
496
|
+
|
|
497
|
+
Declare `@properties` yourself only when you need to override the defaults, for example to set `inherits: false` or provide a custom `initialValue`:
|
|
498
|
+
|
|
499
|
+
```tsx
|
|
500
|
+
'@properties': {
|
|
501
|
+
'$pulse-scale': { syntax: '<number>', inherits: false, initialValue: 1 },
|
|
502
|
+
},
|
|
503
|
+
```
|
|
504
|
+
|
|
341
505
|
### React Hooks
|
|
342
506
|
|
|
343
507
|
For cases where you don't need a full component:
|
|
@@ -347,8 +511,8 @@ import { useStyles, useGlobalStyles, useRawCSS } from '@tenphi/tasty';
|
|
|
347
511
|
|
|
348
512
|
function App() {
|
|
349
513
|
const { className } = useStyles({ padding: '2x', fill: '#surface' });
|
|
350
|
-
useGlobalStyles('
|
|
351
|
-
useRawCSS('
|
|
514
|
+
useGlobalStyles('body', { margin: '0' });
|
|
515
|
+
useRawCSS('@font-face { font-family: "Custom"; src: url(...); }');
|
|
352
516
|
|
|
353
517
|
return <main className={className}>...</main>;
|
|
354
518
|
}
|
|
@@ -380,7 +544,7 @@ module.exports = {
|
|
|
380
544
|
['@tenphi/tasty/babel-plugin', {
|
|
381
545
|
output: 'public/tasty.css',
|
|
382
546
|
config: {
|
|
383
|
-
states: { '@dark': '@root(
|
|
547
|
+
states: { '@dark': '@root(schema=dark)' },
|
|
384
548
|
},
|
|
385
549
|
}],
|
|
386
550
|
],
|
|
@@ -399,21 +563,51 @@ module.exports = {
|
|
|
399
563
|
| **Sub-elements** | Built-in (`<C.Title>`) | Manual (`data-element`) |
|
|
400
564
|
| **Variants** | Built-in (`variants` option) | Separate static styles |
|
|
401
565
|
| **Framework** | React | Any (requires Babel) |
|
|
402
|
-
| **Best for** | Interactive apps, design systems | Static sites, SSG, landing pages |
|
|
566
|
+
| **Best for** | Interactive apps with reusable stateful components, design systems | Static sites, SSG, landing pages |
|
|
403
567
|
|
|
404
568
|
Both share the same DSL, tokens, units, state mappings, and recipes.
|
|
405
569
|
|
|
406
|
-
###
|
|
570
|
+
### Server-Side Rendering
|
|
407
571
|
|
|
408
|
-
|
|
572
|
+
SSR with zero-cost client hydration. Existing `tasty()` components work unchanged — SSR is opt-in and requires no per-component modifications. Supports Next.js (App Router with streaming), Astro (middleware + islands), and any React-based framework via the core API. Requires React 18+.
|
|
409
573
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
574
|
+
**Next.js setup:**
|
|
575
|
+
|
|
576
|
+
```tsx
|
|
577
|
+
// app/tasty-registry.tsx
|
|
578
|
+
'use client';
|
|
579
|
+
|
|
580
|
+
import { TastyRegistry } from '@tenphi/tasty/ssr/next';
|
|
581
|
+
|
|
582
|
+
export default function TastyStyleRegistry({
|
|
583
|
+
children,
|
|
584
|
+
}: {
|
|
585
|
+
children: React.ReactNode;
|
|
586
|
+
}) {
|
|
587
|
+
return <TastyRegistry>{children}</TastyRegistry>;
|
|
588
|
+
}
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
```tsx
|
|
592
|
+
// app/layout.tsx
|
|
593
|
+
import TastyStyleRegistry from './tasty-registry';
|
|
594
|
+
|
|
595
|
+
export default function RootLayout({
|
|
596
|
+
children,
|
|
597
|
+
}: {
|
|
598
|
+
children: React.ReactNode;
|
|
599
|
+
}) {
|
|
600
|
+
return (
|
|
601
|
+
<html>
|
|
602
|
+
<body>
|
|
603
|
+
<TastyStyleRegistry>{children}</TastyStyleRegistry>
|
|
604
|
+
</body>
|
|
605
|
+
</html>
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
See the [full SSR guide](docs/ssr.md) for Astro integration, streaming SSR, generic framework usage, troubleshooting, and the current requirements.
|
|
417
611
|
|
|
418
612
|
## Entry Points
|
|
419
613
|
|
|
@@ -425,6 +619,69 @@ If you choose the runtime approach, performance is usually a non-issue in practi
|
|
|
425
619
|
| `@tenphi/tasty/babel-plugin` | Babel plugin for zero-runtime CSS extraction | Node |
|
|
426
620
|
| `@tenphi/tasty/zero` | Programmatic extraction API | Node |
|
|
427
621
|
| `@tenphi/tasty/next` | Next.js integration wrapper | Node |
|
|
622
|
+
| `@tenphi/tasty/ssr` | Core SSR API (collector, context, hydration) | Node |
|
|
623
|
+
| `@tenphi/tasty/ssr/next` | Next.js App Router SSR integration | Node |
|
|
624
|
+
| `@tenphi/tasty/ssr/astro` | Astro middleware + auto-hydration | Node / Browser |
|
|
625
|
+
|
|
626
|
+
## Browser Requirements
|
|
627
|
+
|
|
628
|
+
Tasty's exclusive selector system relies on modern CSS pseudo-class syntax:
|
|
629
|
+
|
|
630
|
+
- **`:is()`** — available across all major browsers since January 2021 ([MDN Baseline](https://developer.mozilla.org/en-US/docs/Web/CSS/:is)).
|
|
631
|
+
- **Level-4 `:not()` with selector lists** — Chrome/Edge 88+, Firefox 84+, Safari 9+, Opera 75+.
|
|
632
|
+
- **Not supported:** IE 11.
|
|
633
|
+
|
|
634
|
+
## Performance
|
|
635
|
+
|
|
636
|
+
### Bundle Size
|
|
637
|
+
|
|
638
|
+
All sizes measured with [size-limit](https://github.com/ai/size-limit) — minified and brotli-compressed, including all dependencies.
|
|
639
|
+
|
|
640
|
+
| Entry point | Size |
|
|
641
|
+
|-------------|------|
|
|
642
|
+
| `@tenphi/tasty` (runtime + SSR) | ~44 kB |
|
|
643
|
+
| `@tenphi/tasty/core` (runtime, no SSR) | ~41 kB |
|
|
644
|
+
| `@tenphi/tasty/static` (zero-runtime) | ~1.5 kB |
|
|
645
|
+
|
|
646
|
+
Run `pnpm size` for exact up-to-date numbers.
|
|
647
|
+
|
|
648
|
+
### Runtime Benchmarks
|
|
649
|
+
|
|
650
|
+
If you choose the runtime approach, performance is usually a non-issue in practice. The numbers below show single-call throughput for the core pipeline stages, measured with `vitest bench` on an Apple M1 Max (Node 22).
|
|
651
|
+
|
|
652
|
+
| Operation | ops/sec | Latency (mean) |
|
|
653
|
+
|-----------|--------:|---------------:|
|
|
654
|
+
| `renderStyles` — 5 flat properties (cold) | ~72,000 | ~14 us |
|
|
655
|
+
| `renderStyles` — state map with media/hover/modifier (cold) | ~22,000 | ~46 us |
|
|
656
|
+
| `renderStyles` — same styles (cached) | ~7,200,000 | ~0.14 us |
|
|
657
|
+
| `parseStateKey` — simple key like `:hover` (cold) | ~1,200,000 | ~0.9 us |
|
|
658
|
+
| `parseStateKey` — complex OR/AND/NOT key (cold) | ~190,000 | ~5 us |
|
|
659
|
+
| `parseStateKey` — any key (cached) | ~3,300,000–8,900,000 | ~0.1–0.3 us |
|
|
660
|
+
| `parseStyle` — value tokens like `2x 4x` (cold) | ~345,000 | ~3 us |
|
|
661
|
+
| `parseStyle` — color tokens (cold) | ~525,000 | ~1.9 us |
|
|
662
|
+
| `parseStyle` — any value (cached) | ~15,500,000 | ~0.06 us |
|
|
663
|
+
|
|
664
|
+
"Cold" benchmarks use unique inputs to bypass all caches. Cached benchmarks reuse a single input and measure the LRU hot path.
|
|
665
|
+
|
|
666
|
+
Run `pnpm bench` to reproduce.
|
|
667
|
+
|
|
668
|
+
#### What This Means in Practice
|
|
669
|
+
|
|
670
|
+
- **Cached path dominates production.** After a component's first render, subsequent renders with stable styles skip the pipeline entirely (React `useMemo` + LRU cache hits at every level). All cached operations are sub-microsecond — effectively free.
|
|
671
|
+
- **Cold path is fast enough.** The heaviest cold operation — a complex state map with media queries, hover, and modifiers — takes ~46 us. Even a page with 100 unique styled components adds only ~5 ms of total style computation on first render, negligible next to React reconciliation and DOM work.
|
|
672
|
+
- **Cache multipliers are 30x–100x.** This confirms the multi-level LRU architecture (parser, state-key, simplify, condition, pipeline) is delivering real value.
|
|
673
|
+
- **Comparable to lighter systems.** Emotion's `css()` is typically 5–20 us for simple styles; Tasty's cold `renderStyles` at ~14 us for 5 properties is in the same range despite doing significantly more work (state maps, design tokens, sub-elements, chunking).
|
|
674
|
+
- **On slower devices.** The benchmarks above are from an M1 Max (Geekbench 6 SC ~2,400). A mid-range consumer laptop (~1,800 SC) is roughly 1.3x slower; a mid-range phone (~1,200 SC) is roughly 2x slower; a budget phone (~700 SC) is roughly 3–4x slower. Even at 4x, the heaviest cold operation stays under 200 us and 100 unique components under 20 ms — still well within a single frame budget. The cached path remains sub-microsecond on all devices.
|
|
675
|
+
|
|
676
|
+
### How It Stays Fast
|
|
677
|
+
|
|
678
|
+
- CSS is generated and injected only when styles are actually used.
|
|
679
|
+
- Multi-level caching avoids repeated parsing and style recomputation.
|
|
680
|
+
- Styles are split into reusable chunks and applied as multiple class names, so matching chunks can be reused across components instead of re-injected.
|
|
681
|
+
- Style normalization guarantees equivalent style input resolves to the same chunks, improving deduplication hit rates.
|
|
682
|
+
- A style garbage collector removes unused styles/chunks over time.
|
|
683
|
+
- A dedicated style injector minimizes DOM/style-tag overhead.
|
|
684
|
+
- This approach is validated in enterprise-scale apps where runtime styling overhead is not noticeable in normal UI flows.
|
|
428
685
|
|
|
429
686
|
## Ecosystem
|
|
430
687
|
|
|
@@ -432,7 +689,7 @@ Tasty is the core of a production-ready styling platform. These companion tools
|
|
|
432
689
|
|
|
433
690
|
### [ESLint Plugin](https://github.com/tenphi/eslint-plugin-tasty)
|
|
434
691
|
|
|
435
|
-
`@tenphi/eslint-plugin-tasty` — 27 lint rules
|
|
692
|
+
`@tenphi/eslint-plugin-tasty` — 27 total lint rules for style property names, value syntax, token existence, state keys, and best practices. The `recommended` preset enables 18 of them as a practical default. Catch typos and invalid styles at lint time, not at runtime.
|
|
436
693
|
|
|
437
694
|
```bash
|
|
438
695
|
pnpm add -D @tenphi/eslint-plugin-tasty
|
|
@@ -467,18 +724,62 @@ Syntax highlighting for Tasty styles in TypeScript, TSX, JavaScript, and JSX. Hi
|
|
|
467
724
|
<img src="assets/tasty-vscode-highlight.png" width="512" alt="Tasty VS Code syntax highlighting example">
|
|
468
725
|
</p>
|
|
469
726
|
|
|
470
|
-
|
|
727
|
+
## Built with Tasty
|
|
728
|
+
|
|
729
|
+
### [tasty.style](https://tasty.style) ([source](https://github.com/tenphi/tasty.style))
|
|
730
|
+
|
|
731
|
+
The official Tasty documentation and landing page — itself built entirely with Tasty. A showcase for zero-runtime styling via `tastyStatic`, SSR with Next.js, and OKHSL color theming with Glaze.
|
|
732
|
+
|
|
733
|
+
### [Cube Cloud](https://cube.dev/)
|
|
734
|
+
|
|
735
|
+
Enterprise universal semantic layer platform by Cube Dev, Inc. Cube Cloud unifies data modeling, caching, access control, and APIs (REST, GraphQL, SQL, AI) for analytics at scale. Tasty has powered its frontend for over 5 years in production.
|
|
736
|
+
|
|
737
|
+
### [Cube Cloud for Excel and Google Sheets](https://cube.dev/)
|
|
738
|
+
|
|
739
|
+
A single spreadsheet add-in deployed to both [Microsoft Excel](https://marketplace.microsoft.com/en-us/product/office/WA200008486) and [Google Sheets](https://workspace.google.com/u/0/marketplace/app/cube_cloud_for_sheets/641460343379). Connects spreadsheets to any cloud data platform (BigQuery, Databricks, Snowflake, Redshift, and more) via Cube Cloud's universal semantic layer.
|
|
740
|
+
|
|
741
|
+
### [Cube UI Kit](https://github.com/cube-js/cube-ui-kit) ([storybook](https://cube-ui-kit.vercel.app/))
|
|
471
742
|
|
|
472
743
|
Open-source React UI kit built on Tasty + React Aria. 100+ production components proving Tasty works at design-system scale. A reference implementation and a ready-to-use component library.
|
|
473
744
|
|
|
474
745
|
## Documentation
|
|
475
746
|
|
|
476
|
-
|
|
747
|
+
Start from the docs hub if you want the shortest path to the right guide for your role or styling approach.
|
|
748
|
+
|
|
749
|
+
- **[Docs Hub](docs/README.md)** — audience-based navigation across onboarding, design-system authoring, runtime, zero-runtime, runtime SSR integration, debugging, and internals
|
|
750
|
+
|
|
751
|
+
### Start here
|
|
752
|
+
|
|
753
|
+
- **[Getting Started](docs/getting-started.md)** — Installation, first component, optional shared configuration, ESLint plugin setup, editor tooling, and rendering mode decision tree
|
|
754
|
+
- **[Methodology](docs/methodology.md)** — The recommended patterns for structuring Tasty components: root + sub-elements, styleProps, tokens, styles vs style, wrapping and extension
|
|
755
|
+
|
|
756
|
+
### Guides
|
|
757
|
+
|
|
758
|
+
- **[Building a Design System](docs/design-system.md)** — Practical guide to building a DS layer: token vocabulary, state aliases, recipes, primitives, compound components, override contracts
|
|
759
|
+
- **[Adoption Guide](docs/adoption.md)** — Where Tasty sits in the stack, who should adopt it, what you define yourself, and how to introduce it incrementally into an existing design system
|
|
760
|
+
|
|
761
|
+
### Reference
|
|
762
|
+
|
|
763
|
+
- **[Style DSL](docs/dsl.md)** — The Tasty style language: state maps, tokens, units, color syntax, extending semantics, recipes, keyframes, and @property
|
|
764
|
+
- **[Runtime API](docs/runtime.md)** — React-specific API: `tasty()` factory, component props, variants, sub-elements, and hooks
|
|
765
|
+
- **[Configuration](docs/configuration.md)** — Global configuration: tokens, recipes, custom units, style handlers, and TypeScript extensions
|
|
477
766
|
- **[Style Properties](docs/styles.md)** — Complete reference for all enhanced style properties: syntax, values, modifiers, and recommendations
|
|
767
|
+
|
|
768
|
+
### Rendering modes
|
|
769
|
+
|
|
478
770
|
- **[Zero Runtime (tastyStatic)](docs/tasty-static.md)** — Build-time static styling: Babel plugin setup, Next.js integration, and static style patterns
|
|
771
|
+
- **[Server-Side Rendering](docs/ssr.md)** — SSR setup for Next.js, Astro, and generic frameworks: streaming support, cache hydration, and troubleshooting
|
|
772
|
+
|
|
773
|
+
### Internals
|
|
774
|
+
|
|
775
|
+
- **[Style rendering pipeline](docs/PIPELINE.md)** — How `Styles` become mutually exclusive CSS rules: parse → exclusives → combinations → handlers → merge → materialize (`src/pipeline/`)
|
|
479
776
|
- **[Style Injector](docs/injector.md)** — Internal CSS injection engine: `inject()`, `injectGlobal()`, `injectRawCSS()`, `keyframes()`, deduplication, reference counting, cleanup, SSR support, and Shadow DOM
|
|
480
777
|
- **[Debug Utilities](docs/debug.md)** — Runtime CSS inspection via `tastyDebug`: CSS extraction, element inspection, cache metrics, chunk breakdown, and performance monitoring
|
|
481
778
|
|
|
779
|
+
### Context
|
|
780
|
+
|
|
781
|
+
- **[Comparison](docs/comparison.md)** — How Tasty compares to Tailwind, Panda CSS, vanilla-extract, StyleX, Stitches, and Emotion: positioning, trade-offs, and when each tool fits best
|
|
782
|
+
|
|
482
783
|
## License
|
|
483
784
|
|
|
484
785
|
[MIT](LICENSE)
|
package/dist/chunks/cacheKey.js
CHANGED
|
@@ -11,20 +11,29 @@ import { extractLocalPredefinedStates, extractPredefinedStateRefs } from "../sta
|
|
|
11
11
|
* - Global predefined states don't affect cache keys (constant across app)
|
|
12
12
|
* - Local predefined states only affect cache keys if referenced in the chunk
|
|
13
13
|
*/
|
|
14
|
+
const _stableStringifyCache = /* @__PURE__ */ new WeakMap();
|
|
14
15
|
/**
|
|
15
16
|
* Recursively serialize a value with sorted keys for stable output.
|
|
16
17
|
* This ensures that {a: 1, b: 2} and {b: 2, a: 1} produce the same string.
|
|
18
|
+
* Uses a WeakMap cache for object values to avoid re-serializing the same references.
|
|
17
19
|
*/
|
|
18
20
|
function stableStringify(value) {
|
|
19
21
|
if (value === null) return "null";
|
|
20
22
|
if (value === void 0) return "undefined";
|
|
21
23
|
if (typeof value !== "object") return JSON.stringify(value);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const cached = _stableStringifyCache.get(value);
|
|
25
|
+
if (cached !== void 0) return cached;
|
|
26
|
+
let result;
|
|
27
|
+
if (Array.isArray(value)) result = "[" + value.map(stableStringify).join(",") + "]";
|
|
28
|
+
else {
|
|
29
|
+
const obj = value;
|
|
30
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
31
|
+
const parts = [];
|
|
32
|
+
for (const key of sortedKeys) if (obj[key] !== void 0) parts.push(`${JSON.stringify(key)}:${stableStringify(obj[key])}`);
|
|
33
|
+
result = "{" + parts.join(",") + "}";
|
|
34
|
+
}
|
|
35
|
+
_stableStringifyCache.set(value, result);
|
|
36
|
+
return result;
|
|
28
37
|
}
|
|
29
38
|
/**
|
|
30
39
|
* Generate a cache key for a specific chunk.
|
|
@@ -42,9 +51,8 @@ function stableStringify(value) {
|
|
|
42
51
|
*/
|
|
43
52
|
function generateChunkCacheKey(styles, chunkName, styleKeys) {
|
|
44
53
|
const parts = [chunkName];
|
|
45
|
-
const sortedKeys = styleKeys.slice().sort();
|
|
46
54
|
let chunkStylesStr = "";
|
|
47
|
-
for (const key of
|
|
55
|
+
for (const key of styleKeys) {
|
|
48
56
|
const value = styles[key];
|
|
49
57
|
if (value !== void 0) {
|
|
50
58
|
const serialized = stableStringify(value);
|