ablok-components 0.3.127 → 0.3.128

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,12 +1,11 @@
1
1
  import e from "../../atoms/svg-icon/svg-icon.js";
2
2
  import t from "../../atoms/loading-spinner/loading-spinner.js";
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";
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";
10
9
  import le from "lodash";
11
10
  //#region src/components/molecules/base-camera/base-camera.vue?vue&type=script&async=true&setup=true&lang.ts
12
11
  var ue = { class: "camera__preview" }, de = {
@@ -61,7 +60,7 @@ var ue = { class: "camera__preview" }, de = {
61
60
  width: 720,
62
61
  height: 1280
63
62
  }
64
- }, Ae = /*@__PURE__*/ te({
63
+ }, Ae = /*@__PURE__*/ p({
65
64
  ...Oe,
66
65
  props: {
67
66
  modelValue: { type: null },
@@ -83,7 +82,7 @@ var ue = { class: "camera__preview" }, de = {
83
82
  },
84
83
  guideSrc: {
85
84
  type: String,
86
- default: () => c
85
+ default: () => o
87
86
  },
88
87
  countdown: {
89
88
  type: Number,
@@ -140,69 +139,64 @@ var ue = { class: "camera__preview" }, de = {
140
139
  }
141
140
  },
142
141
  emits: ["update:modelValue"],
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;
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
+ }
145
150
  function L() {
146
- I &&= (I(), void 0);
151
+ Fe.value = !0, P &&= (clearTimeout(P), void 0), Re();
147
152
  }
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
- };
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);
161
166
  }
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
- };
167
+ Fe.value || L();
181
168
  }
182
- let R = l(() => F.value && (!Pe.value || Me.value)), z = l(() => ({
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();
179
+ }
180
+ }
181
+ let z = s(() => ({
183
182
  ...ke,
184
- ...b.resolutions
185
- })), He = l(() => Object.values(z.value)[0]);
186
- function Ue(e) {
183
+ ...v.resolutions
184
+ })), Ve = s(() => Object.values(z.value)[0]);
185
+ function He(e) {
187
186
  return String(e || "").trim().toLowerCase().replace(/\s+/g, "").replace(/[:/]/g, "x");
188
187
  }
189
- let B = l(() => {
190
- if (z.value[b.ratio]) return b.ratio;
191
- let e = Ue(b.ratio);
188
+ let B = s(() => {
189
+ if (z.value[v.ratio]) return v.ratio;
190
+ let e = He(v.ratio);
192
191
  if (z.value[e]) return e;
193
- }), V = l(() => B.value ? z.value[B.value] : He.value), We = l(() => {
192
+ }), V = s(() => B.value ? z.value[B.value] : Ve.value), Ue = s(() => {
194
193
  let e = B.value ? z.value[B.value] : void 0;
195
194
  return e ? `${e.width} / ${e.height}` : void 0;
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) {
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) {
203
197
  e && !U.value.includes(e) && (U.value = [...U.value, e]);
204
198
  }
205
- function Ye(e) {
199
+ function Ke(e) {
206
200
  let t = H.value;
207
201
  if (!t.length) return;
208
202
  let n = t.findIndex((t) => t.deviceId === e);
@@ -211,38 +205,38 @@ var ue = { class: "camera__preview" }, de = {
211
205
  if (r && !U.value.includes(r.deviceId)) return r;
212
206
  }
213
207
  }
214
- let Xe = l(() => qe.value.map((e, t) => ({
208
+ let qe = s(() => W.value.map((e, t) => ({
215
209
  text: e.label.slice(0, e.label.indexOf("(")) || `Camera ${t + 1}`,
216
210
  value: e.deviceId
217
- }))), Ze = l({
211
+ }))), Je = s({
218
212
  get() {
219
- return w.value && w.value.deviceId;
213
+ return S.value && S.value.deviceId;
220
214
  },
221
215
  set(e) {
222
- w.value = H.value.find((t) => t.deviceId === e), E.value = void 0;
216
+ S.value = H.value.find((t) => t.deviceId === e), w.value = void 0;
223
217
  }
224
218
  });
225
- l({
219
+ s({
226
220
  get() {
227
- return T.value && T.value.deviceId;
221
+ return C.value && C.value.deviceId;
228
222
  },
229
223
  set(e) {
230
- T.value = Ge.value.find((t) => t.deviceId === e);
224
+ C.value = We.value.find((t) => t.deviceId === e);
231
225
  }
232
226
  });
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);
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);
235
229
  return G.value ? `${G.value} mirror-device-${e}` : "";
236
- }), { tintRgb: $e, applyFilterToCanvas: et } = r(b);
237
- function tt() {
230
+ }), { tintRgb: Xe, applyFilterToCanvas: Ze } = i(v);
231
+ function Qe() {
238
232
  if (B.value && V.value) {
239
- j.value = V.value.width, M.value = V.value.height;
233
+ k.value = V.value.width, A.value = V.value.height;
240
234
  return;
241
235
  }
242
- j.value = x.value.parentElement && x.value.parentElement.clientWidth, M.value = x.value.parentElement && x.value.parentElement.clientHeight;
236
+ k.value = y.value.parentElement && y.value.parentElement.clientWidth, A.value = y.value.parentElement && y.value.parentElement.clientHeight;
243
237
  }
244
- let nt = Ae(() => {
245
- tt();
238
+ let $e = Ae(() => {
239
+ Qe();
246
240
  }, 300, {
247
241
  trailing: !0,
248
242
  leading: !1
@@ -250,11 +244,11 @@ var ue = { class: "camera__preview" }, de = {
250
244
  function K(e) {
251
245
  return new Promise((t) => setTimeout(t, e));
252
246
  }
253
- async function rt() {
247
+ async function et() {
254
248
  let e = V.value ? {
255
249
  width: V.value.width,
256
250
  height: V.value.height
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 = [];
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 = [];
258
252
  i ? (t && n && o.push({
259
253
  deviceId: { exact: i },
260
254
  width: { ideal: t },
@@ -270,227 +264,272 @@ var ue = { class: "camera__preview" }, de = {
270
264
  width: { ideal: t },
271
265
  height: { ideal: n }
272
266
  }), o.push({}));
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);
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;
293
277
  }
278
+ break;
294
279
  }
295
- throw s;
296
280
  }
297
281
  function q() {
298
- L(), F.value = !1, x.value && x.value.srcObject && (x.value.srcObject.getTracks().forEach((e) => {
282
+ y.value && y.value.srcObject && (y.value.srcObject.getTracks().forEach((e) => {
299
283
  e.stop();
300
- }), x.value.srcObject = null);
284
+ }), y.value.srcObject = null);
301
285
  }
302
- let J = 0, Y, X = null;
303
- function Z() {
304
- Y &&= (clearTimeout(Y), void 0);
286
+ let J = 0, Y, tt;
287
+ function X() {
288
+ Y &&= (clearTimeout(Y), void 0), tt &&= (tt(), void 0);
305
289
  }
306
- function it(e) {
307
- Je(e);
308
- let t = Ye(e);
309
- t && t.deviceId !== e && (w.value = t);
290
+ function nt(e) {
291
+ Ge(e);
292
+ let t = Ke(e);
293
+ t && t.deviceId !== e && (S.value = t);
310
294
  }
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();
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?.();
322
322
  return;
323
+ } catch {
324
+ t < 2 && await K(300);
323
325
  }
324
- let r = Ye(n);
325
- r && r.deviceId !== n && (q(), it(n));
326
- }, 5e3);
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 $();
327
348
  }
328
- async function Q() {
349
+ function st() {
350
+ document.visibilityState !== "visible" || !D.value || !y.value || (y.value.paused || y.value.videoWidth === 0) && Z(J);
351
+ }
352
+ async function $() {
329
353
  let e = ++J;
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
- }
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();
339
358
  if (e !== J) {
340
359
  n?.getTracks?.().forEach((e) => e.stop());
341
360
  return;
342
361
  }
343
- if (n && x.value) {
344
- Ve(), x.value.srcObject = n;
362
+ if (n && y.value) {
363
+ it = 0, y.value.srcObject = n;
345
364
  let t = n.getVideoTracks?.()[0]?.getSettings?.();
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();
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 $());
355
368
  return;
356
369
  }
357
- return C.value = await navigator.mediaDevices.enumerateDevices(), {
358
- stream: x.value && x.value.srcObject,
359
- devices: C.value
370
+ return x.value = await navigator.mediaDevices.enumerateDevices(), {
371
+ stream: y.value && y.value.srcObject,
372
+ devices: x.value
360
373
  };
361
374
  }
362
- function ot() {
363
- document.visibilityState !== "visible" || !k.value || !x.value || x.value.paused && x.value.play?.().catch(() => {});
364
- }
365
- function st() {
366
- k.value ? (k.value = !1, A.value = !1, q()) : (k.value = !0, Q());
367
- }
368
375
  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();
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", $();
378
380
  }
379
- async function lt(e, t) {
380
- e && e.deviceId === O.value || e && (!t || e.deviceId !== t.deviceId) && await Q();
381
+ async function ut(e, t) {
382
+ e && e.deviceId === E.value || e && (!t || e.deviceId !== t.deviceId) && await $();
381
383
  }
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();
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();
385
387
  }
386
- te({
387
- onCapture: $,
388
- enableMotion: Fe,
389
- camera: x.value,
390
- zoom: P
388
+ p({
389
+ onCapture: dt,
390
+ enableMotion: R,
391
+ camera: y.value,
392
+ zoom: M
391
393
  });
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));
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;
398
+ }
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);
404
+ }
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"));
404
432
  }
405
- function dt(e) {
406
- je("update:modelValue", o(e));
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
+ });
407
441
  }
408
442
  return re(async () => {
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();
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;
414
453
  }), ne(() => {
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", {
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", {
420
459
  class: m("d-block text-center"),
421
- innerHTML: r.$t("camera.waitForCameraNotification")
460
+ innerHTML: n.$t("camera.waitForCameraNotification")
422
461
  }, null, 8, fe)]),
423
462
  _: 1
424
463
  })])),
425
- f("div", {
464
+ se(d("div", {
426
465
  class: m(["camera__video-wrapper", B.value ? `aspect-ratio--${B.value}` : ""]),
427
- style: h({
428
- aspectRatio: We.value || void 0,
429
- transform: P.value === 1 ? void 0 : `scale(${P.value})`
466
+ style: te({
467
+ aspectRatio: Ue.value || void 0,
468
+ transform: M.value === 1 ? void 0 : `scale(${M.value})`
430
469
  })
431
- }, [f("video", {
470
+ }, [d("video", {
432
471
  ref_key: "camera",
433
- ref: x,
472
+ ref: y,
434
473
  class: "camera__video",
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
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
438
477
  }),
439
478
  autoplay: "",
440
479
  muted: "",
441
480
  playsinline: ""
442
- }, null, 4), c.tintColor ? (g(), d("div", {
481
+ }, null, 4), o.tintColor ? (h(), u("div", {
443
482
  key: 0,
444
483
  class: "camera__tint-overlay",
445
- style: h({
446
- backgroundColor: c.tintColor,
447
- opacity: c.tintIntensity,
484
+ style: te({
485
+ backgroundColor: o.tintColor,
486
+ opacity: o.tintIntensity,
448
487
  mixBlendMode: "multiply"
449
488
  })
450
- }, null, 4)) : u("", !0)], 6),
451
- se(f("canvas", {
489
+ }, null, 4)) : l("", !0)], 6), [[ie, I.value]]),
490
+ se(d("canvas", {
452
491
  ref_key: "canvas",
453
- ref: S,
492
+ ref: b,
454
493
  class: "camera__canvas",
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", {
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", {
459
498
  class: "countdown",
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", {
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", {
465
504
  key: 2,
466
505
  class: "camera__guide",
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)
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)
473
512
  ]),
474
- f("div", ve, [f("div", ye, [f("div", be, [f("div", xe, [f("div", Se, [f("button", {
513
+ d("div", ve, [d("div", ye, [d("div", be, [d("div", xe, [d("div", Se, [d("button", {
475
514
  type: "button",
476
515
  class: "camera__toggle btn btn-primary",
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", {
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", {
479
518
  type: "button",
480
519
  class: "camera__capture btn btn-primary",
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, {
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, {
484
523
  key: 0,
485
- modelValue: Ze.value,
486
- "onUpdate:modelValue": i[1] ||= (e) => Ze.value = e,
487
- options: Xe.value,
524
+ modelValue: Je.value,
525
+ "onUpdate:modelValue": i[1] ||= (e) => Je.value = e,
526
+ options: qe.value,
488
527
  class: "w-100"
489
- }, null, 8, ["modelValue", "options"])) : u("", !0)]), f("div", De, [c.enableSwitchCamera ? (g(), d("button", {
528
+ }, null, 8, ["modelValue", "options"])) : l("", !0)]), d("div", De, [o.enableSwitchCamera ? (h(), u("button", {
490
529
  key: 0,
491
530
  class: "btn",
492
- onClick: ce(ct, ["prevent"])
493
- }, [p(e, { symbol: "switch-camera" })])) : u("", !0)])])) : u("", !0)
531
+ onClick: ce(lt, ["prevent"])
532
+ }, [f(e, { symbol: "switch-camera" })])) : l("", !0)])])) : l("", !0)
494
533
  ], 2));
495
534
  }
496
535
  });