ablok-components 0.3.76 → 0.3.78

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