scanic 1.1.1 → 1.3.0
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/README.md +17 -17
- package/dist/scanic.js +1 -2670
- package/dist/scanic.umd.cjs +1 -1
- package/package.json +26 -6
- package/src/scanic.d.ts +98 -7
package/src/scanic.d.ts
CHANGED
|
@@ -22,12 +22,64 @@ export interface CornerEditorMagnifierOptions {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export interface CornerEditorNudgesOptions {
|
|
25
|
+
/** Show the on-screen nudge pad. Default false. */
|
|
25
26
|
enabled?: boolean;
|
|
27
|
+
/** Step sizes (px) to render as nudge buttons. Default [1, 10]. */
|
|
26
28
|
steps?: number[];
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
export interface CornerEditorToolbarOptions {
|
|
32
|
+
/** Show the floating toolbar. Default true. */
|
|
33
|
+
enabled?: boolean;
|
|
34
|
+
/** Include the Reset button. Default true. */
|
|
35
|
+
reset?: boolean;
|
|
36
|
+
/** Include the Cancel button. Default true. */
|
|
37
|
+
cancel?: boolean;
|
|
38
|
+
/** Include the Apply button. Default true. */
|
|
39
|
+
apply?: boolean;
|
|
40
|
+
/** Override the button labels. */
|
|
41
|
+
labels?: { reset?: string; cancel?: string; apply?: string };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Programmatic theme overrides. Each maps to a CSS custom property on the host
|
|
46
|
+
* (e.g. `accent` → `--scanic-accent`). You can also set these variables directly
|
|
47
|
+
* in your own CSS, or override the `.scanic-*` classes entirely.
|
|
48
|
+
*/
|
|
49
|
+
export interface CornerEditorTheme {
|
|
50
|
+
/** Primary colour for edges, rings and active handles. */
|
|
51
|
+
accent?: string;
|
|
52
|
+
/** Fill colour outside the document quad. */
|
|
53
|
+
mask?: string;
|
|
54
|
+
/** Quad outline colour. Defaults to `accent`. */
|
|
55
|
+
edgeColor?: string;
|
|
56
|
+
/** Quad outline width (unitless number). */
|
|
57
|
+
edgeWidth?: number | string;
|
|
58
|
+
/** Handle diameter. Number is treated as px. */
|
|
59
|
+
handleSize?: number | string;
|
|
60
|
+
/** Pointer/touch hit-target size. Number is treated as px. */
|
|
61
|
+
handleHit?: number | string;
|
|
62
|
+
/** Handle fill colour (idle). */
|
|
63
|
+
handleColor?: string;
|
|
64
|
+
/** Handle ring colour (idle). */
|
|
65
|
+
handleRingColor?: string;
|
|
66
|
+
/** Background of the toolbar / nudge pad. */
|
|
67
|
+
surface?: string;
|
|
68
|
+
/** Foreground (text) colour of the toolbar / nudge pad. */
|
|
69
|
+
surfaceColor?: string;
|
|
70
|
+
/** Corner radius of the toolbar / nudge pad. */
|
|
71
|
+
radius?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface CornerEditorClassNames {
|
|
75
|
+
root?: string;
|
|
76
|
+
handle?: string;
|
|
77
|
+
toolbar?: string;
|
|
78
|
+
nudges?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
29
81
|
export interface CornerEditorOptions {
|
|
30
|
-
/** Host element the editor
|
|
82
|
+
/** Host element the editor is mounted into. */
|
|
31
83
|
container: HTMLElement;
|
|
32
84
|
/** Source image to adjust corners against. */
|
|
33
85
|
image: HTMLImageElement | HTMLCanvasElement | ImageData;
|
|
@@ -35,19 +87,26 @@ export interface CornerEditorOptions {
|
|
|
35
87
|
corners?: CornerPoints;
|
|
36
88
|
magnifier?: CornerEditorMagnifierOptions;
|
|
37
89
|
nudges?: CornerEditorNudgesOptions;
|
|
38
|
-
/**
|
|
90
|
+
/** Floating Reset/Cancel/Apply toolbar. Shown by default. */
|
|
91
|
+
toolbar?: CornerEditorToolbarOptions;
|
|
92
|
+
/** Programmatic theme overrides (CSS variables). */
|
|
93
|
+
theme?: CornerEditorTheme;
|
|
94
|
+
/** Extra class names applied to editor parts. */
|
|
95
|
+
classNames?: CornerEditorClassNames;
|
|
96
|
+
/** Inject the default stylesheet once per document. Default true. */
|
|
97
|
+
injectStyles?: boolean;
|
|
98
|
+
/** Pointer/touch target size (px) around each handle. Default 44. */
|
|
39
99
|
handleHitArea?: number;
|
|
40
100
|
/**
|
|
41
|
-
* Enable keyboard control
|
|
42
|
-
*
|
|
43
|
-
* Enter confirms, Escape cancels.
|
|
101
|
+
* Enable keyboard control (default true): focus a handle, then arrow keys
|
|
102
|
+
* nudge it (Shift = coarse step), Enter confirms, Escape cancels.
|
|
44
103
|
*/
|
|
45
104
|
keyboard?: boolean;
|
|
46
105
|
/** Fired on every corner change (drag, nudge, keyboard). */
|
|
47
106
|
onChange?: (corners: CornerPoints) => void;
|
|
48
|
-
/** Fired by confirm()/Enter with the final corners. */
|
|
107
|
+
/** Fired by confirm()/Enter/Apply with the final corners. */
|
|
49
108
|
onConfirm?: (corners: CornerPoints) => void;
|
|
50
|
-
/** Fired by cancel()/Escape. */
|
|
109
|
+
/** Fired by cancel()/Escape/Cancel. */
|
|
51
110
|
onCancel?: () => void;
|
|
52
111
|
}
|
|
53
112
|
|
|
@@ -56,14 +115,44 @@ export interface CornerEditor {
|
|
|
56
115
|
setCorners(corners: CornerPoints): boolean;
|
|
57
116
|
reset(): void;
|
|
58
117
|
nudge(cornerKey: keyof CornerPoints, dx: number, dy: number, step?: number): boolean;
|
|
118
|
+
/** Re-read CSS variables into the canvas layer after a runtime theme change. */
|
|
119
|
+
refreshTheme(theme?: CornerEditorTheme): void;
|
|
59
120
|
confirm(): CornerPoints;
|
|
60
121
|
cancel(): void;
|
|
61
122
|
destroy(): void;
|
|
62
123
|
}
|
|
63
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Options for the optional ML detector (`detector: 'ml'`). Assets are lazy-loaded
|
|
127
|
+
* from the companion `scanic-ml` package on a CDN by default; `onnxruntime-web`
|
|
128
|
+
* (v1.23.x, matching the bundled wasm) must be installed as a peer dependency.
|
|
129
|
+
*/
|
|
130
|
+
export interface MlDetectorOptions {
|
|
131
|
+
/** Base URL for the wasm + `.ort` model. Default: scanic-ml on jsDelivr. */
|
|
132
|
+
assetBaseUrl?: string;
|
|
133
|
+
/** Explicit model URL (overrides `assetBaseUrl` for the model). */
|
|
134
|
+
modelUrl?: string;
|
|
135
|
+
/** Explicit wasm directory (overrides `assetBaseUrl` for the runtime wasm). */
|
|
136
|
+
wasmPaths?: string;
|
|
137
|
+
/** Pre-fetched `.ort` model bytes (skips the network fetch). */
|
|
138
|
+
modelBytes?: Uint8Array;
|
|
139
|
+
/** ORT thread count. Default 1; values >1 require COOP/COEP headers on the host. */
|
|
140
|
+
numThreads?: number;
|
|
141
|
+
/** Minimum P(document) to report success. Default 0.5. */
|
|
142
|
+
minScore?: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
64
145
|
export interface DetectionOptions {
|
|
65
146
|
mode?: 'detect' | 'extract';
|
|
66
147
|
output?: 'canvas' | 'imagedata' | 'dataurl';
|
|
148
|
+
/**
|
|
149
|
+
* Detection backend. `'classical'` (default) is the pure-JS/WASM Canny
|
|
150
|
+
* pipeline. `'ml'` uses the optional DocCornerNet SimCC model via
|
|
151
|
+
* onnxruntime-web — more robust on cluttered/low-contrast photos.
|
|
152
|
+
*/
|
|
153
|
+
detector?: 'classical' | 'ml';
|
|
154
|
+
/** Options forwarded to the ML detector when `detector: 'ml'`. */
|
|
155
|
+
ml?: MlDetectorOptions;
|
|
67
156
|
debug?: boolean;
|
|
68
157
|
maxProcessingDimension?: number;
|
|
69
158
|
lowThreshold?: number;
|
|
@@ -98,6 +187,8 @@ export interface ScannerResult {
|
|
|
98
187
|
success: boolean;
|
|
99
188
|
message: string;
|
|
100
189
|
confidence?: number | null;
|
|
190
|
+
/** P(document present) from the ML detector (`detector: 'ml'`); null otherwise. */
|
|
191
|
+
score?: number | null;
|
|
101
192
|
output: HTMLCanvasElement | ImageData | string | null;
|
|
102
193
|
corners: CornerPoints | null;
|
|
103
194
|
contour: Point[] | null;
|