capacitor-card-scanner 0.0.1 → 0.2.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 +136 -3
- package/android/build.gradle +2 -0
- package/android/src/main/java/pt/tcgclassifier/cardscanner/CardDetector.java +283 -0
- package/android/src/main/java/pt/tcgclassifier/cardscanner/CardScanner.java +267 -195
- package/android/src/main/java/pt/tcgclassifier/cardscanner/CardScannerPlugin.java +33 -0
- package/android/src/main/java/pt/tcgclassifier/cardscanner/DetectionOverlay.java +82 -0
- package/dist/docs.json +300 -0
- package/dist/esm/definitions.d.ts +83 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +2 -0
- package/dist/esm/web.js +6 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +6 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +6 -0
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/docs.json
CHANGED
|
@@ -98,6 +98,68 @@
|
|
|
98
98
|
"complexTypes": [],
|
|
99
99
|
"slug": "flip"
|
|
100
100
|
},
|
|
101
|
+
{
|
|
102
|
+
"name": "startDetection",
|
|
103
|
+
"signature": "(options?: DetectionOptions | undefined) => Promise<void>",
|
|
104
|
+
"parameters": [
|
|
105
|
+
{
|
|
106
|
+
"name": "options",
|
|
107
|
+
"docs": "",
|
|
108
|
+
"type": "DetectionOptions | undefined"
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
"returns": "Promise<void>",
|
|
112
|
+
"tags": [],
|
|
113
|
+
"docs": "Starts looking for cards: draws a red rectangle around the card and reads\nits text, emitting `cardDetected`. Requires `start()` first. Android only.",
|
|
114
|
+
"complexTypes": [
|
|
115
|
+
"DetectionOptions"
|
|
116
|
+
],
|
|
117
|
+
"slug": "startdetection"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"name": "stopDetection",
|
|
121
|
+
"signature": "() => Promise<void>",
|
|
122
|
+
"parameters": [],
|
|
123
|
+
"returns": "Promise<void>",
|
|
124
|
+
"tags": [],
|
|
125
|
+
"docs": "Stops card detection and hides the rectangle.",
|
|
126
|
+
"complexTypes": [],
|
|
127
|
+
"slug": "stopdetection"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"name": "addListener",
|
|
131
|
+
"signature": "(eventName: 'cardDetected', listener: (event: CardDetectedEvent) => void) => Promise<PluginListenerHandle>",
|
|
132
|
+
"parameters": [
|
|
133
|
+
{
|
|
134
|
+
"name": "eventName",
|
|
135
|
+
"docs": "",
|
|
136
|
+
"type": "'cardDetected'"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"name": "listener",
|
|
140
|
+
"docs": "",
|
|
141
|
+
"type": "(event: CardDetectedEvent) => void"
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
"returns": "Promise<PluginListenerHandle>",
|
|
145
|
+
"tags": [],
|
|
146
|
+
"docs": "Fired once per card, when its text has been read consistently.",
|
|
147
|
+
"complexTypes": [
|
|
148
|
+
"PluginListenerHandle",
|
|
149
|
+
"CardDetectedEvent"
|
|
150
|
+
],
|
|
151
|
+
"slug": "addlistenercarddetected-"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"name": "removeAllListeners",
|
|
155
|
+
"signature": "() => Promise<void>",
|
|
156
|
+
"parameters": [],
|
|
157
|
+
"returns": "Promise<void>",
|
|
158
|
+
"tags": [],
|
|
159
|
+
"docs": "",
|
|
160
|
+
"complexTypes": [],
|
|
161
|
+
"slug": "removealllisteners"
|
|
162
|
+
},
|
|
101
163
|
{
|
|
102
164
|
"name": "checkPermissions",
|
|
103
165
|
"signature": "() => Promise<PermissionStatus>",
|
|
@@ -232,6 +294,244 @@
|
|
|
232
294
|
}
|
|
233
295
|
]
|
|
234
296
|
},
|
|
297
|
+
{
|
|
298
|
+
"name": "DetectionOptions",
|
|
299
|
+
"slug": "detectionoptions",
|
|
300
|
+
"docs": "",
|
|
301
|
+
"tags": [],
|
|
302
|
+
"methods": [],
|
|
303
|
+
"properties": [
|
|
304
|
+
{
|
|
305
|
+
"name": "intervalMs",
|
|
306
|
+
"tags": [
|
|
307
|
+
{
|
|
308
|
+
"text": "300",
|
|
309
|
+
"name": "default"
|
|
310
|
+
}
|
|
311
|
+
],
|
|
312
|
+
"docs": "Minimum time between two OCR runs, in milliseconds.\nThe red rectangle is updated on every frame regardless.",
|
|
313
|
+
"complexTypes": [],
|
|
314
|
+
"type": "number | undefined"
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
"name": "stableFrames",
|
|
318
|
+
"tags": [
|
|
319
|
+
{
|
|
320
|
+
"text": "2",
|
|
321
|
+
"name": "default"
|
|
322
|
+
}
|
|
323
|
+
],
|
|
324
|
+
"docs": "How many consecutive OCR runs must read the same card before\n`cardDetected` fires.",
|
|
325
|
+
"complexTypes": [],
|
|
326
|
+
"type": "number | undefined"
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
"name": "includeImage",
|
|
330
|
+
"tags": [
|
|
331
|
+
{
|
|
332
|
+
"text": "false",
|
|
333
|
+
"name": "default"
|
|
334
|
+
}
|
|
335
|
+
],
|
|
336
|
+
"docs": "Include a JPEG of the detected card in the event.",
|
|
337
|
+
"complexTypes": [],
|
|
338
|
+
"type": "boolean | undefined"
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
"name": "cardAspectRatio",
|
|
342
|
+
"tags": [
|
|
343
|
+
{
|
|
344
|
+
"text": "0.716 (63 x 88 mm)",
|
|
345
|
+
"name": "default"
|
|
346
|
+
}
|
|
347
|
+
],
|
|
348
|
+
"docs": "Expected width / height of an upright card. Only upright cards are\ndetected; a card lying sideways falls outside the tolerance.",
|
|
349
|
+
"complexTypes": [],
|
|
350
|
+
"type": "number | undefined"
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
"name": "aspectTolerance",
|
|
354
|
+
"tags": [
|
|
355
|
+
{
|
|
356
|
+
"text": "0.15",
|
|
357
|
+
"name": "default"
|
|
358
|
+
}
|
|
359
|
+
],
|
|
360
|
+
"docs": "Allowed relative deviation from `cardAspectRatio` (0.15 = ±15%).\nIncrease it if tilted cards are not detected.",
|
|
361
|
+
"complexTypes": [],
|
|
362
|
+
"type": "number | undefined"
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
"name": "minCardArea",
|
|
366
|
+
"tags": [
|
|
367
|
+
{
|
|
368
|
+
"text": "0.08",
|
|
369
|
+
"name": "default"
|
|
370
|
+
}
|
|
371
|
+
],
|
|
372
|
+
"docs": "Smallest card size, as a fraction of the camera frame (0-1).",
|
|
373
|
+
"complexTypes": [],
|
|
374
|
+
"type": "number | undefined"
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
"name": "maxCardArea",
|
|
378
|
+
"tags": [
|
|
379
|
+
{
|
|
380
|
+
"text": "0.9",
|
|
381
|
+
"name": "default"
|
|
382
|
+
}
|
|
383
|
+
],
|
|
384
|
+
"docs": "Largest card size, as a fraction of the camera frame (0-1).",
|
|
385
|
+
"complexTypes": [],
|
|
386
|
+
"type": "number | undefined"
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
"name": "requireCard",
|
|
390
|
+
"tags": [
|
|
391
|
+
{
|
|
392
|
+
"text": "true",
|
|
393
|
+
"name": "default"
|
|
394
|
+
}
|
|
395
|
+
],
|
|
396
|
+
"docs": "Only read text when a card-shaped object is visible. When false, the whole\nframe is read if no card is found.",
|
|
397
|
+
"complexTypes": [],
|
|
398
|
+
"type": "boolean | undefined"
|
|
399
|
+
}
|
|
400
|
+
]
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
"name": "PluginListenerHandle",
|
|
404
|
+
"slug": "pluginlistenerhandle",
|
|
405
|
+
"docs": "",
|
|
406
|
+
"tags": [],
|
|
407
|
+
"methods": [],
|
|
408
|
+
"properties": [
|
|
409
|
+
{
|
|
410
|
+
"name": "remove",
|
|
411
|
+
"tags": [],
|
|
412
|
+
"docs": "",
|
|
413
|
+
"complexTypes": [],
|
|
414
|
+
"type": "() => Promise<void>"
|
|
415
|
+
}
|
|
416
|
+
]
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
"name": "CardDetectedEvent",
|
|
420
|
+
"slug": "carddetectedevent",
|
|
421
|
+
"docs": "",
|
|
422
|
+
"tags": [],
|
|
423
|
+
"methods": [],
|
|
424
|
+
"properties": [
|
|
425
|
+
{
|
|
426
|
+
"name": "name",
|
|
427
|
+
"tags": [],
|
|
428
|
+
"docs": "Best guess for the card name (topmost line of text on the card).",
|
|
429
|
+
"complexTypes": [],
|
|
430
|
+
"type": "string | undefined"
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
"name": "collectorNumber",
|
|
434
|
+
"tags": [],
|
|
435
|
+
"docs": "Collector number, e.g. `025/165`.",
|
|
436
|
+
"complexTypes": [],
|
|
437
|
+
"type": "string | undefined"
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
"name": "text",
|
|
441
|
+
"tags": [],
|
|
442
|
+
"docs": "All text read on the card.",
|
|
443
|
+
"complexTypes": [],
|
|
444
|
+
"type": "string"
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
"name": "lines",
|
|
448
|
+
"tags": [],
|
|
449
|
+
"docs": "",
|
|
450
|
+
"complexTypes": [
|
|
451
|
+
"TextLine"
|
|
452
|
+
],
|
|
453
|
+
"type": "TextLine[]"
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
"name": "cardBox",
|
|
457
|
+
"tags": [],
|
|
458
|
+
"docs": "Where the card is in the camera frame. Missing if no card outline was found.",
|
|
459
|
+
"complexTypes": [
|
|
460
|
+
"Box"
|
|
461
|
+
],
|
|
462
|
+
"type": "Box"
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
"name": "image",
|
|
466
|
+
"tags": [],
|
|
467
|
+
"docs": "Base64 JPEG of the card, when `includeImage` is true.",
|
|
468
|
+
"complexTypes": [],
|
|
469
|
+
"type": "string | undefined"
|
|
470
|
+
}
|
|
471
|
+
]
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
"name": "TextLine",
|
|
475
|
+
"slug": "textline",
|
|
476
|
+
"docs": "",
|
|
477
|
+
"tags": [],
|
|
478
|
+
"methods": [],
|
|
479
|
+
"properties": [
|
|
480
|
+
{
|
|
481
|
+
"name": "text",
|
|
482
|
+
"tags": [],
|
|
483
|
+
"docs": "",
|
|
484
|
+
"complexTypes": [],
|
|
485
|
+
"type": "string"
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
"name": "box",
|
|
489
|
+
"tags": [],
|
|
490
|
+
"docs": "Position inside the card image.",
|
|
491
|
+
"complexTypes": [
|
|
492
|
+
"Box"
|
|
493
|
+
],
|
|
494
|
+
"type": "Box"
|
|
495
|
+
}
|
|
496
|
+
]
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
"name": "Box",
|
|
500
|
+
"slug": "box",
|
|
501
|
+
"docs": "Normalized rectangle (0-1).",
|
|
502
|
+
"tags": [],
|
|
503
|
+
"methods": [],
|
|
504
|
+
"properties": [
|
|
505
|
+
{
|
|
506
|
+
"name": "x",
|
|
507
|
+
"tags": [],
|
|
508
|
+
"docs": "",
|
|
509
|
+
"complexTypes": [],
|
|
510
|
+
"type": "number"
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
"name": "y",
|
|
514
|
+
"tags": [],
|
|
515
|
+
"docs": "",
|
|
516
|
+
"complexTypes": [],
|
|
517
|
+
"type": "number"
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
"name": "width",
|
|
521
|
+
"tags": [],
|
|
522
|
+
"docs": "",
|
|
523
|
+
"complexTypes": [],
|
|
524
|
+
"type": "number"
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
"name": "height",
|
|
528
|
+
"tags": [],
|
|
529
|
+
"docs": "",
|
|
530
|
+
"complexTypes": [],
|
|
531
|
+
"type": "number"
|
|
532
|
+
}
|
|
533
|
+
]
|
|
534
|
+
},
|
|
235
535
|
{
|
|
236
536
|
"name": "PermissionStatus",
|
|
237
537
|
"slug": "permissionstatus",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PermissionState } from '@capacitor/core';
|
|
1
|
+
import type { PermissionState, PluginListenerHandle } from '@capacitor/core';
|
|
2
2
|
export type CameraPosition = 'rear' | 'front';
|
|
3
3
|
export interface StartOptions {
|
|
4
4
|
/**
|
|
@@ -30,6 +30,78 @@ export interface ZoomOptions {
|
|
|
30
30
|
export interface PermissionStatus {
|
|
31
31
|
camera: PermissionState;
|
|
32
32
|
}
|
|
33
|
+
export interface DetectionOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Minimum time between two OCR runs, in milliseconds.
|
|
36
|
+
* The red rectangle is updated on every frame regardless.
|
|
37
|
+
* @default 300
|
|
38
|
+
*/
|
|
39
|
+
intervalMs?: number;
|
|
40
|
+
/**
|
|
41
|
+
* How many consecutive OCR runs must read the same card before
|
|
42
|
+
* `cardDetected` fires.
|
|
43
|
+
* @default 2
|
|
44
|
+
*/
|
|
45
|
+
stableFrames?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Include a JPEG of the detected card in the event.
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
includeImage?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Expected width / height of an upright card. Only upright cards are
|
|
53
|
+
* detected; a card lying sideways falls outside the tolerance.
|
|
54
|
+
* @default 0.716 (63 x 88 mm)
|
|
55
|
+
*/
|
|
56
|
+
cardAspectRatio?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Allowed relative deviation from `cardAspectRatio` (0.15 = ±15%).
|
|
59
|
+
* Increase it if tilted cards are not detected.
|
|
60
|
+
* @default 0.15
|
|
61
|
+
*/
|
|
62
|
+
aspectTolerance?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Smallest card size, as a fraction of the camera frame (0-1).
|
|
65
|
+
* @default 0.08
|
|
66
|
+
*/
|
|
67
|
+
minCardArea?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Largest card size, as a fraction of the camera frame (0-1).
|
|
70
|
+
* @default 0.9
|
|
71
|
+
*/
|
|
72
|
+
maxCardArea?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Only read text when a card-shaped object is visible. When false, the whole
|
|
75
|
+
* frame is read if no card is found.
|
|
76
|
+
* @default true
|
|
77
|
+
*/
|
|
78
|
+
requireCard?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/** Normalized rectangle (0-1). */
|
|
81
|
+
export interface Box {
|
|
82
|
+
x: number;
|
|
83
|
+
y: number;
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
}
|
|
87
|
+
export interface TextLine {
|
|
88
|
+
text: string;
|
|
89
|
+
/** Position inside the card image. */
|
|
90
|
+
box: Box;
|
|
91
|
+
}
|
|
92
|
+
export interface CardDetectedEvent {
|
|
93
|
+
/** Best guess for the card name (topmost line of text on the card). */
|
|
94
|
+
name?: string;
|
|
95
|
+
/** Collector number, e.g. `025/165`. */
|
|
96
|
+
collectorNumber?: string;
|
|
97
|
+
/** All text read on the card. */
|
|
98
|
+
text: string;
|
|
99
|
+
lines: TextLine[];
|
|
100
|
+
/** Where the card is in the camera frame. Missing if no card outline was found. */
|
|
101
|
+
cardBox?: Box;
|
|
102
|
+
/** Base64 JPEG of the card, when `includeImage` is true. */
|
|
103
|
+
image?: string;
|
|
104
|
+
}
|
|
33
105
|
export interface CardScannerPlugin {
|
|
34
106
|
/**
|
|
35
107
|
* Opens the camera **behind** the WebView. The WebView background is made
|
|
@@ -47,6 +119,16 @@ export interface CardScannerPlugin {
|
|
|
47
119
|
setZoom(options: ZoomOptions): Promise<void>;
|
|
48
120
|
/** Switches between the rear and front camera. */
|
|
49
121
|
flip(): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Starts looking for cards: draws a red rectangle around the card and reads
|
|
124
|
+
* its text, emitting `cardDetected`. Requires `start()` first. Android only.
|
|
125
|
+
*/
|
|
126
|
+
startDetection(options?: DetectionOptions): Promise<void>;
|
|
127
|
+
/** Stops card detection and hides the rectangle. */
|
|
128
|
+
stopDetection(): Promise<void>;
|
|
129
|
+
/** Fired once per card, when its text has been read consistently. */
|
|
130
|
+
addListener(eventName: 'cardDetected', listener: (event: CardDetectedEvent) => void): Promise<PluginListenerHandle>;
|
|
131
|
+
removeAllListeners(): Promise<void>;
|
|
50
132
|
checkPermissions(): Promise<PermissionStatus>;
|
|
51
133
|
requestPermissions(): Promise<PermissionStatus>;
|
|
52
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionState } from '@capacitor/core';\n\nexport type CameraPosition = 'rear' | 'front';\n\nexport interface StartOptions {\n /**\n * Which camera to use.\n * @default 'rear'\n */\n position?: CameraPosition;\n}\n\nexport interface CaptureOptions {\n /**\n * JPEG quality (0-100).\n * @default 85\n */\n quality?: number;\n}\n\nexport interface CaptureResult {\n /** Base64 encoded JPEG (without the `data:` prefix). */\n base64: string;\n width: number;\n height: number;\n}\n\nexport interface TorchOptions {\n enabled: boolean;\n}\n\nexport interface ZoomOptions {\n /** Zoom ratio, clamped between the camera's min and max. */\n ratio: number;\n}\n\nexport interface PermissionStatus {\n camera: PermissionState;\n}\n\nexport interface CardScannerPlugin {\n /**\n * Opens the camera **behind** the WebView. The WebView background is made\n * transparent, so the HTML page must also use transparent backgrounds\n * where the camera should be visible.\n */\n start(options?: StartOptions): Promise<void>;\n\n /** Stops the camera and removes the preview. */\n stop(): Promise<void>;\n\n /** Takes a photo from the running camera. */\n capture(options?: CaptureOptions): Promise<CaptureResult>;\n\n /** Turns the flashlight on/off. */\n setTorch(options: TorchOptions): Promise<void>;\n\n /** Sets the zoom ratio. */\n setZoom(options: ZoomOptions): Promise<void>;\n\n /** Switches between the rear and front camera. */\n flip(): Promise<void>;\n\n checkPermissions(): Promise<PermissionStatus>;\n\n requestPermissions(): Promise<PermissionStatus>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionState, PluginListenerHandle } from '@capacitor/core';\n\nexport type CameraPosition = 'rear' | 'front';\n\nexport interface StartOptions {\n /**\n * Which camera to use.\n * @default 'rear'\n */\n position?: CameraPosition;\n}\n\nexport interface CaptureOptions {\n /**\n * JPEG quality (0-100).\n * @default 85\n */\n quality?: number;\n}\n\nexport interface CaptureResult {\n /** Base64 encoded JPEG (without the `data:` prefix). */\n base64: string;\n width: number;\n height: number;\n}\n\nexport interface TorchOptions {\n enabled: boolean;\n}\n\nexport interface ZoomOptions {\n /** Zoom ratio, clamped between the camera's min and max. */\n ratio: number;\n}\n\nexport interface PermissionStatus {\n camera: PermissionState;\n}\n\nexport interface DetectionOptions {\n /**\n * Minimum time between two OCR runs, in milliseconds.\n * The red rectangle is updated on every frame regardless.\n * @default 300\n */\n intervalMs?: number;\n /**\n * How many consecutive OCR runs must read the same card before\n * `cardDetected` fires.\n * @default 2\n */\n stableFrames?: number;\n /**\n * Include a JPEG of the detected card in the event.\n * @default false\n */\n includeImage?: boolean;\n /**\n * Expected width / height of an upright card. Only upright cards are\n * detected; a card lying sideways falls outside the tolerance.\n * @default 0.716 (63 x 88 mm)\n */\n cardAspectRatio?: number;\n /**\n * Allowed relative deviation from `cardAspectRatio` (0.15 = ±15%).\n * Increase it if tilted cards are not detected.\n * @default 0.15\n */\n aspectTolerance?: number;\n /**\n * Smallest card size, as a fraction of the camera frame (0-1).\n * @default 0.08\n */\n minCardArea?: number;\n /**\n * Largest card size, as a fraction of the camera frame (0-1).\n * @default 0.9\n */\n maxCardArea?: number;\n /**\n * Only read text when a card-shaped object is visible. When false, the whole\n * frame is read if no card is found.\n * @default true\n */\n requireCard?: boolean;\n}\n\n/** Normalized rectangle (0-1). */\nexport interface Box {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport interface TextLine {\n text: string;\n /** Position inside the card image. */\n box: Box;\n}\n\nexport interface CardDetectedEvent {\n /** Best guess for the card name (topmost line of text on the card). */\n name?: string;\n /** Collector number, e.g. `025/165`. */\n collectorNumber?: string;\n /** All text read on the card. */\n text: string;\n lines: TextLine[];\n /** Where the card is in the camera frame. Missing if no card outline was found. */\n cardBox?: Box;\n /** Base64 JPEG of the card, when `includeImage` is true. */\n image?: string;\n}\n\nexport interface CardScannerPlugin {\n /**\n * Opens the camera **behind** the WebView. The WebView background is made\n * transparent, so the HTML page must also use transparent backgrounds\n * where the camera should be visible.\n */\n start(options?: StartOptions): Promise<void>;\n\n /** Stops the camera and removes the preview. */\n stop(): Promise<void>;\n\n /** Takes a photo from the running camera. */\n capture(options?: CaptureOptions): Promise<CaptureResult>;\n\n /** Turns the flashlight on/off. */\n setTorch(options: TorchOptions): Promise<void>;\n\n /** Sets the zoom ratio. */\n setZoom(options: ZoomOptions): Promise<void>;\n\n /** Switches between the rear and front camera. */\n flip(): Promise<void>;\n\n /**\n * Starts looking for cards: draws a red rectangle around the card and reads\n * its text, emitting `cardDetected`. Requires `start()` first. Android only.\n */\n startDetection(options?: DetectionOptions): Promise<void>;\n\n /** Stops card detection and hides the rectangle. */\n stopDetection(): Promise<void>;\n\n /** Fired once per card, when its text has been read consistently. */\n addListener(eventName: 'cardDetected', listener: (event: CardDetectedEvent) => void): Promise<PluginListenerHandle>;\n\n removeAllListeners(): Promise<void>;\n\n checkPermissions(): Promise<PermissionStatus>;\n\n requestPermissions(): Promise<PermissionStatus>;\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare class CardScannerWeb extends WebPlugin implements CardScannerPlug
|
|
|
13
13
|
capture(options?: CaptureOptions): Promise<CaptureResult>;
|
|
14
14
|
setTorch(_options: TorchOptions): Promise<void>;
|
|
15
15
|
setZoom(_options: ZoomOptions): Promise<void>;
|
|
16
|
+
startDetection(): Promise<void>;
|
|
17
|
+
stopDetection(): Promise<void>;
|
|
16
18
|
flip(): Promise<void>;
|
|
17
19
|
checkPermissions(): Promise<PermissionStatus>;
|
|
18
20
|
requestPermissions(): Promise<PermissionStatus>;
|
package/dist/esm/web.js
CHANGED
|
@@ -60,6 +60,12 @@ export class CardScannerWeb extends WebPlugin {
|
|
|
60
60
|
async setZoom(_options) {
|
|
61
61
|
throw this.unavailable('Zoom is not available on web');
|
|
62
62
|
}
|
|
63
|
+
async startDetection() {
|
|
64
|
+
throw this.unavailable('Card detection is only available on Android');
|
|
65
|
+
}
|
|
66
|
+
async stopDetection() {
|
|
67
|
+
// Nothing to stop on web.
|
|
68
|
+
}
|
|
63
69
|
async flip() {
|
|
64
70
|
await this.start({ position: this.position === 'rear' ? 'front' : 'rear' });
|
|
65
71
|
}
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAa5C;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,SAAS;IAA7C;;QACU,UAAK,GAA4B,IAAI,CAAC;QACtC,WAAM,GAAuB,IAAI,CAAC;QAClC,aAAQ,GAAmB,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAa5C;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,SAAS;IAA7C;;QACU,UAAK,GAA4B,IAAI,CAAC;QACtC,WAAM,GAAuB,IAAI,CAAC;QAClC,aAAQ,GAAmB,MAAM,CAAC;IAqF5C,CAAC;IAnFC,KAAK,CAAC,KAAK,CAAC,OAAsB;;QAChC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC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AI;QACR,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,QAA0B,EAAE,CAAC,CAAC;YACvF,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;QAClC,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,IAAI,CAAC;YACH,MAAM,CAAC,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACrE,CAAC,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YACvC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC/B,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CameraPosition,\n CaptureOptions,\n CaptureResult,\n CardScannerPlugin,\n PermissionStatus,\n StartOptions,\n TorchOptions,\n ZoomOptions,\n} from './definitions';\n\n/**\n * Browser implementation, useful for testing the layout on a desktop.\n * The <video> element is placed fixed behind the page (z-index -1).\n */\nexport class CardScannerWeb extends WebPlugin implements CardScannerPlugin {\n private video: HTMLVideoElement | null = null;\n private stream: MediaStream | null = null;\n private position: CameraPosition = 'rear';\n\n async start(options?: StartOptions): Promise<void> {\n await this.stop();\n this.position = options?.position ?? 'rear';\n\n this.stream = await navigator.mediaDevices.getUserMedia({\n video: { facingMode: this.position === 'front' ? 'user' : 'environment' },\n audio: false,\n });\n\n const video = document.createElement('video');\n video.setAttribute('playsinline', '');\n video.muted = true;\n video.autoplay = true;\n Object.assign(video.style, {\n position: 'fixed',\n inset: '0',\n width: '100%',\n height: '100%',\n objectFit: 'cover',\n zIndex: '-1',\n });\n video.srcObject = this.stream;\n document.body.appendChild(video);\n await video.play();\n this.video = video;\n }\n\n async stop(): Promise<void> {\n this.stream?.getTracks().forEach((t) => t.stop());\n this.stream = null;\n this.video?.remove();\n this.video = null;\n }\n\n async capture(options?: CaptureOptions): Promise<CaptureResult> {\n if (!this.video) throw new Error('Camera is not running');\n const canvas = document.createElement('canvas');\n canvas.width = this.video.videoWidth;\n canvas.height = this.video.videoHeight;\n canvas.getContext('2d')?.drawImage(this.video, 0, 0);\n const quality = (options?.quality ?? 85) / 100;\n const base64 = canvas.toDataURL('image/jpeg', quality).split(',')[1];\n return { base64, width: canvas.width, height: canvas.height };\n }\n\n async setTorch(_options: TorchOptions): Promise<void> {\n throw this.unavailable('Torch is not available on web');\n }\n\n async setZoom(_options: ZoomOptions): Promise<void> {\n throw this.unavailable('Zoom is not available on web');\n }\n\n async startDetection(): Promise<void> {\n throw this.unavailable('Card detection is only available on Android');\n }\n\n async stopDetection(): Promise<void> {\n // Nothing to stop on web.\n }\n\n async flip(): Promise<void> {\n await this.start({ position: this.position === 'rear' ? 'front' : 'rear' });\n }\n\n async checkPermissions(): Promise<PermissionStatus> {\n try {\n const status = await navigator.permissions.query({ name: 'camera' as PermissionName });\n return { camera: status.state };\n } catch {\n return { camera: 'prompt' };\n }\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n try {\n const s = await navigator.mediaDevices.getUserMedia({ video: true });\n s.getTracks().forEach((t) => t.stop());\n return { camera: 'granted' };\n } catch {\n return { camera: 'denied' };\n }\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -67,6 +67,12 @@ class CardScannerWeb extends core.WebPlugin {
|
|
|
67
67
|
async setZoom(_options) {
|
|
68
68
|
throw this.unavailable('Zoom is not available on web');
|
|
69
69
|
}
|
|
70
|
+
async startDetection() {
|
|
71
|
+
throw this.unavailable('Card detection is only available on Android');
|
|
72
|
+
}
|
|
73
|
+
async stopDetection() {
|
|
74
|
+
// Nothing to stop on web.
|
|
75
|
+
}
|
|
70
76
|
async flip() {
|
|
71
77
|
await this.start({ position: this.position === 'rear' ? 'front' : 'rear' });
|
|
72
78
|
}
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CardScanner = registerPlugin('CardScanner', {\n web: () => import('./web').then((m) => new m.CardScannerWeb()),\n});\nexport * from './definitions';\nexport { CardScanner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Browser implementation, useful for testing the layout on a desktop.\n * The <video> element is placed fixed behind the page (z-index -1).\n */\nexport class CardScannerWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.video = null;\n this.stream = null;\n this.position = 'rear';\n }\n async start(options) {\n var _a;\n await this.stop();\n this.position = (_a = options === null || options === void 0 ? void 0 : options.position) !== null && _a !== void 0 ? _a : 'rear';\n this.stream = await navigator.mediaDevices.getUserMedia({\n video: { facingMode: this.position === 'front' ? 'user' : 'environment' },\n audio: false,\n });\n const video = document.createElement('video');\n video.setAttribute('playsinline', '');\n video.muted = true;\n video.autoplay = true;\n Object.assign(video.style, {\n position: 'fixed',\n inset: '0',\n width: '100%',\n height: '100%',\n objectFit: 'cover',\n zIndex: '-1',\n });\n video.srcObject = this.stream;\n document.body.appendChild(video);\n await video.play();\n this.video = video;\n }\n async stop() {\n var _a, _b;\n (_a = this.stream) === null || _a === void 0 ? void 0 : _a.getTracks().forEach((t) => t.stop());\n this.stream = null;\n (_b = this.video) === null || _b === void 0 ? void 0 : _b.remove();\n this.video = null;\n }\n async capture(options) {\n var _a, _b;\n if (!this.video)\n throw new Error('Camera is not running');\n const canvas = document.createElement('canvas');\n canvas.width = this.video.videoWidth;\n canvas.height = this.video.videoHeight;\n (_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.drawImage(this.video, 0, 0);\n const quality = ((_b = options === null || options === void 0 ? void 0 : options.quality) !== null && _b !== void 0 ? _b : 85) / 100;\n const base64 = canvas.toDataURL('image/jpeg', quality).split(',')[1];\n return { base64, width: canvas.width, height: canvas.height };\n }\n async setTorch(_options) {\n throw this.unavailable('Torch is not available on web');\n }\n async setZoom(_options) {\n throw this.unavailable('Zoom is not available on web');\n }\n async flip() {\n await this.start({ position: this.position === 'rear' ? 'front' : 'rear' });\n }\n async checkPermissions() {\n try {\n const status = await navigator.permissions.query({ name: 'camera' });\n return { camera: status.state };\n }\n catch (_a) {\n return { camera: 'prompt' };\n }\n }\n async requestPermissions() {\n try {\n const s = await navigator.mediaDevices.getUserMedia({ video: true });\n s.getTracks().forEach((t) => t.stop());\n return { camera: 'granted' };\n }\n catch (_a) {\n return { camera: 'denied' };\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,WAAW,GAAGA,mBAAc,CAAC,aAAa,EAAE;AAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;AAClE,CAAC;;ACFD;AACA;AACA;AACA;AACO,MAAM,cAAc,SAASC,cAAS,CAAC;AAC9C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,KAAK,GAAG,IAAI;AACzB,QAAQ,IAAI,CAAC,MAAM,GAAG,IAAI;AAC1B,QAAQ,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AAI,EAAE,CAAC;AAChF,YAAY,CAAC,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AAClD,YAAY,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE;AACxC,QAAQ;AACR,QAAQ,OAAO,EAAE,EAAE;AACnB,YAAY,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;AACvC,QAAQ;AACR,IAAI;AACJ;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CardScanner = registerPlugin('CardScanner', {\n web: () => import('./web').then((m) => new m.CardScannerWeb()),\n});\nexport * from './definitions';\nexport { CardScanner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Browser implementation, useful for testing the layout on a desktop.\n * The <video> element is placed fixed behind the page (z-index -1).\n */\nexport class CardScannerWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.video = null;\n this.stream = null;\n this.position = 'rear';\n }\n async start(options) {\n var _a;\n await this.stop();\n this.position = (_a = options === null || options === void 0 ? void 0 : options.position) !== null && _a !== void 0 ? _a : 'rear';\n this.stream = await navigator.mediaDevices.getUserMedia({\n video: { facingMode: this.position === 'front' ? 'user' : 'environment' },\n audio: false,\n });\n const video = document.createElement('video');\n video.setAttribute('playsinline', '');\n video.muted = true;\n video.autoplay = true;\n Object.assign(video.style, {\n position: 'fixed',\n inset: '0',\n width: '100%',\n height: '100%',\n objectFit: 'cover',\n zIndex: '-1',\n });\n video.srcObject = this.stream;\n document.body.appendChild(video);\n await video.play();\n this.video = video;\n }\n async stop() {\n var _a, _b;\n (_a = this.stream) === null || _a === void 0 ? void 0 : _a.getTracks().forEach((t) => t.stop());\n this.stream = null;\n (_b = this.video) === null || _b === void 0 ? void 0 : _b.remove();\n this.video = null;\n }\n async capture(options) {\n var _a, _b;\n if (!this.video)\n throw new Error('Camera is not running');\n const canvas = document.createElement('canvas');\n canvas.width = this.video.videoWidth;\n canvas.height = this.video.videoHeight;\n (_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.drawImage(this.video, 0, 0);\n const quality = ((_b = options === null || options === void 0 ? void 0 : options.quality) !== null && _b !== void 0 ? _b : 85) / 100;\n const base64 = canvas.toDataURL('image/jpeg', quality).split(',')[1];\n return { base64, width: canvas.width, height: canvas.height };\n }\n async setTorch(_options) {\n throw this.unavailable('Torch is not available on web');\n }\n async setZoom(_options) {\n throw this.unavailable('Zoom is not available on web');\n }\n async startDetection() {\n throw this.unavailable('Card detection is only available on Android');\n }\n async stopDetection() {\n // Nothing to stop on web.\n }\n async flip() {\n await this.start({ position: this.position === 'rear' ? 'front' : 'rear' });\n }\n async checkPermissions() {\n try {\n const status = await navigator.permissions.query({ name: 'camera' });\n return { camera: status.state };\n }\n catch (_a) {\n return { camera: 'prompt' };\n }\n }\n async requestPermissions() {\n try {\n const s = await navigator.mediaDevices.getUserMedia({ video: true });\n s.getTracks().forEach((t) => t.stop());\n return { camera: 'granted' };\n }\n catch (_a) {\n return { camera: 'denied' };\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,WAAW,GAAGA,mBAAc,CAAC,aAAa,EAAE;AAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;AAClE,CAAC;;ACFD;AACA;AACA;AACA;AACO,MAAM,cAAc,SAASC,cAAS,CAAC;AAC9C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,KAAK,GAAG,IAAI;AACzB,QAAQ,IAAI,CAAC,MAAM,GAAG,IAAI;AAC1B,QAAQ,IAAI,CAAC,QAAQ,GAAG,MAAM;AAC9B,IAAI;AACJ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Q,IAAI;AACZ,YAAY,MAAM,CAAC,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAChF,YAAY,CAAC,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AAClD,YAAY,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE;AACxC,QAAQ;AACR,QAAQ,OAAO,EAAE,EAAE;AACnB,YAAY,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;AACvC,QAAQ;AACR,IAAI;AACJ;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -66,6 +66,12 @@ var capacitorCardScanner = (function (exports, core) {
|
|
|
66
66
|
async setZoom(_options) {
|
|
67
67
|
throw this.unavailable('Zoom is not available on web');
|
|
68
68
|
}
|
|
69
|
+
async startDetection() {
|
|
70
|
+
throw this.unavailable('Card detection is only available on Android');
|
|
71
|
+
}
|
|
72
|
+
async stopDetection() {
|
|
73
|
+
// Nothing to stop on web.
|
|
74
|
+
}
|
|
69
75
|
async flip() {
|
|
70
76
|
await this.start({ position: this.position === 'rear' ? 'front' : 'rear' });
|
|
71
77
|
}
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CardScanner = registerPlugin('CardScanner', {\n web: () => import('./web').then((m) => new m.CardScannerWeb()),\n});\nexport * from './definitions';\nexport { CardScanner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Browser implementation, useful for testing the layout on a desktop.\n * The <video> element is placed fixed behind the page (z-index -1).\n */\nexport class CardScannerWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.video = null;\n this.stream = null;\n this.position = 'rear';\n }\n async start(options) {\n var _a;\n await this.stop();\n this.position = (_a = options === null || options === void 0 ? void 0 : options.position) !== null && _a !== void 0 ? _a : 'rear';\n this.stream = await navigator.mediaDevices.getUserMedia({\n video: { facingMode: this.position === 'front' ? 'user' : 'environment' },\n audio: false,\n });\n const video = document.createElement('video');\n video.setAttribute('playsinline', '');\n video.muted = true;\n video.autoplay = true;\n Object.assign(video.style, {\n position: 'fixed',\n inset: '0',\n width: '100%',\n height: '100%',\n objectFit: 'cover',\n zIndex: '-1',\n });\n video.srcObject = this.stream;\n document.body.appendChild(video);\n await video.play();\n this.video = video;\n }\n async stop() {\n var _a, _b;\n (_a = this.stream) === null || _a === void 0 ? void 0 : _a.getTracks().forEach((t) => t.stop());\n this.stream = null;\n (_b = this.video) === null || _b === void 0 ? void 0 : _b.remove();\n this.video = null;\n }\n async capture(options) {\n var _a, _b;\n if (!this.video)\n throw new Error('Camera is not running');\n const canvas = document.createElement('canvas');\n canvas.width = this.video.videoWidth;\n canvas.height = this.video.videoHeight;\n (_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.drawImage(this.video, 0, 0);\n const quality = ((_b = options === null || options === void 0 ? void 0 : options.quality) !== null && _b !== void 0 ? _b : 85) / 100;\n const base64 = canvas.toDataURL('image/jpeg', quality).split(',')[1];\n return { base64, width: canvas.width, height: canvas.height };\n }\n async setTorch(_options) {\n throw this.unavailable('Torch is not available on web');\n }\n async setZoom(_options) {\n throw this.unavailable('Zoom is not available on web');\n }\n async flip() {\n await this.start({ position: this.position === 'rear' ? 'front' : 'rear' });\n }\n async checkPermissions() {\n try {\n const status = await navigator.permissions.query({ name: 'camera' });\n return { camera: status.state };\n }\n catch (_a) {\n return { camera: 'prompt' };\n }\n }\n async requestPermissions() {\n try {\n const s = await navigator.mediaDevices.getUserMedia({ video: true });\n s.getTracks().forEach((t) => t.stop());\n return { camera: 'granted' };\n }\n catch (_a) {\n return { camera: 'denied' };\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,W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C,WAAW,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAChF,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE;IAC3C,QAAQ;IACR,QAAQ,OAAO,EAAE,EAAE;IACnB,YAAY,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;IACvC,QAAQ;IACR,IAAI;IACJ,IAAI,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,IAAI;IACZ,YAAY,MAAM,CAAC,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAChF,YAAY,CAAC,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,YAAY,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE;IACxC,QAAQ;IACR,QAAQ,OAAO,EAAE,EAAE;IACnB,YAAY,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;IACvC,QAAQ;IACR,IAAI;IACJ;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CardScanner = registerPlugin('CardScanner', {\n web: () => import('./web').then((m) => new m.CardScannerWeb()),\n});\nexport * from './definitions';\nexport { CardScanner };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Browser implementation, useful for testing the layout on a desktop.\n * The <video> element is placed fixed behind the page (z-index -1).\n */\nexport class CardScannerWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.video = null;\n this.stream = null;\n this.position = 'rear';\n }\n async start(options) {\n var _a;\n await this.stop();\n this.position = (_a = options === null || options === void 0 ? void 0 : options.position) !== null && _a !== void 0 ? _a : 'rear';\n this.stream = await navigator.mediaDevices.getUserMedia({\n video: { facingMode: this.position === 'front' ? 'user' : 'environment' },\n audio: false,\n });\n const video = document.createElement('video');\n video.setAttribute('playsinline', '');\n video.muted = true;\n video.autoplay = true;\n Object.assign(video.style, {\n position: 'fixed',\n inset: '0',\n width: '100%',\n height: '100%',\n objectFit: 'cover',\n zIndex: '-1',\n });\n video.srcObject = this.stream;\n document.body.appendChild(video);\n await video.play();\n this.video = video;\n }\n async stop() {\n var _a, _b;\n (_a = this.stream) === null || _a === void 0 ? void 0 : _a.getTracks().forEach((t) => t.stop());\n this.stream = null;\n (_b = this.video) === null || _b === void 0 ? void 0 : _b.remove();\n this.video = null;\n }\n async capture(options) {\n var _a, _b;\n if (!this.video)\n throw new Error('Camera is not running');\n const canvas = document.createElement('canvas');\n canvas.width = this.video.videoWidth;\n canvas.height = this.video.videoHeight;\n (_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.drawImage(this.video, 0, 0);\n const quality = ((_b = options === null || options === void 0 ? void 0 : options.quality) !== null && _b !== void 0 ? _b : 85) / 100;\n const base64 = canvas.toDataURL('image/jpeg', quality).split(',')[1];\n return { base64, width: canvas.width, height: canvas.height };\n }\n async setTorch(_options) {\n throw this.unavailable('Torch is not available on web');\n }\n async setZoom(_options) {\n throw this.unavailable('Zoom is not available on web');\n }\n async startDetection() {\n throw this.unavailable('Card detection is only available on Android');\n }\n async stopDetection() {\n // Nothing to stop on web.\n }\n async flip() {\n await this.start({ position: this.position === 'rear' ? 'front' : 'rear' });\n }\n async checkPermissions() {\n try {\n const status = await navigator.permissions.query({ name: 'camera' });\n return { camera: status.state };\n }\n catch (_a) {\n return { camera: 'prompt' };\n }\n }\n async requestPermissions() {\n try {\n const s = await navigator.mediaDevices.getUserMedia({ video: true });\n s.getTracks().forEach((t) => t.stop());\n return { camera: 'granted' };\n }\n catch (_a) {\n return { camera: 'denied' };\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,WAAW,GAAGA,mBAAc,CAAC,aAAa,EAAE;IAClD,IAAI,G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