@nutui/nutui-react 2.3.1 → 2.3.2
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/CHANGELOG.md +12 -0
- package/dist/esm/ActionSheet/style/style.css +1 -1
- package/dist/esm/Address/style/style.css +1 -1
- package/dist/esm/Calendar/style/style.css +1 -1
- package/dist/esm/Cascader/style/style.css +1 -1
- package/dist/esm/DatePicker/style/style.css +1 -1
- package/dist/esm/FixedNav.js +1 -1
- package/dist/esm/ImagePreview/style/style.css +1 -1
- package/dist/esm/NumberKeyboard/style/style.css +1 -1
- package/dist/esm/Picker/style/style.css +1 -1
- package/dist/esm/Popover/style/style.css +1 -1
- package/dist/esm/Popup/style/style.css +1 -1
- package/dist/esm/ShortPassword/style/style.css +1 -1
- package/dist/esm/SideNavBar/style/style.css +1 -1
- package/dist/esm/Swiper.js +120 -167
- package/dist/esm/TimeSelect/style/style.css +1 -1
- package/dist/esm/Tour/style/style.css +1 -1
- package/dist/esm/types/src/packages/address/address.d.ts +1 -1
- package/dist/esm/types/src/packages/address/address.taro.d.ts +1 -1
- package/dist/esm/types/src/packages/address/existRender.d.ts +1 -1
- package/dist/esm/types/src/packages/address/existRender.taro.d.ts +1 -1
- package/dist/esm/types/src/packages/animate/animate.d.ts +1 -1
- package/dist/esm/types/src/packages/animate/animate.taro.d.ts +1 -1
- package/dist/esm/types/src/packages/animate/index.d.ts +1 -1
- package/dist/esm/types/src/packages/animate/index.taro.d.ts +1 -1
- package/dist/esm/types/src/packages/calendar/calendar.d.ts +1 -1
- package/dist/esm/types/src/packages/calendar/calendar.taro.d.ts +1 -1
- package/dist/esm/types/src/packages/calendar/utils.d.ts +1 -1
- package/dist/esm/types/src/packages/calendaritem/calendaritem.d.ts +1 -1
- package/dist/esm/types/src/packages/calendaritem/calendaritem.taro.d.ts +1 -1
- package/dist/esm/types/src/packages/checkboxgroup/checkboxgroup.d.ts +1 -1
- package/dist/esm/types/src/packages/checkboxgroup/checkboxgroup.taro.d.ts +1 -1
- package/dist/esm/types/src/packages/fixednav/fixednav.d.ts +2 -6
- package/dist/esm/types/src/packages/fixednav/fixednav.taro.d.ts +2 -6
- package/dist/esm/types/src/packages/fixednav/index.d.ts +2 -1
- package/dist/esm/types/src/packages/fixednav/index.taro.d.ts +2 -1
- package/dist/esm/types/src/packages/fixednav/types.d.ts +12 -0
- package/dist/esm/types/src/packages/radiogroup/radiogroup.d.ts +1 -1
- package/dist/esm/types/src/packages/radiogroup/radiogroup.taro.d.ts +1 -1
- package/dist/esm/types/src/packages/virtuallist/utils.d.ts +1 -1
- package/dist/esm/types/src/packages/virtuallist/virtuallist.d.ts +1 -1
- package/dist/esm/types/src/packages/virtuallist/virtuallist.taro.d.ts +1 -1
- package/dist/esm/types/src/utils/use-touch.d.ts +2 -0
- package/dist/esm/use-touch.js +7 -0
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/tr-TR.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/locales/zh-UG.js +1 -1
- package/dist/nutui.react.es.js +132 -173
- package/dist/nutui.react.umd.js +132 -173
- package/dist/packages/cascader/cascader.scss +1 -6
- package/dist/packages/popup/popup.scss +2 -2
- package/dist/style.css +1 -1
- package/dist/style.mjs +1 -1
- package/dist/types/packages/address/address.d.ts +1 -1
- package/dist/types/packages/address/address.taro.d.ts +1 -1
- package/dist/types/packages/address/existRender.d.ts +1 -1
- package/dist/types/packages/address/existRender.taro.d.ts +1 -1
- package/dist/types/packages/animate/animate.d.ts +1 -1
- package/dist/types/packages/animate/animate.taro.d.ts +1 -1
- package/dist/types/packages/animate/index.d.ts +1 -1
- package/dist/types/packages/animate/index.taro.d.ts +1 -1
- package/dist/types/packages/calendar/calendar.d.ts +1 -1
- package/dist/types/packages/calendar/calendar.taro.d.ts +1 -1
- package/dist/types/packages/calendar/utils.d.ts +1 -1
- package/dist/types/packages/calendaritem/calendaritem.d.ts +1 -1
- package/dist/types/packages/calendaritem/calendaritem.taro.d.ts +1 -1
- package/dist/types/packages/checkboxgroup/checkboxgroup.d.ts +1 -1
- package/dist/types/packages/checkboxgroup/checkboxgroup.taro.d.ts +1 -1
- package/dist/types/packages/fixednav/fixednav.d.ts +2 -6
- package/dist/types/packages/fixednav/fixednav.taro.d.ts +2 -6
- package/dist/types/packages/fixednav/index.d.ts +2 -1
- package/dist/types/packages/fixednav/index.taro.d.ts +2 -1
- package/dist/types/packages/fixednav/types.d.ts +12 -0
- package/dist/types/packages/radiogroup/radiogroup.d.ts +1 -1
- package/dist/types/packages/radiogroup/radiogroup.taro.d.ts +1 -1
- package/dist/types/packages/virtuallist/utils.d.ts +1 -1
- package/dist/types/packages/virtuallist/virtuallist.d.ts +1 -1
- package/dist/types/packages/virtuallist/virtuallist.taro.d.ts +1 -1
- package/dist/types/utils/use-touch.d.ts +2 -0
- package/package.json +1 -1
- /package/dist/esm/types/src/packages/address/{type.d.ts → types.d.ts} +0 -0
- /package/dist/esm/types/src/packages/animate/{type.d.ts → types.d.ts} +0 -0
- /package/dist/esm/types/src/packages/calendar/{type.d.ts → types.d.ts} +0 -0
- /package/dist/esm/types/src/packages/checkboxgroup/{type.d.ts → types.d.ts} +0 -0
- /package/dist/esm/types/src/packages/radiogroup/{type.d.ts → types.d.ts} +0 -0
- /package/dist/esm/types/src/packages/virtuallist/{type.d.ts → types.d.ts} +0 -0
- /package/dist/types/packages/address/{type.d.ts → types.d.ts} +0 -0
- /package/dist/types/packages/animate/{type.d.ts → types.d.ts} +0 -0
- /package/dist/types/packages/calendar/{type.d.ts → types.d.ts} +0 -0
- /package/dist/types/packages/checkboxgroup/{type.d.ts → types.d.ts} +0 -0
- /package/dist/types/packages/radiogroup/{type.d.ts → types.d.ts} +0 -0
- /package/dist/types/packages/virtuallist/{type.d.ts → types.d.ts} +0 -0
package/dist/nutui.react.es.js
CHANGED
|
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
/*!
|
|
8
|
-
* @nutui/nutui-react v2.3.
|
|
8
|
+
* @nutui/nutui-react v2.3.2 Fri Dec 15 2023 18:53:20 GMT+0800 (China Standard Time)
|
|
9
9
|
* (c) 2023 @jdf2e.
|
|
10
10
|
* Released under the MIT License.
|
|
11
11
|
*/
|
|
@@ -4342,12 +4342,15 @@ function useTouch() {
|
|
|
4342
4342
|
const startY = useRef(0);
|
|
4343
4343
|
const deltaX = useRef(0);
|
|
4344
4344
|
const deltaY = useRef(0);
|
|
4345
|
+
const delta = useRef(0);
|
|
4345
4346
|
const offsetX = useRef(0);
|
|
4346
4347
|
const offsetY = useRef(0);
|
|
4347
4348
|
const direction = useRef("");
|
|
4349
|
+
const touchTime = useRef(null);
|
|
4348
4350
|
const isVertical = () => direction.current === "vertical";
|
|
4349
4351
|
const isHorizontal = () => direction.current === "horizontal";
|
|
4350
4352
|
const reset = () => {
|
|
4353
|
+
touchTime.current = null;
|
|
4351
4354
|
deltaX.current = 0;
|
|
4352
4355
|
deltaY.current = 0;
|
|
4353
4356
|
offsetX.current = 0;
|
|
@@ -4356,6 +4359,7 @@ function useTouch() {
|
|
|
4356
4359
|
};
|
|
4357
4360
|
const start2 = (event) => {
|
|
4358
4361
|
reset();
|
|
4362
|
+
touchTime.current = Date.now();
|
|
4359
4363
|
startX.current = event.touches[0].clientX;
|
|
4360
4364
|
startY.current = event.touches[0].clientY;
|
|
4361
4365
|
};
|
|
@@ -4365,6 +4369,7 @@ function useTouch() {
|
|
|
4365
4369
|
deltaY.current = touch.clientY - startY.current;
|
|
4366
4370
|
offsetX.current = Math.abs(deltaX.current);
|
|
4367
4371
|
offsetY.current = Math.abs(deltaY.current);
|
|
4372
|
+
delta.current = isVertical() ? deltaY.current : deltaX.current;
|
|
4368
4373
|
if (!direction.current) {
|
|
4369
4374
|
direction.current = getDirection(offsetX.current, offsetY.current);
|
|
4370
4375
|
}
|
|
@@ -4373,10 +4378,12 @@ function useTouch() {
|
|
|
4373
4378
|
move,
|
|
4374
4379
|
start: start2,
|
|
4375
4380
|
reset,
|
|
4381
|
+
touchTime,
|
|
4376
4382
|
startX,
|
|
4377
4383
|
startY,
|
|
4378
4384
|
deltaX,
|
|
4379
4385
|
deltaY,
|
|
4386
|
+
delta,
|
|
4380
4387
|
offsetX,
|
|
4381
4388
|
offsetY,
|
|
4382
4389
|
direction,
|
|
@@ -10595,7 +10602,7 @@ const FixedNav = (props) => {
|
|
|
10595
10602
|
onClick: (event) => handleClick2(item, event),
|
|
10596
10603
|
key: item.id || index
|
|
10597
10604
|
},
|
|
10598
|
-
/* @__PURE__ */ React__default.createElement("img", { src: item.icon, alt: "" }),
|
|
10605
|
+
React__default.isValidElement(item.icon) ? item.icon : /* @__PURE__ */ React__default.createElement("img", { src: item.icon, alt: "" }),
|
|
10599
10606
|
/* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}-list-text` }, item.text),
|
|
10600
10607
|
item.num && /* @__PURE__ */ React__default.createElement("div", { className: "b" }, item.num)
|
|
10601
10608
|
);
|
|
@@ -22562,9 +22569,8 @@ const defaultProps$h = {
|
|
|
22562
22569
|
center: false,
|
|
22563
22570
|
className: ""
|
|
22564
22571
|
};
|
|
22565
|
-
const DISTANCE = 5;
|
|
22566
22572
|
const Swiper = React__default.forwardRef((props, ref) => {
|
|
22567
|
-
const
|
|
22573
|
+
const mergedProps = { ...defaultProps$h, ...props };
|
|
22568
22574
|
const {
|
|
22569
22575
|
children,
|
|
22570
22576
|
direction,
|
|
@@ -22578,7 +22584,7 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22578
22584
|
autoPlay,
|
|
22579
22585
|
center,
|
|
22580
22586
|
...rest
|
|
22581
|
-
} =
|
|
22587
|
+
} = mergedProps;
|
|
22582
22588
|
const container = useRef(null);
|
|
22583
22589
|
const innerRef = useRef(null);
|
|
22584
22590
|
const swiperRef = useRef({
|
|
@@ -22589,6 +22595,7 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22589
22595
|
offset: 0,
|
|
22590
22596
|
size: 0
|
|
22591
22597
|
});
|
|
22598
|
+
const touch = useTouch();
|
|
22592
22599
|
const isVertical = direction === "vertical";
|
|
22593
22600
|
const [rect, setRect] = useState(null);
|
|
22594
22601
|
let [active, setActive] = useState(0);
|
|
@@ -22598,39 +22605,28 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22598
22605
|
const [childOffset, setChildOffset] = useState([]);
|
|
22599
22606
|
const [ready, setReady] = useState(false);
|
|
22600
22607
|
let size = isVertical ? height : width;
|
|
22601
|
-
const
|
|
22602
|
-
|
|
22603
|
-
|
|
22604
|
-
deltaX: 0,
|
|
22605
|
-
deltaY: 0,
|
|
22606
|
-
offsetX: 0,
|
|
22607
|
-
offsetY: 0,
|
|
22608
|
-
stateDirection: "",
|
|
22609
|
-
delta: 0,
|
|
22610
|
-
touchTime: 0
|
|
22611
|
-
});
|
|
22612
|
-
const { childs, childCount } = useMemo$1(() => {
|
|
22613
|
-
let childCount2 = 0;
|
|
22614
|
-
const childs2 = React__default.Children.map(props.children, (child) => {
|
|
22608
|
+
const { swiperItems, swiperItemCount } = useMemo$1(() => {
|
|
22609
|
+
let count = 0;
|
|
22610
|
+
const swiperItems2 = React__default.Children.map(props.children, (child) => {
|
|
22615
22611
|
if (!React__default.isValidElement(child))
|
|
22616
22612
|
return null;
|
|
22617
|
-
|
|
22613
|
+
count++;
|
|
22618
22614
|
return child;
|
|
22619
22615
|
});
|
|
22620
22616
|
return {
|
|
22621
|
-
|
|
22622
|
-
|
|
22617
|
+
swiperItems: swiperItems2,
|
|
22618
|
+
swiperItemCount: count
|
|
22623
22619
|
};
|
|
22624
22620
|
}, [props.children]);
|
|
22625
|
-
let trackSize =
|
|
22621
|
+
let trackSize = swiperItemCount * Number(size);
|
|
22626
22622
|
const parent = {
|
|
22627
|
-
propSwiper,
|
|
22623
|
+
propSwiper: mergedProps,
|
|
22628
22624
|
size
|
|
22629
22625
|
};
|
|
22630
22626
|
const minOffset = (() => {
|
|
22631
22627
|
if (rect) {
|
|
22632
22628
|
const base = isVertical ? rect.height : rect.width;
|
|
22633
|
-
return base - Number(size) *
|
|
22629
|
+
return base - Number(size) * swiperItemCount;
|
|
22634
22630
|
}
|
|
22635
22631
|
return 0;
|
|
22636
22632
|
})();
|
|
@@ -22639,65 +22635,59 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22639
22635
|
swiperRef.current.autoplayTimer = null;
|
|
22640
22636
|
};
|
|
22641
22637
|
const startPlay = () => {
|
|
22642
|
-
if (
|
|
22638
|
+
if (mergedProps.autoPlay <= 0 || swiperItemCount <= 1)
|
|
22643
22639
|
return;
|
|
22644
22640
|
stopAutoPlay();
|
|
22645
22641
|
swiperRef.current.autoplayTimer = setTimeout(() => {
|
|
22646
22642
|
next();
|
|
22647
22643
|
startPlay();
|
|
22648
|
-
}, Number(
|
|
22644
|
+
}, Number(mergedProps.autoPlay));
|
|
22649
22645
|
};
|
|
22650
22646
|
const resetPosition = () => {
|
|
22651
22647
|
swiperRef.current.moving = true;
|
|
22652
22648
|
if (active <= -1) {
|
|
22653
|
-
move({ pace:
|
|
22649
|
+
move({ pace: swiperItemCount });
|
|
22654
22650
|
}
|
|
22655
|
-
if (active >=
|
|
22656
|
-
move({ pace: -
|
|
22651
|
+
if (active >= swiperItemCount) {
|
|
22652
|
+
move({ pace: -swiperItemCount });
|
|
22657
22653
|
}
|
|
22658
22654
|
};
|
|
22659
22655
|
const prev = () => {
|
|
22660
22656
|
resetPosition();
|
|
22661
|
-
|
|
22662
|
-
|
|
22663
|
-
|
|
22664
|
-
|
|
22665
|
-
|
|
22666
|
-
|
|
22667
|
-
isEmit: true
|
|
22668
|
-
});
|
|
22657
|
+
touch.reset();
|
|
22658
|
+
requestAniFrame$1(() => {
|
|
22659
|
+
swiperRef.current.moving = false;
|
|
22660
|
+
move({
|
|
22661
|
+
pace: -1,
|
|
22662
|
+
isEmit: true
|
|
22669
22663
|
});
|
|
22670
22664
|
});
|
|
22671
22665
|
};
|
|
22672
22666
|
const next = () => {
|
|
22673
22667
|
resetPosition();
|
|
22674
|
-
|
|
22675
|
-
|
|
22676
|
-
|
|
22677
|
-
|
|
22678
|
-
|
|
22679
|
-
|
|
22680
|
-
isEmit: true
|
|
22681
|
-
});
|
|
22668
|
+
touch.reset();
|
|
22669
|
+
requestAniFrame$1(() => {
|
|
22670
|
+
swiperRef.current.moving = false;
|
|
22671
|
+
move({
|
|
22672
|
+
pace: 1,
|
|
22673
|
+
isEmit: true
|
|
22682
22674
|
});
|
|
22683
22675
|
});
|
|
22684
22676
|
};
|
|
22685
22677
|
const to2 = (index) => {
|
|
22686
22678
|
resetPosition();
|
|
22687
|
-
|
|
22688
|
-
|
|
22689
|
-
|
|
22690
|
-
|
|
22691
|
-
|
|
22692
|
-
|
|
22693
|
-
|
|
22694
|
-
|
|
22695
|
-
|
|
22696
|
-
|
|
22697
|
-
|
|
22698
|
-
|
|
22699
|
-
isEmit: true
|
|
22700
|
-
});
|
|
22679
|
+
touch.reset();
|
|
22680
|
+
requestAniFrame$1(() => {
|
|
22681
|
+
swiperRef.current.moving = false;
|
|
22682
|
+
let targetIndex;
|
|
22683
|
+
if (props.loop && swiperItemCount === index) {
|
|
22684
|
+
targetIndex = active === 0 ? 0 : index;
|
|
22685
|
+
} else {
|
|
22686
|
+
targetIndex = index % swiperItemCount;
|
|
22687
|
+
}
|
|
22688
|
+
move({
|
|
22689
|
+
pace: targetIndex - active,
|
|
22690
|
+
isEmit: true
|
|
22701
22691
|
});
|
|
22702
22692
|
});
|
|
22703
22693
|
};
|
|
@@ -22710,7 +22700,8 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22710
22700
|
isEmit = false,
|
|
22711
22701
|
movingStatus = false
|
|
22712
22702
|
}) => {
|
|
22713
|
-
|
|
22703
|
+
var _a2;
|
|
22704
|
+
if (swiperItemCount <= 1)
|
|
22714
22705
|
return;
|
|
22715
22706
|
const targetActive = getActive(pace);
|
|
22716
22707
|
const targetOffset = getOffset(targetActive, offset2);
|
|
@@ -22719,27 +22710,33 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22719
22710
|
const rightBound = targetOffset < minOffset;
|
|
22720
22711
|
childOffset[0] = rightBound ? trackSize : 0;
|
|
22721
22712
|
}
|
|
22722
|
-
if (Array.isArray(children) && children[
|
|
22713
|
+
if (Array.isArray(children) && children[swiperItemCount - 1] && targetOffset !== 0) {
|
|
22723
22714
|
const leftBound = targetOffset > 0;
|
|
22724
|
-
childOffset[
|
|
22715
|
+
childOffset[swiperItemCount - 1] = leftBound ? -trackSize : 0;
|
|
22725
22716
|
}
|
|
22726
22717
|
setChildOffset(childOffset);
|
|
22727
22718
|
}
|
|
22728
22719
|
if (isEmit && active !== targetActive) {
|
|
22729
|
-
props.onChange
|
|
22720
|
+
(_a2 = props.onChange) == null ? void 0 : _a2.call(props, (targetActive + swiperItemCount) % swiperItemCount);
|
|
22730
22721
|
}
|
|
22731
22722
|
active = targetActive;
|
|
22732
22723
|
setActive(targetActive);
|
|
22733
22724
|
setOffset(targetOffset);
|
|
22734
22725
|
getStyle(targetOffset);
|
|
22735
22726
|
};
|
|
22727
|
+
React__default.useImperativeHandle(ref, () => ({
|
|
22728
|
+
to: to2,
|
|
22729
|
+
next,
|
|
22730
|
+
prev,
|
|
22731
|
+
resize
|
|
22732
|
+
}));
|
|
22736
22733
|
const getActive = (pace) => {
|
|
22737
22734
|
if (pace) {
|
|
22738
22735
|
const _active = active + pace;
|
|
22739
22736
|
if (props.loop) {
|
|
22740
|
-
return range3(_active, -1,
|
|
22737
|
+
return range3(_active, -1, swiperItemCount);
|
|
22741
22738
|
}
|
|
22742
|
-
return range3(_active, 0,
|
|
22739
|
+
return range3(_active, 0, swiperItemCount - 1);
|
|
22743
22740
|
}
|
|
22744
22741
|
return active;
|
|
22745
22742
|
};
|
|
@@ -22754,45 +22751,9 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22754
22751
|
}
|
|
22755
22752
|
return targetOffset;
|
|
22756
22753
|
};
|
|
22757
|
-
const requestFrame = (fn) => {
|
|
22758
|
-
window.requestAnimationFrame.call(window, fn);
|
|
22759
|
-
};
|
|
22760
22754
|
const range3 = (num, min, max) => {
|
|
22761
22755
|
return Math.min(Math.max(num, min), max);
|
|
22762
22756
|
};
|
|
22763
|
-
const getDirection2 = (x, y) => {
|
|
22764
|
-
if (x > y && x > DISTANCE)
|
|
22765
|
-
return "horizontal";
|
|
22766
|
-
if (y > x && y > DISTANCE)
|
|
22767
|
-
return "vertical";
|
|
22768
|
-
return "";
|
|
22769
|
-
};
|
|
22770
|
-
const resetTouchDetails = () => {
|
|
22771
|
-
touch.startX = 0;
|
|
22772
|
-
touch.startY = 0;
|
|
22773
|
-
touch.deltaX = 0;
|
|
22774
|
-
touch.deltaY = 0;
|
|
22775
|
-
touch.offsetX = 0;
|
|
22776
|
-
touch.offsetY = 0;
|
|
22777
|
-
touch.delta = 0;
|
|
22778
|
-
touch.stateDirection = "";
|
|
22779
|
-
touch.touchTime = 0;
|
|
22780
|
-
};
|
|
22781
|
-
const touchStart = (e2) => {
|
|
22782
|
-
resetTouchDetails();
|
|
22783
|
-
touch.startX = e2.touches[0].clientX;
|
|
22784
|
-
touch.startY = e2.touches[0].clientY;
|
|
22785
|
-
};
|
|
22786
|
-
const handleTouchMove = (e2) => {
|
|
22787
|
-
touch.deltaX = e2.touches[0].clientX - touch.startX;
|
|
22788
|
-
touch.deltaY = e2.touches[0].clientY - touch.startY;
|
|
22789
|
-
touch.offsetX = Math.abs(touch.deltaX);
|
|
22790
|
-
touch.offsetY = Math.abs(touch.deltaY);
|
|
22791
|
-
touch.delta = isVertical ? touch.deltaY : touch.deltaX;
|
|
22792
|
-
if (!touch.stateDirection) {
|
|
22793
|
-
touch.stateDirection = getDirection2(touch.offsetX, touch.offsetY);
|
|
22794
|
-
}
|
|
22795
|
-
};
|
|
22796
22757
|
const classPrefix2 = "nut-swiper";
|
|
22797
22758
|
const contentClass = classNames({
|
|
22798
22759
|
[`${classPrefix2}-inner`]: true,
|
|
@@ -22806,18 +22767,17 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22806
22767
|
} else {
|
|
22807
22768
|
const _size = isVertical ? height : width;
|
|
22808
22769
|
const val = isVertical ? rect.height - _size : rect.width - _size;
|
|
22809
|
-
_offset = moveOffset + (active ===
|
|
22770
|
+
_offset = moveOffset + (active === swiperItemCount - 1 && !props.loop ? -val / 2 : val / 2);
|
|
22810
22771
|
}
|
|
22811
22772
|
target.style.transitionDuration = `${swiperRef.current.moving ? 0 : props.duration}ms`;
|
|
22812
|
-
target.style[isVertical ? "height" : "width"] = `${Number(size) *
|
|
22773
|
+
target.style[isVertical ? "height" : "width"] = `${Number(size) * swiperItemCount}px`;
|
|
22813
22774
|
target.style[isVertical ? "width" : "height"] = `${isVertical ? width : height}px`;
|
|
22814
22775
|
target.style.transform = `translate3D${!isVertical ? `(${_offset}px,0,0)` : `(0,${_offset}px,0)`}`;
|
|
22815
22776
|
};
|
|
22816
22777
|
const onTouchStart = (e2) => {
|
|
22817
22778
|
if (!props.touchable)
|
|
22818
22779
|
return;
|
|
22819
|
-
|
|
22820
|
-
touch.touchTime = Date.now();
|
|
22780
|
+
touch.start(e2);
|
|
22821
22781
|
stopAutoPlay();
|
|
22822
22782
|
resetPosition();
|
|
22823
22783
|
};
|
|
@@ -22827,10 +22787,10 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22827
22787
|
if (props.stopPropagation)
|
|
22828
22788
|
e2.stopPropagation();
|
|
22829
22789
|
if (props.touchable && swiperRef.current.moving) {
|
|
22830
|
-
|
|
22831
|
-
if (touch.
|
|
22790
|
+
touch.move(e2);
|
|
22791
|
+
if (touch.direction.current === props.direction) {
|
|
22832
22792
|
move({
|
|
22833
|
-
offset: touch.delta
|
|
22793
|
+
offset: touch.delta.current
|
|
22834
22794
|
});
|
|
22835
22795
|
}
|
|
22836
22796
|
}
|
|
@@ -22838,42 +22798,53 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22838
22798
|
const onTouchEnd = (e2) => {
|
|
22839
22799
|
if (!props.touchable || !swiperRef.current.moving)
|
|
22840
22800
|
return;
|
|
22841
|
-
const speed = touch.delta / (Date.now() - touch.touchTime);
|
|
22842
|
-
const isShouldMove = Math.abs(speed) > 0.3 || Math.abs(touch.delta) > Number((size / 2).toFixed(2));
|
|
22843
|
-
let pace = 0;
|
|
22801
|
+
const speed = touch.delta.current / (Date.now() - touch.touchTime.current);
|
|
22802
|
+
const isShouldMove = Math.abs(speed) > 0.3 || Math.abs(touch.delta.current) > Number((size / 2).toFixed(2));
|
|
22844
22803
|
swiperRef.current.moving = false;
|
|
22845
|
-
if (isShouldMove && touch.
|
|
22846
|
-
|
|
22804
|
+
if (isShouldMove && touch.direction.current === props.direction) {
|
|
22805
|
+
let pace = 0;
|
|
22806
|
+
const offset2 = touch.isVertical() ? touch.offsetY : touch.offsetX;
|
|
22847
22807
|
if (props.loop) {
|
|
22848
|
-
if (offset2 > 0) {
|
|
22849
|
-
pace = touch.delta > 0 ? -1 : 1;
|
|
22850
|
-
} else {
|
|
22851
|
-
pace = 0;
|
|
22808
|
+
if (offset2.current > 0) {
|
|
22809
|
+
pace = touch.delta.current > 0 ? -1 : 1;
|
|
22852
22810
|
}
|
|
22853
22811
|
} else {
|
|
22854
|
-
pace = -Math[touch.delta > 0 ? "ceil" : "floor"](
|
|
22812
|
+
pace = -Math[touch.delta.current > 0 ? "ceil" : "floor"](
|
|
22813
|
+
touch.delta.current / size
|
|
22814
|
+
);
|
|
22855
22815
|
}
|
|
22856
22816
|
move({
|
|
22857
22817
|
pace,
|
|
22858
22818
|
isEmit: true
|
|
22859
22819
|
});
|
|
22860
|
-
} else if (touch.delta) {
|
|
22820
|
+
} else if (touch.delta.current) {
|
|
22861
22821
|
move({ pace: 0 });
|
|
22862
22822
|
} else {
|
|
22863
22823
|
getStyle();
|
|
22864
22824
|
}
|
|
22865
22825
|
startPlay();
|
|
22866
22826
|
};
|
|
22867
|
-
|
|
22868
|
-
|
|
22869
|
-
|
|
22870
|
-
|
|
22827
|
+
const getItemStyle = (index) => {
|
|
22828
|
+
const style = {};
|
|
22829
|
+
if (size) {
|
|
22830
|
+
style[direction === "horizontal" ? "width" : "height"] = `${size}px`;
|
|
22831
|
+
}
|
|
22832
|
+
const offset2 = childOffset[index];
|
|
22833
|
+
if (offset2) {
|
|
22834
|
+
style.transform = `translate3D${direction === "horizontal" ? `(${offset2}px,0,0)` : `(0,${offset2}px,0)`}`;
|
|
22835
|
+
}
|
|
22836
|
+
return style;
|
|
22837
|
+
};
|
|
22838
|
+
const init = (index) => {
|
|
22871
22839
|
const rect2 = getRect(container == null ? void 0 : container.current);
|
|
22872
|
-
const currentIndex = Math.max(
|
|
22873
|
-
|
|
22874
|
-
|
|
22840
|
+
const currentIndex = Math.max(
|
|
22841
|
+
Math.min(swiperItemCount - 1, index || Number(mergedProps.defaultValue)),
|
|
22842
|
+
0
|
|
22843
|
+
);
|
|
22844
|
+
const width2 = Number(mergedProps.width) || rect2.width;
|
|
22845
|
+
const height2 = Number(mergedProps.height) || rect2.height;
|
|
22875
22846
|
size = isVertical ? height2 : width2;
|
|
22876
|
-
trackSize =
|
|
22847
|
+
trackSize = swiperItemCount * Number(size);
|
|
22877
22848
|
const targetOffset = getOffset(currentIndex);
|
|
22878
22849
|
swiperRef.current.moving = true;
|
|
22879
22850
|
if (ready) {
|
|
@@ -22902,61 +22873,49 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22902
22873
|
stopAutoPlay();
|
|
22903
22874
|
startPlay();
|
|
22904
22875
|
}, [children]);
|
|
22905
|
-
useEffect(() => init(), [propSwiper.defaultValue]);
|
|
22906
22876
|
useEffect(() => {
|
|
22907
|
-
const
|
|
22908
|
-
|
|
22909
|
-
|
|
22910
|
-
|
|
22877
|
+
const events = [
|
|
22878
|
+
{ name: "touchstart", e: onTouchStart },
|
|
22879
|
+
{ name: "touchmove", e: onTouchMove },
|
|
22880
|
+
{ name: "touchend", e: onTouchEnd }
|
|
22881
|
+
];
|
|
22882
|
+
events.forEach((item) => {
|
|
22883
|
+
var _a2;
|
|
22884
|
+
(_a2 = container.current) == null ? void 0 : _a2.addEventListener(item.name, item.e, false);
|
|
22885
|
+
});
|
|
22911
22886
|
return () => {
|
|
22912
|
-
|
|
22913
|
-
|
|
22914
|
-
|
|
22887
|
+
events.forEach((item) => {
|
|
22888
|
+
var _a2;
|
|
22889
|
+
(_a2 = container.current) == null ? void 0 : _a2.removeEventListener(item.name, item.e, false);
|
|
22890
|
+
});
|
|
22915
22891
|
};
|
|
22916
22892
|
});
|
|
22893
|
+
useEffect(() => init(), [props.defaultValue]);
|
|
22917
22894
|
useEffect(() => {
|
|
22918
22895
|
return () => stopAutoPlay();
|
|
22919
22896
|
}, []);
|
|
22920
|
-
const getItemStyle = (index) => {
|
|
22921
|
-
const style = {};
|
|
22922
|
-
if (size) {
|
|
22923
|
-
style[direction === "horizontal" ? "width" : "height"] = `${size}px`;
|
|
22924
|
-
}
|
|
22925
|
-
const offset2 = childOffset[index];
|
|
22926
|
-
if (offset2) {
|
|
22927
|
-
style.transform = `translate3D${direction === "horizontal" ? `(${offset2}px,0,0)` : `(0,${offset2}px,0)`}`;
|
|
22928
|
-
}
|
|
22929
|
-
return style;
|
|
22930
|
-
};
|
|
22931
|
-
React__default.useImperativeHandle(ref, () => ({
|
|
22932
|
-
to: to2,
|
|
22933
|
-
next,
|
|
22934
|
-
prev,
|
|
22935
|
-
resize
|
|
22936
|
-
}));
|
|
22937
22897
|
const renderIndicator = () => {
|
|
22938
22898
|
if (React__default.isValidElement(indicator))
|
|
22939
22899
|
return indicator;
|
|
22940
|
-
if (indicator
|
|
22941
|
-
return
|
|
22942
|
-
|
|
22900
|
+
if (!indicator)
|
|
22901
|
+
return null;
|
|
22902
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
22903
|
+
"div",
|
|
22904
|
+
{
|
|
22905
|
+
className: classNames({
|
|
22906
|
+
[`${classPrefix2}-indicator`]: true,
|
|
22907
|
+
[`${classPrefix2}-indicator-vertical`]: isVertical
|
|
22908
|
+
})
|
|
22909
|
+
},
|
|
22910
|
+
/* @__PURE__ */ React__default.createElement(
|
|
22911
|
+
Indicator,
|
|
22943
22912
|
{
|
|
22944
|
-
|
|
22945
|
-
|
|
22946
|
-
|
|
22947
|
-
|
|
22948
|
-
|
|
22949
|
-
|
|
22950
|
-
Indicator,
|
|
22951
|
-
{
|
|
22952
|
-
current: (active + childCount) % childCount,
|
|
22953
|
-
total: childs == null ? void 0 : childs.length,
|
|
22954
|
-
direction
|
|
22955
|
-
}
|
|
22956
|
-
)
|
|
22957
|
-
);
|
|
22958
|
-
}
|
|
22959
|
-
return null;
|
|
22913
|
+
current: (active + swiperItemCount) % swiperItemCount,
|
|
22914
|
+
total: swiperItems == null ? void 0 : swiperItems.length,
|
|
22915
|
+
direction
|
|
22916
|
+
}
|
|
22917
|
+
)
|
|
22918
|
+
);
|
|
22960
22919
|
};
|
|
22961
22920
|
return /* @__PURE__ */ React__default.createElement(DataContext$1.Provider, { value: parent }, /* @__PURE__ */ React__default.createElement(
|
|
22962
22921
|
"div",
|
|
@@ -22965,7 +22924,7 @@ const Swiper = React__default.forwardRef((props, ref) => {
|
|
|
22965
22924
|
ref: container,
|
|
22966
22925
|
...rest
|
|
22967
22926
|
},
|
|
22968
|
-
/* @__PURE__ */ React__default.createElement("div", { className: contentClass, ref: innerRef }, React__default.Children.map(
|
|
22927
|
+
/* @__PURE__ */ React__default.createElement("div", { className: contentClass, ref: innerRef }, React__default.Children.map(swiperItems, (child, index) => /* @__PURE__ */ React__default.createElement(
|
|
22969
22928
|
"div",
|
|
22970
22929
|
{
|
|
22971
22930
|
className: `${classPrefix2}-item-wrapper`,
|