@onesy/ui-react 1.0.129 → 1.0.131

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 (445) hide show
  1. package/Accordion/Accordion.js +342 -242
  2. package/Accordion/index.js +12 -7
  3. package/AdvancedTextField/AdvancedTextField.js +165 -157
  4. package/AdvancedTextField/index.js +12 -7
  5. package/Append/Append.js +502 -519
  6. package/Append/index.js +12 -7
  7. package/AreaChart/AreaChart.js +53 -40
  8. package/AreaChart/index.js +12 -7
  9. package/AreaChartItem/AreaChartItem.js +325 -237
  10. package/AreaChartItem/index.js +12 -7
  11. package/AudioPlayer/AudioPlayer.js +683 -466
  12. package/AudioPlayer/index.js +12 -7
  13. package/AudioRecorder/AudioRecorder.js +359 -259
  14. package/AudioRecorder/index.js +12 -7
  15. package/AutoComplete/AutoComplete.js +693 -568
  16. package/AutoComplete/index.js +12 -7
  17. package/AutoCompleteCountry/AutoCompleteCountry.js +99 -62
  18. package/AutoCompleteCountry/index.js +12 -7
  19. package/AutoCompleteCurrency/AutoCompleteCurrency.js +73 -61
  20. package/AutoCompleteCurrency/index.js +12 -7
  21. package/Avatar/Avatar.js +113 -86
  22. package/Avatar/index.js +12 -7
  23. package/AvatarGroup/AvatarGroup.js +104 -87
  24. package/AvatarGroup/index.js +12 -7
  25. package/Backdrop/Backdrop.js +160 -139
  26. package/Backdrop/index.js +12 -7
  27. package/Badge/Badge.js +116 -96
  28. package/Badge/index.js +12 -7
  29. package/Banner/Banner.js +126 -85
  30. package/Banner/index.js +12 -7
  31. package/BottomAppBar/BottomAppBar.js +89 -60
  32. package/BottomAppBar/index.js +12 -7
  33. package/BottomSheet/BottomSheet.js +66 -59
  34. package/BottomSheet/index.js +12 -7
  35. package/Box/Box.js +43 -35
  36. package/Box/index.js +12 -7
  37. package/Breadcrumbs/Breadcrumbs.js +168 -144
  38. package/Breadcrumbs/index.js +12 -7
  39. package/BubbleChart/BubbleChart.js +261 -132
  40. package/BubbleChart/index.js +12 -7
  41. package/BubbleChartItem/BubbleChartItem.js +228 -161
  42. package/BubbleChartItem/index.js +12 -7
  43. package/Button/Button.js +488 -467
  44. package/Button/index.js +12 -7
  45. package/Buttons/Buttons.js +366 -293
  46. package/Buttons/index.js +12 -7
  47. package/Calendar/Calendar.js +715 -452
  48. package/Calendar/index.js +12 -7
  49. package/CalendarAvailability/CalendarAvailability.js +709 -388
  50. package/CalendarAvailability/index.js +12 -7
  51. package/CalendarMenu/CalendarMenu.js +430 -303
  52. package/CalendarMenu/index.js +12 -7
  53. package/CalendarMonth/CalendarMonth.js +537 -498
  54. package/CalendarMonth/index.js +12 -7
  55. package/CalendarViews/CalendarViews.js +403 -254
  56. package/CalendarViews/index.js +12 -7
  57. package/CalendarWeek/CalendarWeek.js +536 -395
  58. package/CalendarWeek/index.js +12 -7
  59. package/Card/Card.js +133 -101
  60. package/Card/index.js +12 -7
  61. package/CardButton/CardButton.js +78 -58
  62. package/CardButton/index.js +12 -7
  63. package/CardFooter/CardFooter.js +58 -39
  64. package/CardFooter/index.js +12 -7
  65. package/CardHeader/CardHeader.js +61 -44
  66. package/CardHeader/index.js +12 -7
  67. package/CardImage/CardImage.js +80 -67
  68. package/CardImage/index.js +12 -7
  69. package/CardMain/CardMain.js +53 -39
  70. package/CardMain/index.js +12 -7
  71. package/Carousel/Carousel.js +1025 -913
  72. package/Carousel/index.js +12 -7
  73. package/Chart/Chart.js +1325 -1174
  74. package/Chart/index.js +12 -7
  75. package/Checkbox/Checkbox.js +339 -325
  76. package/Checkbox/index.js +12 -7
  77. package/Chip/Chip.js +131 -102
  78. package/Chip/index.js +12 -7
  79. package/Chips/Chips.js +121 -94
  80. package/Chips/index.js +12 -7
  81. package/ClickListener/ClickListener.js +86 -89
  82. package/ClickListener/index.js +12 -7
  83. package/Clock/Clock.js +470 -417
  84. package/Clock/index.js +12 -7
  85. package/ColorTextField/ColorTextField.js +234 -171
  86. package/ColorTextField/index.js +12 -7
  87. package/ColumnChart/ColumnChart.js +63 -46
  88. package/ColumnChart/index.js +12 -7
  89. package/ColumnChartItem/ColumnChartItem.js +208 -149
  90. package/ColumnChartItem/index.js +12 -7
  91. package/Confirm/Confirm.js +184 -129
  92. package/Confirm/Context.js +9 -7
  93. package/Confirm/index.js +32 -13
  94. package/Confirm/useConfirm.js +11 -10
  95. package/Container/Container.js +154 -133
  96. package/Container/index.js +12 -7
  97. package/CookieBanner/CookieBanner.js +142 -76
  98. package/CookieBanner/index.js +12 -7
  99. package/Countdown/Countdown.js +403 -255
  100. package/Countdown/index.js +12 -7
  101. package/DatePicker/DatePicker.js +802 -547
  102. package/DatePicker/index.js +12 -7
  103. package/DateRangePicker/DateRangePicker.js +44 -37
  104. package/DateRangePicker/index.js +12 -7
  105. package/DateTimePicker/DateTimePicker.js +672 -459
  106. package/DateTimePicker/index.js +12 -7
  107. package/DateTimeRangePicker/DateTimeRangePicker.js +44 -37
  108. package/DateTimeRangePicker/index.js +12 -7
  109. package/Divider/Divider.js +198 -185
  110. package/Divider/index.js +12 -7
  111. package/DonutChart/DonutChart.js +49 -42
  112. package/DonutChart/index.js +12 -7
  113. package/DragAndDropList/DragAndDropList.js +160 -156
  114. package/DragAndDropList/index.js +12 -7
  115. package/Drawing/Drawing.js +850 -523
  116. package/Drawing/index.js +12 -7
  117. package/DropZone/DropZone.js +239 -201
  118. package/DropZone/index.js +12 -7
  119. package/Emojis/Emojis.js +409 -317
  120. package/Emojis/emojis_list.js +7279 -9250
  121. package/Emojis/index.js +19 -9
  122. package/Expand/Expand.js +201 -149
  123. package/Expand/index.js +12 -7
  124. package/Fab/Fab.js +46 -26
  125. package/Fab/index.js +12 -7
  126. package/Fade/Fade.js +131 -101
  127. package/Fade/index.js +12 -7
  128. package/FileChoose/FileChoose.js +218 -150
  129. package/FileChoose/index.js +12 -7
  130. package/Focus/Focus.js +87 -88
  131. package/Focus/index.js +12 -7
  132. package/Form/Form.js +194 -120
  133. package/Form/index.js +12 -7
  134. package/FormRow/FormRow.js +123 -78
  135. package/FormRow/index.js +12 -7
  136. package/Forms/Forms.js +55 -41
  137. package/Forms/index.js +12 -7
  138. package/Frame/Frame.js +212 -150
  139. package/Frame/index.js +12 -7
  140. package/Grid/Grid.js +231 -166
  141. package/Grid/index.js +12 -7
  142. package/Grow/Grow.js +137 -109
  143. package/Grow/index.js +12 -7
  144. package/HTMLCanvas/HTMLCanvas.js +752 -542
  145. package/HTMLCanvas/index.js +24 -21
  146. package/IFrame/IFrame.js +122 -104
  147. package/IFrame/index.js +12 -7
  148. package/Icon/Icon.js +112 -95
  149. package/Icon/index.js +24 -21
  150. package/IconButton/IconButton.js +49 -37
  151. package/IconButton/index.js +12 -7
  152. package/Image/Image.js +285 -252
  153. package/Image/index.js +12 -7
  154. package/ImageCrop/ImageCrop.js +1073 -1048
  155. package/ImageCrop/index.js +12 -7
  156. package/ImageEdit/ImageEdit.js +1088 -783
  157. package/ImageEdit/index.js +12 -7
  158. package/ImageGallery/ImageGallery.js +518 -473
  159. package/ImageGallery/index.js +12 -7
  160. package/ImageList/ImageList.js +136 -129
  161. package/ImageList/index.js +12 -7
  162. package/ImageListItem/ImageListItem.js +101 -87
  163. package/ImageListItem/index.js +12 -7
  164. package/ImageListItemBox/ImageListItemBox.js +61 -50
  165. package/ImageListItemBox/index.js +12 -7
  166. package/Info/Info.js +99 -63
  167. package/Info/index.js +12 -7
  168. package/Interaction/Interaction.js +405 -345
  169. package/Interaction/index.js +12 -7
  170. package/Keyframes/Context.js +9 -7
  171. package/Keyframes/Keyframes.js +189 -174
  172. package/Keyframes/index.js +42 -25
  173. package/Keyframes/useKeyframes.js +11 -10
  174. package/Label/Label.js +177 -151
  175. package/Label/index.js +12 -7
  176. package/Labels/Labels.js +126 -98
  177. package/Labels/index.js +12 -7
  178. package/Line/Line.js +296 -174
  179. package/Line/index.js +12 -7
  180. package/LineChart/LineChart.js +57 -40
  181. package/LineChart/index.js +12 -7
  182. package/LineChartItem/LineChartItem.js +239 -177
  183. package/LineChartItem/index.js +12 -7
  184. package/LinearMeter/LinearMeter.js +453 -377
  185. package/LinearMeter/index.js +12 -7
  186. package/LinearProgress/LinearProgress.js +324 -255
  187. package/LinearProgress/index.js +12 -7
  188. package/Link/Link.js +182 -127
  189. package/Link/index.js +12 -7
  190. package/Links/Links.js +277 -156
  191. package/Links/index.js +12 -7
  192. package/List/List.js +148 -113
  193. package/List/index.js +12 -7
  194. package/ListItem/ListItem.js +388 -362
  195. package/ListItem/index.js +12 -7
  196. package/ListSubheader/ListSubheader.js +52 -44
  197. package/ListSubheader/index.js +12 -7
  198. package/MainProgress/Context.js +9 -7
  199. package/MainProgress/MainProgress.js +193 -161
  200. package/MainProgress/index.js +32 -13
  201. package/MainProgress/useMainProgress.js +11 -10
  202. package/Markdown/Markdown.js +676 -704
  203. package/Markdown/index.js +12 -7
  204. package/Masonry/Masonry.js +207 -181
  205. package/Masonry/index.js +12 -7
  206. package/Medias/Medias.js +436 -398
  207. package/Medias/index.js +12 -7
  208. package/Menu/Menu.js +278 -243
  209. package/Menu/index.js +12 -7
  210. package/MenuDesktop/MenuDesktop.js +496 -419
  211. package/MenuDesktop/index.js +12 -7
  212. package/MenuItem/MenuItem.js +286 -231
  213. package/MenuItem/index.js +12 -7
  214. package/Meta/Meta.js +78 -54
  215. package/Meta/index.js +12 -7
  216. package/Modal/Modal.js +333 -272
  217. package/Modal/index.js +12 -7
  218. package/ModalFooter/ModalFooter.js +50 -39
  219. package/ModalFooter/index.js +12 -7
  220. package/ModalHeader/ModalHeader.js +51 -39
  221. package/ModalHeader/index.js +12 -7
  222. package/ModalIcon/ModalIcon.js +29 -23
  223. package/ModalIcon/index.js +12 -7
  224. package/ModalMain/ModalMain.js +50 -41
  225. package/ModalMain/index.js +12 -7
  226. package/ModalText/ModalText.js +47 -37
  227. package/ModalText/index.js +12 -7
  228. package/ModalTitle/ModalTitle.js +47 -37
  229. package/ModalTitle/index.js +12 -7
  230. package/MoreOptions/MoreOptions.js +72 -52
  231. package/MoreOptions/index.js +12 -7
  232. package/Move/Move.js +166 -141
  233. package/Move/index.js +12 -7
  234. package/NavigationBar/NavigationBar.js +133 -109
  235. package/NavigationBar/index.js +12 -7
  236. package/NavigationDrawer/NavigationDrawer.js +241 -211
  237. package/NavigationDrawer/index.js +12 -7
  238. package/NavigationItem/NavigationItem.js +293 -262
  239. package/NavigationItem/index.js +12 -7
  240. package/NavigationRail/NavigationRail.js +187 -150
  241. package/NavigationRail/index.js +12 -7
  242. package/NotFound/NotFound.js +89 -66
  243. package/NotFound/index.js +12 -7
  244. package/NumericTextField/NumericTextField.js +217 -212
  245. package/NumericTextField/index.js +12 -7
  246. package/Page/Page.js +131 -67
  247. package/Page/index.js +12 -7
  248. package/PageTransition/PageTransition.js +112 -102
  249. package/PageTransition/index.js +12 -7
  250. package/Pagination/Pagination.js +153 -98
  251. package/Pagination/index.js +12 -7
  252. package/PaginationItem/PaginationItem.js +85 -65
  253. package/PaginationItem/index.js +12 -7
  254. package/Parallax/Parallax.js +138 -145
  255. package/Parallax/index.js +12 -7
  256. package/Path/Path.js +40 -35
  257. package/Path/index.js +12 -7
  258. package/PieChart/PieChart.js +382 -267
  259. package/PieChart/index.js +12 -7
  260. package/Placeholder/Placeholder.js +125 -117
  261. package/Placeholder/index.js +12 -7
  262. package/Portal/Portal.js +37 -38
  263. package/Portal/index.js +12 -7
  264. package/Properties/Properties.js +85 -64
  265. package/Properties/index.js +12 -7
  266. package/Property/Property.js +120 -108
  267. package/Property/index.js +12 -7
  268. package/Radio/Radio.js +211 -181
  269. package/Radio/index.js +12 -7
  270. package/Radios/Radios.js +124 -92
  271. package/Radios/index.js +12 -7
  272. package/Rating/Rating.js +353 -360
  273. package/Rating/index.js +12 -7
  274. package/Reset/Reset.js +19 -24
  275. package/Reset/index.js +12 -7
  276. package/Reveal/Reveal.js +98 -89
  277. package/Reveal/index.js +12 -7
  278. package/RichTextEditor/RichTextEditor.js +1764 -972
  279. package/RichTextEditor/index.js +12 -7
  280. package/RoundMeter/RoundMeter.js +629 -537
  281. package/RoundMeter/index.js +12 -7
  282. package/RoundProgress/RoundProgress.js +233 -174
  283. package/RoundProgress/index.js +12 -7
  284. package/ScatterChart/ScatterChart.js +53 -40
  285. package/ScatterChart/index.js +12 -7
  286. package/ScatterChartItem/ScatterChartItem.js +214 -153
  287. package/ScatterChartItem/index.js +12 -7
  288. package/ScreenCapture/ScreenCapture.js +427 -335
  289. package/ScreenCapture/index.js +12 -7
  290. package/Section/Section.js +380 -319
  291. package/Section/index.js +12 -7
  292. package/SectionAction/SectionAction.js +72 -61
  293. package/SectionAction/index.js +12 -7
  294. package/SectionBoxes/SectionBoxes.js +240 -208
  295. package/SectionBoxes/index.js +12 -7
  296. package/SectionCards/SectionCards.js +256 -217
  297. package/SectionCards/index.js +12 -7
  298. package/SectionCarousel/SectionCarousel.js +284 -242
  299. package/SectionCarousel/index.js +12 -7
  300. package/SectionContact/SectionContact.js +174 -116
  301. package/SectionContact/index.js +12 -7
  302. package/SectionImageGallery/SectionImageGallery.js +64 -51
  303. package/SectionImageGallery/index.js +12 -7
  304. package/SectionLogos/SectionLogos.js +123 -109
  305. package/SectionLogos/index.js +12 -7
  306. package/SectionMedia/SectionMedia.js +170 -152
  307. package/SectionMedia/index.js +12 -7
  308. package/SectionReviews/SectionReviews.js +170 -129
  309. package/SectionReviews/index.js +12 -7
  310. package/SectionTextMedia/SectionTextMedia.js +187 -142
  311. package/SectionTextMedia/index.js +12 -7
  312. package/SectionTimeline/SectionTimeline.js +126 -95
  313. package/SectionTimeline/index.js +12 -7
  314. package/SectionWatch/SectionWatch.js +65 -53
  315. package/SectionWatch/index.js +12 -7
  316. package/Select/Select.js +517 -406
  317. package/Select/index.js +12 -7
  318. package/Share/Share.js +458 -319
  319. package/Share/index.js +12 -7
  320. package/Slide/Slide.js +184 -140
  321. package/Slide/index.js +12 -7
  322. package/Slider/Slider.js +927 -837
  323. package/Slider/index.js +12 -7
  324. package/SmartTextField/SmartTextField.js +1406 -1014
  325. package/SmartTextField/index.js +12 -7
  326. package/Snackbar/Snackbar.js +227 -185
  327. package/Snackbar/index.js +12 -7
  328. package/Snackbars/Context.js +9 -7
  329. package/Snackbars/Snackbars.js +234 -210
  330. package/Snackbars/index.js +32 -13
  331. package/Snackbars/useSnackbars.js +11 -10
  332. package/Space/Space.js +1683 -968
  333. package/Space/index.js +24 -21
  334. package/SpeechToText/SpeechToText.js +207 -172
  335. package/SpeechToText/index.js +12 -7
  336. package/SpeedDial/SpeedDial.js +434 -398
  337. package/SpeedDial/index.js +12 -7
  338. package/SpeedDialItem/SpeedDialItem.js +89 -63
  339. package/SpeedDialItem/index.js +12 -7
  340. package/SpyScroll/SpyScroll.js +154 -142
  341. package/SpyScroll/index.js +12 -7
  342. package/Step/Step.js +181 -127
  343. package/Step/index.js +12 -7
  344. package/Stepper/Stepper.js +159 -139
  345. package/Stepper/index.js +12 -7
  346. package/Surface/Surface.js +760 -798
  347. package/Surface/index.js +12 -7
  348. package/Switch/Switch.js +688 -532
  349. package/Switch/index.js +12 -7
  350. package/Tab/Tab.js +185 -150
  351. package/Tab/index.js +12 -7
  352. package/Table/Table.js +100 -77
  353. package/Table/index.js +12 -7
  354. package/TableBody/TableBody.js +76 -63
  355. package/TableBody/index.js +12 -7
  356. package/TableCell/TableCell.js +258 -220
  357. package/TableCell/index.js +12 -7
  358. package/TableFooter/TableFooter.js +60 -48
  359. package/TableFooter/index.js +12 -7
  360. package/TableHead/TableHead.js +139 -120
  361. package/TableHead/index.js +12 -7
  362. package/TableHeader/TableHeader.js +65 -50
  363. package/TableHeader/index.js +12 -7
  364. package/TablePagination/TablePagination.js +171 -98
  365. package/TablePagination/index.js +12 -7
  366. package/TableRow/TableRow.js +77 -64
  367. package/TableRow/index.js +12 -7
  368. package/Tabs/Tabs.js +425 -377
  369. package/Tabs/index.js +12 -7
  370. package/Text/Text.js +131 -113
  371. package/Text/index.js +12 -7
  372. package/TextField/TextField.js +940 -879
  373. package/TextField/index.js +12 -7
  374. package/TextToSpeech/TextToSpeech.js +176 -153
  375. package/TextToSpeech/index.js +12 -7
  376. package/TimePicker/TimePicker.js +985 -718
  377. package/TimePicker/index.js +12 -7
  378. package/TimeRangePicker/TimeRangePicker.js +44 -37
  379. package/TimeRangePicker/index.js +12 -7
  380. package/Timeline/Timeline.js +54 -42
  381. package/Timeline/index.js +12 -7
  382. package/TimelineItem/TimelineItem.js +144 -147
  383. package/TimelineItem/index.js +12 -7
  384. package/Timer/Timer.js +321 -204
  385. package/Timer/index.js +12 -7
  386. package/ToggleButton/ToggleButton.js +67 -58
  387. package/ToggleButton/index.js +12 -7
  388. package/ToggleButtons/ToggleButtons.js +46 -37
  389. package/ToggleButtons/index.js +12 -7
  390. package/Tooltip/Tooltip.js +489 -454
  391. package/Tooltip/index.js +12 -7
  392. package/TopAppBar/TopAppBar.js +237 -197
  393. package/TopAppBar/index.js +12 -7
  394. package/Transition/Context.js +9 -7
  395. package/Transition/Transition.js +321 -339
  396. package/Transition/index.js +42 -25
  397. package/Transition/useTransition.js +11 -10
  398. package/Transitions/Transitions.js +215 -179
  399. package/Transitions/index.js +12 -7
  400. package/Tree/Tree.js +375 -312
  401. package/Tree/index.js +12 -7
  402. package/Type/Type.js +251 -152
  403. package/Type/index.js +12 -7
  404. package/VideoPlayer/VideoPlayer.js +866 -656
  405. package/VideoPlayer/index.js +12 -7
  406. package/ViewSplit/ViewSplit.js +413 -387
  407. package/ViewSplit/index.js +12 -7
  408. package/Watch/Watch.js +436 -290
  409. package/Watch/index.js +12 -7
  410. package/Weather/Weather.js +294 -247
  411. package/Weather/index.js +12 -7
  412. package/Whiteboard/Whiteboard.js +1392 -1292
  413. package/Whiteboard/index.js +12 -7
  414. package/Widgets/Context.js +9 -7
  415. package/Widgets/Widgets.js +220 -168
  416. package/Widgets/index.js +32 -13
  417. package/Widgets/useWidgets.js +11 -10
  418. package/WindowSplit/WindowSplit.js +381 -336
  419. package/WindowSplit/index.js +12 -7
  420. package/Zoom/Zoom.js +126 -99
  421. package/Zoom/index.js +12 -7
  422. package/esm/BottomAppBar/BottomAppBar.js +5 -4
  423. package/esm/Buttons/Buttons.js +1 -1
  424. package/esm/index.js +1 -1
  425. package/index.js +4053 -660
  426. package/package.json +1 -1
  427. package/types.js +4 -1
  428. package/useForm/index.js +25 -11
  429. package/useForm/useForm.js +203 -174
  430. package/useForm/validate.js +215 -203
  431. package/useLocation/index.js +12 -7
  432. package/useLocation/useLocation.js +54 -49
  433. package/useMediaQuery/index.js +12 -7
  434. package/useMediaQuery/useMediaQuery.js +44 -43
  435. package/useQuery/index.js +12 -7
  436. package/useQuery/useQuery.js +14 -10
  437. package/useScroll/index.js +12 -7
  438. package/useScroll/useScroll.js +61 -56
  439. package/useSubscription/index.js +12 -7
  440. package/useSubscription/useSubscription.js +35 -35
  441. package/useSwipe/index.js +12 -7
  442. package/useSwipe/useSwipe.js +157 -131
  443. package/useVisible/index.js +12 -7
  444. package/useVisible/useVisible.js +86 -76
  445. package/utils.js +1224 -1362
@@ -1,790 +1,1095 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- const jsx_runtime_1 = require("react/jsx-runtime");
18
- const react_1 = __importDefault(require("react"));
19
- const utils_1 = require("@onesy/utils");
20
- const style_react_1 = require("@onesy/style-react");
21
- const IconMaterialDoneW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialDoneW100"));
22
- const IconMaterialCloseW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialCloseW100"));
23
- const IconMaterialTuneW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialTuneW100"));
24
- const IconMaterialCropW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialCropW100"));
25
- const IconMaterialAspectRatioW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialAspectRatioW100"));
26
- const IconMaterialHighQualityW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialHighQualityW100"));
27
- const IconMaterialClearAllW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialClearAllW100"));
28
- const IconMaterialDownloadW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialDownloadW100"));
29
- const IconMaterialCloudW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialCloudW100"));
30
- const IconMaterialWaterDropW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialWaterDropW100"));
31
- const IconMaterialFlakyW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialFlakyW100"));
32
- const IconMaterialWbSunnyW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialWbSunnyW100"));
33
- const IconMaterialTonalityW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialTonalityW100"));
34
- const IconMaterialNightlightW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialNightlightW100"));
35
- const Type_1 = __importDefault(require("../Type"));
36
- const Surface_1 = __importDefault(require("../Surface"));
37
- const Tooltip_1 = __importDefault(require("../Tooltip"));
38
- const IconButton_1 = __importDefault(require("../IconButton"));
39
- const Expand_1 = __importDefault(require("../Expand"));
40
- const Divider_1 = __importDefault(require("../Divider"));
41
- const Slider_1 = __importDefault(require("../Slider"));
42
- const NumericTextField_1 = __importDefault(require("../NumericTextField"));
43
- const ImageCrop_1 = __importDefault(require("../ImageCrop"));
44
- const Chip_1 = __importDefault(require("../Chip"));
45
- const Line_1 = __importDefault(require("../Line"));
46
- const utils_2 = require("../utils");
47
- const useStyle = (0, style_react_1.style)(theme => ({
48
- root: {},
49
- option: {
50
- width: '100%',
51
- padding: `${theme.methods.space.value(2, 'px')} ${theme.methods.space.value(3, 'px')}`
52
- },
53
- options: {
54
- width: '100%',
55
- overflowX: 'auto',
56
- padding: `${theme.methods.space.value(2, 'px')} ${theme.methods.space.value(3, 'px')}`
57
- },
58
- canvas: {
59
- width: '100%',
60
- height: 'auto',
61
- zIndex: '1'
62
- },
63
- inputs: {
64
- width: '100%'
65
- },
66
- divider: {
67
- '&.onesy-Divider-root': {
68
- margin: '0px'
69
- }
70
- },
71
- imageWrapper: {
72
- position: 'relative',
73
- height: '400px',
74
- width: '100%',
75
- '&::before': {
76
- content: '""',
77
- position: 'absolute',
78
- inset: '0',
79
- width: '100%',
80
- height: '100%',
81
- background: 'currentColor',
82
- zIndex: '0',
83
- opacity: '0.94'
84
- }
85
- },
86
- canvasWrapper: {
87
- position: 'relative',
88
- lineHeight: '0'
89
- },
90
- image: {
91
- width: '100%',
92
- height: 'auto'
93
- },
94
- imageCopy: {
95
- width: '100%',
96
- height: 'auto'
97
- },
98
- imageCrop: {
99
- position: 'absolute',
100
- inset: '0',
101
- width: '100% !important',
102
- height: '100% !important'
103
- },
104
- meta: {
105
- width: '100%',
106
- padding: `${theme.methods.space.value(1.5, 'px')} ${theme.methods.space.value(3, 'px')}`
107
- },
108
- optionInput: {
109
- '& .onesy-TextField-input-wrapper': {
110
- padding: '0px',
111
- height: 'auto'
112
- },
113
- '& .onesy-TextField-input': {
114
- textAlign: 'center'
115
- }
116
- },
117
- filters: {
118
- width: '100%',
119
- overflowX: 'auto',
120
- '& > *': {
121
- flex: '0 0 auto'
122
- }
123
- },
124
- action: {
125
- width: '100%',
126
- paddingTop: theme.methods.space.value(2, 'px')
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _react = _interopRequireDefault(require("react"));
12
+ var _utils = require("@onesy/utils");
13
+ var _styleReact = require("@onesy/style-react");
14
+ var _IconMaterialDoneW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialDoneW100"));
15
+ var _IconMaterialCloseW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialCloseW100"));
16
+ var _IconMaterialTuneW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialTuneW100"));
17
+ var _IconMaterialCropW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialCropW100"));
18
+ var _IconMaterialAspectRatioW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialAspectRatioW100"));
19
+ var _IconMaterialHighQualityW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialHighQualityW100"));
20
+ var _IconMaterialClearAllW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialClearAllW100"));
21
+ var _IconMaterialDownloadW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialDownloadW100"));
22
+ var _IconMaterialCloudW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialCloudW100"));
23
+ var _IconMaterialWaterDropW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialWaterDropW100"));
24
+ var _IconMaterialFlakyW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialFlakyW100"));
25
+ var _IconMaterialWbSunnyW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialWbSunnyW100"));
26
+ var _IconMaterialTonalityW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialTonalityW100"));
27
+ var _IconMaterialNightlightW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialNightlightW100"));
28
+ var _Type = _interopRequireDefault(require("../Type"));
29
+ var _Surface = _interopRequireDefault(require("../Surface"));
30
+ var _Tooltip = _interopRequireDefault(require("../Tooltip"));
31
+ var _IconButton = _interopRequireDefault(require("../IconButton"));
32
+ var _Expand = _interopRequireDefault(require("../Expand"));
33
+ var _Divider = _interopRequireDefault(require("../Divider"));
34
+ var _Slider = _interopRequireDefault(require("../Slider"));
35
+ var _NumericTextField = _interopRequireDefault(require("../NumericTextField"));
36
+ var _ImageCrop = _interopRequireDefault(require("../ImageCrop"));
37
+ var _Chip = _interopRequireDefault(require("../Chip"));
38
+ var _Line = _interopRequireDefault(require("../Line"));
39
+ var _utils2 = require("../utils");
40
+ const _excluded = ["tonal", "color", "image", "name", "type", "openDefault", "openedOptionDefault", "valueDefault", "value", "valueCopyDefault", "valueCopy", "onChange", "onChangeCopy", "onlyFilters", "filters", "meta", "filtersOption", "cropOption", "resizeOption", "qualityOption", "downloadOption", "resizeAspectRatio", "renderOption", "renderOptionClear", "renderSave", "renderCancel", "renderSlider", "renderDownload", "renderInput", "IconBrightness", "IconContrast", "IconSaturation", "IconFade", "IconInvert", "IconOldPhoto", "IconSave", "IconCancel", "IconClear", "IconCrop", "IconFilters", "IconResize", "IconQuality", "IconDownload", "ChipProps", "SliderProps", "TooltipProps", "ImageCropProps", "IconButtonProps", "className", "children"];
41
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
42
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
43
+ const useStyle = (0, _styleReact.style)(theme => ({
44
+ root: {},
45
+ option: {
46
+ width: '100%',
47
+ padding: `${theme.methods.space.value(2, 'px')} ${theme.methods.space.value(3, 'px')}`
48
+ },
49
+ options: {
50
+ width: '100%',
51
+ overflowX: 'auto',
52
+ padding: `${theme.methods.space.value(2, 'px')} ${theme.methods.space.value(3, 'px')}`
53
+ },
54
+ canvas: {
55
+ width: '100%',
56
+ height: 'auto',
57
+ zIndex: '1'
58
+ },
59
+ inputs: {
60
+ width: '100%'
61
+ },
62
+ divider: {
63
+ '&.onesy-Divider-root': {
64
+ margin: '0px'
65
+ }
66
+ },
67
+ imageWrapper: {
68
+ position: 'relative',
69
+ height: '400px',
70
+ width: '100%',
71
+ '&::before': {
72
+ content: '""',
73
+ position: 'absolute',
74
+ inset: '0',
75
+ width: '100%',
76
+ height: '100%',
77
+ background: 'currentColor',
78
+ zIndex: '0',
79
+ opacity: '0.94'
80
+ }
81
+ },
82
+ canvasWrapper: {
83
+ position: 'relative',
84
+ lineHeight: '0'
85
+ },
86
+ image: {
87
+ width: '100%',
88
+ height: 'auto'
89
+ },
90
+ imageCopy: {
91
+ width: '100%',
92
+ height: 'auto'
93
+ },
94
+ imageCrop: {
95
+ position: 'absolute',
96
+ inset: '0',
97
+ width: '100% !important',
98
+ height: '100% !important'
99
+ },
100
+ meta: {
101
+ width: '100%',
102
+ padding: `${theme.methods.space.value(1.5, 'px')} ${theme.methods.space.value(3, 'px')}`
103
+ },
104
+ optionInput: {
105
+ '& .onesy-TextField-input-wrapper': {
106
+ padding: '0px',
107
+ height: 'auto'
127
108
  },
128
- slider: {
129
- width: '100%'
109
+ '& .onesy-TextField-input': {
110
+ textAlign: 'center'
130
111
  }
131
- }), { name: 'onesy-ImageEdit' });
132
- const ImageEdit = react_1.default.forwardRef((props_, ref) => {
133
- var _a, _b;
134
- const theme = (0, style_react_1.useOnesyTheme)();
135
- const l = theme.l;
136
- const props = react_1.default.useMemo(() => { var _a, _b, _c, _d, _e, _f, _g, _h; return (Object.assign(Object.assign(Object.assign({}, (_d = (_c = (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.default), (_h = (_g = (_f = (_e = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _e === void 0 ? void 0 : _e.elements) === null || _f === void 0 ? void 0 : _f.onesyImageEdit) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]);
137
- const Line = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Line) || Line_1.default; }, [theme]);
138
- const Type = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Type) || Type_1.default; }, [theme]);
139
- const Surface = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Surface) || Surface_1.default; }, [theme]);
140
- const IconButton = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.IconButton) || IconButton_1.default; }, [theme]);
141
- const Tooltip = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Tooltip) || Tooltip_1.default; }, [theme]);
142
- const Expand = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Expand) || Expand_1.default; }, [theme]);
143
- const Divider = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Divider) || Divider_1.default; }, [theme]);
144
- const Slider = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Slider) || Slider_1.default; }, [theme]);
145
- const NumericTextField = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.NumericTextField) || NumericTextField_1.default; }, [theme]);
146
- const ImageCrop = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.ImageCrop) || ImageCrop_1.default; }, [theme]);
147
- const Chip = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Chip) || Chip_1.default; }, [theme]);
148
- const { tonal = true, color = 'primary', image, name = 'onesy-image.jpg', type = 'image/jpeg', openDefault, openedOptionDefault, valueDefault, value: value_, valueCopyDefault, valueCopy: valueCopy_, onChange: onChange_, onChangeCopy: onChangeCopy_, onlyFilters, filters: filters_, meta = true, filtersOption = true, cropOption = true, resizeOption = true, qualityOption = true, downloadOption = true, resizeAspectRatio = true, renderOption, renderOptionClear, renderSave, renderCancel, renderSlider, renderDownload, renderInput, IconBrightness = IconMaterialWbSunnyW100_1.default, IconContrast = IconMaterialFlakyW100_1.default, IconSaturation = IconMaterialWaterDropW100_1.default, IconFade = IconMaterialCloudW100_1.default, IconInvert = IconMaterialTonalityW100_1.default, IconOldPhoto = IconMaterialNightlightW100_1.default, IconSave = IconMaterialDoneW100_1.default, IconCancel = IconMaterialCloseW100_1.default, IconClear = IconMaterialClearAllW100_1.default, IconCrop = IconMaterialCropW100_1.default, IconFilters = IconMaterialTuneW100_1.default, IconResize = IconMaterialAspectRatioW100_1.default, IconQuality = IconMaterialHighQualityW100_1.default, IconDownload = IconMaterialDownloadW100_1.default, ChipProps: ChipProps_, SliderProps: SliderProps_, TooltipProps: TooltipProps_, ImageCropProps: ImageCropProps_, IconButtonProps: IconButtonProps_, className, children } = props, other = __rest(props, ["tonal", "color", "image", "name", "type", "openDefault", "openedOptionDefault", "valueDefault", "value", "valueCopyDefault", "valueCopy", "onChange", "onChangeCopy", "onlyFilters", "filters", "meta", "filtersOption", "cropOption", "resizeOption", "qualityOption", "downloadOption", "resizeAspectRatio", "renderOption", "renderOptionClear", "renderSave", "renderCancel", "renderSlider", "renderDownload", "renderInput", "IconBrightness", "IconContrast", "IconSaturation", "IconFade", "IconInvert", "IconOldPhoto", "IconSave", "IconCancel", "IconClear", "IconCrop", "IconFilters", "IconResize", "IconQuality", "IconDownload", "ChipProps", "SliderProps", "TooltipProps", "ImageCropProps", "IconButtonProps", "className", "children"]);
149
- const [init, setInit] = react_1.default.useState(false);
150
- const [value, setValue] = react_1.default.useState(valueDefault !== undefined ? valueDefault : value_);
151
- const [valueCopy, setValueCopy] = react_1.default.useState(valueCopyDefault !== undefined ? valueCopyDefault : valueCopy_);
152
- const [open, setOpen] = react_1.default.useState(openDefault);
153
- const [openedOption, setOpenedOption] = react_1.default.useState(openedOptionDefault);
154
- const [quality, setQuality] = react_1.default.useState(100);
155
- const [filterValues, setFilterValues] = react_1.default.useState({});
156
- const [filterValuesCopy, setFilterValuesCopy] = react_1.default.useState({});
157
- const [filter, setFilter] = react_1.default.useState();
158
- const [resize, setResize] = react_1.default.useState();
159
- const [selection, setSelection] = react_1.default.useState();
160
- const [aspectRatio, setAspectRatio] = react_1.default.useState();
161
- const [aspectRatioCustom, setAspectRatioCustom] = react_1.default.useState([1, 1]);
162
- const [size, setSize] = react_1.default.useState('');
163
- const { classes } = useStyle();
164
- const refs = {
165
- root: react_1.default.useRef(null),
166
- option: react_1.default.useRef(null),
167
- value: react_1.default.useRef(null),
168
- valueCopy: react_1.default.useRef(null),
169
- canvasMain: react_1.default.useRef(null),
170
- open: react_1.default.useRef(null),
171
- resizeAspectRatio: react_1.default.useRef(null),
172
- filterValues: react_1.default.useRef(null),
173
- filterValuesCopy: react_1.default.useRef(null)
174
- };
175
- refs.value.current = value;
176
- refs.valueCopy.current = valueCopy;
177
- refs.open.current = open;
178
- refs.resizeAspectRatio.current = resizeAspectRatio;
179
- refs.filterValues.current = filterValues;
180
- refs.filterValuesCopy.current = filterValuesCopy;
181
- const updateSize = (valueNew = refs.canvasMain.current) => {
182
- const uri = valueNew.toDataURL(type);
183
- // Update size
184
- setSize((0, utils_1.to)((0, utils_1.to)(uri, 'byte-size'), 'size-format'));
185
- };
186
- react_1.default.useEffect(() => {
187
- var _a;
188
- const method = (event) => {
189
- if (['Escape'].includes(event.key) ||
190
- (['s', 'S'].includes(event.key) && event.metaKey) ||
191
- (['f', 'F'].includes(event.key) && event.metaKey && event.shiftKey) ||
192
- (['c', 'C'].includes(event.key) && event.metaKey && event.shiftKey) ||
193
- (['d', 'D'].includes(event.key) && (event.metaKey || event.shiftKey)) ||
194
- (['r', 'R'].includes(event.key) && (event.metaKey || event.shiftKey)) ||
195
- (['q', 'Q'].includes(event.key) && event.metaKey && event.shiftKey)) {
196
- event.preventDefault();
197
- }
198
- switch (event.key) {
199
- case 's':
200
- case 'S':
201
- if (refs.open.current && event.metaKey)
202
- onSave();
203
- return;
204
- case 'f':
205
- case 'F':
206
- if (event.metaKey && event.shiftKey)
207
- openOption('filters');
208
- return;
209
- case 'c':
210
- case 'C':
211
- if (event.metaKey && event.shiftKey)
212
- openOption('crop');
213
- return;
214
- case 'd':
215
- case 'D':
216
- if (event.metaKey && event.shiftKey)
217
- onDownload();
218
- return;
219
- case 'r':
220
- case 'R':
221
- if (event.metaKey && !event.shiftKey)
222
- onReset();
223
- if (event.metaKey && event.shiftKey)
224
- openOption('resize');
225
- return;
226
- case 'q':
227
- case 'Q':
228
- if (event.metaKey && event.shiftKey)
229
- openOption('quality');
230
- return;
231
- case 'Escape':
232
- if (refs.open.current)
233
- onCancel();
234
- return;
235
- default:
236
- break;
237
- }
238
- };
239
- if (!refs.value.current) {
240
- if (image instanceof HTMLCanvasElement)
241
- onChange(image);
242
- else if ((0, utils_1.is)('string', image))
243
- makeImage(image);
244
- }
245
- const rootDocument = (0, utils_1.isEnvironment)('browser') ? (((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) || window.document) : undefined;
246
- rootDocument.addEventListener('keydown', method);
247
- setInit(true);
248
- return () => {
249
- // Clean up
250
- rootDocument.removeEventListener('keydown', method);
251
- };
252
- }, []);
253
- react_1.default.useEffect(() => {
254
- if (image instanceof HTMLCanvasElement)
255
- onChange(image);
256
- else if ((0, utils_1.is)('string', image))
257
- makeImage(image);
258
- }, [image]);
259
- react_1.default.useEffect(() => {
260
- var _a;
261
- const valueToUse = !open ? refs.value.current : refs.valueCopy.current;
262
- if (valueToUse) {
263
- refs.canvasMain.current.width = valueToUse.width;
264
- refs.canvasMain.current.height = valueToUse.height;
265
- (_a = refs.canvasMain.current) === null || _a === void 0 ? void 0 : _a.getContext('2d').drawImage(valueToUse, 0, 0, valueToUse.width, valueToUse.height);
266
- updateSize();
267
- }
268
- }, [value, valueCopy, open]);
269
- react_1.default.useEffect(() => {
270
- if (init) {
271
- if (value_ !== value)
272
- onChange(value_);
273
- }
274
- }, [value_]);
275
- react_1.default.useEffect(() => {
276
- if (init) {
277
- if (valueCopy_ !== valueCopy)
278
- onChangeCopy(valueCopy_);
279
- }
280
- }, [valueCopy_]);
281
- const applyAllFilters = (canvas) => {
282
- let valueCopy__ = refs.valueCopy.current;
283
- // Update filters
284
- Object.keys(refs.filterValuesCopy.current).forEach(item => {
285
- const filterValue_ = filters.find(item_ => item_.value === item);
286
- if (filterValue_) {
287
- const { method } = filterValue_;
288
- if ((0, utils_1.is)('function', method) &&
289
- refs.filterValuesCopy.current[item] !== undefined)
290
- valueCopy__ = method(refs.filterValuesCopy.current[item], canvas, valueCopy__);
291
- }
292
- });
293
- };
294
- const applyAllFiltersDebounced = react_1.default.useCallback((0, utils_1.debounce)(applyAllFilters, 140), []);
295
- react_1.default.useEffect(() => {
296
- applyAllFiltersDebounced(refs.canvasMain.current);
297
- }, [filterValuesCopy]);
298
- const makeImage = async (valueNew = refs.value.current) => {
299
- var _a;
300
- const img = await (0, utils_2.image)(valueNew);
301
- const rootDocument = (0, utils_1.isEnvironment)('browser') ? (((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) || window.document) : undefined;
302
- const canvas = rootDocument.createElement('canvas');
303
- canvas.width = img.width;
304
- canvas.height = img.height;
305
- canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);
306
- // Image
307
- onChange(canvas);
308
- // Image copy
309
- const copy = rootDocument.createElement('canvas');
310
- copy.width = canvas.width;
311
- copy.height = canvas.height;
312
- copy.getContext('2d').drawImage(canvas, 0, 0, canvas.width, canvas.height);
313
- onChangeCopy(copy);
314
- };
315
- const updateResize = (0, utils_1.debounce)(async (width, height) => {
316
- var _a;
317
- const rootDocument = (0, utils_1.isEnvironment)('browser') ? (((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) || window.document) : undefined;
318
- // Update value copy
319
- const canvas = rootDocument.createElement('canvas');
320
- if (width > 1 && height > 1) {
321
- canvas.width = width;
322
- canvas.height = height;
323
- canvas.getContext('2d').drawImage(refs.value.current, 0, 0, width, height);
324
- // Value copy
325
- onChangeCopy(canvas);
326
- // Update the canvas value
327
- refs.canvasMain.current.width = width;
328
- refs.canvasMain.current.height = height;
329
- refs.canvasMain.current.getContext('2d').drawImage(value, 0, 0, width, height);
330
- // Update size
331
- updateSize();
332
- }
333
- }, 140);
334
- const onFilterSliderChange = (valueNew, valueFilter) => {
335
- setFilterValuesCopy(values_ => (Object.assign(Object.assign({}, values_), { [valueFilter]: valueNew })));
336
- };
337
- const onChangeFilter = (valueNew) => {
338
- // If moving to another filter or closing current one
339
- // clean up previous one filter for mainCanvas
340
- if (filter === valueNew)
341
- setFilter('');
342
- else
343
- setFilter(valueNew);
344
- };
345
- const onChangeAspectRatioCustom = (valueNew_, left_ = true) => {
346
- const valueNew = !valueNew_ ? 1 : valueNew_;
347
- let left = (aspectRatioCustom === null || aspectRatioCustom === void 0 ? void 0 : aspectRatioCustom[0]) || 1;
348
- let right = (aspectRatioCustom === null || aspectRatioCustom === void 0 ? void 0 : aspectRatioCustom[1]) || 1;
349
- left_ ? left = valueNew : right = valueNew;
350
- setAspectRatioCustom([left, right]);
351
- onChangeAspectRatio(left / right);
352
- };
353
- const onChangeAspectRatio = (valueNew) => {
354
- if (aspectRatio === valueNew)
355
- setAspectRatio('');
356
- else
357
- setAspectRatio(valueNew);
358
- };
359
- const onChangeResize = async (valueNew, width_ = true) => {
360
- let width;
361
- let height;
362
- if (!refs.resizeAspectRatio.current) {
363
- if (width_) {
364
- width = +valueNew;
365
- height = resize === null || resize === void 0 ? void 0 : resize[1];
366
- }
367
- else {
368
- width = resize === null || resize === void 0 ? void 0 : resize[0];
369
- height = +valueNew;
370
- }
371
- }
372
- else {
373
- const aspectRatio_ = (value === null || value === void 0 ? void 0 : value.width) / (value === null || value === void 0 ? void 0 : value.height);
374
- if (width_) {
375
- width = +valueNew;
376
- height = valueNew / aspectRatio_;
377
- }
378
- else {
379
- height = +valueNew;
380
- width = height * aspectRatio_;
381
- }
382
- }
383
- width = (0, utils_1.clamp)(width, 0);
384
- height = (0, utils_1.clamp)(height, 0);
385
- setResize([width, height]);
386
- await updateResize(width, height);
387
- };
388
- const updateQuality = (0, utils_1.debounce)(async (valueNew) => {
389
- var _a, _b;
390
- const rootDocument = (0, utils_1.isEnvironment)('browser') ? (((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) || window.document) : undefined;
391
- // Update copy value
392
- const uri = value.toDataURL('image/jpeg', valueNew / 100);
393
- const img = await (0, utils_2.image)(uri);
394
- const canvas = rootDocument.createElement('canvas');
395
- canvas.width = img.width;
396
- canvas.height = img.height;
397
- canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);
398
- onChangeCopy(canvas);
399
- // Update the canvas value
400
- refs.canvasMain.current.width = canvas.width;
401
- refs.canvasMain.current.height = canvas.height;
402
- (_b = refs.canvasMain.current) === null || _b === void 0 ? void 0 : _b.getContext('2d').drawImage(canvas, 0, 0, canvas.width, canvas.height);
403
- // Update size
404
- updateSize();
405
- }, 40);
406
- const onChangeQuality = async (valueNew) => {
407
- setQuality(valueNew);
408
- await updateQuality(valueNew);
409
- };
410
- const onChange = (valueNew) => {
411
- // Update inner or controlled
412
- if (!props.hasOwnProperty('value'))
413
- setValue(valueNew);
414
- if ((0, utils_1.is)('function', onChange_))
415
- onChange_(valueNew);
416
- };
417
- const onChangeCopy = (valueNew) => {
418
- // Update inner or controlled
419
- if (!props.hasOwnProperty('valueCopy'))
420
- setValueCopy(valueNew);
421
- if ((0, utils_1.is)('function', onChangeCopy_))
422
- onChangeCopy_(valueNew);
423
- };
424
- const onReset = (imageReset = true, valueCopyReset = true, resizeReset = true) => {
425
- var _a;
426
- const rootDocument = (0, utils_1.isEnvironment)('browser') ? (((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) || window.document) : undefined;
427
- setOpen(false);
428
- setQuality(100);
429
- setAspectRatio('');
430
- setAspectRatioCustom([1, 1]);
431
- setSelection('');
432
- setFilter('');
433
- setFilterValuesCopy(Object.assign({}, filterValues));
434
- if (resizeReset)
435
- setResize([value === null || value === void 0 ? void 0 : value.width, value === null || value === void 0 ? void 0 : value.height]);
436
- if (valueCopyReset) {
437
- const canvas = rootDocument.createElement('canvas');
438
- canvas.width = refs.value.current.width;
439
- canvas.height = refs.value.current.height;
440
- canvas.getContext('2d').drawImage(refs.value.current, 0, 0, refs.value.current.width, refs.value.current.height);
441
- onChangeCopy(canvas);
442
- }
443
- if (imageReset) {
444
- setFilterValues({});
445
- setFilterValuesCopy({});
446
- makeImage(image);
447
- }
448
- };
449
- const openOption = (valueNew) => {
450
- setOpenedOption(valueNew);
451
- if (open && openedOption === valueNew) {
452
- setOpen(false);
453
- onReset(false);
454
- }
455
- else if (!open)
456
- setOpen(true);
457
- };
458
- const onSave = () => {
459
- var _a, _b;
460
- const rootDocument = (0, utils_1.isEnvironment)('browser') ? (((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) || window.document) : undefined;
461
- // Make value copy into value
462
- let canvas = rootDocument.createElement('canvas');
463
- canvas.width = refs.valueCopy.current.width;
464
- canvas.height = refs.valueCopy.current.height;
465
- canvas.getContext('2d').drawImage(refs.valueCopy.current, 0, 0, refs.valueCopy.current.width, refs.valueCopy.current.height);
466
- // Update crop
467
- if (openedOption === 'crop' && selection) {
468
- // Crop the canvas
469
- canvas.width = selection.width;
470
- canvas.height = selection.height;
471
- canvas = (0, utils_1.canvasCrop)(refs.valueCopy.current, selection.left, selection.top, selection.width, selection.height);
472
- }
473
- // Update filters
474
- setFilterValues(Object.assign({}, filterValuesCopy));
475
- applyAllFilters(canvas);
476
- // Update the main canvas value
477
- refs.canvasMain.current.width = canvas.width;
478
- refs.canvasMain.current.height = canvas.height;
479
- (_b = refs.canvasMain.current) === null || _b === void 0 ? void 0 : _b.getContext('2d').drawImage(canvas, 0, 0, canvas.width, canvas.height);
480
- // Update value
481
- onChange(canvas);
482
- const canvasCopy = rootDocument.createElement('canvas');
483
- canvasCopy.width = canvas.width;
484
- canvasCopy.height = canvas.height;
485
- canvasCopy.getContext('2d').drawImage(canvas, 0, 0, canvasCopy.width, canvasCopy.height);
486
- // Update value copy
487
- onChangeCopy(canvasCopy);
488
- // Reset
489
- onReset(false, false, false);
490
- };
491
- const onDownload = () => {
492
- // Download the image from canvas datauri
493
- // of the image type and quality, name
494
- const uri = refs.value.current.toDataURL(type);
495
- (0, utils_1.download)(name, uri, type);
496
- };
497
- const onCancel = () => {
498
- var _a, _b, _c, _d;
499
- const rootDocument = (0, utils_1.isEnvironment)('browser') ? (((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) || window.document) : undefined;
500
- // Reset to unopen
501
- onReset(false);
502
- // Make value copy into value
503
- const canvas = rootDocument.createElement('canvas');
504
- canvas.width = refs.value.current.width;
505
- canvas.height = refs.value.current.height;
506
- canvas.getContext('2d').drawImage(refs.value.current, 0, 0, refs.value.current.width, refs.value.current.height);
507
- onChangeCopy(canvas);
508
- // Update the main canvas value
509
- refs.canvasMain.current.width = (_b = refs.value.current) === null || _b === void 0 ? void 0 : _b.width;
510
- refs.canvasMain.current.height = (_c = refs.value.current) === null || _c === void 0 ? void 0 : _c.height;
511
- (_d = refs.canvasMain.current) === null || _d === void 0 ? void 0 : _d.getContext('2d').drawImage(refs.value.current, 0, 0, refs.value.current.width, refs.value.current.height);
112
+ },
113
+ filters: {
114
+ width: '100%',
115
+ overflowX: 'auto',
116
+ '& > *': {
117
+ flex: '0 0 auto'
118
+ }
119
+ },
120
+ action: {
121
+ width: '100%',
122
+ paddingTop: theme.methods.space.value(2, 'px')
123
+ },
124
+ slider: {
125
+ width: '100%'
126
+ }
127
+ }), {
128
+ name: 'onesy-ImageEdit'
129
+ });
130
+ const ImageEdit = /*#__PURE__*/_react.default.forwardRef((props_, ref) => {
131
+ var _ref, _ref2;
132
+ const theme = (0, _styleReact.useOnesyTheme)();
133
+ const l = theme.l;
134
+ const props = _react.default.useMemo(() => {
135
+ var _theme$ui, _theme$ui2;
136
+ return _objectSpread(_objectSpread(_objectSpread({}, theme === null || theme === void 0 || (_theme$ui = theme.ui) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.elements) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.all) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.props) === null || _theme$ui === void 0 ? void 0 : _theme$ui.default), theme === null || theme === void 0 || (_theme$ui2 = theme.ui) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.elements) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.onesyImageEdit) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_);
137
+ }, [props_]);
138
+ const Line = _react.default.useMemo(() => {
139
+ var _theme$elements;
140
+ return (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Line) || _Line.default;
141
+ }, [theme]);
142
+ const Type = _react.default.useMemo(() => {
143
+ var _theme$elements2;
144
+ return (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Type) || _Type.default;
145
+ }, [theme]);
146
+ const Surface = _react.default.useMemo(() => {
147
+ var _theme$elements3;
148
+ return (theme === null || theme === void 0 || (_theme$elements3 = theme.elements) === null || _theme$elements3 === void 0 ? void 0 : _theme$elements3.Surface) || _Surface.default;
149
+ }, [theme]);
150
+ const IconButton = _react.default.useMemo(() => {
151
+ var _theme$elements4;
152
+ return (theme === null || theme === void 0 || (_theme$elements4 = theme.elements) === null || _theme$elements4 === void 0 ? void 0 : _theme$elements4.IconButton) || _IconButton.default;
153
+ }, [theme]);
154
+ const Tooltip = _react.default.useMemo(() => {
155
+ var _theme$elements5;
156
+ return (theme === null || theme === void 0 || (_theme$elements5 = theme.elements) === null || _theme$elements5 === void 0 ? void 0 : _theme$elements5.Tooltip) || _Tooltip.default;
157
+ }, [theme]);
158
+ const Expand = _react.default.useMemo(() => {
159
+ var _theme$elements6;
160
+ return (theme === null || theme === void 0 || (_theme$elements6 = theme.elements) === null || _theme$elements6 === void 0 ? void 0 : _theme$elements6.Expand) || _Expand.default;
161
+ }, [theme]);
162
+ const Divider = _react.default.useMemo(() => {
163
+ var _theme$elements7;
164
+ return (theme === null || theme === void 0 || (_theme$elements7 = theme.elements) === null || _theme$elements7 === void 0 ? void 0 : _theme$elements7.Divider) || _Divider.default;
165
+ }, [theme]);
166
+ const Slider = _react.default.useMemo(() => {
167
+ var _theme$elements8;
168
+ return (theme === null || theme === void 0 || (_theme$elements8 = theme.elements) === null || _theme$elements8 === void 0 ? void 0 : _theme$elements8.Slider) || _Slider.default;
169
+ }, [theme]);
170
+ const NumericTextField = _react.default.useMemo(() => {
171
+ var _theme$elements9;
172
+ return (theme === null || theme === void 0 || (_theme$elements9 = theme.elements) === null || _theme$elements9 === void 0 ? void 0 : _theme$elements9.NumericTextField) || _NumericTextField.default;
173
+ }, [theme]);
174
+ const ImageCrop = _react.default.useMemo(() => {
175
+ var _theme$elements10;
176
+ return (theme === null || theme === void 0 || (_theme$elements10 = theme.elements) === null || _theme$elements10 === void 0 ? void 0 : _theme$elements10.ImageCrop) || _ImageCrop.default;
177
+ }, [theme]);
178
+ const Chip = _react.default.useMemo(() => {
179
+ var _theme$elements11;
180
+ return (theme === null || theme === void 0 || (_theme$elements11 = theme.elements) === null || _theme$elements11 === void 0 ? void 0 : _theme$elements11.Chip) || _Chip.default;
181
+ }, [theme]);
182
+ const {
183
+ tonal = true,
184
+ color = 'primary',
185
+ image,
186
+ name = 'onesy-image.jpg',
187
+ type = 'image/jpeg',
188
+ openDefault,
189
+ openedOptionDefault,
190
+ valueDefault,
191
+ value: value_,
192
+ valueCopyDefault,
193
+ valueCopy: valueCopy_,
194
+ onChange: onChange_,
195
+ onChangeCopy: onChangeCopy_,
196
+ onlyFilters,
197
+ filters: filters_,
198
+ meta = true,
199
+ filtersOption = true,
200
+ cropOption = true,
201
+ resizeOption = true,
202
+ qualityOption = true,
203
+ downloadOption = true,
204
+ resizeAspectRatio = true,
205
+ renderOption,
206
+ renderOptionClear,
207
+ renderSave,
208
+ renderCancel,
209
+ renderSlider,
210
+ renderDownload,
211
+ renderInput,
212
+ IconBrightness = _IconMaterialWbSunnyW.default,
213
+ IconContrast = _IconMaterialFlakyW.default,
214
+ IconSaturation = _IconMaterialWaterDropW.default,
215
+ IconFade = _IconMaterialCloudW.default,
216
+ IconInvert = _IconMaterialTonalityW.default,
217
+ IconOldPhoto = _IconMaterialNightlightW.default,
218
+ IconSave = _IconMaterialDoneW.default,
219
+ IconCancel = _IconMaterialCloseW.default,
220
+ IconClear = _IconMaterialClearAllW.default,
221
+ IconCrop = _IconMaterialCropW.default,
222
+ IconFilters = _IconMaterialTuneW.default,
223
+ IconResize = _IconMaterialAspectRatioW.default,
224
+ IconQuality = _IconMaterialHighQualityW.default,
225
+ IconDownload = _IconMaterialDownloadW.default,
226
+ ChipProps: ChipProps_,
227
+ SliderProps: SliderProps_,
228
+ TooltipProps: TooltipProps_,
229
+ ImageCropProps: ImageCropProps_,
230
+ IconButtonProps: IconButtonProps_,
231
+ className,
232
+ children
233
+ } = props,
234
+ other = (0, _objectWithoutProperties2.default)(props, _excluded);
235
+ const [init, setInit] = _react.default.useState(false);
236
+ const [value, setValue] = _react.default.useState(valueDefault !== undefined ? valueDefault : value_);
237
+ const [valueCopy, setValueCopy] = _react.default.useState(valueCopyDefault !== undefined ? valueCopyDefault : valueCopy_);
238
+ const [open, setOpen] = _react.default.useState(openDefault);
239
+ const [openedOption, setOpenedOption] = _react.default.useState(openedOptionDefault);
240
+ const [quality, setQuality] = _react.default.useState(100);
241
+ const [filterValues, setFilterValues] = _react.default.useState({});
242
+ const [filterValuesCopy, setFilterValuesCopy] = _react.default.useState({});
243
+ const [filter, setFilter] = _react.default.useState();
244
+ const [resize, setResize] = _react.default.useState();
245
+ const [selection, setSelection] = _react.default.useState();
246
+ const [aspectRatio, setAspectRatio] = _react.default.useState();
247
+ const [aspectRatioCustom, setAspectRatioCustom] = _react.default.useState([1, 1]);
248
+ const [size, setSize] = _react.default.useState('');
249
+ const {
250
+ classes
251
+ } = useStyle();
252
+ const refs = {
253
+ root: _react.default.useRef(null),
254
+ option: _react.default.useRef(null),
255
+ value: _react.default.useRef(null),
256
+ valueCopy: _react.default.useRef(null),
257
+ canvasMain: _react.default.useRef(null),
258
+ open: _react.default.useRef(null),
259
+ resizeAspectRatio: _react.default.useRef(null),
260
+ filterValues: _react.default.useRef(null),
261
+ filterValuesCopy: _react.default.useRef(null)
262
+ };
263
+ refs.value.current = value;
264
+ refs.valueCopy.current = valueCopy;
265
+ refs.open.current = open;
266
+ refs.resizeAspectRatio.current = resizeAspectRatio;
267
+ refs.filterValues.current = filterValues;
268
+ refs.filterValuesCopy.current = filterValuesCopy;
269
+ const updateSize = (valueNew = refs.canvasMain.current) => {
270
+ const uri = valueNew.toDataURL(type);
271
+
272
+ // Update size
273
+ setSize((0, _utils.to)((0, _utils.to)(uri, 'byte-size'), 'size-format'));
274
+ };
275
+ _react.default.useEffect(() => {
276
+ var _refs$root$current;
277
+ const method = event => {
278
+ if (['Escape'].includes(event.key) || ['s', 'S'].includes(event.key) && event.metaKey || ['f', 'F'].includes(event.key) && event.metaKey && event.shiftKey || ['c', 'C'].includes(event.key) && event.metaKey && event.shiftKey || ['d', 'D'].includes(event.key) && (event.metaKey || event.shiftKey) || ['r', 'R'].includes(event.key) && (event.metaKey || event.shiftKey) || ['q', 'Q'].includes(event.key) && event.metaKey && event.shiftKey) {
279
+ event.preventDefault();
280
+ }
281
+ switch (event.key) {
282
+ case 's':
283
+ case 'S':
284
+ if (refs.open.current && event.metaKey) onSave();
285
+ return;
286
+ case 'f':
287
+ case 'F':
288
+ if (event.metaKey && event.shiftKey) openOption('filters');
289
+ return;
290
+ case 'c':
291
+ case 'C':
292
+ if (event.metaKey && event.shiftKey) openOption('crop');
293
+ return;
294
+ case 'd':
295
+ case 'D':
296
+ if (event.metaKey && event.shiftKey) onDownload();
297
+ return;
298
+ case 'r':
299
+ case 'R':
300
+ if (event.metaKey && !event.shiftKey) onReset();
301
+ if (event.metaKey && event.shiftKey) openOption('resize');
302
+ return;
303
+ case 'q':
304
+ case 'Q':
305
+ if (event.metaKey && event.shiftKey) openOption('quality');
306
+ return;
307
+ case 'Escape':
308
+ if (refs.open.current) onCancel();
309
+ return;
310
+ default:
311
+ break;
312
+ }
512
313
  };
513
- let filters = react_1.default.useMemo(() => [
514
- {
515
- label: l('Brightness'),
516
- Icon: IconBrightness,
517
- value: 'brightness',
518
- method: utils_2.canvasBrightness,
519
- renderIconButton: (value__, selected_, onChangeFilter_) => ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: l('Brightness') }, TooltipProps, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ version: 'outlined', selected: selected_, onClick: () => onChangeFilter_(value__) }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconBrightness, {}) })) }), value__)),
520
- renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => ((0, jsx_runtime_1.jsx)(Slider, Object.assign({ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, min: -100, max: 100, precision: 1, marks: [
521
- { value: -100, label: '-100' },
522
- { value: 0, label: '0' },
523
- { value: 100, label: '100' }
524
- ], labels: true, tooltip: true, onChange: (valueNew) => {
525
- if ((0, utils_1.is)('function', onFilterSliderChange_))
526
- onFilterSliderChange_(valueNew, value__);
527
- } }, SliderProps, { className: (0, style_react_1.classNames)([
528
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
529
- 'onesy-ImageEdit-slider'
530
- ],
531
- SliderProps.className,
532
- classes.slider
533
- ]) }), value__))
534
- },
535
- {
536
- label: l('Contrast'),
537
- Icon: IconContrast,
538
- value: 'contrast',
539
- method: utils_2.canvasContrast,
540
- renderIconButton: (value__, selected_, onChangeFilter_) => ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: l('Contrast') }, TooltipProps, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ version: 'outlined', selected: selected_, onClick: () => onChangeFilter_(value__) }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconContrast, {}) })) }), value__)),
541
- renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => ((0, jsx_runtime_1.jsx)(Slider, Object.assign({ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, min: -100, max: 100, precision: 1, marks: [
542
- { value: -100, label: '-100' },
543
- { value: 0, label: '0' },
544
- { value: 100, label: '100' }
545
- ], labels: true, tooltip: true, onChange: (valueNew) => {
546
- if ((0, utils_1.is)('function', onFilterSliderChange_))
547
- onFilterSliderChange_(valueNew, value__);
548
- } }, SliderProps, { className: (0, style_react_1.classNames)([
549
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
550
- 'onesy-ImageEdit-slider'
551
- ],
552
- SliderProps.className,
553
- classes.slider
554
- ]) }), value__))
555
- },
556
- {
557
- label: l('Saturation'),
558
- Icon: IconSaturation,
559
- value: 'saturation',
560
- method: utils_2.canvasSaturation,
561
- renderIconButton: (value__, selected_, onChangeFilter_) => ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: l('Saturation') }, TooltipProps, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ version: 'outlined', selected: selected_, onClick: () => onChangeFilter_(value__) }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconSaturation, {}) })) }), value__)),
562
- renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => ((0, jsx_runtime_1.jsx)(Slider, Object.assign({ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, min: -100, max: 100, precision: 1, marks: [
563
- { value: -100, label: '-100' },
564
- { value: 0, label: '0' },
565
- { value: 100, label: '100' }
566
- ], labels: true, tooltip: true, onChange: (valueNew) => {
567
- if ((0, utils_1.is)('function', onFilterSliderChange_))
568
- onFilterSliderChange_(valueNew, value__);
569
- } }, SliderProps, { className: (0, style_react_1.classNames)([
570
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
571
- 'onesy-ImageEdit-slider'
572
- ],
573
- SliderProps.className,
574
- classes.slider
575
- ]) }), value__))
576
- },
577
- {
578
- label: l('Fade'),
579
- Icon: IconFade,
580
- value: 'fade',
581
- method: utils_2.canvasFade,
582
- renderIconButton: (value__, selected_, onChangeFilter_) => ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: l('Fade') }, TooltipProps, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ version: 'outlined', selected: selected_, onClick: () => onChangeFilter_(value__) }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconFade, {}) })) }), value__)),
583
- renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => ((0, jsx_runtime_1.jsx)(Slider, Object.assign({ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, min: 0, max: 100, precision: 1, marks: [
584
- { value: 0, label: '0' },
585
- { value: 100, label: '100' }
586
- ], labels: true, tooltip: true, onChange: (valueNew) => {
587
- if ((0, utils_1.is)('function', onFilterSliderChange_))
588
- onFilterSliderChange_(valueNew, value__);
589
- } }, SliderProps, { className: (0, style_react_1.classNames)([
590
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
591
- 'onesy-ImageEdit-slider'
592
- ],
593
- SliderProps.className,
594
- classes.slider
595
- ]) }), value__))
596
- },
597
- {
598
- label: l('Invert'),
599
- Icon: IconInvert,
600
- value: 'invert',
601
- method: utils_2.canvasInvert,
602
- renderIconButton: (value__, selected_, onChangeFilter_) => ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: l('Invert') }, TooltipProps, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ version: 'outlined', selected: selected_, onClick: () => onChangeFilter_(value__) }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconInvert, {}) })) }), value__)),
603
- renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => ((0, jsx_runtime_1.jsx)(Slider, Object.assign({ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, min: 0, max: 1, precision: 1, marks: [
604
- { value: 0, label: 'Not inverted' },
605
- { value: 1, label: 'Inverted' }
606
- ], labels: true, tooltip: true, onChange: (valueNew) => {
607
- if ((0, utils_1.is)('function', onFilterSliderChange_))
608
- onFilterSliderChange_(valueNew, value__);
609
- } }, SliderProps, { className: (0, style_react_1.classNames)([
610
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
611
- 'onesy-ImageEdit-slider'
612
- ],
613
- SliderProps.className,
614
- classes.slider
615
- ]) }), value__))
616
- },
617
- {
618
- label: l('Old photo'),
619
- Icon: IconOldPhoto,
620
- value: 'old_photo',
621
- method: utils_2.canvasOldPhoto,
622
- renderIconButton: (value__, selected_, onChangeFilter_) => ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: l('Old photo') }, TooltipProps, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ version: 'outlined', selected: selected_, onClick: () => onChangeFilter_(value__) }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconOldPhoto, {}) })) }), value__)),
623
- renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => ((0, jsx_runtime_1.jsx)(Slider, Object.assign({ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0, min: -40, max: 40, precision: 1, marks: [
624
- { value: -40, label: '-40' },
625
- { value: 0, label: 'No filter' },
626
- { value: 40, label: '40' }
627
- ], labels: true, tooltip: true, onChange: (valueNew) => {
628
- if ((0, utils_1.is)('function', onFilterSliderChange_))
629
- onFilterSliderChange_(valueNew, value__);
630
- } }, SliderProps, { className: (0, style_react_1.classNames)([
631
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
632
- 'onesy-ImageEdit-slider'
633
- ],
634
- SliderProps.className,
635
- classes.slider
636
- ]) }), value__))
637
- },
638
- ...(filters_ || [])
639
- ], [filters_]);
640
- // Only filters
641
- if ((0, utils_1.is)('array', onlyFilters))
642
- filters = filters.filter(item => onlyFilters.includes(item.value));
643
- const ImageCropProps = Object.assign({ gridLines: true }, ImageCropProps_);
644
- const TooltipProps = Object.assign({ position: 'bottom', interactive: false }, TooltipProps_);
645
- const IconButtonProps = Object.assign({ tonal, color: 'inherit' }, IconButtonProps_);
646
- const SliderProps = Object.assign({ tonal: false, color: 'default' }, SliderProps_);
647
- const ChipProps = Object.assign({ size: 'small' }, ChipProps_);
648
- const chips = [
649
- { label: '1:1', value: 1 / 1 },
650
- { label: '4:3', value: 4 / 3 },
651
- { label: '16:9', value: 16 / 9 }
652
- ];
653
- const options = [
654
- filtersOption && { label: l('Filters'), value: 'filters', Icon: IconFilters },
655
- cropOption && { label: l('Crop'), value: 'crop', Icon: IconCrop },
656
- resizeOption && { label: l('Resize'), value: 'resize', Icon: IconResize },
657
- qualityOption && { label: l('Quality'), value: 'quality', Icon: IconQuality }
658
- ]
659
- .filter(Boolean);
660
- const MetaTypeProps = {
661
- version: 'b3'
314
+ if (!refs.value.current) {
315
+ if (image instanceof HTMLCanvasElement) onChange(image);else if ((0, _utils.is)('string', image)) makeImage(image);
316
+ }
317
+ const rootDocument = (0, _utils.isEnvironment)('browser') ? ((_refs$root$current = refs.root.current) === null || _refs$root$current === void 0 ? void 0 : _refs$root$current.ownerDocument) || window.document : undefined;
318
+ rootDocument.addEventListener('keydown', method);
319
+ setInit(true);
320
+ return () => {
321
+ // Clean up
322
+ rootDocument.removeEventListener('keydown', method);
662
323
  };
663
- const filterValue = filters.find(item_ => item_.value === filter);
664
- return ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ ref: item => {
665
- if (ref) {
666
- if ((0, utils_1.is)('function', ref))
667
- ref(item);
668
- else if (ref === null || ref === void 0 ? void 0 : ref.current)
669
- ref.current = item;
670
- }
671
- refs.root.current = item;
672
- }, tonal: tonal, color: color, gap: 0, direction: 'column', Component: Surface, className: (0, style_react_1.classNames)([
673
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
674
- 'onesy-ImageEdit-root',
675
- `onesy-ImageEdit-size-${size}`
676
- ],
677
- className,
678
- classes.root
679
- ]) }, other, { children: [(0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 0, direction: 'column', align: 'center', justify: 'center', className: (0, style_react_1.classNames)([
680
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
681
- 'onesy-ImageEdit-image-wrapper'
682
- ],
683
- classes.imageWrapper
684
- ]) }, { children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, style_react_1.classNames)([
685
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
686
- 'onesy-ImageEdit-canvas-wrapper'
687
- ],
688
- classes.canvasWrapper
689
- ]) }, { children: [(0, jsx_runtime_1.jsx)("canvas", { ref: refs.canvasMain, className: (0, style_react_1.classNames)([
690
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
691
- 'onesy-ImageEdit-canvas',
692
- 'onesy-ImageEdit-canvas-main'
693
- ],
694
- classes.canvas,
695
- classes.canvas_main
696
- ]) }), open && openedOption === 'crop' && ((0, jsx_runtime_1.jsx)(ImageCrop, Object.assign({ image: valueCopy, aspectRatio: aspectRatio ? aspectRatio : undefined, onSelectorChange: (selector) => setSelection(selector) }, ImageCropProps, { className: (0, style_react_1.classNames)([
697
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
698
- 'onesy-ImageEdit-image-crop'
699
- ],
700
- ImageCropProps.className,
701
- classes.imageCrop
702
- ]), style: {
703
- width: valueCopy === null || valueCopy === void 0 ? void 0 : valueCopy.width,
704
- height: valueCopy === null || valueCopy === void 0 ? void 0 : valueCopy.height
705
- } })))] })) })), (filtersOption || cropOption || resizeOption || qualityOption) && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(Expand, Object.assign({ in: !!open, parent: refs.root.current, style: {
706
- width: '100%'
707
- } }, { children: [(0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 0, ref: refs.option, direction: 'column', className: (0, style_react_1.classNames)([
708
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
709
- 'onesy-ImageEdit-option'
710
- ],
711
- classes.option
712
- ]) }, { children: [openedOption === 'filters' && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Expand, Object.assign({ in: !!filterValue, parent: refs.option.current, style: {
713
- width: '100%'
714
- } }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ style: {
715
- paddingInline: theme.methods.space.value(5, 'px'),
716
- paddingBottom: theme.methods.space.value(5, 'px')
717
- } }, { children: (0, utils_1.is)('function', filterValue === null || filterValue === void 0 ? void 0 : filterValue.renderSlider) && (filterValue === null || filterValue === void 0 ? void 0 : filterValue.renderSlider(filterValue.value, refs.filterValuesCopy.current, onFilterSliderChange)) })) })), (0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 1, direction: 'row', align: 'center', justify: 'flex-start', className: (0, style_react_1.classNames)([
718
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
719
- 'onesy-ImageEdit-filters'
720
- ],
721
- classes.filters
722
- ]) }, { children: filters.map((item) => ((0, utils_1.is)('function', item.renderIconButton) && item.renderIconButton(item.value, item.value === filter, onChangeFilter))) }))] }), openedOption === 'crop' && ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'row', align: 'center', justify: 'center', style: {
723
- width: '100%'
724
- } }, { children: [chips.map((item, index) => ((0, jsx_runtime_1.jsx)(Chip, Object.assign({ selected: aspectRatio === item.value, onClick: () => onChangeAspectRatio(item.value) }, ChipProps, { children: item.label }), index))), (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 0, direction: 'row', align: 'center', justify: 'center' }, { children: [(0, utils_1.is)('function', renderInput) ? renderInput(value, valueCopy, aspectRatioCustom, onChangeAspectRatioCustom, 'left') : ((0, jsx_runtime_1.jsx)(NumericTextField, { tonal: tonal, color: 'default', version: 'text', size: 'small', min: 1, value: aspectRatioCustom === null || aspectRatioCustom === void 0 ? void 0 : aspectRatioCustom[0], onChange: (valueNew) => onChangeAspectRatioCustom(+valueNew), increment: false, decrement: false, className: (0, style_react_1.classNames)([
725
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
726
- 'onesy-ImageEdit-option-input'
727
- ],
728
- classes.optionInput
729
- ]), style: {
730
- width: 24
731
- } })), (0, jsx_runtime_1.jsx)(Type, { children: ":" }), (0, utils_1.is)('function', renderInput) ? renderInput(value, valueCopy, aspectRatioCustom, onChangeAspectRatioCustom, 'right') : ((0, jsx_runtime_1.jsx)(NumericTextField, { tonal: tonal, color: 'default', version: 'text', size: 'small', min: 1, value: aspectRatioCustom === null || aspectRatioCustom === void 0 ? void 0 : aspectRatioCustom[1], onChange: (valueNew) => onChangeAspectRatioCustom(+valueNew, false), increment: false, decrement: false, className: (0, style_react_1.classNames)([
732
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
733
- 'onesy-ImageEdit-option-input'
734
- ],
735
- classes.optionInput
736
- ]), style: {
737
- width: 24
738
- } }))] }))] }))), openedOption === 'resize' && ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ direction: 'row', align: 'center', justify: 'center', className: (0, style_react_1.classNames)([
739
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
740
- 'onesy-ImageEdit-inputs'
741
- ],
742
- classes.inputs
743
- ]) }, { children: [(0, utils_1.is)('function', renderInput) ? renderInput(value, valueCopy, resize, onChangeResize, 'width') : ((0, jsx_runtime_1.jsx)(NumericTextField, { tonal: tonal, name: l('Width'), color: 'default', version: 'text', size: 'small', min: 1, max: value === null || value === void 0 ? void 0 : value.width, valueDefault: value === null || value === void 0 ? void 0 : value.width, value: resize === null || resize === void 0 ? void 0 : resize[0], onChange: (valueNew) => onChangeResize(valueNew) })), (0, utils_1.is)('function', renderInput) ? renderInput(value, valueCopy, resize, onChangeResize, 'height') : ((0, jsx_runtime_1.jsx)(NumericTextField, { tonal: tonal, name: l('Height'), color: 'default', version: 'text', size: 'small', min: 1, max: value === null || value === void 0 ? void 0 : value.height, valueDefault: value === null || value === void 0 ? void 0 : value.height, value: resize === null || resize === void 0 ? void 0 : resize[1], onChange: (valueNew) => onChangeResize(valueNew, false) }))] }))), openedOption === 'quality' && ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 3, direction: 'row', align: 'center', style: {
744
- width: '100%'
745
- } }, { children: [(0, jsx_runtime_1.jsx)(Slider, Object.assign({ valueDefault: quality, value: quality, min: 1, max: 100, precision: 1, marks: [
746
- { value: 1 },
747
- { value: 50 },
748
- { value: 100 }
749
- ], tooltip: true, onChange: onChangeQuality }, SliderProps, { className: (0, style_react_1.classNames)([
750
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
751
- 'onesy-ImageEdit-slider'
752
- ],
753
- SliderProps.className,
754
- classes.slider
755
- ]) })), (0, jsx_runtime_1.jsx)(NumericTextField, { tonal: tonal, color: 'default', version: 'text', size: 'small', min: 1, max: 100, value: quality, increment: false, decrement: false, onChange: (valueNew) => onChangeQuality(+valueNew), className: (0, style_react_1.classNames)([
756
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
757
- 'onesy-ImageEdit-option-input'
758
- ],
759
- classes.optionInput
760
- ]), style: {
761
- width: 34
762
- } })] }))), (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'row', align: 'center', justify: 'center', className: (0, style_react_1.classNames)([
763
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
764
- 'onesy-ImageEdit-action'
765
- ],
766
- classes.action
767
- ]) }, { children: [(0, utils_1.is)('function', renderSave) ? renderSave(onSave) : ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: l('Save') }, TooltipProps, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ version: 'outlined', onClick: onSave }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconSave, {}) })) }))), (0, utils_1.is)('function', renderCancel) ? renderCancel(onSave) : ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: l('Cancel') }, TooltipProps, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ version: 'outlined', onClick: onCancel }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconCancel, {}) })) })))] }))] })), (0, jsx_runtime_1.jsx)(Divider, { color: 'inherit', className: (0, style_react_1.classNames)([
768
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
769
- 'onesy-ImageEdit-divider'
770
- ],
771
- classes.divider
772
- ]) })] })), (0, jsx_runtime_1.jsx)(Line, Object.assign({ direction: 'column', align: 'center', justify: 'center', className: (0, style_react_1.classNames)([
773
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
774
- 'onesy-ImageEdit-options'
775
- ],
776
- classes.options
777
- ]) }, { children: (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'row', justify: 'flex-start' }, { children: [options.map((item, index) => ((0, utils_1.is)('function', renderOption) ? renderOption(item, open && (openOption === item.value), openOption) : ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: item.label }, TooltipProps, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ version: 'outlined', selected: open && (openedOption === item.value), onClick: () => openOption(item.value) }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(item.Icon, {}) })) }), index)))), (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 0, direction: 'row', align: 'center' }, { children: [downloadOption && (0, utils_1.is)('function', renderDownload) ? renderDownload(onDownload) : ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: l('Download') }, TooltipProps, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ version: 'text', onClick: onDownload }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconDownload, {}) })) }))), (0, utils_1.is)('function', renderOptionClear) ? renderOptionClear(onReset) : ((0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: l('Reset') }, TooltipProps, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ version: 'text', onClick: onReset }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconClear, {}) })) })))] }))] })) }))] }), children, meta && value && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Divider, { color: 'inherit', className: (0, style_react_1.classNames)([
778
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
779
- 'onesy-ImageEdit-divider'
780
- ],
781
- classes.divider
782
- ]) }), (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'row', align: 'center', justify: 'center', className: (0, style_react_1.classNames)([
783
- (0, utils_2.staticClassName)('ImageEdit', theme) && [
784
- 'onesy-ImageEdit-meta'
785
- ],
786
- classes.meta
787
- ]) }, { children: [(0, jsx_runtime_1.jsxs)(Type, Object.assign({}, MetaTypeProps, { children: [l('Dimensions'), ": ", (_a = (!open ? value : valueCopy)) === null || _a === void 0 ? void 0 : _a.width, "x", (_b = (!open ? value : valueCopy)) === null || _b === void 0 ? void 0 : _b.height] })), (0, jsx_runtime_1.jsx)(Type, Object.assign({}, MetaTypeProps, { children: "\u00B7" })), (0, jsx_runtime_1.jsxs)(Type, Object.assign({}, MetaTypeProps, { children: [l('Size'), ": ", size] }))] }))] })] })));
324
+ }, []);
325
+ _react.default.useEffect(() => {
326
+ if (image instanceof HTMLCanvasElement) onChange(image);else if ((0, _utils.is)('string', image)) makeImage(image);
327
+ }, [image]);
328
+ _react.default.useEffect(() => {
329
+ const valueToUse = !open ? refs.value.current : refs.valueCopy.current;
330
+ if (valueToUse) {
331
+ var _refs$canvasMain$curr;
332
+ refs.canvasMain.current.width = valueToUse.width;
333
+ refs.canvasMain.current.height = valueToUse.height;
334
+ (_refs$canvasMain$curr = refs.canvasMain.current) === null || _refs$canvasMain$curr === void 0 || _refs$canvasMain$curr.getContext('2d').drawImage(valueToUse, 0, 0, valueToUse.width, valueToUse.height);
335
+ updateSize();
336
+ }
337
+ }, [value, valueCopy, open]);
338
+ _react.default.useEffect(() => {
339
+ if (init) {
340
+ if (value_ !== value) onChange(value_);
341
+ }
342
+ }, [value_]);
343
+ _react.default.useEffect(() => {
344
+ if (init) {
345
+ if (valueCopy_ !== valueCopy) onChangeCopy(valueCopy_);
346
+ }
347
+ }, [valueCopy_]);
348
+ const applyAllFilters = canvas => {
349
+ let valueCopy__ = refs.valueCopy.current;
350
+
351
+ // Update filters
352
+ Object.keys(refs.filterValuesCopy.current).forEach(item => {
353
+ const filterValue_ = filters.find(item_ => item_.value === item);
354
+ if (filterValue_) {
355
+ const {
356
+ method
357
+ } = filterValue_;
358
+ if ((0, _utils.is)('function', method) && refs.filterValuesCopy.current[item] !== undefined) valueCopy__ = method(refs.filterValuesCopy.current[item], canvas, valueCopy__);
359
+ }
360
+ });
361
+ };
362
+ const applyAllFiltersDebounced = _react.default.useCallback((0, _utils.debounce)(applyAllFilters, 140), []);
363
+ _react.default.useEffect(() => {
364
+ applyAllFiltersDebounced(refs.canvasMain.current);
365
+ }, [filterValuesCopy]);
366
+ const makeImage = async (valueNew = refs.value.current) => {
367
+ var _refs$root$current2;
368
+ const img = await (0, _utils2.image)(valueNew);
369
+ const rootDocument = (0, _utils.isEnvironment)('browser') ? ((_refs$root$current2 = refs.root.current) === null || _refs$root$current2 === void 0 ? void 0 : _refs$root$current2.ownerDocument) || window.document : undefined;
370
+ const canvas = rootDocument.createElement('canvas');
371
+ canvas.width = img.width;
372
+ canvas.height = img.height;
373
+ canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);
374
+
375
+ // Image
376
+ onChange(canvas);
377
+
378
+ // Image copy
379
+ const copy = rootDocument.createElement('canvas');
380
+ copy.width = canvas.width;
381
+ copy.height = canvas.height;
382
+ copy.getContext('2d').drawImage(canvas, 0, 0, canvas.width, canvas.height);
383
+ onChangeCopy(copy);
384
+ };
385
+ const updateResize = (0, _utils.debounce)(async (width, height) => {
386
+ var _refs$root$current3;
387
+ const rootDocument = (0, _utils.isEnvironment)('browser') ? ((_refs$root$current3 = refs.root.current) === null || _refs$root$current3 === void 0 ? void 0 : _refs$root$current3.ownerDocument) || window.document : undefined;
388
+
389
+ // Update value copy
390
+ const canvas = rootDocument.createElement('canvas');
391
+ if (width > 1 && height > 1) {
392
+ canvas.width = width;
393
+ canvas.height = height;
394
+ canvas.getContext('2d').drawImage(refs.value.current, 0, 0, width, height);
395
+
396
+ // Value copy
397
+ onChangeCopy(canvas);
398
+
399
+ // Update the canvas value
400
+ refs.canvasMain.current.width = width;
401
+ refs.canvasMain.current.height = height;
402
+ refs.canvasMain.current.getContext('2d').drawImage(value, 0, 0, width, height);
403
+
404
+ // Update size
405
+ updateSize();
406
+ }
407
+ }, 140);
408
+ const onFilterSliderChange = (valueNew, valueFilter) => {
409
+ setFilterValuesCopy(values_ => _objectSpread(_objectSpread({}, values_), {}, {
410
+ [valueFilter]: valueNew
411
+ }));
412
+ };
413
+ const onChangeFilter = valueNew => {
414
+ // If moving to another filter or closing current one
415
+ // clean up previous one filter for mainCanvas
416
+ if (filter === valueNew) setFilter('');else setFilter(valueNew);
417
+ };
418
+ const onChangeAspectRatioCustom = (valueNew_, left_ = true) => {
419
+ const valueNew = !valueNew_ ? 1 : valueNew_;
420
+ let left = (aspectRatioCustom === null || aspectRatioCustom === void 0 ? void 0 : aspectRatioCustom[0]) || 1;
421
+ let right = (aspectRatioCustom === null || aspectRatioCustom === void 0 ? void 0 : aspectRatioCustom[1]) || 1;
422
+ left_ ? left = valueNew : right = valueNew;
423
+ setAspectRatioCustom([left, right]);
424
+ onChangeAspectRatio(left / right);
425
+ };
426
+ const onChangeAspectRatio = valueNew => {
427
+ if (aspectRatio === valueNew) setAspectRatio('');else setAspectRatio(valueNew);
428
+ };
429
+ const onChangeResize = async (valueNew, width_ = true) => {
430
+ let width;
431
+ let height;
432
+ if (!refs.resizeAspectRatio.current) {
433
+ if (width_) {
434
+ width = +valueNew;
435
+ height = resize === null || resize === void 0 ? void 0 : resize[1];
436
+ } else {
437
+ width = resize === null || resize === void 0 ? void 0 : resize[0];
438
+ height = +valueNew;
439
+ }
440
+ } else {
441
+ const aspectRatio_ = (value === null || value === void 0 ? void 0 : value.width) / (value === null || value === void 0 ? void 0 : value.height);
442
+ if (width_) {
443
+ width = +valueNew;
444
+ height = valueNew / aspectRatio_;
445
+ } else {
446
+ height = +valueNew;
447
+ width = height * aspectRatio_;
448
+ }
449
+ }
450
+ width = (0, _utils.clamp)(width, 0);
451
+ height = (0, _utils.clamp)(height, 0);
452
+ setResize([width, height]);
453
+ await updateResize(width, height);
454
+ };
455
+ const updateQuality = (0, _utils.debounce)(async valueNew => {
456
+ var _refs$root$current4, _refs$canvasMain$curr2;
457
+ const rootDocument = (0, _utils.isEnvironment)('browser') ? ((_refs$root$current4 = refs.root.current) === null || _refs$root$current4 === void 0 ? void 0 : _refs$root$current4.ownerDocument) || window.document : undefined;
458
+
459
+ // Update copy value
460
+ const uri = value.toDataURL('image/jpeg', valueNew / 100);
461
+ const img = await (0, _utils2.image)(uri);
462
+ const canvas = rootDocument.createElement('canvas');
463
+ canvas.width = img.width;
464
+ canvas.height = img.height;
465
+ canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);
466
+ onChangeCopy(canvas);
467
+
468
+ // Update the canvas value
469
+ refs.canvasMain.current.width = canvas.width;
470
+ refs.canvasMain.current.height = canvas.height;
471
+ (_refs$canvasMain$curr2 = refs.canvasMain.current) === null || _refs$canvasMain$curr2 === void 0 || _refs$canvasMain$curr2.getContext('2d').drawImage(canvas, 0, 0, canvas.width, canvas.height);
472
+
473
+ // Update size
474
+ updateSize();
475
+ }, 40);
476
+ const onChangeQuality = async valueNew => {
477
+ setQuality(valueNew);
478
+ await updateQuality(valueNew);
479
+ };
480
+ const onChange = valueNew => {
481
+ // Update inner or controlled
482
+ if (!props.hasOwnProperty('value')) setValue(valueNew);
483
+ if ((0, _utils.is)('function', onChange_)) onChange_(valueNew);
484
+ };
485
+ const onChangeCopy = valueNew => {
486
+ // Update inner or controlled
487
+ if (!props.hasOwnProperty('valueCopy')) setValueCopy(valueNew);
488
+ if ((0, _utils.is)('function', onChangeCopy_)) onChangeCopy_(valueNew);
489
+ };
490
+ const onReset = (imageReset = true, valueCopyReset = true, resizeReset = true) => {
491
+ var _refs$root$current5;
492
+ const rootDocument = (0, _utils.isEnvironment)('browser') ? ((_refs$root$current5 = refs.root.current) === null || _refs$root$current5 === void 0 ? void 0 : _refs$root$current5.ownerDocument) || window.document : undefined;
493
+ setOpen(false);
494
+ setQuality(100);
495
+ setAspectRatio('');
496
+ setAspectRatioCustom([1, 1]);
497
+ setSelection('');
498
+ setFilter('');
499
+ setFilterValuesCopy(_objectSpread({}, filterValues));
500
+ if (resizeReset) setResize([value === null || value === void 0 ? void 0 : value.width, value === null || value === void 0 ? void 0 : value.height]);
501
+ if (valueCopyReset) {
502
+ const canvas = rootDocument.createElement('canvas');
503
+ canvas.width = refs.value.current.width;
504
+ canvas.height = refs.value.current.height;
505
+ canvas.getContext('2d').drawImage(refs.value.current, 0, 0, refs.value.current.width, refs.value.current.height);
506
+ onChangeCopy(canvas);
507
+ }
508
+ if (imageReset) {
509
+ setFilterValues({});
510
+ setFilterValuesCopy({});
511
+ makeImage(image);
512
+ }
513
+ };
514
+ const openOption = valueNew => {
515
+ setOpenedOption(valueNew);
516
+ if (open && openedOption === valueNew) {
517
+ setOpen(false);
518
+ onReset(false);
519
+ } else if (!open) setOpen(true);
520
+ };
521
+ const onSave = () => {
522
+ var _refs$root$current6, _refs$canvasMain$curr3;
523
+ const rootDocument = (0, _utils.isEnvironment)('browser') ? ((_refs$root$current6 = refs.root.current) === null || _refs$root$current6 === void 0 ? void 0 : _refs$root$current6.ownerDocument) || window.document : undefined;
524
+
525
+ // Make value copy into value
526
+ let canvas = rootDocument.createElement('canvas');
527
+ canvas.width = refs.valueCopy.current.width;
528
+ canvas.height = refs.valueCopy.current.height;
529
+ canvas.getContext('2d').drawImage(refs.valueCopy.current, 0, 0, refs.valueCopy.current.width, refs.valueCopy.current.height);
530
+
531
+ // Update crop
532
+ if (openedOption === 'crop' && selection) {
533
+ // Crop the canvas
534
+ canvas.width = selection.width;
535
+ canvas.height = selection.height;
536
+ canvas = (0, _utils.canvasCrop)(refs.valueCopy.current, selection.left, selection.top, selection.width, selection.height);
537
+ }
538
+
539
+ // Update filters
540
+ setFilterValues(_objectSpread({}, filterValuesCopy));
541
+ applyAllFilters(canvas);
542
+
543
+ // Update the main canvas value
544
+ refs.canvasMain.current.width = canvas.width;
545
+ refs.canvasMain.current.height = canvas.height;
546
+ (_refs$canvasMain$curr3 = refs.canvasMain.current) === null || _refs$canvasMain$curr3 === void 0 || _refs$canvasMain$curr3.getContext('2d').drawImage(canvas, 0, 0, canvas.width, canvas.height);
547
+
548
+ // Update value
549
+ onChange(canvas);
550
+ const canvasCopy = rootDocument.createElement('canvas');
551
+ canvasCopy.width = canvas.width;
552
+ canvasCopy.height = canvas.height;
553
+ canvasCopy.getContext('2d').drawImage(canvas, 0, 0, canvasCopy.width, canvasCopy.height);
554
+
555
+ // Update value copy
556
+ onChangeCopy(canvasCopy);
557
+
558
+ // Reset
559
+ onReset(false, false, false);
560
+ };
561
+ const onDownload = () => {
562
+ // Download the image from canvas datauri
563
+ // of the image type and quality, name
564
+ const uri = refs.value.current.toDataURL(type);
565
+ (0, _utils.download)(name, uri, type);
566
+ };
567
+ const onCancel = () => {
568
+ var _refs$root$current7, _refs$value$current, _refs$value$current2, _refs$canvasMain$curr4;
569
+ const rootDocument = (0, _utils.isEnvironment)('browser') ? ((_refs$root$current7 = refs.root.current) === null || _refs$root$current7 === void 0 ? void 0 : _refs$root$current7.ownerDocument) || window.document : undefined;
570
+
571
+ // Reset to unopen
572
+ onReset(false);
573
+
574
+ // Make value copy into value
575
+ const canvas = rootDocument.createElement('canvas');
576
+ canvas.width = refs.value.current.width;
577
+ canvas.height = refs.value.current.height;
578
+ canvas.getContext('2d').drawImage(refs.value.current, 0, 0, refs.value.current.width, refs.value.current.height);
579
+ onChangeCopy(canvas);
580
+
581
+ // Update the main canvas value
582
+ refs.canvasMain.current.width = (_refs$value$current = refs.value.current) === null || _refs$value$current === void 0 ? void 0 : _refs$value$current.width;
583
+ refs.canvasMain.current.height = (_refs$value$current2 = refs.value.current) === null || _refs$value$current2 === void 0 ? void 0 : _refs$value$current2.height;
584
+ (_refs$canvasMain$curr4 = refs.canvasMain.current) === null || _refs$canvasMain$curr4 === void 0 || _refs$canvasMain$curr4.getContext('2d').drawImage(refs.value.current, 0, 0, refs.value.current.width, refs.value.current.height);
585
+ };
586
+ let filters = _react.default.useMemo(() => [{
587
+ label: l('Brightness'),
588
+ Icon: IconBrightness,
589
+ value: 'brightness',
590
+ method: _utils2.canvasBrightness,
591
+ renderIconButton: (value__, selected_, onChangeFilter_) => /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
592
+ key: value__,
593
+ name: l('Brightness')
594
+ }, TooltipProps), /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
595
+ version: "outlined",
596
+ selected: selected_,
597
+ onClick: () => onChangeFilter_(value__)
598
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(IconBrightness, null))),
599
+ renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => /*#__PURE__*/_react.default.createElement(Slider, (0, _extends2.default)({
600
+ key: value__,
601
+ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
602
+ value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
603
+ min: -100,
604
+ max: 100,
605
+ precision: 1,
606
+ marks: [{
607
+ value: -100,
608
+ label: '-100'
609
+ }, {
610
+ value: 0,
611
+ label: '0'
612
+ }, {
613
+ value: 100,
614
+ label: '100'
615
+ }],
616
+ labels: true,
617
+ tooltip: true,
618
+ onChange: valueNew => {
619
+ if ((0, _utils.is)('function', onFilterSliderChange_)) onFilterSliderChange_(valueNew, value__);
620
+ }
621
+ }, SliderProps, {
622
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-slider'], SliderProps.className, classes.slider])
623
+ }))
624
+ }, {
625
+ label: l('Contrast'),
626
+ Icon: IconContrast,
627
+ value: 'contrast',
628
+ method: _utils2.canvasContrast,
629
+ renderIconButton: (value__, selected_, onChangeFilter_) => /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
630
+ key: value__,
631
+ name: l('Contrast')
632
+ }, TooltipProps), /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
633
+ version: "outlined",
634
+ selected: selected_,
635
+ onClick: () => onChangeFilter_(value__)
636
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(IconContrast, null))),
637
+ renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => /*#__PURE__*/_react.default.createElement(Slider, (0, _extends2.default)({
638
+ key: value__,
639
+ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
640
+ value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
641
+ min: -100,
642
+ max: 100,
643
+ precision: 1,
644
+ marks: [{
645
+ value: -100,
646
+ label: '-100'
647
+ }, {
648
+ value: 0,
649
+ label: '0'
650
+ }, {
651
+ value: 100,
652
+ label: '100'
653
+ }],
654
+ labels: true,
655
+ tooltip: true,
656
+ onChange: valueNew => {
657
+ if ((0, _utils.is)('function', onFilterSliderChange_)) onFilterSliderChange_(valueNew, value__);
658
+ }
659
+ }, SliderProps, {
660
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-slider'], SliderProps.className, classes.slider])
661
+ }))
662
+ }, {
663
+ label: l('Saturation'),
664
+ Icon: IconSaturation,
665
+ value: 'saturation',
666
+ method: _utils2.canvasSaturation,
667
+ renderIconButton: (value__, selected_, onChangeFilter_) => /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
668
+ key: value__,
669
+ name: l('Saturation')
670
+ }, TooltipProps), /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
671
+ version: "outlined",
672
+ selected: selected_,
673
+ onClick: () => onChangeFilter_(value__)
674
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(IconSaturation, null))),
675
+ renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => /*#__PURE__*/_react.default.createElement(Slider, (0, _extends2.default)({
676
+ key: value__,
677
+ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
678
+ value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
679
+ min: -100,
680
+ max: 100,
681
+ precision: 1,
682
+ marks: [{
683
+ value: -100,
684
+ label: '-100'
685
+ }, {
686
+ value: 0,
687
+ label: '0'
688
+ }, {
689
+ value: 100,
690
+ label: '100'
691
+ }],
692
+ labels: true,
693
+ tooltip: true,
694
+ onChange: valueNew => {
695
+ if ((0, _utils.is)('function', onFilterSliderChange_)) onFilterSliderChange_(valueNew, value__);
696
+ }
697
+ }, SliderProps, {
698
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-slider'], SliderProps.className, classes.slider])
699
+ }))
700
+ }, {
701
+ label: l('Fade'),
702
+ Icon: IconFade,
703
+ value: 'fade',
704
+ method: _utils2.canvasFade,
705
+ renderIconButton: (value__, selected_, onChangeFilter_) => /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
706
+ key: value__,
707
+ name: l('Fade')
708
+ }, TooltipProps), /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
709
+ version: "outlined",
710
+ selected: selected_,
711
+ onClick: () => onChangeFilter_(value__)
712
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(IconFade, null))),
713
+ renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => /*#__PURE__*/_react.default.createElement(Slider, (0, _extends2.default)({
714
+ key: value__,
715
+ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
716
+ value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
717
+ min: 0,
718
+ max: 100,
719
+ precision: 1,
720
+ marks: [{
721
+ value: 0,
722
+ label: '0'
723
+ }, {
724
+ value: 100,
725
+ label: '100'
726
+ }],
727
+ labels: true,
728
+ tooltip: true,
729
+ onChange: valueNew => {
730
+ if ((0, _utils.is)('function', onFilterSliderChange_)) onFilterSliderChange_(valueNew, value__);
731
+ }
732
+ }, SliderProps, {
733
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-slider'], SliderProps.className, classes.slider])
734
+ }))
735
+ }, {
736
+ label: l('Invert'),
737
+ Icon: IconInvert,
738
+ value: 'invert',
739
+ method: _utils2.canvasInvert,
740
+ renderIconButton: (value__, selected_, onChangeFilter_) => /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
741
+ key: value__,
742
+ name: l('Invert')
743
+ }, TooltipProps), /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
744
+ version: "outlined",
745
+ selected: selected_,
746
+ onClick: () => onChangeFilter_(value__)
747
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(IconInvert, null))),
748
+ renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => /*#__PURE__*/_react.default.createElement(Slider, (0, _extends2.default)({
749
+ key: value__,
750
+ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
751
+ value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
752
+ min: 0,
753
+ max: 1,
754
+ precision: 1,
755
+ marks: [{
756
+ value: 0,
757
+ label: 'Not inverted'
758
+ }, {
759
+ value: 1,
760
+ label: 'Inverted'
761
+ }],
762
+ labels: true,
763
+ tooltip: true,
764
+ onChange: valueNew => {
765
+ if ((0, _utils.is)('function', onFilterSliderChange_)) onFilterSliderChange_(valueNew, value__);
766
+ }
767
+ }, SliderProps, {
768
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-slider'], SliderProps.className, classes.slider])
769
+ }))
770
+ }, {
771
+ label: l('Old photo'),
772
+ Icon: IconOldPhoto,
773
+ value: 'old_photo',
774
+ method: _utils2.canvasOldPhoto,
775
+ renderIconButton: (value__, selected_, onChangeFilter_) => /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
776
+ key: value__,
777
+ name: l('Old photo')
778
+ }, TooltipProps), /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
779
+ version: "outlined",
780
+ selected: selected_,
781
+ onClick: () => onChangeFilter_(value__)
782
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(IconOldPhoto, null))),
783
+ renderSlider: (value__, filterValuesCopy_, onFilterSliderChange_) => /*#__PURE__*/_react.default.createElement(Slider, (0, _extends2.default)({
784
+ key: value__,
785
+ valueDefault: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
786
+ value: (filterValuesCopy_ === null || filterValuesCopy_ === void 0 ? void 0 : filterValuesCopy_[value__]) || 0,
787
+ min: -40,
788
+ max: 40,
789
+ precision: 1,
790
+ marks: [{
791
+ value: -40,
792
+ label: '-40'
793
+ }, {
794
+ value: 0,
795
+ label: 'No filter'
796
+ }, {
797
+ value: 40,
798
+ label: '40'
799
+ }],
800
+ labels: true,
801
+ tooltip: true,
802
+ onChange: valueNew => {
803
+ if ((0, _utils.is)('function', onFilterSliderChange_)) onFilterSliderChange_(valueNew, value__);
804
+ }
805
+ }, SliderProps, {
806
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-slider'], SliderProps.className, classes.slider])
807
+ }))
808
+ }, ...(filters_ || [])], [filters_]);
809
+
810
+ // Only filters
811
+ if ((0, _utils.is)('array', onlyFilters)) filters = filters.filter(item => onlyFilters.includes(item.value));
812
+ const ImageCropProps = _objectSpread({
813
+ gridLines: true
814
+ }, ImageCropProps_);
815
+ const TooltipProps = _objectSpread({
816
+ position: 'bottom',
817
+ interactive: false
818
+ }, TooltipProps_);
819
+ const IconButtonProps = _objectSpread({
820
+ tonal,
821
+ color: 'inherit'
822
+ }, IconButtonProps_);
823
+ const SliderProps = _objectSpread({
824
+ tonal: false,
825
+ color: 'default'
826
+ }, SliderProps_);
827
+ const ChipProps = _objectSpread({
828
+ size: 'small'
829
+ }, ChipProps_);
830
+ const chips = [{
831
+ label: '1:1',
832
+ value: 1 / 1
833
+ }, {
834
+ label: '4:3',
835
+ value: 4 / 3
836
+ }, {
837
+ label: '16:9',
838
+ value: 16 / 9
839
+ }];
840
+ const options = [filtersOption && {
841
+ label: l('Filters'),
842
+ value: 'filters',
843
+ Icon: IconFilters
844
+ }, cropOption && {
845
+ label: l('Crop'),
846
+ value: 'crop',
847
+ Icon: IconCrop
848
+ }, resizeOption && {
849
+ label: l('Resize'),
850
+ value: 'resize',
851
+ Icon: IconResize
852
+ }, qualityOption && {
853
+ label: l('Quality'),
854
+ value: 'quality',
855
+ Icon: IconQuality
856
+ }].filter(Boolean);
857
+ const MetaTypeProps = {
858
+ version: 'b3'
859
+ };
860
+ const filterValue = filters.find(item_ => item_.value === filter);
861
+ return /*#__PURE__*/_react.default.createElement(Line, (0, _extends2.default)({
862
+ ref: item => {
863
+ if (ref) {
864
+ if ((0, _utils.is)('function', ref)) ref(item);else if (ref !== null && ref !== void 0 && ref.current) ref.current = item;
865
+ }
866
+ refs.root.current = item;
867
+ },
868
+ tonal: tonal,
869
+ color: color,
870
+ gap: 0,
871
+ direction: "column",
872
+ Component: Surface,
873
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-root', `onesy-ImageEdit-size-${size}`], className, classes.root])
874
+ }, other), /*#__PURE__*/_react.default.createElement(Line, {
875
+ gap: 0,
876
+ direction: "column",
877
+ align: "center",
878
+ justify: "center",
879
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-image-wrapper'], classes.imageWrapper])
880
+ }, /*#__PURE__*/_react.default.createElement("div", {
881
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-canvas-wrapper'], classes.canvasWrapper])
882
+ }, /*#__PURE__*/_react.default.createElement("canvas", {
883
+ ref: refs.canvasMain,
884
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-canvas', 'onesy-ImageEdit-canvas-main'], classes.canvas, classes.canvas_main])
885
+ }), open && openedOption === 'crop' && /*#__PURE__*/_react.default.createElement(ImageCrop, (0, _extends2.default)({
886
+ image: valueCopy,
887
+ aspectRatio: aspectRatio ? aspectRatio : undefined,
888
+ onSelectorChange: selector => setSelection(selector)
889
+ }, ImageCropProps, {
890
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-image-crop'], ImageCropProps.className, classes.imageCrop]),
891
+ style: {
892
+ width: valueCopy === null || valueCopy === void 0 ? void 0 : valueCopy.width,
893
+ height: valueCopy === null || valueCopy === void 0 ? void 0 : valueCopy.height
894
+ }
895
+ })))), (filtersOption || cropOption || resizeOption || qualityOption) && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(Expand, {
896
+ in: !!open,
897
+ parent: refs.root.current,
898
+ style: {
899
+ width: '100%'
900
+ }
901
+ }, /*#__PURE__*/_react.default.createElement(Line, {
902
+ gap: 0,
903
+ ref: refs.option,
904
+ direction: "column",
905
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-option'], classes.option])
906
+ }, openedOption === 'filters' && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(Expand, {
907
+ in: !!filterValue,
908
+ parent: refs.option.current,
909
+ style: {
910
+ width: '100%'
911
+ }
912
+ }, /*#__PURE__*/_react.default.createElement("div", {
913
+ style: {
914
+ paddingInline: theme.methods.space.value(5, 'px'),
915
+ paddingBottom: theme.methods.space.value(5, 'px')
916
+ }
917
+ }, (0, _utils.is)('function', filterValue === null || filterValue === void 0 ? void 0 : filterValue.renderSlider) && (filterValue === null || filterValue === void 0 ? void 0 : filterValue.renderSlider(filterValue.value, refs.filterValuesCopy.current, onFilterSliderChange)))), /*#__PURE__*/_react.default.createElement(Line, {
918
+ gap: 1,
919
+ direction: "row",
920
+ align: "center",
921
+ justify: "flex-start",
922
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-filters'], classes.filters])
923
+ }, filters.map(item => (0, _utils.is)('function', item.renderIconButton) && item.renderIconButton(item.value, item.value === filter, onChangeFilter)))), openedOption === 'crop' && /*#__PURE__*/_react.default.createElement(Line, {
924
+ gap: 1,
925
+ direction: "row",
926
+ align: "center",
927
+ justify: "center",
928
+ style: {
929
+ width: '100%'
930
+ }
931
+ }, chips.map((item, index) => /*#__PURE__*/_react.default.createElement(Chip, (0, _extends2.default)({
932
+ key: index,
933
+ selected: aspectRatio === item.value,
934
+ onClick: () => onChangeAspectRatio(item.value)
935
+ }, ChipProps), item.label)), /*#__PURE__*/_react.default.createElement(Line, {
936
+ gap: 0,
937
+ direction: "row",
938
+ align: "center",
939
+ justify: "center"
940
+ }, (0, _utils.is)('function', renderInput) ? renderInput(value, valueCopy, aspectRatioCustom, onChangeAspectRatioCustom, 'left') : /*#__PURE__*/_react.default.createElement(NumericTextField, {
941
+ tonal: tonal,
942
+ color: "default",
943
+ version: "text",
944
+ size: "small",
945
+ min: 1,
946
+ value: aspectRatioCustom === null || aspectRatioCustom === void 0 ? void 0 : aspectRatioCustom[0],
947
+ onChange: valueNew => onChangeAspectRatioCustom(+valueNew),
948
+ increment: false,
949
+ decrement: false,
950
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-option-input'], classes.optionInput]),
951
+ style: {
952
+ width: 24
953
+ }
954
+ }), /*#__PURE__*/_react.default.createElement(Type, null, ":"), (0, _utils.is)('function', renderInput) ? renderInput(value, valueCopy, aspectRatioCustom, onChangeAspectRatioCustom, 'right') : /*#__PURE__*/_react.default.createElement(NumericTextField, {
955
+ tonal: tonal,
956
+ color: "default",
957
+ version: "text",
958
+ size: "small",
959
+ min: 1,
960
+ value: aspectRatioCustom === null || aspectRatioCustom === void 0 ? void 0 : aspectRatioCustom[1],
961
+ onChange: valueNew => onChangeAspectRatioCustom(+valueNew, false),
962
+ increment: false,
963
+ decrement: false,
964
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-option-input'], classes.optionInput]),
965
+ style: {
966
+ width: 24
967
+ }
968
+ }))), openedOption === 'resize' && /*#__PURE__*/_react.default.createElement(Line, {
969
+ direction: "row",
970
+ align: "center",
971
+ justify: "center",
972
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-inputs'], classes.inputs])
973
+ }, (0, _utils.is)('function', renderInput) ? renderInput(value, valueCopy, resize, onChangeResize, 'width') : /*#__PURE__*/_react.default.createElement(NumericTextField, {
974
+ tonal: tonal,
975
+ name: l('Width'),
976
+ color: "default",
977
+ version: "text",
978
+ size: "small",
979
+ min: 1,
980
+ max: value === null || value === void 0 ? void 0 : value.width,
981
+ valueDefault: value === null || value === void 0 ? void 0 : value.width,
982
+ value: resize === null || resize === void 0 ? void 0 : resize[0],
983
+ onChange: valueNew => onChangeResize(valueNew)
984
+ }), (0, _utils.is)('function', renderInput) ? renderInput(value, valueCopy, resize, onChangeResize, 'height') : /*#__PURE__*/_react.default.createElement(NumericTextField, {
985
+ tonal: tonal,
986
+ name: l('Height'),
987
+ color: "default",
988
+ version: "text",
989
+ size: "small",
990
+ min: 1,
991
+ max: value === null || value === void 0 ? void 0 : value.height,
992
+ valueDefault: value === null || value === void 0 ? void 0 : value.height,
993
+ value: resize === null || resize === void 0 ? void 0 : resize[1],
994
+ onChange: valueNew => onChangeResize(valueNew, false)
995
+ })), openedOption === 'quality' && /*#__PURE__*/_react.default.createElement(Line, {
996
+ gap: 3,
997
+ direction: "row",
998
+ align: "center",
999
+ style: {
1000
+ width: '100%'
1001
+ }
1002
+ }, /*#__PURE__*/_react.default.createElement(Slider, (0, _extends2.default)({
1003
+ valueDefault: quality,
1004
+ value: quality,
1005
+ min: 1,
1006
+ max: 100,
1007
+ precision: 1,
1008
+ marks: [{
1009
+ value: 1
1010
+ }, {
1011
+ value: 50
1012
+ }, {
1013
+ value: 100
1014
+ }],
1015
+ tooltip: true,
1016
+ onChange: onChangeQuality
1017
+ }, SliderProps, {
1018
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-slider'], SliderProps.className, classes.slider])
1019
+ })), /*#__PURE__*/_react.default.createElement(NumericTextField, {
1020
+ tonal: tonal,
1021
+ color: "default",
1022
+ version: "text",
1023
+ size: "small",
1024
+ min: 1,
1025
+ max: 100,
1026
+ value: quality,
1027
+ increment: false,
1028
+ decrement: false,
1029
+ onChange: valueNew => onChangeQuality(+valueNew),
1030
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-option-input'], classes.optionInput]),
1031
+ style: {
1032
+ width: 34
1033
+ }
1034
+ })), /*#__PURE__*/_react.default.createElement(Line, {
1035
+ gap: 1,
1036
+ direction: "row",
1037
+ align: "center",
1038
+ justify: "center",
1039
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-action'], classes.action])
1040
+ }, (0, _utils.is)('function', renderSave) ? renderSave(onSave) : /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
1041
+ name: l('Save')
1042
+ }, TooltipProps), /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
1043
+ version: "outlined",
1044
+ onClick: onSave
1045
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(IconSave, null))), (0, _utils.is)('function', renderCancel) ? renderCancel(onSave) : /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
1046
+ name: l('Cancel')
1047
+ }, TooltipProps), /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
1048
+ version: "outlined",
1049
+ onClick: onCancel
1050
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(IconCancel, null))))), /*#__PURE__*/_react.default.createElement(Divider, {
1051
+ color: "inherit",
1052
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-divider'], classes.divider])
1053
+ })), /*#__PURE__*/_react.default.createElement(Line, {
1054
+ direction: "column",
1055
+ align: "center",
1056
+ justify: "center",
1057
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-options'], classes.options])
1058
+ }, /*#__PURE__*/_react.default.createElement(Line, {
1059
+ gap: 1,
1060
+ direction: "row",
1061
+ justify: "flex-start"
1062
+ }, options.map((item, index) => (0, _utils.is)('function', renderOption) ? renderOption(item, open && openOption === item.value, openOption) : /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
1063
+ key: index,
1064
+ name: item.label
1065
+ }, TooltipProps), /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
1066
+ version: "outlined",
1067
+ selected: open && openedOption === item.value,
1068
+ onClick: () => openOption(item.value)
1069
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(item.Icon, null)))), /*#__PURE__*/_react.default.createElement(Line, {
1070
+ gap: 0,
1071
+ direction: "row",
1072
+ align: "center"
1073
+ }, downloadOption && (0, _utils.is)('function', renderDownload) ? renderDownload(onDownload) : /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
1074
+ name: l('Download')
1075
+ }, TooltipProps), /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
1076
+ version: "text",
1077
+ onClick: onDownload
1078
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(IconDownload, null))), (0, _utils.is)('function', renderOptionClear) ? renderOptionClear(onReset) : /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
1079
+ name: l('Reset')
1080
+ }, TooltipProps), /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
1081
+ version: "text",
1082
+ onClick: onReset
1083
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(IconClear, null))))))), children, meta && value && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(Divider, {
1084
+ color: "inherit",
1085
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-divider'], classes.divider])
1086
+ }), /*#__PURE__*/_react.default.createElement(Line, {
1087
+ gap: 1,
1088
+ direction: "row",
1089
+ align: "center",
1090
+ justify: "center",
1091
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageEdit', theme) && ['onesy-ImageEdit-meta'], classes.meta])
1092
+ }, /*#__PURE__*/_react.default.createElement(Type, MetaTypeProps, l('Dimensions'), ": ", (_ref = !open ? value : valueCopy) === null || _ref === void 0 ? void 0 : _ref.width, "x", (_ref2 = !open ? value : valueCopy) === null || _ref2 === void 0 ? void 0 : _ref2.height), /*#__PURE__*/_react.default.createElement(Type, MetaTypeProps, "\xB7"), /*#__PURE__*/_react.default.createElement(Type, MetaTypeProps, l('Size'), ": ", size))));
788
1093
  });
789
1094
  ImageEdit.displayName = 'onesy-ImageEdit';
790
- exports.default = ImageEdit;
1095
+ var _default = exports.default = ImageEdit;