@expcat/tigercat-react 0.3.69 → 0.3.70
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/dist/chunk-2EOXY2LP.mjs +353 -0
- package/dist/chunk-5CLXOFRZ.mjs +248 -0
- package/dist/chunk-6W6CRBBG.mjs +169 -0
- package/dist/chunk-EHYSER2Z.js +144 -0
- package/dist/chunk-GNMOOYHG.js +250 -0
- package/dist/chunk-NV3JUZ3N.js +57 -0
- package/dist/chunk-QFYS5QIZ.mjs +142 -0
- package/dist/chunk-QIJG42YQ.mjs +54 -0
- package/dist/chunk-U3JOBIDU.js +355 -0
- package/dist/chunk-Z7SXK2KO.js +171 -0
- package/dist/components/ActivityFeed.js +4 -4
- package/dist/components/ActivityFeed.mjs +2 -2
- package/dist/components/CropUpload.d.mts +52 -0
- package/dist/components/CropUpload.d.ts +52 -0
- package/dist/components/CropUpload.js +14 -0
- package/dist/components/CropUpload.mjs +5 -0
- package/dist/components/Image.d.mts +20 -0
- package/dist/components/Image.d.ts +20 -0
- package/dist/components/Image.js +13 -0
- package/dist/components/Image.mjs +4 -0
- package/dist/components/ImageCropper.d.mts +21 -0
- package/dist/components/ImageCropper.d.ts +21 -0
- package/dist/components/ImageCropper.js +10 -0
- package/dist/components/ImageCropper.mjs +1 -0
- package/dist/components/ImageGroup.d.mts +30 -0
- package/dist/components/ImageGroup.d.ts +30 -0
- package/dist/components/ImageGroup.js +16 -0
- package/dist/components/ImageGroup.mjs +3 -0
- package/dist/components/ImagePreview.d.mts +20 -0
- package/dist/components/ImagePreview.d.ts +20 -0
- package/dist/components/ImagePreview.js +11 -0
- package/dist/components/ImagePreview.mjs +2 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +105 -76
- package/dist/index.mjs +22 -17
- package/package.json +2 -2
- package/dist/{chunk-MTL2QUM3.mjs → chunk-FTY2W4L2.mjs} +1 -1
- package/dist/{chunk-J3HKED4B.js → chunk-IOM7DWWQ.js} +1 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { ImageGroupContext } from './chunk-QIJG42YQ.mjs';
|
|
2
|
+
import { ImagePreview } from './chunk-5CLXOFRZ.mjs';
|
|
3
|
+
import { useState, useRef, useContext, useEffect, useCallback, useMemo } from 'react';
|
|
4
|
+
import { classNames, imageBaseClasses, imagePreviewCursorClass, getImageImgClasses, toCSSSize, imageErrorClasses, imageErrorIconPath, imageLoadingClasses } from '@expcat/tigercat-core';
|
|
5
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
var SvgIcon = ({ d, className = "w-8 h-8" }) => /* @__PURE__ */ jsx(
|
|
8
|
+
"svg",
|
|
9
|
+
{
|
|
10
|
+
className,
|
|
11
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
12
|
+
fill: "none",
|
|
13
|
+
viewBox: "0 0 24 24",
|
|
14
|
+
stroke: "currentColor",
|
|
15
|
+
children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "1.5", d })
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
var Image = ({
|
|
19
|
+
src,
|
|
20
|
+
alt = "",
|
|
21
|
+
width,
|
|
22
|
+
height,
|
|
23
|
+
fit = "cover",
|
|
24
|
+
fallbackSrc,
|
|
25
|
+
preview = true,
|
|
26
|
+
lazy = false,
|
|
27
|
+
className,
|
|
28
|
+
errorRender,
|
|
29
|
+
placeholderRender,
|
|
30
|
+
onPreviewVisibleChange,
|
|
31
|
+
onClick,
|
|
32
|
+
onKeyDown,
|
|
33
|
+
style,
|
|
34
|
+
...props
|
|
35
|
+
}) => {
|
|
36
|
+
const [loading, setLoading] = useState(true);
|
|
37
|
+
const [error, setError] = useState(false);
|
|
38
|
+
const [actualSrc, setActualSrc] = useState(lazy ? "" : src);
|
|
39
|
+
const [previewVisible, setPreviewVisible] = useState(false);
|
|
40
|
+
const containerRef = useRef(null);
|
|
41
|
+
const group = useContext(ImageGroupContext);
|
|
42
|
+
const registeredIndexRef = useRef(-1);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (group && src) {
|
|
45
|
+
registeredIndexRef.current = group.register(src);
|
|
46
|
+
return () => {
|
|
47
|
+
group.unregister(src);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}, [group, src]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!lazy || !containerRef.current) return;
|
|
53
|
+
const observer = new IntersectionObserver(
|
|
54
|
+
(entries) => {
|
|
55
|
+
if (entries[0]?.isIntersecting) {
|
|
56
|
+
setActualSrc(src);
|
|
57
|
+
observer.disconnect();
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{ threshold: 0.01 }
|
|
61
|
+
);
|
|
62
|
+
observer.observe(containerRef.current);
|
|
63
|
+
return () => observer.disconnect();
|
|
64
|
+
}, [lazy, src]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!lazy) {
|
|
67
|
+
setActualSrc(src);
|
|
68
|
+
setError(false);
|
|
69
|
+
setLoading(true);
|
|
70
|
+
}
|
|
71
|
+
}, [src, lazy]);
|
|
72
|
+
const handleLoad = useCallback(() => {
|
|
73
|
+
setLoading(false);
|
|
74
|
+
setError(false);
|
|
75
|
+
}, []);
|
|
76
|
+
const handleError = useCallback(() => {
|
|
77
|
+
setLoading(false);
|
|
78
|
+
setError(true);
|
|
79
|
+
if (fallbackSrc && actualSrc !== fallbackSrc) {
|
|
80
|
+
setActualSrc(fallbackSrc);
|
|
81
|
+
setError(false);
|
|
82
|
+
setLoading(true);
|
|
83
|
+
}
|
|
84
|
+
}, [fallbackSrc, actualSrc]);
|
|
85
|
+
const handleClick = useCallback(
|
|
86
|
+
(e) => {
|
|
87
|
+
onClick?.(e);
|
|
88
|
+
if (!preview) return;
|
|
89
|
+
if (group) {
|
|
90
|
+
group.openPreview(registeredIndexRef.current >= 0 ? registeredIndexRef.current : 0);
|
|
91
|
+
} else {
|
|
92
|
+
setPreviewVisible(true);
|
|
93
|
+
onPreviewVisibleChange?.(true);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
[preview, group, onClick, onPreviewVisibleChange]
|
|
97
|
+
);
|
|
98
|
+
const handleKeyDown = useCallback(
|
|
99
|
+
(e) => {
|
|
100
|
+
onKeyDown?.(e);
|
|
101
|
+
if (preview && (e.key === "Enter" || e.key === " ")) {
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
handleClick(e);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
[preview, handleClick, onKeyDown]
|
|
107
|
+
);
|
|
108
|
+
const containerClasses = useMemo(
|
|
109
|
+
() => classNames(imageBaseClasses, preview && imagePreviewCursorClass, className),
|
|
110
|
+
[preview, className]
|
|
111
|
+
);
|
|
112
|
+
const imgClasses = useMemo(() => getImageImgClasses(fit), [fit]);
|
|
113
|
+
const containerStyle = useMemo(() => {
|
|
114
|
+
const s = { ...style };
|
|
115
|
+
const w = toCSSSize(width);
|
|
116
|
+
const h = toCSSSize(height);
|
|
117
|
+
if (w) s.width = w;
|
|
118
|
+
if (h) s.height = h;
|
|
119
|
+
return s;
|
|
120
|
+
}, [width, height, style]);
|
|
121
|
+
let content;
|
|
122
|
+
if (error && !fallbackSrc) {
|
|
123
|
+
content = errorRender || /* @__PURE__ */ jsx("div", { className: imageErrorClasses, children: /* @__PURE__ */ jsx(SvgIcon, { d: imageErrorIconPath }) });
|
|
124
|
+
} else if (loading && !actualSrc) {
|
|
125
|
+
content = placeholderRender || /* @__PURE__ */ jsx("div", { className: imageLoadingClasses, children: /* @__PURE__ */ jsx(SvgIcon, { d: imageErrorIconPath }) });
|
|
126
|
+
} else {
|
|
127
|
+
content = /* @__PURE__ */ jsx(
|
|
128
|
+
"img",
|
|
129
|
+
{
|
|
130
|
+
src: actualSrc,
|
|
131
|
+
alt,
|
|
132
|
+
className: imgClasses,
|
|
133
|
+
onLoad: handleLoad,
|
|
134
|
+
onError: handleError
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
139
|
+
/* @__PURE__ */ jsx(
|
|
140
|
+
"div",
|
|
141
|
+
{
|
|
142
|
+
...props,
|
|
143
|
+
ref: containerRef,
|
|
144
|
+
className: containerClasses,
|
|
145
|
+
style: containerStyle,
|
|
146
|
+
role: preview ? "button" : void 0,
|
|
147
|
+
tabIndex: preview ? 0 : void 0,
|
|
148
|
+
"aria-label": preview ? `Preview ${alt || "image"}` : void 0,
|
|
149
|
+
onClick: handleClick,
|
|
150
|
+
onKeyDown: handleKeyDown,
|
|
151
|
+
children: content
|
|
152
|
+
}
|
|
153
|
+
),
|
|
154
|
+
!group && previewVisible && src && /* @__PURE__ */ jsx(
|
|
155
|
+
ImagePreview,
|
|
156
|
+
{
|
|
157
|
+
visible: previewVisible,
|
|
158
|
+
images: [src],
|
|
159
|
+
currentIndex: 0,
|
|
160
|
+
onVisibleChange: (val) => {
|
|
161
|
+
setPreviewVisible(val);
|
|
162
|
+
onPreviewVisibleChange?.(val);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
] });
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export { Image };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk3T7L3MHX_js = require('./chunk-3T7L3MHX.js');
|
|
4
|
+
var chunkU3JOBIDU_js = require('./chunk-U3JOBIDU.js');
|
|
5
|
+
var chunkF24IF2QL_js = require('./chunk-F24IF2QL.js');
|
|
6
|
+
var react = require('react');
|
|
7
|
+
var tigercatCore = require('@expcat/tigercat-core');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
|
|
10
|
+
var CropUpload = ({
|
|
11
|
+
accept = "image/*",
|
|
12
|
+
disabled = false,
|
|
13
|
+
maxSize,
|
|
14
|
+
cropperProps,
|
|
15
|
+
modalTitle = "\u88C1\u526A\u56FE\u7247",
|
|
16
|
+
modalWidth = 520,
|
|
17
|
+
className,
|
|
18
|
+
children,
|
|
19
|
+
onCropComplete,
|
|
20
|
+
onError
|
|
21
|
+
}) => {
|
|
22
|
+
const fileInputRef = react.useRef(null);
|
|
23
|
+
const cropperRef = react.useRef(null);
|
|
24
|
+
const [modalVisible, setModalVisible] = react.useState(false);
|
|
25
|
+
const [imageSrc, setImageSrc] = react.useState("");
|
|
26
|
+
const [cropping, setCropping] = react.useState(false);
|
|
27
|
+
const handleTriggerClick = react.useCallback(() => {
|
|
28
|
+
if (disabled) return;
|
|
29
|
+
fileInputRef.current?.click();
|
|
30
|
+
}, [disabled]);
|
|
31
|
+
const handleFileChange = react.useCallback(
|
|
32
|
+
(e) => {
|
|
33
|
+
const file = e.target.files?.[0];
|
|
34
|
+
if (!file) return;
|
|
35
|
+
if (maxSize && file.size > maxSize) {
|
|
36
|
+
onError?.(new Error(`File size exceeds maximum of ${maxSize} bytes`));
|
|
37
|
+
e.target.value = "";
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const reader = new FileReader();
|
|
41
|
+
reader.onload = (ev) => {
|
|
42
|
+
setImageSrc(ev.target?.result);
|
|
43
|
+
setModalVisible(true);
|
|
44
|
+
};
|
|
45
|
+
reader.readAsDataURL(file);
|
|
46
|
+
e.target.value = "";
|
|
47
|
+
},
|
|
48
|
+
[maxSize, onError]
|
|
49
|
+
);
|
|
50
|
+
const handleConfirm = react.useCallback(async () => {
|
|
51
|
+
if (!cropperRef.current) return;
|
|
52
|
+
setCropping(true);
|
|
53
|
+
try {
|
|
54
|
+
const result = await cropperRef.current.getCropResult();
|
|
55
|
+
onCropComplete?.(result);
|
|
56
|
+
setModalVisible(false);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
onError?.(err);
|
|
59
|
+
} finally {
|
|
60
|
+
setCropping(false);
|
|
61
|
+
}
|
|
62
|
+
}, [onCropComplete, onError]);
|
|
63
|
+
const handleCancel = react.useCallback(() => {
|
|
64
|
+
setModalVisible(false);
|
|
65
|
+
setImageSrc("");
|
|
66
|
+
}, []);
|
|
67
|
+
const triggerClasses = react.useMemo(
|
|
68
|
+
() => tigercatCore.classNames(disabled ? tigercatCore.cropUploadTriggerDisabledClasses : tigercatCore.cropUploadTriggerClasses, className),
|
|
69
|
+
[disabled, className]
|
|
70
|
+
);
|
|
71
|
+
const handleKeyDown = react.useCallback(
|
|
72
|
+
(e) => {
|
|
73
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
handleTriggerClick();
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
[handleTriggerClick]
|
|
79
|
+
);
|
|
80
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tiger-crop-upload inline-block", children: [
|
|
81
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
82
|
+
"input",
|
|
83
|
+
{
|
|
84
|
+
ref: fileInputRef,
|
|
85
|
+
type: "file",
|
|
86
|
+
accept,
|
|
87
|
+
style: { display: "none" },
|
|
88
|
+
onChange: handleFileChange
|
|
89
|
+
}
|
|
90
|
+
),
|
|
91
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
92
|
+
"div",
|
|
93
|
+
{
|
|
94
|
+
className: triggerClasses,
|
|
95
|
+
onClick: handleTriggerClick,
|
|
96
|
+
role: "button",
|
|
97
|
+
tabIndex: disabled ? -1 : 0,
|
|
98
|
+
"aria-label": "Select image to crop and upload",
|
|
99
|
+
"aria-disabled": disabled ? "true" : void 0,
|
|
100
|
+
onKeyDown: handleKeyDown,
|
|
101
|
+
children: children || /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
102
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
103
|
+
"svg",
|
|
104
|
+
{
|
|
105
|
+
className: "w-5 h-5",
|
|
106
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
107
|
+
fill: "none",
|
|
108
|
+
viewBox: "0 0 24 24",
|
|
109
|
+
stroke: "currentColor",
|
|
110
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
111
|
+
"path",
|
|
112
|
+
{
|
|
113
|
+
strokeLinecap: "round",
|
|
114
|
+
strokeLinejoin: "round",
|
|
115
|
+
strokeWidth: "2",
|
|
116
|
+
d: tigercatCore.uploadPlusIconPath
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
),
|
|
121
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u9009\u62E9\u56FE\u7247" })
|
|
122
|
+
] })
|
|
123
|
+
}
|
|
124
|
+
),
|
|
125
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
126
|
+
chunk3T7L3MHX_js.Modal,
|
|
127
|
+
{
|
|
128
|
+
visible: modalVisible,
|
|
129
|
+
size: "lg",
|
|
130
|
+
title: modalTitle,
|
|
131
|
+
closable: true,
|
|
132
|
+
maskClosable: false,
|
|
133
|
+
onClose: handleCancel,
|
|
134
|
+
footer: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-3", children: [
|
|
135
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkF24IF2QL_js.Button, { variant: "secondary", onClick: handleCancel, children: "\u53D6\u6D88" }),
|
|
136
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkF24IF2QL_js.Button, { onClick: handleConfirm, loading: cropping, children: "\u786E\u8BA4\u88C1\u526A" })
|
|
137
|
+
] }),
|
|
138
|
+
children: imageSrc && /* @__PURE__ */ jsxRuntime.jsx(chunkU3JOBIDU_js.ImageCropper, { ref: cropperRef, src: imageSrc, ...cropperProps })
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
] });
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
exports.CropUpload = CropUpload;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkZYPEO2KY_js = require('./chunk-ZYPEO2KY.js');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var reactDom = require('react-dom');
|
|
6
|
+
var tigercatCore = require('@expcat/tigercat-core');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
|
|
9
|
+
var SvgIcon = ({ d, cls = "w-5 h-5" }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
10
|
+
"svg",
|
|
11
|
+
{
|
|
12
|
+
className: cls,
|
|
13
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
14
|
+
fill: "none",
|
|
15
|
+
viewBox: "0 0 24 24",
|
|
16
|
+
stroke: "currentColor",
|
|
17
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d })
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
var ImagePreview = ({
|
|
21
|
+
visible,
|
|
22
|
+
images,
|
|
23
|
+
currentIndex = 0,
|
|
24
|
+
zIndex = 1050,
|
|
25
|
+
maskClosable = true,
|
|
26
|
+
scaleStep = 0.5,
|
|
27
|
+
minScale = 0.25,
|
|
28
|
+
maxScale = 5,
|
|
29
|
+
onVisibleChange,
|
|
30
|
+
onCurrentIndexChange,
|
|
31
|
+
onScaleChange
|
|
32
|
+
}) => {
|
|
33
|
+
const [scale, setScale] = react.useState(1);
|
|
34
|
+
const [offsetX, setOffsetX] = react.useState(0);
|
|
35
|
+
const [offsetY, setOffsetY] = react.useState(0);
|
|
36
|
+
const [index, setIndex] = react.useState(currentIndex);
|
|
37
|
+
const draggingRef = react.useRef(false);
|
|
38
|
+
const dragStartRef = react.useRef({ x: 0, y: 0, ox: 0, oy: 0 });
|
|
39
|
+
const resetTransform = react.useCallback(() => {
|
|
40
|
+
setScale(1);
|
|
41
|
+
setOffsetX(0);
|
|
42
|
+
setOffsetY(0);
|
|
43
|
+
}, []);
|
|
44
|
+
react.useEffect(() => {
|
|
45
|
+
setIndex(currentIndex);
|
|
46
|
+
resetTransform();
|
|
47
|
+
}, [currentIndex, resetTransform]);
|
|
48
|
+
react.useEffect(() => {
|
|
49
|
+
if (visible) {
|
|
50
|
+
resetTransform();
|
|
51
|
+
setIndex(currentIndex);
|
|
52
|
+
document.body.style.overflow = "hidden";
|
|
53
|
+
} else {
|
|
54
|
+
document.body.style.overflow = "";
|
|
55
|
+
}
|
|
56
|
+
return () => {
|
|
57
|
+
document.body.style.overflow = "";
|
|
58
|
+
};
|
|
59
|
+
}, [visible, currentIndex, resetTransform]);
|
|
60
|
+
const handleClose = react.useCallback(() => {
|
|
61
|
+
onVisibleChange?.(false);
|
|
62
|
+
}, [onVisibleChange]);
|
|
63
|
+
chunkZYPEO2KY_js.useEscapeKey({ enabled: !!visible, onEscape: handleClose });
|
|
64
|
+
const navState = react.useMemo(() => tigercatCore.getPreviewNavState(index, images.length), [index, images.length]);
|
|
65
|
+
const handleZoomIn = react.useCallback(() => {
|
|
66
|
+
setScale((s) => {
|
|
67
|
+
const next = tigercatCore.clampScale(s + scaleStep, minScale, maxScale);
|
|
68
|
+
onScaleChange?.(next);
|
|
69
|
+
return next;
|
|
70
|
+
});
|
|
71
|
+
}, [scaleStep, minScale, maxScale, onScaleChange]);
|
|
72
|
+
const handleZoomOut = react.useCallback(() => {
|
|
73
|
+
setScale((s) => {
|
|
74
|
+
const next = tigercatCore.clampScale(s - scaleStep, minScale, maxScale);
|
|
75
|
+
onScaleChange?.(next);
|
|
76
|
+
return next;
|
|
77
|
+
});
|
|
78
|
+
}, [scaleStep, minScale, maxScale, onScaleChange]);
|
|
79
|
+
const handleReset = react.useCallback(() => {
|
|
80
|
+
resetTransform();
|
|
81
|
+
onScaleChange?.(1);
|
|
82
|
+
}, [resetTransform, onScaleChange]);
|
|
83
|
+
const handlePrev = react.useCallback(() => {
|
|
84
|
+
if (index > 0) {
|
|
85
|
+
const next = index - 1;
|
|
86
|
+
setIndex(next);
|
|
87
|
+
resetTransform();
|
|
88
|
+
onCurrentIndexChange?.(next);
|
|
89
|
+
}
|
|
90
|
+
}, [index, resetTransform, onCurrentIndexChange]);
|
|
91
|
+
const handleNext = react.useCallback(() => {
|
|
92
|
+
if (index < images.length - 1) {
|
|
93
|
+
const next = index + 1;
|
|
94
|
+
setIndex(next);
|
|
95
|
+
resetTransform();
|
|
96
|
+
onCurrentIndexChange?.(next);
|
|
97
|
+
}
|
|
98
|
+
}, [index, images.length, resetTransform, onCurrentIndexChange]);
|
|
99
|
+
react.useEffect(() => {
|
|
100
|
+
if (!visible) return;
|
|
101
|
+
const handler = (e) => {
|
|
102
|
+
if (e.key === "ArrowLeft") handlePrev();
|
|
103
|
+
if (e.key === "ArrowRight") handleNext();
|
|
104
|
+
};
|
|
105
|
+
document.addEventListener("keydown", handler);
|
|
106
|
+
return () => document.removeEventListener("keydown", handler);
|
|
107
|
+
}, [visible, handlePrev, handleNext]);
|
|
108
|
+
const handleWheel = react.useCallback(
|
|
109
|
+
(e) => {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
const delta = e.deltaY > 0 ? -scaleStep : scaleStep;
|
|
112
|
+
setScale((s) => {
|
|
113
|
+
const next = tigercatCore.clampScale(s + delta, minScale, maxScale);
|
|
114
|
+
onScaleChange?.(next);
|
|
115
|
+
return next;
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
[scaleStep, minScale, maxScale, onScaleChange]
|
|
119
|
+
);
|
|
120
|
+
const handleMouseDown = react.useCallback(
|
|
121
|
+
(e) => {
|
|
122
|
+
if (e.button !== 0) return;
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
draggingRef.current = true;
|
|
125
|
+
dragStartRef.current = { x: e.clientX, y: e.clientY, ox: offsetX, oy: offsetY };
|
|
126
|
+
},
|
|
127
|
+
[offsetX, offsetY]
|
|
128
|
+
);
|
|
129
|
+
const handleMouseMove = react.useCallback((e) => {
|
|
130
|
+
if (!draggingRef.current) return;
|
|
131
|
+
setOffsetX(dragStartRef.current.ox + (e.clientX - dragStartRef.current.x));
|
|
132
|
+
setOffsetY(dragStartRef.current.oy + (e.clientY - dragStartRef.current.y));
|
|
133
|
+
}, []);
|
|
134
|
+
const handleMouseUp = react.useCallback(() => {
|
|
135
|
+
draggingRef.current = false;
|
|
136
|
+
}, []);
|
|
137
|
+
const handleMaskClick = react.useCallback(
|
|
138
|
+
(e) => {
|
|
139
|
+
if (maskClosable && e.target === e.currentTarget) {
|
|
140
|
+
handleClose();
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
[maskClosable, handleClose]
|
|
144
|
+
);
|
|
145
|
+
const transform = react.useMemo(
|
|
146
|
+
() => tigercatCore.calculateTransform(scale, offsetX, offsetY),
|
|
147
|
+
[scale, offsetX, offsetY]
|
|
148
|
+
);
|
|
149
|
+
if (!visible || !images.length) return null;
|
|
150
|
+
const currentSrc = images[index] || images[0];
|
|
151
|
+
return reactDom.createPortal(
|
|
152
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
153
|
+
"div",
|
|
154
|
+
{
|
|
155
|
+
className: tigercatCore.imagePreviewWrapperClasses,
|
|
156
|
+
style: { zIndex },
|
|
157
|
+
role: "dialog",
|
|
158
|
+
"aria-modal": "true",
|
|
159
|
+
"aria-label": "Image preview",
|
|
160
|
+
onClick: handleMaskClick,
|
|
161
|
+
onWheel: handleWheel,
|
|
162
|
+
children: [
|
|
163
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: tigercatCore.imagePreviewMaskClasses, "aria-hidden": "true" }),
|
|
164
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
165
|
+
"img",
|
|
166
|
+
{
|
|
167
|
+
src: currentSrc,
|
|
168
|
+
className: tigercatCore.imagePreviewImgClasses,
|
|
169
|
+
style: { transform },
|
|
170
|
+
alt: `Preview image ${index + 1}`,
|
|
171
|
+
draggable: false,
|
|
172
|
+
onMouseDown: handleMouseDown,
|
|
173
|
+
onMouseMove: handleMouseMove,
|
|
174
|
+
onMouseUp: handleMouseUp,
|
|
175
|
+
onMouseLeave: handleMouseUp
|
|
176
|
+
}
|
|
177
|
+
),
|
|
178
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
179
|
+
"button",
|
|
180
|
+
{
|
|
181
|
+
className: tigercatCore.imagePreviewCloseBtnClasses,
|
|
182
|
+
onClick: handleClose,
|
|
183
|
+
"aria-label": "Close preview",
|
|
184
|
+
type: "button",
|
|
185
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(SvgIcon, { d: tigercatCore.previewCloseIconPath })
|
|
186
|
+
}
|
|
187
|
+
),
|
|
188
|
+
images.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
189
|
+
"button",
|
|
190
|
+
{
|
|
191
|
+
className: tigercatCore.classNames(tigercatCore.imagePreviewNavBtnClasses, "left-4"),
|
|
192
|
+
onClick: handlePrev,
|
|
193
|
+
disabled: !navState.hasPrev,
|
|
194
|
+
"aria-label": "Previous image",
|
|
195
|
+
type: "button",
|
|
196
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(SvgIcon, { d: tigercatCore.prevIconPath })
|
|
197
|
+
}
|
|
198
|
+
),
|
|
199
|
+
images.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
200
|
+
"button",
|
|
201
|
+
{
|
|
202
|
+
className: tigercatCore.classNames(tigercatCore.imagePreviewNavBtnClasses, "right-4"),
|
|
203
|
+
onClick: handleNext,
|
|
204
|
+
disabled: !navState.hasNext,
|
|
205
|
+
"aria-label": "Next image",
|
|
206
|
+
type: "button",
|
|
207
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(SvgIcon, { d: tigercatCore.nextIconPath })
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: tigercatCore.imagePreviewToolbarClasses, children: [
|
|
211
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
212
|
+
"button",
|
|
213
|
+
{
|
|
214
|
+
className: tigercatCore.imagePreviewToolbarBtnClasses,
|
|
215
|
+
onClick: handleZoomOut,
|
|
216
|
+
"aria-label": "Zoom out",
|
|
217
|
+
type: "button",
|
|
218
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(SvgIcon, { d: tigercatCore.zoomOutIconPath })
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
222
|
+
"button",
|
|
223
|
+
{
|
|
224
|
+
className: tigercatCore.imagePreviewToolbarBtnClasses,
|
|
225
|
+
onClick: handleReset,
|
|
226
|
+
"aria-label": "Reset",
|
|
227
|
+
type: "button",
|
|
228
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(SvgIcon, { d: tigercatCore.resetIconPath })
|
|
229
|
+
}
|
|
230
|
+
),
|
|
231
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
232
|
+
"button",
|
|
233
|
+
{
|
|
234
|
+
className: tigercatCore.imagePreviewToolbarBtnClasses,
|
|
235
|
+
onClick: handleZoomIn,
|
|
236
|
+
"aria-label": "Zoom in",
|
|
237
|
+
type: "button",
|
|
238
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(SvgIcon, { d: tigercatCore.zoomInIconPath })
|
|
239
|
+
}
|
|
240
|
+
),
|
|
241
|
+
navState.counter && /* @__PURE__ */ jsxRuntime.jsx("span", { className: tigercatCore.imagePreviewCounterClasses, children: navState.counter })
|
|
242
|
+
] })
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
),
|
|
246
|
+
document.body
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
exports.ImagePreview = ImagePreview;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkGNMOOYHG_js = require('./chunk-GNMOOYHG.js');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
var ImageGroupContext = react.createContext(null);
|
|
8
|
+
var ImageGroup = ({
|
|
9
|
+
preview = true,
|
|
10
|
+
onPreviewVisibleChange,
|
|
11
|
+
children,
|
|
12
|
+
className
|
|
13
|
+
}) => {
|
|
14
|
+
const [previewVisible, setPreviewVisible] = react.useState(false);
|
|
15
|
+
const [previewIndex, setPreviewIndex] = react.useState(0);
|
|
16
|
+
const imagesRef = react.useRef([]);
|
|
17
|
+
const register = react.useCallback((src) => {
|
|
18
|
+
const idx = imagesRef.current.length;
|
|
19
|
+
imagesRef.current = [...imagesRef.current, src];
|
|
20
|
+
return idx;
|
|
21
|
+
}, []);
|
|
22
|
+
const unregister = react.useCallback((src) => {
|
|
23
|
+
imagesRef.current = imagesRef.current.filter((s) => s !== src);
|
|
24
|
+
}, []);
|
|
25
|
+
const openPreview = react.useCallback(
|
|
26
|
+
(index) => {
|
|
27
|
+
if (!preview) return;
|
|
28
|
+
setPreviewIndex(index);
|
|
29
|
+
setPreviewVisible(true);
|
|
30
|
+
onPreviewVisibleChange?.(true);
|
|
31
|
+
},
|
|
32
|
+
[preview, onPreviewVisibleChange]
|
|
33
|
+
);
|
|
34
|
+
const contextValue = react.useMemo(
|
|
35
|
+
() => ({ register, unregister, openPreview }),
|
|
36
|
+
[register, unregister, openPreview]
|
|
37
|
+
);
|
|
38
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ImageGroupContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: className || "tiger-image-group", role: "group", children: [
|
|
39
|
+
children,
|
|
40
|
+
preview && /* @__PURE__ */ jsxRuntime.jsx(
|
|
41
|
+
chunkGNMOOYHG_js.ImagePreview,
|
|
42
|
+
{
|
|
43
|
+
visible: previewVisible,
|
|
44
|
+
images: imagesRef.current,
|
|
45
|
+
currentIndex: previewIndex,
|
|
46
|
+
onVisibleChange: (val) => {
|
|
47
|
+
setPreviewVisible(val);
|
|
48
|
+
if (!val) onPreviewVisibleChange?.(false);
|
|
49
|
+
},
|
|
50
|
+
onCurrentIndexChange: setPreviewIndex
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
] }) });
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports.ImageGroup = ImageGroup;
|
|
57
|
+
exports.ImageGroupContext = ImageGroupContext;
|