@crystalui/angular-lightbox
Version:
Angular library for viewing images in a pop-up window with touch screen support.
980 lines (967 loc) • 43.6 kB
JavaScript
import { __decorate } from 'tslib';
import { Injectable, Input, HostBinding, ViewChild, Component, EventEmitter, ElementRef, ChangeDetectorRef, HostListener, ComponentFactoryResolver, ApplicationRef, Injector, Output, Directive, ContentChildren, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ReplaySubject } from 'rxjs';
let EventService = class EventService {
constructor() {
this.emitter = new ReplaySubject(1);
}
emitChangeEvent(data) {
this.emitter.next(data);
}
};
EventService = __decorate([
Injectable()
], EventService);
class Utils {
static mobileCheck() {
var check = false;
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
check = true; })(navigator.userAgent || navigator.vendor);
return check;
}
;
}
let LightboxCommonComponent = class LightboxCommonComponent {
constructor(eventService) {
this.eventService = eventService;
this.currentImageIndex = 0;
this.indexCurrentSlide = 1;
this.containerStyles = {
transition: '',
transform: '',
width: '',
height: '',
opacity: ''
};
this.currImageLoadingState = 'not-loaded';
this.isMobile = Utils.mobileCheck();
}
get lightboxImage() {
return this._lightboxImage;
}
get lightboxImageElement() {
if (this.lightboxImage) {
return this.lightboxImage.nativeElement;
}
}
get lightboxImageNaturalHeight() {
if (this.lightboxImageElement) {
return this.lightboxImageElement.naturalHeight;
}
}
get lightboxImageNaturalWidth() {
if (this.lightboxImageElement) {
return this.lightboxImageElement.naturalWidth;
}
}
get index() {
return this.currentImageIndex;
}
get properties() {
return this.lightboxData.properties;
}
get images() {
return this.lightboxData.images || [this.lightboxData.image];
}
get thumbnailImage() {
return this.images[this.currentImageIndex].nativeElement;
}
get thumbnailImagePosition() {
return this.thumbnailImage.getBoundingClientRect();
}
// Image size if it is larger than the window size
get virtualImageDimension() {
let height = this.lightboxImageNaturalHeight;
let width = height * this.imageAspectRatio;
const windowWidth = document.body.clientWidth;
const windowHeight = window.innerHeight;
if (this.isImageLargerWindow) {
if (height > windowHeight) {
height = windowHeight;
width = height * this.imageAspectRatio;
}
if (width > windowWidth) {
width = windowWidth;
height = width / this.imageAspectRatio;
}
}
else {
width = this.lightboxImageNaturalWidth;
height = this.lightboxImageNaturalHeight;
}
if (width === 0 || Number.parseInt(height) === 0) {
return { width: 200, height: 200 };
}
return { width, height };
}
get containerInitialPosition() {
const scale = (this.showState === 'initial-thumbnail-image') ? 1 : this.containerScale;
const top = this.thumbnailImagePosition.top;
const left = this.thumbnailImagePosition.left;
return 'matrix(' + scale + ', 0, 0, ' + scale + ',' + left + ',' + top + ')';
}
get containerFullscreenPosition() {
const left = (document.body.clientWidth - this.virtualImageDimension.width) / 2;
const top = (window.innerHeight - this.virtualImageDimension.height) / 2;
return 'translate3d(' + left + 'px, ' + top + 'px, 0)';
}
get containerScale() {
return this.thumbnailImagePosition.width / this.virtualImageDimension.width;
}
get imageAspectRatio() {
return this.thumbnailImage.naturalWidth / this.thumbnailImage.naturalHeight;
}
get isImageLargerWindow() {
const imageNaturalWidth = this.lightboxImageNaturalWidth;
const imageNaturalHeight = this.lightboxImageNaturalHeight;
const windowWidth = document.body.clientWidth;
const windowHeight = window.innerHeight;
return imageNaturalWidth > windowWidth || imageNaturalHeight > windowHeight;
}
get isFirstImage() {
if (this.properties.loop) {
return false;
}
else {
return this.index === 0;
}
}
get isLastImage() {
if (this.properties.loop) {
return false;
}
else {
return this.index === this.latestImageIndex;
}
}
get latestImageIndex() {
return this.images.length - 1;
}
get backgroundColor() {
const opacity = this.properties.backgroundOpacity;
const color = this.properties.backgroundColor;
if (color === 'black') {
return 'rgba(0, 0, 0, ' + opacity + ')';
}
else {
return 'rgba(255, 255, 255, ' + opacity + ')';
}
}
get animationDuration() {
const animationDuration = this.properties.animationDuration;
if (typeof animationDuration === "string") {
return Number.parseInt(animationDuration);
}
else {
return animationDuration;
}
}
get animationMode() {
if (this.currImageLoadingState === 'error') {
return 'default';
}
return this.properties.animationMode;
}
get animationTimingFunction() {
return this.properties.animationTimingFunction;
}
get closeButtonText() {
return this.properties.closeButtonText;
}
get counterSeparator() {
return this.properties.counterSeparator;
}
get counter() {
return this.currentImageIndex + 1 + this.counterSeparator + this.images.length;
}
emitState(type, state) {
if (state === 'initial-virtual-image' ||
state === 'initial-styles') {
return;
}
if (state === 'initial-default' ||
state === 'initial-thumbnail-image') {
state = 'initial';
}
this.eventService.emitChangeEvent({
type: type + ':' + state
});
}
setShowState(state) {
this.showState = state;
this.emitState('show-state', state);
}
setClosingState(state) {
this.closingState = state;
this.emitState('closing-state', state);
}
setAnimationDuration() {
this.hostStyleTransition = 'background-color ' + this.animationDuration + 'ms';
this.containerStyles.transition = 'all ' + this.animationDuration + 'ms ' + this.animationTimingFunction;
}
setBackgroundColor() {
this.hostStyleBackgroundColor = this.backgroundColor;
}
getContainerHeight() {
return this.thumbnailImagePosition.height / this.containerScale + 'px';
}
showThumbnailImage() {
this.thumbnailImage.style.opacity = '';
}
hideThumbnailImage() {
this.thumbnailImage.style.opacity = 0;
}
updateThumbnailPosition() {
this.containerStyles.transform = this.containerInitialPosition;
}
};
LightboxCommonComponent.ctorParameters = () => [
{ type: EventService }
];
__decorate([
Input()
], LightboxCommonComponent.prototype, "lightboxData", void 0);
__decorate([
HostBinding('style.backgroundColor')
], LightboxCommonComponent.prototype, "hostStyleBackgroundColor", void 0);
__decorate([
HostBinding('style.transition')
], LightboxCommonComponent.prototype, "hostStyleTransition", void 0);
__decorate([
ViewChild('imageFirst', { static: true })
], LightboxCommonComponent.prototype, "_imageFirst", void 0);
__decorate([
ViewChild('imageSecond', { static: true })
], LightboxCommonComponent.prototype, "_imageSecond", void 0);
__decorate([
ViewChild('imageLast', { static: true })
], LightboxCommonComponent.prototype, "_imageLast", void 0);
__decorate([
ViewChild('lightboxImage', { static: true })
], LightboxCommonComponent.prototype, "_lightboxImage", void 0);
LightboxCommonComponent = __decorate([
Component({
selector: 'lightbox-common',
template: ''
})
], LightboxCommonComponent);
let LightboxComponent = class LightboxComponent extends LightboxCommonComponent {
constructor(elementRef, ref, eventService) {
super(eventService);
this.elementRef = elementRef;
this.ref = ref;
this.eventService = eventService;
this.spinnerHeight = 30;
this.minTimeout = 30;
this.preloaderTimeout = 100;
this.spinnerStyles = {
transform: ''
};
this.configThumbnailPreloader = true;
this.events = new EventEmitter();
this.hostShown = false;
this.hideControls = false;
}
get simpleMode() {
return this.properties.simpleMode;
}
get hostLightTheme() {
return this.properties.backgroundColor === 'white';
}
get currImagePath() {
let image = this.images[this.index];
let path;
if (!image) {
return false;
}
if (image.fullImage && image.fullImage.path) {
path = image.fullImage.path;
}
else if (image.thumbnailImage && image.thumbnailImage.path) {
path = image.thumbnailImage.path;
}
else if (image.path) {
path = image.path;
}
return path;
}
get prevImagePath() {
return this.images[this.prevIndex];
}
set prevImagePath(value) {
this.images[this.prevIndex] = value;
}
get isHiddenPrevArrow() {
return this.isFirstImage && !this.properties.loop || this.isZoomIn;
}
get isHiddenNextArrow() {
return this.isLastImage && !this.properties.loop || this.isZoomIn;
}
get isPreloader() {
return this.animationMode === 'zoom-preloader' &&
this.showState != 'animation-end' &&
this.currImageLoadingState === 'loading';
}
get imageOrientation() {
if (this.thumbnailImage.naturalWidth > this.thumbnailImage.naturalHeight) {
return 'horizontal';
}
else {
return 'vertical';
}
}
scrolling() {
if (this.showState === 'initial-thumbnail-image' ||
this.showState === 'initial-virtual-image' ||
this.closingState === 'animation') {
this.updateThumbnailPosition();
}
}
onKeyDown(event) {
switch (event.key) {
case 'ArrowLeft':
this.prev();
break;
case 'ArrowRight':
this.next();
break;
case 'Escape':
this.closeLightbox();
break;
}
}
onMouseEnter(event) {
this.hideControls = false;
}
transitionEnd(event) {
if (event.propertyName === "transform" && this.hostAnimation) {
this.hostAnimation = false;
}
}
ngOnInit() {
this.currentImageIndex = this.properties.index;
this.initialLightbox();
}
ngAfterViewInit() {
setTimeout(() => {
if (this.currImageLoadingState === 'not-loaded') {
this.currImageLoadingState = 'loading';
}
}, this.preloaderTimeout);
// Mode: default
if (this.animationMode === 'default') {
setTimeout(() => {
this.showLightboxAnimation();
}, this.minTimeout);
}
}
onImageLoaded() {
// When opening lightbox
if (this.animationMode === 'zoom-preloader' &&
this.showState === 'initial-thumbnail-image') {
this.initialLightboxVirtualImage();
setTimeout(() => {
this.currImageLoadingState = 'uploaded';
this.showLightboxAnimation();
if (this.properties.hideThumbnail) {
this.hideThumbnailImage();
}
}, this.minTimeout);
}
// When opening next / previous image
if (this.showState === 'animation-end') {
this.currImageLoadingState = 'uploaded';
if (this.properties.hideThumbnail) {
this.hideThumbnailImage();
}
}
this.ref.detectChanges();
}
onImageError(event) {
this.currImageLoadingState = 'error';
this.initialLightboxDefault();
setTimeout(() => {
this.showLightboxAnimation();
}, this.minTimeout);
}
onContainerClick(event) {
if (event.target === this.lightboxContainerElem.nativeElement || this.simpleMode) {
this.closeLightbox();
}
}
initialLightbox() {
this.setMaxDimensions();
this.setAnimationDuration();
switch (this.animationMode) {
case 'zoom-preloader':
this.initialLightboxThumbnailImage();
break;
case 'default':
this.initialLightboxDefault();
break;
}
}
initialLightboxDefault() {
this.showState = 'initial-default';
this.containerStyles = {
transform: 'translate3d(0, 0, 0)',
height: '100%',
width: '100%',
opacity: '0'
};
// next step: AfterViewInit
}
initialLightboxVirtualImage() {
this.setShowState('initial-virtual-image');
this.containerStyles = {
transform: this.containerInitialPosition,
height: this.virtualImageDimension.height + 'px',
width: this.virtualImageDimension.width + 'px'
};
// next step: onImageLoaded() -> showLightboxAnimation()
}
initialLightboxThumbnailImage() {
this.setShowState('initial-thumbnail-image');
this.containerStyles = {
transform: this.containerInitialPosition,
height: this.thumbnailImagePosition.height + 'px',
width: this.thumbnailImagePosition.width + 'px'
};
// next step: onImageLoaded()
}
showLightboxAnimation() {
this.hostAnimation = true;
this.setShowState('animation');
this.hostShown = true;
this.setBackgroundColor();
this.setAnimationDuration();
// Mode: zoom preloader
if (this.animationMode === 'zoom-preloader' &&
this.currImageLoadingState !== 'error') {
this.containerStyles.transform = this.containerFullscreenPosition;
}
// Mode: default
if (this.animationMode === 'default') {
this.containerStyles.opacity = '1';
}
// next step: handleLightboxTransitionEnd
}
showLightboxAnimationEnd() {
this.setShowState('animation-end');
this.containerStyles = {
transform: 'translate3d(0, 0, 0)',
height: '100%',
width: '100%',
};
}
closeLightbox() {
this.setClosingState('initial');
this.hostShown = false;
this.closeLightboxInitial();
}
closeLightboxInitial() {
this.setClosingState('initial-styles');
// Mode: zoom preloader
if (this.animationMode === 'zoom-preloader') {
this.containerStyles = {
transform: this.containerFullscreenPosition,
height: this.virtualImageDimension.height + 'px',
width: this.virtualImageDimension.width + 'px',
};
}
// Mode: default
if (this.animationMode === 'default') {
this.containerStyles.opacity = '1';
}
setTimeout(() => {
this.closeLightboxAnimation();
}, this.minTimeout);
}
closeLightboxAnimation() {
this.setClosingState('animation');
// Mode: zoom preloader
if (this.animationMode === 'zoom-preloader') {
this.hostAnimation = true;
this.containerStyles = {
transform: this.containerInitialPosition,
height: this.getContainerHeight(),
width: this.getContainerWidth(),
};
this.hostStyleBackgroundColor = '';
}
// Mode: default
if (this.animationMode === 'default') {
this.hostAnimation = true;
this.containerStyles.opacity = '0';
this.hostStyleBackgroundColor = '';
}
this.setAnimationDuration();
// next step: handleLightboxTransitionEnd
if (this.animationDuration === 0) { // in the future, change to a type conversion getter
this.closeLightboxAnimationEnd();
}
}
closeLightboxAnimationEnd() {
this.setClosingState('animation-end');
this.events.emit({ type: 'close' });
// Mode: zoom preloader
if (this.animationMode === 'zoom-preloader') {
this.showThumbnailImage();
}
}
/*
* Transition End
*/
handleLightboxTransitionEnd(event) {
if (this.showState === 'animation') {
this.showLightboxAnimationEnd();
}
// Last close step
if (this.closingState === 'animation') {
this.closeLightboxAnimationEnd();
}
}
next() {
if (this.animationMode === 'zoom-preloader') {
this.showThumbnailImage();
}
if (this.isLastImage) {
if (this.properties.loop) {
this.currentImageIndex = 0;
}
else {
return;
}
}
else {
this.currentImageIndex++;
this.currImageLoadingState = 'loading';
}
setTimeout(() => {
if (this.currImageLoadingState !== 'uploaded') {
this.currImageLoadingState = 'loading';
}
}, this.preloaderTimeout);
}
prev() {
if (this.animationMode === 'zoom-preloader') {
this.showThumbnailImage();
}
if (this.isFirstImage) {
if (this.properties.loop) {
this.currentImageIndex = this.latestImageIndex;
}
else {
return;
}
}
else {
this.currentImageIndex--;
this.currImageLoadingState = 'loading';
}
setTimeout(() => {
if (this.currImageLoadingState !== 'uploaded') {
this.currImageLoadingState = 'loading';
}
}, this.preloaderTimeout);
}
setMaxDimensions() {
this.lightboxImage.nativeElement.style.maxHeight = 'calc(' + this.properties.imageMaxHeight + ')';
this.lightboxImage.nativeElement.style.maxWidth = this.properties.imageMaxWidth;
}
handlePinchZoomEvents(event) {
if (event.type === "zoom-in") {
this.isZoomIn = true;
}
if (event.type === "zoom-out") {
this.isZoomIn = false;
}
}
getContainerWidth() {
return this.thumbnailImagePosition.width / this.containerScale + 'px';
}
};
LightboxComponent.ctorParameters = () => [
{ type: ElementRef },
{ type: ChangeDetectorRef },
{ type: EventService }
];
__decorate([
HostBinding('class.lightbox-shown')
], LightboxComponent.prototype, "hostShown", void 0);
__decorate([
HostBinding('class.lightbox-hide-controls')
], LightboxComponent.prototype, "hideControls", void 0);
__decorate([
HostBinding('class.lightbox-animation')
], LightboxComponent.prototype, "hostAnimation", void 0);
__decorate([
HostBinding('class.lightbox-simple-mode')
], LightboxComponent.prototype, "simpleMode", null);
__decorate([
HostBinding('class.lightbox-light')
], LightboxComponent.prototype, "hostLightTheme", null);
__decorate([
HostBinding('style.backgroundColor')
], LightboxComponent.prototype, "hostStyleBackgroundColor", void 0);
__decorate([
ViewChild('prevImageElem', { static: true })
], LightboxComponent.prototype, "prevImageElem", void 0);
__decorate([
ViewChild('lightboxContainer', { static: true })
], LightboxComponent.prototype, "lightboxContainerElem", void 0);
__decorate([
HostListener('window:scroll')
], LightboxComponent.prototype, "scrolling", null);
__decorate([
HostListener('window:keydown', ['$event'])
], LightboxComponent.prototype, "onKeyDown", null);
__decorate([
HostListener("mouseenter", ['$event'])
], LightboxComponent.prototype, "onMouseEnter", null);
__decorate([
HostListener('transitionend', ['$event'])
], LightboxComponent.prototype, "transitionEnd", null);
LightboxComponent = __decorate([
Component({
selector: 'crystal-lightbox',
template: "<div class=\"lightbox-counter\" *ngIf=\"properties.counter && images.length > 1\">{{counter}}</div>\n<div class=\"lightbox-close\" *ngIf=\"!simpleMode\" (click)=\"closeLightbox()\">{{closeButtonText}}</div>\n<div class=\"lightbox-spinner\" \n\t*ngIf=\"currImageLoadingState === 'loading' && showState === 'animation-end'\"></div>\n<div class=\"lightbox-container\" \n\t#lightboxContainer\n\t[ngStyle]=\"containerStyles\"\n\t(transitionend)=\"handleLightboxTransitionEnd($event)\"\n\t(click)=\"onContainerClick($event)\">\n\n\t<div class=\"lightbox-preloader\" *ngIf=\"isPreloader\">\n\t\t<div class=\"lightbox-spinner\"></div>\n\t</div>\n\n\t<div class=\"lightbox-error\" *ngIf=\"currImageLoadingState === 'error' && !closingState\">Failed to load image</div>\n\n\t<img class=\"lightbox-curr-image\" \n\t\t#lightboxImage\n\t\t[src]=\"currImagePath\" \n\t\t[class.lightbox-show]=\"currImageLoadingState === 'uploaded'\" \n\t\t(load)=\"onImageLoaded()\"\n\t\t(error)=\"onImageError($event)\" />\n</div>\n\n<div class=\"lightbox-prev\" [hidden]=\"isHiddenPrevArrow\" (click)=\"prev()\"></div>\n<div class=\"lightbox-next\" [hidden]=\"isHiddenNextArrow\" (click)=\"next()\"></div>",
styles: [".lightbox-spinner,.lightbox-spinner:after,.lightbox-spinner:before{border-radius:50%;width:10px;height:10px;-webkit-animation:1.5s ease-in-out infinite lightbox-load;animation:1.5s ease-in-out infinite lightbox-load}.lightbox-spinner{color:#fff;font-size:10px;margin:0 auto 20px;position:relative;text-indent:-9999em;transform:translateZ(0);-webkit-animation-delay:-.16s;animation-delay:-.16s}.lightbox-spinner:after,.lightbox-spinner:before{content:\"\";position:absolute;top:0}.lightbox-spinner:before{left:-32px;-webkit-animation-delay:-.32s;animation-delay:-.32s}.lightbox-spinner:after{left:32px}@-webkit-keyframes lightbox-load{0%,100%,80%{box-shadow:0 2.5em 0 -1.3em}40%{box-shadow:0 2.5em 0 0}}@keyframes lightbox-load{0%,100%,80%{box-shadow:0 10px 0 -1.3em}40%{box-shadow:0 10px 0 0}}:host.lightbox-shown{opacity:1}:host.lightbox-shown .lightbox-close,:host.lightbox-shown .lightbox-next,:host.lightbox-shown .lightbox-prev{opacity:.5;transition-delay:.1s}:host.lightbox-shown .lightbox-close:hover,:host.lightbox-shown .lightbox-next:hover,:host.lightbox-shown .lightbox-prev:hover{opacity:1;transition-delay:0}:host.lightbox-shown .lightbox-counter{opacity:1}:host.lightbox-hide-controls .lightbox-close,:host.lightbox-hide-controls .lightbox-next,:host.lightbox-hide-controls .lightbox-prev{opacity:0}:host.lightbox-simple-mode .lightbox-container{cursor:zoom-out}:host:not(.lightbox-animation) .lightbox-container{display:flex;align-items:center;justify-content:center;top:0;left:0;height:100%}:host.lightbox-light{color:#000;text-shadow:none}:host{position:fixed;top:0;left:0;width:100%;height:100%;color:#fff;text-shadow:0 0 1px rgba(0,0,0,.65);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:10000}:host img{opacity:1;max-width:100%;max-height:100%}:host img.lightbox-curr-image.lightbox-show{opacity:1}:host img.lightbox-curr-image{opacity:0;z-index:10}:host .lightbox-container.lightbox-hide{display:none}:host .lightbox-container{position:absolute;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;transform-origin:top left}:host .lightbox-preloader{background:rgba(0,0,0,.4);display:flex;align-items:center;justify-content:center;width:100%;height:100%;position:absolute}:host .lightbox-spinner{position:absolute;top:51%;left:50%;margin-top:-15px;margin-left:-5px}:host .lightbox-preloader .lightbox-spinner{margin-top:-9px;margin-left:-3px}:host .lightbox-preloader .lightbox-spinner,:host .lightbox-preloader .lightbox-spinner:after,:host .lightbox-preloader .lightbox-spinner:before{width:6px;height:6px}:host .lightbox-preloader .lightbox-spinner:before{left:-21px}:host .lightbox-preloader .lightbox-spinner:after{left:21px}:host .lightbox-counter{text-align:left;position:absolute;left:22px;top:13px;font-size:14px;z-index:30}:host .lightbox-description{text-align:center;max-width:calc(100% - 200px);margin:0 auto;font-size:14px;line-height:43px;position:relative;z-index:50}:host .lightbox-error{color:rgba(255,255,255,.75);font-size:19px}:host .lightbox-close{position:absolute;top:0;right:0;padding:13px 22px;font-size:13px;text-transform:uppercase;cursor:pointer;opacity:.5;z-index:30;transition:opacity .1s ease-in-out}:host .lightbox-next,:host .lightbox-prev{width:100px;height:100%;position:absolute;top:0;cursor:pointer;opacity:.5;z-index:20;transition:opacity .1s ease-in-out;-webkit-tap-highlight-color:rgba(255,255,255,0)}:host .lightbox-prev{left:0;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAiCAYAAABbXymAAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNv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/eHBhY2tldCBlbmQ9InIiPz7zv5BKAAACl0lEQVR42rTW224SQRwGcHZb8FT1Sm88BJCiFAE5JpyCBNRE8coYEy94AGqi9XDXS0+JVh/CB/EhiFET5LjAclgWjaa1aazfJDM6u6LuLjrJl2124cd0duY/I9h+NoELabtcTLcFCon0bw+SRE4h28hn2xyNoIvISrlcfqAoSluSpLepVKqCe6cRB/2MYAXei1wfjUbSLm34gX4ymbyN+z6rOBmC/ciNer3+fpdrwGXgd8h/YwVn8Dm/37/e6/UGOnyQTqfXrOBsKI4g571e76Nutzv8De43gwv05S0hx5CLwJ/iBWrwyWQyzGazpnHyITtyCDlBcI/H8wS4ZlhUVbWMO/R4p9P5Bc/lcnfx/Ow8+AW32z0LH+Xz+X+Dt9ttmcen0ynDA1bx4wR3Op2PW62WrOv5uFAo3JsXL1K8r+v5LNxmZrb8wJvNpn5YlGKxeJ/WFruZBcRPxUsul2u90WhocCyqBqk3dLGJiwbgb/T6FflCSqkoiluCIGjqNGzWgQUz9YR8aQ9yBqtyDQtH0q1KNZPJPMTzOHKA4oaHwuPz+SooUm0eHY/H00QisUEWFHKUDYVRdBmVr9Lv9/WoGo/HX+J5iY7/QSMvj003hnb0aCwWe4HnV5GTyGEj002DDgYDDYqdRo1Goxu0p3pU+BvqDQQCqzPQCUWvzINKejQcDltHQ6HQLaBdHh0Oh5ZRO0OBaFD8iIL7z82ibGtyRyKR1T+gl82g/GZ6Dev/HY/KsqwEg0FLKL/93+R7C3QM9Nk8KDtiOWq12jb2s2XS01Kp9Kparb7G/TfIR2QT2TF6UBS42bBEi/UK/SIBPyCfkC0zKA+z6rWPXm30tLlJr6ZQ/ZmYDYnI1eEdejV9Thb+18H7uwADAOG/Wcm4x+knAAAAAElFTkSuQmCC) center right 22px no-repeat}:host .lightbox-close,:host .lightbox-counter,:host .lightbox-next,:host .lightbox-prev{opacity:0;transition:opacity 150ms cubic-bezier(.475,.105,.445,.945)}"]
})
], LightboxComponent);
const DefaultProperties = {
loop: false,
index: 0,
counter: false,
imageMaxHeight: "100%",
imageMaxWidth: "100%",
animationDuration: 350,
animationMode: 'zoom-preloader',
animationTimingFunction: 'cubic-bezier(0.475, 0.105, 0.445, 0.945)',
closeButtonText: 'Close',
counterSeparator: '/',
disable: false,
simpleMode: false,
backgroundColor: 'black',
backgroundOpacity: 1,
hideThumbnail: true,
gestureEnable: false
};
let CrystalLightbox = class CrystalLightbox {
constructor(componentFactoryResolver, appRef, injector) {
this.componentFactoryResolver = componentFactoryResolver;
this.appRef = appRef;
this.injector = injector;
}
appendComponentToBody(component, lightboxData) {
const componentRef = this.componentFactoryResolver
.resolveComponentFactory(component)
.create(this.injector);
componentRef.instance.lightboxData = lightboxData;
this.appRef.attachView(componentRef.hostView);
const domElem = componentRef.hostView.rootNodes[0];
// Add to body
document.body.appendChild(domElem);
componentRef.instance.events.subscribe((event) => {
if (event.type === 'close') {
this.appRef.detachView(componentRef.hostView);
componentRef.destroy();
}
});
}
open(lightboxData) {
lightboxData.properties = this.applyPropertieDefaults(DefaultProperties, lightboxData.properties);
let component = this.getLightboxComponent();
this.appendComponentToBody(component, lightboxData);
}
getLightboxComponent() {
return LightboxComponent;
}
applyPropertieDefaults(defaultProperties, properties) {
if (!properties) {
properties = {};
}
if (!properties.index) {
properties.index = 0;
}
this._defaultProperties = Object.assign({}, defaultProperties);
return Object.assign(this._defaultProperties, properties);
}
};
CrystalLightbox.ctorParameters = () => [
{ type: ComponentFactoryResolver },
{ type: ApplicationRef },
{ type: Injector }
];
CrystalLightbox = __decorate([
Injectable()
], CrystalLightbox);
let LightboxDirective = class LightboxDirective {
constructor(lightbox, eventService, elementRef) {
this.lightbox = lightbox;
this.eventService = eventService;
this.elementRef = elementRef;
this.properties = {};
this.events = new EventEmitter();
this.hostLightboxGroup = true;
this.globalEventsSubscription = this.eventService.emitter.subscribe((event) => {
this.handleGlobalEvents(event);
});
}
get hostSimpleMode() {
return this.simpleMode;
}
get isGroupImage() {
return this.elementRef.nativeElement.closest(".lightbox-group");
}
onClick(event) {
if (this.disable) {
return;
}
if (this.isGroupImage) {
this.eventService.emitChangeEvent({
type: 'thumbnail:click',
elementRef: this.elementRef,
properties: this.properties
});
}
else {
this.image = this.getImage();
this.lightbox.open({
images: [this.image],
properties: this.properties,
index: 0
});
}
}
ngOnChanges(changes) {
this.properties = Object.assign({}, this.properties, this.getProperties(changes));
}
handleGlobalEvents(event) {
this.events.emit(event);
}
getImage() {
let image = {};
const nativeElement = this.elementRef.nativeElement;
if (this.fullImage) {
image.fullImage = this.fullImage;
}
image.thumbnailImage = {
path: nativeElement.src,
height: nativeElement.naturalHeight,
width: nativeElement.naturalWidth
};
image.nativeElement = nativeElement;
return image;
}
;
getProperties(changes) {
let properties = {};
for (var prop in changes) {
if (prop !== 'fullImage') {
properties[prop] = changes[prop].currentValue;
}
}
return properties;
}
};
LightboxDirective.ctorParameters = () => [
{ type: CrystalLightbox },
{ type: EventService },
{ type: ElementRef }
];
__decorate([
Input()
], LightboxDirective.prototype, "fullImage", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "properties", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "loop", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "backgroundOpacity", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "counter", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "imageMaxHeight", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "imageMaxWidth", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "animationDuration", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "animationMode", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "animationTimingFunction", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "closeButtonText", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "counterSeparator", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "disable", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "simpleMode", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "backgroundColor", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "hideThumbnail", void 0);
__decorate([
Input()
], LightboxDirective.prototype, "gestureEnable", void 0);
__decorate([
Output()
], LightboxDirective.prototype, "events", void 0);
__decorate([
HostBinding('class.lightbox-single')
], LightboxDirective.prototype, "hostLightboxGroup", void 0);
__decorate([
HostBinding('class.lightbox-simple-mode')
], LightboxDirective.prototype, "hostSimpleMode", null);
__decorate([
HostListener('click', ['$event'])
], LightboxDirective.prototype, "onClick", null);
LightboxDirective = __decorate([
Directive({
selector: '[lightbox]'
})
], LightboxDirective);
let LightboxGroupDirective = class LightboxGroupDirective {
constructor(eventService, lightbox) {
this.eventService = eventService;
this.lightbox = lightbox;
this.thumbnailImages = [];
this.images = [];
this.properties = {};
this.hostLightboxGroup = true;
this.globalEventsSubscription = this.eventService.emitter.subscribe((event) => {
this.handleGlobalEvents(event);
});
}
get lightboxDirectiveList() {
if (this._lightboxDirectiveList) {
return this._lightboxDirectiveList.toArray();
}
else {
return [];
}
}
handleGlobalEvents(event) {
if (event.type === 'thumbnail:click') {
this.thumbnailImageElement = event.elementRef.nativeElement;
this.thumbnailImages = this.getThumbnailImages();
this.thumbnailImageIndex = this.getThumbnailImageIndex(this.thumbnailImageElement);
if (this.thumbnailImageIndex == undefined) {
return;
}
this.thumbnailLightboxDirective = this.getThumbnailLightboxDirective(this.thumbnailImageIndex);
this.images = this.getImages();
this.properties = event.properties;
this.properties.index = this.thumbnailImageIndex;
this.lightbox.open({
images: this.images,
//index: this.thumbnailImageIndex,
properties: this.properties
});
}
}
getThumbnailImageIndex(element) {
const images = this.thumbnailImages;
for (var i = 0; i < images.length; i++) {
if (element === images[i]) {
return i;
}
}
}
getThumbnailLightboxDirective(index) {
return this.lightboxDirectiveList[index];
}
getThumbnailImages() {
let thumbnailImages = [];
this.lightboxDirectiveList.forEach(el => {
thumbnailImages.push(el['elementRef'].nativeElement);
});
return thumbnailImages;
}
getImages() {
let images = [];
this.lightboxDirectiveList.forEach(el => {
let image = {};
const nativeElement = el['elementRef'].nativeElement;
if (el.fullImage) {
image.fullImage = el.fullImage;
}
image.thumbnailImage = {
path: nativeElement.src,
height: nativeElement.naturalHeight,
width: nativeElement.naturalWidth
};
image.nativeElement = nativeElement;
images.push(image);
});
return images;
}
};
LightboxGroupDirective.ctorParameters = () => [
{ type: EventService },
{ type: CrystalLightbox }
];
__decorate([
HostBinding('class.lightbox-group')
], LightboxGroupDirective.prototype, "hostLightboxGroup", void 0);
__decorate([
ContentChildren(LightboxDirective, { descendants: true })
], LightboxGroupDirective.prototype, "_lightboxDirectiveList", void 0);
LightboxGroupDirective = __decorate([
Directive({
selector: '[lightbox-group]'
})
], LightboxGroupDirective);
let CrystalLightboxModule = class CrystalLightboxModule {
};
CrystalLightboxModule = __decorate([
NgModule({
declarations: [
LightboxCommonComponent,
LightboxComponent,
LightboxDirective,
LightboxGroupDirective
],
imports: [
CommonModule
],
exports: [
LightboxDirective,
LightboxGroupDirective
],
providers: [
CrystalLightbox,
EventService
],
bootstrap: [],
entryComponents: [
LightboxComponent
]
})
], CrystalLightboxModule);
/*
* Public API Surface of angular-lightbox
*/
/**
* Generated bundle index. Do not edit.
*/
export { CrystalLightboxModule, EventService, LightboxDirective, LightboxGroupDirective, LightboxCommonComponent as ɵa, LightboxComponent as ɵb, CrystalLightbox as ɵc };
//# sourceMappingURL=crystalui-angular-lightbox.js.map