Merge pull request #31 from giacomoferlaino/master

Prettier code formatter integration
This commit is contained in:
Lorenzo Iovino 2020-03-12 12:41:00 +01:00 committed by GitHub
commit dcca18224b
7 changed files with 152 additions and 2382 deletions

4
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,4 @@
{
"prettier.configPath": "./src/.prettierrc",
"editor.formatOnSave": true
}

2
package-lock.json generated
View file

@ -1,6 +1,6 @@
{
"name": "ng2-fittext",
"version": "1.2.9",
"version": "1.2.10",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

7
src/.prettierrc Normal file
View file

@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"arrowParens": "always"
}

View file

@ -2,20 +2,21 @@ import {
AfterViewChecked,
AfterViewInit,
Directive,
ElementRef, HostListener,
ElementRef,
HostListener,
Input,
Output,
EventEmitter,
OnChanges,
OnInit,
Renderer2
Renderer2,
} from '@angular/core';
@Directive({
selector: '[fittext]'
selector: '[fittext]',
})
export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, AfterViewChecked {
export class Ng2FittextDirective
implements AfterViewInit, OnInit, OnChanges, AfterViewChecked {
@Input('fittext') fittext: any;
@Input('activateOnResize') activateOnResize: boolean;
@Input('container') container: HTMLElement;
@ -34,21 +35,23 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
private speed = 1.05;
private done = false;
constructor(public el: ElementRef,
public renderer: Renderer2) {}
constructor(public el: ElementRef, public renderer: Renderer2) {}
setFontSize(fontSize: number) {
if (this.isVisible() && !this.done) {
if (fontSize < this.minFontSize) {
fontSize = this.minFontSize;
}
if(fontSize > this.maxFontSize){
if (fontSize > this.maxFontSize) {
fontSize = this.maxFontSize;
}
this.fontSize = fontSize;
this.fontSizeChanged.emit(fontSize);
return this.el.nativeElement.style.setProperty('font-size', (fontSize).toString() + 'px');
return this.el.nativeElement.style.setProperty(
'font-size',
fontSize.toString() + 'px'
);
}
}
@ -59,7 +62,7 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
checkOverflow(parent: any, children: any) {
const overflowX = children.scrollWidth - parent.clientWidth;
const overflowY = children.clientHeight - parent.clientHeight;
return (overflowX > 1 || overflowY > 1);
return overflowX > 1 || overflowY > 1;
}
@HostListener('window:resize', ['$event'])
@ -94,8 +97,12 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
ngAfterViewInit() {
if (this.isVisible() && !this.done) {
if (this.fittext) {
const overflow = this.container ? this.checkOverflow(this.container, this.el.nativeElement)
: this.checkOverflow(this.el.nativeElement.parentElement, this.el.nativeElement);
const overflow = this.container
? this.checkOverflow(this.container, this.el.nativeElement)
: this.checkOverflow(
this.el.nativeElement.parentElement,
this.el.nativeElement
);
if (overflow) {
if (this.fontSize > this.minFontSize) {
// iterate only until font size is bigger than minimal value
@ -128,11 +135,15 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
}
private getStartFontSizeFromHeight(): number {
return this.container ? this.container.clientHeight : this.el.nativeElement.parentElement.clientHeight;
return this.container
? this.container.clientHeight
: this.el.nativeElement.parentElement.clientHeight;
}
private getStartFontSizeFromWeight(): number {
return this.container ? this.container.clientWidth : this.el.nativeElement.parentElement.clientWidth;
return this.container
? this.container.clientWidth
: this.el.nativeElement.parentElement.clientWidth;
}
private isVisible(): boolean {

View file

@ -1,23 +1,17 @@
import { Ng2FittextDirective } from './directives/ng2-fittext.directive';
import {CommonModule} from '@angular/common';
import {NgModule} from "@angular/core";
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
@NgModule({
declarations: [
Ng2FittextDirective
],
exports: [
Ng2FittextDirective
],
imports: [
CommonModule
]
declarations: [Ng2FittextDirective],
exports: [Ng2FittextDirective],
imports: [CommonModule],
})
export class Ng2FittextModule {
static forRoot() {
return {
ngModule: Ng2FittextModule,
providers: []
providers: [],
};
}
}

2259
src/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -29,5 +29,8 @@
},
"repository": {
"url": "https://github.com/lokenxo/ng2-fittext.git"
},
"devDependencies": {
"prettier": "^1.19.1"
}
}