@tenphi/tasty 0.0.0-snapshot.2dc73be → 0.0.0-snapshot.2ea241d
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 +298 -250
- package/dist/{ssr/async-storage.js → async-storage-B7_o6FKt.js} +17 -8
- package/dist/async-storage-B7_o6FKt.js.map +1 -0
- package/dist/collector-Crs9kGJW.js +243 -0
- package/dist/collector-Crs9kGJW.js.map +1 -0
- package/dist/{ssr/collector.d.ts → collector-osfWTeRd.d.ts} +38 -15
- package/dist/config-BaxtQMS3.js +10464 -0
- package/dist/config-BaxtQMS3.js.map +1 -0
- package/dist/config-BoZDUHW5.d.ts +945 -0
- package/dist/context-CkSg-kDT.js +24 -0
- package/dist/context-CkSg-kDT.js.map +1 -0
- package/dist/core/index.d.ts +5 -33
- package/dist/core/index.js +6 -26
- package/dist/core-CmxaoZ-N.js +1598 -0
- package/dist/core-CmxaoZ-N.js.map +1 -0
- package/dist/{zero/extractor.js → css-writer-CPy_cbFJ.js} +149 -13
- package/dist/css-writer-CPy_cbFJ.js.map +1 -0
- package/dist/{ssr/format-global-rules.js → format-global-rules-Dbc_1tc3.js} +3 -3
- package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
- package/dist/format-rules-CPirO_Mj.js +143 -0
- package/dist/format-rules-CPirO_Mj.js.map +1 -0
- package/dist/hydrate-CVn-A_3y.js +45 -0
- package/dist/hydrate-CVn-A_3y.js.map +1 -0
- package/dist/index-B_k47mc_.d.ts +1655 -0
- package/dist/index-tcHuMPFt.d.ts +1286 -0
- package/dist/index.d.ts +5 -48
- package/dist/index.js +731 -32
- package/dist/index.js.map +1 -0
- package/dist/keyframes-vpzoVdUR.js +588 -0
- package/dist/keyframes-vpzoVdUR.js.map +1 -0
- package/dist/{utils/merge-styles.d.ts → merge-styles-BMWcH6MF.d.ts} +3 -3
- package/dist/{utils/merge-styles.js → merge-styles-BzQutdAK.js} +4 -6
- package/dist/merge-styles-BzQutdAK.js.map +1 -0
- package/dist/{utils/resolve-recipes.js → resolve-recipes-DgH8A3Nn.js} +5 -8
- package/dist/resolve-recipes-DgH8A3Nn.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +19 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +15 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +78 -10
- package/dist/ssr/astro.js +116 -32
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/index.d.ts +44 -5
- package/dist/ssr/index.js +7 -9
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next.d.ts +7 -6
- package/dist/ssr/next.js +18 -14
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +91 -5
- package/dist/static/index.js +49 -4
- package/dist/static/index.js.map +1 -0
- 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/zero/babel.d.ts +49 -95
- package/dist/zero/babel.js +203 -48
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +67 -3
- package/dist/zero/index.js +2 -4
- package/dist/zero/next.d.ts +28 -1
- package/dist/zero/next.js +70 -15
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +31 -0
- package/docs/adoption.md +298 -0
- package/docs/comparison.md +419 -0
- package/docs/configuration.md +239 -12
- package/docs/debug.md +155 -340
- package/docs/design-system.md +436 -0
- package/docs/dsl.md +690 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +45 -29
- package/docs/methodology.md +642 -0
- package/docs/pipeline.md +699 -0
- package/docs/react-api.md +581 -0
- package/docs/ssr.md +156 -84
- package/docs/styles.md +50 -26
- package/docs/tasty-static.md +194 -23
- package/package.json +30 -14
- package/tasty.config.ts +1 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -8
- package/dist/chunks/cacheKey.js +0 -70
- package/dist/chunks/cacheKey.js.map +0 -1
- package/dist/chunks/definitions.d.ts +0 -37
- package/dist/chunks/definitions.js +0 -259
- package/dist/chunks/definitions.js.map +0 -1
- package/dist/chunks/renderChunk.js +0 -61
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/config.d.ts +0 -288
- package/dist/config.js +0 -417
- package/dist/config.js.map +0 -1
- package/dist/debug.d.ts +0 -204
- package/dist/debug.js +0 -733
- package/dist/debug.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -30
- package/dist/hooks/useGlobalStyles.js +0 -83
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -56
- package/dist/hooks/useKeyframes.js +0 -69
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -79
- package/dist/hooks/useProperty.js +0 -114
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -53
- package/dist/hooks/useRawCSS.js +0 -40
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -45
- package/dist/hooks/useStyles.js +0 -248
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -165
- package/dist/injector/index.js +0 -162
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -148
- package/dist/injector/injector.js +0 -436
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -136
- package/dist/injector/sheet-manager.js +0 -729
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -144
- package/dist/keyframes/index.js +0 -206
- package/dist/keyframes/index.js.map +0 -1
- package/dist/parser/classify.js +0 -319
- package/dist/parser/classify.js.map +0 -1
- package/dist/parser/const.js +0 -33
- package/dist/parser/const.js.map +0 -1
- package/dist/parser/lru.js +0 -109
- package/dist/parser/lru.js.map +0 -1
- package/dist/parser/parser.d.ts +0 -25
- package/dist/parser/parser.js +0 -116
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/tokenizer.js +0 -69
- package/dist/parser/tokenizer.js.map +0 -1
- package/dist/parser/types.d.ts +0 -51
- package/dist/parser/types.js +0 -46
- package/dist/parser/types.js.map +0 -1
- package/dist/pipeline/conditions.d.ts +0 -134
- package/dist/pipeline/conditions.js +0 -406
- package/dist/pipeline/conditions.js.map +0 -1
- package/dist/pipeline/exclusive.js +0 -231
- package/dist/pipeline/exclusive.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -53
- package/dist/pipeline/index.js +0 -660
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -856
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -451
- package/dist/pipeline/parseStateKey.js.map +0 -1
- package/dist/pipeline/simplify.js +0 -516
- package/dist/pipeline/simplify.js.map +0 -1
- package/dist/pipeline/warnings.js +0 -18
- package/dist/pipeline/warnings.js.map +0 -1
- package/dist/plugins/okhsl-plugin.d.ts +0 -35
- package/dist/plugins/okhsl-plugin.js +0 -371
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -69
- package/dist/properties/index.js +0 -236
- package/dist/properties/index.js.map +0 -1
- package/dist/properties/property-type-resolver.d.ts +0 -24
- package/dist/properties/property-type-resolver.js +0 -87
- package/dist/properties/property-type-resolver.js.map +0 -1
- package/dist/ssr/async-storage.d.ts +0 -17
- package/dist/ssr/async-storage.js.map +0 -1
- package/dist/ssr/collect-auto-properties.js +0 -40
- package/dist/ssr/collect-auto-properties.js.map +0 -1
- package/dist/ssr/collector.js +0 -173
- package/dist/ssr/collector.js.map +0 -1
- 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/ssr/format-global-rules.js.map +0 -1
- package/dist/ssr/format-keyframes.js +0 -70
- package/dist/ssr/format-keyframes.js.map +0 -1
- package/dist/ssr/format-property.js +0 -48
- package/dist/ssr/format-property.js.map +0 -1
- package/dist/ssr/format-rules.js +0 -70
- package/dist/ssr/format-rules.js.map +0 -1
- package/dist/ssr/hydrate.d.ts +0 -22
- package/dist/ssr/hydrate.js +0 -50
- package/dist/ssr/hydrate.js.map +0 -1
- package/dist/ssr/ssr-collector-ref.js +0 -12
- package/dist/ssr/ssr-collector-ref.js.map +0 -1
- package/dist/states/index.d.ts +0 -49
- package/dist/states/index.js +0 -416
- package/dist/states/index.js.map +0 -1
- package/dist/static/tastyStatic.d.ts +0 -46
- package/dist/static/tastyStatic.js +0 -31
- package/dist/static/tastyStatic.js.map +0 -1
- package/dist/static/types.d.ts +0 -49
- package/dist/static/types.js +0 -24
- package/dist/static/types.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/border.d.ts +0 -25
- package/dist/styles/border.js +0 -114
- package/dist/styles/border.js.map +0 -1
- package/dist/styles/color.d.ts +0 -14
- package/dist/styles/color.js +0 -23
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/createStyle.js +0 -77
- package/dist/styles/createStyle.js.map +0 -1
- package/dist/styles/dimension.js +0 -97
- package/dist/styles/dimension.js.map +0 -1
- package/dist/styles/display.d.ts +0 -37
- package/dist/styles/display.js +0 -67
- package/dist/styles/display.js.map +0 -1
- package/dist/styles/fade.d.ts +0 -15
- package/dist/styles/fade.js +0 -58
- package/dist/styles/fade.js.map +0 -1
- package/dist/styles/fill.d.ts +0 -42
- package/dist/styles/fill.js +0 -52
- package/dist/styles/fill.js.map +0 -1
- package/dist/styles/flow.d.ts +0 -16
- package/dist/styles/flow.js +0 -12
- package/dist/styles/flow.js.map +0 -1
- package/dist/styles/gap.d.ts +0 -31
- package/dist/styles/gap.js +0 -37
- package/dist/styles/gap.js.map +0 -1
- package/dist/styles/height.d.ts +0 -17
- package/dist/styles/height.js +0 -20
- package/dist/styles/height.js.map +0 -1
- package/dist/styles/index.d.ts +0 -2
- package/dist/styles/index.js +0 -9
- package/dist/styles/index.js.map +0 -1
- package/dist/styles/inset.d.ts +0 -52
- package/dist/styles/inset.js +0 -150
- package/dist/styles/inset.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/dist/styles/list.d.ts +0 -16
- package/dist/styles/list.js +0 -98
- package/dist/styles/list.js.map +0 -1
- package/dist/styles/margin.d.ts +0 -24
- package/dist/styles/margin.js +0 -104
- package/dist/styles/margin.js.map +0 -1
- package/dist/styles/outline.d.ts +0 -29
- package/dist/styles/outline.js +0 -65
- package/dist/styles/outline.js.map +0 -1
- package/dist/styles/padding.d.ts +0 -24
- package/dist/styles/padding.js +0 -104
- package/dist/styles/padding.js.map +0 -1
- package/dist/styles/predefined.d.ts +0 -71
- package/dist/styles/predefined.js +0 -238
- package/dist/styles/predefined.js.map +0 -1
- package/dist/styles/preset.d.ts +0 -47
- package/dist/styles/preset.js +0 -126
- package/dist/styles/preset.js.map +0 -1
- package/dist/styles/radius.d.ts +0 -14
- package/dist/styles/radius.js +0 -51
- package/dist/styles/radius.js.map +0 -1
- package/dist/styles/scrollbar.d.ts +0 -25
- package/dist/styles/scrollbar.js +0 -48
- package/dist/styles/scrollbar.js.map +0 -1
- package/dist/styles/shadow.d.ts +0 -14
- package/dist/styles/shadow.js +0 -24
- package/dist/styles/shadow.js.map +0 -1
- package/dist/styles/transition.d.ts +0 -14
- package/dist/styles/transition.js +0 -158
- package/dist/styles/transition.js.map +0 -1
- package/dist/styles/types.d.ts +0 -495
- package/dist/styles/width.d.ts +0 -17
- package/dist/styles/width.js +0 -20
- package/dist/styles/width.js.map +0 -1
- package/dist/tasty.d.ts +0 -981
- package/dist/tasty.js +0 -206
- package/dist/tasty.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/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -26
- package/dist/utils/cache-wrapper.js.map +0 -1
- package/dist/utils/case-converter.js +0 -8
- package/dist/utils/case-converter.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -9
- package/dist/utils/colors.js.map +0 -1
- package/dist/utils/css-types.d.ts +0 -7
- package/dist/utils/dotize.d.ts +0 -26
- package/dist/utils/dotize.js +0 -122
- package/dist/utils/dotize.js.map +0 -1
- package/dist/utils/filter-base-props.d.ts +0 -15
- package/dist/utils/filter-base-props.js +0 -45
- package/dist/utils/filter-base-props.js.map +0 -1
- package/dist/utils/get-display-name.d.ts +0 -7
- package/dist/utils/get-display-name.js +0 -10
- package/dist/utils/get-display-name.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/is-dev-env.js +0 -19
- package/dist/utils/is-dev-env.js.map +0 -1
- package/dist/utils/is-valid-element-type.js +0 -15
- package/dist/utils/is-valid-element-type.js.map +0 -1
- package/dist/utils/merge-styles.js.map +0 -1
- package/dist/utils/mod-attrs.d.ts +0 -8
- package/dist/utils/mod-attrs.js +0 -21
- package/dist/utils/mod-attrs.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
- package/dist/utils/process-tokens.d.ts +0 -31
- package/dist/utils/process-tokens.js +0 -171
- package/dist/utils/process-tokens.js.map +0 -1
- package/dist/utils/resolve-recipes.d.ts +0 -17
- package/dist/utils/resolve-recipes.js.map +0 -1
- package/dist/utils/selector-transform.js +0 -32
- package/dist/utils/selector-transform.js.map +0 -1
- package/dist/utils/string.js +0 -8
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/styles.d.ts +0 -177
- package/dist/utils/styles.js +0 -730
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -36
- package/dist/utils/typography.js +0 -53
- package/dist/utils/typography.js.map +0 -1
- package/dist/utils/warnings.d.ts +0 -16
- package/dist/utils/warnings.js +0 -16
- package/dist/utils/warnings.js.map +0 -1
- package/dist/zero/css-writer.d.ts +0 -45
- package/dist/zero/css-writer.js +0 -74
- package/dist/zero/css-writer.js.map +0 -1
- package/dist/zero/extractor.d.ts +0 -24
- package/dist/zero/extractor.js.map +0 -1
- package/docs/usage.md +0 -695
package/docs/ssr.md
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
# Server-Side Rendering (SSR)
|
|
2
2
|
|
|
3
|
-
Tasty supports server-side rendering with zero-cost client hydration. Your existing `tasty()` components work unchanged
|
|
3
|
+
Tasty supports server-side rendering with zero-cost client hydration. This does **not** introduce a separate styling engine: SSR uses the same runtime `tasty()` pipeline you already use on the client, then adds server-side CSS collection and client-side cache hydration. Your existing `tasty()` components work unchanged, and SSR remains opt-in with no per-component modifications. For the broader docs map, see the [Docs Hub](README.md).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
| Dependency | Version | Required for |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `react` | >= 18 | All SSR entry points (matches the current peer dependency of `@tenphi/tasty`) |
|
|
12
|
+
| `next` | >= 13 | Next.js integration (`@tenphi/tasty/ssr/next`) — App Router with `useServerInsertedHTML` |
|
|
13
|
+
| Node.js | >= 20 | Generic / streaming SSR (`@tenphi/tasty/ssr`) — uses `node:async_hooks` for `AsyncLocalStorage` |
|
|
14
|
+
|
|
15
|
+
The Astro integration (`@tenphi/tasty/ssr/astro`) has no additional dependencies beyond `react`.
|
|
6
16
|
|
|
7
17
|
---
|
|
8
18
|
|
|
9
19
|
## How It Works
|
|
10
20
|
|
|
11
|
-
|
|
21
|
+
`tasty()` components are hook-free and use `computeStyles()` internally — a synchronous, framework-agnostic function. On the server, `computeStyles()` discovers a `ServerStyleCollector` via a registered getter (module-level for Next.js, `globalThis` for Astro/generic frameworks using `AsyncLocalStorage`) and collects CSS into it instead of trying to access the DOM. On the client, CSS is injected synchronously into the DOM during render; the injector's content-based cache makes this idempotent. The collector accumulates all styles, serializes them as `<style>` tags and a cache state script in the HTML. On the client, `hydrateTastyCache()` pre-populates the injector cache so that `computeStyles()` skips the rendering pipeline entirely during hydration.
|
|
12
22
|
|
|
13
23
|
```
|
|
14
24
|
Server Client
|
|
15
25
|
────── ──────
|
|
16
26
|
tasty() renders hydrateTastyCache() pre-populates cache
|
|
17
|
-
└─
|
|
27
|
+
└─ computeStyles() └─ cacheKey → className map ready
|
|
18
28
|
└─ collector.collect()
|
|
19
29
|
tasty() renders
|
|
20
|
-
After render: └─
|
|
30
|
+
After render: └─ computeStyles()
|
|
21
31
|
<style data-tasty-ssr> └─ cache hit → skip pipeline
|
|
22
32
|
<script data-tasty-cache> └─ no CSS re-injection
|
|
23
33
|
```
|
|
@@ -72,15 +82,21 @@ That's it. All `tasty()` components inside the tree automatically get SSR suppor
|
|
|
72
82
|
|
|
73
83
|
### How it works
|
|
74
84
|
|
|
75
|
-
- `TastyRegistry` is a `'use client'` component, but Next.js still server-renders it on initial page load.
|
|
76
|
-
- During SSR, `
|
|
77
|
-
- `TastyRegistry` uses `useServerInsertedHTML` to flush collected CSS into the HTML stream as `<style data-tasty-ssr>` tags. This is fully streaming-compatible
|
|
78
|
-
- A companion `<script>` tag
|
|
79
|
-
- When the module loads on the client, `hydrateTastyCache()` runs automatically and pre-populates the injector cache. During hydration, `
|
|
85
|
+
- `TastyRegistry` is a `'use client'` component, but Next.js still server-renders it on initial page load. The `'use client'` boundary is required solely to access `useServerInsertedHTML` — **not** because `tasty()` components need the client.
|
|
86
|
+
- During SSR, `TastyRegistry` creates a `ServerStyleCollector` and registers it via a module-level getter (not `globalThis` — this avoids leaking between Next.js's separate RSC and SSR module graphs). It also wraps children in a React context provider so that hooks inside the SSR tree can discover the collector. All style functions — `tasty()` components, `computeStyles()`, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, and `useCounterStyle()` — discover the collector through the module-level getter or context provider.
|
|
87
|
+
- `TastyRegistry` uses `useServerInsertedHTML` to flush collected CSS into the HTML stream as `<style data-tasty-ssr>` tags. This is fully streaming-compatible — styles are injected alongside each Suspense boundary as it resolves.
|
|
88
|
+
- A companion inline `<script>` tag merges the `cacheKey → className` mapping into `window.__TASTY_SSR_CACHE__` for each flush. This streaming-friendly approach accumulates cache entries incrementally as Suspense boundaries resolve.
|
|
89
|
+
- When the `@tenphi/tasty/ssr/next` module loads on the client, `hydrateTastyCache()` runs automatically from `window.__TASTY_SSR_CACHE__` and pre-populates the injector cache. During hydration, `computeStyles()` hits the cache and skips the entire pipeline.
|
|
90
|
+
|
|
91
|
+
### Using Tasty in Server Components
|
|
92
|
+
|
|
93
|
+
All Tasty style functions are hook-free and do not require `'use client'`. They can be used directly in React Server Components:
|
|
80
94
|
|
|
81
|
-
|
|
95
|
+
- `tasty()` components — dynamic `styleProps` like `<Grid flow="column">` work normally
|
|
96
|
+
- `useStyles()`, `useGlobalStyles()`, `useRawCSS()` — inject styles by class or selector
|
|
97
|
+
- `useKeyframes()`, `useProperty()`, `useFontFace()`, `useCounterStyle()` — inject ancillary CSS rules
|
|
82
98
|
|
|
83
|
-
|
|
99
|
+
During SSR, all functions discover the collector via the same global getter registered by `TastyRegistry` — no React context or client boundary needed. In RSC mode without a collector (e.g., Astro zero-setup), CSS is accumulated in a per-request cache and flushed into an inline `<style>` tag by the next `tasty()` component in the tree. Ensure at least one `tasty()` component is present in every RSC render tree — standalone style functions alone cannot emit their CSS without a `tasty()` component to trigger the flush.
|
|
84
100
|
|
|
85
101
|
### Options
|
|
86
102
|
|
|
@@ -106,18 +122,17 @@ The nonce is automatically applied to all `<style>` and `<script>` tags injected
|
|
|
106
122
|
|
|
107
123
|
## Astro
|
|
108
124
|
|
|
109
|
-
|
|
125
|
+
Tasty offers three levels of Astro integration. Choose the one that matches your needs:
|
|
110
126
|
|
|
111
|
-
|
|
127
|
+
| Setup | Config needed | Deduplication | Hooks work | Client JS |
|
|
128
|
+
|---|---|---|---|---|
|
|
129
|
+
| Zero setup | None | Per render tree | Yes (within each tree) | None |
|
|
130
|
+
| `tastyIntegration({ islands: false })` | One line | Cross-tree | Yes | None |
|
|
131
|
+
| `tastyIntegration()` | One line | Cross-tree | Yes | Auto-hydration |
|
|
112
132
|
|
|
113
|
-
|
|
114
|
-
// src/middleware.ts
|
|
115
|
-
import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
|
|
116
|
-
|
|
117
|
-
export const onRequest = tastyMiddleware();
|
|
118
|
-
```
|
|
133
|
+
### Zero setup (static pages)
|
|
119
134
|
|
|
120
|
-
|
|
135
|
+
`tasty()` components work in Astro with **no configuration**. Each component emits its own inline `<style>` tag during server rendering via the RSC inline path. Just import and use:
|
|
121
136
|
|
|
122
137
|
```tsx
|
|
123
138
|
// src/components/Card.tsx
|
|
@@ -143,56 +158,123 @@ import Card from '../components/Card.tsx';
|
|
|
143
158
|
|
|
144
159
|
<html>
|
|
145
160
|
<body>
|
|
146
|
-
<Card>
|
|
147
|
-
<Card client:load>Island card — styles hydrated on client</Card>
|
|
161
|
+
<Card>Styled with zero setup</Card>
|
|
148
162
|
</body>
|
|
149
163
|
</html>
|
|
150
164
|
```
|
|
151
165
|
|
|
152
|
-
|
|
166
|
+
**Trade-offs**: Styles are deduplicated within each React render tree, but Astro renders separate component trees independently, so shared CSS (tokens, `@property` rules) may appear more than once. All style functions (`useGlobalStyles`, `useRawCSS`, `useKeyframes`, `useProperty`, `useFontFace`, `useCounterStyle`) work in zero-setup mode — their CSS is accumulated in the RSC cache and flushed by the next `tasty()` component in the tree.
|
|
153
167
|
|
|
154
|
-
|
|
168
|
+
Best for quick prototyping, small static sites, or trying Tasty out in Astro.
|
|
155
169
|
|
|
156
|
-
|
|
157
|
-
- **Islands** (`client:load`, `client:visible`, etc.): Styles are collected during SSR the same way. On the client, importing `@tenphi/tasty/ssr/astro` auto-hydrates the cache from `<script data-tasty-cache>`. The island's `useStyles()` calls hit the cache during hydration.
|
|
170
|
+
### Astro Integration (recommended)
|
|
158
171
|
|
|
159
|
-
|
|
172
|
+
For production use, add `tastyIntegration()` to your Astro config. This registers middleware automatically and, by default, injects client-side hydration for islands.
|
|
160
173
|
|
|
161
|
-
|
|
174
|
+
#### With islands (default)
|
|
162
175
|
|
|
163
|
-
```
|
|
164
|
-
//
|
|
165
|
-
import '
|
|
166
|
-
import
|
|
176
|
+
```ts
|
|
177
|
+
// astro.config.mjs
|
|
178
|
+
import { defineConfig } from 'astro/config';
|
|
179
|
+
import react from '@astrojs/react';
|
|
180
|
+
import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
167
181
|
|
|
168
|
-
|
|
169
|
-
|
|
182
|
+
export default defineConfig({
|
|
183
|
+
integrations: [react(), tastyIntegration()],
|
|
170
184
|
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
This gives you:
|
|
171
188
|
|
|
172
|
-
|
|
189
|
+
- A `ServerStyleCollector` per request via `AsyncLocalStorage`, deduplicating CSS across all React trees on the page
|
|
190
|
+
- A single consolidated `<style data-tasty-ssr>` injected into `</head>`
|
|
191
|
+
- A `<script data-tasty-cache>` tag with the `cacheKey -> className` map for client hydration
|
|
192
|
+
- Auto-injected client hydration script (via `injectScript('before-hydration')`) so islands skip the style pipeline during hydration -- no need to import anything manually in each island component
|
|
193
|
+
|
|
194
|
+
All style functions (`useGlobalStyles`, `useRawCSS`, `useKeyframes`, `useProperty`, `useFontFace`, `useCounterStyle`) work on the server.
|
|
195
|
+
|
|
196
|
+
```astro
|
|
197
|
+
---
|
|
198
|
+
// src/pages/index.astro
|
|
199
|
+
import Card from '../components/Card.tsx';
|
|
200
|
+
import Interactive from '../components/Interactive.tsx';
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
<html>
|
|
204
|
+
<body>
|
|
205
|
+
<Card>Static -- styles in <style data-tasty-ssr></Card>
|
|
206
|
+
<Interactive client:load>Island -- cache hydrated automatically</Interactive>
|
|
207
|
+
</body>
|
|
208
|
+
</html>
|
|
173
209
|
```
|
|
174
210
|
|
|
175
|
-
|
|
211
|
+
#### Static only (no client JS)
|
|
212
|
+
|
|
213
|
+
If your site has no `client:*` islands, skip the hydration script and cache transfer:
|
|
176
214
|
|
|
177
215
|
```ts
|
|
178
|
-
//
|
|
216
|
+
// astro.config.mjs
|
|
217
|
+
import { defineConfig } from 'astro/config';
|
|
218
|
+
import react from '@astrojs/react';
|
|
219
|
+
import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
220
|
+
|
|
221
|
+
export default defineConfig({
|
|
222
|
+
integrations: [react(), tastyIntegration({ islands: false })],
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
This gives the same middleware deduplication and hook support, but ships zero client-side JavaScript. No `<script data-tasty-cache>` is emitted.
|
|
227
|
+
|
|
228
|
+
### Manual middleware (advanced)
|
|
229
|
+
|
|
230
|
+
If you need to compose Tasty's middleware with other middleware (e.g., via `sequence()`), use `tastyMiddleware()` directly:
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
// src/middleware.ts
|
|
234
|
+
import { sequence } from 'astro:middleware';
|
|
235
|
+
import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
|
|
236
|
+
|
|
237
|
+
export const onRequest = sequence(
|
|
238
|
+
tastyMiddleware(),
|
|
239
|
+
myOtherMiddleware,
|
|
240
|
+
);
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
For island hydration with manual middleware, import the client module in a shared entry point or in each island:
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
import '@tenphi/tasty/ssr/astro-client';
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### Options
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
// Skip cache state transfer (static-only, no islands)
|
|
179
253
|
export const onRequest = tastyMiddleware({ transferCache: false });
|
|
180
254
|
```
|
|
181
255
|
|
|
256
|
+
### How it works
|
|
257
|
+
|
|
258
|
+
Astro's `@astrojs/react` renderer calls `renderToString()` for each React component without wrapping the tree in a provider. The middleware creates a `ServerStyleCollector` and binds it via `AsyncLocalStorage`. All `computeStyles()` calls within the request discover this collector automatically.
|
|
259
|
+
|
|
260
|
+
- **Static components** (no `client:*`): Styles are collected during `renderToString` and injected into `</head>` as a single `<style>` tag. No JavaScript is shipped.
|
|
261
|
+
- **Islands** (`client:load`, `client:visible`, etc.): Styles are collected during SSR the same way. On the client, the hydration script (auto-injected by `tastyIntegration()` or manually via `@tenphi/tasty/ssr/astro-client`) reads the cache state from `<script data-tasty-cache>` and pre-populates the injector. The island's `computeStyles()` calls hit the cache during hydration.
|
|
262
|
+
- The middleware reads the full response body, then injects the collected CSS into `</head>` before sending the final HTML.
|
|
263
|
+
|
|
182
264
|
### CSP nonce
|
|
183
265
|
|
|
184
|
-
|
|
266
|
+
Call `configure({ nonce: '...' })` before any rendering happens. The middleware reads the nonce and applies it to injected `<style>` and `<script>` tags.
|
|
185
267
|
|
|
186
268
|
---
|
|
187
269
|
|
|
188
270
|
## Generic Framework Integration
|
|
189
271
|
|
|
190
|
-
Any React-based framework can integrate using the
|
|
272
|
+
Any React-based framework can integrate using `runWithCollector`, which binds a `ServerStyleCollector` to the current async context via `AsyncLocalStorage`. All style function calls within the render automatically discover the collector.
|
|
191
273
|
|
|
192
274
|
```tsx
|
|
193
275
|
import {
|
|
194
276
|
ServerStyleCollector,
|
|
195
|
-
|
|
277
|
+
runWithCollector,
|
|
196
278
|
hydrateTastyCache,
|
|
197
279
|
} from '@tenphi/tasty/ssr';
|
|
198
280
|
import { renderToString } from 'react-dom/server';
|
|
@@ -202,10 +284,8 @@ import { hydrateRoot } from 'react-dom/client';
|
|
|
202
284
|
|
|
203
285
|
const collector = new ServerStyleCollector();
|
|
204
286
|
|
|
205
|
-
const html =
|
|
206
|
-
<
|
|
207
|
-
<App />
|
|
208
|
-
</TastySSRContext.Provider>
|
|
287
|
+
const html = await runWithCollector(collector, () =>
|
|
288
|
+
renderToString(<App />)
|
|
209
289
|
);
|
|
210
290
|
|
|
211
291
|
const css = collector.getCSS();
|
|
@@ -241,11 +321,8 @@ For streaming with `renderToPipeableStream`, use `flushCSS()` instead of `getCSS
|
|
|
241
321
|
```tsx
|
|
242
322
|
const collector = new ServerStyleCollector();
|
|
243
323
|
|
|
244
|
-
const stream =
|
|
245
|
-
<
|
|
246
|
-
<App />
|
|
247
|
-
</TastySSRContext.Provider>,
|
|
248
|
-
{
|
|
324
|
+
const stream = await runWithCollector(collector, () =>
|
|
325
|
+
renderToPipeableStream(<App />, {
|
|
249
326
|
onShellReady() {
|
|
250
327
|
// Flush styles collected so far
|
|
251
328
|
const css = collector.flushCSS();
|
|
@@ -260,29 +337,8 @@ const stream = renderToPipeableStream(
|
|
|
260
337
|
const state = collector.getCacheState();
|
|
261
338
|
res.write(`<script data-tasty-cache type="application/json">${JSON.stringify(state)}</script>`);
|
|
262
339
|
},
|
|
263
|
-
}
|
|
264
|
-
);
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
### AsyncLocalStorage (no React context)
|
|
268
|
-
|
|
269
|
-
If your framework doesn't support wrapping the React tree with a provider, use `runWithCollector`:
|
|
270
|
-
|
|
271
|
-
```tsx
|
|
272
|
-
import {
|
|
273
|
-
ServerStyleCollector,
|
|
274
|
-
runWithCollector,
|
|
275
|
-
hydrateTastyCache,
|
|
276
|
-
} from '@tenphi/tasty/ssr';
|
|
277
|
-
|
|
278
|
-
const collector = new ServerStyleCollector();
|
|
279
|
-
|
|
280
|
-
const html = await runWithCollector(collector, () =>
|
|
281
|
-
renderToString(<App />)
|
|
340
|
+
})
|
|
282
341
|
);
|
|
283
|
-
|
|
284
|
-
const css = collector.getCSS();
|
|
285
|
-
// ... inject into HTML as above
|
|
286
342
|
```
|
|
287
343
|
|
|
288
344
|
---
|
|
@@ -293,28 +349,34 @@ const css = collector.getCSS();
|
|
|
293
349
|
|
|
294
350
|
| Import path | Description |
|
|
295
351
|
|---|---|
|
|
296
|
-
| `@tenphi/tasty/ssr` | Core SSR API: `ServerStyleCollector`, `
|
|
352
|
+
| `@tenphi/tasty/ssr` | Core SSR API: `ServerStyleCollector`, `runWithCollector`, `hydrateTastyCache` |
|
|
297
353
|
| `@tenphi/tasty/ssr/next` | Next.js App Router: `TastyRegistry` component |
|
|
298
|
-
| `@tenphi/tasty/ssr/astro` | Astro: `
|
|
354
|
+
| `@tenphi/tasty/ssr/astro` | Astro: `tastyIntegration`, `tastyMiddleware` |
|
|
355
|
+
| `@tenphi/tasty/ssr/astro-client` | Astro: client-side cache hydration (auto-injected by integration, or import manually) |
|
|
299
356
|
|
|
300
357
|
### `ServerStyleCollector`
|
|
301
358
|
|
|
302
359
|
Server-safe style collector. One instance per request.
|
|
303
360
|
|
|
361
|
+
Constructor: `new ServerStyleCollector(namePrefix?)`. The optional `namePrefix` overrides the value from `configure({ namePrefix })`; in normal usage you pass nothing and let the global config drive it. See [Configuration: Name prefix](configuration.md#name-prefix).
|
|
362
|
+
|
|
304
363
|
| Method | Description |
|
|
305
364
|
|---|---|
|
|
306
|
-
| `allocateClassName(cacheKey)` | Allocate a
|
|
365
|
+
| `allocateClassName(cacheKey)` | Allocate a deterministic, content-hashed class name for a cache key (e.g. `t1a2b3` with the default prefix). The same `cacheKey` always produces the same class name on server and client when both share the same `namePrefix`. Returns `{ className, isNewAllocation }`. |
|
|
307
366
|
| `collectChunk(cacheKey, className, rules)` | Record CSS rules for a chunk. Deduplicated by `cacheKey`. |
|
|
308
367
|
| `collectKeyframes(name, css)` | Record a `@keyframes` rule. Deduplicated by name. |
|
|
368
|
+
| `allocateKeyframeName(providedName?)` | Allocate a keyframe name. Returns `providedName` if given, otherwise generates one using `${namePrefix}k${counter}` (e.g. `tk0`, `tk1`, ...). |
|
|
309
369
|
| `collectProperty(name, css)` | Record a `@property` rule. Deduplicated by name. |
|
|
370
|
+
| `collectFontFace(key, css)` | Record a `@font-face` rule. Deduplicated by content hash. |
|
|
371
|
+
| `collectCounterStyle(name, css)` | Record a `@counter-style` rule. Deduplicated by name. |
|
|
372
|
+
| `allocateCounterStyleName(providedName?)` | Allocate a counter-style name. Returns `providedName` if given, otherwise generates one using `${namePrefix}c${counter}` (e.g. `tc0`, `tc1`, ...). |
|
|
373
|
+
| `collectGlobalStyles(key, css)` | Record global styles (from `useGlobalStyles`). Deduplicated by key. |
|
|
374
|
+
| `collectRawCSS(key, css)` | Record raw CSS text (from `useRawCSS`). Deduplicated by key. |
|
|
375
|
+
| `collectInternals()` | Collect internal `@property` rules, `:root` token defaults, `@font-face`, and `@counter-style` rules from the global config. Called automatically on first chunk collection; idempotent. |
|
|
310
376
|
| `getCSS()` | Get all collected CSS as a single string. For non-streaming SSR. |
|
|
311
377
|
| `flushCSS()` | Get only CSS collected since the last flush. For streaming SSR. |
|
|
312
378
|
| `getCacheState()` | Serialize `{ entries: Record<cacheKey, className>, classCounter }` for client hydration. |
|
|
313
379
|
|
|
314
|
-
### `TastySSRContext`
|
|
315
|
-
|
|
316
|
-
React context (`createContext<ServerStyleCollector | null>(null)`). Used by `useStyles()` to find the collector during SSR.
|
|
317
|
-
|
|
318
380
|
### `TastyRegistry`
|
|
319
381
|
|
|
320
382
|
Next.js App Router component. Props:
|
|
@@ -324,9 +386,17 @@ Next.js App Router component. Props:
|
|
|
324
386
|
| `children` | `ReactNode` | required | Application tree |
|
|
325
387
|
| `transferCache` | `boolean` | `true` | Embed cache state script for zero-cost hydration |
|
|
326
388
|
|
|
389
|
+
### `tastyIntegration(options?)`
|
|
390
|
+
|
|
391
|
+
Astro integration factory. Registers middleware and optionally injects client hydration.
|
|
392
|
+
|
|
393
|
+
| Option | Type | Default | Description |
|
|
394
|
+
|---|---|---|---|
|
|
395
|
+
| `islands` | `boolean` | `true` | When `true`, injects client hydration script and enables `transferCache`. When `false`, no client JS is shipped. |
|
|
396
|
+
|
|
327
397
|
### `tastyMiddleware(options?)`
|
|
328
398
|
|
|
329
|
-
Astro middleware factory.
|
|
399
|
+
Astro middleware factory. Use for manual middleware composition.
|
|
330
400
|
|
|
331
401
|
| Option | Type | Default | Description |
|
|
332
402
|
|---|---|---|---|
|
|
@@ -338,7 +408,7 @@ Pre-populate the client injector cache. When called without arguments, reads fro
|
|
|
338
408
|
|
|
339
409
|
### `runWithCollector(collector, fn)`
|
|
340
410
|
|
|
341
|
-
Run a function with a `ServerStyleCollector` bound to the current async context via `AsyncLocalStorage`. All
|
|
411
|
+
Run a function with a `ServerStyleCollector` bound to the current async context via `AsyncLocalStorage`. All style function calls within `fn` (and async continuations) — including `computeStyles()`, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, and `useCounterStyle()` — will find this collector.
|
|
342
412
|
|
|
343
413
|
---
|
|
344
414
|
|
|
@@ -346,15 +416,17 @@ Run a function with a `ServerStyleCollector` bound to the current async context
|
|
|
346
416
|
|
|
347
417
|
### Styles flash on page load (FOUC)
|
|
348
418
|
|
|
349
|
-
The `TastyRegistry` or `
|
|
419
|
+
The `TastyRegistry` or `tastyIntegration` is missing. Ensure your layout wraps the app with `TastyRegistry` (Next.js) or that `tastyIntegration()` is in your Astro config (or `tastyMiddleware()` is registered manually).
|
|
350
420
|
|
|
351
421
|
### Hydration mismatch warnings
|
|
352
422
|
|
|
353
|
-
Class names are deterministic for the same render order. If you see mismatches, ensure `hydrateTastyCache()` runs before React hydration. For Next.js, this is automatic. For Astro, import `@tenphi/tasty/ssr/astro` in your island components. For custom setups, call `hydrateTastyCache()` before `hydrateRoot()`.
|
|
423
|
+
Class names are deterministic for the same render order. If you see mismatches, ensure `hydrateTastyCache()` runs before React hydration. For Next.js, this is automatic. For Astro with `tastyIntegration()`, this is also automatic. For manual Astro middleware setups, import `@tenphi/tasty/ssr/astro-client` in your island components. For custom setups, call `hydrateTastyCache()` before `hydrateRoot()`.
|
|
354
424
|
|
|
355
425
|
### Styles duplicated after hydration
|
|
356
426
|
|
|
357
|
-
|
|
427
|
+
**Global CSS** (`:root` tokens, `@property`, `globalStyles`, `@font-face`, `@counter-style`) configured via `configure()` is automatically deduplicated. When Tasty detects `<style data-tasty-ssr>` in the document, it skips client-side injection of globals that were already rendered by the SSR collector. This means `configure()` can be called with the full config on both server and client — no `typeof window === 'undefined'` guard is needed.
|
|
428
|
+
|
|
429
|
+
**Component CSS**: SSR `<style data-tasty-ssr>` tags remain in the DOM. The client injector creates separate `<style>` elements for any new styles. SSR styles are never modified or removed by the client. If this is a concern for very large apps, call `cleanupSSRStyles()` after hydration:
|
|
358
430
|
|
|
359
431
|
```tsx
|
|
360
432
|
import { hydrateTastyCache } from '@tenphi/tasty/ssr';
|
package/docs/styles.md
CHANGED
|
@@ -104,6 +104,8 @@ Element padding with directional modifiers and multi-group support. Use **comma-
|
|
|
104
104
|
|
|
105
105
|
**Direction modifiers:** `top`, `right`, `bottom`, `left`
|
|
106
106
|
|
|
107
|
+
**Output modifier:** `longhand` — forces output as individual CSS longhand properties (`padding-top`, `padding-right`, `padding-bottom`, `padding-left`) instead of the `padding` shorthand. Useful when children need to selectively inherit individual directions.
|
|
108
|
+
|
|
107
109
|
| Value | Effect |
|
|
108
110
|
|-------|--------|
|
|
109
111
|
| `"2x"` | All sides `2x` |
|
|
@@ -112,6 +114,7 @@ Element padding with directional modifiers and multi-group support. Use **comma-
|
|
|
112
114
|
| `"1x left right"` | Left and right `1x`, top/bottom `0` |
|
|
113
115
|
| `"1x, 2x top"` | All sides `1x`, then top overridden to `2x` |
|
|
114
116
|
| `"1x, 2x top bottom"` | Left/right `1x`, top/bottom `2x` |
|
|
117
|
+
| `"2x longhand"` | All sides `2x`, output as 4 individual `padding-*` properties |
|
|
115
118
|
| `true` | All sides `1x` |
|
|
116
119
|
| Number | Converted to `px` |
|
|
117
120
|
|
|
@@ -129,6 +132,8 @@ Element margin. Same syntax, modifiers, and multi-group support as `padding`.
|
|
|
129
132
|
|
|
130
133
|
**Direction modifiers:** `top`, `right`, `bottom`, `left`
|
|
131
134
|
|
|
135
|
+
**Output modifier:** `longhand` — forces output as individual CSS longhand properties (`margin-top`, etc.) instead of the `margin` shorthand.
|
|
136
|
+
|
|
132
137
|
| Value | Effect |
|
|
133
138
|
|-------|--------|
|
|
134
139
|
| `"2x"` | All sides `2x` |
|
|
@@ -146,37 +151,39 @@ Individual props `marginTop`, `marginRight`, `marginBottom`, `marginLeft`, `marg
|
|
|
146
151
|
|
|
147
152
|
### `width`
|
|
148
153
|
|
|
149
|
-
Element width with min/max control.
|
|
154
|
+
Element width with min/max control. One, two, or three values set `min-width`, `width`, and `max-width` together.
|
|
155
|
+
|
|
156
|
+
**Positional syntax:**
|
|
150
157
|
|
|
151
|
-
|
|
158
|
+
| Value | min-width | width | max-width |
|
|
159
|
+
|-------|-----------|-------|-----------|
|
|
160
|
+
| `"10x"` | initial | `10x` | initial |
|
|
161
|
+
| `"1x 10x"` | `1x` | auto | `10x` |
|
|
162
|
+
| `"1x 5x 10x"` | `1x` | `5x` | `10x` |
|
|
163
|
+
| `"0 100% 800px"` | `0` | `100%` | `800px` |
|
|
164
|
+
| `"initial 100% 1400px"` | initial | `100%` | `1400px` |
|
|
152
165
|
|
|
153
|
-
**
|
|
166
|
+
**Modifier syntax:**
|
|
167
|
+
|
|
168
|
+
| Value | min-width | width | max-width |
|
|
169
|
+
|-------|-----------|-------|-----------|
|
|
170
|
+
| `"min 2x"` | `2x` | auto | initial |
|
|
171
|
+
| `"max 100%"` | initial | auto | `100%` |
|
|
172
|
+
| `"fixed 200px"` | `200px` | `200px` | `200px` |
|
|
154
173
|
|
|
155
174
|
**Keywords:** `stretch`, `max-content`, `min-content`, `fit-content`
|
|
156
175
|
|
|
157
176
|
| Value | Effect |
|
|
158
177
|
|-------|--------|
|
|
159
|
-
| `"10x"` | Width `10x`, min `initial`, max `initial` |
|
|
160
|
-
| `"1x 10x"` | Width `auto`, min `1x`, max `10x` |
|
|
161
|
-
| `"1x 5x 10x"` | Min `1x`, width `5x`, max `10x` |
|
|
162
|
-
| `"min 2x"` | Min-width `2x`, width `auto`, max `initial` |
|
|
163
|
-
| `"max 100%"` | Max-width `100%`, width `auto`, min `initial` |
|
|
164
|
-
| `"fixed 200px"` | Min, width, and max all set to `200px` |
|
|
165
178
|
| `"stretch"` | Fill available space (cross-browser) |
|
|
166
|
-
| `true` |
|
|
179
|
+
| `true` | Reset to `auto` / `initial` / `initial` |
|
|
167
180
|
| Number | Converted to `px` |
|
|
168
181
|
|
|
169
182
|
Separate `minWidth` and `maxWidth` props are supported and override values from the `width` syntax.
|
|
170
183
|
|
|
171
184
|
### `height`
|
|
172
185
|
|
|
173
|
-
Element height. Same syntax and
|
|
174
|
-
|
|
175
|
-
**Syntax:** `[value]` | `[min max]` | `[min value max]` | `[modifier value]`
|
|
176
|
-
|
|
177
|
-
**Modifiers:** `min`, `max`, `fixed`
|
|
178
|
-
|
|
179
|
-
**Keywords:** `max-content`, `min-content`, `fit-content`
|
|
186
|
+
Element height. Same syntax, modifiers, and positional patterns as `width`.
|
|
180
187
|
|
|
181
188
|
Separate `minHeight` and `maxHeight` props are supported and override values from the `height` syntax.
|
|
182
189
|
|
|
@@ -188,12 +195,15 @@ Positioning offsets with directional modifiers and multi-group support. Same dir
|
|
|
188
195
|
|
|
189
196
|
**Direction modifiers:** `top`, `right`, `bottom`, `left`
|
|
190
197
|
|
|
198
|
+
**Output modifier:** `longhand` — forces output as individual CSS properties (`top`, `right`, `bottom`, `left`) instead of the `inset` shorthand.
|
|
199
|
+
|
|
191
200
|
| Value | Effect |
|
|
192
201
|
|-------|--------|
|
|
193
202
|
| `"0"` | All sides `0` |
|
|
194
203
|
| `"2x top"` | Top `2x`, right/bottom/left `auto` |
|
|
195
204
|
| `"1x left right"` | Left and right `1x`, top/bottom `auto` |
|
|
196
205
|
| `"0, 2x top"` | All sides `0`, then top overridden to `2x` |
|
|
206
|
+
| `"0 longhand"` | All sides `0`, output as individual `top`/`right`/`bottom`/`left` |
|
|
197
207
|
| `true` | All sides `0` |
|
|
198
208
|
|
|
199
209
|
Later comma-separated groups override earlier groups for conflicting directions.
|
|
@@ -252,7 +262,7 @@ Text color with design token support.
|
|
|
252
262
|
| `"(#primary, #secondary)"` | Fallback: use `#primary`, fall back to `#secondary` |
|
|
253
263
|
| `true` | `currentColor` |
|
|
254
264
|
|
|
255
|
-
When set to a named color token, also sets `$current-color` and `$current-color-
|
|
265
|
+
When set to a named color token, also sets `$current-color` and `$current-color-{colorSpace}` custom properties for downstream use (suffix depends on the configured `colorSpace`, default `oklch`).
|
|
256
266
|
|
|
257
267
|
### `svgFill`
|
|
258
268
|
|
|
@@ -279,12 +289,15 @@ Border shorthand with directional and multi-group support. Use **comma-separated
|
|
|
279
289
|
|
|
280
290
|
**Direction modifiers:** `top`, `right`, `bottom`, `left`
|
|
281
291
|
|
|
292
|
+
**Output modifier:** `longhand` — forces output as individual CSS properties (`border-top`, `border-right`, `border-bottom`, `border-left`) instead of the `border` shorthand. Useful when children need to selectively inherit individual sides.
|
|
293
|
+
|
|
282
294
|
| Value | Effect |
|
|
283
295
|
|-------|--------|
|
|
284
296
|
| `true` | Default border (`1bw solid #border`) on all sides |
|
|
285
297
|
| `"2bw dashed #purple"` | All sides: 2bw dashed purple |
|
|
286
298
|
| `"2bw top"` | Top only: 2bw solid `#border`, others: 0 |
|
|
287
299
|
| `"dotted #danger left right"` | Left/right: 1bw dotted `#danger`, others: 0 |
|
|
300
|
+
| `"1bw longhand"` | All sides: 1bw solid `#border`, output as 4 individual `border-*` properties |
|
|
288
301
|
| `"1bw #red, 2bw #blue top"` | All sides: 1bw solid `#red`, top overridden to 2bw solid `#blue` |
|
|
289
302
|
| `"1bw, dashed top bottom, #purple left right"` | Base: 1bw solid `#border`, top/bottom: 1bw dashed `#border`, left/right: 1bw solid `#purple` |
|
|
290
303
|
|
|
@@ -304,9 +317,12 @@ Border radius with shape presets and directional modifiers.
|
|
|
304
317
|
| `"ellipse"` | Circular (`50%`) |
|
|
305
318
|
| `"leaf"` | Asymmetric: sharp, round, sharp, round |
|
|
306
319
|
| `"backleaf"` | Asymmetric: round, sharp, round, sharp |
|
|
320
|
+
| `"inherit"` | Inherit border-radius from parent |
|
|
307
321
|
|
|
308
322
|
**Direction modifiers:** `top`, `right`, `bottom`, `left` — rounds only the specified corners.
|
|
309
323
|
|
|
324
|
+
**Output modifier:** `longhand` — forces output as individual CSS longhand properties (`border-top-left-radius`, `border-top-right-radius`, `border-bottom-right-radius`, `border-bottom-left-radius`) instead of the `border-radius` shorthand. Useful when children need to selectively inherit individual corners via `radius: 'inherit left'`.
|
|
325
|
+
|
|
310
326
|
| Value | Effect |
|
|
311
327
|
|-------|--------|
|
|
312
328
|
| `"2r"` | All corners `2r` |
|
|
@@ -315,6 +331,9 @@ Border radius with shape presets and directional modifiers.
|
|
|
315
331
|
| `"1r top"` | Top-left and top-right `1r`, bottom-left and bottom-right `0` |
|
|
316
332
|
| `"leaf"` | Alternating sharp/round corners (top-left `0`, top-right `1r`, bottom-right `0`, bottom-left `1r`) |
|
|
317
333
|
| `"backleaf"` | Inverse leaf (top-left `1r`, top-right `0`, bottom-right `1r`, bottom-left `0`) |
|
|
334
|
+
| `"1r longhand"` | All corners `1r`, output as 4 individual `border-*-radius` properties |
|
|
335
|
+
| `"inherit"` | All corners inherit from parent (`border-radius: inherit`) |
|
|
336
|
+
| `"inherit right"` | Right corners inherit from parent (uses longhand properties) |
|
|
318
337
|
|
|
319
338
|
### `outline`
|
|
320
339
|
|
|
@@ -344,7 +363,7 @@ Box shadow. Supports multiple shadows comma-separated.
|
|
|
344
363
|
|
|
345
364
|
| Value | Effect |
|
|
346
365
|
|-------|--------|
|
|
347
|
-
| `true` | Default shadow (
|
|
366
|
+
| `true` | Default shadow (uses `var(--shadow)` — define a `$shadow` token in your design system) |
|
|
348
367
|
| `"1x .5x .5x #dark.50"` | Custom shadow with Tasty units/colors |
|
|
349
368
|
| `"0 1x 2x #dark.20"` | Standard shadow |
|
|
350
369
|
| `"inset 0 1x 2x #dark.10"` | Inset shadow |
|
|
@@ -359,24 +378,29 @@ Multiple shadows: `shadow="1x 1x 2x #dark.20, inset 0 0 4x #dark.10"`
|
|
|
359
378
|
|
|
360
379
|
Typography preset that sets font-size, line-height, letter-spacing, font-weight, font-style, and text-transform from named design tokens.
|
|
361
380
|
|
|
362
|
-
**Syntax:** `
|
|
381
|
+
**Syntax:** `name`, `name / modifier...`, or `modifier...` (shorthand)
|
|
363
382
|
|
|
364
383
|
Preset names are project-specific (e.g. `h1`–`h6`, `t1`–`t4`, `p1`–`p4`). Register them for autocomplete by augmenting `TastyPresetNames`.
|
|
365
384
|
|
|
385
|
+
Use `/` to separate the preset name from one or more space-separated modifiers. When modifiers are used alone (without a name), the preset name defaults to `inherit`. Modifiers can be combined freely because they target different properties.
|
|
386
|
+
|
|
366
387
|
**Modifiers:**
|
|
367
388
|
|
|
368
389
|
| Modifier | Effect |
|
|
369
390
|
|----------|--------|
|
|
370
|
-
| `strong` | Sets `font-weight` to bold (from `$bold-font-weight` token) |
|
|
391
|
+
| `strong` (or `bold`) | Sets `font-weight` to bold (from `$bold-font-weight` token) |
|
|
371
392
|
| `italic` | Sets `font-style: italic` |
|
|
372
393
|
| `icon` | Sets font-size and line-height to icon size |
|
|
373
394
|
| `tight` | Sets line-height equal to font-size |
|
|
374
395
|
|
|
375
396
|
```jsx
|
|
376
|
-
preset="h1"
|
|
377
|
-
preset="h2 strong"
|
|
378
|
-
preset="
|
|
379
|
-
preset="
|
|
397
|
+
preset="h1" // heading 1
|
|
398
|
+
preset="h2 / strong" // bold heading 2
|
|
399
|
+
preset="h2 / strong italic" // bold + italic heading 2
|
|
400
|
+
preset="t3 / italic" // italic text 3
|
|
401
|
+
preset="t2 / strong tight" // bold text 2 with tight line-height
|
|
402
|
+
preset="bold" // inherit preset with bold (shorthand)
|
|
403
|
+
preset="bold italic" // inherit preset with bold + italic (shorthand)
|
|
380
404
|
```
|
|
381
405
|
|
|
382
406
|
Individual typography props (`fontSize`, `lineHeight`, `letterSpacing`, `fontWeight`, `fontStyle`, `textTransform`) can be used alongside `preset` to override specific values, but using `preset` alone is recommended.
|
|
@@ -511,7 +535,7 @@ Scrollbar styling using CSS standard properties (`scrollbar-width`, `scrollbar-c
|
|
|
511
535
|
|
|
512
536
|
**Colors:** Up to 2 color values for thumb and track (optional), applied via `scrollbar-color`.
|
|
513
537
|
|
|
514
|
-
**Defaults:** When no colors are specified, the thumb color comes from
|
|
538
|
+
**Defaults:** When no colors are specified, the thumb color comes from `var(--scrollbar-thumb-color)` and the track color from `var(--scrollbar-track-color, transparent)`. These are not built-in — your design system should define `#scrollbar-thumb` and `#scrollbar-track` tokens (e.g. `'#text.5'` and `'#dark-bg'`). If neither token is defined, the track falls back to `transparent` via a CSS fallback, while the thumb has no CSS-level fallback — the browser treats the entire `scrollbar-color` declaration as invalid and reverts to the platform-default scrollbar appearance.
|
|
515
539
|
|
|
516
540
|
**Note:** `none` takes precedence over all other modifiers and colors. Combining `none` with other tokens (e.g., `"none always #red"`) produces a warning, and only `scrollbar-width: none` is applied.
|
|
517
541
|
|