@microblink/camera-manager 7.0.0-next.5 → 7.0.0-next.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microblink/camera-manager",
3
- "version": "7.0.0-next.5",
3
+ "version": "7.0.0-next.8",
4
4
  "author": "Microblink",
5
5
  "type": "module",
6
6
  "main": "./dist/camera-manager.js",
@@ -16,6 +16,9 @@
16
16
  "solid-zustand": "^1.8.1",
17
17
  "zustand": "^4.5.5"
18
18
  },
19
+ "dependencies": {
20
+ "type-fest": "^4.35.0"
21
+ },
19
22
  "access": "public",
20
23
  "registry": "https://registry.npmjs.org/",
21
24
  "types": "./types/index.rollup.d.ts",
@@ -0,0 +1,295 @@
1
+ import { SetStoreFunction } from 'solid-js/store';
2
+ import { StoreApi } from 'zustand/vanilla';
3
+
4
+ /**
5
+ * Represents a camera device and its active stream.
6
+ */
7
+ export declare class Camera {
8
+ #private;
9
+ deviceInfo: InputDeviceInfo;
10
+ /**
11
+ * Stream capabilities as reported by the stream.
12
+ *
13
+ * On iOS it's the same as `deviceCapabilities`. Firefox is only reporting
14
+ * rudimentary capabilities, so we can't rely on this for picking the right
15
+ * camera.
16
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getCapabilities
17
+ */
18
+ streamCapabilities?: ReturnType<MediaStreamTrack["getCapabilities"]>;
19
+ activeStream: MediaStream | undefined;
20
+ name: string;
21
+ facingMode: FacingMode;
22
+ torchSupported: boolean;
23
+ torchEnabled: boolean;
24
+ singleShotSupported: boolean;
25
+ original: this;
26
+ notify: (reason?: unknown) => void;
27
+ notifyStateChange?: (camera: Camera, reason?: unknown) => void;
28
+ constructor(deviceInfo: InputDeviceInfo);
29
+ startStream(resolution: VideoResolution): Promise<MediaStream>;
30
+ toggleTorch(): Promise<boolean>;
31
+ stopStream(): void;
32
+ getVideoTrack(): MediaStreamTrack | undefined;
33
+ }
34
+
35
+ export declare class CameraManager {
36
+ #private;
37
+ /**
38
+ * Sets the resolution of the camera stream
39
+ */
40
+ setResolution: (resolution: VideoResolution) => Promise<void>;
41
+ get resolution(): "HD" | "FHD" | "UHD";
42
+ /**
43
+ * True if there is a video playing or capturing
44
+ * TODO: see if we can simplify this, by observing the video playback state
45
+ */
46
+ get isActive(): boolean;
47
+ setFacingFilter(facingFilter: FacingMode[]): void;
48
+ /**
49
+ * Returns the cameras that are available to the user, filtered by the facing mode.
50
+ * If no facing mode is set, all cameras are returned.
51
+ */
52
+ getCameras(): Camera[];
53
+ /**
54
+ * Single-time setup for a video element
55
+ */
56
+ initVideoElement(videoElement: HTMLVideoElement): void;
57
+ /**
58
+ * Adds a callback that will be triggered on each frame when the playback state
59
+ * is "capturing".
60
+ *
61
+ * @param frameCaptureCallback
62
+ * @returns a cleanup function to remove the callback
63
+ */
64
+ addFrameCaptureCallback(frameCaptureCallback: FrameCaptureCallback): () => boolean;
65
+ deinitVideoElement(): void;
66
+ /**
67
+ * Select a camera device from available ones.
68
+ */
69
+ selectCamera(camera: Camera): Promise<void>;
70
+ /**
71
+ * Refreshes available devices on the system and updates the state.
72
+ */
73
+ refreshCameraDevices(): Promise<void>;
74
+ /**
75
+ * Starts the video playback
76
+ *
77
+ * @returns resolves when playback starts
78
+ */
79
+ startPlayback(): Promise<void>;
80
+ /**
81
+ * Starts playback and frame capturing.
82
+ */
83
+ startFrameCapture(): Promise<void>;
84
+ /**
85
+ * Starts a best-effort camera stream. Will pick a camera automatically if
86
+ * none is selected.
87
+ * TODO: Rename method
88
+ */
89
+ startCameraStream({ autoplay, preferredCamera, preferredFacing, }?: {
90
+ autoplay?: boolean;
91
+ } & CameraPreference): Promise<void>;
92
+ /**
93
+ * Pauses capturing frames without pausing playback.
94
+ */
95
+ stopFrameCapture(): void;
96
+ /**
97
+ * Stops the currently active stream. Also stops the video playback and capturing process.
98
+ */
99
+ stopStream(): void;
100
+ /**
101
+ * Pauses the video playback. This will also stop the capturing process.
102
+ */
103
+ pausePlayback(): void;
104
+ /**
105
+ * If true, the video and captured frames will be mirrored horizontally.
106
+ * TODO: apply when needed
107
+ */
108
+ setMirrorX(mirrorX: boolean): void;
109
+ /**
110
+ * Allows the user to subscribe to state changes inside the Camera Manager.
111
+ * Implemented using Zustand. For usage information, see
112
+ * {@link https://github.com/pmndrs/zustand#using-subscribe-with-selector}
113
+ */
114
+ subscribe: typeof cameraManagerStore.subscribe;
115
+ /**
116
+ * Gets the current internal state of the CameraManager.
117
+ */
118
+ getState: typeof cameraManagerStore.getState;
119
+ /**
120
+ * Resets the CameraManager and stop all streams
121
+ */
122
+ destroy(): void;
123
+ }
124
+
125
+ export declare type CameraManagerComponent = {
126
+ cameraManager: CameraManager;
127
+ /** Updates the localization strings */
128
+ updateLocalization: SetStoreFunction<CameraUiLocalizationStrings>;
129
+ /** Dismounts the component from the DOM and unloads the SDK */
130
+ dismount: () => void;
131
+ /** Sets a callback to be called when the component is unmounted */
132
+ addOnDismountCallback: (fn: DismountCallback) => void;
133
+ /** Removes a callback that was set with `addOnDismountCallback` */
134
+ removeOnDismountCallback: (fn: DismountCallback) => void;
135
+ /**
136
+ * The feedback layer node that can be used to append custom feedback elements
137
+ */
138
+ feedbackLayerNode: HTMLDivElement;
139
+ /**
140
+ * The overlay layer node that can be used to append custom overlay elements
141
+ */
142
+ overlayLayerNode: HTMLDivElement;
143
+ };
144
+
145
+ export declare type CameraManagerStore = {
146
+ /**
147
+ * The video element that will display the camera stream.
148
+ */
149
+ videoElement?: HTMLVideoElement;
150
+ /**
151
+ * The list of cameras that are available to the user.
152
+ */
153
+ cameras: Camera[];
154
+ /**
155
+ * The facing mode filter that will be used to filter the available cameras.
156
+ * Can be a single facing mode or an array of facing modes.
157
+ */
158
+ facingFilter?: FacingMode[];
159
+ /**
160
+ * The currently selected camera.
161
+ */
162
+ selectedCamera?: Camera;
163
+ /**
164
+ * Capturing / playing / idle
165
+ */
166
+ playbackState: PlaybackState;
167
+ /**
168
+ * Indicates if the camera is currently being swapped.
169
+ */
170
+ isSwappingCamera: boolean;
171
+ /**
172
+ * Indicates if camera list is currently being queried.
173
+ */
174
+ isQueryingCameras: boolean;
175
+ /**
176
+ * Indicates if the captured frames will be mirrored horizontally
177
+ */
178
+ mirrorX: boolean;
179
+ /**
180
+ * If the Camera manager has encountered an error, this will be set to the error.
181
+ */
182
+ errorState?: Error;
183
+ };
184
+
185
+ /**
186
+ * ⚠️ DANGER AHEAD ⚠️
187
+ *
188
+ * The Zustand store. Use only if you know what you're doing.
189
+ *
190
+ * Never set the state as this will break the application logic. We do not have
191
+ * two-way binding. Make sure you only observe the state.
192
+ *
193
+ * Prefer using subscriptions if you require observable state.
194
+ *
195
+ * {@link https://github.com/pmndrs/zustand}
196
+ */
197
+ export declare const cameraManagerStore: Omit<StoreApi<CameraManagerStore>, "subscribe"> & {
198
+ subscribe: {
199
+ (listener: (selectedState: CameraManagerStore, previousSelectedState: CameraManagerStore) => void): () => void;
200
+ <U>(selector: (state: CameraManagerStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
201
+ equalityFn?: ((a: U, b: U) => boolean) | undefined;
202
+ fireImmediately?: boolean;
203
+ } | undefined): () => void;
204
+ };
205
+ };
206
+
207
+ export declare type CameraPreference = {
208
+ preferredCamera: Camera;
209
+ preferredFacing?: never;
210
+ } | {
211
+ preferredFacing: FacingMode;
212
+ preferredCamera?: never;
213
+ } | {
214
+ preferredCamera?: never;
215
+ preferredFacing?: never;
216
+ };
217
+
218
+ export declare type CameraUiLocaleRecord = typeof _default;
219
+
220
+ export declare type CameraUiLocalizationStrings = {
221
+ [K in keyof CameraUiLocaleRecord]: CameraUiLocaleRecord[K] | (string & {});
222
+ };
223
+
224
+ /**
225
+ * Copyright (c) 2025 Microblink Ltd. All rights reserved.
226
+ */
227
+ export declare type CameraUiRefs = {
228
+ feedbackLayer: HTMLDivElement;
229
+ overlayLayer: HTMLDivElement;
230
+ };
231
+
232
+ export declare const cameraUiRefStore: Omit<StoreApi<CameraUiRefs>, "subscribe"> & {
233
+ subscribe: {
234
+ (listener: (selectedState: CameraUiRefs, previousSelectedState: CameraUiRefs) => void): () => void;
235
+ <U>(selector: (state: CameraUiRefs) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
236
+ equalityFn?: ((a: U, b: U) => boolean) | undefined;
237
+ fireImmediately?: boolean;
238
+ } | undefined): () => void;
239
+ };
240
+ };
241
+
242
+ /**
243
+ * Creates a new Camera Manager UI component.
244
+ */
245
+ export declare function createCameraManagerUi(cameraManager: CameraManager, target?: HTMLElement): Promise<CameraManagerComponent>;
246
+
247
+ /**
248
+ * Copyright (c) 2025 Microblink Ltd. All rights reserved.
249
+ */
250
+ declare const _default: {
251
+ readonly selected_camera: "Selected camera";
252
+ readonly select_camera: "Select camera";
253
+ readonly close: "Close";
254
+ readonly torch: "Torch";
255
+ readonly mirror_camera: "Mirror camera";
256
+ readonly modal_title: "Scan a document";
257
+ };
258
+
259
+ declare type DismountCallback = () => void;
260
+
261
+ export declare type FacingMode = "front" | "back" | undefined;
262
+
263
+ export declare type FrameCaptureCallback = (frame: ImageData) => void | Promise<void>;
264
+
265
+ export declare const MOUNT_POINT_ID = "camera-manager-mount-point";
266
+
267
+ export declare type PlaybackState = "idle" | "playback" | "capturing";
268
+
269
+ /**
270
+ * Resets the store to its initial state.
271
+ * Stops all camera streams as a side effect.
272
+ */
273
+ export declare const resetCameraManagerStore: () => void;
274
+
275
+ export declare type VideoResolution = keyof typeof videoResolutions;
276
+
277
+ /**
278
+ * Available video resolutions for the camera stream.
279
+ */
280
+ export declare const videoResolutions: {
281
+ HD: {
282
+ width: number;
283
+ height: number;
284
+ };
285
+ FHD: {
286
+ width: number;
287
+ height: number;
288
+ };
289
+ UHD: {
290
+ width: number;
291
+ height: number;
292
+ };
293
+ };
294
+
295
+ export { }