UNPKG

a4-fit-text

Version:

Angular Fit Text (Auto scale text to fit container) component

16 lines (14 loc) 4.13 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("rxjs"),require("rxjs/operators"),require("@angular/common")):"function"==typeof define&&define.amd?define("a4-fit-text",["exports","@angular/core","rxjs","rxjs/operators","@angular/common"],e):e((t=t||self)["a4-fit-text"]={},t.ng.core,t.rxjs,t.rxjs.operators,t.ng.common)}(this,(function(t,e,n,r,i){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */function o(t,e,n,r){var i,o=arguments.length,s=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(s=(o<3?i(s):o>3?i(e,n,s):i(e,n))||s);return o>3&&s&&Object.defineProperty(e,n,s),s}function s(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var a=function(){function t(t){this.elementRef=t,this.text$=new n.BehaviorSubject(null),this.width$=new n.BehaviorSubject(0),this.height$=new n.BehaviorSubject(0),this.g0Transform$=new n.BehaviorSubject(""),this.g1Transform$=new n.BehaviorSubject(""),this.g2Transform$=new n.BehaviorSubject(""),this.ready=!1}return Object.defineProperty(t.prototype,"text",{set:function(t){this.text$.next(t)},enumerable:!0,configurable:!0}),t.prototype.ngOnInit=function(){var t=this;this.text$.pipe(r.filter((function(e){return!!e&&t.ready}))).subscribe((function(e){return t.update()}))},t.prototype.ngAfterViewInit=function(){var t=this;this.ready=!0,this.g1Rect=this.g1.nativeElement.getBBox(),setTimeout((function(){return t.update()}),0)},t.prototype.update=function(){this.g2Transform$.next("translate(0, -"+this.g1Rect.height/2+")");var t=this.elementRef.nativeElement.parentNode.getBoundingClientRect(),e=t.width/this.g1Rect.width,n=t.height/this.g1Rect.height,r=Math.min(e,n);this.g1Transform$.next("scale("+r+")");var i=t.width/2,o=t.height/2-this.g1Rect.y;this.g0Transform$.next("translate("+i+", "+o+")"),this.width$.next(t.width),this.height$.next(t.height)},t.prototype.resize=function(t){this.update()},t.ctorParameters=function(){return[{type:e.ElementRef}]},o([e.Input(),s("design:type",String),s("design:paramtypes",[String])],t.prototype,"text",null),o([e.ViewChild("g1",{static:!0}),s("design:type",e.ElementRef)],t.prototype,"g1",void 0),o([e.HostListener("window:resize",["$event"]),s("design:type",Function),s("design:paramtypes",[Object]),s("design:returntype",void 0)],t.prototype,"resize",null),t=o([e.Component({selector:"fit-text",template:'\n <svg #svg [attr.width]="width$ | async" [attr.height]="height$ | async">\n <g #g0 [attr.transform]="g0Transform$ | async">\n <g #g1 [attr.transform]="g1Transform$ | async">\n <g #g2 [attr.transform]="g2Transform$ | async">\n <text #te text-anchor="middle" dy="1em">{{text$ | async}}</text>\n </g>\n </g>\n </g>\n </svg>\n ',changeDetection:e.ChangeDetectionStrategy.OnPush,styles:["\n:host {\n display: block;\n}\n "]}),s("design:paramtypes",[e.ElementRef])],t)}(),c=function(){function t(){}return t=o([e.NgModule({imports:[i.CommonModule],declarations:[a],exports:[a]})],t)}();t.FitTextComponent=a,t.FitTextModule=c,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=a4-fit-text.umd.min.js.map