ablok-components 0.3.124 → 0.3.127

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,11 +1,12 @@
1
1
  import e from "../../atoms/svg-icon/svg-icon.js";
2
2
  import t from "../../atoms/loading-spinner/loading-spinner.js";
3
- import { dataURItoBlob as n } from "../../../utilities/helpers.js";
4
- import r from "../input-dropdown/input-dropdown.js";
5
- import { useCameraFilter as i } from "../../../composables/useCameraFilter.js";
6
- import a from "../../atoms/zoom-slider/zoom-slider.js";
7
- import o from "../../../assets/img/guide.js";
8
- import { computed as s, createBlock as c, createCommentVNode as l, createElementBlock as u, createElementVNode as d, createVNode as f, defineComponent as p, nextTick as ee, normalizeClass as m, normalizeStyle as te, onBeforeUnmount as ne, onMounted as re, openBlock as h, ref as g, toDisplayString as _, vShow as ie, watch as ae, withCtx as oe, withDirectives as se, withModifiers as ce } from "vue";
3
+ import n from "../input-dropdown/input-dropdown.js";
4
+ import { useCameraFilter as r } from "../../../composables/useCameraFilter.js";
5
+ import { useOrientationCorrection as i } from "../../../composables/useOrientationCorrection.js";
6
+ import { captureToDataUrl as a, toPhotoPayload as o } from "../../../composables/useCameraCapture.js";
7
+ import s from "../../atoms/zoom-slider/zoom-slider.js";
8
+ import c from "../../../assets/img/guide.js";
9
+ import { computed as l, createBlock as ee, createCommentVNode as u, createElementBlock as d, createElementVNode as f, createVNode as p, defineComponent as te, normalizeClass as m, normalizeStyle as h, onBeforeUnmount as ne, onMounted as re, openBlock as g, ref as _, toDisplayString as v, unref as ie, vShow as ae, watch as y, withCtx as oe, withDirectives as se, withModifiers as ce } from "vue";
9
10
  import le from "lodash";
10
11
  //#region src/components/molecules/base-camera/base-camera.vue?vue&type=script&async=true&setup=true&lang.ts
11
12
  var ue = { class: "camera__preview" }, de = {
@@ -60,7 +61,7 @@ var ue = { class: "camera__preview" }, de = {
60
61
  width: 720,
61
62
  height: 1280
62
63
  }
63
- }, Ae = /*@__PURE__*/ p({
64
+ }, Ae = /*@__PURE__*/ te({
64
65
  ...Oe,
65
66
  props: {
66
67
  modelValue: { type: null },
@@ -82,7 +83,7 @@ var ue = { class: "camera__preview" }, de = {
82
83
  },
83
84
  guideSrc: {
84
85
  type: String,
85
- default: () => o
86
+ default: () => c
86
87
  },
87
88
  countdown: {
88
89
  type: Number,
@@ -139,64 +140,69 @@ var ue = { class: "camera__preview" }, de = {
139
140
  }
140
141
  },
141
142
  emits: ["update:modelValue"],
142
- setup(o, { expose: p, emit: Oe }) {
143
- let { debounce: Ae } = le, v = o, je = Oe, y = g(), b = g(), Me = g(!1), x = g([]), S = g(), C = g(), w = g(), T = g(), E = g(), D = g(!1), O = g(!1), k = g(0), A = g(0), j = g(), M = g(v.zoom || 1), Ne = g(!1), N = g(!1), Pe = g(null), Fe = g(!1), P, F, Ie = typeof window < "u" && "DeviceMotionEvent" in window && (window.matchMedia?.("(pointer: coarse)")?.matches || "ontouchstart" in window), Le = s(() => v.correctOrientation && Ie), I = s(() => Me.value && (!Le.value || Fe.value));
144
- ae(I, (e) => {
145
- e && Z(J);
146
- }, { flush: "post" });
147
- function Re() {
148
- F &&= (window.removeEventListener("pointerdown", F, !0), window.removeEventListener("touchend", F, !0), void 0);
149
- }
143
+ setup(c, { expose: te, emit: Oe }) {
144
+ let { debounce: Ae } = le, b = c, je = Oe, x = _(), S = _(), C = _([]), w = _(), T = _(), E = _(), D = _(), O = _(), k = _(!1), A = _(!1), j = _(0), M = _(0), N = _(), P = _(b.zoom || 1), { orientationReady: Me, orientationFlip: Ne, requiresGate: Pe, enableMotion: Fe, armGate: Ie, getCaptureRotation: Le, dispose: Re } = i(() => b.correctOrientation), F = _(!1), I;
150
145
  function L() {
151
- Fe.value = !0, P &&= (clearTimeout(P), void 0), Re();
152
- }
153
- function ze() {
154
- F || (F = () => {
155
- R();
156
- }, window.addEventListener("pointerdown", F, !0), window.addEventListener("touchend", F, !0));
157
- }
158
- function Be(e) {
159
- let t = e.accelerationIncludingGravity;
160
- if (!t || t.x == null || t.y == null) return;
161
- let n = Math.round(Math.atan2(t.x, t.y) * 180 / Math.PI);
162
- if (Pe.value = n, !(typeof screen < "u" && screen.orientation && screen.orientation.type || "portrait-primary").startsWith("portrait")) N.value = !1;
163
- else {
164
- let e = Math.abs(Math.abs(n) - 90);
165
- !N.value && e < 40 ? N.value = !0 : N.value && e > 50 && (N.value = !1);
166
- }
167
- Fe.value || L();
146
+ I &&= (I(), void 0);
168
147
  }
169
- async function R() {
170
- if (!(!v.correctOrientation || Ne.value)) try {
171
- let e = window.DeviceOrientationEvent, t = window.DeviceMotionEvent;
172
- if (e && typeof e.requestPermission == "function" && await e.requestPermission() !== "granted") {
173
- L();
174
- return;
175
- }
176
- t && typeof t.requestPermission == "function" && await t.requestPermission().catch(() => {}), window.addEventListener("devicemotion", Be, !0), Ne.value = !0, Re();
177
- } catch (e) {
178
- console.error(e, "enableMotion: failed"), L();
148
+ let ze = 0, Be = () => ze;
149
+ function Ve() {
150
+ L(), F.value = !1;
151
+ let e = x.value;
152
+ if (!e) return;
153
+ let t = !1, n, r, i = () => {
154
+ t || (t = !0, L(), F.value = !0, X = null);
155
+ };
156
+ if (typeof e.requestVideoFrameCallback == "function") {
157
+ let t = e.requestVideoFrameCallback(() => i());
158
+ I = () => {
159
+ e.cancelVideoFrameCallback?.(t);
160
+ };
179
161
  }
162
+ n = setInterval(() => {
163
+ e.videoWidth > 0 && i();
164
+ }, 200), r = setTimeout(() => {
165
+ if (r = void 0, t || !x.value) return;
166
+ let e = x.value.srcObject;
167
+ e && (x.value.srcObject = null, setTimeout(() => {
168
+ t || !x.value || (x.value.srcObject = e, x.value.play?.().catch(() => {}), at(Be()));
169
+ }, 100));
170
+ }, 600);
171
+ let a = setTimeout(() => {
172
+ if (t || !x.value) return;
173
+ let e = x.value, n = e.style.display;
174
+ e.style.display = "none", e.offsetHeight, e.style.display = n, x.value.play?.().catch(() => {});
175
+ }, 2500), o = setTimeout(() => {
176
+ t || !x.value || x.value.play?.().catch(() => {});
177
+ }, 1500);
178
+ I = () => {
179
+ n && clearInterval(n), r && clearTimeout(r), a && clearTimeout(a), o && clearTimeout(o);
180
+ };
180
181
  }
181
- let z = s(() => ({
182
+ let R = l(() => F.value && (!Pe.value || Me.value)), z = l(() => ({
182
183
  ...ke,
183
- ...v.resolutions
184
- })), Ve = s(() => Object.values(z.value)[0]);
185
- function He(e) {
184
+ ...b.resolutions
185
+ })), He = l(() => Object.values(z.value)[0]);
186
+ function Ue(e) {
186
187
  return String(e || "").trim().toLowerCase().replace(/\s+/g, "").replace(/[:/]/g, "x");
187
188
  }
188
- let B = s(() => {
189
- if (z.value[v.ratio]) return v.ratio;
190
- let e = He(v.ratio);
189
+ let B = l(() => {
190
+ if (z.value[b.ratio]) return b.ratio;
191
+ let e = Ue(b.ratio);
191
192
  if (z.value[e]) return e;
192
- }), V = s(() => B.value ? z.value[B.value] : Ve.value), Ue = s(() => {
193
+ }), V = l(() => B.value ? z.value[B.value] : He.value), We = l(() => {
193
194
  let e = B.value ? z.value[B.value] : void 0;
194
195
  return e ? `${e.width} / ${e.height}` : void 0;
195
- }), H = s(() => x.value.filter((e) => e.kind === "videoinput")), We = s(() => x.value.filter((e) => e.kind === "audioinput")), U = g([]), W = s(() => H.value.filter((e) => !U.value.includes(e.deviceId)));
196
- function Ge(e) {
196
+ }), H = l(() => C.value.filter((e) => e.kind === "videoinput")), Ge = l(() => C.value.filter((e) => e.kind === "audioinput")), U = _([]), W = l(() => H.value.filter((e) => !U.value.includes(e.deviceId))), Ke = /\b(depth|ir\b|infrared|bayer|virtual|dual|triple|quad)\b/i, qe = l(() => {
197
+ let e = W.value.filter((e) => !e.label || !Ke.test(e.label));
198
+ if (e.length <= 2) return e;
199
+ let t = e.length - 1;
200
+ return e.filter((e, n) => n <= 1 || n === t);
201
+ });
202
+ function Je(e) {
197
203
  e && !U.value.includes(e) && (U.value = [...U.value, e]);
198
204
  }
199
- function Ke(e) {
205
+ function Ye(e) {
200
206
  let t = H.value;
201
207
  if (!t.length) return;
202
208
  let n = t.findIndex((t) => t.deviceId === e);
@@ -205,38 +211,38 @@ var ue = { class: "camera__preview" }, de = {
205
211
  if (r && !U.value.includes(r.deviceId)) return r;
206
212
  }
207
213
  }
208
- let qe = s(() => W.value.map((e, t) => ({
214
+ let Xe = l(() => qe.value.map((e, t) => ({
209
215
  text: e.label.slice(0, e.label.indexOf("(")) || `Camera ${t + 1}`,
210
216
  value: e.deviceId
211
- }))), Je = s({
217
+ }))), Ze = l({
212
218
  get() {
213
- return S.value && S.value.deviceId;
219
+ return w.value && w.value.deviceId;
214
220
  },
215
221
  set(e) {
216
- S.value = H.value.find((t) => t.deviceId === e), w.value = void 0;
222
+ w.value = H.value.find((t) => t.deviceId === e), E.value = void 0;
217
223
  }
218
224
  });
219
- s({
225
+ l({
220
226
  get() {
221
- return C.value && C.value.deviceId;
227
+ return T.value && T.value.deviceId;
222
228
  },
223
229
  set(e) {
224
- C.value = We.value.find((t) => t.deviceId === e);
230
+ T.value = Ge.value.find((t) => t.deviceId === e);
225
231
  }
226
232
  });
227
- let G = s(() => v.enableMirrorCamera ? T.value ? T.value === "user" ? "mirror-cam" : "" : w.value ? w.value === "user" ? "mirror-cam" : "" : (S.value && H.value.findIndex((e) => e.deviceId === S.value?.deviceId)) === 0 ? "mirror-cam" : "" : ""), Ye = s(() => {
228
- let e = S.value && x.value.findIndex((e) => e.deviceId === S.value?.deviceId);
233
+ let G = l(() => b.enableMirrorCamera ? D.value ? D.value === "user" ? "mirror-cam" : "" : E.value ? E.value === "user" ? "mirror-cam" : "" : (w.value && H.value.findIndex((e) => e.deviceId === w.value?.deviceId)) === 0 ? "mirror-cam" : "" : ""), Qe = l(() => {
234
+ let e = w.value && C.value.findIndex((e) => e.deviceId === w.value?.deviceId);
229
235
  return G.value ? `${G.value} mirror-device-${e}` : "";
230
- }), { tintRgb: Xe, applyFilterToCanvas: Ze } = i(v);
231
- function Qe() {
236
+ }), { tintRgb: $e, applyFilterToCanvas: et } = r(b);
237
+ function tt() {
232
238
  if (B.value && V.value) {
233
- k.value = V.value.width, A.value = V.value.height;
239
+ j.value = V.value.width, M.value = V.value.height;
234
240
  return;
235
241
  }
236
- k.value = y.value.parentElement && y.value.parentElement.clientWidth, A.value = y.value.parentElement && y.value.parentElement.clientHeight;
242
+ j.value = x.value.parentElement && x.value.parentElement.clientWidth, M.value = x.value.parentElement && x.value.parentElement.clientHeight;
237
243
  }
238
- let $e = Ae(() => {
239
- Qe();
244
+ let nt = Ae(() => {
245
+ tt();
240
246
  }, 300, {
241
247
  trailing: !0,
242
248
  leading: !1
@@ -244,11 +250,11 @@ var ue = { class: "camera__preview" }, de = {
244
250
  function K(e) {
245
251
  return new Promise((t) => setTimeout(t, e));
246
252
  }
247
- async function et() {
253
+ async function rt() {
248
254
  let e = V.value ? {
249
255
  width: V.value.width,
250
256
  height: V.value.height
251
- } : void 0, t = e ? Math.max(e.width, e.height) : void 0, n = e ? Math.min(e.width, e.height) : void 0, r = v.enableAudio && { ...C.value ? { deviceId: C.value.deviceId } : {} }, i = S.value && S.value.deviceId, a = w.value, o = [];
257
+ } : void 0, t = e ? Math.max(e.width, e.height) : void 0, n = e ? Math.min(e.width, e.height) : void 0, r = b.enableAudio && { ...T.value ? { deviceId: T.value.deviceId } : {} }, i = w.value && w.value.deviceId, a = E.value, o = [];
252
258
  i ? (t && n && o.push({
253
259
  deviceId: { exact: i },
254
260
  width: { ideal: t },
@@ -264,272 +270,227 @@ var ue = { class: "camera__preview" }, de = {
264
270
  width: { ideal: t },
265
271
  height: { ideal: n }
266
272
  }), o.push({}));
267
- for (let e of o) for (let t = 0; t < 5; t++) try {
268
- return await navigator.mediaDevices.getUserMedia({
269
- audio: r,
270
- video: e
271
- });
272
- } catch (e) {
273
- let t = e && e.name;
274
- if (t === "NotReadableError" || t === "AbortError") {
275
- await K(500);
276
- continue;
273
+ let s;
274
+ for (let e of o) {
275
+ let t = !!e.deviceId?.exact, n = t ? 2 : 5;
276
+ for (let i = 0; i < n; i++) try {
277
+ return await navigator.mediaDevices.getUserMedia({
278
+ audio: r,
279
+ video: e
280
+ });
281
+ } catch (e) {
282
+ s = e;
283
+ let n = e && e.name;
284
+ if (n === "NotReadableError" || n === "AbortError") {
285
+ await K(t ? 250 : 500);
286
+ continue;
287
+ }
288
+ break;
289
+ }
290
+ if (t && s?.name === "NotReadableError") {
291
+ let t = e.deviceId?.exact;
292
+ t && Je(t);
277
293
  }
278
- break;
279
294
  }
295
+ throw s;
280
296
  }
281
297
  function q() {
282
- y.value && y.value.srcObject && (y.value.srcObject.getTracks().forEach((e) => {
298
+ L(), F.value = !1, x.value && x.value.srcObject && (x.value.srcObject.getTracks().forEach((e) => {
283
299
  e.stop();
284
- }), y.value.srcObject = null);
300
+ }), x.value.srcObject = null);
285
301
  }
286
- let J = 0, Y, tt;
287
- function X() {
288
- Y &&= (clearTimeout(Y), void 0), tt &&= (tt(), void 0);
302
+ let J = 0, Y, X = null;
303
+ function Z() {
304
+ Y &&= (clearTimeout(Y), void 0);
289
305
  }
290
- function nt(e) {
291
- Ge(e);
292
- let t = Ke(e);
293
- t && t.deviceId !== e && (S.value = t);
306
+ function it(e) {
307
+ Je(e);
308
+ let t = Ye(e);
309
+ t && t.deviceId !== e && (w.value = t);
294
310
  }
295
- function rt(e) {
296
- X();
297
- let t = S.value && S.value.deviceId, n = y.value;
298
- if (!t || !n) return;
299
- let r = n.srcObject && n.srcObject.getVideoTracks?.()[0];
300
- if (!r || typeof r.addEventListener != "function" || n.videoWidth > 0) return;
301
- let i = () => {
302
- if (X(), e !== J || !y.value) return;
303
- let n = Ke(t);
304
- n && n.deviceId !== t && (q(), nt(t));
305
- }, a = () => {
306
- e === J && y.value && y.value.videoWidth > 0 && X();
307
- }, o = () => {
308
- i();
309
- };
310
- r.addEventListener("unmute", a), r.addEventListener("ended", o), tt = () => {
311
- r.removeEventListener("unmute", a), r.removeEventListener("ended", o);
312
- }, Y = setTimeout(() => {
313
- Y = void 0, !(e !== J || !y.value) && (y.value.videoWidth === 0 ? i() : X());
314
- }, 8e3);
315
- }
316
- let it = 0;
317
- async function Z(e) {
318
- for (let t = 0; t < 3; t++) {
319
- if (e !== J || !y.value) return;
320
- try {
321
- await y.value.play?.();
311
+ function at(e) {
312
+ if (Z(), !(w.value && w.value.deviceId)) return;
313
+ let t = y(F, (e) => {
314
+ e && Z();
315
+ });
316
+ Y = setTimeout(async () => {
317
+ if (t(), Y = void 0, e !== J || !x.value || x.value.videoWidth > 0) return;
318
+ let n = w.value && w.value.deviceId;
319
+ if (!n) return;
320
+ if (X !== n) {
321
+ X = n, await Q();
322
322
  return;
323
- } catch {
324
- t < 2 && await K(300);
325
323
  }
326
- }
327
- }
328
- function at() {
329
- return !!(y.value && y.value.videoWidth > 0);
330
- }
331
- function Q(e, t) {
332
- return new Promise((n) => {
333
- let r = Date.now(), i = () => {
334
- if (e !== J || !y.value) return n(!1);
335
- if (at()) return n(!0);
336
- if (Date.now() - r >= t) return n(!1);
337
- setTimeout(i, 100);
338
- };
339
- i();
340
- });
341
- }
342
- async function ot(e) {
343
- if (typeof (y.value?.srcObject)?.getVideoTracks?.()[0]?.addEventListener != "function" || await Q(e, 800) || e !== J || !y.value || (await Z(e), await Q(e, 800)) || e !== J || !y.value) return;
344
- let t = y.value, n = t.style.display;
345
- if (t.style.display = "none", t.offsetHeight, t.style.display = n, await Z(e), await Q(e, 800) || e !== J || !y.value) return;
346
- let r = y.value.srcObject;
347
- r && (y.value.srcObject = null, await ee(), e !== J || !y.value || (y.value.srcObject = r, await Z(e), await Q(e, 800))) || e === J && await $();
324
+ let r = Ye(n);
325
+ r && r.deviceId !== n && (q(), it(n));
326
+ }, 5e3);
348
327
  }
349
- function st() {
350
- document.visibilityState !== "visible" || !D.value || !y.value || (y.value.paused || y.value.videoWidth === 0) && Z(J);
351
- }
352
- async function $() {
328
+ async function Q() {
353
329
  let e = ++J;
354
- X();
355
- let t = !!(y.value && y.value.srcObject);
356
- if (q(), E.value = void 0, t && (await K(350), e !== J)) return;
357
- let n = await et();
330
+ ze = e, Z();
331
+ let t = !!(x.value && x.value.srcObject);
332
+ if (q(), O.value = void 0, t && (await K(350), e !== J)) return;
333
+ let n;
334
+ try {
335
+ n = await rt();
336
+ } catch {
337
+ n = void 0;
338
+ }
358
339
  if (e !== J) {
359
340
  n?.getTracks?.().forEach((e) => e.stop());
360
341
  return;
361
342
  }
362
- if (n && y.value) {
363
- it = 0, y.value.srcObject = n;
343
+ if (n && x.value) {
344
+ Ve(), x.value.srcObject = n;
364
345
  let t = n.getVideoTracks?.()[0]?.getSettings?.();
365
- T.value = t?.facingMode, E.value = t?.deviceId, y.value.muted = !0, await Z(e), rt(e), ot(e);
366
- } else if (!n && S.value) {
367
- it < 2 && (it++, await K(600), e === J && await $());
346
+ D.value = t?.facingMode, O.value = t?.deviceId, x.value.muted = !0;
347
+ try {
348
+ await x.value.play?.();
349
+ } catch {
350
+ await K(300), await x.value.play?.().catch(() => {});
351
+ }
352
+ at(e);
353
+ } else if (!n && w.value) {
354
+ q(), it(w.value.deviceId), e === J && w.value && await Q();
368
355
  return;
369
356
  }
370
- return x.value = await navigator.mediaDevices.enumerateDevices(), {
371
- stream: y.value && y.value.srcObject,
372
- devices: x.value
357
+ return C.value = await navigator.mediaDevices.enumerateDevices(), {
358
+ stream: x.value && x.value.srcObject,
359
+ devices: C.value
373
360
  };
374
361
  }
375
- function ct() {
376
- D.value ? (D.value = !1, O.value = !1, q()) : (D.value = !0, $());
377
- }
378
- function lt() {
379
- S.value = void 0, w.value = w.value === "user" ? "environment" : "user", $();
362
+ function ot() {
363
+ document.visibilityState !== "visible" || !k.value || !x.value || x.value.paused && x.value.play?.().catch(() => {});
380
364
  }
381
- async function ut(e, t) {
382
- e && e.deviceId === E.value || e && (!t || e.deviceId !== t.deviceId) && await $();
365
+ function st() {
366
+ k.value ? (k.value = !1, A.value = !1, q()) : (k.value = !0, Q());
383
367
  }
384
- ae(() => S.value, ut), ae(() => C.value, ut);
385
- function dt() {
386
- v.countdown ? (j.value = j.value ? j.value - 1 : v.countdown, j.value ? setTimeout(dt, 1e3) : mt()) : mt();
368
+ function ct() {
369
+ let e = W.value;
370
+ if (e.length > 1) {
371
+ let t = O.value || w.value && w.value.deviceId, n = e[e.findIndex((e) => e.deviceId === t) <= 0 ? e.length - 1 : 0];
372
+ if (n && n.deviceId !== t) {
373
+ w.value = n, E.value = void 0;
374
+ return;
375
+ }
376
+ }
377
+ w.value = void 0, E.value = E.value === "user" ? "environment" : "user", Q();
387
378
  }
388
- p({
389
- onCapture: dt,
390
- enableMotion: R,
391
- camera: y.value,
392
- zoom: M
393
- });
394
- function ft() {
395
- if (!v.correctOrientation || Pe.value == null) return 0;
396
- let e = ((Pe.value - 180) % 360 + 360) % 360;
397
- return (-1 * (Math.round(e / 90) * 90 % 360) % 360 + 360) % 360;
379
+ async function lt(e, t) {
380
+ e && e.deviceId === O.value || e && (!t || e.deviceId !== t.deviceId) && await Q();
398
381
  }
399
- function pt(e, t, n, r, i) {
400
- let a = b.value.width, o = b.value.height;
401
- e.translate(a / 2, o / 2), G.value && e.scale(-1, 1), e.rotate(n * Math.PI / 180);
402
- let s = o, c = a, l = Math.max(s / r, c / i) * (M.value && M.value > 0 ? M.value : 1), u = r * l, d = i * l;
403
- e.drawImage(t, -u / 2, -d / 2, u, d);
382
+ y(() => w.value, lt), y(() => T.value, lt);
383
+ function $() {
384
+ b.countdown ? (N.value = N.value ? N.value - 1 : b.countdown, N.value ? setTimeout($, 1e3) : ut()) : ut();
404
385
  }
405
- function mt() {
406
- O.value = !0;
407
- let e = b.value.getContext("2d"), t = y.value, n = t && t.srcObject && t.srcObject.getTracks(), { aspectRatio: r, width: i, height: a } = n.length && n[0].getSettings(), o = t?.videoWidth || i || k.value, s = t?.videoHeight || a || A.value, c = o && s ? o / s : r, l = V.value || {
408
- width: o,
409
- height: s
410
- }, u = l?.width || o, d = B.value ? l?.height || s : Math.round(u / c), f = u / d;
411
- if (b.value.width = u, b.value.height = d, !o || !s || !c) return;
412
- let p = ft();
413
- if (e.save(), p === 90 || p === 270) {
414
- pt(e, t, p, o, s), e.restore(), Ze(e, b.value.width, b.value.height), ht(b.value.toDataURL("image/png"));
415
- return;
416
- }
417
- if (p === 180 && (e.translate(b.value.width, b.value.height), e.scale(-1, -1)), G.value && (e.translate(b.value.width, 0), e.scale(-1, 1)), v.enableCropImage) {
418
- let n = 0, r = 0, i = o, a = s;
419
- if (c > f ? (i = s * f, n = (o - i) / 2) : c < f && (a = o / f, r = (s - a) / 2), M.value && M.value !== 1) {
420
- let e = i / M.value, t = a / M.value;
421
- n += (i - e) / 2, r += (a - t) / 2, i = e, a = t;
422
- }
423
- e.drawImage(t, n, r, i, a, 0, 0, b.value.width, b.value.height);
424
- } else {
425
- let n = b.value.width, r = b.value.height, i = 0, a = 0;
426
- if (c > f ? (r = b.value.width / c, a = (b.value.height - r) / 2) : c < f && (n = b.value.height * c, i = (b.value.width - n) / 2), M.value && M.value !== 1) {
427
- let c = o / M.value, l = s / M.value, u = (o - c) / 2, d = (s - l) / 2;
428
- G.value && (i = b.value.width - i - n), e.drawImage(t, u, d, c, l, i, a, n, r);
429
- } else G.value && (i = b.value.width - i - n), e.drawImage(t, 0, 0, o, s, i, a, n, r);
430
- }
431
- e.restore(), Ze(e, b.value.width, b.value.height), ht(b.value.toDataURL("image/png"));
386
+ te({
387
+ onCapture: $,
388
+ enableMotion: Fe,
389
+ camera: x.value,
390
+ zoom: P
391
+ });
392
+ function ut() {
393
+ A.value = !0;
394
+ let e = x.value;
395
+ !S.value || !e || dt(a(S.value, e, {
396
+ targetResolution: V.value || void 0,
397
+ hasExplicitRatio: !!B.value,
398
+ enableCropImage: b.enableCropImage,
399
+ zoom: P.value,
400
+ mirror: !!G.value,
401
+ captureRotation: Le(),
402
+ onSave: dt
403
+ }, et));
432
404
  }
433
- function ht(e) {
434
- let t = n(e);
435
- je("update:modelValue", {
436
- name: `cam-pic-${(/* @__PURE__ */ new Date()).toISOString()}`,
437
- id: `cam-pic-${(/* @__PURE__ */ new Date()).toISOString()}`,
438
- blob: t,
439
- size: t.size
440
- });
405
+ function dt(e) {
406
+ je("update:modelValue", o(e));
441
407
  }
442
408
  return re(async () => {
443
- w.value = v.defaultRearCamera ? "environment" : "user", await $(), D.value = !0;
444
- let e = H.value.find((e) => e.deviceId === E.value), t = v.defaultRearCamera && H.value.length > 1 ? H.value[H.value.length - 1] : e || H.value[0];
445
- if (S.value = t, v.enableAudio && (C.value = We.value[0]), navigator.mediaDevices.addEventListener("devicechange", async (e) => {
446
- await $();
447
- }), document.addEventListener("visibilitychange", st), window.addEventListener("resize", $e), Qe(), Le.value) {
448
- P = setTimeout(L, 3e3);
449
- let e = window.DeviceOrientationEvent;
450
- e && typeof e.requestPermission == "function" ? ze() : R();
451
- }
452
- await ee(), Me.value = !0;
409
+ E.value = b.defaultRearCamera ? "environment" : "user", await Q(), k.value = !0;
410
+ let e = H.value.find((e) => e.deviceId === O.value), t = b.defaultRearCamera && H.value.length > 1 ? H.value[H.value.length - 1] : e || H.value[0];
411
+ w.value = t, b.enableAudio && (T.value = Ge.value[0]), navigator.mediaDevices.addEventListener("devicechange", async (e) => {
412
+ await Q();
413
+ }), document.addEventListener("visibilitychange", ot), window.addEventListener("resize", nt), tt(), Ie();
453
414
  }), ne(() => {
454
- D.value = !1, O.value = !1, X(), q(), window.removeEventListener("resize", $e), window.removeEventListener("devicemotion", Be, !0), document.removeEventListener("visibilitychange", st), P && clearTimeout(P), Re();
455
- }), (n, i) => (h(), u("div", { class: m(["camera", Ye.value]) }, [
456
- d("div", ue, [
457
- I.value ? l("", !0) : (h(), u("div", de, [f(t, { color: "#000" }, {
458
- default: oe(() => [d("span", {
415
+ k.value = !1, A.value = !1, Z(), L(), q(), window.removeEventListener("resize", nt), document.removeEventListener("visibilitychange", ot), Re();
416
+ }), (r, i) => (g(), d("div", { class: m(["camera", Qe.value]) }, [
417
+ f("div", ue, [
418
+ R.value ? u("", !0) : (g(), d("div", de, [p(t, { color: "#000" }, {
419
+ default: oe(() => [f("span", {
459
420
  class: m("d-block text-center"),
460
- innerHTML: n.$t("camera.waitForCameraNotification")
421
+ innerHTML: r.$t("camera.waitForCameraNotification")
461
422
  }, null, 8, fe)]),
462
423
  _: 1
463
424
  })])),
464
- se(d("div", {
425
+ f("div", {
465
426
  class: m(["camera__video-wrapper", B.value ? `aspect-ratio--${B.value}` : ""]),
466
- style: te({
467
- aspectRatio: Ue.value || void 0,
468
- transform: M.value === 1 ? void 0 : `scale(${M.value})`
427
+ style: h({
428
+ aspectRatio: We.value || void 0,
429
+ transform: P.value === 1 ? void 0 : `scale(${P.value})`
469
430
  })
470
- }, [d("video", {
431
+ }, [f("video", {
471
432
  ref_key: "camera",
472
- ref: y,
433
+ ref: x,
473
434
  class: "camera__video",
474
- style: te({
475
- filter: v.filter === "grayscale" ? "grayscale(100%)" : v.filter === "sepia" ? "sepia(100%)" : "none",
476
- transform: o.correctOrientation && N.value ? "rotate(180deg)" : void 0
435
+ style: h({
436
+ filter: b.filter === "grayscale" ? "grayscale(100%)" : b.filter === "sepia" ? "sepia(100%)" : "none",
437
+ transform: c.correctOrientation && ie(Ne) ? "rotate(180deg)" : void 0
477
438
  }),
478
439
  autoplay: "",
479
440
  muted: "",
480
441
  playsinline: ""
481
- }, null, 4), o.tintColor ? (h(), u("div", {
442
+ }, null, 4), c.tintColor ? (g(), d("div", {
482
443
  key: 0,
483
444
  class: "camera__tint-overlay",
484
- style: te({
485
- backgroundColor: o.tintColor,
486
- opacity: o.tintIntensity,
445
+ style: h({
446
+ backgroundColor: c.tintColor,
447
+ opacity: c.tintIntensity,
487
448
  mixBlendMode: "multiply"
488
449
  })
489
- }, null, 4)) : l("", !0)], 6), [[ie, I.value]]),
490
- se(d("canvas", {
450
+ }, null, 4)) : u("", !0)], 6),
451
+ se(f("canvas", {
491
452
  ref_key: "canvas",
492
- ref: b,
453
+ ref: S,
493
454
  class: "camera__canvas",
494
- width: k.value,
495
- height: A.value
496
- }, null, 8, pe), [[ie, O.value]]),
497
- j.value ? (h(), u("div", me, [(h(), u("p", {
455
+ width: j.value,
456
+ height: M.value
457
+ }, null, 8, pe), [[ae, A.value]]),
458
+ N.value ? (g(), d("div", me, [(g(), d("p", {
498
459
  class: "countdown",
499
- key: j.value,
500
- innerHTML: j.value,
501
- "data-countdown": j.value
502
- }, null, 8, he))])) : l("", !0),
503
- o.enableGuide && D.value && I.value ? (h(), u("img", {
460
+ key: N.value,
461
+ innerHTML: N.value,
462
+ "data-countdown": N.value
463
+ }, null, 8, he))])) : u("", !0),
464
+ c.enableGuide && k.value && R.value ? (g(), d("img", {
504
465
  key: 2,
505
466
  class: "camera__guide",
506
- src: o.guideSrc
507
- }, null, 8, ge)) : l("", !0),
508
- o.enableZoomSlider ? (h(), u("div", _e, [f(a, {
509
- modelValue: M.value,
510
- "onUpdate:modelValue": i[0] ||= (e) => M.value = e
511
- }, null, 8, ["modelValue"])])) : l("", !0)
467
+ src: c.guideSrc
468
+ }, null, 8, ge)) : u("", !0),
469
+ c.enableZoomSlider ? (g(), d("div", _e, [p(s, {
470
+ modelValue: P.value,
471
+ "onUpdate:modelValue": i[0] ||= (e) => P.value = e
472
+ }, null, 8, ["modelValue"])])) : u("", !0)
512
473
  ]),
513
- d("div", ve, [d("div", ye, [d("div", be, [d("div", xe, [d("div", Se, [d("button", {
474
+ f("div", ve, [f("div", ye, [f("div", be, [f("div", xe, [f("div", Se, [f("button", {
514
475
  type: "button",
515
476
  class: "camera__toggle btn btn-primary",
516
- onClick: ct
517
- }, [D.value ? (h(), u("span", we, _(n.$t("common.pause")), 1)) : (h(), u("span", Ce, _(n.$t("common.play")), 1))]), d("button", {
477
+ onClick: st
478
+ }, [k.value ? (g(), d("span", we, v(r.$t("common.pause")), 1)) : (g(), d("span", Ce, v(r.$t("common.play")), 1))]), f("button", {
518
479
  type: "button",
519
480
  class: "camera__capture btn btn-primary",
520
- onClick: dt
521
- }, _(n.$t("camera.capture")), 1)])])])])]),
522
- (o.enableSwitchCamera || o.enableSelectDevice) && W.value && W.value.length > 1 ? (h(), u("div", Te, [d("div", Ee, [o.enableSelectDevice ? (h(), c(r, {
481
+ onClick: $
482
+ }, v(r.$t("camera.capture")), 1)])])])])]),
483
+ (c.enableSwitchCamera || c.enableSelectDevice) && W.value && W.value.length > 1 ? (g(), d("div", Te, [f("div", Ee, [c.enableSelectDevice ? (g(), ee(n, {
523
484
  key: 0,
524
- modelValue: Je.value,
525
- "onUpdate:modelValue": i[1] ||= (e) => Je.value = e,
526
- options: qe.value,
485
+ modelValue: Ze.value,
486
+ "onUpdate:modelValue": i[1] ||= (e) => Ze.value = e,
487
+ options: Xe.value,
527
488
  class: "w-100"
528
- }, null, 8, ["modelValue", "options"])) : l("", !0)]), d("div", De, [o.enableSwitchCamera ? (h(), u("button", {
489
+ }, null, 8, ["modelValue", "options"])) : u("", !0)]), f("div", De, [c.enableSwitchCamera ? (g(), d("button", {
529
490
  key: 0,
530
491
  class: "btn",
531
- onClick: ce(lt, ["prevent"])
532
- }, [f(e, { symbol: "switch-camera" })])) : l("", !0)])])) : l("", !0)
492
+ onClick: ce(ct, ["prevent"])
493
+ }, [p(e, { symbol: "switch-camera" })])) : u("", !0)])])) : u("", !0)
533
494
  ], 2));
534
495
  }
535
496
  });