@scicom-esolutions/ng-image-viewer
Version:
[](https://www.npmjs.com/package/@haseeamarathunga/ng-image-viewer) [](https://www.npmjs.com/pac
489 lines (481 loc) • 18.7 kB
JavaScript
import { Injectable, ɵɵdefineInjectable, EventEmitter, Component, Optional, Inject, Input, Output, HostListener, NgModule } from '@angular/core';
import { __assign } from 'tslib';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
/**
* @fileoverview added by tsickle
* Generated from: lib/ng-image-viewer.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NgImageViewerService = /** @class */ (function () {
function NgImageViewerService() {
}
NgImageViewerService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
NgImageViewerService.ctorParameters = function () { return []; };
/** @nocollapse */ NgImageViewerService.ngInjectableDef = ɵɵdefineInjectable({ factory: function NgImageViewerService_Factory() { return new NgImageViewerService(); }, token: NgImageViewerService, providedIn: "root" });
return NgImageViewerService;
}());
/**
* @fileoverview added by tsickle
* Generated from: lib/model/custom-image-event-model.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var CustomImageEvent = /** @class */ (function () {
function CustomImageEvent(name, imageIndex) {
this.name = name;
this.imageIndex = imageIndex;
}
return CustomImageEvent;
}());
if (false) {
/** @type {?} */
CustomImageEvent.prototype.name;
/** @type {?} */
CustomImageEvent.prototype.imageIndex;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/ng-image-viewer.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var DEFAULT_CONFIG = {
btnClass: 'default',
zoomFactor: 0.1,
containerBackgroundColor: '#ccc',
wheelZoom: true,
allowFullscreen: true,
allowKeyboardNavigation: true,
btnShow: {
zoomIn: true,
zoomOut: true,
rotateClockwise: true,
rotateCounterClockwise: true,
},
btnIcons: {
zoomIn: 'fa fa-plus',
zoomOut: 'fa fa-minus',
rotateClockwise: 'fa fa-repeat',
rotateCounterClockwise: 'fa fa-undo',
fullscreen: 'fa fa-refresh',
}
};
var NgImageViewerComponent = /** @class */ (function () {
function NgImageViewerComponent(moduleConfig) {
this.moduleConfig = moduleConfig;
this.index = 0;
this.indexChange = new EventEmitter();
this.configChange = new EventEmitter();
this.customImageEvent = new EventEmitter();
this.style = { transform: '', msTransform: '', oTransform: '', webkitTransform: '', cursor: 'pointer' };
this.fullscreen = false;
this.loading = true;
this.scale = 1;
this.rotation = 0;
this.translateX = 0;
this.translateY = 0;
this.hovered = false;
}
/**
* @return {?}
*/
NgImageViewerComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
/** @type {?} */
var merged = this.mergeConfig(DEFAULT_CONFIG, this.moduleConfig);
this.config = this.mergeConfig(merged, this.config);
this.triggerConfigBinding();
};
/**
* @param {?} event
* @return {?}
*/
NgImageViewerComponent.prototype.nextImage = /**
* @param {?} event
* @return {?}
*/
function (event) {
if (this.canNavigate(event) && this.index < this.src.length - 1) {
this.loading = true;
this.index++;
this.triggerIndexBinding();
this.reset();
}
};
/**
* @param {?} event
* @return {?}
*/
NgImageViewerComponent.prototype.prevImage = /**
* @param {?} event
* @return {?}
*/
function (event) {
if (this.canNavigate(event) && this.index > 0) {
this.loading = true;
this.index--;
this.triggerIndexBinding();
this.reset();
}
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.zoomIn = /**
* @return {?}
*/
function () {
this.scale *= (1 + this.config.zoomFactor);
this.updateStyle();
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.zoomOut = /**
* @return {?}
*/
function () {
if (this.scale > this.config.zoomFactor) {
this.scale /= (1 + this.config.zoomFactor);
}
this.updateStyle();
};
/**
* @param {?} evt
* @return {?}
*/
NgImageViewerComponent.prototype.scrollZoom = /**
* @param {?} evt
* @return {?}
*/
function (evt) {
if (this.config.wheelZoom) {
evt.deltaY > 0 ? this.zoomOut() : this.zoomIn();
return false;
}
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.rotateClockwise = /**
* @return {?}
*/
function () {
this.rotation += 90;
this.updateStyle();
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.rotateCounterClockwise = /**
* @return {?}
*/
function () {
this.rotation -= 90;
this.updateStyle();
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.onLoad = /**
* @return {?}
*/
function () {
this.loading = false;
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.onLoadStart = /**
* @return {?}
*/
function () {
this.loading = true;
};
/**
* @param {?} evt
* @return {?}
*/
NgImageViewerComponent.prototype.onDragOver = /**
* @param {?} evt
* @return {?}
*/
function (evt) {
this.translateX += (evt.clientX - this.prevX);
this.translateY += (evt.clientY - this.prevY);
this.prevX = evt.clientX;
this.prevY = evt.clientY;
this.updateStyle();
};
/**
* @param {?} evt
* @return {?}
*/
NgImageViewerComponent.prototype.onDragStart = /**
* @param {?} evt
* @return {?}
*/
function (evt) {
this.prevX = evt.clientX;
this.prevY = evt.clientY;
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.toggleFullscreen = /**
* @return {?}
*/
function () {
// this.fullscreen = !this.fullscreen;
// if (!this.fullscreen) {
// this.reset();
// }
this.translateX = 0;
this.translateY = 0;
this.scale = 1;
this.rotation = 0;
this.translateX = 0;
this.translateY = 0;
this.zoomIn();
this.zoomOut();
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.triggerIndexBinding = /**
* @return {?}
*/
function () {
this.indexChange.emit(this.index);
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.triggerConfigBinding = /**
* @return {?}
*/
function () {
this.configChange.next(this.config);
};
/**
* @param {?} name
* @param {?} imageIndex
* @return {?}
*/
NgImageViewerComponent.prototype.fireCustomEvent = /**
* @param {?} name
* @param {?} imageIndex
* @return {?}
*/
function (name, imageIndex) {
this.customImageEvent.emit(new CustomImageEvent(name, imageIndex));
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.reset = /**
* @return {?}
*/
function () {
this.scale = 1;
this.rotation = 0;
this.translateX = 0;
this.translateY = 0;
this.updateStyle();
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.onMouseOver = /**
* @return {?}
*/
function () {
this.hovered = true;
};
/**
* @return {?}
*/
NgImageViewerComponent.prototype.onMouseLeave = /**
* @return {?}
*/
function () {
this.hovered = false;
};
/**
* @private
* @param {?} event
* @return {?}
*/
NgImageViewerComponent.prototype.canNavigate = /**
* @private
* @param {?} event
* @return {?}
*/
function (event) {
return event == null || (this.config.allowKeyboardNavigation && this.hovered);
};
/**
* @private
* @return {?}
*/
NgImageViewerComponent.prototype.updateStyle = /**
* @private
* @return {?}
*/
function () {
this.style.transform = "translate(" + this.translateX + "px, " + this.translateY + "px) rotate(" + this.rotation + "deg) scale(" + this.scale + ")";
this.style.msTransform = this.style.transform;
this.style.webkitTransform = this.style.transform;
this.style.oTransform = this.style.transform;
};
/**
* @private
* @param {?} defaultValues
* @param {?} overrideValues
* @return {?}
*/
NgImageViewerComponent.prototype.mergeConfig = /**
* @private
* @param {?} defaultValues
* @param {?} overrideValues
* @return {?}
*/
function (defaultValues, overrideValues) {
/** @type {?} */
var result = __assign({}, defaultValues);
if (overrideValues) {
result = __assign({}, defaultValues, overrideValues);
if (overrideValues.btnIcons) {
result.btnIcons = __assign({}, defaultValues.btnIcons, overrideValues.btnIcons);
}
}
return result;
};
NgImageViewerComponent.decorators = [
{ type: Component, args: [{
// tslint:disable-next-line:component-selector
selector: 'ng-image-viewer',
template: "\n <div class=\"img-container\" [style.backgroundColor]=\"config.containerBackgroundColor\"\n (wheel)=\"scrollZoom($event)\" (dragover)=\"onDragOver($event)\">\n <div [ngStyle]=\"{width: width+'px',height: height+'px'}\">\n <img [src]=\"src[index]\" [ngStyle]=\"style\" alt=\"Image not found...\" (dragstart)=\"onDragStart($event)\"\n (load)=\"onLoad()\" (loadstart)=\"onLoadStart()\" />\n <!-- Div below will be used to hide the 'ghost' image when dragging -->\n </div>\n <div></div>\n <div class=\"spinner-container\" *ngIf=\"loading\">\n <div class=\"spinner\"></div>\n </div>\n\n <button type=\"button\" [class]=\"config.btnClass\" *ngIf=\"config.btnShow.rotateCounterClockwise\"\n (click)=\"rotateCounterClockwise()\">\n <span [class]=\"config.btnIcons.rotateCounterClockwise\"></span>\n </button>\n <button type=\"button\" [class]=\"config.btnClass\" *ngIf=\"config.btnShow.rotateClockwise\" (click)=\"rotateClockwise()\">\n <span [class]=\"config.btnIcons.rotateClockwise\"></span>\n </button>\n\n <button type=\"button\" [class]=\"config.btnClass\" *ngIf=\"config.btnShow.zoomOut\" (click)=\"zoomOut()\">\n <span [class]=\"config.btnIcons.zoomOut\"></span>\n </button>\n <button type=\"button\" [class]=\"config.btnClass\" *ngIf=\"config.btnShow.zoomIn\" (click)=\"zoomIn()\">\n <span [class]=\"config.btnIcons.zoomIn\"></span>\n </button>\n\n <!-- <button type=\"button\" [class]=\"config.btnClass\" *ngFor=\"let cBtn of config.customBtns\"-->\n <!-- (click)=\"fireCustomEvent(cBtn.name, index)\">-->\n <!-- <span [class]=\"cBtn.icon\"></span>-->\n <!-- </button>-->\n\n <button type=\"button\" [class]=\"config.btnClass\" (click)=\"toggleFullscreen()\"\n *ngIf=\"config.allowFullscreen\">\n <span [class]=\"config.btnIcons.fullscreen\"></span>\n </button>\n\n <!-- <div class=\"nav-button-container\" *ngIf=\"src.length > 1\">-->\n <!-- <button type=\"button\" [class]=\"config.btnClass\" (click)=\"prevImage($event)\" [disabled]=\"index === 0\">-->\n <!-- <span [class]=\"config.btnIcons.prev\"></span>-->\n <!-- </button>-->\n <!-- <button type=\"button\" [class]=\"config.btnClass\" (click)=\"nextImage($event)\" [disabled]=\"index === src.length - 1\">-->\n <!-- <span [class]=\"config.btnIcons.next\"></span>-->\n <!-- </button>-->\n <!-- </div>-->\n </div>\n ",
styles: [".img-container{height:100%;width:100%;overflow:hidden;position:relative}.img-container img{z-index:2;margin:0 auto;display:block;max-width:100%;max-height:100%;width:100%}.img-container button{z-index:99;position:absolute;right:15px}.img-container button:not(:disabled){cursor:pointer}.img-container>button:nth-of-type(1):not(#ngx-fs-btn){bottom:15px}.img-container>button:nth-of-type(2):not(#ngx-fs-btn){bottom:65px}.img-container>button:nth-of-type(3):not(#ngx-fs-btn){bottom:115px}.img-container>button:nth-of-type(4):not(#ngx-fs-btn){bottom:165px}.img-container>button:nth-of-type(5):not(#ngx-fs-btn){bottom:215px}.img-container>button:nth-of-type(6):not(#ngx-fs-btn){bottom:265px}.img-container>button:nth-of-type(7):not(#ngx-fs-btn){bottom:315px}#ngx-fs-btn{top:15px}button.default{height:40px;width:40px;border:1px solid #555;border-radius:50%;background-color:#fff;opacity:.7;transition:opacity .2s}button.default:hover{opacity:1}button.default:disabled{opacity:.25}.nav-button-container>button{position:relative;right:0;margin:0 10px}.nav-button-container{text-align:center;position:absolute;z-index:98;bottom:10px;left:0;right:0}.spinner-container{position:absolute;left:0;right:0;top:0;bottom:0;width:60px;height:60px;margin:auto;padding:10px;background-color:rgba(0,0,0,.4);border-radius:25%}.spinner{border-width:7px;border-style:solid;border-color:#ccc #ccc #222;border-radius:50%;height:100%;width:100%;box-sizing:border-box;-webkit-animation:2s linear infinite rotation;animation:2s linear infinite rotation}@keyframes rotation{from{-webkit-transform:rotate(0)}to{-webkit-transform:rotate(359deg)}}@-webkit-keyframes rotation{from{-webkit-transform:rotate(0)}to{-webkit-transform:rotate(359deg)}}"]
}] }
];
/** @nocollapse */
NgImageViewerComponent.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: ['config',] }] }
]; };
NgImageViewerComponent.propDecorators = {
src: [{ type: Input }],
width: [{ type: Input }],
height: [{ type: Input }],
index: [{ type: Input }],
config: [{ type: Input }],
indexChange: [{ type: Output }],
configChange: [{ type: Output }],
customImageEvent: [{ type: Output }],
nextImage: [{ type: HostListener, args: ['window:keyup.ArrowRight', ['$event'],] }],
prevImage: [{ type: HostListener, args: ['window:keyup.ArrowLeft', ['$event'],] }],
onMouseOver: [{ type: HostListener, args: ['mouseover',] }],
onMouseLeave: [{ type: HostListener, args: ['mouseleave',] }]
};
return NgImageViewerComponent;
}());
if (false) {
/** @type {?} */
NgImageViewerComponent.prototype.src;
/** @type {?} */
NgImageViewerComponent.prototype.width;
/** @type {?} */
NgImageViewerComponent.prototype.height;
/** @type {?} */
NgImageViewerComponent.prototype.index;
/** @type {?} */
NgImageViewerComponent.prototype.config;
/** @type {?} */
NgImageViewerComponent.prototype.indexChange;
/** @type {?} */
NgImageViewerComponent.prototype.configChange;
/** @type {?} */
NgImageViewerComponent.prototype.customImageEvent;
/** @type {?} */
NgImageViewerComponent.prototype.style;
/** @type {?} */
NgImageViewerComponent.prototype.fullscreen;
/** @type {?} */
NgImageViewerComponent.prototype.loading;
/**
* @type {?}
* @private
*/
NgImageViewerComponent.prototype.scale;
/**
* @type {?}
* @private
*/
NgImageViewerComponent.prototype.rotation;
/**
* @type {?}
* @private
*/
NgImageViewerComponent.prototype.translateX;
/**
* @type {?}
* @private
*/
NgImageViewerComponent.prototype.translateY;
/**
* @type {?}
* @private
*/
NgImageViewerComponent.prototype.prevX;
/**
* @type {?}
* @private
*/
NgImageViewerComponent.prototype.prevY;
/**
* @type {?}
* @private
*/
NgImageViewerComponent.prototype.hovered;
/** @type {?} */
NgImageViewerComponent.prototype.moduleConfig;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/ng-image-viewer.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NgImageViewerModule = /** @class */ (function () {
function NgImageViewerModule() {
}
NgImageViewerModule.decorators = [
{ type: NgModule, args: [{
declarations: [NgImageViewerComponent],
imports: [
CommonModule,
FormsModule,
],
exports: [NgImageViewerComponent]
},] }
];
return NgImageViewerModule;
}());
/**
* @fileoverview added by tsickle
* Generated from: public-api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: scicom-esolutions-ng-image-viewer.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { NgImageViewerComponent, NgImageViewerModule, NgImageViewerService };
//# sourceMappingURL=scicom-esolutions-ng-image-viewer.js.map