@lumiscaphe/viewer 4.0.2 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -13,5 +13,5 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
15
  ***************************************************************************** */
16
- function(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(t);o<s.length;o++)e.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(t,s[o])&&(i[s[o]]=t[s[o]])}return i}(t,["accessory","decor"]);return e}))}static renderParameters(t){return Object.assign(Object.assign({},t.parameters),{superSampling:t.parameters.superSampling.toString()})}static encoder(t){switch(t.encoder.format){case"jpeg":return{jpeg:{quality:t.encoder.quality}};case"png":return{png:{compression:t.encoder.compression}};case"webp":return{webp:{quality:t.encoder.quality}}}return{jpeg:{quality:80}}}static async fetchFrame(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.url))}static async fetchFrameArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.map((t=>t.url))))}static async fetchHotspots(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t))}static async fetchHotspotsArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t))}async image(t){const e={scene:m.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetchFrame(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:m.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return e.renderParameters.width=Math.max(e.renderParameters.width,e.renderParameters.height),e.renderParameters.height=Math.max(e.renderParameters.width,e.renderParameters.height),m.fetchFrameArray(`${this.server}/Snapshot`,e)}async vrObject(t){let e;e=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const i={scene:m.scene(t),mode:e,renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetchFrameArray(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:m.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetchFrameArray(`${this.server}/Snapshot`,e)}async imageHotspots(t,e){const i={scene:m.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:m.renderParameters(t),tags:e};return await m.fetchHotspots(`${this.server}/Hotspot`,i)}async vrCubeHotspots(t,e){const i={scene:m.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:m.renderParameters(t),tags:e};return i.renderParameters.width=Math.max(i.renderParameters.width,i.renderParameters.height),i.renderParameters.height=Math.max(i.renderParameters.width,i.renderParameters.height),await m.fetchHotspotsArray(`${this.server}/Hotspot`,i)}async vrObjectHotspots(t,e){let i;i=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const s={scene:m.scene(t),mode:i,renderParameters:m.renderParameters(t),tags:e};return await m.fetchHotspotsArray(`${this.server}/Hotspot`,s)}}class u{constructor(t,e,i){switch(e){case"static":this.webrender=new d;break;case"v1":default:this.webrender=new l(t);break;case"v2":this.webrender=new m(t)}this.delegate=i,this.loadingId=0,this.loaded=0,this.total=0,this.onLoadStart=i&&i.onLoadStart?i.onLoadStart:()=>{},this.onLoadProgress=i&&i.onLoadProgress?i.onLoadProgress:()=>{},this.onLoadEnd=i&&i.onLoadEnd?i.onLoadEnd:()=>{}}get progress(){return this.total?this.loaded/this.total:0}async loadImageSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.image(t).then((t=>this.loadImage(t,e))).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVideoSnapshot(t,e){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:i}=this;return this.webrender.video(e).then((s=>this.loadVideo(t,s,!!e.view.loop,i))).then((()=>(this.onLoadEnd(this.progress),t)))}async loadVRCubeSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.vrCube(t).then((t=>{this.total=t.length;const i=t.map((t=>this.loadImage(t,e)));return Promise.all(i)})).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVRObjectSnapshot(t,e){var i;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:s}=this;return t.view.animation?"mp4"===(null===(i=t.encoder)||void 0===i?void 0:i.format)?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,s))):this.webrender.animation(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s))):this.webrender.vrObject(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s)))}async loadImage(t,e){const i=new Image;i.crossOrigin="file:"!==location.protocol||u.isValidHttpUrl(t)?"anonymous":null;const s=new Promise(((s,o)=>{i.addEventListener("load",(()=>{e===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),s(i))}),{once:!0}),i.addEventListener("error",(i=>{e===this.loadingId&&o(`${i.type} : ${t}`)}),{once:!0})}));return i.src=t,s}loadImageFrames(t,e,i,s){this.total=t.length;const o=new Array(t.length),n=i||0;for(let i=0,r=t.length;i<r;i+=1){const a=Math.ceil(i/2)*(i%2==0?1:-1),h=e?c.mod(n+a,r):i;o[h]=this.loadImage(t[h],s)}return Promise.all(o).then((()=>this.onLoadEnd(this.progress))).catch((()=>{})),o}async loadVideo(t,e,i,s){t.loop=i;const o=new Promise(((i,o)=>{t.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),i())}),{once:!0}),t.addEventListener("error",(t=>{s===this.loadingId&&o(`${t.type} : ${e}`)}),{once:!0})}));return t.src=e,t.load(),o}async loadVideoFrame(t,e,i,s,o){let n=0;return new Promise(((r,a)=>{const h=()=>{if(o!==this.loadingId)return;if(n!==s)return void(n+=1);t.removeEventListener("seeked",h);const a=document.createElement("canvas");a.width=t.videoWidth,a.height=t.videoHeight;a.getContext("2d").drawImage(t,0,0);const c=new Image;c.src=a.toDataURL(),r(c),this.loaded+=1,this.onLoadProgress(this.progress),s!==i-1&&(t.currentTime+=1/e)};t.addEventListener("seeked",h),t.addEventListener("error",(t=>{o===this.loadingId&&a(t)}),{once:!0})}))}loadVideoFrames(t,e,i,s){this.total=e;const o=new Array(e),n=document.createElement("video");for(let t=0,r=e;t<r;t+=1)o[t]=this.loadVideoFrame(n,i,e,t,s);return n.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(n.currentTime=1/i/2)}),{once:!0}),n.src=t,n.load(),Promise.all(o).then((()=>this.onLoadEnd(this.progress))).catch((()=>{})),o}async loadImageHotspots(t,e){return this.webrender instanceof m?await this.webrender.imageHotspots(t,e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRCubeHotspots(t,e){return this.webrender instanceof m?await this.webrender.vrCubeHotspots(t,e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRObjectHotspots(t,e){return this.webrender instanceof m?await this.webrender.vrObjectHotspots(t,e):Promise.reject(new Error("Hotspots only available with api V2"))}onLoadStart(t){this.delegate&&this.delegate.onLoadStart(t)}onLoadProgress(t){this.delegate&&this.delegate.onLoadProgress(t)}onLoadEnd(t){this.delegate&&this.delegate.onLoadEnd(t)}static isValidHttpUrl(t){let e;try{e=new URL(t)}catch(t){return!1}return"http:"===e.protocol||"https:"===e.protocol}}class v{constructor(){this.element=document.createElement("video"),this.element.classList.add("ls-viewer-video"),this.element.style.opacity="0",this.element.setAttribute("muted",""),this.element.setAttribute("playsinline",""),this.element.setAttribute("preload","auto")}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(t,e,i,s){const o=r.fit(i,new n(t,e),s);this.element.style.top=`${o.top}px`,this.element.style.left=`${o.left}px`,this.element.style.width=`${o.width}px`,this.element.style.height=`${o.height}px`,i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height)}}class g{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i,this.hotspots=[]}destroy(){}show(){this.canvas.show(!1),this.container.classList.add("ls-viewer-container-image")}hide(){this.canvas.hide(!1),this.container.classList.remove("ls-viewer-container-image")}async goto(t){return Promise.resolve()}async load(t,e,i,s){let o=Promise.resolve();const n=JSON.stringify(t);o=n===this.snapshotHash&&this.image?o.then((()=>this.canvas.draw(this.image,s,.05))):o.then((()=>this.loader.loadImageSnapshot(t).then((t=>{this.canvas.draw(t,s,.05),this.image=t}))));const r=JSON.stringify(e);return!e.length||n===this.snapshotHash&&r===this.tagsHash||(o=o.then((()=>this.loader.loadImageHotspots(t,e).then((t=>{this.hotspots=t}))))),this.snapshotHash=n,this.tagsHash=r,o.then((()=>Promise.resolve(this.hotspots)))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){}onMouseMove(t){}onMouseUp(t){}onMouseEnter(t){}onTouchStart(t){}onTouchMove(t){}onTouchEnd(t){}onDeviceOrientation(t){}}class p{constructor(t,e,i){this.container=t,this.loader=i,this.video=e}destroy(){}show(){this.video.show(),this.container.classList.add("ls-viewer-container-video")}hide(){this.video.hide(),this.container.classList.remove("ls-viewer-container-video")}async goto(t){return Promise.resolve()}async load(t){const e=JSON.stringify(t);return e===this.hash?(this.video.element.load(),Promise.resolve([])):(this.hash=e,this.loader.loadVideoSnapshot(this.video.element,t).then((()=>Promise.resolve([]))))}snapshot(t,e){return"data:image/gif;base64,R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="}async play(){return new Promise(((t,e)=>{this.video.element.addEventListener("ended",(()=>{t()}),{once:!0});const i=this.video.element.play();i&&i.catch((()=>{e()})),this.show()}))}onMouseDown(t){}onMouseMove(t){}onMouseUp(t){}onMouseEnter(t){}onTouchStart(t){}onTouchMove(t){}onTouchEnd(t){}onDeviceOrientation(t){}}class w{constructor(t,e){this.x=t,this.y=e}clone(){return new w(this.x,this.y)}}class b{static pointFromMouseEvent(t){return new w(t.screenX,t.screenY)}static pointFromTouchEvent(t){const e=t.targetTouches[0]||t.changedTouches[0];return new w(e.screenX,e.screenY)}}class y{constructor(...t){3===t.length?(({0:this.u,1:this.v,2:this.o}=t),this.w=i.cross(this.u,this.v)):4===t.length?({0:this.u,1:this.v,2:this.w,3:this.o}=t):(this.u=[1,0,0],this.v=[0,1,0],this.w=[0,0,1],this.o=[0,0,0])}get localToGlobalMatrix(){return[...[this.u[0],this.u[1],this.u[2],0],...[this.v[0],this.v[1],this.v[2],0],...[this.w[0],this.w[1],this.w[2],0],...[this.o[0],this.o[1],this.o[2],1]]}get globalToLocalMatrix(){return s.inverse(this.localToGlobalMatrix)}}class f{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class P{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new w(0,0),this.velocity=new w(0,0),this.loop=this.loop.bind(this)}destroy(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}track(t){const e=Date.now();this.points=this.points.filter((t=>e-t.time<=100)),this.points.push(new f(t.x,t.y,e)),this.lastPoint=t}start(){if(0===this.points.length)return;const t=this.points[0],e=this.points[this.points.length-1],i=e.x-t.x,s=e.y-t.y,o=e.time-t.time;this.velocity=new w(0===o?0:i/(o/15),0===o?0:s/(o/15)),this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0),this.animationFrameId=requestAnimationFrame(this.loop)}stop(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0),this.points=[]}loop(){if(Math.abs(this.velocity.x)<1&&Math.abs(this.velocity.y)<1)return this.animationFrameId=void 0,void(this.points=[]);this.lastPoint.x+=this.velocity.x,this.lastPoint.y+=this.velocity.y,this.velocity.x*=.9,this.velocity.y*=.9,this.onMotion(this.lastPoint.clone()),this.animationFrameId=requestAnimationFrame(this.loop)}}class x{constructor(t,e,s){this.target=i.copy(t),this.eye=i.copy(e),this.up=i.copy(s)}get viewVector(){return i.subtract(this.target,this.eye)}get rightVector(){return i.normalize(i.cross(this.viewVector,this.up))}get viewMatrix(){return s.inverse(s.lookAt(this.eye,this.target,this.up))}clone(){return new x(i.copy(this.target),i.copy(this.eye),i.copy(this.up))}}x.default=new x([0,0,0],[2,2,2],[0,1,0]);class M{constructor(t,e,i){this.isStarted=!1,this.pov=t,this.fov=c.degreesToRadians(e),this.orientationMatrix=s.identity(),this.inertia=new P(this.motion.bind(this)),this.onMotion=i,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=c.degreesToRadians(window.orientation)||0,this.startPov=new x([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new w(0,0)}destroy(){this.inertia.destroy()}get orientedPov(){const t=i.normalize(i.cross(this.pov.up,this.pov.target)),e=new y(t,[0,1,0],this.pov.eye),o=s.identity();s.multiply(o,e.localToGlobalMatrix,o),s.multiply(o,this.orientationMatrix,o),s.multiply(o,e.globalToLocalMatrix,o);const n=s.transformDirection(o,this.pov.target),r=this.pov.eye,a=s.transformDirection(o,this.pov.up);return new x(n,r,a)}reset(){this.pov=this.initPov.clone(),this.fov=this.initFov}start(t,e){this.isStarted=!0,this.startPov=this.pov,this.startSize=e,this.previousPoint=t,this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t);const e={x:t.x-this.previousPoint.x,y:t.y-this.previousPoint.y},o=c.accelerate(e.x,1.3)/this.startSize.width*.2*Math.PI*1.5,n=c.accelerate(e.y,1.3)/this.startSize.height*.2*Math.PI,r=s.multiply(s.rotationY(-o),s.rotationX(-n)),a=i.normalize(i.cross(this.pov.up,this.pov.target)),h=new y(a,[0,1,0],this.pov.eye),d=s.identity();s.multiply(d,h.localToGlobalMatrix,d),s.multiply(d,r,d),s.multiply(d,h.globalToLocalMatrix,d);const l=s.transformPoint(d,this.pov.target),m=s.transformDirection(d,this.pov.up);i.cross(m,[0,0,1])[0]>=0&&(this.pov.target=l,this.pov.up=m),this.previousPoint=t,this.onMotion()}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}orientation(t,e,i){const o=c.degreesToRadians(window.orientation)||0,n=c.degreesToRadians(t),r=c.degreesToRadians(-e),a=c.degreesToRadians(-i),h=s.rotationX(c.degreesToRadians(90));s.rotateZ(h,this.initOrientation,h),s.rotateZ(h,n,h),s.rotateX(h,r,h),s.rotateY(h,a,h),s.rotateZ(h,-o,h),this.orientationMatrix=h,this.onMotion()}}class E{constructor(t,i,o,n){this.container=t,this.canvas=i,this.loader=o,this.images=[],this.hotspotsList=[[]];const r=new x([0,0,1],[0,0,0],[0,1,0]),a=s.rotationX(c.degreesToRadians(15));s.transformDirection(a,r.target,r.target),s.transformDirection(a,r.up,r.up),this.interaction=new M(r,60,(()=>{this.animationFrameId=requestAnimationFrame(this.render),this.onInteraction({pov:this.interaction.pov.clone(),fov:this.interaction.fov})})),this.onInteraction=n,this.gl=this.canvas.context,this.programInfo=e.createProgramInfo(this.gl,["attribute vec4 position;uniform mat4 u_matrix;varying vec3 direction;void main(){direction=(u_matrix*position).xyz;gl_Position=position*vec4(-1,1,1,1);}\n","precision mediump float;uniform float u_mix;uniform samplerCube u_texture;uniform samplerCube u_texture_back;varying vec3 direction;void main(){vec4 backColor=textureCube(u_texture_back,direction);vec4 color=textureCube(u_texture,direction);gl_FragColor=mix(backColor,color,u_mix);}\n"]),this.quad=e.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_matrix:s.identity(),u_mix:0,u_texture_back:e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1})},this.render=this.render.bind(this)}destroy(){this.interaction.destroy(),this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}show(){this.canvas.show(),this.container.classList.add("ls-viewer-container-vrcube")}hide(){this.canvas.hide(),this.container.classList.remove("ls-viewer-container-vrcube")}async goto(t){return Promise.resolve()}get pov(){return this.interaction.pov}set pov(t){this.interaction.pov.eye.every(((e,i)=>e===t.eye[i]))&&this.interaction.pov.target.every(((e,i)=>e===t.target[i]))&&this.interaction.pov.up.every(((e,i)=>e===t.up[i]))||(this.interaction.pov=t.clone(),this.animationFrameId=requestAnimationFrame(this.render))}get fov(){return c.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=c.degreesToRadians(t),this.animationFrameId=requestAnimationFrame(this.render))}get hotspots(){const t=[];this.hotspotsList.flat();const e=this.canvas.element.clientWidth,o=this.canvas.element.clientHeight,n=s.inverse(this.modelViewProjectionMatrix);return this.hotspotsList.forEach(((r,a)=>{r.forEach((r=>{const h=r.position2D.x/this.images[0].width,c=r.position2D.y/this.images[0].height;let d=0,l=0,m=0;switch(a){case 0:if(this.pov.target[2]<0)return;d=2*h-1,l=-1*(2*c-1),m=1;break;case 1:if(this.pov.target[0]<0)return;d=1,l=-1*(2*c-1),m=1-2*h;break;case 2:if(this.pov.target[2]>0)return;d=1-2*h,l=-1*(2*c-1),m=-1;break;case 3:if(this.pov.target[0]>0)return;d=-1,l=-1*(2*c-1),m=2*h-1;break;case 4:if(this.pov.target[1]<0)return;d=2*h-1,l=1,m=2*c-1;break;case 5:if(this.pov.target[1]>0)return;d=2*h-1,l=-1,m=-1*(2*c-1)}const u=i.normalize([d,l,m]),v=s.transformPoint(n,u),g={x:e-.5*e*(v[0]+1),y:o-.5*o*(v[1]+1)};t.push(Object.assign(Object.assign({},r),{position2D:g}))}))})),t}async load(t,i,s,o){let n=Promise.resolve();const r=JSON.stringify(t);r===this.snapshotHash?n=n.then((()=>Promise.resolve())):(this.images=[],this.animationFrameId=requestAnimationFrame(this.render),n=n.then((()=>this.loader.loadVRCubeSnapshot(t).then((t=>{this.images=t,e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,auto:!1,cubeFaceOrder:[this.gl.TEXTURE_CUBE_MAP_POSITIVE_Z,this.gl.TEXTURE_CUBE_MAP_POSITIVE_X,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_X,this.gl.TEXTURE_CUBE_MAP_POSITIVE_Y,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_Y],src:t},((t,e)=>{t||(s&&this.interaction.reset(),this.uniforms.u_mix=o?0:1,this.uniforms.u_texture_back=this.uniforms.u_texture,this.uniforms.u_texture=e,this.animationFrameId=requestAnimationFrame(this.render))}))})))));const a=JSON.stringify(i);return!i.length||r===this.snapshotHash&&a===this.tagsHash||(n=n.then((()=>this.loader.loadVRCubeHotspots(t,i).then((t=>{this.hotspotsList=t}))))),this.snapshotHash=r,this.tagsHash=a,n.then((()=>Promise.resolve(this.hotspots)))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}get modelViewProjectionMatrix(){const t=this.interaction.fov,e=this.canvas.element.clientWidth/this.canvas.element.clientHeight,i=s.inverse(s.perspective(t,e,.5,100)),o=this.interaction.orientedPov,n=s.lookAt(o.eye,o.target,o.up);return s.multiply(n,i)}render(){this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.uniforms.u_matrix=this.modelViewProjectionMatrix,this.gl.useProgram(this.programInfo.program),e.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),e.setUniforms(this.programInfo,this.uniforms),e.drawBufferInfo(this.gl,this.quad),this.uniforms.u_mix<1&&(this.uniforms.u_mix=Math.min(this.uniforms.u_mix+.05,1),this.animationFrameId=requestAnimationFrame(this.render))}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(b.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(b.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class L{constructor(t,e,i,s,o){this.isStarted=!1,this.position=t,this.frames=e,this.rows=i,this.loop=s,this.onMotion=o,this.inertia=new P(this.motion.bind(this)),this.initPosition=this.position,this.startPosition={x:0,y:0},this.startPoint=new w(0,0),this.startSize={width:0,height:0},this.lastPoints=[],this.lastPointsNumber=20}destroy(){this.inertia.destroy()}reset(){this.position=this.initPosition}get positionIndex(){return this.frames*this.position.y+this.position.x}start(t,e){this.isStarted=!0,this.startPosition=Object.assign({},this.position),this.startPoint=t,this.startSize=e,this.lastPoints=[],this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t),this.lastPoints.push({x:t.x,y:t.y}),this.lastPoints.splice(0,this.lastPoints.length-this.lastPointsNumber);const e=o.linear(this.lastPoints.map((t=>[t.x,t.y])));if(Math.abs(e.equation[0])<1){const e=c.accelerate(t.x-this.startPoint.x,1.3)/this.startSize.width*(this.frames/4);let i=this.startPosition.x-Math.round(e);i=this.loop?c.mod(i,this.frames):Math.max(0,Math.min(i,this.frames-1)),i!==this.position.x&&(this.position.x=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.x)));Math.max(...this.lastPoints.map((t=>t.x)))-s>25&&(this.startPoint.y=t.y,this.startPosition.y=this.position.y)}else{const e=c.accelerate(t.y-this.startPoint.y,1.7)/this.startSize.height*(this.rows/4);let i=this.startPosition.y+Math.round(e);i=Math.max(0,Math.min(i,this.rows-1)),i!==this.position.y&&(this.position.y=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.y)));Math.max(...this.lastPoints.map((t=>t.y)))-s>25&&(this.startPoint.x=t.x,this.startPosition.x=this.position.x)}}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}}class I{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.frames=24,this.hotspotsList=[[]],this.interaction=new L({x:0,y:0},1,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:Object.assign({},this.interaction.position)})})),this.onInteraction=s}destroy(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}show(){this.canvas.show(!1),this.container.classList.add("ls-viewer-container-vrobject")}hide(){this.canvas.hide(!1),this.container.classList.remove("ls-viewer-container-vrobject")}async goto(t){return new Promise((e=>{const i=Object.assign({},this.interaction.position),s=()=>{if(this.interaction.position.x===t.x&&this.interaction.position.y===t.y)e();else{let e=i.x>t.x?-1:1;this.interaction.loop&&this.interaction.frames-i.x+t.x<Math.abs(t.x-i.x)&&(e*=-1),i.x+=.5*e,this.position.x=Math.floor(i.x);const o=i.y>t.y?-1:1;i.y+=.5*o,this.animationFrameId=requestAnimationFrame(s)}};this.animationFrameId=requestAnimationFrame(s)}))}set initPosition(t){this.interaction.initPosition=t}get position(){return this.interaction.position}set position(t){this.interaction.position.x===t.x&&this.interaction.position.y===t.y||(this.interaction.loop?this.interaction.position.x=c.mod(t.x,this.interaction.frames):this.interaction.position.x=Math.max(0,Math.min(t.x,this.interaction.frames-1)),this.interaction.position.y=Math.max(0,Math.min(t.y,this.interaction.rows-1)),this.canvas.draw(this.image,!0,.5))}get image(){return this.images[this.interaction.positionIndex]}get hotspots(){return this.hotspotsList[this.interaction.positionIndex]||[]}async load(t,e,i,s){let o=Promise.resolve();i&&this.interaction.reset();const n=JSON.stringify(t);n===this.snapshotHash&&this.image?o=o.then((()=>this.canvas.draw(this.image,s,.05))):(this.images=[],o=o.then((()=>this.loader.loadVRObjectSnapshot(t,this.interaction.positionIndex).then((e=>{const o=e.length;return this.images=new Array(o),this.interaction.frames=t.view.frames||this.frames,this.interaction.rows=o/this.interaction.frames,this.interaction.loop=!!t.view.loop,i&&this.interaction.reset(),e.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,s,.05)})).catch((()=>{}))})),e[this.interaction.positionIndex].then((()=>Promise.resolve()))})))));const r=JSON.stringify(e);return!e.length||n===this.snapshotHash&&r===this.tagsHash||(o=o.then((()=>this.loader.loadVRObjectHotspots(t,e).then((t=>{this.hotspotsList=t}))))),this.snapshotHash=n,this.tagsHash=r,o.then((()=>Promise.resolve(this.hotspots)))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(b.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(b.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}var S;!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===i&&s.firstChild?s.insertBefore(o,s.firstChild):s.appendChild(o),o.styleSheet?o.styleSheet.cssText=t:o.appendChild(document.createTextNode(t))}}(".ls-viewer-container{-webkit-box-flex:1;display:-webkit-box;display:-ms-flexbox;display:flex;-ms-flex:1 0 auto;flex:1 0 auto;overflow:hidden;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.ls-viewer-container-image,.ls-viewer-container-video{cursor:default;pointer-events:none}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{opacity:0;position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");class A{constructor(e,i){this.checkResize=this.checkResize.bind(this),this.onDeviceOrientation=this.onDeviceOrientation.bind(this),this.onResize=this.onResize.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onMouseEnter=this.onMouseEnter.bind(this),this.onTouchStart=this.onTouchStart.bind(this),this.onTouchMove=this.onTouchMove.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this),this.onLoadStart=this.onLoadStart.bind(this),this.onLoadProgress=this.onLoadProgress.bind(this),this.onLoadEnd=this.onLoadEnd.bind(this),this.onLoadError=this.onLoadError.bind(this),this.onHotspotsChange=this.onHotspotsChange.bind(this),this.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options=Object.assign({server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{}},i),this.options.events=Object.assign({onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{},onHotspotsChange:()=>{}},i.events),this.options.events.onLoadError=t(this.options.events.onLoadError,10),this.container=e,this.container.classList.add("ls-viewer-container"),this.containerWidth=0,this.containerHeight=0,this.canvas2D=new a(this.options.fit),this.container.appendChild(this.canvas2D.element),this.canvas3D=new h,this.container.appendChild(this.canvas3D.element),this.video=new v,this.container.appendChild(this.video.element),this.loader=new u(this.options.server,this.options.api,this),this.resolution=new n(0,0),this.parameters={width:0,height:0,antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.widgetImage=new g(e,this.canvas2D,this.loader),this.widgetVideo=new p(e,this.video,this.loader),this.widgetVRCube=new E(e,this.canvas3D,this.loader,this.onVrcubeInteraction),this.widgetVRObject=new I(e,this.canvas2D,this.loader,this.onVrobjectInteraction),this.widget=this.widgetImage,this.isDestroyed=!1,this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mouseenter",this.onMouseEnter),this.container.addEventListener("touchstart",this.onTouchStart),document.addEventListener("mousemove",this.onMouseMove,{passive:!1}),document.addEventListener("mouseup",this.onMouseUp),document.addEventListener("touchmove",this.onTouchMove,{passive:!1}),document.addEventListener("touchend",this.onTouchEnd),this.checkResize(),this.loadWidget=t(this.loadWidget,10),this.onResize=t(this.onResize,250)}destroy(){this.canvas2D.destroy(),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mouseenter",this.onMouseEnter),this.container.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd),this.isDestroyed=!0}async load(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(this.view.mode,i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>(this.scene=Array.isArray(t)?[...t]:[t],this.loadWidget(!1,!(e&&e.animation))))),i.catch((t=>{this.onLoadError(t)})),i}async setEncoder(t){this.encoder=Object.assign({},t);let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setParameters(t){this.parameters=Object.assign({},t),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height;let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setTags(t){this.tags=t,this.loadWidget(!1,!1)}async setView(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>{let i=!0;return this.view=Object.assign({},t),this.view&&this.viewWidget instanceof I&&void 0!==(null==e?void 0:e.toPosition)&&(i=!1,this.viewWidget.position=Object.assign({},e.toPosition)),this.loadWidget(i,!(e&&e.animation))})),i.catch((t=>{this.onLoadError(t)})),i}setVrcube(t){Object.assign(this.widgetVRCube,t)}setVrobject(t){Object.assign(this.widgetVRObject,t)}async loadAnimation(t){var e;const i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return(null===(e=i.view)||void 0===e?void 0:e.background)||(i.view.background="product"),this.widgetVideo.load(i).then((()=>Promise.resolve()))}async playAnimation(t){return this.loadAnimation(t).then((()=>this.widgetVideo.play())).catch((t=>{this.onLoadError(t)}))}stopAnimation(){this.widgetVideo.hide()}snapshot(t,e){return this.viewWidget.snapshot(t,e)}async loadWidget(t,e){if(!this.scene||!this.view)return Promise.resolve();if(!this.parameters.width||!this.parameters.height)return Promise.resolve();const i=this.viewWidget;if(!i)return Promise.reject(new Error("Unknown view mode"));const s={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return s.view.background||(s.view.background="product"),i.load(s,this.tags||[],t,e).then((t=>{this.widget.hide(),this.widget=i,this.widget.show(),this.widgetVideo.hide(),this.onHotspotsChange(t)}))}get viewWidget(){var t;switch(null===(t=this.view)||void 0===t?void 0:t.mode){case"image":default:return this.widgetImage;case"video":return this.widgetVideo;case"vrcube":return this.widgetVRCube;case"vrobject":return this.widgetVRObject}}checkResize(){if(this.isDestroyed)return;const t=this.container.clientWidth,e=this.container.clientHeight;t===this.containerWidth&&e===this.containerHeight||(this.containerWidth=t,this.containerHeight=e,this.onResize()),this.isDestroyed||requestAnimationFrame(this.checkResize)}onMouseDown(t){this.widget.onMouseDown(t)}onMouseEnter(t){this.widget.onMouseEnter(t)}onMouseMove(t){this.widget.onMouseMove(t)}onMouseUp(t){this.widget.onMouseUp(t)}onTouchStart(t){this.widget.onTouchStart(t)}onTouchMove(t){this.widget.onTouchMove(t)}onTouchEnd(t){this.widget.onTouchEnd(t)}onDeviceOrientation(t){this.widget.onDeviceOrientation(t)}onResize(){const t=window.devicePixelRatio,e=this.container.clientWidth*t,i=this.container.clientHeight*t;this.resolution=r.getStandardResolution(e,i),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height,this.canvas2D.resize(e/t,i/t),this.canvas3D.resize(e/t,i/t),this.video.resize(e/t,i/t,this.resolution,this.options.fit),this.loadWidget(!1,!1).catch((t=>{this.onLoadError(t)}))}onVrcubeInteraction(...t){this.options.events.onHotspotsChange(this.widgetVRCube.hotspots),this.options.events.onInteraction(...t),this.options.events.onVrcubeInteraction(...t)}onVrobjectInteraction(...t){this.options.events.onHotspotsChange(this.widgetVRObject.hotspots),this.options.events.onInteraction(...t),this.options.events.onVrobjectInteraction(...t)}onHotspotsChange(...t){this.options.events.onHotspotsChange(...t)}onLoadStart(...t){this.container.classList.add("ls-viewer-container-loading"),this.options.events.onLoadStart(...t)}onLoadProgress(...t){this.options.events.onLoadProgress(...t)}onLoadEnd(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadEnd(...t)}onLoadError(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadError(...t)}}!function(t){var e,i,s;(e=t.SunShadowQualityMode||(t.SunShadowQualityMode={})).VeryLow="veryLow",e.Low="low",e.Medium="medium",e.Fine="fine",e.Ultra="ultra",(i=t.SunShadowSmoothnessMode||(t.SunShadowSmoothnessMode={})).None="none",i.Weak="weak",i.Normal="normal",i.Fine="fine",i.UltraFine="ultraFine",i.Max="max",(s=t.SunUseCaseMode||(t.SunUseCaseMode={})).Manual="manual",s.ExtractedFromEnv="extractedFromEnv"}(S||(S={}));export{A as Viewer,S as WRAPIv2,g as WidgetImage,E as WidgetVRCube,I as WidgetVRObject,p as WidgetVideo};
16
+ function(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(t);o<s.length;o++)e.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(t,s[o])&&(i[s[o]]=t[s[o]])}return i}(t,["accessory","decor"]);return e}))}static renderParameters(t){return Object.assign(Object.assign({},t.parameters),{superSampling:t.parameters.superSampling.toString()})}static encoder(t){switch(t.encoder.format){case"jpeg":return{jpeg:{quality:t.encoder.quality}};case"png":return{png:{compression:t.encoder.compression}};case"webp":return{webp:{quality:t.encoder.quality}}}return{jpeg:{quality:80}}}static async fetchFrame(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.url))}static async fetchFrameArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.map((t=>t.url))))}static async fetchHotspots(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t))}static async fetchHotspotsArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t))}async image(t){const e={scene:m.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetchFrame(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:m.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return e.renderParameters.width=Math.max(e.renderParameters.width,e.renderParameters.height),e.renderParameters.height=Math.max(e.renderParameters.width,e.renderParameters.height),m.fetchFrameArray(`${this.server}/Snapshot`,e)}async vrObject(t){let e;e=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const i={scene:m.scene(t),mode:e,renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetchFrameArray(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:m.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetchFrameArray(`${this.server}/Snapshot`,e)}async imageHotspots(t,e){const i={scene:m.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:m.renderParameters(t),tags:e};return await m.fetchHotspots(`${this.server}/Hotspot`,i)}async vrCubeHotspots(t,e){const i={scene:m.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:m.renderParameters(t),tags:e};return i.renderParameters.width=Math.max(i.renderParameters.width,i.renderParameters.height),i.renderParameters.height=Math.max(i.renderParameters.width,i.renderParameters.height),await m.fetchHotspotsArray(`${this.server}/Hotspot`,i)}async vrObjectHotspots(t,e){let i;i=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const s={scene:m.scene(t),mode:i,renderParameters:m.renderParameters(t),tags:e};return await m.fetchHotspotsArray(`${this.server}/Hotspot`,s)}}class u{constructor(t,e,i){switch(e){case"static":this.webrender=new d;break;case"v1":default:this.webrender=new l(t);break;case"v2":this.webrender=new m(t)}this.delegate=i,this.loadingId=0,this.loaded=0,this.total=0,this.onLoadStart=i&&i.onLoadStart?i.onLoadStart:()=>{},this.onLoadProgress=i&&i.onLoadProgress?i.onLoadProgress:()=>{},this.onLoadEnd=i&&i.onLoadEnd?i.onLoadEnd:()=>{}}get progress(){return this.total?this.loaded/this.total:0}async loadImageSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.image(t).then((t=>this.loadImage(t,e))).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVideoSnapshot(t,e){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:i}=this;return this.webrender.video(e).then((s=>this.loadVideo(t,s,!!e.view.loop,i))).then((()=>(this.onLoadEnd(this.progress),t)))}async loadVRCubeSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.vrCube(t).then((t=>{this.total=t.length;const i=t.map((t=>this.loadImage(t,e)));return Promise.all(i)})).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVRObjectSnapshot(t,e){var i;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:s}=this;return t.view.animation?"mp4"===(null===(i=t.encoder)||void 0===i?void 0:i.format)?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,s))):this.webrender.animation(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s))):this.webrender.vrObject(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s)))}async loadImage(t,e){const i=new Image;i.crossOrigin="file:"!==location.protocol||u.isValidHttpUrl(t)?"anonymous":null;const s=new Promise(((s,o)=>{i.addEventListener("load",(()=>{e===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),s(i))}),{once:!0}),i.addEventListener("error",(i=>{e===this.loadingId&&o(`${i.type} : ${t}`)}),{once:!0})}));return i.src=t,s}loadImageFrames(t,e,i,s){this.total=t.length;const o=new Array(t.length),n=i||0;for(let i=0,r=t.length;i<r;i+=1){const a=Math.ceil(i/2)*(i%2==0?1:-1),h=e?c.mod(n+a,r):i;o[h]=this.loadImage(t[h],s)}return Promise.all(o).then((()=>this.onLoadEnd(this.progress))).catch((()=>{})),o}async loadVideo(t,e,i,s){t.loop=i;const o=new Promise(((i,o)=>{t.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),i())}),{once:!0}),t.addEventListener("error",(t=>{s===this.loadingId&&o(`${t.type} : ${e}`)}),{once:!0})}));return t.src=e,t.load(),o}async loadVideoFrame(t,e,i,s,o){let n=0;return new Promise(((r,a)=>{const h=()=>{if(o!==this.loadingId)return;if(n!==s)return void(n+=1);t.removeEventListener("seeked",h);const a=document.createElement("canvas");a.width=t.videoWidth,a.height=t.videoHeight;a.getContext("2d").drawImage(t,0,0);const c=new Image;c.src=a.toDataURL(),r(c),this.loaded+=1,this.onLoadProgress(this.progress),s!==i-1&&(t.currentTime+=1/e)};t.addEventListener("seeked",h),t.addEventListener("error",(t=>{o===this.loadingId&&a(t)}),{once:!0})}))}loadVideoFrames(t,e,i,s){this.total=e;const o=new Array(e),n=document.createElement("video");for(let t=0,r=e;t<r;t+=1)o[t]=this.loadVideoFrame(n,i,e,t,s);return n.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(n.currentTime=1/i/2)}),{once:!0}),n.src=t,n.load(),Promise.all(o).then((()=>this.onLoadEnd(this.progress))).catch((()=>{})),o}async loadImageHotspots(t,e){return this.webrender instanceof m?await this.webrender.imageHotspots(t,e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRCubeHotspots(t,e){return this.webrender instanceof m?await this.webrender.vrCubeHotspots(t,e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRObjectHotspots(t,e){return this.webrender instanceof m?await this.webrender.vrObjectHotspots(t,e):Promise.reject(new Error("Hotspots only available with api V2"))}onLoadStart(t){this.delegate&&this.delegate.onLoadStart(t)}onLoadProgress(t){this.delegate&&this.delegate.onLoadProgress(t)}onLoadEnd(t){this.delegate&&this.delegate.onLoadEnd(t)}static isValidHttpUrl(t){let e;try{e=new URL(t)}catch(t){return!1}return"http:"===e.protocol||"https:"===e.protocol}}class v{constructor(){this.element=document.createElement("video"),this.element.classList.add("ls-viewer-video"),this.element.style.opacity="0",this.element.setAttribute("muted",""),this.element.setAttribute("playsinline",""),this.element.setAttribute("preload","auto")}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(t,e,i,s){const o=r.fit(i,new n(t,e),s);this.element.style.top=`${o.top}px`,this.element.style.left=`${o.left}px`,this.element.style.width=`${o.width}px`,this.element.style.height=`${o.height}px`,i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height)}}class g{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i,this.hotspots=[]}destroy(){}show(){this.canvas.show(!1),this.container.classList.add("ls-viewer-container-image")}hide(){this.canvas.hide(!1),this.container.classList.remove("ls-viewer-container-image")}async goto(t){return Promise.resolve()}async load(t,e,i,s){let o=Promise.resolve();const n=JSON.stringify(t);o=n===this.snapshotHash&&this.image?o.then((()=>this.canvas.draw(this.image,s,.05))):o.then((()=>this.loader.loadImageSnapshot(t).then((t=>{this.canvas.draw(t,s,.05),this.image=t}))));const r=JSON.stringify(e);return!e.length||n===this.snapshotHash&&r===this.tagsHash||(o=o.then((()=>this.loader.loadImageHotspots(t,e).then((t=>{this.hotspots=t}))))),this.snapshotHash=n,this.tagsHash=r,o.then((()=>Promise.resolve(this.hotspots)))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){}onMouseMove(t){}onMouseUp(t){}onMouseEnter(t){}onTouchStart(t){}onTouchMove(t){}onTouchEnd(t){}onDeviceOrientation(t){}}class p{constructor(t,e,i){this.container=t,this.loader=i,this.video=e}destroy(){}show(){this.video.show(),this.container.classList.add("ls-viewer-container-video")}hide(){this.video.hide(),this.container.classList.remove("ls-viewer-container-video")}async goto(t){return Promise.resolve()}async load(t){const e=JSON.stringify(t);return e===this.hash?(this.video.element.load(),Promise.resolve([])):(this.hash=e,this.loader.loadVideoSnapshot(this.video.element,t).then((()=>Promise.resolve([]))))}snapshot(t,e){return"data:image/gif;base64,R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="}async play(){return new Promise(((t,e)=>{this.video.element.addEventListener("ended",(()=>{t()}),{once:!0});const i=this.video.element.play();i&&i.catch((()=>{e()})),this.show()}))}onMouseDown(t){}onMouseMove(t){}onMouseUp(t){}onMouseEnter(t){}onTouchStart(t){}onTouchMove(t){}onTouchEnd(t){}onDeviceOrientation(t){}}class w{constructor(t,e){this.x=t,this.y=e}clone(){return new w(this.x,this.y)}}class b{static pointFromMouseEvent(t){return new w(t.screenX,t.screenY)}static pointFromTouchEvent(t){const e=t.targetTouches[0]||t.changedTouches[0];return new w(e.screenX,e.screenY)}}class y{constructor(...t){3===t.length?(({0:this.u,1:this.v,2:this.o}=t),this.w=i.cross(this.u,this.v)):4===t.length?({0:this.u,1:this.v,2:this.w,3:this.o}=t):(this.u=[1,0,0],this.v=[0,1,0],this.w=[0,0,1],this.o=[0,0,0])}get localToGlobalMatrix(){return[...[this.u[0],this.u[1],this.u[2],0],...[this.v[0],this.v[1],this.v[2],0],...[this.w[0],this.w[1],this.w[2],0],...[this.o[0],this.o[1],this.o[2],1]]}get globalToLocalMatrix(){return s.inverse(this.localToGlobalMatrix)}}class f{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class P{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new w(0,0),this.velocity=new w(0,0),this.loop=this.loop.bind(this)}destroy(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}track(t){const e=Date.now();this.points=this.points.filter((t=>e-t.time<=100)),this.points.push(new f(t.x,t.y,e)),this.lastPoint=t}start(){if(0===this.points.length)return;const t=this.points[0],e=this.points[this.points.length-1],i=e.x-t.x,s=e.y-t.y,o=e.time-t.time;this.velocity=new w(0===o?0:i/(o/15),0===o?0:s/(o/15)),this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0),this.animationFrameId=requestAnimationFrame(this.loop)}stop(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0),this.points=[]}loop(){if(Math.abs(this.velocity.x)<1&&Math.abs(this.velocity.y)<1)return this.animationFrameId=void 0,void(this.points=[]);this.lastPoint.x+=this.velocity.x,this.lastPoint.y+=this.velocity.y,this.velocity.x*=.9,this.velocity.y*=.9,this.onMotion(this.lastPoint.clone()),this.animationFrameId=requestAnimationFrame(this.loop)}}class M{constructor(t,e,s){this.target=i.copy(t),this.eye=i.copy(e),this.up=i.copy(s)}get viewVector(){return i.subtract(this.target,this.eye)}get rightVector(){return i.normalize(i.cross(this.viewVector,this.up))}get viewMatrix(){return s.inverse(s.lookAt(this.eye,this.target,this.up))}clone(){return new M(i.copy(this.target),i.copy(this.eye),i.copy(this.up))}}M.default=new M([0,0,0],[2,2,2],[0,1,0]);class x{constructor(t,e,i){this.isStarted=!1,this.pov=t,this.fov=c.degreesToRadians(e),this.orientationMatrix=s.identity(),this.inertia=new P(this.motion.bind(this)),this.onMotion=i,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=c.degreesToRadians(window.orientation)||0,this.startPov=new M([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new w(0,0)}destroy(){this.inertia.destroy()}get orientedPov(){const t=i.normalize(i.cross(this.pov.up,this.pov.target)),e=new y(t,[0,1,0],this.pov.eye),o=s.identity();s.multiply(o,e.localToGlobalMatrix,o),s.multiply(o,this.orientationMatrix,o),s.multiply(o,e.globalToLocalMatrix,o);const n=s.transformDirection(o,this.pov.target),r=this.pov.eye,a=s.transformDirection(o,this.pov.up);return new M(n,r,a)}reset(){this.pov=this.initPov.clone(),this.fov=this.initFov}start(t,e){this.isStarted=!0,this.startPov=this.pov,this.startSize=e,this.previousPoint=t,this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t);const e={x:t.x-this.previousPoint.x,y:t.y-this.previousPoint.y},o=c.accelerate(e.x,1.3)/this.startSize.width*.2*Math.PI*1.5,n=c.accelerate(e.y,1.3)/this.startSize.height*.2*Math.PI,r=s.multiply(s.rotationY(-o),s.rotationX(-n)),a=i.normalize(i.cross(this.pov.up,this.pov.target)),h=new y(a,[0,1,0],this.pov.eye),d=s.identity();s.multiply(d,h.localToGlobalMatrix,d),s.multiply(d,r,d),s.multiply(d,h.globalToLocalMatrix,d);const l=s.transformPoint(d,this.pov.target),m=s.transformDirection(d,this.pov.up);i.cross(m,[0,0,1])[0]>=0&&(this.pov.target=l,this.pov.up=m),this.previousPoint=t,this.onMotion()}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}orientation(t,e,i){const o=c.degreesToRadians(window.orientation)||0,n=c.degreesToRadians(t),r=c.degreesToRadians(-e),a=c.degreesToRadians(-i),h=s.rotationX(c.degreesToRadians(90));s.rotateZ(h,this.initOrientation,h),s.rotateZ(h,n,h),s.rotateX(h,r,h),s.rotateY(h,a,h),s.rotateZ(h,-o,h),this.orientationMatrix=h,this.onMotion()}}class E{constructor(t,i,o,n){this.container=t,this.canvas=i,this.loader=o,this.images=[],this.hotspotsList=[[]];const r=new M([0,0,1],[0,0,0],[0,1,0]),a=s.rotationX(c.degreesToRadians(15));s.transformDirection(a,r.target,r.target),s.transformDirection(a,r.up,r.up),this.interaction=new x(r,60,(()=>{this.animationFrameId=requestAnimationFrame(this.render),this.onInteraction({pov:this.interaction.pov.clone(),fov:this.interaction.fov})})),this.onInteraction=n,this.gl=this.canvas.context,this.programInfo=e.createProgramInfo(this.gl,["attribute vec4 position;uniform mat4 u_matrix;varying vec3 direction;void main(){direction=(u_matrix*position).xyz;gl_Position=position*vec4(-1,1,1,1);}\n","precision mediump float;uniform float u_mix;uniform samplerCube u_texture;uniform samplerCube u_texture_back;varying vec3 direction;void main(){vec4 backColor=textureCube(u_texture_back,direction);vec4 color=textureCube(u_texture,direction);gl_FragColor=mix(backColor,color,u_mix);}\n"]),this.quad=e.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_matrix:s.identity(),u_mix:0,u_texture_back:e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1})},this.render=this.render.bind(this)}destroy(){this.interaction.destroy(),this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}show(){this.canvas.show(),this.container.classList.add("ls-viewer-container-vrcube")}hide(){this.canvas.hide(),this.container.classList.remove("ls-viewer-container-vrcube")}async goto(t){return Promise.resolve()}get pov(){return this.interaction.pov}set pov(t){this.interaction.pov.eye.every(((e,i)=>e===t.eye[i]))&&this.interaction.pov.target.every(((e,i)=>e===t.target[i]))&&this.interaction.pov.up.every(((e,i)=>e===t.up[i]))||(this.interaction.pov=t.clone(),this.animationFrameId=requestAnimationFrame(this.render))}get fov(){return c.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=c.degreesToRadians(t),this.animationFrameId=requestAnimationFrame(this.render))}get hotspots(){const t=[];this.hotspotsList.flat();const e=this.canvas.element.clientWidth,o=this.canvas.element.clientHeight,n=s.inverse(this.modelViewProjectionMatrix);return this.hotspotsList.forEach(((r,a)=>{r.forEach((r=>{const h=r.position2D.x/this.images[0].width,c=r.position2D.y/this.images[0].height;let d=0,l=0,m=0;switch(a){case 0:if(this.pov.target[2]<0)return;d=2*h-1,l=-1*(2*c-1),m=1;break;case 1:if(this.pov.target[0]<0)return;d=1,l=-1*(2*c-1),m=1-2*h;break;case 2:if(this.pov.target[2]>0)return;d=1-2*h,l=-1*(2*c-1),m=-1;break;case 3:if(this.pov.target[0]>0)return;d=-1,l=-1*(2*c-1),m=2*h-1;break;case 4:if(this.pov.target[1]<0)return;d=2*h-1,l=1,m=2*c-1;break;case 5:if(this.pov.target[1]>0)return;d=2*h-1,l=-1,m=-1*(2*c-1)}const u=i.normalize([d,l,m]),v=s.transformPoint(n,u),g={x:e-.5*e*(v[0]+1),y:o-.5*o*(v[1]+1)};t.push(Object.assign(Object.assign({},r),{position2D:g}))}))})),t}async load(t,i,s,o){let n=Promise.resolve();const r=JSON.stringify(t);r===this.snapshotHash?n=n.then((()=>Promise.resolve())):(this.images=[],this.animationFrameId=requestAnimationFrame(this.render),n=n.then((()=>this.loader.loadVRCubeSnapshot(t).then((t=>{this.images=t,e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,auto:!1,cubeFaceOrder:[this.gl.TEXTURE_CUBE_MAP_POSITIVE_Z,this.gl.TEXTURE_CUBE_MAP_POSITIVE_X,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_X,this.gl.TEXTURE_CUBE_MAP_POSITIVE_Y,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_Y],src:t},((t,e)=>{t||(s&&this.interaction.reset(),this.uniforms.u_mix=o?0:1,this.uniforms.u_texture_back=this.uniforms.u_texture,this.uniforms.u_texture=e,this.animationFrameId=requestAnimationFrame(this.render))}))})))));const a=JSON.stringify(i);return!i.length||r===this.snapshotHash&&a===this.tagsHash||(n=n.then((()=>this.loader.loadVRCubeHotspots(t,i).then((t=>{this.hotspotsList=t}))))),this.snapshotHash=r,this.tagsHash=a,n.then((()=>Promise.resolve(this.hotspots)))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}get modelViewProjectionMatrix(){const t=this.interaction.fov,e=this.canvas.element.clientWidth/this.canvas.element.clientHeight,i=s.inverse(s.perspective(t,e,.5,100)),o=this.interaction.orientedPov,n=s.lookAt(o.eye,o.target,o.up);return s.multiply(n,i)}render(){this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.uniforms.u_matrix=this.modelViewProjectionMatrix,this.gl.useProgram(this.programInfo.program),e.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),e.setUniforms(this.programInfo,this.uniforms),e.drawBufferInfo(this.gl,this.quad),this.uniforms.u_mix<1&&(this.uniforms.u_mix=Math.min(this.uniforms.u_mix+.05,1),this.animationFrameId=requestAnimationFrame(this.render))}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(b.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(b.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class L{constructor(t,e,i,s,o){this.isStarted=!1,this.position=t,this.frames=e,this.rows=i,this.loop=s,this.onMotion=o,this.inertia=new P(this.motion.bind(this)),this.initPosition=this.position,this.startPosition={x:0,y:0},this.startPoint=new w(0,0),this.startSize={width:0,height:0},this.lastPoints=[],this.lastPointsNumber=20}destroy(){this.inertia.destroy()}reset(){this.position=this.initPosition}get positionIndex(){return this.frames*this.position.y+this.position.x}start(t,e){this.isStarted=!0,this.startPosition=Object.assign({},this.position),this.startPoint=t,this.startSize=e,this.lastPoints=[],this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t),this.lastPoints.push({x:t.x,y:t.y}),this.lastPoints.splice(0,this.lastPoints.length-this.lastPointsNumber);const e=o.linear(this.lastPoints.map((t=>[t.x,t.y])));if(Math.abs(e.equation[0])<1){const e=c.accelerate(t.x-this.startPoint.x,1.3)/this.startSize.width*(this.frames/4);let i=this.startPosition.x-Math.round(e);i=this.loop?c.mod(i,this.frames):Math.max(0,Math.min(i,this.frames-1)),i!==this.position.x&&(this.position.x=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.x)));Math.max(...this.lastPoints.map((t=>t.x)))-s>25&&(this.startPoint.y=t.y,this.startPosition.y=this.position.y)}else{const e=c.accelerate(t.y-this.startPoint.y,1.7)/this.startSize.height*(this.rows/4);let i=this.startPosition.y+Math.round(e);i=Math.max(0,Math.min(i,this.rows-1)),i!==this.position.y&&(this.position.y=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.y)));Math.max(...this.lastPoints.map((t=>t.y)))-s>25&&(this.startPoint.x=t.x,this.startPosition.x=this.position.x)}}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}}class I{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.frames=24,this.hotspotsList=[[]],this.interaction=new L({x:0,y:0},1,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:Object.assign({},this.interaction.position)})})),this.onInteraction=s}destroy(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}show(){this.canvas.show(!1),this.container.classList.add("ls-viewer-container-vrobject")}hide(){this.canvas.hide(!1),this.container.classList.remove("ls-viewer-container-vrobject")}async goto(t){return new Promise((e=>{const i=Object.assign({},this.interaction.position),s=()=>{if(this.interaction.position.x===t.x&&this.interaction.position.y===t.y)e();else{let e=i.x>t.x?-1:1;this.interaction.loop&&this.interaction.frames-i.x+t.x<Math.abs(t.x-i.x)&&(e*=-1),i.x+=.5*e,this.position.x=Math.floor(i.x);const o=i.y>t.y?-1:1;i.y+=.5*o,this.animationFrameId=requestAnimationFrame(s)}};this.animationFrameId=requestAnimationFrame(s)}))}set initPosition(t){this.interaction.initPosition=t}get position(){return this.interaction.position}set position(t){this.interaction.position.x===t.x&&this.interaction.position.y===t.y||(this.interaction.loop?this.interaction.position.x=c.mod(t.x,this.interaction.frames):this.interaction.position.x=Math.max(0,Math.min(t.x,this.interaction.frames-1)),this.interaction.position.y=Math.max(0,Math.min(t.y,this.interaction.rows-1)),this.canvas.draw(this.image,!0,.5))}get image(){return this.images[this.interaction.positionIndex]}get hotspots(){return this.hotspotsList[this.interaction.positionIndex]||[]}async load(t,e,i,s){let o=Promise.resolve();i&&this.interaction.reset();const n=JSON.stringify(t);n===this.snapshotHash&&this.image?o=o.then((()=>this.canvas.draw(this.image,s,.05))):(this.images=[],o=o.then((()=>this.loader.loadVRObjectSnapshot(t,this.interaction.positionIndex).then((e=>{const o=e.length;return this.images=new Array(o),this.interaction.frames=t.view.frames||this.frames,this.interaction.rows=o/this.interaction.frames,this.interaction.loop=!!t.view.loop,i&&this.interaction.reset(),e.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,s,.05)})).catch((()=>{}))})),e[this.interaction.positionIndex].then((()=>Promise.resolve()))})))));const r=JSON.stringify(e);return!e.length||n===this.snapshotHash&&r===this.tagsHash||(o=o.then((()=>this.loader.loadVRObjectHotspots(t,e).then((t=>{this.hotspotsList=t}))))),this.snapshotHash=n,this.tagsHash=r,o.then((()=>Promise.resolve(this.hotspots)))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(b.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(b.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}var S;!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===i&&s.firstChild?s.insertBefore(o,s.firstChild):s.appendChild(o),o.styleSheet?o.styleSheet.cssText=t:o.appendChild(document.createTextNode(t))}}(".ls-viewer-container{display:block;height:100%;overflow:hidden;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:100%}.ls-viewer-container-image,.ls-viewer-container-video{cursor:default;pointer-events:none}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{opacity:0;position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");class A{constructor(e,i){this.checkResize=this.checkResize.bind(this),this.onDeviceOrientation=this.onDeviceOrientation.bind(this),this.onResize=this.onResize.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onMouseEnter=this.onMouseEnter.bind(this),this.onTouchStart=this.onTouchStart.bind(this),this.onTouchMove=this.onTouchMove.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this),this.onLoadStart=this.onLoadStart.bind(this),this.onLoadProgress=this.onLoadProgress.bind(this),this.onLoadEnd=this.onLoadEnd.bind(this),this.onLoadError=this.onLoadError.bind(this),this.onHotspotsChange=this.onHotspotsChange.bind(this),this.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options=Object.assign({server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{}},i),this.options.events=Object.assign({onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{},onHotspotsChange:()=>{}},i.events),this.options.events.onLoadError=t(this.options.events.onLoadError,10),this.container=e,this.container.classList.add("ls-viewer-container"),this.containerWidth=0,this.containerHeight=0,this.canvas2D=new a(this.options.fit),this.container.appendChild(this.canvas2D.element),this.canvas3D=new h,this.container.appendChild(this.canvas3D.element),this.video=new v,this.container.appendChild(this.video.element),this.loader=new u(this.options.server,this.options.api,this),this.resolution=new n(0,0),this.parameters={width:0,height:0,antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.widgetImage=new g(e,this.canvas2D,this.loader),this.widgetVideo=new p(e,this.video,this.loader),this.widgetVRCube=new E(e,this.canvas3D,this.loader,this.onVrcubeInteraction),this.widgetVRObject=new I(e,this.canvas2D,this.loader,this.onVrobjectInteraction),this.widget=this.widgetImage,this.isDestroyed=!1,this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mouseenter",this.onMouseEnter),this.container.addEventListener("touchstart",this.onTouchStart),document.addEventListener("mousemove",this.onMouseMove,{passive:!1}),document.addEventListener("mouseup",this.onMouseUp),document.addEventListener("touchmove",this.onTouchMove,{passive:!1}),document.addEventListener("touchend",this.onTouchEnd),this.checkResize(),this.loadWidget=t(this.loadWidget,10),this.onResize=t(this.onResize,250)}destroy(){this.canvas2D.destroy(),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mouseenter",this.onMouseEnter),this.container.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd),this.isDestroyed=!0}async load(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(this.view.mode,i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>(this.scene=Array.isArray(t)?[...t]:[t],this.loadWidget(!1,!(e&&e.animation))))),i.catch((t=>{this.onLoadError(t)})),i}async setEncoder(t){this.encoder=Object.assign({},t);let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setParameters(t){this.parameters=Object.assign({},t),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height;let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setTags(t){this.tags=t,this.loadWidget(!1,!1)}async setView(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>{let i=!0;return this.view=Object.assign({},t),this.view&&this.viewWidget instanceof I&&void 0!==(null==e?void 0:e.toPosition)&&(i=!1,this.viewWidget.position=Object.assign({},e.toPosition)),this.loadWidget(i,!(e&&e.animation))})),i.catch((t=>{this.onLoadError(t)})),i}setVrcube(t){Object.assign(this.widgetVRCube,t)}setVrobject(t){Object.assign(this.widgetVRObject,t)}async loadAnimation(t){var e;const i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return(null===(e=i.view)||void 0===e?void 0:e.background)||(i.view.background="product"),this.widgetVideo.load(i).then((()=>Promise.resolve()))}async playAnimation(t){return this.loadAnimation(t).then((()=>this.widgetVideo.play())).catch((t=>{this.onLoadError(t)}))}stopAnimation(){this.widgetVideo.hide()}snapshot(t,e){return this.viewWidget.snapshot(t,e)}async loadWidget(t,e){if(!this.scene||!this.view)return Promise.resolve();if(!this.parameters.width||!this.parameters.height)return Promise.resolve();const i=this.viewWidget;if(!i)return Promise.reject(new Error("Unknown view mode"));const s={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return s.view.background||(s.view.background="product"),i.load(s,this.tags||[],t,e).then((t=>{this.widget.hide(),this.widget=i,this.widget.show(),this.widgetVideo.hide(),this.onHotspotsChange(t)}))}get viewWidget(){var t;switch(null===(t=this.view)||void 0===t?void 0:t.mode){case"image":default:return this.widgetImage;case"video":return this.widgetVideo;case"vrcube":return this.widgetVRCube;case"vrobject":return this.widgetVRObject}}checkResize(){if(this.isDestroyed)return;const t=this.container.clientWidth,e=this.container.clientHeight;t===this.containerWidth&&e===this.containerHeight||(this.containerWidth=t,this.containerHeight=e,this.onResize()),this.isDestroyed||requestAnimationFrame(this.checkResize)}onMouseDown(t){this.widget.onMouseDown(t)}onMouseEnter(t){this.widget.onMouseEnter(t)}onMouseMove(t){this.widget.onMouseMove(t)}onMouseUp(t){this.widget.onMouseUp(t)}onTouchStart(t){this.widget.onTouchStart(t)}onTouchMove(t){this.widget.onTouchMove(t)}onTouchEnd(t){this.widget.onTouchEnd(t)}onDeviceOrientation(t){this.widget.onDeviceOrientation(t)}onResize(){const t=window.devicePixelRatio,e=this.container.clientWidth*t,i=this.container.clientHeight*t;this.resolution=r.getStandardResolution(e,i),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height,this.canvas2D.resize(e/t,i/t),this.canvas3D.resize(e/t,i/t),this.video.resize(e/t,i/t,this.resolution,this.options.fit),this.loadWidget(!1,!1).catch((t=>{this.onLoadError(t)}))}onVrcubeInteraction(...t){this.options.events.onHotspotsChange(this.widgetVRCube.hotspots),this.options.events.onInteraction(...t),this.options.events.onVrcubeInteraction(...t)}onVrobjectInteraction(...t){this.options.events.onHotspotsChange(this.widgetVRObject.hotspots),this.options.events.onInteraction(...t),this.options.events.onVrobjectInteraction(...t)}onHotspotsChange(...t){this.options.events.onHotspotsChange(...t)}onLoadStart(...t){this.container.classList.add("ls-viewer-container-loading"),this.options.events.onLoadStart(...t)}onLoadProgress(...t){this.options.events.onLoadProgress(...t)}onLoadEnd(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadEnd(...t)}onLoadError(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadError(...t)}}!function(t){var e,i,s;(e=t.SunShadowQualityMode||(t.SunShadowQualityMode={})).VeryLow="veryLow",e.Low="low",e.Medium="medium",e.Fine="fine",e.Ultra="ultra",(i=t.SunShadowSmoothnessMode||(t.SunShadowSmoothnessMode={})).None="none",i.Weak="weak",i.Normal="normal",i.Fine="fine",i.UltraFine="ultraFine",i.Max="max",(s=t.SunUseCaseMode||(t.SunUseCaseMode={})).Manual="manual",s.ExtractedFromEnv="extractedFromEnv"}(S||(S={}));export{A as Viewer,S as WRAPIv2,g as WidgetImage,E as WidgetVRCube,I as WidgetVRObject,p as WidgetVideo};
17
17
  //# sourceMappingURL=index.es.js.map