@onesy/ui-react 1.0.130 → 1.0.131
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Accordion/Accordion.js +342 -242
- package/Accordion/index.js +12 -7
- package/AdvancedTextField/AdvancedTextField.js +165 -157
- package/AdvancedTextField/index.js +12 -7
- package/Append/Append.js +502 -519
- package/Append/index.js +12 -7
- package/AreaChart/AreaChart.js +53 -40
- package/AreaChart/index.js +12 -7
- package/AreaChartItem/AreaChartItem.js +325 -237
- package/AreaChartItem/index.js +12 -7
- package/AudioPlayer/AudioPlayer.js +683 -466
- package/AudioPlayer/index.js +12 -7
- package/AudioRecorder/AudioRecorder.js +359 -259
- package/AudioRecorder/index.js +12 -7
- package/AutoComplete/AutoComplete.js +693 -568
- package/AutoComplete/index.js +12 -7
- package/AutoCompleteCountry/AutoCompleteCountry.js +99 -62
- package/AutoCompleteCountry/index.js +12 -7
- package/AutoCompleteCurrency/AutoCompleteCurrency.js +73 -61
- package/AutoCompleteCurrency/index.js +12 -7
- package/Avatar/Avatar.js +113 -86
- package/Avatar/index.js +12 -7
- package/AvatarGroup/AvatarGroup.js +104 -87
- package/AvatarGroup/index.js +12 -7
- package/Backdrop/Backdrop.js +160 -139
- package/Backdrop/index.js +12 -7
- package/Badge/Badge.js +116 -96
- package/Badge/index.js +12 -7
- package/Banner/Banner.js +126 -85
- package/Banner/index.js +12 -7
- package/BottomAppBar/BottomAppBar.js +89 -60
- package/BottomAppBar/index.js +12 -7
- package/BottomSheet/BottomSheet.js +66 -59
- package/BottomSheet/index.js +12 -7
- package/Box/Box.js +43 -35
- package/Box/index.js +12 -7
- package/Breadcrumbs/Breadcrumbs.js +168 -144
- package/Breadcrumbs/index.js +12 -7
- package/BubbleChart/BubbleChart.js +261 -132
- package/BubbleChart/index.js +12 -7
- package/BubbleChartItem/BubbleChartItem.js +228 -161
- package/BubbleChartItem/index.js +12 -7
- package/Button/Button.js +488 -467
- package/Button/index.js +12 -7
- package/Buttons/Buttons.js +366 -293
- package/Buttons/index.js +12 -7
- package/Calendar/Calendar.js +715 -452
- package/Calendar/index.js +12 -7
- package/CalendarAvailability/CalendarAvailability.js +709 -388
- package/CalendarAvailability/index.js +12 -7
- package/CalendarMenu/CalendarMenu.js +430 -303
- package/CalendarMenu/index.js +12 -7
- package/CalendarMonth/CalendarMonth.js +537 -498
- package/CalendarMonth/index.js +12 -7
- package/CalendarViews/CalendarViews.js +403 -254
- package/CalendarViews/index.js +12 -7
- package/CalendarWeek/CalendarWeek.js +536 -395
- package/CalendarWeek/index.js +12 -7
- package/Card/Card.js +133 -101
- package/Card/index.js +12 -7
- package/CardButton/CardButton.js +78 -58
- package/CardButton/index.js +12 -7
- package/CardFooter/CardFooter.js +58 -39
- package/CardFooter/index.js +12 -7
- package/CardHeader/CardHeader.js +61 -44
- package/CardHeader/index.js +12 -7
- package/CardImage/CardImage.js +80 -67
- package/CardImage/index.js +12 -7
- package/CardMain/CardMain.js +53 -39
- package/CardMain/index.js +12 -7
- package/Carousel/Carousel.js +1025 -913
- package/Carousel/index.js +12 -7
- package/Chart/Chart.js +1325 -1174
- package/Chart/index.js +12 -7
- package/Checkbox/Checkbox.js +339 -325
- package/Checkbox/index.js +12 -7
- package/Chip/Chip.js +131 -102
- package/Chip/index.js +12 -7
- package/Chips/Chips.js +121 -94
- package/Chips/index.js +12 -7
- package/ClickListener/ClickListener.js +86 -89
- package/ClickListener/index.js +12 -7
- package/Clock/Clock.js +470 -417
- package/Clock/index.js +12 -7
- package/ColorTextField/ColorTextField.js +234 -171
- package/ColorTextField/index.js +12 -7
- package/ColumnChart/ColumnChart.js +63 -46
- package/ColumnChart/index.js +12 -7
- package/ColumnChartItem/ColumnChartItem.js +208 -149
- package/ColumnChartItem/index.js +12 -7
- package/Confirm/Confirm.js +184 -129
- package/Confirm/Context.js +9 -7
- package/Confirm/index.js +32 -13
- package/Confirm/useConfirm.js +11 -10
- package/Container/Container.js +154 -133
- package/Container/index.js +12 -7
- package/CookieBanner/CookieBanner.js +142 -76
- package/CookieBanner/index.js +12 -7
- package/Countdown/Countdown.js +403 -255
- package/Countdown/index.js +12 -7
- package/DatePicker/DatePicker.js +802 -547
- package/DatePicker/index.js +12 -7
- package/DateRangePicker/DateRangePicker.js +44 -37
- package/DateRangePicker/index.js +12 -7
- package/DateTimePicker/DateTimePicker.js +672 -459
- package/DateTimePicker/index.js +12 -7
- package/DateTimeRangePicker/DateTimeRangePicker.js +44 -37
- package/DateTimeRangePicker/index.js +12 -7
- package/Divider/Divider.js +198 -185
- package/Divider/index.js +12 -7
- package/DonutChart/DonutChart.js +49 -42
- package/DonutChart/index.js +12 -7
- package/DragAndDropList/DragAndDropList.js +160 -156
- package/DragAndDropList/index.js +12 -7
- package/Drawing/Drawing.js +850 -523
- package/Drawing/index.js +12 -7
- package/DropZone/DropZone.js +239 -201
- package/DropZone/index.js +12 -7
- package/Emojis/Emojis.js +409 -317
- package/Emojis/emojis_list.js +7279 -9250
- package/Emojis/index.js +19 -9
- package/Expand/Expand.js +201 -149
- package/Expand/index.js +12 -7
- package/Fab/Fab.js +46 -26
- package/Fab/index.js +12 -7
- package/Fade/Fade.js +131 -101
- package/Fade/index.js +12 -7
- package/FileChoose/FileChoose.js +218 -150
- package/FileChoose/index.js +12 -7
- package/Focus/Focus.js +87 -88
- package/Focus/index.js +12 -7
- package/Form/Form.js +194 -120
- package/Form/index.js +12 -7
- package/FormRow/FormRow.js +123 -78
- package/FormRow/index.js +12 -7
- package/Forms/Forms.js +55 -41
- package/Forms/index.js +12 -7
- package/Frame/Frame.js +212 -150
- package/Frame/index.js +12 -7
- package/Grid/Grid.js +231 -166
- package/Grid/index.js +12 -7
- package/Grow/Grow.js +137 -109
- package/Grow/index.js +12 -7
- package/HTMLCanvas/HTMLCanvas.js +752 -542
- package/HTMLCanvas/index.js +24 -21
- package/IFrame/IFrame.js +122 -104
- package/IFrame/index.js +12 -7
- package/Icon/Icon.js +112 -95
- package/Icon/index.js +24 -21
- package/IconButton/IconButton.js +49 -37
- package/IconButton/index.js +12 -7
- package/Image/Image.js +285 -252
- package/Image/index.js +12 -7
- package/ImageCrop/ImageCrop.js +1073 -1048
- package/ImageCrop/index.js +12 -7
- package/ImageEdit/ImageEdit.js +1088 -783
- package/ImageEdit/index.js +12 -7
- package/ImageGallery/ImageGallery.js +518 -473
- package/ImageGallery/index.js +12 -7
- package/ImageList/ImageList.js +136 -129
- package/ImageList/index.js +12 -7
- package/ImageListItem/ImageListItem.js +101 -87
- package/ImageListItem/index.js +12 -7
- package/ImageListItemBox/ImageListItemBox.js +61 -50
- package/ImageListItemBox/index.js +12 -7
- package/Info/Info.js +99 -63
- package/Info/index.js +12 -7
- package/Interaction/Interaction.js +405 -345
- package/Interaction/index.js +12 -7
- package/Keyframes/Context.js +9 -7
- package/Keyframes/Keyframes.js +189 -174
- package/Keyframes/index.js +42 -25
- package/Keyframes/useKeyframes.js +11 -10
- package/Label/Label.js +177 -151
- package/Label/index.js +12 -7
- package/Labels/Labels.js +126 -98
- package/Labels/index.js +12 -7
- package/Line/Line.js +296 -174
- package/Line/index.js +12 -7
- package/LineChart/LineChart.js +57 -40
- package/LineChart/index.js +12 -7
- package/LineChartItem/LineChartItem.js +239 -177
- package/LineChartItem/index.js +12 -7
- package/LinearMeter/LinearMeter.js +453 -377
- package/LinearMeter/index.js +12 -7
- package/LinearProgress/LinearProgress.js +324 -255
- package/LinearProgress/index.js +12 -7
- package/Link/Link.js +182 -127
- package/Link/index.js +12 -7
- package/Links/Links.js +277 -156
- package/Links/index.js +12 -7
- package/List/List.js +148 -113
- package/List/index.js +12 -7
- package/ListItem/ListItem.js +388 -362
- package/ListItem/index.js +12 -7
- package/ListSubheader/ListSubheader.js +52 -44
- package/ListSubheader/index.js +12 -7
- package/MainProgress/Context.js +9 -7
- package/MainProgress/MainProgress.js +193 -161
- package/MainProgress/index.js +32 -13
- package/MainProgress/useMainProgress.js +11 -10
- package/Markdown/Markdown.js +676 -704
- package/Markdown/index.js +12 -7
- package/Masonry/Masonry.js +207 -181
- package/Masonry/index.js +12 -7
- package/Medias/Medias.js +436 -398
- package/Medias/index.js +12 -7
- package/Menu/Menu.js +278 -243
- package/Menu/index.js +12 -7
- package/MenuDesktop/MenuDesktop.js +496 -419
- package/MenuDesktop/index.js +12 -7
- package/MenuItem/MenuItem.js +286 -231
- package/MenuItem/index.js +12 -7
- package/Meta/Meta.js +78 -54
- package/Meta/index.js +12 -7
- package/Modal/Modal.js +333 -272
- package/Modal/index.js +12 -7
- package/ModalFooter/ModalFooter.js +50 -39
- package/ModalFooter/index.js +12 -7
- package/ModalHeader/ModalHeader.js +51 -39
- package/ModalHeader/index.js +12 -7
- package/ModalIcon/ModalIcon.js +29 -23
- package/ModalIcon/index.js +12 -7
- package/ModalMain/ModalMain.js +50 -41
- package/ModalMain/index.js +12 -7
- package/ModalText/ModalText.js +47 -37
- package/ModalText/index.js +12 -7
- package/ModalTitle/ModalTitle.js +47 -37
- package/ModalTitle/index.js +12 -7
- package/MoreOptions/MoreOptions.js +72 -52
- package/MoreOptions/index.js +12 -7
- package/Move/Move.js +166 -141
- package/Move/index.js +12 -7
- package/NavigationBar/NavigationBar.js +133 -109
- package/NavigationBar/index.js +12 -7
- package/NavigationDrawer/NavigationDrawer.js +241 -211
- package/NavigationDrawer/index.js +12 -7
- package/NavigationItem/NavigationItem.js +293 -262
- package/NavigationItem/index.js +12 -7
- package/NavigationRail/NavigationRail.js +187 -150
- package/NavigationRail/index.js +12 -7
- package/NotFound/NotFound.js +89 -66
- package/NotFound/index.js +12 -7
- package/NumericTextField/NumericTextField.js +217 -212
- package/NumericTextField/index.js +12 -7
- package/Page/Page.js +131 -67
- package/Page/index.js +12 -7
- package/PageTransition/PageTransition.js +112 -102
- package/PageTransition/index.js +12 -7
- package/Pagination/Pagination.js +153 -98
- package/Pagination/index.js +12 -7
- package/PaginationItem/PaginationItem.js +85 -65
- package/PaginationItem/index.js +12 -7
- package/Parallax/Parallax.js +138 -145
- package/Parallax/index.js +12 -7
- package/Path/Path.js +40 -35
- package/Path/index.js +12 -7
- package/PieChart/PieChart.js +382 -267
- package/PieChart/index.js +12 -7
- package/Placeholder/Placeholder.js +125 -117
- package/Placeholder/index.js +12 -7
- package/Portal/Portal.js +37 -38
- package/Portal/index.js +12 -7
- package/Properties/Properties.js +85 -64
- package/Properties/index.js +12 -7
- package/Property/Property.js +120 -108
- package/Property/index.js +12 -7
- package/Radio/Radio.js +211 -181
- package/Radio/index.js +12 -7
- package/Radios/Radios.js +124 -92
- package/Radios/index.js +12 -7
- package/Rating/Rating.js +353 -360
- package/Rating/index.js +12 -7
- package/Reset/Reset.js +19 -24
- package/Reset/index.js +12 -7
- package/Reveal/Reveal.js +98 -89
- package/Reveal/index.js +12 -7
- package/RichTextEditor/RichTextEditor.js +1764 -972
- package/RichTextEditor/index.js +12 -7
- package/RoundMeter/RoundMeter.js +629 -537
- package/RoundMeter/index.js +12 -7
- package/RoundProgress/RoundProgress.js +233 -174
- package/RoundProgress/index.js +12 -7
- package/ScatterChart/ScatterChart.js +53 -40
- package/ScatterChart/index.js +12 -7
- package/ScatterChartItem/ScatterChartItem.js +214 -153
- package/ScatterChartItem/index.js +12 -7
- package/ScreenCapture/ScreenCapture.js +427 -335
- package/ScreenCapture/index.js +12 -7
- package/Section/Section.js +380 -319
- package/Section/index.js +12 -7
- package/SectionAction/SectionAction.js +72 -61
- package/SectionAction/index.js +12 -7
- package/SectionBoxes/SectionBoxes.js +240 -208
- package/SectionBoxes/index.js +12 -7
- package/SectionCards/SectionCards.js +256 -217
- package/SectionCards/index.js +12 -7
- package/SectionCarousel/SectionCarousel.js +284 -242
- package/SectionCarousel/index.js +12 -7
- package/SectionContact/SectionContact.js +174 -116
- package/SectionContact/index.js +12 -7
- package/SectionImageGallery/SectionImageGallery.js +64 -51
- package/SectionImageGallery/index.js +12 -7
- package/SectionLogos/SectionLogos.js +123 -109
- package/SectionLogos/index.js +12 -7
- package/SectionMedia/SectionMedia.js +170 -152
- package/SectionMedia/index.js +12 -7
- package/SectionReviews/SectionReviews.js +170 -129
- package/SectionReviews/index.js +12 -7
- package/SectionTextMedia/SectionTextMedia.js +187 -142
- package/SectionTextMedia/index.js +12 -7
- package/SectionTimeline/SectionTimeline.js +126 -95
- package/SectionTimeline/index.js +12 -7
- package/SectionWatch/SectionWatch.js +65 -53
- package/SectionWatch/index.js +12 -7
- package/Select/Select.js +517 -406
- package/Select/index.js +12 -7
- package/Share/Share.js +458 -319
- package/Share/index.js +12 -7
- package/Slide/Slide.js +184 -140
- package/Slide/index.js +12 -7
- package/Slider/Slider.js +927 -837
- package/Slider/index.js +12 -7
- package/SmartTextField/SmartTextField.js +1406 -1014
- package/SmartTextField/index.js +12 -7
- package/Snackbar/Snackbar.js +227 -185
- package/Snackbar/index.js +12 -7
- package/Snackbars/Context.js +9 -7
- package/Snackbars/Snackbars.js +234 -210
- package/Snackbars/index.js +32 -13
- package/Snackbars/useSnackbars.js +11 -10
- package/Space/Space.js +1683 -968
- package/Space/index.js +24 -21
- package/SpeechToText/SpeechToText.js +207 -172
- package/SpeechToText/index.js +12 -7
- package/SpeedDial/SpeedDial.js +434 -398
- package/SpeedDial/index.js +12 -7
- package/SpeedDialItem/SpeedDialItem.js +89 -63
- package/SpeedDialItem/index.js +12 -7
- package/SpyScroll/SpyScroll.js +154 -142
- package/SpyScroll/index.js +12 -7
- package/Step/Step.js +181 -127
- package/Step/index.js +12 -7
- package/Stepper/Stepper.js +159 -139
- package/Stepper/index.js +12 -7
- package/Surface/Surface.js +760 -798
- package/Surface/index.js +12 -7
- package/Switch/Switch.js +688 -532
- package/Switch/index.js +12 -7
- package/Tab/Tab.js +185 -150
- package/Tab/index.js +12 -7
- package/Table/Table.js +100 -77
- package/Table/index.js +12 -7
- package/TableBody/TableBody.js +76 -63
- package/TableBody/index.js +12 -7
- package/TableCell/TableCell.js +258 -220
- package/TableCell/index.js +12 -7
- package/TableFooter/TableFooter.js +60 -48
- package/TableFooter/index.js +12 -7
- package/TableHead/TableHead.js +139 -120
- package/TableHead/index.js +12 -7
- package/TableHeader/TableHeader.js +65 -50
- package/TableHeader/index.js +12 -7
- package/TablePagination/TablePagination.js +171 -98
- package/TablePagination/index.js +12 -7
- package/TableRow/TableRow.js +77 -64
- package/TableRow/index.js +12 -7
- package/Tabs/Tabs.js +425 -377
- package/Tabs/index.js +12 -7
- package/Text/Text.js +131 -113
- package/Text/index.js +12 -7
- package/TextField/TextField.js +940 -879
- package/TextField/index.js +12 -7
- package/TextToSpeech/TextToSpeech.js +176 -153
- package/TextToSpeech/index.js +12 -7
- package/TimePicker/TimePicker.js +985 -718
- package/TimePicker/index.js +12 -7
- package/TimeRangePicker/TimeRangePicker.js +44 -37
- package/TimeRangePicker/index.js +12 -7
- package/Timeline/Timeline.js +54 -42
- package/Timeline/index.js +12 -7
- package/TimelineItem/TimelineItem.js +144 -147
- package/TimelineItem/index.js +12 -7
- package/Timer/Timer.js +321 -204
- package/Timer/index.js +12 -7
- package/ToggleButton/ToggleButton.js +67 -58
- package/ToggleButton/index.js +12 -7
- package/ToggleButtons/ToggleButtons.js +46 -37
- package/ToggleButtons/index.js +12 -7
- package/Tooltip/Tooltip.js +489 -454
- package/Tooltip/index.js +12 -7
- package/TopAppBar/TopAppBar.js +237 -197
- package/TopAppBar/index.js +12 -7
- package/Transition/Context.js +9 -7
- package/Transition/Transition.js +321 -339
- package/Transition/index.js +42 -25
- package/Transition/useTransition.js +11 -10
- package/Transitions/Transitions.js +215 -179
- package/Transitions/index.js +12 -7
- package/Tree/Tree.js +375 -312
- package/Tree/index.js +12 -7
- package/Type/Type.js +251 -152
- package/Type/index.js +12 -7
- package/VideoPlayer/VideoPlayer.js +866 -656
- package/VideoPlayer/index.js +12 -7
- package/ViewSplit/ViewSplit.js +413 -387
- package/ViewSplit/index.js +12 -7
- package/Watch/Watch.js +436 -290
- package/Watch/index.js +12 -7
- package/Weather/Weather.js +294 -247
- package/Weather/index.js +12 -7
- package/Whiteboard/Whiteboard.js +1392 -1292
- package/Whiteboard/index.js +12 -7
- package/Widgets/Context.js +9 -7
- package/Widgets/Widgets.js +220 -168
- package/Widgets/index.js +32 -13
- package/Widgets/useWidgets.js +11 -10
- package/WindowSplit/WindowSplit.js +381 -336
- package/WindowSplit/index.js +12 -7
- package/Zoom/Zoom.js +126 -99
- package/Zoom/index.js +12 -7
- package/esm/Buttons/Buttons.js +1 -1
- package/esm/index.js +1 -1
- package/index.js +4053 -660
- package/package.json +1 -1
- package/types.js +4 -1
- package/useForm/index.js +25 -11
- package/useForm/useForm.js +203 -174
- package/useForm/validate.js +215 -203
- package/useLocation/index.js +12 -7
- package/useLocation/useLocation.js +54 -49
- package/useMediaQuery/index.js +12 -7
- package/useMediaQuery/useMediaQuery.js +44 -43
- package/useQuery/index.js +12 -7
- package/useQuery/useQuery.js +14 -10
- package/useScroll/index.js +12 -7
- package/useScroll/useScroll.js +61 -56
- package/useSubscription/index.js +12 -7
- package/useSubscription/useSubscription.js +35 -35
- package/useSwipe/index.js +12 -7
- package/useSwipe/useSwipe.js +157 -131
- package/useVisible/index.js +12 -7
- package/useVisible/useVisible.js +86 -76
- package/utils.js +1224 -1362
package/ImageCrop/ImageCrop.js
CHANGED
|
@@ -1,1076 +1,1101 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 _Tooltip = _interopRequireDefault(require("../Tooltip"));
|
|
15
|
+
var _utils2 = require("../utils");
|
|
16
|
+
const _excluded = ["image", "minWidth", "minHeight", "maxWidth", "maxHeight", "selectorDefault", "selector", "onSelectorChange", "type", "quality", "aspectRatio", "gridLines", "dynamicParent", "onFocus", "onBlur", "TooltipProps", "Component", "className"];
|
|
17
|
+
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; }
|
|
18
|
+
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; }
|
|
19
|
+
const useStyle = (0, _styleReact.style)(theme => {
|
|
20
|
+
const dot = {
|
|
21
|
+
display: 'inline-block',
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
width: '6px',
|
|
24
|
+
height: '6px',
|
|
25
|
+
borderRadius: '50%',
|
|
26
|
+
background: '#a4a4a4',
|
|
27
|
+
outline: '1px solid white'
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
root: {
|
|
31
|
+
width: '100%',
|
|
32
|
+
minHeight: '1px',
|
|
33
|
+
lineHeight: '0',
|
|
34
|
+
userSelect: 'none',
|
|
35
|
+
overflow: 'hidden'
|
|
36
|
+
},
|
|
37
|
+
mouseDown_move: {
|
|
38
|
+
'& *': {
|
|
39
|
+
cursor: 'grab !important'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
mouseDown_top: {
|
|
43
|
+
'& *': {
|
|
44
|
+
cursor: 'ns-resize !important'
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
mouseDown_left: {
|
|
48
|
+
'& *': {
|
|
49
|
+
cursor: 'ew-resize !important'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
mouseDown_right: {
|
|
53
|
+
'& *': {
|
|
54
|
+
cursor: 'ew-resize !important'
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
mouseDown_bottom: {
|
|
58
|
+
'& *': {
|
|
59
|
+
cursor: 'ns-resize !important'
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
mouseDown_top_left: {
|
|
63
|
+
'& *': {
|
|
64
|
+
cursor: 'nwse-resize !important'
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
mouseDown_top_right: {
|
|
68
|
+
'& *': {
|
|
69
|
+
cursor: 'nesw-resize !important'
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
mouseDown_bottom_left: {
|
|
73
|
+
'& *': {
|
|
74
|
+
cursor: 'nesw-resize !important'
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
mouseDown_bottom_right: {
|
|
78
|
+
'& *': {
|
|
79
|
+
cursor: 'nwse-resize !important'
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
canvas: {
|
|
83
|
+
position: 'absolute',
|
|
84
|
+
zIndex: '0'
|
|
85
|
+
},
|
|
86
|
+
canvas_main: {
|
|
87
|
+
position: 'relative',
|
|
88
|
+
width: '100%',
|
|
89
|
+
height: 'auto'
|
|
90
|
+
},
|
|
91
|
+
canvas_imageSelector: {
|
|
92
|
+
zIndex: -1
|
|
93
|
+
},
|
|
94
|
+
background: {
|
|
95
|
+
position: 'absolute',
|
|
96
|
+
inset: '0',
|
|
97
|
+
width: '100%',
|
|
98
|
+
height: '100%',
|
|
99
|
+
opacity: '0',
|
|
100
|
+
background: theme.methods.palette.color.colorToRgb(theme.palette.text.default.primary, 44),
|
|
101
|
+
transition: theme.methods.transitions.make('opacity', {
|
|
102
|
+
duration: 'xxs'
|
|
103
|
+
}),
|
|
104
|
+
zIndex: '1'
|
|
105
|
+
},
|
|
106
|
+
background_in: {
|
|
107
|
+
opacity: '1'
|
|
108
|
+
},
|
|
109
|
+
imageSelector_main: {
|
|
110
|
+
position: 'absolute',
|
|
111
|
+
top: '0',
|
|
112
|
+
left: '0',
|
|
113
|
+
width: '0',
|
|
114
|
+
height: '0',
|
|
115
|
+
outline: '2px dashed white',
|
|
116
|
+
background: 'transparent',
|
|
117
|
+
touchAction: 'none',
|
|
118
|
+
opacity: '0',
|
|
119
|
+
zIndex: '14',
|
|
120
|
+
userSelect: 'none',
|
|
121
|
+
transition: theme.methods.transitions.make('opacity')
|
|
122
|
+
},
|
|
123
|
+
imageSelector_main_in: {
|
|
124
|
+
opacity: '1'
|
|
125
|
+
},
|
|
126
|
+
imageSelector: {
|
|
127
|
+
position: 'absolute',
|
|
128
|
+
top: '0',
|
|
129
|
+
left: '0',
|
|
130
|
+
width: '0',
|
|
131
|
+
height: '0',
|
|
132
|
+
touchAction: 'none',
|
|
133
|
+
overflow: 'hidden',
|
|
134
|
+
userSelect: 'none',
|
|
135
|
+
zIndex: '11'
|
|
136
|
+
},
|
|
137
|
+
move: {
|
|
138
|
+
position: 'absolute',
|
|
139
|
+
inset: '0',
|
|
140
|
+
width: '100%',
|
|
141
|
+
height: '100%',
|
|
142
|
+
cursor: 'grab',
|
|
143
|
+
'&:active': {
|
|
144
|
+
cursor: 'grabbing !important'
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
grid_line: {
|
|
148
|
+
position: 'absolute',
|
|
149
|
+
background: 'white',
|
|
150
|
+
mixBlendMode: 'difference'
|
|
151
|
+
},
|
|
152
|
+
grid_line_top_start: {
|
|
153
|
+
top: '33.3333%',
|
|
154
|
+
insetInline: '0',
|
|
155
|
+
width: '100%',
|
|
156
|
+
height: '1px'
|
|
157
|
+
},
|
|
158
|
+
grid_line_top_end: {
|
|
159
|
+
top: '66.6666%',
|
|
160
|
+
insetInline: '0',
|
|
161
|
+
width: '100%',
|
|
162
|
+
height: '1px'
|
|
163
|
+
},
|
|
164
|
+
grid_line_left_start: {
|
|
165
|
+
left: '33.3333%',
|
|
166
|
+
insetBlock: '0',
|
|
167
|
+
width: '1px',
|
|
168
|
+
height: '100%'
|
|
169
|
+
},
|
|
170
|
+
grid_line_left_end: {
|
|
171
|
+
left: '66.6666%',
|
|
172
|
+
insetBlock: '0',
|
|
173
|
+
width: '1px',
|
|
174
|
+
height: '100%'
|
|
175
|
+
},
|
|
176
|
+
dot: _objectSpread({}, dot),
|
|
177
|
+
dot_top_left: {
|
|
178
|
+
top: '-1px',
|
|
179
|
+
left: '-1px',
|
|
180
|
+
transform: 'translate(-50%, -50%)',
|
|
181
|
+
cursor: 'nwse-resize'
|
|
182
|
+
},
|
|
183
|
+
dot_top_right: {
|
|
184
|
+
top: '-1px',
|
|
185
|
+
right: '-1px',
|
|
186
|
+
transform: 'translate(50%, -50%)',
|
|
187
|
+
cursor: 'nesw-resize'
|
|
188
|
+
},
|
|
189
|
+
dot_bottom_left: {
|
|
190
|
+
bottom: '-1px',
|
|
191
|
+
left: '-1px',
|
|
192
|
+
transform: 'translate(-50%, 50%)',
|
|
193
|
+
cursor: 'nesw-resize'
|
|
194
|
+
},
|
|
195
|
+
dot_bottom_right: {
|
|
196
|
+
bottom: '-1px',
|
|
197
|
+
right: '-1px',
|
|
198
|
+
transform: 'translate(50%, 50%)',
|
|
199
|
+
cursor: 'nwse-resize'
|
|
200
|
+
},
|
|
201
|
+
border: {
|
|
202
|
+
position: 'absolute'
|
|
203
|
+
},
|
|
204
|
+
border_top: {
|
|
205
|
+
top: '-2px',
|
|
206
|
+
height: '2px',
|
|
207
|
+
width: '100%',
|
|
208
|
+
cursor: 'ns-resize',
|
|
209
|
+
'&::before': _objectSpread(_objectSpread({}, dot), {}, {
|
|
210
|
+
content: '""',
|
|
211
|
+
top: '50%',
|
|
212
|
+
left: '50%',
|
|
213
|
+
transform: 'translate(-50%, -50%)'
|
|
214
|
+
})
|
|
215
|
+
},
|
|
216
|
+
border_left: {
|
|
217
|
+
left: '-2px',
|
|
218
|
+
height: '100%',
|
|
219
|
+
width: '2px',
|
|
220
|
+
cursor: 'ew-resize',
|
|
221
|
+
'&::before': _objectSpread(_objectSpread({}, dot), {}, {
|
|
222
|
+
content: '""',
|
|
223
|
+
top: '50%',
|
|
224
|
+
left: '50%',
|
|
225
|
+
transform: 'translate(-50%, -50%)'
|
|
226
|
+
})
|
|
227
|
+
},
|
|
228
|
+
border_right: {
|
|
229
|
+
right: '-2px',
|
|
230
|
+
height: '100%',
|
|
231
|
+
width: '2px',
|
|
232
|
+
cursor: 'ew-resize',
|
|
233
|
+
'&::before': _objectSpread(_objectSpread({}, dot), {}, {
|
|
234
|
+
content: '""',
|
|
235
|
+
top: '50%',
|
|
236
|
+
right: '50%',
|
|
237
|
+
transform: 'translate(50%, -50%)'
|
|
238
|
+
})
|
|
239
|
+
},
|
|
240
|
+
border_bottom: {
|
|
241
|
+
bottom: '-2px',
|
|
242
|
+
height: '2px',
|
|
243
|
+
width: '100%',
|
|
244
|
+
cursor: 'ns-resize',
|
|
245
|
+
'&::before': _objectSpread(_objectSpread({}, dot), {}, {
|
|
246
|
+
content: '""',
|
|
247
|
+
bottom: '50%',
|
|
248
|
+
left: '50%',
|
|
249
|
+
transform: 'translate(-50%, 50%)'
|
|
250
|
+
})
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}, {
|
|
254
|
+
name: 'onesy-ImageCrop'
|
|
255
|
+
});
|
|
256
|
+
const ImageCrop = /*#__PURE__*/_react.default.forwardRef((props_, ref) => {
|
|
257
|
+
var _refs$root$current4;
|
|
258
|
+
const theme = (0, _styleReact.useOnesyTheme)();
|
|
259
|
+
const props = _react.default.useMemo(() => {
|
|
260
|
+
var _theme$ui, _theme$ui2;
|
|
261
|
+
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.onesyImageCrop) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_);
|
|
262
|
+
}, [props_]);
|
|
263
|
+
const Tooltip = _react.default.useMemo(() => {
|
|
264
|
+
var _theme$elements;
|
|
265
|
+
return (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Tooltip) || _Tooltip.default;
|
|
266
|
+
}, [theme]);
|
|
267
|
+
const {
|
|
268
|
+
// url, datauri or canvas
|
|
269
|
+
image: image_,
|
|
270
|
+
minWidth,
|
|
271
|
+
minHeight,
|
|
272
|
+
maxWidth,
|
|
273
|
+
maxHeight,
|
|
274
|
+
selectorDefault,
|
|
275
|
+
selector: selector_,
|
|
276
|
+
onSelectorChange: onSelectorChange_,
|
|
277
|
+
type = `image/jpeg`,
|
|
278
|
+
quality = 1,
|
|
279
|
+
aspectRatio,
|
|
280
|
+
gridLines,
|
|
281
|
+
dynamicParent,
|
|
282
|
+
onFocus: onFocus_,
|
|
283
|
+
onBlur: onBlur_,
|
|
284
|
+
TooltipProps,
|
|
285
|
+
Component = 'div',
|
|
286
|
+
className
|
|
287
|
+
} = props,
|
|
288
|
+
other = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
289
|
+
const {
|
|
290
|
+
classes
|
|
291
|
+
} = useStyle();
|
|
292
|
+
const [image, setImage] = _react.default.useState();
|
|
293
|
+
const [focus, setFocus] = _react.default.useState();
|
|
294
|
+
const [mouseDown, setMouseDown] = _react.default.useState();
|
|
295
|
+
const [selector, setSelector] = _react.default.useState(selectorDefault !== undefined ? selectorDefault : selector_);
|
|
296
|
+
const [selectorRelative, setSelectorRelative] = _react.default.useState();
|
|
297
|
+
const refs = {
|
|
298
|
+
root: _react.default.useRef(null),
|
|
299
|
+
image: _react.default.useRef(null),
|
|
300
|
+
mouseDown: _react.default.useRef(null),
|
|
301
|
+
selector: _react.default.useRef(null),
|
|
302
|
+
imageSelectorMain: _react.default.useRef(null),
|
|
303
|
+
imageSelector: _react.default.useRef(null),
|
|
304
|
+
previousMouseEvent: _react.default.useRef(null),
|
|
305
|
+
canvasMain: _react.default.useRef(null),
|
|
306
|
+
canvasImageSelector: _react.default.useRef(null),
|
|
307
|
+
move: _react.default.useRef(null),
|
|
308
|
+
borderTop: _react.default.useRef(null),
|
|
309
|
+
borderLeft: _react.default.useRef(null),
|
|
310
|
+
borderRight: _react.default.useRef(null),
|
|
311
|
+
borderBottom: _react.default.useRef(null),
|
|
312
|
+
dotTopLeft: _react.default.useRef(null),
|
|
313
|
+
dotTopRight: _react.default.useRef(null),
|
|
314
|
+
dotBottomLeft: _react.default.useRef(null),
|
|
315
|
+
dotBottomRight: _react.default.useRef(null),
|
|
316
|
+
props: _react.default.useRef(null),
|
|
317
|
+
dynamicParent: _react.default.useRef(null),
|
|
318
|
+
focus: _react.default.useRef(null),
|
|
319
|
+
aspectRatio: _react.default.useRef(null)
|
|
320
|
+
};
|
|
321
|
+
refs.image.current = image;
|
|
322
|
+
refs.mouseDown.current = mouseDown;
|
|
323
|
+
refs.selector.current = selector;
|
|
324
|
+
refs.props.current = props;
|
|
325
|
+
refs.focus.current = focus;
|
|
326
|
+
refs.dynamicParent.current = dynamicParent;
|
|
327
|
+
refs.aspectRatio.current = aspectRatio;
|
|
328
|
+
const onSelectorChange = valueNew => {
|
|
329
|
+
var _refs$canvasMain$curr, _refs$canvasMain$curr2, _refs$canvasMain$curr3, _refs$canvasMain$curr4;
|
|
330
|
+
// min, max for width, height
|
|
331
|
+
// + resolve it to max width and height for aspect ratio
|
|
332
|
+
if ((0, _utils.is)('object', valueNew) && !!Object.keys(valueNew).length && refs.root.current) {
|
|
333
|
+
var _refs$root$current, _refs$mouseDown$curre;
|
|
334
|
+
const rootRect = (_refs$root$current = refs.root.current) === null || _refs$root$current === void 0 ? void 0 : _refs$root$current.getBoundingClientRect();
|
|
335
|
+
const minWidth_ = refs.props.current.minWidth !== undefined ? refs.props.current.minWidth : Number.MIN_SAFE_INTEGER;
|
|
336
|
+
const minHeight_ = refs.props.current.minHeight !== undefined ? refs.props.current.minHeight : Number.MIN_SAFE_INTEGER;
|
|
337
|
+
const maxWidth_ = refs.props.current.maxWidth !== undefined ? refs.props.current.maxWidth : Number.MAX_SAFE_INTEGER;
|
|
338
|
+
const maxHeight_ = refs.props.current.maxHeight !== undefined ? refs.props.current.maxHeight : Number.MAX_SAFE_INTEGER;
|
|
339
|
+
valueNew.width = (0, _utils.clamp)(valueNew.width, minWidth_, maxWidth_);
|
|
340
|
+
valueNew.height = (0, _utils.clamp)(valueNew.height, minHeight_, maxHeight_);
|
|
341
|
+
if (refs.aspectRatio.current !== undefined) {
|
|
342
|
+
if (valueNew.width + valueNew.width / refs.aspectRatio.current >= valueNew.height + valueNew.height * refs.aspectRatio.current) {
|
|
343
|
+
valueNew.height = valueNew.width / refs.aspectRatio.current;
|
|
344
|
+
} else {
|
|
345
|
+
valueNew.width = valueNew.height * refs.aspectRatio.current;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Max width
|
|
349
|
+
if (valueNew.left + valueNew.width > rootRect.width) {
|
|
350
|
+
valueNew.width = rootRect.width - valueNew.left;
|
|
351
|
+
valueNew.height = valueNew.width / refs.aspectRatio.current;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Max height
|
|
355
|
+
if (valueNew.top + valueNew.height > rootRect.height) {
|
|
356
|
+
valueNew.height = rootRect.height - valueNew.top;
|
|
357
|
+
valueNew.width = valueNew.height * refs.aspectRatio.current;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Max width, height per maxWidth and maxHeight
|
|
361
|
+
if (valueNew.width < minWidth_ || valueNew.width > maxWidth_) {
|
|
362
|
+
valueNew.width = (0, _utils.clamp)(valueNew.width, minWidth_, maxWidth_);
|
|
363
|
+
valueNew.height = valueNew.width / refs.aspectRatio.current;
|
|
10
364
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
365
|
+
if (valueNew.height < minHeight_ || valueNew.height > maxHeight_) {
|
|
366
|
+
valueNew.height = (0, _utils.clamp)(valueNew.height, minHeight_, maxHeight_);
|
|
367
|
+
valueNew.width = valueNew.height / refs.aspectRatio.current;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// If previous values are within maxWidth and/or maxHeight
|
|
372
|
+
// and left or top are not same as before
|
|
373
|
+
// return
|
|
374
|
+
if (!['move'].includes((_refs$mouseDown$curre = refs.mouseDown.current) === null || _refs$mouseDown$curre === void 0 ? void 0 : _refs$mouseDown$curre.version)) {
|
|
375
|
+
if (maxWidth_ !== undefined || maxHeight_ !== undefined) {
|
|
376
|
+
var _refs$selector$curren, _refs$selector$curren2, _refs$selector$curren3, _refs$selector$curren4;
|
|
377
|
+
if ((valueNew.top < ((_refs$selector$curren = refs.selector.current) === null || _refs$selector$curren === void 0 ? void 0 : _refs$selector$curren.top) || valueNew.left < ((_refs$selector$curren2 = refs.selector.current) === null || _refs$selector$curren2 === void 0 ? void 0 : _refs$selector$curren2.left)) && (((_refs$selector$curren3 = refs.selector.current) === null || _refs$selector$curren3 === void 0 ? void 0 : _refs$selector$curren3.width) === maxWidth_ || ((_refs$selector$curren4 = refs.selector.current) === null || _refs$selector$curren4 === void 0 ? void 0 : _refs$selector$curren4.height) === maxHeight_)) return;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const rootRect_ = refs.root.current.getBoundingClientRect();
|
|
382
|
+
const selectorRelative_ = {
|
|
383
|
+
top: valueNew.top / (rootRect_ === null || rootRect_ === void 0 ? void 0 : rootRect_.height) * ((_refs$canvasMain$curr = refs.canvasMain.current) === null || _refs$canvasMain$curr === void 0 ? void 0 : _refs$canvasMain$curr.height),
|
|
384
|
+
left: valueNew.left / (rootRect_ === null || rootRect_ === void 0 ? void 0 : rootRect_.width) * ((_refs$canvasMain$curr2 = refs.canvasMain.current) === null || _refs$canvasMain$curr2 === void 0 ? void 0 : _refs$canvasMain$curr2.width),
|
|
385
|
+
width: valueNew.width / (rootRect_ === null || rootRect_ === void 0 ? void 0 : rootRect_.width) * ((_refs$canvasMain$curr3 = refs.canvasMain.current) === null || _refs$canvasMain$curr3 === void 0 ? void 0 : _refs$canvasMain$curr3.width),
|
|
386
|
+
height: valueNew.height / (rootRect_ === null || rootRect_ === void 0 ? void 0 : rootRect_.height) * ((_refs$canvasMain$curr4 = refs.canvasMain.current) === null || _refs$canvasMain$curr4 === void 0 ? void 0 : _refs$canvasMain$curr4.height)
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// Update inner or controlled
|
|
390
|
+
if (!props.hasOwnProperty('selector')) {
|
|
391
|
+
setSelector(valueNew);
|
|
392
|
+
setSelectorRelative(selectorRelative_);
|
|
393
|
+
}
|
|
394
|
+
if ((0, _utils.is)('function', onSelectorChange_)) onSelectorChange_(selectorRelative_);
|
|
395
|
+
};
|
|
396
|
+
_react.default.useEffect(() => {
|
|
397
|
+
var _refs$root$current2;
|
|
398
|
+
const method = event => {
|
|
399
|
+
switch (event.key) {
|
|
400
|
+
case 'Escape':
|
|
401
|
+
if (refs.focus.current) setSelector({});
|
|
402
|
+
break;
|
|
403
|
+
default:
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
32
406
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
407
|
+
const onMouseUp = event => {
|
|
408
|
+
setMouseDown(false);
|
|
409
|
+
refs.previousMouseEvent.current = undefined;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// Move
|
|
413
|
+
const onMove = (x, y) => {
|
|
414
|
+
if (refs.mouseDown.current && refs.previousMouseEvent.current) {
|
|
415
|
+
var _refs$mouseDown$curre2, _refs$mouseDown$curre3, _refs$mouseDown$curre4, _refs$mouseDown$curre5, _refs$mouseDown$curre6, _refs$mouseDown$curre7, _refs$mouseDown$curre8, _refs$mouseDown$curre9, _refs$mouseDown$curre10, _refs$mouseDown$curre11;
|
|
416
|
+
const {
|
|
417
|
+
top: previousTop,
|
|
418
|
+
left: previousLeft
|
|
419
|
+
} = refs.mouseDown.current;
|
|
420
|
+
const rootRect = refs.root.current.getBoundingClientRect();
|
|
421
|
+
const selectorRect_ = refs.imageSelectorMain.current.getBoundingClientRect();
|
|
422
|
+
const selectorRect = {};
|
|
423
|
+
|
|
424
|
+
// Normalize relative to root
|
|
425
|
+
selectorRect.width = selectorRect_.width;
|
|
426
|
+
selectorRect.height = selectorRect_.height;
|
|
427
|
+
selectorRect.top = selectorRect_.top - rootRect.top;
|
|
428
|
+
selectorRect.left = selectorRect_.left - rootRect.left;
|
|
429
|
+
selectorRect.right = selectorRect.left + selectorRect_.width;
|
|
430
|
+
selectorRect.bottom = selectorRect.top + selectorRect_.height;
|
|
431
|
+
if (((_refs$mouseDown$curre2 = refs.mouseDown.current) === null || _refs$mouseDown$curre2 === void 0 ? void 0 : _refs$mouseDown$curre2.version) === 'make') {
|
|
432
|
+
const top_ = (0, _utils.clamp)(y - rootRect.top, 0, rootRect.height);
|
|
433
|
+
const left_ = (0, _utils.clamp)(x - rootRect.left, 0, rootRect.width);
|
|
434
|
+
let top = (0, _utils.clamp)(top_, 0, previousTop);
|
|
435
|
+
let left = (0, _utils.clamp)(left_, 0, previousLeft);
|
|
436
|
+
let width = Math.abs(left_ - previousLeft);
|
|
437
|
+
let height = Math.abs(top_ - previousTop);
|
|
438
|
+
if (refs.aspectRatio.current !== undefined) {
|
|
439
|
+
if (left < previousLeft) {
|
|
440
|
+
var _refs$selector$curren5, _refs$selector$curren6, _refs$selector$curren7, _refs$selector$curren8;
|
|
441
|
+
if (((_refs$selector$curren5 = refs.selector.current) === null || _refs$selector$curren5 === void 0 ? void 0 : _refs$selector$curren5.left) < previousLeft && left < ((_refs$selector$curren6 = refs.selector.current) === null || _refs$selector$curren6 === void 0 ? void 0 : _refs$selector$curren6.left) && (top <= 0 || ((_refs$selector$curren7 = refs.selector.current) === null || _refs$selector$curren7 === void 0 ? void 0 : _refs$selector$curren7.top) + ((_refs$selector$curren8 = refs.selector.current) === null || _refs$selector$curren8 === void 0 ? void 0 : _refs$selector$curren8.height) >= rootRect.height)) return;
|
|
44
442
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
cursor: 'ns-resize !important'
|
|
443
|
+
if (top < previousTop) {
|
|
444
|
+
var _refs$selector$curren9, _refs$selector$curren10, _refs$selector$curren11, _refs$selector$curren12;
|
|
445
|
+
if (((_refs$selector$curren9 = refs.selector.current) === null || _refs$selector$curren9 === void 0 ? void 0 : _refs$selector$curren9.top) < previousTop && top < ((_refs$selector$curren10 = refs.selector.current) === null || _refs$selector$curren10 === void 0 ? void 0 : _refs$selector$curren10.top) && (left <= 0 || ((_refs$selector$curren11 = refs.selector.current) === null || _refs$selector$curren11 === void 0 ? void 0 : _refs$selector$curren11.left) + ((_refs$selector$curren12 = refs.selector.current) === null || _refs$selector$curren12 === void 0 ? void 0 : _refs$selector$curren12.width) >= rootRect.width)) return;
|
|
49
446
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
447
|
+
|
|
448
|
+
// Max surface
|
|
449
|
+
if (width + width / refs.aspectRatio.current >= height + height * refs.aspectRatio.current) {
|
|
450
|
+
height = width / refs.aspectRatio.current;
|
|
451
|
+
} else {
|
|
452
|
+
width = height * refs.aspectRatio.current;
|
|
54
453
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
454
|
+
|
|
455
|
+
// Moved left
|
|
456
|
+
if (left < previousLeft) {
|
|
457
|
+
left = (0, _utils.clamp)(previousLeft - width, 0, previousLeft);
|
|
458
|
+
|
|
459
|
+
// Update width, height upto the previousLeft
|
|
460
|
+
width = (0, _utils.clamp)(width, 0, previousLeft);
|
|
461
|
+
height = width / refs.aspectRatio.current;
|
|
59
462
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
463
|
+
|
|
464
|
+
// Moved top
|
|
465
|
+
if (top < previousTop) {
|
|
466
|
+
top = (0, _utils.clamp)(previousTop - height, 0, previousTop);
|
|
467
|
+
|
|
468
|
+
// Update width, height upto the previousTop
|
|
469
|
+
height = (0, _utils.clamp)(height, 0, previousTop);
|
|
470
|
+
width = height * refs.aspectRatio.current;
|
|
64
471
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
472
|
+
|
|
473
|
+
// Max width
|
|
474
|
+
if (left + width > rootRect.width) {
|
|
475
|
+
width = rootRect.width - left;
|
|
476
|
+
height = width / refs.aspectRatio.current;
|
|
69
477
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
478
|
+
|
|
479
|
+
// Max height
|
|
480
|
+
if (top + height > rootRect.height) {
|
|
481
|
+
height = rootRect.height - top;
|
|
482
|
+
width = height * refs.aspectRatio.current;
|
|
74
483
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
484
|
+
|
|
485
|
+
// Min left
|
|
486
|
+
if (left < previousLeft) left = previousLeft - width;
|
|
487
|
+
|
|
488
|
+
// Min top
|
|
489
|
+
if (top < previousTop) top = previousTop - height;
|
|
490
|
+
}
|
|
491
|
+
onSelectorChange(_objectSpread(_objectSpread({}, refs.selector.current), {}, {
|
|
492
|
+
top,
|
|
493
|
+
left,
|
|
494
|
+
width,
|
|
495
|
+
height
|
|
496
|
+
}));
|
|
497
|
+
} else if (((_refs$mouseDown$curre3 = refs.mouseDown.current) === null || _refs$mouseDown$curre3 === void 0 ? void 0 : _refs$mouseDown$curre3.version) === 'move') {
|
|
498
|
+
const top = y - refs.previousMouseEvent.current.clientY;
|
|
499
|
+
const left = x - refs.previousMouseEvent.current.clientX;
|
|
500
|
+
onSelectorChange(_objectSpread(_objectSpread({}, refs.selector.current), {}, {
|
|
501
|
+
top: (0, _utils.clamp)(refs.selector.current.top + top, 0, rootRect.height - selectorRect.height),
|
|
502
|
+
left: (0, _utils.clamp)(refs.selector.current.left + left, 0, rootRect.width - selectorRect.width)
|
|
503
|
+
}));
|
|
504
|
+
} else if (((_refs$mouseDown$curre4 = refs.mouseDown.current) === null || _refs$mouseDown$curre4 === void 0 ? void 0 : _refs$mouseDown$curre4.version) === 'top_left') {
|
|
505
|
+
const incY = y - refs.previousMouseEvent.current.clientY;
|
|
506
|
+
const incX = x - refs.previousMouseEvent.current.clientX;
|
|
507
|
+
let top = (0, _utils.clamp)(selectorRect.top + incY, 0);
|
|
508
|
+
let left = (0, _utils.clamp)(selectorRect.left + incX, 0);
|
|
509
|
+
if (selectorRect.bottom - top < 0 && selectorRect.right - left < 0) refs.mouseDown.current.version = 'bottom_right';else if (selectorRect.bottom - top < 0) refs.mouseDown.current.version = 'bottom_left';else if (selectorRect.right - left < 0) refs.mouseDown.current.version = 'top_right';
|
|
510
|
+
let width = (0, _utils.clamp)(selectorRect.right - left, 0);
|
|
511
|
+
let height = (0, _utils.clamp)(selectorRect.bottom - top, 0);
|
|
512
|
+
if (refs.aspectRatio.current !== undefined) {
|
|
513
|
+
var _refs$selector$curren13;
|
|
514
|
+
// Left
|
|
515
|
+
if (left < refs.selector.current.left && refs.selector.current.left < previousLeft && ((_refs$selector$curren13 = refs.selector.current) === null || _refs$selector$curren13 === void 0 ? void 0 : _refs$selector$curren13.top) === 0) return;
|
|
516
|
+
|
|
517
|
+
// Max surface
|
|
518
|
+
if (width + width / refs.aspectRatio.current >= height + height * refs.aspectRatio.current) {
|
|
519
|
+
height = width / refs.aspectRatio.current;
|
|
520
|
+
} else {
|
|
521
|
+
width = height * refs.aspectRatio.current;
|
|
79
522
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
523
|
+
|
|
524
|
+
// Moved left
|
|
525
|
+
if (left < previousLeft) {
|
|
526
|
+
left = (0, _utils.clamp)(previousLeft - width, 0, previousLeft);
|
|
527
|
+
|
|
528
|
+
// Update width, height upto the previousLeft
|
|
529
|
+
width = (0, _utils.clamp)(width, 0, previousLeft);
|
|
530
|
+
height = width / refs.aspectRatio.current;
|
|
84
531
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
height: 'auto'
|
|
94
|
-
},
|
|
95
|
-
canvas_imageSelector: {
|
|
96
|
-
zIndex: -1
|
|
97
|
-
},
|
|
98
|
-
background: {
|
|
99
|
-
position: 'absolute',
|
|
100
|
-
inset: '0',
|
|
101
|
-
width: '100%',
|
|
102
|
-
height: '100%',
|
|
103
|
-
opacity: '0',
|
|
104
|
-
background: theme.methods.palette.color.colorToRgb(theme.palette.text.default.primary, 44),
|
|
105
|
-
transition: theme.methods.transitions.make('opacity', { duration: 'xxs' }),
|
|
106
|
-
zIndex: '1'
|
|
107
|
-
},
|
|
108
|
-
background_in: {
|
|
109
|
-
opacity: '1'
|
|
110
|
-
},
|
|
111
|
-
imageSelector_main: {
|
|
112
|
-
position: 'absolute',
|
|
113
|
-
top: '0',
|
|
114
|
-
left: '0',
|
|
115
|
-
width: '0',
|
|
116
|
-
height: '0',
|
|
117
|
-
outline: '2px dashed white',
|
|
118
|
-
background: 'transparent',
|
|
119
|
-
touchAction: 'none',
|
|
120
|
-
opacity: '0',
|
|
121
|
-
zIndex: '14',
|
|
122
|
-
userSelect: 'none',
|
|
123
|
-
transition: theme.methods.transitions.make('opacity'),
|
|
124
|
-
},
|
|
125
|
-
imageSelector_main_in: {
|
|
126
|
-
opacity: '1'
|
|
127
|
-
},
|
|
128
|
-
imageSelector: {
|
|
129
|
-
position: 'absolute',
|
|
130
|
-
top: '0',
|
|
131
|
-
left: '0',
|
|
132
|
-
width: '0',
|
|
133
|
-
height: '0',
|
|
134
|
-
touchAction: 'none',
|
|
135
|
-
overflow: 'hidden',
|
|
136
|
-
userSelect: 'none',
|
|
137
|
-
zIndex: '11'
|
|
138
|
-
},
|
|
139
|
-
move: {
|
|
140
|
-
position: 'absolute',
|
|
141
|
-
inset: '0',
|
|
142
|
-
width: '100%',
|
|
143
|
-
height: '100%',
|
|
144
|
-
cursor: 'grab',
|
|
145
|
-
'&:active': {
|
|
146
|
-
cursor: 'grabbing !important'
|
|
532
|
+
|
|
533
|
+
// Moved top
|
|
534
|
+
if (top < previousTop) {
|
|
535
|
+
top = (0, _utils.clamp)(previousTop - height, 0, previousTop);
|
|
536
|
+
|
|
537
|
+
// Update width, height upto the previousTop
|
|
538
|
+
height = (0, _utils.clamp)(height, 0, previousTop);
|
|
539
|
+
width = height * refs.aspectRatio.current;
|
|
147
540
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
},
|
|
154
|
-
grid_line_top_start: {
|
|
155
|
-
top: '33.3333%',
|
|
156
|
-
insetInline: '0',
|
|
157
|
-
width: '100%',
|
|
158
|
-
height: '1px'
|
|
159
|
-
},
|
|
160
|
-
grid_line_top_end: {
|
|
161
|
-
top: '66.6666%',
|
|
162
|
-
insetInline: '0',
|
|
163
|
-
width: '100%',
|
|
164
|
-
height: '1px'
|
|
165
|
-
},
|
|
166
|
-
grid_line_left_start: {
|
|
167
|
-
left: '33.3333%',
|
|
168
|
-
insetBlock: '0',
|
|
169
|
-
width: '1px',
|
|
170
|
-
height: '100%'
|
|
171
|
-
},
|
|
172
|
-
grid_line_left_end: {
|
|
173
|
-
left: '66.6666%',
|
|
174
|
-
insetBlock: '0',
|
|
175
|
-
width: '1px',
|
|
176
|
-
height: '100%'
|
|
177
|
-
},
|
|
178
|
-
dot: Object.assign({}, dot),
|
|
179
|
-
dot_top_left: {
|
|
180
|
-
top: '-1px',
|
|
181
|
-
left: '-1px',
|
|
182
|
-
transform: 'translate(-50%, -50%)',
|
|
183
|
-
cursor: 'nwse-resize'
|
|
184
|
-
},
|
|
185
|
-
dot_top_right: {
|
|
186
|
-
top: '-1px',
|
|
187
|
-
right: '-1px',
|
|
188
|
-
transform: 'translate(50%, -50%)',
|
|
189
|
-
cursor: 'nesw-resize'
|
|
190
|
-
},
|
|
191
|
-
dot_bottom_left: {
|
|
192
|
-
bottom: '-1px',
|
|
193
|
-
left: '-1px',
|
|
194
|
-
transform: 'translate(-50%, 50%)',
|
|
195
|
-
cursor: 'nesw-resize'
|
|
196
|
-
},
|
|
197
|
-
dot_bottom_right: {
|
|
198
|
-
bottom: '-1px',
|
|
199
|
-
right: '-1px',
|
|
200
|
-
transform: 'translate(50%, 50%)',
|
|
201
|
-
cursor: 'nwse-resize'
|
|
202
|
-
},
|
|
203
|
-
border: {
|
|
204
|
-
position: 'absolute'
|
|
205
|
-
},
|
|
206
|
-
border_top: {
|
|
207
|
-
top: '-2px',
|
|
208
|
-
height: '2px',
|
|
209
|
-
width: '100%',
|
|
210
|
-
cursor: 'ns-resize',
|
|
211
|
-
'&::before': Object.assign(Object.assign({}, dot), { content: '""', top: '50%', left: '50%', transform: 'translate(-50%, -50%)' })
|
|
212
|
-
},
|
|
213
|
-
border_left: {
|
|
214
|
-
left: '-2px',
|
|
215
|
-
height: '100%',
|
|
216
|
-
width: '2px',
|
|
217
|
-
cursor: 'ew-resize',
|
|
218
|
-
'&::before': Object.assign(Object.assign({}, dot), { content: '""', top: '50%', left: '50%', transform: 'translate(-50%, -50%)' })
|
|
219
|
-
},
|
|
220
|
-
border_right: {
|
|
221
|
-
right: '-2px',
|
|
222
|
-
height: '100%',
|
|
223
|
-
width: '2px',
|
|
224
|
-
cursor: 'ew-resize',
|
|
225
|
-
'&::before': Object.assign(Object.assign({}, dot), { content: '""', top: '50%', right: '50%', transform: 'translate(50%, -50%)' })
|
|
226
|
-
},
|
|
227
|
-
border_bottom: {
|
|
228
|
-
bottom: '-2px',
|
|
229
|
-
height: '2px',
|
|
230
|
-
width: '100%',
|
|
231
|
-
cursor: 'ns-resize',
|
|
232
|
-
'&::before': Object.assign(Object.assign({}, dot), { content: '""', bottom: '50%', left: '50%', transform: 'translate(-50%, 50%)' })
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
}, { name: 'onesy-ImageCrop' });
|
|
236
|
-
const ImageCrop = react_1.default.forwardRef((props_, ref) => {
|
|
237
|
-
var _a;
|
|
238
|
-
const theme = (0, style_react_1.useOnesyTheme)();
|
|
239
|
-
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.onesyImageCrop) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]);
|
|
240
|
-
const Tooltip = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Tooltip) || Tooltip_1.default; }, [theme]);
|
|
241
|
-
const {
|
|
242
|
-
// url, datauri or canvas
|
|
243
|
-
image: image_, minWidth, minHeight, maxWidth, maxHeight, selectorDefault, selector: selector_, onSelectorChange: onSelectorChange_, type = `image/jpeg`, quality = 1, aspectRatio, gridLines, dynamicParent, onFocus: onFocus_, onBlur: onBlur_, TooltipProps, Component = 'div', className } = props, other = __rest(props, ["image", "minWidth", "minHeight", "maxWidth", "maxHeight", "selectorDefault", "selector", "onSelectorChange", "type", "quality", "aspectRatio", "gridLines", "dynamicParent", "onFocus", "onBlur", "TooltipProps", "Component", "className"]);
|
|
244
|
-
const { classes } = useStyle();
|
|
245
|
-
const [image, setImage] = react_1.default.useState();
|
|
246
|
-
const [focus, setFocus] = react_1.default.useState();
|
|
247
|
-
const [mouseDown, setMouseDown] = react_1.default.useState();
|
|
248
|
-
const [selector, setSelector] = react_1.default.useState(selectorDefault !== undefined ? selectorDefault : selector_);
|
|
249
|
-
const [selectorRelative, setSelectorRelative] = react_1.default.useState();
|
|
250
|
-
const refs = {
|
|
251
|
-
root: react_1.default.useRef(null),
|
|
252
|
-
image: react_1.default.useRef(null),
|
|
253
|
-
mouseDown: react_1.default.useRef(null),
|
|
254
|
-
selector: react_1.default.useRef(null),
|
|
255
|
-
imageSelectorMain: react_1.default.useRef(null),
|
|
256
|
-
imageSelector: react_1.default.useRef(null),
|
|
257
|
-
previousMouseEvent: react_1.default.useRef(null),
|
|
258
|
-
canvasMain: react_1.default.useRef(null),
|
|
259
|
-
canvasImageSelector: react_1.default.useRef(null),
|
|
260
|
-
move: react_1.default.useRef(null),
|
|
261
|
-
borderTop: react_1.default.useRef(null),
|
|
262
|
-
borderLeft: react_1.default.useRef(null),
|
|
263
|
-
borderRight: react_1.default.useRef(null),
|
|
264
|
-
borderBottom: react_1.default.useRef(null),
|
|
265
|
-
dotTopLeft: react_1.default.useRef(null),
|
|
266
|
-
dotTopRight: react_1.default.useRef(null),
|
|
267
|
-
dotBottomLeft: react_1.default.useRef(null),
|
|
268
|
-
dotBottomRight: react_1.default.useRef(null),
|
|
269
|
-
props: react_1.default.useRef(null),
|
|
270
|
-
dynamicParent: react_1.default.useRef(null),
|
|
271
|
-
focus: react_1.default.useRef(null),
|
|
272
|
-
aspectRatio: react_1.default.useRef(null)
|
|
273
|
-
};
|
|
274
|
-
refs.image.current = image;
|
|
275
|
-
refs.mouseDown.current = mouseDown;
|
|
276
|
-
refs.selector.current = selector;
|
|
277
|
-
refs.props.current = props;
|
|
278
|
-
refs.focus.current = focus;
|
|
279
|
-
refs.dynamicParent.current = dynamicParent;
|
|
280
|
-
refs.aspectRatio.current = aspectRatio;
|
|
281
|
-
const onSelectorChange = (valueNew) => {
|
|
282
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
283
|
-
// min, max for width, height
|
|
284
|
-
// + resolve it to max width and height for aspect ratio
|
|
285
|
-
if ((0, utils_1.is)('object', valueNew) && !!Object.keys(valueNew).length && refs.root.current) {
|
|
286
|
-
const rootRect = (_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
287
|
-
const minWidth_ = refs.props.current.minWidth !== undefined ? refs.props.current.minWidth : Number.MIN_SAFE_INTEGER;
|
|
288
|
-
const minHeight_ = refs.props.current.minHeight !== undefined ? refs.props.current.minHeight : Number.MIN_SAFE_INTEGER;
|
|
289
|
-
const maxWidth_ = refs.props.current.maxWidth !== undefined ? refs.props.current.maxWidth : Number.MAX_SAFE_INTEGER;
|
|
290
|
-
const maxHeight_ = refs.props.current.maxHeight !== undefined ? refs.props.current.maxHeight : Number.MAX_SAFE_INTEGER;
|
|
291
|
-
valueNew.width = (0, utils_1.clamp)(valueNew.width, minWidth_, maxWidth_);
|
|
292
|
-
valueNew.height = (0, utils_1.clamp)(valueNew.height, minHeight_, maxHeight_);
|
|
293
|
-
if (refs.aspectRatio.current !== undefined) {
|
|
294
|
-
if (valueNew.width + (valueNew.width / refs.aspectRatio.current) >= valueNew.height + (valueNew.height * refs.aspectRatio.current)) {
|
|
295
|
-
valueNew.height = valueNew.width / refs.aspectRatio.current;
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
valueNew.width = valueNew.height * refs.aspectRatio.current;
|
|
299
|
-
}
|
|
300
|
-
// Max width
|
|
301
|
-
if (valueNew.left + valueNew.width > rootRect.width) {
|
|
302
|
-
valueNew.width = rootRect.width - valueNew.left;
|
|
303
|
-
valueNew.height = valueNew.width / refs.aspectRatio.current;
|
|
304
|
-
}
|
|
305
|
-
// Max height
|
|
306
|
-
if (valueNew.top + valueNew.height > rootRect.height) {
|
|
307
|
-
valueNew.height = rootRect.height - valueNew.top;
|
|
308
|
-
valueNew.width = valueNew.height * refs.aspectRatio.current;
|
|
309
|
-
}
|
|
310
|
-
// Max width, height per maxWidth and maxHeight
|
|
311
|
-
if (valueNew.width < minWidth_ || valueNew.width > maxWidth_) {
|
|
312
|
-
valueNew.width = (0, utils_1.clamp)(valueNew.width, minWidth_, maxWidth_);
|
|
313
|
-
valueNew.height = valueNew.width / refs.aspectRatio.current;
|
|
314
|
-
}
|
|
315
|
-
if (valueNew.height < minHeight_ || valueNew.height > maxHeight_) {
|
|
316
|
-
valueNew.height = (0, utils_1.clamp)(valueNew.height, minHeight_, maxHeight_);
|
|
317
|
-
valueNew.width = valueNew.height / refs.aspectRatio.current;
|
|
318
|
-
}
|
|
541
|
+
|
|
542
|
+
// Max width
|
|
543
|
+
if (left + width > rootRect.width) {
|
|
544
|
+
width = rootRect.width - left;
|
|
545
|
+
height = width / refs.aspectRatio.current;
|
|
319
546
|
}
|
|
320
|
-
|
|
321
|
-
//
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if ((valueNew.top < ((_c = refs.selector.current) === null || _c === void 0 ? void 0 : _c.top) || valueNew.left < ((_d = refs.selector.current) === null || _d === void 0 ? void 0 : _d.left)) && (((_e = refs.selector.current) === null || _e === void 0 ? void 0 : _e.width) === maxWidth_ || ((_f = refs.selector.current) === null || _f === void 0 ? void 0 : _f.height) === maxHeight_))
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
547
|
+
|
|
548
|
+
// Max height
|
|
549
|
+
if (top + height > rootRect.height) {
|
|
550
|
+
height = rootRect.height - top;
|
|
551
|
+
width = height * refs.aspectRatio.current;
|
|
328
552
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if ((0
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
553
|
+
|
|
554
|
+
// Min left
|
|
555
|
+
if (left < previousLeft) left = previousLeft - width;
|
|
556
|
+
|
|
557
|
+
// Min top
|
|
558
|
+
if (top < previousTop) top = previousTop - height;
|
|
559
|
+
}
|
|
560
|
+
onSelectorChange(_objectSpread(_objectSpread({}, refs.selector.current), {}, {
|
|
561
|
+
top,
|
|
562
|
+
left,
|
|
563
|
+
width,
|
|
564
|
+
height
|
|
565
|
+
}));
|
|
566
|
+
} else if (((_refs$mouseDown$curre5 = refs.mouseDown.current) === null || _refs$mouseDown$curre5 === void 0 ? void 0 : _refs$mouseDown$curre5.version) === 'top_right') {
|
|
567
|
+
const incY = y - refs.previousMouseEvent.current.clientY;
|
|
568
|
+
const incX = x - refs.previousMouseEvent.current.clientX;
|
|
569
|
+
const top = (0, _utils.clamp)(selectorRect.top + incY, 0);
|
|
570
|
+
if (selectorRect.bottom - top < 0 && selectorRect.width + incX < 0) refs.mouseDown.current.version = 'bottom_left';else if (selectorRect.bottom - top < 0) refs.mouseDown.current.version = 'bottom_right';else if (selectorRect.width + incX < 0) refs.mouseDown.current.version = 'top_left';
|
|
571
|
+
let width = (0, _utils.clamp)(Math.abs(selectorRect.width + incX), 0, rootRect.width - selectorRect.left);
|
|
572
|
+
let height = (0, _utils.clamp)(selectorRect.bottom - top, 0);
|
|
573
|
+
|
|
574
|
+
// Top
|
|
575
|
+
if (refs.aspectRatio.current !== undefined) {
|
|
576
|
+
// Top
|
|
577
|
+
if (top < refs.selector.current.top && refs.selector.current.top < previousTop && refs.selector.current.left + refs.selector.current.width >= rootRect.width) return;
|
|
578
|
+
width = height * refs.aspectRatio.current;
|
|
579
|
+
height = width / refs.aspectRatio.current;
|
|
580
|
+
|
|
581
|
+
// Max width
|
|
582
|
+
if (refs.selector.current.left + width > rootRect.width) {
|
|
583
|
+
width = rootRect.width - refs.selector.current.left;
|
|
584
|
+
height = width / refs.aspectRatio.current;
|
|
355
585
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
// Move
|
|
362
|
-
const onMove = (x, y) => {
|
|
363
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
364
|
-
if (refs.mouseDown.current && refs.previousMouseEvent.current) {
|
|
365
|
-
const { top: previousTop, left: previousLeft } = refs.mouseDown.current;
|
|
366
|
-
const rootRect = refs.root.current.getBoundingClientRect();
|
|
367
|
-
const selectorRect_ = refs.imageSelectorMain.current.getBoundingClientRect();
|
|
368
|
-
const selectorRect = {};
|
|
369
|
-
// Normalize relative to root
|
|
370
|
-
selectorRect.width = selectorRect_.width;
|
|
371
|
-
selectorRect.height = selectorRect_.height;
|
|
372
|
-
selectorRect.top = selectorRect_.top - rootRect.top;
|
|
373
|
-
selectorRect.left = selectorRect_.left - rootRect.left;
|
|
374
|
-
selectorRect.right = selectorRect.left + selectorRect_.width;
|
|
375
|
-
selectorRect.bottom = selectorRect.top + selectorRect_.height;
|
|
376
|
-
if (((_a = refs.mouseDown.current) === null || _a === void 0 ? void 0 : _a.version) === 'make') {
|
|
377
|
-
const top_ = (0, utils_1.clamp)(y - rootRect.top, 0, rootRect.height);
|
|
378
|
-
const left_ = (0, utils_1.clamp)(x - rootRect.left, 0, rootRect.width);
|
|
379
|
-
let top = (0, utils_1.clamp)(top_, 0, previousTop);
|
|
380
|
-
let left = (0, utils_1.clamp)(left_, 0, previousLeft);
|
|
381
|
-
let width = Math.abs(left_ - previousLeft);
|
|
382
|
-
let height = Math.abs(top_ - previousTop);
|
|
383
|
-
if (refs.aspectRatio.current !== undefined) {
|
|
384
|
-
if (left < previousLeft) {
|
|
385
|
-
if (((_b = refs.selector.current) === null || _b === void 0 ? void 0 : _b.left) < previousLeft && left < ((_c = refs.selector.current) === null || _c === void 0 ? void 0 : _c.left) && (top <= 0 || ((_d = refs.selector.current) === null || _d === void 0 ? void 0 : _d.top) + ((_e = refs.selector.current) === null || _e === void 0 ? void 0 : _e.height) >= rootRect.height))
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
if (top < previousTop) {
|
|
389
|
-
if (((_f = refs.selector.current) === null || _f === void 0 ? void 0 : _f.top) < previousTop && top < ((_g = refs.selector.current) === null || _g === void 0 ? void 0 : _g.top) && (left <= 0 || ((_h = refs.selector.current) === null || _h === void 0 ? void 0 : _h.left) + ((_j = refs.selector.current) === null || _j === void 0 ? void 0 : _j.width) >= rootRect.width))
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
// Max surface
|
|
393
|
-
if (width + (width / refs.aspectRatio.current) >= height + (height * refs.aspectRatio.current)) {
|
|
394
|
-
height = width / refs.aspectRatio.current;
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
width = height * refs.aspectRatio.current;
|
|
398
|
-
}
|
|
399
|
-
// Moved left
|
|
400
|
-
if (left < previousLeft) {
|
|
401
|
-
left = (0, utils_1.clamp)(previousLeft - width, 0, previousLeft);
|
|
402
|
-
// Update width, height upto the previousLeft
|
|
403
|
-
width = (0, utils_1.clamp)(width, 0, previousLeft);
|
|
404
|
-
height = width / refs.aspectRatio.current;
|
|
405
|
-
}
|
|
406
|
-
// Moved top
|
|
407
|
-
if (top < previousTop) {
|
|
408
|
-
top = (0, utils_1.clamp)(previousTop - height, 0, previousTop);
|
|
409
|
-
// Update width, height upto the previousTop
|
|
410
|
-
height = (0, utils_1.clamp)(height, 0, previousTop);
|
|
411
|
-
width = height * refs.aspectRatio.current;
|
|
412
|
-
}
|
|
413
|
-
// Max width
|
|
414
|
-
if (left + width > rootRect.width) {
|
|
415
|
-
width = rootRect.width - left;
|
|
416
|
-
height = width / refs.aspectRatio.current;
|
|
417
|
-
}
|
|
418
|
-
// Max height
|
|
419
|
-
if (top + height > rootRect.height) {
|
|
420
|
-
height = rootRect.height - top;
|
|
421
|
-
width = height * refs.aspectRatio.current;
|
|
422
|
-
}
|
|
423
|
-
// Min left
|
|
424
|
-
if (left < previousLeft)
|
|
425
|
-
left = previousLeft - width;
|
|
426
|
-
// Min top
|
|
427
|
-
if (top < previousTop)
|
|
428
|
-
top = previousTop - height;
|
|
429
|
-
}
|
|
430
|
-
onSelectorChange(Object.assign(Object.assign({}, refs.selector.current), { top,
|
|
431
|
-
left,
|
|
432
|
-
width,
|
|
433
|
-
height }));
|
|
434
|
-
}
|
|
435
|
-
else if (((_k = refs.mouseDown.current) === null || _k === void 0 ? void 0 : _k.version) === 'move') {
|
|
436
|
-
const top = y - refs.previousMouseEvent.current.clientY;
|
|
437
|
-
const left = x - refs.previousMouseEvent.current.clientX;
|
|
438
|
-
onSelectorChange(Object.assign(Object.assign({}, refs.selector.current), { top: (0, utils_1.clamp)(refs.selector.current.top + top, 0, rootRect.height - selectorRect.height), left: (0, utils_1.clamp)(refs.selector.current.left + left, 0, rootRect.width - selectorRect.width) }));
|
|
439
|
-
}
|
|
440
|
-
else if (((_l = refs.mouseDown.current) === null || _l === void 0 ? void 0 : _l.version) === 'top_left') {
|
|
441
|
-
const incY = y - refs.previousMouseEvent.current.clientY;
|
|
442
|
-
const incX = x - refs.previousMouseEvent.current.clientX;
|
|
443
|
-
let top = (0, utils_1.clamp)(selectorRect.top + incY, 0);
|
|
444
|
-
let left = (0, utils_1.clamp)(selectorRect.left + incX, 0);
|
|
445
|
-
if ((selectorRect.bottom - top < 0) &&
|
|
446
|
-
(selectorRect.right - left < 0))
|
|
447
|
-
refs.mouseDown.current.version = 'bottom_right';
|
|
448
|
-
else if (selectorRect.bottom - top < 0)
|
|
449
|
-
refs.mouseDown.current.version = 'bottom_left';
|
|
450
|
-
else if (selectorRect.right - left < 0)
|
|
451
|
-
refs.mouseDown.current.version = 'top_right';
|
|
452
|
-
let width = (0, utils_1.clamp)(selectorRect.right - left, 0);
|
|
453
|
-
let height = (0, utils_1.clamp)(selectorRect.bottom - top, 0);
|
|
454
|
-
if (refs.aspectRatio.current !== undefined) {
|
|
455
|
-
// Left
|
|
456
|
-
if (left < refs.selector.current.left && refs.selector.current.left < previousLeft && ((_m = refs.selector.current) === null || _m === void 0 ? void 0 : _m.top) === 0)
|
|
457
|
-
return;
|
|
458
|
-
// Max surface
|
|
459
|
-
if (width + (width / refs.aspectRatio.current) >= height + (height * refs.aspectRatio.current)) {
|
|
460
|
-
height = width / refs.aspectRatio.current;
|
|
461
|
-
}
|
|
462
|
-
else {
|
|
463
|
-
width = height * refs.aspectRatio.current;
|
|
464
|
-
}
|
|
465
|
-
// Moved left
|
|
466
|
-
if (left < previousLeft) {
|
|
467
|
-
left = (0, utils_1.clamp)(previousLeft - width, 0, previousLeft);
|
|
468
|
-
// Update width, height upto the previousLeft
|
|
469
|
-
width = (0, utils_1.clamp)(width, 0, previousLeft);
|
|
470
|
-
height = width / refs.aspectRatio.current;
|
|
471
|
-
}
|
|
472
|
-
// Moved top
|
|
473
|
-
if (top < previousTop) {
|
|
474
|
-
top = (0, utils_1.clamp)(previousTop - height, 0, previousTop);
|
|
475
|
-
// Update width, height upto the previousTop
|
|
476
|
-
height = (0, utils_1.clamp)(height, 0, previousTop);
|
|
477
|
-
width = height * refs.aspectRatio.current;
|
|
478
|
-
}
|
|
479
|
-
// Max width
|
|
480
|
-
if (left + width > rootRect.width) {
|
|
481
|
-
width = rootRect.width - left;
|
|
482
|
-
height = width / refs.aspectRatio.current;
|
|
483
|
-
}
|
|
484
|
-
// Max height
|
|
485
|
-
if (top + height > rootRect.height) {
|
|
486
|
-
height = rootRect.height - top;
|
|
487
|
-
width = height * refs.aspectRatio.current;
|
|
488
|
-
}
|
|
489
|
-
// Min left
|
|
490
|
-
if (left < previousLeft)
|
|
491
|
-
left = previousLeft - width;
|
|
492
|
-
// Min top
|
|
493
|
-
if (top < previousTop)
|
|
494
|
-
top = previousTop - height;
|
|
495
|
-
}
|
|
496
|
-
onSelectorChange(Object.assign(Object.assign({}, refs.selector.current), { top,
|
|
497
|
-
left,
|
|
498
|
-
width,
|
|
499
|
-
height }));
|
|
500
|
-
}
|
|
501
|
-
else if (((_o = refs.mouseDown.current) === null || _o === void 0 ? void 0 : _o.version) === 'top_right') {
|
|
502
|
-
const incY = y - refs.previousMouseEvent.current.clientY;
|
|
503
|
-
const incX = x - refs.previousMouseEvent.current.clientX;
|
|
504
|
-
const top = (0, utils_1.clamp)(selectorRect.top + incY, 0);
|
|
505
|
-
if ((selectorRect.bottom - top < 0) &&
|
|
506
|
-
(selectorRect.width + incX < 0))
|
|
507
|
-
refs.mouseDown.current.version = 'bottom_left';
|
|
508
|
-
else if (selectorRect.bottom - top < 0)
|
|
509
|
-
refs.mouseDown.current.version = 'bottom_right';
|
|
510
|
-
else if (selectorRect.width + incX < 0)
|
|
511
|
-
refs.mouseDown.current.version = 'top_left';
|
|
512
|
-
let width = (0, utils_1.clamp)(Math.abs(selectorRect.width + incX), 0, rootRect.width - selectorRect.left);
|
|
513
|
-
let height = (0, utils_1.clamp)(selectorRect.bottom - top, 0);
|
|
514
|
-
// Top
|
|
515
|
-
if (refs.aspectRatio.current !== undefined) {
|
|
516
|
-
// Top
|
|
517
|
-
if (top < refs.selector.current.top && refs.selector.current.top < previousTop && refs.selector.current.left + refs.selector.current.width >= rootRect.width)
|
|
518
|
-
return;
|
|
519
|
-
width = height * refs.aspectRatio.current;
|
|
520
|
-
height = width / refs.aspectRatio.current;
|
|
521
|
-
// Max width
|
|
522
|
-
if (refs.selector.current.left + width > rootRect.width) {
|
|
523
|
-
width = rootRect.width - refs.selector.current.left;
|
|
524
|
-
height = width / refs.aspectRatio.current;
|
|
525
|
-
}
|
|
526
|
-
// Max height
|
|
527
|
-
if (refs.selector.current.top + height > rootRect.height) {
|
|
528
|
-
height = rootRect.height - refs.selector.current.top;
|
|
529
|
-
width = height * refs.aspectRatio.current;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
onSelectorChange(Object.assign(Object.assign({}, refs.selector.current), { top,
|
|
533
|
-
width,
|
|
534
|
-
height }));
|
|
535
|
-
}
|
|
536
|
-
else if (((_p = refs.mouseDown.current) === null || _p === void 0 ? void 0 : _p.version) === 'bottom_right') {
|
|
537
|
-
const incY = y - refs.previousMouseEvent.current.clientY;
|
|
538
|
-
const incX = x - refs.previousMouseEvent.current.clientX;
|
|
539
|
-
if ((selectorRect.height + incY < 0) && (selectorRect.width + incX < 0))
|
|
540
|
-
refs.mouseDown.current.version = 'top_left';
|
|
541
|
-
else if (selectorRect.height + incY < 0)
|
|
542
|
-
refs.mouseDown.current.version = 'top_right';
|
|
543
|
-
else if (selectorRect.width + incX < 0)
|
|
544
|
-
refs.mouseDown.current.version = 'bottom_left';
|
|
545
|
-
let width = (0, utils_1.clamp)(Math.abs(selectorRect.width + incX), 0, rootRect.width - selectorRect.left);
|
|
546
|
-
let height = (0, utils_1.clamp)(Math.abs(selectorRect.height + incY), 0, rootRect.height - selectorRect.top);
|
|
547
|
-
// Right
|
|
548
|
-
if (refs.aspectRatio.current !== undefined) {
|
|
549
|
-
height = width / refs.aspectRatio.current;
|
|
550
|
-
// Max width
|
|
551
|
-
if (refs.selector.current.left + width > rootRect.width) {
|
|
552
|
-
width = rootRect.width - refs.selector.current.left;
|
|
553
|
-
height = width / refs.aspectRatio.current;
|
|
554
|
-
}
|
|
555
|
-
// Max height
|
|
556
|
-
if (refs.selector.current.top + height > rootRect.height) {
|
|
557
|
-
height = rootRect.height - refs.selector.current.top;
|
|
558
|
-
width = height * refs.aspectRatio.current;
|
|
559
|
-
}
|
|
560
|
-
width = height * refs.aspectRatio.current;
|
|
561
|
-
// Max width
|
|
562
|
-
if (refs.selector.current.left + width > rootRect.width) {
|
|
563
|
-
width = rootRect.width - refs.selector.current.left;
|
|
564
|
-
height = width / refs.aspectRatio.current;
|
|
565
|
-
}
|
|
566
|
-
// Max height
|
|
567
|
-
if (refs.selector.current.top + height > rootRect.height) {
|
|
568
|
-
height = rootRect.height - refs.selector.current.top;
|
|
569
|
-
width = height * refs.aspectRatio.current;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
onSelectorChange(Object.assign(Object.assign({}, refs.selector.current), { width,
|
|
573
|
-
height }));
|
|
574
|
-
}
|
|
575
|
-
else if (((_q = refs.mouseDown.current) === null || _q === void 0 ? void 0 : _q.version) === 'bottom_left') {
|
|
576
|
-
const incY = y - refs.previousMouseEvent.current.clientY;
|
|
577
|
-
const incX = x - refs.previousMouseEvent.current.clientX;
|
|
578
|
-
const left = (0, utils_1.clamp)(selectorRect.left + incX, 0);
|
|
579
|
-
if ((selectorRect.height + incY < 0) && (selectorRect.right - left < 0))
|
|
580
|
-
refs.mouseDown.current.version = 'top_right';
|
|
581
|
-
else if (selectorRect.height + incY < 0)
|
|
582
|
-
refs.mouseDown.current.version = 'top_left';
|
|
583
|
-
else if (selectorRect.right - left < 0)
|
|
584
|
-
refs.mouseDown.current.version = 'bottom_right';
|
|
585
|
-
let width = (0, utils_1.clamp)(selectorRect.right - left, 0);
|
|
586
|
-
let height = (0, utils_1.clamp)(Math.abs(selectorRect.height + incY), 0, rootRect.height - selectorRect.top);
|
|
587
|
-
// Left
|
|
588
|
-
if (refs.aspectRatio.current !== undefined) {
|
|
589
|
-
// Left
|
|
590
|
-
if (left < refs.selector.current.left && ((_r = refs.selector.current) === null || _r === void 0 ? void 0 : _r.top) + ((_s = refs.selector.current) === null || _s === void 0 ? void 0 : _s.height) >= rootRect.height)
|
|
591
|
-
return;
|
|
592
|
-
height = width / refs.aspectRatio.current;
|
|
593
|
-
// Max width
|
|
594
|
-
if (refs.selector.current.left + width > rootRect.width) {
|
|
595
|
-
width = rootRect.width - refs.selector.current.left;
|
|
596
|
-
height = width / refs.aspectRatio.current;
|
|
597
|
-
}
|
|
598
|
-
// Max height
|
|
599
|
-
if (refs.selector.current.top + height > rootRect.height) {
|
|
600
|
-
height = rootRect.height - refs.selector.current.top;
|
|
601
|
-
width = height * refs.aspectRatio.current;
|
|
602
|
-
}
|
|
603
|
-
width = height * refs.aspectRatio.current;
|
|
604
|
-
// Max width
|
|
605
|
-
if (refs.selector.current.left + width > rootRect.width) {
|
|
606
|
-
width = rootRect.width - refs.selector.current.left;
|
|
607
|
-
height = width / refs.aspectRatio.current;
|
|
608
|
-
}
|
|
609
|
-
// Max height
|
|
610
|
-
if (refs.selector.current.top + height > rootRect.height) {
|
|
611
|
-
height = rootRect.height - refs.selector.current.top;
|
|
612
|
-
width = height * refs.aspectRatio.current;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
onSelectorChange(Object.assign(Object.assign({}, refs.selector.current), { left,
|
|
616
|
-
width,
|
|
617
|
-
height }));
|
|
618
|
-
}
|
|
619
|
-
else if (((_t = refs.mouseDown.current) === null || _t === void 0 ? void 0 : _t.version) === 'top') {
|
|
620
|
-
const inc = y - refs.previousMouseEvent.current.clientY;
|
|
621
|
-
const top = (0, utils_1.clamp)(refs.selector.current.top + inc, 0);
|
|
622
|
-
if (refs.selector.current.top <= 0 && top <= 0)
|
|
623
|
-
return;
|
|
624
|
-
if (selectorRect.bottom - top < 0)
|
|
625
|
-
refs.mouseDown.current.version = 'bottom';
|
|
626
|
-
let width = refs.selector.current.width;
|
|
627
|
-
let height = (0, utils_1.clamp)(Math.abs(refs.selector.current.height - inc), 0, previousTop - top);
|
|
628
|
-
if (refs.aspectRatio.current !== undefined) {
|
|
629
|
-
// Top
|
|
630
|
-
if (top < refs.selector.current.top && refs.selector.current.top < previousTop && refs.selector.current.left + refs.selector.current.width >= rootRect.width)
|
|
631
|
-
return;
|
|
632
|
-
width = height * refs.aspectRatio.current;
|
|
633
|
-
// Max width
|
|
634
|
-
if (refs.selector.current.left + width > rootRect.width) {
|
|
635
|
-
width = rootRect.width - refs.selector.current.left;
|
|
636
|
-
height = width / refs.aspectRatio.current;
|
|
637
|
-
}
|
|
638
|
-
// Max height
|
|
639
|
-
if (top + height > rootRect.height) {
|
|
640
|
-
height = rootRect.height - top;
|
|
641
|
-
width = height * refs.aspectRatio.current;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
onSelectorChange(Object.assign(Object.assign({}, refs.selector.current), { top,
|
|
645
|
-
width,
|
|
646
|
-
height }));
|
|
647
|
-
}
|
|
648
|
-
else if (((_u = refs.mouseDown.current) === null || _u === void 0 ? void 0 : _u.version) === 'bottom') {
|
|
649
|
-
const inc = y - refs.previousMouseEvent.current.clientY;
|
|
650
|
-
if (selectorRect.height + inc < 0)
|
|
651
|
-
refs.mouseDown.current.version = 'top';
|
|
652
|
-
let width = refs.selector.current.width;
|
|
653
|
-
let height = (0, utils_1.clamp)(Math.abs(selectorRect.height + inc), 0, rootRect.height - refs.selector.current.top);
|
|
654
|
-
if (refs.aspectRatio.current !== undefined) {
|
|
655
|
-
width = height * refs.aspectRatio.current;
|
|
656
|
-
// Max height
|
|
657
|
-
if (refs.selector.current.top + height > rootRect.height) {
|
|
658
|
-
height = rootRect.height - refs.selector.current.top;
|
|
659
|
-
width = height * refs.aspectRatio.current;
|
|
660
|
-
}
|
|
661
|
-
// Max width
|
|
662
|
-
if (refs.selector.current.left + width > rootRect.width) {
|
|
663
|
-
width = rootRect.width - refs.selector.current.left;
|
|
664
|
-
height = width / refs.aspectRatio.current;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
onSelectorChange(Object.assign(Object.assign({}, refs.selector.current), { width,
|
|
668
|
-
height }));
|
|
669
|
-
}
|
|
670
|
-
else if (((_v = refs.mouseDown.current) === null || _v === void 0 ? void 0 : _v.version) === 'left') {
|
|
671
|
-
const inc = x - refs.previousMouseEvent.current.clientX;
|
|
672
|
-
const left = (0, utils_1.clamp)(selectorRect.left + inc, 0);
|
|
673
|
-
if (selectorRect.right - left < 0)
|
|
674
|
-
refs.mouseDown.current.version = 'right';
|
|
675
|
-
let width = (0, utils_1.clamp)(selectorRect.right - left, 0);
|
|
676
|
-
let height = refs.selector.current.height;
|
|
677
|
-
if (refs.aspectRatio.current !== undefined) {
|
|
678
|
-
if (left < refs.selector.current.left && ((_w = refs.selector.current) === null || _w === void 0 ? void 0 : _w.top) + ((_x = refs.selector.current) === null || _x === void 0 ? void 0 : _x.height) >= rootRect.height)
|
|
679
|
-
return;
|
|
680
|
-
height = width / refs.aspectRatio.current;
|
|
681
|
-
// Max width
|
|
682
|
-
if (refs.selector.current.left + width > rootRect.width) {
|
|
683
|
-
width = rootRect.width - refs.selector.current.left;
|
|
684
|
-
height = width / refs.aspectRatio.current;
|
|
685
|
-
}
|
|
686
|
-
// Max height
|
|
687
|
-
if (refs.selector.current.top + height > rootRect.height) {
|
|
688
|
-
height = rootRect.height - refs.selector.current.top;
|
|
689
|
-
width = height * refs.aspectRatio.current;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
onSelectorChange(Object.assign(Object.assign({}, refs.selector.current), { left,
|
|
693
|
-
width,
|
|
694
|
-
height }));
|
|
695
|
-
}
|
|
696
|
-
else if (((_y = refs.mouseDown.current) === null || _y === void 0 ? void 0 : _y.version) === 'right') {
|
|
697
|
-
const inc = x - refs.previousMouseEvent.current.clientX;
|
|
698
|
-
if (selectorRect.width + inc < 0)
|
|
699
|
-
refs.mouseDown.current.version = 'left';
|
|
700
|
-
let width = (0, utils_1.clamp)(Math.abs(selectorRect.width + inc), 0, rootRect.width - selectorRect.left);
|
|
701
|
-
let height = refs.selector.current.height;
|
|
702
|
-
if (refs.aspectRatio.current !== undefined) {
|
|
703
|
-
height = width / refs.aspectRatio.current;
|
|
704
|
-
// Max width
|
|
705
|
-
if (refs.selector.current.left + width > rootRect.width) {
|
|
706
|
-
width = rootRect.width - refs.selector.current.left;
|
|
707
|
-
height = width / refs.aspectRatio.current;
|
|
708
|
-
}
|
|
709
|
-
// Max height
|
|
710
|
-
if (refs.selector.current.top + height > rootRect.height) {
|
|
711
|
-
height = rootRect.height - refs.selector.current.top;
|
|
712
|
-
width = height * refs.aspectRatio.current;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
onSelectorChange(Object.assign(Object.assign({}, refs.selector.current), { width,
|
|
716
|
-
height }));
|
|
717
|
-
}
|
|
586
|
+
|
|
587
|
+
// Max height
|
|
588
|
+
if (refs.selector.current.top + height > rootRect.height) {
|
|
589
|
+
height = rootRect.height - refs.selector.current.top;
|
|
590
|
+
width = height * refs.aspectRatio.current;
|
|
718
591
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
592
|
+
}
|
|
593
|
+
onSelectorChange(_objectSpread(_objectSpread({}, refs.selector.current), {}, {
|
|
594
|
+
top,
|
|
595
|
+
width,
|
|
596
|
+
height
|
|
597
|
+
}));
|
|
598
|
+
} else if (((_refs$mouseDown$curre6 = refs.mouseDown.current) === null || _refs$mouseDown$curre6 === void 0 ? void 0 : _refs$mouseDown$curre6.version) === 'bottom_right') {
|
|
599
|
+
const incY = y - refs.previousMouseEvent.current.clientY;
|
|
600
|
+
const incX = x - refs.previousMouseEvent.current.clientX;
|
|
601
|
+
if (selectorRect.height + incY < 0 && selectorRect.width + incX < 0) refs.mouseDown.current.version = 'top_left';else if (selectorRect.height + incY < 0) refs.mouseDown.current.version = 'top_right';else if (selectorRect.width + incX < 0) refs.mouseDown.current.version = 'bottom_left';
|
|
602
|
+
let width = (0, _utils.clamp)(Math.abs(selectorRect.width + incX), 0, rootRect.width - selectorRect.left);
|
|
603
|
+
let height = (0, _utils.clamp)(Math.abs(selectorRect.height + incY), 0, rootRect.height - selectorRect.top);
|
|
604
|
+
|
|
605
|
+
// Right
|
|
606
|
+
if (refs.aspectRatio.current !== undefined) {
|
|
607
|
+
height = width / refs.aspectRatio.current;
|
|
608
|
+
|
|
609
|
+
// Max width
|
|
610
|
+
if (refs.selector.current.left + width > rootRect.width) {
|
|
611
|
+
width = rootRect.width - refs.selector.current.left;
|
|
612
|
+
height = width / refs.aspectRatio.current;
|
|
726
613
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
onMove(clientX, clientY);
|
|
733
|
-
refs.previousMouseEvent.current = event;
|
|
734
|
-
// Normalize for use as a mouseDown value
|
|
735
|
-
refs.previousMouseEvent.current.clientY = clientY;
|
|
736
|
-
refs.previousMouseEvent.current.clientX = clientX;
|
|
614
|
+
|
|
615
|
+
// Max height
|
|
616
|
+
if (refs.selector.current.top + height > rootRect.height) {
|
|
617
|
+
height = rootRect.height - refs.selector.current.top;
|
|
618
|
+
width = height * refs.aspectRatio.current;
|
|
737
619
|
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
rootDocument.addEventListener('touchend', onMouseUp);
|
|
745
|
-
return () => {
|
|
746
|
-
// Clean up
|
|
747
|
-
rootDocument.removeEventListener('keydown', method);
|
|
748
|
-
rootDocument.removeEventListener('mousemove', onMouseMove);
|
|
749
|
-
rootDocument.removeEventListener('mouseup', onMouseUp);
|
|
750
|
-
rootDocument.removeEventListener('touchmove', onTouchMove);
|
|
751
|
-
rootDocument.removeEventListener('touchend', onMouseUp);
|
|
752
|
-
if (refs.image.current) {
|
|
753
|
-
setImage('');
|
|
754
|
-
if (rootDocument.body.style.overflow === 'hidden')
|
|
755
|
-
rootDocument.body.style.removeProperty('overflow');
|
|
620
|
+
width = height * refs.aspectRatio.current;
|
|
621
|
+
|
|
622
|
+
// Max width
|
|
623
|
+
if (refs.selector.current.left + width > rootRect.width) {
|
|
624
|
+
width = rootRect.width - refs.selector.current.left;
|
|
625
|
+
height = width / refs.aspectRatio.current;
|
|
756
626
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
627
|
+
|
|
628
|
+
// Max height
|
|
629
|
+
if (refs.selector.current.top + height > rootRect.height) {
|
|
630
|
+
height = rootRect.height - refs.selector.current.top;
|
|
631
|
+
width = height * refs.aspectRatio.current;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
onSelectorChange(_objectSpread(_objectSpread({}, refs.selector.current), {}, {
|
|
635
|
+
width,
|
|
636
|
+
height
|
|
637
|
+
}));
|
|
638
|
+
} else if (((_refs$mouseDown$curre7 = refs.mouseDown.current) === null || _refs$mouseDown$curre7 === void 0 ? void 0 : _refs$mouseDown$curre7.version) === 'bottom_left') {
|
|
639
|
+
const incY = y - refs.previousMouseEvent.current.clientY;
|
|
640
|
+
const incX = x - refs.previousMouseEvent.current.clientX;
|
|
641
|
+
const left = (0, _utils.clamp)(selectorRect.left + incX, 0);
|
|
642
|
+
if (selectorRect.height + incY < 0 && selectorRect.right - left < 0) refs.mouseDown.current.version = 'top_right';else if (selectorRect.height + incY < 0) refs.mouseDown.current.version = 'top_left';else if (selectorRect.right - left < 0) refs.mouseDown.current.version = 'bottom_right';
|
|
643
|
+
let width = (0, _utils.clamp)(selectorRect.right - left, 0);
|
|
644
|
+
let height = (0, _utils.clamp)(Math.abs(selectorRect.height + incY), 0, rootRect.height - selectorRect.top);
|
|
645
|
+
|
|
646
|
+
// Left
|
|
647
|
+
if (refs.aspectRatio.current !== undefined) {
|
|
648
|
+
var _refs$selector$curren14, _refs$selector$curren15;
|
|
649
|
+
// Left
|
|
650
|
+
if (left < refs.selector.current.left && ((_refs$selector$curren14 = refs.selector.current) === null || _refs$selector$curren14 === void 0 ? void 0 : _refs$selector$curren14.top) + ((_refs$selector$curren15 = refs.selector.current) === null || _refs$selector$curren15 === void 0 ? void 0 : _refs$selector$curren15.height) >= rootRect.height) return;
|
|
651
|
+
height = width / refs.aspectRatio.current;
|
|
652
|
+
|
|
653
|
+
// Max width
|
|
654
|
+
if (refs.selector.current.left + width > rootRect.width) {
|
|
655
|
+
width = rootRect.width - refs.selector.current.left;
|
|
656
|
+
height = width / refs.aspectRatio.current;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// Max height
|
|
660
|
+
if (refs.selector.current.top + height > rootRect.height) {
|
|
661
|
+
height = rootRect.height - refs.selector.current.top;
|
|
662
|
+
width = height * refs.aspectRatio.current;
|
|
663
|
+
}
|
|
664
|
+
width = height * refs.aspectRatio.current;
|
|
665
|
+
|
|
666
|
+
// Max width
|
|
667
|
+
if (refs.selector.current.left + width > rootRect.width) {
|
|
668
|
+
width = rootRect.width - refs.selector.current.left;
|
|
669
|
+
height = width / refs.aspectRatio.current;
|
|
796
670
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
671
|
+
|
|
672
|
+
// Max height
|
|
673
|
+
if (refs.selector.current.top + height > rootRect.height) {
|
|
674
|
+
height = rootRect.height - refs.selector.current.top;
|
|
675
|
+
width = height * refs.aspectRatio.current;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
onSelectorChange(_objectSpread(_objectSpread({}, refs.selector.current), {}, {
|
|
679
|
+
left,
|
|
680
|
+
width,
|
|
681
|
+
height
|
|
682
|
+
}));
|
|
683
|
+
} else if (((_refs$mouseDown$curre8 = refs.mouseDown.current) === null || _refs$mouseDown$curre8 === void 0 ? void 0 : _refs$mouseDown$curre8.version) === 'top') {
|
|
684
|
+
const inc = y - refs.previousMouseEvent.current.clientY;
|
|
685
|
+
const top = (0, _utils.clamp)(refs.selector.current.top + inc, 0);
|
|
686
|
+
if (refs.selector.current.top <= 0 && top <= 0) return;
|
|
687
|
+
if (selectorRect.bottom - top < 0) refs.mouseDown.current.version = 'bottom';
|
|
688
|
+
let width = refs.selector.current.width;
|
|
689
|
+
let height = (0, _utils.clamp)(Math.abs(refs.selector.current.height - inc), 0, previousTop - top);
|
|
690
|
+
if (refs.aspectRatio.current !== undefined) {
|
|
691
|
+
// Top
|
|
692
|
+
if (top < refs.selector.current.top && refs.selector.current.top < previousTop && refs.selector.current.left + refs.selector.current.width >= rootRect.width) return;
|
|
693
|
+
width = height * refs.aspectRatio.current;
|
|
694
|
+
|
|
695
|
+
// Max width
|
|
696
|
+
if (refs.selector.current.left + width > rootRect.width) {
|
|
697
|
+
width = rootRect.width - refs.selector.current.left;
|
|
698
|
+
height = width / refs.aspectRatio.current;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// Max height
|
|
702
|
+
if (top + height > rootRect.height) {
|
|
703
|
+
height = rootRect.height - top;
|
|
704
|
+
width = height * refs.aspectRatio.current;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
onSelectorChange(_objectSpread(_objectSpread({}, refs.selector.current), {}, {
|
|
708
|
+
top,
|
|
709
|
+
width,
|
|
710
|
+
height
|
|
711
|
+
}));
|
|
712
|
+
} else if (((_refs$mouseDown$curre9 = refs.mouseDown.current) === null || _refs$mouseDown$curre9 === void 0 ? void 0 : _refs$mouseDown$curre9.version) === 'bottom') {
|
|
713
|
+
const inc = y - refs.previousMouseEvent.current.clientY;
|
|
714
|
+
if (selectorRect.height + inc < 0) refs.mouseDown.current.version = 'top';
|
|
715
|
+
let width = refs.selector.current.width;
|
|
716
|
+
let height = (0, _utils.clamp)(Math.abs(selectorRect.height + inc), 0, rootRect.height - refs.selector.current.top);
|
|
717
|
+
if (refs.aspectRatio.current !== undefined) {
|
|
718
|
+
width = height * refs.aspectRatio.current;
|
|
719
|
+
|
|
720
|
+
// Max height
|
|
721
|
+
if (refs.selector.current.top + height > rootRect.height) {
|
|
722
|
+
height = rootRect.height - refs.selector.current.top;
|
|
723
|
+
width = height * refs.aspectRatio.current;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// Max width
|
|
727
|
+
if (refs.selector.current.left + width > rootRect.width) {
|
|
728
|
+
width = rootRect.width - refs.selector.current.left;
|
|
729
|
+
height = width / refs.aspectRatio.current;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
onSelectorChange(_objectSpread(_objectSpread({}, refs.selector.current), {}, {
|
|
733
|
+
width,
|
|
734
|
+
height
|
|
735
|
+
}));
|
|
736
|
+
} else if (((_refs$mouseDown$curre10 = refs.mouseDown.current) === null || _refs$mouseDown$curre10 === void 0 ? void 0 : _refs$mouseDown$curre10.version) === 'left') {
|
|
737
|
+
const inc = x - refs.previousMouseEvent.current.clientX;
|
|
738
|
+
const left = (0, _utils.clamp)(selectorRect.left + inc, 0);
|
|
739
|
+
if (selectorRect.right - left < 0) refs.mouseDown.current.version = 'right';
|
|
740
|
+
let width = (0, _utils.clamp)(selectorRect.right - left, 0);
|
|
741
|
+
let height = refs.selector.current.height;
|
|
742
|
+
if (refs.aspectRatio.current !== undefined) {
|
|
743
|
+
var _refs$selector$curren16, _refs$selector$curren17;
|
|
744
|
+
if (left < refs.selector.current.left && ((_refs$selector$curren16 = refs.selector.current) === null || _refs$selector$curren16 === void 0 ? void 0 : _refs$selector$curren16.top) + ((_refs$selector$curren17 = refs.selector.current) === null || _refs$selector$curren17 === void 0 ? void 0 : _refs$selector$curren17.height) >= rootRect.height) return;
|
|
745
|
+
height = width / refs.aspectRatio.current;
|
|
746
|
+
|
|
747
|
+
// Max width
|
|
748
|
+
if (refs.selector.current.left + width > rootRect.width) {
|
|
749
|
+
width = rootRect.width - refs.selector.current.left;
|
|
750
|
+
height = width / refs.aspectRatio.current;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// Max height
|
|
754
|
+
if (refs.selector.current.top + height > rootRect.height) {
|
|
755
|
+
height = rootRect.height - refs.selector.current.top;
|
|
756
|
+
width = height * refs.aspectRatio.current;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
onSelectorChange(_objectSpread(_objectSpread({}, refs.selector.current), {}, {
|
|
760
|
+
left,
|
|
761
|
+
width,
|
|
762
|
+
height
|
|
763
|
+
}));
|
|
764
|
+
} else if (((_refs$mouseDown$curre11 = refs.mouseDown.current) === null || _refs$mouseDown$curre11 === void 0 ? void 0 : _refs$mouseDown$curre11.version) === 'right') {
|
|
765
|
+
const inc = x - refs.previousMouseEvent.current.clientX;
|
|
766
|
+
if (selectorRect.width + inc < 0) refs.mouseDown.current.version = 'left';
|
|
767
|
+
let width = (0, _utils.clamp)(Math.abs(selectorRect.width + inc), 0, rootRect.width - selectorRect.left);
|
|
768
|
+
let height = refs.selector.current.height;
|
|
769
|
+
if (refs.aspectRatio.current !== undefined) {
|
|
770
|
+
height = width / refs.aspectRatio.current;
|
|
771
|
+
|
|
772
|
+
// Max width
|
|
773
|
+
if (refs.selector.current.left + width > rootRect.width) {
|
|
774
|
+
width = rootRect.width - refs.selector.current.left;
|
|
775
|
+
height = width / refs.aspectRatio.current;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// Max height
|
|
779
|
+
if (refs.selector.current.top + height > rootRect.height) {
|
|
780
|
+
height = rootRect.height - refs.selector.current.top;
|
|
781
|
+
width = height * refs.aspectRatio.current;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
onSelectorChange(_objectSpread(_objectSpread({}, refs.selector.current), {}, {
|
|
785
|
+
width,
|
|
786
|
+
height
|
|
787
|
+
}));
|
|
806
788
|
}
|
|
789
|
+
}
|
|
807
790
|
};
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
refs.canvasMain.current.getContext('2d').drawImage(image, 0, 0), image.width, image.height;
|
|
820
|
-
refs.canvasImageSelector.current.width = image.width;
|
|
821
|
-
refs.canvasImageSelector.current.height = image.height;
|
|
822
|
-
refs.canvasImageSelector.current.getContext('2d').drawImage(image, 0, 0), image.width, image.height;
|
|
823
|
-
// Update selector
|
|
824
|
-
updateSelector();
|
|
825
|
-
}
|
|
826
|
-
}, [image]);
|
|
827
|
-
const makeImage = async (value = image) => {
|
|
828
|
-
var _a;
|
|
829
|
-
const img = await (0, utils_2.image)(value);
|
|
830
|
-
const rootDocument = (0, utils_1.isEnvironment)('browser') ? (((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) || window.document) : undefined;
|
|
831
|
-
const canvas = rootDocument.createElement('canvas');
|
|
832
|
-
const rootRect = refs.root.current.getBoundingClientRect();
|
|
833
|
-
const aspectRatioImg = img.width / img.height;
|
|
834
|
-
// width being parent width
|
|
835
|
-
img.width = rootRect.width;
|
|
836
|
-
// height keep aspect ratio of the img for the height
|
|
837
|
-
img.height = img.width / aspectRatioImg;
|
|
838
|
-
canvas.width = img.width;
|
|
839
|
-
canvas.height = img.height;
|
|
840
|
-
canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);
|
|
841
|
-
setImage(canvas);
|
|
791
|
+
|
|
792
|
+
// Mouse move
|
|
793
|
+
const onMouseMove = event => {
|
|
794
|
+
if (refs.mouseDown.current) {
|
|
795
|
+
const {
|
|
796
|
+
clientY,
|
|
797
|
+
clientX
|
|
798
|
+
} = event;
|
|
799
|
+
onMove(clientX, clientY);
|
|
800
|
+
refs.previousMouseEvent.current = event;
|
|
801
|
+
}
|
|
842
802
|
};
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
refs.borderTop.current,
|
|
859
|
-
refs.borderLeft.current,
|
|
860
|
-
refs.borderRight.current,
|
|
861
|
-
refs.borderBottom.current,
|
|
862
|
-
refs.dotTopLeft.current,
|
|
863
|
-
refs.dotTopRight.current,
|
|
864
|
-
refs.dotBottomLeft.current,
|
|
865
|
-
refs.dotBottomRight.current
|
|
866
|
-
].includes(event.target)) {
|
|
867
|
-
const { clientY, clientX } = event.touches[0];
|
|
868
|
-
const rootRect = refs.root.current.getBoundingClientRect();
|
|
869
|
-
setMouseDown({
|
|
870
|
-
version: 'make',
|
|
871
|
-
top: clientY - rootRect.top,
|
|
872
|
-
left: clientX - rootRect.left
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
}, []);
|
|
876
|
-
const onMouseDown = react_1.default.useCallback((event) => {
|
|
877
|
-
if (![
|
|
878
|
-
refs.imageSelectorMain.current,
|
|
879
|
-
refs.imageSelector.current,
|
|
880
|
-
refs.move.current,
|
|
881
|
-
refs.borderTop.current,
|
|
882
|
-
refs.borderLeft.current,
|
|
883
|
-
refs.borderRight.current,
|
|
884
|
-
refs.borderBottom.current,
|
|
885
|
-
refs.dotTopLeft.current,
|
|
886
|
-
refs.dotTopRight.current,
|
|
887
|
-
refs.dotBottomLeft.current,
|
|
888
|
-
refs.dotBottomRight.current
|
|
889
|
-
].includes(event.target)) {
|
|
890
|
-
const { clientY, clientX } = event;
|
|
891
|
-
const rootRect = refs.root.current.getBoundingClientRect();
|
|
892
|
-
setMouseDown({
|
|
893
|
-
version: 'make',
|
|
894
|
-
top: clientY - rootRect.top,
|
|
895
|
-
left: clientX - rootRect.left
|
|
896
|
-
});
|
|
897
|
-
}
|
|
898
|
-
}, []);
|
|
899
|
-
const onTouchStartSelector = react_1.default.useCallback((event) => {
|
|
900
|
-
const { clientY, clientX } = event.touches[0];
|
|
901
|
-
const rootRect = refs.root.current.getBoundingClientRect();
|
|
902
|
-
setMouseDown({
|
|
903
|
-
version: 'move',
|
|
904
|
-
top: clientY - rootRect.top,
|
|
905
|
-
left: clientX - rootRect.left
|
|
906
|
-
});
|
|
907
|
-
}, []);
|
|
908
|
-
const onMouseDownSelector = react_1.default.useCallback((event) => {
|
|
909
|
-
const { clientY, clientX } = event;
|
|
910
|
-
const rootRect = refs.root.current.getBoundingClientRect();
|
|
911
|
-
setMouseDown({
|
|
912
|
-
version: 'move',
|
|
913
|
-
top: clientY - rootRect.top,
|
|
914
|
-
left: clientX - rootRect.left
|
|
915
|
-
});
|
|
916
|
-
}, []);
|
|
917
|
-
const onTouchStartBorder = (version) => (event) => {
|
|
918
|
-
var _a, _b, _c, _d;
|
|
919
|
-
setMouseDown({
|
|
920
|
-
version,
|
|
921
|
-
top: ((_a = refs.selector.current) === null || _a === void 0 ? void 0 : _a.top) + ((_b = refs.selector.current) === null || _b === void 0 ? void 0 : _b.height),
|
|
922
|
-
left: ((_c = refs.selector.current) === null || _c === void 0 ? void 0 : _c.left) + ((_d = refs.selector.current) === null || _d === void 0 ? void 0 : _d.width)
|
|
923
|
-
});
|
|
803
|
+
|
|
804
|
+
// Touch move
|
|
805
|
+
const onTouchMove = event => {
|
|
806
|
+
if (refs.mouseDown.current) {
|
|
807
|
+
const {
|
|
808
|
+
clientY,
|
|
809
|
+
clientX
|
|
810
|
+
} = event.touches[0];
|
|
811
|
+
onMove(clientX, clientY);
|
|
812
|
+
refs.previousMouseEvent.current = event;
|
|
813
|
+
|
|
814
|
+
// Normalize for use as a mouseDown value
|
|
815
|
+
refs.previousMouseEvent.current.clientY = clientY;
|
|
816
|
+
refs.previousMouseEvent.current.clientX = clientX;
|
|
817
|
+
}
|
|
924
818
|
};
|
|
925
|
-
const
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
819
|
+
const rootDocument = (0, _utils.isEnvironment)('browser') ? ((_refs$root$current2 = refs.root.current) === null || _refs$root$current2 === void 0 ? void 0 : _refs$root$current2.ownerDocument) || window.document : undefined;
|
|
820
|
+
rootDocument.addEventListener('keydown', method);
|
|
821
|
+
rootDocument.addEventListener('mousemove', onMouseMove);
|
|
822
|
+
rootDocument.addEventListener('mouseup', onMouseUp);
|
|
823
|
+
rootDocument.addEventListener('touchmove', onTouchMove, {
|
|
824
|
+
passive: true
|
|
825
|
+
});
|
|
826
|
+
rootDocument.addEventListener('touchend', onMouseUp);
|
|
827
|
+
return () => {
|
|
828
|
+
// Clean up
|
|
829
|
+
rootDocument.removeEventListener('keydown', method);
|
|
830
|
+
rootDocument.removeEventListener('mousemove', onMouseMove);
|
|
831
|
+
rootDocument.removeEventListener('mouseup', onMouseUp);
|
|
832
|
+
rootDocument.removeEventListener('touchmove', onTouchMove);
|
|
833
|
+
rootDocument.removeEventListener('touchend', onMouseUp);
|
|
834
|
+
if (refs.image.current) {
|
|
835
|
+
setImage('');
|
|
836
|
+
if (rootDocument.body.style.overflow === 'hidden') rootDocument.body.style.removeProperty('overflow');
|
|
837
|
+
}
|
|
932
838
|
};
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
839
|
+
}, []);
|
|
840
|
+
_react.default.useEffect(() => {
|
|
841
|
+
if (image_ !== image) {
|
|
842
|
+
if (image_ instanceof HTMLCanvasElement) setImage(image_);else if ((0, _utils.is)('string', image_)) !refs.dynamicParent.current ? makeImage(image_) : setTimeout(() => makeImage(image_), 140);
|
|
843
|
+
}
|
|
844
|
+
}, [image_]);
|
|
845
|
+
const updateSelector = (selector__ = refs.selector.current, image__ = refs.image.current) => {
|
|
846
|
+
if (selector__ !== undefined && image__ !== undefined) {
|
|
847
|
+
var _refs$canvasMain$curr5, _refs$canvasMain$curr6, _refs$canvasMain$curr7, _refs$canvasMain$curr8;
|
|
848
|
+
const rootRect = refs.root.current.getBoundingClientRect();
|
|
849
|
+
const selectorValue = {
|
|
850
|
+
top: (0, _utils.clamp)(selector__.top, 0, image__.height),
|
|
851
|
+
left: (0, _utils.clamp)(selector__.left, 0, image__.height)
|
|
852
|
+
};
|
|
853
|
+
selectorValue.width = (0, _utils.clamp)(selector__.width || 0, 0, rootRect.width - selectorValue.left);
|
|
854
|
+
selectorValue.height = (0, _utils.clamp)(selector__.height || 0, 0, rootRect.height - selectorValue.top);
|
|
855
|
+
|
|
856
|
+
// Aspect ratio
|
|
857
|
+
if (refs.aspectRatio.current !== undefined) {
|
|
858
|
+
// Max surface
|
|
859
|
+
if (selectorValue.width + selectorValue.width / refs.aspectRatio.current >= selectorValue.height + selectorValue.height * refs.aspectRatio.current) {
|
|
860
|
+
selectorValue.height = selectorValue.width / refs.aspectRatio.current;
|
|
861
|
+
} else {
|
|
862
|
+
selectorValue.width = selectorValue.height * refs.aspectRatio.current;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// Max width
|
|
866
|
+
if (selectorValue.left + selectorValue.width > rootRect.width) {
|
|
867
|
+
selectorValue.width = rootRect.width - selectorValue.left;
|
|
868
|
+
selectorValue.height = selectorValue.width / refs.aspectRatio.current;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
// Max height
|
|
872
|
+
if (selectorValue.top + selectorValue.height > rootRect.height) {
|
|
873
|
+
selectorValue.height = rootRect.height - selectorValue.top;
|
|
874
|
+
selectorValue.width = selectorValue.height * refs.aspectRatio.current;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// Update selector
|
|
879
|
+
setSelector(selectorValue);
|
|
880
|
+
|
|
881
|
+
// Update selector relative
|
|
882
|
+
setSelectorRelative({
|
|
883
|
+
top: selectorValue.top / (rootRect === null || rootRect === void 0 ? void 0 : rootRect.height) * ((_refs$canvasMain$curr5 = refs.canvasMain.current) === null || _refs$canvasMain$curr5 === void 0 ? void 0 : _refs$canvasMain$curr5.height),
|
|
884
|
+
left: selectorValue.left / (rootRect === null || rootRect === void 0 ? void 0 : rootRect.width) * ((_refs$canvasMain$curr6 = refs.canvasMain.current) === null || _refs$canvasMain$curr6 === void 0 ? void 0 : _refs$canvasMain$curr6.width),
|
|
885
|
+
width: selectorValue.width / (rootRect === null || rootRect === void 0 ? void 0 : rootRect.width) * ((_refs$canvasMain$curr7 = refs.canvasMain.current) === null || _refs$canvasMain$curr7 === void 0 ? void 0 : _refs$canvasMain$curr7.width),
|
|
886
|
+
height: selectorValue.height / (rootRect === null || rootRect === void 0 ? void 0 : rootRect.height) * ((_refs$canvasMain$curr8 = refs.canvasMain.current) === null || _refs$canvasMain$curr8 === void 0 ? void 0 : _refs$canvasMain$curr8.height)
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
_react.default.useEffect(() => {
|
|
891
|
+
updateSelector();
|
|
892
|
+
}, [aspectRatio]);
|
|
893
|
+
_react.default.useEffect(() => {
|
|
894
|
+
if (selector_ !== selector) updateSelector(selector_);
|
|
895
|
+
}, [selector_]);
|
|
896
|
+
_react.default.useEffect(() => {
|
|
897
|
+
if (image) {
|
|
898
|
+
refs.canvasMain.current.width = image.width;
|
|
899
|
+
refs.canvasMain.current.height = image.height;
|
|
900
|
+
refs.canvasMain.current.getContext('2d').drawImage(image, 0, 0), image.width, image.height;
|
|
901
|
+
refs.canvasImageSelector.current.width = image.width;
|
|
902
|
+
refs.canvasImageSelector.current.height = image.height;
|
|
903
|
+
refs.canvasImageSelector.current.getContext('2d').drawImage(image, 0, 0), image.width, image.height;
|
|
904
|
+
|
|
905
|
+
// Update selector
|
|
906
|
+
updateSelector();
|
|
907
|
+
}
|
|
908
|
+
}, [image]);
|
|
909
|
+
const makeImage = async (value = image) => {
|
|
910
|
+
var _refs$root$current3;
|
|
911
|
+
const img = await (0, _utils2.image)(value);
|
|
912
|
+
const rootDocument = (0, _utils.isEnvironment)('browser') ? ((_refs$root$current3 = refs.root.current) === null || _refs$root$current3 === void 0 ? void 0 : _refs$root$current3.ownerDocument) || window.document : undefined;
|
|
913
|
+
const canvas = rootDocument.createElement('canvas');
|
|
914
|
+
const rootRect = refs.root.current.getBoundingClientRect();
|
|
915
|
+
const aspectRatioImg = img.width / img.height;
|
|
916
|
+
|
|
917
|
+
// width being parent width
|
|
918
|
+
img.width = rootRect.width;
|
|
919
|
+
|
|
920
|
+
// height keep aspect ratio of the img for the height
|
|
921
|
+
img.height = img.width / aspectRatioImg;
|
|
922
|
+
canvas.width = img.width;
|
|
923
|
+
canvas.height = img.height;
|
|
924
|
+
canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);
|
|
925
|
+
setImage(canvas);
|
|
926
|
+
};
|
|
927
|
+
const onFocus = _react.default.useCallback(event => {
|
|
928
|
+
setFocus(true);
|
|
929
|
+
if ((0, _utils.is)('function', onFocus_)) onFocus_(event);
|
|
930
|
+
}, []);
|
|
931
|
+
const onBlur = _react.default.useCallback(event => {
|
|
932
|
+
setFocus(false);
|
|
933
|
+
if ((0, _utils.is)('function', onBlur_)) onBlur_(event);
|
|
934
|
+
}, []);
|
|
935
|
+
const onTouchStart = _react.default.useCallback(event => {
|
|
936
|
+
if (![refs.imageSelectorMain.current, refs.imageSelector.current, refs.move.current, refs.borderTop.current, refs.borderLeft.current, refs.borderRight.current, refs.borderBottom.current, refs.dotTopLeft.current, refs.dotTopRight.current, refs.dotBottomLeft.current, refs.dotBottomRight.current].includes(event.target)) {
|
|
937
|
+
const {
|
|
938
|
+
clientY,
|
|
939
|
+
clientX
|
|
940
|
+
} = event.touches[0];
|
|
941
|
+
const rootRect = refs.root.current.getBoundingClientRect();
|
|
942
|
+
setMouseDown({
|
|
943
|
+
version: 'make',
|
|
944
|
+
top: clientY - rootRect.top,
|
|
945
|
+
left: clientX - rootRect.left
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
}, []);
|
|
949
|
+
const onMouseDown = _react.default.useCallback(event => {
|
|
950
|
+
if (![refs.imageSelectorMain.current, refs.imageSelector.current, refs.move.current, refs.borderTop.current, refs.borderLeft.current, refs.borderRight.current, refs.borderBottom.current, refs.dotTopLeft.current, refs.dotTopRight.current, refs.dotBottomLeft.current, refs.dotBottomRight.current].includes(event.target)) {
|
|
951
|
+
const {
|
|
952
|
+
clientY,
|
|
953
|
+
clientX
|
|
954
|
+
} = event;
|
|
955
|
+
const rootRect = refs.root.current.getBoundingClientRect();
|
|
956
|
+
setMouseDown({
|
|
957
|
+
version: 'make',
|
|
958
|
+
top: clientY - rootRect.top,
|
|
959
|
+
left: clientX - rootRect.left
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
}, []);
|
|
963
|
+
const onTouchStartSelector = _react.default.useCallback(event => {
|
|
964
|
+
const {
|
|
965
|
+
clientY,
|
|
966
|
+
clientX
|
|
967
|
+
} = event.touches[0];
|
|
968
|
+
const rootRect = refs.root.current.getBoundingClientRect();
|
|
969
|
+
setMouseDown({
|
|
970
|
+
version: 'move',
|
|
971
|
+
top: clientY - rootRect.top,
|
|
972
|
+
left: clientX - rootRect.left
|
|
973
|
+
});
|
|
974
|
+
}, []);
|
|
975
|
+
const onMouseDownSelector = _react.default.useCallback(event => {
|
|
976
|
+
const {
|
|
977
|
+
clientY,
|
|
978
|
+
clientX
|
|
979
|
+
} = event;
|
|
980
|
+
const rootRect = refs.root.current.getBoundingClientRect();
|
|
981
|
+
setMouseDown({
|
|
982
|
+
version: 'move',
|
|
983
|
+
top: clientY - rootRect.top,
|
|
984
|
+
left: clientX - rootRect.left
|
|
985
|
+
});
|
|
986
|
+
}, []);
|
|
987
|
+
const onTouchStartBorder = version => event => {
|
|
988
|
+
var _refs$selector$curren18, _refs$selector$curren19, _refs$selector$curren20, _refs$selector$curren21;
|
|
989
|
+
setMouseDown({
|
|
990
|
+
version,
|
|
991
|
+
top: ((_refs$selector$curren18 = refs.selector.current) === null || _refs$selector$curren18 === void 0 ? void 0 : _refs$selector$curren18.top) + ((_refs$selector$curren19 = refs.selector.current) === null || _refs$selector$curren19 === void 0 ? void 0 : _refs$selector$curren19.height),
|
|
992
|
+
left: ((_refs$selector$curren20 = refs.selector.current) === null || _refs$selector$curren20 === void 0 ? void 0 : _refs$selector$curren20.left) + ((_refs$selector$curren21 = refs.selector.current) === null || _refs$selector$curren21 === void 0 ? void 0 : _refs$selector$curren21.width)
|
|
993
|
+
});
|
|
994
|
+
};
|
|
995
|
+
const onMouseDownBorder = version => event => {
|
|
996
|
+
var _refs$selector$curren22, _refs$selector$curren23, _refs$selector$curren24, _refs$selector$curren25;
|
|
997
|
+
setMouseDown({
|
|
998
|
+
version,
|
|
999
|
+
top: ((_refs$selector$curren22 = refs.selector.current) === null || _refs$selector$curren22 === void 0 ? void 0 : _refs$selector$curren22.top) + ((_refs$selector$curren23 = refs.selector.current) === null || _refs$selector$curren23 === void 0 ? void 0 : _refs$selector$curren23.height),
|
|
1000
|
+
left: ((_refs$selector$curren24 = refs.selector.current) === null || _refs$selector$curren24 === void 0 ? void 0 : _refs$selector$curren24.left) + ((_refs$selector$curren25 = refs.selector.current) === null || _refs$selector$curren25 === void 0 ? void 0 : _refs$selector$curren25.width)
|
|
1001
|
+
});
|
|
1002
|
+
};
|
|
1003
|
+
const rect = (_refs$root$current4 = refs.root.current) === null || _refs$root$current4 === void 0 ? void 0 : _refs$root$current4.getBoundingClientRect();
|
|
1004
|
+
return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({
|
|
1005
|
+
ref: item => {
|
|
1006
|
+
if (ref) {
|
|
1007
|
+
if ((0, _utils.is)('function', ref)) ref(item);else ref.current = item;
|
|
1008
|
+
}
|
|
1009
|
+
refs.root.current = item;
|
|
1010
|
+
},
|
|
1011
|
+
tabIndex: 0,
|
|
1012
|
+
onFocus: onFocus,
|
|
1013
|
+
onBlur: onBlur,
|
|
1014
|
+
onTouchStart: onTouchStart,
|
|
1015
|
+
onMouseDown: onMouseDown,
|
|
1016
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-root'], className, classes.root])
|
|
1017
|
+
}, other), /*#__PURE__*/_react.default.createElement("canvas", {
|
|
1018
|
+
ref: refs.canvasMain,
|
|
1019
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-canvas', 'onesy-ImageCrop-canvas-main'], classes.canvas, classes.canvas_main])
|
|
1020
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
1021
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-background'], classes.background, image && classes.background_in])
|
|
1022
|
+
}), /*#__PURE__*/_react.default.createElement(Tooltip, (0, _extends2.default)({
|
|
1023
|
+
open: mouseDown && (selector === null || selector === void 0 ? void 0 : selector.width) + (selector === null || selector === void 0 ? void 0 : selector.height) > 0,
|
|
1024
|
+
label: `${Math.round((selectorRelative === null || selectorRelative === void 0 ? void 0 : selectorRelative.width) || 0)} x ${Math.round((selectorRelative === null || selectorRelative === void 0 ? void 0 : selectorRelative.height) || 0)}`,
|
|
1025
|
+
position: "bottom"
|
|
1026
|
+
}, TooltipProps), /*#__PURE__*/_react.default.createElement("div", {
|
|
1027
|
+
ref: refs.imageSelectorMain,
|
|
1028
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-image-selector-main'], classes.imageSelector_main, selector && classes.imageSelector_main_in]),
|
|
1029
|
+
style: _objectSpread({}, selector)
|
|
1030
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
1031
|
+
ref: refs.move,
|
|
1032
|
+
onTouchStart: onTouchStartSelector,
|
|
1033
|
+
onMouseDown: onMouseDownSelector,
|
|
1034
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-move'], classes.move])
|
|
1035
|
+
}), gridLines && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
1036
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-grid-line', 'onesy-ImageCrop-grid-line-top-start'], classes.grid_line, classes.grid_line_top_start])
|
|
1037
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
1038
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-grid-line', 'onesy-ImageCrop-grid-line-top-end'], classes.grid_line, classes.grid_line_top_end])
|
|
1039
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
1040
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-grid-line', 'onesy-ImageCrop-grid-line-left-start'], classes.grid_line, classes.grid_line_left_start])
|
|
1041
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
1042
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-grid-line', 'onesy-ImageCrop-grid-line-left-end'], classes.grid_line, classes.grid_line_left_end])
|
|
1043
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
1044
|
+
ref: refs.dotTopLeft,
|
|
1045
|
+
onTouchStart: onTouchStartBorder('top_left'),
|
|
1046
|
+
onMouseDown: onMouseDownBorder('top_left'),
|
|
1047
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-dot', 'onesy-ImageCrop-dot-top-left'], classes.dot, classes.dot_top_left])
|
|
1048
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
1049
|
+
ref: refs.dotTopRight,
|
|
1050
|
+
onTouchStart: onTouchStartBorder('top_right'),
|
|
1051
|
+
onMouseDown: onMouseDownBorder('top_right'),
|
|
1052
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-dot', 'onesy-ImageCrop-dot-top-right'], classes.dot, classes.dot_top_right])
|
|
1053
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
1054
|
+
ref: refs.dotBottomLeft,
|
|
1055
|
+
onTouchStart: onTouchStartBorder('bottom_left'),
|
|
1056
|
+
onMouseDown: onMouseDownBorder('bottom_left'),
|
|
1057
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-dot', 'onesy-ImageCrop-dot-bottom-left'], classes.dot, classes.dot_bottom_left])
|
|
1058
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
1059
|
+
ref: refs.dotBottomRight,
|
|
1060
|
+
onTouchStart: onTouchStartBorder('bottom_right'),
|
|
1061
|
+
onMouseDown: onMouseDownBorder('bottom_right'),
|
|
1062
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-dot', 'onesy-ImageCrop-dot-bottom-right'], classes.dot, classes.dot_bottom_right])
|
|
1063
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
1064
|
+
ref: refs.borderTop,
|
|
1065
|
+
onTouchStart: onTouchStartBorder('top'),
|
|
1066
|
+
onMouseDown: onMouseDownBorder('top'),
|
|
1067
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-border', 'onesy-ImageCrop-border-top'], classes.border, classes.border_top])
|
|
1068
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
1069
|
+
ref: refs.borderLeft,
|
|
1070
|
+
onTouchStart: onTouchStartBorder('left'),
|
|
1071
|
+
onMouseDown: onMouseDownBorder('left'),
|
|
1072
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-border', 'onesy-ImageCrop-border-left'], classes.border, classes.border_left])
|
|
1073
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
1074
|
+
ref: refs.borderRight,
|
|
1075
|
+
onTouchStart: onTouchStartBorder('right'),
|
|
1076
|
+
onMouseDown: onMouseDownBorder('right'),
|
|
1077
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-border', 'onesy-ImageCrop-border-right'], classes.border, classes.border_right])
|
|
1078
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
1079
|
+
ref: refs.borderBottom,
|
|
1080
|
+
onTouchStart: onTouchStartBorder('bottom'),
|
|
1081
|
+
onMouseDown: onMouseDownBorder('bottom'),
|
|
1082
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-border', 'onesy-ImageCrop-border-bottom'], classes.border, classes.border_bottom])
|
|
1083
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
1084
|
+
ref: refs.imageSelector,
|
|
1085
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-image-selector'], classes.imageSelector]),
|
|
1086
|
+
style: _objectSpread({}, selector)
|
|
1087
|
+
}, /*#__PURE__*/_react.default.createElement("canvas", {
|
|
1088
|
+
ref: refs.canvasImageSelector,
|
|
1089
|
+
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('ImageCrop', theme) && ['onesy-ImageCrop-canvas', 'onesy-ImageCrop-canvas-image-selector'], classes.canvas, classes.canvas_imageSelector]),
|
|
1090
|
+
width: (image === null || image === void 0 ? void 0 : image.width) || 0,
|
|
1091
|
+
height: (image === null || image === void 0 ? void 0 : image.height) || 0,
|
|
1092
|
+
style: {
|
|
1093
|
+
top: `${((selector === null || selector === void 0 ? void 0 : selector.top) || 0) * -1}px`,
|
|
1094
|
+
left: `${((selector === null || selector === void 0 ? void 0 : selector.left) || 0) * -1}px`,
|
|
1095
|
+
width: rect === null || rect === void 0 ? void 0 : rect.width,
|
|
1096
|
+
height: rect === null || rect === void 0 ? void 0 : rect.height
|
|
1097
|
+
}
|
|
1098
|
+
})));
|
|
1074
1099
|
});
|
|
1075
1100
|
ImageCrop.displayName = 'onesy-ImageCrop';
|
|
1076
|
-
exports.default = ImageCrop;
|
|
1101
|
+
var _default = exports.default = ImageCrop;
|