eli-video-interview 1.2.39 → 1.2.40-alpha.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/esm/components/react-photo-view/Photo.css +14 -0
- package/esm/components/react-photo-view/Photo.d.ts +18 -0
- package/esm/components/react-photo-view/Photo.js +54 -0
- package/esm/components/react-photo-view/PhotoBox.css +18 -0
- package/esm/components/react-photo-view/PhotoBox.d.ts +22 -0
- package/esm/components/react-photo-view/PhotoBox.js +302 -0
- package/esm/components/react-photo-view/PhotoPage.d.ts +9 -0
- package/esm/components/react-photo-view/PhotoPage.js +77 -0
- package/esm/components/react-photo-view/PhotoProvider.d.ts +14 -0
- package/esm/components/react-photo-view/PhotoProvider.js +98 -0
- package/esm/components/react-photo-view/PhotoSlider.css +125 -0
- package/esm/components/react-photo-view/PhotoSlider.d.ts +12 -0
- package/esm/components/react-photo-view/PhotoSlider.js +262 -0
- package/esm/components/react-photo-view/PhotoView.d.ts +30 -0
- package/esm/components/react-photo-view/PhotoView.js +48 -0
- package/esm/components/react-photo-view/components/ArrowLeft.d.ts +3 -0
- package/esm/components/react-photo-view/components/ArrowLeft.js +18 -0
- package/esm/components/react-photo-view/components/ArrowRight.d.ts +3 -0
- package/esm/components/react-photo-view/components/ArrowRight.js +18 -0
- package/esm/components/react-photo-view/components/CloseIcon.d.ts +3 -0
- package/esm/components/react-photo-view/components/CloseIcon.js +16 -0
- package/esm/components/react-photo-view/components/PreventScroll.d.ts +1 -0
- package/esm/components/react-photo-view/components/PreventScroll.js +12 -0
- package/esm/components/react-photo-view/components/SlidePortal.css +10 -0
- package/esm/components/react-photo-view/components/SlidePortal.d.ts +7 -0
- package/esm/components/react-photo-view/components/SlidePortal.js +30 -0
- package/esm/components/react-photo-view/components/Spinner.css +23 -0
- package/esm/components/react-photo-view/components/Spinner.d.ts +4 -0
- package/esm/components/react-photo-view/components/Spinner.js +29 -0
- package/esm/components/react-photo-view/hooks/useAdjacentImages.d.ts +5 -0
- package/esm/components/react-photo-view/hooks/useAdjacentImages.js +14 -0
- package/esm/components/react-photo-view/hooks/useAnimationOrigin.d.ts +6 -0
- package/esm/components/react-photo-view/hooks/useAnimationOrigin.js +72 -0
- package/esm/components/react-photo-view/hooks/useAnimationPosition.d.ts +2 -0
- package/esm/components/react-photo-view/hooks/useAnimationPosition.js +28 -0
- package/esm/components/react-photo-view/hooks/useAnimationVisible.d.ts +6 -0
- package/esm/components/react-photo-view/hooks/useAnimationVisible.js +49 -0
- package/esm/components/react-photo-view/hooks/useContinuousTap.d.ts +8 -0
- package/esm/components/react-photo-view/hooks/useContinuousTap.js +36 -0
- package/esm/components/react-photo-view/hooks/useDebounceCallback.d.ts +10 -0
- package/esm/components/react-photo-view/hooks/useDebounceCallback.js +48 -0
- package/esm/components/react-photo-view/hooks/useEventListener.d.ts +1 -0
- package/esm/components/react-photo-view/hooks/useEventListener.js +18 -0
- package/esm/components/react-photo-view/hooks/useForkedVariable.d.ts +5 -0
- package/esm/components/react-photo-view/hooks/useForkedVariable.js +17 -0
- package/esm/components/react-photo-view/hooks/useInitial.d.ts +1 -0
- package/esm/components/react-photo-view/hooks/useInitial.js +9 -0
- package/esm/components/react-photo-view/hooks/useIsomorphicLayoutEffect.d.ts +3 -0
- package/esm/components/react-photo-view/hooks/useIsomorphicLayoutEffect.js +3 -0
- package/esm/components/react-photo-view/hooks/useMethods.d.ts +4 -0
- package/esm/components/react-photo-view/hooks/useMethods.js +35 -0
- package/esm/components/react-photo-view/hooks/useMountedRef.d.ts +3 -0
- package/esm/components/react-photo-view/hooks/useMountedRef.js +12 -0
- package/esm/components/react-photo-view/hooks/useScrollPosition.d.ts +4 -0
- package/esm/components/react-photo-view/hooks/useScrollPosition.js +157 -0
- package/esm/components/react-photo-view/hooks/useSetState.d.ts +2 -0
- package/esm/components/react-photo-view/hooks/useSetState.js +15 -0
- package/esm/components/react-photo-view/hooks/useTargetScale.d.ts +4 -0
- package/esm/components/react-photo-view/hooks/useTargetScale.js +70 -0
- package/esm/components/react-photo-view/index.d.ts +4 -0
- package/esm/components/react-photo-view/index.js +4 -0
- package/esm/components/react-photo-view/photo-context.d.ts +11 -0
- package/esm/components/react-photo-view/photo-context.js +2 -0
- package/esm/components/react-photo-view/types.d.ts +196 -0
- package/esm/components/react-photo-view/types.js +1 -0
- package/esm/components/react-photo-view/utils/edgeHandle.d.ts +15 -0
- package/esm/components/react-photo-view/utils/edgeHandle.js +40 -0
- package/esm/components/react-photo-view/utils/getMultipleTouchPosition.d.ts +5 -0
- package/esm/components/react-photo-view/utils/getMultipleTouchPosition.js +11 -0
- package/esm/components/react-photo-view/utils/getPositionOnMoveOrScale.d.ts +9 -0
- package/esm/components/react-photo-view/utils/getPositionOnMoveOrScale.js +31 -0
- package/esm/components/react-photo-view/utils/getRotateSize.d.ts +4 -0
- package/esm/components/react-photo-view/utils/getRotateSize.js +11 -0
- package/esm/components/react-photo-view/utils/getSuitableImageSize.d.ts +10 -0
- package/esm/components/react-photo-view/utils/getSuitableImageSize.js +42 -0
- package/esm/components/react-photo-view/utils/isTouchDevice.d.ts +5 -0
- package/esm/components/react-photo-view/utils/isTouchDevice.js +5 -0
- package/esm/components/react-photo-view/utils/limitTarget.d.ts +5 -0
- package/esm/components/react-photo-view/utils/limitTarget.js +12 -0
- package/esm/components/react-photo-view/variables.d.ts +48 -0
- package/esm/components/react-photo-view/variables.js +48 -0
- package/esm/constants/ai-question.d.ts +9 -0
- package/esm/constants/ai-question.js +33 -4
- package/esm/enum/ai-question.d.ts +5 -2
- package/esm/enum/ai-question.js +3 -0
- package/esm/modules/ai-ability/Root.js +15 -4
- package/esm/modules/ai-ability-select/Root.js +2 -2
- package/esm/modules/ai-ability-select/interface.d.ts +1 -0
- package/esm/modules/ai-question/components/BootVideo/index.js +1 -1
- package/esm/modules/ai-question/components/QuestionModel/Item.js +14 -9
- package/esm/modules/ai-question/components/QuestionTemplate/AiEvaluation.js +10 -5
- package/esm/modules/ai-question/components/QuestionUpdate/Chioce.d.ts +17 -0
- package/esm/modules/ai-question/components/QuestionUpdate/Chioce.js +96 -0
- package/esm/modules/ai-question/components/QuestionUpdate/Form.js +42 -12
- package/esm/modules/ai-question/components/QuestionUpdate/RandomQuestion.js +14 -4
- package/esm/modules/ai-question/components/QuestionUpdate/const.js +4 -0
- package/esm/modules/ai-question/components/QuestionUpdate/index.js +12 -14
- package/esm/modules/ai-question/components/QuestionUpdate/interface.d.ts +8 -0
- package/esm/modules/ai-question/components/QuestionUpdate/styled.d.ts +15 -0
- package/esm/modules/ai-question/components/QuestionUpdate/styled.js +53 -1
- package/esm/modules/ai-report/components/ScoreReport/Score.js +4 -1
- package/esm/modules/ai-report/components/VideoQuestion/BodyImages.d.ts +7 -0
- package/esm/modules/ai-report/components/VideoQuestion/BodyImages.js +40 -0
- package/esm/modules/ai-report/components/VideoQuestion/QuestionItem.js +5 -3
- package/esm/modules/ai-report/components/VideoQuestion/SingleChoice.d.ts +8 -0
- package/esm/modules/ai-report/components/VideoQuestion/SingleChoice.js +25 -0
- package/esm/modules/ai-report/components/VideoQuestion/styled.d.ts +1 -0
- package/esm/modules/ai-report/components/VideoQuestion/styled.js +7 -1
- package/esm/modules/ai-report/interface.d.ts +19 -0
- package/esm/services/ai-ability.d.ts +1 -1
- package/esm/services/ai-ability.js +1 -1
- package/lib/components/react-photo-view/Photo.css +14 -0
- package/lib/components/react-photo-view/Photo.d.ts +18 -0
- package/lib/components/react-photo-view/Photo.js +60 -0
- package/lib/components/react-photo-view/PhotoBox.css +18 -0
- package/lib/components/react-photo-view/PhotoBox.d.ts +22 -0
- package/lib/components/react-photo-view/PhotoBox.js +308 -0
- package/lib/components/react-photo-view/PhotoPage.d.ts +9 -0
- package/lib/components/react-photo-view/PhotoPage.js +79 -0
- package/lib/components/react-photo-view/PhotoProvider.d.ts +14 -0
- package/lib/components/react-photo-view/PhotoProvider.js +104 -0
- package/lib/components/react-photo-view/PhotoSlider.css +125 -0
- package/lib/components/react-photo-view/PhotoSlider.d.ts +12 -0
- package/lib/components/react-photo-view/PhotoSlider.js +268 -0
- package/lib/components/react-photo-view/PhotoView.d.ts +30 -0
- package/lib/components/react-photo-view/PhotoView.js +53 -0
- package/lib/components/react-photo-view/components/ArrowLeft.d.ts +3 -0
- package/lib/components/react-photo-view/components/ArrowLeft.js +20 -0
- package/lib/components/react-photo-view/components/ArrowRight.d.ts +3 -0
- package/lib/components/react-photo-view/components/ArrowRight.js +20 -0
- package/lib/components/react-photo-view/components/CloseIcon.d.ts +3 -0
- package/lib/components/react-photo-view/components/CloseIcon.js +18 -0
- package/lib/components/react-photo-view/components/PreventScroll.d.ts +1 -0
- package/lib/components/react-photo-view/components/PreventScroll.js +15 -0
- package/lib/components/react-photo-view/components/SlidePortal.css +10 -0
- package/lib/components/react-photo-view/components/SlidePortal.d.ts +7 -0
- package/lib/components/react-photo-view/components/SlidePortal.js +32 -0
- package/lib/components/react-photo-view/components/Spinner.css +23 -0
- package/lib/components/react-photo-view/components/Spinner.d.ts +4 -0
- package/lib/components/react-photo-view/components/Spinner.js +31 -0
- package/lib/components/react-photo-view/hooks/useAdjacentImages.d.ts +5 -0
- package/lib/components/react-photo-view/hooks/useAdjacentImages.js +17 -0
- package/lib/components/react-photo-view/hooks/useAnimationOrigin.d.ts +6 -0
- package/lib/components/react-photo-view/hooks/useAnimationOrigin.js +78 -0
- package/lib/components/react-photo-view/hooks/useAnimationPosition.d.ts +2 -0
- package/lib/components/react-photo-view/hooks/useAnimationPosition.js +34 -0
- package/lib/components/react-photo-view/hooks/useAnimationVisible.d.ts +6 -0
- package/lib/components/react-photo-view/hooks/useAnimationVisible.js +55 -0
- package/lib/components/react-photo-view/hooks/useContinuousTap.d.ts +8 -0
- package/lib/components/react-photo-view/hooks/useContinuousTap.js +42 -0
- package/lib/components/react-photo-view/hooks/useDebounceCallback.d.ts +10 -0
- package/lib/components/react-photo-view/hooks/useDebounceCallback.js +51 -0
- package/lib/components/react-photo-view/hooks/useEventListener.d.ts +1 -0
- package/lib/components/react-photo-view/hooks/useEventListener.js +21 -0
- package/lib/components/react-photo-view/hooks/useForkedVariable.d.ts +5 -0
- package/lib/components/react-photo-view/hooks/useForkedVariable.js +20 -0
- package/lib/components/react-photo-view/hooks/useInitial.d.ts +1 -0
- package/lib/components/react-photo-view/hooks/useInitial.js +12 -0
- package/lib/components/react-photo-view/hooks/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib/components/react-photo-view/hooks/useIsomorphicLayoutEffect.js +5 -0
- package/lib/components/react-photo-view/hooks/useMethods.d.ts +4 -0
- package/lib/components/react-photo-view/hooks/useMethods.js +38 -0
- package/lib/components/react-photo-view/hooks/useMountedRef.d.ts +3 -0
- package/lib/components/react-photo-view/hooks/useMountedRef.js +14 -0
- package/lib/components/react-photo-view/hooks/useScrollPosition.d.ts +4 -0
- package/lib/components/react-photo-view/hooks/useScrollPosition.js +163 -0
- package/lib/components/react-photo-view/hooks/useSetState.d.ts +2 -0
- package/lib/components/react-photo-view/hooks/useSetState.js +18 -0
- package/lib/components/react-photo-view/hooks/useTargetScale.d.ts +4 -0
- package/lib/components/react-photo-view/hooks/useTargetScale.js +76 -0
- package/lib/components/react-photo-view/index.d.ts +4 -0
- package/lib/components/react-photo-view/index.js +12 -0
- package/lib/components/react-photo-view/photo-context.d.ts +11 -0
- package/lib/components/react-photo-view/photo-context.js +4 -0
- package/lib/components/react-photo-view/types.d.ts +196 -0
- package/lib/components/react-photo-view/types.js +2 -0
- package/lib/components/react-photo-view/utils/edgeHandle.d.ts +15 -0
- package/lib/components/react-photo-view/utils/edgeHandle.js +45 -0
- package/lib/components/react-photo-view/utils/getMultipleTouchPosition.d.ts +5 -0
- package/lib/components/react-photo-view/utils/getMultipleTouchPosition.js +14 -0
- package/lib/components/react-photo-view/utils/getPositionOnMoveOrScale.d.ts +9 -0
- package/lib/components/react-photo-view/utils/getPositionOnMoveOrScale.js +34 -0
- package/lib/components/react-photo-view/utils/getRotateSize.d.ts +4 -0
- package/lib/components/react-photo-view/utils/getRotateSize.js +14 -0
- package/lib/components/react-photo-view/utils/getSuitableImageSize.d.ts +10 -0
- package/lib/components/react-photo-view/utils/getSuitableImageSize.js +48 -0
- package/lib/components/react-photo-view/utils/isTouchDevice.d.ts +5 -0
- package/lib/components/react-photo-view/utils/isTouchDevice.js +7 -0
- package/lib/components/react-photo-view/utils/limitTarget.d.ts +5 -0
- package/lib/components/react-photo-view/utils/limitTarget.js +17 -0
- package/lib/components/react-photo-view/variables.d.ts +48 -0
- package/lib/components/react-photo-view/variables.js +51 -0
- package/lib/constants/ai-question.d.ts +9 -0
- package/lib/constants/ai-question.js +34 -5
- package/lib/enum/ai-question.d.ts +5 -2
- package/lib/enum/ai-question.js +3 -0
- package/lib/modules/ai-ability/Root.js +15 -4
- package/lib/modules/ai-ability-select/Root.js +2 -2
- package/lib/modules/ai-ability-select/interface.d.ts +1 -0
- package/lib/modules/ai-question/components/BootVideo/index.js +1 -1
- package/lib/modules/ai-question/components/QuestionModel/Item.js +11 -6
- package/lib/modules/ai-question/components/QuestionTemplate/AiEvaluation.js +8 -3
- package/lib/modules/ai-question/components/QuestionUpdate/Chioce.d.ts +17 -0
- package/lib/modules/ai-question/components/QuestionUpdate/Chioce.js +103 -0
- package/lib/modules/ai-question/components/QuestionUpdate/Form.js +40 -10
- package/lib/modules/ai-question/components/QuestionUpdate/RandomQuestion.js +12 -2
- package/lib/modules/ai-question/components/QuestionUpdate/const.js +4 -0
- package/lib/modules/ai-question/components/QuestionUpdate/index.js +11 -13
- package/lib/modules/ai-question/components/QuestionUpdate/interface.d.ts +8 -0
- package/lib/modules/ai-question/components/QuestionUpdate/styled.d.ts +15 -0
- package/lib/modules/ai-question/components/QuestionUpdate/styled.js +53 -1
- package/lib/modules/ai-report/components/ScoreReport/Score.js +4 -1
- package/lib/modules/ai-report/components/VideoQuestion/BodyImages.d.ts +7 -0
- package/lib/modules/ai-report/components/VideoQuestion/BodyImages.js +45 -0
- package/lib/modules/ai-report/components/VideoQuestion/QuestionItem.js +4 -2
- package/lib/modules/ai-report/components/VideoQuestion/SingleChoice.d.ts +8 -0
- package/lib/modules/ai-report/components/VideoQuestion/SingleChoice.js +27 -0
- package/lib/modules/ai-report/components/VideoQuestion/styled.d.ts +1 -0
- package/lib/modules/ai-report/components/VideoQuestion/styled.js +8 -2
- package/lib/modules/ai-report/interface.d.ts +19 -0
- package/lib/services/ai-ability.d.ts +1 -1
- package/lib/services/ai-ability.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var react_1 = require("react");
|
|
7
|
+
var variables_1 = require("../variables");
|
|
8
|
+
var useMethods_1 = __importDefault(require("./useMethods"));
|
|
9
|
+
var initialRect = {
|
|
10
|
+
T: 0,
|
|
11
|
+
L: 0,
|
|
12
|
+
W: 0,
|
|
13
|
+
H: 0,
|
|
14
|
+
// 图像填充方式
|
|
15
|
+
FIT: undefined,
|
|
16
|
+
};
|
|
17
|
+
function useAnimationOrigin(visible, originRef, loaded, speed, updateEasing) {
|
|
18
|
+
var _a = (0, react_1.useState)(initialRect), originRect = _a[0], updateOriginRect = _a[1];
|
|
19
|
+
// 动画状态
|
|
20
|
+
var _b = (0, react_1.useState)(0), easingMode = _b[0], updateEasingMode = _b[1];
|
|
21
|
+
var initialTime = (0, react_1.useRef)();
|
|
22
|
+
var fn = (0, useMethods_1.default)({
|
|
23
|
+
OK: function () { return visible && updateEasingMode(4); },
|
|
24
|
+
});
|
|
25
|
+
(0, react_1.useEffect)(function () {
|
|
26
|
+
// 记录初始打开的时间
|
|
27
|
+
if (!initialTime.current) {
|
|
28
|
+
initialTime.current = Date.now();
|
|
29
|
+
}
|
|
30
|
+
if (!loaded) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
handleUpdateOrigin(originRef, updateOriginRect);
|
|
34
|
+
// 打开动画处理
|
|
35
|
+
if (visible) {
|
|
36
|
+
// 小于最大允许动画时间,则执行缩放动画
|
|
37
|
+
if (Date.now() - initialTime.current < variables_1.maxWaitAnimationTime) {
|
|
38
|
+
updateEasingMode(1);
|
|
39
|
+
// 延时执行动画,保持 transition 生效
|
|
40
|
+
requestAnimationFrame(function () {
|
|
41
|
+
updateEasingMode(2);
|
|
42
|
+
requestAnimationFrame(function () { return handleToShape(3); });
|
|
43
|
+
});
|
|
44
|
+
setTimeout(fn.OK, speed);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// 超出则不执行
|
|
48
|
+
updateEasingMode(4);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// 关闭动画处理
|
|
52
|
+
handleToShape(5);
|
|
53
|
+
}, [visible, loaded]);
|
|
54
|
+
function handleToShape(currentShape) {
|
|
55
|
+
updateEasing(false);
|
|
56
|
+
updateEasingMode(currentShape);
|
|
57
|
+
}
|
|
58
|
+
return [easingMode, originRect];
|
|
59
|
+
}
|
|
60
|
+
exports.default = useAnimationOrigin;
|
|
61
|
+
/**
|
|
62
|
+
* 更新缩略图位置信息
|
|
63
|
+
*/
|
|
64
|
+
function handleUpdateOrigin(originRef, updateOriginRect) {
|
|
65
|
+
var element = originRef && originRef.current;
|
|
66
|
+
if (element && element.nodeType === 1) {
|
|
67
|
+
// 获取触发时节点位置
|
|
68
|
+
var _a = element.getBoundingClientRect(), top_1 = _a.top, left = _a.left, width = _a.width, height = _a.height;
|
|
69
|
+
var isImage = element.tagName === 'IMG';
|
|
70
|
+
updateOriginRect({
|
|
71
|
+
T: top_1,
|
|
72
|
+
L: left,
|
|
73
|
+
W: width,
|
|
74
|
+
H: height,
|
|
75
|
+
FIT: isImage ? getComputedStyle(element).objectFit : undefined,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
export default function useAnimationPosition(visible: boolean | undefined, originRef: MutableRefObject<HTMLElement | null> | undefined, loaded: boolean, x: number, y: number, width: number, height: number, scale: number, speed: number, updateEasing: (pause: boolean) => void): readonly [number, number, number, number, number, 0 | 1, import("../types").EasingMode, "fill" | "contain" | "cover" | undefined];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var useAnimationOrigin_1 = __importDefault(require("./useAnimationOrigin"));
|
|
7
|
+
var useTargetScale_1 = __importDefault(require("./useTargetScale"));
|
|
8
|
+
function useAnimationPosition(visible, originRef, loaded, x, y, width, height, scale, speed, updateEasing) {
|
|
9
|
+
// 延迟更新 width/height
|
|
10
|
+
var _a = (0, useTargetScale_1.default)(width, height, scale, speed, updateEasing), autoWidth = _a[0], autoHeight = _a[1], autoScale = _a[2];
|
|
11
|
+
// 动画源处理
|
|
12
|
+
var _b = (0, useAnimationOrigin_1.default)(visible, originRef, loaded, speed, updateEasing), easingMode = _b[0], originRect = _b[1];
|
|
13
|
+
// 计算动画位置
|
|
14
|
+
var T = originRect.T, L = originRect.L, W = originRect.W, H = originRect.H, FIT = originRect.FIT;
|
|
15
|
+
// 偏移量,x: 0, y: 0 居中为初始
|
|
16
|
+
var centerWidth = window.innerWidth / 2;
|
|
17
|
+
var centerHeight = window.innerHeight / 2;
|
|
18
|
+
var offsetX = centerWidth - (width * scale) / 2;
|
|
19
|
+
var offsetY = centerHeight - (height * scale) / 2;
|
|
20
|
+
// 缩略图状态
|
|
21
|
+
var miniMode = easingMode < 3 || easingMode > 4;
|
|
22
|
+
// 有缩略图时,则为缩略图的位置,否则居中
|
|
23
|
+
var translateX = miniMode ? (W ? L : centerWidth) : x + offsetX;
|
|
24
|
+
var translateY = miniMode ? (W ? T : centerHeight) : y + offsetY;
|
|
25
|
+
// 最小值缩放
|
|
26
|
+
var minScale = W / (width * scale) || 0.01;
|
|
27
|
+
// 适应 objectFit 保持缩略图宽高比
|
|
28
|
+
var currentHeight = miniMode && FIT ? autoWidth * (H / W) : autoHeight;
|
|
29
|
+
// 初始加载情况无缩放
|
|
30
|
+
var currentScale = easingMode === 0 ? autoScale : miniMode ? minScale : autoScale;
|
|
31
|
+
var opacity = miniMode ? (FIT ? 1 : 0) : 1;
|
|
32
|
+
return [translateX, translateY, autoWidth, currentHeight, currentScale, opacity, easingMode, FIT];
|
|
33
|
+
}
|
|
34
|
+
exports.default = useAnimationPosition;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ActiveAnimationType } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 动画关闭处理真实关闭状态
|
|
4
|
+
* 通过 onAnimationEnd 回调实现 leaveCallback
|
|
5
|
+
*/
|
|
6
|
+
export default function useAnimationVisible(visible: boolean | undefined, afterClose?: () => void): [realVisible: boolean | undefined, activeAnimation: ActiveAnimationType, onAnimationEnd: () => void];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var react_1 = require("react");
|
|
7
|
+
var useForkedVariable_1 = __importDefault(require("./useForkedVariable"));
|
|
8
|
+
/**
|
|
9
|
+
* 动画关闭处理真实关闭状态
|
|
10
|
+
* 通过 onAnimationEnd 回调实现 leaveCallback
|
|
11
|
+
*/
|
|
12
|
+
function useAnimationVisible(visible, afterClose) {
|
|
13
|
+
var _a = (0, react_1.useReducer)(function (c) { return !c; }, false), handleRender = _a[1];
|
|
14
|
+
var activeAnimation = (0, react_1.useRef)(0);
|
|
15
|
+
// 可见状态分支
|
|
16
|
+
var _b = (0, useForkedVariable_1.default)(visible, function (modify) {
|
|
17
|
+
// 可见状态:设置进入动画
|
|
18
|
+
if (visible) {
|
|
19
|
+
modify(visible);
|
|
20
|
+
activeAnimation.current = 1;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
activeAnimation.current = 2;
|
|
24
|
+
}
|
|
25
|
+
}), realVisible = _b[0], modifyRealVisible = _b[1];
|
|
26
|
+
function onAnimationEnd() {
|
|
27
|
+
// 动画结束后触发渲染
|
|
28
|
+
handleRender();
|
|
29
|
+
// 结束动画:设置隐藏状态
|
|
30
|
+
if (activeAnimation.current === 2) {
|
|
31
|
+
modifyRealVisible(false);
|
|
32
|
+
// 触发隐藏回调
|
|
33
|
+
if (afterClose) {
|
|
34
|
+
afterClose();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// 重置状态
|
|
38
|
+
activeAnimation.current = 0;
|
|
39
|
+
}
|
|
40
|
+
return [
|
|
41
|
+
/**
|
|
42
|
+
* 真实可见状态
|
|
43
|
+
*/
|
|
44
|
+
realVisible,
|
|
45
|
+
/**
|
|
46
|
+
* 正在进行的动画
|
|
47
|
+
*/
|
|
48
|
+
activeAnimation.current,
|
|
49
|
+
/**
|
|
50
|
+
* 动画结束后回调
|
|
51
|
+
*/
|
|
52
|
+
onAnimationEnd,
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
exports.default = useAnimationVisible;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare type TapFuncType<T> = (...args: T[]) => void;
|
|
2
|
+
/**
|
|
3
|
+
* 单击和双击事件处理
|
|
4
|
+
* @param singleTap - 单击事件
|
|
5
|
+
* @param doubleTap - 双击事件
|
|
6
|
+
* @return invokeTap
|
|
7
|
+
*/
|
|
8
|
+
export default function useContinuousTap<T>(singleTap: TapFuncType<T>, doubleTap: TapFuncType<T>): TapFuncType<T>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var react_1 = require("react");
|
|
7
|
+
var useDebounceCallback_1 = __importDefault(require("./useDebounceCallback"));
|
|
8
|
+
/**
|
|
9
|
+
* 单击和双击事件处理
|
|
10
|
+
* @param singleTap - 单击事件
|
|
11
|
+
* @param doubleTap - 双击事件
|
|
12
|
+
* @return invokeTap
|
|
13
|
+
*/
|
|
14
|
+
function useContinuousTap(singleTap, doubleTap) {
|
|
15
|
+
// 当前连续点击次数
|
|
16
|
+
var continuousClick = (0, react_1.useRef)(0);
|
|
17
|
+
var debounceTap = (0, useDebounceCallback_1.default)(function () {
|
|
18
|
+
var args = [];
|
|
19
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
20
|
+
args[_i] = arguments[_i];
|
|
21
|
+
}
|
|
22
|
+
continuousClick.current = 0;
|
|
23
|
+
singleTap.apply(void 0, args);
|
|
24
|
+
}, {
|
|
25
|
+
wait: 300,
|
|
26
|
+
});
|
|
27
|
+
return function invokeTap() {
|
|
28
|
+
var args = [];
|
|
29
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
30
|
+
args[_i] = arguments[_i];
|
|
31
|
+
}
|
|
32
|
+
continuousClick.current += 1;
|
|
33
|
+
debounceTap.apply(void 0, args);
|
|
34
|
+
// 双击
|
|
35
|
+
if (continuousClick.current >= 2) {
|
|
36
|
+
debounceTap.cancel();
|
|
37
|
+
continuousClick.current = 0;
|
|
38
|
+
doubleTap.apply(void 0, args);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.default = useContinuousTap;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface DebounceCallback<CallbackArguments extends any[]> {
|
|
2
|
+
(...args: CallbackArguments): void;
|
|
3
|
+
cancel: () => void;
|
|
4
|
+
}
|
|
5
|
+
export default function useDebounceCallback<CallbackArguments extends any[]>(callback: (...args: CallbackArguments) => void, { leading, maxWait, wait, }: {
|
|
6
|
+
leading?: boolean;
|
|
7
|
+
maxWait?: number;
|
|
8
|
+
wait?: number;
|
|
9
|
+
}): DebounceCallback<CallbackArguments>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var react_1 = require("react");
|
|
4
|
+
function useDebounceCallback(callback, _a) {
|
|
5
|
+
var _b = _a.leading, leading = _b === void 0 ? false : _b, maxWait = _a.maxWait, _c = _a.wait, wait = _c === void 0 ? maxWait || 0 : _c;
|
|
6
|
+
var callbackRef = (0, react_1.useRef)(callback);
|
|
7
|
+
callbackRef.current = callback;
|
|
8
|
+
var prev = (0, react_1.useRef)(0);
|
|
9
|
+
var trailingTimeout = (0, react_1.useRef)();
|
|
10
|
+
var clearTrailing = function () { return trailingTimeout.current && clearTimeout(trailingTimeout.current); };
|
|
11
|
+
var fn = (0, react_1.useCallback)(function () {
|
|
12
|
+
var args = [];
|
|
13
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
14
|
+
args[_i] = arguments[_i];
|
|
15
|
+
}
|
|
16
|
+
var now = Date.now();
|
|
17
|
+
function call() {
|
|
18
|
+
prev.current = now;
|
|
19
|
+
clearTrailing();
|
|
20
|
+
callbackRef.current.apply(null, args);
|
|
21
|
+
}
|
|
22
|
+
var last = prev.current;
|
|
23
|
+
var offset = now - last;
|
|
24
|
+
// leading
|
|
25
|
+
if (last === 0) {
|
|
26
|
+
if (leading) {
|
|
27
|
+
call();
|
|
28
|
+
}
|
|
29
|
+
prev.current = now;
|
|
30
|
+
}
|
|
31
|
+
// body
|
|
32
|
+
if (maxWait !== undefined) {
|
|
33
|
+
if (offset > maxWait) {
|
|
34
|
+
call();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (offset < wait) {
|
|
39
|
+
prev.current = now;
|
|
40
|
+
}
|
|
41
|
+
// trailing
|
|
42
|
+
clearTrailing();
|
|
43
|
+
trailingTimeout.current = setTimeout(function () {
|
|
44
|
+
call();
|
|
45
|
+
prev.current = 0;
|
|
46
|
+
}, wait);
|
|
47
|
+
}, [wait, maxWait, leading]);
|
|
48
|
+
fn.cancel = clearTrailing;
|
|
49
|
+
return fn;
|
|
50
|
+
}
|
|
51
|
+
exports.default = useDebounceCallback;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useEventListener<K extends keyof WindowEventMap>(type: K | undefined, fn: (evt: WindowEventMap[K]) => void, options?: AddEventListenerOptions): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var react_1 = require("react");
|
|
4
|
+
function useEventListener(type, fn, options) {
|
|
5
|
+
var latest = (0, react_1.useRef)(fn);
|
|
6
|
+
latest.current = fn;
|
|
7
|
+
(0, react_1.useEffect)(function () {
|
|
8
|
+
function wrapper(evt) {
|
|
9
|
+
latest.current(evt);
|
|
10
|
+
}
|
|
11
|
+
if (type) {
|
|
12
|
+
window.addEventListener(type, wrapper, options);
|
|
13
|
+
}
|
|
14
|
+
return function () {
|
|
15
|
+
if (type) {
|
|
16
|
+
window.removeEventListener(type, wrapper);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}, [type]);
|
|
20
|
+
}
|
|
21
|
+
exports.default = useEventListener;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var react_1 = require("react");
|
|
4
|
+
/**
|
|
5
|
+
* 逻辑分叉变量处理
|
|
6
|
+
* 此 hook 不触发额外渲染
|
|
7
|
+
*/
|
|
8
|
+
function useForkedVariable(initial, updater) {
|
|
9
|
+
// 初始分叉变量
|
|
10
|
+
var forkedRef = (0, react_1.useRef)(initial);
|
|
11
|
+
function modify(next) {
|
|
12
|
+
forkedRef.current = next;
|
|
13
|
+
}
|
|
14
|
+
(0, react_1.useMemo)(function () {
|
|
15
|
+
// 参数变化之后同步内部分叉变量
|
|
16
|
+
updater(modify);
|
|
17
|
+
}, [initial]);
|
|
18
|
+
return [forkedRef.current, modify];
|
|
19
|
+
}
|
|
20
|
+
exports.default = useForkedVariable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useInitial<T extends (...args: any) => any>(callback: T): ReturnType<T>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var react_1 = require("react");
|
|
4
|
+
function useInitial(callback) {
|
|
5
|
+
var current = (0, react_1.useRef)({ sign: false, fn: undefined }).current;
|
|
6
|
+
if (!current.sign) {
|
|
7
|
+
current.sign = true;
|
|
8
|
+
current.fn = callback();
|
|
9
|
+
}
|
|
10
|
+
return current.fn;
|
|
11
|
+
}
|
|
12
|
+
exports.default = useInitial;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var react_1 = require("react");
|
|
4
|
+
var isSSR = typeof window === 'undefined' || /ServerSideRendering/.test(navigator && navigator.userAgent);
|
|
5
|
+
exports.default = isSSR ? react_1.useEffect : react_1.useLayoutEffect;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
var react_1 = require("react");
|
|
13
|
+
/**
|
|
14
|
+
* Hook of persistent methods
|
|
15
|
+
*/
|
|
16
|
+
function useMethods(fn) {
|
|
17
|
+
var current = (0, react_1.useRef)({
|
|
18
|
+
fn: fn,
|
|
19
|
+
curr: undefined,
|
|
20
|
+
}).current;
|
|
21
|
+
current.fn = fn;
|
|
22
|
+
if (!current.curr) {
|
|
23
|
+
var curr_1 = Object.create(null);
|
|
24
|
+
Object.keys(fn).forEach(function (key) {
|
|
25
|
+
curr_1[key] = function () {
|
|
26
|
+
var _a;
|
|
27
|
+
var args = [];
|
|
28
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
29
|
+
args[_i] = arguments[_i];
|
|
30
|
+
}
|
|
31
|
+
return (_a = current.fn[key]).call.apply(_a, __spreadArray([current.fn], args, false));
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
current.curr = curr_1;
|
|
35
|
+
}
|
|
36
|
+
return current.curr;
|
|
37
|
+
}
|
|
38
|
+
exports.default = useMethods;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var react_1 = require("react");
|
|
4
|
+
var useMountedRef = function () {
|
|
5
|
+
var mountedRef = (0, react_1.useRef)(false);
|
|
6
|
+
(0, react_1.useEffect)(function () {
|
|
7
|
+
mountedRef.current = true;
|
|
8
|
+
return function () {
|
|
9
|
+
mountedRef.current = false;
|
|
10
|
+
};
|
|
11
|
+
}, []);
|
|
12
|
+
return mountedRef;
|
|
13
|
+
};
|
|
14
|
+
exports.default = useMountedRef;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 物理滚动到具体位置
|
|
3
|
+
*/
|
|
4
|
+
export default function useScrollPosition<C extends (spatial: number) => boolean>(callbackX: C, callbackY: C, callbackS: C): (x: number, y: number, lastX: number, lastY: number, width: number, height: number, scale: number, safeScale: number, lastScale: number, rotate: number, touchedTime: number) => void;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var edgeHandle_1 = require("../utils/edgeHandle");
|
|
7
|
+
var getPositionOnMoveOrScale_1 = __importDefault(require("../utils/getPositionOnMoveOrScale"));
|
|
8
|
+
var getRotateSize_1 = __importDefault(require("../utils/getRotateSize"));
|
|
9
|
+
var variables_1 = require("../variables");
|
|
10
|
+
var useMethods_1 = __importDefault(require("./useMethods"));
|
|
11
|
+
// 触边运动反馈
|
|
12
|
+
var rebound = function (start, bound, callback) {
|
|
13
|
+
return easeOutMove(start, bound, callback, variables_1.defaultSpeed / 4, function (t) { return t; }, function () { return easeOutMove(bound, start, callback); });
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* 物理滚动到具体位置
|
|
17
|
+
*/
|
|
18
|
+
function useScrollPosition(callbackX, callbackY, callbackS) {
|
|
19
|
+
var callback = (0, useMethods_1.default)({
|
|
20
|
+
X: function (spatial) { return callbackX(spatial); },
|
|
21
|
+
Y: function (spatial) { return callbackY(spatial); },
|
|
22
|
+
S: function (spatial) { return callbackS(spatial); },
|
|
23
|
+
});
|
|
24
|
+
return function (x, y, lastX, lastY, width, height, scale, safeScale, lastScale, rotate, touchedTime) {
|
|
25
|
+
var _a = (0, getRotateSize_1.default)(rotate, width, height), currentWidth = _a[0], currentHeight = _a[1];
|
|
26
|
+
// 开始状态下边缘触发状态
|
|
27
|
+
var _b = (0, edgeHandle_1.computePositionEdge)(x, safeScale, currentWidth, window.innerWidth), beginEdgeX = _b[0], beginX = _b[1];
|
|
28
|
+
var _c = (0, edgeHandle_1.computePositionEdge)(y, safeScale, currentHeight, window.innerHeight), beginEdgeY = _c[0], beginY = _c[1];
|
|
29
|
+
var moveTime = Date.now() - touchedTime;
|
|
30
|
+
// 时间过长、超出安全范围的情况下不执行滚动逻辑,恢复安全范围
|
|
31
|
+
if (moveTime >= variables_1.maxTouchTime || safeScale !== scale || Math.abs(lastScale - scale) > 1) {
|
|
32
|
+
// 计算中心缩放点
|
|
33
|
+
var _d = (0, getPositionOnMoveOrScale_1.default)(x, y, width, height, scale, safeScale), nextX = _d.x, nextY = _d.y;
|
|
34
|
+
var targetX = beginEdgeX ? beginX : nextX !== x ? nextX : null;
|
|
35
|
+
var targetY = beginEdgeY ? beginY : nextY !== y ? nextY : null;
|
|
36
|
+
if (targetX !== null) {
|
|
37
|
+
easeOutMove(x, targetX, callback.X);
|
|
38
|
+
}
|
|
39
|
+
if (targetY !== null) {
|
|
40
|
+
easeOutMove(y, targetY, callback.Y);
|
|
41
|
+
}
|
|
42
|
+
if (safeScale !== scale) {
|
|
43
|
+
easeOutMove(scale, safeScale, callback.S);
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// 初始速度
|
|
48
|
+
var speedX = (x - lastX) / moveTime;
|
|
49
|
+
var speedY = (y - lastY) / moveTime;
|
|
50
|
+
var speedT = Math.sqrt(Math.pow(speedX, 2) + Math.pow(speedY, 2));
|
|
51
|
+
// 是否接触到边缘
|
|
52
|
+
var edgeX = false;
|
|
53
|
+
var edgeY = false;
|
|
54
|
+
scrollMove(speedT, function (spatial) {
|
|
55
|
+
var nextX = x + spatial * (speedX / speedT);
|
|
56
|
+
var nextY = y + spatial * (speedY / speedT);
|
|
57
|
+
var _a = (0, edgeHandle_1.computePositionEdge)(nextX, scale, currentWidth, window.innerWidth), isEdgeX = _a[0], currentX = _a[1];
|
|
58
|
+
var _b = (0, edgeHandle_1.computePositionEdge)(nextY, scale, currentHeight, window.innerHeight), isEdgeY = _b[0], currentY = _b[1];
|
|
59
|
+
if (isEdgeX && !edgeX) {
|
|
60
|
+
edgeX = true;
|
|
61
|
+
if (beginEdgeX) {
|
|
62
|
+
easeOutMove(nextX, currentX, callback.X);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
rebound(currentX, nextX + (nextX - currentX), callback.X);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (isEdgeY && !edgeY) {
|
|
69
|
+
edgeY = true;
|
|
70
|
+
if (beginEdgeY) {
|
|
71
|
+
easeOutMove(nextY, currentY, callback.Y);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
rebound(currentY, nextY + (nextY - currentY), callback.Y);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// 同时接触边缘的情况下停止滚动
|
|
78
|
+
if (edgeX && edgeY) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
var resultX = edgeX || callback.X(currentX);
|
|
82
|
+
var resultY = edgeY || callback.Y(currentY);
|
|
83
|
+
return resultX && resultY;
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.default = useScrollPosition;
|
|
88
|
+
// 加速度
|
|
89
|
+
var acceleration = -0.001;
|
|
90
|
+
// 阻力
|
|
91
|
+
var resistance = 0.0002;
|
|
92
|
+
/**
|
|
93
|
+
* 通过速度滚动到停止
|
|
94
|
+
*/
|
|
95
|
+
function scrollMove(initialSpeed, callback) {
|
|
96
|
+
var v = initialSpeed;
|
|
97
|
+
var s = 0;
|
|
98
|
+
var lastTime = undefined;
|
|
99
|
+
var frameId = 0;
|
|
100
|
+
var calcMove = function (now) {
|
|
101
|
+
if (!lastTime) {
|
|
102
|
+
lastTime = now;
|
|
103
|
+
}
|
|
104
|
+
var dt = now - lastTime;
|
|
105
|
+
var direction = Math.sign(initialSpeed);
|
|
106
|
+
var a = direction * acceleration;
|
|
107
|
+
var f = Math.sign(-v) * Math.pow(v, 2) * resistance;
|
|
108
|
+
var ds = v * dt + ((a + f) * Math.pow(dt, 2)) / 2;
|
|
109
|
+
v = v + (a + f) * dt;
|
|
110
|
+
s = s + ds;
|
|
111
|
+
// move to s
|
|
112
|
+
lastTime = now;
|
|
113
|
+
if (direction * v <= 0) {
|
|
114
|
+
caf();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (callback(s)) {
|
|
118
|
+
raf();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
caf();
|
|
122
|
+
};
|
|
123
|
+
raf();
|
|
124
|
+
function raf() {
|
|
125
|
+
frameId = requestAnimationFrame(calcMove);
|
|
126
|
+
}
|
|
127
|
+
function caf() {
|
|
128
|
+
cancelAnimationFrame(frameId);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 缓动函数
|
|
133
|
+
*/
|
|
134
|
+
var easeOutQuart = function (x) { return 1 - Math.pow((1 - x), 4); };
|
|
135
|
+
/**
|
|
136
|
+
* 缓动回调
|
|
137
|
+
*/
|
|
138
|
+
function easeOutMove(start, end, callback, speed, easing, complete) {
|
|
139
|
+
if (speed === void 0) { speed = variables_1.defaultSpeed; }
|
|
140
|
+
if (easing === void 0) { easing = easeOutQuart; }
|
|
141
|
+
var distance = end - start;
|
|
142
|
+
if (distance === 0) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
var startTime = Date.now();
|
|
146
|
+
var frameId = 0;
|
|
147
|
+
var calcMove = function () {
|
|
148
|
+
var time = Math.min(1, (Date.now() - startTime) / speed);
|
|
149
|
+
var result = callback(start + easing(time) * distance);
|
|
150
|
+
if (result && time < 1) {
|
|
151
|
+
raf();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
cancelAnimationFrame(frameId);
|
|
155
|
+
if (time >= 1 && complete) {
|
|
156
|
+
complete();
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
raf();
|
|
160
|
+
function raf() {
|
|
161
|
+
frameId = requestAnimationFrame(calcMove);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var react_1 = require("react");
|
|
15
|
+
function useSetState(initialState) {
|
|
16
|
+
return (0, react_1.useReducer)(function (state, action) { return (__assign(__assign({}, state), (typeof action === 'function' ? action(state) : action))); }, initialState);
|
|
17
|
+
}
|
|
18
|
+
exports.default = useSetState;
|