@tenphi/tasty 0.0.0-snapshot.b3fbcbb → 0.0.0-snapshot.b478bc9
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 +297 -208
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +17 -10
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.d.ts +1 -1
- package/dist/chunks/definitions.js +3 -5
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +32 -34
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +322 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +149 -30
- package/dist/config.js +233 -45
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +12 -11
- package/dist/core/index.js +12 -11
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +26 -141
- package/dist/debug.js +359 -639
- package/dist/debug.js.map +1 -1
- package/dist/font-face/index.js +63 -0
- package/dist/font-face/index.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/useCounterStyle.d.ts +36 -0
- package/dist/hooks/useCounterStyle.js +65 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +45 -0
- package/dist/hooks/useFontFace.js +66 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +21 -2
- package/dist/hooks/useGlobalStyles.js +60 -28
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.d.ts +4 -2
- package/dist/hooks/useKeyframes.js +44 -43
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.d.ts +4 -2
- package/dist/hooks/useProperty.js +36 -31
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.d.ts +13 -44
- package/dist/hooks/useRawCSS.js +91 -16
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +3 -3
- package/dist/hooks/useStyles.js +8 -146
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +15 -12
- package/dist/index.js +15 -12
- package/dist/injector/index.d.ts +36 -11
- package/dist/injector/index.js +43 -12
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +62 -3
- package/dist/injector/injector.js +256 -31
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +10 -13
- package/dist/injector/sheet-manager.js +42 -71
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +112 -21
- package/dist/keyframes/index.js +1 -1
- package/dist/parser/classify.js +6 -6
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/const.js +30 -3
- package/dist/parser/const.js.map +1 -1
- package/dist/parser/lru.js +1 -1
- package/dist/parser/lru.js.map +1 -1
- package/dist/parser/parser.js +2 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/types.js +1 -1
- package/dist/parser/types.js.map +1 -1
- package/dist/pipeline/conditions.js +1 -1
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/exclusive.js +163 -5
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +172 -83
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize-contradictions.js +125 -0
- package/dist/pipeline/materialize-contradictions.js.map +1 -0
- package/dist/pipeline/materialize.js +437 -243
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +1 -1
- package/dist/pipeline/parseStateKey.js +21 -13
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +181 -7
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/pipeline/warnings.js +1 -1
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.js +3 -277
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +20 -2
- package/dist/properties/index.js +15 -30
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.js +13 -2
- package/dist/properties/property-type-resolver.js.map +1 -1
- package/dist/rsc-cache.js +79 -0
- package/dist/rsc-cache.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +19 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +15 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +108 -0
- package/dist/ssr/astro.js +149 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +44 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +58 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +98 -0
- package/dist/ssr/collector.js +235 -0
- package/dist/ssr/collector.js.map +1 -0
- package/dist/ssr/context.js +16 -0
- package/dist/ssr/context.js.map +1 -0
- package/dist/ssr/format-global-rules.js +22 -0
- package/dist/ssr/format-global-rules.js.map +1 -0
- package/dist/ssr/format-keyframes.js +69 -0
- package/dist/ssr/format-keyframes.js.map +1 -0
- package/dist/ssr/format-property.js +49 -0
- package/dist/ssr/format-property.js.map +1 -0
- package/dist/ssr/format-rules.js +73 -0
- package/dist/ssr/format-rules.js.map +1 -0
- package/dist/ssr/hydrate.d.ts +29 -0
- package/dist/ssr/hydrate.js +45 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/index.d.ts +4 -0
- package/dist/ssr/index.js +10 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +46 -0
- package/dist/ssr/next.js +75 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/ssr/ssr-collector-ref.js +29 -0
- package/dist/ssr/ssr-collector-ref.js.map +1 -0
- package/dist/states/index.js +13 -259
- package/dist/states/index.js.map +1 -1
- package/dist/static/index.js +1 -2
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/static/tastyStatic.js +1 -2
- package/dist/static/tastyStatic.js.map +1 -1
- package/dist/static/types.js +1 -1
- package/dist/styles/border.d.ts +1 -1
- package/dist/styles/border.js +30 -24
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +1 -1
- package/dist/styles/color.js +11 -8
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +28 -26
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/dimension.js +15 -3
- package/dist/styles/dimension.js.map +1 -1
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +3 -10
- package/dist/styles/display.js +45 -39
- package/dist/styles/display.js.map +1 -1
- package/dist/styles/fade.d.ts +1 -1
- package/dist/styles/fade.js +9 -5
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +2 -2
- package/dist/styles/fill.js +3 -4
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.js +1 -1
- package/dist/styles/gap.d.ts +1 -1
- package/dist/styles/gap.js +4 -3
- package/dist/styles/gap.js.map +1 -1
- package/dist/styles/height.d.ts +1 -1
- package/dist/styles/height.js +1 -2
- package/dist/styles/height.js.map +1 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +3 -4
- package/dist/styles/index.js.map +1 -1
- package/dist/styles/inset.d.ts +1 -29
- package/dist/styles/inset.js +19 -135
- package/dist/styles/inset.js.map +1 -1
- package/dist/styles/list.d.ts +5 -5
- package/dist/styles/list.js +4 -2
- package/dist/styles/list.js.map +1 -1
- package/dist/styles/margin.d.ts +1 -1
- package/dist/styles/margin.js +17 -89
- package/dist/styles/margin.js.map +1 -1
- package/dist/styles/outline.d.ts +1 -1
- package/dist/styles/outline.js +6 -16
- package/dist/styles/outline.js.map +1 -1
- package/dist/styles/padding.d.ts +1 -1
- package/dist/styles/padding.js +17 -89
- package/dist/styles/padding.js.map +1 -1
- package/dist/styles/placement.d.ts +37 -0
- package/dist/styles/placement.js +74 -0
- package/dist/styles/placement.js.map +1 -0
- package/dist/styles/predefined.d.ts +4 -6
- package/dist/styles/predefined.js +9 -13
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.d.ts +6 -1
- package/dist/styles/preset.js +54 -53
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/radius.d.ts +1 -3
- package/dist/styles/radius.js +38 -6
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollMargin.d.ts +24 -0
- package/dist/styles/scrollMargin.js +32 -0
- package/dist/styles/scrollMargin.js.map +1 -0
- package/dist/styles/scrollbar.d.ts +9 -5
- package/dist/styles/scrollbar.js +31 -92
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +1 -1
- package/dist/styles/shadow.js +4 -3
- package/dist/styles/shadow.js.map +1 -1
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +1 -1
- package/dist/styles/transition.js +6 -5
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +94 -28
- package/dist/styles/width.d.ts +1 -1
- package/dist/styles/width.js +1 -2
- package/dist/styles/width.js.map +1 -1
- package/dist/tasty.d.ts +46 -894
- package/dist/tasty.js +101 -59
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/cache-wrapper.js +4 -9
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/case-converter.js +1 -1
- package/dist/utils/color-math.d.ts +46 -0
- package/dist/utils/color-math.js +749 -0
- package/dist/utils/color-math.js.map +1 -0
- package/dist/utils/color-space.d.ts +5 -0
- package/dist/utils/color-space.js +228 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.js +3 -2
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/deps-equal.js +15 -0
- package/dist/utils/deps-equal.js.map +1 -0
- package/dist/utils/dotize.js +1 -1
- package/dist/utils/dotize.js.map +1 -1
- package/dist/utils/filter-base-props.d.ts +1 -1
- package/dist/utils/filter-base-props.js +1 -1
- package/dist/utils/filter-base-props.js.map +1 -1
- package/dist/utils/get-display-name.js +1 -1
- package/dist/utils/has-keys.js +13 -0
- package/dist/utils/has-keys.js.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/is-dev-env.js +1 -1
- package/dist/utils/is-dev-env.js.map +1 -1
- package/dist/utils/is-valid-element-type.js +1 -1
- package/dist/utils/merge-styles.js +1 -2
- package/dist/utils/merge-styles.js.map +1 -1
- package/dist/utils/mod-attrs.d.ts +0 -2
- package/dist/utils/mod-attrs.js +3 -4
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +3 -17
- package/dist/utils/process-tokens.js +19 -107
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/resolve-recipes.js +1 -2
- package/dist/utils/resolve-recipes.js.map +1 -1
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/string.js +1 -1
- package/dist/utils/styles.d.ts +3 -82
- package/dist/utils/styles.js +29 -560
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +35 -13
- package/dist/utils/typography.js +16 -18
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +57 -89
- package/dist/zero/babel.js +214 -40
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/css-writer.js +1 -2
- package/dist/zero/css-writer.js.map +1 -1
- package/dist/zero/extractor.js +54 -3
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/index.js +1 -2
- package/dist/zero/next.d.ts +56 -30
- package/dist/zero/next.js +105 -40
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +31 -0
- package/docs/adoption.md +298 -0
- package/docs/comparison.md +419 -0
- package/docs/configuration.md +394 -0
- package/docs/debug.md +320 -0
- package/docs/design-system.md +436 -0
- package/docs/dsl.md +688 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +544 -0
- package/docs/methodology.md +616 -0
- package/docs/pipeline.md +673 -0
- package/docs/react-api.md +557 -0
- package/docs/ssr.md +442 -0
- package/docs/styles.md +596 -0
- package/docs/tasty-static.md +532 -0
- package/package.json +68 -36
- 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/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.js.map +0 -1
- package/dist/styles/styledScrollbar.d.ts +0 -47
- package/dist/styles/styledScrollbar.js +0 -38
- package/dist/styles/styledScrollbar.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { StyleResult } from "../pipeline/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/ssr/collector.d.ts
|
|
4
|
+
declare class ServerStyleCollector {
|
|
5
|
+
private chunks;
|
|
6
|
+
private cacheKeyToClassName;
|
|
7
|
+
private flushedKeys;
|
|
8
|
+
private propertyRules;
|
|
9
|
+
private flushedPropertyKeys;
|
|
10
|
+
private keyframeRules;
|
|
11
|
+
private flushedKeyframeKeys;
|
|
12
|
+
private globalStyles;
|
|
13
|
+
private flushedGlobalKeys;
|
|
14
|
+
private rawCSS;
|
|
15
|
+
private flushedRawKeys;
|
|
16
|
+
private fontFaceRules;
|
|
17
|
+
private flushedFontFaceKeys;
|
|
18
|
+
private counterStyleRules;
|
|
19
|
+
private flushedCounterStyleKeys;
|
|
20
|
+
private keyframesCounter;
|
|
21
|
+
private counterStyleCounter;
|
|
22
|
+
private internalsCollected;
|
|
23
|
+
/**
|
|
24
|
+
* Collect internal @property rules and :root token defaults.
|
|
25
|
+
* Mirrors markStylesGenerated() from the client-side injector.
|
|
26
|
+
* Called automatically on first chunk collection; idempotent.
|
|
27
|
+
*
|
|
28
|
+
* Internals are always emitted here — the RSC path deliberately
|
|
29
|
+
* defers to SSR so that tokens appear exactly once per page in
|
|
30
|
+
* <style data-tasty-ssr> (avoiding duplication of large token sets).
|
|
31
|
+
*/
|
|
32
|
+
collectInternals(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Allocate a className for a cache key, server-side.
|
|
35
|
+
* Mirrors StyleInjector.allocateClassName but without DOM access.
|
|
36
|
+
*/
|
|
37
|
+
allocateClassName(cacheKey: string): {
|
|
38
|
+
className: string;
|
|
39
|
+
isNewAllocation: boolean;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Record CSS rules for a chunk.
|
|
43
|
+
* Called by useStyles during server render.
|
|
44
|
+
*/
|
|
45
|
+
collectChunk(cacheKey: string, className: string, rules: StyleResult[]): void;
|
|
46
|
+
/**
|
|
47
|
+
* Record a @property rule. Deduplicated by name.
|
|
48
|
+
*/
|
|
49
|
+
collectProperty(name: string, css: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Record a @keyframes rule. Deduplicated by name.
|
|
52
|
+
*/
|
|
53
|
+
collectKeyframes(name: string, css: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Allocate a keyframe name for SSR. Uses provided name or generates one.
|
|
56
|
+
*/
|
|
57
|
+
allocateKeyframeName(providedName?: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Record a @font-face rule. Deduplicated by key (content hash).
|
|
60
|
+
*/
|
|
61
|
+
collectFontFace(key: string, css: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Record a @counter-style rule. Deduplicated by name.
|
|
64
|
+
*/
|
|
65
|
+
collectCounterStyle(name: string, css: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* Allocate a counter-style name for SSR. Uses provided name or generates one.
|
|
68
|
+
*/
|
|
69
|
+
allocateCounterStyleName(providedName?: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* Record global styles (from useGlobalStyles). Deduplicated by key.
|
|
72
|
+
*/
|
|
73
|
+
collectGlobalStyles(key: string, css: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* Record raw CSS text (from useRawCSS). Deduplicated by key.
|
|
76
|
+
*/
|
|
77
|
+
collectRawCSS(key: string, css: string): void;
|
|
78
|
+
/**
|
|
79
|
+
* Extract all CSS collected so far as a single string.
|
|
80
|
+
* Includes @property and @keyframes rules.
|
|
81
|
+
* Used for non-streaming SSR (renderToString).
|
|
82
|
+
*/
|
|
83
|
+
getCSS(): string;
|
|
84
|
+
/**
|
|
85
|
+
* Flush only newly collected CSS since the last flush.
|
|
86
|
+
* Used for streaming SSR (renderToPipeableStream + useServerInsertedHTML).
|
|
87
|
+
*/
|
|
88
|
+
flushCSS(): string;
|
|
89
|
+
private flushedClassNames;
|
|
90
|
+
/**
|
|
91
|
+
* Return class names rendered since the last call (for streaming).
|
|
92
|
+
* Used to emit lightweight class-list scripts for client hydration.
|
|
93
|
+
*/
|
|
94
|
+
getRenderedClassNames(): string[];
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { ServerStyleCollector };
|
|
98
|
+
//# sourceMappingURL=collector.d.ts.map
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { hashString } from "../utils/hash.js";
|
|
2
|
+
import { fontFaceContentHash, formatFontFaceRule } from "../font-face/index.js";
|
|
3
|
+
import { formatCounterStyleRule } from "../counter-style/index.js";
|
|
4
|
+
import { renderStyles } from "../pipeline/index.js";
|
|
5
|
+
import { getEffectiveProperties, getGlobalConfigTokens, getGlobalCounterStyle, getGlobalFontFace, getGlobalStyles } from "../config.js";
|
|
6
|
+
import { formatPropertyCSS } from "./format-property.js";
|
|
7
|
+
import { formatRules } from "./format-rules.js";
|
|
8
|
+
import { formatGlobalRules } from "./format-global-rules.js";
|
|
9
|
+
//#region src/ssr/collector.ts
|
|
10
|
+
/**
|
|
11
|
+
* ServerStyleCollector — server-safe style collector for SSR.
|
|
12
|
+
*
|
|
13
|
+
* Accumulates CSS rules and cache metadata during server rendering.
|
|
14
|
+
* This is the server-side counterpart to StyleInjector: it allocates
|
|
15
|
+
* hash-based class names (`t${hash}`), formats CSS rules into text,
|
|
16
|
+
* and tracks rendered class names for lightweight client transfer.
|
|
17
|
+
*
|
|
18
|
+
* One instance is created per HTTP request. Concurrent requests
|
|
19
|
+
* each get their own collector (via AsyncLocalStorage or React context).
|
|
20
|
+
*/
|
|
21
|
+
function generateClassName(cacheKey) {
|
|
22
|
+
return `t${hashString(cacheKey)}`;
|
|
23
|
+
}
|
|
24
|
+
var ServerStyleCollector = class {
|
|
25
|
+
chunks = /* @__PURE__ */ new Map();
|
|
26
|
+
cacheKeyToClassName = /* @__PURE__ */ new Map();
|
|
27
|
+
flushedKeys = /* @__PURE__ */ new Set();
|
|
28
|
+
propertyRules = /* @__PURE__ */ new Map();
|
|
29
|
+
flushedPropertyKeys = /* @__PURE__ */ new Set();
|
|
30
|
+
keyframeRules = /* @__PURE__ */ new Map();
|
|
31
|
+
flushedKeyframeKeys = /* @__PURE__ */ new Set();
|
|
32
|
+
globalStyles = /* @__PURE__ */ new Map();
|
|
33
|
+
flushedGlobalKeys = /* @__PURE__ */ new Set();
|
|
34
|
+
rawCSS = /* @__PURE__ */ new Map();
|
|
35
|
+
flushedRawKeys = /* @__PURE__ */ new Set();
|
|
36
|
+
fontFaceRules = /* @__PURE__ */ new Map();
|
|
37
|
+
flushedFontFaceKeys = /* @__PURE__ */ new Set();
|
|
38
|
+
counterStyleRules = /* @__PURE__ */ new Map();
|
|
39
|
+
flushedCounterStyleKeys = /* @__PURE__ */ new Set();
|
|
40
|
+
keyframesCounter = 0;
|
|
41
|
+
counterStyleCounter = 0;
|
|
42
|
+
internalsCollected = false;
|
|
43
|
+
/**
|
|
44
|
+
* Collect internal @property rules and :root token defaults.
|
|
45
|
+
* Mirrors markStylesGenerated() from the client-side injector.
|
|
46
|
+
* Called automatically on first chunk collection; idempotent.
|
|
47
|
+
*
|
|
48
|
+
* Internals are always emitted here — the RSC path deliberately
|
|
49
|
+
* defers to SSR so that tokens appear exactly once per page in
|
|
50
|
+
* <style data-tasty-ssr> (avoiding duplication of large token sets).
|
|
51
|
+
*/
|
|
52
|
+
collectInternals() {
|
|
53
|
+
if (this.internalsCollected) return;
|
|
54
|
+
this.internalsCollected = true;
|
|
55
|
+
for (const [token, definition] of Object.entries(getEffectiveProperties())) {
|
|
56
|
+
const css = formatPropertyCSS(token, definition);
|
|
57
|
+
if (css) this.collectProperty(`__prop:${token}`, css);
|
|
58
|
+
}
|
|
59
|
+
const tokenStyles = getGlobalConfigTokens();
|
|
60
|
+
if (tokenStyles && Object.keys(tokenStyles).length > 0) {
|
|
61
|
+
const tokenRules = renderStyles(tokenStyles, ":root");
|
|
62
|
+
if (tokenRules.length > 0) {
|
|
63
|
+
const css = formatGlobalRules(tokenRules);
|
|
64
|
+
if (css) this.collectGlobalStyles("__global:tokens", css);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const globalFF = getGlobalFontFace();
|
|
68
|
+
if (globalFF) for (const [family, input] of Object.entries(globalFF)) {
|
|
69
|
+
const descriptors = Array.isArray(input) ? input : [input];
|
|
70
|
+
for (const desc of descriptors) {
|
|
71
|
+
const hash = fontFaceContentHash(family, desc);
|
|
72
|
+
const css = formatFontFaceRule(family, desc);
|
|
73
|
+
this.collectFontFace(hash, css);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const globalCS = getGlobalCounterStyle();
|
|
77
|
+
if (globalCS) for (const [name, descriptors] of Object.entries(globalCS)) {
|
|
78
|
+
const css = formatCounterStyleRule(name, descriptors);
|
|
79
|
+
this.collectCounterStyle(name, css);
|
|
80
|
+
}
|
|
81
|
+
const globalStyles = getGlobalStyles();
|
|
82
|
+
if (globalStyles) {
|
|
83
|
+
for (const [selector, styles] of Object.entries(globalStyles)) if (Object.keys(styles).length > 0) {
|
|
84
|
+
const rules = renderStyles(styles, selector);
|
|
85
|
+
if (rules.length > 0) {
|
|
86
|
+
const css = formatGlobalRules(rules);
|
|
87
|
+
if (css) this.collectGlobalStyles(`__global:styles:${selector}`, css);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Allocate a className for a cache key, server-side.
|
|
94
|
+
* Mirrors StyleInjector.allocateClassName but without DOM access.
|
|
95
|
+
*/
|
|
96
|
+
allocateClassName(cacheKey) {
|
|
97
|
+
const existing = this.cacheKeyToClassName.get(cacheKey);
|
|
98
|
+
if (existing) return {
|
|
99
|
+
className: existing,
|
|
100
|
+
isNewAllocation: false
|
|
101
|
+
};
|
|
102
|
+
const className = generateClassName(cacheKey);
|
|
103
|
+
this.cacheKeyToClassName.set(cacheKey, className);
|
|
104
|
+
return {
|
|
105
|
+
className,
|
|
106
|
+
isNewAllocation: true
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Record CSS rules for a chunk.
|
|
111
|
+
* Called by useStyles during server render.
|
|
112
|
+
*/
|
|
113
|
+
collectChunk(cacheKey, className, rules) {
|
|
114
|
+
if (this.chunks.has(cacheKey)) return;
|
|
115
|
+
const css = formatRules(rules, className);
|
|
116
|
+
if (css) this.chunks.set(cacheKey, css);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Record a @property rule. Deduplicated by name.
|
|
120
|
+
*/
|
|
121
|
+
collectProperty(name, css) {
|
|
122
|
+
if (!this.propertyRules.has(name)) this.propertyRules.set(name, css);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Record a @keyframes rule. Deduplicated by name.
|
|
126
|
+
*/
|
|
127
|
+
collectKeyframes(name, css) {
|
|
128
|
+
if (!this.keyframeRules.has(name)) this.keyframeRules.set(name, css);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Allocate a keyframe name for SSR. Uses provided name or generates one.
|
|
132
|
+
*/
|
|
133
|
+
allocateKeyframeName(providedName) {
|
|
134
|
+
return providedName ?? `k${this.keyframesCounter++}`;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Record a @font-face rule. Deduplicated by key (content hash).
|
|
138
|
+
*/
|
|
139
|
+
collectFontFace(key, css) {
|
|
140
|
+
if (!this.fontFaceRules.has(key)) this.fontFaceRules.set(key, css);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Record a @counter-style rule. Deduplicated by name.
|
|
144
|
+
*/
|
|
145
|
+
collectCounterStyle(name, css) {
|
|
146
|
+
if (!this.counterStyleRules.has(name)) this.counterStyleRules.set(name, css);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Allocate a counter-style name for SSR. Uses provided name or generates one.
|
|
150
|
+
*/
|
|
151
|
+
allocateCounterStyleName(providedName) {
|
|
152
|
+
return providedName ?? `cs${this.counterStyleCounter++}`;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Record global styles (from useGlobalStyles). Deduplicated by key.
|
|
156
|
+
*/
|
|
157
|
+
collectGlobalStyles(key, css) {
|
|
158
|
+
if (!this.globalStyles.has(key)) this.globalStyles.set(key, css);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Record raw CSS text (from useRawCSS). Deduplicated by key.
|
|
162
|
+
*/
|
|
163
|
+
collectRawCSS(key, css) {
|
|
164
|
+
if (!this.rawCSS.has(key)) this.rawCSS.set(key, css);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Extract all CSS collected so far as a single string.
|
|
168
|
+
* Includes @property and @keyframes rules.
|
|
169
|
+
* Used for non-streaming SSR (renderToString).
|
|
170
|
+
*/
|
|
171
|
+
getCSS() {
|
|
172
|
+
const parts = [];
|
|
173
|
+
for (const css of this.propertyRules.values()) parts.push(css);
|
|
174
|
+
for (const css of this.fontFaceRules.values()) parts.push(css);
|
|
175
|
+
for (const css of this.counterStyleRules.values()) parts.push(css);
|
|
176
|
+
for (const css of this.rawCSS.values()) parts.push(css);
|
|
177
|
+
for (const css of this.globalStyles.values()) parts.push(css);
|
|
178
|
+
for (const css of this.chunks.values()) parts.push(css);
|
|
179
|
+
for (const css of this.keyframeRules.values()) parts.push(css);
|
|
180
|
+
return parts.join("\n");
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Flush only newly collected CSS since the last flush.
|
|
184
|
+
* Used for streaming SSR (renderToPipeableStream + useServerInsertedHTML).
|
|
185
|
+
*/
|
|
186
|
+
flushCSS() {
|
|
187
|
+
const parts = [];
|
|
188
|
+
for (const [name, css] of this.propertyRules) if (!this.flushedPropertyKeys.has(name)) {
|
|
189
|
+
parts.push(css);
|
|
190
|
+
this.flushedPropertyKeys.add(name);
|
|
191
|
+
}
|
|
192
|
+
for (const [key, css] of this.fontFaceRules) if (!this.flushedFontFaceKeys.has(key)) {
|
|
193
|
+
parts.push(css);
|
|
194
|
+
this.flushedFontFaceKeys.add(key);
|
|
195
|
+
}
|
|
196
|
+
for (const [key, css] of this.counterStyleRules) if (!this.flushedCounterStyleKeys.has(key)) {
|
|
197
|
+
parts.push(css);
|
|
198
|
+
this.flushedCounterStyleKeys.add(key);
|
|
199
|
+
}
|
|
200
|
+
for (const [key, css] of this.rawCSS) if (!this.flushedRawKeys.has(key)) {
|
|
201
|
+
parts.push(css);
|
|
202
|
+
this.flushedRawKeys.add(key);
|
|
203
|
+
}
|
|
204
|
+
for (const [key, css] of this.globalStyles) if (!this.flushedGlobalKeys.has(key)) {
|
|
205
|
+
parts.push(css);
|
|
206
|
+
this.flushedGlobalKeys.add(key);
|
|
207
|
+
}
|
|
208
|
+
for (const [key, css] of this.chunks) if (!this.flushedKeys.has(key)) {
|
|
209
|
+
parts.push(css);
|
|
210
|
+
this.flushedKeys.add(key);
|
|
211
|
+
}
|
|
212
|
+
for (const [name, css] of this.keyframeRules) if (!this.flushedKeyframeKeys.has(name)) {
|
|
213
|
+
parts.push(css);
|
|
214
|
+
this.flushedKeyframeKeys.add(name);
|
|
215
|
+
}
|
|
216
|
+
return parts.join("\n");
|
|
217
|
+
}
|
|
218
|
+
flushedClassNames = /* @__PURE__ */ new Set();
|
|
219
|
+
/**
|
|
220
|
+
* Return class names rendered since the last call (for streaming).
|
|
221
|
+
* Used to emit lightweight class-list scripts for client hydration.
|
|
222
|
+
*/
|
|
223
|
+
getRenderedClassNames() {
|
|
224
|
+
const names = [];
|
|
225
|
+
for (const className of this.cacheKeyToClassName.values()) if (!this.flushedClassNames.has(className)) {
|
|
226
|
+
this.flushedClassNames.add(className);
|
|
227
|
+
names.push(className);
|
|
228
|
+
}
|
|
229
|
+
return names;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
//#endregion
|
|
233
|
+
export { ServerStyleCollector };
|
|
234
|
+
|
|
235
|
+
//# sourceMappingURL=collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collector.js","names":[],"sources":["../../src/ssr/collector.ts"],"sourcesContent":["/**\n * ServerStyleCollector — server-safe style collector for SSR.\n *\n * Accumulates CSS rules and cache metadata during server rendering.\n * This is the server-side counterpart to StyleInjector: it allocates\n * hash-based class names (`t${hash}`), formats CSS rules into text,\n * and tracks rendered class names for lightweight client transfer.\n *\n * One instance is created per HTTP request. Concurrent requests\n * each get their own collector (via AsyncLocalStorage or React context).\n */\n\nimport {\n getEffectiveProperties,\n getGlobalStyles,\n getGlobalCounterStyle,\n getGlobalFontFace,\n getGlobalConfigTokens,\n} from '../config';\nimport { formatCounterStyleRule } from '../counter-style';\nimport { fontFaceContentHash, formatFontFaceRule } from '../font-face';\nimport { renderStyles } from '../pipeline';\nimport type { StyleResult } from '../pipeline';\nimport { hashString } from '../utils/hash';\nimport { formatPropertyCSS } from './format-property';\nimport { formatGlobalRules } from './format-global-rules';\nimport { formatRules } from './format-rules';\n\nfunction generateClassName(cacheKey: string): string {\n return `t${hashString(cacheKey)}`;\n}\n\nexport class ServerStyleCollector {\n private chunks = new Map<string, string>();\n private cacheKeyToClassName = new Map<string, string>();\n private flushedKeys = new Set<string>();\n private propertyRules = new Map<string, string>();\n private flushedPropertyKeys = new Set<string>();\n private keyframeRules = new Map<string, string>();\n private flushedKeyframeKeys = new Set<string>();\n private globalStyles = new Map<string, string>();\n private flushedGlobalKeys = new Set<string>();\n private rawCSS = new Map<string, string>();\n private flushedRawKeys = new Set<string>();\n private fontFaceRules = new Map<string, string>();\n private flushedFontFaceKeys = new Set<string>();\n private counterStyleRules = new Map<string, string>();\n private flushedCounterStyleKeys = new Set<string>();\n private keyframesCounter = 0;\n private counterStyleCounter = 0;\n private internalsCollected = false;\n\n /**\n * Collect internal @property rules and :root token defaults.\n * Mirrors markStylesGenerated() from the client-side injector.\n * Called automatically on first chunk collection; idempotent.\n *\n * Internals are always emitted here — the RSC path deliberately\n * defers to SSR so that tokens appear exactly once per page in\n * <style data-tasty-ssr> (avoiding duplication of large token sets).\n */\n collectInternals(): void {\n if (this.internalsCollected) return;\n this.internalsCollected = true;\n\n for (const [token, definition] of Object.entries(\n getEffectiveProperties(),\n )) {\n const css = formatPropertyCSS(token, definition);\n if (css) {\n this.collectProperty(`__prop:${token}`, css);\n }\n }\n\n const tokenStyles = getGlobalConfigTokens();\n if (tokenStyles && Object.keys(tokenStyles).length > 0) {\n const tokenRules = renderStyles(tokenStyles, ':root') as StyleResult[];\n if (tokenRules.length > 0) {\n const css = formatGlobalRules(tokenRules);\n if (css) {\n this.collectGlobalStyles('__global:tokens', css);\n }\n }\n }\n\n const globalFF = getGlobalFontFace();\n if (globalFF) {\n for (const [family, input] of Object.entries(globalFF)) {\n const descriptors = Array.isArray(input) ? input : [input];\n for (const desc of descriptors) {\n const hash = fontFaceContentHash(family, desc);\n const css = formatFontFaceRule(family, desc);\n this.collectFontFace(hash, css);\n }\n }\n }\n\n const globalCS = getGlobalCounterStyle();\n if (globalCS) {\n for (const [name, descriptors] of Object.entries(globalCS)) {\n const css = formatCounterStyleRule(name, descriptors);\n this.collectCounterStyle(name, css);\n }\n }\n\n const globalStyles = getGlobalStyles();\n if (globalStyles) {\n for (const [selector, styles] of Object.entries(globalStyles)) {\n if (Object.keys(styles).length > 0) {\n const rules = renderStyles(styles, selector) as StyleResult[];\n if (rules.length > 0) {\n const css = formatGlobalRules(rules);\n if (css) {\n this.collectGlobalStyles(`__global:styles:${selector}`, css);\n }\n }\n }\n }\n }\n }\n\n /**\n * Allocate a className for a cache key, server-side.\n * Mirrors StyleInjector.allocateClassName but without DOM access.\n */\n allocateClassName(cacheKey: string): {\n className: string;\n isNewAllocation: boolean;\n } {\n const existing = this.cacheKeyToClassName.get(cacheKey);\n if (existing) {\n return { className: existing, isNewAllocation: false };\n }\n\n const className = generateClassName(cacheKey);\n this.cacheKeyToClassName.set(cacheKey, className);\n\n return { className, isNewAllocation: true };\n }\n\n /**\n * Record CSS rules for a chunk.\n * Called by useStyles during server render.\n */\n collectChunk(\n cacheKey: string,\n className: string,\n rules: StyleResult[],\n ): void {\n if (this.chunks.has(cacheKey)) return;\n const css = formatRules(rules, className);\n if (css) {\n this.chunks.set(cacheKey, css);\n }\n }\n\n /**\n * Record a @property rule. Deduplicated by name.\n */\n collectProperty(name: string, css: string): void {\n if (!this.propertyRules.has(name)) {\n this.propertyRules.set(name, css);\n }\n }\n\n /**\n * Record a @keyframes rule. Deduplicated by name.\n */\n collectKeyframes(name: string, css: string): void {\n if (!this.keyframeRules.has(name)) {\n this.keyframeRules.set(name, css);\n }\n }\n\n /**\n * Allocate a keyframe name for SSR. Uses provided name or generates one.\n */\n allocateKeyframeName(providedName?: string): string {\n return providedName ?? `k${this.keyframesCounter++}`;\n }\n\n /**\n * Record a @font-face rule. Deduplicated by key (content hash).\n */\n collectFontFace(key: string, css: string): void {\n if (!this.fontFaceRules.has(key)) {\n this.fontFaceRules.set(key, css);\n }\n }\n\n /**\n * Record a @counter-style rule. Deduplicated by name.\n */\n collectCounterStyle(name: string, css: string): void {\n if (!this.counterStyleRules.has(name)) {\n this.counterStyleRules.set(name, css);\n }\n }\n\n /**\n * Allocate a counter-style name for SSR. Uses provided name or generates one.\n */\n allocateCounterStyleName(providedName?: string): string {\n return providedName ?? `cs${this.counterStyleCounter++}`;\n }\n\n /**\n * Record global styles (from useGlobalStyles). Deduplicated by key.\n */\n collectGlobalStyles(key: string, css: string): void {\n if (!this.globalStyles.has(key)) {\n this.globalStyles.set(key, css);\n }\n }\n\n /**\n * Record raw CSS text (from useRawCSS). Deduplicated by key.\n */\n collectRawCSS(key: string, css: string): void {\n if (!this.rawCSS.has(key)) {\n this.rawCSS.set(key, css);\n }\n }\n\n /**\n * Extract all CSS collected so far as a single string.\n * Includes @property and @keyframes rules.\n * Used for non-streaming SSR (renderToString).\n */\n getCSS(): string {\n const parts: string[] = [];\n\n for (const css of this.propertyRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.fontFaceRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.counterStyleRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.rawCSS.values()) {\n parts.push(css);\n }\n\n for (const css of this.globalStyles.values()) {\n parts.push(css);\n }\n\n for (const css of this.chunks.values()) {\n parts.push(css);\n }\n\n for (const css of this.keyframeRules.values()) {\n parts.push(css);\n }\n\n return parts.join('\\n');\n }\n\n /**\n * Flush only newly collected CSS since the last flush.\n * Used for streaming SSR (renderToPipeableStream + useServerInsertedHTML).\n */\n flushCSS(): string {\n const parts: string[] = [];\n\n for (const [name, css] of this.propertyRules) {\n if (!this.flushedPropertyKeys.has(name)) {\n parts.push(css);\n this.flushedPropertyKeys.add(name);\n }\n }\n\n for (const [key, css] of this.fontFaceRules) {\n if (!this.flushedFontFaceKeys.has(key)) {\n parts.push(css);\n this.flushedFontFaceKeys.add(key);\n }\n }\n\n for (const [key, css] of this.counterStyleRules) {\n if (!this.flushedCounterStyleKeys.has(key)) {\n parts.push(css);\n this.flushedCounterStyleKeys.add(key);\n }\n }\n\n for (const [key, css] of this.rawCSS) {\n if (!this.flushedRawKeys.has(key)) {\n parts.push(css);\n this.flushedRawKeys.add(key);\n }\n }\n\n for (const [key, css] of this.globalStyles) {\n if (!this.flushedGlobalKeys.has(key)) {\n parts.push(css);\n this.flushedGlobalKeys.add(key);\n }\n }\n\n for (const [key, css] of this.chunks) {\n if (!this.flushedKeys.has(key)) {\n parts.push(css);\n this.flushedKeys.add(key);\n }\n }\n\n for (const [name, css] of this.keyframeRules) {\n if (!this.flushedKeyframeKeys.has(name)) {\n parts.push(css);\n this.flushedKeyframeKeys.add(name);\n }\n }\n\n return parts.join('\\n');\n }\n\n private flushedClassNames = new Set<string>();\n\n /**\n * Return class names rendered since the last call (for streaming).\n * Used to emit lightweight class-list scripts for client hydration.\n */\n getRenderedClassNames(): string[] {\n const names: string[] = [];\n for (const className of this.cacheKeyToClassName.values()) {\n if (!this.flushedClassNames.has(className)) {\n this.flushedClassNames.add(className);\n names.push(className);\n }\n }\n return names;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4BA,SAAS,kBAAkB,UAA0B;AACnD,QAAO,IAAI,WAAW,SAAS;;AAGjC,IAAa,uBAAb,MAAkC;CAChC,yBAAiB,IAAI,KAAqB;CAC1C,sCAA8B,IAAI,KAAqB;CACvD,8BAAsB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|
|
6
|
+
* Used by Next.js TastyRegistry to provide the ServerStyleCollector
|
|
7
|
+
* to useStyles() via React context (the streaming-compatible path).
|
|
8
|
+
*
|
|
9
|
+
* This avoids relying on globalThis for cross-layer communication,
|
|
10
|
+
* which leaks between RSC and SSR module graphs in Next.js App Router.
|
|
11
|
+
*/
|
|
12
|
+
const TastySSRContext = createContext(null);
|
|
13
|
+
//#endregion
|
|
14
|
+
export { TastySSRContext };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../../src/ssr/context.ts"],"sourcesContent":["/**\n * React context for SSR collector discovery.\n *\n * Used by Next.js TastyRegistry to provide the ServerStyleCollector\n * to useStyles() via React context (the streaming-compatible path).\n *\n * This avoids relying on globalThis for cross-layer communication,\n * which leaks between RSC and SSR module graphs in Next.js App Router.\n */\n\nimport { createContext } from 'react';\n\nimport type { ServerStyleCollector } from './collector';\n\nexport const TastySSRContext = createContext<ServerStyleCollector | null>(null);\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,kBAAkB,cAA2C,KAAK"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/ssr/format-global-rules.ts
|
|
2
|
+
/**
|
|
3
|
+
* Format an array of global StyleResult rules into a CSS text string.
|
|
4
|
+
*
|
|
5
|
+
* Rules already have their full selectors applied by renderStyles().
|
|
6
|
+
* Handles rootPrefix prepending and at-rule wrapping.
|
|
7
|
+
*/
|
|
8
|
+
function formatGlobalRules(rules) {
|
|
9
|
+
if (rules.length === 0) return "";
|
|
10
|
+
const cssRules = [];
|
|
11
|
+
for (const rule of rules) {
|
|
12
|
+
const baseRule = `${rule.rootPrefix ? `${rule.rootPrefix} ${rule.selector}` : rule.selector} { ${rule.declarations} }`;
|
|
13
|
+
let fullRule = baseRule;
|
|
14
|
+
if (rule.atRules && rule.atRules.length > 0) fullRule = rule.atRules.reduce((css, atRule) => `${atRule} { ${css} }`, baseRule);
|
|
15
|
+
cssRules.push(fullRule);
|
|
16
|
+
}
|
|
17
|
+
return cssRules.join("\n");
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { formatGlobalRules };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=format-global-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-global-rules.js","names":[],"sources":["../../src/ssr/format-global-rules.ts"],"sourcesContent":["/**\n * Format global CSS rules for SSR output.\n *\n * Unlike formatRules() which applies className-based specificity doubling,\n * this function formats rules that already have their full selectors\n * (from renderStyles called with a selector string).\n */\n\nimport type { StyleResult } from '../pipeline';\n\n/**\n * Format an array of global StyleResult rules into a CSS text string.\n *\n * Rules already have their full selectors applied by renderStyles().\n * Handles rootPrefix prepending and at-rule wrapping.\n */\nexport function formatGlobalRules(rules: StyleResult[]): string {\n if (rules.length === 0) return '';\n\n const cssRules: string[] = [];\n\n for (const rule of rules) {\n const selector = rule.rootPrefix\n ? `${rule.rootPrefix} ${rule.selector}`\n : rule.selector;\n\n const baseRule = `${selector} { ${rule.declarations} }`;\n\n let fullRule = baseRule;\n if (rule.atRules && rule.atRules.length > 0) {\n fullRule = rule.atRules.reduce(\n (css, atRule) => `${atRule} { ${css} }`,\n baseRule,\n );\n }\n\n cssRules.push(fullRule);\n }\n\n return cssRules.join('\\n');\n}\n"],"mappings":";;;;;;;AAgBA,SAAgB,kBAAkB,OAA8B;AAC9D,KAAI,MAAM,WAAW,EAAG,QAAO;CAE/B,MAAM,WAAqB,EAAE;AAE7B,MAAK,MAAM,QAAQ,OAAO;EAKxB,MAAM,WAAW,GAJA,KAAK,aAClB,GAAG,KAAK,WAAW,GAAG,KAAK,aAC3B,KAAK,SAEoB,KAAK,KAAK,aAAa;EAEpD,IAAI,WAAW;AACf,MAAI,KAAK,WAAW,KAAK,QAAQ,SAAS,EACxC,YAAW,KAAK,QAAQ,QACrB,KAAK,WAAW,GAAG,OAAO,KAAK,IAAI,KACpC,SACD;AAGH,WAAS,KAAK,SAAS;;AAGzB,QAAO,SAAS,KAAK,KAAK"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createStyle } from "../styles/createStyle.js";
|
|
2
|
+
import { STYLE_HANDLER_MAP } from "../styles/index.js";
|
|
3
|
+
//#region src/ssr/format-keyframes.ts
|
|
4
|
+
/**
|
|
5
|
+
* Convert keyframes steps to a CSS string.
|
|
6
|
+
* Replicates SheetManager.stepsToCSS() without the class instance.
|
|
7
|
+
*/
|
|
8
|
+
function stepsToCSS(steps) {
|
|
9
|
+
const rules = [];
|
|
10
|
+
for (const [key, value] of Object.entries(steps)) {
|
|
11
|
+
if (typeof value === "string") {
|
|
12
|
+
rules.push(`${key} { ${value.trim()} }`);
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const styleMap = value || {};
|
|
16
|
+
const styleNames = Object.keys(styleMap).sort();
|
|
17
|
+
const handlerQueue = [];
|
|
18
|
+
const seenHandlers = /* @__PURE__ */ new Set();
|
|
19
|
+
styleNames.forEach((styleName) => {
|
|
20
|
+
let handlers = STYLE_HANDLER_MAP[styleName];
|
|
21
|
+
if (!handlers) handlers = STYLE_HANDLER_MAP[styleName] = [createStyle(styleName)];
|
|
22
|
+
handlers.forEach((handler) => {
|
|
23
|
+
if (!seenHandlers.has(handler)) {
|
|
24
|
+
seenHandlers.add(handler);
|
|
25
|
+
handlerQueue.push(handler);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
const declarationPairs = [];
|
|
30
|
+
handlerQueue.forEach((handler) => {
|
|
31
|
+
const result = handler(handler.__lookupStyles.reduce((acc, name) => {
|
|
32
|
+
const v = styleMap[name];
|
|
33
|
+
if (v !== void 0) acc[name] = v;
|
|
34
|
+
return acc;
|
|
35
|
+
}, {}));
|
|
36
|
+
if (!result) return;
|
|
37
|
+
(Array.isArray(result) ? result : [result]).forEach((cssMap) => {
|
|
38
|
+
if (!cssMap || typeof cssMap !== "object") return;
|
|
39
|
+
const { $: _$, ...props } = cssMap;
|
|
40
|
+
Object.entries(props).forEach(([prop, val]) => {
|
|
41
|
+
if (val == null || val === "") return;
|
|
42
|
+
if (Array.isArray(val)) val.forEach((v) => {
|
|
43
|
+
if (v != null && v !== "") declarationPairs.push({
|
|
44
|
+
prop,
|
|
45
|
+
value: String(v)
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
else declarationPairs.push({
|
|
49
|
+
prop,
|
|
50
|
+
value: String(val)
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
const declarations = declarationPairs.map((d) => `${d.prop}: ${d.value}`).join("; ");
|
|
56
|
+
rules.push(`${key} { ${declarations.trim()} }`);
|
|
57
|
+
}
|
|
58
|
+
return rules.join(" ");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Format a @keyframes rule as a CSS string.
|
|
62
|
+
*/
|
|
63
|
+
function formatKeyframesCSS(name, steps) {
|
|
64
|
+
return `@keyframes ${name} { ${stepsToCSS(steps)} }`;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { formatKeyframesCSS };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=format-keyframes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-keyframes.js","names":[],"sources":["../../src/ssr/format-keyframes.ts"],"sourcesContent":["/**\n * Format @keyframes CSS rules for SSR output.\n *\n * Replicates the stepsToCSS logic from SheetManager but as a\n * standalone function that doesn't need DOM access.\n */\n\nimport type { KeyframesSteps } from '../injector/types';\nimport { createStyle, STYLE_HANDLER_MAP } from '../styles';\nimport type { CSSMap, StyleHandler, StyleValueStateMap } from '../utils/styles';\n\n/**\n * Convert keyframes steps to a CSS string.\n * Replicates SheetManager.stepsToCSS() without the class instance.\n */\nfunction stepsToCSS(steps: KeyframesSteps): string {\n const rules: string[] = [];\n\n for (const [key, value] of Object.entries(steps)) {\n if (typeof value === 'string') {\n rules.push(`${key} { ${value.trim()} }`);\n continue;\n }\n\n const styleMap = (value || {}) as StyleValueStateMap;\n const styleNames = Object.keys(styleMap).sort();\n const handlerQueue: StyleHandler[] = [];\n const seenHandlers = new Set<StyleHandler>();\n\n styleNames.forEach((styleName) => {\n let handlers = STYLE_HANDLER_MAP[styleName];\n if (!handlers) {\n handlers = STYLE_HANDLER_MAP[styleName] = [createStyle(styleName)];\n }\n\n handlers.forEach((handler) => {\n if (!seenHandlers.has(handler)) {\n seenHandlers.add(handler);\n handlerQueue.push(handler);\n }\n });\n });\n\n const declarationPairs: { prop: string; value: string }[] = [];\n\n handlerQueue.forEach((handler) => {\n const lookup = handler.__lookupStyles;\n const filteredMap = lookup.reduce<StyleValueStateMap>((acc, name) => {\n const v = styleMap[name];\n if (v !== undefined) acc[name] = v;\n return acc;\n }, {});\n\n const result = handler(filteredMap);\n if (!result) return;\n\n const results = Array.isArray(result) ? result : [result];\n results.forEach((cssMap) => {\n if (!cssMap || typeof cssMap !== 'object') return;\n const { $: _$, ...props } = cssMap as CSSMap;\n\n Object.entries(props).forEach(([prop, val]) => {\n if (val == null || val === '') return;\n\n if (Array.isArray(val)) {\n val.forEach((v) => {\n if (v != null && v !== '') {\n declarationPairs.push({ prop, value: String(v) });\n }\n });\n } else {\n declarationPairs.push({ prop, value: String(val) });\n }\n });\n });\n });\n\n const declarations = declarationPairs\n .map((d) => `${d.prop}: ${d.value}`)\n .join('; ');\n\n rules.push(`${key} { ${declarations.trim()} }`);\n }\n\n return rules.join(' ');\n}\n\n/**\n * Format a @keyframes rule as a CSS string.\n */\nexport function formatKeyframesCSS(\n name: string,\n steps: KeyframesSteps,\n): string {\n const cssSteps = stepsToCSS(steps);\n return `@keyframes ${name} { ${cssSteps} }`;\n}\n"],"mappings":";;;;;;;AAeA,SAAS,WAAW,OAA+B;CACjD,MAAM,QAAkB,EAAE;AAE1B,MAAK,MAAM,CAAC,KAAK,UAAU,O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AErD;KACF;IACF;EAEF,MAAM,eAAe,iBAClB,KAAK,MAAM,GAAG,EAAE,KAAK,IAAI,EAAE,QAAQ,CACnC,KAAK,KAAK;AAEb,QAAM,KAAK,GAAG,IAAI,KAAK,aAAa,MAAM,CAAC,IAAI;;AAGjD,QAAO,MAAM,KAAK,IAAI;;;;;AAMxB,SAAgB,mBACd,MACA,OACQ;AAER,QAAO,cAAc,KAAK,KADT,WAAW,MAAM,CACM"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { colorInitialValueToComponents, getColorSpaceSuffix, getComponentPropertySyntax } from "../utils/color-space.js";
|
|
2
|
+
import { getEffectiveDefinition } from "../properties/index.js";
|
|
3
|
+
import { parseStyle } from "../utils/styles.js";
|
|
4
|
+
//#region src/ssr/format-property.ts
|
|
5
|
+
/**
|
|
6
|
+
* Format a single @property rule as a CSS string.
|
|
7
|
+
*
|
|
8
|
+
* Returns the full `@property --name { ... }` text, or empty string
|
|
9
|
+
* if the token is invalid. For color properties, also returns
|
|
10
|
+
* the companion component property.
|
|
11
|
+
*/
|
|
12
|
+
function formatPropertyCSS(token, definition) {
|
|
13
|
+
const result = getEffectiveDefinition(token, definition);
|
|
14
|
+
if (!result.isValid) return "";
|
|
15
|
+
const rules = [];
|
|
16
|
+
rules.push(buildPropertyRule(result.cssName, result.definition));
|
|
17
|
+
if (result.isColor) {
|
|
18
|
+
const suffix = getColorSpaceSuffix();
|
|
19
|
+
const componentCssName = `${result.cssName}-${suffix}`;
|
|
20
|
+
const componentInitial = colorInitialValueToComponents(result.definition.initialValue);
|
|
21
|
+
rules.push(buildPropertyRule(componentCssName, {
|
|
22
|
+
syntax: getComponentPropertySyntax(),
|
|
23
|
+
inherits: result.definition.inherits,
|
|
24
|
+
initialValue: componentInitial
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
return rules.join("\n");
|
|
28
|
+
}
|
|
29
|
+
function buildPropertyRule(cssName, definition) {
|
|
30
|
+
const parts = [];
|
|
31
|
+
if (definition.syntax != null) {
|
|
32
|
+
let syntax = String(definition.syntax).trim();
|
|
33
|
+
if (!/^['"]/u.test(syntax)) syntax = `"${syntax}"`;
|
|
34
|
+
parts.push(`syntax: ${syntax};`);
|
|
35
|
+
}
|
|
36
|
+
const inherits = definition.inherits ?? true;
|
|
37
|
+
parts.push(`inherits: ${inherits ? "true" : "false"};`);
|
|
38
|
+
if (definition.initialValue != null) {
|
|
39
|
+
let initialValueStr;
|
|
40
|
+
if (typeof definition.initialValue === "number") initialValueStr = String(definition.initialValue);
|
|
41
|
+
else initialValueStr = parseStyle(definition.initialValue).output;
|
|
42
|
+
parts.push(`initial-value: ${initialValueStr};`);
|
|
43
|
+
}
|
|
44
|
+
return `@property ${cssName} { ${parts.join(" ").trim()} }`;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { formatPropertyCSS };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=format-property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-property.js","names":[],"sources":["../../src/ssr/format-property.ts"],"sourcesContent":["/**\n * Format @property CSS rules for SSR output.\n *\n * Replicates the CSS construction from StyleInjector.property()\n * but returns a CSS string instead of inserting into the DOM.\n */\n\nimport type { PropertyDefinition } from '../injector/types';\nimport { getEffectiveDefinition } from '../properties';\nimport {\n colorInitialValueToComponents,\n getColorSpaceSuffix,\n getComponentPropertySyntax,\n} from '../utils/color-space';\nimport type { StyleValue } from '../utils/styles';\nimport { parseStyle } from '../utils/styles';\n\n/**\n * Format a single @property rule as a CSS string.\n *\n * Returns the full `@property --name { ... }` text, or empty string\n * if the token is invalid. For color properties, also returns\n * the companion component property.\n */\nexport function formatPropertyCSS(\n token: string,\n definition: PropertyDefinition,\n): string {\n const result = getEffectiveDefinition(token, definition);\n if (!result.isValid) return '';\n\n const rules: string[] = [];\n\n rules.push(buildPropertyRule(result.cssName, result.definition));\n\n if (result.isColor) {\n const suffix = getColorSpaceSuffix();\n const componentCssName = `${result.cssName}-${suffix}`;\n const componentInitial = colorInitialValueToComponents(\n result.definition.initialValue,\n );\n rules.push(\n buildPropertyRule(componentCssName, {\n syntax: getComponentPropertySyntax(),\n inherits: result.definition.inherits,\n initialValue: componentInitial,\n }),\n );\n }\n\n return rules.join('\\n');\n}\n\nfunction buildPropertyRule(\n cssName: string,\n definition: PropertyDefinition,\n): string {\n const parts: string[] = [];\n\n if (definition.syntax != null) {\n let syntax = String(definition.syntax).trim();\n if (!/^['\"]/u.test(syntax)) syntax = `\"${syntax}\"`;\n parts.push(`syntax: ${syntax};`);\n }\n\n const inherits = definition.inherits ?? true;\n parts.push(`inherits: ${inherits ? 'true' : 'false'};`);\n\n if (definition.initialValue != null) {\n let initialValueStr: string;\n if (typeof definition.initialValue === 'number') {\n initialValueStr = String(definition.initialValue);\n } else {\n initialValueStr = parseStyle(\n definition.initialValue as StyleValue,\n ).output;\n }\n parts.push(`initial-value: ${initialValueStr};`);\n }\n\n const declarations = parts.join(' ').trim();\n return `@property ${cssName} { ${declarations} }`;\n}\n"],"mappings":";;;;;;;;;;;AAwBA,SAAgB,kBACd,OACA,YACQ;CACR,MAAM,SAAS,uBAAuB,OAAO,WAAW;AACxD,KAAI,CAAC,OAAO,QAAS,QAAO;CAE5B,MAAM,QAAkB,EAAE;AAE1B,OAAM,KAAK,kBAAkB,OAAO,SAAS,OAAO,WAAW,CAAC;AAEhE,KAAI,OAAO,SAAS;EAClB,MAAM,SAAS,qBAAqB;EACpC,MAAM,mBAAmB,GAAG,OAAO,QAAQ,GAAG;EAC9C,MAAM,mBAAmB,8BACvB,OAAO,WAAW,aACnB;AACD,QAAM,KACJ,kBAAkB,kBAAkB;GAClC,QAAQ,4BAA4B;GACpC,UAAU,OAAO,WAAW;GAC5B,cAAc;GACf,CAAC,CACH;;AAGH,QAAO,MAAM,KAAK,KAAK;;AAGzB,SAAS,kBACP,SACA,YACQ;CACR,MAAM,QAAkB,EAAE;AAE1B,KAAI,WAAW,UAAU,MAAM;EAC7B,IAAI,SAAS,OAAO,WAAW,OAAO,CAAC,MAAM;AAC7C,MAAI,CAAC,SAAS,KAAK,OAAO,CAAE,UAAS,IAAI,OAAO;AAChD,QAAM,KAAK,WAAW,OAAO,GAAG;;CAGlC,MAAM,WAAW,WAAW,YAAY;AACxC,OAAM,KAAK,aAAa,WAAW,SAAS,QAAQ,GAAG;AAEvD,KAAI,WAAW,gBAAgB,MAAM;EACnC,IAAI;AACJ,MAAI,OAAO,WAAW,iBAAiB,SACrC,mBAAkB,OAAO,WAAW,aAAa;MAEjD,mBAAkB,WAChB,WAAW,aACZ,CAAC;AAEJ,QAAM,KAAK,kBAAkB,gBAAgB,GAAG;;AAIlD,QAAO,aAAa,QAAQ,KADP,MAAM,KAAK,IAAI,CAAC,MAAM,CACG"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//#region src/ssr/format-rules.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolve selectors for a rule, applying className-based specificity doubling
|
|
4
|
+
* and rootPrefix handling. Mirrors the logic in StyleInjector.inject().
|
|
5
|
+
*/
|
|
6
|
+
function resolveSelector(rule, className) {
|
|
7
|
+
let selector = rule.selector;
|
|
8
|
+
if (rule.needsClassName) {
|
|
9
|
+
const selectorParts = selector ? selector.split("|||") : [""];
|
|
10
|
+
const classPrefix = `.${className}.${className}`;
|
|
11
|
+
selector = selectorParts.map((part) => {
|
|
12
|
+
const classSelector = part ? `${classPrefix}${part}` : classPrefix;
|
|
13
|
+
if (rule.rootPrefix) return `${rule.rootPrefix} ${classSelector}`;
|
|
14
|
+
return classSelector;
|
|
15
|
+
}).join(", ");
|
|
16
|
+
}
|
|
17
|
+
return selector;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Group rules by selector + at-rules + startingStyle and merge their declarations.
|
|
21
|
+
* Mirrors the grouping logic in SheetManager.insertRule().
|
|
22
|
+
*/
|
|
23
|
+
function groupRules(rules) {
|
|
24
|
+
const groupMap = /* @__PURE__ */ new Map();
|
|
25
|
+
const order = [];
|
|
26
|
+
const atKey = (at) => at && at.length ? at.join("|") : "";
|
|
27
|
+
for (const r of rules) {
|
|
28
|
+
const key = `${atKey(r.atRules)}||${r.selector}||${r.startingStyle ? "1" : "0"}`;
|
|
29
|
+
const existing = groupMap.get(key);
|
|
30
|
+
if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${r.declarations}` : r.declarations;
|
|
31
|
+
else {
|
|
32
|
+
groupMap.set(key, {
|
|
33
|
+
selector: r.selector,
|
|
34
|
+
atRules: r.atRules,
|
|
35
|
+
startingStyle: r.startingStyle,
|
|
36
|
+
declarations: r.declarations
|
|
37
|
+
});
|
|
38
|
+
order.push(key);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return order.map((key) => groupMap.get(key));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Format an array of StyleResult rules into a CSS text string.
|
|
45
|
+
*
|
|
46
|
+
* Applies className-based specificity doubling (.cls.cls),
|
|
47
|
+
* groups rules by selector + at-rules, and wraps with at-rule blocks.
|
|
48
|
+
*
|
|
49
|
+
* Produces the same CSS text as SheetManager.insertRule() would insert
|
|
50
|
+
* into the DOM, but as a plain string suitable for SSR output.
|
|
51
|
+
*/
|
|
52
|
+
function formatRules(rules, className) {
|
|
53
|
+
if (rules.length === 0) return "";
|
|
54
|
+
const grouped = groupRules(rules.map((rule) => ({
|
|
55
|
+
selector: resolveSelector(rule, className),
|
|
56
|
+
declarations: rule.declarations,
|
|
57
|
+
atRules: rule.atRules,
|
|
58
|
+
startingStyle: rule.startingStyle
|
|
59
|
+
})));
|
|
60
|
+
const cssRules = [];
|
|
61
|
+
for (const rule of grouped) {
|
|
62
|
+
const innerContent = rule.startingStyle ? `@starting-style { ${rule.declarations} }` : rule.declarations;
|
|
63
|
+
const baseRule = `${rule.selector} { ${innerContent} }`;
|
|
64
|
+
let fullRule = baseRule;
|
|
65
|
+
if (rule.atRules && rule.atRules.length > 0) fullRule = rule.atRules.reduce((css, atRule) => `${atRule} { ${css} }`, baseRule);
|
|
66
|
+
cssRules.push(fullRule);
|
|
67
|
+
}
|
|
68
|
+
return cssRules.join("\n");
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { formatRules };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=format-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-rules.js","names":[],"sources":["../../src/ssr/format-rules.ts"],"sourcesContent":["/**\n * Shared CSS rule formatting utility.\n *\n * Extracted from SheetManager to allow both the DOM-based injector (client)\n * and the ServerStyleCollector (server) to produce identical CSS text\n * from StyleResult arrays.\n */\n\nimport type { StyleResult } from '../pipeline';\n\n/**\n * Resolve selectors for a rule, applying className-based specificity doubling\n * and rootPrefix handling. Mirrors the logic in StyleInjector.inject().\n */\nfunction resolveSelector(rule: StyleResult, className: string): string {\n let selector = rule.selector;\n\n if (rule.needsClassName) {\n const selectorParts = selector ? selector.split('|||') : [''];\n const classPrefix = `.${className}.${className}`;\n\n selector = selectorParts\n .map((part) => {\n const classSelector = part ? `${classPrefix}${part}` : classPrefix;\n\n if (rule.rootPrefix) {\n return `${rule.rootPrefix} ${classSelector}`;\n }\n return classSelector;\n })\n .join(', ');\n }\n\n return selector;\n}\n\ninterface GroupedRule {\n selector: string;\n declarations: string;\n atRules?: string[];\n startingStyle?: boolean;\n}\n\n/**\n * Group rules by selector + at-rules + startingStyle and merge their declarations.\n * Mirrors the grouping logic in SheetManager.insertRule().\n */\nfunction groupRules(rules: GroupedRule[]): GroupedRule[] {\n const groupMap = new Map<string, GroupedRule>();\n const order: string[] = [];\n\n const atKey = (at?: string[]) => (at && at.length ? at.join('|') : '');\n\n for (const r of rules) {\n const key = `${atKey(r.atRules)}||${r.selector}||${r.startingStyle ? '1' : '0'}`;\n const existing = groupMap.get(key);\n if (existing) {\n existing.declarations = existing.declarations\n ? `${existing.declarations} ${r.declarations}`\n : r.declarations;\n } else {\n groupMap.set(key, {\n selector: r.selector,\n atRules: r.atRules,\n startingStyle: r.startingStyle,\n declarations: r.declarations,\n });\n order.push(key);\n }\n }\n\n return order.map((key) => groupMap.get(key)!);\n}\n\n/**\n * Format an array of StyleResult rules into a CSS text string.\n *\n * Applies className-based specificity doubling (.cls.cls),\n * groups rules by selector + at-rules, and wraps with at-rule blocks.\n *\n * Produces the same CSS text as SheetManager.insertRule() would insert\n * into the DOM, but as a plain string suitable for SSR output.\n */\nexport function formatRules(rules: StyleResult[], className: string): string {\n if (rules.length === 0) return '';\n\n const resolvedRules = rules.map((rule) => ({\n selector: resolveSelector(rule, className),\n declarations: rule.declarations,\n atRules: rule.atRules,\n startingStyle: rule.startingStyle,\n }));\n\n const grouped = groupRules(resolvedRules);\n const cssRules: string[] = [];\n\n for (const rule of grouped) {\n const innerContent = rule.startingStyle\n ? `@starting-style { ${rule.declarations} }`\n : rule.declarations;\n const baseRule = `${rule.selector} { ${innerContent} }`;\n\n let fullRule = baseRule;\n if (rule.atRules && rule.atRules.length > 0) {\n fullRule = rule.atRules.reduce(\n (css, atRule) => `${atRule} { ${css} }`,\n baseRule,\n );\n }\n\n cssRules.push(fullRule);\n }\n\n return cssRules.join('\\n');\n}\n"],"mappings":";;;;;AAcA,SAAS,gBAAgB,MAAmB,WAA2B;CACrE,IAAI,WAAW,KAAK;AAEpB,KAAI,KAAK,gBAAgB;EACvB,MAAM,gBAAgB,WAAW,SAAS,MAAM,MAAM,GAAG,CAAC,GAAG;EAC7D,MAAM,cAAc,IAAI,UAAU,GAAG;AAErC,aAAW,cACR,KAAK,SAAS;GACb,MAAM,gBAAgB,OAAO,GAAG,cAAc,SAAS;AAEvD,OAAI,KAAK,WACP,QAAO,GAAG,KAAK,WAAW,GAAG;AAE/B,UAAO;IACP,CACD,KAAK,KAAK;;AAGf,QAAO;;;;;;AAcT,SAAS,WAAW,OAAqC;CACvD,MAAM,2BAAW,IAAI,KAA0B;CAC/C,MAAM,QAAkB,EAAE;CAE1B,MA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