disguise-ui 0.2.8 → 0.3.0
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/README.md +20 -0
- package/dist/{avatar-cell-BPzpEjQT.js → avatar-cell-CSanGG5Y.js} +1 -1
- package/dist/disguise-ui.js +221 -199
- package/dist/{file-upload-BkRSvBlx.js → file-upload-ClPojHbE.js} +1 -1
- package/dist/{file-upload-CeqibzK8.js → file-upload-D7N0tsLF.js} +2 -2
- package/dist/{i18n-DejVnxC8.js → i18n-_x6RCAst.js} +36 -2
- package/dist/{picture-cell-DApeh9FW.js → picture-cell-BhKqFZUx.js} +31 -32
- package/dist/picture-upload-BrrTtaCc.js +649 -0
- package/dist/{picture-upload-uc9FsqEo.js → picture-upload-VK7YOAr4.js} +1 -1
- package/dist/style.css +1 -1
- package/dist/types/components/images-view/index.vue.d.ts +13 -1
- package/dist/types/components/picture-upload/image-crop-dialog.vue.d.ts +18 -0
- package/dist/types/components/picture-upload/index.d.ts +1 -0
- package/dist/types/components/picture-upload/picture-upload.type.d.ts +65 -0
- package/dist/types/components/picture-upload/picture-upload.vue.d.ts +30 -21
- package/dist/types/components/schema-form/schema-form.type.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/{use-multiple-file-upload-BFNkLVy-.js → use-multiple-file-upload-Cv2dfA07.js} +7 -5
- package/dist/{user-avatar-info-SD6OE607.js → user-avatar-info-BruEfYy4.js} +1 -1
- package/package.json +3 -2
- package/dist/picture-upload-E97PfpUU.js +0 -320
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
import { t as e } from "./i18n-_x6RCAst.js";
|
|
2
|
+
import { t } from "./_plugin-vue_export-helper-Djzt4Yr7.js";
|
|
3
|
+
import { t as n } from "./use-image-url-Bs5WMZ6L.js";
|
|
4
|
+
import { n as r, t as i } from "./use-multiple-file-upload-Cv2dfA07.js";
|
|
5
|
+
import { Fragment as a, computed as o, createBlock as s, createCommentVNode as c, createElementBlock as l, createElementVNode as u, createTextVNode as d, createVNode as f, defineComponent as p, nextTick as ee, normalizeClass as te, normalizeStyle as m, onBeforeUnmount as ne, openBlock as h, reactive as g, ref as _, renderList as re, renderSlot as v, toDisplayString as y, toRefs as b, unref as x, useSlots as S, watch as ie, withCtx as C, withModifiers as w } from "vue";
|
|
6
|
+
import { ElButton as T, ElDialog as ae, ElIcon as E, ElImageViewer as D, ElMessage as O, ElProgress as k, ElUpload as A } from "element-plus";
|
|
7
|
+
import { Close as j, Download as oe, Plus as M, ZoomIn as N } from "@element-plus/icons-vue";
|
|
8
|
+
// src/components/picture-upload/image-crop-dialog.vue?vue&type=script&setup=true&lang.ts
|
|
9
|
+
var P = { class: "picture-crop" }, F = { class: "picture-crop__stage" }, I = {
|
|
10
|
+
key: 0,
|
|
11
|
+
class: "picture-crop__image-shell"
|
|
12
|
+
}, se = ["src"], ce = ["onPointerdown"], L = { class: "picture-crop__meta" }, le = { key: 0 }, R = {
|
|
13
|
+
key: 0,
|
|
14
|
+
class: "picture-crop__ratios"
|
|
15
|
+
}, z = { class: "picture-crop__ratios-label" }, B = {
|
|
16
|
+
key: 1,
|
|
17
|
+
class: "picture-crop__error"
|
|
18
|
+
}, V = {
|
|
19
|
+
key: 2,
|
|
20
|
+
class: "picture-crop__hint"
|
|
21
|
+
}, ue = /*#__PURE__*/ t(/* @__PURE__ */ p({
|
|
22
|
+
__name: "image-crop-dialog",
|
|
23
|
+
props: {
|
|
24
|
+
crop: {},
|
|
25
|
+
dimensions: {},
|
|
26
|
+
file: {},
|
|
27
|
+
modelValue: { type: Boolean }
|
|
28
|
+
},
|
|
29
|
+
emits: [
|
|
30
|
+
"cancel",
|
|
31
|
+
"confirm",
|
|
32
|
+
"update:modelValue"
|
|
33
|
+
],
|
|
34
|
+
setup(t, { emit: n }) {
|
|
35
|
+
let r = t, i = n, p = _(), v = _(""), b = _(!1), S = _(), w = g({
|
|
36
|
+
height: 0,
|
|
37
|
+
naturalHeight: 0,
|
|
38
|
+
naturalWidth: 0,
|
|
39
|
+
width: 0
|
|
40
|
+
}), E = g({
|
|
41
|
+
height: 0,
|
|
42
|
+
width: 0,
|
|
43
|
+
x: 0,
|
|
44
|
+
y: 0
|
|
45
|
+
}), D, k = o(() => r.crop?.aspectRatios ?? []), A = o(() => {
|
|
46
|
+
let { height: e, width: t } = r.dimensions ?? {};
|
|
47
|
+
return e && t ? t / e : void 0;
|
|
48
|
+
}), j = o(() => {
|
|
49
|
+
if (A.value) return A.value;
|
|
50
|
+
let e = S.value;
|
|
51
|
+
return e && e > 0 ? e : void 0;
|
|
52
|
+
}), oe = o(() => ({
|
|
53
|
+
height: w.height ? Math.max(1, Math.round(E.height / w.height * w.naturalHeight)) : 0,
|
|
54
|
+
width: w.width ? Math.max(1, Math.round(E.width / w.width * w.naturalWidth)) : 0
|
|
55
|
+
})), M = o(() => {
|
|
56
|
+
let e = oe.value, t = r.dimensions?.width, n = r.dimensions?.height;
|
|
57
|
+
return t && n ? {
|
|
58
|
+
height: n,
|
|
59
|
+
width: t
|
|
60
|
+
} : t && e.width ? {
|
|
61
|
+
height: Math.max(1, Math.round(t / e.width * e.height)),
|
|
62
|
+
width: t
|
|
63
|
+
} : n && e.height ? {
|
|
64
|
+
height: n,
|
|
65
|
+
width: Math.max(1, Math.round(n / e.height * e.width))
|
|
66
|
+
} : e;
|
|
67
|
+
}), N = o(() => {
|
|
68
|
+
let t = r.dimensions, { height: n, width: i } = M.value;
|
|
69
|
+
return !t || !i || !n ? "" : t.width !== void 0 && i !== t.width ? e("components.pictureUpload.widthExact", { width: t.width }) : t.height !== void 0 && n !== t.height ? e("components.pictureUpload.heightExact", { height: t.height }) : t.minWidth !== void 0 && i < t.minWidth ? e("components.pictureUpload.widthMin", { width: t.minWidth }) : t.minHeight !== void 0 && n < t.minHeight ? e("components.pictureUpload.heightMin", { height: t.minHeight }) : t.maxWidth !== void 0 && i > t.maxWidth ? e("components.pictureUpload.widthMax", { width: t.maxWidth }) : t.maxHeight !== void 0 && n > t.maxHeight ? e("components.pictureUpload.heightMax", { height: t.maxHeight }) : "";
|
|
70
|
+
}), ue = o(() => ({
|
|
71
|
+
height: `${E.height}px`,
|
|
72
|
+
transform: `translate(${E.x}px, ${E.y}px)`,
|
|
73
|
+
width: `${E.width}px`
|
|
74
|
+
}));
|
|
75
|
+
ie(() => [r.modelValue, r.file], async ([e, t]) => {
|
|
76
|
+
if (H(), !e || !t) return;
|
|
77
|
+
let n = r.crop?.aspectRatio;
|
|
78
|
+
S.value = n && n > 0 ? n : k.value[0]?.value ?? null, v.value = URL.createObjectURL(t), await ee();
|
|
79
|
+
}, { immediate: !0 }), ne(() => {
|
|
80
|
+
H(), ge();
|
|
81
|
+
});
|
|
82
|
+
function H() {
|
|
83
|
+
v.value && URL.revokeObjectURL(v.value), v.value = "";
|
|
84
|
+
}
|
|
85
|
+
function U() {
|
|
86
|
+
let e = p.value;
|
|
87
|
+
if (!e) return;
|
|
88
|
+
w.width = e.clientWidth, w.height = e.clientHeight, w.naturalWidth = e.naturalWidth, w.naturalHeight = e.naturalHeight;
|
|
89
|
+
let t = Math.min(w.width, w.height) * .08, n = Math.max(32, w.width - t * 2), r = Math.max(32, w.height - t * 2), i = n, a = r;
|
|
90
|
+
j.value && (a = i / j.value, a > r && (a = r, i = a * j.value)), Object.assign(E, {
|
|
91
|
+
height: a,
|
|
92
|
+
width: i,
|
|
93
|
+
x: (w.width - i) / 2,
|
|
94
|
+
y: (w.height - a) / 2
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function de(e) {
|
|
98
|
+
A.value || (S.value = e, U());
|
|
99
|
+
}
|
|
100
|
+
function fe(e) {
|
|
101
|
+
return A.value ? e !== null && e === A.value : S.value === e;
|
|
102
|
+
}
|
|
103
|
+
function pe(e, t, n) {
|
|
104
|
+
e.preventDefault(), e.stopPropagation(), D = {
|
|
105
|
+
corner: n,
|
|
106
|
+
mode: t,
|
|
107
|
+
pointerId: e.pointerId,
|
|
108
|
+
start: { ...E },
|
|
109
|
+
startX: e.clientX,
|
|
110
|
+
startY: e.clientY
|
|
111
|
+
}, window.addEventListener("pointermove", me), window.addEventListener("pointerup", W), window.addEventListener("pointercancel", W);
|
|
112
|
+
}
|
|
113
|
+
function me(e) {
|
|
114
|
+
let t = D;
|
|
115
|
+
if (!t || e.pointerId !== t.pointerId) return;
|
|
116
|
+
let n = e.clientX - t.startX, r = e.clientY - t.startY;
|
|
117
|
+
t.mode === "move" ? (E.x = G(t.start.x + n, 0, w.width - t.start.width), E.y = G(t.start.y + r, 0, w.height - t.start.height)) : he(t.start, t.corner ?? "se", n, r);
|
|
118
|
+
}
|
|
119
|
+
function he(e, t, n, r) {
|
|
120
|
+
let i = t.includes("w"), a = t.includes("n"), o = i ? e.x + e.width : e.x, s = a ? e.y + e.height : e.y, c = (i ? e.x : e.x + e.width) + n, l = (a ? e.y : e.y + e.height) + r;
|
|
121
|
+
if (j.value) {
|
|
122
|
+
let e = i ? o : w.width - o, t = a ? s : w.height - s, n = G(Math.max(Math.abs(c - o), Math.abs(l - s) * j.value), 32, Math.min(e, t * j.value)), r = n / j.value;
|
|
123
|
+
Object.assign(E, {
|
|
124
|
+
height: r,
|
|
125
|
+
width: n,
|
|
126
|
+
x: i ? o - n : o,
|
|
127
|
+
y: a ? s - r : s
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
let u = i ? G(c, 0, o - 32) : o, d = a ? G(l, 0, s - 32) : s, f = i ? o : G(c, o + 32, w.width), p = a ? s : G(l, s + 32, w.height);
|
|
132
|
+
Object.assign(E, {
|
|
133
|
+
height: p - d,
|
|
134
|
+
width: f - u,
|
|
135
|
+
x: u,
|
|
136
|
+
y: d
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function W(e) {
|
|
140
|
+
D && e.pointerId === D.pointerId && (D = void 0, ge());
|
|
141
|
+
}
|
|
142
|
+
function ge() {
|
|
143
|
+
window.removeEventListener("pointermove", me), window.removeEventListener("pointerup", W), window.removeEventListener("pointercancel", W);
|
|
144
|
+
}
|
|
145
|
+
function G(e, t, n) {
|
|
146
|
+
return Math.min(Math.max(e, t), Math.max(t, n));
|
|
147
|
+
}
|
|
148
|
+
function _e() {
|
|
149
|
+
i("update:modelValue", !1), i("cancel");
|
|
150
|
+
}
|
|
151
|
+
function ve(e) {
|
|
152
|
+
e ? i("update:modelValue", !0) : _e();
|
|
153
|
+
}
|
|
154
|
+
async function K() {
|
|
155
|
+
let t = p.value, n = r.file;
|
|
156
|
+
if (t && n && !N.value) {
|
|
157
|
+
b.value = !0;
|
|
158
|
+
try {
|
|
159
|
+
let { height: a, width: o } = M.value, s = document.createElement("canvas");
|
|
160
|
+
s.width = o, s.height = a;
|
|
161
|
+
let c = s.getContext("2d");
|
|
162
|
+
if (!c) throw Error(e("components.pictureUpload.cropFailed"));
|
|
163
|
+
c.drawImage(t, E.x / w.width * w.naturalWidth, E.y / w.height * w.naturalHeight, E.width / w.width * w.naturalWidth, E.height / w.height * w.naturalHeight, 0, 0, o, a);
|
|
164
|
+
let l = [
|
|
165
|
+
"image/jpeg",
|
|
166
|
+
"image/png",
|
|
167
|
+
"image/webp"
|
|
168
|
+
].includes(n.type) ? n.type : "image/png", u = r.crop?.mimeType ?? l, d = G(r.crop?.quality ?? .9, 0, 1), f = await new Promise((t, n) => {
|
|
169
|
+
s.toBlob((r) => r ? t(r) : n(Error(e("components.pictureUpload.cropFailed"))), u, d);
|
|
170
|
+
}), p = {
|
|
171
|
+
"image/jpeg": "jpg",
|
|
172
|
+
"image/png": "png",
|
|
173
|
+
"image/webp": "webp"
|
|
174
|
+
}[u], ee = n.name.replace(/\.[^.]+$/, "");
|
|
175
|
+
i("confirm", new File([f], `${ee}.${p}`, {
|
|
176
|
+
lastModified: Date.now(),
|
|
177
|
+
type: u
|
|
178
|
+
})), i("update:modelValue", !1);
|
|
179
|
+
} catch (t) {
|
|
180
|
+
O.error(t instanceof Error ? t.message : e("components.pictureUpload.cropFailed"));
|
|
181
|
+
} finally {
|
|
182
|
+
b.value = !1;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return (n, r) => (h(), s(x(ae), {
|
|
187
|
+
"model-value": t.modelValue,
|
|
188
|
+
title: x(e)("components.pictureUpload.cropTitle"),
|
|
189
|
+
width: "min(900px, 92vw)",
|
|
190
|
+
"append-to-body": "",
|
|
191
|
+
"destroy-on-close": "",
|
|
192
|
+
"close-on-click-modal": !1,
|
|
193
|
+
"onUpdate:modelValue": ve
|
|
194
|
+
}, {
|
|
195
|
+
footer: C(() => [f(x(T), { onClick: _e }, {
|
|
196
|
+
default: C(() => [d(y(x(e)("common.cancel")), 1)]),
|
|
197
|
+
_: 1
|
|
198
|
+
}), f(x(T), {
|
|
199
|
+
type: "primary",
|
|
200
|
+
loading: b.value,
|
|
201
|
+
disabled: !!N.value,
|
|
202
|
+
onClick: K
|
|
203
|
+
}, {
|
|
204
|
+
default: C(() => [d(y(x(e)("common.confirm")), 1)]),
|
|
205
|
+
_: 1
|
|
206
|
+
}, 8, ["loading", "disabled"])]),
|
|
207
|
+
default: C(() => [u("div", P, [
|
|
208
|
+
u("div", F, [v.value ? (h(), l("div", I, [u("img", {
|
|
209
|
+
ref_key: "imageRef",
|
|
210
|
+
ref: p,
|
|
211
|
+
src: v.value,
|
|
212
|
+
alt: "",
|
|
213
|
+
onLoad: U
|
|
214
|
+
}, null, 40, se), u("div", {
|
|
215
|
+
class: "picture-crop__selection",
|
|
216
|
+
style: m(ue.value),
|
|
217
|
+
onPointerdown: r[0] ||= (e) => pe(e, "move")
|
|
218
|
+
}, [(h(), l(a, null, re([
|
|
219
|
+
"nw",
|
|
220
|
+
"ne",
|
|
221
|
+
"sw",
|
|
222
|
+
"se"
|
|
223
|
+
], (e) => u("i", {
|
|
224
|
+
key: e,
|
|
225
|
+
class: te(["picture-crop__handle", `is-${e}`]),
|
|
226
|
+
onPointerdown: (t) => pe(t, "resize", e)
|
|
227
|
+
}, null, 42, ce)), 64))], 36)])) : c("", !0)]),
|
|
228
|
+
u("div", L, [u("span", null, y(x(e)("components.pictureUpload.resultSize")) + ":" + y(M.value.width) + " × " + y(M.value.height) + " px", 1), j.value ? (h(), l("span", le, y(x(e)("components.pictureUpload.aspectRatio")) + ":" + y(j.value.toFixed(2)), 1)) : c("", !0)]),
|
|
229
|
+
k.value.length ? (h(), l("div", R, [u("span", z, y(x(e)("components.pictureUpload.selectAspectRatio")), 1), (h(!0), l(a, null, re(k.value, (e) => (h(), s(x(T), {
|
|
230
|
+
key: e.label,
|
|
231
|
+
size: "small",
|
|
232
|
+
type: fe(e.value) ? "primary" : "default",
|
|
233
|
+
disabled: !!A.value,
|
|
234
|
+
plain: "",
|
|
235
|
+
onClick: (t) => de(e.value)
|
|
236
|
+
}, {
|
|
237
|
+
default: C(() => [d(y(e.label), 1)]),
|
|
238
|
+
_: 2
|
|
239
|
+
}, 1032, [
|
|
240
|
+
"type",
|
|
241
|
+
"disabled",
|
|
242
|
+
"onClick"
|
|
243
|
+
]))), 128))])) : c("", !0),
|
|
244
|
+
N.value ? (h(), l("p", B, y(N.value), 1)) : (h(), l("p", V, y(x(e)("components.pictureUpload.cropHint")), 1))
|
|
245
|
+
])]),
|
|
246
|
+
_: 1
|
|
247
|
+
}, 8, ["model-value", "title"]));
|
|
248
|
+
}
|
|
249
|
+
}), [["__scopeId", "data-v-6e23c269"]]), H = { class: "picture-upload" }, U = { class: "picture-upload__multiple-grid" }, de = ["src"], fe = ["aria-label", "onClick"], pe = {
|
|
250
|
+
key: 3,
|
|
251
|
+
class: "picture-upload__actions"
|
|
252
|
+
}, me = ["aria-label", "onClick"], he = ["aria-label", "onClick"], W = ["src"], ge = ["aria-label"], G = {
|
|
253
|
+
key: 3,
|
|
254
|
+
class: "picture-upload__actions"
|
|
255
|
+
}, _e = ["aria-label"], ve = ["aria-label"], K = /*#__PURE__*/ t(/* @__PURE__ */ p({
|
|
256
|
+
__name: "picture-upload",
|
|
257
|
+
props: {
|
|
258
|
+
modelValue: { default: "" },
|
|
259
|
+
disabled: {
|
|
260
|
+
type: Boolean,
|
|
261
|
+
default: !1
|
|
262
|
+
},
|
|
263
|
+
maxSize: { default: 5 },
|
|
264
|
+
accept: { default: () => ["image/*"] },
|
|
265
|
+
width: { default: 96 },
|
|
266
|
+
height: { default: 96 },
|
|
267
|
+
showPreview: {
|
|
268
|
+
type: Boolean,
|
|
269
|
+
default: !0
|
|
270
|
+
},
|
|
271
|
+
showDownload: {
|
|
272
|
+
type: Boolean,
|
|
273
|
+
default: !0
|
|
274
|
+
},
|
|
275
|
+
showRemove: {
|
|
276
|
+
type: Boolean,
|
|
277
|
+
default: !0
|
|
278
|
+
},
|
|
279
|
+
selected: {
|
|
280
|
+
type: Boolean,
|
|
281
|
+
default: !1
|
|
282
|
+
},
|
|
283
|
+
errorMessage: { default: "" },
|
|
284
|
+
baseFolder: { default: "" },
|
|
285
|
+
addWatermark: { type: Boolean },
|
|
286
|
+
maxCount: { default: 1 },
|
|
287
|
+
crop: {},
|
|
288
|
+
dimensions: {}
|
|
289
|
+
},
|
|
290
|
+
emits: [
|
|
291
|
+
"update:modelValue",
|
|
292
|
+
"uploadSuccess",
|
|
293
|
+
"uploadError",
|
|
294
|
+
"remove",
|
|
295
|
+
"preview",
|
|
296
|
+
"download"
|
|
297
|
+
],
|
|
298
|
+
setup(t, { emit: d }) {
|
|
299
|
+
let p = t, g = d, y = S(), { resolveImageUrl: T } = n(), { accept: ae, errorMessage: P, maxSize: F } = b(p), I = o(() => p.maxCount > 1 || Array.isArray(p.modelValue)), se = o(() => Array.isArray(p.modelValue) && p.modelValue.every((e) => typeof e == "string")), ce = (e) => typeof e == "string" ? { url: e } : e, L = o(() => Array.isArray(p.modelValue) ? p.modelValue.map(ce) : []), le = (e) => e ? se.value ? e.map((e) => e.fileUrl || e.url || "") : e : se.value ? [] : void 0, R = _(!1), z = _(""), B = _(!1), V = _(!1), K = _(), q = [], J, Y = r({
|
|
300
|
+
modelValue: o(() => {
|
|
301
|
+
if (!I.value) return p.modelValue || void 0;
|
|
302
|
+
}),
|
|
303
|
+
maxSize: F,
|
|
304
|
+
accept: ae,
|
|
305
|
+
errorMessage: P,
|
|
306
|
+
baseFolder: o(() => p.baseFolder || void 0),
|
|
307
|
+
addWatermark: o(() => p.addWatermark),
|
|
308
|
+
onUpdate: (e) => {
|
|
309
|
+
g("update:modelValue", e);
|
|
310
|
+
},
|
|
311
|
+
onUploadSuccess: (e) => {
|
|
312
|
+
g("uploadSuccess", e);
|
|
313
|
+
},
|
|
314
|
+
onUploadError: (e) => {
|
|
315
|
+
g("uploadError", e);
|
|
316
|
+
},
|
|
317
|
+
onRemove: (e) => {
|
|
318
|
+
g("remove", e);
|
|
319
|
+
},
|
|
320
|
+
onPreview: (e) => {
|
|
321
|
+
g("preview", e);
|
|
322
|
+
},
|
|
323
|
+
onDownload: (e) => {
|
|
324
|
+
g("download", e);
|
|
325
|
+
}
|
|
326
|
+
}), X = i({
|
|
327
|
+
modelValue: o(() => I.value ? L.value : void 0),
|
|
328
|
+
maxSize: F,
|
|
329
|
+
accept: ae,
|
|
330
|
+
maxCount: b(p).maxCount,
|
|
331
|
+
errorMessage: P,
|
|
332
|
+
baseFolder: o(() => p.baseFolder || void 0),
|
|
333
|
+
addWatermark: o(() => p.addWatermark),
|
|
334
|
+
onUpdate: (e) => g("update:modelValue", le(e)),
|
|
335
|
+
onUploadSuccess: (e) => g("uploadSuccess", e),
|
|
336
|
+
onUploadError: (e) => g("uploadError", e),
|
|
337
|
+
onRemove: (e) => g("remove", e),
|
|
338
|
+
onPreview: (e) => g("preview", e),
|
|
339
|
+
onDownload: (e) => g("download", e)
|
|
340
|
+
}), Z = o(() => ({
|
|
341
|
+
width: `${p.width}px`,
|
|
342
|
+
height: `${p.height}px`
|
|
343
|
+
})), ye = o(() => T(Y.fileData.value?.fileUrl || Y.fileData.value?.url || Y.fileUrl.value || "")), Q = o(() => L.value.map((e) => T(e.fileUrl || e.url || e.name || "")));
|
|
344
|
+
ie(ye, () => {
|
|
345
|
+
B.value = !1;
|
|
346
|
+
});
|
|
347
|
+
let $ = o(() => B.value && z.value ? z.value : ye.value || z.value), be = _([]), xe = _(0);
|
|
348
|
+
function Se() {
|
|
349
|
+
z.value.startsWith("blob:") && (URL.revokeObjectURL(z.value), z.value = "");
|
|
350
|
+
}
|
|
351
|
+
function Ce() {
|
|
352
|
+
z.value && $.value !== z.value && (B.value = !0);
|
|
353
|
+
}
|
|
354
|
+
ne(() => {
|
|
355
|
+
Se(), J?.resolve(!1), q.splice(0).forEach((e) => e.resolve(!1));
|
|
356
|
+
});
|
|
357
|
+
let we = o(() => I.value ? L.value.length === 0 && !X.loading.value : !$.value && !Y.loading.value), Te = o(() => I.value ? X.acceptAttr.value : Y.acceptAttr.value), Ee = o(() => I.value ? X.isError.value : Y.isError.value), De = o(() => ({
|
|
358
|
+
"picture-upload__uploader--selected": p.selected && !we.value && !Ee.value,
|
|
359
|
+
"picture-upload__uploader--error": Ee.value,
|
|
360
|
+
"is-disabled": p.disabled
|
|
361
|
+
}));
|
|
362
|
+
function Oe(e) {
|
|
363
|
+
return I.value ? X.handleUpload(e) : (Se(), z.value = URL.createObjectURL(e.file), B.value = !1, Y.handleUpload(e));
|
|
364
|
+
}
|
|
365
|
+
async function ke(t) {
|
|
366
|
+
let n = t;
|
|
367
|
+
if (p.crop?.enabled) {
|
|
368
|
+
if (!Ae(t)) return O.error(e("components.fileUpload.typeNotAllowed", { types: p.accept.join(", ") })), !1;
|
|
369
|
+
let r = await je(t);
|
|
370
|
+
if (!r) return !1;
|
|
371
|
+
n = r;
|
|
372
|
+
}
|
|
373
|
+
let r = await Pe(n);
|
|
374
|
+
return r ? (O.error(r), !1) : (I.value ? X.beforeUpload(n) : Y.beforeUpload(n)) !== !1 && n;
|
|
375
|
+
}
|
|
376
|
+
function Ae(e) {
|
|
377
|
+
return p.accept.length === 0 || p.accept.some((t) => {
|
|
378
|
+
if (t.startsWith(".")) return e.name.toLowerCase().endsWith(t.toLowerCase());
|
|
379
|
+
let n = t.toLowerCase().replace("*", "");
|
|
380
|
+
return e.type.toLowerCase().startsWith(n);
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
function je(e) {
|
|
384
|
+
return new Promise((t) => {
|
|
385
|
+
q.push({
|
|
386
|
+
file: e,
|
|
387
|
+
resolve: t
|
|
388
|
+
}), Me();
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
function Me() {
|
|
392
|
+
J || q.length === 0 || (J = q.shift(), K.value = J?.file, V.value = !!J);
|
|
393
|
+
}
|
|
394
|
+
function Ne(e) {
|
|
395
|
+
let t = J;
|
|
396
|
+
t && (J = void 0, V.value = !1, K.value = void 0, t.resolve(e), ee(Me));
|
|
397
|
+
}
|
|
398
|
+
async function Pe(t) {
|
|
399
|
+
let n = p.dimensions;
|
|
400
|
+
if (!n) return "";
|
|
401
|
+
let r = URL.createObjectURL(t);
|
|
402
|
+
try {
|
|
403
|
+
let t = await new Promise((t, n) => {
|
|
404
|
+
let i = new Image();
|
|
405
|
+
i.onload = () => t(i), i.onerror = () => n(Error(e("components.pictureUpload.readFailed"))), i.src = r;
|
|
406
|
+
}), i = t.naturalWidth, a = t.naturalHeight;
|
|
407
|
+
return n.width !== void 0 && i !== n.width ? e("components.pictureUpload.widthExact", { width: n.width }) : n.height !== void 0 && a !== n.height ? e("components.pictureUpload.heightExact", { height: n.height }) : n.minWidth !== void 0 && i < n.minWidth ? e("components.pictureUpload.widthMin", { width: n.minWidth }) : n.minHeight !== void 0 && a < n.minHeight ? e("components.pictureUpload.heightMin", { height: n.minHeight }) : n.maxWidth !== void 0 && i > n.maxWidth ? e("components.pictureUpload.widthMax", { width: n.maxWidth }) : n.maxHeight !== void 0 && a > n.maxHeight ? e("components.pictureUpload.heightMax", { height: n.maxHeight }) : "";
|
|
408
|
+
} catch (t) {
|
|
409
|
+
return t instanceof Error ? t.message : e("components.pictureUpload.readFailed");
|
|
410
|
+
} finally {
|
|
411
|
+
URL.revokeObjectURL(r);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
function Fe() {
|
|
415
|
+
$.value && p.showPreview && (R.value = !0, Y.fileData.value && g("preview", Y.fileData.value));
|
|
416
|
+
}
|
|
417
|
+
function Ie(e) {
|
|
418
|
+
if (!p.showPreview || !Q.value[e]) return;
|
|
419
|
+
be.value = Q.value, xe.value = e, R.value = !0;
|
|
420
|
+
let t = L.value[e];
|
|
421
|
+
t && g("preview", t);
|
|
422
|
+
}
|
|
423
|
+
function Le() {
|
|
424
|
+
p.showDownload && (!$.value || !Y.fileData.value ? O.error(e("components.fileUpload.fileDownloadError")) : Y.handleDownload());
|
|
425
|
+
}
|
|
426
|
+
function Re(t) {
|
|
427
|
+
if (!p.showDownload) return;
|
|
428
|
+
let n = T(t.fileUrl || t.url || t.name || "");
|
|
429
|
+
if (!n) {
|
|
430
|
+
O.error(e("components.fileUpload.fileDownloadError"));
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
let r = document.createElement("a");
|
|
434
|
+
r.href = n, r.download = t.name || "image", r.click(), g("download", t);
|
|
435
|
+
}
|
|
436
|
+
function ze() {
|
|
437
|
+
I.value || p.showRemove && !p.disabled && (Se(), B.value = !1, Y.handleRemove());
|
|
438
|
+
}
|
|
439
|
+
function Be(e) {
|
|
440
|
+
if (!p.showRemove || p.disabled) return;
|
|
441
|
+
let t = e.fileUrl || e.url || e.name || "", n = L.value.filter((e) => (e.fileUrl || e.url || e.name || "") !== t);
|
|
442
|
+
g("update:modelValue", le(n)), g("remove", e);
|
|
443
|
+
}
|
|
444
|
+
return (t, n) => (h(), l("div", H, [
|
|
445
|
+
I.value ? (h(), s(x(A), {
|
|
446
|
+
key: 0,
|
|
447
|
+
class: te(["picture-upload__uploader picture-upload__uploader--multiple", De.value]),
|
|
448
|
+
"show-file-list": !1,
|
|
449
|
+
multiple: !0,
|
|
450
|
+
"before-upload": ke,
|
|
451
|
+
"http-request": Oe,
|
|
452
|
+
disabled: p.disabled || x(X).loading.value || p.maxCount > 1 && L.value.length >= p.maxCount,
|
|
453
|
+
accept: Te.value
|
|
454
|
+
}, {
|
|
455
|
+
default: C(() => [u("div", U, [
|
|
456
|
+
(h(!0), l(a, null, re(L.value, (n, r) => (h(), l("div", {
|
|
457
|
+
key: n.fileUrl || n.url || n.name || r,
|
|
458
|
+
class: "picture-upload__image-wrap",
|
|
459
|
+
style: m(Z.value)
|
|
460
|
+
}, [
|
|
461
|
+
y.picture ? v(t.$slots, "picture", {
|
|
462
|
+
file: n,
|
|
463
|
+
url: Q.value[r],
|
|
464
|
+
index: r,
|
|
465
|
+
preview: () => Ie(r),
|
|
466
|
+
download: () => Re(n),
|
|
467
|
+
remove: () => Be(n)
|
|
468
|
+
}, void 0, !0, 0) : (h(), l("img", {
|
|
469
|
+
key: 1,
|
|
470
|
+
class: "picture-upload__image",
|
|
471
|
+
src: Q.value[r],
|
|
472
|
+
alt: "",
|
|
473
|
+
referrerpolicy: "no-referrer"
|
|
474
|
+
}, null, 8, de)),
|
|
475
|
+
!y.picture && p.showRemove && !p.disabled ? (h(), l("button", {
|
|
476
|
+
key: 2,
|
|
477
|
+
type: "button",
|
|
478
|
+
class: "picture-upload__remove",
|
|
479
|
+
"aria-label": x(e)("components.fileUpload.remove"),
|
|
480
|
+
onClick: w((e) => Be(n), ["stop", "prevent"])
|
|
481
|
+
}, [f(x(E), { size: 12 }, {
|
|
482
|
+
default: C(() => [f(x(j))]),
|
|
483
|
+
_: 1
|
|
484
|
+
})], 8, fe)) : c("", !0),
|
|
485
|
+
y.picture ? c("", !0) : (h(), l("div", pe, [p.showPreview ? (h(), l("button", {
|
|
486
|
+
key: 0,
|
|
487
|
+
type: "button",
|
|
488
|
+
class: "picture-upload__action",
|
|
489
|
+
"aria-label": x(e)("components.fileUpload.preview"),
|
|
490
|
+
onClick: w((e) => Ie(r), ["stop", "prevent"])
|
|
491
|
+
}, [f(x(E), {
|
|
492
|
+
size: 20,
|
|
493
|
+
color: "#fff"
|
|
494
|
+
}, {
|
|
495
|
+
default: C(() => [f(x(N))]),
|
|
496
|
+
_: 1
|
|
497
|
+
})], 8, me)) : c("", !0), p.showDownload ? (h(), l("button", {
|
|
498
|
+
key: 1,
|
|
499
|
+
type: "button",
|
|
500
|
+
class: "picture-upload__action",
|
|
501
|
+
"aria-label": x(e)("components.fileUpload.download"),
|
|
502
|
+
onClick: w((e) => Re(n), ["stop", "prevent"])
|
|
503
|
+
}, [f(x(E), {
|
|
504
|
+
size: 20,
|
|
505
|
+
color: "#fff"
|
|
506
|
+
}, {
|
|
507
|
+
default: C(() => [f(x(oe))]),
|
|
508
|
+
_: 1
|
|
509
|
+
})], 8, he)) : c("", !0)]))
|
|
510
|
+
], 4))), 128)),
|
|
511
|
+
x(X).loading.value ? (h(), l("div", {
|
|
512
|
+
key: 0,
|
|
513
|
+
class: "picture-upload__loading",
|
|
514
|
+
style: m(Z.value)
|
|
515
|
+
}, [v(t.$slots, "loading", { progress: x(X).totalProgress.value }, () => [f(x(k), {
|
|
516
|
+
type: "circle",
|
|
517
|
+
width: Math.min(p.width, p.height, 72),
|
|
518
|
+
percentage: x(X).totalProgress.value
|
|
519
|
+
}, null, 8, ["width", "percentage"])], !0)], 4)) : c("", !0),
|
|
520
|
+
p.maxCount <= 1 || L.value.length < p.maxCount ? (h(), l("div", {
|
|
521
|
+
key: 1,
|
|
522
|
+
class: "picture-upload__placeholder",
|
|
523
|
+
style: m(Z.value)
|
|
524
|
+
}, [v(t.$slots, "placeholder", { multiple: !0 }, () => [v(t.$slots, "default", { multiple: !0 }, () => [f(x(E), {
|
|
525
|
+
class: "picture-upload__placeholder-icon",
|
|
526
|
+
size: 28
|
|
527
|
+
}, {
|
|
528
|
+
default: C(() => [f(x(M))]),
|
|
529
|
+
_: 1
|
|
530
|
+
})], !0)], !0)], 4)) : c("", !0)
|
|
531
|
+
])]),
|
|
532
|
+
_: 3
|
|
533
|
+
}, 8, [
|
|
534
|
+
"class",
|
|
535
|
+
"disabled",
|
|
536
|
+
"accept"
|
|
537
|
+
])) : (h(), s(x(A), {
|
|
538
|
+
key: 1,
|
|
539
|
+
class: te(["picture-upload__uploader", De.value]),
|
|
540
|
+
"show-file-list": !1,
|
|
541
|
+
"before-upload": ke,
|
|
542
|
+
"http-request": Oe,
|
|
543
|
+
disabled: p.disabled || x(Y).loading.value,
|
|
544
|
+
accept: Te.value
|
|
545
|
+
}, {
|
|
546
|
+
default: C(() => [x(Y).loading.value ? (h(), l("div", {
|
|
547
|
+
key: 0,
|
|
548
|
+
class: "picture-upload__loading",
|
|
549
|
+
style: m(Z.value)
|
|
550
|
+
}, [v(t.$slots, "loading", { progress: x(Y).uploadProgress.value }, () => [f(x(k), {
|
|
551
|
+
type: "circle",
|
|
552
|
+
width: Math.min(p.width, p.height, 72),
|
|
553
|
+
percentage: x(Y).uploadProgress.value
|
|
554
|
+
}, null, 8, ["width", "percentage"])], !0)], 4)) : we.value ? (h(), l("div", {
|
|
555
|
+
key: 2,
|
|
556
|
+
class: "picture-upload__placeholder",
|
|
557
|
+
style: m(Z.value)
|
|
558
|
+
}, [v(t.$slots, "placeholder", { multiple: !1 }, () => [v(t.$slots, "default", { multiple: !1 }, () => [f(x(E), {
|
|
559
|
+
class: "picture-upload__placeholder-icon",
|
|
560
|
+
size: 28
|
|
561
|
+
}, {
|
|
562
|
+
default: C(() => [f(x(M))]),
|
|
563
|
+
_: 1
|
|
564
|
+
})], !0)], !0)], 4)) : (h(), l("div", {
|
|
565
|
+
key: 1,
|
|
566
|
+
class: "picture-upload__image-wrap",
|
|
567
|
+
style: m(Z.value)
|
|
568
|
+
}, [
|
|
569
|
+
y.picture && x(Y).fileData.value ? v(t.$slots, "picture", {
|
|
570
|
+
file: x(Y).fileData.value,
|
|
571
|
+
url: $.value,
|
|
572
|
+
index: 0,
|
|
573
|
+
preview: Fe,
|
|
574
|
+
download: Le,
|
|
575
|
+
remove: ze
|
|
576
|
+
}, void 0, !0, 0) : (h(), l("img", {
|
|
577
|
+
key: 1,
|
|
578
|
+
class: "picture-upload__image",
|
|
579
|
+
src: $.value,
|
|
580
|
+
alt: "",
|
|
581
|
+
referrerpolicy: "no-referrer",
|
|
582
|
+
onError: Ce
|
|
583
|
+
}, null, 40, W)),
|
|
584
|
+
!y.picture && p.showRemove && !p.disabled ? (h(), l("button", {
|
|
585
|
+
key: 2,
|
|
586
|
+
type: "button",
|
|
587
|
+
class: "picture-upload__remove",
|
|
588
|
+
"aria-label": x(e)("components.fileUpload.remove"),
|
|
589
|
+
onClick: w(ze, ["stop", "prevent"])
|
|
590
|
+
}, [f(x(E), { size: 12 }, {
|
|
591
|
+
default: C(() => [f(x(j))]),
|
|
592
|
+
_: 1
|
|
593
|
+
})], 8, ge)) : c("", !0),
|
|
594
|
+
y.picture ? c("", !0) : (h(), l("div", G, [p.showPreview ? (h(), l("button", {
|
|
595
|
+
key: 0,
|
|
596
|
+
type: "button",
|
|
597
|
+
class: "picture-upload__action",
|
|
598
|
+
"aria-label": x(e)("components.fileUpload.preview"),
|
|
599
|
+
onClick: w(Fe, ["stop", "prevent"])
|
|
600
|
+
}, [f(x(E), {
|
|
601
|
+
size: 20,
|
|
602
|
+
color: "#fff"
|
|
603
|
+
}, {
|
|
604
|
+
default: C(() => [f(x(N))]),
|
|
605
|
+
_: 1
|
|
606
|
+
})], 8, _e)) : c("", !0), p.showDownload ? (h(), l("button", {
|
|
607
|
+
key: 1,
|
|
608
|
+
type: "button",
|
|
609
|
+
class: "picture-upload__action",
|
|
610
|
+
"aria-label": x(e)("components.fileUpload.download"),
|
|
611
|
+
onClick: w(Le, ["stop", "prevent"])
|
|
612
|
+
}, [f(x(E), {
|
|
613
|
+
size: 20,
|
|
614
|
+
color: "#fff"
|
|
615
|
+
}, {
|
|
616
|
+
default: C(() => [f(x(oe))]),
|
|
617
|
+
_: 1
|
|
618
|
+
})], 8, ve)) : c("", !0)]))
|
|
619
|
+
], 4))]),
|
|
620
|
+
_: 3
|
|
621
|
+
}, 8, [
|
|
622
|
+
"class",
|
|
623
|
+
"disabled",
|
|
624
|
+
"accept"
|
|
625
|
+
])),
|
|
626
|
+
R.value ? (h(), s(x(D), {
|
|
627
|
+
key: 2,
|
|
628
|
+
"url-list": I.value ? be.value : [$.value],
|
|
629
|
+
"initial-index": I.value ? xe.value : 0,
|
|
630
|
+
onClose: n[0] ||= (e) => R.value = !1
|
|
631
|
+
}, null, 8, ["url-list", "initial-index"])) : c("", !0),
|
|
632
|
+
f(ue, {
|
|
633
|
+
modelValue: V.value,
|
|
634
|
+
"onUpdate:modelValue": n[1] ||= (e) => V.value = e,
|
|
635
|
+
file: K.value,
|
|
636
|
+
crop: p.crop,
|
|
637
|
+
dimensions: p.dimensions,
|
|
638
|
+
onConfirm: Ne,
|
|
639
|
+
onCancel: n[2] ||= (e) => Ne(!1)
|
|
640
|
+
}, null, 8, [
|
|
641
|
+
"modelValue",
|
|
642
|
+
"file",
|
|
643
|
+
"crop",
|
|
644
|
+
"dimensions"
|
|
645
|
+
])
|
|
646
|
+
]));
|
|
647
|
+
}
|
|
648
|
+
}), [["__scopeId", "data-v-8c2cff09"]]);
|
|
649
|
+
export { K as t };
|