@tenphi/tasty 0.0.0-snapshot.2dc73be → 0.0.0-snapshot.2ea241d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +298 -250
- package/dist/{ssr/async-storage.js → async-storage-B7_o6FKt.js} +17 -8
- package/dist/async-storage-B7_o6FKt.js.map +1 -0
- package/dist/collector-Crs9kGJW.js +243 -0
- package/dist/collector-Crs9kGJW.js.map +1 -0
- package/dist/{ssr/collector.d.ts → collector-osfWTeRd.d.ts} +38 -15
- package/dist/config-BaxtQMS3.js +10464 -0
- package/dist/config-BaxtQMS3.js.map +1 -0
- package/dist/config-BoZDUHW5.d.ts +945 -0
- package/dist/context-CkSg-kDT.js +24 -0
- package/dist/context-CkSg-kDT.js.map +1 -0
- package/dist/core/index.d.ts +5 -33
- package/dist/core/index.js +6 -26
- package/dist/core-CmxaoZ-N.js +1598 -0
- package/dist/core-CmxaoZ-N.js.map +1 -0
- package/dist/{zero/extractor.js → css-writer-CPy_cbFJ.js} +149 -13
- package/dist/css-writer-CPy_cbFJ.js.map +1 -0
- package/dist/{ssr/format-global-rules.js → format-global-rules-Dbc_1tc3.js} +3 -3
- package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
- package/dist/format-rules-CPirO_Mj.js +143 -0
- package/dist/format-rules-CPirO_Mj.js.map +1 -0
- package/dist/hydrate-CVn-A_3y.js +45 -0
- package/dist/hydrate-CVn-A_3y.js.map +1 -0
- package/dist/index-B_k47mc_.d.ts +1655 -0
- package/dist/index-tcHuMPFt.d.ts +1286 -0
- package/dist/index.d.ts +5 -48
- package/dist/index.js +731 -32
- package/dist/index.js.map +1 -0
- package/dist/keyframes-vpzoVdUR.js +588 -0
- package/dist/keyframes-vpzoVdUR.js.map +1 -0
- package/dist/{utils/merge-styles.d.ts → merge-styles-BMWcH6MF.d.ts} +3 -3
- package/dist/{utils/merge-styles.js → merge-styles-BzQutdAK.js} +4 -6
- package/dist/merge-styles-BzQutdAK.js.map +1 -0
- package/dist/{utils/resolve-recipes.js → resolve-recipes-DgH8A3Nn.js} +5 -8
- package/dist/resolve-recipes-DgH8A3Nn.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +19 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +15 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +78 -10
- package/dist/ssr/astro.js +116 -32
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/index.d.ts +44 -5
- package/dist/ssr/index.js +7 -9
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next.d.ts +7 -6
- package/dist/ssr/next.js +18 -14
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +91 -5
- package/dist/static/index.js +49 -4
- package/dist/static/index.js.map +1 -0
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/zero/babel.d.ts +49 -95
- package/dist/zero/babel.js +203 -48
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +67 -3
- package/dist/zero/index.js +2 -4
- package/dist/zero/next.d.ts +28 -1
- package/dist/zero/next.js +70 -15
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +31 -0
- package/docs/adoption.md +298 -0
- package/docs/comparison.md +419 -0
- package/docs/configuration.md +239 -12
- package/docs/debug.md +155 -340
- package/docs/design-system.md +436 -0
- package/docs/dsl.md +690 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +45 -29
- package/docs/methodology.md +642 -0
- package/docs/pipeline.md +699 -0
- package/docs/react-api.md +581 -0
- package/docs/ssr.md +156 -84
- package/docs/styles.md +50 -26
- package/docs/tasty-static.md +194 -23
- package/package.json +30 -14
- package/tasty.config.ts +1 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -8
- package/dist/chunks/cacheKey.js +0 -70
- package/dist/chunks/cacheKey.js.map +0 -1
- package/dist/chunks/definitions.d.ts +0 -37
- package/dist/chunks/definitions.js +0 -259
- package/dist/chunks/definitions.js.map +0 -1
- package/dist/chunks/renderChunk.js +0 -61
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/config.d.ts +0 -288
- package/dist/config.js +0 -417
- package/dist/config.js.map +0 -1
- package/dist/debug.d.ts +0 -204
- package/dist/debug.js +0 -733
- package/dist/debug.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -30
- package/dist/hooks/useGlobalStyles.js +0 -83
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -56
- package/dist/hooks/useKeyframes.js +0 -69
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -79
- package/dist/hooks/useProperty.js +0 -114
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -53
- package/dist/hooks/useRawCSS.js +0 -40
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -45
- package/dist/hooks/useStyles.js +0 -248
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -165
- package/dist/injector/index.js +0 -162
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -148
- package/dist/injector/injector.js +0 -436
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -136
- package/dist/injector/sheet-manager.js +0 -729
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -144
- package/dist/keyframes/index.js +0 -206
- package/dist/keyframes/index.js.map +0 -1
- package/dist/parser/classify.js +0 -319
- package/dist/parser/classify.js.map +0 -1
- package/dist/parser/const.js +0 -33
- package/dist/parser/const.js.map +0 -1
- package/dist/parser/lru.js +0 -109
- package/dist/parser/lru.js.map +0 -1
- package/dist/parser/parser.d.ts +0 -25
- package/dist/parser/parser.js +0 -116
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/tokenizer.js +0 -69
- package/dist/parser/tokenizer.js.map +0 -1
- package/dist/parser/types.d.ts +0 -51
- package/dist/parser/types.js +0 -46
- package/dist/parser/types.js.map +0 -1
- package/dist/pipeline/conditions.d.ts +0 -134
- package/dist/pipeline/conditions.js +0 -406
- package/dist/pipeline/conditions.js.map +0 -1
- package/dist/pipeline/exclusive.js +0 -231
- package/dist/pipeline/exclusive.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -53
- package/dist/pipeline/index.js +0 -660
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -856
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -451
- package/dist/pipeline/parseStateKey.js.map +0 -1
- package/dist/pipeline/simplify.js +0 -516
- package/dist/pipeline/simplify.js.map +0 -1
- package/dist/pipeline/warnings.js +0 -18
- package/dist/pipeline/warnings.js.map +0 -1
- package/dist/plugins/okhsl-plugin.d.ts +0 -35
- package/dist/plugins/okhsl-plugin.js +0 -371
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -69
- package/dist/properties/index.js +0 -236
- package/dist/properties/index.js.map +0 -1
- package/dist/properties/property-type-resolver.d.ts +0 -24
- package/dist/properties/property-type-resolver.js +0 -87
- package/dist/properties/property-type-resolver.js.map +0 -1
- package/dist/ssr/async-storage.d.ts +0 -17
- package/dist/ssr/async-storage.js.map +0 -1
- package/dist/ssr/collect-auto-properties.js +0 -40
- package/dist/ssr/collect-auto-properties.js.map +0 -1
- package/dist/ssr/collector.js +0 -173
- package/dist/ssr/collector.js.map +0 -1
- package/dist/ssr/context.d.ts +0 -8
- package/dist/ssr/context.js +0 -14
- package/dist/ssr/context.js.map +0 -1
- package/dist/ssr/format-global-rules.js.map +0 -1
- package/dist/ssr/format-keyframes.js +0 -70
- package/dist/ssr/format-keyframes.js.map +0 -1
- package/dist/ssr/format-property.js +0 -48
- package/dist/ssr/format-property.js.map +0 -1
- package/dist/ssr/format-rules.js +0 -70
- package/dist/ssr/format-rules.js.map +0 -1
- package/dist/ssr/hydrate.d.ts +0 -22
- package/dist/ssr/hydrate.js +0 -50
- package/dist/ssr/hydrate.js.map +0 -1
- package/dist/ssr/ssr-collector-ref.js +0 -12
- package/dist/ssr/ssr-collector-ref.js.map +0 -1
- package/dist/states/index.d.ts +0 -49
- package/dist/states/index.js +0 -416
- package/dist/states/index.js.map +0 -1
- package/dist/static/tastyStatic.d.ts +0 -46
- package/dist/static/tastyStatic.js +0 -31
- package/dist/static/tastyStatic.js.map +0 -1
- package/dist/static/types.d.ts +0 -49
- package/dist/static/types.js +0 -24
- package/dist/static/types.js.map +0 -1
- package/dist/styles/align.d.ts +0 -15
- package/dist/styles/align.js +0 -14
- package/dist/styles/align.js.map +0 -1
- package/dist/styles/border.d.ts +0 -25
- package/dist/styles/border.js +0 -114
- package/dist/styles/border.js.map +0 -1
- package/dist/styles/color.d.ts +0 -14
- package/dist/styles/color.js +0 -23
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/createStyle.js +0 -77
- package/dist/styles/createStyle.js.map +0 -1
- package/dist/styles/dimension.js +0 -97
- package/dist/styles/dimension.js.map +0 -1
- package/dist/styles/display.d.ts +0 -37
- package/dist/styles/display.js +0 -67
- package/dist/styles/display.js.map +0 -1
- package/dist/styles/fade.d.ts +0 -15
- package/dist/styles/fade.js +0 -58
- package/dist/styles/fade.js.map +0 -1
- package/dist/styles/fill.d.ts +0 -42
- package/dist/styles/fill.js +0 -52
- package/dist/styles/fill.js.map +0 -1
- package/dist/styles/flow.d.ts +0 -16
- package/dist/styles/flow.js +0 -12
- package/dist/styles/flow.js.map +0 -1
- package/dist/styles/gap.d.ts +0 -31
- package/dist/styles/gap.js +0 -37
- package/dist/styles/gap.js.map +0 -1
- package/dist/styles/height.d.ts +0 -17
- package/dist/styles/height.js +0 -20
- package/dist/styles/height.js.map +0 -1
- package/dist/styles/index.d.ts +0 -2
- package/dist/styles/index.js +0 -9
- package/dist/styles/index.js.map +0 -1
- package/dist/styles/inset.d.ts +0 -52
- package/dist/styles/inset.js +0 -150
- package/dist/styles/inset.js.map +0 -1
- package/dist/styles/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.js.map +0 -1
- package/dist/styles/list.d.ts +0 -16
- package/dist/styles/list.js +0 -98
- package/dist/styles/list.js.map +0 -1
- package/dist/styles/margin.d.ts +0 -24
- package/dist/styles/margin.js +0 -104
- package/dist/styles/margin.js.map +0 -1
- package/dist/styles/outline.d.ts +0 -29
- package/dist/styles/outline.js +0 -65
- package/dist/styles/outline.js.map +0 -1
- package/dist/styles/padding.d.ts +0 -24
- package/dist/styles/padding.js +0 -104
- package/dist/styles/padding.js.map +0 -1
- package/dist/styles/predefined.d.ts +0 -71
- package/dist/styles/predefined.js +0 -238
- package/dist/styles/predefined.js.map +0 -1
- package/dist/styles/preset.d.ts +0 -47
- package/dist/styles/preset.js +0 -126
- package/dist/styles/preset.js.map +0 -1
- package/dist/styles/radius.d.ts +0 -14
- package/dist/styles/radius.js +0 -51
- package/dist/styles/radius.js.map +0 -1
- package/dist/styles/scrollbar.d.ts +0 -25
- package/dist/styles/scrollbar.js +0 -48
- package/dist/styles/scrollbar.js.map +0 -1
- package/dist/styles/shadow.d.ts +0 -14
- package/dist/styles/shadow.js +0 -24
- package/dist/styles/shadow.js.map +0 -1
- package/dist/styles/transition.d.ts +0 -14
- package/dist/styles/transition.js +0 -158
- package/dist/styles/transition.js.map +0 -1
- package/dist/styles/types.d.ts +0 -495
- package/dist/styles/width.d.ts +0 -17
- package/dist/styles/width.js +0 -20
- package/dist/styles/width.js.map +0 -1
- package/dist/tasty.d.ts +0 -981
- package/dist/tasty.js +0 -206
- package/dist/tasty.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -26
- package/dist/utils/cache-wrapper.js.map +0 -1
- package/dist/utils/case-converter.js +0 -8
- package/dist/utils/case-converter.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -9
- package/dist/utils/colors.js.map +0 -1
- package/dist/utils/css-types.d.ts +0 -7
- package/dist/utils/dotize.d.ts +0 -26
- package/dist/utils/dotize.js +0 -122
- package/dist/utils/dotize.js.map +0 -1
- package/dist/utils/filter-base-props.d.ts +0 -15
- package/dist/utils/filter-base-props.js +0 -45
- package/dist/utils/filter-base-props.js.map +0 -1
- package/dist/utils/get-display-name.d.ts +0 -7
- package/dist/utils/get-display-name.js +0 -10
- package/dist/utils/get-display-name.js.map +0 -1
- package/dist/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/is-dev-env.js +0 -19
- package/dist/utils/is-dev-env.js.map +0 -1
- package/dist/utils/is-valid-element-type.js +0 -15
- package/dist/utils/is-valid-element-type.js.map +0 -1
- package/dist/utils/merge-styles.js.map +0 -1
- package/dist/utils/mod-attrs.d.ts +0 -8
- package/dist/utils/mod-attrs.js +0 -21
- package/dist/utils/mod-attrs.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
- package/dist/utils/process-tokens.d.ts +0 -31
- package/dist/utils/process-tokens.js +0 -171
- package/dist/utils/process-tokens.js.map +0 -1
- package/dist/utils/resolve-recipes.d.ts +0 -17
- package/dist/utils/resolve-recipes.js.map +0 -1
- package/dist/utils/selector-transform.js +0 -32
- package/dist/utils/selector-transform.js.map +0 -1
- package/dist/utils/string.js +0 -8
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/styles.d.ts +0 -177
- package/dist/utils/styles.js +0 -730
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -36
- package/dist/utils/typography.js +0 -53
- package/dist/utils/typography.js.map +0 -1
- package/dist/utils/warnings.d.ts +0 -16
- package/dist/utils/warnings.js +0 -16
- package/dist/utils/warnings.js.map +0 -1
- package/dist/zero/css-writer.d.ts +0 -45
- package/dist/zero/css-writer.js +0 -74
- package/dist/zero/css-writer.js.map +0 -1
- package/dist/zero/extractor.d.ts +0 -24
- package/dist/zero/extractor.js.map +0 -1
- package/docs/usage.md +0 -695
package/docs/tasty-static.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Zero Runtime Mode (tastyStatic)
|
|
2
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.
|
|
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
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -11,9 +11,30 @@
|
|
|
11
11
|
- **Performance-critical pages** — Zero runtime overhead for styling
|
|
12
12
|
- **Landing pages** — Minimal bundle size with pre-generated CSS
|
|
13
13
|
|
|
14
|
-
##
|
|
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
|
+
---
|
|
15
36
|
|
|
16
|
-
|
|
37
|
+
## Quick Start
|
|
17
38
|
|
|
18
39
|
### Basic Usage
|
|
19
40
|
|
|
@@ -109,6 +130,8 @@ module.exports = {
|
|
|
109
130
|
};
|
|
110
131
|
```
|
|
111
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
|
+
|
|
112
135
|
### With Configuration
|
|
113
136
|
|
|
114
137
|
```javascript
|
|
@@ -120,7 +143,7 @@ module.exports = {
|
|
|
120
143
|
states: {
|
|
121
144
|
'@mobile': '@media(w < 768px)',
|
|
122
145
|
'@tablet': '@media(w < 1024px)',
|
|
123
|
-
'@dark': '@root(
|
|
146
|
+
'@dark': '@root(schema=dark)',
|
|
124
147
|
},
|
|
125
148
|
devMode: true,
|
|
126
149
|
},
|
|
@@ -134,9 +157,42 @@ module.exports = {
|
|
|
134
157
|
| Option | Type | Default | Description |
|
|
135
158
|
|--------|------|---------|-------------|
|
|
136
159
|
| `output` | `string` | `'tasty.css'` | Path for generated CSS file |
|
|
137
|
-
| `
|
|
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)' }`) |
|
|
138
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. |
|
|
139
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.globalStyles` | `Record<string, Styles>` | — | Global Tasty styles keyed by CSS selector. 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
|
+
| `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). |
|
|
182
|
+
|
|
183
|
+
### Coexisting with runtime tasty
|
|
184
|
+
|
|
185
|
+
When a page mixes `tastyStatic` with runtime `tasty`, both must use **different** `namePrefix` values. The defaults handle this automatically (`'t'` for runtime, `'ts'` for zero-runtime). If you customize one, customize the other:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
// tasty-zero.config.ts (Babel plugin)
|
|
189
|
+
export default { namePrefix: 'mbs' };
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
// app entry (runtime configure)
|
|
194
|
+
configure({ namePrefix: 'mb' });
|
|
195
|
+
```
|
|
140
196
|
|
|
141
197
|
---
|
|
142
198
|
|
|
@@ -176,31 +232,52 @@ const card = tastyStatic({
|
|
|
176
232
|
|
|
177
233
|
## Next.js Integration
|
|
178
234
|
|
|
179
|
-
|
|
180
|
-
// next.config.js
|
|
181
|
-
const { withTastyZero } = require('@tenphi/tasty/next');
|
|
235
|
+
The `withTastyZero` wrapper configures both **webpack** and **Turbopack** automatically. No `--webpack` flag is needed — it works with whichever bundler Next.js uses.
|
|
182
236
|
|
|
183
|
-
|
|
237
|
+
```typescript
|
|
238
|
+
// next.config.ts
|
|
239
|
+
import { withTastyZero } from '@tenphi/tasty/next';
|
|
240
|
+
|
|
241
|
+
export default withTastyZero({
|
|
184
242
|
output: 'public/tasty.css',
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
'@mobile': '@media(w < 768px)',
|
|
188
|
-
},
|
|
189
|
-
devMode: process.env.NODE_ENV === 'development',
|
|
190
|
-
},
|
|
243
|
+
configFile: './app/tasty-zero.config.ts',
|
|
244
|
+
configDeps: ['./app/theme.ts'],
|
|
191
245
|
})({
|
|
192
246
|
reactStrictMode: true,
|
|
193
247
|
});
|
|
194
248
|
```
|
|
195
249
|
|
|
196
|
-
###
|
|
250
|
+
### `withTastyZero` Options
|
|
197
251
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
252
|
+
| Option | Type | Default | Description |
|
|
253
|
+
|--------|------|---------|-------------|
|
|
254
|
+
| `output` | `string` | `'public/tasty.css'` | Output path for CSS relative to project root |
|
|
255
|
+
| `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS |
|
|
256
|
+
| `enabled` | `boolean` | `true` | Enable/disable the plugin |
|
|
257
|
+
| `configFile` | `string` | — | Path to a TS/JS module that default-exports `TastyZeroConfig`. Recommended for Turbopack compatibility. |
|
|
258
|
+
| `config` | `TastyZeroConfig` | — | Inline config object. For static configs that don't change during dev. |
|
|
259
|
+
| `configDeps` | `string[]` | `[]` | Extra files the config depends on (for cache invalidation) |
|
|
260
|
+
|
|
261
|
+
### Turbopack Support
|
|
262
|
+
|
|
263
|
+
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.
|
|
201
264
|
|
|
202
|
-
|
|
203
|
-
|
|
265
|
+
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.
|
|
266
|
+
|
|
267
|
+
**Requirements**: `babel-loader` must be installed in your project:
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
pnpm add babel-loader
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### CSS Injection
|
|
274
|
+
|
|
275
|
+
`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.
|
|
276
|
+
|
|
277
|
+
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`:
|
|
278
|
+
|
|
279
|
+
```gitignore
|
|
280
|
+
public/tasty.css
|
|
204
281
|
```
|
|
205
282
|
|
|
206
283
|
---
|
|
@@ -285,6 +362,91 @@ export const Button = () => <button className={button}>Click</button>;
|
|
|
285
362
|
|
|
286
363
|
---
|
|
287
364
|
|
|
365
|
+
## Inject Mode
|
|
366
|
+
|
|
367
|
+
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.
|
|
368
|
+
|
|
369
|
+
This is ideal for **reusable components**, **extensions**, and **libraries** where consumers shouldn't need to manage an external CSS file.
|
|
370
|
+
|
|
371
|
+
### How It Works
|
|
372
|
+
|
|
373
|
+
1. The Babel plugin extracts CSS at build time (same pipeline as file mode).
|
|
374
|
+
2. Instead of writing to a `.css` file, the CSS is embedded as string literals in the JS output.
|
|
375
|
+
3. The `@tenphi/tasty/static` import is rewritten to `@tenphi/tasty/static/inject`.
|
|
376
|
+
4. Each `tastyStatic` call becomes a self-contained expression that injects its CSS and evaluates to a `StaticStyle` object.
|
|
377
|
+
|
|
378
|
+
### Configuration
|
|
379
|
+
|
|
380
|
+
```javascript
|
|
381
|
+
// babel.config.js
|
|
382
|
+
module.exports = {
|
|
383
|
+
plugins: [
|
|
384
|
+
['@tenphi/tasty/babel-plugin', {
|
|
385
|
+
mode: 'inject',
|
|
386
|
+
config: {
|
|
387
|
+
states: { '@mobile': '@media(w < 768px)' },
|
|
388
|
+
},
|
|
389
|
+
}]
|
|
390
|
+
]
|
|
391
|
+
};
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
With Next.js:
|
|
395
|
+
|
|
396
|
+
```typescript
|
|
397
|
+
// next.config.ts
|
|
398
|
+
import { withTastyZero } from '@tenphi/tasty/next';
|
|
399
|
+
|
|
400
|
+
export default withTastyZero({
|
|
401
|
+
mode: 'inject',
|
|
402
|
+
configFile: './app/tasty-zero.config.ts',
|
|
403
|
+
})({
|
|
404
|
+
reactStrictMode: true,
|
|
405
|
+
});
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
When `mode` is `'inject'`, the `output` and `injectImport` options are ignored.
|
|
409
|
+
|
|
410
|
+
### Build Transformation (inject mode)
|
|
411
|
+
|
|
412
|
+
**Before:**
|
|
413
|
+
|
|
414
|
+
```tsx
|
|
415
|
+
import { tastyStatic } from '@tenphi/tasty/static';
|
|
416
|
+
|
|
417
|
+
const button = tastyStatic({
|
|
418
|
+
padding: '2x 4x',
|
|
419
|
+
fill: '#purple',
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
tastyStatic('.heading', { preset: 'h1' });
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
**After:**
|
|
426
|
+
|
|
427
|
+
```tsx
|
|
428
|
+
import { injectCSS as _$i } from '@tenphi/tasty/static/inject';
|
|
429
|
+
|
|
430
|
+
const button = (_$i("ts3f2a1b ts8c4d2e", ".ts3f2a1b.ts3f2a1b{padding:16px 32px}\n.ts8c4d2e.ts8c4d2e{background:#9370db}"), {
|
|
431
|
+
className: 'ts3f2a1b ts8c4d2e',
|
|
432
|
+
styles: { padding: '2x 4x', fill: '#purple' },
|
|
433
|
+
toString() { return this.className; }
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
_$i(".heading", ".heading{font-size:2.5rem;font-weight:700;line-height:1.2}");
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Dev Mode / HMR
|
|
440
|
+
|
|
441
|
+
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.
|
|
442
|
+
|
|
443
|
+
### Limitations (inject mode)
|
|
444
|
+
|
|
445
|
+
- **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()`.
|
|
446
|
+
- **Larger JS bundle** — CSS is embedded in JavaScript, increasing bundle size. Best suited for components and extensions, not full-app styling.
|
|
447
|
+
|
|
448
|
+
---
|
|
449
|
+
|
|
288
450
|
## Style Extension
|
|
289
451
|
|
|
290
452
|
```tsx
|
|
@@ -366,11 +528,20 @@ const card = tastyStatic({
|
|
|
366
528
|
2. **Use selector mode** for global/body styles
|
|
367
529
|
3. **Enable devMode** in development for easier debugging
|
|
368
530
|
4. **Configure states** for consistent responsive breakpoints
|
|
369
|
-
|
|
531
|
+
|
|
532
|
+
---
|
|
533
|
+
|
|
534
|
+
## Common Issues
|
|
535
|
+
|
|
536
|
+
- 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.
|
|
537
|
+
- 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()`.
|
|
538
|
+
- Turbopack config behaves inconsistently: prefer `configFile` over inline functions so the setup stays JSON-serializable.
|
|
370
539
|
|
|
371
540
|
---
|
|
372
541
|
|
|
373
542
|
## Related
|
|
374
543
|
|
|
375
|
-
- [
|
|
544
|
+
- [Docs Hub](README.md) — Choose the right guide by task or rendering mode
|
|
545
|
+
- [Style DSL](dsl.md) — State maps, tokens, units, extending semantics (shared by runtime and static)
|
|
546
|
+
- [React API](react-api.md) — Runtime styling: `tasty()` factory, component props, variants, sub-elements, style functions
|
|
376
547
|
- [Configuration](configuration.md) — Global configuration: tokens, recipes, custom units, and style handlers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tenphi/tasty",
|
|
3
|
-
"version": "0.0.0-snapshot.
|
|
3
|
+
"version": "0.0.0-snapshot.2ea241d",
|
|
4
4
|
"description": "A design-system-integrated styling system and DSL for concise, state-aware UI styling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
"import": "./dist/static/index.js",
|
|
18
18
|
"default": "./dist/static/index.js"
|
|
19
19
|
},
|
|
20
|
+
"./static/inject": {
|
|
21
|
+
"types": "./dist/static/inject.d.ts",
|
|
22
|
+
"import": "./dist/static/inject.js",
|
|
23
|
+
"default": "./dist/static/inject.js"
|
|
24
|
+
},
|
|
20
25
|
"./babel-plugin": {
|
|
21
26
|
"types": "./dist/zero/babel.d.ts",
|
|
22
27
|
"import": "./dist/zero/babel.js",
|
|
@@ -52,6 +57,11 @@
|
|
|
52
57
|
"import": "./dist/ssr/astro.js",
|
|
53
58
|
"default": "./dist/ssr/astro.js"
|
|
54
59
|
},
|
|
60
|
+
"./ssr/astro-client": {
|
|
61
|
+
"types": "./dist/ssr/astro-client.d.ts",
|
|
62
|
+
"import": "./dist/ssr/astro-client.js",
|
|
63
|
+
"default": "./dist/ssr/astro-client.js"
|
|
64
|
+
},
|
|
55
65
|
"./tasty.config": "./tasty.config.ts"
|
|
56
66
|
},
|
|
57
67
|
"files": [
|
|
@@ -62,7 +72,8 @@
|
|
|
62
72
|
"sideEffects": [
|
|
63
73
|
"./dist/ssr/index.js",
|
|
64
74
|
"./dist/ssr/next.js",
|
|
65
|
-
"./dist/ssr/astro.js"
|
|
75
|
+
"./dist/ssr/astro.js",
|
|
76
|
+
"./dist/ssr/astro-client.js"
|
|
66
77
|
],
|
|
67
78
|
"engines": {
|
|
68
79
|
"node": ">=20"
|
|
@@ -78,6 +89,7 @@
|
|
|
78
89
|
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
79
90
|
"format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
|
|
80
91
|
"size": "size-limit",
|
|
92
|
+
"bench": "vitest bench",
|
|
81
93
|
"prepublishOnly": "pnpm run build",
|
|
82
94
|
"changeset": "changeset",
|
|
83
95
|
"version": "changeset version",
|
|
@@ -110,6 +122,7 @@
|
|
|
110
122
|
"@babel/core": "^7.24.0",
|
|
111
123
|
"@babel/helper-plugin-utils": "^7.24.0",
|
|
112
124
|
"@babel/types": "^7.24.0",
|
|
125
|
+
"jiti": "^2.6.1",
|
|
113
126
|
"react": "^18.0.0 || ^19.0.0"
|
|
114
127
|
},
|
|
115
128
|
"peerDependenciesMeta": {
|
|
@@ -124,15 +137,17 @@
|
|
|
124
137
|
},
|
|
125
138
|
"react": {
|
|
126
139
|
"optional": true
|
|
140
|
+
},
|
|
141
|
+
"jiti": {
|
|
142
|
+
"optional": true
|
|
127
143
|
}
|
|
128
144
|
},
|
|
129
145
|
"dependencies": {
|
|
130
|
-
"csstype": "^3.1.0"
|
|
131
|
-
"jiti": "^2.6.1"
|
|
146
|
+
"csstype": "^3.1.0"
|
|
132
147
|
},
|
|
133
148
|
"devDependencies": {
|
|
134
149
|
"@babel/core": "^7.24.0",
|
|
135
|
-
"@changesets/changelog-github": "^0.
|
|
150
|
+
"@changesets/changelog-github": "^0.7.0",
|
|
136
151
|
"@changesets/cli": "^2.29.8",
|
|
137
152
|
"@eslint/js": "^10.0.1",
|
|
138
153
|
"@size-limit/esbuild": "^12.0.0",
|
|
@@ -146,12 +161,13 @@
|
|
|
146
161
|
"@vitest/runner": "^4.0.18",
|
|
147
162
|
"eslint": "^10.0.0",
|
|
148
163
|
"eslint-config-prettier": "^10.1.8",
|
|
149
|
-
"
|
|
164
|
+
"happy-dom": "^20.9.0",
|
|
165
|
+
"jsdom": "^29.0.2",
|
|
150
166
|
"prettier": "^3.8.1",
|
|
151
167
|
"react": "^19.0.0",
|
|
152
168
|
"size-limit": "^12.0.0",
|
|
153
|
-
"tsdown": "^0.
|
|
154
|
-
"typescript": "^
|
|
169
|
+
"tsdown": "^0.22.0",
|
|
170
|
+
"typescript": "^6.0.2",
|
|
155
171
|
"typescript-eslint": "^8.56.0",
|
|
156
172
|
"vitest": "^4.0.18"
|
|
157
173
|
},
|
|
@@ -160,25 +176,25 @@
|
|
|
160
176
|
"esbuild"
|
|
161
177
|
]
|
|
162
178
|
},
|
|
163
|
-
"packageManager": "pnpm@
|
|
179
|
+
"packageManager": "pnpm@11.0.8",
|
|
164
180
|
"size-limit": [
|
|
165
181
|
{
|
|
166
182
|
"name": "main (import *)",
|
|
167
183
|
"path": "dist/index.js",
|
|
168
184
|
"import": "*",
|
|
169
|
-
"limit": "
|
|
185
|
+
"limit": "52 kB"
|
|
170
186
|
},
|
|
171
187
|
{
|
|
172
188
|
"name": "core (import *)",
|
|
173
189
|
"path": "dist/core/index.js",
|
|
174
190
|
"import": "*",
|
|
175
|
-
"limit": "
|
|
191
|
+
"limit": "49.5 kB"
|
|
176
192
|
},
|
|
177
193
|
{
|
|
178
194
|
"name": "static",
|
|
179
195
|
"path": "dist/static/index.js",
|
|
180
196
|
"import": "*",
|
|
181
|
-
"limit": "
|
|
197
|
+
"limit": "17 kB"
|
|
182
198
|
},
|
|
183
199
|
{
|
|
184
200
|
"name": "zero",
|
|
@@ -189,7 +205,7 @@
|
|
|
189
205
|
"path",
|
|
190
206
|
"crypto"
|
|
191
207
|
],
|
|
192
|
-
"limit": "
|
|
208
|
+
"limit": "31 kB"
|
|
193
209
|
},
|
|
194
210
|
{
|
|
195
211
|
"name": "babel-plugin",
|
|
@@ -200,7 +216,7 @@
|
|
|
200
216
|
"path",
|
|
201
217
|
"crypto"
|
|
202
218
|
],
|
|
203
|
-
"limit": "
|
|
219
|
+
"limit": "45.65 kB"
|
|
204
220
|
}
|
|
205
221
|
]
|
|
206
222
|
}
|
package/tasty.config.ts
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
3
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
4
|
-
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
//#endregion
|
|
8
|
-
export { __require };
|
package/dist/chunks/cacheKey.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { extractLocalPredefinedStates, extractPredefinedStateRefs } from "../states/index.js";
|
|
2
|
-
|
|
3
|
-
//#region src/chunks/cacheKey.ts
|
|
4
|
-
/**
|
|
5
|
-
* Chunk-specific cache key generation.
|
|
6
|
-
*
|
|
7
|
-
* Generates cache keys that only include styles relevant to a specific chunk,
|
|
8
|
-
* enabling more granular caching and reuse.
|
|
9
|
-
*
|
|
10
|
-
* Enhanced to support predefined states:
|
|
11
|
-
* - Global predefined states don't affect cache keys (constant across app)
|
|
12
|
-
* - Local predefined states only affect cache keys if referenced in the chunk
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Recursively serialize a value with sorted keys for stable output.
|
|
16
|
-
* This ensures that {a: 1, b: 2} and {b: 2, a: 1} produce the same string.
|
|
17
|
-
*/
|
|
18
|
-
function stableStringify(value) {
|
|
19
|
-
if (value === null) return "null";
|
|
20
|
-
if (value === void 0) return "undefined";
|
|
21
|
-
if (typeof value !== "object") return JSON.stringify(value);
|
|
22
|
-
if (Array.isArray(value)) return "[" + value.map(stableStringify).join(",") + "]";
|
|
23
|
-
const obj = value;
|
|
24
|
-
const sortedKeys = Object.keys(obj).sort();
|
|
25
|
-
const parts = [];
|
|
26
|
-
for (const key of sortedKeys) if (obj[key] !== void 0) parts.push(`${JSON.stringify(key)}:${stableStringify(obj[key])}`);
|
|
27
|
-
return "{" + parts.join(",") + "}";
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Generate a cache key for a specific chunk.
|
|
31
|
-
*
|
|
32
|
-
* Only includes the styles that belong to this chunk, allowing
|
|
33
|
-
* chunks to be cached independently.
|
|
34
|
-
*
|
|
35
|
-
* Also includes relevant local predefined states that are referenced
|
|
36
|
-
* by this chunk's styles.
|
|
37
|
-
*
|
|
38
|
-
* @param styles - The full styles object
|
|
39
|
-
* @param chunkName - Name of the chunk
|
|
40
|
-
* @param styleKeys - Keys of styles belonging to this chunk
|
|
41
|
-
* @returns A stable cache key string
|
|
42
|
-
*/
|
|
43
|
-
function generateChunkCacheKey(styles, chunkName, styleKeys) {
|
|
44
|
-
const parts = [chunkName];
|
|
45
|
-
const sortedKeys = styleKeys.slice().sort();
|
|
46
|
-
let chunkStylesStr = "";
|
|
47
|
-
for (const key of sortedKeys) {
|
|
48
|
-
const value = styles[key];
|
|
49
|
-
if (value !== void 0) {
|
|
50
|
-
const serialized = stableStringify(value);
|
|
51
|
-
parts.push(`${key}:${serialized}`);
|
|
52
|
-
chunkStylesStr += serialized;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const localStates = extractLocalPredefinedStates(styles);
|
|
56
|
-
if (Object.keys(localStates).length > 0) {
|
|
57
|
-
const referencedStates = extractPredefinedStateRefs(chunkStylesStr);
|
|
58
|
-
const relevantLocalStates = [];
|
|
59
|
-
for (const stateName of referencedStates) if (localStates[stateName]) relevantLocalStates.push(`${stateName}=${localStates[stateName]}`);
|
|
60
|
-
if (relevantLocalStates.length > 0) {
|
|
61
|
-
relevantLocalStates.sort();
|
|
62
|
-
parts.unshift(`[states:${relevantLocalStates.join("|")}]`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return parts.join("\0");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
//#endregion
|
|
69
|
-
export { generateChunkCacheKey };
|
|
70
|
-
//# sourceMappingURL=cacheKey.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cacheKey.js","names":[],"sources":["../../src/chunks/cacheKey.ts"],"sourcesContent":["/**\n * Chunk-specific cache key generation.\n *\n * Generates cache keys that only include styles relevant to a specific chunk,\n * enabling more granular caching and reuse.\n *\n * Enhanced to support predefined states:\n * - Global predefined states don't affect cache keys (constant across app)\n * - Local predefined states only affect cache keys if referenced in the chunk\n */\n\nimport {\n extractLocalPredefinedStates,\n extractPredefinedStateRefs,\n} from '../states';\nimport type { Styles } from '../styles/types';\n\n/**\n * Recursively serialize a value with sorted keys for stable output.\n * This ensures that {a: 1, b: 2} and {b: 2, a: 1} produce the same string.\n */\nfunction stableStringify(value: unknown): string {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return 'undefined';\n }\n if (typeof value !== 'object') {\n return JSON.stringify(value);\n }\n if (Array.isArray(value)) {\n return '[' + value.map(stableStringify).join(',') + ']';\n }\n // Object: sort keys for stable order\n const obj = value as Record<string, unknown>;\n const sortedKeys = Object.keys(obj).sort();\n const parts: string[] = [];\n for (const key of sortedKeys) {\n if (obj[key] !== undefined) {\n parts.push(`${JSON.stringify(key)}:${stableStringify(obj[key])}`);\n }\n }\n return '{' + parts.join(',') + '}';\n}\n\n/**\n * Generate a cache key for a specific chunk.\n *\n * Only includes the styles that belong to this chunk, allowing\n * chunks to be cached independently.\n *\n * Also includes relevant local predefined states that are referenced\n * by this chunk's styles.\n *\n * @param styles - The full styles object\n * @param chunkName - Name of the chunk\n * @param styleKeys - Keys of styles belonging to this chunk\n * @returns A stable cache key string\n */\nexport function generateChunkCacheKey(\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): string {\n // Start with chunk name for namespace separation\n const parts: string[] = [chunkName];\n\n // Sort keys for stable ordering\n const sortedKeys = styleKeys.slice().sort();\n\n // Build the chunk-specific styles string for predefined state detection\n let chunkStylesStr = '';\n\n for (const key of sortedKeys) {\n const value = styles[key];\n if (value !== undefined) {\n // Use stable stringify for consistent serialization regardless of key order\n const serialized = stableStringify(value);\n parts.push(`${key}:${serialized}`);\n chunkStylesStr += serialized;\n }\n }\n\n // Extract local predefined states from the full styles object\n const localStates = extractLocalPredefinedStates(styles);\n\n // Only include local predefined states that are actually referenced in this chunk\n if (Object.keys(localStates).length > 0) {\n const referencedStates = extractPredefinedStateRefs(chunkStylesStr);\n const relevantLocalStates: string[] = [];\n\n for (const stateName of referencedStates) {\n if (localStates[stateName]) {\n relevantLocalStates.push(`${stateName}=${localStates[stateName]}`);\n }\n }\n\n // Add relevant local states to the cache key (sorted for stability)\n if (relevantLocalStates.length > 0) {\n relevantLocalStates.sort();\n parts.unshift(`[states:${relevantLocalStates.join('|')}]`);\n }\n }\n\n // Use null character as separator (safe, not in JSON output)\n return parts.join('\\0');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,SAAS,gBAAgB,OAAwB;AAC/C,KAAI,UAAU,KACZ,QAAO;AAET,KAAI,UAAU,OACZ,QAAO;AAET,KAAI,OAAO,UAAU,SACnB,QAAO,KAAK,UAAU,MAAM;AAE9B,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,MAAM,IAAI,gBAAgB,CAAC,KAAK,IAAI,GAAG;CAGtD,MAAM,MAAM;CACZ,MAAM,aAAa,OAAO,KAAK,IAAI,CAAC,MAAM;CAC1C,MAAM,QAAkB,EAAE;AAC1B,MAAK,MAAM,OAAO,WAChB,KAAI,IAAI,SAAS,OACf,OAAM,KAAK,GAAG,KAAK,UAAU,IAAI,CAAC,GAAG,gBAAgB,IAAI,KAAK,GAAG;AAGrE,QAAO,MAAM,MAAM,KAAK,IAAI,GAAG;;;;;;;;;;;;;;;;AAiBjC,SAAgB,sBACd,QACA,WACA,WACQ;CAER,MAAM,QAAkB,CAAC,UAAU;CAGnC,MAAM,aAAa,UAAU,OAAO,CAAC,MAAM;CAG3C,IAAI,iBAAiB;AAErB,MAAK,MAAM,OAAO,YAAY;EAC5B,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,QAAW;GAEvB,MAAM,aAAa,gBAAgB,MAAM;AACzC,SAAM,KAAK,GAAG,IAAI,GAAG,aAAa;AAClC,qBAAkB;;;CAKtB,MAAM,cAAc,6BAA6B,OAAO;AAGxD,KAAI,OAAO,KAAK,YAAY,CAAC,SAAS,GAAG;EACvC,MAAM,mBAAmB,2BAA2B,eAAe;EACnE,MAAM,sBAAgC,EAAE;AAExC,OAAK,MAAM,aAAa,iBACtB,KAAI,YAAY,WACd,qBAAoB,KAAK,GAAG,UAAU,GAAG,YAAY,aAAa;AAKtE,MAAI,oBAAoB,SAAS,GAAG;AAClC,uBAAoB,MAAM;AAC1B,SAAM,QAAQ,WAAW,oBAAoB,KAAK,IAAI,CAAC,GAAG;;;AAK9D,QAAO,MAAM,KAAK,KAAK"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
//#region src/chunks/definitions.d.ts
|
|
2
|
-
declare const CHUNK_NAMES: {
|
|
3
|
-
/** Special chunk for styles that cannot be split (e.g., @starting-style) */readonly COMBINED: "combined";
|
|
4
|
-
readonly SUBCOMPONENTS: "subcomponents";
|
|
5
|
-
readonly APPEARANCE: "appearance";
|
|
6
|
-
readonly FONT: "font";
|
|
7
|
-
readonly DIMENSION: "dimension";
|
|
8
|
-
readonly DISPLAY: "display";
|
|
9
|
-
readonly LAYOUT: "layout";
|
|
10
|
-
readonly POSITION: "position";
|
|
11
|
-
readonly MISC: "misc";
|
|
12
|
-
};
|
|
13
|
-
type ChunkName = (typeof CHUNK_NAMES)[keyof typeof CHUNK_NAMES];
|
|
14
|
-
/**
|
|
15
|
-
* Pre-computed map for O(1) style-to-chunk lookup.
|
|
16
|
-
* Built once at module load time.
|
|
17
|
-
*/
|
|
18
|
-
declare const STYLE_TO_CHUNK: Map<string, ChunkName>;
|
|
19
|
-
interface ChunkInfo {
|
|
20
|
-
/** Name of the chunk */
|
|
21
|
-
name: ChunkName | string;
|
|
22
|
-
/** Style keys belonging to this chunk */
|
|
23
|
-
styleKeys: string[];
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Categorize style keys into chunks.
|
|
27
|
-
*
|
|
28
|
-
* Returns chunks in a deterministic order (by CHUNK_ORDER) regardless
|
|
29
|
-
* of the order of keys in the input styles object.
|
|
30
|
-
*
|
|
31
|
-
* @param styles - The styles object to categorize
|
|
32
|
-
* @returns Map of chunk name to array of style keys in that chunk (in priority order)
|
|
33
|
-
*/
|
|
34
|
-
declare function categorizeStyleKeys(styles: Record<string, unknown>): Map<string, string[]>;
|
|
35
|
-
//#endregion
|
|
36
|
-
export { CHUNK_NAMES, ChunkInfo, ChunkName, STYLE_TO_CHUNK, categorizeStyleKeys };
|
|
37
|
-
//# sourceMappingURL=definitions.d.ts.map
|