@colijnit/sharedcomponents 259.1.7 → 259.1.8
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/358.645812766f7a400d0d38.js +1 -0
- package/3rdpartylicenses.txt +2017 -0
- package/719.eae3283e9de629a67fcc.js +1 -0
- package/977.bd6291f9ee6f6ddf91f1.js +1 -0
- package/bundles/colijnit-sharedcomponents.umd.js +121 -54
- package/bundles/colijnit-sharedcomponents.umd.js.map +1 -1
- package/colijnit-sharedcomponents.metadata.json +1 -1
- package/esm2015/lib/components/custom-pdf/custom-pdf-dialog.component.js +112 -48
- package/favicon.ico +0 -0
- package/fesm2015/colijnit-sharedcomponents.js +111 -47
- package/fesm2015/colijnit-sharedcomponents.js.map +1 -1
- package/index.html +12 -0
- package/lib/components/custom-pdf/custom-pdf-dialog.component.d.ts +3 -0
- package/main.987141ee790ebcd9f915.js +1 -0
- package/package.json +1 -1
- package/polyfills.907fe9d1887c5de17993.js +1 -0
- package/runtime.75ebd9b0a664565e2d37.js +1 -0
- package/styles.d0f69b6bddb7c4e48842.css +1 -0
|
@@ -3790,22 +3790,17 @@
|
|
|
3790
3790
|
this.additionalFileChangeEvent = new i0.EventEmitter();
|
|
3791
3791
|
this.signaturePads = {};
|
|
3792
3792
|
this.signatureCanvases = {};
|
|
3793
|
+
this.fileBody = '';
|
|
3794
|
+
this.fileStyle = '';
|
|
3793
3795
|
this.showLoader = false;
|
|
3796
|
+
// set to true if you want to skip email for debug purposes
|
|
3797
|
+
this.enableLocalPreview = false;
|
|
3794
3798
|
}
|
|
3795
3799
|
CustomPdfDialogComponent.prototype.showClass = function () {
|
|
3796
3800
|
return true;
|
|
3797
3801
|
};
|
|
3798
3802
|
CustomPdfDialogComponent.prototype.ngOnInit = function () {
|
|
3799
|
-
|
|
3800
|
-
var head = document.getElementsByTagName('head')[0];
|
|
3801
|
-
var styles = this.extractStyleParts(this.additionalFileContents);
|
|
3802
|
-
this.fileStyle = styles[0];
|
|
3803
|
-
var style = document.createElement('style');
|
|
3804
|
-
style.appendChild(document.createTextNode(this.fileStyle));
|
|
3805
|
-
head.appendChild(style);
|
|
3806
|
-
var body = this.extractBodyContents(this.additionalFileContents);
|
|
3807
|
-
this.fileBody = this._sanitizer.bypassSecurityTrustHtml(body[0]);
|
|
3808
|
-
}
|
|
3803
|
+
this._processAdditionalFileContents();
|
|
3809
3804
|
};
|
|
3810
3805
|
CustomPdfDialogComponent.prototype.ngAfterViewInit = function () {
|
|
3811
3806
|
var _this = this;
|
|
@@ -3848,108 +3843,180 @@
|
|
|
3848
3843
|
}
|
|
3849
3844
|
});
|
|
3850
3845
|
};
|
|
3846
|
+
CustomPdfDialogComponent.prototype._processAdditionalFileContents = function () {
|
|
3847
|
+
var _a;
|
|
3848
|
+
if (!this.additionalFileContents)
|
|
3849
|
+
return;
|
|
3850
|
+
var styles = this.extractStyleParts(this.additionalFileContents);
|
|
3851
|
+
this.fileStyle = styles.join('\n').trim();
|
|
3852
|
+
if (this.fileStyle) {
|
|
3853
|
+
var head = document.getElementsByTagName('head')[0];
|
|
3854
|
+
var styleEl = document.createElement('style');
|
|
3855
|
+
styleEl.appendChild(document.createTextNode(this.fileStyle));
|
|
3856
|
+
head.appendChild(styleEl);
|
|
3857
|
+
}
|
|
3858
|
+
var bodyParts = this.extractBodyContents(this.additionalFileContents);
|
|
3859
|
+
var bodyHtml = ((_a = bodyParts[0]) !== null && _a !== void 0 ? _a : this.removeStyleAndScriptTags(this.additionalFileContents)).trim();
|
|
3860
|
+
this.fileBody = this._sanitizer.bypassSecurityTrustHtml(bodyHtml);
|
|
3861
|
+
};
|
|
3851
3862
|
CustomPdfDialogComponent.prototype.extractStyleParts = function (html) {
|
|
3863
|
+
var _a;
|
|
3852
3864
|
var stylePattern = /<style[^>]*>([\s\S]*?)<\/style>/gi;
|
|
3853
3865
|
var matches = [];
|
|
3854
3866
|
var match;
|
|
3855
3867
|
while ((match = stylePattern.exec(html)) !== null) {
|
|
3856
|
-
matches.push(match[1].trim());
|
|
3868
|
+
matches.push(((_a = match[1]) !== null && _a !== void 0 ? _a : '').trim());
|
|
3857
3869
|
}
|
|
3858
3870
|
return matches;
|
|
3859
3871
|
};
|
|
3860
3872
|
CustomPdfDialogComponent.prototype.removeStyleAndScriptTags = function (html) {
|
|
3861
3873
|
var styleTagPattern = /<style[^>]*>[\s\S]*?<\/style>/gi;
|
|
3862
3874
|
var scriptTagPattern = /<script[^>]*>[\s\S]*?<\/script>/gi;
|
|
3863
|
-
return html.replace(styleTagPattern, '').replace(scriptTagPattern, '');
|
|
3875
|
+
return (html || '').replace(styleTagPattern, '').replace(scriptTagPattern, '');
|
|
3864
3876
|
};
|
|
3865
3877
|
CustomPdfDialogComponent.prototype.extractBodyContents = function (html) {
|
|
3878
|
+
var _a;
|
|
3866
3879
|
html = this.removeStyleAndScriptTags(html);
|
|
3867
|
-
var
|
|
3880
|
+
var bodyPattern = /<body[^>]*>([\s\S]*?)<\/body>/gi;
|
|
3868
3881
|
var matches = [];
|
|
3869
3882
|
var match;
|
|
3870
|
-
while ((match =
|
|
3871
|
-
matches.push(match[1].trim());
|
|
3883
|
+
while ((match = bodyPattern.exec(html)) !== null) {
|
|
3884
|
+
matches.push(((_a = match[1]) !== null && _a !== void 0 ? _a : '').trim());
|
|
3872
3885
|
}
|
|
3873
3886
|
return matches;
|
|
3874
3887
|
};
|
|
3888
|
+
CustomPdfDialogComponent.prototype._isLocalhost = function () {
|
|
3889
|
+
return ['localhost', '127.0.0.1', '::1'].includes(location.hostname);
|
|
3890
|
+
};
|
|
3875
3891
|
CustomPdfDialogComponent.prototype.handleSaveClicked = function () {
|
|
3892
|
+
var _a, _b;
|
|
3876
3893
|
return __awaiter(this, void 0, void 0, function () {
|
|
3877
|
-
var clearButton, doc,
|
|
3878
|
-
return __generator(this, function (
|
|
3879
|
-
switch (
|
|
3894
|
+
var clearButton, doc, createdTemp, root, html, parsed, allSections, leafSections, nodesToRender, pageWidth, pageHeight, _loop_1, i, blob, url, tempFile, file, fileAsCoDocument, e_1;
|
|
3895
|
+
return __generator(this, function (_c) {
|
|
3896
|
+
switch (_c.label) {
|
|
3880
3897
|
case 0:
|
|
3881
3898
|
this.showLoader = true;
|
|
3882
3899
|
clearButton = document.getElementById('clearButton');
|
|
3883
|
-
clearButton
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3900
|
+
if (clearButton)
|
|
3901
|
+
clearButton.hidden = true;
|
|
3902
|
+
doc = new jspdf.jsPDF({ unit: 'mm', format: 'a4' });
|
|
3903
|
+
createdTemp = false;
|
|
3904
|
+
root = ((_a = this.pdfBody) === null || _a === void 0 ? void 0 : _a.nativeElement) ||
|
|
3905
|
+
document.querySelector('#pdfBody');
|
|
3906
|
+
if (!root) {
|
|
3907
|
+
root = document.createElement('div');
|
|
3908
|
+
root.id = 'pdfBody';
|
|
3909
|
+
root.style.position = 'fixed';
|
|
3910
|
+
root.style.left = '-99999px';
|
|
3911
|
+
root.style.top = '0';
|
|
3912
|
+
root.style.width = '794px';
|
|
3913
|
+
root.style.pointerEvents = 'none';
|
|
3914
|
+
document.body.appendChild(root);
|
|
3915
|
+
createdTemp = true;
|
|
3916
|
+
}
|
|
3917
|
+
if (this.additionalFileContents && !root.hasChildNodes()) {
|
|
3918
|
+
html = String(this.additionalFileContents);
|
|
3919
|
+
if (html.includes('<html')) {
|
|
3920
|
+
parsed = new DOMParser().parseFromString(html, 'text/html');
|
|
3921
|
+
root.innerHTML = ((_b = parsed.body) === null || _b === void 0 ? void 0 : _b.innerHTML) || html;
|
|
3922
|
+
}
|
|
3923
|
+
else {
|
|
3924
|
+
root.innerHTML = html;
|
|
3925
|
+
}
|
|
3926
|
+
}
|
|
3927
|
+
allSections = Array.from(root.querySelectorAll('section'));
|
|
3928
|
+
leafSections = allSections.filter(function (s) { return !s.querySelector('section'); });
|
|
3929
|
+
nodesToRender = leafSections.length ? leafSections : (allSections.length ? allSections : [root]);
|
|
3930
|
+
pageWidth = doc.internal.pageSize.getWidth();
|
|
3931
|
+
pageHeight = doc.internal.pageSize.getHeight();
|
|
3888
3932
|
_loop_1 = function (i) {
|
|
3889
|
-
var
|
|
3890
|
-
return __generator(this, function (
|
|
3891
|
-
switch (
|
|
3933
|
+
var el, dataUrl_1, err_1;
|
|
3934
|
+
return __generator(this, function (_d) {
|
|
3935
|
+
switch (_d.label) {
|
|
3892
3936
|
case 0:
|
|
3893
|
-
|
|
3894
|
-
|
|
3937
|
+
el = nodesToRender[i];
|
|
3938
|
+
_d.label = 1;
|
|
3895
3939
|
case 1:
|
|
3896
|
-
|
|
3897
|
-
return [4 /*yield*/, htmlToImage.toJpeg(
|
|
3898
|
-
quality: 1,
|
|
3899
|
-
backgroundColor: 'white'
|
|
3900
|
-
})];
|
|
3940
|
+
_d.trys.push([1, 4, , 5]);
|
|
3941
|
+
return [4 /*yield*/, htmlToImage.toJpeg(el, { quality: 1, backgroundColor: 'white' })];
|
|
3901
3942
|
case 2:
|
|
3902
|
-
dataUrl_1 =
|
|
3903
|
-
img_1 = new Image();
|
|
3904
|
-
img_1.src = dataUrl_1;
|
|
3943
|
+
dataUrl_1 = _d.sent();
|
|
3905
3944
|
return [4 /*yield*/, new Promise(function (resolve) {
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
var
|
|
3909
|
-
|
|
3910
|
-
|
|
3945
|
+
var img = new Image();
|
|
3946
|
+
img.onload = function () {
|
|
3947
|
+
var w = img.width;
|
|
3948
|
+
var h = img.height;
|
|
3949
|
+
var scale = Math.min(pageWidth / w, pageHeight / h);
|
|
3950
|
+
var renderW = w * scale;
|
|
3951
|
+
var renderH = h * scale;
|
|
3952
|
+
doc.addImage(dataUrl_1, 'JPG', 0, 0, renderW, renderH);
|
|
3953
|
+
if (i < nodesToRender.length - 1)
|
|
3911
3954
|
doc.addPage();
|
|
3912
|
-
}
|
|
3913
3955
|
resolve();
|
|
3914
3956
|
};
|
|
3957
|
+
img.src = dataUrl_1;
|
|
3915
3958
|
})];
|
|
3916
3959
|
case 3:
|
|
3917
|
-
|
|
3960
|
+
_d.sent();
|
|
3918
3961
|
return [3 /*break*/, 5];
|
|
3919
3962
|
case 4:
|
|
3920
|
-
|
|
3921
|
-
console.error('Error generating image:',
|
|
3963
|
+
err_1 = _d.sent();
|
|
3964
|
+
console.error('Error generating image:', err_1);
|
|
3922
3965
|
return [3 /*break*/, 5];
|
|
3923
3966
|
case 5: return [2 /*return*/];
|
|
3924
3967
|
}
|
|
3925
3968
|
});
|
|
3926
3969
|
};
|
|
3927
3970
|
i = 0;
|
|
3928
|
-
|
|
3971
|
+
_c.label = 1;
|
|
3929
3972
|
case 1:
|
|
3930
|
-
if (!(i <
|
|
3973
|
+
if (!(i < nodesToRender.length)) return [3 /*break*/, 4];
|
|
3931
3974
|
return [5 /*yield**/, _loop_1(i)];
|
|
3932
3975
|
case 2:
|
|
3933
|
-
|
|
3934
|
-
|
|
3976
|
+
_c.sent();
|
|
3977
|
+
_c.label = 3;
|
|
3935
3978
|
case 3:
|
|
3936
3979
|
i++;
|
|
3937
3980
|
return [3 /*break*/, 1];
|
|
3938
3981
|
case 4:
|
|
3982
|
+
if (createdTemp && root && root.parentNode) {
|
|
3983
|
+
root.parentNode.removeChild(root);
|
|
3984
|
+
}
|
|
3985
|
+
// enableLocalPreview can be enabled to see the output without sending email
|
|
3986
|
+
if (this.enableLocalPreview && this._isLocalhost()) {
|
|
3987
|
+
blob = doc.output('blob');
|
|
3988
|
+
url = URL.createObjectURL(blob);
|
|
3989
|
+
window.open(url, '_blank');
|
|
3990
|
+
this.showLoader = false;
|
|
3991
|
+
if (clearButton)
|
|
3992
|
+
clearButton.hidden = false;
|
|
3993
|
+
return [2 /*return*/];
|
|
3994
|
+
}
|
|
3995
|
+
_c.label = 5;
|
|
3996
|
+
case 5:
|
|
3997
|
+
_c.trys.push([5, 7, 8, 9]);
|
|
3939
3998
|
tempFile = doc.output('datauristring');
|
|
3940
3999
|
file = this.dataURItoBlob(tempFile);
|
|
3941
4000
|
return [4 /*yield*/, fileUtils.FileUtils.ReadFileAsNewCoDocument(file)];
|
|
3942
|
-
case
|
|
3943
|
-
fileAsCoDocument =
|
|
4001
|
+
case 6:
|
|
4002
|
+
fileAsCoDocument = _c.sent();
|
|
3944
4003
|
fileAsCoDocument.fileType = fileUtils.FileUtils.IsImageFile(file) ? fileType_enum.FileType.Image : fileType_enum.FileType.Document;
|
|
3945
4004
|
fileAsCoDocument.creationDate = new Date();
|
|
3946
4005
|
fileAsCoDocument.modifiedDate = new Date();
|
|
3947
4006
|
fileAsCoDocument.reports = 1;
|
|
3948
4007
|
this.additionalFileChangeEvent.emit(fileAsCoDocument);
|
|
4008
|
+
return [3 /*break*/, 9];
|
|
4009
|
+
case 7:
|
|
4010
|
+
e_1 = _c.sent();
|
|
4011
|
+
console.error('PDF packaging failed:', e_1);
|
|
4012
|
+
return [3 /*break*/, 9];
|
|
4013
|
+
case 8:
|
|
3949
4014
|
this.showLoader = false;
|
|
3950
4015
|
this.closePDFDialog.emit();
|
|
3951
|
-
clearButton
|
|
3952
|
-
|
|
4016
|
+
if (clearButton)
|
|
4017
|
+
clearButton.hidden = false;
|
|
4018
|
+
return [7 /*endfinally*/];
|
|
4019
|
+
case 9: return [2 /*return*/];
|
|
3953
4020
|
}
|
|
3954
4021
|
});
|
|
3955
4022
|
});
|
|
@@ -3981,7 +4048,7 @@
|
|
|
3981
4048
|
CustomPdfDialogComponent.decorators = [
|
|
3982
4049
|
{ type: i0.Component, args: [{
|
|
3983
4050
|
selector: 'co-custom-pdf-dialog',
|
|
3984
|
-
template: "\n <co-dialog\n [footerTemplate]=\"footerTemplate\"\n id=\"custom-pdf-dialog\"\n (closeClick)=\"closePDFDialog.emit()\">\n <!-- create a nice container for loader so it is not random in the corner somewhere -->\n <div *ngIf=\"showLoader\" class=\"loader-container\">\n <co-loader *ngIf=\"showLoader\"></co-loader>\n </div>\n
|
|
4051
|
+
template: "\n <co-dialog\n [footerTemplate]=\"footerTemplate\"\n id=\"custom-pdf-dialog\"\n (closeClick)=\"closePDFDialog.emit()\">\n <!-- create a nice container for loader so it is not random in the corner somewhere -->\n <div *ngIf=\"showLoader\" class=\"loader-container\">\n <co-loader *ngIf=\"showLoader\"></co-loader>\n </div>\n\n <div #pdfBody id=\"pdfBody\">\n <section [innerHTML]=\"fileBody\"></section>\n </div>\n <ng-template #footerTemplate>\n <div class=\"co-dialog-footer-button-wrapper\">\n <co-button class=\"save-button\"\n [iconData]=\"iconCacheService.getIcon(icons.CheckDuotone)\"\n (click)=\"handleSaveClicked()\"></co-button>\n <co-button class=\"close-button\"\n [iconData]=\"iconCacheService.getIcon(icons.CrossSkinny)\"\n (click)=\"closePDFDialog.emit()\"></co-button>\n </div>\n </ng-template>\n </co-dialog>\n ",
|
|
3985
4052
|
encapsulation: i0.ViewEncapsulation.None
|
|
3986
4053
|
},] }
|
|
3987
4054
|
];
|