@tenphi/tasty 0.0.0-snapshot.fa94a5a → 0.0.0-snapshot.fdb16ea

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