@senvenli/react 0.0.0-stage → 0.2.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 (636) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -2
  3. package/dist/action/button-group.d.ts +26 -0
  4. package/dist/action/button-group.js +12 -0
  5. package/dist/action/button-group.js.map +1 -0
  6. package/dist/action/button.d.ts +42 -0
  7. package/dist/action/button.js +58 -0
  8. package/dist/action/button.js.map +1 -0
  9. package/dist/action/close-button.d.ts +12 -0
  10. package/dist/action/close-button.js +13 -0
  11. package/dist/action/close-button.js.map +1 -0
  12. package/dist/action/copy-button.d.ts +21 -0
  13. package/dist/action/copy-button.js +38 -0
  14. package/dist/action/copy-button.js.map +1 -0
  15. package/dist/action/fab.d.ts +29 -0
  16. package/dist/action/fab.js +57 -0
  17. package/dist/action/fab.js.map +1 -0
  18. package/dist/action/files.d.ts +70 -0
  19. package/dist/action/files.js +156 -0
  20. package/dist/action/files.js.map +1 -0
  21. package/dist/action/index.d.ts +23 -0
  22. package/dist/action/index.js +16 -0
  23. package/dist/action/index.js.map +1 -0
  24. package/dist/action/language-names.d.ts +19 -0
  25. package/dist/action/language-names.js +79 -0
  26. package/dist/action/language-names.js.map +1 -0
  27. package/dist/action/language-switcher.d.ts +57 -0
  28. package/dist/action/language-switcher.js +53 -0
  29. package/dist/action/language-switcher.js.map +1 -0
  30. package/dist/action/link-button.d.ts +57 -0
  31. package/dist/action/link-button.js +48 -0
  32. package/dist/action/link-button.js.map +1 -0
  33. package/dist/action/link.d.ts +24 -0
  34. package/dist/action/link.js +18 -0
  35. package/dist/action/link.js.map +1 -0
  36. package/dist/action/pressable.d.ts +40 -0
  37. package/dist/action/pressable.js +65 -0
  38. package/dist/action/pressable.js.map +1 -0
  39. package/dist/action/styles.d.ts +60 -0
  40. package/dist/action/styles.js +109 -0
  41. package/dist/action/styles.js.map +1 -0
  42. package/dist/action/theme-script.d.ts +12 -0
  43. package/dist/action/theme-script.js +23 -0
  44. package/dist/action/theme-script.js.map +1 -0
  45. package/dist/action/theme-switcher.d.ts +43 -0
  46. package/dist/action/theme-switcher.js +260 -0
  47. package/dist/action/theme-switcher.js.map +1 -0
  48. package/dist/action/theme-toggle.d.ts +43 -0
  49. package/dist/action/theme-toggle.js +259 -0
  50. package/dist/action/theme-toggle.js.map +1 -0
  51. package/dist/action/toggle.d.ts +44 -0
  52. package/dist/action/toggle.js +28 -0
  53. package/dist/action/toggle.js.map +1 -0
  54. package/dist/action/touch-target.d.ts +9 -0
  55. package/dist/action/touch-target.js +14 -0
  56. package/dist/action/touch-target.js.map +1 -0
  57. package/dist/charts/axis-width.d.ts +186 -0
  58. package/dist/charts/axis-width.js +1262 -0
  59. package/dist/charts/axis-width.js.map +1 -0
  60. package/dist/charts/bar-public.d.ts +16 -0
  61. package/dist/charts/bar-public.js +16 -0
  62. package/dist/charts/bar-public.js.map +1 -0
  63. package/dist/charts/chart-parts.d.ts +136 -0
  64. package/dist/charts/chart-parts.js +160 -0
  65. package/dist/charts/chart-parts.js.map +1 -0
  66. package/dist/charts/core-charts.d.ts +157 -0
  67. package/dist/charts/core-charts.js +505 -0
  68. package/dist/charts/core-charts.js.map +1 -0
  69. package/dist/charts/index.d.ts +12 -0
  70. package/dist/charts/index.js +8 -0
  71. package/dist/charts/index.js.map +1 -0
  72. package/dist/charts/list-charts.d.ts +124 -0
  73. package/dist/charts/list-charts.js +308 -0
  74. package/dist/charts/list-charts.js.map +1 -0
  75. package/dist/charts/more-charts.d.ts +138 -0
  76. package/dist/charts/more-charts.js +284 -0
  77. package/dist/charts/more-charts.js.map +1 -0
  78. package/dist/charts/report-charts.d.ts +138 -0
  79. package/dist/charts/report-charts.js +370 -0
  80. package/dist/charts/report-charts.js.map +1 -0
  81. package/dist/charts/value-tick.d.ts +178 -0
  82. package/dist/charts/value-tick.js +240 -0
  83. package/dist/charts/value-tick.js.map +1 -0
  84. package/dist/collection/data-table-url-hook.d.ts +34 -0
  85. package/dist/collection/data-table-url-hook.js +70 -0
  86. package/dist/collection/data-table-url-hook.js.map +1 -0
  87. package/dist/collection/data-table-url.d.ts +30 -0
  88. package/dist/collection/data-table-url.js +48 -0
  89. package/dist/collection/data-table-url.js.map +1 -0
  90. package/dist/collection/data-table.d.ts +112 -0
  91. package/dist/collection/data-table.js +188 -0
  92. package/dist/collection/data-table.js.map +1 -0
  93. package/dist/collection/grid-list-public.d.ts +18 -0
  94. package/dist/collection/grid-list-public.js +19 -0
  95. package/dist/collection/grid-list-public.js.map +1 -0
  96. package/dist/collection/grid-list.d.ts +73 -0
  97. package/dist/collection/grid-list.js +46 -0
  98. package/dist/collection/grid-list.js.map +1 -0
  99. package/dist/collection/index.d.ts +14 -0
  100. package/dist/collection/index.js +8 -0
  101. package/dist/collection/index.js.map +1 -0
  102. package/dist/collection/list.d.ts +61 -0
  103. package/dist/collection/list.js +38 -0
  104. package/dist/collection/list.js.map +1 -0
  105. package/dist/collection/selection-checkbox.d.ts +5 -0
  106. package/dist/collection/selection-checkbox.js +13 -0
  107. package/dist/collection/selection-checkbox.js.map +1 -0
  108. package/dist/collection/table.d.ts +91 -0
  109. package/dist/collection/table.js +183 -0
  110. package/dist/collection/table.js.map +1 -0
  111. package/dist/collection/tree.d.ts +31 -0
  112. package/dist/collection/tree.js +22 -0
  113. package/dist/collection/tree.js.map +1 -0
  114. package/dist/color/color.d.ts +87 -0
  115. package/dist/color/color.js +200 -0
  116. package/dist/color/color.js.map +1 -0
  117. package/dist/color/contrast.d.ts +34 -0
  118. package/dist/color/contrast.js +44 -0
  119. package/dist/color/contrast.js.map +1 -0
  120. package/dist/color/index.d.ts +4 -0
  121. package/dist/color/index.js +5 -0
  122. package/dist/color/index.js.map +1 -0
  123. package/dist/date/calendar.d.ts +71 -0
  124. package/dist/date/calendar.js +291 -0
  125. package/dist/date/calendar.js.map +1 -0
  126. package/dist/date/fields.d.ts +174 -0
  127. package/dist/date/fields.js +250 -0
  128. package/dist/date/fields.js.map +1 -0
  129. package/dist/date/index.d.ts +7 -0
  130. package/dist/date/index.js +6 -0
  131. package/dist/date/index.js.map +1 -0
  132. package/dist/date/month-grid.d.ts +31 -0
  133. package/dist/date/month-grid.js +115 -0
  134. package/dist/date/month-grid.js.map +1 -0
  135. package/dist/date/pickers.d.ts +118 -0
  136. package/dist/date/pickers.js +176 -0
  137. package/dist/date/pickers.js.map +1 -0
  138. package/dist/date/public.d.ts +25 -0
  139. package/dist/date/public.js +24 -0
  140. package/dist/date/public.js.map +1 -0
  141. package/dist/date/segments.d.ts +153 -0
  142. package/dist/date/segments.js +433 -0
  143. package/dist/date/segments.js.map +1 -0
  144. package/dist/defaults.d.ts +74 -0
  145. package/dist/defaults.js +100 -0
  146. package/dist/defaults.js.map +1 -0
  147. package/dist/density.d.ts +2 -0
  148. package/dist/density.js +2 -0
  149. package/dist/density.js.map +1 -0
  150. package/dist/display/avatar.d.ts +29 -0
  151. package/dist/display/avatar.js +71 -0
  152. package/dist/display/avatar.js.map +1 -0
  153. package/dist/display/badge.d.ts +65 -0
  154. package/dist/display/badge.js +99 -0
  155. package/dist/display/badge.js.map +1 -0
  156. package/dist/display/card.d.ts +72 -0
  157. package/dist/display/card.js +91 -0
  158. package/dist/display/card.js.map +1 -0
  159. package/dist/display/carousel.d.ts +47 -0
  160. package/dist/display/carousel.js +214 -0
  161. package/dist/display/carousel.js.map +1 -0
  162. package/dist/display/description-list.d.ts +25 -0
  163. package/dist/display/description-list.js +36 -0
  164. package/dist/display/description-list.js.map +1 -0
  165. package/dist/display/icon-aliases.d.ts +1 -0
  166. package/dist/display/icon-aliases.js +259 -0
  167. package/dist/display/icon-aliases.js.map +1 -0
  168. package/dist/display/icon-names.d.ts +4 -0
  169. package/dist/display/icon-names.js +2 -0
  170. package/dist/display/icon-names.js.map +1 -0
  171. package/dist/display/icon.d.ts +51 -0
  172. package/dist/display/icon.js +96 -0
  173. package/dist/display/icon.js.map +1 -0
  174. package/dist/display/image-crop.d.ts +106 -0
  175. package/dist/display/image-crop.js +117 -0
  176. package/dist/display/image-crop.js.map +1 -0
  177. package/dist/display/image-cropper.d.ts +68 -0
  178. package/dist/display/image-cropper.js +284 -0
  179. package/dist/display/image-cropper.js.map +1 -0
  180. package/dist/display/image-viewer.d.ts +54 -0
  181. package/dist/display/image-viewer.js +84 -0
  182. package/dist/display/image-viewer.js.map +1 -0
  183. package/dist/display/image.d.ts +26 -0
  184. package/dist/display/image.js +17 -0
  185. package/dist/display/image.js.map +1 -0
  186. package/dist/display/index.d.ts +29 -0
  187. package/dist/display/index.js +16 -0
  188. package/dist/display/index.js.map +1 -0
  189. package/dist/display/iso-chip.d.ts +19 -0
  190. package/dist/display/iso-chip.js +21 -0
  191. package/dist/display/iso-chip.js.map +1 -0
  192. package/dist/display/kbd.d.ts +11 -0
  193. package/dist/display/kbd.js +33 -0
  194. package/dist/display/kbd.js.map +1 -0
  195. package/dist/display/lozenge.d.ts +30 -0
  196. package/dist/display/lozenge.js +55 -0
  197. package/dist/display/lozenge.js.map +1 -0
  198. package/dist/display/scroll-area.d.ts +29 -0
  199. package/dist/display/scroll-area.js +95 -0
  200. package/dist/display/scroll-area.js.map +1 -0
  201. package/dist/display/separator.d.ts +13 -0
  202. package/dist/display/separator.js +24 -0
  203. package/dist/display/separator.js.map +1 -0
  204. package/dist/display/stat.d.ts +35 -0
  205. package/dist/display/stat.js +41 -0
  206. package/dist/display/stat.js.map +1 -0
  207. package/dist/display/timeline.d.ts +44 -0
  208. package/dist/display/timeline.js +111 -0
  209. package/dist/display/timeline.js.map +1 -0
  210. package/dist/display/typography.d.ts +37 -0
  211. package/dist/display/typography.js +53 -0
  212. package/dist/display/typography.js.map +1 -0
  213. package/dist/display/visually-hidden.d.ts +14 -0
  214. package/dist/display/visually-hidden.js +10 -0
  215. package/dist/display/visually-hidden.js.map +1 -0
  216. package/dist/feedback/banner.d.ts +46 -0
  217. package/dist/feedback/banner.js +157 -0
  218. package/dist/feedback/banner.js.map +1 -0
  219. package/dist/feedback/cooldown.d.ts +17 -0
  220. package/dist/feedback/cooldown.js +59 -0
  221. package/dist/feedback/cooldown.js.map +1 -0
  222. package/dist/feedback/empty-state.d.ts +35 -0
  223. package/dist/feedback/empty-state.js +39 -0
  224. package/dist/feedback/empty-state.js.map +1 -0
  225. package/dist/feedback/index.d.ts +12 -0
  226. package/dist/feedback/index.js +11 -0
  227. package/dist/feedback/index.js.map +1 -0
  228. package/dist/feedback/meter.d.ts +33 -0
  229. package/dist/feedback/meter.js +42 -0
  230. package/dist/feedback/meter.js.map +1 -0
  231. package/dist/feedback/motion.d.ts +9 -0
  232. package/dist/feedback/motion.js +57 -0
  233. package/dist/feedback/motion.js.map +1 -0
  234. package/dist/feedback/progress.d.ts +39 -0
  235. package/dist/feedback/progress.js +68 -0
  236. package/dist/feedback/progress.js.map +1 -0
  237. package/dist/feedback/skeleton.d.ts +48 -0
  238. package/dist/feedback/skeleton.js +61 -0
  239. package/dist/feedback/skeleton.js.map +1 -0
  240. package/dist/feedback/spinner.d.ts +19 -0
  241. package/dist/feedback/spinner.js +29 -0
  242. package/dist/feedback/spinner.js.map +1 -0
  243. package/dist/feedback/status-dot.d.ts +23 -0
  244. package/dist/feedback/status-dot.js +37 -0
  245. package/dist/feedback/status-dot.js.map +1 -0
  246. package/dist/form/countries.d.ts +34 -0
  247. package/dist/form/countries.js +273 -0
  248. package/dist/form/countries.js.map +1 -0
  249. package/dist/form/data-attributes.d.ts +11 -0
  250. package/dist/form/data-attributes.js +22 -0
  251. package/dist/form/data-attributes.js.map +1 -0
  252. package/dist/form/field-parts.d.ts +113 -0
  253. package/dist/form/field-parts.js +178 -0
  254. package/dist/form/field-parts.js.map +1 -0
  255. package/dist/form/field.d.ts +36 -0
  256. package/dist/form/field.js +65 -0
  257. package/dist/form/field.js.map +1 -0
  258. package/dist/form/files.d.ts +70 -0
  259. package/dist/form/files.js +156 -0
  260. package/dist/form/files.js.map +1 -0
  261. package/dist/form/form.d.ts +40 -0
  262. package/dist/form/form.js +74 -0
  263. package/dist/form/form.js.map +1 -0
  264. package/dist/form/image-crop.d.ts +106 -0
  265. package/dist/form/image-crop.js +117 -0
  266. package/dist/form/image-crop.js.map +1 -0
  267. package/dist/form/image-cropper.d.ts +68 -0
  268. package/dist/form/image-cropper.js +284 -0
  269. package/dist/form/image-cropper.js.map +1 -0
  270. package/dist/form/index.d.ts +24 -0
  271. package/dist/form/index.js +15 -0
  272. package/dist/form/index.js.map +1 -0
  273. package/dist/form/input-group.d.ts +63 -0
  274. package/dist/form/input-group.js +63 -0
  275. package/dist/form/input-group.js.map +1 -0
  276. package/dist/form/input-otp.d.ts +35 -0
  277. package/dist/form/input-otp.js +83 -0
  278. package/dist/form/input-otp.js.map +1 -0
  279. package/dist/form/input.d.ts +36 -0
  280. package/dist/form/input.js +41 -0
  281. package/dist/form/input.js.map +1 -0
  282. package/dist/form/number-field.d.ts +84 -0
  283. package/dist/form/number-field.js +81 -0
  284. package/dist/form/number-field.js.map +1 -0
  285. package/dist/form/otp-field.d.ts +37 -0
  286. package/dist/form/otp-field.js +116 -0
  287. package/dist/form/otp-field.js.map +1 -0
  288. package/dist/form/password-field.d.ts +61 -0
  289. package/dist/form/password-field.js +61 -0
  290. package/dist/form/password-field.js.map +1 -0
  291. package/dist/form/phone-field.d.ts +104 -0
  292. package/dist/form/phone-field.js +275 -0
  293. package/dist/form/phone-field.js.map +1 -0
  294. package/dist/form/phone-paste.d.ts +24 -0
  295. package/dist/form/phone-paste.js +40 -0
  296. package/dist/form/phone-paste.js.map +1 -0
  297. package/dist/form/phone.d.ts +159 -0
  298. package/dist/form/phone.js +309 -0
  299. package/dist/form/phone.js.map +1 -0
  300. package/dist/form/search-field.d.ts +29 -0
  301. package/dist/form/search-field.js +23 -0
  302. package/dist/form/search-field.js.map +1 -0
  303. package/dist/form/styles.d.ts +31 -0
  304. package/dist/form/styles.js +43 -0
  305. package/dist/form/styles.js.map +1 -0
  306. package/dist/form/text-area.d.ts +70 -0
  307. package/dist/form/text-area.js +93 -0
  308. package/dist/form/text-area.js.map +1 -0
  309. package/dist/form/text-field.d.ts +131 -0
  310. package/dist/form/text-field.js +59 -0
  311. package/dist/form/text-field.js.map +1 -0
  312. package/dist/form/validation.d.ts +145 -0
  313. package/dist/form/validation.js +136 -0
  314. package/dist/form/validation.js.map +1 -0
  315. package/dist/i18n.d.ts +438 -0
  316. package/dist/i18n.js +948 -0
  317. package/dist/i18n.js.map +1 -0
  318. package/dist/index.d.ts +9 -0
  319. package/dist/index.js +7 -0
  320. package/dist/index.js.map +1 -0
  321. package/dist/intl-locale.d.ts +30 -0
  322. package/dist/intl-locale.js +83 -0
  323. package/dist/intl-locale.js.map +1 -0
  324. package/dist/layers.d.ts +32 -0
  325. package/dist/layers.js +33 -0
  326. package/dist/layers.js.map +1 -0
  327. package/dist/layout/auth-form-layout.d.ts +71 -0
  328. package/dist/layout/auth-form-layout.js +61 -0
  329. package/dist/layout/auth-form-layout.js.map +1 -0
  330. package/dist/layout/auth-layout.d.ts +59 -0
  331. package/dist/layout/auth-layout.js +26 -0
  332. package/dist/layout/auth-layout.js.map +1 -0
  333. package/dist/layout/box.d.ts +26 -0
  334. package/dist/layout/box.js +16 -0
  335. package/dist/layout/box.js.map +1 -0
  336. package/dist/layout/grid.d.ts +27 -0
  337. package/dist/layout/grid.js +26 -0
  338. package/dist/layout/grid.js.map +1 -0
  339. package/dist/layout/index.d.ts +16 -0
  340. package/dist/layout/index.js +12 -0
  341. package/dist/layout/index.js.map +1 -0
  342. package/dist/layout/pressable.d.ts +40 -0
  343. package/dist/layout/pressable.js +65 -0
  344. package/dist/layout/pressable.js.map +1 -0
  345. package/dist/layout/reset-sent-card.d.ts +39 -0
  346. package/dist/layout/reset-sent-card.js +22 -0
  347. package/dist/layout/reset-sent-card.js.map +1 -0
  348. package/dist/layout/scroll-area.d.ts +29 -0
  349. package/dist/layout/scroll-area.js +95 -0
  350. package/dist/layout/scroll-area.js.map +1 -0
  351. package/dist/layout/section.d.ts +41 -0
  352. package/dist/layout/section.js +22 -0
  353. package/dist/layout/section.js.map +1 -0
  354. package/dist/layout/split.d.ts +50 -0
  355. package/dist/layout/split.js +35 -0
  356. package/dist/layout/split.js.map +1 -0
  357. package/dist/layout/stack.d.ts +44 -0
  358. package/dist/layout/stack.js +36 -0
  359. package/dist/layout/stack.js.map +1 -0
  360. package/dist/layout/tokens.d.ts +33 -0
  361. package/dist/layout/tokens.js +85 -0
  362. package/dist/layout/tokens.js.map +1 -0
  363. package/dist/layout/toolbar.d.ts +37 -0
  364. package/dist/layout/toolbar.js +334 -0
  365. package/dist/layout/toolbar.js.map +1 -0
  366. package/dist/navigate-context.d.ts +12 -0
  367. package/dist/navigate-context.js +13 -0
  368. package/dist/navigate-context.js.map +1 -0
  369. package/dist/navigation/accordion.d.ts +40 -0
  370. package/dist/navigation/accordion.js +33 -0
  371. package/dist/navigation/accordion.js.map +1 -0
  372. package/dist/navigation/bottom-nav.d.ts +29 -0
  373. package/dist/navigation/bottom-nav.js +48 -0
  374. package/dist/navigation/bottom-nav.js.map +1 -0
  375. package/dist/navigation/brand-link-context.d.ts +8 -0
  376. package/dist/navigation/brand-link-context.js +9 -0
  377. package/dist/navigation/brand-link-context.js.map +1 -0
  378. package/dist/navigation/breadcrumbs.d.ts +36 -0
  379. package/dist/navigation/breadcrumbs.js +51 -0
  380. package/dist/navigation/breadcrumbs.js.map +1 -0
  381. package/dist/navigation/dock.d.ts +27 -0
  382. package/dist/navigation/dock.js +47 -0
  383. package/dist/navigation/dock.js.map +1 -0
  384. package/dist/navigation/footer.d.ts +43 -0
  385. package/dist/navigation/footer.js +43 -0
  386. package/dist/navigation/footer.js.map +1 -0
  387. package/dist/navigation/index.d.ts +22 -0
  388. package/dist/navigation/index.js +17 -0
  389. package/dist/navigation/index.js.map +1 -0
  390. package/dist/navigation/language-names.d.ts +19 -0
  391. package/dist/navigation/language-names.js +79 -0
  392. package/dist/navigation/language-names.js.map +1 -0
  393. package/dist/navigation/language-switcher.d.ts +55 -0
  394. package/dist/navigation/language-switcher.js +53 -0
  395. package/dist/navigation/language-switcher.js.map +1 -0
  396. package/dist/navigation/nav-panel.d.ts +18 -0
  397. package/dist/navigation/nav-panel.js +51 -0
  398. package/dist/navigation/nav-panel.js.map +1 -0
  399. package/dist/navigation/navbar.d.ts +73 -0
  400. package/dist/navigation/navbar.js +64 -0
  401. package/dist/navigation/navbar.js.map +1 -0
  402. package/dist/navigation/page-header.d.ts +37 -0
  403. package/dist/navigation/page-header.js +50 -0
  404. package/dist/navigation/page-header.js.map +1 -0
  405. package/dist/navigation/pagination.d.ts +25 -0
  406. package/dist/navigation/pagination.js +51 -0
  407. package/dist/navigation/pagination.js.map +1 -0
  408. package/dist/navigation/panel-header.d.ts +37 -0
  409. package/dist/navigation/panel-header.js +50 -0
  410. package/dist/navigation/panel-header.js.map +1 -0
  411. package/dist/navigation/sidebar-script.d.ts +12 -0
  412. package/dist/navigation/sidebar-script.js +20 -0
  413. package/dist/navigation/sidebar-script.js.map +1 -0
  414. package/dist/navigation/sidebar.d.ts +149 -0
  415. package/dist/navigation/sidebar.js +332 -0
  416. package/dist/navigation/sidebar.js.map +1 -0
  417. package/dist/navigation/skip-link.d.ts +12 -0
  418. package/dist/navigation/skip-link.js +30 -0
  419. package/dist/navigation/skip-link.js.map +1 -0
  420. package/dist/navigation/stepper.d.ts +50 -0
  421. package/dist/navigation/stepper.js +96 -0
  422. package/dist/navigation/stepper.js.map +1 -0
  423. package/dist/navigation/tabs.d.ts +84 -0
  424. package/dist/navigation/tabs.js +118 -0
  425. package/dist/navigation/tabs.js.map +1 -0
  426. package/dist/navigation/toolbar.d.ts +37 -0
  427. package/dist/navigation/toolbar.js +334 -0
  428. package/dist/navigation/toolbar.js.map +1 -0
  429. package/dist/overlay/alert-dialog.d.ts +63 -0
  430. package/dist/overlay/alert-dialog.js +76 -0
  431. package/dist/overlay/alert-dialog.js.map +1 -0
  432. package/dist/overlay/command-palette.d.ts +53 -0
  433. package/dist/overlay/command-palette.js +130 -0
  434. package/dist/overlay/command-palette.js.map +1 -0
  435. package/dist/overlay/command.d.ts +53 -0
  436. package/dist/overlay/command.js +129 -0
  437. package/dist/overlay/command.js.map +1 -0
  438. package/dist/overlay/context-menu.d.ts +29 -0
  439. package/dist/overlay/context-menu.js +58 -0
  440. package/dist/overlay/context-menu.js.map +1 -0
  441. package/dist/overlay/dialog.d.ts +162 -0
  442. package/dist/overlay/dialog.js +174 -0
  443. package/dist/overlay/dialog.js.map +1 -0
  444. package/dist/overlay/drawer.d.ts +41 -0
  445. package/dist/overlay/drawer.js +114 -0
  446. package/dist/overlay/drawer.js.map +1 -0
  447. package/dist/overlay/floating.d.ts +142 -0
  448. package/dist/overlay/floating.js +226 -0
  449. package/dist/overlay/floating.js.map +1 -0
  450. package/dist/overlay/hover-card.d.ts +19 -0
  451. package/dist/overlay/hover-card.js +31 -0
  452. package/dist/overlay/hover-card.js.map +1 -0
  453. package/dist/overlay/index.d.ts +18 -0
  454. package/dist/overlay/index.js +12 -0
  455. package/dist/overlay/index.js.map +1 -0
  456. package/dist/overlay/overlay-base.d.ts +105 -0
  457. package/dist/overlay/overlay-base.js +250 -0
  458. package/dist/overlay/overlay-base.js.map +1 -0
  459. package/dist/overlay/overlay.d.ts +299 -0
  460. package/dist/overlay/overlay.js +558 -0
  461. package/dist/overlay/overlay.js.map +1 -0
  462. package/dist/overlay/toast.d.ts +58 -0
  463. package/dist/overlay/toast.js +145 -0
  464. package/dist/overlay/toast.js.map +1 -0
  465. package/dist/provider.d.ts +26 -0
  466. package/dist/provider.js +30 -0
  467. package/dist/provider.js.map +1 -0
  468. package/dist/selection/autocomplete.d.ts +54 -0
  469. package/dist/selection/autocomplete.js +122 -0
  470. package/dist/selection/autocomplete.js.map +1 -0
  471. package/dist/selection/checkbox.d.ts +56 -0
  472. package/dist/selection/checkbox.js +49 -0
  473. package/dist/selection/checkbox.js.map +1 -0
  474. package/dist/selection/choice-size.d.ts +26 -0
  475. package/dist/selection/choice-size.js +50 -0
  476. package/dist/selection/choice-size.js.map +1 -0
  477. package/dist/selection/choice-text.d.ts +21 -0
  478. package/dist/selection/choice-text.js +33 -0
  479. package/dist/selection/choice-text.js.map +1 -0
  480. package/dist/selection/combobox.d.ts +173 -0
  481. package/dist/selection/combobox.js +410 -0
  482. package/dist/selection/combobox.js.map +1 -0
  483. package/dist/selection/index.d.ts +20 -0
  484. package/dist/selection/index.js +13 -0
  485. package/dist/selection/index.js.map +1 -0
  486. package/dist/selection/list-box.d.ts +30 -0
  487. package/dist/selection/list-box.js +16 -0
  488. package/dist/selection/list-box.js.map +1 -0
  489. package/dist/selection/listbox.d.ts +44 -0
  490. package/dist/selection/listbox.js +49 -0
  491. package/dist/selection/listbox.js.map +1 -0
  492. package/dist/selection/match.d.ts +20 -0
  493. package/dist/selection/match.js +57 -0
  494. package/dist/selection/match.js.map +1 -0
  495. package/dist/selection/multi-select.d.ts +72 -0
  496. package/dist/selection/multi-select.js +138 -0
  497. package/dist/selection/multi-select.js.map +1 -0
  498. package/dist/selection/radio-card.d.ts +31 -0
  499. package/dist/selection/radio-card.js +29 -0
  500. package/dist/selection/radio-card.js.map +1 -0
  501. package/dist/selection/radio.d.ts +72 -0
  502. package/dist/selection/radio.js +64 -0
  503. package/dist/selection/radio.js.map +1 -0
  504. package/dist/selection/select-public.d.ts +19 -0
  505. package/dist/selection/select-public.js +24 -0
  506. package/dist/selection/select-public.js.map +1 -0
  507. package/dist/selection/select.d.ts +72 -0
  508. package/dist/selection/select.js +69 -0
  509. package/dist/selection/select.js.map +1 -0
  510. package/dist/selection/slider.d.ts +16 -0
  511. package/dist/selection/slider.js +44 -0
  512. package/dist/selection/slider.js.map +1 -0
  513. package/dist/selection/styles.d.ts +26 -0
  514. package/dist/selection/styles.js +78 -0
  515. package/dist/selection/styles.js.map +1 -0
  516. package/dist/selection/switch.d.ts +24 -0
  517. package/dist/selection/switch.js +27 -0
  518. package/dist/selection/switch.js.map +1 -0
  519. package/dist/selection/tag-group.d.ts +38 -0
  520. package/dist/selection/tag-group.js +45 -0
  521. package/dist/selection/tag-group.js.map +1 -0
  522. package/dist/tone.d.ts +6 -0
  523. package/dist/tone.js +2 -0
  524. package/dist/tone.js.map +1 -0
  525. package/dist/utils.d.ts +9 -0
  526. package/dist/utils.js +42 -0
  527. package/dist/utils.js.map +1 -0
  528. package/manifest/component.full.schema.json +391 -0
  529. package/manifest/component.schema.json +279 -0
  530. package/manifests/accordion.json +299 -0
  531. package/manifests/alert-dialog.json +261 -0
  532. package/manifests/area-chart.json +338 -0
  533. package/manifests/autocomplete.json +299 -0
  534. package/manifests/avatar.json +253 -0
  535. package/manifests/badge.json +288 -0
  536. package/manifests/banner.json +185 -0
  537. package/manifests/bar-chart.json +454 -0
  538. package/manifests/bar-list.json +262 -0
  539. package/manifests/bottom-nav.json +139 -0
  540. package/manifests/box.json +3450 -0
  541. package/manifests/breadcrumbs.json +199 -0
  542. package/manifests/button-group.json +2294 -0
  543. package/manifests/button.json +1211 -0
  544. package/manifests/calendar-heatmap.json +218 -0
  545. package/manifests/calendar.json +299 -0
  546. package/manifests/card.json +308 -0
  547. package/manifests/carousel.json +263 -0
  548. package/manifests/chart-parts.json +309 -0
  549. package/manifests/checkbox.json +998 -0
  550. package/manifests/close-button.json +1000 -0
  551. package/manifests/color-field.json +276 -0
  552. package/manifests/color-picker.json +161 -0
  553. package/manifests/color-swatch-picker.json +220 -0
  554. package/manifests/color-swatch.json +140 -0
  555. package/manifests/combobox.json +581 -0
  556. package/manifests/command.json +275 -0
  557. package/manifests/composed-chart.json +287 -0
  558. package/manifests/context-menu.json +148 -0
  559. package/manifests/copy-button.json +192 -0
  560. package/manifests/data-table.json +334 -0
  561. package/manifests/date-field.json +302 -0
  562. package/manifests/date-picker.json +472 -0
  563. package/manifests/description-list.json +201 -0
  564. package/manifests/dialog.json +322 -0
  565. package/manifests/donut-chart.json +264 -0
  566. package/manifests/drawer.json +211 -0
  567. package/manifests/empty-state.json +185 -0
  568. package/manifests/fab.json +172 -0
  569. package/manifests/field.json +209 -0
  570. package/manifests/file-upload.json +791 -0
  571. package/manifests/form.json +829 -0
  572. package/manifests/funnel-chart.json +223 -0
  573. package/manifests/gauge-chart.json +252 -0
  574. package/manifests/grid-list.json +335 -0
  575. package/manifests/grid.json +3482 -0
  576. package/manifests/heading.json +183 -0
  577. package/manifests/heatmap.json +265 -0
  578. package/manifests/hover-card.json +172 -0
  579. package/manifests/icon.json +201 -0
  580. package/manifests/image-cropper.json +295 -0
  581. package/manifests/image-viewer.json +198 -0
  582. package/manifests/image.json +193 -0
  583. package/manifests/index.json +2035 -0
  584. package/manifests/input-group.json +3571 -0
  585. package/manifests/input.json +1557 -0
  586. package/manifests/kbd.json +98 -0
  587. package/manifests/language-switcher.json +274 -0
  588. package/manifests/line-chart.json +342 -0
  589. package/manifests/link.json +867 -0
  590. package/manifests/list-box.json +213 -0
  591. package/manifests/menu.json +453 -0
  592. package/manifests/meter.json +145 -0
  593. package/manifests/navbar.json +281 -0
  594. package/manifests/otp-field.json +1029 -0
  595. package/manifests/page-header.json +164 -0
  596. package/manifests/pagination.json +181 -0
  597. package/manifests/popover.json +205 -0
  598. package/manifests/pressable.json +367 -0
  599. package/manifests/progress.json +282 -0
  600. package/manifests/radar-chart.json +229 -0
  601. package/manifests/radial-chart.json +195 -0
  602. package/manifests/radio.json +975 -0
  603. package/manifests/scatter-chart.json +277 -0
  604. package/manifests/scroll-area.json +127 -0
  605. package/manifests/section.json +169 -0
  606. package/manifests/select.json +474 -0
  607. package/manifests/separator.json +119 -0
  608. package/manifests/sidebar.json +584 -0
  609. package/manifests/skeleton.json +235 -0
  610. package/manifests/skip-link.json +89 -0
  611. package/manifests/slider.json +706 -0
  612. package/manifests/sparkline.json +208 -0
  613. package/manifests/spinner.json +105 -0
  614. package/manifests/split.json +6618 -0
  615. package/manifests/stack.json +3541 -0
  616. package/manifests/stat.json +192 -0
  617. package/manifests/stepper.json +279 -0
  618. package/manifests/switch.json +205 -0
  619. package/manifests/table.json +375 -0
  620. package/manifests/tabs.json +438 -0
  621. package/manifests/tag-group.json +264 -0
  622. package/manifests/text-area.json +1136 -0
  623. package/manifests/text.json +244 -0
  624. package/manifests/theme-switcher.json +152 -0
  625. package/manifests/time-field.json +284 -0
  626. package/manifests/timeline.json +196 -0
  627. package/manifests/toast.json +87 -0
  628. package/manifests/toggle-button.json +1489 -0
  629. package/manifests/toolbar.json +145 -0
  630. package/manifests/tooltip.json +181 -0
  631. package/manifests/tracker.json +192 -0
  632. package/manifests/tree.json +245 -0
  633. package/manifests/visually-hidden.json +114 -0
  634. package/package.json +117 -3
  635. package/styles/base.css +56 -0
  636. package/styles/theme.css +154 -0
@@ -0,0 +1,117 @@
1
+ /**
2
+ * ImageCropper's geometry and output, kept apart from the component so the rules the
3
+ * cropper exists for are tested on their own:
4
+ * - never upscale: the output is the crop region in source pixels, only ever scaled down;
5
+ * - contain never paints black: an output without alpha (JPEG) fills the empty area with the
6
+ * background, white by default; PNG and WebP keep it transparent.
7
+ *
8
+ * Coordinates are in the source's pixels after rotation ("rotated space"): a 90° turn of a 4000 × 3000
9
+ * photo is a 3000 × 4000 image to crop.
10
+ */
11
+ export const MIN_ZOOM = 1;
12
+ export const MAX_ZOOM = 4;
13
+ /** Outputs that keep transparency; the rest get the background under empty areas. */
14
+ export const hasAlpha = (type) => type !== "image/jpeg";
15
+ /** The source's size once turned. */
16
+ export function rotatedSize(width, height, rotation) {
17
+ return rotation % 180 === 0 ? { width, height } : { width: height, height: width };
18
+ }
19
+ /**
20
+ * The crop region for a frame aspect (width / height): at zoom 1, `cover` is the largest region of that
21
+ * shape inside the image and `contain` the smallest that holds the whole image (the rest is empty area).
22
+ * Zoom shrinks the region; the centre is kept so the region never leaves the image along a side it is
23
+ * smaller than, and stays centred along a side it is larger than (only contain's empty area).
24
+ */
25
+ export function cropRegion(image, aspect, fit, state) {
26
+ const imageAspect = image.width / image.height;
27
+ const widerFrame = aspect > imageAspect;
28
+ // cover: limited by the image's short side for this shape; contain: by its long side.
29
+ const baseWidth = fit === "cover" ? (widerFrame ? image.width : image.height * aspect) : widerFrame ? image.height * aspect : image.width;
30
+ const zoom = clampZoom(state.zoom);
31
+ const width = baseWidth / zoom;
32
+ const height = width / aspect;
33
+ const centerX = clampCenter(state.centerX, width, image.width);
34
+ const centerY = clampCenter(state.centerY, height, image.height);
35
+ return { left: centerX - width / 2, top: centerY - height / 2, width, height };
36
+ }
37
+ export const clampZoom = (zoom) => Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, Number.isFinite(zoom) ? zoom : MIN_ZOOM));
38
+ function clampCenter(center, size, extent) {
39
+ if (size >= extent)
40
+ return extent / 2;
41
+ return Math.min(extent - size / 2, Math.max(size / 2, center));
42
+ }
43
+ /**
44
+ * The output size: the region in source pixels, scaled down to `maxOutputSize` on the long edge, never up.
45
+ * `small` is true when the long edge is under `minOutputSize` (the warning; it never blocks).
46
+ */
47
+ export function outputSize(region, { maxOutputSize, minOutputSize }) {
48
+ const long = Math.max(region.width, region.height);
49
+ const scale = maxOutputSize && long > maxOutputSize ? maxOutputSize / long : 1;
50
+ const width = Math.max(1, Math.round(region.width * scale));
51
+ const height = Math.max(1, Math.round(region.height * scale));
52
+ return { width, height, scale, small: Boolean(minOutputSize && Math.max(width, height) < minOutputSize) };
53
+ }
54
+ /**
55
+ * Draws the crop on a context sized `size`: the background first when the output has no alpha (so empty
56
+ * contain areas and transparent pixels never turn black), then the turned image mapped so the region fills
57
+ * the canvas.
58
+ */
59
+ export function drawCrop(context, image, source, region, size, { rotation, outputType, background = "#ffffff" }) {
60
+ context.clearRect(0, 0, size.width, size.height);
61
+ if (!hasAlpha(outputType)) {
62
+ context.fillStyle = background;
63
+ context.fillRect(0, 0, size.width, size.height);
64
+ }
65
+ const turned = rotatedSize(source.width, source.height, rotation);
66
+ // Each edge on its own: after rounding, width and height can differ by under a pixel, which would leave
67
+ // a faint row of background (or transparency) along the bottom.
68
+ context.save();
69
+ context.imageSmoothingEnabled = true;
70
+ context.imageSmoothingQuality = "high";
71
+ context.scale(size.width / region.width, size.height / region.height);
72
+ context.translate(-region.left, -region.top);
73
+ // Into rotated space: turn about the turned image's centre, then draw the source centred on it.
74
+ context.translate(turned.width / 2, turned.height / 2);
75
+ context.rotate((rotation * Math.PI) / 180);
76
+ context.drawImage(image, -source.width / 2, -source.height / 2, source.width, source.height);
77
+ context.restore();
78
+ }
79
+ /** The output file's extension for its type. */
80
+ export const extensionOf = (type) => (type === "image/jpeg" ? "jpg" : type === "image/png" ? "png" : "webp");
81
+ /**
82
+ * The qualities to try under a byte limit, as an image upload typically needs for a logo,
83
+ * hero and slide uploads: from `quality` down in steps of 0.1, never under `minimumQuality` (0.1 by default, at most
84
+ * `quality`), rounded to hundredths. Without a limit, or for PNG (lossless: its quality does nothing), one try.
85
+ */
86
+ export function qualitySteps({ outputType, quality, minimumQuality, maxBytes }) {
87
+ if (!maxBytes || outputType === "image/png")
88
+ return [quality];
89
+ const floor = Math.min(quality, Math.max(0.1, minimumQuality ?? 0.1));
90
+ const steps = [];
91
+ for (let index = 0;; index++) {
92
+ const step = Math.round(Math.max(floor, quality - index * 0.1) * 100) / 100;
93
+ if (steps[steps.length - 1] !== step)
94
+ steps.push(step);
95
+ if (step <= floor)
96
+ break;
97
+ }
98
+ return steps;
99
+ }
100
+ /**
101
+ * Encodes at each of `qualitySteps` until the file is at most `maxBytes`, and says whether it got there. `encode` is
102
+ * the canvas's toBlob (a stub in tests); a null from it is a failed export and throws.
103
+ */
104
+ export async function encodeWithin(encode, options) {
105
+ let last;
106
+ for (const quality of qualitySteps(options)) {
107
+ // PNG is lossless: the browser ignores a quality for it, so none is passed.
108
+ const blob = await encode(options.outputType === "image/png" ? undefined : quality);
109
+ if (!blob)
110
+ throw new Error("export-failed");
111
+ last = { blob, quality };
112
+ if (!options.maxBytes || blob.size <= options.maxBytes)
113
+ return { ...last, fits: true };
114
+ }
115
+ return { ...last, fits: false };
116
+ }
117
+ //# sourceMappingURL=image-crop.js.map
@@ -0,0 +1 @@
1
+ {"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KAAK,EAAE,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;QAC5E,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvD,IAAI,IAAI,IAAI,KAAK;YAAE,MAAM;IAC3B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAID;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA6D,EAC7D,OAAoG;IAEpG,IAAI,IAAiD,CAAC;IACtD,KAAK,MAAM,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5C,4EAA4E;QAC5E,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,UAAU,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACpF,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QAC5C,IAAI,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,QAAQ;YAAE,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACzF,CAAC;IACD,OAAO,EAAE,GAAG,IAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACnC,CAAC","sourcesContent":["/**\n * ImageCropper's geometry and output, kept apart from the component so the rules the\n * cropper exists for are tested on their own:\n * - never upscale: the output is the crop region in source pixels, only ever scaled down;\n * - contain never paints black: an output without alpha (JPEG) fills the empty area with the\n * background, white by default; PNG and WebP keep it transparent.\n *\n * Coordinates are in the source's pixels after rotation (\"rotated space\"): a 90° turn of a 4000 × 3000\n * photo is a 3000 × 4000 image to crop.\n */\n\nexport type CropFit = \"cover\" | \"contain\";\nexport type CropOutputType = \"image/jpeg\" | \"image/png\" | \"image/webp\";\nexport type CropRotation = 0 | 90 | 180 | 270;\n\nexport type CropState = {\n /** 1 shows the whole fit; up to 4. */\n zoom: number;\n /** The crop region's centre, in rotated-space pixels. */\n centerX: number;\n centerY: number;\n rotation: CropRotation;\n};\n\nexport type CropRegion = { left: number; top: number; width: number; height: number };\n\nexport const MIN_ZOOM = 1;\nexport const MAX_ZOOM = 4;\n\n/** Outputs that keep transparency; the rest get the background under empty areas. */\nexport const hasAlpha = (type: CropOutputType) => type !== \"image/jpeg\";\n\n/** The source's size once turned. */\nexport function rotatedSize(width: number, height: number, rotation: CropRotation) {\n return rotation % 180 === 0 ? { width, height } : { width: height, height: width };\n}\n\n/**\n * The crop region for a frame aspect (width / height): at zoom 1, `cover` is the largest region of that\n * shape inside the image and `contain` the smallest that holds the whole image (the rest is empty area).\n * Zoom shrinks the region; the centre is kept so the region never leaves the image along a side it is\n * smaller than, and stays centred along a side it is larger than (only contain's empty area).\n */\nexport function cropRegion(image: { width: number; height: number }, aspect: number, fit: CropFit, state: Pick<CropState, \"zoom\" | \"centerX\" | \"centerY\">): CropRegion {\n const imageAspect = image.width / image.height;\n const widerFrame = aspect > imageAspect;\n // cover: limited by the image's short side for this shape; contain: by its long side.\n const baseWidth = fit === \"cover\" ? (widerFrame ? image.width : image.height * aspect) : widerFrame ? image.height * aspect : image.width;\n const zoom = clampZoom(state.zoom);\n const width = baseWidth / zoom;\n const height = width / aspect;\n const centerX = clampCenter(state.centerX, width, image.width);\n const centerY = clampCenter(state.centerY, height, image.height);\n return { left: centerX - width / 2, top: centerY - height / 2, width, height };\n}\n\nexport const clampZoom = (zoom: number) => Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, Number.isFinite(zoom) ? zoom : MIN_ZOOM));\n\nfunction clampCenter(center: number, size: number, extent: number) {\n if (size >= extent) return extent / 2;\n return Math.min(extent - size / 2, Math.max(size / 2, center));\n}\n\n/**\n * The output size: the region in source pixels, scaled down to `maxOutputSize` on the long edge, never up.\n * `small` is true when the long edge is under `minOutputSize` (the warning; it never blocks).\n */\nexport function outputSize(region: CropRegion, { maxOutputSize, minOutputSize }: { maxOutputSize?: number; minOutputSize?: number }) {\n const long = Math.max(region.width, region.height);\n const scale = maxOutputSize && long > maxOutputSize ? maxOutputSize / long : 1;\n const width = Math.max(1, Math.round(region.width * scale));\n const height = Math.max(1, Math.round(region.height * scale));\n return { width, height, scale, small: Boolean(minOutputSize && Math.max(width, height) < minOutputSize) };\n}\n\n/** The 2D context calls the renderer makes; a canvas's context, or a recorder in tests. */\nexport type CropContext = Pick<\n CanvasRenderingContext2D,\n \"fillStyle\" | \"fillRect\" | \"clearRect\" | \"save\" | \"restore\" | \"translate\" | \"rotate\" | \"scale\" | \"drawImage\" | \"imageSmoothingEnabled\" | \"imageSmoothingQuality\"\n>;\n\n/**\n * Draws the crop on a context sized `size`: the background first when the output has no alpha (so empty\n * contain areas and transparent pixels never turn black), then the turned image mapped so the region fills\n * the canvas.\n */\nexport function drawCrop(\n context: CropContext,\n image: CanvasImageSource,\n source: { width: number; height: number },\n region: CropRegion,\n size: { width: number; height: number },\n { rotation, outputType, background = \"#ffffff\" }: { rotation: CropRotation; outputType: CropOutputType; background?: string },\n) {\n context.clearRect(0, 0, size.width, size.height);\n if (!hasAlpha(outputType)) {\n context.fillStyle = background;\n context.fillRect(0, 0, size.width, size.height);\n }\n const turned = rotatedSize(source.width, source.height, rotation);\n // Each edge on its own: after rounding, width and height can differ by under a pixel, which would leave\n // a faint row of background (or transparency) along the bottom.\n context.save();\n context.imageSmoothingEnabled = true;\n context.imageSmoothingQuality = \"high\";\n context.scale(size.width / region.width, size.height / region.height);\n context.translate(-region.left, -region.top);\n // Into rotated space: turn about the turned image's centre, then draw the source centred on it.\n context.translate(turned.width / 2, turned.height / 2);\n context.rotate((rotation * Math.PI) / 180);\n context.drawImage(image, -source.width / 2, -source.height / 2, source.width, source.height);\n context.restore();\n}\n\n/** The output file's extension for its type. */\nexport const extensionOf = (type: CropOutputType) => (type === \"image/jpeg\" ? \"jpg\" : type === \"image/png\" ? \"png\" : \"webp\");\n\n/**\n * The qualities to try under a byte limit, as an image upload typically needs for a logo,\n * hero and slide uploads: from `quality` down in steps of 0.1, never under `minimumQuality` (0.1 by default, at most\n * `quality`), rounded to hundredths. Without a limit, or for PNG (lossless: its quality does nothing), one try.\n */\nexport function qualitySteps({ outputType, quality, minimumQuality, maxBytes }: { outputType: CropOutputType; quality: number; minimumQuality?: number; maxBytes?: number }) {\n if (!maxBytes || outputType === \"image/png\") return [quality];\n const floor = Math.min(quality, Math.max(0.1, minimumQuality ?? 0.1));\n const steps: number[] = [];\n for (let index = 0; ; index++) {\n const step = Math.round(Math.max(floor, quality - index * 0.1) * 100) / 100;\n if (steps[steps.length - 1] !== step) steps.push(step);\n if (step <= floor) break;\n }\n return steps;\n}\n\nexport type EncodeResult = { blob: Blob; quality: number; fits: boolean };\n\n/**\n * Encodes at each of `qualitySteps` until the file is at most `maxBytes`, and says whether it got there. `encode` is\n * the canvas's toBlob (a stub in tests); a null from it is a failed export and throws.\n */\nexport async function encodeWithin(\n encode: (quality: number | undefined) => Promise<Blob | null>,\n options: { outputType: CropOutputType; quality: number; minimumQuality?: number; maxBytes?: number },\n): Promise<EncodeResult> {\n let last: { blob: Blob; quality: number } | undefined;\n for (const quality of qualitySteps(options)) {\n // PNG is lossless: the browser ignores a quality for it, so none is passed.\n const blob = await encode(options.outputType === \"image/png\" ? undefined : quality);\n if (!blob) throw new Error(\"export-failed\");\n last = { blob, quality };\n if (!options.maxBytes || blob.size <= options.maxBytes) return { ...last, fits: true };\n }\n return { ...last!, fits: false };\n}\n"]}
@@ -0,0 +1,68 @@
1
+ import * as React from "react";
2
+ import { type CropFit, type CropOutputType } from "./image-crop.js";
3
+ export type ImageCropperAspect = number | "free";
4
+ export type ImageCropperPreset = {
5
+ id: string;
6
+ /** "Cover 16:9". */
7
+ label: string;
8
+ aspectRatio: ImageCropperAspect;
9
+ /** The fit this surface uses; the cropper's `fit` otherwise. */
10
+ fit?: CropFit;
11
+ };
12
+ export type ImageCropperResult = {
13
+ width: number;
14
+ height: number;
15
+ type: CropOutputType;
16
+ };
17
+ export type ImageCropperProps = {
18
+ /**
19
+ * The picked file (from FileTrigger, already checked for size and type), or an image URL. A URL from
20
+ * another origin is loaded with CORS so the crop can be read back: its server must send
21
+ * `Access-Control-Allow-Origin`, or the image does not open (rather than failing later at save).
22
+ */
23
+ src: Blob | string;
24
+ /** What is being cropped ("Cover photo"); names the crop frame. */
25
+ label: string;
26
+ /** 16:9 by default; `"free"` keeps the image's own shape. Ignored when presets are given. */
27
+ aspectRatio?: ImageCropperAspect;
28
+ /** Two or more shapes to choose from (a segmented control); the first is selected. */
29
+ aspectPresets?: readonly ImageCropperPreset[];
30
+ /** `cover` (default) fills the frame; `contain` fits the whole image and leaves empty area. */
31
+ fit?: CropFit;
32
+ /** The empty area's colour in `contain` when the output has no alpha (JPEG). White by default. */
33
+ background?: string;
34
+ /** `image/jpeg` by default. PNG and WebP keep transparency. */
35
+ outputType?: CropOutputType;
36
+ /** 0–1, for JPEG and WebP. 0.9 by default. */
37
+ quality?: number;
38
+ /**
39
+ * The largest file the surface takes, in bytes. A JPEG or WebP
40
+ * over it is encoded again at a quality 0.1 lower each time, down to `minimumQuality`; when even that is over, or
41
+ * a PNG is, nothing is handed to `onCrop` and the cropper says the image is over the limit (a smaller crop, by
42
+ * zooming in, or another image fits).
43
+ */
44
+ maxBytes?: number;
45
+ /** The lowest quality `maxBytes` may step down to (0.9 keeps a hero or slide sharp). 0.1 by default; at most `quality`. */
46
+ minimumQuality?: number;
47
+ /**
48
+ * The output's long edge in px at most (a surface's size, 2560 for a full-width photo): larger crops scale down,
49
+ * never up. 4096 by default, so a 48 MP phone photo stays within every browser's canvas limit.
50
+ */
51
+ maxOutputSize?: number;
52
+ /** Under this long edge the warning shows; it never blocks. */
53
+ minOutputSize?: number;
54
+ /** The output file's name without extension; the source file's name by default. */
55
+ fileName?: string;
56
+ onCrop: (file: File, result: ImageCropperResult) => unknown;
57
+ onCancel?: () => void;
58
+ };
59
+ /**
60
+ * Frames one picked image to the shape a surface needs (a 16:9 cover photo, a square logo) and hands
61
+ * back the cropped file at the source's own pixel density: never upscaled, only scaled down to
62
+ * `maxOutputSize`. In `contain`, the empty area takes `background` when the output has no
63
+ * alpha, white by default, never black. A sunken stage dims what falls outside a white frame
64
+ * with thirds guides; the toolbar holds the shapes, zoom, rotation and fit. The frame is one focusable
65
+ * group: arrows move the image (Shift for 10%), + and − zoom, [ and ] rotate, and each change is announced.
66
+ * The toolbar mirrors in RTL; the image and the arrows never do.
67
+ */
68
+ export declare function ImageCropper({ src, label, aspectRatio, aspectPresets, fit: fitProp, background: backgroundProp, outputType, quality, maxBytes, minimumQuality, maxOutputSize, minOutputSize, fileName, onCrop, onCancel, }: ImageCropperProps): React.JSX.Element;
@@ -0,0 +1,284 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Slider as AriaSlider, SliderThumb, SliderTrack, useLocale } from "react-aria-components";
5
+ import { cn } from "../utils.js";
6
+ import { Button } from "../action/button.js";
7
+ import { formatFileSize } from "../action/files.js";
8
+ import { ColorSwatchPicker } from "../color/color.js";
9
+ import { cancelLabel, colorBlackLabel, colorLightGreyLabel, colorWhiteLabel, cropAspectLabel, cropBackgroundLabel, cropCenteredLabel, cropContainLabel, cropCoverLabel, cropFitLabel, cropHelpLabel, cropKeepsAlphaLabel, cropLoadFailedLabel, cropOutputLabel, cropPositionLabel, cropRotateLeftLabel, cropRotateRightLabel, cropSaveFailedLabel, cropSaveLabel, cropSmallLabel, cropStatusLabel, cropTooLargeLabel, cropZoomInLabel, cropZoomLabel, cropZoomOutLabel, intlLocale, } from "../i18n.js";
10
+ import { SegmentedControl } from "../navigation/tabs.js";
11
+ import { SLIDER_FILL, SLIDER_RAIL, SLIDER_THUMB, SLIDER_TRACK } from "../selection/styles.js";
12
+ import { IconGlyph } from "./icon.js";
13
+ import { MAX_ZOOM, MIN_ZOOM, clampZoom, cropRegion, drawCrop, encodeWithin, extensionOf, hasAlpha, outputSize, rotatedSize, } from "./image-crop.js";
14
+ const STAGE_ASPECT = 16 / 10;
15
+ const FRAME_INSET = 0.06;
16
+ const ZOOM_STEP = 0.1;
17
+ /** Fixed paper and light grey: the frame and checkerboard draw on the photo, not on a theme surface. */
18
+ const CHECKER = "repeating-conic-gradient(#ebe9e6 0 25%, #fcfcfb 0 50%) 0 0 / 16px 16px";
19
+ const SWATCHES = ["#ffffff", "#ebe9e6", "#0e0c09"];
20
+ const TYPE_NAMES = { "image/jpeg": "JPEG", "image/png": "PNG", "image/webp": "WebP" };
21
+ /** The image behind `src`, decoded; an object URL for a file, revoked when it changes. */
22
+ function useSourceImage(src) {
23
+ const [state, setState] = React.useState({});
24
+ React.useEffect(() => {
25
+ const url = typeof src === "string" ? src : URL.createObjectURL(src);
26
+ let live = true;
27
+ setState({ url });
28
+ const image = new Image();
29
+ image.decoding = "async";
30
+ // A URL from a CDN must not taint the canvas, or the crop could never be read back.
31
+ if (typeof src === "string" && !/^(data|blob):/.test(src))
32
+ image.crossOrigin = "anonymous";
33
+ image.onload = () => live && setState({ url, loaded: { image, width: image.naturalWidth, height: image.naturalHeight } });
34
+ image.onerror = () => live && setState({ url, failed: true });
35
+ image.src = url;
36
+ return () => {
37
+ live = false;
38
+ if (typeof src !== "string")
39
+ URL.revokeObjectURL(url);
40
+ };
41
+ }, [src]);
42
+ return state;
43
+ }
44
+ /** The element's width in whole px, following resizes. */
45
+ function useWidth() {
46
+ const [element, setElement] = React.useState(null);
47
+ const [width, setWidth] = React.useState(0);
48
+ React.useLayoutEffect(() => {
49
+ if (!element)
50
+ return;
51
+ setWidth(Math.floor(element.getBoundingClientRect().width));
52
+ if (typeof ResizeObserver === "undefined")
53
+ return;
54
+ const observer = new ResizeObserver(([entry]) => setWidth(Math.floor(entry.contentRect.width)));
55
+ observer.observe(element);
56
+ return () => observer.disconnect();
57
+ }, [element]);
58
+ return [setElement, width, element];
59
+ }
60
+ /**
61
+ * Frames one picked image to the shape a surface needs (a 16:9 cover photo, a square logo) and hands
62
+ * back the cropped file at the source's own pixel density: never upscaled, only scaled down to
63
+ * `maxOutputSize`. In `contain`, the empty area takes `background` when the output has no
64
+ * alpha, white by default, never black. A sunken stage dims what falls outside a white frame
65
+ * with thirds guides; the toolbar holds the shapes, zoom, rotation and fit. The frame is one focusable
66
+ * group: arrows move the image (Shift for 10%), + and − zoom, [ and ] rotate, and each change is announced.
67
+ * The toolbar mirrors in RTL; the image and the arrows never do.
68
+ */
69
+ export function ImageCropper({ src, label, aspectRatio = 16 / 9, aspectPresets, fit: fitProp = "cover", background: backgroundProp = "#ffffff", outputType = "image/jpeg", quality = 0.9, maxBytes, minimumQuality, maxOutputSize = 4096, minOutputSize, fileName, onCrop, onCancel, }) {
70
+ const { locale } = useLocale();
71
+ const source = useSourceImage(src);
72
+ const presets = aspectPresets && aspectPresets.length > 1 ? aspectPresets : undefined;
73
+ const [presetId, setPresetId] = React.useState(presets?.[0]?.id);
74
+ const preset = presets?.find((item) => item.id === presetId) ?? presets?.[0];
75
+ const [fit, setFit] = React.useState(preset?.fit ?? fitProp);
76
+ const [background, setBackground] = React.useState(backgroundProp);
77
+ // Props changed later win again: a new fit or background from the surface.
78
+ React.useEffect(() => setFit(preset?.fit ?? fitProp), [fitProp]); // preset changes set fit themselves
79
+ React.useEffect(() => setBackground(backgroundProp), [backgroundProp]);
80
+ // `true` a failed save; "too-large" a crop over `maxBytes` at the lowest quality allowed.
81
+ const [saveError, setSaveError] = React.useState(false);
82
+ const [rotation, setRotation] = React.useState(0);
83
+ const [zoom, setZoom] = React.useState(1);
84
+ const [center, setCenter] = React.useState(null);
85
+ const [status, setStatus] = React.useState("");
86
+ const [saving, setSaving] = React.useState(false);
87
+ const [stageRef, stageWidth, stageElement] = useWidth();
88
+ const helpId = React.useId();
89
+ const loaded = source.loaded;
90
+ // A new picture starts afresh: upright, whole, centred.
91
+ React.useEffect(() => {
92
+ setRotation(0);
93
+ setZoom(1);
94
+ setCenter(null);
95
+ setStatus("");
96
+ setSaveError(false);
97
+ }, [source.url]);
98
+ const turned = loaded ? rotatedSize(loaded.width, loaded.height, rotation) : { width: 1, height: 1 };
99
+ const shape = preset ? preset.aspectRatio : aspectRatio;
100
+ const aspect = shape === "free" ? turned.width / turned.height : shape;
101
+ const centerX = center?.x ?? turned.width / 2;
102
+ const centerY = center?.y ?? turned.height / 2;
103
+ const region = cropRegion(turned, aspect, fit, { zoom, centerX, centerY });
104
+ const size = outputSize(region, { maxOutputSize, minOutputSize });
105
+ // The warning is about the source, not the zoom: shown when even the whole fit is under the surface's size.
106
+ const sourceTooSmall = outputSize(cropRegion(turned, aspect, fit, { zoom: 1, centerX, centerY }), { maxOutputSize, minOutputSize }).small;
107
+ const alpha = hasAlpha(outputType);
108
+ // The frame inside the stage: the largest rectangle of the crop's shape, inset from the edges.
109
+ const stageHeight = Math.round(stageWidth / STAGE_ASPECT);
110
+ const roomWidth = stageWidth * (1 - 2 * FRAME_INSET);
111
+ const roomHeight = stageHeight * (1 - 2 * FRAME_INSET);
112
+ const frameWidth = Math.min(roomWidth, roomHeight * aspect);
113
+ const frameHeight = frameWidth / aspect;
114
+ const frameLeft = (stageWidth - frameWidth) / 2;
115
+ const frameTop = (stageHeight - frameHeight) / 2;
116
+ const scale = region.width > 0 ? frameWidth / region.width : 0;
117
+ const percent = React.useMemo(() => new Intl.NumberFormat(intlLocale(locale), { style: "percent", maximumFractionDigits: 0 }), [locale]);
118
+ const describe = (nextZoom, x, y, dims = turned) => {
119
+ const across = x / dims.width;
120
+ const down = y / dims.height;
121
+ const position = Math.abs(across - 0.5) < 0.005 && Math.abs(down - 0.5) < 0.005 ? cropCenteredLabel(locale) : cropPositionLabel(locale, percent.format(across), percent.format(down));
122
+ return cropStatusLabel(locale, percent.format(nextZoom), position);
123
+ };
124
+ // The latest position, ahead of React's render: several keys or wheel ticks in one task each build on the
125
+ // one before instead of the same rendered state.
126
+ const live = React.useRef({ zoom, x: centerX, y: centerY, rotation });
127
+ live.current = { zoom, x: centerX, y: centerY, rotation };
128
+ const turnedFor = (turn) => (loaded ? rotatedSize(loaded.width, loaded.height, turn) : turned);
129
+ // Every change keeps the centre where the region can be, then says where things are.
130
+ const apply = (next, announce = true) => {
131
+ const base = live.current;
132
+ const nextRotation = next.rotation ?? base.rotation;
133
+ const nextTurned = turnedFor(nextRotation);
134
+ const nextAspect = shape === "free" ? nextTurned.width / nextTurned.height : shape;
135
+ const nextZoom = clampZoom(next.zoom ?? base.zoom);
136
+ const settled = cropRegion(nextTurned, nextAspect, fit, { zoom: nextZoom, centerX: next.x ?? base.x, centerY: next.y ?? base.y });
137
+ const x = settled.left + settled.width / 2;
138
+ const y = settled.top + settled.height / 2;
139
+ live.current = { zoom: nextZoom, x, y, rotation: nextRotation };
140
+ setZoom(nextZoom);
141
+ setCenter({ x, y });
142
+ if (next.rotation !== undefined)
143
+ setRotation(nextRotation);
144
+ if (announce)
145
+ setStatus(describe(nextZoom, x, y, nextTurned));
146
+ };
147
+ const zoomBy = (delta, announce = true) => apply({ zoom: live.current.zoom + delta }, announce);
148
+ const nudge = (dx, dy) => {
149
+ const size = turnedFor(live.current.rotation);
150
+ apply({ x: live.current.x - dx * size.width, y: live.current.y - dy * size.height });
151
+ };
152
+ const rotate = (turn) => {
153
+ const next = ((((live.current.rotation + turn) % 360) + 360) % 360);
154
+ // The new shape starts centred.
155
+ const nextTurned = turnedFor(next);
156
+ apply({ rotation: next, x: nextTurned.width / 2, y: nextTurned.height / 2 });
157
+ };
158
+ const onKeyDown = (event) => {
159
+ // Browser zoom (Ctrl/Cmd with + and −) and other shortcuts stay the browser's.
160
+ if (event.ctrlKey || event.metaKey || event.altKey)
161
+ return;
162
+ const step = event.shiftKey ? 0.1 : 0.01;
163
+ // Spatial, so never mirrored in RTL: the image moves the way the arrow points.
164
+ const moves = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, -step], ArrowDown: [0, step] };
165
+ if (moves[event.key])
166
+ nudge(...moves[event.key]);
167
+ else if (event.key === "+" || event.key === "=")
168
+ zoomBy(ZOOM_STEP);
169
+ else if (event.key === "-" || event.key === "_")
170
+ zoomBy(-ZOOM_STEP);
171
+ else if (event.key === "[")
172
+ rotate(-90);
173
+ else if (event.key === "]")
174
+ rotate(90);
175
+ else
176
+ return;
177
+ event.preventDefault();
178
+ };
179
+ // Pointer: drag moves, the wheel zooms.
180
+ const drag = React.useRef(null);
181
+ const onPointerDown = (event) => {
182
+ if (!loaded || event.button !== 0)
183
+ return;
184
+ event.currentTarget.setPointerCapture?.(event.pointerId);
185
+ drag.current = { x: event.clientX, y: event.clientY, centerX, centerY };
186
+ };
187
+ const onPointerMove = (event) => {
188
+ if (!drag.current || scale <= 0)
189
+ return;
190
+ apply({ x: drag.current.centerX - (event.clientX - drag.current.x) / scale, y: drag.current.centerY - (event.clientY - drag.current.y) / scale }, false);
191
+ };
192
+ const onPointerUp = () => {
193
+ if (drag.current)
194
+ setStatus(describe(live.current.zoom, live.current.x, live.current.y, turnedFor(live.current.rotation)));
195
+ drag.current = null;
196
+ };
197
+ // The wheel zooms in proportion to how far it turns (a trackpad sends many small steps) and never scrolls
198
+ // the page underneath: React's wheel listener is passive, so this one is native.
199
+ const wheelRef = React.useRef(() => { });
200
+ wheelRef.current = (event) => {
201
+ if (!loaded || event.deltaY === 0)
202
+ return;
203
+ const pixels = event.deltaMode === 1 ? event.deltaY * 16 : event.deltaMode === 2 ? event.deltaY * 400 : event.deltaY;
204
+ const zoomingIn = pixels < 0;
205
+ // At a limit in the wheel's direction the page scrolls on, as it does over any other part of it.
206
+ if ((zoomingIn && live.current.zoom >= MAX_ZOOM) || (!zoomingIn && live.current.zoom <= MIN_ZOOM))
207
+ return;
208
+ event.preventDefault();
209
+ zoomBy(Math.max(-0.5, Math.min(0.5, -pixels / 500)), false);
210
+ };
211
+ React.useEffect(() => {
212
+ if (!stageElement)
213
+ return;
214
+ const onWheel = (event) => wheelRef.current(event);
215
+ stageElement.addEventListener("wheel", onWheel, { passive: false });
216
+ return () => stageElement.removeEventListener("wheel", onWheel);
217
+ }, [stageElement]);
218
+ const save = async () => {
219
+ if (!loaded)
220
+ return;
221
+ setSaving(true);
222
+ setSaveError(false);
223
+ try {
224
+ const canvas = document.createElement("canvas");
225
+ canvas.width = size.width;
226
+ canvas.height = size.height;
227
+ const context = canvas.getContext("2d");
228
+ if (!context)
229
+ throw new Error("canvas-unavailable");
230
+ drawCrop(context, loaded.image, loaded, region, size, { rotation, outputType, background });
231
+ const encoded = await encodeWithin((step) => new Promise((resolve) => canvas.toBlob(resolve, outputType, step)), {
232
+ outputType,
233
+ quality,
234
+ minimumQuality,
235
+ maxBytes,
236
+ });
237
+ if (!encoded.fits) {
238
+ setSaveError("too-large");
239
+ return;
240
+ }
241
+ const blob = encoded.blob;
242
+ const base = fileName ?? (typeof src !== "string" && "name" in src ? String(src.name).replace(/\.[^.]+$/, "") : "image");
243
+ await onCrop(new File([blob], `${base}.${extensionOf(outputType)}`, { type: outputType }), { width: size.width, height: size.height, type: outputType });
244
+ }
245
+ catch {
246
+ // No canvas, a tainted canvas (a cross-origin image), a canvas too large for the device, or the app's
247
+ // own save failing: say so and keep the crop, so it can be tried again.
248
+ setSaveError(true);
249
+ }
250
+ finally {
251
+ setSaving(false);
252
+ }
253
+ };
254
+ const showBackground = fit === "contain" && !alpha;
255
+ const swatches = [...new Set([...SWATCHES, backgroundProp.toLowerCase()])].map((value) => ({
256
+ value,
257
+ name: value === "#ffffff" ? colorWhiteLabel(locale) : value === "#ebe9e6" ? colorLightGreyLabel(locale) : value === "#0e0c09" ? colorBlackLabel(locale) : value,
258
+ }));
259
+ const sizeText = `${size.width} × ${size.height} px`;
260
+ return (_jsxs("div", { "data-slot": "image-cropper", className: "flex min-w-0 flex-col gap-ds-150", children: [_jsxs("div", { ref: stageRef,
261
+ // Spatial: the photo and its frame never mirror; logical classes inside resolve as left and right.
262
+ dir: "ltr", "data-slot": "image-cropper-stage", className: "relative w-full touch-none overflow-hidden rounded-ds-large bg-ds-surface-sunken select-none",
263
+ // Whole pixels once measured: a fractional height would shift everything below it off the pixel grid.
264
+ style: stageWidth > 0 ? { height: stageHeight } : { aspectRatio: String(STAGE_ASPECT) }, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerUp, onPointerCancel: onPointerUp, children: [source.failed && (_jsx("p", { "data-slot": "image-cropper-error", role: "alert", className: "absolute inset-0 m-0 grid place-items-center p-ds-300 text-center text-body text-ds-text-subtle", children: cropLoadFailedLabel(locale) })), loaded && stageWidth > 0 && (_jsxs(_Fragment, { children: [_jsx("div", { "aria-hidden": true, "data-slot": "image-cropper-fill", className: "absolute", style: { left: frameLeft, top: frameTop, width: frameWidth, height: frameHeight, background: alpha ? CHECKER : background } }), _jsx("div", { "aria-hidden": true, "data-slot": "image-cropper-image", className: "absolute", style: { left: frameLeft - region.left * scale, top: frameTop - region.top * scale, width: turned.width * scale, height: turned.height * scale }, children: _jsx("img", { src: source.url, alt: "", draggable: false, className: "absolute start-1/2 top-1/2 max-w-none", style: { width: loaded.width * scale, height: loaded.height * scale, transform: `translate(-50%, -50%) rotate(${rotation}deg)` } }) })] })), _jsxs("div", { role: "group", "aria-label": label, "aria-describedby": helpId, tabIndex: loaded ? 0 : -1, "data-slot": "image-cropper-frame", onKeyDown: onKeyDown, className: "absolute border border-[#fcfcfb] outline-hidden focus-visible:inset-ring-2 focus-visible:inset-ring-ds-border-focused",
265
+ // The blanket dims everything outside the frame.
266
+ style: { left: frameLeft, top: frameTop, width: frameWidth, height: frameHeight, boxShadow: "0 0 0 9999px var(--ds-blanket)" }, children: [_jsx("span", { "aria-hidden": true, className: "absolute inset-y-0 start-1/3 w-px bg-[#fcfcfb]/40" }), _jsx("span", { "aria-hidden": true, className: "absolute inset-y-0 start-2/3 w-px bg-[#fcfcfb]/40" }), _jsx("span", { "aria-hidden": true, className: "absolute inset-x-0 top-1/3 h-px bg-[#fcfcfb]/40" }), _jsx("span", { "aria-hidden": true, className: "absolute inset-x-0 top-2/3 h-px bg-[#fcfcfb]/40" }), ["-start-1.5 -top-1.5", "-end-1.5 -top-1.5", "-start-1.5 -bottom-1.5", "-end-1.5 -bottom-1.5"].map((corner) => (_jsx("span", { "aria-hidden": true, "data-slot": "image-cropper-handle", className: cn("absolute size-3 rounded-[2px] bg-[#fcfcfb] shadow-ds-raised", corner) }, corner)))] }), _jsx("span", { id: helpId, className: "sr-only", children: cropHelpLabel(locale) }), _jsx("span", { role: "status", "data-slot": "image-cropper-status", className: "sr-only", children: status })] }), _jsxs("div", { "data-slot": "image-cropper-toolbar", className: "flex flex-wrap items-center gap-ds-150", children: [presets && (_jsx(SegmentedControl, { label: cropAspectLabel(locale), items: presets.map((item) => ({ id: item.id, label: item.label })), value: preset?.id, onChange: (id) => {
267
+ const next = presets.find((item) => item.id === id);
268
+ setPresetId(String(id));
269
+ if (next?.fit)
270
+ setFit(next.fit);
271
+ setCenter(null);
272
+ setZoom(1);
273
+ } })), _jsxs("div", { "data-slot": "image-cropper-zoom", className: "flex min-w-48 flex-1 items-center gap-ds-100", children: [_jsx(Button, { size: "small", variant: "subtle", iconOnly: true, iconBefore: "minus", "aria-label": cropZoomOutLabel(locale), isDisabled: !loaded || zoom <= MIN_ZOOM, onPress: () => zoomBy(-ZOOM_STEP) }), _jsx(AriaSlider, { "aria-label": cropZoomLabel(locale), minValue: MIN_ZOOM, maxValue: MAX_ZOOM,
274
+ // Fine enough that a wheel or keyboard zoom is always a value the slider can show.
275
+ step: 0.01, value: zoom, onChange: (value) => apply({ zoom: value }, false), onChangeEnd: () => setStatus(describe(live.current.zoom, live.current.x, live.current.y, turnedFor(live.current.rotation))), isDisabled: !loaded, formatOptions: { style: "percent" }, "data-slot": "image-cropper-zoom-slider", className: "min-w-24 flex-1", children: _jsx(SliderTrack, { className: SLIDER_TRACK, children: ({ state }) => (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, className: SLIDER_RAIL }), _jsx("span", { "aria-hidden": true, className: SLIDER_FILL, style: { insetInlineStart: 0, insetInlineEnd: `${100 - state.getThumbPercent(0) * 100}%` } }), _jsx(SliderThumb, { className: SLIDER_THUMB })] })) }) }), _jsx(Button, { size: "small", variant: "subtle", iconOnly: true, iconBefore: "plus", "aria-label": cropZoomInLabel(locale), isDisabled: !loaded || zoom >= MAX_ZOOM, onPress: () => zoomBy(ZOOM_STEP) }), _jsx("span", { "data-slot": "image-cropper-zoom-value", className: "w-12 text-body-small tabular-nums text-ds-text-subtle", children: percent.format(zoom) })] }), _jsx("span", { "aria-hidden": true, className: "h-5 w-px bg-ds-border" }), _jsx(Button, { size: "small", variant: "subtle", iconOnly: true, iconBefore: "rotate-ccw", "aria-label": cropRotateLeftLabel(locale), isDisabled: !loaded, onPress: () => rotate(-90) }), _jsx(Button, { size: "small", variant: "subtle", iconOnly: true, iconBefore: "rotate-cw", "aria-label": cropRotateRightLabel(locale), isDisabled: !loaded, onPress: () => rotate(90) }), presets && (_jsx(SegmentedControl, { label: cropFitLabel(locale), items: [
276
+ { id: "cover", label: cropCoverLabel(locale) },
277
+ { id: "contain", label: cropContainLabel(locale) },
278
+ ], value: fit, onChange: (value) => {
279
+ setFit(value);
280
+ setCenter(null);
281
+ setZoom(1);
282
+ } }))] }), showBackground && (_jsx(ColorSwatchPicker, { label: cropBackgroundLabel(locale), items: swatches, value: background.toLowerCase(), onChange: setBackground })), _jsxs("div", { "data-slot": "image-cropper-meta", className: "flex flex-col gap-ds-050 text-body-small tabular-nums", children: [loaded && (_jsxs("span", { className: "text-ds-text-subtlest", children: [cropOutputLabel(locale, sizeText, TYPE_NAMES[outputType]), alpha && fit === "contain" ? ` (${cropKeepsAlphaLabel(locale)})` : ""] })), loaded && sourceTooSmall && (_jsxs("span", { "data-slot": "image-cropper-warning", className: "flex items-center gap-ds-050 text-ds-text-warning", children: [_jsx(IconGlyph, { name: "triangle-alert", size: "small" }), cropSmallLabel(locale, String(turned.width), sizeText)] }))] }), saveError && (_jsxs("p", { role: "alert", "data-slot": "image-cropper-save-error", "data-reason": saveError === "too-large" ? "too-large" : undefined, className: "m-0 flex items-center gap-ds-050 text-body-small text-ds-text-danger", children: [_jsx(IconGlyph, { name: "circle-alert", size: "small" }), saveError === "too-large" && maxBytes ? cropTooLargeLabel(locale, formatFileSize(maxBytes, intlLocale(locale))) : cropSaveFailedLabel(locale)] })), _jsxs("div", { "data-slot": "image-cropper-actions", className: "flex flex-wrap justify-end gap-ds-100", children: [onCancel && _jsx(Button, { onPress: onCancel, children: cancelLabel(locale) }), _jsx(Button, { variant: "primary", isPending: saving, isDisabled: !loaded, onPress: () => void save(), children: cropSaveLabel(locale) })] })] }));
283
+ }
284
+ //# sourceMappingURL=image-cropper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-cropper.js","sourceRoot":"","sources":["../../src/display/image-cropper.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElG,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,gBAA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EAC/C,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,IAClD,CACR,IACG,EAEL,SAAS,IAAI,CACZ,aACE,IAAI,EAAC,OAAO,eACF,0BAA0B,iBACvB,SAAS,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EAChE,SAAS,EAAC,sEAAsE,aAEhF,KAAC,SAAS,IAAC,IAAI,EAAC,cAAc,EAAC,IAAI,EAAC,OAAO,GAAG,EAC7C,SAAS,KAAK,WAAW,IAAI,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,EAAE,cAAc,CAAC,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAC5I,CACL,EAED,4BAAe,uBAAuB,EAAC,SAAS,EAAC,uCAAuC,aACrF,QAAQ,IAAI,KAAC,MAAM,IAAC,OAAO,EAAE,QAAQ,YAAG,WAAW,CAAC,MAAM,CAAC,GAAU,EACtE,KAAC,MAAM,IAAC,OAAO,EAAC,SAAS,EAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,IAAI,EAAE,YACzF,aAAa,CAAC,MAAM,CAAC,GACf,IACL,IACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Slider as AriaSlider, SliderThumb, SliderTrack, useLocale } from \"react-aria-components\";\n\nimport { cn } from \"../utils\";\nimport { Button } from \"../action/button\";\nimport { formatFileSize } from \"../action/files\";\nimport { ColorSwatchPicker } from \"../color/color\";\nimport {\n cancelLabel,\n colorBlackLabel,\n colorLightGreyLabel,\n colorWhiteLabel,\n cropAspectLabel,\n cropBackgroundLabel,\n cropCenteredLabel,\n cropContainLabel,\n cropCoverLabel,\n cropFitLabel,\n cropHelpLabel,\n cropKeepsAlphaLabel,\n cropLoadFailedLabel,\n cropOutputLabel,\n cropPositionLabel,\n cropRotateLeftLabel,\n cropRotateRightLabel,\n cropSaveFailedLabel,\n cropSaveLabel,\n cropSmallLabel,\n cropStatusLabel,\n cropTooLargeLabel,\n cropZoomInLabel,\n cropZoomLabel,\n cropZoomOutLabel,\n intlLocale,\n} from \"../i18n\";\nimport { SegmentedControl } from \"../navigation/tabs\";\nimport { SLIDER_FILL, SLIDER_RAIL, SLIDER_THUMB, SLIDER_TRACK } from \"../selection/styles\";\nimport { IconGlyph } from \"./icon\";\nimport {\n MAX_ZOOM,\n MIN_ZOOM,\n clampZoom,\n cropRegion,\n drawCrop,\n encodeWithin,\n extensionOf,\n hasAlpha,\n outputSize,\n rotatedSize,\n type CropFit,\n type CropOutputType,\n type CropRotation,\n} from \"./image-crop\";\n\nexport type ImageCropperAspect = number | \"free\";\n\nexport type ImageCropperPreset = {\n id: string;\n /** \"Cover 16:9\". */\n label: string;\n aspectRatio: ImageCropperAspect;\n /** The fit this surface uses; the cropper's `fit` otherwise. */\n fit?: CropFit;\n};\n\nexport type ImageCropperResult = { width: number; height: number; type: CropOutputType };\n\nexport type ImageCropperProps = {\n /**\n * The picked file (from FileTrigger, already checked for size and type), or an image URL. A URL from\n * another origin is loaded with CORS so the crop can be read back: its server must send\n * `Access-Control-Allow-Origin`, or the image does not open (rather than failing later at save).\n */\n src: Blob | string;\n /** What is being cropped (\"Cover photo\"); names the crop frame. */\n label: string;\n /** 16:9 by default; `\"free\"` keeps the image's own shape. Ignored when presets are given. */\n aspectRatio?: ImageCropperAspect;\n /** Two or more shapes to choose from (a segmented control); the first is selected. */\n aspectPresets?: readonly ImageCropperPreset[];\n /** `cover` (default) fills the frame; `contain` fits the whole image and leaves empty area. */\n fit?: CropFit;\n /** The empty area's colour in `contain` when the output has no alpha (JPEG). White by default. */\n background?: string;\n /** `image/jpeg` by default. PNG and WebP keep transparency. */\n outputType?: CropOutputType;\n /** 0–1, for JPEG and WebP. 0.9 by default. */\n quality?: number;\n /**\n * The largest file the surface takes, in bytes. A JPEG or WebP\n * over it is encoded again at a quality 0.1 lower each time, down to `minimumQuality`; when even that is over, or\n * a PNG is, nothing is handed to `onCrop` and the cropper says the image is over the limit (a smaller crop, by\n * zooming in, or another image fits).\n */\n maxBytes?: number;\n /** The lowest quality `maxBytes` may step down to (0.9 keeps a hero or slide sharp). 0.1 by default; at most `quality`. */\n minimumQuality?: number;\n /**\n * The output's long edge in px at most (a surface's size, 2560 for a full-width photo): larger crops scale down,\n * never up. 4096 by default, so a 48 MP phone photo stays within every browser's canvas limit.\n */\n maxOutputSize?: number;\n /** Under this long edge the warning shows; it never blocks. */\n minOutputSize?: number;\n /** The output file's name without extension; the source file's name by default. */\n fileName?: string;\n onCrop: (file: File, result: ImageCropperResult) => unknown;\n onCancel?: () => void;\n};\n\nconst STAGE_ASPECT = 16 / 10;\nconst FRAME_INSET = 0.06;\nconst ZOOM_STEP = 0.1;\n/** Fixed paper and light grey: the frame and checkerboard draw on the photo, not on a theme surface. */\nconst CHECKER = \"repeating-conic-gradient(#ebe9e6 0 25%, #fcfcfb 0 50%) 0 0 / 16px 16px\";\nconst SWATCHES = [\"#ffffff\", \"#ebe9e6\", \"#0e0c09\"] as const;\nconst TYPE_NAMES: Record<CropOutputType, string> = { \"image/jpeg\": \"JPEG\", \"image/png\": \"PNG\", \"image/webp\": \"WebP\" };\n\ntype Loaded = { image: HTMLImageElement; width: number; height: number };\n\n/** The image behind `src`, decoded; an object URL for a file, revoked when it changes. */\nfunction useSourceImage(src: Blob | string) {\n const [state, setState] = React.useState<{ url?: string; loaded?: Loaded; failed?: boolean }>({});\n React.useEffect(() => {\n const url = typeof src === \"string\" ? src : URL.createObjectURL(src);\n let live = true;\n setState({ url });\n const image = new Image();\n image.decoding = \"async\";\n // A URL from a CDN must not taint the canvas, or the crop could never be read back.\n if (typeof src === \"string\" && !/^(data|blob):/.test(src)) image.crossOrigin = \"anonymous\";\n image.onload = () => live && setState({ url, loaded: { image, width: image.naturalWidth, height: image.naturalHeight } });\n image.onerror = () => live && setState({ url, failed: true });\n image.src = url;\n return () => {\n live = false;\n if (typeof src !== \"string\") URL.revokeObjectURL(url);\n };\n }, [src]);\n return state;\n}\n\n/** The element's width in whole px, following resizes. */\nfunction useWidth() {\n const [element, setElement] = React.useState<HTMLElement | null>(null);\n const [width, setWidth] = React.useState(0);\n React.useLayoutEffect(() => {\n if (!element) return;\n setWidth(Math.floor(element.getBoundingClientRect().width));\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(([entry]) => setWidth(Math.floor(entry!.contentRect.width)));\n observer.observe(element);\n return () => observer.disconnect();\n }, [element]);\n return [setElement, width, element] as const;\n}\n\n/**\n * Frames one picked image to the shape a surface needs (a 16:9 cover photo, a square logo) and hands\n * back the cropped file at the source's own pixel density: never upscaled, only scaled down to\n * `maxOutputSize`. In `contain`, the empty area takes `background` when the output has no\n * alpha, white by default, never black. A sunken stage dims what falls outside a white frame\n * with thirds guides; the toolbar holds the shapes, zoom, rotation and fit. The frame is one focusable\n * group: arrows move the image (Shift for 10%), + and − zoom, [ and ] rotate, and each change is announced.\n * The toolbar mirrors in RTL; the image and the arrows never do.\n */\nexport function ImageCropper({\n src,\n label,\n aspectRatio = 16 / 9,\n aspectPresets,\n fit: fitProp = \"cover\",\n background: backgroundProp = \"#ffffff\",\n outputType = \"image/jpeg\",\n quality = 0.9,\n maxBytes,\n minimumQuality,\n maxOutputSize = 4096,\n minOutputSize,\n fileName,\n onCrop,\n onCancel,\n}: ImageCropperProps) {\n const { locale } = useLocale();\n const source = useSourceImage(src);\n const presets = aspectPresets && aspectPresets.length > 1 ? aspectPresets : undefined;\n const [presetId, setPresetId] = React.useState(presets?.[0]?.id);\n const preset = presets?.find((item) => item.id === presetId) ?? presets?.[0];\n const [fit, setFit] = React.useState<CropFit>(preset?.fit ?? fitProp);\n const [background, setBackground] = React.useState(backgroundProp);\n // Props changed later win again: a new fit or background from the surface.\n React.useEffect(() => setFit(preset?.fit ?? fitProp), [fitProp]); // preset changes set fit themselves\n React.useEffect(() => setBackground(backgroundProp), [backgroundProp]);\n // `true` a failed save; \"too-large\" a crop over `maxBytes` at the lowest quality allowed.\n const [saveError, setSaveError] = React.useState<boolean | \"too-large\">(false);\n const [rotation, setRotation] = React.useState<CropRotation>(0);\n const [zoom, setZoom] = React.useState(1);\n const [center, setCenter] = React.useState<{ x: number; y: number } | null>(null);\n const [status, setStatus] = React.useState(\"\");\n const [saving, setSaving] = React.useState(false);\n const [stageRef, stageWidth, stageElement] = useWidth();\n const helpId = React.useId();\n\n const loaded = source.loaded;\n // A new picture starts afresh: upright, whole, centred.\n React.useEffect(() => {\n setRotation(0);\n setZoom(1);\n setCenter(null);\n setStatus(\"\");\n setSaveError(false);\n }, [source.url]);\n const turned = loaded ? rotatedSize(loaded.width, loaded.height, rotation) : { width: 1, height: 1 };\n const shape = preset ? preset.aspectRatio : aspectRatio;\n const aspect = shape === \"free\" ? turned.width / turned.height : shape;\n const centerX = center?.x ?? turned.width / 2;\n const centerY = center?.y ?? turned.height / 2;\n const region = cropRegion(turned, aspect, fit, { zoom, centerX, centerY });\n const size = outputSize(region, { maxOutputSize, minOutputSize });\n // The warning is about the source, not the zoom: shown when even the whole fit is under the surface's size.\n const sourceTooSmall = outputSize(cropRegion(turned, aspect, fit, { zoom: 1, centerX, centerY }), { maxOutputSize, minOutputSize }).small;\n const alpha = hasAlpha(outputType);\n\n // The frame inside the stage: the largest rectangle of the crop's shape, inset from the edges.\n const stageHeight = Math.round(stageWidth / STAGE_ASPECT);\n const roomWidth = stageWidth * (1 - 2 * FRAME_INSET);\n const roomHeight = stageHeight * (1 - 2 * FRAME_INSET);\n const frameWidth = Math.min(roomWidth, roomHeight * aspect);\n const frameHeight = frameWidth / aspect;\n const frameLeft = (stageWidth - frameWidth) / 2;\n const frameTop = (stageHeight - frameHeight) / 2;\n const scale = region.width > 0 ? frameWidth / region.width : 0;\n\n const percent = React.useMemo(() => new Intl.NumberFormat(intlLocale(locale), { style: \"percent\", maximumFractionDigits: 0 }), [locale]);\n const describe = (nextZoom: number, x: number, y: number, dims: { width: number; height: number } = turned) => {\n const across = x / dims.width;\n const down = y / dims.height;\n const position = Math.abs(across - 0.5) < 0.005 && Math.abs(down - 0.5) < 0.005 ? cropCenteredLabel(locale) : cropPositionLabel(locale, percent.format(across), percent.format(down));\n return cropStatusLabel(locale, percent.format(nextZoom), position);\n };\n\n // The latest position, ahead of React's render: several keys or wheel ticks in one task each build on the\n // one before instead of the same rendered state.\n const live = React.useRef({ zoom, x: centerX, y: centerY, rotation });\n live.current = { zoom, x: centerX, y: centerY, rotation };\n const turnedFor = (turn: CropRotation) => (loaded ? rotatedSize(loaded.width, loaded.height, turn) : turned);\n\n // Every change keeps the centre where the region can be, then says where things are.\n const apply = (next: { zoom?: number; x?: number; y?: number; rotation?: CropRotation }, announce = true) => {\n const base = live.current;\n const nextRotation = next.rotation ?? base.rotation;\n const nextTurned = turnedFor(nextRotation);\n const nextAspect = shape === \"free\" ? nextTurned.width / nextTurned.height : shape;\n const nextZoom = clampZoom(next.zoom ?? base.zoom);\n const settled = cropRegion(nextTurned, nextAspect, fit, { zoom: nextZoom, centerX: next.x ?? base.x, centerY: next.y ?? base.y });\n const x = settled.left + settled.width / 2;\n const y = settled.top + settled.height / 2;\n live.current = { zoom: nextZoom, x, y, rotation: nextRotation };\n setZoom(nextZoom);\n setCenter({ x, y });\n if (next.rotation !== undefined) setRotation(nextRotation);\n if (announce) setStatus(describe(nextZoom, x, y, nextTurned));\n };\n const zoomBy = (delta: number, announce = true) => apply({ zoom: live.current.zoom + delta }, announce);\n const nudge = (dx: number, dy: number) => {\n const size = turnedFor(live.current.rotation);\n apply({ x: live.current.x - dx * size.width, y: live.current.y - dy * size.height });\n };\n const rotate = (turn: 90 | -90) => {\n const next = ((((live.current.rotation + turn) % 360) + 360) % 360) as CropRotation;\n // The new shape starts centred.\n const nextTurned = turnedFor(next);\n apply({ rotation: next, x: nextTurned.width / 2, y: nextTurned.height / 2 });\n };\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n // Browser zoom (Ctrl/Cmd with + and −) and other shortcuts stay the browser's.\n if (event.ctrlKey || event.metaKey || event.altKey) return;\n const step = event.shiftKey ? 0.1 : 0.01;\n // Spatial, so never mirrored in RTL: the image moves the way the arrow points.\n const moves: Record<string, [number, number]> = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, -step], ArrowDown: [0, step] };\n if (moves[event.key]) nudge(...moves[event.key]!);\n else if (event.key === \"+\" || event.key === \"=\") zoomBy(ZOOM_STEP);\n else if (event.key === \"-\" || event.key === \"_\") zoomBy(-ZOOM_STEP);\n else if (event.key === \"[\") rotate(-90);\n else if (event.key === \"]\") rotate(90);\n else return;\n event.preventDefault();\n };\n\n // Pointer: drag moves, the wheel zooms.\n const drag = React.useRef<{ x: number; y: number; centerX: number; centerY: number } | null>(null);\n const onPointerDown = (event: React.PointerEvent) => {\n if (!loaded || event.button !== 0) return;\n (event.currentTarget as HTMLElement).setPointerCapture?.(event.pointerId);\n drag.current = { x: event.clientX, y: event.clientY, centerX, centerY };\n };\n const onPointerMove = (event: React.PointerEvent) => {\n if (!drag.current || scale <= 0) return;\n apply({ x: drag.current.centerX - (event.clientX - drag.current.x) / scale, y: drag.current.centerY - (event.clientY - drag.current.y) / scale }, false);\n };\n const onPointerUp = () => {\n if (drag.current) setStatus(describe(live.current.zoom, live.current.x, live.current.y, turnedFor(live.current.rotation)));\n drag.current = null;\n };\n\n // The wheel zooms in proportion to how far it turns (a trackpad sends many small steps) and never scrolls\n // the page underneath: React's wheel listener is passive, so this one is native.\n const wheelRef = React.useRef<(event: WheelEvent) => void>(() => {});\n wheelRef.current = (event: WheelEvent) => {\n if (!loaded || event.deltaY === 0) return;\n const pixels = event.deltaMode === 1 ? event.deltaY * 16 : event.deltaMode === 2 ? event.deltaY * 400 : event.deltaY;\n const zoomingIn = pixels < 0;\n // At a limit in the wheel's direction the page scrolls on, as it does over any other part of it.\n if ((zoomingIn && live.current.zoom >= MAX_ZOOM) || (!zoomingIn && live.current.zoom <= MIN_ZOOM)) return;\n event.preventDefault();\n zoomBy(Math.max(-0.5, Math.min(0.5, -pixels / 500)), false);\n };\n React.useEffect(() => {\n if (!stageElement) return;\n const onWheel = (event: WheelEvent) => wheelRef.current(event);\n stageElement.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => stageElement.removeEventListener(\"wheel\", onWheel);\n }, [stageElement]);\n\n const save = async () => {\n if (!loaded) return;\n setSaving(true);\n setSaveError(false);\n try {\n const canvas = document.createElement(\"canvas\");\n canvas.width = size.width;\n canvas.height = size.height;\n const context = canvas.getContext(\"2d\");\n if (!context) throw new Error(\"canvas-unavailable\");\n drawCrop(context, loaded.image, loaded, region, size, { rotation, outputType, background });\n const encoded = await encodeWithin((step) => new Promise<Blob | null>((resolve) => canvas.toBlob(resolve, outputType, step)), {\n outputType,\n quality,\n minimumQuality,\n maxBytes,\n });\n if (!encoded.fits) {\n setSaveError(\"too-large\");\n return;\n }\n const blob = encoded.blob;\n const base = fileName ?? (typeof src !== \"string\" && \"name\" in src ? String((src as File).name).replace(/\\.[^.]+$/, \"\") : \"image\");\n await onCrop(new File([blob], `${base}.${extensionOf(outputType)}`, { type: outputType }), { width: size.width, height: size.height, type: outputType });\n } catch {\n // No canvas, a tainted canvas (a cross-origin image), a canvas too large for the device, or the app's\n // own save failing: say so and keep the crop, so it can be tried again.\n setSaveError(true);\n } finally {\n setSaving(false);\n }\n };\n\n const showBackground = fit === \"contain\" && !alpha;\n const swatches = [...new Set<string>([...SWATCHES, backgroundProp.toLowerCase()])].map((value) => ({\n value,\n name: value === \"#ffffff\" ? colorWhiteLabel(locale) : value === \"#ebe9e6\" ? colorLightGreyLabel(locale) : value === \"#0e0c09\" ? colorBlackLabel(locale) : value,\n }));\n const sizeText = `${size.width} × ${size.height} px`;\n\n return (\n <div data-slot=\"image-cropper\" className=\"flex min-w-0 flex-col gap-ds-150\">\n <div\n ref={stageRef}\n // Spatial: the photo and its frame never mirror; logical classes inside resolve as left and right.\n dir=\"ltr\"\n data-slot=\"image-cropper-stage\"\n className=\"relative w-full touch-none overflow-hidden rounded-ds-large bg-ds-surface-sunken select-none\"\n // Whole pixels once measured: a fractional height would shift everything below it off the pixel grid.\n style={stageWidth > 0 ? { height: stageHeight } : { aspectRatio: String(STAGE_ASPECT) }}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n >\n {source.failed && (\n <p data-slot=\"image-cropper-error\" role=\"alert\" className=\"absolute inset-0 m-0 grid place-items-center p-ds-300 text-center text-body text-ds-text-subtle\">\n {cropLoadFailedLabel(locale)}\n </p>\n )}\n {loaded && stageWidth > 0 && (\n <>\n {/* What the empty area of the output will be: kept transparent (checkerboard) or the background. */}\n <div\n aria-hidden\n data-slot=\"image-cropper-fill\"\n className=\"absolute\"\n style={{ left: frameLeft, top: frameTop, width: frameWidth, height: frameHeight, background: alpha ? CHECKER : background }}\n />\n <div\n aria-hidden\n data-slot=\"image-cropper-image\"\n className=\"absolute\"\n style={{ left: frameLeft - region.left * scale, top: frameTop - region.top * scale, width: turned.width * scale, height: turned.height * scale }}\n >\n <img\n src={source.url}\n alt=\"\"\n draggable={false}\n className=\"absolute start-1/2 top-1/2 max-w-none\"\n style={{ width: loaded.width * scale, height: loaded.height * scale, transform: `translate(-50%, -50%) rotate(${rotation}deg)` }}\n />\n </div>\n </>\n )}\n <div\n role=\"group\"\n aria-label={label}\n aria-describedby={helpId}\n tabIndex={loaded ? 0 : -1}\n data-slot=\"image-cropper-frame\"\n onKeyDown={onKeyDown}\n className=\"absolute border border-[#fcfcfb] outline-hidden focus-visible:inset-ring-2 focus-visible:inset-ring-ds-border-focused\"\n // The blanket dims everything outside the frame.\n style={{ left: frameLeft, top: frameTop, width: frameWidth, height: frameHeight, boxShadow: \"0 0 0 9999px var(--ds-blanket)\" }}\n >\n {/* Rule-of-thirds guides, paper at 40%. */}\n <span aria-hidden className=\"absolute inset-y-0 start-1/3 w-px bg-[#fcfcfb]/40\" />\n <span aria-hidden className=\"absolute inset-y-0 start-2/3 w-px bg-[#fcfcfb]/40\" />\n <span aria-hidden className=\"absolute inset-x-0 top-1/3 h-px bg-[#fcfcfb]/40\" />\n <span aria-hidden className=\"absolute inset-x-0 top-2/3 h-px bg-[#fcfcfb]/40\" />\n {([\"-start-1.5 -top-1.5\", \"-end-1.5 -top-1.5\", \"-start-1.5 -bottom-1.5\", \"-end-1.5 -bottom-1.5\"] as const).map((corner) => (\n <span key={corner} aria-hidden data-slot=\"image-cropper-handle\" className={cn(\"absolute size-3 rounded-[2px] bg-[#fcfcfb] shadow-ds-raised\", corner)} />\n ))}\n </div>\n <span id={helpId} className=\"sr-only\">\n {cropHelpLabel(locale)}\n </span>\n <span role=\"status\" data-slot=\"image-cropper-status\" className=\"sr-only\">\n {status}\n </span>\n </div>\n\n <div data-slot=\"image-cropper-toolbar\" className=\"flex flex-wrap items-center gap-ds-150\">\n {presets && (\n <SegmentedControl\n label={cropAspectLabel(locale)}\n items={presets.map((item) => ({ id: item.id, label: item.label }))}\n value={preset?.id}\n onChange={(id) => {\n const next = presets.find((item) => item.id === id);\n setPresetId(String(id));\n if (next?.fit) setFit(next.fit);\n setCenter(null);\n setZoom(1);\n }}\n />\n )}\n <div data-slot=\"image-cropper-zoom\" className=\"flex min-w-48 flex-1 items-center gap-ds-100\">\n <Button size=\"small\" variant=\"subtle\" iconOnly iconBefore=\"minus\" aria-label={cropZoomOutLabel(locale)} isDisabled={!loaded || zoom <= MIN_ZOOM} onPress={() => zoomBy(-ZOOM_STEP)} />\n <AriaSlider\n aria-label={cropZoomLabel(locale)}\n minValue={MIN_ZOOM}\n maxValue={MAX_ZOOM}\n // Fine enough that a wheel or keyboard zoom is always a value the slider can show.\n step={0.01}\n value={zoom}\n onChange={(value) => apply({ zoom: value as number }, false)}\n onChangeEnd={() => setStatus(describe(live.current.zoom, live.current.x, live.current.y, turnedFor(live.current.rotation)))}\n isDisabled={!loaded}\n formatOptions={{ style: \"percent\" }}\n data-slot=\"image-cropper-zoom-slider\"\n className=\"min-w-24 flex-1\"\n >\n <SliderTrack className={SLIDER_TRACK}>\n {({ state }) => (\n <>\n <span aria-hidden className={SLIDER_RAIL} />\n <span aria-hidden className={SLIDER_FILL} style={{ insetInlineStart: 0, insetInlineEnd: `${100 - state.getThumbPercent(0) * 100}%` }} />\n <SliderThumb className={SLIDER_THUMB} />\n </>\n )}\n </SliderTrack>\n </AriaSlider>\n <Button size=\"small\" variant=\"subtle\" iconOnly iconBefore=\"plus\" aria-label={cropZoomInLabel(locale)} isDisabled={!loaded || zoom >= MAX_ZOOM} onPress={() => zoomBy(ZOOM_STEP)} />\n <span data-slot=\"image-cropper-zoom-value\" className=\"w-12 text-body-small tabular-nums text-ds-text-subtle\">\n {percent.format(zoom)}\n </span>\n </div>\n <span aria-hidden className=\"h-5 w-px bg-ds-border\" />\n <Button size=\"small\" variant=\"subtle\" iconOnly iconBefore=\"rotate-ccw\" aria-label={cropRotateLeftLabel(locale)} isDisabled={!loaded} onPress={() => rotate(-90)} />\n <Button size=\"small\" variant=\"subtle\" iconOnly iconBefore=\"rotate-cw\" aria-label={cropRotateRightLabel(locale)} isDisabled={!loaded} onPress={() => rotate(90)} />\n {presets && (\n <SegmentedControl\n label={cropFitLabel(locale)}\n items={[\n { id: \"cover\", label: cropCoverLabel(locale) },\n { id: \"contain\", label: cropContainLabel(locale) },\n ]}\n value={fit}\n onChange={(value) => {\n setFit(value as CropFit);\n setCenter(null);\n setZoom(1);\n }}\n />\n )}\n </div>\n\n {showBackground && (\n <ColorSwatchPicker label={cropBackgroundLabel(locale)} items={swatches} value={background.toLowerCase()} onChange={setBackground} />\n )}\n\n <div data-slot=\"image-cropper-meta\" className=\"flex flex-col gap-ds-050 text-body-small tabular-nums\">\n {loaded && (\n <span className=\"text-ds-text-subtlest\">\n {cropOutputLabel(locale, sizeText, TYPE_NAMES[outputType])}\n {alpha && fit === \"contain\" ? ` (${cropKeepsAlphaLabel(locale)})` : \"\"}\n </span>\n )}\n {loaded && sourceTooSmall && (\n <span data-slot=\"image-cropper-warning\" className=\"flex items-center gap-ds-050 text-ds-text-warning\">\n <IconGlyph name=\"triangle-alert\" size=\"small\" />\n {cropSmallLabel(locale, String(turned.width), sizeText)}\n </span>\n )}\n </div>\n\n {saveError && (\n <p\n role=\"alert\"\n data-slot=\"image-cropper-save-error\"\n data-reason={saveError === \"too-large\" ? \"too-large\" : undefined}\n className=\"m-0 flex items-center gap-ds-050 text-body-small text-ds-text-danger\"\n >\n <IconGlyph name=\"circle-alert\" size=\"small\" />\n {saveError === \"too-large\" && maxBytes ? cropTooLargeLabel(locale, formatFileSize(maxBytes, intlLocale(locale))) : cropSaveFailedLabel(locale)}\n </p>\n )}\n\n <div data-slot=\"image-cropper-actions\" className=\"flex flex-wrap justify-end gap-ds-100\">\n {onCancel && <Button onPress={onCancel}>{cancelLabel(locale)}</Button>}\n <Button variant=\"primary\" isPending={saving} isDisabled={!loaded} onPress={() => void save()}>\n {cropSaveLabel(locale)}\n </Button>\n </div>\n </div>\n );\n}\n"]}