nuxeo-development-framework 5.7.0 → 5.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -792,7 +792,7 @@
792
792
  expandedSidenav: true
793
793
  };
794
794
  this.userPreferenceStatus = this.defaults;
795
- this.clientCustomTranslateFiles = { arFile: rxjs.of({}), enFile: rxjs.of({}) };
795
+ this.clientCustomTranslateFiles = { ar: {}, en: {} };
796
796
  this.onChangeSubject = new rxjs.BehaviorSubject(this.userPreferenceStatus);
797
797
  this.onChange = this.onChangeSubject.asObservable();
798
798
  }
@@ -1682,16 +1682,13 @@
1682
1682
  */
1683
1683
  TranslationService.prototype.loadTranslation = function (lang, fallback) {
1684
1684
  var _this = this;
1685
- var clientTranslation;
1686
1685
  if (lang === exports.Lang.Arabic) {
1687
1686
  this.renderer.addClass(document.body, 'rtl');
1688
1687
  this.isArabic.next(true);
1689
- clientTranslation = __classPrivateFieldGet(this, _TranslationService_instances, "a", _TranslationService_ClientTranslationFiles_get).arFile;
1690
1688
  }
1691
1689
  else {
1692
1690
  this.renderer.removeClass(document.body, 'rtl');
1693
1691
  this.isArabic.next(false);
1694
- clientTranslation = __classPrivateFieldGet(this, _TranslationService_instances, "a", _TranslationService_ClientTranslationFiles_get).enFile;
1695
1692
  }
1696
1693
  var arabicFile$ = this.getOrCreateTranslationFile('ar');
1697
1694
  var englishFile$ = this.getOrCreateTranslationFile('en');
@@ -1699,7 +1696,6 @@
1699
1696
  arabicFile$,
1700
1697
  englishFile$,
1701
1698
  this.translate.getTranslation(lang),
1702
- clientTranslation
1703
1699
  ]).subscribe(function (res) {
1704
1700
  _this.arabicFile = res[0];
1705
1701
  _this.englishFile = res[1];
@@ -1707,7 +1703,7 @@
1707
1703
  var ArorEnFile = lang === 'en'
1708
1704
  ? JSON.parse(res[1].properties['note:note'])
1709
1705
  : JSON.parse(res[0].properties['note:note']);
1710
- _this.translate.setTranslation(_this.translate.currentLang, Object.assign(Object.assign({}, (res[3] || {})), ArorEnFile), true);
1706
+ _this.translate.setTranslation(_this.translate.currentLang, Object.assign(Object.assign({}, (__classPrivateFieldGet(_this, _TranslationService_instances, "a", _TranslationService_ClientTranslationFiles_get)[lang] || {})), ArorEnFile), true);
1711
1707
  _this.onTranslationChanged(lang);
1712
1708
  }, function () {
1713
1709
  if (fallback && fallback !== lang) {
@@ -38734,26 +38730,224 @@
38734
38730
  type: i0.Output
38735
38731
  }] } });
38736
38732
 
38733
+ var NdfTronExtractText = /** @class */ (function (_super) {
38734
+ __extends(NdfTronExtractText, _super);
38735
+ function NdfTronExtractText(pdfTronService, renderer, injector) {
38736
+ var _this = _super.call(this, injector) || this;
38737
+ _this.pdfTronService = pdfTronService;
38738
+ _this.renderer = renderer;
38739
+ _this.injector = injector;
38740
+ _this.listnerAdded = false;
38741
+ _this.detectionRectColor = {
38742
+ R: 255,
38743
+ G: 230,
38744
+ B: 162,
38745
+ A: 1
38746
+ };
38747
+ _this.focusedField = '';
38748
+ _this.focusedFieldPrefix = '';
38749
+ _this.onExtractText = new i0.EventEmitter();
38750
+ _this.extractedText = '';
38751
+ _this.savedCoordinates = [];
38752
+ _this.onAnnotationsChange = function (annotations, action) {
38753
+ var _a;
38754
+ _this.extractedText = '';
38755
+ var _f = (_a = _this.pdfTronService) === null || _a === void 0 ? void 0 : _a.instance, annotManager = _f.annotManager, docViewer = _f.docViewer, Annotations = _f.Annotations;
38756
+ if (action === 'add') {
38757
+ annotations.forEach(function (annot) {
38758
+ var _a;
38759
+ if (annot instanceof ((_a = _this.pdfTronService) === null || _a === void 0 ? void 0 : _a.instance.Annotations.RectangleAnnotation)) {
38760
+ _this.rect = annot.getRect();
38761
+ if (_this.currentPageNum != docViewer.getCurrentPage()) {
38762
+ _this.currentPageNum = docViewer.getCurrentPage();
38763
+ _this.targetPage = _this.pagesZones.pages[_this.currentPageNum - 1];
38764
+ _this.allWords = _this.getAllWordsInThePage();
38765
+ }
38766
+ var pageHeight = _this.targetPage.page_height;
38767
+ var pageWidth = _this.targetPage.page_width;
38768
+ var standardHeight = docViewer.getPageHeight(_this.currentPageNum);
38769
+ var standardWidth = docViewer.getPageWidth(_this.currentPageNum);
38770
+ var widthRatio_1 = pageWidth / standardWidth;
38771
+ var heightRatio_1 = pageHeight / standardHeight;
38772
+ _this.allWords.forEach(function (word) {
38773
+ if (word.coordinates.upper_left.x >= widthRatio_1 * _this.rect.x1 &&
38774
+ word.coordinates.upper_left.y >= heightRatio_1 * _this.rect.y1 &&
38775
+ word.coordinates.bottom_right.x <= widthRatio_1 * _this.rect.x2 &&
38776
+ word.coordinates.bottom_right.y <= heightRatio_1 * _this.rect.y2) {
38777
+ _this.extractedText += word.text + ' ';
38778
+ }
38779
+ });
38780
+ if (_this.extractedText) {
38781
+ _this.onExtractText.emit(_this.extractedText);
38782
+ _this.addFieldNameToRectangle(docViewer, annotManager, Annotations);
38783
+ _this.holdDrawedRectangleCoordinates({
38784
+ width: widthRatio_1,
38785
+ height: heightRatio_1
38786
+ });
38787
+ }
38788
+ }
38789
+ });
38790
+ }
38791
+ };
38792
+ _this.initiateTextDimensions();
38793
+ _this.routerService.events.pipe(operators.takeUntil(_this.destroy$)).subscribe(function (res) {
38794
+ var _a;
38795
+ if (res instanceof i1$3.NavigationStart) {
38796
+ var _f = (_a = _this.pdfTronService) === null || _a === void 0 ? void 0 : _a.instance, annotManager = _f.annotManager, docViewer = _f.docViewer;
38797
+ annotManager.off('annotationChanged', _this.onAnnotationsChange);
38798
+ docViewer.off('documentLoaded', _this.enableAnnotationRectangle);
38799
+ }
38800
+ });
38801
+ return _this;
38802
+ }
38803
+ NdfTronExtractText.prototype.ngOnChanges = function (changes) {
38804
+ if (changes.focusedField || changes.pagesZones) {
38805
+ this.enableAnnotationRectangle();
38806
+ }
38807
+ };
38808
+ NdfTronExtractText.prototype.enableAnnotationRectangle = function () {
38809
+ var _a, _b, _c, _d, _e;
38810
+ if (this.focusedField && ((_a = this.pagesZones.pages) === null || _a === void 0 ? void 0 : _a.length)) {
38811
+ (_c = (_b = this.pdfTronService) === null || _b === void 0 ? void 0 : _b.instance) === null || _c === void 0 ? void 0 : _c.setToolMode('AnnotationCreateRectangle');
38812
+ this.focusedLabelDimensions = this.calculateWidthOfText();
38813
+ }
38814
+ else {
38815
+ (_e = (_d = this.pdfTronService) === null || _d === void 0 ? void 0 : _d.instance) === null || _e === void 0 ? void 0 : _e.setToolMode('TextSelect');
38816
+ this.initiateTextDimensions();
38817
+ }
38818
+ };
38819
+ NdfTronExtractText.prototype.ngAfterViewChecked = function () {
38820
+ var _a, _b;
38821
+ if (((_a = this.pdfTronService) === null || _a === void 0 ? void 0 : _a.instance) && !this.listnerAdded && this.pagesZones) {
38822
+ this.listnerAdded = true;
38823
+ var _f = (_b = this.pdfTronService) === null || _b === void 0 ? void 0 : _b.instance, annotManager = _f.annotManager, docViewer = _f.docViewer;
38824
+ docViewer.on('documentLoaded', this.enableAnnotationRectangle);
38825
+ this.setColorOfRectangle(docViewer);
38826
+ annotManager.on('annotationChanged', this.onAnnotationsChange);
38827
+ }
38828
+ };
38829
+ NdfTronExtractText.prototype.setColorOfRectangle = function (docViewer) {
38830
+ var rectangleTool = docViewer.getTool('AnnotationCreateRectangle');
38831
+ rectangleTool.defaults = {
38832
+ StrokeColor: this.detectionRectColor,
38833
+ FillColor: this.detectionRectColor,
38834
+ StrokeThickness: 2,
38835
+ Opacity: 0.4
38836
+ };
38837
+ };
38838
+ NdfTronExtractText.prototype.addFieldNameToRectangle = function (docViewer, annotManager, Annotations) {
38839
+ var _f = this.rect, x1 = _f.x1, x2 = _f.x2, y1 = _f.y1, y2 = _f.y2;
38840
+ if (this.focusedField) {
38841
+ var textAnnot = new Annotations.FreeTextAnnotation();
38842
+ textAnnot.PageNumber = docViewer.getCurrentPage();
38843
+ var rectWidth = x2 - x1;
38844
+ var rectHeight = y2 - y1;
38845
+ if (this.focusedLabelDimensions.width > rectWidth || this.focusedLabelDimensions.height > rectHeight) {
38846
+ textAnnot.X = x1;
38847
+ textAnnot.Y = y1 - 15;
38848
+ }
38849
+ else {
38850
+ textAnnot.X = x1 + rectWidth / 2 - this.focusedLabelDimensions.width / 2;
38851
+ textAnnot.Y = y1 + rectHeight / 2 - this.focusedLabelDimensions.height / 2;
38852
+ }
38853
+ textAnnot.Width = this.focusedLabelDimensions.width;
38854
+ textAnnot.Height = this.focusedLabelDimensions.height;
38855
+ textAnnot.FontSize = '24px';
38856
+ textAnnot.setPadding(new Annotations.Rect(0, 0, 0, 0));
38857
+ textAnnot.TextColor = new Annotations.Color(83, 70, 199);
38858
+ textAnnot.setContents(this.translatedLabel);
38859
+ textAnnot.StrokeThickness = 0;
38860
+ annotManager.addAnnotation(textAnnot);
38861
+ annotManager.redrawAnnotation(textAnnot);
38862
+ }
38863
+ };
38864
+ NdfTronExtractText.prototype.holdDrawedRectangleCoordinates = function (ratio) {
38865
+ var _this = this;
38866
+ var _windowCoordinates = {
38867
+ x1: ratio.width * this.rect.x1,
38868
+ x2: ratio.width * this.rect.x2,
38869
+ y1: ratio.height * this.rect.y1,
38870
+ y2: ratio.height * this.rect.y2
38871
+ };
38872
+ var index = this.savedCoordinates.findIndex(function (elem) { return elem.fieldName === _this.focusedField; });
38873
+ if (index > -1) {
38874
+ this.savedCoordinates[index].coordinates.push({
38875
+ pdfTronCoordinate: this.rect,
38876
+ windowCoordinate: _windowCoordinates
38877
+ });
38878
+ }
38879
+ else {
38880
+ this.savedCoordinates.push({
38881
+ fieldName: this.focusedField,
38882
+ coordinates: [
38883
+ {
38884
+ pdfTronCoordinate: this.rect,
38885
+ windowCoordinate: _windowCoordinates
38886
+ }
38887
+ ]
38888
+ });
38889
+ }
38890
+ };
38891
+ NdfTronExtractText.prototype.getAllWordsInThePage = function () {
38892
+ return _.flatMap(this.targetPage.zones, function (zone) { return _.flatMap(zone.paragraphs, function (paragraph) { return _.flatMap(paragraph.lines, function (line) { return _.map(line.words); }); }); });
38893
+ };
38894
+ NdfTronExtractText.prototype.initiateTextDimensions = function () {
38895
+ this.focusedLabelDimensions = { width: 0, height: 0 };
38896
+ };
38897
+ NdfTronExtractText.prototype.calculateWidthOfText = function () {
38898
+ var span = this.renderer.createElement('span');
38899
+ var textNode = this.renderer.createText(this.translatedLabel);
38900
+ this.renderer.appendChild(span, textNode);
38901
+ this.renderer.setStyle(span, 'font-size', '24px');
38902
+ this.renderer.setStyle(span, 'visibility', 'hidden');
38903
+ this.renderer.setStyle(span, 'position', 'absolute');
38904
+ this.renderer.appendChild(document.body, span);
38905
+ var dimensions = { width: span.clientWidth, height: span.clientHeight };
38906
+ this.renderer.removeChild(document.body, span);
38907
+ return dimensions;
38908
+ };
38909
+ Object.defineProperty(NdfTronExtractText.prototype, "translatedLabel", {
38910
+ get: function () {
38911
+ return this.translateService.instant(this.focusedFieldPrefix + this.focusedField);
38912
+ },
38913
+ enumerable: false,
38914
+ configurable: true
38915
+ });
38916
+ return NdfTronExtractText;
38917
+ }(BaseComponent));
38918
+ NdfTronExtractText.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NdfTronExtractText, deps: [{ token: PdftronService }, { token: i0__namespace.Renderer2 }, { token: i0__namespace.Injector }], target: i0__namespace.ɵɵFactoryTarget.Directive });
38919
+ NdfTronExtractText.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.17", type: NdfTronExtractText, selector: "[ndfTronExtractText]", inputs: { pagesZones: "pagesZones", detectionRectColor: "detectionRectColor", focusedField: "focusedField", focusedFieldPrefix: "focusedFieldPrefix" }, outputs: { onExtractText: "onExtractText" }, usesInheritance: true, usesOnChanges: true, ngImport: i0__namespace });
38920
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NdfTronExtractText, decorators: [{
38921
+ type: i0.Directive,
38922
+ args: [{
38923
+ selector: '[ndfTronExtractText]'
38924
+ }]
38925
+ }], ctorParameters: function () { return [{ type: PdftronService }, { type: i0__namespace.Renderer2 }, { type: i0__namespace.Injector }]; }, propDecorators: { pagesZones: [{
38926
+ type: i0.Input
38927
+ }], detectionRectColor: [{
38928
+ type: i0.Input
38929
+ }], focusedField: [{
38930
+ type: i0.Input
38931
+ }], focusedFieldPrefix: [{
38932
+ type: i0.Input
38933
+ }], onExtractText: [{
38934
+ type: i0.Output
38935
+ }] } });
38936
+
38737
38937
  var PdfTronModule = /** @class */ (function () {
38738
38938
  function PdfTronModule() {
38739
38939
  }
38740
38940
  return PdfTronModule;
38741
38941
  }());
38742
38942
  PdfTronModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: PdfTronModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
38743
- PdfTronModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: PdfTronModule, declarations: [PdftronComponent], imports: [i4.CommonModule], exports: [PdftronComponent] });
38744
- PdfTronModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: PdfTronModule, imports: [[
38745
- i4.CommonModule
38746
- ]] });
38943
+ PdfTronModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: PdfTronModule, declarations: [PdftronComponent, NdfTronExtractText], imports: [i4.CommonModule], exports: [PdftronComponent, NdfTronExtractText] });
38944
+ PdfTronModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: PdfTronModule, imports: [[i4.CommonModule]] });
38747
38945
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: PdfTronModule, decorators: [{
38748
38946
  type: i0.NgModule,
38749
38947
  args: [{
38750
- declarations: [PdftronComponent],
38751
- imports: [
38752
- i4.CommonModule
38753
- ],
38754
- exports: [
38755
- PdftronComponent
38756
- ]
38948
+ declarations: [PdftronComponent, NdfTronExtractText],
38949
+ imports: [i4.CommonModule],
38950
+ exports: [PdftronComponent, NdfTronExtractText]
38757
38951
  }]
38758
38952
  }] });
38759
38953
 
@@ -48810,6 +49004,7 @@
48810
49004
  exports.NdfTabsComponent = NdfTabsComponent;
48811
49005
  exports.NdfTabsModule = NdfTabsModule;
48812
49006
  exports.NdfTransformService = NdfTransformService;
49007
+ exports.NdfTronExtractText = NdfTronExtractText;
48813
49008
  exports.NgxHijriGregorianDatepickerModule = NgxHijriGregorianDatepickerModule;
48814
49009
  exports.NoDataComponent = NoDataComponent;
48815
49010
  exports.NoDataFoundComponent = NoDataFoundComponent;