ngx-print 1.2.1 → 1.3.0

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.
Files changed (40) hide show
  1. package/.editorconfig +13 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +31 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  4. package/.nvmrc +1 -0
  5. package/.travis.yml +40 -0
  6. package/CHANGELOG.md +10 -0
  7. package/README.md +23 -0
  8. package/_config.yml +1 -0
  9. package/angular.json +48 -0
  10. package/karma.conf.js +47 -0
  11. package/ng-package.json +8 -0
  12. package/package.json +47 -71
  13. package/src/lib/ngx-print.directive.spec.ts +112 -0
  14. package/src/lib/ngx-print.directive.ts +193 -0
  15. package/src/lib/ngx-print.module.ts +10 -0
  16. package/{public_api.d.ts → src/public_api.ts} +4 -0
  17. package/tsconfig.json +29 -0
  18. package/tsconfig.lib.json +14 -0
  19. package/tsconfig.spec.json +17 -0
  20. package/tslint.json +17 -0
  21. package/bundles/ngx-print.umd.js +0 -349
  22. package/bundles/ngx-print.umd.js.map +0 -1
  23. package/bundles/ngx-print.umd.min.js +0 -2
  24. package/bundles/ngx-print.umd.min.js.map +0 -1
  25. package/esm2015/lib/ngx-print.directive.js +0 -247
  26. package/esm2015/lib/ngx-print.module.js +0 -16
  27. package/esm2015/ngx-print.js +0 -9
  28. package/esm2015/public_api.js +0 -10
  29. package/esm5/lib/ngx-print.directive.js +0 -321
  30. package/esm5/lib/ngx-print.module.js +0 -20
  31. package/esm5/ngx-print.js +0 -9
  32. package/esm5/public_api.js +0 -10
  33. package/fesm2015/ngx-print.js +0 -233
  34. package/fesm2015/ngx-print.js.map +0 -1
  35. package/fesm5/ngx-print.js +0 -309
  36. package/fesm5/ngx-print.js.map +0 -1
  37. package/lib/ngx-print.directive.d.ts +0 -85
  38. package/lib/ngx-print.module.d.ts +0 -2
  39. package/ngx-print.d.ts +0 -4
  40. package/ngx-print.metadata.json +0 -1
@@ -0,0 +1,193 @@
1
+ import { Directive, HostListener, Input } from '@angular/core';
2
+ @Directive({
3
+ selector: "button[ngxPrint]"
4
+ })
5
+ export class NgxPrintDirective {
6
+
7
+ public _printStyle = [];
8
+
9
+ /**
10
+ * Prevents the print dialog from opening on the window
11
+ *
12
+ * @memberof NgxPrintDirective
13
+ */
14
+ @Input() previewOnly: boolean = false;
15
+
16
+ /**
17
+ *
18
+ *
19
+ * @memberof NgxPrintDirective
20
+ */
21
+ @Input() printSectionId: string;
22
+
23
+ /**
24
+ *
25
+ *
26
+ * @memberof NgxPrintDirective
27
+ */
28
+ @Input() printTitle: string;
29
+
30
+ /**
31
+ *
32
+ *
33
+ * @memberof NgxPrintDirective
34
+ */
35
+ @Input() useExistingCss = false;
36
+
37
+ /**
38
+ * A delay in milliseconds to force the print dialog to wait before opened. Default: 0
39
+ *
40
+ * @memberof NgxPrintDirective
41
+ */
42
+ @Input() printDelay: number = 0;
43
+
44
+ /**
45
+ *
46
+ *
47
+ * @memberof NgxPrintDirective
48
+ */
49
+ @Input()
50
+ set printStyle(values: { [key: string]: { [key: string]: string } }) {
51
+ for (let key in values) {
52
+ if (values.hasOwnProperty(key)) {
53
+ this._printStyle.push((key + JSON.stringify(values[key])).replace(/['"]+/g, ''));
54
+ }
55
+ }
56
+ this.returnStyleValues();
57
+ }
58
+
59
+ /**
60
+ *
61
+ *
62
+ * @returns the string that create the stylesheet which will be injected
63
+ * later within <style></style> tag.
64
+ *
65
+ * -join/replace to transform an array objects to css-styled string
66
+ *
67
+ * @memberof NgxPrintDirective
68
+ */
69
+ public returnStyleValues() {
70
+ return `<style> ${this._printStyle.join(' ').replace(/,/g,';')} </style>`;
71
+ }
72
+
73
+ /**
74
+ *
75
+ *
76
+ * @returns html for the given tag
77
+ *
78
+ * @memberof NgxPrintDirective
79
+ */
80
+ private _styleSheetFile = '';
81
+
82
+ /**
83
+ * @memberof NgxPrintDirective
84
+ * @param cssList
85
+ */
86
+ @Input()
87
+ set styleSheetFile(cssList: string) {
88
+ let linkTagFn = function(cssFileName) {
89
+ return `<link rel="stylesheet" type="text/css" href="${cssFileName}">`;
90
+ }
91
+ if (cssList.indexOf(',') !== -1) {
92
+ const valueArr = cssList.split(',');
93
+ for (let val of valueArr) {
94
+ this._styleSheetFile = this._styleSheetFile + linkTagFn(val);
95
+ }
96
+ } else {
97
+ this._styleSheetFile = linkTagFn(cssList);
98
+ }
99
+ }
100
+
101
+ /**
102
+ * @returns string which contains the link tags containing the css which will
103
+ * be injected later within <head></head> tag.
104
+ *
105
+ */
106
+ private returnStyleSheetLinkTags() {
107
+ return this._styleSheetFile;
108
+ }
109
+ private getElementTag(tag: keyof HTMLElementTagNameMap): string {
110
+ const html: string[] = [];
111
+ const elements = document.getElementsByTagName(tag);
112
+ for (let index = 0; index < elements.length; index++) {
113
+ html.push(elements[index].outerHTML);
114
+ }
115
+ return html.join('\r\n');
116
+ }
117
+
118
+ /**
119
+ *
120
+ * @param data the html element collection to save defaults to
121
+ *
122
+ */
123
+ private getFormData(data: any) {
124
+ for (var i = 0; i < data.length; i++) {
125
+ data[i].defaultValue = data[i].value;
126
+ if(data[i].checked) {
127
+ data[i].defaultChecked = true;
128
+ }
129
+ }
130
+ }
131
+
132
+ /**
133
+ * @returns html section to be printed along with some associated inputs
134
+ *
135
+ */
136
+ private getHtmlContents() {
137
+ let printContents = document.getElementById(this.printSectionId);
138
+ let innards = printContents.getElementsByTagName('input');
139
+ this.getFormData(innards);
140
+
141
+ let txt = printContents.getElementsByTagName('textarea');
142
+ this.getFormData(txt);
143
+
144
+ return printContents.innerHTML;
145
+ }
146
+
147
+ /**
148
+ *
149
+ *
150
+ * @memberof NgxPrintDirective
151
+ */
152
+ @HostListener('click')
153
+ public print(): void {
154
+ let printContents, popupWin, styles = '', links = '';
155
+ const baseTag = this.getElementTag('base');
156
+
157
+ if(this.useExistingCss) {
158
+ styles = this.getElementTag('style');
159
+ links = this.getElementTag('link');
160
+ }
161
+
162
+ printContents = this.getHtmlContents();
163
+ popupWin = window.open("", "_blank", "top=0,left=0,height=auto,width=auto");
164
+ popupWin.document.open();
165
+ popupWin.document.write(`
166
+ <html>
167
+ <head>
168
+ <title>${this.printTitle ? this.printTitle : ""}</title>
169
+ ${baseTag}
170
+ ${this.returnStyleValues()}
171
+ ${this.returnStyleSheetLinkTags()}
172
+ ${styles}
173
+ ${links}
174
+ </head>
175
+ <body>
176
+ ${printContents}
177
+ <script defer>
178
+ function triggerPrint(event) {
179
+ window.removeEventListener('load', triggerPrint, false);
180
+ ${this.previewOnly ? '' : `setTimeout(function() {
181
+ closeWindow(window.print());
182
+ }, ${this.printDelay});`}
183
+ }
184
+ function closeWindow(){
185
+ window.close();
186
+ }
187
+ window.addEventListener('load', triggerPrint, false);
188
+ </script>
189
+ </body>
190
+ </html>`);
191
+ popupWin.document.close();
192
+ }
193
+ }
@@ -0,0 +1,10 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { NgxPrintDirective } from './ngx-print.directive';
3
+
4
+ @NgModule({
5
+ declarations: [NgxPrintDirective],
6
+ imports: [
7
+ ],
8
+ exports: [NgxPrintDirective]
9
+ })
10
+ export class NgxPrintModule { }
@@ -1,2 +1,6 @@
1
+ /*
2
+ * Public API Surface of ngx-print
3
+ */
4
+
1
5
  export * from './lib/ngx-print.directive';
2
6
  export * from './lib/ngx-print.module';
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compileOnSave": false,
3
+ "compilerOptions": {
4
+ "baseUrl": "./",
5
+ "outDir": "./dist/out-tsc",
6
+ "sourceMap": true,
7
+ "declaration": false,
8
+ "module": "ES2022",
9
+ "moduleResolution": "node",
10
+ "emitDecoratorMetadata": true,
11
+ "experimentalDecorators": true,
12
+ "target": "ES2022",
13
+ "typeRoots": [
14
+ "node_modules/@types"
15
+ ],
16
+ "lib": [
17
+ "ES2022",
18
+ "dom"
19
+ ],
20
+ "paths": {
21
+ "ngx-print": [
22
+ "dist/ngx-print"
23
+ ],
24
+ "ngx-print/*": [
25
+ "dist/ngx-print/*"
26
+ ]
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../out-tsc/lib",
5
+ "declaration": true,
6
+ "declarationMap": true,
7
+ "inlineSources": true,
8
+ "types": []
9
+ },
10
+ "exclude": [
11
+ "src/test.ts",
12
+ "**/*.spec.ts"
13
+ ]
14
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./out-tsc/spec",
5
+ "types": [
6
+ "jasmine",
7
+ "node"
8
+ ]
9
+ },
10
+ "files": [
11
+ ],
12
+ "include": [
13
+ "**/*.spec.ts",
14
+ "**/*.d.ts",
15
+ "**/*.ts"
16
+ ]
17
+ }
package/tslint.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../../tslint.json",
3
+ "rules": {
4
+ "directive-selector": [
5
+ false,
6
+ "attribute",
7
+ "lib",
8
+ "camelCase"
9
+ ],
10
+ "component-selector": [
11
+ true,
12
+ "element",
13
+ "lib",
14
+ "kebab-case"
15
+ ]
16
+ }
17
+ }
@@ -1,349 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) :
3
- typeof define === 'function' && define.amd ? define('ngx-print', ['exports', '@angular/core'], factory) :
4
- (factory((global['ngx-print'] = {}),global.ng.core));
5
- }(this, (function (exports,core) { 'use strict';
6
-
7
- /*! *****************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- function __values(o) {
22
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
23
- if (m)
24
- return m.call(o);
25
- if (o && typeof o.length === "number")
26
- return {
27
- next: function () {
28
- if (o && i >= o.length)
29
- o = void 0;
30
- return { value: o && o[i++], done: !o };
31
- }
32
- };
33
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
34
- }
35
-
36
- /**
37
- * @fileoverview added by tsickle
38
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
39
- */
40
- var NgxPrintDirective = /** @class */ (function () {
41
- function NgxPrintDirective() {
42
- this._printStyle = [];
43
- /**
44
- *
45
- *
46
- * \@memberof NgxPrintDirective
47
- */
48
- this.useExistingCss = false;
49
- /**
50
- * A delay in milliseconds to force the print dialog to wait before opened. Default: 0
51
- *
52
- * \@memberof NgxPrintDirective
53
- */
54
- this.printDelay = 0;
55
- /**
56
- *
57
- *
58
- * @return html for the given tag
59
- *
60
- * \@memberof NgxPrintDirective
61
- */
62
- this._styleSheetFile = '';
63
- }
64
- Object.defineProperty(NgxPrintDirective.prototype, "printStyle", {
65
- /**
66
- *
67
- *
68
- * @memberof NgxPrintDirective
69
- */
70
- set: /**
71
- *
72
- *
73
- * \@memberof NgxPrintDirective
74
- * @param {?} values
75
- * @return {?}
76
- */ function (values) {
77
- for (var key in values) {
78
- if (values.hasOwnProperty(key)) {
79
- this._printStyle.push((key + JSON.stringify(values[key])).replace(/['"]+/g, ''));
80
- }
81
- }
82
- this.returnStyleValues();
83
- },
84
- enumerable: true,
85
- configurable: true
86
- });
87
- /**
88
- *
89
- *
90
- * @returns the string that create the stylesheet which will be injected
91
- * later within <style></style> tag.
92
- *
93
- * -join/replace to transform an array objects to css-styled string
94
- *
95
- * @memberof NgxPrintDirective
96
- */
97
- /**
98
- *
99
- *
100
- * \@memberof NgxPrintDirective
101
- * @return {?} the string that create the stylesheet which will be injected
102
- * later within <style></style> tag.
103
- *
104
- * -join/replace to transform an array objects to css-styled string
105
- *
106
- */
107
- NgxPrintDirective.prototype.returnStyleValues = /**
108
- *
109
- *
110
- * \@memberof NgxPrintDirective
111
- * @return {?} the string that create the stylesheet which will be injected
112
- * later within <style></style> tag.
113
- *
114
- * -join/replace to transform an array objects to css-styled string
115
- *
116
- */
117
- function () {
118
- return "<style> " + this._printStyle.join(' ').replace(/,/g, ';') + " </style>";
119
- };
120
- Object.defineProperty(NgxPrintDirective.prototype, "styleSheetFile", {
121
- /**
122
- * @memberof NgxPrintDirective
123
- * @param cssList
124
- */
125
- set: /**
126
- * \@memberof NgxPrintDirective
127
- * @param {?} cssList
128
- * @return {?}
129
- */ function (cssList) {
130
- var e_1, _a;
131
- /** @type {?} */
132
- var linkTagFn = ( /**
133
- * @param {?} cssFileName
134
- * @return {?}
135
- */function (cssFileName) {
136
- return "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + cssFileName + "\">";
137
- });
138
- if (cssList.indexOf(',') !== -1) {
139
- /** @type {?} */
140
- var valueArr = cssList.split(',');
141
- try {
142
- for (var valueArr_1 = __values(valueArr), valueArr_1_1 = valueArr_1.next(); !valueArr_1_1.done; valueArr_1_1 = valueArr_1.next()) {
143
- var val = valueArr_1_1.value;
144
- this._styleSheetFile = this._styleSheetFile + linkTagFn(val);
145
- }
146
- }
147
- catch (e_1_1) {
148
- e_1 = { error: e_1_1 };
149
- }
150
- finally {
151
- try {
152
- if (valueArr_1_1 && !valueArr_1_1.done && (_a = valueArr_1.return))
153
- _a.call(valueArr_1);
154
- }
155
- finally {
156
- if (e_1)
157
- throw e_1.error;
158
- }
159
- }
160
- }
161
- else {
162
- this._styleSheetFile = linkTagFn(cssList);
163
- }
164
- },
165
- enumerable: true,
166
- configurable: true
167
- });
168
- /**
169
- * @returns string which contains the link tags containing the css which will
170
- * be injected later within <head></head> tag.
171
- *
172
- */
173
- /**
174
- * @private
175
- * @return {?} string which contains the link tags containing the css which will
176
- * be injected later within <head></head> tag.
177
- *
178
- */
179
- NgxPrintDirective.prototype.returnStyleSheetLinkTags = /**
180
- * @private
181
- * @return {?} string which contains the link tags containing the css which will
182
- * be injected later within <head></head> tag.
183
- *
184
- */
185
- function () {
186
- return this._styleSheetFile;
187
- };
188
- /**
189
- * @private
190
- * @param {?} tag
191
- * @return {?}
192
- */
193
- NgxPrintDirective.prototype.getElementTag = /**
194
- * @private
195
- * @param {?} tag
196
- * @return {?}
197
- */
198
- function (tag) {
199
- /** @type {?} */
200
- var html = [];
201
- /** @type {?} */
202
- var elements = document.getElementsByTagName(tag);
203
- for (var index = 0; index < elements.length; index++) {
204
- html.push(elements[index].outerHTML);
205
- }
206
- return html.join('\r\n');
207
- };
208
- /**
209
- *
210
- * @param data the html element collection to save defaults to
211
- *
212
- */
213
- /**
214
- *
215
- * @private
216
- * @param {?} data the html element collection to save defaults to
217
- *
218
- * @return {?}
219
- */
220
- NgxPrintDirective.prototype.getFormData = /**
221
- *
222
- * @private
223
- * @param {?} data the html element collection to save defaults to
224
- *
225
- * @return {?}
226
- */
227
- function (data) {
228
- for (var i = 0; i < data.length; i++) {
229
- data[i].defaultValue = data[i].value;
230
- if (data[i].checked) {
231
- data[i].defaultChecked = true;
232
- }
233
- }
234
- };
235
- /**
236
- * @returns html section to be printed along with some associated inputs
237
- *
238
- */
239
- /**
240
- * @private
241
- * @return {?} html section to be printed along with some associated inputs
242
- *
243
- */
244
- NgxPrintDirective.prototype.getHtmlContents = /**
245
- * @private
246
- * @return {?} html section to be printed along with some associated inputs
247
- *
248
- */
249
- function () {
250
- /** @type {?} */
251
- var printContents = document.getElementById(this.printSectionId);
252
- /** @type {?} */
253
- var innards = printContents.getElementsByTagName('input');
254
- this.getFormData(innards);
255
- /** @type {?} */
256
- var txt = printContents.getElementsByTagName('textarea');
257
- this.getFormData(txt);
258
- return printContents.innerHTML;
259
- };
260
- /**
261
- *
262
- *
263
- * @memberof NgxPrintDirective
264
- */
265
- /**
266
- *
267
- *
268
- * \@memberof NgxPrintDirective
269
- * @return {?}
270
- */
271
- NgxPrintDirective.prototype.print = /**
272
- *
273
- *
274
- * \@memberof NgxPrintDirective
275
- * @return {?}
276
- */
277
- function () {
278
- /** @type {?} */
279
- var printContents;
280
- /** @type {?} */
281
- var popupWin;
282
- /** @type {?} */
283
- var styles = '';
284
- /** @type {?} */
285
- var links = '';
286
- /** @type {?} */
287
- var baseTag = this.getElementTag('base');
288
- if (this.useExistingCss) {
289
- styles = this.getElementTag('style');
290
- links = this.getElementTag('link');
291
- }
292
- printContents = this.getHtmlContents();
293
- popupWin = window.open("", "_blank", "top=0,left=0,height=auto,width=auto");
294
- popupWin.document.open();
295
- popupWin.document.write("\n <html>\n <head>\n <title>" + (this.printTitle ? this.printTitle : "") + "</title>\n " + baseTag + "\n " + this.returnStyleValues() + "\n " + this.returnStyleSheetLinkTags() + "\n " + styles + "\n " + links + "\n </head>\n <body>\n " + printContents + "\n <script defer>\n function triggerPrint(event) {\n window.removeEventListener('load', triggerPrint, false);\n setTimeout(function() {\n closeWindow(window.print());\n }, " + this.printDelay + ");\n }\n function closeWindow(){\n window.close();\n }\n window.addEventListener('load', triggerPrint, false);\n </script>\n </body>\n </html>");
296
- popupWin.document.close();
297
- };
298
- NgxPrintDirective.decorators = [
299
- { type: core.Directive, args: [{
300
- selector: "button[ngxPrint]"
301
- },] }
302
- ];
303
- NgxPrintDirective.propDecorators = {
304
- printSectionId: [{ type: core.Input }],
305
- printTitle: [{ type: core.Input }],
306
- useExistingCss: [{ type: core.Input }],
307
- printDelay: [{ type: core.Input }],
308
- printStyle: [{ type: core.Input }],
309
- styleSheetFile: [{ type: core.Input }],
310
- print: [{ type: core.HostListener, args: ['click',] }]
311
- };
312
- return NgxPrintDirective;
313
- }());
314
-
315
- /**
316
- * @fileoverview added by tsickle
317
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
318
- */
319
- var NgxPrintModule = /** @class */ (function () {
320
- function NgxPrintModule() {
321
- }
322
- NgxPrintModule.decorators = [
323
- { type: core.NgModule, args: [{
324
- declarations: [NgxPrintDirective],
325
- imports: [],
326
- exports: [NgxPrintDirective]
327
- },] }
328
- ];
329
- return NgxPrintModule;
330
- }());
331
-
332
- /**
333
- * @fileoverview added by tsickle
334
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
335
- */
336
-
337
- /**
338
- * @fileoverview added by tsickle
339
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
340
- */
341
-
342
- exports.NgxPrintDirective = NgxPrintDirective;
343
- exports.NgxPrintModule = NgxPrintModule;
344
-
345
- Object.defineProperty(exports, '__esModule', { value: true });
346
-
347
- })));
348
-
349
- //# sourceMappingURL=ngx-print.umd.js.map