@nubisco/ui 5.63.0 → 5.64.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.
@@ -1,413 +0,0 @@
1
- import { t as e } from "./_plugin-vue_export-helper-C6QCLu9I.js";
2
- import { t } from "./Grid-BVIhOyQ1.js";
3
- import { t as n } from "./vue-i18n-DgCNp5tk.js";
4
- import { Fragment as r, computed as i, createBlock as a, createCommentVNode as o, createElementBlock as s, createElementVNode as c, createTextVNode as l, createVNode as u, defineComponent as d, normalizeClass as f, normalizeStyle as p, onBeforeUnmount as ee, onMounted as te, openBlock as m, ref as h, renderList as ne, toDisplayString as g, watch as _, withCtx as v, withModifiers as y } from "vue";
5
- //#region src/components/ImageCropper.d.ts
6
- var b = /* @__PURE__ */ function(e) {
7
- return e.TopLeft = "top-left", e.Top = "top", e.TopRight = "top-right", e.Right = "right", e.BottomRight = "bottom-right", e.Bottom = "bottom", e.BottomLeft = "bottom-left", e.Left = "left", e;
8
- }(b || {}), x = { class: "nb-image-cropper" }, S = ["onMousedown", "onTouchstart"], re = ["src", "alt"], C = 700, w = 400, T = /* @__PURE__ */ e(/* @__PURE__ */ d({
9
- __name: "ImageCropper",
10
- props: {
11
- image: {},
12
- cropAsCircle: {
13
- type: Boolean,
14
- default: !1
15
- },
16
- outputAsCircle: {
17
- type: Boolean,
18
- default: !1
19
- },
20
- lockAspectRatio: {
21
- type: Boolean,
22
- default: !1
23
- },
24
- showPreview: {
25
- type: Boolean,
26
- default: !1
27
- }
28
- },
29
- emits: ["crop"],
30
- setup(e, { emit: d }) {
31
- let T = {
32
- en: {
33
- X: "X",
34
- Y: "Y",
35
- WIDTH: "Width",
36
- HEIGHT: "Height",
37
- IMAGE_THUMBNAIL: "Cropped preview"
38
- },
39
- pt: {
40
- X: "X",
41
- Y: "Y",
42
- WIDTH: "Largura",
43
- HEIGHT: "Altura",
44
- IMAGE_THUMBNAIL: "Pré-visualização recortada"
45
- }
46
- }, { t: ie, te: ae, locale: oe } = n({ useScope: "global" });
47
- function E(e) {
48
- if (ae(e)) return ie(e);
49
- let t = e.slice(7);
50
- return T[String(oe.value).toLowerCase().split("-")[0]]?.[t] ?? T.en[t] ?? e;
51
- }
52
- let D = e, O = d, k = h(null), A = null, j = new Image(), M = null, N = {
53
- x: 1,
54
- y: 1
55
- }, P = h({
56
- x: 50,
57
- y: 50,
58
- width: 200,
59
- height: 200
60
- }), F = h(null), I = h(null), L = !1, R = !1, z = {
61
- x: 0,
62
- y: 0
63
- }, B = !1, V = {
64
- x: 0,
65
- y: 0
66
- }, H = {
67
- x: 0,
68
- y: 0,
69
- width: 0,
70
- height: 0
71
- }, U = null, W = !1, se = [
72
- { name: b.TopLeft },
73
- { name: b.Top },
74
- { name: b.TopRight },
75
- { name: b.Right },
76
- { name: b.BottomRight },
77
- { name: b.Bottom },
78
- { name: b.BottomLeft },
79
- { name: b.Left }
80
- ], G = () => {
81
- if (!D.image) {
82
- console.error("No image file provided");
83
- return;
84
- }
85
- M &&= (URL.revokeObjectURL(M), null), j.onload = () => {
86
- let { drawWidth: e, drawHeight: t } = ce();
87
- if (k.value) {
88
- k.value.width = e, k.value.height = t;
89
- let n = (k.value.width - j.width * N.x) / 2, r = (k.value.height - j.height * N.y) / 2;
90
- if (D.cropAsCircle || D.lockAspectRatio) {
91
- let e = Math.min(j.width * N.x, j.height * N.y) * .5;
92
- P.value = {
93
- x: n + (j.width * N.x - e) / 2,
94
- y: r + (j.height * N.y - e) / 2,
95
- width: e,
96
- height: e
97
- };
98
- } else P.value = {
99
- x: n + (j.width * N.x * .5 - j.width * N.x * .25),
100
- y: r + (j.height * N.y * .5 - j.height * N.y * .25),
101
- width: j.width * N.x * .5,
102
- height: j.height * N.y * .5
103
- };
104
- K(), $();
105
- }
106
- }, j.onerror = () => {
107
- console.error("Failed to load image");
108
- }, M = URL.createObjectURL(D.image), j.src = M;
109
- };
110
- te(() => {
111
- k.value && (A = k.value.getContext("2d"), A && (A.imageSmoothingEnabled = !0, A.imageSmoothingQuality = "high"), D.image && G());
112
- }), ee(() => {
113
- M &&= (URL.revokeObjectURL(M), null);
114
- let e = F.value;
115
- e && (URL.revokeObjectURL(e), F.value = null);
116
- }), _(() => D.image, (e) => {
117
- e && G();
118
- }), _(() => [
119
- D.cropAsCircle,
120
- D.outputAsCircle,
121
- D.lockAspectRatio
122
- ], () => {
123
- k.value && A && K();
124
- });
125
- let ce = () => {
126
- let e = j.width / j.height, t = C, n = w;
127
- return e > C / w ? n = C / e : t = w * e, N.x = t / j.width, N.y = n / j.height, {
128
- drawWidth: t,
129
- drawHeight: n
130
- };
131
- }, K = () => {
132
- if (A && k.value) {
133
- A.clearRect(0, 0, k.value.width, k.value.height);
134
- let e = (k.value.width - j.width * N.x) / 2, t = (k.value.height - j.height * N.y) / 2;
135
- A.drawImage(j, 0, 0, j.width, j.height, e, t, j.width * N.x, j.height * N.y), le();
136
- }
137
- }, le = () => {
138
- A && k.value && (A.save(), A.beginPath(), D.cropAsCircle ? A.arc(P.value.x + P.value.width / 2, P.value.y + P.value.height / 2, P.value.width / 2, 0, Math.PI * 2) : A.rect(P.value.x, P.value.y, P.value.width, P.value.height), A.rect(0, 0, k.value.width, k.value.height), A.clip("evenodd"), A.fillStyle = "rgba(0, 0, 0, 0.5)", A.fillRect(0, 0, k.value.width, k.value.height), A.restore(), A.save(), A.strokeStyle = "rgba(255, 255, 255, 0.8)", A.lineWidth = 1, A.setLineDash([5, 5]), A.imageSmoothingEnabled = !1, D.cropAsCircle ? (A.beginPath(), A.arc(P.value.x + P.value.width / 2, P.value.y + P.value.height / 2, P.value.width / 2, 0, Math.PI * 2), A.stroke()) : A.strokeRect(P.value.x, P.value.y, P.value.width, P.value.height), A.restore());
139
- }, ue = i(() => {
140
- if (D.cropAsCircle) {
141
- let e = P.value.x + P.value.width / 2, t = P.value.y + P.value.height / 2, n = P.value.width / 2;
142
- return {
143
- "top-left": {
144
- left: `${e - n - 5}px`,
145
- top: `${t - n - 5}px`
146
- },
147
- top: {
148
- left: `${e - 5}px`,
149
- top: `${t - n - 5}px`
150
- },
151
- "top-right": {
152
- left: `${e + n - 5}px`,
153
- top: `${t - n - 5}px`
154
- },
155
- right: {
156
- left: `${e + n - 5}px`,
157
- top: `${t - 5}px`
158
- },
159
- "bottom-right": {
160
- left: `${e + n - 5}px`,
161
- top: `${t + n - 5}px`
162
- },
163
- bottom: {
164
- left: `${e - 5}px`,
165
- top: `${t + n - 5}px`
166
- },
167
- "bottom-left": {
168
- left: `${e - n - 5}px`,
169
- top: `${t + n - 5}px`
170
- },
171
- left: {
172
- left: `${e - n - 5}px`,
173
- top: `${t - 5}px`
174
- }
175
- };
176
- } else return {
177
- "top-left": {
178
- left: `${P.value.x - 5}px`,
179
- top: `${P.value.y - 5}px`
180
- },
181
- top: {
182
- left: `${P.value.x + P.value.width / 2 - 5}px`,
183
- top: `${P.value.y - 5}px`
184
- },
185
- "top-right": {
186
- left: `${P.value.x + P.value.width - 5}px`,
187
- top: `${P.value.y - 5}px`
188
- },
189
- right: {
190
- left: `${P.value.x + P.value.width - 5}px`,
191
- top: `${P.value.y + P.value.height / 2 - 5}px`
192
- },
193
- "bottom-right": {
194
- left: `${P.value.x + P.value.width - 5}px`,
195
- top: `${P.value.y + P.value.height - 5}px`
196
- },
197
- bottom: {
198
- left: `${P.value.x + P.value.width / 2 - 5}px`,
199
- top: `${P.value.y + P.value.height - 5}px`
200
- },
201
- "bottom-left": {
202
- left: `${P.value.x - 5}px`,
203
- top: `${P.value.y + P.value.height - 5}px`
204
- },
205
- left: {
206
- left: `${P.value.x - 5}px`,
207
- top: `${P.value.y + P.value.height / 2 - 5}px`
208
- }
209
- };
210
- }), de = (e) => {
211
- if ("touches" in e && e.touches.length > 0) {
212
- let t = e.touches[0];
213
- return {
214
- clientX: t.clientX,
215
- clientY: t.clientY
216
- };
217
- } else if ("clientX" in e && "clientY" in e) return {
218
- clientX: e.clientX,
219
- clientY: e.clientY
220
- };
221
- return {
222
- clientX: 0,
223
- clientY: 0
224
- };
225
- }, q = (e) => {
226
- let t = k.value;
227
- if (!t) return null;
228
- let { clientX: n, clientY: r } = de(e), { left: i, top: a } = t.getBoundingClientRect();
229
- return {
230
- x: n - i,
231
- y: r - a
232
- };
233
- }, J = (e) => {
234
- e.preventDefault();
235
- let t = q(e);
236
- if (!t) return;
237
- let { x: n, y: r } = t;
238
- ge(n, r) && (R = !0, L = !0, z = {
239
- x: n - P.value.x,
240
- y: r - P.value.y
241
- });
242
- }, Y = (e) => {
243
- R ? fe(e) : B && me(e);
244
- }, X = () => {
245
- R && (pe(), R = !1, $()), B && (he(), $()), L = !1, R = !1;
246
- }, fe = (e) => {
247
- if (L) {
248
- let t = q(e);
249
- if (!t) return;
250
- let { x: n, y: r } = t;
251
- P.value.x = Math.floor(n - z.x), P.value.y = Math.floor(r - z.y), K();
252
- }
253
- }, pe = () => {
254
- L &&= (Q(), K(), !1);
255
- }, Z = (e, t) => {
256
- e.preventDefault();
257
- let n = q(e);
258
- n && (B = !0, U = t, V = {
259
- x: n.x,
260
- y: n.y
261
- }, H = { ...P.value }, W = e instanceof MouseEvent && e.shiftKey);
262
- }, me = (e) => {
263
- if (!B) return;
264
- if (D.lockAspectRatio && k.value) {
265
- let t = q(e);
266
- if (!t) return;
267
- let { x: n, y: r } = t, i = H.x + H.width / 2, a = H.y + H.height / 2;
268
- if (D.cropAsCircle) {
269
- let e = Math.max(Math.abs(n - i), Math.abs(r - a)), t = e * 2;
270
- P.value = {
271
- x: i - e,
272
- y: a - e,
273
- width: t,
274
- height: t
275
- };
276
- } else {
277
- let e = H.width / H.height, t = Math.abs(n - i), r = Math.max(t * 2, 50), o = r / e;
278
- P.value = {
279
- x: i - r / 2,
280
- y: a - o / 2,
281
- width: r,
282
- height: o
283
- };
284
- }
285
- K();
286
- return;
287
- }
288
- let t = q(e);
289
- if (!t) return;
290
- let { x: n, y: r } = t, i = n - V.x, a = r - V.y;
291
- W = e instanceof MouseEvent && e.shiftKey;
292
- let o = { ...H };
293
- switch (U) {
294
- case "top-left":
295
- o.x += i, o.y += a, o.width -= i, o.height -= a;
296
- break;
297
- case "top":
298
- o.y += a, o.height -= a;
299
- break;
300
- case "top-right":
301
- o.y += a, o.width += i, o.height -= a;
302
- break;
303
- case "right":
304
- o.width += i;
305
- break;
306
- case "bottom-right":
307
- o.width += i, o.height += a;
308
- break;
309
- case "bottom":
310
- o.height += a;
311
- break;
312
- case "bottom-left":
313
- o.x += i, o.width -= i, o.height += a;
314
- break;
315
- case "left":
316
- o.x += i, o.width -= i;
317
- break;
318
- }
319
- if (o.width < 50 && (o.width = 50), o.height < 50 && (o.height = 50), W && U) {
320
- let e = H.width / H.height;
321
- ["left", "right"].includes(U) ? (o.height = o.width / e, U === "left" && (o.y = H.y - (o.height - H.height) / 2)) : ["top", "bottom"].includes(U) && (o.width = o.height * e, U === "top" && (o.x = H.x - (o.width - H.width) / 2));
322
- }
323
- P.value = o, K();
324
- }, he = () => {
325
- B && (Q(), K(), B = !1, U = null);
326
- }, ge = (e, t) => {
327
- if (D.cropAsCircle) {
328
- let n = P.value.x + P.value.width / 2, r = P.value.y + P.value.height / 2, i = P.value.width / 2, a = e - n, o = t - r;
329
- return a * a + o * o <= i * i;
330
- } else return e >= P.value.x - 2 && e <= P.value.x + P.value.width + 2 && t >= P.value.y - 2 && t <= P.value.y + P.value.height + 2;
331
- }, Q = () => {
332
- let e = k.value.width, t = k.value.height;
333
- if (P.value.width < 50 && (P.value.width = 50), P.value.height < 50 && (P.value.height = 50), D.lockAspectRatio) if (D.cropAsCircle) P.value.height = P.value.width;
334
- else {
335
- let e = H.width / H.height;
336
- P.value.height = P.value.width / e;
337
- }
338
- else if (W) {
339
- let e = H.width / H.height;
340
- P.value.height = P.value.width / e;
341
- }
342
- if (D.cropAsCircle || D.lockAspectRatio) {
343
- let n = P.value.width / P.value.height;
344
- (P.value.width > e || P.value.height > t) && (P.value.width > P.value.height ? (P.value.width = e, P.value.height = e / n) : (P.value.height = t, P.value.width = t * n)), P.value.x < 0 && (P.value.x = 0), P.value.y < 0 && (P.value.y = 0), P.value.x + P.value.width > e && (P.value.x = e - P.value.width), P.value.y + P.value.height > t && (P.value.y = t - P.value.height);
345
- } else P.value.x < 0 && (P.value.x = 0), P.value.y < 0 && (P.value.y = 0), P.value.width > e && (P.value.width = e, P.value.x = 0), P.value.height > t && (P.value.height = t, P.value.y = 0), P.value.x + P.value.width > e && (P.value.x = e - P.value.width), P.value.y + P.value.height > t && (P.value.y = t - P.value.height);
346
- }, $ = () => {
347
- if (k.value && A) {
348
- let e = (k.value.width - j.width * N.x) / 2, t = (k.value.height - j.height * N.y) / 2, n = (P.value.x - e) / N.x, r = (P.value.y - t) / N.y, i = P.value.width / N.x, a = P.value.height / N.y, o = {
349
- x: Math.round(n),
350
- y: Math.round(r),
351
- width: Math.round(i),
352
- height: Math.round(a)
353
- }, s = Math.max(0, Math.min(o.x, j.width)), c = Math.max(0, Math.min(o.y, j.height)), l = Math.min(o.width, j.width - s), u = Math.min(o.height, j.height - c), d = document.createElement("canvas");
354
- d.width = l, d.height = u;
355
- let f = d.getContext("2d");
356
- f && (f.drawImage(j, s, c, l, u, 0, 0, l, u), D.cropAsCircle && D.outputAsCircle && (f.globalCompositeOperation = "destination-in", f.beginPath(), f.arc(l / 2, u / 2, l / 2, 0, Math.PI * 2), f.closePath(), f.fill(), f.globalCompositeOperation = "source-over"), d.toBlob((e) => {
357
- if (e) {
358
- let t = F.value;
359
- t && URL.revokeObjectURL(t), F.value = URL.createObjectURL(e), I.value = o, O("crop", {
360
- blob: e,
361
- geometry: o
362
- });
363
- }
364
- }, "image/jpeg", .8));
365
- }
366
- };
367
- return _(() => D, () => {
368
- $();
369
- }, { deep: !0 }), (n, i) => (m(), s("div", x, [c("div", {
370
- class: "canvas-container",
371
- onMousedown: J,
372
- onMousemove: Y,
373
- onMouseup: X,
374
- onMouseleave: X,
375
- onTouchstart: J,
376
- onTouchmove: Y,
377
- onTouchend: X
378
- }, [c("canvas", {
379
- ref_key: "canvas",
380
- ref: k
381
- }, null, 512), (m(), s(r, null, ne(se, (e) => c("div", {
382
- key: e.name,
383
- class: f(["resize-handle", e.name]),
384
- style: p(ue.value[e.name]),
385
- onMousedown: y((t) => Z(t, e.name), ["stop"]),
386
- onTouchstart: y((t) => Z(t, e.name), ["stop"])
387
- }, null, 46, S)), 64))], 32), e.showPreview && F.value && I.value ? (m(), a(t, {
388
- key: 0,
389
- class: "cropped-image-preview"
390
- }, {
391
- default: v(() => [u(t, {
392
- is: "ul",
393
- dir: "col",
394
- justify: "center",
395
- gap: "sm"
396
- }, {
397
- default: v(() => [
398
- c("li", null, [c("strong", null, g(E("common.X")), 1), l(" " + g(I.value.x.toFixed(0)), 1)]),
399
- c("li", null, [c("strong", null, g(E("common.Y")), 1), l(" " + g(I.value.y.toFixed(0)), 1)]),
400
- c("li", null, [c("strong", null, g(E("common.WIDTH")), 1), l(" " + g(I.value.width.toFixed(0)), 1)]),
401
- c("li", null, [c("strong", null, g(E("common.HEIGHT")), 1), l(" " + g(I.value.height.toFixed(0)), 1)])
402
- ]),
403
- _: 1
404
- }), c("img", {
405
- src: F.value,
406
- alt: E("common.IMAGE_THUMBNAIL")
407
- }, null, 8, re)]),
408
- _: 1
409
- })) : o("", !0)]));
410
- }
411
- }), [["__scopeId", "data-v-057c9675"]]);
412
- //#endregion
413
- export { b as n, T as t };