@feugene/granularity-media 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +23 -6
  2. package/dist/chunks/{config-CZ4ZDG0_.js → config-DHLlFslI.js} +1 -1
  3. package/dist/chunks/config-DfJkKtIh.js +27 -0
  4. package/dist/chunks/{en-C-Wc5fTB.js → en-BugobSAO.js} +12 -4
  5. package/dist/chunks/{es-BUPtE9_0.js → es-B7iA-ExH.js} +12 -4
  6. package/dist/chunks/outputSize-D2FU4CbB.js +23 -0
  7. package/dist/chunks/ru-DSjpFh8N.js +4 -0
  8. package/dist/chunks/{ru-BqNILj54.js → ru-DpiW6Vax.js} +12 -4
  9. package/dist/chunks/useCameraStream-CPdm3r90.js +86 -0
  10. package/dist/components/GrCameraCapture/chunks/GrCameraCapture-t-uFTD9s.js +134 -0
  11. package/dist/components/GrCameraCapture/index.js +4 -3
  12. package/dist/components/GrCodeScanner/chunks/GrCodeScanner-BX147Gct.js +162 -0
  13. package/dist/components/GrCodeScanner/index.js +3 -0
  14. package/dist/components/GrImageCrop/chunks/{GrImageCrop-Fo2qrX2n.js → GrImageCrop-g1StRUis.js} +85 -84
  15. package/dist/components/GrImageCrop/index.js +1 -1
  16. package/dist/granular-provider.js +14 -12
  17. package/dist/i18n/all.js +1 -1
  18. package/dist/i18n/index.js +4 -4
  19. package/dist/index.js +8 -5
  20. package/dist/resolver.js +5 -1
  21. package/dist/types/componentNames.d.ts +1 -1
  22. package/dist/types/components/GrCameraCapture/GrCameraCapture.vue.d.ts +13 -9
  23. package/dist/types/components/GrCameraCapture/cameraState.d.ts +0 -17
  24. package/dist/types/components/GrCameraCapture/grCameraCaptureStyles.d.ts +6 -2
  25. package/dist/types/components/GrCameraCapture/index.d.ts +2 -2
  26. package/dist/types/components/GrCodeScanner/GrCodeScanner.vue.d.ts +121 -0
  27. package/dist/types/components/GrCodeScanner/__tests__/GrCodeScanner.test.d.ts +1 -0
  28. package/dist/types/components/GrCodeScanner/__tests__/codeDetection.test.d.ts +1 -0
  29. package/dist/types/components/GrCodeScanner/codeDetection.d.ts +42 -0
  30. package/dist/types/components/GrCodeScanner/config.d.ts +5 -0
  31. package/dist/types/components/GrCodeScanner/defaults.d.ts +16 -0
  32. package/dist/types/components/GrCodeScanner/grCodeScannerStyles.d.ts +19 -0
  33. package/dist/types/components/GrCodeScanner/index.d.ts +9 -0
  34. package/dist/types/granular-provider/shared.d.ts +1 -0
  35. package/dist/types/i18n/index.d.ts +21 -0
  36. package/dist/types/i18n/messages/en.d.ts +14 -0
  37. package/dist/types/i18n/messages/es.d.ts +14 -0
  38. package/dist/types/i18n/messages/ru.d.ts +14 -0
  39. package/dist/types/index.d.ts +1 -0
  40. package/dist/types/internal/__tests__/outputSize.test.d.ts +1 -0
  41. package/dist/types/internal/outputSize.d.ts +26 -0
  42. package/dist/types/internal/useCameraStream.d.ts +30 -0
  43. package/package.json +5 -1
  44. package/dist/chunks/ru-DN_wJDkP.js +0 -4
  45. package/dist/components/GrCameraCapture/chunks/GrCameraCapture-B9EPXm7r.js +0 -201
@@ -1,43 +1,44 @@
1
- import { c as e, d as t, f as n, i as r, l as i, n as a, o, r as s, s as c, u as l } from "../../../chunks/config-Be_Mh801.js";
2
- import { Fragment as u, computed as d, createCommentVNode as ee, createElementBlock as f, createElementVNode as p, createVNode as te, defineComponent as m, normalizeClass as h, normalizeStyle as g, onBeforeUnmount as _, onMounted as ne, openBlock as v, ref as y, renderSlot as b, shallowRef as x, toDisplayString as re, unref as S, watch as ie } from "vue";
3
- import { useGrComponentSize as ae } from "@feugene/granularity/composables/useGrComponentConfig";
4
- import { useGranularityTranslations as oe } from "@feugene/granularity/composables/useGranularityTranslations";
5
- import se from "@feugene/granularity/components/GrSlider";
6
- import { useDragGesture as ce } from "@feugene/granularity/composables/useDragGesture";
1
+ import { t as e } from "../../../chunks/outputSize-D2FU4CbB.js";
2
+ import { c as t, d as n, f as r, i, l as a, n as o, o as ee, r as te, s, u as ne } from "../../../chunks/config-Be_Mh801.js";
3
+ import { Fragment as c, computed as l, createCommentVNode as re, createElementBlock as u, createElementVNode as d, createVNode as ie, defineComponent as f, normalizeClass as p, normalizeStyle as m, onBeforeUnmount as ae, onMounted as oe, openBlock as h, ref as g, renderSlot as _, shallowRef as se, toDisplayString as v, unref as y, watch as ce } from "vue";
4
+ import { useGrComponentSize as le } from "@feugene/granularity/composables/useGrComponentConfig";
5
+ import { useGranularityTranslations as ue } from "@feugene/granularity/composables/useGranularityTranslations";
6
+ import b from "@feugene/granularity/components/GrSlider";
7
+ import { useDragGesture as de } from "@feugene/granularity/composables/useDragGesture";
7
8
  //#region src/components/GrImageCrop/cropGeometry.ts
8
- function C(e, t) {
9
+ function x(e, t) {
9
10
  return e.width <= 0 || e.height <= 0 ? 1 : Math.max(t.width / e.width, t.height / e.height);
10
11
  }
11
- function w(e, t, n) {
12
- let r = C(e, t) * n;
12
+ function S(e, t, n) {
13
+ let r = x(e, t) * n;
13
14
  return {
14
15
  width: e.width * r,
15
16
  height: e.height * r
16
17
  };
17
18
  }
18
- function T(e, t, n) {
19
- let r = w(e, t, n);
19
+ function C(e, t, n) {
20
+ let r = S(e, t, n);
20
21
  return {
21
22
  x: Math.max(0, (r.width - t.width) / 2),
22
23
  y: Math.max(0, (r.height - t.height) / 2)
23
24
  };
24
25
  }
25
- function E(e, t, n, r) {
26
- let i = T(t, n, r);
26
+ function w(e, t, n, r) {
27
+ let i = C(t, n, r);
27
28
  return {
28
29
  x: Math.min(i.x, Math.max(-i.x, e.x)),
29
30
  y: Math.min(i.y, Math.max(-i.y, e.y))
30
31
  };
31
32
  }
32
- function D(e, t, n, r) {
33
- let i = C(e, t) * n;
33
+ function T(e, t, n, r) {
34
+ let i = x(e, t) * n;
34
35
  if (i <= 0) return {
35
36
  sx: 0,
36
37
  sy: 0,
37
38
  sw: 0,
38
39
  sh: 0
39
40
  };
40
- let a = E(r, e, t, n), o = w(e, t, n);
41
+ let a = w(r, e, t, n), o = S(e, t, n);
41
42
  return {
42
43
  sx: (o.width - t.width) / 2 / i - a.x / i,
43
44
  sy: (o.height - t.height) / 2 / i - a.y / i,
@@ -45,7 +46,7 @@ function D(e, t, n, r) {
45
46
  sh: t.height / i
46
47
  };
47
48
  }
48
- function O(e, t) {
49
+ function E(e, t) {
49
50
  return {
50
51
  width: e,
51
52
  height: e / (t > 0 ? t : 1)
@@ -53,11 +54,11 @@ function O(e, t) {
53
54
  }
54
55
  //#endregion
55
56
  //#region src/components/GrImageCrop/GrImageCrop.vue?vue&type=script&setup=true&lang.ts
56
- var le = ["aria-label"], ue = [
57
+ var D = ["aria-label"], O = [
57
58
  "tabindex",
58
59
  "aria-label",
59
60
  "aria-disabled"
60
- ], de = ["src"], k = 12, A = .15, j = /* @__PURE__ */ m({
61
+ ], fe = ["src"], k = 12, A = .15, j = /* @__PURE__ */ f({
61
62
  __name: "GrImageCrop",
62
63
  props: {
63
64
  src: { default: null },
@@ -79,14 +80,14 @@ var le = ["aria-label"], ue = [
79
80
  "load",
80
81
  "error"
81
82
  ],
82
- setup(m, { expose: C, emit: w }) {
83
- let T = m, j = w, { t: M } = oe(), N = ae(() => T.size, { component: "GrImageCrop" }), P = y(null), F = x(null), I = y({
83
+ setup(f, { expose: x, emit: S }) {
84
+ let C = f, j = S, { t: M } = ue(), N = le(() => C.size, { component: "GrImageCrop" }), P = g(null), F = se(null), I = g({
84
85
  width: 0,
85
86
  height: 0
86
- }), L = y(0), R = y({
87
+ }), L = g(0), R = g({
87
88
  x: 0,
88
89
  y: 0
89
- }), z = y(null), B = d(() => O(L.value, T.aspectRatio)), V = d(() => F.value !== null && I.value.width > 0), H = d(() => Math.min(T.maxZoom, Math.max(1, T.zoom))), fe = d(() => {
90
+ }), z = g(null), B = l(() => E(L.value, C.aspectRatio)), V = l(() => F.value !== null && I.value.width > 0), H = l(() => Math.min(C.maxZoom, Math.max(1, C.zoom))), pe = l(() => {
90
91
  let e = B.value.width > 0 && I.value.width > 0 ? Math.max(B.value.width / I.value.width, B.value.height / I.value.height) * H.value : 1;
91
92
  return {
92
93
  width: `${I.value.width}px`,
@@ -95,21 +96,21 @@ var le = ["aria-label"], ue = [
95
96
  };
96
97
  });
97
98
  function U() {
98
- return D(I.value, B.value, H.value, R.value);
99
+ return T(I.value, B.value, H.value, R.value);
99
100
  }
100
101
  function W() {
101
102
  V.value && j("change", U());
102
103
  }
103
104
  function G(e, t) {
104
- T.disabled || !V.value || (R.value = E({
105
+ C.disabled || !V.value || (R.value = w({
105
106
  x: R.value.x + e,
106
107
  y: R.value.y + t
107
108
  }, I.value, B.value, H.value), W());
108
109
  }
109
110
  function K(e) {
110
- if (T.disabled) return;
111
- let t = Math.min(T.maxZoom, Math.max(1, e));
112
- j("update:zoom", t), R.value = E(R.value, I.value, B.value, t), W();
111
+ if (C.disabled) return;
112
+ let t = Math.min(C.maxZoom, Math.max(1, e));
113
+ j("update:zoom", t), R.value = w(R.value, I.value, B.value, t), W();
113
114
  }
114
115
  function q() {
115
116
  R.value = {
@@ -117,14 +118,14 @@ var le = ["aria-label"], ue = [
117
118
  y: 0
118
119
  }, j("update:zoom", 1), W();
119
120
  }
120
- let J = y({
121
+ let J = g({
121
122
  x: 0,
122
123
  y: 0
123
- }), Y = y({
124
+ }), Y = g({
124
125
  x: 0,
125
126
  y: 0
126
- }), X = ce({
127
- disabled: () => T.disabled || !V.value,
127
+ }), X = de({
128
+ disabled: () => C.disabled || !V.value,
128
129
  onStart: (e) => {
129
130
  J.value = {
130
131
  x: e.clientX,
@@ -132,7 +133,7 @@ var le = ["aria-label"], ue = [
132
133
  }, Y.value = { ...R.value };
133
134
  },
134
135
  onMove: (e) => {
135
- R.value = E({
136
+ R.value = w({
136
137
  x: Y.value.x + (e.clientX - J.value.x),
137
138
  y: Y.value.y + (e.clientY - J.value.y)
138
139
  }, I.value, B.value, H.value);
@@ -142,10 +143,10 @@ var le = ["aria-label"], ue = [
142
143
  R.value = Y.value;
143
144
  }
144
145
  });
145
- function pe(e) {
146
- T.disabled || !V.value || (e.preventDefault(), K(H.value + (e.deltaY < 0 ? A : -.15)));
147
- }
148
146
  function me(e) {
147
+ C.disabled || !V.value || (e.preventDefault(), K(H.value + (e.deltaY < 0 ? A : -.15)));
148
+ }
149
+ function he(e) {
149
150
  let t = {
150
151
  ArrowLeft: () => G(k, 0),
151
152
  ArrowRight: () => G(-12, 0),
@@ -161,7 +162,7 @@ var le = ["aria-label"], ue = [
161
162
  function Z() {
162
163
  z.value &&= (URL.revokeObjectURL(z.value), null);
163
164
  }
164
- function he(e) {
165
+ function ge(e) {
165
166
  if (!e) return null;
166
167
  if (typeof e == "string") return e;
167
168
  let t = URL.createObjectURL(e);
@@ -169,7 +170,7 @@ var le = ["aria-label"], ue = [
169
170
  }
170
171
  function Q(e) {
171
172
  Z();
172
- let t = he(e);
173
+ let t = ge(e);
173
174
  if (!t) {
174
175
  F.value = null, I.value = {
175
176
  width: 0,
@@ -189,83 +190,83 @@ var le = ["aria-label"], ue = [
189
190
  }), n.addEventListener("error", (e) => j("error", e)), n.src = t;
190
191
  }
191
192
  let $ = null;
192
- ne(() => {
193
+ oe(() => {
193
194
  P.value && (L.value = P.value.clientWidth, $ = new ResizeObserver(([e]) => {
194
- L.value = e?.contentRect.width ?? 0, R.value = E(R.value, I.value, B.value, H.value);
195
- }), $.observe(P.value)), Q(T.src);
196
- }), _(() => {
195
+ L.value = e?.contentRect.width ?? 0, R.value = w(R.value, I.value, B.value, H.value);
196
+ }), $.observe(P.value)), Q(C.src);
197
+ }), ae(() => {
197
198
  $?.disconnect(), $ = null, Z();
198
- }), ie(() => T.src, (e) => Q(e));
199
- async function ge() {
200
- let e = F.value;
201
- if (!e || !V.value) return null;
202
- let t = U(), n = document.createElement("canvas");
203
- n.width = Math.max(1, Math.round(T.output?.width ?? t.sw)), n.height = Math.max(1, Math.round(T.output?.height ?? t.sh));
204
- let r = n.getContext("2d");
205
- if (!r) return null;
206
- r.drawImage(e, t.sx, t.sy, t.sw, t.sh, 0, 0, n.width, n.height);
199
+ }), ce(() => C.src, (e) => Q(e));
200
+ async function _e() {
201
+ let t = F.value;
202
+ if (!t || !V.value) return null;
203
+ let n = U(), r = document.createElement("canvas"), i = e(n, C.output);
204
+ r.width = i.width, r.height = i.height;
205
+ let a = r.getContext("2d");
206
+ if (!a) return null;
207
+ a.drawImage(t, n.sx, n.sy, n.sw, n.sh, 0, 0, r.width, r.height);
207
208
  try {
208
209
  return await new Promise((e) => {
209
- n.toBlob(e, T.output?.type ?? "image/png", T.output?.quality);
210
+ r.toBlob(e, C.output?.type ?? "image/png", C.output?.quality);
210
211
  });
211
212
  } catch (e) {
212
213
  return typeof process < "u" && process.env.NODE_ENV !== "production" && console.warn("[granularity-media] GrImageCrop: экспорт кадра запрещён политикой источника. Картинка приехала с другого домена без заголовка `Access-Control-Allow-Origin`, и холст стал непригоден для чтения."), j("error", e), null;
213
214
  }
214
215
  }
215
- return C({
216
- crop: ge,
216
+ return x({
217
+ crop: _e,
217
218
  reset: q,
218
219
  rect: U
219
- }), (d, _) => (v(), f("div", {
220
- class: h(S(i)),
220
+ }), (e, l) => (h(), u("div", {
221
+ class: p(y(a)),
221
222
  role: "group",
222
- "aria-label": m.ariaLabel ?? S(M)("grMedia.imageCrop.label", "Image crop")
223
- }, [p("div", {
223
+ "aria-label": f.ariaLabel ?? y(M)("grMedia.imageCrop.label", "Image crop")
224
+ }, [d("div", {
224
225
  ref_key: "viewportEl",
225
226
  ref: P,
226
227
  role: "application",
227
- class: h([S(n), V.value ? "" : [S(r), S(l)[S(N)]]]),
228
- style: g(V.value ? { aspectRatio: String(m.aspectRatio) } : void 0),
229
- tabindex: m.disabled || !V.value ? -1 : 0,
230
- "aria-label": S(M)("grMedia.imageCrop.frame", "Frame: arrow keys move the image, plus and minus zoom"),
231
- "aria-disabled": m.disabled || void 0,
232
- onPointerdown: _[0] ||= (...e) => S(X).start && S(X).start(...e),
233
- onWheel: pe,
234
- onKeydown: me
235
- }, [V.value ? (v(), f(u, { key: 0 }, [p("img", {
228
+ class: p([y(r), V.value ? "" : [y(i), y(ne)[y(N)]]]),
229
+ style: m(V.value ? { aspectRatio: String(f.aspectRatio) } : void 0),
230
+ tabindex: f.disabled || !V.value ? -1 : 0,
231
+ "aria-label": y(M)("grMedia.imageCrop.frame", "Frame: arrow keys move the image, plus and minus zoom"),
232
+ "aria-disabled": f.disabled || void 0,
233
+ onPointerdown: l[0] ||= (...e) => y(X).start && y(X).start(...e),
234
+ onWheel: me,
235
+ onKeydown: he
236
+ }, [V.value ? (h(), u(c, { key: 0 }, [d("img", {
236
237
  src: F.value.src,
237
238
  alt: "",
238
- class: h([S(o), S(X).isDragging.value ? "" : S(c)]),
239
- style: g(fe.value)
240
- }, null, 14, de), m.shape === "circle" ? (v(), f("div", {
239
+ class: p([y(ee), y(X).isDragging.value ? "" : y(s)]),
240
+ style: m(pe.value)
241
+ }, null, 14, fe), f.shape === "circle" ? (h(), u("div", {
241
242
  key: 0,
242
- class: h(S(a))
243
- }, null, 2)) : (v(), f("div", {
243
+ class: p(y(o))
244
+ }, null, 2)) : (h(), u("div", {
244
245
  key: 1,
245
- class: h(S(e))
246
- }, null, 2))], 64)) : b(d.$slots, "empty", {}, () => [p("span", { class: h(S(t)[S(N)]) }, re(S(M)("grMedia.imageCrop.empty", "No image selected")), 3)], void 0, 1)], 46, ue), V.value ? (v(), f("div", {
246
+ class: p(y(t))
247
+ }, null, 2))], 64)) : _(e.$slots, "empty", {}, () => [d("span", { class: p(y(n)[y(N)]) }, v(y(M)("grMedia.imageCrop.empty", "No image selected")), 3)], void 0, 1)], 46, O), V.value ? (h(), u("div", {
247
248
  key: 0,
248
- class: h(S(s))
249
- }, [b(d.$slots, "controls", {
249
+ class: p(y(te))
250
+ }, [_(e.$slots, "controls", {
250
251
  zoom: H.value,
251
252
  setZoom: K
252
- }, () => [te(S(se), {
253
+ }, () => [ie(y(b), {
253
254
  "model-value": H.value,
254
255
  min: 1,
255
- max: m.maxZoom,
256
+ max: f.maxZoom,
256
257
  step: .01,
257
- size: S(N),
258
- disabled: m.disabled,
259
- "aria-label": S(M)("grMedia.imageCrop.zoom", "Zoom"),
260
- "onUpdate:modelValue": _[1] ||= (e) => K(Number(e))
258
+ size: y(N),
259
+ disabled: f.disabled,
260
+ "aria-label": y(M)("grMedia.imageCrop.zoom", "Zoom"),
261
+ "onUpdate:modelValue": l[1] ||= (e) => K(Number(e))
261
262
  }, null, 8, [
262
263
  "model-value",
263
264
  "max",
264
265
  "size",
265
266
  "disabled",
266
267
  "aria-label"
267
- ])])], 2)) : ee("", !0)], 10, le));
268
+ ])])], 2)) : re("", !0)], 10, D));
268
269
  }
269
270
  });
270
271
  //#endregion
271
- export { w as a, D as i, E as n, T as o, C as r, O as s, j as t };
272
+ export { S as a, T as i, w as n, C as o, x as r, E as s, j as t };
@@ -1,3 +1,3 @@
1
- import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./chunks/GrImageCrop-Fo2qrX2n.js";
1
+ import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./chunks/GrImageCrop-g1StRUis.js";
2
2
  import { a as s, t as c } from "../../chunks/config-Be_Mh801.js";
3
3
  export { o as GrImageCrop, o as default, n as clampOffset, i as coverScale, t as cropRect, e as displaySize, c as grImageCropConfig, s as grImageCropSafelist, r as offsetBounds, a as viewportFor };
@@ -1,21 +1,23 @@
1
- import { t as e } from "./chunks/config-CZ4ZDG0_.js";
2
- import { t } from "./chunks/config-Be_Mh801.js";
3
- import { defineGranularProvider as n, resolvePackageBaseUrl as r } from "@feugene/unocss-preset-granular/contract";
4
- import { granularityProvider as i } from "@feugene/granularity/granular-provider";
1
+ import { t as e } from "./chunks/config-DHLlFslI.js";
2
+ import { t } from "./chunks/config-DfJkKtIh.js";
3
+ import { t as n } from "./chunks/config-Be_Mh801.js";
4
+ import { defineGranularProvider as r, resolvePackageBaseUrl as i } from "@feugene/unocss-preset-granular/contract";
5
+ import { granularityProvider as a } from "@feugene/granularity/granular-provider";
5
6
  //#region src/granular-provider/shared.ts
6
- var a = "@feugene/granularity-media", o = {
7
+ var o = "@feugene/granularity-media", s = {
7
8
  GrCameraCapture: e,
8
- GrImageCrop: t
9
+ GrCodeScanner: t,
10
+ GrImageCrop: n
9
11
  };
10
- function s(e, t) {
11
- return n({
12
- id: a,
12
+ function c(e, t) {
13
+ return r({
14
+ id: o,
13
15
  contractVersion: 1,
14
16
  packageBaseUrl: t,
15
- components: Object.values(o),
17
+ components: Object.values(s),
16
18
  dependencies: [e]
17
19
  });
18
20
  }
19
- var c = s(i, r(import.meta.url, 0));
21
+ var l = c(a, i(import.meta.url, 0));
20
22
  //#endregion
21
- export { a as GRANULARITY_MEDIA_PROVIDER_ID, s as createGranularityMediaProvider, c as default, c as granularityMediaProvider, o as granularityMediaComponentConfigs };
23
+ export { o as GRANULARITY_MEDIA_PROVIDER_ID, c as createGranularityMediaProvider, l as default, l as granularityMediaProvider, s as granularityMediaComponentConfigs };
package/dist/i18n/all.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as e, r as t, t as n } from "../chunks/ru-DN_wJDkP.js";
1
+ import { n as e, r as t, t as n } from "../chunks/ru-DSjpFh8N.js";
2
2
  //#region src/i18n/all.ts
3
3
  var r = [
4
4
  t,
@@ -1,7 +1,7 @@
1
- import { t as e } from "../chunks/en-C-Wc5fTB.js";
2
- import { t } from "../chunks/es-BUPtE9_0.js";
3
- import { t as n } from "../chunks/ru-BqNILj54.js";
4
- import { i as r, n as i, r as a, t as o } from "../chunks/ru-DN_wJDkP.js";
1
+ import { t as e } from "../chunks/en-BugobSAO.js";
2
+ import { t } from "../chunks/es-B7iA-ExH.js";
3
+ import { t as n } from "../chunks/ru-DpiW6Vax.js";
4
+ import { i as r, n as i, r as a, t as o } from "../chunks/ru-DSjpFh8N.js";
5
5
  //#region src/i18n/index.ts
6
6
  var s = {
7
7
  en: e,
package/dist/index.js CHANGED
@@ -1,5 +1,8 @@
1
- import { a as e, i as t, n, r, t as i } from "./components/GrCameraCapture/chunks/GrCameraCapture-B9EPXm7r.js";
2
- import { i as a, t as o } from "./chunks/config-CZ4ZDG0_.js";
3
- import { a as s, i as c, n as l, o as u, r as d, s as f, t as p } from "./components/GrImageCrop/chunks/GrImageCrop-Fo2qrX2n.js";
4
- import { a as m, t as h } from "./chunks/config-Be_Mh801.js";
5
- export { i as GrCameraCapture, p as GrImageCrop, n as cameraFrameRect, r as cameraStatusFromError, t as cameraSupported, l as clampOffset, d as coverScale, c as cropRect, s as displaySize, o as grCameraCaptureConfig, a as grCameraCaptureSafelist, h as grImageCropConfig, m as grImageCropSafelist, u as offsetBounds, e as shouldMirrorPreview, f as viewportFor };
1
+ import { i as e, n as t, r as n } from "./chunks/useCameraStream-CPdm3r90.js";
2
+ import { i as r, t as i } from "./chunks/config-DHLlFslI.js";
3
+ import { t as a } from "./components/GrCameraCapture/chunks/GrCameraCapture-t-uFTD9s.js";
4
+ import { i as o, n as s, r as c, t as l } from "./components/GrCodeScanner/chunks/GrCodeScanner-BX147Gct.js";
5
+ import { i as u, t as d } from "./chunks/config-DfJkKtIh.js";
6
+ import { a as f, i as p, n as m, o as h, r as g, s as _, t as v } from "./components/GrImageCrop/chunks/GrImageCrop-g1StRUis.js";
7
+ import { a as y, t as b } from "./chunks/config-Be_Mh801.js";
8
+ export { a as GrCameraCapture, l as GrCodeScanner, v as GrImageCrop, t as cameraStatusFromError, n as cameraSupported, m as clampOffset, g as coverScale, s as createNativeDetector, p as cropRect, f as displaySize, c as freshCodes, i as grCameraCaptureConfig, r as grCameraCaptureSafelist, d as grCodeScannerConfig, u as grCodeScannerSafelist, b as grImageCropConfig, y as grImageCropSafelist, o as nativeDetectorSupported, h as offsetBounds, e as shouldMirrorPreview, _ as viewportFor };
package/dist/resolver.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { createGranularResolver as e } from "@feugene/unplugin-granularity";
2
2
  //#region src/componentNames.ts
3
- var t = ["GrCameraCapture", "GrImageCrop"], n = "@feugene/granularity-media";
3
+ var t = [
4
+ "GrCameraCapture",
5
+ "GrCodeScanner",
6
+ "GrImageCrop"
7
+ ], n = "@feugene/granularity-media";
4
8
  function r() {
5
9
  return e({
6
10
  packageName: n,
@@ -8,5 +8,5 @@
8
8
  *
9
9
  * Список генерируется `yarn generate:registry` — руками не писать.
10
10
  */
11
- export declare const GRANULARITY_MEDIA_COMPONENTS: readonly ["GrCameraCapture", "GrImageCrop"];
11
+ export declare const GRANULARITY_MEDIA_COMPONENTS: readonly ["GrCameraCapture", "GrCodeScanner", "GrImageCrop"];
12
12
  export type GranularityMediaComponentName = typeof GRANULARITY_MEDIA_COMPONENTS[number];
@@ -12,10 +12,11 @@ export interface GrCameraCaptureProps {
12
12
  /** Конкретное устройство, если приложение его уже выбрало. */
13
13
  deviceId?: string;
14
14
  /**
15
- * Соотношение сторон рамки и снимка.
15
+ * Пожелание камере: какое соотношение сторон запросить у устройства.
16
16
  *
17
- * Без него рамка принимает соотношение самого потока: камеры отдают то 4:3,
18
- * то 16:9, и любое зашитое число показало бы обрезанный кадр как настоящий.
17
+ * Это **не обрезка**. Камера, которая умеет запрошенное, отдаст его сама;
18
+ * та, что не умеет, отдаст своё и показан, и снят будет её настоящий кадр.
19
+ * Нужен ровно квадрат — это `GrImageCrop` после съёмки.
19
20
  */
20
21
  aspectRatio?: number;
21
22
  /**
@@ -47,10 +48,13 @@ type __VLS_Slots = {
47
48
  capture: () => Promise<Blob | null>;
48
49
  }) => unknown;
49
50
  };
50
- declare function start(): Promise<void>;
51
- declare function stop(): void;
52
51
  /**
53
- * Снимок текущего кадра.
52
+ * Снимок текущего кадра — целиком, без среза.
53
+ *
54
+ * Камеры на разных устройствах отдают разные размеры и соотношения, поэтому
55
+ * подгонять кадр под окно бессмысленно: на одном телефоне срезалось бы одно, на
56
+ * другом другое. Снимок повторяет то, что показывало превью, а обрезка под
57
+ * нужное место — работа `GrImageCrop`.
54
58
  *
55
59
  * Зеркало превью сюда **не переносится**: на снимке оказывается то, что было
56
60
  * перед камерой. Иначе текст на визитке или в документе уехал бы в зазеркалье —
@@ -68,8 +72,8 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
68
72
  disabled: boolean;
69
73
  ariaLabel: undefined;
70
74
  }>>, {
71
- start: typeof start;
72
- stop: typeof stop;
75
+ start: () => Promise<void>;
76
+ stop: () => void;
73
77
  capture: typeof capture;
74
78
  status: import("vue").Ref<GrCameraStatus, GrCameraStatus>;
75
79
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
@@ -93,9 +97,9 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
93
97
  onStop?: (() => any) | undefined;
94
98
  onStatusChange?: ((status: GrCameraStatus) => any) | undefined;
95
99
  }>, {
96
- facing: GrCameraFacing;
97
100
  deviceId: string;
98
101
  aspectRatio: number;
102
+ facing: GrCameraFacing;
99
103
  autoStart: boolean;
100
104
  mirror: boolean;
101
105
  output: GrCameraCaptureOutput;
@@ -48,20 +48,3 @@ export declare function cameraSupported(navigatorLike: Pick<Navigator, 'mediaDev
48
48
  * уедет в зазеркалье — а снимают ими ровно это.
49
49
  */
50
50
  export declare function shouldMirrorPreview(facing: 'user' | 'environment', mirror: boolean | undefined): boolean;
51
- export interface GrCameraFrameRect {
52
- sx: number;
53
- sy: number;
54
- sw: number;
55
- sh: number;
56
- }
57
- /**
58
- * Какая часть кадра камеры попадёт в снимок при заданном соотношении сторон.
59
- *
60
- * Камера отдаёт своё соотношение (обычно 4:3 или 16:9), а приложению нужно
61
- * своё. Лишнее срезается по центру — так же, как это делает `object-fit: cover`
62
- * в превью: снимок обязан совпасть с тем, что пользователь видел.
63
- */
64
- export declare function cameraFrameRect(frame: {
65
- width: number;
66
- height: number;
67
- }, aspectRatio: number): GrCameraFrameRect;
@@ -2,8 +2,12 @@ export type GrCameraCaptureSize = 'xs' | 'sm' | 'md' | 'lg';
2
2
  export type GrCameraFacing = 'user' | 'environment';
3
3
  export declare const rootClass = "grid gap-2";
4
4
  export declare const frameClass = "relative w-full overflow-hidden rounded-[var(--gr-radius-md)] border border-[var(--gr-brd)] bg-[var(--gr-muted)]";
5
- /** Превью покрывает рамку целиком: снимок берётся тем же `cover`, что и показ. */
6
- export declare const videoClass = "h-full w-full object-cover";
5
+ /**
6
+ * Превью **вписывается**, а не покрывает: кадр показывается целиком, в своих
7
+ * пропорциях. При совпадающей рамке разницы нет, но между стартом и первым
8
+ * кадром рамка ещё держит запасные 4:3 — и `cover` срезал бы картинку.
9
+ */
10
+ export declare const videoClass = "h-full w-full object-contain";
7
11
  export declare const mirroredClass = "scale-x-[-1]";
8
12
  /**
9
13
  * Подложка состояния поверх рамки. Появление плавное: отказ и ошибка приходят
@@ -1,7 +1,7 @@
1
1
  export { default } from './GrCameraCapture.vue';
2
2
  export { default as GrCameraCapture } from './GrCameraCapture.vue';
3
- export type { GrCameraFrameRect, GrCameraStatus } from './cameraState';
4
- export { cameraFrameRect, cameraStatusFromError, cameraSupported, shouldMirrorPreview } from './cameraState';
3
+ export type { GrCameraStatus } from './cameraState';
4
+ export { cameraStatusFromError, cameraSupported, shouldMirrorPreview } from './cameraState';
5
5
  export { grCameraCaptureConfig } from './config';
6
6
  export type { GrCameraCaptureConfigurableProps } from './defaults';
7
7
  export type { GrCameraCaptureEmits, GrCameraCaptureOutput, GrCameraCaptureProps } from './GrCameraCapture.vue';
@@ -0,0 +1,121 @@
1
+ import type { GrCameraStatus } from '../GrCameraCapture/cameraState';
2
+ import type { GrCodeDetector, GrCodeResult } from './codeDetection';
3
+ import type { GrCodeScannerSize } from './grCodeScannerStyles';
4
+ export interface GrCodeScannerProps {
5
+ /** Какая камера: `environment` — тыловая, ей и сканируют. */
6
+ facing?: 'user' | 'environment';
7
+ deviceId?: string;
8
+ /**
9
+ * Включать камеру сразу.
10
+ *
11
+ * По умолчанию `false`: запрос разрешения без действия пользователя
12
+ * отклоняют не глядя, а второй раз браузер уже не спросит.
13
+ */
14
+ autoStart?: boolean;
15
+ /** Символики: `qr_code`, `ean_13`, `code_128`, … Без списка — все, что умеет браузер. */
16
+ formats?: readonly string[];
17
+ /**
18
+ * Детектор для браузеров без `BarcodeDetector` — Safari и Firefox.
19
+ *
20
+ * Пакет своего декодера не несёт: у него нет ни одной зависимости, и ради
21
+ * одного компонента появилась бы самая тяжёлая. Рецепт подключения готовой
22
+ * библиотеки — на странице компонента.
23
+ */
24
+ detector?: GrCodeDetector;
25
+ /** Как часто разбирать кадр, мс. Чаще — горячее устройство, реже — вялый отклик. */
26
+ interval?: number;
27
+ /** Сообщать один и тот же код повторно: приёмка сканирует подряд. */
28
+ continuous?: boolean;
29
+ size?: GrCodeScannerSize;
30
+ disabled?: boolean;
31
+ ariaLabel?: string;
32
+ }
33
+ export interface GrCodeScannerEmits {
34
+ (e: 'detect', codes: GrCodeResult[]): void;
35
+ (e: 'start'): void;
36
+ (e: 'stop'): void;
37
+ (e: 'statusChange', status: GrCameraStatus): void;
38
+ }
39
+ type __VLS_Slots = {
40
+ /** Своя панель управления вместо встроенной. */
41
+ controls?: (props: {
42
+ status: GrCameraStatus;
43
+ start: () => void;
44
+ stop: () => void;
45
+ }) => unknown;
46
+ };
47
+ declare function stopAll(): void;
48
+ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<GrCodeScannerProps>, {
49
+ facing: string;
50
+ deviceId: undefined;
51
+ autoStart: boolean;
52
+ formats: undefined;
53
+ detector: undefined;
54
+ interval: number;
55
+ continuous: boolean;
56
+ size: undefined;
57
+ disabled: boolean;
58
+ ariaLabel: undefined;
59
+ }>>, {
60
+ start: () => Promise<void>;
61
+ stop: typeof stopAll;
62
+ status: import("vue").Ref<GrCameraStatus, GrCameraStatus>;
63
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
64
+ detect: (codes: GrCodeResult[]) => void;
65
+ start: () => void;
66
+ stop: () => void;
67
+ statusChange: (status: GrCameraStatus) => void;
68
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<GrCodeScannerProps>, {
69
+ facing: string;
70
+ deviceId: undefined;
71
+ autoStart: boolean;
72
+ formats: undefined;
73
+ detector: undefined;
74
+ interval: number;
75
+ continuous: boolean;
76
+ size: undefined;
77
+ disabled: boolean;
78
+ ariaLabel: undefined;
79
+ }>>> & Readonly<{
80
+ onStart?: (() => any) | undefined;
81
+ onStop?: (() => any) | undefined;
82
+ onStatusChange?: ((status: GrCameraStatus) => any) | undefined;
83
+ onDetect?: ((codes: GrCodeResult[]) => any) | undefined;
84
+ }>, {
85
+ deviceId: string;
86
+ facing: "user" | "environment";
87
+ autoStart: boolean;
88
+ size: GrCodeScannerSize;
89
+ disabled: boolean;
90
+ ariaLabel: string;
91
+ formats: readonly string[];
92
+ detector: GrCodeDetector;
93
+ interval: number;
94
+ continuous: boolean;
95
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
96
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
97
+ declare const _default: typeof __VLS_export;
98
+ export default _default;
99
+ type __VLS_TypePropsToOption<T> = {
100
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
101
+ type: import('vue').PropType<Required<T>[K]>;
102
+ } : {
103
+ type: import('vue').PropType<T[K]>;
104
+ required: true;
105
+ };
106
+ };
107
+ type __VLS_WithDefaults<P, D> = {
108
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_PrettifyLocal<P[K] & {
109
+ default: D[K];
110
+ }> : P[K];
111
+ };
112
+ type __VLS_WithSlots<T, S> = T & {
113
+ new (): {
114
+ $slots: S;
115
+ };
116
+ };
117
+ type __VLS_PrettifyLocal<T> = (T extends any ? {
118
+ [K in keyof T]: T[K];
119
+ } : {
120
+ [K in keyof T as K]: T[K];
121
+ }) & {};