ngx-print 1.4.0 → 1.5.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.
@@ -2,15 +2,15 @@ import { NgModule } from '@angular/core';
2
2
  import { NgxPrintDirective } from './ngx-print.directive';
3
3
  import * as i0 from "@angular/core";
4
4
  export class NgxPrintModule {
5
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgxPrintModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
6
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: NgxPrintModule, imports: [NgxPrintDirective], exports: [NgxPrintDirective] });
7
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgxPrintModule });
5
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
6
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintModule, imports: [NgxPrintDirective], exports: [NgxPrintDirective] });
7
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintModule });
8
8
  }
9
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgxPrintModule, decorators: [{
9
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintModule, decorators: [{
10
10
  type: NgModule,
11
11
  args: [{
12
12
  imports: [NgxPrintDirective],
13
13
  exports: [NgxPrintDirective]
14
14
  }]
15
15
  }] });
16
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmd4LXByaW50Lm1vZHVsZS5q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UsUUFBUSxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBQ3pDLE9BQU8sRUFBRSxpQkFBaUIsRUFBRSxNQUFNLHVCQUF1QixDQUFDOztBQU0xRCxNQUFNLE9BQU8sY0FBYzt1R0FBZCxjQUFjO3dHQUFkLGNBQWMsWUFIZixpQkFBaUIsYUFDakIsaUJBQWlCO3dHQUVoQixjQUFjOzsyRkFBZCxjQUFjO2tCQUoxQixRQUFRO21CQUFDO29CQUNSLE9BQU8sRUFBRSxDQUFDLGlCQUFpQixDQUFDO29CQUM1QixPQUFPLEVBQUUsQ0FBQyxpQkFBaUIsQ0FBQztpQkFDN0IiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBOZ01vZHVsZSB9IGZyb20gJ0Bhbmd1bGFyL2NvcmUnO1xyXG5pbXBvcnQgeyBOZ3hQcmludERpcmVjdGl2ZSB9IGZyb20gJy4vbmd4LXByaW50LmRpcmVjdGl2ZSc7XHJcblxyXG5ATmdNb2R1bGUoe1xyXG4gIGltcG9ydHM6IFtOZ3hQcmludERpcmVjdGl2ZV0sXHJcbiAgZXhwb3J0czogW05neFByaW50RGlyZWN0aXZlXVxyXG59KVxyXG5leHBvcnQgY2xhc3MgTmd4UHJpbnRNb2R1bGUgeyB9XHJcbiJdfQ==
@@ -0,0 +1,53 @@
1
+ import { Injectable } from "@angular/core";
2
+ import { PrintBase } from "./ngx-print.base";
3
+ import * as i0 from "@angular/core";
4
+ /**
5
+ * Service for handling printing functionality in Angular applications.
6
+ * Extends the base printing class (PrintBase).
7
+ *
8
+ * @export
9
+ * @class NgxPrintService
10
+ * @extends {PrintBase}
11
+ */
12
+ export class NgxPrintService extends PrintBase {
13
+ /**
14
+ * Initiates the printing process using the provided print options.
15
+ *
16
+ * @param {PrintOptions} printOptions - Options for configuring the printing process.
17
+ * @memberof NgxPrintService
18
+ * @returns {void}
19
+ */
20
+ print(printOptions) {
21
+ // Call the print method in the parent class
22
+ super.print(printOptions);
23
+ }
24
+ /**
25
+ * Sets the print style for the printing process.
26
+ *
27
+ * @param {{ [key: string]: { [key: string]: string } }} values - A dictionary representing the print styles.
28
+ * @memberof NgxPrintService
29
+ * @setter
30
+ */
31
+ set printStyle(values) {
32
+ super.setPrintStyle(values);
33
+ }
34
+ /**
35
+ * Sets the stylesheet file for the printing process.
36
+ *
37
+ * @param {string} cssList - A string representing the path to the stylesheet file.
38
+ * @memberof NgxPrintService
39
+ * @setter
40
+ */
41
+ set styleSheetFile(cssList) {
42
+ super.setStyleSheetFile(cssList);
43
+ }
44
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
45
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintService, providedIn: "root" });
46
+ }
47
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintService, decorators: [{
48
+ type: Injectable,
49
+ args: [{
50
+ providedIn: "root",
51
+ }]
52
+ }] });
53
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmd4LXByaW50LnNlcnZpY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvbGliL25neC1wcmludC5zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDM0MsT0FBTyxFQUFFLFNBQVMsRUFBRSxNQUFNLGtCQUFrQixDQUFDOztBQUc3Qzs7Ozs7OztHQU9HO0FBSUgsTUFBTSxPQUFPLGVBQWdCLFNBQVEsU0FBUztJQUU1Qzs7Ozs7O09BTUc7SUFDSSxLQUFLLENBQUMsWUFBMEI7UUFDckMsNENBQTRDO1FBQzVDLEt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lxyXG4gICAqXHJcbiAgICogQHBhcmFtIHtzdHJpbmd9IGNzc0xpc3QgLSBBIHN0cmluZyByZXByZXNlbnRpbmcgdGhlIHBhdGggdG8gdGhlIHN0eWxlc2hlZXQgZmlsZS5cclxuICAgKiBAbWVtYmVyb2YgTmd4UHJpbnRTZXJ2aWNlXHJcbiAgICogQHNldHRlclxyXG4gICAqL1xyXG4gIHNldCBzdHlsZVNoZWV0RmlsZShjc3NMaXN0OiBzdHJpbmcpIHtcclxuICAgIHN1cGVyLnNldFN0eWxlU2hlZXRGaWxlKGNzc0xpc3QpO1xyXG4gIH1cclxufVxyXG4iXX0=
@@ -0,0 +1,16 @@
1
+ export class PrintOptions {
2
+ printSectionId = null;
3
+ printTitle = null;
4
+ useExistingCss = false;
5
+ bodyClass = '';
6
+ openNewTab = false;
7
+ previewOnly = false;
8
+ closeWindow = true;
9
+ printDelay = 0;
10
+ constructor(options) {
11
+ if (options) {
12
+ Object.assign(this, options);
13
+ }
14
+ }
15
+ }
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJpbnQtb3B0aW9ucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9saWIvcHJpbnQtb3B0aW9ucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLE9BQU8sWUFBWTtJQUN2QixjQUFjLEdBQVcsSUFBSSxDQUFDO0lBQzlCLFVBQVUsR0FBVyxJQUFJLENBQUM7SUFDMUIsY0FBYyxHQUFZLEtBQUssQ0FBQztJQUNoQyxTQUFTLEdBQVcsRUFBRSxDQUFDO0lBQ3ZCLFVBQVUsR0FBWSxLQUFLLENBQUM7SUFDNUIsV0FBVyxHQUFZLEtBQUssQ0FBQztJQUM3QixXQUFXLEdBQVksSUFBSSxDQUFDO0lBQzVCLFVBQVUsR0FBVyxDQUFDLENBQUM7SUFFdkIsWUFBWSxPQUErQjtRQUN6QyxJQUFJLE9BQU8sRUFBRTtZQUNYLE1BQU0sQ0FBQyxNQUFNLENBQUMsSUFBSSxFQUFFLE9BQU8sQ0FBQyxDQUFDO1NBQzlCO0lBQ0gsQ0FBQztDQUNGIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGNsYXNzIFByaW50T3B0aW9ucyB7XHJcbiAgcHJpbnRTZWN0aW9uSWQ6IHN0cmluZyA9IG51bGw7XHJcbiAgcHJpbnRUaXRsZTogc3RyaW5nID0gbnVsbDtcclxuICB1c2VFeGlzdGluZ0NzczogYm9vbGVhbiA9IGZhbHNlO1xyXG4gIGJvZHlDbGFzczogc3RyaW5nID0gJyc7XHJcbiAgb3Blbk5ld1RhYjogYm9vbGVhbiA9IGZhbHNlO1xyXG4gIHByZXZpZXdPbmx5OiBib29sZWFuID0gZmFsc2U7XHJcbiAgY2xvc2VXaW5kb3c6IGJvb2xlYW4gPSB0cnVlO1xyXG4gIHByaW50RGVsYXk6IG51bWJlciA9IDA7XHJcblxyXG4gIGNvbnN0cnVjdG9yKG9wdGlvbnM/OiBQYXJ0aWFsPFByaW50T3B0aW9ucz4pIHtcclxuICAgIGlmIChvcHRpb25zKSB7XHJcbiAgICAgIE9iamVjdC5hc3NpZ24odGhpcywgb3B0aW9ucyk7XHJcbiAgICB9XHJcbiAgfVxyXG59XHJcbiJdfQ==
@@ -1,6 +1,8 @@
1
1
  /*
2
2
  * Public API Surface of ngx-print
3
3
  */
4
+ export * from './lib/ngx-print.service';
4
5
  export * from './lib/ngx-print.directive';
5
6
  export * from './lib/ngx-print.module';
6
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljX2FwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wdWJsaWNfYXBpLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBRUgsY0FBYywyQkFBMkIsQ0FBQztBQUMxQyxjQUFjLHdCQUF3QixDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLypcclxuICogUHVibGljIEFQSSBTdXJmYWNlIG9mIG5neC1wcmludFxyXG4gKi9cclxuXHJcbmV4cG9ydCAqIGZyb20gJy4vbGliL25neC1wcmludC5kaXJlY3RpdmUnO1xyXG5leHBvcnQgKiBmcm9tICcuL2xpYi9uZ3gtcHJpbnQubW9kdWxlJztcclxuIl19
7
+ export * from './lib/print-options';
8
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljX2FwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wdWJsaWNfYXBpLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsY0FBYyx5QkFBeUIsQ0FBQztBQUN4QyxjQUFjLDJCQUEyQixDQUFDO0FBQzFDLGNBQWMsd0JBQXdCLENBQUM7QUFDdkMsY0FBYyxxQkFBcUIsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qXHJcbiAqIFB1YmxpYyBBUEkgU3VyZmFjZSBvZiBuZ3gtcHJpbnRcclxuICovXHJcbmV4cG9ydCAqIGZyb20gJy4vbGliL25neC1wcmludC5zZXJ2aWNlJztcclxuZXhwb3J0ICogZnJvbSAnLi9saWIvbmd4LXByaW50LmRpcmVjdGl2ZSc7XHJcbmV4cG9ydCAqIGZyb20gJy4vbGliL25neC1wcmludC5tb2R1bGUnO1xyXG5leHBvcnQgKiBmcm9tICcuL2xpYi9wcmludC1vcHRpb25zJztcclxuIl19
@@ -1,60 +1,23 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Directive, Input, HostListener, NgModule } from '@angular/core';
2
+ import { Injectable, Directive, Input, HostListener, NgModule } from '@angular/core';
3
3
 
4
- class NgxPrintDirective {
4
+ class PrintBase {
5
5
  _printStyle = [];
6
+ _styleSheetFile = '';
7
+ //#region Getters and Setters
6
8
  /**
7
- * Prevents the print dialog from opening on the window
8
- *
9
- * @memberof NgxPrintDirective
10
- */
11
- previewOnly = false;
12
- /**
13
- *
14
- *
15
- * @memberof NgxPrintDirective
16
- */
17
- printSectionId;
18
- /**
19
- *
20
- *
21
- * @memberof NgxPrintDirective
22
- */
23
- printTitle;
24
- /**
25
- *
26
- *
27
- * @memberof NgxPrintDirective
28
- */
29
- useExistingCss = false;
30
- /**
31
- * A delay in milliseconds to force the print dialog to wait before opened. Default: 0
32
- *
33
- * @memberof NgxPrintDirective
34
- */
35
- printDelay = 0;
36
- /**
37
- * Whether to close the window after print() returns.
38
- *
39
- */
40
- closeWindow = true;
41
- /**
42
- * Class attribute to apply to the body element.
43
- *
44
- */
45
- bodyClass = '';
46
- /**
9
+ * Sets the print styles based on the provided values.
47
10
  *
48
- *
49
- * @memberof NgxPrintDirective
11
+ * @param {Object} values - Key-value pairs representing print styles.
12
+ * @protected
50
13
  */
51
- set printStyle(values) {
14
+ setPrintStyle(values) {
15
+ this._printStyle = [];
52
16
  for (let key in values) {
53
17
  if (values.hasOwnProperty(key)) {
54
18
  this._printStyle.push((key + JSON.stringify(values[key])).replace(/['"]+/g, ''));
55
19
  }
56
20
  }
57
- this.returnStyleValues();
58
21
  }
59
22
  /**
60
23
  *
@@ -63,62 +26,44 @@ class NgxPrintDirective {
63
26
  * later within <style></style> tag.
64
27
  *
65
28
  * -join/replace to transform an array objects to css-styled string
66
- *
67
- * @memberof NgxPrintDirective
68
29
  */
69
30
  returnStyleValues() {
70
31
  return `<style> ${this._printStyle.join(' ').replace(/,/g, ';')} </style>`;
71
32
  }
72
33
  /**
73
- *
74
- *
75
- * @returns html for the given tag
76
- *
77
- * @memberof NgxPrintDirective
78
- */
79
- _styleSheetFile = '';
34
+ * @returns string which contains the link tags containing the css which will
35
+ * be injected later within <head></head> tag.
36
+ *
37
+ */
38
+ returnStyleSheetLinkTags() {
39
+ return this._styleSheetFile;
40
+ }
80
41
  /**
81
- * @memberof NgxPrintDirective
82
- * @param cssList
42
+ * Sets the style sheet file based on the provided CSS list.
43
+ *
44
+ * @param {string} cssList - CSS file or list of CSS files.
45
+ * @protected
83
46
  */
84
- set styleSheetFile(cssList) {
47
+ setStyleSheetFile(cssList) {
85
48
  let linkTagFn = function (cssFileName) {
86
49
  return `<link rel="stylesheet" type="text/css" href="${cssFileName}">`;
87
50
  };
88
51
  if (cssList.indexOf(',') !== -1) {
89
52
  const valueArr = cssList.split(',');
90
- for (let val of valueArr) {
91
- this._styleSheetFile = this._styleSheetFile + linkTagFn(val);
92
- }
53
+ this._styleSheetFile = valueArr.map(val => linkTagFn(val)).join('');
93
54
  }
94
55
  else {
95
56
  this._styleSheetFile = linkTagFn(cssList);
96
57
  }
97
58
  }
59
+ //#endregion
60
+ //#region Private methods used by PrintBase
98
61
  /**
99
- * @returns string which contains the link tags containing the css which will
100
- * be injected later within <head></head> tag.
62
+ * Updates the default values for input elements.
101
63
  *
64
+ * @param {HTMLCollectionOf<HTMLInputElement>} elements - Collection of input elements.
65
+ * @private
102
66
  */
103
- returnStyleSheetLinkTags() {
104
- return this._styleSheetFile;
105
- }
106
- getElementTag(tag) {
107
- const html = [];
108
- const elements = document.getElementsByTagName(tag);
109
- for (let index = 0; index < elements.length; index++) {
110
- html.push(elements[index].outerHTML);
111
- }
112
- return html.join('\r\n');
113
- }
114
- /**
115
- *
116
- * @description When printing, the default option of form elements are printed.
117
- * Here we update what that default is to print the current values.
118
- *
119
- * @param elements the html element collection to save defaults to
120
- *
121
- */
122
67
  updateInputDefaults(elements) {
123
68
  for (let i = 0; i < elements.length; i++) {
124
69
  const element = elements[i];
@@ -127,6 +72,12 @@ class NgxPrintDirective {
127
72
  element['defaultChecked'] = true;
128
73
  }
129
74
  }
75
+ /**
76
+ * Updates the default values for select elements.
77
+ *
78
+ * @param {HTMLCollectionOf<HTMLSelectElement>} elements - Collection of select elements.
79
+ * @private
80
+ */
130
81
  updateSelectDefaults(elements) {
131
82
  for (let i = 0; i < elements.length; i++) {
132
83
  const element = elements[i];
@@ -135,6 +86,12 @@ class NgxPrintDirective {
135
86
  selectedOption.defaultSelected = true;
136
87
  }
137
88
  }
89
+ /**
90
+ * Updates the default values for textarea elements.
91
+ *
92
+ * @param {HTMLCollectionOf<HTMLTextAreaElement>} elements - Collection of textarea elements.
93
+ * @private
94
+ */
138
95
  updateTextAreaDefaults(elements) {
139
96
  for (let i = 0; i < elements.length; i++) {
140
97
  const element = elements[i];
@@ -142,71 +99,291 @@ class NgxPrintDirective {
142
99
  }
143
100
  }
144
101
  /**
145
- * @description Retrieves the html contents of the print section id.
146
- * Updates the html elements to default their form values to the current form values
102
+ * Converts a canvas element to an image and returns its HTML string.
147
103
  *
148
- * @returns {string | null} html section to be printed
104
+ * @param {HTMLCanvasElement} element - The canvas element to convert.
105
+ * @returns {string} - HTML string of the image.
106
+ * @private
107
+ */
108
+ canvasToImageHtml(element) {
109
+ const dataUrl = element.toDataURL();
110
+ return `<img src="${dataUrl}" style="max-width: 100%;">`;
111
+ }
112
+ /**
113
+ * Includes canvas contents in the print section via img tags.
114
+ *
115
+ * @param {HTMLCollectionOf<HTMLCanvasElement>} elements - Collection of canvas elements.
116
+ * @private
117
+ */
118
+ updateCanvasToImage(elements) {
119
+ for (let i = 0; i < elements.length; i++) {
120
+ const element = this.canvasToImageHtml(elements[i]);
121
+ elements[i].insertAdjacentHTML('afterend', element);
122
+ elements[i].remove();
123
+ }
124
+ }
125
+ /**
126
+ * Retrieves the HTML content of a specified printing section.
149
127
  *
128
+ * @param {string} printSectionId - Id of the printing section.
129
+ * @returns {string | null} - HTML content of the printing section, or null if not found.
130
+ * @private
150
131
  */
151
- getHtmlContents() {
152
- const printContents = document.getElementById(this.printSectionId);
132
+ getHtmlContents(printSectionId) {
133
+ const printContents = document.getElementById(printSectionId);
153
134
  if (!printContents)
154
135
  return null;
155
136
  const inputEls = printContents.getElementsByTagName('input');
156
137
  const selectEls = printContents.getElementsByTagName('select');
157
138
  const textAreaEls = printContents.getElementsByTagName('textarea');
139
+ const canvasEls = printContents.getElementsByTagName('canvas');
158
140
  this.updateInputDefaults(inputEls);
159
141
  this.updateSelectDefaults(selectEls);
160
142
  this.updateTextAreaDefaults(textAreaEls);
143
+ this.updateCanvasToImage(canvasEls);
161
144
  return printContents.innerHTML;
162
145
  }
163
146
  /**
147
+ * Retrieves the HTML content of elements with the specified tag.
164
148
  *
149
+ * @param {keyof HTMLElementTagNameMap} tag - HTML tag name.
150
+ * @returns {string} - Concatenated outerHTML of elements with the specified tag.
151
+ * @private
152
+ */
153
+ getElementTag(tag) {
154
+ const html = [];
155
+ const elements = document.getElementsByTagName(tag);
156
+ for (let index = 0; index < elements.length; index++) {
157
+ html.push(elements[index].outerHTML);
158
+ }
159
+ return html.join('\r\n');
160
+ }
161
+ //#endregion
162
+ /**
163
+ * Prints the specified content using the provided print options.
165
164
  *
166
- * @memberof NgxPrintDirective
165
+ * @param {PrintOptions} printOptions - Options for printing.
166
+ * @public
167
167
  */
168
- print() {
169
- let printContents, popupWin, styles = '', links = '';
168
+ print(printOptions) {
169
+ let styles = '', links = '', popOut = 'top=0,left=0,height=auto,width=auto';
170
170
  const baseTag = this.getElementTag('base');
171
- if (this.useExistingCss) {
171
+ if (printOptions.useExistingCss) {
172
172
  styles = this.getElementTag('style');
173
173
  links = this.getElementTag('link');
174
174
  }
175
- printContents = this.getHtmlContents();
176
- popupWin = window.open("", "_blank", "top=0,left=0,height=auto,width=auto");
175
+ // If the openNewTab option is set to true, then set the popOut option to an empty string.
176
+ // This will cause the print dialog to open in a new tab.
177
+ if (printOptions.openNewTab) {
178
+ popOut = '';
179
+ }
180
+ const printContents = this.getHtmlContents(printOptions.printSectionId);
181
+ if (!printContents) {
182
+ // Handle the case where the specified print section is not found.
183
+ console.error(`Print section with id ${printOptions.printSectionId} not found.`);
184
+ return;
185
+ }
186
+ const popupWin = window.open("", "_blank", popOut);
187
+ if (!popupWin) {
188
+ // the popup window could not be opened.
189
+ console.error('Could not open print window.');
190
+ return;
191
+ }
177
192
  popupWin.document.open();
178
193
  popupWin.document.write(`
179
- <html>
180
- <head>
181
- <title>${this.printTitle ? this.printTitle : ""}</title>
182
- ${baseTag}
183
- ${this.returnStyleValues()}
184
- ${this.returnStyleSheetLinkTags()}
185
- ${styles}
186
- ${links}
187
- </head>
188
- <body ${this.bodyClass ? `class="${this.bodyClass}"` : ''}>
189
- ${printContents}
190
- <script defer>
191
- function triggerPrint(event) {
192
- window.removeEventListener('load', triggerPrint, false);
193
- ${this.previewOnly || !this.closeWindow ? '' : `setTimeout(function() {
194
- closeWindow(window.print());
195
- }, ${this.printDelay});`}
196
- }
197
- function closeWindow(){
198
- window.close();
199
- }
200
- window.addEventListener('load', triggerPrint, false);
201
- </script>
202
- </body>
203
- </html>`);
194
+ <html>
195
+ <head>
196
+ <title>${printOptions.printTitle ? printOptions.printTitle : ""}</title>
197
+ ${baseTag}
198
+ ${this.returnStyleValues()}
199
+ ${this.returnStyleSheetLinkTags()}
200
+ ${styles}
201
+ ${links}
202
+ </head>
203
+ <body ${printOptions.bodyClass ? `class="${printOptions.bodyClass}"` : ''}>
204
+ ${printContents}
205
+ <script defer>
206
+ function triggerPrint(event) {
207
+ window.removeEventListener('load', triggerPrint, false);
208
+ ${printOptions.previewOnly ? '' : `setTimeout(function() {
209
+ closeWindow(window.print());
210
+ }, ${printOptions.printDelay});`}
211
+ }
212
+ function closeWindow(){
213
+ ${printOptions.closeWindow ? 'window.close();' : ''}
214
+ }
215
+ window.addEventListener('load', triggerPrint, false);
216
+ </script>
217
+ </body>
218
+ </html>`);
204
219
  popupWin.document.close();
205
220
  }
206
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgxPrintDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
207
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: NgxPrintDirective, isStandalone: true, selector: "button[ngxPrint]", inputs: { previewOnly: "previewOnly", printSectionId: "printSectionId", printTitle: "printTitle", useExistingCss: "useExistingCss", printDelay: "printDelay", closeWindow: "closeWindow", bodyClass: "bodyClass", printStyle: "printStyle", styleSheetFile: "styleSheetFile" }, host: { listeners: { "click": "print()" } }, ngImport: i0 });
221
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: PrintBase, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
222
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: PrintBase, providedIn: 'root' });
223
+ }
224
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: PrintBase, decorators: [{
225
+ type: Injectable,
226
+ args: [{
227
+ providedIn: 'root'
228
+ }]
229
+ }] });
230
+
231
+ /**
232
+ * Service for handling printing functionality in Angular applications.
233
+ * Extends the base printing class (PrintBase).
234
+ *
235
+ * @export
236
+ * @class NgxPrintService
237
+ * @extends {PrintBase}
238
+ */
239
+ class NgxPrintService extends PrintBase {
240
+ /**
241
+ * Initiates the printing process using the provided print options.
242
+ *
243
+ * @param {PrintOptions} printOptions - Options for configuring the printing process.
244
+ * @memberof NgxPrintService
245
+ * @returns {void}
246
+ */
247
+ print(printOptions) {
248
+ // Call the print method in the parent class
249
+ super.print(printOptions);
250
+ }
251
+ /**
252
+ * Sets the print style for the printing process.
253
+ *
254
+ * @param {{ [key: string]: { [key: string]: string } }} values - A dictionary representing the print styles.
255
+ * @memberof NgxPrintService
256
+ * @setter
257
+ */
258
+ set printStyle(values) {
259
+ super.setPrintStyle(values);
260
+ }
261
+ /**
262
+ * Sets the stylesheet file for the printing process.
263
+ *
264
+ * @param {string} cssList - A string representing the path to the stylesheet file.
265
+ * @memberof NgxPrintService
266
+ * @setter
267
+ */
268
+ set styleSheetFile(cssList) {
269
+ super.setStyleSheetFile(cssList);
270
+ }
271
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
272
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintService, providedIn: "root" });
273
+ }
274
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintService, decorators: [{
275
+ type: Injectable,
276
+ args: [{
277
+ providedIn: "root",
278
+ }]
279
+ }] });
280
+
281
+ class PrintOptions {
282
+ printSectionId = null;
283
+ printTitle = null;
284
+ useExistingCss = false;
285
+ bodyClass = '';
286
+ openNewTab = false;
287
+ previewOnly = false;
288
+ closeWindow = true;
289
+ printDelay = 0;
290
+ constructor(options) {
291
+ if (options) {
292
+ Object.assign(this, options);
293
+ }
294
+ }
208
295
  }
209
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgxPrintDirective, decorators: [{
296
+
297
+ class NgxPrintDirective extends PrintBase {
298
+ printOptions = new PrintOptions();
299
+ /**
300
+ * Prevents the print dialog from opening on the window
301
+ *
302
+ * @memberof NgxPrintDirective
303
+ */
304
+ set previewOnly(value) {
305
+ this.printOptions = { ...this.printOptions, previewOnly: value };
306
+ }
307
+ /**
308
+ *
309
+ *
310
+ * @memberof NgxPrintDirective
311
+ */
312
+ set printSectionId(value) {
313
+ this.printOptions = { ...this.printOptions, printSectionId: value };
314
+ }
315
+ /**
316
+ *
317
+ *
318
+ * @memberof NgxPrintDirective
319
+ */
320
+ set printTitle(value) {
321
+ this.printOptions = { ...this.printOptions, printTitle: value };
322
+ }
323
+ /**
324
+ *
325
+ *
326
+ * @memberof NgxPrintDirective
327
+ */
328
+ set useExistingCss(value) {
329
+ this.printOptions = { ...this.printOptions, useExistingCss: value };
330
+ }
331
+ /**
332
+ * A delay in milliseconds to force the print dialog to wait before opened. Default: 0
333
+ *
334
+ * @memberof NgxPrintDirective
335
+ */
336
+ set printDelay(value) {
337
+ this.printOptions = { ...this.printOptions, printDelay: value };
338
+ }
339
+ /**
340
+ * Whether to close the window after print() returns.
341
+ *
342
+ */
343
+ set closeWindow(value) {
344
+ this.printOptions = { ...this.printOptions, closeWindow: value };
345
+ }
346
+ /**
347
+ * Class attribute to apply to the body element.
348
+ *
349
+ */
350
+ set bodyClass(value) {
351
+ this.printOptions = { ...this.printOptions, bodyClass: value };
352
+ }
353
+ /**
354
+ * Whether to open a new window or default to new window.
355
+ *
356
+ */
357
+ set openNewTab(value) {
358
+ this.printOptions = { ...this.printOptions, openNewTab: value };
359
+ }
360
+ /**
361
+ *
362
+ *
363
+ * @memberof NgxPrintDirective
364
+ */
365
+ set printStyle(values) {
366
+ super.setPrintStyle(values);
367
+ }
368
+ /**
369
+ * @memberof NgxPrintDirective
370
+ * @param cssList
371
+ */
372
+ set styleSheetFile(cssList) {
373
+ super.setStyleSheetFile(cssList);
374
+ }
375
+ /**
376
+ *
377
+ *
378
+ * @memberof NgxPrintDirective
379
+ */
380
+ print() {
381
+ super.print(this.printOptions);
382
+ }
383
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
384
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.0.4", type: NgxPrintDirective, isStandalone: true, selector: "button[ngxPrint]", inputs: { previewOnly: "previewOnly", printSectionId: "printSectionId", printTitle: "printTitle", useExistingCss: "useExistingCss", printDelay: "printDelay", closeWindow: "closeWindow", bodyClass: "bodyClass", openNewTab: "openNewTab", printStyle: "printStyle", styleSheetFile: "styleSheetFile" }, host: { listeners: { "click": "print()" } }, usesInheritance: true, ngImport: i0 });
385
+ }
386
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintDirective, decorators: [{
210
387
  type: Directive,
211
388
  args: [{
212
389
  selector: "button[ngxPrint]",
@@ -226,6 +403,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
226
403
  type: Input
227
404
  }], bodyClass: [{
228
405
  type: Input
406
+ }], openNewTab: [{
407
+ type: Input
229
408
  }], printStyle: [{
230
409
  type: Input
231
410
  }], styleSheetFile: [{
@@ -236,11 +415,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
236
415
  }] } });
237
416
 
238
417
  class NgxPrintModule {
239
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgxPrintModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
240
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: NgxPrintModule, imports: [NgxPrintDirective], exports: [NgxPrintDirective] });
241
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgxPrintModule });
418
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
419
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintModule, imports: [NgxPrintDirective], exports: [NgxPrintDirective] });
420
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintModule });
242
421
  }
243
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgxPrintModule, decorators: [{
422
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NgxPrintModule, decorators: [{
244
423
  type: NgModule,
245
424
  args: [{
246
425
  imports: [NgxPrintDirective],
@@ -256,5 +435,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
256
435
  * Generated bundle index. Do not edit.
257
436
  */
258
437
 
259
- export { NgxPrintDirective, NgxPrintModule };
438
+ export { NgxPrintDirective, NgxPrintModule, NgxPrintService, PrintOptions };
260
439
  //# sourceMappingURL=ngx-print.mjs.map