@v-c/image 1.0.9 → 1.0.10
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/Image.js +13 -11
- package/dist/Preview/CloseBtn.d.ts +3 -0
- package/dist/Preview/CloseBtn.js +19 -7
- package/dist/Preview/Footer.js +26 -48
- package/dist/Preview/PrevNext.js +9 -12
- package/dist/Preview/index.d.ts +3 -1
- package/dist/Preview/index.js +44 -26
- package/dist/PreviewGroup.js +7 -5
- package/dist/common.js +3 -1
- package/dist/context.js +2 -0
- package/dist/getFixScaleEleTransPosition.js +14 -0
- package/dist/hooks/useImageTransform.js +16 -4
- package/dist/hooks/useMouseEvent.js +5 -2
- package/dist/hooks/usePreviewItems.js +5 -0
- package/dist/hooks/useRegisterImage.js +2 -0
- package/dist/hooks/useStatus.js +2 -0
- package/dist/hooks/useTouchEvent.js +6 -2
- package/dist/index.js +7 -6
- package/dist/previewConfig.js +6 -2
- package/dist/util.js +2 -0
- package/package.json +1 -1
- package/dist/util/dist/Dom/canUseDom.js +0 -4
- package/dist/util/dist/Dom/findDOMNode.js +0 -20
- package/dist/util/dist/Dom/focus.js +0 -129
- package/dist/util/dist/Dom/isVisible.js +0 -16
- package/dist/util/dist/KeyCode.js +0 -81
- package/dist/util/dist/hooks/useId.js +0 -12
- package/dist/util/dist/hooks/useMergedState.js +0 -24
- package/dist/util/dist/isEqual.js +0 -27
- package/dist/util/dist/omit.js +0 -8
- package/dist/util/dist/pickAttrs.js +0 -39
- package/dist/util/dist/props-util/index.js +0 -32
- package/dist/util/dist/raf.js +0 -36
- package/dist/util/dist/type.js +0 -2
- package/dist/util/dist/utils/transition.js +0 -21
- package/dist/util/dist/warning.js +0 -37
package/dist/Image.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { useMergedState } from "./util/dist/hooks/useMergedState.js";
|
|
2
|
-
import { pickAttrs } from "./util/dist/pickAttrs.js";
|
|
3
|
-
import { getAttrStyleAndClass, getStylePxValue } from "./util/dist/props-util/index.js";
|
|
4
1
|
import { COMMON_PROPS } from "./common.js";
|
|
5
2
|
import { usePreviewGroupContext } from "./context.js";
|
|
6
3
|
import useRegisterImage from "./hooks/useRegisterImage.js";
|
|
7
4
|
import useStatus from "./hooks/useStatus.js";
|
|
8
|
-
import
|
|
5
|
+
import Preview from "./Preview/index.js";
|
|
9
6
|
import { Fragment, computed, createVNode, defineComponent, mergeDefaults, mergeProps, shallowRef } from "vue";
|
|
10
7
|
import { clsx } from "@v-c/util";
|
|
11
|
-
|
|
8
|
+
import useMergedState from "@v-c/util/dist/hooks/useMergedState";
|
|
9
|
+
import pickAttrs from "@v-c/util/dist/pickAttrs";
|
|
10
|
+
import { getAttrStyleAndClass, getStylePxValue } from "@v-c/util/dist/props-util";
|
|
11
|
+
//#region src/Image.tsx
|
|
12
|
+
var Image = /* @__PURE__ */ defineComponent((props, { attrs, slots }) => {
|
|
12
13
|
const groupContext = usePreviewGroupContext();
|
|
13
14
|
const prefixCls = computed(() => props.prefixCls ?? "vc-image");
|
|
14
15
|
const previewPrefixCls = computed(() => props.previewPrefixCls ?? `${prefixCls.value}-preview`);
|
|
@@ -71,7 +72,7 @@ var Image_default = /* @__PURE__ */ defineComponent((props, { attrs, slots }) =>
|
|
|
71
72
|
};
|
|
72
73
|
const onPreviewKeyDown = (event) => {
|
|
73
74
|
props.onKeydown?.(event);
|
|
74
|
-
if (!canPreview) return;
|
|
75
|
+
if (!canPreview.value) return;
|
|
75
76
|
if (event.key === "Enter" || event.key === " ") {
|
|
76
77
|
event.preventDefault();
|
|
77
78
|
const rect = event.target.getBoundingClientRect();
|
|
@@ -114,9 +115,9 @@ var Image_default = /* @__PURE__ */ defineComponent((props, { attrs, slots }) =>
|
|
|
114
115
|
return createVNode(Fragment, null, [createVNode("div", mergeProps(pickAttrs(restAttrs, false), {
|
|
115
116
|
"class": rootCls,
|
|
116
117
|
"onClick": canPreview.value ? onPreview : onInternalClick,
|
|
117
|
-
"role": canPreview ? "button" : restAttrs.role,
|
|
118
|
-
"tabindex": canPreview && restAttrs.tabIndex == null ? 0 : restAttrs.tabIndex,
|
|
119
|
-
"aria-label": canPreview ? restAttrs["aria-label"] ?? restAttrs.alt : restAttrs["aria-label"],
|
|
118
|
+
"role": canPreview.value ? "button" : restAttrs.role,
|
|
119
|
+
"tabindex": canPreview.value && restAttrs.tabIndex == null ? 0 : restAttrs.tabIndex,
|
|
120
|
+
"aria-label": canPreview.value ? restAttrs["aria-label"] ?? restAttrs.alt : restAttrs["aria-label"],
|
|
120
121
|
"onKeydown": onPreviewKeyDown,
|
|
121
122
|
"style": rootStyle
|
|
122
123
|
}), [
|
|
@@ -138,7 +139,7 @@ var Image_default = /* @__PURE__ */ defineComponent((props, { attrs, slots }) =>
|
|
|
138
139
|
"class": clsx(`${prefixCls.value}-cover`, props.classNames?.cover, `${prefixCls.value}-cover-${coverPlacement}`),
|
|
139
140
|
"style": props.styles?.cover
|
|
140
141
|
}, [coverNode])
|
|
141
|
-
]), !groupContext && canPreview.value && createVNode(
|
|
142
|
+
]), !groupContext && canPreview.value && createVNode(Preview, mergeProps({
|
|
142
143
|
"aria-hidden": !isShowPreview.value,
|
|
143
144
|
"open": isShowPreview.value,
|
|
144
145
|
"prefixCls": previewPrefixCls.value,
|
|
@@ -253,4 +254,5 @@ var Image_default = /* @__PURE__ */ defineComponent((props, { attrs, slots }) =>
|
|
|
253
254
|
name: "Image",
|
|
254
255
|
inheritAttrs: false
|
|
255
256
|
});
|
|
256
|
-
|
|
257
|
+
//#endregion
|
|
258
|
+
export { Image as default };
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { VueNode } from '@v-c/util/dist/type';
|
|
2
|
+
import { CSSProperties } from 'vue';
|
|
2
3
|
export interface CloseBtnProps {
|
|
3
4
|
prefixCls: string;
|
|
4
5
|
icon?: VueNode;
|
|
5
6
|
onClick: (e: MouseEvent) => void;
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: CSSProperties;
|
|
6
9
|
}
|
|
7
10
|
declare const CloseBtn: import('vue').DefineSetupFnComponent<CloseBtnProps, {}, {}, CloseBtnProps & {}, import('vue').PublicProps>;
|
|
8
11
|
export default CloseBtn;
|
package/dist/Preview/CloseBtn.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { createVNode, defineComponent } from "vue";
|
|
2
|
-
|
|
2
|
+
import { clsx } from "@v-c/util";
|
|
3
|
+
//#region src/Preview/CloseBtn.tsx
|
|
4
|
+
var CloseBtn = /* @__PURE__ */ defineComponent((props) => {
|
|
3
5
|
return () => {
|
|
4
|
-
const { prefixCls, icon, onClick } = props;
|
|
6
|
+
const { prefixCls, icon, onClick, className, style } = props;
|
|
5
7
|
return createVNode("button", {
|
|
6
|
-
"class": `${prefixCls}-close`,
|
|
8
|
+
"class": clsx(`${prefixCls}-close`, className),
|
|
9
|
+
"style": style,
|
|
7
10
|
"type": "button",
|
|
8
11
|
"onClick": onClick
|
|
9
12
|
}, [icon]);
|
|
@@ -12,8 +15,7 @@ var CloseBtn_default = /* @__PURE__ */ defineComponent((props) => {
|
|
|
12
15
|
props: {
|
|
13
16
|
prefixCls: {
|
|
14
17
|
type: String,
|
|
15
|
-
required: true
|
|
16
|
-
default: void 0
|
|
18
|
+
required: true
|
|
17
19
|
},
|
|
18
20
|
icon: {
|
|
19
21
|
type: [
|
|
@@ -30,10 +32,20 @@ var CloseBtn_default = /* @__PURE__ */ defineComponent((props) => {
|
|
|
30
32
|
},
|
|
31
33
|
onClick: {
|
|
32
34
|
type: Function,
|
|
33
|
-
required: true
|
|
35
|
+
required: true
|
|
36
|
+
},
|
|
37
|
+
className: {
|
|
38
|
+
type: String,
|
|
39
|
+
required: false,
|
|
40
|
+
default: void 0
|
|
41
|
+
},
|
|
42
|
+
style: {
|
|
43
|
+
type: Object,
|
|
44
|
+
required: false,
|
|
34
45
|
default: void 0
|
|
35
46
|
}
|
|
36
47
|
},
|
|
37
48
|
name: "ImagePreviewCloseBtn"
|
|
38
49
|
});
|
|
39
|
-
|
|
50
|
+
//#endregion
|
|
51
|
+
export { CloseBtn as default };
|
package/dist/Preview/Footer.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createVNode, defineComponent } from "vue";
|
|
2
2
|
import { clsx } from "@v-c/util";
|
|
3
|
-
|
|
3
|
+
//#region src/Preview/Footer.tsx
|
|
4
|
+
var Footer = /* @__PURE__ */ defineComponent((props) => {
|
|
4
5
|
const renderOperation = ({ type, disabled, onClick, icon }) => {
|
|
5
6
|
const actionCls = `${props.prefixCls}-actions-action`;
|
|
6
7
|
return createVNode("button", {
|
|
@@ -108,13 +109,11 @@ var Footer_default = /* @__PURE__ */ defineComponent((props) => {
|
|
|
108
109
|
props: {
|
|
109
110
|
prefixCls: {
|
|
110
111
|
type: String,
|
|
111
|
-
required: true
|
|
112
|
-
default: void 0
|
|
112
|
+
required: true
|
|
113
113
|
},
|
|
114
114
|
showProgress: {
|
|
115
115
|
type: Boolean,
|
|
116
|
-
required: true
|
|
117
|
-
default: void 0
|
|
116
|
+
required: true
|
|
118
117
|
},
|
|
119
118
|
countRender: {
|
|
120
119
|
type: Function,
|
|
@@ -128,104 +127,83 @@ var Footer_default = /* @__PURE__ */ defineComponent((props) => {
|
|
|
128
127
|
},
|
|
129
128
|
current: {
|
|
130
129
|
type: Number,
|
|
131
|
-
required: true
|
|
132
|
-
default: void 0
|
|
130
|
+
required: true
|
|
133
131
|
},
|
|
134
132
|
count: {
|
|
135
133
|
type: Number,
|
|
136
|
-
required: true
|
|
137
|
-
default: void 0
|
|
134
|
+
required: true
|
|
138
135
|
},
|
|
139
136
|
showSwitch: {
|
|
140
137
|
type: Boolean,
|
|
141
|
-
required: true
|
|
142
|
-
default: void 0
|
|
143
|
-
},
|
|
144
|
-
icons: {
|
|
145
|
-
required: true,
|
|
146
|
-
default: void 0
|
|
138
|
+
required: true
|
|
147
139
|
},
|
|
140
|
+
icons: { required: true },
|
|
148
141
|
scale: {
|
|
149
142
|
type: Number,
|
|
150
|
-
required: true
|
|
151
|
-
default: void 0
|
|
143
|
+
required: true
|
|
152
144
|
},
|
|
153
145
|
minScale: {
|
|
154
146
|
type: Number,
|
|
155
|
-
required: true
|
|
156
|
-
default: void 0
|
|
147
|
+
required: true
|
|
157
148
|
},
|
|
158
149
|
maxScale: {
|
|
159
150
|
type: Number,
|
|
160
|
-
required: true
|
|
161
|
-
default: void 0
|
|
151
|
+
required: true
|
|
162
152
|
},
|
|
163
153
|
image: {
|
|
164
154
|
type: Object,
|
|
165
|
-
required: true
|
|
166
|
-
default: void 0
|
|
155
|
+
required: true
|
|
167
156
|
},
|
|
168
157
|
transform: {
|
|
169
158
|
type: Object,
|
|
170
|
-
required: true
|
|
171
|
-
default: void 0
|
|
159
|
+
required: true
|
|
172
160
|
},
|
|
173
161
|
classNames: {
|
|
174
162
|
type: Object,
|
|
175
|
-
required: true
|
|
176
|
-
default: void 0
|
|
163
|
+
required: true
|
|
177
164
|
},
|
|
178
165
|
styles: {
|
|
179
166
|
type: Object,
|
|
180
|
-
required: true
|
|
181
|
-
default: void 0
|
|
167
|
+
required: true
|
|
182
168
|
},
|
|
183
169
|
onActive: {
|
|
184
170
|
type: Function,
|
|
185
|
-
required: true
|
|
186
|
-
default: void 0
|
|
171
|
+
required: true
|
|
187
172
|
},
|
|
188
173
|
onFlipY: {
|
|
189
174
|
type: Function,
|
|
190
|
-
required: true
|
|
191
|
-
default: void 0
|
|
175
|
+
required: true
|
|
192
176
|
},
|
|
193
177
|
onFlipX: {
|
|
194
178
|
type: Function,
|
|
195
|
-
required: true
|
|
196
|
-
default: void 0
|
|
179
|
+
required: true
|
|
197
180
|
},
|
|
198
181
|
onRotateLeft: {
|
|
199
182
|
type: Function,
|
|
200
|
-
required: true
|
|
201
|
-
default: void 0
|
|
183
|
+
required: true
|
|
202
184
|
},
|
|
203
185
|
onRotateRight: {
|
|
204
186
|
type: Function,
|
|
205
|
-
required: true
|
|
206
|
-
default: void 0
|
|
187
|
+
required: true
|
|
207
188
|
},
|
|
208
189
|
onZoomOut: {
|
|
209
190
|
type: Function,
|
|
210
|
-
required: true
|
|
211
|
-
default: void 0
|
|
191
|
+
required: true
|
|
212
192
|
},
|
|
213
193
|
onZoomIn: {
|
|
214
194
|
type: Function,
|
|
215
|
-
required: true
|
|
216
|
-
default: void 0
|
|
195
|
+
required: true
|
|
217
196
|
},
|
|
218
197
|
onClose: {
|
|
219
198
|
type: Function,
|
|
220
|
-
required: true
|
|
221
|
-
default: void 0
|
|
199
|
+
required: true
|
|
222
200
|
},
|
|
223
201
|
onReset: {
|
|
224
202
|
type: Function,
|
|
225
|
-
required: true
|
|
226
|
-
default: void 0
|
|
203
|
+
required: true
|
|
227
204
|
}
|
|
228
205
|
},
|
|
229
206
|
name: "ImagePreviewFooter"
|
|
230
207
|
});
|
|
231
|
-
|
|
208
|
+
//#endregion
|
|
209
|
+
export { Footer as default };
|
package/dist/Preview/PrevNext.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fragment, createVNode, defineComponent } from "vue";
|
|
2
2
|
import { clsx } from "@v-c/util";
|
|
3
|
-
|
|
3
|
+
//#region src/Preview/PrevNext.tsx
|
|
4
|
+
var PrevNext = /* @__PURE__ */ defineComponent((props) => {
|
|
4
5
|
return () => {
|
|
5
6
|
const { prefixCls, onActive, current, count, icons } = props;
|
|
6
7
|
const switchCls = `${prefixCls}-switch`;
|
|
@@ -26,30 +27,26 @@ var PrevNext_default = /* @__PURE__ */ defineComponent((props) => {
|
|
|
26
27
|
props: {
|
|
27
28
|
prefixCls: {
|
|
28
29
|
type: String,
|
|
29
|
-
required: true
|
|
30
|
-
default: void 0
|
|
30
|
+
required: true
|
|
31
31
|
},
|
|
32
32
|
onActive: {
|
|
33
33
|
type: Function,
|
|
34
|
-
required: true
|
|
35
|
-
default: void 0
|
|
34
|
+
required: true
|
|
36
35
|
},
|
|
37
36
|
current: {
|
|
38
37
|
type: Number,
|
|
39
|
-
required: true
|
|
40
|
-
default: void 0
|
|
38
|
+
required: true
|
|
41
39
|
},
|
|
42
40
|
count: {
|
|
43
41
|
type: Number,
|
|
44
|
-
required: true
|
|
45
|
-
default: void 0
|
|
42
|
+
required: true
|
|
46
43
|
},
|
|
47
44
|
icons: {
|
|
48
45
|
type: Object,
|
|
49
|
-
required: true
|
|
50
|
-
default: void 0
|
|
46
|
+
required: true
|
|
51
47
|
}
|
|
52
48
|
},
|
|
53
49
|
name: "ImagePreviewPrevNext"
|
|
54
50
|
});
|
|
55
|
-
|
|
51
|
+
//#endregion
|
|
52
|
+
export { PrevNext as default };
|
package/dist/Preview/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { CSSProperties } from 'vue';
|
|
|
4
4
|
import { TransformAction, TransformType } from '../hooks/useImageTransform';
|
|
5
5
|
import { ImgInfo } from '../Image';
|
|
6
6
|
import { FooterSemanticName } from './Footer';
|
|
7
|
-
export type PreviewSemanticName = 'root' | 'mask' | 'body' | FooterSemanticName;
|
|
7
|
+
export type PreviewSemanticName = 'root' | 'mask' | 'body' | 'close' | FooterSemanticName;
|
|
8
8
|
export interface OperationIcons {
|
|
9
9
|
rotateLeft?: VueNode;
|
|
10
10
|
rotateRight?: VueNode;
|
|
@@ -60,7 +60,9 @@ export interface InternalPreviewConfig {
|
|
|
60
60
|
open?: boolean;
|
|
61
61
|
getContainer?: PortalProps['getContainer'];
|
|
62
62
|
zIndex?: number;
|
|
63
|
+
maskClosable?: boolean;
|
|
63
64
|
afterOpenChange?: (open: boolean) => void;
|
|
65
|
+
focusTrap?: boolean;
|
|
64
66
|
movable?: boolean;
|
|
65
67
|
icons?: OperationIcons;
|
|
66
68
|
closeIcon?: VueNode | boolean | null;
|
package/dist/Preview/index.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { usePreviewGroupContext } from "../context.js";
|
|
2
2
|
import useStatus from "../hooks/useStatus.js";
|
|
3
|
-
import { canUseDom } from "../util/dist/Dom/canUseDom.js";
|
|
4
|
-
import { useLockFocus } from "../util/dist/Dom/focus.js";
|
|
5
|
-
import { KeyCodeStr } from "../util/dist/KeyCode.js";
|
|
6
|
-
import { getTransitionProps } from "../util/dist/utils/transition.js";
|
|
7
3
|
import useImageTransform from "../hooks/useImageTransform.js";
|
|
8
|
-
import
|
|
4
|
+
import "../previewConfig.js";
|
|
9
5
|
import useMouseEvent from "../hooks/useMouseEvent.js";
|
|
10
6
|
import useTouchEvent from "../hooks/useTouchEvent.js";
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
7
|
+
import CloseBtn from "./CloseBtn.js";
|
|
8
|
+
import Footer from "./Footer.js";
|
|
9
|
+
import PrevNext from "./PrevNext.js";
|
|
14
10
|
import { Transition, computed, createVNode, defineComponent, mergeDefaults, mergeProps, nextTick, shallowRef, watch, watchEffect } from "vue";
|
|
15
11
|
import { clsx } from "@v-c/util";
|
|
16
12
|
import Portal from "@v-c/portal";
|
|
17
|
-
|
|
13
|
+
import canUseDom from "@v-c/util/dist/Dom/canUseDom";
|
|
14
|
+
import { useLockFocus } from "@v-c/util/dist/Dom/focus";
|
|
15
|
+
import { KeyCodeStr } from "@v-c/util/dist/KeyCode";
|
|
16
|
+
import { getTransitionProps } from "@v-c/util/dist/utils/transition";
|
|
17
|
+
//#region src/Preview/index.tsx
|
|
18
|
+
var Preview = /* @__PURE__ */ defineComponent((props, { attrs, slots }) => {
|
|
18
19
|
const imgEl = shallowRef();
|
|
19
20
|
const wrapperRef = shallowRef(null);
|
|
21
|
+
const triggerRef = shallowRef(null);
|
|
20
22
|
const groupContext = usePreviewGroupContext();
|
|
21
23
|
const showLeftOrRightSwitches = computed(() => !!groupContext && (props.count ?? 1) > 1);
|
|
22
24
|
const showOperationsProgress = computed(() => !!groupContext && (props.count ?? 1) >= 1);
|
|
@@ -33,6 +35,9 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
|
|
|
33
35
|
watch(() => props.open, (open) => {
|
|
34
36
|
if (!open) resetTransform("close");
|
|
35
37
|
});
|
|
38
|
+
watch(() => props.open, (open) => {
|
|
39
|
+
if (open && canUseDom()) triggerRef.value = document.activeElement;
|
|
40
|
+
});
|
|
36
41
|
const onDoubleClick = (event) => {
|
|
37
42
|
if (!props.open) return;
|
|
38
43
|
if (transform.value.scale !== 1) updateTransform({
|
|
@@ -76,10 +81,6 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
|
|
|
76
81
|
const onKeyDown = (event) => {
|
|
77
82
|
if (!props.open) return;
|
|
78
83
|
const { key } = event;
|
|
79
|
-
if (key === KeyCodeStr.Escape) {
|
|
80
|
-
props.onClose?.();
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
84
|
if (showLeftOrRightSwitches.value) {
|
|
84
85
|
if (key === KeyCodeStr.ArrowLeft) onActive(-1);
|
|
85
86
|
else if (key === KeyCodeStr.ArrowRight) onActive(1);
|
|
@@ -104,6 +105,8 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
|
|
|
104
105
|
if (!nextVisible) {
|
|
105
106
|
animatedVisible.value = false;
|
|
106
107
|
portalRender.value = false;
|
|
108
|
+
triggerRef.value?.focus?.();
|
|
109
|
+
triggerRef.value = null;
|
|
107
110
|
}
|
|
108
111
|
props.afterOpenChange?.(nextVisible);
|
|
109
112
|
};
|
|
@@ -114,9 +117,10 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
|
|
|
114
117
|
src: computed(() => props.src),
|
|
115
118
|
fallback: computed(() => props.fallback)
|
|
116
119
|
});
|
|
117
|
-
|
|
120
|
+
const focusTrap = computed(() => props.focusTrap ?? true);
|
|
121
|
+
useLockFocus(computed(() => !!(focusTrap.value && props.open && portalRender.value)), () => wrapperRef.value);
|
|
118
122
|
return () => {
|
|
119
|
-
const { prefixCls, rootClassName, src, alt, imageInfo, open, closeIcon, getContainer, current = 0, count = 1, countRender, motionName = "fade", imageRender, imgCommonProps, actionsRender = slots?.actionsRender, classNames = {}, styles = {}, mousePosition, zIndex, icons = {}, movable = true } = props;
|
|
123
|
+
const { prefixCls, rootClassName, src, alt, imageInfo, open, closeIcon, getContainer, current = 0, count = 1, countRender, motionName = "fade", imageRender, imgCommonProps, actionsRender = slots?.actionsRender, classNames = {}, styles = {}, mousePosition, zIndex, icons = {}, movable = true, maskClosable = true } = props;
|
|
120
124
|
const bodyStyle = { ...styles.body ?? {} };
|
|
121
125
|
if (mousePosition) bodyStyle.transformOrigin = `${mousePosition.x}px ${mousePosition.y}px`;
|
|
122
126
|
const image = {
|
|
@@ -160,7 +164,10 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
|
|
|
160
164
|
return createVNode(Portal, {
|
|
161
165
|
"open": open || animatedVisible.value || portalRender.value,
|
|
162
166
|
"getContainer": getContainer,
|
|
163
|
-
"autoLock": open || animatedVisible.value
|
|
167
|
+
"autoLock": open || animatedVisible.value,
|
|
168
|
+
"onEsc": ({ top }) => {
|
|
169
|
+
if (top) props.onClose?.();
|
|
170
|
+
}
|
|
164
171
|
}, { default: () => [createVNode(Transition, mergeProps(transitionProps, {
|
|
165
172
|
"onAfterEnter": () => onVisibleChanged(true),
|
|
166
173
|
"onAfterLeave": () => onVisibleChanged(false)
|
|
@@ -178,7 +185,7 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
|
|
|
178
185
|
createVNode("div", {
|
|
179
186
|
"class": clsx(`${prefixCls}-mask`, classNames.mask),
|
|
180
187
|
"style": styles.mask,
|
|
181
|
-
"onClick": () => props.onClose?.()
|
|
188
|
+
"onClick": maskClosable ? () => props.onClose?.() : void 0
|
|
182
189
|
}, null),
|
|
183
190
|
createVNode("div", {
|
|
184
191
|
"class": clsx(`${prefixCls}-body`, classNames.body),
|
|
@@ -188,19 +195,21 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
|
|
|
188
195
|
image,
|
|
189
196
|
...groupContext ? { current } : {}
|
|
190
197
|
}) : imgNode]),
|
|
191
|
-
closeIcon !== false && closeIcon !== null && createVNode(
|
|
198
|
+
closeIcon !== false && closeIcon !== null && createVNode(CloseBtn, {
|
|
192
199
|
"prefixCls": prefixCls,
|
|
193
200
|
"icon": closeIcon === true ? icons.close : closeIcon || icons.close,
|
|
194
|
-
"onClick": () => props.onClose?.()
|
|
201
|
+
"onClick": () => props.onClose?.(),
|
|
202
|
+
"className": classNames.close,
|
|
203
|
+
"style": styles.close
|
|
195
204
|
}, null),
|
|
196
|
-
showLeftOrRightSwitches.value && createVNode(
|
|
205
|
+
showLeftOrRightSwitches.value && createVNode(PrevNext, {
|
|
197
206
|
"prefixCls": prefixCls,
|
|
198
207
|
"current": current,
|
|
199
208
|
"count": count,
|
|
200
209
|
"icons": icons,
|
|
201
210
|
"onActive": onActive
|
|
202
211
|
}, null),
|
|
203
|
-
createVNode(
|
|
212
|
+
createVNode(Footer, {
|
|
204
213
|
"prefixCls": prefixCls,
|
|
205
214
|
"showProgress": showOperationsProgress.value,
|
|
206
215
|
"current": current,
|
|
@@ -233,8 +242,7 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
|
|
|
233
242
|
props: /* @__PURE__ */ mergeDefaults({
|
|
234
243
|
prefixCls: {
|
|
235
244
|
type: String,
|
|
236
|
-
required: true
|
|
237
|
-
default: void 0
|
|
245
|
+
required: true
|
|
238
246
|
},
|
|
239
247
|
classNames: {
|
|
240
248
|
type: Object,
|
|
@@ -293,8 +301,7 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
|
|
|
293
301
|
},
|
|
294
302
|
mousePosition: {
|
|
295
303
|
type: [null, Object],
|
|
296
|
-
required: true
|
|
297
|
-
default: void 0
|
|
304
|
+
required: true
|
|
298
305
|
},
|
|
299
306
|
rootClassName: {
|
|
300
307
|
type: String,
|
|
@@ -345,11 +352,21 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
|
|
|
345
352
|
required: false,
|
|
346
353
|
default: void 0
|
|
347
354
|
},
|
|
355
|
+
maskClosable: {
|
|
356
|
+
type: Boolean,
|
|
357
|
+
required: false,
|
|
358
|
+
default: void 0
|
|
359
|
+
},
|
|
348
360
|
afterOpenChange: {
|
|
349
361
|
type: Function,
|
|
350
362
|
required: false,
|
|
351
363
|
default: void 0
|
|
352
364
|
},
|
|
365
|
+
focusTrap: {
|
|
366
|
+
type: Boolean,
|
|
367
|
+
required: false,
|
|
368
|
+
default: void 0
|
|
369
|
+
},
|
|
353
370
|
movable: {
|
|
354
371
|
type: Boolean,
|
|
355
372
|
required: false,
|
|
@@ -406,4 +423,5 @@ var Preview_default = /* @__PURE__ */ defineComponent((props, { attrs, slots })
|
|
|
406
423
|
name: "ImagePreview",
|
|
407
424
|
inheritAttrs: false
|
|
408
425
|
});
|
|
409
|
-
|
|
426
|
+
//#endregion
|
|
427
|
+
export { Preview as default };
|
package/dist/PreviewGroup.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { useMergedState } from "./util/dist/hooks/useMergedState.js";
|
|
2
1
|
import { usePreviewGroupProvider } from "./context.js";
|
|
3
|
-
import
|
|
2
|
+
import Preview from "./Preview/index.js";
|
|
4
3
|
import usePreviewItems from "./hooks/usePreviewItems.js";
|
|
5
4
|
import { Fragment, computed, createVNode, defineComponent, mergeDefaults, mergeProps, shallowRef, toRef, watch } from "vue";
|
|
6
|
-
|
|
5
|
+
import useMergedState from "@v-c/util/dist/hooks/useMergedState";
|
|
6
|
+
//#region src/PreviewGroup.tsx
|
|
7
|
+
var PreviewGroup = /* @__PURE__ */ defineComponent((props, { slots, emit }) => {
|
|
7
8
|
const mergedPreviewConfig = computed(() => {
|
|
8
9
|
if (props.preview && typeof props.preview === "object") return props.preview;
|
|
9
10
|
return {};
|
|
@@ -54,7 +55,7 @@ var PreviewGroup_default = /* @__PURE__ */ defineComponent((props, { slots, emit
|
|
|
54
55
|
const { src, ...imgCommonProps } = itemsList[current.value]?.data || {};
|
|
55
56
|
const countRender = slots.countRender ? (currentNum, total) => slots.countRender?.(currentNum, total) : mergedPreviewConfig.value.countRender;
|
|
56
57
|
const { open: _open, current: _current, onOpenChange: _onOpenChange, onChange: _onChange, ...restPreviewConfig } = mergedPreviewConfig.value;
|
|
57
|
-
return createVNode(Fragment, null, [slots.default?.(), createVNode(
|
|
58
|
+
return createVNode(Fragment, null, [slots.default?.(), createVNode(Preview, mergeProps({
|
|
58
59
|
"aria-hidden": !isShowPreview.value,
|
|
59
60
|
"open": isShowPreview.value,
|
|
60
61
|
"prefixCls": props.previewPrefixCls,
|
|
@@ -130,4 +131,5 @@ var PreviewGroup_default = /* @__PURE__ */ defineComponent((props, { slots, emit
|
|
|
130
131
|
inheritAttrs: false,
|
|
131
132
|
emits: ["change"]
|
|
132
133
|
});
|
|
133
|
-
|
|
134
|
+
//#endregion
|
|
135
|
+
export { PreviewGroup as default };
|
package/dist/common.js
CHANGED
package/dist/context.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { inject, provide } from "vue";
|
|
2
|
+
//#region src/context.ts
|
|
2
3
|
var PreviewGroupContextKey = Symbol("PreviewGroupContext");
|
|
3
4
|
function usePreviewGroupContext() {
|
|
4
5
|
return inject(PreviewGroupContextKey, null);
|
|
@@ -6,4 +7,5 @@ function usePreviewGroupContext() {
|
|
|
6
7
|
function usePreviewGroupProvider(value) {
|
|
7
8
|
provide(PreviewGroupContextKey, value);
|
|
8
9
|
}
|
|
10
|
+
//#endregion
|
|
9
11
|
export { usePreviewGroupContext, usePreviewGroupProvider };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getClientSize } from "./util.js";
|
|
2
|
+
//#region src/getFixScaleEleTransPosition.ts
|
|
2
3
|
function fixPoint(key, start, width, clientWidth) {
|
|
3
4
|
const startAddWidth = start + width;
|
|
4
5
|
const offsetStart = (width - clientWidth) / 2;
|
|
@@ -8,6 +9,18 @@ function fixPoint(key, start, width, clientWidth) {
|
|
|
8
9
|
} else if (start < 0 || startAddWidth > clientWidth) return { [key]: start < 0 ? offsetStart : -offsetStart };
|
|
9
10
|
return {};
|
|
10
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Fix positon x,y point when
|
|
14
|
+
*
|
|
15
|
+
* Ele width && height < client
|
|
16
|
+
* - Back origin
|
|
17
|
+
*
|
|
18
|
+
* - Ele width | height > clientWidth | clientHeight
|
|
19
|
+
* - left | top > 0 -> Back 0
|
|
20
|
+
* - left | top + width | height < clientWidth | clientHeight -> Back left | top + width | height === clientWidth | clientHeight
|
|
21
|
+
*
|
|
22
|
+
* Regardless of other
|
|
23
|
+
*/
|
|
11
24
|
function getFixScaleEleTransPosition(width, height, left, top) {
|
|
12
25
|
const { width: clientWidth, height: clientHeight } = getClientSize();
|
|
13
26
|
let fixPos = null;
|
|
@@ -21,4 +34,5 @@ function getFixScaleEleTransPosition(width, height, left, top) {
|
|
|
21
34
|
};
|
|
22
35
|
return fixPos;
|
|
23
36
|
}
|
|
37
|
+
//#endregion
|
|
24
38
|
export { getFixScaleEleTransPosition as default };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getClientSize } from "../util.js";
|
|
2
|
-
import { isEqual_default } from "../util/dist/isEqual.js";
|
|
3
|
-
import { raf_default } from "../util/dist/raf.js";
|
|
4
2
|
import { ref, shallowRef } from "vue";
|
|
3
|
+
import isEqual from "@v-c/util/dist/isEqual";
|
|
4
|
+
import raf from "@v-c/util/dist/raf";
|
|
5
|
+
//#region src/hooks/useImageTransform.ts
|
|
5
6
|
var initialTransform = {
|
|
6
7
|
x: 0,
|
|
7
8
|
y: 0,
|
|
@@ -17,15 +18,16 @@ function useImageTransform(imgRef, minScale, maxScale, onTransform) {
|
|
|
17
18
|
const resetTransform = (action) => {
|
|
18
19
|
const oldTransform = transform.value;
|
|
19
20
|
transform.value = initialTransform;
|
|
20
|
-
if (!
|
|
21
|
+
if (!isEqual(initialTransform, oldTransform)) onTransform?.({
|
|
21
22
|
transform: initialTransform,
|
|
22
23
|
action
|
|
23
24
|
});
|
|
24
25
|
};
|
|
26
|
+
/** Direct update transform */
|
|
25
27
|
const updateTransform = (newTransform, action) => {
|
|
26
28
|
if (frame.value === null) {
|
|
27
29
|
queue.value = [];
|
|
28
|
-
frame.value =
|
|
30
|
+
frame.value = raf(() => {
|
|
29
31
|
let memoState = transform.value;
|
|
30
32
|
queue.value.forEach((queueState) => {
|
|
31
33
|
memoState = {
|
|
@@ -46,6 +48,7 @@ function useImageTransform(imgRef, minScale, maxScale, onTransform) {
|
|
|
46
48
|
...newTransform
|
|
47
49
|
});
|
|
48
50
|
};
|
|
51
|
+
/** Scale according to the position of centerX and centerY */
|
|
49
52
|
const dispatchZoomChange = (ratio, action, centerX, centerY, isTouch) => {
|
|
50
53
|
if (!imgRef.value) return;
|
|
51
54
|
const { width, height, offsetWidth, offsetHeight, offsetLeft, offsetTop } = imgRef.value;
|
|
@@ -61,15 +64,23 @@ function useImageTransform(imgRef, minScale, maxScale, onTransform) {
|
|
|
61
64
|
newScale = isTouch ? newScale : _minScale;
|
|
62
65
|
newRatio = newScale / _transform.scale;
|
|
63
66
|
}
|
|
67
|
+
/** Default center point scaling */
|
|
64
68
|
const mergedCenterX = centerX ?? innerWidth / 2;
|
|
65
69
|
const mergedCenterY = centerY ?? innerHeight / 2;
|
|
66
70
|
const diffRatio = newRatio - 1;
|
|
71
|
+
/** Deviation calculated from image size */
|
|
67
72
|
const diffImgX = diffRatio * width * .5;
|
|
68
73
|
const diffImgY = diffRatio * height * .5;
|
|
74
|
+
/** The difference between the click position and the edge of the document */
|
|
69
75
|
const diffOffsetLeft = diffRatio * (mergedCenterX - _transform.x - offsetLeft);
|
|
70
76
|
const diffOffsetTop = diffRatio * (mergedCenterY - _transform.y - offsetTop);
|
|
77
|
+
/** Final positioning */
|
|
71
78
|
let newX = _transform.x - (diffOffsetLeft - diffImgX);
|
|
72
79
|
let newY = _transform.y - (diffOffsetTop - diffImgY);
|
|
80
|
+
/**
|
|
81
|
+
* When zooming the image
|
|
82
|
+
* When the image size is smaller than the width and height of the window, the position is initialized
|
|
83
|
+
*/
|
|
73
84
|
if (ratio < 1 && newScale === 1) {
|
|
74
85
|
const mergedWidth = offsetWidth * newScale;
|
|
75
86
|
const mergedHeight = offsetHeight * newScale;
|
|
@@ -92,4 +103,5 @@ function useImageTransform(imgRef, minScale, maxScale, onTransform) {
|
|
|
92
103
|
dispatchZoomChange
|
|
93
104
|
};
|
|
94
105
|
}
|
|
106
|
+
//#endregion
|
|
95
107
|
export { useImageTransform as default };
|