UNPKG

scandit-react-native-datacapture-core

Version:

Scandit Data Capture SDK for React Native

1,526 lines (1,420 loc) 129 kB
function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } var eventemitter3 = {exports: {}}; var hasRequiredEventemitter3; function requireEventemitter3 () { if (hasRequiredEventemitter3) return eventemitter3.exports; hasRequiredEventemitter3 = 1; (function (module) { var has = Object.prototype.hasOwnProperty , prefix = '~'; /** * Constructor to create a storage for our `EE` objects. * An `Events` instance is a plain object whose properties are event names. * * @constructor * @private */ function Events() {} // // We try to not inherit from `Object.prototype`. In some engines creating an // instance in this way is faster than calling `Object.create(null)` directly. // If `Object.create(null)` is not supported we prefix the event names with a // character to make sure that the built-in object properties are not // overridden or used as an attack vector. // if (Object.create) { Events.prototype = Object.create(null); // // This hack is needed because the `__proto__` property is still inherited in // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5. // if (!new Events().__proto__) prefix = false; } /** * Representation of a single event listener. * * @param {Function} fn The listener function. * @param {*} context The context to invoke the listener with. * @param {Boolean} [once=false] Specify if the listener is a one-time listener. * @constructor * @private */ function EE(fn, context, once) { this.fn = fn; this.context = context; this.once = once || false; } /** * Add a listener for a given event. * * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} context The context to invoke the listener with. * @param {Boolean} once Specify if the listener is a one-time listener. * @returns {EventEmitter} * @private */ function addListener(emitter, event, fn, context, once) { if (typeof fn !== 'function') { throw new TypeError('The listener must be a function'); } var listener = new EE(fn, context || emitter, once) , evt = prefix ? prefix + event : event; if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++; else if (!emitter._events[evt].fn) emitter._events[evt].push(listener); else emitter._events[evt] = [emitter._events[evt], listener]; return emitter; } /** * Clear event by name. * * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. * @param {(String|Symbol)} evt The Event name. * @private */ function clearEvent(emitter, evt) { if (--emitter._eventsCount === 0) emitter._events = new Events(); else delete emitter._events[evt]; } /** * Minimal `EventEmitter` interface that is molded against the Node.js * `EventEmitter` interface. * * @constructor * @public */ function EventEmitter() { this._events = new Events(); this._eventsCount = 0; } /** * Return an array listing the events for which the emitter has registered * listeners. * * @returns {Array} * @public */ EventEmitter.prototype.eventNames = function eventNames() { var names = [] , events , name; if (this._eventsCount === 0) return names; for (name in (events = this._events)) { if (has.call(events, name)) names.push(prefix ? name.slice(1) : name); } if (Object.getOwnPropertySymbols) { return names.concat(Object.getOwnPropertySymbols(events)); } return names; }; /** * Return the listeners registered for a given event. * * @param {(String|Symbol)} event The event name. * @returns {Array} The registered listeners. * @public */ EventEmitter.prototype.listeners = function listeners(event) { var evt = prefix ? prefix + event : event , handlers = this._events[evt]; if (!handlers) return []; if (handlers.fn) return [handlers.fn]; for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { ee[i] = handlers[i].fn; } return ee; }; /** * Return the number of listeners listening to a given event. * * @param {(String|Symbol)} event The event name. * @returns {Number} The number of listeners. * @public */ EventEmitter.prototype.listenerCount = function listenerCount(event) { var evt = prefix ? prefix + event : event , listeners = this._events[evt]; if (!listeners) return 0; if (listeners.fn) return 1; return listeners.length; }; /** * Calls each of the listeners registered for a given event. * * @param {(String|Symbol)} event The event name. * @returns {Boolean} `true` if the event had listeners, else `false`. * @public */ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { var evt = prefix ? prefix + event : event; if (!this._events[evt]) return false; var listeners = this._events[evt] , len = arguments.length , args , i; if (listeners.fn) { if (listeners.once) this.removeListener(event, listeners.fn, undefined, true); switch (len) { case 1: return listeners.fn.call(listeners.context), true; case 2: return listeners.fn.call(listeners.context, a1), true; case 3: return listeners.fn.call(listeners.context, a1, a2), true; case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true; case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; } for (i = 1, args = new Array(len -1); i < len; i++) { args[i - 1] = arguments[i]; } listeners.fn.apply(listeners.context, args); } else { var length = listeners.length , j; for (i = 0; i < length; i++) { if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true); switch (len) { case 1: listeners[i].fn.call(listeners[i].context); break; case 2: listeners[i].fn.call(listeners[i].context, a1); break; case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break; default: if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { args[j - 1] = arguments[j]; } listeners[i].fn.apply(listeners[i].context, args); } } } return true; }; /** * Add a listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.on = function on(event, fn, context) { return addListener(this, event, fn, context, false); }; /** * Add a one-time listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.once = function once(event, fn, context) { return addListener(this, event, fn, context, true); }; /** * Remove the listeners of a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn Only remove the listeners that match this function. * @param {*} context Only remove the listeners that have this context. * @param {Boolean} once Only remove one-time listeners. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { var evt = prefix ? prefix + event : event; if (!this._events[evt]) return this; if (!fn) { clearEvent(this, evt); return this; } var listeners = this._events[evt]; if (listeners.fn) { if ( listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context) ) { clearEvent(this, evt); } } else { for (var i = 0, events = [], length = listeners.length; i < length; i++) { if ( listeners[i].fn !== fn || (once && !listeners[i].once) || (context && listeners[i].context !== context) ) { events.push(listeners[i]); } } // // Reset the array, or remove it completely if we have no more listeners. // if (events.length) this._events[evt] = events.length === 1 ? events[0] : events; else clearEvent(this, evt); } return this; }; /** * Remove all listeners, or those of the specified event. * * @param {(String|Symbol)} [event] The event name. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { var evt; if (event) { evt = prefix ? prefix + event : event; if (this._events[evt]) clearEvent(this, evt); } else { this._events = new Events(); this._eventsCount = 0; } return this; }; // // Alias methods names because people roll like that. // EventEmitter.prototype.off = EventEmitter.prototype.removeListener; EventEmitter.prototype.addListener = EventEmitter.prototype.on; // // Expose the prefix. // EventEmitter.prefixed = prefix; // // Allow `EventEmitter` to be imported as module namespace. // EventEmitter.EventEmitter = EventEmitter; // // Expose the module. // { module.exports = EventEmitter; } } (eventemitter3)); return eventemitter3.exports; } var eventemitter3Exports = requireEventemitter3(); var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports); class FactoryMaker { static bindInstance(clsName, instance) { FactoryMaker.instances.set(clsName, { instance }); } static bindLazyInstance(clsName, builder) { FactoryMaker.instances.set(clsName, { builder }); } static bindInstanceIfNotExists(clsName, instance) { if (FactoryMaker.instances.has(clsName)) { return; } FactoryMaker.instances.set(clsName, { instance }); } static getInstance(clsName) { var _a; const item = FactoryMaker.instances.get(clsName); if (item === null || item === undefined) { throw new Error(`Trying to get a non existing instance for ${clsName}`); } if (!item.instance && item.builder) { item.instance = (_a = item.builder) === null || _a === void 0 ? void 0 : _a.call(item); } return item.instance; } static createInstance(clsName) { var _a; const item = FactoryMaker.instances.get(clsName); if (item === null || item === undefined) { throw new Error(`Trying to get a non existing instance for ${clsName}`); } const proxyInstance = (_a = item.builder) === null || _a === void 0 ? void 0 : _a.call(item); if (proxyInstance === undefined) { throw new Error(`item.builder?.() returned undefined for ${clsName}`); } return proxyInstance; } } FactoryMaker.instances = new Map(); function createEventEmitter() { const ee = new EventEmitter(); FactoryMaker.bindInstanceIfNotExists('EventEmitter', ee); } /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { var e = new Error(message); return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; }; class BaseController { get _proxy() { return FactoryMaker.getInstance(this.proxyName); } constructor(proxyName) { this.eventEmitter = FactoryMaker.getInstance('EventEmitter'); this.proxyName = proxyName; } } class BaseNativeProxy { constructor() { this.eventEmitter = FactoryMaker.getInstance('EventEmitter'); } } /** * JS Proxy hook to act as middleware to all the calls performed by an AdvancedNativeProxy instance * This will allow AdvancedNativeProxy to call dynamically the methods defined in the interface defined * as parameter in createAdvancedNativeProxy function */ const advancedNativeProxyHook = { /** * Dynamic property getter for the AdvancedNativeProxy * In order to call a native method this needs to be preceded by the `$` symbol on the name, ie `$methodName` * In order to set a native event handler this needs to be preceded by `on$` prefix, ie `on$eventName` * @param advancedNativeProxy * @param prop */ get(advancedNativeProxy, prop) { // Important: $ and on$ are required since if they are not added all // properties present on AdvancedNativeProxy will be redirected to the // advancedNativeProxy._call, which will call native even for the own // properties of the class // All the methods with the following structure // $methodName will be redirected to the special _call // method on AdvancedNativeProxy if (prop.startsWith("$")) { if (prop in advancedNativeProxy) { return advancedNativeProxy[prop]; } return (args) => { return advancedNativeProxy._call(prop.substring(1), args); }; // All methods with the following structure // on$methodName will trigger the event handler properties } else if (prop.startsWith("on$")) { return advancedNativeProxy[prop.substring(3)]; // Everything else will be taken as a property } else { return advancedNativeProxy[prop]; } } }; /** * AdvancedNativeProxy will provide an easy way to communicate between native proxies * and other parts of the architecture such as the controller layer */ class AdvancedNativeProxy extends BaseNativeProxy { constructor(nativeCaller, events = []) { super(); this.nativeCaller = nativeCaller; this.events = events; this.eventSubscriptions = new Map(); this.events.forEach((event) => __awaiter(this, void 0, void 0, function* () { yield this._registerEvent(event); })); // Wrapping the AdvancedNativeProxy instance with the JS proxy hook return new Proxy(this, advancedNativeProxyHook); } dispose() { return __awaiter(this, void 0, void 0, function* () { for (const event of this.events) { yield this._unregisterEvent(event); } this.eventSubscriptions.clear(); this.events = []; }); } _call(fnName, args) { return this.nativeCaller.callFn(fnName, args); } _registerEvent(event) { return __awaiter(this, void 0, void 0, function* () { const handler = (args) => __awaiter(this, void 0, void 0, function* () { this.eventEmitter.emit(event.nativeEventName, args); }); this.eventEmitter.on(event.nativeEventName, (args) => __awaiter(this, void 0, void 0, function* () { // Call to the special method defined on the JS Proxy hook try { const hookArg = this.nativeCaller.eventHook(args); yield this[`on$${event.name}`](hookArg); } catch (e) { console.error(`Error while trying to execute handler for ${event.nativeEventName}`, e); throw e; } })); const subscription = yield this.nativeCaller.registerEvent(event.nativeEventName, handler); this.eventSubscriptions.set(event.name, subscription); }); } _unregisterEvent(event) { return __awaiter(this, void 0, void 0, function* () { const subscription = this.eventSubscriptions.get(event.name); yield this.nativeCaller.unregisterEvent(event.nativeEventName, subscription); this.eventEmitter.off(event.nativeEventName); this.eventSubscriptions.delete(event.name); }); } } /** * Function to create a custom AdvancedNativeProxy. This will return an object which will provide dynamically the * methods specified in the PROXY interface. * * The Proxy interface implemented in order to call native methods will require a special mark * `$methodName` for method calls * `on$methodName` for the listeners added to the events defined in eventsEnum * @param nativeCaller * @param eventsEnum */ function createAdvancedNativeProxy(nativeCaller, eventsEnum = undefined) { const eventsList = eventsEnum == null ? [] : Object.entries(eventsEnum).map(([key, value]) => ({ name: key, nativeEventName: value })); return new AdvancedNativeProxy(nativeCaller, eventsList); } /** * Function to create a custom AdvancedNativeProxy. This will return an object which will provide dynamically the * methods specified in the PROXY interface. * * The Proxy interface implemented in order to call native methods will require a special mark * `$methodName` for method calls * `on$methodName` for the listeners added to the events defined in eventsEnum * @param klass * @param nativeCaller * @param eventsEnum */ function createAdvancedNativeFromCtorProxy(klass, nativeCaller, eventsEnum = undefined) { const eventsList = Object.entries(eventsEnum).map(([key, value]) => ({ name: key, nativeEventName: value })); return new klass(nativeCaller, eventsList); } function getCoreDefaults() { return FactoryMaker.getInstance('CoreDefaults'); } function ignoreFromSerialization(target, propertyName) { target.ignoredProperties = target.ignoredProperties || []; target.ignoredProperties.push(propertyName); } function nameForSerialization(customName) { return (target, propertyName) => { target.customPropertyNames = target.customPropertyNames || {}; target.customPropertyNames[propertyName] = customName; }; } function ignoreFromSerializationIfNull(target, propertyName) { target.ignoredIfNullProperties = target.ignoredIfNullProperties || []; target.ignoredIfNullProperties.push(propertyName); } function serializationDefault(defaultValue) { return (target, propertyName) => { target.customPropertyDefaults = target.customPropertyDefaults || {}; target.customPropertyDefaults[propertyName] = defaultValue; }; } class DefaultSerializeable { toJSON() { const properties = Object.keys(this); // use @ignoreFromSerialization to ignore properties const ignoredProperties = this.ignoredProperties || []; // use @ignoreFromSerializationIfNull to ignore properties if they're null const ignoredIfNullProperties = this.ignoredIfNullProperties || []; // use @nameForSerialization('customName') to rename properties in the JSON output const customPropertyNames = this.customPropertyNames || {}; // use @serializationDefault({}) to use a different value in the JSON output if they're null const customPropertyDefaults = this.customPropertyDefaults || {}; return properties.reduce((json, property) => { if (ignoredProperties.includes(property)) { return json; } let value = this[property]; if (value === undefined) { return json; } // Ignore if it's null and should be ignored. // This is basically responsible for not including optional properties in the JSON if they're null, // as that's not always deserialized to mean the same as not present. if (value === null && ignoredIfNullProperties.includes(property)) { return json; } if (value === null && customPropertyDefaults[property] !== undefined) { value = customPropertyDefaults[property]; } // Serialize if serializeable if (value != null && value.toJSON) { value = value.toJSON(); } // Serialize the array if the elements are serializeable if (Array.isArray(value)) { value = value.map(e => e.toJSON ? e.toJSON() : e); } const propertyName = customPropertyNames[property] || property; json[propertyName] = value; return json; }, {}); } } class TapToFocus extends DefaultSerializeable { constructor() { super(); this.type = 'tapToFocus'; } } class PrivateFocusGestureDeserializer { static fromJSON(json) { if (json && json.type === new TapToFocus().type) { return new TapToFocus(); } else { return null; } } } class SwipeToZoom extends DefaultSerializeable { constructor() { super(); this.type = 'swipeToZoom'; } } class PrivateZoomGestureDeserializer { static fromJSON(json) { if (json && json.type === new SwipeToZoom().type) { return new SwipeToZoom(); } else { return null; } } } var FrameSourceState; (function (FrameSourceState) { FrameSourceState["On"] = "on"; FrameSourceState["Off"] = "off"; FrameSourceState["Starting"] = "starting"; FrameSourceState["Stopping"] = "stopping"; FrameSourceState["Standby"] = "standby"; FrameSourceState["BootingUp"] = "bootingUp"; FrameSourceState["WakingUp"] = "wakingUp"; FrameSourceState["GoingToSleep"] = "goingToSleep"; FrameSourceState["ShuttingDown"] = "shuttingDown"; })(FrameSourceState || (FrameSourceState = {})); class ImageBuffer { get width() { return this._width; } get height() { return this._height; } get data() { return this._data; } } class FrameDataSettings extends DefaultSerializeable { constructor() { super(); // Enables the file system cache for the frame. this._isFileSystemCacheEnabled = false; // The quality of the image. 0-100. this._imageQuality = 100; // Enables the auto-rotation of the frame. this._isAutoRotateEnabled = false; } get isFileSystemCacheEnabled() { return this._isFileSystemCacheEnabled; } set isFileSystemCacheEnabled(enabled) { this._isFileSystemCacheEnabled = enabled; } get imageQuality() { return this._imageQuality; } set imageQuality(quality) { if (quality < 0 || quality > 100) { throw new Error('Image quality must be between 0 and 100'); } this._imageQuality = quality; } get isAutoRotateEnabled() { return this._isAutoRotateEnabled; } set isAutoRotateEnabled(enabled) { this._isAutoRotateEnabled = enabled; } } __decorate([ nameForSerialization('sc_frame_isFileSystemCacheEnabled') ], FrameDataSettings.prototype, "_isFileSystemCacheEnabled", void 0); __decorate([ nameForSerialization('sc_frame_imageQuality') ], FrameDataSettings.prototype, "_imageQuality", void 0); __decorate([ nameForSerialization('sc_frame_autoRotate') ], FrameDataSettings.prototype, "_isAutoRotateEnabled", void 0); class FrameDataSettingsBuilder { constructor(settings) { this.settings = settings; } enableFileSystemCache(enabled) { this.settings.isFileSystemCacheEnabled = enabled; return this; } setImageQuality(quality) { this.settings.imageQuality = quality; return this; } enableAutoRotate(enabled) { this.settings.isAutoRotateEnabled = enabled; return this; } } var CameraPosition; (function (CameraPosition) { CameraPosition["WorldFacing"] = "worldFacing"; CameraPosition["UserFacing"] = "userFacing"; CameraPosition["Unspecified"] = "unspecified"; })(CameraPosition || (CameraPosition = {})); var FrameSourceListenerEvents; (function (FrameSourceListenerEvents) { FrameSourceListenerEvents["didChangeState"] = "FrameSourceListener.onStateChanged"; })(FrameSourceListenerEvents || (FrameSourceListenerEvents = {})); var FontFamily; (function (FontFamily) { FontFamily["SystemDefault"] = "systemDefault"; FontFamily["ModernMono"] = "modernMono"; FontFamily["SystemSans"] = "systemSans"; })(FontFamily || (FontFamily = {})); var TextAlignment; (function (TextAlignment) { TextAlignment["Left"] = "left"; TextAlignment["Right"] = "right"; TextAlignment["Center"] = "center"; TextAlignment["Start"] = "start"; TextAlignment["End"] = "end"; })(TextAlignment || (TextAlignment = {})); class Point extends DefaultSerializeable { get x() { return this._x; } get y() { return this._y; } static fromJSON(json) { return new Point(json.x, json.y); } constructor(x, y) { super(); this._x = x; this._y = y; } } __decorate([ nameForSerialization('x') ], Point.prototype, "_x", void 0); __decorate([ nameForSerialization('y') ], Point.prototype, "_y", void 0); class Quadrilateral extends DefaultSerializeable { get topLeft() { return this._topLeft; } get topRight() { return this._topRight; } get bottomRight() { return this._bottomRight; } get bottomLeft() { return this._bottomLeft; } static fromJSON(json) { return new Quadrilateral(Point.fromJSON(json.topLeft), Point.fromJSON(json.topRight), Point.fromJSON(json.bottomRight), Point.fromJSON(json.bottomLeft)); } constructor(topLeft, topRight, bottomRight, bottomLeft) { super(); this._topLeft = topLeft; this._topRight = topRight; this._bottomRight = bottomRight; this._bottomLeft = bottomLeft; } } __decorate([ nameForSerialization('topLeft') ], Quadrilateral.prototype, "_topLeft", void 0); __decorate([ nameForSerialization('topRight') ], Quadrilateral.prototype, "_topRight", void 0); __decorate([ nameForSerialization('bottomRight') ], Quadrilateral.prototype, "_bottomRight", void 0); __decorate([ nameForSerialization('bottomLeft') ], Quadrilateral.prototype, "_bottomLeft", void 0); class NumberWithUnit extends DefaultSerializeable { get value() { return this._value; } get unit() { return this._unit; } static fromJSON(json) { return new NumberWithUnit(json.value, json.unit); } constructor(value, unit) { super(); this._value = value; this._unit = unit; } } __decorate([ nameForSerialization('value') ], NumberWithUnit.prototype, "_value", void 0); __decorate([ nameForSerialization('unit') ], NumberWithUnit.prototype, "_unit", void 0); var MeasureUnit; (function (MeasureUnit) { MeasureUnit["DIP"] = "dip"; MeasureUnit["Pixel"] = "pixel"; MeasureUnit["Fraction"] = "fraction"; })(MeasureUnit || (MeasureUnit = {})); class PointWithUnit extends DefaultSerializeable { get x() { return this._x; } get y() { return this._y; } static fromJSON(json) { return new PointWithUnit(NumberWithUnit.fromJSON(json.x), NumberWithUnit.fromJSON(json.y)); } static get zero() { return new PointWithUnit(new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel)); } constructor(x, y) { super(); this._x = x; this._y = y; } } __decorate([ nameForSerialization('x') ], PointWithUnit.prototype, "_x", void 0); __decorate([ nameForSerialization('y') ], PointWithUnit.prototype, "_y", void 0); class Rect extends DefaultSerializeable { get origin() { return this._origin; } get size() { return this._size; } constructor(origin, size) { super(); this._origin = origin; this._size = size; } } __decorate([ nameForSerialization('origin') ], Rect.prototype, "_origin", void 0); __decorate([ nameForSerialization('size') ], Rect.prototype, "_size", void 0); class RectWithUnit extends DefaultSerializeable { get origin() { return this._origin; } get size() { return this._size; } constructor(origin, size) { super(); this._origin = origin; this._size = size; } } __decorate([ nameForSerialization('origin') ], RectWithUnit.prototype, "_origin", void 0); __decorate([ nameForSerialization('size') ], RectWithUnit.prototype, "_size", void 0); class ScanditIcon extends DefaultSerializeable { static fromJSON(json) { if (!json) { return null; } const scanditIcon = new ScanditIcon(json.iconColor || null, json.backgroundColor || null, json.backgroundShape || null, json.icon || null, json.backgroundStrokeColor || null, json.backgroundStrokeWidth); return scanditIcon; } constructor(iconColor, backgroundColor, backgroundShape, icon, backgroundStrokeColor, backgroundStrokeWidth) { super(); this._backgroundStrokeWidth = 3.0; this._iconColor = iconColor; this._backgroundColor = backgroundColor; this._backgroundShape = backgroundShape; this._icon = icon; this._backgroundStrokeColor = backgroundStrokeColor; this._backgroundStrokeWidth = backgroundStrokeWidth; } get backgroundColor() { return this._backgroundColor; } get backgroundShape() { return this._backgroundShape; } get icon() { return this._icon; } get iconColor() { return this._iconColor; } get backgroundStrokeColor() { return this._backgroundStrokeColor; } get backgroundStrokeWidth() { return this._backgroundStrokeWidth; } } __decorate([ nameForSerialization('backgroundColor'), ignoreFromSerializationIfNull ], ScanditIcon.prototype, "_backgroundColor", void 0); __decorate([ nameForSerialization('backgroundShape'), ignoreFromSerializationIfNull ], ScanditIcon.prototype, "_backgroundShape", void 0); __decorate([ nameForSerialization('icon'), ignoreFromSerializationIfNull ], ScanditIcon.prototype, "_icon", void 0); __decorate([ nameForSerialization('iconColor'), ignoreFromSerializationIfNull ], ScanditIcon.prototype, "_iconColor", void 0); __decorate([ nameForSerialization('backgroundStrokeColor'), ignoreFromSerializationIfNull ], ScanditIcon.prototype, "_backgroundStrokeColor", void 0); __decorate([ nameForSerialization('backgroundStrokeWidth') ], ScanditIcon.prototype, "_backgroundStrokeWidth", void 0); class ScanditIconBuilder { constructor() { this._iconColor = null; this._backgroundColor = null; this._backgroundShape = null; this._icon = null; this._backgroundStrokeColor = null; this._backgroundStrokeWidth = 3.0; } withIconColor(iconColor) { this._iconColor = iconColor; return this; } withBackgroundColor(backgroundColor) { this._backgroundColor = backgroundColor; return this; } withBackgroundShape(backgroundShape) { this._backgroundShape = backgroundShape; return this; } withIcon(iconType) { this._icon = iconType; return this; } withBackgroundStrokeColor(backgroundStrokeColor) { this._backgroundStrokeColor = backgroundStrokeColor; return this; } withBackgroundStrokeWidth(backgroundStrokeWidth) { this._backgroundStrokeWidth = backgroundStrokeWidth; return this; } build() { return new ScanditIcon(this._iconColor, this._backgroundColor, this._backgroundShape, this._icon, this._backgroundStrokeColor, this._backgroundStrokeWidth); } } var ScanditIconShape; (function (ScanditIconShape) { ScanditIconShape["Circle"] = "circle"; ScanditIconShape["Square"] = "square"; })(ScanditIconShape || (ScanditIconShape = {})); var ScanditIconType; (function (ScanditIconType) { ScanditIconType["ArrowRight"] = "arrowRight"; ScanditIconType["ArrowLeft"] = "arrowLeft"; ScanditIconType["ArrowUp"] = "arrowUp"; ScanditIconType["ArrowDown"] = "arrowDown"; ScanditIconType["ToPick"] = "toPick"; ScanditIconType["Checkmark"] = "checkmark"; ScanditIconType["XMark"] = "xmark"; ScanditIconType["QuestionMark"] = "questionMark"; ScanditIconType["ExclamationMark"] = "exclamationMark"; ScanditIconType["LowStock"] = "lowStock"; ScanditIconType["ExpiredItem"] = "expiredItem"; ScanditIconType["WrongItem"] = "wrongItem"; ScanditIconType["FragileItem"] = "fragileItem"; ScanditIconType["StarFilled"] = "starFilled"; ScanditIconType["StarHalfFilled"] = "starHalfFilled"; ScanditIconType["ChevronUp"] = "chevronUp"; ScanditIconType["ChevronDown"] = "chevronDown"; ScanditIconType["ChevronLeft"] = "chevronLeft"; ScanditIconType["ChevronRight"] = "chevronRight"; ScanditIconType["InspectItem"] = "inspectItem"; ScanditIconType["StarOutlined"] = "starOutlined"; ScanditIconType["Print"] = "print"; })(ScanditIconType || (ScanditIconType = {})); class Size extends DefaultSerializeable { get width() { return this._width; } get height() { return this._height; } static fromJSON(json) { return new Size(json.width, json.height); } constructor(width, height) { super(); this._width = width; this._height = height; } } __decorate([ nameForSerialization('width') ], Size.prototype, "_width", void 0); __decorate([ nameForSerialization('height') ], Size.prototype, "_height", void 0); class SizeWithAspect extends DefaultSerializeable { get size() { return this._size; } get aspect() { return this._aspect; } constructor(size, aspect) { super(); this._size = size; this._aspect = aspect; } } __decorate([ nameForSerialization('size') ], SizeWithAspect.prototype, "_size", void 0); __decorate([ nameForSerialization('aspect') ], SizeWithAspect.prototype, "_aspect", void 0); class SizeWithUnit extends DefaultSerializeable { get width() { return this._width; } get height() { return this._height; } constructor(width, height) { super(); this._width = width; this._height = height; } } __decorate([ nameForSerialization('width') ], SizeWithUnit.prototype, "_width", void 0); __decorate([ nameForSerialization('height') ], SizeWithUnit.prototype, "_height", void 0); var SizingMode; (function (SizingMode) { SizingMode["WidthAndHeight"] = "widthAndHeight"; SizingMode["WidthAndAspectRatio"] = "widthAndAspectRatio"; SizingMode["HeightAndAspectRatio"] = "heightAndAspectRatio"; SizingMode["ShorterDimensionAndAspectRatio"] = "shorterDimensionAndAspectRatio"; })(SizingMode || (SizingMode = {})); class SizeWithUnitAndAspect { constructor() { this._widthAndHeight = null; this._widthAndAspectRatio = null; this._heightAndAspectRatio = null; this._shorterDimensionAndAspectRatio = null; } get widthAndHeight() { return this._widthAndHeight; } get widthAndAspectRatio() { return this._widthAndAspectRatio; } get heightAndAspectRatio() { return this._heightAndAspectRatio; } get shorterDimensionAndAspectRatio() { return this._shorterDimensionAndAspectRatio; } get sizingMode() { if (this.widthAndAspectRatio) { return SizingMode.WidthAndAspectRatio; } if (this.heightAndAspectRatio) { return SizingMode.HeightAndAspectRatio; } if (this.shorterDimensionAndAspectRatio) { return SizingMode.ShorterDimensionAndAspectRatio; } return SizingMode.WidthAndHeight; } static sizeWithWidthAndHeight(widthAndHeight) { const sizeWithUnitAndAspect = new SizeWithUnitAndAspect(); sizeWithUnitAndAspect._widthAndHeight = widthAndHeight; return sizeWithUnitAndAspect; } static sizeWithWidthAndAspectRatio(width, aspectRatio) { const sizeWithUnitAndAspect = new SizeWithUnitAndAspect(); sizeWithUnitAndAspect._widthAndAspectRatio = new SizeWithAspect(width, aspectRatio); return sizeWithUnitAndAspect; } static sizeWithHeightAndAspectRatio(height, aspectRatio) { const sizeWithUnitAndAspect = new SizeWithUnitAndAspect(); sizeWithUnitAndAspect._heightAndAspectRatio = new SizeWithAspect(height, aspectRatio); return sizeWithUnitAndAspect; } static sizeWithShorterDimensionAndAspectRatio(shorterDimension, aspectRatio) { const sizeWithUnitAndAspect = new SizeWithUnitAndAspect(); sizeWithUnitAndAspect._shorterDimensionAndAspectRatio = new SizeWithAspect(shorterDimension, aspectRatio); return sizeWithUnitAndAspect; } static fromJSON(json) { if (json.width && json.height) { return this.sizeWithWidthAndHeight(new SizeWithUnit(NumberWithUnit.fromJSON(json.width), NumberWithUnit.fromJSON(json.height))); } else if (json.width && json.aspect) { return this.sizeWithWidthAndAspectRatio(NumberWithUnit.fromJSON(json.width), json.aspect); } else if (json.height && json.aspect) { return this.sizeWithHeightAndAspectRatio(NumberWithUnit.fromJSON(json.height), json.aspect); } else if (json.shorterDimension && json.aspect) { return this.sizeWithShorterDimensionAndAspectRatio(NumberWithUnit.fromJSON(json.shorterDimension), json.aspect); } else { throw new Error(`SizeWithUnitAndAspectJSON is malformed: ${JSON.stringify(json)}`); } } toJSON() { switch (this.sizingMode) { case SizingMode.WidthAndAspectRatio: return { width: this.widthAndAspectRatio.size.toJSON(), aspect: this.widthAndAspectRatio.aspect, }; case SizingMode.HeightAndAspectRatio: return { height: this.heightAndAspectRatio.size.toJSON(), aspect: this.heightAndAspectRatio.aspect, }; case SizingMode.ShorterDimensionAndAspectRatio: return { shorterDimension: this.shorterDimensionAndAspectRatio.size.toJSON(), aspect: this.shorterDimensionAndAspectRatio.aspect, }; default: return { width: this.widthAndHeight.width.toJSON(), height: this.widthAndHeight.height.toJSON(), }; } } } __decorate([ nameForSerialization('widthAndHeight') ], SizeWithUnitAndAspect.prototype, "_widthAndHeight", void 0); __decorate([ nameForSerialization('widthAndAspectRatio') ], SizeWithUnitAndAspect.prototype, "_widthAndAspectRatio", void 0); __decorate([ nameForSerialization('heightAndAspectRatio') ], SizeWithUnitAndAspect.prototype, "_heightAndAspectRatio", void 0); __decorate([ nameForSerialization('shorterDimensionAndAspectRatio') ], SizeWithUnitAndAspect.prototype, "_shorterDimensionAndAspectRatio", void 0); class MarginsWithUnit extends DefaultSerializeable { get left() { return this._left; } get right() { return this._right; } get top() { return this._top; } get bottom() { return this._bottom; } static fromJSON(json) { return new MarginsWithUnit(NumberWithUnit.fromJSON(json.left), NumberWithUnit.fromJSON(json.right), NumberWithUnit.fromJSON(json.top), NumberWithUnit.fromJSON(json.bottom)); } static get zero() { return new MarginsWithUnit(new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel)); } constructor(left, right, top, bottom) { super(); this._left = left; this._right = right; this._top = top; this._bottom = bottom; } } __decorate([ nameForSerialization('left') ], MarginsWithUnit.prototype, "_left", void 0); __decorate([ nameForSerialization('right') ], MarginsWithUnit.prototype, "_right", void 0); __decorate([ nameForSerialization('top') ], MarginsWithUnit.prototype, "_top", void 0); __decorate([ nameForSerialization('bottom') ], MarginsWithUnit.prototype, "_bottom", void 0); class Color { get redComponent() { return this.hexadecimalString.slice(0, 2); } get greenComponent() { return this.hexadecimalString.slice(2, 4); } get blueComponent() { return this.hexadecimalString.slice(4, 6); } get alphaComponent() { return this.hexadecimalString.slice(6, 8); } get red() { return Color.hexToNumber(this.redComponent); } get green() { return Color.hexToNumber(this.greenComponent); } get blue() { return Color.hexToNumber(this.blueComponent); } get alpha() { return Color.hexToNumber(this.alphaComponent); } static fromHex(hex) { return new Color(Color.normalizeHex(hex)); } static fromRGBA(red, green, blue, alpha = 1) { const hexString = [red, green, blue, this.normalizeAlpha(alpha)] .reduce((hex, colorComponent) => hex + this.numberToHex(colorComponent), ''); return new Color(hexString); } static hexToNumber(hex) { return parseInt(hex, 16); } static fromJSON(json) { return Color.fromHex(json); } static numberToHex(x) { x = Math.round(x); let hex = x.toString(16); if (hex.length === 1) { hex = '0' + hex; } return hex.toUpperCase(); } static normalizeHex(hex) { // remove leading # if (hex[0] === '#') { hex = hex.slice(1); } // double digits if single digit if (hex.length < 6) { hex = hex.split('').map(s => s + s).join(''); } // add alpha if missing if (hex.length === 6) { hex = hex + 'FF'; } return '#' + hex.toUpperCase(); } static normalizeAlpha(alpha) { if (alpha > 0 && alpha <= 1) { return 255 * alpha; } return alpha; } constructor(hex) { this.hexadecimalString = hex; } withAlpha(alpha) { const newHex = this.hexadecimalString.slice(0, 6) + Color.numberToHex(Color.normalizeAlpha(alpha)); return Color.fromHex(newHex); } toJSON() { return this.hexadecimalString; } } class Brush extends DefaultSerializeable { static get transparent() { const transparentBlack = Color.fromRGBA(255, 255, 255, 0); return new Brush(transparentBlack, transparentBlack, 0); } get fillColor() { return this.fill.color; } get strokeColor() { return this.stroke.color; } get strokeWidth() { return this.stroke.width; } get copy() { return new Brush(this.fillColor, this.strokeColor, this.strokeWidth); } constructor(fillColor = Brush.defaults.fillColor, strokeColor = Brush.defaults.strokeColor, strokeWidth = Brush.defaults.strokeWidth) { super(); this.fill = { color: fillColor }; this.stroke = { color: strokeColor, width: strokeWidth }; } static fromJSON(brushJson) { return new Brush(Color.fromHex(brushJson.fillColor), Color.fromHex(brushJson.strokeColor), brushJson.strokeWidth); } } var Anchor; (function (Anchor) { Anchor["TopLeft"] = "topLeft"; Anchor["TopCenter"] = "topCenter"; Anchor["TopRight"] = "topRight"; Anchor["CenterLeft"] = "centerLeft"; Anchor["Center"] = "center"; Anchor["CenterRight"] = "centerRight"; Anchor["BottomLeft"] = "bottomLeft"; Anchor["BottomCenter"] = "bottomCenter"; Anchor["BottomRight"] = "bottomRight"; })(Anchor || (Anchor = {})); var Orientation; (function (Orientation) { Orientation["Unknown"] = "unknown"; Orientation["Portrait"] = "portrait"; Orientation["PortraitUpsideDown"] = "portraitUpsideDown"; Orientation["LandscapeRight"] = "landscapeRight"; Orientation["LandscapeLeft"] = "landscapeLeft"; })(Orientation || (Orientation = {})); var Direction; (function (Direction) { Direction["None"] = "none"; Direction["Horizontal"] = "horizontal"; Direction["LeftToRight"] = "leftToRight"; Direction["RightToLeft"] = "rightToLeft"; Direction["Vertical"] = "vertical"; Direction["TopToBottom"] = "topToBottom"; Direction["BottomToTop"] = "bottomToTop"; })(Direction || (Direction = {})); var ScanIntention; (function (ScanIntention) { ScanIntention["Manual"] = "manual"; ScanIntention["Smart"] = "smart"; ScanIntention["SmartSelection"] = "smartSelection"; })(ScanIntention || (ScanIntention = {})); class EventDataParser { static parse(data) { if (data == null) { return null; } return JSON.parse(data); } } class Observable extends DefaultSerializeable { constructor() { super(...arguments); this.listeners = []; } addListener(listener) { this.listeners.push(listener); } removeListener(listener) { this.listeners = this.listeners.filter(l => l !== listener); } notifyListeners(property, value) { this.listeners.forEach(listener => listener(property, value)); } } __decorate([ ignoreFromSerialization ], Observable.prototype, "listeners", void 0); class HtmlElementPosition { constructor(top, left) { this.top = 0; this.left = 0; this.top = top; this.left = left; } didChangeComparedTo(other) { if (!other) return true; return this.top !== other.top || this.left !== other.left; } } class HtmlElementSize { constructor(width, height) { this.width = width; this.height = height; } didChangeComparedTo(other) { if (!other) return true; return this.width !== other.width || this.height !== other.height; } } class HTMLElementState { constructor() { this.isShown = false; this.position = null; this.size = null; this.shouldBeUnderContent = false; } get isValid() { return this.isShown !== undefined && this.isShown !== null && this.position !== undefined && this.position !== null && this.size !== undefined && this.size !== null && this.shouldBeUnderContent !== undefined && this.shouldBeUnderContent !== null; } didChangeComparedTo(other) { var _a, _b, _c, _d; if (!other) return true; const positionChanged = (_b = (_a = this.position) === null || _a === void 0 ? void 0 : _a.didChangeComparedTo(other.position)) !== null && _b !== void 0 ? _b : (this.position !== other.position); const sizeChanged = (_d = (_c = this.size) === null || _c === void 0 ? void 0 : _c.didChangeComparedTo(o