@overdoser/react-toolkit 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 (273) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +14 -0
  3. package/components/Accordion/Accordion.js +160 -177
  4. package/components/Accordion/Accordion.module.js +20 -0
  5. package/components/ActionButton/ActionButton.js +155 -209
  6. package/components/ActionButton/ActionButton.module.js +25 -0
  7. package/components/ActionButton/CopyButton.js +52 -64
  8. package/components/Alert/Alert.js +92 -95
  9. package/components/Alert/Alert.module.js +18 -0
  10. package/components/Avatar/Avatar.js +44 -55
  11. package/components/Avatar/Avatar.module.js +23 -0
  12. package/components/Badge/Badge.js +16 -38
  13. package/components/Badge/Badge.module.js +17 -0
  14. package/components/Breadcrumbs/Breadcrumbs.d.ts +1 -1
  15. package/components/Breadcrumbs/Breadcrumbs.js +52 -48
  16. package/components/Breadcrumbs/Breadcrumbs.module.js +10 -0
  17. package/components/Button/Button.js +35 -57
  18. package/components/Button/Button.module.js +25 -0
  19. package/components/Card/Card.js +94 -131
  20. package/components/Card/Card.module.js +35 -0
  21. package/components/Chart/AreaChart.d.ts +1 -1
  22. package/components/Chart/AreaChart.js +248 -249
  23. package/components/Chart/Axis.d.ts +2 -2
  24. package/components/Chart/Axis.js +34 -43
  25. package/components/Chart/BarChart.d.ts +1 -1
  26. package/components/Chart/BarChart.js +307 -348
  27. package/components/Chart/Chart.module.js +32 -0
  28. package/components/Chart/ChartContainer.js +33 -41
  29. package/components/Chart/ChartLegend.d.ts +1 -1
  30. package/components/Chart/ChartLegend.js +31 -30
  31. package/components/Chart/ChartTooltip.d.ts +1 -1
  32. package/components/Chart/ChartTooltip.js +46 -41
  33. package/components/Chart/LineChart.d.ts +1 -1
  34. package/components/Chart/LineChart.js +220 -232
  35. package/components/Chart/PieChart.d.ts +1 -1
  36. package/components/Chart/PieChart.js +224 -240
  37. package/components/Chart/RadarChart.d.ts +1 -1
  38. package/components/Chart/RadarChart.js +166 -215
  39. package/components/Chart/Sparkline.js +73 -68
  40. package/components/Chart/TradingChart.d.ts +1 -1
  41. package/components/Chart/TradingChart.js +804 -701
  42. package/components/Chart/scales.js +28 -35
  43. package/components/Chart/trading/indicators.js +61 -62
  44. package/components/Chart/trading/period.js +46 -68
  45. package/components/Chart/useChartDimensions.js +30 -22
  46. package/components/Chip/Chip.js +98 -141
  47. package/components/Chip/Chip.module.js +32 -0
  48. package/components/CodeBlock/CodeBlock.js +111 -119
  49. package/components/CodeBlock/CodeBlock.module.js +23 -0
  50. package/components/CommandPalette/CommandPalette.js +387 -392
  51. package/components/CommandPalette/CommandPalette.module.js +28 -0
  52. package/components/ConfirmDialog/ConfirmDialog.d.ts +1 -1
  53. package/components/ConfirmDialog/ConfirmDialog.js +184 -199
  54. package/components/ConfirmDialog/ConfirmDialog.module.js +12 -0
  55. package/components/Divider/Divider.js +25 -36
  56. package/components/Divider/Divider.module.js +17 -0
  57. package/components/Draggable/Draggable.d.ts +1 -1
  58. package/components/Draggable/Draggable.js +157 -164
  59. package/components/Draggable/Draggable.module.js +10 -0
  60. package/components/Drawer/Drawer.js +104 -126
  61. package/components/Drawer/Drawer.module.js +66 -0
  62. package/components/Dropdown/Dropdown.js +175 -234
  63. package/components/Dropdown/Dropdown.module.js +29 -0
  64. package/components/Dropdown/DropdownItem.js +55 -58
  65. package/components/Dropdown/DropdownLabel.js +14 -11
  66. package/components/Dropdown/DropdownSeparator.js +12 -10
  67. package/components/Dropdown/dropdownContext.js +4 -5
  68. package/components/Dropdown/useContextMenu.js +27 -17
  69. package/components/Dropzone/Dropzone.js +99 -105
  70. package/components/Dropzone/Dropzone.module.js +12 -0
  71. package/components/EmptyState/EmptyState.js +58 -55
  72. package/components/EmptyState/EmptyState.module.js +14 -0
  73. package/components/Form/Form.d.ts +1 -1
  74. package/components/Form/Form.js +32 -35
  75. package/components/Form/Form.module.js +16 -0
  76. package/components/Form/FormField.d.ts +1 -1
  77. package/components/Form/FormField.js +71 -75
  78. package/components/Form/FormRow.d.ts +1 -1
  79. package/components/Form/FormRow.js +11 -8
  80. package/components/Form/formFieldDefaults.js +4 -5
  81. package/components/ImageViewer/ImageViewer.js +312 -201
  82. package/components/ImageViewer/ImageViewer.module.js +26 -0
  83. package/components/ImageViewer/useZoomPan.js +206 -137
  84. package/components/Kbd/Kbd.js +25 -22
  85. package/components/Kbd/Kbd.module.js +10 -0
  86. package/components/KeyValueList/KeyValueList.js +119 -123
  87. package/components/KeyValueList/KeyValueList.module.js +23 -0
  88. package/components/Link/Link.js +45 -59
  89. package/components/Link/Link.module.js +10 -0
  90. package/components/List/List.js +22 -46
  91. package/components/List/List.module.js +12 -0
  92. package/components/Loader/Loader.js +152 -182
  93. package/components/Loader/Loader.module.js +40 -0
  94. package/components/Modal/Modal.js +93 -105
  95. package/components/Modal/Modal.module.js +18 -0
  96. package/components/PageHeader/PageHeader.js +78 -72
  97. package/components/PageHeader/PageHeader.module.js +23 -0
  98. package/components/Pagination/Pagination.js +63 -84
  99. package/components/Pagination/Pagination.module.js +13 -0
  100. package/components/Pagination/paginationRange.js +15 -22
  101. package/components/Popover/Popover.js +110 -134
  102. package/components/Popover/Popover.module.js +12 -0
  103. package/components/ProgressBar/ProgressBar.d.ts +15 -1
  104. package/components/ProgressBar/ProgressBar.js +57 -90
  105. package/components/ProgressBar/ProgressBar.module.js +29 -0
  106. package/components/RelativeTime/RelativeTime.js +36 -43
  107. package/components/RelativeTime/RelativeTime.module.js +3 -0
  108. package/components/SegmentedControl/SegmentedControl.js +94 -130
  109. package/components/SegmentedControl/SegmentedControl.module.js +21 -0
  110. package/components/Skeleton/Skeleton.js +36 -50
  111. package/components/Skeleton/Skeleton.module.js +15 -0
  112. package/components/Spinner/Spinner.js +25 -25
  113. package/components/Spinner/Spinner.module.js +12 -0
  114. package/components/SplitButton/SplitButton.js +149 -196
  115. package/components/SplitButton/SplitButton.module.js +31 -0
  116. package/components/SplitPane/SplitPane.js +134 -170
  117. package/components/SplitPane/SplitPane.module.js +14 -0
  118. package/components/StatCard/StatCard.js +132 -125
  119. package/components/StatCard/StatCard.module.js +42 -0
  120. package/components/StatusDot/StatusDot.js +28 -39
  121. package/components/StatusDot/StatusDot.module.js +18 -0
  122. package/components/Table/Table.d.ts +1 -1
  123. package/components/Table/Table.js +381 -451
  124. package/components/Table/Table.module.js +42 -0
  125. package/components/Table/useTableSort.js +51 -42
  126. package/components/Tabs/Tabs.js +109 -161
  127. package/components/Tabs/Tabs.module.js +28 -0
  128. package/components/ThemeToggle/ThemeToggle.js +122 -98
  129. package/components/ThemeToggle/ThemeToggle.module.js +13 -0
  130. package/components/Timeline/GanttTimeline.js +357 -318
  131. package/components/Timeline/GanttTimeline.module.js +29 -0
  132. package/components/Timeline/HistoryTimeline.js +486 -450
  133. package/components/Timeline/HistoryTimeline.module.js +31 -0
  134. package/components/Timeline/Timeline.module.js +76 -0
  135. package/components/Timeline/TimelineShared.d.ts +7 -7
  136. package/components/Timeline/TimelineShared.js +288 -279
  137. package/components/Timeline/TraceEventDetails.d.ts +3 -3
  138. package/components/Timeline/TraceEventDetails.js +245 -178
  139. package/components/Timeline/TraceTimeline.js +823 -783
  140. package/components/Timeline/TraceTimeline.module.js +98 -0
  141. package/components/Timeline/historyLayout.js +336 -263
  142. package/components/Timeline/timelineCore.js +208 -183
  143. package/components/Timeline/traceEvent.js +59 -61
  144. package/components/Timeline/traceLayout.js +101 -90
  145. package/components/Timeline/useTimeline.js +76 -79
  146. package/components/Timer/Timer.js +190 -156
  147. package/components/Timer/Timer.module.js +29 -0
  148. package/components/Toast/Toast.d.ts +1 -1
  149. package/components/Toast/Toast.js +128 -128
  150. package/components/Toast/Toast.module.js +37 -0
  151. package/components/Toast/toastStore.js +58 -62
  152. package/components/ToggleIconButton/ToggleIconButton.js +35 -57
  153. package/components/ToggleIconButton/ToggleIconButton.module.js +15 -0
  154. package/components/Tooltip/Tooltip.d.ts +1 -1
  155. package/components/Tooltip/Tooltip.js +76 -85
  156. package/components/Tooltip/Tooltip.module.js +17 -0
  157. package/components/Typography/Typography.js +11 -36
  158. package/components/Typography/Typography.module.js +30 -0
  159. package/components/inputs/Checkbox/Checkbox.js +27 -51
  160. package/components/inputs/Checkbox/Checkbox.module.js +10 -0
  161. package/components/inputs/Checkbox/CheckboxGroup.js +53 -111
  162. package/components/inputs/Checkbox/CheckboxGroup.module.js +17 -0
  163. package/components/inputs/DatePicker/CalendarPanel.d.ts +1 -1
  164. package/components/inputs/DatePicker/CalendarPanel.js +263 -286
  165. package/components/inputs/DatePicker/CalendarPanel.module.js +23 -0
  166. package/components/inputs/DatePicker/DatePicker.js +115 -142
  167. package/components/inputs/DatePicker/DatePicker.module.js +14 -0
  168. package/components/inputs/DatePicker/dateUtils.js +32 -41
  169. package/components/inputs/DateTimePicker/DateTimePicker.js +226 -232
  170. package/components/inputs/DateTimePicker/DateTimePicker.module.js +20 -0
  171. package/components/inputs/DateTimePicker/DateTimeSegments.js +273 -252
  172. package/components/inputs/DateTimePicker/TimeField.d.ts +1 -1
  173. package/components/inputs/DateTimePicker/TimeField.js +131 -132
  174. package/components/inputs/DateTimePicker/timeZoneUtils.js +95 -92
  175. package/components/inputs/Input/Input.js +98 -109
  176. package/components/inputs/Input/Input.module.js +15 -0
  177. package/components/inputs/NumberInput/NumberInput.js +112 -132
  178. package/components/inputs/NumberInput/NumberInput.module.js +14 -0
  179. package/components/inputs/Radio/Radio.js +50 -73
  180. package/components/inputs/Radio/Radio.module.js +9 -0
  181. package/components/inputs/SearchInput/SearchInput.js +98 -115
  182. package/components/inputs/SearchInput/SearchInput.module.js +8 -0
  183. package/components/inputs/Select/Select.js +555 -682
  184. package/components/inputs/Select/Select.module.js +38 -0
  185. package/components/inputs/Slider/Slider.js +97 -128
  186. package/components/inputs/Slider/Slider.module.js +9 -0
  187. package/components/inputs/Switch/Switch.js +11 -8
  188. package/components/inputs/Textarea/Textarea.js +42 -58
  189. package/components/inputs/Textarea/Textarea.module.js +14 -0
  190. package/hooks/useClickOutside.js +17 -14
  191. package/hooks/useDebouncedValue.js +13 -14
  192. package/hooks/useElementSize.js +27 -22
  193. package/hooks/useEscapeLayer.js +28 -29
  194. package/hooks/useFocusTrap.js +27 -38
  195. package/hooks/useKeyboard.js +76 -64
  196. package/hooks/useMediaQuery.js +10 -15
  197. package/hooks/useNow.js +28 -33
  198. package/hooks/usePersistedState.js +98 -94
  199. package/hooks/usePortalPosition.js +25 -19
  200. package/hooks/useResizable.js +106 -104
  201. package/hooks/useTheme.js +28 -23
  202. package/index.css +2 -1
  203. package/index.js +97 -215
  204. package/index.layered.css +2 -3
  205. package/llms.txt +3 -0
  206. package/manifest.json +8 -0
  207. package/package.json +1 -1
  208. package/utils/formatBytes.js +29 -13
  209. package/utils/themeScript.js +6 -8
  210. package/utils/timeAgo.js +59 -32
  211. package/components/Accordion/Accordion.module.scss.js +0 -36
  212. package/components/ActionButton/ActionButton.module.scss.js +0 -47
  213. package/components/Alert/Alert.module.scss.js +0 -33
  214. package/components/Avatar/Avatar.module.scss.js +0 -43
  215. package/components/Badge/Badge.module.scss.js +0 -31
  216. package/components/Breadcrumbs/Breadcrumbs.module.scss.js +0 -17
  217. package/components/Button/Button.module.scss.js +0 -47
  218. package/components/Card/Card.module.scss.js +0 -60
  219. package/components/Chart/Chart.module.scss.js +0 -61
  220. package/components/Chip/Chip.module.scss.js +0 -59
  221. package/components/CodeBlock/CodeBlock.module.scss.js +0 -43
  222. package/components/CommandPalette/CommandPalette.module.scss.js +0 -49
  223. package/components/ConfirmDialog/ConfirmDialog.module.scss.js +0 -21
  224. package/components/Divider/Divider.module.scss.js +0 -31
  225. package/components/Draggable/Draggable.module.scss.js +0 -17
  226. package/components/Drawer/Drawer.module.scss.js +0 -119
  227. package/components/Dropdown/Dropdown.module.scss.js +0 -53
  228. package/components/Dropzone/Dropzone.module.scss.js +0 -21
  229. package/components/EmptyState/EmptyState.module.scss.js +0 -25
  230. package/components/Form/Form.module.scss.js +0 -29
  231. package/components/ImageViewer/ImageViewer.module.scss.js +0 -47
  232. package/components/Kbd/Kbd.module.scss.js +0 -17
  233. package/components/KeyValueList/KeyValueList.module.scss.js +0 -43
  234. package/components/Link/Link.module.scss.js +0 -16
  235. package/components/List/List.module.scss.js +0 -21
  236. package/components/Loader/Loader.module.scss.js +0 -70
  237. package/components/Modal/Modal.module.scss.js +0 -33
  238. package/components/PageHeader/PageHeader.module.scss.js +0 -43
  239. package/components/Pagination/Pagination.module.scss.js +0 -23
  240. package/components/Popover/Popover.module.scss.js +0 -21
  241. package/components/ProgressBar/ProgressBar.module.scss.js +0 -51
  242. package/components/RelativeTime/RelativeTime.module.scss.js +0 -7
  243. package/components/SegmentedControl/SegmentedControl.module.scss.js +0 -39
  244. package/components/Skeleton/Skeleton.module.scss.js +0 -25
  245. package/components/Spinner/Spinner.module.scss.js +0 -20
  246. package/components/SplitButton/SplitButton.module.scss.js +0 -57
  247. package/components/SplitPane/SplitPane.module.scss.js +0 -25
  248. package/components/StatCard/StatCard.module.scss.js +0 -72
  249. package/components/StatusDot/StatusDot.module.scss.js +0 -32
  250. package/components/Table/Table.module.scss.js +0 -81
  251. package/components/Tabs/Tabs.module.scss.js +0 -53
  252. package/components/ThemeToggle/ThemeToggle.module.scss.js +0 -23
  253. package/components/Timeline/GanttTimeline.module.scss.js +0 -55
  254. package/components/Timeline/HistoryTimeline.module.scss.js +0 -59
  255. package/components/Timeline/Timeline.module.scss.js +0 -141
  256. package/components/Timeline/TraceTimeline.module.scss.js +0 -189
  257. package/components/Timer/Timer.module.scss.js +0 -55
  258. package/components/Toast/Toast.module.scss.js +0 -62
  259. package/components/ToggleIconButton/ToggleIconButton.module.scss.js +0 -27
  260. package/components/Tooltip/Tooltip.module.scss.js +0 -30
  261. package/components/Typography/Typography.module.scss.js +0 -53
  262. package/components/inputs/Checkbox/Checkbox.module.scss.js +0 -17
  263. package/components/inputs/Checkbox/CheckboxGroup.module.scss.js +0 -31
  264. package/components/inputs/DatePicker/CalendarPanel.module.scss.js +0 -41
  265. package/components/inputs/DatePicker/DatePicker.module.scss.js +0 -25
  266. package/components/inputs/DateTimePicker/DateTimePicker.module.scss.js +0 -37
  267. package/components/inputs/Input/Input.module.scss.js +0 -27
  268. package/components/inputs/NumberInput/NumberInput.module.scss.js +0 -25
  269. package/components/inputs/Radio/Radio.module.scss.js +0 -15
  270. package/components/inputs/SearchInput/SearchInput.module.scss.js +0 -13
  271. package/components/inputs/Select/Select.module.scss.js +0 -73
  272. package/components/inputs/Slider/Slider.module.scss.js +0 -15
  273. package/components/inputs/Textarea/Textarea.module.scss.js +0 -25
@@ -1,201 +1,312 @@
1
- import { jsx as e, jsxs as f, Fragment as ce } from "react/jsx-runtime";
2
- import { forwardRef as de, useState as O, useRef as C, useCallback as P, useEffect as z, useId as ue } from "react";
3
- import { createPortal as me } from "react-dom";
4
- import c from "clsx";
5
- import t from "./ImageViewer.module.scss.js";
6
- import { useFocusTrap as he } from "../../hooks/useFocusTrap.js";
7
- import { useEscapeLayer as fe, EscapeLayerProvider as pe } from "../../hooks/useEscapeLayer.js";
8
- import { useKeyboard as ve } from "../../hooks/useKeyboard.js";
9
- import { Spinner as be } from "../Spinner/Spinner.js";
10
- import { useZoomPan as ge } from "./useZoomPan.js";
11
- const ye = {
12
- viewer: "Image viewer",
13
- close: "Close",
14
- previous: "Previous image",
15
- next: "Next image",
16
- zoomIn: "Zoom in",
17
- zoomOut: "Zoom out",
18
- reset: "Reset zoom",
19
- fit: "Fit to screen",
20
- download: "Download",
21
- loading: "Loading image"
22
- }, ke = 60, we = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ e("path", { d: "M5 5l10 10M15 5L5 15" }) }), T = ({ dir: d }) => /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: d === "left" ? /* @__PURE__ */ e("path", { d: "M12.5 4.5L7 10l5.5 5.5" }) : /* @__PURE__ */ e("path", { d: "M7.5 4.5L13 10l-5.5 5.5" }) }), Ne = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ e("path", { d: "M10 3v10m0 0l-4-4m4 4l4-4M4 16h12" }) }), xe = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ e("path", { d: "M4 10a6 6 0 1 1 1.8 4.3M4 15v-4h4" }) }), Le = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ e("path", { d: "M3 8V3h5M12 3h5v5M17 12v5h-5M8 17H3v-5" }) }), Ie = de(
23
- ({
24
- open: d,
25
- onClose: y,
26
- items: m,
27
- index: R,
28
- defaultIndex: Z = 0,
29
- onIndexChange: E,
30
- loop: v = !0,
31
- showCounter: H = !0,
32
- showThumbnails: U = !1,
33
- showZoomControls: V = !0,
34
- showDownload: $,
35
- renderSlide: D,
36
- closeOnBackdrop: _ = !0,
37
- zoom: X,
38
- labels: Y,
39
- classes: l,
40
- className: K,
41
- style: q
42
- }, b) => {
43
- const u = { ...ye, ...Y }, n = m.length, k = R !== void 0, [G, J] = O(Z), a = n === 0 ? 0 : Math.min(Math.max(0, k ? R : G), n - 1), s = m[a], B = C(null), Q = (o) => {
44
- B.current = o, typeof b == "function" ? b(o) : b && (b.current = o);
45
- }, i = ge(X), { reset: S, scale: j, isPanning: ee } = i, p = P(
46
- (o) => {
47
- if (n === 0) return;
48
- let r = o;
49
- v ? r = (o % n + n) % n : r = Math.min(Math.max(0, o), n - 1), r !== a && (k || J(r), E?.(r));
50
- },
51
- [n, v, a, k, E]
52
- ), w = v ? n > 1 : a > 0, N = v ? n > 1 : a < n - 1, x = P(() => w && p(a - 1), [w, p, a]), L = P(() => N && p(a + 1), [N, p, a]), [A, I] = O(!1);
53
- z(() => {
54
- I(!1), S();
55
- }, [a, s?.src, S]), z(() => {
56
- if (!d || n < 2 || typeof Image > "u") return;
57
- const o = [m[(a + 1) % n], m[(a - 1 + n) % n]];
58
- for (const r of o) {
59
- if (!r) continue;
60
- const h = new Image();
61
- h.src = r.src;
62
- }
63
- }, [d, a, m, n]), he(B, d);
64
- const te = fe(() => y(), d);
65
- z(() => {
66
- if (!d) return;
67
- const o = document.body.style.overflow;
68
- return document.body.style.overflow = "hidden", () => {
69
- document.body.style.overflow = o;
70
- };
71
- }, [d]), ve(
72
- {
73
- ArrowLeft: x,
74
- ArrowRight: L,
75
- "+": i.zoomIn,
76
- "=": i.zoomIn,
77
- "-": i.zoomOut,
78
- 0: i.reset
79
- },
80
- { active: d, ignoreEditable: !0 }
81
- );
82
- const M = C(null), g = C(!1), oe = (o) => {
83
- M.current = { x: o.clientX ?? 0, y: o.clientY ?? 0 }, g.current = !1, i.stageProps.onPointerDown(o);
84
- }, ne = (o) => {
85
- i.stageProps.onPointerUp(o);
86
- const r = M.current;
87
- if (M.current = null, !r) return;
88
- const h = (o.clientX ?? 0) - r.x, F = (o.clientY ?? 0) - r.y;
89
- Math.hypot(h, F) >= 5 && (g.current = !0), j === 1 && Math.abs(h) > ke && Math.abs(h) > Math.abs(F) && (h < 0 ? L() : x());
90
- }, re = (o) => {
91
- const r = g.current;
92
- g.current = !1, !(!_ || r) && o.target === o.currentTarget && y();
93
- }, ae = ue();
94
- if (!d || n === 0 || !s) return null;
95
- const ie = $ ?? !!s.download, le = typeof s.download == "string" ? s.download : s.src, W = D ? D(s, { index: a, active: !0 }) : null, se = `${Math.round(j * 100)}%`;
96
- return me(
97
- /* @__PURE__ */ e(
98
- "div",
99
- {
100
- ref: Q,
101
- className: c(t.root, l?.root, K),
102
- style: q,
103
- role: "dialog",
104
- "aria-modal": "true",
105
- "aria-label": s.alt || u.viewer,
106
- "data-index": a,
107
- children: /* @__PURE__ */ f(pe, { value: te, children: [
108
- /* @__PURE__ */ e("div", { className: c(t.backdrop, l?.backdrop), "aria-hidden": "true" }),
109
- /* @__PURE__ */ f("div", { className: c(t.toolbar, l?.toolbar), children: [
110
- H && n > 1 && /* @__PURE__ */ f("span", { className: c(t.counter, l?.counter), "aria-live": "polite", children: [
111
- a + 1,
112
- " / ",
113
- n
114
- ] }),
115
- /* @__PURE__ */ e("span", { className: t.spacer }),
116
- V && /* @__PURE__ */ f("div", { className: c(t.zoomControls, l?.zoomControls), role: "group", "aria-label": "Zoom", children: [
117
- /* @__PURE__ */ e("button", { type: "button", className: t.control, onClick: i.zoomOut, "aria-label": u.zoomOut, children: "−" }),
118
- /* @__PURE__ */ e("span", { className: t.zoomValue, "data-testid": "zoom-value", children: se }),
119
- /* @__PURE__ */ e("button", { type: "button", className: t.control, onClick: i.zoomIn, "aria-label": u.zoomIn, children: "+" }),
120
- /* @__PURE__ */ e("button", { type: "button", className: t.control, onClick: i.reset, "aria-label": u.reset, children: /* @__PURE__ */ e(xe, {}) }),
121
- /* @__PURE__ */ e("button", { type: "button", className: t.control, onClick: i.fit, "aria-label": u.fit, children: /* @__PURE__ */ e(Le, {}) })
122
- ] }),
123
- ie && /* @__PURE__ */ e("a", { className: t.control, href: le, download: !0, "aria-label": u.download, target: "_blank", rel: "noreferrer", children: /* @__PURE__ */ e(Ne, {}) }),
124
- /* @__PURE__ */ e("button", { type: "button", className: t.control, onClick: y, "aria-label": u.close, children: /* @__PURE__ */ e(we, {}) })
125
- ] }),
126
- /* @__PURE__ */ f("div", { className: t.body, children: [
127
- n > 1 && w && /* @__PURE__ */ e(
128
- "button",
129
- {
130
- type: "button",
131
- className: c(t.nav, t.navPrev, l?.nav, l?.navPrev),
132
- onClick: x,
133
- "aria-label": u.previous,
134
- children: /* @__PURE__ */ e(T, { dir: "left" })
135
- }
136
- ),
137
- /* @__PURE__ */ e(
138
- "div",
139
- {
140
- className: c(t.stage, ee && t.panning, l?.stage),
141
- ...i.stageProps,
142
- onPointerDown: oe,
143
- onPointerUp: ne,
144
- onClick: re,
145
- style: i.stageProps.style,
146
- "data-testid": "image-viewer-stage",
147
- children: W ? /* @__PURE__ */ e("div", { ref: i.contentRef, className: c(t.image, l?.image), style: i.contentStyle, children: W }) : /* @__PURE__ */ f(ce, { children: [
148
- /* @__PURE__ */ e(
149
- "img",
150
- {
151
- ref: i.contentRef,
152
- className: c(t.image, !A && t.imageLoading, l?.image),
153
- style: i.contentStyle,
154
- src: s.src,
155
- alt: s.alt ?? "",
156
- draggable: !1,
157
- onLoad: () => I(!0),
158
- onError: () => I(!0)
159
- },
160
- s.src
161
- ),
162
- !A && /* @__PURE__ */ e("span", { className: t.spinner, children: /* @__PURE__ */ e(be, { size: "lg", label: u.loading }) })
163
- ] })
164
- }
165
- ),
166
- n > 1 && N && /* @__PURE__ */ e(
167
- "button",
168
- {
169
- type: "button",
170
- className: c(t.nav, t.navNext, l?.nav, l?.navNext),
171
- onClick: L,
172
- "aria-label": u.next,
173
- children: /* @__PURE__ */ e(T, { dir: "right" })
174
- }
175
- )
176
- ] }),
177
- s.caption && /* @__PURE__ */ e("div", { id: ae, className: c(t.caption, l?.caption), children: s.caption }),
178
- U && n > 1 && /* @__PURE__ */ e("div", { className: c(t.thumbnails, l?.thumbnails), role: "list", children: m.map((o, r) => /* @__PURE__ */ e(
179
- "button",
180
- {
181
- type: "button",
182
- role: "listitem",
183
- className: c(t.thumbnail, r === a && t.thumbnailActive, l?.thumbnail, r === a && l?.thumbnailActive),
184
- onClick: () => p(r),
185
- "aria-label": o.alt || `${r + 1}`,
186
- "aria-current": r === a ? "true" : void 0,
187
- children: /* @__PURE__ */ e("img", { src: o.thumbnail ?? o.src, alt: "", draggable: !1 })
188
- },
189
- `${o.src}-${r}`
190
- )) })
191
- ] })
192
- }
193
- ),
194
- document.body
195
- );
196
- }
197
- );
198
- Ie.displayName = "ImageViewer";
199
- export {
200
- Ie as ImageViewer
201
- };
1
+ import e from "./ImageViewer.module.js";
2
+ import { useFocusTrap as t } from "../../hooks/useFocusTrap.js";
3
+ import { EscapeLayerProvider as n, useEscapeLayer as r } from "../../hooks/useEscapeLayer.js";
4
+ import { useKeyboard as i } from "../../hooks/useKeyboard.js";
5
+ import { Spinner as a } from "../Spinner/Spinner.js";
6
+ import { useZoomPan as o } from "./useZoomPan.js";
7
+ import { forwardRef as s, useCallback as c, useEffect as l, useId as u, useRef as d, useState as f } from "react";
8
+ import p from "clsx";
9
+ import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
10
+ import { createPortal as ee } from "react-dom";
11
+ // src/components/ImageViewer/ImageViewer.tsx
12
+ var te = {
13
+ viewer: "Image viewer",
14
+ close: "Close",
15
+ previous: "Previous image",
16
+ next: "Next image",
17
+ zoomIn: "Zoom in",
18
+ zoomOut: "Zoom out",
19
+ reset: "Reset zoom",
20
+ fit: "Fit to screen",
21
+ download: "Download",
22
+ loading: "Loading image"
23
+ }, ne = 60, _ = () => /* @__PURE__ */ h("svg", {
24
+ viewBox: "0 0 20 20",
25
+ fill: "none",
26
+ stroke: "currentColor",
27
+ strokeWidth: "2",
28
+ strokeLinecap: "round",
29
+ "aria-hidden": "true",
30
+ children: /* @__PURE__ */ h("path", { d: "M5 5l10 10M15 5L5 15" })
31
+ }), v = ({ dir: e }) => /* @__PURE__ */ h("svg", {
32
+ viewBox: "0 0 20 20",
33
+ fill: "none",
34
+ stroke: "currentColor",
35
+ strokeWidth: "2",
36
+ strokeLinecap: "round",
37
+ strokeLinejoin: "round",
38
+ "aria-hidden": "true",
39
+ children: e === "left" ? /* @__PURE__ */ h("path", { d: "M12.5 4.5L7 10l5.5 5.5" }) : /* @__PURE__ */ h("path", { d: "M7.5 4.5L13 10l-5.5 5.5" })
40
+ }), y = () => /* @__PURE__ */ h("svg", {
41
+ viewBox: "0 0 20 20",
42
+ fill: "none",
43
+ stroke: "currentColor",
44
+ strokeWidth: "1.8",
45
+ strokeLinecap: "round",
46
+ strokeLinejoin: "round",
47
+ "aria-hidden": "true",
48
+ children: /* @__PURE__ */ h("path", { d: "M10 3v10m0 0l-4-4m4 4l4-4M4 16h12" })
49
+ }), b = () => /* @__PURE__ */ h("svg", {
50
+ viewBox: "0 0 20 20",
51
+ fill: "none",
52
+ stroke: "currentColor",
53
+ strokeWidth: "1.8",
54
+ strokeLinecap: "round",
55
+ strokeLinejoin: "round",
56
+ "aria-hidden": "true",
57
+ children: /* @__PURE__ */ h("path", { d: "M4 10a6 6 0 1 1 1.8 4.3M4 15v-4h4" })
58
+ }), x = () => /* @__PURE__ */ h("svg", {
59
+ viewBox: "0 0 20 20",
60
+ fill: "none",
61
+ stroke: "currentColor",
62
+ strokeWidth: "1.8",
63
+ strokeLinecap: "round",
64
+ strokeLinejoin: "round",
65
+ "aria-hidden": "true",
66
+ children: /* @__PURE__ */ h("path", { d: "M3 8V3h5M12 3h5v5M17 12v5h-5M8 17H3v-5" })
67
+ }), S = s(({ open: s, onClose: S, items: C, index: w, defaultIndex: T = 0, onIndexChange: E, loop: D = !0, showCounter: re = !0, showThumbnails: ie = !1, showZoomControls: ae = !0, showDownload: oe, renderSlide: O, closeOnBackdrop: se = !0, zoom: ce, labels: le, classes: k, className: ue, style: de }, A) => {
68
+ let j = {
69
+ ...te,
70
+ ...le
71
+ }, M = C.length, N = w !== void 0, [P, F] = f(T), I = M === 0 ? 0 : Math.min(Math.max(0, N ? w : P), M - 1), L = C[I], R = d(null), z = (e) => {
72
+ R.current = e, typeof A == "function" ? A(e) : A && (A.current = e);
73
+ }, B = o(ce), { reset: V, scale: H, isPanning: fe } = B, U = c((e) => {
74
+ if (M === 0) return;
75
+ let t = e;
76
+ t = D ? (e % M + M) % M : Math.min(Math.max(0, e), M - 1), t !== I && (N || F(t), E?.(t));
77
+ }, [
78
+ M,
79
+ D,
80
+ I,
81
+ N,
82
+ E
83
+ ]), W = D ? M > 1 : I > 0, G = D ? M > 1 : I < M - 1, K = c(() => W && U(I - 1), [
84
+ W,
85
+ U,
86
+ I
87
+ ]), q = c(() => G && U(I + 1), [
88
+ G,
89
+ U,
90
+ I
91
+ ]), [J, Y] = f(!1);
92
+ l(() => {
93
+ Y(!1), V();
94
+ }, [
95
+ I,
96
+ L?.src,
97
+ V
98
+ ]), l(() => {
99
+ if (!s || M < 2 || typeof Image > "u") return;
100
+ let e = [C[(I + 1) % M], C[(I - 1 + M) % M]];
101
+ for (let t of e) {
102
+ if (!t) continue;
103
+ let e = new Image();
104
+ e.src = t.src;
105
+ }
106
+ }, [
107
+ s,
108
+ I,
109
+ C,
110
+ M
111
+ ]), t(R, s);
112
+ let pe = r(() => S(), s);
113
+ l(() => {
114
+ if (!s) return;
115
+ let e = document.body.style.overflow;
116
+ return document.body.style.overflow = "hidden", () => {
117
+ document.body.style.overflow = e;
118
+ };
119
+ }, [s]), i({
120
+ ArrowLeft: K,
121
+ ArrowRight: q,
122
+ "+": B.zoomIn,
123
+ "=": B.zoomIn,
124
+ "-": B.zoomOut,
125
+ 0: B.reset
126
+ }, {
127
+ active: s,
128
+ ignoreEditable: !0
129
+ });
130
+ let X = d(null), Z = d(!1), me = (e) => {
131
+ X.current = {
132
+ x: e.clientX ?? 0,
133
+ y: e.clientY ?? 0
134
+ }, Z.current = !1, B.stageProps.onPointerDown(e);
135
+ }, Q = (e) => {
136
+ B.stageProps.onPointerUp(e);
137
+ let t = X.current;
138
+ if (X.current = null, !t) return;
139
+ let n = (e.clientX ?? 0) - t.x, r = (e.clientY ?? 0) - t.y;
140
+ Math.hypot(n, r) >= 5 && (Z.current = !0), H === 1 && Math.abs(n) > ne && Math.abs(n) > Math.abs(r) && (n < 0 ? q() : K());
141
+ }, he = (e) => {
142
+ let t = Z.current;
143
+ Z.current = !1, se && !t && e.target === e.currentTarget && S();
144
+ }, ge = u();
145
+ if (!s || M === 0 || !L) return null;
146
+ let _e = oe ?? !!L.download, ve = typeof L.download == "string" ? L.download : L.src, $ = O ? O(L, {
147
+ index: I,
148
+ active: !0
149
+ }) : null, ye = `${Math.round(H * 100)}%`;
150
+ return ee(/* @__PURE__ */ h("div", {
151
+ ref: z,
152
+ className: p(e.root, k?.root, ue),
153
+ style: de,
154
+ role: "dialog",
155
+ "aria-modal": "true",
156
+ "aria-label": L.alt || j.viewer,
157
+ "data-index": I,
158
+ children: /* @__PURE__ */ g(n, {
159
+ value: pe,
160
+ children: [
161
+ /* @__PURE__ */ h("div", {
162
+ className: p(e.backdrop, k?.backdrop),
163
+ "aria-hidden": "true"
164
+ }),
165
+ /* @__PURE__ */ g("div", {
166
+ className: p(e.toolbar, k?.toolbar),
167
+ children: [
168
+ re && M > 1 && /* @__PURE__ */ g("span", {
169
+ className: p(e.counter, k?.counter),
170
+ "aria-live": "polite",
171
+ children: [
172
+ I + 1,
173
+ " / ",
174
+ M
175
+ ]
176
+ }),
177
+ /* @__PURE__ */ h("span", { className: e.spacer }),
178
+ ae && /* @__PURE__ */ g("div", {
179
+ className: p(e.zoomControls, k?.zoomControls),
180
+ role: "group",
181
+ "aria-label": "Zoom",
182
+ children: [
183
+ /* @__PURE__ */ h("button", {
184
+ type: "button",
185
+ className: e.control,
186
+ onClick: B.zoomOut,
187
+ "aria-label": j.zoomOut,
188
+ children: "−"
189
+ }),
190
+ /* @__PURE__ */ h("span", {
191
+ className: e.zoomValue,
192
+ "data-testid": "zoom-value",
193
+ children: ye
194
+ }),
195
+ /* @__PURE__ */ h("button", {
196
+ type: "button",
197
+ className: e.control,
198
+ onClick: B.zoomIn,
199
+ "aria-label": j.zoomIn,
200
+ children: "+"
201
+ }),
202
+ /* @__PURE__ */ h("button", {
203
+ type: "button",
204
+ className: e.control,
205
+ onClick: B.reset,
206
+ "aria-label": j.reset,
207
+ children: /* @__PURE__ */ h(b, {})
208
+ }),
209
+ /* @__PURE__ */ h("button", {
210
+ type: "button",
211
+ className: e.control,
212
+ onClick: B.fit,
213
+ "aria-label": j.fit,
214
+ children: /* @__PURE__ */ h(x, {})
215
+ })
216
+ ]
217
+ }),
218
+ _e && /* @__PURE__ */ h("a", {
219
+ className: e.control,
220
+ href: ve,
221
+ download: !0,
222
+ "aria-label": j.download,
223
+ target: "_blank",
224
+ rel: "noreferrer",
225
+ children: /* @__PURE__ */ h(y, {})
226
+ }),
227
+ /* @__PURE__ */ h("button", {
228
+ type: "button",
229
+ className: e.control,
230
+ onClick: S,
231
+ "aria-label": j.close,
232
+ children: /* @__PURE__ */ h(_, {})
233
+ })
234
+ ]
235
+ }),
236
+ /* @__PURE__ */ g("div", {
237
+ className: e.body,
238
+ children: [
239
+ M > 1 && W && /* @__PURE__ */ h("button", {
240
+ type: "button",
241
+ className: p(e.nav, e.navPrev, k?.nav, k?.navPrev),
242
+ onClick: K,
243
+ "aria-label": j.previous,
244
+ children: /* @__PURE__ */ h(v, { dir: "left" })
245
+ }),
246
+ /* @__PURE__ */ h("div", {
247
+ className: p(e.stage, fe && e.panning, k?.stage),
248
+ ...B.stageProps,
249
+ onPointerDown: me,
250
+ onPointerUp: Q,
251
+ onClick: he,
252
+ style: B.stageProps.style,
253
+ "data-testid": "image-viewer-stage",
254
+ children: $ ? /* @__PURE__ */ h("div", {
255
+ ref: B.contentRef,
256
+ className: p(e.image, k?.image),
257
+ style: B.contentStyle,
258
+ children: $
259
+ }) : /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h("img", {
260
+ ref: B.contentRef,
261
+ className: p(e.image, !J && e.imageLoading, k?.image),
262
+ style: B.contentStyle,
263
+ src: L.src,
264
+ alt: L.alt ?? "",
265
+ draggable: !1,
266
+ onLoad: () => Y(!0),
267
+ onError: () => Y(!0)
268
+ }, L.src), !J && /* @__PURE__ */ h("span", {
269
+ className: e.spinner,
270
+ children: /* @__PURE__ */ h(a, {
271
+ size: "lg",
272
+ label: j.loading
273
+ })
274
+ })] })
275
+ }),
276
+ M > 1 && G && /* @__PURE__ */ h("button", {
277
+ type: "button",
278
+ className: p(e.nav, e.navNext, k?.nav, k?.navNext),
279
+ onClick: q,
280
+ "aria-label": j.next,
281
+ children: /* @__PURE__ */ h(v, { dir: "right" })
282
+ })
283
+ ]
284
+ }),
285
+ L.caption && /* @__PURE__ */ h("div", {
286
+ id: ge,
287
+ className: p(e.caption, k?.caption),
288
+ children: L.caption
289
+ }),
290
+ ie && M > 1 && /* @__PURE__ */ h("div", {
291
+ className: p(e.thumbnails, k?.thumbnails),
292
+ role: "list",
293
+ children: C.map((t, n) => /* @__PURE__ */ h("button", {
294
+ type: "button",
295
+ role: "listitem",
296
+ className: p(e.thumbnail, n === I && e.thumbnailActive, k?.thumbnail, n === I && k?.thumbnailActive),
297
+ onClick: () => U(n),
298
+ "aria-label": t.alt || `${n + 1}`,
299
+ "aria-current": n === I ? "true" : void 0,
300
+ children: /* @__PURE__ */ h("img", {
301
+ src: t.thumbnail ?? t.src,
302
+ alt: "",
303
+ draggable: !1
304
+ })
305
+ }, `${t.src}-${n}`))
306
+ })
307
+ ]
308
+ })
309
+ }), document.body);
310
+ });
311
+ S.displayName = "ImageViewer";
312
+ export { S as ImageViewer };
@@ -0,0 +1,26 @@
1
+ // src/components/ImageViewer/ImageViewer.module.scss
2
+ var e = "crk-root-ONPec", t = "crk-viewerIn-LGN1N", n = "crk-backdrop-zT-Q5", r = "crk-toolbar-AnTEv", i = "crk-spacer-w02Ek", a = "crk-counter-VTMp2", o = "crk-zoomControls-7H0yp", s = "crk-zoomValue-SJmdu", c = "crk-control-PyHnZ", l = "crk-body-OJK4N", u = "crk-stage-e0AOa", d = "crk-image-m6tek", f = "crk-panning-KHk5X", p = "crk-imageLoading-jrFiP", m = "crk-spinner-eg9--", h = "crk-nav-Bejfo", g = "crk-navPrev-GAvIZ", _ = "crk-navNext-Ly2YK", v = "crk-caption-25w3Q", y = "crk-thumbnails-JZb4b", b = "crk-thumbnail-hzBpT", x = "crk-thumbnailActive-Pfwmf", S = {
3
+ root: e,
4
+ viewerIn: t,
5
+ backdrop: n,
6
+ toolbar: r,
7
+ spacer: i,
8
+ counter: a,
9
+ zoomControls: o,
10
+ zoomValue: s,
11
+ control: c,
12
+ body: l,
13
+ stage: u,
14
+ image: d,
15
+ panning: f,
16
+ imageLoading: p,
17
+ spinner: m,
18
+ nav: h,
19
+ navPrev: g,
20
+ navNext: _,
21
+ caption: v,
22
+ thumbnails: y,
23
+ thumbnail: b,
24
+ thumbnailActive: x
25
+ };
26
+ export { n as backdrop, l as body, v as caption, c as control, a as counter, S as default, d as image, p as imageLoading, h as nav, _ as navNext, g as navPrev, f as panning, e as root, i as spacer, m as spinner, u as stage, b as thumbnail, x as thumbnailActive, y as thumbnails, r as toolbar, t as viewerIn, o as zoomControls, s as zoomValue };