@tenphi/tasty 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ssr/async-storage.js → async-storage-B7_o6FKt.js} +2 -2
- package/dist/async-storage-B7_o6FKt.js.map +1 -0
- package/dist/{ssr/collector.js → collector-DrgDE7QB.js} +5 -10
- package/dist/collector-DrgDE7QB.js.map +1 -0
- package/dist/{ssr/collector.d.ts → collector-LuU1vZ68.d.ts} +3 -3
- package/dist/config-_aQ_PZ-P.js +10131 -0
- package/dist/config-_aQ_PZ-P.js.map +1 -0
- package/dist/config-vuCRkBWX.d.ts +884 -0
- package/dist/{ssr/context.js → context-CkSg-kDT.js} +11 -3
- package/dist/context-CkSg-kDT.js.map +1 -0
- package/dist/core/index.d.ts +5 -34
- package/dist/core/index.js +6 -27
- package/dist/core-BqO8pplb.js +1592 -0
- package/dist/core-BqO8pplb.js.map +1 -0
- package/dist/{zero/extractor.js → css-writer-D--REwtp.js} +74 -11
- package/dist/css-writer-D--REwtp.js.map +1 -0
- package/dist/{ssr/format-global-rules.js → format-global-rules-Dbc_1tc3.js} +2 -2
- package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
- package/dist/format-rules-xwteB7a1.js +143 -0
- package/dist/format-rules-xwteB7a1.js.map +1 -0
- package/dist/{ssr/hydrate.js → hydrate-BvPT4ndL.js} +3 -3
- package/dist/hydrate-BvPT4ndL.js.map +1 -0
- package/dist/index-ZRxZWzlj.d.ts +1602 -0
- package/dist/{styles/types.d.ts → index-dUtwpOux.d.ts} +707 -5
- package/dist/index.d.ts +5 -51
- package/dist/index.js +732 -36
- package/dist/index.js.map +1 -0
- package/dist/keyframes-ClPFWy33.js +587 -0
- package/dist/keyframes-ClPFWy33.js.map +1 -0
- package/dist/{utils/merge-styles.js → merge-styles-BUQsEpbv.js} +3 -4
- package/dist/merge-styles-BUQsEpbv.js.map +1 -0
- package/dist/{utils/merge-styles.d.ts → merge-styles-CtDJMhpJ.d.ts} +3 -3
- package/dist/{utils/resolve-recipes.js → resolve-recipes-C0-AMzCz.js} +4 -6
- package/dist/resolve-recipes-C0-AMzCz.js.map +1 -0
- package/dist/ssr/astro-client.js +1 -1
- package/dist/ssr/astro.js +4 -4
- package/dist/ssr/index.d.ts +44 -4
- package/dist/ssr/index.js +4 -4
- package/dist/ssr/next.d.ts +1 -1
- package/dist/ssr/next.js +6 -6
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +91 -5
- package/dist/static/index.js +49 -3
- package/dist/static/index.js.map +1 -0
- package/dist/zero/babel.d.ts +1 -1
- package/dist/zero/babel.js +10 -6
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +67 -3
- package/dist/zero/index.js +1 -2
- package/docs/injector.md +2 -2
- package/package.json +10 -9
- package/dist/_virtual/_rolldown/runtime.js +0 -7
- package/dist/chunks/cacheKey.d.ts +0 -1
- package/dist/chunks/cacheKey.js +0 -77
- package/dist/chunks/cacheKey.js.map +0 -1
- package/dist/chunks/definitions.d.ts +0 -37
- package/dist/chunks/definitions.js +0 -258
- package/dist/chunks/definitions.js.map +0 -1
- package/dist/chunks/index.d.ts +0 -1
- package/dist/chunks/renderChunk.d.ts +0 -1
- package/dist/chunks/renderChunk.js +0 -59
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/compute-styles.d.ts +0 -31
- package/dist/compute-styles.js +0 -322
- package/dist/compute-styles.js.map +0 -1
- package/dist/config.d.ts +0 -407
- package/dist/config.js +0 -591
- package/dist/config.js.map +0 -1
- package/dist/counter-style/index.js +0 -51
- package/dist/counter-style/index.js.map +0 -1
- package/dist/debug.d.ts +0 -89
- package/dist/debug.js +0 -453
- package/dist/debug.js.map +0 -1
- package/dist/font-face/index.js +0 -63
- package/dist/font-face/index.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -7
- package/dist/hooks/useCounterStyle.d.ts +0 -36
- package/dist/hooks/useCounterStyle.js +0 -65
- package/dist/hooks/useCounterStyle.js.map +0 -1
- package/dist/hooks/useFontFace.d.ts +0 -45
- package/dist/hooks/useFontFace.js +0 -66
- package/dist/hooks/useFontFace.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -46
- package/dist/hooks/useGlobalStyles.js +0 -88
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -58
- package/dist/hooks/useKeyframes.js +0 -55
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -81
- package/dist/hooks/useProperty.js +0 -96
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -22
- package/dist/hooks/useRawCSS.js +0 -103
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -40
- package/dist/hooks/useStyles.js +0 -31
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -182
- package/dist/injector/index.js +0 -185
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -198
- package/dist/injector/injector.js +0 -651
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -132
- package/dist/injector/sheet-manager.js +0 -699
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -235
- package/dist/keyframes/index.js +0 -206
- package/dist/keyframes/index.js.map +0 -1
- package/dist/parser/classify.js +0 -319
- package/dist/parser/classify.js.map +0 -1
- package/dist/parser/const.js +0 -60
- package/dist/parser/const.js.map +0 -1
- package/dist/parser/lru.js +0 -109
- package/dist/parser/lru.js.map +0 -1
- package/dist/parser/parser.d.ts +0 -25
- package/dist/parser/parser.js +0 -115
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/tokenizer.js +0 -69
- package/dist/parser/tokenizer.js.map +0 -1
- package/dist/parser/types.d.ts +0 -51
- package/dist/parser/types.js +0 -46
- package/dist/parser/types.js.map +0 -1
- package/dist/pipeline/conditions.d.ts +0 -134
- package/dist/pipeline/conditions.js +0 -406
- package/dist/pipeline/conditions.js.map +0 -1
- package/dist/pipeline/exclusive.js +0 -389
- package/dist/pipeline/exclusive.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -55
- package/dist/pipeline/index.js +0 -749
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize-contradictions.js +0 -125
- package/dist/pipeline/materialize-contradictions.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -1038
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -446
- package/dist/pipeline/parseStateKey.js.map +0 -1
- package/dist/pipeline/simplify.js +0 -725
- package/dist/pipeline/simplify.js.map +0 -1
- package/dist/pipeline/warnings.js +0 -18
- package/dist/pipeline/warnings.js.map +0 -1
- package/dist/plugins/index.d.ts +0 -2
- package/dist/plugins/okhsl-plugin.d.ts +0 -35
- package/dist/plugins/okhsl-plugin.js +0 -97
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -87
- package/dist/properties/index.js +0 -222
- package/dist/properties/index.js.map +0 -1
- package/dist/properties/property-type-resolver.d.ts +0 -24
- package/dist/properties/property-type-resolver.js +0 -90
- package/dist/properties/property-type-resolver.js.map +0 -1
- package/dist/rsc-cache.js +0 -79
- package/dist/rsc-cache.js.map +0 -1
- package/dist/ssr/async-storage.d.ts +0 -17
- package/dist/ssr/async-storage.js.map +0 -1
- package/dist/ssr/collect-auto-properties.js +0 -58
- package/dist/ssr/collect-auto-properties.js.map +0 -1
- package/dist/ssr/collector.js.map +0 -1
- package/dist/ssr/context.js.map +0 -1
- package/dist/ssr/format-global-rules.js.map +0 -1
- package/dist/ssr/format-keyframes.js +0 -69
- package/dist/ssr/format-keyframes.js.map +0 -1
- package/dist/ssr/format-property.js +0 -49
- package/dist/ssr/format-property.js.map +0 -1
- package/dist/ssr/format-rules.js +0 -73
- package/dist/ssr/format-rules.js.map +0 -1
- package/dist/ssr/hydrate.d.ts +0 -29
- package/dist/ssr/hydrate.js.map +0 -1
- package/dist/ssr/ssr-collector-ref.js +0 -29
- package/dist/ssr/ssr-collector-ref.js.map +0 -1
- package/dist/states/index.d.ts +0 -49
- package/dist/states/index.js +0 -170
- package/dist/states/index.js.map +0 -1
- package/dist/static/tastyStatic.d.ts +0 -46
- package/dist/static/tastyStatic.js +0 -30
- package/dist/static/tastyStatic.js.map +0 -1
- package/dist/static/types.d.ts +0 -49
- package/dist/static/types.js +0 -24
- package/dist/static/types.js.map +0 -1
- package/dist/styles/border.d.ts +0 -25
- package/dist/styles/border.js +0 -120
- package/dist/styles/border.js.map +0 -1
- package/dist/styles/color.d.ts +0 -14
- package/dist/styles/color.js +0 -26
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/const.js +0 -17
- package/dist/styles/const.js.map +0 -1
- package/dist/styles/createStyle.js +0 -79
- package/dist/styles/createStyle.js.map +0 -1
- package/dist/styles/dimension.js +0 -109
- package/dist/styles/dimension.js.map +0 -1
- package/dist/styles/directional.js +0 -133
- package/dist/styles/directional.js.map +0 -1
- package/dist/styles/display.d.ts +0 -30
- package/dist/styles/display.js +0 -73
- package/dist/styles/display.js.map +0 -1
- package/dist/styles/fade.d.ts +0 -15
- package/dist/styles/fade.js +0 -62
- package/dist/styles/fade.js.map +0 -1
- package/dist/styles/fill.d.ts +0 -42
- package/dist/styles/fill.js +0 -51
- package/dist/styles/fill.js.map +0 -1
- package/dist/styles/flow.d.ts +0 -16
- package/dist/styles/flow.js +0 -12
- package/dist/styles/flow.js.map +0 -1
- package/dist/styles/gap.d.ts +0 -31
- package/dist/styles/gap.js +0 -38
- package/dist/styles/gap.js.map +0 -1
- package/dist/styles/height.d.ts +0 -17
- package/dist/styles/height.js +0 -19
- package/dist/styles/height.js.map +0 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +0 -8
- package/dist/styles/index.js.map +0 -1
- package/dist/styles/inset.d.ts +0 -24
- package/dist/styles/inset.js +0 -34
- package/dist/styles/inset.js.map +0 -1
- package/dist/styles/list.d.ts +0 -16
- package/dist/styles/list.js +0 -100
- package/dist/styles/list.js.map +0 -1
- package/dist/styles/margin.d.ts +0 -24
- package/dist/styles/margin.js +0 -32
- package/dist/styles/margin.js.map +0 -1
- package/dist/styles/outline.d.ts +0 -29
- package/dist/styles/outline.js +0 -55
- package/dist/styles/outline.js.map +0 -1
- package/dist/styles/padding.d.ts +0 -24
- package/dist/styles/padding.js +0 -32
- package/dist/styles/padding.js.map +0 -1
- package/dist/styles/placement.d.ts +0 -37
- package/dist/styles/placement.js +0 -74
- package/dist/styles/placement.js.map +0 -1
- package/dist/styles/predefined.d.ts +0 -71
- package/dist/styles/predefined.js +0 -237
- package/dist/styles/predefined.js.map +0 -1
- package/dist/styles/preset.d.ts +0 -52
- package/dist/styles/preset.js +0 -127
- package/dist/styles/preset.js.map +0 -1
- package/dist/styles/radius.d.ts +0 -12
- package/dist/styles/radius.js +0 -83
- package/dist/styles/radius.js.map +0 -1
- package/dist/styles/scrollMargin.d.ts +0 -24
- package/dist/styles/scrollMargin.js +0 -32
- package/dist/styles/scrollMargin.js.map +0 -1
- package/dist/styles/scrollbar.d.ts +0 -25
- package/dist/styles/scrollbar.js +0 -51
- package/dist/styles/scrollbar.js.map +0 -1
- package/dist/styles/shadow.d.ts +0 -14
- package/dist/styles/shadow.js +0 -25
- package/dist/styles/shadow.js.map +0 -1
- package/dist/styles/shared.js +0 -17
- package/dist/styles/shared.js.map +0 -1
- package/dist/styles/transition.d.ts +0 -14
- package/dist/styles/transition.js +0 -159
- package/dist/styles/transition.js.map +0 -1
- package/dist/styles/width.d.ts +0 -17
- package/dist/styles/width.js +0 -19
- package/dist/styles/width.js.map +0 -1
- package/dist/tasty.d.ts +0 -134
- package/dist/tasty.js +0 -248
- package/dist/tasty.js.map +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -21
- package/dist/utils/cache-wrapper.js.map +0 -1
- package/dist/utils/case-converter.js +0 -8
- package/dist/utils/case-converter.js.map +0 -1
- package/dist/utils/color-math.d.ts +0 -46
- package/dist/utils/color-math.js +0 -749
- package/dist/utils/color-math.js.map +0 -1
- package/dist/utils/color-space.d.ts +0 -5
- package/dist/utils/color-space.js +0 -228
- package/dist/utils/color-space.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -10
- package/dist/utils/colors.js.map +0 -1
- package/dist/utils/css-types.d.ts +0 -7
- package/dist/utils/deps-equal.js +0 -15
- package/dist/utils/deps-equal.js.map +0 -1
- package/dist/utils/dotize.d.ts +0 -26
- package/dist/utils/dotize.js +0 -122
- package/dist/utils/dotize.js.map +0 -1
- package/dist/utils/filter-base-props.d.ts +0 -15
- package/dist/utils/filter-base-props.js +0 -45
- package/dist/utils/filter-base-props.js.map +0 -1
- package/dist/utils/get-display-name.d.ts +0 -7
- package/dist/utils/get-display-name.js +0 -10
- package/dist/utils/get-display-name.js.map +0 -1
- package/dist/utils/has-keys.js +0 -13
- package/dist/utils/has-keys.js.map +0 -1
- package/dist/utils/hash.js +0 -14
- package/dist/utils/hash.js.map +0 -1
- package/dist/utils/is-dev-env.js +0 -19
- package/dist/utils/is-dev-env.js.map +0 -1
- package/dist/utils/is-valid-element-type.js +0 -15
- package/dist/utils/is-valid-element-type.js.map +0 -1
- package/dist/utils/merge-styles.js.map +0 -1
- package/dist/utils/mod-attrs.d.ts +0 -6
- package/dist/utils/mod-attrs.js +0 -20
- package/dist/utils/mod-attrs.js.map +0 -1
- package/dist/utils/process-tokens.d.ts +0 -17
- package/dist/utils/process-tokens.js +0 -83
- package/dist/utils/process-tokens.js.map +0 -1
- package/dist/utils/resolve-recipes.d.ts +0 -17
- package/dist/utils/resolve-recipes.js.map +0 -1
- package/dist/utils/selector-transform.js +0 -32
- package/dist/utils/selector-transform.js.map +0 -1
- package/dist/utils/string.js +0 -8
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/styles.d.ts +0 -99
- package/dist/utils/styles.js +0 -220
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -58
- package/dist/utils/typography.js +0 -51
- package/dist/utils/typography.js.map +0 -1
- package/dist/utils/warnings.d.ts +0 -16
- package/dist/utils/warnings.js +0 -16
- package/dist/utils/warnings.js.map +0 -1
- package/dist/zero/css-writer.d.ts +0 -45
- package/dist/zero/css-writer.js +0 -73
- package/dist/zero/css-writer.js.map +0 -1
- package/dist/zero/extractor.d.ts +0 -24
- package/dist/zero/extractor.js.map +0 -1
|
@@ -0,0 +1,1592 @@
|
|
|
1
|
+
import { $ as parseStyle, A as extractLocalCounterStyle, C as camelToKebab, Ct as Lru, F as formatFontFaceRule, H as createStyle, I as hasLocalFontFace, M as hasLocalCounterStyle, N as extractLocalFontFace, P as fontFaceContentHash, R as STYLE_HANDLER_MAP, U as PropertyTypeResolver, Z as normalizeColorTokenValue, c as getGlobalKeyframes, ct as hashString, d as hasGlobalKeyframes, dt as hasLocalProperties, ft as parsePropertyToken, g as markStylesGenerated, gt as getColorSpaceSuffix, h as isTestEnvironment, ht as getColorSpaceFunc, j as formatCounterStyleRule, k as StyleInjector, lt as extractLocalProperties, mt as getColorSpaceComponents, n as getConfig, s as getGlobalInjector, st as isDevEnv } from "./config-_aQ_PZ-P.js";
|
|
2
|
+
import { a as mergeKeyframes, c as generateChunkCacheKey, d as categorizeStyleKeys, i as hasLocalKeyframes, l as CHUNK_NAMES, n as extractLocalKeyframes, o as replaceAnimationNames, r as filterUsedKeyframes, s as renderStylesForChunk, t as extractAnimationNamesFromStyles } from "./keyframes-ClPFWy33.js";
|
|
3
|
+
import { n as formatPropertyCSS, r as getRegisteredSSRCollector, t as formatRules } from "./format-rules-xwteB7a1.js";
|
|
4
|
+
import { t as resolveRecipes } from "./resolve-recipes-C0-AMzCz.js";
|
|
5
|
+
import { cache } from "react";
|
|
6
|
+
//#region src/styles/list.ts
|
|
7
|
+
const BASE_STYLES = [
|
|
8
|
+
"display",
|
|
9
|
+
"font",
|
|
10
|
+
"preset",
|
|
11
|
+
"hide",
|
|
12
|
+
"whiteSpace",
|
|
13
|
+
"opacity",
|
|
14
|
+
"transition"
|
|
15
|
+
];
|
|
16
|
+
const POSITION_STYLES = [
|
|
17
|
+
"gridArea",
|
|
18
|
+
"order",
|
|
19
|
+
"gridColumn",
|
|
20
|
+
"gridRow",
|
|
21
|
+
"placeSelf",
|
|
22
|
+
"alignSelf",
|
|
23
|
+
"justifySelf",
|
|
24
|
+
"zIndex",
|
|
25
|
+
"margin",
|
|
26
|
+
"inset",
|
|
27
|
+
"position",
|
|
28
|
+
"scrollMargin"
|
|
29
|
+
];
|
|
30
|
+
const BLOCK_INNER_STYLES = [
|
|
31
|
+
"padding",
|
|
32
|
+
"paddingInline",
|
|
33
|
+
"paddingBlock",
|
|
34
|
+
"overflow",
|
|
35
|
+
"scrollbar",
|
|
36
|
+
"textAlign"
|
|
37
|
+
];
|
|
38
|
+
const BLOCK_OUTER_STYLES = [
|
|
39
|
+
"border",
|
|
40
|
+
"radius",
|
|
41
|
+
"shadow",
|
|
42
|
+
"outline"
|
|
43
|
+
];
|
|
44
|
+
const BLOCK_STYLES = [...BLOCK_INNER_STYLES, ...BLOCK_OUTER_STYLES];
|
|
45
|
+
const COLOR_STYLES = [
|
|
46
|
+
"color",
|
|
47
|
+
"fill",
|
|
48
|
+
"fade",
|
|
49
|
+
"image"
|
|
50
|
+
];
|
|
51
|
+
const TEXT_STYLES = [
|
|
52
|
+
"textTransform",
|
|
53
|
+
"fontWeight",
|
|
54
|
+
"fontStyle"
|
|
55
|
+
];
|
|
56
|
+
const DIMENSION_STYLES = [
|
|
57
|
+
"width",
|
|
58
|
+
"height",
|
|
59
|
+
"flexBasis",
|
|
60
|
+
"flexGrow",
|
|
61
|
+
"flexShrink",
|
|
62
|
+
"flex"
|
|
63
|
+
];
|
|
64
|
+
const FLOW_STYLES = [
|
|
65
|
+
"flow",
|
|
66
|
+
"place",
|
|
67
|
+
"placeItems",
|
|
68
|
+
"placeContent",
|
|
69
|
+
"alignItems",
|
|
70
|
+
"alignContent",
|
|
71
|
+
"justifyItems",
|
|
72
|
+
"justifyContent",
|
|
73
|
+
"align",
|
|
74
|
+
"justify",
|
|
75
|
+
"gap",
|
|
76
|
+
"columnGap",
|
|
77
|
+
"rowGap",
|
|
78
|
+
"gridColumns",
|
|
79
|
+
"gridRows",
|
|
80
|
+
"gridTemplate",
|
|
81
|
+
"gridAreas"
|
|
82
|
+
];
|
|
83
|
+
const CONTAINER_STYLES = [
|
|
84
|
+
...BASE_STYLES,
|
|
85
|
+
...COLOR_STYLES,
|
|
86
|
+
...DIMENSION_STYLES,
|
|
87
|
+
...POSITION_STYLES,
|
|
88
|
+
...BLOCK_STYLES,
|
|
89
|
+
...FLOW_STYLES
|
|
90
|
+
];
|
|
91
|
+
const OUTER_STYLES = [
|
|
92
|
+
...POSITION_STYLES,
|
|
93
|
+
...DIMENSION_STYLES,
|
|
94
|
+
...BLOCK_OUTER_STYLES
|
|
95
|
+
];
|
|
96
|
+
const INNER_STYLES = [
|
|
97
|
+
...BASE_STYLES,
|
|
98
|
+
...COLOR_STYLES,
|
|
99
|
+
...BLOCK_INNER_STYLES,
|
|
100
|
+
...FLOW_STYLES
|
|
101
|
+
];
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/injector/chunk-sheet-registry.ts
|
|
104
|
+
/**
|
|
105
|
+
* Global registry mapping CSS content hashes to shared constructable
|
|
106
|
+
* CSSStyleSheet objects with reference counting.
|
|
107
|
+
*
|
|
108
|
+
* Multiple shadow roots adopting the same chunk share a single underlying
|
|
109
|
+
* stylesheet object — parse once, adopt everywhere.
|
|
110
|
+
*/
|
|
111
|
+
var ChunkSheetRegistry = class {
|
|
112
|
+
sheets = /* @__PURE__ */ new Map();
|
|
113
|
+
sheetToHash = /* @__PURE__ */ new WeakMap();
|
|
114
|
+
/**
|
|
115
|
+
* Get or create a CSSStyleSheet for the given CSS text.
|
|
116
|
+
* Increments refCount. Uses content hash as the dedup key.
|
|
117
|
+
*/
|
|
118
|
+
acquire(cssText) {
|
|
119
|
+
const hash = hashString(cssText);
|
|
120
|
+
const existing = this.sheets.get(hash);
|
|
121
|
+
if (existing) {
|
|
122
|
+
existing.refCount++;
|
|
123
|
+
return existing.sheet;
|
|
124
|
+
}
|
|
125
|
+
const sheet = new CSSStyleSheet();
|
|
126
|
+
sheet.replaceSync(cssText);
|
|
127
|
+
const entry = {
|
|
128
|
+
sheet,
|
|
129
|
+
cssText,
|
|
130
|
+
refCount: 1
|
|
131
|
+
};
|
|
132
|
+
this.sheets.set(hash, entry);
|
|
133
|
+
this.sheetToHash.set(sheet, hash);
|
|
134
|
+
return sheet;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Decrement refCount for a sheet. When refCount reaches 0,
|
|
138
|
+
* the sheet is removed from the registry.
|
|
139
|
+
*/
|
|
140
|
+
release(sheet) {
|
|
141
|
+
const hash = this.sheetToHash.get(sheet);
|
|
142
|
+
if (!hash) return;
|
|
143
|
+
const entry = this.sheets.get(hash);
|
|
144
|
+
if (!entry) return;
|
|
145
|
+
entry.refCount--;
|
|
146
|
+
if (entry.refCount <= 0) {
|
|
147
|
+
this.sheets.delete(hash);
|
|
148
|
+
this.sheetToHash.delete(sheet);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Bulk acquire — returns an array of CSSStyleSheet in the same order.
|
|
153
|
+
*/
|
|
154
|
+
acquireAll(cssTexts) {
|
|
155
|
+
return cssTexts.map((text) => this.acquire(text));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Bulk release — decrements refCount for each sheet.
|
|
159
|
+
*/
|
|
160
|
+
releaseAll(sheets) {
|
|
161
|
+
for (const sheet of sheets) this.release(sheet);
|
|
162
|
+
}
|
|
163
|
+
/** Number of unique sheets currently held. */
|
|
164
|
+
get size() {
|
|
165
|
+
return this.sheets.size;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
/** Module-level singleton shared across the entire application. */
|
|
169
|
+
const chunkSheetRegistry = new ChunkSheetRegistry();
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/injector/index.ts
|
|
172
|
+
/**
|
|
173
|
+
* Inject styles and return className with dispose function
|
|
174
|
+
*/
|
|
175
|
+
function inject(rules, options) {
|
|
176
|
+
const injector = getGlobalInjector();
|
|
177
|
+
markStylesGenerated();
|
|
178
|
+
return injector.inject(rules, options);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Inject global rules that should not reserve tasty class names
|
|
182
|
+
*/
|
|
183
|
+
function injectGlobal(rules, options) {
|
|
184
|
+
return getGlobalInjector().injectGlobal(rules, options);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Inject raw CSS text directly without parsing
|
|
188
|
+
* This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.
|
|
189
|
+
* The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```tsx
|
|
193
|
+
* // Inject raw CSS
|
|
194
|
+
* const { dispose } = injectRawCSS(`
|
|
195
|
+
* body { margin: 0; padding: 0; }
|
|
196
|
+
* .my-class { color: red; }
|
|
197
|
+
* `);
|
|
198
|
+
*
|
|
199
|
+
* // Later, remove the injected CSS
|
|
200
|
+
* dispose();
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
function injectRawCSS(css, options) {
|
|
204
|
+
return getGlobalInjector().injectRawCSS(css, options);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get raw CSS text for SSR
|
|
208
|
+
*/
|
|
209
|
+
function getRawCSSText(options) {
|
|
210
|
+
return getGlobalInjector().getRawCSSText(options);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Inject keyframes and return object with toString() and dispose()
|
|
214
|
+
*/
|
|
215
|
+
function keyframes(steps, nameOrOptions) {
|
|
216
|
+
return getGlobalInjector().keyframes(steps, nameOrOptions);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Define a CSS @property custom property.
|
|
220
|
+
* This enables advanced features like animating custom properties.
|
|
221
|
+
*
|
|
222
|
+
* Note: @property rules are global and persistent once defined.
|
|
223
|
+
* Re-registering the same property name is a no-op.
|
|
224
|
+
*
|
|
225
|
+
* @param name - The custom property name (must start with --)
|
|
226
|
+
* @param options - Property configuration
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* // Define a color property that can be animated
|
|
231
|
+
* property('--my-color', {
|
|
232
|
+
* syntax: '<color>',
|
|
233
|
+
* initialValue: 'red',
|
|
234
|
+
* });
|
|
235
|
+
*
|
|
236
|
+
* // Define an angle property
|
|
237
|
+
* property('--rotation', {
|
|
238
|
+
* syntax: '<angle>',
|
|
239
|
+
* inherits: false,
|
|
240
|
+
* initialValue: '0deg',
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
function property(name, options) {
|
|
245
|
+
return getGlobalInjector().property(name, options);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Check if a CSS @property has already been defined
|
|
249
|
+
*
|
|
250
|
+
* @param name - The custom property name to check
|
|
251
|
+
* @param options - Options including root
|
|
252
|
+
*/
|
|
253
|
+
function isPropertyDefined(name, options) {
|
|
254
|
+
return getGlobalInjector().isPropertyDefined(name, options);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Inject a CSS @font-face rule.
|
|
258
|
+
*
|
|
259
|
+
* Permanent and global — no dispose or ref-counting.
|
|
260
|
+
* Deduplicates by content hash (family + descriptors).
|
|
261
|
+
*/
|
|
262
|
+
function fontFace(family, descriptors, options) {
|
|
263
|
+
return getGlobalInjector().fontFace(family, descriptors, options);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Inject a CSS @counter-style rule.
|
|
267
|
+
*
|
|
268
|
+
* Permanent and global — no dispose or ref-counting.
|
|
269
|
+
* Deduplicates by name (first definition wins).
|
|
270
|
+
*/
|
|
271
|
+
function counterStyle(name, descriptors, options) {
|
|
272
|
+
return getGlobalInjector().counterStyle(name, descriptors, options);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get CSS text from all sheets (for SSR)
|
|
276
|
+
*/
|
|
277
|
+
function getCssText(options) {
|
|
278
|
+
return getGlobalInjector().getCssText(options);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Collect only CSS used by a rendered subtree (like jest-styled-components).
|
|
282
|
+
* Pass the container returned by render(...).
|
|
283
|
+
*/
|
|
284
|
+
function getCssTextForNode(node, options) {
|
|
285
|
+
const classSet = /* @__PURE__ */ new Set();
|
|
286
|
+
const readClasses = (el) => {
|
|
287
|
+
const cls = el.getAttribute("class");
|
|
288
|
+
if (!cls) return;
|
|
289
|
+
for (const token of cls.split(/\s+/)) if (/^t[a-z0-9]+$/.test(token)) classSet.add(token);
|
|
290
|
+
};
|
|
291
|
+
if (node.getAttribute) readClasses(node);
|
|
292
|
+
const elements = node.querySelectorAll ? node.querySelectorAll("[class]") : [];
|
|
293
|
+
if (elements) elements.forEach(readClasses);
|
|
294
|
+
return getGlobalInjector().getCssTextForClasses(classSet, options);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Force cleanup of unused rules
|
|
298
|
+
*/
|
|
299
|
+
function cleanup(root) {
|
|
300
|
+
return getGlobalInjector().cleanup(root);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Record a render-time usage hit for one or more classNames.
|
|
304
|
+
* Used internally by computeStyles and tasty() to track usage for GC.
|
|
305
|
+
* When the global touch counter reaches `touchInterval`, schedules GC.
|
|
306
|
+
*/
|
|
307
|
+
function touch(className, options) {
|
|
308
|
+
if (!getConfig().gc) return;
|
|
309
|
+
getGlobalInjector().touch(className, options);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Synchronous garbage collection of unused styles.
|
|
313
|
+
* Evicts the oldest unused styles when usageMap exceeds capacity.
|
|
314
|
+
* With `{ force: true }`, removes ALL unused styles regardless of capacity.
|
|
315
|
+
*
|
|
316
|
+
* @returns Number of styles evicted.
|
|
317
|
+
*/
|
|
318
|
+
function gc(options) {
|
|
319
|
+
return getGlobalInjector().gc(options);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Check if we're currently running in a test environment
|
|
323
|
+
*/
|
|
324
|
+
function getIsTestEnvironment() {
|
|
325
|
+
return isTestEnvironment();
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get the global injector instance for debugging
|
|
329
|
+
*/
|
|
330
|
+
const injector = { get instance() {
|
|
331
|
+
return getGlobalInjector();
|
|
332
|
+
} };
|
|
333
|
+
/**
|
|
334
|
+
* Destroy all resources and clean up
|
|
335
|
+
*/
|
|
336
|
+
function destroy(root) {
|
|
337
|
+
return getGlobalInjector().destroy(root);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Create a new isolated injector instance
|
|
341
|
+
*/
|
|
342
|
+
function createInjector(config = {}) {
|
|
343
|
+
return new StyleInjector({
|
|
344
|
+
...getConfig(),
|
|
345
|
+
forceTextInjection: config.forceTextInjection ?? isTestEnvironment(),
|
|
346
|
+
...config
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/rsc-cache.ts
|
|
351
|
+
/**
|
|
352
|
+
* Shared RSC (React Server Components) inline style cache.
|
|
353
|
+
*
|
|
354
|
+
* Uses React.cache for per-request memoization in Server Components.
|
|
355
|
+
* Both computeStyles() and standalone style functions (useGlobalStyles,
|
|
356
|
+
* useRawCSS, useKeyframes, useProperty, useFontFace, useCounterStyle)
|
|
357
|
+
* share this cache so that CSS accumulated by standalone functions is
|
|
358
|
+
* flushed into inline <style> tags by the next tasty() component.
|
|
359
|
+
*/
|
|
360
|
+
/**
|
|
361
|
+
* Per-request RSC style cache using React.cache.
|
|
362
|
+
* React.cache provides per-request memoization in Server Components,
|
|
363
|
+
* so each request gets its own isolated cache.
|
|
364
|
+
*/
|
|
365
|
+
const getRSCCache = cache(() => ({
|
|
366
|
+
cacheKeyToClassName: /* @__PURE__ */ new Map(),
|
|
367
|
+
emittedKeys: /* @__PURE__ */ new Set(),
|
|
368
|
+
internalsEmitted: false,
|
|
369
|
+
pendingCSS: [],
|
|
370
|
+
generatedNames: /* @__PURE__ */ new Map()
|
|
371
|
+
}));
|
|
372
|
+
function rscAllocateClassName(rscCache, cacheKey) {
|
|
373
|
+
const existing = rscCache.cacheKeyToClassName.get(cacheKey);
|
|
374
|
+
if (existing) return {
|
|
375
|
+
className: existing,
|
|
376
|
+
isNew: false
|
|
377
|
+
};
|
|
378
|
+
const className = `t${hashString(cacheKey)}`;
|
|
379
|
+
rscCache.cacheKeyToClassName.set(cacheKey, className);
|
|
380
|
+
return {
|
|
381
|
+
className,
|
|
382
|
+
isNew: true
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Flush any pending CSS accumulated by standalone functions.
|
|
387
|
+
* Returns the CSS string and clears the buffer.
|
|
388
|
+
*/
|
|
389
|
+
function flushPendingCSS(rscCache) {
|
|
390
|
+
if (rscCache.pendingCSS.length === 0) return "";
|
|
391
|
+
const css = rscCache.pendingCSS.join("\n");
|
|
392
|
+
rscCache.pendingCSS.length = 0;
|
|
393
|
+
return css;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Push CSS into the RSC pending buffer with dedup via emittedKeys.
|
|
397
|
+
* Returns true if the CSS was added, false if it was already emitted.
|
|
398
|
+
*/
|
|
399
|
+
function pushRSCCSS(rscCache, key, css) {
|
|
400
|
+
if (rscCache.emittedKeys.has(key)) return false;
|
|
401
|
+
rscCache.emittedKeys.add(key);
|
|
402
|
+
rscCache.pendingCSS.push(css);
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Determine the current style injection target.
|
|
407
|
+
* Centralizes the three-way detection (SSR collector / RSC cache / client DOM)
|
|
408
|
+
* used by all style functions.
|
|
409
|
+
*/
|
|
410
|
+
function getStyleTarget() {
|
|
411
|
+
const collector = getRegisteredSSRCollector();
|
|
412
|
+
if (collector) return {
|
|
413
|
+
mode: "ssr",
|
|
414
|
+
collector
|
|
415
|
+
};
|
|
416
|
+
if (typeof document === "undefined") return {
|
|
417
|
+
mode: "rsc",
|
|
418
|
+
cache: getRSCCache()
|
|
419
|
+
};
|
|
420
|
+
return { mode: "client" };
|
|
421
|
+
}
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/ssr/collect-auto-properties.ts
|
|
424
|
+
/**
|
|
425
|
+
* Scan rendered rules for auto-inferable custom properties and emit
|
|
426
|
+
* @property CSS via the provided callback.
|
|
427
|
+
*/
|
|
428
|
+
function scanAndEmitAutoProperties(rules, styles, emit) {
|
|
429
|
+
const registered = /* @__PURE__ */ new Set();
|
|
430
|
+
if (styles) {
|
|
431
|
+
const localProps = styles["@properties"];
|
|
432
|
+
if (localProps && typeof localProps === "object") for (const token of Object.keys(localProps)) {
|
|
433
|
+
const parsed = parsePropertyToken(token);
|
|
434
|
+
if (parsed.isValid) registered.add(parsed.cssName);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
const resolver = new PropertyTypeResolver();
|
|
438
|
+
for (const rule of rules) {
|
|
439
|
+
if (!rule.declarations) continue;
|
|
440
|
+
resolver.scanDeclarations(rule.declarations, (name) => registered.has(name), (name, syntax, initialValue) => {
|
|
441
|
+
registered.add(name);
|
|
442
|
+
const css = formatPropertyCSS(name, {
|
|
443
|
+
syntax,
|
|
444
|
+
inherits: true,
|
|
445
|
+
initialValue
|
|
446
|
+
});
|
|
447
|
+
if (css) emit(name, css);
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Scan rendered rules for custom property declarations and collect
|
|
453
|
+
* auto-inferred @property rules via the SSR collector.
|
|
454
|
+
*
|
|
455
|
+
* @param rules - Rendered style rules containing CSS declarations
|
|
456
|
+
* @param collector - SSR collector to emit @property CSS into
|
|
457
|
+
* @param styles - Original styles object (used to skip explicit @properties)
|
|
458
|
+
*/
|
|
459
|
+
function collectAutoInferredProperties(rules, collector, styles) {
|
|
460
|
+
scanAndEmitAutoProperties(rules, styles, (name, css) => {
|
|
461
|
+
collector.collectProperty(`__auto:${name}`, css);
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* RSC variant: scan rendered rules and push auto-inferred @property CSS
|
|
466
|
+
* into the RSC pending buffer.
|
|
467
|
+
*/
|
|
468
|
+
function collectAutoInferredPropertiesRSC(rules, rscCache, styles) {
|
|
469
|
+
scanAndEmitAutoProperties(rules, styles, (name, css) => {
|
|
470
|
+
pushRSCCSS(rscCache, `__auto:${name}`, css);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/ssr/format-keyframes.ts
|
|
475
|
+
/**
|
|
476
|
+
* Convert keyframes steps to a CSS string.
|
|
477
|
+
* Replicates SheetManager.stepsToCSS() without the class instance.
|
|
478
|
+
*/
|
|
479
|
+
function stepsToCSS(steps) {
|
|
480
|
+
const rules = [];
|
|
481
|
+
for (const [key, value] of Object.entries(steps)) {
|
|
482
|
+
if (typeof value === "string") {
|
|
483
|
+
rules.push(`${key} { ${value.trim()} }`);
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
const styleMap = value || {};
|
|
487
|
+
const styleNames = Object.keys(styleMap).sort();
|
|
488
|
+
const handlerQueue = [];
|
|
489
|
+
const seenHandlers = /* @__PURE__ */ new Set();
|
|
490
|
+
styleNames.forEach((styleName) => {
|
|
491
|
+
let handlers = STYLE_HANDLER_MAP[styleName];
|
|
492
|
+
if (!handlers) handlers = STYLE_HANDLER_MAP[styleName] = [createStyle(styleName)];
|
|
493
|
+
handlers.forEach((handler) => {
|
|
494
|
+
if (!seenHandlers.has(handler)) {
|
|
495
|
+
seenHandlers.add(handler);
|
|
496
|
+
handlerQueue.push(handler);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
const declarationPairs = [];
|
|
501
|
+
handlerQueue.forEach((handler) => {
|
|
502
|
+
const result = handler(handler.__lookupStyles.reduce((acc, name) => {
|
|
503
|
+
const v = styleMap[name];
|
|
504
|
+
if (v !== void 0) acc[name] = v;
|
|
505
|
+
return acc;
|
|
506
|
+
}, {}));
|
|
507
|
+
if (!result) return;
|
|
508
|
+
(Array.isArray(result) ? result : [result]).forEach((cssMap) => {
|
|
509
|
+
if (!cssMap || typeof cssMap !== "object") return;
|
|
510
|
+
const { $: _$, ...props } = cssMap;
|
|
511
|
+
Object.entries(props).forEach(([prop, val]) => {
|
|
512
|
+
if (val == null || val === "") return;
|
|
513
|
+
if (Array.isArray(val)) val.forEach((v) => {
|
|
514
|
+
if (v != null && v !== "") declarationPairs.push({
|
|
515
|
+
prop,
|
|
516
|
+
value: String(v)
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
else declarationPairs.push({
|
|
520
|
+
prop,
|
|
521
|
+
value: String(val)
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
const declarations = declarationPairs.map((d) => `${d.prop}: ${d.value}`).join("; ");
|
|
527
|
+
rules.push(`${key} { ${declarations.trim()} }`);
|
|
528
|
+
}
|
|
529
|
+
return rules.join(" ");
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Format a @keyframes rule as a CSS string.
|
|
533
|
+
*/
|
|
534
|
+
function formatKeyframesCSS(name, steps) {
|
|
535
|
+
return `@keyframes ${name} { ${stepsToCSS(steps)} }`;
|
|
536
|
+
}
|
|
537
|
+
//#endregion
|
|
538
|
+
//#region src/utils/has-keys.ts
|
|
539
|
+
/**
|
|
540
|
+
* Check if an object has any own enumerable keys.
|
|
541
|
+
* Avoids the array allocation of Object.keys(obj).length > 0.
|
|
542
|
+
*/
|
|
543
|
+
function hasKeys(obj) {
|
|
544
|
+
for (const _ in obj) return true;
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region src/compute-styles.ts
|
|
549
|
+
/**
|
|
550
|
+
* Hook-free, synchronous style computation.
|
|
551
|
+
*
|
|
552
|
+
* Extracts the core logic from useStyles() into a plain function that can
|
|
553
|
+
* be called during React render without any hooks. Three code paths:
|
|
554
|
+
*
|
|
555
|
+
* 1. SSR collector — styles collected via ServerStyleCollector
|
|
556
|
+
* 2. Client inject — styles injected synchronously into the DOM
|
|
557
|
+
* 3. RSC inline — styles returned as CSS strings for inline <style> emission
|
|
558
|
+
*
|
|
559
|
+
* This enables tasty() components to work as React Server Components.
|
|
560
|
+
*/
|
|
561
|
+
const EMPTY_RESULT = { className: "" };
|
|
562
|
+
/**
|
|
563
|
+
* Mark internals as emitted for this RSC request.
|
|
564
|
+
*
|
|
565
|
+
* Internals (tokens, @property, @font-face, @counter-style) are emitted
|
|
566
|
+
* exclusively by the SSR collector via ServerStyleCollector.collectInternals().
|
|
567
|
+
* The SSR path is reliable because TastyRegistry is always present as a
|
|
568
|
+
* client component in the root layout, guaranteeing SSR runs for every page.
|
|
569
|
+
*
|
|
570
|
+
* Previously this function also emitted internals and coordinated with SSR
|
|
571
|
+
* via a globalThis flag, but that flag leaked across requests in the same
|
|
572
|
+
* Node.js process, causing pages without RSC-rendered tasty components
|
|
573
|
+
* (e.g. the playground route) to lose all token CSS.
|
|
574
|
+
*/
|
|
575
|
+
function collectInternalsRSC(rscCache) {
|
|
576
|
+
if (rscCache.internalsEmitted) return "";
|
|
577
|
+
rscCache.internalsEmitted = true;
|
|
578
|
+
return "";
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Collect per-component ancillary CSS (keyframes, @property, font-face,
|
|
582
|
+
* counter-style) for RSC mode.
|
|
583
|
+
*/
|
|
584
|
+
function collectAncillaryRSC(rscCache, styles) {
|
|
585
|
+
const parts = [];
|
|
586
|
+
const usedKf = getUsedKeyframes(styles);
|
|
587
|
+
if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
|
|
588
|
+
const key = `__kf:${name}:${JSON.stringify(steps)}`;
|
|
589
|
+
if (!rscCache.emittedKeys.has(key)) {
|
|
590
|
+
rscCache.emittedKeys.add(key);
|
|
591
|
+
parts.push(formatKeyframesCSS(name, steps));
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (hasLocalProperties(styles)) {
|
|
595
|
+
const localProperties = extractLocalProperties(styles);
|
|
596
|
+
if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
|
|
597
|
+
const key = `__prop:${token}`;
|
|
598
|
+
if (!rscCache.emittedKeys.has(key)) {
|
|
599
|
+
rscCache.emittedKeys.add(key);
|
|
600
|
+
const css = formatPropertyCSS(token, definition);
|
|
601
|
+
if (css) parts.push(css);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
if (hasLocalFontFace(styles)) {
|
|
606
|
+
const localFontFace = extractLocalFontFace(styles);
|
|
607
|
+
if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
|
|
608
|
+
const descriptors = Array.isArray(input) ? input : [input];
|
|
609
|
+
for (const desc of descriptors) {
|
|
610
|
+
const key = `__ff:${fontFaceContentHash(family, desc)}`;
|
|
611
|
+
if (!rscCache.emittedKeys.has(key)) {
|
|
612
|
+
rscCache.emittedKeys.add(key);
|
|
613
|
+
parts.push(formatFontFaceRule(family, desc));
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (hasLocalCounterStyle(styles)) {
|
|
619
|
+
const localCounterStyle = extractLocalCounterStyle(styles);
|
|
620
|
+
if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) {
|
|
621
|
+
const key = `__cs:${name}:${JSON.stringify(descriptors)}`;
|
|
622
|
+
if (!rscCache.emittedKeys.has(key)) {
|
|
623
|
+
rscCache.emittedKeys.add(key);
|
|
624
|
+
parts.push(formatCounterStyleRule(name, descriptors));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return parts.join("\n");
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Process all chunks in RSC mode: render CSS to strings, allocate classNames,
|
|
632
|
+
* and return combined { className, css }.
|
|
633
|
+
*/
|
|
634
|
+
function computeStylesRSC(styles, chunkMap) {
|
|
635
|
+
const rscCache = getRSCCache();
|
|
636
|
+
const cssParts = [];
|
|
637
|
+
const classNames = [];
|
|
638
|
+
const pendingCSS = flushPendingCSS(rscCache);
|
|
639
|
+
if (pendingCSS) cssParts.push(pendingCSS);
|
|
640
|
+
const internalsCSS = collectInternalsRSC(rscCache);
|
|
641
|
+
if (internalsCSS) cssParts.push(internalsCSS);
|
|
642
|
+
for (const [chunkName, chunkStyleKeys] of chunkMap) {
|
|
643
|
+
if (chunkStyleKeys.length === 0) continue;
|
|
644
|
+
const { className, isNew } = rscAllocateClassName(rscCache, generateChunkCacheKey(styles, chunkName, chunkStyleKeys));
|
|
645
|
+
classNames.push(className);
|
|
646
|
+
if (isNew) {
|
|
647
|
+
const renderResult = renderStylesForChunk(styles, chunkName, chunkStyleKeys);
|
|
648
|
+
if (renderResult.rules.length > 0) {
|
|
649
|
+
const css = formatRules(renderResult.rules, className);
|
|
650
|
+
if (css) cssParts.push(css);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
const ancillaryCSS = collectAncillaryRSC(rscCache, styles);
|
|
655
|
+
if (ancillaryCSS) cssParts.push(ancillaryCSS);
|
|
656
|
+
if (classNames.length === 0) return EMPTY_RESULT;
|
|
657
|
+
const css = cssParts.join("\n");
|
|
658
|
+
return {
|
|
659
|
+
className: classNames.join(" "),
|
|
660
|
+
css: css || void 0
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Get keyframes that are actually used in styles.
|
|
665
|
+
* Returns null if no keyframes are used (fast path for zero overhead).
|
|
666
|
+
*/
|
|
667
|
+
function getUsedKeyframes(styles) {
|
|
668
|
+
const hasLocal = hasLocalKeyframes(styles);
|
|
669
|
+
const hasGlobal = hasGlobalKeyframes();
|
|
670
|
+
if (!hasLocal && !hasGlobal) return null;
|
|
671
|
+
const usedNames = extractAnimationNamesFromStyles(styles);
|
|
672
|
+
if (usedNames.size === 0) return null;
|
|
673
|
+
return filterUsedKeyframes(mergeKeyframes(hasLocal ? extractLocalKeyframes(styles) : null, hasGlobal ? getGlobalKeyframes() : null), usedNames);
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Process a chunk on the SSR path: allocate via collector, render, collect CSS.
|
|
677
|
+
*/
|
|
678
|
+
function processChunkSSR(collector, styles, chunkName, styleKeys) {
|
|
679
|
+
if (styleKeys.length === 0) return null;
|
|
680
|
+
const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
|
|
681
|
+
const { className, isNewAllocation } = collector.allocateClassName(cacheKey);
|
|
682
|
+
if (isNewAllocation) {
|
|
683
|
+
const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);
|
|
684
|
+
if (renderResult.rules.length > 0) {
|
|
685
|
+
collector.collectChunk(cacheKey, className, renderResult.rules);
|
|
686
|
+
return {
|
|
687
|
+
name: chunkName,
|
|
688
|
+
styleKeys,
|
|
689
|
+
cacheKey,
|
|
690
|
+
renderResult,
|
|
691
|
+
className
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
return {
|
|
697
|
+
name: chunkName,
|
|
698
|
+
styleKeys,
|
|
699
|
+
cacheKey,
|
|
700
|
+
renderResult: { rules: [] },
|
|
701
|
+
className
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Process a chunk on the client: render, allocate className, and inject
|
|
706
|
+
* CSS synchronously. The injector's cache makes this idempotent.
|
|
707
|
+
*/
|
|
708
|
+
function processChunkSync(styles, chunkName, styleKeys, root) {
|
|
709
|
+
if (styleKeys.length === 0) return null;
|
|
710
|
+
const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
|
|
711
|
+
const renderResult = renderStylesForChunk(styles, chunkName, styleKeys, cacheKey);
|
|
712
|
+
if (renderResult.rules.length === 0) return null;
|
|
713
|
+
const { className } = inject(renderResult.rules, {
|
|
714
|
+
cacheKey,
|
|
715
|
+
root
|
|
716
|
+
});
|
|
717
|
+
return {
|
|
718
|
+
name: chunkName,
|
|
719
|
+
styleKeys,
|
|
720
|
+
cacheKey,
|
|
721
|
+
renderResult,
|
|
722
|
+
className
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Inject keyframes synchronously and return a name replacement map.
|
|
727
|
+
* On the client, keyframes are injected into the DOM.
|
|
728
|
+
*/
|
|
729
|
+
function injectKeyframesSync(usedKeyframes, root) {
|
|
730
|
+
let nameMap = null;
|
|
731
|
+
for (const [name, steps] of Object.entries(usedKeyframes)) {
|
|
732
|
+
const injectedName = keyframes(steps, {
|
|
733
|
+
name,
|
|
734
|
+
root
|
|
735
|
+
}).toString();
|
|
736
|
+
if (injectedName !== name) {
|
|
737
|
+
if (!nameMap) nameMap = /* @__PURE__ */ new Map();
|
|
738
|
+
nameMap.set(name, injectedName);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return nameMap;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Inject chunk rules synchronously, replacing animation names if needed.
|
|
745
|
+
*/
|
|
746
|
+
function injectChunkRulesSync(chunks, nameMap, root) {
|
|
747
|
+
for (const chunk of chunks) if (chunk.renderResult.rules.length > 0) inject(nameMap ? chunk.renderResult.rules.map((rule) => ({
|
|
748
|
+
...rule,
|
|
749
|
+
declarations: replaceAnimationNames(rule.declarations, nameMap)
|
|
750
|
+
})) : chunk.renderResult.rules, {
|
|
751
|
+
cacheKey: chunk.cacheKey,
|
|
752
|
+
root
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Inject all ancillary rules (properties, font-faces, counter-styles) synchronously.
|
|
757
|
+
*/
|
|
758
|
+
function injectAncillarySync(styles, root) {
|
|
759
|
+
if (hasLocalProperties(styles)) {
|
|
760
|
+
const localProperties = extractLocalProperties(styles);
|
|
761
|
+
if (localProperties) for (const [token, definition] of Object.entries(localProperties)) property(token, {
|
|
762
|
+
...definition,
|
|
763
|
+
root
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
if (hasLocalFontFace(styles)) {
|
|
767
|
+
const localFontFace = extractLocalFontFace(styles);
|
|
768
|
+
if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
|
|
769
|
+
const descriptors = Array.isArray(input) ? input : [input];
|
|
770
|
+
for (const desc of descriptors) fontFace(family, desc, { root });
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
if (hasLocalCounterStyle(styles)) {
|
|
774
|
+
const localCounterStyle = extractLocalCounterStyle(styles);
|
|
775
|
+
if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) counterStyle(name, descriptors, { root });
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Collect all ancillary rules into the SSR collector.
|
|
780
|
+
*/
|
|
781
|
+
function collectAncillarySSR(collector, styles, chunks) {
|
|
782
|
+
const usedKf = getUsedKeyframes(styles);
|
|
783
|
+
if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
|
|
784
|
+
const css = formatKeyframesCSS(name, steps);
|
|
785
|
+
collector.collectKeyframes(name, css);
|
|
786
|
+
}
|
|
787
|
+
if (hasLocalProperties(styles)) {
|
|
788
|
+
const localProperties = extractLocalProperties(styles);
|
|
789
|
+
if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
|
|
790
|
+
const css = formatPropertyCSS(token, definition);
|
|
791
|
+
if (css) collector.collectProperty(token, css);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
if (hasLocalFontFace(styles)) {
|
|
795
|
+
const localFontFace = extractLocalFontFace(styles);
|
|
796
|
+
if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
|
|
797
|
+
const descriptors = Array.isArray(input) ? input : [input];
|
|
798
|
+
for (const desc of descriptors) {
|
|
799
|
+
const hash = fontFaceContentHash(family, desc);
|
|
800
|
+
const css = formatFontFaceRule(family, desc);
|
|
801
|
+
collector.collectFontFace(hash, css);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (hasLocalCounterStyle(styles)) {
|
|
806
|
+
const localCounterStyle = extractLocalCounterStyle(styles);
|
|
807
|
+
if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) {
|
|
808
|
+
const css = formatCounterStyleRule(name, descriptors);
|
|
809
|
+
collector.collectCounterStyle(name, css);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
if (getConfig().autoPropertyTypes !== false) {
|
|
813
|
+
const allRules = chunks.flatMap((c) => c.renderResult.rules);
|
|
814
|
+
if (allRules.length > 0) collectAutoInferredProperties(allRules, collector, styles);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Synchronous, hook-free style computation.
|
|
819
|
+
*
|
|
820
|
+
* Resolves recipes, categorizes style keys into chunks, renders CSS rules,
|
|
821
|
+
* allocates class names, and injects / collects / returns the CSS.
|
|
822
|
+
*
|
|
823
|
+
* Three code paths:
|
|
824
|
+
* 1. SSR collector — discovered via ALS or passed explicitly; CSS collected
|
|
825
|
+
* 2. RSC inline — no collector and no `document`; CSS returned as `result.css`
|
|
826
|
+
* for the caller to emit as an inline `<style>` tag
|
|
827
|
+
* 3. Client inject — CSS injected synchronously into the DOM (idempotent)
|
|
828
|
+
*
|
|
829
|
+
* @param styles - Tasty styles object (or undefined for no styles)
|
|
830
|
+
* @param options - Optional SSR collector override
|
|
831
|
+
*/
|
|
832
|
+
function computeStyles(styles, options) {
|
|
833
|
+
if (!styles || !hasKeys(styles)) return EMPTY_RESULT;
|
|
834
|
+
const resolved = resolveRecipes(styles);
|
|
835
|
+
const chunkMap = categorizeStyleKeys(resolved);
|
|
836
|
+
const collector = options?.ssrCollector !== void 0 ? options.ssrCollector : getRegisteredSSRCollector();
|
|
837
|
+
const chunks = [];
|
|
838
|
+
if (collector) {
|
|
839
|
+
collector.collectInternals();
|
|
840
|
+
for (const [chunkName, chunkStyleKeys] of chunkMap) {
|
|
841
|
+
const chunk = processChunkSSR(collector, resolved, chunkName, chunkStyleKeys);
|
|
842
|
+
if (chunk) chunks.push(chunk);
|
|
843
|
+
}
|
|
844
|
+
collectAncillarySSR(collector, resolved, chunks);
|
|
845
|
+
} else if (typeof document === "undefined") return computeStylesRSC(resolved, chunkMap);
|
|
846
|
+
else {
|
|
847
|
+
const root = options?.root;
|
|
848
|
+
injectAncillarySync(resolved, root);
|
|
849
|
+
const usedKf = getUsedKeyframes(resolved);
|
|
850
|
+
const nameMap = usedKf ? injectKeyframesSync(usedKf, root) : null;
|
|
851
|
+
for (const [chunkName, chunkStyleKeys] of chunkMap) {
|
|
852
|
+
const chunk = processChunkSync(resolved, chunkName, chunkStyleKeys, root);
|
|
853
|
+
if (chunk) chunks.push(chunk);
|
|
854
|
+
}
|
|
855
|
+
if (nameMap) injectChunkRulesSync(chunks, nameMap, root);
|
|
856
|
+
for (const chunk of chunks) touch(chunk.className, { root });
|
|
857
|
+
}
|
|
858
|
+
if (chunks.length === 0) return EMPTY_RESULT;
|
|
859
|
+
if (chunks.length === 1) return { className: chunks[0].className };
|
|
860
|
+
return { className: chunks.map((c) => c.className).join(" ") };
|
|
861
|
+
}
|
|
862
|
+
//#endregion
|
|
863
|
+
//#region src/utils/filter-base-props.ts
|
|
864
|
+
const DOMPropNames = new Set(["id"]);
|
|
865
|
+
const BasePropNames = new Set([
|
|
866
|
+
"role",
|
|
867
|
+
"as",
|
|
868
|
+
"element",
|
|
869
|
+
"css",
|
|
870
|
+
"qa",
|
|
871
|
+
"mods",
|
|
872
|
+
"qaVal",
|
|
873
|
+
"hidden",
|
|
874
|
+
"isHidden",
|
|
875
|
+
"disabled",
|
|
876
|
+
"isDisabled",
|
|
877
|
+
"children",
|
|
878
|
+
"style",
|
|
879
|
+
"className",
|
|
880
|
+
"href",
|
|
881
|
+
"target",
|
|
882
|
+
"tabIndex"
|
|
883
|
+
]);
|
|
884
|
+
const ignoreEventPropsNames = new Set([
|
|
885
|
+
"onPress",
|
|
886
|
+
"onHoverStart",
|
|
887
|
+
"onHoverEnd",
|
|
888
|
+
"onPressStart",
|
|
889
|
+
"onPressEnd"
|
|
890
|
+
]);
|
|
891
|
+
const propRe = /^((data-).*)$/;
|
|
892
|
+
const eventRe = /^on[A-Z].+$/;
|
|
893
|
+
/**
|
|
894
|
+
* Filters out all props that aren't valid DOM props or defined via override prop obj.
|
|
895
|
+
* @param props - The component props to be filtered.
|
|
896
|
+
* @param opts - Props to override.
|
|
897
|
+
*/
|
|
898
|
+
function filterBaseProps(props, opts = {}) {
|
|
899
|
+
const { propNames, eventProps } = opts;
|
|
900
|
+
const filteredProps = {};
|
|
901
|
+
for (const prop in props) if (Object.prototype.hasOwnProperty.call(props, prop) && (DOMPropNames.has(prop) || BasePropNames.has(prop) || prop.startsWith("aria-") || eventProps && eventRe.test(prop) && !ignoreEventPropsNames.has(prop) || propNames?.has(prop) || propRe.test(prop))) filteredProps[prop] = props[prop];
|
|
902
|
+
return filteredProps;
|
|
903
|
+
}
|
|
904
|
+
//#endregion
|
|
905
|
+
//#region src/utils/colors.ts
|
|
906
|
+
function color(name, opacity = 1) {
|
|
907
|
+
if (opacity !== 1) return `${getColorSpaceFunc()}(var(--${name}-color-${getColorSpaceSuffix()}) / ${opacity})`;
|
|
908
|
+
return `var(--${name}-color)`;
|
|
909
|
+
}
|
|
910
|
+
//#endregion
|
|
911
|
+
//#region src/utils/cache-wrapper.ts
|
|
912
|
+
/**
|
|
913
|
+
* Create a function that caches the result with LRU eviction.
|
|
914
|
+
*/
|
|
915
|
+
function cacheWrapper(handler, limit = 1e3) {
|
|
916
|
+
const cache = new Lru(limit);
|
|
917
|
+
return (firstArg, secondArg) => {
|
|
918
|
+
const key = typeof firstArg === "string" && secondArg == null ? firstArg : JSON.stringify([firstArg, secondArg]);
|
|
919
|
+
let result = cache.get(key);
|
|
920
|
+
if (result === void 0) {
|
|
921
|
+
result = secondArg == null ? handler(firstArg) : handler(firstArg, secondArg);
|
|
922
|
+
cache.set(key, result);
|
|
923
|
+
}
|
|
924
|
+
return result;
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
//#endregion
|
|
928
|
+
//#region src/utils/mod-attrs.ts
|
|
929
|
+
function modAttrs(map) {
|
|
930
|
+
return map ? Object.keys(map).reduce((attrs, key) => {
|
|
931
|
+
const value = map[key];
|
|
932
|
+
if (value == null || value === false) return attrs;
|
|
933
|
+
const attrName = `data-${camelToKebab(key)}`;
|
|
934
|
+
if (value === true) attrs[attrName] = "";
|
|
935
|
+
else if (typeof value === "string") attrs[attrName] = value;
|
|
936
|
+
else if (typeof value === "number") attrs[attrName] = String(value);
|
|
937
|
+
else console.warn(`Tasty: Invalid mod value for "${key}". Expected boolean, string, or number, got ${typeof value}`);
|
|
938
|
+
return attrs;
|
|
939
|
+
}, {}) : null;
|
|
940
|
+
}
|
|
941
|
+
const _modAttrs = cacheWrapper(modAttrs);
|
|
942
|
+
//#endregion
|
|
943
|
+
//#region src/utils/dotize.ts
|
|
944
|
+
const dotize = {
|
|
945
|
+
valTypes: {
|
|
946
|
+
none: "NONE",
|
|
947
|
+
primitive: "PRIM",
|
|
948
|
+
object: "OBJECT",
|
|
949
|
+
array: "ARRAY"
|
|
950
|
+
},
|
|
951
|
+
getValType: function(val) {
|
|
952
|
+
if (!val || typeof val != "object" || Array.isArray(val)) return dotize.valTypes.primitive;
|
|
953
|
+
if (typeof val == "object") return dotize.valTypes.object;
|
|
954
|
+
},
|
|
955
|
+
getPathType: function(arrPath) {
|
|
956
|
+
const arrPathTypes = [];
|
|
957
|
+
for (const path in arrPath) {
|
|
958
|
+
const pathVal = arrPath[path];
|
|
959
|
+
if (!pathVal) arrPathTypes.push(dotize.valTypes.none);
|
|
960
|
+
else if (dotize.isNumber(pathVal)) arrPathTypes.push(dotize.valTypes.array);
|
|
961
|
+
else arrPathTypes.push(dotize.valTypes.object);
|
|
962
|
+
}
|
|
963
|
+
return arrPathTypes;
|
|
964
|
+
},
|
|
965
|
+
isUndefined: function(obj) {
|
|
966
|
+
return typeof obj == "undefined";
|
|
967
|
+
},
|
|
968
|
+
isNumber: function(f) {
|
|
969
|
+
return !isNaN(parseInt(f));
|
|
970
|
+
},
|
|
971
|
+
isEmptyObj: function(obj) {
|
|
972
|
+
for (const prop in obj) if (Object.hasOwnProperty.call(obj, prop)) return false;
|
|
973
|
+
return JSON.stringify(obj) === JSON.stringify({});
|
|
974
|
+
},
|
|
975
|
+
isPlainObject: function(obj) {
|
|
976
|
+
if (typeof obj !== "object" || obj === null) return false;
|
|
977
|
+
return Object.getPrototypeOf(obj) === Object.prototype;
|
|
978
|
+
},
|
|
979
|
+
isNotObject: function(obj) {
|
|
980
|
+
return !obj || !this.isPlainObject(obj);
|
|
981
|
+
},
|
|
982
|
+
isEmptyArray: function(arr) {
|
|
983
|
+
return Array.isArray(arr) && arr.length == 0;
|
|
984
|
+
},
|
|
985
|
+
isNotArray: function(arr) {
|
|
986
|
+
return Array.isArray(arr) == false;
|
|
987
|
+
},
|
|
988
|
+
removeEmptyArrayItem: function(arr) {
|
|
989
|
+
return arr.filter(function(el) {
|
|
990
|
+
return el != null && el != "";
|
|
991
|
+
});
|
|
992
|
+
},
|
|
993
|
+
getFieldName: function(field, prefix, isRoot, isArrayItem, isArray) {
|
|
994
|
+
if (isArray) return (prefix ? prefix : "") + (dotize.isNumber(field) ? "[" + field + "]" : (isRoot && !prefix ? "" : ".") + field);
|
|
995
|
+
else if (isArrayItem) return (prefix ? prefix : "") + "[" + field + "]";
|
|
996
|
+
else return (prefix ? prefix + "." : "") + field;
|
|
997
|
+
},
|
|
998
|
+
startsWith: function(val, valToSearch) {
|
|
999
|
+
return val.indexOf(valToSearch) == 0;
|
|
1000
|
+
},
|
|
1001
|
+
convert: function(obj, prefix = "") {
|
|
1002
|
+
let newObj = {};
|
|
1003
|
+
if (dotize.isNotObject(obj)) if (prefix) {
|
|
1004
|
+
newObj[prefix] = obj;
|
|
1005
|
+
return newObj;
|
|
1006
|
+
} else return obj;
|
|
1007
|
+
return (function recurse(o, p, isRoot) {
|
|
1008
|
+
const isArrayItem = Array.isArray(o);
|
|
1009
|
+
for (const f in o) {
|
|
1010
|
+
const currentProp = o[f];
|
|
1011
|
+
if (currentProp && typeof currentProp === "object" && !Array.isArray(currentProp) && dotize.isPlainObject(currentProp)) {
|
|
1012
|
+
if (isArrayItem && dotize.isEmptyObj(currentProp) == false) newObj = recurse(currentProp, dotize.getFieldName(f, p, isRoot, true));
|
|
1013
|
+
else if (dotize.isEmptyObj(currentProp) == false) newObj = recurse(currentProp, dotize.getFieldName(f, p, isRoot));
|
|
1014
|
+
else if (dotize.isEmptyObj(currentProp)) newObj[dotize.getFieldName(f, p, isRoot, isArrayItem)] = currentProp;
|
|
1015
|
+
} else if (isArrayItem || dotize.isNumber(f)) newObj[dotize.getFieldName(f, p, isRoot, true)] = currentProp;
|
|
1016
|
+
else newObj[dotize.getFieldName(f, p, isRoot)] = currentProp;
|
|
1017
|
+
}
|
|
1018
|
+
return newObj;
|
|
1019
|
+
})(obj, prefix, true);
|
|
1020
|
+
},
|
|
1021
|
+
backward: function(obj, prefix) {
|
|
1022
|
+
let newObj = {};
|
|
1023
|
+
const arStartRegex = /\[(\d+)\]/g;
|
|
1024
|
+
if (dotize.isNotObject(obj) && dotize.isNotArray(obj)) if (prefix) return obj[prefix];
|
|
1025
|
+
else return obj;
|
|
1026
|
+
for (let tProp in obj) {
|
|
1027
|
+
const tPropVal = obj[tProp];
|
|
1028
|
+
if (prefix) {
|
|
1029
|
+
const prefixRegex = new RegExp("^" + prefix);
|
|
1030
|
+
tProp = tProp.replace(prefixRegex, "");
|
|
1031
|
+
}
|
|
1032
|
+
tProp = tProp.replace(arStartRegex, ".$1");
|
|
1033
|
+
if (dotize.startsWith(tProp, ".")) tProp = tProp.replace(/^\./, "");
|
|
1034
|
+
const arrPath = tProp.split(".");
|
|
1035
|
+
const arrPathTypes = dotize.getPathType(arrPath);
|
|
1036
|
+
if (!dotize.isUndefined(arrPathTypes) && arrPathTypes[0] == dotize.valTypes.array && Array.isArray(newObj) == false) newObj = [];
|
|
1037
|
+
(function recurse(rPropVal, rObj, rPropValPrev, rObjPrev) {
|
|
1038
|
+
let currentPath = arrPath.shift();
|
|
1039
|
+
const currentPathType = arrPathTypes.shift();
|
|
1040
|
+
if (typeof currentPath == "undefined" || currentPath == "") {
|
|
1041
|
+
newObj = rPropVal;
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
const isArray = currentPathType == dotize.valTypes.array;
|
|
1045
|
+
if (dotize.isNumber(currentPath)) currentPath = parseInt(currentPath);
|
|
1046
|
+
if (arrPath.length > 0) {
|
|
1047
|
+
if (typeof rObj[currentPath] == "undefined") if (isArray) rObj[currentPath] = [];
|
|
1048
|
+
else rObj[currentPath] = {};
|
|
1049
|
+
recurse(rPropVal, rObj[currentPath], currentPath, rObj);
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
if (currentPathType == dotize.valTypes.array && rPropValPrev && rObjPrev) {
|
|
1053
|
+
if (Array.isArray(rObjPrev[rPropValPrev]) == false) rObjPrev[rPropValPrev] = [];
|
|
1054
|
+
rObjPrev[rPropValPrev].push(rPropVal);
|
|
1055
|
+
} else rObj[currentPath] = rPropVal;
|
|
1056
|
+
})(tPropVal, newObj);
|
|
1057
|
+
}
|
|
1058
|
+
return newObj;
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
//#endregion
|
|
1062
|
+
//#region src/utils/process-tokens.ts
|
|
1063
|
+
/**
|
|
1064
|
+
* Extract color components in the configured color space.
|
|
1065
|
+
* Returns a CSS variable reference for token colors, or decomposed
|
|
1066
|
+
* components as a space-separated string.
|
|
1067
|
+
*/
|
|
1068
|
+
function extractColorSpaceValue(colorValue, parsedOutput) {
|
|
1069
|
+
const suffix = getColorSpaceSuffix();
|
|
1070
|
+
const varMatch = parsedOutput.match(/var\(--([a-z0-9-]+)-color\)/);
|
|
1071
|
+
if (varMatch) return `var(--${varMatch[1]}-color-${suffix})`;
|
|
1072
|
+
const components = getColorSpaceComponents(colorValue);
|
|
1073
|
+
if (components !== colorValue) return components;
|
|
1074
|
+
const componentsFromParsed = getColorSpaceComponents(parsedOutput);
|
|
1075
|
+
if (componentsFromParsed !== parsedOutput) return componentsFromParsed;
|
|
1076
|
+
return parsedOutput;
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Check if a value is a valid token value (string, number, or boolean - not object).
|
|
1080
|
+
* Returns false for `false` values (they mean "skip this token").
|
|
1081
|
+
*/
|
|
1082
|
+
function isValidTokenValue(value) {
|
|
1083
|
+
if (value === void 0 || value === null || value === false) return false;
|
|
1084
|
+
if (typeof value === "object") {
|
|
1085
|
+
console.warn("Tasty: Object values are not allowed in tokens prop. Tokens do not support state-based styling. Use a primitive value instead.");
|
|
1086
|
+
return false;
|
|
1087
|
+
}
|
|
1088
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Process a single token value through the tasty parser.
|
|
1092
|
+
* Numbers are converted to strings; 0 stays as "0".
|
|
1093
|
+
*/
|
|
1094
|
+
function processTokenValue(value) {
|
|
1095
|
+
if (typeof value === "number") {
|
|
1096
|
+
if (value === 0) return "0";
|
|
1097
|
+
return parseStyle(String(value)).output;
|
|
1098
|
+
}
|
|
1099
|
+
return parseStyle(value).output;
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Process tokens object into inline style properties.
|
|
1103
|
+
* - $name -> --name with parsed value
|
|
1104
|
+
* - #name -> --name-color AND --name-color-{colorSpace} with parsed values
|
|
1105
|
+
*
|
|
1106
|
+
* @param tokens - The tokens object to process
|
|
1107
|
+
* @returns CSSProperties object or undefined if no tokens to process
|
|
1108
|
+
*/
|
|
1109
|
+
function processTokens(tokens) {
|
|
1110
|
+
if (!tokens) return;
|
|
1111
|
+
const keys = Object.keys(tokens);
|
|
1112
|
+
if (keys.length === 0) return;
|
|
1113
|
+
let result;
|
|
1114
|
+
for (const key of keys) {
|
|
1115
|
+
const value = tokens[key];
|
|
1116
|
+
if (!isValidTokenValue(value)) continue;
|
|
1117
|
+
if (key.startsWith("$")) {
|
|
1118
|
+
const propName = `--${key.slice(1)}`;
|
|
1119
|
+
const processedValue = processTokenValue(value === true ? "" : value);
|
|
1120
|
+
if (!result) result = {};
|
|
1121
|
+
result[propName] = processedValue;
|
|
1122
|
+
} else if (key.startsWith("#")) {
|
|
1123
|
+
const colorName = key.slice(1);
|
|
1124
|
+
const suffix = getColorSpaceSuffix();
|
|
1125
|
+
const effectiveValue = normalizeColorTokenValue(value);
|
|
1126
|
+
if (effectiveValue === null) continue;
|
|
1127
|
+
const originalValue = typeof effectiveValue === "number" ? String(effectiveValue) : effectiveValue;
|
|
1128
|
+
const lowerValue = originalValue.toLowerCase();
|
|
1129
|
+
const processedValue = processTokenValue(effectiveValue);
|
|
1130
|
+
if (!result) result = {};
|
|
1131
|
+
result[`--${colorName}-color`] = processedValue;
|
|
1132
|
+
if (/^#current(?:\.|$)/i.test(lowerValue)) continue;
|
|
1133
|
+
result[`--${colorName}-color-${suffix}`] = extractColorSpaceValue(originalValue, processedValue);
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
return result;
|
|
1137
|
+
}
|
|
1138
|
+
//#endregion
|
|
1139
|
+
//#region src/debug.ts
|
|
1140
|
+
function fmtSize(bytes) {
|
|
1141
|
+
return bytes > 1024 ? `${(bytes / 1024).toFixed(1)}KB` : `${bytes}B`;
|
|
1142
|
+
}
|
|
1143
|
+
function countRules(css) {
|
|
1144
|
+
return (css.match(/\{[^}]*\}/g) || []).length;
|
|
1145
|
+
}
|
|
1146
|
+
function sortTastyClasses(classes) {
|
|
1147
|
+
return Array.from(classes).sort((a, b) => a.localeCompare(b));
|
|
1148
|
+
}
|
|
1149
|
+
function getRegistry(root = document) {
|
|
1150
|
+
return injector.instance._sheetManager?.getRegistry(root);
|
|
1151
|
+
}
|
|
1152
|
+
function getUnusedClasses(root = document) {
|
|
1153
|
+
const registry = getRegistry(root);
|
|
1154
|
+
if (!registry) return [];
|
|
1155
|
+
const result = [];
|
|
1156
|
+
for (const [cls, rc] of registry.refCounts) if (rc === 0) result.push(cls);
|
|
1157
|
+
return sortTastyClasses(result);
|
|
1158
|
+
}
|
|
1159
|
+
function findDomTastyClasses(root = document) {
|
|
1160
|
+
const classes = /* @__PURE__ */ new Set();
|
|
1161
|
+
(root.querySelectorAll?.("[class]") || []).forEach((el) => {
|
|
1162
|
+
const attr = el.getAttribute("class");
|
|
1163
|
+
if (attr) {
|
|
1164
|
+
for (const cls of attr.split(/\s+/)) if (/^t[a-z0-9]+$/.test(cls)) classes.add(cls);
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
return sortTastyClasses(classes);
|
|
1168
|
+
}
|
|
1169
|
+
function prettifyCSS(css) {
|
|
1170
|
+
if (!css || !css.trim()) return "";
|
|
1171
|
+
const out = [];
|
|
1172
|
+
let depth = 0;
|
|
1173
|
+
const indent = () => " ".repeat(depth);
|
|
1174
|
+
let normalized = css.replace(/\s+/g, " ").trim();
|
|
1175
|
+
normalized = normalized.replace(/\s*\{\s*/g, " { ");
|
|
1176
|
+
normalized = normalized.replace(/\s*\}\s*/g, " } ");
|
|
1177
|
+
normalized = normalized.replace(/;\s*/g, "; ");
|
|
1178
|
+
const tokens = normalized.split(/\s+/);
|
|
1179
|
+
let buf = "";
|
|
1180
|
+
for (const t of tokens) if (t === "{") {
|
|
1181
|
+
const header = buf.trim();
|
|
1182
|
+
if (header) {
|
|
1183
|
+
const parts = splitOutsideParens(header, ",");
|
|
1184
|
+
if (parts.length > 1) out.push(parts.map((p, idx) => idx === 0 ? `${indent()}${p.trim()},` : `${indent()}${p.trim()}${idx < parts.length - 1 ? "," : ""}`).join("\n") + " {");
|
|
1185
|
+
else out.push(`${indent()}${header} {`);
|
|
1186
|
+
} else out.push(`${indent()}{`);
|
|
1187
|
+
depth++;
|
|
1188
|
+
buf = "";
|
|
1189
|
+
} else if (t === "}") {
|
|
1190
|
+
if (buf.trim()) {
|
|
1191
|
+
for (const decl of buf.split(";").filter((s) => s.trim())) out.push(`${indent()}${decl.trim()};`);
|
|
1192
|
+
buf = "";
|
|
1193
|
+
}
|
|
1194
|
+
depth = Math.max(0, depth - 1);
|
|
1195
|
+
out.push(`${indent()}}`);
|
|
1196
|
+
} else if (t.endsWith(";")) {
|
|
1197
|
+
buf += ` ${t}`;
|
|
1198
|
+
const full = buf.trim();
|
|
1199
|
+
if (full) out.push(`${indent()}${full}`);
|
|
1200
|
+
buf = "";
|
|
1201
|
+
} else buf += ` ${t}`;
|
|
1202
|
+
if (buf.trim()) out.push(buf.trim());
|
|
1203
|
+
return out.filter((l) => l.trim()).join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
1204
|
+
}
|
|
1205
|
+
/** Split `str` by `sep` only when not inside parentheses */
|
|
1206
|
+
function splitOutsideParens(str, sep) {
|
|
1207
|
+
const parts = [];
|
|
1208
|
+
let depth = 0;
|
|
1209
|
+
let start = 0;
|
|
1210
|
+
for (let i = 0; i < str.length; i++) {
|
|
1211
|
+
const ch = str[i];
|
|
1212
|
+
if (ch === "(") depth++;
|
|
1213
|
+
else if (ch === ")") depth--;
|
|
1214
|
+
else if (depth === 0 && str.startsWith(sep, i)) {
|
|
1215
|
+
parts.push(str.slice(start, i));
|
|
1216
|
+
start = i + sep.length;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
parts.push(str.slice(start));
|
|
1220
|
+
return parts;
|
|
1221
|
+
}
|
|
1222
|
+
function extractChunkName(cacheKey) {
|
|
1223
|
+
for (const part of cacheKey.split("\0")) {
|
|
1224
|
+
if (part.startsWith("[states:")) continue;
|
|
1225
|
+
if (!part.includes(":") && part.length > 0) return part;
|
|
1226
|
+
}
|
|
1227
|
+
return null;
|
|
1228
|
+
}
|
|
1229
|
+
function getChunkForClass(className, root = document) {
|
|
1230
|
+
const registry = getRegistry(root);
|
|
1231
|
+
if (!registry) return null;
|
|
1232
|
+
for (const [key, cn] of registry.cacheKeyToClassName) if (cn === className) return extractChunkName(key);
|
|
1233
|
+
return null;
|
|
1234
|
+
}
|
|
1235
|
+
function buildChunkBreakdown(root = document) {
|
|
1236
|
+
const registry = getRegistry(root);
|
|
1237
|
+
if (!registry) return {
|
|
1238
|
+
byChunk: {},
|
|
1239
|
+
totalChunkTypes: 0,
|
|
1240
|
+
totalClasses: 0
|
|
1241
|
+
};
|
|
1242
|
+
const byChunk = {};
|
|
1243
|
+
for (const [cacheKey, className] of registry.cacheKeyToClassName) {
|
|
1244
|
+
const chunk = extractChunkName(cacheKey) || "unknown";
|
|
1245
|
+
if (!byChunk[chunk]) byChunk[chunk] = {
|
|
1246
|
+
classes: [],
|
|
1247
|
+
cssSize: 0,
|
|
1248
|
+
ruleCount: 0
|
|
1249
|
+
};
|
|
1250
|
+
byChunk[chunk].classes.push(className);
|
|
1251
|
+
const css = injector.instance.getCssTextForClasses([className], { root });
|
|
1252
|
+
byChunk[chunk].cssSize += css.length;
|
|
1253
|
+
byChunk[chunk].ruleCount += countRules(css);
|
|
1254
|
+
}
|
|
1255
|
+
for (const entry of Object.values(byChunk)) entry.classes = sortTastyClasses(entry.classes);
|
|
1256
|
+
const totalClasses = Object.values(byChunk).reduce((s, e) => s + e.classes.length, 0);
|
|
1257
|
+
return {
|
|
1258
|
+
byChunk,
|
|
1259
|
+
totalChunkTypes: Object.keys(byChunk).length,
|
|
1260
|
+
totalClasses
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
function getGlobalTypeCSS(type, root = document) {
|
|
1264
|
+
const registry = getRegistry(root);
|
|
1265
|
+
if (!registry) return {
|
|
1266
|
+
css: "",
|
|
1267
|
+
ruleCount: 0,
|
|
1268
|
+
size: 0
|
|
1269
|
+
};
|
|
1270
|
+
const chunks = [];
|
|
1271
|
+
let rc = 0;
|
|
1272
|
+
if (type === "keyframes") for (const [, entry] of registry.keyframesCache) {
|
|
1273
|
+
const info = entry.info;
|
|
1274
|
+
const sheetInfo = registry.sheets[info.sheetIndex];
|
|
1275
|
+
const sm = injector.instance._sheetManager;
|
|
1276
|
+
const ss = sheetInfo && sm ? sm.getCSSSheet(sheetInfo) : null;
|
|
1277
|
+
if (ss && info.ruleIndex < ss.cssRules.length) {
|
|
1278
|
+
const rule = ss.cssRules[info.ruleIndex];
|
|
1279
|
+
if (rule) {
|
|
1280
|
+
chunks.push(rule.cssText);
|
|
1281
|
+
rc++;
|
|
1282
|
+
}
|
|
1283
|
+
} else if (info.cssText) {
|
|
1284
|
+
chunks.push(info.cssText);
|
|
1285
|
+
rc++;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
else {
|
|
1289
|
+
const prefix = type === "global" ? "global:" : type === "raw" ? "raw:" : "property:";
|
|
1290
|
+
for (const [key, ri] of registry.globalRules) {
|
|
1291
|
+
if (!key.startsWith(prefix)) continue;
|
|
1292
|
+
const sheetInfo = registry.sheets[ri.sheetIndex];
|
|
1293
|
+
const sm = injector.instance._sheetManager;
|
|
1294
|
+
const ss = sheetInfo && sm ? sm.getCSSSheet(sheetInfo) : null;
|
|
1295
|
+
if (ss) {
|
|
1296
|
+
const start = Math.max(0, ri.ruleIndex);
|
|
1297
|
+
const end = Math.min(ss.cssRules.length - 1, ri.endRuleIndex ?? ri.ruleIndex);
|
|
1298
|
+
if (start >= 0 && end >= start && start < ss.cssRules.length) for (let i = start; i <= end; i++) {
|
|
1299
|
+
const rule = ss.cssRules[i];
|
|
1300
|
+
if (rule) {
|
|
1301
|
+
chunks.push(rule.cssText);
|
|
1302
|
+
rc++;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
} else if (ri.cssText?.length) {
|
|
1306
|
+
chunks.push(...ri.cssText);
|
|
1307
|
+
rc += ri.cssText.length;
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
const raw = chunks.join("\n");
|
|
1312
|
+
return {
|
|
1313
|
+
css: prettifyCSS(raw),
|
|
1314
|
+
ruleCount: rc,
|
|
1315
|
+
size: raw.length
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
function getSourceCssForClasses(classNames, root = document) {
|
|
1319
|
+
const registry = getRegistry(root);
|
|
1320
|
+
if (!registry) return null;
|
|
1321
|
+
const chunks = [];
|
|
1322
|
+
let found = false;
|
|
1323
|
+
for (const cls of classNames) {
|
|
1324
|
+
const info = registry.rules.get(cls);
|
|
1325
|
+
if (info?.cssText?.length) {
|
|
1326
|
+
chunks.push(...info.cssText);
|
|
1327
|
+
found = true;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
return found ? chunks.join("\n") : null;
|
|
1331
|
+
}
|
|
1332
|
+
function getDefs(root = document) {
|
|
1333
|
+
const registry = getRegistry(root);
|
|
1334
|
+
let properties = [];
|
|
1335
|
+
if (registry?.injectedProperties) properties = Array.from(registry.injectedProperties.keys()).sort();
|
|
1336
|
+
const keyframes = [];
|
|
1337
|
+
if (registry) {
|
|
1338
|
+
for (const entry of registry.keyframesCache.values()) keyframes.push({
|
|
1339
|
+
name: entry.name,
|
|
1340
|
+
refCount: entry.refCount
|
|
1341
|
+
});
|
|
1342
|
+
keyframes.sort((a, b) => a.name.localeCompare(b.name));
|
|
1343
|
+
}
|
|
1344
|
+
return {
|
|
1345
|
+
properties,
|
|
1346
|
+
keyframes
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
const CHUNK_ORDER = [
|
|
1350
|
+
CHUNK_NAMES.COMBINED,
|
|
1351
|
+
CHUNK_NAMES.APPEARANCE,
|
|
1352
|
+
CHUNK_NAMES.FONT,
|
|
1353
|
+
CHUNK_NAMES.DIMENSION,
|
|
1354
|
+
CHUNK_NAMES.DISPLAY,
|
|
1355
|
+
CHUNK_NAMES.LAYOUT,
|
|
1356
|
+
CHUNK_NAMES.POSITION,
|
|
1357
|
+
CHUNK_NAMES.MISC,
|
|
1358
|
+
CHUNK_NAMES.SUBCOMPONENTS
|
|
1359
|
+
];
|
|
1360
|
+
const tastyDebug = {
|
|
1361
|
+
css(target, opts) {
|
|
1362
|
+
const { root = document, prettify = true, raw = false, source = false } = opts || {};
|
|
1363
|
+
let css = "";
|
|
1364
|
+
if (source && typeof target === "string" && /^t[a-z0-9]+$/.test(target)) {
|
|
1365
|
+
const src = getSourceCssForClasses([target], root);
|
|
1366
|
+
if (src) css = src;
|
|
1367
|
+
else {
|
|
1368
|
+
if (!raw) console.warn("tastyDebug: source CSS not available (requires dev mode or TASTY_DEBUG=true). Falling back to live CSSOM.");
|
|
1369
|
+
css = injector.instance.getCssTextForClasses([target], { root });
|
|
1370
|
+
}
|
|
1371
|
+
} else if (source && Array.isArray(target)) {
|
|
1372
|
+
const src = getSourceCssForClasses(target, root);
|
|
1373
|
+
if (src) css = src;
|
|
1374
|
+
else {
|
|
1375
|
+
if (!raw) console.warn("tastyDebug: source CSS not available. Falling back to live CSSOM.");
|
|
1376
|
+
css = injector.instance.getCssTextForClasses(target, { root });
|
|
1377
|
+
}
|
|
1378
|
+
} else if (typeof target === "string") if (target === "all") css = injector.instance.getCssText({ root });
|
|
1379
|
+
else if (target === "global") {
|
|
1380
|
+
css = getGlobalTypeCSS("global", root).css;
|
|
1381
|
+
return css;
|
|
1382
|
+
} else if (target === "active") {
|
|
1383
|
+
const active = findDomTastyClasses(root);
|
|
1384
|
+
css = injector.instance.getCssTextForClasses(active, { root });
|
|
1385
|
+
} else if (target === "unused") {
|
|
1386
|
+
const unused = getUnusedClasses(root);
|
|
1387
|
+
css = injector.instance.getCssTextForClasses(unused, { root });
|
|
1388
|
+
} else if (target === "page") css = getPageCSS(root);
|
|
1389
|
+
else if (/^t[a-z0-9]+$/.test(target)) css = injector.instance.getCssTextForClasses([target], { root });
|
|
1390
|
+
else {
|
|
1391
|
+
const el = root.querySelector?.(target);
|
|
1392
|
+
if (el) css = getCssTextForNode(el, { root });
|
|
1393
|
+
}
|
|
1394
|
+
else if (Array.isArray(target)) css = injector.instance.getCssTextForClasses(target, { root });
|
|
1395
|
+
else if (target instanceof Element) css = getCssTextForNode(target, { root });
|
|
1396
|
+
const result = prettify ? prettifyCSS(css) : css;
|
|
1397
|
+
if (!raw) {
|
|
1398
|
+
const label = Array.isArray(target) ? `[${target.join(", ")}]` : target;
|
|
1399
|
+
const rc = countRules(css);
|
|
1400
|
+
console.group(`CSS for ${label} (${rc} rules, ${fmtSize(css.length)})`);
|
|
1401
|
+
console.log(result || "(empty)");
|
|
1402
|
+
console.groupEnd();
|
|
1403
|
+
}
|
|
1404
|
+
return result;
|
|
1405
|
+
},
|
|
1406
|
+
inspect(target, opts) {
|
|
1407
|
+
const { root = document, raw = false } = opts || {};
|
|
1408
|
+
const element = typeof target === "string" ? root.querySelector?.(target) : target;
|
|
1409
|
+
if (!element) {
|
|
1410
|
+
const empty = {
|
|
1411
|
+
element: null,
|
|
1412
|
+
classes: [],
|
|
1413
|
+
chunks: [],
|
|
1414
|
+
css: "",
|
|
1415
|
+
size: 0,
|
|
1416
|
+
rules: 0
|
|
1417
|
+
};
|
|
1418
|
+
if (!raw) console.warn("tastyDebug.inspect: element not found");
|
|
1419
|
+
return empty;
|
|
1420
|
+
}
|
|
1421
|
+
const tastyClasses = (element.getAttribute("class") || "").split(/\s+/).filter((cls) => /^t[a-z0-9]+$/.test(cls));
|
|
1422
|
+
const chunks = tastyClasses.map((className) => ({
|
|
1423
|
+
className,
|
|
1424
|
+
chunkName: getChunkForClass(className, root)
|
|
1425
|
+
}));
|
|
1426
|
+
const css = getCssTextForNode(element, { root });
|
|
1427
|
+
const rules = countRules(css);
|
|
1428
|
+
const result = {
|
|
1429
|
+
element,
|
|
1430
|
+
classes: tastyClasses,
|
|
1431
|
+
chunks,
|
|
1432
|
+
css: prettifyCSS(css),
|
|
1433
|
+
size: css.length,
|
|
1434
|
+
rules
|
|
1435
|
+
};
|
|
1436
|
+
if (!raw) {
|
|
1437
|
+
const tag = element.tagName.toLowerCase();
|
|
1438
|
+
const id = element.id ? `#${element.id}` : "";
|
|
1439
|
+
console.group(`inspect ${tag}${id} — ${tastyClasses.length} classes, ${rules} rules, ${fmtSize(css.length)}`);
|
|
1440
|
+
if (chunks.length) console.log("Chunks:", chunks.map((c) => `${c.className}→${c.chunkName || "?"}`).join(", "));
|
|
1441
|
+
console.groupCollapsed("CSS");
|
|
1442
|
+
console.log(result.css || "(empty)");
|
|
1443
|
+
console.groupEnd();
|
|
1444
|
+
console.groupEnd();
|
|
1445
|
+
}
|
|
1446
|
+
return result;
|
|
1447
|
+
},
|
|
1448
|
+
summary(opts) {
|
|
1449
|
+
const { root = document, raw = false } = opts || {};
|
|
1450
|
+
const activeClasses = findDomTastyClasses(root);
|
|
1451
|
+
const unusedClasses = getUnusedClasses(root);
|
|
1452
|
+
const totalStyledClasses = [...activeClasses, ...unusedClasses];
|
|
1453
|
+
const activeCSS = injector.instance.getCssTextForClasses(activeClasses, { root });
|
|
1454
|
+
const unusedCSS = injector.instance.getCssTextForClasses(unusedClasses, { root });
|
|
1455
|
+
const allCSS = injector.instance.getCssText({ root });
|
|
1456
|
+
const activeRuleCount = countRules(activeCSS);
|
|
1457
|
+
const unusedRuleCount = countRules(unusedCSS);
|
|
1458
|
+
const globalData = getGlobalTypeCSS("global", root);
|
|
1459
|
+
const rawData = getGlobalTypeCSS("raw", root);
|
|
1460
|
+
const kfData = getGlobalTypeCSS("keyframes", root);
|
|
1461
|
+
const propData = getGlobalTypeCSS("property", root);
|
|
1462
|
+
const totalRuleCount = activeRuleCount + unusedRuleCount + globalData.ruleCount + rawData.ruleCount + kfData.ruleCount + propData.ruleCount;
|
|
1463
|
+
const metrics = injector.instance.getMetrics({ root });
|
|
1464
|
+
const defs = getDefs(root);
|
|
1465
|
+
const chunkBreakdown = buildChunkBreakdown(root);
|
|
1466
|
+
const summary = {
|
|
1467
|
+
activeClasses,
|
|
1468
|
+
unusedClasses,
|
|
1469
|
+
totalStyledClasses,
|
|
1470
|
+
activeCSSSize: activeCSS.length,
|
|
1471
|
+
unusedCSSSize: unusedCSS.length,
|
|
1472
|
+
globalCSSSize: globalData.size,
|
|
1473
|
+
rawCSSSize: rawData.size,
|
|
1474
|
+
keyframesCSSSize: kfData.size,
|
|
1475
|
+
propertyCSSSize: propData.size,
|
|
1476
|
+
totalCSSSize: allCSS.length,
|
|
1477
|
+
activeRuleCount,
|
|
1478
|
+
unusedRuleCount,
|
|
1479
|
+
globalRuleCount: globalData.ruleCount,
|
|
1480
|
+
rawRuleCount: rawData.ruleCount,
|
|
1481
|
+
keyframesRuleCount: kfData.ruleCount,
|
|
1482
|
+
propertyRuleCount: propData.ruleCount,
|
|
1483
|
+
totalRuleCount,
|
|
1484
|
+
metrics,
|
|
1485
|
+
definedProperties: defs.properties,
|
|
1486
|
+
definedKeyframes: defs.keyframes,
|
|
1487
|
+
chunkBreakdown
|
|
1488
|
+
};
|
|
1489
|
+
if (!raw) {
|
|
1490
|
+
console.group("Tasty Summary");
|
|
1491
|
+
console.log(`Active: ${activeClasses.length} classes, ${activeRuleCount} rules, ${fmtSize(activeCSS.length)}`);
|
|
1492
|
+
console.log(`Unused: ${unusedClasses.length} classes, ${unusedRuleCount} rules, ${fmtSize(unusedCSS.length)}`);
|
|
1493
|
+
console.log(`Global: ${globalData.ruleCount} rules, ${fmtSize(globalData.size)}`);
|
|
1494
|
+
if (rawData.ruleCount) console.log(`Raw: ${rawData.ruleCount} rules, ${fmtSize(rawData.size)}`);
|
|
1495
|
+
if (kfData.ruleCount) console.log(`Keyframes: ${kfData.ruleCount} rules, ${fmtSize(kfData.size)}`);
|
|
1496
|
+
if (propData.ruleCount) console.log(`@property: ${propData.ruleCount} rules, ${fmtSize(propData.size)}`);
|
|
1497
|
+
console.log(`Total: ${totalStyledClasses.length} classes, ${totalRuleCount} rules, ${fmtSize(allCSS.length)}`);
|
|
1498
|
+
if (metrics) {
|
|
1499
|
+
const total = metrics.hits + metrics.misses;
|
|
1500
|
+
const rate = total > 0 ? (metrics.hits / total * 100).toFixed(1) : 0;
|
|
1501
|
+
console.log(`Cache: ${rate}% hit rate (${total} lookups)`);
|
|
1502
|
+
}
|
|
1503
|
+
if (chunkBreakdown.totalChunkTypes > 0) {
|
|
1504
|
+
console.groupCollapsed(`Chunks (${chunkBreakdown.totalChunkTypes} types, ${chunkBreakdown.totalClasses} classes)`);
|
|
1505
|
+
for (const name of CHUNK_ORDER) {
|
|
1506
|
+
const d = chunkBreakdown.byChunk[name];
|
|
1507
|
+
if (d) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
|
|
1508
|
+
}
|
|
1509
|
+
for (const [name, d] of Object.entries(chunkBreakdown.byChunk)) if (!CHUNK_ORDER.includes(name)) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
|
|
1510
|
+
console.groupEnd();
|
|
1511
|
+
}
|
|
1512
|
+
if (defs.properties.length || defs.keyframes.length) console.log(`Defs: ${defs.properties.length} @property, ${defs.keyframes.length} @keyframes`);
|
|
1513
|
+
console.groupEnd();
|
|
1514
|
+
}
|
|
1515
|
+
return summary;
|
|
1516
|
+
},
|
|
1517
|
+
chunks(opts) {
|
|
1518
|
+
const { root = document, raw = false } = opts || {};
|
|
1519
|
+
const breakdown = buildChunkBreakdown(root);
|
|
1520
|
+
if (!raw) {
|
|
1521
|
+
console.group(`Chunks (${breakdown.totalChunkTypes} types, ${breakdown.totalClasses} classes)`);
|
|
1522
|
+
for (const name of CHUNK_ORDER) {
|
|
1523
|
+
const d = breakdown.byChunk[name];
|
|
1524
|
+
if (d) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
|
|
1525
|
+
}
|
|
1526
|
+
for (const [name, d] of Object.entries(breakdown.byChunk)) if (!CHUNK_ORDER.includes(name)) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
|
|
1527
|
+
console.groupEnd();
|
|
1528
|
+
}
|
|
1529
|
+
return breakdown;
|
|
1530
|
+
},
|
|
1531
|
+
cache(opts) {
|
|
1532
|
+
const { root = document, raw = false } = opts || {};
|
|
1533
|
+
const active = findDomTastyClasses(root);
|
|
1534
|
+
const unused = getUnusedClasses(root);
|
|
1535
|
+
const metrics = injector.instance.getMetrics({ root });
|
|
1536
|
+
const status = {
|
|
1537
|
+
classes: {
|
|
1538
|
+
active,
|
|
1539
|
+
unused,
|
|
1540
|
+
all: [...active, ...unused]
|
|
1541
|
+
},
|
|
1542
|
+
metrics
|
|
1543
|
+
};
|
|
1544
|
+
if (!raw) {
|
|
1545
|
+
console.group("Cache");
|
|
1546
|
+
console.log(`Active: ${active.length}, Unused: ${unused.length}`);
|
|
1547
|
+
if (metrics) {
|
|
1548
|
+
const total = metrics.hits + metrics.misses;
|
|
1549
|
+
const rate = total > 0 ? (metrics.hits / total * 100).toFixed(1) : 0;
|
|
1550
|
+
console.log(`Hits: ${metrics.hits}, Misses: ${metrics.misses}, Rate: ${rate}%`);
|
|
1551
|
+
}
|
|
1552
|
+
console.groupEnd();
|
|
1553
|
+
}
|
|
1554
|
+
return status;
|
|
1555
|
+
},
|
|
1556
|
+
cleanup(opts) {
|
|
1557
|
+
injector.instance.cleanup(opts?.root);
|
|
1558
|
+
},
|
|
1559
|
+
help() {
|
|
1560
|
+
console.log(`tastyDebug API:
|
|
1561
|
+
.summary() — overview (classes, rules, sizes)
|
|
1562
|
+
.css("active") — CSS for classes in DOM
|
|
1563
|
+
.css("t42") — CSS for a specific class
|
|
1564
|
+
.css("t42",{source:1})— original CSS before browser parsing (dev only)
|
|
1565
|
+
.css(".selector") — CSS for a DOM element
|
|
1566
|
+
.inspect(".selector") — element details (classes, chunks, rules)
|
|
1567
|
+
.chunks() — style chunk breakdown
|
|
1568
|
+
.cache() — cache status and metrics
|
|
1569
|
+
.cleanup() — force unused style cleanup
|
|
1570
|
+
Options: { raw: true } suppresses logging, { root: shadowRoot } targets Shadow DOM`);
|
|
1571
|
+
},
|
|
1572
|
+
install() {
|
|
1573
|
+
if (typeof window !== "undefined" && window.tastyDebug !== tastyDebug) {
|
|
1574
|
+
window.tastyDebug = tastyDebug;
|
|
1575
|
+
console.log("tastyDebug installed. Run tastyDebug.help() for commands.");
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1579
|
+
function getPageCSS(root = document) {
|
|
1580
|
+
const chunks = [];
|
|
1581
|
+
try {
|
|
1582
|
+
if ("styleSheets" in root) for (const sheet of Array.from(root.styleSheets)) try {
|
|
1583
|
+
if (sheet.cssRules) chunks.push(Array.from(sheet.cssRules).map((r) => r.cssText).join("\n"));
|
|
1584
|
+
} catch {}
|
|
1585
|
+
} catch {}
|
|
1586
|
+
return chunks.join("\n");
|
|
1587
|
+
}
|
|
1588
|
+
if (typeof window !== "undefined" && isDevEnv()) tastyDebug.install();
|
|
1589
|
+
//#endregion
|
|
1590
|
+
export { property as A, DIMENSION_STYLES as B, getRawCSSText as C, injector as D, injectRawCSS as E, BLOCK_INNER_STYLES as F, TEXT_STYLES as G, INNER_STYLES as H, BLOCK_OUTER_STYLES as I, BLOCK_STYLES as L, ChunkSheetRegistry as M, chunkSheetRegistry as N, isPropertyDefined as O, BASE_STYLES as P, COLOR_STYLES as R, getIsTestEnvironment as S, injectGlobal as T, OUTER_STYLES as U, FLOW_STYLES as V, POSITION_STYLES as W, destroy as _, color as a, getCssText as b, hasKeys as c, collectAutoInferredPropertiesRSC as d, getStyleTarget as f, createInjector as g, counterStyle as h, _modAttrs as i, touch as j, keyframes as k, formatKeyframesCSS as l, cleanup as m, processTokens as n, filterBaseProps as o, pushRSCCSS as p, dotize as r, computeStyles as s, tastyDebug as t, collectAutoInferredProperties as u, fontFace as v, inject as w, getCssTextForNode as x, gc as y, CONTAINER_STYLES as z };
|
|
1591
|
+
|
|
1592
|
+
//# sourceMappingURL=core-BqO8pplb.js.map
|