ngx-print 1.3.0 → 1.3.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.
package/karma.conf.js DELETED
@@ -1,47 +0,0 @@
1
- // Karma configuration file, see link for more information
2
- // https://karma-runner.github.io/1.0/config/configuration-file.html
3
-
4
- module.exports = function (config) {
5
- config.set({
6
- basePath: '',
7
- frameworks: ['jasmine', '@angular-devkit/build-angular'],
8
- plugins: [
9
- require('karma-jasmine'),
10
- require('karma-chrome-launcher'),
11
- require('karma-jasmine-html-reporter'),
12
- require('karma-coverage'),
13
- require('@angular-devkit/build-angular/plugins/karma')
14
- ],
15
- client: {
16
- clearContext: false // leave Jasmine Spec Runner output visible in browser
17
- },
18
- ccoverageReporter: {
19
- dir: require('path').join(__dirname, './coverage/<project-name>'),
20
- subdir: '.',
21
- reporters: [
22
- { type: 'html' },
23
- { type: 'text-summary' }
24
- ],
25
- check: {
26
- global: {
27
- statements: 80,
28
- branches: 80,
29
- functions: 80,
30
- lines: 80
31
- }
32
- }
33
- },
34
- port: 9876,
35
- colors: true,
36
- logLevel: config.LOG_INFO,
37
- autoWatch: true,
38
- browsers: ['Chrome'],
39
- customLaunchers: {
40
- ChromeHeadlessCI: {
41
- base: 'ChromeHeadless',
42
- flags: ['--no-sandbox']
43
- }
44
- },
45
- singleRun: true
46
- });
47
- };
package/ng-package.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
3
- "dest": "./dist/ngx-print",
4
- "lib": {
5
- "entryFile": "src/public_api.ts"
6
-
7
- }
8
- }
@@ -1,112 +0,0 @@
1
- import {Component, DebugElement} from "@angular/core";
2
- import {TestBed, ComponentFixture} from '@angular/core/testing';
3
- import {By} from "@angular/platform-browser";
4
-
5
- import { NgxPrintDirective } from './ngx-print.directive';
6
-
7
- @Component({
8
- template: `
9
- <div id="print-section">
10
- <h1>
11
- Welcome to ngx-print
12
- </h1>
13
- <img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
14
- <h2>Here are some links to help you start: </h2>
15
- <ul >
16
- <li>
17
- <h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
18
- </li>
19
- <li>
20
- <h2><a target="_blank" rel="noopener" href="https://github.com/angular/angular-cli/wiki">CLI Documentation</a></h2>
21
- </li>
22
- <li>
23
- <h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
24
- </li>
25
- </ul>
26
- <table border = "1">
27
- <tr>
28
- <td>Row 1, Column 1</td>
29
- <td>Row 1, Column 2</td>
30
- </tr>
31
- <tr>
32
- <td>Row 2, Column 1</td>
33
- <td>Row 2, Column 2</td>
34
- </tr>
35
- </table>
36
- </div>
37
- <button printSectionId="print-section" ngxPrint></button>
38
- `
39
- })
40
- class TestNgxPrintComponent {
41
- }
42
-
43
- describe('NgxPrintDirective', () => {
44
-
45
- let buttonEl: DebugElement;
46
- let component: TestNgxPrintComponent;
47
- let fixture: ComponentFixture<TestNgxPrintComponent>;
48
-
49
- // To change this later, so it'll depend on TestNgxPrintComponent
50
- let styleSheet: {[key: string]: {[key: string]: string}}
51
- = {
52
- 'h2' : {'border': 'solid 1px'},
53
- 'h1' : {'color': 'red', 'border': '1px solid'}
54
- };
55
-
56
- beforeEach(() => {
57
-
58
- // Configure a NgModule-like decorator metadata
59
- TestBed.configureTestingModule({
60
- declarations: [TestNgxPrintComponent, NgxPrintDirective]
61
- });
62
-
63
- // Create a fixture object (that is going to allows us to create an instance of that component)
64
- fixture = TestBed.createComponent(TestNgxPrintComponent);
65
-
66
- // Create a component instance ( ~ new Component)
67
- component = fixture.componentInstance;
68
-
69
- // Get the button element (on which we tag the directive) to simulate clicks on it
70
- buttonEl = fixture.debugElement.query(By.directive(NgxPrintDirective));
71
-
72
- fixture.detectChanges();
73
- });
74
-
75
- it('should create an instance', () => {
76
- const directive = new NgxPrintDirective();
77
- expect(directive).toBeTruthy();
78
- });
79
-
80
- // it('should test the @Input printStyle', () => {
81
- // const directive = new NgxPrintDirective();
82
- // directive.printStyle = styleSheet;
83
- // for (var key in directive.printStyle) {
84
- // if (directive.printStyle.hasOwnProperty(key)) {
85
- // directive._printStyle.push((key + JSON.stringify(directive.printStyle[key])).replace(/['"]+/g, ''));
86
- // }
87
- // }
88
- // directive.returnStyleValues();
89
-
90
- // expect(directive.returnStyleValues).toHaveBeenCalled();
91
- // });
92
-
93
- // it('should returns a string from array of objects', () => {
94
- // const directive = new NgxPrintDirective();
95
- // directive._printStyle = [
96
- // "h2{border:solid 1px}",
97
- // "h1{color:red,border:1px solid}"
98
- // ];
99
- // // let returnedString = directive.returnStyleValues();
100
-
101
- // // immediately invoked arrow function, else you can uncomment `returnedString` and use it instead
102
- // expect((() => {return directive.returnStyleValues()})()).toEqual('h2{border:solid 1px} h1{color:red,border:1px solid}');
103
- // });
104
-
105
- it(`should popup a new window`, ()=> {
106
- spyOn(window, 'open');
107
- // simulate click
108
- buttonEl.triggerEventHandler('click', {});
109
- expect(window.open).toHaveBeenCalled();
110
- });
111
-
112
- });
@@ -1,193 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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 { }
package/tsconfig.json DELETED
@@ -1,29 +0,0 @@
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
- }
package/tsconfig.lib.json DELETED
@@ -1,14 +0,0 @@
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
- }
@@ -1,17 +0,0 @@
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 DELETED
@@ -1,17 +0,0 @@
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
- }