@tenphi/tasty 0.0.0-snapshot.2705ab9 → 0.0.0-snapshot.272039a
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 +441 -362
- package/dist/babel-types-Dc5zghyE.d.ts +18 -0
- package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
- package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
- package/dist/chunks/build-config-D9Iq8QQm.js +60 -0
- package/dist/chunks/build-config-D9Iq8QQm.js.map +1 -0
- package/dist/chunks/collector-Cb8ah2JF.js +210 -0
- package/dist/chunks/collector-Cb8ah2JF.js.map +1 -0
- package/dist/chunks/config-engine-CMYFZYQh.js +272 -0
- package/dist/chunks/config-engine-CMYFZYQh.js.map +1 -0
- package/dist/chunks/config-file-DlZXJMj8.js +25 -0
- package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
- package/dist/chunks/css-definitions-B4aWBkH3.js +910 -0
- package/dist/chunks/css-definitions-B4aWBkH3.js.map +1 -0
- package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/{debug.js → chunks/debug-D2Pu7Xhy.js} +197 -149
- package/dist/chunks/debug-D2Pu7Xhy.js.map +1 -0
- package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
- package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
- package/dist/chunks/hydration-TRcz5vnk.js +41 -0
- package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
- package/dist/chunks/react-runtime-DHiopXCu.js +691 -0
- package/dist/chunks/react-runtime-DHiopXCu.js.map +1 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js +2435 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js.map +1 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js +152 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js.map +1 -0
- package/dist/{utils/merge-styles.js → chunks/shared-utils-y-HjvPN4.js} +61 -58
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-DnkV_4Jg.js +5602 -0
- package/dist/chunks/style-engine-DnkV_4Jg.js.map +1 -0
- package/dist/chunks/zero-engine-DcwaCvFs.js +310 -0
- package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
- package/dist/collector-D2OT6I2G.d.ts +164 -0
- package/dist/config-C4ftFxgI.d.ts +1367 -0
- package/dist/core/index.d.ts +5 -34
- package/dist/core/index.js +9 -27
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/index-DxQNRj50.d.ts +1964 -0
- package/dist/index.d.ts +5 -51
- package/dist/index.js +11 -36
- package/dist/{utils/merge-styles.d.ts → merge-styles-D39qBtox.d.ts} +3 -4
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +6 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +17 -0
- package/dist/ssr/astro-middleware-static.js +7 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +18 -0
- package/dist/ssr/astro-middleware.js +7 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +110 -12
- package/dist/ssr/astro.js +206 -50
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +17 -5
- package/dist/ssr/index.js +7 -9
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +123 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +13 -12
- package/dist/ssr/next.js +40 -51
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +90 -5
- package/dist/static/index.js +31 -4
- package/dist/static/index.js.map +1 -0
- package/dist/static/inject.d.ts +4 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/types-CYQIhUg1.d.ts +1569 -0
- package/dist/zero/babel.d.ts +27 -121
- package/dist/zero/babel.js +192 -151
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +136 -3
- package/dist/zero/index.js +24 -3
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +16 -5
- package/dist/zero/next.js +8 -42
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +23 -12
- package/docs/adoption.md +72 -37
- package/docs/ai-agents.md +259 -0
- package/docs/comparison.md +83 -54
- package/docs/configuration.md +712 -81
- package/docs/debug.md +39 -24
- package/docs/design-system.md +174 -41
- package/docs/dsl.md +733 -195
- package/docs/getting-started.md +132 -52
- package/docs/injector.md +197 -90
- package/docs/methodology.md +154 -48
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +768 -0
- package/docs/plugins.md +333 -0
- package/docs/react-api.md +746 -0
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +403 -151
- package/docs/styles.md +251 -49
- package/docs/tasty-static.md +368 -101
- package/package.json +157 -40
- package/tasty.config.ts +7 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -8
- package/dist/chunks/cacheKey.js +0 -78
- 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 -60
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/config.d.ts +0 -366
- package/dist/config.js +0 -504
- package/dist/config.js.map +0 -1
- package/dist/counter-style/index.js +0 -51
- package/dist/counter-style/index.js.map +0 -1
- package/dist/debug.d.ts +0 -89
- package/dist/debug.js.map +0 -1
- package/dist/font-face/index.js +0 -63
- package/dist/font-face/index.js.map +0 -1
- package/dist/hooks/resolve-ssr-collector.js +0 -15
- package/dist/hooks/resolve-ssr-collector.js.map +0 -1
- package/dist/hooks/useCounterStyle.d.ts +0 -50
- package/dist/hooks/useCounterStyle.js +0 -47
- package/dist/hooks/useCounterStyle.js.map +0 -1
- package/dist/hooks/useFontFace.d.ts +0 -43
- package/dist/hooks/useFontFace.js +0 -71
- package/dist/hooks/useFontFace.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -30
- package/dist/hooks/useGlobalStyles.js +0 -79
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -56
- package/dist/hooks/useKeyframes.js +0 -65
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -79
- package/dist/hooks/useProperty.js +0 -110
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -53
- package/dist/hooks/useRawCSS.js +0 -36
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -45
- package/dist/hooks/useStyles.js +0 -238
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -183
- package/dist/injector/index.js +0 -180
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -166
- package/dist/injector/injector.js +0 -465
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -136
- package/dist/injector/sheet-manager.js +0 -734
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -204
- package/dist/keyframes/index.js +0 -206
- package/dist/keyframes/index.js.map +0 -1
- package/dist/parser/classify.js +0 -320
- package/dist/parser/classify.js.map +0 -1
- package/dist/parser/const.js +0 -49
- 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 -55
- package/dist/pipeline/index.js +0 -709
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -1104
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -447
- 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 -98
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -76
- package/dist/properties/index.js +0 -223
- 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 -91
- 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 +0 -35
- 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.d.ts +0 -102
- package/dist/ssr/collector.js +0 -227
- 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 +0 -22
- 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 -50
- package/dist/ssr/format-property.js.map +0 -1
- package/dist/ssr/format-rules.js +0 -73
- 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 -171
- 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 -27
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/createStyle.js +0 -80
- 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 -52
- package/dist/styles/preset.js +0 -127
- 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 -547
- 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 -119
- package/dist/tasty.js +0 -232
- package/dist/tasty.js.map +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -22
- 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/color-math.d.ts +0 -46
- package/dist/utils/color-math.js +0 -749
- package/dist/utils/color-math.js.map +0 -1
- package/dist/utils/color-space.d.ts +0 -5
- package/dist/utils/color-space.js +0 -229
- package/dist/utils/color-space.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -11
- 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/has-keys.js +0 -13
- package/dist/utils/has-keys.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/process-tokens.d.ts +0 -21
- package/dist/utils/process-tokens.js +0 -91
- package/dist/utils/process-tokens.js.map +0 -1
- package/dist/utils/resolve-recipes.d.ts +0 -17
- package/dist/utils/resolve-recipes.js +0 -147
- 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 -99
- package/dist/utils/styles.js +0 -221
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -47
- package/dist/utils/typography.js +0 -51
- 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 +0 -267
- package/dist/zero/extractor.js.map +0 -1
- package/docs/PIPELINE.md +0 -519
- package/docs/runtime.md +0 -485
package/docs/tasty-static.md
CHANGED
|
@@ -1,35 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Build-Time Extraction (`tastyStatic`)
|
|
2
2
|
|
|
3
|
-
`tastyStatic` is
|
|
3
|
+
`tastyStatic` is Tasty's framework-agnostic build-time utility for extracting CSS before rendering. It produces no client styling runtime in file mode, but it is not the only way to achieve zero-runtime delivery: server-only `tasty()` also ships no Tasty runtime to the browser while retaining the full React component API. Astro's `tastyIntegration({ islands: false })` is the clearest example; the same architecture applies to server-only Next.js RSC.
|
|
4
|
+
|
|
5
|
+
Choose `tastyStatic` specifically when styles must be generated during the build, when the consumer is not React, or when you want static class-name objects instead of components. For the broader docs map, see the [Docs Hub](README.md).
|
|
4
6
|
|
|
5
7
|
---
|
|
6
8
|
|
|
7
9
|
## When to Use
|
|
8
10
|
|
|
9
|
-
- **
|
|
10
|
-
- **No
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
11
|
+
- **CSS that must exist before anything renders** — static sites, landing pages, and HTML served from a CDN get one stylesheet generated at build time
|
|
12
|
+
- **No React at runtime** — `tastyStatic` returns class names, so plain DOM code or any templating that sets `class` can use them; the [Programmatic API](#programmatic-api) covers frameworks Babel does not process
|
|
13
|
+
- **Class-name objects instead of components** — extend them with `tastyStatic(base, styles)` and pass them wherever a `className` goes
|
|
14
|
+
- **Self-contained packages** — [inject mode](#inject-mode) embeds the CSS in the JavaScript, so consumers have no stylesheet to wire up
|
|
15
|
+
|
|
16
|
+
If the styles depend on props, keep `tasty()`: rendered only on the server, it also ships no styling runtime (see [Server-Side Rendering](ssr.md)).
|
|
13
17
|
|
|
14
18
|
## Requirements
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
Build-time extraction is part of the main `@tenphi/tasty` package but requires additional peer dependencies depending on your setup:
|
|
17
21
|
|
|
18
|
-
| Dependency
|
|
19
|
-
|
|
20
|
-
| `@babel/core`
|
|
21
|
-
| `@babel/helper-plugin-utils` |
|
|
22
|
-
| `@babel/types`
|
|
23
|
-
| `jiti`
|
|
22
|
+
| Dependency | Version | Required for |
|
|
23
|
+
| ---------------------------- | ---------------------- | ---------------------------------------------------- |
|
|
24
|
+
| `@babel/core` | 7.24+ or 8 | Babel plugin (`@tenphi/tasty/babel-plugin`) |
|
|
25
|
+
| `@babel/helper-plugin-utils` | 7.24+ or 8 | Babel plugin |
|
|
26
|
+
| `@babel/types` | 7.24+ or 8 | Babel plugin |
|
|
27
|
+
| `jiti` | >= 2.6 | `configFile` only (Babel plugin and Next.js wrapper) |
|
|
28
|
+
| `babel-loader` | any (10+ with Babel 8) | Next.js wrapper (`@tenphi/tasty/zero/next`) |
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
Install the three Babel packages from the same major. Babel 8 itself needs Node 22.18+ or 24.11+, and `babel-loader` accepts it from version 10.
|
|
31
|
+
|
|
32
|
+
The Babel packages and `jiti` are optional peer dependencies of `@tenphi/tasty`; `babel-loader` is resolved from your project. `jiti` is loaded only to read a `configFile`, so a setup that passes `config` directly does not need it; without it, `configFile` fails with an error that says to install it. Install what your setup requires:
|
|
26
33
|
|
|
27
34
|
```bash
|
|
28
|
-
#
|
|
35
|
+
# Any Babel-based setup (Vite, custom Babel config, etc.)
|
|
29
36
|
pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types
|
|
30
37
|
|
|
31
|
-
#
|
|
32
|
-
pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types
|
|
38
|
+
# Next.js
|
|
39
|
+
pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types babel-loader
|
|
40
|
+
|
|
41
|
+
# Either, with configFile
|
|
42
|
+
pnpm add -D jiti
|
|
33
43
|
```
|
|
34
44
|
|
|
35
45
|
---
|
|
@@ -50,13 +60,15 @@ const button = tastyStatic({
|
|
|
50
60
|
radius: '1r',
|
|
51
61
|
});
|
|
52
62
|
|
|
53
|
-
// Use in JSX
|
|
54
|
-
<button className={button}>Click me</button
|
|
63
|
+
// Use in JSX
|
|
64
|
+
<button className={button.className}>Click me</button>;
|
|
55
65
|
|
|
56
|
-
//
|
|
57
|
-
|
|
66
|
+
// toString() returns the class name, for template strings and plain JS
|
|
67
|
+
element.className = `${button} is-active`;
|
|
58
68
|
```
|
|
59
69
|
|
|
70
|
+
In TSX, pass `button.className`: React types `className` as `string`, so passing the `StaticStyle` object fails type-checking even though it works at runtime.
|
|
71
|
+
|
|
60
72
|
---
|
|
61
73
|
|
|
62
74
|
## API Reference
|
|
@@ -103,15 +115,17 @@ tastyStatic('body', {
|
|
|
103
115
|
});
|
|
104
116
|
```
|
|
105
117
|
|
|
118
|
+
The selector can be a list (`'.uni-checkbox, uni-checkbox'`): every item gets the states and sub-elements. Local `@keyframes` and `@starting` states work as in `tastyStatic(styles)`.
|
|
119
|
+
|
|
106
120
|
---
|
|
107
121
|
|
|
108
122
|
## StaticStyle Object
|
|
109
123
|
|
|
110
|
-
| Property
|
|
111
|
-
|
|
112
|
-
| `className`
|
|
113
|
-
| `styles`
|
|
114
|
-
| `toString()` | `() => string` | Returns `className` for string coercion
|
|
124
|
+
| Property | Type | Description |
|
|
125
|
+
| ------------ | -------------- | ------------------------------------------ |
|
|
126
|
+
| `className` | `string` | Space-separated class names for use in JSX |
|
|
127
|
+
| `styles` | `Styles` | The original (or merged) styles object |
|
|
128
|
+
| `toString()` | `() => string` | Returns `className` for string coercion |
|
|
115
129
|
|
|
116
130
|
---
|
|
117
131
|
|
|
@@ -123,48 +137,84 @@ tastyStatic('body', {
|
|
|
123
137
|
// babel.config.js
|
|
124
138
|
module.exports = {
|
|
125
139
|
plugins: [
|
|
126
|
-
[
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
140
|
+
[
|
|
141
|
+
'@tenphi/tasty/babel-plugin',
|
|
142
|
+
{
|
|
143
|
+
output: 'public/tasty.css',
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
],
|
|
130
147
|
};
|
|
131
148
|
```
|
|
132
149
|
|
|
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
|
|
150
|
+
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 build-time config.
|
|
134
151
|
|
|
135
152
|
### With Configuration
|
|
136
153
|
|
|
137
154
|
```javascript
|
|
138
155
|
module.exports = {
|
|
139
156
|
plugins: [
|
|
140
|
-
[
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
157
|
+
[
|
|
158
|
+
'@tenphi/tasty/babel-plugin',
|
|
159
|
+
{
|
|
160
|
+
output: 'public/tasty.css',
|
|
161
|
+
config: {
|
|
162
|
+
states: {
|
|
163
|
+
'@mobile': '@media(w < 768px)',
|
|
164
|
+
'@tablet': '@media(w < 1024px)',
|
|
165
|
+
'@dark': '@root(schema=dark)',
|
|
166
|
+
},
|
|
167
|
+
devMode: true,
|
|
147
168
|
},
|
|
148
|
-
devMode: true,
|
|
149
169
|
},
|
|
150
|
-
|
|
151
|
-
]
|
|
170
|
+
],
|
|
171
|
+
],
|
|
152
172
|
};
|
|
153
173
|
```
|
|
154
174
|
|
|
155
175
|
### Plugin Options
|
|
156
176
|
|
|
157
|
-
| Option
|
|
158
|
-
|
|
159
|
-
| `output`
|
|
160
|
-
| `
|
|
161
|
-
| `
|
|
162
|
-
| `
|
|
163
|
-
| `
|
|
164
|
-
| `
|
|
165
|
-
| `config.
|
|
166
|
-
| `config.
|
|
167
|
-
| `config.
|
|
177
|
+
| Option | Type | Default | Description |
|
|
178
|
+
| -------------------------- | ------------------------------------------------ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
179
|
+
| `output` | `string` | `'tasty.css'` | Path for generated CSS file |
|
|
180
|
+
| `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS (see [Inject Mode](#inject-mode)) |
|
|
181
|
+
| `configFile` | `string` | — | Absolute path to a TS/JS module that default-exports a `TastyZeroConfig` object. JSON-serializable alternative to `config` — required for Turbopack. Loaded with the optional `jiti` peer. |
|
|
182
|
+
| `config` | `TastyZeroConfig \| () => TastyZeroConfig` | `{}` | Inline config object or factory function. Takes precedence over `configFile`. |
|
|
183
|
+
| `configDeps` | `string[]` | `[]` | Absolute file paths that affect config (for cache invalidation) |
|
|
184
|
+
| `injectImport` | `boolean` | `true` | Replace `@tenphi/tasty/static` imports with an import of the generated CSS file. Set to `false` to manage CSS imports manually. |
|
|
185
|
+
| `config.states` | `Record<string, string>` | `{}` | Predefined state aliases (e.g. `{ '@mobile': '@media(w < 768px)' }`) |
|
|
186
|
+
| `config.devMode` | `boolean` | `false` | Add source comments to CSS |
|
|
187
|
+
| `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. |
|
|
188
|
+
| `config.replaceTokens` | `Record<string, string \| number>` | — | Parse-time token substitution. Keys use `$name` for custom properties and `#name` for color tokens. |
|
|
189
|
+
| `config.recipes` | `Record<string, RecipeStyles>` | `{}` | Predefined style recipes |
|
|
190
|
+
| `config.keyframes` | `Record<string, KeyframesSteps>` | — | Global `@keyframes` definitions available to all `tastyStatic` calls |
|
|
191
|
+
| `config.fontFaces` | `Record<string, FontFaceInput>` | — | Global `@font-face` definitions |
|
|
192
|
+
| `config.counterStyles` | `Record<string, CounterStyleDescriptors>` | — | Global `@counter-style` definitions |
|
|
193
|
+
| `config.properties` | `Record<string, PropertyDefinition>` | — | Global `@property` definitions, written with Tasty's [default properties](dsl.md#default-properties) |
|
|
194
|
+
| `config.units` | `Record<string, string \| UnitHandler>` | — | Custom units for the style parser (merged with built-ins). E.g. `{ u: 'var(--u)' }` makes `2u` compile to `calc(2 * var(--u))`. Native CSS units need no entry |
|
|
195
|
+
| `config.functions` | `Record<string, FunctionDefinition \| Function>` | — | Custom functions (merged). Bare keys → parse functions; `$$name` keys → declarative CSS `@function` definitions |
|
|
196
|
+
| `config.polyfills` | `{ functions?: boolean }` | `{}` | Opt-in polyfills. `functions: true` inlines `@function` calls into plain CSS at build time |
|
|
197
|
+
| `config.plugins` | `TastyPlugin[]` | — | Plugins that extend tasty with custom functions, units, states, and handlers |
|
|
198
|
+
| `config.handlers` | `Record<string, StyleHandlerDefinition>` | — | Custom style handlers that transform style properties into CSS declarations |
|
|
199
|
+
| `config.presets` | `Record<string, TypographyPreset>` | — | Typography presets — shorthand for `generateTypographyTokens()`. Generated tokens merge under explicit `tokens`. |
|
|
200
|
+
| `config.globalStyles` | `Record<string, Styles>` | — | Global Tasty styles keyed by CSS selector. Supports the full style syntax. |
|
|
201
|
+
| `config.autoPropertyTypes` | `boolean` | `true` | Automatically infer and register CSS `@property` declarations from values |
|
|
202
|
+
| `config.parserCacheSize` | `number` | `1000` | Parser LRU cache size. Larger values improve performance for builds with many unique style values |
|
|
203
|
+
| `config.namePrefix` | `string` | `'ts'` | Prefix prepended to every generated identifier. Defaults to `'ts'` so static classes never collide with runtime (`'t'`) classes. See [Configuration: Name prefix](configuration.md#name-prefix). |
|
|
204
|
+
|
|
205
|
+
### Coexisting with `tasty()`
|
|
206
|
+
|
|
207
|
+
When a page mixes `tastyStatic` with `tasty`, both must use **different** `namePrefix` values. The defaults handle this automatically (`'t'` for React rendering, `'ts'` for build-time extraction). If you customize one, customize the other:
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
// tasty-zero.config.ts (Babel plugin)
|
|
211
|
+
export default { namePrefix: 'mbs' };
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
// app entry (`tasty()` configure)
|
|
216
|
+
configure({ namePrefix: 'mb' });
|
|
217
|
+
```
|
|
168
218
|
|
|
169
219
|
---
|
|
170
220
|
|
|
@@ -176,16 +226,24 @@ Recipes work with `tastyStatic` the same way as with runtime `tasty`:
|
|
|
176
226
|
// babel.config.js
|
|
177
227
|
module.exports = {
|
|
178
228
|
plugins: [
|
|
179
|
-
[
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
229
|
+
[
|
|
230
|
+
'@tenphi/tasty/babel-plugin',
|
|
231
|
+
{
|
|
232
|
+
output: 'public/tasty.css',
|
|
233
|
+
config: {
|
|
234
|
+
recipes: {
|
|
235
|
+
card: {
|
|
236
|
+
padding: '4x',
|
|
237
|
+
fill: '#surface',
|
|
238
|
+
radius: '1r',
|
|
239
|
+
border: true,
|
|
240
|
+
},
|
|
241
|
+
elevated: { shadow: '2x 2x 4x #shadow' },
|
|
242
|
+
},
|
|
185
243
|
},
|
|
186
244
|
},
|
|
187
|
-
|
|
188
|
-
]
|
|
245
|
+
],
|
|
246
|
+
],
|
|
189
247
|
};
|
|
190
248
|
```
|
|
191
249
|
|
|
@@ -197,7 +255,7 @@ const card = tastyStatic({
|
|
|
197
255
|
color: '#text',
|
|
198
256
|
});
|
|
199
257
|
|
|
200
|
-
<div className={card}>Styled card</div
|
|
258
|
+
<div className={card.className}>Styled card</div>;
|
|
201
259
|
```
|
|
202
260
|
|
|
203
261
|
---
|
|
@@ -208,7 +266,7 @@ The `withTastyZero` wrapper configures both **webpack** and **Turbopack** automa
|
|
|
208
266
|
|
|
209
267
|
```typescript
|
|
210
268
|
// next.config.ts
|
|
211
|
-
import { withTastyZero } from '@tenphi/tasty/next';
|
|
269
|
+
import { withTastyZero } from '@tenphi/tasty/zero/next';
|
|
212
270
|
|
|
213
271
|
export default withTastyZero({
|
|
214
272
|
output: 'public/tasty.css',
|
|
@@ -221,24 +279,25 @@ export default withTastyZero({
|
|
|
221
279
|
|
|
222
280
|
### `withTastyZero` Options
|
|
223
281
|
|
|
224
|
-
| Option
|
|
225
|
-
|
|
226
|
-
| `output`
|
|
227
|
-
| `
|
|
228
|
-
| `
|
|
229
|
-
| `
|
|
230
|
-
| `
|
|
282
|
+
| Option | Type | Default | Description |
|
|
283
|
+
| ------------ | -------------------- | -------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
284
|
+
| `output` | `string` | `'public/tasty.css'` | Output path for CSS relative to project root |
|
|
285
|
+
| `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS |
|
|
286
|
+
| `enabled` | `boolean` | `true` | Enable/disable the plugin |
|
|
287
|
+
| `configFile` | `string` | — | Path to a TS/JS module that default-exports `TastyZeroConfig`. Recommended for Turbopack compatibility. |
|
|
288
|
+
| `config` | `TastyZeroConfig` | — | Inline config object. For static configs that don't change during dev. |
|
|
289
|
+
| `configDeps` | `string[]` | `[]` | Extra files the config depends on (for cache invalidation) |
|
|
231
290
|
|
|
232
291
|
### Turbopack Support
|
|
233
292
|
|
|
234
293
|
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.
|
|
235
294
|
|
|
236
|
-
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.
|
|
295
|
+
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`, which must be installed.
|
|
237
296
|
|
|
238
|
-
**Requirements**: `babel-loader` must be installed in your project:
|
|
297
|
+
**Requirements**: `babel-loader` must be installed in your project (see [Requirements](#requirements)):
|
|
239
298
|
|
|
240
299
|
```bash
|
|
241
|
-
pnpm add babel-loader
|
|
300
|
+
pnpm add -D babel-loader
|
|
242
301
|
```
|
|
243
302
|
|
|
244
303
|
### CSS Injection
|
|
@@ -253,31 +312,107 @@ public/tasty.css
|
|
|
253
312
|
|
|
254
313
|
---
|
|
255
314
|
|
|
315
|
+
## Programmatic API
|
|
316
|
+
|
|
317
|
+
`@tenphi/tasty/zero` turns styles into CSS in Node without Babel or React — for build scripts, or CSS shipped to other frameworks:
|
|
318
|
+
|
|
319
|
+
```ts
|
|
320
|
+
import {
|
|
321
|
+
configure,
|
|
322
|
+
extractStylesForSelector,
|
|
323
|
+
extractStylesWithChunks,
|
|
324
|
+
} from '@tenphi/tasty/zero';
|
|
325
|
+
|
|
326
|
+
configure({
|
|
327
|
+
units: { u: 'var(--unit)' },
|
|
328
|
+
states: { '@dark': '@root(schema=dark)' },
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
extractStylesForSelector('.card', { padding: '2u', fill: '#surface' }).css;
|
|
332
|
+
// → '.card { padding: calc(2 * var(--unit)); background-color: … }'
|
|
333
|
+
|
|
334
|
+
extractStylesWithChunks({ display: 'flex', gap: '1u' });
|
|
335
|
+
// → [{ className: 'ts…', css: '.ts….ts… { … }' }]
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
`configure()` takes the same options as the Babel plugin's `config` (see [Plugin Options](#plugin-options)) and replaces the previous configuration on each call; `resetConfig()` returns to the defaults. Options that shape the extracted rules apply — `states`, `units`, parse `functions`, `handlers`, `replaceTokens`, `recipes`, `plugins`, `namePrefix`. Definitions that become at-rules or global CSS of their own are not emitted with the rules: `tokens`, `globalStyles`, `fontFaces`, `counterStyles`, `properties` and `$$` `@function` definitions. Render tokens and global styles with `extractStylesForSelector(':root', tokens)` and `extractStylesForSelector(selector, styles)`.
|
|
339
|
+
|
|
340
|
+
`extractConfigProperties()` returns the `@property` rules the Babel plugin writes at the top of its output: Tasty's [default set](dsl.md#default-properties) (`#border`, `#outline`, `$gap`, `$radius`, `$transition`, …) overlaid with the configured `properties`, or with the `properties` map you pass it. Emit them once per stylesheet. Style handlers read several of these tokens with no fallback of their own (`border: true` reads `#border`, `transition` reads `$transition`), so without them those declarations resolve to nothing.
|
|
341
|
+
|
|
342
|
+
The configuration is process-wide and shared with the Babel plugin and the runtime `configure()` from `@tenphi/tasty`. The extractors re-apply their own configuration when the Babel plugin replaced it, but not after a runtime `configure()` — don't mix the runtime and build-time configuration in one process.
|
|
343
|
+
|
|
344
|
+
`extractStylesForSelector()` output starts with the `@keyframes` its rules animate — local `@keyframes` and configured `keyframes` — under hashed names the `animation` declarations are rewritten to. `extractStylesWithChunks()` returns class rules only.
|
|
345
|
+
|
|
346
|
+
`mergeStyles()` merges style objects with the rules `tasty(Base, { styles })` extends by — state maps with and without a `''` key, `null`, `false`, `'@inherit'` and sub-elements (see [Extending vs. Replacing State Maps](dsl.md#extending-vs-replacing-state-maps)) — so a build script can layer overrides onto source styles before extracting them, without React:
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
import { extractStylesForSelector, mergeStyles } from '@tenphi/tasty/zero';
|
|
350
|
+
|
|
351
|
+
const styles = mergeStyles(checkboxStyles, {
|
|
352
|
+
Indicator: { radius: '0.5r' },
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
extractStylesForSelector('.checkbox', styles).css;
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
To write the results to a file the way the Babel plugin does, use `createCSSWriter()`. It deduplicates blocks by key and prepends the generated-file header:
|
|
359
|
+
|
|
360
|
+
```ts
|
|
361
|
+
import {
|
|
362
|
+
createCSSWriter,
|
|
363
|
+
extractConfigProperties,
|
|
364
|
+
extractStylesWithChunks,
|
|
365
|
+
} from '@tenphi/tasty/zero';
|
|
366
|
+
|
|
367
|
+
const writer = createCSSWriter('dist/tasty.css', { devMode: true });
|
|
368
|
+
|
|
369
|
+
for (const prop of extractConfigProperties()) {
|
|
370
|
+
writer.add(`@property:${prop.name}`, prop.css);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
for (const chunk of extractStylesWithChunks({ display: 'flex', gap: '1u' })) {
|
|
374
|
+
writer.add(chunk.className, chunk.css, 'src/card.ts'); // source is a devMode comment
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
writer.write(); // also: has(key), getCSS(), clear(), getOutputPath()
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
256
382
|
## Vite Integration
|
|
257
383
|
|
|
384
|
+
`@vitejs/plugin-react` 6 no longer runs Babel; add it with `@rolldown/plugin-babel` (`pnpm add -D @rolldown/plugin-babel`):
|
|
385
|
+
|
|
258
386
|
```typescript
|
|
259
387
|
// vite.config.ts
|
|
260
388
|
import { defineConfig } from 'vite';
|
|
261
389
|
import react from '@vitejs/plugin-react';
|
|
390
|
+
import babel from '@rolldown/plugin-babel';
|
|
262
391
|
|
|
263
392
|
export default defineConfig({
|
|
264
393
|
plugins: [
|
|
265
|
-
react(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
394
|
+
react(),
|
|
395
|
+
babel({
|
|
396
|
+
plugins: [
|
|
397
|
+
[
|
|
398
|
+
'@tenphi/tasty/babel-plugin',
|
|
399
|
+
{
|
|
400
|
+
output: 'src/tasty.css',
|
|
270
401
|
config: {
|
|
271
402
|
states: { '@mobile': '@media(w < 768px)' },
|
|
272
403
|
},
|
|
273
|
-
}
|
|
404
|
+
},
|
|
274
405
|
],
|
|
275
|
-
|
|
406
|
+
],
|
|
276
407
|
}),
|
|
277
408
|
],
|
|
278
409
|
});
|
|
279
410
|
```
|
|
280
411
|
|
|
412
|
+
With `@vitejs/plugin-react` 5 or older, pass the same `plugins` array to `react({ babel: { plugins } })` instead.
|
|
413
|
+
|
|
414
|
+
Keep `output` outside `public/`: the plugin replaces each `@tenphi/tasty/static` import with an import of the generated file, and Vite does not let JavaScript import files from `public/`. Vite then bundles the CSS like any other stylesheet.
|
|
415
|
+
|
|
281
416
|
---
|
|
282
417
|
|
|
283
418
|
## Build Transformation
|
|
@@ -295,42 +430,169 @@ const button = tastyStatic({
|
|
|
295
430
|
|
|
296
431
|
tastyStatic('.heading', { preset: 'h1' });
|
|
297
432
|
|
|
298
|
-
export const Button = () => <button className={button}>Click</button>;
|
|
433
|
+
export const Button = () => <button className={button.className}>Click</button>;
|
|
299
434
|
```
|
|
300
435
|
|
|
301
436
|
### After (Production Build)
|
|
302
437
|
|
|
303
438
|
```tsx
|
|
439
|
+
import './tasty.css';
|
|
440
|
+
|
|
304
441
|
const button = {
|
|
305
|
-
className: '
|
|
442
|
+
className: 'ts3f783b ts070801',
|
|
306
443
|
styles: { padding: '2x 4x', fill: '#purple', color: '#white' },
|
|
307
|
-
toString() {
|
|
444
|
+
toString() {
|
|
445
|
+
return this.className;
|
|
446
|
+
},
|
|
308
447
|
};
|
|
309
448
|
|
|
310
|
-
export const Button = () => <button className={button}>Click</button>;
|
|
449
|
+
export const Button = () => <button className={button.className}>Click</button>;
|
|
311
450
|
```
|
|
312
451
|
|
|
452
|
+
The `@tenphi/tasty/static` import becomes an import of the generated file (relative to the source file), and the selector-mode call is removed.
|
|
453
|
+
|
|
313
454
|
### Generated CSS (tasty.css)
|
|
314
455
|
|
|
315
456
|
```css
|
|
316
457
|
/* Generated by @tenphi/tasty/zero - DO NOT EDIT */
|
|
317
458
|
|
|
318
|
-
|
|
319
|
-
|
|
459
|
+
@property --tasty-second-fill-color {
|
|
460
|
+
syntax: '<color>';
|
|
461
|
+
inherits: false;
|
|
462
|
+
initial-value: transparent;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
@property --current-color {
|
|
466
|
+
syntax: '<color>';
|
|
467
|
+
inherits: true;
|
|
468
|
+
initial-value: currentcolor;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/* …the rest of Tasty's default @property rules (--white-color, --border-color, --gap, --transition, …), then config.properties */
|
|
472
|
+
|
|
473
|
+
.ts3f783b.ts3f783b {
|
|
474
|
+
color: var(--white-color);
|
|
475
|
+
--current-color: var(--white-color);
|
|
320
476
|
}
|
|
321
477
|
|
|
322
|
-
.
|
|
323
|
-
background:
|
|
324
|
-
color: #fff;
|
|
478
|
+
.ts3f783b.ts3f783b {
|
|
479
|
+
background-color: var(--purple-color);
|
|
325
480
|
}
|
|
326
481
|
|
|
327
|
-
.
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
482
|
+
.ts070801.ts070801 {
|
|
483
|
+
padding: 16px 32px;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
.heading {
|
|
487
|
+
font-size: var(--h1-font-size, var(--default-font-size));
|
|
488
|
+
/* …line-height, letter-spacing, font-weight, and the rest of the h1 preset */
|
|
331
489
|
}
|
|
332
490
|
```
|
|
333
491
|
|
|
492
|
+
The file starts with Tasty's [default `@property` rules](dsl.md#default-properties) and your `config.properties`, written once. Styles are split into chunks (here appearance and spacing), each with its own class. Color tokens compile to custom properties: `#purple` becomes `var(--purple-color)`. Define it in `config.tokens` and the plugin writes it to `:root` at the top of the same file. Units are literal (`2x` is `16px`). Selector-mode rules use the selector as written, without the doubled specificity of class rules.
|
|
493
|
+
|
|
494
|
+
---
|
|
495
|
+
|
|
496
|
+
## Inject Mode
|
|
497
|
+
|
|
498
|
+
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.
|
|
499
|
+
|
|
500
|
+
This is ideal for **reusable components**, **extensions**, and **libraries** where consumers shouldn't need to manage an external CSS file.
|
|
501
|
+
|
|
502
|
+
### How It Works
|
|
503
|
+
|
|
504
|
+
1. The Babel plugin extracts CSS at build time (same pipeline as file mode).
|
|
505
|
+
2. Instead of writing to a `.css` file, the CSS is embedded as string literals in the JS output.
|
|
506
|
+
3. The `@tenphi/tasty/static` import is rewritten to `@tenphi/tasty/static/inject`.
|
|
507
|
+
4. Each `tastyStatic` call becomes a self-contained expression that injects its CSS and evaluates to a `StaticStyle` object.
|
|
508
|
+
|
|
509
|
+
### Configuration
|
|
510
|
+
|
|
511
|
+
```javascript
|
|
512
|
+
// babel.config.js
|
|
513
|
+
module.exports = {
|
|
514
|
+
plugins: [
|
|
515
|
+
[
|
|
516
|
+
'@tenphi/tasty/babel-plugin',
|
|
517
|
+
{
|
|
518
|
+
mode: 'inject',
|
|
519
|
+
config: {
|
|
520
|
+
states: { '@mobile': '@media(w < 768px)' },
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
],
|
|
524
|
+
],
|
|
525
|
+
};
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
With Next.js:
|
|
529
|
+
|
|
530
|
+
```typescript
|
|
531
|
+
// next.config.ts
|
|
532
|
+
import { withTastyZero } from '@tenphi/tasty/zero/next';
|
|
533
|
+
|
|
534
|
+
export default withTastyZero({
|
|
535
|
+
mode: 'inject',
|
|
536
|
+
configFile: './app/tasty-zero.config.ts',
|
|
537
|
+
})({
|
|
538
|
+
reactStrictMode: true,
|
|
539
|
+
});
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
When `mode` is `'inject'`, the `output` and `injectImport` options are ignored.
|
|
543
|
+
|
|
544
|
+
### Build Transformation (inject mode)
|
|
545
|
+
|
|
546
|
+
**Before:**
|
|
547
|
+
|
|
548
|
+
```tsx
|
|
549
|
+
import { tastyStatic } from '@tenphi/tasty/static';
|
|
550
|
+
|
|
551
|
+
const button = tastyStatic({
|
|
552
|
+
padding: '2x 4x',
|
|
553
|
+
fill: '#purple',
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
tastyStatic('.heading', { preset: 'h1' });
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
**After:**
|
|
560
|
+
|
|
561
|
+
```tsx
|
|
562
|
+
import { injectCSS as _$i } from '@tenphi/tasty/static/inject';
|
|
563
|
+
|
|
564
|
+
_$i(
|
|
565
|
+
'@property',
|
|
566
|
+
'@property --tasty-second-fill-color { … }\n@property --current-color { … }\n…',
|
|
567
|
+
);
|
|
568
|
+
|
|
569
|
+
const button =
|
|
570
|
+
(_$i(
|
|
571
|
+
'tsa903d6 ts070801',
|
|
572
|
+
'.tsa903d6.tsa903d6 { background-color: var(--purple-color); }\n.ts070801.ts070801 { padding: 16px 32px; }',
|
|
573
|
+
),
|
|
574
|
+
{
|
|
575
|
+
className: 'tsa903d6 ts070801',
|
|
576
|
+
styles: { padding: '2x 4x', fill: '#purple' },
|
|
577
|
+
toString() {
|
|
578
|
+
return this.className;
|
|
579
|
+
},
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
_$i('.heading', '.heading { font-size: var(--h1-font-size, …); … }');
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
Each file that calls `tastyStatic()` starts by injecting Tasty's default `@property` rules and your `config.properties` under the `@property` id. `injectCSS()` skips an id it has already injected, so the page gets them once.
|
|
586
|
+
|
|
587
|
+
### Dev Mode / HMR
|
|
588
|
+
|
|
589
|
+
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.
|
|
590
|
+
|
|
591
|
+
### Limitations (inject mode)
|
|
592
|
+
|
|
593
|
+
- **Client-side only** — Styles are injected via the DOM, so they are not available during SSR. For server-rendered apps, use `mode: 'file'` or React `tasty()`.
|
|
594
|
+
- **Larger JS bundle** — CSS is embedded in JavaScript, increasing bundle size. Best suited for components and extensions, not full-app styling.
|
|
595
|
+
|
|
334
596
|
---
|
|
335
597
|
|
|
336
598
|
## Style Extension
|
|
@@ -343,7 +605,7 @@ const button = tastyStatic({
|
|
|
343
605
|
radius: '1r',
|
|
344
606
|
fill: '#gray.20',
|
|
345
607
|
color: '#text',
|
|
346
|
-
transition: 'fill
|
|
608
|
+
transition: 'fill',
|
|
347
609
|
});
|
|
348
610
|
|
|
349
611
|
// Variants
|
|
@@ -379,7 +641,7 @@ const card = tastyStatic({
|
|
|
379
641
|
|
|
380
642
|
## Extending Style Types (TypeScript)
|
|
381
643
|
|
|
382
|
-
If you add custom style properties, use module augmentation so `tastyStatic` recognizes them too. See [
|
|
644
|
+
If you add custom style properties, use module augmentation so `tastyStatic` recognizes them too. See [TypeScript](configuration.md#typescript) in the configuration docs.
|
|
383
645
|
|
|
384
646
|
---
|
|
385
647
|
|
|
@@ -397,13 +659,17 @@ For dynamic styling needs, combine with regular CSS or CSS variables:
|
|
|
397
659
|
```tsx
|
|
398
660
|
const card = tastyStatic({
|
|
399
661
|
padding: '4x',
|
|
400
|
-
fill: '
|
|
662
|
+
fill: '($card-bg, #white)',
|
|
401
663
|
});
|
|
402
664
|
|
|
403
665
|
<div
|
|
404
|
-
className={card}
|
|
405
|
-
style={
|
|
406
|
-
|
|
666
|
+
className={card.className}
|
|
667
|
+
style={
|
|
668
|
+
{
|
|
669
|
+
'--card-bg': isActive ? 'var(--purple-color)' : 'var(--white-color)',
|
|
670
|
+
} as React.CSSProperties
|
|
671
|
+
}
|
|
672
|
+
/>;
|
|
407
673
|
```
|
|
408
674
|
|
|
409
675
|
---
|
|
@@ -420,14 +686,15 @@ const card = tastyStatic({
|
|
|
420
686
|
## Common Issues
|
|
421
687
|
|
|
422
688
|
- 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.
|
|
423
|
-
- Styles stay dynamic by mistake: `tastyStatic()` only supports build-time-known values. Move
|
|
689
|
+
- Styles stay dynamic by mistake: `tastyStatic()` only supports build-time-known values. Move dynamic values to CSS variables or switch that component to React `tasty()`.
|
|
424
690
|
- Turbopack config behaves inconsistently: prefer `configFile` over inline functions so the setup stays JSON-serializable.
|
|
425
691
|
|
|
426
692
|
---
|
|
427
693
|
|
|
428
694
|
## Related
|
|
429
695
|
|
|
430
|
-
- [Docs Hub](README.md) — Choose the right guide by task or
|
|
696
|
+
- [Docs Hub](README.md) — Choose the right guide by task or CSS delivery model
|
|
431
697
|
- [Style DSL](dsl.md) — State maps, tokens, units, extending semantics (shared by runtime and static)
|
|
432
|
-
- [
|
|
698
|
+
- [React API](react-api.md) — Client or server rendering with `tasty()`: component props, variants, sub-elements, and style functions
|
|
433
699
|
- [Configuration](configuration.md) — Global configuration: tokens, recipes, custom units, and style handlers
|
|
700
|
+
- [Plugins & Extension Points](plugins.md) — Which extension points work at build time (`functions`, `units`, `states`, `handlers`, `recipes`) and which do not (`propHandlers` — `tastyStatic()` takes styles objects, not props)
|