UNPKG

17.1 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("ngx-bootstrap/utils"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-bootstrap/carousel",["exports","@angular/core","ngx-bootstrap/utils","@angular/common"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["ngx-bootstrap"]=e["ngx-bootstrap"]||{},e["ngx-bootstrap"].carousel={}),e.ng.core,e.utils,e.ng.common)}(this,(function(e,t,i,s){"use strict";
2/*! *****************************************************************************
3 Copyright (c) Microsoft Corporation.
4
5 Permission to use, copy, modify, and/or distribute this software for any
6 purpose with or without fee is hereby granted.
7
8 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 PERFORMANCE OF THIS SOFTWARE.
15 ***************************************************************************** */Object.create;function n(e,t){var i="function"==typeof Symbol&&e[Symbol.iterator];if(!i)return e;var s,n,r=i.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(s=r.next()).done;)o.push(s.value)}catch(e){n={error:e}}finally{try{s&&!s.done&&(i=r.return)&&i.call(r)}finally{if(n)throw n.error}}return o}function r(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(n(arguments[t]));return e}Object.create;var o,l=function(){this.interval=5e3,this.noPause=!1,this.noWrap=!1,this.showIndicators=!0,this.pauseOnFocus=!1,this.indicatorsByChunk=!1,this.itemsPerSlide=1,this.singleSlideOffset=!1};l.ɵprov=t.ɵɵdefineInjectable({factory:function(){return new l},token:l,providedIn:"root"}),l.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.NEXT=1]="NEXT",e[e.PREV=2]="PREV"}(o||(o={}));var d=1,a=function(){function e(e,s){this.ngZone=s,this.noWrap=!1,this.noPause=!1,this.showIndicators=!0,this.pauseOnFocus=!1,this.indicatorsByChunk=!1,this.itemsPerSlide=1,this.singleSlideOffset=!1,this.isAnimated=!1,this.activeSlideChange=new t.EventEmitter(!1),this.slideRangeChange=new t.EventEmitter,this.startFromIndex=0,this._interval=5e3,this._slides=new i.LinkedList,this._currentVisibleSlidesIndex=0,this.isPlaying=!1,this.destroyed=!1,this.currentId=0,this.getActive=function(e){return e.active},this.makeSlidesConsistent=function(e){e.forEach((function(e,t){return e.item.order=t}))},Object.assign(this,e),this.currentId=d++}return Object.defineProperty(e.prototype,"activeSlide",{get:function(){return this._currentActiveSlide||0},set:function(e){this.multilist||this._slides.length&&e!==this._currentActiveSlide&&this._select(e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"interval",{get:function(){return this._interval},set:function(e){this._interval=e,this.restartTimer()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"slides",{get:function(){return this._slides.toArray()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isBs4",{get:function(){return!i.isBs3()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"_bsVer",{get:function(){return i.getBsVer()},enumerable:!1,configurable:!0}),e.prototype.ngAfterViewInit=function(){var e=this;setTimeout((function(){e.singleSlideOffset&&(e.indicatorsByChunk=!1),e.multilist&&(e._chunkedSlides=function(e,t){for(var i=[],s=Math.ceil(e.length/t),n=0;n<s;){var r=e.splice(0,n===s-1&&t<e.length?e.length:t);i.push(r),n++}return i}(e.mapSlidesAndIndexes(),e.itemsPerSlide),e.selectInitialSlides())}),0)},e.prototype.ngOnDestroy=function(){this.destroyed=!0},e.prototype.addSlide=function(e){this._slides.add(e),this.multilist&&this._slides.length<=this.itemsPerSlide&&(e.active=!0),!this.multilist&&this.isAnimated&&(e.isAnimated=!0),this.multilist||1!==this._slides.length||(this._currentActiveSlide=void 0,this.activeSlide=0,this.play()),this.multilist&&this._slides.length>this.itemsPerSlide&&this.play()},e.prototype.removeSlide=function(e){var t=this,i=this._slides.indexOf(e);if(this._currentActiveSlide===i){var s;this._slides.length>1&&(s=this.isLast(i)?this.noWrap?i-1:0:i),this._slides.remove(i),setTimeout((function(){t._select(s)}),0)}else{this._slides.remove(i);var n=this.getCurrentSlideIndex();setTimeout((function(){t._currentActiveSlide=n,t.activeSlideChange.emit(t._currentActiveSlide)}),0)}},e.prototype.nextSlideFromInterval=function(e){void 0===e&&(e=!1),this.move(o.NEXT,e)},e.prototype.nextSlide=function(e){void 0===e&&(e=!1),this.isPlaying&&this.restartTimer(),this.move(o.NEXT,e)},e.prototype.previousSlide=function(e){void 0===e&&(e=!1),this.isPlaying&&this.restartTimer(),this.move(o.PREV,e)},e.prototype.getFirstVisibleIndex=function(){return this.slides.findIndex(this.getActive)},e.prototype.getLastVisibleIndex=function(){return function(e,t){for(var i=e.length;i--;)if(t(e[i],i,e))return i;return-1}(this.slides,this.getActive)},e.prototype.move=function(e,t){void 0===t&&(t=!1);var i=this.getFirstVisibleIndex(),s=this.getLastVisibleIndex();this.noWrap&&(e===o.NEXT&&this.isLast(s)||e===o.PREV&&0===i)||(this.multilist?this.moveMultilist(e):this.activeSlide=this.findNextSlideIndex(e,t)||0)},e.prototype.keydownPress=function(e){if(13===e.keyCode||"Enter"===e.key||32===e.keyCode||"Space"===e.key)return this.nextSlide(),void e.preventDefault();37!==e.keyCode&&"LeftArrow"!==e.key?39!==e.keyCode&&"RightArrow"!==e.key||this.nextSlide():this.previousSlide()},e.prototype.onMouseLeave=function(){this.pauseOnFocus||this.play()},e.prototype.onMouseUp=function(){this.pauseOnFocus||this.play()},e.prototype.pauseFocusIn=function(){this.pauseOnFocus&&(this.isPlaying=!1,this.resetTimer())},e.prototype.pauseFocusOut=function(){this.play()},e.prototype.selectSlide=function(e){this.isPlaying&&this.restartTimer(),this.multilist?this.selectSlideRange(this.indicatorsByChunk?e*this.itemsPerSlide:e):this.activeSlide=this.indicatorsByChunk?e*this.itemsPerSlide:e},e.prototype.play=function(){this.isPlaying||(this.isPlaying=!0,this.restartTimer())},e.prototype.pause=function(){this.noPause||(this.isPlaying=!1,this.resetTimer())},e.prototype.getCurrentSlideIndex=function(){return this._slides.findIndex(this.getActive)},e.prototype.isLast=function(e){return e+1>=this._slides.length},e.prototype.isFirst=function(e){return 0===e},e.prototype.indicatorsSlides=function(){var e=this;return this.slides.filter((function(t,i){return!e.indicatorsByChunk||i%e.itemsPerSlide==0}))},e.prototype.selectInitialSlides=function(){var e=this.startFromIndex<=this._slides.length?this.startFromIndex:0;if(this.hideSlides(),this.singleSlideOffset){if(this._slidesWithIndexes=this.mapSlidesAndIndexes(),this._slides.length-e<this.itemsPerSlide){var t=this._slidesWithIndexes.slice(0,e);this._slidesWithIndexes=r(this._slidesWithIndexes,t).slice(t.length).slice(0,this.itemsPerSlide)}else this._slidesWithIndexes=this._slidesWithIndexes.slice(e,e+this.itemsPerSlide);this._slidesWithIndexes.forEach((function(e){return e.item.active=!0})),this.makeSlidesConsistent(this._slidesWithIndexes)}else this.selectRangeByNestedIndex(e);this.slideRangeChange.emit(this.getVisibleIndexes())},e.prototype.findNextSlideIndex=function(e,t){var i=0;if(t||!this.isLast(this.activeSlide)||e===o.PREV||!this.noWrap){switch(e){case o.NEXT:if(void 0===this._currentActiveSlide){i=0;break}if(!this.isLast(this._currentActiveSlide)){i=this._currentActiveSlide+1;break}i=!t&&this.noWrap?this._currentActiveSlide:0;break;case o.PREV:if(void 0===this._currentActiveSlide){i=0;break}if(this._currentActiveSlide>0){i=this._currentActiveSlide-1;break}if(!t&&this.noWrap){i=this._currentActiveSlide;break}i=this._slides.length-1;break;default:throw new Error("Unknown direction")}return i}},e.prototype.mapSlidesAndIndexes=function(){return this.slides.slice().map((function(e,t){return{index:t,item:e}}))},e.prototype.selectSlideRange=function(e){if(!this.isIndexInRange(e)){if(this.hideSlides(),this.singleSlideOffset){var t=this.isIndexOnTheEdges(e)?e:e-this.itemsPerSlide+1,i=this.isIndexOnTheEdges(e)?e+this.itemsPerSlide:e+1;this._slidesWithIndexes=this.mapSlidesAndIndexes().slice(t,i),this.makeSlidesConsistent(this._slidesWithIndexes),this._slidesWithIndexes.forEach((function(e){return e.item.active=!0}))}else this.selectRangeByNestedIndex(e);this.slideRangeChange.emit(this.getVisibleIndexes())}},e.prototype.selectRangeByNestedIndex=function(e){if(this._chunkedSlides){var t=this._chunkedSlides.map((function(e,t){return{index:t,list:e}})).find((function(t){return void 0!==t.list.find((function(t){return t.index===e}))}));t&&(this._currentVisibleSlidesIndex=t.index,this._chunkedSlides[t.index].forEach((function(e){e.item.active=!0})))}},e.prototype.isIndexOnTheEdges=function(e){return e+1-this.itemsPerSlide<=0||e+this.itemsPerSlide<=this._slides.length},e.prototype.isIndexInRange=function(e){return this.singleSlideOffset&&this._slidesWithIndexes?this._slidesWithIndexes.map((function(e){return e.index})).indexOf(e)>=0:e<=this.getLastVisibleIndex()&&e>=this.getFirstVisibleIndex()},e.prototype.hideSlides=function(){this.slides.forEach((function(e){return e.active=!1}))},e.prototype.isVisibleSlideListLast=function(){return!!this._chunkedSlides&&this._currentVisibleSlidesIndex===this._chunkedSlides.length-1},e.prototype.isVisibleSlideListFirst=function(){return 0===this._currentVisibleSlidesIndex},e.prototype.moveSliderByOneItem=function(e){var t,i,s,n;if(this.noWrap){t=this.getFirstVisibleIndex(),i=this.getLastVisibleIndex(),s=e===o.NEXT?t:i,n=e!==o.NEXT?t-1:this.isLast(i)?0:i+1;var l=this._slides.get(s);l&&(l.active=!1);var d=this._slides.get(n);d&&(d.active=!0);var a=this.mapSlidesAndIndexes().filter((function(e){return e.item.active}));return this.makeSlidesConsistent(a),void this.slideRangeChange.emit(this.getVisibleIndexes())}if(this._slidesWithIndexes&&this._slidesWithIndexes[0]){var h,c;if(t=this._slidesWithIndexes[0].index,i=this._slidesWithIndexes[this._slidesWithIndexes.length-1].index,e===o.NEXT)this._slidesWithIndexes.shift(),h=this.isLast(i)?0:i+1,(c=this._slides.get(h))&&this._slidesWithIndexes.push({index:h,item:c});else this._slidesWithIndexes.pop(),h=this.isFirst(t)?this._slides.length-1:t-1,(c=this._slides.get(h))&&(this._slidesWithIndexes=r([{index:h,item:c}],this._slidesWithIndexes));this.hideSlides(),this._slidesWithIndexes.forEach((function(e){return e.item.active=!0})),this.makeSlidesConsistent(this._slidesWithIndexes),this.slideRangeChange.emit(this._slidesWithIndexes.map((function(e){return e.index})))}},e.prototype.moveMultilist=function(e){this.singleSlideOffset?this.moveSliderByOneItem(e):(this.hideSlides(),this.noWrap?this._currentVisibleSlidesIndex=e===o.NEXT?this._currentVisibleSlidesIndex+1:this._currentVisibleSlidesIndex-1:e===o.NEXT?this._currentVisibleSlidesIndex=this.isVisibleSlideListLast()?0:this._currentVisibleSlidesIndex+1:this.isVisibleSlideListFirst()?this._currentVisibleSlidesIndex=this._chunkedSlides?this._chunkedSlides.length-1:0:this._currentVisibleSlidesIndex=this._currentVisibleSlidesIndex-1,this._chunkedSlides&&this._chunkedSlides[this._currentVisibleSlidesIndex].forEach((function(e){return e.item.active=!0})),this.slideRangeChange.emit(this.getVisibleIndexes()))},e.prototype.getVisibleIndexes=function(){return!this.singleSlideOffset&&this._chunkedSlides?this._chunkedSlides[this._currentVisibleSlidesIndex].map((function(e){return e.index})):this._slidesWithIndexes?this._slidesWithIndexes.map((function(e){return e.index})):void 0},e.prototype._select=function(e){if(isNaN(e))this.pause();else{if(!this.multilist&&void 0!==this._currentActiveSlide){var t=this._slides.get(this._currentActiveSlide);void 0!==t&&(t.active=!1)}var i=this._slides.get(e);void 0!==i&&(this._currentActiveSlide=e,i.active=!0,this.activeSlide=e,this.activeSlideChange.emit(e))}},e.prototype.restartTimer=function(){var e=this;this.resetTimer();var t=+this.interval;!isNaN(t)&&t>0&&(this.currentInterval=this.ngZone.runOutsideAngular((function(){return setInterval((function(){var t=+e.interval;e.ngZone.run((function(){e.isPlaying&&!isNaN(e.interval)&&t>0&&e.slides.length?e.nextSlideFromInterval():e.pause()}))}),t)})))},Object.defineProperty(e.prototype,"multilist",{get:function(){return this.itemsPerSlide>1},enumerable:!1,configurable:!0}),e.prototype.resetTimer=function(){this.currentInterval&&(clearInterval(this.currentInterval),this.currentInterval=void 0)},e}();a.decorators=[{type:t.Component,args:[{selector:"carousel",template:'<div (mouseenter)="pause()"\n (mouseleave)="onMouseLeave()"\n (mouseup)="onMouseUp()"\n (keydown)="keydownPress($event)"\n (focusin)="pauseFocusIn()"\n (focusout)="pauseFocusOut()"\n [id]="currentId"\n class="carousel slide" tabindex="0">\n <ng-container *ngIf="!_bsVer.isBs5 && showIndicators && slides.length > 1">\n <ol class="carousel-indicators">\n <li *ngFor="let slide of indicatorsSlides(); let i = index;"\n [class.active]="slide.active === true"\n (click)="selectSlide(i)">\n </li>\n </ol>\n </ng-container>\n <ng-container *ngIf="_bsVer.isBs5 && showIndicators && slides.length > 1">\n <div class="carousel-indicators">\n <button\n *ngFor="let slide of indicatorsSlides(); let i = index;"\n [class.active]="slide.active === true"\n (click)="selectSlide(i)"\n type="button"\n [attr.data-bs-target]="\'#\'+currentId"\n [attr.data-bs-slide-to]="i" aria-current="true"\n >\n </button>\n </div>\n </ng-container>\n <div class="carousel-inner" [ngStyle]="{\'display\': multilist ? \'flex\' : \'block\'}">\n <ng-content></ng-content>\n </div>\n <a class="left carousel-control carousel-control-prev"\n *ngIf="slides.length > 1"\n [class.disabled]="activeSlide === 0 && noWrap"\n [attr.data-bs-target]="\'#\'+currentId"\n (click)="previousSlide()"\n tabindex="0" role="button">\n <span class="icon-prev carousel-control-prev-icon" aria-hidden="true"></span>\n <span *ngIf="isBs4" class="sr-only visually-hidden">Previous</span>\n </a>\n <a class="right carousel-control carousel-control-next"\n *ngIf="slides.length > 1"\n [class.disabled]="isLast(activeSlide) && noWrap"\n [attr.data-bs-target]="\'#\'+currentId"\n (click)="nextSlide()"\n tabindex="0" role="button">\n <span class="icon-next carousel-control-next-icon" aria-hidden="true"></span>\n <span class="sr-only visually-hidden">Next</span>\n </a>\n</div>\n'}]}],a.ctorParameters=function(){return[{type:l},{type:t.NgZone}]},a.propDecorators={noWrap:[{type:t.Input}],noPause:[{type:t.Input}],showIndicators:[{type:t.Input}],pauseOnFocus:[{type:t.Input}],indicatorsByChunk:[{type:t.Input}],itemsPerSlide:[{type:t.Input}],singleSlideOffset:[{type:t.Input}],isAnimated:[{type:t.Input}],activeSlideChange:[{type:t.Output}],slideRangeChange:[{type:t.Output}],activeSlide:[{type:t.Input}],startFromIndex:[{type:t.Input}],interval:[{type:t.Input}]};var h=function(){function e(e){this.active=!1,this.itemWidth="100%",this.order=0,this.isAnimated=!1,this.addClass=!0,this.carousel=e}return e.prototype.ngOnInit=function(){this.carousel.addSlide(this),this.itemWidth=100/this.carousel.itemsPerSlide+"%"},e.prototype.ngOnDestroy=function(){this.carousel.removeSlide(this)},e}();h.decorators=[{type:t.Component,args:[{selector:"slide",template:'\n <div [class.active]="active" class="item">\n <ng-content></ng-content>\n </div>\n ',host:{"[attr.aria-hidden]":"!active"},styles:["\n :host.carousel-animation {\n transition: opacity 0.6s ease, visibility 0.6s ease;\n float: left;\n }\n :host.carousel-animation.active {\n opacity: 1;\n visibility: visible;\n }\n :host.carousel-animation:not(.active) {\n display: block;\n position: absolute;\n opacity: 0;\n visibility: hidden;\n }\n :host.carousel-item {\n margin-right: auto;\n }\n "]}]}],h.ctorParameters=function(){return[{type:a}]},h.propDecorators={active:[{type:t.HostBinding,args:["class.active"]},{type:t.Input}],itemWidth:[{type:t.HostBinding,args:["style.width"]}],order:[{type:t.HostBinding,args:["style.order"]}],isAnimated:[{type:t.HostBinding,args:["class.carousel-animation"]}],addClass:[{type:t.HostBinding,args:["class.item"]},{type:t.HostBinding,args:["class.carousel-item"]}]};var c=function(){function e(){}return e.forRoot=function(){return{ngModule:e,providers:[]}},e}();c.decorators=[{type:t.NgModule,args:[{imports:[s.CommonModule],declarations:[h,a],exports:[h,a]}]}],e.CarouselComponent=a,e.CarouselConfig=l,e.CarouselModule=c,e.SlideComponent=h,Object.defineProperty(e,"__esModule",{value:!0})}));
16//# sourceMappingURL=ngx-bootstrap-carousel.umd.min.js.map
\No newline at end of file