@x-plat/design-system 0.20.0 → 0.21.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 (292) hide show
  1. package/dist/chunk-2EGVOUGV.cjs +93 -0
  2. package/dist/chunk-2T3BVV7R.js +0 -0
  3. package/dist/chunk-3FYYFDKQ.js +159 -0
  4. package/dist/chunk-3M3GFSHJ.js +67 -0
  5. package/dist/chunk-3WBHUFOA.cjs +48 -0
  6. package/dist/chunk-3XYYZQR5.cjs +22 -0
  7. package/dist/chunk-4EF7NVAL.js +67 -0
  8. package/dist/chunk-4ISERXK2.cjs +1 -0
  9. package/dist/chunk-4KYHHJ6Z.cjs +250 -0
  10. package/dist/chunk-4NSRDRXC.cjs +70 -0
  11. package/dist/chunk-4OXMRSVE.cjs +99 -0
  12. package/dist/chunk-55EPYLXN.js +30 -0
  13. package/dist/chunk-5CE3ADO5.js +254 -0
  14. package/dist/chunk-5F6Y2JD6.cjs +1 -0
  15. package/dist/chunk-5FMTMXSP.cjs +127 -0
  16. package/dist/chunk-5POCKDDY.js +36 -0
  17. package/dist/chunk-5VDI56BV.js +33 -0
  18. package/dist/chunk-5WLBUPSK.js +77 -0
  19. package/dist/chunk-5WNNWQHD.cjs +272 -0
  20. package/dist/chunk-66STZB6I.cjs +404 -0
  21. package/dist/chunk-6AIKCZN7.js +1455 -0
  22. package/dist/chunk-6IUJJUVP.js +18 -0
  23. package/dist/chunk-6P2B3ZGP.js +79 -0
  24. package/dist/chunk-764ILIDG.cjs +22 -0
  25. package/dist/chunk-7B44DWC4.js +0 -0
  26. package/dist/chunk-7BE6ETFY.js +18 -0
  27. package/dist/chunk-7BSUS5A4.js +97 -0
  28. package/dist/chunk-7RPWCDEW.cjs +20 -0
  29. package/dist/chunk-7ULXHGLO.cjs +77 -0
  30. package/dist/chunk-7YOI5XOW.js +55 -0
  31. package/dist/chunk-AFVTM5CP.js +0 -0
  32. package/dist/chunk-AN2WSL3B.cjs +1 -0
  33. package/dist/chunk-AT5Y5GLS.cjs +118 -0
  34. package/dist/chunk-AWPO2FI7.js +404 -0
  35. package/dist/chunk-BGXHIDUR.js +103 -0
  36. package/dist/chunk-BPZXL5TP.js +99 -0
  37. package/dist/chunk-BRTS5GWV.js +275 -0
  38. package/dist/chunk-BS3MLZCK.cjs +97 -0
  39. package/dist/chunk-BSPYYE2U.js +36 -0
  40. package/dist/chunk-BWJAEB42.js +48 -0
  41. package/dist/chunk-C4RMTISI.cjs +18 -0
  42. package/dist/chunk-C6M4XVR7.cjs +36 -0
  43. package/dist/chunk-CGC4D5MP.cjs +89 -0
  44. package/dist/chunk-CIRQYSQW.js +70 -0
  45. package/dist/chunk-CLOTWJNP.cjs +310 -0
  46. package/dist/chunk-CS7ZY35M.cjs +49 -0
  47. package/dist/chunk-CUV4RLDE.js +89 -0
  48. package/dist/chunk-CZAMLFSE.cjs +275 -0
  49. package/dist/chunk-D7QZLJ3Z.cjs +18 -0
  50. package/dist/chunk-DMSAAZ3M.cjs +92 -0
  51. package/dist/chunk-DUIZC7VJ.cjs +36 -0
  52. package/dist/chunk-DVBF4BDH.js +43 -0
  53. package/dist/chunk-EETYMP6K.cjs +584 -0
  54. package/dist/chunk-EFQL7JPX.js +0 -0
  55. package/dist/chunk-EFU7IAF5.cjs +12 -0
  56. package/dist/chunk-F3M2H5EX.cjs +79 -0
  57. package/dist/chunk-F436V2SX.cjs +254 -0
  58. package/dist/chunk-F664X2OY.js +250 -0
  59. package/dist/chunk-FF7ELUQW.cjs +1 -0
  60. package/dist/chunk-G3HE4S3Q.cjs +296 -0
  61. package/dist/chunk-GOPD5KUK.js +23 -0
  62. package/dist/chunk-GYTB24V6.cjs +107 -0
  63. package/dist/chunk-GZ657SGO.js +310 -0
  64. package/dist/chunk-H2QN65L6.cjs +1 -0
  65. package/dist/chunk-H6WUT7CK.js +22 -0
  66. package/dist/chunk-H76OQ75T.js +49 -0
  67. package/dist/chunk-HA3XONYI.js +18 -0
  68. package/dist/chunk-HF3UFXEU.js +296 -0
  69. package/dist/chunk-HGA47QVV.cjs +55 -0
  70. package/dist/chunk-HHPPAMXF.cjs +674 -0
  71. package/dist/chunk-HLV2XIE2.cjs +385 -0
  72. package/dist/chunk-HNQGIL45.cjs +96 -0
  73. package/dist/chunk-HQ37R7T3.js +53 -0
  74. package/dist/chunk-HXUGW4RR.js +187 -0
  75. package/dist/chunk-HYPRLWD3.js +272 -0
  76. package/dist/chunk-I7TLJUTP.cjs +6 -0
  77. package/dist/chunk-ICTWDTKC.cjs +1 -0
  78. package/dist/chunk-IPYKHDP4.cjs +187 -0
  79. package/dist/chunk-IRKREQ2X.cjs +18 -0
  80. package/dist/chunk-IVJJBMRY.js +92 -0
  81. package/dist/chunk-JPVIVOFG.js +26 -0
  82. package/dist/chunk-JYNBNSNF.js +151 -0
  83. package/dist/chunk-JZC3BXAC.js +93 -0
  84. package/dist/chunk-K5XPQWXN.cjs +92 -0
  85. package/dist/chunk-KQ3GOMHL.js +31 -0
  86. package/dist/chunk-KUJH72U6.cjs +159 -0
  87. package/dist/chunk-KVUXLC6M.cjs +479 -0
  88. package/dist/chunk-KZOJN57Q.js +19 -0
  89. package/dist/chunk-L3XPL4NP.cjs +53 -0
  90. package/dist/chunk-LOEMSXYB.js +0 -0
  91. package/dist/chunk-LU4KBPNG.cjs +23 -0
  92. package/dist/chunk-MWWWPQDB.js +26 -0
  93. package/dist/chunk-NCBB3WUJ.js +562 -0
  94. package/dist/chunk-NGCZTZST.cjs +562 -0
  95. package/dist/chunk-NSDKALIS.cjs +67 -0
  96. package/dist/chunk-NZHCRLNB.cjs +26 -0
  97. package/dist/chunk-OL4NANHB.js +0 -0
  98. package/dist/chunk-OTJRNKLR.js +96 -0
  99. package/dist/chunk-OWWFKTSK.js +0 -0
  100. package/dist/chunk-P2E3PB62.cjs +99 -0
  101. package/dist/chunk-P2QVFR7S.js +20 -0
  102. package/dist/chunk-P6ZGIYY7.cjs +18 -0
  103. package/dist/chunk-PFGSJJRY.cjs +19 -0
  104. package/dist/chunk-PNIUW7AJ.cjs +32 -0
  105. package/dist/chunk-Q2M2ONGO.js +70 -0
  106. package/dist/chunk-Q4PGP5KE.cjs +562 -0
  107. package/dist/chunk-QAI2YQPY.cjs +51 -0
  108. package/dist/chunk-QCD7UEZ3.cjs +59 -0
  109. package/dist/chunk-QEZ4R3SK.js +6 -0
  110. package/dist/chunk-QKDCPM2D.cjs +23 -0
  111. package/dist/chunk-QRGG3V7W.cjs +59 -0
  112. package/dist/chunk-QURIHUEC.js +107 -0
  113. package/dist/chunk-QY742LWN.js +30 -0
  114. package/dist/chunk-QYMRGYTN.js +127 -0
  115. package/dist/chunk-RLKJ2RZG.js +23 -0
  116. package/dist/chunk-RRR5BUOM.cjs +30 -0
  117. package/dist/chunk-RU3FCVXM.cjs +1 -0
  118. package/dist/chunk-RYTDVTV2.js +32 -0
  119. package/dist/chunk-RYYGUYDE.js +92 -0
  120. package/dist/chunk-SGLP4U3Y.cjs +67 -0
  121. package/dist/chunk-SJC543ZK.js +71 -0
  122. package/dist/chunk-SLYQK4SC.js +20 -0
  123. package/dist/chunk-SMLCOMLS.js +2888 -0
  124. package/dist/chunk-SNMOPLMH.cjs +372 -0
  125. package/dist/chunk-TRJUJYW7.cjs +151 -0
  126. package/dist/chunk-TTY5PE3P.js +30 -0
  127. package/dist/chunk-TXARYG3J.js +22 -0
  128. package/dist/chunk-TYXJU4EF.js +18 -0
  129. package/dist/chunk-U3PC7FYZ.cjs +26 -0
  130. package/dist/chunk-U67JM2WL.cjs +34 -0
  131. package/dist/chunk-UARGO5UG.js +59 -0
  132. package/dist/chunk-UCYE3H3F.cjs +43 -0
  133. package/dist/chunk-UGEGN35F.js +118 -0
  134. package/dist/chunk-UHUA3GQC.cjs +30 -0
  135. package/dist/chunk-UJQN477L.js +59 -0
  136. package/dist/chunk-UMX7DTFZ.cjs +70 -0
  137. package/dist/chunk-UT42P54P.js +372 -0
  138. package/dist/chunk-V76ZRGHQ.cjs +1 -0
  139. package/dist/chunk-VCIK366Y.cjs +1455 -0
  140. package/dist/chunk-VMA74ABT.cjs +137 -0
  141. package/dist/chunk-VSA62N2O.js +12 -0
  142. package/dist/chunk-WDAFLVQK.js +479 -0
  143. package/dist/chunk-WHMLMAMO.js +674 -0
  144. package/dist/chunk-WNBLKKLM.js +0 -0
  145. package/dist/chunk-WQ2GY7F3.js +46 -0
  146. package/dist/chunk-WRLCCK3M.cjs +30 -0
  147. package/dist/chunk-WVCZIOLY.js +562 -0
  148. package/dist/chunk-WZLGJQLW.js +385 -0
  149. package/dist/chunk-XB6FEBK6.js +34 -0
  150. package/dist/chunk-XMERDSRE.js +75 -0
  151. package/dist/chunk-XMLFKZYY.js +137 -0
  152. package/dist/chunk-XMM52J3T.js +584 -0
  153. package/dist/chunk-XZ7C5CGB.cjs +103 -0
  154. package/dist/chunk-YGFBAOKX.js +51 -0
  155. package/dist/chunk-YIN552MF.cjs +20 -0
  156. package/dist/chunk-YLC42E65.cjs +31 -0
  157. package/dist/chunk-YOTXRYJL.cjs +46 -0
  158. package/dist/chunk-ZAUGJZK7.js +99 -0
  159. package/dist/chunk-ZIZOQTDG.cjs +75 -0
  160. package/dist/chunk-ZMSV5VZI.cjs +2888 -0
  161. package/dist/chunk-ZN6MLZAE.cjs +71 -0
  162. package/dist/chunk-ZNCT6HXA.cjs +33 -0
  163. package/dist/components/Accordion/index.cjs +5 -1036
  164. package/dist/components/Accordion/index.js +5 -999
  165. package/dist/components/Alert/index.cjs +4 -69
  166. package/dist/components/Alert/index.js +4 -42
  167. package/dist/components/AutoResizeTextArea/index.cjs +6 -260
  168. package/dist/components/AutoResizeTextArea/index.js +6 -223
  169. package/dist/components/Avatar/index.cjs +4 -65
  170. package/dist/components/Avatar/index.js +4 -38
  171. package/dist/components/Badge/index.cjs +6 -69
  172. package/dist/components/Badge/index.js +5 -40
  173. package/dist/components/Box/index.cjs +4 -58
  174. package/dist/components/Box/index.js +4 -31
  175. package/dist/components/Breadcrumb/index.cjs +4 -42
  176. package/dist/components/Breadcrumb/index.js +3 -14
  177. package/dist/components/Button/index.cjs +5 -65
  178. package/dist/components/Button/index.js +5 -38
  179. package/dist/components/Calendar/index.cjs +6 -1317
  180. package/dist/components/Calendar/index.js +10 -1281
  181. package/dist/components/CardTab/index.cjs +4 -120
  182. package/dist/components/CardTab/index.js +4 -83
  183. package/dist/components/Chart/index.cjs +5 -708
  184. package/dist/components/Chart/index.js +4 -670
  185. package/dist/components/ChatInput/index.cjs +9 -390
  186. package/dist/components/ChatInput/index.js +9 -353
  187. package/dist/components/CheckBox/index.cjs +20 -1125
  188. package/dist/components/CheckBox/index.js +17 -1095
  189. package/dist/components/Chip/index.cjs +5 -55
  190. package/dist/components/Chip/index.js +5 -28
  191. package/dist/components/DatePicker/index.cjs +16 -2136
  192. package/dist/components/DatePicker/index.js +19 -2099
  193. package/dist/components/Divider/index.cjs +4 -58
  194. package/dist/components/Divider/index.js +4 -31
  195. package/dist/components/Drawer/index.cjs +5 -190
  196. package/dist/components/Drawer/index.js +5 -153
  197. package/dist/components/Dropdown/index.cjs +7 -375
  198. package/dist/components/Dropdown/index.js +7 -338
  199. package/dist/components/Editor/index.cjs +6 -1486
  200. package/dist/components/Editor/index.css +53 -0
  201. package/dist/components/Editor/index.d.cts +13 -0
  202. package/dist/components/Editor/index.d.ts +13 -0
  203. package/dist/components/Editor/index.js +6 -1453
  204. package/dist/components/EmptyState/index.cjs +4 -42
  205. package/dist/components/EmptyState/index.js +3 -14
  206. package/dist/components/FieldMessage/index.cjs +7 -182
  207. package/dist/components/FieldMessage/index.js +8 -154
  208. package/dist/components/FileUpload/index.cjs +7 -1171
  209. package/dist/components/FileUpload/index.js +7 -1134
  210. package/dist/components/HtmlTypeWriter/index.cjs +3 -171
  211. package/dist/components/HtmlTypeWriter/index.js +3 -133
  212. package/dist/components/IconButton/index.cjs +4 -65
  213. package/dist/components/IconButton/index.js +4 -38
  214. package/dist/components/ImageSelector/index.cjs +8 -1214
  215. package/dist/components/ImageSelector/index.js +8 -1177
  216. package/dist/components/Input/index.cjs +7 -429
  217. package/dist/components/Input/index.js +8 -392
  218. package/dist/components/Link/index.cjs +4 -61
  219. package/dist/components/Link/index.js +4 -34
  220. package/dist/components/LinkButton/index.cjs +5 -61
  221. package/dist/components/LinkButton/index.js +5 -34
  222. package/dist/components/Modal/index.cjs +5 -190
  223. package/dist/components/Modal/index.js +5 -153
  224. package/dist/components/NotificationBadge/index.cjs +5 -68
  225. package/dist/components/NotificationBadge/index.js +5 -40
  226. package/dist/components/Pagination/index.cjs +6 -1034
  227. package/dist/components/Pagination/index.js +6 -1007
  228. package/dist/components/PopOver/index.cjs +7 -363
  229. package/dist/components/PopOver/index.js +7 -326
  230. package/dist/components/Progress/index.cjs +5 -84
  231. package/dist/components/Progress/index.js +5 -57
  232. package/dist/components/Radio/index.cjs +7 -274
  233. package/dist/components/Radio/index.js +8 -237
  234. package/dist/components/Select/index.cjs +10 -1577
  235. package/dist/components/Select/index.js +11 -1540
  236. package/dist/components/Skeleton/index.cjs +4 -71
  237. package/dist/components/Skeleton/index.js +4 -44
  238. package/dist/components/Spinner/index.cjs +5 -88
  239. package/dist/components/Spinner/index.js +5 -61
  240. package/dist/components/Stat/index.cjs +5 -81
  241. package/dist/components/Stat/index.js +5 -54
  242. package/dist/components/Steps/index.cjs +7 -968
  243. package/dist/components/Steps/index.js +7 -941
  244. package/dist/components/Swiper/index.cjs +4 -357
  245. package/dist/components/Swiper/index.js +4 -320
  246. package/dist/components/Switch/index.cjs +7 -252
  247. package/dist/components/Switch/index.js +7 -215
  248. package/dist/components/Tab/index.cjs +4 -144
  249. package/dist/components/Tab/index.js +4 -107
  250. package/dist/components/Table/index.cjs +4 -337
  251. package/dist/components/Table/index.js +8 -300
  252. package/dist/components/Tag/index.cjs +6 -969
  253. package/dist/components/Tag/index.js +6 -942
  254. package/dist/components/TextArea/index.cjs +6 -229
  255. package/dist/components/TextArea/index.js +6 -192
  256. package/dist/components/TimePicker/index.cjs +9 -579
  257. package/dist/components/TimePicker/index.js +9 -542
  258. package/dist/components/Toast/index.cjs +5 -146
  259. package/dist/components/Toast/index.js +5 -108
  260. package/dist/components/ToggleChip/index.cjs +5 -66
  261. package/dist/components/ToggleChip/index.js +5 -39
  262. package/dist/components/Tooltip/index.cjs +6 -204
  263. package/dist/components/Tooltip/index.js +6 -167
  264. package/dist/components/Tour/index.cjs +6 -414
  265. package/dist/components/Tour/index.js +6 -377
  266. package/dist/components/Video/index.cjs +7 -796
  267. package/dist/components/Video/index.js +7 -759
  268. package/dist/components/index.cjs +140 -8342
  269. package/dist/components/index.js +190 -8288
  270. package/dist/index.cjs +903 -13318
  271. package/dist/index.js +524 -12526
  272. package/dist/layout/Grid/FullGrid/index.cjs +4 -46
  273. package/dist/layout/Grid/FullGrid/index.js +3 -18
  274. package/dist/layout/Grid/FullScreen/index.cjs +4 -46
  275. package/dist/layout/Grid/FullScreen/index.js +3 -18
  276. package/dist/layout/Grid/Item/index.cjs +5 -68
  277. package/dist/layout/Grid/Item/index.js +5 -41
  278. package/dist/layout/Grid/index.cjs +14 -109
  279. package/dist/layout/Grid/index.js +14 -79
  280. package/dist/layout/Header/index.cjs +4 -44
  281. package/dist/layout/Header/index.js +3 -16
  282. package/dist/layout/Layout/index.cjs +4 -42
  283. package/dist/layout/Layout/index.js +3 -14
  284. package/dist/layout/SideBar/index.cjs +6 -96
  285. package/dist/layout/SideBar/index.js +6 -57
  286. package/dist/layout/index.cjs +38 -209
  287. package/dist/layout/index.js +27 -153
  288. package/dist/tokens/index.cjs +627 -6119
  289. package/dist/tokens/index.js +324 -5489
  290. package/guidelines/components/editor.md +3 -0
  291. package/guidelines/setup.md +7 -0
  292. package/package.json +6 -3
@@ -1,710 +1,7 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
29
2
 
30
- // src/components/Chart/index.ts
31
- var Chart_exports = {};
32
- __export(Chart_exports, {
33
- Chart: () => Chart_default
34
- });
35
- module.exports = __toCommonJS(Chart_exports);
3
+ var _chunkHHPPAMXFcjs = require('../../chunk-HHPPAMXF.cjs');
4
+ require('../../chunk-4ISERXK2.cjs');
36
5
 
37
- // src/components/Chart/Chart.tsx
38
- var import_react = __toESM(require("react"), 1);
39
- var import_jsx_runtime = require("react/jsx-runtime");
40
- var CATEGORICAL_COUNT = 8;
41
- var LINE_BAR_PALETTES = Array.from({ length: CATEGORICAL_COUNT }, (_, i) => {
42
- const n = i + 1;
43
- return [
44
- `var(--semantic-categorical-${n}-bg)`,
45
- `var(--semantic-categorical-${n}-area)`,
46
- `var(--semantic-categorical-${n}-fill)`,
47
- `var(--semantic-categorical-${n}-text)`
48
- ];
49
- });
50
- var PIE_COLORS = Array.from(
51
- { length: CATEGORICAL_COUNT },
52
- (_, i) => `var(--semantic-categorical-${i + 1}-fill)`
53
- );
54
- var hashString = (str) => {
55
- let hash = 0;
56
- for (let i = 0; i < str.length; i++) {
57
- hash = (hash << 5) - hash + str.charCodeAt(i) | 0;
58
- }
59
- return Math.abs(hash);
60
- };
61
- var getPalette = (palettes, index, key) => {
62
- const offset = key ? hashString(key) : 0;
63
- return palettes[(index + offset) % palettes.length];
64
- };
65
- var PADDING = { top: 20, right: 20, bottom: 30, left: 40 };
66
- var toSmoothPath = (points) => {
67
- if (points.length < 2) return "";
68
- const p = points;
69
- let d = `M ${p[0].x} ${p[0].y}`;
70
- for (let i = 0; i < p.length - 1; i++) {
71
- const p0 = p[Math.max(0, i - 1)];
72
- const p1 = p[i];
73
- const p2 = p[i + 1];
74
- const p3 = p[Math.min(p.length - 1, i + 2)];
75
- const cp1x = p1.x + (p2.x - p0.x) / 6;
76
- const cp1y = p1.y + (p2.y - p0.y) / 6;
77
- const cp2x = p2.x - (p3.x - p1.x) / 6;
78
- const cp2y = p2.y - (p3.y - p1.y) / 6;
79
- d += ` C ${cp1x} ${cp1y}, ${cp2x} ${cp2y}, ${p2.x} ${p2.y}`;
80
- }
81
- return d;
82
- };
83
- var useChartSize = (ref) => {
84
- const [size, setSize] = import_react.default.useState({ width: 0, height: 0 });
85
- import_react.default.useEffect(() => {
86
- const el = ref.current;
87
- if (!el) return;
88
- let rafId = 0;
89
- const observer = new ResizeObserver((entries) => {
90
- cancelAnimationFrame(rafId);
91
- rafId = requestAnimationFrame(() => {
92
- const entry = entries[0];
93
- if (!entry) return;
94
- const { width, height } = entry.contentRect;
95
- const w = Math.floor(width);
96
- const h = Math.floor(height);
97
- if (w <= 0 || h <= 0) return;
98
- setSize((prev) => prev.width === w && prev.height === h ? prev : { width: w, height: h });
99
- });
100
- });
101
- observer.observe(el);
102
- return () => {
103
- cancelAnimationFrame(rafId);
104
- observer.disconnect();
105
- };
106
- }, [ref]);
107
- return size;
108
- };
109
- var prefersReducedMotion = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
110
- var useChartAnimation = (containerRef, dataKey) => {
111
- const [animate, setAnimate] = import_react.default.useState(false);
112
- const prevDataKey = import_react.default.useRef(dataKey);
113
- const hasAnimated = import_react.default.useRef(false);
114
- import_react.default.useEffect(() => {
115
- if (prefersReducedMotion()) return;
116
- const el = containerRef.current;
117
- if (!el) return;
118
- const observer = new IntersectionObserver(
119
- ([entry]) => {
120
- if (entry.isIntersecting && !hasAnimated.current) {
121
- hasAnimated.current = true;
122
- setAnimate(true);
123
- }
124
- },
125
- { threshold: 0.1 }
126
- );
127
- observer.observe(el);
128
- return () => observer.disconnect();
129
- }, [containerRef]);
130
- import_react.default.useEffect(() => {
131
- if (dataKey !== prevDataKey.current) {
132
- prevDataKey.current = dataKey;
133
- if (prefersReducedMotion()) return;
134
- setAnimate(false);
135
- requestAnimationFrame(() => {
136
- requestAnimationFrame(() => setAnimate(true));
137
- });
138
- }
139
- }, [dataKey]);
140
- return animate || prefersReducedMotion();
141
- };
142
- var TOOLTIP_OFFSET = 12;
143
- var useChartTooltip = (enabled) => {
144
- const [tooltip, setTooltip] = import_react.default.useState({
145
- visible: false,
146
- x: 0,
147
- y: 0,
148
- content: ""
149
- });
150
- const containerRef = import_react.default.useRef(null);
151
- const rafRef = import_react.default.useRef(0);
152
- const move = import_react.default.useCallback((e) => {
153
- if (!enabled) return;
154
- const cx = e.clientX;
155
- const cy = e.clientY;
156
- cancelAnimationFrame(rafRef.current);
157
- rafRef.current = requestAnimationFrame(() => {
158
- const rect = containerRef.current?.getBoundingClientRect();
159
- if (!rect) return;
160
- setTooltip((prev) => ({ ...prev, x: cx - rect.left, y: cy - rect.top }));
161
- });
162
- }, [enabled]);
163
- const show = import_react.default.useCallback((e, content) => {
164
- if (!enabled) return;
165
- const rect = containerRef.current?.getBoundingClientRect();
166
- if (!rect) return;
167
- setTooltip({ visible: true, x: e.clientX - rect.left, y: e.clientY - rect.top, content });
168
- }, [enabled]);
169
- const hide = import_react.default.useCallback(() => {
170
- cancelAnimationFrame(rafRef.current);
171
- setTooltip((prev) => ({ ...prev, visible: false }));
172
- }, []);
173
- return { tooltip, show, hide, move, containerRef };
174
- };
175
- var formatTick = (value, maxVal) => {
176
- const step = maxVal / 4;
177
- if (!Number.isFinite(step) || step <= 0) return "0";
178
- const decimals = step >= 1 ? 0 : Math.min(4, Math.ceil(-Math.log10(step)));
179
- const fixed = value.toFixed(decimals);
180
- return decimals === 0 ? Number(fixed).toLocaleString("en-US") : fixed;
181
- };
182
- var GridLines = import_react.default.memo(({ width, height, chartH, maxVal }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: [0, 0.25, 0.5, 0.75, 1].map((ratio) => {
183
- const y = PADDING.top + (1 - ratio) * chartH;
184
- const val = formatTick(maxVal * ratio, maxVal);
185
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
186
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: PADDING.left, y1: y, x2: width - PADDING.right, y2: y, className: "chart-grid" }),
187
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x: PADDING.left - 8, y: y + 4, className: "chart-axis-label", textAnchor: "end", children: val })
188
- ] }, ratio);
189
- }) }));
190
- GridLines.displayName = "GridLines";
191
- var getLabelStep = (count, chartW) => {
192
- const minLabelWidth = 40;
193
- const maxLabels = Math.floor(chartW / minLabelWidth);
194
- if (count <= maxLabels) return 1;
195
- return Math.ceil(count / maxLabels);
196
- };
197
- var AxisLabels = import_react.default.memo(({ labels, count, chartW, height }) => {
198
- const step = getLabelStep(count, chartW);
199
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: labels.map((label, i) => {
200
- if (i % step !== 0) return null;
201
- const x = PADDING.left + i / (count - 1 || 1) * chartW;
202
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
203
- }) });
204
- });
205
- AxisLabels.displayName = "AxisLabels";
206
- var useCrosshair = (seriesPoints, entries, labels, chartH) => {
207
- const [activeIndex, setActiveIndex] = import_react.default.useState(null);
208
- const handleMouseMove = import_react.default.useCallback((e) => {
209
- const svg = e.currentTarget;
210
- const rect = svg.getBoundingClientRect();
211
- const mx = (e.clientX - rect.left) / rect.width * svg.viewBox.baseVal.width;
212
- if (seriesPoints.length === 0 || seriesPoints[0].length === 0) return;
213
- const points = seriesPoints[0];
214
- const step = points.length > 1 ? Math.abs(points[1].x - points[0].x) : 20;
215
- const threshold = step / 2;
216
- let closest = 0;
217
- let minDist = Math.abs(points[0].x - mx);
218
- for (let i = 1; i < points.length; i++) {
219
- const dist = Math.abs(points[i].x - mx);
220
- if (dist < minDist) {
221
- minDist = dist;
222
- closest = i;
223
- }
224
- }
225
- setActiveIndex(minDist <= threshold ? closest : null);
226
- }, [seriesPoints]);
227
- const handleMouseLeave = import_react.default.useCallback(() => {
228
- setActiveIndex(null);
229
- }, []);
230
- const tooltipContent = import_react.default.useMemo(() => {
231
- if (activeIndex === null) return "";
232
- return entries.map(([key], di) => {
233
- const p = seriesPoints[di]?.[activeIndex];
234
- return p ? `${key}: ${p.v}` : "";
235
- }).filter(Boolean).join(" / ");
236
- }, [activeIndex, entries, seriesPoints]);
237
- const getTooltipAt = import_react.default.useCallback((idx) => {
238
- return entries.map(([key], di) => {
239
- const p = seriesPoints[di]?.[idx];
240
- return p ? `${key}: ${p.v}` : "";
241
- }).filter(Boolean).join(" / ");
242
- }, [entries, seriesPoints]);
243
- return { activeIndex, handleMouseMove, handleMouseLeave, tooltipContent, getTooltipAt };
244
- };
245
- var LineChart = import_react.default.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
246
- const entries = import_react.default.useMemo(() => Object.entries(data), [data]);
247
- const maxVal = import_react.default.useMemo(() => {
248
- const allValues = entries.flatMap(([, v]) => v);
249
- return Math.max(...allValues) * 1.2 || 1;
250
- }, [entries]);
251
- const count = labels.length;
252
- const chartW = width - PADDING.left - PADDING.right;
253
- const chartH = height - PADDING.top - PADDING.bottom;
254
- const seriesPoints = import_react.default.useMemo(
255
- () => entries.map(
256
- ([, values]) => values.map((v, i) => ({
257
- x: PADDING.left + i / (count - 1 || 1) * chartW,
258
- y: PADDING.top + (1 - v / maxVal) * chartH,
259
- v
260
- }))
261
- ),
262
- [entries, count, chartW, chartH, maxVal]
263
- );
264
- const clipRef = import_react.default.useRef(null);
265
- const { activeIndex, handleMouseMove, handleMouseLeave, getTooltipAt } = useCrosshair(seriesPoints, entries, labels, chartH);
266
- import_react.default.useEffect(() => {
267
- if (!animate || !clipRef.current) return;
268
- clipRef.current.setAttribute("width", "0");
269
- requestAnimationFrame(() => {
270
- if (clipRef.current) {
271
- clipRef.current.style.transition = "width 1200ms ease-out 200ms";
272
- clipRef.current.setAttribute("width", `${width}`);
273
- }
274
- });
275
- }, [animate, width]);
276
- const activeX = activeIndex !== null ? seriesPoints[0]?.[activeIndex]?.x ?? null : null;
277
- const lineClipId = "line-area-clip";
278
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
279
- "svg",
280
- {
281
- viewBox: `0 0 ${width} ${height}`,
282
- className: "chart-svg",
283
- onMouseMove: (e) => {
284
- handleMouseMove(e);
285
- if (activeIndex !== null) {
286
- onHover(e, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
287
- } else {
288
- onLeave();
289
- }
290
- },
291
- onMouseLeave: () => {
292
- handleMouseLeave();
293
- onLeave();
294
- },
295
- children: [
296
- animate && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("clipPath", { id: lineClipId, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { ref: clipRef, x: "0", y: "0", width: animate ? 0 : width, height }) }) }),
297
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GridLines, { width, height, chartH, maxVal }),
298
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AxisLabels, { labels, count, chartW, height }),
299
- entries.map(([key], di) => {
300
- const palette = getPalette(LINE_BAR_PALETTES, di, key);
301
- const color = palette[2];
302
- const areaColor = palette[0];
303
- const points = seriesPoints[di];
304
- const gradientId = `line-gradient-${di}`;
305
- const polyPoints = points.map((p) => `${p.x},${p.y}`).join(" ");
306
- const areaD = `M ${points[0].x},${points[0].y} ${points.map((p) => `L ${p.x},${p.y}`).join(" ")} L ${points[points.length - 1].x},${PADDING.top + chartH} L ${points[0].x},${PADDING.top + chartH} Z`;
307
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
308
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
309
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "0%", stopColor: areaColor, stopOpacity: "0.2" }),
310
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "100%", stopColor: areaColor, stopOpacity: "0" })
311
- ] }) }),
312
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { clipPath: animate ? `url(#${lineClipId})` : void 0, children: [
313
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: areaD, fill: `url(#${gradientId})` }),
314
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: polyPoints, fill: "none", stroke: color, strokeWidth: "2" })
315
- ] }),
316
- activeIndex !== null && points[activeIndex] && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
317
- "circle",
318
- {
319
- cx: points[activeIndex].x,
320
- cy: points[activeIndex].y,
321
- r: "5",
322
- fill: color,
323
- className: "chart-point-active"
324
- }
325
- )
326
- ] }, di);
327
- }),
328
- activeX !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
329
- "line",
330
- {
331
- x1: activeX,
332
- y1: PADDING.top,
333
- x2: activeX,
334
- y2: PADDING.top + chartH,
335
- className: "chart-crosshair"
336
- }
337
- ),
338
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
339
- "rect",
340
- {
341
- x: PADDING.left,
342
- y: PADDING.top,
343
- width: chartW,
344
- height: chartH,
345
- fill: "transparent",
346
- style: { cursor: "crosshair" }
347
- }
348
- )
349
- ]
350
- }
351
- );
352
- });
353
- LineChart.displayName = "LineChart";
354
- var CurveChart = import_react.default.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
355
- const entries = import_react.default.useMemo(() => Object.entries(data), [data]);
356
- const maxVal = import_react.default.useMemo(() => {
357
- const allValues = entries.flatMap(([, v]) => v);
358
- return Math.max(...allValues) * 1.2 || 1;
359
- }, [entries]);
360
- const count = labels.length;
361
- const chartW = width - PADDING.left - PADDING.right;
362
- const chartH = height - PADDING.top - PADDING.bottom;
363
- const seriesPoints = import_react.default.useMemo(
364
- () => entries.map(
365
- ([, values]) => values.map((v, i) => ({
366
- x: PADDING.left + i / (count - 1 || 1) * chartW,
367
- y: PADDING.top + (1 - v / maxVal) * chartH,
368
- v
369
- }))
370
- ),
371
- [entries, count, chartW, chartH, maxVal]
372
- );
373
- const curveClipRef = import_react.default.useRef(null);
374
- const { activeIndex, handleMouseMove, handleMouseLeave, getTooltipAt } = useCrosshair(seriesPoints, entries, labels, chartH);
375
- import_react.default.useEffect(() => {
376
- if (!animate || !curveClipRef.current) return;
377
- curveClipRef.current.setAttribute("width", "0");
378
- requestAnimationFrame(() => {
379
- if (curveClipRef.current) {
380
- curveClipRef.current.style.transition = "width 1200ms ease-out 200ms";
381
- curveClipRef.current.setAttribute("width", `${width}`);
382
- }
383
- });
384
- }, [animate, width]);
385
- const activeX = activeIndex !== null ? seriesPoints[0]?.[activeIndex]?.x ?? null : null;
386
- const curveClipId = "curve-area-clip";
387
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
388
- "svg",
389
- {
390
- viewBox: `0 0 ${width} ${height}`,
391
- className: "chart-svg",
392
- onMouseMove: (e) => {
393
- handleMouseMove(e);
394
- if (activeIndex !== null && seriesPoints[0]?.[activeIndex]) {
395
- const p = seriesPoints[0][activeIndex];
396
- onHover(e, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
397
- } else {
398
- onLeave();
399
- }
400
- },
401
- onMouseLeave: () => {
402
- handleMouseLeave();
403
- onLeave();
404
- },
405
- children: [
406
- animate && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("clipPath", { id: curveClipId, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { ref: curveClipRef, x: "0", y: "0", width: animate ? 0 : width, height }) }) }),
407
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GridLines, { width, height, chartH, maxVal }),
408
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AxisLabels, { labels, count, chartW, height }),
409
- entries.map(([key], di) => {
410
- const palette = getPalette(LINE_BAR_PALETTES, di, key);
411
- const color = palette[2];
412
- const areaColor = palette[0];
413
- const points = seriesPoints[di];
414
- const gradientId = `curve-gradient-${di}`;
415
- const linePath = toSmoothPath(points);
416
- const areaPath = linePath + ` L ${points[points.length - 1].x} ${PADDING.top + chartH} L ${points[0].x} ${PADDING.top + chartH} Z`;
417
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
418
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
419
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "0%", stopColor: areaColor, stopOpacity: "0.4" }),
420
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "100%", stopColor: areaColor, stopOpacity: "0.02" })
421
- ] }) }),
422
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { clipPath: animate ? `url(#${curveClipId})` : void 0, children: [
423
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: areaPath, fill: `url(#${gradientId})` }),
424
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: linePath, fill: "none", stroke: color, strokeWidth: "2" })
425
- ] }),
426
- activeIndex !== null && points[activeIndex] && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
427
- "circle",
428
- {
429
- cx: points[activeIndex].x,
430
- cy: points[activeIndex].y,
431
- r: "5",
432
- fill: color,
433
- className: "chart-point-active"
434
- }
435
- )
436
- ] }, di);
437
- }),
438
- activeX !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
439
- "line",
440
- {
441
- x1: activeX,
442
- y1: PADDING.top,
443
- x2: activeX,
444
- y2: PADDING.top + chartH,
445
- className: "chart-crosshair"
446
- }
447
- ),
448
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
449
- "rect",
450
- {
451
- x: PADDING.left,
452
- y: PADDING.top,
453
- width: chartW,
454
- height: chartH,
455
- fill: "transparent",
456
- style: { cursor: "crosshair" }
457
- }
458
- )
459
- ]
460
- }
461
- );
462
- });
463
- CurveChart.displayName = "CurveChart";
464
- var BarChart = import_react.default.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
465
- const entries = import_react.default.useMemo(() => Object.entries(data), [data]);
466
- const maxVal = import_react.default.useMemo(() => {
467
- const allValues = entries.flatMap(([, v]) => v);
468
- return Math.max(...allValues) * 1.2 || 1;
469
- }, [entries]);
470
- const count = labels.length;
471
- const groupCount = entries.length;
472
- const chartW = width - PADDING.left - PADDING.right;
473
- const chartH = height - PADDING.top - PADDING.bottom;
474
- const groupW = chartW / count;
475
- const barGap = groupCount > 1 ? 2 : 0;
476
- const barW = Math.max(1, Math.min(32, (groupW * 0.7 - barGap * (groupCount - 1)) / groupCount));
477
- const baseline = PADDING.top + chartH;
478
- const bars = import_react.default.useMemo(
479
- () => entries.map(
480
- ([, values], di) => values.map((v, i) => {
481
- const totalBarsW = barW * groupCount + barGap * (groupCount - 1);
482
- const h = Math.max(0, v / maxVal * chartH);
483
- const x = PADDING.left + groupW * i + (groupW - totalBarsW) / 2 + (barW + barGap) * di;
484
- const y = PADDING.top + chartH - h;
485
- return { x, y, w: barW, h, v };
486
- })
487
- ),
488
- [entries, maxVal, chartH, groupW, barW, barGap, groupCount]
489
- );
490
- const barLabelStep = getLabelStep(count, chartW);
491
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { viewBox: `0 0 ${width} ${height}`, className: "chart-svg", children: [
492
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GridLines, { width, height, chartH, maxVal }),
493
- labels.map((label, i) => {
494
- if (i % barLabelStep !== 0) return null;
495
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("text", { x: PADDING.left + groupW * i + groupW / 2, y: height - 8, className: "chart-axis-label", textAnchor: "middle", children: label }, i);
496
- }),
497
- entries.map(([key], di) => {
498
- const palette = getPalette(LINE_BAR_PALETTES, di, key);
499
- const color = palette[2];
500
- return bars[di].map((b, i) => {
501
- const r = Math.min(4, b.w / 2);
502
- const d = b.h <= r ? `M ${b.x} ${b.y + b.h} V ${b.y} H ${b.x + b.w} V ${b.y + b.h} Z` : `M ${b.x} ${b.y + b.h} V ${b.y + r} Q ${b.x} ${b.y} ${b.x + r} ${b.y} H ${b.x + b.w - r} Q ${b.x + b.w} ${b.y} ${b.x + b.w} ${b.y + r} V ${b.y + b.h} Z`;
503
- const delay = 100 + i * 80;
504
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
505
- "path",
506
- {
507
- d,
508
- fill: color,
509
- className: `chart-bar ${animate ? "chart-bar-animate" : ""}`,
510
- style: animate ? {
511
- transformOrigin: `${b.x + b.w / 2}px ${baseline}px`,
512
- animationDelay: `${delay}ms`
513
- } : void 0,
514
- onMouseEnter: (e) => onHover(e, `${key}: ${labels[i]} \u2014 ${b.v}`),
515
- onMouseMove: onMove,
516
- onMouseLeave: onLeave
517
- },
518
- `${di}-${i}`
519
- );
520
- });
521
- })
522
- ] });
523
- });
524
- BarChart.displayName = "BarChart";
525
- var PieDonutChart = import_react.default.memo(
526
- ({ data, labels, width, height, animate, isDoughnut, onHover, onMove, onLeave }) => {
527
- const entries = import_react.default.useMemo(() => Object.entries(data), [data]);
528
- const values = import_react.default.useMemo(() => entries.flatMap(([, v]) => v), [entries]);
529
- const total = import_react.default.useMemo(() => values.reduce((a, b) => a + b, 0) || 1, [values]);
530
- const size = Math.min(width, height);
531
- const cx = size / 2;
532
- const cy = size / 2;
533
- const r = size * 0.4;
534
- const innerR = isDoughnut ? r * 0.5 : 0;
535
- const firstKey = entries[0]?.[0] ?? "";
536
- const colorOffset = hashString(firstKey);
537
- const maskRef = import_react.default.useRef(null);
538
- const maskR = r + 10;
539
- const maskCircumference = 2 * Math.PI * maskR;
540
- import_react.default.useEffect(() => {
541
- if (!animate || !maskRef.current) return;
542
- const el = maskRef.current;
543
- el.style.strokeDasharray = `${maskCircumference}`;
544
- el.style.strokeDashoffset = `${maskCircumference}`;
545
- requestAnimationFrame(() => {
546
- el.style.transition = "stroke-dashoffset 1000ms ease-out";
547
- el.style.strokeDashoffset = "0";
548
- });
549
- }, [animate, maskCircumference]);
550
- const sliceData = import_react.default.useMemo(() => {
551
- let angle0 = -Math.PI / 2;
552
- let cumulativeAngle = 0;
553
- return values.map((v, i) => {
554
- const angle = v / total * Math.PI * 2;
555
- const endAngle = angle0 + angle;
556
- const largeArc = angle > Math.PI ? 1 : 0;
557
- const x1 = cx + r * Math.cos(angle0);
558
- const y1 = cy + r * Math.sin(angle0);
559
- const x2 = cx + r * Math.cos(endAngle);
560
- const y2 = cy + r * Math.sin(endAngle);
561
- let d;
562
- if (innerR > 0) {
563
- const ix1 = cx + innerR * Math.cos(angle0);
564
- const iy1 = cy + innerR * Math.sin(angle0);
565
- const ix2 = cx + innerR * Math.cos(endAngle);
566
- const iy2 = cy + innerR * Math.sin(endAngle);
567
- d = `M ${ix1} ${iy1} L ${x1} ${y1} A ${r} ${r} 0 ${largeArc} 1 ${x2} ${y2} L ${ix2} ${iy2} A ${innerR} ${innerR} 0 ${largeArc} 0 ${ix1} ${iy1} Z`;
568
- } else {
569
- d = `M ${cx} ${cy} L ${x1} ${y1} A ${r} ${r} 0 ${largeArc} 1 ${x2} ${y2} Z`;
570
- }
571
- const midAngle = angle0 + angle / 2;
572
- const labelR = innerR > 0 ? (r + innerR) / 2 : r * 0.6;
573
- const lx = cx + labelR * Math.cos(midAngle);
574
- const ly = cy + labelR * Math.sin(midAngle);
575
- const pct = Math.round(v / total * 100);
576
- cumulativeAngle += angle;
577
- const sliceEndRatio = cumulativeAngle / (Math.PI * 2);
578
- const labelDelay = 1e3 * sliceEndRatio + 150;
579
- angle0 = endAngle;
580
- return { d, lx, ly, v, pct, angle, label: labels[i] || `${i + 1}`, labelDelay };
581
- });
582
- }, [values, total, cx, cy, r, innerR, labels]);
583
- const maskId = `pie-mask-${isDoughnut ? "d" : "p"}`;
584
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { viewBox: `0 0 ${size} ${size}`, className: "chart-svg chart-pie", children: [
585
- animate && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("mask", { id: maskId, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
586
- "circle",
587
- {
588
- ref: maskRef,
589
- cx,
590
- cy,
591
- r: maskR,
592
- fill: "none",
593
- stroke: "white",
594
- strokeWidth: maskR * 2,
595
- transform: `rotate(-90 ${cx} ${cy})`
596
- }
597
- ) }) }),
598
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { mask: animate ? `url(#${maskId})` : void 0, children: sliceData.map((s, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
599
- "path",
600
- {
601
- d: s.d,
602
- fill: PIE_COLORS[(i + colorOffset) % PIE_COLORS.length],
603
- className: "chart-slice",
604
- onMouseEnter: (e) => onHover(e, `${s.label} \u2014 ${s.v.toLocaleString()} (${s.pct}%)`),
605
- onMouseMove: onMove,
606
- onMouseLeave: onLeave
607
- }
608
- ) }, i)) })
609
- ] });
610
- }
611
- );
612
- PieDonutChart.displayName = "PieDonutChart";
613
- var ChartTooltip = ({ x, y, containerWidth, containerHeight, tooltipType, children }) => {
614
- const ref = import_react.default.useRef(null);
615
- const [pos, setPos] = import_react.default.useState({ left: 0, top: 0 });
616
- import_react.default.useLayoutEffect(() => {
617
- const el = ref.current;
618
- if (!el) return;
619
- const w = el.offsetWidth;
620
- const h = el.offsetHeight;
621
- let left = x + TOOLTIP_OFFSET;
622
- let top = y - h - TOOLTIP_OFFSET;
623
- if (left + w > containerWidth) left = x - w - TOOLTIP_OFFSET;
624
- if (left < 0) left = 0;
625
- if (top < 0) top = y + TOOLTIP_OFFSET;
626
- if (top + h > containerHeight) top = containerHeight - h;
627
- setPos({ left, top });
628
- }, [x, y, containerWidth, containerHeight]);
629
- const content = typeof children === "string" ? children : "";
630
- const sepIdx = content.indexOf(" \u2014 ");
631
- const title = sepIdx >= 0 ? content.slice(0, sepIdx) : content;
632
- const desc = sepIdx >= 0 ? content.slice(sepIdx + 3) : "";
633
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
634
- "div",
635
- {
636
- ref,
637
- className: `lib-xplat-tooltip ${tooltipType} chart-tooltip-pos`,
638
- style: { left: pos.left, top: pos.top },
639
- children: [
640
- title && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tooltip-title", children: title }),
641
- desc && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tooltip-desc", children: desc })
642
- ]
643
- }
644
- );
645
- };
646
- var ChartLegend = ({ data, labels, shape }) => {
647
- const entries = Object.entries(data);
648
- if (shape === "pie" || shape === "doughnut") {
649
- const values = entries.flatMap(([, v]) => v);
650
- const total = values.reduce((a, b) => a + b, 0) || 1;
651
- const firstKey = entries[0]?.[0] ?? "";
652
- const colorOffset = hashString(firstKey);
653
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "chart-legend", children: values.map((v, i) => {
654
- const pct = Math.round(v / total * 100);
655
- const color = PIE_COLORS[(i + colorOffset) % PIE_COLORS.length];
656
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "chart-legend-item", children: [
657
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "chart-legend-dot", style: { backgroundColor: color } }),
658
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "chart-legend-text", children: [
659
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "chart-legend-label", children: labels[i] || `${i + 1}` }),
660
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "chart-legend-value", children: [
661
- v.toLocaleString(),
662
- "(",
663
- pct,
664
- "%)"
665
- ] })
666
- ] })
667
- ] }, i);
668
- }) });
669
- }
670
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "chart-legend", children: entries.map(([key], di) => {
671
- const palette = getPalette(LINE_BAR_PALETTES, di, key);
672
- const color = palette[2];
673
- const values = entries[di][1];
674
- const sum = values.reduce((a, b) => a + b, 0);
675
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "chart-legend-item", children: [
676
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "chart-legend-dot", style: { backgroundColor: color } }),
677
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "chart-legend-text", children: [
678
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "chart-legend-label", children: key }),
679
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "chart-legend-value", children: sum.toLocaleString() })
680
- ] })
681
- ] }, di);
682
- }) });
683
- };
684
- var Chart = import_react.default.memo((props) => {
685
- const { variant, type, data, labels, legend, tooltip: showTooltip = true, tooltipType = "light" } = props;
686
- const shape = variant ?? type ?? "line";
687
- const showLegend = legend ?? (shape === "pie" || shape === "doughnut");
688
- const { tooltip, show, hide, move, containerRef } = useChartTooltip(showTooltip);
689
- const { width, height } = useChartSize(containerRef);
690
- const stableData = import_react.default.useMemo(() => data, [JSON.stringify(data)]);
691
- const stableLabels = import_react.default.useMemo(() => labels, [JSON.stringify(labels)]);
692
- const dataKey = import_react.default.useMemo(() => JSON.stringify(labels), [labels]);
693
- const animate = useChartAnimation(containerRef, dataKey);
694
- const ready = width > 0 && height > 0;
695
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "lib-xplat-chart", ref: containerRef, children: [
696
- ready && shape === "line" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LineChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
697
- ready && shape === "curve" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CurveChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
698
- ready && shape === "bar" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
699
- ready && shape === "pie" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
700
- ready && shape === "doughnut" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onMove: move, onLeave: hide }),
701
- ready && showLegend && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChartLegend, { data: stableData, labels: stableLabels, shape }),
702
- tooltip.visible && tooltip.content && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, tooltipType, children: tooltip.content })
703
- ] });
704
- });
705
- Chart.displayName = "Chart";
706
- var Chart_default = Chart;
707
- // Annotate the CommonJS export names for ESM import in node:
708
- 0 && (module.exports = {
709
- Chart
710
- });
6
+
7
+ exports.Chart = _chunkHHPPAMXFcjs.Chart_default;