scandit-datacapture-frameworks-core 7.0.2 → 7.1.0-beta.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/dist/index.js CHANGED
@@ -385,6 +385,45 @@ function createEventEmitter() {
385
385
  FactoryMaker.bindInstanceIfNotExists('EventEmitter', ee);
386
386
  }
387
387
 
388
+ /******************************************************************************
389
+ Copyright (c) Microsoft Corporation.
390
+
391
+ Permission to use, copy, modify, and/or distribute this software for any
392
+ purpose with or without fee is hereby granted.
393
+
394
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
395
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
396
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
397
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
398
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
399
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
400
+ PERFORMANCE OF THIS SOFTWARE.
401
+ ***************************************************************************** */
402
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
403
+
404
+
405
+ function __decorate(decorators, target, key, desc) {
406
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
407
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
408
+ 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;
409
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
410
+ }
411
+
412
+ function __awaiter(thisArg, _arguments, P, generator) {
413
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
414
+ return new (P || (P = Promise))(function (resolve, reject) {
415
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
416
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
417
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
418
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
419
+ });
420
+ }
421
+
422
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
423
+ var e = new Error(message);
424
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
425
+ };
426
+
388
427
  class BaseController {
389
428
  get _proxy() {
390
429
  return FactoryMaker.getInstance(this.proxyName);
@@ -402,6 +441,108 @@ class BaseNativeProxy {
402
441
  this.eventEmitter = FactoryMaker.getInstance('EventEmitter');
403
442
  }
404
443
  }
444
+ /**
445
+ * JS Proxy hook to act as middleware to all the calls performed by an AdvancedNativeProxy instance
446
+ * This will allow AdvancedNativeProxy to call dynamically the methods defined in the interface defined
447
+ * as parameter in createAdvancedNativeProxy function
448
+ */
449
+ const advancedNativeProxyHook = {
450
+ /**
451
+ * Dynamic property getter for the AdvancedNativeProxy
452
+ * In order to call a native method this needs to be preceded by the `$` symbol on the name, ie `$methodName`
453
+ * In order to set a native event handler this needs to be preceded by `on$` prefix, ie `on$eventName`
454
+ * @param advancedNativeProxy
455
+ * @param prop
456
+ */
457
+ get(advancedNativeProxy, prop) {
458
+ // Important: $ and on$ are required since if they are not added all
459
+ // properties present on AdvancedNativeProxy will be redirected to the
460
+ // advancedNativeProxy._call, which will call native even for the own
461
+ // properties of the class
462
+ // All the methods with the following structure
463
+ // $methodName will be redirected to the special _call
464
+ // method on AdvancedNativeProxy
465
+ if (prop.startsWith("$")) {
466
+ return (args) => {
467
+ return advancedNativeProxy._call(prop.substring(1), args);
468
+ };
469
+ // All methods with the following structure
470
+ // on$methodName will trigger the event handler properties
471
+ }
472
+ else if (prop.startsWith("on$")) {
473
+ return advancedNativeProxy[prop.substring(3)];
474
+ // Everything else will be taken as a property
475
+ }
476
+ else {
477
+ return advancedNativeProxy[prop];
478
+ }
479
+ }
480
+ };
481
+ /**
482
+ * AdvancedNativeProxy will provide an easy way to communicate between native proxies
483
+ * and other parts of the architecture such as the controller layer
484
+ */
485
+ class AdvancedNativeProxy extends BaseNativeProxy {
486
+ constructor(nativeCaller, events = []) {
487
+ super();
488
+ this.nativeCaller = nativeCaller;
489
+ this.events = events;
490
+ this.eventSubscriptions = new Map();
491
+ this.events.forEach((event) => __awaiter(this, void 0, void 0, function* () {
492
+ yield this._registerEvent(event);
493
+ }));
494
+ // Wrapping the AdvancedNativeProxy instance with the JS proxy hook
495
+ return new Proxy(this, advancedNativeProxyHook);
496
+ }
497
+ dispose() {
498
+ return __awaiter(this, void 0, void 0, function* () {
499
+ for (const event of this.events) {
500
+ yield this._unregisterEvent(event);
501
+ }
502
+ });
503
+ }
504
+ _call(fnName, args) {
505
+ return this.nativeCaller.callFn(fnName, args);
506
+ }
507
+ _registerEvent(event) {
508
+ return __awaiter(this, void 0, void 0, function* () {
509
+ const handler = (args) => __awaiter(this, void 0, void 0, function* () {
510
+ this.eventEmitter.emit(event.nativeEventName, args);
511
+ });
512
+ this.eventEmitter.on(event.nativeEventName, (args) => __awaiter(this, void 0, void 0, function* () {
513
+ // Call to the special method defined on the JS Proxy hook
514
+ yield this[`on$${event.name}`](args);
515
+ }));
516
+ const subscription = yield this.nativeCaller.registerEvent(event.nativeEventName, handler);
517
+ this.eventSubscriptions.set(event.name, subscription);
518
+ });
519
+ }
520
+ _unregisterEvent(event) {
521
+ return __awaiter(this, void 0, void 0, function* () {
522
+ const subscription = this.eventSubscriptions.get(event.name);
523
+ yield this.nativeCaller.unregisterEvent(event.nativeEventName, subscription);
524
+ this.eventEmitter.off(event.nativeEventName);
525
+ this.eventSubscriptions.delete(event.name);
526
+ });
527
+ }
528
+ }
529
+ /**
530
+ * Function to create a custom AdvancedNativeProxy. This will return an object which will provide dynamically the
531
+ * methods specified in the PROXY interface.
532
+ *
533
+ * The Proxy interface implemented in order to call native methods will require a special mark
534
+ * `$methodName` for method calls
535
+ * `on$methodName` for the listeners added to the events defined in eventsEnum
536
+ * @param nativeCaller
537
+ * @param eventsEnum
538
+ */
539
+ function createAdvancedNativeProxy(nativeCaller, eventsEnum = undefined) {
540
+ const eventsList = Object.entries(eventsEnum).map(([key, value]) => ({
541
+ name: key,
542
+ nativeEventName: value
543
+ }));
544
+ return new AdvancedNativeProxy(nativeCaller, eventsList);
545
+ }
405
546
 
406
547
  function getCoreDefaults() {
407
548
  return FactoryMaker.getInstance('CoreDefaults');
@@ -510,45 +651,6 @@ class PrivateZoomGestureDeserializer {
510
651
  }
511
652
  }
512
653
 
513
- /******************************************************************************
514
- Copyright (c) Microsoft Corporation.
515
-
516
- Permission to use, copy, modify, and/or distribute this software for any
517
- purpose with or without fee is hereby granted.
518
-
519
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
520
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
521
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
522
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
523
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
524
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
525
- PERFORMANCE OF THIS SOFTWARE.
526
- ***************************************************************************** */
527
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
528
-
529
-
530
- function __decorate(decorators, target, key, desc) {
531
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
532
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
533
- 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;
534
- return c > 3 && r && Object.defineProperty(target, key, r), r;
535
- }
536
-
537
- function __awaiter(thisArg, _arguments, P, generator) {
538
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
539
- return new (P || (P = Promise))(function (resolve, reject) {
540
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
541
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
542
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
543
- step((generator = generator.apply(thisArg, _arguments || [])).next());
544
- });
545
- }
546
-
547
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
548
- var e = new Error(message);
549
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
550
- };
551
-
552
654
  var FrameSourceState;
553
655
  (function (FrameSourceState) {
554
656
  FrameSourceState["On"] = "on";
@@ -586,1268 +688,1491 @@ var FrameSourceListenerEvents;
586
688
  FrameSourceListenerEvents["didChangeState"] = "FrameSourceListener.onStateChanged";
587
689
  })(FrameSourceListenerEvents || (FrameSourceListenerEvents = {}));
588
690
 
589
- class ImageFrameSourceController {
590
- static forImage(imageFrameSource) {
591
- const controller = new ImageFrameSourceController();
592
- controller.imageFrameSource = imageFrameSource;
593
- return controller;
594
- }
595
- constructor() {
596
- this.eventEmitter = FactoryMaker.getInstance('EventEmitter');
597
- this._proxy = FactoryMaker.getInstance('ImageFrameSourceProxy');
598
- }
599
- getCurrentState() {
600
- return this._proxy.getCurrentCameraState(this.imageFrameSource.position);
691
+ var FontFamily;
692
+ (function (FontFamily) {
693
+ FontFamily["SystemDefault"] = "systemDefault";
694
+ FontFamily["ModernMono"] = "modernMono";
695
+ FontFamily["SystemSans"] = "systemSans";
696
+ })(FontFamily || (FontFamily = {}));
697
+
698
+ var TextAlignment;
699
+ (function (TextAlignment) {
700
+ TextAlignment["Left"] = "left";
701
+ TextAlignment["Right"] = "right";
702
+ TextAlignment["Center"] = "center";
703
+ TextAlignment["Start"] = "start";
704
+ TextAlignment["End"] = "end";
705
+ })(TextAlignment || (TextAlignment = {}));
706
+
707
+ class Point extends DefaultSerializeable {
708
+ get x() {
709
+ return this._x;
601
710
  }
602
- switchCameraToDesiredState(desiredStateJson) {
603
- return this._proxy.switchCameraToDesiredState(desiredStateJson);
711
+ get y() {
712
+ return this._y;
604
713
  }
605
- subscribeListener() {
606
- var _a, _b;
607
- this._proxy.registerListenerForEvents();
608
- (_b = (_a = this._proxy).subscribeDidChangeState) === null || _b === void 0 ? void 0 : _b.call(_a);
609
- this.eventEmitter.on(FrameSourceListenerEvents.didChangeState, (payload) => {
610
- const newState = payload.state;
611
- this.imageFrameSource.listeners.forEach(listener => {
612
- if (listener.didChangeState) {
613
- listener.didChangeState(this.imageFrameSource, newState);
614
- }
615
- });
616
- });
714
+ static fromJSON(json) {
715
+ return new Point(json.x, json.y);
617
716
  }
618
- unsubscribeListener() {
619
- this._proxy.unregisterListenerForEvents();
620
- this.eventEmitter.removeAllListeners(FrameSourceListenerEvents.didChangeState);
717
+ constructor(x, y) {
718
+ super();
719
+ this._x = x;
720
+ this._y = y;
621
721
  }
622
722
  }
723
+ __decorate([
724
+ nameForSerialization('x')
725
+ ], Point.prototype, "_x", void 0);
726
+ __decorate([
727
+ nameForSerialization('y')
728
+ ], Point.prototype, "_y", void 0);
623
729
 
624
- class ImageFrameSource extends DefaultSerializeable {
625
- set context(newContext) {
626
- if (newContext == null) {
627
- this.controller.unsubscribeListener();
628
- }
629
- else if (this._context == null) {
630
- this.controller.subscribeListener();
631
- }
632
- this._context = newContext;
730
+ class Quadrilateral extends DefaultSerializeable {
731
+ get topLeft() {
732
+ return this._topLeft;
633
733
  }
634
- get context() {
635
- return this._context;
734
+ get topRight() {
735
+ return this._topRight;
636
736
  }
637
- get desiredState() {
638
- return this._desiredState;
737
+ get bottomRight() {
738
+ return this._bottomRight;
639
739
  }
640
- static create(image) {
641
- const imageFrameSource = new ImageFrameSource();
642
- imageFrameSource.image = image;
643
- return imageFrameSource;
740
+ get bottomLeft() {
741
+ return this._bottomLeft;
644
742
  }
645
743
  static fromJSON(json) {
646
- return ImageFrameSource.create(json.image);
744
+ return new Quadrilateral(Point.fromJSON(json.topLeft), Point.fromJSON(json.topRight), Point.fromJSON(json.bottomRight), Point.fromJSON(json.bottomLeft));
647
745
  }
648
- constructor() {
746
+ constructor(topLeft, topRight, bottomRight, bottomLeft) {
649
747
  super();
650
- this.type = 'image';
651
- this.image = '';
652
- this._id = `${Date.now()}`;
653
- this._desiredState = FrameSourceState.Off;
654
- this.listeners = [];
655
- this._context = null;
656
- this.controller = ImageFrameSourceController.forImage(this);
657
- }
658
- didChange() {
659
- if (this.context) {
660
- return this.context.update();
661
- }
662
- else {
663
- return Promise.resolve();
664
- }
665
- }
666
- switchToDesiredState(state) {
667
- this._desiredState = state;
668
- return this.controller.switchCameraToDesiredState(state);
669
- }
670
- addListener(listener) {
671
- if (listener == null) {
672
- return;
673
- }
674
- if (this.listeners.includes(listener)) {
675
- return;
676
- }
677
- this.listeners.push(listener);
678
- }
679
- removeListener(listener) {
680
- if (listener == null) {
681
- return;
682
- }
683
- if (!this.listeners.includes(listener)) {
684
- return;
685
- }
686
- this.listeners.splice(this.listeners.indexOf(listener), 1);
687
- }
688
- getCurrentState() {
689
- return this.controller.getCurrentState();
748
+ this._topLeft = topLeft;
749
+ this._topRight = topRight;
750
+ this._bottomRight = bottomRight;
751
+ this._bottomLeft = bottomLeft;
690
752
  }
691
753
  }
692
754
  __decorate([
693
- nameForSerialization('id')
694
- ], ImageFrameSource.prototype, "_id", void 0);
695
- __decorate([
696
- nameForSerialization('desiredState')
697
- ], ImageFrameSource.prototype, "_desiredState", void 0);
755
+ nameForSerialization('topLeft')
756
+ ], Quadrilateral.prototype, "_topLeft", void 0);
698
757
  __decorate([
699
- ignoreFromSerialization
700
- ], ImageFrameSource.prototype, "listeners", void 0);
758
+ nameForSerialization('topRight')
759
+ ], Quadrilateral.prototype, "_topRight", void 0);
701
760
  __decorate([
702
- ignoreFromSerialization
703
- ], ImageFrameSource.prototype, "_context", void 0);
761
+ nameForSerialization('bottomRight')
762
+ ], Quadrilateral.prototype, "_bottomRight", void 0);
704
763
  __decorate([
705
- ignoreFromSerialization
706
- ], ImageFrameSource.prototype, "controller", void 0);
764
+ nameForSerialization('bottomLeft')
765
+ ], Quadrilateral.prototype, "_bottomLeft", void 0);
707
766
 
708
- class PrivateFrameData {
709
- get imageBuffers() {
710
- return this._imageBuffers;
767
+ class NumberWithUnit extends DefaultSerializeable {
768
+ get value() {
769
+ return this._value;
711
770
  }
712
- get orientation() {
713
- return this._orientation;
771
+ get unit() {
772
+ return this._unit;
714
773
  }
715
774
  static fromJSON(json) {
716
- const frameData = new PrivateFrameData();
717
- frameData._imageBuffers = json.imageBuffers.map((imageBufferJSON) => {
718
- const imageBuffer = new ImageBuffer();
719
- imageBuffer._width = imageBufferJSON.width;
720
- imageBuffer._height = imageBufferJSON.height;
721
- imageBuffer._data = imageBufferJSON.data;
722
- return imageBuffer;
723
- });
724
- frameData._orientation = json.orientation;
725
- return frameData;
775
+ return new NumberWithUnit(json.value, json.unit);
726
776
  }
727
- static empty() {
728
- const frameData = new PrivateFrameData();
729
- frameData._imageBuffers = [];
730
- frameData._orientation = 90;
731
- return frameData;
777
+ constructor(value, unit) {
778
+ super();
779
+ this._value = value;
780
+ this._unit = unit;
732
781
  }
733
782
  }
783
+ __decorate([
784
+ nameForSerialization('value')
785
+ ], NumberWithUnit.prototype, "_value", void 0);
786
+ __decorate([
787
+ nameForSerialization('unit')
788
+ ], NumberWithUnit.prototype, "_unit", void 0);
734
789
 
735
- class CameraController {
736
- static get _proxy() {
737
- return FactoryMaker.getInstance('CameraProxy');
738
- }
739
- static forCamera(camera) {
740
- const controller = new CameraController();
741
- controller.camera = camera;
742
- return controller;
743
- }
744
- constructor() {
745
- this.eventEmitter = FactoryMaker.getInstance('EventEmitter');
746
- }
747
- get privateCamera() {
748
- return this.camera;
749
- }
750
- static getFrame(frameId) {
751
- return __awaiter(this, void 0, void 0, function* () {
752
- const frameDataJSONString = yield CameraController._proxy.getFrame(frameId);
753
- if (frameDataJSONString == null) {
754
- return PrivateFrameData.empty();
755
- }
756
- const frameDataJSON = JSON.parse(frameDataJSONString);
757
- return PrivateFrameData.fromJSON(frameDataJSON);
758
- });
759
- }
760
- static getFrameOrNull(frameId) {
761
- return __awaiter(this, void 0, void 0, function* () {
762
- const frameDataJSONString = yield CameraController._proxy.getFrame(frameId);
763
- if (frameDataJSONString == null) {
764
- return null;
765
- }
766
- const frameDataJSON = JSON.parse(frameDataJSONString);
767
- return PrivateFrameData.fromJSON(frameDataJSON);
768
- });
769
- }
770
- getCurrentState() {
771
- return CameraController._proxy.getCurrentCameraState(this.privateCamera.position);
790
+ var MeasureUnit;
791
+ (function (MeasureUnit) {
792
+ MeasureUnit["DIP"] = "dip";
793
+ MeasureUnit["Pixel"] = "pixel";
794
+ MeasureUnit["Fraction"] = "fraction";
795
+ })(MeasureUnit || (MeasureUnit = {}));
796
+
797
+ class PointWithUnit extends DefaultSerializeable {
798
+ get x() {
799
+ return this._x;
772
800
  }
773
- getIsTorchAvailable() {
774
- return CameraController._proxy.isTorchAvailable(this.privateCamera.position);
801
+ get y() {
802
+ return this._y;
775
803
  }
776
- switchCameraToDesiredState(desiredState) {
777
- return CameraController._proxy.switchCameraToDesiredState(desiredState);
804
+ static fromJSON(json) {
805
+ return new PointWithUnit(NumberWithUnit.fromJSON(json.x), NumberWithUnit.fromJSON(json.y));
778
806
  }
779
- subscribeListener() {
780
- var _a, _b;
781
- CameraController._proxy.registerListenerForCameraEvents();
782
- (_b = (_a = CameraController._proxy).subscribeDidChangeState) === null || _b === void 0 ? void 0 : _b.call(_a);
783
- this.eventEmitter.on(FrameSourceListenerEvents.didChangeState, (state) => {
784
- this.privateCamera.listeners.forEach(listener => {
785
- var _a;
786
- (_a = listener === null || listener === void 0 ? void 0 : listener.didChangeState) === null || _a === void 0 ? void 0 : _a.call(listener, this.camera, state);
787
- });
788
- });
807
+ static get zero() {
808
+ return new PointWithUnit(new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel));
789
809
  }
790
- unsubscribeListener() {
791
- CameraController._proxy.unregisterListenerForCameraEvents();
792
- this.eventEmitter.off(FrameSourceListenerEvents.didChangeState);
810
+ constructor(x, y) {
811
+ super();
812
+ this._x = x;
813
+ this._y = y;
793
814
  }
794
815
  }
816
+ __decorate([
817
+ nameForSerialization('x')
818
+ ], PointWithUnit.prototype, "_x", void 0);
819
+ __decorate([
820
+ nameForSerialization('y')
821
+ ], PointWithUnit.prototype, "_y", void 0);
795
822
 
796
- var TorchState;
797
- (function (TorchState) {
798
- TorchState["On"] = "on";
799
- TorchState["Off"] = "off";
800
- TorchState["Auto"] = "auto";
801
- })(TorchState || (TorchState = {}));
802
-
803
- class Camera extends DefaultSerializeable {
804
- static get coreDefaults() {
805
- return getCoreDefaults();
823
+ class Rect extends DefaultSerializeable {
824
+ get origin() {
825
+ return this._origin;
806
826
  }
807
- set context(newContext) {
808
- this._context = newContext;
827
+ get size() {
828
+ return this._size;
809
829
  }
810
- get context() {
811
- return this._context;
830
+ constructor(origin, size) {
831
+ super();
832
+ this._origin = origin;
833
+ this._size = size;
812
834
  }
813
- static get default() {
814
- if (Camera.coreDefaults.Camera.defaultPosition) {
815
- const camera = new Camera();
816
- camera.position = Camera.coreDefaults.Camera.defaultPosition;
817
- return camera;
818
- }
819
- else {
820
- return null;
821
- }
835
+ }
836
+ __decorate([
837
+ nameForSerialization('origin')
838
+ ], Rect.prototype, "_origin", void 0);
839
+ __decorate([
840
+ nameForSerialization('size')
841
+ ], Rect.prototype, "_size", void 0);
842
+
843
+ class RectWithUnit extends DefaultSerializeable {
844
+ get origin() {
845
+ return this._origin;
822
846
  }
823
- static withSettings(settings) {
824
- const camera = Camera.default;
825
- if (camera) {
826
- camera.settings = settings;
827
- }
828
- return camera;
847
+ get size() {
848
+ return this._size;
829
849
  }
830
- static asPositionWithSettings(cameraPosition, settings) {
831
- if (Camera.coreDefaults.Camera.availablePositions.includes(cameraPosition)) {
832
- const camera = new Camera();
833
- camera.settings = settings;
834
- camera.position = cameraPosition;
835
- return camera;
836
- }
837
- else {
838
- return null;
839
- }
850
+ constructor(origin, size) {
851
+ super();
852
+ this._origin = origin;
853
+ this._size = size;
840
854
  }
841
- static atPosition(cameraPosition) {
842
- if (Camera.coreDefaults.Camera.availablePositions.includes(cameraPosition)) {
843
- const camera = new Camera();
844
- camera.position = cameraPosition;
845
- return camera;
846
- }
847
- else {
855
+ }
856
+ __decorate([
857
+ nameForSerialization('origin')
858
+ ], RectWithUnit.prototype, "_origin", void 0);
859
+ __decorate([
860
+ nameForSerialization('size')
861
+ ], RectWithUnit.prototype, "_size", void 0);
862
+
863
+ class ScanditIcon extends DefaultSerializeable {
864
+ static fromJSON(json) {
865
+ if (!json) {
848
866
  return null;
849
867
  }
868
+ const scanditIcon = new ScanditIcon(json.iconColor || null, json.backgroundColor || null, json.backgroundShape || null, json.icon || null, json.backgroundStrokeColor || null, json.backgroundStrokeWidth);
869
+ return scanditIcon;
850
870
  }
851
- get desiredState() {
852
- return this._desiredState;
853
- }
854
- set desiredTorchState(desiredTorchState) {
855
- this._desiredTorchState = desiredTorchState;
856
- this.didChange();
857
- }
858
- get desiredTorchState() {
859
- return this._desiredTorchState;
860
- }
861
- constructor() {
871
+ constructor(iconColor, backgroundColor, backgroundShape, icon, backgroundStrokeColor, backgroundStrokeWidth) {
862
872
  super();
863
- this.type = 'camera';
864
- this.settings = null;
865
- this._desiredTorchState = TorchState.Off;
866
- this._desiredState = FrameSourceState.Off;
867
- this.listeners = [];
868
- this._context = null;
869
- this.controller = CameraController.forCamera(this);
870
- }
871
- switchToDesiredState(state) {
872
- this._desiredState = state;
873
- return this.controller.switchCameraToDesiredState(state);
874
- }
875
- getCurrentState() {
876
- return this.controller.getCurrentState();
873
+ this._backgroundStrokeWidth = 3.0;
874
+ this._iconColor = iconColor;
875
+ this._backgroundColor = backgroundColor;
876
+ this._backgroundShape = backgroundShape;
877
+ this._icon = icon;
878
+ this._backgroundStrokeColor = backgroundStrokeColor;
879
+ this._backgroundStrokeWidth = backgroundStrokeWidth;
877
880
  }
878
- getIsTorchAvailable() {
879
- return this.controller.getIsTorchAvailable();
881
+ get backgroundColor() {
882
+ return this._backgroundColor;
880
883
  }
881
- /**
882
- * @deprecated
883
- */
884
- get isTorchAvailable() {
885
- console.warn('isTorchAvailable is deprecated. Use getIsTorchAvailable instead.');
886
- return false;
884
+ get backgroundShape() {
885
+ return this._backgroundShape;
887
886
  }
888
- addListener(listener) {
889
- if (listener == null) {
890
- return;
891
- }
892
- if (this.listeners.length === 0) {
893
- this.controller.subscribeListener();
894
- }
895
- if (this.listeners.includes(listener)) {
896
- return;
897
- }
898
- this.listeners.push(listener);
887
+ get icon() {
888
+ return this._icon;
899
889
  }
900
- removeListener(listener) {
901
- if (listener == null) {
902
- return;
903
- }
904
- if (!this.listeners.includes(listener)) {
905
- return;
906
- }
907
- this.listeners.splice(this.listeners.indexOf(listener), 1);
908
- if (this.listeners.length === 0) {
909
- this.controller.unsubscribeListener();
910
- }
890
+ get iconColor() {
891
+ return this._iconColor;
911
892
  }
912
- applySettings(settings) {
913
- this.settings = settings;
914
- return this.didChange();
893
+ get backgroundStrokeColor() {
894
+ return this._backgroundStrokeColor;
915
895
  }
916
- didChange() {
917
- return __awaiter(this, void 0, void 0, function* () {
918
- if (this.context) {
919
- yield this.context.update();
920
- }
921
- });
896
+ get backgroundStrokeWidth() {
897
+ return this._backgroundStrokeWidth;
922
898
  }
923
899
  }
924
900
  __decorate([
925
- serializationDefault({})
926
- ], Camera.prototype, "settings", void 0);
927
- __decorate([
928
- nameForSerialization('desiredTorchState')
929
- ], Camera.prototype, "_desiredTorchState", void 0);
901
+ nameForSerialization('backgroundColor'),
902
+ ignoreFromSerializationIfNull
903
+ ], ScanditIcon.prototype, "_backgroundColor", void 0);
930
904
  __decorate([
931
- ignoreFromSerialization
932
- ], Camera.prototype, "_desiredState", void 0);
905
+ nameForSerialization('backgroundShape'),
906
+ ignoreFromSerializationIfNull
907
+ ], ScanditIcon.prototype, "_backgroundShape", void 0);
933
908
  __decorate([
934
- ignoreFromSerialization
935
- ], Camera.prototype, "listeners", void 0);
909
+ nameForSerialization('icon'),
910
+ ignoreFromSerializationIfNull
911
+ ], ScanditIcon.prototype, "_icon", void 0);
936
912
  __decorate([
937
- ignoreFromSerialization
938
- ], Camera.prototype, "_context", void 0);
913
+ nameForSerialization('iconColor'),
914
+ ignoreFromSerializationIfNull
915
+ ], ScanditIcon.prototype, "_iconColor", void 0);
939
916
  __decorate([
940
- ignoreFromSerialization
941
- ], Camera.prototype, "controller", void 0);
917
+ nameForSerialization('backgroundStrokeColor'),
918
+ ignoreFromSerializationIfNull
919
+ ], ScanditIcon.prototype, "_backgroundStrokeColor", void 0);
942
920
  __decorate([
943
- ignoreFromSerialization
944
- ], Camera, "coreDefaults", null);
921
+ nameForSerialization('backgroundStrokeWidth')
922
+ ], ScanditIcon.prototype, "_backgroundStrokeWidth", void 0);
945
923
 
946
- class ControlImage extends DefaultSerializeable {
947
- constructor(type, data, name) {
948
- super();
949
- this.type = type;
950
- this._data = data;
951
- this._name = name;
924
+ class ScanditIconBuilder {
925
+ constructor() {
926
+ this._iconColor = null;
927
+ this._backgroundColor = null;
928
+ this._backgroundShape = null;
929
+ this._icon = null;
930
+ this._backgroundStrokeColor = null;
931
+ this._backgroundStrokeWidth = 3.0;
952
932
  }
953
- static fromBase64EncodedImage(data) {
954
- if (data === null)
955
- return null;
956
- return new ControlImage("base64", data, null);
933
+ withIconColor(iconColor) {
934
+ this._iconColor = iconColor;
935
+ return this;
957
936
  }
958
- static fromResourceName(resource) {
959
- return new ControlImage("resource", null, resource);
937
+ withBackgroundColor(backgroundColor) {
938
+ this._backgroundColor = backgroundColor;
939
+ return this;
960
940
  }
961
- isBase64EncodedImage() {
962
- return this.type === "base64";
941
+ withBackgroundShape(backgroundShape) {
942
+ this._backgroundShape = backgroundShape;
943
+ return this;
963
944
  }
964
- get data() {
965
- return this._data;
945
+ withIcon(iconType) {
946
+ this._icon = iconType;
947
+ return this;
948
+ }
949
+ withBackgroundStrokeColor(backgroundStrokeColor) {
950
+ this._backgroundStrokeColor = backgroundStrokeColor;
951
+ return this;
952
+ }
953
+ withBackgroundStrokeWidth(backgroundStrokeWidth) {
954
+ this._backgroundStrokeWidth = backgroundStrokeWidth;
955
+ return this;
956
+ }
957
+ build() {
958
+ return new ScanditIcon(this._iconColor, this._backgroundColor, this._backgroundShape, this._icon, this._backgroundStrokeColor, this._backgroundStrokeWidth);
966
959
  }
967
960
  }
968
- __decorate([
969
- ignoreFromSerializationIfNull,
970
- nameForSerialization('data')
971
- ], ControlImage.prototype, "_data", void 0);
972
- __decorate([
973
- ignoreFromSerializationIfNull,
974
- nameForSerialization('name')
975
- ], ControlImage.prototype, "_name", void 0);
976
961
 
977
- class ContextStatus {
978
- static fromJSON(json) {
979
- const status = new ContextStatus();
980
- status._code = json.code;
981
- status._message = json.message;
982
- status._isValid = json.isValid;
983
- return status;
962
+ var ScanditIconShape;
963
+ (function (ScanditIconShape) {
964
+ ScanditIconShape["Circle"] = "circle";
965
+ ScanditIconShape["Square"] = "square";
966
+ })(ScanditIconShape || (ScanditIconShape = {}));
967
+
968
+ var ScanditIconType;
969
+ (function (ScanditIconType) {
970
+ ScanditIconType["ArrowRight"] = "arrowRight";
971
+ ScanditIconType["ArrowLeft"] = "arrowLeft";
972
+ ScanditIconType["ArrowUp"] = "arrowUp";
973
+ ScanditIconType["ArrowDown"] = "arrowDown";
974
+ ScanditIconType["ToPick"] = "toPick";
975
+ ScanditIconType["Checkmark"] = "checkmark";
976
+ ScanditIconType["XMark"] = "xmark";
977
+ ScanditIconType["QuestionMark"] = "questionMark";
978
+ ScanditIconType["ExclamationMark"] = "exclamationMark";
979
+ ScanditIconType["LowStock"] = "lowStock";
980
+ ScanditIconType["ExpiredItem"] = "expiredItem";
981
+ ScanditIconType["WrongItem"] = "wrongItem";
982
+ ScanditIconType["FragileItem"] = "fragileItem";
983
+ ScanditIconType["StarFilled"] = "starFilled";
984
+ ScanditIconType["StarHalfFilled"] = "starHalfFilled";
985
+ ScanditIconType["ChevronUp"] = "chevronUp";
986
+ ScanditIconType["ChevronDown"] = "chevronDown";
987
+ ScanditIconType["ChevronLeft"] = "chevronLeft";
988
+ ScanditIconType["ChevronRight"] = "chevronRight";
989
+ ScanditIconType["InspectItem"] = "inspectItem";
990
+ ScanditIconType["StarOutlined"] = "starOutlined";
991
+ ScanditIconType["Print"] = "print";
992
+ })(ScanditIconType || (ScanditIconType = {}));
993
+
994
+ class Size extends DefaultSerializeable {
995
+ get width() {
996
+ return this._width;
984
997
  }
985
- get message() {
986
- return this._message;
998
+ get height() {
999
+ return this._height;
987
1000
  }
988
- get code() {
989
- return this._code;
1001
+ static fromJSON(json) {
1002
+ return new Size(json.width, json.height);
990
1003
  }
991
- get isValid() {
992
- return this._isValid;
1004
+ constructor(width, height) {
1005
+ super();
1006
+ this._width = width;
1007
+ this._height = height;
993
1008
  }
994
1009
  }
1010
+ __decorate([
1011
+ nameForSerialization('width')
1012
+ ], Size.prototype, "_width", void 0);
1013
+ __decorate([
1014
+ nameForSerialization('height')
1015
+ ], Size.prototype, "_height", void 0);
995
1016
 
996
- class DataCaptureContextSettings extends DefaultSerializeable {
997
- constructor() {
998
- super();
1017
+ class SizeWithAspect extends DefaultSerializeable {
1018
+ get size() {
1019
+ return this._size;
999
1020
  }
1000
- setProperty(name, value) {
1001
- this[name] = value;
1021
+ get aspect() {
1022
+ return this._aspect;
1002
1023
  }
1003
- getProperty(name) {
1004
- return this[name];
1024
+ constructor(size, aspect) {
1025
+ super();
1026
+ this._size = size;
1027
+ this._aspect = aspect;
1005
1028
  }
1006
1029
  }
1030
+ __decorate([
1031
+ nameForSerialization('size')
1032
+ ], SizeWithAspect.prototype, "_size", void 0);
1033
+ __decorate([
1034
+ nameForSerialization('aspect')
1035
+ ], SizeWithAspect.prototype, "_aspect", void 0);
1007
1036
 
1008
- class DataCaptureContextFeatures {
1009
- static get featureFlags() {
1010
- return this._featureFlags;
1037
+ class SizeWithUnit extends DefaultSerializeable {
1038
+ get width() {
1039
+ return this._width;
1011
1040
  }
1012
- static set featureFlags(value) {
1013
- this._featureFlags = value;
1041
+ get height() {
1042
+ return this._height;
1043
+ }
1044
+ constructor(width, height) {
1045
+ super();
1046
+ this._width = width;
1047
+ this._height = height;
1014
1048
  }
1015
1049
  }
1016
- DataCaptureContextFeatures._featureFlags = {};
1050
+ __decorate([
1051
+ nameForSerialization('width')
1052
+ ], SizeWithUnit.prototype, "_width", void 0);
1053
+ __decorate([
1054
+ nameForSerialization('height')
1055
+ ], SizeWithUnit.prototype, "_height", void 0);
1017
1056
 
1018
- class OpenSourceSoftwareLicenseInfo {
1019
- constructor(licenseText) {
1020
- this._licenseText = licenseText;
1057
+ var SizingMode;
1058
+ (function (SizingMode) {
1059
+ SizingMode["WidthAndHeight"] = "widthAndHeight";
1060
+ SizingMode["WidthAndAspectRatio"] = "widthAndAspectRatio";
1061
+ SizingMode["HeightAndAspectRatio"] = "heightAndAspectRatio";
1062
+ SizingMode["ShorterDimensionAndAspectRatio"] = "shorterDimensionAndAspectRatio";
1063
+ })(SizingMode || (SizingMode = {}));
1064
+
1065
+ class SizeWithUnitAndAspect {
1066
+ constructor() {
1067
+ this._widthAndHeight = null;
1068
+ this._widthAndAspectRatio = null;
1069
+ this._heightAndAspectRatio = null;
1070
+ this._shorterDimensionAndAspectRatio = null;
1021
1071
  }
1022
- get licenseText() {
1023
- return this._licenseText;
1072
+ get widthAndHeight() {
1073
+ return this._widthAndHeight;
1024
1074
  }
1025
- }
1026
-
1027
- var DataCaptureContextEvents;
1028
- (function (DataCaptureContextEvents) {
1029
- DataCaptureContextEvents["didChangeStatus"] = "DataCaptureContextListener.onStatusChanged";
1030
- DataCaptureContextEvents["didStartObservingContext"] = "DataCaptureContextListener.onObservationStarted";
1031
- })(DataCaptureContextEvents || (DataCaptureContextEvents = {}));
1032
- class DataCaptureContextController {
1033
- get framework() {
1034
- return this._proxy.framework;
1075
+ get widthAndAspectRatio() {
1076
+ return this._widthAndAspectRatio;
1035
1077
  }
1036
- get frameworkVersion() {
1037
- return this._proxy.frameworkVersion;
1078
+ get heightAndAspectRatio() {
1079
+ return this._heightAndAspectRatio;
1038
1080
  }
1039
- get privateContext() {
1040
- return this.context;
1081
+ get shorterDimensionAndAspectRatio() {
1082
+ return this._shorterDimensionAndAspectRatio;
1041
1083
  }
1042
- static forDataCaptureContext(context) {
1043
- const controller = new DataCaptureContextController();
1044
- controller.context = context;
1045
- controller.initialize();
1046
- return controller;
1084
+ get sizingMode() {
1085
+ if (this.widthAndAspectRatio) {
1086
+ return SizingMode.WidthAndAspectRatio;
1087
+ }
1088
+ if (this.heightAndAspectRatio) {
1089
+ return SizingMode.HeightAndAspectRatio;
1090
+ }
1091
+ if (this.shorterDimensionAndAspectRatio) {
1092
+ return SizingMode.ShorterDimensionAndAspectRatio;
1093
+ }
1094
+ return SizingMode.WidthAndHeight;
1047
1095
  }
1048
- constructor() {
1049
- this._proxy = FactoryMaker.getInstance('DataCaptureContextProxy');
1050
- this.eventEmitter = FactoryMaker.getInstance('EventEmitter');
1096
+ static sizeWithWidthAndHeight(widthAndHeight) {
1097
+ const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1098
+ sizeWithUnitAndAspect._widthAndHeight = widthAndHeight;
1099
+ return sizeWithUnitAndAspect;
1051
1100
  }
1052
- updateContextFromJSON() {
1053
- return __awaiter(this, void 0, void 0, function* () {
1054
- try {
1055
- yield this._proxy.updateContextFromJSON(JSON.stringify(this.context.toJSON()));
1056
- }
1057
- catch (error) {
1058
- this.notifyListenersOfDeserializationError(error);
1059
- throw error;
1060
- }
1061
- });
1101
+ static sizeWithWidthAndAspectRatio(width, aspectRatio) {
1102
+ const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1103
+ sizeWithUnitAndAspect._widthAndAspectRatio = new SizeWithAspect(width, aspectRatio);
1104
+ return sizeWithUnitAndAspect;
1062
1105
  }
1063
- addModeToContext(mode) {
1064
- return this._proxy.addModeToContext(JSON.stringify(mode.toJSON()));
1106
+ static sizeWithHeightAndAspectRatio(height, aspectRatio) {
1107
+ const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1108
+ sizeWithUnitAndAspect._heightAndAspectRatio = new SizeWithAspect(height, aspectRatio);
1109
+ return sizeWithUnitAndAspect;
1065
1110
  }
1066
- removeModeFromContext(mode) {
1067
- return this._proxy.removeModeFromContext(JSON.stringify(mode.toJSON()));
1111
+ static sizeWithShorterDimensionAndAspectRatio(shorterDimension, aspectRatio) {
1112
+ const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1113
+ sizeWithUnitAndAspect._shorterDimensionAndAspectRatio = new SizeWithAspect(shorterDimension, aspectRatio);
1114
+ return sizeWithUnitAndAspect;
1068
1115
  }
1069
- removeAllModesFromContext() {
1070
- return this._proxy.removeAllModesFromContext();
1116
+ static fromJSON(json) {
1117
+ if (json.width && json.height) {
1118
+ return this.sizeWithWidthAndHeight(new SizeWithUnit(NumberWithUnit.fromJSON(json.width), NumberWithUnit.fromJSON(json.height)));
1119
+ }
1120
+ else if (json.width && json.aspect) {
1121
+ return this.sizeWithWidthAndAspectRatio(NumberWithUnit.fromJSON(json.width), json.aspect);
1122
+ }
1123
+ else if (json.height && json.aspect) {
1124
+ return this.sizeWithHeightAndAspectRatio(NumberWithUnit.fromJSON(json.height), json.aspect);
1125
+ }
1126
+ else if (json.shorterDimension && json.aspect) {
1127
+ return this.sizeWithShorterDimensionAndAspectRatio(NumberWithUnit.fromJSON(json.shorterDimension), json.aspect);
1128
+ }
1129
+ else {
1130
+ throw new Error(`SizeWithUnitAndAspectJSON is malformed: ${JSON.stringify(json)}`);
1131
+ }
1071
1132
  }
1072
- dispose() {
1073
- this.unsubscribeListener();
1074
- this._proxy.dispose();
1133
+ toJSON() {
1134
+ switch (this.sizingMode) {
1135
+ case SizingMode.WidthAndAspectRatio:
1136
+ return {
1137
+ width: this.widthAndAspectRatio.size.toJSON(),
1138
+ aspect: this.widthAndAspectRatio.aspect,
1139
+ };
1140
+ case SizingMode.HeightAndAspectRatio:
1141
+ return {
1142
+ height: this.heightAndAspectRatio.size.toJSON(),
1143
+ aspect: this.heightAndAspectRatio.aspect,
1144
+ };
1145
+ case SizingMode.ShorterDimensionAndAspectRatio:
1146
+ return {
1147
+ shorterDimension: this.shorterDimensionAndAspectRatio.size.toJSON(),
1148
+ aspect: this.shorterDimensionAndAspectRatio.aspect,
1149
+ };
1150
+ default:
1151
+ return {
1152
+ width: this.widthAndHeight.width.toJSON(),
1153
+ height: this.widthAndHeight.height.toJSON(),
1154
+ };
1155
+ }
1075
1156
  }
1076
- unsubscribeListener() {
1077
- this._proxy.unregisterListenerForDataCaptureContext();
1078
- this.eventEmitter.removeAllListeners(DataCaptureContextEvents.didChangeStatus);
1079
- this.eventEmitter.removeAllListeners(DataCaptureContextEvents.didStartObservingContext);
1157
+ }
1158
+ __decorate([
1159
+ nameForSerialization('widthAndHeight')
1160
+ ], SizeWithUnitAndAspect.prototype, "_widthAndHeight", void 0);
1161
+ __decorate([
1162
+ nameForSerialization('widthAndAspectRatio')
1163
+ ], SizeWithUnitAndAspect.prototype, "_widthAndAspectRatio", void 0);
1164
+ __decorate([
1165
+ nameForSerialization('heightAndAspectRatio')
1166
+ ], SizeWithUnitAndAspect.prototype, "_heightAndAspectRatio", void 0);
1167
+ __decorate([
1168
+ nameForSerialization('shorterDimensionAndAspectRatio')
1169
+ ], SizeWithUnitAndAspect.prototype, "_shorterDimensionAndAspectRatio", void 0);
1170
+
1171
+ class MarginsWithUnit extends DefaultSerializeable {
1172
+ get left() {
1173
+ return this._left;
1080
1174
  }
1081
- initialize() {
1082
- this.subscribeListener();
1083
- return this.initializeContextFromJSON();
1175
+ get right() {
1176
+ return this._right;
1084
1177
  }
1085
- initializeContextFromJSON() {
1086
- return __awaiter(this, void 0, void 0, function* () {
1087
- try {
1088
- const featureFlagsString = yield this._proxy.contextFromJSON(JSON.stringify(this.context.toJSON()));
1089
- DataCaptureContextFeatures.featureFlags =
1090
- JSON.parse(featureFlagsString);
1091
- }
1092
- catch (error) {
1093
- this.notifyListenersOfDeserializationError(error);
1094
- throw error;
1095
- }
1096
- });
1178
+ get top() {
1179
+ return this._top;
1097
1180
  }
1098
- static getOpenSourceSoftwareLicenseInfo() {
1099
- return __awaiter(this, void 0, void 0, function* () {
1100
- const proxy = FactoryMaker.getInstance('DataCaptureContextProxy');
1101
- const licenseText = yield proxy.getOpenSourceSoftwareLicenseInfo();
1102
- return new OpenSourceSoftwareLicenseInfo(licenseText);
1103
- });
1181
+ get bottom() {
1182
+ return this._bottom;
1104
1183
  }
1105
- subscribeListener() {
1106
- var _a, _b, _c, _d;
1107
- this._proxy.registerListenerForDataCaptureContext();
1108
- (_b = (_a = this._proxy).subscribeDidChangeStatus) === null || _b === void 0 ? void 0 : _b.call(_a);
1109
- (_d = (_c = this._proxy).subscribeDidStartObservingContext) === null || _d === void 0 ? void 0 : _d.call(_c);
1110
- this.eventEmitter.on(DataCaptureContextEvents.didChangeStatus, (contextStatus) => {
1111
- this.notifyListenersOfDidChangeStatus(contextStatus);
1112
- });
1113
- this.eventEmitter.on(DataCaptureContextEvents.didStartObservingContext, () => {
1114
- this.privateContext.listeners.forEach(listener => {
1115
- var _a;
1116
- (_a = listener.didStartObservingContext) === null || _a === void 0 ? void 0 : _a.call(listener, this.context);
1117
- });
1118
- });
1184
+ static fromJSON(json) {
1185
+ return new MarginsWithUnit(NumberWithUnit.fromJSON(json.left), NumberWithUnit.fromJSON(json.right), NumberWithUnit.fromJSON(json.top), NumberWithUnit.fromJSON(json.bottom));
1119
1186
  }
1120
- notifyListenersOfDeserializationError(error) {
1121
- const contextStatus = ContextStatus
1122
- .fromJSON({
1123
- message: error,
1124
- code: -1,
1125
- isValid: true,
1126
- });
1127
- this.notifyListenersOfDidChangeStatus(contextStatus);
1187
+ static get zero() {
1188
+ return new MarginsWithUnit(new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel));
1128
1189
  }
1129
- notifyListenersOfDidChangeStatus(contextStatus) {
1130
- this.privateContext.listeners.forEach(listener => {
1131
- if (listener.didChangeStatus) {
1132
- listener.didChangeStatus(this.context, contextStatus);
1133
- }
1134
- });
1190
+ constructor(left, right, top, bottom) {
1191
+ super();
1192
+ this._left = left;
1193
+ this._right = right;
1194
+ this._top = top;
1195
+ this._bottom = bottom;
1135
1196
  }
1136
1197
  }
1198
+ __decorate([
1199
+ nameForSerialization('left')
1200
+ ], MarginsWithUnit.prototype, "_left", void 0);
1201
+ __decorate([
1202
+ nameForSerialization('right')
1203
+ ], MarginsWithUnit.prototype, "_right", void 0);
1204
+ __decorate([
1205
+ nameForSerialization('top')
1206
+ ], MarginsWithUnit.prototype, "_top", void 0);
1207
+ __decorate([
1208
+ nameForSerialization('bottom')
1209
+ ], MarginsWithUnit.prototype, "_bottom", void 0);
1137
1210
 
1138
- class DataCaptureContext extends DefaultSerializeable {
1139
- get framework() {
1140
- return this.controller.framework;
1211
+ class Color {
1212
+ get redComponent() {
1213
+ return this.hexadecimalString.slice(0, 2);
1141
1214
  }
1142
- get frameworkVersion() {
1143
- return this.controller.frameworkVersion;
1215
+ get greenComponent() {
1216
+ return this.hexadecimalString.slice(2, 4);
1144
1217
  }
1145
- static get coreDefaults() {
1146
- return getCoreDefaults();
1218
+ get blueComponent() {
1219
+ return this.hexadecimalString.slice(4, 6);
1147
1220
  }
1148
- get frameSource() {
1149
- return this._frameSource;
1221
+ get alphaComponent() {
1222
+ return this.hexadecimalString.slice(6, 8);
1150
1223
  }
1151
- static get deviceID() {
1152
- return DataCaptureContext.coreDefaults.deviceID;
1224
+ get red() {
1225
+ return Color.hexToNumber(this.redComponent);
1153
1226
  }
1154
- /**
1155
- * @deprecated
1156
- */
1157
- get deviceID() {
1158
- console.log('The instance property "deviceID" on the DataCaptureContext is deprecated, please use the static property DataCaptureContext.deviceID instead.');
1159
- return DataCaptureContext.deviceID;
1227
+ get green() {
1228
+ return Color.hexToNumber(this.greenComponent);
1160
1229
  }
1161
- static forLicenseKey(licenseKey) {
1162
- return DataCaptureContext.create(licenseKey, null, null);
1230
+ get blue() {
1231
+ return Color.hexToNumber(this.blueComponent);
1163
1232
  }
1164
- static forLicenseKeyWithSettings(licenseKey, settings) {
1165
- return DataCaptureContext.create(licenseKey, null, settings);
1233
+ get alpha() {
1234
+ return Color.hexToNumber(this.alphaComponent);
1166
1235
  }
1167
- static forLicenseKeyWithOptions(licenseKey, options) {
1168
- return DataCaptureContext.create(licenseKey, options, null);
1236
+ static fromHex(hex) {
1237
+ return new Color(Color.normalizeHex(hex));
1169
1238
  }
1170
- static create(licenseKey, options, settings) {
1171
- if (options == null) {
1172
- options = { deviceName: null };
1173
- }
1174
- if (!DataCaptureContext.instance) {
1175
- DataCaptureContext.instance = new DataCaptureContext(licenseKey, options.deviceName || '', settings);
1176
- }
1177
- return DataCaptureContext.instance;
1239
+ static fromRGBA(red, green, blue, alpha = 1) {
1240
+ const hexString = [red, green, blue, this.normalizeAlpha(alpha)]
1241
+ .reduce((hex, colorComponent) => hex + this.numberToHex(colorComponent), '');
1242
+ return new Color(hexString);
1178
1243
  }
1179
- constructor(licenseKey, deviceName, settings) {
1180
- super();
1181
- this.licenseKey = licenseKey;
1182
- this.deviceName = deviceName;
1183
- this.settings = new DataCaptureContextSettings();
1184
- this._frameSource = null;
1185
- this.view = null;
1186
- this.modes = [];
1187
- this.listeners = [];
1188
- if (settings) {
1189
- this.settings = settings;
1190
- }
1191
- this.initialize();
1244
+ static hexToNumber(hex) {
1245
+ return parseInt(hex, 16);
1192
1246
  }
1193
- setFrameSource(frameSource) {
1194
- if (this._frameSource) {
1195
- this._frameSource.context = null;
1196
- }
1197
- this._frameSource = frameSource;
1198
- if (frameSource) {
1199
- frameSource.context = this;
1200
- }
1201
- return this.update();
1247
+ static fromJSON(json) {
1248
+ return Color.fromHex(json);
1202
1249
  }
1203
- addListener(listener) {
1204
- if (this.listeners.includes(listener)) {
1205
- return;
1250
+ static numberToHex(x) {
1251
+ x = Math.round(x);
1252
+ let hex = x.toString(16);
1253
+ if (hex.length === 1) {
1254
+ hex = '0' + hex;
1206
1255
  }
1207
- this.listeners.push(listener);
1256
+ return hex.toUpperCase();
1208
1257
  }
1209
- removeListener(listener) {
1210
- if (!this.listeners.includes(listener)) {
1211
- return;
1258
+ static normalizeHex(hex) {
1259
+ // remove leading #
1260
+ if (hex[0] === '#') {
1261
+ hex = hex.slice(1);
1212
1262
  }
1213
- this.listeners.splice(this.listeners.indexOf(listener), 1);
1214
- }
1215
- addMode(mode) {
1216
- if (!this.modes.includes(mode)) {
1217
- this.modes.push(mode);
1218
- mode._context = this;
1219
- this.controller.addModeToContext(mode);
1263
+ // double digits if single digit
1264
+ if (hex.length < 6) {
1265
+ hex = hex.split('').map(s => s + s).join('');
1220
1266
  }
1221
- }
1222
- removeMode(mode) {
1223
- if (this.modes.includes(mode)) {
1224
- this.modes.splice(this.modes.indexOf(mode), 1);
1225
- mode._context = null;
1226
- this.controller.removeModeFromContext(mode);
1267
+ // add alpha if missing
1268
+ if (hex.length === 6) {
1269
+ hex = hex + 'FF';
1227
1270
  }
1271
+ return '#' + hex.toUpperCase();
1228
1272
  }
1229
- removeAllModes() {
1230
- this.modes.forEach(mode => {
1231
- mode._context = null;
1232
- });
1233
- this.modes = [];
1234
- this.controller.removeAllModesFromContext();
1235
- }
1236
- dispose() {
1237
- var _a;
1238
- if (!this.controller) {
1239
- return;
1273
+ static normalizeAlpha(alpha) {
1274
+ if (alpha > 0 && alpha <= 1) {
1275
+ return 255 * alpha;
1240
1276
  }
1241
- DataCaptureContext.instance = null;
1242
- (_a = this.view) === null || _a === void 0 ? void 0 : _a.dispose();
1243
- this.removeAllModes();
1244
- this.controller.dispose();
1245
- }
1246
- applySettings(settings) {
1247
- this.settings = settings;
1248
- return this.update();
1277
+ return alpha;
1249
1278
  }
1250
- static getOpenSourceSoftwareLicenseInfo() {
1251
- return __awaiter(this, void 0, void 0, function* () {
1252
- return DataCaptureContextController.getOpenSourceSoftwareLicenseInfo();
1253
- });
1279
+ constructor(hex) {
1280
+ this.hexadecimalString = hex;
1254
1281
  }
1255
- // Called when the capture view is shown, that is the earliest point that we need the context deserialized.
1256
- initialize() {
1257
- if (this.controller) {
1258
- return;
1259
- }
1260
- this.controller = DataCaptureContextController.forDataCaptureContext(this);
1282
+ withAlpha(alpha) {
1283
+ const newHex = this.hexadecimalString.slice(0, 6) + Color.numberToHex(Color.normalizeAlpha(alpha));
1284
+ return Color.fromHex(newHex);
1261
1285
  }
1262
- update() {
1263
- if (!this.controller) {
1264
- return Promise.resolve();
1265
- }
1266
- return this.controller.updateContextFromJSON();
1286
+ toJSON() {
1287
+ return this.hexadecimalString;
1267
1288
  }
1268
1289
  }
1269
- DataCaptureContext.instance = null;
1270
- __decorate([
1271
- nameForSerialization('frameSource')
1272
- ], DataCaptureContext.prototype, "_frameSource", void 0);
1273
- __decorate([
1274
- ignoreFromSerialization
1275
- ], DataCaptureContext.prototype, "view", void 0);
1276
- __decorate([
1277
- ignoreFromSerialization
1278
- ], DataCaptureContext.prototype, "modes", void 0);
1279
- __decorate([
1280
- ignoreFromSerialization
1281
- ], DataCaptureContext.prototype, "controller", void 0);
1282
- __decorate([
1283
- ignoreFromSerialization
1284
- ], DataCaptureContext.prototype, "listeners", void 0);
1285
- __decorate([
1286
- ignoreFromSerialization
1287
- ], DataCaptureContext, "coreDefaults", null);
1288
1290
 
1289
- class Point extends DefaultSerializeable {
1290
- get x() {
1291
- return this._x;
1291
+ class Brush extends DefaultSerializeable {
1292
+ static get transparent() {
1293
+ const transparentBlack = Color.fromRGBA(255, 255, 255, 0);
1294
+ return new Brush(transparentBlack, transparentBlack, 0);
1292
1295
  }
1293
- get y() {
1294
- return this._y;
1296
+ get fillColor() {
1297
+ return this.fill.color;
1295
1298
  }
1296
- static fromJSON(json) {
1297
- return new Point(json.x, json.y);
1299
+ get strokeColor() {
1300
+ return this.stroke.color;
1298
1301
  }
1299
- constructor(x, y) {
1300
- super();
1301
- this._x = x;
1302
- this._y = y;
1302
+ get strokeWidth() {
1303
+ return this.stroke.width;
1304
+ }
1305
+ get copy() {
1306
+ return new Brush(this.fillColor, this.strokeColor, this.strokeWidth);
1307
+ }
1308
+ constructor(fillColor = Brush.defaults.fillColor, strokeColor = Brush.defaults.strokeColor, strokeWidth = Brush.defaults.strokeWidth) {
1309
+ super();
1310
+ this.fill = { color: fillColor };
1311
+ this.stroke = { color: strokeColor, width: strokeWidth };
1303
1312
  }
1304
1313
  }
1305
- __decorate([
1306
- nameForSerialization('x')
1307
- ], Point.prototype, "_x", void 0);
1308
- __decorate([
1309
- nameForSerialization('y')
1310
- ], Point.prototype, "_y", void 0);
1311
1314
 
1312
- class Quadrilateral extends DefaultSerializeable {
1313
- get topLeft() {
1314
- return this._topLeft;
1315
- }
1316
- get topRight() {
1317
- return this._topRight;
1315
+ var Anchor;
1316
+ (function (Anchor) {
1317
+ Anchor["TopLeft"] = "topLeft";
1318
+ Anchor["TopCenter"] = "topCenter";
1319
+ Anchor["TopRight"] = "topRight";
1320
+ Anchor["CenterLeft"] = "centerLeft";
1321
+ Anchor["Center"] = "center";
1322
+ Anchor["CenterRight"] = "centerRight";
1323
+ Anchor["BottomLeft"] = "bottomLeft";
1324
+ Anchor["BottomCenter"] = "bottomCenter";
1325
+ Anchor["BottomRight"] = "bottomRight";
1326
+ })(Anchor || (Anchor = {}));
1327
+
1328
+ var Orientation;
1329
+ (function (Orientation) {
1330
+ Orientation["Unknown"] = "unknown";
1331
+ Orientation["Portrait"] = "portrait";
1332
+ Orientation["PortraitUpsideDown"] = "portraitUpsideDown";
1333
+ Orientation["LandscapeRight"] = "landscapeRight";
1334
+ Orientation["LandscapeLeft"] = "landscapeLeft";
1335
+ })(Orientation || (Orientation = {}));
1336
+
1337
+ var Direction;
1338
+ (function (Direction) {
1339
+ Direction["None"] = "none";
1340
+ Direction["Horizontal"] = "horizontal";
1341
+ Direction["LeftToRight"] = "leftToRight";
1342
+ Direction["RightToLeft"] = "rightToLeft";
1343
+ Direction["Vertical"] = "vertical";
1344
+ Direction["TopToBottom"] = "topToBottom";
1345
+ Direction["BottomToTop"] = "bottomToTop";
1346
+ })(Direction || (Direction = {}));
1347
+
1348
+ var ScanIntention;
1349
+ (function (ScanIntention) {
1350
+ ScanIntention["Manual"] = "manual";
1351
+ ScanIntention["Smart"] = "smart";
1352
+ })(ScanIntention || (ScanIntention = {}));
1353
+
1354
+ class EventDataParser {
1355
+ static parse(data) {
1356
+ if (data == null) {
1357
+ return null;
1358
+ }
1359
+ return JSON.parse(data);
1318
1360
  }
1319
- get bottomRight() {
1320
- return this._bottomRight;
1361
+ }
1362
+
1363
+ class Observable extends DefaultSerializeable {
1364
+ constructor() {
1365
+ super(...arguments);
1366
+ this.listeners = [];
1321
1367
  }
1322
- get bottomLeft() {
1323
- return this._bottomLeft;
1368
+ addListener(listener) {
1369
+ this.listeners.push(listener);
1324
1370
  }
1325
- static fromJSON(json) {
1326
- return new Quadrilateral(Point.fromJSON(json.topLeft), Point.fromJSON(json.topRight), Point.fromJSON(json.bottomRight), Point.fromJSON(json.bottomLeft));
1371
+ removeListener(listener) {
1372
+ this.listeners = this.listeners.filter(l => l !== listener);
1327
1373
  }
1328
- constructor(topLeft, topRight, bottomRight, bottomLeft) {
1329
- super();
1330
- this._topLeft = topLeft;
1331
- this._topRight = topRight;
1332
- this._bottomRight = bottomRight;
1333
- this._bottomLeft = bottomLeft;
1374
+ notifyListeners(property, value) {
1375
+ this.listeners.forEach(listener => listener(property, value));
1334
1376
  }
1335
1377
  }
1336
1378
  __decorate([
1337
- nameForSerialization('topLeft')
1338
- ], Quadrilateral.prototype, "_topLeft", void 0);
1339
- __decorate([
1340
- nameForSerialization('topRight')
1341
- ], Quadrilateral.prototype, "_topRight", void 0);
1342
- __decorate([
1343
- nameForSerialization('bottomRight')
1344
- ], Quadrilateral.prototype, "_bottomRight", void 0);
1345
- __decorate([
1346
- nameForSerialization('bottomLeft')
1347
- ], Quadrilateral.prototype, "_bottomLeft", void 0);
1379
+ ignoreFromSerialization
1380
+ ], Observable.prototype, "listeners", void 0);
1348
1381
 
1349
- class NumberWithUnit extends DefaultSerializeable {
1350
- get value() {
1351
- return this._value;
1352
- }
1353
- get unit() {
1354
- return this._unit;
1355
- }
1356
- static fromJSON(json) {
1357
- return new NumberWithUnit(json.value, json.unit);
1382
+ class HtmlElementPosition {
1383
+ constructor(top, left) {
1384
+ this.top = 0;
1385
+ this.left = 0;
1386
+ this.top = top;
1387
+ this.left = left;
1358
1388
  }
1359
- constructor(value, unit) {
1360
- super();
1361
- this._value = value;
1362
- this._unit = unit;
1389
+ didChangeComparedTo(other) {
1390
+ if (!other)
1391
+ return true;
1392
+ return this.top !== other.top || this.left !== other.left;
1363
1393
  }
1364
1394
  }
1365
- __decorate([
1366
- nameForSerialization('value')
1367
- ], NumberWithUnit.prototype, "_value", void 0);
1368
- __decorate([
1369
- nameForSerialization('unit')
1370
- ], NumberWithUnit.prototype, "_unit", void 0);
1371
-
1372
- var MeasureUnit;
1373
- (function (MeasureUnit) {
1374
- MeasureUnit["DIP"] = "dip";
1375
- MeasureUnit["Pixel"] = "pixel";
1376
- MeasureUnit["Fraction"] = "fraction";
1377
- })(MeasureUnit || (MeasureUnit = {}));
1378
-
1379
- class PointWithUnit extends DefaultSerializeable {
1380
- get x() {
1381
- return this._x;
1395
+ class HtmlElementSize {
1396
+ constructor(width, height) {
1397
+ this.width = width;
1398
+ this.height = height;
1382
1399
  }
1383
- get y() {
1384
- return this._y;
1400
+ didChangeComparedTo(other) {
1401
+ if (!other)
1402
+ return true;
1403
+ return this.width !== other.width || this.height !== other.height;
1385
1404
  }
1386
- static fromJSON(json) {
1387
- return new PointWithUnit(NumberWithUnit.fromJSON(json.x), NumberWithUnit.fromJSON(json.y));
1405
+ }
1406
+ class HTMLElementState {
1407
+ constructor() {
1408
+ this.isShown = false;
1409
+ this.position = null;
1410
+ this.size = null;
1411
+ this.shouldBeUnderContent = false;
1388
1412
  }
1389
- static get zero() {
1390
- return new PointWithUnit(new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel));
1413
+ get isValid() {
1414
+ return this.isShown !== undefined && this.isShown !== null
1415
+ && this.position !== undefined && this.position !== null
1416
+ && this.size !== undefined && this.size !== null
1417
+ && this.shouldBeUnderContent !== undefined && this.shouldBeUnderContent !== null;
1391
1418
  }
1392
- constructor(x, y) {
1393
- super();
1394
- this._x = x;
1395
- this._y = y;
1419
+ didChangeComparedTo(other) {
1420
+ var _a, _b, _c, _d;
1421
+ if (!other)
1422
+ return true;
1423
+ 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);
1424
+ const sizeChanged = (_d = (_c = this.size) === null || _c === void 0 ? void 0 : _c.didChangeComparedTo(other.size)) !== null && _d !== void 0 ? _d : (this.size !== other.size);
1425
+ return positionChanged || sizeChanged || this.shouldBeUnderContent !== other.shouldBeUnderContent;
1396
1426
  }
1397
1427
  }
1398
- __decorate([
1399
- nameForSerialization('x')
1400
- ], PointWithUnit.prototype, "_x", void 0);
1401
- __decorate([
1402
- nameForSerialization('y')
1403
- ], PointWithUnit.prototype, "_y", void 0);
1404
1428
 
1405
- class Rect extends DefaultSerializeable {
1406
- get origin() {
1407
- return this._origin;
1429
+ class ImageFrameSourceController {
1430
+ static forImage(imageFrameSource) {
1431
+ const controller = new ImageFrameSourceController();
1432
+ controller.imageFrameSource = imageFrameSource;
1433
+ return controller;
1408
1434
  }
1409
- get size() {
1410
- return this._size;
1435
+ constructor() {
1436
+ this.eventEmitter = FactoryMaker.getInstance('EventEmitter');
1437
+ this._proxy = FactoryMaker.getInstance('ImageFrameSourceProxy');
1411
1438
  }
1412
- constructor(origin, size) {
1413
- super();
1414
- this._origin = origin;
1415
- this._size = size;
1439
+ getCurrentState() {
1440
+ return __awaiter(this, void 0, void 0, function* () {
1441
+ const result = yield this._proxy.getCurrentCameraState(this.imageFrameSource.position);
1442
+ if (result == null) {
1443
+ return FrameSourceState.Off;
1444
+ }
1445
+ return result.data;
1446
+ });
1416
1447
  }
1417
- }
1418
- __decorate([
1419
- nameForSerialization('origin')
1420
- ], Rect.prototype, "_origin", void 0);
1421
- __decorate([
1422
- nameForSerialization('size')
1423
- ], Rect.prototype, "_size", void 0);
1424
-
1425
- class RectWithUnit extends DefaultSerializeable {
1426
- get origin() {
1427
- return this._origin;
1448
+ switchCameraToDesiredState(desiredStateJson) {
1449
+ return this._proxy.switchCameraToDesiredState(desiredStateJson);
1428
1450
  }
1429
- get size() {
1430
- return this._size;
1451
+ subscribeListener() {
1452
+ var _a, _b;
1453
+ this._proxy.registerListenerForEvents();
1454
+ (_b = (_a = this._proxy).subscribeDidChangeState) === null || _b === void 0 ? void 0 : _b.call(_a);
1455
+ this.eventEmitter.on(FrameSourceListenerEvents.didChangeState, (data) => {
1456
+ const event = EventDataParser.parse(data);
1457
+ if (event === null) {
1458
+ console.error('ImageFrameSourceController didChangeState payload is null');
1459
+ return;
1460
+ }
1461
+ const newState = event.state;
1462
+ this.imageFrameSource.listeners.forEach(listener => {
1463
+ if (listener.didChangeState) {
1464
+ listener.didChangeState(this.imageFrameSource, newState);
1465
+ }
1466
+ });
1467
+ });
1431
1468
  }
1432
- constructor(origin, size) {
1433
- super();
1434
- this._origin = origin;
1435
- this._size = size;
1469
+ unsubscribeListener() {
1470
+ this._proxy.unregisterListenerForEvents();
1471
+ this.eventEmitter.removeAllListeners(FrameSourceListenerEvents.didChangeState);
1436
1472
  }
1437
1473
  }
1438
- __decorate([
1439
- nameForSerialization('origin')
1440
- ], RectWithUnit.prototype, "_origin", void 0);
1441
- __decorate([
1442
- nameForSerialization('size')
1443
- ], RectWithUnit.prototype, "_size", void 0);
1444
1474
 
1445
- class Size extends DefaultSerializeable {
1446
- get width() {
1447
- return this._width;
1475
+ class ImageFrameSource extends DefaultSerializeable {
1476
+ set context(newContext) {
1477
+ if (newContext == null) {
1478
+ this.controller.unsubscribeListener();
1479
+ }
1480
+ else if (this._context == null) {
1481
+ this.controller.subscribeListener();
1482
+ }
1483
+ this._context = newContext;
1448
1484
  }
1449
- get height() {
1450
- return this._height;
1485
+ get context() {
1486
+ return this._context;
1487
+ }
1488
+ get desiredState() {
1489
+ return this._desiredState;
1490
+ }
1491
+ static create(image) {
1492
+ const imageFrameSource = new ImageFrameSource();
1493
+ imageFrameSource.image = image;
1494
+ return imageFrameSource;
1451
1495
  }
1452
1496
  static fromJSON(json) {
1453
- return new Size(json.width, json.height);
1497
+ return ImageFrameSource.create(json.image);
1454
1498
  }
1455
- constructor(width, height) {
1499
+ constructor() {
1456
1500
  super();
1457
- this._width = width;
1458
- this._height = height;
1501
+ this.type = 'image';
1502
+ this.image = '';
1503
+ this._id = `${Date.now()}`;
1504
+ this._desiredState = FrameSourceState.Off;
1505
+ this.listeners = [];
1506
+ this._context = null;
1507
+ this.controller = ImageFrameSourceController.forImage(this);
1459
1508
  }
1460
- }
1461
- __decorate([
1462
- nameForSerialization('width')
1463
- ], Size.prototype, "_width", void 0);
1464
- __decorate([
1465
- nameForSerialization('height')
1466
- ], Size.prototype, "_height", void 0);
1467
-
1468
- class SizeWithAspect extends DefaultSerializeable {
1469
- get size() {
1470
- return this._size;
1509
+ didChange() {
1510
+ if (this.context) {
1511
+ return this.context.update();
1512
+ }
1513
+ else {
1514
+ return Promise.resolve();
1515
+ }
1471
1516
  }
1472
- get aspect() {
1473
- return this._aspect;
1517
+ switchToDesiredState(state) {
1518
+ this._desiredState = state;
1519
+ return this.controller.switchCameraToDesiredState(state);
1474
1520
  }
1475
- constructor(size, aspect) {
1476
- super();
1477
- this._size = size;
1478
- this._aspect = aspect;
1521
+ addListener(listener) {
1522
+ if (listener == null) {
1523
+ return;
1524
+ }
1525
+ if (this.listeners.includes(listener)) {
1526
+ return;
1527
+ }
1528
+ this.listeners.push(listener);
1529
+ }
1530
+ removeListener(listener) {
1531
+ if (listener == null) {
1532
+ return;
1533
+ }
1534
+ if (!this.listeners.includes(listener)) {
1535
+ return;
1536
+ }
1537
+ this.listeners.splice(this.listeners.indexOf(listener), 1);
1538
+ }
1539
+ getCurrentState() {
1540
+ return this.controller.getCurrentState();
1479
1541
  }
1480
1542
  }
1481
1543
  __decorate([
1482
- nameForSerialization('size')
1483
- ], SizeWithAspect.prototype, "_size", void 0);
1544
+ nameForSerialization('id')
1545
+ ], ImageFrameSource.prototype, "_id", void 0);
1484
1546
  __decorate([
1485
- nameForSerialization('aspect')
1486
- ], SizeWithAspect.prototype, "_aspect", void 0);
1547
+ nameForSerialization('desiredState')
1548
+ ], ImageFrameSource.prototype, "_desiredState", void 0);
1549
+ __decorate([
1550
+ ignoreFromSerialization
1551
+ ], ImageFrameSource.prototype, "listeners", void 0);
1552
+ __decorate([
1553
+ ignoreFromSerialization
1554
+ ], ImageFrameSource.prototype, "_context", void 0);
1555
+ __decorate([
1556
+ ignoreFromSerialization
1557
+ ], ImageFrameSource.prototype, "controller", void 0);
1487
1558
 
1488
- class SizeWithUnit extends DefaultSerializeable {
1489
- get width() {
1490
- return this._width;
1559
+ class PrivateFrameData {
1560
+ get imageBuffers() {
1561
+ return this._imageBuffers;
1491
1562
  }
1492
- get height() {
1493
- return this._height;
1563
+ get orientation() {
1564
+ return this._orientation;
1494
1565
  }
1495
- constructor(width, height) {
1496
- super();
1497
- this._width = width;
1498
- this._height = height;
1566
+ static fromJSON(json) {
1567
+ const frameData = new PrivateFrameData();
1568
+ frameData._imageBuffers = json.imageBuffers.map((imageBufferJSON) => {
1569
+ const imageBuffer = new ImageBuffer();
1570
+ imageBuffer._width = imageBufferJSON.width;
1571
+ imageBuffer._height = imageBufferJSON.height;
1572
+ imageBuffer._data = imageBufferJSON.data;
1573
+ return imageBuffer;
1574
+ });
1575
+ frameData._orientation = json.orientation;
1576
+ return frameData;
1577
+ }
1578
+ static empty() {
1579
+ const frameData = new PrivateFrameData();
1580
+ frameData._imageBuffers = [];
1581
+ frameData._orientation = 90;
1582
+ return frameData;
1499
1583
  }
1500
1584
  }
1501
- __decorate([
1502
- nameForSerialization('width')
1503
- ], SizeWithUnit.prototype, "_width", void 0);
1504
- __decorate([
1505
- nameForSerialization('height')
1506
- ], SizeWithUnit.prototype, "_height", void 0);
1507
-
1508
- var SizingMode;
1509
- (function (SizingMode) {
1510
- SizingMode["WidthAndHeight"] = "widthAndHeight";
1511
- SizingMode["WidthAndAspectRatio"] = "widthAndAspectRatio";
1512
- SizingMode["HeightAndAspectRatio"] = "heightAndAspectRatio";
1513
- SizingMode["ShorterDimensionAndAspectRatio"] = "shorterDimensionAndAspectRatio";
1514
- })(SizingMode || (SizingMode = {}));
1515
1585
 
1516
- class SizeWithUnitAndAspect {
1586
+ class CameraController {
1587
+ static get _proxy() {
1588
+ return FactoryMaker.getInstance('CameraProxy');
1589
+ }
1590
+ static forCamera(camera) {
1591
+ const controller = new CameraController();
1592
+ controller.camera = camera;
1593
+ return controller;
1594
+ }
1517
1595
  constructor() {
1518
- this._widthAndHeight = null;
1519
- this._widthAndAspectRatio = null;
1520
- this._heightAndAspectRatio = null;
1521
- this._shorterDimensionAndAspectRatio = null;
1596
+ this.eventEmitter = FactoryMaker.getInstance('EventEmitter');
1522
1597
  }
1523
- get widthAndHeight() {
1524
- return this._widthAndHeight;
1598
+ get privateCamera() {
1599
+ return this.camera;
1525
1600
  }
1526
- get widthAndAspectRatio() {
1527
- return this._widthAndAspectRatio;
1601
+ static getFrame(frameId) {
1602
+ return __awaiter(this, void 0, void 0, function* () {
1603
+ const result = yield CameraController._proxy.getFrame(frameId);
1604
+ if (result == null) {
1605
+ return PrivateFrameData.empty();
1606
+ }
1607
+ const frameDataJSON = JSON.parse(result.data);
1608
+ return PrivateFrameData.fromJSON(frameDataJSON);
1609
+ });
1528
1610
  }
1529
- get heightAndAspectRatio() {
1530
- return this._heightAndAspectRatio;
1611
+ static getFrameOrNull(frameId) {
1612
+ return __awaiter(this, void 0, void 0, function* () {
1613
+ const result = yield CameraController._proxy.getFrame(frameId);
1614
+ if (result == null) {
1615
+ return null;
1616
+ }
1617
+ const frameDataJSON = JSON.parse(result.data);
1618
+ return PrivateFrameData.fromJSON(frameDataJSON);
1619
+ });
1531
1620
  }
1532
- get shorterDimensionAndAspectRatio() {
1533
- return this._shorterDimensionAndAspectRatio;
1621
+ getCurrentState() {
1622
+ return __awaiter(this, void 0, void 0, function* () {
1623
+ const result = yield CameraController._proxy.getCurrentCameraState(this.privateCamera.position);
1624
+ if (result == null) {
1625
+ return FrameSourceState.Off;
1626
+ }
1627
+ return result.data;
1628
+ });
1534
1629
  }
1535
- get sizingMode() {
1536
- if (this.widthAndAspectRatio) {
1537
- return SizingMode.WidthAndAspectRatio;
1538
- }
1539
- if (this.heightAndAspectRatio) {
1540
- return SizingMode.HeightAndAspectRatio;
1541
- }
1542
- if (this.shorterDimensionAndAspectRatio) {
1543
- return SizingMode.ShorterDimensionAndAspectRatio;
1544
- }
1545
- return SizingMode.WidthAndHeight;
1630
+ getIsTorchAvailable() {
1631
+ return __awaiter(this, void 0, void 0, function* () {
1632
+ const result = yield CameraController._proxy.isTorchAvailable(this.privateCamera.position);
1633
+ if (result == null) {
1634
+ return false;
1635
+ }
1636
+ return result.data === 'true';
1637
+ });
1546
1638
  }
1547
- static sizeWithWidthAndHeight(widthAndHeight) {
1548
- const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1549
- sizeWithUnitAndAspect._widthAndHeight = widthAndHeight;
1550
- return sizeWithUnitAndAspect;
1639
+ switchCameraToDesiredState(desiredState) {
1640
+ return CameraController._proxy.switchCameraToDesiredState(desiredState);
1551
1641
  }
1552
- static sizeWithWidthAndAspectRatio(width, aspectRatio) {
1553
- const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1554
- sizeWithUnitAndAspect._widthAndAspectRatio = new SizeWithAspect(width, aspectRatio);
1555
- return sizeWithUnitAndAspect;
1642
+ subscribeListener() {
1643
+ var _a, _b;
1644
+ CameraController._proxy.registerListenerForCameraEvents();
1645
+ (_b = (_a = CameraController._proxy).subscribeDidChangeState) === null || _b === void 0 ? void 0 : _b.call(_a);
1646
+ this.eventEmitter.on(FrameSourceListenerEvents.didChangeState, (data) => {
1647
+ const event = EventDataParser.parse(data);
1648
+ if (event) {
1649
+ this.privateCamera.listeners.forEach(listener => {
1650
+ var _a;
1651
+ (_a = listener === null || listener === void 0 ? void 0 : listener.didChangeState) === null || _a === void 0 ? void 0 : _a.call(listener, this.camera, event.state);
1652
+ });
1653
+ }
1654
+ });
1556
1655
  }
1557
- static sizeWithHeightAndAspectRatio(height, aspectRatio) {
1558
- const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1559
- sizeWithUnitAndAspect._heightAndAspectRatio = new SizeWithAspect(height, aspectRatio);
1560
- return sizeWithUnitAndAspect;
1656
+ unsubscribeListener() {
1657
+ CameraController._proxy.unregisterListenerForCameraEvents();
1658
+ this.eventEmitter.off(FrameSourceListenerEvents.didChangeState);
1561
1659
  }
1562
- static sizeWithShorterDimensionAndAspectRatio(shorterDimension, aspectRatio) {
1563
- const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1564
- sizeWithUnitAndAspect._shorterDimensionAndAspectRatio = new SizeWithAspect(shorterDimension, aspectRatio);
1565
- return sizeWithUnitAndAspect;
1660
+ }
1661
+
1662
+ var TorchState;
1663
+ (function (TorchState) {
1664
+ TorchState["On"] = "on";
1665
+ TorchState["Off"] = "off";
1666
+ TorchState["Auto"] = "auto";
1667
+ })(TorchState || (TorchState = {}));
1668
+
1669
+ class Camera extends DefaultSerializeable {
1670
+ static get coreDefaults() {
1671
+ return getCoreDefaults();
1566
1672
  }
1567
- static fromJSON(json) {
1568
- if (json.width && json.height) {
1569
- return this.sizeWithWidthAndHeight(new SizeWithUnit(NumberWithUnit.fromJSON(json.width), NumberWithUnit.fromJSON(json.height)));
1570
- }
1571
- else if (json.width && json.aspect) {
1572
- return this.sizeWithWidthAndAspectRatio(NumberWithUnit.fromJSON(json.width), json.aspect);
1573
- }
1574
- else if (json.height && json.aspect) {
1575
- return this.sizeWithHeightAndAspectRatio(NumberWithUnit.fromJSON(json.height), json.aspect);
1576
- }
1577
- else if (json.shorterDimension && json.aspect) {
1578
- return this.sizeWithShorterDimensionAndAspectRatio(NumberWithUnit.fromJSON(json.shorterDimension), json.aspect);
1673
+ set context(newContext) {
1674
+ this._context = newContext;
1675
+ }
1676
+ get context() {
1677
+ return this._context;
1678
+ }
1679
+ static get default() {
1680
+ if (Camera.coreDefaults.Camera.defaultPosition) {
1681
+ const camera = new Camera();
1682
+ camera.position = Camera.coreDefaults.Camera.defaultPosition;
1683
+ return camera;
1579
1684
  }
1580
1685
  else {
1581
- throw new Error(`SizeWithUnitAndAspectJSON is malformed: ${JSON.stringify(json)}`);
1686
+ return null;
1582
1687
  }
1583
1688
  }
1584
- toJSON() {
1585
- switch (this.sizingMode) {
1586
- case SizingMode.WidthAndAspectRatio:
1587
- return {
1588
- width: this.widthAndAspectRatio.size.toJSON(),
1589
- aspect: this.widthAndAspectRatio.aspect,
1590
- };
1591
- case SizingMode.HeightAndAspectRatio:
1592
- return {
1593
- height: this.heightAndAspectRatio.size.toJSON(),
1594
- aspect: this.heightAndAspectRatio.aspect,
1595
- };
1596
- case SizingMode.ShorterDimensionAndAspectRatio:
1597
- return {
1598
- shorterDimension: this.shorterDimensionAndAspectRatio.size.toJSON(),
1599
- aspect: this.shorterDimensionAndAspectRatio.aspect,
1600
- };
1601
- default:
1602
- return {
1603
- width: this.widthAndHeight.width.toJSON(),
1604
- height: this.widthAndHeight.height.toJSON(),
1605
- };
1689
+ static withSettings(settings) {
1690
+ const camera = Camera.default;
1691
+ if (camera) {
1692
+ camera.settings = settings;
1606
1693
  }
1694
+ return camera;
1695
+ }
1696
+ static asPositionWithSettings(cameraPosition, settings) {
1697
+ if (Camera.coreDefaults.Camera.availablePositions.includes(cameraPosition)) {
1698
+ const camera = new Camera();
1699
+ camera.settings = settings;
1700
+ camera.position = cameraPosition;
1701
+ return camera;
1702
+ }
1703
+ else {
1704
+ return null;
1705
+ }
1706
+ }
1707
+ static atPosition(cameraPosition) {
1708
+ if (Camera.coreDefaults.Camera.availablePositions.includes(cameraPosition)) {
1709
+ const camera = new Camera();
1710
+ camera.position = cameraPosition;
1711
+ return camera;
1712
+ }
1713
+ else {
1714
+ return null;
1715
+ }
1716
+ }
1717
+ get desiredState() {
1718
+ return this._desiredState;
1719
+ }
1720
+ set desiredTorchState(desiredTorchState) {
1721
+ this._desiredTorchState = desiredTorchState;
1722
+ this.didChange();
1723
+ }
1724
+ get desiredTorchState() {
1725
+ return this._desiredTorchState;
1726
+ }
1727
+ constructor() {
1728
+ super();
1729
+ this.type = 'camera';
1730
+ this.settings = null;
1731
+ this._desiredTorchState = TorchState.Off;
1732
+ this._desiredState = FrameSourceState.Off;
1733
+ this.listeners = [];
1734
+ this._context = null;
1735
+ this.controller = CameraController.forCamera(this);
1736
+ }
1737
+ switchToDesiredState(state) {
1738
+ this._desiredState = state;
1739
+ return this.controller.switchCameraToDesiredState(state);
1740
+ }
1741
+ getCurrentState() {
1742
+ return this.controller.getCurrentState();
1743
+ }
1744
+ getIsTorchAvailable() {
1745
+ return this.controller.getIsTorchAvailable();
1746
+ }
1747
+ /**
1748
+ * @deprecated
1749
+ */
1750
+ get isTorchAvailable() {
1751
+ console.warn('isTorchAvailable is deprecated. Use getIsTorchAvailable instead.');
1752
+ return false;
1753
+ }
1754
+ addListener(listener) {
1755
+ if (listener == null) {
1756
+ return;
1757
+ }
1758
+ if (this.listeners.length === 0) {
1759
+ this.controller.subscribeListener();
1760
+ }
1761
+ if (this.listeners.includes(listener)) {
1762
+ return;
1763
+ }
1764
+ this.listeners.push(listener);
1765
+ }
1766
+ removeListener(listener) {
1767
+ if (listener == null) {
1768
+ return;
1769
+ }
1770
+ if (!this.listeners.includes(listener)) {
1771
+ return;
1772
+ }
1773
+ this.listeners.splice(this.listeners.indexOf(listener), 1);
1774
+ if (this.listeners.length === 0) {
1775
+ this.controller.unsubscribeListener();
1776
+ }
1777
+ }
1778
+ applySettings(settings) {
1779
+ this.settings = settings;
1780
+ return this.didChange();
1781
+ }
1782
+ didChange() {
1783
+ return __awaiter(this, void 0, void 0, function* () {
1784
+ if (this.context) {
1785
+ yield this.context.update();
1786
+ }
1787
+ });
1607
1788
  }
1608
1789
  }
1609
1790
  __decorate([
1610
- nameForSerialization('widthAndHeight')
1611
- ], SizeWithUnitAndAspect.prototype, "_widthAndHeight", void 0);
1791
+ serializationDefault({})
1792
+ ], Camera.prototype, "settings", void 0);
1612
1793
  __decorate([
1613
- nameForSerialization('widthAndAspectRatio')
1614
- ], SizeWithUnitAndAspect.prototype, "_widthAndAspectRatio", void 0);
1794
+ nameForSerialization('desiredTorchState')
1795
+ ], Camera.prototype, "_desiredTorchState", void 0);
1615
1796
  __decorate([
1616
- nameForSerialization('heightAndAspectRatio')
1617
- ], SizeWithUnitAndAspect.prototype, "_heightAndAspectRatio", void 0);
1797
+ ignoreFromSerialization
1798
+ ], Camera.prototype, "_desiredState", void 0);
1618
1799
  __decorate([
1619
- nameForSerialization('shorterDimensionAndAspectRatio')
1620
- ], SizeWithUnitAndAspect.prototype, "_shorterDimensionAndAspectRatio", void 0);
1800
+ ignoreFromSerialization
1801
+ ], Camera.prototype, "listeners", void 0);
1802
+ __decorate([
1803
+ ignoreFromSerialization
1804
+ ], Camera.prototype, "_context", void 0);
1805
+ __decorate([
1806
+ ignoreFromSerialization
1807
+ ], Camera.prototype, "controller", void 0);
1808
+ __decorate([
1809
+ ignoreFromSerialization
1810
+ ], Camera, "coreDefaults", null);
1621
1811
 
1622
- class MarginsWithUnit extends DefaultSerializeable {
1623
- get left() {
1624
- return this._left;
1812
+ class ControlImage extends DefaultSerializeable {
1813
+ constructor(type, data, name) {
1814
+ super();
1815
+ this.type = type;
1816
+ this._data = data;
1817
+ this._name = name;
1625
1818
  }
1626
- get right() {
1627
- return this._right;
1819
+ static fromBase64EncodedImage(data) {
1820
+ if (data === null)
1821
+ return null;
1822
+ return new ControlImage("base64", data, null);
1628
1823
  }
1629
- get top() {
1630
- return this._top;
1824
+ static fromResourceName(resource) {
1825
+ return new ControlImage("resource", null, resource);
1631
1826
  }
1632
- get bottom() {
1633
- return this._bottom;
1827
+ isBase64EncodedImage() {
1828
+ return this.type === "base64";
1634
1829
  }
1830
+ get data() {
1831
+ return this._data;
1832
+ }
1833
+ }
1834
+ __decorate([
1835
+ ignoreFromSerializationIfNull,
1836
+ nameForSerialization('data')
1837
+ ], ControlImage.prototype, "_data", void 0);
1838
+ __decorate([
1839
+ ignoreFromSerializationIfNull,
1840
+ nameForSerialization('name')
1841
+ ], ControlImage.prototype, "_name", void 0);
1842
+
1843
+ class ContextStatus {
1635
1844
  static fromJSON(json) {
1636
- return new MarginsWithUnit(NumberWithUnit.fromJSON(json.left), NumberWithUnit.fromJSON(json.right), NumberWithUnit.fromJSON(json.top), NumberWithUnit.fromJSON(json.bottom));
1845
+ const status = new ContextStatus();
1846
+ status._code = json.code;
1847
+ status._message = json.message;
1848
+ status._isValid = json.isValid;
1849
+ return status;
1637
1850
  }
1638
- static get zero() {
1639
- return new MarginsWithUnit(new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel), new NumberWithUnit(0, MeasureUnit.Pixel));
1851
+ get message() {
1852
+ return this._message;
1640
1853
  }
1641
- constructor(left, right, top, bottom) {
1854
+ get code() {
1855
+ return this._code;
1856
+ }
1857
+ get isValid() {
1858
+ return this._isValid;
1859
+ }
1860
+ }
1861
+
1862
+ class DataCaptureContextSettings extends DefaultSerializeable {
1863
+ constructor() {
1642
1864
  super();
1643
- this._left = left;
1644
- this._right = right;
1645
- this._top = top;
1646
- this._bottom = bottom;
1865
+ }
1866
+ setProperty(name, value) {
1867
+ this[name] = value;
1868
+ }
1869
+ getProperty(name) {
1870
+ return this[name];
1647
1871
  }
1648
1872
  }
1649
- __decorate([
1650
- nameForSerialization('left')
1651
- ], MarginsWithUnit.prototype, "_left", void 0);
1652
- __decorate([
1653
- nameForSerialization('right')
1654
- ], MarginsWithUnit.prototype, "_right", void 0);
1655
- __decorate([
1656
- nameForSerialization('top')
1657
- ], MarginsWithUnit.prototype, "_top", void 0);
1658
- __decorate([
1659
- nameForSerialization('bottom')
1660
- ], MarginsWithUnit.prototype, "_bottom", void 0);
1661
1873
 
1662
- class Color {
1663
- get redComponent() {
1664
- return this.hexadecimalString.slice(0, 2);
1874
+ class OpenSourceSoftwareLicenseInfo {
1875
+ constructor(licenseText) {
1876
+ this._licenseText = licenseText;
1665
1877
  }
1666
- get greenComponent() {
1667
- return this.hexadecimalString.slice(2, 4);
1878
+ get licenseText() {
1879
+ return this._licenseText;
1668
1880
  }
1669
- get blueComponent() {
1670
- return this.hexadecimalString.slice(4, 6);
1881
+ }
1882
+
1883
+ var DataCaptureContextEvents;
1884
+ (function (DataCaptureContextEvents) {
1885
+ DataCaptureContextEvents["didChangeStatus"] = "DataCaptureContextListener.onStatusChanged";
1886
+ DataCaptureContextEvents["didStartObservingContext"] = "DataCaptureContextListener.onObservationStarted";
1887
+ })(DataCaptureContextEvents || (DataCaptureContextEvents = {}));
1888
+ class DataCaptureContextController {
1889
+ static get framework() {
1890
+ return FactoryMaker.getInstance('DataCaptureContextProxy').framework;
1671
1891
  }
1672
- get alphaComponent() {
1673
- return this.hexadecimalString.slice(6, 8);
1892
+ static get frameworkVersion() {
1893
+ return FactoryMaker.getInstance('DataCaptureContextProxy').frameworkVersion;
1674
1894
  }
1675
- get red() {
1676
- return Color.hexToNumber(this.redComponent);
1895
+ get privateContext() {
1896
+ return this.context;
1677
1897
  }
1678
- get green() {
1679
- return Color.hexToNumber(this.greenComponent);
1898
+ static forDataCaptureContext(context) {
1899
+ const controller = new DataCaptureContextController();
1900
+ controller.context = context;
1901
+ controller.initialize();
1902
+ return controller;
1680
1903
  }
1681
- get blue() {
1682
- return Color.hexToNumber(this.blueComponent);
1904
+ static forDataCaptureContextAsync(context) {
1905
+ return __awaiter(this, void 0, void 0, function* () {
1906
+ const controller = new DataCaptureContextController();
1907
+ controller.context = context;
1908
+ yield controller.initialize();
1909
+ return controller;
1910
+ });
1683
1911
  }
1684
- get alpha() {
1685
- return Color.hexToNumber(this.alphaComponent);
1912
+ constructor() {
1913
+ this._proxy = FactoryMaker.getInstance('DataCaptureContextProxy');
1914
+ this.eventEmitter = FactoryMaker.getInstance('EventEmitter');
1915
+ }
1916
+ updateContextFromJSON() {
1917
+ return __awaiter(this, void 0, void 0, function* () {
1918
+ try {
1919
+ yield this._proxy.updateContextFromJSON(JSON.stringify(this.context.toJSON()));
1920
+ }
1921
+ catch (error) {
1922
+ this.notifyListenersOfDeserializationError(error);
1923
+ throw error;
1924
+ }
1925
+ });
1926
+ }
1927
+ addModeToContext(mode) {
1928
+ return this._proxy.addModeToContext(JSON.stringify(mode.toJSON()));
1929
+ }
1930
+ removeModeFromContext(mode) {
1931
+ return this._proxy.removeModeFromContext(JSON.stringify(mode.toJSON()));
1932
+ }
1933
+ removeAllModesFromContext() {
1934
+ return this._proxy.removeAllModesFromContext();
1935
+ }
1936
+ dispose() {
1937
+ this.unsubscribeListener();
1938
+ this._proxy.dispose();
1939
+ }
1940
+ unsubscribeListener() {
1941
+ this._proxy.unregisterListenerForDataCaptureContext();
1942
+ this.eventEmitter.removeAllListeners(DataCaptureContextEvents.didChangeStatus);
1943
+ this.eventEmitter.removeAllListeners(DataCaptureContextEvents.didStartObservingContext);
1944
+ }
1945
+ initialize() {
1946
+ this.subscribeListener();
1947
+ return this.initializeContextFromJSON();
1948
+ }
1949
+ initializeContextFromJSON() {
1950
+ return __awaiter(this, void 0, void 0, function* () {
1951
+ try {
1952
+ yield this._proxy.contextFromJSON(JSON.stringify(this.context.toJSON()));
1953
+ }
1954
+ catch (error) {
1955
+ this.notifyListenersOfDeserializationError(error);
1956
+ throw error;
1957
+ }
1958
+ });
1959
+ }
1960
+ static getOpenSourceSoftwareLicenseInfo() {
1961
+ return __awaiter(this, void 0, void 0, function* () {
1962
+ const proxy = FactoryMaker.getInstance('DataCaptureContextProxy');
1963
+ const result = yield proxy.getOpenSourceSoftwareLicenseInfo();
1964
+ return new OpenSourceSoftwareLicenseInfo(result.data);
1965
+ });
1966
+ }
1967
+ subscribeListener() {
1968
+ var _a, _b, _c, _d;
1969
+ this._proxy.registerListenerForDataCaptureContext();
1970
+ (_b = (_a = this._proxy).subscribeDidChangeStatus) === null || _b === void 0 ? void 0 : _b.call(_a);
1971
+ (_d = (_c = this._proxy).subscribeDidStartObservingContext) === null || _d === void 0 ? void 0 : _d.call(_c);
1972
+ this.eventEmitter.on(DataCaptureContextEvents.didChangeStatus, (data) => {
1973
+ const event = EventDataParser.parse(data);
1974
+ if (event === null) {
1975
+ console.error('DataCaptureContextController didChangeStatus payload is null');
1976
+ return;
1977
+ }
1978
+ const contextStatus = ContextStatus.fromJSON(JSON.parse(event.status));
1979
+ this.notifyListenersOfDidChangeStatus(contextStatus);
1980
+ });
1981
+ this.eventEmitter.on(DataCaptureContextEvents.didStartObservingContext, () => {
1982
+ this.privateContext.listeners.forEach(listener => {
1983
+ var _a;
1984
+ (_a = listener.didStartObservingContext) === null || _a === void 0 ? void 0 : _a.call(listener, this.context);
1985
+ });
1986
+ });
1987
+ }
1988
+ notifyListenersOfDeserializationError(error) {
1989
+ const contextStatus = ContextStatus
1990
+ .fromJSON({
1991
+ message: error,
1992
+ code: -1,
1993
+ isValid: true,
1994
+ });
1995
+ this.notifyListenersOfDidChangeStatus(contextStatus);
1996
+ }
1997
+ notifyListenersOfDidChangeStatus(contextStatus) {
1998
+ this.privateContext.listeners.forEach(listener => {
1999
+ if (listener.didChangeStatus) {
2000
+ listener.didChangeStatus(this.context, contextStatus);
2001
+ }
2002
+ });
2003
+ }
2004
+ }
2005
+
2006
+ class DataCaptureContext extends DefaultSerializeable {
2007
+ static get coreDefaults() {
2008
+ return getCoreDefaults();
2009
+ }
2010
+ get frameSource() {
2011
+ return this._frameSource;
2012
+ }
2013
+ static get deviceID() {
2014
+ return DataCaptureContext.coreDefaults.deviceID;
2015
+ }
2016
+ /**
2017
+ * @deprecated
2018
+ */
2019
+ get deviceID() {
2020
+ console.log('The instance property "deviceID" on the DataCaptureContext is deprecated, please use the static property DataCaptureContext.deviceID instead.');
2021
+ return DataCaptureContext.deviceID;
1686
2022
  }
1687
- static fromHex(hex) {
1688
- return new Color(Color.normalizeHex(hex));
2023
+ static forLicenseKey(licenseKey) {
2024
+ return DataCaptureContext.create(licenseKey, null, null);
1689
2025
  }
1690
- static fromRGBA(red, green, blue, alpha = 1) {
1691
- const hexString = [red, green, blue, this.normalizeAlpha(alpha)]
1692
- .reduce((hex, colorComponent) => hex + this.numberToHex(colorComponent), '');
1693
- return new Color(hexString);
2026
+ static forLicenseKeyWithSettings(licenseKey, settings) {
2027
+ return DataCaptureContext.create(licenseKey, null, settings);
1694
2028
  }
1695
- static hexToNumber(hex) {
1696
- return parseInt(hex, 16);
2029
+ static forLicenseKeyWithOptions(licenseKey, options) {
2030
+ return DataCaptureContext.create(licenseKey, options, null);
1697
2031
  }
1698
- static fromJSON(json) {
1699
- return Color.fromHex(json);
2032
+ static create(licenseKey, options, settings) {
2033
+ if (options == null) {
2034
+ options = { deviceName: null };
2035
+ }
2036
+ if (!DataCaptureContext.instance) {
2037
+ DataCaptureContext.instance = new DataCaptureContext(licenseKey, options.deviceName || '', settings);
2038
+ }
2039
+ return DataCaptureContext.instance;
1700
2040
  }
1701
- static numberToHex(x) {
1702
- x = Math.round(x);
1703
- let hex = x.toString(16);
1704
- if (hex.length === 1) {
1705
- hex = '0' + hex;
2041
+ constructor(licenseKey, deviceName, settings) {
2042
+ super();
2043
+ this.licenseKey = licenseKey;
2044
+ this.deviceName = deviceName;
2045
+ this._framework = DataCaptureContextController.framework;
2046
+ this._frameworkVersion = DataCaptureContextController.frameworkVersion;
2047
+ this.settings = new DataCaptureContextSettings();
2048
+ this._frameSource = null;
2049
+ this.view = null;
2050
+ this.modes = [];
2051
+ this.listeners = [];
2052
+ if (settings) {
2053
+ this.settings = settings;
1706
2054
  }
1707
- return hex.toUpperCase();
2055
+ this.initialize();
1708
2056
  }
1709
- static normalizeHex(hex) {
1710
- // remove leading #
1711
- if (hex[0] === '#') {
1712
- hex = hex.slice(1);
2057
+ setFrameSource(frameSource) {
2058
+ if (this._frameSource) {
2059
+ this._frameSource.context = null;
1713
2060
  }
1714
- // double digits if single digit
1715
- if (hex.length < 6) {
1716
- hex = hex.split('').map(s => s + s).join('');
2061
+ this._frameSource = frameSource;
2062
+ if (frameSource) {
2063
+ frameSource.context = this;
1717
2064
  }
1718
- // add alpha if missing
1719
- if (hex.length === 6) {
1720
- hex = hex + 'FF';
2065
+ return this.update();
2066
+ }
2067
+ addListener(listener) {
2068
+ if (this.listeners.includes(listener)) {
2069
+ return;
1721
2070
  }
1722
- return hex.toUpperCase();
2071
+ this.listeners.push(listener);
1723
2072
  }
1724
- static normalizeAlpha(alpha) {
1725
- if (alpha > 0 && alpha <= 1) {
1726
- return 255 * alpha;
2073
+ removeListener(listener) {
2074
+ if (!this.listeners.includes(listener)) {
2075
+ return;
1727
2076
  }
1728
- return alpha;
2077
+ this.listeners.splice(this.listeners.indexOf(listener), 1);
1729
2078
  }
1730
- constructor(hex) {
1731
- this.hexadecimalString = hex;
2079
+ addMode(mode) {
2080
+ if (!this.modes.includes(mode)) {
2081
+ this.modes.push(mode);
2082
+ mode._context = this;
2083
+ this.controller.addModeToContext(mode);
2084
+ }
1732
2085
  }
1733
- withAlpha(alpha) {
1734
- const newHex = this.hexadecimalString.slice(0, 6) + Color.numberToHex(Color.normalizeAlpha(alpha));
1735
- return Color.fromHex(newHex);
2086
+ removeMode(mode) {
2087
+ if (this.modes.includes(mode)) {
2088
+ this.modes.splice(this.modes.indexOf(mode), 1);
2089
+ mode._context = null;
2090
+ this.controller.removeModeFromContext(mode);
2091
+ }
1736
2092
  }
1737
- toJSON() {
1738
- return this.hexadecimalString;
2093
+ removeAllModes() {
2094
+ this.modes.forEach(mode => {
2095
+ mode._context = null;
2096
+ });
2097
+ this.modes = [];
2098
+ this.controller.removeAllModesFromContext();
1739
2099
  }
1740
- }
1741
-
1742
- class Brush extends DefaultSerializeable {
1743
- static get transparent() {
1744
- const transparentBlack = Color.fromRGBA(255, 255, 255, 0);
1745
- return new Brush(transparentBlack, transparentBlack, 0);
2100
+ dispose() {
2101
+ var _a;
2102
+ if (!this.controller) {
2103
+ return;
2104
+ }
2105
+ DataCaptureContext.instance = null;
2106
+ (_a = this.view) === null || _a === void 0 ? void 0 : _a.dispose();
2107
+ this.removeAllModes();
2108
+ this.controller.dispose();
1746
2109
  }
1747
- get fillColor() {
1748
- return this.fill.color;
2110
+ applySettings(settings) {
2111
+ this.settings = settings;
2112
+ return this.update();
1749
2113
  }
1750
- get strokeColor() {
1751
- return this.stroke.color;
2114
+ static getOpenSourceSoftwareLicenseInfo() {
2115
+ return __awaiter(this, void 0, void 0, function* () {
2116
+ return DataCaptureContextController.getOpenSourceSoftwareLicenseInfo();
2117
+ });
1752
2118
  }
1753
- get strokeWidth() {
1754
- return this.stroke.width;
2119
+ // Called when the capture view is shown, that is the earliest point that we need the context deserialized.
2120
+ initialize() {
2121
+ if (this.controller) {
2122
+ return;
2123
+ }
2124
+ this.controller = DataCaptureContextController.forDataCaptureContext(this);
1755
2125
  }
1756
- get copy() {
1757
- return new Brush(this.fillColor, this.strokeColor, this.strokeWidth);
2126
+ initializeAsync() {
2127
+ return __awaiter(this, void 0, void 0, function* () {
2128
+ if (this.controller) {
2129
+ return;
2130
+ }
2131
+ this.controller = yield DataCaptureContextController.forDataCaptureContextAsync(this);
2132
+ });
1758
2133
  }
1759
- constructor(fillColor = Brush.defaults.fillColor, strokeColor = Brush.defaults.strokeColor, strokeWidth = Brush.defaults.strokeWidth) {
1760
- super();
1761
- this.fill = { color: fillColor };
1762
- this.stroke = { color: strokeColor, width: strokeWidth };
2134
+ update() {
2135
+ if (!this.controller) {
2136
+ return Promise.resolve();
2137
+ }
2138
+ return this.controller.updateContextFromJSON();
1763
2139
  }
1764
2140
  }
2141
+ DataCaptureContext.instance = null;
2142
+ __decorate([
2143
+ ignoreFromSerialization
2144
+ ], DataCaptureContext.prototype, "controller", void 0);
2145
+ __decorate([
2146
+ nameForSerialization('framework')
2147
+ ], DataCaptureContext.prototype, "_framework", void 0);
2148
+ __decorate([
2149
+ nameForSerialization('frameworkVersion')
2150
+ ], DataCaptureContext.prototype, "_frameworkVersion", void 0);
2151
+ __decorate([
2152
+ nameForSerialization('frameSource')
2153
+ ], DataCaptureContext.prototype, "_frameSource", void 0);
2154
+ __decorate([
2155
+ ignoreFromSerialization
2156
+ ], DataCaptureContext.prototype, "view", void 0);
2157
+ __decorate([
2158
+ ignoreFromSerialization
2159
+ ], DataCaptureContext.prototype, "modes", void 0);
2160
+ __decorate([
2161
+ ignoreFromSerialization
2162
+ ], DataCaptureContext.prototype, "listeners", void 0);
2163
+ __decorate([
2164
+ ignoreFromSerialization
2165
+ ], DataCaptureContext, "coreDefaults", null);
1765
2166
 
1766
- var Anchor;
1767
- (function (Anchor) {
1768
- Anchor["TopLeft"] = "topLeft";
1769
- Anchor["TopCenter"] = "topCenter";
1770
- Anchor["TopRight"] = "topRight";
1771
- Anchor["CenterLeft"] = "centerLeft";
1772
- Anchor["Center"] = "center";
1773
- Anchor["CenterRight"] = "centerRight";
1774
- Anchor["BottomLeft"] = "bottomLeft";
1775
- Anchor["BottomCenter"] = "bottomCenter";
1776
- Anchor["BottomRight"] = "bottomRight";
1777
- })(Anchor || (Anchor = {}));
1778
-
1779
- var Orientation;
1780
- (function (Orientation) {
1781
- Orientation["Unknown"] = "unknown";
1782
- Orientation["Portrait"] = "portrait";
1783
- Orientation["PortraitUpsideDown"] = "portraitUpsideDown";
1784
- Orientation["LandscapeRight"] = "landscapeRight";
1785
- Orientation["LandscapeLeft"] = "landscapeLeft";
1786
- })(Orientation || (Orientation = {}));
1787
-
1788
- var Direction;
1789
- (function (Direction) {
1790
- Direction["None"] = "none";
1791
- Direction["Horizontal"] = "horizontal";
1792
- Direction["LeftToRight"] = "leftToRight";
1793
- Direction["RightToLeft"] = "rightToLeft";
1794
- Direction["Vertical"] = "vertical";
1795
- Direction["TopToBottom"] = "topToBottom";
1796
- Direction["BottomToTop"] = "bottomToTop";
1797
- })(Direction || (Direction = {}));
1798
-
1799
- var ScanIntention;
1800
- (function (ScanIntention) {
1801
- ScanIntention["Manual"] = "manual";
1802
- ScanIntention["Smart"] = "smart";
1803
- })(ScanIntention || (ScanIntention = {}));
1804
-
1805
- class HtmlElementPosition {
1806
- constructor(top, left) {
1807
- this.top = 0;
1808
- this.left = 0;
1809
- this.top = top;
1810
- this.left = left;
1811
- }
1812
- didChangeComparedTo(other) {
1813
- if (!other)
1814
- return true;
1815
- return this.top !== other.top || this.left !== other.left;
1816
- }
1817
- }
1818
- class HtmlElementSize {
1819
- constructor(width, height) {
1820
- this.width = width;
1821
- this.height = height;
1822
- }
1823
- didChangeComparedTo(other) {
1824
- if (!other)
1825
- return true;
1826
- return this.width !== other.width || this.height !== other.height;
1827
- }
1828
- }
1829
- class HTMLElementState {
1830
- constructor() {
1831
- this.isShown = false;
1832
- this.position = null;
1833
- this.size = null;
1834
- this.shouldBeUnderContent = false;
1835
- }
1836
- get isValid() {
1837
- return this.isShown !== undefined && this.isShown !== null
1838
- && this.position !== undefined && this.position !== null
1839
- && this.size !== undefined && this.size !== null
1840
- && this.shouldBeUnderContent !== undefined && this.shouldBeUnderContent !== null;
2167
+ class DataCaptureContextFeatures {
2168
+ static isFeatureSupported(feature) {
2169
+ return this._featureFlags.get(feature);
1841
2170
  }
1842
- didChangeComparedTo(other) {
1843
- var _a, _b, _c, _d;
1844
- if (!other)
1845
- return true;
1846
- 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);
1847
- const sizeChanged = (_d = (_c = this.size) === null || _c === void 0 ? void 0 : _c.didChangeComparedTo(other.size)) !== null && _d !== void 0 ? _d : (this.size !== other.size);
1848
- return positionChanged || sizeChanged || this.shouldBeUnderContent !== other.shouldBeUnderContent;
2171
+ static setIsFeatureSupported(feature, value) {
2172
+ this._featureFlags.set(feature, value);
1849
2173
  }
1850
2174
  }
2175
+ DataCaptureContextFeatures._featureFlags = new Map();
1851
2176
 
1852
2177
  var DataCaptureViewEvents;
1853
2178
  (function (DataCaptureViewEvents) {
@@ -1868,14 +2193,14 @@ class DataCaptureViewController extends BaseController {
1868
2193
  }
1869
2194
  viewPointForFramePoint(point) {
1870
2195
  return __awaiter(this, void 0, void 0, function* () {
1871
- const jsonString = yield this._proxy.viewPointForFramePoint(JSON.stringify(point.toJSON()));
1872
- return Point.fromJSON(JSON.parse(jsonString));
2196
+ const result = yield this._proxy.viewPointForFramePoint(JSON.stringify(point.toJSON()));
2197
+ return Point.fromJSON(JSON.parse(result.data));
1873
2198
  });
1874
2199
  }
1875
2200
  viewQuadrilateralForFrameQuadrilateral(quadrilateral) {
1876
2201
  return __awaiter(this, void 0, void 0, function* () {
1877
- const jsonString = yield this._proxy.viewQuadrilateralForFrameQuadrilateral(JSON.stringify(quadrilateral.toJSON()));
1878
- return Quadrilateral.fromJSON(JSON.parse(jsonString));
2202
+ const result = yield this._proxy.viewQuadrilateralForFrameQuadrilateral(JSON.stringify(quadrilateral.toJSON()));
2203
+ return Quadrilateral.fromJSON(JSON.parse(result.data));
1879
2204
  });
1880
2205
  }
1881
2206
  setPositionAndSize(top, left, width, height, shouldBeUnderWebView) {
@@ -1909,10 +2234,14 @@ class DataCaptureViewController extends BaseController {
1909
2234
  var _a, _b;
1910
2235
  this._proxy.registerListenerForViewEvents();
1911
2236
  (_b = (_a = this._proxy).subscribeDidChangeSize) === null || _b === void 0 ? void 0 : _b.call(_a);
1912
- this.eventEmitter.on(DataCaptureViewEvents.didChangeSize, (payload) => {
1913
- const payloadJSON = JSON.parse(payload);
1914
- const size = Size.fromJSON(payloadJSON.size);
1915
- const orientation = payloadJSON.orientation;
2237
+ this.eventEmitter.on(DataCaptureViewEvents.didChangeSize, (data) => {
2238
+ const event = EventDataParser.parse(data);
2239
+ if (event === null) {
2240
+ console.error('DataCaptureViewController didChangeSize payload is null');
2241
+ return;
2242
+ }
2243
+ const size = Size.fromJSON(event.size);
2244
+ const orientation = event.orientation;
1916
2245
  this.view.listeners.forEach(listener => {
1917
2246
  if (listener.didChangeSize) {
1918
2247
  listener.didChangeSize(this.view.viewComponent, size, orientation);
@@ -2896,5 +3225,5 @@ var Expiration;
2896
3225
 
2897
3226
  createEventEmitter();
2898
3227
 
2899
- export { AimerViewfinder, Anchor, BaseController, BaseDataCaptureView, BaseNativeProxy, Brush, Camera, CameraController, CameraPosition, CameraSettings, Color, ContextStatus, ControlImage, DataCaptureContext, DataCaptureContextEvents, DataCaptureContextFeatures, DataCaptureContextSettings, DataCaptureViewController, DataCaptureViewEvents, DefaultSerializeable, Direction, EventEmitter, Expiration, FactoryMaker, Feedback, FocusGestureStrategy, FocusRange, FrameSourceListenerEvents, FrameSourceState, HTMLElementState, HtmlElementPosition, HtmlElementSize, ImageBuffer, ImageFrameSource, LicenseInfo, LogoStyle, MarginsWithUnit, MeasureUnit, NoViewfinder, NoneLocationSelection, NumberWithUnit, OpenSourceSoftwareLicenseInfo, Orientation, Point, PointWithUnit, PrivateFocusGestureDeserializer, PrivateFrameData, PrivateZoomGestureDeserializer, Quadrilateral, RadiusLocationSelection, Rect, RectWithUnit, RectangularLocationSelection, RectangularViewfinder, RectangularViewfinderAnimation, RectangularViewfinderLineStyle, RectangularViewfinderStyle, ScanIntention, Size, SizeWithAspect, SizeWithUnit, SizeWithUnitAndAspect, SizingMode, Sound, SwipeToZoom, TapToFocus, TorchState, TorchSwitchControl, Vibration, VibrationType, VideoResolution, WaveFormVibration, ZoomSwitchControl, getCoreDefaults, ignoreFromSerialization, ignoreFromSerializationIfNull, loadCoreDefaults, nameForSerialization, serializationDefault };
3228
+ export { AdvancedNativeProxy, AimerViewfinder, Anchor, BaseController, BaseDataCaptureView, BaseNativeProxy, Brush, Camera, CameraController, CameraPosition, CameraSettings, Color, ContextStatus, ControlImage, DataCaptureContext, DataCaptureContextEvents, DataCaptureContextFeatures, DataCaptureContextSettings, DataCaptureViewController, DataCaptureViewEvents, DefaultSerializeable, Direction, EventDataParser, EventEmitter, Expiration, FactoryMaker, Feedback, FocusGestureStrategy, FocusRange, FontFamily, FrameSourceListenerEvents, FrameSourceState, HTMLElementState, HtmlElementPosition, HtmlElementSize, ImageBuffer, ImageFrameSource, LicenseInfo, LogoStyle, MarginsWithUnit, MeasureUnit, NoViewfinder, NoneLocationSelection, NumberWithUnit, Observable, OpenSourceSoftwareLicenseInfo, Orientation, Point, PointWithUnit, PrivateFocusGestureDeserializer, PrivateFrameData, PrivateZoomGestureDeserializer, Quadrilateral, RadiusLocationSelection, Rect, RectWithUnit, RectangularLocationSelection, RectangularViewfinder, RectangularViewfinderAnimation, RectangularViewfinderLineStyle, RectangularViewfinderStyle, ScanIntention, ScanditIcon, ScanditIconBuilder, ScanditIconShape, ScanditIconType, Size, SizeWithAspect, SizeWithUnit, SizeWithUnitAndAspect, SizingMode, Sound, SwipeToZoom, TapToFocus, TextAlignment, TorchState, TorchSwitchControl, Vibration, VibrationType, VideoResolution, WaveFormVibration, ZoomSwitchControl, createAdvancedNativeProxy, getCoreDefaults, ignoreFromSerialization, ignoreFromSerializationIfNull, loadCoreDefaults, nameForSerialization, serializationDefault };
2900
3229
  //# sourceMappingURL=index.js.map