ngx-ratio-image 0.1.3 → 0.1.4

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.
@@ -0,0 +1,77 @@
1
+ import { Component, Input } from '@angular/core';
2
+ import { DecimalPipe } from '@angular/common';
3
+ import * as i0 from "@angular/core";
4
+ export class RatioImageComponent {
5
+ constructor() {
6
+ this.src = '';
7
+ this.width = 0;
8
+ this.height = 0;
9
+ this.debug = false;
10
+ this.imageWidth = 0;
11
+ this.imageHeight = 0;
12
+ this.naturalWidth = 0;
13
+ this.naturalHeight = 0;
14
+ this.imageLeft = 0;
15
+ this.imageTop = 0;
16
+ this.ratioImage = 1;
17
+ this.ratioBox = 1;
18
+ this.scale = 1;
19
+ if (this.debug)
20
+ console.log('constructor', this.src);
21
+ }
22
+ ngAfterViewInit() {
23
+ if (this.debug)
24
+ console.log('ngAfterViewInit', this.src, this.width, this.height);
25
+ }
26
+ onImageLoad(img) {
27
+ if (this.debug)
28
+ console.log('onImageLoad ', img);
29
+ if (img) {
30
+ this.naturalWidth = img.naturalWidth;
31
+ this.naturalHeight = img.naturalHeight;
32
+ if (this.width > 0 && this.height > 0) {
33
+ this.calculate();
34
+ }
35
+ }
36
+ }
37
+ ngOnChanges() {
38
+ this.calculate();
39
+ }
40
+ calculate() {
41
+ this.ratioImage = this.naturalWidth / this.naturalHeight;
42
+ this.ratioBox = this.width / this.height;
43
+ if (this.ratioBox > this.ratioImage) {
44
+ this.scale = this.height / this.naturalHeight;
45
+ this.imageLeft = (this.width - this.naturalWidth * this.scale) / 2;
46
+ }
47
+ else if (this.ratioBox < this.ratioImage) {
48
+ this.scale = this.width / this.naturalWidth;
49
+ this.imageTop = (this.height - this.naturalHeight * this.scale) / 2;
50
+ }
51
+ else {
52
+ this.scale = this.width / this.naturalWidth;
53
+ this.imageLeft = 0;
54
+ this.imageTop = 0;
55
+ }
56
+ if (this.debug)
57
+ console.log('calculate', this.src, this.naturalWidth + ' x ' + this.naturalHeight);
58
+ }
59
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: RatioImageComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
60
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: RatioImageComponent, isStandalone: true, selector: "ngx-ratio-image", inputs: { src: "src", width: "width", height: "height", debug: "debug" }, usesOnChanges: true, ngImport: i0, template: "<div\n [style.position]=\"'relative'\"\n [style.z-index]=\"2\"\n [style.border]=\"debug ? '1px solid red' : ''\"\n [style.width]=\"width + 'px'\"\n [style.height]=\"height + 'px'\"\n >\n <img\n class=\"img-background\"\n #img\n [src]=\"src\"\n [style.position]=\"'absolute'\"\n [style.z-index]=\"1\"\n [style.filter]=\"'blur(5px)'\"\n [style.opacity]=\"0.5\"\n [width]=\"width\"\n [height]=\"height\"\n [style.overflow]=\"'hidden'\"\n (load)=\"onImageLoad(img)\"\n alt=\"\"\n />\n <img\n class=\"img-main\"\n [src]=\"src\"\n [width]=\"naturalWidth * scale\"\n [height]=\"naturalHeight * scale\"\n [style.position]=\"'absolute'\"\n [style.z-index]=\"2\"\n [style.left]=\"imageLeft + 'px'\"\n [style.top]=\"imageTop + 'px'\"\n alt=\"\"\n />\n</div>\n@if (debug) {\n <div style=\"margin-top: 10px\">\n <div>Container: {{ width }} x {{ height }}</div>\n <div>Natural: {{ naturalWidth }} x {{ naturalHeight }}</div>\n <div>Pos: {{ imageLeft }} , {{ imageTop }}</div>\n <div>Scale: {{ scale | number: '0.0-2' }}</div>\n <div>\n Ratio Box , Image: {{ this.ratioBox | number: '0.0-2' }} : 1 , {{ this.ratioImage | number: '0.0-2' }} : 1\n </div>\n </div>\n}\n", dependencies: [{ kind: "pipe", type: DecimalPipe, name: "number" }] }); }
61
+ }
62
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: RatioImageComponent, decorators: [{
63
+ type: Component,
64
+ args: [{ selector: 'ngx-ratio-image', standalone: true, imports: [DecimalPipe], template: "<div\n [style.position]=\"'relative'\"\n [style.z-index]=\"2\"\n [style.border]=\"debug ? '1px solid red' : ''\"\n [style.width]=\"width + 'px'\"\n [style.height]=\"height + 'px'\"\n >\n <img\n class=\"img-background\"\n #img\n [src]=\"src\"\n [style.position]=\"'absolute'\"\n [style.z-index]=\"1\"\n [style.filter]=\"'blur(5px)'\"\n [style.opacity]=\"0.5\"\n [width]=\"width\"\n [height]=\"height\"\n [style.overflow]=\"'hidden'\"\n (load)=\"onImageLoad(img)\"\n alt=\"\"\n />\n <img\n class=\"img-main\"\n [src]=\"src\"\n [width]=\"naturalWidth * scale\"\n [height]=\"naturalHeight * scale\"\n [style.position]=\"'absolute'\"\n [style.z-index]=\"2\"\n [style.left]=\"imageLeft + 'px'\"\n [style.top]=\"imageTop + 'px'\"\n alt=\"\"\n />\n</div>\n@if (debug) {\n <div style=\"margin-top: 10px\">\n <div>Container: {{ width }} x {{ height }}</div>\n <div>Natural: {{ naturalWidth }} x {{ naturalHeight }}</div>\n <div>Pos: {{ imageLeft }} , {{ imageTop }}</div>\n <div>Scale: {{ scale | number: '0.0-2' }}</div>\n <div>\n Ratio Box , Image: {{ this.ratioBox | number: '0.0-2' }} : 1 , {{ this.ratioImage | number: '0.0-2' }} : 1\n </div>\n </div>\n}\n" }]
65
+ }], ctorParameters: () => [], propDecorators: { src: [{
66
+ type: Input,
67
+ args: [{ required: true }]
68
+ }], width: [{
69
+ type: Input,
70
+ args: [{ required: true }]
71
+ }], height: [{
72
+ type: Input,
73
+ args: [{ required: true }]
74
+ }], debug: [{
75
+ type: Input
76
+ }] } });
77
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmF0aW8taW1hZ2UuY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvbm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cbkBpZiAoZGVidWcpIHtcbiAgPGRpdiBzdHlsZT1cIm1hcmdpbi10b3A6IDEwcHhcIj5cbiAgICA8ZGl2PkNvbnRhaW5lcjoge3sgd2lkdGggfX0geCB7eyBoZWlnaHQgfX08L2Rpdj5cbiAgICA8ZGl2Pk5hdHVyYWw6IHt7IG5hdHVyYWxXaWR0aCB9fSB4IHt7IG5hdHVyYWxIZWlnaHQgfX08L2Rpdj5cbiAgICA8ZGl2PlBvczoge3sgaW1hZ2VMZWZ0IH19ICwge3sgaW1hZ2VUb3AgfX08L2Rpdj5cbiAgICA8ZGl2PlNjYWxlOiB7eyBzY2FsZSB8IG51bWJlcjogJzAuMC0yJyB9fTwvZGl2PlxuICAgIDxkaXY+XG4gICAgICBSYXRpbyBCb3ggLCBJbWFnZToge3sgdGhpcy5yYXRpb0JveCB8IG51bWJlcjogJzAuMC0yJyB9fSA6IDEgLCB7eyB0aGlzLnJhdGlvSW1hZ2UgfCBudW1iZXI6ICcwLjAtMicgfX0gOiAxXG4gICAgPC9kaXY+XG4gIDwvZGl2PlxufVxuIl19
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ export * from './public-api';
5
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmd4LXJhdGlvLWltYWdlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vcHJvamVjdHMvbmd4LXJhdGlvLWltYWdlL3NyYy9uZ3gtcmF0aW8taW1hZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O0dBRUc7QUFFSCxjQUFjLGNBQWMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogR2VuZXJhdGVkIGJ1bmRsZSBpbmRleC4gRG8gbm90IGVkaXQuXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9wdWJsaWMtYXBpJztcbiJdfQ==
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Public API Surface of ngx-ratio-image
3
+ */
4
+ export * from './lib/ratio-image/ratio-image.component';
5
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL25neC1yYXRpby1pbWFnZS9zcmMvcHVibGljLWFwaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUVILGNBQWMseUNBQXlDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyIvKlxuICogUHVibGljIEFQSSBTdXJmYWNlIG9mIG5neC1yYXRpby1pbWFnZVxuICovXG5cbmV4cG9ydCAqIGZyb20gJy4vbGliL3JhdGlvLWltYWdlL3JhdGlvLWltYWdlLmNvbXBvbmVudCc7XG4iXX0=
@@ -0,0 +1,88 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Input, Component } from '@angular/core';
3
+ import { DecimalPipe } from '@angular/common';
4
+
5
+ class RatioImageComponent {
6
+ constructor() {
7
+ this.src = '';
8
+ this.width = 0;
9
+ this.height = 0;
10
+ this.debug = false;
11
+ this.imageWidth = 0;
12
+ this.imageHeight = 0;
13
+ this.naturalWidth = 0;
14
+ this.naturalHeight = 0;
15
+ this.imageLeft = 0;
16
+ this.imageTop = 0;
17
+ this.ratioImage = 1;
18
+ this.ratioBox = 1;
19
+ this.scale = 1;
20
+ if (this.debug)
21
+ console.log('constructor', this.src);
22
+ }
23
+ ngAfterViewInit() {
24
+ if (this.debug)
25
+ console.log('ngAfterViewInit', this.src, this.width, this.height);
26
+ }
27
+ onImageLoad(img) {
28
+ if (this.debug)
29
+ console.log('onImageLoad ', img);
30
+ if (img) {
31
+ this.naturalWidth = img.naturalWidth;
32
+ this.naturalHeight = img.naturalHeight;
33
+ if (this.width > 0 && this.height > 0) {
34
+ this.calculate();
35
+ }
36
+ }
37
+ }
38
+ ngOnChanges() {
39
+ this.calculate();
40
+ }
41
+ calculate() {
42
+ this.ratioImage = this.naturalWidth / this.naturalHeight;
43
+ this.ratioBox = this.width / this.height;
44
+ if (this.ratioBox > this.ratioImage) {
45
+ this.scale = this.height / this.naturalHeight;
46
+ this.imageLeft = (this.width - this.naturalWidth * this.scale) / 2;
47
+ }
48
+ else if (this.ratioBox < this.ratioImage) {
49
+ this.scale = this.width / this.naturalWidth;
50
+ this.imageTop = (this.height - this.naturalHeight * this.scale) / 2;
51
+ }
52
+ else {
53
+ this.scale = this.width / this.naturalWidth;
54
+ this.imageLeft = 0;
55
+ this.imageTop = 0;
56
+ }
57
+ if (this.debug)
58
+ console.log('calculate', this.src, this.naturalWidth + ' x ' + this.naturalHeight);
59
+ }
60
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: RatioImageComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
61
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: RatioImageComponent, isStandalone: true, selector: "ngx-ratio-image", inputs: { src: "src", width: "width", height: "height", debug: "debug" }, usesOnChanges: true, ngImport: i0, template: "<div\n [style.position]=\"'relative'\"\n [style.z-index]=\"2\"\n [style.border]=\"debug ? '1px solid red' : ''\"\n [style.width]=\"width + 'px'\"\n [style.height]=\"height + 'px'\"\n >\n <img\n class=\"img-background\"\n #img\n [src]=\"src\"\n [style.position]=\"'absolute'\"\n [style.z-index]=\"1\"\n [style.filter]=\"'blur(5px)'\"\n [style.opacity]=\"0.5\"\n [width]=\"width\"\n [height]=\"height\"\n [style.overflow]=\"'hidden'\"\n (load)=\"onImageLoad(img)\"\n alt=\"\"\n />\n <img\n class=\"img-main\"\n [src]=\"src\"\n [width]=\"naturalWidth * scale\"\n [height]=\"naturalHeight * scale\"\n [style.position]=\"'absolute'\"\n [style.z-index]=\"2\"\n [style.left]=\"imageLeft + 'px'\"\n [style.top]=\"imageTop + 'px'\"\n alt=\"\"\n />\n</div>\n@if (debug) {\n <div style=\"margin-top: 10px\">\n <div>Container: {{ width }} x {{ height }}</div>\n <div>Natural: {{ naturalWidth }} x {{ naturalHeight }}</div>\n <div>Pos: {{ imageLeft }} , {{ imageTop }}</div>\n <div>Scale: {{ scale | number: '0.0-2' }}</div>\n <div>\n Ratio Box , Image: {{ this.ratioBox | number: '0.0-2' }} : 1 , {{ this.ratioImage | number: '0.0-2' }} : 1\n </div>\n </div>\n}\n", dependencies: [{ kind: "pipe", type: DecimalPipe, name: "number" }] }); }
62
+ }
63
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: RatioImageComponent, decorators: [{
64
+ type: Component,
65
+ args: [{ selector: 'ngx-ratio-image', standalone: true, imports: [DecimalPipe], template: "<div\n [style.position]=\"'relative'\"\n [style.z-index]=\"2\"\n [style.border]=\"debug ? '1px solid red' : ''\"\n [style.width]=\"width + 'px'\"\n [style.height]=\"height + 'px'\"\n >\n <img\n class=\"img-background\"\n #img\n [src]=\"src\"\n [style.position]=\"'absolute'\"\n [style.z-index]=\"1\"\n [style.filter]=\"'blur(5px)'\"\n [style.opacity]=\"0.5\"\n [width]=\"width\"\n [height]=\"height\"\n [style.overflow]=\"'hidden'\"\n (load)=\"onImageLoad(img)\"\n alt=\"\"\n />\n <img\n class=\"img-main\"\n [src]=\"src\"\n [width]=\"naturalWidth * scale\"\n [height]=\"naturalHeight * scale\"\n [style.position]=\"'absolute'\"\n [style.z-index]=\"2\"\n [style.left]=\"imageLeft + 'px'\"\n [style.top]=\"imageTop + 'px'\"\n alt=\"\"\n />\n</div>\n@if (debug) {\n <div style=\"margin-top: 10px\">\n <div>Container: {{ width }} x {{ height }}</div>\n <div>Natural: {{ naturalWidth }} x {{ naturalHeight }}</div>\n <div>Pos: {{ imageLeft }} , {{ imageTop }}</div>\n <div>Scale: {{ scale | number: '0.0-2' }}</div>\n <div>\n Ratio Box , Image: {{ this.ratioBox | number: '0.0-2' }} : 1 , {{ this.ratioImage | number: '0.0-2' }} : 1\n </div>\n </div>\n}\n" }]
66
+ }], ctorParameters: () => [], propDecorators: { src: [{
67
+ type: Input,
68
+ args: [{ required: true }]
69
+ }], width: [{
70
+ type: Input,
71
+ args: [{ required: true }]
72
+ }], height: [{
73
+ type: Input,
74
+ args: [{ required: true }]
75
+ }], debug: [{
76
+ type: Input
77
+ }] } });
78
+
79
+ /*
80
+ * Public API Surface of ngx-ratio-image
81
+ */
82
+
83
+ /**
84
+ * Generated bundle index. Do not edit.
85
+ */
86
+
87
+ export { RatioImageComponent };
88
+ //# sourceMappingURL=ngx-ratio-image.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngx-ratio-image.mjs","sources":["../../../projects/ngx-ratio-image/src/lib/ratio-image/ratio-image.component.ts","../../../projects/ngx-ratio-image/src/lib/ratio-image/ratio-image.component.html","../../../projects/ngx-ratio-image/src/public-api.ts","../../../projects/ngx-ratio-image/src/ngx-ratio-image.ts"],"sourcesContent":["import { AfterViewInit, Component, Input, OnChanges } from '@angular/core';\nimport { DecimalPipe } from '@angular/common';\n\ninterface Image {\n\tclientWidth: number;\n\tclientHeight: number;\n\tnaturalWidth: number;\n\tnaturalHeight: number;\n}\n\n@Component({\n\tselector: 'ngx-ratio-image',\n\ttemplateUrl: 'ratio-image.component.html',\n\tstyles: [],\n\tstandalone: true,\n\timports: [DecimalPipe]\n})\nexport class RatioImageComponent implements AfterViewInit, OnChanges {\n\t@Input({ required: true }) public src = '';\n\t@Input({ required: true }) public width = 0;\n\t@Input({ required: true }) public height = 0;\n\t@Input() public debug = false;\n\n\tpublic imageWidth = 0;\n\tpublic imageHeight = 0;\n\n\tpublic naturalWidth = 0;\n\tpublic naturalHeight = 0;\n\n\tpublic imageLeft = 0;\n\tpublic imageTop = 0;\n\tpublic ratioImage = 1;\n\tpublic ratioBox = 1;\n\n\tpublic scale = 1;\n\n\tconstructor() {\n\t\tif (this.debug) console.log('constructor', this.src);\n\t}\n\n\tngAfterViewInit() {\n\t\tif (this.debug) console.log('ngAfterViewInit', this.src, this.width, this.height);\n\t}\n\n\tonImageLoad(img: Image) {\n\t\tif (this.debug) console.log('onImageLoad ', img);\n\t\tif (img) {\n\t\t\tthis.naturalWidth = img.naturalWidth;\n\t\t\tthis.naturalHeight = img.naturalHeight;\n\t\t\tif (this.width > 0 && this.height > 0) {\n\t\t\t\tthis.calculate();\n\t\t\t}\n\t\t}\n\t}\n\n\tngOnChanges(): void {\n\t\tthis.calculate();\n\t}\n\n\tprivate calculate() {\n\t\tthis.ratioImage = this.naturalWidth / this.naturalHeight;\n\t\tthis.ratioBox = this.width / this.height;\n\n\t\tif (this.ratioBox > this.ratioImage) {\n\t\t\tthis.scale = this.height / this.naturalHeight;\n\t\t\tthis.imageLeft = (this.width - this.naturalWidth * this.scale) / 2;\n\t\t} else if (this.ratioBox < this.ratioImage) {\n\t\t\tthis.scale = this.width / this.naturalWidth;\n\t\t\tthis.imageTop = (this.height - this.naturalHeight * this.scale) / 2;\n\t\t} else {\n\t\t\tthis.scale = this.width / this.naturalWidth;\n\t\t\tthis.imageLeft = 0;\n\t\t\tthis.imageTop = 0;\n\t\t}\n\n\t\tif (this.debug) console.log('calculate', this.src, this.naturalWidth + ' x ' + this.naturalHeight);\n\t}\n}\n","<div\n [style.position]=\"'relative'\"\n [style.z-index]=\"2\"\n [style.border]=\"debug ? '1px solid red' : ''\"\n [style.width]=\"width + 'px'\"\n [style.height]=\"height + 'px'\"\n >\n <img\n class=\"img-background\"\n #img\n [src]=\"src\"\n [style.position]=\"'absolute'\"\n [style.z-index]=\"1\"\n [style.filter]=\"'blur(5px)'\"\n [style.opacity]=\"0.5\"\n [width]=\"width\"\n [height]=\"height\"\n [style.overflow]=\"'hidden'\"\n (load)=\"onImageLoad(img)\"\n alt=\"\"\n />\n <img\n class=\"img-main\"\n [src]=\"src\"\n [width]=\"naturalWidth * scale\"\n [height]=\"naturalHeight * scale\"\n [style.position]=\"'absolute'\"\n [style.z-index]=\"2\"\n [style.left]=\"imageLeft + 'px'\"\n [style.top]=\"imageTop + 'px'\"\n alt=\"\"\n />\n</div>\n@if (debug) {\n <div style=\"margin-top: 10px\">\n <div>Container: {{ width }} x {{ height }}</div>\n <div>Natural: {{ naturalWidth }} x {{ naturalHeight }}</div>\n <div>Pos: {{ imageLeft }} , {{ imageTop }}</div>\n <div>Scale: {{ scale | number: '0.0-2' }}</div>\n <div>\n Ratio Box , Image: {{ this.ratioBox | number: '0.0-2' }} : 1 , {{ this.ratioImage | number: '0.0-2' }} : 1\n </div>\n </div>\n}\n","/*\n * Public API Surface of ngx-ratio-image\n */\n\nexport * from './lib/ratio-image/ratio-image.component';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAiBa,mBAAmB,CAAA;AAmB/B,IAAA,WAAA,GAAA;QAlBkC,IAAA,CAAA,GAAG,GAAG,EAAE;QACR,IAAA,CAAA,KAAK,GAAG,CAAC;QACT,IAAA,CAAA,MAAM,GAAG,CAAC;QAC5B,IAAA,CAAA,KAAK,GAAG,KAAK;QAEtB,IAAA,CAAA,UAAU,GAAG,CAAC;QACd,IAAA,CAAA,WAAW,GAAG,CAAC;QAEf,IAAA,CAAA,YAAY,GAAG,CAAC;QAChB,IAAA,CAAA,aAAa,GAAG,CAAC;QAEjB,IAAA,CAAA,SAAS,GAAG,CAAC;QACb,IAAA,CAAA,QAAQ,GAAG,CAAC;QACZ,IAAA,CAAA,UAAU,GAAG,CAAC;QACd,IAAA,CAAA,QAAQ,GAAG,CAAC;QAEZ,IAAA,CAAA,KAAK,GAAG,CAAC;QAGf,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC;IACrD;IAEA,eAAe,GAAA;QACd,IAAI,IAAI,CAAC,KAAK;AAAE,YAAA,OAAO,CAAC,GAAG,CAAC,i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C,EAAE,QAAQ,EAAE,IAAI,EAAE;gBACT,KAAK,EAAA,CAAA;sBAApB;;;AErBF;;AAEG;;ACFH;;AAEG;;;;"}
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ /// <amd-module name="ngx-ratio-image" />
5
+ export * from './public-api';
@@ -0,0 +1,31 @@
1
+ import { AfterViewInit, OnChanges } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ interface Image {
4
+ clientWidth: number;
5
+ clientHeight: number;
6
+ naturalWidth: number;
7
+ naturalHeight: number;
8
+ }
9
+ export declare class RatioImageComponent implements AfterViewInit, OnChanges {
10
+ src: string;
11
+ width: number;
12
+ height: number;
13
+ debug: boolean;
14
+ imageWidth: number;
15
+ imageHeight: number;
16
+ naturalWidth: number;
17
+ naturalHeight: number;
18
+ imageLeft: number;
19
+ imageTop: number;
20
+ ratioImage: number;
21
+ ratioBox: number;
22
+ scale: number;
23
+ constructor();
24
+ ngAfterViewInit(): void;
25
+ onImageLoad(img: Image): void;
26
+ ngOnChanges(): void;
27
+ private calculate;
28
+ static ɵfac: i0.ɵɵFactoryDeclaration<RatioImageComponent, never>;
29
+ static ɵcmp: i0.ɵɵComponentDeclaration<RatioImageComponent, "ngx-ratio-image", never, { "src": { "alias": "src"; "required": true; }; "width": { "alias": "width"; "required": true; }; "height": { "alias": "height"; "required": true; }; "debug": { "alias": "debug"; "required": false; }; }, {}, never, never, true, never>;
30
+ }
31
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-ratio-image",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "author": {
5
5
  "name": "Gerd Siebert"
6
6
  },
@@ -30,5 +30,18 @@
30
30
  "bugs": {
31
31
  "url": "https://github.com/gerd-siebert/ngx-ratio-image/issues"
32
32
  },
33
- "homepage": "https://github.com/gerd-siebert/ngx-ratio-image#readme"
33
+ "homepage": "https://github.com/gerd-siebert/ngx-ratio-image#readme",
34
+ "module": "fesm2022/ngx-ratio-image.mjs",
35
+ "typings": "index.d.ts",
36
+ "exports": {
37
+ "./package.json": {
38
+ "default": "./package.json"
39
+ },
40
+ ".": {
41
+ "types": "./index.d.ts",
42
+ "esm2022": "./esm2022/ngx-ratio-image.mjs",
43
+ "esm": "./esm2022/ngx-ratio-image.mjs",
44
+ "default": "./fesm2022/ngx-ratio-image.mjs"
45
+ }
46
+ }
34
47
  }
@@ -0,0 +1 @@
1
+ export * from './lib/ratio-image/ratio-image.component';
package/.eslintrc.json DELETED
@@ -1,31 +0,0 @@
1
- {
2
- "extends": "../../.eslintrc.json",
3
- "ignorePatterns": ["!**/*"],
4
- "overrides": [
5
- {
6
- "files": ["*.ts"],
7
- "rules": {
8
- "@angular-eslint/directive-selector": [
9
- "error",
10
- {
11
- "type": "attribute",
12
- "prefix": "ngx",
13
- "style": "camelCase"
14
- }
15
- ],
16
- "@angular-eslint/component-selector": [
17
- "error",
18
- {
19
- "type": "element",
20
- "prefix": "ngx",
21
- "style": "kebab-case"
22
- }
23
- ]
24
- }
25
- },
26
- {
27
- "files": ["*.html"],
28
- "rules": {}
29
- }
30
- ]
31
- }
package/ng-package.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
- "dest": "../../dist/ngx-ratio-image",
4
- "lib": {
5
- "entryFile": "src/public-api.ts"
6
- }
7
- }
@@ -1,44 +0,0 @@
1
- <div
2
- [style.position]="'relative'"
3
- [style.z-index]="2"
4
- [style.border]="debug ? '1px solid red' : ''"
5
- [style.width]="width + 'px'"
6
- [style.height]="height + 'px'"
7
- >
8
- <img
9
- class="img-background"
10
- #img
11
- [src]="src"
12
- [style.position]="'absolute'"
13
- [style.z-index]="1"
14
- [style.filter]="'blur(5px)'"
15
- [style.opacity]="0.5"
16
- [width]="width"
17
- [height]="height"
18
- [style.overflow]="'hidden'"
19
- (load)="onImageLoad(img)"
20
- alt=""
21
- />
22
- <img
23
- class="img-main"
24
- [src]="src"
25
- [width]="naturalWidth * scale"
26
- [height]="naturalHeight * scale"
27
- [style.position]="'absolute'"
28
- [style.z-index]="2"
29
- [style.left]="imageLeft + 'px'"
30
- [style.top]="imageTop + 'px'"
31
- alt=""
32
- />
33
- </div>
34
- @if (debug) {
35
- <div style="margin-top: 10px">
36
- <div>Container: {{ width }} x {{ height }}</div>
37
- <div>Natural: {{ naturalWidth }} x {{ naturalHeight }}</div>
38
- <div>Pos: {{ imageLeft }} , {{ imageTop }}</div>
39
- <div>Scale: {{ scale | number: '0.0-2' }}</div>
40
- <div>
41
- Ratio Box , Image: {{ this.ratioBox | number: '0.0-2' }} : 1 , {{ this.ratioImage | number: '0.0-2' }} : 1
42
- </div>
43
- </div>
44
- }
@@ -1,21 +0,0 @@
1
- import { ComponentFixture, TestBed } from '@angular/core/testing';
2
-
3
- import { RatioImageComponent } from './ratio-image.component';
4
-
5
- describe('RatioImageComponent', () => {
6
- let component: RatioImageComponent;
7
- let fixture: ComponentFixture<RatioImageComponent>;
8
-
9
- beforeEach(() => {
10
- TestBed.configureTestingModule({
11
- declarations: [RatioImageComponent]
12
- });
13
- fixture = TestBed.createComponent(RatioImageComponent);
14
- component = fixture.componentInstance;
15
- fixture.detectChanges();
16
- });
17
-
18
- it('should create', () => {
19
- expect(component).toBeTruthy();
20
- });
21
- });
@@ -1,75 +0,0 @@
1
- import { AfterViewInit, Component, Input, OnChanges } from '@angular/core';
2
-
3
- interface Image {
4
- clientWidth: number;
5
- clientHeight: number;
6
- naturalWidth: number;
7
- naturalHeight: number;
8
- }
9
-
10
- @Component({
11
- selector: 'ngx-ratio-image',
12
- templateUrl: 'ratio-image.component.html',
13
- styles: []
14
- })
15
- export class RatioImageComponent implements AfterViewInit, OnChanges {
16
- @Input({ required: true }) public src = '';
17
- @Input({ required: true }) public width = 0;
18
- @Input({ required: true }) public height = 0;
19
- @Input() public debug = false;
20
-
21
- public imageWidth = 0;
22
- public imageHeight = 0;
23
-
24
- public naturalWidth = 0;
25
- public naturalHeight = 0;
26
-
27
- public imageLeft = 0;
28
- public imageTop = 0;
29
- public ratioImage = 1;
30
- public ratioBox = 1;
31
-
32
- public scale = 1;
33
-
34
- constructor() {
35
- if (this.debug) console.log('constructor', this.src);
36
- }
37
-
38
- ngAfterViewInit() {
39
- if (this.debug) console.log('ngAfterViewInit', this.src, this.width, this.height);
40
- }
41
-
42
- onImageLoad(img: Image) {
43
- if (this.debug) console.log('onImageLoad ', img);
44
- if (img) {
45
- this.naturalWidth = img.naturalWidth;
46
- this.naturalHeight = img.naturalHeight;
47
- if (this.width > 0 && this.height > 0) {
48
- this.calculate();
49
- }
50
- }
51
- }
52
-
53
- ngOnChanges(): void {
54
- this.calculate();
55
- }
56
-
57
- private calculate() {
58
- this.ratioImage = this.naturalWidth / this.naturalHeight;
59
- this.ratioBox = this.width / this.height;
60
-
61
- if (this.ratioBox > this.ratioImage) {
62
- this.scale = this.height / this.naturalHeight;
63
- this.imageLeft = (this.width - this.naturalWidth * this.scale) / 2;
64
- } else if (this.ratioBox < this.ratioImage) {
65
- this.scale = this.width / this.naturalWidth;
66
- this.imageTop = (this.height - this.naturalHeight * this.scale) / 2;
67
- } else {
68
- this.scale = this.width / this.naturalWidth;
69
- this.imageLeft = 0;
70
- this.imageTop = 0;
71
- }
72
-
73
- if (this.debug) console.log('calculate', this.src, this.naturalWidth + ' x ' + this.naturalHeight);
74
- }
75
- }
@@ -1,10 +0,0 @@
1
- import { NgModule } from '@angular/core';
2
- import { RatioImageComponent } from './ratio-image/ratio-image.component';
3
- import { DecimalPipe, NgIf } from '@angular/common';
4
-
5
- @NgModule({
6
- declarations: [RatioImageComponent],
7
- imports: [NgIf, DecimalPipe],
8
- exports: [RatioImageComponent]
9
- })
10
- export class RatioImageModule {}
package/src/public-api.ts DELETED
@@ -1,6 +0,0 @@
1
- /*
2
- * Public API Surface of ngx-ratio-image
3
- */
4
-
5
- export * from './lib/ratio-image/ratio-image.component';
6
- export * from './lib/ratio-image.module';
package/tsconfig.lib.json DELETED
@@ -1,12 +0,0 @@
1
- /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
- {
3
- "extends": "../../tsconfig.json",
4
- "compilerOptions": {
5
- "outDir": "../../out-tsc/lib",
6
- "declaration": true,
7
- "declarationMap": true,
8
- "inlineSources": true,
9
- "types": []
10
- },
11
- "exclude": ["**/*.spec.ts"]
12
- }
@@ -1,10 +0,0 @@
1
- /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
- {
3
- "extends": "./tsconfig.lib.json",
4
- "compilerOptions": {
5
- "declarationMap": false
6
- },
7
- "angularCompilerOptions": {
8
- "compilationMode": "partial"
9
- }
10
- }
@@ -1,9 +0,0 @@
1
- /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
- {
3
- "extends": "../../tsconfig.json",
4
- "compilerOptions": {
5
- "outDir": "../../out-tsc/spec",
6
- "types": ["jasmine"]
7
- },
8
- "include": ["**/*.spec.ts", "**/*.d.ts"]
9
- }