@capturebridge/sdk 0.7.0 → 0.7.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/Camera.js +68 -68
- package/CanonCamera.js +25 -25
- package/CaptureBridge.js +162 -162
- package/CapturePlugin.js +79 -79
- package/Common.js +98 -98
- package/Device.js +451 -451
- package/ICAO.js +70 -70
- package/IFace.js +274 -274
- package/Logs.js +129 -129
- package/MockCamera.js +10 -10
- package/Plugin.js +298 -298
- package/Scanner.js +64 -64
- package/SignatureTablet.js +109 -109
- package/SignatureTabletWidgets.js +153 -153
- package/StreamingCapturePlugin.js +121 -121
- package/TopazSigGem.js +25 -25
- package/package.json +1 -1
package/Scanner.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
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 } 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
|
package/SignatureTablet.js
CHANGED
|
@@ -1,109 +1,109 @@
|
|
|
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 } 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,153 +1,153 @@
|
|
|
1
|
-
import { blobToBase64 } from './Common.js'
|
|
2
|
-
|
|
3
|
-
export class DisplayWidget {
|
|
4
|
-
x
|
|
5
|
-
y
|
|
6
|
-
constructor (x, y) {
|
|
7
|
-
this.x = x
|
|
8
|
-
this.y = y
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* TextButton
|
|
14
|
-
* @classdesc A button for displaying clickable text on a tablet
|
|
15
|
-
*
|
|
16
|
-
* @see {@link SignatureTablet}
|
|
17
|
-
*/
|
|
18
|
-
export class TextButton extends DisplayWidget {
|
|
19
|
-
text
|
|
20
|
-
fontFace
|
|
21
|
-
fontSize
|
|
22
|
-
id
|
|
23
|
-
/**
|
|
24
|
-
* Instantiate a Tablet Text Button
|
|
25
|
-
* @constructor
|
|
26
|
-
* @param {string} text - Text to display on the button
|
|
27
|
-
* @param {number} x - X position to draw the button
|
|
28
|
-
* @param {number} y - Y position to draw the button
|
|
29
|
-
* @param {text} [id] - ID of the button that will be returned when it is
|
|
30
|
-
* clicked. If not set one will attempt to be constructed from the button
|
|
31
|
-
* text but there is no guarantee it will be unique.
|
|
32
|
-
* @param {string} [fontFace] - Font face for the text on the button.
|
|
33
|
-
* Defaults to 'Arial'
|
|
34
|
-
* @param {number} [fontSize] - Size of the font for the text on the button.
|
|
35
|
-
* Defaults to 40.
|
|
36
|
-
* @example
|
|
37
|
-
* const new TextButton("OK", 20, 200)
|
|
38
|
-
*/
|
|
39
|
-
constructor (text, x, y, id, fontFace = 'Arial', fontSize = 40) {
|
|
40
|
-
super(x, y)
|
|
41
|
-
this.text = text
|
|
42
|
-
this.fontFace = fontFace
|
|
43
|
-
this.fontSize = fontSize
|
|
44
|
-
if (id) {
|
|
45
|
-
this.id = id
|
|
46
|
-
} else {
|
|
47
|
-
this.id = text.length > 16 ? text.slice(0, 16) : text
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
toJSON () {
|
|
52
|
-
return {
|
|
53
|
-
type: 'button',
|
|
54
|
-
text: this.text,
|
|
55
|
-
font_face: this.fontFace,
|
|
56
|
-
font_size: this.fontSize,
|
|
57
|
-
x: this.x,
|
|
58
|
-
y: this.y,
|
|
59
|
-
id: this.id
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Text
|
|
66
|
-
* @classdesc Text to be displayed on a tablet
|
|
67
|
-
*
|
|
68
|
-
* @see {@link SignatureTablet}
|
|
69
|
-
*/
|
|
70
|
-
export class Text extends DisplayWidget {
|
|
71
|
-
text
|
|
72
|
-
fontFace
|
|
73
|
-
fontSize
|
|
74
|
-
/**
|
|
75
|
-
* Instantiate a Text object
|
|
76
|
-
* @constructor
|
|
77
|
-
* @param {string} text - Text to display on the button
|
|
78
|
-
* @param {number} x - X position to draw the button
|
|
79
|
-
* @param {number} y - Y position to draw the button
|
|
80
|
-
* @param {string} [fontFace] - Font face for the text on the button.
|
|
81
|
-
* Defaults to 'Arial'
|
|
82
|
-
* @param {number} [fontSize] - Size of the font for the text on the button.
|
|
83
|
-
* Defaults to 40.
|
|
84
|
-
* @example
|
|
85
|
-
* const new Text("Do you agree?", 20, 200)
|
|
86
|
-
*/
|
|
87
|
-
constructor (text, x, y, fontFace = 'Arial', fontSize = 40) {
|
|
88
|
-
super(x, y)
|
|
89
|
-
this.text = text
|
|
90
|
-
this.fontFace = fontFace
|
|
91
|
-
this.fontSize = fontSize
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
toJSON () {
|
|
95
|
-
return {
|
|
96
|
-
type: 'text',
|
|
97
|
-
text: this.text,
|
|
98
|
-
font_face: this.fontFace,
|
|
99
|
-
font_size: this.fontSize,
|
|
100
|
-
x: this.x,
|
|
101
|
-
y: this.y
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Image
|
|
108
|
-
* @classdesc Image to be displayed on a tablet
|
|
109
|
-
*
|
|
110
|
-
* @see {@link SignatureTablet}
|
|
111
|
-
*/
|
|
112
|
-
export class Image extends DisplayWidget {
|
|
113
|
-
url
|
|
114
|
-
imageData
|
|
115
|
-
delay
|
|
116
|
-
/**
|
|
117
|
-
* Instantiate an Image object
|
|
118
|
-
* @constructor
|
|
119
|
-
* @param {string} url - URL of the image.
|
|
120
|
-
* @param {number} [x] - X position to draw the button
|
|
121
|
-
* @param {number} [y] - Y position to draw the button
|
|
122
|
-
* @param {number} [delay] - Milliseconds to sleep after displaying the image
|
|
123
|
-
* @example
|
|
124
|
-
* const new Image("/img/logo.tif", 20, 200)
|
|
125
|
-
*/
|
|
126
|
-
constructor (url, x = 0, y = 0, delay = 0) {
|
|
127
|
-
super(x, y)
|
|
128
|
-
this.url = url
|
|
129
|
-
this.delay = delay
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Fetch the image data and base64 encode it
|
|
134
|
-
* @async
|
|
135
|
-
* @example
|
|
136
|
-
* const new Image("/img/logo.tif", 20, 200)
|
|
137
|
-
*/
|
|
138
|
-
async data () {
|
|
139
|
-
const response = await fetch(this.url)
|
|
140
|
-
const blob = await response.blob()
|
|
141
|
-
this.imageData = await blobToBase64(blob)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
toJSON () {
|
|
145
|
-
return {
|
|
146
|
-
type: 'image',
|
|
147
|
-
data: this.imageData,
|
|
148
|
-
delay: this.delay,
|
|
149
|
-
x: this.x,
|
|
150
|
-
y: this.y
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
1
|
+
import { blobToBase64 } from './Common.js'
|
|
2
|
+
|
|
3
|
+
export class DisplayWidget {
|
|
4
|
+
x
|
|
5
|
+
y
|
|
6
|
+
constructor (x, y) {
|
|
7
|
+
this.x = x
|
|
8
|
+
this.y = y
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* TextButton
|
|
14
|
+
* @classdesc A button for displaying clickable text on a tablet
|
|
15
|
+
*
|
|
16
|
+
* @see {@link SignatureTablet}
|
|
17
|
+
*/
|
|
18
|
+
export class TextButton extends DisplayWidget {
|
|
19
|
+
text
|
|
20
|
+
fontFace
|
|
21
|
+
fontSize
|
|
22
|
+
id
|
|
23
|
+
/**
|
|
24
|
+
* Instantiate a Tablet Text Button
|
|
25
|
+
* @constructor
|
|
26
|
+
* @param {string} text - Text to display on the button
|
|
27
|
+
* @param {number} x - X position to draw the button
|
|
28
|
+
* @param {number} y - Y position to draw the button
|
|
29
|
+
* @param {text} [id] - ID of the button that will be returned when it is
|
|
30
|
+
* clicked. If not set one will attempt to be constructed from the button
|
|
31
|
+
* text but there is no guarantee it will be unique.
|
|
32
|
+
* @param {string} [fontFace] - Font face for the text on the button.
|
|
33
|
+
* Defaults to 'Arial'
|
|
34
|
+
* @param {number} [fontSize] - Size of the font for the text on the button.
|
|
35
|
+
* Defaults to 40.
|
|
36
|
+
* @example
|
|
37
|
+
* const new TextButton("OK", 20, 200)
|
|
38
|
+
*/
|
|
39
|
+
constructor (text, x, y, id, fontFace = 'Arial', fontSize = 40) {
|
|
40
|
+
super(x, y)
|
|
41
|
+
this.text = text
|
|
42
|
+
this.fontFace = fontFace
|
|
43
|
+
this.fontSize = fontSize
|
|
44
|
+
if (id) {
|
|
45
|
+
this.id = id
|
|
46
|
+
} else {
|
|
47
|
+
this.id = text.length > 16 ? text.slice(0, 16) : text
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toJSON () {
|
|
52
|
+
return {
|
|
53
|
+
type: 'button',
|
|
54
|
+
text: this.text,
|
|
55
|
+
font_face: this.fontFace,
|
|
56
|
+
font_size: this.fontSize,
|
|
57
|
+
x: this.x,
|
|
58
|
+
y: this.y,
|
|
59
|
+
id: this.id
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Text
|
|
66
|
+
* @classdesc Text to be displayed on a tablet
|
|
67
|
+
*
|
|
68
|
+
* @see {@link SignatureTablet}
|
|
69
|
+
*/
|
|
70
|
+
export class Text extends DisplayWidget {
|
|
71
|
+
text
|
|
72
|
+
fontFace
|
|
73
|
+
fontSize
|
|
74
|
+
/**
|
|
75
|
+
* Instantiate a Text object
|
|
76
|
+
* @constructor
|
|
77
|
+
* @param {string} text - Text to display on the button
|
|
78
|
+
* @param {number} x - X position to draw the button
|
|
79
|
+
* @param {number} y - Y position to draw the button
|
|
80
|
+
* @param {string} [fontFace] - Font face for the text on the button.
|
|
81
|
+
* Defaults to 'Arial'
|
|
82
|
+
* @param {number} [fontSize] - Size of the font for the text on the button.
|
|
83
|
+
* Defaults to 40.
|
|
84
|
+
* @example
|
|
85
|
+
* const new Text("Do you agree?", 20, 200)
|
|
86
|
+
*/
|
|
87
|
+
constructor (text, x, y, fontFace = 'Arial', fontSize = 40) {
|
|
88
|
+
super(x, y)
|
|
89
|
+
this.text = text
|
|
90
|
+
this.fontFace = fontFace
|
|
91
|
+
this.fontSize = fontSize
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
toJSON () {
|
|
95
|
+
return {
|
|
96
|
+
type: 'text',
|
|
97
|
+
text: this.text,
|
|
98
|
+
font_face: this.fontFace,
|
|
99
|
+
font_size: this.fontSize,
|
|
100
|
+
x: this.x,
|
|
101
|
+
y: this.y
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Image
|
|
108
|
+
* @classdesc Image to be displayed on a tablet
|
|
109
|
+
*
|
|
110
|
+
* @see {@link SignatureTablet}
|
|
111
|
+
*/
|
|
112
|
+
export class Image extends DisplayWidget {
|
|
113
|
+
url
|
|
114
|
+
imageData
|
|
115
|
+
delay
|
|
116
|
+
/**
|
|
117
|
+
* Instantiate an Image object
|
|
118
|
+
* @constructor
|
|
119
|
+
* @param {string} url - URL of the image.
|
|
120
|
+
* @param {number} [x] - X position to draw the button
|
|
121
|
+
* @param {number} [y] - Y position to draw the button
|
|
122
|
+
* @param {number} [delay] - Milliseconds to sleep after displaying the image
|
|
123
|
+
* @example
|
|
124
|
+
* const new Image("/img/logo.tif", 20, 200)
|
|
125
|
+
*/
|
|
126
|
+
constructor (url, x = 0, y = 0, delay = 0) {
|
|
127
|
+
super(x, y)
|
|
128
|
+
this.url = url
|
|
129
|
+
this.delay = delay
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Fetch the image data and base64 encode it
|
|
134
|
+
* @async
|
|
135
|
+
* @example
|
|
136
|
+
* const new Image("/img/logo.tif", 20, 200)
|
|
137
|
+
*/
|
|
138
|
+
async data () {
|
|
139
|
+
const response = await fetch(this.url)
|
|
140
|
+
const blob = await response.blob()
|
|
141
|
+
this.imageData = await blobToBase64(blob)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
toJSON () {
|
|
145
|
+
return {
|
|
146
|
+
type: 'image',
|
|
147
|
+
data: this.imageData,
|
|
148
|
+
delay: this.delay,
|
|
149
|
+
x: this.x,
|
|
150
|
+
y: this.y
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|