scandit-datacapture-frameworks-core 7.0.1 → 7.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,1493 @@ 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;
952
- }
953
- static fromBase64EncodedImage(data) {
954
- if (data === null)
955
- return null;
956
- return new ControlImage("base64", data, null);
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;
957
932
  }
958
- static fromResourceName(resource) {
959
- return new ControlImage("resource", null, resource);
933
+ withIconColor(iconColor) {
934
+ this._iconColor = iconColor;
935
+ return this;
960
936
  }
961
- isBase64EncodedImage() {
962
- return this.type === "base64";
937
+ withBackgroundColor(backgroundColor) {
938
+ this._backgroundColor = backgroundColor;
939
+ return this;
963
940
  }
964
- get data() {
965
- return this._data;
941
+ withBackgroundShape(backgroundShape) {
942
+ this._backgroundShape = backgroundShape;
943
+ return this;
966
944
  }
967
- }
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
-
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;
945
+ withIcon(iconType) {
946
+ this._icon = iconType;
947
+ return this;
984
948
  }
985
- get message() {
986
- return this._message;
949
+ withBackgroundStrokeColor(backgroundStrokeColor) {
950
+ this._backgroundStrokeColor = backgroundStrokeColor;
951
+ return this;
987
952
  }
988
- get code() {
989
- return this._code;
953
+ withBackgroundStrokeWidth(backgroundStrokeWidth) {
954
+ this._backgroundStrokeWidth = backgroundStrokeWidth;
955
+ return this;
990
956
  }
991
- get isValid() {
992
- return this._isValid;
957
+ build() {
958
+ return new ScanditIcon(this._iconColor, this._backgroundColor, this._backgroundShape, this._icon, this._backgroundStrokeColor, this._backgroundStrokeWidth);
993
959
  }
994
960
  }
995
961
 
996
- class DataCaptureContextSettings extends DefaultSerializeable {
997
- constructor() {
998
- super();
999
- }
1000
- setProperty(name, value) {
1001
- this[name] = value;
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;
1002
997
  }
1003
- getProperty(name) {
1004
- return this[name];
998
+ get height() {
999
+ return this._height;
1005
1000
  }
1006
- }
1007
-
1008
- class DataCaptureContextFeatures {
1009
- static get featureFlags() {
1010
- return this._featureFlags;
1001
+ static fromJSON(json) {
1002
+ return new Size(json.width, json.height);
1011
1003
  }
1012
- static set featureFlags(value) {
1013
- this._featureFlags = value;
1004
+ constructor(width, height) {
1005
+ super();
1006
+ this._width = width;
1007
+ this._height = height;
1014
1008
  }
1015
1009
  }
1016
- DataCaptureContextFeatures._featureFlags = {};
1010
+ __decorate([
1011
+ nameForSerialization('width')
1012
+ ], Size.prototype, "_width", void 0);
1013
+ __decorate([
1014
+ nameForSerialization('height')
1015
+ ], Size.prototype, "_height", void 0);
1017
1016
 
1018
- class OpenSourceSoftwareLicenseInfo {
1019
- constructor(licenseText) {
1020
- this._licenseText = licenseText;
1017
+ class SizeWithAspect extends DefaultSerializeable {
1018
+ get size() {
1019
+ return this._size;
1021
1020
  }
1022
- get licenseText() {
1023
- return this._licenseText;
1021
+ get aspect() {
1022
+ return this._aspect;
1023
+ }
1024
+ constructor(size, aspect) {
1025
+ super();
1026
+ this._size = size;
1027
+ this._aspect = aspect;
1024
1028
  }
1025
1029
  }
1030
+ __decorate([
1031
+ nameForSerialization('size')
1032
+ ], SizeWithAspect.prototype, "_size", void 0);
1033
+ __decorate([
1034
+ nameForSerialization('aspect')
1035
+ ], SizeWithAspect.prototype, "_aspect", void 0);
1026
1036
 
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;
1035
- }
1036
- get frameworkVersion() {
1037
- return this._proxy.frameworkVersion;
1037
+ class SizeWithUnit extends DefaultSerializeable {
1038
+ get width() {
1039
+ return this._width;
1038
1040
  }
1039
- get privateContext() {
1040
- return this.context;
1041
+ get height() {
1042
+ return this._height;
1041
1043
  }
1042
- static forDataCaptureContext(context) {
1043
- const controller = new DataCaptureContextController();
1044
- controller.context = context;
1045
- controller.initialize();
1046
- return controller;
1044
+ constructor(width, height) {
1045
+ super();
1046
+ this._width = width;
1047
+ this._height = height;
1047
1048
  }
1049
+ }
1050
+ __decorate([
1051
+ nameForSerialization('width')
1052
+ ], SizeWithUnit.prototype, "_width", void 0);
1053
+ __decorate([
1054
+ nameForSerialization('height')
1055
+ ], SizeWithUnit.prototype, "_height", void 0);
1056
+
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 {
1048
1066
  constructor() {
1049
- this._proxy = FactoryMaker.getInstance('DataCaptureContextProxy');
1050
- this.eventEmitter = FactoryMaker.getInstance('EventEmitter');
1051
- }
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
- });
1067
+ this._widthAndHeight = null;
1068
+ this._widthAndAspectRatio = null;
1069
+ this._heightAndAspectRatio = null;
1070
+ this._shorterDimensionAndAspectRatio = null;
1062
1071
  }
1063
- addModeToContext(mode) {
1064
- return this._proxy.addModeToContext(JSON.stringify(mode.toJSON()));
1072
+ get widthAndHeight() {
1073
+ return this._widthAndHeight;
1065
1074
  }
1066
- removeModeFromContext(mode) {
1067
- return this._proxy.removeModeFromContext(JSON.stringify(mode.toJSON()));
1075
+ get widthAndAspectRatio() {
1076
+ return this._widthAndAspectRatio;
1068
1077
  }
1069
- removeAllModesFromContext() {
1070
- return this._proxy.removeAllModesFromContext();
1078
+ get heightAndAspectRatio() {
1079
+ return this._heightAndAspectRatio;
1071
1080
  }
1072
- dispose() {
1073
- this.unsubscribeListener();
1074
- this._proxy.dispose();
1081
+ get shorterDimensionAndAspectRatio() {
1082
+ return this._shorterDimensionAndAspectRatio;
1075
1083
  }
1076
- unsubscribeListener() {
1077
- this._proxy.unregisterListenerForDataCaptureContext();
1078
- this.eventEmitter.removeAllListeners(DataCaptureContextEvents.didChangeStatus);
1079
- this.eventEmitter.removeAllListeners(DataCaptureContextEvents.didStartObservingContext);
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;
1080
1095
  }
1081
- initialize() {
1082
- this.subscribeListener();
1083
- return this.initializeContextFromJSON();
1096
+ static sizeWithWidthAndHeight(widthAndHeight) {
1097
+ const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1098
+ sizeWithUnitAndAspect._widthAndHeight = widthAndHeight;
1099
+ return sizeWithUnitAndAspect;
1084
1100
  }
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
- });
1101
+ static sizeWithWidthAndAspectRatio(width, aspectRatio) {
1102
+ const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1103
+ sizeWithUnitAndAspect._widthAndAspectRatio = new SizeWithAspect(width, aspectRatio);
1104
+ return sizeWithUnitAndAspect;
1097
1105
  }
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
- });
1106
+ static sizeWithHeightAndAspectRatio(height, aspectRatio) {
1107
+ const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1108
+ sizeWithUnitAndAspect._heightAndAspectRatio = new SizeWithAspect(height, aspectRatio);
1109
+ return sizeWithUnitAndAspect;
1104
1110
  }
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
- });
1111
+ static sizeWithShorterDimensionAndAspectRatio(shorterDimension, aspectRatio) {
1112
+ const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1113
+ sizeWithUnitAndAspect._shorterDimensionAndAspectRatio = new SizeWithAspect(shorterDimension, aspectRatio);
1114
+ return sizeWithUnitAndAspect;
1119
1115
  }
1120
- notifyListenersOfDeserializationError(error) {
1121
- const contextStatus = ContextStatus
1122
- .fromJSON({
1123
- message: error,
1124
- code: -1,
1125
- isValid: true,
1126
- });
1127
- this.notifyListenersOfDidChangeStatus(contextStatus);
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
+ }
1128
1132
  }
1129
- notifyListenersOfDidChangeStatus(contextStatus) {
1130
- this.privateContext.listeners.forEach(listener => {
1131
- if (listener.didChangeStatus) {
1132
- listener.didChangeStatus(this.context, contextStatus);
1133
- }
1134
- });
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
+ }
1135
1156
  }
1136
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);
1137
1170
 
1138
- class DataCaptureContext extends DefaultSerializeable {
1139
- get framework() {
1140
- return this.controller.framework;
1171
+ class MarginsWithUnit extends DefaultSerializeable {
1172
+ get left() {
1173
+ return this._left;
1141
1174
  }
1142
- get frameworkVersion() {
1143
- return this.controller.frameworkVersion;
1175
+ get right() {
1176
+ return this._right;
1144
1177
  }
1145
- static get coreDefaults() {
1146
- return getCoreDefaults();
1178
+ get top() {
1179
+ return this._top;
1147
1180
  }
1148
- get frameSource() {
1149
- return this._frameSource;
1181
+ get bottom() {
1182
+ return this._bottom;
1150
1183
  }
1151
- static get deviceID() {
1152
- return DataCaptureContext.coreDefaults.deviceID;
1184
+ static fromJSON(json) {
1185
+ return new MarginsWithUnit(NumberWithUnit.fromJSON(json.left), NumberWithUnit.fromJSON(json.right), NumberWithUnit.fromJSON(json.top), NumberWithUnit.fromJSON(json.bottom));
1153
1186
  }
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;
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));
1160
1189
  }
1161
- static forLicenseKey(licenseKey) {
1162
- return DataCaptureContext.create(licenseKey, null, null);
1190
+ constructor(left, right, top, bottom) {
1191
+ super();
1192
+ this._left = left;
1193
+ this._right = right;
1194
+ this._top = top;
1195
+ this._bottom = bottom;
1163
1196
  }
1164
- static forLicenseKeyWithSettings(licenseKey, settings) {
1165
- return DataCaptureContext.create(licenseKey, null, settings);
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);
1210
+
1211
+ class Color {
1212
+ get redComponent() {
1213
+ return this.hexadecimalString.slice(0, 2);
1166
1214
  }
1167
- static forLicenseKeyWithOptions(licenseKey, options) {
1168
- return DataCaptureContext.create(licenseKey, options, null);
1215
+ get greenComponent() {
1216
+ return this.hexadecimalString.slice(2, 4);
1169
1217
  }
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;
1218
+ get blueComponent() {
1219
+ return this.hexadecimalString.slice(4, 6);
1178
1220
  }
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;
1221
+ get alphaComponent() {
1222
+ return this.hexadecimalString.slice(6, 8);
1223
+ }
1224
+ get red() {
1225
+ return Color.hexToNumber(this.redComponent);
1226
+ }
1227
+ get green() {
1228
+ return Color.hexToNumber(this.greenComponent);
1229
+ }
1230
+ get blue() {
1231
+ return Color.hexToNumber(this.blueComponent);
1232
+ }
1233
+ get alpha() {
1234
+ return Color.hexToNumber(this.alphaComponent);
1235
+ }
1236
+ static fromHex(hex) {
1237
+ return new Color(Color.normalizeHex(hex));
1238
+ }
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);
1243
+ }
1244
+ static hexToNumber(hex) {
1245
+ return parseInt(hex, 16);
1246
+ }
1247
+ static fromJSON(json) {
1248
+ return Color.fromHex(json);
1249
+ }
1250
+ static numberToHex(x) {
1251
+ x = Math.round(x);
1252
+ let hex = x.toString(16);
1253
+ if (hex.length === 1) {
1254
+ hex = '0' + hex;
1190
1255
  }
1191
- this.initialize();
1256
+ return hex.toUpperCase();
1192
1257
  }
1193
- setFrameSource(frameSource) {
1194
- if (this._frameSource) {
1195
- this._frameSource.context = null;
1258
+ static normalizeHex(hex) {
1259
+ // remove leading #
1260
+ if (hex[0] === '#') {
1261
+ hex = hex.slice(1);
1196
1262
  }
1197
- this._frameSource = frameSource;
1198
- if (frameSource) {
1199
- frameSource.context = this;
1263
+ // double digits if single digit
1264
+ if (hex.length < 6) {
1265
+ hex = hex.split('').map(s => s + s).join('');
1200
1266
  }
1201
- return this.update();
1202
- }
1203
- addListener(listener) {
1204
- if (this.listeners.includes(listener)) {
1205
- return;
1267
+ // add alpha if missing
1268
+ if (hex.length === 6) {
1269
+ hex = hex + 'FF';
1206
1270
  }
1207
- this.listeners.push(listener);
1271
+ return '#' + hex.toUpperCase();
1208
1272
  }
1209
- removeListener(listener) {
1210
- if (!this.listeners.includes(listener)) {
1211
- return;
1273
+ static normalizeAlpha(alpha) {
1274
+ if (alpha > 0 && alpha <= 1) {
1275
+ return 255 * alpha;
1212
1276
  }
1213
- this.listeners.splice(this.listeners.indexOf(listener), 1);
1277
+ return alpha;
1214
1278
  }
1215
- addMode(mode) {
1216
- if (!this.modes.includes(mode)) {
1217
- this.modes.push(mode);
1218
- mode._context = this;
1219
- this.controller.addModeToContext(mode);
1220
- }
1279
+ constructor(hex) {
1280
+ this.hexadecimalString = hex;
1221
1281
  }
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);
1227
- }
1282
+ withAlpha(alpha) {
1283
+ const newHex = this.hexadecimalString.slice(0, 6) + Color.numberToHex(Color.normalizeAlpha(alpha));
1284
+ return Color.fromHex(newHex);
1228
1285
  }
1229
- removeAllModes() {
1230
- this.modes.forEach(mode => {
1231
- mode._context = null;
1232
- });
1233
- this.modes = [];
1234
- this.controller.removeAllModesFromContext();
1286
+ toJSON() {
1287
+ return this.hexadecimalString;
1235
1288
  }
1236
- dispose() {
1237
- var _a;
1238
- if (!this.controller) {
1239
- return;
1240
- }
1241
- DataCaptureContext.instance = null;
1242
- (_a = this.view) === null || _a === void 0 ? void 0 : _a.dispose();
1243
- this.removeAllModes();
1244
- this.controller.dispose();
1289
+ }
1290
+
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);
1245
1295
  }
1246
- applySettings(settings) {
1247
- this.settings = settings;
1248
- return this.update();
1296
+ get fillColor() {
1297
+ return this.fill.color;
1249
1298
  }
1250
- static getOpenSourceSoftwareLicenseInfo() {
1251
- return __awaiter(this, void 0, void 0, function* () {
1252
- return DataCaptureContextController.getOpenSourceSoftwareLicenseInfo();
1253
- });
1299
+ get strokeColor() {
1300
+ return this.stroke.color;
1254
1301
  }
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);
1302
+ get strokeWidth() {
1303
+ return this.stroke.width;
1261
1304
  }
1262
- update() {
1263
- if (!this.controller) {
1264
- return Promise.resolve();
1265
- }
1266
- return this.controller.updateContextFromJSON();
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 };
1267
1312
  }
1268
1313
  }
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
1314
 
1289
- class Point extends DefaultSerializeable {
1290
- get x() {
1291
- return this._x;
1292
- }
1293
- get y() {
1294
- return this._y;
1295
- }
1296
- static fromJSON(json) {
1297
- return new Point(json.x, json.y);
1298
- }
1299
- constructor(x, y) {
1300
- super();
1301
- this._x = x;
1302
- this._y = y;
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);
1303
1360
  }
1304
1361
  }
1305
- __decorate([
1306
- nameForSerialization('x')
1307
- ], Point.prototype, "_x", void 0);
1308
- __decorate([
1309
- nameForSerialization('y')
1310
- ], Point.prototype, "_y", void 0);
1311
1362
 
1312
- class Quadrilateral extends DefaultSerializeable {
1313
- get topLeft() {
1314
- return this._topLeft;
1315
- }
1316
- get topRight() {
1317
- return this._topRight;
1318
- }
1319
- get bottomRight() {
1320
- return this._bottomRight;
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 {
1517
- constructor() {
1518
- this._widthAndHeight = null;
1519
- this._widthAndAspectRatio = null;
1520
- this._heightAndAspectRatio = null;
1521
- this._shorterDimensionAndAspectRatio = null;
1586
+ class CameraController {
1587
+ static get _proxy() {
1588
+ return FactoryMaker.getInstance('CameraProxy');
1522
1589
  }
1523
- get widthAndHeight() {
1524
- return this._widthAndHeight;
1590
+ static forCamera(camera) {
1591
+ const controller = new CameraController();
1592
+ controller.camera = camera;
1593
+ return controller;
1525
1594
  }
1526
- get widthAndAspectRatio() {
1527
- return this._widthAndAspectRatio;
1595
+ constructor() {
1596
+ this.eventEmitter = FactoryMaker.getInstance('EventEmitter');
1528
1597
  }
1529
- get heightAndAspectRatio() {
1530
- return this._heightAndAspectRatio;
1598
+ get privateCamera() {
1599
+ return this.camera;
1531
1600
  }
1532
- get shorterDimensionAndAspectRatio() {
1533
- return this._shorterDimensionAndAspectRatio;
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
+ });
1534
1610
  }
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;
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
+ });
1546
1620
  }
1547
- static sizeWithWidthAndHeight(widthAndHeight) {
1548
- const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1549
- sizeWithUnitAndAspect._widthAndHeight = widthAndHeight;
1550
- return sizeWithUnitAndAspect;
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
+ });
1551
1629
  }
1552
- static sizeWithWidthAndAspectRatio(width, aspectRatio) {
1553
- const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1554
- sizeWithUnitAndAspect._widthAndAspectRatio = new SizeWithAspect(width, aspectRatio);
1555
- return sizeWithUnitAndAspect;
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
+ });
1556
1638
  }
1557
- static sizeWithHeightAndAspectRatio(height, aspectRatio) {
1558
- const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1559
- sizeWithUnitAndAspect._heightAndAspectRatio = new SizeWithAspect(height, aspectRatio);
1560
- return sizeWithUnitAndAspect;
1639
+ switchCameraToDesiredState(desiredState) {
1640
+ return CameraController._proxy.switchCameraToDesiredState(desiredState);
1561
1641
  }
1562
- static sizeWithShorterDimensionAndAspectRatio(shorterDimension, aspectRatio) {
1563
- const sizeWithUnitAndAspect = new SizeWithUnitAndAspect();
1564
- sizeWithUnitAndAspect._shorterDimensionAndAspectRatio = new SizeWithAspect(shorterDimension, aspectRatio);
1565
- 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
+ });
1566
1655
  }
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);
1579
- }
1580
- else {
1581
- throw new Error(`SizeWithUnitAndAspectJSON is malformed: ${JSON.stringify(json)}`);
1582
- }
1656
+ unsubscribeListener() {
1657
+ CameraController._proxy.unregisterListenerForCameraEvents();
1658
+ this.eventEmitter.off(FrameSourceListenerEvents.didChangeState);
1583
1659
  }
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
- };
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();
1672
+ }
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;
1684
+ }
1685
+ else {
1686
+ return null;
1687
+ }
1688
+ }
1689
+ static withSettings(settings) {
1690
+ const camera = Camera.default;
1691
+ if (camera) {
1692
+ camera.settings = settings;
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;
1606
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";
1829
+ }
1830
+ get data() {
1831
+ return this._data;
1634
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 DataCaptureContextFeatures {
1875
+ static get featureFlags() {
1876
+ return this._featureFlags;
1665
1877
  }
1666
- get greenComponent() {
1667
- return this.hexadecimalString.slice(2, 4);
1878
+ static set featureFlags(value) {
1879
+ this._featureFlags = value;
1668
1880
  }
1669
- get blueComponent() {
1670
- return this.hexadecimalString.slice(4, 6);
1881
+ }
1882
+ DataCaptureContextFeatures._featureFlags = {};
1883
+
1884
+ class OpenSourceSoftwareLicenseInfo {
1885
+ constructor(licenseText) {
1886
+ this._licenseText = licenseText;
1671
1887
  }
1672
- get alphaComponent() {
1673
- return this.hexadecimalString.slice(6, 8);
1888
+ get licenseText() {
1889
+ return this._licenseText;
1674
1890
  }
1675
- get red() {
1676
- return Color.hexToNumber(this.redComponent);
1891
+ }
1892
+
1893
+ var DataCaptureContextEvents;
1894
+ (function (DataCaptureContextEvents) {
1895
+ DataCaptureContextEvents["didChangeStatus"] = "DataCaptureContextListener.onStatusChanged";
1896
+ DataCaptureContextEvents["didStartObservingContext"] = "DataCaptureContextListener.onObservationStarted";
1897
+ })(DataCaptureContextEvents || (DataCaptureContextEvents = {}));
1898
+ class DataCaptureContextController {
1899
+ static get framework() {
1900
+ return FactoryMaker.getInstance('DataCaptureContextProxy').framework;
1677
1901
  }
1678
- get green() {
1679
- return Color.hexToNumber(this.greenComponent);
1902
+ static get frameworkVersion() {
1903
+ return FactoryMaker.getInstance('DataCaptureContextProxy').frameworkVersion;
1680
1904
  }
1681
- get blue() {
1682
- return Color.hexToNumber(this.blueComponent);
1905
+ get privateContext() {
1906
+ return this.context;
1683
1907
  }
1684
- get alpha() {
1685
- return Color.hexToNumber(this.alphaComponent);
1908
+ static forDataCaptureContext(context) {
1909
+ const controller = new DataCaptureContextController();
1910
+ controller.context = context;
1911
+ controller.initialize();
1912
+ return controller;
1686
1913
  }
1687
- static fromHex(hex) {
1688
- return new Color(Color.normalizeHex(hex));
1914
+ static forDataCaptureContextAsync(context) {
1915
+ return __awaiter(this, void 0, void 0, function* () {
1916
+ const controller = new DataCaptureContextController();
1917
+ controller.context = context;
1918
+ yield controller.initialize();
1919
+ return controller;
1920
+ });
1921
+ }
1922
+ constructor() {
1923
+ this._proxy = FactoryMaker.getInstance('DataCaptureContextProxy');
1924
+ this.eventEmitter = FactoryMaker.getInstance('EventEmitter');
1925
+ }
1926
+ updateContextFromJSON() {
1927
+ return __awaiter(this, void 0, void 0, function* () {
1928
+ try {
1929
+ yield this._proxy.updateContextFromJSON(JSON.stringify(this.context.toJSON()));
1930
+ }
1931
+ catch (error) {
1932
+ this.notifyListenersOfDeserializationError(error);
1933
+ throw error;
1934
+ }
1935
+ });
1936
+ }
1937
+ addModeToContext(mode) {
1938
+ return this._proxy.addModeToContext(JSON.stringify(mode.toJSON()));
1939
+ }
1940
+ removeModeFromContext(mode) {
1941
+ return this._proxy.removeModeFromContext(JSON.stringify(mode.toJSON()));
1942
+ }
1943
+ removeAllModesFromContext() {
1944
+ return this._proxy.removeAllModesFromContext();
1945
+ }
1946
+ dispose() {
1947
+ this.unsubscribeListener();
1948
+ this._proxy.dispose();
1949
+ }
1950
+ unsubscribeListener() {
1951
+ this._proxy.unregisterListenerForDataCaptureContext();
1952
+ this.eventEmitter.removeAllListeners(DataCaptureContextEvents.didChangeStatus);
1953
+ this.eventEmitter.removeAllListeners(DataCaptureContextEvents.didStartObservingContext);
1954
+ }
1955
+ initialize() {
1956
+ this.subscribeListener();
1957
+ return this.initializeContextFromJSON();
1958
+ }
1959
+ initializeContextFromJSON() {
1960
+ return __awaiter(this, void 0, void 0, function* () {
1961
+ try {
1962
+ const result = yield this._proxy.contextFromJSON(JSON.stringify(this.context.toJSON()));
1963
+ DataCaptureContextFeatures.featureFlags =
1964
+ JSON.parse(result.data);
1965
+ }
1966
+ catch (error) {
1967
+ this.notifyListenersOfDeserializationError(error);
1968
+ throw error;
1969
+ }
1970
+ });
1971
+ }
1972
+ static getOpenSourceSoftwareLicenseInfo() {
1973
+ return __awaiter(this, void 0, void 0, function* () {
1974
+ const proxy = FactoryMaker.getInstance('DataCaptureContextProxy');
1975
+ const result = yield proxy.getOpenSourceSoftwareLicenseInfo();
1976
+ return new OpenSourceSoftwareLicenseInfo(result.data);
1977
+ });
1978
+ }
1979
+ subscribeListener() {
1980
+ var _a, _b, _c, _d;
1981
+ this._proxy.registerListenerForDataCaptureContext();
1982
+ (_b = (_a = this._proxy).subscribeDidChangeStatus) === null || _b === void 0 ? void 0 : _b.call(_a);
1983
+ (_d = (_c = this._proxy).subscribeDidStartObservingContext) === null || _d === void 0 ? void 0 : _d.call(_c);
1984
+ this.eventEmitter.on(DataCaptureContextEvents.didChangeStatus, (data) => {
1985
+ const event = EventDataParser.parse(data);
1986
+ if (event === null) {
1987
+ console.error('DataCaptureContextController didChangeStatus payload is null');
1988
+ return;
1989
+ }
1990
+ const contextStatus = ContextStatus.fromJSON(JSON.parse(event.status));
1991
+ this.notifyListenersOfDidChangeStatus(contextStatus);
1992
+ });
1993
+ this.eventEmitter.on(DataCaptureContextEvents.didStartObservingContext, () => {
1994
+ this.privateContext.listeners.forEach(listener => {
1995
+ var _a;
1996
+ (_a = listener.didStartObservingContext) === null || _a === void 0 ? void 0 : _a.call(listener, this.context);
1997
+ });
1998
+ });
1999
+ }
2000
+ notifyListenersOfDeserializationError(error) {
2001
+ const contextStatus = ContextStatus
2002
+ .fromJSON({
2003
+ message: error,
2004
+ code: -1,
2005
+ isValid: true,
2006
+ });
2007
+ this.notifyListenersOfDidChangeStatus(contextStatus);
2008
+ }
2009
+ notifyListenersOfDidChangeStatus(contextStatus) {
2010
+ this.privateContext.listeners.forEach(listener => {
2011
+ if (listener.didChangeStatus) {
2012
+ listener.didChangeStatus(this.context, contextStatus);
2013
+ }
2014
+ });
2015
+ }
2016
+ }
2017
+
2018
+ class DataCaptureContext extends DefaultSerializeable {
2019
+ static get coreDefaults() {
2020
+ return getCoreDefaults();
2021
+ }
2022
+ get frameSource() {
2023
+ return this._frameSource;
2024
+ }
2025
+ static get deviceID() {
2026
+ return DataCaptureContext.coreDefaults.deviceID;
2027
+ }
2028
+ /**
2029
+ * @deprecated
2030
+ */
2031
+ get deviceID() {
2032
+ console.log('The instance property "deviceID" on the DataCaptureContext is deprecated, please use the static property DataCaptureContext.deviceID instead.');
2033
+ return DataCaptureContext.deviceID;
1689
2034
  }
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);
2035
+ static forLicenseKey(licenseKey) {
2036
+ return DataCaptureContext.create(licenseKey, null, null);
1694
2037
  }
1695
- static hexToNumber(hex) {
1696
- return parseInt(hex, 16);
2038
+ static forLicenseKeyWithSettings(licenseKey, settings) {
2039
+ return DataCaptureContext.create(licenseKey, null, settings);
1697
2040
  }
1698
- static fromJSON(json) {
1699
- return Color.fromHex(json);
2041
+ static forLicenseKeyWithOptions(licenseKey, options) {
2042
+ return DataCaptureContext.create(licenseKey, options, null);
1700
2043
  }
1701
- static numberToHex(x) {
1702
- x = Math.round(x);
1703
- let hex = x.toString(16);
1704
- if (hex.length === 1) {
1705
- hex = '0' + hex;
2044
+ static create(licenseKey, options, settings) {
2045
+ if (options == null) {
2046
+ options = { deviceName: null };
1706
2047
  }
1707
- return hex.toUpperCase();
2048
+ if (!DataCaptureContext.instance) {
2049
+ DataCaptureContext.instance = new DataCaptureContext(licenseKey, options.deviceName || '', settings);
2050
+ }
2051
+ return DataCaptureContext.instance;
1708
2052
  }
1709
- static normalizeHex(hex) {
1710
- // remove leading #
1711
- if (hex[0] === '#') {
1712
- hex = hex.slice(1);
2053
+ constructor(licenseKey, deviceName, settings) {
2054
+ super();
2055
+ this.licenseKey = licenseKey;
2056
+ this.deviceName = deviceName;
2057
+ this._framework = DataCaptureContextController.framework;
2058
+ this._frameworkVersion = DataCaptureContextController.frameworkVersion;
2059
+ this.settings = new DataCaptureContextSettings();
2060
+ this._frameSource = null;
2061
+ this.view = null;
2062
+ this.modes = [];
2063
+ this.listeners = [];
2064
+ if (settings) {
2065
+ this.settings = settings;
1713
2066
  }
1714
- // double digits if single digit
1715
- if (hex.length < 6) {
1716
- hex = hex.split('').map(s => s + s).join('');
2067
+ this.initialize();
2068
+ }
2069
+ setFrameSource(frameSource) {
2070
+ if (this._frameSource) {
2071
+ this._frameSource.context = null;
1717
2072
  }
1718
- // add alpha if missing
1719
- if (hex.length === 6) {
1720
- hex = hex + 'FF';
2073
+ this._frameSource = frameSource;
2074
+ if (frameSource) {
2075
+ frameSource.context = this;
1721
2076
  }
1722
- return hex.toUpperCase();
2077
+ return this.update();
1723
2078
  }
1724
- static normalizeAlpha(alpha) {
1725
- if (alpha > 0 && alpha <= 1) {
1726
- return 255 * alpha;
2079
+ addListener(listener) {
2080
+ if (this.listeners.includes(listener)) {
2081
+ return;
1727
2082
  }
1728
- return alpha;
1729
- }
1730
- constructor(hex) {
1731
- this.hexadecimalString = hex;
1732
- }
1733
- withAlpha(alpha) {
1734
- const newHex = this.hexadecimalString.slice(0, 6) + Color.numberToHex(Color.normalizeAlpha(alpha));
1735
- return Color.fromHex(newHex);
1736
- }
1737
- toJSON() {
1738
- return this.hexadecimalString;
1739
- }
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);
1746
- }
1747
- get fillColor() {
1748
- return this.fill.color;
1749
- }
1750
- get strokeColor() {
1751
- return this.stroke.color;
2083
+ this.listeners.push(listener);
1752
2084
  }
1753
- get strokeWidth() {
1754
- return this.stroke.width;
2085
+ removeListener(listener) {
2086
+ if (!this.listeners.includes(listener)) {
2087
+ return;
2088
+ }
2089
+ this.listeners.splice(this.listeners.indexOf(listener), 1);
1755
2090
  }
1756
- get copy() {
1757
- return new Brush(this.fillColor, this.strokeColor, this.strokeWidth);
2091
+ addMode(mode) {
2092
+ if (!this.modes.includes(mode)) {
2093
+ this.modes.push(mode);
2094
+ mode._context = this;
2095
+ this.controller.addModeToContext(mode);
2096
+ }
1758
2097
  }
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 };
2098
+ removeMode(mode) {
2099
+ if (this.modes.includes(mode)) {
2100
+ this.modes.splice(this.modes.indexOf(mode), 1);
2101
+ mode._context = null;
2102
+ this.controller.removeModeFromContext(mode);
2103
+ }
1763
2104
  }
1764
- }
1765
-
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;
2105
+ removeAllModes() {
2106
+ this.modes.forEach(mode => {
2107
+ mode._context = null;
2108
+ });
2109
+ this.modes = [];
2110
+ this.controller.removeAllModesFromContext();
1811
2111
  }
1812
- didChangeComparedTo(other) {
1813
- if (!other)
1814
- return true;
1815
- return this.top !== other.top || this.left !== other.left;
2112
+ dispose() {
2113
+ var _a;
2114
+ if (!this.controller) {
2115
+ return;
2116
+ }
2117
+ DataCaptureContext.instance = null;
2118
+ (_a = this.view) === null || _a === void 0 ? void 0 : _a.dispose();
2119
+ this.removeAllModes();
2120
+ this.controller.dispose();
1816
2121
  }
1817
- }
1818
- class HtmlElementSize {
1819
- constructor(width, height) {
1820
- this.width = width;
1821
- this.height = height;
2122
+ applySettings(settings) {
2123
+ this.settings = settings;
2124
+ return this.update();
1822
2125
  }
1823
- didChangeComparedTo(other) {
1824
- if (!other)
1825
- return true;
1826
- return this.width !== other.width || this.height !== other.height;
2126
+ static getOpenSourceSoftwareLicenseInfo() {
2127
+ return __awaiter(this, void 0, void 0, function* () {
2128
+ return DataCaptureContextController.getOpenSourceSoftwareLicenseInfo();
2129
+ });
1827
2130
  }
1828
- }
1829
- class HTMLElementState {
1830
- constructor() {
1831
- this.isShown = false;
1832
- this.position = null;
1833
- this.size = null;
1834
- this.shouldBeUnderContent = false;
2131
+ // Called when the capture view is shown, that is the earliest point that we need the context deserialized.
2132
+ initialize() {
2133
+ if (this.controller) {
2134
+ return;
2135
+ }
2136
+ this.controller = DataCaptureContextController.forDataCaptureContext(this);
1835
2137
  }
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;
2138
+ initializeAsync() {
2139
+ return __awaiter(this, void 0, void 0, function* () {
2140
+ if (this.controller) {
2141
+ return;
2142
+ }
2143
+ this.controller = yield DataCaptureContextController.forDataCaptureContextAsync(this);
2144
+ });
1841
2145
  }
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;
2146
+ update() {
2147
+ if (!this.controller) {
2148
+ return Promise.resolve();
2149
+ }
2150
+ return this.controller.updateContextFromJSON();
1849
2151
  }
1850
2152
  }
2153
+ DataCaptureContext.instance = null;
2154
+ __decorate([
2155
+ ignoreFromSerialization
2156
+ ], DataCaptureContext.prototype, "controller", void 0);
2157
+ __decorate([
2158
+ nameForSerialization('framework')
2159
+ ], DataCaptureContext.prototype, "_framework", void 0);
2160
+ __decorate([
2161
+ nameForSerialization('frameworkVersion')
2162
+ ], DataCaptureContext.prototype, "_frameworkVersion", void 0);
2163
+ __decorate([
2164
+ nameForSerialization('frameSource')
2165
+ ], DataCaptureContext.prototype, "_frameSource", void 0);
2166
+ __decorate([
2167
+ ignoreFromSerialization
2168
+ ], DataCaptureContext.prototype, "view", void 0);
2169
+ __decorate([
2170
+ ignoreFromSerialization
2171
+ ], DataCaptureContext.prototype, "modes", void 0);
2172
+ __decorate([
2173
+ ignoreFromSerialization
2174
+ ], DataCaptureContext.prototype, "listeners", void 0);
2175
+ __decorate([
2176
+ ignoreFromSerialization
2177
+ ], DataCaptureContext, "coreDefaults", null);
1851
2178
 
1852
2179
  var DataCaptureViewEvents;
1853
2180
  (function (DataCaptureViewEvents) {
@@ -1868,14 +2195,14 @@ class DataCaptureViewController extends BaseController {
1868
2195
  }
1869
2196
  viewPointForFramePoint(point) {
1870
2197
  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));
2198
+ const result = yield this._proxy.viewPointForFramePoint(JSON.stringify(point.toJSON()));
2199
+ return Point.fromJSON(JSON.parse(result.data));
1873
2200
  });
1874
2201
  }
1875
2202
  viewQuadrilateralForFrameQuadrilateral(quadrilateral) {
1876
2203
  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));
2204
+ const result = yield this._proxy.viewQuadrilateralForFrameQuadrilateral(JSON.stringify(quadrilateral.toJSON()));
2205
+ return Quadrilateral.fromJSON(JSON.parse(result.data));
1879
2206
  });
1880
2207
  }
1881
2208
  setPositionAndSize(top, left, width, height, shouldBeUnderWebView) {
@@ -1909,10 +2236,14 @@ class DataCaptureViewController extends BaseController {
1909
2236
  var _a, _b;
1910
2237
  this._proxy.registerListenerForViewEvents();
1911
2238
  (_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;
2239
+ this.eventEmitter.on(DataCaptureViewEvents.didChangeSize, (data) => {
2240
+ const event = EventDataParser.parse(data);
2241
+ if (event === null) {
2242
+ console.error('DataCaptureViewController didChangeSize payload is null');
2243
+ return;
2244
+ }
2245
+ const size = Size.fromJSON(event.size);
2246
+ const orientation = event.orientation;
1916
2247
  this.view.listeners.forEach(listener => {
1917
2248
  if (listener.didChangeSize) {
1918
2249
  listener.didChangeSize(this.view.viewComponent, size, orientation);
@@ -2896,5 +3227,5 @@ var Expiration;
2896
3227
 
2897
3228
  createEventEmitter();
2898
3229
 
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 };
3230
+ 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
3231
  //# sourceMappingURL=index.js.map