@tenphi/tasty 2.0.3 → 2.1.0
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/dist/{ssr/async-storage.js → async-storage-B7_o6FKt.js} +2 -2
- package/dist/async-storage-B7_o6FKt.js.map +1 -0
- package/dist/{ssr/collector.js → collector-DrgDE7QB.js} +5 -10
- package/dist/collector-DrgDE7QB.js.map +1 -0
- package/dist/{ssr/collector.d.ts → collector-LuU1vZ68.d.ts} +3 -3
- package/dist/config-_aQ_PZ-P.js +10131 -0
- package/dist/config-_aQ_PZ-P.js.map +1 -0
- package/dist/config-vuCRkBWX.d.ts +884 -0
- package/dist/{ssr/context.js → context-CkSg-kDT.js} +11 -3
- package/dist/context-CkSg-kDT.js.map +1 -0
- package/dist/core/index.d.ts +5 -34
- package/dist/core/index.js +6 -27
- package/dist/core-BqO8pplb.js +1592 -0
- package/dist/core-BqO8pplb.js.map +1 -0
- package/dist/{zero/extractor.js → css-writer-D--REwtp.js} +74 -11
- package/dist/css-writer-D--REwtp.js.map +1 -0
- package/dist/{ssr/format-global-rules.js → format-global-rules-Dbc_1tc3.js} +2 -2
- package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
- package/dist/format-rules-xwteB7a1.js +143 -0
- package/dist/format-rules-xwteB7a1.js.map +1 -0
- package/dist/{ssr/hydrate.js → hydrate-BvPT4ndL.js} +3 -3
- package/dist/hydrate-BvPT4ndL.js.map +1 -0
- package/dist/index-ZRxZWzlj.d.ts +1602 -0
- package/dist/{styles/types.d.ts → index-dUtwpOux.d.ts} +707 -5
- package/dist/index.d.ts +5 -51
- package/dist/index.js +732 -36
- package/dist/index.js.map +1 -0
- package/dist/keyframes-ClPFWy33.js +587 -0
- package/dist/keyframes-ClPFWy33.js.map +1 -0
- package/dist/{utils/merge-styles.js → merge-styles-BUQsEpbv.js} +3 -4
- package/dist/merge-styles-BUQsEpbv.js.map +1 -0
- package/dist/{utils/merge-styles.d.ts → merge-styles-CtDJMhpJ.d.ts} +3 -3
- package/dist/{utils/resolve-recipes.js → resolve-recipes-C0-AMzCz.js} +4 -6
- package/dist/resolve-recipes-C0-AMzCz.js.map +1 -0
- package/dist/ssr/astro-client.js +1 -1
- package/dist/ssr/astro.js +4 -4
- package/dist/ssr/index.d.ts +44 -4
- package/dist/ssr/index.js +4 -4
- package/dist/ssr/next.d.ts +1 -1
- package/dist/ssr/next.js +6 -6
- package/dist/ssr/next.js.map +1 -1
- 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/zero/babel.d.ts +1 -1
- package/dist/zero/babel.js +10 -6
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +67 -3
- package/dist/zero/index.js +1 -2
- package/docs/injector.md +2 -2
- package/package.json +10 -9
- 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 +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/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 -389
- package/dist/pipeline/exclusive.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -55
- package/dist/pipeline/index.js +0 -749
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize-contradictions.js +0 -125
- package/dist/pipeline/materialize-contradictions.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -1038
- 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 -725
- 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.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.js.map +0 -1
- 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 +0 -73
- package/dist/ssr/format-rules.js.map +0 -1
- package/dist/ssr/hydrate.d.ts +0 -29
- 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/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.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.map +0 -1
package/dist/compute-styles.js
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { extractLocalProperties, hasLocalProperties } from "./properties/index.js";
|
|
2
|
-
import { extractLocalFontFace, fontFaceContentHash, formatFontFaceRule, hasLocalFontFace } from "./font-face/index.js";
|
|
3
|
-
import { extractLocalCounterStyle, formatCounterStyleRule, hasLocalCounterStyle } from "./counter-style/index.js";
|
|
4
|
-
import { getConfig, getGlobalKeyframes, hasGlobalKeyframes } from "./config.js";
|
|
5
|
-
import { categorizeStyleKeys } from "./chunks/definitions.js";
|
|
6
|
-
import { generateChunkCacheKey } from "./chunks/cacheKey.js";
|
|
7
|
-
import { renderStylesForChunk } from "./chunks/renderChunk.js";
|
|
8
|
-
import { counterStyle, fontFace, inject, keyframes, property, touch } from "./injector/index.js";
|
|
9
|
-
import { extractAnimationNamesFromStyles, extractLocalKeyframes, filterUsedKeyframes, hasLocalKeyframes, mergeKeyframes, replaceAnimationNames } from "./keyframes/index.js";
|
|
10
|
-
import { getRegisteredSSRCollector } from "./ssr/ssr-collector-ref.js";
|
|
11
|
-
import { flushPendingCSS, getRSCCache, rscAllocateClassName } from "./rsc-cache.js";
|
|
12
|
-
import { formatPropertyCSS } from "./ssr/format-property.js";
|
|
13
|
-
import { collectAutoInferredProperties } from "./ssr/collect-auto-properties.js";
|
|
14
|
-
import { formatKeyframesCSS } from "./ssr/format-keyframes.js";
|
|
15
|
-
import { formatRules } from "./ssr/format-rules.js";
|
|
16
|
-
import { hasKeys } from "./utils/has-keys.js";
|
|
17
|
-
import { resolveRecipes } from "./utils/resolve-recipes.js";
|
|
18
|
-
//#region src/compute-styles.ts
|
|
19
|
-
/**
|
|
20
|
-
* Hook-free, synchronous style computation.
|
|
21
|
-
*
|
|
22
|
-
* Extracts the core logic from useStyles() into a plain function that can
|
|
23
|
-
* be called during React render without any hooks. Three code paths:
|
|
24
|
-
*
|
|
25
|
-
* 1. SSR collector — styles collected via ServerStyleCollector
|
|
26
|
-
* 2. Client inject — styles injected synchronously into the DOM
|
|
27
|
-
* 3. RSC inline — styles returned as CSS strings for inline <style> emission
|
|
28
|
-
*
|
|
29
|
-
* This enables tasty() components to work as React Server Components.
|
|
30
|
-
*/
|
|
31
|
-
const EMPTY_RESULT = { className: "" };
|
|
32
|
-
/**
|
|
33
|
-
* Mark internals as emitted for this RSC request.
|
|
34
|
-
*
|
|
35
|
-
* Internals (tokens, @property, @font-face, @counter-style) are emitted
|
|
36
|
-
* exclusively by the SSR collector via ServerStyleCollector.collectInternals().
|
|
37
|
-
* The SSR path is reliable because TastyRegistry is always present as a
|
|
38
|
-
* client component in the root layout, guaranteeing SSR runs for every page.
|
|
39
|
-
*
|
|
40
|
-
* Previously this function also emitted internals and coordinated with SSR
|
|
41
|
-
* via a globalThis flag, but that flag leaked across requests in the same
|
|
42
|
-
* Node.js process, causing pages without RSC-rendered tasty components
|
|
43
|
-
* (e.g. the playground route) to lose all token CSS.
|
|
44
|
-
*/
|
|
45
|
-
function collectInternalsRSC(rscCache) {
|
|
46
|
-
if (rscCache.internalsEmitted) return "";
|
|
47
|
-
rscCache.internalsEmitted = true;
|
|
48
|
-
return "";
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Collect per-component ancillary CSS (keyframes, @property, font-face,
|
|
52
|
-
* counter-style) for RSC mode.
|
|
53
|
-
*/
|
|
54
|
-
function collectAncillaryRSC(rscCache, styles) {
|
|
55
|
-
const parts = [];
|
|
56
|
-
const usedKf = getUsedKeyframes(styles);
|
|
57
|
-
if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
|
|
58
|
-
const key = `__kf:${name}:${JSON.stringify(steps)}`;
|
|
59
|
-
if (!rscCache.emittedKeys.has(key)) {
|
|
60
|
-
rscCache.emittedKeys.add(key);
|
|
61
|
-
parts.push(formatKeyframesCSS(name, steps));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (hasLocalProperties(styles)) {
|
|
65
|
-
const localProperties = extractLocalProperties(styles);
|
|
66
|
-
if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
|
|
67
|
-
const key = `__prop:${token}`;
|
|
68
|
-
if (!rscCache.emittedKeys.has(key)) {
|
|
69
|
-
rscCache.emittedKeys.add(key);
|
|
70
|
-
const css = formatPropertyCSS(token, definition);
|
|
71
|
-
if (css) parts.push(css);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (hasLocalFontFace(styles)) {
|
|
76
|
-
const localFontFace = extractLocalFontFace(styles);
|
|
77
|
-
if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
|
|
78
|
-
const descriptors = Array.isArray(input) ? input : [input];
|
|
79
|
-
for (const desc of descriptors) {
|
|
80
|
-
const key = `__ff:${fontFaceContentHash(family, desc)}`;
|
|
81
|
-
if (!rscCache.emittedKeys.has(key)) {
|
|
82
|
-
rscCache.emittedKeys.add(key);
|
|
83
|
-
parts.push(formatFontFaceRule(family, desc));
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (hasLocalCounterStyle(styles)) {
|
|
89
|
-
const localCounterStyle = extractLocalCounterStyle(styles);
|
|
90
|
-
if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) {
|
|
91
|
-
const key = `__cs:${name}:${JSON.stringify(descriptors)}`;
|
|
92
|
-
if (!rscCache.emittedKeys.has(key)) {
|
|
93
|
-
rscCache.emittedKeys.add(key);
|
|
94
|
-
parts.push(formatCounterStyleRule(name, descriptors));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return parts.join("\n");
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Process all chunks in RSC mode: render CSS to strings, allocate classNames,
|
|
102
|
-
* and return combined { className, css }.
|
|
103
|
-
*/
|
|
104
|
-
function computeStylesRSC(styles, chunkMap) {
|
|
105
|
-
const rscCache = getRSCCache();
|
|
106
|
-
const cssParts = [];
|
|
107
|
-
const classNames = [];
|
|
108
|
-
const pendingCSS = flushPendingCSS(rscCache);
|
|
109
|
-
if (pendingCSS) cssParts.push(pendingCSS);
|
|
110
|
-
const internalsCSS = collectInternalsRSC(rscCache);
|
|
111
|
-
if (internalsCSS) cssParts.push(internalsCSS);
|
|
112
|
-
for (const [chunkName, chunkStyleKeys] of chunkMap) {
|
|
113
|
-
if (chunkStyleKeys.length === 0) continue;
|
|
114
|
-
const { className, isNew } = rscAllocateClassName(rscCache, generateChunkCacheKey(styles, chunkName, chunkStyleKeys));
|
|
115
|
-
classNames.push(className);
|
|
116
|
-
if (isNew) {
|
|
117
|
-
const renderResult = renderStylesForChunk(styles, chunkName, chunkStyleKeys);
|
|
118
|
-
if (renderResult.rules.length > 0) {
|
|
119
|
-
const css = formatRules(renderResult.rules, className);
|
|
120
|
-
if (css) cssParts.push(css);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const ancillaryCSS = collectAncillaryRSC(rscCache, styles);
|
|
125
|
-
if (ancillaryCSS) cssParts.push(ancillaryCSS);
|
|
126
|
-
if (classNames.length === 0) return EMPTY_RESULT;
|
|
127
|
-
const css = cssParts.join("\n");
|
|
128
|
-
return {
|
|
129
|
-
className: classNames.join(" "),
|
|
130
|
-
css: css || void 0
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Get keyframes that are actually used in styles.
|
|
135
|
-
* Returns null if no keyframes are used (fast path for zero overhead).
|
|
136
|
-
*/
|
|
137
|
-
function getUsedKeyframes(styles) {
|
|
138
|
-
const hasLocal = hasLocalKeyframes(styles);
|
|
139
|
-
const hasGlobal = hasGlobalKeyframes();
|
|
140
|
-
if (!hasLocal && !hasGlobal) return null;
|
|
141
|
-
const usedNames = extractAnimationNamesFromStyles(styles);
|
|
142
|
-
if (usedNames.size === 0) return null;
|
|
143
|
-
return filterUsedKeyframes(mergeKeyframes(hasLocal ? extractLocalKeyframes(styles) : null, hasGlobal ? getGlobalKeyframes() : null), usedNames);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Process a chunk on the SSR path: allocate via collector, render, collect CSS.
|
|
147
|
-
*/
|
|
148
|
-
function processChunkSSR(collector, styles, chunkName, styleKeys) {
|
|
149
|
-
if (styleKeys.length === 0) return null;
|
|
150
|
-
const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
|
|
151
|
-
const { className, isNewAllocation } = collector.allocateClassName(cacheKey);
|
|
152
|
-
if (isNewAllocation) {
|
|
153
|
-
const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);
|
|
154
|
-
if (renderResult.rules.length > 0) {
|
|
155
|
-
collector.collectChunk(cacheKey, className, renderResult.rules);
|
|
156
|
-
return {
|
|
157
|
-
name: chunkName,
|
|
158
|
-
styleKeys,
|
|
159
|
-
cacheKey,
|
|
160
|
-
renderResult,
|
|
161
|
-
className
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
name: chunkName,
|
|
168
|
-
styleKeys,
|
|
169
|
-
cacheKey,
|
|
170
|
-
renderResult: { rules: [] },
|
|
171
|
-
className
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Process a chunk on the client: render, allocate className, and inject
|
|
176
|
-
* CSS synchronously. The injector's cache makes this idempotent.
|
|
177
|
-
*/
|
|
178
|
-
function processChunkSync(styles, chunkName, styleKeys) {
|
|
179
|
-
if (styleKeys.length === 0) return null;
|
|
180
|
-
const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
|
|
181
|
-
const renderResult = renderStylesForChunk(styles, chunkName, styleKeys, cacheKey);
|
|
182
|
-
if (renderResult.rules.length === 0) return null;
|
|
183
|
-
const { className } = inject(renderResult.rules, { cacheKey });
|
|
184
|
-
return {
|
|
185
|
-
name: chunkName,
|
|
186
|
-
styleKeys,
|
|
187
|
-
cacheKey,
|
|
188
|
-
renderResult,
|
|
189
|
-
className
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Inject keyframes synchronously and return a name replacement map.
|
|
194
|
-
* On the client, keyframes are injected into the DOM.
|
|
195
|
-
*/
|
|
196
|
-
function injectKeyframesSync(usedKeyframes) {
|
|
197
|
-
let nameMap = null;
|
|
198
|
-
for (const [name, steps] of Object.entries(usedKeyframes)) {
|
|
199
|
-
const injectedName = keyframes(steps, { name }).toString();
|
|
200
|
-
if (injectedName !== name) {
|
|
201
|
-
if (!nameMap) nameMap = /* @__PURE__ */ new Map();
|
|
202
|
-
nameMap.set(name, injectedName);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return nameMap;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Inject chunk rules synchronously, replacing animation names if needed.
|
|
209
|
-
*/
|
|
210
|
-
function injectChunkRulesSync(chunks, nameMap) {
|
|
211
|
-
for (const chunk of chunks) if (chunk.renderResult.rules.length > 0) inject(nameMap ? chunk.renderResult.rules.map((rule) => ({
|
|
212
|
-
...rule,
|
|
213
|
-
declarations: replaceAnimationNames(rule.declarations, nameMap)
|
|
214
|
-
})) : chunk.renderResult.rules, { cacheKey: chunk.cacheKey });
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Inject all ancillary rules (properties, font-faces, counter-styles) synchronously.
|
|
218
|
-
*/
|
|
219
|
-
function injectAncillarySync(styles) {
|
|
220
|
-
if (hasLocalProperties(styles)) {
|
|
221
|
-
const localProperties = extractLocalProperties(styles);
|
|
222
|
-
if (localProperties) for (const [token, definition] of Object.entries(localProperties)) property(token, definition);
|
|
223
|
-
}
|
|
224
|
-
if (hasLocalFontFace(styles)) {
|
|
225
|
-
const localFontFace = extractLocalFontFace(styles);
|
|
226
|
-
if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
|
|
227
|
-
const descriptors = Array.isArray(input) ? input : [input];
|
|
228
|
-
for (const desc of descriptors) fontFace(family, desc);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (hasLocalCounterStyle(styles)) {
|
|
232
|
-
const localCounterStyle = extractLocalCounterStyle(styles);
|
|
233
|
-
if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) counterStyle(name, descriptors);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Collect all ancillary rules into the SSR collector.
|
|
238
|
-
*/
|
|
239
|
-
function collectAncillarySSR(collector, styles, chunks) {
|
|
240
|
-
const usedKf = getUsedKeyframes(styles);
|
|
241
|
-
if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
|
|
242
|
-
const css = formatKeyframesCSS(name, steps);
|
|
243
|
-
collector.collectKeyframes(name, css);
|
|
244
|
-
}
|
|
245
|
-
if (hasLocalProperties(styles)) {
|
|
246
|
-
const localProperties = extractLocalProperties(styles);
|
|
247
|
-
if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
|
|
248
|
-
const css = formatPropertyCSS(token, definition);
|
|
249
|
-
if (css) collector.collectProperty(token, css);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
if (hasLocalFontFace(styles)) {
|
|
253
|
-
const localFontFace = extractLocalFontFace(styles);
|
|
254
|
-
if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
|
|
255
|
-
const descriptors = Array.isArray(input) ? input : [input];
|
|
256
|
-
for (const desc of descriptors) {
|
|
257
|
-
const hash = fontFaceContentHash(family, desc);
|
|
258
|
-
const css = formatFontFaceRule(family, desc);
|
|
259
|
-
collector.collectFontFace(hash, css);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
if (hasLocalCounterStyle(styles)) {
|
|
264
|
-
const localCounterStyle = extractLocalCounterStyle(styles);
|
|
265
|
-
if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) {
|
|
266
|
-
const css = formatCounterStyleRule(name, descriptors);
|
|
267
|
-
collector.collectCounterStyle(name, css);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
if (getConfig().autoPropertyTypes !== false) {
|
|
271
|
-
const allRules = chunks.flatMap((c) => c.renderResult.rules);
|
|
272
|
-
if (allRules.length > 0) collectAutoInferredProperties(allRules, collector, styles);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Synchronous, hook-free style computation.
|
|
277
|
-
*
|
|
278
|
-
* Resolves recipes, categorizes style keys into chunks, renders CSS rules,
|
|
279
|
-
* allocates class names, and injects / collects / returns the CSS.
|
|
280
|
-
*
|
|
281
|
-
* Three code paths:
|
|
282
|
-
* 1. SSR collector — discovered via ALS or passed explicitly; CSS collected
|
|
283
|
-
* 2. RSC inline — no collector and no `document`; CSS returned as `result.css`
|
|
284
|
-
* for the caller to emit as an inline `<style>` tag
|
|
285
|
-
* 3. Client inject — CSS injected synchronously into the DOM (idempotent)
|
|
286
|
-
*
|
|
287
|
-
* @param styles - Tasty styles object (or undefined for no styles)
|
|
288
|
-
* @param options - Optional SSR collector override
|
|
289
|
-
*/
|
|
290
|
-
function computeStyles(styles, options) {
|
|
291
|
-
if (!styles || !hasKeys(styles)) return EMPTY_RESULT;
|
|
292
|
-
const resolved = resolveRecipes(styles);
|
|
293
|
-
const chunkMap = categorizeStyleKeys(resolved);
|
|
294
|
-
const collector = options?.ssrCollector !== void 0 ? options.ssrCollector : getRegisteredSSRCollector();
|
|
295
|
-
const chunks = [];
|
|
296
|
-
if (collector) {
|
|
297
|
-
collector.collectInternals();
|
|
298
|
-
for (const [chunkName, chunkStyleKeys] of chunkMap) {
|
|
299
|
-
const chunk = processChunkSSR(collector, resolved, chunkName, chunkStyleKeys);
|
|
300
|
-
if (chunk) chunks.push(chunk);
|
|
301
|
-
}
|
|
302
|
-
collectAncillarySSR(collector, resolved, chunks);
|
|
303
|
-
} else if (typeof document === "undefined") return computeStylesRSC(resolved, chunkMap);
|
|
304
|
-
else {
|
|
305
|
-
injectAncillarySync(resolved);
|
|
306
|
-
const usedKf = getUsedKeyframes(resolved);
|
|
307
|
-
const nameMap = usedKf ? injectKeyframesSync(usedKf) : null;
|
|
308
|
-
for (const [chunkName, chunkStyleKeys] of chunkMap) {
|
|
309
|
-
const chunk = processChunkSync(resolved, chunkName, chunkStyleKeys);
|
|
310
|
-
if (chunk) chunks.push(chunk);
|
|
311
|
-
}
|
|
312
|
-
if (nameMap) injectChunkRulesSync(chunks, nameMap);
|
|
313
|
-
for (const chunk of chunks) touch(chunk.className);
|
|
314
|
-
}
|
|
315
|
-
if (chunks.length === 0) return EMPTY_RESULT;
|
|
316
|
-
if (chunks.length === 1) return { className: chunks[0].className };
|
|
317
|
-
return { className: chunks.map((c) => c.className).join(" ") };
|
|
318
|
-
}
|
|
319
|
-
//#endregion
|
|
320
|
-
export { computeStyles };
|
|
321
|
-
|
|
322
|
-
//# sourceMappingURL=compute-styles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compute-styles.js","names":[],"sources":["../src/compute-styles.ts"],"sourcesContent":["/**\n * Hook-free, synchronous style computation.\n *\n * Extracts the core logic from useStyles() into a plain function that can\n * be called during React render without any hooks. Three code paths:\n *\n * 1. SSR collector — styles collected via ServerStyleCollector\n * 2. Client inject — styles injected synchronously into the DOM\n * 3. RSC inline — styles returned as CSS strings for inline <style> emission\n *\n * This enables tasty() components to work as React Server Components.\n */\n\nimport {\n categorizeStyleKeys,\n generateChunkCacheKey,\n renderStylesForChunk,\n} from './chunks';\nimport { getConfig, getGlobalKeyframes, hasGlobalKeyframes } from './config';\nimport {\n counterStyle,\n fontFace,\n inject,\n keyframes,\n property,\n touch,\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, StyleResult } from './pipeline';\nimport {\n flushPendingCSS,\n getRSCCache,\n rscAllocateClassName,\n} from './rsc-cache';\nimport type { RSCStyleCache } from './rsc-cache';\nimport { extractLocalProperties, hasLocalProperties } from './properties';\nimport { collectAutoInferredProperties } from './ssr/collect-auto-properties';\nimport type { ServerStyleCollector } from './ssr/collector';\nimport { formatKeyframesCSS } from './ssr/format-keyframes';\nimport { formatPropertyCSS } from './ssr/format-property';\nimport { formatRules } from './ssr/format-rules';\nimport { getRegisteredSSRCollector } from './ssr/ssr-collector-ref';\nimport type { Styles } from './styles/types';\nimport { hasKeys } from './utils/has-keys';\nimport { resolveRecipes } from './utils/resolve-recipes';\n\nexport interface ComputeStylesResult {\n className: string;\n /** CSS text to emit as an inline <style> tag (RSC mode only). */\n css?: string;\n}\n\nexport interface ComputeStylesOptions {\n ssrCollector?: ServerStyleCollector | null;\n}\n\ninterface ProcessedChunk {\n name: string;\n styleKeys: string[];\n cacheKey: string;\n renderResult: RenderResult;\n className: string;\n}\n\nconst EMPTY_RESULT: ComputeStylesResult = { className: '' };\n\n// ---------------------------------------------------------------------------\n// RSC (React Server Components) inline style support\n// ---------------------------------------------------------------------------\n\n/**\n * Mark internals as emitted for this RSC request.\n *\n * Internals (tokens, @property, @font-face, @counter-style) are emitted\n * exclusively by the SSR collector via ServerStyleCollector.collectInternals().\n * The SSR path is reliable because TastyRegistry is always present as a\n * client component in the root layout, guaranteeing SSR runs for every page.\n *\n * Previously this function also emitted internals and coordinated with SSR\n * via a globalThis flag, but that flag leaked across requests in the same\n * Node.js process, causing pages without RSC-rendered tasty components\n * (e.g. the playground route) to lose all token CSS.\n */\nfunction collectInternalsRSC(rscCache: RSCStyleCache): string {\n if (rscCache.internalsEmitted) return '';\n rscCache.internalsEmitted = true;\n\n return '';\n}\n\n/**\n * Collect per-component ancillary CSS (keyframes, @property, font-face,\n * counter-style) for RSC mode.\n */\nfunction collectAncillaryRSC(rscCache: RSCStyleCache, styles: Styles): string {\n const parts: string[] = [];\n\n const usedKf = getUsedKeyframes(styles);\n if (usedKf) {\n for (const [name, steps] of Object.entries(usedKf)) {\n const key = `__kf:${name}:${JSON.stringify(steps)}`;\n if (!rscCache.emittedKeys.has(key)) {\n rscCache.emittedKeys.add(key);\n parts.push(formatKeyframesCSS(name, steps));\n }\n }\n }\n\n if (hasLocalProperties(styles)) {\n const localProperties = extractLocalProperties(styles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n const key = `__prop:${token}`;\n if (!rscCache.emittedKeys.has(key)) {\n rscCache.emittedKeys.add(key);\n const css = formatPropertyCSS(token, definition);\n if (css) parts.push(css);\n }\n }\n }\n }\n\n if (hasLocalFontFace(styles)) {\n const localFontFace = extractLocalFontFace(styles);\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 key = `__ff:${hash}`;\n if (!rscCache.emittedKeys.has(key)) {\n rscCache.emittedKeys.add(key);\n parts.push(formatFontFaceRule(family, desc));\n }\n }\n }\n }\n }\n\n if (hasLocalCounterStyle(styles)) {\n const localCounterStyle = extractLocalCounterStyle(styles);\n if (localCounterStyle) {\n for (const [name, descriptors] of Object.entries(localCounterStyle)) {\n const key = `__cs:${name}:${JSON.stringify(descriptors)}`;\n if (!rscCache.emittedKeys.has(key)) {\n rscCache.emittedKeys.add(key);\n parts.push(formatCounterStyleRule(name, descriptors));\n }\n }\n }\n }\n\n return parts.join('\\n');\n}\n\n/**\n * Process all chunks in RSC mode: render CSS to strings, allocate classNames,\n * and return combined { className, css }.\n */\nfunction computeStylesRSC(\n styles: Styles,\n chunkMap: Map<string, string[]>,\n): ComputeStylesResult {\n const rscCache = getRSCCache();\n const cssParts: string[] = [];\n const classNames: string[] = [];\n\n // Flush CSS accumulated by standalone style functions\n const pendingCSS = flushPendingCSS(rscCache);\n if (pendingCSS) cssParts.push(pendingCSS);\n\n const internalsCSS = collectInternalsRSC(rscCache);\n if (internalsCSS) cssParts.push(internalsCSS);\n\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n if (chunkStyleKeys.length === 0) continue;\n\n const cacheKey = generateChunkCacheKey(styles, chunkName, chunkStyleKeys);\n const { className, isNew } = rscAllocateClassName(rscCache, cacheKey);\n classNames.push(className);\n\n if (isNew) {\n const renderResult = renderStylesForChunk(\n styles,\n chunkName,\n chunkStyleKeys,\n );\n if (renderResult.rules.length > 0) {\n const css = formatRules(renderResult.rules, className);\n if (css) cssParts.push(css);\n }\n }\n }\n\n const ancillaryCSS = collectAncillaryRSC(rscCache, styles);\n if (ancillaryCSS) cssParts.push(ancillaryCSS);\n\n if (classNames.length === 0) return EMPTY_RESULT;\n\n const css = cssParts.join('\\n');\n\n return {\n className: classNames.join(' '),\n css: css || undefined,\n };\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 */\nfunction getUsedKeyframes(\n styles: Styles,\n): Record<string, KeyframesSteps> | null {\n const hasLocal = hasLocalKeyframes(styles);\n const hasGlobal = hasGlobalKeyframes();\n if (!hasLocal && !hasGlobal) return null;\n\n const usedNames = extractAnimationNamesFromStyles(styles);\n if (usedNames.size === 0) return null;\n\n const local = hasLocal ? extractLocalKeyframes(styles) : null;\n const global = hasGlobal ? getGlobalKeyframes() : null;\n const allKeyframes = mergeKeyframes(local, global);\n\n return filterUsedKeyframes(allKeyframes, usedNames);\n}\n\n/**\n * Process a chunk on the SSR path: allocate via collector, render, collect CSS.\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 { name: chunkName, styleKeys, cacheKey, renderResult, className };\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 * Process a chunk on the client: render, allocate className, and inject\n * CSS synchronously. The injector's cache makes this idempotent.\n */\nfunction processChunkSync(\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 } = inject(renderResult.rules, { cacheKey });\n\n return { name: chunkName, styleKeys, cacheKey, renderResult, className };\n}\n\n/**\n * Inject keyframes synchronously and return a name replacement map.\n * On the client, keyframes are injected into the DOM.\n */\nfunction injectKeyframesSync(\n usedKeyframes: Record<string, KeyframesSteps>,\n): Map<string, string> | null {\n let nameMap: Map<string, string> | null = null;\n\n for (const [name, steps] of Object.entries(usedKeyframes)) {\n const result = keyframes(steps, { name });\n const injectedName = result.toString();\n if (injectedName !== name) {\n if (!nameMap) nameMap = new Map();\n nameMap.set(name, injectedName);\n }\n }\n\n return nameMap;\n}\n\n/**\n * Inject chunk rules synchronously, replacing animation names if needed.\n */\nfunction injectChunkRulesSync(\n chunks: ProcessedChunk[],\n nameMap: Map<string, string> | null,\n): void {\n for (const chunk of chunks) {\n if (chunk.renderResult.rules.length > 0) {\n const rulesToInject: StyleResult[] = nameMap\n ? chunk.renderResult.rules.map((rule) => ({\n ...rule,\n declarations: replaceAnimationNames(rule.declarations, nameMap!),\n }))\n : chunk.renderResult.rules;\n\n inject(rulesToInject, { cacheKey: chunk.cacheKey });\n }\n }\n}\n\n/**\n * Inject all ancillary rules (properties, font-faces, counter-styles) synchronously.\n */\nfunction injectAncillarySync(styles: Styles): void {\n if (hasLocalProperties(styles)) {\n const localProperties = extractLocalProperties(styles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n property(token, definition);\n }\n }\n }\n\n if (hasLocalFontFace(styles)) {\n const localFontFace = extractLocalFontFace(styles);\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 if (hasLocalCounterStyle(styles)) {\n const localCounterStyle = extractLocalCounterStyle(styles);\n if (localCounterStyle) {\n for (const [name, descriptors] of Object.entries(localCounterStyle)) {\n counterStyle(name, descriptors);\n }\n }\n }\n}\n\n/**\n * Collect all ancillary rules into the SSR collector.\n */\nfunction collectAncillarySSR(\n collector: ServerStyleCollector,\n styles: Styles,\n chunks: ProcessedChunk[],\n): void {\n const usedKf = getUsedKeyframes(styles);\n if (usedKf) {\n for (const [name, steps] of Object.entries(usedKf)) {\n const css = formatKeyframesCSS(name, steps);\n collector.collectKeyframes(name, css);\n }\n }\n\n if (hasLocalProperties(styles)) {\n const localProperties = extractLocalProperties(styles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n const css = formatPropertyCSS(token, definition);\n if (css) {\n collector.collectProperty(token, css);\n }\n }\n }\n }\n\n if (hasLocalFontFace(styles)) {\n const localFontFace = extractLocalFontFace(styles);\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 collector.collectFontFace(hash, css);\n }\n }\n }\n }\n\n if (hasLocalCounterStyle(styles)) {\n const localCounterStyle = extractLocalCounterStyle(styles);\n if (localCounterStyle) {\n for (const [name, descriptors] of Object.entries(localCounterStyle)) {\n const css = formatCounterStyleRule(name, descriptors);\n collector.collectCounterStyle(name, css);\n }\n }\n }\n\n if (getConfig().autoPropertyTypes !== false) {\n const allRules = chunks.flatMap((c) => c.renderResult.rules);\n if (allRules.length > 0) {\n collectAutoInferredProperties(allRules, collector, styles);\n }\n }\n}\n\n/**\n * Synchronous, hook-free style computation.\n *\n * Resolves recipes, categorizes style keys into chunks, renders CSS rules,\n * allocates class names, and injects / collects / returns the CSS.\n *\n * Three code paths:\n * 1. SSR collector — discovered via ALS or passed explicitly; CSS collected\n * 2. RSC inline — no collector and no `document`; CSS returned as `result.css`\n * for the caller to emit as an inline `<style>` tag\n * 3. Client inject — CSS injected synchronously into the DOM (idempotent)\n *\n * @param styles - Tasty styles object (or undefined for no styles)\n * @param options - Optional SSR collector override\n */\nexport function computeStyles(\n styles: Styles | undefined,\n options?: ComputeStylesOptions,\n): ComputeStylesResult {\n if (!styles || !hasKeys(styles as Record<string, unknown>)) {\n return EMPTY_RESULT;\n }\n\n const resolved = resolveRecipes(styles);\n const chunkMap = categorizeStyleKeys(resolved as Record<string, unknown>);\n\n const collector =\n options?.ssrCollector !== undefined\n ? options.ssrCollector\n : getRegisteredSSRCollector();\n\n const chunks: ProcessedChunk[] = [];\n\n if (collector) {\n collector.collectInternals();\n\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n const chunk = processChunkSSR(\n collector,\n resolved,\n chunkName,\n chunkStyleKeys,\n );\n if (chunk) chunks.push(chunk);\n }\n\n collectAncillarySSR(collector, resolved, chunks);\n } else if (typeof document === 'undefined') {\n // RSC path: render CSS to strings for inline <style> emission\n return computeStylesRSC(resolved, chunkMap);\n } else {\n injectAncillarySync(resolved);\n\n const usedKf = getUsedKeyframes(resolved);\n const nameMap = usedKf ? injectKeyframesSync(usedKf) : null;\n\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n const chunk = processChunkSync(resolved, chunkName, chunkStyleKeys);\n if (chunk) chunks.push(chunk);\n }\n\n if (nameMap) {\n injectChunkRulesSync(chunks, nameMap);\n }\n\n for (const chunk of chunks) {\n touch(chunk.className);\n }\n }\n\n if (chunks.length === 0) return EMPTY_RESULT;\n if (chunks.length === 1) return { className: chunks[0].className };\n\n return { className: chunks.map((c) => c.className).join(' ') };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,MAAM,eAAoC,EAAE,WAAW,IAAI;;;;;;;;;;;;;;AAmB3D,SAAS,oBAAoB,UAAiC;AAC5D,KAAI,SAAS,iBAAkB,QAAO;AACtC,UAAS,mBAAmB;AAE5B,QAAO;;;;;;AAOT,SAAS,oBAAoB,UAAyB,QAAwB;CAC5E,MAAM,QAAkB,EAAE;CAE1B,MAAM,SAAS,iBAAiB,OAAO;AACvC,KAAI,OACF,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,OAAO,EAAE;EAClD,MAAM,MAAM,QAAQ,KAAK,GAAG,KAAK,UAAU,MAAM;AACjD,MAAI,CAAC,SAAS,YAAY,IAAI,IAAI,EAAE;AAClC,YAAS,YAAY,IAAI,IAAI;AAC7B,SAAM,KAAK,mBAAmB,MAAM,MAAM,CAAC;;;AAKjD,KAAI,mBAAmB,OAAO,EAAE;EAC9B,MAAM,kBAAkB,uBAAuB,OAAO;AACtD,MAAI,gBACF,MAAK,MAAM,CAAC,OAA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