@tenphi/tasty 0.0.0-snapshot.c8c7b2a → 0.0.0-snapshot.ca60cc0
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 +440 -367
- 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--0qoqt_P.js +60 -0
- package/dist/chunks/build-config--0qoqt_P.js.map +1 -0
- package/dist/{ssr/collector.js → chunks/collector-zp5BrLF0.js} +79 -104
- package/dist/chunks/collector-zp5BrLF0.js.map +1 -0
- package/dist/chunks/config-engine-BaLq8HrX.js +272 -0
- package/dist/chunks/config-engine-BaLq8HrX.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-CfXZ3tU9.js +910 -0
- package/dist/chunks/css-definitions-CfXZ3tU9.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--OC-WA-Q.js} +195 -146
- package/dist/chunks/debug--OC-WA-Q.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-DnZ6M1Iv.js +691 -0
- package/dist/chunks/react-runtime-DnZ6M1Iv.js.map +1 -0
- package/dist/chunks/runtime-engine-J9X_h-Pw.js +2435 -0
- package/dist/chunks/runtime-engine-J9X_h-Pw.js.map +1 -0
- package/dist/chunks/runtime-state-o_v3Bj7b.js +152 -0
- package/dist/chunks/runtime-state-o_v3Bj7b.js.map +1 -0
- package/dist/{utils/merge-styles.js → chunks/shared-utils-y-HjvPN4.js} +60 -56
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-D6lC3O3G.js +5626 -0
- package/dist/chunks/style-engine-D6lC3O3G.js.map +1 -0
- package/dist/chunks/zero-engine-BnjoV04F.js +310 -0
- package/dist/chunks/zero-engine-BnjoV04F.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 -1
- package/dist/ssr/astro-client.js +1 -14
- package/dist/ssr/astro-client.js.map +1 -1
- 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 +11 -8
- package/dist/ssr/astro-middleware.js +2 -14
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +33 -14
- package/dist/ssr/astro.js +163 -91
- 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 -4
- package/dist/ssr/index.js +6 -6
- 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 +9 -9
- package/dist/ssr/next.js +30 -45
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +90 -5
- package/dist/static/index.js +31 -3
- package/dist/static/index.js.map +1 -0
- package/dist/static/inject.d.ts +1 -2
- package/dist/static/inject.js.map +1 -1
- package/dist/types-CYQIhUg1.d.ts +1569 -0
- package/dist/zero/babel.d.ts +12 -20
- package/dist/zero/babel.js +107 -154
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +136 -3
- package/dist/zero/index.js +25 -3
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +3 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +20 -9
- package/docs/adoption.md +69 -36
- package/docs/ai-agents.md +259 -0
- package/docs/comparison.md +77 -47
- package/docs/configuration.md +648 -85
- package/docs/debug.md +28 -15
- package/docs/design-system.md +166 -33
- package/docs/dsl.md +739 -196
- package/docs/getting-started.md +130 -50
- package/docs/injector.md +162 -71
- package/docs/methodology.md +106 -49
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +319 -70
- package/docs/plugins.md +333 -0
- package/docs/react-api.md +236 -47
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +310 -116
- package/docs/styles.md +234 -49
- package/docs/tasty-static.md +298 -130
- package/package.json +146 -40
- package/tasty.config.ts +7 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -7
- package/dist/chunks/cacheKey.d.ts +0 -1
- package/dist/chunks/cacheKey.js +0 -77
- package/dist/chunks/cacheKey.js.map +0 -1
- package/dist/chunks/definitions.d.ts +0 -37
- package/dist/chunks/definitions.js +0 -258
- package/dist/chunks/definitions.js.map +0 -1
- package/dist/chunks/index.d.ts +0 -1
- package/dist/chunks/renderChunk.d.ts +0 -1
- package/dist/chunks/renderChunk.js +0 -59
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/compute-styles.d.ts +0 -31
- package/dist/compute-styles.js +0 -322
- package/dist/compute-styles.js.map +0 -1
- package/dist/config.d.ts +0 -407
- package/dist/config.js +0 -591
- 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/index.d.ts +0 -7
- package/dist/hooks/useCounterStyle.d.ts +0 -36
- package/dist/hooks/useCounterStyle.js +0 -65
- package/dist/hooks/useCounterStyle.js.map +0 -1
- package/dist/hooks/useFontFace.d.ts +0 -45
- package/dist/hooks/useFontFace.js +0 -66
- package/dist/hooks/useFontFace.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -46
- package/dist/hooks/useGlobalStyles.js +0 -88
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -58
- package/dist/hooks/useKeyframes.js +0 -55
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -81
- package/dist/hooks/useProperty.js +0 -96
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -22
- package/dist/hooks/useRawCSS.js +0 -103
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -40
- package/dist/hooks/useStyles.js +0 -31
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -182
- package/dist/injector/index.js +0 -185
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -198
- package/dist/injector/injector.js +0 -651
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -132
- package/dist/injector/sheet-manager.js +0 -699
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -235
- 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 -60
- 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 -115
- 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 -285
- package/dist/pipeline/exclusive.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -55
- package/dist/pipeline/index.js +0 -708
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -1157
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -446
- package/dist/pipeline/parseStateKey.js.map +0 -1
- package/dist/pipeline/simplify.js +0 -690
- 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/index.d.ts +0 -2
- package/dist/plugins/okhsl-plugin.d.ts +0 -35
- package/dist/plugins/okhsl-plugin.js +0 -97
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -87
- package/dist/properties/index.js +0 -222
- 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 -90
- package/dist/properties/property-type-resolver.js.map +0 -1
- package/dist/rsc-cache.js +0 -79
- package/dist/rsc-cache.js.map +0 -1
- package/dist/ssr/async-storage.d.ts +0 -17
- package/dist/ssr/async-storage.js +0 -44
- package/dist/ssr/async-storage.js.map +0 -1
- package/dist/ssr/collect-auto-properties.js +0 -58
- package/dist/ssr/collect-auto-properties.js.map +0 -1
- package/dist/ssr/collector.d.ts +0 -98
- package/dist/ssr/collector.js.map +0 -1
- package/dist/ssr/context.js +0 -16
- 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 -69
- package/dist/ssr/format-keyframes.js.map +0 -1
- package/dist/ssr/format-property.js +0 -49
- 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 -29
- package/dist/ssr/hydrate.js +0 -45
- package/dist/ssr/hydrate.js.map +0 -1
- package/dist/ssr/ssr-collector-ref.js +0 -29
- package/dist/ssr/ssr-collector-ref.js.map +0 -1
- package/dist/states/index.d.ts +0 -49
- package/dist/states/index.js +0 -170
- package/dist/states/index.js.map +0 -1
- package/dist/static/tastyStatic.d.ts +0 -46
- package/dist/static/tastyStatic.js +0 -30
- 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/border.d.ts +0 -25
- package/dist/styles/border.js +0 -120
- package/dist/styles/border.js.map +0 -1
- package/dist/styles/color.d.ts +0 -14
- package/dist/styles/color.js +0 -26
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/const.js +0 -17
- package/dist/styles/const.js.map +0 -1
- package/dist/styles/createStyle.js +0 -79
- package/dist/styles/createStyle.js.map +0 -1
- package/dist/styles/dimension.js +0 -109
- package/dist/styles/dimension.js.map +0 -1
- package/dist/styles/directional.js +0 -133
- package/dist/styles/directional.js.map +0 -1
- package/dist/styles/display.d.ts +0 -30
- package/dist/styles/display.js +0 -73
- package/dist/styles/display.js.map +0 -1
- package/dist/styles/fade.d.ts +0 -15
- package/dist/styles/fade.js +0 -62
- package/dist/styles/fade.js.map +0 -1
- package/dist/styles/fill.d.ts +0 -42
- package/dist/styles/fill.js +0 -51
- 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 -38
- package/dist/styles/gap.js.map +0 -1
- package/dist/styles/height.d.ts +0 -17
- package/dist/styles/height.js +0 -19
- package/dist/styles/height.js.map +0 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +0 -8
- package/dist/styles/index.js.map +0 -1
- package/dist/styles/inset.d.ts +0 -24
- package/dist/styles/inset.js +0 -34
- package/dist/styles/inset.js.map +0 -1
- package/dist/styles/list.d.ts +0 -16
- package/dist/styles/list.js +0 -100
- package/dist/styles/list.js.map +0 -1
- package/dist/styles/margin.d.ts +0 -24
- package/dist/styles/margin.js +0 -32
- package/dist/styles/margin.js.map +0 -1
- package/dist/styles/outline.d.ts +0 -29
- package/dist/styles/outline.js +0 -55
- package/dist/styles/outline.js.map +0 -1
- package/dist/styles/padding.d.ts +0 -24
- package/dist/styles/padding.js +0 -32
- package/dist/styles/padding.js.map +0 -1
- package/dist/styles/placement.d.ts +0 -37
- package/dist/styles/placement.js +0 -74
- package/dist/styles/placement.js.map +0 -1
- package/dist/styles/predefined.d.ts +0 -71
- package/dist/styles/predefined.js +0 -237
- 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 -12
- package/dist/styles/radius.js +0 -83
- package/dist/styles/radius.js.map +0 -1
- package/dist/styles/scrollMargin.d.ts +0 -24
- package/dist/styles/scrollMargin.js +0 -32
- package/dist/styles/scrollMargin.js.map +0 -1
- package/dist/styles/scrollbar.d.ts +0 -25
- package/dist/styles/scrollbar.js +0 -51
- package/dist/styles/scrollbar.js.map +0 -1
- package/dist/styles/shadow.d.ts +0 -14
- package/dist/styles/shadow.js +0 -25
- package/dist/styles/shadow.js.map +0 -1
- package/dist/styles/shared.js +0 -17
- package/dist/styles/shared.js.map +0 -1
- package/dist/styles/transition.d.ts +0 -14
- package/dist/styles/transition.js +0 -159
- package/dist/styles/transition.js.map +0 -1
- package/dist/styles/types.d.ts +0 -564
- package/dist/styles/width.d.ts +0 -17
- package/dist/styles/width.js +0 -19
- package/dist/styles/width.js.map +0 -1
- package/dist/tasty.d.ts +0 -134
- package/dist/tasty.js +0 -248
- package/dist/tasty.js.map +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -21
- 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 -228
- package/dist/utils/color-space.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -10
- package/dist/utils/colors.js.map +0 -1
- package/dist/utils/css-types.d.ts +0 -7
- package/dist/utils/deps-equal.js +0 -15
- package/dist/utils/deps-equal.js.map +0 -1
- 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/hash.js +0 -14
- package/dist/utils/hash.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 -6
- package/dist/utils/mod-attrs.js +0 -20
- package/dist/utils/mod-attrs.js.map +0 -1
- package/dist/utils/process-tokens.d.ts +0 -17
- package/dist/utils/process-tokens.js +0 -83
- 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 -146
- 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 -220
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -58
- 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 -73
- package/dist/zero/css-writer.js.map +0 -1
- package/dist/zero/extractor.d.ts +0 -24
- package/dist/zero/extractor.js +0 -266
- package/dist/zero/extractor.js.map +0 -1
package/docs/injector.md
CHANGED
|
@@ -9,11 +9,11 @@ A high-performance CSS-in-JS solution that powers the Tasty design system with e
|
|
|
9
9
|
The Style Injector is the core engine behind Tasty's styling system, providing:
|
|
10
10
|
|
|
11
11
|
- **Hash-based deduplication** - Identical CSS gets the same className
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
12
|
+
- **DOM-driven lifetime** - Styles are collected once nothing renders them
|
|
13
|
+
- **Selector assembly** - Prepends the doubled `.tX.tX` class and root prefix to the pipeline's selector fragments (sub-element and `&` nesting is flattened earlier, by the pipeline)
|
|
14
|
+
- **At-rule injection** - First-class `@keyframes`, `@property`, `@font-face`, `@counter-style`, and `@function` support
|
|
15
15
|
- **Smart cleanup** - CSS rules batched cleanup, keyframes disposed immediately
|
|
16
|
-
- **SSR support** - Deterministic class names and
|
|
16
|
+
- **SSR support** - Deterministic class names shared with `ServerStyleCollector`, and hydration of server-rendered classes
|
|
17
17
|
- **Multiple roots** - Works with Document and ShadowRoot
|
|
18
18
|
- **Non-stacking cleanups** - Prevents timeout accumulation for better performance
|
|
19
19
|
|
|
@@ -55,18 +55,26 @@ Injects CSS rules and returns a className with dispose function.
|
|
|
55
55
|
```typescript
|
|
56
56
|
import { inject } from '@tenphi/tasty';
|
|
57
57
|
|
|
58
|
-
//
|
|
58
|
+
// Rules flagged needsClassName get the generated class prepended (doubled)
|
|
59
59
|
const result = inject([{
|
|
60
|
-
selector: '
|
|
60
|
+
selector: '',
|
|
61
61
|
declarations: 'color: red; padding: 10px;',
|
|
62
|
+
needsClassName: true,
|
|
62
63
|
}]);
|
|
63
64
|
|
|
64
|
-
console.log(result.className); // 't
|
|
65
|
+
console.log(result.className); // 'th8n0uh' — `t` + base36 hash of the rules
|
|
66
|
+
// Injected: .th8n0uh.th8n0uh { color: red; padding: 10px; }
|
|
65
67
|
|
|
66
|
-
//
|
|
68
|
+
// Release the pin; the class becomes collectible once nothing renders it
|
|
67
69
|
result.dispose();
|
|
68
70
|
```
|
|
69
71
|
|
|
72
|
+
`inject()` **pins** the class it returns, and `gc()` never evicts a pinned class
|
|
73
|
+
— that is what `dispose()` releases. Pass `{ pin: false }` when the caller keeps
|
|
74
|
+
no handle and the DOM is the only record that the class is in use; `dispose()`
|
|
75
|
+
is then a no-op. The render path (`tasty()` / `computeStyles()`) injects this
|
|
76
|
+
way, because a hook-free render has no unmount signal to dispose on.
|
|
77
|
+
|
|
70
78
|
### `injectGlobal(rules, options?): { dispose: () => void }`
|
|
71
79
|
|
|
72
80
|
Injects global styles that don't reserve tasty class names.
|
|
@@ -169,7 +177,7 @@ const result = testInjector.inject(rules);
|
|
|
169
177
|
Injects CSS keyframes with automatic deduplication.
|
|
170
178
|
|
|
171
179
|
```typescript
|
|
172
|
-
// Generated name (
|
|
180
|
+
// Generated name (tk0, tk1, … — namePrefix + 'k' + counter)
|
|
173
181
|
const fadeIn = keyframes({
|
|
174
182
|
from: { opacity: 0 },
|
|
175
183
|
to: { opacity: 1 },
|
|
@@ -224,14 +232,78 @@ configure({
|
|
|
224
232
|
|
|
225
233
|
**Auto-Detection Features:**
|
|
226
234
|
- `devMode`: Automatically enabled in development environments (detected via `isDevEnv()`)
|
|
227
|
-
- `forceTextInjection`: Automatically enabled in test environments (Jest, Vitest, Mocha, jsdom)
|
|
235
|
+
- `forceTextInjection`: Automatically enabled in test environments (Jest, Vitest, Mocha, happy-dom, jsdom)
|
|
236
|
+
|
|
237
|
+
**Injection Modes:**
|
|
238
|
+
|
|
239
|
+
Each sheet picks its write mode once, when it is created, and keeps it for its
|
|
240
|
+
lifetime:
|
|
241
|
+
|
|
242
|
+
| Mode | How rules are written | How rules are removed |
|
|
243
|
+
|---|---|---|
|
|
244
|
+
| CSSOM (default) | `styleSheet.insertRule(rule, index)` | `styleSheet.deleteRule(index)` |
|
|
245
|
+
| Text (`forceTextInjection`, or when `styleElement.sheet` is unavailable) | appended to `<style>.textContent` | rule texts are tracked per sheet and the element's text is rebuilt without them |
|
|
246
|
+
| Adopted (ShadowRoot with constructable sheets) | `insertRule` on the constructable sheet | `deleteRule` on the constructable sheet |
|
|
247
|
+
|
|
248
|
+
Text mode cannot edit a single rule in place the way CSSOM can, so the sheet
|
|
249
|
+
keeps the inserted rule texts in index order and rewrites the element on delete.
|
|
250
|
+
Dispose, ref-counted cleanup and GC therefore behave identically in every mode.
|
|
228
251
|
|
|
229
252
|
**Configuration Notes:**
|
|
230
253
|
- Most options have sensible defaults and auto-detection
|
|
231
254
|
- `configure()` is optional - the injector works with defaults
|
|
232
255
|
- **Configuration is locked after styles are generated** - calling `configure()` after first render will emit a warning and be ignored
|
|
233
|
-
- `gc.touchInterval`: Number of
|
|
234
|
-
- `gc.
|
|
256
|
+
- `gc.touchInterval`: Number of renders between sweeps. When the counter reaches this value, a sweep is scheduled via `requestIdleCallback`; without idle callbacks nothing is collected automatically.
|
|
257
|
+
- `gc.grace`: How long a class is left alone after collection first notices nothing is carrying it, in milliseconds (default `10000`).
|
|
258
|
+
- Automatic sweeps are opt-in: they run only when `configure({ gc })` is set (`gc: {}` enables them with these defaults). Without it nothing is collected until you call `gc()` or `cleanup()`.
|
|
259
|
+
|
|
260
|
+
**What a sweep does.** Everything the injector holds falls into one of five bands, and only the last is ever deleted:
|
|
261
|
+
|
|
262
|
+
| Band | | Deleted |
|
|
263
|
+
|---|---|---|
|
|
264
|
+
| 1 | **Rendered** — some element carries the class right now | never |
|
|
265
|
+
| 2 | **Not ours** — queued for a batched write, pre-allocated, or server-rendered | never |
|
|
266
|
+
| 3 | **Hot** — nothing carries it, but that was noticed less than `grace` ago | never |
|
|
267
|
+
| 4 | **Cached** — cold, but within `capacity` when ordered by when it went cold | never |
|
|
268
|
+
| 5 | Everything else | on every sweep |
|
|
269
|
+
|
|
270
|
+
`gc({ force: true })` and `cleanup()` take bands 4 and 5 together, ignoring capacity. Band 3 is spared even then: an explicit cleanup is still no reason to take rules from a render that has not committed yet.
|
|
271
|
+
|
|
272
|
+
`tasty()` components cache the class names they computed, so a re-render with the same styles skips the pipeline. Whenever `gc()`, `cleanup()` or `destroy()` deletes rules, those caches are dropped too, so a component whose CSS was collected injects it again on its next render.
|
|
273
|
+
|
|
274
|
+
> **Why band 3 exists.** Rendering is not commit-aware: a render can resolve a class and commit it a little later, and in between nothing on the page carries it. From outside React that is indistinguishable from a class that is finished, so collection does not try to tell them apart — it leaves alone anything only just noticed to be cold. A render would have to stay pending for the whole window to lose its rules, and it gets them back on its next render.
|
|
275
|
+
>
|
|
276
|
+
> The clock starts when a sweep *notices*, not when the element actually left — nothing observes that moment, so starting it at the sighting is what gives every class the same full window however long ago it went.
|
|
277
|
+
>
|
|
278
|
+
> This is also why collection costs nothing to run: the timestamps are written by the sweep's own DOM scan, so rendering tracks nothing per class.
|
|
279
|
+
- `gc.capacity`: Maximum number of unused styles (not in the DOM, not pinned) to retain. When exceeded, the least recently used are evicted first. Rendered and pinned styles don't count against this limit.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
### At-rule injection
|
|
284
|
+
|
|
285
|
+
Beyond ordinary rules, the injector has a dedicated entry point per at-rule. All of them deduplicate by name and are **permanent** — there is no ref-counting or dispose, because a rule that other CSS references by name cannot be safely removed while any of it might still apply.
|
|
286
|
+
|
|
287
|
+
| Function | Injects | Notes |
|
|
288
|
+
|---|---|---|
|
|
289
|
+
| `keyframes(steps, nameOrOptions?)` | `@keyframes` | The exception: ref-counted and disposed immediately when unused. Returns the injected name, which may differ from the requested one. |
|
|
290
|
+
| `property(name, options?)` | `@property` | `name` accepts `$name`, `#name`, or `--name`. Usually unnecessary — types are inferred automatically unless `configure({ autoPropertyTypes: false })`. |
|
|
291
|
+
| `fontFace(family, descriptors, options?)` | `@font-face` | Deduplicated by family **and** descriptor content, so several faces of one family coexist. |
|
|
292
|
+
| `counterStyle(name, descriptors, options?)` | `@counter-style` | |
|
|
293
|
+
| `func(name, definition, options?)` | `@function` | `name` accepts `$$name`, `$name`, or `--name`. Abbreviated because `function` is a reserved word. |
|
|
294
|
+
|
|
295
|
+
Every one of these takes an optional `root` (a `Document` or `ShadowRoot`).
|
|
296
|
+
|
|
297
|
+
`counterStyle()` and `func()` also accept `weak: true`, which registers the rule **without** overriding an existing one of the same name. `configure()` uses it for global `@counter-style` and `@function` definitions so a component-local definition always wins over the global default, regardless of which is injected first.
|
|
298
|
+
|
|
299
|
+
```ts
|
|
300
|
+
import { counterStyle, fontFace, func, property } from '@tenphi/tasty';
|
|
301
|
+
|
|
302
|
+
property('$card-elevation', { syntax: '<number>', initialValue: '0' });
|
|
303
|
+
fontFace('Inter', { src: 'url(/inter.woff2)', fontWeight: '400 700' });
|
|
304
|
+
counterStyle('dashes', { system: 'cyclic', symbols: '"—"', suffix: ' ' });
|
|
305
|
+
func('$$negative', { args: ['$value'], result: '(-1 * $value)' });
|
|
306
|
+
```
|
|
235
307
|
|
|
236
308
|
---
|
|
237
309
|
|
|
@@ -239,60 +311,74 @@ configure({
|
|
|
239
311
|
|
|
240
312
|
### Style Result Format
|
|
241
313
|
|
|
242
|
-
The injector works with `StyleResult` objects from the
|
|
314
|
+
The injector works with `StyleResult` objects from the pipeline (`renderStyles`):
|
|
243
315
|
|
|
244
316
|
```typescript
|
|
245
317
|
interface StyleResult {
|
|
246
|
-
selector: string;
|
|
247
|
-
declarations: string;
|
|
248
|
-
atRules?: string[];
|
|
249
|
-
|
|
318
|
+
selector: string; // full selector, or a fragment when needsClassName
|
|
319
|
+
declarations: string; // CSS declarations
|
|
320
|
+
atRules?: string[]; // @media, @container, @supports, …
|
|
321
|
+
needsClassName?: boolean; // prepend the generated `.tX.tX` (OR'd fragments joined with '|||')
|
|
322
|
+
rootPrefix?: string; // root-state prefix placed before the class
|
|
323
|
+
startingStyle?: boolean; // wrap declarations in @starting-style
|
|
250
324
|
}
|
|
251
325
|
|
|
252
326
|
// Example StyleResult
|
|
253
327
|
const styleRule: StyleResult = {
|
|
254
|
-
selector: '
|
|
328
|
+
selector: ':where([data-hovered])',
|
|
255
329
|
declarations: 'padding: 8px 16px; background: blue; color: white;',
|
|
256
330
|
atRules: ['@media (min-width: 768px)'],
|
|
257
|
-
|
|
331
|
+
needsClassName: true,
|
|
258
332
|
};
|
|
259
333
|
```
|
|
260
334
|
|
|
335
|
+
### Batched Injection
|
|
336
|
+
|
|
337
|
+
`configure({ batchInjection: true })` queues every sheet write — component
|
|
338
|
+
rules, global rules, raw CSS and at-rules — into one FIFO and applies them
|
|
339
|
+
together, so the document is style-invalidated once per flush instead of once per
|
|
340
|
+
component. `<TastyBatchProvider>` flushes in `useInsertionEffect`, before any
|
|
341
|
+
layout effect, so a queued write can never be observed by a measurement. See
|
|
342
|
+
[Batched injection](configuration.md#batched-injection) for the modes and the
|
|
343
|
+
ordering guarantee. `flushStyles()` applies pending writes on demand; every read
|
|
344
|
+
API here calls it for you.
|
|
345
|
+
|
|
261
346
|
### Deduplication & Performance
|
|
262
347
|
|
|
263
348
|
```typescript
|
|
264
|
-
|
|
265
|
-
const button1 = inject([{
|
|
266
|
-
selector: '.t-btn1',
|
|
267
|
-
declarations: 'padding: 8px; color: red;'
|
|
268
|
-
}]);
|
|
349
|
+
const rule = { selector: '', declarations: 'padding: 8px; color: red;', needsClassName: true };
|
|
269
350
|
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
declarations: 'padding: 8px; color: red;' // Same declarations
|
|
273
|
-
}]);
|
|
351
|
+
const button1 = inject([rule], { cacheKey: 'button' });
|
|
352
|
+
const button2 = inject([rule], { cacheKey: 'button' });
|
|
274
353
|
|
|
275
|
-
//
|
|
354
|
+
// One class, one copy of the CSS
|
|
276
355
|
console.log(button1.className === button2.className); // true
|
|
277
356
|
```
|
|
278
357
|
|
|
279
|
-
|
|
358
|
+
Without `cacheKey` the class name is a hash of the rules, so injecting the same rules again reuses the class the same way: the rules are written once, and each call adds a pin that its own `dispose()` releases.
|
|
359
|
+
|
|
360
|
+
### Pinning
|
|
280
361
|
|
|
281
362
|
```typescript
|
|
282
|
-
// Multiple
|
|
283
|
-
const comp1 = inject([commonStyle]);
|
|
284
|
-
const comp2 = inject([commonStyle]);
|
|
285
|
-
const comp3 = inject([commonStyle]);
|
|
286
|
-
|
|
287
|
-
// Style is
|
|
288
|
-
comp1.dispose(); //
|
|
289
|
-
comp2.dispose(); //
|
|
290
|
-
comp3.dispose(); //
|
|
291
|
-
|
|
292
|
-
//
|
|
293
|
-
//
|
|
363
|
+
// Multiple callers using the same styles
|
|
364
|
+
const comp1 = inject([commonStyle], { cacheKey: 'common' });
|
|
365
|
+
const comp2 = inject([commonStyle], { cacheKey: 'common' });
|
|
366
|
+
const comp3 = inject([commonStyle], { cacheKey: 'common' });
|
|
367
|
+
|
|
368
|
+
// Style is pinned while any caller holds a handle
|
|
369
|
+
comp1.dispose(); // pins: 3 → 2
|
|
370
|
+
comp2.dispose(); // pins: 2 → 1
|
|
371
|
+
comp3.dispose(); // pins: 1 → 0, now up to the DOM and gc()
|
|
372
|
+
|
|
373
|
+
// Unpinned does not mean deleted: the rule stays cached and is reused instantly
|
|
374
|
+
// by the next inject(). gc() decides when it actually goes.
|
|
294
375
|
```
|
|
295
376
|
|
|
377
|
+
Pinning covers callers that hold a handle. Styles that come from rendering are
|
|
378
|
+
never pinned — see `{ pin: false }` under
|
|
379
|
+
[`inject()`](#injectrules-options-injectresult) — so what keeps them alive is
|
|
380
|
+
being in the DOM, and nothing else.
|
|
381
|
+
|
|
296
382
|
### Garbage Collection
|
|
297
383
|
|
|
298
384
|
```typescript
|
|
@@ -300,6 +386,9 @@ import { configure, gc } from '@tenphi/tasty';
|
|
|
300
386
|
|
|
301
387
|
// Keyframes: Disposed immediately when refCount = 0 (safer for global scope)
|
|
302
388
|
// CSS rules: Tracked by touch count and cleaned up via gc()
|
|
389
|
+
//
|
|
390
|
+
// A CSS rule is collectible when no element carries its class AND nobody
|
|
391
|
+
// pinned it with inject().
|
|
303
392
|
|
|
304
393
|
configure({
|
|
305
394
|
gc: {
|
|
@@ -314,15 +403,19 @@ gc();
|
|
|
314
403
|
// Force-remove ALL unused styles (e.g. on route change or test teardown):
|
|
315
404
|
gc({ force: true });
|
|
316
405
|
|
|
317
|
-
//
|
|
318
|
-
|
|
406
|
+
// cleanup() is the same thing:
|
|
407
|
+
cleanup();
|
|
408
|
+
|
|
409
|
+
// Every `touchInterval` renders, a sweep is scheduled in idle time. It scans
|
|
410
|
+
// the DOM for the classes actually on the page and sorts everything the
|
|
411
|
+
// injector holds into five bands — only the last one is deleted. See below.
|
|
319
412
|
|
|
320
413
|
// Benefits:
|
|
321
414
|
// - Activity-proportional: busy apps trigger GC more often
|
|
322
415
|
// - DOM-safe: styles currently in the DOM are never evicted
|
|
323
416
|
// - Oldest-first: least recently used styles are evicted first
|
|
324
417
|
// - Keyframes: Immediate cleanup prevents global namespace pollution
|
|
325
|
-
// - Unused styles
|
|
418
|
+
// - Unused styles stay cached until evicted, so re-rendering them is a cache hit
|
|
326
419
|
```
|
|
327
420
|
|
|
328
421
|
### Shadow DOM Support
|
|
@@ -349,15 +442,16 @@ const shadowAnimation = keyframes({
|
|
|
349
442
|
|
|
350
443
|
### Server-Side Rendering
|
|
351
444
|
|
|
445
|
+
`getCSSText()` reads the injector's stylesheets, so it needs a DOM; on a server it throws. Collect server CSS with `ServerStyleCollector` from `@tenphi/tasty/ssr` (`collector.getCSS()`) — see [SSR](./ssr.md).
|
|
446
|
+
|
|
352
447
|
```typescript
|
|
353
|
-
import {
|
|
448
|
+
import { getCSSText, getCSSTextForNode } from '@tenphi/tasty';
|
|
449
|
+
import { render } from '@testing-library/react';
|
|
354
450
|
|
|
355
|
-
//
|
|
356
|
-
const cssText = getCssText();
|
|
451
|
+
const cssText = getCSSText(); // everything the injector holds (browser / test DOM)
|
|
357
452
|
|
|
358
|
-
|
|
359
|
-
const
|
|
360
|
-
const componentCSS = getCssTextForNode(container);
|
|
453
|
+
const { container } = render(<MyComponent />);
|
|
454
|
+
const componentCSS = getCSSTextForNode(container); // only the CSS this subtree uses
|
|
361
455
|
```
|
|
362
456
|
|
|
363
457
|
### Test Environment Detection
|
|
@@ -366,7 +460,7 @@ const componentCSS = getCssTextForNode(container);
|
|
|
366
460
|
// Automatically detected test environments:
|
|
367
461
|
// - NODE_ENV === 'test'
|
|
368
462
|
// - Jest globals (jest, describe, it, expect)
|
|
369
|
-
// - jsdom user agent
|
|
463
|
+
// - jsdom / HappyDOM user agent
|
|
370
464
|
// - Vitest globals (vitest)
|
|
371
465
|
// - Mocha globals (mocha)
|
|
372
466
|
|
|
@@ -417,11 +511,11 @@ const metrics = injector.instance.getMetrics();
|
|
|
417
511
|
console.log({
|
|
418
512
|
cacheHits: metrics.hits, // Successful cache hits
|
|
419
513
|
cacheMisses: metrics.misses, // New styles injected
|
|
420
|
-
unusedHits: metrics.unusedHits, //
|
|
514
|
+
unusedHits: metrics.unusedHits, // Styles currently eligible for eviction (scans the DOM)
|
|
421
515
|
bulkCleanups: metrics.bulkCleanups, // Number of bulk cleanup operations
|
|
422
516
|
stylesCleanedUp: metrics.stylesCleanedUp, // Total styles removed in bulk cleanups
|
|
423
517
|
totalInsertions: metrics.totalInsertions, // Lifetime insertions
|
|
424
|
-
totalUnused: metrics.totalUnused, //
|
|
518
|
+
totalUnused: metrics.totalUnused, // Times a pinned style lost its last pin
|
|
425
519
|
startTime: metrics.startTime, // Metrics collection start timestamp
|
|
426
520
|
cleanupHistory: metrics.cleanupHistory, // Detailed cleanup operation history
|
|
427
521
|
});
|
|
@@ -430,17 +524,14 @@ console.log({
|
|
|
430
524
|
### Debug Information
|
|
431
525
|
|
|
432
526
|
```typescript
|
|
433
|
-
|
|
434
|
-
const debugInfo = injector.instance.getDebugInfo();
|
|
527
|
+
import { tastyDebug } from '@tenphi/tasty';
|
|
435
528
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
unusedStyles: debugInfo.unusedStyles, // Styles marked for cleanup
|
|
439
|
-
totalSheets: debugInfo.totalSheets, // Number of stylesheets
|
|
440
|
-
totalRules: debugInfo.totalRules, // Total CSS rules
|
|
441
|
-
});
|
|
529
|
+
const { activeClasses, unusedClasses, hotClasses, totalRuleCount } =
|
|
530
|
+
tastyDebug.summary({ raw: true });
|
|
442
531
|
```
|
|
443
532
|
|
|
533
|
+
See [Debug Utilities](./debug.md).
|
|
534
|
+
|
|
444
535
|
### Cleanup History
|
|
445
536
|
|
|
446
537
|
```typescript
|
|
@@ -465,10 +556,10 @@ metrics.cleanupHistory.forEach(cleanup => {
|
|
|
465
556
|
|
|
466
557
|
```typescript
|
|
467
558
|
// ✅ Reuse styles - identical CSS gets deduplicated
|
|
468
|
-
const buttonBase =
|
|
559
|
+
const buttonBase = 'padding: 8px 16px; border-radius: 4px;';
|
|
469
560
|
|
|
470
561
|
// ✅ Avoid frequent disposal and re-injection
|
|
471
|
-
// Let the
|
|
562
|
+
// Let the injector handle cleanup
|
|
472
563
|
|
|
473
564
|
// ✅ Use bulk operations for global styles
|
|
474
565
|
injectGlobal([
|
|
@@ -494,13 +585,13 @@ configure({
|
|
|
494
585
|
// The injector automatically manages memory through:
|
|
495
586
|
|
|
496
587
|
// 1. Hash-based deduplication - same CSS = same className
|
|
497
|
-
// 2.
|
|
498
|
-
// 3.
|
|
499
|
-
// 4.
|
|
500
|
-
// 5.
|
|
588
|
+
// 2. DOM-driven lifetime - a rendered class is never evicted
|
|
589
|
+
// 3. Pinning - inject() callers hold their classes until they dispose
|
|
590
|
+
// 4. Immediate keyframes cleanup - disposed instantly when refCount = 0
|
|
591
|
+
// 5. Touch-count GC - unused CSS rules are evicted oldest-first when over capacity
|
|
501
592
|
|
|
502
593
|
// Manual cleanup is rarely needed but available:
|
|
503
|
-
cleanup(); //
|
|
594
|
+
cleanup(); // Remove every rule that is neither rendered nor pinned
|
|
504
595
|
destroy(); // Nuclear option: remove all stylesheets and reset
|
|
505
596
|
```
|
|
506
597
|
|
|
@@ -522,9 +613,9 @@ const StyledButton = tasty({
|
|
|
522
613
|
|
|
523
614
|
// Internally uses the injector:
|
|
524
615
|
// 1. Styles are parsed into StyleResult objects
|
|
525
|
-
// 2. inject() is called with the parsed results
|
|
616
|
+
// 2. inject() is called with the parsed results, unpinned
|
|
526
617
|
// 3. Component gets the returned className
|
|
527
|
-
// 4.
|
|
618
|
+
// 4. gc() reclaims the class once no element carries it
|
|
528
619
|
```
|
|
529
620
|
|
|
530
621
|
For most development, you'll use the [React API](./react-api.md) rather than the injector directly. The injector provides the high-performance foundation that makes Tasty's declarative styling possible.
|