ablok-components 0.3.127 → 0.3.131

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.
Files changed (32) hide show
  1. package/dist/ablok-components.css +1 -1
  2. package/dist/ablok-components.umd.js +2 -2
  3. package/dist/components/atoms/canvas-confetti/canvas-confetti.vue.d.ts +1 -1
  4. package/dist/components/molecules/base-camera/base-camera.js +5 -4
  5. package/dist/components/molecules/base-camera/base-camera.vue.d.ts +204 -66
  6. package/dist/components/molecules/base-camera/base-camera.vue_vue_type_script_setup_true_lang.js +410 -0
  7. package/dist/components/molecules/base-map/base-map.vue.d.ts +2 -2
  8. package/dist/components/molecules/camera-preview/camera-preview.js +7 -0
  9. package/dist/components/molecules/camera-preview/camera-preview.vue.d.ts +32 -0
  10. package/dist/components/molecules/camera-preview/camera-preview.vue_vue_type_script_setup_true_lang.js +67 -0
  11. package/dist/components/molecules/popover-tooltip/popover-tooltip.vue.d.ts +1 -1
  12. package/dist/composables/useCamera.d.ts +37 -0
  13. package/dist/composables/useCamera.js +44 -0
  14. package/dist/index.js +34 -34
  15. package/dist/symbol-defs.svg +6 -0
  16. package/dist/utilities/camera/CameraManager.d.ts +91 -0
  17. package/dist/utilities/camera/CameraManager.js +345 -0
  18. package/dist/utilities/camera/capture.d.ts +35 -0
  19. package/dist/utilities/camera/capture.js +82 -0
  20. package/dist/utilities/camera/constraints.d.ts +29 -0
  21. package/dist/utilities/camera/constraints.js +96 -0
  22. package/dist/utilities/camera/platform.d.ts +11 -0
  23. package/dist/utilities/camera/platform.js +20 -0
  24. package/dist/utilities/camera/types.d.ts +48 -0
  25. package/dist/utilities/camera/types.js +9 -0
  26. package/dist/utilities/helpers.js +10 -15
  27. package/package.json +1 -1
  28. package/dist/components/molecules/base-camera/base-camera.vue_vue_type_script_async_true_setup_true_lang.js +0 -498
  29. package/dist/composables/useCameraCapture.d.ts +0 -34
  30. package/dist/composables/useCameraCapture.js +0 -53
  31. package/dist/composables/useOrientationCorrection.d.ts +0 -27
  32. package/dist/composables/useOrientationCorrection.js +0 -66
@@ -1,498 +0,0 @@
1
- import e from "../../atoms/svg-icon/svg-icon.js";
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";
10
- import le from "lodash";
11
- //#region src/components/molecules/base-camera/base-camera.vue?vue&type=script&async=true&setup=true&lang.ts
12
- var ue = { class: "camera__preview" }, de = {
13
- key: 0,
14
- class: "camera__bg-notification"
15
- }, fe = ["innerHTML"], pe = ["width", "height"], me = {
16
- key: 1,
17
- class: "camera__countdown-overlay"
18
- }, he = ["innerHTML", "data-countdown"], ge = ["src"], _e = {
19
- key: 3,
20
- class: "camera__zoom-slider"
21
- }, ve = { class: "camera__controls" }, ye = { class: "container" }, be = { class: "row" }, xe = { class: "col" }, Se = { class: "btn-group" }, Ce = { key: 0 }, we = { key: 1 }, Te = {
22
- key: 0,
23
- class: "camera__select-device"
24
- }, Ee = { class: "col" }, De = { class: "" }, Oe = {
25
- name: "BaseCamera",
26
- inheritAttrs: !1
27
- }, ke = {
28
- "1x1": {
29
- width: 720,
30
- height: 720
31
- },
32
- "2x3": {
33
- width: 720,
34
- height: 1080
35
- },
36
- "3x2": {
37
- width: 1080,
38
- height: 720
39
- },
40
- "3x4": {
41
- width: 720,
42
- height: 960
43
- },
44
- "4x3": {
45
- width: 960,
46
- height: 720
47
- },
48
- "4x5": {
49
- width: 960,
50
- height: 1200
51
- },
52
- "5x4": {
53
- width: 1200,
54
- height: 960
55
- },
56
- "16x9": {
57
- width: 1280,
58
- height: 720
59
- },
60
- "9x16": {
61
- width: 720,
62
- height: 1280
63
- }
64
- }, Ae = /*@__PURE__*/ te({
65
- ...Oe,
66
- props: {
67
- modelValue: { type: null },
68
- enableSwitchCamera: {
69
- type: Boolean,
70
- default: !0
71
- },
72
- defaultRearCamera: {
73
- type: Boolean,
74
- default: !1
75
- },
76
- enableMirrorCamera: {
77
- type: Boolean,
78
- default: !1
79
- },
80
- enableGuide: {
81
- type: Boolean,
82
- default: !0
83
- },
84
- guideSrc: {
85
- type: String,
86
- default: () => c
87
- },
88
- countdown: {
89
- type: Number,
90
- default: 0
91
- },
92
- ratio: {
93
- type: String,
94
- default: ""
95
- },
96
- filter: {
97
- type: String,
98
- default: "none",
99
- validator: (e) => [
100
- "none",
101
- "grayscale",
102
- "sepia"
103
- ].includes(e)
104
- },
105
- tintColor: {
106
- type: String,
107
- default: ""
108
- },
109
- tintIntensity: {
110
- type: Number,
111
- default: .3
112
- },
113
- enableAudio: {
114
- type: Boolean,
115
- default: !1
116
- },
117
- enableSelectDevice: {
118
- type: Boolean,
119
- default: !1
120
- },
121
- enableCropImage: {
122
- type: Boolean,
123
- default: !0
124
- },
125
- resolutions: {
126
- type: Object,
127
- default: () => ke
128
- },
129
- zoom: {
130
- type: Number,
131
- default: 1
132
- },
133
- enableZoomSlider: {
134
- type: Boolean,
135
- default: !1
136
- },
137
- correctOrientation: {
138
- type: Boolean,
139
- default: !1
140
- }
141
- },
142
- 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;
145
- function L() {
146
- I &&= (I(), void 0);
147
- }
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
- };
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
- };
181
- }
182
- let R = l(() => F.value && (!Pe.value || Me.value)), z = l(() => ({
183
- ...ke,
184
- ...b.resolutions
185
- })), He = l(() => Object.values(z.value)[0]);
186
- function Ue(e) {
187
- return String(e || "").trim().toLowerCase().replace(/\s+/g, "").replace(/[:/]/g, "x");
188
- }
189
- let B = l(() => {
190
- if (z.value[b.ratio]) return b.ratio;
191
- let e = Ue(b.ratio);
192
- if (z.value[e]) return e;
193
- }), V = l(() => B.value ? z.value[B.value] : He.value), We = l(() => {
194
- let e = B.value ? z.value[B.value] : void 0;
195
- 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) {
203
- e && !U.value.includes(e) && (U.value = [...U.value, e]);
204
- }
205
- function Ye(e) {
206
- let t = H.value;
207
- if (!t.length) return;
208
- let n = t.findIndex((t) => t.deviceId === e);
209
- for (let e = 1; e <= t.length; e++) {
210
- let r = t[(Math.max(n, 0) + e) % t.length];
211
- if (r && !U.value.includes(r.deviceId)) return r;
212
- }
213
- }
214
- let Xe = l(() => qe.value.map((e, t) => ({
215
- text: e.label.slice(0, e.label.indexOf("(")) || `Camera ${t + 1}`,
216
- value: e.deviceId
217
- }))), Ze = l({
218
- get() {
219
- return w.value && w.value.deviceId;
220
- },
221
- set(e) {
222
- w.value = H.value.find((t) => t.deviceId === e), E.value = void 0;
223
- }
224
- });
225
- l({
226
- get() {
227
- return T.value && T.value.deviceId;
228
- },
229
- set(e) {
230
- T.value = Ge.value.find((t) => t.deviceId === e);
231
- }
232
- });
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);
235
- return G.value ? `${G.value} mirror-device-${e}` : "";
236
- }), { tintRgb: $e, applyFilterToCanvas: et } = r(b);
237
- function tt() {
238
- if (B.value && V.value) {
239
- j.value = V.value.width, M.value = V.value.height;
240
- return;
241
- }
242
- j.value = x.value.parentElement && x.value.parentElement.clientWidth, M.value = x.value.parentElement && x.value.parentElement.clientHeight;
243
- }
244
- let nt = Ae(() => {
245
- tt();
246
- }, 300, {
247
- trailing: !0,
248
- leading: !1
249
- });
250
- function K(e) {
251
- return new Promise((t) => setTimeout(t, e));
252
- }
253
- async function rt() {
254
- let e = V.value ? {
255
- width: V.value.width,
256
- 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 = [];
258
- i ? (t && n && o.push({
259
- deviceId: { exact: i },
260
- width: { ideal: t },
261
- height: { ideal: n }
262
- }), o.push({ deviceId: { exact: i } })) : a ? (t && n && o.push({
263
- facingMode: { exact: a },
264
- width: { ideal: t },
265
- height: { ideal: n }
266
- }), o.push({ facingMode: { exact: a } }), t && n && o.push({
267
- width: { ideal: t },
268
- height: { ideal: n }
269
- }), o.push({})) : (t && n && o.push({
270
- width: { ideal: t },
271
- height: { ideal: n }
272
- }), 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);
293
- }
294
- }
295
- throw s;
296
- }
297
- function q() {
298
- L(), F.value = !1, x.value && x.value.srcObject && (x.value.srcObject.getTracks().forEach((e) => {
299
- e.stop();
300
- }), x.value.srcObject = null);
301
- }
302
- let J = 0, Y, X = null;
303
- function Z() {
304
- Y &&= (clearTimeout(Y), void 0);
305
- }
306
- function it(e) {
307
- Je(e);
308
- let t = Ye(e);
309
- t && t.deviceId !== e && (w.value = t);
310
- }
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
- return;
323
- }
324
- let r = Ye(n);
325
- r && r.deviceId !== n && (q(), it(n));
326
- }, 5e3);
327
- }
328
- async function Q() {
329
- 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
- }
339
- if (e !== J) {
340
- n?.getTracks?.().forEach((e) => e.stop());
341
- return;
342
- }
343
- if (n && x.value) {
344
- Ve(), x.value.srcObject = n;
345
- 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();
355
- return;
356
- }
357
- return C.value = await navigator.mediaDevices.enumerateDevices(), {
358
- stream: x.value && x.value.srcObject,
359
- devices: C.value
360
- };
361
- }
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
- 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();
378
- }
379
- async function lt(e, t) {
380
- e && e.deviceId === O.value || e && (!t || e.deviceId !== t.deviceId) && await Q();
381
- }
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();
385
- }
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));
404
- }
405
- function dt(e) {
406
- je("update:modelValue", o(e));
407
- }
408
- 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();
414
- }), 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", {
420
- class: m("d-block text-center"),
421
- innerHTML: r.$t("camera.waitForCameraNotification")
422
- }, null, 8, fe)]),
423
- _: 1
424
- })])),
425
- f("div", {
426
- 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})`
430
- })
431
- }, [f("video", {
432
- ref_key: "camera",
433
- ref: x,
434
- 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
438
- }),
439
- autoplay: "",
440
- muted: "",
441
- playsinline: ""
442
- }, null, 4), c.tintColor ? (g(), d("div", {
443
- key: 0,
444
- class: "camera__tint-overlay",
445
- style: h({
446
- backgroundColor: c.tintColor,
447
- opacity: c.tintIntensity,
448
- mixBlendMode: "multiply"
449
- })
450
- }, null, 4)) : u("", !0)], 6),
451
- se(f("canvas", {
452
- ref_key: "canvas",
453
- ref: S,
454
- 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", {
459
- 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", {
465
- key: 2,
466
- 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)
473
- ]),
474
- f("div", ve, [f("div", ye, [f("div", be, [f("div", xe, [f("div", Se, [f("button", {
475
- type: "button",
476
- 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", {
479
- type: "button",
480
- 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, {
484
- key: 0,
485
- modelValue: Ze.value,
486
- "onUpdate:modelValue": i[1] ||= (e) => Ze.value = e,
487
- options: Xe.value,
488
- class: "w-100"
489
- }, null, 8, ["modelValue", "options"])) : u("", !0)]), f("div", De, [c.enableSwitchCamera ? (g(), d("button", {
490
- key: 0,
491
- class: "btn",
492
- onClick: ce(ct, ["prevent"])
493
- }, [p(e, { symbol: "switch-camera" })])) : u("", !0)])])) : u("", !0)
494
- ], 2));
495
- }
496
- });
497
- //#endregion
498
- export { Ae as default };
@@ -1,34 +0,0 @@
1
- export interface CaptureOptions {
2
- /** Target canvas dimensions; falls back to the source video dimensions. */
3
- targetResolution?: {
4
- width: number;
5
- height: number;
6
- } | undefined;
7
- /** True when the target ratio was explicitly requested (else derive height from source ratio). */
8
- hasExplicitRatio: boolean;
9
- /** Crop to the target ratio (cover) instead of letterboxing (contain). */
10
- enableCropImage: boolean;
11
- /** Digital zoom factor (1 = none). */
12
- zoom: number;
13
- /** Front-camera mirroring — flip horizontally. */
14
- mirror: boolean;
15
- /** Portrait-upright correction rotation (0/90/180/270), from useOrientationCorrection. */
16
- captureRotation: number;
17
- /** Called with the resulting PNG data URL. */
18
- onSave: (dataUrl: string) => void;
19
- }
20
- /**
21
- * Captures the current video frame onto the canvas, honouring ratio cropping,
22
- * zoom, mirroring and device-orientation rotation. Pure drawing logic — no
23
- * reactivity, trivially unit-testable.
24
- */
25
- export declare function captureFrame(canvas: HTMLCanvasElement, image: HTMLVideoElement, options: CaptureOptions): void;
26
- /** Runs the canvas-capture pipeline (drawing + optional post-filter) and returns the PNG data URL. */
27
- export declare function captureToDataUrl(canvas: HTMLCanvasElement, image: HTMLVideoElement, options: CaptureOptions, applyFilter?: (context: CanvasRenderingContext2D, width: number, height: number) => void): string;
28
- /** Converts a captured data URL into the emitted photo payload. */
29
- export declare function toPhotoPayload(dataUrl: string): {
30
- name: string;
31
- id: string;
32
- blob: Blob;
33
- size: number;
34
- };
@@ -1,53 +0,0 @@
1
- import { dataURItoBlob as e } from "../utilities/helpers.js";
2
- //#region src/composables/useCameraCapture.ts
3
- function t(e, t, n, r, i, a, o) {
4
- let s = e.canvas.width, c = e.canvas.height;
5
- e.translate(s / 2, c / 2), o && e.scale(-1, 1), e.rotate(n * Math.PI / 180);
6
- let l = c, u = s, d = Math.max(l / r, u / i) * (a && a > 0 ? a : 1), f = r * d, p = i * d;
7
- e.drawImage(t, -f / 2, -p / 2, f, p);
8
- }
9
- function n(e, n, r) {
10
- let i = e.getContext("2d");
11
- if (!i) return;
12
- let a = n.srcObject instanceof MediaStream ? n.srcObject.getTracks() : [], { aspectRatio: o, width: s, height: c } = a.length ? a[0].getSettings() : {}, l = n?.videoWidth || s || 0, u = n?.videoHeight || c || 0, d = l && u ? l / u : o, f = r.targetResolution || {
13
- width: l,
14
- height: u
15
- }, p = f?.width || l, m = r.hasExplicitRatio ? f?.height || u : Math.round(p / (d || 1)), h = p / m;
16
- if (e.width = p, e.height = m, !l || !u || !d) return;
17
- let g = r.zoom, _ = r.mirror;
18
- if (i.save(), r.captureRotation === 90 || r.captureRotation === 270) {
19
- t(i, n, r.captureRotation, l, u, g, _), i.restore();
20
- return;
21
- }
22
- if (r.captureRotation === 180 && (i.translate(e.width, e.height), i.scale(-1, -1)), _ && (i.translate(e.width, 0), i.scale(-1, 1)), r.enableCropImage) {
23
- let t = 0, r = 0, a = l, o = u;
24
- if (d > h ? (a = u * h, t = (l - a) / 2) : d < h && (o = l / h, r = (u - o) / 2), g && g !== 1) {
25
- let e = a / g, n = o / g;
26
- t += (a - e) / 2, r += (o - n) / 2, a = e, o = n;
27
- }
28
- i.drawImage(n, t, r, a, o, 0, 0, e.width, e.height);
29
- } else {
30
- let t = e.width, r = e.height, a = 0, o = 0;
31
- if (d > h ? (r = e.width / d, o = (e.height - r) / 2) : d < h && (t = e.height * d, a = (e.width - t) / 2), g && g !== 1) {
32
- let s = l / g, c = u / g, d = (l - s) / 2, f = (u - c) / 2;
33
- _ && (a = e.width - a - t), i.drawImage(n, d, f, s, c, a, o, t, r);
34
- } else _ && (a = e.width - a - t), i.drawImage(n, 0, 0, l, u, a, o, t, r);
35
- }
36
- i.restore();
37
- }
38
- function r(e, t, r, i) {
39
- n(e, t, r);
40
- let a = e.getContext("2d");
41
- return a && i && i(a, e.width, e.height), e.toDataURL("image/png");
42
- }
43
- function i(t) {
44
- let n = e(t), r = `cam-pic-${(/* @__PURE__ */ new Date()).toISOString()}`;
45
- return {
46
- name: r,
47
- id: r,
48
- blob: n,
49
- size: n.size
50
- };
51
- }
52
- //#endregion
53
- export { n as captureFrame, r as captureToDataUrl, i as toPhotoPayload };
@@ -1,27 +0,0 @@
1
- import { ComputedRef, Ref } from '../../vue/dist/vue.esm-bundler.js';
2
- /**
3
- * Device-orientation correction for rotation-locked pages.
4
- *
5
- * When the page is rotation-locked, the OS bakes a portrait-up OR portrait-down
6
- * (0°/180°) orientation into the camera buffer based on gravity. That affects the
7
- * preview AND the captured canvas identically. `orientationFlip` is true only while
8
- * the device is actually held in landscape (in-plane gravity near ±90°), where the
9
- * buffer arrives upside-down relative to the device frame; the preview counter-rotates
10
- * with a 180° rotation. Portrait-up and portrait-down are left untouched. Hysteresis
11
- * around the band edges prevents flicker.
12
- *
13
- * `previewReady` gates the preview until the correction is live (motion permission
14
- * granted + first sensor reading applied). A safety timeout prevents the preview
15
- * from being blocked forever if permission is denied or never granted.
16
- */
17
- export declare function useOrientationCorrection(enabled: () => boolean): {
18
- motionEnabled: Ref<boolean, boolean>;
19
- orientationFlip: Ref<boolean>;
20
- lastGravityAngle: Ref<number | null, number | null>;
21
- orientationReady: Ref<boolean, boolean>;
22
- requiresGate: ComputedRef<boolean>;
23
- enableMotion: () => Promise<void>;
24
- armGate: () => void;
25
- getCaptureRotation: () => number;
26
- dispose: () => void;
27
- };
@@ -1,66 +0,0 @@
1
- import { computed as e, ref as t } from "vue";
2
- //#region src/composables/useOrientationCorrection.ts
3
- function n(n) {
4
- let r = t(!1), i = t(!1), a = t(null), o = t(!1), s, c, l = typeof window < "u" && "DeviceMotionEvent" in window && (window.matchMedia?.("(pointer: coarse)")?.matches || "ontouchstart" in window), u = e(() => n() && l);
5
- function d() {
6
- c &&= (window.removeEventListener("pointerdown", c, !0), window.removeEventListener("touchend", c, !0), void 0);
7
- }
8
- function f() {
9
- o.value = !0, s &&= (clearTimeout(s), void 0), d();
10
- }
11
- function p() {
12
- c || (c = () => {
13
- h();
14
- }, window.addEventListener("pointerdown", c, !0), window.addEventListener("touchend", c, !0));
15
- }
16
- function m(e) {
17
- let t = e.accelerationIncludingGravity;
18
- if (!t || t.x == null || t.y == null) return;
19
- let n = Math.round(Math.atan2(t.x, t.y) * 180 / Math.PI);
20
- if (a.value = n, !(typeof screen < "u" && screen.orientation && screen.orientation.type || "portrait-primary").startsWith("portrait")) i.value = !1;
21
- else {
22
- let e = Math.abs(Math.abs(n) - 90);
23
- !i.value && e < 40 ? i.value = !0 : i.value && e > 50 && (i.value = !1);
24
- }
25
- o.value || f();
26
- }
27
- async function h() {
28
- if (!(!n() || r.value)) try {
29
- let e = window.DeviceOrientationEvent, t = window.DeviceMotionEvent;
30
- if (e && typeof e.requestPermission == "function" && await e.requestPermission() !== "granted") {
31
- f();
32
- return;
33
- }
34
- t && typeof t.requestPermission == "function" && await t.requestPermission().catch(() => {}), window.addEventListener("devicemotion", m, !0), r.value = !0, d();
35
- } catch (e) {
36
- console.error(e, "enableMotion: failed"), f();
37
- }
38
- }
39
- function g() {
40
- if (!u.value) return;
41
- s = setTimeout(f, 3e3);
42
- let e = window.DeviceOrientationEvent;
43
- e && typeof e.requestPermission == "function" ? p() : h();
44
- }
45
- function _() {
46
- if (!n() || a.value == null) return 0;
47
- let e = ((a.value - 180) % 360 + 360) % 360;
48
- return (-1 * (Math.round(e / 90) * 90 % 360) % 360 + 360) % 360;
49
- }
50
- function v() {
51
- window.removeEventListener("devicemotion", m, !0), s && clearTimeout(s), d();
52
- }
53
- return {
54
- motionEnabled: r,
55
- orientationFlip: i,
56
- lastGravityAngle: a,
57
- orientationReady: o,
58
- requiresGate: u,
59
- enableMotion: h,
60
- armGate: g,
61
- getCaptureRotation: _,
62
- dispose: v
63
- };
64
- }
65
- //#endregion
66
- export { n as useOrientationCorrection };