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,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './Photo.css';
|
|
3
|
+
import type { BrokenElementParams } from './types';
|
|
4
|
+
export interface IPhotoLoadedParams {
|
|
5
|
+
loaded?: boolean;
|
|
6
|
+
naturalWidth?: number;
|
|
7
|
+
naturalHeight?: number;
|
|
8
|
+
broken?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface IPhotoProps extends React.HTMLAttributes<HTMLElement> {
|
|
11
|
+
src: string;
|
|
12
|
+
loaded: boolean;
|
|
13
|
+
broken: boolean;
|
|
14
|
+
onPhotoLoad: (params: IPhotoLoadedParams) => void;
|
|
15
|
+
loadingElement?: JSX.Element;
|
|
16
|
+
brokenElement?: JSX.Element | ((photoProps: BrokenElementParams) => JSX.Element);
|
|
17
|
+
}
|
|
18
|
+
export default function Photo({ src, loaded, broken, className, onPhotoLoad, loadingElement, brokenElement, ...restProps }: IPhotoProps): JSX.Element | null;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
|
+
import Spinner from './components/Spinner';
|
|
25
|
+
import useMountedRef from './hooks/useMountedRef';
|
|
26
|
+
import './Photo.css';
|
|
27
|
+
export default function Photo(_a) {
|
|
28
|
+
var src = _a.src, loaded = _a.loaded, broken = _a.broken, className = _a.className, onPhotoLoad = _a.onPhotoLoad, loadingElement = _a.loadingElement, brokenElement = _a.brokenElement, restProps = __rest(_a, ["src", "loaded", "broken", "className", "onPhotoLoad", "loadingElement", "brokenElement"]);
|
|
29
|
+
var mountedRef = useMountedRef();
|
|
30
|
+
function handleImageLoaded(e) {
|
|
31
|
+
var _a = e.target, naturalWidth = _a.naturalWidth, naturalHeight = _a.naturalHeight;
|
|
32
|
+
if (mountedRef.current) {
|
|
33
|
+
onPhotoLoad({
|
|
34
|
+
loaded: true,
|
|
35
|
+
naturalWidth: naturalWidth,
|
|
36
|
+
naturalHeight: naturalHeight,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function handleImageBroken() {
|
|
41
|
+
if (mountedRef.current) {
|
|
42
|
+
onPhotoLoad({
|
|
43
|
+
broken: true,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (src && !broken) {
|
|
48
|
+
return (_jsxs(_Fragment, { children: [_jsx("img", __assign({ className: "PhotoView__Photo".concat(className ? " ".concat(className) : ''), src: src, onLoad: handleImageLoaded, onError: handleImageBroken, alt: "" }, restProps)), !loaded && (_jsx("span", __assign({ className: "PhotoView__icon" }, { children: loadingElement })) || _jsx(Spinner, { className: "PhotoView__icon" }))] }));
|
|
49
|
+
}
|
|
50
|
+
if (brokenElement) {
|
|
51
|
+
return _jsx("span", __assign({ className: "PhotoView__icon" }, { children: typeof brokenElement === 'function' ? brokenElement({ src: src }) : brokenElement }));
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.PhotoView__PhotoWrap,
|
|
2
|
+
.PhotoView__PhotoBox {
|
|
3
|
+
position: absolute;
|
|
4
|
+
top: 24px;
|
|
5
|
+
right: 0;
|
|
6
|
+
bottom: 182px;
|
|
7
|
+
left: 0;
|
|
8
|
+
width: 100%;
|
|
9
|
+
touch-action: none;
|
|
10
|
+
direction: ltr;
|
|
11
|
+
}
|
|
12
|
+
.PhotoView__PhotoWrap {
|
|
13
|
+
z-index: 10;
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
}
|
|
16
|
+
.PhotoView__PhotoBox {
|
|
17
|
+
transform-origin: left top;
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import './PhotoBox.css';
|
|
3
|
+
import type { BrokenElementParams, DataType, ExposedProperties, PhotoTapFunction, ReachFunction, ReachMoveFunction } from './types';
|
|
4
|
+
export interface PhotoBoxProps {
|
|
5
|
+
item: DataType;
|
|
6
|
+
visible: boolean;
|
|
7
|
+
speed: number;
|
|
8
|
+
easing: string;
|
|
9
|
+
wrapClassName?: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: object;
|
|
12
|
+
loadingElement?: JSX.Element;
|
|
13
|
+
brokenElement?: JSX.Element | ((photoProps: BrokenElementParams) => JSX.Element);
|
|
14
|
+
onPhotoTap: PhotoTapFunction;
|
|
15
|
+
onMaskTap: PhotoTapFunction;
|
|
16
|
+
onReachMove: ReachMoveFunction;
|
|
17
|
+
onReachUp: ReachFunction;
|
|
18
|
+
onPhotoResize: () => void;
|
|
19
|
+
expose: (state: ExposedProperties) => void;
|
|
20
|
+
isActive: boolean;
|
|
21
|
+
}
|
|
22
|
+
export default function PhotoBox({ item: { src, render, width: customWidth, height: customHeight, originRef }, visible, speed, easing, wrapClassName, className, style, loadingElement, brokenElement, onPhotoTap, onMaskTap, onReachMove, onReachUp, onPhotoResize, isActive, expose, }: PhotoBoxProps): JSX.Element;
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { useRef } from 'react';
|
|
14
|
+
import useAnimationPosition from './hooks/useAnimationPosition';
|
|
15
|
+
import useContinuousTap from './hooks/useContinuousTap';
|
|
16
|
+
import useDebounceCallback from './hooks/useDebounceCallback';
|
|
17
|
+
import useEventListener from './hooks/useEventListener';
|
|
18
|
+
import useIsomorphicLayoutEffect from './hooks/useIsomorphicLayoutEffect';
|
|
19
|
+
import useMethods from './hooks/useMethods';
|
|
20
|
+
import useMountedRef from './hooks/useMountedRef';
|
|
21
|
+
import useScrollPosition from './hooks/useScrollPosition';
|
|
22
|
+
import useSetState from './hooks/useSetState';
|
|
23
|
+
import Photo from './Photo';
|
|
24
|
+
import './PhotoBox.css';
|
|
25
|
+
import { computePositionEdge, getReachType } from './utils/edgeHandle';
|
|
26
|
+
import getMultipleTouchPosition from './utils/getMultipleTouchPosition';
|
|
27
|
+
import getPositionOnMoveOrScale from './utils/getPositionOnMoveOrScale';
|
|
28
|
+
import getRotateSize from './utils/getRotateSize';
|
|
29
|
+
import getSuitableImageSize from './utils/getSuitableImageSize';
|
|
30
|
+
import isTouchDevice from './utils/isTouchDevice';
|
|
31
|
+
import { limitScale } from './utils/limitTarget';
|
|
32
|
+
import { minStartTouchOffset, scaleBuffer } from './variables';
|
|
33
|
+
var initialState = {
|
|
34
|
+
// 真实宽度
|
|
35
|
+
naturalWidth: undefined,
|
|
36
|
+
// 真实高度
|
|
37
|
+
naturalHeight: undefined,
|
|
38
|
+
// 宽度
|
|
39
|
+
width: undefined,
|
|
40
|
+
// 高度
|
|
41
|
+
height: undefined,
|
|
42
|
+
// 加载成功状态
|
|
43
|
+
loaded: undefined,
|
|
44
|
+
// 破碎状态
|
|
45
|
+
broken: false,
|
|
46
|
+
// 图片 X 偏移量
|
|
47
|
+
x: 0,
|
|
48
|
+
// 图片 y 偏移量
|
|
49
|
+
y: 0,
|
|
50
|
+
// 图片处于触摸的状态
|
|
51
|
+
touched: false,
|
|
52
|
+
// 背景处于触摸状态
|
|
53
|
+
maskTouched: false,
|
|
54
|
+
// 旋转状态
|
|
55
|
+
rotate: 0,
|
|
56
|
+
// 放大缩小
|
|
57
|
+
scale: 1,
|
|
58
|
+
// 触摸开始时 x 原始坐标
|
|
59
|
+
CX: 0,
|
|
60
|
+
// 触摸开始时 y 原始坐标
|
|
61
|
+
CY: 0,
|
|
62
|
+
// 触摸开始时图片 x 偏移量
|
|
63
|
+
lastX: 0,
|
|
64
|
+
// 触摸开始时图片 y 偏移量
|
|
65
|
+
lastY: 0,
|
|
66
|
+
// 上一个触摸状态 x 原始坐标
|
|
67
|
+
lastCX: 0,
|
|
68
|
+
// 上一个触摸状态 y 原始坐标
|
|
69
|
+
lastCY: 0,
|
|
70
|
+
// 上一个触摸状态的 scale
|
|
71
|
+
lastScale: 1,
|
|
72
|
+
// 触摸开始时时间
|
|
73
|
+
touchTime: 0,
|
|
74
|
+
// 多指触控间距
|
|
75
|
+
touchLength: 0,
|
|
76
|
+
// 是否暂停 transition
|
|
77
|
+
pause: true,
|
|
78
|
+
// 停止 Raf
|
|
79
|
+
stopRaf: true,
|
|
80
|
+
// 当前边缘触发状态
|
|
81
|
+
reach: undefined,
|
|
82
|
+
};
|
|
83
|
+
export default function PhotoBox(_a) {
|
|
84
|
+
var _b = _a.item, src = _b.src, render = _b.render, _c = _b.width, customWidth = _c === void 0 ? 0 : _c, _d = _b.height, customHeight = _d === void 0 ? 0 : _d, originRef = _b.originRef, visible = _a.visible, speed = _a.speed, easing = _a.easing, wrapClassName = _a.wrapClassName, className = _a.className, style = _a.style, loadingElement = _a.loadingElement, brokenElement = _a.brokenElement, onPhotoTap = _a.onPhotoTap, onMaskTap = _a.onMaskTap, onReachMove = _a.onReachMove, onReachUp = _a.onReachUp, onPhotoResize = _a.onPhotoResize, isActive = _a.isActive, expose = _a.expose;
|
|
85
|
+
var _e = useSetState(initialState), state = _e[0], updateState = _e[1];
|
|
86
|
+
var initialTouchRef = useRef(0);
|
|
87
|
+
var mounted = useMountedRef();
|
|
88
|
+
var _f = state.naturalWidth, naturalWidth = _f === void 0 ? customWidth : _f, _g = state.naturalHeight, naturalHeight = _g === void 0 ? customHeight : _g, _h = state.width, width = _h === void 0 ? customWidth : _h, _j = state.height, height = _j === void 0 ? customHeight : _j, _k = state.loaded, loaded = _k === void 0 ? !src : _k, broken = state.broken, x = state.x, y = state.y, touched = state.touched, stopRaf = state.stopRaf, maskTouched = state.maskTouched, rotate = state.rotate, scale = state.scale, CX = state.CX, CY = state.CY, lastX = state.lastX, lastY = state.lastY, lastCX = state.lastCX, lastCY = state.lastCY, lastScale = state.lastScale, touchTime = state.touchTime, touchLength = state.touchLength, pause = state.pause, reach = state.reach;
|
|
89
|
+
var fn = useMethods({
|
|
90
|
+
onScale: function (current) { return onScale(limitScale(current)); },
|
|
91
|
+
onRotate: function (current) {
|
|
92
|
+
if (rotate !== current) {
|
|
93
|
+
expose({ rotate: current });
|
|
94
|
+
updateState(__assign({ rotate: current }, getSuitableImageSize(naturalWidth, naturalHeight, current)));
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
// 默认为屏幕中心缩放
|
|
99
|
+
function onScale(current, clientX, clientY) {
|
|
100
|
+
if (scale !== current) {
|
|
101
|
+
expose({ scale: current });
|
|
102
|
+
updateState(__assign(__assign({ scale: current }, getPositionOnMoveOrScale(x, y, width, height, scale, current, clientX, clientY)), (current <= 1 && { x: 0, y: 0 })));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
var handleMove = useDebounceCallback(function (nextClientX, nextClientY, currentTouchLength) {
|
|
106
|
+
if (currentTouchLength === void 0) { currentTouchLength = 0; }
|
|
107
|
+
if ((touched || maskTouched) && isActive) {
|
|
108
|
+
// 通过旋转调换宽高
|
|
109
|
+
var _a = getRotateSize(rotate, width, height), currentWidth_1 = _a[0], currentHeight_1 = _a[1];
|
|
110
|
+
// 单指最小缩放下,以初始移动距离来判断意图
|
|
111
|
+
if (currentTouchLength === 0 && initialTouchRef.current === 0) {
|
|
112
|
+
var isStillX = Math.abs(nextClientX - CX) <= minStartTouchOffset;
|
|
113
|
+
var isStillY = Math.abs(nextClientY - CY) <= minStartTouchOffset;
|
|
114
|
+
// 初始移动距离不足
|
|
115
|
+
if (isStillX && isStillY) {
|
|
116
|
+
// 方向记录上次移动距离,以便平滑过渡
|
|
117
|
+
updateState({ lastCX: nextClientX, lastCY: nextClientY });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// 设置响应状态
|
|
121
|
+
initialTouchRef.current = !isStillX ? 1 : nextClientY > CY ? 3 : 2;
|
|
122
|
+
}
|
|
123
|
+
var offsetX = nextClientX - lastCX;
|
|
124
|
+
var offsetY = nextClientY - lastCY;
|
|
125
|
+
// 边缘触发状态
|
|
126
|
+
var currentReach = undefined;
|
|
127
|
+
if (currentTouchLength === 0) {
|
|
128
|
+
// 边缘超出状态
|
|
129
|
+
var horizontalCloseEdge = computePositionEdge(offsetX + lastX, scale, currentWidth_1, window.innerWidth)[0];
|
|
130
|
+
var verticalCloseEdge = computePositionEdge(offsetY + lastY, scale, currentHeight_1, window.innerHeight)[0];
|
|
131
|
+
// 边缘触发检测
|
|
132
|
+
currentReach = getReachType(initialTouchRef.current, horizontalCloseEdge, verticalCloseEdge, reach);
|
|
133
|
+
// 接触边缘
|
|
134
|
+
if (currentReach !== undefined) {
|
|
135
|
+
onReachMove(currentReach, nextClientX, nextClientY, scale);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// 横向边缘触发、背景触发禁用当前滑动
|
|
139
|
+
if (currentReach === 'x' || maskTouched) {
|
|
140
|
+
updateState({ reach: 'x' });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
// 目标倍数
|
|
144
|
+
var toScale = limitScale(scale + ((currentTouchLength - touchLength) / 100 / 2) * scale, naturalWidth / width, scaleBuffer);
|
|
145
|
+
// 导出变量
|
|
146
|
+
expose({ scale: toScale });
|
|
147
|
+
updateState(__assign({ touchLength: currentTouchLength, reach: currentReach, scale: toScale }, getPositionOnMoveOrScale(x, y, width, height, scale, toScale, nextClientX, nextClientY, offsetX, offsetY)));
|
|
148
|
+
}
|
|
149
|
+
}, {
|
|
150
|
+
maxWait: 8,
|
|
151
|
+
});
|
|
152
|
+
function updateRaf(position) {
|
|
153
|
+
if (stopRaf || touched) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
if (mounted.current) {
|
|
157
|
+
// 下拉关闭时可以有动画
|
|
158
|
+
updateState(__assign(__assign({}, position), { pause: visible }));
|
|
159
|
+
}
|
|
160
|
+
return mounted.current;
|
|
161
|
+
}
|
|
162
|
+
var slideToPosition = useScrollPosition(function (nextX) { return updateRaf({ x: nextX }); }, function (nextY) { return updateRaf({ y: nextY }); }, function (nextScale) {
|
|
163
|
+
if (mounted.current) {
|
|
164
|
+
expose({ scale: nextScale });
|
|
165
|
+
updateState({ scale: nextScale });
|
|
166
|
+
}
|
|
167
|
+
return !touched && mounted.current;
|
|
168
|
+
});
|
|
169
|
+
var handlePhotoTap = useContinuousTap(onPhotoTap, function (currentClientX, currentClientY) {
|
|
170
|
+
if (!reach) {
|
|
171
|
+
// 若图片足够大,则放大适应的倍数
|
|
172
|
+
var endScale = scale !== 1 ? 1 : Math.max(2, naturalWidth / width);
|
|
173
|
+
onScale(endScale, currentClientX, currentClientY);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
function handleUp(nextClientX, nextClientY) {
|
|
177
|
+
// 重置响应状态
|
|
178
|
+
initialTouchRef.current = 0;
|
|
179
|
+
if ((touched || maskTouched) && isActive) {
|
|
180
|
+
updateState({
|
|
181
|
+
touched: false,
|
|
182
|
+
maskTouched: false,
|
|
183
|
+
pause: false,
|
|
184
|
+
stopRaf: false,
|
|
185
|
+
reach: undefined,
|
|
186
|
+
});
|
|
187
|
+
var safeScale = limitScale(scale, naturalWidth / width);
|
|
188
|
+
// Go
|
|
189
|
+
slideToPosition(x, y, lastX, lastY, width, height, scale, safeScale, lastScale, rotate, touchTime);
|
|
190
|
+
onReachUp(nextClientX, nextClientY);
|
|
191
|
+
// 触发 Tap 事件
|
|
192
|
+
if (CX === nextClientX && CY === nextClientY) {
|
|
193
|
+
if (touched) {
|
|
194
|
+
handlePhotoTap(nextClientX, nextClientY);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (maskTouched) {
|
|
198
|
+
onMaskTap(nextClientX, nextClientY);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
useEventListener(isTouchDevice ? undefined : 'mousemove', function (e) {
|
|
204
|
+
e.preventDefault();
|
|
205
|
+
handleMove(e.clientX, e.clientY);
|
|
206
|
+
});
|
|
207
|
+
useEventListener(isTouchDevice ? undefined : 'mouseup', function (e) {
|
|
208
|
+
handleUp(e.clientX, e.clientY);
|
|
209
|
+
});
|
|
210
|
+
useEventListener(isTouchDevice ? 'touchmove' : undefined, function (e) {
|
|
211
|
+
e.preventDefault();
|
|
212
|
+
var position = getMultipleTouchPosition(e);
|
|
213
|
+
handleMove.apply(void 0, position);
|
|
214
|
+
}, { passive: false });
|
|
215
|
+
useEventListener(isTouchDevice ? 'touchend' : undefined, function (_a) {
|
|
216
|
+
var changedTouches = _a.changedTouches;
|
|
217
|
+
var touch = changedTouches[0];
|
|
218
|
+
handleUp(touch.clientX, touch.clientY);
|
|
219
|
+
}, { passive: false });
|
|
220
|
+
useEventListener('resize', useDebounceCallback(function () {
|
|
221
|
+
if (loaded && !touched) {
|
|
222
|
+
updateState(getSuitableImageSize(naturalWidth, naturalHeight, rotate));
|
|
223
|
+
onPhotoResize();
|
|
224
|
+
}
|
|
225
|
+
}, { maxWait: 8 }));
|
|
226
|
+
useIsomorphicLayoutEffect(function () {
|
|
227
|
+
if (isActive) {
|
|
228
|
+
expose(__assign({ scale: scale, rotate: rotate }, fn));
|
|
229
|
+
}
|
|
230
|
+
}, [isActive]);
|
|
231
|
+
function handlePhotoLoad(params) {
|
|
232
|
+
updateState(__assign(__assign({}, params), (params.loaded && getSuitableImageSize(params.naturalWidth || 0, params.naturalHeight || 0, rotate))));
|
|
233
|
+
}
|
|
234
|
+
function handleStart(currentClientX, currentClientY, currentTouchLength) {
|
|
235
|
+
if (currentTouchLength === void 0) { currentTouchLength = 0; }
|
|
236
|
+
updateState({
|
|
237
|
+
touched: true,
|
|
238
|
+
CX: currentClientX,
|
|
239
|
+
CY: currentClientY,
|
|
240
|
+
lastCX: currentClientX,
|
|
241
|
+
lastCY: currentClientY,
|
|
242
|
+
lastX: x,
|
|
243
|
+
lastY: y,
|
|
244
|
+
lastScale: scale,
|
|
245
|
+
touchLength: currentTouchLength,
|
|
246
|
+
touchTime: Date.now(),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
function handleWheel(e) {
|
|
250
|
+
if (!reach) {
|
|
251
|
+
// 限制最大倍数和最小倍数
|
|
252
|
+
var toScale = limitScale(scale - e.deltaY / 100 / 2, naturalWidth / width);
|
|
253
|
+
updateState({ stopRaf: true });
|
|
254
|
+
onScale(toScale, e.clientX, e.clientY);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function handleMaskStart(e) {
|
|
258
|
+
updateState({
|
|
259
|
+
maskTouched: true,
|
|
260
|
+
CX: e.clientX,
|
|
261
|
+
CY: e.clientY,
|
|
262
|
+
lastX: x,
|
|
263
|
+
lastY: y,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function handleTouchStart(e) {
|
|
267
|
+
e.stopPropagation();
|
|
268
|
+
handleStart.apply(void 0, getMultipleTouchPosition(e));
|
|
269
|
+
}
|
|
270
|
+
function handleMouseDown(e) {
|
|
271
|
+
e.stopPropagation();
|
|
272
|
+
if (e.button === 0) {
|
|
273
|
+
handleStart(e.clientX, e.clientY, 0);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// 计算位置
|
|
277
|
+
var _l = useAnimationPosition(visible, originRef, loaded, x, y, width, height, scale, speed, function (isPause) { return updateState({ pause: isPause }); }), translateX = _l[0], translateY = _l[1], currentWidth = _l[2], currentHeight = _l[3], currentScale = _l[4], opacity = _l[5], easingMode = _l[6], FIT = _l[7];
|
|
278
|
+
// 图片 objectFit 渐变时间
|
|
279
|
+
var transitionLayoutTime = easingMode < 4 ? speed / 2 : easingMode > 4 ? speed : 0;
|
|
280
|
+
var transitionCSS = "transform ".concat(speed, "ms ").concat(easing);
|
|
281
|
+
var attrs = {
|
|
282
|
+
className: className,
|
|
283
|
+
onMouseDown: isTouchDevice ? undefined : handleMouseDown,
|
|
284
|
+
onTouchStart: isTouchDevice ? handleTouchStart : undefined,
|
|
285
|
+
onWheel: handleWheel,
|
|
286
|
+
style: {
|
|
287
|
+
width: currentWidth,
|
|
288
|
+
height: currentHeight,
|
|
289
|
+
opacity: opacity,
|
|
290
|
+
objectFit: easingMode === 4 ? undefined : FIT,
|
|
291
|
+
transform: rotate ? "rotate(".concat(rotate, "deg)") : undefined,
|
|
292
|
+
transition:
|
|
293
|
+
// 初始状态无渐变
|
|
294
|
+
easingMode > 2 ? "".concat(transitionCSS, ", opacity ").concat(speed, "ms ease, height ").concat(transitionLayoutTime, "ms ").concat(easing) : undefined,
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
return (_jsx("div", __assign({ className: "PhotoView__PhotoWrap".concat(wrapClassName ? " ".concat(wrapClassName) : ''), style: style, onMouseDown: !isTouchDevice && isActive ? handleMaskStart : undefined, onTouchStart: isTouchDevice && isActive ? function (e) { return handleMaskStart(e.touches[0]); } : undefined }, { children: _jsx("div", __assign({ className: "PhotoView__PhotoBox", style: {
|
|
298
|
+
transform: "matrix(".concat(currentScale, ", 0, 0, ").concat(currentScale, ", ").concat(translateX, ", ").concat(translateY - 107, ")"),
|
|
299
|
+
transition: touched || pause ? undefined : transitionCSS,
|
|
300
|
+
willChange: isActive ? 'transform' : undefined,
|
|
301
|
+
} }, { children: src ? (_jsx(Photo, __assign({ src: src, loaded: loaded, broken: broken }, attrs, { onPhotoLoad: handlePhotoLoad, loadingElement: loadingElement, brokenElement: brokenElement }))) : (render && render({ attrs: attrs, scale: currentScale, rotate: rotate })) })) })));
|
|
302
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DataType } from './types';
|
|
3
|
+
interface PhotoPageProps {
|
|
4
|
+
images: DataType[];
|
|
5
|
+
index: number;
|
|
6
|
+
onSelected?: (string: any, number: any) => void;
|
|
7
|
+
}
|
|
8
|
+
declare const PhotoPage: React.FC<PhotoPageProps>;
|
|
9
|
+
export default PhotoPage;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
import { useEffect, useState } from 'react';
|
|
23
|
+
import { Box, KeyboardArrowLeftIcon, KeyboardArrowRightIcon, styled, Typography } from 'fbm-ui';
|
|
24
|
+
import { Stack } from 'fbm-ui/lib/mui';
|
|
25
|
+
var chunk = function (a, n) { return __spreadArray([], Array(Math.ceil(a.length / n)), true).map(function (_, i) { return a.slice(n * i, n + n * i); }); };
|
|
26
|
+
var IconButton = styled(Box)(function (_a) {
|
|
27
|
+
var disabled = _a.disabled;
|
|
28
|
+
return ({
|
|
29
|
+
marginTop: -56,
|
|
30
|
+
width: 48,
|
|
31
|
+
height: 48,
|
|
32
|
+
display: 'flex',
|
|
33
|
+
justifyContent: 'center',
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
color: disabled ? 'RGBA(255, 255, 255, 0.26)' : 'white',
|
|
36
|
+
backgroundColor: disabled ? 'RGBA(0, 0, 0, 0.26)' : 'RGBA(0, 0, 0, 0.56)',
|
|
37
|
+
borderRadius: 24,
|
|
38
|
+
cursor: disabled ? 'default' : 'pointer',
|
|
39
|
+
flexShrink: 0,
|
|
40
|
+
'& .MuiBox-root': {
|
|
41
|
+
backgroundColor: 'transparent',
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
var Image = styled('img')(function (_a) {
|
|
46
|
+
var selected = _a.selected;
|
|
47
|
+
return ({
|
|
48
|
+
width: 96,
|
|
49
|
+
height: 96,
|
|
50
|
+
objectFit: 'cover',
|
|
51
|
+
cursor: 'pointer',
|
|
52
|
+
boxSizing: 'border-box',
|
|
53
|
+
border: "".concat(selected ? 'solid 5px RGB(76, 175, 80) ' : 'none'),
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
var PhotoPage = function (_a) {
|
|
57
|
+
var images = _a.images, index = _a.index, onSelected = _a.onSelected;
|
|
58
|
+
var pre = Math.floor((window.innerWidth - 200) / 110);
|
|
59
|
+
var maxPage = Math.ceil(images.length / pre);
|
|
60
|
+
var _b = useState(0), page = _b[0], setPage = _b[1];
|
|
61
|
+
var handleNext = function () {
|
|
62
|
+
if (page < maxPage - 1)
|
|
63
|
+
setPage(function (prevPage) { return prevPage + 1; });
|
|
64
|
+
};
|
|
65
|
+
var handleBack = function () {
|
|
66
|
+
if (page > 0)
|
|
67
|
+
setPage(function (prevPage) { return prevPage - 1; });
|
|
68
|
+
};
|
|
69
|
+
useEffect(function () {
|
|
70
|
+
setPage(Math.floor(index / pre));
|
|
71
|
+
}, [index, images, pre]);
|
|
72
|
+
return (_jsxs(Box, __assign({ sx: { flexGrow: 1, display: 'flex', alignItems: 'center', px: 7 } }, { children: [_jsx(IconButton, __assign({ onClick: handleBack, disabled: page === 0 }, { children: _jsx(KeyboardArrowLeftIcon, {}) })), _jsx(Stack, __assign({ spacing: 1, direction: "row", sx: { height: 150, display: 'flex', justifyContent: 'center', flexGrow: 1, p: 2 } }, { children: chunk(images, pre)[page].map(function (_a, i) {
|
|
73
|
+
var key = _a.key, src = _a.src, title = _a.title;
|
|
74
|
+
return (_jsxs(Stack, __assign({ alignItems: "center", spacing: 1, onClick: function () { return onSelected === null || onSelected === void 0 ? void 0 : onSelected(src, i); } }, { children: [_jsx(Image, { src: src, selected: key === images[index].key }), _jsx(Typography, __assign({ sx: { width: 96, lineHeight: '14px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, variant: "body2", color: "white" }, { children: title }))] }), key));
|
|
75
|
+
}) })), _jsx(IconButton, __assign({ onClick: handleNext, disabled: page === maxPage - 1 }, { children: _jsx(KeyboardArrowRightIcon, {}) }))] })));
|
|
76
|
+
};
|
|
77
|
+
export default PhotoPage;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { DataType, PhotoProviderBase } from './types';
|
|
3
|
+
export interface PhotoProviderProps extends PhotoProviderBase {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
onIndexChange?: (index: number, state: PhotoProviderState) => void;
|
|
6
|
+
onVisibleChange?: (visible: boolean, index: number, state: PhotoProviderState) => void;
|
|
7
|
+
}
|
|
8
|
+
declare type PhotoProviderState = {
|
|
9
|
+
images: DataType[];
|
|
10
|
+
visible: boolean;
|
|
11
|
+
index: number;
|
|
12
|
+
};
|
|
13
|
+
export default function PhotoProvider({ children, onIndexChange, onVisibleChange, ...restProps }: PhotoProviderProps): JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
|
+
import { useMemo, useRef } from 'react';
|
|
25
|
+
import useMethods from './hooks/useMethods';
|
|
26
|
+
import useSetState from './hooks/useSetState';
|
|
27
|
+
import PhotoContext from './photo-context';
|
|
28
|
+
import PhotoSlider from './PhotoSlider';
|
|
29
|
+
var initialState = {
|
|
30
|
+
images: [],
|
|
31
|
+
visible: false,
|
|
32
|
+
index: 0,
|
|
33
|
+
};
|
|
34
|
+
export default function PhotoProvider(_a) {
|
|
35
|
+
var children = _a.children, onIndexChange = _a.onIndexChange, onVisibleChange = _a.onVisibleChange, restProps = __rest(_a, ["children", "onIndexChange", "onVisibleChange"]);
|
|
36
|
+
var _b = useSetState(initialState), state = _b[0], updateState = _b[1];
|
|
37
|
+
var uniqueIdRef = useRef(0);
|
|
38
|
+
var images = state.images, visible = state.visible, index = state.index;
|
|
39
|
+
var methods = useMethods({
|
|
40
|
+
nextId: function () {
|
|
41
|
+
return (uniqueIdRef.current += 1);
|
|
42
|
+
},
|
|
43
|
+
update: function (imageItem) {
|
|
44
|
+
var currentIndex = images.findIndex(function (n) { return n.key === imageItem.key; });
|
|
45
|
+
if (currentIndex > -1) {
|
|
46
|
+
var nextImages = images.slice();
|
|
47
|
+
nextImages.splice(currentIndex, 1, imageItem);
|
|
48
|
+
updateState({
|
|
49
|
+
images: nextImages,
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
updateState(function (prev) { return ({
|
|
54
|
+
images: prev.images.concat(imageItem),
|
|
55
|
+
}); });
|
|
56
|
+
},
|
|
57
|
+
remove: function (key) {
|
|
58
|
+
updateState(function (prev) {
|
|
59
|
+
var nextImages = prev.images.filter(function (item) { return item.key !== key; });
|
|
60
|
+
var nextEndIndex = nextImages.length - 1;
|
|
61
|
+
return {
|
|
62
|
+
images: nextImages,
|
|
63
|
+
index: Math.min(nextEndIndex, index),
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
show: function (key) {
|
|
68
|
+
var currentIndex = images.findIndex(function (item) { return item.key === key; });
|
|
69
|
+
updateState({
|
|
70
|
+
visible: true,
|
|
71
|
+
index: currentIndex,
|
|
72
|
+
});
|
|
73
|
+
if (onVisibleChange) {
|
|
74
|
+
onVisibleChange(true, currentIndex, state);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
var fn = useMethods({
|
|
79
|
+
close: function () {
|
|
80
|
+
updateState({
|
|
81
|
+
visible: false,
|
|
82
|
+
});
|
|
83
|
+
if (onVisibleChange) {
|
|
84
|
+
onVisibleChange(false, index, state);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
changeIndex: function (nextIndex) {
|
|
88
|
+
updateState({
|
|
89
|
+
index: nextIndex,
|
|
90
|
+
});
|
|
91
|
+
if (onIndexChange) {
|
|
92
|
+
onIndexChange(nextIndex, state);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
var value = useMemo(function () { return (__assign(__assign({}, state), methods)); }, [state, methods]);
|
|
97
|
+
return (_jsxs(PhotoContext.Provider, __assign({ value: value }, { children: [children, _jsx(PhotoSlider, __assign({ images: images, visible: visible, index: index, onIndexChange: fn.changeIndex, onClose: fn.close }, restProps))] })));
|
|
98
|
+
}
|