@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.
Files changed (69) hide show
  1. package/dist/Image.d.ts +6 -0
  2. package/dist/Image.js +322 -0
  3. package/dist/ImagePreview.d.ts +6 -0
  4. package/dist/ImagePreview.js +593 -0
  5. package/dist/g-image.esm.js +1577 -0
  6. package/dist/g-image.js +1 -0
  7. package/dist/hooks/useImageBoundary.d.ts +15 -0
  8. package/dist/hooks/useImageBoundary.js +24 -0
  9. package/dist/hooks/useImagePreview.d.ts +23 -0
  10. package/dist/hooks/useImagePreview.js +54 -0
  11. package/dist/hooks/useImageTransform.d.ts +23 -0
  12. package/dist/hooks/useImageTransform.js +92 -0
  13. package/dist/hooks/useMouseEvent.d.ts +22 -0
  14. package/dist/hooks/useMouseEvent.js +71 -0
  15. package/dist/hooks/useTouchEvent.d.ts +23 -0
  16. package/dist/{ImagePreview/hooks → hooks}/useTouchEvent.js +31 -32
  17. package/dist/index.d.ts +4 -5
  18. package/dist/index.js +3 -6
  19. package/dist/interface.d.ts +169 -0
  20. package/dist/interface.js +1 -0
  21. package/dist/style/index.d.ts +7 -0
  22. package/dist/{style.js → style/index.js} +19 -26
  23. package/dist/style/preview.d.ts +14 -0
  24. package/dist/style/preview.js +182 -0
  25. package/dist/theme/augment.d.ts +10 -0
  26. package/dist/theme/augment.js +1 -0
  27. package/dist/theme/interface/components.d.ts +10 -0
  28. package/dist/theme/interface/components.js +1 -0
  29. package/package.json +9 -8
  30. package/dist/GImage.d.ts +0 -162
  31. package/dist/GImage.js +0 -221
  32. package/dist/ImagePreview/Operations.d.ts +0 -83
  33. package/dist/ImagePreview/Operations.js +0 -71
  34. package/dist/ImagePreview/hooks/getFixScaleEleTransPosition.d.ts +0 -19
  35. package/dist/ImagePreview/hooks/getFixScaleEleTransPosition.js +0 -40
  36. package/dist/ImagePreview/hooks/useImageTransform.d.ts +0 -39
  37. package/dist/ImagePreview/hooks/useImageTransform.js +0 -105
  38. package/dist/ImagePreview/hooks/useMouseEvent.d.ts +0 -14
  39. package/dist/ImagePreview/hooks/useMouseEvent.js +0 -100
  40. package/dist/ImagePreview/hooks/useTouchEvent.d.ts +0 -12
  41. package/dist/ImagePreview/index.d.ts +0 -162
  42. package/dist/ImagePreview/index.js +0 -303
  43. package/dist/ImagePreview/props.d.ts +0 -88
  44. package/dist/ImagePreview/props.js +0 -53
  45. package/dist/ImagePreview/style.d.ts +0 -30
  46. package/dist/ImagePreview/style.js +0 -286
  47. package/dist/ImagePreview/typings.d.ts +0 -19
  48. package/dist/ImagePreview/typings.js +0 -1
  49. package/dist/ImagePreview/utils/KeyCode.d.ts +0 -438
  50. package/dist/ImagePreview/utils/KeyCode.js +0 -173
  51. package/dist/ImagePreview/utils/addEventListener.d.ts +0 -6
  52. package/dist/ImagePreview/utils/addEventListener.js +0 -22
  53. package/dist/ImagePreview/utils/util.d.ts +0 -7
  54. package/dist/ImagePreview/utils/util.js +0 -8
  55. package/dist/hooks/useFrameSetState.d.ts +0 -5
  56. package/dist/hooks/useFrameSetState.js +0 -33
  57. package/dist/image.esm.js +0 -2374
  58. package/dist/image.js +0 -1
  59. package/dist/props.d.ts +0 -84
  60. package/dist/props.js +0 -66
  61. package/dist/slots.d.ts +0 -6
  62. package/dist/slots.js +0 -21
  63. package/dist/style.d.ts +0 -9
  64. package/dist/typings.d.ts +0 -6
  65. package/dist/typings.js +0 -1
  66. package/dist/utils/aria.d.ts +0 -15
  67. package/dist/utils/aria.js +0 -16
  68. package/dist/utils/util.d.ts +0 -4
  69. package/dist/utils/util.js +0 -8
@@ -0,0 +1,6 @@
1
+ import { ForwardGImageType } from "./interface.js";
2
+
3
+ //#region src/Image.d.ts
4
+ declare const _default: ForwardGImageType;
5
+ //#endregion
6
+ export { _default as default };
package/dist/Image.js ADDED
@@ -0,0 +1,322 @@
1
+ import useImagePreview from "./hooks/useImagePreview.js";
2
+ import ForwardImagePreview from "./ImagePreview.js";
3
+ import style_default from "./style/index.js";
4
+ import { Fragment, computed, createVNode, defineComponent, mergeDefaults, mergeProps, nextTick, onMounted, ref, watch } from "vue";
5
+ import { EyeOutlined } from "@antdv-next/icons";
6
+ import { unit } from "@gx-design-vue/pro-provider";
7
+ import { classNames, getScrollContainer, getSlotsProps, isNumber, isString } from "@gx-design-vue/pro-utils";
8
+ import { isClient, useEventListener, useThrottleFn } from "@vueuse/core";
9
+ import { useBaseConfig } from "antdv-next/config-provider/context";
10
+ import useCSSVarCls from "antdv-next/config-provider/hooks/useCSSVarCls";
11
+ //#region src/Image.tsx
12
+ const defaults = {
13
+ src: "",
14
+ alt: "",
15
+ fit: "contain",
16
+ preview: true,
17
+ loading: "eager"
18
+ };
19
+ function isElement(value) {
20
+ return value && value.nodeType === 1;
21
+ }
22
+ const Image = /* @__PURE__ */ defineComponent((props, { emit, slots, expose, attrs }) => {
23
+ const supportNativeLazy = isClient && "loading" in HTMLImageElement.prototype;
24
+ const { prefixCls } = useBaseConfig("pro-image", props);
25
+ const rootCls = useCSSVarCls(prefixCls);
26
+ const [hashId, cssVarCls] = style_default(prefixCls, rootCls);
27
+ const imageSrc = ref();
28
+ const hasLoadError = ref(false);
29
+ const isLoading = ref(true);
30
+ const containerRef = ref();
31
+ const scrollContainerRef = ref();
32
+ let stopScrollListener;
33
+ const isManualLazy = computed(() => {
34
+ if (props.loading === "eager") return false;
35
+ return !supportNativeLazy && props.loading === "lazy" || props.lazy;
36
+ });
37
+ const imageStyle = computed(() => {
38
+ if (isClient && props.fit) return {
39
+ ...props.imageStyle,
40
+ objectFit: props.fit
41
+ };
42
+ return { ...props.imageStyle };
43
+ });
44
+ const previewConfig = computed(() => typeof props.preview === "object" ? props.preview : {});
45
+ const canPreview = computed(() => !!props.preview);
46
+ const currentPreviewIndex = computed(() => {
47
+ const { urls = [], current = 0 } = previewConfig.value;
48
+ if (isNumber(current)) return urls.length >= current ? current : 0;
49
+ const srcIndex = urls.indexOf(props.src ?? "");
50
+ return srcIndex >= 0 ? srcIndex : 0;
51
+ });
52
+ const containerWidth = computed(() => unit(props.width));
53
+ const containerHeight = computed(() => unit(props.height));
54
+ const { showViewer, mousePosition, openPreview, closePreview } = useImagePreview({ canPreview });
55
+ const loadImage = () => {
56
+ if (!isClient) return;
57
+ isLoading.value = true;
58
+ hasLoadError.value = false;
59
+ imageSrc.value = props.src;
60
+ };
61
+ const handleLoad = (event) => {
62
+ if (hasLoadError.value) return;
63
+ isLoading.value = false;
64
+ hasLoadError.value = false;
65
+ props.onLoad?.(event);
66
+ emit("load", event);
67
+ };
68
+ const handleError = (event) => {
69
+ isLoading.value = false;
70
+ hasLoadError.value = true;
71
+ props.onError?.(event);
72
+ emit("error", event);
73
+ };
74
+ const checkInViewport = () => {
75
+ if (!containerRef.value || !scrollContainerRef.value) return false;
76
+ const rect = containerRef.value.getBoundingClientRect();
77
+ const containerRect = scrollContainerRef.value.getBoundingClientRect ? scrollContainerRef.value.getBoundingClientRect() : {
78
+ top: 0,
79
+ bottom: scrollContainerRef.value.innerHeight ?? 0,
80
+ left: 0,
81
+ right: scrollContainerRef.value.innerWidth ?? 0
82
+ };
83
+ return rect.top < containerRect.bottom && rect.bottom > containerRect.top && rect.left < containerRect.right && rect.right > containerRect.left;
84
+ };
85
+ const handleLazyCheck = useThrottleFn(() => {
86
+ if (checkInViewport()) {
87
+ loadImage();
88
+ stopScrollListener?.();
89
+ stopScrollListener = void 0;
90
+ }
91
+ }, 200, true);
92
+ const setupLazyLoad = async () => {
93
+ if (!isClient) return;
94
+ await nextTick();
95
+ const { scrollContainer } = props;
96
+ if (isElement(scrollContainer)) scrollContainerRef.value = scrollContainer;
97
+ else if (isString(scrollContainer) && scrollContainer !== "") scrollContainerRef.value = document.querySelector(scrollContainer) ?? void 0;
98
+ else if (containerRef.value) scrollContainerRef.value = getScrollContainer(containerRef.value);
99
+ if (scrollContainerRef.value) {
100
+ stopScrollListener = useEventListener(scrollContainerRef.value, "scroll", handleLazyCheck);
101
+ setTimeout(handleLazyCheck, 100);
102
+ }
103
+ };
104
+ const handleClick = (clickEvent) => {
105
+ const clickType = isLoading.value ? "loaded" : hasLoadError.value ? "error" : "success";
106
+ props.onClick?.(clickType);
107
+ emit("click", clickType);
108
+ if (isLoading.value || hasLoadError.value) return;
109
+ if (canPreview.value) {
110
+ const rect = clickEvent.currentTarget?.getBoundingClientRect();
111
+ if (rect) openPreview({
112
+ ...clickEvent,
113
+ clientX: rect.x + rect.width / 2,
114
+ clientY: rect.y + rect.height / 2
115
+ });
116
+ else openPreview(clickEvent);
117
+ }
118
+ };
119
+ watch(() => props.src, () => {
120
+ if (isManualLazy.value) {
121
+ isLoading.value = true;
122
+ hasLoadError.value = false;
123
+ stopScrollListener?.();
124
+ setupLazyLoad();
125
+ } else loadImage();
126
+ });
127
+ onMounted(() => {
128
+ if (isManualLazy.value) setupLazyLoad();
129
+ else loadImage();
130
+ });
131
+ expose({ setOpen: (open) => {
132
+ if (open) openPreview();
133
+ else closePreview();
134
+ } });
135
+ return () => {
136
+ const containerAttrs = {};
137
+ const imgAttrs = {};
138
+ for (const [key, value] of Object.entries(attrs)) if (/^(?:data-|on[A-Z])/i.test(key) || [
139
+ "id",
140
+ "style",
141
+ "class"
142
+ ].includes(key)) containerAttrs[key] = value;
143
+ else imgAttrs[key] = value;
144
+ const slotProps = getSlotsProps({
145
+ slots,
146
+ props,
147
+ keys: [
148
+ "fallback",
149
+ "mask",
150
+ "placeholder"
151
+ ],
152
+ render: true
153
+ });
154
+ return createVNode("div", mergeProps({
155
+ "class": classNames(prefixCls.value, hashId.value, cssVarCls.value, rootCls.value, props.class),
156
+ "ref": containerRef
157
+ }, containerAttrs, {
158
+ "style": {
159
+ width: unit(props.size) || containerWidth.value,
160
+ height: unit(props.size) || containerHeight.value,
161
+ ...containerAttrs.style || {}
162
+ },
163
+ "onClick": (event) => {
164
+ if (hasLoadError.value) handleClick(event);
165
+ }
166
+ }), [
167
+ hasLoadError.value ? createVNode("div", { "class": classNames(`${prefixCls.value}-error`) }, [slotProps.fallback]) : createVNode(Fragment, null, [createVNode("img", mergeProps(imgAttrs, {
168
+ "src": imageSrc.value,
169
+ "loading": props.loading,
170
+ "style": imageStyle.value,
171
+ "class": classNames(props.imageClass, `${prefixCls.value}-img`, {
172
+ [`${prefixCls.value}-img-placeholder`]: props.placeholder === true,
173
+ [`${prefixCls.value}-img-preview`]: canPreview.value
174
+ }),
175
+ "crossorigin": props.crossOrigin,
176
+ "width": containerWidth.value,
177
+ "height": containerHeight.value,
178
+ "onClick": handleClick,
179
+ "onLoad": handleLoad,
180
+ "onError": handleError
181
+ }), null), isLoading.value && createVNode("div", {
182
+ "class": classNames(`${prefixCls.value}-placeholder`),
183
+ "onClick": handleClick
184
+ }, [slotProps.placeholder])]),
185
+ previewConfig.value.mask && canPreview.value && createVNode("div", {
186
+ "class": classNames(`${prefixCls.value}-mask`, previewConfig.value.maskClass),
187
+ "style": { display: containerAttrs.style?.display === "none" ? "none" : void 0 }
188
+ }, [slotProps.mask || createVNode("div", { "class": classNames(`${prefixCls.value}-mask-info`) }, [createVNode(EyeOutlined, null, null)])]),
189
+ canPreview.value && createVNode(ForwardImagePreview, mergeProps(previewConfig.value, {
190
+ "urls": previewConfig.value.urls || (props.src ? [props.src] : []),
191
+ "current": currentPreviewIndex.value,
192
+ "zIndex": props.zIndex ?? previewConfig.value.zIndex,
193
+ "open": showViewer.value,
194
+ "mousePosition": mousePosition.value,
195
+ "onClose": () => closePreview()
196
+ }), slots)
197
+ ]);
198
+ };
199
+ }, {
200
+ props: /* @__PURE__ */ mergeDefaults({
201
+ rootClass: {
202
+ type: String,
203
+ required: false
204
+ },
205
+ prefixCls: {
206
+ type: String,
207
+ required: false
208
+ },
209
+ src: {
210
+ type: String,
211
+ required: false
212
+ },
213
+ alt: {
214
+ type: String,
215
+ required: false
216
+ },
217
+ width: {
218
+ type: Number,
219
+ required: false
220
+ },
221
+ height: {
222
+ type: Number,
223
+ required: false
224
+ },
225
+ size: {
226
+ type: Number,
227
+ required: false
228
+ },
229
+ fit: {
230
+ type: String,
231
+ required: false
232
+ },
233
+ loading: {
234
+ type: String,
235
+ required: false
236
+ },
237
+ crossOrigin: {
238
+ type: String,
239
+ required: false
240
+ },
241
+ imageStyle: {
242
+ type: Object,
243
+ required: false
244
+ },
245
+ imageClass: {
246
+ type: String,
247
+ required: false
248
+ },
249
+ preview: {
250
+ type: [Boolean, Object],
251
+ required: false,
252
+ default: void 0
253
+ },
254
+ zIndex: {
255
+ type: Number,
256
+ required: false
257
+ },
258
+ lazy: {
259
+ type: Boolean,
260
+ required: false,
261
+ default: void 0
262
+ },
263
+ scrollContainer: { required: false },
264
+ placeholder: {
265
+ type: [
266
+ Function,
267
+ Object,
268
+ String,
269
+ Number,
270
+ Boolean,
271
+ null,
272
+ Array
273
+ ],
274
+ required: false,
275
+ default: void 0
276
+ },
277
+ fallback: {
278
+ type: [
279
+ Function,
280
+ Object,
281
+ String,
282
+ Number,
283
+ Boolean,
284
+ null,
285
+ Array
286
+ ],
287
+ required: false,
288
+ default: void 0
289
+ },
290
+ onLoad: {
291
+ type: Function,
292
+ required: false
293
+ },
294
+ onError: {
295
+ type: Function,
296
+ required: false
297
+ },
298
+ onClick: {
299
+ type: Function,
300
+ required: false
301
+ },
302
+ "onUpdate:open": {
303
+ type: Function,
304
+ required: false
305
+ }
306
+ }, defaults),
307
+ emits: [
308
+ "click",
309
+ "load",
310
+ "error"
311
+ ],
312
+ name: "GImage",
313
+ inheritAttrs: false
314
+ });
315
+ Image.isGImage = true;
316
+ Image.install = (app) => {
317
+ app.component(Image.name, Image);
318
+ return app;
319
+ };
320
+ const GImage = Image;
321
+ //#endregion
322
+ export { GImage as default };
@@ -0,0 +1,6 @@
1
+ import { ForwardImagePreviewType } from "./interface.js";
2
+
3
+ //#region src/ImagePreview.d.ts
4
+ declare const _default: ForwardImagePreviewType;
5
+ //#endregion
6
+ export { _default as default };