nuxeo-development-framework 5.7.1 → 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.
@@ -38730,26 +38730,224 @@
38730
38730
  type: i0.Output
38731
38731
  }] } });
38732
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
+
38733
38937
  var PdfTronModule = /** @class */ (function () {
38734
38938
  function PdfTronModule() {
38735
38939
  }
38736
38940
  return PdfTronModule;
38737
38941
  }());
38738
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 });
38739
- 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] });
38740
- PdfTronModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: PdfTronModule, imports: [[
38741
- i4.CommonModule
38742
- ]] });
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]] });
38743
38945
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: PdfTronModule, decorators: [{
38744
38946
  type: i0.NgModule,
38745
38947
  args: [{
38746
- declarations: [PdftronComponent],
38747
- imports: [
38748
- i4.CommonModule
38749
- ],
38750
- exports: [
38751
- PdftronComponent
38752
- ]
38948
+ declarations: [PdftronComponent, NdfTronExtractText],
38949
+ imports: [i4.CommonModule],
38950
+ exports: [PdftronComponent, NdfTronExtractText]
38753
38951
  }]
38754
38952
  }] });
38755
38953
 
@@ -48806,6 +49004,7 @@
48806
49004
  exports.NdfTabsComponent = NdfTabsComponent;
48807
49005
  exports.NdfTabsModule = NdfTabsModule;
48808
49006
  exports.NdfTransformService = NdfTransformService;
49007
+ exports.NdfTronExtractText = NdfTronExtractText;
48809
49008
  exports.NgxHijriGregorianDatepickerModule = NgxHijriGregorianDatepickerModule;
48810
49009
  exports.NoDataComponent = NoDataComponent;
48811
49010
  exports.NoDataFoundComponent = NoDataFoundComponent;