import StreamingCapturePlugin from './StreamingCapturePlugin.js'
import { BASE_URL, DEFAULT_CAPTURE_OPT, DEPRECATION_01 } from './Common.js'
/**
* SignatureTablet
* @classdesc Class for invoking methods on a Signature Capture Tablet
* @extends StreamingCapturePlugin
* @see {@link TopazSigGem}
*/
class SignatureTablet extends StreamingCapturePlugin {
constructor (plugin, baseUrl = BASE_URL) {
super(plugin, baseUrl)
}
/**
* @description Clear a signature tablet's display.
*
* @param {boolean} [backlight=false] If `true`, the device's backlight will be
* enabled. If `false`, it will be disabled. If unspecified no action will be
* taken on the backlight.
*
* @param {string|Device} [deviceOpt] - Clear the display of a either a
* specific Device ID or a Device Object. The default is the first available
* device.
*
* @async
* @method
* @returns {object}
*/
async clear (backlight, deviceOpt) {
const device = await this.setupDevice(deviceOpt)
return device.clear(backlight)
}
/**
* Render an Array of Objects on the display and wait for user input.
*
* @description If any Objects are Buttons, the method will wait for one
* to be clicked and will then return results. The format of the Array of
* Objects, the response structure, and the scene options are plugin specific.
*
* @param {Object[]} objects An array of drawable objects to display.
* @param {Object} [sceneOpt] Options for configuring the scene.
*
* @async
* @method
* @returns {object?}
*/
async displayObjects (objects, sceneOpt = {}, deviceOpt) {
const device = await this.setupDevice(deviceOpt)
return device.displayObjects(objects, sceneOpt)
}
/**
* Capture a high resolution signature.
*
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
* signature.
*
* @param {string|object} [deviceOpt] - Capture the signature using either a
* specific Device ID or a Device Object. The default is the first available
* device.
*
* @async
* @example
* // Capture signature as an ArrayBuffer and add it to an img tag appended to
* // the document's body.
* const img = document.createElement('img')
* img.src = await tablet.signature()
* document.body.appendChild(img)
*/
async signature (captureOpt = {}, deviceOpt) {
if (typeof captureOpt === 'string' && DEPRECATION_01) {
captureOpt = { kind: captureOpt }
console.warn('CaptureBridge SDK Deprecation Warning: ' +
'`SignatureTablet.signature()` converted the `captureOpt` argument ' +
'from a string (%s) to an object (%s). This conversion may not be ' +
'performed in future SDK versions.',
captureOpt.kind, JSON.stringify(captureOpt))
}
const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
return await this.fullCapture(mergedOpt, deviceOpt)
}
}
export default SignatureTablet