UNPKG

@lxlib/seed

Version:

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.

16 lines (14 loc) 8.4 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/common"),require("@angular/core"),require("@angular/platform-browser"),require("@lxlib/util"),require("rxjs/operators"),require("@angular/cdk/observers"),require("ng-zorro-antd/tooltip")):"function"==typeof define&&define.amd?define("@lxlib/seed/ellipsis",["exports","@angular/common","@angular/core","@angular/platform-browser","@lxlib/util","rxjs/operators","@angular/cdk/observers","ng-zorro-antd/tooltip"],e):e(((t=t||self).lxlib=t.lxlib||{},t.lxlib.seed=t.lxlib.seed||{},t.lxlib.seed.ellipsis={}),t.ng.common,t.ng.core,t.ng.platformBrowser,t.lxlib.util,t.rxjs.operators,t.ng.cdk.observers,t["ng-zorro-antd/tooltip"])}(this,(function(t,e,n,i,l,o,r,s){"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 a(t,e,n,i){var l,o=arguments.length,r=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,i);else for(var s=t.length-1;s>=0;s--)(l=t[s])&&(r=(o<3?l(r):o>3?l(e,n,r):l(e,n))||r);return o>3&&r&&Object.defineProperty(e,n,r),r}function p(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function c(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,l,o=n.call(t),r=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)r.push(i.value)}catch(t){l={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(l)throw l.error}}return r}function g(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(c(arguments[e]));return t}var u=function(){function t(t,e,n,i,l){this.el=t,this.ngZone=e,this.dom=n,this.doc=i,this.cdr=l,this.isSupportLineClamp=void 0!==this.doc.body.style.webkitLineClamp,this.inited=!1,this.type="default",this.cls={},this.text="",this.targetCount=0,this.tooltip=!1,this.fullWidthRecognition=!1,this.tail="..."}return Object.defineProperty(t.prototype,"linsWord",{get:function(){var t=this.targetCount,e=this.text,n=this.tail;return(t>0?e.substring(0,t):"")+(t>0&&t<e.length?n:"")},enumerable:!0,configurable:!0}),t.prototype.getStrFullLength=function(t){return t.split("").reduce((function(t,e){var n=e.charCodeAt(0);return n>=0&&n<=128?t+1:t+2}),0)},t.prototype.cutStrByFullLength=function(t,e){var n=0;return t.split("").reduce((function(t,i){var l=i.charCodeAt(0);return(n+=l>=0&&l<=128?1:2)<=e?t+i:t}),"")},t.prototype.bisection=function(t,e,n,i,l,o){var r=this.tail;o.innerHTML=l.substring(0,e)+r;var s=o.offsetHeight;return s<=t?(o.innerHTML=l.substring(0,e+1)+r,(s=o.offsetHeight)>t||e===n?e:(e=i-(n=e)==1?n+1:Math.floor((i-n)/2)+n,this.bisection(t,e,n,i,l,o))):e-1<0?e:(o.innerHTML=l.substring(0,e-1)+r,(s=o.offsetHeight)<=t?e-1:(i=e,e=Math.floor((i-n)/2)+n,this.bisection(t,e,n,i,l,o)))},t.prototype.genType=function(){var t=this.lines,e=this.length,n=this.isSupportLineClamp;this.cls={ellipsis:!0,ellipsis__lines:t&&!n,"ellipsis__line-clamp":t&&n},this.type=t||e?t?n?"line-clamp":"line":"length":"default"},t.prototype.gen=function(){var t=this,e=t.type,n=t.lines,i=t.length,l=t.fullWidthRecognition,o=t.tail,r=t.orgEl,s=t.cdr,a=t.ngZone;if("length"===e){var p=r.nativeElement;if(p.children.length>0)throw new Error("Ellipsis content must be string.");var c=p.textContent;if((l?this.getStrFullLength(c):c.length)<=i||i<0)this.text=c;else{var g=void 0;g=i-o.length<=0?"":l?this.cutStrByFullLength(c,i):c.slice(0,i),this.text=g+o}a.run((function(){return s.detectChanges()}))}else if("line"===e){var u=this.shadowOrgEl,h=this.shadowTextEl,d=u.nativeElement,f=d.innerText||d.textContent,m=n*parseInt(getComputedStyle(this.getEl(".ellipsis")).lineHeight,10);if(this.getEl(".ellipsis__handle").style.height=m+"px",d.offsetHeight<=m)this.text=f,this.targetCount=f.length;else{var y=f.length,v=Math.ceil(y/2),b=this.bisection(m,v,0,y,f,h.nativeElement.firstChild);this.text=f,this.targetCount=b}a.run((function(){return s.detectChanges()}))}},t.prototype.getEl=function(t){return this.el.nativeElement.querySelector(t)},t.prototype.executeOnStable=function(t){this.ngZone.isStable?t():this.ngZone.onStable.asObservable().pipe(o.take(1)).subscribe(t)},t.prototype.refresh=function(){var t=this;this.genType();var e=this.type,n=this.dom,i=this.orgEl,l=this.cdr,o=i.nativeElement.innerHTML;this.orgHtml=n.bypassSecurityTrustHtml(o),l.detectChanges(),this.executeOnStable((function(){if(t.gen(),"line"!==e){var n=t.getEl(".ellipsis");n&&(n.innerHTML=o)}}))},t.prototype.ngAfterViewInit=function(){this.inited=!0,this.refresh()},t.prototype.ngOnChanges=function(){this.inited&&this.refresh()},t.decorators=[{type:n.Component,args:[{selector:"ellipsis",exportAs:"ellipsis",template:'<div (cdkObserveContent)="refresh()" #orgEl style="display: none;"><ng-content></ng-content></div>\n<ng-template #tooltipTpl let-con>\n <span *ngIf="tooltip; else con" nz-tooltip [nzTooltipTitle]="titleTpl" [nzOverlayStyle]="{ \'overflow-wrap\': \'break-word\', \'word-wrap\': \'break-word\' }">\n <ng-container *ngTemplateOutlet="con"></ng-container>\n <ng-template #titleTpl><div [innerHTML]="orgHtml"></div></ng-template>\n </span>\n</ng-template>\n<ng-container [ngSwitch]="type">\n <span *ngSwitchCase="\'default\'" [ngClass]="cls"></span>\n <ng-container *ngSwitchCase="\'length\'">\n <ng-template [ngTemplateOutlet]="tooltipTpl" [ngTemplateOutletContext]="{$implicit: lengthTpl}"></ng-template>\n <ng-template #lengthTpl>{{text}}</ng-template>\n </ng-container>\n <ng-container *ngSwitchCase="\'line-clamp\'">\n <ng-template [ngTemplateOutlet]="tooltipTpl" [ngTemplateOutletContext]="{$implicit: lineClampTpl}"></ng-template>\n <ng-template #lineClampTpl>\n <div [ngClass]="cls" [ngStyle]="{\'-webkit-line-clamp\': lines, \'-webkit-box-orient\': \'vertical\'}"></div>\n </ng-template>\n </ng-container>\n <div *ngSwitchCase="\'line\'" [ngClass]="cls">\n <div class="ellipsis__handle">\n <ng-template [ngTemplateOutlet]="tooltipTpl" [ngTemplateOutletContext]="{$implicit: lineTpl}"></ng-template>\n <ng-template #lineTpl>{{ linsWord }}</ng-template>\n <div class="ellipsis__shadow" #shadowOrgEl [innerHTML]="orgHtml"></div>\n <div class="ellipsis__shadow" #shadowTextEl><span>{{text}}</span></div>\n </div>\n </div>\n</ng-container>\n',preserveWhitespaces:!1,changeDetection:n.ChangeDetectionStrategy.OnPush,encapsulation:n.ViewEncapsulation.None}]}],t.ctorParameters=function(){return[{type:n.ElementRef},{type:n.NgZone},{type:i.DomSanitizer},{type:Document,decorators:[{type:n.Inject,args:[e.DOCUMENT]}]},{type:n.ChangeDetectorRef}]},t.propDecorators={orgEl:[{type:n.ViewChild,args:["orgEl",{static:!1}]}],shadowOrgEl:[{type:n.ViewChild,args:["shadowOrgEl",{static:!1}]}],shadowTextEl:[{type:n.ViewChild,args:["shadowTextEl",{static:!1}]}],tooltip:[{type:n.Input}],length:[{type:n.Input}],lines:[{type:n.Input}],fullWidthRecognition:[{type:n.Input}],tail:[{type:n.Input}]},a([l.InputBoolean(),p("design:type",Object)],t.prototype,"tooltip",void 0),a([l.InputNumber(null),p("design:type",Number)],t.prototype,"length",void 0),a([l.InputNumber(null),p("design:type",Number)],t.prototype,"lines",void 0),a([l.InputBoolean(),p("design:type",Object)],t.prototype,"fullWidthRecognition",void 0),t}();var h=[u],d=function(){function t(){}return t.decorators=[{type:n.NgModule,args:[{imports:[e.CommonModule,r.ObserversModule,l.LxlibUtilModule,s.NzToolTipModule],declarations:g(h),exports:g(h)}]}],t}();t.EllipsisComponent=u,t.EllipsisModule=d,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=ellipsis.umd.min.js.map