UNPKG

7.01 kBJavaScriptView Raw
1/*
2Copyright (c) 2017-present NAVER Corp.
3name: @egjs/view360
4license: MIT
5author: NAVER Corp.
6repository: https://github.com/naver/egjs-view360
7version: 3.6.1
8*/
9!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@egjs/component"),require("@egjs/axes"),require("@egjs/agent")):"function"==typeof define&&define.amd?define(["@egjs/component","@egjs/axes","@egjs/agent"],e):((t="undefined"!=typeof globalThis?globalThis:t||self).eg=t.eg||{},t.eg.view360=e(t.eg.Component,t.eg.Axes,t.eg.agent))}(this,function(c,i,t){"use strict";var n="3.6.1",o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function r(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var l=function(){return(l=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function a(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,r,a=n.call(t),i=[];try{for(;(void 0===e||0<e--)&&!(o=a.next()).done;)i.push(o.value)}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}return i}(arguments[e]));return t}var e="undefined"!=typeof window&&window.Math===Math?window:"undefined"!=typeof self&&self.Math===Math?self:Function("return this")(),s=e.document,t=(e.navigator,t());t.os.name,t.browser.name;e.Float32Array=void 0!==e.Float32Array?e.Float32Array:e.Array;e.Float32Array,e.getComputedStyle,e.navigator&&e.navigator.userAgent,e.DeviceMotionEvent,e.devicePixelRatio;var g=function(){for(var t,e=null!==(t=null==s?void 0:s.documentElement.style)&&void 0!==t?t:{},n=["transform","webkitTransform","msTransform","mozTransform"],o=0,r=n.length;o<r;o++)if(n[o]in e)return n[o];return""}(),_=e.CSS&&e.CSS.supports&&e.CSS.supports("will-change","transform"),h="view360-wrapper",f="view360-image",t={__proto__:null,SPINVIEWER_OPTIONS:{imageUrl:!0,rowCount:!0,colCount:!0,width:!0,height:!0,autoHeight:!0,colRow:!0,scale:!0,frameIndex:!0,wrapperClass:!0,imageClass:!0},SPINVIEWER_EVENTS:{LOAD:"load",IMAGE_ERROR:"imageError",CHANGE:"change",ANIMATION_END:"animationEnd"},DEFAULT_WRAPPER_CLASS:h,DEFAULT_IMAGE_CLASS:f},u=function(s){function u(t,e){void 0===e&&(e={});var n=s.call(this)||this,o=e||{};n._el=t,n._rowCount=o.rowCount||1,n._colCount=o.colCount||1,n._totalCount=n._rowCount*n._colCount,n._width=o.width||"auto",n._height=o.height||"auto",n._autoHeight=null==o.autoHeight||o.autoHeight,n._colRow=[0,0],o.colRow?n._colRow=o.colRow:o.frameIndex&&n.setFrameIndex(o.frameIndex),n._el.style.width=u._getSizeString(n._width),n._el.style.height=u._getSizeString(n._height);var r=o.wrapperClass||h,e=o.imageClass||f;if(!o.imageUrl)return setTimeout(function(){n.trigger(new c.ComponentEvent("imageError",{imageUrl:o.imageUrl}))},0),n;var a=t.querySelector("."+e),i=t.querySelector("."+r);i&&a&&(a.style.display="none"),n._image=a||new Image;var l=n._image;return l.onload=function(){i&&a&&(a.style.display=""),n._bg=u._createBgDiv(i,l,n._rowCount,n._colCount,n._autoHeight),n._el.appendChild(n._bg),n.setColRow(n._colRow[0],n._colRow[1]),n.trigger(new c.ComponentEvent("load",{target:n._el,bgElement:n._bg})),n._autoPlayReservedInfo&&(n.play(n._autoPlayReservedInfo),n._autoPlayReservedInfo=null)},l.onerror=function(){n.trigger(new c.ComponentEvent("imageError",{imageUrl:o.imageUrl}))},l.src=o.imageUrl,n}r(u,s);var t=u.prototype;return u._createBgDiv=function(t,e,n,o,r){t=t||document.createElement("div");t.style.position="relative",t.style.overflow="hidden",e.style.position="absolute",e.style.width=100*o+"%",e.style.height=100*n+"%",e.ondragstart=function(){return!1},_&&(e.style.willChange="transform"),t.appendChild(e);o=e.naturalWidth/o,n=e.naturalHeight/n;return r?(o=n/o,t.style.paddingBottom=100*o+"%"):t.style.height="100%",t},u._getSizeString=function(t){return"number"==typeof t?t+"px":t},t.setFrameIndex=function(t){t=this.toColRow(t);this.setColRow(t[0],t[1])},t.getFrameIndex=function(){return this._colRow[1]*this._colCount+this._colRow[0]},t.setColRow=function(t,e){e>this._rowCount-1||t>this._colCount-1||(this._image&&g&&(this._image.style[g]="translate("+-(t/this._colCount)*100+"%, "+-(e/this._rowCount)*100+"%)"),this._colRow=[t,e])},t.getColRow=function(){return this._colRow},t.stop=function(){this._autoPlayTimer&&(clearInterval(this._autoPlayTimer),this._autoPlayTimer=-1)},t.play=function(t){var e,n,o,r=this,a=void 0===t?{interval:1e3/this._totalCount,playCount:0}:t,t=a.interval,i=a.playCount;this._bg?(this._autoPlayTimer&&(clearInterval(this._autoPlayTimer),this._autoPlayTimer=-1),e=this.getFrameIndex(),o=n=0,this._autoPlayTimer=window.setInterval(function(){e%=r._totalCount;var t=r.toColRow(e);r.setColRow(t[0],t[1]),e++,++o===r._totalCount&&(o=0,n++),0<i&&n===i&&clearInterval(r._autoPlayTimer)},t)):this._autoPlayReservedInfo={interval:t,playCount:i}},t.toColRow=function(t){var e=this._colCount,n=this._rowCount;return t<0?[0,0]:t>=this._totalCount?[e-1,n-1]:[t%e,Math.floor(t/e)]},u.VERSION=n,u}(c),e={SpinViewer:function(a){function t(t,e){void 0===e&&(e={});var n=a.call(this)||this;n._el=t;var o=l({},e),r=o.colCount||1,e=o.rowCount||1;return n._scale=o.scale||1,n._panScale=.21*n._scale,n._frameCount=r*e,n._sprites=new u(t,o).on({load:function(t){n.trigger(new c.ComponentEvent("load",t))},imageError:function(t){n.trigger(new c.ComponentEvent("imageError",{imageUrl:t.imageUrl}))}}),n._panInput=new i.PanInput(n._el,{scale:[n._panScale,n._panScale]}),n._axes=new i({angle:{range:[0,359],circular:!0}}).on({change:function(t){var e=Math.floor(t.pos.angle/(360/n._frameCount)),e=n._frameCount-e-1;n._sprites.setFrameIndex(e),n.trigger(new c.ComponentEvent("change",{frameIndex:e,colRow:n._sprites.getColRow(),angle:t.pos.angle}))},animationEnd:function(t){n.trigger(new c.ComponentEvent("animationEnd",{isTrusted:t.isTrusted}))}}),n._axes.connect("angle",n._panInput),n}r(t,a);var e=t.prototype;return e.setScale=function(t){return isNaN(t)||t<0||(this._scale=t,this._panScale=.21*t,this._panInput.options.scale=[this._panScale,this._panScale]),this},e.getScale=function(){return this._scale},e.spinBy=function(t,e){return void 0===t&&(t=0),void 0===e&&(e={duration:0}),this._axes.setBy({angle:t},e.duration),this},e.spinTo=function(t,e){return void 0===t&&(t=0),void 0===e&&(e={duration:0}),this._axes.setTo({angle:t},e.duration),this},e.getAngle=function(){return this._axes.get().angle||0},t.VERSION=n,t}(c),SpriteImage:u,VERSION:n};return function(o){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];t.forEach(function(n){Object.keys(n).forEach(function(t){var e=n[t];Array.isArray(o[t])&&Array.isArray(e)?o[t]=a(o[t],e):o[t]=e})})}(e,t),e});
10//# sourceMappingURL=view360.spinviewer.min.js.map