@mdrajibul/zoomify
Version:
A simple zoomify image library
1 lines • 3.8 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).window=t.window||{})}(this,function(t){"use strict";var e=function(t,a,s,c){return new(s=s||Promise)(function(n,e){function i(t){try{r(c.next(t))}catch(t){e(t)}}function o(t){try{r(c.throw(t))}catch(t){e(t)}}function r(t){var e;t.done?n(t.value):((e=t.value)instanceof s?e:new s(function(t){t(e)})).then(i,o)}r((c=c.apply(t,a||[])).next())})},o=function(n,i){var o,r,a,s={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},t={next:e(0),throw:e(1),return:e(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,r&&(a=2&e[0]?r.return:e[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,e[1])).done)return a;switch(r=0,(e=a?[2&e[0],a.value]:e)[0]){case 0:case 1:a=e;break;case 4:return s.label++,{value:e[1],done:!1};case 5:s.label++,r=e[1],e=[0];continue;case 7:e=s.ops.pop(),s.trys.pop();continue;default:if(!(a=0<(a=s.trys).length&&a[a.length-1])&&(6===e[0]||2===e[0])){s=0;continue}if(3===e[0]&&(!a||e[1]>a[0]&&e[1]<a[3])){s.label=e[1];break}if(6===e[0]&&s.label<a[1]){s.label=a[1],a=e;break}if(a&&s.label<a[2]){s.label=a[2],s.ops.push(e);break}a[2]&&s.ops.pop(),s.trys.pop();continue}e=i.call(n,s)}catch(t){e=[6,t],r=0}finally{o=a=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}},n=(r.run=function(i){var t=this;return new Promise(function(n){return e(t,void 0,void 0,function(){var e;return o(this,function(t){switch(t.label){case 0:return[4,(e=new r(i,!0)).start()];case 1:return t.sent(),n(e),[2]}})})})},r.prototype.init=function(){var e=this;return new Promise(function(t){e.imageSrc.onload=function(){e.imageWidth=e.imageSrc.naturalWidth,e.imageHeight=e.imageSrc.naturalHeight,e.ratio=e.imageHeight/e.imageWidth;var t=100*e.ratio+"%";e.container.style.paddingBottom=t,e.isLoaded=!0},e.imageSrc.src=e.imageUrl,t(e.isLoaded)})},r.prototype.start=function(){return e(this,void 0,void 0,function(){return o(this,function(t){switch(t.label){case 0:return this.isLoaded?[3,2]:[4,this.init()];case 1:t.sent(),t.label=2;case 2:return this.afterLoad(),[2]}})})},r.prototype.stop=function(){this.reset(),this.container.onmousemove=null,this.container.onmouseout=null},r.prototype.afterLoad=function(){var e=this;this.container.style.cursor="crosshair",this.container.onmousemove=function(t){return e.move(t,e.ratio,e.imageWidth)},this.autoStop&&(this.container.onmouseout=function(){return e.reset()})},r.prototype.move=function(t,e,n){var i=0<this.container.scrollLeft?this.container.scrollLeft:this.container.parentElement&&0<this.container.parentElement.scrollLeft?this.container.parentElement.scrollLeft:0,o=0<this.container.scrollTop?this.container.scrollTop:this.container.parentElement&&0<this.container.parentElement.scrollTop?this.container.parentElement.scrollTop:0,r=this.container.clientWidth,a=t.pageX-this.container.offsetLeft,t=t.pageY-this.container.offsetTop;Object.assign(this.container.style,{backgroundPosition:(a+i)/(r/100)+"%"+" "+((t+o)/(r*e/100)+"%"),backgroundSize:n+"px"})},r.prototype.reset=function(){Object.assign(this.container.style,{backgroundPosition:"top",backgroundSize:"cover",cursor:"default"})},r);function r(t,e){void 0===e&&(e=!1),this.imageUrl="",this.imageWidth=0,this.imageHeight=0,this.ratio=0,this.isLoaded=!1,this.container=t,this.autoStop=e;t=window.getComputedStyle(t);t.backgroundImage&&(this.imageUrl=t.backgroundImage.slice(4,-1).replace(/['"]/g,"")),this.imageSrc=new Image}t.Zoomify=n,Object.defineProperty(t,"__esModule",{value:!0})});