@arcships/light-ocr 0.3.4 → 0.5.1

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/js/index.d.ts DELETED
@@ -1,284 +0,0 @@
1
- /// <reference types="node" />
2
-
3
- export type PixelFormat = 'gray8' | 'rgb8' | 'bgr8' | 'rgba8';
4
- export type DetectionStrategy = 'bounded' | 'tiled' | 'upstreamExact';
5
- export type BuiltInModel = 'ppocrv6-small';
6
- export type ExecutionProvider = 'auto' | 'cpu' | 'apple' | 'webgpu';
7
- export type SessionFallback = 'error' | 'cpu';
8
- export type CpuPartition = 'allow' | 'forbid';
9
- export type PerformanceHint = 'latency' | 'throughput';
10
- /** WebGPU accepts auto/fp32; fp16 is reserved for the Apple provider. */
11
- export type Precision = 'auto' | 'fp32' | 'fp16';
12
-
13
- export interface DetectionOptions {
14
- readonly strategy?: DetectionStrategy;
15
- readonly maxSide?: number;
16
- }
17
-
18
- export interface ExecutionOptions {
19
- /** Only providers shipped and qualified by this release appear in this union. */
20
- readonly provider?: ExecutionProvider;
21
- readonly sessionFallback?: SessionFallback;
22
- readonly cpuPartition?: CpuPartition;
23
- readonly deviceId?: number;
24
- readonly performanceHint?: PerformanceHint;
25
- readonly precision?: Precision;
26
- }
27
-
28
- export interface RawImage {
29
- readonly data: Uint8Array;
30
- readonly width: number;
31
- readonly height: number;
32
- readonly stride: number;
33
- readonly pixelFormat: PixelFormat;
34
- }
35
-
36
- export interface ResourceLimits {
37
- readonly maxWidth: number;
38
- readonly maxHeight: number;
39
- readonly maxPixels: number;
40
- readonly maxDetectionSide: number;
41
- readonly maxDetectionCandidates: number;
42
- readonly maxDetectionTiles: number;
43
- readonly maxRecognitionBatchSize: number;
44
- readonly maxRecognitionWidth: number;
45
- readonly maxTemporaryBytes: number;
46
- }
47
-
48
- export interface CreateEngineOptions {
49
- readonly model?: BuiltInModel;
50
- readonly bundlePath?: string;
51
- readonly intraOpThreads?: number;
52
- readonly interOpThreads?: number;
53
- readonly recognitionScoreThreshold?: number;
54
- readonly recognitionBatchSize?: number;
55
- readonly reducedLimits?: Omit<ResourceLimits, 'maxDetectionTiles'> & {
56
- /** Omission preserves the 0.1 reducedLimits source shape. */
57
- readonly maxDetectionTiles?: number;
58
- };
59
- readonly queueCapacity?: number;
60
- readonly maxPendingInputBytes?: number;
61
- readonly detection?: DetectionOptions;
62
- readonly execution?: ExecutionOptions;
63
- }
64
-
65
- export interface RecognizeOptions {
66
- readonly recognitionScoreThreshold?: number;
67
- readonly recognitionBatchSize?: number;
68
- readonly includeDiagnostics?: boolean;
69
- readonly signal?: AbortSignal;
70
- readonly useTextlineOrientation?: boolean;
71
- readonly detectionMaxSide?: number;
72
- readonly applyExif?: boolean;
73
- readonly region?: Rect;
74
- }
75
-
76
- export interface Point { readonly x: number; readonly y: number }
77
- export interface Rect {
78
- readonly x: number;
79
- readonly y: number;
80
- readonly width: number;
81
- readonly height: number;
82
- }
83
- export interface OcrLine {
84
- readonly text: string;
85
- readonly confidence: number;
86
- readonly box: readonly [Point, Point, Point, Point];
87
- }
88
- export type RejectionReason = 'below_score_threshold' | 'empty_decode';
89
- export interface RejectedLine { readonly line: OcrLine; readonly reason: RejectionReason }
90
- export interface DiagnosticWarning { readonly code: string; readonly message: string }
91
- export interface RecognitionBatchShape {
92
- readonly batchSize: number;
93
- readonly height: number;
94
- readonly width: number;
95
- readonly computeUnit: 'cpu' | 'ane' | 'gpu';
96
- readonly modelId: string;
97
- readonly shapeBucket: string;
98
- }
99
- export interface DetectionPassShape {
100
- readonly tileOrdinal: number;
101
- readonly x: number;
102
- readonly y: number;
103
- readonly width: number;
104
- readonly height: number;
105
- readonly tensorWidth: number;
106
- readonly tensorHeight: number;
107
- readonly contourCandidates: number;
108
- readonly rawCandidates: number;
109
- }
110
- export interface Diagnostics {
111
- readonly rejectedLines: readonly RejectedLine[];
112
- readonly warnings: readonly DiagnosticWarning[];
113
- readonly detectedCandidates: number;
114
- readonly acceptedBoxes: number;
115
- readonly detectionInputWidth: number;
116
- readonly detectionInputHeight: number;
117
- readonly rawDetectionBoxes: number;
118
- readonly suppressedDuplicateBoxes: number;
119
- readonly maxLiveDetectionPassBuffers: number;
120
- readonly detectionPasses: readonly DetectionPassShape[];
121
- readonly recognitionBatchShapes: readonly RecognitionBatchShape[];
122
- }
123
- export interface TimingUs {
124
- readonly total: number;
125
- readonly decode: number;
126
- readonly inputValidation: number;
127
- readonly detectionPreprocess: number;
128
- readonly detectionInference: number;
129
- readonly detectionPostprocess: number;
130
- readonly detectionMerge: number;
131
- readonly cropAndSort: number;
132
- readonly recognitionPreprocess: number;
133
- readonly recognitionInference: number;
134
- readonly recognitionPostprocess: number;
135
- }
136
- export interface OcrResult {
137
- readonly lines: readonly OcrLine[];
138
- readonly imageWidth: number;
139
- readonly imageHeight: number;
140
- readonly modelBundleId: string;
141
- readonly timingUs: TimingUs;
142
- readonly diagnostics?: Diagnostics;
143
- }
144
- export interface TiledDetectionInfo {
145
- readonly contractVersion: 'tiled-v1';
146
- readonly tileSide: 1280;
147
- readonly minimumOverlap: 128;
148
- readonly artificialBoundaryMargin: 32;
149
- readonly mergeIouThreshold: 0.5;
150
- readonly mergeIosThreshold: 0.8;
151
- }
152
- export interface ProviderCapabilityInfo {
153
- readonly provider: string;
154
- readonly packageIncluded: boolean;
155
- readonly deviceAvailable: boolean;
156
- /** True only when this exact hardware family has reviewed qualification evidence. */
157
- readonly deviceValidated: boolean;
158
- }
159
- export interface SessionExecutionInfo {
160
- readonly requestedProvider: string;
161
- readonly actualProviderChain: readonly string[];
162
- readonly device: string;
163
- readonly deviceFamily: string;
164
- readonly operatingSystem: string;
165
- readonly precision: string;
166
- readonly shapePolicy: string;
167
- readonly modelId: string;
168
- readonly modelSha256: string;
169
- readonly runtime: string;
170
- readonly runtimeVersion: string;
171
- readonly providerVersion: string;
172
- readonly modelCacheStatus: string;
173
- readonly qualificationId: string;
174
- /** False means the open macOS compatibility path is experimental on this device. */
175
- readonly deviceValidated: boolean;
176
- readonly sessionFallback: boolean;
177
- readonly fallbackReason?: string;
178
- }
179
- export type CreationReason =
180
- | 'adapter_unavailable' | 'model_compute_unsupported'
181
- | 'device_memory_insufficient' | 'driver_version_unsupported'
182
- | 'package_corrupt' | 'artifact_hash_mismatch' | 'provider_abi_mismatch'
183
- | 'internal_assertion_failed' | 'unrecoverable_load_failed';
184
- export type CreationAttemptStatus = 'selected' | 'skipped' | 'fatal';
185
- export interface CreationAttempt {
186
- readonly provider: string;
187
- readonly status: CreationAttemptStatus;
188
- readonly creationReason?: CreationReason;
189
- readonly errorCode?: CoreErrorCode;
190
- }
191
- export interface CreationTrace {
192
- readonly requestedProvider: string;
193
- readonly policyId?: string;
194
- readonly policyVersion?: number;
195
- readonly orderedCandidates: readonly string[];
196
- readonly attempts: readonly CreationAttempt[];
197
- readonly selectedProvider?: string;
198
- }
199
- export interface ExecutionInfo {
200
- readonly requestedProvider: ExecutionProvider;
201
- readonly sessionFallback: SessionFallback;
202
- readonly cpuPartition: CpuPartition;
203
- readonly deviceId?: number;
204
- readonly performanceHint: PerformanceHint;
205
- readonly requestedPrecision: Precision;
206
- readonly providerCapabilities: readonly ProviderCapabilityInfo[];
207
- readonly selectionTrace: CreationTrace;
208
- readonly sessions: {
209
- readonly detection: SessionExecutionInfo;
210
- readonly recognition: SessionExecutionInfo;
211
- };
212
- }
213
- export interface EngineInfo {
214
- readonly coreVersion: string;
215
- readonly modelBundleId: string;
216
- readonly modelBundleSchemaVersion: string;
217
- readonly normalizedConfigSchemaVersion: string;
218
- readonly backend: string;
219
- /** @deprecated Use execution.sessions for stage-specific provider details. */
220
- readonly executionProvider: string;
221
- readonly execution: ExecutionInfo;
222
- readonly capabilities: {
223
- readonly detection: boolean;
224
- readonly recognition: boolean;
225
- readonly textlineOrientation: boolean;
226
- readonly tiledDetection: boolean;
227
- };
228
- readonly concurrencyMode: 'serialized_reject_when_busy';
229
- readonly limits: ResourceLimits & { readonly maxConcurrentCalls: 1 };
230
- readonly intraOpThreads: number;
231
- readonly interOpThreads: number;
232
- readonly detectionStrategy: DetectionStrategy;
233
- readonly detectionMaxSide: number;
234
- readonly tiledDetection?: TiledDetectionInfo;
235
- readonly defaultRecognitionScoreThreshold: number;
236
- readonly defaultRecognitionBatchSize: number;
237
- readonly adapter: {
238
- readonly scheduler: 'dedicated_fifo';
239
- readonly queueCapacity: number;
240
- readonly maxPendingInputBytes: number;
241
- };
242
- }
243
-
244
- export type CoreErrorCode =
245
- | 'invalid_argument' | 'invalid_image' | 'unsupported_pixel_format'
246
- | 'unsupported_capability' | 'invalid_model_bundle' | 'unsupported_model'
247
- | 'model_integrity_failed' | 'runtime_initialization_failed' | 'inference_failed'
248
- | 'postprocess_failed' | 'resource_limit_exceeded' | 'invalid_engine'
249
- | 'internal_error';
250
- export type AdapterErrorCode =
251
- | 'bundle_io_failed' | 'queue_full' | 'environment_closing'
252
- | 'unsupported_platform' | 'package_load_failed';
253
- export type OcrErrorCode = CoreErrorCode | AdapterErrorCode;
254
-
255
- export class OcrError extends Error {
256
- constructor(code: OcrErrorCode, message: string, detail?: string);
257
- readonly name: 'OcrError';
258
- readonly code: OcrErrorCode;
259
- readonly detail?: string;
260
- readonly creationTrace?: CreationTrace;
261
- }
262
-
263
- export interface OcrEngine {
264
- readonly info: EngineInfo;
265
- recognize(image: RawImage, options?: RecognizeOptions): Promise<OcrResult>;
266
- recognizeEncoded(data: Uint8Array, options?: RecognizeOptions): Promise<OcrResult>;
267
- detect(data: Uint8Array, options?: RecognizeOptions): Promise<DetectionResult>;
268
- close(): Promise<void>;
269
- }
270
-
271
- export interface DetectionBox {
272
- readonly score: number;
273
- readonly box: readonly [Point, Point, Point, Point];
274
- }
275
-
276
- export interface DetectionResult {
277
- readonly boxes: readonly DetectionBox[];
278
- readonly imageWidth: number;
279
- readonly imageHeight: number;
280
- readonly modelBundleId: string;
281
- readonly timingUs: TimingUs;
282
- }
283
-
284
- export function createEngine(options?: CreateEngineOptions): Promise<OcrEngine>;