ngx-ratio-image 0.1.2 → 0.1.3

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/.eslintrc.json ADDED
@@ -0,0 +1,31 @@
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
+ }
@@ -0,0 +1,7 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-ratio-image",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "author": {
5
5
  "name": "Gerd Siebert"
6
6
  },
@@ -8,7 +8,6 @@
8
8
  "Image",
9
9
  "Scaling",
10
10
  "Ratio",
11
- "Angular 17",
12
11
  "Angular 18",
13
12
  "Angular 19",
14
13
  "Angular 20",
@@ -17,8 +16,8 @@
17
16
  "description": "An Angular lib to show an image with variable ratio in container with a fixed ratio.",
18
17
  "license": "MIT",
19
18
  "peerDependencies": {
20
- "@angular/common": "^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0",
21
- "@angular/core": "^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0"
19
+ "@angular/common": "^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0",
20
+ "@angular/core": "^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0"
22
21
  },
23
22
  "dependencies": {
24
23
  "tslib": "^2.3.0"
@@ -31,18 +30,5 @@
31
30
  "bugs": {
32
31
  "url": "https://github.com/gerd-siebert/ngx-ratio-image/issues"
33
32
  },
34
- "homepage": "https://github.com/gerd-siebert/ngx-ratio-image#readme",
35
- "module": "fesm2022/ngx-ratio-image.mjs",
36
- "typings": "index.d.ts",
37
- "exports": {
38
- "./package.json": {
39
- "default": "./package.json"
40
- },
41
- ".": {
42
- "types": "./index.d.ts",
43
- "esm2022": "./esm2022/ngx-ratio-image.mjs",
44
- "esm": "./esm2022/ngx-ratio-image.mjs",
45
- "default": "./fesm2022/ngx-ratio-image.mjs"
46
- }
47
- }
33
+ "homepage": "https://github.com/gerd-siebert/ngx-ratio-image#readme"
48
34
  }
@@ -0,0 +1,44 @@
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
+ }
@@ -0,0 +1,21 @@
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
+ });
@@ -0,0 +1,75 @@
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
+ }
@@ -0,0 +1,10 @@
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 {}
@@ -1,2 +1,6 @@
1
+ /*
2
+ * Public API Surface of ngx-ratio-image
3
+ */
4
+
1
5
  export * from './lib/ratio-image/ratio-image.component';
2
6
  export * from './lib/ratio-image.module';
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,9 @@
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
+ }
@@ -1,77 +0,0 @@
1
- import { Component, Input } from '@angular/core';
2
- import * as i0 from "@angular/core";
3
- import * as i1 from "@angular/common";
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: "17.3.12", ngImport: i0, type: RatioImageComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
60
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: RatioImageComponent, selector: "ngx-ratio-image", inputs: { src: "src", width: "width", height: "height", debug: "debug" }, usesOnChanges: true, ngImport: i0, template: "<div\n\t[style.position]=\"'relative'\"\n\t[style.z-index]=\"2\"\n\t[style.border]=\"debug ? '1px solid red' : ''\"\n\t[style.width]=\"width + 'px'\"\n\t[style.height]=\"height + 'px'\"\n>\n\t<img\n\t\tclass=\"img-background\"\n\t\t#img\n\t\t[src]=\"src\"\n\t\t[style.position]=\"'absolute'\"\n\t\t[style.z-index]=\"1\"\n\t\t[style.filter]=\"'blur(5px)'\"\n\t\t[style.opacity]=\"0.5\"\n\t\t[width]=\"width\"\n\t\t[height]=\"height\"\n\t\t[style.overflow]=\"'hidden'\"\n\t\t(load)=\"onImageLoad(img)\"\n\t\talt=\"\"\n\t/>\n\t<img\n\t\tclass=\"img-main\"\n\t\t[src]=\"src\"\n\t\t[width]=\"naturalWidth * scale\"\n\t\t[height]=\"naturalHeight * scale\"\n\t\t[style.position]=\"'absolute'\"\n\t\t[style.z-index]=\"2\"\n\t\t[style.left]=\"imageLeft + 'px'\"\n\t\t[style.top]=\"imageTop + 'px'\"\n\t\talt=\"\"\n\t/>\n</div>\n<div *ngIf=\"debug\" style=\"margin-top: 10px\">\n\t<div>Container: {{ width }} x {{ height }}</div>\n\t<div>Natural: {{ naturalWidth }} x {{ naturalHeight }}</div>\n\t<div>Pos: {{ imageLeft }} , {{ imageTop }}</div>\n\t<div>Scale: {{ scale | number: '0.0-2' }}</div>\n\t<div>\n\t\tRatio Box , Image: {{ this.ratioBox | number: '0.0-2' }} : 1 , {{ this.ratioImage | number: '0.0-2' }} : 1\n\t</div>\n</div>\n", dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i1.DecimalPipe, name: "number" }] }); }
61
- }
62
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RatioImageComponent, decorators: [{
63
- type: Component,
64
- args: [{ selector: 'ngx-ratio-image', template: "<div\n\t[style.position]=\"'relative'\"\n\t[style.z-index]=\"2\"\n\t[style.border]=\"debug ? '1px solid red' : ''\"\n\t[style.width]=\"width + 'px'\"\n\t[style.height]=\"height + 'px'\"\n>\n\t<img\n\t\tclass=\"img-background\"\n\t\t#img\n\t\t[src]=\"src\"\n\t\t[style.position]=\"'absolute'\"\n\t\t[style.z-index]=\"1\"\n\t\t[style.filter]=\"'blur(5px)'\"\n\t\t[style.opacity]=\"0.5\"\n\t\t[width]=\"width\"\n\t\t[height]=\"height\"\n\t\t[style.overflow]=\"'hidden'\"\n\t\t(load)=\"onImageLoad(img)\"\n\t\talt=\"\"\n\t/>\n\t<img\n\t\tclass=\"img-main\"\n\t\t[src]=\"src\"\n\t\t[width]=\"naturalWidth * scale\"\n\t\t[height]=\"naturalHeight * scale\"\n\t\t[style.position]=\"'absolute'\"\n\t\t[style.z-index]=\"2\"\n\t\t[style.left]=\"imageLeft + 'px'\"\n\t\t[style.top]=\"imageTop + 'px'\"\n\t\talt=\"\"\n\t/>\n</div>\n<div *ngIf=\"debug\" style=\"margin-top: 10px\">\n\t<div>Container: {{ width }} x {{ height }}</div>\n\t<div>Natural: {{ naturalWidth }} x {{ naturalHeight }}</div>\n\t<div>Pos: {{ imageLeft }} , {{ imageTop }}</div>\n\t<div>Scale: {{ scale | number: '0.0-2' }}</div>\n\t<div>\n\t\tRatio Box , Image: {{ this.ratioBox | number: '0.0-2' }} : 1 , {{ this.ratioImage | number: '0.0-2' }} : 1\n\t</div>\n</div>\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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmF0aW8taW1hZ2UuY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvbmd4LXJhdGlvLWltYWdlL3NyYy9saWIvcmF0aW8taW1hZ2UvcmF0aW8taW1hZ2UuY29tcG9uZW50LnRzIiwiLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvbmd4LXJhdGlvLWltYWdlL3NyYy9saWIvcmF0aW8taW1hZ2UvcmF0aW8taW1hZ2UuY29tcG9uZW50Lmh0bWwiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFpQixTQUFTLEVBQUUsS0FBSyxFQUFhLE1BQU0sZUFBZSxDQUFDOzs7QUFjM0UsTUFBTSxPQUFPLG1CQUFtQjtJQW1CL0I7UUFsQmtDLFFBQUcsR0FBRyxFQUFFLENBQUM7UUFDVCxVQUFLLEdBQUcsQ0FBQyxDQUFDO1FBQ1YsV0FBTSxHQUFHLENBQUMsQ0FBQztRQUM3QixVQUFLLEdBQUcsS0FBSyxDQUFDO1FBRXZCLGVBQVUsR0FBRyxDQUFDLENBQUM7UUFDZixnQkFBVyxHQUFHLENBQUMsQ0FBQztRQUVoQixpQkFBWSxHQ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S5wb3NpdGlvbl09XCInYWJzb2x1dGUnXCJcblx0XHRbc3R5bGUuei1pbmRleF09XCIyXCJcblx0XHRbc3R5bGUubGVmdF09XCJpbWFnZUxlZnQgKyAncHgnXCJcblx0XHRbc3R5bGUudG9wXT1cImltYWdlVG9wICsgJ3B4J1wiXG5cdFx0YWx0PVwiXCJcblx0Lz5cbjwvZGl2PlxuPGRpdiAqbmdJZj1cImRlYnVnXCIgc3R5bGU9XCJtYXJnaW4tdG9wOiAxMHB4XCI+XG5cdDxkaXY+Q29udGFpbmVyOiB7eyB3aWR0aCB9fSB4IHt7IGhlaWdodCB9fTwvZGl2PlxuXHQ8ZGl2Pk5hdHVyYWw6IHt7IG5hdHVyYWxXaWR0aCB9fSB4IHt7IG5hdHVyYWxIZWlnaHQgfX08L2Rpdj5cblx0PGRpdj5Qb3M6IHt7IGltYWdlTGVmdCB9fSAsIHt7IGltYWdlVG9wIH19PC9kaXY+XG5cdDxkaXY+U2NhbGU6IHt7IHNjYWxlIHwgbnVtYmVyOiAnMC4wLTInIH19PC9kaXY+XG5cdDxkaXY+XG5cdFx0UmF0aW8gQm94ICwgSW1hZ2U6IHt7IHRoaXMucmF0aW9Cb3ggfCBudW1iZXI6ICcwLjAtMicgfX0gOiAxICwge3sgdGhpcy5yYXRpb0ltYWdlIHwgbnVtYmVyOiAnMC4wLTInIH19IDogMVxuXHQ8L2Rpdj5cbjwvZGl2PlxuIl19
@@ -1,18 +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
- import * as i0 from "@angular/core";
5
- export class RatioImageModule {
6
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RatioImageModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
7
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: RatioImageModule, declarations: [RatioImageComponent], imports: [NgIf, DecimalPipe], exports: [RatioImageComponent] }); }
8
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RatioImageModule }); }
9
- }
10
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RatioImageModule, decorators: [{
11
- type: NgModule,
12
- args: [{
13
- declarations: [RatioImageComponent],
14
- imports: [NgIf, DecimalPipe],
15
- exports: [RatioImageComponent]
16
- }]
17
- }] });
18
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmF0aW8taW1hZ2UubW9kdWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvbmd4LXJhdGlvLWltYWdlL3NyYy9saWIvcmF0aW8taW1hZ2UubW9kdWxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDekMsT0FBTyxFQUFFLG1CQUFtQixFQUFFLE1BQU0scUNBQXFDLENBQUM7QUFDMUUsT0FBTyxFQUFFLFdBQVcsRUFBRSxJQUFJLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQzs7QUFPcEQsTUFBTSxPQUFPLGdCQUFnQjsrR0FBaEIsZ0JBQWdCO2dIQUFoQixnQkFBZ0IsaUJBSmIsbUJBQW1CLGFBQ3hCLElBQUksRUFBRSxXQUFXLGFBQ2pCLG1CQUFtQjtnSEFFakIsZ0JBQWdCOzs0RkFBaEIsZ0JBQWdCO2tCQUw1QixRQUFRO21CQUFDO29CQUNULFlBQVksRUFBRSxDQUFDLG1CQUFtQixDQUFDO29CQUNuQyxPQUFPLEVBQUUsQ0FBQyxJQUFJLEVBQUUsV0FBVyxDQUFDO29CQUM1QixPQUFPLEVBQUUsQ0FBQyxtQkFBbUIsQ0FBQztpQkFDOUIiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBOZ01vZHVsZSB9IGZyb20gJ0Bhbmd1bGFyL2NvcmUnO1xuaW1wb3J0IHsgUmF0aW9JbWFnZUNvbXBvbmVudCB9IGZyb20gJy4vcmF0aW8taW1hZ2UvcmF0aW8taW1hZ2UuY29tcG9uZW50JztcbmltcG9ydCB7IERlY2ltYWxQaXBlLCBOZ0lmIH0gZnJvbSAnQGFuZ3VsYXIvY29tbW9uJztcblxuQE5nTW9kdWxlKHtcblx0ZGVjbGFyYXRpb25zOiBbUmF0aW9JbWFnZUNvbXBvbmVudF0sXG5cdGltcG9ydHM6IFtOZ0lmLCBEZWNpbWFsUGlwZV0sXG5cdGV4cG9ydHM6IFtSYXRpb0ltYWdlQ29tcG9uZW50XVxufSlcbmV4cG9ydCBjbGFzcyBSYXRpb0ltYWdlTW9kdWxlIHt9XG4iXX0=
@@ -1,5 +0,0 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- export * from './public-api';
5
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmd4LXJhdGlvLWltYWdlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vcHJvamVjdHMvbmd4LXJhdGlvLWltYWdlL3NyYy9uZ3gtcmF0aW8taW1hZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O0dBRUc7QUFFSCxjQUFjLGNBQWMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogR2VuZXJhdGVkIGJ1bmRsZSBpbmRleC4gRG8gbm90IGVkaXQuXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9wdWJsaWMtYXBpJztcbiJdfQ==
@@ -1,6 +0,0 @@
1
- /*
2
- * Public API Surface of ngx-ratio-image
3
- */
4
- export * from './lib/ratio-image/ratio-image.component';
5
- export * from './lib/ratio-image.module';
6
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL25neC1yYXRpby1pbWFnZS9zcmMvcHVibGljLWFwaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUVILGNBQWMseUNBQXlDLENBQUM7QUFDeEQsY0FBYywwQkFBMEIsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qXG4gKiBQdWJsaWMgQVBJIFN1cmZhY2Ugb2Ygbmd4LXJhdGlvLWltYWdlXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9saWIvcmF0aW8taW1hZ2UvcmF0aW8taW1hZ2UuY29tcG9uZW50JztcbmV4cG9ydCAqIGZyb20gJy4vbGliL3JhdGlvLWltYWdlLm1vZHVsZSc7XG4iXX0=
@@ -1,103 +0,0 @@
1
- import * as i0 from '@angular/core';
2
- import { Input, Component, NgModule } from '@angular/core';
3
- import * as i1 from '@angular/common';
4
- import { NgIf, DecimalPipe } from '@angular/common';
5
-
6
- class RatioImageComponent {
7
- constructor() {
8
- this.src = '';
9
- this.width = 0;
10
- this.height = 0;
11
- this.debug = false;
12
- this.imageWidth = 0;
13
- this.imageHeight = 0;
14
- this.naturalWidth = 0;
15
- this.naturalHeight = 0;
16
- this.imageLeft = 0;
17
- this.imageTop = 0;
18
- this.ratioImage = 1;
19
- this.ratioBox = 1;
20
- this.scale = 1;
21
- if (this.debug)
22
- console.log('constructor', this.src);
23
- }
24
- ngAfterViewInit() {
25
- if (this.debug)
26
- console.log('ngAfterViewInit', this.src, this.width, this.height);
27
- }
28
- onImageLoad(img) {
29
- if (this.debug)
30
- console.log('onImageLoad ', img);
31
- if (img) {
32
- this.naturalWidth = img.naturalWidth;
33
- this.naturalHeight = img.naturalHeight;
34
- if (this.width > 0 && this.height > 0) {
35
- this.calculate();
36
- }
37
- }
38
- }
39
- ngOnChanges() {
40
- this.calculate();
41
- }
42
- calculate() {
43
- this.ratioImage = this.naturalWidth / this.naturalHeight;
44
- this.ratioBox = this.width / this.height;
45
- if (this.ratioBox > this.ratioImage) {
46
- this.scale = this.height / this.naturalHeight;
47
- this.imageLeft = (this.width - this.naturalWidth * this.scale) / 2;
48
- }
49
- else if (this.ratioBox < this.ratioImage) {
50
- this.scale = this.width / this.naturalWidth;
51
- this.imageTop = (this.height - this.naturalHeight * this.scale) / 2;
52
- }
53
- else {
54
- this.scale = this.width / this.naturalWidth;
55
- this.imageLeft = 0;
56
- this.imageTop = 0;
57
- }
58
- if (this.debug)
59
- console.log('calculate', this.src, this.naturalWidth + ' x ' + this.naturalHeight);
60
- }
61
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RatioImageComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
62
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: RatioImageComponent, selector: "ngx-ratio-image", inputs: { src: "src", width: "width", height: "height", debug: "debug" }, usesOnChanges: true, ngImport: i0, template: "<div\n\t[style.position]=\"'relative'\"\n\t[style.z-index]=\"2\"\n\t[style.border]=\"debug ? '1px solid red' : ''\"\n\t[style.width]=\"width + 'px'\"\n\t[style.height]=\"height + 'px'\"\n>\n\t<img\n\t\tclass=\"img-background\"\n\t\t#img\n\t\t[src]=\"src\"\n\t\t[style.position]=\"'absolute'\"\n\t\t[style.z-index]=\"1\"\n\t\t[style.filter]=\"'blur(5px)'\"\n\t\t[style.opacity]=\"0.5\"\n\t\t[width]=\"width\"\n\t\t[height]=\"height\"\n\t\t[style.overflow]=\"'hidden'\"\n\t\t(load)=\"onImageLoad(img)\"\n\t\talt=\"\"\n\t/>\n\t<img\n\t\tclass=\"img-main\"\n\t\t[src]=\"src\"\n\t\t[width]=\"naturalWidth * scale\"\n\t\t[height]=\"naturalHeight * scale\"\n\t\t[style.position]=\"'absolute'\"\n\t\t[style.z-index]=\"2\"\n\t\t[style.left]=\"imageLeft + 'px'\"\n\t\t[style.top]=\"imageTop + 'px'\"\n\t\talt=\"\"\n\t/>\n</div>\n<div *ngIf=\"debug\" style=\"margin-top: 10px\">\n\t<div>Container: {{ width }} x {{ height }}</div>\n\t<div>Natural: {{ naturalWidth }} x {{ naturalHeight }}</div>\n\t<div>Pos: {{ imageLeft }} , {{ imageTop }}</div>\n\t<div>Scale: {{ scale | number: '0.0-2' }}</div>\n\t<div>\n\t\tRatio Box , Image: {{ this.ratioBox | number: '0.0-2' }} : 1 , {{ this.ratioImage | number: '0.0-2' }} : 1\n\t</div>\n</div>\n", dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i1.DecimalPipe, name: "number" }] }); }
63
- }
64
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RatioImageComponent, decorators: [{
65
- type: Component,
66
- args: [{ selector: 'ngx-ratio-image', template: "<div\n\t[style.position]=\"'relative'\"\n\t[style.z-index]=\"2\"\n\t[style.border]=\"debug ? '1px solid red' : ''\"\n\t[style.width]=\"width + 'px'\"\n\t[style.height]=\"height + 'px'\"\n>\n\t<img\n\t\tclass=\"img-background\"\n\t\t#img\n\t\t[src]=\"src\"\n\t\t[style.position]=\"'absolute'\"\n\t\t[style.z-index]=\"1\"\n\t\t[style.filter]=\"'blur(5px)'\"\n\t\t[style.opacity]=\"0.5\"\n\t\t[width]=\"width\"\n\t\t[height]=\"height\"\n\t\t[style.overflow]=\"'hidden'\"\n\t\t(load)=\"onImageLoad(img)\"\n\t\talt=\"\"\n\t/>\n\t<img\n\t\tclass=\"img-main\"\n\t\t[src]=\"src\"\n\t\t[width]=\"naturalWidth * scale\"\n\t\t[height]=\"naturalHeight * scale\"\n\t\t[style.position]=\"'absolute'\"\n\t\t[style.z-index]=\"2\"\n\t\t[style.left]=\"imageLeft + 'px'\"\n\t\t[style.top]=\"imageTop + 'px'\"\n\t\talt=\"\"\n\t/>\n</div>\n<div *ngIf=\"debug\" style=\"margin-top: 10px\">\n\t<div>Container: {{ width }} x {{ height }}</div>\n\t<div>Natural: {{ naturalWidth }} x {{ naturalHeight }}</div>\n\t<div>Pos: {{ imageLeft }} , {{ imageTop }}</div>\n\t<div>Scale: {{ scale | number: '0.0-2' }}</div>\n\t<div>\n\t\tRatio Box , Image: {{ this.ratioBox | number: '0.0-2' }} : 1 , {{ this.ratioImage | number: '0.0-2' }} : 1\n\t</div>\n</div>\n" }]
67
- }], ctorParameters: () => [], propDecorators: { src: [{
68
- type: Input,
69
- args: [{ required: true }]
70
- }], width: [{
71
- type: Input,
72
- args: [{ required: true }]
73
- }], height: [{
74
- type: Input,
75
- args: [{ required: true }]
76
- }], debug: [{
77
- type: Input
78
- }] } });
79
-
80
- class RatioImageModule {
81
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RatioImageModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
82
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: RatioImageModule, declarations: [RatioImageComponent], imports: [NgIf, DecimalPipe], exports: [RatioImageComponent] }); }
83
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RatioImageModule }); }
84
- }
85
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: RatioImageModule, decorators: [{
86
- type: NgModule,
87
- args: [{
88
- declarations: [RatioImageComponent],
89
- imports: [NgIf, DecimalPipe],
90
- exports: [RatioImageComponent]
91
- }]
92
- }] });
93
-
94
- /*
95
- * Public API Surface of ngx-ratio-image
96
- */
97
-
98
- /**
99
- * Generated bundle index. Do not edit.
100
- */
101
-
102
- export { RatioImageComponent, RatioImageModule };
103
- //# sourceMappingURL=ngx-ratio-image.mjs.map
@@ -1 +0,0 @@
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/lib/ratio-image.module.ts","../../../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';\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})\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\t[style.position]=\"'relative'\"\n\t[style.z-index]=\"2\"\n\t[style.border]=\"debug ? '1px solid red' : ''\"\n\t[style.width]=\"width + 'px'\"\n\t[style.height]=\"height + 'px'\"\n>\n\t<img\n\t\tclass=\"img-background\"\n\t\t#img\n\t\t[src]=\"src\"\n\t\t[style.position]=\"'absolute'\"\n\t\t[style.z-index]=\"1\"\n\t\t[style.filter]=\"'blur(5px)'\"\n\t\t[style.opacity]=\"0.5\"\n\t\t[width]=\"width\"\n\t\t[height]=\"height\"\n\t\t[style.overflow]=\"'hidden'\"\n\t\t(load)=\"onImageLoad(img)\"\n\t\talt=\"\"\n\t/>\n\t<img\n\t\tclass=\"img-main\"\n\t\t[src]=\"src\"\n\t\t[width]=\"naturalWidth * scale\"\n\t\t[height]=\"naturalHeight * scale\"\n\t\t[style.position]=\"'absolute'\"\n\t\t[style.z-index]=\"2\"\n\t\t[style.left]=\"imageLeft + 'px'\"\n\t\t[style.top]=\"imageTop + 'px'\"\n\t\talt=\"\"\n\t/>\n</div>\n<div *ngIf=\"debug\" style=\"margin-top: 10px\">\n\t<div>Container: {{ width }} x {{ height }}</div>\n\t<div>Natural: {{ naturalWidth }} x {{ naturalHeight }}</div>\n\t<div>Pos: {{ imageLeft }} , {{ imageTop }}</div>\n\t<div>Scale: {{ scale | number: '0.0-2' }}</div>\n\t<div>\n\t\tRatio Box , Image: {{ this.ratioBox | number: '0.0-2' }} : 1 , {{ this.ratioImage | number: '0.0-2' }} : 1\n\t</div>\n</div>\n","import { NgModule } from '@angular/core';\nimport { RatioImageComponent } from './ratio-image/ratio-image.component';\nimport { DecimalPipe, NgIf } from '@angular/common';\n\n@NgModule({\n\tdeclarations: [RatioImageComponent],\n\timports: [NgIf, DecimalPipe],\n\texports: [RatioImageComponent]\n})\nexport class RatioImageModule {}\n","/*\n * Public API Surface of ngx-ratio-image\n */\n\nexport * from './lib/ratio-image/ratio-image.component';\nexport * from './lib/ratio-image.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAca,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,iBAAiB,EAAE,IAAI,CAA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A;sBAApB;;;METW,gBAAgB,CAAA;+GAAhB,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;AAAhB,IAAA,SAAA,IAAA,CAAA,IAAA,GAAA,EAAA,CAAA,mBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,gBAAgB,iBAJb,mBAAmB,CAAA,EAAA,OAAA,EAAA,CACxB,IAAI,EAAE,WAAW,aACjB,mBAAmB,CAAA,EAAA,CAAA,CAAA;gHAEjB,gBAAgB,EAAA,CAAA,CAAA;;4FAAhB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAL5B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;oBACT,YAAY,EAAE,CAAC,mBAAmB,CAAC;AACnC,oBAAA,OAAO,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC;oBAC5B,OAAO,EAAE,CAAC,mBAAmB;AAC7B,iBAAA;;;ACRD;;AAEG;;ACFH;;AAEG;;;;"}
package/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- /// <amd-module name="ngx-ratio-image" />
5
- export * from './public-api';
@@ -1,31 +0,0 @@
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, false, never>;
30
- }
31
- export {};
@@ -1,8 +0,0 @@
1
- import * as i0 from "@angular/core";
2
- import * as i1 from "./ratio-image/ratio-image.component";
3
- import * as i2 from "@angular/common";
4
- export declare class RatioImageModule {
5
- static ɵfac: i0.ɵɵFactoryDeclaration<RatioImageModule, never>;
6
- static ɵmod: i0.ɵɵNgModuleDeclaration<RatioImageModule, [typeof i1.RatioImageComponent], [typeof i2.NgIf, typeof i2.DecimalPipe], [typeof i1.RatioImageComponent]>;
7
- static ɵinj: i0.ɵɵInjectorDeclaration<RatioImageModule>;
8
- }