Fix: Issues #14,#15,#19,#20. Ref: Deleted angular-librarian and added scripts in package.json to manage publishing; Version upgrade
This commit is contained in:
parent
2726231e1a
commit
c1d07a1af1
65 changed files with 22464 additions and 1460 deletions
|
|
@ -1,15 +0,0 @@
|
|||
/* tslint:disable:no-unused-variable */
|
||||
import {
|
||||
async,
|
||||
TestBed
|
||||
} from '@angular/core/testing';
|
||||
|
||||
import { Ng2FittextDirective } from './ng2-fittext.directive';
|
||||
|
||||
describe('Ng2FittextDirective', () => {
|
||||
it('', () => {
|
||||
const directive = new Ng2FittextDirective();
|
||||
|
||||
expect(directive).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,4 +1,13 @@
|
|||
import {Directive, ElementRef, Renderer, Input, AfterViewInit, AfterViewChecked, HostListener, OnInit, OnChanges} from '@angular/core';
|
||||
import {
|
||||
AfterViewChecked,
|
||||
AfterViewInit,
|
||||
Directive,
|
||||
ElementRef, HostListener,
|
||||
Input,
|
||||
OnChanges,
|
||||
OnInit,
|
||||
Renderer2
|
||||
} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[fittext]'
|
||||
|
|
@ -7,7 +16,7 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
|
||||
@Input('fittext') fittext: any;
|
||||
@Input('activateOnResize') activateOnResize: boolean;
|
||||
@Input('container') container: any;
|
||||
@Input('container') container: HTMLElement;
|
||||
@Input('activateOnInputEvents') activateOnInputEvents: boolean;
|
||||
@Input('useMaxFontSize') useMaxFontSize: boolean;
|
||||
@Input('minFontSize') minFontSize = 7;
|
||||
|
|
@ -17,10 +26,11 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
private speed = 1.05;
|
||||
private done = false;
|
||||
|
||||
constructor(public el: ElementRef, public renderer: Renderer) { }
|
||||
constructor(public el: ElementRef,
|
||||
public renderer: Renderer2) {}
|
||||
|
||||
setFontSize(fontSize) {
|
||||
if (this.isVisible() && this.done === false) {
|
||||
setFontSize(fontSize: number) {
|
||||
if (this.isVisible() && !this.done) {
|
||||
if (fontSize < this.minFontSize) {
|
||||
// force that font size will never be lower than minimal allowed font size
|
||||
fontSize = this.minFontSize;
|
||||
|
|
@ -31,7 +41,7 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
}
|
||||
}
|
||||
|
||||
calculateFontSize(fontSize, speed) {
|
||||
calculateFontSize(fontSize: number, speed: number) {
|
||||
// TODO Do with Gauss
|
||||
return Math.floor(fontSize / speed);
|
||||
}
|
||||
|
|
@ -68,7 +78,10 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
ngOnInit() {
|
||||
this.done = false;
|
||||
if (this.useMaxFontSize) {
|
||||
this.maxFontSize = parseInt(this.getComputetStyle().fontSize, null);
|
||||
const fontSize = this.getComputetStyle().fontSize;
|
||||
if (fontSize) {
|
||||
this.maxFontSize = parseInt(fontSize, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.fittext) {
|
||||
|
|
@ -76,10 +89,11 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
}
|
||||
|
||||
this.el.nativeElement.style.setProperty('will-change', 'content');
|
||||
this.ngAfterViewInit();
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
if (this.isVisible() && this.done === false) {
|
||||
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);
|
||||
|
|
@ -92,8 +106,11 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
} else {
|
||||
if (this.useMaxFontSize) {
|
||||
if (this.fontSize > this.maxFontSize) {
|
||||
this.maxFontSize = parseInt(this.getComputetStyle().fontSize, null);
|
||||
this.setFontSize(this.maxFontSize);
|
||||
const fontSize = this.getComputetStyle().fontSize;
|
||||
if (fontSize) {
|
||||
this.maxFontSize = parseInt(fontSize, undefined);
|
||||
this.setFontSize(this.maxFontSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.done = true;
|
||||
|
|
@ -105,7 +122,11 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
ngOnChanges(changes: any): void {
|
||||
if (changes.modelToWatch) {
|
||||
// change of model to watch - call ngAfterViewInit where is implemented logic to change size
|
||||
setTimeout(_ => this.ngAfterViewInit() );
|
||||
setTimeout(() => {
|
||||
this.done = false;
|
||||
this.setFontSize(this.maxFontSize);
|
||||
this.ngAfterViewInit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
28
src/distPackage.json
Normal file
28
src/distPackage.json
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "angular-amazing",
|
||||
"version": "1.0.0",
|
||||
"description": "An amazing module for Angular.",
|
||||
"main": "bundles/amazing.umd.js",
|
||||
"module": "index.js",
|
||||
"typings": "index.d.ts",
|
||||
"keywords": [
|
||||
"angular",
|
||||
"angular2",
|
||||
"angular 2",
|
||||
"angular4"
|
||||
],
|
||||
"author": "Your name",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/youraccount/angular-amazing.git"
|
||||
},
|
||||
"homepage": "https://github.com/youraccount/angular-amazing",
|
||||
"bugs": {
|
||||
"url": "https://github.com/youraccount/angular-amazing/issues"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@angular/core": "^2.4.0 || ^4.0.0",
|
||||
"rxjs": "^5.0.1"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Ng2FittextDirective } from './directives/ng2-fittext.directive';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
|
|
|||
24
src/test.js
24
src/test.js
|
|
@ -1,24 +0,0 @@
|
|||
require('core-js/es6');
|
||||
require('core-js/es7');
|
||||
require('zone.js/dist/zone');
|
||||
require('zone.js/dist/long-stack-trace-zone');
|
||||
require('zone.js/dist/async-test');
|
||||
require('zone.js/dist/fake-async-test');
|
||||
require('zone.js/dist/sync-test');
|
||||
require('zone.js/dist/proxy');
|
||||
require('zone.js/dist/jasmine-patch');
|
||||
|
||||
const browserTesting = require('@angular/platform-browser-dynamic/testing');
|
||||
const coreTesting = require('@angular/core/testing');
|
||||
const context = require.context('./', true, /\.spec\.ts$/);
|
||||
|
||||
Error.stackTraceLimit = Infinity;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;
|
||||
|
||||
coreTesting.TestBed.resetTestEnvironment();
|
||||
coreTesting.TestBed.initTestEnvironment(
|
||||
browserTesting.BrowserDynamicTestingModule,
|
||||
browserTesting.platformBrowserDynamicTesting()
|
||||
);
|
||||
|
||||
context.keys().forEach(context);
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// polyfills Angular 2 requires to be loaded BEFORE the application
|
||||
// only used in library development--not packaged
|
||||
import 'core-js/es6/symbol';
|
||||
import 'core-js/es6/object';
|
||||
import 'core-js/es6/function';
|
||||
import 'core-js/es6/parse-int';
|
||||
import 'core-js/es6/parse-float';
|
||||
import 'core-js/es6/number';
|
||||
import 'core-js/es6/math';
|
||||
import 'core-js/es6/string';
|
||||
import 'core-js/es6/date';
|
||||
import 'core-js/es6/array';
|
||||
import 'core-js/es6/regexp';
|
||||
import 'core-js/es6/map';
|
||||
import 'core-js/es6/set';
|
||||
import 'core-js/es6/reflect';
|
||||
|
||||
import 'core-js/es7/reflect';
|
||||
import 'zone.js/dist/zone';
|
||||
Loading…
Add table
Add a link
Reference in a new issue