@capturebridge/sdk 0.12.1 → 0.14.2

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,55 +1,55 @@
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
+ 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,108 +1,86 @@
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
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
+ constructor (plugin, baseUrl = BASE_URL) {
12
+ super(plugin, baseUrl)
13
+ }
14
+
15
+ /**
16
+ * @description Clear a signature tablet's display.
17
+ *
18
+ * @param {boolean} [backlight=false] If `true`, the device's backlight will be
19
+ * enabled. If `false`, it will be disabled. If unspecified no action will be
20
+ * taken on the backlight.
21
+ *
22
+ * @param {string|Device} [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
+ */
30
+ async clear (backlight, deviceOpt) {
31
+ const device = await this.setupDevice(deviceOpt)
32
+ return device.clear(backlight)
33
+ }
34
+
35
+ /**
36
+ * Render an Array of Objects on the display and wait for user input.
37
+ *
38
+ * @description If any Objects are Buttons, the method will wait for one
39
+ * to be clicked and will then return results. The format of the Array of
40
+ * Objects, the response structure, and the scene options are plugin specific.
41
+ *
42
+ * @param {Object[]} objects An array of drawable objects to display.
43
+ * @param {Object} [sceneOpt] Options for configuring the scene.
44
+ *
45
+ * @async
46
+ * @method
47
+ * @returns {object?}
48
+ */
49
+ async displayObjects (objects, sceneOpt = {}, deviceOpt) {
50
+ const device = await this.setupDevice(deviceOpt)
51
+ return device.displayObjects(objects, sceneOpt)
52
+ }
53
+
54
+ /**
55
+ * Capture a high resolution signature.
56
+ *
57
+ * @param {CaptureOptions} [captureOpt] - Additional options for capturing a
58
+ * signature.
59
+ *
60
+ * @param {string|object} [deviceOpt] - Capture the signature using either a
61
+ * specific Device ID or a Device Object. The default is the first available
62
+ * device.
63
+ *
64
+ * @async
65
+ * @example
66
+ * // Capture signature as an ArrayBuffer and add it to an img tag appended to
67
+ * // the document's body.
68
+ * const img = document.createElement('img')
69
+ * img.src = await tablet.signature()
70
+ * document.body.appendChild(img)
71
+ */
72
+ async signature (captureOpt = {}, deviceOpt) {
73
+ if (typeof captureOpt === 'string' && DEPRECATION_01) {
74
+ captureOpt = { kind: captureOpt }
75
+ console.warn('CaptureBridge SDK Deprecation Warning: ' +
76
+ '`SignatureTablet.signature()` converted the `captureOpt` argument ' +
77
+ 'from a string (%s) to an object (%s). This conversion may not be ' +
78
+ 'performed in future SDK versions.',
79
+ captureOpt.kind, JSON.stringify(captureOpt))
80
+ }
81
+ const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
82
+ return await this.fullCapture(mergedOpt, deviceOpt)
83
+ }
84
+ }
85
+
86
+ export default SignatureTablet
@@ -1,164 +1,164 @@
1
- /**
2
- * @module SignatureTabletWidgets
3
- */
4
-
5
- import { blobToBase64 } from './Common.js'
6
-
7
- /**
8
- * DisplayWidget
9
- * @classdesc Represents a widget that can be displayed at some x and y coordinates
10
- * @see {@link TextButton}
11
- * @see {@link Text}
12
- * @see {@link Image}
13
- */
14
- export class DisplayWidget {
15
- x
16
- y
17
- constructor (x, y) {
18
- this.x = x
19
- this.y = y
20
- }
21
- }
22
-
23
- /**
24
- * TextButton
25
- * @classdesc A button for displaying clickable text on a tablet
26
- * @extends DisplayWidget
27
- * @see {@link SignatureTablet}
28
- */
29
- export class TextButton extends DisplayWidget {
30
- text
31
- fontFace
32
- fontSize
33
- id
34
- /**
35
- * Instantiate a Tablet Text Button
36
- * @constructor
37
- * @param {string} text - Text to display on the button
38
- * @param {number} x - X position to draw the button
39
- * @param {number} y - Y position to draw the button
40
- * @param {text} [id] - ID of the button that will be returned when it is
41
- * clicked. If not set one will attempt to be constructed from the button
42
- * text but there is no guarantee it will be unique.
43
- * @param {string} [fontFace] - Font face for the text on the button.
44
- * Defaults to 'Arial'
45
- * @param {number} [fontSize] - Size of the font for the text on the button.
46
- * Defaults to 40.
47
- * @example
48
- * const new TextButton("OK", 20, 200)
49
- */
50
- constructor (text, x, y, id, fontFace = 'Arial', fontSize = 40) {
51
- super(x, y)
52
- this.text = text
53
- this.fontFace = fontFace
54
- this.fontSize = fontSize
55
- if (id) {
56
- this.id = id
57
- } else {
58
- this.id = text.length > 16 ? text.slice(0, 16) : text
59
- }
60
- }
61
-
62
- toJSON () {
63
- return {
64
- type: 'button',
65
- text: this.text,
66
- font_face: this.fontFace,
67
- font_size: this.fontSize,
68
- x: this.x,
69
- y: this.y,
70
- id: this.id
71
- }
72
- }
73
- }
74
-
75
- /**
76
- * Text
77
- * @classdesc Text to be displayed on a tablet
78
- * @extends DisplayWidget
79
- * @see {@link SignatureTablet}
80
- */
81
- export class Text extends DisplayWidget {
82
- text
83
- fontFace
84
- fontSize
85
- /**
86
- * Instantiate a Text object
87
- * @constructor
88
- * @param {string} text - Text to display on the button
89
- * @param {number} x - X position to draw the button
90
- * @param {number} y - Y position to draw the button
91
- * @param {string} [fontFace] - Font face for the text on the button.
92
- * Defaults to 'Arial'
93
- * @param {number} [fontSize] - Size of the font for the text on the button.
94
- * Defaults to 40.
95
- * @example
96
- * const new Text("Do you agree?", 20, 200)
97
- */
98
- constructor (text, x, y, fontFace = 'Arial', fontSize = 40) {
99
- super(x, y)
100
- this.text = text
101
- this.fontFace = fontFace
102
- this.fontSize = fontSize
103
- }
104
-
105
- toJSON () {
106
- return {
107
- type: 'text',
108
- text: this.text,
109
- font_face: this.fontFace,
110
- font_size: this.fontSize,
111
- x: this.x,
112
- y: this.y
113
- }
114
- }
115
- }
116
-
117
- /**
118
- * Image
119
- * @classdesc Image to be displayed on a tablet
120
- * @extends DisplayWidget
121
- * @see {@link SignatureTablet}
122
- */
123
- export class Image extends DisplayWidget {
124
- url
125
- imageData
126
- delay
127
- /**
128
- * Instantiate an Image object
129
- * @constructor
130
- * @param {string} url - URL of the image.
131
- * @param {number} [x] - X position to draw the button
132
- * @param {number} [y] - Y position to draw the button
133
- * @param {number} [delay] - Milliseconds to sleep after displaying the image
134
- * @example
135
- * const new Image("/img/logo.tif", 20, 200)
136
- */
137
- constructor (url, x = 0, y = 0, delay = 0) {
138
- super(x, y)
139
- this.url = url
140
- this.delay = delay
141
- }
142
-
143
- /**
144
- * Fetch the image data and base64 encode it
145
- * @async
146
- * @example
147
- * const new Image("/img/logo.tif", 20, 200)
148
- */
149
- async data () {
150
- const response = await fetch(this.url)
151
- const blob = await response.blob()
152
- this.imageData = await blobToBase64(blob)
153
- }
154
-
155
- toJSON () {
156
- return {
157
- type: 'image',
158
- data: this.imageData,
159
- delay: this.delay,
160
- x: this.x,
161
- y: this.y
162
- }
163
- }
164
- }
1
+ /**
2
+ * @module SignatureTabletWidgets
3
+ */
4
+
5
+ import { blobToBase64 } from './Common.js'
6
+
7
+ /**
8
+ * DisplayWidget
9
+ * @classdesc Represents a widget that can be displayed at some x and y coordinates
10
+ * @see {@link TextButton}
11
+ * @see {@link Text}
12
+ * @see {@link Image}
13
+ */
14
+ export class DisplayWidget {
15
+ x
16
+ y
17
+ constructor (x, y) {
18
+ this.x = x
19
+ this.y = y
20
+ }
21
+ }
22
+
23
+ /**
24
+ * TextButton
25
+ * @classdesc A button for displaying clickable text on a tablet
26
+ * @extends DisplayWidget
27
+ * @see {@link SignatureTablet}
28
+ */
29
+ export class TextButton extends DisplayWidget {
30
+ text
31
+ fontFace
32
+ fontSize
33
+ id
34
+ /**
35
+ * Instantiate a Tablet Text Button
36
+ * @constructor
37
+ * @param {string} text - Text to display on the button
38
+ * @param {number} x - X position to draw the button
39
+ * @param {number} y - Y position to draw the button
40
+ * @param {text} [id] - ID of the button that will be returned when it is
41
+ * clicked. If not set one will attempt to be constructed from the button
42
+ * text but there is no guarantee it will be unique.
43
+ * @param {string} [fontFace] - Font face for the text on the button.
44
+ * Defaults to 'Arial'
45
+ * @param {number} [fontSize] - Size of the font for the text on the button.
46
+ * Defaults to 40.
47
+ * @example
48
+ * const new TextButton("OK", 20, 200)
49
+ */
50
+ constructor (text, x, y, id, fontFace = 'Arial', fontSize = 40) {
51
+ super(x, y)
52
+ this.text = text
53
+ this.fontFace = fontFace
54
+ this.fontSize = fontSize
55
+ if (id) {
56
+ this.id = id
57
+ } else {
58
+ this.id = text.length > 16 ? text.slice(0, 16) : text
59
+ }
60
+ }
61
+
62
+ toJSON () {
63
+ return {
64
+ type: 'button',
65
+ text: this.text,
66
+ font_face: this.fontFace,
67
+ font_size: this.fontSize,
68
+ x: this.x,
69
+ y: this.y,
70
+ id: this.id
71
+ }
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Text
77
+ * @classdesc Text to be displayed on a tablet
78
+ * @extends DisplayWidget
79
+ * @see {@link SignatureTablet}
80
+ */
81
+ export class Text extends DisplayWidget {
82
+ text
83
+ fontFace
84
+ fontSize
85
+ /**
86
+ * Instantiate a Text object
87
+ * @constructor
88
+ * @param {string} text - Text to display on the button
89
+ * @param {number} x - X position to draw the button
90
+ * @param {number} y - Y position to draw the button
91
+ * @param {string} [fontFace] - Font face for the text on the button.
92
+ * Defaults to 'Arial'
93
+ * @param {number} [fontSize] - Size of the font for the text on the button.
94
+ * Defaults to 40.
95
+ * @example
96
+ * const new Text("Do you agree?", 20, 200)
97
+ */
98
+ constructor (text, x, y, fontFace = 'Arial', fontSize = 40) {
99
+ super(x, y)
100
+ this.text = text
101
+ this.fontFace = fontFace
102
+ this.fontSize = fontSize
103
+ }
104
+
105
+ toJSON () {
106
+ return {
107
+ type: 'text',
108
+ text: this.text,
109
+ font_face: this.fontFace,
110
+ font_size: this.fontSize,
111
+ x: this.x,
112
+ y: this.y
113
+ }
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Image
119
+ * @classdesc Image to be displayed on a tablet
120
+ * @extends DisplayWidget
121
+ * @see {@link SignatureTablet}
122
+ */
123
+ export class Image extends DisplayWidget {
124
+ url
125
+ imageData
126
+ delay
127
+ /**
128
+ * Instantiate an Image object
129
+ * @constructor
130
+ * @param {string} url - URL of the image.
131
+ * @param {number} [x] - X position to draw the button
132
+ * @param {number} [y] - Y position to draw the button
133
+ * @param {number} [delay] - Milliseconds to sleep after displaying the image
134
+ * @example
135
+ * const new Image("/img/logo.tif", 20, 200)
136
+ */
137
+ constructor (url, x = 0, y = 0, delay = 0) {
138
+ super(x, y)
139
+ this.url = url
140
+ this.delay = delay
141
+ }
142
+
143
+ /**
144
+ * Fetch the image data and base64 encode it
145
+ * @async
146
+ * @example
147
+ * const new Image("/img/logo.tif", 20, 200)
148
+ */
149
+ async data () {
150
+ const response = await fetch(this.url)
151
+ const blob = await response.blob()
152
+ this.imageData = await blobToBase64(blob)
153
+ }
154
+
155
+ toJSON () {
156
+ return {
157
+ type: 'image',
158
+ data: this.imageData,
159
+ delay: this.delay,
160
+ x: this.x,
161
+ y: this.y
162
+ }
163
+ }
164
+ }