@onesy/ui-react 1.0.130 → 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 (444) 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/Buttons/Buttons.js +1 -1
  423. package/esm/index.js +1 -1
  424. package/index.js +4053 -660
  425. package/package.json +1 -1
  426. package/types.js +4 -1
  427. package/useForm/index.js +25 -11
  428. package/useForm/useForm.js +203 -174
  429. package/useForm/validate.js +215 -203
  430. package/useLocation/index.js +12 -7
  431. package/useLocation/useLocation.js +54 -49
  432. package/useMediaQuery/index.js +12 -7
  433. package/useMediaQuery/useMediaQuery.js +44 -43
  434. package/useQuery/index.js +12 -7
  435. package/useQuery/useQuery.js +14 -10
  436. package/useScroll/index.js +12 -7
  437. package/useScroll/useScroll.js +61 -56
  438. package/useSubscription/index.js +12 -7
  439. package/useSubscription/useSubscription.js +35 -35
  440. package/useSwipe/index.js +12 -7
  441. package/useSwipe/useSwipe.js +157 -131
  442. package/useVisible/index.js +12 -7
  443. package/useVisible/useVisible.js +86 -76
  444. package/utils.js +1224 -1362
@@ -1,549 +1,759 @@
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 IconMaterialCenterFocusWeakW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialCenterFocusWeakW100"));
22
- const Line_1 = __importDefault(require("../Line"));
23
- const Surface_1 = __importDefault(require("../Surface"));
24
- const IconButton_1 = __importDefault(require("../IconButton"));
25
- const Type_1 = __importDefault(require("../Type"));
26
- const Tooltip_1 = __importDefault(require("../Tooltip"));
27
- const Menu_1 = __importDefault(require("../Menu"));
28
- const ListItem_1 = __importDefault(require("../ListItem"));
29
- const Label_1 = __importDefault(require("../Label"));
30
- const Switch_1 = __importDefault(require("../Switch"));
31
- const utils_2 = require("../utils");
32
- const useStyle = (0, style_react_1.style)(theme => ({
33
- root: {
34
- position: 'relative',
35
- width: '100%',
36
- height: '100%',
37
- overflow: 'hidden'
38
- },
39
- container: {
40
- position: 'absolute',
41
- transformOrigin: '0 0'
42
- },
43
- miniMap: {
44
- position: 'absolute',
45
- bottom: '12px',
46
- left: '12px',
47
- borderRadius: 8,
48
- background: theme.palette.background.default.primary,
49
- border: theme.palette.light ? '' : `1px solid ${theme.palette.text.divider}`,
50
- boxShadow: theme.shadows.values.default[2],
51
- cursor: 'pointer'
52
- },
53
- miniMapMain: {
54
- position: 'absolute',
55
- inset: 0
56
- },
57
- miniMapViewport: {
58
- position: 'absolute',
59
- borderRadius: 14,
60
- border: `2px solid ${theme.palette.color.info.main}`
61
- },
62
- actions: {
63
- position: 'absolute',
64
- top: '8px',
65
- right: '8px',
66
- padding: '4px 20px',
67
- borderRadius: 140,
68
- background: theme.palette.background.default[theme.palette.light ? 'primary' : 'quaternary'],
69
- boxShadow: theme.shadows.values.default[1],
70
- overflow: 'auto hidden',
71
- zIndex: '1'
72
- },
73
- // luv you: https://stackoverflow.com/a/32861765
74
- guidelines_lines: {
75
- backgroundSize: '40px 40px',
76
- backgroundImage: `linear-gradient(to right, ${theme.palette.text.default.quaternary} 0.5px, transparent 0.5px), linear-gradient(to bottom, ${theme.palette.text.default.quaternary} 0.5px, transparent 0.5px)`
77
- },
78
- guidelines_dots: {
79
- backgroundSize: '40px 40px',
80
- backgroundImage: `radial-gradient(circle, ${theme.palette.text.default.tertiary} 0.5px, transparent 0.5px)`,
81
- backgroundPosition: `20px 20px`
82
- },
83
- move: {
84
- cursor: 'grabbing',
85
- userSelect: 'none'
86
- },
87
- zoom: {
88
- width: 40,
89
- height: 34,
90
- cursor: 'pointer',
91
- userSelect: 'none'
92
- },
93
- menu: {
94
- '& .onesy-List-root': {
95
- maxHeight: 240,
96
- overflow: 'hidden auto'
97
- }
98
- },
99
- disabled: {
100
- pointerEvents: 'none',
101
- opacity: 0.54,
102
- cursor: 'default'
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 _IconMaterialCenterFocusWeakW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialCenterFocusWeakW100"));
15
+ var _Line = _interopRequireDefault(require("../Line"));
16
+ var _Surface = _interopRequireDefault(require("../Surface"));
17
+ var _IconButton = _interopRequireDefault(require("../IconButton"));
18
+ var _Type = _interopRequireDefault(require("../Type"));
19
+ var _Tooltip = _interopRequireDefault(require("../Tooltip"));
20
+ var _Menu = _interopRequireDefault(require("../Menu"));
21
+ var _ListItem = _interopRequireDefault(require("../ListItem"));
22
+ var _Label = _interopRequireDefault(require("../Label"));
23
+ var _Switch = _interopRequireDefault(require("../Switch"));
24
+ var _utils2 = require("../utils");
25
+ const _excluded = ["size", "width", "height", "minZoom", "maxZoom", "showGuidelinesDefault", "guidelines", "pre", "post", "miniMap", "methods", "onChange", "onWheel", "onMouseDown", "onTouchStart", "noActions", "noGuideLines", "noFitCenter", "noZoomMenu", "disabled", "IconCenter", "ContainerProps", "IconButtonProps", "Component", "className", "children"];
26
+ 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; }
27
+ 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; }
28
+ const useStyle = (0, _styleReact.style)(theme => ({
29
+ root: {
30
+ position: 'relative',
31
+ width: '100%',
32
+ height: '100%',
33
+ overflow: 'hidden'
34
+ },
35
+ container: {
36
+ position: 'absolute',
37
+ transformOrigin: '0 0'
38
+ },
39
+ miniMap: {
40
+ position: 'absolute',
41
+ bottom: '12px',
42
+ left: '12px',
43
+ borderRadius: 8,
44
+ background: theme.palette.background.default.primary,
45
+ border: theme.palette.light ? '' : `1px solid ${theme.palette.text.divider}`,
46
+ boxShadow: theme.shadows.values.default[2],
47
+ cursor: 'pointer'
48
+ },
49
+ miniMapMain: {
50
+ position: 'absolute',
51
+ inset: 0
52
+ },
53
+ miniMapViewport: {
54
+ position: 'absolute',
55
+ borderRadius: 14,
56
+ border: `2px solid ${theme.palette.color.info.main}`
57
+ },
58
+ actions: {
59
+ position: 'absolute',
60
+ top: '8px',
61
+ right: '8px',
62
+ padding: '4px 20px',
63
+ borderRadius: 140,
64
+ background: theme.palette.background.default[theme.palette.light ? 'primary' : 'quaternary'],
65
+ boxShadow: theme.shadows.values.default[1],
66
+ overflow: 'auto hidden',
67
+ zIndex: '1'
68
+ },
69
+ // luv you: https://stackoverflow.com/a/32861765
70
+ guidelines_lines: {
71
+ backgroundSize: '40px 40px',
72
+ backgroundImage: `linear-gradient(to right, ${theme.palette.text.default.quaternary} 0.5px, transparent 0.5px), linear-gradient(to bottom, ${theme.palette.text.default.quaternary} 0.5px, transparent 0.5px)`
73
+ },
74
+ guidelines_dots: {
75
+ backgroundSize: '40px 40px',
76
+ backgroundImage: `radial-gradient(circle, ${theme.palette.text.default.tertiary} 0.5px, transparent 0.5px)`,
77
+ backgroundPosition: `20px 20px`
78
+ },
79
+ move: {
80
+ cursor: 'grabbing',
81
+ userSelect: 'none'
82
+ },
83
+ zoom: {
84
+ width: 40,
85
+ height: 34,
86
+ cursor: 'pointer',
87
+ userSelect: 'none'
88
+ },
89
+ menu: {
90
+ '& .onesy-List-root': {
91
+ maxHeight: 240,
92
+ overflow: 'hidden auto'
103
93
  }
104
- }), { name: 'onesy-HTMLCanvas' });
105
- const HTMLCanvas = react_1.default.forwardRef((props_, ref) => {
106
- const theme = (0, style_react_1.useOnesyTheme)();
107
- 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.onesyHTMLCanvas) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]);
108
- 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]);
109
- 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]);
110
- 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]);
111
- 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]);
112
- 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]);
113
- const Menu = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Menu) || Menu_1.default; }, [theme]);
114
- const ListItem = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.ListItem) || ListItem_1.default; }, [theme]);
115
- const Label = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Label) || Label_1.default; }, [theme]);
116
- const Switch = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Switch) || Switch_1.default; }, [theme]);
117
- const { size = 'regular', width = 240000, height = 240000, minZoom = 0.04, maxZoom = 4, showGuidelinesDefault, guidelines = 'dots', pre, post, miniMap: useMiniMap = true, methods, onChange: onChange_, onWheel: onWheel_, onMouseDown: onMouseDown_, onTouchStart: onTouchStart_, noActions, noGuideLines, noFitCenter, noZoomMenu, disabled, IconCenter = IconMaterialCenterFocusWeakW100_1.default, ContainerProps, IconButtonProps, Component = Line, className, children } = props, other = __rest(props, ["size", "width", "height", "minZoom", "maxZoom", "showGuidelinesDefault", "guidelines", "pre", "post", "miniMap", "methods", "onChange", "onWheel", "onMouseDown", "onTouchStart", "noActions", "noGuideLines", "noFitCenter", "noZoomMenu", "disabled", "IconCenter", "ContainerProps", "IconButtonProps", "Component", "className", "children"]);
118
- const { classes } = useStyle();
119
- const [positions, setPositions] = react_1.default.useState({ zoom: 1, left: 0, top: 0 });
120
- const [keyDown, setKeyDown] = react_1.default.useState();
121
- const [showGuidelines, setShowGuidelines] = react_1.default.useState(!!showGuidelinesDefault);
122
- const refs = {
123
- root: react_1.default.useRef(null),
124
- container: react_1.default.useRef(null),
125
- miniMap: react_1.default.useRef(null),
126
- minZoom: react_1.default.useRef(minZoom),
127
- maxZoom: react_1.default.useRef(maxZoom),
128
- positions: react_1.default.useRef(positions),
129
- previousMouseEvent: react_1.default.useRef(null),
130
- mouseDown: react_1.default.useRef(false),
131
- mouseDownMiniMap: react_1.default.useRef(false),
132
- keyDown: react_1.default.useRef(null),
133
- boundaries: react_1.default.useRef({ x: [width * (positions === null || positions === void 0 ? void 0 : positions.zoom) * -1, 0], y: [height * (positions === null || positions === void 0 ? void 0 : positions.zoom) * -1, 0] }),
134
- width: react_1.default.useRef(width),
135
- height: react_1.default.useRef(height),
136
- disabled: react_1.default.useRef(disabled)
94
+ },
95
+ disabled: {
96
+ pointerEvents: 'none',
97
+ opacity: 0.54,
98
+ cursor: 'default'
99
+ }
100
+ }), {
101
+ name: 'onesy-HTMLCanvas'
102
+ });
103
+ const HTMLCanvas = /*#__PURE__*/_react.default.forwardRef((props_, ref) => {
104
+ const theme = (0, _styleReact.useOnesyTheme)();
105
+ const props = _react.default.useMemo(() => {
106
+ var _theme$ui, _theme$ui2;
107
+ 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.onesyHTMLCanvas) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_);
108
+ }, [props_]);
109
+ const Line = _react.default.useMemo(() => {
110
+ var _theme$elements;
111
+ return (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Line) || _Line.default;
112
+ }, [theme]);
113
+ const Surface = _react.default.useMemo(() => {
114
+ var _theme$elements2;
115
+ return (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Surface) || _Surface.default;
116
+ }, [theme]);
117
+ const IconButton = _react.default.useMemo(() => {
118
+ var _theme$elements3;
119
+ return (theme === null || theme === void 0 || (_theme$elements3 = theme.elements) === null || _theme$elements3 === void 0 ? void 0 : _theme$elements3.IconButton) || _IconButton.default;
120
+ }, [theme]);
121
+ const Type = _react.default.useMemo(() => {
122
+ var _theme$elements4;
123
+ return (theme === null || theme === void 0 || (_theme$elements4 = theme.elements) === null || _theme$elements4 === void 0 ? void 0 : _theme$elements4.Type) || _Type.default;
124
+ }, [theme]);
125
+ const Tooltip = _react.default.useMemo(() => {
126
+ var _theme$elements5;
127
+ return (theme === null || theme === void 0 || (_theme$elements5 = theme.elements) === null || _theme$elements5 === void 0 ? void 0 : _theme$elements5.Tooltip) || _Tooltip.default;
128
+ }, [theme]);
129
+ const Menu = _react.default.useMemo(() => {
130
+ var _theme$elements6;
131
+ return (theme === null || theme === void 0 || (_theme$elements6 = theme.elements) === null || _theme$elements6 === void 0 ? void 0 : _theme$elements6.Menu) || _Menu.default;
132
+ }, [theme]);
133
+ const ListItem = _react.default.useMemo(() => {
134
+ var _theme$elements7;
135
+ return (theme === null || theme === void 0 || (_theme$elements7 = theme.elements) === null || _theme$elements7 === void 0 ? void 0 : _theme$elements7.ListItem) || _ListItem.default;
136
+ }, [theme]);
137
+ const Label = _react.default.useMemo(() => {
138
+ var _theme$elements8;
139
+ return (theme === null || theme === void 0 || (_theme$elements8 = theme.elements) === null || _theme$elements8 === void 0 ? void 0 : _theme$elements8.Label) || _Label.default;
140
+ }, [theme]);
141
+ const Switch = _react.default.useMemo(() => {
142
+ var _theme$elements9;
143
+ return (theme === null || theme === void 0 || (_theme$elements9 = theme.elements) === null || _theme$elements9 === void 0 ? void 0 : _theme$elements9.Switch) || _Switch.default;
144
+ }, [theme]);
145
+ const {
146
+ size = 'regular',
147
+ width = 240000,
148
+ height = 240000,
149
+ minZoom = 0.04,
150
+ maxZoom = 4,
151
+ showGuidelinesDefault,
152
+ guidelines = 'dots',
153
+ pre,
154
+ post,
155
+ miniMap: useMiniMap = true,
156
+ methods,
157
+ onChange: onChange_,
158
+ onWheel: onWheel_,
159
+ onMouseDown: onMouseDown_,
160
+ onTouchStart: onTouchStart_,
161
+ noActions,
162
+ noGuideLines,
163
+ noFitCenter,
164
+ noZoomMenu,
165
+ disabled,
166
+ IconCenter = _IconMaterialCenterFocusWeakW.default,
167
+ ContainerProps,
168
+ IconButtonProps,
169
+ Component = Line,
170
+ className,
171
+ children
172
+ } = props,
173
+ other = (0, _objectWithoutProperties2.default)(props, _excluded);
174
+ const {
175
+ classes
176
+ } = useStyle();
177
+ const [positions, setPositions] = _react.default.useState({
178
+ zoom: 1,
179
+ left: 0,
180
+ top: 0
181
+ });
182
+ const [keyDown, setKeyDown] = _react.default.useState();
183
+ const [showGuidelines, setShowGuidelines] = _react.default.useState(!!showGuidelinesDefault);
184
+ const refs = {
185
+ root: _react.default.useRef(null),
186
+ container: _react.default.useRef(null),
187
+ miniMap: _react.default.useRef(null),
188
+ minZoom: _react.default.useRef(minZoom),
189
+ maxZoom: _react.default.useRef(maxZoom),
190
+ positions: _react.default.useRef(positions),
191
+ previousMouseEvent: _react.default.useRef(null),
192
+ mouseDown: _react.default.useRef(false),
193
+ mouseDownMiniMap: _react.default.useRef(false),
194
+ keyDown: _react.default.useRef(null),
195
+ boundaries: _react.default.useRef({
196
+ x: [width * (positions === null || positions === void 0 ? void 0 : positions.zoom) * -1, 0],
197
+ y: [height * (positions === null || positions === void 0 ? void 0 : positions.zoom) * -1, 0]
198
+ }),
199
+ width: _react.default.useRef(width),
200
+ height: _react.default.useRef(height),
201
+ disabled: _react.default.useRef(disabled)
202
+ };
203
+ refs.positions.current = positions;
204
+ refs.minZoom.current = minZoom;
205
+ refs.maxZoom.current = maxZoom;
206
+ refs.keyDown.current = keyDown;
207
+ refs.width.current = width;
208
+ refs.height.current = height;
209
+ refs.disabled.current = disabled;
210
+ _react.default.useEffect(() => {
211
+ if ((0, _utils.is)('object', methods)) {
212
+ methods.updatePositions = updatePositions;
213
+ }
214
+ }, [methods]);
215
+ const onChange = _react.default.useCallback(valueNew => {
216
+ const root = refs.root.current;
217
+ const values = _objectSpread(_objectSpread(_objectSpread({}, refs.positions.current), valueNew), {}, {
218
+ root: {
219
+ width: root.clientWidth,
220
+ height: root.clientHeight
221
+ },
222
+ boundaries: refs.boundaries.current
223
+ });
224
+ if ((0, _utils.is)('function', onChange_)) onChange_(values);
225
+ }, [onChange_]);
226
+ const updateBoundaries = _react.default.useCallback((valueZoom = (_refs$positions$curre => (_refs$positions$curre = refs.positions.current) === null || _refs$positions$curre === void 0 ? void 0 : _refs$positions$curre.zoom)()) => {
227
+ const root = refs.root.current;
228
+ const rootRect = root.getBoundingClientRect();
229
+ refs.boundaries.current = {
230
+ x: [refs.width.current * valueZoom * -1 + rootRect.width, 0],
231
+ y: [refs.height.current * valueZoom * -1 + rootRect.height, 0]
137
232
  };
138
- refs.positions.current = positions;
139
- refs.minZoom.current = minZoom;
140
- refs.maxZoom.current = maxZoom;
141
- refs.keyDown.current = keyDown;
142
- refs.width.current = width;
143
- refs.height.current = height;
144
- refs.disabled.current = disabled;
145
- react_1.default.useEffect(() => {
146
- if ((0, utils_1.is)('object', methods)) {
147
- methods.updatePositions = updatePositions;
148
- }
149
- }, [methods]);
150
- const onChange = react_1.default.useCallback((valueNew) => {
151
- const root = refs.root.current;
152
- const values = Object.assign(Object.assign(Object.assign({}, refs.positions.current), valueNew), { root: {
153
- width: root.clientWidth,
154
- height: root.clientHeight
155
- }, boundaries: refs.boundaries.current });
156
- if ((0, utils_1.is)('function', onChange_))
157
- onChange_(values);
158
- }, [onChange_]);
159
- const updateBoundaries = react_1.default.useCallback((valueZoom) => {
160
- var _a;
161
- if (valueZoom === void 0) { valueZoom = (_a = refs.positions.current) === null || _a === void 0 ? void 0 : _a.zoom; }
162
- const root = refs.root.current;
163
- const rootRect = root.getBoundingClientRect();
164
- refs.boundaries.current = {
165
- x: [(refs.width.current * valueZoom * -1) + rootRect.width, 0],
166
- y: [(refs.height.current * valueZoom * -1) + rootRect.height, 0]
167
- };
168
- }, []);
169
- react_1.default.useEffect(() => {
170
- // update boundaries
171
- updateBoundaries();
172
- }, [width, height, positions]);
173
- const updatePositions = react_1.default.useCallback((valueNew) => {
174
- valueNew.zoom = (0, utils_1.clamp)(valueNew.zoom, refs.minZoom.current, refs.maxZoom.current);
175
- valueNew.top = (0, utils_1.clamp)(valueNew.top, ...refs.boundaries.current.y);
176
- valueNew.left = (0, utils_1.clamp)(valueNew.left, ...refs.boundaries.current.x);
177
- refs.container.current.style.transform = `matrix(${valueNew.zoom}, 0, 0, ${valueNew.zoom}, ${valueNew.left}, ${valueNew.top})`;
178
- setPositions(valueNew);
179
- onChange(valueNew);
180
- }, []);
181
- const update = react_1.default.useCallback((values, event) => {
182
- const root = refs.root.current;
183
- const container = refs.container.current;
184
- const rootRect = root.getBoundingClientRect();
185
- const transform = window.getComputedStyle(container).transform;
186
- const matrix = new DOMMatrixReadOnly(transform);
187
- let left = matrix.e || 0;
188
- let top = matrix.f || 0;
189
- let zoom_ = matrix.a || 1;
190
- const { x = event ? event.clientX - rootRect.x : rootRect.width / 2, y = event ? event.clientY - rootRect.y : rootRect.height / 2 } = values;
191
- if (values.zoom !== undefined) {
192
- zoom_ = (0, utils_1.clamp)(values.zoom, refs.minZoom.current, refs.maxZoom.current);
193
- // update boundaries
194
- updateBoundaries(zoom_);
195
- // left, top
196
- const zoomDelta = zoom_ / matrix.a;
197
- left = values.left !== undefined ? values.left : x - ((left >= 0 ? left - x : x - left) * zoomDelta);
198
- top = values.top !== undefined ? values.top : y - ((top >= 0 ? top - y : y - top) * zoomDelta);
199
- }
200
- else {
201
- if (values.top !== undefined) {
202
- top = values.top;
203
- }
204
- if (values.left !== undefined) {
205
- left = values.left;
206
- }
207
- }
208
- // update
209
- updatePositions({ zoom: zoom_, left, top });
210
- }, []);
211
- const zoom = react_1.default.useCallback((value = 1, event) => {
212
- update({ zoom: value });
213
- }, []);
214
- const onCenter = react_1.default.useCallback(() => {
215
- const root = refs.root.current;
216
- const container = refs.container.current;
217
- const rootRect = root.getBoundingClientRect();
218
- const items = Array.from(container.children);
219
- // container
220
- // reset
221
- container.style.transform = `matrix(1, 0, 0, 1, 0, 0)`;
222
- const values = {
223
- top: Number.MAX_SAFE_INTEGER,
224
- left: Number.MAX_SAFE_INTEGER,
225
- width: 0,
226
- height: 0
227
- };
228
- // left, top
229
- items.forEach((item) => {
230
- const itemRect = item.getBoundingClientRect();
231
- item.rect = itemRect;
232
- values.top = Math.min(values.top, itemRect.top - rootRect.top);
233
- values.left = Math.min(values.left, itemRect.left - rootRect.left);
234
- });
235
- // width, height
236
- items.forEach((item) => {
237
- const itemRect = item.rect;
238
- const top_ = itemRect.top - rootRect.top;
239
- const left_ = itemRect.left - rootRect.left;
240
- const right = left_ + itemRect.width;
241
- const bottom = top_ + itemRect.height;
242
- values.width = Math.max(values.width, Math.abs(right) - Math.abs(values.left));
243
- values.height = Math.max(values.height, Math.abs(bottom) - Math.abs(values.top));
244
- });
245
- if (!items.length) {
246
- values.top = container.clientHeight / 2;
247
- values.left = container.clientWidth / 2;
248
- values.width = values.height = 0;
249
- }
250
- const top = (values.top + (values.height / 2) - (rootRect.height / 2)) * -1;
251
- const left = (values.left + (values.width / 2) - (rootRect.width / 2)) * -1;
252
- const zoomPadding = 0.94;
253
- let zoom_ = Math.min((0, utils_1.clamp)(rootRect.width / values.width, 0, 4) * zoomPadding, (0, utils_1.clamp)(rootRect.height / values.height, 0, 4) * zoomPadding);
254
- if (!items.length || items.length === 1)
255
- zoom_ = 1;
256
- // update
257
- // top, left
258
- update({ zoom: 1, top, left });
259
- // update
260
- // zoom
261
- if (zoom_ !== 1)
262
- update({ zoom: zoom_ });
263
- }, []);
264
- const init = react_1.default.useCallback(() => {
265
- // initially
266
- // center
267
- onCenter();
268
- }, []);
269
- const onWheel = react_1.default.useCallback((event) => {
270
- var _a;
271
- if (event.target === refs.root.current || ((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.contains(event.target))) {
272
- const positions_ = refs.positions.current;
273
- const root = refs.root.current;
274
- const rootRect = root.getBoundingClientRect();
275
- const x = event.clientX - rootRect.x;
276
- const y = event.clientY - rootRect.y;
277
- const meta = event.ctrlKey || event.metaKey;
278
- // zoom
279
- if (event.deltaY !== 0 && meta) {
280
- const delta = event.deltaY * -0.0024;
281
- const value = positions_.zoom + delta;
282
- update({ zoom: value, x, y, delta }, event);
283
- event.preventDefault();
284
- }
285
- // move
286
- else if (!meta) {
287
- // vertical
288
- if (event.deltaY !== 0) {
289
- const value = positions_.top + event.deltaY * -1;
290
- update({ top: value, x, y });
291
- }
292
- // horizontal
293
- if (event.deltaX !== 0) {
294
- const value = positions_.left + event.deltaX * -1;
295
- update({ left: value, x, y });
296
- }
297
- event.preventDefault();
298
- }
299
- }
300
- }, []);
301
- const onKeyUp = react_1.default.useCallback(() => {
302
- setKeyDown(null);
303
- }, []);
304
- const onKeyDown = react_1.default.useCallback((event) => {
305
- if (event.key === ' ')
306
- setKeyDown(event.key);
307
- }, []);
308
- const onMouseUp = react_1.default.useCallback(() => {
309
- refs.mouseDown.current = false;
310
- refs.mouseDownMiniMap.current = false;
311
- refs.previousMouseEvent.current = undefined;
312
- }, []);
313
- const onMouseDown = react_1.default.useCallback((event) => {
314
- refs.mouseDown.current = true;
315
- if ((0, utils_1.is)('function', onMouseDown_))
316
- onMouseDown_(event);
317
- }, [onMouseDown_]);
318
- const onTouchStart = react_1.default.useCallback((event) => {
319
- refs.mouseDown.current = true;
320
- if ((0, utils_1.is)('function', onTouchStart_))
321
- onTouchStart_(event);
322
- }, [onTouchStart_]);
323
- const onMouseDownMiniMap = react_1.default.useCallback((event) => {
324
- refs.mouseDownMiniMap.current = true;
325
- }, []);
326
- const onTouchStartMiniMap = react_1.default.useCallback((event) => {
327
- refs.mouseDownMiniMap.current = true;
328
- }, []);
329
- const onMoveMiniMap = react_1.default.useCallback((x_, y_, event) => {
330
- if (refs.mouseDownMiniMap.current && refs.previousMouseEvent.current && !refs.disabled.current) {
331
- const positions_ = refs.positions.current;
332
- const root = refs.root.current;
333
- const container = refs.container.current;
334
- const miniMap_ = refs.miniMap.current;
335
- const rectMiniMap = miniMap_.getBoundingClientRect();
336
- const ratios = {
337
- containerMiniMap: container.clientWidth / 170,
338
- rootContainer: root.clientWidth / container.clientWidth
339
- };
340
- const zoomAdjusted = 1 / positions_.zoom;
341
- const x = (event.clientX - rectMiniMap.x) * ratios.containerMiniMap / zoomAdjusted;
342
- const y = (event.clientY - rectMiniMap.y) * ratios.containerMiniMap / zoomAdjusted;
343
- const left = (x * -1) + (root.clientWidth / 2);
344
- const top = (y * -1) + (root.clientHeight / 2);
345
- update({ left, top });
346
- }
347
- }, []);
348
- const onMove = react_1.default.useCallback((x_, y_, event) => {
349
- if (refs.keyDown.current === ' ' && refs.mouseDown.current && refs.previousMouseEvent.current && !refs.disabled.current) {
350
- const { clientX: xPrevious, clientY: yPrevious } = refs.previousMouseEvent.current;
351
- const positions_ = refs.positions.current;
352
- const x = x_ - xPrevious;
353
- const y = y_ - yPrevious;
354
- const left = x + positions_.left;
355
- const top = y + positions_.top;
356
- update({ left, top });
357
- }
358
- }, []);
359
- const onMouseMove = react_1.default.useCallback((event) => {
360
- if ((refs.mouseDown.current || refs.mouseDownMiniMap.current) && !refs.disabled.current) {
361
- const { clientY, clientX } = event;
362
- if (refs.mouseDownMiniMap.current)
363
- onMoveMiniMap(clientX, clientY, event);
364
- else if (refs.mouseDown.current)
365
- onMove(clientX, clientY, event);
366
- refs.previousMouseEvent.current = event;
233
+ }, []);
234
+ _react.default.useEffect(() => {
235
+ // update boundaries
236
+ updateBoundaries();
237
+ }, [width, height, positions]);
238
+ const updatePositions = _react.default.useCallback(valueNew => {
239
+ valueNew.zoom = (0, _utils.clamp)(valueNew.zoom, refs.minZoom.current, refs.maxZoom.current);
240
+ valueNew.top = (0, _utils.clamp)(valueNew.top, ...refs.boundaries.current.y);
241
+ valueNew.left = (0, _utils.clamp)(valueNew.left, ...refs.boundaries.current.x);
242
+ refs.container.current.style.transform = `matrix(${valueNew.zoom}, 0, 0, ${valueNew.zoom}, ${valueNew.left}, ${valueNew.top})`;
243
+ setPositions(valueNew);
244
+ onChange(valueNew);
245
+ }, []);
246
+ const update = _react.default.useCallback((values, event) => {
247
+ const root = refs.root.current;
248
+ const container = refs.container.current;
249
+ const rootRect = root.getBoundingClientRect();
250
+ const transform = window.getComputedStyle(container).transform;
251
+ const matrix = new DOMMatrixReadOnly(transform);
252
+ let left = matrix.e || 0;
253
+ let top = matrix.f || 0;
254
+ let zoom_ = matrix.a || 1;
255
+ const {
256
+ x = event ? event.clientX - rootRect.x : rootRect.width / 2,
257
+ y = event ? event.clientY - rootRect.y : rootRect.height / 2
258
+ } = values;
259
+ if (values.zoom !== undefined) {
260
+ zoom_ = (0, _utils.clamp)(values.zoom, refs.minZoom.current, refs.maxZoom.current);
261
+
262
+ // update boundaries
263
+ updateBoundaries(zoom_);
264
+
265
+ // left, top
266
+ const zoomDelta = zoom_ / matrix.a;
267
+ left = values.left !== undefined ? values.left : x - (left >= 0 ? left - x : x - left) * zoomDelta;
268
+ top = values.top !== undefined ? values.top : y - (top >= 0 ? top - y : y - top) * zoomDelta;
269
+ } else {
270
+ if (values.top !== undefined) {
271
+ top = values.top;
272
+ }
273
+ if (values.left !== undefined) {
274
+ left = values.left;
275
+ }
276
+ }
277
+
278
+ // update
279
+ updatePositions({
280
+ zoom: zoom_,
281
+ left,
282
+ top
283
+ });
284
+ }, []);
285
+ const zoom = _react.default.useCallback((value = 1, event) => {
286
+ update({
287
+ zoom: value
288
+ });
289
+ }, []);
290
+ const onCenter = _react.default.useCallback(() => {
291
+ const root = refs.root.current;
292
+ const container = refs.container.current;
293
+ const rootRect = root.getBoundingClientRect();
294
+ const items = Array.from(container.children);
295
+
296
+ // container
297
+ // reset
298
+ container.style.transform = `matrix(1, 0, 0, 1, 0, 0)`;
299
+ const values = {
300
+ top: Number.MAX_SAFE_INTEGER,
301
+ left: Number.MAX_SAFE_INTEGER,
302
+ width: 0,
303
+ height: 0
304
+ };
305
+
306
+ // left, top
307
+ items.forEach(item => {
308
+ const itemRect = item.getBoundingClientRect();
309
+ item.rect = itemRect;
310
+ values.top = Math.min(values.top, itemRect.top - rootRect.top);
311
+ values.left = Math.min(values.left, itemRect.left - rootRect.left);
312
+ });
313
+
314
+ // width, height
315
+ items.forEach(item => {
316
+ const itemRect = item.rect;
317
+ const top_ = itemRect.top - rootRect.top;
318
+ const left_ = itemRect.left - rootRect.left;
319
+ const right = left_ + itemRect.width;
320
+ const bottom = top_ + itemRect.height;
321
+ values.width = Math.max(values.width, Math.abs(right) - Math.abs(values.left));
322
+ values.height = Math.max(values.height, Math.abs(bottom) - Math.abs(values.top));
323
+ });
324
+ if (!items.length) {
325
+ values.top = container.clientHeight / 2;
326
+ values.left = container.clientWidth / 2;
327
+ values.width = values.height = 0;
328
+ }
329
+ const top = (values.top + values.height / 2 - rootRect.height / 2) * -1;
330
+ const left = (values.left + values.width / 2 - rootRect.width / 2) * -1;
331
+ const zoomPadding = 0.94;
332
+ let zoom_ = Math.min((0, _utils.clamp)(rootRect.width / values.width, 0, 4) * zoomPadding, (0, _utils.clamp)(rootRect.height / values.height, 0, 4) * zoomPadding);
333
+ if (!items.length || items.length === 1) zoom_ = 1;
334
+
335
+ // update
336
+ // top, left
337
+ update({
338
+ zoom: 1,
339
+ top,
340
+ left
341
+ });
342
+
343
+ // update
344
+ // zoom
345
+ if (zoom_ !== 1) update({
346
+ zoom: zoom_
347
+ });
348
+ }, []);
349
+ const init = _react.default.useCallback(() => {
350
+ // initially
351
+ // center
352
+ onCenter();
353
+ }, []);
354
+ const onWheel = _react.default.useCallback(event => {
355
+ var _refs$root$current;
356
+ if (event.target === refs.root.current || (_refs$root$current = refs.root.current) !== null && _refs$root$current !== void 0 && _refs$root$current.contains(event.target)) {
357
+ const positions_ = refs.positions.current;
358
+ const root = refs.root.current;
359
+ const rootRect = root.getBoundingClientRect();
360
+ const x = event.clientX - rootRect.x;
361
+ const y = event.clientY - rootRect.y;
362
+ const meta = event.ctrlKey || event.metaKey;
363
+
364
+ // zoom
365
+ if (event.deltaY !== 0 && meta) {
366
+ const delta = event.deltaY * -0.0024;
367
+ const value = positions_.zoom + delta;
368
+ update({
369
+ zoom: value,
370
+ x,
371
+ y,
372
+ delta
373
+ }, event);
374
+ event.preventDefault();
375
+ }
376
+ // move
377
+ else if (!meta) {
378
+ // vertical
379
+ if (event.deltaY !== 0) {
380
+ const value = positions_.top + event.deltaY * -1;
381
+ update({
382
+ top: value,
383
+ x,
384
+ y
385
+ });
367
386
  }
368
- }, []);
369
- const onTouchMove = react_1.default.useCallback((event) => {
370
- if ((refs.mouseDown.current || refs.mouseDownMiniMap.current) && !refs.disabled.current) {
371
- const { clientY, clientX } = event.touches[0];
372
- if (refs.mouseDownMiniMap.current)
373
- onMoveMiniMap(clientX, clientY, event);
374
- else if (refs.mouseDown.current)
375
- onMove(clientX, clientY, event);
376
- refs.previousMouseEvent.current = event;
377
- // Normalize for use as a mouseDown value
378
- refs.previousMouseEvent.current.clientY = clientY;
379
- refs.previousMouseEvent.current.clientX = clientX;
387
+
388
+ // horizontal
389
+ if (event.deltaX !== 0) {
390
+ const value = positions_.left + event.deltaX * -1;
391
+ update({
392
+ left: value,
393
+ x,
394
+ y
395
+ });
380
396
  }
381
- }, []);
382
- react_1.default.useEffect(() => {
383
- var _a;
384
- // init
385
- init();
386
- const rootDocument = (0, utils_1.isEnvironment)('browser') ? (((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) || window.document) : undefined;
387
- window.addEventListener('wheel', onWheel, { passive: false });
388
- rootDocument.addEventListener('keyup', onKeyUp);
389
- rootDocument.addEventListener('keydown', onKeyDown);
390
- rootDocument.addEventListener('mousemove', onMouseMove);
391
- rootDocument.addEventListener('touchmove', onTouchMove, { passive: true });
392
- rootDocument.addEventListener('mouseup', onMouseUp);
393
- rootDocument.addEventListener('touchend', onMouseUp);
394
- return () => {
395
- window.removeEventListener('wheel', onWheel);
396
- rootDocument.removeEventListener('keyup', onKeyUp);
397
- rootDocument.removeEventListener('keydown', onKeyDown);
398
- rootDocument.removeEventListener('mousemove', onMouseMove);
399
- rootDocument.removeEventListener('touchmove', onTouchMove);
400
- rootDocument.removeEventListener('mouseup', onMouseUp);
401
- rootDocument.removeEventListener('touchend', onMouseUp);
402
- };
403
- }, []);
404
- const onShowGuidelines = react_1.default.useCallback((valueNew) => {
405
- setShowGuidelines(valueNew);
406
- }, []);
407
- const zoomOptions = react_1.default.useMemo(() => {
408
- return [
409
- { name: 'Zoom to fit', props: { onClick: (event) => onCenter() } },
410
- { name: 'Zoom to 25%', value: 0.25, props: { onClick: (event) => zoom(0.25, event) } },
411
- { name: 'Zoom to 50%', value: 0.5, props: { onClick: (event) => zoom(0.5, event) } },
412
- { name: 'Zoom to 75%', value: 0.75, props: { onClick: (event) => zoom(0.75, event) } },
413
- { name: 'Zoom to 100%', value: 1, props: { onClick: (event) => zoom(1, event) } },
414
- { name: 'Zoom to 125%', value: 1.25, props: { onClick: (event) => zoom(1.25, event) } },
415
- { name: 'Zoom to 150%', value: 1.5, props: { onClick: (event) => zoom(1.5, event) } },
416
- { name: 'Zoom to 175%', value: 1.75, props: { onClick: (event) => zoom(1.75, event) } },
417
- { name: 'Zoom to 200%', value: 2, props: { onClick: (event) => zoom(2, event) } },
418
- { name: 'Zoom to 400%', value: 4, props: { onClick: (event) => zoom(4, event) } }
419
- ];
420
- }, []);
421
- const miniMap = react_1.default.useMemo(() => {
422
- const root = refs.root.current;
423
- const container = refs.container.current;
424
- if (!container)
425
- return null;
426
- const zoomAdjusted = 1 / positions.zoom;
427
- const ratios = {
428
- root: root.clientWidth / root.clientHeight,
429
- container: container.clientWidth / container.clientHeight,
430
- rootContainer: root.clientWidth / container.clientWidth
431
- };
432
- const width_ = 170;
433
- const height_ = 170 / ratios.container;
434
- const zoomPerSize = container.clientWidth / width_;
435
- const viewportStyles = {
436
- width: (width_ * ratios.rootContainer) * zoomAdjusted,
437
- height: ((width_ / ratios.root) * ratios.rootContainer) * zoomAdjusted
438
- };
439
- viewportStyles.left = (Math.abs(positions.left) / zoomPerSize) * zoomAdjusted;
440
- viewportStyles.top = (Math.abs(positions.top) / zoomPerSize) * zoomAdjusted;
441
- return ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ ref: refs.miniMap, onMouseDown: onMouseDownMiniMap, onTouchStart: onTouchStartMiniMap, className: (0, style_react_1.classNames)([
442
- classes.miniMap
443
- ]), style: {
444
- width: width_,
445
- height: height_
446
- } }, { children: [(0, jsx_runtime_1.jsx)(Line, { className: classes.miniMapMain }), (0, jsx_runtime_1.jsx)(Line, { className: classes.miniMapViewport, style: Object.assign({}, viewportStyles) })] })));
447
- }, [positions, onMouseDownMiniMap, onTouchStartMiniMap]);
448
- const updateMiniMap = react_1.default.useCallback((0, utils_1.debounce)(() => {
449
- const root = refs.root.current;
450
- const container = refs.container.current;
451
- const miniMap_ = refs.miniMap.current;
452
- if (!miniMap_)
453
- return;
454
- const itemsContainer = Array.from(container.children);
455
- const itemsContainerMap = {};
456
- itemsContainer.forEach(element => {
457
- itemsContainerMap[element.dataset.id] = element;
458
- });
459
- const miniMapItems = miniMap_.children[0];
460
- const itemsMiniMapItems = Array.from(miniMapItems.children);
461
- const itemsMiniMapItemsMap = {};
462
- itemsMiniMapItems.forEach(element => {
463
- itemsMiniMapItemsMap[element.dataset.id] = element;
464
- });
465
- const ratios = {
466
- root: root.clientWidth / root.clientHeight,
467
- container: container.clientWidth / container.clientHeight,
468
- contanerMiniMap: 170 / container.clientWidth
469
- };
470
- const updateItemCopy = (item) => {
471
- const left = +item.style.left.replace('px', '');
472
- const top = +item.style.top.replace('px', '');
473
- const width_ = +item.style.width.replace('px', '');
474
- const height_ = +item.style.height.replace('px', '');
475
- item.style.width = `${width_ * ratios.contanerMiniMap}px`;
476
- item.style.height = `${height_ * ratios.contanerMiniMap}px`;
477
- item.style.left = `${left * ratios.contanerMiniMap}px`;
478
- item.style.top = `${top * ratios.contanerMiniMap}px`;
479
- };
480
- itemsContainer.forEach(item => {
481
- const id = item.dataset.id;
482
- const itemCopy = item.cloneNode();
483
- updateItemCopy(itemCopy);
484
- // add
485
- if (!itemsMiniMapItemsMap[id]) {
486
- miniMapItems.append(itemCopy);
487
- }
488
- // update
489
- else {
490
- const itemExisting = itemsMiniMapItemsMap[id];
491
- itemExisting.style.left = itemCopy.style.left;
492
- itemExisting.style.top = itemCopy.style.top;
493
- itemExisting.style.width = itemCopy.style.width;
494
- itemExisting.style.height = itemCopy.style.height;
495
- }
496
- });
497
- itemsMiniMapItems.forEach(item => {
498
- const id = item.dataset.id;
499
- // remove
500
- if (!itemsContainerMap[id]) {
501
- item.remove();
502
- }
503
- });
504
- }, 440), []);
505
- react_1.default.useEffect(() => {
506
- // update
507
- // mini map
508
- if (useMiniMap)
509
- updateMiniMap();
510
- }, [children, useMiniMap]);
511
- return ((0, jsx_runtime_1.jsxs)(Surface, Object.assign({ ref: (item) => {
512
- if (ref) {
513
- if ((0, utils_1.is)('function', ref))
514
- ref(item);
515
- ref.current = item;
516
- }
517
- refs.root.current = item;
518
- }, color: 'default', gap: 0, align: 'unset', justify: 'unset', flex: true, fullWidth: true, onMouseDown: onMouseDown, onTouchStart: onTouchStart, Component: Component, className: (0, style_react_1.classNames)([
519
- (0, utils_2.staticClassName)('HTMLCanvas', theme) && [
520
- 'onesy-HTMLCanvas-root'
521
- ],
522
- className,
523
- classes.root,
524
- keyDown === ' ' && classes.move,
525
- disabled && classes.disabled
526
- ]) }, other, { children: [pre, !noActions && ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 0.5, direction: 'row', align: 'center', justify: 'flex-start', className: (0, style_react_1.classNames)([
527
- (0, utils_2.staticClassName)('HTMLCanvas', theme) && [
528
- 'onesy-HTMLCanvas-actions'
529
- ],
530
- classes.actions
531
- ]) }, { children: [!noGuideLines && ((0, jsx_runtime_1.jsxs)(Label, Object.assign({ value: showGuidelines, onChange: onShowGuidelines, size: 'small' }, { children: [(0, jsx_runtime_1.jsx)(Switch, {}), "Guidelines"] }))), !noFitCenter && ((0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 1, direction: 'row', align: 'center', justify: 'flex-end' }, { children: (0, jsx_runtime_1.jsx)(Tooltip, Object.assign({ name: 'Fit' }, { children: (0, jsx_runtime_1.jsx)(IconButton, Object.assign({ size: size, onClick: onCenter }, IconButtonProps, { children: (0, jsx_runtime_1.jsx)(IconCenter, {}) })) })) }))), !noZoomMenu && ((0, jsx_runtime_1.jsx)(Menu, Object.assign({ menuItems: zoomOptions.map((item, index) => ((0, jsx_runtime_1.jsx)(ListItem, Object.assign({ primary: ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3' }, { children: item.name }))), value: item.name, selected: +(positions.zoom).toFixed(2) === +(item.value || 0).toFixed(2) }, item.props, { size: 'small', button: true }), item.name))), className: classes.menu }, { children: (0, jsx_runtime_1.jsx)(Line, Object.assign({ align: 'center', justify: 'center', className: classes.zoom }, { children: (0, jsx_runtime_1.jsxs)(Type, Object.assign({ version: size === 'large' ? 'b2' : size === 'regular' ? 'b3' : 'b3', align: 'center', whiteSpace: 'nowrap', fullWidth: true }, { children: [(positions.zoom * 100).toFixed(0), "%"] })) })) })))] }))), (0, jsx_runtime_1.jsx)(Line, Object.assign({}, ContainerProps, { ref: (item) => {
532
- if (ContainerProps === null || ContainerProps === void 0 ? void 0 : ContainerProps.ref) {
533
- if ((0, utils_1.is)('function', ContainerProps === null || ContainerProps === void 0 ? void 0 : ContainerProps.ref))
534
- ContainerProps.ref(item);
535
- ContainerProps.ref.current = item;
536
- }
537
- refs.container.current = item;
538
- }, gap: 0, align: 'unset', justify: 'unset', flex: true, fullWidth: true, className: (0, style_react_1.classNames)([
539
- (0, utils_2.staticClassName)('HTMLCanvas', theme) && [
540
- 'onesy-HTMLCanvas-container'
541
- ],
542
- ContainerProps === null || ContainerProps === void 0 ? void 0 : ContainerProps.className,
543
- classes.container,
544
- showGuidelines && guidelines && classes[`guidelines_${[true, 'dots'].includes(guidelines) ? 'dots' : 'lines'}`]
545
- ]), style: Object.assign({ width,
546
- height }, ContainerProps === null || ContainerProps === void 0 ? void 0 : ContainerProps.style) }, { children: children })), useMiniMap && miniMap, post] })));
397
+ event.preventDefault();
398
+ }
399
+ }
400
+ }, []);
401
+ const onKeyUp = _react.default.useCallback(() => {
402
+ setKeyDown(null);
403
+ }, []);
404
+ const onKeyDown = _react.default.useCallback(event => {
405
+ if (event.key === ' ') setKeyDown(event.key);
406
+ }, []);
407
+ const onMouseUp = _react.default.useCallback(() => {
408
+ refs.mouseDown.current = false;
409
+ refs.mouseDownMiniMap.current = false;
410
+ refs.previousMouseEvent.current = undefined;
411
+ }, []);
412
+ const onMouseDown = _react.default.useCallback(event => {
413
+ refs.mouseDown.current = true;
414
+ if ((0, _utils.is)('function', onMouseDown_)) onMouseDown_(event);
415
+ }, [onMouseDown_]);
416
+ const onTouchStart = _react.default.useCallback(event => {
417
+ refs.mouseDown.current = true;
418
+ if ((0, _utils.is)('function', onTouchStart_)) onTouchStart_(event);
419
+ }, [onTouchStart_]);
420
+ const onMouseDownMiniMap = _react.default.useCallback(event => {
421
+ refs.mouseDownMiniMap.current = true;
422
+ }, []);
423
+ const onTouchStartMiniMap = _react.default.useCallback(event => {
424
+ refs.mouseDownMiniMap.current = true;
425
+ }, []);
426
+ const onMoveMiniMap = _react.default.useCallback((x_, y_, event) => {
427
+ if (refs.mouseDownMiniMap.current && refs.previousMouseEvent.current && !refs.disabled.current) {
428
+ const positions_ = refs.positions.current;
429
+ const root = refs.root.current;
430
+ const container = refs.container.current;
431
+ const miniMap_ = refs.miniMap.current;
432
+ const rectMiniMap = miniMap_.getBoundingClientRect();
433
+ const ratios = {
434
+ containerMiniMap: container.clientWidth / 170,
435
+ rootContainer: root.clientWidth / container.clientWidth
436
+ };
437
+ const zoomAdjusted = 1 / positions_.zoom;
438
+ const x = (event.clientX - rectMiniMap.x) * ratios.containerMiniMap / zoomAdjusted;
439
+ const y = (event.clientY - rectMiniMap.y) * ratios.containerMiniMap / zoomAdjusted;
440
+ const left = x * -1 + root.clientWidth / 2;
441
+ const top = y * -1 + root.clientHeight / 2;
442
+ update({
443
+ left,
444
+ top
445
+ });
446
+ }
447
+ }, []);
448
+ const onMove = _react.default.useCallback((x_, y_, event) => {
449
+ if (refs.keyDown.current === ' ' && refs.mouseDown.current && refs.previousMouseEvent.current && !refs.disabled.current) {
450
+ const {
451
+ clientX: xPrevious,
452
+ clientY: yPrevious
453
+ } = refs.previousMouseEvent.current;
454
+ const positions_ = refs.positions.current;
455
+ const x = x_ - xPrevious;
456
+ const y = y_ - yPrevious;
457
+ const left = x + positions_.left;
458
+ const top = y + positions_.top;
459
+ update({
460
+ left,
461
+ top
462
+ });
463
+ }
464
+ }, []);
465
+ const onMouseMove = _react.default.useCallback(event => {
466
+ if ((refs.mouseDown.current || refs.mouseDownMiniMap.current) && !refs.disabled.current) {
467
+ const {
468
+ clientY,
469
+ clientX
470
+ } = event;
471
+ if (refs.mouseDownMiniMap.current) onMoveMiniMap(clientX, clientY, event);else if (refs.mouseDown.current) onMove(clientX, clientY, event);
472
+ refs.previousMouseEvent.current = event;
473
+ }
474
+ }, []);
475
+ const onTouchMove = _react.default.useCallback(event => {
476
+ if ((refs.mouseDown.current || refs.mouseDownMiniMap.current) && !refs.disabled.current) {
477
+ const {
478
+ clientY,
479
+ clientX
480
+ } = event.touches[0];
481
+ if (refs.mouseDownMiniMap.current) onMoveMiniMap(clientX, clientY, event);else if (refs.mouseDown.current) onMove(clientX, clientY, event);
482
+ refs.previousMouseEvent.current = event;
483
+
484
+ // Normalize for use as a mouseDown value
485
+ refs.previousMouseEvent.current.clientY = clientY;
486
+ refs.previousMouseEvent.current.clientX = clientX;
487
+ }
488
+ }, []);
489
+ _react.default.useEffect(() => {
490
+ var _refs$root$current2;
491
+ // init
492
+ init();
493
+ 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;
494
+ window.addEventListener('wheel', onWheel, {
495
+ passive: false
496
+ });
497
+ rootDocument.addEventListener('keyup', onKeyUp);
498
+ rootDocument.addEventListener('keydown', onKeyDown);
499
+ rootDocument.addEventListener('mousemove', onMouseMove);
500
+ rootDocument.addEventListener('touchmove', onTouchMove, {
501
+ passive: true
502
+ });
503
+ rootDocument.addEventListener('mouseup', onMouseUp);
504
+ rootDocument.addEventListener('touchend', onMouseUp);
505
+ return () => {
506
+ window.removeEventListener('wheel', onWheel);
507
+ rootDocument.removeEventListener('keyup', onKeyUp);
508
+ rootDocument.removeEventListener('keydown', onKeyDown);
509
+ rootDocument.removeEventListener('mousemove', onMouseMove);
510
+ rootDocument.removeEventListener('touchmove', onTouchMove);
511
+ rootDocument.removeEventListener('mouseup', onMouseUp);
512
+ rootDocument.removeEventListener('touchend', onMouseUp);
513
+ };
514
+ }, []);
515
+ const onShowGuidelines = _react.default.useCallback(valueNew => {
516
+ setShowGuidelines(valueNew);
517
+ }, []);
518
+ const zoomOptions = _react.default.useMemo(() => {
519
+ return [{
520
+ name: 'Zoom to fit',
521
+ props: {
522
+ onClick: event => onCenter()
523
+ }
524
+ }, {
525
+ name: 'Zoom to 25%',
526
+ value: 0.25,
527
+ props: {
528
+ onClick: event => zoom(0.25, event)
529
+ }
530
+ }, {
531
+ name: 'Zoom to 50%',
532
+ value: 0.5,
533
+ props: {
534
+ onClick: event => zoom(0.5, event)
535
+ }
536
+ }, {
537
+ name: 'Zoom to 75%',
538
+ value: 0.75,
539
+ props: {
540
+ onClick: event => zoom(0.75, event)
541
+ }
542
+ }, {
543
+ name: 'Zoom to 100%',
544
+ value: 1,
545
+ props: {
546
+ onClick: event => zoom(1, event)
547
+ }
548
+ }, {
549
+ name: 'Zoom to 125%',
550
+ value: 1.25,
551
+ props: {
552
+ onClick: event => zoom(1.25, event)
553
+ }
554
+ }, {
555
+ name: 'Zoom to 150%',
556
+ value: 1.5,
557
+ props: {
558
+ onClick: event => zoom(1.5, event)
559
+ }
560
+ }, {
561
+ name: 'Zoom to 175%',
562
+ value: 1.75,
563
+ props: {
564
+ onClick: event => zoom(1.75, event)
565
+ }
566
+ }, {
567
+ name: 'Zoom to 200%',
568
+ value: 2,
569
+ props: {
570
+ onClick: event => zoom(2, event)
571
+ }
572
+ }, {
573
+ name: 'Zoom to 400%',
574
+ value: 4,
575
+ props: {
576
+ onClick: event => zoom(4, event)
577
+ }
578
+ }];
579
+ }, []);
580
+ const miniMap = _react.default.useMemo(() => {
581
+ const root = refs.root.current;
582
+ const container = refs.container.current;
583
+ if (!container) return null;
584
+ const zoomAdjusted = 1 / positions.zoom;
585
+ const ratios = {
586
+ root: root.clientWidth / root.clientHeight,
587
+ container: container.clientWidth / container.clientHeight,
588
+ rootContainer: root.clientWidth / container.clientWidth
589
+ };
590
+ const width_ = 170;
591
+ const height_ = 170 / ratios.container;
592
+ const zoomPerSize = container.clientWidth / width_;
593
+ const viewportStyles = {
594
+ width: width_ * ratios.rootContainer * zoomAdjusted,
595
+ height: width_ / ratios.root * ratios.rootContainer * zoomAdjusted
596
+ };
597
+ viewportStyles.left = Math.abs(positions.left) / zoomPerSize * zoomAdjusted;
598
+ viewportStyles.top = Math.abs(positions.top) / zoomPerSize * zoomAdjusted;
599
+ return /*#__PURE__*/_react.default.createElement(Line, {
600
+ ref: refs.miniMap,
601
+ onMouseDown: onMouseDownMiniMap,
602
+ onTouchStart: onTouchStartMiniMap,
603
+ className: (0, _styleReact.classNames)([classes.miniMap]),
604
+ style: {
605
+ width: width_,
606
+ height: height_
607
+ }
608
+ }, /*#__PURE__*/_react.default.createElement(Line, {
609
+ className: classes.miniMapMain
610
+ }), /*#__PURE__*/_react.default.createElement(Line, {
611
+ className: classes.miniMapViewport,
612
+ style: _objectSpread({}, viewportStyles)
613
+ }));
614
+ }, [positions, onMouseDownMiniMap, onTouchStartMiniMap]);
615
+ const updateMiniMap = _react.default.useCallback((0, _utils.debounce)(() => {
616
+ const root = refs.root.current;
617
+ const container = refs.container.current;
618
+ const miniMap_ = refs.miniMap.current;
619
+ if (!miniMap_) return;
620
+ const itemsContainer = Array.from(container.children);
621
+ const itemsContainerMap = {};
622
+ itemsContainer.forEach(element => {
623
+ itemsContainerMap[element.dataset.id] = element;
624
+ });
625
+ const miniMapItems = miniMap_.children[0];
626
+ const itemsMiniMapItems = Array.from(miniMapItems.children);
627
+ const itemsMiniMapItemsMap = {};
628
+ itemsMiniMapItems.forEach(element => {
629
+ itemsMiniMapItemsMap[element.dataset.id] = element;
630
+ });
631
+ const ratios = {
632
+ root: root.clientWidth / root.clientHeight,
633
+ container: container.clientWidth / container.clientHeight,
634
+ contanerMiniMap: 170 / container.clientWidth
635
+ };
636
+ const updateItemCopy = item => {
637
+ const left = +item.style.left.replace('px', '');
638
+ const top = +item.style.top.replace('px', '');
639
+ const width_ = +item.style.width.replace('px', '');
640
+ const height_ = +item.style.height.replace('px', '');
641
+ item.style.width = `${width_ * ratios.contanerMiniMap}px`;
642
+ item.style.height = `${height_ * ratios.contanerMiniMap}px`;
643
+ item.style.left = `${left * ratios.contanerMiniMap}px`;
644
+ item.style.top = `${top * ratios.contanerMiniMap}px`;
645
+ };
646
+ itemsContainer.forEach(item => {
647
+ const id = item.dataset.id;
648
+ const itemCopy = item.cloneNode();
649
+ updateItemCopy(itemCopy);
650
+
651
+ // add
652
+ if (!itemsMiniMapItemsMap[id]) {
653
+ miniMapItems.append(itemCopy);
654
+ }
655
+ // update
656
+ else {
657
+ const itemExisting = itemsMiniMapItemsMap[id];
658
+ itemExisting.style.left = itemCopy.style.left;
659
+ itemExisting.style.top = itemCopy.style.top;
660
+ itemExisting.style.width = itemCopy.style.width;
661
+ itemExisting.style.height = itemCopy.style.height;
662
+ }
663
+ });
664
+ itemsMiniMapItems.forEach(item => {
665
+ const id = item.dataset.id;
666
+
667
+ // remove
668
+ if (!itemsContainerMap[id]) {
669
+ item.remove();
670
+ }
671
+ });
672
+ }, 440), []);
673
+ _react.default.useEffect(() => {
674
+ // update
675
+ // mini map
676
+ if (useMiniMap) updateMiniMap();
677
+ }, [children, useMiniMap]);
678
+ return /*#__PURE__*/_react.default.createElement(Surface, (0, _extends2.default)({
679
+ ref: item => {
680
+ if (ref) {
681
+ if ((0, _utils.is)('function', ref)) ref(item);
682
+ ref.current = item;
683
+ }
684
+ refs.root.current = item;
685
+ },
686
+ color: "default",
687
+ gap: 0,
688
+ align: "unset",
689
+ justify: "unset",
690
+ flex: true,
691
+ fullWidth: true,
692
+ onMouseDown: onMouseDown,
693
+ onTouchStart: onTouchStart,
694
+ Component: Component,
695
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('HTMLCanvas', theme) && ['onesy-HTMLCanvas-root'], className, classes.root, keyDown === ' ' && classes.move, disabled && classes.disabled])
696
+ }, other), pre, !noActions && /*#__PURE__*/_react.default.createElement(Line, {
697
+ gap: 0.5,
698
+ direction: "row",
699
+ align: "center",
700
+ justify: "flex-start",
701
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('HTMLCanvas', theme) && ['onesy-HTMLCanvas-actions'], classes.actions])
702
+ }, !noGuideLines && /*#__PURE__*/_react.default.createElement(Label, {
703
+ value: showGuidelines,
704
+ onChange: onShowGuidelines,
705
+ size: "small"
706
+ }, /*#__PURE__*/_react.default.createElement(Switch, null), "Guidelines"), !noFitCenter && /*#__PURE__*/_react.default.createElement(Line, {
707
+ gap: 1,
708
+ direction: "row",
709
+ align: "center",
710
+ justify: "flex-end"
711
+ }, /*#__PURE__*/_react.default.createElement(Tooltip, {
712
+ name: "Fit"
713
+ }, /*#__PURE__*/_react.default.createElement(IconButton, (0, _extends2.default)({
714
+ size: size,
715
+ onClick: onCenter
716
+ }, IconButtonProps), /*#__PURE__*/_react.default.createElement(IconCenter, null)))), !noZoomMenu && /*#__PURE__*/_react.default.createElement(Menu, {
717
+ menuItems: zoomOptions.map((item, index) => /*#__PURE__*/_react.default.createElement(ListItem, (0, _extends2.default)({
718
+ key: item.name,
719
+ primary: /*#__PURE__*/_react.default.createElement(Type, {
720
+ version: "b3"
721
+ }, item.name),
722
+ value: item.name,
723
+ selected: +positions.zoom.toFixed(2) === +(item.value || 0).toFixed(2)
724
+ }, item.props, {
725
+ size: "small",
726
+ button: true
727
+ }))),
728
+ className: classes.menu
729
+ }, /*#__PURE__*/_react.default.createElement(Line, {
730
+ align: "center",
731
+ justify: "center",
732
+ className: classes.zoom
733
+ }, /*#__PURE__*/_react.default.createElement(Type, {
734
+ version: size === 'large' ? 'b2' : size === 'regular' ? 'b3' : 'b3',
735
+ align: "center",
736
+ whiteSpace: "nowrap",
737
+ fullWidth: true
738
+ }, (positions.zoom * 100).toFixed(0), "%")))), /*#__PURE__*/_react.default.createElement(Line, (0, _extends2.default)({}, ContainerProps, {
739
+ ref: item => {
740
+ if (ContainerProps !== null && ContainerProps !== void 0 && ContainerProps.ref) {
741
+ if ((0, _utils.is)('function', ContainerProps === null || ContainerProps === void 0 ? void 0 : ContainerProps.ref)) ContainerProps.ref(item);
742
+ ContainerProps.ref.current = item;
743
+ }
744
+ refs.container.current = item;
745
+ },
746
+ gap: 0,
747
+ align: "unset",
748
+ justify: "unset",
749
+ flex: true,
750
+ fullWidth: true,
751
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('HTMLCanvas', theme) && ['onesy-HTMLCanvas-container'], ContainerProps === null || ContainerProps === void 0 ? void 0 : ContainerProps.className, classes.container, showGuidelines && guidelines && classes[`guidelines_${[true, 'dots'].includes(guidelines) ? 'dots' : 'lines'}`]]),
752
+ style: _objectSpread({
753
+ width,
754
+ height
755
+ }, ContainerProps === null || ContainerProps === void 0 ? void 0 : ContainerProps.style)
756
+ }), children), useMiniMap && miniMap, post);
547
757
  });
548
758
  HTMLCanvas.displayName = 'onesy-HTMLCanvas';
549
- exports.default = HTMLCanvas;
759
+ var _default = exports.default = HTMLCanvas;