@gx-design-vue/image 0.1.0 → 0.1.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.mjs DELETED
@@ -1,591 +0,0 @@
1
- import { createVNode as l, defineComponent as Z, ref as g, computed as b, watch as U, nextTick as oe, Fragment as re, resolveComponent as ue, cloneVNode as ve, Teleport as ce, isVNode as me, createTextVNode as ge, mergeProps as he } from "vue";
2
- import { ExpandOutlined as ye, OneToOneOutlined as we, CloseOutlined as be, LeftOutlined as pe, RightOutlined as Oe, ZoomOutOutlined as Ce, ZoomInOutlined as Ie, RotateLeftOutlined as ke, RotateRightOutlined as xe, LoadingOutlined as Le } from "@ant-design/icons-vue";
3
- import { isServer as T, getPrefixCls as K, getSlotVNode as ee, isInContainer as Se, isString as Ne, getScrollContainer as $e } from "@gx-design-vue/pro-utils";
4
- import { onMountedOrActivated as se } from "@gx-design-vue/pro-hooks";
5
- import { createTypes as Te } from "vue-types";
6
- import { useThrottleFn as Ae, useEventListener as te } from "@vueuse/core";
7
- var de = Te({
8
- func: void 0,
9
- bool: void 0,
10
- string: void 0,
11
- number: void 0,
12
- array: void 0,
13
- object: void 0,
14
- integer: void 0
15
- });
16
- de.extend([{
17
- name: "looseBool",
18
- getter: !0,
19
- type: Boolean,
20
- default: void 0
21
- }, {
22
- name: "style",
23
- getter: !0,
24
- type: [String, Object],
25
- default: void 0
26
- }, {
27
- name: "VueNode",
28
- getter: !0,
29
- type: null
30
- }]);
31
- const _ = de, P = {
32
- appendToBody: {
33
- type: Boolean,
34
- default: !1
35
- },
36
- hideOnClickModal: {
37
- type: Boolean,
38
- default: !0
39
- },
40
- src: {
41
- type: String,
42
- default: ""
43
- },
44
- fit: {
45
- type: String,
46
- default: ""
47
- },
48
- lazy: _.bool,
49
- scrollContainer: {
50
- type: [String, Object]
51
- },
52
- placeholder: {
53
- type: [Function, Object],
54
- default: () => {
55
- }
56
- },
57
- fallback: {
58
- type: [Function, Object],
59
- default: () => {
60
- }
61
- },
62
- onError: {
63
- type: Function
64
- },
65
- onClick: {
66
- type: Function
67
- },
68
- disablePreview: _.bool,
69
- previewSrcList: {
70
- type: Array,
71
- default: () => []
72
- },
73
- width: _.number,
74
- height: _.number,
75
- zIndex: {
76
- type: Number,
77
- default: 2e3
78
- }
79
- }, ze = {
80
- urlList: {
81
- type: Array,
82
- default: () => []
83
- },
84
- zIndex: P.zIndex,
85
- initialIndex: {
86
- type: Number,
87
- default: 0
88
- },
89
- infinite: {
90
- type: Boolean,
91
- default: !0
92
- },
93
- onHideOnClickModal: P.hideOnClickModal
94
- }, $ = {
95
- tab: "Tab",
96
- enter: "Enter",
97
- space: "Space",
98
- left: "ArrowLeft",
99
- up: "ArrowUp",
100
- right: "ArrowRight",
101
- down: "ArrowDown",
102
- esc: "Escape",
103
- delete: "Delete",
104
- backspace: "Backspace"
105
- }, Y = function(e, a, d, w = !1) {
106
- e && a && d && e.addEventListener(a, d, w);
107
- }, X = function(e, a, d, w = !1) {
108
- e && a && d && e.removeEventListener(a, d, w);
109
- }, V = {
110
- CONTAIN: {
111
- name: "contain",
112
- icon: l(ye, null, null)
113
- },
114
- ORIGINAL: {
115
- name: "original",
116
- icon: l(we, null, null)
117
- }
118
- }, Ee = function() {
119
- return !T && !!window.navigator.userAgent.match(/firefox/i);
120
- }, ne = Ee() ? "DOMMouseScroll" : "mousewheel";
121
- function q(e) {
122
- let a = !1;
123
- return function(...d) {
124
- a || (a = !0, window.requestAnimationFrame(() => {
125
- e.apply(this, d), a = !1;
126
- }));
127
- };
128
- }
129
- const fe = /* @__PURE__ */ Z({
130
- props: ze,
131
- emits: ["close", "switch"],
132
- setup: function(e, {
133
- emit: a
134
- }) {
135
- let d = null, w = null, p = null;
136
- const i = K({
137
- suffixCls: "image-viewer"
138
- }), f = g(!0), h = g(e.initialIndex), k = g(null), x = g(null), O = g(V.CONTAIN), o = g({
139
- scale: 1,
140
- deg: 0,
141
- offsetX: 0,
142
- offsetY: 0,
143
- enableTransition: !1
144
- }), u = b(() => {
145
- const {
146
- urlList: n
147
- } = e;
148
- return n.length <= 1;
149
- }), s = b(() => h.value === 0), v = b(() => h.value === e.urlList.length - 1), I = b(() => e.urlList[h.value]), L = g("viewer-fade-enter-active"), A = b(() => {
150
- const {
151
- scale: n,
152
- deg: y,
153
- offsetX: t,
154
- offsetY: r,
155
- enableTransition: c
156
- } = o.value, m = {
157
- transform: `scale(${n}) rotate(${y}deg)`,
158
- transition: c ? "transform .3s" : "",
159
- marginLeft: `${t}px`,
160
- marginTop: `${r}px`
161
- };
162
- return O.value.name === V.CONTAIN.name && (m.maxWidth = m.maxHeight = "100%"), m;
163
- }), z = () => {
164
- W(), setTimeout(() => {
165
- a("close");
166
- }, 200);
167
- }, S = () => {
168
- L.value = "viewer-fade-enter-active", d = q((n) => {
169
- switch (n.code) {
170
- case $.esc:
171
- z();
172
- break;
173
- case $.space:
174
- M();
175
- break;
176
- case $.left:
177
- R();
178
- break;
179
- case $.up:
180
- C("zoomIn");
181
- break;
182
- case $.right:
183
- j();
184
- break;
185
- case $.down:
186
- C("zoomOut");
187
- break;
188
- }
189
- }), w = q((n) => {
190
- (n.wheelDelta ? n.wheelDelta : -n.detail) > 0 ? C("zoomIn", {
191
- zoomRate: 0.015,
192
- enableTransition: !1
193
- }) : C("zoomOut", {
194
- zoomRate: 0.015,
195
- enableTransition: !1
196
- });
197
- }), Y(document, "keydown", d), Y(document, ne, w);
198
- }, W = () => {
199
- L.value = "viewer-fade-leave-active", X(document, "keydown", d), X(document, ne, w), d = null, w = null;
200
- }, E = () => {
201
- f.value = !1;
202
- }, D = (n) => {
203
- f.value = !1, n.target.alt = "加载失败";
204
- }, H = (n) => {
205
- if (f.value || n.button !== 0)
206
- return;
207
- const {
208
- offsetX: y,
209
- offsetY: t
210
- } = o.value, r = n.pageX, c = n.pageY;
211
- p = q((m) => {
212
- o.value = {
213
- ...o.value,
214
- offsetX: y + m.pageX - r,
215
- offsetY: t + m.pageY - c
216
- };
217
- }), Y(document, "mousemove", p), Y(document, "mouseup", () => {
218
- X(document, "mousemove", p);
219
- }), n.preventDefault();
220
- }, F = () => {
221
- o.value = {
222
- scale: 1,
223
- deg: 0,
224
- offsetX: 0,
225
- offsetY: 0,
226
- enableTransition: !1
227
- };
228
- }, M = () => {
229
- if (f.value)
230
- return;
231
- const n = Object.keys(V), y = Object.values(V), t = O.value.name, c = (y.findIndex((m) => m.name === t) + 1) % n.length;
232
- O.value = V[n[c]], F();
233
- }, R = () => {
234
- if (s.value && !e.infinite)
235
- return;
236
- const n = e.urlList.length;
237
- h.value = (h.value - 1 + n) % n;
238
- }, j = () => {
239
- if (v.value && !e.infinite)
240
- return;
241
- const n = e.urlList.length;
242
- h.value = (h.value + 1) % n;
243
- }, C = (n, y = {}) => {
244
- if (f.value)
245
- return;
246
- const {
247
- zoomRate: t,
248
- rotateDeg: r,
249
- enableTransition: c
250
- } = {
251
- zoomRate: 0.2,
252
- rotateDeg: 90,
253
- enableTransition: !0,
254
- ...y
255
- };
256
- switch (n) {
257
- case "zoomOut":
258
- o.value.scale > 0.2 && (o.value.scale = parseFloat((o.value.scale - t).toFixed(3)));
259
- break;
260
- case "zoomIn":
261
- o.value.scale = parseFloat((o.value.scale + t).toFixed(3));
262
- break;
263
- case "clocelise":
264
- o.value.deg += r;
265
- break;
266
- case "anticlocelise":
267
- o.value.deg -= r;
268
- break;
269
- }
270
- o.value.enableTransition = c;
271
- };
272
- return U(I, () => {
273
- oe(() => {
274
- x.value.complete || (f.value = !0);
275
- });
276
- }), U(h, (n) => {
277
- F(), a("switch", n);
278
- }), se(() => {
279
- var n, y;
280
- S(), (y = (n = k.value) == null ? void 0 : n.focus) == null || y.call(n);
281
- }), () => l("div", {
282
- ref: (n) => k.value = n,
283
- tabindex: 1,
284
- class: [`${i}-wrapper`, `${L.value}`],
285
- style: {
286
- zIndex: e.zIndex
287
- }
288
- }, [l("div", {
289
- class: `${i}-mask`,
290
- onClick: () => e.onHideOnClickModal && z()
291
- }, null), l("span", {
292
- class: [`${i}-btn`, `${i}-close`],
293
- onClick: () => z()
294
- }, [l(be, null, null)]), !u.value && l(re, null, [l("span", {
295
- class: {
296
- [`${i}-btn`]: !0,
297
- [`${i}-prev`]: !0,
298
- ["is-disabled"]: !e.infinite && s.value
299
- },
300
- onClick: () => R()
301
- }, [l(pe, null, null)]), l("span", {
302
- class: {
303
- [`${i}-btn`]: !0,
304
- [`${i}-next`]: !0,
305
- ["is-disabled"]: !e.infinite && s.value
306
- },
307
- onClick: () => j()
308
- }, [l(Oe, null, null)])]), l("div", {
309
- class: [`${i}-btn`, `${i}-actions`]
310
- }, [l("div", {
311
- class: `${i}-actions-inner`
312
- }, [l(Ce, {
313
- onClick: () => C("zoomOut")
314
- }, null), l(Ie, {
315
- onClick: () => C("zoomIn")
316
- }, null), l("i", {
317
- class: `${i}-actions-divider`
318
- }, null), l("i", {
319
- onClick: () => M()
320
- }, [O.value.icon]), l("i", {
321
- class: `${i}-actions-divider`
322
- }, null), l(ke, {
323
- onClick: () => C("anticlocelise")
324
- }, null), l(xe, {
325
- onClick: () => C("clocelise")
326
- }, null)])]), f.value && l("div", {
327
- class: `${i}-canvas`
328
- }, [l(ue("a-spin"), {
329
- indicator: l(Le, {
330
- style: {
331
- color: "#fff",
332
- fontSize: "40px"
333
- }
334
- }, null)
335
- }, null)]), l("div", {
336
- class: `${i}-canvas`
337
- }, [e.urlList.map((n, y) => l("img", {
338
- ref: (t) => x.value = t,
339
- class: `${i}-img`,
340
- key: n,
341
- style: {
342
- ...A.value,
343
- display: y === h.value ? "block" : "none"
344
- },
345
- src: n,
346
- onLoad: () => E(),
347
- onError: (t) => D(t),
348
- onMousedown: (t) => H(t)
349
- }, null))])]);
350
- }
351
- });
352
- function Fe(e) {
353
- return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !me(e);
354
- }
355
- let le = "";
356
- const Ge = /* @__PURE__ */ Z({
357
- props: {
358
- hideOnClickModal: P.hideOnClickModal
359
- },
360
- setup(e, {
361
- slots: a
362
- }) {
363
- const d = K({
364
- suffixCls: "image-viewer-group"
365
- }), w = g(!1), p = g(""), i = b(() => {
366
- var u, s, v, I, L;
367
- return ((u = a.default) == null ? void 0 : u.call(a).length) === 1 && (String((s = a.default) == null ? void 0 : s.call(a)[0].type) === String(Symbol("Fragment")) || String((v = a.default) == null ? void 0 : v.call(a)[0].type) === String(Symbol())) ? ((I = a.default) == null ? void 0 : I.call(a)[0].children) || [] : ((L = a.default) == null ? void 0 : L.call(a)) || [];
368
- }), f = b(() => i.value.filter((v) => k(v)).map((v) => v.props.src).filter((v) => v) || []), h = b(() => Array.isArray(f.value) && f.value.length > 0), k = (u) => u && u.type && (u.type.isGImage || u.type.name === "GImage"), x = () => {
369
- let u = 0;
370
- const s = f.value.findIndex((v) => v === p.value);
371
- return s >= 0 && (u = s), u;
372
- }, O = (u) => {
373
- !h.value || !u || (p.value = u, le = document.body.style.overflow, document.body.style.overflow = "hidden", w.value = !0);
374
- }, o = () => {
375
- document.body.style.overflow = le, w.value = !1;
376
- };
377
- return () => {
378
- let u;
379
- return l("div", {
380
- class: `${d}`
381
- }, [l(ue("a-space"), {
382
- size: 15
383
- }, Fe(u = i.value.map((s, v) => k(s) ? l("div", {
384
- key: v,
385
- class: `${d}-item`,
386
- onClick: () => {
387
- var I;
388
- return O(((I = s.props) == null ? void 0 : I.src) || "");
389
- }
390
- }, [ve(s, {
391
- disablePreview: !0
392
- })]) : null)) ? u : {
393
- default: () => [u]
394
- }), l(ce, {
395
- to: "body"
396
- }, {
397
- default: () => [h.value && w.value && l(fe, {
398
- initialIndex: x(),
399
- urlList: f.value,
400
- onHideOnClickModal: e.hideOnClickModal,
401
- onClose: () => o()
402
- }, null)]
403
- })]);
404
- };
405
- }
406
- }), Me = (e) => e && e.nodeType === Node.ELEMENT_NODE, ae = () => document.documentElement.style.objectFit !== void 0;
407
- let ie = "";
408
- const N = {
409
- NONE: "none",
410
- CONTAIN: "contain",
411
- COVER: "cover",
412
- FILL: "fill",
413
- SCALE_DOWN: "scale-down"
414
- }, G = /* @__PURE__ */ Z({
415
- props: P,
416
- name: "GImage",
417
- inheritAttrs: !1,
418
- emits: ["error", "click"],
419
- setup(e, {
420
- slots: a,
421
- emit: d,
422
- attrs: w
423
- }) {
424
- const p = K({
425
- suffixCls: "image"
426
- }), i = g(!1), f = g(!0), h = g(0), k = g(0), x = g(!1), O = g(null), o = g();
427
- let u, s;
428
- const v = b(() => ({
429
- width: e.width ? `${e.width}px` : void 0,
430
- height: e.height ? `${e.height}px` : void 0
431
- })), I = b(() => {
432
- const {
433
- fit: t
434
- } = e;
435
- return !T && t ? ae() ? {
436
- "object-fit": t,
437
- ...v.value
438
- } : {
439
- ...W(t),
440
- ...v.value
441
- } : v.value;
442
- }), L = b(() => {
443
- const {
444
- fit: t
445
- } = e;
446
- return !T && !ae() && t !== N.FILL;
447
- }), A = b(() => {
448
- const {
449
- previewSrcList: t
450
- } = e;
451
- return Array.isArray(t) && t.length > 0;
452
- }), z = b(() => {
453
- const {
454
- src: t,
455
- previewSrcList: r
456
- } = e;
457
- let c = 0;
458
- const m = r.indexOf(t);
459
- return m >= 0 && (c = m), c;
460
- }), S = b(() => w), W = (t) => {
461
- const r = e.width || h.value, c = e.height || k.value;
462
- if (!O.value)
463
- return {};
464
- const {
465
- clientWidth: m,
466
- clientHeight: B
467
- } = O.value;
468
- if (!r || !c || !m || !B)
469
- return {};
470
- const J = r / c, Q = m / B;
471
- switch (t === N.SCALE_DOWN && (t = r < m && c < B ? N.NONE : N.CONTAIN), t) {
472
- case N.NONE:
473
- return {
474
- width: "auto",
475
- height: "auto"
476
- };
477
- case N.CONTAIN:
478
- return J < Q ? {
479
- width: "auto"
480
- } : {
481
- height: "auto"
482
- };
483
- case N.COVER:
484
- return J < Q ? {
485
- height: "auto"
486
- } : {
487
- width: "auto"
488
- };
489
- default:
490
- return {};
491
- }
492
- }, E = () => {
493
- if (T)
494
- return;
495
- const t = S.value;
496
- f.value = !0, i.value = !1;
497
- const r = new Image();
498
- r.onload = (c) => R(c, r), r.onerror = j, Object.keys(t).forEach((c) => {
499
- if (c.toLowerCase() === "onload")
500
- return;
501
- const m = t[c];
502
- r.setAttribute(c, m);
503
- }), r.src = e.src;
504
- };
505
- function D() {
506
- Se(O.value, o.value) && (E(), M());
507
- }
508
- const H = Ae(D, 200), F = async () => {
509
- if (T)
510
- return;
511
- await oe();
512
- const {
513
- scrollContainer: t
514
- } = e;
515
- Me(t) ? o.value = t : Ne(t) && t !== "" ? o.value = document.querySelector(t) ?? void 0 : O.value && (o.value = $e(O.value)), o.value && (u = te(o, "scroll", H), setTimeout(() => D(), 200));
516
- }, M = () => {
517
- T || !o.value || !H || (u(), o.value = void 0);
518
- }, R = (t, r) => {
519
- h.value = r.width, k.value = r.height, f.value = !1, i.value = !1;
520
- }, j = (t) => {
521
- f.value = !1, i.value = !0, d("error", t);
522
- }, C = (t) => {
523
- if (t.ctrlKey) {
524
- if (t.deltaY < 0)
525
- return t.preventDefault(), !1;
526
- if (t.deltaY > 0)
527
- return t.preventDefault(), !1;
528
- }
529
- }, n = () => {
530
- !A.value || e.disablePreview || (s = te("wheel", C, {
531
- passive: !1
532
- }), ie = document.body.style.overflow, document.body.style.overflow = "hidden", x.value = !0);
533
- }, y = () => {
534
- s == null || s(), document.body.style.overflow = ie, x.value = !1;
535
- };
536
- return U(() => e.src, () => {
537
- e.lazy ? (f.value = !0, i.value = !1, M(), F()) : E();
538
- }), se(() => {
539
- e.lazy ? F() : E();
540
- }), () => {
541
- const t = ee(a, e, "fallback"), r = ee(a, e, "placeholder");
542
- return l(re, null, [l("div", {
543
- class: {
544
- [`${p}`]: !0,
545
- [`${S.value.class}`]: S.value.class
546
- },
547
- ref: (c) => O.value = c,
548
- style: {
549
- ...S.value.style || {},
550
- display: e.lazy ? "block" : void 0
551
- },
552
- onClick: () => {
553
- d("click");
554
- }
555
- }, [f.value ? r || l("div", {
556
- class: `${p}-placeholder`
557
- }, null) : i.value ? t || l("div", {
558
- class: `${p}-error`
559
- }, [ge("加载失败")]) : l("img", he({
560
- class: {
561
- [`${p}-inner`]: !0,
562
- [`${p}-inner-center`]: L.value,
563
- [`${p}-preview`]: A.value
564
- }
565
- }, S.value, {
566
- src: e.src,
567
- style: I.value,
568
- onClick: () => n()
569
- }), null), l(ce, {
570
- to: "body",
571
- disabled: !e.appendToBody
572
- }, {
573
- default: () => [A.value && x.value && l(fe, {
574
- zIndex: e.zIndex,
575
- initialIndex: z.value,
576
- urlList: e.previewSrcList,
577
- onHideOnClickModal: e.hideOnClickModal,
578
- onClose: () => y()
579
- }, null)]
580
- })])]);
581
- };
582
- }
583
- });
584
- G.isWImage = !0;
585
- G.install = (e) => (e.component(G.name, G), e);
586
- export {
587
- G as GImage,
588
- fe as ImageViewer,
589
- Ge as ImageViewerGroup,
590
- G as default
591
- };