@tenphi/tasty 0.0.0-snapshot.ef8cc29 → 0.0.0-snapshot.efb24cc
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 +65 -215
- 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 +322 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +105 -21
- package/dist/config.js +175 -49
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +7 -7
- package/dist/core/index.js +8 -8
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.js +5 -6
- 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 +36 -0
- package/dist/hooks/useCounterStyle.js +65 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +45 -0
- package/dist/hooks/useFontFace.js +66 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +18 -2
- package/dist/hooks/useGlobalStyles.js +52 -47
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.d.ts +4 -2
- package/dist/hooks/useKeyframes.js +43 -57
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.d.ts +4 -2
- package/dist/hooks/useProperty.js +30 -48
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.d.ts +13 -44
- package/dist/hooks/useRawCSS.js +91 -28
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +3 -8
- package/dist/hooks/useStyles.js +7 -225
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.js +11 -9
- package/dist/injector/index.d.ts +36 -19
- package/dist/injector/index.js +43 -20
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +53 -3
- package/dist/injector/injector.js +235 -14
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +9 -13
- package/dist/injector/sheet-manager.js +41 -71
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +112 -21
- 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 +58 -4
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.d.ts +2 -0
- package/dist/pipeline/index.js +39 -12
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +57 -5
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.js +5 -6
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +181 -7
- 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/plugins/types.d.ts +12 -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/rsc-cache.js +79 -0
- package/dist/rsc-cache.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 +89 -10
- package/dist/ssr/astro.js +113 -29
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/async-storage.js +15 -6
- package/dist/ssr/async-storage.js.map +1 -1
- package/dist/ssr/collect-auto-properties.js +29 -11
- package/dist/ssr/collect-auto-properties.js.map +1 -1
- package/dist/ssr/collector.d.ts +26 -13
- package/dist/ssr/collector.js +84 -32
- package/dist/ssr/collector.js.map +1 -1
- package/dist/ssr/context.js +4 -2
- package/dist/ssr/context.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.d.ts +20 -13
- package/dist/ssr/hydrate.js +25 -30
- package/dist/ssr/hydrate.js.map +1 -1
- package/dist/ssr/index.d.ts +3 -4
- package/dist/ssr/index.js +5 -7
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next.d.ts +6 -5
- package/dist/ssr/next.js +14 -10
- package/dist/ssr/next.js.map +1 -1
- package/dist/ssr/ssr-collector-ref.js +20 -3
- package/dist/ssr/ssr-collector-ref.js.map +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 +52 -11
- 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 +96 -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/deps-equal.js +15 -0
- package/dist/utils/deps-equal.js.map +1 -0
- 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/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- 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.d.ts +21 -10
- package/dist/utils/typography.js +10 -2
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +27 -101
- package/dist/zero/babel.js +164 -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 +2 -2
- package/docs/adoption.md +5 -3
- package/docs/comparison.md +24 -25
- package/docs/configuration.md +130 -1
- package/docs/design-system.md +47 -12
- package/docs/dsl.md +115 -9
- package/docs/getting-started.md +10 -10
- package/docs/injector.md +41 -25
- package/docs/methodology.md +119 -6
- package/docs/react-api.md +557 -0
- package/docs/ssr.md +141 -81
- package/docs/styles.md +45 -23
- package/docs/tasty-static.md +103 -2
- package/package.json +20 -9
- package/dist/ssr/context.d.ts +0 -8
- 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/docs/runtime.md +0 -317
package/docs/ssr.md
CHANGED
|
@@ -18,16 +18,16 @@ The Astro integration (`@tenphi/tasty/ssr/astro`) has no additional dependencies
|
|
|
18
18
|
|
|
19
19
|
## How It Works
|
|
20
20
|
|
|
21
|
-
|
|
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.
|
|
22
22
|
|
|
23
23
|
```
|
|
24
24
|
Server Client
|
|
25
25
|
────── ──────
|
|
26
26
|
tasty() renders hydrateTastyCache() pre-populates cache
|
|
27
|
-
└─
|
|
27
|
+
└─ computeStyles() └─ cacheKey → className map ready
|
|
28
28
|
└─ collector.collect()
|
|
29
29
|
tasty() renders
|
|
30
|
-
After render: └─
|
|
30
|
+
After render: └─ computeStyles()
|
|
31
31
|
<style data-tasty-ssr> └─ cache hit → skip pipeline
|
|
32
32
|
<script data-tasty-cache> └─ no CSS re-injection
|
|
33
33
|
```
|
|
@@ -82,15 +82,21 @@ That's it. All `tasty()` components inside the tree automatically get SSR suppor
|
|
|
82
82
|
|
|
83
83
|
### How it works
|
|
84
84
|
|
|
85
|
-
- `TastyRegistry` is a `'use client'` component, but Next.js still server-renders it on initial page load.
|
|
86
|
-
- During SSR, `
|
|
87
|
-
- `TastyRegistry` uses `useServerInsertedHTML` to flush collected CSS into the HTML stream as `<style data-tasty-ssr>` tags. This is fully streaming-compatible
|
|
88
|
-
- A companion `<script>` tag
|
|
89
|
-
- 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
90
|
|
|
91
|
-
### Using
|
|
91
|
+
### Using Tasty in Server Components
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
All Tasty style functions are hook-free and do not require `'use client'`. They can be used directly in React Server Components:
|
|
94
|
+
|
|
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
|
|
98
|
+
|
|
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.
|
|
94
100
|
|
|
95
101
|
### Options
|
|
96
102
|
|
|
@@ -116,18 +122,17 @@ The nonce is automatically applied to all `<style>` and `<script>` tags injected
|
|
|
116
122
|
|
|
117
123
|
## Astro
|
|
118
124
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
Create or update your Astro middleware:
|
|
125
|
+
Tasty offers three levels of Astro integration. Choose the one that matches your needs:
|
|
122
126
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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 |
|
|
126
132
|
|
|
127
|
-
|
|
128
|
-
```
|
|
133
|
+
### Zero setup (static pages)
|
|
129
134
|
|
|
130
|
-
|
|
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:
|
|
131
136
|
|
|
132
137
|
```tsx
|
|
133
138
|
// src/components/Card.tsx
|
|
@@ -153,56 +158,123 @@ import Card from '../components/Card.tsx';
|
|
|
153
158
|
|
|
154
159
|
<html>
|
|
155
160
|
<body>
|
|
156
|
-
<Card>
|
|
157
|
-
<Card client:load>Island card — styles hydrated on client</Card>
|
|
161
|
+
<Card>Styled with zero setup</Card>
|
|
158
162
|
</body>
|
|
159
163
|
</html>
|
|
160
164
|
```
|
|
161
165
|
|
|
162
|
-
|
|
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.
|
|
163
167
|
|
|
164
|
-
|
|
168
|
+
Best for quick prototyping, small static sites, or trying Tasty out in Astro.
|
|
165
169
|
|
|
166
|
-
|
|
167
|
-
- **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)
|
|
168
171
|
|
|
169
|
-
|
|
172
|
+
For production use, add `tastyIntegration()` to your Astro config. This registers middleware automatically and, by default, injects client-side hydration for islands.
|
|
170
173
|
|
|
171
|
-
|
|
174
|
+
#### With islands (default)
|
|
172
175
|
|
|
173
|
-
```
|
|
174
|
-
//
|
|
175
|
-
import '
|
|
176
|
-
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';
|
|
177
181
|
|
|
178
|
-
|
|
179
|
-
|
|
182
|
+
export default defineConfig({
|
|
183
|
+
integrations: [react(), tastyIntegration()],
|
|
180
184
|
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
This gives you:
|
|
188
|
+
|
|
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
|
+
---
|
|
181
202
|
|
|
182
|
-
|
|
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>
|
|
183
209
|
```
|
|
184
210
|
|
|
185
|
-
|
|
211
|
+
#### Static only (no client JS)
|
|
212
|
+
|
|
213
|
+
If your site has no `client:*` islands, skip the hydration script and cache transfer:
|
|
214
|
+
|
|
215
|
+
```ts
|
|
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
|
|
186
250
|
|
|
187
251
|
```ts
|
|
188
|
-
// Skip cache state transfer
|
|
252
|
+
// Skip cache state transfer (static-only, no islands)
|
|
189
253
|
export const onRequest = tastyMiddleware({ transferCache: false });
|
|
190
254
|
```
|
|
191
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
|
+
|
|
192
264
|
### CSP nonce
|
|
193
265
|
|
|
194
|
-
|
|
266
|
+
Call `configure({ nonce: '...' })` before any rendering happens. The middleware reads the nonce and applies it to injected `<style>` and `<script>` tags.
|
|
195
267
|
|
|
196
268
|
---
|
|
197
269
|
|
|
198
270
|
## Generic Framework Integration
|
|
199
271
|
|
|
200
|
-
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.
|
|
201
273
|
|
|
202
274
|
```tsx
|
|
203
275
|
import {
|
|
204
276
|
ServerStyleCollector,
|
|
205
|
-
|
|
277
|
+
runWithCollector,
|
|
206
278
|
hydrateTastyCache,
|
|
207
279
|
} from '@tenphi/tasty/ssr';
|
|
208
280
|
import { renderToString } from 'react-dom/server';
|
|
@@ -212,10 +284,8 @@ import { hydrateRoot } from 'react-dom/client';
|
|
|
212
284
|
|
|
213
285
|
const collector = new ServerStyleCollector();
|
|
214
286
|
|
|
215
|
-
const html =
|
|
216
|
-
<
|
|
217
|
-
<App />
|
|
218
|
-
</TastySSRContext.Provider>
|
|
287
|
+
const html = await runWithCollector(collector, () =>
|
|
288
|
+
renderToString(<App />)
|
|
219
289
|
);
|
|
220
290
|
|
|
221
291
|
const css = collector.getCSS();
|
|
@@ -251,11 +321,8 @@ For streaming with `renderToPipeableStream`, use `flushCSS()` instead of `getCSS
|
|
|
251
321
|
```tsx
|
|
252
322
|
const collector = new ServerStyleCollector();
|
|
253
323
|
|
|
254
|
-
const stream =
|
|
255
|
-
<
|
|
256
|
-
<App />
|
|
257
|
-
</TastySSRContext.Provider>,
|
|
258
|
-
{
|
|
324
|
+
const stream = await runWithCollector(collector, () =>
|
|
325
|
+
renderToPipeableStream(<App />, {
|
|
259
326
|
onShellReady() {
|
|
260
327
|
// Flush styles collected so far
|
|
261
328
|
const css = collector.flushCSS();
|
|
@@ -270,29 +337,8 @@ const stream = renderToPipeableStream(
|
|
|
270
337
|
const state = collector.getCacheState();
|
|
271
338
|
res.write(`<script data-tasty-cache type="application/json">${JSON.stringify(state)}</script>`);
|
|
272
339
|
},
|
|
273
|
-
}
|
|
274
|
-
);
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
### AsyncLocalStorage (no React context)
|
|
278
|
-
|
|
279
|
-
If your framework doesn't support wrapping the React tree with a provider, use `runWithCollector`:
|
|
280
|
-
|
|
281
|
-
```tsx
|
|
282
|
-
import {
|
|
283
|
-
ServerStyleCollector,
|
|
284
|
-
runWithCollector,
|
|
285
|
-
hydrateTastyCache,
|
|
286
|
-
} from '@tenphi/tasty/ssr';
|
|
287
|
-
|
|
288
|
-
const collector = new ServerStyleCollector();
|
|
289
|
-
|
|
290
|
-
const html = await runWithCollector(collector, () =>
|
|
291
|
-
renderToString(<App />)
|
|
340
|
+
})
|
|
292
341
|
);
|
|
293
|
-
|
|
294
|
-
const css = collector.getCSS();
|
|
295
|
-
// ... inject into HTML as above
|
|
296
342
|
```
|
|
297
343
|
|
|
298
344
|
---
|
|
@@ -303,9 +349,10 @@ const css = collector.getCSS();
|
|
|
303
349
|
|
|
304
350
|
| Import path | Description |
|
|
305
351
|
|---|---|
|
|
306
|
-
| `@tenphi/tasty/ssr` | Core SSR API: `ServerStyleCollector`, `
|
|
352
|
+
| `@tenphi/tasty/ssr` | Core SSR API: `ServerStyleCollector`, `runWithCollector`, `hydrateTastyCache` |
|
|
307
353
|
| `@tenphi/tasty/ssr/next` | Next.js App Router: `TastyRegistry` component |
|
|
308
|
-
| `@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) |
|
|
309
356
|
|
|
310
357
|
### `ServerStyleCollector`
|
|
311
358
|
|
|
@@ -316,15 +363,18 @@ Server-safe style collector. One instance per request.
|
|
|
316
363
|
| `allocateClassName(cacheKey)` | Allocate a sequential class name (`t0`, `t1`, ...) for a cache key. Returns `{ className, isNewAllocation }`. |
|
|
317
364
|
| `collectChunk(cacheKey, className, rules)` | Record CSS rules for a chunk. Deduplicated by `cacheKey`. |
|
|
318
365
|
| `collectKeyframes(name, css)` | Record a `@keyframes` rule. Deduplicated by name. |
|
|
366
|
+
| `allocateKeyframeName(providedName?)` | Allocate a keyframe name. Returns `providedName` if given, otherwise generates one (`k0`, `k1`, ...). |
|
|
319
367
|
| `collectProperty(name, css)` | Record a `@property` rule. Deduplicated by name. |
|
|
368
|
+
| `collectFontFace(key, css)` | Record a `@font-face` rule. Deduplicated by content hash. |
|
|
369
|
+
| `collectCounterStyle(name, css)` | Record a `@counter-style` rule. Deduplicated by name. |
|
|
370
|
+
| `allocateCounterStyleName(providedName?)` | Allocate a counter-style name. Returns `providedName` if given, otherwise generates one (`cs0`, `cs1`, ...). |
|
|
371
|
+
| `collectGlobalStyles(key, css)` | Record global styles (from `useGlobalStyles`). Deduplicated by key. |
|
|
372
|
+
| `collectRawCSS(key, css)` | Record raw CSS text (from `useRawCSS`). Deduplicated by key. |
|
|
373
|
+
| `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. |
|
|
320
374
|
| `getCSS()` | Get all collected CSS as a single string. For non-streaming SSR. |
|
|
321
375
|
| `flushCSS()` | Get only CSS collected since the last flush. For streaming SSR. |
|
|
322
376
|
| `getCacheState()` | Serialize `{ entries: Record<cacheKey, className>, classCounter }` for client hydration. |
|
|
323
377
|
|
|
324
|
-
### `TastySSRContext`
|
|
325
|
-
|
|
326
|
-
React context (`createContext<ServerStyleCollector | null>(null)`). Used by `useStyles()` to find the collector during SSR.
|
|
327
|
-
|
|
328
378
|
### `TastyRegistry`
|
|
329
379
|
|
|
330
380
|
Next.js App Router component. Props:
|
|
@@ -334,9 +384,17 @@ Next.js App Router component. Props:
|
|
|
334
384
|
| `children` | `ReactNode` | required | Application tree |
|
|
335
385
|
| `transferCache` | `boolean` | `true` | Embed cache state script for zero-cost hydration |
|
|
336
386
|
|
|
387
|
+
### `tastyIntegration(options?)`
|
|
388
|
+
|
|
389
|
+
Astro integration factory. Registers middleware and optionally injects client hydration.
|
|
390
|
+
|
|
391
|
+
| Option | Type | Default | Description |
|
|
392
|
+
|---|---|---|---|
|
|
393
|
+
| `islands` | `boolean` | `true` | When `true`, injects client hydration script and enables `transferCache`. When `false`, no client JS is shipped. |
|
|
394
|
+
|
|
337
395
|
### `tastyMiddleware(options?)`
|
|
338
396
|
|
|
339
|
-
Astro middleware factory.
|
|
397
|
+
Astro middleware factory. Use for manual middleware composition.
|
|
340
398
|
|
|
341
399
|
| Option | Type | Default | Description |
|
|
342
400
|
|---|---|---|---|
|
|
@@ -348,7 +406,7 @@ Pre-populate the client injector cache. When called without arguments, reads fro
|
|
|
348
406
|
|
|
349
407
|
### `runWithCollector(collector, fn)`
|
|
350
408
|
|
|
351
|
-
Run a function with a `ServerStyleCollector` bound to the current async context via `AsyncLocalStorage`. All
|
|
409
|
+
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.
|
|
352
410
|
|
|
353
411
|
---
|
|
354
412
|
|
|
@@ -356,15 +414,17 @@ Run a function with a `ServerStyleCollector` bound to the current async context
|
|
|
356
414
|
|
|
357
415
|
### Styles flash on page load (FOUC)
|
|
358
416
|
|
|
359
|
-
The `TastyRegistry` or `
|
|
417
|
+
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).
|
|
360
418
|
|
|
361
419
|
### Hydration mismatch warnings
|
|
362
420
|
|
|
363
|
-
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()`.
|
|
421
|
+
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()`.
|
|
364
422
|
|
|
365
423
|
### Styles duplicated after hydration
|
|
366
424
|
|
|
367
|
-
|
|
425
|
+
**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.
|
|
426
|
+
|
|
427
|
+
**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:
|
|
368
428
|
|
|
369
429
|
```tsx
|
|
370
430
|
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.
|
|
@@ -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
|
|
|
@@ -359,24 +378,27 @@ 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 a modifier. When a modifier is used alone (without a name), the preset name defaults to `inherit`.
|
|
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="t3 italic"
|
|
379
|
-
preset="t2 tight"
|
|
397
|
+
preset="h1" // heading 1
|
|
398
|
+
preset="h2 / strong" // bold heading 2
|
|
399
|
+
preset="t3 / italic" // italic text 3
|
|
400
|
+
preset="t2 / tight" // text 2 with tight line-height
|
|
401
|
+
preset="bold" // inherit preset with bold (shorthand for "inherit / bold")
|
|
380
402
|
```
|
|
381
403
|
|
|
382
404
|
Individual typography props (`fontSize`, `lineHeight`, `letterSpacing`, `fontWeight`, `fontStyle`, `textTransform`) can be used alongside `preset` to override specific values, but using `preset` alone is recommended.
|