naive-ui 2.23.2 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/es/_internal/icons/Switcher.js +2 -3
- package/es/_internal/selection/src/styles/index.cssr.js +1 -1
- package/es/_internal/selection/styles/_common.js +1 -1
- package/es/auto-complete/src/AutoComplete.d.ts +12 -12
- package/es/auto-complete/src/AutoComplete.js +13 -15
- package/es/back-top/src/BackTop.d.ts +3 -3
- package/es/calendar/src/Calendar.d.ts +5 -1
- package/es/calendar/src/Calendar.js +16 -4
- package/es/calendar/src/interface.d.ts +4 -0
- package/es/carousel/index.d.ts +1 -0
- package/es/carousel/index.js +1 -0
- package/es/carousel/src/Carousel.d.ts +235 -19
- package/es/carousel/src/Carousel.js +683 -229
- package/es/carousel/src/CarouselArrow.d.ts +9 -0
- package/es/carousel/src/CarouselArrow.js +43 -0
- package/es/carousel/src/CarouselDots.d.ts +66 -0
- package/es/carousel/src/CarouselDots.js +118 -0
- package/es/carousel/src/CarouselItem.d.ts +11 -0
- package/es/carousel/src/CarouselItem.js +72 -0
- package/es/carousel/src/interface.d.ts +28 -0
- package/es/carousel/src/interface.js +2 -0
- package/es/carousel/src/styles/index.cssr.js +141 -38
- package/es/carousel/src/utils.d.ts +12 -0
- package/es/carousel/src/utils.js +58 -0
- package/es/carousel/styles/light.d.ts +3 -0
- package/es/carousel/styles/light.js +5 -2
- package/es/cascader/src/Cascader.d.ts +6 -2
- package/es/cascader/src/Cascader.js +2 -1
- package/es/cascader/src/CascaderOption.d.ts +1 -0
- package/es/cascader/src/CascaderOption.js +7 -4
- package/es/cascader/src/interface.d.ts +2 -1
- package/es/checkbox/src/styles/index.cssr.js +1 -1
- package/es/code/src/Code.d.ts +5 -0
- package/es/code/src/Code.js +6 -3
- package/es/code/src/styles/index.cssr.js +2 -2
- package/es/color-picker/src/ColorInputUnit.js +2 -2
- package/es/color-picker/src/ColorPicker.d.ts +13 -5
- package/es/color-picker/src/ColorPicker.js +19 -10
- package/es/color-picker/src/ColorPickerTrigger.d.ts +1 -1
- package/es/color-picker/src/ColorPickerTrigger.js +23 -17
- package/es/color-picker/src/interface.d.ts +2 -0
- package/es/color-picker/src/styles/index.cssr.js +1 -0
- package/es/config-provider/src/ConfigProvider.d.ts +27 -0
- package/es/data-table/src/DataTable.d.ts +10 -55
- package/es/data-table/src/DataTable.js +23 -49
- package/es/data-table/src/interface.d.ts +1 -1
- package/es/data-table/src/styles/index.cssr.js +4 -1
- package/es/data-table/src/utils.js +4 -1
- package/es/date-picker/src/DatePicker.d.ts +26 -22
- package/es/date-picker/src/DatePicker.js +99 -49
- package/es/date-picker/src/interface.d.ts +17 -2
- package/es/date-picker/src/panel/use-calendar.js +2 -2
- package/es/drawer/src/Drawer.d.ts +18 -58
- package/es/drawer/src/Drawer.js +32 -49
- package/es/drawer/src/DrawerBodyWrapper.js +21 -13
- package/es/drawer/src/DrawerContent.js +6 -6
- package/es/dropdown/src/Dropdown.d.ts +5 -0
- package/es/form/src/Feedbacks.js +4 -1
- package/es/form/src/Form.d.ts +7 -7
- package/es/form/src/Form.js +17 -8
- package/es/form/src/FormItem.d.ts +12 -7
- package/es/form/src/FormItem.js +24 -12
- package/es/form/src/FormItemCol.d.ts +8 -4
- package/es/form/src/FormItemGridItem.d.ts +8 -4
- package/es/form/src/FormItemRow.d.ts +7 -3
- package/es/form/src/interface.d.ts +6 -2
- package/es/form/src/styles/form-item.cssr.js +2 -0
- package/es/form/src/utils.d.ts +2 -2
- package/es/form/src/utils.js +29 -18
- package/es/image/src/Image.d.ts +279 -10
- package/es/image/src/Image.js +4 -17
- package/es/image/src/ImageGroup.d.ts +272 -2
- package/es/image/src/ImageGroup.js +5 -8
- package/es/image/src/ImagePreview.d.ts +195 -7
- package/es/image/src/ImagePreview.js +50 -31
- package/es/image/src/interface.d.ts +94 -0
- package/es/image/src/interface.js +2 -1
- package/es/image/src/styles/index.cssr.js +8 -4
- package/es/image/styles/dark.js +8 -1
- package/es/image/styles/light.d.ts +32 -3
- package/es/image/styles/light.js +8 -1
- package/es/input-number/src/utils.js +2 -2
- package/es/locales/common/deDE.js +10 -0
- package/es/locales/common/enUS.d.ts +9 -0
- package/es/locales/common/enUS.js +10 -0
- package/es/locales/common/frFR.js +10 -0
- package/es/locales/common/idID.js +10 -0
- package/es/locales/common/jaJP.js +10 -0
- package/es/locales/common/nbNO.js +10 -0
- package/es/locales/common/ruRU.js +10 -0
- package/es/locales/common/ukUA.js +10 -0
- package/es/locales/common/zhCN.js +9 -0
- package/es/locales/common/zhTW.js +10 -0
- package/es/mention/src/utils.js +0 -1
- package/es/message/index.d.ts +2 -1
- package/es/message/src/Message.d.ts +191 -19
- package/es/message/src/Message.js +13 -11
- package/es/message/src/MessageEnvironment.d.ts +3 -3
- package/es/message/src/MessageProvider.d.ts +5 -10
- package/es/message/src/MessageProvider.js +1 -1
- package/es/message/src/message-props.d.ts +5 -2
- package/es/message/src/types.d.ts +15 -0
- package/es/message/src/types.js +1 -0
- package/es/modal/src/Modal.d.ts +5 -0
- package/es/modal/src/Modal.js +2 -1
- package/es/page-header/index.d.ts +1 -1
- package/es/page-header/src/PageHeader.d.ts +1 -1
- package/es/pagination/index.d.ts +1 -1
- package/es/pagination/src/Pagination.d.ts +8 -4
- package/es/pagination/src/Pagination.js +66 -19
- package/es/pagination/src/interface.d.ts +10 -1
- package/es/pagination/src/utils.d.ts +2 -2
- package/es/pagination/src/utils.js +2 -4
- package/es/popconfirm/src/Popconfirm.d.ts +5 -0
- package/es/popover/src/Popover.d.ts +7 -0
- package/es/popover/src/Popover.js +24 -1
- package/es/popover/src/PopoverBody.d.ts +5 -0
- package/es/popover/src/PopoverBody.js +28 -46
- package/es/popover/src/styles/index.cssr.js +9 -8
- package/es/popselect/src/Popselect.d.ts +62 -73
- package/es/popselect/src/Popselect.js +2 -2
- package/es/progress/src/Circle.d.ts +7 -0
- package/es/progress/src/Circle.js +8 -1
- package/es/progress/src/Line.d.ts +2 -2
- package/es/progress/src/Line.js +4 -1
- package/es/progress/src/Progress.d.ts +6 -2
- package/es/progress/src/Progress.js +2 -2
- package/es/progress/src/styles/index.cssr.js +16 -16
- package/es/radio/src/styles/radio.cssr.js +4 -1
- package/es/result/src/Result.js +9 -10
- package/es/result/src/styles/index.cssr.js +7 -7
- package/es/select/src/Select.d.ts +8 -27
- package/es/select/src/Select.js +16 -24
- package/es/slider/src/Slider.d.ts +2 -4
- package/es/tabs/index.d.ts +1 -0
- package/es/tabs/src/Tabs.d.ts +2 -2
- package/es/tabs/src/Tabs.js +25 -22
- package/es/tabs/src/interface.d.ts +3 -0
- package/es/time-picker/src/TimePicker.d.ts +22 -2
- package/es/time-picker/src/TimePicker.js +59 -29
- package/es/time-picker/src/interface.d.ts +4 -2
- package/es/tooltip/src/Tooltip.d.ts +5 -0
- package/es/tree/src/Tree.d.ts +5 -1
- package/es/tree/src/Tree.js +4 -2
- package/es/tree/src/TreeNodeSwitcher.d.ts +1 -1
- package/es/tree/src/TreeNodeSwitcher.js +25 -14
- package/es/tree/src/interface.d.ts +2 -0
- package/es/tree/src/styles/index.cssr.js +4 -2
- package/es/upload/src/Upload.d.ts +15 -6
- package/es/upload/src/Upload.js +18 -9
- package/es/upload/src/UploadFile.d.ts +5 -5
- package/es/upload/src/UploadFileList.js +2 -2
- package/es/upload/src/interface.d.ts +11 -4
- package/es/version.d.ts +1 -1
- package/es/version.js +1 -1
- package/lib/_internal/icons/Switcher.js +2 -3
- package/lib/_internal/selection/src/styles/index.cssr.js +1 -1
- package/lib/_internal/selection/styles/_common.js +1 -1
- package/lib/auto-complete/src/AutoComplete.d.ts +12 -12
- package/lib/auto-complete/src/AutoComplete.js +14 -16
- package/lib/back-top/src/BackTop.d.ts +3 -3
- package/lib/calendar/src/Calendar.d.ts +5 -1
- package/lib/calendar/src/Calendar.js +15 -3
- package/lib/calendar/src/interface.d.ts +4 -0
- package/lib/carousel/index.d.ts +1 -0
- package/lib/carousel/index.js +3 -1
- package/lib/carousel/src/Carousel.d.ts +235 -19
- package/lib/carousel/src/Carousel.js +681 -227
- package/lib/carousel/src/CarouselArrow.d.ts +9 -0
- package/lib/carousel/src/CarouselArrow.js +45 -0
- package/lib/carousel/src/CarouselDots.d.ts +66 -0
- package/lib/carousel/src/CarouselDots.js +120 -0
- package/lib/carousel/src/CarouselItem.d.ts +11 -0
- package/lib/carousel/src/CarouselItem.js +74 -0
- package/lib/carousel/src/interface.d.ts +28 -0
- package/lib/carousel/src/interface.js +6 -0
- package/lib/carousel/src/styles/index.cssr.js +141 -38
- package/lib/carousel/src/utils.d.ts +12 -0
- package/lib/carousel/src/utils.js +69 -0
- package/lib/carousel/styles/light.d.ts +3 -0
- package/lib/carousel/styles/light.js +5 -2
- package/lib/cascader/src/Cascader.d.ts +6 -2
- package/lib/cascader/src/Cascader.js +2 -1
- package/lib/cascader/src/CascaderOption.d.ts +1 -0
- package/lib/cascader/src/CascaderOption.js +7 -4
- package/lib/cascader/src/interface.d.ts +2 -1
- package/lib/checkbox/src/styles/index.cssr.js +1 -1
- package/lib/code/src/Code.d.ts +5 -0
- package/lib/code/src/Code.js +6 -3
- package/lib/code/src/styles/index.cssr.js +1 -1
- package/lib/color-picker/src/ColorInputUnit.js +1 -1
- package/lib/color-picker/src/ColorPicker.d.ts +13 -5
- package/lib/color-picker/src/ColorPicker.js +19 -10
- package/lib/color-picker/src/ColorPickerTrigger.d.ts +1 -1
- package/lib/color-picker/src/ColorPickerTrigger.js +22 -16
- package/lib/color-picker/src/interface.d.ts +2 -0
- package/lib/color-picker/src/styles/index.cssr.js +1 -0
- package/lib/config-provider/src/ConfigProvider.d.ts +27 -0
- package/lib/data-table/src/DataTable.d.ts +10 -55
- package/lib/data-table/src/DataTable.js +21 -47
- package/lib/data-table/src/interface.d.ts +1 -1
- package/lib/data-table/src/styles/index.cssr.js +4 -1
- package/lib/data-table/src/utils.js +3 -0
- package/lib/date-picker/src/DatePicker.d.ts +26 -22
- package/lib/date-picker/src/DatePicker.js +98 -48
- package/lib/date-picker/src/interface.d.ts +17 -2
- package/lib/date-picker/src/panel/use-calendar.js +2 -2
- package/lib/drawer/src/Drawer.d.ts +18 -58
- package/lib/drawer/src/Drawer.js +30 -47
- package/lib/drawer/src/DrawerBodyWrapper.js +21 -13
- package/lib/drawer/src/DrawerContent.js +6 -6
- package/lib/dropdown/src/Dropdown.d.ts +5 -0
- package/lib/form/src/Feedbacks.js +4 -1
- package/lib/form/src/Form.d.ts +7 -7
- package/lib/form/src/Form.js +16 -7
- package/lib/form/src/FormItem.d.ts +12 -7
- package/lib/form/src/FormItem.js +23 -11
- package/lib/form/src/FormItemCol.d.ts +8 -4
- package/lib/form/src/FormItemGridItem.d.ts +8 -4
- package/lib/form/src/FormItemRow.d.ts +7 -3
- package/lib/form/src/interface.d.ts +6 -2
- package/lib/form/src/styles/form-item.cssr.js +2 -0
- package/lib/form/src/utils.d.ts +2 -2
- package/lib/form/src/utils.js +29 -18
- package/lib/image/src/Image.d.ts +279 -10
- package/lib/image/src/Image.js +4 -17
- package/lib/image/src/ImageGroup.d.ts +272 -2
- package/lib/image/src/ImageGroup.js +4 -7
- package/lib/image/src/ImagePreview.d.ts +195 -7
- package/lib/image/src/ImagePreview.js +49 -30
- package/lib/image/src/interface.d.ts +94 -0
- package/lib/image/src/interface.js +3 -0
- package/lib/image/src/styles/index.cssr.js +8 -4
- package/lib/image/styles/dark.js +8 -1
- package/lib/image/styles/light.d.ts +32 -3
- package/lib/image/styles/light.js +8 -1
- package/lib/input-number/src/utils.js +2 -2
- package/lib/locales/common/deDE.js +10 -0
- package/lib/locales/common/enUS.d.ts +9 -0
- package/lib/locales/common/enUS.js +10 -0
- package/lib/locales/common/frFR.js +10 -0
- package/lib/locales/common/idID.js +10 -0
- package/lib/locales/common/jaJP.js +10 -0
- package/lib/locales/common/nbNO.js +10 -0
- package/lib/locales/common/ruRU.js +10 -0
- package/lib/locales/common/ukUA.js +10 -0
- package/lib/locales/common/zhCN.js +9 -0
- package/lib/locales/common/zhTW.js +10 -0
- package/lib/mention/src/utils.js +0 -1
- package/lib/message/index.d.ts +2 -1
- package/lib/message/src/Message.d.ts +191 -19
- package/lib/message/src/Message.js +13 -11
- package/lib/message/src/MessageEnvironment.d.ts +3 -3
- package/lib/message/src/MessageProvider.d.ts +5 -10
- package/lib/message/src/MessageProvider.js +1 -1
- package/lib/message/src/message-props.d.ts +5 -2
- package/lib/message/src/types.d.ts +15 -0
- package/lib/message/src/types.js +2 -0
- package/lib/modal/src/Modal.d.ts +5 -0
- package/lib/modal/src/Modal.js +2 -1
- package/lib/page-header/index.d.ts +1 -1
- package/lib/page-header/src/PageHeader.d.ts +1 -1
- package/lib/pagination/index.d.ts +1 -1
- package/lib/pagination/src/Pagination.d.ts +8 -4
- package/lib/pagination/src/Pagination.js +65 -18
- package/lib/pagination/src/interface.d.ts +10 -1
- package/lib/pagination/src/utils.d.ts +2 -2
- package/lib/pagination/src/utils.js +2 -4
- package/lib/popconfirm/src/Popconfirm.d.ts +5 -0
- package/lib/popover/src/Popover.d.ts +7 -0
- package/lib/popover/src/Popover.js +23 -0
- package/lib/popover/src/PopoverBody.d.ts +5 -0
- package/lib/popover/src/PopoverBody.js +27 -45
- package/lib/popover/src/styles/index.cssr.js +9 -8
- package/lib/popselect/src/Popselect.d.ts +62 -73
- package/lib/popselect/src/Popselect.js +2 -2
- package/lib/progress/src/Circle.d.ts +7 -0
- package/lib/progress/src/Circle.js +8 -1
- package/lib/progress/src/Line.d.ts +2 -2
- package/lib/progress/src/Line.js +4 -1
- package/lib/progress/src/Progress.d.ts +6 -2
- package/lib/progress/src/Progress.js +2 -2
- package/lib/progress/src/styles/index.cssr.js +16 -16
- package/lib/radio/src/styles/radio.cssr.js +4 -1
- package/lib/result/src/Result.js +8 -9
- package/lib/result/src/styles/index.cssr.js +6 -6
- package/lib/select/src/Select.d.ts +8 -27
- package/lib/select/src/Select.js +14 -22
- package/lib/slider/src/Slider.d.ts +2 -4
- package/lib/tabs/index.d.ts +1 -0
- package/lib/tabs/src/Tabs.d.ts +2 -2
- package/lib/tabs/src/Tabs.js +25 -22
- package/lib/tabs/src/interface.d.ts +3 -0
- package/lib/time-picker/src/TimePicker.d.ts +22 -2
- package/lib/time-picker/src/TimePicker.js +59 -29
- package/lib/time-picker/src/interface.d.ts +4 -2
- package/lib/tooltip/src/Tooltip.d.ts +5 -0
- package/lib/tree/src/Tree.d.ts +5 -1
- package/lib/tree/src/Tree.js +4 -2
- package/lib/tree/src/TreeNodeSwitcher.d.ts +1 -1
- package/lib/tree/src/TreeNodeSwitcher.js +24 -13
- package/lib/tree/src/interface.d.ts +2 -0
- package/lib/tree/src/styles/index.cssr.js +4 -2
- package/lib/upload/src/Upload.d.ts +15 -6
- package/lib/upload/src/Upload.js +18 -9
- package/lib/upload/src/UploadFile.d.ts +5 -5
- package/lib/upload/src/UploadFileList.js +2 -2
- package/lib/upload/src/interface.d.ts +11 -4
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +21 -13
- package/web-types.json +413 -31
|
@@ -4,303 +4,757 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const vue_1 = require("vue");
|
|
7
|
-
const
|
|
7
|
+
const vueuc_1 = require("vueuc");
|
|
8
8
|
const evtd_1 = require("evtd");
|
|
9
|
-
const icons_1 = require("../../_internal/icons");
|
|
10
9
|
const _mixins_1 = require("../../_mixins");
|
|
11
10
|
const _utils_1 = require("../../_utils");
|
|
12
11
|
const styles_1 = require("../styles");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const CarouselDots_1 = __importDefault(require("./CarouselDots"));
|
|
14
|
+
const CarouselArrow_1 = __importDefault(require("./CarouselArrow"));
|
|
15
|
+
const CarouselItem_1 = __importDefault(require("./CarouselItem"));
|
|
16
|
+
const interface_1 = require("./interface");
|
|
13
17
|
const index_cssr_1 = __importDefault(require("./styles/index.cssr"));
|
|
14
|
-
const
|
|
18
|
+
const transitionProperties = (0, interface_1.tuple)('transitionDuration', 'transitionTimingFunction');
|
|
19
|
+
const carouselProps = Object.assign(Object.assign({}, _mixins_1.useTheme.props), { defaultIndex: {
|
|
20
|
+
type: Number,
|
|
21
|
+
default: 0
|
|
22
|
+
}, currentIndex: Number, showArrow: Boolean, dotType: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: 'dot'
|
|
25
|
+
}, dotPlacement: {
|
|
15
26
|
type: String,
|
|
16
27
|
default: 'bottom'
|
|
17
|
-
},
|
|
28
|
+
}, slidesPerView: {
|
|
29
|
+
type: [Number, String],
|
|
30
|
+
default: 1
|
|
31
|
+
}, spaceBetween: {
|
|
32
|
+
type: Number,
|
|
33
|
+
default: 0
|
|
34
|
+
}, centeredSlides: Boolean, direction: {
|
|
35
|
+
type: String,
|
|
36
|
+
default: 'horizontal'
|
|
37
|
+
}, autoplay: Boolean, interval: {
|
|
18
38
|
type: Number,
|
|
19
39
|
default: 5000
|
|
40
|
+
}, loop: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: true
|
|
43
|
+
}, effect: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: 'slide'
|
|
46
|
+
}, showDots: {
|
|
47
|
+
type: Boolean,
|
|
48
|
+
default: true
|
|
20
49
|
}, trigger: {
|
|
21
50
|
type: String,
|
|
22
51
|
default: 'click'
|
|
23
|
-
}
|
|
52
|
+
}, transitionStyle: {
|
|
53
|
+
type: Object,
|
|
54
|
+
default: () => ({
|
|
55
|
+
transitionDuration: '300ms'
|
|
56
|
+
})
|
|
57
|
+
}, transitionProps: Object, draggable: Boolean, touchable: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: true
|
|
60
|
+
}, mousewheel: Boolean, keyboard: Boolean, 'onUpdate:currentIndex': Function, onUpdateCurrentIndex: Function });
|
|
61
|
+
// only one carousel is allowed to trigger touch globally
|
|
62
|
+
let globalDragging = false;
|
|
24
63
|
exports.default = (0, vue_1.defineComponent)({
|
|
25
64
|
name: 'Carousel',
|
|
26
65
|
props: carouselProps,
|
|
27
66
|
setup(props) {
|
|
28
67
|
const { mergedClsPrefixRef } = (0, _mixins_1.useConfig)(props);
|
|
29
|
-
|
|
30
|
-
const lengthRef = { value: 1 };
|
|
31
|
-
const touchingRef = (0, vue_1.ref)(false);
|
|
32
|
-
const dragOffsetRef = (0, vue_1.ref)(0);
|
|
68
|
+
// Dom
|
|
33
69
|
const selfElRef = (0, vue_1.ref)(null);
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
70
|
+
const slidesElsRef = (0, vue_1.ref)([]);
|
|
71
|
+
const slideVNodesRef = { value: [] };
|
|
72
|
+
// user wants to control the transition animation
|
|
73
|
+
const userWantsControlRef = (0, vue_1.computed)(() => props.effect === 'custom');
|
|
74
|
+
const translateableRef = (0, vue_1.computed)(() => !userWantsControlRef.value && props.effect === 'slide');
|
|
75
|
+
// TODO
|
|
76
|
+
const allowLoopRef = (0, vue_1.computed)(() => props.loop && props.slidesPerView === 1);
|
|
77
|
+
// Because of the nature of the loop slide work,
|
|
78
|
+
// we need to add duplicates to the left and right of the carousel
|
|
79
|
+
// slot [ 0 1 2 ]
|
|
80
|
+
// display 2 0 1 2 0
|
|
81
|
+
// index 0 1 2 3 4
|
|
82
|
+
const duplicatedableRef = (0, vue_1.computed)(
|
|
83
|
+
// only duplicate the copy operation in `slide` mode,
|
|
84
|
+
// because other effects have special process
|
|
85
|
+
() => translateableRef.value && allowLoopRef.value);
|
|
86
|
+
// used to calculate total views
|
|
87
|
+
const displaySlidesPerViewRef = (0, vue_1.computed)(() => userWantsControlRef.value ||
|
|
88
|
+
props.centeredSlides ||
|
|
89
|
+
props.effect !== 'slide'
|
|
90
|
+
? 1
|
|
91
|
+
: props.slidesPerView);
|
|
92
|
+
// used to calculate the size of each slide
|
|
93
|
+
const realSlidesPerViewRef = (0, vue_1.computed)(() => userWantsControlRef.value ? 1 : props.slidesPerView);
|
|
94
|
+
// we automatically calculate total view for special slides per view
|
|
95
|
+
const autoSlideSizeRef = (0, vue_1.computed)(() => displaySlidesPerViewRef.value === 'auto' ||
|
|
96
|
+
(props.slidesPerView === 'auto' && props.centeredSlides));
|
|
97
|
+
const transitionStyleRef = (0, vue_1.computed)(() => props.transitionStyle
|
|
98
|
+
? (0, _utils_1.keep)(props.transitionStyle, transitionProperties)
|
|
99
|
+
: {});
|
|
100
|
+
const speedRef = (0, vue_1.computed)(() => userWantsControlRef.value
|
|
101
|
+
? 0
|
|
102
|
+
: (0, utils_1.resolveSpeed)(transitionStyleRef.value.transitionDuration));
|
|
103
|
+
const verticalRef = (0, vue_1.computed)(() => props.direction === 'vertical');
|
|
104
|
+
const sizeAxisRef = (0, vue_1.computed)(() => (verticalRef.value ? 'height' : 'width'));
|
|
105
|
+
const perViewSizeRef = (0, vue_1.ref)({ width: 0, height: 0 });
|
|
106
|
+
const slideSizesRef = (0, vue_1.computed)(() => {
|
|
107
|
+
const { value: slidesEls } = slidesElsRef;
|
|
108
|
+
const { length } = slidesEls;
|
|
109
|
+
if (!length)
|
|
110
|
+
return [];
|
|
111
|
+
if (autoSlideSizeRef.value) {
|
|
112
|
+
return slidesEls.map((slide) => (0, utils_1.calculateSize)(slide));
|
|
113
|
+
}
|
|
114
|
+
const { value: slidesPerView } = realSlidesPerViewRef;
|
|
115
|
+
const { value: perViewSize } = perViewSizeRef;
|
|
116
|
+
const { value: axis } = sizeAxisRef;
|
|
117
|
+
let slideSize = perViewSize[axis];
|
|
118
|
+
if (slidesPerView !== 'auto') {
|
|
119
|
+
const { spaceBetween } = props;
|
|
120
|
+
const remaining = slideSize - (slidesPerView - 1) * spaceBetween;
|
|
121
|
+
const percentage = 1 / Math.max(1, slidesPerView);
|
|
122
|
+
slideSize = remaining * percentage;
|
|
123
|
+
}
|
|
124
|
+
return slidesEls.map(() => (Object.assign(Object.assign({}, perViewSize), { [axis]: slideSize })));
|
|
125
|
+
});
|
|
126
|
+
// The translate required to reach each slide
|
|
127
|
+
const slideTranlatesRef = (0, vue_1.computed)(() => {
|
|
128
|
+
const { value: slideSizes } = slideSizesRef;
|
|
129
|
+
const { length } = slideSizes;
|
|
130
|
+
if (!length)
|
|
131
|
+
return [];
|
|
132
|
+
const { centeredSlides, spaceBetween } = props;
|
|
133
|
+
const { value: axis } = sizeAxisRef;
|
|
134
|
+
const { [axis]: perViewSize } = perViewSizeRef.value;
|
|
135
|
+
let previousTranslate = 0;
|
|
136
|
+
return slideSizes.map(({ [axis]: slideSize }) => {
|
|
137
|
+
let translate = previousTranslate;
|
|
138
|
+
if (centeredSlides) {
|
|
139
|
+
translate += (slideSize - perViewSize) / 2;
|
|
140
|
+
}
|
|
141
|
+
previousTranslate += slideSize + spaceBetween;
|
|
142
|
+
return translate;
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
let isMounted = false;
|
|
146
|
+
const slideStylesRef = (0, vue_1.computed)(() => {
|
|
147
|
+
const { value: slideSizes } = slideSizesRef;
|
|
148
|
+
const { length } = slideSizes;
|
|
149
|
+
if (!length)
|
|
150
|
+
return [];
|
|
151
|
+
const { value: axis } = sizeAxisRef;
|
|
152
|
+
// when user wants to control the transition animation, we center each slide
|
|
153
|
+
if (userWantsControlRef.value) {
|
|
154
|
+
return slideSizes.map((size) => ({
|
|
155
|
+
[axis]: `${size[axis]}px`
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
const { effect, spaceBetween } = props;
|
|
159
|
+
const { value: vertical } = verticalRef;
|
|
160
|
+
const spaceAxis = vertical ? 'bottom' : 'right';
|
|
161
|
+
const slideStyles = [];
|
|
162
|
+
for (let i = 0; i < length; i++) {
|
|
163
|
+
const size = slideSizes[i][axis];
|
|
164
|
+
const style = {
|
|
165
|
+
[axis]: `${size}px`,
|
|
166
|
+
[`margin-${spaceAxis}`]: `${spaceBetween}px`
|
|
167
|
+
};
|
|
168
|
+
// TODO: fix
|
|
169
|
+
// if (isMounted && (effect === 'fade' || effect === 'card')) {
|
|
170
|
+
if (isMounted && effect === 'fade') {
|
|
171
|
+
Object.assign(style, transitionStyleRef.value);
|
|
172
|
+
}
|
|
173
|
+
slideStyles.push(style);
|
|
174
|
+
}
|
|
175
|
+
return slideStyles;
|
|
176
|
+
});
|
|
177
|
+
// Total
|
|
178
|
+
const totalViewRef = (0, vue_1.computed)(() => {
|
|
179
|
+
const { value: slidesPerView } = displaySlidesPerViewRef;
|
|
180
|
+
const { length: originLength } = slidesElsRef.value;
|
|
181
|
+
if (slidesPerView !== 'auto') {
|
|
182
|
+
return originLength - slidesPerView + 1;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
const { value: slideSizes } = slideSizesRef;
|
|
186
|
+
const { length } = slideSizes;
|
|
187
|
+
if (!length)
|
|
188
|
+
return originLength;
|
|
189
|
+
const { value: translates } = slideTranlatesRef;
|
|
190
|
+
const { value: axis } = sizeAxisRef;
|
|
191
|
+
const perViewSize = perViewSizeRef.value[axis];
|
|
192
|
+
let lastViewSize = slideSizes[slideSizes.length - 1][axis];
|
|
193
|
+
let i = length;
|
|
194
|
+
while (i > 1 && lastViewSize < perViewSize) {
|
|
195
|
+
i--;
|
|
196
|
+
lastViewSize += translates[i] - translates[i - 1];
|
|
197
|
+
}
|
|
198
|
+
if (i !== length)
|
|
199
|
+
i++;
|
|
200
|
+
if (i < 1)
|
|
201
|
+
i = 1;
|
|
202
|
+
return i;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
const displayTotalViewRef = (0, vue_1.computed)(() => {
|
|
206
|
+
const { value: totalView } = totalViewRef;
|
|
207
|
+
return duplicatedableRef.value && totalView > 3
|
|
208
|
+
? totalView - 2
|
|
209
|
+
: totalView;
|
|
210
|
+
});
|
|
211
|
+
// Index
|
|
212
|
+
const initializeIndex = props.defaultIndex + (duplicatedableRef.value ? 1 : 0);
|
|
213
|
+
const displayIndexRef = (0, vue_1.ref)((0, utils_1.getDisplayIndex)(initializeIndex, totalViewRef.value, duplicatedableRef.value));
|
|
214
|
+
const virtualIndexRef = (0, vue_1.ref)(initializeIndex);
|
|
215
|
+
const realIndexRef = (0, vue_1.ref)(initializeIndex);
|
|
216
|
+
// record the translate of each slide, so that it can be restored at touch
|
|
217
|
+
let previousTranslate = 0;
|
|
218
|
+
// Reality methods
|
|
219
|
+
function toRealIndex(index, speed = speedRef.value) {
|
|
220
|
+
var _a, _b;
|
|
221
|
+
const { value: length } = totalViewRef;
|
|
222
|
+
if ((index = (0, utils_1.clampValue)(index, 0, length - 1)) !== realIndexRef.value) {
|
|
223
|
+
const { value: lastDisplayIndex } = displayIndexRef;
|
|
224
|
+
// When it is loop from the first silde to the last one,
|
|
225
|
+
// we control its animation effect
|
|
226
|
+
if (duplicatedableRef.value && displayTotalViewRef.value > 2) {
|
|
227
|
+
if (lastDisplayIndex === 0 && index === displayTotalViewRef.value) {
|
|
228
|
+
index = 0;
|
|
229
|
+
}
|
|
230
|
+
else if (lastDisplayIndex === displayTotalViewRef.value - 1 &&
|
|
231
|
+
index === 1) {
|
|
232
|
+
index = length - 1;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const displayIndex = (displayIndexRef.value = (0, utils_1.getDisplayIndex)(index, totalViewRef.value, duplicatedableRef.value));
|
|
236
|
+
virtualIndexRef.value = index;
|
|
237
|
+
realIndexRef.value = (0, utils_1.getRealIndex)(displayIndex, duplicatedableRef.value);
|
|
238
|
+
if (translateableRef.value) {
|
|
239
|
+
translateTo(index, speed);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
fixTranslate();
|
|
243
|
+
}
|
|
244
|
+
if (displayIndex !== lastDisplayIndex) {
|
|
245
|
+
(_a = props['onUpdate:currentIndex']) === null || _a === void 0 ? void 0 : _a.call(props, displayIndex, lastDisplayIndex);
|
|
246
|
+
(_b = props.onUpdateCurrentIndex) === null || _b === void 0 ? void 0 : _b.call(props, displayIndex, lastDisplayIndex);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function getRealPrevIndex(index = realIndexRef.value) {
|
|
251
|
+
return (0, utils_1.getPrevIndex)(index, totalViewRef.value, props.loop);
|
|
252
|
+
}
|
|
253
|
+
function getRealNextIndex(index = realIndexRef.value) {
|
|
254
|
+
return (0, utils_1.getNextIndex)(index, totalViewRef.value, props.loop);
|
|
255
|
+
}
|
|
256
|
+
function isRealPrev(slideOrIndex) {
|
|
257
|
+
const index = getSlideIndex(slideOrIndex);
|
|
258
|
+
return index !== null && getRealPrevIndex() === index;
|
|
259
|
+
}
|
|
260
|
+
function isRealNext(slideOrIndex) {
|
|
261
|
+
const index = getSlideIndex(slideOrIndex);
|
|
262
|
+
return index !== null && getRealNextIndex() === index;
|
|
263
|
+
}
|
|
264
|
+
function isRealActive(slideOrIndex) {
|
|
265
|
+
return realIndexRef.value === getSlideIndex(slideOrIndex);
|
|
266
|
+
}
|
|
267
|
+
// Display methods
|
|
268
|
+
// They are used to deal with the actual values displayed on the UI
|
|
269
|
+
function isDisplayActive(index) {
|
|
270
|
+
return displayIndexRef.value === index;
|
|
271
|
+
}
|
|
272
|
+
function isPrevDisabled() {
|
|
273
|
+
return getRealPrevIndex() === null;
|
|
274
|
+
}
|
|
275
|
+
function isNextDisabled() {
|
|
276
|
+
return getRealNextIndex() === null;
|
|
277
|
+
}
|
|
278
|
+
// Slide to
|
|
279
|
+
function to(index) {
|
|
280
|
+
const realIndex = (0, utils_1.getRealIndex)(index, duplicatedableRef.value);
|
|
281
|
+
if (index !== displayIndexRef.value || realIndex !== realIndexRef.value) {
|
|
282
|
+
toRealIndex(realIndex);
|
|
283
|
+
}
|
|
46
284
|
}
|
|
47
285
|
function prev() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
inTransition = true;
|
|
53
|
-
// no need for reset since transitionend handler will handle it
|
|
54
|
-
currentRef.value--;
|
|
286
|
+
const prevIndex = getRealPrevIndex();
|
|
287
|
+
if (prevIndex !== null) {
|
|
288
|
+
toRealIndex(prevIndex);
|
|
289
|
+
}
|
|
55
290
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
291
|
+
function next() {
|
|
292
|
+
const nextIndex = getRealNextIndex();
|
|
293
|
+
if (nextIndex !== null) {
|
|
294
|
+
toRealIndex(nextIndex);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// Translate to
|
|
298
|
+
const translateStyleRef = (0, vue_1.ref)({});
|
|
299
|
+
let inTransition = false;
|
|
300
|
+
function updateTranslate(translate, speed = 0) {
|
|
301
|
+
const isVersical = props.direction === 'vertical';
|
|
302
|
+
translateStyleRef.value = Object.assign({}, transitionStyleRef.value, {
|
|
303
|
+
transform: isVersical
|
|
304
|
+
? `translateY(${-translate}px)`
|
|
305
|
+
: `translateX(${-translate}px)`,
|
|
306
|
+
transitionDuration: `${speed}ms`
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
function fixTranslate(speed = 0) {
|
|
310
|
+
if (translateableRef.value) {
|
|
311
|
+
translateTo(realIndexRef.value, speed);
|
|
312
|
+
}
|
|
313
|
+
else if (previousTranslate !== 0) {
|
|
314
|
+
updateTranslate((previousTranslate = 0), speed);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function translateTo(index, speed = speedRef.value) {
|
|
318
|
+
const translate = getTranslate(index);
|
|
319
|
+
if (translate !== previousTranslate && speed > 0) {
|
|
320
|
+
inTransition = true;
|
|
67
321
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
322
|
+
updateTranslate(translate, speed);
|
|
323
|
+
previousTranslate = getTranslate(realIndexRef.value);
|
|
324
|
+
}
|
|
325
|
+
function getTranslate(index) {
|
|
326
|
+
let translate;
|
|
327
|
+
// Deal with auto slides pre view
|
|
328
|
+
if (index >= totalViewRef.value - 1) {
|
|
329
|
+
translate = getLastViewTranslate();
|
|
72
330
|
}
|
|
73
331
|
else {
|
|
74
|
-
|
|
332
|
+
translate = slideTranlatesRef.value[index] || 0;
|
|
75
333
|
}
|
|
76
|
-
|
|
77
|
-
|
|
334
|
+
return translate;
|
|
335
|
+
}
|
|
336
|
+
function getLastViewTranslate() {
|
|
337
|
+
if (displaySlidesPerViewRef.value === 'auto') {
|
|
338
|
+
const { value: axis } = sizeAxisRef;
|
|
339
|
+
const { [axis]: perViewSize } = perViewSizeRef.value;
|
|
340
|
+
const { value: translates } = slideTranlatesRef;
|
|
341
|
+
const lastTranslate = translates[translates.length - 1];
|
|
342
|
+
let overallSize;
|
|
343
|
+
if (lastTranslate === undefined) {
|
|
344
|
+
overallSize = perViewSize;
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
const { value: slideSizes } = slideSizesRef;
|
|
348
|
+
overallSize = lastTranslate + slideSizes[slideSizes.length - 1][axis];
|
|
349
|
+
}
|
|
350
|
+
// Bring the last slide to the edge
|
|
351
|
+
return overallSize - perViewSize;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
const { value: translates } = slideTranlatesRef;
|
|
355
|
+
return translates[totalViewRef.value - 1] || 0;
|
|
78
356
|
}
|
|
79
357
|
}
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
function handleTransitionEnd(e) {
|
|
84
|
-
const target = e.target;
|
|
85
|
-
if (target !== e.currentTarget)
|
|
358
|
+
// Provide
|
|
359
|
+
function addSlide(slide) {
|
|
360
|
+
if (!slide)
|
|
86
361
|
return;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
target.style.transition = '';
|
|
96
|
-
inTransition = false;
|
|
97
|
-
});
|
|
362
|
+
slidesElsRef.value.push(slide);
|
|
363
|
+
}
|
|
364
|
+
function removeSlide(slide) {
|
|
365
|
+
if (!slide)
|
|
366
|
+
return;
|
|
367
|
+
const index = getSlideIndex(slide);
|
|
368
|
+
if (index !== -1) {
|
|
369
|
+
slidesElsRef.value.splice(index, 1);
|
|
98
370
|
}
|
|
99
|
-
|
|
100
|
-
|
|
371
|
+
}
|
|
372
|
+
function getSlideIndex(slideOrIndex) {
|
|
373
|
+
return typeof slideOrIndex === 'number'
|
|
374
|
+
? slideOrIndex
|
|
375
|
+
: slidesElsRef.value.indexOf(slideOrIndex);
|
|
376
|
+
}
|
|
377
|
+
function getSlideStyle(slide) {
|
|
378
|
+
const index = getSlideIndex(slide);
|
|
379
|
+
if (index !== -1) {
|
|
380
|
+
return slideStylesRef.value[index];
|
|
101
381
|
}
|
|
102
382
|
}
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
383
|
+
function onCarouselItemClick(index) {
|
|
384
|
+
// TODO fix
|
|
385
|
+
// if (
|
|
386
|
+
// !dragTriggered &&
|
|
387
|
+
// !userWantsControlRef.value &&
|
|
388
|
+
// props.effect === 'card' &&
|
|
389
|
+
// !isRealActive(index)
|
|
390
|
+
// ) {
|
|
391
|
+
// to(index)
|
|
392
|
+
// }
|
|
393
|
+
}
|
|
394
|
+
const carouselMethods = {
|
|
395
|
+
to,
|
|
396
|
+
prev: () => {
|
|
397
|
+
// wait transition end
|
|
398
|
+
if (!inTransition || !duplicatedableRef.value)
|
|
399
|
+
prev();
|
|
400
|
+
},
|
|
401
|
+
next: () => {
|
|
402
|
+
// wait transition end
|
|
403
|
+
if (!inTransition || !duplicatedableRef.value)
|
|
404
|
+
next();
|
|
405
|
+
},
|
|
406
|
+
isVertical: () => verticalRef.value,
|
|
407
|
+
isHorizontal: () => !verticalRef.value,
|
|
408
|
+
isPrev: isRealPrev,
|
|
409
|
+
isNext: isRealNext,
|
|
410
|
+
isActive: isRealActive,
|
|
411
|
+
isPrevDisabled,
|
|
412
|
+
isNextDisabled,
|
|
413
|
+
getCurrentIndex: () => displayIndexRef.value,
|
|
414
|
+
getSlideIndex,
|
|
415
|
+
getSlideStyle,
|
|
416
|
+
addSlide,
|
|
417
|
+
removeSlide,
|
|
418
|
+
onCarouselItemClick
|
|
419
|
+
};
|
|
420
|
+
(0, vue_1.provide)(interface_1.carouselMethodsInjectionKey, carouselMethods);
|
|
421
|
+
// Autoplay
|
|
422
|
+
let autoplayTimer = null;
|
|
423
|
+
function resetAutoplay(cleanOnly) {
|
|
424
|
+
if (autoplayTimer) {
|
|
425
|
+
clearInterval(autoplayTimer);
|
|
426
|
+
autoplayTimer = null;
|
|
427
|
+
}
|
|
428
|
+
const { autoplay, interval } = props;
|
|
429
|
+
if (autoplay && interval && !cleanOnly) {
|
|
430
|
+
autoplayTimer = setInterval(next, interval);
|
|
109
431
|
}
|
|
110
432
|
}
|
|
433
|
+
function mesureAutoplay() {
|
|
434
|
+
const { autoplay } = props;
|
|
435
|
+
if (autoplay) {
|
|
436
|
+
resetAutoplay();
|
|
437
|
+
}
|
|
438
|
+
else if (displayTotalViewRef.value < 2) {
|
|
439
|
+
resetAutoplay(true);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
// Drag
|
|
111
443
|
let dragStartX = 0;
|
|
112
444
|
let dragStartY = 0;
|
|
445
|
+
let dragOffset = 0;
|
|
113
446
|
let dragStartTime = 0;
|
|
114
|
-
let
|
|
115
|
-
let
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
447
|
+
let dragging = false;
|
|
448
|
+
let allowClick = true;
|
|
449
|
+
// whether the last touch triggered the drag successfully
|
|
450
|
+
// const dragTriggered = false
|
|
451
|
+
function handleTouchstart(event) {
|
|
452
|
+
allowClick = true;
|
|
453
|
+
if (globalDragging)
|
|
454
|
+
return;
|
|
455
|
+
// pause autoplay
|
|
456
|
+
resetAutoplay(true);
|
|
457
|
+
dragging = true;
|
|
458
|
+
globalDragging = true;
|
|
459
|
+
dragStartTime = Date.now();
|
|
460
|
+
// dragTriggered = false
|
|
461
|
+
if (event.type !== 'touchstart' &&
|
|
462
|
+
!event.target.isContentEditable) {
|
|
463
|
+
event.preventDefault();
|
|
128
464
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
touchingRef.value = true;
|
|
133
|
-
dragStartTime = Date.now();
|
|
134
|
-
dragStartX = e.touches[0].clientX;
|
|
135
|
-
}
|
|
136
|
-
(0, evtd_1.on)('touchmove', document, handleTouchmove);
|
|
137
|
-
(0, evtd_1.on)('touchend', document, handleTouchend);
|
|
138
|
-
(0, evtd_1.on)('touchcancel', document, handleTouchend);
|
|
139
|
-
}
|
|
140
|
-
function handleTouchmove(e) {
|
|
141
|
-
const { value: dotPlacement } = dotPlacementRef;
|
|
142
|
-
if (dotPlacement === 'left' || dotPlacement === 'right') {
|
|
143
|
-
const dragOffset = e.touches[0].clientY - dragStartY;
|
|
144
|
-
dragOffsetRef.value =
|
|
145
|
-
dragOffset > memorizedContainerHeight
|
|
146
|
-
? memorizedContainerHeight
|
|
147
|
-
: dragOffset < -memorizedContainerHeight
|
|
148
|
-
? -memorizedContainerHeight
|
|
149
|
-
: dragOffset;
|
|
465
|
+
const touchEvent = (0, utils_1.isTouchEvent)(event) ? event.touches[0] : event;
|
|
466
|
+
if (verticalRef.value) {
|
|
467
|
+
dragStartY = touchEvent.clientY;
|
|
150
468
|
}
|
|
151
469
|
else {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
470
|
+
dragStartX = touchEvent.clientX;
|
|
471
|
+
}
|
|
472
|
+
if (props.touchable) {
|
|
473
|
+
(0, evtd_1.on)('touchmove', document, handleTouchmove);
|
|
474
|
+
(0, evtd_1.on)('touchend', document, handleTouchend);
|
|
475
|
+
(0, evtd_1.on)('touchcancel', document, handleTouchend);
|
|
476
|
+
}
|
|
477
|
+
if (props.draggable) {
|
|
478
|
+
(0, evtd_1.on)('mousemove', document, handleTouchmove);
|
|
479
|
+
(0, evtd_1.on)('mouseup', document, handleTouchend);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function handleTouchmove(event) {
|
|
483
|
+
const { value: vertical } = verticalRef;
|
|
484
|
+
const axis = vertical ? 'height' : 'width';
|
|
485
|
+
const perViewSize = perViewSizeRef.value[axis];
|
|
486
|
+
const touchEvent = (0, utils_1.isTouchEvent)(event) ? event.touches[0] : event;
|
|
487
|
+
const offset = vertical
|
|
488
|
+
? touchEvent.clientY - dragStartY
|
|
489
|
+
: touchEvent.clientX - dragStartX;
|
|
490
|
+
dragOffset = (0, utils_1.clampValue)(offset, -perViewSize, perViewSize);
|
|
491
|
+
allowClick = false;
|
|
492
|
+
if (translateableRef.value) {
|
|
493
|
+
updateTranslate(previousTranslate - dragOffset, 0);
|
|
159
494
|
}
|
|
160
495
|
}
|
|
161
496
|
function handleTouchend() {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
else if (dragOffset < -offsetHeight / 2 ||
|
|
179
|
-
dragOffset / duration < -0.4) {
|
|
180
|
-
next();
|
|
497
|
+
const duration = Date.now() - dragStartTime;
|
|
498
|
+
const { value: axis } = sizeAxisRef;
|
|
499
|
+
const { value: realIndex } = realIndexRef;
|
|
500
|
+
const { value: translateable } = translateableRef;
|
|
501
|
+
let currentIndex = realIndex;
|
|
502
|
+
if (!inTransition && translateable && dragOffset !== 0) {
|
|
503
|
+
const currentTranslate = previousTranslate - dragOffset;
|
|
504
|
+
const translates = [
|
|
505
|
+
...slideTranlatesRef.value.slice(0, totalViewRef.value - 1),
|
|
506
|
+
getLastViewTranslate()
|
|
507
|
+
];
|
|
508
|
+
let prevOffset = null;
|
|
509
|
+
for (let i = 0; i < translates.length; i++) {
|
|
510
|
+
const offset = Math.abs(translates[i] - currentTranslate);
|
|
511
|
+
if (prevOffset !== null && prevOffset < offset) {
|
|
512
|
+
break;
|
|
181
513
|
}
|
|
514
|
+
prevOffset = offset;
|
|
515
|
+
currentIndex = i;
|
|
182
516
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
next();
|
|
190
|
-
}
|
|
517
|
+
}
|
|
518
|
+
if (currentIndex === realIndex) {
|
|
519
|
+
const perViewSize = perViewSizeRef.value[axis];
|
|
520
|
+
// more than 50% width or faster than 0.4px per ms
|
|
521
|
+
if (dragOffset > perViewSize / 2 || dragOffset / duration > 0.4) {
|
|
522
|
+
currentIndex = getRealPrevIndex(realIndex);
|
|
191
523
|
}
|
|
524
|
+
else if (dragOffset < -perViewSize / 2 ||
|
|
525
|
+
dragOffset / duration < -0.4) {
|
|
526
|
+
currentIndex = getRealNextIndex(realIndex);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (currentIndex !== null && currentIndex !== realIndex) {
|
|
530
|
+
// dragTriggered = true
|
|
531
|
+
toRealIndex(currentIndex);
|
|
192
532
|
}
|
|
193
|
-
|
|
533
|
+
else {
|
|
534
|
+
fixTranslate(speedRef.value);
|
|
535
|
+
}
|
|
536
|
+
mesureAutoplay();
|
|
537
|
+
resetDragStatus();
|
|
538
|
+
}
|
|
539
|
+
function resetDragStatus() {
|
|
540
|
+
if (dragging) {
|
|
541
|
+
dragging = false;
|
|
542
|
+
globalDragging = false;
|
|
543
|
+
}
|
|
544
|
+
dragStartX = 0;
|
|
545
|
+
dragStartY = 0;
|
|
546
|
+
dragOffset = 0;
|
|
547
|
+
dragStartTime = 0;
|
|
194
548
|
(0, evtd_1.off)('touchmove', document, handleTouchmove);
|
|
195
549
|
(0, evtd_1.off)('touchend', document, handleTouchend);
|
|
196
550
|
(0, evtd_1.off)('touchcancel', document, handleTouchend);
|
|
551
|
+
(0, evtd_1.off)('mousemove', document, handleTouchmove);
|
|
552
|
+
(0, evtd_1.off)('mouseup', document, handleTouchend);
|
|
197
553
|
}
|
|
198
|
-
function
|
|
199
|
-
|
|
200
|
-
|
|
554
|
+
function handleTransitionEnd() {
|
|
555
|
+
const { value: virtualIndex } = virtualIndexRef;
|
|
556
|
+
const { value: realIndex } = realIndexRef;
|
|
557
|
+
if (inTransition && virtualIndex !== realIndex) {
|
|
558
|
+
translateTo(realIndex, 0);
|
|
201
559
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
560
|
+
else {
|
|
561
|
+
resetAutoplay();
|
|
562
|
+
}
|
|
563
|
+
if (translateableRef.value) {
|
|
564
|
+
translateStyleRef.value.transitionDuration = '0ms';
|
|
206
565
|
}
|
|
207
|
-
|
|
208
|
-
next();
|
|
209
|
-
}, props.interval);
|
|
566
|
+
inTransition = false;
|
|
210
567
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
568
|
+
function handleMousewheel(event) {
|
|
569
|
+
event.preventDefault();
|
|
570
|
+
if (inTransition)
|
|
571
|
+
return;
|
|
572
|
+
const { value: vertical } = verticalRef;
|
|
573
|
+
let { deltaX, deltaY } = event;
|
|
574
|
+
if (event.shiftKey && !deltaX) {
|
|
575
|
+
deltaX = deltaY;
|
|
576
|
+
}
|
|
577
|
+
const PREV_R = -1;
|
|
578
|
+
const NEXT_R = 1;
|
|
579
|
+
const r = (deltaX || deltaY) > 0 ? NEXT_R : PREV_R;
|
|
580
|
+
let rx = 0;
|
|
581
|
+
let ry = 0;
|
|
582
|
+
if (vertical) {
|
|
583
|
+
ry = r;
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
rx = r;
|
|
587
|
+
}
|
|
588
|
+
const RESPONSE_STEP = 10;
|
|
589
|
+
if (ry * deltaY >= RESPONSE_STEP || rx * deltaX >= RESPONSE_STEP) {
|
|
590
|
+
if (r === NEXT_R && !isNextDisabled()) {
|
|
591
|
+
next();
|
|
215
592
|
}
|
|
216
|
-
else {
|
|
217
|
-
|
|
218
|
-
window.clearInterval(timerId);
|
|
219
|
-
}
|
|
593
|
+
else if (r === PREV_R && !isPrevDisabled()) {
|
|
594
|
+
prev();
|
|
220
595
|
}
|
|
221
|
-
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
function handleClick(event) {
|
|
599
|
+
if (!allowClick) {
|
|
600
|
+
event.preventDefault();
|
|
601
|
+
event.stopPropagation();
|
|
602
|
+
allowClick = true;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
function handleResize() {
|
|
606
|
+
perViewSizeRef.value = (0, utils_1.calculateSize)(selfElRef.value, true);
|
|
607
|
+
resetAutoplay();
|
|
608
|
+
}
|
|
609
|
+
function handleSlideResize() {
|
|
610
|
+
var _a, _b;
|
|
611
|
+
if (autoSlideSizeRef.value) {
|
|
612
|
+
(_b = (_a = slideSizesRef.effect).scheduler) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
613
|
+
slideSizesRef.effect.run();
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
(0, vue_1.onMounted)(() => {
|
|
617
|
+
(0, vue_1.watchEffect)(mesureAutoplay);
|
|
618
|
+
void (0, vue_1.nextTick)(() => (isMounted = true));
|
|
222
619
|
});
|
|
223
620
|
(0, vue_1.onBeforeUnmount)(() => {
|
|
224
|
-
|
|
225
|
-
|
|
621
|
+
resetDragStatus();
|
|
622
|
+
resetAutoplay(true);
|
|
623
|
+
});
|
|
624
|
+
// Fix index when remounting
|
|
625
|
+
(0, vue_1.onUpdated)(() => {
|
|
626
|
+
const { value: slidesEls } = slidesElsRef;
|
|
627
|
+
const { value: slideVNodes } = slideVNodesRef;
|
|
628
|
+
const indexMap = new Map();
|
|
629
|
+
const getDisplayIndex = (el) =>
|
|
630
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
631
|
+
indexMap.has(el) ? indexMap.get(el) : -1;
|
|
632
|
+
let isChanged = false;
|
|
633
|
+
for (let i = 0; i < slidesEls.length; i++) {
|
|
634
|
+
const index = slideVNodes.findIndex((v) => v.el === slidesEls[i]);
|
|
635
|
+
if (index !== i) {
|
|
636
|
+
isChanged = true;
|
|
637
|
+
}
|
|
638
|
+
indexMap.set(slidesEls[i], index);
|
|
639
|
+
}
|
|
640
|
+
if (isChanged) {
|
|
641
|
+
slidesEls.sort((a, b) => getDisplayIndex(a) - getDisplayIndex(b));
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
(0, vue_1.watch)((0, vue_1.toRef)(props, 'currentIndex'), (index) => index !== undefined && to(index));
|
|
645
|
+
(0, vue_1.watch)(duplicatedableRef, () => void (0, vue_1.nextTick)(() => to(displayIndexRef.value)));
|
|
646
|
+
(0, vue_1.watch)(slideTranlatesRef, () => translateableRef.value && fixTranslate(), {
|
|
647
|
+
deep: true
|
|
648
|
+
});
|
|
649
|
+
(0, vue_1.watch)(translateableRef, (value) => {
|
|
650
|
+
if (!value) {
|
|
651
|
+
inTransition = false;
|
|
652
|
+
// if the current mode does not support translate, reset the position of the wrapper
|
|
653
|
+
updateTranslate((previousTranslate = 0));
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
fixTranslate();
|
|
226
657
|
}
|
|
227
658
|
});
|
|
659
|
+
const caroulseSlotProps = {
|
|
660
|
+
arrowSlotProps: (0, vue_1.computed)(() => (Object.assign({ total: displayTotalViewRef.value, currentIndex: displayIndexRef.value }, (0, _utils_1.keep)(carouselMethods, [
|
|
661
|
+
'to',
|
|
662
|
+
'prev',
|
|
663
|
+
'next',
|
|
664
|
+
'isPrevDisabled',
|
|
665
|
+
'isNextDisabled'
|
|
666
|
+
])))),
|
|
667
|
+
dotSlotProps: (0, vue_1.computed)(() => ({
|
|
668
|
+
total: displayTotalViewRef.value,
|
|
669
|
+
currentIndex: displayIndexRef.value,
|
|
670
|
+
to
|
|
671
|
+
}))
|
|
672
|
+
};
|
|
673
|
+
const caroulseExposedMethod = {
|
|
674
|
+
getCurrentIndex: () => displayIndexRef.value,
|
|
675
|
+
to: to,
|
|
676
|
+
prev: prev,
|
|
677
|
+
next: next
|
|
678
|
+
};
|
|
228
679
|
const themeRef = (0, _mixins_1.useTheme)('Carousel', 'Carousel', index_cssr_1.default, styles_1.carouselLight, props);
|
|
229
|
-
return {
|
|
230
|
-
selfElRef,
|
|
231
|
-
mergedClsPrefix: mergedClsPrefixRef,
|
|
232
|
-
current: currentRef,
|
|
233
|
-
lengthRef,
|
|
234
|
-
touching: touchingRef,
|
|
235
|
-
dragOffset: dragOffsetRef,
|
|
236
|
-
prev,
|
|
237
|
-
next,
|
|
238
|
-
setCurrent,
|
|
239
|
-
handleKeydown,
|
|
240
|
-
handleTouchstart,
|
|
680
|
+
return Object.assign(Object.assign(Object.assign({ mergedClsPrefix: mergedClsPrefixRef, selfElRef, slideVNodes: slideVNodesRef, duplicatedable: duplicatedableRef, userWantsControl: userWantsControlRef, autoSlideSize: autoSlideSizeRef, displayIndex: displayIndexRef, realIndex: realIndexRef, slideStyles: slideStylesRef, translateStyle: translateStyleRef, handleTouchstart,
|
|
241
681
|
handleTransitionEnd,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
682
|
+
handleMousewheel,
|
|
683
|
+
handleClick,
|
|
684
|
+
handleResize,
|
|
685
|
+
handleSlideResize, isActive: isDisplayActive }, caroulseSlotProps), caroulseExposedMethod), { cssVars: (0, vue_1.computed)(() => {
|
|
686
|
+
const { common: { cubicBezierEaseInOut }, self: { dotSize, dotColor, dotColorActive, dotColorFocus, dotLineWidth, dotLineWidthActive, arrowColor } } = themeRef.value;
|
|
245
687
|
return {
|
|
246
688
|
'--n-bezier': cubicBezierEaseInOut,
|
|
247
689
|
'--n-dot-color': dotColor,
|
|
690
|
+
'--n-dot-color-focus': dotColorFocus,
|
|
248
691
|
'--n-dot-color-active': dotColorActive,
|
|
249
692
|
'--n-dot-size': dotSize,
|
|
693
|
+
'--n-dot-line-width': dotLineWidth,
|
|
694
|
+
'--n-dot-line-width-active': dotLineWidthActive,
|
|
250
695
|
'--n-arrow-color': arrowColor
|
|
251
696
|
};
|
|
252
|
-
})
|
|
253
|
-
};
|
|
697
|
+
}) });
|
|
254
698
|
},
|
|
255
699
|
render() {
|
|
256
|
-
const { showArrow,
|
|
257
|
-
const children = (0, _utils_1.flatten)(
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
700
|
+
const { mergedClsPrefix, showArrow, userWantsControl, draggable, touchable, slideStyles, dotType, dotPlacement, transitionProps = {}, arrowSlotProps, dotSlotProps, $slots: { default: defaultSlot, dots: dotsSlot, arrow: arrowSlot } } = this;
|
|
701
|
+
const children = (defaultSlot && (0, _utils_1.flatten)(defaultSlot())) || [];
|
|
702
|
+
let slides = filterCarouselItem(children);
|
|
703
|
+
if (!slides.length) {
|
|
704
|
+
slides = children.map((ch) => ((0, vue_1.h)(CarouselItem_1.default, null, {
|
|
705
|
+
default: () => (0, vue_1.cloneVNode)(ch)
|
|
706
|
+
})));
|
|
707
|
+
}
|
|
708
|
+
const { length: realLength } = slides;
|
|
709
|
+
if (realLength > 1 && this.duplicatedable) {
|
|
710
|
+
slides.push(duplicateSlide(slides[0], 0, 'append'));
|
|
711
|
+
slides.unshift(duplicateSlide(slides[realLength - 1], realLength - 1, 'prepend'));
|
|
712
|
+
}
|
|
713
|
+
this.slideVNodes.value = slides;
|
|
714
|
+
// When users need to customize the size of the slide,
|
|
715
|
+
// we listen to them to fix the current translate
|
|
716
|
+
if (this.autoSlideSize) {
|
|
717
|
+
slides = slides.map((slide) => ((0, vue_1.h)(vueuc_1.VResizeObserver, { onResize: this.handleSlideResize }, {
|
|
718
|
+
default: () => slide
|
|
719
|
+
})));
|
|
720
|
+
}
|
|
721
|
+
return ((0, vue_1.h)("div", { ref: "selfElRef", class: [
|
|
265
722
|
`${mergedClsPrefix}-carousel`,
|
|
266
|
-
`${mergedClsPrefix}-carousel--${
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
: undefined, onKeydown: (e) => this.handleKeydown(e, i + 1) }));
|
|
288
|
-
})),
|
|
289
|
-
showArrow && [
|
|
290
|
-
(0, vue_1.h)("div", { class: [
|
|
291
|
-
`${mergedClsPrefix}-carousel__arrow`,
|
|
292
|
-
`${mergedClsPrefix}-carousel__arrow--${vertical ? 'bottom' : 'right'}`
|
|
293
|
-
], role: "button", onClick: () => {
|
|
294
|
-
this.next();
|
|
295
|
-
} },
|
|
296
|
-
(0, vue_1.h)(icons_1.ForwardIcon, null)),
|
|
297
|
-
(0, vue_1.h)("div", { class: [
|
|
298
|
-
`${mergedClsPrefix}-carousel__arrow`,
|
|
299
|
-
`${mergedClsPrefix}-carousel__arrow--${vertical ? 'top' : 'left'}`
|
|
300
|
-
], role: "button", onClick: () => {
|
|
301
|
-
this.prev();
|
|
302
|
-
} },
|
|
303
|
-
(0, vue_1.h)(icons_1.BackwardIcon, null))
|
|
304
|
-
]));
|
|
723
|
+
`${mergedClsPrefix}-carousel--${dotPlacement}`,
|
|
724
|
+
`${mergedClsPrefix}-carousel--${this.direction}`,
|
|
725
|
+
`${mergedClsPrefix}-carousel--${this.effect}`,
|
|
726
|
+
userWantsControl && `${mergedClsPrefix}-carousel--usercontrol`
|
|
727
|
+
], style: this.cssVars },
|
|
728
|
+
(0, vue_1.h)(vueuc_1.VResizeObserver, { onResize: this.handleResize }, {
|
|
729
|
+
default: () => ((0, vue_1.h)("div", { class: `${mergedClsPrefix}-carousel__slides`, role: "listbox", style: this.translateStyle, onMousedown: draggable ? this.handleTouchstart : undefined, onTouchstart: touchable ? this.handleTouchstart : undefined,
|
|
730
|
+
// @ts-expect-error
|
|
731
|
+
onClickCapture: this.handleClick, onWheel: this.mousewheel ? this.handleMousewheel : undefined, onTransitionend: this.handleTransitionEnd }, userWantsControl
|
|
732
|
+
? slides.map((slide, i) => ((0, vue_1.h)("div", { style: slideStyles[i], key: i }, (0, vue_1.withDirectives)((0, vue_1.h)(vue_1.Transition, Object.assign({}, transitionProps), {
|
|
733
|
+
default: () => slide
|
|
734
|
+
}), [[vue_1.vShow, this.isActive(i)]]))))
|
|
735
|
+
: slides))
|
|
736
|
+
}),
|
|
737
|
+
this.showDots &&
|
|
738
|
+
(dotsSlot
|
|
739
|
+
? dotsSlot(dotSlotProps)
|
|
740
|
+
: dotSlotProps.total > 1 && ((0, vue_1.h)(CarouselDots_1.default, { key: dotType + dotPlacement, total: dotSlotProps.total, currentIndex: dotSlotProps.currentIndex, dotType: dotType, trigger: this.trigger, keyboard: this.keyboard }))),
|
|
741
|
+
showArrow &&
|
|
742
|
+
(arrowSlot ? arrowSlot(arrowSlotProps) : (0, vue_1.h)(CarouselArrow_1.default, null))));
|
|
305
743
|
}
|
|
306
744
|
});
|
|
745
|
+
function filterCarouselItem(vnodes, carouselItems = []) {
|
|
746
|
+
if (Array.isArray(vnodes)) {
|
|
747
|
+
vnodes.forEach((vnode) => {
|
|
748
|
+
if (vnode.type && vnode.type.name === 'CarouselItem') {
|
|
749
|
+
carouselItems.push(vnode);
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
return carouselItems;
|
|
754
|
+
}
|
|
755
|
+
function duplicateSlide(child, index, position) {
|
|
756
|
+
return (0, vue_1.cloneVNode)(child, {
|
|
757
|
+
// for patch
|
|
758
|
+
key: `carousel-item-duplicate-${index}-${position}`
|
|
759
|
+
});
|
|
760
|
+
}
|