@tenphi/tasty 0.0.0-snapshot.056b911
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/LICENSE +21 -0
- package/README.md +635 -0
- package/dist/_virtual/_rolldown/runtime.js +7 -0
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +77 -0
- package/dist/chunks/cacheKey.js.map +1 -0
- package/dist/chunks/definitions.d.ts +37 -0
- package/dist/chunks/definitions.js +258 -0
- package/dist/chunks/definitions.js.map +1 -0
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +59 -0
- package/dist/chunks/renderChunk.js.map +1 -0
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +335 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +409 -0
- package/dist/config.js +584 -0
- package/dist/config.js.map +1 -0
- package/dist/core/index.d.ts +34 -0
- package/dist/core/index.js +27 -0
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +89 -0
- package/dist/debug.js +453 -0
- package/dist/debug.js.map +1 -0
- 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 +64 -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 +46 -0
- package/dist/hooks/useGlobalStyles.js +88 -0
- package/dist/hooks/useGlobalStyles.js.map +1 -0
- package/dist/hooks/useKeyframes.d.ts +58 -0
- package/dist/hooks/useKeyframes.js +54 -0
- package/dist/hooks/useKeyframes.js.map +1 -0
- package/dist/hooks/useProperty.d.ts +81 -0
- package/dist/hooks/useProperty.js +96 -0
- package/dist/hooks/useProperty.js.map +1 -0
- package/dist/hooks/useRawCSS.d.ts +22 -0
- package/dist/hooks/useRawCSS.js +103 -0
- package/dist/hooks/useRawCSS.js.map +1 -0
- package/dist/hooks/useStyles.d.ts +40 -0
- package/dist/hooks/useStyles.js +31 -0
- package/dist/hooks/useStyles.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +36 -0
- package/dist/injector/index.d.ts +182 -0
- package/dist/injector/index.js +185 -0
- package/dist/injector/index.js.map +1 -0
- package/dist/injector/injector.d.ts +193 -0
- package/dist/injector/injector.js +564 -0
- package/dist/injector/injector.js.map +1 -0
- package/dist/injector/sheet-manager.d.ts +132 -0
- package/dist/injector/sheet-manager.js +698 -0
- package/dist/injector/sheet-manager.js.map +1 -0
- package/dist/injector/types.d.ts +228 -0
- package/dist/keyframes/index.js +206 -0
- package/dist/keyframes/index.js.map +1 -0
- package/dist/parser/classify.js +319 -0
- package/dist/parser/classify.js.map +1 -0
- package/dist/parser/const.js +60 -0
- package/dist/parser/const.js.map +1 -0
- package/dist/parser/lru.js +109 -0
- package/dist/parser/lru.js.map +1 -0
- package/dist/parser/parser.d.ts +25 -0
- package/dist/parser/parser.js +115 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/tokenizer.js +69 -0
- package/dist/parser/tokenizer.js.map +1 -0
- package/dist/parser/types.d.ts +51 -0
- package/dist/parser/types.js +46 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/pipeline/conditions.d.ts +134 -0
- package/dist/pipeline/conditions.js +406 -0
- package/dist/pipeline/conditions.js.map +1 -0
- package/dist/pipeline/exclusive.js +230 -0
- package/dist/pipeline/exclusive.js.map +1 -0
- package/dist/pipeline/index.d.ts +55 -0
- package/dist/pipeline/index.js +708 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/materialize.js +1103 -0
- package/dist/pipeline/materialize.js.map +1 -0
- package/dist/pipeline/parseStateKey.d.ts +15 -0
- package/dist/pipeline/parseStateKey.js +446 -0
- package/dist/pipeline/parseStateKey.js.map +1 -0
- package/dist/pipeline/simplify.js +515 -0
- package/dist/pipeline/simplify.js.map +1 -0
- package/dist/pipeline/warnings.js +18 -0
- package/dist/pipeline/warnings.js.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.d.ts +35 -0
- package/dist/plugins/okhsl-plugin.js +97 -0
- package/dist/plugins/okhsl-plugin.js.map +1 -0
- package/dist/plugins/types.d.ts +87 -0
- package/dist/properties/index.js +222 -0
- package/dist/properties/index.js.map +1 -0
- package/dist/properties/property-type-resolver.d.ts +24 -0
- package/dist/properties/property-type-resolver.js +90 -0
- package/dist/properties/property-type-resolver.js.map +1 -0
- package/dist/rsc-cache.js +81 -0
- package/dist/rsc-cache.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +24 -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 +106 -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 +102 -0
- package/dist/ssr/collector.js +227 -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 +22 -0
- package/dist/ssr/hydrate.js +49 -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 +45 -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.d.ts +49 -0
- package/dist/states/index.js +170 -0
- package/dist/states/index.js.map +1 -0
- package/dist/static/index.d.ts +5 -0
- package/dist/static/index.js +4 -0
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/static/tastyStatic.d.ts +46 -0
- package/dist/static/tastyStatic.js +30 -0
- package/dist/static/tastyStatic.js.map +1 -0
- package/dist/static/types.d.ts +49 -0
- package/dist/static/types.js +24 -0
- package/dist/static/types.js.map +1 -0
- package/dist/styles/border.d.ts +25 -0
- package/dist/styles/border.js +120 -0
- package/dist/styles/border.js.map +1 -0
- package/dist/styles/color.d.ts +14 -0
- package/dist/styles/color.js +26 -0
- package/dist/styles/color.js.map +1 -0
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +79 -0
- package/dist/styles/createStyle.js.map +1 -0
- package/dist/styles/dimension.js +109 -0
- package/dist/styles/dimension.js.map +1 -0
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +30 -0
- package/dist/styles/display.js +73 -0
- package/dist/styles/display.js.map +1 -0
- package/dist/styles/fade.d.ts +15 -0
- package/dist/styles/fade.js +62 -0
- package/dist/styles/fade.js.map +1 -0
- package/dist/styles/fill.d.ts +42 -0
- package/dist/styles/fill.js +51 -0
- package/dist/styles/fill.js.map +1 -0
- package/dist/styles/flow.d.ts +16 -0
- package/dist/styles/flow.js +12 -0
- package/dist/styles/flow.js.map +1 -0
- package/dist/styles/gap.d.ts +31 -0
- package/dist/styles/gap.js +38 -0
- package/dist/styles/gap.js.map +1 -0
- package/dist/styles/height.d.ts +17 -0
- package/dist/styles/height.js +19 -0
- package/dist/styles/height.js.map +1 -0
- package/dist/styles/index.d.ts +1 -0
- package/dist/styles/index.js +8 -0
- package/dist/styles/index.js.map +1 -0
- package/dist/styles/inset.d.ts +24 -0
- package/dist/styles/inset.js +34 -0
- package/dist/styles/inset.js.map +1 -0
- package/dist/styles/list.d.ts +16 -0
- package/dist/styles/list.js +100 -0
- package/dist/styles/list.js.map +1 -0
- package/dist/styles/margin.d.ts +24 -0
- package/dist/styles/margin.js +32 -0
- package/dist/styles/margin.js.map +1 -0
- package/dist/styles/outline.d.ts +29 -0
- package/dist/styles/outline.js +55 -0
- package/dist/styles/outline.js.map +1 -0
- package/dist/styles/padding.d.ts +24 -0
- package/dist/styles/padding.js +32 -0
- package/dist/styles/padding.js.map +1 -0
- 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 +71 -0
- package/dist/styles/predefined.js +237 -0
- package/dist/styles/predefined.js.map +1 -0
- package/dist/styles/preset.d.ts +52 -0
- package/dist/styles/preset.js +127 -0
- package/dist/styles/preset.js.map +1 -0
- package/dist/styles/radius.d.ts +12 -0
- package/dist/styles/radius.js +83 -0
- package/dist/styles/radius.js.map +1 -0
- 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 +25 -0
- package/dist/styles/scrollbar.js +51 -0
- package/dist/styles/scrollbar.js.map +1 -0
- package/dist/styles/shadow.d.ts +14 -0
- package/dist/styles/shadow.js +25 -0
- package/dist/styles/shadow.js.map +1 -0
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +14 -0
- package/dist/styles/transition.js +159 -0
- package/dist/styles/transition.js.map +1 -0
- package/dist/styles/types.d.ts +564 -0
- package/dist/styles/width.d.ts +17 -0
- package/dist/styles/width.js +19 -0
- package/dist/styles/width.js.map +1 -0
- package/dist/tasty.d.ts +134 -0
- package/dist/tasty.js +243 -0
- package/dist/tasty.js.map +1 -0
- package/dist/types.d.ts +184 -0
- package/dist/utils/cache-wrapper.js +21 -0
- package/dist/utils/cache-wrapper.js.map +1 -0
- package/dist/utils/case-converter.js +8 -0
- package/dist/utils/case-converter.js.map +1 -0
- 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.d.ts +5 -0
- package/dist/utils/colors.js +10 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/css-types.d.ts +7 -0
- package/dist/utils/deps-equal.js +15 -0
- package/dist/utils/deps-equal.js.map +1 -0
- package/dist/utils/dotize.d.ts +26 -0
- package/dist/utils/dotize.js +122 -0
- package/dist/utils/dotize.js.map +1 -0
- package/dist/utils/filter-base-props.d.ts +15 -0
- package/dist/utils/filter-base-props.js +45 -0
- package/dist/utils/filter-base-props.js.map +1 -0
- package/dist/utils/get-display-name.d.ts +7 -0
- package/dist/utils/get-display-name.js +10 -0
- package/dist/utils/get-display-name.js.map +1 -0
- 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 +19 -0
- package/dist/utils/is-dev-env.js.map +1 -0
- package/dist/utils/is-valid-element-type.js +15 -0
- package/dist/utils/is-valid-element-type.js.map +1 -0
- package/dist/utils/merge-styles.d.ts +7 -0
- package/dist/utils/merge-styles.js +145 -0
- package/dist/utils/merge-styles.js.map +1 -0
- package/dist/utils/mod-attrs.d.ts +6 -0
- package/dist/utils/mod-attrs.js +20 -0
- package/dist/utils/mod-attrs.js.map +1 -0
- package/dist/utils/process-tokens.d.ts +17 -0
- package/dist/utils/process-tokens.js +83 -0
- package/dist/utils/process-tokens.js.map +1 -0
- package/dist/utils/resolve-recipes.d.ts +17 -0
- package/dist/utils/resolve-recipes.js +146 -0
- package/dist/utils/resolve-recipes.js.map +1 -0
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/styles.d.ts +99 -0
- package/dist/utils/styles.js +220 -0
- package/dist/utils/styles.js.map +1 -0
- package/dist/utils/typography.d.ts +58 -0
- package/dist/utils/typography.js +51 -0
- package/dist/utils/typography.js.map +1 -0
- package/dist/utils/warnings.d.ts +16 -0
- package/dist/utils/warnings.js +16 -0
- package/dist/utils/warnings.js.map +1 -0
- package/dist/zero/babel.d.ts +195 -0
- package/dist/zero/babel.js +456 -0
- package/dist/zero/babel.js.map +1 -0
- package/dist/zero/css-writer.d.ts +45 -0
- package/dist/zero/css-writer.js +73 -0
- package/dist/zero/css-writer.js.map +1 -0
- package/dist/zero/extractor.d.ts +24 -0
- package/dist/zero/extractor.js +266 -0
- package/dist/zero/extractor.js.map +1 -0
- package/dist/zero/index.d.ts +3 -0
- package/dist/zero/index.js +3 -0
- package/dist/zero/next.d.ts +86 -0
- package/dist/zero/next.js +143 -0
- package/dist/zero/next.js.map +1 -0
- package/docs/PIPELINE.md +519 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +298 -0
- package/docs/comparison.md +419 -0
- package/docs/configuration.md +389 -0
- package/docs/debug.md +318 -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/react-api.md +557 -0
- package/docs/ssr.md +440 -0
- package/docs/styles.md +596 -0
- package/docs/tasty-static.md +532 -0
- package/package.json +221 -0
- package/tasty.config.ts +14 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { parsePropertyToken } from "../properties/index.js";
|
|
2
|
+
import { PropertyTypeResolver } from "../properties/property-type-resolver.js";
|
|
3
|
+
import { pushRSCCSS } from "../rsc-cache.js";
|
|
4
|
+
import { formatPropertyCSS } from "./format-property.js";
|
|
5
|
+
//#region src/ssr/collect-auto-properties.ts
|
|
6
|
+
/**
|
|
7
|
+
* Scan rendered rules for auto-inferable custom properties and emit
|
|
8
|
+
* @property CSS via the provided callback.
|
|
9
|
+
*/
|
|
10
|
+
function scanAndEmitAutoProperties(rules, styles, emit) {
|
|
11
|
+
const registered = /* @__PURE__ */ new Set();
|
|
12
|
+
if (styles) {
|
|
13
|
+
const localProps = styles["@properties"];
|
|
14
|
+
if (localProps && typeof localProps === "object") for (const token of Object.keys(localProps)) {
|
|
15
|
+
const parsed = parsePropertyToken(token);
|
|
16
|
+
if (parsed.isValid) registered.add(parsed.cssName);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const resolver = new PropertyTypeResolver();
|
|
20
|
+
for (const rule of rules) {
|
|
21
|
+
if (!rule.declarations) continue;
|
|
22
|
+
resolver.scanDeclarations(rule.declarations, (name) => registered.has(name), (name, syntax, initialValue) => {
|
|
23
|
+
registered.add(name);
|
|
24
|
+
const css = formatPropertyCSS(name, {
|
|
25
|
+
syntax,
|
|
26
|
+
inherits: true,
|
|
27
|
+
initialValue
|
|
28
|
+
});
|
|
29
|
+
if (css) emit(name, css);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Scan rendered rules for custom property declarations and collect
|
|
35
|
+
* auto-inferred @property rules via the SSR collector.
|
|
36
|
+
*
|
|
37
|
+
* @param rules - Rendered style rules containing CSS declarations
|
|
38
|
+
* @param collector - SSR collector to emit @property CSS into
|
|
39
|
+
* @param styles - Original styles object (used to skip explicit @properties)
|
|
40
|
+
*/
|
|
41
|
+
function collectAutoInferredProperties(rules, collector, styles) {
|
|
42
|
+
scanAndEmitAutoProperties(rules, styles, (name, css) => {
|
|
43
|
+
collector.collectProperty(`__auto:${name}`, css);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* RSC variant: scan rendered rules and push auto-inferred @property CSS
|
|
48
|
+
* into the RSC pending buffer.
|
|
49
|
+
*/
|
|
50
|
+
function collectAutoInferredPropertiesRSC(rules, rscCache, styles) {
|
|
51
|
+
scanAndEmitAutoProperties(rules, styles, (name, css) => {
|
|
52
|
+
pushRSCCSS(rscCache, `__auto:${name}`, css);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { collectAutoInferredProperties, collectAutoInferredPropertiesRSC };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=collect-auto-properties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect-auto-properties.js","names":[],"sources":["../../src/ssr/collect-auto-properties.ts"],"sourcesContent":["/**\n * SSR / RSC auto-property inference.\n *\n * Scans rendered CSS declarations for custom properties whose types\n * can be inferred from their values (e.g. `--angle: 30deg` → `<angle>`).\n * Mirrors the client-side auto-inference in StyleInjector.inject().\n */\n\nimport type { StyleResult } from '../pipeline';\nimport { parsePropertyToken } from '../properties';\nimport { PropertyTypeResolver } from '../properties/property-type-resolver';\nimport type { RSCStyleCache } from '../rsc-cache';\nimport { pushRSCCSS } from '../rsc-cache';\nimport type { Styles } from '../styles/types';\n\nimport type { ServerStyleCollector } from './collector';\nimport { formatPropertyCSS } from './format-property';\n\n/**\n * Scan rendered rules for auto-inferable custom properties and emit\n * @property CSS via the provided callback.\n */\nfunction scanAndEmitAutoProperties(\n rules: StyleResult[],\n styles: Styles | undefined,\n emit: (name: string, css: string) => void,\n): void {\n const registered = new Set<string>();\n\n if (styles) {\n const localProps = styles['@properties'];\n if (localProps && typeof localProps === 'object') {\n for (const token of Object.keys(localProps as Record<string, unknown>)) {\n const parsed = parsePropertyToken(token);\n if (parsed.isValid) {\n registered.add(parsed.cssName);\n }\n }\n }\n }\n\n const resolver = new PropertyTypeResolver();\n\n for (const rule of rules) {\n if (!rule.declarations) continue;\n resolver.scanDeclarations(\n rule.declarations,\n (name) => registered.has(name),\n (name, syntax, initialValue) => {\n registered.add(name);\n const css = formatPropertyCSS(name, {\n syntax,\n inherits: true,\n initialValue,\n });\n if (css) {\n emit(name, css);\n }\n },\n );\n }\n}\n\n/**\n * Scan rendered rules for custom property declarations and collect\n * auto-inferred @property rules via the SSR collector.\n *\n * @param rules - Rendered style rules containing CSS declarations\n * @param collector - SSR collector to emit @property CSS into\n * @param styles - Original styles object (used to skip explicit @properties)\n */\nexport function collectAutoInferredProperties(\n rules: StyleResult[],\n collector: ServerStyleCollector,\n styles?: Styles,\n): void {\n scanAndEmitAutoProperties(rules, styles, (name, css) => {\n collector.collectProperty(`__auto:${name}`, css);\n });\n}\n\n/**\n * RSC variant: scan rendered rules and push auto-inferred @property CSS\n * into the RSC pending buffer.\n */\nexport function collectAutoInferredPropertiesRSC(\n rules: StyleResult[],\n rscCache: RSCStyleCache,\n styles?: Styles,\n): void {\n scanAndEmitAutoProperties(rules, styles, (name, css) => {\n pushRSCCSS(rscCache, `__auto:${name}`, css);\n });\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAS,0BACP,OACA,QACA,MACM;CACN,MAAM,6BAAa,IAAI,KAAa;AAEpC,KAAI,QAAQ;EACV,MAAM,aAAa,OAAO;AAC1B,MAAI,cAAc,OAAO,eAAe,SACtC,MAAK,MAAM,SAAS,OAAO,KAAK,WAAsC,EAAE;GACtE,MAAM,SAAS,mBAAmB,MAAM;AACxC,OAAI,OAAO,QACT,YAAW,IAAI,OAAO,QAAQ;;;CAMtC,MAAM,WAAW,IAAI,sBAAsB;AAE3C,MAAK,MAAM,QAAQ,OAAO;AACxB,MAAI,CAAC,KAAK,aAAc;AACxB,WAAS,iBACP,KAAK,eACJ,SAAS,WAAW,IAAI,KAAK,GAC7B,MAAM,QAAQ,iBAAiB;AAC9B,cAAW,IAAI,KAAK;GACpB,MAAM,MAAM,kBAAkB,MAAM;IAClC;IACA,UAAU;IACV;IACD,CAAC;AACF,OAAI,IACF,MAAK,MAAM,IAAI;IAGpB;;;;;;;;;;;AAYL,SAAgB,8BACd,OACA,WACA,QACM;AACN,2BAA0B,OAAO,SAAS,MAAM,QAAQ;AACtD,YAAU,gBAAgB,UAAU,QAAQ,IAAI;GAChD;;;;;;AAOJ,SAAgB,iCACd,OACA,UACA,QACM;AACN,2BAA0B,OAAO,SAAS,MAAM,QAAQ;AACtD,aAAW,UAAU,UAAU,QAAQ,IAAI;GAC3C"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { StyleResult } from "../pipeline/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/ssr/collector.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Cache state serialized to the client for hydration.
|
|
6
|
+
*/
|
|
7
|
+
interface SSRCacheState {
|
|
8
|
+
/** cacheKey → className map, to pre-populate the client registry */
|
|
9
|
+
entries: Record<string, string>;
|
|
10
|
+
/** Counter value so client allocations don't collide with server ones */
|
|
11
|
+
classCounter: number;
|
|
12
|
+
}
|
|
13
|
+
declare class ServerStyleCollector {
|
|
14
|
+
private chunks;
|
|
15
|
+
private cacheKeyToClassName;
|
|
16
|
+
private classCounter;
|
|
17
|
+
private flushedKeys;
|
|
18
|
+
private propertyRules;
|
|
19
|
+
private flushedPropertyKeys;
|
|
20
|
+
private keyframeRules;
|
|
21
|
+
private flushedKeyframeKeys;
|
|
22
|
+
private globalStyles;
|
|
23
|
+
private flushedGlobalKeys;
|
|
24
|
+
private rawCSS;
|
|
25
|
+
private flushedRawKeys;
|
|
26
|
+
private fontFaceRules;
|
|
27
|
+
private flushedFontFaceKeys;
|
|
28
|
+
private counterStyleRules;
|
|
29
|
+
private flushedCounterStyleKeys;
|
|
30
|
+
private keyframesCounter;
|
|
31
|
+
private counterStyleCounter;
|
|
32
|
+
private internalsCollected;
|
|
33
|
+
/**
|
|
34
|
+
* Collect internal @property rules and :root token defaults.
|
|
35
|
+
* Mirrors markStylesGenerated() from the client-side injector.
|
|
36
|
+
* Called automatically on first chunk collection; idempotent.
|
|
37
|
+
*/
|
|
38
|
+
collectInternals(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Allocate a className for a cache key, server-side.
|
|
41
|
+
* Mirrors StyleInjector.allocateClassName but without DOM access.
|
|
42
|
+
*/
|
|
43
|
+
allocateClassName(cacheKey: string): {
|
|
44
|
+
className: string;
|
|
45
|
+
isNewAllocation: boolean;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Record CSS rules for a chunk.
|
|
49
|
+
* Called by useStyles during server render.
|
|
50
|
+
*/
|
|
51
|
+
collectChunk(cacheKey: string, className: string, rules: StyleResult[]): void;
|
|
52
|
+
/**
|
|
53
|
+
* Record a @property rule. Deduplicated by name.
|
|
54
|
+
*/
|
|
55
|
+
collectProperty(name: string, css: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Record a @keyframes rule. Deduplicated by name.
|
|
58
|
+
*/
|
|
59
|
+
collectKeyframes(name: string, css: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Allocate a keyframe name for SSR. Uses provided name or generates one.
|
|
62
|
+
*/
|
|
63
|
+
allocateKeyframeName(providedName?: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Record a @font-face rule. Deduplicated by key (content hash).
|
|
66
|
+
*/
|
|
67
|
+
collectFontFace(key: string, css: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Record a @counter-style rule. Deduplicated by name.
|
|
70
|
+
*/
|
|
71
|
+
collectCounterStyle(name: string, css: string): void;
|
|
72
|
+
/**
|
|
73
|
+
* Allocate a counter-style name for SSR. Uses provided name or generates one.
|
|
74
|
+
*/
|
|
75
|
+
allocateCounterStyleName(providedName?: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Record global styles (from useGlobalStyles). Deduplicated by key.
|
|
78
|
+
*/
|
|
79
|
+
collectGlobalStyles(key: string, css: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Record raw CSS text (from useRawCSS). Deduplicated by key.
|
|
82
|
+
*/
|
|
83
|
+
collectRawCSS(key: string, css: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* Extract all CSS collected so far as a single string.
|
|
86
|
+
* Includes @property and @keyframes rules.
|
|
87
|
+
* Used for non-streaming SSR (renderToString).
|
|
88
|
+
*/
|
|
89
|
+
getCSS(): string;
|
|
90
|
+
/**
|
|
91
|
+
* Flush only newly collected CSS since the last flush.
|
|
92
|
+
* Used for streaming SSR (renderToPipeableStream + useServerInsertedHTML).
|
|
93
|
+
*/
|
|
94
|
+
flushCSS(): string;
|
|
95
|
+
/**
|
|
96
|
+
* Serialize the cache state for client hydration.
|
|
97
|
+
*/
|
|
98
|
+
getCacheState(): SSRCacheState;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { SSRCacheState, ServerStyleCollector };
|
|
102
|
+
//# sourceMappingURL=collector.d.ts.map
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { fontFaceContentHash, formatFontFaceRule } from "../font-face/index.js";
|
|
2
|
+
import { formatCounterStyleRule } from "../counter-style/index.js";
|
|
3
|
+
import { renderStyles } from "../pipeline/index.js";
|
|
4
|
+
import { getEffectiveProperties, getGlobalBodyStyles, getGlobalConfigTokens, getGlobalCounterStyle, getGlobalFontFace } from "../config.js";
|
|
5
|
+
import { formatPropertyCSS } from "./format-property.js";
|
|
6
|
+
import { formatGlobalRules } from "./format-global-rules.js";
|
|
7
|
+
import { formatRules } from "./format-rules.js";
|
|
8
|
+
//#region src/ssr/collector.ts
|
|
9
|
+
/**
|
|
10
|
+
* ServerStyleCollector — server-safe style collector for SSR.
|
|
11
|
+
*
|
|
12
|
+
* Accumulates CSS rules and cache metadata during server rendering.
|
|
13
|
+
* This is the server-side counterpart to StyleInjector: it allocates
|
|
14
|
+
* sequential class names (t0, t1, …), formats CSS rules into text,
|
|
15
|
+
* and serializes the cache state for client hydration.
|
|
16
|
+
*
|
|
17
|
+
* One instance is created per HTTP request. Concurrent requests
|
|
18
|
+
* each get their own collector (via AsyncLocalStorage or React context).
|
|
19
|
+
*/
|
|
20
|
+
function generateClassName(counter) {
|
|
21
|
+
return `t${counter}`;
|
|
22
|
+
}
|
|
23
|
+
var ServerStyleCollector = class {
|
|
24
|
+
chunks = /* @__PURE__ */ new Map();
|
|
25
|
+
cacheKeyToClassName = /* @__PURE__ */ new Map();
|
|
26
|
+
classCounter = 0;
|
|
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
|
+
collectInternals() {
|
|
49
|
+
if (this.internalsCollected) return;
|
|
50
|
+
this.internalsCollected = true;
|
|
51
|
+
for (const [token, definition] of Object.entries(getEffectiveProperties())) {
|
|
52
|
+
const css = formatPropertyCSS(token, definition);
|
|
53
|
+
if (css) this.collectProperty(`__prop:${token}`, css);
|
|
54
|
+
}
|
|
55
|
+
const tokenStyles = getGlobalConfigTokens();
|
|
56
|
+
if (tokenStyles && Object.keys(tokenStyles).length > 0) {
|
|
57
|
+
const tokenRules = renderStyles(tokenStyles, ":root");
|
|
58
|
+
if (tokenRules.length > 0) {
|
|
59
|
+
const css = formatGlobalRules(tokenRules);
|
|
60
|
+
if (css) this.collectGlobalStyles("__global:tokens", css);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const bodyStyles = getGlobalBodyStyles();
|
|
64
|
+
if (bodyStyles && Object.keys(bodyStyles).length > 0) {
|
|
65
|
+
const bodyRules = renderStyles(bodyStyles, "body");
|
|
66
|
+
if (bodyRules.length > 0) {
|
|
67
|
+
const css = formatGlobalRules(bodyRules);
|
|
68
|
+
if (css) this.collectGlobalStyles("__global:bodyStyles", css);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const globalFF = getGlobalFontFace();
|
|
72
|
+
if (globalFF) for (const [family, input] of Object.entries(globalFF)) {
|
|
73
|
+
const descriptors = Array.isArray(input) ? input : [input];
|
|
74
|
+
for (const desc of descriptors) {
|
|
75
|
+
const hash = fontFaceContentHash(family, desc);
|
|
76
|
+
const css = formatFontFaceRule(family, desc);
|
|
77
|
+
this.collectFontFace(hash, css);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const globalCS = getGlobalCounterStyle();
|
|
81
|
+
if (globalCS) for (const [name, descriptors] of Object.entries(globalCS)) {
|
|
82
|
+
const css = formatCounterStyleRule(name, descriptors);
|
|
83
|
+
this.collectCounterStyle(name, css);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Allocate a className for a cache key, server-side.
|
|
88
|
+
* Mirrors StyleInjector.allocateClassName but without DOM access.
|
|
89
|
+
*/
|
|
90
|
+
allocateClassName(cacheKey) {
|
|
91
|
+
const existing = this.cacheKeyToClassName.get(cacheKey);
|
|
92
|
+
if (existing) return {
|
|
93
|
+
className: existing,
|
|
94
|
+
isNewAllocation: false
|
|
95
|
+
};
|
|
96
|
+
const className = generateClassName(this.classCounter++);
|
|
97
|
+
this.cacheKeyToClassName.set(cacheKey, className);
|
|
98
|
+
return {
|
|
99
|
+
className,
|
|
100
|
+
isNewAllocation: true
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Record CSS rules for a chunk.
|
|
105
|
+
* Called by useStyles during server render.
|
|
106
|
+
*/
|
|
107
|
+
collectChunk(cacheKey, className, rules) {
|
|
108
|
+
if (this.chunks.has(cacheKey)) return;
|
|
109
|
+
const css = formatRules(rules, className);
|
|
110
|
+
if (css) this.chunks.set(cacheKey, css);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Record a @property rule. Deduplicated by name.
|
|
114
|
+
*/
|
|
115
|
+
collectProperty(name, css) {
|
|
116
|
+
if (!this.propertyRules.has(name)) this.propertyRules.set(name, css);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Record a @keyframes rule. Deduplicated by name.
|
|
120
|
+
*/
|
|
121
|
+
collectKeyframes(name, css) {
|
|
122
|
+
if (!this.keyframeRules.has(name)) this.keyframeRules.set(name, css);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Allocate a keyframe name for SSR. Uses provided name or generates one.
|
|
126
|
+
*/
|
|
127
|
+
allocateKeyframeName(providedName) {
|
|
128
|
+
return providedName ?? `k${this.keyframesCounter++}`;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Record a @font-face rule. Deduplicated by key (content hash).
|
|
132
|
+
*/
|
|
133
|
+
collectFontFace(key, css) {
|
|
134
|
+
if (!this.fontFaceRules.has(key)) this.fontFaceRules.set(key, css);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Record a @counter-style rule. Deduplicated by name.
|
|
138
|
+
*/
|
|
139
|
+
collectCounterStyle(name, css) {
|
|
140
|
+
if (!this.counterStyleRules.has(name)) this.counterStyleRules.set(name, css);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Allocate a counter-style name for SSR. Uses provided name or generates one.
|
|
144
|
+
*/
|
|
145
|
+
allocateCounterStyleName(providedName) {
|
|
146
|
+
return providedName ?? `cs${this.counterStyleCounter++}`;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Record global styles (from useGlobalStyles). Deduplicated by key.
|
|
150
|
+
*/
|
|
151
|
+
collectGlobalStyles(key, css) {
|
|
152
|
+
if (!this.globalStyles.has(key)) this.globalStyles.set(key, css);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Record raw CSS text (from useRawCSS). Deduplicated by key.
|
|
156
|
+
*/
|
|
157
|
+
collectRawCSS(key, css) {
|
|
158
|
+
if (!this.rawCSS.has(key)) this.rawCSS.set(key, css);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Extract all CSS collected so far as a single string.
|
|
162
|
+
* Includes @property and @keyframes rules.
|
|
163
|
+
* Used for non-streaming SSR (renderToString).
|
|
164
|
+
*/
|
|
165
|
+
getCSS() {
|
|
166
|
+
const parts = [];
|
|
167
|
+
for (const css of this.propertyRules.values()) parts.push(css);
|
|
168
|
+
for (const css of this.fontFaceRules.values()) parts.push(css);
|
|
169
|
+
for (const css of this.counterStyleRules.values()) parts.push(css);
|
|
170
|
+
for (const css of this.rawCSS.values()) parts.push(css);
|
|
171
|
+
for (const css of this.globalStyles.values()) parts.push(css);
|
|
172
|
+
for (const css of this.chunks.values()) parts.push(css);
|
|
173
|
+
for (const css of this.keyframeRules.values()) parts.push(css);
|
|
174
|
+
return parts.join("\n");
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Flush only newly collected CSS since the last flush.
|
|
178
|
+
* Used for streaming SSR (renderToPipeableStream + useServerInsertedHTML).
|
|
179
|
+
*/
|
|
180
|
+
flushCSS() {
|
|
181
|
+
const parts = [];
|
|
182
|
+
for (const [name, css] of this.propertyRules) if (!this.flushedPropertyKeys.has(name)) {
|
|
183
|
+
parts.push(css);
|
|
184
|
+
this.flushedPropertyKeys.add(name);
|
|
185
|
+
}
|
|
186
|
+
for (const [key, css] of this.fontFaceRules) if (!this.flushedFontFaceKeys.has(key)) {
|
|
187
|
+
parts.push(css);
|
|
188
|
+
this.flushedFontFaceKeys.add(key);
|
|
189
|
+
}
|
|
190
|
+
for (const [key, css] of this.counterStyleRules) if (!this.flushedCounterStyleKeys.has(key)) {
|
|
191
|
+
parts.push(css);
|
|
192
|
+
this.flushedCounterStyleKeys.add(key);
|
|
193
|
+
}
|
|
194
|
+
for (const [key, css] of this.rawCSS) if (!this.flushedRawKeys.has(key)) {
|
|
195
|
+
parts.push(css);
|
|
196
|
+
this.flushedRawKeys.add(key);
|
|
197
|
+
}
|
|
198
|
+
for (const [key, css] of this.globalStyles) if (!this.flushedGlobalKeys.has(key)) {
|
|
199
|
+
parts.push(css);
|
|
200
|
+
this.flushedGlobalKeys.add(key);
|
|
201
|
+
}
|
|
202
|
+
for (const [key, css] of this.chunks) if (!this.flushedKeys.has(key)) {
|
|
203
|
+
parts.push(css);
|
|
204
|
+
this.flushedKeys.add(key);
|
|
205
|
+
}
|
|
206
|
+
for (const [name, css] of this.keyframeRules) if (!this.flushedKeyframeKeys.has(name)) {
|
|
207
|
+
parts.push(css);
|
|
208
|
+
this.flushedKeyframeKeys.add(name);
|
|
209
|
+
}
|
|
210
|
+
return parts.join("\n");
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Serialize the cache state for client hydration.
|
|
214
|
+
*/
|
|
215
|
+
getCacheState() {
|
|
216
|
+
const entries = {};
|
|
217
|
+
for (const [cacheKey, className] of this.cacheKeyToClassName) entries[cacheKey] = className;
|
|
218
|
+
return {
|
|
219
|
+
entries,
|
|
220
|
+
classCounter: this.classCounter
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
//#endregion
|
|
225
|
+
export { ServerStyleCollector };
|
|
226
|
+
|
|
227
|
+
//# 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 * sequential class names (t0, t1, …), formats CSS rules into text,\n * and serializes the cache state for client hydration.\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 getGlobalBodyStyles,\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 { formatPropertyCSS } from './format-property';\nimport { formatGlobalRules } from './format-global-rules';\nimport { formatRules } from './format-rules';\n\n/**\n * Cache state serialized to the client for hydration.\n */\nexport interface SSRCacheState {\n /** cacheKey → className map, to pre-populate the client registry */\n entries: Record<string, string>;\n /** Counter value so client allocations don't collide with server ones */\n classCounter: number;\n}\n\nfunction generateClassName(counter: number): string {\n return `t${counter}`;\n}\n\nexport class ServerStyleCollector {\n private chunks = new Map<string, string>();\n private cacheKeyToClassName = new Map<string, string>();\n private classCounter = 0;\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 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 // Inject configured tokens as :root CSS custom properties\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 // Inject configured body styles\n const bodyStyles = getGlobalBodyStyles();\n if (bodyStyles && Object.keys(bodyStyles).length > 0) {\n const bodyRules = renderStyles(bodyStyles, 'body') as StyleResult[];\n if (bodyRules.length > 0) {\n const css = formatGlobalRules(bodyRules);\n if (css) {\n this.collectGlobalStyles('__global:bodyStyles', css);\n }\n }\n }\n\n // Inject global @font-face rules (mirrors markStylesGenerated)\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 // Inject global @counter-style rules (mirrors markStylesGenerated)\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\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(this.classCounter++);\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 /**\n * Serialize the cache state for client hydration.\n */\n getCacheState(): SSRCacheState {\n const entries: Record<string, string> = {};\n for (const [cacheKey, className] of this.cacheKeyToClassName) {\n entries[cacheKey] = className;\n }\n return { entries, classCounter: this.classCounter };\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
//#region src/ssr/context.ts
|
|
3
|
+
/**
|
|
4
|
+
* React context for SSR collector discovery.
|
|
5
|
+
*
|
|
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,OAAO,QAAQ,MAAM,EAAE;AAChD,MAAI,OAAO,UAAU,UAAU;AAC7B,SAAM,KAAK,GAAG,IAAI,KAAK,MAAM,MAAM,CAAC,IAAI;AACxC;;EAGF,MAAM,WAAY,SAAS,EAAE;EAC7B,MAAM,aAAa,OAAO,KAAK,SAAS,CAAC,MAAM;EAC/C,MAAM,eAA+B,EAAE;EACvC,MAAM,+BAAe,IAAI,KAAmB;AAE5C,aAAW,SAAS,cAAc;GAChC,IAAI,WAAW,kBAAkB;AACjC,OAAI,CAAC,SACH,YAAW,kBAAkB,aAAa,CAAC,YAAY,UAAU,CAAC;AAGpE,YAAS,SAAS,YAAY;AAC5B,QAAI,CAAC,aAAa,IAAI,QAAQ,EAAE;AAC9B,kBAAa,IAAI,QAAQ;AACzB,kBAAa,KAAK,QAAQ;;KAE5B;IACF;EAEF,MAAM,mBAAsD,EAAE;AAE9D,eAAa,SAAS,YAAY;GAQhC,MAAM,SAAS,QAPA,QAAQ,eACI,QAA4B,KAAK,SAAS;IACnE,MAAM,IAAI,SAAS;AACnB,QAAI,MAAM,KAAA,EAAW,KAAI,QAAQ;AACjC,WAAO;MACN,EAAE,CAAC,CAE6B;AACnC,OAAI,CAAC,OAAQ;AAGb,IADgB,MAAM,QAAQ,OAAO,GAAG,SAAS,CAAC,OAAO,EACjD,SAAS,WAAW;AAC1B,QAAI,CAAC,UAAU,OAAO,WAAW,SAAU;IAC3C,MAAM,EAAE,GAAG,IAAI,GAAG,UAAU;AAE5B,WAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,MAAM,SAAS;AAC7C,SAAI,OAAO,QAAQ,QAAQ,GAAI;AAE/B,SAAI,MAAM,QAAQ,IAAI,CACpB,KAAI,SAAS,MAAM;AACjB,UAAI,KAAK,QAAQ,MAAM,GACrB,kBAAiB,KAAK;OAAE;OAAM,OAAO,OAAO,EAAE;OAAE,CAAC;OAEnD;SAEF,kBAAiB,KAAK;MAAE;MAAM,OAAO,OAAO,IAAI;MAAE,CAAC;MAErD;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"}
|