@incodetech/core 0.0.0-dev-20260126-4504c5b

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.
@@ -0,0 +1,344 @@
1
+ import { s as WasmPipeline } from "./types-CMR6NkxW.js";
2
+
3
+ //#region ../infra/src/media/canvas.d.ts
4
+ /**
5
+ * Class representing a canvas element for image capture and manipulation.
6
+ */
7
+ declare class IncodeCanvas {
8
+ canvas: HTMLCanvasElement;
9
+ private base64Image;
10
+ private blobData;
11
+ /**
12
+ * Creates an {@link IncodeCanvas} from a raw {@link ImageData} frame.
13
+ * @param imageData - Frame pixels in RGBA format
14
+ * @returns An {@link IncodeCanvas} containing the provided pixels
15
+ */
16
+ static fromImageData(imageData: ImageData): IncodeCanvas;
17
+ /**
18
+ * Create a new canvas element.
19
+ * @param canvas_ - The canvas element to clone.
20
+ */
21
+ constructor(canvas_: HTMLCanvasElement);
22
+ /**
23
+ * Check if the current canvas is valid.
24
+ */
25
+ private checkCanvas;
26
+ /**
27
+ * Disposes of resources, including revoking object URLs to prevent memory leaks.
28
+ */
29
+ dispose(): void;
30
+ /**
31
+ * Release the data stored by IncodeCanvas.
32
+ */
33
+ release(): void;
34
+ /**
35
+ * Revokes the object URL if one exists, preventing memory leaks.
36
+ * Use this when you no longer need the preview image URL.
37
+ */
38
+ revokeObjectURL(): void;
39
+ /**
40
+ * Get the width of the canvas.
41
+ */
42
+ width(): number | null;
43
+ /**
44
+ * Get the height of the canvas.
45
+ */
46
+ height(): number | null;
47
+ /**
48
+ * Set the width of the canvas.
49
+ */
50
+ setWidth(width: number): void;
51
+ /**
52
+ * Set the height of the canvas.
53
+ */
54
+ setHeight(height: number): void;
55
+ /**
56
+ * Clone the current canvas.
57
+ */
58
+ clone(): IncodeCanvas | null;
59
+ /**
60
+ * Deep clone the current IncodeCanvas including blob data.
61
+ */
62
+ deepClone(): Promise<IncodeCanvas | null>;
63
+ /**
64
+ * Returns the drawing context on the canvas.
65
+ */
66
+ getContext(contextId: '2d', contextAttributes?: CanvasRenderingContext2DSettings): CanvasRenderingContext2D | null;
67
+ /**
68
+ * Retrieves the image data from the canvas.
69
+ */
70
+ getImageData(): ImageData | null;
71
+ /**
72
+ * Updates the base64 representation of the current canvas image.
73
+ */
74
+ updateBase64Image(jpegQuality?: number): void;
75
+ /**
76
+ * Converts the current canvas element to a base64 string.
77
+ */
78
+ getBase64Image(jpegQuality?: number, includeDataURLPrefix?: boolean): string | null;
79
+ /**
80
+ * Sets the base64 representation of the current canvas image.
81
+ */
82
+ setBase64Image(base64Image: string | null): void;
83
+ /**
84
+ * Updates the Blob representation of the current canvas image.
85
+ */
86
+ updateBlob(jpegQuality?: number, includeDataURLPrefix?: boolean): void;
87
+ /**
88
+ * Converts a base64 string to a Blob and creates a URL for it.
89
+ */
90
+ static base64ToBlob(base64: string): {
91
+ blob: Blob;
92
+ url: string;
93
+ } | null;
94
+ /**
95
+ * Retrieves the Blob data and its URL from the current canvas.
96
+ */
97
+ getBlobData(jpegQuality?: number, includeDataURLPrefix?: boolean): {
98
+ blob: Blob;
99
+ url: string;
100
+ } | null;
101
+ /**
102
+ * Sets the Blob data of the current canvas image.
103
+ */
104
+ setBlobData(blobData: {
105
+ blob: Blob;
106
+ url: string;
107
+ }): Promise<void>;
108
+ /**
109
+ * Returns a resized canvas according to video element size.
110
+ */
111
+ getResizedCanvas(videoElementWidth: number, videoElementHeight: number): IncodeCanvas | null;
112
+ }
113
+ //#endregion
114
+ //#region ../infra/src/capabilities/IMLProviderCapability.d.ts
115
+ /**
116
+ * Base configuration shared by all ML provider capabilities.
117
+ */
118
+ interface MLProviderConfig {
119
+ /** Path to the WASM binary */
120
+ wasmPath?: string;
121
+ /** Path to the SIMD-optimized WASM binary (optional) */
122
+ wasmSimdPath?: string;
123
+ /** Path to the WASM glue code */
124
+ glueCodePath?: string;
125
+ /** Whether to use SIMD optimizations (default: true) */
126
+ useSimd?: boolean;
127
+ /**
128
+ * Base path for ML model files. Models will be loaded from `${modelsBasePath}/${modelFileName}`.
129
+ * If not provided, models are expected in a 'models' subdirectory relative to the WASM binary.
130
+ */
131
+ modelsBasePath?: string;
132
+ }
133
+ /**
134
+ * Base interface for ML provider capabilities.
135
+ * Provides common lifecycle and frame processing methods shared by
136
+ * FaceDetectionCapability and IdCaptureCapability.
137
+ */
138
+ interface IMLProviderCapability<TConfig extends MLProviderConfig> {
139
+ /**
140
+ * Whether the provider has been initialized and is ready to process frames.
141
+ */
142
+ readonly initialized: boolean;
143
+ /**
144
+ * Initializes the provider with the given configuration.
145
+ * If WASM was already warmed up via `setup()` or `warmupWasm()`, this returns almost instantly.
146
+ * @param config - Provider configuration including WASM paths
147
+ */
148
+ initialize(config: TConfig): Promise<void>;
149
+ /**
150
+ * Processes a frame through the ML pipeline.
151
+ * Callbacks set via `setCallbacks()` will be invoked based on the analysis results.
152
+ * @param image - Image data to process
153
+ * @throws Error if provider is not initialized
154
+ */
155
+ processFrame(image: ImageData): Promise<void>;
156
+ /**
157
+ * Resets the pipeline to its initial state.
158
+ * Safe to call even if not initialized (no-op in that case).
159
+ */
160
+ reset(): void;
161
+ /**
162
+ * Disposes of resources and resets initialization state.
163
+ * Safe to call even if not initialized.
164
+ */
165
+ dispose(): Promise<void>;
166
+ }
167
+ //#endregion
168
+ //#region ../infra/src/capabilities/IMotionSensorCapability.d.ts
169
+ type MotionStatus = 'PASS' | 'FAIL' | 'UNCLEAR';
170
+ type MotionPermissionState = 'granted' | 'denied' | 'not-required';
171
+ type IMotionSensorCapability = {
172
+ requestPermission(): Promise<MotionPermissionState>;
173
+ start(): Promise<void>;
174
+ stop(): void;
175
+ check(): MotionStatus;
176
+ readonly isRunning: boolean;
177
+ readonly hasPermission: boolean;
178
+ };
179
+ //#endregion
180
+ //#region ../infra/src/capabilities/IRecordingCapability.d.ts
181
+ type RecordingPublisher = {
182
+ getStreamId: () => string | undefined;
183
+ replaceVideoTrack: (track: MediaStreamTrack) => Promise<void>;
184
+ destroy: () => void;
185
+ };
186
+ type RecordingConnection = {
187
+ sessionId: string | undefined;
188
+ publisher: RecordingPublisher;
189
+ disconnect: () => Promise<void>;
190
+ };
191
+ type RecordingConnectionEvents = {
192
+ onSessionConnected?: (sessionId: string | undefined) => void;
193
+ onSessionDisconnected?: (sessionId: string | undefined) => void;
194
+ onSessionException?: (params: {
195
+ name?: string;
196
+ message?: string;
197
+ sessionId?: string;
198
+ }) => void;
199
+ onPublisherCreated?: (params: {
200
+ streamId?: string;
201
+ sessionId?: string;
202
+ }) => void;
203
+ onPublisherError?: (params: {
204
+ message?: string;
205
+ sessionId?: string;
206
+ streamId?: string;
207
+ }) => void;
208
+ };
209
+ type ConnectRecordingParams = {
210
+ sessionToken: string;
211
+ stream: MediaStream;
212
+ events?: RecordingConnectionEvents;
213
+ };
214
+ type IRecordingCapability = {
215
+ /**
216
+ * Connects to a recording session and publishes the provided media stream.
217
+ * Returns a connection handle that can be disconnected and used to manage the publisher.
218
+ */
219
+ connect: (params: ConnectRecordingParams) => Promise<RecordingConnection>;
220
+ };
221
+ //#endregion
222
+ //#region ../infra/src/media/camera.d.ts
223
+ type CameraStream = MediaStream;
224
+ //#endregion
225
+ //#region ../infra/src/media/StreamCanvasCapture.d.ts
226
+ type StreamCanvasCaptureOptions = {
227
+ fps?: number;
228
+ width?: number;
229
+ height?: number;
230
+ };
231
+ type StreamCanvasCaptureEventMap = {
232
+ frame: Event;
233
+ };
234
+ declare class StreamCanvasCapture {
235
+ private video;
236
+ private canvas;
237
+ private ctx;
238
+ private rafId;
239
+ private lastFrameTimeSeconds;
240
+ private lastTickTimeMs;
241
+ private hasFrame;
242
+ private disposed;
243
+ private eventTarget;
244
+ constructor(stream: CameraStream, options?: StreamCanvasCaptureOptions);
245
+ addEventListener(type: keyof StreamCanvasCaptureEventMap, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
246
+ removeEventListener(type: keyof StreamCanvasCaptureEventMap, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;
247
+ /**
248
+ * Returns the latest cached frame as an {@link IncodeCanvas}.
249
+ */
250
+ getLatestCanvas(): IncodeCanvas | null;
251
+ /**
252
+ * Returns the latest cached frame as raw {@link ImageData}.
253
+ */
254
+ getLatestFrame(): ImageData | null;
255
+ /**
256
+ * Disposes internal resources and stops the capture loop.
257
+ */
258
+ dispose(): void;
259
+ private rafLoop;
260
+ private tick;
261
+ }
262
+ //#endregion
263
+ //#region ../infra/src/wasm/WasmPipelineType.d.ts
264
+ declare enum WasmPipelineType {
265
+ IdBlurGlarePipeline = 0,
266
+ IdBarcodeAndTextQualityPipeline = 1,
267
+ IdVideoSelfiePipeline = 2,
268
+ SelfieWithAggregationMetrics = 3,
269
+ SelfieWithQualityMetrics = 4,
270
+ IdFaceDetectionPipeline = 5,
271
+ }
272
+ //#endregion
273
+ //#region ../infra/src/providers/wasm/BaseWasmProvider.d.ts
274
+ /**
275
+ * Base configuration for WASM providers
276
+ */
277
+ interface BaseWasmConfig {
278
+ /** Path to the WASM binary */
279
+ wasmPath?: string;
280
+ /** Path to the SIMD-optimized WASM binary (optional) */
281
+ wasmSimdPath?: string;
282
+ /** Path to the WASM glue code */
283
+ glueCodePath?: string;
284
+ /** Whether to use SIMD optimizations (default: true) */
285
+ useSimd?: boolean;
286
+ /**
287
+ * Base path for ML model files. Models will be loaded from `${modelsBasePath}/${modelFileName}`.
288
+ * If not provided, models are expected in a 'models' subdirectory relative to the WASM binary.
289
+ */
290
+ modelsBasePath?: string;
291
+ }
292
+ /**
293
+ * Base provider class that abstracts common WASM functionality.
294
+ * This serves as a foundation for specific ML capability providers
295
+ * like FaceDetectionProvider and IdCaptureProvider.
296
+ */
297
+ declare abstract class BaseWasmProvider {
298
+ private _isInitialized;
299
+ protected pipelineType: WasmPipelineType | undefined;
300
+ /**
301
+ * Creates a new BaseWasmProvider
302
+ * @param pipelineType - The WASM pipeline type this provider uses
303
+ */
304
+ constructor(pipelineType?: WasmPipelineType);
305
+ /**
306
+ * Returns whether this provider has been initialized.
307
+ */
308
+ get initialized(): boolean;
309
+ protected getPipelineType(): WasmPipelineType;
310
+ /**
311
+ * Initializes the provider by ensuring WASM is loaded
312
+ * @param config - Provider configuration
313
+ * @param pipeline - The pipeline type to warm up ('selfie', 'idCapture', etc.)
314
+ */
315
+ protected initializeBase(config: BaseWasmConfig, pipeline: WasmPipeline): Promise<void>;
316
+ /**
317
+ * Ensures the provider is initialized before performing operations.
318
+ * @throws Error if not initialized
319
+ */
320
+ protected ensureInitialized(): void;
321
+ /**
322
+ * Processes a frame through the WASM pipeline
323
+ * @param image - Image data to process
324
+ * @returns The pipeline result (type depends on pipeline - WASM returns any)
325
+ */
326
+ protected processFrameWasm(image: ImageData): Promise<any>;
327
+ abstract processFrame(image: ImageData): Promise<void>;
328
+ /**
329
+ * Resets the pipeline to its initial state.
330
+ * Safe to call even if not initialized (no-op in that case).
331
+ */
332
+ reset(): void;
333
+ /**
334
+ * Disposes of resources and resets initialization state.
335
+ * Safe to call even if not initialized.
336
+ */
337
+ dispose(): Promise<void>;
338
+ }
339
+ //#endregion
340
+ //#region src/internal/permissions/types.d.ts
341
+ type PermissionResult = 'granted' | 'denied' | 'prompt';
342
+ type PermissionStatus = 'idle' | 'requesting' | 'denied' | 'learnMore';
343
+ //#endregion
344
+ export { CameraStream as a, IMotionSensorCapability as c, IMLProviderCapability as d, MLProviderConfig as f, StreamCanvasCapture as i, MotionPermissionState as l, PermissionStatus as n, IRecordingCapability as o, IncodeCanvas as p, BaseWasmProvider as r, RecordingConnection as s, PermissionResult as t, MotionStatus as u };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@incodetech/core",
3
+ "version": "0.0.0-dev-20260126-4504c5b",
4
+ "type": "module",
5
+ "main": "./dist/index.esm.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.esm.js"
11
+ },
12
+ "./flow": {
13
+ "types": "./dist/flow.d.ts",
14
+ "import": "./dist/flow.esm.js"
15
+ },
16
+ "./selfie": {
17
+ "types": "./dist/selfie.d.ts",
18
+ "import": "./dist/selfie.esm.js"
19
+ },
20
+ "./phone": {
21
+ "types": "./dist/phone.d.ts",
22
+ "import": "./dist/phone.esm.js"
23
+ },
24
+ "./email": {
25
+ "types": "./dist/email.d.ts",
26
+ "import": "./dist/email.esm.js"
27
+ },
28
+ "./id": {
29
+ "types": "./dist/id.d.ts",
30
+ "import": "./dist/id.esm.js"
31
+ },
32
+ "./camera": {
33
+ "types": "./dist/camera.d.ts",
34
+ "import": "./dist/camera.esm.js"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "devDependencies": {
41
+ "@biomejs/biome": "^2.3.7",
42
+ "@vitest/coverage-v8": "^4.0.13",
43
+ "tsdown": "^0.16.6",
44
+ "typescript": "^5.9.3",
45
+ "vitest": "^4.0.13",
46
+ "@incodetech/config": "1.0.0",
47
+ "@incodetech/infra": "1.1.0-alpha.1"
48
+ },
49
+ "scripts": {
50
+ "build": "tsdown -c tsdown.config.ts",
51
+ "dev": "tsdown -c tsdown.config.ts --watch",
52
+ "test": "vitest run",
53
+ "coverage": "vitest run --coverage",
54
+ "lint": "biome lint .",
55
+ "format": "biome format . --write",
56
+ "typecheck": "tsc -p tsconfig.json --noEmit"
57
+ }
58
+ }