@tenphi/tasty 0.0.0-snapshot.89ab060 → 0.0.0-snapshot.8c027cf
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 +118 -244
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +1 -2
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.d.ts +1 -1
- package/dist/chunks/definitions.js +2 -3
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +1 -2
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +357 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +63 -20
- package/dist/config.js +85 -48
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +6 -6
- package/dist/core/index.js +7 -7
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.js +1 -2
- package/dist/debug.js.map +1 -1
- package/dist/font-face/index.js +63 -0
- package/dist/font-face/index.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/useCounterStyle.d.ts +50 -0
- package/dist/hooks/useCounterStyle.js +45 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +43 -0
- package/dist/hooks/useFontFace.js +69 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.js +5 -11
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.js +3 -9
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.js +3 -9
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.js +3 -9
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +4 -9
- package/dist/hooks/useStyles.js +7 -227
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.js +10 -8
- package/dist/injector/index.d.ts +41 -19
- package/dist/injector/index.js +49 -19
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +50 -3
- package/dist/injector/injector.js +166 -9
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +9 -13
- package/dist/injector/sheet-manager.js +38 -70
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +110 -19
- package/dist/keyframes/index.js +1 -1
- package/dist/parser/classify.js +4 -5
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/const.js +30 -3
- package/dist/parser/const.js.map +1 -1
- package/dist/parser/lru.js +1 -1
- package/dist/parser/lru.js.map +1 -1
- package/dist/parser/parser.js +1 -2
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/types.js +1 -1
- package/dist/parser/types.js.map +1 -1
- package/dist/pipeline/conditions.js +1 -1
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/exclusive.js +1 -2
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.d.ts +2 -0
- package/dist/pipeline/index.js +58 -20
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +1 -3
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.js +1 -2
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +1 -2
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/pipeline/warnings.js +1 -1
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.js +1 -2
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/properties/index.js +2 -3
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.js +1 -2
- package/dist/properties/property-type-resolver.js.map +1 -1
- package/dist/ssr/astro.js +1 -2
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/async-storage.js +1 -2
- package/dist/ssr/async-storage.js.map +1 -1
- package/dist/ssr/collect-auto-properties.js +1 -2
- package/dist/ssr/collect-auto-properties.js.map +1 -1
- package/dist/ssr/collector.d.ts +17 -0
- package/dist/ssr/collector.js +53 -17
- package/dist/ssr/collector.js.map +1 -1
- package/dist/ssr/format-global-rules.js +1 -1
- package/dist/ssr/format-keyframes.js +1 -2
- package/dist/ssr/format-keyframes.js.map +1 -1
- package/dist/ssr/format-property.js +1 -2
- package/dist/ssr/format-property.js.map +1 -1
- package/dist/ssr/format-rules.js +8 -5
- package/dist/ssr/format-rules.js.map +1 -1
- package/dist/ssr/hydrate.js +1 -2
- package/dist/ssr/hydrate.js.map +1 -1
- package/dist/ssr/index.d.ts +1 -2
- package/dist/ssr/index.js +2 -4
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next.d.ts +1 -3
- package/dist/ssr/next.js +10 -7
- package/dist/ssr/next.js.map +1 -1
- package/dist/ssr/ssr-collector-ref.js +1 -1
- package/dist/states/index.js +3 -2
- package/dist/states/index.js.map +1 -1
- package/dist/static/index.js +1 -2
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/static/tastyStatic.js +1 -2
- package/dist/static/tastyStatic.js.map +1 -1
- package/dist/static/types.js +1 -1
- package/dist/styles/border.d.ts +1 -1
- package/dist/styles/border.js +30 -24
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +1 -1
- package/dist/styles/color.js +2 -3
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +4 -5
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/dimension.js +15 -3
- package/dist/styles/dimension.js.map +1 -1
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +3 -10
- package/dist/styles/display.js +45 -39
- package/dist/styles/display.js.map +1 -1
- package/dist/styles/fade.d.ts +1 -1
- package/dist/styles/fade.js +9 -5
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +2 -2
- package/dist/styles/fill.js +3 -4
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.js +1 -1
- package/dist/styles/gap.d.ts +1 -1
- package/dist/styles/gap.js +4 -3
- package/dist/styles/gap.js.map +1 -1
- package/dist/styles/height.d.ts +1 -1
- package/dist/styles/height.js +1 -2
- package/dist/styles/height.js.map +1 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +3 -4
- package/dist/styles/index.js.map +1 -1
- package/dist/styles/inset.d.ts +1 -29
- package/dist/styles/inset.js +19 -135
- package/dist/styles/inset.js.map +1 -1
- package/dist/styles/list.d.ts +5 -5
- package/dist/styles/list.js +4 -2
- package/dist/styles/list.js.map +1 -1
- package/dist/styles/margin.d.ts +1 -1
- package/dist/styles/margin.js +17 -89
- package/dist/styles/margin.js.map +1 -1
- package/dist/styles/outline.d.ts +1 -1
- package/dist/styles/outline.js +6 -16
- package/dist/styles/outline.js.map +1 -1
- package/dist/styles/padding.d.ts +1 -1
- package/dist/styles/padding.js +17 -89
- package/dist/styles/padding.js.map +1 -1
- package/dist/styles/placement.d.ts +37 -0
- package/dist/styles/placement.js +74 -0
- package/dist/styles/placement.js.map +1 -0
- package/dist/styles/predefined.d.ts +4 -4
- package/dist/styles/predefined.js +8 -9
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.d.ts +6 -1
- package/dist/styles/preset.js +54 -53
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/radius.d.ts +1 -3
- package/dist/styles/radius.js +38 -6
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollMargin.d.ts +24 -0
- package/dist/styles/scrollMargin.js +32 -0
- package/dist/styles/scrollMargin.js.map +1 -0
- package/dist/styles/scrollbar.d.ts +1 -1
- package/dist/styles/scrollbar.js +8 -5
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +1 -1
- package/dist/styles/shadow.js +4 -3
- package/dist/styles/shadow.js.map +1 -1
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +1 -1
- package/dist/styles/transition.js +5 -4
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +70 -14
- package/dist/styles/width.d.ts +1 -1
- package/dist/styles/width.js +1 -2
- package/dist/styles/width.js.map +1 -1
- package/dist/tasty.d.ts +46 -893
- package/dist/tasty.js +91 -67
- package/dist/tasty.js.map +1 -1
- package/dist/utils/cache-wrapper.js +1 -2
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/case-converter.js +1 -1
- package/dist/utils/color-math.js +1 -1
- package/dist/utils/color-math.js.map +1 -1
- package/dist/utils/color-space.js +1 -2
- package/dist/utils/color-space.js.map +1 -1
- package/dist/utils/colors.js +1 -2
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/dotize.js +1 -1
- package/dist/utils/dotize.js.map +1 -1
- package/dist/utils/filter-base-props.d.ts +1 -1
- package/dist/utils/filter-base-props.js +1 -1
- package/dist/utils/filter-base-props.js.map +1 -1
- package/dist/utils/get-display-name.js +1 -1
- package/dist/utils/has-keys.js +1 -1
- package/dist/utils/is-dev-env.js +1 -1
- package/dist/utils/is-dev-env.js.map +1 -1
- package/dist/utils/is-valid-element-type.js +1 -1
- package/dist/utils/merge-styles.js +1 -2
- package/dist/utils/merge-styles.js.map +1 -1
- package/dist/utils/mod-attrs.d.ts +0 -2
- package/dist/utils/mod-attrs.js +1 -2
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +1 -5
- package/dist/utils/process-tokens.js +3 -11
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/resolve-recipes.js +1 -2
- package/dist/utils/resolve-recipes.js.map +1 -1
- package/dist/utils/selector-transform.js +1 -1
- package/dist/utils/string.js +1 -1
- package/dist/utils/styles.d.ts +1 -3
- package/dist/utils/styles.js +2 -5
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.js +9 -1
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +31 -4
- package/dist/zero/babel.js +140 -48
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/css-writer.js +1 -2
- package/dist/zero/css-writer.js.map +1 -1
- package/dist/zero/extractor.js +54 -3
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/index.js +1 -2
- package/dist/zero/next.d.ts +12 -0
- package/dist/zero/next.js +5 -4
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +5 -4
- package/docs/adoption.md +6 -4
- package/docs/comparison.md +9 -7
- package/docs/configuration.md +61 -0
- package/docs/design-system.md +26 -3
- package/docs/dsl.md +133 -2
- package/docs/getting-started.md +11 -9
- package/docs/injector.md +33 -18
- package/docs/methodology.md +121 -6
- package/docs/runtime.md +255 -24
- package/docs/ssr.md +22 -50
- package/docs/styles.md +45 -23
- package/docs/tasty-static.md +89 -0
- package/package.json +13 -8
- package/dist/ssr/context.d.ts +0 -8
- package/dist/ssr/context.js +0 -14
- package/dist/ssr/context.js.map +0 -1
- package/dist/styles/align.d.ts +0 -15
- package/dist/styles/align.js +0 -14
- package/dist/styles/align.js.map +0 -1
- package/dist/styles/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.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,23 +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
|
-
- **Runtime
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
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 and mod props** — `styleProps` exposes selected CSS properties as typed React props (`<Space flow="row" gap="2x">`); `modProps` does the same for modifier keys (`<Button isLoading size="large">`). Both support state maps and full TypeScript autocomplete. See [Style Props](#style-props) and [Mod Props](#mod-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).
|
|
37
55
|
|
|
38
56
|
## Installation
|
|
39
57
|
|
|
@@ -56,20 +74,15 @@ yarn add @tenphi/tasty
|
|
|
56
74
|
|
|
57
75
|
## Start Here
|
|
58
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
|
|
59
81
|
- **[Getting Started](docs/getting-started.md)** — the canonical onboarding path: install, first component, optional shared `configure()`, ESLint, editor tooling, and rendering mode selection
|
|
60
|
-
- **[
|
|
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
|
|
61
84
|
- **[Methodology](docs/methodology.md)** — the recommended component model and public API conventions for design-system code
|
|
62
85
|
|
|
63
|
-
## Choose a Rendering Mode
|
|
64
|
-
|
|
65
|
-
| Mode | Entry point | Best for | Trade-off |
|
|
66
|
-
|------|-------------|----------|-----------|
|
|
67
|
-
| **Runtime** | `@tenphi/tasty` | Interactive apps and design systems | Full feature set; CSS is generated on demand at runtime |
|
|
68
|
-
| **Zero-runtime** | `@tenphi/tasty/static` | Static sites, SSG, landing pages | Requires the Babel plugin; no component-level `styleProps` or runtime-only APIs |
|
|
69
|
-
| **SSR** | `@tenphi/tasty/ssr/*` | Next.js, Astro, and other streaming React SSR setups | Uses runtime `tasty()` with server-collected CSS and hydration cache transfer |
|
|
70
|
-
|
|
71
|
-
All three share the same DSL, tokens, units, and state mappings. See [Getting Started](docs/getting-started.md#choosing-a-rendering-mode), [Zero Runtime](docs/tasty-static.md), and [Server-Side Rendering](docs/ssr.md).
|
|
72
|
-
|
|
73
86
|
## Quick Start
|
|
74
87
|
|
|
75
88
|
### Create a styled component
|
|
@@ -82,12 +95,12 @@ const Card = tasty({
|
|
|
82
95
|
styles: {
|
|
83
96
|
display: 'flex',
|
|
84
97
|
flow: 'column',
|
|
85
|
-
padding: '
|
|
86
|
-
gap: '
|
|
87
|
-
fill: '
|
|
88
|
-
color: '
|
|
89
|
-
border: '
|
|
90
|
-
radius: '
|
|
98
|
+
padding: '24px',
|
|
99
|
+
gap: '12px',
|
|
100
|
+
fill: 'white',
|
|
101
|
+
color: '#222',
|
|
102
|
+
border: '1px solid #ddd',
|
|
103
|
+
radius: '12px',
|
|
91
104
|
},
|
|
92
105
|
});
|
|
93
106
|
|
|
@@ -95,7 +108,9 @@ const Card = tasty({
|
|
|
95
108
|
<Card>Hello World</Card>
|
|
96
109
|
```
|
|
97
110
|
|
|
98
|
-
Every value maps to CSS you'd recognize. This example is intentionally
|
|
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.
|
|
99
114
|
|
|
100
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).
|
|
101
116
|
|
|
@@ -163,58 +178,28 @@ configure({
|
|
|
163
178
|
|
|
164
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.
|
|
165
180
|
|
|
166
|
-
###
|
|
167
|
-
|
|
168
|
-
With `styleProps`, a component can expose the styles you choose as normal typed props. That means you can adjust layout, spacing, alignment, or positioning right where the component is used, instead of introducing wrapper elements or reaching for a separate styling API.
|
|
169
|
-
|
|
170
|
-
This is especially good for prototyping and fast UI iteration: you can shape interfaces quickly, while still staying inside a typed, design-system-aware component API that scales to production.
|
|
171
|
-
|
|
172
|
-
```tsx
|
|
173
|
-
import { tasty, FLOW_STYLES, POSITION_STYLES } from '@tenphi/tasty';
|
|
174
|
-
|
|
175
|
-
const Space = tasty({
|
|
176
|
-
styles: {
|
|
177
|
-
display: 'flex',
|
|
178
|
-
flow: 'column',
|
|
179
|
-
gap: '1x',
|
|
180
|
-
},
|
|
181
|
-
styleProps: FLOW_STYLES,
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
const Button = tasty({
|
|
185
|
-
as: 'button',
|
|
186
|
-
styles: {
|
|
187
|
-
padding: '1.5x 3x',
|
|
188
|
-
fill: '#primary',
|
|
189
|
-
color: '#primary-text',
|
|
190
|
-
radius: true,
|
|
191
|
-
},
|
|
192
|
-
styleProps: POSITION_STYLES,
|
|
193
|
-
});
|
|
194
|
-
```
|
|
181
|
+
### Props as the public API
|
|
195
182
|
|
|
196
|
-
|
|
183
|
+
`styleProps` exposes selected CSS properties as typed React props, and `modProps` does the same for modifier keys. Together they let design systems define a governed, typed component API without wrapper elements or `styles` overrides:
|
|
197
184
|
|
|
198
185
|
```tsx
|
|
199
186
|
<Space flow="row" gap="2x" placeItems="center">
|
|
200
|
-
<
|
|
201
|
-
<Button placeSelf="end">Add Item</Button>
|
|
187
|
+
<Button isLoading size="large" placeSelf="end">Submit</Button>
|
|
202
188
|
</Space>
|
|
203
189
|
```
|
|
204
190
|
|
|
205
|
-
|
|
191
|
+
See [Style Props](#style-props) and [Mod Props](#mod-props) below, or the full reference in [Runtime API](docs/runtime.md#style-props).
|
|
206
192
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
```
|
|
193
|
+
## Choose a Styling Approach
|
|
194
|
+
|
|
195
|
+
Once you understand the component model, pick the rendering mode that matches your app.
|
|
196
|
+
|
|
197
|
+
| Approach | Entry point | Best for | Trade-off |
|
|
198
|
+
|----------|-------------|----------|-----------|
|
|
199
|
+
| **Runtime** | `@tenphi/tasty` | Interactive apps with reusable stateful components and design systems | Full feature set; CSS is generated on demand at runtime |
|
|
200
|
+
| **Zero-runtime** | `@tenphi/tasty/static` | Static sites, SSG, landing pages | Requires the Babel plugin; no component-level `styleProps` or runtime-only APIs |
|
|
216
201
|
|
|
217
|
-
|
|
202
|
+
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).
|
|
218
203
|
|
|
219
204
|
## How It Actually Works
|
|
220
205
|
|
|
@@ -222,7 +207,7 @@ This is the core idea that makes everything else possible.
|
|
|
222
207
|
|
|
223
208
|
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)**.
|
|
224
209
|
|
|
225
|
-
|
|
210
|
+
### The structural problem with normal CSS
|
|
226
211
|
|
|
227
212
|
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.
|
|
228
213
|
|
|
@@ -235,7 +220,11 @@ A small example makes this tangible. Two rules for a button's background:
|
|
|
235
220
|
|
|
236
221
|
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.
|
|
237
222
|
|
|
238
|
-
|
|
223
|
+
### Why real state logic is hard to author by hand
|
|
224
|
+
|
|
225
|
+
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.
|
|
226
|
+
|
|
227
|
+
### What Tasty generates instead
|
|
239
228
|
|
|
240
229
|
Tasty solves both problems at once: **every state mapping compiles into mutually exclusive selectors.**
|
|
241
230
|
|
|
@@ -280,8 +269,6 @@ Better — but the bare `.t0` default still matches unconditionally. It matches
|
|
|
280
269
|
|
|
281
270
|
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:
|
|
282
271
|
|
|
283
|
-
Tasty generates the correct version automatically:
|
|
284
|
-
|
|
285
272
|
```css
|
|
286
273
|
/* Branch 1: Explicit dark schema */
|
|
287
274
|
:root[data-schema="dark"] .t0.t0 {
|
|
@@ -308,11 +295,13 @@ Tasty generates the correct version automatically:
|
|
|
308
295
|
}
|
|
309
296
|
```
|
|
310
297
|
|
|
298
|
+
### What guarantee that gives you
|
|
299
|
+
|
|
311
300
|
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.
|
|
312
301
|
|
|
313
|
-
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
|
|
302
|
+
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.
|
|
314
303
|
|
|
315
|
-
[Try it in the
|
|
304
|
+
[Try it in the playground →](https://tasty.style/playground)
|
|
316
305
|
|
|
317
306
|
## Capabilities
|
|
318
307
|
|
|
@@ -370,214 +359,99 @@ fill: {
|
|
|
370
359
|
|
|
371
360
|
### Sub-Element Styling
|
|
372
361
|
|
|
373
|
-
|
|
362
|
+
Compound components can style inner parts from the parent definition with capitalized keys in `styles` and optional `elements` declarations, producing typed sub-components like `<Card.Title />` instead of separate wrapper components or ad hoc class naming.
|
|
374
363
|
|
|
375
|
-
|
|
376
|
-
const Card = tasty({
|
|
377
|
-
styles: {
|
|
378
|
-
padding: '4x',
|
|
379
|
-
Title: { preset: 'h3', color: '#primary' },
|
|
380
|
-
Content: { color: '#text', preset: 't2' },
|
|
381
|
-
},
|
|
382
|
-
elements: { Title: 'h2', Content: 'div' },
|
|
383
|
-
});
|
|
364
|
+
Sub-elements share the root state context by default, so keys like `:hover`, modifiers, root states, and media queries resolve as one coordinated styling block. Use `@own(...)` when a sub-element should react to its own state, and use the `$` selector affix when you need precise descendant targeting.
|
|
384
365
|
|
|
385
|
-
|
|
386
|
-
<Card.Title>Heading</Card.Title>
|
|
387
|
-
<Card.Content>Body text</Card.Content>
|
|
388
|
-
</Card>
|
|
389
|
-
```
|
|
366
|
+
See [Runtime API - Sub-element Styling](docs/runtime.md#sub-element-styling), [Style DSL - Advanced States](docs/dsl.md#advanced-states--prefix), and [Methodology](docs/methodology.md#component-architecture-root--sub-elements).
|
|
390
367
|
|
|
391
|
-
|
|
368
|
+
### Style Props
|
|
392
369
|
|
|
393
|
-
|
|
370
|
+
`styleProps` exposes selected CSS properties as typed React props. Components control which properties to open up; consumers get layout and composition knobs without `styles` overrides. Supports state maps for responsive values.
|
|
394
371
|
|
|
395
|
-
|
|
372
|
+
```tsx
|
|
373
|
+
const Space = tasty({
|
|
374
|
+
styles: { display: 'flex', flow: 'column', gap: '1x' },
|
|
375
|
+
styleProps: FLOW_STYLES,
|
|
376
|
+
});
|
|
396
377
|
|
|
397
|
-
|
|
378
|
+
<Space flow="row" gap={{ '': '2x', '@tablet': '4x' }}>
|
|
379
|
+
```
|
|
398
380
|
|
|
399
|
-
|
|
381
|
+
See [Runtime API - Style Props](docs/runtime.md#style-props) and [Methodology - styleProps](docs/methodology.md#styleprops-as-the-public-api).
|
|
400
382
|
|
|
401
|
-
###
|
|
383
|
+
### Mod Props
|
|
402
384
|
|
|
403
|
-
|
|
385
|
+
`modProps` exposes modifier keys as typed React props — the modifier equivalent of `styleProps`. Accepts an array of key names or an object with type descriptors (`Boolean`, `String`, `Number`, or enum arrays) for full TypeScript autocomplete.
|
|
404
386
|
|
|
405
387
|
```tsx
|
|
406
388
|
const Button = tasty({
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
389
|
+
as: 'button',
|
|
390
|
+
modProps: { isLoading: Boolean, size: ['sm', 'md', 'lg'] as const },
|
|
391
|
+
styles: {
|
|
392
|
+
fill: { '': '#primary', isLoading: '#primary.5' },
|
|
393
|
+
padding: { '': '2x 4x', 'size=sm': '1x 2x' },
|
|
412
394
|
},
|
|
413
395
|
});
|
|
414
396
|
|
|
415
|
-
<Button
|
|
397
|
+
<Button isLoading size="lg">Submit</Button>
|
|
416
398
|
```
|
|
417
399
|
|
|
418
|
-
|
|
400
|
+
See [Runtime API - Mod Props](docs/runtime.md#mod-props) and [Methodology - modProps](docs/methodology.md#modprops-and-mods).
|
|
419
401
|
|
|
420
|
-
|
|
402
|
+
### Variants
|
|
421
403
|
|
|
422
|
-
|
|
423
|
-
configure({
|
|
424
|
-
recipes: {
|
|
425
|
-
card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
|
|
426
|
-
elevated: { shadow: '0 2x 4x #shadow' },
|
|
427
|
-
},
|
|
428
|
-
});
|
|
404
|
+
Variants let one component expose named visual versions without pre-generating a separate class for every possible combination. In runtime mode, Tasty emits only the variant CSS that is actually used.
|
|
429
405
|
|
|
430
|
-
|
|
431
|
-
styles: {
|
|
432
|
-
recipe: 'card elevated',
|
|
433
|
-
color: '#text',
|
|
434
|
-
},
|
|
435
|
-
});
|
|
436
|
-
```
|
|
406
|
+
See [Runtime API - Variants](docs/runtime.md#variants).
|
|
437
407
|
|
|
438
|
-
|
|
408
|
+
### Recipes
|
|
439
409
|
|
|
440
|
-
|
|
410
|
+
Recipes are reusable style bundles defined in `configure({ recipes })` and applied with the `recipe` style property. They are useful when your design system wants shared state logic or visual presets without forcing every component to repeat the same style map.
|
|
441
411
|
|
|
442
|
-
|
|
412
|
+
Use `/` to post-apply recipes after local styles when recipe states should win the final merge order, and use `none` to skip base recipes entirely.
|
|
443
413
|
|
|
444
|
-
|
|
414
|
+
See [Style DSL - Recipes](docs/dsl.md#recipes) and [Configuration - recipes](docs/configuration.md#recipes).
|
|
445
415
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
animation: 'pulse 2s infinite',
|
|
450
|
-
transform: 'scale($pulse-scale)',
|
|
451
|
-
'@keyframes': {
|
|
452
|
-
pulse: {
|
|
453
|
-
'0%, 100%': { '$pulse-scale': 1 },
|
|
454
|
-
'50%': { '$pulse-scale': 1.05 },
|
|
455
|
-
},
|
|
456
|
-
},
|
|
457
|
-
},
|
|
458
|
-
});
|
|
459
|
-
```
|
|
416
|
+
### Auto-Inferred `@property`
|
|
417
|
+
|
|
418
|
+
Tasty usually removes the need to hand-author CSS [`@property`](https://developer.mozilla.org/en-US/docs/Web/CSS/@property) rules. When a custom property receives a concrete value, Tasty infers its syntax and registers the matching `@property` automatically, which makes transitions and animations on custom properties work without extra boilerplate.
|
|
460
419
|
|
|
461
|
-
|
|
420
|
+
If you prefer explicit control, disable inference with `configure({ autoPropertyTypes: false })` or declare the properties yourself.
|
|
462
421
|
|
|
463
|
-
|
|
422
|
+
See [Style DSL - Properties (`@property`)](docs/dsl.md#properties-property).
|
|
464
423
|
|
|
465
424
|
### Explicit `@properties`
|
|
466
425
|
|
|
467
|
-
|
|
426
|
+
Use explicit `@properties` only when you need to override defaults such as `inherits: false` or a custom `initialValue`.
|
|
468
427
|
|
|
469
|
-
|
|
470
|
-
'@properties': {
|
|
471
|
-
'$pulse-scale': { syntax: '<number>', inherits: false, initialValue: 1 },
|
|
472
|
-
},
|
|
473
|
-
```
|
|
428
|
+
See [Style DSL - Properties (`@property`)](docs/dsl.md#properties-property).
|
|
474
429
|
|
|
475
430
|
### React Hooks
|
|
476
431
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
```tsx
|
|
480
|
-
import { useStyles, useGlobalStyles, useRawCSS } from '@tenphi/tasty';
|
|
432
|
+
When you do not need a full component wrapper, use the hooks directly: `useStyles` for local class names, `useGlobalStyles` for selector-scoped global CSS, `useRawCSS` for raw rules, plus `useKeyframes` and `useProperty` for animation and custom-property primitives.
|
|
481
433
|
|
|
482
|
-
|
|
483
|
-
const { className } = useStyles({ padding: '2x', fill: '#surface' });
|
|
484
|
-
useGlobalStyles('body', { margin: '0' });
|
|
485
|
-
useRawCSS('@font-face { font-family: "Custom"; src: url(...); }');
|
|
486
|
-
|
|
487
|
-
return <main className={className}>...</main>;
|
|
488
|
-
}
|
|
489
|
-
```
|
|
434
|
+
See [Runtime API - Hooks](docs/runtime.md#hooks).
|
|
490
435
|
|
|
491
436
|
### Zero-Runtime Mode
|
|
492
437
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
```tsx
|
|
496
|
-
import { tastyStatic } from '@tenphi/tasty/static';
|
|
497
|
-
|
|
498
|
-
const card = tastyStatic({
|
|
499
|
-
padding: '4x',
|
|
500
|
-
fill: '#surface',
|
|
501
|
-
radius: '1r',
|
|
502
|
-
color: { '': '#text', '@dark': '#text-on-dark' },
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
// card is a CSS class name string
|
|
506
|
-
<div className={card}>Static styles, zero runtime</div>
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
Configure the Babel plugin:
|
|
438
|
+
Use `tastyStatic` when you want the same DSL and state model, but with CSS extracted at build time and no styling runtime in the client bundle. It is a strong fit for static sites, landing pages, and other build-time-first setups.
|
|
510
439
|
|
|
511
|
-
|
|
512
|
-
module.exports = {
|
|
513
|
-
plugins: [
|
|
514
|
-
['@tenphi/tasty/babel-plugin', {
|
|
515
|
-
output: 'public/tasty.css',
|
|
516
|
-
config: {
|
|
517
|
-
states: { '@dark': '@root(schema=dark)' },
|
|
518
|
-
},
|
|
519
|
-
}],
|
|
520
|
-
],
|
|
521
|
-
};
|
|
522
|
-
```
|
|
440
|
+
See [Zero Runtime (tastyStatic)](docs/tasty-static.md) and [Getting Started - Choosing a rendering mode](docs/getting-started.md#choosing-a-rendering-mode).
|
|
523
441
|
|
|
524
442
|
### `tasty` vs `tastyStatic`
|
|
525
443
|
|
|
526
|
-
|
|
527
|
-
|---|---|---|
|
|
528
|
-
| **Output** | React component | CSS class name |
|
|
529
|
-
| **CSS injection** | Runtime `<style>` tags | Build-time extraction |
|
|
530
|
-
| **Runtime cost** | Style generation on mount | None |
|
|
531
|
-
| **Generated CSS scope** | Only styles/variants used at runtime | All extracted static styles at build time |
|
|
532
|
-
| **Dynamic values** | Fully supported | Via CSS custom properties |
|
|
533
|
-
| **Sub-elements** | Built-in (`<C.Title>`) | Manual (`data-element`) |
|
|
534
|
-
| **Variants** | Built-in (`variants` option) | Separate static styles |
|
|
535
|
-
| **Framework** | React | Any (requires Babel) |
|
|
536
|
-
| **Best for** | Interactive apps, design systems | Static sites, SSG, landing pages |
|
|
444
|
+
`tasty()` returns React components and injects CSS on demand at runtime. `tastyStatic()` returns class names and extracts CSS during the build. Both share the same DSL, tokens, units, state mappings, and recipes, so the main choice is runtime flexibility versus build-time extraction.
|
|
537
445
|
|
|
538
|
-
|
|
446
|
+
See [Zero Runtime (tastyStatic)](docs/tasty-static.md), [Runtime API](docs/runtime.md), and [Comparison - Build-time vs runtime](docs/comparison.md#build-time-vs-runtime).
|
|
539
447
|
|
|
540
448
|
### Server-Side Rendering
|
|
541
449
|
|
|
542
|
-
SSR
|
|
543
|
-
|
|
544
|
-
**Next.js setup:**
|
|
545
|
-
|
|
546
|
-
```tsx
|
|
547
|
-
// app/tasty-registry.tsx
|
|
548
|
-
'use client';
|
|
549
|
-
|
|
550
|
-
import { TastyRegistry } from '@tenphi/tasty/ssr/next';
|
|
450
|
+
SSR layers on top of runtime `tasty()` rather than introducing a separate styling model. Existing components stay unchanged while Tasty collects CSS during server rendering and hydrates the cache on the client.
|
|
551
451
|
|
|
552
|
-
|
|
553
|
-
children,
|
|
554
|
-
}: {
|
|
555
|
-
children: React.ReactNode;
|
|
556
|
-
}) {
|
|
557
|
-
return <TastyRegistry>{children}</TastyRegistry>;
|
|
558
|
-
}
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
```tsx
|
|
562
|
-
// app/layout.tsx
|
|
563
|
-
import TastyStyleRegistry from './tasty-registry';
|
|
564
|
-
|
|
565
|
-
export default function RootLayout({
|
|
566
|
-
children,
|
|
567
|
-
}: {
|
|
568
|
-
children: React.ReactNode;
|
|
569
|
-
}) {
|
|
570
|
-
return (
|
|
571
|
-
<html>
|
|
572
|
-
<body>
|
|
573
|
-
<TastyStyleRegistry>{children}</TastyStyleRegistry>
|
|
574
|
-
</body>
|
|
575
|
-
</html>
|
|
576
|
-
);
|
|
577
|
-
}
|
|
578
|
-
```
|
|
452
|
+
Use `@tenphi/tasty/ssr/next` for Next.js App Router, `@tenphi/tasty/ssr/astro` for Astro, or the core SSR API for other React SSR setups.
|
|
579
453
|
|
|
580
|
-
See the [full SSR guide](docs/ssr.md)
|
|
454
|
+
See the [full SSR guide](docs/ssr.md).
|
|
581
455
|
|
|
582
456
|
## Entry Points
|
|
583
457
|
|
|
@@ -714,9 +588,9 @@ Open-source React UI kit built on Tasty + React Aria. 100+ production components
|
|
|
714
588
|
|
|
715
589
|
## Documentation
|
|
716
590
|
|
|
717
|
-
Start from the docs hub if you want the shortest path to the right guide for your role or
|
|
591
|
+
Start from the docs hub if you want the shortest path to the right guide for your role or styling approach.
|
|
718
592
|
|
|
719
|
-
- **[Docs Hub](docs/README.md)** — audience-based navigation across onboarding, design-system authoring, runtime, zero-runtime, SSR, debugging, and internals
|
|
593
|
+
- **[Docs Hub](docs/README.md)** — audience-based navigation across onboarding, design-system authoring, runtime, zero-runtime, runtime SSR integration, debugging, and internals
|
|
720
594
|
|
|
721
595
|
### Start here
|
|
722
596
|
|
|
@@ -3,6 +3,5 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
3
3
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
4
4
|
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
//#endregion
|
|
8
|
-
export { __require };
|
|
7
|
+
export { __require };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/chunks/cacheKey.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { extractLocalPredefinedStates, extractPredefinedStateRefs } from "../states/index.js";
|
|
2
|
-
|
|
3
2
|
//#region src/chunks/cacheKey.ts
|
|
4
3
|
/**
|
|
5
4
|
* Chunk-specific cache key generation.
|
|
@@ -72,7 +71,7 @@ function generateChunkCacheKey(styles, chunkName, styleKeys) {
|
|
|
72
71
|
}
|
|
73
72
|
return parts.join("\0");
|
|
74
73
|
}
|
|
75
|
-
|
|
76
74
|
//#endregion
|
|
77
75
|
export { generateChunkCacheKey };
|
|
76
|
+
|
|
78
77
|
//# sourceMappingURL=cacheKey.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cacheKey.js","names":[],"sources":["../../src/chunks/cacheKey.ts"],"sourcesContent":["/**\n * Chunk-specific cache key generation.\n *\n * Generates cache keys that only include styles relevant to a specific chunk,\n * enabling more granular caching and reuse.\n *\n * Enhanced to support predefined states:\n * - Global predefined states don't affect cache keys (constant across app)\n * - Local predefined states only affect cache keys if referenced in the chunk\n */\n\nimport {\n extractLocalPredefinedStates,\n extractPredefinedStateRefs,\n} from '../states';\nimport type { Styles } from '../styles/types';\n\nconst _stableStringifyCache = new WeakMap<object, string>();\n\n/**\n * Recursively serialize a value with sorted keys for stable output.\n * This ensures that {a: 1, b: 2} and {b: 2, a: 1} produce the same string.\n * Uses a WeakMap cache for object values to avoid re-serializing the same references.\n */\nfunction stableStringify(value: unknown): string {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return 'undefined';\n }\n if (typeof value !== 'object') {\n return JSON.stringify(value);\n }\n\n const cached = _stableStringifyCache.get(value as object);\n if (cached !== undefined) return cached;\n\n let result: string;\n if (Array.isArray(value)) {\n result = '[' + value.map(stableStringify).join(',') + ']';\n } else {\n const obj = value as Record<string, unknown>;\n const sortedKeys = Object.keys(obj).sort();\n const parts: string[] = [];\n for (const key of sortedKeys) {\n if (obj[key] !== undefined) {\n parts.push(`${JSON.stringify(key)}:${stableStringify(obj[key])}`);\n }\n }\n result = '{' + parts.join(',') + '}';\n }\n\n _stableStringifyCache.set(value as object, result);\n return result;\n}\n\n/**\n * Generate a cache key for a specific chunk.\n *\n * Only includes the styles that belong to this chunk, allowing\n * chunks to be cached independently.\n *\n * Also includes relevant local predefined states that are referenced\n * by this chunk's styles.\n *\n * @param styles - The full styles object\n * @param chunkName - Name of the chunk\n * @param styleKeys - Keys of styles belonging to this chunk\n * @returns A stable cache key string\n */\nexport function generateChunkCacheKey(\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): string {\n // Start with chunk name for namespace separation\n const parts: string[] = [chunkName];\n\n // styleKeys are already sorted by categorizeStyleKeys\n let chunkStylesStr = '';\n\n for (const key of styleKeys) {\n const value = styles[key];\n if (value !== undefined) {\n // Use stable stringify for consistent serialization regardless of key order\n const serialized = stableStringify(value);\n parts.push(`${key}:${serialized}`);\n chunkStylesStr += serialized;\n }\n }\n\n // Extract local predefined states from the full styles object\n const localStates = extractLocalPredefinedStates(styles);\n\n // Only include local predefined states that are actually referenced in this chunk\n if (Object.keys(localStates).length > 0) {\n const referencedStates = extractPredefinedStateRefs(chunkStylesStr);\n const relevantLocalStates: string[] = [];\n\n for (const stateName of referencedStates) {\n if (localStates[stateName]) {\n relevantLocalStates.push(`${stateName}=${localStates[stateName]}`);\n }\n }\n\n // Add relevant local states to the cache key (sorted for stability)\n if (relevantLocalStates.length > 0) {\n relevantLocalStates.sort();\n parts.unshift(`[states:${relevantLocalStates.join('|')}]`);\n }\n }\n\n // Use null character as separator (safe, not in JSON output)\n return parts.join('\\0');\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"cacheKey.js","names":[],"sources":["../../src/chunks/cacheKey.ts"],"sourcesContent":["/**\n * Chunk-specific cache key generation.\n *\n * Generates cache keys that only include styles relevant to a specific chunk,\n * enabling more granular caching and reuse.\n *\n * Enhanced to support predefined states:\n * - Global predefined states don't affect cache keys (constant across app)\n * - Local predefined states only affect cache keys if referenced in the chunk\n */\n\nimport {\n extractLocalPredefinedStates,\n extractPredefinedStateRefs,\n} from '../states';\nimport type { Styles } from '../styles/types';\n\nconst _stableStringifyCache = new WeakMap<object, string>();\n\n/**\n * Recursively serialize a value with sorted keys for stable output.\n * This ensures that {a: 1, b: 2} and {b: 2, a: 1} produce the same string.\n * Uses a WeakMap cache for object values to avoid re-serializing the same references.\n */\nfunction stableStringify(value: unknown): string {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return 'undefined';\n }\n if (typeof value !== 'object') {\n return JSON.stringify(value);\n }\n\n const cached = _stableStringifyCache.get(value as object);\n if (cached !== undefined) return cached;\n\n let result: string;\n if (Array.isArray(value)) {\n result = '[' + value.map(stableStringify).join(',') + ']';\n } else {\n const obj = value as Record<string, unknown>;\n const sortedKeys = Object.keys(obj).sort();\n const parts: string[] = [];\n for (const key of sortedKeys) {\n if (obj[key] !== undefined) {\n parts.push(`${JSON.stringify(key)}:${stableStringify(obj[key])}`);\n }\n }\n result = '{' + parts.join(',') + '}';\n }\n\n _stableStringifyCache.set(value as object, result);\n return result;\n}\n\n/**\n * Generate a cache key for a specific chunk.\n *\n * Only includes the styles that belong to this chunk, allowing\n * chunks to be cached independently.\n *\n * Also includes relevant local predefined states that are referenced\n * by this chunk's styles.\n *\n * @param styles - The full styles object\n * @param chunkName - Name of the chunk\n * @param styleKeys - Keys of styles belonging to this chunk\n * @returns A stable cache key string\n */\nexport function generateChunkCacheKey(\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): string {\n // Start with chunk name for namespace separation\n const parts: string[] = [chunkName];\n\n // styleKeys are already sorted by categorizeStyleKeys\n let chunkStylesStr = '';\n\n for (const key of styleKeys) {\n const value = styles[key];\n if (value !== undefined) {\n // Use stable stringify for consistent serialization regardless of key order\n const serialized = stableStringify(value);\n parts.push(`${key}:${serialized}`);\n chunkStylesStr += serialized;\n }\n }\n\n // Extract local predefined states from the full styles object\n const localStates = extractLocalPredefinedStates(styles);\n\n // Only include local predefined states that are actually referenced in this chunk\n if (Object.keys(localStates).length > 0) {\n const referencedStates = extractPredefinedStateRefs(chunkStylesStr);\n const relevantLocalStates: string[] = [];\n\n for (const stateName of referencedStates) {\n if (localStates[stateName]) {\n relevantLocalStates.push(`${stateName}=${localStates[stateName]}`);\n }\n }\n\n // Add relevant local states to the cache key (sorted for stability)\n if (relevantLocalStates.length > 0) {\n relevantLocalStates.sort();\n parts.unshift(`[states:${relevantLocalStates.join('|')}]`);\n }\n }\n\n // Use null character as separator (safe, not in JSON output)\n return parts.join('\\0');\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAM,wCAAwB,IAAI,SAAyB;;;;;;AAO3D,SAAS,gBAAgB,OAAwB;AAC/C,KAAI,UAAU,KACZ,QAAO;AAET,KAAI,UAAU,KAAA,EACZ,QAAO;AAET,KAAI,OAAO,UAAU,SACnB,QAAO,KAAK,UAAU,MAAM;CAG9B,MAAM,SAAS,sBAAsB,IAAI,MAAgB;AACzD,KAAI,WAAW,KAAA,EAAW,QAAO;CAEjC,IAAI;AACJ,KAAI,MAAM,QAAQ,MAAM,CACtB,UAAS,MAAM,MAAM,IAAI,gBAAgB,CAAC,KAAK,IAAI,GAAG;MACjD;EACL,MAAM,MAAM;EACZ,MAAM,aAAa,OAAO,KAAK,IAAI,CAAC,MAAM;EAC1C,MAAM,QAAkB,EAAE;AAC1B,OAAK,MAAM,OAAO,WAChB,KAAI,IAAI,SAAS,KAAA,EACf,OAAM,KAAK,GAAG,KAAK,UAAU,IAAI,CAAC,GAAG,gBAAgB,IAAI,KAAK,GAAG;AAGrE,WAAS,MAAM,MAAM,KAAK,IAAI,GAAG;;AAGnC,uBAAsB,IAAI,OAAiB,OAAO;AAClD,QAAO;;;;;;;;;;;;;;;;AAiBT,SAAgB,sBACd,QACA,WACA,WACQ;CAER,MAAM,QAAkB,CAAC,UAAU;CAGnC,IAAI,iBAAiB;AAErB,MAAK,MAAM,OAAO,WAAW;EAC3B,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,KAAA,GAAW;GAEvB,MAAM,aAAa,gBAAgB,MAAM;AACzC,SAAM,KAAK,GAAG,IAAI,GAAG,aAAa;AAClC,qBAAkB;;;CAKtB,MAAM,cAAc,6BAA6B,OAAO;AAGxD,KAAI,OAAO,KAAK,YAAY,CAAC,SAAS,GAAG;EACvC,MAAM,mBAAmB,2BAA2B,eAAe;EACnE,MAAM,sBAAgC,EAAE;AAExC,OAAK,MAAM,aAAa,iBACtB,KAAI,YAAY,WACd,qBAAoB,KAAK,GAAG,UAAU,GAAG,YAAY,aAAa;AAKtE,MAAI,oBAAoB,SAAS,GAAG;AAClC,uBAAoB,MAAM;AAC1B,SAAM,QAAQ,WAAW,oBAAoB,KAAK,IAAI,CAAC,GAAG;;;AAK9D,QAAO,MAAM,KAAK,KAAK"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/chunks/definitions.d.ts
|
|
2
2
|
declare const CHUNK_NAMES: {
|
|
3
|
-
/** Special chunk for styles that cannot be split
|
|
3
|
+
/** Special chunk for styles that cannot be split */readonly COMBINED: "combined";
|
|
4
4
|
readonly SUBCOMPONENTS: "subcomponents";
|
|
5
5
|
readonly APPEARANCE: "appearance";
|
|
6
6
|
readonly FONT: "font";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isSelector } from "../pipeline/index.js";
|
|
2
|
-
|
|
3
2
|
//#region src/chunks/definitions.ts
|
|
4
3
|
/**
|
|
5
4
|
* Style chunk definitions for CSS chunking optimization.
|
|
@@ -238,7 +237,7 @@ function categorizeStyleKeys(styles) {
|
|
|
238
237
|
const chunkData = {};
|
|
239
238
|
const keys = Object.keys(styles);
|
|
240
239
|
for (const key of keys) {
|
|
241
|
-
if (key === "$" || key === "@keyframes" || key === "@properties" || key === "recipe") continue;
|
|
240
|
+
if (key === "$" || key === "@keyframes" || key === "@properties" || key === "@fontFace" || key === "@counterStyle" || key === "recipe") continue;
|
|
242
241
|
if (isSelector(key)) {
|
|
243
242
|
if (!chunkData[CHUNK_NAMES.SUBCOMPONENTS]) chunkData[CHUNK_NAMES.SUBCOMPONENTS] = [];
|
|
244
243
|
chunkData[CHUNK_NAMES.SUBCOMPONENTS].push(key);
|
|
@@ -253,7 +252,7 @@ function categorizeStyleKeys(styles) {
|
|
|
253
252
|
for (const chunkName of Object.keys(chunkData)) if (!orderedChunks.has(chunkName)) orderedChunks.set(chunkName, chunkData[chunkName].sort());
|
|
254
253
|
return orderedChunks;
|
|
255
254
|
}
|
|
256
|
-
|
|
257
255
|
//#endregion
|
|
258
256
|
export { CHUNK_NAMES, STYLE_TO_CHUNK, categorizeStyleKeys };
|
|
257
|
+
|
|
259
258
|
//# sourceMappingURL=definitions.js.map
|