@onesy/ui-react 1.0.130 → 1.0.132

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 (712) hide show
  1. package/Accordion/Accordion.d.ts +2 -2
  2. package/Accordion/Accordion.js +342 -242
  3. package/Accordion/index.js +12 -7
  4. package/AdvancedTextField/AdvancedTextField.d.ts +1 -1
  5. package/AdvancedTextField/AdvancedTextField.js +165 -157
  6. package/AdvancedTextField/index.js +12 -7
  7. package/Append/Append.d.ts +3 -3
  8. package/Append/Append.js +502 -519
  9. package/Append/index.js +12 -7
  10. package/AreaChart/AreaChart.d.ts +1 -1
  11. package/AreaChart/AreaChart.js +53 -40
  12. package/AreaChart/index.js +12 -7
  13. package/AreaChartItem/AreaChartItem.d.ts +1 -1
  14. package/AreaChartItem/AreaChartItem.js +325 -237
  15. package/AreaChartItem/index.js +12 -7
  16. package/AudioPlayer/AudioPlayer.d.ts +1 -1
  17. package/AudioPlayer/AudioPlayer.js +683 -466
  18. package/AudioPlayer/index.js +12 -7
  19. package/AudioRecorder/AudioRecorder.d.ts +1 -1
  20. package/AudioRecorder/AudioRecorder.js +359 -259
  21. package/AudioRecorder/index.js +12 -7
  22. package/AutoComplete/AutoComplete.d.ts +3 -3
  23. package/AutoComplete/AutoComplete.js +693 -568
  24. package/AutoComplete/index.js +12 -7
  25. package/AutoCompleteCountry/AutoCompleteCountry.d.ts +1 -1
  26. package/AutoCompleteCountry/AutoCompleteCountry.js +99 -62
  27. package/AutoCompleteCountry/index.js +12 -7
  28. package/AutoCompleteCurrency/AutoCompleteCurrency.d.ts +1 -1
  29. package/AutoCompleteCurrency/AutoCompleteCurrency.js +73 -61
  30. package/AutoCompleteCurrency/index.js +12 -7
  31. package/Avatar/Avatar.d.ts +1 -1
  32. package/Avatar/Avatar.js +113 -86
  33. package/Avatar/index.js +12 -7
  34. package/AvatarGroup/AvatarGroup.d.ts +1 -1
  35. package/AvatarGroup/AvatarGroup.js +104 -87
  36. package/AvatarGroup/index.js +12 -7
  37. package/Backdrop/Backdrop.d.ts +1 -1
  38. package/Backdrop/Backdrop.js +160 -139
  39. package/Backdrop/index.js +12 -7
  40. package/Badge/Badge.d.ts +1 -1
  41. package/Badge/Badge.js +116 -96
  42. package/Badge/index.js +12 -7
  43. package/Banner/Banner.d.ts +1 -1
  44. package/Banner/Banner.js +126 -85
  45. package/Banner/index.js +12 -7
  46. package/BottomAppBar/BottomAppBar.d.ts +1 -1
  47. package/BottomAppBar/BottomAppBar.js +89 -60
  48. package/BottomAppBar/index.js +12 -7
  49. package/BottomSheet/BottomSheet.d.ts +1 -1
  50. package/BottomSheet/BottomSheet.js +66 -59
  51. package/BottomSheet/index.js +12 -7
  52. package/Box/Box.d.ts +1 -1
  53. package/Box/Box.js +43 -35
  54. package/Box/index.js +12 -7
  55. package/Breadcrumbs/Breadcrumbs.d.ts +1 -1
  56. package/Breadcrumbs/Breadcrumbs.js +168 -144
  57. package/Breadcrumbs/index.js +12 -7
  58. package/BubbleChart/BubbleChart.d.ts +1 -1
  59. package/BubbleChart/BubbleChart.js +261 -132
  60. package/BubbleChart/index.js +12 -7
  61. package/BubbleChartItem/BubbleChartItem.d.ts +1 -1
  62. package/BubbleChartItem/BubbleChartItem.js +228 -161
  63. package/BubbleChartItem/index.js +12 -7
  64. package/Button/Button.d.ts +1 -1
  65. package/Button/Button.js +488 -467
  66. package/Button/index.js +12 -7
  67. package/Buttons/Buttons.d.ts +1 -1
  68. package/Buttons/Buttons.js +343 -294
  69. package/Buttons/index.js +12 -7
  70. package/Calendar/Calendar.d.ts +3 -3
  71. package/Calendar/Calendar.js +715 -452
  72. package/Calendar/index.js +12 -7
  73. package/CalendarAvailability/CalendarAvailability.d.ts +2 -2
  74. package/CalendarAvailability/CalendarAvailability.js +709 -388
  75. package/CalendarAvailability/index.js +12 -7
  76. package/CalendarMenu/CalendarMenu.d.ts +1 -1
  77. package/CalendarMenu/CalendarMenu.js +430 -303
  78. package/CalendarMenu/index.js +12 -7
  79. package/CalendarMonth/CalendarMonth.d.ts +5 -5
  80. package/CalendarMonth/CalendarMonth.js +537 -498
  81. package/CalendarMonth/index.js +12 -7
  82. package/CalendarViews/CalendarViews.d.ts +2 -2
  83. package/CalendarViews/CalendarViews.js +403 -254
  84. package/CalendarViews/index.js +12 -7
  85. package/CalendarWeek/CalendarWeek.d.ts +1 -1
  86. package/CalendarWeek/CalendarWeek.js +536 -395
  87. package/CalendarWeek/index.js +12 -7
  88. package/Card/Card.d.ts +1 -1
  89. package/Card/Card.js +133 -101
  90. package/Card/index.js +12 -7
  91. package/CardButton/CardButton.d.ts +1 -1
  92. package/CardButton/CardButton.js +78 -58
  93. package/CardButton/index.js +12 -7
  94. package/CardFooter/CardFooter.d.ts +1 -1
  95. package/CardFooter/CardFooter.js +58 -39
  96. package/CardFooter/index.js +12 -7
  97. package/CardHeader/CardHeader.d.ts +1 -1
  98. package/CardHeader/CardHeader.js +61 -44
  99. package/CardHeader/index.js +12 -7
  100. package/CardImage/CardImage.d.ts +1 -1
  101. package/CardImage/CardImage.js +80 -67
  102. package/CardImage/index.js +12 -7
  103. package/CardMain/CardMain.d.ts +1 -1
  104. package/CardMain/CardMain.js +53 -39
  105. package/CardMain/index.js +12 -7
  106. package/Carousel/Carousel.d.ts +4 -4
  107. package/Carousel/Carousel.js +1025 -913
  108. package/Carousel/index.js +12 -7
  109. package/Chart/Chart.d.ts +4 -4
  110. package/Chart/Chart.js +1325 -1174
  111. package/Chart/index.js +12 -7
  112. package/Checkbox/Checkbox.d.ts +1 -1
  113. package/Checkbox/Checkbox.js +339 -325
  114. package/Checkbox/index.js +12 -7
  115. package/Chip/Chip.d.ts +1 -1
  116. package/Chip/Chip.js +131 -102
  117. package/Chip/index.js +12 -7
  118. package/Chips/Chips.d.ts +1 -1
  119. package/Chips/Chips.js +121 -94
  120. package/Chips/index.js +12 -7
  121. package/ClickListener/ClickListener.d.ts +1 -1
  122. package/ClickListener/ClickListener.js +86 -89
  123. package/ClickListener/index.js +12 -7
  124. package/Clock/Clock.d.ts +5 -5
  125. package/Clock/Clock.js +470 -417
  126. package/Clock/index.js +12 -7
  127. package/ColorTextField/ColorTextField.d.ts +1 -1
  128. package/ColorTextField/ColorTextField.js +234 -171
  129. package/ColorTextField/index.js +12 -7
  130. package/ColumnChart/ColumnChart.d.ts +1 -1
  131. package/ColumnChart/ColumnChart.js +63 -46
  132. package/ColumnChart/index.js +12 -7
  133. package/ColumnChartItem/ColumnChartItem.d.ts +1 -1
  134. package/ColumnChartItem/ColumnChartItem.js +208 -149
  135. package/ColumnChartItem/index.js +12 -7
  136. package/Confirm/Confirm.d.ts +4 -4
  137. package/Confirm/Confirm.js +184 -129
  138. package/Confirm/Context.js +9 -7
  139. package/Confirm/index.js +32 -13
  140. package/Confirm/useConfirm.js +11 -10
  141. package/Container/Container.d.ts +1 -1
  142. package/Container/Container.js +154 -133
  143. package/Container/index.js +12 -7
  144. package/CookieBanner/CookieBanner.d.ts +1 -1
  145. package/CookieBanner/CookieBanner.js +142 -76
  146. package/CookieBanner/index.js +12 -7
  147. package/Countdown/Countdown.d.ts +1 -1
  148. package/Countdown/Countdown.js +403 -255
  149. package/Countdown/index.js +12 -7
  150. package/DatePicker/DatePicker.d.ts +1 -1
  151. package/DatePicker/DatePicker.js +802 -547
  152. package/DatePicker/index.js +12 -7
  153. package/DateRangePicker/DateRangePicker.d.ts +1 -1
  154. package/DateRangePicker/DateRangePicker.js +44 -37
  155. package/DateRangePicker/index.js +12 -7
  156. package/DateTimePicker/DateTimePicker.d.ts +2 -2
  157. package/DateTimePicker/DateTimePicker.js +672 -459
  158. package/DateTimePicker/index.js +12 -7
  159. package/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -1
  160. package/DateTimeRangePicker/DateTimeRangePicker.js +44 -37
  161. package/DateTimeRangePicker/index.js +12 -7
  162. package/Divider/Divider.d.ts +1 -1
  163. package/Divider/Divider.js +198 -185
  164. package/Divider/index.js +12 -7
  165. package/DonutChart/DonutChart.d.ts +1 -1
  166. package/DonutChart/DonutChart.js +49 -42
  167. package/DonutChart/index.js +12 -7
  168. package/DragAndDropList/DragAndDropList.d.ts +1 -1
  169. package/DragAndDropList/DragAndDropList.js +160 -156
  170. package/DragAndDropList/index.js +12 -7
  171. package/Drawing/Drawing.d.ts +2 -2
  172. package/Drawing/Drawing.js +850 -523
  173. package/Drawing/index.js +12 -7
  174. package/DropZone/DropZone.d.ts +1 -1
  175. package/DropZone/DropZone.js +239 -201
  176. package/DropZone/index.js +12 -7
  177. package/Emojis/Emojis.d.ts +3 -3
  178. package/Emojis/Emojis.js +409 -317
  179. package/Emojis/emojis_list.js +7279 -9250
  180. package/Emojis/index.js +19 -9
  181. package/Expand/Expand.d.ts +1 -1
  182. package/Expand/Expand.js +201 -149
  183. package/Expand/index.js +12 -7
  184. package/Fab/Fab.d.ts +1 -1
  185. package/Fab/Fab.js +46 -26
  186. package/Fab/index.js +12 -7
  187. package/Fade/Fade.d.ts +1 -1
  188. package/Fade/Fade.js +131 -101
  189. package/Fade/index.js +12 -7
  190. package/FileChoose/FileChoose.d.ts +2 -2
  191. package/FileChoose/FileChoose.js +218 -150
  192. package/FileChoose/index.js +12 -7
  193. package/Focus/Focus.d.ts +1 -1
  194. package/Focus/Focus.js +87 -88
  195. package/Focus/index.js +12 -7
  196. package/Form/Form.d.ts +1 -1
  197. package/Form/Form.js +194 -120
  198. package/Form/index.js +12 -7
  199. package/FormRow/FormRow.d.ts +1 -1
  200. package/FormRow/FormRow.js +123 -78
  201. package/FormRow/index.js +12 -7
  202. package/Forms/Forms.d.ts +1 -1
  203. package/Forms/Forms.js +55 -41
  204. package/Forms/index.js +12 -7
  205. package/Frame/Frame.d.ts +1 -1
  206. package/Frame/Frame.js +212 -150
  207. package/Frame/index.js +12 -7
  208. package/Grid/Grid.d.ts +2 -2
  209. package/Grid/Grid.js +231 -166
  210. package/Grid/index.js +12 -7
  211. package/Grow/Grow.d.ts +1 -1
  212. package/Grow/Grow.js +137 -109
  213. package/Grow/index.js +12 -7
  214. package/HTMLCanvas/HTMLCanvas.d.ts +2 -2
  215. package/HTMLCanvas/HTMLCanvas.js +752 -542
  216. package/HTMLCanvas/index.js +23 -21
  217. package/IFrame/IFrame.d.ts +1 -1
  218. package/IFrame/IFrame.js +122 -104
  219. package/IFrame/index.js +12 -7
  220. package/Icon/Icon.d.ts +1 -1
  221. package/Icon/Icon.js +112 -95
  222. package/Icon/index.js +23 -21
  223. package/IconButton/IconButton.d.ts +1 -1
  224. package/IconButton/IconButton.js +49 -37
  225. package/IconButton/index.js +12 -7
  226. package/Image/Image.d.ts +1 -1
  227. package/Image/Image.js +285 -252
  228. package/Image/index.js +12 -7
  229. package/ImageCrop/ImageCrop.d.ts +2 -2
  230. package/ImageCrop/ImageCrop.js +1073 -1048
  231. package/ImageCrop/index.js +12 -7
  232. package/ImageEdit/ImageEdit.d.ts +2 -2
  233. package/ImageEdit/ImageEdit.js +1088 -783
  234. package/ImageEdit/index.js +12 -7
  235. package/ImageGallery/ImageGallery.d.ts +1 -1
  236. package/ImageGallery/ImageGallery.js +518 -473
  237. package/ImageGallery/index.js +12 -7
  238. package/ImageList/ImageList.d.ts +1 -1
  239. package/ImageList/ImageList.js +136 -129
  240. package/ImageList/index.js +12 -7
  241. package/ImageListItem/ImageListItem.d.ts +1 -1
  242. package/ImageListItem/ImageListItem.js +101 -87
  243. package/ImageListItem/index.js +12 -7
  244. package/ImageListItemBox/ImageListItemBox.d.ts +1 -1
  245. package/ImageListItemBox/ImageListItemBox.js +61 -50
  246. package/ImageListItemBox/index.js +12 -7
  247. package/Info/Info.d.ts +1 -1
  248. package/Info/Info.js +99 -63
  249. package/Info/index.js +12 -7
  250. package/Interaction/Interaction.d.ts +2 -2
  251. package/Interaction/Interaction.js +405 -345
  252. package/Interaction/index.js +12 -7
  253. package/Keyframes/Context.js +9 -7
  254. package/Keyframes/Keyframes.d.ts +3 -3
  255. package/Keyframes/Keyframes.js +189 -174
  256. package/Keyframes/index.js +41 -25
  257. package/Keyframes/useKeyframes.js +11 -10
  258. package/Label/Label.d.ts +1 -1
  259. package/Label/Label.js +177 -151
  260. package/Label/index.js +12 -7
  261. package/Labels/Labels.d.ts +1 -1
  262. package/Labels/Labels.js +126 -98
  263. package/Labels/index.js +12 -7
  264. package/Line/Line.d.ts +6 -6
  265. package/Line/Line.js +296 -174
  266. package/Line/index.js +12 -7
  267. package/LineChart/LineChart.d.ts +1 -1
  268. package/LineChart/LineChart.js +57 -40
  269. package/LineChart/index.js +12 -7
  270. package/LineChartItem/LineChartItem.d.ts +1 -1
  271. package/LineChartItem/LineChartItem.js +239 -177
  272. package/LineChartItem/index.js +12 -7
  273. package/LinearMeter/LinearMeter.d.ts +1 -1
  274. package/LinearMeter/LinearMeter.js +453 -377
  275. package/LinearMeter/index.js +12 -7
  276. package/LinearProgress/LinearProgress.d.ts +1 -1
  277. package/LinearProgress/LinearProgress.js +324 -255
  278. package/LinearProgress/index.js +12 -7
  279. package/Link/Link.d.ts +1 -1
  280. package/Link/Link.js +182 -127
  281. package/Link/index.js +12 -7
  282. package/Links/Links.d.ts +2 -2
  283. package/Links/Links.js +277 -156
  284. package/Links/index.js +12 -7
  285. package/List/List.d.ts +1 -1
  286. package/List/List.js +148 -113
  287. package/List/index.js +12 -7
  288. package/ListItem/ListItem.d.ts +1 -1
  289. package/ListItem/ListItem.js +388 -362
  290. package/ListItem/index.js +12 -7
  291. package/ListSubheader/ListSubheader.d.ts +1 -1
  292. package/ListSubheader/ListSubheader.js +52 -44
  293. package/ListSubheader/index.js +12 -7
  294. package/MainProgress/Context.js +9 -7
  295. package/MainProgress/MainProgress.d.ts +3 -3
  296. package/MainProgress/MainProgress.js +193 -161
  297. package/MainProgress/index.js +32 -13
  298. package/MainProgress/useMainProgress.js +11 -10
  299. package/Markdown/Markdown.d.ts +1 -1
  300. package/Markdown/Markdown.js +676 -704
  301. package/Markdown/index.js +12 -7
  302. package/Masonry/Masonry.d.ts +1 -1
  303. package/Masonry/Masonry.js +207 -181
  304. package/Masonry/index.js +12 -7
  305. package/Medias/Medias.d.ts +3 -3
  306. package/Medias/Medias.js +436 -398
  307. package/Medias/index.js +12 -7
  308. package/Menu/Menu.d.ts +1 -1
  309. package/Menu/Menu.js +278 -243
  310. package/Menu/index.js +12 -7
  311. package/MenuDesktop/MenuDesktop.d.ts +3 -3
  312. package/MenuDesktop/MenuDesktop.js +496 -419
  313. package/MenuDesktop/index.js +12 -7
  314. package/MenuItem/MenuItem.d.ts +1 -1
  315. package/MenuItem/MenuItem.js +286 -231
  316. package/MenuItem/index.js +12 -7
  317. package/Meta/Meta.d.ts +1 -1
  318. package/Meta/Meta.js +78 -54
  319. package/Meta/index.js +12 -7
  320. package/Modal/Modal.d.ts +1 -1
  321. package/Modal/Modal.js +333 -272
  322. package/Modal/index.js +12 -7
  323. package/ModalFooter/ModalFooter.d.ts +1 -1
  324. package/ModalFooter/ModalFooter.js +50 -39
  325. package/ModalFooter/index.js +12 -7
  326. package/ModalHeader/ModalHeader.d.ts +1 -1
  327. package/ModalHeader/ModalHeader.js +51 -39
  328. package/ModalHeader/index.js +12 -7
  329. package/ModalIcon/ModalIcon.d.ts +1 -1
  330. package/ModalIcon/ModalIcon.js +29 -23
  331. package/ModalIcon/index.js +12 -7
  332. package/ModalMain/ModalMain.d.ts +1 -1
  333. package/ModalMain/ModalMain.js +50 -41
  334. package/ModalMain/index.js +12 -7
  335. package/ModalText/ModalText.d.ts +1 -1
  336. package/ModalText/ModalText.js +47 -37
  337. package/ModalText/index.js +12 -7
  338. package/ModalTitle/ModalTitle.d.ts +1 -1
  339. package/ModalTitle/ModalTitle.js +47 -37
  340. package/ModalTitle/index.js +12 -7
  341. package/MoreOptions/MoreOptions.d.ts +1 -1
  342. package/MoreOptions/MoreOptions.js +72 -52
  343. package/MoreOptions/index.js +12 -7
  344. package/Move/Move.d.ts +1 -1
  345. package/Move/Move.js +166 -141
  346. package/Move/index.js +12 -7
  347. package/NavigationBar/NavigationBar.d.ts +2 -2
  348. package/NavigationBar/NavigationBar.js +133 -109
  349. package/NavigationBar/index.js +12 -7
  350. package/NavigationDrawer/NavigationDrawer.d.ts +1 -1
  351. package/NavigationDrawer/NavigationDrawer.js +241 -211
  352. package/NavigationDrawer/index.js +12 -7
  353. package/NavigationItem/NavigationItem.d.ts +2 -2
  354. package/NavigationItem/NavigationItem.js +293 -262
  355. package/NavigationItem/index.js +12 -7
  356. package/NavigationRail/NavigationRail.d.ts +1 -1
  357. package/NavigationRail/NavigationRail.js +187 -150
  358. package/NavigationRail/index.js +12 -7
  359. package/NotFound/NotFound.d.ts +1 -1
  360. package/NotFound/NotFound.js +89 -66
  361. package/NotFound/index.js +12 -7
  362. package/NumericTextField/NumericTextField.d.ts +1 -1
  363. package/NumericTextField/NumericTextField.js +217 -212
  364. package/NumericTextField/index.js +12 -7
  365. package/Page/Page.d.ts +2 -2
  366. package/Page/Page.js +131 -67
  367. package/Page/index.js +12 -7
  368. package/PageTransition/PageTransition.d.ts +1 -1
  369. package/PageTransition/PageTransition.js +112 -102
  370. package/PageTransition/index.js +12 -7
  371. package/Pagination/Pagination.d.ts +1 -1
  372. package/Pagination/Pagination.js +153 -98
  373. package/Pagination/index.js +12 -7
  374. package/PaginationItem/PaginationItem.d.ts +1 -1
  375. package/PaginationItem/PaginationItem.js +85 -65
  376. package/PaginationItem/index.js +12 -7
  377. package/Parallax/Parallax.d.ts +2 -2
  378. package/Parallax/Parallax.js +138 -145
  379. package/Parallax/index.js +12 -7
  380. package/Path/Path.d.ts +1 -1
  381. package/Path/Path.js +40 -35
  382. package/Path/index.js +12 -7
  383. package/PieChart/PieChart.d.ts +1 -1
  384. package/PieChart/PieChart.js +382 -267
  385. package/PieChart/index.js +12 -7
  386. package/Placeholder/Placeholder.d.ts +1 -1
  387. package/Placeholder/Placeholder.js +125 -117
  388. package/Placeholder/index.js +12 -7
  389. package/Portal/Portal.d.ts +1 -1
  390. package/Portal/Portal.js +37 -38
  391. package/Portal/index.js +12 -7
  392. package/Properties/Properties.d.ts +2 -2
  393. package/Properties/Properties.js +85 -64
  394. package/Properties/index.js +12 -7
  395. package/Property/Property.d.ts +1 -1
  396. package/Property/Property.js +120 -108
  397. package/Property/index.js +12 -7
  398. package/Radio/Radio.d.ts +1 -1
  399. package/Radio/Radio.js +211 -181
  400. package/Radio/index.js +12 -7
  401. package/Radios/Radios.d.ts +1 -1
  402. package/Radios/Radios.js +124 -92
  403. package/Radios/index.js +12 -7
  404. package/Rating/Rating.d.ts +1 -1
  405. package/Rating/Rating.js +353 -360
  406. package/Rating/index.js +12 -7
  407. package/Reset/Reset.d.ts +1 -1
  408. package/Reset/Reset.js +19 -24
  409. package/Reset/index.js +12 -7
  410. package/Reveal/Reveal.d.ts +1 -1
  411. package/Reveal/Reveal.js +98 -89
  412. package/Reveal/index.js +12 -7
  413. package/RichTextEditor/RichTextEditor.d.ts +1 -1
  414. package/RichTextEditor/RichTextEditor.js +1764 -972
  415. package/RichTextEditor/index.js +12 -7
  416. package/RoundMeter/RoundMeter.d.ts +1 -1
  417. package/RoundMeter/RoundMeter.js +629 -537
  418. package/RoundMeter/index.js +12 -7
  419. package/RoundProgress/RoundProgress.d.ts +1 -1
  420. package/RoundProgress/RoundProgress.js +233 -174
  421. package/RoundProgress/index.js +12 -7
  422. package/ScatterChart/ScatterChart.d.ts +1 -1
  423. package/ScatterChart/ScatterChart.js +53 -40
  424. package/ScatterChart/index.js +12 -7
  425. package/ScatterChartItem/ScatterChartItem.d.ts +1 -1
  426. package/ScatterChartItem/ScatterChartItem.js +214 -153
  427. package/ScatterChartItem/index.js +12 -7
  428. package/ScreenCapture/ScreenCapture.d.ts +2 -2
  429. package/ScreenCapture/ScreenCapture.js +427 -335
  430. package/ScreenCapture/index.js +12 -7
  431. package/Section/Section.d.ts +2 -2
  432. package/Section/Section.js +380 -319
  433. package/Section/index.js +12 -7
  434. package/SectionAction/SectionAction.d.ts +1 -1
  435. package/SectionAction/SectionAction.js +72 -61
  436. package/SectionAction/index.js +12 -7
  437. package/SectionBoxes/SectionBoxes.d.ts +2 -2
  438. package/SectionBoxes/SectionBoxes.js +240 -208
  439. package/SectionBoxes/index.js +12 -7
  440. package/SectionCards/SectionCards.d.ts +2 -2
  441. package/SectionCards/SectionCards.js +256 -217
  442. package/SectionCards/index.js +12 -7
  443. package/SectionCarousel/SectionCarousel.d.ts +2 -2
  444. package/SectionCarousel/SectionCarousel.js +284 -242
  445. package/SectionCarousel/index.js +12 -7
  446. package/SectionContact/SectionContact.d.ts +1 -1
  447. package/SectionContact/SectionContact.js +174 -116
  448. package/SectionContact/index.js +12 -7
  449. package/SectionImageGallery/SectionImageGallery.d.ts +1 -1
  450. package/SectionImageGallery/SectionImageGallery.js +64 -51
  451. package/SectionImageGallery/index.js +12 -7
  452. package/SectionLogos/SectionLogos.d.ts +1 -1
  453. package/SectionLogos/SectionLogos.js +123 -109
  454. package/SectionLogos/index.js +12 -7
  455. package/SectionMedia/SectionMedia.d.ts +1 -1
  456. package/SectionMedia/SectionMedia.js +170 -152
  457. package/SectionMedia/index.js +12 -7
  458. package/SectionReviews/SectionReviews.d.ts +2 -2
  459. package/SectionReviews/SectionReviews.js +170 -129
  460. package/SectionReviews/index.js +12 -7
  461. package/SectionTextMedia/SectionTextMedia.d.ts +1 -1
  462. package/SectionTextMedia/SectionTextMedia.js +187 -142
  463. package/SectionTextMedia/index.js +12 -7
  464. package/SectionTimeline/SectionTimeline.d.ts +2 -2
  465. package/SectionTimeline/SectionTimeline.js +126 -95
  466. package/SectionTimeline/index.js +12 -7
  467. package/SectionWatch/SectionWatch.d.ts +1 -1
  468. package/SectionWatch/SectionWatch.js +65 -53
  469. package/SectionWatch/index.js +12 -7
  470. package/Select/Select.d.ts +1 -1
  471. package/Select/Select.js +517 -406
  472. package/Select/index.js +12 -7
  473. package/Share/Share.d.ts +1 -1
  474. package/Share/Share.js +458 -319
  475. package/Share/index.js +12 -7
  476. package/Slide/Slide.d.ts +1 -1
  477. package/Slide/Slide.js +184 -140
  478. package/Slide/index.js +12 -7
  479. package/Slider/Slider.d.ts +2 -2
  480. package/Slider/Slider.js +927 -837
  481. package/Slider/index.js +12 -7
  482. package/SmartTextField/SmartTextField.d.ts +1 -1
  483. package/SmartTextField/SmartTextField.js +1406 -1014
  484. package/SmartTextField/index.js +12 -7
  485. package/Snackbar/Snackbar.d.ts +1 -1
  486. package/Snackbar/Snackbar.js +227 -185
  487. package/Snackbar/index.js +12 -7
  488. package/Snackbars/Context.d.ts +1 -1
  489. package/Snackbars/Context.js +9 -7
  490. package/Snackbars/Snackbars.d.ts +2 -2
  491. package/Snackbars/Snackbars.js +234 -210
  492. package/Snackbars/index.js +32 -13
  493. package/Snackbars/useSnackbars.js +11 -10
  494. package/Space/Space.d.ts +1 -1
  495. package/Space/Space.js +1683 -968
  496. package/Space/index.js +23 -21
  497. package/SpeechToText/SpeechToText.d.ts +1 -1
  498. package/SpeechToText/SpeechToText.js +207 -172
  499. package/SpeechToText/index.js +12 -7
  500. package/SpeedDial/SpeedDial.d.ts +1 -1
  501. package/SpeedDial/SpeedDial.js +434 -398
  502. package/SpeedDial/index.js +12 -7
  503. package/SpeedDialItem/SpeedDialItem.d.ts +1 -1
  504. package/SpeedDialItem/SpeedDialItem.js +89 -63
  505. package/SpeedDialItem/index.js +12 -7
  506. package/SpyScroll/SpyScroll.d.ts +1 -1
  507. package/SpyScroll/SpyScroll.js +154 -142
  508. package/SpyScroll/index.js +12 -7
  509. package/Step/Step.d.ts +1 -1
  510. package/Step/Step.js +181 -127
  511. package/Step/index.js +12 -7
  512. package/Stepper/Stepper.d.ts +1 -1
  513. package/Stepper/Stepper.js +159 -139
  514. package/Stepper/index.js +12 -7
  515. package/Surface/Surface.d.ts +1 -1
  516. package/Surface/Surface.js +760 -798
  517. package/Surface/index.js +12 -7
  518. package/Switch/Switch.d.ts +1 -1
  519. package/Switch/Switch.js +688 -532
  520. package/Switch/index.js +12 -7
  521. package/Tab/Tab.d.ts +1 -1
  522. package/Tab/Tab.js +185 -150
  523. package/Tab/index.js +12 -7
  524. package/Table/Table.d.ts +1 -1
  525. package/Table/Table.js +100 -77
  526. package/Table/index.js +12 -7
  527. package/TableBody/TableBody.d.ts +1 -1
  528. package/TableBody/TableBody.js +76 -63
  529. package/TableBody/index.js +12 -7
  530. package/TableCell/TableCell.d.ts +2 -2
  531. package/TableCell/TableCell.js +258 -220
  532. package/TableCell/index.js +12 -7
  533. package/TableFooter/TableFooter.d.ts +1 -1
  534. package/TableFooter/TableFooter.js +60 -48
  535. package/TableFooter/index.js +12 -7
  536. package/TableHead/TableHead.d.ts +1 -1
  537. package/TableHead/TableHead.js +139 -120
  538. package/TableHead/index.js +12 -7
  539. package/TableHeader/TableHeader.d.ts +1 -1
  540. package/TableHeader/TableHeader.js +65 -50
  541. package/TableHeader/index.js +12 -7
  542. package/TablePagination/TablePagination.d.ts +1 -1
  543. package/TablePagination/TablePagination.js +171 -98
  544. package/TablePagination/index.js +12 -7
  545. package/TableRow/TableRow.d.ts +1 -1
  546. package/TableRow/TableRow.js +77 -64
  547. package/TableRow/index.js +12 -7
  548. package/Tabs/Tabs.d.ts +1 -1
  549. package/Tabs/Tabs.js +425 -377
  550. package/Tabs/index.js +12 -7
  551. package/Text/Text.d.ts +1 -1
  552. package/Text/Text.js +131 -113
  553. package/Text/index.js +12 -7
  554. package/TextField/TextField.d.ts +1 -1
  555. package/TextField/TextField.js +940 -879
  556. package/TextField/index.js +12 -7
  557. package/TextToSpeech/TextToSpeech.d.ts +1 -1
  558. package/TextToSpeech/TextToSpeech.js +176 -153
  559. package/TextToSpeech/index.js +12 -7
  560. package/TimePicker/TimePicker.d.ts +3 -3
  561. package/TimePicker/TimePicker.js +985 -718
  562. package/TimePicker/index.js +12 -7
  563. package/TimeRangePicker/TimeRangePicker.d.ts +1 -1
  564. package/TimeRangePicker/TimeRangePicker.js +44 -37
  565. package/TimeRangePicker/index.js +12 -7
  566. package/Timeline/Timeline.d.ts +1 -1
  567. package/Timeline/Timeline.js +54 -42
  568. package/Timeline/index.js +12 -7
  569. package/TimelineItem/TimelineItem.d.ts +1 -1
  570. package/TimelineItem/TimelineItem.js +144 -147
  571. package/TimelineItem/index.js +12 -7
  572. package/Timer/Timer.d.ts +1 -1
  573. package/Timer/Timer.js +321 -204
  574. package/Timer/index.js +12 -7
  575. package/ToggleButton/ToggleButton.d.ts +1 -1
  576. package/ToggleButton/ToggleButton.js +67 -58
  577. package/ToggleButton/index.js +12 -7
  578. package/ToggleButtons/ToggleButtons.d.ts +1 -1
  579. package/ToggleButtons/ToggleButtons.js +46 -37
  580. package/ToggleButtons/index.js +12 -7
  581. package/Tooltip/Tooltip.d.ts +1 -1
  582. package/Tooltip/Tooltip.js +489 -454
  583. package/Tooltip/index.js +12 -7
  584. package/TopAppBar/TopAppBar.d.ts +1 -1
  585. package/TopAppBar/TopAppBar.js +237 -197
  586. package/TopAppBar/index.js +12 -7
  587. package/Transition/Context.js +9 -7
  588. package/Transition/Transition.d.ts +3 -3
  589. package/Transition/Transition.js +321 -339
  590. package/Transition/index.js +41 -25
  591. package/Transition/useTransition.js +11 -10
  592. package/Transitions/Transitions.d.ts +2 -2
  593. package/Transitions/Transitions.js +215 -179
  594. package/Transitions/index.js +12 -7
  595. package/Tree/Tree.d.ts +1 -1
  596. package/Tree/Tree.js +375 -312
  597. package/Tree/index.js +12 -7
  598. package/Type/Type.d.ts +1 -1
  599. package/Type/Type.js +251 -152
  600. package/Type/index.js +12 -7
  601. package/VideoPlayer/VideoPlayer.d.ts +1 -1
  602. package/VideoPlayer/VideoPlayer.js +866 -656
  603. package/VideoPlayer/index.js +12 -7
  604. package/ViewSplit/ViewSplit.d.ts +1 -1
  605. package/ViewSplit/ViewSplit.js +413 -387
  606. package/ViewSplit/index.js +12 -7
  607. package/Watch/Watch.d.ts +1 -1
  608. package/Watch/Watch.js +436 -290
  609. package/Watch/index.js +12 -7
  610. package/Weather/Weather.d.ts +4 -4
  611. package/Weather/Weather.js +294 -247
  612. package/Weather/index.js +12 -7
  613. package/Whiteboard/Whiteboard.d.ts +5 -5
  614. package/Whiteboard/Whiteboard.js +1392 -1292
  615. package/Whiteboard/index.js +12 -7
  616. package/Widgets/Context.js +9 -7
  617. package/Widgets/Widgets.d.ts +2 -2
  618. package/Widgets/Widgets.js +220 -168
  619. package/Widgets/index.js +32 -13
  620. package/Widgets/useWidgets.js +11 -10
  621. package/WindowSplit/WindowSplit.d.ts +1 -1
  622. package/WindowSplit/WindowSplit.js +381 -336
  623. package/WindowSplit/index.js +12 -7
  624. package/Zoom/Zoom.d.ts +1 -1
  625. package/Zoom/Zoom.js +126 -99
  626. package/Zoom/index.js +12 -7
  627. package/esm/Append/Append.js +6 -8
  628. package/esm/AutoComplete/AutoComplete.js +8 -20
  629. package/esm/Breadcrumbs/Breadcrumbs.js +1 -3
  630. package/esm/Buttons/Buttons.js +8 -33
  631. package/esm/Calendar/Calendar.js +74 -80
  632. package/esm/CalendarAvailability/CalendarAvailability.js +1 -2
  633. package/esm/CalendarMenu/CalendarMenu.js +2 -2
  634. package/esm/CalendarMonth/CalendarMonth.js +65 -68
  635. package/esm/CalendarWeek/CalendarWeek.js +3 -7
  636. package/esm/Carousel/Carousel.js +4 -12
  637. package/esm/Chart/Chart.js +19 -25
  638. package/esm/Clock/Clock.js +5 -8
  639. package/esm/Confirm/Confirm.js +1 -2
  640. package/esm/DatePicker/DatePicker.js +8 -13
  641. package/esm/DateTimePicker/DateTimePicker.js +6 -9
  642. package/esm/Drawing/Drawing.js +1 -6
  643. package/esm/Expand/Expand.js +1 -2
  644. package/esm/Fade/Fade.js +1 -2
  645. package/esm/Focus/Focus.js +1 -2
  646. package/esm/Grow/Grow.js +1 -2
  647. package/esm/HTMLCanvas/HTMLCanvas.js +2 -5
  648. package/esm/ImageCrop/ImageCrop.js +2 -5
  649. package/esm/ImageEdit/ImageEdit.js +5 -12
  650. package/esm/ImageGallery/ImageGallery.js +1 -2
  651. package/esm/Interaction/Interaction.js +1 -2
  652. package/esm/Keyframes/Keyframes.js +1 -2
  653. package/esm/LinearMeter/LinearMeter.js +77 -80
  654. package/esm/Markdown/Markdown.js +41 -144
  655. package/esm/MenuDesktop/MenuDesktop.js +5 -6
  656. package/esm/Rating/Rating.js +2 -4
  657. package/esm/RichTextEditor/RichTextEditor.js +36 -50
  658. package/esm/RoundMeter/RoundMeter.js +70 -73
  659. package/esm/ScreenCapture/ScreenCapture.js +2 -5
  660. package/esm/Select/Select.js +5 -9
  661. package/esm/Share/Share.js +4 -5
  662. package/esm/Slide/Slide.js +2 -4
  663. package/esm/Slider/Slider.js +3 -6
  664. package/esm/SmartTextField/SmartTextField.js +2 -4
  665. package/esm/Snackbar/Snackbar.js +1 -2
  666. package/esm/Snackbars/Snackbars.js +3 -3
  667. package/esm/Space/Space.js +3 -6
  668. package/esm/Switch/Switch.js +1 -2
  669. package/esm/Tabs/Tabs.js +1 -2
  670. package/esm/TimePicker/TimePicker.js +27 -38
  671. package/esm/Timer/Timer.js +3 -4
  672. package/esm/Tooltip/Tooltip.js +1 -2
  673. package/esm/ViewSplit/ViewSplit.js +1 -2
  674. package/esm/Watch/Watch.js +4 -5
  675. package/esm/Weather/Weather.js +14 -17
  676. package/esm/Whiteboard/Whiteboard.js +1 -4
  677. package/esm/WindowSplit/WindowSplit.js +1 -2
  678. package/esm/Zoom/Zoom.js +1 -2
  679. package/esm/index.js +1 -1
  680. package/esm/useForm/useForm.js +1 -4
  681. package/esm/useLocation/useLocation.js +1 -2
  682. package/esm/useSwipe/useSwipe.js +1 -2
  683. package/esm/utils.js +3 -11
  684. package/index.js +4052 -660
  685. package/package.json +3 -3
  686. package/types.d.ts +27 -27
  687. package/types.js +4 -1
  688. package/useForm/index.js +25 -11
  689. package/useForm/useForm.d.ts +2 -2
  690. package/useForm/useForm.js +203 -174
  691. package/useForm/validate.d.ts +12 -12
  692. package/useForm/validate.js +215 -203
  693. package/useLocation/index.js +12 -7
  694. package/useLocation/useLocation.d.ts +1 -1
  695. package/useLocation/useLocation.js +54 -49
  696. package/useMediaQuery/index.js +12 -7
  697. package/useMediaQuery/useMediaQuery.d.ts +1 -1
  698. package/useMediaQuery/useMediaQuery.js +44 -43
  699. package/useQuery/index.js +12 -7
  700. package/useQuery/useQuery.js +14 -10
  701. package/useScroll/index.js +12 -7
  702. package/useScroll/useScroll.d.ts +2 -2
  703. package/useScroll/useScroll.js +61 -56
  704. package/useSubscription/index.js +12 -7
  705. package/useSubscription/useSubscription.js +35 -35
  706. package/useSwipe/index.js +12 -7
  707. package/useSwipe/useSwipe.d.ts +2 -2
  708. package/useSwipe/useSwipe.js +157 -131
  709. package/useVisible/index.js +12 -7
  710. package/useVisible/useVisible.d.ts +2 -2
  711. package/useVisible/useVisible.js +86 -76
  712. package/utils.js +1224 -1362
@@ -1,1334 +1,1434 @@
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 date_1 = require("@onesy/date");
22
- const Line_1 = __importDefault(require("../Line"));
23
- const utils_2 = require("../utils");
24
- const useStyle = (0, style_react_1.style)(theme => ({
25
- root: {
26
- position: 'relative'
27
- },
28
- canvas: {
29
- position: 'absolute',
30
- inset: 0,
31
- width: '100%',
32
- height: '100%',
33
- imageRendering: 'pixelated',
34
- background: '#fff',
35
- appearance: 'none',
36
- border: 'none',
37
- userSelect: 'none',
38
- transition: theme.methods.transitions.make('opacity'),
39
- '&[disabled]': {
40
- opacity: 0.7,
41
- pointerEvents: 'none'
42
- }
43
- },
44
- ui: {
45
- zIndex: 0
46
- },
47
- object: {
48
- cursor: 'crosshair'
49
- },
50
- pen: {
51
- cursor: 'crosshair'
52
- },
53
- pan: {
54
- cursor: 'grab'
55
- },
56
- panning: {
57
- cursor: 'grabbing'
58
- },
59
- zoom: {
60
- cursor: 'zoom-in'
61
- },
62
- eraser: {
63
- cursor: 'not-allowed'
64
- },
65
- image: {
66
- cursor: 'copy'
67
- },
68
- text: {
69
- cursor: 'text'
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 _date = require("@onesy/date");
15
+ var _Line = _interopRequireDefault(require("../Line"));
16
+ var _utils2 = require("../utils");
17
+ const _excluded = ["valueDefault", "onChange", "minZoom", "maxZoom", "grid", "settings", "className"];
18
+ 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; }
19
+ 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; }
20
+ const useStyle = (0, _styleReact.style)(theme => ({
21
+ root: {
22
+ position: 'relative'
23
+ },
24
+ canvas: {
25
+ position: 'absolute',
26
+ inset: 0,
27
+ width: '100%',
28
+ height: '100%',
29
+ imageRendering: 'pixelated',
30
+ background: '#fff',
31
+ appearance: 'none',
32
+ border: 'none',
33
+ userSelect: 'none',
34
+ transition: theme.methods.transitions.make('opacity'),
35
+ '&[disabled]': {
36
+ opacity: 0.7,
37
+ pointerEvents: 'none'
70
38
  }
71
- }), { name: 'onesy-Whiteboard' });
39
+ },
40
+ ui: {
41
+ zIndex: 0
42
+ },
43
+ object: {
44
+ cursor: 'crosshair'
45
+ },
46
+ pen: {
47
+ cursor: 'crosshair'
48
+ },
49
+ pan: {
50
+ cursor: 'grab'
51
+ },
52
+ panning: {
53
+ cursor: 'grabbing'
54
+ },
55
+ zoom: {
56
+ cursor: 'zoom-in'
57
+ },
58
+ eraser: {
59
+ cursor: 'not-allowed'
60
+ },
61
+ image: {
62
+ cursor: 'copy'
63
+ },
64
+ text: {
65
+ cursor: 'text'
66
+ }
67
+ }), {
68
+ name: 'onesy-Whiteboard'
69
+ });
72
70
  const colorSelect = 'hsl(244deg 64% 64%)';
73
71
  const colorSelectBackground = 'hsla(244deg 64% 64% / 4%)';
74
- const Whiteboard = react_1.default.forwardRef((props_, ref) => {
75
- const theme = (0, style_react_1.useOnesyTheme)();
76
- 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.onesyWhiteboard) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]);
77
- 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]);
78
- const { valueDefault, onChange: onChangeProps,
79
- // 10%
80
- minZoom = 10,
81
- // 400%
82
- maxZoom = 4000, grid: gridProps = true, settings = {
72
+ const Whiteboard = /*#__PURE__*/_react.default.forwardRef((props_, ref) => {
73
+ const theme = (0, _styleReact.useOnesyTheme)();
74
+ const props = _react.default.useMemo(() => {
75
+ var _theme$ui, _theme$ui2;
76
+ 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.onesyWhiteboard) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_);
77
+ }, [props_]);
78
+ const Line = _react.default.useMemo(() => {
79
+ var _theme$elements;
80
+ return (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Line) || _Line.default;
81
+ }, [theme]);
82
+ const {
83
+ valueDefault,
84
+ onChange: onChangeProps,
85
+ // 10%
86
+ minZoom = 10,
87
+ // 400%
88
+ maxZoom = 4000,
89
+ grid: gridProps = true,
90
+ settings = {
83
91
  lineCap: 'round',
84
92
  lineJoin: 'round',
85
93
  lineWidth: 10,
86
94
  fillStyle: 'lightgreen',
87
95
  strokeStyle: 'lightgreen',
88
96
  globalAlpha: 0.44
89
- }, className } = props, other = __rest(props, ["valueDefault", "onChange", "minZoom", "maxZoom", "grid", "settings", "className"]);
90
- const { classes } = useStyle();
91
- const [size, setSize] = react_1.default.useState({});
92
- const [tool, setTool] = react_1.default.useState('select');
93
- const [mouseDown, setMouseDown] = react_1.default.useState(false);
94
- const [grid, setGrid] = react_1.default.useState(gridProps);
95
- const [loaded, setLoaded] = react_1.default.useState(false);
96
- const refs = {
97
- root: react_1.default.useRef(null),
98
- ui: react_1.default.useRef(null),
99
- interactive: react_1.default.useRef(null),
100
- on: react_1.default.useRef(false),
101
- items: react_1.default.useRef(valueDefault || []),
102
- previous: react_1.default.useRef({ x: 0, y: 0 }),
103
- previousMouse: react_1.default.useRef({ x: 0, y: 0 }),
104
- moveStarted: react_1.default.useRef(false),
105
- undo: react_1.default.useRef([]),
106
- redo: react_1.default.useRef([]),
107
- move: react_1.default.useRef({ x: 0, y: 0 }),
108
- offset: react_1.default.useRef({ x: 0, y: 0 }),
109
- start: react_1.default.useRef({ x: 0, y: 0 }),
110
- end: react_1.default.useRef({ x: 0, y: 0 }),
111
- scale: react_1.default.useRef(1),
112
- mouseDown: react_1.default.useRef(mouseDown),
113
- mouseMove: react_1.default.useRef({
114
- current: { x: 0, y: 0 },
115
- previous: undefined,
116
- delta: { x: 0, y: 0 }
117
- }),
118
- tool: react_1.default.useRef(tool),
119
- previousTool: react_1.default.useRef(tool),
120
- toolUpdateAuto: react_1.default.useRef(false),
121
- remove: react_1.default.useRef([]),
122
- grid: react_1.default.useRef(grid),
123
- typing: react_1.default.useRef(false),
124
- image: react_1.default.useRef((0, utils_1.isEnvironment)('browser') && new Image()),
125
- aspectRatio: react_1.default.useRef(1),
126
- select: react_1.default.useRef(null),
127
- textActive: react_1.default.useRef(null),
128
- textSettings: react_1.default.useRef({
129
- lineHeight: 20,
130
- padding: 5,
131
- fillStyle: 'black'
132
- })
97
+ },
98
+ className
99
+ } = props,
100
+ other = (0, _objectWithoutProperties2.default)(props, _excluded);
101
+ const {
102
+ classes
103
+ } = useStyle();
104
+ const [size, setSize] = _react.default.useState({});
105
+ const [tool, setTool] = _react.default.useState('select');
106
+ const [mouseDown, setMouseDown] = _react.default.useState(false);
107
+ const [grid, setGrid] = _react.default.useState(gridProps);
108
+ const [loaded, setLoaded] = _react.default.useState(false);
109
+ const refs = {
110
+ root: _react.default.useRef(null),
111
+ ui: _react.default.useRef(null),
112
+ interactive: _react.default.useRef(null),
113
+ on: _react.default.useRef(false),
114
+ items: _react.default.useRef(valueDefault || []),
115
+ previous: _react.default.useRef({
116
+ x: 0,
117
+ y: 0
118
+ }),
119
+ previousMouse: _react.default.useRef({
120
+ x: 0,
121
+ y: 0
122
+ }),
123
+ moveStarted: _react.default.useRef(false),
124
+ undo: _react.default.useRef([]),
125
+ redo: _react.default.useRef([]),
126
+ move: _react.default.useRef({
127
+ x: 0,
128
+ y: 0
129
+ }),
130
+ offset: _react.default.useRef({
131
+ x: 0,
132
+ y: 0
133
+ }),
134
+ start: _react.default.useRef({
135
+ x: 0,
136
+ y: 0
137
+ }),
138
+ end: _react.default.useRef({
139
+ x: 0,
140
+ y: 0
141
+ }),
142
+ scale: _react.default.useRef(1),
143
+ mouseDown: _react.default.useRef(mouseDown),
144
+ mouseMove: _react.default.useRef({
145
+ current: {
146
+ x: 0,
147
+ y: 0
148
+ },
149
+ previous: undefined,
150
+ delta: {
151
+ x: 0,
152
+ y: 0
153
+ }
154
+ }),
155
+ tool: _react.default.useRef(tool),
156
+ previousTool: _react.default.useRef(tool),
157
+ toolUpdateAuto: _react.default.useRef(false),
158
+ remove: _react.default.useRef([]),
159
+ grid: _react.default.useRef(grid),
160
+ typing: _react.default.useRef(false),
161
+ image: _react.default.useRef((0, _utils.isEnvironment)('browser') && new Image()),
162
+ aspectRatio: _react.default.useRef(1),
163
+ select: _react.default.useRef(null),
164
+ textActive: _react.default.useRef(null),
165
+ textSettings: _react.default.useRef({
166
+ lineHeight: 20,
167
+ padding: 5,
168
+ fillStyle: 'black'
169
+ })
170
+ };
171
+ refs.mouseDown.current = mouseDown;
172
+ refs.tool.current = tool;
173
+ refs.grid.current = grid;
174
+ const init = _react.default.useCallback(() => {
175
+ // Todo
176
+ // items
177
+ // load all of the images in memory and attach theme to items as image elements
178
+ // once it's all done, setLoaded(true), render
179
+
180
+ setTimeout(() => {
181
+ render();
182
+ setLoaded(true);
183
+ }, 40);
184
+ }, []);
185
+ _react.default.useEffect(() => {
186
+ if (!['zoom'].includes(tool)) refs.previousTool.current = tool;
187
+ }, [tool]);
188
+ const onChange = _react.default.useCallback(() => {
189
+ if ((0, _utils.is)('function', onChangeProps)) onChangeProps(refs.items.current);
190
+ }, [onChangeProps]);
191
+ const getItems = _react.default.useCallback((selected = undefined) => refs.items.current.filter(item => selected === undefined || item.se === selected), []);
192
+ const getItem = _react.default.useCallback(() => refs.items.current[refs.items.current.length - 1], []);
193
+ const filterItems = _react.default.useCallback(() => {
194
+ const toRemove = refs.items.current.filter(item => {
195
+ var _item$s;
196
+ if (refs.tool.current === 'text' && item !== refs.textActive.current) item.se = false;
197
+ const lines = ((_item$s = item.s) === null || _item$s === void 0 ? void 0 : _item$s.lines) || [];
198
+ return !(item.v !== 't' || item === refs.textActive.current || lines.length > 1 || lines[0].length);
199
+ });
200
+ if (toRemove.length) remove(toRemove);
201
+ }, []);
202
+ const add = _react.default.useCallback(toAdd => {
203
+ const itemsAdd = (Array.isArray(toAdd) ? toAdd : [toAdd]).filter(Boolean);
204
+ const items = getItems();
205
+
206
+ // add to undo stack snapshot of current state
207
+ refs.undo.current.push([...items]);
208
+
209
+ // clear redo stack
210
+ refs.redo.current = [];
211
+ refs.items.current.push(...itemsAdd);
212
+ }, []);
213
+ const remove = _react.default.useCallback(toRemove => {
214
+ const itemsRemove = (Array.isArray(toRemove) ? toRemove : [toRemove]).filter(Boolean);
215
+ const items = getItems();
216
+ const IDs = itemsRemove === null || itemsRemove === void 0 ? void 0 : itemsRemove.map(item => item.i);
217
+ const toRemoveIDs = items.filter(item => IDs.includes(item.i)).map(item => item.i);
218
+ if (!toRemoveIDs) return;
219
+
220
+ // add to undo stack snapshot of current state
221
+ refs.undo.current.push([...items]);
222
+
223
+ // clear redo stack
224
+ refs.redo.current = [];
225
+ refs.items.current = refs.items.current.filter(item => !toRemoveIDs.includes(item.i));
226
+ }, []);
227
+ const reset = _react.default.useCallback(() => {
228
+ refs.on.current = false;
229
+ refs.moveStarted.current = false;
230
+ refs.image.current = null;
231
+
232
+ // new move start
233
+ refs.offset.current.x = refs.move.current.x;
234
+ refs.offset.current.y = refs.move.current.y;
235
+ }, []);
236
+ const transform = _react.default.useCallback(coordinate => coordinate / refs.scale.current, []);
237
+ const selectAll = _react.default.useCallback(() => {
238
+ return [...refs.items.current].filter(Boolean).map(item => {
239
+ item.se = true;
240
+ return item;
241
+ });
242
+ }, []);
243
+ const unselectAll = _react.default.useCallback(eventReact => {
244
+ const event = (eventReact === null || eventReact === void 0 ? void 0 : eventReact.nativeEvent) || eventReact;
245
+ const shift = event === null || event === void 0 ? void 0 : event.shiftKey;
246
+ return [...refs.items.current].filter(Boolean).map(item => {
247
+ if (shift) return item;
248
+ item.se = false;
249
+ return item;
250
+ });
251
+ }, []);
252
+ const onInteractionDown = _react.default.useCallback((body, eventReact) => {
253
+ const event = (eventReact === null || eventReact === void 0 ? void 0 : eventReact.nativeEvent) || eventReact;
254
+ const {
255
+ offsetX: x,
256
+ offsetY: y,
257
+ clientX,
258
+ clientY
259
+ } = body;
260
+ refs.on.current = true;
261
+ refs.previous.current = {
262
+ x,
263
+ y
133
264
  };
134
- refs.mouseDown.current = mouseDown;
135
- refs.tool.current = tool;
136
- refs.grid.current = grid;
137
- const init = react_1.default.useCallback(() => {
138
- // Todo
139
- // items
140
- // load all of the images in memory and attach theme to items as image elements
141
- // once it's all done, setLoaded(true), render
142
- setTimeout(() => {
143
- render();
144
- setLoaded(true);
145
- }, 40);
146
- }, []);
147
- react_1.default.useEffect(() => {
148
- if (!['zoom'].includes(tool))
149
- refs.previousTool.current = tool;
150
- }, [tool]);
151
- const onChange = react_1.default.useCallback(() => {
152
- if ((0, utils_1.is)('function', onChangeProps))
153
- onChangeProps(refs.items.current);
154
- }, [onChangeProps]);
155
- const getItems = react_1.default.useCallback((selected = undefined) => refs.items.current.filter(item => selected === undefined || item.se === selected), []);
156
- const getItem = react_1.default.useCallback(() => refs.items.current[refs.items.current.length - 1], []);
157
- const filterItems = react_1.default.useCallback(() => {
158
- const toRemove = refs.items.current.filter(item => {
159
- var _a;
160
- if (refs.tool.current === 'text' && item !== refs.textActive.current)
161
- item.se = false;
162
- const lines = ((_a = item.s) === null || _a === void 0 ? void 0 : _a.lines) || [];
163
- return !(item.v !== 't' || (item === refs.textActive.current || (lines.length > 1 || lines[0].length)));
164
- });
165
- if (toRemove.length)
166
- remove(toRemove);
167
- }, []);
168
- const add = react_1.default.useCallback((toAdd) => {
169
- const itemsAdd = (Array.isArray(toAdd) ? toAdd : [toAdd]).filter(Boolean);
170
- const items = getItems();
171
- // add to undo stack snapshot of current state
172
- refs.undo.current.push([...items]);
173
- // clear redo stack
174
- refs.redo.current = [];
175
- refs.items.current.push(...itemsAdd);
176
- }, []);
177
- const remove = react_1.default.useCallback((toRemove) => {
178
- const itemsRemove = (Array.isArray(toRemove) ? toRemove : [toRemove]).filter(Boolean);
179
- const items = getItems();
180
- const IDs = itemsRemove === null || itemsRemove === void 0 ? void 0 : itemsRemove.map(item => item.i);
181
- const toRemoveIDs = items.filter(item => IDs.includes(item.i)).map(item => item.i);
182
- if (!toRemoveIDs)
183
- return;
184
- // add to undo stack snapshot of current state
185
- refs.undo.current.push([...items]);
186
- // clear redo stack
187
- refs.redo.current = [];
188
- refs.items.current = refs.items.current.filter(item => !toRemoveIDs.includes(item.i));
189
- }, []);
190
- const reset = react_1.default.useCallback(() => {
191
- refs.on.current = false;
192
- refs.moveStarted.current = false;
193
- refs.image.current = null;
194
- // new move start
195
- refs.offset.current.x = refs.move.current.x;
196
- refs.offset.current.y = refs.move.current.y;
197
- }, []);
198
- const transform = react_1.default.useCallback((coordinate) => coordinate / refs.scale.current, []);
199
- const selectAll = react_1.default.useCallback(() => {
200
- return [...refs.items.current].filter(Boolean).map(item => {
201
- item.se = true;
202
- return item;
203
- });
204
- }, []);
205
- const unselectAll = react_1.default.useCallback((eventReact) => {
206
- const event = (eventReact === null || eventReact === void 0 ? void 0 : eventReact.nativeEvent) || eventReact;
207
- const shift = event === null || event === void 0 ? void 0 : event.shiftKey;
208
- return [...refs.items.current].filter(Boolean).map(item => {
209
- if (shift)
210
- return item;
211
- item.se = false;
212
- return item;
213
- });
214
- }, []);
215
- const onInteractionDown = react_1.default.useCallback((body, eventReact) => {
216
- var _a, _b;
217
- const event = (eventReact === null || eventReact === void 0 ? void 0 : eventReact.nativeEvent) || eventReact;
218
- const { offsetX: x, offsetY: y, clientX, clientY } = body;
219
- refs.on.current = true;
220
- refs.previous.current = { x, y };
221
- refs.mouseMove.current = {
222
- current: { x: 0, y: 0 },
223
- previous: undefined,
224
- delta: { x: 0, y: 0 }
225
- };
226
- const shift = event === null || event === void 0 ? void 0 : event.shiftKey;
227
- const ui = refs.ui.current.getContext('2d');
228
- const rect = refs.ui.current.getBoundingClientRect();
229
- refs.start.current.x = clientX - rect.left;
230
- refs.start.current.y = clientY - rect.top;
231
- refs.textActive.current = null;
232
- const start = refs.start.current;
233
- const startTransformed = {
234
- x: transform(start.x - refs.move.current.x),
235
- y: transform(start.y - refs.move.current.y)
265
+ refs.mouseMove.current = {
266
+ current: {
267
+ x: 0,
268
+ y: 0
269
+ },
270
+ previous: undefined,
271
+ delta: {
272
+ x: 0,
273
+ y: 0
274
+ }
275
+ };
276
+ const shift = event === null || event === void 0 ? void 0 : event.shiftKey;
277
+ const ui = refs.ui.current.getContext('2d');
278
+ const rect = refs.ui.current.getBoundingClientRect();
279
+ refs.start.current.x = clientX - rect.left;
280
+ refs.start.current.y = clientY - rect.top;
281
+ refs.textActive.current = null;
282
+ const start = refs.start.current;
283
+ const startTransformed = {
284
+ x: transform(start.x - refs.move.current.x),
285
+ y: transform(start.y - refs.move.current.y)
286
+ };
287
+ Object.keys(settings).forEach(item_ => ui[item_] = settings[item_]);
288
+ let item;
289
+ const items = getItems();
290
+ const t = refs.tool.current;
291
+ refs.select.current = null;
292
+ if (t === 'select') {
293
+ // z-index top to bottom order
294
+ const itemsReversed = [...items].reverse();
295
+ const itemsClicked = itemsReversed.filter(item_ => {
296
+ return item_.c && startTransformed.x >= item_.c[0] && startTransformed.x <= item_.c[0] + item_.c[2] && startTransformed.y >= item_.c[1] && startTransformed.y <= item_.c[1] + item_.c[3];
297
+ });
298
+ const itemsSelected = getItems(true);
299
+ const clicked = itemsClicked[0];
300
+ if (!clicked) {
301
+ unselectAll();
302
+ refs.select.current = {
303
+ p: [],
304
+ ar: []
236
305
  };
237
- Object.keys(settings).forEach(item_ => ui[item_] = settings[item_]);
238
- let item;
239
- const items = getItems();
240
- const t = refs.tool.current;
241
- refs.select.current = null;
242
- if (t === 'select') {
243
- // z-index top to bottom order
244
- const itemsReversed = [...items].reverse();
245
- const itemsClicked = itemsReversed.filter(item_ => {
246
- return item_.c && startTransformed.x >= item_.c[0] && startTransformed.x <= item_.c[0] + item_.c[2] && startTransformed.y >= item_.c[1] && startTransformed.y <= item_.c[1] + item_.c[3];
247
- });
248
- const itemsSelected = getItems(true);
249
- const clicked = itemsClicked[0];
250
- if (!clicked) {
251
- unselectAll();
252
- refs.select.current = { p: [], ar: [] };
253
- }
254
- if (!shift && !((clicked === null || clicked === void 0 ? void 0 : clicked.se) && itemsSelected.length > 1))
255
- unselectAll();
256
- if (clicked) {
257
- clicked.se = shift ? !clicked.se : true;
258
- }
259
- }
260
- else if (t === 'text') {
261
- const { lineHeight, padding } = refs.textSettings.current;
262
- const selectedText = items.find(item_ => item_.c && startTransformed.x >= item_.c[0] && startTransformed.x <= item_.c[0] + item_.c[2] && startTransformed.y >= item_.c[1] && startTransformed.y <= item_.c[1] + item_.c[3]);
263
- if (selectedText) {
264
- refs.textActive.current = selectedText;
265
- selectedText.se = true;
266
- const relativeY = startTransformed.y - selectedText.c[1] - padding;
267
- const lineIndex = Math.floor(relativeY / lineHeight);
268
- const clickedLine = ((_b = (_a = selectedText.s) === null || _a === void 0 ? void 0 : _a.lines) === null || _b === void 0 ? void 0 : _b[lineIndex]) || '';
269
- const relativeX = startTransformed.x - selectedText.c[0] - padding;
270
- let charIndex = clickedLine.length;
271
- for (let i = 0; i < clickedLine.length; i++) {
272
- if (relativeX < ui.measureText(clickedLine.slice(0, i + 1)).width) {
273
- charIndex = i;
274
- break;
275
- }
276
- }
277
- selectedText.s.cursor = { line: lineIndex, char: charIndex };
278
- }
279
- else {
280
- item = {
281
- i: (0, utils_1.getID)(),
282
- v: 't',
283
- p: [startTransformed.x, startTransformed.y],
284
- ar: [15, lineHeight + (padding * 2)],
285
- s: Object.assign(Object.assign({}, refs.textSettings.current), { lines: [''], cursor: { line: 0, char: 0 } }),
286
- se: true,
287
- a: date_1.OnesyDate.milliseconds
288
- };
289
- refs.textActive.current = item;
290
- }
291
- }
292
- else {
293
- // pen
294
- if (t === 'pen') {
295
- // point
296
- item = {
297
- i: (0, utils_1.getID)(),
298
- v: 'dp',
299
- p: [transform(x - refs.move.current.x), transform(y - refs.move.current.y)],
300
- ar: [ui.lineWidth / 2, 0, Math.PI * 2],
301
- s: (0, utils_1.copy)(settings),
302
- a: date_1.OnesyDate.milliseconds
303
- };
304
- }
305
- // circle, rectangle, line, line-arrow
306
- if (['circle', 'rectangle', 'triangle', 'line', 'line-arrow'].includes(t)) {
307
- item = {
308
- i: (0, utils_1.getID)(),
309
- p: [],
310
- ar: [],
311
- s: (0, utils_1.copy)(settings),
312
- a: date_1.OnesyDate.milliseconds
313
- };
314
- }
315
- // pan
316
- if (t === 'pan') {
317
- // new move start
318
- refs.offset.current.x = refs.move.current.x;
319
- refs.offset.current.y = refs.move.current.y;
320
- }
321
- // image
322
- else if (t === 'image' && refs.image.current.complete && refs.image.current.src) {
323
- refs.aspectRatio.current = refs.image.current.width / refs.image.current.height;
324
- // Todo
325
- // add url of the image
326
- // instead of embeding the image
327
- item = {
328
- i: (0, utils_1.getID)(),
329
- v: 'i',
330
- p: [],
331
- ar: [],
332
- s: {
333
- // Todo
334
- // remove in the future
335
- image: refs.image.current,
336
- aspectRatio: refs.aspectRatio.current
337
- },
338
- a: date_1.OnesyDate.milliseconds
339
- };
340
- }
341
- }
342
- if (item)
343
- add(item);
344
- filterItems();
345
- // render
346
- render();
347
- setMouseDown(true);
348
- }, []);
349
- const onMouseDown = react_1.default.useCallback((event) => {
350
- const { offsetX, offsetY, clientX, clientY } = event.nativeEvent;
351
- onInteractionDown({ offsetX, offsetY, clientX, clientY }, event);
352
- }, [onInteractionDown]);
353
- const onTouchStart = react_1.default.useCallback((event) => {
354
- // Get the first touch point
355
- const touch = event.touches[0];
356
- const { clientX, clientY } = touch;
357
- let { offsetX, offsetY } = touch;
358
- const targetElement = touch.target;
359
- if (targetElement instanceof HTMLElement) {
360
- // Get the bounding rectangle of the target element
361
- const rect = targetElement.getBoundingClientRect();
362
- // Calculate the offsetX and offsetY
363
- offsetX = touch.clientX - rect.left;
364
- offsetY = touch.clientY - rect.top;
306
+ }
307
+ if (!shift && !(clicked !== null && clicked !== void 0 && clicked.se && itemsSelected.length > 1)) unselectAll();
308
+ if (clicked) {
309
+ clicked.se = shift ? !clicked.se : true;
310
+ }
311
+ } else if (t === 'text') {
312
+ const {
313
+ lineHeight,
314
+ padding
315
+ } = refs.textSettings.current;
316
+ const selectedText = items.find(item_ => item_.c && startTransformed.x >= item_.c[0] && startTransformed.x <= item_.c[0] + item_.c[2] && startTransformed.y >= item_.c[1] && startTransformed.y <= item_.c[1] + item_.c[3]);
317
+ if (selectedText) {
318
+ var _selectedText$s;
319
+ refs.textActive.current = selectedText;
320
+ selectedText.se = true;
321
+ const relativeY = startTransformed.y - selectedText.c[1] - padding;
322
+ const lineIndex = Math.floor(relativeY / lineHeight);
323
+ const clickedLine = ((_selectedText$s = selectedText.s) === null || _selectedText$s === void 0 || (_selectedText$s = _selectedText$s.lines) === null || _selectedText$s === void 0 ? void 0 : _selectedText$s[lineIndex]) || '';
324
+ const relativeX = startTransformed.x - selectedText.c[0] - padding;
325
+ let charIndex = clickedLine.length;
326
+ for (let i = 0; i < clickedLine.length; i++) {
327
+ if (relativeX < ui.measureText(clickedLine.slice(0, i + 1)).width) {
328
+ charIndex = i;
329
+ break;
330
+ }
365
331
  }
366
- onInteractionDown({ offsetX, offsetY, clientX, clientY }, event);
367
- }, [onInteractionDown]);
368
- const removeItems = react_1.default.useCallback(() => {
369
- // remove
370
- if (refs.remove.current.length) {
371
- const toRemove = [];
372
- for (const item of refs.remove.current) {
373
- const index = refs.items.current.findIndex(itemItems => itemItems === item);
374
- if (index > -1)
375
- toRemove.push(item);
376
- }
377
- if (toRemove.length)
378
- remove(toRemove);
379
- refs.remove.current = [];
380
- }
381
- }, []);
382
- const onUpdateCoordinates = react_1.default.useCallback(() => {
383
- const items = getItems();
384
- items.forEach(item => {
385
- const p = (item === null || item === void 0 ? void 0 : item.p) || [];
386
- const ar = (item === null || item === void 0 ? void 0 : item.ar) || [];
387
- const s = (item === null || item === void 0 ? void 0 : item.s) || {};
388
- if (p.length) {
389
- // cache
390
- // x1, y1, width. height for position on the screen
391
- const v = item.v;
392
- // draw point
393
- if (v === 'dp') {
394
- const lineWidth = s.lineWidth || 10;
395
- item.c = [
396
- p[0] - (lineWidth / 2),
397
- p[1] - (lineWidth / 2),
398
- lineWidth,
399
- lineWidth
400
- ];
401
- }
402
- // draw line
403
- else if (v === 'dl') {
404
- const x = [];
405
- const y = [];
406
- for (let i = 0; i < p.length; i += 2) {
407
- x.push(p[i]);
408
- y.push(p[i + 1]);
409
- }
410
- const xMin = Math.min(...x);
411
- const yMin = Math.min(...y);
412
- const xMax = Math.max(...x);
413
- const yMax = Math.max(...y);
414
- item.c = [
415
- xMin,
416
- yMin,
417
- xMax - xMin,
418
- yMax - yMin
419
- ];
420
- }
421
- // object line, object arrow
422
- else if (['ol', 'oa'].includes(v)) {
423
- const x = [p[0], ar[0]];
424
- const y = [p[1], ar[1]];
425
- const xMin = Math.min(...x);
426
- const yMin = Math.min(...y);
427
- const xMax = Math.max(...x);
428
- const yMax = Math.max(...y);
429
- item.c = [
430
- xMin,
431
- yMin,
432
- xMax - xMin,
433
- yMax - yMin
434
- ];
435
- }
436
- // object rectangle, object square
437
- else if (['or', 'os'].includes(v)) {
438
- item.c = [
439
- ...p,
440
- ...ar
441
- ];
442
- }
443
- // object circle, object ellipse
444
- else if (['oc', 'oe'].includes(v)) {
445
- if (v === 'oc') {
446
- item.c = [
447
- p[0] - ar[0],
448
- p[1] - ar[0],
449
- ar[0] * 2,
450
- ar[0] * 2
451
- ];
452
- }
453
- else {
454
- item.c = [
455
- p[0] - ar[0],
456
- p[1] - ar[1],
457
- ar[0] * 2,
458
- ar[1] * 2
459
- ];
460
- }
461
- }
462
- // object triangle, object triangle equilateral
463
- else if (['ot', 'ote'].includes(v)) {
464
- const [x1, y1, x2] = p;
465
- const { height } = s;
466
- item.c = [
467
- x1,
468
- y1 - height,
469
- x2 - x1,
470
- height
471
- ];
472
- }
473
- // image
474
- else if (['i', 't'].includes(v)) {
475
- item.c = [
476
- ...p,
477
- ...ar
478
- ];
479
- }
332
+ selectedText.s.cursor = {
333
+ line: lineIndex,
334
+ char: charIndex
335
+ };
336
+ } else {
337
+ item = {
338
+ i: (0, _utils.getID)(),
339
+ v: 't',
340
+ p: [startTransformed.x, startTransformed.y],
341
+ ar: [15, lineHeight + padding * 2],
342
+ s: _objectSpread(_objectSpread({}, refs.textSettings.current), {}, {
343
+ lines: [''],
344
+ cursor: {
345
+ line: 0,
346
+ char: 0
480
347
  }
481
- });
482
- }, []);
483
- const onSelect = react_1.default.useCallback(() => {
484
- const select = refs.select.current;
485
- if (!select)
486
- return;
487
- const px1 = select.p[0];
488
- const px2 = px1 + select.ar[0];
489
- const py1 = select.p[1];
490
- const py2 = py1 + select.ar[1];
491
- const min = {
492
- x: Math.min(px1, px2),
493
- y: Math.min(py1, py2)
348
+ }),
349
+ se: true,
350
+ a: _date.OnesyDate.milliseconds
494
351
  };
495
- const max = {
496
- x: Math.max(px1, px2),
497
- y: Math.max(py1, py2)
352
+ refs.textActive.current = item;
353
+ }
354
+ } else {
355
+ // pen
356
+ if (t === 'pen') {
357
+ // point
358
+ item = {
359
+ i: (0, _utils.getID)(),
360
+ v: 'dp',
361
+ p: [transform(x - refs.move.current.x), transform(y - refs.move.current.y)],
362
+ ar: [ui.lineWidth / 2, 0, Math.PI * 2],
363
+ s: (0, _utils.copy)(settings),
364
+ a: _date.OnesyDate.milliseconds
498
365
  };
499
- const items = getItems();
500
- items.forEach(item => {
501
- const { c } = item;
502
- const [x1, y1] = c;
503
- let [x2, y2] = c;
504
- x2 = x1 + x2;
505
- y2 = y1 + y2;
506
- const minItem = {
507
- x: Math.min(x1, x2),
508
- y: Math.min(y1, y2)
509
- };
510
- const maxItem = {
511
- x: Math.max(x1, x2),
512
- y: Math.max(y1, y2)
513
- };
514
- const selected = (minItem.x >= min.x && maxItem.x <= max.x) && (minItem.y >= min.y && maxItem.y <= max.y);
515
- if (selected)
516
- item.se = true;
517
- });
518
- }, []);
519
- const onMouseUp = react_1.default.useCallback((event) => {
520
- if (refs.mouseDown.current) {
521
- refs.select.current = null;
522
- // update coordinates
523
- onUpdateCoordinates();
524
- // reset
525
- reset();
526
- // remove
527
- removeItems();
528
- console.log('items', refs.items.current);
529
- // onChange
530
- onChange();
531
- setMouseDown(false);
532
- if (['circle', 'rectangle', 'triangle', 'line', 'line-arrow', 'image'].includes(refs.previousTool.current)) {
533
- setTool('select');
534
- }
535
- render();
366
+ }
367
+ // circle, rectangle, line, line-arrow
368
+ if (['circle', 'rectangle', 'triangle', 'line', 'line-arrow'].includes(t)) {
369
+ item = {
370
+ i: (0, _utils.getID)(),
371
+ p: [],
372
+ ar: [],
373
+ s: (0, _utils.copy)(settings),
374
+ a: _date.OnesyDate.milliseconds
375
+ };
376
+ }
377
+ // pan
378
+ if (t === 'pan') {
379
+ // new move start
380
+ refs.offset.current.x = refs.move.current.x;
381
+ refs.offset.current.y = refs.move.current.y;
382
+ }
383
+ // image
384
+ else if (t === 'image' && refs.image.current.complete && refs.image.current.src) {
385
+ refs.aspectRatio.current = refs.image.current.width / refs.image.current.height;
386
+
387
+ // Todo
388
+ // add url of the image
389
+ // instead of embeding the image
390
+ item = {
391
+ i: (0, _utils.getID)(),
392
+ v: 'i',
393
+ p: [],
394
+ ar: [],
395
+ s: {
396
+ // Todo
397
+ // remove in the future
398
+ image: refs.image.current,
399
+ aspectRatio: refs.aspectRatio.current
400
+ },
401
+ a: _date.OnesyDate.milliseconds
402
+ };
403
+ }
404
+ }
405
+ if (item) add(item);
406
+ filterItems();
407
+
408
+ // render
409
+ render();
410
+ setMouseDown(true);
411
+ }, []);
412
+ const onMouseDown = _react.default.useCallback(event => {
413
+ const {
414
+ offsetX,
415
+ offsetY,
416
+ clientX,
417
+ clientY
418
+ } = event.nativeEvent;
419
+ onInteractionDown({
420
+ offsetX,
421
+ offsetY,
422
+ clientX,
423
+ clientY
424
+ }, event);
425
+ }, [onInteractionDown]);
426
+ const onTouchStart = _react.default.useCallback(event => {
427
+ // Get the first touch point
428
+ const touch = event.touches[0];
429
+ const {
430
+ clientX,
431
+ clientY
432
+ } = touch;
433
+ let {
434
+ offsetX,
435
+ offsetY
436
+ } = touch;
437
+ const targetElement = touch.target;
438
+ if (targetElement instanceof HTMLElement) {
439
+ // Get the bounding rectangle of the target element
440
+ const rect = targetElement.getBoundingClientRect();
441
+
442
+ // Calculate the offsetX and offsetY
443
+ offsetX = touch.clientX - rect.left;
444
+ offsetY = touch.clientY - rect.top;
445
+ }
446
+ onInteractionDown({
447
+ offsetX,
448
+ offsetY,
449
+ clientX,
450
+ clientY
451
+ }, event);
452
+ }, [onInteractionDown]);
453
+ const removeItems = _react.default.useCallback(() => {
454
+ // remove
455
+ if (refs.remove.current.length) {
456
+ const toRemove = [];
457
+ for (const item of refs.remove.current) {
458
+ const index = refs.items.current.findIndex(itemItems => itemItems === item);
459
+ if (index > -1) toRemove.push(item);
460
+ }
461
+ if (toRemove.length) remove(toRemove);
462
+ refs.remove.current = [];
463
+ }
464
+ }, []);
465
+ const onUpdateCoordinates = _react.default.useCallback(() => {
466
+ const items = getItems();
467
+ items.forEach(item => {
468
+ const p = (item === null || item === void 0 ? void 0 : item.p) || [];
469
+ const ar = (item === null || item === void 0 ? void 0 : item.ar) || [];
470
+ const s = (item === null || item === void 0 ? void 0 : item.s) || {};
471
+ if (p.length) {
472
+ // cache
473
+ // x1, y1, width. height for position on the screen
474
+ const v = item.v;
475
+
476
+ // draw point
477
+ if (v === 'dp') {
478
+ const lineWidth = s.lineWidth || 10;
479
+ item.c = [p[0] - lineWidth / 2, p[1] - lineWidth / 2, lineWidth, lineWidth];
536
480
  }
537
- }, [onChange]);
538
- const updateTextBoxDimensions = react_1.default.useCallback((item) => {
539
- const ui = refs.ui.current.getContext('2d');
540
- const { lineHeight, padding } = refs.textSettings.current;
541
- ui.font = '16px Arial';
542
- const maxWidth = Math.max(...item.s.lines.map(line => ui.measureText(line).width));
543
- item.ar[0] = maxWidth + padding * 2.5;
544
- item.ar[1] = item.s.lines.length * lineHeight + padding * 2;
545
- }, []);
546
- const getPath = react_1.default.useCallback((item) => {
547
- const path = new Path2D();
548
- const { v, p, ar } = item;
549
481
  // draw line
550
- if (v === 'dl') {
551
- const points = (0, utils_1.arrayToParts)(p, 2);
552
- for (let i = 0; i < points.length - 1; i++) {
553
- const current = points[i];
554
- const next = points[i + 1];
555
- // calculate the control point for the curve
556
- const midX = (current[0] + next[0]) / 2;
557
- const midY = (current[1] + next[1]) / 2;
558
- if (i === 0) {
559
- // start from the first point
560
- path.moveTo(current[0], current[1]);
561
- }
562
- path.quadraticCurveTo(current[0], current[1], midX, midY);
563
- }
482
+ else if (v === 'dl') {
483
+ const x = [];
484
+ const y = [];
485
+ for (let i = 0; i < p.length; i += 2) {
486
+ x.push(p[i]);
487
+ y.push(p[i + 1]);
488
+ }
489
+ const xMin = Math.min(...x);
490
+ const yMin = Math.min(...y);
491
+ const xMax = Math.max(...x);
492
+ const yMax = Math.max(...y);
493
+ item.c = [xMin, yMin, xMax - xMin, yMax - yMin];
564
494
  }
565
- // draw point, object circle
566
- else if (['dp', 'oc'].includes(v) && ar.length === 3) {
567
- path.arc(p[0], p[1], ...ar);
568
- }
569
- // object ellipse
570
- else if (v === 'oe' && ar.length === 5) {
571
- path.ellipse(p[0], p[1], ...ar);
495
+ // object line, object arrow
496
+ else if (['ol', 'oa'].includes(v)) {
497
+ const x = [p[0], ar[0]];
498
+ const y = [p[1], ar[1]];
499
+ const xMin = Math.min(...x);
500
+ const yMin = Math.min(...y);
501
+ const xMax = Math.max(...x);
502
+ const yMax = Math.max(...y);
503
+ item.c = [xMin, yMin, xMax - xMin, yMax - yMin];
572
504
  }
573
- // object rectangle
505
+ // object rectangle, object square
574
506
  else if (['or', 'os'].includes(v)) {
575
- path.roundRect(p[0], p[1], ...ar);
507
+ item.c = [...p, ...ar];
576
508
  }
577
- // object line
578
- else if (['ol', 'oa'].includes(v) && ar.length === 2) {
579
- path.moveTo(p[0], p[1]);
580
- path.lineTo(...ar);
581
- // draw an arrow
582
- if (v === 'oa') {
583
- // Length of the arrowhead
584
- const headLength = 40;
585
- const angle = Math.atan2(ar[1] - p[1], ar[0] - p[0]);
586
- path.moveTo(ar[0], ar[1]);
587
- path.lineTo(ar[0] - headLength * Math.cos(angle - Math.PI / 6), ar[1] - headLength * Math.sin(angle - Math.PI / 6));
588
- path.moveTo(ar[0], ar[1]);
589
- path.lineTo(ar[0] - headLength * Math.cos(angle + Math.PI / 6), ar[1] - headLength * Math.sin(angle + Math.PI / 6));
590
- }
509
+ // object circle, object ellipse
510
+ else if (['oc', 'oe'].includes(v)) {
511
+ if (v === 'oc') {
512
+ item.c = [p[0] - ar[0], p[1] - ar[0], ar[0] * 2, ar[0] * 2];
513
+ } else {
514
+ item.c = [p[0] - ar[0], p[1] - ar[1], ar[0] * 2, ar[1] * 2];
515
+ }
591
516
  }
592
- // object triangle
517
+ // object triangle, object triangle equilateral
593
518
  else if (['ot', 'ote'].includes(v)) {
594
- path.moveTo(p[0], p[1]);
595
- path.lineTo(p[2], p[3]);
596
- path.lineTo(p[4], p[5]);
597
- path.closePath();
598
- }
599
- return path;
600
- }, []);
601
- const draw = react_1.default.useCallback((item) => {
602
- var _a, _b;
603
- const ui = refs.ui.current.getContext('2d');
604
- // settings
605
- Object.keys(item.s || {}).forEach(key => { var _a; return ui[key] = (_a = item.s) === null || _a === void 0 ? void 0 : _a[key]; });
606
- ui.globalAlpha = refs.remove.current.includes(item) ? 0.25 : ((_a = item.s) === null || _a === void 0 ? void 0 : _a.globalAlpha) !== undefined ? (_b = item.s) === null || _b === void 0 ? void 0 : _b.globalAlpha : 1;
607
- ui.beginPath();
608
- const path = getPath(item);
609
- const v = item.v;
610
- if (['dp'].includes(v))
611
- ui.fill(path);
612
- else if (['dl', 'oc', 'oe', 'or', 'os', 'ol', 'oa', 'ot', 'ote'].includes(v))
613
- ui.stroke(path);
614
- }, []);
615
- const drawGrid = react_1.default.useCallback(() => {
616
- const uiCanvas = refs.ui.current;
617
- const ui = refs.ui.current.getContext('2d');
618
- const zoom = refs.scale.current;
619
- const gridSize = 70;
620
- const offsetX = refs.move.current.x / zoom;
621
- const offsetY = refs.move.current.y / zoom;
622
- // Calculate start positions based on offsets
623
- const startX = Math.floor(-offsetX / gridSize) * gridSize;
624
- const startY = Math.floor(-offsetY / gridSize) * gridSize;
625
- const width = (uiCanvas.clientWidth * 1.5) / (zoom < 1 ? zoom : 1);
626
- const height = (uiCanvas.clientHeight * 1.5) / (zoom < 1 ? zoom : 1);
627
- if (gridSize < 30)
628
- return;
629
- // Draw main grid lines
630
- ui.globalAlpha = 1;
631
- ui.lineWidth = (zoom < 0.5 ? 0.3 : zoom <= 1 ? 0.5 : 0.7) / zoom;
632
- ui.strokeStyle = '#ccc';
633
- // grid
634
- for (let x = startX; x < width + Math.abs(startX); x += gridSize) {
635
- ui.beginPath();
636
- ui.moveTo(x, startY);
637
- ui.lineTo(x, height + startY);
638
- ui.stroke();
639
- }
640
- for (let y = startY; y < height + Math.abs(startY); y += gridSize) {
641
- ui.beginPath();
642
- ui.moveTo(startX, y);
643
- ui.lineTo(width + startX, y);
644
- ui.stroke();
519
+ const [x1, y1, x2] = p;
520
+ const {
521
+ height
522
+ } = s;
523
+ item.c = [x1, y1 - height, x2 - x1, height];
645
524
  }
646
- // subgrid
647
- if (gridSize * zoom > 100) {
648
- // Draw subgrid lines if zoomed in
649
- const subGridSize = gridSize / 5;
650
- ui.lineWidth = (zoom <= 5 ? 0.6 : zoom <= 10 ? 0.8 : 1) / zoom;
651
- ui.strokeStyle = '#ddd';
652
- const dash = zoom < 1 ? 3 * zoom : 3 / zoom;
653
- ui.setLineDash([dash, dash]);
654
- for (let x = startX; x < width + Math.abs(startX); x += subGridSize) {
655
- // without overlap
656
- if (!(x % gridSize))
657
- continue;
658
- ui.beginPath();
659
- ui.moveTo(x, startY);
660
- ui.lineTo(x, height + startY);
661
- ui.stroke();
662
- }
663
- for (let y = startY; y < height + Math.abs(startY); y += subGridSize) {
664
- // without overlap
665
- if (!(y % gridSize))
666
- continue;
667
- ui.beginPath();
668
- ui.moveTo(startX, y);
669
- ui.lineTo(width + startX, y);
670
- ui.stroke();
671
- }
672
- ui.setLineDash([]); // Reset line dash
525
+ // image
526
+ else if (['i', 't'].includes(v)) {
527
+ item.c = [...p, ...ar];
673
528
  }
674
- }, []);
675
- const drawImage = react_1.default.useCallback((item) => {
676
- const ui = refs.ui.current.getContext('2d');
677
- ui.globalAlpha = 1;
678
- ui.drawImage(item.s.image || refs.image.current, ...item.p, ...item.ar);
679
- }, []);
680
- const drawCursor = react_1.default.useCallback((item) => {
681
- if (!item || !item.s.cursor)
682
- return;
683
- const ui = refs.ui.current.getContext('2d');
684
- const { line, char } = item.s.cursor;
685
- const currentLine = item.s.lines[line] || '';
686
- const textWidth = ui.measureText(currentLine.slice(0, char)).width;
687
- const { padding, lineHeight } = refs.textSettings.current;
688
- const cursorX = item.p[0] + padding + textWidth;
689
- const cursorY = item.p[1] + padding + (line + 1) * lineHeight;
690
- ui.fillStyle = 'black';
691
- ui.fillRect(cursorX, cursorY - lineHeight + 3, 2, lineHeight - 5);
692
- }, []);
693
- const drawText = react_1.default.useCallback((item) => {
694
- const ui = refs.ui.current.getContext('2d');
695
- const zoom = refs.scale.current;
696
- const [x, y] = item.p;
697
- const [width, height] = item.ar;
698
- const { lineHeight, padding, fillStyle } = refs.textSettings.current;
699
- const selected = (refs.tool.current === 'text' && item.se);
700
- // Draw the box
701
- ui.globalAlpha = 1;
702
- ui.fillStyle = 'transparent';
703
- ui.fillRect(x, y, width, height);
704
- ui.lineWidth = 1 / zoom;
705
- ui.strokeStyle = selected ? colorSelect : 'transparent';
706
- ui.strokeRect(x, y, width, height);
707
- // Draw the text
708
- ui.fillStyle = fillStyle || 'black';
709
- ui.font = '16px Arial';
710
- item.s.lines.forEach((line, index) => {
711
- ui.fillText(line, x + padding, y + padding + (index + 1) * lineHeight - 5);
712
- });
713
- if (selected)
714
- drawCursor(item);
715
- }, []);
716
- const drawSelect = react_1.default.useCallback((item) => {
717
- const ui = refs.ui.current.getContext('2d');
718
- const [x, y, width, height] = item.c || [];
719
- const path = new Path2D();
720
- path.rect(x, y, width, height);
721
- ui.globalAlpha = 1;
722
- ui.strokeStyle = colorSelect;
723
- ui.lineCap = 'square';
724
- ui.lineJoin = 'bevel';
725
- ui.lineWidth = 1 / refs.scale.current;
726
- ui.stroke(path);
727
- }, []);
728
- const drawSelection = react_1.default.useCallback(() => {
729
- const ui = refs.ui.current.getContext('2d');
730
- const zoom = refs.scale.current;
731
- // canvas selection
732
- const select = refs.select.current;
733
- if (select) {
734
- ui.globalAlpha = 1;
735
- ui.globalCompositeOperation = 'source-over';
736
- ui.lineWidth = 1 / zoom;
737
- ui.lineCap = 'square';
738
- ui.lineJoin = 'bevel';
739
- ui.strokeStyle = colorSelect;
740
- ui.fillStyle = colorSelectBackground;
741
- const path = getPath(select);
742
- ui.fill(path);
743
- ui.stroke(path);
529
+ }
530
+ });
531
+ }, []);
532
+ const onSelect = _react.default.useCallback(() => {
533
+ const select = refs.select.current;
534
+ if (!select) return;
535
+ const px1 = select.p[0];
536
+ const px2 = px1 + select.ar[0];
537
+ const py1 = select.p[1];
538
+ const py2 = py1 + select.ar[1];
539
+ const min = {
540
+ x: Math.min(px1, px2),
541
+ y: Math.min(py1, py2)
542
+ };
543
+ const max = {
544
+ x: Math.max(px1, px2),
545
+ y: Math.max(py1, py2)
546
+ };
547
+ const items = getItems();
548
+ items.forEach(item => {
549
+ const {
550
+ c
551
+ } = item;
552
+ const [x1, y1] = c;
553
+ let [x2, y2] = c;
554
+ x2 = x1 + x2;
555
+ y2 = y1 + y2;
556
+ const minItem = {
557
+ x: Math.min(x1, x2),
558
+ y: Math.min(y1, y2)
559
+ };
560
+ const maxItem = {
561
+ x: Math.max(x1, x2),
562
+ y: Math.max(y1, y2)
563
+ };
564
+ const selected = minItem.x >= min.x && maxItem.x <= max.x && minItem.y >= min.y && maxItem.y <= max.y;
565
+ if (selected) item.se = true;
566
+ });
567
+ }, []);
568
+ const onMouseUp = _react.default.useCallback(event => {
569
+ if (refs.mouseDown.current) {
570
+ refs.select.current = null;
571
+
572
+ // update coordinates
573
+ onUpdateCoordinates();
574
+
575
+ // reset
576
+ reset();
577
+
578
+ // remove
579
+ removeItems();
580
+ console.log('items', refs.items.current);
581
+
582
+ // onChange
583
+ onChange();
584
+ setMouseDown(false);
585
+ if (['circle', 'rectangle', 'triangle', 'line', 'line-arrow', 'image'].includes(refs.previousTool.current)) {
586
+ setTool('select');
587
+ }
588
+ render();
589
+ }
590
+ }, [onChange]);
591
+ const updateTextBoxDimensions = _react.default.useCallback(item => {
592
+ const ui = refs.ui.current.getContext('2d');
593
+ const {
594
+ lineHeight,
595
+ padding
596
+ } = refs.textSettings.current;
597
+ ui.font = '16px Arial';
598
+ const maxWidth = Math.max(...item.s.lines.map(line => ui.measureText(line).width));
599
+ item.ar[0] = maxWidth + padding * 2.5;
600
+ item.ar[1] = item.s.lines.length * lineHeight + padding * 2;
601
+ }, []);
602
+ const getPath = _react.default.useCallback(item => {
603
+ const path = new Path2D();
604
+ const {
605
+ v,
606
+ p,
607
+ ar
608
+ } = item;
609
+
610
+ // draw line
611
+ if (v === 'dl') {
612
+ const points = (0, _utils.arrayToParts)(p, 2);
613
+ for (let i = 0; i < points.length - 1; i++) {
614
+ const current = points[i];
615
+ const next = points[i + 1];
616
+
617
+ // calculate the control point for the curve
618
+ const midX = (current[0] + next[0]) / 2;
619
+ const midY = (current[1] + next[1]) / 2;
620
+ if (i === 0) {
621
+ // start from the first point
622
+ path.moveTo(current[0], current[1]);
744
623
  }
745
- }, []);
746
- const render = react_1.default.useCallback(() => {
747
- const ui = refs.ui.current.getContext('2d');
748
- const items = refs.items.current.filter(Boolean);
749
- // methods
750
- ui.clearRect(0, 0, refs.ui.current.width, refs.ui.current.height);
751
- ui.save();
752
- // pan
753
- ui.translate(refs.move.current.x, refs.move.current.y);
754
- // zoom
755
- ui.scale(refs.scale.current, refs.scale.current);
756
- // grid
757
- if (refs.grid.current)
758
- drawGrid();
759
- // draw
760
- items.forEach(item => {
761
- // image
762
- if (item.v === 'i' && item.ar.length === 2)
763
- drawImage(item);
764
- // text
765
- else if (item.v === 't')
766
- drawText(item);
767
- // other
768
- else
769
- draw(item);
770
- // select
771
- if (item.se)
772
- drawSelect(item);
773
- });
774
- // canvas selection
775
- drawSelection();
776
- ui.restore();
777
- }, []);
778
- // Snap angle to nearest multiple of 15 degrees
779
- const snapToAngle = react_1.default.useCallback((dx, dy) => {
780
- // Current angle in radians
781
- const angle = Math.atan2(dy, dx);
782
- // Snap to nearest 15 degrees
783
- const snappedAngle = Math.round(angle / (Math.PI / 12)) * (Math.PI / 12);
784
- // Length of the vector
785
- const length = Math.sqrt(dx * dx + dy * dy);
786
- return {
787
- x: Math.cos(snappedAngle) * length,
788
- y: Math.sin(snappedAngle) * length
789
- };
790
- }, []);
791
- const onMoveItems = react_1.default.useCallback((x, y) => {
792
- const itemsSelected = getItems(true);
793
- itemsSelected.forEach(item => {
794
- const v = item.v;
795
- // draw line
796
- if (v === 'dl') {
797
- item.p = item.p.map((value, index) => {
798
- return index % 2 ? value + y : value + x;
799
- });
800
- }
801
- // rectangle, draw point, object circle, ellipse, object line, object arrow, object triangle, image, text
802
- if (['or', 'os', 'dp', 'oc', 'oe', 'ol', 'oa', 'ot', 'ote', 'i', 't'].includes(v)) {
803
- item.p[0] += x;
804
- item.p[1] += y;
805
- }
806
- // object line
807
- if (['ol', 'oa'].includes(v)) {
808
- item.ar[0] += x;
809
- item.ar[1] += y;
810
- }
811
- // object triangle
812
- if (['ot', 'ote'].includes(v)) {
813
- item.p[2] += x;
814
- item.p[4] += x;
815
- item.p[3] += y;
816
- item.p[5] += y;
817
- }
624
+ path.quadraticCurveTo(current[0], current[1], midX, midY);
625
+ }
626
+ }
627
+ // draw point, object circle
628
+ else if (['dp', 'oc'].includes(v) && ar.length === 3) {
629
+ path.arc(p[0], p[1], ...ar);
630
+ }
631
+ // object ellipse
632
+ else if (v === 'oe' && ar.length === 5) {
633
+ path.ellipse(p[0], p[1], ...ar);
634
+ }
635
+ // object rectangle
636
+ else if (['or', 'os'].includes(v)) {
637
+ path.roundRect(p[0], p[1], ...ar);
638
+ }
639
+ // object line
640
+ else if (['ol', 'oa'].includes(v) && ar.length === 2) {
641
+ path.moveTo(p[0], p[1]);
642
+ path.lineTo(...ar);
643
+
644
+ // draw an arrow
645
+ if (v === 'oa') {
646
+ // Length of the arrowhead
647
+ const headLength = 40;
648
+ const angle = Math.atan2(ar[1] - p[1], ar[0] - p[0]);
649
+ path.moveTo(ar[0], ar[1]);
650
+ path.lineTo(ar[0] - headLength * Math.cos(angle - Math.PI / 6), ar[1] - headLength * Math.sin(angle - Math.PI / 6));
651
+ path.moveTo(ar[0], ar[1]);
652
+ path.lineTo(ar[0] - headLength * Math.cos(angle + Math.PI / 6), ar[1] - headLength * Math.sin(angle + Math.PI / 6));
653
+ }
654
+ }
655
+ // object triangle
656
+ else if (['ot', 'ote'].includes(v)) {
657
+ path.moveTo(p[0], p[1]);
658
+ path.lineTo(p[2], p[3]);
659
+ path.lineTo(p[4], p[5]);
660
+ path.closePath();
661
+ }
662
+ return path;
663
+ }, []);
664
+ const draw = _react.default.useCallback(item => {
665
+ var _item$s3, _item$s4;
666
+ const ui = refs.ui.current.getContext('2d');
667
+
668
+ // settings
669
+ Object.keys(item.s || {}).forEach(key => {
670
+ var _item$s2;
671
+ return ui[key] = (_item$s2 = item.s) === null || _item$s2 === void 0 ? void 0 : _item$s2[key];
672
+ });
673
+ ui.globalAlpha = refs.remove.current.includes(item) ? 0.25 : ((_item$s3 = item.s) === null || _item$s3 === void 0 ? void 0 : _item$s3.globalAlpha) !== undefined ? (_item$s4 = item.s) === null || _item$s4 === void 0 ? void 0 : _item$s4.globalAlpha : 1;
674
+ ui.beginPath();
675
+ const path = getPath(item);
676
+ const v = item.v;
677
+ if (['dp'].includes(v)) ui.fill(path);else if (['dl', 'oc', 'oe', 'or', 'os', 'ol', 'oa', 'ot', 'ote'].includes(v)) ui.stroke(path);
678
+ }, []);
679
+ const drawGrid = _react.default.useCallback(() => {
680
+ const uiCanvas = refs.ui.current;
681
+ const ui = refs.ui.current.getContext('2d');
682
+ const zoom = refs.scale.current;
683
+ const gridSize = 70;
684
+ const offsetX = refs.move.current.x / zoom;
685
+ const offsetY = refs.move.current.y / zoom;
686
+
687
+ // Calculate start positions based on offsets
688
+ const startX = Math.floor(-offsetX / gridSize) * gridSize;
689
+ const startY = Math.floor(-offsetY / gridSize) * gridSize;
690
+ const width = uiCanvas.clientWidth * 1.5 / (zoom < 1 ? zoom : 1);
691
+ const height = uiCanvas.clientHeight * 1.5 / (zoom < 1 ? zoom : 1);
692
+ if (gridSize < 30) return;
693
+
694
+ // Draw main grid lines
695
+ ui.globalAlpha = 1;
696
+ ui.lineWidth = (zoom < 0.5 ? 0.3 : zoom <= 1 ? 0.5 : 0.7) / zoom;
697
+ ui.strokeStyle = '#ccc';
698
+
699
+ // grid
700
+ for (let x = startX; x < width + Math.abs(startX); x += gridSize) {
701
+ ui.beginPath();
702
+ ui.moveTo(x, startY);
703
+ ui.lineTo(x, height + startY);
704
+ ui.stroke();
705
+ }
706
+ for (let y = startY; y < height + Math.abs(startY); y += gridSize) {
707
+ ui.beginPath();
708
+ ui.moveTo(startX, y);
709
+ ui.lineTo(width + startX, y);
710
+ ui.stroke();
711
+ }
712
+
713
+ // subgrid
714
+ if (gridSize * zoom > 100) {
715
+ // Draw subgrid lines if zoomed in
716
+ const subGridSize = gridSize / 5;
717
+ ui.lineWidth = (zoom <= 5 ? 0.6 : zoom <= 10 ? 0.8 : 1) / zoom;
718
+ ui.strokeStyle = '#ddd';
719
+ const dash = zoom < 1 ? 3 * zoom : 3 / zoom;
720
+ ui.setLineDash([dash, dash]);
721
+ for (let x = startX; x < width + Math.abs(startX); x += subGridSize) {
722
+ // without overlap
723
+ if (!(x % gridSize)) continue;
724
+ ui.beginPath();
725
+ ui.moveTo(x, startY);
726
+ ui.lineTo(x, height + startY);
727
+ ui.stroke();
728
+ }
729
+ for (let y = startY; y < height + Math.abs(startY); y += subGridSize) {
730
+ // without overlap
731
+ if (!(y % gridSize)) continue;
732
+ ui.beginPath();
733
+ ui.moveTo(startX, y);
734
+ ui.lineTo(width + startX, y);
735
+ ui.stroke();
736
+ }
737
+ ui.setLineDash([]); // Reset line dash
738
+ }
739
+ }, []);
740
+ const drawImage = _react.default.useCallback(item => {
741
+ const ui = refs.ui.current.getContext('2d');
742
+ ui.globalAlpha = 1;
743
+ ui.drawImage(item.s.image || refs.image.current, ...item.p, ...item.ar);
744
+ }, []);
745
+ const drawCursor = _react.default.useCallback(item => {
746
+ if (!item || !item.s.cursor) return;
747
+ const ui = refs.ui.current.getContext('2d');
748
+ const {
749
+ line,
750
+ char
751
+ } = item.s.cursor;
752
+ const currentLine = item.s.lines[line] || '';
753
+ const textWidth = ui.measureText(currentLine.slice(0, char)).width;
754
+ const {
755
+ padding,
756
+ lineHeight
757
+ } = refs.textSettings.current;
758
+ const cursorX = item.p[0] + padding + textWidth;
759
+ const cursorY = item.p[1] + padding + (line + 1) * lineHeight;
760
+ ui.fillStyle = 'black';
761
+ ui.fillRect(cursorX, cursorY - lineHeight + 3, 2, lineHeight - 5);
762
+ }, []);
763
+ const drawText = _react.default.useCallback(item => {
764
+ const ui = refs.ui.current.getContext('2d');
765
+ const zoom = refs.scale.current;
766
+ const [x, y] = item.p;
767
+ const [width, height] = item.ar;
768
+ const {
769
+ lineHeight,
770
+ padding,
771
+ fillStyle
772
+ } = refs.textSettings.current;
773
+ const selected = refs.tool.current === 'text' && item.se;
774
+
775
+ // Draw the box
776
+ ui.globalAlpha = 1;
777
+ ui.fillStyle = 'transparent';
778
+ ui.fillRect(x, y, width, height);
779
+ ui.lineWidth = 1 / zoom;
780
+ ui.strokeStyle = selected ? colorSelect : 'transparent';
781
+ ui.strokeRect(x, y, width, height);
782
+
783
+ // Draw the text
784
+ ui.fillStyle = fillStyle || 'black';
785
+ ui.font = '16px Arial';
786
+ item.s.lines.forEach((line, index) => {
787
+ ui.fillText(line, x + padding, y + padding + (index + 1) * lineHeight - 5);
788
+ });
789
+ if (selected) drawCursor(item);
790
+ }, []);
791
+ const drawSelect = _react.default.useCallback(item => {
792
+ const ui = refs.ui.current.getContext('2d');
793
+ const [x, y, width, height] = item.c || [];
794
+ const path = new Path2D();
795
+ path.rect(x, y, width, height);
796
+ ui.globalAlpha = 1;
797
+ ui.strokeStyle = colorSelect;
798
+ ui.lineCap = 'square';
799
+ ui.lineJoin = 'bevel';
800
+ ui.lineWidth = 1 / refs.scale.current;
801
+ ui.stroke(path);
802
+ }, []);
803
+ const drawSelection = _react.default.useCallback(() => {
804
+ const ui = refs.ui.current.getContext('2d');
805
+ const zoom = refs.scale.current;
806
+
807
+ // canvas selection
808
+ const select = refs.select.current;
809
+ if (select) {
810
+ ui.globalAlpha = 1;
811
+ ui.globalCompositeOperation = 'source-over';
812
+ ui.lineWidth = 1 / zoom;
813
+ ui.lineCap = 'square';
814
+ ui.lineJoin = 'bevel';
815
+ ui.strokeStyle = colorSelect;
816
+ ui.fillStyle = colorSelectBackground;
817
+ const path = getPath(select);
818
+ ui.fill(path);
819
+ ui.stroke(path);
820
+ }
821
+ }, []);
822
+ const render = _react.default.useCallback(() => {
823
+ const ui = refs.ui.current.getContext('2d');
824
+ const items = refs.items.current.filter(Boolean);
825
+
826
+ // methods
827
+ ui.clearRect(0, 0, refs.ui.current.width, refs.ui.current.height);
828
+ ui.save();
829
+
830
+ // pan
831
+ ui.translate(refs.move.current.x, refs.move.current.y);
832
+ // zoom
833
+ ui.scale(refs.scale.current, refs.scale.current);
834
+
835
+ // grid
836
+ if (refs.grid.current) drawGrid();
837
+
838
+ // draw
839
+ items.forEach(item => {
840
+ // image
841
+ if (item.v === 'i' && item.ar.length === 2) drawImage(item);
842
+ // text
843
+ else if (item.v === 't') drawText(item);
844
+ // other
845
+ else draw(item);
846
+
847
+ // select
848
+ if (item.se) drawSelect(item);
849
+ });
850
+
851
+ // canvas selection
852
+ drawSelection();
853
+ ui.restore();
854
+ }, []);
855
+
856
+ // Snap angle to nearest multiple of 15 degrees
857
+ const snapToAngle = _react.default.useCallback((dx, dy) => {
858
+ // Current angle in radians
859
+ const angle = Math.atan2(dy, dx);
860
+ // Snap to nearest 15 degrees
861
+ const snappedAngle = Math.round(angle / (Math.PI / 12)) * (Math.PI / 12);
862
+ // Length of the vector
863
+ const length = Math.sqrt(dx * dx + dy * dy);
864
+ return {
865
+ x: Math.cos(snappedAngle) * length,
866
+ y: Math.sin(snappedAngle) * length
867
+ };
868
+ }, []);
869
+ const onMoveItems = _react.default.useCallback((x, y) => {
870
+ const itemsSelected = getItems(true);
871
+ itemsSelected.forEach(item => {
872
+ const v = item.v;
873
+
874
+ // draw line
875
+ if (v === 'dl') {
876
+ item.p = item.p.map((value, index) => {
877
+ return index % 2 ? value + y : value + x;
818
878
  });
819
- onUpdateCoordinates();
820
- }, []);
821
- const onMove = react_1.default.useCallback((body, event) => {
822
- if (!refs.on.current)
823
- return;
824
- const { offsetX: x, offsetY: y, clientX, clientY } = body;
825
- const xo = transform(x - refs.move.current.x);
826
- const yo = transform(y - refs.move.current.y);
827
- const ui = refs.ui.current.getContext('2d');
828
- const rect = refs.ui.current.getBoundingClientRect();
829
- const currentX = clientX - rect.left;
830
- const currentY = clientY - rect.top;
831
- const start = refs.start.current;
832
- const startTransformed = {
833
- x: transform(start.x - refs.move.current.x),
834
- y: transform(start.y - refs.move.current.y)
835
- };
836
- const item = getItem();
837
- const items = getItems();
838
- const t = refs.tool.current;
839
- const shiftKey = event.shiftKey;
840
- const zoom = refs.scale.current;
841
- refs.mouseMove.current.current = { x: clientX / zoom, y: clientY / zoom };
842
- refs.mouseMove.current.delta = { x: refs.mouseMove.current.previous ? refs.mouseMove.current.current.x - refs.mouseMove.current.previous.x : 0, y: refs.mouseMove.current.previous ? refs.mouseMove.current.current.y - refs.mouseMove.current.previous.y : 0 };
843
- refs.mouseMove.current.previous = Object.assign({}, refs.mouseMove.current.current);
844
- const delta = refs.mouseMove.current.delta;
845
- // select
846
- if (t === 'select') {
847
- if (!refs.moveStarted.current)
848
- refs.moveStarted.current = true;
849
- if (refs.select.current) {
850
- unselectAll();
851
- const width = currentX - start.x;
852
- const height = currentY - start.y;
853
- const isSquare = shiftKey;
854
- const radius = 0;
855
- if (isSquare) {
856
- const side = Math.min(Math.abs(width), Math.abs(height));
857
- refs.select.current.v = 'os';
858
- refs.select.current.p = [startTransformed.x, startTransformed.y];
859
- refs.select.current.ar = [transform(Math.sign(width) * side), transform(Math.sign(height) * side), radius];
860
- }
861
- else {
862
- refs.select.current.v = 'or';
863
- refs.select.current.p = [startTransformed.x, startTransformed.y];
864
- refs.select.current.ar = [transform(width), transform(height), radius];
865
- }
866
- }
867
- else
868
- onMoveItems(delta.x, delta.y);
869
- }
870
- // pen
871
- else if (t === 'pen' && item) {
872
- // same path from draw point, to move
873
- if (!refs.moveStarted.current) {
874
- item.v = 'dl';
875
- refs.moveStarted.current = true;
876
- }
877
- // Add the current point to the path
878
- item.p.push(xo, yo);
879
- }
880
- // pan
881
- else if (t === 'pan') {
882
- refs.move.current.x = x - refs.previous.current.x + refs.offset.current.x;
883
- refs.move.current.y = y - refs.previous.current.y + refs.offset.current.y;
884
- }
885
- // eraser
886
- else if (t === 'eraser') {
887
- // find all items that x, y collides with, with certain radius
888
- for (const i of items) {
889
- const isPointInStroke = ui.isPointInStroke(getPath(i), xo, yo);
890
- if (isPointInStroke)
891
- refs.remove.current.push(i);
892
- }
893
- }
894
- // object line, object arrow
895
- else if (['line', 'line-arrow'].includes(t)) {
896
- const snapAt15Degrees = shiftKey;
897
- let endX = currentX;
898
- let endY = currentY;
899
- if (snapAt15Degrees) {
900
- const snapped = snapToAngle(currentX - start.x, currentY - start.y);
901
- endX = start.x + snapped.x;
902
- endY = start.y + snapped.y;
903
- }
904
- item.v = t === 'line' ? 'ol' : 'oa';
905
- item.p = [startTransformed.x, startTransformed.y];
906
- item.ar = [transform(endX - refs.move.current.x), transform(endY - refs.move.current.y)];
907
- }
908
- // object circle
909
- else if (t === 'circle') {
910
- const width = currentX - start.x;
911
- const height = currentY - start.y;
912
- const isCircle = shiftKey;
913
- if (isCircle) {
914
- const radius = Math.min(Math.abs(width), Math.abs(height)) / 2;
915
- const centerX = start.x + Math.sign(width) * radius;
916
- const centerY = start.y + Math.sign(height) * radius;
917
- item.v = 'oc';
918
- item.p = [transform(centerX - refs.move.current.x), transform(centerY - refs.move.current.y)];
919
- item.ar = [transform(radius), 0, Math.PI * 2];
920
- }
921
- else {
922
- item.v = 'oe';
923
- item.p = [transform((start.x + width / 2) - refs.move.current.x), transform((start.y + height / 2) - refs.move.current.y)];
924
- item.ar = [transform(Math.abs(width) / 2), transform(Math.abs(height) / 2), 0, 0, Math.PI * 2];
925
- }
926
- }
927
- // object rectangle
928
- else if (t === 'rectangle') {
929
- const width = currentX - start.x;
930
- const height = currentY - start.y;
931
- const isSquare = shiftKey;
932
- const radius = 0;
933
- if (isSquare) {
934
- const side = Math.min(Math.abs(width), Math.abs(height));
935
- item.v = 'os';
936
- item.p = [startTransformed.x, startTransformed.y];
937
- item.ar = [transform(Math.sign(width) * side), transform(Math.sign(height) * side), radius];
938
- }
939
- else {
940
- item.v = 'or';
941
- item.p = [startTransformed.x, startTransformed.y];
942
- item.ar = [transform(width), transform(height), radius];
943
- }
944
- }
945
- // object triangle
946
- else if (['triangle'].includes(t)) {
947
- const endX = xo;
948
- const endY = yo;
949
- const base = Math.abs(endX - startTransformed.x);
950
- const height = shiftKey ? base * Math.sqrt(3) / 2 : Math.abs(endY - startTransformed.y);
951
- const points = [startTransformed.x, startTransformed.y, endX, startTransformed.y, startTransformed.x + (endX - startTransformed.x) / 2, startTransformed.y - height];
952
- item.v = shiftKey ? 'ote' : 'ot';
953
- item.p = points;
954
- item.s = Object.assign(Object.assign({}, item.s), { height });
879
+ }
880
+
881
+ // rectangle, draw point, object circle, ellipse, object line, object arrow, object triangle, image, text
882
+ if (['or', 'os', 'dp', 'oc', 'oe', 'ol', 'oa', 'ot', 'ote', 'i', 't'].includes(v)) {
883
+ item.p[0] += x;
884
+ item.p[1] += y;
885
+ }
886
+
887
+ // object line
888
+ if (['ol', 'oa'].includes(v)) {
889
+ item.ar[0] += x;
890
+ item.ar[1] += y;
891
+ }
892
+
893
+ // object triangle
894
+ if (['ot', 'ote'].includes(v)) {
895
+ item.p[2] += x;
896
+ item.p[4] += x;
897
+ item.p[3] += y;
898
+ item.p[5] += y;
899
+ }
900
+ });
901
+ onUpdateCoordinates();
902
+ }, []);
903
+ const onMove = _react.default.useCallback((body, event) => {
904
+ if (!refs.on.current) return;
905
+ const {
906
+ offsetX: x,
907
+ offsetY: y,
908
+ clientX,
909
+ clientY
910
+ } = body;
911
+ const xo = transform(x - refs.move.current.x);
912
+ const yo = transform(y - refs.move.current.y);
913
+ const ui = refs.ui.current.getContext('2d');
914
+ const rect = refs.ui.current.getBoundingClientRect();
915
+ const currentX = clientX - rect.left;
916
+ const currentY = clientY - rect.top;
917
+ const start = refs.start.current;
918
+ const startTransformed = {
919
+ x: transform(start.x - refs.move.current.x),
920
+ y: transform(start.y - refs.move.current.y)
921
+ };
922
+ const item = getItem();
923
+ const items = getItems();
924
+ const t = refs.tool.current;
925
+ const shiftKey = event.shiftKey;
926
+ const zoom = refs.scale.current;
927
+ refs.mouseMove.current.current = {
928
+ x: clientX / zoom,
929
+ y: clientY / zoom
930
+ };
931
+ refs.mouseMove.current.delta = {
932
+ x: refs.mouseMove.current.previous ? refs.mouseMove.current.current.x - refs.mouseMove.current.previous.x : 0,
933
+ y: refs.mouseMove.current.previous ? refs.mouseMove.current.current.y - refs.mouseMove.current.previous.y : 0
934
+ };
935
+ refs.mouseMove.current.previous = _objectSpread({}, refs.mouseMove.current.current);
936
+ const delta = refs.mouseMove.current.delta;
937
+
938
+ // select
939
+ if (t === 'select') {
940
+ if (!refs.moveStarted.current) refs.moveStarted.current = true;
941
+ if (refs.select.current) {
942
+ unselectAll();
943
+ const width = currentX - start.x;
944
+ const height = currentY - start.y;
945
+ const isSquare = shiftKey;
946
+ const radius = 0;
947
+ if (isSquare) {
948
+ const side = Math.min(Math.abs(width), Math.abs(height));
949
+ refs.select.current.v = 'os';
950
+ refs.select.current.p = [startTransformed.x, startTransformed.y];
951
+ refs.select.current.ar = [transform(Math.sign(width) * side), transform(Math.sign(height) * side), radius];
952
+ } else {
953
+ refs.select.current.v = 'or';
954
+ refs.select.current.p = [startTransformed.x, startTransformed.y];
955
+ refs.select.current.ar = [transform(width), transform(height), radius];
955
956
  }
956
- // image
957
- else if (t === 'image' && (refs.image.current.complete && refs.image.current.src)) {
958
- const width = transform(currentX - start.x);
959
- const height = transform(currentY - start.y);
960
- const keepAspectRatio = !shiftKey;
961
- let currentWidth;
962
- let currentHeight;
963
- if (keepAspectRatio) {
964
- if (Math.abs(width / refs.aspectRatio.current) <= Math.abs(height)) {
965
- currentWidth = width;
966
- currentHeight = width / refs.aspectRatio.current;
967
- }
968
- else {
969
- currentWidth = height * refs.aspectRatio.current;
970
- currentHeight = height;
971
- }
972
- }
973
- else {
974
- currentWidth = width;
975
- currentHeight = height;
976
- }
977
- if (keepAspectRatio) {
978
- if ((width < 0 && currentWidth > 0) ||
979
- (width > 0 && currentWidth < 0))
980
- currentWidth *= -1;
981
- if ((height < 0 && currentHeight > 0) ||
982
- (height > 0 && currentHeight < 0))
983
- currentHeight *= -1;
984
- }
985
- item.p = [startTransformed.x, startTransformed.y];
986
- item.ar = [currentWidth, currentHeight];
957
+ } else onMoveItems(delta.x, delta.y);
958
+ }
959
+ // pen
960
+ else if (t === 'pen' && item) {
961
+ // same path from draw point, to move
962
+ if (!refs.moveStarted.current) {
963
+ item.v = 'dl';
964
+ refs.moveStarted.current = true;
965
+ }
966
+
967
+ // Add the current point to the path
968
+ item.p.push(xo, yo);
969
+ }
970
+ // pan
971
+ else if (t === 'pan') {
972
+ refs.move.current.x = x - refs.previous.current.x + refs.offset.current.x;
973
+ refs.move.current.y = y - refs.previous.current.y + refs.offset.current.y;
974
+ }
975
+ // eraser
976
+ else if (t === 'eraser') {
977
+ // find all items that x, y collides with, with certain radius
978
+ for (const i of items) {
979
+ const isPointInStroke = ui.isPointInStroke(getPath(i), xo, yo);
980
+ if (isPointInStroke) refs.remove.current.push(i);
981
+ }
982
+ }
983
+ // object line, object arrow
984
+ else if (['line', 'line-arrow'].includes(t)) {
985
+ const snapAt15Degrees = shiftKey;
986
+ let endX = currentX;
987
+ let endY = currentY;
988
+ if (snapAt15Degrees) {
989
+ const snapped = snapToAngle(currentX - start.x, currentY - start.y);
990
+ endX = start.x + snapped.x;
991
+ endY = start.y + snapped.y;
992
+ }
993
+ item.v = t === 'line' ? 'ol' : 'oa';
994
+ item.p = [startTransformed.x, startTransformed.y];
995
+ item.ar = [transform(endX - refs.move.current.x), transform(endY - refs.move.current.y)];
996
+ }
997
+ // object circle
998
+ else if (t === 'circle') {
999
+ const width = currentX - start.x;
1000
+ const height = currentY - start.y;
1001
+ const isCircle = shiftKey;
1002
+ if (isCircle) {
1003
+ const radius = Math.min(Math.abs(width), Math.abs(height)) / 2;
1004
+ const centerX = start.x + Math.sign(width) * radius;
1005
+ const centerY = start.y + Math.sign(height) * radius;
1006
+ item.v = 'oc';
1007
+ item.p = [transform(centerX - refs.move.current.x), transform(centerY - refs.move.current.y)];
1008
+ item.ar = [transform(radius), 0, Math.PI * 2];
1009
+ } else {
1010
+ item.v = 'oe';
1011
+ item.p = [transform(start.x + width / 2 - refs.move.current.x), transform(start.y + height / 2 - refs.move.current.y)];
1012
+ item.ar = [transform(Math.abs(width) / 2), transform(Math.abs(height) / 2), 0, 0, Math.PI * 2];
1013
+ }
1014
+ }
1015
+ // object rectangle
1016
+ else if (t === 'rectangle') {
1017
+ const width = currentX - start.x;
1018
+ const height = currentY - start.y;
1019
+ const isSquare = shiftKey;
1020
+ const radius = 0;
1021
+ if (isSquare) {
1022
+ const side = Math.min(Math.abs(width), Math.abs(height));
1023
+ item.v = 'os';
1024
+ item.p = [startTransformed.x, startTransformed.y];
1025
+ item.ar = [transform(Math.sign(width) * side), transform(Math.sign(height) * side), radius];
1026
+ } else {
1027
+ item.v = 'or';
1028
+ item.p = [startTransformed.x, startTransformed.y];
1029
+ item.ar = [transform(width), transform(height), radius];
1030
+ }
1031
+ }
1032
+ // object triangle
1033
+ else if (['triangle'].includes(t)) {
1034
+ const endX = xo;
1035
+ const endY = yo;
1036
+ const base = Math.abs(endX - startTransformed.x);
1037
+ const height = shiftKey ? base * Math.sqrt(3) / 2 : Math.abs(endY - startTransformed.y);
1038
+ const points = [startTransformed.x, startTransformed.y, endX, startTransformed.y, startTransformed.x + (endX - startTransformed.x) / 2, startTransformed.y - height];
1039
+ item.v = shiftKey ? 'ote' : 'ot';
1040
+ item.p = points;
1041
+ item.s = _objectSpread(_objectSpread({}, item.s), {}, {
1042
+ height
1043
+ });
1044
+ }
1045
+ // image
1046
+ else if (t === 'image' && refs.image.current.complete && refs.image.current.src) {
1047
+ const width = transform(currentX - start.x);
1048
+ const height = transform(currentY - start.y);
1049
+ const keepAspectRatio = !shiftKey;
1050
+ let currentWidth;
1051
+ let currentHeight;
1052
+ if (keepAspectRatio) {
1053
+ if (Math.abs(width / refs.aspectRatio.current) <= Math.abs(height)) {
1054
+ currentWidth = width;
1055
+ currentHeight = width / refs.aspectRatio.current;
1056
+ } else {
1057
+ currentWidth = height * refs.aspectRatio.current;
1058
+ currentHeight = height;
987
1059
  }
988
- // select box
989
- onSelect();
990
- // render
1060
+ } else {
1061
+ currentWidth = width;
1062
+ currentHeight = height;
1063
+ }
1064
+ if (keepAspectRatio) {
1065
+ if (width < 0 && currentWidth > 0 || width > 0 && currentWidth < 0) currentWidth *= -1;
1066
+ if (height < 0 && currentHeight > 0 || height > 0 && currentHeight < 0) currentHeight *= -1;
1067
+ }
1068
+ item.p = [startTransformed.x, startTransformed.y];
1069
+ item.ar = [currentWidth, currentHeight];
1070
+ }
1071
+
1072
+ // select box
1073
+ onSelect();
1074
+
1075
+ // render
1076
+ render();
1077
+ }, []);
1078
+ const onMouseMove = _react.default.useCallback(event => {
1079
+ const {
1080
+ offsetX,
1081
+ offsetY,
1082
+ clientX,
1083
+ clientY
1084
+ } = event;
1085
+ onMove({
1086
+ offsetX,
1087
+ offsetY,
1088
+ clientX,
1089
+ clientY
1090
+ }, event);
1091
+ }, [onMove]);
1092
+ const onTouchMove = _react.default.useCallback(event => {
1093
+ // Get the first touch point
1094
+ const touch = event.touches[0];
1095
+ const {
1096
+ clientX,
1097
+ clientY
1098
+ } = touch;
1099
+ let {
1100
+ offsetX,
1101
+ offsetY
1102
+ } = touch;
1103
+ const targetElement = touch.target;
1104
+ if (targetElement instanceof HTMLElement) {
1105
+ // Get the bounding rectangle of the target element
1106
+ const rect = targetElement.getBoundingClientRect();
1107
+
1108
+ // Calculate the offsetX and offsetY
1109
+ offsetX = touch.clientX - rect.left;
1110
+ offsetY = touch.clientY - rect.top;
1111
+ }
1112
+ onMove({
1113
+ offsetX,
1114
+ offsetY,
1115
+ clientX,
1116
+ clientY
1117
+ }, event);
1118
+ }, [onInteractionDown]);
1119
+ const undo = _react.default.useCallback(() => {
1120
+ if (!refs.undo.current.length) return;
1121
+
1122
+ // add current state to redo
1123
+ refs.redo.current.push([...getItems()]);
1124
+
1125
+ // restore the undo state
1126
+ refs.items.current = refs.undo.current.pop();
1127
+
1128
+ // render
1129
+ render();
1130
+ }, []);
1131
+ const redo = _react.default.useCallback(() => {
1132
+ if (!refs.redo.current.length) return;
1133
+
1134
+ // add current state to undo
1135
+ refs.undo.current.push([...getItems()]);
1136
+
1137
+ // restore the redo state
1138
+ refs.items.current = refs.redo.current.pop();
1139
+
1140
+ // render
1141
+ render();
1142
+ }, []);
1143
+ const onWheel = _react.default.useCallback(eventReact => {
1144
+ const event = eventReact.nativeEvent;
1145
+
1146
+ // zoom
1147
+ if (event.metaKey || event.ctrlKey) {
1148
+ setTool('zoom');
1149
+ refs.toolUpdateAuto.current = true;
1150
+ const zoomFactor = 1.054;
1151
+ const mouseX = event.offsetX;
1152
+ const mouseY = event.offsetY;
1153
+ const scale = refs.scale.current;
1154
+
1155
+ // Convert mouse position to canvas coordinates
1156
+ const canvasX = (mouseX - refs.move.current.x) / scale;
1157
+ const canvasY = (mouseY - refs.move.current.y) / scale;
1158
+
1159
+ // Adjust scale
1160
+ const zoomIn = event.deltaY < 0;
1161
+ const newScale = zoomIn ? scale * zoomFactor : scale / zoomFactor;
1162
+ if (newScale <= maxZoom / 100 && newScale >= minZoom / 100) {
1163
+ // Update origin to focus on mouse position
1164
+ refs.move.current.x -= canvasX * (newScale - scale);
1165
+ refs.move.current.y -= canvasY * (newScale - scale);
1166
+ refs.scale.current = newScale;
991
1167
  render();
992
- }, []);
993
- const onMouseMove = react_1.default.useCallback((event) => {
994
- const { offsetX, offsetY, clientX, clientY } = event;
995
- onMove({ offsetX, offsetY, clientX, clientY }, event);
996
- }, [onMove]);
997
- const onTouchMove = react_1.default.useCallback((event) => {
998
- // Get the first touch point
999
- const touch = event.touches[0];
1000
- const { clientX, clientY } = touch;
1001
- let { offsetX, offsetY } = touch;
1002
- const targetElement = touch.target;
1003
- if (targetElement instanceof HTMLElement) {
1004
- // Get the bounding rectangle of the target element
1005
- const rect = targetElement.getBoundingClientRect();
1006
- // Calculate the offsetX and offsetY
1007
- offsetX = touch.clientX - rect.left;
1008
- offsetY = touch.clientY - rect.top;
1168
+ }
1169
+ }
1170
+ // pan
1171
+ else if (!refs.mouseDown.current) {
1172
+ refs.move.current.x -= event.deltaX;
1173
+ refs.move.current.y -= event.deltaY;
1174
+ render();
1175
+ }
1176
+ }, [minZoom, maxZoom]);
1177
+ const onPaste = _react.default.useCallback(event => {
1178
+ event.preventDefault();
1179
+
1180
+ // Get clipboard data
1181
+ const items = Array.from(event.clipboardData.items);
1182
+
1183
+ // Loop through clipboard items to find an image
1184
+ for (const item of items) {
1185
+ if (item.type.startsWith('image/')) {
1186
+ // Get the image file
1187
+ const blob = item.getAsFile();
1188
+ refs.image.current = new Image();
1189
+
1190
+ // Load the image and draw it on the canvas
1191
+ refs.image.current.onload = () => {
1192
+ refs.aspectRatio.current = refs.image.current.width / refs.image.current.height;
1193
+
1194
+ // Todo
1195
+ // 1) Upload the image first, than read it in image src
1196
+ // 2) Add url of the image
1197
+ // instead of embeding the image
1198
+ const item_ = {
1199
+ i: (0, _utils.getID)(),
1200
+ v: 'i',
1201
+ p: [],
1202
+ ar: [],
1203
+ s: {
1204
+ // Todo
1205
+ // remove in the future
1206
+ image: refs.image.current,
1207
+ aspectRatio: refs.aspectRatio.current
1208
+ },
1209
+ a: _date.OnesyDate.milliseconds
1210
+ };
1211
+ add(item_);
1212
+ setTool('image');
1213
+ };
1214
+
1215
+ // Create an object URL for the blob and set it as the image source
1216
+ refs.image.current.src = URL.createObjectURL(blob);
1217
+ break;
1218
+ }
1219
+ }
1220
+ }, []);
1221
+ _react.default.useEffect(() => {
1222
+ const method = () => {
1223
+ const width = refs.root.current.offsetWidth;
1224
+ const height = refs.root.current.offsetHeight;
1225
+ setSize({
1226
+ width,
1227
+ height
1228
+ });
1229
+ };
1230
+ const onKeyUp = event => {
1231
+ if (refs.toolUpdateAuto.current) setTool(refs.previousTool.current || 'pen');
1232
+ };
1233
+ const onKeyDown = async event => {
1234
+ refs.toolUpdateAuto.current = false;
1235
+ const {
1236
+ key
1237
+ } = event;
1238
+ const itemsAll = [...refs.items.current].filter(Boolean);
1239
+ const t = refs.tool.current;
1240
+ const zoom = refs.scale.current;
1241
+ if (['a', 'A'].includes(key) && (event.metaKey || event.ctrlKey)) {
1242
+ event.preventDefault();
1243
+ selectAll();
1244
+ render();
1245
+ } else if (t === 'select' && ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Backspace'].includes(key)) {
1246
+ const value = event.shiftKey ? 10 : 1;
1247
+ if (key === 'ArrowUp') onMoveItems(0, -value / zoom);
1248
+ if (key === 'ArrowDown') onMoveItems(0, value / zoom);
1249
+ if (key === 'ArrowLeft') onMoveItems(-value / zoom, 0);
1250
+ if (key === 'ArrowRight') onMoveItems(value / zoom, 0);
1251
+ if (key === 'Backspace') {
1252
+ const toRemove = [];
1253
+ refs.items.current.forEach(item => {
1254
+ if (item.se) toRemove.push(item);
1255
+ });
1256
+ if (toRemove.length) remove(toRemove);
1009
1257
  }
1010
- onMove({ offsetX, offsetY, clientX, clientY }, event);
1011
- }, [onInteractionDown]);
1012
- const undo = react_1.default.useCallback(() => {
1013
- if (!refs.undo.current.length)
1014
- return;
1015
- // add current state to redo
1016
- refs.redo.current.push([...getItems()]);
1017
- // restore the undo state
1018
- refs.items.current = refs.undo.current.pop();
1019
- // render
1020
1258
  render();
1021
- }, []);
1022
- const redo = react_1.default.useCallback(() => {
1023
- if (!refs.redo.current.length)
1024
- return;
1025
- // add current state to undo
1026
- refs.undo.current.push([...getItems()]);
1027
- // restore the redo state
1028
- refs.items.current = refs.redo.current.pop();
1029
- // render
1259
+ } else if (key === 'Escape') {
1260
+ setTool('select');
1261
+ refs.textActive.current = null;
1262
+ unselectAll();
1263
+ filterItems();
1030
1264
  render();
1031
- }, []);
1032
- const onWheel = react_1.default.useCallback((eventReact) => {
1033
- const event = eventReact.nativeEvent;
1034
- // zoom
1035
- if (event.metaKey || event.ctrlKey) {
1036
- setTool('zoom');
1037
- refs.toolUpdateAuto.current = true;
1038
- const zoomFactor = 1.054;
1039
- const mouseX = event.offsetX;
1040
- const mouseY = event.offsetY;
1041
- const scale = refs.scale.current;
1042
- // Convert mouse position to canvas coordinates
1043
- const canvasX = (mouseX - refs.move.current.x) / scale;
1044
- const canvasY = (mouseY - refs.move.current.y) / scale;
1045
- // Adjust scale
1046
- const zoomIn = event.deltaY < 0;
1047
- const newScale = zoomIn ? scale * zoomFactor : scale / zoomFactor;
1048
- if (newScale <= (maxZoom / 100) && newScale >= (minZoom / 100)) {
1049
- // Update origin to focus on mouse position
1050
- refs.move.current.x -= canvasX * (newScale - scale);
1051
- refs.move.current.y -= canvasY * (newScale - scale);
1052
- refs.scale.current = newScale;
1053
- render();
1054
- }
1265
+ } else if (tool === 'text') {
1266
+ const selectedTextBox = itemsAll.find(item => item.v === 't' && item.se);
1267
+ if (!selectedTextBox) return;
1268
+ const {
1269
+ line,
1270
+ char
1271
+ } = selectedTextBox.s.cursor;
1272
+ const lines = selectedTextBox.s.lines;
1273
+ const currentLine = lines[line];
1274
+ if (['ArrowLeft', 'ArrowRight'].includes(key)) {
1275
+ var _lines$line, _lines$selectedTextBo2;
1276
+ event.preventDefault();
1277
+ selectedTextBox.s.cursor.char += key === 'ArrowLeft' ? -1 : 1;
1278
+ if (selectedTextBox.s.cursor.char < 0) {
1279
+ var _lines$selectedTextBo;
1280
+ selectedTextBox.s.cursor.line--;
1281
+ selectedTextBox.s.cursor.char = (_lines$selectedTextBo = lines[selectedTextBox.s.cursor.line]) === null || _lines$selectedTextBo === void 0 ? void 0 : _lines$selectedTextBo.length;
1282
+ } else if (selectedTextBox.s.cursor.char > ((_lines$line = lines[line]) === null || _lines$line === void 0 ? void 0 : _lines$line.length) && line !== lines.length - 1) {
1283
+ selectedTextBox.s.cursor.line++;
1284
+ selectedTextBox.s.cursor.char = 0;
1285
+ }
1286
+ selectedTextBox.s.cursor.line = (0, _utils.clamp)(selectedTextBox.s.cursor.line, 0, lines.length - 1);
1287
+ selectedTextBox.s.cursor.char = (0, _utils.clamp)(selectedTextBox.s.cursor.char, 0, (_lines$selectedTextBo2 = lines[selectedTextBox.s.cursor.line]) === null || _lines$selectedTextBo2 === void 0 ? void 0 : _lines$selectedTextBo2.length);
1055
1288
  }
1056
- // pan
1057
- else if (!refs.mouseDown.current) {
1058
- refs.move.current.x -= event.deltaX;
1059
- refs.move.current.y -= event.deltaY;
1060
- render();
1289
+ if (['ArrowUp', 'ArrowDown'].includes(key)) {
1290
+ var _lines$selectedTextBo3;
1291
+ event.preventDefault();
1292
+ selectedTextBox.s.cursor.line += key === 'ArrowUp' ? -1 : 1;
1293
+ selectedTextBox.s.cursor.line = (0, _utils.clamp)(selectedTextBox.s.cursor.line, 0, lines.length - 1);
1294
+ selectedTextBox.s.cursor.char = (0, _utils.clamp)(selectedTextBox.s.cursor.char, 0, (_lines$selectedTextBo3 = lines[selectedTextBox.s.cursor.line]) === null || _lines$selectedTextBo3 === void 0 ? void 0 : _lines$selectedTextBo3.length);
1295
+ } else if (key === 'Enter') {
1296
+ event.preventDefault();
1297
+ const newLine = currentLine.slice(char);
1298
+ lines[line] = currentLine.slice(0, char);
1299
+ lines.splice(line + 1, 0, newLine);
1300
+ selectedTextBox.s.cursor.line++;
1301
+ selectedTextBox.s.cursor.char = 0;
1302
+ } else if (key === 'Backspace') {
1303
+ event.preventDefault();
1304
+ if (char > 0) {
1305
+ lines[line] = currentLine.slice(0, char - 1) + currentLine.slice(char);
1306
+ selectedTextBox.s.cursor.char--;
1307
+ } else if (line > 0) {
1308
+ const prevLine = lines[line - 1];
1309
+ selectedTextBox.s.cursor.char = prevLine.length;
1310
+ lines[line - 1] += lines[line];
1311
+ lines.splice(line, 1);
1312
+ selectedTextBox.s.cursor.line--;
1313
+ }
1314
+ } else if (key.length === 1) {
1315
+ if ([' '].includes(key)) event.preventDefault();
1316
+ let textClipboard = '';
1317
+ const isPaste = (event.ctrlKey || event.metaKey) && ['v', 'V'].includes(key);
1318
+ if (isPaste) {
1319
+ try {
1320
+ textClipboard = await window.navigator.clipboard.readText();
1321
+ } catch (error) {}
1322
+ }
1323
+ const text = isPaste ? textClipboard : key;
1324
+ selectedTextBox.s.lines[line] = currentLine.slice(0, char) + text + currentLine.slice(char);
1325
+ selectedTextBox.s.cursor.char += text.length;
1061
1326
  }
1062
- }, [minZoom, maxZoom]);
1063
- const onPaste = react_1.default.useCallback((event) => {
1064
- event.preventDefault();
1065
- // Get clipboard data
1066
- const items = Array.from(event.clipboardData.items);
1067
- // Loop through clipboard items to find an image
1068
- for (const item of items) {
1069
- if (item.type.startsWith('image/')) {
1070
- // Get the image file
1071
- const blob = item.getAsFile();
1072
- refs.image.current = new Image();
1073
- // Load the image and draw it on the canvas
1074
- refs.image.current.onload = () => {
1075
- refs.aspectRatio.current = refs.image.current.width / refs.image.current.height;
1076
- // Todo
1077
- // 1) Upload the image first, than read it in image src
1078
- // 2) Add url of the image
1079
- // instead of embeding the image
1080
- const item_ = {
1081
- i: (0, utils_1.getID)(),
1082
- v: 'i',
1083
- p: [],
1084
- ar: [],
1085
- s: {
1086
- // Todo
1087
- // remove in the future
1088
- image: refs.image.current,
1089
- aspectRatio: refs.aspectRatio.current
1090
- },
1091
- a: date_1.OnesyDate.milliseconds
1092
- };
1093
- add(item_);
1094
- setTool('image');
1095
- };
1096
- // Create an object URL for the blob and set it as the image source
1097
- refs.image.current.src = URL.createObjectURL(blob);
1098
- break;
1099
- }
1327
+ updateTextBoxDimensions(selectedTextBox);
1328
+ selectedTextBox.c = [...selectedTextBox.p, ...selectedTextBox.ar];
1329
+ render();
1330
+ } else {
1331
+ if (event.metaKey && key === 'z') {
1332
+ if (event.shiftKey) redo();else undo();
1100
1333
  }
1101
- }, []);
1102
- react_1.default.useEffect(() => {
1103
- const method = () => {
1104
- const width = refs.root.current.offsetWidth;
1105
- const height = refs.root.current.offsetHeight;
1106
- setSize({ width, height });
1107
- };
1108
- const onKeyUp = (event) => {
1109
- if (refs.toolUpdateAuto.current)
1110
- setTool(refs.previousTool.current || 'pen');
1111
- };
1112
- const onKeyDown = async (event) => {
1113
- var _a, _b, _c, _d;
1114
- refs.toolUpdateAuto.current = false;
1115
- const { key } = event;
1116
- const itemsAll = [...refs.items.current].filter(Boolean);
1117
- const t = refs.tool.current;
1118
- const zoom = refs.scale.current;
1119
- if (['a', 'A'].includes(key) && (event.metaKey || event.ctrlKey)) {
1120
- event.preventDefault();
1121
- selectAll();
1122
- render();
1123
- }
1124
- else if (t === 'select' && ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Backspace'].includes(key)) {
1125
- const value = event.shiftKey ? 10 : 1;
1126
- if (key === 'ArrowUp')
1127
- onMoveItems(0, -value / zoom);
1128
- if (key === 'ArrowDown')
1129
- onMoveItems(0, value / zoom);
1130
- if (key === 'ArrowLeft')
1131
- onMoveItems(-value / zoom, 0);
1132
- if (key === 'ArrowRight')
1133
- onMoveItems(value / zoom, 0);
1134
- if (key === 'Backspace') {
1135
- const toRemove = [];
1136
- refs.items.current.forEach(item => {
1137
- if (item.se)
1138
- toRemove.push(item);
1139
- });
1140
- if (toRemove.length)
1141
- remove(toRemove);
1142
- }
1143
- render();
1144
- }
1145
- else if (key === 'Escape') {
1146
- setTool('select');
1147
- refs.textActive.current = null;
1148
- unselectAll();
1149
- filterItems();
1150
- render();
1151
- }
1152
- else if (tool === 'text') {
1153
- const selectedTextBox = itemsAll.find(item => item.v === 't' && item.se);
1154
- if (!selectedTextBox)
1155
- return;
1156
- const { line, char } = selectedTextBox.s.cursor;
1157
- const lines = selectedTextBox.s.lines;
1158
- const currentLine = lines[line];
1159
- if (['ArrowLeft', 'ArrowRight'].includes(key)) {
1160
- event.preventDefault();
1161
- selectedTextBox.s.cursor.char += key === 'ArrowLeft' ? -1 : 1;
1162
- if (selectedTextBox.s.cursor.char < 0) {
1163
- selectedTextBox.s.cursor.line--;
1164
- selectedTextBox.s.cursor.char = (_a = lines[selectedTextBox.s.cursor.line]) === null || _a === void 0 ? void 0 : _a.length;
1165
- }
1166
- else if ((selectedTextBox.s.cursor.char > ((_b = lines[line]) === null || _b === void 0 ? void 0 : _b.length)) && line !== lines.length - 1) {
1167
- selectedTextBox.s.cursor.line++;
1168
- selectedTextBox.s.cursor.char = 0;
1169
- }
1170
- selectedTextBox.s.cursor.line = (0, utils_1.clamp)(selectedTextBox.s.cursor.line, 0, lines.length - 1);
1171
- selectedTextBox.s.cursor.char = (0, utils_1.clamp)(selectedTextBox.s.cursor.char, 0, (_c = lines[selectedTextBox.s.cursor.line]) === null || _c === void 0 ? void 0 : _c.length);
1172
- }
1173
- if (['ArrowUp', 'ArrowDown'].includes(key)) {
1174
- event.preventDefault();
1175
- selectedTextBox.s.cursor.line += key === 'ArrowUp' ? -1 : 1;
1176
- selectedTextBox.s.cursor.line = (0, utils_1.clamp)(selectedTextBox.s.cursor.line, 0, lines.length - 1);
1177
- selectedTextBox.s.cursor.char = (0, utils_1.clamp)(selectedTextBox.s.cursor.char, 0, (_d = lines[selectedTextBox.s.cursor.line]) === null || _d === void 0 ? void 0 : _d.length);
1178
- }
1179
- else if (key === 'Enter') {
1180
- event.preventDefault();
1181
- const newLine = currentLine.slice(char);
1182
- lines[line] = currentLine.slice(0, char);
1183
- lines.splice(line + 1, 0, newLine);
1184
- selectedTextBox.s.cursor.line++;
1185
- selectedTextBox.s.cursor.char = 0;
1186
- }
1187
- else if (key === 'Backspace') {
1188
- event.preventDefault();
1189
- if (char > 0) {
1190
- lines[line] = currentLine.slice(0, char - 1) + currentLine.slice(char);
1191
- selectedTextBox.s.cursor.char--;
1192
- }
1193
- else if (line > 0) {
1194
- const prevLine = lines[line - 1];
1195
- selectedTextBox.s.cursor.char = prevLine.length;
1196
- lines[line - 1] += lines[line];
1197
- lines.splice(line, 1);
1198
- selectedTextBox.s.cursor.line--;
1199
- }
1200
- }
1201
- else if (key.length === 1) {
1202
- if ([' '].includes(key))
1203
- event.preventDefault();
1204
- let textClipboard = '';
1205
- const isPaste = (event.ctrlKey || event.metaKey) && ['v', 'V'].includes(key);
1206
- if (isPaste) {
1207
- try {
1208
- textClipboard = await window.navigator.clipboard.readText();
1209
- }
1210
- catch (error) { }
1211
- }
1212
- const text = isPaste ? textClipboard : key;
1213
- selectedTextBox.s.lines[line] = currentLine.slice(0, char) + text + currentLine.slice(char);
1214
- selectedTextBox.s.cursor.char += text.length;
1215
- }
1216
- updateTextBoxDimensions(selectedTextBox);
1217
- selectedTextBox.c = [
1218
- ...selectedTextBox.p,
1219
- ...selectedTextBox.ar
1220
- ];
1221
- render();
1222
- }
1223
- else {
1224
- if (event.metaKey && key === 'z') {
1225
- if (event.shiftKey)
1226
- redo();
1227
- else
1228
- undo();
1229
- }
1230
- if (key === ' ') {
1231
- refs.toolUpdateAuto.current = true;
1232
- setTool('pan');
1233
- }
1234
- // tools
1235
- if (event.shiftKey) {
1236
- if (['E', 'D', 'P', 'S', 'C', 'R', 'I', 'L', 'A', 'T', 'G'].includes(key))
1237
- refs.toolUpdateAuto.current = false;
1238
- if (key === 'E')
1239
- setTool('eraser');
1240
- if (key === 'D')
1241
- setTool('pen');
1242
- if (key === 'P')
1243
- setTool('pan');
1244
- if (key === 'S')
1245
- setTool('select');
1246
- if (key === 'C')
1247
- setTool('circle');
1248
- if (key === 'R')
1249
- setTool('rectangle');
1250
- if (key === 'I')
1251
- setTool('triangle');
1252
- if (key === 'L')
1253
- setTool('line');
1254
- if (key === 'A')
1255
- setTool('line-arrow');
1256
- if (key === 'T')
1257
- setTool('text');
1258
- if (key === 'G') {
1259
- setGrid(previous => !previous);
1260
- render();
1261
- }
1262
- }
1263
- }
1264
- };
1265
- window.addEventListener('resize', method);
1266
- window.document.addEventListener('mouseup', onMouseUp);
1267
- window.document.addEventListener('touchend', onMouseUp);
1268
- window.document.addEventListener('mousemove', onMouseMove);
1269
- window.document.addEventListener('touchmove', onTouchMove);
1270
- window.document.addEventListener('keyup', onKeyUp);
1271
- window.document.addEventListener('keydown', onKeyDown);
1272
- window.document.addEventListener('paste', onPaste);
1273
- method();
1274
- init();
1275
- return () => {
1276
- window.removeEventListener('resize', method);
1277
- window.document.removeEventListener('mouseup', onMouseUp);
1278
- window.document.removeEventListener('touchend', onMouseUp);
1279
- window.document.removeEventListener('mousemove', onMouseMove);
1280
- window.document.removeEventListener('touchmove', onTouchMove);
1281
- window.document.removeEventListener('keyup', onKeyUp);
1282
- window.document.removeEventListener('keydown', onKeyDown);
1283
- window.document.removeEventListener('paste', onPaste);
1284
- };
1285
- }, []);
1286
- const onChangeInputFile = react_1.default.useCallback((event) => {
1287
- const file = event.target.files[0];
1288
- if (file) {
1289
- const reader = new FileReader();
1290
- reader.onload = eventReader => {
1291
- refs.image.current = new Image();
1292
- refs.image.current.src = eventReader.target.result;
1293
- refs.toolUpdateAuto.current = true;
1294
- event.target.value = '';
1295
- setTool('image');
1296
- };
1297
- reader.readAsDataURL(file);
1334
+ if (key === ' ') {
1335
+ refs.toolUpdateAuto.current = true;
1336
+ setTool('pan');
1298
1337
  }
1299
- }, []);
1300
- const propsCanvas = {
1301
- width: size.width,
1302
- height: size.height,
1303
- disabled: !loaded,
1304
- style: {
1305
- width: size.width,
1306
- height: size.height,
1338
+
1339
+ // tools
1340
+ if (event.shiftKey) {
1341
+ if (['E', 'D', 'P', 'S', 'C', 'R', 'I', 'L', 'A', 'T', 'G'].includes(key)) refs.toolUpdateAuto.current = false;
1342
+ if (key === 'E') setTool('eraser');
1343
+ if (key === 'D') setTool('pen');
1344
+ if (key === 'P') setTool('pan');
1345
+ if (key === 'S') setTool('select');
1346
+ if (key === 'C') setTool('circle');
1347
+ if (key === 'R') setTool('rectangle');
1348
+ if (key === 'I') setTool('triangle');
1349
+ if (key === 'L') setTool('line');
1350
+ if (key === 'A') setTool('line-arrow');
1351
+ if (key === 'T') setTool('text');
1352
+ if (key === 'G') {
1353
+ setGrid(previous => !previous);
1354
+ render();
1355
+ }
1307
1356
  }
1357
+ }
1308
1358
  };
1309
- return ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ ref: (item) => {
1310
- if (ref) {
1311
- if ((0, utils_1.is)('function', ref))
1312
- ref(item);
1313
- else
1314
- ref.current = item;
1315
- }
1316
- refs.root.current = item;
1317
- }, flex: true, fullWidth: true, className: (0, style_react_1.classNames)([
1318
- (0, utils_2.staticClassName)('Whiteboard', theme) && [
1319
- 'onesy-Whiteboard-root'
1320
- ],
1321
- className,
1322
- classes.root
1323
- ]) }, other, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ id: 'controls', style: { position: 'absolute', zIndex: 14, top: 12, left: '50%' } }, { children: (0, jsx_runtime_1.jsx)("input", { type: 'file', accept: 'image/*', onChange: onChangeInputFile }) })), (0, jsx_runtime_1.jsx)("canvas", Object.assign({ ref: refs.ui, onMouseDown: onMouseDown, onTouchStart: onTouchStart, onWheel: onWheel, className: (0, style_react_1.classNames)([
1324
- classes.canvas,
1325
- classes.interactive,
1326
- tool === 'pan' && classes[!mouseDown ? 'pan' : 'panning'],
1327
- tool === 'image' && classes.image,
1328
- tool === 'text' && classes.text,
1329
- ['pen', 'eraser', 'zoom'].includes(tool) && classes[tool],
1330
- ['circle', 'rectangle', 'triangle', 'line', 'arrow'].includes(tool) && classes.object
1331
- ]) }, propsCanvas))] })));
1359
+ window.addEventListener('resize', method);
1360
+ window.document.addEventListener('mouseup', onMouseUp);
1361
+ window.document.addEventListener('touchend', onMouseUp);
1362
+ window.document.addEventListener('mousemove', onMouseMove);
1363
+ window.document.addEventListener('touchmove', onTouchMove);
1364
+ window.document.addEventListener('keyup', onKeyUp);
1365
+ window.document.addEventListener('keydown', onKeyDown);
1366
+ window.document.addEventListener('paste', onPaste);
1367
+ method();
1368
+ init();
1369
+ return () => {
1370
+ window.removeEventListener('resize', method);
1371
+ window.document.removeEventListener('mouseup', onMouseUp);
1372
+ window.document.removeEventListener('touchend', onMouseUp);
1373
+ window.document.removeEventListener('mousemove', onMouseMove);
1374
+ window.document.removeEventListener('touchmove', onTouchMove);
1375
+ window.document.removeEventListener('keyup', onKeyUp);
1376
+ window.document.removeEventListener('keydown', onKeyDown);
1377
+ window.document.removeEventListener('paste', onPaste);
1378
+ };
1379
+ }, []);
1380
+ const onChangeInputFile = _react.default.useCallback(event => {
1381
+ const file = event.target.files[0];
1382
+ if (file) {
1383
+ const reader = new FileReader();
1384
+ reader.onload = eventReader => {
1385
+ refs.image.current = new Image();
1386
+ refs.image.current.src = eventReader.target.result;
1387
+ refs.toolUpdateAuto.current = true;
1388
+ event.target.value = '';
1389
+ setTool('image');
1390
+ };
1391
+ reader.readAsDataURL(file);
1392
+ }
1393
+ }, []);
1394
+ const propsCanvas = {
1395
+ width: size.width,
1396
+ height: size.height,
1397
+ disabled: !loaded,
1398
+ style: {
1399
+ width: size.width,
1400
+ height: size.height
1401
+ }
1402
+ };
1403
+ return /*#__PURE__*/_react.default.createElement(Line, (0, _extends2.default)({
1404
+ ref: item => {
1405
+ if (ref) {
1406
+ if ((0, _utils.is)('function', ref)) ref(item);else ref.current = item;
1407
+ }
1408
+ refs.root.current = item;
1409
+ },
1410
+ flex: true,
1411
+ fullWidth: true,
1412
+ className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('Whiteboard', theme) && ['onesy-Whiteboard-root'], className, classes.root])
1413
+ }, other), /*#__PURE__*/_react.default.createElement("div", {
1414
+ id: "controls",
1415
+ style: {
1416
+ position: 'absolute',
1417
+ zIndex: 14,
1418
+ top: 12,
1419
+ left: '50%'
1420
+ }
1421
+ }, /*#__PURE__*/_react.default.createElement("input", {
1422
+ type: "file",
1423
+ accept: "image/*",
1424
+ onChange: onChangeInputFile
1425
+ })), /*#__PURE__*/_react.default.createElement("canvas", (0, _extends2.default)({
1426
+ ref: refs.ui,
1427
+ onMouseDown: onMouseDown,
1428
+ onTouchStart: onTouchStart,
1429
+ onWheel: onWheel,
1430
+ className: (0, _styleReact.classNames)([classes.canvas, classes.interactive, tool === 'pan' && classes[!mouseDown ? 'pan' : 'panning'], tool === 'image' && classes.image, tool === 'text' && classes.text, ['pen', 'eraser', 'zoom'].includes(tool) && classes[tool], ['circle', 'rectangle', 'triangle', 'line', 'arrow'].includes(tool) && classes.object])
1431
+ }, propsCanvas)));
1332
1432
  });
1333
1433
  Whiteboard.displayName = 'onesy-Whiteboard';
1334
- exports.default = Whiteboard;
1434
+ var _default = exports.default = Whiteboard;