@godxjp/ui 5.0.2 → 6.0.1

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 (242) hide show
  1. package/README.md +101 -142
  2. package/dist/app/index.d.ts +140 -0
  3. package/dist/app/index.js +38 -0
  4. package/dist/app.prop-IobwLwaM.d.ts +90 -0
  5. package/dist/checkbox-NkFkqsQ8.d.ts +13 -0
  6. package/dist/chunk-2XW7J3EI.js +226 -0
  7. package/dist/chunk-3F2AKYRD.js +416 -0
  8. package/dist/chunk-3KPEZ5CF.js +37 -0
  9. package/dist/chunk-3UGU5TYP.js +89 -0
  10. package/dist/chunk-6RA3KSVK.js +588 -0
  11. package/dist/chunk-7NZFVD24.js +122 -0
  12. package/dist/chunk-7PWBC4BY.js +25 -0
  13. package/dist/chunk-7S7MYFXE.js +61 -0
  14. package/dist/chunk-7WRZG2IG.js +71 -0
  15. package/dist/chunk-B775Y6BE.js +1 -0
  16. package/dist/chunk-BHV2FUOA.js +111 -0
  17. package/dist/chunk-BI3HERR7.js +70 -0
  18. package/dist/chunk-BPSKQUL2.js +68 -0
  19. package/dist/chunk-CDWPQ5RP.js +187 -0
  20. package/dist/chunk-CP2LET6N.js +244 -0
  21. package/dist/chunk-CQBADMFG.js +20 -0
  22. package/dist/chunk-CRERCLIZ.js +33 -0
  23. package/dist/chunk-DU6ZYZRP.js +238 -0
  24. package/dist/chunk-DY5C44UP.js +55 -0
  25. package/dist/chunk-E4HJNQ62.js +117 -0
  26. package/dist/chunk-E76QIYSY.js +93 -0
  27. package/dist/chunk-F7PG4OEV.js +37 -0
  28. package/dist/chunk-GDSVW62T.js +171 -0
  29. package/dist/chunk-H2FHJOLU.js +178 -0
  30. package/dist/chunk-HJEBRCXL.js +55 -0
  31. package/dist/chunk-ICM6XBST.js +16 -0
  32. package/dist/chunk-IK7I3ABN.js +88 -0
  33. package/dist/chunk-L6J44O74.js +144 -0
  34. package/dist/chunk-LDSLS6HE.js +1 -0
  35. package/dist/chunk-LVNUHUEZ.js +191 -0
  36. package/dist/chunk-M64MVRLS.js +92 -0
  37. package/dist/chunk-NGQW3KEM.js +402 -0
  38. package/dist/chunk-NZ4FOC5N.js +559 -0
  39. package/dist/chunk-PIIRNAXA.js +26 -0
  40. package/dist/chunk-S66TJXJU.js +33 -0
  41. package/dist/chunk-SMLKNECP.js +133 -0
  42. package/dist/chunk-TAHBM3F2.js +66 -0
  43. package/dist/chunk-TO33OY4L.js +150 -0
  44. package/dist/chunk-TO7URV7U.js +51 -0
  45. package/dist/chunk-TOO5AEKL.js +81 -0
  46. package/dist/chunk-U3GHAOIJ.js +299 -0
  47. package/dist/chunk-U7N2A7A3.js +9 -0
  48. package/dist/chunk-UX634MYF.js +123 -0
  49. package/dist/chunk-V6UWJKZF.js +28 -0
  50. package/dist/chunk-VOHTRR5X.js +28 -0
  51. package/dist/chunk-WRFKVUPW.js +332 -0
  52. package/dist/chunk-WXW43RK5.js +24 -0
  53. package/dist/chunk-XG7XDYIM.js +60 -0
  54. package/dist/chunk-YFCQKO3B.js +842 -0
  55. package/dist/chunk-ZDWXGWLY.js +73 -0
  56. package/dist/chunk-ZLK5SPT6.js +11 -0
  57. package/dist/chunk-ZS6DTAM2.js +31 -0
  58. package/dist/chunk-ZT5UEUBO.js +1 -0
  59. package/dist/components/admin/index.d.ts +80 -0
  60. package/dist/components/admin/index.js +38 -0
  61. package/dist/components/data-display/badge.d.ts +12 -0
  62. package/dist/components/data-display/badge.js +3 -0
  63. package/dist/components/data-display/card.d.ts +87 -0
  64. package/dist/components/data-display/card.js +2 -0
  65. package/dist/components/data-display/index.d.ts +72 -0
  66. package/dist/components/data-display/index.js +89 -0
  67. package/dist/components/data-display/popover.d.ts +13 -0
  68. package/dist/components/data-display/popover.js +2 -0
  69. package/dist/components/data-display/scroll-area.d.ts +7 -0
  70. package/dist/components/data-display/scroll-area.js +2 -0
  71. package/dist/components/data-display/table.d.ts +10 -0
  72. package/dist/components/data-display/table.js +3 -0
  73. package/dist/components/data-entry/autocomplete.d.ts +16 -0
  74. package/dist/components/data-entry/autocomplete.js +8 -0
  75. package/dist/components/data-entry/calendar.d.ts +16 -0
  76. package/dist/components/data-entry/calendar.js +4 -0
  77. package/dist/components/data-entry/cascader.d.ts +32 -0
  78. package/dist/components/data-entry/cascader.js +13 -0
  79. package/dist/components/data-entry/checkbox.d.ts +13 -0
  80. package/dist/components/data-entry/checkbox.js +4 -0
  81. package/dist/components/data-entry/color-picker.d.ts +16 -0
  82. package/dist/components/data-entry/color-picker.js +6 -0
  83. package/dist/components/data-entry/command.d.ts +69 -0
  84. package/dist/components/data-entry/command.js +3 -0
  85. package/dist/components/data-entry/date-picker.d.ts +16 -0
  86. package/dist/components/data-entry/date-picker.js +8 -0
  87. package/dist/components/data-entry/date-range-picker.d.ts +16 -0
  88. package/dist/components/data-entry/date-range-picker.js +8 -0
  89. package/dist/components/data-entry/index.d.ts +53 -0
  90. package/dist/components/data-entry/index.js +152 -0
  91. package/dist/components/data-entry/input.d.ts +6 -0
  92. package/dist/components/data-entry/input.js +2 -0
  93. package/dist/components/data-entry/label.d.ts +8 -0
  94. package/dist/components/data-entry/label.js +2 -0
  95. package/dist/components/data-entry/radio.d.ts +24 -0
  96. package/dist/components/data-entry/radio.js +4 -0
  97. package/dist/components/data-entry/select.d.ts +18 -0
  98. package/dist/components/data-entry/select.js +3 -0
  99. package/dist/components/data-entry/slider.d.ts +16 -0
  100. package/dist/components/data-entry/slider.js +2 -0
  101. package/dist/components/data-entry/switch.d.ts +17 -0
  102. package/dist/components/data-entry/switch.js +2 -0
  103. package/dist/components/data-entry/textarea.d.ts +6 -0
  104. package/dist/components/data-entry/textarea.js +3 -0
  105. package/dist/components/data-entry/time-picker.d.ts +16 -0
  106. package/dist/components/data-entry/time-picker.js +7 -0
  107. package/dist/components/data-entry/transfer.d.ts +17 -0
  108. package/dist/components/data-entry/transfer.js +11 -0
  109. package/dist/components/data-entry/tree-select.d.ts +26 -0
  110. package/dist/components/data-entry/tree-select.js +13 -0
  111. package/dist/components/data-entry/upload.d.ts +42 -0
  112. package/dist/components/data-entry/upload.js +11 -0
  113. package/dist/components/feedback/alert.d.ts +60 -0
  114. package/dist/components/feedback/alert.js +7 -0
  115. package/dist/components/feedback/dialog.d.ts +64 -0
  116. package/dist/components/feedback/dialog.js +7 -0
  117. package/dist/components/feedback/index.d.ts +16 -0
  118. package/dist/components/feedback/index.js +14 -0
  119. package/dist/components/feedback/sheet.d.ts +24 -0
  120. package/dist/components/feedback/sheet.js +2 -0
  121. package/dist/components/feedback/sonner.d.ts +6 -0
  122. package/dist/components/feedback/sonner.js +1 -0
  123. package/dist/components/general/button.d.ts +20 -0
  124. package/dist/components/general/button.js +2 -0
  125. package/dist/components/general/index.d.ts +6 -0
  126. package/dist/components/general/index.js +2 -0
  127. package/dist/components/layout/index.d.ts +71 -0
  128. package/dist/components/layout/index.js +5 -0
  129. package/dist/components/navigation/dropdown-menu.d.ts +28 -0
  130. package/dist/components/navigation/dropdown-menu.js +2 -0
  131. package/dist/components/navigation/index.d.ts +32 -0
  132. package/dist/components/navigation/index.js +12 -0
  133. package/dist/components/navigation/pagination.d.ts +11 -0
  134. package/dist/components/navigation/pagination.js +7 -0
  135. package/dist/components/navigation/steps.d.ts +12 -0
  136. package/dist/components/navigation/steps.js +3 -0
  137. package/dist/components/navigation/tabs-items.d.ts +12 -0
  138. package/dist/components/navigation/tabs-items.js +3 -0
  139. package/dist/components/navigation/tabs.d.ts +12 -0
  140. package/dist/components/navigation/tabs.js +2 -0
  141. package/dist/components/query/index.d.ts +43 -0
  142. package/dist/components/query/index.js +8 -0
  143. package/dist/components/ui/index.d.ts +57 -0
  144. package/dist/components/ui/index.js +37 -0
  145. package/dist/content.prop-D1Dd3TAc.d.ts +31 -0
  146. package/dist/data-display.prop-DNTAzmDy.d.ts +58 -0
  147. package/dist/data-entry.prop-BEGA1lTq.d.ts +323 -0
  148. package/dist/data-table-D1u_rKLK.d.ts +83 -0
  149. package/dist/data.prop-BVvfKC_g.d.ts +41 -0
  150. package/dist/feedback.prop-BmxUlpAW.d.ts +64 -0
  151. package/dist/filter-bar-B7OGFO9S.d.ts +10 -0
  152. package/dist/form/index.d.ts +21 -0
  153. package/dist/form/index.js +4 -0
  154. package/dist/form.prop-BHgpuFFm.d.ts +41 -0
  155. package/dist/format-date-ByyZoqI5.d.ts +51 -0
  156. package/dist/general.prop-D7brMPNL.d.ts +16 -0
  157. package/dist/i18n/index.d.ts +217 -0
  158. package/dist/i18n/index.js +2 -0
  159. package/dist/index.d.ts +46 -26
  160. package/dist/index.js +39 -13062
  161. package/dist/inline-C5u6ptJV.d.ts +10 -0
  162. package/dist/interaction.prop-Cdn7wOtq.d.ts +25 -0
  163. package/dist/layout.prop-4TCNvyQZ.d.ts +20 -0
  164. package/dist/layout.prop-C795F0qg.d.ts +112 -0
  165. package/dist/lib/datetime/index.d.ts +31 -0
  166. package/dist/lib/datetime/index.js +1 -0
  167. package/dist/lib/utils.d.ts +5 -0
  168. package/dist/lib/utils.js +1 -0
  169. package/dist/navigation.prop-DpZqcXey.d.ts +78 -0
  170. package/dist/navigation.prop-DxBiClEH.d.ts +20 -0
  171. package/dist/props/components/index.d.ts +27 -0
  172. package/dist/props/components/index.js +1 -0
  173. package/dist/props/index.d.ts +28 -0
  174. package/dist/props/index.js +3 -0
  175. package/dist/props/registry.d.ts +649 -0
  176. package/dist/props/registry.js +1 -0
  177. package/dist/props/vocabulary/index.d.ts +7 -0
  178. package/dist/props/vocabulary/index.js +1 -0
  179. package/dist/query.prop-hIPrk2zI.d.ts +71 -0
  180. package/dist/search-input-uP01rY1L.d.ts +22 -0
  181. package/dist/shared.prop-BNRJc9K0.d.ts +45 -0
  182. package/dist/styles/alert-layout.css +191 -0
  183. package/dist/styles/badge-layout.css +22 -0
  184. package/dist/styles/card-layout.css +373 -0
  185. package/dist/styles/control.css +504 -0
  186. package/dist/styles/data-display-layout.css +246 -0
  187. package/dist/styles/density.css +43 -0
  188. package/dist/styles/dialog-layout.css +84 -0
  189. package/dist/styles/index.css +105 -0
  190. package/dist/styles/layout.css +479 -0
  191. package/dist/styles/shell-layout.css +604 -0
  192. package/dist/styles/table-layout.css +109 -0
  193. package/dist/theme/example.service.css +37 -0
  194. package/dist/tokens/base.css +13 -0
  195. package/dist/tokens/foundation.css +151 -0
  196. package/dist/tokens/primitives/badge.css +13 -0
  197. package/dist/tokens/primitives/card.css +29 -0
  198. package/dist/tokens/primitives/control.css +55 -0
  199. package/dist/tokens/primitives/feedback.css +17 -0
  200. package/dist/tokens/primitives/layout.css +20 -0
  201. package/dist/tokens/primitives/navigation.css +13 -0
  202. package/dist/tokens/primitives/table.css +10 -0
  203. package/dist/types-mvzYGrma.d.ts +37 -0
  204. package/dist/use-toast-Dol5bdY3.d.ts +34 -0
  205. package/package.json +279 -117
  206. package/scripts/ui-audit.mjs +179 -0
  207. package/BRAND.md +0 -296
  208. package/CHANGELOG.md +0 -668
  209. package/config/eslint.js +0 -54
  210. package/config/prettier.cjs +0 -20
  211. package/config/tsconfig.base.json +0 -22
  212. package/config/vitest.base.ts +0 -26
  213. package/dist/MiniMonth-YAmPGEpC.d.ts +0 -143
  214. package/dist/Table.types-BbsxoIYE.d.ts +0 -352
  215. package/dist/color-DO0qqUAb.d.ts +0 -38
  216. package/dist/components/composites.d.ts +0 -963
  217. package/dist/components/composites.js +0 -7343
  218. package/dist/components/composites.js.map +0 -1
  219. package/dist/components/primitives.d.ts +0 -2744
  220. package/dist/components/primitives.js +0 -7356
  221. package/dist/components/primitives.js.map +0 -1
  222. package/dist/components/shell.d.ts +0 -182
  223. package/dist/components/shell.js +0 -774
  224. package/dist/components/shell.js.map +0 -1
  225. package/dist/hooks.d.ts +0 -100
  226. package/dist/hooks.js +0 -558
  227. package/dist/hooks.js.map +0 -1
  228. package/dist/i18n.d.ts +0 -61
  229. package/dist/i18n.js +0 -860
  230. package/dist/i18n.js.map +0 -1
  231. package/dist/index.js.map +0 -1
  232. package/dist/padding-DY0JV5Ja.d.ts +0 -16
  233. package/dist/preferences.d.ts +0 -132
  234. package/dist/preferences.js +0 -262
  235. package/dist/preferences.js.map +0 -1
  236. package/dist/props.d.ts +0 -86
  237. package/dist/props.js +0 -16
  238. package/dist/props.js.map +0 -1
  239. package/dist/size-CQwNvOWd.d.ts +0 -19
  240. package/dist/types-LTj-2bl-.d.ts +0 -30
  241. package/dist/useTableViews-D5NIAJ7h.d.ts +0 -154
  242. package/src/tokens/tailwind.css +0 -158
@@ -0,0 +1,559 @@
1
+ import { Slider } from './chunk-CRERCLIZ.js';
2
+ import { controlIconClass } from './chunk-ICM6XBST.js';
3
+ import { formatBytes } from './chunk-7S7MYFXE.js';
4
+ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from './chunk-DU6ZYZRP.js';
5
+ import { Button } from './chunk-HJEBRCXL.js';
6
+ import { useTranslation } from './chunk-3F2AKYRD.js';
7
+ import { cn } from './chunk-U7N2A7A3.js';
8
+ import * as React2 from 'react';
9
+ import { Upload as Upload$1, ImagePlus, Camera, Trash2, RotateCcw, X } from 'lucide-react';
10
+ import { jsxs, jsx } from 'react/jsx-runtime';
11
+
12
+ function UploadCropDialog({ open, onOpenChange, file, onConfirm }) {
13
+ const { t } = useTranslation();
14
+ const [scale, setScale] = React2.useState(1.2);
15
+ const [src, setSrc] = React2.useState(null);
16
+ const imgRef = React2.useRef(null);
17
+ React2.useEffect(() => {
18
+ if (!file) {
19
+ setSrc(null);
20
+ return;
21
+ }
22
+ const url = URL.createObjectURL(file);
23
+ setSrc(url);
24
+ return () => URL.revokeObjectURL(url);
25
+ }, [file]);
26
+ const handleConfirm = async () => {
27
+ const img = imgRef.current;
28
+ if (!img || !file) return;
29
+ const size = 256;
30
+ const canvas = document.createElement("canvas");
31
+ canvas.width = size;
32
+ canvas.height = size;
33
+ const ctx = canvas.getContext("2d");
34
+ if (!ctx) return;
35
+ const iw = img.naturalWidth;
36
+ const ih = img.naturalHeight;
37
+ const side = Math.min(iw, ih) / scale;
38
+ const sx = (iw - side) / 2;
39
+ const sy = (ih - side) / 2;
40
+ ctx.drawImage(img, sx, sy, side, side, 0, 0, size, size);
41
+ const blob = await new Promise(
42
+ (resolve) => canvas.toBlob(resolve, "image/jpeg", 0.92)
43
+ );
44
+ if (!blob) return;
45
+ const cropped = new File([blob], file.name.replace(/\.\w+$/, "") + ".jpg", {
46
+ type: "image/jpeg"
47
+ });
48
+ onConfirm(cropped);
49
+ onOpenChange(false);
50
+ };
51
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(DialogContent, { className: "max-w-sm", children: [
52
+ /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: t("dataEntry.upload.cropTitle") }) }),
53
+ /* @__PURE__ */ jsxs("div", { className: "ui-stack-sm", children: [
54
+ /* @__PURE__ */ jsx(
55
+ "div",
56
+ {
57
+ className: cn(
58
+ "bg-muted relative mx-auto size-48 overflow-hidden rounded-full border",
59
+ "flex items-center justify-center"
60
+ ),
61
+ children: src ? /* @__PURE__ */ jsx(
62
+ "img",
63
+ {
64
+ ref: imgRef,
65
+ src,
66
+ alt: "",
67
+ className: "size-full object-cover transition-transform duration-150",
68
+ style: { transform: `scale(${scale})` }
69
+ }
70
+ ) : null
71
+ }
72
+ ),
73
+ /* @__PURE__ */ jsxs("div", { className: "ui-stack-xs px-2", children: [
74
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: t("dataEntry.upload.cropZoom") }),
75
+ /* @__PURE__ */ jsx(
76
+ Slider,
77
+ {
78
+ min: 1,
79
+ max: 2.5,
80
+ step: 0.05,
81
+ value: [scale],
82
+ onValueChange: (v) => setScale(v[0] ?? 1),
83
+ "aria-label": t("dataEntry.upload.cropZoom")
84
+ }
85
+ )
86
+ ] })
87
+ ] }),
88
+ /* @__PURE__ */ jsxs(DialogFooter, { children: [
89
+ /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => onOpenChange(false), children: t("common.cancel") }),
90
+ /* @__PURE__ */ jsx(Button, { onClick: () => void handleConfirm(), children: t("dataEntry.upload.cropConfirm") })
91
+ ] })
92
+ ] }) });
93
+ }
94
+
95
+ // src/components/data-entry/upload-types.ts
96
+ function createUploadItem(file, partial) {
97
+ const previewUrl = file.type.startsWith("image/") ? URL.createObjectURL(file) : void 0;
98
+ return {
99
+ uid: partial?.uid ?? crypto.randomUUID(),
100
+ name: file.name,
101
+ size: file.size,
102
+ mimeType: file.type,
103
+ previewUrl,
104
+ status: "idle",
105
+ file,
106
+ ...partial
107
+ };
108
+ }
109
+ function revokePreviewUrl(item) {
110
+ if (item?.previewUrl?.startsWith("blob:")) URL.revokeObjectURL(item.previewUrl);
111
+ }
112
+ function collectUploadCommitActions(items) {
113
+ const deleteMediaIds = [];
114
+ const promoteMediaIds = [];
115
+ for (const item of items) {
116
+ if (item.pendingDelete && item.mediaId) {
117
+ deleteMediaIds.push(item.mediaId);
118
+ continue;
119
+ }
120
+ if (item.pendingReplace && item.replacesMediaId) {
121
+ deleteMediaIds.push(item.replacesMediaId);
122
+ }
123
+ if (item.mediaId && !item.pendingDelete && item.status !== "error") {
124
+ promoteMediaIds.push(item.mediaId);
125
+ }
126
+ }
127
+ return {
128
+ deleteMediaIds: [...new Set(deleteMediaIds)],
129
+ promoteMediaIds: [...new Set(promoteMediaIds)]
130
+ };
131
+ }
132
+ function useUploadDraft({ value, onChange }) {
133
+ const [baseline, setBaseline] = React2.useState(value ?? null);
134
+ React2.useEffect(() => {
135
+ if (value && !value.pendingDelete && !value.pendingReplace && value.mediaId) {
136
+ setBaseline(value);
137
+ }
138
+ }, [value]);
139
+ const markRemove = React2.useCallback(() => {
140
+ if (!value) return;
141
+ onChange?.({ ...value, pendingDelete: true, pendingReplace: false, status: "removed" });
142
+ }, [onChange, value]);
143
+ const undoRemove = React2.useCallback(() => {
144
+ if (!baseline) {
145
+ onChange?.(null);
146
+ return;
147
+ }
148
+ onChange?.({ ...baseline, pendingDelete: false, pendingReplace: false, status: "done" });
149
+ }, [baseline, onChange]);
150
+ const stageReplace = React2.useCallback(
151
+ (file) => {
152
+ revokePreviewUrl(value);
153
+ const next = createUploadItem(file, {
154
+ pendingReplace: Boolean(value?.mediaId),
155
+ replacesMediaId: value?.mediaId,
156
+ status: "idle"
157
+ });
158
+ onChange?.({ ...next, pendingDelete: false });
159
+ },
160
+ [onChange, value]
161
+ );
162
+ const undoReplace = React2.useCallback(() => {
163
+ revokePreviewUrl(value);
164
+ onChange?.(baseline ? { ...baseline, pendingReplace: false, pendingDelete: false } : null);
165
+ }, [baseline, onChange, value]);
166
+ const getCommitActions = React2.useCallback(() => {
167
+ if (!value) return { deleteMediaIds: [], promoteMediaIds: [] };
168
+ const deleteMediaIds = [];
169
+ if (value.pendingDelete && value.mediaId) deleteMediaIds.push(value.mediaId);
170
+ if (value.pendingReplace && value.replacesMediaId) deleteMediaIds.push(value.replacesMediaId);
171
+ const promoteMediaIds = value.mediaId && !value.pendingDelete && value.status !== "error" ? [value.mediaId] : [];
172
+ return {
173
+ deleteMediaIds: [...new Set(deleteMediaIds)],
174
+ promoteMediaIds: [...new Set(promoteMediaIds)]
175
+ };
176
+ }, [value]);
177
+ const state = React2.useMemo(
178
+ () => ({
179
+ display: value ?? null,
180
+ baseline,
181
+ canUndoRemove: Boolean(value?.pendingDelete),
182
+ canUndoReplace: Boolean(value?.pendingReplace)
183
+ }),
184
+ [baseline, value]
185
+ );
186
+ return { state, markRemove, undoRemove, stageReplace, undoReplace, getCommitActions };
187
+ }
188
+ function defaultAcceptForVariant(variant) {
189
+ if (variant === "avatar" || variant === "avatar-crop" || variant === "picture" || variant === "picture-card") {
190
+ return "image/*";
191
+ }
192
+ return void 0;
193
+ }
194
+ function defaultMaxCount(variant) {
195
+ if (variant === "avatar" || variant === "avatar-crop" || variant === "picture") return 1;
196
+ return void 0;
197
+ }
198
+ function fileMatchesAccept(file, accept) {
199
+ if (!accept) return true;
200
+ return accept.split(",").some((rule) => {
201
+ const trimmed = rule.trim();
202
+ if (trimmed.endsWith("/*")) return file.type.startsWith(trimmed.slice(0, -1));
203
+ return file.type === trimmed || file.name.endsWith(trimmed);
204
+ });
205
+ }
206
+ function useUploadList(controlled, defaultValue, onChange) {
207
+ const [internal, setInternal] = React2.useState(defaultValue ?? []);
208
+ const items = controlled ?? internal;
209
+ const setItems = React2.useCallback(
210
+ (next) => {
211
+ const resolved = typeof next === "function" ? next(items) : next;
212
+ if (controlled === void 0) setInternal(resolved);
213
+ onChange?.(resolved);
214
+ },
215
+ [controlled, items, onChange]
216
+ );
217
+ return [items, setItems];
218
+ }
219
+ async function runUpload(file, item, onUpload, setItems) {
220
+ const uid = item.uid;
221
+ setItems((prev) => prev.map((it) => it.uid === uid ? { ...it, status: "uploading" } : it));
222
+ try {
223
+ const result = await onUpload(file, item);
224
+ setItems(
225
+ (prev) => prev.map(
226
+ (it) => it.uid === uid ? {
227
+ ...it,
228
+ status: "done",
229
+ mediaId: result.mediaId,
230
+ previewUrl: result.previewUrl ?? it.previewUrl,
231
+ file: void 0
232
+ } : it
233
+ )
234
+ );
235
+ } catch (err) {
236
+ const message = err instanceof Error ? err.message : String(err);
237
+ setItems(
238
+ (prev) => prev.map((it) => it.uid === uid ? { ...it, status: "error", error: message } : it)
239
+ );
240
+ }
241
+ }
242
+ function Upload({
243
+ variant = "dropzone",
244
+ value,
245
+ defaultValue,
246
+ onChange,
247
+ accept: acceptProp,
248
+ multiple: multipleProp,
249
+ maxCount: maxCountProp,
250
+ maxSizeBytes,
251
+ disabled,
252
+ removable = true,
253
+ onUpload,
254
+ className,
255
+ children
256
+ }) {
257
+ const { t } = useTranslation();
258
+ const accept = acceptProp ?? defaultAcceptForVariant(variant);
259
+ const maxCount = maxCountProp ?? defaultMaxCount(variant);
260
+ const multiple = multipleProp ?? (maxCount === 1 ? false : true);
261
+ const inputRef = React2.useRef(null);
262
+ const [dragActive, setDragActive] = React2.useState(false);
263
+ const [cropFile, setCropFile] = React2.useState(null);
264
+ const [items, setItems] = useUploadList(value, defaultValue, onChange);
265
+ const isSingleAvatar = variant === "avatar" || variant === "avatar-crop" || variant === "picture" && maxCount === 1;
266
+ const singleItem = isSingleAvatar ? items[0] ?? null : null;
267
+ const draft = useUploadDraft({
268
+ value: singleItem,
269
+ onChange: (next) => {
270
+ setItems(next ? [next] : []);
271
+ }
272
+ });
273
+ const pickFiles = (fileList) => {
274
+ if (!fileList?.length || disabled) return;
275
+ const slotsLeft = maxCount != null ? Math.max(0, maxCount - items.length) : fileList.length;
276
+ const candidates = Array.from(fileList).slice(0, multiple ? slotsLeft || fileList.length : 1);
277
+ for (const file of candidates) {
278
+ if (!fileMatchesAccept(file, accept)) continue;
279
+ if (maxSizeBytes != null && file.size > maxSizeBytes) continue;
280
+ if (variant === "avatar-crop") {
281
+ setCropFile(file);
282
+ return;
283
+ }
284
+ if (isSingleAvatar) {
285
+ const baseline = items[0];
286
+ const item3 = createUploadItem(file, {
287
+ pendingReplace: Boolean(baseline?.mediaId),
288
+ replacesMediaId: baseline?.mediaId
289
+ });
290
+ setItems([item3]);
291
+ if (onUpload) void runUpload(file, item3, onUpload, setItems);
292
+ return;
293
+ }
294
+ const item2 = createUploadItem(file);
295
+ setItems((prev) => [...prev, item2]);
296
+ if (onUpload) void runUpload(file, item2, onUpload, setItems);
297
+ }
298
+ };
299
+ const removeItem = (uid) => {
300
+ if (isSingleAvatar) {
301
+ draft.markRemove();
302
+ return;
303
+ }
304
+ setItems((prev) => {
305
+ const target = prev.find((it) => it.uid === uid);
306
+ revokePreviewUrl(target);
307
+ return prev.filter((it) => it.uid !== uid);
308
+ });
309
+ };
310
+ const hiddenInput = /* @__PURE__ */ jsx(
311
+ "input",
312
+ {
313
+ ref: inputRef,
314
+ type: "file",
315
+ className: "sr-only",
316
+ accept,
317
+ multiple: multiple && !isSingleAvatar,
318
+ disabled,
319
+ onChange: (e) => {
320
+ pickFiles(e.target.files);
321
+ e.target.value = "";
322
+ }
323
+ }
324
+ );
325
+ const openPicker = () => {
326
+ if (!disabled) inputRef.current?.click();
327
+ };
328
+ if (variant === "dropzone") {
329
+ return /* @__PURE__ */ jsxs("div", { className: cn("ui-stack-sm", className), children: [
330
+ hiddenInput,
331
+ /* @__PURE__ */ jsxs(
332
+ "div",
333
+ {
334
+ role: "button",
335
+ tabIndex: disabled ? -1 : 0,
336
+ "aria-disabled": disabled,
337
+ "aria-label": t("dataEntry.upload.dropzoneLabel"),
338
+ onClick: openPicker,
339
+ onKeyDown: (e) => {
340
+ if (e.key === "Enter" || e.key === " ") {
341
+ e.preventDefault();
342
+ openPicker();
343
+ }
344
+ },
345
+ onDragOver: (e) => {
346
+ e.preventDefault();
347
+ setDragActive(true);
348
+ },
349
+ onDragLeave: () => setDragActive(false),
350
+ onDrop: (e) => {
351
+ e.preventDefault();
352
+ setDragActive(false);
353
+ pickFiles(e.dataTransfer.files);
354
+ },
355
+ className: cn(
356
+ "cursor-pointer rounded-lg border-2 border-dashed p-10 text-center transition-colors",
357
+ dragActive ? "border-primary bg-primary/5" : "border-border hover:border-primary/50",
358
+ disabled && "pointer-events-none opacity-50"
359
+ ),
360
+ children: [
361
+ /* @__PURE__ */ jsx(Upload$1, { className: "text-muted-foreground mx-auto size-10", "aria-hidden": "true" }),
362
+ /* @__PURE__ */ jsx("p", { className: "mt-3 text-sm", children: t("dataEntry.upload.dropzoneHint") }),
363
+ /* @__PURE__ */ jsx("p", { className: "text-muted-foreground mt-1 text-xs", children: t("dataEntry.upload.dropzoneMeta") })
364
+ ]
365
+ }
366
+ ),
367
+ items.length > 0 && /* @__PURE__ */ jsx(UploadFileList, { items, onRemove: removable ? removeItem : void 0 })
368
+ ] });
369
+ }
370
+ if (variant === "button") {
371
+ return /* @__PURE__ */ jsxs("div", { className: cn("ui-stack-sm", className), children: [
372
+ hiddenInput,
373
+ /* @__PURE__ */ jsxs(Button, { type: "button", variant: "outline", disabled, onClick: openPicker, children: [
374
+ /* @__PURE__ */ jsx(Upload$1, { className: "mr-2 size-4", "aria-hidden": "true" }),
375
+ children ?? t("dataEntry.upload.buttonLabel")
376
+ ] }),
377
+ items.length > 0 && /* @__PURE__ */ jsx(UploadFileList, { items, onRemove: removable ? removeItem : void 0 })
378
+ ] });
379
+ }
380
+ if (variant === "picture-card") {
381
+ const canAdd = maxCount == null || items.length < maxCount;
382
+ return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-wrap gap-3", className), children: [
383
+ hiddenInput,
384
+ items.map((item2) => /* @__PURE__ */ jsx(
385
+ UploadPictureCard,
386
+ {
387
+ item: item2,
388
+ onRemove: removable ? () => removeItem(item2.uid) : void 0
389
+ },
390
+ item2.uid
391
+ )),
392
+ canAdd && /* @__PURE__ */ jsxs(
393
+ "button",
394
+ {
395
+ type: "button",
396
+ disabled,
397
+ onClick: openPicker,
398
+ className: cn(
399
+ "flex size-24 flex-col items-center justify-center rounded-md border border-dashed",
400
+ "text-muted-foreground hover:border-primary hover:text-primary transition-colors",
401
+ disabled && "pointer-events-none opacity-50"
402
+ ),
403
+ "aria-label": t("dataEntry.upload.addImage"),
404
+ children: [
405
+ /* @__PURE__ */ jsx(ImagePlus, { className: "size-6", "aria-hidden": "true" }),
406
+ /* @__PURE__ */ jsx("span", { className: "mt-1 text-xs", children: t("dataEntry.upload.addImage") })
407
+ ]
408
+ }
409
+ )
410
+ ] });
411
+ }
412
+ if (variant === "picture") {
413
+ const item2 = draft.state.display;
414
+ return /* @__PURE__ */ jsxs("div", { className: cn("ui-stack-sm max-w-xs", className), children: [
415
+ hiddenInput,
416
+ item2?.previewUrl && !item2.pendingDelete ? /* @__PURE__ */ jsxs("div", { className: "relative overflow-hidden rounded-md border", children: [
417
+ /* @__PURE__ */ jsx("img", { src: item2.previewUrl, alt: "", className: "max-h-48 w-full object-cover" }),
418
+ item2.status === "uploading" && /* @__PURE__ */ jsx("div", { className: "bg-background/70 absolute inset-0 flex items-center justify-center text-sm", children: t("dataEntry.upload.uploading") }),
419
+ item2.pendingReplace && /* @__PURE__ */ jsx("div", { className: "bg-warning text-warning-foreground absolute top-2 left-2 rounded px-2 py-0.5 text-xs", children: t("dataEntry.upload.pendingReplace") })
420
+ ] }) : /* @__PURE__ */ jsxs(
421
+ "button",
422
+ {
423
+ type: "button",
424
+ disabled,
425
+ onClick: openPicker,
426
+ className: "text-muted-foreground hover:border-primary flex h-32 w-full flex-col items-center justify-center rounded-md border border-dashed",
427
+ children: [
428
+ /* @__PURE__ */ jsx(ImagePlus, { className: controlIconClass, "aria-hidden": "true" }),
429
+ /* @__PURE__ */ jsx("span", { className: "mt-2 text-sm", children: t("dataEntry.upload.addImage") })
430
+ ]
431
+ }
432
+ ),
433
+ /* @__PURE__ */ jsx(UploadDraftActions, { draft, disabled, onPick: openPicker })
434
+ ] });
435
+ }
436
+ const item = draft.state.display;
437
+ const showPlaceholder = !item?.previewUrl || item.pendingDelete;
438
+ return /* @__PURE__ */ jsxs("div", { className: cn("ui-stack-sm items-start", className), children: [
439
+ hiddenInput,
440
+ /* @__PURE__ */ jsx(
441
+ UploadCropDialog,
442
+ {
443
+ open: variant === "avatar-crop" && cropFile != null,
444
+ onOpenChange: (open) => !open && setCropFile(null),
445
+ file: cropFile,
446
+ onConfirm: (cropped) => {
447
+ const baseline = items[0];
448
+ const item2 = createUploadItem(cropped, {
449
+ pendingReplace: Boolean(baseline?.mediaId),
450
+ replacesMediaId: baseline?.mediaId
451
+ });
452
+ setItems([item2]);
453
+ setCropFile(null);
454
+ if (onUpload) void runUpload(cropped, item2, onUpload, setItems);
455
+ }
456
+ }
457
+ ),
458
+ /* @__PURE__ */ jsxs("div", { className: "relative inline-block", children: [
459
+ /* @__PURE__ */ jsxs(
460
+ "button",
461
+ {
462
+ type: "button",
463
+ disabled,
464
+ onClick: openPicker,
465
+ className: cn(
466
+ "border-border bg-muted relative size-24 overflow-hidden rounded-full border-2",
467
+ "focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none",
468
+ item?.pendingDelete && "opacity-40",
469
+ disabled && "pointer-events-none opacity-50"
470
+ ),
471
+ "aria-label": t("dataEntry.upload.avatarLabel"),
472
+ children: [
473
+ !showPlaceholder && item?.previewUrl ? /* @__PURE__ */ jsx("img", { src: item.previewUrl, alt: "", className: "size-full object-cover" }) : /* @__PURE__ */ jsx("span", { className: "text-muted-foreground flex size-full items-center justify-center", children: /* @__PURE__ */ jsx(Camera, { className: controlIconClass, "aria-hidden": "true" }) }),
474
+ !disabled && /* @__PURE__ */ jsx("span", { className: "absolute inset-x-0 bottom-0 bg-black/50 py-1 text-center text-[10px] text-white", children: t("dataEntry.upload.change") })
475
+ ]
476
+ }
477
+ ),
478
+ removable && item && !item.pendingDelete && /* @__PURE__ */ jsx(
479
+ "button",
480
+ {
481
+ type: "button",
482
+ disabled,
483
+ onClick: () => draft.markRemove(),
484
+ className: "bg-background hover:bg-destructive hover:text-destructive-foreground absolute -top-1 -right-1 rounded-full border p-1 shadow-sm",
485
+ "aria-label": t("dataEntry.upload.removeAvatar"),
486
+ children: /* @__PURE__ */ jsx(Trash2, { className: "size-3.5", "aria-hidden": "true" })
487
+ }
488
+ )
489
+ ] }),
490
+ /* @__PURE__ */ jsx(UploadDraftActions, { draft, disabled, onPick: openPicker })
491
+ ] });
492
+ }
493
+ function UploadDraftActions({
494
+ draft,
495
+ disabled,
496
+ onPick
497
+ }) {
498
+ const { t } = useTranslation();
499
+ const { state, undoRemove, undoReplace } = draft;
500
+ if (state.canUndoRemove) {
501
+ return /* @__PURE__ */ jsxs("div", { className: "border-destructive/40 bg-destructive/5 flex flex-wrap items-center gap-2 rounded-md border border-dashed px-3 py-2 text-sm", children: [
502
+ /* @__PURE__ */ jsx("span", { className: "text-destructive", children: t("dataEntry.upload.markedForDelete") }),
503
+ /* @__PURE__ */ jsxs(Button, { type: "button", size: "sm", variant: "outline", disabled, onClick: undoRemove, children: [
504
+ /* @__PURE__ */ jsx(RotateCcw, { className: "mr-1 size-3.5", "aria-hidden": "true" }),
505
+ t("dataEntry.upload.undo")
506
+ ] })
507
+ ] });
508
+ }
509
+ if (state.canUndoReplace) {
510
+ return /* @__PURE__ */ jsxs("div", { className: "text-muted-foreground flex flex-wrap items-center gap-2 text-sm", children: [
511
+ /* @__PURE__ */ jsx("span", { children: t("dataEntry.upload.pendingReplaceHint") }),
512
+ /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "ghost", disabled, onClick: undoReplace, children: t("dataEntry.upload.undo") }),
513
+ /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "outline", disabled, onClick: onPick, children: t("dataEntry.upload.change") })
514
+ ] });
515
+ }
516
+ return null;
517
+ }
518
+ function UploadPictureCard({ item, onRemove }) {
519
+ return /* @__PURE__ */ jsxs("div", { className: "bg-muted relative size-24 overflow-hidden rounded-md border", children: [
520
+ item.previewUrl ? /* @__PURE__ */ jsx("img", { src: item.previewUrl, alt: "", className: "size-full object-cover" }) : /* @__PURE__ */ jsx("div", { className: "text-muted-foreground flex size-full items-center justify-center text-xs", children: "\u2026" }),
521
+ item.status === "uploading" && /* @__PURE__ */ jsx("div", { className: "bg-background/70 absolute inset-0 flex items-center justify-center text-xs", children: "\u2026" }),
522
+ onRemove && /* @__PURE__ */ jsx(
523
+ "button",
524
+ {
525
+ type: "button",
526
+ onClick: onRemove,
527
+ className: "bg-background/90 hover:bg-destructive hover:text-destructive-foreground absolute top-1 right-1 rounded-full p-0.5 shadow",
528
+ "aria-label": "Remove",
529
+ children: /* @__PURE__ */ jsx(X, { className: "size-3.5", "aria-hidden": "true" })
530
+ }
531
+ )
532
+ ] });
533
+ }
534
+ function UploadFileList({
535
+ items,
536
+ onRemove
537
+ }) {
538
+ return /* @__PURE__ */ jsx("ul", { className: "ui-stack-xs", children: items.map((item) => /* @__PURE__ */ jsxs("li", { className: "flex items-center gap-3 rounded-md border px-3 py-2 text-sm", children: [
539
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
540
+ /* @__PURE__ */ jsx("div", { className: "truncate font-medium", children: item.name }),
541
+ /* @__PURE__ */ jsxs("div", { className: "text-muted-foreground text-xs", children: [
542
+ formatBytes(item.size),
543
+ item.status === "uploading" && " \xB7 \u2026",
544
+ item.status === "error" && item.error && /* @__PURE__ */ jsxs("span", { className: "text-destructive", children: [
545
+ " \xB7 ",
546
+ item.error
547
+ ] }),
548
+ item.mediaId && /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
549
+ " \xB7 ",
550
+ item.mediaId.slice(0, 8),
551
+ "\u2026"
552
+ ] })
553
+ ] })
554
+ ] }),
555
+ onRemove && /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => onRemove(item.uid), children: /* @__PURE__ */ jsx(X, { className: "size-4", "aria-hidden": "true" }) })
556
+ ] }, item.uid)) });
557
+ }
558
+
559
+ export { Upload, collectUploadCommitActions, createUploadItem, useUploadDraft };
@@ -0,0 +1,26 @@
1
+ import { toneWarningClass, toneSuccessClass } from './chunk-ICM6XBST.js';
2
+ import { cn } from './chunk-U7N2A7A3.js';
3
+ import { cva } from 'class-variance-authority';
4
+ import { jsx } from 'react/jsx-runtime';
5
+
6
+ var badgeVariants = cva(
7
+ "inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring",
8
+ {
9
+ variants: {
10
+ variant: {
11
+ default: "border-transparent bg-primary text-primary-foreground",
12
+ secondary: "border-transparent bg-secondary text-secondary-foreground",
13
+ destructive: "border-transparent bg-destructive text-destructive-foreground",
14
+ outline: "text-foreground",
15
+ success: cn("border-transparent", toneSuccessClass),
16
+ warning: cn("border-transparent", toneWarningClass)
17
+ }
18
+ },
19
+ defaultVariants: { variant: "default" }
20
+ }
21
+ );
22
+ function Badge({ className, variant, ...props }) {
23
+ return /* @__PURE__ */ jsx("div", { className: cn(badgeVariants({ variant }), className), ...props });
24
+ }
25
+
26
+ export { Badge };
@@ -0,0 +1,33 @@
1
+ import { cn } from './chunk-U7N2A7A3.js';
2
+ import { jsx } from 'react/jsx-runtime';
3
+
4
+ // src/lib/variants.ts
5
+ var densityClass = {
6
+ compact: "ui-density-compact",
7
+ default: "ui-density-default",
8
+ comfortable: "ui-density-comfortable"
9
+ };
10
+ var pageContainerVariantClass = {
11
+ default: void 0,
12
+ narrow: "ui-page-container--narrow",
13
+ flush: "ui-page-container--flush",
14
+ ghost: "ui-page-container--ghost"
15
+ };
16
+ var stackGapClass = {
17
+ xs: "ui-stack-xs",
18
+ sm: "ui-stack-sm",
19
+ md: "ui-stack-md",
20
+ lg: "ui-stack-lg",
21
+ xl: "ui-stack-xl"
22
+ };
23
+ var inlineGapClass = {
24
+ xs: "ui-inline-xs",
25
+ sm: "ui-inline-sm",
26
+ md: "ui-inline-md",
27
+ lg: "ui-inline-lg"
28
+ };
29
+ function Inline({ gap = "sm", className, children, ...props }) {
30
+ return /* @__PURE__ */ jsx("div", { className: cn(inlineGapClass[gap], className), ...props, children });
31
+ }
32
+
33
+ export { Inline, densityClass, pageContainerVariantClass, stackGapClass };