@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,749 +0,0 @@
1
- //#region src/utils/color-math.ts
2
- const OKLab_to_LMS_M = [
3
- [
4
- 1,
5
- .3963377773761749,
6
- .2158037573099136
7
- ],
8
- [
9
- 1,
10
- -.1055613458156586,
11
- -.0638541728258133
12
- ],
13
- [
14
- 1,
15
- -.0894841775298119,
16
- -1.2914855480194092
17
- ]
18
- ];
19
- const LMS_to_linear_sRGB_M = [
20
- [
21
- 4.076741636075959,
22
- -3.307711539258062,
23
- .2309699031821041
24
- ],
25
- [
26
- -1.2684379732850313,
27
- 2.6097573492876878,
28
- -.3413193760026569
29
- ],
30
- [
31
- -.004196076138675526,
32
- -.703418617935936,
33
- 1.7076146940746113
34
- ]
35
- ];
36
- const OKLab_to_linear_sRGB_coefficients = [
37
- [[-1.8817030993265873, -.8093650129914302], [
38
- 1.19086277,
39
- 1.76576728,
40
- .59662641,
41
- .75515197,
42
- .56771245
43
- ]],
44
- [[1.8144407988010998, -1.194452667805235], [
45
- .73956515,
46
- -.45954404,
47
- .08285427,
48
- .1254107,
49
- .14503204
50
- ]],
51
- [[.13110757611180954, 1.813339709266608], [
52
- 1.35733652,
53
- -.00915799,
54
- -1.1513021,
55
- -.50559606,
56
- .00692167
57
- ]]
58
- ];
59
- const dotXY = (a, b) => a[0] * b[0] + a[1] * b[1];
60
- function srgbToLinear(c) {
61
- return c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
62
- }
63
- const INV_GAMMA = 1 / 2.4;
64
- function srgbLinearToGamma(val) {
65
- const sign = val < 0 ? -1 : 1;
66
- const abs = Math.abs(val);
67
- return abs > .0031308 ? sign * (1.055 * abs ** INV_GAMMA - .055) : 12.92 * val;
68
- }
69
- const TAU = 2 * Math.PI;
70
- const K1 = .206;
71
- const K2 = .03;
72
- const K3 = (1 + K1) / (1 + K2);
73
- const clamp = (value, min, max) => Math.max(Math.min(value, max), min);
74
- const constrainAngle = (angle) => (angle % 360 + 360) % 360;
75
- const toeInv = (x) => (x ** 2 + K1 * x) / (K3 * (x + K2));
76
- const oklabToLinearSrgb = (lab) => {
77
- const L = lab[0];
78
- const a = lab[1];
79
- const b = lab[2];
80
- const l_ = L + .3963377773761749 * a + .2158037573099136 * b;
81
- const m_ = L - .1055613458156586 * a - .0638541728258133 * b;
82
- const s_ = L - .0894841775298119 * a - 1.2914855480194092 * b;
83
- const l = l_ * l_ * l_;
84
- const m = m_ * m_ * m_;
85
- const s = s_ * s_ * s_;
86
- return [
87
- 4.076741636075959 * l - 3.307711539258062 * m + .2309699031821041 * s,
88
- -1.2684379732850313 * l + 2.6097573492876878 * m - .3413193760026569 * s,
89
- -.004196076138675526 * l - .703418617935936 * m + 1.7076146940746113 * s
90
- ];
91
- };
92
- const linearSrgbToOklab = (rgb) => {
93
- const r = rgb[0];
94
- const g = rgb[1];
95
- const b = rgb[2];
96
- const l = .4122214708 * r + .5363325363 * g + .0514459929 * b;
97
- const m = .2119034982 * r + .6806995451 * g + .1073969566 * b;
98
- const s = .0883024619 * r + .2817188376 * g + .6299787005 * b;
99
- const l_ = Math.cbrt(l);
100
- const m_ = Math.cbrt(m);
101
- const s_ = Math.cbrt(s);
102
- return [
103
- .2104542553 * l_ + .793617785 * m_ - .0040720468 * s_,
104
- 1.9779984951 * l_ - 2.428592205 * m_ + .4505937099 * s_,
105
- .0259040371 * l_ + .7827717662 * m_ - .808675766 * s_
106
- ];
107
- };
108
- const computeMaxSaturationOKLC = (a, b) => {
109
- const okCoeff = OKLab_to_linear_sRGB_coefficients;
110
- const lmsToRgb = LMS_to_linear_sRGB_M;
111
- const tmp2 = [a, b];
112
- const tmp3 = [
113
- 0,
114
- a,
115
- b
116
- ];
117
- let chnlCoeff;
118
- let chnlLMS;
119
- if (dotXY(okCoeff[0][0], tmp2) > 1) {
120
- chnlCoeff = okCoeff[0][1];
121
- chnlLMS = lmsToRgb[0];
122
- } else if (dotXY(okCoeff[1][0], tmp2) > 1) {
123
- chnlCoeff = okCoeff[1][1];
124
- chnlLMS = lmsToRgb[1];
125
- } else {
126
- chnlCoeff = okCoeff[2][1];
127
- chnlLMS = lmsToRgb[2];
128
- }
129
- const [k0, k1, k2, k3, k4] = chnlCoeff;
130
- const [wl, wm, ws] = chnlLMS;
131
- let sat = k0 + k1 * a + k2 * b + k3 * (a * a) + k4 * a * b;
132
- const dotYZ = (mat, vec) => mat[1] * vec[1] + mat[2] * vec[2];
133
- const kl = dotYZ(OKLab_to_LMS_M[0], tmp3);
134
- const km = dotYZ(OKLab_to_LMS_M[1], tmp3);
135
- const ks = dotYZ(OKLab_to_LMS_M[2], tmp3);
136
- const l_ = 1 + sat * kl;
137
- const m_ = 1 + sat * km;
138
- const s_ = 1 + sat * ks;
139
- const l = l_ ** 3;
140
- const m = m_ ** 3;
141
- const s = s_ ** 3;
142
- const lds = 3 * kl * (l_ * l_);
143
- const mds = 3 * km * (m_ * m_);
144
- const sds = 3 * ks * (s_ * s_);
145
- const lds2 = 6 * (kl * kl) * l_;
146
- const mds2 = 6 * (km * km) * m_;
147
- const sds2 = 6 * (ks * ks) * s_;
148
- const f = wl * l + wm * m + ws * s;
149
- const f1 = wl * lds + wm * mds + ws * sds;
150
- const f2 = wl * lds2 + wm * mds2 + ws * sds2;
151
- sat = sat - f * f1 / (f1 * f1 - .5 * f * f2);
152
- return sat;
153
- };
154
- const findCuspOKLCH = (a, b) => {
155
- const S_cusp = computeMaxSaturationOKLC(a, b);
156
- const rgb_at_max = oklabToLinearSrgb([
157
- 1,
158
- S_cusp * a,
159
- S_cusp * b
160
- ]);
161
- const L_cusp = Math.cbrt(1 / Math.max(Math.max(rgb_at_max[0], rgb_at_max[1]), Math.max(rgb_at_max[2], 0)));
162
- return [L_cusp, L_cusp * S_cusp];
163
- };
164
- const findGamutIntersectionOKLCH = (a, b, l1, c1, l0, cusp) => {
165
- const lmsToRgb = LMS_to_linear_sRGB_M;
166
- const tmp3 = [
167
- 0,
168
- a,
169
- b
170
- ];
171
- const floatMax = Number.MAX_VALUE;
172
- let t;
173
- const dotYZ = (mat, vec) => mat[1] * vec[1] + mat[2] * vec[2];
174
- const dotXYZ = (vec, x, y, z) => vec[0] * x + vec[1] * y + vec[2] * z;
175
- if ((l1 - l0) * cusp[1] - (cusp[0] - l0) * c1 <= 0) {
176
- const denom = c1 * cusp[0] + cusp[1] * (l0 - l1);
177
- t = denom === 0 ? 0 : cusp[1] * l0 / denom;
178
- } else {
179
- const denom = c1 * (cusp[0] - 1) + cusp[1] * (l0 - l1);
180
- t = denom === 0 ? 0 : cusp[1] * (l0 - 1) / denom;
181
- const dl = l1 - l0;
182
- const dc = c1;
183
- const kl = dotYZ(OKLab_to_LMS_M[0], tmp3);
184
- const km = dotYZ(OKLab_to_LMS_M[1], tmp3);
185
- const ks = dotYZ(OKLab_to_LMS_M[2], tmp3);
186
- const ldt_ = dl + dc * kl;
187
- const mdt_ = dl + dc * km;
188
- const sdt_ = dl + dc * ks;
189
- const L = l0 * (1 - t) + t * l1;
190
- const C = t * c1;
191
- const l_ = L + C * kl;
192
- const m_ = L + C * km;
193
- const s_ = L + C * ks;
194
- const l = l_ ** 3;
195
- const m = m_ ** 3;
196
- const s = s_ ** 3;
197
- const ldt = 3 * ldt_ * l_ * l_;
198
- const mdt = 3 * mdt_ * m_ * m_;
199
- const sdt = 3 * sdt_ * s_ * s_;
200
- const ldt2 = 6 * ldt_ * ldt_ * l_;
201
- const mdt2 = 6 * mdt_ * mdt_ * m_;
202
- const sdt2 = 6 * sdt_ * sdt_ * s_;
203
- const r_ = dotXYZ(lmsToRgb[0], l, m, s) - 1;
204
- const r1 = dotXYZ(lmsToRgb[0], ldt, mdt, sdt);
205
- const r2 = dotXYZ(lmsToRgb[0], ldt2, mdt2, sdt2);
206
- const ur = r1 / (r1 * r1 - .5 * r_ * r2);
207
- let tr = -r_ * ur;
208
- const g_ = dotXYZ(lmsToRgb[1], l, m, s) - 1;
209
- const g1 = dotXYZ(lmsToRgb[1], ldt, mdt, sdt);
210
- const g2 = dotXYZ(lmsToRgb[1], ldt2, mdt2, sdt2);
211
- const ug = g1 / (g1 * g1 - .5 * g_ * g2);
212
- let tg = -g_ * ug;
213
- const b_ = dotXYZ(lmsToRgb[2], l, m, s) - 1;
214
- const b1 = dotXYZ(lmsToRgb[2], ldt, mdt, sdt);
215
- const b2 = dotXYZ(lmsToRgb[2], ldt2, mdt2, sdt2);
216
- const ub = b1 / (b1 * b1 - .5 * b_ * b2);
217
- let tb = -b_ * ub;
218
- tr = ur >= 0 ? tr : floatMax;
219
- tg = ug >= 0 ? tg : floatMax;
220
- tb = ub >= 0 ? tb : floatMax;
221
- t += Math.min(tr, Math.min(tg, tb));
222
- }
223
- return t;
224
- };
225
- const computeSt = (cusp) => [cusp[1] / cusp[0], cusp[1] / (1 - cusp[0])];
226
- const computeStMid = (a, b) => [.11516993 + 1 / (7.4477897 + 4.1590124 * b + a * (-2.19557347 + 1.75198401 * b + a * (-2.13704948 - 10.02301043 * b + a * (-4.24894561 + 5.38770819 * b + 4.69891013 * a)))), .11239642 + 1 / (1.6132032 - .68124379 * b + a * (.40370612 + .90148123 * b + a * (-.27087943 + .6122399 * b + a * (.00299215 - .45399568 * b - .14661872 * a))))];
227
- const getCs = (L, a, b, cusp) => {
228
- const cMax = findGamutIntersectionOKLCH(a, b, L, 1, L, cusp);
229
- const stMax = computeSt(cusp);
230
- const k = cMax / Math.min(L * stMax[0], (1 - L) * stMax[1]);
231
- const stMid = computeStMid(a, b);
232
- let ca = L * stMid[0];
233
- let cb = (1 - L) * stMid[1];
234
- const cMid = .9 * k * Math.sqrt(Math.sqrt(1 / (1 / ca ** 4 + 1 / cb ** 4)));
235
- ca = L * .4;
236
- cb = (1 - L) * .8;
237
- return [
238
- Math.sqrt(1 / (1 / ca ** 2 + 1 / cb ** 2)),
239
- cMid,
240
- cMax
241
- ];
242
- };
243
- const okhslToOklab = (hsl) => {
244
- let h = hsl[0];
245
- const s = hsl[1];
246
- const l = hsl[2];
247
- const L = toeInv(l);
248
- let a = 0;
249
- let b = 0;
250
- h = constrainAngle(h) / 360;
251
- if (L !== 0 && L !== 1 && s !== 0) {
252
- const a_ = Math.cos(TAU * h);
253
- const b_ = Math.sin(TAU * h);
254
- const [c0, cMid, cMax] = getCs(L, a_, b_, findCuspOKLCH(a_, b_));
255
- const mid = .8;
256
- const midInv = 1.25;
257
- let t, k0, k1, k2;
258
- if (s < mid) {
259
- t = midInv * s;
260
- k0 = 0;
261
- k1 = mid * c0;
262
- k2 = 1 - k1 / cMid;
263
- } else {
264
- t = 5 * (s - .8);
265
- k0 = cMid;
266
- k1 = .2 * cMid ** 2 * 1.25 ** 2 / c0;
267
- k2 = 1 - k1 / (cMax - cMid);
268
- }
269
- const c = k0 + t * k1 / (1 - k2 * t);
270
- a = c * a_;
271
- b = c * b_;
272
- }
273
- return [
274
- L,
275
- a,
276
- b
277
- ];
278
- };
279
- /**
280
- * HSL to RGB.
281
- * Algorithm from CSS Color 4 spec.
282
- *
283
- * @param h - Hue in degrees (0-360)
284
- * @param s - Saturation (0-1)
285
- * @param l - Lightness (0-1)
286
- * @returns RGB values in 0-255 range (may have fractional values)
287
- */
288
- function hslToRgbValues(h, s, l) {
289
- const a = s * Math.min(l, 1 - l);
290
- const f = (n) => {
291
- const k = (n + h / 30) % 12;
292
- return l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
293
- };
294
- return [
295
- f(0) * 255,
296
- f(8) * 255,
297
- f(4) * 255
298
- ];
299
- }
300
- /**
301
- * RGB (0-255) to HSL.
302
- * @returns [h (0-360), s (0-1), l (0-1)]
303
- */
304
- function rgbToHsl(r, g, b) {
305
- r /= 255;
306
- g /= 255;
307
- b /= 255;
308
- const max = Math.max(r, g, b);
309
- const min = Math.min(r, g, b);
310
- const l = (max + min) / 2;
311
- if (max === min) return [
312
- 0,
313
- 0,
314
- l
315
- ];
316
- const d = max - min;
317
- const s = l > .5 ? d / (2 - max - min) : d / (max + min);
318
- let h;
319
- if (max === r) h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
320
- else if (max === g) h = ((b - r) / d + 2) / 6;
321
- else h = ((r - g) / d + 4) / 6;
322
- return [
323
- h * 360,
324
- s,
325
- l
326
- ];
327
- }
328
- /**
329
- * RGB (0-255) to OKLCH via sRGB -> linear sRGB -> OKLab -> OKLCH.
330
- * @returns [L, C, H] where H is in degrees (0-360)
331
- */
332
- function rgbToOklch(r, g, b) {
333
- const [L, a, bLab] = linearSrgbToOklab([
334
- srgbToLinear(r / 255),
335
- srgbToLinear(g / 255),
336
- srgbToLinear(b / 255)
337
- ]);
338
- const C = Math.sqrt(a * a + bLab * bLab);
339
- let H = Math.atan2(bLab, a) * 180 / Math.PI;
340
- if (H < 0) H += 360;
341
- return [
342
- L,
343
- C,
344
- H
345
- ];
346
- }
347
- /**
348
- * OKHSL to sRGB (0-1 range).
349
- * @param h - Hue in degrees (0-360)
350
- * @param s - Saturation (0-1)
351
- * @param l - Lightness (0-1)
352
- * @returns sRGB values in 0-1 range, clamped to gamut
353
- */
354
- function okhslToSrgb(h, s, l) {
355
- const linearRGB = oklabToLinearSrgb(okhslToOklab([
356
- h,
357
- s,
358
- l
359
- ]));
360
- return [
361
- clamp(srgbLinearToGamma(linearRGB[0]), 0, 1),
362
- clamp(srgbLinearToGamma(linearRGB[1]), 0, 1),
363
- clamp(srgbLinearToGamma(linearRGB[2]), 0, 1)
364
- ];
365
- }
366
- /**
367
- * OKLCH to sRGB (0-255 range).
368
- * @param L - Lightness (0-1)
369
- * @param C - Chroma (typically 0-0.4)
370
- * @param H - Hue in degrees (0-360)
371
- * @returns RGB values in 0-255 range, clamped to gamut
372
- */
373
- function oklchToRgbValues(L, C, H) {
374
- const hRad = H * Math.PI / 180;
375
- const linear = oklabToLinearSrgb([
376
- L,
377
- C * Math.cos(hRad),
378
- C * Math.sin(hRad)
379
- ]);
380
- return [
381
- clamp(srgbLinearToGamma(linear[0]), 0, 1) * 255,
382
- clamp(srgbLinearToGamma(linear[1]), 0, 1) * 255,
383
- clamp(srgbLinearToGamma(linear[2]), 0, 1) * 255
384
- ];
385
- }
386
- let _namedColorHex = null;
387
- function getNamedColorHex() {
388
- if (_namedColorHex) return _namedColorHex;
389
- _namedColorHex = new Map([
390
- ["aliceblue", "#f0f8ff"],
391
- ["antiquewhite", "#faebd7"],
392
- ["aqua", "#00ffff"],
393
- ["aquamarine", "#7fffd4"],
394
- ["azure", "#f0ffff"],
395
- ["beige", "#f5f5dc"],
396
- ["bisque", "#ffe4c4"],
397
- ["black", "#000000"],
398
- ["blanchedalmond", "#ffebcd"],
399
- ["blue", "#0000ff"],
400
- ["blueviolet", "#8a2be2"],
401
- ["brown", "#a52a2a"],
402
- ["burlywood", "#deb887"],
403
- ["cadetblue", "#5f9ea0"],
404
- ["chartreuse", "#7fff00"],
405
- ["chocolate", "#d2691e"],
406
- ["coral", "#ff7f50"],
407
- ["cornflowerblue", "#6495ed"],
408
- ["cornsilk", "#fff8dc"],
409
- ["crimson", "#dc143c"],
410
- ["cyan", "#00ffff"],
411
- ["darkblue", "#00008b"],
412
- ["darkcyan", "#008b8b"],
413
- ["darkgoldenrod", "#b8860b"],
414
- ["darkgray", "#a9a9a9"],
415
- ["darkgreen", "#006400"],
416
- ["darkgrey", "#a9a9a9"],
417
- ["darkkhaki", "#bdb76b"],
418
- ["darkmagenta", "#8b008b"],
419
- ["darkolivegreen", "#556b2f"],
420
- ["darkorange", "#ff8c00"],
421
- ["darkorchid", "#9932cc"],
422
- ["darkred", "#8b0000"],
423
- ["darksalmon", "#e9967a"],
424
- ["darkseagreen", "#8fbc8f"],
425
- ["darkslateblue", "#483d8b"],
426
- ["darkslategray", "#2f4f4f"],
427
- ["darkslategrey", "#2f4f4f"],
428
- ["darkturquoise", "#00ced1"],
429
- ["darkviolet", "#9400d3"],
430
- ["deeppink", "#ff1493"],
431
- ["deepskyblue", "#00bfff"],
432
- ["dimgray", "#696969"],
433
- ["dimgrey", "#696969"],
434
- ["dodgerblue", "#1e90ff"],
435
- ["firebrick", "#b22222"],
436
- ["floralwhite", "#fffaf0"],
437
- ["forestgreen", "#228b22"],
438
- ["fuchsia", "#ff00ff"],
439
- ["gainsboro", "#dcdcdc"],
440
- ["ghostwhite", "#f8f8ff"],
441
- ["gold", "#ffd700"],
442
- ["goldenrod", "#daa520"],
443
- ["gray", "#808080"],
444
- ["green", "#008000"],
445
- ["greenyellow", "#adff2f"],
446
- ["grey", "#808080"],
447
- ["honeydew", "#f0fff0"],
448
- ["hotpink", "#ff69b4"],
449
- ["indianred", "#cd5c5c"],
450
- ["indigo", "#4b0082"],
451
- ["ivory", "#fffff0"],
452
- ["khaki", "#f0e68c"],
453
- ["lavender", "#e6e6fa"],
454
- ["lavenderblush", "#fff0f5"],
455
- ["lawngreen", "#7cfc00"],
456
- ["lemonchiffon", "#fffacd"],
457
- ["lightblue", "#add8e6"],
458
- ["lightcoral", "#f08080"],
459
- ["lightcyan", "#e0ffff"],
460
- ["lightgoldenrodyellow", "#fafad2"],
461
- ["lightgray", "#d3d3d3"],
462
- ["lightgreen", "#90ee90"],
463
- ["lightgrey", "#d3d3d3"],
464
- ["lightpink", "#ffb6c1"],
465
- ["lightsalmon", "#ffa07a"],
466
- ["lightseagreen", "#20b2aa"],
467
- ["lightskyblue", "#87cefa"],
468
- ["lightslategray", "#778899"],
469
- ["lightslategrey", "#778899"],
470
- ["lightsteelblue", "#b0c4de"],
471
- ["lightyellow", "#ffffe0"],
472
- ["lime", "#00ff00"],
473
- ["limegreen", "#32cd32"],
474
- ["linen", "#faf0e6"],
475
- ["magenta", "#ff00ff"],
476
- ["maroon", "#800000"],
477
- ["mediumaquamarine", "#66cdaa"],
478
- ["mediumblue", "#0000cd"],
479
- ["mediumorchid", "#ba55d3"],
480
- ["mediumpurple", "#9370db"],
481
- ["mediumseagreen", "#3cb371"],
482
- ["mediumslateblue", "#7b68ee"],
483
- ["mediumspringgreen", "#00fa9a"],
484
- ["mediumturquoise", "#48d1cc"],
485
- ["mediumvioletred", "#c71585"],
486
- ["midnightblue", "#191970"],
487
- ["mintcream", "#f5fffa"],
488
- ["mistyrose", "#ffe4e1"],
489
- ["moccasin", "#ffe4b5"],
490
- ["navajowhite", "#ffdead"],
491
- ["navy", "#000080"],
492
- ["oldlace", "#fdf5e6"],
493
- ["olive", "#808000"],
494
- ["olivedrab", "#6b8e23"],
495
- ["orange", "#ffa500"],
496
- ["orangered", "#ff4500"],
497
- ["orchid", "#da70d6"],
498
- ["palegoldenrod", "#eee8aa"],
499
- ["palegreen", "#98fb98"],
500
- ["paleturquoise", "#afeeee"],
501
- ["palevioletred", "#db7093"],
502
- ["papayawhip", "#ffefd5"],
503
- ["peachpuff", "#ffdab9"],
504
- ["peru", "#cd853f"],
505
- ["pink", "#ffc0cb"],
506
- ["plum", "#dda0dd"],
507
- ["powderblue", "#b0e0e6"],
508
- ["purple", "#800080"],
509
- ["rebeccapurple", "#663399"],
510
- ["red", "#ff0000"],
511
- ["rosybrown", "#bc8f8f"],
512
- ["royalblue", "#4169e1"],
513
- ["saddlebrown", "#8b4513"],
514
- ["salmon", "#fa8072"],
515
- ["sandybrown", "#f4a460"],
516
- ["seagreen", "#2e8b57"],
517
- ["seashell", "#fff5ee"],
518
- ["sienna", "#a0522d"],
519
- ["silver", "#c0c0c0"],
520
- ["skyblue", "#87ceeb"],
521
- ["slateblue", "#6a5acd"],
522
- ["slategray", "#708090"],
523
- ["slategrey", "#708090"],
524
- ["snow", "#fffafa"],
525
- ["springgreen", "#00ff7f"],
526
- ["steelblue", "#4682b4"],
527
- ["tan", "#d2b48c"],
528
- ["teal", "#008080"],
529
- ["thistle", "#d8bfd8"],
530
- ["tomato", "#ff6347"],
531
- ["turquoise", "#40e0d0"],
532
- ["violet", "#ee82ee"],
533
- ["wheat", "#f5deb3"],
534
- ["white", "#ffffff"],
535
- ["whitesmoke", "#f5f5f5"],
536
- ["yellow", "#ffff00"],
537
- ["yellowgreen", "#9acd32"]
538
- ]);
539
- return _namedColorHex;
540
- }
541
- const hexCharToNum = (c) => {
542
- if (c >= 48 && c <= 57) return c - 48;
543
- if (c >= 65 && c <= 70) return c - 55;
544
- if (c >= 97 && c <= 102) return c - 87;
545
- return -1;
546
- };
547
- /**
548
- * Parse a hex color string to RGBA values (RGB 0-255, alpha 0-1).
549
- * Supports 3, 4, 6, and 8 character hex values (with or without `#`).
550
- * For 3/6-char hex (no alpha channel), alpha defaults to 1.
551
- */
552
- function hexToRgbaValues(hex) {
553
- let start = 0;
554
- if (hex.charCodeAt(0) === 35) start = 1;
555
- const len = hex.length - start;
556
- if (len === 3) {
557
- const r = hexCharToNum(hex.charCodeAt(start));
558
- const g = hexCharToNum(hex.charCodeAt(start + 1));
559
- const b = hexCharToNum(hex.charCodeAt(start + 2));
560
- if (r < 0 || g < 0 || b < 0) return null;
561
- return [
562
- r * 17,
563
- g * 17,
564
- b * 17,
565
- 1
566
- ];
567
- }
568
- if (len === 4) {
569
- const r = hexCharToNum(hex.charCodeAt(start));
570
- const g = hexCharToNum(hex.charCodeAt(start + 1));
571
- const b = hexCharToNum(hex.charCodeAt(start + 2));
572
- const a = hexCharToNum(hex.charCodeAt(start + 3));
573
- if (r < 0 || g < 0 || b < 0 || a < 0) return null;
574
- return [
575
- r * 17,
576
- g * 17,
577
- b * 17,
578
- a * 17 / 255
579
- ];
580
- }
581
- if (len === 6) {
582
- const r1 = hexCharToNum(hex.charCodeAt(start));
583
- const r2 = hexCharToNum(hex.charCodeAt(start + 1));
584
- const g1 = hexCharToNum(hex.charCodeAt(start + 2));
585
- const g2 = hexCharToNum(hex.charCodeAt(start + 3));
586
- const b1 = hexCharToNum(hex.charCodeAt(start + 4));
587
- const b2 = hexCharToNum(hex.charCodeAt(start + 5));
588
- if (r1 < 0 || r2 < 0 || g1 < 0 || g2 < 0 || b1 < 0 || b2 < 0) return null;
589
- return [
590
- r1 * 16 + r2,
591
- g1 * 16 + g2,
592
- b1 * 16 + b2,
593
- 1
594
- ];
595
- }
596
- if (len === 8) {
597
- const r1 = hexCharToNum(hex.charCodeAt(start));
598
- const r2 = hexCharToNum(hex.charCodeAt(start + 1));
599
- const g1 = hexCharToNum(hex.charCodeAt(start + 2));
600
- const g2 = hexCharToNum(hex.charCodeAt(start + 3));
601
- const b1 = hexCharToNum(hex.charCodeAt(start + 4));
602
- const b2 = hexCharToNum(hex.charCodeAt(start + 5));
603
- const a1 = hexCharToNum(hex.charCodeAt(start + 6));
604
- const a2 = hexCharToNum(hex.charCodeAt(start + 7));
605
- if (r1 < 0 || r2 < 0 || g1 < 0 || g2 < 0 || b1 < 0 || b2 < 0 || a1 < 0 || a2 < 0) return null;
606
- return [
607
- r1 * 16 + r2,
608
- g1 * 16 + g2,
609
- b1 * 16 + b2,
610
- (a1 * 16 + a2) / 255
611
- ];
612
- }
613
- return null;
614
- }
615
- /**
616
- * Convert hex color string to `rgb()` CSS string.
617
- * Supports 3, 4, 6, and 8 character hex values (with or without `#`).
618
- */
619
- function hexToRgb(hex) {
620
- const matched = hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (_m, r, g, b) => "#" + r + r + g + g + b + b).substring(1).match(/.{2}/g);
621
- if (!matched) return null;
622
- const rgba = matched.map((x, i) => parseInt(x, 16) * (i === 3 ? 1 / 255 : 1));
623
- if (rgba.some((v) => Number.isNaN(v))) return null;
624
- if (rgba.length >= 3) return `rgb(${rgba.slice(0, 3).join(" ")}${rgba.length > 3 ? ` / ${rgba[3]}` : ""})`;
625
- return null;
626
- }
627
- /**
628
- * Extract RGB values from an `rgb()`/`rgba()` string.
629
- * Supports comma-separated, space-separated, fractional, percentage,
630
- * and slash alpha notation.
631
- *
632
- * @returns Array of RGB values (0-255 range), converting percentages as needed.
633
- */
634
- function getRgbValuesFromRgbaString(str) {
635
- const match = str.match(/rgba?\(([^)]+)\)/i);
636
- if (!match) return [];
637
- const [colorPart] = match[1].trim().split("/");
638
- return colorPart.trim().split(/[,\s]+/).filter(Boolean).slice(0, 3).map((part) => {
639
- part = part.trim();
640
- if (part.endsWith("%")) return parseFloat(part) / 100 * 255;
641
- return parseFloat(part);
642
- });
643
- }
644
- /**
645
- * Convert any recognized color string to an `rgb()` CSS string.
646
- * Handles hex, `okhsl()`, `hsl()`/`hsla()`, named CSS colors,
647
- * and `rgb()`/`rgba()` pass-through.
648
- */
649
- function strToRgb(color, _ignoreAlpha = false) {
650
- if (!color) return void 0;
651
- if (color.startsWith("rgb")) return color;
652
- if (color.startsWith("#")) return hexToRgb(color);
653
- if (color.startsWith("oklch(")) return oklchStringToRgb(color);
654
- if (color.startsWith("okhsl(")) return okhslStringToRgb(color);
655
- if (color.startsWith("hsl")) return hslStringToRgb(color);
656
- const namedHex = getNamedColorHex().get(color.toLowerCase());
657
- if (namedHex) return hexToRgb(namedHex);
658
- return null;
659
- }
660
- /**
661
- * Convert an HSL/HSLA color string to an `rgb()`/`rgba()` CSS string.
662
- * Supports modern space-separated and legacy comma-separated syntax,
663
- * deg/turn/rad hue units, and slash alpha notation.
664
- */
665
- function hslStringToRgb(hslStr) {
666
- const match = hslStr.match(/hsla?\(([^)]+)\)/i);
667
- if (!match) return null;
668
- const [colorPart, slashAlpha] = match[1].trim().split("/");
669
- const parts = colorPart.trim().split(/[,\s]+/).filter(Boolean);
670
- if (parts.length < 3) return null;
671
- const alphaPart = slashAlpha?.trim() || (parts.length >= 4 ? parts[3] : null);
672
- let h = parseFloat(parts[0]);
673
- const hueStr = parts[0].toLowerCase();
674
- if (hueStr.endsWith("turn")) h = parseFloat(hueStr) * 360;
675
- else if (hueStr.endsWith("rad")) h = parseFloat(hueStr) * 180 / Math.PI;
676
- h = (h % 360 + 360) % 360;
677
- const parsePercent = (val) => {
678
- const num = parseFloat(val);
679
- return val.includes("%") ? num / 100 : num;
680
- };
681
- const s = Math.max(0, Math.min(1, parsePercent(parts[1])));
682
- const l = Math.max(0, Math.min(1, parsePercent(parts[2])));
683
- const [r, g, b] = hslToRgbValues(h, s, l);
684
- if (alphaPart) {
685
- const alpha = parseFloat(alphaPart.trim());
686
- return `rgba(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}, ${alpha})`;
687
- }
688
- return `rgb(${Math.round(r)} ${Math.round(g)} ${Math.round(b)})`;
689
- }
690
- /**
691
- * Convert an `okhsl()` color string to an `rgb()`/`rgba()` CSS string.
692
- * Supports deg/turn/rad hue units and percentage saturation/lightness.
693
- */
694
- function okhslStringToRgb(okhslStr) {
695
- const match = okhslStr.match(/okhsl\(([^)]+)\)/i);
696
- if (!match) return null;
697
- const [colorPart, alphaPart] = match[1].trim().split("/");
698
- const parts = colorPart.trim().split(/[,\s]+/).filter(Boolean);
699
- if (parts.length < 3) return null;
700
- let h = parseFloat(parts[0]);
701
- const hueStr = parts[0].toLowerCase();
702
- if (hueStr.endsWith("turn")) h = parseFloat(hueStr) * 360;
703
- else if (hueStr.endsWith("rad")) h = parseFloat(hueStr) * 180 / Math.PI;
704
- else if (hueStr.endsWith("deg")) h = parseFloat(hueStr);
705
- const parsePercent = (val) => {
706
- const num = parseFloat(val);
707
- return val.includes("%") ? num / 100 : num;
708
- };
709
- const s = Math.max(0, Math.min(1, parsePercent(parts[1])));
710
- const l = Math.max(0, Math.min(1, parsePercent(parts[2])));
711
- const [r, g, b] = okhslToSrgb(h, s, l);
712
- const r255 = Math.round(Math.max(0, Math.min(1, r)) * 255);
713
- const g255 = Math.round(Math.max(0, Math.min(1, g)) * 255);
714
- const b255 = Math.round(Math.max(0, Math.min(1, b)) * 255);
715
- if (alphaPart) return `rgba(${r255}, ${g255}, ${b255}, ${parseFloat(alphaPart.trim())})`;
716
- return `rgb(${r255} ${g255} ${b255})`;
717
- }
718
- /**
719
- * Convert an `oklch()` color string to an `rgb()`/`rgba()` CSS string.
720
- * Supports deg/turn/rad hue units and percentage lightness.
721
- */
722
- function oklchStringToRgb(oklchStr) {
723
- const match = oklchStr.match(/oklch\(([^)]+)\)/i);
724
- if (!match) return null;
725
- const [colorPart, alphaPart] = match[1].trim().split("/");
726
- const parts = colorPart.trim().split(/[,\s]+/).filter(Boolean);
727
- if (parts.length < 3) return null;
728
- const parsePercent = (val) => {
729
- const num = parseFloat(val);
730
- return val.includes("%") ? num / 100 : num;
731
- };
732
- const L = Math.max(0, Math.min(1, parsePercent(parts[0])));
733
- const C = Math.max(0, parseFloat(parts[1]));
734
- let H = parseFloat(parts[2]);
735
- const hueStr = parts[2].toLowerCase();
736
- if (hueStr.endsWith("turn")) H = parseFloat(hueStr) * 360;
737
- else if (hueStr.endsWith("rad")) H = parseFloat(hueStr) * 180 / Math.PI;
738
- else if (hueStr.endsWith("deg")) H = parseFloat(hueStr);
739
- const [r, g, b] = oklchToRgbValues(L, C, H);
740
- if (alphaPart) {
741
- const alpha = parseFloat(alphaPart.trim());
742
- return `rgba(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}, ${alpha})`;
743
- }
744
- return `rgb(${Math.round(r)} ${Math.round(g)} ${Math.round(b)})`;
745
- }
746
-
747
- //#endregion
748
- export { getNamedColorHex, getRgbValuesFromRgbaString, hexToRgb, hexToRgbaValues, hslToRgbValues, okhslToSrgb, oklchToRgbValues, rgbToHsl, rgbToOklch, strToRgb };
749
- //# sourceMappingURL=color-math.js.map