@tenphi/tasty 0.0.0-snapshot.2705ab9 → 0.0.0-snapshot.27699f6

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.
Files changed (336) hide show
  1. package/README.md +35 -27
  2. package/dist/{ssr/async-storage.js → async-storage-B7_o6FKt.js} +17 -8
  3. package/dist/async-storage-B7_o6FKt.js.map +1 -0
  4. package/dist/{ssr/collector.d.ts → collector-LuU1vZ68.d.ts} +11 -15
  5. package/dist/{ssr/collector.js → collector-QwpPODsy.js} +37 -34
  6. package/dist/collector-QwpPODsy.js.map +1 -0
  7. package/dist/config-rrijM-U2.js +10137 -0
  8. package/dist/config-rrijM-U2.js.map +1 -0
  9. package/dist/config-vuCRkBWX.d.ts +884 -0
  10. package/dist/context-CkSg-kDT.js +24 -0
  11. package/dist/context-CkSg-kDT.js.map +1 -0
  12. package/dist/core/index.d.ts +5 -34
  13. package/dist/core/index.js +6 -27
  14. package/dist/core-BvTG0J_M.js +1592 -0
  15. package/dist/core-BvTG0J_M.js.map +1 -0
  16. package/dist/{zero/extractor.js → css-writer-C7HJGEmN.js} +75 -13
  17. package/dist/css-writer-C7HJGEmN.js.map +1 -0
  18. package/dist/{ssr/format-global-rules.js → format-global-rules-Dbc_1tc3.js} +3 -3
  19. package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
  20. package/dist/format-rules-BvokPr1L.js +143 -0
  21. package/dist/format-rules-BvokPr1L.js.map +1 -0
  22. package/dist/hydrate-Dsv7Pwon.js +45 -0
  23. package/dist/hydrate-Dsv7Pwon.js.map +1 -0
  24. package/dist/index-ZRxZWzlj.d.ts +1602 -0
  25. package/dist/index-dUtwpOux.d.ts +1266 -0
  26. package/dist/index.d.ts +5 -51
  27. package/dist/index.js +731 -35
  28. package/dist/index.js.map +1 -0
  29. package/dist/keyframes-DDqRjwa9.js +587 -0
  30. package/dist/keyframes-DDqRjwa9.js.map +1 -0
  31. package/dist/{utils/merge-styles.js → merge-styles-B8jV6zu3.js} +4 -6
  32. package/dist/merge-styles-B8jV6zu3.js.map +1 -0
  33. package/dist/{utils/merge-styles.d.ts → merge-styles-CtDJMhpJ.d.ts} +3 -3
  34. package/dist/{utils/resolve-recipes.js → resolve-recipes-BnTZz2I_.js} +5 -8
  35. package/dist/resolve-recipes-BnTZz2I_.js.map +1 -0
  36. package/dist/ssr/astro-client.d.ts +1 -0
  37. package/dist/ssr/astro-client.js +19 -0
  38. package/dist/ssr/astro-client.js.map +1 -0
  39. package/dist/ssr/astro-middleware.d.ts +15 -0
  40. package/dist/ssr/astro-middleware.js +19 -0
  41. package/dist/ssr/astro-middleware.js.map +1 -0
  42. package/dist/ssr/astro.d.ts +89 -10
  43. package/dist/ssr/astro.js +116 -32
  44. package/dist/ssr/astro.js.map +1 -1
  45. package/dist/ssr/index.d.ts +44 -5
  46. package/dist/ssr/index.js +7 -9
  47. package/dist/ssr/index.js.map +1 -1
  48. package/dist/ssr/next.d.ts +7 -6
  49. package/dist/ssr/next.js +18 -14
  50. package/dist/ssr/next.js.map +1 -1
  51. package/dist/static/index.d.ts +91 -5
  52. package/dist/static/index.js +49 -4
  53. package/dist/static/index.js.map +1 -0
  54. package/dist/static/inject.d.ts +5 -0
  55. package/dist/static/inject.js +17 -0
  56. package/dist/static/inject.js.map +1 -0
  57. package/dist/zero/babel.d.ts +24 -110
  58. package/dist/zero/babel.js +139 -47
  59. package/dist/zero/babel.js.map +1 -1
  60. package/dist/zero/index.d.ts +67 -3
  61. package/dist/zero/index.js +2 -4
  62. package/dist/zero/next.d.ts +12 -0
  63. package/dist/zero/next.js +5 -4
  64. package/dist/zero/next.js.map +1 -1
  65. package/docs/README.md +4 -4
  66. package/docs/adoption.md +5 -3
  67. package/docs/comparison.md +24 -25
  68. package/docs/configuration.md +69 -1
  69. package/docs/debug.md +11 -9
  70. package/docs/design-system.md +22 -10
  71. package/docs/dsl.md +24 -8
  72. package/docs/getting-started.md +10 -10
  73. package/docs/injector.md +43 -27
  74. package/docs/methodology.md +52 -3
  75. package/docs/{PIPELINE.md → pipeline.md} +204 -50
  76. package/docs/{runtime.md → react-api.md} +104 -32
  77. package/docs/ssr.md +139 -81
  78. package/docs/styles.md +17 -0
  79. package/docs/tasty-static.md +101 -2
  80. package/package.json +23 -11
  81. package/dist/_virtual/_rolldown/runtime.js +0 -8
  82. package/dist/chunks/cacheKey.js +0 -78
  83. package/dist/chunks/cacheKey.js.map +0 -1
  84. package/dist/chunks/definitions.d.ts +0 -37
  85. package/dist/chunks/definitions.js +0 -259
  86. package/dist/chunks/definitions.js.map +0 -1
  87. package/dist/chunks/renderChunk.js +0 -60
  88. package/dist/chunks/renderChunk.js.map +0 -1
  89. package/dist/config.d.ts +0 -366
  90. package/dist/config.js +0 -504
  91. package/dist/config.js.map +0 -1
  92. package/dist/counter-style/index.js +0 -51
  93. package/dist/counter-style/index.js.map +0 -1
  94. package/dist/debug.d.ts +0 -89
  95. package/dist/debug.js +0 -454
  96. package/dist/debug.js.map +0 -1
  97. package/dist/font-face/index.js +0 -63
  98. package/dist/font-face/index.js.map +0 -1
  99. package/dist/hooks/resolve-ssr-collector.js +0 -15
  100. package/dist/hooks/resolve-ssr-collector.js.map +0 -1
  101. package/dist/hooks/useCounterStyle.d.ts +0 -50
  102. package/dist/hooks/useCounterStyle.js +0 -47
  103. package/dist/hooks/useCounterStyle.js.map +0 -1
  104. package/dist/hooks/useFontFace.d.ts +0 -43
  105. package/dist/hooks/useFontFace.js +0 -71
  106. package/dist/hooks/useFontFace.js.map +0 -1
  107. package/dist/hooks/useGlobalStyles.d.ts +0 -30
  108. package/dist/hooks/useGlobalStyles.js +0 -79
  109. package/dist/hooks/useGlobalStyles.js.map +0 -1
  110. package/dist/hooks/useKeyframes.d.ts +0 -56
  111. package/dist/hooks/useKeyframes.js +0 -65
  112. package/dist/hooks/useKeyframes.js.map +0 -1
  113. package/dist/hooks/useProperty.d.ts +0 -79
  114. package/dist/hooks/useProperty.js +0 -110
  115. package/dist/hooks/useProperty.js.map +0 -1
  116. package/dist/hooks/useRawCSS.d.ts +0 -53
  117. package/dist/hooks/useRawCSS.js +0 -36
  118. package/dist/hooks/useRawCSS.js.map +0 -1
  119. package/dist/hooks/useStyles.d.ts +0 -45
  120. package/dist/hooks/useStyles.js +0 -238
  121. package/dist/hooks/useStyles.js.map +0 -1
  122. package/dist/injector/index.d.ts +0 -183
  123. package/dist/injector/index.js +0 -180
  124. package/dist/injector/index.js.map +0 -1
  125. package/dist/injector/injector.d.ts +0 -166
  126. package/dist/injector/injector.js +0 -465
  127. package/dist/injector/injector.js.map +0 -1
  128. package/dist/injector/sheet-manager.d.ts +0 -136
  129. package/dist/injector/sheet-manager.js +0 -734
  130. package/dist/injector/sheet-manager.js.map +0 -1
  131. package/dist/injector/types.d.ts +0 -204
  132. package/dist/keyframes/index.js +0 -206
  133. package/dist/keyframes/index.js.map +0 -1
  134. package/dist/parser/classify.js +0 -320
  135. package/dist/parser/classify.js.map +0 -1
  136. package/dist/parser/const.js +0 -49
  137. package/dist/parser/const.js.map +0 -1
  138. package/dist/parser/lru.js +0 -109
  139. package/dist/parser/lru.js.map +0 -1
  140. package/dist/parser/parser.d.ts +0 -25
  141. package/dist/parser/parser.js +0 -116
  142. package/dist/parser/parser.js.map +0 -1
  143. package/dist/parser/tokenizer.js +0 -69
  144. package/dist/parser/tokenizer.js.map +0 -1
  145. package/dist/parser/types.d.ts +0 -51
  146. package/dist/parser/types.js +0 -46
  147. package/dist/parser/types.js.map +0 -1
  148. package/dist/pipeline/conditions.d.ts +0 -134
  149. package/dist/pipeline/conditions.js +0 -406
  150. package/dist/pipeline/conditions.js.map +0 -1
  151. package/dist/pipeline/exclusive.js +0 -231
  152. package/dist/pipeline/exclusive.js.map +0 -1
  153. package/dist/pipeline/index.d.ts +0 -55
  154. package/dist/pipeline/index.js +0 -709
  155. package/dist/pipeline/index.js.map +0 -1
  156. package/dist/pipeline/materialize.js +0 -1104
  157. package/dist/pipeline/materialize.js.map +0 -1
  158. package/dist/pipeline/parseStateKey.d.ts +0 -15
  159. package/dist/pipeline/parseStateKey.js +0 -447
  160. package/dist/pipeline/parseStateKey.js.map +0 -1
  161. package/dist/pipeline/simplify.js +0 -516
  162. package/dist/pipeline/simplify.js.map +0 -1
  163. package/dist/pipeline/warnings.js +0 -18
  164. package/dist/pipeline/warnings.js.map +0 -1
  165. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  166. package/dist/plugins/okhsl-plugin.js +0 -98
  167. package/dist/plugins/okhsl-plugin.js.map +0 -1
  168. package/dist/plugins/types.d.ts +0 -76
  169. package/dist/properties/index.js +0 -223
  170. package/dist/properties/index.js.map +0 -1
  171. package/dist/properties/property-type-resolver.d.ts +0 -24
  172. package/dist/properties/property-type-resolver.js +0 -91
  173. package/dist/properties/property-type-resolver.js.map +0 -1
  174. package/dist/ssr/async-storage.d.ts +0 -17
  175. package/dist/ssr/async-storage.js.map +0 -1
  176. package/dist/ssr/collect-auto-properties.js +0 -40
  177. package/dist/ssr/collect-auto-properties.js.map +0 -1
  178. package/dist/ssr/collector.js.map +0 -1
  179. package/dist/ssr/context.d.ts +0 -8
  180. package/dist/ssr/context.js +0 -14
  181. package/dist/ssr/context.js.map +0 -1
  182. package/dist/ssr/format-global-rules.js.map +0 -1
  183. package/dist/ssr/format-keyframes.js +0 -70
  184. package/dist/ssr/format-keyframes.js.map +0 -1
  185. package/dist/ssr/format-property.js +0 -50
  186. package/dist/ssr/format-property.js.map +0 -1
  187. package/dist/ssr/format-rules.js +0 -73
  188. package/dist/ssr/format-rules.js.map +0 -1
  189. package/dist/ssr/hydrate.d.ts +0 -22
  190. package/dist/ssr/hydrate.js +0 -50
  191. package/dist/ssr/hydrate.js.map +0 -1
  192. package/dist/ssr/ssr-collector-ref.js +0 -12
  193. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  194. package/dist/states/index.d.ts +0 -49
  195. package/dist/states/index.js +0 -171
  196. package/dist/states/index.js.map +0 -1
  197. package/dist/static/tastyStatic.d.ts +0 -46
  198. package/dist/static/tastyStatic.js +0 -31
  199. package/dist/static/tastyStatic.js.map +0 -1
  200. package/dist/static/types.d.ts +0 -49
  201. package/dist/static/types.js +0 -24
  202. package/dist/static/types.js.map +0 -1
  203. package/dist/styles/align.d.ts +0 -15
  204. package/dist/styles/align.js +0 -14
  205. package/dist/styles/align.js.map +0 -1
  206. package/dist/styles/border.d.ts +0 -25
  207. package/dist/styles/border.js +0 -114
  208. package/dist/styles/border.js.map +0 -1
  209. package/dist/styles/color.d.ts +0 -14
  210. package/dist/styles/color.js +0 -27
  211. package/dist/styles/color.js.map +0 -1
  212. package/dist/styles/createStyle.js +0 -80
  213. package/dist/styles/createStyle.js.map +0 -1
  214. package/dist/styles/dimension.js +0 -97
  215. package/dist/styles/dimension.js.map +0 -1
  216. package/dist/styles/display.d.ts +0 -37
  217. package/dist/styles/display.js +0 -67
  218. package/dist/styles/display.js.map +0 -1
  219. package/dist/styles/fade.d.ts +0 -15
  220. package/dist/styles/fade.js +0 -58
  221. package/dist/styles/fade.js.map +0 -1
  222. package/dist/styles/fill.d.ts +0 -42
  223. package/dist/styles/fill.js +0 -52
  224. package/dist/styles/fill.js.map +0 -1
  225. package/dist/styles/flow.d.ts +0 -16
  226. package/dist/styles/flow.js +0 -12
  227. package/dist/styles/flow.js.map +0 -1
  228. package/dist/styles/gap.d.ts +0 -31
  229. package/dist/styles/gap.js +0 -37
  230. package/dist/styles/gap.js.map +0 -1
  231. package/dist/styles/height.d.ts +0 -17
  232. package/dist/styles/height.js +0 -20
  233. package/dist/styles/height.js.map +0 -1
  234. package/dist/styles/index.d.ts +0 -2
  235. package/dist/styles/index.js +0 -9
  236. package/dist/styles/index.js.map +0 -1
  237. package/dist/styles/inset.d.ts +0 -52
  238. package/dist/styles/inset.js +0 -150
  239. package/dist/styles/inset.js.map +0 -1
  240. package/dist/styles/justify.d.ts +0 -15
  241. package/dist/styles/justify.js +0 -14
  242. package/dist/styles/justify.js.map +0 -1
  243. package/dist/styles/list.d.ts +0 -16
  244. package/dist/styles/list.js +0 -98
  245. package/dist/styles/list.js.map +0 -1
  246. package/dist/styles/margin.d.ts +0 -24
  247. package/dist/styles/margin.js +0 -104
  248. package/dist/styles/margin.js.map +0 -1
  249. package/dist/styles/outline.d.ts +0 -29
  250. package/dist/styles/outline.js +0 -65
  251. package/dist/styles/outline.js.map +0 -1
  252. package/dist/styles/padding.d.ts +0 -24
  253. package/dist/styles/padding.js +0 -104
  254. package/dist/styles/padding.js.map +0 -1
  255. package/dist/styles/predefined.d.ts +0 -71
  256. package/dist/styles/predefined.js +0 -238
  257. package/dist/styles/predefined.js.map +0 -1
  258. package/dist/styles/preset.d.ts +0 -52
  259. package/dist/styles/preset.js +0 -127
  260. package/dist/styles/preset.js.map +0 -1
  261. package/dist/styles/radius.d.ts +0 -14
  262. package/dist/styles/radius.js +0 -51
  263. package/dist/styles/radius.js.map +0 -1
  264. package/dist/styles/scrollbar.d.ts +0 -25
  265. package/dist/styles/scrollbar.js +0 -48
  266. package/dist/styles/scrollbar.js.map +0 -1
  267. package/dist/styles/shadow.d.ts +0 -14
  268. package/dist/styles/shadow.js +0 -24
  269. package/dist/styles/shadow.js.map +0 -1
  270. package/dist/styles/transition.d.ts +0 -14
  271. package/dist/styles/transition.js +0 -158
  272. package/dist/styles/transition.js.map +0 -1
  273. package/dist/styles/types.d.ts +0 -547
  274. package/dist/styles/width.d.ts +0 -17
  275. package/dist/styles/width.js +0 -20
  276. package/dist/styles/width.js.map +0 -1
  277. package/dist/tasty.d.ts +0 -119
  278. package/dist/tasty.js +0 -232
  279. package/dist/tasty.js.map +0 -1
  280. package/dist/types.d.ts +0 -184
  281. package/dist/utils/cache-wrapper.js +0 -22
  282. package/dist/utils/cache-wrapper.js.map +0 -1
  283. package/dist/utils/case-converter.js +0 -8
  284. package/dist/utils/case-converter.js.map +0 -1
  285. package/dist/utils/color-math.d.ts +0 -46
  286. package/dist/utils/color-math.js +0 -749
  287. package/dist/utils/color-math.js.map +0 -1
  288. package/dist/utils/color-space.d.ts +0 -5
  289. package/dist/utils/color-space.js +0 -229
  290. package/dist/utils/color-space.js.map +0 -1
  291. package/dist/utils/colors.d.ts +0 -5
  292. package/dist/utils/colors.js +0 -11
  293. package/dist/utils/colors.js.map +0 -1
  294. package/dist/utils/css-types.d.ts +0 -7
  295. package/dist/utils/dotize.d.ts +0 -26
  296. package/dist/utils/dotize.js +0 -122
  297. package/dist/utils/dotize.js.map +0 -1
  298. package/dist/utils/filter-base-props.d.ts +0 -15
  299. package/dist/utils/filter-base-props.js +0 -45
  300. package/dist/utils/filter-base-props.js.map +0 -1
  301. package/dist/utils/get-display-name.d.ts +0 -7
  302. package/dist/utils/get-display-name.js +0 -10
  303. package/dist/utils/get-display-name.js.map +0 -1
  304. package/dist/utils/has-keys.js +0 -13
  305. package/dist/utils/has-keys.js.map +0 -1
  306. package/dist/utils/is-dev-env.js +0 -19
  307. package/dist/utils/is-dev-env.js.map +0 -1
  308. package/dist/utils/is-valid-element-type.js +0 -15
  309. package/dist/utils/is-valid-element-type.js.map +0 -1
  310. package/dist/utils/merge-styles.js.map +0 -1
  311. package/dist/utils/mod-attrs.d.ts +0 -8
  312. package/dist/utils/mod-attrs.js +0 -21
  313. package/dist/utils/mod-attrs.js.map +0 -1
  314. package/dist/utils/process-tokens.d.ts +0 -21
  315. package/dist/utils/process-tokens.js +0 -91
  316. package/dist/utils/process-tokens.js.map +0 -1
  317. package/dist/utils/resolve-recipes.d.ts +0 -17
  318. package/dist/utils/resolve-recipes.js.map +0 -1
  319. package/dist/utils/selector-transform.js +0 -32
  320. package/dist/utils/selector-transform.js.map +0 -1
  321. package/dist/utils/string.js +0 -8
  322. package/dist/utils/string.js.map +0 -1
  323. package/dist/utils/styles.d.ts +0 -99
  324. package/dist/utils/styles.js +0 -221
  325. package/dist/utils/styles.js.map +0 -1
  326. package/dist/utils/typography.d.ts +0 -47
  327. package/dist/utils/typography.js +0 -51
  328. package/dist/utils/typography.js.map +0 -1
  329. package/dist/utils/warnings.d.ts +0 -16
  330. package/dist/utils/warnings.js +0 -16
  331. package/dist/utils/warnings.js.map +0 -1
  332. package/dist/zero/css-writer.d.ts +0 -45
  333. package/dist/zero/css-writer.js +0 -74
  334. package/dist/zero/css-writer.js.map +0 -1
  335. package/dist/zero/extractor.d.ts +0 -24
  336. package/dist/zero/extractor.js.map +0 -1
@@ -1,709 +0,0 @@
1
- import { Lru } from "../parser/lru.js";
2
- import { stringifyStyles } from "../utils/styles.js";
3
- import { createStyle } from "../styles/createStyle.js";
4
- import { STYLE_HANDLER_MAP } from "../styles/index.js";
5
- import { createStateParserContext, extractLocalPredefinedStates } from "../states/index.js";
6
- import { and, falseCondition, not, or, trueCondition } from "./conditions.js";
7
- import { simplifyCondition } from "./simplify.js";
8
- import { buildExclusiveConditions, expandExclusiveOrs, expandOrConditions, isValueMapping, parseStyleEntries } from "./exclusive.js";
9
- import { branchToCSS, buildAtRulesFromVariant, conditionToCSS, mergeVariantsIntoSelectorGroups, optimizeGroups, parentGroupsToCSS, rootGroupsToCSS, selectorGroupToCSS } from "./materialize.js";
10
- import { emitWarning } from "./warnings.js";
11
- import { parseStateKey } from "./parseStateKey.js";
12
-
13
- //#region src/pipeline/index.ts
14
- /**
15
- * Tasty Style Rendering Pipeline
16
- *
17
- * This is the main entrypoint for the new pipeline implementation.
18
- * It implements the complete flow from style objects to CSS rules.
19
- *
20
- * Pipeline stages:
21
- * 1. PARSE CONDITIONS - Parse state keys into ConditionNode trees
22
- * 2. BUILD EXCLUSIVE CONDITIONS - AND with negation of higher-priority conditions
23
- * 3. SIMPLIFY CONDITIONS - Apply boolean algebra, detect contradictions
24
- * 4. GROUP BY HANDLER - Collect styles per handler, compute combinations
25
- * 5. COMPUTE CSS VALUES - Call handlers to get CSS declarations
26
- * 6. MERGE BY VALUE - Merge rules with identical CSS output
27
- * 7. MATERIALIZE CSS - Convert conditions to CSS selectors + at-rules
28
- */
29
- const pipelineCache = new Lru(5e3);
30
- /**
31
- * Check if a cache key exists in the pipeline cache.
32
- * Used by renderStylesForChunk to avoid building filtered styles on cache hit.
33
- */
34
- function hasPipelineCacheEntry(cacheKey) {
35
- return pipelineCache.get(cacheKey) !== void 0;
36
- }
37
- /**
38
- * Clear the pipeline cache (for testing)
39
- */
40
- function clearPipelineCache() {
41
- pipelineCache.clear();
42
- }
43
- function runPipeline(styles, parserContext) {
44
- const allRules = [];
45
- processStyles(styles, "", parserContext, allRules);
46
- const seen = /* @__PURE__ */ new Set();
47
- const dedupedRules = allRules.filter((rule) => {
48
- const key = `${rule.selector}|${rule.declarations}|${rule.atRules?.join("|") ?? ""}|${rule.rootPrefix || ""}|${rule.startingStyle ? "1" : "0"}`;
49
- if (seen.has(key)) return false;
50
- seen.add(key);
51
- return true;
52
- });
53
- const normal = [];
54
- const starting = [];
55
- for (const rule of dedupedRules) if (rule.startingStyle) starting.push(rule);
56
- else normal.push(rule);
57
- return normal.concat(starting);
58
- }
59
- /**
60
- * Process styles at a given nesting level
61
- */
62
- function processStyles(styles, selectorSuffix, parserContext, allRules) {
63
- const keys = Object.keys(styles);
64
- const selectorKeys = keys.filter((key) => isSelector(key));
65
- const styleKeys = keys.filter((key) => !isSelector(key) && !key.startsWith("@"));
66
- for (const key of selectorKeys) {
67
- const nestedStyles = styles[key];
68
- if (!nestedStyles || typeof nestedStyles !== "object") continue;
69
- const suffixes = getAllSelectors(key, nestedStyles);
70
- if (!suffixes) continue;
71
- const { $: _$, ...cleanedStyles } = nestedStyles;
72
- const subLocalStates = extractLocalPredefinedStates(cleanedStyles);
73
- const hasSubStates = Object.keys(subLocalStates).length > 0;
74
- const subContext = {
75
- ...parserContext,
76
- isSubElement: true,
77
- localPredefinedStates: hasSubStates ? {
78
- ...parserContext.localPredefinedStates,
79
- ...subLocalStates
80
- } : parserContext.localPredefinedStates
81
- };
82
- for (const suffix of suffixes) processStyles(cleanedStyles, selectorSuffix + suffix, subContext, allRules);
83
- }
84
- const handlerQueue = buildHandlerQueue(styleKeys, styles);
85
- for (const { handler, styleMap } of handlerQueue) {
86
- const lookupStyles = handler.__lookupStyles;
87
- const exclusiveByStyle = /* @__PURE__ */ new Map();
88
- for (const styleName of lookupStyles) {
89
- const value = styleMap[styleName];
90
- if (value === void 0) continue;
91
- if (isValueMapping(value)) {
92
- const fullyExpanded = expandExclusiveOrs(buildExclusiveConditions(expandOrConditions(parseStyleEntries(styleName, value, (stateKey) => parseStateKey(stateKey, { context: parserContext })))));
93
- exclusiveByStyle.set(styleName, fullyExpanded);
94
- } else exclusiveByStyle.set(styleName, [{
95
- styleKey: styleName,
96
- stateKey: "",
97
- value,
98
- condition: trueCondition(),
99
- priority: 0,
100
- exclusiveCondition: trueCondition()
101
- }]);
102
- }
103
- const stateSnapshots = computeStateCombinations(exclusiveByStyle, lookupStyles);
104
- const computedRules = [];
105
- for (const snapshot of stateSnapshots) {
106
- const result = handler(snapshot.values);
107
- if (!result) continue;
108
- const results = Array.isArray(result) ? result : [result];
109
- for (const r of results) {
110
- if (!r || typeof r !== "object") continue;
111
- const { $, ...styleProps } = r;
112
- const declarations = {};
113
- for (const [prop, val] of Object.entries(styleProps)) if (val != null && val !== "") declarations[prop] = String(val);
114
- if (Object.keys(declarations).length === 0) continue;
115
- const suffixes = $ ? (Array.isArray($) ? $ : [$]).map((s) => selectorSuffix + normalizeSelectorSuffix(String(s))) : [selectorSuffix];
116
- for (const suffix of suffixes) computedRules.push({
117
- condition: snapshot.condition,
118
- declarations,
119
- selectorSuffix: suffix
120
- });
121
- }
122
- }
123
- const mergedRules = mergeByValue(computedRules);
124
- for (const rule of mergedRules) {
125
- const cssRules = materializeComputedRule(rule);
126
- allRules.push(...cssRules);
127
- }
128
- }
129
- }
130
- /**
131
- * Check if a key is a CSS selector
132
- */
133
- function isSelector(key) {
134
- return key.startsWith("&") || key.startsWith(".") || /^[A-Z]/.test(key);
135
- }
136
- /**
137
- * Get all selector suffixes for a sub-element key.
138
- *
139
- * Handles three types of selector keys:
140
- * - `&` prefix: Raw selector suffix (e.g., `&:hover` → `:hover`)
141
- * - `.` prefix: Class selector (e.g., `.active` → ` .active`)
142
- * - Uppercase: Sub-element with optional `$` affix pattern
143
- *
144
- * @param key - The sub-element key (e.g., 'Label', '&:hover', '.active')
145
- * @param styles - The styles object, may contain `$` property for selector affix
146
- * @returns Array of selector suffixes, or null if invalid (with console warning)
147
- *
148
- * @example
149
- * getAllSelectors('Label', {})
150
- * // → [' [data-element="Label"]']
151
- *
152
- * getAllSelectors('Cell', { $: '>, >Body>' })
153
- * // → ['> [data-element="Cell"]', ' [data-element="Body"] > [data-element="Cell"]']
154
- */
155
- function getAllSelectors(key, styles) {
156
- if (key.startsWith("&")) return [key.slice(1)];
157
- if (key.startsWith(".")) return [` ${key}`];
158
- if (/^[A-Z]/.test(key)) {
159
- const affix = styles?.$;
160
- if (affix !== void 0) {
161
- const result = processAffix(String(affix), key);
162
- if (!result.valid) {
163
- emitWarning("INVALID_SELECTOR_AFFIX", result.reason);
164
- return null;
165
- }
166
- return result.selectors;
167
- }
168
- return [` [data-element="${key}"]`];
169
- }
170
- return null;
171
- }
172
- /**
173
- * Process selector affix pattern and return selector(s)
174
- *
175
- * Supports:
176
- * - Direct child: '>'
177
- * - Chained elements: '>Body>Row>'
178
- * - HTML tags (no key injection): 'h1', '>ul>li', 'button:hover'
179
- * - Universal selector: '*', 'h1 *'
180
- * - Pseudo-elements on root: '::before'
181
- * - Pseudo on sub-element: '@::before', '>@:hover'
182
- * - Classes: '.active', '>@.active'
183
- * - Multiple selectors: '>, >Body>'
184
- * - Sibling combinators (after element): '>Item+', '>Item~'
185
- */
186
- function processAffix(affix, key) {
187
- const trimmed = affix.trim();
188
- if (!trimmed) return {
189
- valid: true,
190
- selectors: [` [data-element="${key}"]`]
191
- };
192
- const patterns = trimmed.split(",").map((p) => p.trim());
193
- const selectors = [];
194
- for (const pattern of patterns) {
195
- const validation = validatePattern(pattern);
196
- if (!validation.valid) return validation;
197
- const selector = processSinglePattern(pattern, key);
198
- selectors.push(selector);
199
- }
200
- return {
201
- valid: true,
202
- selectors
203
- };
204
- }
205
- /**
206
- * Recognized token patterns for selector affix validation.
207
- *
208
- * These patterns are used to tokenize and validate `$` affix strings.
209
- * Order matters: more specific patterns must come first to avoid
210
- * partial matches (e.g., `::before` must match before `:` alone).
211
- *
212
- * Unrecognized tokens (like `#id`, `*`, or numbers) will cause validation to fail.
213
- */
214
- const VALID_TOKEN_PATTERNS = [
215
- /^[>+~]/,
216
- /^\*/,
217
- /^[A-Z][a-zA-Z0-9]*/,
218
- /^@/,
219
- /^::?[a-z][a-z0-9-]*(?:\([^)]*\))?/,
220
- /^\.[a-zA-Z_-][a-zA-Z0-9_-]*/,
221
- /^\[[^\]]+\]/,
222
- /^[a-z][a-z0-9-]*/,
223
- /^\s+/,
224
- /^&/
225
- ];
226
- /**
227
- * Scan a pattern for unrecognized tokens.
228
- *
229
- * Iterates through the pattern, consuming recognized tokens until
230
- * either the pattern is fully consumed (valid) or an unrecognized
231
- * character sequence is found (invalid).
232
- *
233
- * @param pattern - The selector pattern to validate
234
- * @returns The first unrecognized token found, or null if all tokens are valid
235
- *
236
- * @example
237
- * findUnrecognizedTokens('>Body>Row>') // → null (valid)
238
- * findUnrecognizedTokens('123') // → '123' (invalid)
239
- * findUnrecognizedTokens('#myId') // → '#' (invalid)
240
- */
241
- function findUnrecognizedTokens(pattern) {
242
- let remaining = pattern;
243
- while (remaining.length > 0) {
244
- let matched = false;
245
- for (const regex of VALID_TOKEN_PATTERNS) {
246
- const match = remaining.match(regex);
247
- if (match) {
248
- remaining = remaining.slice(match[0].length);
249
- matched = true;
250
- break;
251
- }
252
- }
253
- if (!matched) {
254
- const unrecognized = remaining.match(/^[^\s>+~@.:[\]A-Z]+/);
255
- return unrecognized ? unrecognized[0] : remaining[0];
256
- }
257
- }
258
- return null;
259
- }
260
- /**
261
- * Validate a selector pattern for structural correctness.
262
- *
263
- * Checks for:
264
- * 1. Out-of-scope selectors: Patterns starting with `+` or `~` target siblings
265
- * of the root element, which is outside the component's DOM scope.
266
- * 2. Consecutive combinators: Patterns like `>>` or `>+` are malformed CSS.
267
- * 3. Unrecognized tokens: Characters/sequences not matching valid CSS selectors.
268
- *
269
- * @param pattern - A single selector pattern (already split by comma)
270
- * @returns AffixResult indicating validity and error reason if invalid
271
- *
272
- * @example
273
- * validatePattern('>Body>Row>') // → { valid: true, selectors: [] }
274
- * validatePattern('+') // → { valid: false, reason: '...outside root scope...' }
275
- * validatePattern('>>') // → { valid: false, reason: '...consecutive combinators...' }
276
- */
277
- function validatePattern(pattern) {
278
- const trimmed = pattern.trim();
279
- if (/^[+~]/.test(trimmed)) return {
280
- valid: false,
281
- reason: `Selector affix "${pattern}" targets elements outside the root scope. Sibling selectors (+, ~) must be preceded by an element inside the root. Use ">Element+" or ">Element~" instead.`
282
- };
283
- if (/[>+~]{2,}/.test(trimmed.replace(/\s+/g, ""))) return {
284
- valid: false,
285
- reason: `Selector affix "${pattern}" contains consecutive combinators.`
286
- };
287
- const unrecognized = findUnrecognizedTokens(trimmed);
288
- if (unrecognized) return {
289
- valid: false,
290
- reason: `Selector affix "${pattern}" contains unrecognized token "${unrecognized}". Valid tokens: combinators (>, +, ~), element names (Uppercase), @ placeholder, pseudo (:hover, ::before), class (.name), attribute ([attr]).`
291
- };
292
- return {
293
- valid: true,
294
- selectors: []
295
- };
296
- }
297
- /**
298
- * Process a single selector pattern into a CSS selector suffix.
299
- *
300
- * This is the main transformation function that converts a `$` affix pattern
301
- * into a valid CSS selector suffix. It handles:
302
- *
303
- * 1. `@` placeholder replacement with `[data-element="key"]`
304
- * 2. Key injection based on pattern ending (see `shouldInjectKey`)
305
- * 3. Proper spacing for descendant vs direct child selectors
306
- *
307
- * @param pattern - A single validated selector pattern
308
- * @param key - The sub-element key to inject (e.g., 'Label', 'Cell')
309
- * @returns CSS selector suffix ready to append to the root selector
310
- *
311
- * @example
312
- * processSinglePattern('>', 'Row')
313
- * // → '> [data-element="Row"]'
314
- *
315
- * processSinglePattern('>Body>Row>', 'Cell')
316
- * // → '> [data-element="Body"] > [data-element="Row"] > [data-element="Cell"]'
317
- *
318
- * processSinglePattern('::before', 'Before')
319
- * // → '::before' (no key injection for pseudo on root)
320
- *
321
- * processSinglePattern('>@:hover', 'Item')
322
- * // → '> [data-element="Item"]:hover'
323
- */
324
- function processSinglePattern(pattern, key) {
325
- const normalized = pattern.replace(/^&/, "").trim();
326
- if (!normalized) return ` [data-element="${key}"]`;
327
- const startsWithPseudo = /^::?[a-z]/.test(normalized);
328
- let result = transformPattern(normalized);
329
- if (result.includes("@")) {
330
- result = result.replace(/@ (?=[.:])/g, "@");
331
- result = result.replace(/@/g, `[data-element="${key}"]`);
332
- if (!startsWithPseudo && !result.startsWith(" ")) result = " " + result;
333
- return result;
334
- }
335
- if (shouldInjectKey(normalized)) result = result + ` [data-element="${key}"]`;
336
- if (!startsWithPseudo && !result.startsWith(" ")) result = " " + result;
337
- return result;
338
- }
339
- /**
340
- * Transform a selector pattern by converting element names and normalizing spacing.
341
- *
342
- * This is a character-by-character tokenizer that:
343
- * - Converts uppercase names to `[data-element="Name"]` selectors
344
- * - Adds proper spacing around combinators (>, +, ~)
345
- * - Preserves lowercase tags, classes, pseudos, and attributes as-is
346
- * - Keeps @ placeholder for later replacement
347
- *
348
- * The tokenizer handles these token types in order:
349
- * 1. Whitespace (skipped)
350
- * 2. Combinators: >, +, ~ (add surrounding spaces)
351
- * 3. Universal selector: * (keep as-is with spacing)
352
- * 4. Uppercase names: Body, Row (convert to [data-element="..."])
353
- * 5. @ placeholder (keep for later replacement)
354
- * 6. Pseudo: :hover, ::before (attach to previous token)
355
- * 7. Tags: a, div, button (keep as-is with spacing)
356
- * 8. Classes: .active (attach to previous element/tag/placeholder)
357
- * 9. Attributes: [type="text"] (keep as-is)
358
- *
359
- * @param pattern - The raw selector pattern to transform
360
- * @returns Transformed pattern with proper CSS selector syntax
361
- *
362
- * @example
363
- * transformPattern('>Body>Row>')
364
- * // → '> [data-element="Body"] > [data-element="Row"] >'
365
- *
366
- * transformPattern('button.primary:hover')
367
- * // → 'button.primary:hover'
368
- */
369
- function transformPattern(pattern) {
370
- let result = "";
371
- let lastCh = "";
372
- let i = 0;
373
- while (i < pattern.length) {
374
- const char = pattern[i];
375
- if (/\s/.test(char)) {
376
- i++;
377
- continue;
378
- }
379
- if (/[>+~]/.test(char)) {
380
- if (result && lastCh !== " ") result += " ";
381
- result += char;
382
- lastCh = char;
383
- i++;
384
- continue;
385
- }
386
- if (char === "*") {
387
- if (result && lastCh !== " ") result += " ";
388
- result += "*";
389
- lastCh = "*";
390
- i++;
391
- continue;
392
- }
393
- if (/[A-Z]/.test(char)) {
394
- const nameStart = i;
395
- while (i < pattern.length && /[a-zA-Z0-9]/.test(pattern[i])) i++;
396
- if (result && lastCh !== " ") result += " ";
397
- const segment = `[data-element="${pattern.slice(nameStart, i)}"]`;
398
- result += segment;
399
- lastCh = "]";
400
- continue;
401
- }
402
- if (char === "@") {
403
- if (result && lastCh !== " ") result += " ";
404
- result += "@";
405
- lastCh = "@";
406
- i++;
407
- continue;
408
- }
409
- if (char === ":") {
410
- const pseudoStart = i;
411
- while (i < pattern.length && !/[\s>+~,@]/.test(pattern[i]) && !/[A-Z]/.test(pattern[i])) i++;
412
- const segment = pattern.slice(pseudoStart, i);
413
- result += segment;
414
- lastCh = segment[segment.length - 1] || lastCh;
415
- continue;
416
- }
417
- if (/[a-z]/.test(char)) {
418
- const tagStart = i;
419
- while (i < pattern.length && /[a-z0-9-]/.test(pattern[i])) i++;
420
- if (result && lastCh !== " ") result += " ";
421
- const segment = pattern.slice(tagStart, i);
422
- result += segment;
423
- lastCh = segment[segment.length - 1] || lastCh;
424
- continue;
425
- }
426
- if (char === ".") {
427
- const attachToLast = lastCh === "]" || lastCh === "@" || /[a-zA-Z0-9-]/.test(lastCh);
428
- if (result && !attachToLast && lastCh !== " ") result += " ";
429
- const clsStart = i;
430
- i++;
431
- while (i < pattern.length && /[a-zA-Z0-9_-]/.test(pattern[i])) i++;
432
- const segment = pattern.slice(clsStart, i);
433
- result += segment;
434
- lastCh = segment[segment.length - 1] || lastCh;
435
- continue;
436
- }
437
- if (char === "[") {
438
- const attachToLast = lastCh === "]" || lastCh === "@" || /[a-zA-Z0-9-]/.test(lastCh);
439
- if (result && !attachToLast && lastCh !== " ") result += " ";
440
- const attrStart = i;
441
- let depth = 0;
442
- while (i < pattern.length) {
443
- if (pattern[i] === "[") depth++;
444
- if (pattern[i] === "]") depth--;
445
- i++;
446
- if (depth === 0) break;
447
- }
448
- result += pattern.slice(attrStart, i);
449
- lastCh = "]";
450
- continue;
451
- }
452
- result += char;
453
- lastCh = char;
454
- i++;
455
- }
456
- return result;
457
- }
458
- /**
459
- * Determine if the sub-element key should be auto-injected based on pattern ending.
460
- *
461
- * Key injection rules (when no @ placeholder is present):
462
- *
463
- * | Pattern Ending | Inject Key? | Example | Result |
464
- * |----------------|-------------|---------|--------|
465
- * | Combinator (>, +, ~) | Yes | `'>Body>'` | `> [data-element="Body"] > [el]` |
466
- * | Uppercase element | Yes | `'>Body>Row'` | `> [el1] > [el2] [key]` |
467
- * | Lowercase tag | No | `'h1'` | ` h1` |
468
- * | Universal (*) | No | `'h1 *'` | ` h1 *` |
469
- * | Pseudo (:hover, ::before) | No | `'::before'` | `::before` |
470
- * | Class (.active) | No | `'.active'` | `.active` |
471
- * | Attribute ([type]) | No | `'[type="text"]'` | `[type="text"]` |
472
- *
473
- * @param pattern - The normalized pattern (after stripping &)
474
- * @returns true if key should be injected, false otherwise
475
- *
476
- * @example
477
- * shouldInjectKey('>') // → true (trailing combinator)
478
- * shouldInjectKey('>Body>Row') // → true (ends with element)
479
- * shouldInjectKey('h1') // → false (ends with tag)
480
- * shouldInjectKey('*') // → false (universal selector)
481
- * shouldInjectKey('::before') // → false (ends with pseudo)
482
- * shouldInjectKey('.active') // → false (ends with class)
483
- * shouldInjectKey('a:hover') // → false (ends with pseudo)
484
- * shouldInjectKey('button.primary') // → false (ends with class)
485
- */
486
- function shouldInjectKey(pattern) {
487
- const trimmed = pattern.trim();
488
- if (/[>+~]$/.test(trimmed)) return true;
489
- if (/(?:^|[\s>+~\]:])[A-Z][a-zA-Z0-9]*$/.test(trimmed)) return true;
490
- return false;
491
- }
492
- /**
493
- * Normalize selector suffix from $ property
494
- */
495
- function normalizeSelectorSuffix(suffix) {
496
- if (!suffix) return "";
497
- return suffix.startsWith("&") ? suffix.slice(1) : suffix;
498
- }
499
- /**
500
- * Build handler queue from style keys
501
- */
502
- function buildHandlerQueue(styleKeys, styles) {
503
- const queue = [];
504
- const seenHandlers = /* @__PURE__ */ new Set();
505
- for (const styleName of styleKeys) {
506
- let handlers = STYLE_HANDLER_MAP[styleName];
507
- if (!handlers) handlers = STYLE_HANDLER_MAP[styleName] = [createStyle(styleName)];
508
- for (const handler of handlers) {
509
- if (seenHandlers.has(handler)) continue;
510
- seenHandlers.add(handler);
511
- const lookupStyles = handler.__lookupStyles;
512
- const styleMap = {};
513
- for (const name of lookupStyles) {
514
- const val = styles[name];
515
- if (val !== void 0) styleMap[name] = val;
516
- }
517
- queue.push({
518
- handler,
519
- styleMap
520
- });
521
- }
522
- }
523
- return queue;
524
- }
525
- /**
526
- * Compute all valid state combinations for a handler's lookup styles
527
- */
528
- function computeStateCombinations(exclusiveByStyle, lookupStyles) {
529
- const combinations = cartesianProduct(lookupStyles.map((style) => exclusiveByStyle.get(style) || []));
530
- const snapshots = [];
531
- for (const combo of combinations) {
532
- const simplified = simplifyCondition(and(...combo.map((e) => e.exclusiveCondition)));
533
- if (simplified.kind === "false") continue;
534
- const values = {};
535
- for (const entry of combo) values[entry.styleKey] = entry.value;
536
- snapshots.push({
537
- condition: simplified,
538
- values
539
- });
540
- }
541
- return snapshots;
542
- }
543
- /**
544
- * Cartesian product of arrays
545
- */
546
- function cartesianProduct(arrays) {
547
- if (arrays.length === 0) return [[]];
548
- const nonEmpty = arrays.filter((a) => a.length > 0);
549
- if (nonEmpty.length === 0) return [[]];
550
- let result = [[]];
551
- for (const arr of nonEmpty) {
552
- const next = [];
553
- for (const combo of result) for (const item of arr) {
554
- const newCombo = new Array(combo.length + 1);
555
- for (let i = 0; i < combo.length; i++) newCombo[i] = combo[i];
556
- newCombo[combo.length] = item;
557
- next.push(newCombo);
558
- }
559
- result = next;
560
- }
561
- return result;
562
- }
563
- const declStringCache = /* @__PURE__ */ new WeakMap();
564
- function stringifyDeclarations(decl) {
565
- let cached = declStringCache.get(decl);
566
- if (cached === void 0) {
567
- cached = JSON.stringify(decl);
568
- declStringCache.set(decl, cached);
569
- }
570
- return cached;
571
- }
572
- /**
573
- * Merge rules with identical CSS output
574
- */
575
- function mergeByValue(rules) {
576
- const groups = /* @__PURE__ */ new Map();
577
- for (const rule of rules) {
578
- const key = `${rule.selectorSuffix}|${stringifyDeclarations(rule.declarations)}`;
579
- if (!groups.has(key)) groups.set(key, []);
580
- groups.get(key).push(rule);
581
- }
582
- const merged = [];
583
- for (const [, groupRules] of groups) if (groupRules.length === 1) merged.push(groupRules[0]);
584
- else {
585
- const mergedCondition = simplifyCondition(or(...groupRules.map((r) => r.condition)));
586
- merged.push({
587
- condition: mergedCondition,
588
- declarations: groupRules[0].declarations,
589
- selectorSuffix: groupRules[0].selectorSuffix
590
- });
591
- }
592
- return merged;
593
- }
594
- /**
595
- * Build selector fragment from a variant (without className prefix)
596
- */
597
- function buildSelectorFromVariant(variant, selectorSuffix) {
598
- let selector = "";
599
- selector += branchToCSS([...variant.modifierConditions, ...variant.pseudoConditions]);
600
- for (const group of variant.selectorGroups) selector += selectorGroupToCSS(group);
601
- if (variant.parentGroups.length > 0) selector += parentGroupsToCSS(variant.parentGroups);
602
- selector += selectorSuffix;
603
- const ownOptimized = optimizeGroups(variant.ownGroups);
604
- for (const group of ownOptimized) selector += selectorGroupToCSS(group);
605
- return selector;
606
- }
607
- /**
608
- * Materialize a computed rule to final CSS format
609
- *
610
- * Returns an array because OR conditions may generate multiple CSS rules
611
- * (when different branches have different at-rules)
612
- */
613
- function materializeComputedRule(rule) {
614
- const components = conditionToCSS(rule.condition);
615
- if (components.isImpossible || components.variants.length === 0) return [];
616
- const declarations = Object.entries(rule.declarations).map(([prop, value]) => `${prop}: ${value};`).join(" ");
617
- const getRootPrefixKey = (variant) => {
618
- return rootGroupsToCSS(variant.rootGroups) || "";
619
- };
620
- const byAtRules = /* @__PURE__ */ new Map();
621
- for (const variant of components.variants) {
622
- const atRules = buildAtRulesFromVariant(variant);
623
- const startingStyle = variant.startingStyle;
624
- const key = atRules.sort().join("|||") + "###" + getRootPrefixKey(variant) + "###" + (startingStyle ? "1" : "0");
625
- const group = byAtRules.get(key);
626
- if (group) group.variants.push(variant);
627
- else byAtRules.set(key, {
628
- variants: [variant],
629
- atRules,
630
- rootPrefix: rootGroupsToCSS(variant.rootGroups),
631
- startingStyle: startingStyle || void 0
632
- });
633
- }
634
- const rules = [];
635
- for (const [, group] of byAtRules) {
636
- const selectorFragments = mergeVariantsIntoSelectorGroups(group.variants).map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
637
- const cssRule = {
638
- selector: selectorFragments.length === 1 ? selectorFragments[0] : selectorFragments,
639
- declarations
640
- };
641
- if (group.atRules.length > 0) cssRule.atRules = group.atRules;
642
- if (group.rootPrefix) cssRule.rootPrefix = group.rootPrefix;
643
- if (group.startingStyle) cssRule.startingStyle = true;
644
- rules.push(cssRule);
645
- }
646
- return rules;
647
- }
648
- /**
649
- * Merge StyleResult entries that share the same selector and at-rules,
650
- * concatenating their declarations into a single rule.
651
- *
652
- * This reduces CSS output size when many style keys (e.g. design tokens)
653
- * resolve to the same selector/state combination.
654
- */
655
- function mergeStyleResults(results) {
656
- if (results.length <= 1) return results;
657
- const groups = /* @__PURE__ */ new Map();
658
- for (const result of results) {
659
- const key = `${result.atRules?.join("|") ?? ""}||${result.selector}||${result.startingStyle ? "1" : "0"}`;
660
- const existing = groups.get(key);
661
- if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${result.declarations}` : result.declarations;
662
- else groups.set(key, { ...result });
663
- }
664
- return Array.from(groups.values());
665
- }
666
- function renderStyles(styles, classNameOrSelector, options, pipelineCacheKey) {
667
- const directSelector = !!classNameOrSelector;
668
- let rules;
669
- if (pipelineCacheKey) rules = pipelineCache.get(pipelineCacheKey);
670
- if (!rules && !styles) return directSelector ? [] : { rules: [] };
671
- const cacheKey = pipelineCacheKey || stringifyStyles(styles);
672
- if (!rules) rules = pipelineCache.get(cacheKey);
673
- if (!rules) {
674
- rules = runPipeline(styles, createStateParserContext(styles));
675
- pipelineCache.set(cacheKey, rules);
676
- }
677
- if (directSelector) {
678
- const shouldDouble = options?.doubleSelector ?? false;
679
- return mergeStyleResults(rules.map((rule) => {
680
- const result = {
681
- selector: (Array.isArray(rule.selector) ? rule.selector : rule.selector ? [rule.selector] : [""]).map((part) => {
682
- let sel = part ? `${classNameOrSelector}${part}` : classNameOrSelector;
683
- if (shouldDouble && sel.startsWith(".")) {
684
- const classMatch = sel.match(/^\.[a-zA-Z_-][a-zA-Z0-9_-]*/);
685
- if (classMatch) sel = classMatch[0] + sel;
686
- }
687
- if (rule.rootPrefix) sel = `${rule.rootPrefix} ${sel}`;
688
- return sel;
689
- }).join(", "),
690
- declarations: rule.declarations
691
- };
692
- if (rule.atRules && rule.atRules.length > 0) result.atRules = rule.atRules;
693
- if (rule.startingStyle) result.startingStyle = true;
694
- return result;
695
- }));
696
- }
697
- return { rules: rules.map((r) => ({
698
- selector: Array.isArray(r.selector) ? r.selector.join("|||") : r.selector,
699
- declarations: r.declarations,
700
- atRules: r.atRules,
701
- needsClassName: true,
702
- rootPrefix: r.rootPrefix,
703
- startingStyle: r.startingStyle
704
- })) };
705
- }
706
-
707
- //#endregion
708
- export { clearPipelineCache, hasPipelineCacheEntry, isSelector, renderStyles };
709
- //# sourceMappingURL=index.js.map