@lumiscaphe/viewer
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -1,61 +0,13 @@ | ||
import { Animation } from './Animation'; | ||
import { Encoder } from './Encoder'; | ||
import { Options } from './Options'; | ||
import { Parameters } from './Parameters'; | ||
import { Scene } from './Scene'; | ||
import { Transition } from './Transition'; | ||
import { View } from './View'; | ||
import { WidgetVRCube } from './WidgetVRCube'; | ||
import { WidgetVRObject } from './WidgetVRObject'; | ||
import './index.css'; | ||
export declare class LSViewer { | ||
options: Options; | ||
private container; | ||
private containerWidth; | ||
private containerHeight; | ||
private canvas2D; | ||
private canvas3D; | ||
private video; | ||
private loader; | ||
private scene?; | ||
private view?; | ||
private parameters; | ||
private encoder; | ||
private resolution; | ||
private widget; | ||
private widgetImage; | ||
private widgetVideo; | ||
private widgetVRCube; | ||
private widgetVRObject; | ||
private isDestroyed; | ||
constructor(container: HTMLElement, options: Partial<Options>); | ||
destroy(): void; | ||
load(scene: Scene | Scene[], transition?: Transition): Promise<void>; | ||
setEncoder(encoder: Encoder): Promise<void>; | ||
setParameters(parameters: Parameters): Promise<void>; | ||
setView(view: View, transition?: Transition): Promise<void>; | ||
setVrcube(data: WidgetVRCube): void; | ||
setVrobject(data: WidgetVRObject): void; | ||
private loadAnimation; | ||
playAnimation(animation: Animation): Promise<void>; | ||
stopAnimation(): void; | ||
snapshot(type: string, quality: number): string; | ||
private loadWidget; | ||
private get viewWidget(); | ||
private checkResize; | ||
private onMouseDown; | ||
private onMouseEnter; | ||
private onMouseMove; | ||
private onMouseUp; | ||
private onTouchStart; | ||
private onTouchMove; | ||
private onTouchEnd; | ||
private onDeviceOrientation; | ||
private onResize; | ||
private onVrcubeInteraction; | ||
private onVrobjectInteraction; | ||
onLoadStart(...args: any[]): void; | ||
onLoadProgress(...args: any[]): void; | ||
onLoadEnd(...args: any[]): void; | ||
private onLoadError; | ||
} | ||
export * from './Animation'; | ||
export * from './Encoder'; | ||
export * from './Options'; | ||
export * from './Parameters'; | ||
export * from './Scene'; | ||
export * from './Transition'; | ||
export * from './View'; | ||
export * from './Viewer'; | ||
export * from './Widget'; | ||
export * from './WidgetImage'; | ||
export * from './WidgetVideo'; | ||
export * from './WidgetVRCube'; | ||
export * from './WidgetVRObject'; |
@@ -1,2 +0,2 @@ | ||
import t from"debounce-promise";import*as e from"twgl.js";import{v3 as i,m4 as s}from"twgl.js";import o from"axios";class n{constructor(t,e){this.width=t,this.height=e}get aspect(){return this.width/this.height}}class r{constructor(t,e,i,s){this.top=t,this.left=e,this.width=i,this.height=s}static fit(t,e,i){const s=t.aspect,o=e.aspect;let n=0,a=0;switch(i){case"contain":n=o<s?e.width:e.height*s,a=o<s?e.width/s:e.height;break;case"cover":default:n=o<s?e.height*s:e.width,a=o<s?e.height:e.width/s;break;case"fill":n=e.width,a=e.height}const h=(e.height-a)/2,c=(e.width-n)/2;return new r(h,c,n,a)}static getStandardAspectRatio(t,e){if(0===t||0===e)return 0;const i=t/e;if(t<e){return Math.abs(3/4-i)<Math.abs(9/16-i)?3/4:9/16}return Math.abs(4/3-i)<Math.abs(16/9-i)?4/3:16/9}static getStandardResolution(t,e){if(0===t||0===e)return new n(0,0);const i=r.getStandardAspectRatio(t,e);if(t<e){const t=r.getStandardQuality(e*i);return new n(Math.round(t),Math.round(t/i))}const s=r.getStandardQuality(t/i);return new n(Math.round(s*i),Math.round(s))}static getStandardQuality(t){return t<=240?240:t<=360?360:t<=480?480:t<=720?720:1080}}class a{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.context=this.element.getContext("2d"),this.backCanvas=document.createElement("canvas"),this.backContext=this.backCanvas.getContext("2d")}show(t){t?this.element.style.display="block":this.element.style.opacity="1"}hide(t){t?this.element.style.display="none":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,this.backCanvas.width=i.width,this.backCanvas.height=i.height)}load(t){const e=new Image;e.onload=()=>{this.draw(e,!1)},e.src=t}draw(t,e,i){t&&(this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=void 0),e?(this.backContext.drawImage(this.element,0,0,this.element.width,this.element.height),this.context.globalAlpha=0,this.fadeLoop(t,i||0)):(this.context.globalAlpha=1,this.context.drawImage(t,0,0,this.element.width,this.element.height)))}fadeLoop(t,e){if(this.context.globalAlpha>=1)return cancelAnimationFrame(this.requestAnimationId),void(this.requestAnimationId=void 0);const i=Math.min(this.context.globalAlpha+e,1);this.context.clearRect(0,0,this.element.width,this.element.height),this.context.globalAlpha=1,this.context.drawImage(this.backCanvas,0,0,this.element.width,this.element.height),this.context.globalAlpha=i,this.context.drawImage(t,0,0,this.element.width,this.element.height),this.requestAnimationId=requestAnimationFrame((()=>{this.fadeLoop(t,e)}))}}class h{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.context=e.getContext(this.element,{preserveDrawingBuffer:!0}),e.setDefaultTextureColor([1,1,1,1])}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(){this.element.style.width="100%",this.element.style.height="100%",this.element.style.top="0",this.element.style.left="0"}}class c{static accelerate(t,e){const i=e||1.5;return Math.abs(t)**i*(t>0?1:-1)}static degreesToRadians(t){return t*(Math.PI/180)}static radiansToDegrees(t){return t*(180/Math.PI)}static mod(t,e){return t-e*Math.floor(t/e)}}class d{constructor(t){this.server=t}static buildQuery(t){return Object.entries(t).filter((([t,e])=>!!e)).map((([t,e])=>`${t}=${e}`)).join("&")}static sceneParameters(t){const{scene:e}=t,i=e.length>1?e.find((t=>t.accessory)):null,s=e.length>1?e.find((t=>t.decor)):null,o=e.find((t=>t!==i&&t!==s));return{databaseId:o.database,configuration:o?.configuration,animations:o?.animations?.join("/"),accessoryDatabaseId:i?.database,decorDatabaseId:s?.database,decorDeltaAltitude:s?.translation?.y}}static renderParameters(t){const{parameters:e,view:i}=t;return{background:i.background,width:e.width,height:e.height,softwareAntialiasing:e.antialiasing,superSampling:e.superSampling}}static encoderParameters(t){const{encoder:e}=t;return{imageFormat:e.format,imageQuality:e.quality}}static async fetch(t){return o.get(t).then((t=>{const e=t.data.replace(/&/g,"&").match(this.xmlRegex);return e?e.map((t=>t.replace(this.xmlRegex,"$1"))):Promise.reject()}))}async animation(t){const e={...d.sceneParameters(t),animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],frames:t.view.frames,loop:!!t.view.loop,...d.renderParameters(t),...d.encoderParameters(t)},i=d.buildQuery(e);return d.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async image(t){const e={...d.sceneParameters(t),bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],...d.renderParameters(t),...d.encoderParameters(t)},i=d.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e={...d.sceneParameters(t),animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],duration:t.view.duration,frames:t.view.frames,loop:!!t.view.loop,reverse:!!t.view.reverse,...d.renderParameters(t),...d.encoderParameters(t)},i=d.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e={...d.sceneParameters(t),bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],...d.renderParameters(t),...d.encoderParameters(t)};e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=d.buildQuery(e);return d.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e={...d.sceneParameters(t),bookmarkSet:t.view.camera,...d.renderParameters(t),...d.encoderParameters(t)},i=d.buildQuery(e);return d.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}d.xmlRegex=/directUrl="([^"]*)"/g;class l{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const{accessory:e,decor:i,...s}=t;return s}))}static renderParameters(t){return{...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 fetch(t,e){return o.post(t,e).then((t=>t.data.map((t=>t.url))))}static async fetchOne(t,e){return o.post(t,e).then((t=>t.data.url))}async image(t){const e={scene:l.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:l.renderParameters(t),encoder:l.encoder(t)};return l.fetchOne(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:l.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:l.renderParameters(t),encoder:l.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),l.fetch(`${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:l.scene(t),mode:e,renderParameters:l.renderParameters(t),encoder:l.encoder(t)};return l.fetch(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:l.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:l.renderParameters(t),encoder:l.encoder(t)};return l.fetch(`${this.server}/Snapshot`,e)}}class m{constructor(t,e,i){switch(e){case"v1":this.webrender=new d(t);break;case"v2":this.webrender=new l(t);break;default:this.webrender=new d(t)}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 loadImage(t,e){const i=new Image;i.crossOrigin="anonymous";const s=new Promise(((t,s)=>{i.addEventListener("load",(()=>{e===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),t(i))}),{once:!0}),i.addEventListener("error",(t=>{e===this.loadingId&&s(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))),o}async loadVideo(t,e,i,s){t.loop=i;const o=new Promise(((e,i)=>{t.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),e())}),{once:!0}),t.addEventListener("error",(t=>{s===this.loadingId&&i(t)}),{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))),o}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){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:i}=this;return t.view.animation?"mp4"===t.encoder?.format?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,i))):this.webrender.animation(t).then((s=>this.loadImageFrames(s,t.view.loop,e,i))):this.webrender.vrObject(t).then((s=>this.loadImageFrames(s,t.view.loop,e,i)))}}class u{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 v{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i}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){const s=JSON.stringify(t);return s===this.hash&&this.image?(this.canvas.draw(this.image,i,.05),Promise.resolve()):(this.hash=s,this.loader.loadImageSnapshot(t).then((t=>{this.image=t,this.canvas.draw(this.image,i,.05)})))}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 g{constructor(t,e,i){this.container=t,this.loader=i,this.video=e}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))}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 p{constructor(t,e){this.x=t,this.y=e}clone(){return new p(this.x,this.y)}}class w{static pointFromMouseEvent(t){return new p(t.screenX,t.screenY)}static pointFromTouchEvent(t){return new p(t.touches[0].screenX,t.touches[0].screenY)}}class b{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 y{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class f{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new p(0,0),this.velocity=new p(0,0),this.loop=this.loop.bind(this)}track(t){const e=Date.now();this.points=this.points.filter((t=>e-t.time<=100)),this.points.push(new y(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 p(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 E{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 E(i.copy(this.target),i.copy(this.eye),i.copy(this.up))}}E.default=new E([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 f(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 E([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new p(0,0)}get orientedPov(){const t=i.normalize(i.cross(this.pov.up,this.pov.target)),e=new b(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 E(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 b(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 P{constructor(t,i,o,n){this.container=t,this.canvas=i,this.loader=o,this.images=[];const r=new E([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,(()=>{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)}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(),requestAnimationFrame(this.render))}get fov(){return c.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=c.degreesToRadians(t),requestAnimationFrame(this.render))}async load(t,i,s){const o=JSON.stringify(t);return o===this.hash?(requestAnimationFrame(this.render),Promise.resolve()):(this.hash=o,this.images=[],requestAnimationFrame(this.render),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||(i&&this.interaction.reset(),this.uniforms.u_mix=s?0:1,this.uniforms.u_texture_back=this.uniforms.u_texture,this.uniforms.u_texture=e,requestAnimationFrame(this.render))}))})))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}render(){e.resizeCanvasToDisplaySize(this.canvas.element,window.devicePixelRatio),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);const t=this.canvas.element.clientWidth,i=this.canvas.element.clientHeight,o=r.getStandardAspectRatio(t,i),n=t/i,a=this.interaction.fov*(o/n),h=s.inverse(s.perspective(a,n,.5,100)),c=this.interaction.orientedPov,d=s.lookAt(c.eye,c.target,c.up);this.uniforms.u_matrix=s.multiply(d,h),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),requestAnimationFrame(this.render))}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(w.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(w.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(w.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(w.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(w.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(w.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(w.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class L{constructor(t,e,i,s){this.isStarted=!1,this.position=t,this.count=e,this.loop=i,this.onMotion=s,this.inertia=new f(this.motion.bind(this)),this.initPosition=this.position,this.startPosition=0,this.startPoint=new p(0,0),this.startSize={width:0,height:0}}reset(){this.position=this.initPosition}start(t,e){this.isStarted=!0,this.startPosition=this.position,this.startPoint=t,this.startSize=e,this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t);const e={x:t.x-this.startPoint.x,y:t.y-this.startPoint.y},i=c.accelerate(e.x,1.3)/this.startSize.width*(this.count/4);let s=this.startPosition-Math.round(i);s=this.loop?c.mod(s,this.count):Math.max(0,Math.min(s,this.count-1)),s!==this.position&&(this.position=s,this.onMotion())}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}}class x{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.interaction=new L(0,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:this.interaction.position})})),this.onInteraction=s}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=>{let i=this.interaction.position;const s=()=>{if(this.interaction.position===t)e();else{let e=i>t?-1:1;this.interaction.loop&&this.interaction.count-i+t<Math.abs(t-i)&&(e*=-1),i+=.5*e,this.position=Math.floor(i),requestAnimationFrame(s)}};requestAnimationFrame(s)}))}get position(){return this.interaction.position}set position(t){this.interaction.position!==t&&(this.interaction.loop?this.interaction.position=c.mod(t,this.interaction.count):this.interaction.position=Math.max(0,Math.min(t,this.interaction.count-1)),this.canvas.draw(this.image,!0,.5))}get image(){return this.images[this.interaction.position]}async load(t,e,i){const s=JSON.stringify(t);if(s===this.hash)return this.canvas.draw(this.image,i,.05),Promise.resolve();this.hash=s,this.images=[],e&&this.interaction.reset();const{position:o}=this.interaction;return this.loader.loadVRObjectSnapshot(t,o).then((e=>{const s=e.length;return this.images=new Array(s),this.interaction.count=s,this.interaction.loop=!!t.view.loop,e.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,i,.05)}))})),e[this.interaction.position]}))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(w.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(w.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(w.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(w.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(w.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(w.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(w.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}!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:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-flex:1;-ms-flex:1 0 auto;flex:1 0 auto;position:relative;overflow:hidden;-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{position:absolute;opacity:0;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");class I{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.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options={server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{},...i},this.options.events={onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{},...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.container.appendChild(this.canvas2D.element),this.canvas3D=new h,this.container.appendChild(this.canvas3D.element),this.video=new u,this.container.appendChild(this.video.element),this.loader=new m(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 v(e,this.canvas2D,this.loader),this.widgetVideo=new g(e,this.video,this.loader),this.widgetVRCube=new P(e,this.canvas3D,this.loader,this.onVrcubeInteraction),this.widgetVRObject=new x(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.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mouseenter",this.onMouseEnter),this.container.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd),window.removeEventListener("deviceorientation",this.onDeviceOrientation),this.isDestroyed=!0}async load(t,e){let i=Promise.resolve();return e?.animation&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==e?.fromPosition&&(this.view.mode,i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),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={...t};let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setParameters(t){this.parameters={...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}async setView(t,e){let i=Promise.resolve();return e?.animation&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==e?.fromPosition&&(i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),e?.animation&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>{let i=!0;return this.view={...t},this.view&&this.viewWidget instanceof x&&void 0!==e?.toPosition&&(i=!1,this.viewWidget.position=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){const e={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 e.view?.background||(e.view.background="product"),this.widgetVideo.load(e)}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,t,e).then((()=>{this.widget.hide(),this.widget=i,this.widget.show(),this.widgetVideo.hide()}))}get viewWidget(){switch(this.view?.mode){case"image":return this.widgetImage;case"video":return this.widgetVideo;case"vrcube":return this.widgetVRCube;case"vrobject":return this.widgetVRObject;default:return this.widgetImage}}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.resolution,this.options.fit),this.canvas3D.resize(),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.onInteraction(...t),this.options.events.onVrcubeInteraction(...t)}onVrobjectInteraction(...t){this.options.events.onInteraction(...t),this.options.events.onVrobjectInteraction(...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)}}export{I as LSViewer}; | ||
import t from"debounce-promise";import*as e from"twgl.js";import{v3 as i,m4 as s}from"twgl.js";import o from"axios";class n{constructor(t,e){this.width=t,this.height=e}get aspect(){return this.width/this.height}}class r{constructor(t,e,i,s){this.top=t,this.left=e,this.width=i,this.height=s}static fit(t,e,i){const s=t.aspect,o=e.aspect;let n=0,a=0;switch(i){case"contain":n=o<s?e.width:e.height*s,a=o<s?e.width/s:e.height;break;case"cover":default:n=o<s?e.height*s:e.width,a=o<s?e.height:e.width/s;break;case"fill":n=e.width,a=e.height}const h=(e.height-a)/2,c=(e.width-n)/2;return new r(h,c,n,a)}static getStandardAspectRatio(t,e){if(0===t||0===e)return 0;const i=t/e;if(t<e){return Math.abs(3/4-i)<Math.abs(9/16-i)?3/4:9/16}return Math.abs(4/3-i)<Math.abs(16/9-i)?4/3:16/9}static getStandardResolution(t,e){if(0===t||0===e)return new n(0,0);const i=r.getStandardAspectRatio(t,e);if(t<e){const t=r.getStandardQuality(e*i);return new n(Math.round(t),Math.round(t/i))}const s=r.getStandardQuality(t/i);return new n(Math.round(s*i),Math.round(s))}static getStandardQuality(t){return t<=240?240:t<=360?360:t<=480?480:t<=720?720:1080}}class a{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.context=this.element.getContext("2d"),this.backCanvas=document.createElement("canvas"),this.backContext=this.backCanvas.getContext("2d")}show(t){t?this.element.style.display="block":this.element.style.opacity="1"}hide(t){t?this.element.style.display="none":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,this.backCanvas.width=i.width,this.backCanvas.height=i.height)}load(t){const e=new Image;e.onload=()=>{this.draw(e,!1)},e.src=t}draw(t,e,i){t&&(this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=void 0),e?(this.backContext.drawImage(this.element,0,0,this.element.width,this.element.height),this.context.globalAlpha=0,this.fadeLoop(t,i||0)):(this.context.globalAlpha=1,this.context.drawImage(t,0,0,this.element.width,this.element.height)))}fadeLoop(t,e){if(this.context.globalAlpha>=1)return cancelAnimationFrame(this.requestAnimationId),void(this.requestAnimationId=void 0);const i=Math.min(this.context.globalAlpha+e,1);this.context.clearRect(0,0,this.element.width,this.element.height),this.context.globalAlpha=1,this.context.drawImage(this.backCanvas,0,0,this.element.width,this.element.height),this.context.globalAlpha=i,this.context.drawImage(t,0,0,this.element.width,this.element.height),this.requestAnimationId=requestAnimationFrame((()=>{this.fadeLoop(t,e)}))}}class h{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.context=e.getContext(this.element,{preserveDrawingBuffer:!0}),e.setDefaultTextureColor([1,1,1,1])}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(){this.element.style.width="100%",this.element.style.height="100%",this.element.style.top="0",this.element.style.left="0"}}class c{static accelerate(t,e){const i=e||1.5;return Math.abs(t)**i*(t>0?1:-1)}static degreesToRadians(t){return t*(Math.PI/180)}static radiansToDegrees(t){return t*(180/Math.PI)}static mod(t,e){return t-e*Math.floor(t/e)}}class d{constructor(t){this.server=t}static buildQuery(t){return Object.entries(t).filter((([t,e])=>!!e)).map((([t,e])=>`${t}=${e}`)).join("&")}static sceneParameters(t){const{scene:e}=t,i=e.length>1?e.find((t=>t.accessory)):null,s=e.length>1?e.find((t=>t.decor)):null,o=e.find((t=>t!==i&&t!==s));return{databaseId:o.database,configuration:o?.configuration,animations:o?.animations?.join("/"),accessoryDatabaseId:i?.database,decorDatabaseId:s?.database,decorDeltaAltitude:s?.translation?.y}}static renderParameters(t){const{parameters:e,view:i}=t;return{background:i.background,width:e.width,height:e.height,softwareAntialiasing:e.antialiasing,superSampling:e.superSampling}}static encoderParameters(t){const{encoder:e}=t;return{imageFormat:e.format,imageQuality:e.quality}}static async fetch(t){return o.get(t).then((t=>{const e=t.data.replace(/&/g,"&").match(this.xmlRegex);return e?e.map((t=>t.replace(this.xmlRegex,"$1"))):Promise.reject()}))}async animation(t){const e={...d.sceneParameters(t),animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],frames:t.view.frames,loop:!!t.view.loop,...d.renderParameters(t),...d.encoderParameters(t)},i=d.buildQuery(e);return d.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async image(t){const e={...d.sceneParameters(t),bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],...d.renderParameters(t),...d.encoderParameters(t)},i=d.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e={...d.sceneParameters(t),animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],duration:t.view.duration,frames:t.view.frames,loop:!!t.view.loop,reverse:!!t.view.reverse,...d.renderParameters(t),...d.encoderParameters(t)},i=d.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e={...d.sceneParameters(t),bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],...d.renderParameters(t),...d.encoderParameters(t)};e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=d.buildQuery(e);return d.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e={...d.sceneParameters(t),bookmarkSet:t.view.camera,...d.renderParameters(t),...d.encoderParameters(t)},i=d.buildQuery(e);return d.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}d.xmlRegex=/directUrl="([^"]*)"/g;class l{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const{accessory:e,decor:i,...s}=t;return s}))}static renderParameters(t){return{...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 fetch(t,e){return o.post(t,e).then((t=>t.data.map((t=>t.url))))}static async fetchOne(t,e){return o.post(t,e).then((t=>t.data.url))}async image(t){const e={scene:l.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:l.renderParameters(t),encoder:l.encoder(t)};return l.fetchOne(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:l.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:l.renderParameters(t),encoder:l.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),l.fetch(`${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:l.scene(t),mode:e,renderParameters:l.renderParameters(t),encoder:l.encoder(t)};return l.fetch(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:l.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:l.renderParameters(t),encoder:l.encoder(t)};return l.fetch(`${this.server}/Snapshot`,e)}}class m{constructor(t,e,i){switch(e){case"v1":this.webrender=new d(t);break;case"v2":this.webrender=new l(t);break;default:this.webrender=new d(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){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:i}=this;return t.view.animation?"mp4"===t.encoder?.format?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,i))):this.webrender.animation(t).then((s=>this.loadImageFrames(s,t.view.loop,e,i))):this.webrender.vrObject(t).then((s=>this.loadImageFrames(s,t.view.loop,e,i)))}async loadImage(t,e){const i=new Image;i.crossOrigin="anonymous";const s=new Promise(((t,s)=>{i.addEventListener("load",(()=>{e===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),t(i))}),{once:!0}),i.addEventListener("error",(t=>{e===this.loadingId&&s(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))),o}async loadVideo(t,e,i,s){t.loop=i;const o=new Promise(((e,i)=>{t.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),e())}),{once:!0}),t.addEventListener("error",(t=>{s===this.loadingId&&i(t)}),{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))),o}onLoadStart(t){this.delegate&&this.delegate.onLoadStart(t)}onLoadProgress(t){this.delegate&&this.delegate.onLoadProgress(t)}onLoadEnd(t){this.delegate&&this.delegate.onLoadEnd(t)}}class u{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 v{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i}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){const s=JSON.stringify(t);return s===this.hash&&this.image?(this.canvas.draw(this.image,i,.05),Promise.resolve()):(this.hash=s,this.loader.loadImageSnapshot(t).then((t=>{this.image=t,this.canvas.draw(this.image,i,.05)})))}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 g{constructor(t,e,i){this.container=t,this.loader=i,this.video=e}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))}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 p{constructor(t,e){this.x=t,this.y=e}clone(){return new p(this.x,this.y)}}class w{static pointFromMouseEvent(t){return new p(t.screenX,t.screenY)}static pointFromTouchEvent(t){return new p(t.touches[0].screenX,t.touches[0].screenY)}}class b{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 y{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class f{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new p(0,0),this.velocity=new p(0,0),this.loop=this.loop.bind(this)}track(t){const e=Date.now();this.points=this.points.filter((t=>e-t.time<=100)),this.points.push(new y(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 p(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 E{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 E(i.copy(this.target),i.copy(this.eye),i.copy(this.up))}}E.default=new E([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 f(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 E([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new p(0,0)}get orientedPov(){const t=i.normalize(i.cross(this.pov.up,this.pov.target)),e=new b(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 E(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 b(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 P{constructor(t,i,o,n){this.container=t,this.canvas=i,this.loader=o,this.images=[];const r=new E([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,(()=>{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)}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(),requestAnimationFrame(this.render))}get fov(){return c.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=c.degreesToRadians(t),requestAnimationFrame(this.render))}async load(t,i,s){const o=JSON.stringify(t);return o===this.hash?(requestAnimationFrame(this.render),Promise.resolve()):(this.hash=o,this.images=[],requestAnimationFrame(this.render),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||(i&&this.interaction.reset(),this.uniforms.u_mix=s?0:1,this.uniforms.u_texture_back=this.uniforms.u_texture,this.uniforms.u_texture=e,requestAnimationFrame(this.render))}))})))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}render(){e.resizeCanvasToDisplaySize(this.canvas.element,window.devicePixelRatio),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);const t=this.canvas.element.clientWidth,i=this.canvas.element.clientHeight,o=r.getStandardAspectRatio(t,i),n=t/i,a=this.interaction.fov*(o/n),h=s.inverse(s.perspective(a,n,.5,100)),c=this.interaction.orientedPov,d=s.lookAt(c.eye,c.target,c.up);this.uniforms.u_matrix=s.multiply(d,h),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),requestAnimationFrame(this.render))}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(w.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(w.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(w.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(w.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(w.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(w.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(w.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class L{constructor(t,e,i,s){this.isStarted=!1,this.position=t,this.count=e,this.loop=i,this.onMotion=s,this.inertia=new f(this.motion.bind(this)),this.initPosition=this.position,this.startPosition=0,this.startPoint=new p(0,0),this.startSize={width:0,height:0}}reset(){this.position=this.initPosition}start(t,e){this.isStarted=!0,this.startPosition=this.position,this.startPoint=t,this.startSize=e,this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t);const e={x:t.x-this.startPoint.x,y:t.y-this.startPoint.y},i=c.accelerate(e.x,1.3)/this.startSize.width*(this.count/4);let s=this.startPosition-Math.round(i);s=this.loop?c.mod(s,this.count):Math.max(0,Math.min(s,this.count-1)),s!==this.position&&(this.position=s,this.onMotion())}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}}class x{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.interaction=new L(0,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:this.interaction.position})})),this.onInteraction=s}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=>{let i=this.interaction.position;const s=()=>{if(this.interaction.position===t)e();else{let e=i>t?-1:1;this.interaction.loop&&this.interaction.count-i+t<Math.abs(t-i)&&(e*=-1),i+=.5*e,this.position=Math.floor(i),requestAnimationFrame(s)}};requestAnimationFrame(s)}))}get position(){return this.interaction.position}set position(t){this.interaction.position!==t&&(this.interaction.loop?this.interaction.position=c.mod(t,this.interaction.count):this.interaction.position=Math.max(0,Math.min(t,this.interaction.count-1)),this.canvas.draw(this.image,!0,.5))}get image(){return this.images[this.interaction.position]}async load(t,e,i){const s=JSON.stringify(t);if(s===this.hash)return this.canvas.draw(this.image,i,.05),Promise.resolve();this.hash=s,this.images=[],e&&this.interaction.reset();const{position:o}=this.interaction;return this.loader.loadVRObjectSnapshot(t,o).then((e=>{const s=e.length;return this.images=new Array(s),this.interaction.count=s,this.interaction.loop=!!t.view.loop,e.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,i,.05)}))})),e[this.interaction.position]}))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(w.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(w.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(w.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(w.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(w.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(w.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(w.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}!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:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-flex:1;-ms-flex:1 0 auto;flex:1 0 auto;position:relative;overflow:hidden;-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{position:absolute;opacity:0;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");class I{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.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options={server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{},...i},this.options.events={onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{},...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.container.appendChild(this.canvas2D.element),this.canvas3D=new h,this.container.appendChild(this.canvas3D.element),this.video=new u,this.container.appendChild(this.video.element),this.loader=new m(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 v(e,this.canvas2D,this.loader),this.widgetVideo=new g(e,this.video,this.loader),this.widgetVRCube=new P(e,this.canvas3D,this.loader,this.onVrcubeInteraction),this.widgetVRObject=new x(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.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mouseenter",this.onMouseEnter),this.container.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd),window.removeEventListener("deviceorientation",this.onDeviceOrientation),this.isDestroyed=!0}async load(t,e){let i=Promise.resolve();return e?.animation&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==e?.fromPosition&&(this.view.mode,i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),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={...t};let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setParameters(t){this.parameters={...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}async setView(t,e){let i=Promise.resolve();return e?.animation&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==e?.fromPosition&&(i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),e?.animation&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>{let i=!0;return this.view={...t},this.view&&this.viewWidget instanceof x&&void 0!==e?.toPosition&&(i=!1,this.viewWidget.position=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){const e={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 e.view?.background||(e.view.background="product"),this.widgetVideo.load(e)}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,t,e).then((()=>{this.widget.hide(),this.widget=i,this.widget.show(),this.widgetVideo.hide()}))}get viewWidget(){switch(this.view?.mode){case"image":return this.widgetImage;case"video":return this.widgetVideo;case"vrcube":return this.widgetVRCube;case"vrobject":return this.widgetVRObject;default:return this.widgetImage}}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.resolution,this.options.fit),this.canvas3D.resize(),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.onInteraction(...t),this.options.events.onVrcubeInteraction(...t)}onVrobjectInteraction(...t){this.options.events.onInteraction(...t),this.options.events.onVrobjectInteraction(...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)}}export{I as Viewer,v as WidgetImage,P as WidgetVRCube,x as WidgetVRObject,g as WidgetVideo}; | ||
//# sourceMappingURL=index.es.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("debounce-promise"),e=require("twgl.js"),i=require("axios");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function n(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var o=s(t),r=n(e),a=s(i);class h{constructor(t,e){this.width=t,this.height=e}get aspect(){return this.width/this.height}}class c{constructor(t,e,i,s){this.top=t,this.left=e,this.width=i,this.height=s}static fit(t,e,i){const s=t.aspect,n=e.aspect;let o=0,r=0;switch(i){case"contain":o=n<s?e.width:e.height*s,r=n<s?e.width/s:e.height;break;case"cover":default:o=n<s?e.height*s:e.width,r=n<s?e.height:e.width/s;break;case"fill":o=e.width,r=e.height}const a=(e.height-r)/2,h=(e.width-o)/2;return new c(a,h,o,r)}static getStandardAspectRatio(t,e){if(0===t||0===e)return 0;const i=t/e;if(t<e){return Math.abs(3/4-i)<Math.abs(9/16-i)?3/4:9/16}return Math.abs(4/3-i)<Math.abs(16/9-i)?4/3:16/9}static getStandardResolution(t,e){if(0===t||0===e)return new h(0,0);const i=c.getStandardAspectRatio(t,e);if(t<e){const t=c.getStandardQuality(e*i);return new h(Math.round(t),Math.round(t/i))}const s=c.getStandardQuality(t/i);return new h(Math.round(s*i),Math.round(s))}static getStandardQuality(t){return t<=240?240:t<=360?360:t<=480?480:t<=720?720:1080}}class d{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.context=this.element.getContext("2d"),this.backCanvas=document.createElement("canvas"),this.backContext=this.backCanvas.getContext("2d")}show(t){t?this.element.style.display="block":this.element.style.opacity="1"}hide(t){t?this.element.style.display="none":this.element.style.opacity="0"}resize(t,e,i,s){const n=c.fit(i,new h(t,e),s);this.element.style.top=`${n.top}px`,this.element.style.left=`${n.left}px`,this.element.style.width=`${n.width}px`,this.element.style.height=`${n.height}px`,i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height,this.backCanvas.width=i.width,this.backCanvas.height=i.height)}load(t){const e=new Image;e.onload=()=>{this.draw(e,!1)},e.src=t}draw(t,e,i){t&&(this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=void 0),e?(this.backContext.drawImage(this.element,0,0,this.element.width,this.element.height),this.context.globalAlpha=0,this.fadeLoop(t,i||0)):(this.context.globalAlpha=1,this.context.drawImage(t,0,0,this.element.width,this.element.height)))}fadeLoop(t,e){if(this.context.globalAlpha>=1)return cancelAnimationFrame(this.requestAnimationId),void(this.requestAnimationId=void 0);const i=Math.min(this.context.globalAlpha+e,1);this.context.clearRect(0,0,this.element.width,this.element.height),this.context.globalAlpha=1,this.context.drawImage(this.backCanvas,0,0,this.element.width,this.element.height),this.context.globalAlpha=i,this.context.drawImage(t,0,0,this.element.width,this.element.height),this.requestAnimationId=requestAnimationFrame((()=>{this.fadeLoop(t,e)}))}}class l{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.context=r.getContext(this.element,{preserveDrawingBuffer:!0}),r.setDefaultTextureColor([1,1,1,1])}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(){this.element.style.width="100%",this.element.style.height="100%",this.element.style.top="0",this.element.style.left="0"}}class m{static accelerate(t,e){const i=e||1.5;return Math.abs(t)**i*(t>0?1:-1)}static degreesToRadians(t){return t*(Math.PI/180)}static radiansToDegrees(t){return t*(180/Math.PI)}static mod(t,e){return t-e*Math.floor(t/e)}}class u{constructor(t){this.server=t}static buildQuery(t){return Object.entries(t).filter((([t,e])=>!!e)).map((([t,e])=>`${t}=${e}`)).join("&")}static sceneParameters(t){const{scene:e}=t,i=e.length>1?e.find((t=>t.accessory)):null,s=e.length>1?e.find((t=>t.decor)):null,n=e.find((t=>t!==i&&t!==s));return{databaseId:n.database,configuration:n?.configuration,animations:n?.animations?.join("/"),accessoryDatabaseId:i?.database,decorDatabaseId:s?.database,decorDeltaAltitude:s?.translation?.y}}static renderParameters(t){const{parameters:e,view:i}=t;return{background:i.background,width:e.width,height:e.height,softwareAntialiasing:e.antialiasing,superSampling:e.superSampling}}static encoderParameters(t){const{encoder:e}=t;return{imageFormat:e.format,imageQuality:e.quality}}static async fetch(t){return a.default.get(t).then((t=>{const e=t.data.replace(/&/g,"&").match(this.xmlRegex);return e?e.map((t=>t.replace(this.xmlRegex,"$1"))):Promise.reject()}))}async animation(t){const e={...u.sceneParameters(t),animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],frames:t.view.frames,loop:!!t.view.loop,...u.renderParameters(t),...u.encoderParameters(t)},i=u.buildQuery(e);return u.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async image(t){const e={...u.sceneParameters(t),bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],...u.renderParameters(t),...u.encoderParameters(t)},i=u.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e={...u.sceneParameters(t),animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],duration:t.view.duration,frames:t.view.frames,loop:!!t.view.loop,reverse:!!t.view.reverse,...u.renderParameters(t),...u.encoderParameters(t)},i=u.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e={...u.sceneParameters(t),bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],...u.renderParameters(t),...u.encoderParameters(t)};e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=u.buildQuery(e);return u.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e={...u.sceneParameters(t),bookmarkSet:t.view.camera,...u.renderParameters(t),...u.encoderParameters(t)},i=u.buildQuery(e);return u.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}u.xmlRegex=/directUrl="([^"]*)"/g;class v{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const{accessory:e,decor:i,...s}=t;return s}))}static renderParameters(t){return{...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 fetch(t,e){return a.default.post(t,e).then((t=>t.data.map((t=>t.url))))}static async fetchOne(t,e){return a.default.post(t,e).then((t=>t.data.url))}async image(t){const e={scene:v.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetchOne(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:v.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:v.renderParameters(t),encoder:v.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),v.fetch(`${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:v.scene(t),mode:e,renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetch(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:v.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetch(`${this.server}/Snapshot`,e)}}class g{constructor(t,e,i){switch(e){case"v1":this.webrender=new u(t);break;case"v2":this.webrender=new v(t);break;default:this.webrender=new u(t)}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 loadImage(t,e){const i=new Image;i.crossOrigin="anonymous";const s=new Promise(((t,s)=>{i.addEventListener("load",(()=>{e===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),t(i))}),{once:!0}),i.addEventListener("error",(t=>{e===this.loadingId&&s(t)}),{once:!0})}));return i.src=t,s}loadImageFrames(t,e,i,s){this.total=t.length;const n=new Array(t.length),o=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?m.mod(o+a,r):i;n[h]=this.loadImage(t[h],s)}return Promise.all(n).then((()=>this.onLoadEnd(this.progress))),n}async loadVideo(t,e,i,s){t.loop=i;const n=new Promise(((e,i)=>{t.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),e())}),{once:!0}),t.addEventListener("error",(t=>{s===this.loadingId&&i(t)}),{once:!0})}));return t.src=e,t.load(),n}async loadVideoFrame(t,e,i,s,n){let o=0;return new Promise(((r,a)=>{const h=()=>{if(n!==this.loadingId)return;if(o!==s)return void(o+=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=>{n===this.loadingId&&a(t)}),{once:!0})}))}loadVideoFrames(t,e,i,s){this.total=e;const n=new Array(e),o=document.createElement("video");for(let t=0,r=e;t<r;t+=1)n[t]=this.loadVideoFrame(o,i,e,t,s);return o.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(o.currentTime=1/i/2)}),{once:!0}),o.src=t,o.load(),Promise.all(n).then((()=>this.onLoadEnd(this.progress))),n}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){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:i}=this;return t.view.animation?"mp4"===t.encoder?.format?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,i))):this.webrender.animation(t).then((s=>this.loadImageFrames(s,t.view.loop,e,i))):this.webrender.vrObject(t).then((s=>this.loadImageFrames(s,t.view.loop,e,i)))}}class p{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 n=c.fit(i,new h(t,e),s);this.element.style.top=`${n.top}px`,this.element.style.left=`${n.left}px`,this.element.style.width=`${n.width}px`,this.element.style.height=`${n.height}px`,i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height)}}class w{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i}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){const s=JSON.stringify(t);return s===this.hash&&this.image?(this.canvas.draw(this.image,i,.05),Promise.resolve()):(this.hash=s,this.loader.loadImageSnapshot(t).then((t=>{this.image=t,this.canvas.draw(this.image,i,.05)})))}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 b{constructor(t,e,i){this.container=t,this.loader=i,this.video=e}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))}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 y{constructor(t,e){this.x=t,this.y=e}clone(){return new y(this.x,this.y)}}class f{static pointFromMouseEvent(t){return new y(t.screenX,t.screenY)}static pointFromTouchEvent(t){return new y(t.touches[0].screenX,t.touches[0].screenY)}}class E{constructor(...t){3===t.length?(({0:this.u,1:this.v,2:this.o}=t),this.w=e.v3.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 e.m4.inverse(this.localToGlobalMatrix)}}class M{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 y(0,0),this.velocity=new y(0,0),this.loop=this.loop.bind(this)}track(t){const e=Date.now();this.points=this.points.filter((t=>e-t.time<=100)),this.points.push(new M(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,n=e.time-t.time;this.velocity=new y(0===n?0:i/(n/15),0===n?0:s/(n/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 L{constructor(t,i,s){this.target=e.v3.copy(t),this.eye=e.v3.copy(i),this.up=e.v3.copy(s)}get viewVector(){return e.v3.subtract(this.target,this.eye)}get rightVector(){return e.v3.normalize(e.v3.cross(this.viewVector,this.up))}get viewMatrix(){return e.m4.inverse(e.m4.lookAt(this.eye,this.target,this.up))}clone(){return new L(e.v3.copy(this.target),e.v3.copy(this.eye),e.v3.copy(this.up))}}L.default=new L([0,0,0],[2,2,2],[0,1,0]);class x{constructor(t,i,s){this.isStarted=!1,this.pov=t,this.fov=m.degreesToRadians(i),this.orientationMatrix=e.m4.identity(),this.inertia=new P(this.motion.bind(this)),this.onMotion=s,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=m.degreesToRadians(window.orientation)||0,this.startPov=new L([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new y(0,0)}get orientedPov(){const t=e.v3.normalize(e.v3.cross(this.pov.up,this.pov.target)),i=new E(t,[0,1,0],this.pov.eye),s=e.m4.identity();e.m4.multiply(s,i.localToGlobalMatrix,s),e.m4.multiply(s,this.orientationMatrix,s),e.m4.multiply(s,i.globalToLocalMatrix,s);const n=e.m4.transformDirection(s,this.pov.target),o=this.pov.eye,r=e.m4.transformDirection(s,this.pov.up);return new L(n,o,r)}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 i={x:t.x-this.previousPoint.x,y:t.y-this.previousPoint.y},s=m.accelerate(i.x,1.3)/this.startSize.width*.2*Math.PI*1.5,n=m.accelerate(i.y,1.3)/this.startSize.height*.2*Math.PI,o=e.m4.multiply(e.m4.rotationY(-s),e.m4.rotationX(-n)),r=e.v3.normalize(e.v3.cross(this.pov.up,this.pov.target)),a=new E(r,[0,1,0],this.pov.eye),h=e.m4.identity();e.m4.multiply(h,a.localToGlobalMatrix,h),e.m4.multiply(h,o,h),e.m4.multiply(h,a.globalToLocalMatrix,h);const c=e.m4.transformPoint(h,this.pov.target),d=e.m4.transformDirection(h,this.pov.up);e.v3.cross(d,[0,0,1])[0]>=0&&(this.pov.target=c,this.pov.up=d),this.previousPoint=t,this.onMotion()}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}orientation(t,i,s){const n=m.degreesToRadians(window.orientation)||0,o=m.degreesToRadians(t),r=m.degreesToRadians(-i),a=m.degreesToRadians(-s),h=e.m4.rotationX(m.degreesToRadians(90));e.m4.rotateZ(h,this.initOrientation,h),e.m4.rotateZ(h,o,h),e.m4.rotateX(h,r,h),e.m4.rotateY(h,a,h),e.m4.rotateZ(h,-n,h),this.orientationMatrix=h,this.onMotion()}}class I{constructor(t,i,s,n){this.container=t,this.canvas=i,this.loader=s,this.images=[];const o=new L([0,0,1],[0,0,0],[0,1,0]),a=e.m4.rotationX(m.degreesToRadians(15));e.m4.transformDirection(a,o.target,o.target),e.m4.transformDirection(a,o.up,o.up),this.interaction=new x(o,60,(()=>{requestAnimationFrame(this.render),this.onInteraction({pov:this.interaction.pov.clone(),fov:this.interaction.fov})})),this.onInteraction=n,this.gl=this.canvas.context,this.programInfo=r.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=r.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_matrix:e.m4.identity(),u_mix:0,u_texture_back:r.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:r.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1})},this.render=this.render.bind(this)}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(),requestAnimationFrame(this.render))}get fov(){return m.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=m.degreesToRadians(t),requestAnimationFrame(this.render))}async load(t,e,i){const s=JSON.stringify(t);return s===this.hash?(requestAnimationFrame(this.render),Promise.resolve()):(this.hash=s,this.images=[],requestAnimationFrame(this.render),this.loader.loadVRCubeSnapshot(t).then((t=>{this.images=t,r.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,s)=>{t||(e&&this.interaction.reset(),this.uniforms.u_mix=i?0:1,this.uniforms.u_texture_back=this.uniforms.u_texture,this.uniforms.u_texture=s,requestAnimationFrame(this.render))}))})))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}render(){r.resizeCanvasToDisplaySize(this.canvas.element,window.devicePixelRatio),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);const t=this.canvas.element.clientWidth,i=this.canvas.element.clientHeight,s=c.getStandardAspectRatio(t,i),n=t/i,o=this.interaction.fov*(s/n),a=e.m4.inverse(e.m4.perspective(o,n,.5,100)),h=this.interaction.orientedPov,d=e.m4.lookAt(h.eye,h.target,h.up);this.uniforms.u_matrix=e.m4.multiply(d,a),this.gl.useProgram(this.programInfo.program),r.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),r.setUniforms(this.programInfo,this.uniforms),r.drawBufferInfo(this.gl,this.quad),this.uniforms.u_mix<1&&(this.uniforms.u_mix=Math.min(this.uniforms.u_mix+.05,1),requestAnimationFrame(this.render))}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(f.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(f.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class A{constructor(t,e,i,s){this.isStarted=!1,this.position=t,this.count=e,this.loop=i,this.onMotion=s,this.inertia=new P(this.motion.bind(this)),this.initPosition=this.position,this.startPosition=0,this.startPoint=new y(0,0),this.startSize={width:0,height:0}}reset(){this.position=this.initPosition}start(t,e){this.isStarted=!0,this.startPosition=this.position,this.startPoint=t,this.startSize=e,this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t);const e={x:t.x-this.startPoint.x,y:t.y-this.startPoint.y},i=m.accelerate(e.x,1.3)/this.startSize.width*(this.count/4);let s=this.startPosition-Math.round(i);s=this.loop?m.mod(s,this.count):Math.max(0,Math.min(s,this.count-1)),s!==this.position&&(this.position=s,this.onMotion())}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}}class T{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.interaction=new A(0,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:this.interaction.position})})),this.onInteraction=s}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=>{let i=this.interaction.position;const s=()=>{if(this.interaction.position===t)e();else{let e=i>t?-1:1;this.interaction.loop&&this.interaction.count-i+t<Math.abs(t-i)&&(e*=-1),i+=.5*e,this.position=Math.floor(i),requestAnimationFrame(s)}};requestAnimationFrame(s)}))}get position(){return this.interaction.position}set position(t){this.interaction.position!==t&&(this.interaction.loop?this.interaction.position=m.mod(t,this.interaction.count):this.interaction.position=Math.max(0,Math.min(t,this.interaction.count-1)),this.canvas.draw(this.image,!0,.5))}get image(){return this.images[this.interaction.position]}async load(t,e,i){const s=JSON.stringify(t);if(s===this.hash)return this.canvas.draw(this.image,i,.05),Promise.resolve();this.hash=s,this.images=[],e&&this.interaction.reset();const{position:n}=this.interaction;return this.loader.loadVRObjectSnapshot(t,n).then((e=>{const s=e.length;return this.images=new Array(s),this.interaction.count=s,this.interaction.loop=!!t.view.loop,e.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,i,.05)}))})),e[this.interaction.position]}))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(f.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(f.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&s.firstChild?s.insertBefore(n,s.firstChild):s.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}}(".ls-viewer-container{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-flex:1;-ms-flex:1 0 auto;flex:1 0 auto;position:relative;overflow:hidden;-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{position:absolute;opacity:0;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");exports.LSViewer=class{constructor(t,e){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.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options={server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{},...e},this.options.events={onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{},...e.events},this.options.events.onLoadError=o.default(this.options.events.onLoadError,10),this.container=t,this.container.classList.add("ls-viewer-container"),this.containerWidth=0,this.containerHeight=0,this.canvas2D=new d,this.container.appendChild(this.canvas2D.element),this.canvas3D=new l,this.container.appendChild(this.canvas3D.element),this.video=new p,this.container.appendChild(this.video.element),this.loader=new g(this.options.server,this.options.api,this),this.resolution=new h(0,0),this.parameters={width:0,height:0,antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.widgetImage=new w(t,this.canvas2D,this.loader),this.widgetVideo=new b(t,this.video,this.loader),this.widgetVRCube=new I(t,this.canvas3D,this.loader,this.onVrcubeInteraction),this.widgetVRObject=new T(t,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=o.default(this.loadWidget,10),this.onResize=o.default(this.onResize,250)}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("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd),window.removeEventListener("deviceorientation",this.onDeviceOrientation),this.isDestroyed=!0}async load(t,e){let i=Promise.resolve();return e?.animation&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==e?.fromPosition&&(this.view.mode,i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),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={...t};let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setParameters(t){this.parameters={...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}async setView(t,e){let i=Promise.resolve();return e?.animation&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==e?.fromPosition&&(i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),e?.animation&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>{let i=!0;return this.view={...t},this.view&&this.viewWidget instanceof T&&void 0!==e?.toPosition&&(i=!1,this.viewWidget.position=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){const e={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 e.view?.background||(e.view.background="product"),this.widgetVideo.load(e)}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,t,e).then((()=>{this.widget.hide(),this.widget=i,this.widget.show(),this.widgetVideo.hide()}))}get viewWidget(){switch(this.view?.mode){case"image":return this.widgetImage;case"video":return this.widgetVideo;case"vrcube":return this.widgetVRCube;case"vrobject":return this.widgetVRObject;default:return this.widgetImage}}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=c.getStandardResolution(e,i),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height,this.canvas2D.resize(e/t,i/t,this.resolution,this.options.fit),this.canvas3D.resize(),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.onInteraction(...t),this.options.events.onVrcubeInteraction(...t)}onVrobjectInteraction(...t){this.options.events.onInteraction(...t),this.options.events.onVrobjectInteraction(...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)}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("debounce-promise"),e=require("twgl.js"),i=require("axios");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function n(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var o=s(t),r=n(e),a=s(i);class h{constructor(t,e){this.width=t,this.height=e}get aspect(){return this.width/this.height}}class c{constructor(t,e,i,s){this.top=t,this.left=e,this.width=i,this.height=s}static fit(t,e,i){const s=t.aspect,n=e.aspect;let o=0,r=0;switch(i){case"contain":o=n<s?e.width:e.height*s,r=n<s?e.width/s:e.height;break;case"cover":default:o=n<s?e.height*s:e.width,r=n<s?e.height:e.width/s;break;case"fill":o=e.width,r=e.height}const a=(e.height-r)/2,h=(e.width-o)/2;return new c(a,h,o,r)}static getStandardAspectRatio(t,e){if(0===t||0===e)return 0;const i=t/e;if(t<e){return Math.abs(3/4-i)<Math.abs(9/16-i)?3/4:9/16}return Math.abs(4/3-i)<Math.abs(16/9-i)?4/3:16/9}static getStandardResolution(t,e){if(0===t||0===e)return new h(0,0);const i=c.getStandardAspectRatio(t,e);if(t<e){const t=c.getStandardQuality(e*i);return new h(Math.round(t),Math.round(t/i))}const s=c.getStandardQuality(t/i);return new h(Math.round(s*i),Math.round(s))}static getStandardQuality(t){return t<=240?240:t<=360?360:t<=480?480:t<=720?720:1080}}class d{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.context=this.element.getContext("2d"),this.backCanvas=document.createElement("canvas"),this.backContext=this.backCanvas.getContext("2d")}show(t){t?this.element.style.display="block":this.element.style.opacity="1"}hide(t){t?this.element.style.display="none":this.element.style.opacity="0"}resize(t,e,i,s){const n=c.fit(i,new h(t,e),s);this.element.style.top=`${n.top}px`,this.element.style.left=`${n.left}px`,this.element.style.width=`${n.width}px`,this.element.style.height=`${n.height}px`,i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height,this.backCanvas.width=i.width,this.backCanvas.height=i.height)}load(t){const e=new Image;e.onload=()=>{this.draw(e,!1)},e.src=t}draw(t,e,i){t&&(this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=void 0),e?(this.backContext.drawImage(this.element,0,0,this.element.width,this.element.height),this.context.globalAlpha=0,this.fadeLoop(t,i||0)):(this.context.globalAlpha=1,this.context.drawImage(t,0,0,this.element.width,this.element.height)))}fadeLoop(t,e){if(this.context.globalAlpha>=1)return cancelAnimationFrame(this.requestAnimationId),void(this.requestAnimationId=void 0);const i=Math.min(this.context.globalAlpha+e,1);this.context.clearRect(0,0,this.element.width,this.element.height),this.context.globalAlpha=1,this.context.drawImage(this.backCanvas,0,0,this.element.width,this.element.height),this.context.globalAlpha=i,this.context.drawImage(t,0,0,this.element.width,this.element.height),this.requestAnimationId=requestAnimationFrame((()=>{this.fadeLoop(t,e)}))}}class l{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.context=r.getContext(this.element,{preserveDrawingBuffer:!0}),r.setDefaultTextureColor([1,1,1,1])}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(){this.element.style.width="100%",this.element.style.height="100%",this.element.style.top="0",this.element.style.left="0"}}class m{static accelerate(t,e){const i=e||1.5;return Math.abs(t)**i*(t>0?1:-1)}static degreesToRadians(t){return t*(Math.PI/180)}static radiansToDegrees(t){return t*(180/Math.PI)}static mod(t,e){return t-e*Math.floor(t/e)}}class u{constructor(t){this.server=t}static buildQuery(t){return Object.entries(t).filter((([t,e])=>!!e)).map((([t,e])=>`${t}=${e}`)).join("&")}static sceneParameters(t){const{scene:e}=t,i=e.length>1?e.find((t=>t.accessory)):null,s=e.length>1?e.find((t=>t.decor)):null,n=e.find((t=>t!==i&&t!==s));return{databaseId:n.database,configuration:n?.configuration,animations:n?.animations?.join("/"),accessoryDatabaseId:i?.database,decorDatabaseId:s?.database,decorDeltaAltitude:s?.translation?.y}}static renderParameters(t){const{parameters:e,view:i}=t;return{background:i.background,width:e.width,height:e.height,softwareAntialiasing:e.antialiasing,superSampling:e.superSampling}}static encoderParameters(t){const{encoder:e}=t;return{imageFormat:e.format,imageQuality:e.quality}}static async fetch(t){return a.default.get(t).then((t=>{const e=t.data.replace(/&/g,"&").match(this.xmlRegex);return e?e.map((t=>t.replace(this.xmlRegex,"$1"))):Promise.reject()}))}async animation(t){const e={...u.sceneParameters(t),animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],frames:t.view.frames,loop:!!t.view.loop,...u.renderParameters(t),...u.encoderParameters(t)},i=u.buildQuery(e);return u.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async image(t){const e={...u.sceneParameters(t),bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],...u.renderParameters(t),...u.encoderParameters(t)},i=u.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e={...u.sceneParameters(t),animation:t.view.animation,bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],duration:t.view.duration,frames:t.view.frames,loop:!!t.view.loop,reverse:!!t.view.reverse,...u.renderParameters(t),...u.encoderParameters(t)},i=u.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e={...u.sceneParameters(t),bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1],...u.renderParameters(t),...u.encoderParameters(t)};e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=u.buildQuery(e);return u.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e={...u.sceneParameters(t),bookmarkSet:t.view.camera,...u.renderParameters(t),...u.encoderParameters(t)},i=u.buildQuery(e);return u.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}u.xmlRegex=/directUrl="([^"]*)"/g;class v{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const{accessory:e,decor:i,...s}=t;return s}))}static renderParameters(t){return{...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 fetch(t,e){return a.default.post(t,e).then((t=>t.data.map((t=>t.url))))}static async fetchOne(t,e){return a.default.post(t,e).then((t=>t.data.url))}async image(t){const e={scene:v.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetchOne(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:v.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:v.renderParameters(t),encoder:v.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),v.fetch(`${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:v.scene(t),mode:e,renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetch(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:v.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetch(`${this.server}/Snapshot`,e)}}class g{constructor(t,e,i){switch(e){case"v1":this.webrender=new u(t);break;case"v2":this.webrender=new v(t);break;default:this.webrender=new u(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){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:i}=this;return t.view.animation?"mp4"===t.encoder?.format?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,i))):this.webrender.animation(t).then((s=>this.loadImageFrames(s,t.view.loop,e,i))):this.webrender.vrObject(t).then((s=>this.loadImageFrames(s,t.view.loop,e,i)))}async loadImage(t,e){const i=new Image;i.crossOrigin="anonymous";const s=new Promise(((t,s)=>{i.addEventListener("load",(()=>{e===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),t(i))}),{once:!0}),i.addEventListener("error",(t=>{e===this.loadingId&&s(t)}),{once:!0})}));return i.src=t,s}loadImageFrames(t,e,i,s){this.total=t.length;const n=new Array(t.length),o=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?m.mod(o+a,r):i;n[h]=this.loadImage(t[h],s)}return Promise.all(n).then((()=>this.onLoadEnd(this.progress))),n}async loadVideo(t,e,i,s){t.loop=i;const n=new Promise(((e,i)=>{t.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),e())}),{once:!0}),t.addEventListener("error",(t=>{s===this.loadingId&&i(t)}),{once:!0})}));return t.src=e,t.load(),n}async loadVideoFrame(t,e,i,s,n){let o=0;return new Promise(((r,a)=>{const h=()=>{if(n!==this.loadingId)return;if(o!==s)return void(o+=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=>{n===this.loadingId&&a(t)}),{once:!0})}))}loadVideoFrames(t,e,i,s){this.total=e;const n=new Array(e),o=document.createElement("video");for(let t=0,r=e;t<r;t+=1)n[t]=this.loadVideoFrame(o,i,e,t,s);return o.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(o.currentTime=1/i/2)}),{once:!0}),o.src=t,o.load(),Promise.all(n).then((()=>this.onLoadEnd(this.progress))),n}onLoadStart(t){this.delegate&&this.delegate.onLoadStart(t)}onLoadProgress(t){this.delegate&&this.delegate.onLoadProgress(t)}onLoadEnd(t){this.delegate&&this.delegate.onLoadEnd(t)}}class p{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 n=c.fit(i,new h(t,e),s);this.element.style.top=`${n.top}px`,this.element.style.left=`${n.left}px`,this.element.style.width=`${n.width}px`,this.element.style.height=`${n.height}px`,i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height)}}class w{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i}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){const s=JSON.stringify(t);return s===this.hash&&this.image?(this.canvas.draw(this.image,i,.05),Promise.resolve()):(this.hash=s,this.loader.loadImageSnapshot(t).then((t=>{this.image=t,this.canvas.draw(this.image,i,.05)})))}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 b{constructor(t,e,i){this.container=t,this.loader=i,this.video=e}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))}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 y{constructor(t,e){this.x=t,this.y=e}clone(){return new y(this.x,this.y)}}class f{static pointFromMouseEvent(t){return new y(t.screenX,t.screenY)}static pointFromTouchEvent(t){return new y(t.touches[0].screenX,t.touches[0].screenY)}}class E{constructor(...t){3===t.length?(({0:this.u,1:this.v,2:this.o}=t),this.w=e.v3.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 e.m4.inverse(this.localToGlobalMatrix)}}class M{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 y(0,0),this.velocity=new y(0,0),this.loop=this.loop.bind(this)}track(t){const e=Date.now();this.points=this.points.filter((t=>e-t.time<=100)),this.points.push(new M(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,n=e.time-t.time;this.velocity=new y(0===n?0:i/(n/15),0===n?0:s/(n/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 L{constructor(t,i,s){this.target=e.v3.copy(t),this.eye=e.v3.copy(i),this.up=e.v3.copy(s)}get viewVector(){return e.v3.subtract(this.target,this.eye)}get rightVector(){return e.v3.normalize(e.v3.cross(this.viewVector,this.up))}get viewMatrix(){return e.m4.inverse(e.m4.lookAt(this.eye,this.target,this.up))}clone(){return new L(e.v3.copy(this.target),e.v3.copy(this.eye),e.v3.copy(this.up))}}L.default=new L([0,0,0],[2,2,2],[0,1,0]);class x{constructor(t,i,s){this.isStarted=!1,this.pov=t,this.fov=m.degreesToRadians(i),this.orientationMatrix=e.m4.identity(),this.inertia=new P(this.motion.bind(this)),this.onMotion=s,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=m.degreesToRadians(window.orientation)||0,this.startPov=new L([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new y(0,0)}get orientedPov(){const t=e.v3.normalize(e.v3.cross(this.pov.up,this.pov.target)),i=new E(t,[0,1,0],this.pov.eye),s=e.m4.identity();e.m4.multiply(s,i.localToGlobalMatrix,s),e.m4.multiply(s,this.orientationMatrix,s),e.m4.multiply(s,i.globalToLocalMatrix,s);const n=e.m4.transformDirection(s,this.pov.target),o=this.pov.eye,r=e.m4.transformDirection(s,this.pov.up);return new L(n,o,r)}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 i={x:t.x-this.previousPoint.x,y:t.y-this.previousPoint.y},s=m.accelerate(i.x,1.3)/this.startSize.width*.2*Math.PI*1.5,n=m.accelerate(i.y,1.3)/this.startSize.height*.2*Math.PI,o=e.m4.multiply(e.m4.rotationY(-s),e.m4.rotationX(-n)),r=e.v3.normalize(e.v3.cross(this.pov.up,this.pov.target)),a=new E(r,[0,1,0],this.pov.eye),h=e.m4.identity();e.m4.multiply(h,a.localToGlobalMatrix,h),e.m4.multiply(h,o,h),e.m4.multiply(h,a.globalToLocalMatrix,h);const c=e.m4.transformPoint(h,this.pov.target),d=e.m4.transformDirection(h,this.pov.up);e.v3.cross(d,[0,0,1])[0]>=0&&(this.pov.target=c,this.pov.up=d),this.previousPoint=t,this.onMotion()}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}orientation(t,i,s){const n=m.degreesToRadians(window.orientation)||0,o=m.degreesToRadians(t),r=m.degreesToRadians(-i),a=m.degreesToRadians(-s),h=e.m4.rotationX(m.degreesToRadians(90));e.m4.rotateZ(h,this.initOrientation,h),e.m4.rotateZ(h,o,h),e.m4.rotateX(h,r,h),e.m4.rotateY(h,a,h),e.m4.rotateZ(h,-n,h),this.orientationMatrix=h,this.onMotion()}}class I{constructor(t,i,s,n){this.container=t,this.canvas=i,this.loader=s,this.images=[];const o=new L([0,0,1],[0,0,0],[0,1,0]),a=e.m4.rotationX(m.degreesToRadians(15));e.m4.transformDirection(a,o.target,o.target),e.m4.transformDirection(a,o.up,o.up),this.interaction=new x(o,60,(()=>{requestAnimationFrame(this.render),this.onInteraction({pov:this.interaction.pov.clone(),fov:this.interaction.fov})})),this.onInteraction=n,this.gl=this.canvas.context,this.programInfo=r.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=r.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_matrix:e.m4.identity(),u_mix:0,u_texture_back:r.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:r.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1})},this.render=this.render.bind(this)}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(),requestAnimationFrame(this.render))}get fov(){return m.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=m.degreesToRadians(t),requestAnimationFrame(this.render))}async load(t,e,i){const s=JSON.stringify(t);return s===this.hash?(requestAnimationFrame(this.render),Promise.resolve()):(this.hash=s,this.images=[],requestAnimationFrame(this.render),this.loader.loadVRCubeSnapshot(t).then((t=>{this.images=t,r.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,s)=>{t||(e&&this.interaction.reset(),this.uniforms.u_mix=i?0:1,this.uniforms.u_texture_back=this.uniforms.u_texture,this.uniforms.u_texture=s,requestAnimationFrame(this.render))}))})))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}render(){r.resizeCanvasToDisplaySize(this.canvas.element,window.devicePixelRatio),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height);const t=this.canvas.element.clientWidth,i=this.canvas.element.clientHeight,s=c.getStandardAspectRatio(t,i),n=t/i,o=this.interaction.fov*(s/n),a=e.m4.inverse(e.m4.perspective(o,n,.5,100)),h=this.interaction.orientedPov,d=e.m4.lookAt(h.eye,h.target,h.up);this.uniforms.u_matrix=e.m4.multiply(d,a),this.gl.useProgram(this.programInfo.program),r.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),r.setUniforms(this.programInfo,this.uniforms),r.drawBufferInfo(this.gl,this.quad),this.uniforms.u_mix<1&&(this.uniforms.u_mix=Math.min(this.uniforms.u_mix+.05,1),requestAnimationFrame(this.render))}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(f.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(f.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class A{constructor(t,e,i,s){this.isStarted=!1,this.position=t,this.count=e,this.loop=i,this.onMotion=s,this.inertia=new P(this.motion.bind(this)),this.initPosition=this.position,this.startPosition=0,this.startPoint=new y(0,0),this.startSize={width:0,height:0}}reset(){this.position=this.initPosition}start(t,e){this.isStarted=!0,this.startPosition=this.position,this.startPoint=t,this.startSize=e,this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t);const e={x:t.x-this.startPoint.x,y:t.y-this.startPoint.y},i=m.accelerate(e.x,1.3)/this.startSize.width*(this.count/4);let s=this.startPosition-Math.round(i);s=this.loop?m.mod(s,this.count):Math.max(0,Math.min(s,this.count-1)),s!==this.position&&(this.position=s,this.onMotion())}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}}class T{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.interaction=new A(0,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:this.interaction.position})})),this.onInteraction=s}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=>{let i=this.interaction.position;const s=()=>{if(this.interaction.position===t)e();else{let e=i>t?-1:1;this.interaction.loop&&this.interaction.count-i+t<Math.abs(t-i)&&(e*=-1),i+=.5*e,this.position=Math.floor(i),requestAnimationFrame(s)}};requestAnimationFrame(s)}))}get position(){return this.interaction.position}set position(t){this.interaction.position!==t&&(this.interaction.loop?this.interaction.position=m.mod(t,this.interaction.count):this.interaction.position=Math.max(0,Math.min(t,this.interaction.count-1)),this.canvas.draw(this.image,!0,.5))}get image(){return this.images[this.interaction.position]}async load(t,e,i){const s=JSON.stringify(t);if(s===this.hash)return this.canvas.draw(this.image,i,.05),Promise.resolve();this.hash=s,this.images=[],e&&this.interaction.reset();const{position:n}=this.interaction;return this.loader.loadVRObjectSnapshot(t,n).then((e=>{const s=e.length;return this.images=new Array(s),this.interaction.count=s,this.interaction.loop=!!t.view.loop,e.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,i,.05)}))})),e[this.interaction.position]}))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(f.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(f.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&s.firstChild?s.insertBefore(n,s.firstChild):s.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}}(".ls-viewer-container{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-flex:1;-ms-flex:1 0 auto;flex:1 0 auto;position:relative;overflow:hidden;-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{position:absolute;opacity:0;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");exports.Viewer=class{constructor(t,e){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.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options={server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{},...e},this.options.events={onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{},...e.events},this.options.events.onLoadError=o.default(this.options.events.onLoadError,10),this.container=t,this.container.classList.add("ls-viewer-container"),this.containerWidth=0,this.containerHeight=0,this.canvas2D=new d,this.container.appendChild(this.canvas2D.element),this.canvas3D=new l,this.container.appendChild(this.canvas3D.element),this.video=new p,this.container.appendChild(this.video.element),this.loader=new g(this.options.server,this.options.api,this),this.resolution=new h(0,0),this.parameters={width:0,height:0,antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.widgetImage=new w(t,this.canvas2D,this.loader),this.widgetVideo=new b(t,this.video,this.loader),this.widgetVRCube=new I(t,this.canvas3D,this.loader,this.onVrcubeInteraction),this.widgetVRObject=new T(t,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=o.default(this.loadWidget,10),this.onResize=o.default(this.onResize,250)}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("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd),window.removeEventListener("deviceorientation",this.onDeviceOrientation),this.isDestroyed=!0}async load(t,e){let i=Promise.resolve();return e?.animation&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==e?.fromPosition&&(this.view.mode,i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),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={...t};let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setParameters(t){this.parameters={...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}async setView(t,e){let i=Promise.resolve();return e?.animation&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==e?.fromPosition&&(i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),e?.animation&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>{let i=!0;return this.view={...t},this.view&&this.viewWidget instanceof T&&void 0!==e?.toPosition&&(i=!1,this.viewWidget.position=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){const e={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 e.view?.background||(e.view.background="product"),this.widgetVideo.load(e)}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,t,e).then((()=>{this.widget.hide(),this.widget=i,this.widget.show(),this.widgetVideo.hide()}))}get viewWidget(){switch(this.view?.mode){case"image":return this.widgetImage;case"video":return this.widgetVideo;case"vrcube":return this.widgetVRCube;case"vrobject":return this.widgetVRObject;default:return this.widgetImage}}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=c.getStandardResolution(e,i),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height,this.canvas2D.resize(e/t,i/t,this.resolution,this.options.fit),this.canvas3D.resize(),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.onInteraction(...t),this.options.events.onVrcubeInteraction(...t)}onVrobjectInteraction(...t){this.options.events.onInteraction(...t),this.options.events.onVrobjectInteraction(...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)}},exports.WidgetImage=w,exports.WidgetVRCube=I,exports.WidgetVRObject=T,exports.WidgetVideo=b; | ||
//# sourceMappingURL=index.js.map |
@@ -1,13 +0,15 @@ | ||
import { LSViewer } from './index'; | ||
import { LoaderDelegate } from './LoaderDelegate'; | ||
import { Snapshot } from './Snapshot'; | ||
export declare class Loader { | ||
private webrender; | ||
private delegate?; | ||
private loadingId; | ||
private loaded; | ||
private total; | ||
private onLoadStart; | ||
private onLoadProgress; | ||
private onLoadEnd; | ||
constructor(server: string, api: string, delegate: LSViewer); | ||
constructor(server: string, api: string, delegate: LoaderDelegate); | ||
get progress(): number; | ||
loadImageSnapshot(snapshot: Snapshot): Promise<HTMLImageElement>; | ||
loadVideoSnapshot(video: HTMLVideoElement, snapshot: Snapshot): Promise<any>; | ||
loadVRCubeSnapshot(snapshot: Snapshot): Promise<HTMLImageElement[]>; | ||
loadVRObjectSnapshot(snapshot: Snapshot, position: number): Promise<Promise<HTMLImageElement>[]>; | ||
private loadImage; | ||
@@ -18,6 +20,5 @@ private loadImageFrames; | ||
private loadVideoFrames; | ||
loadImageSnapshot(snapshot: Snapshot): Promise<HTMLImageElement>; | ||
loadVideoSnapshot(video: HTMLVideoElement, snapshot: Snapshot): Promise<any>; | ||
loadVRCubeSnapshot(snapshot: Snapshot): Promise<HTMLImageElement[]>; | ||
loadVRObjectSnapshot(snapshot: Snapshot, position: number): Promise<Promise<HTMLImageElement>[]>; | ||
private onLoadStart; | ||
private onLoadProgress; | ||
private onLoadEnd; | ||
} |
{ | ||
"name": "@lumiscaphe/viewer", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Lumiscaphe 3D Viewer", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
186684
45
1031
0