@tenphi/tasty 0.0.0-snapshot.db103fd → 0.0.0-snapshot.dc62ea3
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 +196 -140
- package/dist/astro-CeYENy2x.js +301 -0
- package/dist/astro-CeYENy2x.js.map +1 -0
- package/dist/{ssr/async-storage.js → async-storage-DKK-wTD4.js} +16 -6
- package/dist/async-storage-DKK-wTD4.js.map +1 -0
- package/dist/babel-DWCsafYw.d.ts +83 -0
- package/dist/collector-B3OsM252.js +327 -0
- package/dist/collector-B3OsM252.js.map +1 -0
- package/dist/collector-BTVXj2hS.d.ts +163 -0
- package/dist/config-B3gPdCqd.js +12421 -0
- package/dist/config-B3gPdCqd.js.map +1 -0
- package/dist/config-LfIDmVHx.d.ts +1363 -0
- package/dist/context-CA8YKeMn.js +24 -0
- package/dist/context-CA8YKeMn.js.map +1 -0
- package/dist/core/index.d.ts +5 -33
- package/dist/core/index.js +6 -26
- package/dist/core-DGm0CFHP.js +1732 -0
- package/dist/core-DGm0CFHP.js.map +1 -0
- package/dist/css-resources-Cyl_axbI.js +149 -0
- package/dist/css-resources-Cyl_axbI.js.map +1 -0
- package/dist/{zero/extractor.js → css-writer-Bgowobbx.js} +148 -24
- package/dist/css-writer-Bgowobbx.js.map +1 -0
- package/dist/{ssr/format-global-rules.js → format-global-rules-DklyaXv-.js} +2 -2
- package/dist/format-global-rules-DklyaXv-.js.map +1 -0
- package/dist/{ssr/format-rules.js → format-rules-XRw9u7d4.js} +33 -2
- package/dist/format-rules-XRw9u7d4.js.map +1 -0
- package/dist/hydrate-CNOmZprz.js +37 -0
- package/dist/hydrate-CNOmZprz.js.map +1 -0
- package/dist/index-Bm9ltvdH.d.ts +1933 -0
- package/dist/index-BmogEzTo.d.ts +1575 -0
- package/dist/index.d.ts +5 -50
- package/dist/index.js +922 -35
- package/dist/index.js.map +1 -0
- package/dist/keyframes-DE-OE76F.js +535 -0
- package/dist/keyframes-DE-OE76F.js.map +1 -0
- package/dist/{utils/merge-styles.d.ts → merge-styles-BcLl1u_d.d.ts} +3 -3
- package/dist/{utils/merge-styles.js → merge-styles-DuoZEsm9.js} +3 -4
- package/dist/merge-styles-DuoZEsm9.js.map +1 -0
- package/dist/{utils/resolve-recipes.js → resolve-recipes-H9NqOQuP.js} +4 -6
- package/dist/resolve-recipes-H9NqOQuP.js.map +1 -0
- package/dist/ssr/astro-client.js +19 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware-extract-static.d.ts +11 -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 +11 -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 +18 -0
- package/dist/ssr/astro-middleware-static.js +18 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +19 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +117 -11
- package/dist/ssr/astro.js +2 -64
- package/dist/ssr/index.d.ts +37 -5
- package/dist/ssr/index.js +6 -7
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +66 -0
- package/dist/ssr/next-config.js +115 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +14 -7
- package/dist/ssr/next.js +38 -16
- package/dist/ssr/next.js.map +1 -1
- package/dist/ssr-collector-ref-COs_ioWl.js +29 -0
- package/dist/ssr-collector-ref-COs_ioWl.js.map +1 -0
- package/dist/static/index.d.ts +91 -5
- package/dist/static/index.js +49 -3
- package/dist/static/index.js.map +1 -0
- package/dist/static/inject.js.map +1 -1
- package/dist/zero/babel.d.ts +2 -182
- package/dist/zero/babel.js +80 -40
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +81 -3
- package/dist/zero/index.js +2 -3
- package/dist/zero/next.d.ts +1 -1
- package/dist/zero/next.js +1 -1
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +20 -12
- package/docs/adoption.md +59 -32
- package/docs/ai-agents.md +224 -0
- package/docs/comparison.md +76 -48
- package/docs/configuration.md +566 -69
- package/docs/debug.md +35 -18
- package/docs/design-system.md +63 -32
- package/docs/dsl.md +527 -179
- package/docs/getting-started.md +62 -41
- package/docs/injector.md +157 -51
- package/docs/methodology.md +116 -35
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +741 -0
- package/docs/plugins.md +353 -0
- package/docs/react-api.md +681 -0
- package/docs/runtime-benchmarks.md +351 -0
- package/docs/ssr.md +356 -130
- package/docs/styles.md +79 -16
- package/docs/tasty-static.md +149 -87
- package/package.json +78 -23
- package/tasty.config.ts +6 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -7
- 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/config.d.ts +0 -366
- package/dist/config.js +0 -503
- 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 +0 -453
- 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/resolve-ssr-collector.js +0 -14
- package/dist/hooks/resolve-ssr-collector.js.map +0 -1
- package/dist/hooks/useCounterStyle.d.ts +0 -50
- package/dist/hooks/useCounterStyle.js +0 -46
- package/dist/hooks/useCounterStyle.js.map +0 -1
- package/dist/hooks/useFontFace.d.ts +0 -43
- package/dist/hooks/useFontFace.js +0 -70
- package/dist/hooks/useFontFace.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -30
- package/dist/hooks/useGlobalStyles.js +0 -78
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -56
- package/dist/hooks/useKeyframes.js +0 -64
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -79
- package/dist/hooks/useProperty.js +0 -109
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -53
- package/dist/hooks/useRawCSS.js +0 -35
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -45
- package/dist/hooks/useStyles.js +0 -237
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -183
- package/dist/injector/index.js +0 -179
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -166
- package/dist/injector/injector.js +0 -464
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -136
- package/dist/injector/sheet-manager.js +0 -733
- 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 -319
- 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 -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 -230
- 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 -1103
- 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 -515
- 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 -76
- 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/ssr/astro.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 -39
- package/dist/ssr/collect-auto-properties.js.map +0 -1
- package/dist/ssr/collector.d.ts +0 -102
- package/dist/ssr/collector.js +0 -226
- package/dist/ssr/collector.js.map +0 -1
- package/dist/ssr/context.d.ts +0 -8
- package/dist/ssr/context.js +0 -13
- 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 -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.map +0 -1
- package/dist/ssr/hydrate.d.ts +0 -22
- package/dist/ssr/hydrate.js +0 -49
- 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 -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/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 -113
- 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/createStyle.js +0 -79
- package/dist/styles/createStyle.js.map +0 -1
- package/dist/styles/dimension.js +0 -96
- package/dist/styles/dimension.js.map +0 -1
- package/dist/styles/display.d.ts +0 -37
- package/dist/styles/display.js +0 -66
- package/dist/styles/display.js.map +0 -1
- package/dist/styles/fade.d.ts +0 -15
- package/dist/styles/fade.js +0 -57
- 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 -36
- 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 -52
- package/dist/styles/inset.js +0 -149
- 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 -103
- package/dist/styles/margin.js.map +0 -1
- package/dist/styles/outline.d.ts +0 -29
- package/dist/styles/outline.js +0 -64
- package/dist/styles/outline.js.map +0 -1
- package/dist/styles/padding.d.ts +0 -24
- package/dist/styles/padding.js +0 -103
- package/dist/styles/padding.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 -126
- package/dist/styles/preset.js.map +0 -1
- package/dist/styles/radius.d.ts +0 -12
- package/dist/styles/radius.js +0 -71
- package/dist/styles/radius.js.map +0 -1
- package/dist/styles/scrollbar.d.ts +0 -25
- package/dist/styles/scrollbar.js +0 -46
- package/dist/styles/scrollbar.js.map +0 -1
- package/dist/styles/shadow.d.ts +0 -14
- package/dist/styles/shadow.js +0 -23
- package/dist/styles/shadow.js.map +0 -1
- package/dist/styles/transition.d.ts +0 -14
- package/dist/styles/transition.js +0 -157
- package/dist/styles/transition.js.map +0 -1
- package/dist/styles/types.d.ts +0 -549
- 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 -119
- package/dist/tasty.js +0 -231
- 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/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 -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 -21
- package/dist/utils/process-tokens.js +0 -90
- 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 -99
- package/dist/utils/styles.js +0 -220
- 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 -73
- 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/PIPELINE.md +0 -519
- package/docs/runtime.md +0 -485
- /package/dist/{chunks/cacheKey.d.ts → ssr/astro-client.d.ts} +0 -0
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
//#region src/hooks/useProperty.d.ts
|
|
2
|
-
interface UsePropertyOptions {
|
|
3
|
-
/**
|
|
4
|
-
* CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>').
|
|
5
|
-
* For color tokens (#name), this is auto-set to '<color>' and cannot be overridden.
|
|
6
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax
|
|
7
|
-
*/
|
|
8
|
-
syntax?: string;
|
|
9
|
-
/**
|
|
10
|
-
* Whether the property inherits from parent elements
|
|
11
|
-
* @default true
|
|
12
|
-
*/
|
|
13
|
-
inherits?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Initial value for the property.
|
|
16
|
-
* For color tokens (#name), this defaults to 'transparent' if not specified.
|
|
17
|
-
*/
|
|
18
|
-
initialValue?: string | number;
|
|
19
|
-
/**
|
|
20
|
-
* Shadow root or document to inject into
|
|
21
|
-
*/
|
|
22
|
-
root?: Document | ShadowRoot;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Hook to register a CSS @property custom property.
|
|
26
|
-
* This enables advanced features like animating custom properties.
|
|
27
|
-
*
|
|
28
|
-
* Note: @property rules are global and persistent once defined.
|
|
29
|
-
* The hook ensures the property is only registered once per root.
|
|
30
|
-
*
|
|
31
|
-
* Accepts tasty token syntax for the property name:
|
|
32
|
-
* - `$name` → defines `--name`
|
|
33
|
-
* - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
|
|
34
|
-
* - `--name` → defines `--name` (legacy format)
|
|
35
|
-
*
|
|
36
|
-
* @param name - The property token ($name, #name) or CSS property name (--name)
|
|
37
|
-
* @param options - Property configuration
|
|
38
|
-
*
|
|
39
|
-
* @example Basic property with token syntax
|
|
40
|
-
* ```tsx
|
|
41
|
-
* function Spinner() {
|
|
42
|
-
* useProperty('$rotation', {
|
|
43
|
-
* syntax: '<angle>',
|
|
44
|
-
* inherits: false,
|
|
45
|
-
* initialValue: '0deg',
|
|
46
|
-
* });
|
|
47
|
-
*
|
|
48
|
-
* return <div className="spinner" />;
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @example Color property with token syntax (auto-sets syntax)
|
|
53
|
-
* ```tsx
|
|
54
|
-
* function MyComponent() {
|
|
55
|
-
* useProperty('#theme', {
|
|
56
|
-
* initialValue: 'red', // syntax: '<color>' is auto-set
|
|
57
|
-
* });
|
|
58
|
-
*
|
|
59
|
-
* // Now --theme-color can be animated with CSS transitions
|
|
60
|
-
* return <div style={{ '--theme-color': 'blue' } as React.CSSProperties}>Colored</div>;
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* @example Legacy format (still supported)
|
|
65
|
-
* ```tsx
|
|
66
|
-
* function ResizableBox() {
|
|
67
|
-
* useProperty('--box-size', {
|
|
68
|
-
* syntax: '<length>',
|
|
69
|
-
* initialValue: '100px',
|
|
70
|
-
* });
|
|
71
|
-
*
|
|
72
|
-
* return <div style={{ width: 'var(--box-size)' }} />;
|
|
73
|
-
* }
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
declare function useProperty(name: string, options?: UsePropertyOptions): void;
|
|
77
|
-
//#endregion
|
|
78
|
-
export { UsePropertyOptions, useProperty };
|
|
79
|
-
//# sourceMappingURL=useProperty.d.ts.map
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { getGlobalInjector } from "../config.js";
|
|
2
|
-
import { formatPropertyCSS } from "../ssr/format-property.js";
|
|
3
|
-
import { resolveSSRCollector } from "./resolve-ssr-collector.js";
|
|
4
|
-
import { TastySSRContext } from "../ssr/context.js";
|
|
5
|
-
import { useContext, useInsertionEffect, useMemo } from "react";
|
|
6
|
-
//#region src/hooks/useProperty.ts
|
|
7
|
-
/**
|
|
8
|
-
* Hook to register a CSS @property custom property.
|
|
9
|
-
* This enables advanced features like animating custom properties.
|
|
10
|
-
*
|
|
11
|
-
* Note: @property rules are global and persistent once defined.
|
|
12
|
-
* The hook ensures the property is only registered once per root.
|
|
13
|
-
*
|
|
14
|
-
* Accepts tasty token syntax for the property name:
|
|
15
|
-
* - `$name` → defines `--name`
|
|
16
|
-
* - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
|
|
17
|
-
* - `--name` → defines `--name` (legacy format)
|
|
18
|
-
*
|
|
19
|
-
* @param name - The property token ($name, #name) or CSS property name (--name)
|
|
20
|
-
* @param options - Property configuration
|
|
21
|
-
*
|
|
22
|
-
* @example Basic property with token syntax
|
|
23
|
-
* ```tsx
|
|
24
|
-
* function Spinner() {
|
|
25
|
-
* useProperty('$rotation', {
|
|
26
|
-
* syntax: '<angle>',
|
|
27
|
-
* inherits: false,
|
|
28
|
-
* initialValue: '0deg',
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* return <div className="spinner" />;
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @example Color property with token syntax (auto-sets syntax)
|
|
36
|
-
* ```tsx
|
|
37
|
-
* function MyComponent() {
|
|
38
|
-
* useProperty('#theme', {
|
|
39
|
-
* initialValue: 'red', // syntax: '<color>' is auto-set
|
|
40
|
-
* });
|
|
41
|
-
*
|
|
42
|
-
* // Now --theme-color can be animated with CSS transitions
|
|
43
|
-
* return <div style={{ '--theme-color': 'blue' } as React.CSSProperties}>Colored</div>;
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @example Legacy format (still supported)
|
|
48
|
-
* ```tsx
|
|
49
|
-
* function ResizableBox() {
|
|
50
|
-
* useProperty('--box-size', {
|
|
51
|
-
* syntax: '<length>',
|
|
52
|
-
* initialValue: '100px',
|
|
53
|
-
* });
|
|
54
|
-
*
|
|
55
|
-
* return <div style={{ width: 'var(--box-size)' }} />;
|
|
56
|
-
* }
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
function useProperty(name, options) {
|
|
60
|
-
const ssrCollector = resolveSSRCollector(useContext(TastySSRContext));
|
|
61
|
-
const optionsKey = useMemo(() => {
|
|
62
|
-
if (!options) return "";
|
|
63
|
-
return JSON.stringify({
|
|
64
|
-
syntax: options.syntax,
|
|
65
|
-
inherits: options.inherits,
|
|
66
|
-
initialValue: options.initialValue
|
|
67
|
-
});
|
|
68
|
-
}, [
|
|
69
|
-
options?.syntax,
|
|
70
|
-
options?.inherits,
|
|
71
|
-
options?.initialValue
|
|
72
|
-
]);
|
|
73
|
-
useMemo(() => {
|
|
74
|
-
if (!ssrCollector || !name) return;
|
|
75
|
-
ssrCollector.collectInternals();
|
|
76
|
-
const css = formatPropertyCSS(name, {
|
|
77
|
-
syntax: options?.syntax,
|
|
78
|
-
inherits: options?.inherits,
|
|
79
|
-
initialValue: options?.initialValue
|
|
80
|
-
});
|
|
81
|
-
if (css) ssrCollector.collectProperty(name, css);
|
|
82
|
-
}, [
|
|
83
|
-
ssrCollector,
|
|
84
|
-
name,
|
|
85
|
-
optionsKey
|
|
86
|
-
]);
|
|
87
|
-
useInsertionEffect(() => {
|
|
88
|
-
if (!name) {
|
|
89
|
-
console.warn(`[Tasty] useProperty: property name is required`);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const injector = getGlobalInjector();
|
|
93
|
-
if (injector.isPropertyDefined(name, { root: options?.root })) return;
|
|
94
|
-
injector.property(name, {
|
|
95
|
-
syntax: options?.syntax,
|
|
96
|
-
inherits: options?.inherits,
|
|
97
|
-
initialValue: options?.initialValue,
|
|
98
|
-
root: options?.root
|
|
99
|
-
});
|
|
100
|
-
}, [
|
|
101
|
-
name,
|
|
102
|
-
optionsKey,
|
|
103
|
-
options?.root
|
|
104
|
-
]);
|
|
105
|
-
}
|
|
106
|
-
//#endregion
|
|
107
|
-
export { useProperty };
|
|
108
|
-
|
|
109
|
-
//# sourceMappingURL=useProperty.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useProperty.js","names":[],"sources":["../../src/hooks/useProperty.ts"],"sourcesContent":["import { useContext, useInsertionEffect, useMemo } from 'react';\n\nimport { getGlobalInjector } from '../config';\nimport { resolveSSRCollector } from './resolve-ssr-collector';\nimport { TastySSRContext } from '../ssr/context';\nimport { formatPropertyCSS } from '../ssr/format-property';\n\nexport interface UsePropertyOptions {\n /**\n * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>').\n * For color tokens (#name), this is auto-set to '<color>' and cannot be overridden.\n * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax\n */\n syntax?: string;\n /**\n * Whether the property inherits from parent elements\n * @default true\n */\n inherits?: boolean;\n /**\n * Initial value for the property.\n * For color tokens (#name), this defaults to 'transparent' if not specified.\n */\n initialValue?: string | number;\n /**\n * Shadow root or document to inject into\n */\n root?: Document | ShadowRoot;\n}\n\n/**\n * Hook to register a CSS @property custom property.\n * This enables advanced features like animating custom properties.\n *\n * Note: @property rules are global and persistent once defined.\n * The hook ensures the property is only registered once per root.\n *\n * Accepts tasty token syntax for the property name:\n * - `$name` → defines `--name`\n * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')\n * - `--name` → defines `--name` (legacy format)\n *\n * @param name - The property token ($name, #name) or CSS property name (--name)\n * @param options - Property configuration\n *\n * @example Basic property with token syntax\n * ```tsx\n * function Spinner() {\n * useProperty('$rotation', {\n * syntax: '<angle>',\n * inherits: false,\n * initialValue: '0deg',\n * });\n *\n * return <div className=\"spinner\" />;\n * }\n * ```\n *\n * @example Color property with token syntax (auto-sets syntax)\n * ```tsx\n * function MyComponent() {\n * useProperty('#theme', {\n * initialValue: 'red', // syntax: '<color>' is auto-set\n * });\n *\n * // Now --theme-color can be animated with CSS transitions\n * return <div style={{ '--theme-color': 'blue' } as React.CSSProperties}>Colored</div>;\n * }\n * ```\n *\n * @example Legacy format (still supported)\n * ```tsx\n * function ResizableBox() {\n * useProperty('--box-size', {\n * syntax: '<length>',\n * initialValue: '100px',\n * });\n *\n * return <div style={{ width: 'var(--box-size)' }} />;\n * }\n * ```\n */\nexport function useProperty(name: string, options?: UsePropertyOptions): void {\n const ssrContextValue = useContext(TastySSRContext);\n const ssrCollector = resolveSSRCollector(ssrContextValue);\n\n // Memoize the options to create a stable dependency\n const optionsKey = useMemo(() => {\n if (!options) return '';\n return JSON.stringify({\n syntax: options.syntax,\n inherits: options.inherits,\n initialValue: options.initialValue,\n });\n }, [options?.syntax, options?.inherits, options?.initialValue]);\n\n // SSR path: collect @property CSS during render\n useMemo(() => {\n if (!ssrCollector || !name) return;\n\n ssrCollector.collectInternals();\n\n const css = formatPropertyCSS(name, {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n });\n if (css) {\n ssrCollector.collectProperty(name, css);\n }\n }, [ssrCollector, name, optionsKey]);\n\n // Client path: inject via DOM\n useInsertionEffect(() => {\n if (!name) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`[Tasty] useProperty: property name is required`);\n }\n return;\n }\n\n const injector = getGlobalInjector();\n\n if (injector.isPropertyDefined(name, { root: options?.root })) {\n return;\n }\n\n injector.property(name, {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n root: options?.root,\n });\n }, [name, optionsKey, options?.root]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,YAAY,MAAc,SAAoC;CAE5E,MAAM,eAAe,oBADG,WAAW,gBAAgB,CACM;CAGzD,MAAM,aAAa,cAAc;AAC/B,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,KAAK,UAAU;GACpB,QAAQ,QAAQ;GAChB,UAAU,QAAQ;GAClB,cAAc,QAAQ;GACvB,CAAC;IACD;EAAC,SAAS;EAAQ,SAAS;EAAU,SAAS;EAAa,CAAC;AAG/D,eAAc;AACZ,MAAI,CAAC,gBAAgB,CAAC,KAAM;AAE5B,eAAa,kBAAkB;EAE/B,MAAM,MAAM,kBAAkB,MAAM;GAClC,QAAQ,SAAS;GACjB,UAAU,SAAS;GACnB,cAAc,SAAS;GACxB,CAAC;AACF,MAAI,IACF,cAAa,gBAAgB,MAAM,IAAI;IAExC;EAAC;EAAc;EAAM;EAAW,CAAC;AAGpC,0BAAyB;AACvB,MAAI,CAAC,MAAM;AAEP,WAAQ,KAAK,iDAAiD;AAEhE;;EAGF,MAAM,WAAW,mBAAmB;AAEpC,MAAI,SAAS,kBAAkB,MAAM,EAAE,MAAM,SAAS,MAAM,CAAC,CAC3D;AAGF,WAAS,SAAS,MAAM;GACtB,QAAQ,SAAS;GACjB,UAAU,SAAS;GACnB,cAAc,SAAS;GACvB,MAAM,SAAS;GAChB,CAAC;IACD;EAAC;EAAM;EAAY,SAAS;EAAK,CAAC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
//#region src/hooks/useRawCSS.d.ts
|
|
2
|
-
interface UseRawCSSOptions {
|
|
3
|
-
root?: Document | ShadowRoot;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Hook to inject raw CSS text directly without parsing.
|
|
7
|
-
* This is a low-overhead alternative for injecting global CSS that doesn't need tasty processing.
|
|
8
|
-
*
|
|
9
|
-
* The CSS is inserted into a separate style element (data-tasty-raw) to avoid conflicts
|
|
10
|
-
* with tasty's chunked style sheets.
|
|
11
|
-
*
|
|
12
|
-
* @example Static CSS string
|
|
13
|
-
* ```tsx
|
|
14
|
-
* function GlobalStyles() {
|
|
15
|
-
* useRawCSS(`
|
|
16
|
-
* body {
|
|
17
|
-
* margin: 0;
|
|
18
|
-
* padding: 0;
|
|
19
|
-
* font-family: sans-serif;
|
|
20
|
-
* }
|
|
21
|
-
* `);
|
|
22
|
-
*
|
|
23
|
-
* return null;
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @example Factory function with dependencies (like useMemo)
|
|
28
|
-
* ```tsx
|
|
29
|
-
* function ThemeStyles({ theme }: { theme: 'light' | 'dark' }) {
|
|
30
|
-
* useRawCSS(() => `
|
|
31
|
-
* :root {
|
|
32
|
-
* --bg-color: ${theme === 'dark' ? '#1a1a1a' : '#ffffff'};
|
|
33
|
-
* --text-color: ${theme === 'dark' ? '#ffffff' : '#1a1a1a'};
|
|
34
|
-
* }
|
|
35
|
-
* `, [theme]);
|
|
36
|
-
*
|
|
37
|
-
* return null;
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @example With options
|
|
42
|
-
* ```tsx
|
|
43
|
-
* function ShadowStyles({ shadowRoot }) {
|
|
44
|
-
* useRawCSS(() => `.scoped { color: red; }`, [], { root: shadowRoot });
|
|
45
|
-
* return null;
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
declare function useRawCSS(css: string, options?: UseRawCSSOptions): void;
|
|
50
|
-
declare function useRawCSS(factory: () => string, deps: readonly unknown[], options?: UseRawCSSOptions): void;
|
|
51
|
-
//#endregion
|
|
52
|
-
export { useRawCSS };
|
|
53
|
-
//# sourceMappingURL=useRawCSS.d.ts.map
|
package/dist/hooks/useRawCSS.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { injectRawCSS } from "../injector/index.js";
|
|
2
|
-
import { resolveSSRCollector } from "./resolve-ssr-collector.js";
|
|
3
|
-
import { TastySSRContext } from "../ssr/context.js";
|
|
4
|
-
import { useContext, useInsertionEffect, useMemo, useRef } from "react";
|
|
5
|
-
//#region src/hooks/useRawCSS.ts
|
|
6
|
-
function useRawCSS(cssOrFactory, depsOrOptions, options) {
|
|
7
|
-
const ssrCollector = resolveSSRCollector(useContext(TastySSRContext));
|
|
8
|
-
const isFactory = typeof cssOrFactory === "function";
|
|
9
|
-
const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
|
|
10
|
-
const opts = isFactory ? options : depsOrOptions;
|
|
11
|
-
const css = useMemo(() => isFactory ? cssOrFactory() : cssOrFactory, isFactory ? deps ?? [] : [cssOrFactory]);
|
|
12
|
-
useMemo(() => {
|
|
13
|
-
if (!ssrCollector || !css.trim()) return;
|
|
14
|
-
const key = `raw:${css.length}:${css.slice(0, 64)}`;
|
|
15
|
-
ssrCollector.collectRawCSS(key, css);
|
|
16
|
-
}, [ssrCollector, css]);
|
|
17
|
-
const disposeRef = useRef(null);
|
|
18
|
-
useInsertionEffect(() => {
|
|
19
|
-
disposeRef.current?.();
|
|
20
|
-
if (!css.trim()) {
|
|
21
|
-
disposeRef.current = null;
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const { dispose } = injectRawCSS(css, opts);
|
|
25
|
-
disposeRef.current = dispose;
|
|
26
|
-
return () => {
|
|
27
|
-
disposeRef.current?.();
|
|
28
|
-
disposeRef.current = null;
|
|
29
|
-
};
|
|
30
|
-
}, [css, opts?.root]);
|
|
31
|
-
}
|
|
32
|
-
//#endregion
|
|
33
|
-
export { useRawCSS };
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=useRawCSS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRawCSS.js","names":[],"sources":["../../src/hooks/useRawCSS.ts"],"sourcesContent":["import { useContext, useInsertionEffect, useMemo, useRef } from 'react';\n\nimport { injectRawCSS } from '../injector';\nimport { resolveSSRCollector } from './resolve-ssr-collector';\nimport { TastySSRContext } from '../ssr/context';\n\ninterface UseRawCSSOptions {\n root?: Document | ShadowRoot;\n}\n\n/**\n * Hook to inject raw CSS text directly without parsing.\n * This is a low-overhead alternative for injecting global CSS that doesn't need tasty processing.\n *\n * The CSS is inserted into a separate style element (data-tasty-raw) to avoid conflicts\n * with tasty's chunked style sheets.\n *\n * @example Static CSS string\n * ```tsx\n * function GlobalStyles() {\n * useRawCSS(`\n * body {\n * margin: 0;\n * padding: 0;\n * font-family: sans-serif;\n * }\n * `);\n *\n * return null;\n * }\n * ```\n *\n * @example Factory function with dependencies (like useMemo)\n * ```tsx\n * function ThemeStyles({ theme }: { theme: 'light' | 'dark' }) {\n * useRawCSS(() => `\n * :root {\n * --bg-color: ${theme === 'dark' ? '#1a1a1a' : '#ffffff'};\n * --text-color: ${theme === 'dark' ? '#ffffff' : '#1a1a1a'};\n * }\n * `, [theme]);\n *\n * return null;\n * }\n * ```\n *\n * @example With options\n * ```tsx\n * function ShadowStyles({ shadowRoot }) {\n * useRawCSS(() => `.scoped { color: red; }`, [], { root: shadowRoot });\n * return null;\n * }\n * ```\n */\n\n// Overload 1: Static CSS string\nexport function useRawCSS(css: string, options?: UseRawCSSOptions): void;\n\n// Overload 2: Factory function with dependencies\nexport function useRawCSS(\n factory: () => string,\n deps: readonly unknown[],\n options?: UseRawCSSOptions,\n): void;\n\n// Implementation\nexport function useRawCSS(\n cssOrFactory: string | (() => string),\n depsOrOptions?: readonly unknown[] | UseRawCSSOptions,\n options?: UseRawCSSOptions,\n): void {\n const ssrContextValue = useContext(TastySSRContext);\n const ssrCollector = resolveSSRCollector(ssrContextValue);\n\n // Detect which overload is being used\n const isFactory = typeof cssOrFactory === 'function';\n\n // Parse arguments based on overload\n const deps =\n isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : undefined;\n const opts = isFactory\n ? options\n : (depsOrOptions as UseRawCSSOptions | undefined);\n\n // Memoize CSS - for factory functions, use provided deps; for strings, use the string itself\n const css = useMemo(\n () =>\n isFactory ? (cssOrFactory as () => string)() : (cssOrFactory as string),\n\n isFactory ? (deps ?? []) : [cssOrFactory],\n );\n\n // SSR path: collect raw CSS during render\n useMemo(() => {\n if (!ssrCollector || !css.trim()) return;\n\n const key = `raw:${css.length}:${css.slice(0, 64)}`;\n ssrCollector.collectRawCSS(key, css);\n }, [ssrCollector, css]);\n\n const disposeRef = useRef<(() => void) | null>(null);\n\n // Client path: inject via DOM\n useInsertionEffect(() => {\n disposeRef.current?.();\n\n if (!css.trim()) {\n disposeRef.current = null;\n return;\n }\n\n const { dispose } = injectRawCSS(css, opts);\n disposeRef.current = dispose;\n\n return () => {\n disposeRef.current?.();\n disposeRef.current = null;\n };\n }, [css, opts?.root]);\n}\n"],"mappings":";;;;;AAkEA,SAAgB,UACd,cACA,eACA,SACM;CAEN,MAAM,eAAe,oBADG,WAAW,gBAAgB,CACM;CAGzD,MAAM,YAAY,OAAO,iBAAiB;CAG1C,MAAM,OACJ,aAAa,MAAM,QAAQ,cAAc,GAAG,gBAAgB,KAAA;CAC9D,MAAM,OAAO,YACT,UACC;CAGL,MAAM,MAAM,cAER,YAAa,cAA+B,GAAI,cAElD,YAAa,QAAQ,EAAE,GAAI,CAAC,aAAa,CAC1C;AAGD,eAAc;AACZ,MAAI,CAAC,gBAAgB,CAAC,IAAI,MAAM,CAAE;EAElC,MAAM,MAAM,OAAO,IAAI,OAAO,GAAG,IAAI,MAAM,GAAG,GAAG;AACjD,eAAa,cAAc,KAAK,IAAI;IACnC,CAAC,cAAc,IAAI,CAAC;CAEvB,MAAM,aAAa,OAA4B,KAAK;AAGpD,0BAAyB;AACvB,aAAW,WAAW;AAEtB,MAAI,CAAC,IAAI,MAAM,EAAE;AACf,cAAW,UAAU;AACrB;;EAGF,MAAM,EAAE,YAAY,aAAa,KAAK,KAAK;AAC3C,aAAW,UAAU;AAErB,eAAa;AACX,cAAW,WAAW;AACtB,cAAW,UAAU;;IAEtB,CAAC,KAAK,MAAM,KAAK,CAAC"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Styles } from "../styles/types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/hooks/useStyles.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Tasty styles object to generate CSS classes for.
|
|
6
|
-
* Can be undefined or empty object for no styles.
|
|
7
|
-
*/
|
|
8
|
-
type UseStylesOptions = Styles | undefined;
|
|
9
|
-
interface UseStylesResult {
|
|
10
|
-
/**
|
|
11
|
-
* Generated className(s) to apply to the element.
|
|
12
|
-
* Can be empty string if no styles are provided.
|
|
13
|
-
* With chunking enabled, may contain multiple space-separated class names.
|
|
14
|
-
*/
|
|
15
|
-
className: string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Hook to generate CSS classes from Tasty styles.
|
|
19
|
-
* Handles style rendering, className allocation, and CSS injection.
|
|
20
|
-
*
|
|
21
|
-
* SSR-aware: when a ServerStyleCollector is available (via React context
|
|
22
|
-
* or AsyncLocalStorage), CSS is collected during the render phase instead
|
|
23
|
-
* of being injected into the DOM. useInsertionEffect does not run on the
|
|
24
|
-
* server, so the collector path is the only active path during SSR.
|
|
25
|
-
*
|
|
26
|
-
* Uses chunking to split styles into logical groups for better caching
|
|
27
|
-
* and CSS reuse across components.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```tsx
|
|
31
|
-
* function MyComponent() {
|
|
32
|
-
* const { className } = useStyles({
|
|
33
|
-
* padding: '2x',
|
|
34
|
-
* fill: '#purple',
|
|
35
|
-
* radius: '1r',
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* return <div className={className}>Styled content</div>;
|
|
39
|
-
* }
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
declare function useStyles(styles: UseStylesOptions): UseStylesResult;
|
|
43
|
-
//#endregion
|
|
44
|
-
export { UseStylesOptions, UseStylesResult, useStyles };
|
|
45
|
-
//# sourceMappingURL=useStyles.d.ts.map
|
package/dist/hooks/useStyles.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { extractLocalProperties, hasLocalProperties } from "../properties/index.js";
|
|
2
|
-
import { stringifyStyles } from "../utils/styles.js";
|
|
3
|
-
import { extractLocalFontFace, fontFaceContentHash, formatFontFaceRule, hasLocalFontFace } from "../font-face/index.js";
|
|
4
|
-
import { extractLocalCounterStyle, formatCounterStyleRule, hasLocalCounterStyle } from "../counter-style/index.js";
|
|
5
|
-
import { getConfig, getGlobalKeyframes, hasGlobalKeyframes } from "../config.js";
|
|
6
|
-
import { categorizeStyleKeys } from "../chunks/definitions.js";
|
|
7
|
-
import { generateChunkCacheKey } from "../chunks/cacheKey.js";
|
|
8
|
-
import { renderStylesForChunk } from "../chunks/renderChunk.js";
|
|
9
|
-
import { allocateClassName, counterStyle, fontFace, inject, keyframes, property } from "../injector/index.js";
|
|
10
|
-
import { resolveRecipes } from "../utils/resolve-recipes.js";
|
|
11
|
-
import { extractAnimationNamesFromStyles, extractLocalKeyframes, filterUsedKeyframes, hasLocalKeyframes, mergeKeyframes, replaceAnimationNames } from "../keyframes/index.js";
|
|
12
|
-
import { formatPropertyCSS } from "../ssr/format-property.js";
|
|
13
|
-
import { collectAutoInferredProperties } from "../ssr/collect-auto-properties.js";
|
|
14
|
-
import { resolveSSRCollector } from "./resolve-ssr-collector.js";
|
|
15
|
-
import { TastySSRContext } from "../ssr/context.js";
|
|
16
|
-
import { formatKeyframesCSS } from "../ssr/format-keyframes.js";
|
|
17
|
-
import { hasKeys } from "../utils/has-keys.js";
|
|
18
|
-
import { useContext, useInsertionEffect, useMemo, useRef } from "react";
|
|
19
|
-
//#region src/hooks/useStyles.ts
|
|
20
|
-
/**
|
|
21
|
-
* Render, cache-key, and allocate a className for a single chunk.
|
|
22
|
-
* Returns a ProcessedChunk, or null if the chunk produces no CSS rules.
|
|
23
|
-
*
|
|
24
|
-
* Always runs the pipeline and calls allocateClassName. The inject()
|
|
25
|
-
* call in useInsertionEffect handles all edge cases: placeholders from
|
|
26
|
-
* abandoned concurrent renders, hydration hits (ruleIndex -2), and
|
|
27
|
-
* runtime cache hits (already injected). The pipeline's own LRU cache
|
|
28
|
-
* makes repeated calls for identical styles cheap.
|
|
29
|
-
*/
|
|
30
|
-
function processChunk(styles, chunkName, styleKeys) {
|
|
31
|
-
if (styleKeys.length === 0) return null;
|
|
32
|
-
const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
|
|
33
|
-
const renderResult = renderStylesForChunk(styles, chunkName, styleKeys, cacheKey);
|
|
34
|
-
if (renderResult.rules.length === 0) return null;
|
|
35
|
-
const { className } = allocateClassName(cacheKey);
|
|
36
|
-
return {
|
|
37
|
-
name: chunkName,
|
|
38
|
-
styleKeys,
|
|
39
|
-
cacheKey,
|
|
40
|
-
renderResult,
|
|
41
|
-
className
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Get keyframes that are actually used in styles.
|
|
46
|
-
* Returns null if no keyframes are used (fast path for zero overhead).
|
|
47
|
-
*
|
|
48
|
-
* Optimization order:
|
|
49
|
-
* 1. Check if any keyframes are defined (local or global) - if not, return null
|
|
50
|
-
* 2. Extract animation names from styles - if none, return null
|
|
51
|
-
* 3. Merge and filter keyframes to only used ones
|
|
52
|
-
*/
|
|
53
|
-
function getUsedKeyframes(styles) {
|
|
54
|
-
const hasLocal = hasLocalKeyframes(styles);
|
|
55
|
-
const hasGlobal = hasGlobalKeyframes();
|
|
56
|
-
if (!hasLocal && !hasGlobal) return null;
|
|
57
|
-
const usedNames = extractAnimationNamesFromStyles(styles);
|
|
58
|
-
if (usedNames.size === 0) return null;
|
|
59
|
-
return filterUsedKeyframes(mergeKeyframes(hasLocal ? extractLocalKeyframes(styles) : null, hasGlobal ? getGlobalKeyframes() : null), usedNames);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Process a chunk on the SSR path: allocate via collector, render, collect CSS.
|
|
63
|
-
* Returns null if the chunk produces no CSS rules.
|
|
64
|
-
*/
|
|
65
|
-
function processChunkSSR(collector, styles, chunkName, styleKeys) {
|
|
66
|
-
if (styleKeys.length === 0) return null;
|
|
67
|
-
const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
|
|
68
|
-
const { className, isNewAllocation } = collector.allocateClassName(cacheKey);
|
|
69
|
-
if (isNewAllocation) {
|
|
70
|
-
const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);
|
|
71
|
-
if (renderResult.rules.length > 0) {
|
|
72
|
-
collector.collectChunk(cacheKey, className, renderResult.rules);
|
|
73
|
-
return {
|
|
74
|
-
name: chunkName,
|
|
75
|
-
styleKeys,
|
|
76
|
-
cacheKey,
|
|
77
|
-
renderResult,
|
|
78
|
-
className
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
name: chunkName,
|
|
85
|
-
styleKeys,
|
|
86
|
-
cacheKey,
|
|
87
|
-
renderResult: { rules: [] },
|
|
88
|
-
className
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Hook to generate CSS classes from Tasty styles.
|
|
93
|
-
* Handles style rendering, className allocation, and CSS injection.
|
|
94
|
-
*
|
|
95
|
-
* SSR-aware: when a ServerStyleCollector is available (via React context
|
|
96
|
-
* or AsyncLocalStorage), CSS is collected during the render phase instead
|
|
97
|
-
* of being injected into the DOM. useInsertionEffect does not run on the
|
|
98
|
-
* server, so the collector path is the only active path during SSR.
|
|
99
|
-
*
|
|
100
|
-
* Uses chunking to split styles into logical groups for better caching
|
|
101
|
-
* and CSS reuse across components.
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* ```tsx
|
|
105
|
-
* function MyComponent() {
|
|
106
|
-
* const { className } = useStyles({
|
|
107
|
-
* padding: '2x',
|
|
108
|
-
* fill: '#purple',
|
|
109
|
-
* radius: '1r',
|
|
110
|
-
* });
|
|
111
|
-
*
|
|
112
|
-
* return <div className={className}>Styled content</div>;
|
|
113
|
-
* }
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
function useStyles(styles) {
|
|
117
|
-
const ssrCollector = resolveSSRCollector(useContext(TastySSRContext));
|
|
118
|
-
const disposeRef = useRef([]);
|
|
119
|
-
const stylesRef = useRef({
|
|
120
|
-
key: "",
|
|
121
|
-
styles: void 0
|
|
122
|
-
});
|
|
123
|
-
const resolvedStyles = useMemo(() => {
|
|
124
|
-
if (!styles) return styles;
|
|
125
|
-
return resolveRecipes(styles);
|
|
126
|
-
}, [styles]);
|
|
127
|
-
const styleKey = useMemo(() => {
|
|
128
|
-
if (!resolvedStyles || !hasKeys(resolvedStyles)) return "";
|
|
129
|
-
return stringifyStyles(resolvedStyles);
|
|
130
|
-
}, [resolvedStyles]);
|
|
131
|
-
if (stylesRef.current.key !== styleKey) stylesRef.current = {
|
|
132
|
-
key: styleKey,
|
|
133
|
-
styles: resolvedStyles
|
|
134
|
-
};
|
|
135
|
-
const processedChunks = useMemo(() => {
|
|
136
|
-
const currentStyles = stylesRef.current.styles;
|
|
137
|
-
if (!styleKey || !currentStyles) return [];
|
|
138
|
-
const chunkMap = categorizeStyleKeys(currentStyles);
|
|
139
|
-
const chunks = [];
|
|
140
|
-
if (ssrCollector) {
|
|
141
|
-
ssrCollector.collectInternals();
|
|
142
|
-
for (const [chunkName, chunkStyleKeys] of chunkMap) {
|
|
143
|
-
const chunk = processChunkSSR(ssrCollector, currentStyles, chunkName, chunkStyleKeys);
|
|
144
|
-
if (chunk) chunks.push(chunk);
|
|
145
|
-
}
|
|
146
|
-
const usedKeyframes = getUsedKeyframes(currentStyles);
|
|
147
|
-
if (usedKeyframes) for (const [name, steps] of Object.entries(usedKeyframes)) {
|
|
148
|
-
const css = formatKeyframesCSS(name, steps);
|
|
149
|
-
ssrCollector.collectKeyframes(name, css);
|
|
150
|
-
}
|
|
151
|
-
if (hasLocalProperties(currentStyles)) {
|
|
152
|
-
const localProperties = extractLocalProperties(currentStyles);
|
|
153
|
-
if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
|
|
154
|
-
const css = formatPropertyCSS(token, definition);
|
|
155
|
-
if (css) ssrCollector.collectProperty(token, css);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (hasLocalFontFace(currentStyles)) {
|
|
159
|
-
const localFontFace = extractLocalFontFace(currentStyles);
|
|
160
|
-
if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
|
|
161
|
-
const descriptors = Array.isArray(input) ? input : [input];
|
|
162
|
-
for (const desc of descriptors) {
|
|
163
|
-
const hash = fontFaceContentHash(family, desc);
|
|
164
|
-
const css = formatFontFaceRule(family, desc);
|
|
165
|
-
ssrCollector.collectFontFace(hash, css);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (hasLocalCounterStyle(currentStyles)) {
|
|
170
|
-
const localCounterStyle = extractLocalCounterStyle(currentStyles);
|
|
171
|
-
if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) {
|
|
172
|
-
const css = formatCounterStyleRule(name, descriptors);
|
|
173
|
-
ssrCollector.collectCounterStyle(name, css);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (getConfig().autoPropertyTypes !== false) {
|
|
177
|
-
const allRules = chunks.flatMap((c) => c.renderResult.rules);
|
|
178
|
-
if (allRules.length > 0) collectAutoInferredProperties(allRules, ssrCollector, currentStyles);
|
|
179
|
-
}
|
|
180
|
-
} else for (const [chunkName, chunkStyleKeys] of chunkMap) {
|
|
181
|
-
const chunk = processChunk(currentStyles, chunkName, chunkStyleKeys);
|
|
182
|
-
if (chunk) chunks.push(chunk);
|
|
183
|
-
}
|
|
184
|
-
return chunks;
|
|
185
|
-
}, [styleKey]);
|
|
186
|
-
useInsertionEffect(() => {
|
|
187
|
-
disposeRef.current.forEach((dispose) => dispose?.());
|
|
188
|
-
disposeRef.current = [];
|
|
189
|
-
if (processedChunks.length === 0) return;
|
|
190
|
-
const currentStyles = stylesRef.current.styles;
|
|
191
|
-
if (currentStyles && hasLocalProperties(currentStyles)) {
|
|
192
|
-
const localProperties = extractLocalProperties(currentStyles);
|
|
193
|
-
if (localProperties) for (const [token, definition] of Object.entries(localProperties)) property(token, definition);
|
|
194
|
-
}
|
|
195
|
-
if (currentStyles && hasLocalFontFace(currentStyles)) {
|
|
196
|
-
const localFontFace = extractLocalFontFace(currentStyles);
|
|
197
|
-
if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
|
|
198
|
-
const descriptors = Array.isArray(input) ? input : [input];
|
|
199
|
-
for (const desc of descriptors) fontFace(family, desc);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
if (currentStyles && hasLocalCounterStyle(currentStyles)) {
|
|
203
|
-
const localCounterStyle = extractLocalCounterStyle(currentStyles);
|
|
204
|
-
if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) counterStyle(name, descriptors);
|
|
205
|
-
}
|
|
206
|
-
const usedKeyframes = currentStyles ? getUsedKeyframes(currentStyles) : null;
|
|
207
|
-
let nameMap = null;
|
|
208
|
-
if (usedKeyframes) {
|
|
209
|
-
nameMap = /* @__PURE__ */ new Map();
|
|
210
|
-
for (const [name, steps] of Object.entries(usedKeyframes)) {
|
|
211
|
-
const result = keyframes(steps, { name });
|
|
212
|
-
const injectedName = result.toString();
|
|
213
|
-
if (injectedName !== name) nameMap.set(name, injectedName);
|
|
214
|
-
disposeRef.current.push(result.dispose);
|
|
215
|
-
}
|
|
216
|
-
if (nameMap.size === 0) nameMap = null;
|
|
217
|
-
}
|
|
218
|
-
for (const chunk of processedChunks) if (chunk.renderResult.rules.length > 0) {
|
|
219
|
-
const { dispose } = inject(nameMap ? chunk.renderResult.rules.map((rule) => ({
|
|
220
|
-
...rule,
|
|
221
|
-
declarations: replaceAnimationNames(rule.declarations, nameMap)
|
|
222
|
-
})) : chunk.renderResult.rules, { cacheKey: chunk.cacheKey });
|
|
223
|
-
disposeRef.current.push(dispose);
|
|
224
|
-
}
|
|
225
|
-
return () => {
|
|
226
|
-
disposeRef.current.forEach((dispose) => dispose?.());
|
|
227
|
-
disposeRef.current = [];
|
|
228
|
-
};
|
|
229
|
-
}, [processedChunks]);
|
|
230
|
-
return { className: useMemo(() => {
|
|
231
|
-
return processedChunks.map((chunk) => chunk.className).join(" ");
|
|
232
|
-
}, [processedChunks]) };
|
|
233
|
-
}
|
|
234
|
-
//#endregion
|
|
235
|
-
export { useStyles };
|
|
236
|
-
|
|
237
|
-
//# sourceMappingURL=useStyles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useStyles.js","names":[],"sources":["../../src/hooks/useStyles.ts"],"sourcesContent":["import { useContext, useInsertionEffect, useMemo, useRef } from 'react';\n\nimport {\n categorizeStyleKeys,\n generateChunkCacheKey,\n renderStylesForChunk,\n} from '../chunks';\nimport { getConfig, getGlobalKeyframes, hasGlobalKeyframes } from '../config';\nimport {\n allocateClassName,\n counterStyle,\n fontFace,\n inject,\n keyframes,\n property,\n} from '../injector';\nimport type { FontFaceDescriptors, KeyframesSteps } from '../injector/types';\nimport {\n extractLocalCounterStyle,\n formatCounterStyleRule,\n hasLocalCounterStyle,\n} from '../counter-style';\nimport {\n extractLocalFontFace,\n fontFaceContentHash,\n formatFontFaceRule,\n hasLocalFontFace,\n} from '../font-face';\nimport {\n extractAnimationNamesFromStyles,\n extractLocalKeyframes,\n filterUsedKeyframes,\n hasLocalKeyframes,\n mergeKeyframes,\n replaceAnimationNames,\n} from '../keyframes';\nimport type { RenderResult } from '../pipeline';\nimport { extractLocalProperties, hasLocalProperties } from '../properties';\nimport { collectAutoInferredProperties } from '../ssr/collect-auto-properties';\nimport type { ServerStyleCollector } from '../ssr/collector';\nimport { resolveSSRCollector } from './resolve-ssr-collector';\nimport { TastySSRContext } from '../ssr/context';\nimport { formatKeyframesCSS } from '../ssr/format-keyframes';\nimport { formatPropertyCSS } from '../ssr/format-property';\nimport type { Styles } from '../styles/types';\nimport { hasKeys } from '../utils/has-keys';\nimport { resolveRecipes } from '../utils/resolve-recipes';\nimport { stringifyStyles } from '../utils/styles';\n\n/**\n * Tasty styles object to generate CSS classes for.\n * Can be undefined or empty object for no styles.\n */\nexport type UseStylesOptions = Styles | undefined;\n\nexport interface UseStylesResult {\n /**\n * Generated className(s) to apply to the element.\n * Can be empty string if no styles are provided.\n * With chunking enabled, may contain multiple space-separated class names.\n */\n className: string;\n}\n\n/**\n * Information about a processed chunk\n */\ninterface ProcessedChunk {\n name: string;\n styleKeys: string[];\n cacheKey: string;\n renderResult: RenderResult;\n className: string;\n}\n\n/**\n * Render, cache-key, and allocate a className for a single chunk.\n * Returns a ProcessedChunk, or null if the chunk produces no CSS rules.\n *\n * Always runs the pipeline and calls allocateClassName. The inject()\n * call in useInsertionEffect handles all edge cases: placeholders from\n * abandoned concurrent renders, hydration hits (ruleIndex -2), and\n * runtime cache hits (already injected). The pipeline's own LRU cache\n * makes repeated calls for identical styles cheap.\n */\nfunction processChunk(\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): ProcessedChunk | null {\n if (styleKeys.length === 0) return null;\n\n const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);\n const renderResult = renderStylesForChunk(\n styles,\n chunkName,\n styleKeys,\n cacheKey,\n );\n if (renderResult.rules.length === 0) return null;\n\n const { className } = allocateClassName(cacheKey);\n\n return { name: chunkName, styleKeys, cacheKey, renderResult, className };\n}\n\n/**\n * Get keyframes that are actually used in styles.\n * Returns null if no keyframes are used (fast path for zero overhead).\n *\n * Optimization order:\n * 1. Check if any keyframes are defined (local or global) - if not, return null\n * 2. Extract animation names from styles - if none, return null\n * 3. Merge and filter keyframes to only used ones\n */\nfunction getUsedKeyframes(\n styles: Styles,\n): Record<string, KeyframesSteps> | null {\n // Fast path: no keyframes defined anywhere\n const hasLocal = hasLocalKeyframes(styles);\n const hasGlobal = hasGlobalKeyframes();\n if (!hasLocal && !hasGlobal) return null;\n\n // Extract animation names from styles (not from rendered CSS - faster)\n const usedNames = extractAnimationNamesFromStyles(styles);\n if (usedNames.size === 0) return null;\n\n // Merge local and global keyframes\n const local = hasLocal ? extractLocalKeyframes(styles) : null;\n const global = hasGlobal ? getGlobalKeyframes() : null;\n const allKeyframes = mergeKeyframes(local, global);\n\n // Filter to only used keyframes\n return filterUsedKeyframes(allKeyframes, usedNames);\n}\n\n/**\n * Process a chunk on the SSR path: allocate via collector, render, collect CSS.\n * Returns null if the chunk produces no CSS rules.\n */\nfunction processChunkSSR(\n collector: ServerStyleCollector,\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): ProcessedChunk | null {\n if (styleKeys.length === 0) return null;\n\n const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);\n const { className, isNewAllocation } = collector.allocateClassName(cacheKey);\n\n if (isNewAllocation) {\n const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);\n if (renderResult.rules.length > 0) {\n collector.collectChunk(cacheKey, className, renderResult.rules);\n return {\n name: chunkName,\n styleKeys,\n cacheKey,\n renderResult,\n className,\n };\n }\n return null;\n }\n\n return {\n name: chunkName,\n styleKeys,\n cacheKey,\n renderResult: { rules: [] },\n className,\n };\n}\n\n/**\n * Hook to generate CSS classes from Tasty styles.\n * Handles style rendering, className allocation, and CSS injection.\n *\n * SSR-aware: when a ServerStyleCollector is available (via React context\n * or AsyncLocalStorage), CSS is collected during the render phase instead\n * of being injected into the DOM. useInsertionEffect does not run on the\n * server, so the collector path is the only active path during SSR.\n *\n * Uses chunking to split styles into logical groups for better caching\n * and CSS reuse across components.\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { className } = useStyles({\n * padding: '2x',\n * fill: '#purple',\n * radius: '1r',\n * });\n *\n * return <div className={className}>Styled content</div>;\n * }\n * ```\n */\nexport function useStyles(styles: UseStylesOptions): UseStylesResult {\n const ssrContextValue = useContext(TastySSRContext);\n const ssrCollector = resolveSSRCollector(ssrContextValue);\n\n // Array of dispose functions for each chunk\n const disposeRef = useRef<(() => void)[]>([]);\n\n // Store styles by their stringified key to avoid recomputing when only reference changes\n const stylesRef = useRef<{ key: string; styles: Styles | undefined }>({\n key: '',\n styles: undefined,\n });\n\n // Resolve recipes before any processing (zero overhead if no recipes configured)\n const resolvedStyles = useMemo(() => {\n if (!styles) return styles;\n return resolveRecipes(styles);\n }, [styles]);\n\n // Compute style key - this is a primitive string that captures style content\n const styleKey = useMemo(() => {\n if (!resolvedStyles || !hasKeys(resolvedStyles)) {\n return '';\n }\n return stringifyStyles(resolvedStyles);\n }, [resolvedStyles]);\n\n // Update ref when styleKey changes (content actually changed)\n if (stylesRef.current.key !== styleKey) {\n stylesRef.current = { key: styleKey, styles: resolvedStyles };\n }\n\n // Process chunks: categorize, generate cache keys, render, and allocate classNames\n // Only depends on styleKey (primitive), not styles object reference\n const processedChunks: ProcessedChunk[] = useMemo(() => {\n const currentStyles = stylesRef.current.styles;\n if (!styleKey || !currentStyles) {\n return [];\n }\n\n // Categorize style keys into chunks\n const chunkMap = categorizeStyleKeys(\n currentStyles as Record<string, unknown>,\n );\n\n const chunks: ProcessedChunk[] = [];\n\n if (ssrCollector) {\n // Ensure internal @property and :root token CSS is included\n ssrCollector.collectInternals();\n\n // SERVER PATH: allocate via collector, collect CSS\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n const chunk = processChunkSSR(\n ssrCollector,\n currentStyles,\n chunkName,\n chunkStyleKeys,\n );\n if (chunk) chunks.push(chunk);\n }\n\n // Collect keyframes on the server\n const usedKeyframes = getUsedKeyframes(currentStyles);\n if (usedKeyframes) {\n for (const [name, steps] of Object.entries(usedKeyframes)) {\n const css = formatKeyframesCSS(name, steps);\n ssrCollector.collectKeyframes(name, css);\n }\n }\n\n // Collect explicit @property rules on the server\n if (hasLocalProperties(currentStyles)) {\n const localProperties = extractLocalProperties(currentStyles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n const css = formatPropertyCSS(token, definition);\n if (css) {\n ssrCollector.collectProperty(token, css);\n }\n }\n }\n }\n\n // Collect @font-face rules on the server\n if (hasLocalFontFace(currentStyles)) {\n const localFontFace = extractLocalFontFace(currentStyles);\n if (localFontFace) {\n for (const [family, input] of Object.entries(localFontFace)) {\n const descriptors: FontFaceDescriptors[] = Array.isArray(input)\n ? input\n : [input];\n for (const desc of descriptors) {\n const hash = fontFaceContentHash(family, desc);\n const css = formatFontFaceRule(family, desc);\n ssrCollector.collectFontFace(hash, css);\n }\n }\n }\n }\n\n // Collect @counter-style rules on the server\n if (hasLocalCounterStyle(currentStyles)) {\n const localCounterStyle = extractLocalCounterStyle(currentStyles);\n if (localCounterStyle) {\n for (const [name, descriptors] of Object.entries(localCounterStyle)) {\n const css = formatCounterStyleRule(name, descriptors);\n ssrCollector.collectCounterStyle(name, css);\n }\n }\n }\n\n // Auto-infer @property types from rendered declarations (SSR).\n // On the client this happens inside StyleInjector.inject(), which\n // runs in useInsertionEffect and therefore never executes on the server.\n if (getConfig().autoPropertyTypes !== false) {\n const allRules = chunks.flatMap((c) => c.renderResult.rules);\n if (allRules.length > 0) {\n collectAutoInferredProperties(allRules, ssrCollector, currentStyles);\n }\n }\n } else {\n // CLIENT PATH: unchanged behavior\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n const chunk = processChunk(currentStyles, chunkName, chunkStyleKeys);\n if (chunk) chunks.push(chunk);\n }\n }\n\n return chunks;\n }, [styleKey]);\n\n // Inject styles in insertion effect (avoids render phase side effects).\n // Does NOT run on the server — the SSR path above handles collection.\n useInsertionEffect(() => {\n // Cleanup all previous disposals\n disposeRef.current.forEach((dispose) => dispose?.());\n disposeRef.current = [];\n\n // Fast path: no chunks to inject\n if (processedChunks.length === 0) {\n return;\n }\n\n const currentStyles = stylesRef.current.styles;\n\n // Register explicit @properties first so they take precedence over auto-inference\n // that happens during keyframe and style chunk injection.\n // Token formats: $name → --name, #name → --name-color (with auto syntax: '<color>')\n // Note: Global properties are injected once when styles are first generated (see markStylesGenerated)\n if (currentStyles && hasLocalProperties(currentStyles)) {\n const localProperties = extractLocalProperties(currentStyles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n property(token, definition);\n }\n }\n }\n\n // Inject @font-face rules (permanent, no cleanup needed)\n if (currentStyles && hasLocalFontFace(currentStyles)) {\n const localFontFace = extractLocalFontFace(currentStyles);\n if (localFontFace) {\n for (const [family, input] of Object.entries(localFontFace)) {\n const descriptors: FontFaceDescriptors[] = Array.isArray(input)\n ? input\n : [input];\n for (const desc of descriptors) {\n fontFace(family, desc);\n }\n }\n }\n }\n\n // Inject @counter-style rules (permanent, no cleanup needed)\n if (currentStyles && hasLocalCounterStyle(currentStyles)) {\n const localCounterStyle = extractLocalCounterStyle(currentStyles);\n if (localCounterStyle) {\n for (const [name, descriptors] of Object.entries(localCounterStyle)) {\n counterStyle(name, descriptors);\n }\n }\n }\n\n // Get keyframes that are actually used (returns null if none - zero overhead)\n const usedKeyframes = currentStyles\n ? getUsedKeyframes(currentStyles)\n : null;\n\n // Inject keyframes and build name map (only if we have keyframes)\n let nameMap: Map<string, string> | null = null;\n\n if (usedKeyframes) {\n nameMap = new Map();\n for (const [name, steps] of Object.entries(usedKeyframes)) {\n const result = keyframes(steps, { name });\n const injectedName = result.toString();\n // Only add to map if name differs (optimization for replacement check)\n if (injectedName !== name) {\n nameMap.set(name, injectedName);\n }\n disposeRef.current.push(result.dispose);\n }\n // Clear map if no replacements needed\n if (nameMap.size === 0) {\n nameMap = null;\n }\n }\n\n // Inject each chunk\n for (const chunk of processedChunks) {\n if (chunk.renderResult.rules.length > 0) {\n // Replace animation names only if needed\n const rulesToInject = nameMap\n ? chunk.renderResult.rules.map((rule) => ({\n ...rule,\n declarations: replaceAnimationNames(rule.declarations, nameMap!),\n }))\n : chunk.renderResult.rules;\n\n const { dispose } = inject(rulesToInject, {\n cacheKey: chunk.cacheKey,\n });\n disposeRef.current.push(dispose);\n }\n }\n\n return () => {\n disposeRef.current.forEach((dispose) => dispose?.());\n disposeRef.current = [];\n };\n }, [processedChunks]);\n\n // Combine all chunk classNames\n const className = useMemo(() => {\n return processedChunks.map((chunk) => chunk.className).join(' ');\n }, [processedChunks]);\n\n return {\n className,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;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