@gx-design-vue/image 0.2.0-alpha.0 → 0.2.0-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/dist/Image.d.ts +6 -0
- package/dist/Image.js +322 -0
- package/dist/ImagePreview.d.ts +6 -0
- package/dist/ImagePreview.js +593 -0
- package/dist/g-image.esm.js +1577 -0
- package/dist/g-image.js +1 -0
- package/dist/hooks/useImageBoundary.d.ts +15 -0
- package/dist/hooks/useImageBoundary.js +24 -0
- package/dist/hooks/useImagePreview.d.ts +23 -0
- package/dist/hooks/useImagePreview.js +54 -0
- package/dist/hooks/useImageTransform.d.ts +23 -0
- package/dist/hooks/useImageTransform.js +92 -0
- package/dist/hooks/useMouseEvent.d.ts +22 -0
- package/dist/hooks/useMouseEvent.js +71 -0
- package/dist/hooks/useTouchEvent.d.ts +23 -0
- package/dist/{ImagePreview/hooks → hooks}/useTouchEvent.js +31 -32
- package/dist/index.d.ts +4 -5
- package/dist/index.js +3 -6
- package/dist/interface.d.ts +169 -0
- package/dist/interface.js +1 -0
- package/dist/style/index.d.ts +7 -0
- package/dist/{style.js → style/index.js} +19 -26
- package/dist/style/preview.d.ts +14 -0
- package/dist/style/preview.js +182 -0
- package/dist/theme/augment.d.ts +10 -0
- package/dist/theme/augment.js +1 -0
- package/dist/theme/interface/components.d.ts +10 -0
- package/dist/theme/interface/components.js +1 -0
- package/package.json +9 -8
- package/dist/GImage.d.ts +0 -162
- package/dist/GImage.js +0 -221
- package/dist/ImagePreview/Operations.d.ts +0 -83
- package/dist/ImagePreview/Operations.js +0 -71
- package/dist/ImagePreview/hooks/getFixScaleEleTransPosition.d.ts +0 -19
- package/dist/ImagePreview/hooks/getFixScaleEleTransPosition.js +0 -40
- package/dist/ImagePreview/hooks/useImageTransform.d.ts +0 -39
- package/dist/ImagePreview/hooks/useImageTransform.js +0 -105
- package/dist/ImagePreview/hooks/useMouseEvent.d.ts +0 -14
- package/dist/ImagePreview/hooks/useMouseEvent.js +0 -100
- package/dist/ImagePreview/hooks/useTouchEvent.d.ts +0 -12
- package/dist/ImagePreview/index.d.ts +0 -162
- package/dist/ImagePreview/index.js +0 -303
- package/dist/ImagePreview/props.d.ts +0 -88
- package/dist/ImagePreview/props.js +0 -53
- package/dist/ImagePreview/style.d.ts +0 -30
- package/dist/ImagePreview/style.js +0 -286
- package/dist/ImagePreview/typings.d.ts +0 -19
- package/dist/ImagePreview/typings.js +0 -1
- package/dist/ImagePreview/utils/KeyCode.d.ts +0 -438
- package/dist/ImagePreview/utils/KeyCode.js +0 -173
- package/dist/ImagePreview/utils/addEventListener.d.ts +0 -6
- package/dist/ImagePreview/utils/addEventListener.js +0 -22
- package/dist/ImagePreview/utils/util.d.ts +0 -7
- package/dist/ImagePreview/utils/util.js +0 -8
- package/dist/hooks/useFrameSetState.d.ts +0 -5
- package/dist/hooks/useFrameSetState.js +0 -33
- package/dist/image.esm.js +0 -2374
- package/dist/image.js +0 -1
- package/dist/props.d.ts +0 -84
- package/dist/props.js +0 -66
- package/dist/slots.d.ts +0 -6
- package/dist/slots.js +0 -21
- package/dist/style.d.ts +0 -9
- package/dist/typings.d.ts +0 -6
- package/dist/typings.js +0 -1
- package/dist/utils/aria.d.ts +0 -15
- package/dist/utils/aria.js +0 -16
- package/dist/utils/util.d.ts +0 -4
- package/dist/utils/util.js +0 -8
package/dist/GImage.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { imageProps } from "./props.js";
|
|
2
|
-
import ImagePreview_default from "./ImagePreview/index.js";
|
|
3
|
-
import { genImageStyle } from "./style.js";
|
|
4
|
-
import { isElement } from "./utils/util.js";
|
|
5
|
-
import { Fragment, computed, createVNode, defineComponent, mergeProps, nextTick, onMounted, ref, watch, watchEffect } from "vue";
|
|
6
|
-
import { EyeOutlined } from "@ant-design/icons-vue";
|
|
7
|
-
import { unit, useProStyle } from "@gx-design-vue/pro-provider";
|
|
8
|
-
import { classNames, getPrefixCls, getScrollContainer, getSlotsProps, isInContainer, isNumber, isString } from "@gx-design-vue/pro-utils";
|
|
9
|
-
import { isClient, useEventListener, useThrottleFn } from "@vueuse/core";
|
|
10
|
-
import { omit } from "es-toolkit";
|
|
11
|
-
|
|
12
|
-
//#region src/GImage.tsx
|
|
13
|
-
let prevOverflow = "";
|
|
14
|
-
function fromPairs(pairs) {
|
|
15
|
-
const result = {};
|
|
16
|
-
for (let i = 0; i < pairs.length; i++) {
|
|
17
|
-
const pair = pairs[i];
|
|
18
|
-
result[pair[0]] = pair[1];
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
const GImage = /* @__PURE__ */ defineComponent({
|
|
23
|
-
props: imageProps,
|
|
24
|
-
name: "GImage",
|
|
25
|
-
inheritAttrs: false,
|
|
26
|
-
emits: {
|
|
27
|
-
click: (_type) => true,
|
|
28
|
-
load: (_event) => true,
|
|
29
|
-
error: (_event) => true
|
|
30
|
-
},
|
|
31
|
-
slots: Object,
|
|
32
|
-
setup(props, { slots, emit, attrs }) {
|
|
33
|
-
const supportLoading = isClient && "loading" in HTMLImageElement.prototype;
|
|
34
|
-
const baseClassName = getPrefixCls({ suffixCls: "image" });
|
|
35
|
-
const { wrapSSR, hashId } = useProStyle("Image", [genImageStyle], baseClassName);
|
|
36
|
-
const imageViewer = ref();
|
|
37
|
-
const imageSrc = ref();
|
|
38
|
-
const hasLoadError = ref(false);
|
|
39
|
-
const isLoading = ref(true);
|
|
40
|
-
const showViewer = ref(false);
|
|
41
|
-
const container = ref();
|
|
42
|
-
const _scrollContainer = ref();
|
|
43
|
-
let stopScrollListener;
|
|
44
|
-
let stopWheelListener;
|
|
45
|
-
const isManual = computed(() => {
|
|
46
|
-
if (props.loading === "eager") return false;
|
|
47
|
-
return !supportLoading && props.loading === "lazy" || props.lazy;
|
|
48
|
-
});
|
|
49
|
-
const imageStyle = computed(() => {
|
|
50
|
-
if (isClient && props.fit) return {
|
|
51
|
-
...props.imageStyle,
|
|
52
|
-
objectFit: props.fit
|
|
53
|
-
};
|
|
54
|
-
return props.imageStyle;
|
|
55
|
-
});
|
|
56
|
-
const previewProps = computed(() => typeof props.preview === "object" ? props.preview : {});
|
|
57
|
-
const canPreview = computed(() => !!props.preview);
|
|
58
|
-
const currentImage = computed(() => {
|
|
59
|
-
const { urls = [], current = 0 } = previewProps.value;
|
|
60
|
-
if (isNumber(current)) return urls.length >= current ? current : 0;
|
|
61
|
-
const srcIndex = urls.indexOf(props.src);
|
|
62
|
-
if (srcIndex >= 0) return srcIndex;
|
|
63
|
-
return 0;
|
|
64
|
-
});
|
|
65
|
-
const width = computed(() => unit(props.width));
|
|
66
|
-
const height = computed(() => unit(props.height));
|
|
67
|
-
const loadImage = () => {
|
|
68
|
-
if (!isClient) return;
|
|
69
|
-
isLoading.value = true;
|
|
70
|
-
hasLoadError.value = false;
|
|
71
|
-
imageSrc.value = props.src;
|
|
72
|
-
};
|
|
73
|
-
function handleLoad(event) {
|
|
74
|
-
if (hasLoadError.value) return;
|
|
75
|
-
isLoading.value = false;
|
|
76
|
-
hasLoadError.value = false;
|
|
77
|
-
emit("load", event);
|
|
78
|
-
}
|
|
79
|
-
function handleError(event) {
|
|
80
|
-
isLoading.value = false;
|
|
81
|
-
hasLoadError.value = true;
|
|
82
|
-
emit("error", event);
|
|
83
|
-
}
|
|
84
|
-
function handleLazyLoad() {
|
|
85
|
-
if (isInContainer(container.value, _scrollContainer.value)) {
|
|
86
|
-
loadImage();
|
|
87
|
-
removeLazyLoadListener();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const lazyLoadHandler = useThrottleFn(handleLazyLoad, 200, true);
|
|
91
|
-
async function addLazyLoadListener() {
|
|
92
|
-
if (!isClient) return;
|
|
93
|
-
await nextTick();
|
|
94
|
-
const { scrollContainer } = props;
|
|
95
|
-
if (isElement(scrollContainer)) _scrollContainer.value = scrollContainer;
|
|
96
|
-
else if (isString(scrollContainer) && scrollContainer !== "") _scrollContainer.value = document.querySelector(scrollContainer) ?? void 0;
|
|
97
|
-
else if (container.value) _scrollContainer.value = getScrollContainer(container.value);
|
|
98
|
-
if (_scrollContainer.value) {
|
|
99
|
-
stopScrollListener = useEventListener(_scrollContainer, "scroll", lazyLoadHandler);
|
|
100
|
-
setTimeout(() => handleLazyLoad(), 100);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function removeLazyLoadListener() {
|
|
104
|
-
if (!isClient || !_scrollContainer.value || !lazyLoadHandler) return;
|
|
105
|
-
stopScrollListener?.();
|
|
106
|
-
_scrollContainer.value = void 0;
|
|
107
|
-
}
|
|
108
|
-
function wheelHandler(e) {
|
|
109
|
-
if (!e.ctrlKey) return;
|
|
110
|
-
if (e.deltaY < 0) {
|
|
111
|
-
e.preventDefault();
|
|
112
|
-
return false;
|
|
113
|
-
} else if (e.deltaY > 0) {
|
|
114
|
-
e.preventDefault();
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const clickHandler = () => {
|
|
119
|
-
emit("click", isLoading.value ? "loaded" : hasLoadError.value ? "error" : "success");
|
|
120
|
-
if (isLoading.value || hasLoadError.value) return;
|
|
121
|
-
if (canPreview.value) {
|
|
122
|
-
stopWheelListener = useEventListener("wheel", wheelHandler, { passive: false });
|
|
123
|
-
prevOverflow = document.body.style.overflow;
|
|
124
|
-
document.body.style.overflow = "hidden";
|
|
125
|
-
showViewer.value = true;
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
const closeViewer = () => {
|
|
129
|
-
stopWheelListener?.();
|
|
130
|
-
document.body.style.overflow = prevOverflow;
|
|
131
|
-
showViewer.value = false;
|
|
132
|
-
};
|
|
133
|
-
watch(() => props.src, () => {
|
|
134
|
-
if (isManual.value) {
|
|
135
|
-
isLoading.value = true;
|
|
136
|
-
hasLoadError.value = false;
|
|
137
|
-
removeLazyLoadListener();
|
|
138
|
-
addLazyLoadListener();
|
|
139
|
-
} else loadImage();
|
|
140
|
-
});
|
|
141
|
-
watchEffect(() => {
|
|
142
|
-
if (canPreview.value && showViewer.value) imageViewer.value?.setOpen(true);
|
|
143
|
-
else imageViewer.value?.setOpen(false);
|
|
144
|
-
});
|
|
145
|
-
onMounted(() => {
|
|
146
|
-
if (isManual.value) addLazyLoadListener();
|
|
147
|
-
else loadImage();
|
|
148
|
-
});
|
|
149
|
-
return () => {
|
|
150
|
-
const containerAttrs = fromPairs(Object.entries(attrs).filter(([key]) => /^(?:data-|on[A-Z])/i.test(key) || [
|
|
151
|
-
"id",
|
|
152
|
-
"style",
|
|
153
|
-
"class"
|
|
154
|
-
].includes(key)));
|
|
155
|
-
const imgAttrs = omit(attrs, Object.keys(containerAttrs));
|
|
156
|
-
const slotsProps = getSlotsProps({
|
|
157
|
-
slots,
|
|
158
|
-
props,
|
|
159
|
-
keys: [
|
|
160
|
-
"fallback",
|
|
161
|
-
"mask",
|
|
162
|
-
"placeholder"
|
|
163
|
-
],
|
|
164
|
-
render: true
|
|
165
|
-
});
|
|
166
|
-
return wrapSSR(createVNode("div", mergeProps({
|
|
167
|
-
"class": {
|
|
168
|
-
[`${hashId.value}`]: true,
|
|
169
|
-
[`${baseClassName}`]: true
|
|
170
|
-
},
|
|
171
|
-
"ref": container
|
|
172
|
-
}, containerAttrs, {
|
|
173
|
-
"style": {
|
|
174
|
-
width: unit(props.size) || width.value,
|
|
175
|
-
height: unit(props.size) || height.value,
|
|
176
|
-
...containerAttrs.style || {}
|
|
177
|
-
},
|
|
178
|
-
"onClick": () => {
|
|
179
|
-
if (hasLoadError.value) clickHandler();
|
|
180
|
-
}
|
|
181
|
-
}), [
|
|
182
|
-
hasLoadError.value ? createVNode("div", { "class": classNames(hashId.value, `${baseClassName}-error`) }, [slotsProps.fallback]) : createVNode(Fragment, null, [createVNode("img", mergeProps(imgAttrs, {
|
|
183
|
-
"src": imageSrc.value,
|
|
184
|
-
"loading": props.loading,
|
|
185
|
-
"style": imageStyle.value,
|
|
186
|
-
"class": classNames(hashId.value, props.imageClass, `${baseClassName}-img`, {
|
|
187
|
-
[`${baseClassName}-img-placeholder`]: props.placeholder === true,
|
|
188
|
-
[`${baseClassName}-img-preview`]: canPreview.value
|
|
189
|
-
}),
|
|
190
|
-
"crossorigin": props.crossOrigin,
|
|
191
|
-
"width": width.value,
|
|
192
|
-
"height": height.value,
|
|
193
|
-
"onClick": clickHandler,
|
|
194
|
-
"onLoad": handleLoad,
|
|
195
|
-
"onError": handleError
|
|
196
|
-
}), null), isLoading.value && createVNode("div", {
|
|
197
|
-
"class": classNames(`${baseClassName}-placeholder`, hashId.value),
|
|
198
|
-
"onClick": clickHandler
|
|
199
|
-
}, [slotsProps.placeholder])]),
|
|
200
|
-
previewProps.value.mask && canPreview.value && createVNode("div", {
|
|
201
|
-
"class": classNames(`${baseClassName}-mask`, previewProps.value.maskClass, hashId.value),
|
|
202
|
-
"style": { display: containerAttrs.style?.display === "none" ? "none" : void 0 }
|
|
203
|
-
}, [slotsProps.mask || createVNode("div", { "class": classNames(`${baseClassName}-mask-info`, hashId.value) }, [createVNode(EyeOutlined, null, null)])]),
|
|
204
|
-
canPreview.value && createVNode(ImagePreview_default, mergeProps({ "ref": imageViewer }, previewProps.value, {
|
|
205
|
-
"urls": previewProps.value.urls || [props.src],
|
|
206
|
-
"current": currentImage.value,
|
|
207
|
-
"onClose": () => closeViewer()
|
|
208
|
-
}), slots)
|
|
209
|
-
]));
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
GImage.isGImage = true;
|
|
214
|
-
GImage.install = (app) => {
|
|
215
|
-
app.component(GImage.name, GImage);
|
|
216
|
-
return app;
|
|
217
|
-
};
|
|
218
|
-
var GImage_default = GImage;
|
|
219
|
-
|
|
220
|
-
//#endregion
|
|
221
|
-
export { GImage_default as default };
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { PreviewPropsIcons } from "./props.js";
|
|
2
|
-
import { ImagePreviewTools } from "./typings.js";
|
|
3
|
-
import * as vue84 from "vue";
|
|
4
|
-
import { PropType } from "vue";
|
|
5
|
-
import * as _gx_design_vue_pro_utils13 from "@gx-design-vue/pro-utils";
|
|
6
|
-
import * as vue_jsx_runtime0 from "vue/jsx-runtime";
|
|
7
|
-
|
|
8
|
-
//#region src/ImagePreview/Operations.d.ts
|
|
9
|
-
declare const _default: vue84.DefineComponent<vue84.ExtractPropTypes<{
|
|
10
|
-
open: PropType<boolean>;
|
|
11
|
-
count: {
|
|
12
|
-
type: PropType<number>;
|
|
13
|
-
default: number;
|
|
14
|
-
};
|
|
15
|
-
current: {
|
|
16
|
-
type: PropType<number>;
|
|
17
|
-
default: number;
|
|
18
|
-
};
|
|
19
|
-
showSwitch: PropType<boolean>;
|
|
20
|
-
showProgress: PropType<boolean>;
|
|
21
|
-
prefixCls: PropType<string>;
|
|
22
|
-
hashId: PropType<string>;
|
|
23
|
-
zIndex: {
|
|
24
|
-
type: PropType<number>;
|
|
25
|
-
default: number;
|
|
26
|
-
};
|
|
27
|
-
icons: {
|
|
28
|
-
type: PropType<PreviewPropsIcons>;
|
|
29
|
-
default: () => PreviewPropsIcons;
|
|
30
|
-
};
|
|
31
|
-
infinite: {
|
|
32
|
-
type: PropType<boolean>;
|
|
33
|
-
default: boolean;
|
|
34
|
-
};
|
|
35
|
-
getContainer: {
|
|
36
|
-
type: PropType<string>;
|
|
37
|
-
};
|
|
38
|
-
countRender: PropType<_gx_design_vue_pro_utils13.WithFalse<(current: number, total: number) => _gx_design_vue_pro_utils13.CustomRender>>;
|
|
39
|
-
tools: PropType<ImagePreviewTools[]>;
|
|
40
|
-
onClose: PropType<() => void>;
|
|
41
|
-
onActive: PropType<(offset: number) => void>;
|
|
42
|
-
}>, () => vue_jsx_runtime0.JSX.Element, {}, {}, {}, vue84.ComponentOptionsMixin, vue84.ComponentOptionsMixin, {}, string, vue84.PublicProps, Readonly<vue84.ExtractPropTypes<{
|
|
43
|
-
open: PropType<boolean>;
|
|
44
|
-
count: {
|
|
45
|
-
type: PropType<number>;
|
|
46
|
-
default: number;
|
|
47
|
-
};
|
|
48
|
-
current: {
|
|
49
|
-
type: PropType<number>;
|
|
50
|
-
default: number;
|
|
51
|
-
};
|
|
52
|
-
showSwitch: PropType<boolean>;
|
|
53
|
-
showProgress: PropType<boolean>;
|
|
54
|
-
prefixCls: PropType<string>;
|
|
55
|
-
hashId: PropType<string>;
|
|
56
|
-
zIndex: {
|
|
57
|
-
type: PropType<number>;
|
|
58
|
-
default: number;
|
|
59
|
-
};
|
|
60
|
-
icons: {
|
|
61
|
-
type: PropType<PreviewPropsIcons>;
|
|
62
|
-
default: () => PreviewPropsIcons;
|
|
63
|
-
};
|
|
64
|
-
infinite: {
|
|
65
|
-
type: PropType<boolean>;
|
|
66
|
-
default: boolean;
|
|
67
|
-
};
|
|
68
|
-
getContainer: {
|
|
69
|
-
type: PropType<string>;
|
|
70
|
-
};
|
|
71
|
-
countRender: PropType<_gx_design_vue_pro_utils13.WithFalse<(current: number, total: number) => _gx_design_vue_pro_utils13.CustomRender>>;
|
|
72
|
-
tools: PropType<ImagePreviewTools[]>;
|
|
73
|
-
onClose: PropType<() => void>;
|
|
74
|
-
onActive: PropType<(offset: number) => void>;
|
|
75
|
-
}>> & Readonly<{}>, {
|
|
76
|
-
zIndex: number;
|
|
77
|
-
current: number;
|
|
78
|
-
infinite: boolean;
|
|
79
|
-
icons: PreviewPropsIcons;
|
|
80
|
-
count: number;
|
|
81
|
-
}, {}, {}, {}, string, vue84.ComponentProvideOptions, true, {}, any>;
|
|
82
|
-
//#endregion
|
|
83
|
-
export { _default as default };
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import props_default from "./props.js";
|
|
2
|
-
import { Fragment, Teleport, Transition, cloneVNode, createVNode, defineComponent, vShow, withDirectives } from "vue";
|
|
3
|
-
import { CloseOutlined, LeftOutlined, RightOutlined } from "@ant-design/icons-vue";
|
|
4
|
-
import { getTransitionProps } from "@gx-design-vue/pro-provider";
|
|
5
|
-
import { classNames } from "@gx-design-vue/pro-utils";
|
|
6
|
-
|
|
7
|
-
//#region src/ImagePreview/Operations.tsx
|
|
8
|
-
var Operations_default = /* @__PURE__ */ defineComponent({
|
|
9
|
-
name: "Operations",
|
|
10
|
-
inheritAttrs: false,
|
|
11
|
-
props: {
|
|
12
|
-
open: Boolean,
|
|
13
|
-
count: {
|
|
14
|
-
type: Number,
|
|
15
|
-
default: 0
|
|
16
|
-
},
|
|
17
|
-
current: {
|
|
18
|
-
type: Number,
|
|
19
|
-
default: 0
|
|
20
|
-
},
|
|
21
|
-
showSwitch: Boolean,
|
|
22
|
-
showProgress: Boolean,
|
|
23
|
-
prefixCls: String,
|
|
24
|
-
hashId: String,
|
|
25
|
-
zIndex: props_default.zIndex,
|
|
26
|
-
icons: props_default.icons,
|
|
27
|
-
infinite: props_default.infinite,
|
|
28
|
-
getContainer: props_default.getContainer,
|
|
29
|
-
countRender: props_default.countRender,
|
|
30
|
-
tools: Array,
|
|
31
|
-
onClose: Function,
|
|
32
|
-
onActive: Function
|
|
33
|
-
},
|
|
34
|
-
setup(props) {
|
|
35
|
-
const handleActive = (e, offset) => {
|
|
36
|
-
e.preventDefault();
|
|
37
|
-
e.stopPropagation();
|
|
38
|
-
props.onActive?.(offset);
|
|
39
|
-
};
|
|
40
|
-
return () => {
|
|
41
|
-
const { prefixCls, hashId, tools } = props;
|
|
42
|
-
const transitionProps = getTransitionProps(`${props.prefixCls}-fade`);
|
|
43
|
-
const toolClassName = `${prefixCls}-operations-operation`;
|
|
44
|
-
const iconClassName = `${prefixCls}-operations-icon`;
|
|
45
|
-
return createVNode(Teleport, { "to": props.getContainer || "body" }, { default: () => [createVNode(Transition, transitionProps, { default: () => [withDirectives(createVNode("div", {
|
|
46
|
-
"class": classNames(`${prefixCls}-operations-wrapper`, hashId),
|
|
47
|
-
"style": { zIndex: props.zIndex }
|
|
48
|
-
}, [
|
|
49
|
-
props.icons?.close === null ? null : createVNode("button", {
|
|
50
|
-
"class": `${prefixCls}-close ${hashId}`,
|
|
51
|
-
"onClick": props.onClose
|
|
52
|
-
}, [props.icons?.close || createVNode(CloseOutlined, null, null)]),
|
|
53
|
-
props.showSwitch && createVNode(Fragment, null, [createVNode("div", {
|
|
54
|
-
"class": classNames(`${prefixCls}-switch-left ${hashId}`, { [`${prefixCls}-switch-left-disabled`]: props.infinite ? false : props.current === 0 }),
|
|
55
|
-
"onClick": (e) => handleActive(e, -1)
|
|
56
|
-
}, [props.icons?.left || createVNode(LeftOutlined, null, null)]), createVNode("div", {
|
|
57
|
-
"class": classNames(`${prefixCls}-switch-right ${hashId}`, { [`${prefixCls}-switch-right-disabled`]: props.infinite ? false : props.current === props.count - 1 }),
|
|
58
|
-
"onClick": (e) => handleActive(e, 1)
|
|
59
|
-
}, [props.icons?.right || createVNode(RightOutlined, null, null)])]),
|
|
60
|
-
createVNode("div", { "class": `${prefixCls}-footer ${hashId}` }, [props.showProgress && createVNode("div", { "class": `${prefixCls}-progress` }, [props.countRender ? props.countRender(props.current + 1, props.count) : `${props.current + 1} / ${props.count}`]), createVNode("div", { "class": `${props.prefixCls}-operations` }, [tools?.map(({ icon: IconType, onClick, type, disabled }) => createVNode("div", {
|
|
61
|
-
"class": classNames(toolClassName, { [`${props.prefixCls}-operations-operation-disabled`]: disabled && disabled?.value }),
|
|
62
|
-
"onClick": onClick,
|
|
63
|
-
"key": type
|
|
64
|
-
}, [cloneVNode(IconType, { class: iconClassName })]))])])
|
|
65
|
-
]), [[vShow, props.open]])] })] });
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
//#endregion
|
|
71
|
-
export { Operations_default as default };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//#region src/ImagePreview/hooks/getFixScaleEleTransPosition.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Fix positon x,y point when
|
|
4
|
-
*
|
|
5
|
-
* Ele width && height < client
|
|
6
|
-
* - Back origin
|
|
7
|
-
*
|
|
8
|
-
* - Ele width | height > clientWidth | clientHeight
|
|
9
|
-
* - left | top > 0 -> Back 0
|
|
10
|
-
* - left | top + width | height < clientWidth | clientHeight -> Back left | top + width | height === clientWidth | clientHeight
|
|
11
|
-
*
|
|
12
|
-
* Regardless of other
|
|
13
|
-
*/
|
|
14
|
-
declare function getFixScaleEleTransPosition(width: number, height: number, left: number, top: number): null | {
|
|
15
|
-
x: number;
|
|
16
|
-
y: number;
|
|
17
|
-
};
|
|
18
|
-
//#endregion
|
|
19
|
-
export { getFixScaleEleTransPosition as default };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useWindowSize } from "@vueuse/core";
|
|
2
|
-
|
|
3
|
-
//#region src/ImagePreview/hooks/getFixScaleEleTransPosition.ts
|
|
4
|
-
function fixPoint(key, start, width, clientWidth) {
|
|
5
|
-
const startAddWidth = start + width;
|
|
6
|
-
const offsetStart = (width - clientWidth) / 2;
|
|
7
|
-
if (width > clientWidth) {
|
|
8
|
-
if (start > 0) return { [key]: offsetStart };
|
|
9
|
-
if (start < 0 && startAddWidth < clientWidth) return { [key]: -offsetStart };
|
|
10
|
-
} else if (start < 0 || startAddWidth > clientWidth) return { [key]: start < 0 ? offsetStart : -offsetStart };
|
|
11
|
-
return {};
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Fix positon x,y point when
|
|
15
|
-
*
|
|
16
|
-
* Ele width && height < client
|
|
17
|
-
* - Back origin
|
|
18
|
-
*
|
|
19
|
-
* - Ele width | height > clientWidth | clientHeight
|
|
20
|
-
* - left | top > 0 -> Back 0
|
|
21
|
-
* - left | top + width | height < clientWidth | clientHeight -> Back left | top + width | height === clientWidth | clientHeight
|
|
22
|
-
*
|
|
23
|
-
* Regardless of other
|
|
24
|
-
*/
|
|
25
|
-
function getFixScaleEleTransPosition(width, height, left, top) {
|
|
26
|
-
const { width: clientWidth, height: clientHeight } = useWindowSize();
|
|
27
|
-
let fixPos = null;
|
|
28
|
-
if (width <= clientWidth.value && height <= clientHeight.value) fixPos = {
|
|
29
|
-
x: 0,
|
|
30
|
-
y: 0
|
|
31
|
-
};
|
|
32
|
-
else if (width > clientWidth.value || height > clientHeight.value) fixPos = {
|
|
33
|
-
...fixPoint("x", left, width, clientWidth.value),
|
|
34
|
-
...fixPoint("y", top, height, clientHeight.value)
|
|
35
|
-
};
|
|
36
|
-
return fixPos;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
export { getFixScaleEleTransPosition as default };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Ref } from "vue";
|
|
2
|
-
|
|
3
|
-
//#region src/ImagePreview/hooks/useImageTransform.d.ts
|
|
4
|
-
interface TransformType {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
rotate: number;
|
|
8
|
-
scale: number;
|
|
9
|
-
flipX: boolean;
|
|
10
|
-
flipY: boolean;
|
|
11
|
-
}
|
|
12
|
-
type TransformAction = 'flipY' | 'flipX' | 'rotateLeft' | 'rotateRight' | 'zoomIn' | 'zoomOut' | 'close' | 'prev' | 'next' | 'wheel' | 'doubleClick' | 'move' | 'dragRebound' | 'touchZoom' | 'reset';
|
|
13
|
-
type UpdateTransformFunc = (newTransform: Partial<TransformType>, action: TransformAction) => void;
|
|
14
|
-
type DispatchZoomChangeFunc = (ratio: number, action: TransformAction, centerX?: number, centerY?: number, isTouch?: boolean) => void;
|
|
15
|
-
declare function useImageTransform(imgRef: Ref<HTMLImageElement>, minScale: Ref<number>, maxScale: Ref<number>, onTransform?: (info: {
|
|
16
|
-
transform: TransformType;
|
|
17
|
-
action: TransformAction;
|
|
18
|
-
}) => void): {
|
|
19
|
-
transform: Ref<{
|
|
20
|
-
x: number;
|
|
21
|
-
y: number;
|
|
22
|
-
rotate: number;
|
|
23
|
-
scale: number;
|
|
24
|
-
flipX: boolean;
|
|
25
|
-
flipY: boolean;
|
|
26
|
-
}, {
|
|
27
|
-
x: number;
|
|
28
|
-
y: number;
|
|
29
|
-
rotate: number;
|
|
30
|
-
scale: number;
|
|
31
|
-
flipX: boolean;
|
|
32
|
-
flipY: boolean;
|
|
33
|
-
}>;
|
|
34
|
-
resetTransform: (action: TransformAction) => void;
|
|
35
|
-
updateTransform: UpdateTransformFunc;
|
|
36
|
-
dispatchZoomChange: DispatchZoomChangeFunc;
|
|
37
|
-
};
|
|
38
|
-
//#endregion
|
|
39
|
-
export { DispatchZoomChangeFunc, TransformAction, TransformType, UpdateTransformFunc, useImageTransform as default };
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { ref } from "vue";
|
|
2
|
-
import { raf } from "@gx-design-vue/pro-utils";
|
|
3
|
-
import { useWindowSize } from "@vueuse/core";
|
|
4
|
-
import { cloneDeep, isEqual } from "es-toolkit";
|
|
5
|
-
import { useState } from "@gx-design-vue/pro-hooks";
|
|
6
|
-
|
|
7
|
-
//#region src/ImagePreview/hooks/useImageTransform.ts
|
|
8
|
-
const initialTransform = {
|
|
9
|
-
x: 0,
|
|
10
|
-
y: 0,
|
|
11
|
-
rotate: 0,
|
|
12
|
-
scale: 1,
|
|
13
|
-
flipX: false,
|
|
14
|
-
flipY: false
|
|
15
|
-
};
|
|
16
|
-
function useImageTransform(imgRef, minScale, maxScale, onTransform) {
|
|
17
|
-
const frame = ref(null);
|
|
18
|
-
const queue = ref([]);
|
|
19
|
-
const [transform, setTransform] = useState(initialTransform);
|
|
20
|
-
const resetTransform = (action) => {
|
|
21
|
-
setTransform(initialTransform);
|
|
22
|
-
if (!isEqual(initialTransform, transform.value)) onTransform?.({
|
|
23
|
-
transform: initialTransform,
|
|
24
|
-
action
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
/** Direct update transform */
|
|
28
|
-
const updateTransform = (newTransform, action) => {
|
|
29
|
-
if (frame.value === null) {
|
|
30
|
-
queue.value = [];
|
|
31
|
-
frame.value = raf(() => {
|
|
32
|
-
let memoState = cloneDeep(transform.value);
|
|
33
|
-
queue.value.forEach((queueState) => {
|
|
34
|
-
memoState = {
|
|
35
|
-
...memoState,
|
|
36
|
-
...queueState
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
frame.value = null;
|
|
40
|
-
onTransform?.({
|
|
41
|
-
transform: memoState,
|
|
42
|
-
action
|
|
43
|
-
});
|
|
44
|
-
setTransform(memoState);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
queue.value.push({
|
|
48
|
-
...transform.value,
|
|
49
|
-
...newTransform
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
/** Scale according to the position of centerX and centerY */
|
|
53
|
-
const dispatchZoomChange = (ratio, action, centerX, centerY, isTouch) => {
|
|
54
|
-
const { width, height, offsetWidth, offsetHeight, offsetLeft, offsetTop } = imgRef.value;
|
|
55
|
-
let newRatio = ratio;
|
|
56
|
-
let newScale = transform.value.scale * ratio;
|
|
57
|
-
if (newScale > maxScale.value) {
|
|
58
|
-
newScale = maxScale.value;
|
|
59
|
-
newRatio = maxScale.value / transform.value.scale;
|
|
60
|
-
} else if (newScale < minScale.value) {
|
|
61
|
-
newScale = isTouch ? newScale : minScale.value;
|
|
62
|
-
newRatio = newScale / transform.value.scale;
|
|
63
|
-
}
|
|
64
|
-
/** Default center point scaling */
|
|
65
|
-
const mergedCenterX = centerX ?? innerWidth / 2;
|
|
66
|
-
const mergedCenterY = centerY ?? innerHeight / 2;
|
|
67
|
-
const diffRatio = newRatio - 1;
|
|
68
|
-
/** Deviation calculated from image size */
|
|
69
|
-
const diffImgX = diffRatio * width * .5;
|
|
70
|
-
const diffImgY = diffRatio * height * .5;
|
|
71
|
-
/** The difference between the click position and the edge of the document */
|
|
72
|
-
const diffOffsetLeft = diffRatio * (mergedCenterX - transform.value.x - offsetLeft);
|
|
73
|
-
const diffOffsetTop = diffRatio * (mergedCenterY - transform.value.y - offsetTop);
|
|
74
|
-
/** Final positioning */
|
|
75
|
-
let newX = transform.value.x - (diffOffsetLeft - diffImgX);
|
|
76
|
-
let newY = transform.value.y - (diffOffsetTop - diffImgY);
|
|
77
|
-
/**
|
|
78
|
-
* When zooming the image
|
|
79
|
-
* When the image size is smaller than the width and height of the window, the position is initialized
|
|
80
|
-
*/
|
|
81
|
-
if (ratio < 1 && newScale === 1) {
|
|
82
|
-
const mergedWidth = offsetWidth * newScale;
|
|
83
|
-
const mergedHeight = offsetHeight * newScale;
|
|
84
|
-
const { width: clientWidth, height: clientHeight } = useWindowSize();
|
|
85
|
-
if (mergedWidth <= clientWidth.value && mergedHeight <= clientHeight.value) {
|
|
86
|
-
newX = 0;
|
|
87
|
-
newY = 0;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
updateTransform({
|
|
91
|
-
x: newX,
|
|
92
|
-
y: newY,
|
|
93
|
-
scale: newScale
|
|
94
|
-
}, action);
|
|
95
|
-
};
|
|
96
|
-
return {
|
|
97
|
-
transform,
|
|
98
|
-
resetTransform,
|
|
99
|
-
updateTransform,
|
|
100
|
-
dispatchZoomChange
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
//#endregion
|
|
105
|
-
export { useImageTransform as default };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DispatchZoomChangeFunc, TransformType, UpdateTransformFunc } from "./useImageTransform.js";
|
|
2
|
-
import { MouseEventHandler } from "../typings.js";
|
|
3
|
-
import { Ref } from "vue";
|
|
4
|
-
|
|
5
|
-
//#region src/ImagePreview/hooks/useMouseEvent.d.ts
|
|
6
|
-
declare function useMouseEvent(imgRef: Ref<HTMLImageElement>, movable: Ref<boolean>, visible: Ref<boolean>, scaleStep: Ref<number>, transform: Ref<TransformType>, updateTransform: UpdateTransformFunc, dispatchZoomChange: DispatchZoomChangeFunc): {
|
|
7
|
-
isMoving: Ref<boolean, boolean>;
|
|
8
|
-
onMouseDown: MouseEventHandler;
|
|
9
|
-
onMouseMove: MouseEventHandler;
|
|
10
|
-
onMouseUp: MouseEventHandler;
|
|
11
|
-
onWheel: (event: WheelEvent) => void;
|
|
12
|
-
};
|
|
13
|
-
//#endregion
|
|
14
|
-
export { useMouseEvent as default };
|