@microblink/camera-manager 7.2.4 → 7.2.5
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 +1 -1
- package/types/index.rollup.d.ts +711 -0
package/package.json
CHANGED
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
import { Owner } from 'solid-js';
|
|
2
|
+
import { Promisable } from 'type-fest';
|
|
3
|
+
import { SetStoreFunction } from 'solid-js/store';
|
|
4
|
+
import { StoreApi } from 'zustand/vanilla';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a camera device and its active stream.
|
|
8
|
+
*
|
|
9
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getCapabilities for more details.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Camera {
|
|
12
|
+
#private;
|
|
13
|
+
/**
|
|
14
|
+
* The device info.
|
|
15
|
+
*/
|
|
16
|
+
deviceInfo: InputDeviceInfo;
|
|
17
|
+
/**
|
|
18
|
+
* Stream capabilities as reported by the stream.
|
|
19
|
+
*
|
|
20
|
+
* On iOS it's the same as `deviceCapabilities`. Firefox is only reporting
|
|
21
|
+
* rudimentary capabilities, so we can't rely on this for picking the right
|
|
22
|
+
* camera.
|
|
23
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getCapabilities
|
|
24
|
+
*/
|
|
25
|
+
streamCapabilities?: ReturnType<MediaStreamTrack["getCapabilities"]>;
|
|
26
|
+
activeStream: MediaStream | undefined;
|
|
27
|
+
name: string;
|
|
28
|
+
facingMode: FacingMode;
|
|
29
|
+
torchSupported: boolean;
|
|
30
|
+
torchEnabled: boolean;
|
|
31
|
+
singleShotSupported: boolean;
|
|
32
|
+
maxSupportedResolution?: VideoResolutionName;
|
|
33
|
+
/**
|
|
34
|
+
* Reference to the original instance before it was proxied.
|
|
35
|
+
*/
|
|
36
|
+
original: this;
|
|
37
|
+
notify: (reason?: unknown) => void;
|
|
38
|
+
notifyStateChange?: (camera: Camera, reason?: unknown) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new Camera instance.
|
|
41
|
+
*
|
|
42
|
+
* @param deviceInfo - The device info.
|
|
43
|
+
*/
|
|
44
|
+
constructor(deviceInfo: InputDeviceInfo);
|
|
45
|
+
/**
|
|
46
|
+
* Starts a stream with the specified resolution.
|
|
47
|
+
*
|
|
48
|
+
* @param resolution - The resolution to start the stream with.
|
|
49
|
+
* @returns The stream.
|
|
50
|
+
*/
|
|
51
|
+
startStream(resolution: VideoResolutionName): Promise<MediaStream>;
|
|
52
|
+
/**
|
|
53
|
+
* Acquires a camera stream with the specified resolution.
|
|
54
|
+
* If acquisition fails, it tries a lower resolution as fallback.
|
|
55
|
+
*
|
|
56
|
+
* @param resolution - The resolution to acquire the stream with.
|
|
57
|
+
* @returns The stream.
|
|
58
|
+
*/
|
|
59
|
+
private acquireStreamWithFallback;
|
|
60
|
+
/**
|
|
61
|
+
* Populates the camera instance with capabilities from the stream.
|
|
62
|
+
*
|
|
63
|
+
* @param stream - The stream to populate the capabilities from.
|
|
64
|
+
*/
|
|
65
|
+
private populateCapabilities;
|
|
66
|
+
/**
|
|
67
|
+
* Toggles the torch on the camera.
|
|
68
|
+
*
|
|
69
|
+
* @returns The torch status.
|
|
70
|
+
*/
|
|
71
|
+
toggleTorch(): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Stops the stream on the camera.
|
|
74
|
+
*/
|
|
75
|
+
stopStream(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Gets the video track on the camera.
|
|
78
|
+
*
|
|
79
|
+
* @returns The video track.
|
|
80
|
+
*/
|
|
81
|
+
getVideoTrack(): MediaStreamTrack | undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A camera error.
|
|
86
|
+
*/
|
|
87
|
+
export declare class CameraError extends Error {
|
|
88
|
+
code: CameraErrorCode;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new camera error.
|
|
91
|
+
*
|
|
92
|
+
* @param message - The error message.
|
|
93
|
+
* @param code - The error code.
|
|
94
|
+
* @param cause - The cause of the error.
|
|
95
|
+
*/
|
|
96
|
+
constructor(message: string, code: CameraErrorCode, cause?: Error);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Copyright (c) 2025 Microblink Ltd. All rights reserved.
|
|
101
|
+
*/
|
|
102
|
+
/**
|
|
103
|
+
* A camera error code.
|
|
104
|
+
*/
|
|
105
|
+
export declare type CameraErrorCode = "PERMISSION_DENIED" | (string & {});
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A camera getter.
|
|
109
|
+
*
|
|
110
|
+
* @param cameras - The cameras to get.
|
|
111
|
+
* @returns The camera.
|
|
112
|
+
*/
|
|
113
|
+
declare type CameraGetter = (cameras: Camera[]) => Camera | undefined;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The CameraManager class.
|
|
117
|
+
*
|
|
118
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getCapabilities for more details.
|
|
119
|
+
*/
|
|
120
|
+
export declare class CameraManager {
|
|
121
|
+
#private;
|
|
122
|
+
/**
|
|
123
|
+
* If true, the user has initiated an abort. This will prevent the
|
|
124
|
+
* CameraManager from throwing errors when the user interrupts the process.
|
|
125
|
+
*/
|
|
126
|
+
get userInitiatedAbort(): boolean;
|
|
127
|
+
set userInitiatedAbort(value: boolean);
|
|
128
|
+
/**
|
|
129
|
+
* Sets the area of the video frame that will be extracted.
|
|
130
|
+
*
|
|
131
|
+
* @param extractionArea The area of the video frame that will be extracted.
|
|
132
|
+
*/
|
|
133
|
+
setExtractionArea(extractionArea: ExtractionArea): void;
|
|
134
|
+
/**
|
|
135
|
+
* Creates a new CameraManager instance.
|
|
136
|
+
*
|
|
137
|
+
* @param options - The options for the CameraManager.
|
|
138
|
+
* @param videoFrameProcessorOptions - The options for the VideoFrameProcessor.
|
|
139
|
+
*/
|
|
140
|
+
constructor(options?: Partial<CameraManagerOptions>, videoFrameProcessorOptions?: VideoFrameProcessorInitOptions);
|
|
141
|
+
/**
|
|
142
|
+
* Sets the desired video resolution for camera streams. This is used as the ideal resolution
|
|
143
|
+
* when starting camera streams. If a camera doesn't support the specified resolution,
|
|
144
|
+
* the camera will automatically fall back to the next lower supported resolution in this order:
|
|
145
|
+
* 4k → 1080p → 720p. If there's an active stream, it will be restarted with the new resolution.
|
|
146
|
+
*
|
|
147
|
+
* @param resolution - The ideal resolution to set for camera streams.
|
|
148
|
+
*/
|
|
149
|
+
setResolution: (resolution: VideoResolutionName) => Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* The desired video resolution for camera streams. This is used as the ideal resolution
|
|
152
|
+
* when starting camera streams. If a camera doesn't support the specified resolution,
|
|
153
|
+
* the camera will automatically fall back to the next lower supported resolution in this order:
|
|
154
|
+
* 4k → 1080p → 720p. The actual resolution used may differ from this setting based on
|
|
155
|
+
* camera capabilities and system constraints.
|
|
156
|
+
*/
|
|
157
|
+
get resolution(): "720p" | "1080p" | "4k";
|
|
158
|
+
/**
|
|
159
|
+
* True if there is a video playing or capturing
|
|
160
|
+
*
|
|
161
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaSession/playbackState for more details.
|
|
162
|
+
*/
|
|
163
|
+
get isActive(): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Sets the facing filter.
|
|
166
|
+
*
|
|
167
|
+
* @param facingFilter - The facing filter.
|
|
168
|
+
*/
|
|
169
|
+
setFacingFilter(facingFilter: FacingMode[]): void;
|
|
170
|
+
/**
|
|
171
|
+
* Returns the cameras that are available to the user, filtered by the facing mode.
|
|
172
|
+
* If no facing mode is set, all cameras are returned.
|
|
173
|
+
*
|
|
174
|
+
* @returns The cameras that are available to the user, filtered by the facing mode.
|
|
175
|
+
*/
|
|
176
|
+
getCameraDevices(): Promise<Camera[]>;
|
|
177
|
+
/**
|
|
178
|
+
* Initializes the CameraManager with a video element.
|
|
179
|
+
*
|
|
180
|
+
* @param videoElement - The video element to initialize.
|
|
181
|
+
*/
|
|
182
|
+
initVideoElement(videoElement: HTMLVideoElement): void;
|
|
183
|
+
/**
|
|
184
|
+
* Adds a callback that will be triggered on each frame when the playback state
|
|
185
|
+
* is "capturing".
|
|
186
|
+
*
|
|
187
|
+
* @param frameCaptureCallback - The callback to add.
|
|
188
|
+
* @returns a cleanup function to remove the callback
|
|
189
|
+
*/
|
|
190
|
+
addFrameCaptureCallback(frameCaptureCallback: FrameCaptureCallback): () => boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Cleans up the video element, and stops the stream.
|
|
193
|
+
*/
|
|
194
|
+
releaseVideoElement(): void;
|
|
195
|
+
/**
|
|
196
|
+
* Select a camera device from available ones.
|
|
197
|
+
*
|
|
198
|
+
* @param camera - The camera to select.
|
|
199
|
+
*/
|
|
200
|
+
selectCamera(camera: Camera): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Refreshes available devices on the system and updates the state.
|
|
203
|
+
*
|
|
204
|
+
* @returns resolves when the camera devices are refreshed
|
|
205
|
+
*/
|
|
206
|
+
refreshCameraDevices(): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Starts the video playback
|
|
209
|
+
*
|
|
210
|
+
* @returns resolves when playback starts
|
|
211
|
+
*/
|
|
212
|
+
startPlayback(): Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Starts capturing frames from the video element.
|
|
215
|
+
*
|
|
216
|
+
* @returns resolves when frame capture starts
|
|
217
|
+
*/
|
|
218
|
+
startFrameCapture: () => Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Starts a best-effort camera stream. Will pick a camera automatically if
|
|
221
|
+
* none is selected.
|
|
222
|
+
*
|
|
223
|
+
* @param params - The parameters for the camera stream.
|
|
224
|
+
* @returns resolves when the camera stream starts
|
|
225
|
+
*/
|
|
226
|
+
startCameraStream(params?: StartCameraStreamOptions): Promise<void>;
|
|
227
|
+
/**
|
|
228
|
+
* Pauses capturing frames, without stopping playback.
|
|
229
|
+
*/
|
|
230
|
+
stopFrameCapture(): void;
|
|
231
|
+
/**
|
|
232
|
+
* Stops the currently active stream. Also stops the video playback and capturing process.
|
|
233
|
+
*/
|
|
234
|
+
stopStream(): void;
|
|
235
|
+
/**
|
|
236
|
+
* Pauses the video playback. This will also stop the capturing process.
|
|
237
|
+
*/
|
|
238
|
+
pausePlayback(): void;
|
|
239
|
+
/**
|
|
240
|
+
* If true, the video and captured frames will be mirrored horizontally.
|
|
241
|
+
*
|
|
242
|
+
* @param mirrorX - If true, the video and captured frames will be mirrored horizontally.
|
|
243
|
+
*/
|
|
244
|
+
setCameraMirrorX(mirrorX: boolean): void;
|
|
245
|
+
/**
|
|
246
|
+
* Allows the user to subscribe to state changes inside the Camera Manager.
|
|
247
|
+
* Implemented using Zustand. For usage information, see
|
|
248
|
+
* @see https://github.com/pmndrs/zustand#using-subscribe-with-selector for more details.
|
|
249
|
+
*
|
|
250
|
+
* @returns a cleanup function to remove the subscription
|
|
251
|
+
*/
|
|
252
|
+
subscribe: typeof cameraManagerStore.subscribe;
|
|
253
|
+
/**
|
|
254
|
+
* Gets the current internal state of the CameraManager.
|
|
255
|
+
*
|
|
256
|
+
* @returns the current state of the CameraManager
|
|
257
|
+
*/
|
|
258
|
+
getState: typeof cameraManagerStore.getState;
|
|
259
|
+
/**
|
|
260
|
+
* Resets the CameraManager and stops all streams.
|
|
261
|
+
*/
|
|
262
|
+
reset(): void;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* The camera manager component.
|
|
267
|
+
*/
|
|
268
|
+
export declare type CameraManagerComponent = {
|
|
269
|
+
/** The camera manager. */
|
|
270
|
+
cameraManager: CameraManager;
|
|
271
|
+
/** Updates the localization strings */
|
|
272
|
+
updateLocalization: SetStoreFunction<CameraUiLocalizationStrings>;
|
|
273
|
+
/** Dismounts the component from the DOM and unloads the SDK */
|
|
274
|
+
dismount: () => void;
|
|
275
|
+
/**
|
|
276
|
+
* Sets a callback to be called when the component is unmounted.
|
|
277
|
+
* Returns a cleanup function that removes the callback when called.
|
|
278
|
+
*/
|
|
279
|
+
addOnDismountCallback: (fn: DismountCallback) => () => void;
|
|
280
|
+
/**
|
|
281
|
+
* The feedback layer node that can be used to append custom feedback elements
|
|
282
|
+
*/
|
|
283
|
+
feedbackLayerNode: HTMLDivElement;
|
|
284
|
+
/**
|
|
285
|
+
* The overlay layer node that can be used to append custom overlay elements
|
|
286
|
+
*/
|
|
287
|
+
overlayLayerNode: HTMLDivElement;
|
|
288
|
+
/**
|
|
289
|
+
* The owner of the component.
|
|
290
|
+
*
|
|
291
|
+
* @see https://docs.solidjs.com/reference/reactive-utilities/get-owner
|
|
292
|
+
*/
|
|
293
|
+
owner: Owner;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Options for the CameraManager.
|
|
298
|
+
*
|
|
299
|
+
* @param mirrorFrontCameras - If true, front-facing cameras will be mirrored horizontally when started.
|
|
300
|
+
* @param preferredResolution - The desired video resolution for camera streams. This is used as the ideal resolution when starting camera streams. If a camera doesn't support the specified resolution, the camera will automatically fall back to the next lower supported resolution in this order: 4k → 1080p → 720p.
|
|
301
|
+
*/
|
|
302
|
+
export declare type CameraManagerOptions = {
|
|
303
|
+
/** If true, the camera stream will be mirrored horizontally when started. */
|
|
304
|
+
mirrorFrontCameras: boolean;
|
|
305
|
+
/**
|
|
306
|
+
* The desired video resolution for camera streams. This is used as the ideal resolution
|
|
307
|
+
* when starting camera streams. If a camera doesn't support the specified resolution,
|
|
308
|
+
* the camera will automatically fall back to the next lower supported resolution in this order:
|
|
309
|
+
* 4k → 1080p → 720p. The actual resolution used may differ from this setting based on
|
|
310
|
+
* camera capabilities and system constraints.
|
|
311
|
+
*/
|
|
312
|
+
preferredResolution: VideoResolutionName;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The camera manager store.
|
|
317
|
+
*/
|
|
318
|
+
export declare type CameraManagerStore = {
|
|
319
|
+
/**
|
|
320
|
+
* The video element that will display the camera stream.
|
|
321
|
+
*/
|
|
322
|
+
videoElement?: HTMLVideoElement;
|
|
323
|
+
/**
|
|
324
|
+
* The list of cameras that are available to the user.
|
|
325
|
+
*/
|
|
326
|
+
cameras: Camera[];
|
|
327
|
+
/**
|
|
328
|
+
* The facing mode filter that will be used to filter the available cameras.
|
|
329
|
+
* Can be a single facing mode or an array of facing modes.
|
|
330
|
+
*/
|
|
331
|
+
facingFilter?: FacingMode[];
|
|
332
|
+
/**
|
|
333
|
+
* The currently selected camera.
|
|
334
|
+
*/
|
|
335
|
+
selectedCamera?: Camera;
|
|
336
|
+
/**
|
|
337
|
+
* Capturing / playing / idle.
|
|
338
|
+
*/
|
|
339
|
+
playbackState: PlaybackState;
|
|
340
|
+
/**
|
|
341
|
+
* Indicates if the camera is currently being swapped.
|
|
342
|
+
*/
|
|
343
|
+
isSwappingCamera: boolean;
|
|
344
|
+
/**
|
|
345
|
+
* Indicates if camera list is currently being queried.
|
|
346
|
+
*/
|
|
347
|
+
isQueryingCameras: boolean;
|
|
348
|
+
/**
|
|
349
|
+
* Indicates if the captured frames will be mirrored horizontally
|
|
350
|
+
*/
|
|
351
|
+
mirrorX: boolean;
|
|
352
|
+
/**
|
|
353
|
+
* If the Camera manager has encountered an error, this will be set to the error.
|
|
354
|
+
*/
|
|
355
|
+
errorState?: Error | CameraError;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* ⚠️ DANGER AHEAD ⚠️
|
|
360
|
+
*
|
|
361
|
+
* The Zustand store. Use only if you know what you're doing.
|
|
362
|
+
*
|
|
363
|
+
* Never set the state as this will break the application logic. We do not have
|
|
364
|
+
* two-way binding. Make sure you only observe the state.
|
|
365
|
+
*
|
|
366
|
+
* Prefer using subscriptions if you require observable state.
|
|
367
|
+
*
|
|
368
|
+
* @see https://github.com/pmndrs/zustand for more details.
|
|
369
|
+
*/
|
|
370
|
+
export declare const cameraManagerStore: Omit<StoreApi<CameraManagerStore>, "subscribe"> & {
|
|
371
|
+
subscribe: {
|
|
372
|
+
(listener: (selectedState: CameraManagerStore, previousSelectedState: CameraManagerStore) => void): () => void;
|
|
373
|
+
<U>(selector: (state: CameraManagerStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
|
|
374
|
+
equalityFn?: ((a: U, b: U) => boolean) | undefined;
|
|
375
|
+
fireImmediately?: boolean;
|
|
376
|
+
} | undefined): () => void;
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* The camera manager UI options.
|
|
382
|
+
*/
|
|
383
|
+
export declare type CameraManagerUiOptions = {
|
|
384
|
+
/**
|
|
385
|
+
* The localization strings.
|
|
386
|
+
*/
|
|
387
|
+
localizationStrings?: Partial<CameraUiLocalizationStrings>;
|
|
388
|
+
/**
|
|
389
|
+
* If set to `true`, the mirror camera button will be shown.
|
|
390
|
+
*
|
|
391
|
+
* @defaultValue false
|
|
392
|
+
*/
|
|
393
|
+
showMirrorCameraButton?: boolean;
|
|
394
|
+
/**
|
|
395
|
+
* If set to `true`, the torch button will be shown.
|
|
396
|
+
*
|
|
397
|
+
* @defaultValue true
|
|
398
|
+
*/
|
|
399
|
+
showTorchButton?: boolean;
|
|
400
|
+
/**
|
|
401
|
+
* If set to `true`, the close button will be shown.
|
|
402
|
+
*
|
|
403
|
+
* @defaultValue true
|
|
404
|
+
*/
|
|
405
|
+
showCloseButton?: boolean;
|
|
406
|
+
/**
|
|
407
|
+
* If set to `true`, the camera error modal will be shown.
|
|
408
|
+
*
|
|
409
|
+
* @defaultValue true
|
|
410
|
+
*/
|
|
411
|
+
showCameraErrorModal?: boolean;
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* A camera preference.
|
|
416
|
+
*
|
|
417
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/facingMode for facing mode details.
|
|
418
|
+
*/
|
|
419
|
+
export declare type CameraPreference = {
|
|
420
|
+
preferredCamera: Camera | undefined;
|
|
421
|
+
preferredFacing?: undefined;
|
|
422
|
+
} | {
|
|
423
|
+
preferredCamera: CameraGetter | undefined;
|
|
424
|
+
preferredFacing?: undefined;
|
|
425
|
+
} | {
|
|
426
|
+
preferredFacing: FacingMode;
|
|
427
|
+
preferredCamera?: undefined;
|
|
428
|
+
} | {
|
|
429
|
+
preferredCamera?: undefined;
|
|
430
|
+
preferredFacing?: undefined;
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* The camera UI locale record.
|
|
435
|
+
*/
|
|
436
|
+
export declare type CameraUiLocaleRecord = typeof _default;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* The camera UI localization strings.
|
|
440
|
+
*/
|
|
441
|
+
export declare type CameraUiLocalizationStrings = {
|
|
442
|
+
[K in keyof CameraUiLocaleRecord]: CameraUiLocaleRecord[K] | (string & {});
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* The camera UI refs.
|
|
447
|
+
*/
|
|
448
|
+
export declare type CameraUiRefs = {
|
|
449
|
+
/** The feedback layer. */
|
|
450
|
+
feedbackLayer: HTMLDivElement;
|
|
451
|
+
/** The overlay layer. */
|
|
452
|
+
overlayLayer: HTMLDivElement;
|
|
453
|
+
/** The owner of the component. */
|
|
454
|
+
owner: Owner;
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* The camera UI ref store.
|
|
459
|
+
*/
|
|
460
|
+
export declare const cameraUiRefStore: Omit<StoreApi<CameraUiRefs>, "subscribe"> & {
|
|
461
|
+
subscribe: {
|
|
462
|
+
(listener: (selectedState: CameraUiRefs, previousSelectedState: CameraUiRefs) => void): () => void;
|
|
463
|
+
<U>(selector: (state: CameraUiRefs) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
|
|
464
|
+
equalityFn?: ((a: U, b: U) => boolean) | undefined;
|
|
465
|
+
fireImmediately?: boolean;
|
|
466
|
+
} | undefined): () => void;
|
|
467
|
+
};
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Copyright (c) 2025 Microblink Ltd. All rights reserved.
|
|
472
|
+
*/
|
|
473
|
+
export declare type CanvasRenderingMode = "2d" | "webgl2";
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Creates a new Camera Manager UI component.
|
|
477
|
+
*
|
|
478
|
+
* @param cameraManager - The camera manager.
|
|
479
|
+
* @param target - The target element to mount the component to.
|
|
480
|
+
* @param options - The options for the camera manager UI.
|
|
481
|
+
* @returns The camera manager UI component.
|
|
482
|
+
*/
|
|
483
|
+
export declare function createCameraManagerUi(cameraManager: CameraManager, target?: HTMLElement, { localizationStrings, showMirrorCameraButton, showTorchButton, showCloseButton, showCameraErrorModal, }?: CameraManagerUiOptions): Promise<CameraManagerComponent>;
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* The default English localization strings.
|
|
487
|
+
*/
|
|
488
|
+
declare const _default: {
|
|
489
|
+
readonly selected_camera: "Selected camera";
|
|
490
|
+
readonly loading_cameras: "Loading cameras...";
|
|
491
|
+
readonly select_a_camera: "Select a camera";
|
|
492
|
+
readonly select_camera: "Select camera";
|
|
493
|
+
readonly close: "Close";
|
|
494
|
+
readonly torch: "Torch";
|
|
495
|
+
readonly mirror_camera: "Mirror camera";
|
|
496
|
+
readonly scan_document: "Scan a document";
|
|
497
|
+
readonly camera_error_title: "Camera permission required";
|
|
498
|
+
readonly camera_error_details: "Please allow camera access in your browser and try again.";
|
|
499
|
+
readonly camera_error_cancel_btn: "Cancel";
|
|
500
|
+
readonly camera_error_primary_btn: "Retry";
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Default options for the CameraManager.
|
|
505
|
+
*/
|
|
506
|
+
export declare const defaultCameraManagerOptions: CameraManagerOptions;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* A dismount callback.
|
|
510
|
+
*/
|
|
511
|
+
export declare type DismountCallback = () => void;
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* The extraction area.
|
|
515
|
+
*/
|
|
516
|
+
export declare type ExtractionArea = {
|
|
517
|
+
x: number;
|
|
518
|
+
y: number;
|
|
519
|
+
width: number;
|
|
520
|
+
height: number;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Copyright (c) 2025 Microblink Ltd. All rights reserved.
|
|
525
|
+
*/
|
|
526
|
+
export declare type FacingMode = "front" | "back" | undefined;
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Finds the closest resolution key to the given resolution.
|
|
530
|
+
*
|
|
531
|
+
* @param videoTrackResolution - The resolution to find the closest key for.
|
|
532
|
+
* @returns The closest resolution key.
|
|
533
|
+
*/
|
|
534
|
+
export declare function findResolutionKey(videoTrackResolution: Resolution): VideoResolutionName;
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* A callback that will be triggered on each frame when the playback state is
|
|
538
|
+
* "capturing".
|
|
539
|
+
*
|
|
540
|
+
* @param frame - The frame to capture.
|
|
541
|
+
* @returns The frame.
|
|
542
|
+
*/
|
|
543
|
+
export declare type FrameCaptureCallback = (frame: ImageData) => Promisable<ArrayBufferLike | void>;
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Converts a view to a buffer, since both match the type signature of
|
|
547
|
+
* `ArrayBufferLike`.
|
|
548
|
+
*
|
|
549
|
+
* @param buffer - The buffer or view to convert
|
|
550
|
+
* @returns The actual underlying buffer
|
|
551
|
+
*/
|
|
552
|
+
export declare const getBuffer: (buffer: ArrayBufferLike) => ArrayBufferLike;
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Normalizes a resolution to the longer side.
|
|
556
|
+
*
|
|
557
|
+
* @param resolution - The resolution to normalize.
|
|
558
|
+
* @returns The normalized resolution.
|
|
559
|
+
*/
|
|
560
|
+
export declare function getNormalizedResolution(resolution: Resolution): Resolution;
|
|
561
|
+
|
|
562
|
+
export declare type ImageSource = HTMLVideoElement | HTMLCanvasElement | ImageBitmap;
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Check if an ArrayBuffer is detached
|
|
566
|
+
* @param buffer - ArrayBuffer to check
|
|
567
|
+
* @returns true if the buffer is detached, false otherwise
|
|
568
|
+
*/
|
|
569
|
+
export declare function isBufferDetached(buffer: ArrayBuffer): boolean;
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Matches the closest resolution to the given resolution.
|
|
573
|
+
*
|
|
574
|
+
* @param resolution - The resolution to match.
|
|
575
|
+
* @returns The closest resolution.
|
|
576
|
+
*/
|
|
577
|
+
export declare function matchClosestResolution(resolution: Resolution): VideoResolutionName;
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* The default mount point ID.
|
|
581
|
+
*/
|
|
582
|
+
export declare const MOUNT_POINT_ID = "camera-manager-mount-point";
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* The playback state of the camera manager.
|
|
586
|
+
*/
|
|
587
|
+
export declare type PlaybackState = "idle" | "playback" | "capturing";
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Resets the store to its initial state.
|
|
591
|
+
*
|
|
592
|
+
* Stops all camera streams as a side effect.
|
|
593
|
+
*/
|
|
594
|
+
export declare const resetCameraManagerStore: () => void;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Represents a video resolution.
|
|
598
|
+
*
|
|
599
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/width for width details.
|
|
600
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/height for height details.
|
|
601
|
+
*/
|
|
602
|
+
export declare type Resolution = {
|
|
603
|
+
width: number;
|
|
604
|
+
height: number;
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Returns the longer side of a resolution.
|
|
609
|
+
*
|
|
610
|
+
* @param resolution - The resolution to get the longer side of.
|
|
611
|
+
* @returns The longer side of the resolution.
|
|
612
|
+
*/
|
|
613
|
+
export declare function returnLongerSide(resolution: Resolution): number;
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Options for starting a camera stream.
|
|
617
|
+
*
|
|
618
|
+
* @param autoplay - If true, the camera stream will be started automatically.
|
|
619
|
+
* @param preferredCamera - The camera to start the stream with.
|
|
620
|
+
* @param preferredFacing - The facing mode to start the stream with.
|
|
621
|
+
*/
|
|
622
|
+
export declare type StartCameraStreamOptions = {
|
|
623
|
+
autoplay?: boolean;
|
|
624
|
+
} & CameraPreference;
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* VideoFrameProcessor captures frames from video or image sources using either 2D or WebGL2 rendering
|
|
628
|
+
*/
|
|
629
|
+
export declare class VideoFrameProcessor {
|
|
630
|
+
#private;
|
|
631
|
+
/**
|
|
632
|
+
* Creates a new VideoFrameProcessor.
|
|
633
|
+
*
|
|
634
|
+
* @param options - The options for the VideoFrameProcessor.
|
|
635
|
+
*/
|
|
636
|
+
constructor(options?: VideoFrameProcessorInitOptions);
|
|
637
|
+
/**
|
|
638
|
+
* Returns ownership of an ArrayBuffer to the processor for reuse.
|
|
639
|
+
*
|
|
640
|
+
* This should only be called with ArrayBuffers that were originally from this processor.
|
|
641
|
+
* Typically used after transferring the buffer to/from a worker.
|
|
642
|
+
*
|
|
643
|
+
* @param arrayBuffer - The array buffer to reattach.
|
|
644
|
+
*/
|
|
645
|
+
reattachArrayBuffer(arrayBuffer: ArrayBufferLike): void;
|
|
646
|
+
/**
|
|
647
|
+
* Used to check if the processor owns the buffer.
|
|
648
|
+
*
|
|
649
|
+
* @returns true if the processor owns the buffer, false otherwise.
|
|
650
|
+
*/
|
|
651
|
+
isBufferDetached(): boolean;
|
|
652
|
+
/**
|
|
653
|
+
* Extracts image data from a source element.
|
|
654
|
+
*
|
|
655
|
+
* @param source - The source element to extract image data from.
|
|
656
|
+
* @param area - The extraction area.
|
|
657
|
+
* @returns The image data.
|
|
658
|
+
*/
|
|
659
|
+
getImageData(source: ImageSource, area?: ExtractionArea): ImageData;
|
|
660
|
+
/**
|
|
661
|
+
* Used to get the current ImageData object with the current buffer. Useful
|
|
662
|
+
* when you need to get the same `ImageData` object multiple times after the
|
|
663
|
+
* original `ImageData` buffer has been detached
|
|
664
|
+
*
|
|
665
|
+
* @returns ImageData object with the current buffer
|
|
666
|
+
*/
|
|
667
|
+
getCurrentImageData(): ImageData;
|
|
668
|
+
/**
|
|
669
|
+
* Clean up resources.
|
|
670
|
+
*/
|
|
671
|
+
dispose(): void;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Options for the VideoFrameProcessor.
|
|
676
|
+
*/
|
|
677
|
+
export declare type VideoFrameProcessorInitOptions = {
|
|
678
|
+
canvasRenderingMode?: CanvasRenderingMode;
|
|
679
|
+
fallbackWebGlTo2d?: boolean;
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Represents a video resolution name.
|
|
684
|
+
*
|
|
685
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/width for width details.
|
|
686
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/height for height details.
|
|
687
|
+
*/
|
|
688
|
+
export declare type VideoResolutionName = keyof typeof videoResolutions;
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Available video resolutions for the camera stream.
|
|
692
|
+
*
|
|
693
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/width for width details.
|
|
694
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/height for height details.
|
|
695
|
+
*/
|
|
696
|
+
export declare const videoResolutions: {
|
|
697
|
+
readonly "720p": {
|
|
698
|
+
readonly width: 1280;
|
|
699
|
+
readonly height: 720;
|
|
700
|
+
};
|
|
701
|
+
readonly "1080p": {
|
|
702
|
+
readonly width: 1920;
|
|
703
|
+
readonly height: 1080;
|
|
704
|
+
};
|
|
705
|
+
readonly "4k": {
|
|
706
|
+
readonly width: 3840;
|
|
707
|
+
readonly height: 2160;
|
|
708
|
+
};
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
export { }
|