@tenphi/tasty 0.0.0-snapshot.056b911
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/LICENSE +21 -0
- package/README.md +635 -0
- package/dist/_virtual/_rolldown/runtime.js +7 -0
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +77 -0
- package/dist/chunks/cacheKey.js.map +1 -0
- package/dist/chunks/definitions.d.ts +37 -0
- package/dist/chunks/definitions.js +258 -0
- package/dist/chunks/definitions.js.map +1 -0
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +59 -0
- package/dist/chunks/renderChunk.js.map +1 -0
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +335 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +409 -0
- package/dist/config.js +584 -0
- package/dist/config.js.map +1 -0
- package/dist/core/index.d.ts +34 -0
- package/dist/core/index.js +27 -0
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +89 -0
- package/dist/debug.js +453 -0
- package/dist/debug.js.map +1 -0
- 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 +64 -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 +46 -0
- package/dist/hooks/useGlobalStyles.js +88 -0
- package/dist/hooks/useGlobalStyles.js.map +1 -0
- package/dist/hooks/useKeyframes.d.ts +58 -0
- package/dist/hooks/useKeyframes.js +54 -0
- package/dist/hooks/useKeyframes.js.map +1 -0
- package/dist/hooks/useProperty.d.ts +81 -0
- package/dist/hooks/useProperty.js +96 -0
- package/dist/hooks/useProperty.js.map +1 -0
- package/dist/hooks/useRawCSS.d.ts +22 -0
- package/dist/hooks/useRawCSS.js +103 -0
- package/dist/hooks/useRawCSS.js.map +1 -0
- package/dist/hooks/useStyles.d.ts +40 -0
- package/dist/hooks/useStyles.js +31 -0
- package/dist/hooks/useStyles.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +36 -0
- package/dist/injector/index.d.ts +182 -0
- package/dist/injector/index.js +185 -0
- package/dist/injector/index.js.map +1 -0
- package/dist/injector/injector.d.ts +193 -0
- package/dist/injector/injector.js +564 -0
- package/dist/injector/injector.js.map +1 -0
- package/dist/injector/sheet-manager.d.ts +132 -0
- package/dist/injector/sheet-manager.js +698 -0
- package/dist/injector/sheet-manager.js.map +1 -0
- package/dist/injector/types.d.ts +228 -0
- package/dist/keyframes/index.js +206 -0
- package/dist/keyframes/index.js.map +1 -0
- package/dist/parser/classify.js +319 -0
- package/dist/parser/classify.js.map +1 -0
- package/dist/parser/const.js +60 -0
- package/dist/parser/const.js.map +1 -0
- package/dist/parser/lru.js +109 -0
- package/dist/parser/lru.js.map +1 -0
- package/dist/parser/parser.d.ts +25 -0
- package/dist/parser/parser.js +115 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/tokenizer.js +69 -0
- package/dist/parser/tokenizer.js.map +1 -0
- package/dist/parser/types.d.ts +51 -0
- package/dist/parser/types.js +46 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/pipeline/conditions.d.ts +134 -0
- package/dist/pipeline/conditions.js +406 -0
- package/dist/pipeline/conditions.js.map +1 -0
- package/dist/pipeline/exclusive.js +230 -0
- package/dist/pipeline/exclusive.js.map +1 -0
- package/dist/pipeline/index.d.ts +55 -0
- package/dist/pipeline/index.js +708 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/materialize.js +1103 -0
- package/dist/pipeline/materialize.js.map +1 -0
- package/dist/pipeline/parseStateKey.d.ts +15 -0
- package/dist/pipeline/parseStateKey.js +446 -0
- package/dist/pipeline/parseStateKey.js.map +1 -0
- package/dist/pipeline/simplify.js +515 -0
- package/dist/pipeline/simplify.js.map +1 -0
- package/dist/pipeline/warnings.js +18 -0
- package/dist/pipeline/warnings.js.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.d.ts +35 -0
- package/dist/plugins/okhsl-plugin.js +97 -0
- package/dist/plugins/okhsl-plugin.js.map +1 -0
- package/dist/plugins/types.d.ts +87 -0
- package/dist/properties/index.js +222 -0
- package/dist/properties/index.js.map +1 -0
- package/dist/properties/property-type-resolver.d.ts +24 -0
- package/dist/properties/property-type-resolver.js +90 -0
- package/dist/properties/property-type-resolver.js.map +1 -0
- package/dist/rsc-cache.js +81 -0
- package/dist/rsc-cache.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +24 -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 +106 -0
- package/dist/ssr/astro.js +149 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +44 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +58 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +102 -0
- package/dist/ssr/collector.js +227 -0
- package/dist/ssr/collector.js.map +1 -0
- package/dist/ssr/context.js +16 -0
- package/dist/ssr/context.js.map +1 -0
- package/dist/ssr/format-global-rules.js +22 -0
- package/dist/ssr/format-global-rules.js.map +1 -0
- package/dist/ssr/format-keyframes.js +69 -0
- package/dist/ssr/format-keyframes.js.map +1 -0
- package/dist/ssr/format-property.js +49 -0
- package/dist/ssr/format-property.js.map +1 -0
- package/dist/ssr/format-rules.js +73 -0
- package/dist/ssr/format-rules.js.map +1 -0
- package/dist/ssr/hydrate.d.ts +22 -0
- package/dist/ssr/hydrate.js +49 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/index.d.ts +4 -0
- package/dist/ssr/index.js +10 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +45 -0
- package/dist/ssr/next.js +75 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/ssr/ssr-collector-ref.js +29 -0
- package/dist/ssr/ssr-collector-ref.js.map +1 -0
- package/dist/states/index.d.ts +49 -0
- package/dist/states/index.js +170 -0
- package/dist/states/index.js.map +1 -0
- package/dist/static/index.d.ts +5 -0
- package/dist/static/index.js +4 -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/static/tastyStatic.d.ts +46 -0
- package/dist/static/tastyStatic.js +30 -0
- package/dist/static/tastyStatic.js.map +1 -0
- package/dist/static/types.d.ts +49 -0
- package/dist/static/types.js +24 -0
- package/dist/static/types.js.map +1 -0
- package/dist/styles/border.d.ts +25 -0
- package/dist/styles/border.js +120 -0
- package/dist/styles/border.js.map +1 -0
- package/dist/styles/color.d.ts +14 -0
- package/dist/styles/color.js +26 -0
- package/dist/styles/color.js.map +1 -0
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +79 -0
- package/dist/styles/createStyle.js.map +1 -0
- package/dist/styles/dimension.js +109 -0
- package/dist/styles/dimension.js.map +1 -0
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +30 -0
- package/dist/styles/display.js +73 -0
- package/dist/styles/display.js.map +1 -0
- package/dist/styles/fade.d.ts +15 -0
- package/dist/styles/fade.js +62 -0
- package/dist/styles/fade.js.map +1 -0
- package/dist/styles/fill.d.ts +42 -0
- package/dist/styles/fill.js +51 -0
- package/dist/styles/fill.js.map +1 -0
- package/dist/styles/flow.d.ts +16 -0
- package/dist/styles/flow.js +12 -0
- package/dist/styles/flow.js.map +1 -0
- package/dist/styles/gap.d.ts +31 -0
- package/dist/styles/gap.js +38 -0
- package/dist/styles/gap.js.map +1 -0
- package/dist/styles/height.d.ts +17 -0
- package/dist/styles/height.js +19 -0
- package/dist/styles/height.js.map +1 -0
- package/dist/styles/index.d.ts +1 -0
- package/dist/styles/index.js +8 -0
- package/dist/styles/index.js.map +1 -0
- package/dist/styles/inset.d.ts +24 -0
- package/dist/styles/inset.js +34 -0
- package/dist/styles/inset.js.map +1 -0
- package/dist/styles/list.d.ts +16 -0
- package/dist/styles/list.js +100 -0
- package/dist/styles/list.js.map +1 -0
- package/dist/styles/margin.d.ts +24 -0
- package/dist/styles/margin.js +32 -0
- package/dist/styles/margin.js.map +1 -0
- package/dist/styles/outline.d.ts +29 -0
- package/dist/styles/outline.js +55 -0
- package/dist/styles/outline.js.map +1 -0
- package/dist/styles/padding.d.ts +24 -0
- package/dist/styles/padding.js +32 -0
- package/dist/styles/padding.js.map +1 -0
- 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 +71 -0
- package/dist/styles/predefined.js +237 -0
- package/dist/styles/predefined.js.map +1 -0
- package/dist/styles/preset.d.ts +52 -0
- package/dist/styles/preset.js +127 -0
- package/dist/styles/preset.js.map +1 -0
- package/dist/styles/radius.d.ts +12 -0
- package/dist/styles/radius.js +83 -0
- package/dist/styles/radius.js.map +1 -0
- 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 +25 -0
- package/dist/styles/scrollbar.js +51 -0
- package/dist/styles/scrollbar.js.map +1 -0
- package/dist/styles/shadow.d.ts +14 -0
- package/dist/styles/shadow.js +25 -0
- package/dist/styles/shadow.js.map +1 -0
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +14 -0
- package/dist/styles/transition.js +159 -0
- package/dist/styles/transition.js.map +1 -0
- package/dist/styles/types.d.ts +564 -0
- package/dist/styles/width.d.ts +17 -0
- package/dist/styles/width.js +19 -0
- package/dist/styles/width.js.map +1 -0
- package/dist/tasty.d.ts +134 -0
- package/dist/tasty.js +243 -0
- package/dist/tasty.js.map +1 -0
- package/dist/types.d.ts +184 -0
- package/dist/utils/cache-wrapper.js +21 -0
- package/dist/utils/cache-wrapper.js.map +1 -0
- package/dist/utils/case-converter.js +8 -0
- package/dist/utils/case-converter.js.map +1 -0
- package/dist/utils/color-math.d.ts +46 -0
- package/dist/utils/color-math.js +749 -0
- package/dist/utils/color-math.js.map +1 -0
- package/dist/utils/color-space.d.ts +5 -0
- package/dist/utils/color-space.js +228 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.d.ts +5 -0
- package/dist/utils/colors.js +10 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/css-types.d.ts +7 -0
- package/dist/utils/deps-equal.js +15 -0
- package/dist/utils/deps-equal.js.map +1 -0
- package/dist/utils/dotize.d.ts +26 -0
- package/dist/utils/dotize.js +122 -0
- package/dist/utils/dotize.js.map +1 -0
- package/dist/utils/filter-base-props.d.ts +15 -0
- package/dist/utils/filter-base-props.js +45 -0
- package/dist/utils/filter-base-props.js.map +1 -0
- package/dist/utils/get-display-name.d.ts +7 -0
- package/dist/utils/get-display-name.js +10 -0
- package/dist/utils/get-display-name.js.map +1 -0
- package/dist/utils/has-keys.js +13 -0
- package/dist/utils/has-keys.js.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/is-dev-env.js +19 -0
- package/dist/utils/is-dev-env.js.map +1 -0
- package/dist/utils/is-valid-element-type.js +15 -0
- package/dist/utils/is-valid-element-type.js.map +1 -0
- package/dist/utils/merge-styles.d.ts +7 -0
- package/dist/utils/merge-styles.js +145 -0
- package/dist/utils/merge-styles.js.map +1 -0
- package/dist/utils/mod-attrs.d.ts +6 -0
- package/dist/utils/mod-attrs.js +20 -0
- package/dist/utils/mod-attrs.js.map +1 -0
- package/dist/utils/process-tokens.d.ts +17 -0
- package/dist/utils/process-tokens.js +83 -0
- package/dist/utils/process-tokens.js.map +1 -0
- package/dist/utils/resolve-recipes.d.ts +17 -0
- package/dist/utils/resolve-recipes.js +146 -0
- package/dist/utils/resolve-recipes.js.map +1 -0
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/styles.d.ts +99 -0
- package/dist/utils/styles.js +220 -0
- package/dist/utils/styles.js.map +1 -0
- package/dist/utils/typography.d.ts +58 -0
- package/dist/utils/typography.js +51 -0
- package/dist/utils/typography.js.map +1 -0
- package/dist/utils/warnings.d.ts +16 -0
- package/dist/utils/warnings.js +16 -0
- package/dist/utils/warnings.js.map +1 -0
- package/dist/zero/babel.d.ts +195 -0
- package/dist/zero/babel.js +456 -0
- package/dist/zero/babel.js.map +1 -0
- package/dist/zero/css-writer.d.ts +45 -0
- package/dist/zero/css-writer.js +73 -0
- package/dist/zero/css-writer.js.map +1 -0
- package/dist/zero/extractor.d.ts +24 -0
- package/dist/zero/extractor.js +266 -0
- package/dist/zero/extractor.js.map +1 -0
- package/dist/zero/index.d.ts +3 -0
- package/dist/zero/index.js +3 -0
- package/dist/zero/next.d.ts +86 -0
- package/dist/zero/next.js +143 -0
- package/dist/zero/next.js.map +1 -0
- package/docs/PIPELINE.md +519 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +298 -0
- package/docs/comparison.md +419 -0
- package/docs/configuration.md +389 -0
- package/docs/debug.md +318 -0
- package/docs/design-system.md +436 -0
- package/docs/dsl.md +688 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +544 -0
- package/docs/methodology.md +616 -0
- package/docs/react-api.md +557 -0
- package/docs/ssr.md +440 -0
- package/docs/styles.md +596 -0
- package/docs/tasty-static.md +532 -0
- package/package.json +221 -0
- package/tasty.config.ts +14 -0
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
# Zero Runtime Mode (tastyStatic)
|
|
2
|
+
|
|
3
|
+
`tastyStatic` is a build-time utility for generating CSS with zero runtime overhead. It's designed for static sites, no-JS websites, and performance-critical applications where you want to eliminate all runtime styling code. For the broader docs map, see the [Docs Hub](README.md).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
- **Static site generation (SSG)** — Pre-render all styles at build time
|
|
10
|
+
- **No-JavaScript websites** — CSS works without any JS runtime
|
|
11
|
+
- **Performance-critical pages** — Zero runtime overhead for styling
|
|
12
|
+
- **Landing pages** — Minimal bundle size with pre-generated CSS
|
|
13
|
+
|
|
14
|
+
## Requirements
|
|
15
|
+
|
|
16
|
+
The zero-runtime mode is part of the main `@tenphi/tasty` package but requires additional peer dependencies depending on your setup:
|
|
17
|
+
|
|
18
|
+
| Dependency | Version | Required for |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| `@babel/core` | >= 7.24 | Babel plugin (`@tenphi/tasty/babel-plugin`) |
|
|
21
|
+
| `@babel/helper-plugin-utils` | >= 7.24 | Babel plugin |
|
|
22
|
+
| `@babel/types` | >= 7.24 | Babel plugin |
|
|
23
|
+
| `jiti` | >= 2.6 | Next.js wrapper (`@tenphi/tasty/next`) when using `configFile` option |
|
|
24
|
+
|
|
25
|
+
All of these are declared as optional peer dependencies of `@tenphi/tasty`. Install only what your setup requires:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# For any Babel-based setup (Vite, custom Babel config, etc.)
|
|
29
|
+
pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types
|
|
30
|
+
|
|
31
|
+
# For Next.js with TypeScript config file
|
|
32
|
+
pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types jiti
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### Basic Usage
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { tastyStatic } from '@tenphi/tasty/static';
|
|
43
|
+
|
|
44
|
+
// Define styles - returns StaticStyle object
|
|
45
|
+
const button = tastyStatic({
|
|
46
|
+
display: 'inline-flex',
|
|
47
|
+
padding: '2x 4x',
|
|
48
|
+
fill: '#purple',
|
|
49
|
+
color: '#white',
|
|
50
|
+
radius: '1r',
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Use in JSX - works via toString() coercion
|
|
54
|
+
<button className={button}>Click me</button>
|
|
55
|
+
|
|
56
|
+
// Or access className explicitly
|
|
57
|
+
<button className={button.className}>Click me</button>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## API Reference
|
|
63
|
+
|
|
64
|
+
### tastyStatic(styles)
|
|
65
|
+
|
|
66
|
+
Creates a `StaticStyle` object from a styles definition.
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
const card = tastyStatic({
|
|
70
|
+
padding: '4x',
|
|
71
|
+
fill: '#white',
|
|
72
|
+
border: true,
|
|
73
|
+
radius: true,
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### tastyStatic(base, styles)
|
|
78
|
+
|
|
79
|
+
Extends an existing `StaticStyle` with additional styles. Uses `mergeStyles` internally for proper nested selector handling.
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
const button = tastyStatic({
|
|
83
|
+
padding: '2x 4x',
|
|
84
|
+
fill: '#blue',
|
|
85
|
+
Icon: { color: '#white' },
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const primaryButton = tastyStatic(button, {
|
|
89
|
+
fill: '#purple',
|
|
90
|
+
Icon: { opacity: 0.8 },
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### tastyStatic(selector, styles)
|
|
95
|
+
|
|
96
|
+
Generates global styles for a CSS selector. The call is removed from the bundle after transformation.
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
tastyStatic('body', {
|
|
100
|
+
fill: '#surface',
|
|
101
|
+
color: '#text',
|
|
102
|
+
preset: 't3',
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## StaticStyle Object
|
|
109
|
+
|
|
110
|
+
| Property | Type | Description |
|
|
111
|
+
|----------|------|-------------|
|
|
112
|
+
| `className` | `string` | Space-separated class names for use in JSX |
|
|
113
|
+
| `styles` | `Styles` | The original (or merged) styles object |
|
|
114
|
+
| `toString()` | `() => string` | Returns `className` for string coercion |
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Babel Plugin Configuration
|
|
119
|
+
|
|
120
|
+
### Basic Configuration
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
// babel.config.js
|
|
124
|
+
module.exports = {
|
|
125
|
+
plugins: [
|
|
126
|
+
['@tenphi/tasty/babel-plugin', {
|
|
127
|
+
output: 'public/tasty.css',
|
|
128
|
+
}]
|
|
129
|
+
]
|
|
130
|
+
};
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
These examples use `data-schema="dark"` as the root-state convention. If your app already uses a different root attribute such as `data-theme`, keep the same alias pattern and swap the attribute name consistently in your zero-runtime config.
|
|
134
|
+
|
|
135
|
+
### With Configuration
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
module.exports = {
|
|
139
|
+
plugins: [
|
|
140
|
+
['@tenphi/tasty/babel-plugin', {
|
|
141
|
+
output: 'public/tasty.css',
|
|
142
|
+
config: {
|
|
143
|
+
states: {
|
|
144
|
+
'@mobile': '@media(w < 768px)',
|
|
145
|
+
'@tablet': '@media(w < 1024px)',
|
|
146
|
+
'@dark': '@root(schema=dark)',
|
|
147
|
+
},
|
|
148
|
+
devMode: true,
|
|
149
|
+
},
|
|
150
|
+
}]
|
|
151
|
+
]
|
|
152
|
+
};
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Plugin Options
|
|
156
|
+
|
|
157
|
+
| Option | Type | Default | Description |
|
|
158
|
+
|--------|------|---------|-------------|
|
|
159
|
+
| `output` | `string` | `'tasty.css'` | Path for generated CSS file |
|
|
160
|
+
| `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS (see [Inject Mode](#inject-mode)) |
|
|
161
|
+
| `configFile` | `string` | — | Absolute path to a TS/JS module that default-exports a `TastyZeroConfig` object. JSON-serializable alternative to `config` — required for Turbopack. |
|
|
162
|
+
| `config` | `TastyZeroConfig \| () => TastyZeroConfig` | `{}` | Inline config object or factory function. Takes precedence over `configFile`. |
|
|
163
|
+
| `configDeps` | `string[]` | `[]` | Absolute file paths that affect config (for cache invalidation) |
|
|
164
|
+
| `injectImport` | `boolean` | `true` | Replace `@tenphi/tasty/static` imports with an import of the generated CSS file. Set to `false` to manage CSS imports manually. |
|
|
165
|
+
| `config.states` | `Record<string, string>` | `{}` | Predefined state aliases (e.g. `{ '@mobile': '@media(w < 768px)' }`) |
|
|
166
|
+
| `config.devMode` | `boolean` | `false` | Add source comments to CSS |
|
|
167
|
+
| `config.tokens` | `ConfigTokens` | — | Design tokens injected as CSS custom properties on `:root`. Values are parsed through the Tasty DSL. Supports state maps for responsive/themed tokens. |
|
|
168
|
+
| `config.replaceTokens` | `Record<string, string \| number>` | — | Parse-time token substitution. Keys use `$name` for custom properties and `#name` for color tokens. |
|
|
169
|
+
| `config.recipes` | `Record<string, RecipeStyles>` | `{}` | Predefined style recipes |
|
|
170
|
+
| `config.keyframes` | `Record<string, KeyframesSteps>` | — | Global `@keyframes` definitions available to all `tastyStatic` calls |
|
|
171
|
+
| `config.fontFace` | `Record<string, FontFaceInput>` | — | Global `@font-face` definitions |
|
|
172
|
+
| `config.counterStyle` | `Record<string, CounterStyleDescriptors>` | — | Global `@counter-style` definitions |
|
|
173
|
+
| `config.units` | `Record<string, string \| UnitHandler>` | — | Custom units for the style parser (merged with built-ins). E.g. `{ em: 'em', vw: 'vw' }` |
|
|
174
|
+
| `config.funcs` | `Record<string, Function>` | — | Custom functions for the style parser (merged with existing) |
|
|
175
|
+
| `config.plugins` | `TastyPlugin[]` | — | Plugins that extend tasty with custom functions, units, states, and handlers |
|
|
176
|
+
| `config.handlers` | `Record<string, StyleHandlerDefinition>` | — | Custom style handlers that transform style properties into CSS declarations |
|
|
177
|
+
| `config.presets` | `Record<string, TypographyPreset>` | — | Typography presets — shorthand for `generateTypographyTokens()`. Generated tokens merge under explicit `tokens`. |
|
|
178
|
+
| `config.bodyStyles` | `Styles` | — | Tasty styles applied to the `body` tag. Supports the full style syntax. |
|
|
179
|
+
| `config.autoPropertyTypes` | `boolean` | `true` | Automatically infer and register CSS `@property` declarations from values |
|
|
180
|
+
| `config.parserCacheSize` | `number` | `1000` | Parser LRU cache size. Larger values improve performance for builds with many unique style values |
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Recipes
|
|
185
|
+
|
|
186
|
+
Recipes work with `tastyStatic` the same way as with runtime `tasty`:
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
// babel.config.js
|
|
190
|
+
module.exports = {
|
|
191
|
+
plugins: [
|
|
192
|
+
['@tenphi/tasty/babel-plugin', {
|
|
193
|
+
output: 'public/tasty.css',
|
|
194
|
+
config: {
|
|
195
|
+
recipes: {
|
|
196
|
+
card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
|
|
197
|
+
elevated: { shadow: '2x 2x 4x #shadow' },
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
}]
|
|
201
|
+
]
|
|
202
|
+
};
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
```tsx
|
|
206
|
+
import { tastyStatic } from '@tenphi/tasty/static';
|
|
207
|
+
|
|
208
|
+
const card = tastyStatic({
|
|
209
|
+
recipe: 'card elevated',
|
|
210
|
+
color: '#text',
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
<div className={card}>Styled card</div>
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Next.js Integration
|
|
219
|
+
|
|
220
|
+
The `withTastyZero` wrapper configures both **webpack** and **Turbopack** automatically. No `--webpack` flag is needed — it works with whichever bundler Next.js uses.
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
// next.config.ts
|
|
224
|
+
import { withTastyZero } from '@tenphi/tasty/next';
|
|
225
|
+
|
|
226
|
+
export default withTastyZero({
|
|
227
|
+
output: 'public/tasty.css',
|
|
228
|
+
configFile: './app/tasty-zero.config.ts',
|
|
229
|
+
configDeps: ['./app/theme.ts'],
|
|
230
|
+
})({
|
|
231
|
+
reactStrictMode: true,
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### `withTastyZero` Options
|
|
236
|
+
|
|
237
|
+
| Option | Type | Default | Description |
|
|
238
|
+
|--------|------|---------|-------------|
|
|
239
|
+
| `output` | `string` | `'public/tasty.css'` | Output path for CSS relative to project root |
|
|
240
|
+
| `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS |
|
|
241
|
+
| `enabled` | `boolean` | `true` | Enable/disable the plugin |
|
|
242
|
+
| `configFile` | `string` | — | Path to a TS/JS module that default-exports `TastyZeroConfig`. Recommended for Turbopack compatibility. |
|
|
243
|
+
| `config` | `TastyZeroConfig` | — | Inline config object. For static configs that don't change during dev. |
|
|
244
|
+
| `configDeps` | `string[]` | `[]` | Extra files the config depends on (for cache invalidation) |
|
|
245
|
+
|
|
246
|
+
### Turbopack Support
|
|
247
|
+
|
|
248
|
+
Starting with Next.js 16, Turbopack is the default bundler. `withTastyZero` supports it out of the box by injecting `turbopack.rules` with `babel-loader` and JSON-serializable options.
|
|
249
|
+
|
|
250
|
+
The `configFile` option is key for Turbopack — it passes a file path (JSON-serializable) instead of a function, and the Babel plugin loads the config internally via jiti.
|
|
251
|
+
|
|
252
|
+
**Requirements**: `babel-loader` must be installed in your project:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
pnpm add babel-loader
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### CSS Injection
|
|
259
|
+
|
|
260
|
+
`withTastyZero` automatically injects the generated CSS into your app. Every file that imports from `@tenphi/tasty/static` gets its import replaced with an import of the output CSS file at build time. No manual CSS import is needed.
|
|
261
|
+
|
|
262
|
+
The generated CSS file (e.g. `public/tasty.css`) is created as an empty stub before the first build if it doesn't exist, so there's no chicken-and-egg problem with fresh clones or CI builds. Add it to `.gitignore`:
|
|
263
|
+
|
|
264
|
+
```gitignore
|
|
265
|
+
public/tasty.css
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Vite Integration
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
// vite.config.ts
|
|
274
|
+
import { defineConfig } from 'vite';
|
|
275
|
+
import react from '@vitejs/plugin-react';
|
|
276
|
+
|
|
277
|
+
export default defineConfig({
|
|
278
|
+
plugins: [
|
|
279
|
+
react({
|
|
280
|
+
babel: {
|
|
281
|
+
plugins: [
|
|
282
|
+
['@tenphi/tasty/babel-plugin', {
|
|
283
|
+
output: 'public/tasty.css',
|
|
284
|
+
config: {
|
|
285
|
+
states: { '@mobile': '@media(w < 768px)' },
|
|
286
|
+
},
|
|
287
|
+
}],
|
|
288
|
+
],
|
|
289
|
+
},
|
|
290
|
+
}),
|
|
291
|
+
],
|
|
292
|
+
});
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## Build Transformation
|
|
298
|
+
|
|
299
|
+
### Before (Source Code)
|
|
300
|
+
|
|
301
|
+
```tsx
|
|
302
|
+
import { tastyStatic } from '@tenphi/tasty/static';
|
|
303
|
+
|
|
304
|
+
const button = tastyStatic({
|
|
305
|
+
padding: '2x 4x',
|
|
306
|
+
fill: '#purple',
|
|
307
|
+
color: '#white',
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
tastyStatic('.heading', { preset: 'h1' });
|
|
311
|
+
|
|
312
|
+
export const Button = () => <button className={button}>Click</button>;
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### After (Production Build)
|
|
316
|
+
|
|
317
|
+
```tsx
|
|
318
|
+
const button = {
|
|
319
|
+
className: 'ts3f2a1b ts8c4d2e',
|
|
320
|
+
styles: { padding: '2x 4x', fill: '#purple', color: '#white' },
|
|
321
|
+
toString() { return this.className; }
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
export const Button = () => <button className={button}>Click</button>;
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Generated CSS (tasty.css)
|
|
328
|
+
|
|
329
|
+
```css
|
|
330
|
+
/* Generated by @tenphi/tasty/zero - DO NOT EDIT */
|
|
331
|
+
|
|
332
|
+
.ts3f2a1b.ts3f2a1b {
|
|
333
|
+
padding: 16px 32px;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
.ts8c4d2e.ts8c4d2e {
|
|
337
|
+
background: #9370db;
|
|
338
|
+
color: #fff;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.heading.heading {
|
|
342
|
+
font-size: 2.5rem;
|
|
343
|
+
font-weight: 700;
|
|
344
|
+
line-height: 1.2;
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
## Inject Mode
|
|
351
|
+
|
|
352
|
+
By default the Babel plugin writes CSS to a file (`mode: 'file'`). **Inject mode** (`mode: 'inject'`) embeds CSS inline in your JavaScript and injects it at runtime via a tiny injector. No CSS file is produced.
|
|
353
|
+
|
|
354
|
+
This is ideal for **reusable components**, **extensions**, and **libraries** where consumers shouldn't need to manage an external CSS file.
|
|
355
|
+
|
|
356
|
+
### How It Works
|
|
357
|
+
|
|
358
|
+
1. The Babel plugin extracts CSS at build time (same pipeline as file mode).
|
|
359
|
+
2. Instead of writing to a `.css` file, the CSS is embedded as string literals in the JS output.
|
|
360
|
+
3. The `@tenphi/tasty/static` import is rewritten to `@tenphi/tasty/static/inject`.
|
|
361
|
+
4. Each `tastyStatic` call becomes a self-contained expression that injects its CSS and evaluates to a `StaticStyle` object.
|
|
362
|
+
|
|
363
|
+
### Configuration
|
|
364
|
+
|
|
365
|
+
```javascript
|
|
366
|
+
// babel.config.js
|
|
367
|
+
module.exports = {
|
|
368
|
+
plugins: [
|
|
369
|
+
['@tenphi/tasty/babel-plugin', {
|
|
370
|
+
mode: 'inject',
|
|
371
|
+
config: {
|
|
372
|
+
states: { '@mobile': '@media(w < 768px)' },
|
|
373
|
+
},
|
|
374
|
+
}]
|
|
375
|
+
]
|
|
376
|
+
};
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
With Next.js:
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
// next.config.ts
|
|
383
|
+
import { withTastyZero } from '@tenphi/tasty/next';
|
|
384
|
+
|
|
385
|
+
export default withTastyZero({
|
|
386
|
+
mode: 'inject',
|
|
387
|
+
configFile: './app/tasty-zero.config.ts',
|
|
388
|
+
})({
|
|
389
|
+
reactStrictMode: true,
|
|
390
|
+
});
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
When `mode` is `'inject'`, the `output` and `injectImport` options are ignored.
|
|
394
|
+
|
|
395
|
+
### Build Transformation (inject mode)
|
|
396
|
+
|
|
397
|
+
**Before:**
|
|
398
|
+
|
|
399
|
+
```tsx
|
|
400
|
+
import { tastyStatic } from '@tenphi/tasty/static';
|
|
401
|
+
|
|
402
|
+
const button = tastyStatic({
|
|
403
|
+
padding: '2x 4x',
|
|
404
|
+
fill: '#purple',
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
tastyStatic('.heading', { preset: 'h1' });
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
**After:**
|
|
411
|
+
|
|
412
|
+
```tsx
|
|
413
|
+
import { injectCSS as _$i } from '@tenphi/tasty/static/inject';
|
|
414
|
+
|
|
415
|
+
const button = (_$i("ts3f2a1b ts8c4d2e", ".ts3f2a1b.ts3f2a1b{padding:16px 32px}\n.ts8c4d2e.ts8c4d2e{background:#9370db}"), {
|
|
416
|
+
className: 'ts3f2a1b ts8c4d2e',
|
|
417
|
+
styles: { padding: '2x 4x', fill: '#purple' },
|
|
418
|
+
toString() { return this.className; }
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
_$i(".heading", ".heading{font-size:2.5rem;font-weight:700;line-height:1.2}");
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
### Dev Mode / HMR
|
|
425
|
+
|
|
426
|
+
Class names are content-hashed (`ts` + MD5). When styles change, a new hash produces a new `_$i` call that injects fresh CSS. The injector deduplicates by id, so unchanged styles are skipped. Old CSS stays in the DOM but is harmless since no elements reference those class names.
|
|
427
|
+
|
|
428
|
+
### Limitations (inject mode)
|
|
429
|
+
|
|
430
|
+
- **Client-side only** — Styles are injected via the DOM, so they are not available during SSR. For server-rendered apps, use `mode: 'file'` or the runtime `tasty()`.
|
|
431
|
+
- **Larger JS bundle** — CSS is embedded in JavaScript, increasing bundle size. Best suited for components and extensions, not full-app styling.
|
|
432
|
+
|
|
433
|
+
---
|
|
434
|
+
|
|
435
|
+
## Style Extension
|
|
436
|
+
|
|
437
|
+
```tsx
|
|
438
|
+
// Base button
|
|
439
|
+
const button = tastyStatic({
|
|
440
|
+
display: 'inline-flex',
|
|
441
|
+
padding: '2x 4x',
|
|
442
|
+
radius: '1r',
|
|
443
|
+
fill: '#gray.20',
|
|
444
|
+
color: '#text',
|
|
445
|
+
transition: 'fill 0.15s',
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
// Variants
|
|
449
|
+
const primaryButton = tastyStatic(button, {
|
|
450
|
+
fill: '#purple',
|
|
451
|
+
color: '#white',
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const dangerButton = tastyStatic(button, {
|
|
455
|
+
fill: '#danger',
|
|
456
|
+
color: '#white',
|
|
457
|
+
});
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
---
|
|
461
|
+
|
|
462
|
+
## State-based Styling
|
|
463
|
+
|
|
464
|
+
```tsx
|
|
465
|
+
const card = tastyStatic({
|
|
466
|
+
padding: {
|
|
467
|
+
'': '4x',
|
|
468
|
+
'@mobile': '2x',
|
|
469
|
+
},
|
|
470
|
+
display: {
|
|
471
|
+
'': 'flex',
|
|
472
|
+
'@mobile': 'block',
|
|
473
|
+
},
|
|
474
|
+
});
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
## Extending Style Types (TypeScript)
|
|
480
|
+
|
|
481
|
+
If you add custom style properties, use module augmentation so `tastyStatic` recognizes them too. See [Extending Style Types](configuration.md#extending-style-types-typescript) in the configuration docs.
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
## Limitations
|
|
486
|
+
|
|
487
|
+
1. **Static values only** — All style values must be known at build time
|
|
488
|
+
2. **No runtime props** — Cannot use `styleProps` or dynamic `styles` prop
|
|
489
|
+
3. **No mods at runtime** — Modifiers must be defined statically
|
|
490
|
+
4. **Build-time transformation required** — Babel plugin must process files
|
|
491
|
+
|
|
492
|
+
### Workarounds
|
|
493
|
+
|
|
494
|
+
For dynamic styling needs, combine with regular CSS or CSS variables:
|
|
495
|
+
|
|
496
|
+
```tsx
|
|
497
|
+
const card = tastyStatic({
|
|
498
|
+
padding: '4x',
|
|
499
|
+
fill: 'var(--card-bg, #white)',
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
<div
|
|
503
|
+
className={card}
|
|
504
|
+
style={{ '--card-bg': isActive ? '#purple' : '#white' }}
|
|
505
|
+
/>
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
---
|
|
509
|
+
|
|
510
|
+
## Best Practices
|
|
511
|
+
|
|
512
|
+
1. **Define base styles** for common patterns, then extend for variants
|
|
513
|
+
2. **Use selector mode** for global/body styles
|
|
514
|
+
3. **Enable devMode** in development for easier debugging
|
|
515
|
+
4. **Configure states** for consistent responsive breakpoints
|
|
516
|
+
|
|
517
|
+
---
|
|
518
|
+
|
|
519
|
+
## Common Issues
|
|
520
|
+
|
|
521
|
+
- No CSS file is generated: make sure the Babel plugin actually runs for files importing `@tenphi/tasty/static`, and verify the `output` path is writable.
|
|
522
|
+
- Styles stay dynamic by mistake: `tastyStatic()` only supports build-time-known values. Move runtime values to CSS variables or switch that component to runtime `tasty()`.
|
|
523
|
+
- Turbopack config behaves inconsistently: prefer `configFile` over inline functions so the setup stays JSON-serializable.
|
|
524
|
+
|
|
525
|
+
---
|
|
526
|
+
|
|
527
|
+
## Related
|
|
528
|
+
|
|
529
|
+
- [Docs Hub](README.md) — Choose the right guide by task or rendering mode
|
|
530
|
+
- [Style DSL](dsl.md) — State maps, tokens, units, extending semantics (shared by runtime and static)
|
|
531
|
+
- [React API](react-api.md) — Runtime styling: `tasty()` factory, component props, variants, sub-elements, style functions
|
|
532
|
+
- [Configuration](configuration.md) — Global configuration: tokens, recipes, custom units, and style handlers
|