ablok-components 0.3.134 → 0.3.137

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.
@@ -10,6 +10,9 @@ export interface CameraSnapshot {
10
10
  permission: CameraPermission;
11
11
  zoom: number;
12
12
  zoomCapability: ZoomCapability | null;
13
+ torch: boolean;
14
+ torchCapability: boolean;
15
+ canLockExposure: boolean;
13
16
  }
14
17
  export interface CameraManagerOptions {
15
18
  preferredFacing?: Facing;
@@ -31,6 +34,9 @@ export declare class CameraManager {
31
34
  private zoom;
32
35
  private zoomCapability;
33
36
  private desiredZoom;
37
+ private torch;
38
+ private torchCapability;
39
+ private canLockExposure;
34
40
  private video;
35
41
  private seq;
36
42
  private tearingDown;
@@ -66,6 +72,9 @@ export declare class CameraManager {
66
72
  /** Restart at a new resolution, keeping the active device. */
67
73
  setResolution(resolution: Resolution): Promise<boolean>;
68
74
  setZoom(value: number): Promise<boolean>;
75
+ setTorch(on: boolean): Promise<boolean>;
76
+ /** Freeze auto-exposure so a screen flash brightens the frame instead of being metered away. */
77
+ setExposureLocked(locked: boolean): Promise<boolean>;
69
78
  refreshDevices(): Promise<void>;
70
79
  dispose(): void;
71
80
  private teardown;
@@ -88,4 +97,5 @@ export declare class CameraManager {
88
97
  private probeDevice;
89
98
  private initPermission;
90
99
  private readZoomCapability;
100
+ private readTorchCapability;
91
101
  }
@@ -23,6 +23,9 @@ var f = 1500, p = 2, m = 300, h = [
23
23
  zoom = 1;
24
24
  zoomCapability = null;
25
25
  desiredZoom = null;
26
+ torch = !1;
27
+ torchCapability = !1;
28
+ canLockExposure = !1;
26
29
  video = null;
27
30
  seq = 0;
28
31
  tearingDown = !1;
@@ -55,7 +58,10 @@ var f = 1500, p = 2, m = 300, h = [
55
58
  error: this.error,
56
59
  permission: this.permission,
57
60
  zoom: this.zoom,
58
- zoomCapability: this.zoomCapability
61
+ zoomCapability: this.zoomCapability,
62
+ torch: this.torch,
63
+ torchCapability: this.torchCapability,
64
+ canLockExposure: this.canLockExposure
59
65
  };
60
66
  }
61
67
  static isSupported() {
@@ -104,7 +110,7 @@ var f = 1500, p = 2, m = 300, h = [
104
110
  if (v && this.probeCache.set(v, b), this.stream = p, this.activeDeviceId = v, this.activeFacing = b, this.lastGood = {
105
111
  deviceId: v,
106
112
  resolution: n
107
- }, this.permission !== "granted" && (this.permission = "granted"), g.onended = this.onTrackEnded, this.readZoomCapability(g), this.setState("live"), this.armStableTimer(), this.bindStream(), this.desiredZoom !== null && this.setZoom(this.desiredZoom), await this.refreshDevices(), t !== this.seq) return !1;
113
+ }, this.permission !== "granted" && (this.permission = "granted"), g.onended = this.onTrackEnded, this.readZoomCapability(g), this.readTorchCapability(g), this.setState("live"), this.armStableTimer(), this.bindStream(), this.desiredZoom !== null && this.setZoom(this.desiredZoom), await this.refreshDevices(), t !== this.seq) return !1;
108
114
  if (!e.deviceId && !this.autoCorrected && this.opts.preferredFacing && b && (this.autoCorrected = !0, b !== this.opts.preferredFacing)) {
109
115
  let e = this.devices.find((e) => e.facing === this.opts.preferredFacing && e.deviceId !== v);
110
116
  if (e) return this.start({
@@ -177,6 +183,26 @@ var f = 1500, p = 2, m = 300, h = [
177
183
  }
178
184
  return this.zoom = t.getSettings().zoom ?? r, this.emit(), !0;
179
185
  }
186
+ async setTorch(e) {
187
+ let t = this.stream?.getVideoTracks()[0];
188
+ if (!t || !this.torchCapability) return !1;
189
+ try {
190
+ await t.applyConstraints({ advanced: [{ torch: e }] });
191
+ } catch {
192
+ return !1;
193
+ }
194
+ return this.torch = t.getSettings().torch ?? e, this.emit(), !0;
195
+ }
196
+ async setExposureLocked(e) {
197
+ let t = this.stream?.getVideoTracks()[0];
198
+ if (!t || !this.canLockExposure) return !1;
199
+ try {
200
+ await t.applyConstraints({ advanced: [{ exposureMode: e ? "manual" : "continuous" }] });
201
+ } catch {
202
+ return !1;
203
+ }
204
+ return !0;
205
+ }
180
206
  async refreshDevices() {
181
207
  return this.refreshing ||= this.doRefreshDevices().finally(() => {
182
208
  this.refreshing = null;
@@ -189,7 +215,7 @@ var f = 1500, p = 2, m = 300, h = [
189
215
  this.tearingDown = !0, this.clearWatchdog(), this.stableTimer && clearTimeout(this.stableTimer), this.stableTimer = null;
190
216
  let e = this.stream;
191
217
  if (this.stream = null, e) for (let t of e.getTracks()) t.onended = null, t.onmute = null, t.onunmute = null, t.stop();
192
- this.video && (this.video.pause(), this.video.srcObject = null), this.zoomCapability = null, this.tearingDown = !1;
218
+ this.video && (this.video.pause(), this.video.srcObject = null), this.zoomCapability = null, this.torch = !1, this.torchCapability = !1, this.canLockExposure = !1, this.tearingDown = !1;
193
219
  }
194
220
  fail(e) {
195
221
  this.teardown(), this.error = e, this.setState("error");
@@ -337,6 +363,10 @@ var f = 1500, p = 2, m = 300, h = [
337
363
  step: t.step && t.step > 0 ? t.step : .1
338
364
  }, this.zoom = e.getSettings().zoom ?? t.min) : (this.zoomCapability = null, this.zoom = 1);
339
365
  }
366
+ readTorchCapability(e) {
367
+ let t = e.getCapabilities?.();
368
+ this.torchCapability = t?.torch === !0, this.torch = this.torchCapability ? e.getSettings().torch ?? !1 : !1, this.canLockExposure = Array.isArray(t?.exposureMode) && t.exposureMode.includes("manual");
369
+ }
340
370
  };
341
371
  function C(e) {
342
372
  return e instanceof Error ? e.message || e.name : "Camera could not be started";
@@ -38,11 +38,17 @@ declare global {
38
38
  max: number;
39
39
  step?: number;
40
40
  };
41
+ torch?: boolean;
42
+ exposureMode?: string[];
41
43
  }
42
44
  interface MediaTrackConstraintSet {
43
45
  zoom?: ConstrainDouble;
46
+ torch?: boolean;
47
+ exposureMode?: ConstrainDOMString;
44
48
  }
45
49
  interface MediaTrackSettings {
46
50
  zoom?: number;
51
+ torch?: boolean;
52
+ exposureMode?: string;
47
53
  }
48
54
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ablok-components",
3
3
  "private": false,
4
- "version": "0.3.134",
4
+ "version": "0.3.137",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "@tiptap/core": "^3.30.0",