@number10/jsx-core 5.0.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 (340) hide show
  1. package/LICENSE +667 -0
  2. package/README.md +38 -0
  3. package/dist/animation/animated-signal.cjs +19 -0
  4. package/dist/animation/animated-signal.cjs.map +1 -0
  5. package/dist/animation/animated-signal.d.ts +35 -0
  6. package/dist/animation/animated-signal.d.ts.map +1 -0
  7. package/dist/animation/animated-signal.js +19 -0
  8. package/dist/animation/animated-signal.js.map +1 -0
  9. package/dist/animation/create-spring.cjs +80 -0
  10. package/dist/animation/create-spring.cjs.map +1 -0
  11. package/dist/animation/create-spring.d.ts +56 -0
  12. package/dist/animation/create-spring.d.ts.map +1 -0
  13. package/dist/animation/create-spring.js +80 -0
  14. package/dist/animation/create-spring.js.map +1 -0
  15. package/dist/animation/easing.cjs +76 -0
  16. package/dist/animation/easing.cjs.map +1 -0
  17. package/dist/animation/easing.d.ts +45 -0
  18. package/dist/animation/easing.d.ts.map +1 -0
  19. package/dist/animation/easing.js +76 -0
  20. package/dist/animation/easing.js.map +1 -0
  21. package/dist/animation/effect-definitions.cjs +441 -0
  22. package/dist/animation/effect-definitions.cjs.map +1 -0
  23. package/dist/animation/effect-definitions.d.ts +60 -0
  24. package/dist/animation/effect-definitions.d.ts.map +1 -0
  25. package/dist/animation/effect-definitions.js +441 -0
  26. package/dist/animation/effect-definitions.js.map +1 -0
  27. package/dist/animation/effect-engine.cjs +189 -0
  28. package/dist/animation/effect-engine.cjs.map +1 -0
  29. package/dist/animation/effect-engine.d.ts +70 -0
  30. package/dist/animation/effect-engine.d.ts.map +1 -0
  31. package/dist/animation/effect-engine.js +189 -0
  32. package/dist/animation/effect-engine.js.map +1 -0
  33. package/dist/animation/index.d.ts +24 -0
  34. package/dist/animation/index.d.ts.map +1 -0
  35. package/dist/animation/spring-physics.cjs +94 -0
  36. package/dist/animation/spring-physics.cjs.map +1 -0
  37. package/dist/animation/spring-physics.d.ts +145 -0
  38. package/dist/animation/spring-physics.d.ts.map +1 -0
  39. package/dist/animation/spring-physics.js +94 -0
  40. package/dist/animation/spring-physics.js.map +1 -0
  41. package/dist/animation/tween.cjs +67 -0
  42. package/dist/animation/tween.cjs.map +1 -0
  43. package/dist/animation/tween.d.ts +60 -0
  44. package/dist/animation/tween.d.ts.map +1 -0
  45. package/dist/animation/tween.js +67 -0
  46. package/dist/animation/tween.js.map +1 -0
  47. package/dist/animation/types.d.ts +31 -0
  48. package/dist/animation/types.d.ts.map +1 -0
  49. package/dist/animation/useSpring.cjs +152 -0
  50. package/dist/animation/useSpring.cjs.map +1 -0
  51. package/dist/animation/useSpring.d.ts +55 -0
  52. package/dist/animation/useSpring.d.ts.map +1 -0
  53. package/dist/animation/useSpring.js +149 -0
  54. package/dist/animation/useSpring.js.map +1 -0
  55. package/dist/animation/useTween.cjs +208 -0
  56. package/dist/animation/useTween.cjs.map +1 -0
  57. package/dist/animation/useTween.d.ts +116 -0
  58. package/dist/animation/useTween.d.ts.map +1 -0
  59. package/dist/animation/useTween.js +208 -0
  60. package/dist/animation/useTween.js.map +1 -0
  61. package/dist/border-geometry.cjs +447 -0
  62. package/dist/border-geometry.cjs.map +1 -0
  63. package/dist/border-geometry.d.ts +114 -0
  64. package/dist/border-geometry.d.ts.map +1 -0
  65. package/dist/border-geometry.js +447 -0
  66. package/dist/border-geometry.js.map +1 -0
  67. package/dist/colors/color-presets.cjs +236 -0
  68. package/dist/colors/color-presets.cjs.map +1 -0
  69. package/dist/colors/color-presets.d.ts +89 -0
  70. package/dist/colors/color-presets.d.ts.map +1 -0
  71. package/dist/colors/color-presets.js +236 -0
  72. package/dist/colors/color-presets.js.map +1 -0
  73. package/dist/colors/color-theme-helpers.cjs +32 -0
  74. package/dist/colors/color-theme-helpers.cjs.map +1 -0
  75. package/dist/colors/color-theme-helpers.d.ts +65 -0
  76. package/dist/colors/color-theme-helpers.d.ts.map +1 -0
  77. package/dist/colors/color-theme-helpers.js +32 -0
  78. package/dist/colors/color-theme-helpers.js.map +1 -0
  79. package/dist/colors/color-types.cjs +38 -0
  80. package/dist/colors/color-types.cjs.map +1 -0
  81. package/dist/colors/color-types.d.ts +112 -0
  82. package/dist/colors/color-types.d.ts.map +1 -0
  83. package/dist/colors/color-types.js +38 -0
  84. package/dist/colors/color-types.js.map +1 -0
  85. package/dist/colors/color-utils.cjs +197 -0
  86. package/dist/colors/color-utils.cjs.map +1 -0
  87. package/dist/colors/color-utils.d.ts +216 -0
  88. package/dist/colors/color-utils.d.ts.map +1 -0
  89. package/dist/colors/color-utils.js +197 -0
  90. package/dist/colors/color-utils.js.map +1 -0
  91. package/dist/colors/contrast-contracts.cjs +265 -0
  92. package/dist/colors/contrast-contracts.cjs.map +1 -0
  93. package/dist/colors/contrast-contracts.d.ts +289 -0
  94. package/dist/colors/contrast-contracts.d.ts.map +1 -0
  95. package/dist/colors/contrast-contracts.js +265 -0
  96. package/dist/colors/contrast-contracts.js.map +1 -0
  97. package/dist/colors/index.cjs +55 -0
  98. package/dist/colors/index.cjs.map +1 -0
  99. package/dist/colors/index.d.ts +16 -0
  100. package/dist/colors/index.d.ts.map +1 -0
  101. package/dist/colors/index.js +55 -0
  102. package/dist/colors/index.js.map +1 -0
  103. package/dist/core-props.cjs +66 -0
  104. package/dist/core-props.cjs.map +1 -0
  105. package/dist/core-props.d.ts +395 -0
  106. package/dist/core-props.d.ts.map +1 -0
  107. package/dist/core-props.js +66 -0
  108. package/dist/core-props.js.map +1 -0
  109. package/dist/design-tokens/design-token-presets.cjs +91 -0
  110. package/dist/design-tokens/design-token-presets.cjs.map +1 -0
  111. package/dist/design-tokens/design-token-presets.d.ts +34 -0
  112. package/dist/design-tokens/design-token-presets.d.ts.map +1 -0
  113. package/dist/design-tokens/design-token-presets.js +91 -0
  114. package/dist/design-tokens/design-token-presets.js.map +1 -0
  115. package/dist/design-tokens/design-token-types.d.ts +97 -0
  116. package/dist/design-tokens/design-token-types.d.ts.map +1 -0
  117. package/dist/design-tokens/index.cjs +10 -0
  118. package/dist/design-tokens/index.cjs.map +1 -0
  119. package/dist/design-tokens/index.d.ts +9 -0
  120. package/dist/design-tokens/index.d.ts.map +1 -0
  121. package/dist/design-tokens/index.js +10 -0
  122. package/dist/design-tokens/index.js.map +1 -0
  123. package/dist/dev-config.cjs +296 -0
  124. package/dist/dev-config.cjs.map +1 -0
  125. package/dist/dev-config.d.ts +238 -0
  126. package/dist/dev-config.d.ts.map +1 -0
  127. package/dist/dev-config.js +296 -0
  128. package/dist/dev-config.js.map +1 -0
  129. package/dist/effects.cjs +69 -0
  130. package/dist/effects.cjs.map +1 -0
  131. package/dist/effects.d.ts +152 -0
  132. package/dist/effects.d.ts.map +1 -0
  133. package/dist/effects.js +69 -0
  134. package/dist/effects.js.map +1 -0
  135. package/dist/global-registry.cjs +25 -0
  136. package/dist/global-registry.cjs.map +1 -0
  137. package/dist/global-registry.d.ts +19 -0
  138. package/dist/global-registry.d.ts.map +1 -0
  139. package/dist/global-registry.js +25 -0
  140. package/dist/global-registry.js.map +1 -0
  141. package/dist/hooks.cjs +378 -0
  142. package/dist/hooks.cjs.map +1 -0
  143. package/dist/hooks.d.ts +322 -0
  144. package/dist/hooks.d.ts.map +1 -0
  145. package/dist/hooks.js +378 -0
  146. package/dist/hooks.js.map +1 -0
  147. package/dist/host-adapter.d.ts +414 -0
  148. package/dist/host-adapter.d.ts.map +1 -0
  149. package/dist/index.cjs +229 -0
  150. package/dist/index.cjs.map +1 -0
  151. package/dist/index.d.ts +32 -0
  152. package/dist/index.d.ts.map +1 -0
  153. package/dist/index.js +226 -0
  154. package/dist/index.js.map +1 -0
  155. package/dist/jsx-dev-runtime.cjs +10 -0
  156. package/dist/jsx-dev-runtime.cjs.map +1 -0
  157. package/dist/jsx-dev-runtime.d.ts +5 -0
  158. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  159. package/dist/jsx-dev-runtime.js +11 -0
  160. package/dist/jsx-dev-runtime.js.map +1 -0
  161. package/dist/jsx-runtime.cjs +44 -0
  162. package/dist/jsx-runtime.cjs.map +1 -0
  163. package/dist/jsx-runtime.d.ts +24 -0
  164. package/dist/jsx-runtime.d.ts.map +1 -0
  165. package/dist/jsx-runtime.js +44 -0
  166. package/dist/jsx-runtime.js.map +1 -0
  167. package/dist/jsx-types.d.ts +25 -0
  168. package/dist/jsx-types.d.ts.map +1 -0
  169. package/dist/layout/appliers/container-applier.cjs +20 -0
  170. package/dist/layout/appliers/container-applier.cjs.map +1 -0
  171. package/dist/layout/appliers/container-applier.d.ts +9 -0
  172. package/dist/layout/appliers/container-applier.d.ts.map +1 -0
  173. package/dist/layout/appliers/container-applier.js +20 -0
  174. package/dist/layout/appliers/container-applier.js.map +1 -0
  175. package/dist/layout/appliers/position-applier.cjs +31 -0
  176. package/dist/layout/appliers/position-applier.cjs.map +1 -0
  177. package/dist/layout/appliers/position-applier.d.ts +8 -0
  178. package/dist/layout/appliers/position-applier.d.ts.map +1 -0
  179. package/dist/layout/appliers/position-applier.js +31 -0
  180. package/dist/layout/appliers/position-applier.js.map +1 -0
  181. package/dist/layout/layout-engine-test-utils.d.ts +26 -0
  182. package/dist/layout/layout-engine-test-utils.d.ts.map +1 -0
  183. package/dist/layout/layout-engine.cjs +628 -0
  184. package/dist/layout/layout-engine.cjs.map +1 -0
  185. package/dist/layout/layout-engine.d.ts +140 -0
  186. package/dist/layout/layout-engine.d.ts.map +1 -0
  187. package/dist/layout/layout-engine.js +628 -0
  188. package/dist/layout/layout-engine.js.map +1 -0
  189. package/dist/layout/strategies/base-strategy.cjs +31 -0
  190. package/dist/layout/strategies/base-strategy.cjs.map +1 -0
  191. package/dist/layout/strategies/base-strategy.d.ts +59 -0
  192. package/dist/layout/strategies/base-strategy.d.ts.map +1 -0
  193. package/dist/layout/strategies/base-strategy.js +31 -0
  194. package/dist/layout/strategies/base-strategy.js.map +1 -0
  195. package/dist/layout/strategies/column-layout.cjs +145 -0
  196. package/dist/layout/strategies/column-layout.cjs.map +1 -0
  197. package/dist/layout/strategies/column-layout.d.ts +38 -0
  198. package/dist/layout/strategies/column-layout.d.ts.map +1 -0
  199. package/dist/layout/strategies/column-layout.js +145 -0
  200. package/dist/layout/strategies/column-layout.js.map +1 -0
  201. package/dist/layout/strategies/row-layout.cjs +145 -0
  202. package/dist/layout/strategies/row-layout.cjs.map +1 -0
  203. package/dist/layout/strategies/row-layout.d.ts +38 -0
  204. package/dist/layout/strategies/row-layout.d.ts.map +1 -0
  205. package/dist/layout/strategies/row-layout.js +145 -0
  206. package/dist/layout/strategies/row-layout.js.map +1 -0
  207. package/dist/layout/strategies/stack-layout.cjs +94 -0
  208. package/dist/layout/strategies/stack-layout.cjs.map +1 -0
  209. package/dist/layout/strategies/stack-layout.d.ts +30 -0
  210. package/dist/layout/strategies/stack-layout.d.ts.map +1 -0
  211. package/dist/layout/strategies/stack-layout.js +94 -0
  212. package/dist/layout/strategies/stack-layout.js.map +1 -0
  213. package/dist/layout/types.d.ts +134 -0
  214. package/dist/layout/types.d.ts.map +1 -0
  215. package/dist/layout/utils/child-utils.cjs +129 -0
  216. package/dist/layout/utils/child-utils.cjs.map +1 -0
  217. package/dist/layout/utils/child-utils.d.ts +54 -0
  218. package/dist/layout/utils/child-utils.d.ts.map +1 -0
  219. package/dist/layout/utils/child-utils.js +129 -0
  220. package/dist/layout/utils/child-utils.js.map +1 -0
  221. package/dist/layout/utils/dimension-calculator.cjs +109 -0
  222. package/dist/layout/utils/dimension-calculator.cjs.map +1 -0
  223. package/dist/layout/utils/dimension-calculator.d.ts +59 -0
  224. package/dist/layout/utils/dimension-calculator.d.ts.map +1 -0
  225. package/dist/layout/utils/dimension-calculator.js +109 -0
  226. package/dist/layout/utils/dimension-calculator.js.map +1 -0
  227. package/dist/layout/utils/flex-distributor.cjs +173 -0
  228. package/dist/layout/utils/flex-distributor.cjs.map +1 -0
  229. package/dist/layout/utils/flex-distributor.d.ts +18 -0
  230. package/dist/layout/utils/flex-distributor.d.ts.map +1 -0
  231. package/dist/layout/utils/flex-distributor.js +173 -0
  232. package/dist/layout/utils/flex-distributor.js.map +1 -0
  233. package/dist/layout/utils/size-resolver.cjs +280 -0
  234. package/dist/layout/utils/size-resolver.cjs.map +1 -0
  235. package/dist/layout/utils/size-resolver.d.ts +84 -0
  236. package/dist/layout/utils/size-resolver.d.ts.map +1 -0
  237. package/dist/layout/utils/size-resolver.js +280 -0
  238. package/dist/layout/utils/size-resolver.js.map +1 -0
  239. package/dist/layout/utils/spacing-calculator.cjs +50 -0
  240. package/dist/layout/utils/spacing-calculator.cjs.map +1 -0
  241. package/dist/layout/utils/spacing-calculator.d.ts +27 -0
  242. package/dist/layout/utils/spacing-calculator.d.ts.map +1 -0
  243. package/dist/layout/utils/spacing-calculator.js +50 -0
  244. package/dist/layout/utils/spacing-calculator.js.map +1 -0
  245. package/dist/memo.cjs +18 -0
  246. package/dist/memo.cjs.map +1 -0
  247. package/dist/memo.d.ts +29 -0
  248. package/dist/memo.d.ts.map +1 -0
  249. package/dist/memo.js +18 -0
  250. package/dist/memo.js.map +1 -0
  251. package/dist/nineslice-contract.cjs +60 -0
  252. package/dist/nineslice-contract.cjs.map +1 -0
  253. package/dist/nineslice-contract.d.ts +107 -0
  254. package/dist/nineslice-contract.d.ts.map +1 -0
  255. package/dist/nineslice-contract.js +60 -0
  256. package/dist/nineslice-contract.js.map +1 -0
  257. package/dist/placeholder.cjs +12 -0
  258. package/dist/placeholder.cjs.map +1 -0
  259. package/dist/placeholder.d.ts +44 -0
  260. package/dist/placeholder.d.ts.map +1 -0
  261. package/dist/placeholder.js +12 -0
  262. package/dist/placeholder.js.map +1 -0
  263. package/dist/portal.cjs +89 -0
  264. package/dist/portal.cjs.map +1 -0
  265. package/dist/portal.d.ts +62 -0
  266. package/dist/portal.d.ts.map +1 -0
  267. package/dist/portal.js +89 -0
  268. package/dist/portal.js.map +1 -0
  269. package/dist/primitive-contracts.cjs +12 -0
  270. package/dist/primitive-contracts.cjs.map +1 -0
  271. package/dist/primitive-contracts.d.ts +186 -0
  272. package/dist/primitive-contracts.d.ts.map +1 -0
  273. package/dist/primitive-contracts.js +12 -0
  274. package/dist/primitive-contracts.js.map +1 -0
  275. package/dist/theme.cjs +332 -0
  276. package/dist/theme.cjs.map +1 -0
  277. package/dist/theme.d.ts +204 -0
  278. package/dist/theme.d.ts.map +1 -0
  279. package/dist/theme.js +332 -0
  280. package/dist/theme.js.map +1 -0
  281. package/dist/types.d.ts +86 -0
  282. package/dist/types.d.ts.map +1 -0
  283. package/dist/vdom/create-runtime.cjs +79 -0
  284. package/dist/vdom/create-runtime.cjs.map +1 -0
  285. package/dist/vdom/create-runtime.d.ts +7 -0
  286. package/dist/vdom/create-runtime.d.ts.map +1 -0
  287. package/dist/vdom/create-runtime.js +79 -0
  288. package/dist/vdom/create-runtime.js.map +1 -0
  289. package/dist/vdom/index.cjs +8 -0
  290. package/dist/vdom/index.cjs.map +1 -0
  291. package/dist/vdom/index.d.ts +4 -0
  292. package/dist/vdom/index.d.ts.map +1 -0
  293. package/dist/vdom/index.js +8 -0
  294. package/dist/vdom/index.js.map +1 -0
  295. package/dist/vdom/mount.cjs +161 -0
  296. package/dist/vdom/mount.cjs.map +1 -0
  297. package/dist/vdom/mount.d.ts +6 -0
  298. package/dist/vdom/mount.d.ts.map +1 -0
  299. package/dist/vdom/mount.js +161 -0
  300. package/dist/vdom/mount.js.map +1 -0
  301. package/dist/vdom/patch.cjs +163 -0
  302. package/dist/vdom/patch.cjs.map +1 -0
  303. package/dist/vdom/patch.d.ts +3 -0
  304. package/dist/vdom/patch.d.ts.map +1 -0
  305. package/dist/vdom/patch.js +163 -0
  306. package/dist/vdom/patch.js.map +1 -0
  307. package/dist/vdom/registry.cjs +85 -0
  308. package/dist/vdom/registry.cjs.map +1 -0
  309. package/dist/vdom/registry.d.ts +28 -0
  310. package/dist/vdom/registry.d.ts.map +1 -0
  311. package/dist/vdom/registry.js +85 -0
  312. package/dist/vdom/registry.js.map +1 -0
  313. package/dist/vdom/runtime-helpers.cjs +23 -0
  314. package/dist/vdom/runtime-helpers.cjs.map +1 -0
  315. package/dist/vdom/runtime-helpers.d.ts +8 -0
  316. package/dist/vdom/runtime-helpers.d.ts.map +1 -0
  317. package/dist/vdom/runtime-helpers.js +23 -0
  318. package/dist/vdom/runtime-helpers.js.map +1 -0
  319. package/dist/vdom/surface.cjs +107 -0
  320. package/dist/vdom/surface.cjs.map +1 -0
  321. package/dist/vdom/surface.d.ts +9 -0
  322. package/dist/vdom/surface.d.ts.map +1 -0
  323. package/dist/vdom/surface.js +107 -0
  324. package/dist/vdom/surface.js.map +1 -0
  325. package/dist/vdom/types.d.ts +104 -0
  326. package/dist/vdom/types.d.ts.map +1 -0
  327. package/dist/vdom/utils.cjs +146 -0
  328. package/dist/vdom/utils.cjs.map +1 -0
  329. package/dist/vdom/utils.d.ts +24 -0
  330. package/dist/vdom/utils.d.ts.map +1 -0
  331. package/dist/vdom/utils.js +146 -0
  332. package/dist/vdom/utils.js.map +1 -0
  333. package/dist/vdom.d.ts +4 -0
  334. package/dist/vdom.d.ts.map +1 -0
  335. package/dist/vector-draw-context.d.ts +63 -0
  336. package/dist/vector-draw-context.d.ts.map +1 -0
  337. package/package.json +161 -0
  338. package/vdom/index.cjs +1 -0
  339. package/vdom/index.d.ts +1 -0
  340. package/vdom/index.js +1 -0
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const colorTypes = require("./color-types.cjs");
4
+ function hexToNumber(hex) {
5
+ const cleaned = hex.replace("#", "");
6
+ return parseInt(cleaned, 16);
7
+ }
8
+ function numberToHex(num, withHash = true) {
9
+ const hex = normalizeColorNumber(num).toString(16).padStart(6, "0");
10
+ return withHash ? `#${hex}` : hex;
11
+ }
12
+ function normalizeColorNumber(color) {
13
+ if (!Number.isFinite(color)) return 0;
14
+ return Math.max(0, Math.round(color)) & 16777215;
15
+ }
16
+ function normalizeTextColor(color) {
17
+ if (color === void 0 || color === null) return void 0;
18
+ if (typeof color === "number") {
19
+ return numberToHex(normalizeColorNumber(color));
20
+ }
21
+ const trimmed = color.trim();
22
+ if (trimmed === "") return void 0;
23
+ if (/^0x[0-9a-fA-F]+$/.test(trimmed)) {
24
+ const num = parseInt(trimmed.slice(2), 16);
25
+ if (Number.isNaN(num)) return void 0;
26
+ return numberToHex(normalizeColorNumber(num));
27
+ }
28
+ if (/^#[0-9a-fA-F]{3}$/.test(trimmed)) {
29
+ const r = trimmed[1];
30
+ const g = trimmed[2];
31
+ const b = trimmed[3];
32
+ return `#${r}${r}${g}${g}${b}${b}`;
33
+ }
34
+ return trimmed;
35
+ }
36
+ function rgbToNumber(r, g, b) {
37
+ return (r & 255) << 16 | (g & 255) << 8 | b & 255;
38
+ }
39
+ function numberToRgb(num) {
40
+ const normalized = normalizeColorNumber(num);
41
+ return {
42
+ r: normalized >> 16 & 255,
43
+ g: normalized >> 8 & 255,
44
+ b: normalized & 255
45
+ };
46
+ }
47
+ function rgbToHsl(r, g, b) {
48
+ const red = r / 255;
49
+ const green = g / 255;
50
+ const blue = b / 255;
51
+ const max = Math.max(red, green, blue);
52
+ const min = Math.min(red, green, blue);
53
+ const delta = max - min;
54
+ const light = (max + min) / 2;
55
+ if (delta === 0) {
56
+ return { h: 0, s: 0, l: light };
57
+ }
58
+ const saturationValue = light > 0.5 ? delta / (2 - max - min) : delta / (max + min);
59
+ let hueValue;
60
+ if (max === red) {
61
+ hueValue = (green - blue) / delta + (green < blue ? 6 : 0);
62
+ } else if (max === green) {
63
+ hueValue = (blue - red) / delta + 2;
64
+ } else {
65
+ hueValue = (red - green) / delta + 4;
66
+ }
67
+ return { h: hueValue / 6, s: saturationValue, l: light };
68
+ }
69
+ function hslToRgb(h, s, l) {
70
+ const hue = ((Number.isFinite(h) ? h : 0) % 1 + 1) % 1;
71
+ const saturation = Math.max(0, Math.min(1, Number.isFinite(s) ? s : 0));
72
+ const lightness = Math.max(0, Math.min(1, Number.isFinite(l) ? l : 0));
73
+ if (saturation === 0) {
74
+ const value = Math.round(lightness * 255);
75
+ return { r: value, g: value, b: value };
76
+ }
77
+ const hueToRgb = (p2, q2, t) => {
78
+ let next = t;
79
+ if (next < 0) next += 1;
80
+ if (next > 1) next -= 1;
81
+ if (next < 1 / 6) return p2 + (q2 - p2) * 6 * next;
82
+ if (next < 1 / 2) return q2;
83
+ if (next < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - next) * 6;
84
+ return p2;
85
+ };
86
+ const q = lightness < 0.5 ? lightness * (1 + saturation) : lightness + saturation - lightness * saturation;
87
+ const p = 2 * lightness - q;
88
+ return {
89
+ r: Math.round(hueToRgb(p, q, hue + 1 / 3) * 255),
90
+ g: Math.round(hueToRgb(p, q, hue) * 255),
91
+ b: Math.round(hueToRgb(p, q, hue - 1 / 3) * 255)
92
+ };
93
+ }
94
+ function hslToNumber(h, s, l) {
95
+ const rgb = hslToRgb(h, s, l);
96
+ return rgbToNumber(rgb.r, rgb.g, rgb.b);
97
+ }
98
+ function numberToHsl(color) {
99
+ const rgb = numberToRgb(color);
100
+ return rgbToHsl(rgb.r, rgb.g, rgb.b);
101
+ }
102
+ function lighten(color, amount) {
103
+ const rgb = numberToRgb(color);
104
+ const factor = Math.max(0, Math.min(1, amount));
105
+ const r = Math.round(rgb.r + (255 - rgb.r) * factor);
106
+ const g = Math.round(rgb.g + (255 - rgb.g) * factor);
107
+ const b = Math.round(rgb.b + (255 - rgb.b) * factor);
108
+ return rgbToNumber(r, g, b);
109
+ }
110
+ function darken(color, amount) {
111
+ const rgb = numberToRgb(color);
112
+ const factor = 1 - Math.max(0, Math.min(1, amount));
113
+ const r = Math.round(rgb.r * factor);
114
+ const g = Math.round(rgb.g * factor);
115
+ const b = Math.round(rgb.b * factor);
116
+ return rgbToNumber(r, g, b);
117
+ }
118
+ function lightenHex(hex, amount) {
119
+ const num = hexToNumber(hex);
120
+ const lightened = lighten(num, amount);
121
+ return colorTypes.HexColor.from(numberToHex(lightened));
122
+ }
123
+ function darkenHex(hex, amount) {
124
+ const num = hexToNumber(hex);
125
+ const darkened = darken(num, amount);
126
+ return colorTypes.HexColor.from(numberToHex(darkened));
127
+ }
128
+ function alpha(color, alphaValue = 1) {
129
+ const rgb = numberToRgb(color);
130
+ const a = Math.max(0, Math.min(1, alphaValue));
131
+ return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${a})`;
132
+ }
133
+ function getLuminance(color) {
134
+ const rgb = numberToRgb(color);
135
+ const rsRGB = rgb.r / 255;
136
+ const gsRGB = rgb.g / 255;
137
+ const bsRGB = rgb.b / 255;
138
+ const r = rsRGB <= 0.03928 ? rsRGB / 12.92 : Math.pow((rsRGB + 0.055) / 1.055, 2.4);
139
+ const g = gsRGB <= 0.03928 ? gsRGB / 12.92 : Math.pow((gsRGB + 0.055) / 1.055, 2.4);
140
+ const b = bsRGB <= 0.03928 ? bsRGB / 12.92 : Math.pow((bsRGB + 0.055) / 1.055, 2.4);
141
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
142
+ }
143
+ function getContrastRatio(foreground, background) {
144
+ const l1 = getLuminance(foreground);
145
+ const l2 = getLuminance(background);
146
+ const lighter = Math.max(l1, l2);
147
+ const darker = Math.min(l1, l2);
148
+ return (lighter + 0.05) / (darker + 0.05);
149
+ }
150
+ function ensureContrast(foreground, background, minRatio = 4.5) {
151
+ if (getContrastRatio(foreground, background) >= minRatio) {
152
+ return foreground;
153
+ }
154
+ const bgLuminance = getLuminance(background);
155
+ const shouldLighten = bgLuminance < 0.5;
156
+ let low = 0;
157
+ let high = 1;
158
+ while (high - low > 0.01) {
159
+ const mid = (low + high) / 2;
160
+ const adjusted = shouldLighten ? lighten(foreground, mid) : darken(foreground, mid);
161
+ if (getContrastRatio(adjusted, background) >= minRatio) {
162
+ high = mid;
163
+ } else {
164
+ low = mid;
165
+ }
166
+ }
167
+ return shouldLighten ? lighten(foreground, high) : darken(foreground, high);
168
+ }
169
+ function createTextStyle(baseStyle, overrides) {
170
+ const base = baseStyle ?? {};
171
+ return {
172
+ fontSize: overrides.fontSize ?? base.fontSize ?? "14px",
173
+ color: overrides.color ?? base.color ?? "#ffffff",
174
+ ...base.fontFamily && { fontFamily: base.fontFamily },
175
+ ...base.align && { align: base.align },
176
+ ...overrides
177
+ };
178
+ }
179
+ exports.alpha = alpha;
180
+ exports.createTextStyle = createTextStyle;
181
+ exports.darken = darken;
182
+ exports.darkenHex = darkenHex;
183
+ exports.ensureContrast = ensureContrast;
184
+ exports.getContrastRatio = getContrastRatio;
185
+ exports.hexToNumber = hexToNumber;
186
+ exports.hslToNumber = hslToNumber;
187
+ exports.hslToRgb = hslToRgb;
188
+ exports.lighten = lighten;
189
+ exports.lightenHex = lightenHex;
190
+ exports.normalizeColorNumber = normalizeColorNumber;
191
+ exports.normalizeTextColor = normalizeTextColor;
192
+ exports.numberToHex = numberToHex;
193
+ exports.numberToHsl = numberToHsl;
194
+ exports.numberToRgb = numberToRgb;
195
+ exports.rgbToHsl = rgbToHsl;
196
+ exports.rgbToNumber = rgbToNumber;
197
+ //# sourceMappingURL=color-utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-utils.cjs","sources":["../../src/colors/color-utils.ts"],"sourcesContent":["/**\n * Color utility functions — renderer-neutral color math.\n * Provides conversion between formats and color manipulation.\n */\n\nimport type { TextStyleToken } from '../design-tokens/design-token-types'\nimport { HexColor, type RGBColor } from './color-types'\n\n/**\n * Convert hex string to Phaser number format\n * @param hex - Hex color string (e.g., '#ffffff' or 'ffffff')\n * @returns Phaser color number (e.g., 0xffffff)\n * @example\n * ```typescript\n * hexToNumber('#ff0000') // returns 0xff0000\n * hexToNumber('00ff00') // returns 0x00ff00\n * ```\n */\nexport function hexToNumber(hex: string): number {\n const cleaned = hex.replace('#', '')\n return parseInt(cleaned, 16)\n}\n\n/**\n * Convert Phaser number format to hex string\n * @param num - Phaser color number (e.g., 0xffffff)\n * @param withHash - Include '#' prefix (default: true)\n * @returns Hex color string (e.g., '#ffffff')\n * @example\n * ```typescript\n * numberToHex(0xff0000) // returns '#ff0000'\n * numberToHex(0x00ff00, false) // returns '00ff00'\n * ```\n */\nexport function numberToHex(num: number, withHash = true): string {\n const hex = normalizeColorNumber(num).toString(16).padStart(6, '0')\n return withHash ? `#${hex}` : hex\n}\n\n/**\n * Normalize a color number to Phaser's 0x000000-0xffffff RGB range.\n * @param color - Color number to normalize\n * @returns RGB color number in the 24-bit range\n */\nexport function normalizeColorNumber(color: number): number {\n if (!Number.isFinite(color)) return 0x000000\n return Math.max(0, Math.round(color)) & 0xffffff\n}\n\n/**\n * Normalize a text color value to a CSS-compatible hex string.\n *\n * Handles all common formats users might pass in JSX style.color:\n * - `0xff0000` (number) → `'#ff0000'`\n * - `'0xff0000'` (0x-prefixed string) → `'#ff0000'`\n * - `'0xf00'` (0x short string) → `'#ff0000'`\n * - `'#f00'` (short CSS hex) → `'#ff0000'`\n * - `'#ff0000'` (full CSS hex) → `'#ff0000'` (passthrough)\n * - `'red'`, `'yellow'` (CSS name) → passthrough unchanged\n * - `undefined` → `undefined`\n *\n * Both renderers (Phaser, Pixi) receive the same normalized value,\n * preventing inconsistent color rendering across renderers.\n *\n * @param color - Raw color value from style.color\n * @returns Normalized CSS hex string, CSS name, or undefined\n */\nexport function normalizeTextColor(color: string | number | undefined): string | undefined {\n if (color === undefined || color === null) return undefined\n\n // Number: convert to #rrggbb\n if (typeof color === 'number') {\n return numberToHex(normalizeColorNumber(color))\n }\n\n // String: detect and normalize 0x-prefixed hex strings\n const trimmed = color.trim()\n if (trimmed === '') return undefined\n\n // '0xf00' or '0xff0000' → parse as hex, convert to #rrggbb\n if (/^0x[0-9a-fA-F]+$/.test(trimmed)) {\n const num = parseInt(trimmed.slice(2), 16)\n if (Number.isNaN(num)) return undefined\n return numberToHex(normalizeColorNumber(num))\n }\n\n // '#f00' → '#ff0000' (expand short CSS hex)\n if (/^#[0-9a-fA-F]{3}$/.test(trimmed)) {\n const r = trimmed[1]\n const g = trimmed[2]\n const b = trimmed[3]\n return `#${r}${r}${g}${g}${b}${b}`\n }\n\n // Already clean '#ff0000' or CSS name like 'red' — passthrough\n return trimmed\n}\n\n/**\n * Convert RGB values to Phaser number format\n * @param r - Red component (0-255)\n * @param g - Green component (0-255)\n * @param b - Blue component (0-255)\n * @returns Phaser color number\n * @example\n * ```typescript\n * rgbToNumber(255, 0, 0) // returns 0xff0000 (red)\n * rgbToNumber(0, 255, 0) // returns 0x00ff00 (green)\n * rgbToNumber(255, 255, 255) // returns 0xffffff (white)\n * ```\n */\nexport function rgbToNumber(r: number, g: number, b: number): number {\n return ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)\n}\n\n/**\n * Convert Phaser number to RGB components\n * @param num - Phaser color number\n * @returns RGB color object\n * @example\n * ```typescript\n * numberToRgb(0xff0000) // returns { r: 255, g: 0, b: 0 }\n * numberToRgb(0x00ff00) // returns { r: 0, g: 255, b: 0 }\n * ```\n */\nexport function numberToRgb(num: number): RGBColor {\n const normalized = normalizeColorNumber(num)\n\n return {\n r: (normalized >> 16) & 0xff,\n g: (normalized >> 8) & 0xff,\n b: normalized & 0xff,\n }\n}\n\n/**\n * HSL color representation\n */\nexport interface HSLColor {\n /** Hue in normalized range (0.0 to 1.0) */\n h: number\n /** Saturation in normalized range (0.0 to 1.0) */\n s: number\n /** Lightness in normalized range (0.0 to 1.0) */\n l: number\n}\n\n/**\n * Convert RGB values to HSL values (normalized 0.0 to 1.0)\n * @param r - Red component (0-255)\n * @param g - Green component (0-255)\n * @param b - Blue component (0-255)\n * @returns HSL color values with normalized components\n * @example\n * ```typescript\n * rgbToHsl(255, 0, 0) // returns { h: 0, s: 1, l: 0.5 }\n * rgbToHsl(0, 255, 0) // returns { h: 0.333..., s: 1, l: 0.5 }\n * ```\n */\nexport function rgbToHsl(r: number, g: number, b: number): HSLColor {\n const red = r / 255\n const green = g / 255\n const blue = b / 255\n const max = Math.max(red, green, blue)\n const min = Math.min(red, green, blue)\n const delta = max - min\n const light = (max + min) / 2\n\n if (delta === 0) {\n return { h: 0, s: 0, l: light }\n }\n\n const saturationValue = light > 0.5 ? delta / (2 - max - min) : delta / (max + min)\n let hueValue: number\n if (max === red) {\n hueValue = (green - blue) / delta + (green < blue ? 6 : 0)\n } else if (max === green) {\n hueValue = (blue - red) / delta + 2\n } else {\n hueValue = (red - green) / delta + 4\n }\n return { h: hueValue / 6, s: saturationValue, l: light }\n}\n\n/**\n * Convert normalized HSL values to RGB components.\n * @param h - Hue in normalized range (0.0 to 1.0)\n * @param s - Saturation in normalized range (0.0 to 1.0)\n * @param l - Lightness in normalized range (0.0 to 1.0)\n * @returns RGB color object\n */\nexport function hslToRgb(h: number, s: number, l: number): RGBColor {\n const hue = (((Number.isFinite(h) ? h : 0) % 1) + 1) % 1\n const saturation = Math.max(0, Math.min(1, Number.isFinite(s) ? s : 0))\n const lightness = Math.max(0, Math.min(1, Number.isFinite(l) ? l : 0))\n\n if (saturation === 0) {\n const value = Math.round(lightness * 255)\n return { r: value, g: value, b: value }\n }\n\n const hueToRgb = (p: number, q: number, t: number): number => {\n let next = t\n if (next < 0) next += 1\n if (next > 1) next -= 1\n if (next < 1 / 6) return p + (q - p) * 6 * next\n if (next < 1 / 2) return q\n if (next < 2 / 3) return p + (q - p) * (2 / 3 - next) * 6\n return p\n }\n\n const q =\n lightness < 0.5 ? lightness * (1 + saturation) : lightness + saturation - lightness * saturation\n const p = 2 * lightness - q\n\n return {\n r: Math.round(hueToRgb(p, q, hue + 1 / 3) * 255),\n g: Math.round(hueToRgb(p, q, hue) * 255),\n b: Math.round(hueToRgb(p, q, hue - 1 / 3) * 255),\n }\n}\n\n/**\n * Convert normalized HSL values to Phaser number format.\n * @param h - Hue in normalized range (0.0 to 1.0)\n * @param s - Saturation in normalized range (0.0 to 1.0)\n * @param l - Lightness in normalized range (0.0 to 1.0)\n * @returns Phaser color number\n */\nexport function hslToNumber(h: number, s: number, l: number): number {\n const rgb = hslToRgb(h, s, l)\n return rgbToNumber(rgb.r, rgb.g, rgb.b)\n}\n\n/**\n * Convert Phaser number format to normalized HSL values.\n * @param color - Phaser color number\n * @returns HSL color values with normalized components\n */\nexport function numberToHsl(color: number): HSLColor {\n const rgb = numberToRgb(color)\n return rgbToHsl(rgb.r, rgb.g, rgb.b)\n}\n\n/**\n * Lighten a color by a given amount\n * @param color - Phaser color number\n * @param amount - Amount to lighten (0.0 to 1.0, where 1.0 is white)\n * @returns Lightened color number\n * @example\n * ```typescript\n * lighten(0x0000ff, 0.3) // returns lighter blue\n * lighten(0xff0000, 0.5) // returns light red/pink\n * ```\n */\nexport function lighten(color: number, amount: number): number {\n const rgb = numberToRgb(color)\n const factor = Math.max(0, Math.min(1, amount))\n\n const r = Math.round(rgb.r + (255 - rgb.r) * factor)\n const g = Math.round(rgb.g + (255 - rgb.g) * factor)\n const b = Math.round(rgb.b + (255 - rgb.b) * factor)\n\n return rgbToNumber(r, g, b)\n}\n\n/**\n * Darken a color by a given amount\n * @param color - Phaser color number\n * @param amount - Amount to darken (0.0 to 1.0, where 1.0 is black)\n * @returns Darkened color number\n * @example\n * ```typescript\n * darken(0x0000ff, 0.3) // returns darker blue\n * darken(0xff0000, 0.5) // returns dark red\n * ```\n */\nexport function darken(color: number, amount: number): number {\n const rgb = numberToRgb(color)\n const factor = 1 - Math.max(0, Math.min(1, amount))\n\n const r = Math.round(rgb.r * factor)\n const g = Math.round(rgb.g * factor)\n const b = Math.round(rgb.b * factor)\n\n return rgbToNumber(r, g, b)\n}\n\n/**\n * Lighten a hex color by a given amount\n * @param hex - Hex color (e.g., '#ffffff' or 'ffffff')\n * @param amount - Amount to lighten (0.0 to 1.0, where 1.0 is white)\n * @returns Lightened hex color string with '#' prefix\n * @example\n * ```typescript\n * lightenHex('#0000ff', 0.3) // returns lighter blue\n * lightenHex('#ff0000', 0.5) // returns light red/pink\n * ```\n */\nexport function lightenHex(hex: string, amount: number): HexColor {\n const num = hexToNumber(hex)\n const lightened = lighten(num, amount)\n return HexColor.from(numberToHex(lightened))\n}\n\n/**\n * Darken a hex color by a given amount\n * @param hex - Hex color (e.g., '#ffffff' or 'ffffff')\n * @param amount - Amount to darken (0.0 to 1.0, where 1.0 is black)\n * @returns Darkened hex color string with '#' prefix\n * @example\n * ```typescript\n * darkenHex('#0000ff', 0.3) // returns darker blue\n * darkenHex('#ff0000', 0.5) // returns dark red\n * ```\n */\nexport function darkenHex(hex: string, amount: number): HexColor {\n const num = hexToNumber(hex)\n const darkened = darken(num, amount)\n return HexColor.from(numberToHex(darkened))\n}\n\n/**\n * Convert color to rgba string for Phaser Text style\n * @param color - Phaser color number\n * @param alphaValue - Alpha value (0.0 to 1.0, default: 1.0)\n * @returns RGBA string usable in Text style (e.g., 'rgba(255, 0, 0, 0.5)')\n * @example\n * ```typescript\n * alpha(0xff0000, 1.0) // returns 'rgba(255, 0, 0, 1)'\n * alpha(0x00ff00, 0.5) // returns 'rgba(0, 255, 0, 0.5)'\n * alpha(0x0000ff) // returns 'rgba(0, 0, 255, 1)'\n * ```\n */\nexport function alpha(color: number, alphaValue = 1.0): string {\n const rgb = numberToRgb(color)\n const a = Math.max(0, Math.min(1, alphaValue))\n return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${a})`\n}\n\n/**\n * Calculate relative luminance of a color (WCAG formula)\n * @param color - Phaser color number\n * @returns Relative luminance (0.0 to 1.0)\n */\nfunction getLuminance(color: number): number {\n const rgb = numberToRgb(color)\n\n // Convert to sRGB\n const rsRGB = rgb.r / 255\n const gsRGB = rgb.g / 255\n const bsRGB = rgb.b / 255\n\n // Apply gamma correction\n const r = rsRGB <= 0.03928 ? rsRGB / 12.92 : Math.pow((rsRGB + 0.055) / 1.055, 2.4)\n const g = gsRGB <= 0.03928 ? gsRGB / 12.92 : Math.pow((gsRGB + 0.055) / 1.055, 2.4)\n const b = bsRGB <= 0.03928 ? bsRGB / 12.92 : Math.pow((bsRGB + 0.055) / 1.055, 2.4)\n\n // Calculate luminance\n return 0.2126 * r + 0.7152 * g + 0.0722 * b\n}\n\n/**\n * Calculate contrast ratio between two colors (WCAG 2.0)\n * @param foreground - Foreground color (e.g., text)\n * @param background - Background color\n * @returns Contrast ratio (1 to 21)\n * @example\n * ```typescript\n * getContrastRatio(0x000000, 0xffffff) // returns 21 (black on white)\n * getContrastRatio(0xffffff, 0xffffff) // returns 1 (white on white)\n * ```\n */\nexport function getContrastRatio(foreground: number, background: number): number {\n const l1 = getLuminance(foreground)\n const l2 = getLuminance(background)\n\n const lighter = Math.max(l1, l2)\n const darker = Math.min(l1, l2)\n\n return (lighter + 0.05) / (darker + 0.05)\n}\n\n/**\n * Ensure minimum contrast ratio by adjusting foreground color\n * Uses binary search for efficiency (O(log n) vs O(n))\n * @param foreground - Foreground color to adjust\n * @param background - Background color (fixed)\n * @param minRatio - Minimum contrast ratio (default: 4.5 for WCAG AA)\n * @returns Adjusted foreground color meeting contrast requirements\n * @example\n * ```typescript\n * // Ensure text is readable on background\n * const textColor = ensureContrast(0x888888, 0xffffff, 4.5)\n * ```\n */\nexport function ensureContrast(foreground: number, background: number, minRatio = 4.5): number {\n // If contrast is already sufficient, return original\n if (getContrastRatio(foreground, background) >= minRatio) {\n return foreground\n }\n\n // Determine if we should lighten or darken\n const bgLuminance = getLuminance(background)\n const shouldLighten = bgLuminance < 0.5\n\n // Binary search for the minimal adjustment needed\n let low = 0\n let high = 1\n\n while (high - low > 0.01) {\n const mid = (low + high) / 2\n const adjusted = shouldLighten ? lighten(foreground, mid) : darken(foreground, mid)\n\n if (getContrastRatio(adjusted, background) >= minRatio) {\n high = mid\n } else {\n low = mid\n }\n }\n\n return shouldLighten ? lighten(foreground, high) : darken(foreground, high)\n}\n\n/**\n * Create a TextStyleToken by merging base style with overrides to ensure required properties are set\n * @param baseStyle\n * @param overrides\n * @returns\n */\nexport function createTextStyle(\n baseStyle: Partial<TextStyleToken> | undefined,\n overrides: Partial<TextStyleToken>\n): TextStyleToken {\n const base = baseStyle ?? {}\n return {\n fontSize: overrides.fontSize ?? base.fontSize ?? '14px',\n color: overrides.color ?? base.color ?? '#ffffff',\n ...(base.fontFamily && { fontFamily: base.fontFamily }),\n ...(base.align && { align: base.align }),\n ...overrides,\n }\n}\n"],"names":["p","q","HexColor"],"mappings":";;;AAkBO,SAAS,YAAY,KAAqB;AAC/C,QAAM,UAAU,IAAI,QAAQ,KAAK,EAAE;AACnC,SAAO,SAAS,SAAS,EAAE;AAC7B;AAaO,SAAS,YAAY,KAAa,WAAW,MAAc;AAChE,QAAM,MAAM,qBAAqB,GAAG,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAClE,SAAO,WAAW,IAAI,GAAG,KAAK;AAChC;AAOO,SAAS,qBAAqB,OAAuB;AAC1D,MAAI,CAAC,OAAO,SAAS,KAAK,EAAG,QAAO;AACpC,SAAO,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC,IAAI;AAC1C;AAoBO,SAAS,mBAAmB,OAAwD;AACzF,MAAI,UAAU,UAAa,UAAU,KAAM,QAAO;AAGlD,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,YAAY,qBAAqB,KAAK,CAAC;AAAA,EAChD;AAGA,QAAM,UAAU,MAAM,KAAA;AACtB,MAAI,YAAY,GAAI,QAAO;AAG3B,MAAI,mBAAmB,KAAK,OAAO,GAAG;AACpC,UAAM,MAAM,SAAS,QAAQ,MAAM,CAAC,GAAG,EAAE;AACzC,QAAI,OAAO,MAAM,GAAG,EAAG,QAAO;AAC9B,WAAO,YAAY,qBAAqB,GAAG,CAAC;AAAA,EAC9C;AAGA,MAAI,oBAAoB,KAAK,OAAO,GAAG;AACrC,UAAM,IAAI,QAAQ,CAAC;AACnB,UAAM,IAAI,QAAQ,CAAC;AACnB,UAAM,IAAI,QAAQ,CAAC;AACnB,WAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;AAAA,EAClC;AAGA,SAAO;AACT;AAeO,SAAS,YAAY,GAAW,GAAW,GAAmB;AACnE,UAAS,IAAI,Q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AAS,EAAE,OAAO,KAAK,MAAA;AAAA,IAChC,GAAG;AAAA,EAAA;AAEP;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,216 @@
1
+ import { TextStyleToken } from '../design-tokens/design-token-types';
2
+ import { HexColor, RGBColor } from './color-types';
3
+ /**
4
+ * Convert hex string to Phaser number format
5
+ * @param hex - Hex color string (e.g., '#ffffff' or 'ffffff')
6
+ * @returns Phaser color number (e.g., 0xffffff)
7
+ * @example
8
+ * ```typescript
9
+ * hexToNumber('#ff0000') // returns 0xff0000
10
+ * hexToNumber('00ff00') // returns 0x00ff00
11
+ * ```
12
+ */
13
+ export declare function hexToNumber(hex: string): number;
14
+ /**
15
+ * Convert Phaser number format to hex string
16
+ * @param num - Phaser color number (e.g., 0xffffff)
17
+ * @param withHash - Include '#' prefix (default: true)
18
+ * @returns Hex color string (e.g., '#ffffff')
19
+ * @example
20
+ * ```typescript
21
+ * numberToHex(0xff0000) // returns '#ff0000'
22
+ * numberToHex(0x00ff00, false) // returns '00ff00'
23
+ * ```
24
+ */
25
+ export declare function numberToHex(num: number, withHash?: boolean): string;
26
+ /**
27
+ * Normalize a color number to Phaser's 0x000000-0xffffff RGB range.
28
+ * @param color - Color number to normalize
29
+ * @returns RGB color number in the 24-bit range
30
+ */
31
+ export declare function normalizeColorNumber(color: number): number;
32
+ /**
33
+ * Normalize a text color value to a CSS-compatible hex string.
34
+ *
35
+ * Handles all common formats users might pass in JSX style.color:
36
+ * - `0xff0000` (number) → `'#ff0000'`
37
+ * - `'0xff0000'` (0x-prefixed string) → `'#ff0000'`
38
+ * - `'0xf00'` (0x short string) → `'#ff0000'`
39
+ * - `'#f00'` (short CSS hex) → `'#ff0000'`
40
+ * - `'#ff0000'` (full CSS hex) → `'#ff0000'` (passthrough)
41
+ * - `'red'`, `'yellow'` (CSS name) → passthrough unchanged
42
+ * - `undefined` → `undefined`
43
+ *
44
+ * Both renderers (Phaser, Pixi) receive the same normalized value,
45
+ * preventing inconsistent color rendering across renderers.
46
+ *
47
+ * @param color - Raw color value from style.color
48
+ * @returns Normalized CSS hex string, CSS name, or undefined
49
+ */
50
+ export declare function normalizeTextColor(color: string | number | undefined): string | undefined;
51
+ /**
52
+ * Convert RGB values to Phaser number format
53
+ * @param r - Red component (0-255)
54
+ * @param g - Green component (0-255)
55
+ * @param b - Blue component (0-255)
56
+ * @returns Phaser color number
57
+ * @example
58
+ * ```typescript
59
+ * rgbToNumber(255, 0, 0) // returns 0xff0000 (red)
60
+ * rgbToNumber(0, 255, 0) // returns 0x00ff00 (green)
61
+ * rgbToNumber(255, 255, 255) // returns 0xffffff (white)
62
+ * ```
63
+ */
64
+ export declare function rgbToNumber(r: number, g: number, b: number): number;
65
+ /**
66
+ * Convert Phaser number to RGB components
67
+ * @param num - Phaser color number
68
+ * @returns RGB color object
69
+ * @example
70
+ * ```typescript
71
+ * numberToRgb(0xff0000) // returns { r: 255, g: 0, b: 0 }
72
+ * numberToRgb(0x00ff00) // returns { r: 0, g: 255, b: 0 }
73
+ * ```
74
+ */
75
+ export declare function numberToRgb(num: number): RGBColor;
76
+ /**
77
+ * HSL color representation
78
+ */
79
+ export interface HSLColor {
80
+ /** Hue in normalized range (0.0 to 1.0) */
81
+ h: number;
82
+ /** Saturation in normalized range (0.0 to 1.0) */
83
+ s: number;
84
+ /** Lightness in normalized range (0.0 to 1.0) */
85
+ l: number;
86
+ }
87
+ /**
88
+ * Convert RGB values to HSL values (normalized 0.0 to 1.0)
89
+ * @param r - Red component (0-255)
90
+ * @param g - Green component (0-255)
91
+ * @param b - Blue component (0-255)
92
+ * @returns HSL color values with normalized components
93
+ * @example
94
+ * ```typescript
95
+ * rgbToHsl(255, 0, 0) // returns { h: 0, s: 1, l: 0.5 }
96
+ * rgbToHsl(0, 255, 0) // returns { h: 0.333..., s: 1, l: 0.5 }
97
+ * ```
98
+ */
99
+ export declare function rgbToHsl(r: number, g: number, b: number): HSLColor;
100
+ /**
101
+ * Convert normalized HSL values to RGB components.
102
+ * @param h - Hue in normalized range (0.0 to 1.0)
103
+ * @param s - Saturation in normalized range (0.0 to 1.0)
104
+ * @param l - Lightness in normalized range (0.0 to 1.0)
105
+ * @returns RGB color object
106
+ */
107
+ export declare function hslToRgb(h: number, s: number, l: number): RGBColor;
108
+ /**
109
+ * Convert normalized HSL values to Phaser number format.
110
+ * @param h - Hue in normalized range (0.0 to 1.0)
111
+ * @param s - Saturation in normalized range (0.0 to 1.0)
112
+ * @param l - Lightness in normalized range (0.0 to 1.0)
113
+ * @returns Phaser color number
114
+ */
115
+ export declare function hslToNumber(h: number, s: number, l: number): number;
116
+ /**
117
+ * Convert Phaser number format to normalized HSL values.
118
+ * @param color - Phaser color number
119
+ * @returns HSL color values with normalized components
120
+ */
121
+ export declare function numberToHsl(color: number): HSLColor;
122
+ /**
123
+ * Lighten a color by a given amount
124
+ * @param color - Phaser color number
125
+ * @param amount - Amount to lighten (0.0 to 1.0, where 1.0 is white)
126
+ * @returns Lightened color number
127
+ * @example
128
+ * ```typescript
129
+ * lighten(0x0000ff, 0.3) // returns lighter blue
130
+ * lighten(0xff0000, 0.5) // returns light red/pink
131
+ * ```
132
+ */
133
+ export declare function lighten(color: number, amount: number): number;
134
+ /**
135
+ * Darken a color by a given amount
136
+ * @param color - Phaser color number
137
+ * @param amount - Amount to darken (0.0 to 1.0, where 1.0 is black)
138
+ * @returns Darkened color number
139
+ * @example
140
+ * ```typescript
141
+ * darken(0x0000ff, 0.3) // returns darker blue
142
+ * darken(0xff0000, 0.5) // returns dark red
143
+ * ```
144
+ */
145
+ export declare function darken(color: number, amount: number): number;
146
+ /**
147
+ * Lighten a hex color by a given amount
148
+ * @param hex - Hex color (e.g., '#ffffff' or 'ffffff')
149
+ * @param amount - Amount to lighten (0.0 to 1.0, where 1.0 is white)
150
+ * @returns Lightened hex color string with '#' prefix
151
+ * @example
152
+ * ```typescript
153
+ * lightenHex('#0000ff', 0.3) // returns lighter blue
154
+ * lightenHex('#ff0000', 0.5) // returns light red/pink
155
+ * ```
156
+ */
157
+ export declare function lightenHex(hex: string, amount: number): HexColor;
158
+ /**
159
+ * Darken a hex color by a given amount
160
+ * @param hex - Hex color (e.g., '#ffffff' or 'ffffff')
161
+ * @param amount - Amount to darken (0.0 to 1.0, where 1.0 is black)
162
+ * @returns Darkened hex color string with '#' prefix
163
+ * @example
164
+ * ```typescript
165
+ * darkenHex('#0000ff', 0.3) // returns darker blue
166
+ * darkenHex('#ff0000', 0.5) // returns dark red
167
+ * ```
168
+ */
169
+ export declare function darkenHex(hex: string, amount: number): HexColor;
170
+ /**
171
+ * Convert color to rgba string for Phaser Text style
172
+ * @param color - Phaser color number
173
+ * @param alphaValue - Alpha value (0.0 to 1.0, default: 1.0)
174
+ * @returns RGBA string usable in Text style (e.g., 'rgba(255, 0, 0, 0.5)')
175
+ * @example
176
+ * ```typescript
177
+ * alpha(0xff0000, 1.0) // returns 'rgba(255, 0, 0, 1)'
178
+ * alpha(0x00ff00, 0.5) // returns 'rgba(0, 255, 0, 0.5)'
179
+ * alpha(0x0000ff) // returns 'rgba(0, 0, 255, 1)'
180
+ * ```
181
+ */
182
+ export declare function alpha(color: number, alphaValue?: number): string;
183
+ /**
184
+ * Calculate contrast ratio between two colors (WCAG 2.0)
185
+ * @param foreground - Foreground color (e.g., text)
186
+ * @param background - Background color
187
+ * @returns Contrast ratio (1 to 21)
188
+ * @example
189
+ * ```typescript
190
+ * getContrastRatio(0x000000, 0xffffff) // returns 21 (black on white)
191
+ * getContrastRatio(0xffffff, 0xffffff) // returns 1 (white on white)
192
+ * ```
193
+ */
194
+ export declare function getContrastRatio(foreground: number, background: number): number;
195
+ /**
196
+ * Ensure minimum contrast ratio by adjusting foreground color
197
+ * Uses binary search for efficiency (O(log n) vs O(n))
198
+ * @param foreground - Foreground color to adjust
199
+ * @param background - Background color (fixed)
200
+ * @param minRatio - Minimum contrast ratio (default: 4.5 for WCAG AA)
201
+ * @returns Adjusted foreground color meeting contrast requirements
202
+ * @example
203
+ * ```typescript
204
+ * // Ensure text is readable on background
205
+ * const textColor = ensureContrast(0x888888, 0xffffff, 4.5)
206
+ * ```
207
+ */
208
+ export declare function ensureContrast(foreground: number, background: number, minRatio?: number): number;
209
+ /**
210
+ * Create a TextStyleToken by merging base style with overrides to ensure required properties are set
211
+ * @param baseStyle
212
+ * @param overrides
213
+ * @returns
214
+ */
215
+ export declare function createTextStyle(baseStyle: Partial<TextStyleToken> | undefined, overrides: Partial<TextStyleToken>): TextStyleToken;
216
+ //# sourceMappingURL=color-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-utils.d.ts","sourceRoot":"","sources":["../../src/colors/color-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACzE,OAAO,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEvD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,UAAO,GAAG,MAAM,CAGhE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CA6BzF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAQjD;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,2CAA2C;IAC3C,CAA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AQ/E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,SAAM,GAAG,MAAM,CA0B7F;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,SAAS,EAC9C,SAAS,EAAE,OAAO,CAAC,cAAc,CAAC,GACjC,cAAc,CAShB"}
@@ -0,0 +1,197 @@
1
+ import { HexColor } from "./color-types.js";
2
+ function hexToNumber(hex) {
3
+ const cleaned = hex.replace("#", "");
4
+ return parseInt(cleaned, 16);
5
+ }
6
+ function numberToHex(num, withHash = true) {
7
+ const hex = normalizeColorNumber(num).toString(16).padStart(6, "0");
8
+ return withHash ? `#${hex}` : hex;
9
+ }
10
+ function normalizeColorNumber(color) {
11
+ if (!Number.isFinite(color)) return 0;
12
+ return Math.max(0, Math.round(color)) & 16777215;
13
+ }
14
+ function normalizeTextColor(color) {
15
+ if (color === void 0 || color === null) return void 0;
16
+ if (typeof color === "number") {
17
+ return numberToHex(normalizeColorNumber(color));
18
+ }
19
+ const trimmed = color.trim();
20
+ if (trimmed === "") return void 0;
21
+ if (/^0x[0-9a-fA-F]+$/.test(trimmed)) {
22
+ const num = parseInt(trimmed.slice(2), 16);
23
+ if (Number.isNaN(num)) return void 0;
24
+ return numberToHex(normalizeColorNumber(num));
25
+ }
26
+ if (/^#[0-9a-fA-F]{3}$/.test(trimmed)) {
27
+ const r = trimmed[1];
28
+ const g = trimmed[2];
29
+ const b = trimmed[3];
30
+ return `#${r}${r}${g}${g}${b}${b}`;
31
+ }
32
+ return trimmed;
33
+ }
34
+ function rgbToNumber(r, g, b) {
35
+ return (r & 255) << 16 | (g & 255) << 8 | b & 255;
36
+ }
37
+ function numberToRgb(num) {
38
+ const normalized = normalizeColorNumber(num);
39
+ return {
40
+ r: normalized >> 16 & 255,
41
+ g: normalized >> 8 & 255,
42
+ b: normalized & 255
43
+ };
44
+ }
45
+ function rgbToHsl(r, g, b) {
46
+ const red = r / 255;
47
+ const green = g / 255;
48
+ const blue = b / 255;
49
+ const max = Math.max(red, green, blue);
50
+ const min = Math.min(red, green, blue);
51
+ const delta = max - min;
52
+ const light = (max + min) / 2;
53
+ if (delta === 0) {
54
+ return { h: 0, s: 0, l: light };
55
+ }
56
+ const saturationValue = light > 0.5 ? delta / (2 - max - min) : delta / (max + min);
57
+ let hueValue;
58
+ if (max === red) {
59
+ hueValue = (green - blue) / delta + (green < blue ? 6 : 0);
60
+ } else if (max === green) {
61
+ hueValue = (blue - red) / delta + 2;
62
+ } else {
63
+ hueValue = (red - green) / delta + 4;
64
+ }
65
+ return { h: hueValue / 6, s: saturationValue, l: light };
66
+ }
67
+ function hslToRgb(h, s, l) {
68
+ const hue = ((Number.isFinite(h) ? h : 0) % 1 + 1) % 1;
69
+ const saturation = Math.max(0, Math.min(1, Number.isFinite(s) ? s : 0));
70
+ const lightness = Math.max(0, Math.min(1, Number.isFinite(l) ? l : 0));
71
+ if (saturation === 0) {
72
+ const value = Math.round(lightness * 255);
73
+ return { r: value, g: value, b: value };
74
+ }
75
+ const hueToRgb = (p2, q2, t) => {
76
+ let next = t;
77
+ if (next < 0) next += 1;
78
+ if (next > 1) next -= 1;
79
+ if (next < 1 / 6) return p2 + (q2 - p2) * 6 * next;
80
+ if (next < 1 / 2) return q2;
81
+ if (next < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - next) * 6;
82
+ return p2;
83
+ };
84
+ const q = lightness < 0.5 ? lightness * (1 + saturation) : lightness + saturation - lightness * saturation;
85
+ const p = 2 * lightness - q;
86
+ return {
87
+ r: Math.round(hueToRgb(p, q, hue + 1 / 3) * 255),
88
+ g: Math.round(hueToRgb(p, q, hue) * 255),
89
+ b: Math.round(hueToRgb(p, q, hue - 1 / 3) * 255)
90
+ };
91
+ }
92
+ function hslToNumber(h, s, l) {
93
+ const rgb = hslToRgb(h, s, l);
94
+ return rgbToNumber(rgb.r, rgb.g, rgb.b);
95
+ }
96
+ function numberToHsl(color) {
97
+ const rgb = numberToRgb(color);
98
+ return rgbToHsl(rgb.r, rgb.g, rgb.b);
99
+ }
100
+ function lighten(color, amount) {
101
+ const rgb = numberToRgb(color);
102
+ const factor = Math.max(0, Math.min(1, amount));
103
+ const r = Math.round(rgb.r + (255 - rgb.r) * factor);
104
+ const g = Math.round(rgb.g + (255 - rgb.g) * factor);
105
+ const b = Math.round(rgb.b + (255 - rgb.b) * factor);
106
+ return rgbToNumber(r, g, b);
107
+ }
108
+ function darken(color, amount) {
109
+ const rgb = numberToRgb(color);
110
+ const factor = 1 - Math.max(0, Math.min(1, amount));
111
+ const r = Math.round(rgb.r * factor);
112
+ const g = Math.round(rgb.g * factor);
113
+ const b = Math.round(rgb.b * factor);
114
+ return rgbToNumber(r, g, b);
115
+ }
116
+ function lightenHex(hex, amount) {
117
+ const num = hexToNumber(hex);
118
+ const lightened = lighten(num, amount);
119
+ return HexColor.from(numberToHex(lightened));
120
+ }
121
+ function darkenHex(hex, amount) {
122
+ const num = hexToNumber(hex);
123
+ const darkened = darken(num, amount);
124
+ return HexColor.from(numberToHex(darkened));
125
+ }
126
+ function alpha(color, alphaValue = 1) {
127
+ const rgb = numberToRgb(color);
128
+ const a = Math.max(0, Math.min(1, alphaValue));
129
+ return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${a})`;
130
+ }
131
+ function getLuminance(color) {
132
+ const rgb = numberToRgb(color);
133
+ const rsRGB = rgb.r / 255;
134
+ const gsRGB = rgb.g / 255;
135
+ const bsRGB = rgb.b / 255;
136
+ const r = rsRGB <= 0.03928 ? rsRGB / 12.92 : Math.pow((rsRGB + 0.055) / 1.055, 2.4);
137
+ const g = gsRGB <= 0.03928 ? gsRGB / 12.92 : Math.pow((gsRGB + 0.055) / 1.055, 2.4);
138
+ const b = bsRGB <= 0.03928 ? bsRGB / 12.92 : Math.pow((bsRGB + 0.055) / 1.055, 2.4);
139
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
140
+ }
141
+ function getContrastRatio(foreground, background) {
142
+ const l1 = getLuminance(foreground);
143
+ const l2 = getLuminance(background);
144
+ const lighter = Math.max(l1, l2);
145
+ const darker = Math.min(l1, l2);
146
+ return (lighter + 0.05) / (darker + 0.05);
147
+ }
148
+ function ensureContrast(foreground, background, minRatio = 4.5) {
149
+ if (getContrastRatio(foreground, background) >= minRatio) {
150
+ return foreground;
151
+ }
152
+ const bgLuminance = getLuminance(background);
153
+ const shouldLighten = bgLuminance < 0.5;
154
+ let low = 0;
155
+ let high = 1;
156
+ while (high - low > 0.01) {
157
+ const mid = (low + high) / 2;
158
+ const adjusted = shouldLighten ? lighten(foreground, mid) : darken(foreground, mid);
159
+ if (getContrastRatio(adjusted, background) >= minRatio) {
160
+ high = mid;
161
+ } else {
162
+ low = mid;
163
+ }
164
+ }
165
+ return shouldLighten ? lighten(foreground, high) : darken(foreground, high);
166
+ }
167
+ function createTextStyle(baseStyle, overrides) {
168
+ const base = baseStyle ?? {};
169
+ return {
170
+ fontSize: overrides.fontSize ?? base.fontSize ?? "14px",
171
+ color: overrides.color ?? base.color ?? "#ffffff",
172
+ ...base.fontFamily && { fontFamily: base.fontFamily },
173
+ ...base.align && { align: base.align },
174
+ ...overrides
175
+ };
176
+ }
177
+ export {
178
+ alpha,
179
+ createTextStyle,
180
+ darken,
181
+ darkenHex,
182
+ ensureContrast,
183
+ getContrastRatio,
184
+ hexToNumber,
185
+ hslToNumber,
186
+ hslToRgb,
187
+ lighten,
188
+ lightenHex,
189
+ normalizeColorNumber,
190
+ normalizeTextColor,
191
+ numberToHex,
192
+ numberToHsl,
193
+ numberToRgb,
194
+ rgbToHsl,
195
+ rgbToNumber
196
+ };
197
+ //# sourceMappingURL=color-utils.js.map