@fluixi-css/core 0.1.0-next.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.
Files changed (389) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -0
  3. package/base.css +4 -0
  4. package/components.css +1 -0
  5. package/dist/base.css +4 -0
  6. package/dist/components.css +1 -0
  7. package/dist/index.css +2 -0
  8. package/dist/package.json +139 -0
  9. package/dist/reset.css +168 -0
  10. package/dist/src/ast.d.ts +298 -0
  11. package/dist/src/ast.js +2240 -0
  12. package/dist/src/ast.js.map +1 -0
  13. package/dist/src/commons/constants.d.ts +1193 -0
  14. package/dist/src/commons/constants.js +1323 -0
  15. package/dist/src/commons/constants.js.map +1 -0
  16. package/dist/src/commons/helper.d.ts +1298 -0
  17. package/dist/src/commons/helper.js +1310 -0
  18. package/dist/src/commons/helper.js.map +1 -0
  19. package/dist/src/commons/index.d.ts +3 -0
  20. package/dist/src/commons/index.js +4 -0
  21. package/dist/src/commons/index.js.map +1 -0
  22. package/dist/src/commons/properties.d.ts +1431 -0
  23. package/dist/src/commons/properties.js +2855 -0
  24. package/dist/src/commons/properties.js.map +1 -0
  25. package/dist/src/commons/types.d.ts +359 -0
  26. package/dist/src/commons/types.js +4 -0
  27. package/dist/src/commons/types.js.map +1 -0
  28. package/dist/src/components/avatar/index.d.ts +19 -0
  29. package/dist/src/components/avatar/index.js +22 -0
  30. package/dist/src/components/avatar/index.js.map +1 -0
  31. package/dist/src/components/button/index.d.ts +48 -0
  32. package/dist/src/components/button/index.js +51 -0
  33. package/dist/src/components/button/index.js.map +1 -0
  34. package/dist/src/components/card/index.d.ts +44 -0
  35. package/dist/src/components/card/index.js +47 -0
  36. package/dist/src/components/card/index.js.map +1 -0
  37. package/dist/src/components/checkbox/index.d.ts +69 -0
  38. package/dist/src/components/checkbox/index.js +80 -0
  39. package/dist/src/components/checkbox/index.js.map +1 -0
  40. package/dist/src/components/daterangepicker/index.d.ts +147 -0
  41. package/dist/src/components/daterangepicker/index.js +150 -0
  42. package/dist/src/components/daterangepicker/index.js.map +1 -0
  43. package/dist/src/components/dialog/index.d.ts +71 -0
  44. package/dist/src/components/dialog/index.js +74 -0
  45. package/dist/src/components/dialog/index.js.map +1 -0
  46. package/dist/src/components/drawer/index.d.ts +26 -0
  47. package/dist/src/components/drawer/index.js +29 -0
  48. package/dist/src/components/drawer/index.js.map +1 -0
  49. package/dist/src/components/dropdown/index.d.ts +101 -0
  50. package/dist/src/components/dropdown/index.js +104 -0
  51. package/dist/src/components/dropdown/index.js.map +1 -0
  52. package/dist/src/components/forms/index.d.ts +58 -0
  53. package/dist/src/components/forms/index.js +62 -0
  54. package/dist/src/components/forms/index.js.map +1 -0
  55. package/dist/src/components/index.d.ts +1228 -0
  56. package/dist/src/components/index.js +64 -0
  57. package/dist/src/components/index.js.map +1 -0
  58. package/dist/src/components/layout/index.d.ts +28 -0
  59. package/dist/src/components/layout/index.js +33 -0
  60. package/dist/src/components/layout/index.js.map +1 -0
  61. package/dist/src/components/list/index.d.ts +65 -0
  62. package/dist/src/components/list/index.js +68 -0
  63. package/dist/src/components/list/index.js.map +1 -0
  64. package/dist/src/components/popover/index.d.ts +79 -0
  65. package/dist/src/components/popover/index.js +82 -0
  66. package/dist/src/components/popover/index.js.map +1 -0
  67. package/dist/src/components/radio/index.d.ts +77 -0
  68. package/dist/src/components/radio/index.js +80 -0
  69. package/dist/src/components/radio/index.js.map +1 -0
  70. package/dist/src/components/select/index.d.ts +102 -0
  71. package/dist/src/components/select/index.js +105 -0
  72. package/dist/src/components/select/index.js.map +1 -0
  73. package/dist/src/components/sidenav/index.d.ts +98 -0
  74. package/dist/src/components/sidenav/index.js +101 -0
  75. package/dist/src/components/sidenav/index.js.map +1 -0
  76. package/dist/src/components/table/index.d.ts +95 -0
  77. package/dist/src/components/table/index.js +98 -0
  78. package/dist/src/components/table/index.js.map +1 -0
  79. package/dist/src/constants.d.ts +3 -0
  80. package/dist/src/constants.js +29 -0
  81. package/dist/src/constants.js.map +1 -0
  82. package/dist/src/css-ast.d.ts +48 -0
  83. package/dist/src/css-ast.js +2 -0
  84. package/dist/src/css-ast.js.map +1 -0
  85. package/dist/src/css-generator.d.ts +29 -0
  86. package/dist/src/css-generator.js +104 -0
  87. package/dist/src/css-generator.js.map +1 -0
  88. package/dist/src/css-helpers.d.ts +76 -0
  89. package/dist/src/css-helpers.js +272 -0
  90. package/dist/src/css-helpers.js.map +1 -0
  91. package/dist/src/css-lexer.d.ts +48 -0
  92. package/dist/src/css-lexer.js +255 -0
  93. package/dist/src/css-lexer.js.map +1 -0
  94. package/dist/src/css-parser.cjs +2047 -0
  95. package/dist/src/css-parser.cjs.map +1 -0
  96. package/dist/src/css-parser.d.ts +100 -0
  97. package/dist/src/css-parser.js +1098 -0
  98. package/dist/src/css-parser.js.map +1 -0
  99. package/dist/src/css-parser.mjs +2028 -0
  100. package/dist/src/css-parser.mjs.map +1 -0
  101. package/dist/src/design-system.d.ts +210 -0
  102. package/dist/src/design-system.js +1034 -0
  103. package/dist/src/design-system.js.map +1 -0
  104. package/dist/src/engine/ast.d.ts +44 -0
  105. package/dist/src/engine/ast.js +92 -0
  106. package/dist/src/engine/ast.js.map +1 -0
  107. package/dist/src/engine/atom.d.ts +74 -0
  108. package/dist/src/engine/atom.js +227 -0
  109. package/dist/src/engine/atom.js.map +1 -0
  110. package/dist/src/engine/compile.d.ts +5 -0
  111. package/dist/src/engine/compile.js +79 -0
  112. package/dist/src/engine/compile.js.map +1 -0
  113. package/dist/src/engine/defaults.d.ts +2 -0
  114. package/dist/src/engine/defaults.js +14 -0
  115. package/dist/src/engine/defaults.js.map +1 -0
  116. package/dist/src/engine/directives.d.ts +2 -0
  117. package/dist/src/engine/directives.js +191 -0
  118. package/dist/src/engine/directives.js.map +1 -0
  119. package/dist/src/engine/index.d.ts +41 -0
  120. package/dist/src/engine/index.js +88 -0
  121. package/dist/src/engine/index.js.map +1 -0
  122. package/dist/src/engine/registry.d.ts +46 -0
  123. package/dist/src/engine/registry.js +49 -0
  124. package/dist/src/engine/registry.js.map +1 -0
  125. package/dist/src/engine/scanner.d.ts +1 -0
  126. package/dist/src/engine/scanner.js +45 -0
  127. package/dist/src/engine/scanner.js.map +1 -0
  128. package/dist/src/engine/source.d.ts +12 -0
  129. package/dist/src/engine/source.js +81 -0
  130. package/dist/src/engine/source.js.map +1 -0
  131. package/dist/src/engine/theme-defaults.d.ts +2 -0
  132. package/dist/src/engine/theme-defaults.js +54 -0
  133. package/dist/src/engine/theme-defaults.js.map +1 -0
  134. package/dist/src/engine/theme-source.d.ts +5 -0
  135. package/dist/src/engine/theme-source.js +71 -0
  136. package/dist/src/engine/theme-source.js.map +1 -0
  137. package/dist/src/engine/theme.d.ts +10 -0
  138. package/dist/src/engine/theme.js +42 -0
  139. package/dist/src/engine/theme.js.map +1 -0
  140. package/dist/src/engine/transform.d.ts +25 -0
  141. package/dist/src/engine/transform.js +91 -0
  142. package/dist/src/engine/transform.js.map +1 -0
  143. package/dist/src/engine/ui-preset.d.ts +4 -0
  144. package/dist/src/engine/ui-preset.js +56 -0
  145. package/dist/src/engine/ui-preset.js.map +1 -0
  146. package/dist/src/engine/utilities/backgrounds.d.ts +2 -0
  147. package/dist/src/engine/utilities/backgrounds.js +32 -0
  148. package/dist/src/engine/utilities/backgrounds.js.map +1 -0
  149. package/dist/src/engine/utilities/borders.d.ts +2 -0
  150. package/dist/src/engine/utilities/borders.js +95 -0
  151. package/dist/src/engine/utilities/borders.js.map +1 -0
  152. package/dist/src/engine/utilities/effects.d.ts +2 -0
  153. package/dist/src/engine/utilities/effects.js +61 -0
  154. package/dist/src/engine/utilities/effects.js.map +1 -0
  155. package/dist/src/engine/utilities/flexgrid.d.ts +2 -0
  156. package/dist/src/engine/utilities/flexgrid.js +125 -0
  157. package/dist/src/engine/utilities/flexgrid.js.map +1 -0
  158. package/dist/src/engine/utilities/index.d.ts +3 -0
  159. package/dist/src/engine/utilities/index.js +20 -0
  160. package/dist/src/engine/utilities/index.js.map +1 -0
  161. package/dist/src/engine/utilities/layout.d.ts +2 -0
  162. package/dist/src/engine/utilities/layout.js +84 -0
  163. package/dist/src/engine/utilities/layout.js.map +1 -0
  164. package/dist/src/engine/utilities/sizing.d.ts +2 -0
  165. package/dist/src/engine/utilities/sizing.js +21 -0
  166. package/dist/src/engine/utilities/sizing.js.map +1 -0
  167. package/dist/src/engine/utilities/spacing.d.ts +2 -0
  168. package/dist/src/engine/utilities/spacing.js +39 -0
  169. package/dist/src/engine/utilities/spacing.js.map +1 -0
  170. package/dist/src/engine/utilities/typography.d.ts +2 -0
  171. package/dist/src/engine/utilities/typography.js +120 -0
  172. package/dist/src/engine/utilities/typography.js.map +1 -0
  173. package/dist/src/engine/utilities/values.d.ts +16 -0
  174. package/dist/src/engine/utilities/values.js +91 -0
  175. package/dist/src/engine/utilities/values.js.map +1 -0
  176. package/dist/src/engine/variants.d.ts +2 -0
  177. package/dist/src/engine/variants.js +99 -0
  178. package/dist/src/engine/variants.js.map +1 -0
  179. package/dist/src/extractor.d.ts +146 -0
  180. package/dist/src/extractor.js +3862 -0
  181. package/dist/src/extractor.js.map +1 -0
  182. package/dist/src/index.cjs +4518 -0
  183. package/dist/src/index.cjs.map +1 -0
  184. package/dist/src/index.d.ts +1 -0
  185. package/dist/src/index.js +9 -0
  186. package/dist/src/index.js.map +1 -0
  187. package/dist/src/index.mjs +4480 -0
  188. package/dist/src/index.mjs.map +1 -0
  189. package/dist/src/keyframes.cjs +367 -0
  190. package/dist/src/keyframes.cjs.map +1 -0
  191. package/dist/src/keyframes.d.ts +27 -0
  192. package/dist/src/keyframes.js +188 -0
  193. package/dist/src/keyframes.js.map +1 -0
  194. package/dist/src/keyframes.mjs +362 -0
  195. package/dist/src/keyframes.mjs.map +1 -0
  196. package/dist/src/logger.d.ts +2 -0
  197. package/dist/src/logger.js +31 -0
  198. package/dist/src/logger.js.map +1 -0
  199. package/dist/src/plugin.cjs +43 -0
  200. package/dist/src/plugin.cjs.map +1 -0
  201. package/dist/src/plugin.d.ts +12 -0
  202. package/dist/src/plugin.js +39 -0
  203. package/dist/src/plugin.js.map +1 -0
  204. package/dist/src/plugin.mjs +41 -0
  205. package/dist/src/plugin.mjs.map +1 -0
  206. package/dist/src/presets-plugins.cjs +99 -0
  207. package/dist/src/presets-plugins.cjs.map +1 -0
  208. package/dist/src/presets-plugins.d.ts +1 -0
  209. package/dist/src/presets-plugins.js +56 -0
  210. package/dist/src/presets-plugins.js.map +1 -0
  211. package/dist/src/presets-plugins.mjs +97 -0
  212. package/dist/src/presets-plugins.mjs.map +1 -0
  213. package/dist/src/state.d.ts +76 -0
  214. package/dist/src/state.js +314 -0
  215. package/dist/src/state.js.map +1 -0
  216. package/dist/src/theme/constants.d.ts +22 -0
  217. package/dist/src/theme/constants.js +17 -0
  218. package/dist/src/theme/constants.js.map +1 -0
  219. package/dist/src/theme/index.d.ts +2 -0
  220. package/dist/src/theme/index.js +48 -0
  221. package/dist/src/theme/index.js.map +1 -0
  222. package/dist/src/theme/types.d.ts +13 -0
  223. package/dist/src/theme/types.js +2 -0
  224. package/dist/src/theme/types.js.map +1 -0
  225. package/dist/src/types/ast.d.ts +23 -0
  226. package/dist/src/types/ast.js +2 -0
  227. package/dist/src/types/ast.js.map +1 -0
  228. package/dist/src/types/base-types.d.ts +53 -0
  229. package/dist/src/types/base-types.js +2 -0
  230. package/dist/src/types/base-types.js.map +1 -0
  231. package/dist/src/types/components-types.d.ts +28 -0
  232. package/dist/src/types/components-types.js +2 -0
  233. package/dist/src/types/components-types.js.map +1 -0
  234. package/dist/src/types/config.d.ts +90 -0
  235. package/dist/src/types/config.js +3 -0
  236. package/dist/src/types/config.js.map +1 -0
  237. package/dist/src/types/css-parser.d.ts +361 -0
  238. package/dist/src/types/css-parser.js +2 -0
  239. package/dist/src/types/css-parser.js.map +1 -0
  240. package/dist/src/types/keyframes-type.d.ts +47 -0
  241. package/dist/src/types/keyframes-type.js +2 -0
  242. package/dist/src/types/keyframes-type.js.map +1 -0
  243. package/dist/src/types/plugin.d.ts +10 -0
  244. package/dist/src/types/plugin.js +2 -0
  245. package/dist/src/types/plugin.js.map +1 -0
  246. package/dist/src/types/screens-types.d.ts +47 -0
  247. package/dist/src/types/screens-types.js +2 -0
  248. package/dist/src/types/screens-types.js.map +1 -0
  249. package/dist/src/types/utilities-types.d.ts +147 -0
  250. package/dist/src/types/utilities-types.js +2 -0
  251. package/dist/src/types/utilities-types.js.map +1 -0
  252. package/dist/src/types.d.ts +77 -0
  253. package/dist/src/types.js +12 -0
  254. package/dist/src/types.js.map +1 -0
  255. package/dist/src/units/constants.d.ts +35 -0
  256. package/dist/src/units/constants.js +9 -0
  257. package/dist/src/units/constants.js.map +1 -0
  258. package/dist/src/units/index.d.ts +15 -0
  259. package/dist/src/units/index.js +7 -0
  260. package/dist/src/units/index.js.map +1 -0
  261. package/dist/src/units/types.d.ts +9 -0
  262. package/dist/src/units/types.js +2 -0
  263. package/dist/src/units/types.js.map +1 -0
  264. package/dist/src/utilities/backgrounds/constants.d.ts +2810 -0
  265. package/dist/src/utilities/backgrounds/constants.js +119 -0
  266. package/dist/src/utilities/backgrounds/constants.js.map +1 -0
  267. package/dist/src/utilities/backgrounds/index.d.ts +1 -0
  268. package/dist/src/utilities/backgrounds/index.js +2 -0
  269. package/dist/src/utilities/backgrounds/index.js.map +1 -0
  270. package/dist/src/utilities/borders/constants.d.ts +10586 -0
  271. package/dist/src/utilities/borders/constants.js +309 -0
  272. package/dist/src/utilities/borders/constants.js.map +1 -0
  273. package/dist/src/utilities/borders/index.d.ts +1 -0
  274. package/dist/src/utilities/borders/index.js +2 -0
  275. package/dist/src/utilities/borders/index.js.map +1 -0
  276. package/dist/src/utilities/breakpoints/constants.d.ts +330 -0
  277. package/dist/src/utilities/breakpoints/constants.js +269 -0
  278. package/dist/src/utilities/breakpoints/constants.js.map +1 -0
  279. package/dist/src/utilities/breakpoints/index.d.ts +2 -0
  280. package/dist/src/utilities/breakpoints/index.js +3 -0
  281. package/dist/src/utilities/breakpoints/index.js.map +1 -0
  282. package/dist/src/utilities/breakpoints/types.d.ts +8 -0
  283. package/dist/src/utilities/breakpoints/types.js +2 -0
  284. package/dist/src/utilities/breakpoints/types.js.map +1 -0
  285. package/dist/src/utilities/colors/base.d.ts +778 -0
  286. package/dist/src/utilities/colors/base.js +872 -0
  287. package/dist/src/utilities/colors/base.js.map +1 -0
  288. package/dist/src/utilities/colors/color.d.ts +1122 -0
  289. package/dist/src/utilities/colors/color.js +957 -0
  290. package/dist/src/utilities/colors/color.js.map +1 -0
  291. package/dist/src/utilities/colors/constants.d.ts +1 -0
  292. package/dist/src/utilities/colors/constants.js +2 -0
  293. package/dist/src/utilities/colors/constants.js.map +1 -0
  294. package/dist/src/utilities/colors/index.d.ts +4 -0
  295. package/dist/src/utilities/colors/index.js +29 -0
  296. package/dist/src/utilities/colors/index.js.map +1 -0
  297. package/dist/src/utilities/colors/types.d.ts +3 -0
  298. package/dist/src/utilities/colors/types.js +2 -0
  299. package/dist/src/utilities/colors/types.js.map +1 -0
  300. package/dist/src/utilities/effects/constants.d.ts +641 -0
  301. package/dist/src/utilities/effects/constants.js +83 -0
  302. package/dist/src/utilities/effects/constants.js.map +1 -0
  303. package/dist/src/utilities/effects/index.d.ts +1 -0
  304. package/dist/src/utilities/effects/index.js +2 -0
  305. package/dist/src/utilities/effects/index.js.map +1 -0
  306. package/dist/src/utilities/filters/constants.d.ts +406 -0
  307. package/dist/src/utilities/filters/constants.js +206 -0
  308. package/dist/src/utilities/filters/constants.js.map +1 -0
  309. package/dist/src/utilities/filters/index.d.ts +1 -0
  310. package/dist/src/utilities/filters/index.js +2 -0
  311. package/dist/src/utilities/filters/index.js.map +1 -0
  312. package/dist/src/utilities/flex/constants.d.ts +934 -0
  313. package/dist/src/utilities/flex/constants.js +221 -0
  314. package/dist/src/utilities/flex/constants.js.map +1 -0
  315. package/dist/src/utilities/flex/index.d.ts +1 -0
  316. package/dist/src/utilities/flex/index.js +2 -0
  317. package/dist/src/utilities/flex/index.js.map +1 -0
  318. package/dist/src/utilities/flex/types.d.ts +0 -0
  319. package/dist/src/utilities/flex/types.js +4 -0
  320. package/dist/src/utilities/flex/types.js.map +1 -0
  321. package/dist/src/utilities/index.d.ts +31338 -0
  322. package/dist/src/utilities/index.js +333 -0
  323. package/dist/src/utilities/index.js.map +1 -0
  324. package/dist/src/utilities/interactivity/constants.d.ts +1244 -0
  325. package/dist/src/utilities/interactivity/constants.js +165 -0
  326. package/dist/src/utilities/interactivity/constants.js.map +1 -0
  327. package/dist/src/utilities/interactivity/index.d.ts +1 -0
  328. package/dist/src/utilities/interactivity/index.js +2 -0
  329. package/dist/src/utilities/interactivity/index.js.map +1 -0
  330. package/dist/src/utilities/layout/constants.d.ts +837 -0
  331. package/dist/src/utilities/layout/constants.js +159 -0
  332. package/dist/src/utilities/layout/constants.js.map +1 -0
  333. package/dist/src/utilities/layout/index.d.ts +1 -0
  334. package/dist/src/utilities/layout/index.js +2 -0
  335. package/dist/src/utilities/layout/index.js.map +1 -0
  336. package/dist/src/utilities/layout/types.d.ts +0 -0
  337. package/dist/src/utilities/layout/types.js +2 -0
  338. package/dist/src/utilities/layout/types.js.map +1 -0
  339. package/dist/src/utilities/sizing/constants.d.ts +989 -0
  340. package/dist/src/utilities/sizing/constants.js +53 -0
  341. package/dist/src/utilities/sizing/constants.js.map +1 -0
  342. package/dist/src/utilities/sizing/index.d.ts +2 -0
  343. package/dist/src/utilities/sizing/index.js +3 -0
  344. package/dist/src/utilities/sizing/index.js.map +1 -0
  345. package/dist/src/utilities/sizing/types.d.ts +10 -0
  346. package/dist/src/utilities/sizing/types.js +2 -0
  347. package/dist/src/utilities/sizing/types.js.map +1 -0
  348. package/dist/src/utilities/spacing/constants.d.ts +1779 -0
  349. package/dist/src/utilities/spacing/constants.js +142 -0
  350. package/dist/src/utilities/spacing/constants.js.map +1 -0
  351. package/dist/src/utilities/spacing/index.d.ts +2 -0
  352. package/dist/src/utilities/spacing/index.js +3 -0
  353. package/dist/src/utilities/spacing/index.js.map +1 -0
  354. package/dist/src/utilities/spacing/types.d.ts +15 -0
  355. package/dist/src/utilities/spacing/types.js +8 -0
  356. package/dist/src/utilities/spacing/types.js.map +1 -0
  357. package/dist/src/utilities/svg/constants.d.ts +1062 -0
  358. package/dist/src/utilities/svg/constants.js +34 -0
  359. package/dist/src/utilities/svg/constants.js.map +1 -0
  360. package/dist/src/utilities/transforms/constants.d.ts +247 -0
  361. package/dist/src/utilities/transforms/constants.js +74 -0
  362. package/dist/src/utilities/transforms/constants.js.map +1 -0
  363. package/dist/src/utilities/transforms/index.d.ts +1 -0
  364. package/dist/src/utilities/transforms/index.js +2 -0
  365. package/dist/src/utilities/transforms/index.js.map +1 -0
  366. package/dist/src/utilities/transitions/constants.d.ts +116 -0
  367. package/dist/src/utilities/transitions/constants.js +91 -0
  368. package/dist/src/utilities/transitions/constants.js.map +1 -0
  369. package/dist/src/utilities/transitions/index.d.ts +1 -0
  370. package/dist/src/utilities/transitions/index.js +2 -0
  371. package/dist/src/utilities/transitions/index.js.map +1 -0
  372. package/dist/src/utilities/typography/constants.d.ts +2401 -0
  373. package/dist/src/utilities/typography/constants.js +401 -0
  374. package/dist/src/utilities/typography/constants.js.map +1 -0
  375. package/dist/src/utilities/typography/index.d.ts +1 -0
  376. package/dist/src/utilities/typography/index.js +2 -0
  377. package/dist/src/utilities/typography/index.js.map +1 -0
  378. package/dist/src/utils.d.ts +18 -0
  379. package/dist/src/utils.js +282 -0
  380. package/dist/src/utils.js.map +1 -0
  381. package/dist/src/watcher.d.ts +15 -0
  382. package/dist/src/watcher.js +62 -0
  383. package/dist/src/watcher.js.map +1 -0
  384. package/dist/tsconfig.tsbuildinfo +1 -0
  385. package/dist/utilities.css +1 -0
  386. package/index.css +2 -0
  387. package/package.json +139 -0
  388. package/reset.css +168 -0
  389. package/utilities.css +1 -0
@@ -0,0 +1,1098 @@
1
+ // ─── Charcode constants (avoids string allocation on hot paths) ───────────────
2
+ const CC_TAB = 9, CC_LF = 10, CC_CR = 13, CC_FF = 12, CC_SPACE = 32;
3
+ const CC_DQUOTE = 34, CC_HASH = 35, CC_AMP = 38, CC_SQUOTE = 39;
4
+ const CC_LPAREN = 40, CC_RPAREN = 41, CC_STAR = 42, CC_PLUS = 43;
5
+ const CC_COMMA = 44, CC_MINUS = 45, CC_DOT = 46, CC_SLASH = 47;
6
+ const CC_COLON = 58, CC_SEMI = 59, CC_LT = 60, CC_GT = 62;
7
+ const CC_AT = 64, CC_LBRACK = 91, CC_BSLASH = 92, CC_RBRACK = 93;
8
+ const CC_UNDER = 95, CC_LBRACE = 123, CC_RBRACE = 125, CC_TILDE = 126;
9
+ const CC_BANG = 33;
10
+ // ─── Character predicates (charcode-based, no regex) ─────────────────────────
11
+ function isWS(c) {
12
+ return c === CC_SPACE || c === CC_TAB || c === CC_LF || c === CC_CR || c === CC_FF;
13
+ }
14
+ function isDigit(c) { return c >= 48 && c <= 57; }
15
+ function isAlpha(c) {
16
+ return (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
17
+ }
18
+ function isHex(c) {
19
+ return isDigit(c) || (c >= 65 && c <= 70) || (c >= 97 && c <= 102);
20
+ }
21
+ /**
22
+ * CSS ident-start: letter | underscore | non-ASCII | hyphen.
23
+ * A leading hyphen is valid (vendor prefixes, custom properties).
24
+ */
25
+ function isNameStart(c) {
26
+ return isAlpha(c) || c === CC_UNDER || c === CC_MINUS || c > 127;
27
+ }
28
+ /** CSS ident-char: ident-start | digit */
29
+ function isNameChar(c) {
30
+ return isAlpha(c) || isDigit(c) || c === CC_UNDER || c === CC_MINUS || c > 127;
31
+ }
32
+ // ─── CssParser ────────────────────────────────────────────────────────────────
33
+ export class CssParser {
34
+ constructor(options = {}) {
35
+ this.input = '';
36
+ this.pos = 0;
37
+ this.length = 0;
38
+ this.line = 1;
39
+ this.col = 1;
40
+ this.errors = [];
41
+ this.warnings = [];
42
+ this.stats = CssParser.emptyStats();
43
+ this.options = Object.assign({ parseAtrulePrelude: true, parseValue: true, parseCustomProperty: true, parseRulePrelude: true, parseSelector: true, includeComments: true, includeSourceMaps: true, includeSpecificity: true, includeVendorPrefixes: true, onError: () => { }, onWarning: () => { }, maxDepth: 100, maxNodes: 100000, enableNesting: true, enableCustomProperties: true, enableLogicalProperties: true, enableContainerQueries: true, enableLayerQueries: true, enableSupportsQueries: true,
44
+ // middleware — undefined by default (fast path skips them)
45
+ onRule: undefined, onAtRule: undefined, onDeclaration: undefined, onComment: undefined, onKeyframe: undefined }, options);
46
+ }
47
+ // ── Public API ────────────────────────────────────────────────────────────
48
+ parse(css) {
49
+ const t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
50
+ this.reset(css);
51
+ const sheet = this.parseStylesheet();
52
+ this.stats.parseTime = (typeof performance !== 'undefined' ? performance.now() : Date.now()) - t0;
53
+ return sheet;
54
+ }
55
+ getErrors() { return [...this.errors]; }
56
+ getWarnings() { return [...this.warnings]; }
57
+ getStats() { return Object.assign({}, this.stats); }
58
+ toLegacyFormat(stylesheet) {
59
+ return stylesheet.children
60
+ .map(c => this.toLegacyNode(c))
61
+ .filter(Boolean);
62
+ }
63
+ // ── Reset ─────────────────────────────────────────────────────────────────
64
+ reset(css) {
65
+ this.input = css;
66
+ this.pos = 0;
67
+ this.length = css.length;
68
+ this.line = 1;
69
+ this.col = 1;
70
+ this.errors = [];
71
+ this.warnings = [];
72
+ this.stats = CssParser.emptyStats();
73
+ }
74
+ static emptyStats() {
75
+ return {
76
+ totalNodes: 0, totalRules: 0, totalDeclarations: 0, totalAtRules: 0,
77
+ totalComments: 0, totalSelectors: 0, totalValues: 0,
78
+ parseTime: 0, memoryUsage: 0, errors: 0, warnings: 0,
79
+ };
80
+ }
81
+ // ── Stylesheet ────────────────────────────────────────────────────────────
82
+ parseStylesheet() {
83
+ const locStart = this.locPos();
84
+ const ss = {
85
+ type: 'stylesheet', source: this.input, children: [],
86
+ charset: undefined, imports: [], namespaces: [], mediaQueries: [],
87
+ keyframes: [], fontFaces: [], layers: [], containers: [],
88
+ supports: [], documents: [], pages: [], counterStyles: [],
89
+ fontFeatureValues: [], viewports: [], charsets: [],
90
+ };
91
+ while (this.pos < this.length) {
92
+ this.skipWS();
93
+ if (this.pos >= this.length)
94
+ break;
95
+ const node = this.parseTopNode();
96
+ if (node) {
97
+ ss.children.push(node);
98
+ this.categorize(ss, node);
99
+ this.stats.totalNodes++;
100
+ }
101
+ }
102
+ if (this.options.includeSourceMaps) {
103
+ ss.loc = { start: locStart, end: this.locPos(), source: this.input };
104
+ }
105
+ return ss;
106
+ }
107
+ // ── Top-level node dispatch ───────────────────────────────────────────────
108
+ parseTopNode() {
109
+ const c = this.peek();
110
+ if (c === CC_SLASH && this.peek(1) === CC_STAR) {
111
+ const comment = this.parseComment();
112
+ return this.options.includeComments ? comment : null;
113
+ }
114
+ if (c === CC_AT)
115
+ return this.parseAtRule();
116
+ // Skip stray closing braces that can appear in malformed CSS
117
+ if (c === CC_RBRACE) {
118
+ this.advance();
119
+ return null;
120
+ }
121
+ return this.parseRule();
122
+ }
123
+ // ── Block-level node dispatch ─────────────────────────────────────────────
124
+ parseBlockNode(mode) {
125
+ this.skipWS();
126
+ if (this.pos >= this.length || this.peek() === CC_RBRACE)
127
+ return null;
128
+ const c = this.peek();
129
+ if (c === CC_SLASH && this.peek(1) === CC_STAR) {
130
+ const comment = this.parseComment();
131
+ return this.options.includeComments ? comment : null;
132
+ }
133
+ if (c === CC_AT)
134
+ return this.parseAtRule();
135
+ switch (mode) {
136
+ case 'keyframes': return this.parseKeyframeStop();
137
+ case 'declarations': return this.parseDeclaration();
138
+ case 'mixed':
139
+ case 'stylesheet':
140
+ if (c === CC_RBRACE)
141
+ return null;
142
+ return this.parseRule();
143
+ case 'rule':
144
+ default:
145
+ // Unambiguous nesting-selector starters
146
+ if (this.isNestingStart(c))
147
+ return this.parseRule();
148
+ // Lookahead: first unescaped { at depth 0 → rule, ; or } → declaration
149
+ if (this.lookaheadIsRule())
150
+ return this.parseRule();
151
+ // console.log('parse block', c, mode);
152
+ return this.parseDeclaration();
153
+ }
154
+ }
155
+ // ── At-rule ───────────────────────────────────────────────────────────────
156
+ parseAtRule() {
157
+ if (this.peek() !== CC_AT)
158
+ return null;
159
+ const locStart = this.locPos();
160
+ this.advance(); // '@'
161
+ const name = this.readIdent();
162
+ if (!name) {
163
+ this.recoverPast(CC_SEMI, CC_RBRACE);
164
+ return null;
165
+ }
166
+ this.skipWS();
167
+ const preludeText = this.readPrelude();
168
+ this.skipWS();
169
+ const baseName = name.replace(/^-(webkit|moz|ms|o)-/, '');
170
+ const ar = {
171
+ type: 'atrule',
172
+ name,
173
+ preludeText,
174
+ prelude: this.options.parseAtrulePrelude ? this.tokenizeValue(preludeText) : [],
175
+ };
176
+ if (this.options.includeVendorPrefixes) {
177
+ const vp = name.match(/^-(webkit|moz|ms|o)-/);
178
+ if (vp)
179
+ ar.vendorPrefix = vp[0];
180
+ }
181
+ if (this.peek() === CC_LBRACE) {
182
+ const mode = this.modeForAtRule(baseName);
183
+ const blockStart = this.locPos();
184
+ const children = this.parseBlockChildren(mode);
185
+ const blockEnd = this.locPos();
186
+ ar.block = Object.assign({ type: 'block', children: children }, (this.options.includeSourceMaps ? { loc: { start: blockStart, end: blockEnd } } : {}));
187
+ // Populate keyframes shortcut
188
+ if (baseName === 'keyframes') {
189
+ ar.keyframes =
190
+ children.filter(n => n.type === 'keyframe');
191
+ }
192
+ }
193
+ else if (this.peek() === CC_SEMI) {
194
+ this.advance();
195
+ }
196
+ this.stats.totalAtRules++;
197
+ if (this.options.includeSourceMaps) {
198
+ ar.loc = {
199
+ start: locStart,
200
+ end: this.locPos(),
201
+ source: this.input,
202
+ };
203
+ }
204
+ if (this.options.onAtRule) {
205
+ const result = this.options.onAtRule(ar);
206
+ if (result === null)
207
+ return null;
208
+ if (result)
209
+ return result;
210
+ }
211
+ return ar;
212
+ }
213
+ modeForAtRule(baseName) {
214
+ // AWC encodes comments as @comment-XXXXXXXX { --rule-...: "..."; }
215
+ // which contain only declarations — must NOT use mixed/rule mode or
216
+ // readUntilLBrace() will consume past the closing } and corrupt state.
217
+ if (baseName.startsWith('comment'))
218
+ return 'declarations';
219
+ switch (baseName) {
220
+ case 'keyframes': return 'keyframes';
221
+ case 'font-face':
222
+ case 'page':
223
+ case 'counter-style':
224
+ case 'viewport':
225
+ case 'theme':
226
+ case 'utility': return 'declarations';
227
+ case 'media':
228
+ case 'supports':
229
+ case 'container':
230
+ case 'layer':
231
+ case 'document':
232
+ default: return 'mixed';
233
+ }
234
+ }
235
+ // ── Regular rule ──────────────────────────────────────────────────────────
236
+ parseRule() {
237
+ const locStart = this.locPos();
238
+ const rawSelector = this.readUntilLBrace().trim();
239
+ if (!rawSelector || this.peek() !== CC_LBRACE) {
240
+ // Malformed — skip to closing brace
241
+ if (this.peek() === CC_LBRACE) {
242
+ this.skipBalancedBraces();
243
+ }
244
+ return null;
245
+ }
246
+ const mode = this.options.enableNesting ? 'rule' : 'declarations';
247
+ const children = this.parseBlockChildren(mode);
248
+ const declarations = [];
249
+ const nested = [];
250
+ for (const child of children) {
251
+ const t = child.type;
252
+ if (t === 'declaration')
253
+ declarations.push(child);
254
+ else if (t === 'rule')
255
+ nested.push(child);
256
+ else if (t === 'atrule')
257
+ nested.push(child);
258
+ }
259
+ const selectors = this.parseSelectorList(rawSelector);
260
+ this.stats.totalRules++;
261
+ this.stats.totalSelectors += selectors.length;
262
+ const rule = {
263
+ type: 'rule',
264
+ rawSelector,
265
+ selectors,
266
+ declarations,
267
+ };
268
+ if (nested.length > 0)
269
+ rule.children = nested;
270
+ if (this.options.includeSpecificity) {
271
+ rule.specificity = this.calcSpecificity(rawSelector);
272
+ }
273
+ if (this.options.includeSourceMaps) {
274
+ rule.loc = {
275
+ start: locStart,
276
+ end: this.locPos(),
277
+ source: this.input,
278
+ };
279
+ }
280
+ if (this.options.onRule) {
281
+ const result = this.options.onRule(rule);
282
+ if (result === null)
283
+ return null;
284
+ if (result)
285
+ return result;
286
+ }
287
+ return rule;
288
+ }
289
+ // ── Keyframe stop (from / to / <percentage>) ──────────────────────────────
290
+ parseKeyframeStop() {
291
+ const locStart = this.locPos();
292
+ const selector = this.readUntilLBrace().trim();
293
+ if (!selector || this.peek() !== CC_LBRACE)
294
+ return null;
295
+ const children = this.parseBlockChildren('declarations');
296
+ const declarations = children
297
+ .filter(n => n.type === 'declaration');
298
+ const kf = Object.assign({ type: 'keyframe', selector,
299
+ declarations }, (this.options.includeSourceMaps
300
+ ? { loc: { start: locStart, end: this.locPos() } }
301
+ : {}));
302
+ if (this.options.onKeyframe) {
303
+ const result = this.options.onKeyframe(kf);
304
+ if (result === null)
305
+ return null;
306
+ if (result)
307
+ return result;
308
+ }
309
+ return kf;
310
+ }
311
+ // ── Block (consumes { … }) ────────────────────────────────────────────────
312
+ parseBlockChildren(mode) {
313
+ if (this.peek() !== CC_LBRACE)
314
+ return [];
315
+ this.advance(); // '{'
316
+ const children = [];
317
+ while (this.pos < this.length) {
318
+ this.skipWS();
319
+ if (this.pos >= this.length || this.peek() === CC_RBRACE)
320
+ break;
321
+ const prevPos = this.pos;
322
+ const node = this.parseBlockNode(mode);
323
+ // Guard against infinite loop: if nothing was consumed, force-advance
324
+ if (this.pos === prevPos) {
325
+ this.advance();
326
+ continue;
327
+ }
328
+ if (node) {
329
+ children.push(node);
330
+ this.stats.totalNodes++;
331
+ }
332
+ }
333
+ if (this.pos < this.length && this.peek() === CC_RBRACE)
334
+ this.advance(); // '}'
335
+ return children;
336
+ }
337
+ // ── Declaration ───────────────────────────────────────────────────────────
338
+ parseDeclaration() {
339
+ const locStart = this.locPos();
340
+ // Property name (supports --custom-props and -vendor-prefixed)
341
+ const property = this.readIdent();
342
+ if (!property) {
343
+ this.recoverTo(CC_SEMI, CC_RBRACE);
344
+ return null;
345
+ }
346
+ this.skipWS();
347
+ if (this.peek() !== CC_COLON) {
348
+ this.recoverTo(CC_SEMI, CC_RBRACE);
349
+ return null;
350
+ }
351
+ this.advance(); // ':'
352
+ this.skipWS();
353
+ const rawFull = this.readRawValue();
354
+ // Strip !important
355
+ let rawValue = rawFull;
356
+ let important = false;
357
+ const impMatch = rawFull.match(/\s*!important\s*$/i);
358
+ if (impMatch) {
359
+ important = true;
360
+ rawValue = rawFull.slice(0, rawFull.length - impMatch[0].length).trimEnd();
361
+ }
362
+ this.skipWS();
363
+ if (this.pos < this.length && this.peek() === CC_SEMI)
364
+ this.advance();
365
+ this.stats.totalDeclarations++;
366
+ const decl = {
367
+ type: 'declaration',
368
+ property,
369
+ rawValue,
370
+ value: this.options.parseValue ? this.tokenizeValue(rawValue) : [],
371
+ important,
372
+ };
373
+ if (this.options.enableCustomProperties && property.startsWith('--')) {
374
+ decl.customProperty = true;
375
+ }
376
+ if (this.options.includeVendorPrefixes) {
377
+ const vp = property.match(/^-(webkit|moz|ms|o)-/);
378
+ if (vp)
379
+ decl.vendorPrefix = vp[0];
380
+ }
381
+ if (this.options.includeSourceMaps) {
382
+ decl.loc = {
383
+ start: locStart,
384
+ end: this.locPos(),
385
+ source: this.input,
386
+ };
387
+ }
388
+ if (this.options.onDeclaration) {
389
+ const result = this.options.onDeclaration(decl);
390
+ if (result === null)
391
+ return null;
392
+ if (result)
393
+ return result;
394
+ }
395
+ return decl;
396
+ }
397
+ // ── Comment ───────────────────────────────────────────────────────────────
398
+ parseComment() {
399
+ const locStart = this.locPos();
400
+ this.advance(); // '/'
401
+ this.advance(); // '*'
402
+ const start = this.pos;
403
+ while (this.pos < this.length - 1) {
404
+ if (this.peek() === CC_STAR && this.peek(1) === CC_SLASH) {
405
+ const value = this.input.slice(start, this.pos);
406
+ this.advance();
407
+ this.advance(); // '*/'
408
+ this.stats.totalComments++;
409
+ const c = Object.assign({ type: 'comment', value, style: value.includes('\n') ? 'multi-line' : 'single-line' }, (this.options.includeSourceMaps
410
+ ? { loc: { start: locStart, end: this.locPos() } }
411
+ : {}));
412
+ if (this.options.onComment) {
413
+ const result = this.options.onComment(c);
414
+ if (result === null)
415
+ return null;
416
+ if (result)
417
+ return result;
418
+ }
419
+ return c;
420
+ }
421
+ this.advance();
422
+ }
423
+ // Unterminated comment
424
+ const value = this.input.slice(start);
425
+ this.pos = this.length;
426
+ this.stats.totalComments++;
427
+ const c = { type: 'comment', value, style: 'multi-line' };
428
+ if (this.options.onComment) {
429
+ const result = this.options.onComment(c);
430
+ if (result === null)
431
+ return null;
432
+ if (result)
433
+ return result;
434
+ }
435
+ return c;
436
+ }
437
+ // ── Selectors ─────────────────────────────────────────────────────────────
438
+ /**
439
+ * Splits a raw selector string on commas (respecting parentheses depth)
440
+ * and returns one CssSelector per part.
441
+ */
442
+ parseSelectorList(raw) {
443
+ const parts = [];
444
+ let depth = 0, start = 0;
445
+ for (let i = 0; i < raw.length; i++) {
446
+ const c = raw.charCodeAt(i);
447
+ if (c === CC_LPAREN || c === CC_LBRACK)
448
+ depth++;
449
+ else if (c === CC_RPAREN || c === CC_RBRACK)
450
+ depth--;
451
+ else if (c === CC_COMMA && depth === 0) {
452
+ parts.push(raw.slice(start, i).trim());
453
+ start = i + 1;
454
+ }
455
+ }
456
+ parts.push(raw.slice(start).trim());
457
+ return parts
458
+ .filter(p => p.length > 0)
459
+ .map(p => ({ type: 'selector', value: p }));
460
+ }
461
+ /**
462
+ * Simple specificity scorer — counts IDs, classes/attributes/pseudos, elements.
463
+ */
464
+ calcSpecificity(sel) {
465
+ let ids = 0, classes = 0, elements = 0;
466
+ let i = 0;
467
+ while (i < sel.length) {
468
+ const c = sel.charCodeAt(i);
469
+ if (c === CC_HASH) {
470
+ ids++;
471
+ i++;
472
+ while (i < sel.length && isNameChar(sel.charCodeAt(i)))
473
+ i++;
474
+ }
475
+ else if (c === CC_DOT) {
476
+ classes++;
477
+ i++;
478
+ while (i < sel.length && isNameChar(sel.charCodeAt(i)))
479
+ i++;
480
+ }
481
+ else if (c === CC_LBRACK) {
482
+ classes++;
483
+ while (i < sel.length && sel.charCodeAt(i) !== CC_RBRACK)
484
+ i++;
485
+ i++;
486
+ }
487
+ else if (c === CC_COLON) {
488
+ if (sel.charCodeAt(i + 1) === CC_COLON) {
489
+ elements++;
490
+ i += 2;
491
+ }
492
+ else {
493
+ // :not(), :is(), :has() — don't double-count the wrapper
494
+ classes++;
495
+ i++;
496
+ }
497
+ while (i < sel.length && isNameChar(sel.charCodeAt(i)))
498
+ i++;
499
+ // skip argument parens
500
+ if (i < sel.length && sel.charCodeAt(i) === CC_LPAREN) {
501
+ let d = 1;
502
+ i++;
503
+ while (i < sel.length && d > 0) {
504
+ if (sel.charCodeAt(i) === CC_LPAREN)
505
+ d++;
506
+ else if (sel.charCodeAt(i) === CC_RPAREN)
507
+ d--;
508
+ i++;
509
+ }
510
+ }
511
+ }
512
+ else if (isAlpha(c) || c === CC_UNDER) {
513
+ elements++;
514
+ while (i < sel.length && isNameChar(sel.charCodeAt(i)))
515
+ i++;
516
+ }
517
+ else {
518
+ i++;
519
+ }
520
+ }
521
+ return { ids, classes, elements, total: ids * 100 + classes * 10 + elements };
522
+ }
523
+ // ── Value tokenizer ───────────────────────────────────────────────────────
524
+ /**
525
+ * Tokenises a raw CSS value string into a flat array of CssValue tokens.
526
+ * Handles: strings, colors (#hex), numbers/dimensions/percentages,
527
+ * functions (recursive), identifiers, operators, commas.
528
+ */
529
+ tokenizeValue(raw) {
530
+ const tokens = [];
531
+ let i = 0;
532
+ const len = raw.length;
533
+ while (i < len) {
534
+ const c = raw.charCodeAt(i);
535
+ // Whitespace — skip (no whitespace tokens)
536
+ if (isWS(c)) {
537
+ i++;
538
+ continue;
539
+ }
540
+ // Quoted string
541
+ if (c === CC_DQUOTE || c === CC_SQUOTE) {
542
+ const q = c;
543
+ i++;
544
+ const s = i;
545
+ while (i < len && raw.charCodeAt(i) !== q) {
546
+ if (raw.charCodeAt(i) === CC_BSLASH)
547
+ i++;
548
+ i++;
549
+ }
550
+ tokens.push({ type: 'string', value: raw.slice(s, i) });
551
+ i++; // closing quote
552
+ continue;
553
+ }
554
+ // Hex color (#rrggbb / #rgb / #rrggbbaa / #rgba)
555
+ if (c === CC_HASH) {
556
+ const s = i++;
557
+ while (i < len && isHex(raw.charCodeAt(i)))
558
+ i++;
559
+ tokens.push({ type: 'color', value: raw.slice(s, i) });
560
+ continue;
561
+ }
562
+ // Number / dimension / percentage
563
+ // Handles: 10, 1.5, .5, 1e3, +10px, -2em, 50%
564
+ const isNumStart = isDigit(c)
565
+ || (c === CC_DOT && isDigit(raw.charCodeAt(i + 1)))
566
+ || ((c === CC_PLUS || c === CC_MINUS)
567
+ && (isDigit(raw.charCodeAt(i + 1))
568
+ || (raw.charCodeAt(i + 1) === CC_DOT && isDigit(raw.charCodeAt(i + 2)))));
569
+ if (isNumStart) {
570
+ const s = i;
571
+ if (c === CC_PLUS || c === CC_MINUS)
572
+ i++;
573
+ while (i < len && isDigit(raw.charCodeAt(i)))
574
+ i++;
575
+ if (i < len && raw.charCodeAt(i) === CC_DOT) {
576
+ i++;
577
+ while (i < len && isDigit(raw.charCodeAt(i)))
578
+ i++;
579
+ }
580
+ // Exponent
581
+ if (i < len && (raw.charCodeAt(i) === 101 || raw.charCodeAt(i) === 69)) {
582
+ i++;
583
+ if (i < len && (raw.charCodeAt(i) === CC_PLUS || raw.charCodeAt(i) === CC_MINUS))
584
+ i++;
585
+ while (i < len && isDigit(raw.charCodeAt(i)))
586
+ i++;
587
+ }
588
+ const num = parseFloat(raw.slice(s, i));
589
+ // Unit / percentage
590
+ const us = i;
591
+ while (i < len && (isAlpha(raw.charCodeAt(i)) || raw.charCodeAt(i) === CC_UNDER))
592
+ i++;
593
+ if (i < len && raw[i] === '%')
594
+ i++;
595
+ const unit = raw.slice(us, i);
596
+ if (unit === '%')
597
+ tokens.push({ type: 'percentage', value: num });
598
+ else if (unit)
599
+ tokens.push({ type: 'dimension', value: num, unit });
600
+ else
601
+ tokens.push({ type: 'number', value: num });
602
+ continue;
603
+ }
604
+ // Identifier or function call
605
+ if (isNameStart(c)) {
606
+ const s = i;
607
+ while (i < len && isNameChar(raw.charCodeAt(i)))
608
+ i++;
609
+ const name = raw.slice(s, i);
610
+ if (i < len && raw.charCodeAt(i) === CC_LPAREN) {
611
+ i++; // '('
612
+ const as_ = i;
613
+ let depth = 1;
614
+ while (i < len && depth > 0) {
615
+ const ch = raw.charCodeAt(i);
616
+ if (ch === CC_LPAREN)
617
+ depth++;
618
+ else if (ch === CC_RPAREN)
619
+ depth--;
620
+ i++;
621
+ }
622
+ const argStr = raw.slice(as_, i - 1);
623
+ const args = name.toLowerCase() === 'url'
624
+ ? [{ type: 'string', value: argStr.replace(/^['"]|['"]$/g, '') }]
625
+ : this.tokenizeValue(argStr);
626
+ tokens.push({ type: 'function', name, value: `${name}(${argStr})`, args });
627
+ }
628
+ else {
629
+ tokens.push({ type: 'identifier', value: name });
630
+ }
631
+ continue;
632
+ }
633
+ // Comma
634
+ if (c === CC_COMMA) {
635
+ tokens.push({ type: 'comma', value: ',' });
636
+ i++;
637
+ continue;
638
+ }
639
+ // Operator or any other character
640
+ tokens.push({ type: 'operator', value: raw[i] });
641
+ i++;
642
+ }
643
+ this.stats.totalValues += tokens.length;
644
+ return tokens;
645
+ }
646
+ // ── Scanner primitives ────────────────────────────────────────────────────
647
+ peek(offset = 0) {
648
+ return this.input.charCodeAt(this.pos + offset);
649
+ }
650
+ advance() {
651
+ if (this.pos < this.length) {
652
+ if (this.input.charCodeAt(this.pos) === CC_LF) {
653
+ this.line++;
654
+ this.col = 1;
655
+ }
656
+ else
657
+ this.col++;
658
+ this.pos++;
659
+ }
660
+ }
661
+ skipWS() {
662
+ while (this.pos < this.length && isWS(this.peek()))
663
+ this.advance();
664
+ }
665
+ /**
666
+ * Read a CSS identifier (supports `--custom-props` and `-vendor-prefix`).
667
+ * Returns empty string if the current position isn't the start of an ident.
668
+ */
669
+ readIdent() {
670
+ if (this.pos >= this.length)
671
+ return '';
672
+ const c = this.peek();
673
+ // Allow backslash-escape as a valid ident start (e.g. \/ in custom props)
674
+ if (!isNameStart(c) && c !== CC_BSLASH)
675
+ return '';
676
+ const start = this.pos;
677
+ while (this.pos < this.length) {
678
+ const ch = this.peek();
679
+ if (ch === CC_BSLASH) {
680
+ // CSS escape sequence: consume backslash + following char/codepoint
681
+ // Preserve raw text (including the backslash) so the generator
682
+ // can emit valid CSS unchanged.
683
+ this.advance(); // consume '\'
684
+ if (this.pos >= this.length)
685
+ break;
686
+ const next = this.peek();
687
+ if (isHex(next)) {
688
+ // 1–6 hex digits
689
+ let hexLen = 0;
690
+ while (this.pos < this.length && isHex(this.peek()) && hexLen < 6) {
691
+ this.advance();
692
+ hexLen++;
693
+ }
694
+ // optional single whitespace after hex escape
695
+ if (this.pos < this.length && isWS(this.peek()))
696
+ this.advance();
697
+ }
698
+ else if (next === CC_LF || next === CC_CR || next === CC_FF) {
699
+ // newline inside escape — skip
700
+ this.advance();
701
+ }
702
+ else {
703
+ // e.g. \/ — consume the escaped character
704
+ this.advance();
705
+ }
706
+ }
707
+ else if (isNameChar(ch)) {
708
+ this.advance();
709
+ }
710
+ else {
711
+ break;
712
+ }
713
+ }
714
+ return this.input.slice(start, this.pos);
715
+ }
716
+ /**
717
+ * Read at-rule prelude: raw text from current position up to (but not
718
+ * including) the next `{` or `;` at depth 0.
719
+ * Parentheses, brackets, strings and comments are respected.
720
+ */
721
+ readPrelude() {
722
+ const start = this.pos;
723
+ let depth = 0;
724
+ while (this.pos < this.length) {
725
+ const c = this.peek();
726
+ if (c === CC_DQUOTE || c === CC_SQUOTE) {
727
+ this.skipString(c);
728
+ continue;
729
+ }
730
+ if (c === CC_SLASH && this.peek(1) === CC_STAR) {
731
+ this.skipMLComment();
732
+ continue;
733
+ }
734
+ if (c === CC_LPAREN || c === CC_LBRACK) {
735
+ depth++;
736
+ this.advance();
737
+ continue;
738
+ }
739
+ if (c === CC_RPAREN || c === CC_RBRACK) {
740
+ depth--;
741
+ this.advance();
742
+ continue;
743
+ }
744
+ if (depth === 0 && (c === CC_LBRACE || c === CC_SEMI))
745
+ break;
746
+ this.advance();
747
+ }
748
+ return this.input.slice(start, this.pos).trim();
749
+ }
750
+ /**
751
+ * Read a declaration value: raw text up to `;` or `}` at depth 0.
752
+ */
753
+ readRawValue() {
754
+ const start = this.pos;
755
+ let depth = 0;
756
+ while (this.pos < this.length) {
757
+ const c = this.peek();
758
+ // Backslash escape: consume '\' + next char as a unit.
759
+ // This prevents '\"' from being misread as a string delimiter,
760
+ // '\;' from prematurely terminating the value, and '\(' from
761
+ // incorrectly incrementing paren depth.
762
+ if (c === CC_BSLASH) {
763
+ this.advance(); // consume '\'
764
+ if (this.pos < this.length)
765
+ this.advance(); // consume escaped char
766
+ continue;
767
+ }
768
+ if (c === CC_DQUOTE || c === CC_SQUOTE) {
769
+ this.skipString(c);
770
+ continue;
771
+ }
772
+ if (c === CC_SLASH && this.peek(1) === CC_STAR) {
773
+ this.skipMLComment();
774
+ continue;
775
+ }
776
+ if (c === CC_LPAREN || c === CC_LBRACK) {
777
+ depth++;
778
+ this.advance();
779
+ continue;
780
+ }
781
+ if (c === CC_RPAREN || c === CC_RBRACK) {
782
+ depth--;
783
+ this.advance();
784
+ continue;
785
+ }
786
+ if (depth === 0 && (c === CC_SEMI || c === CC_RBRACE))
787
+ break;
788
+ this.advance();
789
+ }
790
+ return this.input.slice(start, this.pos).trim();
791
+ }
792
+ /**
793
+ * Read a selector (rule prelude): raw text up to the first `{` at depth 0.
794
+ * Parentheses, brackets, strings and comments are respected.
795
+ */
796
+ readUntilLBrace() {
797
+ const start = this.pos;
798
+ let depth = 0;
799
+ while (this.pos < this.length) {
800
+ const c = this.peek();
801
+ // Backslash escape: consume '\' + next char as a unit.
802
+ // Prevents '\{' from falsely terminating the selector,
803
+ // and '\"' from being misread as a string delimiter.
804
+ if (c === CC_BSLASH) {
805
+ this.advance(); // consume '\'
806
+ if (this.pos < this.length)
807
+ this.advance(); // consume escaped char
808
+ continue;
809
+ }
810
+ if (c === CC_DQUOTE || c === CC_SQUOTE) {
811
+ this.skipString(c);
812
+ continue;
813
+ }
814
+ if (c === CC_SLASH && this.peek(1) === CC_STAR) {
815
+ this.skipMLComment();
816
+ continue;
817
+ }
818
+ if (c === CC_LPAREN || c === CC_LBRACK) {
819
+ depth++;
820
+ this.advance();
821
+ continue;
822
+ }
823
+ if (c === CC_RPAREN || c === CC_RBRACK) {
824
+ depth--;
825
+ this.advance();
826
+ continue;
827
+ }
828
+ if (depth === 0 && c === CC_LBRACE)
829
+ break;
830
+ this.advance();
831
+ }
832
+ return this.input.slice(start, this.pos);
833
+ }
834
+ /** Skip a quoted string starting at the current position (quote char given). */
835
+ skipString(quote) {
836
+ this.advance(); // opening quote
837
+ while (this.pos < this.length) {
838
+ const c = this.peek();
839
+ if (c === CC_BSLASH) {
840
+ this.advance();
841
+ this.advance();
842
+ continue;
843
+ }
844
+ if (c === quote) {
845
+ this.advance();
846
+ return;
847
+ }
848
+ if (c === CC_LF)
849
+ return; // unterminated → stop
850
+ this.advance();
851
+ }
852
+ }
853
+ /** Skip a block comment (slash-star ... star-slash) starting at current position. */
854
+ skipMLComment() {
855
+ this.advance();
856
+ this.advance(); // '/' '*'
857
+ while (this.pos < this.length - 1) {
858
+ if (this.peek() === CC_STAR && this.peek(1) === CC_SLASH) {
859
+ this.advance();
860
+ this.advance();
861
+ return;
862
+ }
863
+ this.advance();
864
+ }
865
+ this.pos = this.length;
866
+ }
867
+ /** Skip a balanced `{ … }` block (including the opening brace). */
868
+ skipBalancedBraces() {
869
+ if (this.peek() !== CC_LBRACE)
870
+ return;
871
+ let depth = 0;
872
+ while (this.pos < this.length) {
873
+ const c = this.peek();
874
+ if (c === CC_LBRACE)
875
+ depth++;
876
+ else if (c === CC_RBRACE) {
877
+ depth--;
878
+ if (depth === 0) {
879
+ this.advance();
880
+ return;
881
+ }
882
+ }
883
+ this.advance();
884
+ }
885
+ }
886
+ /**
887
+ * Lookahead: scan forward from current position and return true if
888
+ * an unescaped `{` at depth 0 is found before any `;` or `}`.
889
+ * Used in `rule` block mode to distinguish declarations from nested rules.
890
+ */
891
+ lookaheadIsRule() {
892
+ let i = this.pos, depth = 0;
893
+ while (i < this.length) {
894
+ const c = this.input.charCodeAt(i);
895
+ if (c === CC_DQUOTE || c === CC_SQUOTE) {
896
+ const q = c;
897
+ i++;
898
+ while (i < this.length && this.input.charCodeAt(i) !== q) {
899
+ if (this.input.charCodeAt(i) === CC_BSLASH)
900
+ i++;
901
+ i++;
902
+ }
903
+ i++;
904
+ continue;
905
+ }
906
+ if (c === CC_LPAREN || c === CC_LBRACK) {
907
+ depth++;
908
+ i++;
909
+ continue;
910
+ }
911
+ if (c === CC_RPAREN || c === CC_RBRACK) {
912
+ depth--;
913
+ i++;
914
+ continue;
915
+ }
916
+ if (depth === 0) {
917
+ if (c === CC_LBRACE)
918
+ return true;
919
+ if (c === CC_SEMI || c === CC_RBRACE)
920
+ return false;
921
+ }
922
+ i++;
923
+ }
924
+ return false;
925
+ }
926
+ /**
927
+ * Characters that unambiguously start a CSS nesting selector
928
+ * (can never be the start of a property name).
929
+ */
930
+ isNestingStart(c) {
931
+ return c === CC_AMP // & nesting selector
932
+ || c === CC_DOT // . class
933
+ || c === CC_HASH // # id
934
+ || c === CC_LBRACK // [ attribute
935
+ || c === 42 // * universal
936
+ || c === CC_GT // > child combinator
937
+ || c === CC_PLUS // + adjacent sibling
938
+ || c === CC_TILDE // ~ general sibling
939
+ || c === CC_COLON; // : pseudo-class / ::pseudo-element
940
+ }
941
+ /** Advance past chars until one of the given charcodes (exclusive). */
942
+ recoverTo(...stops) {
943
+ while (this.pos < this.length && !stops.includes(this.peek()))
944
+ this.advance();
945
+ }
946
+ /** Advance past chars until one of the given charcodes, then advance one more. */
947
+ recoverPast(...stops) {
948
+ this.recoverTo(...stops);
949
+ if (this.pos < this.length)
950
+ this.advance();
951
+ }
952
+ // ── Location helpers ──────────────────────────────────────────────────────
953
+ locPos() {
954
+ return { line: this.line, column: this.col, offset: this.pos };
955
+ }
956
+ // ── Stylesheet categorizer ────────────────────────────────────────────────
957
+ categorize(ss, node) {
958
+ var _a, _b;
959
+ if (node.type !== 'atrule')
960
+ return;
961
+ const ar = node;
962
+ const base = ar.name.replace(/^-(webkit|moz|ms|o)-/, '');
963
+ switch (base) {
964
+ case 'import':
965
+ ss.imports.push(ar);
966
+ break;
967
+ case 'media':
968
+ ss.mediaQueries.push({
969
+ type: 'media-query',
970
+ media: (_a = ar.preludeText) !== null && _a !== void 0 ? _a : '',
971
+ features: [],
972
+ loc: ar.loc,
973
+ });
974
+ break;
975
+ case 'namespace':
976
+ ss.namespaces.push(ar);
977
+ break;
978
+ case 'keyframes':
979
+ ss.keyframes.push(ar);
980
+ break;
981
+ case 'font-face':
982
+ ss.fontFaces.push(ar);
983
+ break;
984
+ case 'layer': {
985
+ const layerRule = ar;
986
+ // preludeText holds the layer name (e.g. "atomic" for "@layer atomic { … }")
987
+ if (ar.preludeText)
988
+ layerRule.layerName = ar.preludeText.trim();
989
+ ss.layers.push(layerRule);
990
+ break;
991
+ }
992
+ case 'container': {
993
+ const containerRule = ar;
994
+ if (ar.preludeText) {
995
+ // "@container main (width > 600px)" → name is the first token
996
+ const parts = ar.preludeText.trim().match(/^([\w-]+)?\s*(.*)/);
997
+ if (parts === null || parts === void 0 ? void 0 : parts[1])
998
+ containerRule.containerName = parts[1];
999
+ if (parts === null || parts === void 0 ? void 0 : parts[2])
1000
+ containerRule.containerQuery = parts[2].trim();
1001
+ }
1002
+ ss.containers.push(containerRule);
1003
+ break;
1004
+ }
1005
+ case 'supports':
1006
+ ss.supports.push(ar);
1007
+ break;
1008
+ case 'document':
1009
+ ss.documents.push(ar);
1010
+ break;
1011
+ case 'page':
1012
+ ss.pages.push(ar);
1013
+ break;
1014
+ case 'counter-style':
1015
+ ss.counterStyles.push(ar);
1016
+ break;
1017
+ case 'font-feature-values':
1018
+ ss.fontFeatureValues.push(ar);
1019
+ break;
1020
+ case 'viewport':
1021
+ ss.viewports.push(ar);
1022
+ break;
1023
+ case 'charset':
1024
+ ss.charsets.push(ar);
1025
+ ss.charset = (_b = ar.preludeText) === null || _b === void 0 ? void 0 : _b.replace(/^['"]|['"]$/g, '');
1026
+ break;
1027
+ }
1028
+ }
1029
+ // ── Legacy format ─────────────────────────────────────────────────────────
1030
+ toLegacyNode(node) {
1031
+ var _a, _b, _c, _d, _e, _f, _g;
1032
+ switch (node.type) {
1033
+ case 'rule': {
1034
+ const r = node;
1035
+ const name = (_a = r.rawSelector) !== null && _a !== void 0 ? _a : r.selectors.map(s => s.value).join(', ');
1036
+ return {
1037
+ kind: 'rule', name,
1038
+ value: r.declarations
1039
+ .map(d => { var _a; return `${d.property}: ${(_a = d.rawValue) !== null && _a !== void 0 ? _a : d.value.map(v => String(v.value)).join(' ')}${d.important ? ' !important' : ''}`; })
1040
+ .join('; '),
1041
+ important: false,
1042
+ children: r.declarations.map(d => this.toLegacyNode(d)).filter(Boolean),
1043
+ loc: r.loc, node: 'rule', cssNode: {}, parents: [],
1044
+ selectors: r.selectors.map(s => ({
1045
+ kind: 'rule', name: s.value, value: s.value,
1046
+ loc: s.loc, node: 'selector', cssNode: {}, parents: [],
1047
+ })),
1048
+ };
1049
+ }
1050
+ case 'atrule': {
1051
+ const ar = node;
1052
+ return {
1053
+ kind: 'atrule', name: ar.name,
1054
+ value: (_d = (_b = ar.preludeText) !== null && _b !== void 0 ? _b : (_c = ar.prelude) === null || _c === void 0 ? void 0 : _c.map(v => String(v.value)).join(' ')) !== null && _d !== void 0 ? _d : '',
1055
+ important: false,
1056
+ children: ((_f = (_e = ar.block) === null || _e === void 0 ? void 0 : _e.children) !== null && _f !== void 0 ? _f : [])
1057
+ .map(c => this.toLegacyNode(c))
1058
+ .filter(Boolean),
1059
+ loc: ar.loc, node: 'atrule', cssNode: {}, parents: [],
1060
+ };
1061
+ }
1062
+ case 'declaration': {
1063
+ const d = node;
1064
+ return {
1065
+ kind: 'decl', name: d.property,
1066
+ value: (_g = d.rawValue) !== null && _g !== void 0 ? _g : d.value.map(v => String(v.value)).join(' '),
1067
+ important: d.important, children: [],
1068
+ loc: d.loc, node: 'declaration', cssNode: {}, parents: [],
1069
+ };
1070
+ }
1071
+ case 'comment': {
1072
+ const c = node;
1073
+ return {
1074
+ kind: 'comment', name: undefined, value: c.value,
1075
+ important: false, children: [],
1076
+ loc: c.loc, node: 'comment', cssNode: {}, parents: [],
1077
+ };
1078
+ }
1079
+ default:
1080
+ return null;
1081
+ }
1082
+ }
1083
+ }
1084
+ // ─── Public parse helpers ─────────────────────────────────────────────────────
1085
+ /** Parse a CSS string into a stylesheet AST. */
1086
+ export function parseCss(css, options) {
1087
+ return new CssParser(options).parse(css);
1088
+ }
1089
+ /** Parse CSS and convert to the legacy AstNode[] format. */
1090
+ export function parseCssToLegacy(css, options) {
1091
+ const parser = new CssParser(options);
1092
+ return parser.toLegacyFormat(parser.parse(css));
1093
+ }
1094
+ // ─── Re-exports ───────────────────────────────────────────────────────────────
1095
+ export { CssGenerator, stringify } from './css-generator';
1096
+ export { location, locationPos, declaration, decl, rule, atRule, comment, keyframe, stylesheet, cloneNode, cloneNodeDeep, walk, selector, } from './css-helpers';
1097
+ export * from './types/ast';
1098
+ //# sourceMappingURL=css-parser.js.map