@v-c/image 1.0.1 → 1.0.3
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 +1 -1
- package/dist/Preview/index.js +1 -1
- package/dist/portal/dist/Portal.js +3 -2
- package/dist/util/dist/Dom/findDOMNode.js +20 -0
- package/dist/util/dist/getScrollBarSize.js +42 -44
- package/package.json +12 -12
- package/LICENSE +0 -21
- package/dist/Image.cjs +0 -231
- package/dist/Preview/CloseBtn.cjs +0 -44
- package/dist/Preview/Footer.cjs +0 -234
- package/dist/Preview/PrevNext.cjs +0 -59
- package/dist/Preview/index.cjs +0 -404
- package/dist/PreviewGroup.cjs +0 -138
- package/dist/common.cjs +0 -13
- package/dist/context.cjs +0 -11
- package/dist/getFixScaleEleTransPosition.cjs +0 -28
- package/dist/hooks/useImageTransform.cjs +0 -99
- package/dist/hooks/useMouseEvent.cjs +0 -96
- package/dist/hooks/usePreviewItems.cjs +0 -48
- package/dist/hooks/useRegisterImage.cjs +0 -28
- package/dist/hooks/useStatus.cjs +0 -49
- package/dist/hooks/useTouchEvent.cjs +0 -125
- package/dist/index.cjs +0 -11
- package/dist/interface.cjs +0 -1
- package/dist/portal/dist/Context.cjs +0 -12
- package/dist/portal/dist/Portal.cjs +0 -100
- package/dist/portal/dist/index.cjs +0 -3
- package/dist/portal/dist/useDom.cjs +0 -47
- package/dist/portal/dist/useEscKeyDown.cjs +0 -57
- package/dist/portal/dist/useScrollLocker.cjs +0 -28
- package/dist/portal/dist/util.cjs +0 -4
- package/dist/previewConfig.cjs +0 -5
- package/dist/util/dist/Dom/canUseDom.cjs +0 -4
- package/dist/util/dist/Dom/contains.cjs +0 -11
- package/dist/util/dist/Dom/dynamicCSS.cjs +0 -80
- package/dist/util/dist/KeyCode.cjs +0 -81
- package/dist/util/dist/RenderComponent.cjs +0 -29
- package/dist/util/dist/classnames.cjs +0 -36
- package/dist/util/dist/getScrollBarSize.cjs +0 -53
- package/dist/util/dist/hooks/useControlledState.cjs +0 -1
- package/dist/util/dist/hooks/useId.cjs +0 -5
- package/dist/util/dist/hooks/useMergedState.cjs +0 -24
- package/dist/util/dist/index.cjs +0 -8
- package/dist/util/dist/isEqual.cjs +0 -27
- package/dist/util/dist/omit.cjs +0 -8
- package/dist/util/dist/pickAttrs.cjs +0 -39
- package/dist/util/dist/props-util/index.cjs +0 -47
- package/dist/util/dist/raf.cjs +0 -36
- package/dist/util/dist/type.cjs +0 -2
- package/dist/util/dist/utils/transition.cjs +0 -21
- package/dist/util/dist/warning.cjs +0 -37
- package/dist/util.cjs +0 -27
package/dist/PreviewGroup.cjs
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_useMergedState = require("./util/dist/hooks/useMergedState.cjs");
|
|
6
|
-
const require_context = require("./context.cjs");
|
|
7
|
-
const require_index = require("./Preview/index.cjs");
|
|
8
|
-
const require_usePreviewItems = require("./hooks/usePreviewItems.cjs");
|
|
9
|
-
let vue = require("vue");
|
|
10
|
-
var PreviewGroup = /* @__PURE__ */ (0, vue.defineComponent)((props, { slots, emit }) => {
|
|
11
|
-
const mergedPreviewConfig = (0, vue.computed)(() => {
|
|
12
|
-
if (props.preview && typeof props.preview === "object") return props.preview;
|
|
13
|
-
return {};
|
|
14
|
-
});
|
|
15
|
-
const previewOpen = (0, vue.computed)(() => mergedPreviewConfig.value.open);
|
|
16
|
-
const previewCurrent = (0, vue.computed)(() => mergedPreviewConfig.value.current);
|
|
17
|
-
const [mergedItems, register, fromItems] = require_usePreviewItems.default((0, vue.toRef)(props, "items"));
|
|
18
|
-
const [current, setCurrent] = require_useMergedState.useMergedState(0, { value: previewCurrent });
|
|
19
|
-
const keepOpenIndex = (0, vue.shallowRef)(false);
|
|
20
|
-
const [isShowPreview, setShowPreview] = require_useMergedState.useMergedState(!!previewOpen.value, { value: previewOpen });
|
|
21
|
-
const triggerShowPreview = (next) => {
|
|
22
|
-
const prev = isShowPreview.value;
|
|
23
|
-
setShowPreview(next);
|
|
24
|
-
if (next !== prev) mergedPreviewConfig.value.onOpenChange?.(next, { current: current.value });
|
|
25
|
-
};
|
|
26
|
-
const mousePosition = (0, vue.shallowRef)(null);
|
|
27
|
-
const onPreviewFromImage = (id, imageSrc, mouseX, mouseY) => {
|
|
28
|
-
const itemsList = mergedItems.value;
|
|
29
|
-
const index = fromItems.value ? itemsList.findIndex((item) => item.data.src === imageSrc) : itemsList.findIndex((item) => item.id === id);
|
|
30
|
-
setCurrent(index < 0 ? 0 : index);
|
|
31
|
-
triggerShowPreview(true);
|
|
32
|
-
mousePosition.value = {
|
|
33
|
-
x: mouseX,
|
|
34
|
-
y: mouseY
|
|
35
|
-
};
|
|
36
|
-
keepOpenIndex.value = true;
|
|
37
|
-
};
|
|
38
|
-
(0, vue.watch)(isShowPreview, (open) => {
|
|
39
|
-
if (open) {
|
|
40
|
-
if (!keepOpenIndex.value) setCurrent(0);
|
|
41
|
-
} else keepOpenIndex.value = false;
|
|
42
|
-
});
|
|
43
|
-
const onInternalChange = (next, prev) => {
|
|
44
|
-
setCurrent(next);
|
|
45
|
-
mergedPreviewConfig.value.onChange?.(next, prev);
|
|
46
|
-
emit("change", next, prev);
|
|
47
|
-
};
|
|
48
|
-
const onPreviewClose = () => {
|
|
49
|
-
triggerShowPreview(false);
|
|
50
|
-
mousePosition.value = null;
|
|
51
|
-
};
|
|
52
|
-
require_context.usePreviewGroupProvider({
|
|
53
|
-
register,
|
|
54
|
-
onPreview: onPreviewFromImage
|
|
55
|
-
});
|
|
56
|
-
return () => {
|
|
57
|
-
const itemsList = mergedItems.value;
|
|
58
|
-
const { src, ...imgCommonProps } = itemsList[current.value]?.data || {};
|
|
59
|
-
const countRender = slots.countRender ? (currentNum, total) => slots.countRender?.(currentNum, total) : mergedPreviewConfig.value.countRender;
|
|
60
|
-
const { open: _open, current: _current, onOpenChange: _onOpenChange, onChange: _onChange, ...restPreviewConfig } = mergedPreviewConfig.value;
|
|
61
|
-
return (0, vue.createVNode)(vue.Fragment, null, [slots.default?.(), (0, vue.createVNode)(require_index.default, (0, vue.mergeProps)({
|
|
62
|
-
"aria-hidden": !isShowPreview.value,
|
|
63
|
-
"open": isShowPreview.value,
|
|
64
|
-
"prefixCls": props.previewPrefixCls,
|
|
65
|
-
"onClose": onPreviewClose,
|
|
66
|
-
"mousePosition": mousePosition.value,
|
|
67
|
-
"imgCommonProps": imgCommonProps,
|
|
68
|
-
"src": src,
|
|
69
|
-
"fallback": props.fallback,
|
|
70
|
-
"icons": props.icons,
|
|
71
|
-
"current": current.value,
|
|
72
|
-
"count": itemsList.length,
|
|
73
|
-
"onChange": onInternalChange
|
|
74
|
-
}, restPreviewConfig, {
|
|
75
|
-
"countRender": countRender,
|
|
76
|
-
"classNames": props.classNames?.popup,
|
|
77
|
-
"styles": props.styles?.popup
|
|
78
|
-
}), slots)]);
|
|
79
|
-
};
|
|
80
|
-
}, {
|
|
81
|
-
props: /* @__PURE__ */ (0, vue.mergeDefaults)({
|
|
82
|
-
previewPrefixCls: {
|
|
83
|
-
type: String,
|
|
84
|
-
required: false,
|
|
85
|
-
default: void 0
|
|
86
|
-
},
|
|
87
|
-
classNames: {
|
|
88
|
-
type: Object,
|
|
89
|
-
required: false,
|
|
90
|
-
default: void 0
|
|
91
|
-
},
|
|
92
|
-
styles: {
|
|
93
|
-
type: Object,
|
|
94
|
-
required: false,
|
|
95
|
-
default: void 0
|
|
96
|
-
},
|
|
97
|
-
icons: {
|
|
98
|
-
required: false,
|
|
99
|
-
default: void 0
|
|
100
|
-
},
|
|
101
|
-
items: {
|
|
102
|
-
type: Array,
|
|
103
|
-
required: false,
|
|
104
|
-
default: void 0
|
|
105
|
-
},
|
|
106
|
-
fallback: {
|
|
107
|
-
type: String,
|
|
108
|
-
required: false,
|
|
109
|
-
default: void 0
|
|
110
|
-
},
|
|
111
|
-
preview: {
|
|
112
|
-
type: [Boolean, Object],
|
|
113
|
-
required: false,
|
|
114
|
-
default: void 0
|
|
115
|
-
},
|
|
116
|
-
children: {
|
|
117
|
-
type: [
|
|
118
|
-
Object,
|
|
119
|
-
Function,
|
|
120
|
-
String,
|
|
121
|
-
Number,
|
|
122
|
-
null,
|
|
123
|
-
Boolean,
|
|
124
|
-
Array
|
|
125
|
-
],
|
|
126
|
-
required: false,
|
|
127
|
-
default: void 0
|
|
128
|
-
}
|
|
129
|
-
}, {
|
|
130
|
-
previewPrefixCls: "vc-image-preview",
|
|
131
|
-
icons: {}
|
|
132
|
-
}),
|
|
133
|
-
name: "ImagePreviewGroup",
|
|
134
|
-
inheritAttrs: false,
|
|
135
|
-
emits: ["change"]
|
|
136
|
-
});
|
|
137
|
-
var PreviewGroup_default = PreviewGroup;
|
|
138
|
-
exports.default = PreviewGroup_default;
|
package/dist/common.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const COMMON_PROPS = [
|
|
3
|
-
"crossOrigin",
|
|
4
|
-
"decoding",
|
|
5
|
-
"draggable",
|
|
6
|
-
"loading",
|
|
7
|
-
"referrerPolicy",
|
|
8
|
-
"sizes",
|
|
9
|
-
"srcset",
|
|
10
|
-
"useMap",
|
|
11
|
-
"alt"
|
|
12
|
-
];
|
|
13
|
-
exports.COMMON_PROPS = COMMON_PROPS;
|
package/dist/context.cjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
let vue = require("vue");
|
|
3
|
-
var PreviewGroupContextKey = Symbol("PreviewGroupContext");
|
|
4
|
-
function usePreviewGroupContext() {
|
|
5
|
-
return (0, vue.inject)(PreviewGroupContextKey, null);
|
|
6
|
-
}
|
|
7
|
-
function usePreviewGroupProvider(value) {
|
|
8
|
-
(0, vue.provide)(PreviewGroupContextKey, value);
|
|
9
|
-
}
|
|
10
|
-
exports.usePreviewGroupContext = usePreviewGroupContext;
|
|
11
|
-
exports.usePreviewGroupProvider = usePreviewGroupProvider;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_util = require("./util.cjs");
|
|
6
|
-
function fixPoint(key, start, width, clientWidth) {
|
|
7
|
-
const startAddWidth = start + width;
|
|
8
|
-
const offsetStart = (width - clientWidth) / 2;
|
|
9
|
-
if (width > clientWidth) {
|
|
10
|
-
if (start > 0) return { [key]: offsetStart };
|
|
11
|
-
if (start < 0 && startAddWidth < clientWidth) return { [key]: -offsetStart };
|
|
12
|
-
} else if (start < 0 || startAddWidth > clientWidth) return { [key]: start < 0 ? offsetStart : -offsetStart };
|
|
13
|
-
return {};
|
|
14
|
-
}
|
|
15
|
-
function getFixScaleEleTransPosition(width, height, left, top) {
|
|
16
|
-
const { width: clientWidth, height: clientHeight } = require_util.getClientSize();
|
|
17
|
-
let fixPos = null;
|
|
18
|
-
if (width <= clientWidth && height <= clientHeight) fixPos = {
|
|
19
|
-
x: 0,
|
|
20
|
-
y: 0
|
|
21
|
-
};
|
|
22
|
-
else if (width > clientWidth || height > clientHeight) fixPos = {
|
|
23
|
-
...fixPoint("x", left, width, clientWidth),
|
|
24
|
-
...fixPoint("y", top, height, clientHeight)
|
|
25
|
-
};
|
|
26
|
-
return fixPos;
|
|
27
|
-
}
|
|
28
|
-
exports.default = getFixScaleEleTransPosition;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_raf = require("../util/dist/raf.cjs");
|
|
6
|
-
const require_util = require("../util.cjs");
|
|
7
|
-
const require_isEqual = require("../util/dist/isEqual.cjs");
|
|
8
|
-
let vue = require("vue");
|
|
9
|
-
var initialTransform = {
|
|
10
|
-
x: 0,
|
|
11
|
-
y: 0,
|
|
12
|
-
rotate: 0,
|
|
13
|
-
scale: 1,
|
|
14
|
-
flipX: false,
|
|
15
|
-
flipY: false
|
|
16
|
-
};
|
|
17
|
-
function useImageTransform(imgRef, minScale, maxScale, onTransform) {
|
|
18
|
-
const frame = (0, vue.shallowRef)(null);
|
|
19
|
-
const queue = (0, vue.ref)([]);
|
|
20
|
-
const transform = (0, vue.shallowRef)(initialTransform);
|
|
21
|
-
const resetTransform = (action) => {
|
|
22
|
-
const oldTransform = transform.value;
|
|
23
|
-
transform.value = initialTransform;
|
|
24
|
-
if (!require_isEqual.isEqual_default(initialTransform, oldTransform)) onTransform?.({
|
|
25
|
-
transform: initialTransform,
|
|
26
|
-
action
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
const updateTransform = (newTransform, action) => {
|
|
30
|
-
if (frame.value === null) {
|
|
31
|
-
queue.value = [];
|
|
32
|
-
frame.value = require_raf.raf_default(() => {
|
|
33
|
-
let memoState = transform.value;
|
|
34
|
-
queue.value.forEach((queueState) => {
|
|
35
|
-
memoState = {
|
|
36
|
-
...memoState,
|
|
37
|
-
...queueState
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
frame.value = null;
|
|
41
|
-
onTransform?.({
|
|
42
|
-
transform: memoState,
|
|
43
|
-
action
|
|
44
|
-
});
|
|
45
|
-
transform.value = memoState;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
queue.value.push({
|
|
49
|
-
...transform.value,
|
|
50
|
-
...newTransform
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
const dispatchZoomChange = (ratio, action, centerX, centerY, isTouch) => {
|
|
54
|
-
if (!imgRef.value) return;
|
|
55
|
-
const { width, height, offsetWidth, offsetHeight, offsetLeft, offsetTop } = imgRef.value;
|
|
56
|
-
const _transform = transform.value;
|
|
57
|
-
const _maxScale = maxScale.value;
|
|
58
|
-
const _minScale = minScale.value;
|
|
59
|
-
let newRatio = ratio;
|
|
60
|
-
let newScale = _transform.scale * ratio;
|
|
61
|
-
if (newScale > _maxScale) {
|
|
62
|
-
newScale = _maxScale;
|
|
63
|
-
newRatio = _maxScale / _transform.scale;
|
|
64
|
-
} else if (newScale < _minScale) {
|
|
65
|
-
newScale = isTouch ? newScale : _minScale;
|
|
66
|
-
newRatio = newScale / _transform.scale;
|
|
67
|
-
}
|
|
68
|
-
const mergedCenterX = centerX ?? innerWidth / 2;
|
|
69
|
-
const mergedCenterY = centerY ?? innerHeight / 2;
|
|
70
|
-
const diffRatio = newRatio - 1;
|
|
71
|
-
const diffImgX = diffRatio * width * .5;
|
|
72
|
-
const diffImgY = diffRatio * height * .5;
|
|
73
|
-
const diffOffsetLeft = diffRatio * (mergedCenterX - _transform.x - offsetLeft);
|
|
74
|
-
const diffOffsetTop = diffRatio * (mergedCenterY - _transform.y - offsetTop);
|
|
75
|
-
let newX = _transform.x - (diffOffsetLeft - diffImgX);
|
|
76
|
-
let newY = _transform.y - (diffOffsetTop - diffImgY);
|
|
77
|
-
if (ratio < 1 && newScale === 1) {
|
|
78
|
-
const mergedWidth = offsetWidth * newScale;
|
|
79
|
-
const mergedHeight = offsetHeight * newScale;
|
|
80
|
-
const { width: clientWidth, height: clientHeight } = require_util.getClientSize();
|
|
81
|
-
if (mergedWidth <= clientWidth && mergedHeight <= clientHeight) {
|
|
82
|
-
newX = 0;
|
|
83
|
-
newY = 0;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
updateTransform({
|
|
87
|
-
x: newX,
|
|
88
|
-
y: newY,
|
|
89
|
-
scale: newScale
|
|
90
|
-
}, action);
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
transform,
|
|
94
|
-
resetTransform,
|
|
95
|
-
updateTransform,
|
|
96
|
-
dispatchZoomChange
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
exports.default = useImageTransform;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_warning = require("../util/dist/warning.cjs");
|
|
6
|
-
require("../util/dist/index.cjs");
|
|
7
|
-
const require_getFixScaleEleTransPosition = require("../getFixScaleEleTransPosition.cjs");
|
|
8
|
-
const require_previewConfig = require("../previewConfig.cjs");
|
|
9
|
-
let vue = require("vue");
|
|
10
|
-
function useMouseEvent(imgRef, movable, open, scaleStep, transform, updateTransform, dispatchZoomChange) {
|
|
11
|
-
const isMoving = (0, vue.shallowRef)(false);
|
|
12
|
-
const startPositionInfo = (0, vue.shallowRef)({
|
|
13
|
-
diffX: 0,
|
|
14
|
-
diffY: 0,
|
|
15
|
-
transformX: 0,
|
|
16
|
-
transformY: 0
|
|
17
|
-
});
|
|
18
|
-
const onMouseDown = (event) => {
|
|
19
|
-
const { x, y } = transform.value;
|
|
20
|
-
if (!movable.value || event.button !== 0) return;
|
|
21
|
-
event.preventDefault();
|
|
22
|
-
event.stopPropagation();
|
|
23
|
-
startPositionInfo.value = {
|
|
24
|
-
diffX: event.pageX - x,
|
|
25
|
-
diffY: event.pageY - y,
|
|
26
|
-
transformX: x,
|
|
27
|
-
transformY: y
|
|
28
|
-
};
|
|
29
|
-
isMoving.value = true;
|
|
30
|
-
};
|
|
31
|
-
const onMouseMove = (event) => {
|
|
32
|
-
if (open.value && isMoving.value) updateTransform({
|
|
33
|
-
x: event.pageX - startPositionInfo.value.diffX,
|
|
34
|
-
y: event.pageY - startPositionInfo.value.diffY
|
|
35
|
-
}, "move");
|
|
36
|
-
};
|
|
37
|
-
const onMouseUp = () => {
|
|
38
|
-
if (open.value && isMoving.value) {
|
|
39
|
-
const { x, y, scale, rotate } = transform.value;
|
|
40
|
-
isMoving.value = false;
|
|
41
|
-
const { transformX, transformY } = startPositionInfo.value;
|
|
42
|
-
if (!(x !== transformX && y !== transformY)) return;
|
|
43
|
-
if (!imgRef.value) return;
|
|
44
|
-
const width = imgRef.value.offsetWidth * scale;
|
|
45
|
-
const height = imgRef.value.offsetHeight * scale;
|
|
46
|
-
const { left, top } = imgRef.value.getBoundingClientRect() ?? {};
|
|
47
|
-
const isRotate = rotate % 180 !== 0;
|
|
48
|
-
const fixState = require_getFixScaleEleTransPosition.default(isRotate ? height : width, isRotate ? width : height, left, top);
|
|
49
|
-
if (fixState) updateTransform({ ...fixState }, "dragRebound");
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const onWheel = (event) => {
|
|
53
|
-
if (!open.value || event.deltaY === 0) return;
|
|
54
|
-
const scaleRatio = Math.abs(event.deltaY / 100);
|
|
55
|
-
let ratio = 1 + Math.min(scaleRatio, 1) * scaleStep.value;
|
|
56
|
-
if (event.deltaY > 0) ratio = 1 / ratio;
|
|
57
|
-
dispatchZoomChange(ratio, "wheel", event.clientX, event.clientY);
|
|
58
|
-
};
|
|
59
|
-
(0, vue.watch)([
|
|
60
|
-
open,
|
|
61
|
-
isMoving,
|
|
62
|
-
transform,
|
|
63
|
-
movable
|
|
64
|
-
], (_n, _o, onCleanup) => {
|
|
65
|
-
if (movable.value) {
|
|
66
|
-
window.addEventListener("mouseup", onMouseUp, false);
|
|
67
|
-
window.addEventListener("mousemove", onMouseMove, false);
|
|
68
|
-
try {
|
|
69
|
-
/* istanbul ignore next */
|
|
70
|
-
if (window.top !== window.self) {
|
|
71
|
-
window?.top?.addEventListener("mouseup", onMouseUp, false);
|
|
72
|
-
window?.top?.addEventListener("mousemove", onMouseMove, false);
|
|
73
|
-
}
|
|
74
|
-
} catch (e) {
|
|
75
|
-
require_warning.warning_default(false, `[vc-image] ${e}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
onCleanup(() => {
|
|
79
|
-
window.removeEventListener("mouseup", onMouseUp);
|
|
80
|
-
window.removeEventListener("mousemove", onMouseMove);
|
|
81
|
-
/* istanbul ignore next */
|
|
82
|
-
try {
|
|
83
|
-
window.top?.removeEventListener("mouseup", onMouseUp);
|
|
84
|
-
window.top?.removeEventListener("mousemove", onMouseMove);
|
|
85
|
-
} catch (error) {}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
isMoving,
|
|
90
|
-
onMouseDown,
|
|
91
|
-
onMouseMove,
|
|
92
|
-
onMouseUp,
|
|
93
|
-
onWheel
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
exports.default = useMouseEvent;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_common = require("../common.cjs");
|
|
6
|
-
let vue = require("vue");
|
|
7
|
-
function usePreviewItems(items) {
|
|
8
|
-
const images = (0, vue.shallowRef)({});
|
|
9
|
-
const registerImage = (id, data) => {
|
|
10
|
-
images.value = {
|
|
11
|
-
...images.value,
|
|
12
|
-
[id]: data
|
|
13
|
-
};
|
|
14
|
-
return () => {
|
|
15
|
-
const cloneImgs = { ...images.value };
|
|
16
|
-
delete cloneImgs[id];
|
|
17
|
-
images.value = cloneImgs;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
const mergedItems = (0, vue.shallowRef)([]);
|
|
21
|
-
(0, vue.watchEffect)(() => {
|
|
22
|
-
if (items?.value) {
|
|
23
|
-
mergedItems.value = items.value.map((item) => {
|
|
24
|
-
if (typeof item === "string") return { data: { src: item } };
|
|
25
|
-
const data = {};
|
|
26
|
-
Object.keys(item).forEach((key) => {
|
|
27
|
-
if (["src", ...require_common.COMMON_PROPS].includes(key)) data[key] = item[key];
|
|
28
|
-
});
|
|
29
|
-
return { data };
|
|
30
|
-
});
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
mergedItems.value = Object.keys(images.value).reduce((total, id) => {
|
|
34
|
-
const { canPreview, data } = images.value[id];
|
|
35
|
-
if (canPreview) total.push({
|
|
36
|
-
data,
|
|
37
|
-
id
|
|
38
|
-
});
|
|
39
|
-
return total;
|
|
40
|
-
}, []);
|
|
41
|
-
});
|
|
42
|
-
return [
|
|
43
|
-
mergedItems,
|
|
44
|
-
registerImage,
|
|
45
|
-
(0, vue.computed)(() => !!items?.value)
|
|
46
|
-
];
|
|
47
|
-
}
|
|
48
|
-
exports.default = usePreviewItems;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_context = require("../context.cjs");
|
|
6
|
-
let vue = require("vue");
|
|
7
|
-
var uid = 0;
|
|
8
|
-
function useRegisterImage(canPreview, data) {
|
|
9
|
-
uid += 1;
|
|
10
|
-
const id = (0, vue.shallowRef)(String(uid));
|
|
11
|
-
const groupContext = require_context.usePreviewGroupContext();
|
|
12
|
-
const registerData = () => ({
|
|
13
|
-
data: data.value,
|
|
14
|
-
canPreview: canPreview.value
|
|
15
|
-
});
|
|
16
|
-
let unRegister;
|
|
17
|
-
(0, vue.onMounted)(() => {
|
|
18
|
-
if (groupContext) unRegister = groupContext.register(id.value, registerData());
|
|
19
|
-
});
|
|
20
|
-
(0, vue.watch)([canPreview, data], () => {
|
|
21
|
-
if (groupContext) groupContext.register(id.value, registerData());
|
|
22
|
-
}, { deep: true });
|
|
23
|
-
(0, vue.onBeforeUnmount)(() => {
|
|
24
|
-
unRegister?.();
|
|
25
|
-
});
|
|
26
|
-
return id.value;
|
|
27
|
-
}
|
|
28
|
-
exports.default = useRegisterImage;
|
package/dist/hooks/useStatus.cjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_util = require("../util.cjs");
|
|
6
|
-
let vue = require("vue");
|
|
7
|
-
function useStatus(options) {
|
|
8
|
-
const { src, isCustomPlaceholder, fallback } = options;
|
|
9
|
-
const status = (0, vue.shallowRef)(isCustomPlaceholder?.value ? "loading" : "normal");
|
|
10
|
-
const isLoaded = (0, vue.shallowRef)(false);
|
|
11
|
-
const isError = (0, vue.computed)(() => status.value === "error");
|
|
12
|
-
(0, vue.watchEffect)((onCleanup) => {
|
|
13
|
-
let isCurrentSrc = true;
|
|
14
|
-
require_util.isImageValid(src.value || "").then((isValid) => {
|
|
15
|
-
if (!isValid && isCurrentSrc) status.value = "error";
|
|
16
|
-
});
|
|
17
|
-
onCleanup(() => {
|
|
18
|
-
isCurrentSrc = false;
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
(0, vue.watch)(() => src.value, () => {
|
|
22
|
-
isLoaded.value = false;
|
|
23
|
-
if (isCustomPlaceholder?.value && !isLoaded.value) status.value = "loading";
|
|
24
|
-
else if (isError.value) status.value = "normal";
|
|
25
|
-
}, { immediate: true });
|
|
26
|
-
const onLoad = () => {
|
|
27
|
-
isLoaded.value = true;
|
|
28
|
-
status.value = "normal";
|
|
29
|
-
};
|
|
30
|
-
const getImgRef = (img) => {
|
|
31
|
-
isLoaded.value = false;
|
|
32
|
-
if (status.value === "loading" && img?.complete && (img.naturalWidth || img.naturalHeight)) {
|
|
33
|
-
isLoaded.value = true;
|
|
34
|
-
onLoad();
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
return [
|
|
38
|
-
getImgRef,
|
|
39
|
-
(0, vue.computed)(() => {
|
|
40
|
-
if (isError.value && fallback?.value) return { src: fallback.value };
|
|
41
|
-
return {
|
|
42
|
-
onLoad,
|
|
43
|
-
src: src.value
|
|
44
|
-
};
|
|
45
|
-
}),
|
|
46
|
-
status
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
exports.default = useStatus;
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_canUseDom = require("../util/dist/Dom/canUseDom.cjs");
|
|
6
|
-
const require_getFixScaleEleTransPosition = require("../getFixScaleEleTransPosition.cjs");
|
|
7
|
-
let vue = require("vue");
|
|
8
|
-
function getDistance(a, b) {
|
|
9
|
-
const x = a.x - b.x;
|
|
10
|
-
const y = a.y - b.y;
|
|
11
|
-
return Math.hypot(x, y);
|
|
12
|
-
}
|
|
13
|
-
function getCenter(oldPoint1, oldPoint2, newPoint1, newPoint2) {
|
|
14
|
-
const distance1 = getDistance(oldPoint1, newPoint1);
|
|
15
|
-
const distance2 = getDistance(oldPoint2, newPoint2);
|
|
16
|
-
if (distance1 === 0 && distance2 === 0) return [oldPoint1.x, oldPoint1.y];
|
|
17
|
-
const ratio = distance1 / (distance1 + distance2);
|
|
18
|
-
return [oldPoint1.x + ratio * (oldPoint2.x - oldPoint1.x), oldPoint1.y + ratio * (oldPoint2.y - oldPoint1.y)];
|
|
19
|
-
}
|
|
20
|
-
function useTouchEvent(imgRef, movable, open, minScale, transform, updateTransform, dispatchZoomChange) {
|
|
21
|
-
const isTouching = (0, vue.shallowRef)(false);
|
|
22
|
-
const touchPointInfo = (0, vue.shallowRef)({
|
|
23
|
-
point1: {
|
|
24
|
-
x: 0,
|
|
25
|
-
y: 0
|
|
26
|
-
},
|
|
27
|
-
point2: {
|
|
28
|
-
x: 0,
|
|
29
|
-
y: 0
|
|
30
|
-
},
|
|
31
|
-
eventType: "none"
|
|
32
|
-
});
|
|
33
|
-
const updateTouchPointInfo = (values) => {
|
|
34
|
-
touchPointInfo.value = {
|
|
35
|
-
...touchPointInfo.value,
|
|
36
|
-
...values
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
const onTouchStart = (event) => {
|
|
40
|
-
if (!movable.value) return;
|
|
41
|
-
event.stopPropagation();
|
|
42
|
-
isTouching.value = true;
|
|
43
|
-
const { touches = [] } = event;
|
|
44
|
-
const { x, y } = transform.value;
|
|
45
|
-
if (touches.length > 1) updateTouchPointInfo({
|
|
46
|
-
point1: {
|
|
47
|
-
x: touches[0].clientX,
|
|
48
|
-
y: touches[0].clientY
|
|
49
|
-
},
|
|
50
|
-
point2: {
|
|
51
|
-
x: touches[1].clientX,
|
|
52
|
-
y: touches[1].clientY
|
|
53
|
-
},
|
|
54
|
-
eventType: "touchZoom"
|
|
55
|
-
});
|
|
56
|
-
else updateTouchPointInfo({
|
|
57
|
-
point1: {
|
|
58
|
-
x: touches[0].clientX - x,
|
|
59
|
-
y: touches[0].clientY - y
|
|
60
|
-
},
|
|
61
|
-
eventType: "move"
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
const onTouchMove = (event) => {
|
|
65
|
-
const { touches = [] } = event;
|
|
66
|
-
const { point1, point2, eventType } = touchPointInfo.value;
|
|
67
|
-
if (touches.length > 1 && eventType === "touchZoom") {
|
|
68
|
-
const newPoint1 = {
|
|
69
|
-
x: touches[0].clientX,
|
|
70
|
-
y: touches[0].clientY
|
|
71
|
-
};
|
|
72
|
-
const newPoint2 = {
|
|
73
|
-
x: touches[1].clientX,
|
|
74
|
-
y: touches[1].clientY
|
|
75
|
-
};
|
|
76
|
-
const [centerX, centerY] = getCenter(point1, point2, newPoint1, newPoint2);
|
|
77
|
-
dispatchZoomChange(getDistance(newPoint1, newPoint2) / getDistance(point1, point2), "touchZoom", centerX, centerY, true);
|
|
78
|
-
updateTouchPointInfo({
|
|
79
|
-
point1: newPoint1,
|
|
80
|
-
point2: newPoint2,
|
|
81
|
-
eventType: "touchZoom"
|
|
82
|
-
});
|
|
83
|
-
} else if (eventType === "move") {
|
|
84
|
-
updateTransform({
|
|
85
|
-
x: touches[0].clientX - point1.x,
|
|
86
|
-
y: touches[0].clientY - point1.y
|
|
87
|
-
}, "move");
|
|
88
|
-
updateTouchPointInfo({ eventType: "move" });
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
const onTouchEnd = () => {
|
|
92
|
-
if (!open.value || !imgRef.value) return;
|
|
93
|
-
if (isTouching.value) isTouching.value = false;
|
|
94
|
-
updateTouchPointInfo({ eventType: "none" });
|
|
95
|
-
const { rotate, scale } = transform.value;
|
|
96
|
-
if (minScale.value > scale) return updateTransform({
|
|
97
|
-
x: 0,
|
|
98
|
-
y: 0,
|
|
99
|
-
scale: minScale.value
|
|
100
|
-
}, "touchZoom");
|
|
101
|
-
const width = imgRef.value.offsetWidth * scale;
|
|
102
|
-
const height = imgRef.value.offsetHeight * scale;
|
|
103
|
-
const { left, top } = imgRef.value.getBoundingClientRect() ?? {};
|
|
104
|
-
const isRotate = rotate % 180 !== 0;
|
|
105
|
-
const fixState = require_getFixScaleEleTransPosition.default(isRotate ? height : width, isRotate ? width : height, left, top);
|
|
106
|
-
if (fixState) updateTransform({ ...fixState }, "dragRebound");
|
|
107
|
-
};
|
|
108
|
-
(0, vue.watchEffect)((onCleanup) => {
|
|
109
|
-
const preventDefault = (e) => {
|
|
110
|
-
e.preventDefault();
|
|
111
|
-
};
|
|
112
|
-
if (open.value && movable.value) window.addEventListener("touchmove", preventDefault, { passive: false });
|
|
113
|
-
onCleanup(() => {
|
|
114
|
-
if (!require_canUseDom.canUseDom()) return;
|
|
115
|
-
window.removeEventListener("touchmove", preventDefault);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
return {
|
|
119
|
-
isTouching,
|
|
120
|
-
onTouchStart,
|
|
121
|
-
onTouchMove,
|
|
122
|
-
onTouchEnd
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
exports.default = useTouchEvent;
|
package/dist/index.cjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_Image = require("./Image.cjs");
|
|
6
|
-
const require_PreviewGroup = require("./PreviewGroup.cjs");
|
|
7
|
-
var ExportImage = require_Image.default;
|
|
8
|
-
ExportImage.PreviewGroup = require_PreviewGroup.default;
|
|
9
|
-
var src_default = ExportImage;
|
|
10
|
-
exports.PreviewGroup = require_PreviewGroup.default;
|
|
11
|
-
exports.default = src_default;
|
package/dist/interface.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
let vue = require("vue");
|
|
2
|
-
var QueueContextKey = Symbol("QueueContextKey");
|
|
3
|
-
function useContextProvider(appendFunc) {
|
|
4
|
-
const queueCreate = appendFunc;
|
|
5
|
-
(0, vue.provide)(QueueContextKey, queueCreate);
|
|
6
|
-
return queueCreate;
|
|
7
|
-
}
|
|
8
|
-
function useContextState() {
|
|
9
|
-
return (0, vue.inject)(QueueContextKey, void 0);
|
|
10
|
-
}
|
|
11
|
-
exports.useContextProvider = useContextProvider;
|
|
12
|
-
exports.useContextState = useContextState;
|