@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.
@@ -0,0 +1,484 @@
1
+ /**
2
+ * @module SignatureTabletWidgets
3
+ */
4
+
5
+ import { blobToBase64 } from './Common.js'
6
+ import { DisplayWidget } from './SignatureTabletWidgets.js'
7
+
8
+ export class AccessKey {
9
+ static STAR = 'Š'
10
+ static HASH = '‹'
11
+ static CANCEL = ''
12
+ static BACK = ''
13
+ static ENTER = '
'
14
+ }
15
+
16
+ /**
17
+ * Button
18
+ * @classdesc A button for displaying clickable text on a tablet
19
+ * @extends DisplayWidget
20
+ * @see {@link SignatureTablet}
21
+ */
22
+ export class Button extends DisplayWidget {
23
+ id
24
+ text
25
+ width = 200
26
+ height = 100
27
+ font
28
+ border
29
+ background
30
+ padding
31
+ accessKey
32
+ beep = false
33
+
34
+ /**
35
+ * Instantiate a Button
36
+ * @constructor
37
+ * @param {number} id - ID of the button that will be returned when it is
38
+ * clicked
39
+ * @param {string} text - Text to display on the button
40
+ * @param {number} x - X position to draw the button
41
+ * @param {number} y - Y position to draw the button
42
+ *
43
+ * @param {object} [options] - Additional configuration options.
44
+ * @param {number} [options.width=200] - Width of button in pixesl
45
+ * @param {number} [options.height=100] - height of button in pixels
46
+ * @param {object} [options.border] - Border styles
47
+ * @param {string} [options.background] - Background color (hex or RGB)
48
+ * @param {array} [options.padding] - Padding
49
+ * @param {string} [options.accessKey] - Map button to a key on the keypad
50
+ * @param {object} [options.font] - Font styles
51
+ * @param {boolean} [options.beep=false] - On press, emit a beep
52
+ */
53
+ constructor (id, text, x, y, options) {
54
+ super(x, y)
55
+ this.id = id
56
+ this.text = text
57
+ if (typeof options === 'object') {
58
+ Object.assign(this, options)
59
+ }
60
+ }
61
+
62
+ toJSON () {
63
+ return {
64
+ type: 'button',
65
+ text: this.text,
66
+ x: this.x,
67
+ y: this.y,
68
+ id: this.id,
69
+ width: this.width,
70
+ height: this.height,
71
+ font: this.font,
72
+ border: this.border,
73
+ padding: this.padding,
74
+ background: this.background,
75
+ access_key: this.accessKey,
76
+ beep: this.beep
77
+ }
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Text
83
+ * @classdesc Text to be displayed on a tablet
84
+ * @extends DisplayWidget
85
+ * @see {@link SignatureTablet}
86
+ */
87
+ export class Text extends DisplayWidget {
88
+ id
89
+ text
90
+ width
91
+ height
92
+ font
93
+ border
94
+ background
95
+ padding
96
+ align = 'left'
97
+ lineHeight
98
+ /**
99
+ * Instantiate a Text object
100
+ * @constructor
101
+ * @param {number} id - ID of the text object
102
+ * @param {string} text - Text to display
103
+ * @param {number} x - X position to draw the text
104
+ * @param {number} y - Y position to draw the text
105
+ *
106
+ * @param {object} [options] - Additional configuration options.
107
+ * @param {number} [options.width] - Width of text bounding box in pixesl
108
+ * @param {number} [options.height] - height of text bounding in pixels
109
+ * @param {object} [options.border] - Border styles
110
+ * @param {string} [options.background] - Background color (hex or RGB)
111
+ * @param {array} [options.padding] - Padding
112
+ * @param {string} [options.align] - Align text `left`, `right`, or `center`
113
+ * @param {object} [options.font] - Font styles
114
+ * @param {number} [options.lineHeight] - Text line height
115
+ */
116
+ constructor (id, text, x, y, options) {
117
+ super(x, y)
118
+ this.id = id
119
+ this.text = text
120
+ if (typeof options === 'object') {
121
+ Object.assign(this, options)
122
+ }
123
+ }
124
+
125
+ toJSON () {
126
+ return {
127
+ type: 'text',
128
+ text: this.text,
129
+ align: this.align,
130
+ x: this.x,
131
+ y: this.y,
132
+ id: this.id,
133
+ width: this.width,
134
+ height: this.height,
135
+ font: this.font,
136
+ border: this.border,
137
+ padding: this.padding,
138
+ background: this.background,
139
+ line_height: this.lineHeight
140
+ }
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Image
146
+ * @classdesc Image to be displayed on a tablet
147
+ * @extends DisplayWidget
148
+ * @see {@link SignatureTablet}
149
+ */
150
+ export class Image extends DisplayWidget {
151
+ id
152
+ url
153
+ imageData
154
+ format = 'jpg'
155
+ height
156
+ width
157
+ border
158
+ /**
159
+ * Instantiate an Image object
160
+ * @constructor
161
+ * @param {number} id - ID of the image object
162
+ * @param {string} url - URL of the image. To provide the image data directly
163
+ * set the `url` argument to `null`, set the`imageData` property to the
164
+ * base64 encoded contents of the image, and set the `format` property to
165
+ * the file extension of the image (e.g. `jpg` or `png`)
166
+ * @param {number} x - X position to draw the image
167
+ * @param {number} y - Y position to draw the image
168
+ *
169
+ * @param {object} [options] - Additional configuration options
170
+ * @param {string} [options.format] - `jpg` or `png`
171
+ * @param {string} [options.imageData] - base64 encoded image data
172
+ * @param {number} [options.width] - Width of image in pixels
173
+ * @param {number} [options.height] - height of image in pixels
174
+ * @param {object} [options.border] - Border styles
175
+ */
176
+ constructor (id, url, x = 0, y = 0, options) {
177
+ super(x, y)
178
+ this.id = id
179
+ this.url = url
180
+
181
+ // if no format is provided look for the file extension
182
+ if ((!options || !options.format) && url) {
183
+ this.format = /(?:\.([^.]+))?$/.exec(url)[1]
184
+ }
185
+
186
+ if (typeof options === 'object') {
187
+ Object.assign(this, options)
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Fetch the image data and base64 encode it
193
+ * @async
194
+ */
195
+ async data () {
196
+ if (!this.imageData) {
197
+ const response = await fetch(this.url)
198
+ const blob = await response.blob()
199
+ this.imageData = await blobToBase64(blob)
200
+ }
201
+ }
202
+
203
+ toJSON () {
204
+ return {
205
+ id: this.id,
206
+ width: this.width,
207
+ height: this.height,
208
+ format: this.format,
209
+ type: 'image',
210
+ data: this.imageData,
211
+ x: this.x,
212
+ y: this.y,
213
+ border: this.border ? this.border.toJSON() : undefined
214
+ }
215
+ }
216
+ }
217
+
218
+ /**
219
+ * SignatureBox
220
+ * @classdesc Bounding box to capture a signature
221
+ * @extends DisplayWidget
222
+ * @see {@link SignatureTablet}
223
+ */
224
+ export class SignatureBox extends DisplayWidget {
225
+ id
226
+ width
227
+ height
228
+ postSignTimeout = 25
229
+
230
+ /**
231
+ * Instantiate a SignatureBox object
232
+ * @constructor
233
+ * @param {number} id - ID of the signature box object
234
+ * @param {number} x - X position to draw the sig box
235
+ * @param {number} y - Y position to draw the sig box
236
+ *
237
+ * @param {object} [options] - Additional configuration options
238
+ * @param {string} [options.format] - `jpg` or `png`
239
+ * @param {number} [options.width] - Width of sig box in pixels
240
+ * @param {number} [options.height] - height of sig box in pixels
241
+ * @param {number} [options.postSignTimeout] - Timeout after signing has started
242
+ */
243
+ constructor (id, x, y, options) {
244
+ super(x, y)
245
+ this.id = id
246
+ if (typeof options === 'object') {
247
+ Object.assign(this, options)
248
+ }
249
+ }
250
+
251
+ toJSON () {
252
+ return {
253
+ id: this.id,
254
+ type: 'signature',
255
+ x: this.x,
256
+ y: this.y,
257
+ width: this.width,
258
+ height: this.height,
259
+ post_sign_timeout: this.postSignTimeout
260
+ }
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Rect
266
+ * @classdesc A rectangle
267
+ * @extends DisplayWidget
268
+ * @see {@link SignatureTablet}
269
+ */
270
+ export class Rect extends DisplayWidget {
271
+ id
272
+ width = 100
273
+ height = 100
274
+ background
275
+ opacity
276
+ border
277
+ zIndex
278
+
279
+ /**
280
+ * Instantiate a Rect object
281
+ * @constructor
282
+ * @param {number} id - ID of the rectangle object
283
+ * @param {number} x - X position to draw the rectangle
284
+ * @param {number} y - Y position to draw the rectangle
285
+ *
286
+ * @param {object} [options] - Additional configuration options
287
+ * @param {number} [options.width=100] - Width of rectangle in pixels
288
+ * @param {number} [options.height=100] - height of rectangle in pixels
289
+ * @param {object} [options.border] - Border styles
290
+ * @param {float} [options.opacity] - Set object opacity (0.0 to 1)
291
+ * @param {number} [options.zIndex] - Manually set z-index
292
+ */
293
+ constructor (id, x, y, options) {
294
+ super(x, y)
295
+ this.id = id
296
+ if (typeof options === 'object') {
297
+ Object.assign(this, options)
298
+ }
299
+ }
300
+
301
+ toJSON () {
302
+ return {
303
+ id: this.id,
304
+ type: 'rect',
305
+ x: this.x,
306
+ y: this.y,
307
+ width: this.width,
308
+ height: this.height,
309
+ border: this.border,
310
+ opacity: this.opacity,
311
+ background: this.background,
312
+ z_index: this.zIndex
313
+ }
314
+ }
315
+ }
316
+
317
+ /**
318
+ * CheckBox
319
+ * @classdesc A check box object
320
+ * @extends DisplayWidget
321
+ * @see {@link SignatureTablet}
322
+ */
323
+ export class CheckBox extends DisplayWidget {
324
+ id
325
+ width = 50
326
+ height = 50
327
+ checked
328
+
329
+ /**
330
+ * Instantiate a check box object
331
+ * @constructor
332
+ * @param {number} id - ID of the rectangle object
333
+ * @param {number} x - X position to draw the check box
334
+ * @param {number} y - Y position to draw the check box
335
+ *
336
+ * @param {object} [options] - Additional configuration options
337
+ * @param {number} [options.width=50] - Width of check box in pixels
338
+ * @param {number} [options.height=50] - height of check box in pixels
339
+ * @param {boolean} [options.boolean=false] - Set the checked state
340
+ */
341
+ constructor (id, x, y, options) {
342
+ super(x, y)
343
+ this.id = id
344
+ if (typeof options === 'object') {
345
+ Object.assign(this, options)
346
+ }
347
+ }
348
+
349
+ toJSON () {
350
+ return {
351
+ type: 'checkbox',
352
+ x: this.x,
353
+ y: this.y,
354
+ id: this.id,
355
+ width: this.width,
356
+ height: this.height,
357
+ checked: this.checked
358
+ }
359
+ }
360
+ }
361
+
362
+ /**
363
+ * RadioButton
364
+ * @classdesc A radio button object
365
+ * @extends DisplayWidget
366
+ * @see {@link SignatureTablet}
367
+ */
368
+ export class RadioButton extends DisplayWidget {
369
+ id
370
+ groupId
371
+ width = 50
372
+ height = 50
373
+ checked
374
+ value
375
+
376
+ /**
377
+ * Instantiate a radio button object
378
+ * @constructor
379
+ * @param {number} id - ID of the radio button object
380
+ * @param {number} groupId - Group ID of the radio button object
381
+ * @param {number} x - X position to draw the radio button
382
+ * @param {number} y - Y position to draw the radio button
383
+ *
384
+ * @param {object} [options] - Additional configuration options
385
+ * @param {number} [options.width=50] - Width of radio button in pixels
386
+ * @param {number} [options.height=50] - height of radio button in pixels
387
+ * @param {boolean} [options.boolean=false] - Set the checked state
388
+ */
389
+ constructor (id, groupId, value, x, y, options) {
390
+ super(x, y)
391
+ this.id = id
392
+ this.groupId = groupId
393
+ this.value = value
394
+ if (typeof options === 'object') {
395
+ Object.assign(this, options)
396
+ }
397
+ }
398
+
399
+ toJSON () {
400
+ return {
401
+ type: 'radio',
402
+ x: this.x,
403
+ y: this.y,
404
+ id: this.id,
405
+ group_id: this.groupId,
406
+ width: this.width,
407
+ height: this.height,
408
+ checked: this.checked,
409
+ value: this.value
410
+ }
411
+ }
412
+ }
413
+
414
+ /**
415
+ * TextInput
416
+ * @classdesc A text input object
417
+ * @extends DisplayWidget
418
+ * @see {@link SignatureTablet}
419
+ */
420
+ export class TextInput extends DisplayWidget {
421
+ id
422
+ width
423
+ height
424
+ value
425
+ font
426
+ border
427
+ background
428
+ padding
429
+ placeholder
430
+ allowedChars
431
+ minLength
432
+ maxLength
433
+ align = 'left'
434
+
435
+ /**
436
+ * Instantiate a text input object
437
+ * @constructor
438
+ * @param {number} id - ID of the radio button object
439
+ * @param {number} x - X position to draw the text input
440
+ * @param {number} y - Y position to draw the text input
441
+ *
442
+ * @param {object} [options] - Additional configuration options
443
+ * @param {number} [options.width] - Width of text input in pixels
444
+ * @param {number} [options.height] - height of text input in pixels
445
+ * @param {string} [options.value] - Set the value of the text input
446
+ * @param {object} [options.font] - Font styles
447
+ * @param {object} [options.border] - Border styles
448
+ * @param {string} [options.background] - Background color
449
+ * @param {array} [options.padding] - Padding
450
+ * @param {string} [options.placeholder] - Placeholder text
451
+ * @param {string} [options.allowedChars] - Characters allowed for input
452
+ * @param {number} [options.minLength] - Minimum allowed number of characters
453
+ * @param {number} [options.maxLength] - Maximum allowed number of characters
454
+ * @param {string} [options.align] - Align text `left`, `right`, or `center`
455
+ */
456
+ constructor (id, x, y, options) {
457
+ super(x, y)
458
+ this.id = id
459
+ if (typeof options === 'object') {
460
+ Object.assign(this, options)
461
+ }
462
+ }
463
+
464
+ toJSON () {
465
+ return {
466
+ type: 'input',
467
+ id: this.id,
468
+ x: this.x,
469
+ y: this.y,
470
+ width: this.width,
471
+ height: this.height,
472
+ value: this.value,
473
+ font: this.font,
474
+ border: this.border,
475
+ background: this.background,
476
+ padding: this.padding,
477
+ placeholder: this.placeholder,
478
+ allowed_chars: this.allowedChars,
479
+ min_length: this.minLength,
480
+ max_length: this.maxLength,
481
+ align: this.align
482
+ }
483
+ }
484
+ }
package/Version.js CHANGED
@@ -1,8 +1,8 @@
1
- /**
2
- * @summary SDK Version as published on
3
- * {@link https://www.npmjs.com/package/@capturebridge/sdk|NPM}
4
- * @constant
5
- * @type {string}
6
- */
7
- const VERSION = '0.12.1'
1
+ /**
2
+ * @summary SDK Version as published on
3
+ * {@link https://www.npmjs.com/package/@capturebridge/sdk|NPM}
4
+ * @constant
5
+ * @type {string}
6
+ */
7
+ const VERSION = '0.14.2'
8
8
  export default VERSION
package/WindowsScanner.js CHANGED
@@ -1,25 +1,25 @@
1
- import Scanner from './Scanner.js'
2
- import { BASE_URL } from './Common.js'
3
-
4
- /**
5
- * WindowsScanner
6
- * @classdesc Convenience class for instantiating a WIA compatible Scanner.
7
- * Inherits all methods on the {@link Scanner} class.
8
- * @extends Scanner
9
- * @see {@link Scanner}
10
- */
11
- class WindowsScanner extends Scanner {
12
- /**
13
- * Instantiate a WIA compatible scanner
14
- * @constructor
15
- * @param {string} [baseURL] - Protocol, domain, and port for the service.
16
- * @example
17
- * const scanner = new WindowsScanner()
18
- * const doc = await camera.scan()
19
- */
20
- constructor (baseUrl = BASE_URL) {
21
- super('capture_scanner_windows', baseUrl)
22
- }
23
- }
24
-
25
- export default WindowsScanner
1
+ import Scanner from './Scanner.js'
2
+ import { BASE_URL } from './Common.js'
3
+
4
+ /**
5
+ * WindowsScanner
6
+ * @classdesc Convenience class for instantiating a WIA compatible Scanner.
7
+ * Inherits all methods on the {@link Scanner} class.
8
+ * @extends Scanner
9
+ * @see {@link Scanner}
10
+ */
11
+ class WindowsScanner extends Scanner {
12
+ /**
13
+ * Instantiate a WIA compatible scanner
14
+ * @constructor
15
+ * @param {string} [baseURL] - Protocol, domain, and port for the service.
16
+ * @example
17
+ * const scanner = new WindowsScanner()
18
+ * const doc = await camera.scan()
19
+ */
20
+ constructor (baseUrl = BASE_URL) {
21
+ super('capture_scanner_windows', baseUrl)
22
+ }
23
+ }
24
+
25
+ export default WindowsScanner
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capturebridge/sdk",
3
- "version": "0.12.1",
3
+ "version": "0.14.2",
4
4
  "description": "Capture Bridge JavaScript SDK for web applications",
5
5
  "type": "module",
6
6
  "types": "types.d.ts",