UNPKG

angular-gallery

Version:

Responsive gallery for Angular with touch screen support.

16 lines (14 loc) 38.5 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("rxjs")):"function"==typeof define&&define.amd?define("angular-gallery",["exports","@angular/core","@angular/common","rxjs"],e):e((t=t||self)["angular-gallery"]={},t.ng.core,t.ng.common,t.rxjs)}(this,(function(t,e,i,o){"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 n(t,e,i,o){var n,s=arguments.length,r=s<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,o);else for(var l=t.length-1;l>=0;l--)(n=t[l])&&(r=(s<3?n(r):s>3?n(e,i,r):n(e,i))||r);return s>3&&r&&Object.defineProperty(e,i,r),r}var s=function(){function t(t){var e=this;this.eventType=void 0,this.handlers={},this.startX=0,this.startY=0,this.lastTap=0,this.doubleTapMinTimeout=300,this.tapMinTimeout=200,this.touchstartTime=0,this.i=0,this.isMousedown=!1,this.touchListeners={touchstart:"handleTouchstart",touchmove:"handleTouchmove",touchend:"handleTouchend"},this.mouseListeners={mousedown:"handleMousedown",mousemove:"handleMousemove",mouseup:"handleMouseup",wheel:"handleWheel"},this.otherListeners={resize:"handleResize"},this.handleTouchstart=function(t){e.elementPosition=e.getElementPosition(),e.touchstartTime=(new Date).getTime(),void 0===e.eventType&&e.getTouchstartPosition(t),e.runHandler("touchstart",t)},this.handleTouchmove=function(t){var i=t.touches;switch(e.detectPan(i)&&e.runHandler("pan",t),e.detectPinch(t)&&e.runHandler("pinch",t),e.detectLinearSwipe(t)){case"horizontal-swipe":t.swipeType="horizontal-swipe",e.runHandler("horizontal-swipe",t);break;case"vertical-swipe":t.swipeType="vertical-swipe",e.runHandler("vertical-swipe",t)}(e.detectLinearSwipe(t)||"horizontal-swipe"===e.eventType||"vertical-swipe"===e.eventType)&&e.handleLinearSwipe(t)},this.handleTouchend=function(t){var i=t.touches;e.detectDoubleTap()&&e.runHandler("double-tap",t),e.detectTap(),e.runHandler("touchend",t),e.eventType="touchend",i&&0===i.length&&(e.eventType=void 0,e.i=0)},this.handleMousedown=function(t){e.isMousedown=!0,e.elementPosition=e.getElementPosition(),e.touchstartTime=(new Date).getTime(),void 0===e.eventType&&e.getMousedownPosition(t),e.runHandler("mousedown",t)},this.handleMousemove=function(t){if(e.isMousedown){switch(e.runHandler("pan",t),e.detectLinearSwipe(t)){case"horizontal-swipe":t.swipeType="horizontal-swipe",e.runHandler("horizontal-swipe",t);break;case"vertical-swipe":t.swipeType="vertical-swipe",e.runHandler("vertical-swipe",t)}(e.detectLinearSwipe(t)||"horizontal-swipe"===e.eventType||"vertical-swipe"===e.eventType)&&e.handleLinearSwipe(t)}},this.handleMouseup=function(t){e.detectTap(),e.isMousedown=!1,e.runHandler("mouseup",t),e.eventType=void 0,e.i=0},this.handleWheel=function(t){e.runHandler("wheel",t)},this.handleResize=function(t){e.runHandler("resize",t)},this.properties=t,this.element=this.properties.element,this.elementPosition=this.getElementPosition(),this.toggleEventListeners("addEventListener")}return t.prototype.destroy=function(){this.toggleEventListeners("removeEventListener")},t.prototype.toggleEventListeners=function(t){var e;for(var i in e="mouse and touch"===this.properties.listeners?Object.assign(this.touchListeners,this.mouseListeners):this.detectTouchScreen()?this.touchListeners:this.mouseListeners,this.properties.resize&&(e=Object.assign(e,this.otherListeners)),e){var o=e[i];"resize"===i?("addEventListener"===t&&window.addEventListener(i,this[o],!1),"removeEventListener"===t&&window.removeEventListener(i,this[o],!1)):"mouseup"===i||"mousemove"===i?("addEventListener"===t&&document.addEventListener(i,this[o],!1),"removeEventListener"===t&&document.removeEventListener(i,this[o],!1)):("addEventListener"===t&&this.element.addEventListener(i,this[o],!1),"removeEventListener"===t&&this.element.removeEventListener(i,this[o],!1))}},t.prototype.handleLinearSwipe=function(t){this.i++,this.i>3&&(this.eventType=this.getLinearSwipeType(t)),"horizontal-swipe"===this.eventType&&this.runHandler("horizontal-swipe",t),"vertical-swipe"===this.eventType&&this.runHandler("vertical-swipe",t)},t.prototype.runHandler=function(t,e){this.handlers[t]&&this.handlers[t](e)},t.prototype.detectPan=function(t){return 1===t.length&&!this.eventType||"pan"===this.eventType},t.prototype.detectDoubleTap=function(){var t=this;if(null==this.eventType){var e=(new Date).getTime(),i=e-this.lastTap;if(clearTimeout(this.doubleTapTimeout),i<this.doubleTapMinTimeout&&i>0)return!0;this.doubleTapTimeout=setTimeout((function(){clearTimeout(t.doubleTapTimeout)}),this.doubleTapMinTimeout),this.lastTap=e}},t.prototype.detectTap=function(){if(null==this.eventType){var t=(new Date).getTime()-this.touchstartTime;t>0&&(t<this.tapMinTimeout?this.runHandler("tap",event):this.runHandler("longtap",event))}},t.prototype.detectPinch=function(t){return 2===t.touches.length&&void 0===this.eventType||"pinch"===this.eventType},t.prototype.detectLinearSwipe=function(t){var e=t.touches;if(e){if(1===e.length&&!this.eventType||"horizontal-swipe"===this.eventType||"vertical-swipe"===this.eventType)return this.getLinearSwipeType(t)}else if(!this.eventType||"horizontal-swipe"===this.eventType||"vertical-swipe"===this.eventType)return this.getLinearSwipeType(t)},t.prototype.getLinearSwipeType=function(t){if("horizontal-swipe"!==this.eventType&&"vertical-swipe"!==this.eventType){var e=Math.abs(this.moveLeft(0,t)-this.startX);return 3*Math.abs(this.moveTop(0,t)-this.startY)>e?"vertical-swipe":"horizontal-swipe"}return this.eventType},t.prototype.getElementPosition=function(){return this.element.getBoundingClientRect()},t.prototype.getTouchstartPosition=function(t){this.startX=t.touches[0].clientX-this.elementPosition.left,this.startY=t.touches[0].clientY-this.elementPosition.top},t.prototype.getMousedownPosition=function(t){this.startX=t.clientX-this.elementPosition.left,this.startY=t.clientY-this.elementPosition.top},t.prototype.moveLeft=function(t,e){var i=e.touches;return i?i[t].clientX-this.elementPosition.left:e.clientX-this.elementPosition.left},t.prototype.moveTop=function(t,e){var i=e.touches;return i?i[t].clientY-this.elementPosition.top:e.clientY-this.elementPosition.top},t.prototype.detectTouchScreen=function(){var t=" -webkit- -moz- -o- -ms- ".split(" ");return"ontouchstart"in window||function(t){return window.matchMedia(t).matches}(["(",t.join("touch-enabled),("),"heartz",")"].join(""))},t.prototype.on=function(t,e){t&&(this.handlers[t]=e)},t}(),r=function(){function t(t){var e=this;this.initialPositionX=0,this.newContainerPositionIndex=0,this.preliminarySlideCounter=0,this.slideCounter=0,this.previousSlideCounter=0,this.isContentImages=!0,this.isLazyLoad=!0,this.isContainerLocked=!1,this.alignCells="left",this.initialContainerPosition=0,this.handleTouchstart=function(t){if(e.isTouchstart=!0,!e.isSlideInProgress){var i=t.touches;e.startX=i?i[0].clientX-e.getCarouselElementPosition().left:t.clientX-e.getCarouselElementPosition().left,e.containerInitialPositionX=e.getElementPosition().left-e.getCarouselElementPosition().left,e.isMoveInProgress=!0}},this.handleHorizontalSwipe=function(t){if(!e.isSlideInProgress){var i=t.touches;e.moveX=i?i[0].clientX-e.getCarouselElementPosition().left:t.clientX-e.getCarouselElementPosition().left,e.distanceAbs=e.getDistanceAbs(),e.direction=e.getDirection(),e.moveContainer()}},this.handleTouchend=function(t){!e.isSlideInProgress&&e.isTouchstart?(e.isMoveInProgress=!1,e.detectSlide()?e.handleSlide():(e.newContainerPositionIndex=0,e.alignContainer()),e.startX=e.moveX=e.distanceAbs=void 0,e.isTouchstart=!1):e.isTouchstart=!1},this.element=t.element,this.properties=t,this.cells=this.element.children,this.visibleWidth=this.properties.visibleWidth||this.element.parentElement.clientWidth,this.setContainerWidth(),this.alignContainer(0)}return Object.defineProperty(t.prototype,"isFirstCell",{get:function(){return 0===this.slideCounter},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"lastCellIndex",{get:function(){return this.images.length?this.images.length-1:this.cells.length-1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"overflowCellsLimit",{get:function(){return this.properties.overflowCellsLimit},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cellLimit",{get:function(){return this.visibleCellsCount+2*this.overflowCellsLimit},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"images",{get:function(){return this.properties.images},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"margin",{get:function(){return this.properties.margin},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"minSwipeDistance",{get:function(){return this.properties.minSwipeDistance},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"transitionDuration",{get:function(){return this.properties.transitionDuration},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"transitionTimingFunction",{get:function(){return this.properties.transitionTimingFunction},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fullCellWidth",{get:function(){return this.properties.cellWidth+this.margin},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"visibleCellsCount",{get:function(){return Math.ceil(this.visibleWidth/this.fullCellWidth)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"lapCounter",{get:function(){return Math.floor(this.slideCounter/this.totalContainerCellsCount)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"visibleCellsOverflowContainer",{get:function(){return this.visibleCellsCount*this.fullCellWidth-this.margin>this.visibleWidth},enumerable:!0,configurable:!0}),t.prototype.moveContainer=function(){var t=this.getMovePositionX();this.transformPositionX(t,0)},t.prototype.getMovePositionX=function(){var t=this.getDistance();return this.containerInitialPositionX-t},t.prototype.alignContainer=function(t){void 0===t&&(t=this.transitionDuration);var e=this.getContainerPosition();this.transformPositionX(e,t),this.setInitialContainerPosition(e)},t.prototype.getContainerPosition=function(){var t=this.getContainerPositionCorrection();return this.isContainerPositionCorrection=0!=t,this.initialContainerPosition+this.newContainerPositionIndex*this.fullCellWidth+t},t.prototype.setInitialContainerPosition=function(t){var e=this.getContainerPositionCorrection();this.initialContainerPosition=t-e},t.prototype.getContainerPositionCorrection=function(){var t=0;return(this.images.length-this.preliminarySlideCounter<this.visibleCellsCount||this.isSlideLengthLimited)&&(this.visibleWidth<this.totalContainerCellsCount*this.fullCellWidth&&(t=-(this.visibleCellsCount*this.fullCellWidth-this.visibleWidth-this.margin)),t>=-this.margin&&(t=0)),t},t.prototype.quicklyPositionContainer=function(){var t=this.getContainerPositionCorrection(),e=this.getNewContainerPosition()+t;this.transformPositionX(e,0),this.setInitialContainerPosition(e)},t.prototype.getNewContainerPosition=function(){return this.slideCounter>this.overflowCellsLimit&&"left"===this.alignCells?(this.lineUpCells(),-this.overflowCellsLimit*this.fullCellWidth):this.slideCounter<=this.overflowCellsLimit?(this.previousSlideCounter>this.overflowCellsLimit&&this.lineUpCells(),-this.slideCounter*this.fullCellWidth):void 0},t.prototype.setContainerWidth=function(){var t=this.getContainerWidth();this.element.style.width=t+"px"},t.prototype.getContainerWidth=function(){this.totalContainerCellsCount=this.visibleCellsCount+2*this.overflowCellsLimit;var t=this.totalContainerCellsCount*this.fullCellWidth,e=this.images.length*this.fullCellWidth;return e<t&&(t=e),t},t.prototype.getFile=function(t){var e=this.getFileIndex(t),i=this.images[e];return i&&!i.type&&(i.type="image"),{image:this.images[e],imageIndex:e}},t.prototype.getFileIndex=function(t){var e,i=this.getPositionIndex(t);this.totalContainerCellsCount;if(!this.isContainerLocked)return this.slideCounter<=this.overflowCellsLimit?t:e=i+(this.slideCounter-this.overflowCellsLimit);"left"===this.alignCells&&(e=this.slideCounter>this.overflowCellsLimit?i+(this.slideCounter-this.overflowCellsLimit):t);return!(e>this.lastCellIndex)&&e},t.prototype.transformPositionX=function(t,e){void 0===e&&(e=this.transitionDuration),this.element.style.transition="transform "+e+"ms "+this.transitionTimingFunction,this.element.style.transform="translateX("+t+"px)"},t.prototype.detectSlide=function(){return this.distanceAbs>=this.minSwipeDistance},t.prototype.next=function(){this.isSlideInProgress||(this.direction="left",this.handleSlide(1))},t.prototype.prev=function(){this.isSlideInProgress||(this.direction="right",this.handleSlide(1))},t.prototype.select=function(t){this.slideCounter=t,this.quicklyPositionContainer()},t.prototype.handleSlide=function(t){void 0===t&&(t=void 0),this.slideLength=this.getSlideLength(),this.slideLength=t||this.limitSlideLength(this.slideLength),"left"!==this.direction||this.isSlideInProgress||(this.preliminarySlideCounter=this.slideCounter+this.slideLength,this.detectLastSlide(this.slideCounter+this.slideLength)||(this.newContainerPositionIndex=this.newContainerPositionIndex-this.slideLength,this.isSlideInProgress=!0,this.isLazyLoad&&(this.isContainerLocked=this.preliminarySlideCounter>this.overflowCellsLimit,this.detectContainerUnlock()&&(this.isContainerLocked=!1)))),"right"!==this.direction||this.isSlideInProgress||(this.slideCounter-this.slideLength<0&&(this.slideLength=this.slideCounter),this.preliminarySlideCounter=this.slideCounter-this.slideLength,this.isFirstCell||(this.newContainerPositionIndex=this.newContainerPositionIndex+this.slideLength,this.isSlideInProgress=!0,this.isLazyLoad&&(this.preliminarySlideCounter>this.overflowCellsLimit?this.isContainerLocked=!0:this.isContainerLocked=!1,this.detectContainerUnlock()&&(this.isContainerLocked=!1)))),this.alignContainer()},t.prototype.getSlideLength=function(){var t=this.getContainerPositionCorrection(),e=Math.floor((this.distanceAbs+t)/this.fullCellWidth);return this.distanceAbs%this.fullCellWidth>=this.minSwipeDistance&&e++,e},t.prototype.limitSlideLength=function(t){if(t>1)for(var e=0;e<t;e++){var i=this.slideCounter+(t-e);if(!this.detectLastSlide(i)){t-=e,this.isSlideLengthLimited=e>0;break}}return t},t.prototype.detectLastSlide=function(t){return this.images.length-t<this.visibleCellsCount},t.prototype.isNextArrowDisabled=function(){return this.visibleCellsOverflowContainer?this.detectLastSlide(this.slideCounter+1)&&this.isContainerPositionCorrection:this.detectLastSlide(this.slideCounter+1)},t.prototype.isPrevArrowDisabled=function(){return 0===this.slideCounter},t.prototype.detectContainerUnlock=function(){return this.images.length-this.preliminarySlideCounter<this.visibleCellsCount+this.overflowCellsLimit},t.prototype.handleSlideEnd=function(){this.isSlideInProgress&&(this.transformSlideEnd(),this.isSlideInProgress=!1,this.newContainerPositionIndex=0,this.isSlideLengthLimited=void 0)},t.prototype.transformSlideEnd=function(){this.isLazyLoad&&(this.setSlideCounter(),this.quicklyPositionContainer()),this.previousSlideCounter=this.slideCounter},t.prototype.setSlideCounter=function(){"left"===this.direction&&(this.slideCounter=this.slideCounter+this.slideLength),"right"===this.direction&&(this.slideCounter=this.slideCounter-this.slideLength),this.direction=void 0,this.slideLength=0},t.prototype.resetTransition=function(){this.element.style.transition=""},t.prototype.getElementPosition=function(){return this.element.getBoundingClientRect()},t.prototype.getCarouselElementPosition=function(){return this.properties.container.getBoundingClientRect()},t.prototype.getDistance=function(){return this.startX-this.moveX},t.prototype.getDistanceAbs=function(){return Math.abs(this.startX-this.moveX)},t.prototype.getDirection=function(){var t=Math.sign(this.startX-this.moveX);return-1===t?"right":1===t?"left":void 0},t.prototype.lineUpCells=function(){for(var t=this.element.children,e=0;e<t.length;e++){var i=t[e],o=this.getCellPositionX(e);i.style.transform="translateX("+o+"px)"}},t.prototype.getCellPositionX=function(t){return this.getPositionIndex(t)*this.fullCellWidth},t.prototype.getPositionIndex=function(t){var e,i=this.slideCounter-this.overflowCellsLimit;return i>this.totalContainerCellsCount&&(i%=this.totalContainerCellsCount),i<0?t:((e=t-i)<0&&(e=this.totalContainerCellsCount+e),e)},Object.defineProperty(t.prototype,"containerOverflowRightCount",{get:function(){var t=this.images.length-this.totalContainerCellsCount,e=0;return t>0&&(e=t-(this.previousSlideCounter-this.overflowCellsLimit)),e},enumerable:!0,configurable:!0}),t.prototype.getCenterPositionIndex=function(){return(this.totalContainerCellsCount-1)/2},t}(),l=function(){function t(){this.emitter=new o.ReplaySubject(1)}return t.prototype.emitChangeEvent=function(t){this.emitter.next(t)},t=n([e.Injectable()],t)}(),a=function(){function t(t,i,o){var n=this;this.elementRef=t,this.ref=i,this.overlayEventService=o,this.minTimeout=30,this._cellWidth=200,this._transitionDuration=200,this.events=new e.EventEmitter,this.height=200,this.margin=10,this.objectFit="cover",this.minSwipeDistance=50,this.transitionTimingFunction="ease",this.counterSeparator=" / ",this.overflowCellsLimit=3,this.listeners="mouse and touch",this.arrows=!0,this.arrowsTheme="light",this.hostClassCarousel=!0,this.handleTouchstart=function(t){t.preventDefault(),n.carousel.handleTouchstart(t),n.isMoving=!0,n.events.emit({type:"touchstart",event:t})},this.handleHorizontalSwipe=function(t){t.preventDefault(),n.carousel.handleHorizontalSwipe(t),n.events.emit({type:"swipe",event:t})},this.handleTouchend=function(t){t.touches;n.carousel.handleTouchend(t),n.isMoving=!1,n.events.emit({type:"touchend",event:t})},this.handleTap=function(t){var e=n.carousel.slideCounter,i=n.carousel.currentCellIndex,o=n.carousel.getFileIndex(e),s=n.carousel.getFile(i);n.events.emit({type:"click",file:s,index:o})}}return Object.defineProperty(t.prototype,"isLandscape",{get:function(){return window.innerWidth>window.innerHeight},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isSafari",{get:function(){var t=navigator.userAgent.toLowerCase();if(-1!==t.indexOf("safari"))return!(t.indexOf("chrome")>-1)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"counter",{get:function(){return this.carousel.slideCounter+1+this.counterSeparator+this.images.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"images",{get:function(){return this._images},set:function(t){this._images=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isNgContent",{get:function(){return this.elementRef.nativeElement.querySelector(".carousel-content-wrapper").children.length>0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"transitionDuration",{get:function(){return 0===this._transitionDuration?1:this._transitionDuration},set:function(t){this._transitionDuration=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cellWidth",{set:function(t){t&&(this._cellWidth=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isCounter",{get:function(){return this._isCounter&&this.images.length>1},set:function(t){t&&(this._isCounter=t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"overlayProperties",{set:function(t){this._properties=t,this._images=this._properties.metadata.images,this._cellWidth=this._properties.metadata.width,this.height=this._properties.metadata.height,this.objectFit=this._properties.metadata.objectFit,this.margin=this._properties.metadata.margin,this.transitionDuration=this._properties.metadata.transitionDuration,this.overflowCellsLimit=this._properties.metadata.overflowCellsLimit,this.minSwipeDistance=this._properties.metadata.minSwipeDistance,this.transitionTimingFunction=this._properties.metadata.transitionTimingFunction,this._isCounter=this._properties.metadata.counter,this.counterSeparator=this._properties.metadata.counterSeparator,this.arrows=this._properties.metadata.arrows},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"properties",{get:function(){return this._properties},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cellLimit",{get:function(){if(this.carousel)return this.carousel.cellLimit},enumerable:!0,configurable:!0}),t.prototype.onWindowResize=function(t){this.landscapeMode=this.isLandscape,this.ref.detectChanges(),this.initCarousel(),this.carousel.lineUpCells()},t.prototype.ngOnInit=function(){this.touches=new s({element:this.elementRef.nativeElement.querySelector(".carousel-cells"),listeners:this.listeners}),this.touches.on("touchstart",this.handleTouchstart),this.touches.on("horizontal-swipe",this.handleHorizontalSwipe),this.touches.on("touchend",this.handleTouchend),this.touches.on("mousedown",this.handleTouchstart),this.touches.on("mouseup",this.handleTouchend),this.touches.on("tap",this.handleTap),this.initCarousel(),this.setDimensions(),this.setInitialIndex()},t.prototype.ngAfterViewInit=function(){this.carousel.lineUpCells()},t.prototype.ngOnChanges=function(t){(t.width||t.height)&&(this.setDimensions(),this.initCarousel(),this.carousel.lineUpCells())},t.prototype.ngOnDestroy=function(){this.touches.destroy()},t.prototype.initCarousel=function(){this.carousel=new r({element:this.elementRef.nativeElement.querySelector(".carousel-cells"),container:this.elementRef.nativeElement,images:this.images,cellWidth:this.getCellWidth(),overflowCellsLimit:this.overflowCellsLimit,visibleWidth:this.width,margin:this.margin,minSwipeDistance:this.minSwipeDistance,transitionDuration:this.transitionDuration,transitionTimingFunction:this.transitionTimingFunction,videoProperties:this.videoProperties})},t.prototype.setDimensions=function(){this.hostStyleHeight=this.height+"px",this.hostStyleWidth=this.width+"px"},t.prototype.getFile=function(t){return this.carousel.getFile(t)},t.prototype.handleTransitionendCellContainer=function(t){this.carousel.handleSlideEnd()},t.prototype.toggleVideo=function(t){event.preventDefault(),this.videoProperties.noPlay||(t.paused?(t.play(),this.isVideoPlaying=!0):(t.pause(),this.isVideoPlaying=!1),this.ref.detectChanges())},t.prototype.getCurrentIndex=function(){return this.carousel.slideCounter},t.prototype.getCellWidth=function(){return"100%"===this._cellWidth?this.elementRef.nativeElement.clientWidth:this._cellWidth},t.prototype.next=function(){this.carousel.next(1)},t.prototype.prev=function(){this.carousel.prev(1)},t.prototype.select=function(t){this.carousel.select(t)},t.prototype.isNextArrowDisabled=function(){return this.carousel.isNextArrowDisabled()},t.prototype.isPrevArrowDisabled=function(){return this.carousel.isPrevArrowDisabled()},t.prototype.close=function(){this.overlayEventService.emitChangeEvent({type:"Hide"})},t.prototype.setInitialIndex=function(){null!=this._properties.metadata.index&&this.select(this._properties.metadata.index)},t.ctorParameters=function(){return[{type:e.ElementRef},{type:e.ChangeDetectorRef},{type:l}]},n([e.Input()],t.prototype,"images",null),n([e.Output()],t.prototype,"events",void 0),n([e.Input()],t.prototype,"height",void 0),n([e.Input()],t.prototype,"width",void 0),n([e.Input()],t.prototype,"borderRadius",void 0),n([e.Input()],t.prototype,"margin",void 0),n([e.Input()],t.prototype,"objectFit",void 0),n([e.Input()],t.prototype,"minSwipeDistance",void 0),n([e.Input()],t.prototype,"transitionDuration",null),n([e.Input()],t.prototype,"transitionTimingFunction",void 0),n([e.Input()],t.prototype,"videoProperties",void 0),n([e.Input()],t.prototype,"counterSeparator",void 0),n([e.Input()],t.prototype,"overflowCellsLimit",void 0),n([e.Input()],t.prototype,"listeners",void 0),n([e.Input("cellWidth")],t.prototype,"cellWidth",null),n([e.Input("counter")],t.prototype,"isCounter",null),n([e.Input()],t.prototype,"arrows",void 0),n([e.Input()],t.prototype,"arrowsOutside",void 0),n([e.Input()],t.prototype,"arrowsTheme",void 0),n([e.Input()],t.prototype,"overlayProperties",null),n([e.HostBinding("class.carousel")],t.prototype,"hostClassCarousel",void 0),n([e.HostBinding("style.height")],t.prototype,"hostStyleHeight",void 0),n([e.HostBinding("style.width")],t.prototype,"hostStyleWidth",void 0),n([e.HostListener("window:resize",["$event"])],t.prototype,"onWindowResize",null),t=n([e.Component({selector:"carousel, [carousel]",exportAs:"carousel",template:'<div class="carousel-backdrop"></div>\n\n<div class="carousel-close" (click)="close()"></div>\n\n<div class="carousel-counter" *ngIf="isCounter">{{counter}}</div>\n\n<div class="carousel-container" [class.carousel-moving]="isMoving">\n\t<div class="carousel-cells" (transitionend)="handleTransitionendCellContainer($event)">\n\t\t<ng-template ngFor let-image [ngForOf]="images" let-i="index">\n\t\t\t<div class="carousel-cell" \n\t\t\t\t*ngIf="i < cellLimit" \n\t\t\t\t[style.width]="getCellWidth()+\'px\'"\n\t\t\t\t[style.border-radius]="borderRadius+\'px\'">\n\t\t\t\t\x3c!-- Image --\x3e\n\t\t\t\t<img \n\t\t\t\t\t*ngIf="getFile(i) && getFile(i)[\'image\']" \n\t\t\t\t\t[src]="getFile(i)[\'image\'][\'path\']"\n\t\t\t\t\t[style.object-fit]="objectFit"\n\t\t\t\t\tdraggable="false" />\n\n\t\t\t\t\x3c!-- Video --\x3e\n\t\t\t\t<ng-template [ngIf]="getFile(i) && getFile(i)[\'type\'] === \'video\'">\n\t\t\t\t\t<div class="carousel-play" (click)="toggleVideo(video)"></div>\n\n\t\t\t\t\t<video #video\n\t\t\t\t\t\t[loop]="videoProperties.loop"\n\t\t\t\t\t\t[muted]="videoProperties.muted"\n\t\t\t\t\t\t[controls]="isSafari"\n\t\t\t\t\t\t[style.object-fit]="objectFit"\n\t\t\t\t\t\t[style.border-radius]="borderRadius+\'px\'">\n\t\t\t\t\t\t\n\t\t\t\t\t\t<source [src]="getFile(i)[\'path\']" type="video/mp4">\n\t\t\t\t\t</video>\n\t\t\t\t</ng-template>\n\t\t\t</div>\n\t\t</ng-template>\n\t</div>\n</div>\n\n<div class="carousel-arrows" \n\t[class.carousel-arrows-outside]="arrowsOutside" \n\t[class.carousel-dark-arrows]="arrowsTheme === \'dark\'"\n\t*ngIf="arrows">\n\t\n\t<div class="carousel-arrow carousel-arrow-prev" [class.carousel-arrow-disabled]="isPrevArrowDisabled()" (click)="prev()"></div>\n\t<div class="carousel-arrow carousel-arrow-next" [class.carousel-arrow-disabled]="isNextArrowDisabled()" (click)="next()"></div>\n</div>',styles:[":host{position:relative;display:block;top:0;left:0;width:100%;height:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:10000;transform-origin:top left;box-sizing:border-box}:host .carousel-container{overflow:hidden;width:100%;height:100%;cursor:-webkit-grab;cursor:grab}:host .carousel-container.carousel-moving{cursor:-webkit-grabbing;cursor:grabbing}:host .carousel-counter{text-align:right;position:absolute;z-index:30;transition:opacity .2s;top:15px;left:10px;border-radius:13px;background-color:rgba(23,37,68,.3);font-size:13px;color:#fff;padding:5px 7px;line-height:initial}:host .carousel-cells{transition:transform .2s;width:100%;height:100%;display:block}:host .carousel-cells ::ng-deep .carousel-cell.swiper-prev-image{transform:translate3d(-100%,0,0)}:host .carousel-cells ::ng-deep .carousel-cell.swiper-next-image{transform:translate3d(100%,0,0)}:host .carousel-cells ::ng-deep .carousel-cell{width:100%;height:100%;text-align:center;position:absolute;display:flex;align-items:center;justify-content:center;overflow:hidden}:host .carousel-cells ::ng-deep .carousel-cell img,:host .carousel-cells ::ng-deep .carousel-cell video{width:100%;height:100%;position:relative;-o-object-fit:contain;object-fit:contain}:host .carousel-cells ::ng-deep .carousel-cell img.swiper-hide{display:none}:host .carousel-cells ::ng-deep .carousel-cell .carousel-play{position:absolute;top:0;left:0;bottom:0;right:0;z-index:1}:host .carousel-arrow{width:40px;height:40px;background-color:#fff;background-repeat:no-repeat;background-size:31px;background-position:center;border-radius:100px;position:absolute;top:50%;margin-top:-20px;z-index:10;cursor:pointer;box-shadow:0 0 5px rgba(0,0,0,.15)}:host .carousel-arrow-prev{left:10px;background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0Ij48cGF0aCBkPSJNMTUuNDEgMTYuNTlMMTAuODMgMTJsNC41OC00LjU5TDE0IDZsLTYgNiA2IDYgMS40MS0xLjQxeiIvPjxwYXRoIGQ9Ik0wIDBoMjR2MjRIMFYweiIgZmlsbD0ibm9uZSIvPjwvc3ZnPg==)}:host .carousel-arrow-next{right:10px;background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0Ij48cGF0aCBkPSJNOC41OSAxNi41OUwxMy4xNyAxMiA4LjU5IDcuNDEgMTAgNmw2IDYtNiA2LTEuNDEtMS40MXoiLz48cGF0aCBkPSJNMCAwaDI0djI0SDBWMHoiIGZpbGw9Im5vbmUiLz48L3N2Zz4=)}:host .carousel-arrows-outside .carousel-arrow-prev{left:-60px}:host .carousel-arrows-outside .carousel-arrow-next{right:-60px}:host .carousel-dark-arrows .carousel-arrow{-webkit-filter:invert(1);filter:invert(1)}:host .carousel-arrow-disabled{cursor:default;opacity:.5}:host .carousel-close{position:fixed;top:10px;right:10px;width:40px;height:40px;z-index:100;cursor:pointer;background-repeat:no-repeat;background-size:31px;background-position:center;background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0Ij48cGF0aCBkPSJNMTkgNi40MUwxNy41OSA1IDEyIDEwLjU5IDYuNDEgNSA1IDYuNDEgMTAuNTkgMTIgNSAxNy41OSA2LjQxIDE5IDEyIDEzLjQxIDE3LjU5IDE5IDE5IDE3LjU5IDEzLjQxIDEyeiIvPjxwYXRoIGQ9Ik0wIDBoMjR2MjRIMHoiIGZpbGw9Im5vbmUiLz48L3N2Zz4=);-webkit-filter:invert(1);filter:invert(1)}:host .carousel-backdrop{position:fixed;top:0;left:0;right:0;bottom:0;background-color:#000;opacity:.5}"]})],t)}(),h=function(){function t(t){this.viewContainerRef=t}return t.ctorParameters=function(){return[{type:e.ViewContainerRef}]},t=n([e.Directive({selector:"[ad-host]"})],t)}(),p=function(){function t(t,e,i){var o=this;this.componentFactoryResolver=t,this.elementRef=e,this.eventService=i,this.overlayBackdrop=!0,this.minTimeout=30,this._hostOpacity=0,this.globalEventsSubscription=this.eventService.emitter.subscribe((function(t){o.handleGlobalEvents(t)}))}return Object.defineProperty(t.prototype,"hostOpacity",{get:function(){return this.properties.fadeIn?this._hostOpacity:1},set:function(t){this._hostOpacity=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hostTransition",{get:function(){var t=this.properties.animationDuration+"ms ",e=this.properties.animationTimingFunction;return"opacity "+t+e+", transform "+t+e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hostZIndex",{get:function(){return this.properties.zIndex},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hostWidth",{get:function(){return this.properties.wrapperWidth},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hostHeight",{get:function(){return this.properties.wrapperHeight},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hostPosition",{get:function(){return this.properties.position},enumerable:!0,configurable:!0}),t.prototype.onClick=function(t){this.elementRef.nativeElement.contains(t.target)||this.hostShown&&this.closeOverlay()},t.prototype.transitionEnd=function(t){"overlay"==t.target.tagName.toLowerCase()&&"opacity"==t.propertyName&&(this.hostShown?this.closeOverlayEnd():this.hostShown=!0)},Object.defineProperty(t.prototype,"popoverClass",{get:function(){if(this.properties.metadata)return this.properties.metadata.popoverClass},enumerable:!0,configurable:!0}),t.prototype.ngOnInit=function(){var t=this;this.loadComponent(),this.initialOverlay(),setTimeout((function(){t.isInitial=!0}),this.minTimeout)},t.prototype.ngAfterViewInit=function(){var t=this;setTimeout((function(){t.showOverlayAnimation()}),this.minTimeout)},t.prototype.ngOnDestroy=function(){this.globalEventsSubscription&&this.globalEventsSubscription.unsubscribe()},t.prototype.initialOverlay=function(){this.hostTransform="translateY("+this.properties.animationTranslateY+")"},t.prototype.showOverlayAnimation=function(){this.hostOpacity=1,this.hostTransform="translateY(0px)"},t.prototype.loadComponent=function(){var t=this.properties,e=this.componentFactoryResolver.resolveComponentFactory(t.mainComponent),i=this.adHost.viewContainerRef;i.clear();var o=i.createComponent(e),n=o.location.nativeElement;n.style.width=this.properties.width,n.style.height=this.properties.height,"string"==typeof this.popoverClass&&n.classList.add(this.popoverClass),"object"==typeof this.popoverClass&&this.popoverClass.forEach((function(t){n.classList.add(t)})),o.instance.overlayProperties=this.properties},t.prototype.closeOverlay=function(){this.hostOpacity=0,this.hostTransform="translateY("+this.properties.animationTranslateY+")"},t.prototype.closeOverlayEnd=function(){this.hostShown=!1,this.eventService.emitChangeEvent({type:"[Overlay] Hide"})},t.prototype.handleGlobalEvents=function(t){"Hide"===t.type&&this.closeOverlay()},t.ctorParameters=function(){return[{type:e.ComponentFactoryResolver},{type:e.ElementRef},{type:l}]},n([e.ViewChild(h,{static:!0})],t.prototype,"adHost",void 0),n([e.Input()],t.prototype,"properties",void 0),n([e.HostBinding("style.opacity")],t.prototype,"hostOpacity",null),n([e.HostBinding("style.transition")],t.prototype,"hostTransition",null),n([e.HostBinding("style.transform")],t.prototype,"hostTransform",void 0),n([e.HostBinding("style.z-index")],t.prototype,"hostZIndex",null),n([e.HostBinding("style.width")],t.prototype,"hostWidth",null),n([e.HostBinding("style.height")],t.prototype,"hostHeight",null),n([e.HostBinding("style.position")],t.prototype,"hostPosition",null),n([e.HostBinding("class.overlay-shown")],t.prototype,"hostShown",void 0),n([e.HostListener("document:click",["$event"])],t.prototype,"onClick",null),n([e.HostListener("transitionend",["$event"])],t.prototype,"transitionEnd",null),t=n([e.Component({selector:"overlay",template:'\x3c!--\n<div class="overlay-backdrop" \n\t*ngIf="properties.overlayBackdrop" \n\t(click)="onBackdropClick()" \n\t[ngClass]="properties.backdropClass"></div>\n--\x3e\n\x3c!--\n<div class="overlay-container"\n\t[ngStyle]="containerStyles" \n\t[ngClass]="properties.overlayClass">\n\n\t<ng-template ad-host></ng-template>\n</div>\n--\x3e\n\n<ng-template ad-host></ng-template>',styles:[":host{position:absolute;top:0;left:0}:host .overlay-backdrop{position:fixed;top:0;left:0;right:0;bottom:0;background-color:#000;opacity:0;z-index:1000;pointer-events:auto}"]})],t)}(),u={animationDuration:100,animationTimingFunction:"ease-in-out",position:"absolute",zIndex:1e3,fadeIn:!0},c=function(){function t(t,e,i,o){var n=this;this.componentFactoryResolver=t,this.appRef=e,this.injector=i,this.eventService=o,this.componentRefs={},this._properties={},this.globalEventsSubscription=this.eventService.emitter.subscribe((function(t){n.handleGlobalEvents(t)}))}return t.prototype.appendComponentToBody=function(t,e){if(void 0===e&&(e=p),!this.componentRefs[0]){var i=this.componentFactoryResolver.resolveComponentFactory(e).create(this.injector);this.componentRefs[0]=i,i.instance.properties=t,this.appRef.attachView(i.hostView);var o=i.hostView.rootNodes[0];document.body.appendChild(o)}},t.prototype.load=function(t){t=this.applyPropertieDefaults(u,t),this.appendComponentToBody(t)},t.prototype.close=function(t){void 0===t&&(t={})},t.prototype.applyPropertieDefaults=function(t,e){return e||(e={}),e.index||(e.index=0),this._defaultProperties=Object.assign({},t),Object.assign(this._defaultProperties,e)},t.prototype.objectLength=function(t){var e,i=0;for(e in t)t.hasOwnProperty(e)&&i++;return i},t.prototype.handleGlobalEvents=function(t){"[Overlay] Hide"===t.type&&this.handleCloseEvent()},t.prototype.handleCloseEvent=function(){this.appRef.detachView(this.componentRefs[0].hostView),this.componentRefs[0].destroy(),delete this.componentRefs[0]},t.ctorParameters=function(){return[{type:e.ComponentFactoryResolver},{type:e.ApplicationRef},{type:e.Injector},{type:l}]},t=n([e.Injectable()],t)}(),d={transitionDuration:400,minSwipeDistance:50,transitionTimingFunction:"ease",counterSeparator:" / ",arrows:!0},g=function(){function t(t,e){this.overlay=t,this.overlayEventService=e}return t.prototype.load=function(t){t=this.applyPropertieDefaults(d,t),this.overlay.load({id:"gallery",mainComponent:a,width:document.body.clientWidth+"px",overlayBackdrop:!0,position:"fixed",metadata:{images:t.images,index:t.index,width:document.body.clientWidth,height:window.innerHeight,objectFit:"none",margin:0,transitionDuration:t.transitionDuration,overflowCellsLimit:1,transitionTimingFunction:t.transitionTimingFunction,counter:t.counter,counterSeparator:t.counterSeparator,arrows:t.arrows,minSwipeDistance:t.minSwipeDistance}})},t.prototype.close=function(){this.overlayEventService.emitChangeEvent({type:"Hide"})},t.prototype.applyPropertieDefaults=function(t,e){for(var i in e||(e={}),e)void 0===e[i]&&delete e[i];return this._defaultProperties=Object.assign({},t),Object.assign(this._defaultProperties,e)},t.ctorParameters=function(){return[{type:c},{type:l}]},t=n([e.Injectable()],t)}(),f=function(){function t(){}return t=n([e.NgModule({declarations:[p,h],imports:[i.CommonModule],exports:[],providers:[c,l],bootstrap:[],entryComponents:[p]})],t)}(),m=function(){function t(){}return t=n([e.NgModule({declarations:[a],imports:[i.CommonModule,f],exports:[a],providers:[g],bootstrap:[],entryComponents:[a]})],t)}();t.Gallery=g,t.IvyGalleryModule=m,t.ɵa=a,t.ɵb=l,t.ɵc=f,t.ɵd=p,t.ɵe=h,t.ɵf=c,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=angular-gallery.umd.min.js.map