@capturebridge/sdk 0.7.0 → 0.8.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/Scanner.js CHANGED
@@ -1,64 +1,55 @@
1
- import CapturePlugin from './CapturePlugin.js'
2
- import { BASE_URL } from './Common.js'
3
-
4
- /**
5
- * Scanner
6
- * @classdesc Class for invoking methods on a Scanner
7
- *
8
- * @see {@link CanonScanner}
9
- */
10
- class Scanner extends CapturePlugin {
11
- /**
12
- * Instantiate a Generic Scanner
13
- * @constructor
14
- * @param {string} [baseURL] - Protocol, domain, and port for the service.
15
- * @param {string} pluginId - The Id of the desired plugin to use for this
16
- * scanner instance. The plugin must support the "devices", and "capture"
17
- * methods.
18
- * @example
19
- * const scanner = new Scanner('capture_scanner_windows')
20
- */
21
- constructor (plugin, baseUrl = BASE_URL) {
22
- super(plugin, baseUrl)
23
- }
24
-
25
- /**
26
- * Scan a document
27
- * @param {string} [kind] - Specify how to return the scanned document. Valid
28
- * values are 'blob', 'buffer', 'base64', or 'dataurl'.
29
- *
30
- * The default value of 'buffer' will load the image into an
31
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer|ArrayBuffer}
32
- * that can be set directly on an img tag's src attribute.
33
- *
34
- * The value of 'blob' will return a
35
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob} that can
36
- * be used with a
37
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader|FileReader}.
38
- *
39
- * The value of 'base64' will return the image contents as a
40
- * {@link https://en.wikipedia.org/wiki/Base64|Base64} encoded string that is
41
- * suitable for use with JSON serialization.
42
- *
43
- * The value of 'dataurl' will return a JPEG
44
- * {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
45
- * that can be set on an img tag's src attribute or loaded as a document
46
- * location.
47
- *
48
- * @param {string|object} [deviceOpt] - Can a document using either a specific
49
- * Device ID or a Device Object. The default is the first available device.
50
- *
51
- * @async
52
- * @example
53
- * // Scan document as an ArrayBuffer and add it to an img tag appended to
54
- * // the document's body.
55
- * const img = document.createElement('img')
56
- * img.src = await scanner.scan()
57
- * document.body.appendChild(img)
58
- */
59
- async scan (kind = 'buffer', deviceOpt) {
60
- return await this.fullCapture(kind, deviceOpt)
61
- }
62
- }
63
-
64
- export default Scanner
1
+ import CapturePlugin from './CapturePlugin.js'
2
+ import { BASE_URL, DEFAULT_CAPTURE_OPT, DEPRECATION_01 } from './Common.js'
3
+
4
+ /**
5
+ * Scanner
6
+ * @classdesc Class for invoking methods on a Scanner
7
+ *
8
+ * @see {@link CanonScanner}
9
+ */
10
+ class Scanner extends CapturePlugin {
11
+ /**
12
+ * Instantiate a Generic Scanner
13
+ * @constructor
14
+ * @param {string} [baseURL] - Protocol, domain, and port for the service.
15
+ * @param {string} pluginId - The Id of the desired plugin to use for this
16
+ * scanner instance. The plugin must support the "devices", and "capture"
17
+ * methods.
18
+ * @example
19
+ * const scanner = new Scanner('capture_scanner_windows')
20
+ */
21
+ constructor (plugin, baseUrl = BASE_URL) {
22
+ super(plugin, baseUrl)
23
+ }
24
+
25
+ /**
26
+ * Scan a document
27
+ *
28
+ * @param {CaptureOptions} [captureOpt] - Additional options for capturing a
29
+ * signature.
30
+ *
31
+ * @param {string|object} [deviceOpt] - Can a document using either a specific
32
+ * Device ID or a Device Object. The default is the first available device.
33
+ *
34
+ * @async
35
+ * @example
36
+ * // Scan document as an ArrayBuffer and add it to an img tag appended to
37
+ * // the document's body.
38
+ * const img = document.createElement('img')
39
+ * img.src = await scanner.scan()
40
+ * document.body.appendChild(img)
41
+ */
42
+ async scan (captureOpt = {}, deviceOpt) {
43
+ if (typeof captureOpt === 'string' && DEPRECATION_01) {
44
+ captureOpt = { kind: captureOpt }
45
+ console.warn('CaptureBridge SDK Deprecation Warning: `Scanner.scan()` ' +
46
+ 'converted the `captureOpt` argument from a string (%s) to an object ' +
47
+ '(%s). This conversion may not be performed in future SDK versions.',
48
+ captureOpt.kind, JSON.stringify(captureOpt))
49
+ }
50
+ const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
51
+ return await this.fullCapture(mergedOpt, deviceOpt)
52
+ }
53
+ }
54
+
55
+ export default Scanner
@@ -1,109 +1,108 @@
1
- import StreamingCapturePlugin from './StreamingCapturePlugin.js'
2
- import { BASE_URL } from './Common.js'
3
-
4
- class SignatureTablet extends StreamingCapturePlugin {
5
- #captureBridge
6
- #scene = {}
7
-
8
- constructor (plugin, baseUrl = BASE_URL) {
9
- super(plugin, baseUrl)
10
- }
11
-
12
- /**
13
- * Clear the tablet's display.
14
- *
15
- * @description This method will set the tablet's LCD screen to an empty white
16
- * background. The blacklight will also be enabled if it is not already.
17
- *
18
- * @param {boolean} [backlight] If provided and set to true, will enable
19
- * backlight. If false, it will be disabled. If unspecified no action will be
20
- * taken on the backlight.
21
- *
22
- * @param {string|object} [deviceOpt] - Clear the display of a either a
23
- * specific Device ID or a Device Object. The default is the first available
24
- * device.
25
- *
26
- * @async
27
- * @method
28
- * @returns {object}
29
- * @example
30
- * const img = document.createElement('img')
31
- * img.src = await camera.streamUrl()
32
- * document.body.appendChild(img)
33
- */
34
- async clear (backlight, deviceOpt) {
35
- const device = await this.setupDevice(deviceOpt)
36
- return device.clear(backlight)
37
- }
38
-
39
- /**
40
- * Display an Array of objects on the display.
41
- *
42
- * @description If any objects are Button types, the method will wait for one
43
- * to be clicked and will then return the ID of the clicked object.
44
- *
45
- * @param {object[]} objects An array of Signature Tablet Widgets to display.
46
- *
47
- * @param {boolean} [clear] If true (the default), the display will be cleared
48
- * before adding the objects.
49
- *
50
- * @param {string|object} [deviceOpt] - Display the objects on either a
51
- * specific Device ID or a Device Object. The default is the first available
52
- * device.
53
- *
54
- * @async
55
- * @method
56
- * @returns {string?} ID of the clicked object if any
57
- * @example
58
- * const result = await tablet.displayObjects([
59
- * new Button("OK", 20, 200),
60
- * new Button("Cancel", 80, 200)
61
- * ])
62
- *
63
- * console.log(`${result} was clicked`)
64
- */
65
- async displayObjects (objects, clear = true, deviceOpt) {
66
- const device = await this.setupDevice(deviceOpt)
67
- return device.displayObjects(objects, clear)
68
- }
69
-
70
- /**
71
- * Capture a high resolution signature
72
- * @param {string} [kind] - Specify how to return the captured photo. Valid
73
- * values are 'blob', 'buffer', 'base64', or 'dataurl'.
74
- *
75
- * The default value of 'buffer' will load the image into an
76
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer|ArrayBuffer}
77
- * that can be set directly on an img tag's src attribute.
78
- *
79
- * The value of 'blob' will return a
80
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob} that can
81
- * be used with a
82
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader|FileReader}.
83
- *
84
- * The value of 'base64' will return the image contents as a
85
- * {@link https://en.wikipedia.org/wiki/Base64|Base64} encoded string that is
86
- * suitable for use with JSON serialization.
87
- *
88
- * The value of 'dataurl' will return a JPEG
89
- * {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
90
- * that can be set on an img tag's src attribute or loaded as a document
91
- * location.
92
- *
93
- * @param {string|object} [deviceOpt] - Capture the signature using either a
94
- * specific Device ID or a Device Object. The default is the first available device.
95
- *
96
- * @async
97
- * @example
98
- * // Capture signature as an ArrayBuffer and add it to an img tag appended to
99
- * // the document's body.
100
- * const img = document.createElement('img')
101
- * img.src = await tablet.signature()
102
- * document.body.appendChild(img)
103
- */
104
- async signature (kind = 'buffer', deviceOpt) {
105
- return await this.fullCapture(kind, deviceOpt)
106
- }
107
- }
108
-
109
- export default SignatureTablet
1
+ import StreamingCapturePlugin from './StreamingCapturePlugin.js'
2
+ import { BASE_URL, DEFAULT_CAPTURE_OPT, DEPRECATION_01 } from './Common.js'
3
+
4
+ /**
5
+ * SignatureTablet
6
+ * @classdesc Class for invoking methods on a Signature Capture Tablet
7
+ * @extends StreamingCapturePlugin
8
+ * @see {@link TopazSigGem}
9
+ */
10
+ class SignatureTablet extends StreamingCapturePlugin {
11
+ #captureBridge
12
+ #scene = {}
13
+
14
+ constructor (plugin, baseUrl = BASE_URL) {
15
+ super(plugin, baseUrl)
16
+ }
17
+
18
+ /**
19
+ * Clear the tablet's display.
20
+ *
21
+ * @description This method will set the tablet's LCD screen to an empty white
22
+ * background. The blacklight will also be enabled if it is not already.
23
+ *
24
+ * @param {boolean} [backlight] If provided and set to true, will enable
25
+ * backlight. If false, it will be disabled. If unspecified no action will be
26
+ * taken on the backlight.
27
+ *
28
+ * @param {string|object} [deviceOpt] - Clear the display of a either a
29
+ * specific Device ID or a Device Object. The default is the first available
30
+ * device.
31
+ *
32
+ * @async
33
+ * @method
34
+ * @returns {object}
35
+ * @example
36
+ * const img = document.createElement('img')
37
+ * img.src = await camera.streamUrl()
38
+ * document.body.appendChild(img)
39
+ */
40
+ async clear (backlight, deviceOpt) {
41
+ const device = await this.setupDevice(deviceOpt)
42
+ return device.clear(backlight)
43
+ }
44
+
45
+ /**
46
+ * Display an Array of objects on the display.
47
+ *
48
+ * @description If any objects are Button types, the method will wait for one
49
+ * to be clicked and will then return the ID of the clicked object.
50
+ *
51
+ * @param {object[]} objects An array of Signature Tablet Widgets to display.
52
+ *
53
+ * @param {boolean} [clear] If true (the default), the display will be cleared
54
+ * before adding the objects.
55
+ *
56
+ * @param {string|object} [deviceOpt] - Display the objects on either a
57
+ * specific Device ID or a Device Object. The default is the first available
58
+ * device.
59
+ *
60
+ * @async
61
+ * @method
62
+ * @returns {string?} ID of the clicked object if any
63
+ * @example
64
+ * const result = await tablet.displayObjects([
65
+ * new Button("OK", 20, 200),
66
+ * new Button("Cancel", 80, 200)
67
+ * ])
68
+ *
69
+ * console.log(`${result} was clicked`)
70
+ */
71
+ async displayObjects (objects, clear = true, deviceOpt) {
72
+ const device = await this.setupDevice(deviceOpt)
73
+ return device.displayObjects(objects, clear)
74
+ }
75
+
76
+ /**
77
+ * Capture a high resolution signature
78
+ *
79
+ * @param {CaptureOptions} [captureOpt] - Additional options for capturing a
80
+ * signature.
81
+ *
82
+ * @param {string|object} [deviceOpt] - Capture the signature using either a
83
+ * specific Device ID or a Device Object. The default is the first available
84
+ * device.
85
+ *
86
+ * @async
87
+ * @example
88
+ * // Capture signature as an ArrayBuffer and add it to an img tag appended to
89
+ * // the document's body.
90
+ * const img = document.createElement('img')
91
+ * img.src = await tablet.signature()
92
+ * document.body.appendChild(img)
93
+ */
94
+ async signature (captureOpt = {}, deviceOpt) {
95
+ if (typeof captureOpt === 'string' && DEPRECATION_01) {
96
+ captureOpt = { kind: captureOpt }
97
+ console.warn('CaptureBridge SDK Deprecation Warning: ' +
98
+ '`SignatureTablet.signature()` converted the `captureOpt` argument ' +
99
+ 'from a string (%s) to an object (%s). This conversion may not be ' +
100
+ 'performed in future SDK versions.',
101
+ captureOpt.kind, JSON.stringify(captureOpt))
102
+ }
103
+ const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
104
+ return await this.fullCapture(mergedOpt, deviceOpt)
105
+ }
106
+ }
107
+
108
+ export default SignatureTablet