@lumiscaphe/viewer
Advanced tools
Comparing version 3.0.9 to 3.0.10
@@ -9,2 +9,3 @@ import { Resolution } from './Resolution'; | ||
constructor(); | ||
destroy(): void; | ||
show(useDisplay: boolean): void; | ||
@@ -11,0 +12,0 @@ hide(useDisplay: boolean): void; |
@@ -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";class n{constructor(t,e){this.width=t,this.height=e}get aspect(){return this.width/this.height}}class o{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 r=0,a=0;switch(i){case"contain":r=n<s?e.width:e.height*s,a=n<s?e.width/s:e.height;break;case"cover":default:r=n<s?e.height*s:e.width,a=n<s?e.height:e.width/s;break;case"fill":r=e.width,a=e.height}const h=(e.height-a)/2,c=(e.width-r)/2;return new o(h,c,r,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=o.getStandardAspectRatio(t,e);if(t<e){const s=o.getStandardQuality(Math.max(e*i,t));return new n(Math.round(s),Math.round(s/i))}const s=o.getStandardQuality(Math.max(t/i,e));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 r{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 r=o.fit(i,new n(t,e),s);this.element.style.top=`${r.top}px`,this.element.style.left=`${r.left}px`,this.element.style.width=`${r.width}px`,this.element.style.height=`${r.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 a{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 h{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 c{constructor(t){this.server=t}static buildQuery(t){return Object.entries(t).filter((([t,e])=>null!=e)).map((([t,e])=>`${t}=${e}`)).join("&")}static sceneParameters(t){var e,i;const{scene:s}=t,n=s.length>1?s.find((t=>t.accessory)):null,o=s.length>1?s.find((t=>t.decor)):null,r=s.find((t=>t!==n&&t!==o));return{databaseId:r.database,configuration:null==r?void 0:r.configuration,animations:null===(e=null==r?void 0:r.animations)||void 0===e?void 0:e.join("/"),accessoryDatabaseId:null==n?void 0:n.database,decorDatabaseId:null==o?void 0:o.database,decorDeltaAltitude:null===(i=null==o?void 0:o.translation)||void 0===i?void 0:i.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 fetch(t).then((t=>t.text())).then((t=>{const e=t.replace(/&/g,"&").match(this.xmlRegex);return e?e.map((t=>t.replace(this.xmlRegex,"$1"))):Promise.reject()}))}async animation(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},c.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}),c.renderParameters(t)),c.encoderParameters(t)),i=c.buildQuery(e);return c.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async image(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},c.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),c.renderParameters(t)),c.encoderParameters(t)),i=c.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},c.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}),c.renderParameters(t)),c.encoderParameters(t)),i=c.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},c.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),c.renderParameters(t)),c.encoderParameters(t));e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=c.buildQuery(e);return c.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},c.sceneParameters(t)),{bookmarkSet:t.view.camera}),c.renderParameters(t)),c.encoderParameters(t)),i=c.buildQuery(e);return c.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}c.xmlRegex=/directUrl="([^"]*)"/g;class d{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const e= | ||
import t from"debounce-promise";import*as e from"twgl.js";import{v3 as i,m4 as s}from"twgl.js";class n{constructor(t,e){this.width=t,this.height=e}get aspect(){return this.width/this.height}}class o{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 r=0,a=0;switch(i){case"contain":r=n<s?e.width:e.height*s,a=n<s?e.width/s:e.height;break;case"cover":default:r=n<s?e.height*s:e.width,a=n<s?e.height:e.width/s;break;case"fill":r=e.width,a=e.height}const h=(e.height-a)/2,c=(e.width-r)/2;return new o(h,c,r,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=o.getStandardAspectRatio(t,e);if(t<e){const s=o.getStandardQuality(Math.max(e*i,t));return new n(Math.round(s),Math.round(s/i))}const s=o.getStandardQuality(Math.max(t/i,e));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 r{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")}destroy(){this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=void 0)}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 r=o.fit(i,new n(t,e),s);this.element.style.top=`${r.top}px`,this.element.style.left=`${r.left}px`,this.element.style.width=`${r.width}px`,this.element.style.height=`${r.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 a{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 h{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 c{constructor(t){this.server=t}static buildQuery(t){return Object.entries(t).filter((([t,e])=>null!=e)).map((([t,e])=>`${t}=${e}`)).join("&")}static sceneParameters(t){var e,i;const{scene:s}=t,n=s.length>1?s.find((t=>t.accessory)):null,o=s.length>1?s.find((t=>t.decor)):null,r=s.find((t=>t!==n&&t!==o));return{databaseId:r.database,configuration:null==r?void 0:r.configuration,animations:null===(e=null==r?void 0:r.animations)||void 0===e?void 0:e.join("/"),accessoryDatabaseId:null==n?void 0:n.database,decorDatabaseId:null==o?void 0:o.database,decorDeltaAltitude:null===(i=null==o?void 0:o.translation)||void 0===i?void 0:i.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 fetch(t).then((t=>t.text())).then((t=>{const e=t.replace(/&/g,"&").match(this.xmlRegex);return e?e.map((t=>t.replace(this.xmlRegex,"$1"))):Promise.reject()}))}async animation(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},c.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}),c.renderParameters(t)),c.encoderParameters(t)),i=c.buildQuery(e);return c.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async image(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},c.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),c.renderParameters(t)),c.encoderParameters(t)),i=c.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},c.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}),c.renderParameters(t)),c.encoderParameters(t)),i=c.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},c.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),c.renderParameters(t)),c.encoderParameters(t));e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=c.buildQuery(e);return c.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},c.sceneParameters(t)),{bookmarkSet:t.view.camera}),c.renderParameters(t)),c.encoderParameters(t)),i=c.buildQuery(e);return c.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}c.xmlRegex=/directUrl="([^"]*)"/g;class d{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const e= | ||
/*! ***************************************************************************** | ||
@@ -16,3 +16,3 @@ Copyright (c) Microsoft Corporation. | ||
***************************************************************************** */ | ||
function(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}(t,["accessory","decor"]);return e}))}static renderParameters(t){return Object.assign(Object.assign({},t.parameters),{superSampling:t.parameters.superSampling.toString()})}static encoder(t){switch(t.encoder.format){case"jpeg":return{jpeg:{quality:t.encoder.quality}};case"png":return{png:{compression:t.encoder.compression}};case"webp":return{webp:{quality:t.encoder.quality}}}return{jpeg:{quality:80}}}static async fetch(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.map((t=>t.url))))}static async fetchOne(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.url))}async image(t){const e={scene:d.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:d.renderParameters(t),encoder:d.encoder(t)};return d.fetchOne(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:d.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:d.renderParameters(t),encoder:d.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),d.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:d.scene(t),mode:e,renderParameters:d.renderParameters(t),encoder:d.encoder(t)};return d.fetch(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:d.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:d.renderParameters(t),encoder:d.encoder(t)};return d.fetch(`${this.server}/Snapshot`,e)}}class l{constructor(t,e,i){switch(e){case"v1":default:this.webrender=new c(t);break;case"v2":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){var i;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:s}=this;return t.view.animation?"mp4"===(null===(i=t.encoder)||void 0===i?void 0:i.format)?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,s))):this.webrender.animation(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s))):this.webrender.vrObject(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s)))}async loadImage(t,e){const i=new Image;i.crossOrigin="anonymous";const s=new Promise(((s,n)=>{i.addEventListener("load",(()=>{e===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),s(i))}),{once:!0}),i.addEventListener("error",(i=>{e===this.loadingId&&n(`${i.type} : ${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),c=e?h.mod(o+a,r):i;n[c]=this.loadImage(t[c],s)}return Promise.all(n).then((()=>this.onLoadEnd(this.progress))),n}async loadVideo(t,e,i,s){t.loop=i;const n=new Promise(((i,n)=>{t.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),i())}),{once:!0}),t.addEventListener("error",(t=>{s===this.loadingId&&n(`${t.type} : ${e}`)}),{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 m{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 r=o.fit(i,new n(t,e),s);this.element.style.top=`${r.top}px`,this.element.style.left=`${r.left}px`,this.element.style.width=`${r.width}px`,this.element.style.height=`${r.height}px`,i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height)}}class u{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 v{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 g{constructor(t,e){this.x=t,this.y=e}clone(){return new g(this.x,this.y)}}class p{static pointFromMouseEvent(t){return new g(t.screenX,t.screenY)}static pointFromTouchEvent(t){const e=t.targetTouches[0]||t.changedTouches[0];return new g(e.screenX,e.screenY)}}class w{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 b{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class y{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new g(0,0),this.velocity=new g(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 b(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 g(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 f{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 f(i.copy(this.target),i.copy(this.eye),i.copy(this.up))}}f.default=new f([0,0,0],[2,2,2],[0,1,0]);class E{constructor(t,e,i){this.isStarted=!1,this.pov=t,this.fov=h.degreesToRadians(e),this.orientationMatrix=s.identity(),this.inertia=new y(this.motion.bind(this)),this.onMotion=i,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=h.degreesToRadians(window.orientation)||0,this.startPov=new f([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new g(0,0)}get orientedPov(){const t=i.normalize(i.cross(this.pov.up,this.pov.target)),e=new w(t,[0,1,0],this.pov.eye),n=s.identity();s.multiply(n,e.localToGlobalMatrix,n),s.multiply(n,this.orientationMatrix,n),s.multiply(n,e.globalToLocalMatrix,n);const o=s.transformDirection(n,this.pov.target),r=this.pov.eye,a=s.transformDirection(n,this.pov.up);return new f(o,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},n=h.accelerate(e.x,1.3)/this.startSize.width*.2*Math.PI*1.5,o=h.accelerate(e.y,1.3)/this.startSize.height*.2*Math.PI,r=s.multiply(s.rotationY(-n),s.rotationX(-o)),a=i.normalize(i.cross(this.pov.up,this.pov.target)),c=new w(a,[0,1,0],this.pov.eye),d=s.identity();s.multiply(d,c.localToGlobalMatrix,d),s.multiply(d,r,d),s.multiply(d,c.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 n=h.degreesToRadians(window.orientation)||0,o=h.degreesToRadians(t),r=h.degreesToRadians(-e),a=h.degreesToRadians(-i),c=s.rotationX(h.degreesToRadians(90));s.rotateZ(c,this.initOrientation,c),s.rotateZ(c,o,c),s.rotateX(c,r,c),s.rotateY(c,a,c),s.rotateZ(c,-n,c),this.orientationMatrix=c,this.onMotion()}}class M{constructor(t,i,n,o){this.container=t,this.canvas=i,this.loader=n,this.images=[];const r=new f([0,0,1],[0,0,0],[0,1,0]),a=s.rotationX(h.degreesToRadians(15));s.transformDirection(a,r.target,r.target),s.transformDirection(a,r.up,r.up),this.interaction=new E(r,60,(()=>{requestAnimationFrame(this.render),this.onInteraction({pov:this.interaction.pov.clone(),fov:this.interaction.fov})})),this.onInteraction=o,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 h.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=h.degreesToRadians(t),requestAnimationFrame(this.render))}async load(t,i,s){const n=JSON.stringify(t);return n===this.hash?(requestAnimationFrame(this.render),Promise.resolve()):(this.hash=n,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,n=o.getStandardAspectRatio(t,i),r=t/i,a=this.interaction.fov*(n/r),h=s.inverse(s.perspective(a,r,.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(p.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(p.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(p.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(p.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(p.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(p.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(p.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class P{constructor(t,e,i,s){this.isStarted=!1,this.position=t,this.count=e,this.loop=i,this.onMotion=s,this.inertia=new y(this.motion.bind(this)),this.initPosition=this.position,this.startPosition=0,this.startPoint=new g(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=h.accelerate(e.x,1.3)/this.startSize.width*(this.count/4);let s=this.startPosition-Math.round(i);s=this.loop?h.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 L{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.interaction=new P(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)}))}set initPosition(t){this.interaction.initPosition=t}get position(){return this.interaction.position}set position(t){this.interaction.position!==t&&(this.interaction.loop?this.interaction.position=h.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((s=>{const n=s.length;return this.images=new Array(n),this.interaction.count=n,this.interaction.loop=!!t.view.loop,e&&this.interaction.reset(),s.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,i,.05)}))})),s[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(p.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(p.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(p.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(p.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(p.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(p.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(p.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}var x;!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{-webkit-box-flex:1;display:-webkit-box;display:-ms-flexbox;display:flex;-ms-flex:1 0 auto;flex:1 0 auto;overflow:hidden;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.ls-viewer-container-image,.ls-viewer-container-video{cursor:default;pointer-events:none}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{opacity:0;position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");class S{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=Object.assign({server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{}},i),this.options.events=Object.assign({onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{}},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 r,this.container.appendChild(this.canvas2D.element),this.canvas3D=new a,this.container.appendChild(this.canvas3D.element),this.video=new m,this.container.appendChild(this.video.element),this.loader=new l(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 u(e,this.canvas2D,this.loader),this.widgetVideo=new v(e,this.video,this.loader),this.widgetVRCube=new M(e,this.canvas3D,this.loader,this.onVrcubeInteraction),this.widgetVRObject=new L(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(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(this.view.mode,i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>(this.scene=Array.isArray(t)?[...t]:[t],this.loadWidget(!1,!(e&&e.animation))))),i.catch((t=>{this.onLoadError(t)})),i}async setEncoder(t){this.encoder=Object.assign({},t);let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setParameters(t){this.parameters=Object.assign({},t),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height;let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}async setView(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>{let i=!0;return this.view=Object.assign({},t),this.view&&this.viewWidget instanceof L&&void 0!==(null==e?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){var e;const i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return(null===(e=i.view)||void 0===e?void 0:e.background)||(i.view.background="product"),this.widgetVideo.load(i)}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(){var t;switch(null===(t=this.view)||void 0===t?void 0:t.mode){case"image":default:return this.widgetImage;case"video":return this.widgetVideo;case"vrcube":return this.widgetVRCube;case"vrobject":return this.widgetVRObject}}checkResize(){if(this.isDestroyed)return;const t=this.container.clientWidth,e=this.container.clientHeight;t===this.containerWidth&&e===this.containerHeight||(this.containerWidth=t,this.containerHeight=e,this.onResize()),this.isDestroyed||requestAnimationFrame(this.checkResize)}onMouseDown(t){this.widget.onMouseDown(t)}onMouseEnter(t){this.widget.onMouseEnter(t)}onMouseMove(t){this.widget.onMouseMove(t)}onMouseUp(t){this.widget.onMouseUp(t)}onTouchStart(t){this.widget.onTouchStart(t)}onTouchMove(t){this.widget.onTouchMove(t)}onTouchEnd(t){this.widget.onTouchEnd(t)}onDeviceOrientation(t){this.widget.onDeviceOrientation(t)}onResize(){const t=window.devicePixelRatio,e=this.container.clientWidth*t,i=this.container.clientHeight*t;this.resolution=o.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)}}!function(t){var e,i,s;(e=t.SunShadowQualityMode||(t.SunShadowQualityMode={})).VeryLow="veryLow",e.Low="low",e.Medium="medium",e.Fine="fine",e.Ultra="ultra",(i=t.SunShadowSmoothnessMode||(t.SunShadowSmoothnessMode={})).None="none",i.Weak="weak",i.Normal="normal",i.Fine="fine",i.UltraFine="ultraFine",i.Max="max",(s=t.SunUseCaseMode||(t.SunUseCaseMode={})).Manual="manual",s.ExtractedFromEnv="extractedFromEnv"}(x||(x={}));export{S as Viewer,x as WRAPIv2,u as WidgetImage,M as WidgetVRCube,L as WidgetVRObject,v as WidgetVideo}; | ||
function(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}(t,["accessory","decor"]);return e}))}static renderParameters(t){return Object.assign(Object.assign({},t.parameters),{superSampling:t.parameters.superSampling.toString()})}static encoder(t){switch(t.encoder.format){case"jpeg":return{jpeg:{quality:t.encoder.quality}};case"png":return{png:{compression:t.encoder.compression}};case"webp":return{webp:{quality:t.encoder.quality}}}return{jpeg:{quality:80}}}static async fetch(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.map((t=>t.url))))}static async fetchOne(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.url))}async image(t){const e={scene:d.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:d.renderParameters(t),encoder:d.encoder(t)};return d.fetchOne(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:d.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:d.renderParameters(t),encoder:d.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),d.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:d.scene(t),mode:e,renderParameters:d.renderParameters(t),encoder:d.encoder(t)};return d.fetch(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:d.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:d.renderParameters(t),encoder:d.encoder(t)};return d.fetch(`${this.server}/Snapshot`,e)}}class l{constructor(t,e,i){switch(e){case"v1":default:this.webrender=new c(t);break;case"v2":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){var i;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:s}=this;return t.view.animation?"mp4"===(null===(i=t.encoder)||void 0===i?void 0:i.format)?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,s))):this.webrender.animation(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s))):this.webrender.vrObject(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s)))}async loadImage(t,e){const i=new Image;i.crossOrigin="anonymous";const s=new Promise(((s,n)=>{i.addEventListener("load",(()=>{e===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),s(i))}),{once:!0}),i.addEventListener("error",(i=>{e===this.loadingId&&n(`${i.type} : ${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),c=e?h.mod(o+a,r):i;n[c]=this.loadImage(t[c],s)}return Promise.all(n).then((()=>this.onLoadEnd(this.progress))),n}async loadVideo(t,e,i,s){t.loop=i;const n=new Promise(((i,n)=>{t.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),i())}),{once:!0}),t.addEventListener("error",(t=>{s===this.loadingId&&n(`${t.type} : ${e}`)}),{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 m{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 r=o.fit(i,new n(t,e),s);this.element.style.top=`${r.top}px`,this.element.style.left=`${r.left}px`,this.element.style.width=`${r.width}px`,this.element.style.height=`${r.height}px`,i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height)}}class u{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i}destroy(){}show(){this.canvas.show(!1),this.container.classList.add("ls-viewer-container-image")}hide(){this.canvas.hide(!1),this.container.classList.remove("ls-viewer-container-image")}async goto(t){return Promise.resolve()}async load(t,e,i){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 v{constructor(t,e,i){this.container=t,this.loader=i,this.video=e}destroy(){}show(){this.video.show(),this.container.classList.add("ls-viewer-container-video")}hide(){this.video.hide(),this.container.classList.remove("ls-viewer-container-video")}async goto(t){return Promise.resolve()}async load(t){const e=JSON.stringify(t);return e===this.hash?(this.video.element.load(),Promise.resolve()):(this.hash=e,this.loader.loadVideoSnapshot(this.video.element,t))}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 g{constructor(t,e){this.x=t,this.y=e}clone(){return new g(this.x,this.y)}}class p{static pointFromMouseEvent(t){return new g(t.screenX,t.screenY)}static pointFromTouchEvent(t){const e=t.targetTouches[0]||t.changedTouches[0];return new g(e.screenX,e.screenY)}}class w{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 b{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class y{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new g(0,0),this.velocity=new g(0,0),this.loop=this.loop.bind(this)}destroy(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}track(t){const e=Date.now();this.points=this.points.filter((t=>e-t.time<=100)),this.points.push(new b(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 g(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 f{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 f(i.copy(this.target),i.copy(this.eye),i.copy(this.up))}}f.default=new f([0,0,0],[2,2,2],[0,1,0]);class E{constructor(t,e,i){this.isStarted=!1,this.pov=t,this.fov=h.degreesToRadians(e),this.orientationMatrix=s.identity(),this.inertia=new y(this.motion.bind(this)),this.onMotion=i,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=h.degreesToRadians(window.orientation)||0,this.startPov=new f([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new g(0,0)}destroy(){this.inertia.destroy()}get orientedPov(){const t=i.normalize(i.cross(this.pov.up,this.pov.target)),e=new w(t,[0,1,0],this.pov.eye),n=s.identity();s.multiply(n,e.localToGlobalMatrix,n),s.multiply(n,this.orientationMatrix,n),s.multiply(n,e.globalToLocalMatrix,n);const o=s.transformDirection(n,this.pov.target),r=this.pov.eye,a=s.transformDirection(n,this.pov.up);return new f(o,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},n=h.accelerate(e.x,1.3)/this.startSize.width*.2*Math.PI*1.5,o=h.accelerate(e.y,1.3)/this.startSize.height*.2*Math.PI,r=s.multiply(s.rotationY(-n),s.rotationX(-o)),a=i.normalize(i.cross(this.pov.up,this.pov.target)),c=new w(a,[0,1,0],this.pov.eye),d=s.identity();s.multiply(d,c.localToGlobalMatrix,d),s.multiply(d,r,d),s.multiply(d,c.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 n=h.degreesToRadians(window.orientation)||0,o=h.degreesToRadians(t),r=h.degreesToRadians(-e),a=h.degreesToRadians(-i),c=s.rotationX(h.degreesToRadians(90));s.rotateZ(c,this.initOrientation,c),s.rotateZ(c,o,c),s.rotateX(c,r,c),s.rotateY(c,a,c),s.rotateZ(c,-n,c),this.orientationMatrix=c,this.onMotion()}}class M{constructor(t,i,n,o){this.container=t,this.canvas=i,this.loader=n,this.images=[];const r=new f([0,0,1],[0,0,0],[0,1,0]),a=s.rotationX(h.degreesToRadians(15));s.transformDirection(a,r.target,r.target),s.transformDirection(a,r.up,r.up),this.interaction=new E(r,60,(()=>{this.animationFrameId=requestAnimationFrame(this.render),this.onInteraction({pov:this.interaction.pov.clone(),fov:this.interaction.fov})})),this.onInteraction=o,this.gl=this.canvas.context,this.programInfo=e.createProgramInfo(this.gl,["attribute vec4 position;uniform mat4 u_matrix;varying vec3 direction;void main(){direction=(u_matrix*position).xyz;gl_Position=position*vec4(-1,1,1,1);}\n","precision mediump float;uniform float u_mix;uniform samplerCube u_texture;uniform samplerCube u_texture_back;varying vec3 direction;void main(){vec4 backColor=textureCube(u_texture_back,direction);vec4 color=textureCube(u_texture,direction);gl_FragColor=mix(backColor,color,u_mix);}\n"]),this.quad=e.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_matrix:s.identity(),u_mix:0,u_texture_back:e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1})},this.render=this.render.bind(this)}destroy(){this.interaction.destroy(),this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}show(){this.canvas.show(),this.container.classList.add("ls-viewer-container-vrcube")}hide(){this.canvas.hide(),this.container.classList.remove("ls-viewer-container-vrcube")}async goto(t){return Promise.resolve()}get pov(){return this.interaction.pov}set pov(t){this.interaction.pov.eye.every(((e,i)=>e===t.eye[i]))&&this.interaction.pov.target.every(((e,i)=>e===t.target[i]))&&this.interaction.pov.up.every(((e,i)=>e===t.up[i]))||(this.interaction.pov=t.clone(),this.animationFrameId=requestAnimationFrame(this.render))}get fov(){return h.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=h.degreesToRadians(t),this.animationFrameId=requestAnimationFrame(this.render))}async load(t,i,s){const n=JSON.stringify(t);return n===this.hash?(this.animationFrameId=requestAnimationFrame(this.render),Promise.resolve()):(this.hash=n,this.images=[],this.animationFrameId=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,this.animationFrameId=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,n=o.getStandardAspectRatio(t,i),r=t/i,a=this.interaction.fov*(n/r),h=s.inverse(s.perspective(a,r,.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),this.animationFrameId=requestAnimationFrame(this.render))}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(p.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(p.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(p.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(p.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(p.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(p.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(p.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class P{constructor(t,e,i,s){this.isStarted=!1,this.position=t,this.count=e,this.loop=i,this.onMotion=s,this.inertia=new y(this.motion.bind(this)),this.initPosition=this.position,this.startPosition=0,this.startPoint=new g(0,0),this.startSize={width:0,height:0}}destroy(){this.inertia.destroy()}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=h.accelerate(e.x,1.3)/this.startSize.width*(this.count/4);let s=this.startPosition-Math.round(i);s=this.loop?h.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 I{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.interaction=new P(0,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:this.interaction.position})})),this.onInteraction=s}destroy(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}show(){this.canvas.show(!1),this.container.classList.add("ls-viewer-container-vrobject")}hide(){this.canvas.hide(!1),this.container.classList.remove("ls-viewer-container-vrobject")}async goto(t){return new Promise((e=>{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),this.animationFrameId=requestAnimationFrame(s)}};this.animationFrameId=requestAnimationFrame(s)}))}set initPosition(t){this.interaction.initPosition=t}get position(){return this.interaction.position}set position(t){this.interaction.position!==t&&(this.interaction.loop?this.interaction.position=h.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((s=>{const n=s.length;return this.images=new Array(n),this.interaction.count=n,this.interaction.loop=!!t.view.loop,e&&this.interaction.reset(),s.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,i,.05)}))})),s[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(p.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(p.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(p.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(p.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(p.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(p.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(p.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}var L;!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{-webkit-box-flex:1;display:-webkit-box;display:-ms-flexbox;display:flex;-ms-flex:1 0 auto;flex:1 0 auto;overflow:hidden;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.ls-viewer-container-image,.ls-viewer-container-video{cursor:default;pointer-events:none}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{opacity:0;position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");class x{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=Object.assign({server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{}},i),this.options.events=Object.assign({onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{}},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 r,this.container.appendChild(this.canvas2D.element),this.canvas3D=new a,this.container.appendChild(this.canvas3D.element),this.video=new m,this.container.appendChild(this.video.element),this.loader=new l(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 u(e,this.canvas2D,this.loader),this.widgetVideo=new v(e,this.video,this.loader),this.widgetVRCube=new M(e,this.canvas3D,this.loader,this.onVrcubeInteraction),this.widgetVRObject=new I(e,this.canvas2D,this.loader,this.onVrobjectInteraction),this.widget=this.widgetImage,this.isDestroyed=!1,this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mouseenter",this.onMouseEnter),this.container.addEventListener("touchstart",this.onTouchStart),document.addEventListener("mousemove",this.onMouseMove,{passive:!1}),document.addEventListener("mouseup",this.onMouseUp),document.addEventListener("touchmove",this.onTouchMove,{passive:!1}),document.addEventListener("touchend",this.onTouchEnd),this.checkResize(),this.loadWidget=t(this.loadWidget,10),this.onResize=t(this.onResize,250)}destroy(){this.canvas2D.destroy(),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mouseenter",this.onMouseEnter),this.container.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("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(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(this.view.mode,i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>(this.scene=Array.isArray(t)?[...t]:[t],this.loadWidget(!1,!(e&&e.animation))))),i.catch((t=>{this.onLoadError(t)})),i}async setEncoder(t){this.encoder=Object.assign({},t);let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setParameters(t){this.parameters=Object.assign({},t),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height;let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}async setView(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>{let i=!0;return this.view=Object.assign({},t),this.view&&this.viewWidget instanceof I&&void 0!==(null==e?void 0:e.toPosition)&&(i=!1,this.viewWidget.position=e.toPosition),this.loadWidget(i,!(e&&e.animation))})),i.catch((t=>{this.onLoadError(t)})),i}setVrcube(t){Object.assign(this.widgetVRCube,t)}setVrobject(t){Object.assign(this.widgetVRObject,t)}async loadAnimation(t){var e;const i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return(null===(e=i.view)||void 0===e?void 0:e.background)||(i.view.background="product"),this.widgetVideo.load(i)}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(){var t;switch(null===(t=this.view)||void 0===t?void 0:t.mode){case"image":default:return this.widgetImage;case"video":return this.widgetVideo;case"vrcube":return this.widgetVRCube;case"vrobject":return this.widgetVRObject}}checkResize(){if(this.isDestroyed)return;const t=this.container.clientWidth,e=this.container.clientHeight;t===this.containerWidth&&e===this.containerHeight||(this.containerWidth=t,this.containerHeight=e,this.onResize()),this.isDestroyed||requestAnimationFrame(this.checkResize)}onMouseDown(t){this.widget.onMouseDown(t)}onMouseEnter(t){this.widget.onMouseEnter(t)}onMouseMove(t){this.widget.onMouseMove(t)}onMouseUp(t){this.widget.onMouseUp(t)}onTouchStart(t){this.widget.onTouchStart(t)}onTouchMove(t){this.widget.onTouchMove(t)}onTouchEnd(t){this.widget.onTouchEnd(t)}onDeviceOrientation(t){this.widget.onDeviceOrientation(t)}onResize(){const t=window.devicePixelRatio,e=this.container.clientWidth*t,i=this.container.clientHeight*t;this.resolution=o.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)}}!function(t){var e,i,s;(e=t.SunShadowQualityMode||(t.SunShadowQualityMode={})).VeryLow="veryLow",e.Low="low",e.Medium="medium",e.Fine="fine",e.Ultra="ultra",(i=t.SunShadowSmoothnessMode||(t.SunShadowSmoothnessMode={})).None="none",i.Weak="weak",i.Normal="normal",i.Fine="fine",i.UltraFine="ultraFine",i.Max="max",(s=t.SunUseCaseMode||(t.SunUseCaseMode={})).Manual="manual",s.ExtractedFromEnv="extractedFromEnv"}(L||(L={}));export{x as Viewer,L as WRAPIv2,u as WidgetImage,M as WidgetVRCube,I as WidgetVRObject,v 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");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function s(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 n=i(t),o=s(e);class r{constructor(t,e){this.width=t,this.height=e}get aspect(){return this.width/this.height}}class a{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 h=(e.height-r)/2,c=(e.width-o)/2;return new a(h,c,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 r(0,0);const i=a.getStandardAspectRatio(t,e);if(t<e){const s=a.getStandardQuality(Math.max(e*i,t));return new r(Math.round(s),Math.round(s/i))}const s=a.getStandardQuality(Math.max(t/i,e));return new r(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 h{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=a.fit(i,new r(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 c{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.context=o.getContext(this.element,{preserveDrawingBuffer:!0}),o.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 d{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 l{constructor(t){this.server=t}static buildQuery(t){return Object.entries(t).filter((([t,e])=>null!=e)).map((([t,e])=>`${t}=${e}`)).join("&")}static sceneParameters(t){var e,i;const{scene:s}=t,n=s.length>1?s.find((t=>t.accessory)):null,o=s.length>1?s.find((t=>t.decor)):null,r=s.find((t=>t!==n&&t!==o));return{databaseId:r.database,configuration:null==r?void 0:r.configuration,animations:null===(e=null==r?void 0:r.animations)||void 0===e?void 0:e.join("/"),accessoryDatabaseId:null==n?void 0:n.database,decorDatabaseId:null==o?void 0:o.database,decorDeltaAltitude:null===(i=null==o?void 0:o.translation)||void 0===i?void 0:i.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 fetch(t).then((t=>t.text())).then((t=>{const e=t.replace(/&/g,"&").match(this.xmlRegex);return e?e.map((t=>t.replace(this.xmlRegex,"$1"))):Promise.reject()}))}async animation(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},l.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}),l.renderParameters(t)),l.encoderParameters(t)),i=l.buildQuery(e);return l.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async image(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},l.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),l.renderParameters(t)),l.encoderParameters(t)),i=l.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},l.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}),l.renderParameters(t)),l.encoderParameters(t)),i=l.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},l.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),l.renderParameters(t)),l.encoderParameters(t));e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=l.buildQuery(e);return l.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},l.sceneParameters(t)),{bookmarkSet:t.view.camera}),l.renderParameters(t)),l.encoderParameters(t)),i=l.buildQuery(e);return l.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}l.xmlRegex=/directUrl="([^"]*)"/g;class m{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const e= | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("debounce-promise"),e=require("twgl.js");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function s(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 n=i(t),o=s(e);class r{constructor(t,e){this.width=t,this.height=e}get aspect(){return this.width/this.height}}class a{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 h=(e.height-r)/2,c=(e.width-o)/2;return new a(h,c,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 r(0,0);const i=a.getStandardAspectRatio(t,e);if(t<e){const s=a.getStandardQuality(Math.max(e*i,t));return new r(Math.round(s),Math.round(s/i))}const s=a.getStandardQuality(Math.max(t/i,e));return new r(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 h{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")}destroy(){this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=void 0)}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=a.fit(i,new r(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 c{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.context=o.getContext(this.element,{preserveDrawingBuffer:!0}),o.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 d{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 l{constructor(t){this.server=t}static buildQuery(t){return Object.entries(t).filter((([t,e])=>null!=e)).map((([t,e])=>`${t}=${e}`)).join("&")}static sceneParameters(t){var e,i;const{scene:s}=t,n=s.length>1?s.find((t=>t.accessory)):null,o=s.length>1?s.find((t=>t.decor)):null,r=s.find((t=>t!==n&&t!==o));return{databaseId:r.database,configuration:null==r?void 0:r.configuration,animations:null===(e=null==r?void 0:r.animations)||void 0===e?void 0:e.join("/"),accessoryDatabaseId:null==n?void 0:n.database,decorDatabaseId:null==o?void 0:o.database,decorDeltaAltitude:null===(i=null==o?void 0:o.translation)||void 0===i?void 0:i.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 fetch(t).then((t=>t.text())).then((t=>{const e=t.replace(/&/g,"&").match(this.xmlRegex);return e?e.map((t=>t.replace(this.xmlRegex,"$1"))):Promise.reject()}))}async animation(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},l.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}),l.renderParameters(t)),l.encoderParameters(t)),i=l.buildQuery(e);return l.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async image(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},l.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),l.renderParameters(t)),l.encoderParameters(t)),i=l.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},l.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}),l.renderParameters(t)),l.encoderParameters(t)),i=l.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},l.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),l.renderParameters(t)),l.encoderParameters(t));e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=l.buildQuery(e);return l.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},l.sceneParameters(t)),{bookmarkSet:t.view.camera}),l.renderParameters(t)),l.encoderParameters(t)),i=l.buildQuery(e);return l.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}l.xmlRegex=/directUrl="([^"]*)"/g;class m{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const e= | ||
/*! ***************************************************************************** | ||
@@ -16,3 +16,3 @@ Copyright (c) Microsoft Corporation. | ||
***************************************************************************** */ | ||
function(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}(t,["accessory","decor"]);return e}))}static renderParameters(t){return Object.assign(Object.assign({},t.parameters),{superSampling:t.parameters.superSampling.toString()})}static encoder(t){switch(t.encoder.format){case"jpeg":return{jpeg:{quality:t.encoder.quality}};case"png":return{png:{compression:t.encoder.compression}};case"webp":return{webp:{quality:t.encoder.quality}}}return{jpeg:{quality:80}}}static async fetch(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.map((t=>t.url))))}static async fetchOne(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.url))}async image(t){const e={scene:m.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetchOne(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:m.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return e.renderParameters.width=Math.max(e.renderParameters.width,e.renderParameters.height),e.renderParameters.height=Math.max(e.renderParameters.width,e.renderParameters.height),m.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:m.scene(t),mode:e,renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetch(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:m.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetch(`${this.server}/Snapshot`,e)}}class u{constructor(t,e,i){switch(e){case"v1":default:this.webrender=new l(t);break;case"v2":this.webrender=new m(t)}this.delegate=i,this.loadingId=0,this.loaded=0,this.total=0,this.onLoadStart=i&&i.onLoadStart?i.onLoadStart:()=>{},this.onLoadProgress=i&&i.onLoadProgress?i.onLoadProgress:()=>{},this.onLoadEnd=i&&i.onLoadEnd?i.onLoadEnd:()=>{}}get progress(){return this.total?this.loaded/this.total:0}async loadImageSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.image(t).then((t=>this.loadImage(t,e))).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVideoSnapshot(t,e){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:i}=this;return this.webrender.video(e).then((s=>this.loadVideo(t,s,!!e.view.loop,i))).then((()=>(this.onLoadEnd(this.progress),t)))}async loadVRCubeSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.vrCube(t).then((t=>{this.total=t.length;const i=t.map((t=>this.loadImage(t,e)));return Promise.all(i)})).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVRObjectSnapshot(t,e){var i;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:s}=this;return t.view.animation?"mp4"===(null===(i=t.encoder)||void 0===i?void 0:i.format)?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,s))):this.webrender.animation(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s))):this.webrender.vrObject(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s)))}async loadImage(t,e){const i=new Image;i.crossOrigin="anonymous";const s=new Promise(((s,n)=>{i.addEventListener("load",(()=>{e===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),s(i))}),{once:!0}),i.addEventListener("error",(i=>{e===this.loadingId&&n(`${i.type} : ${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?d.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(((i,n)=>{t.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),i())}),{once:!0}),t.addEventListener("error",(t=>{s===this.loadingId&&n(`${t.type} : ${e}`)}),{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 v{constructor(){this.element=document.createElement("video"),this.element.classList.add("ls-viewer-video"),this.element.style.opacity="0",this.element.setAttribute("muted",""),this.element.setAttribute("playsinline",""),this.element.setAttribute("preload","auto")}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(t,e,i,s){const n=a.fit(i,new r(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 g{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 p{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 w{constructor(t,e){this.x=t,this.y=e}clone(){return new w(this.x,this.y)}}class b{static pointFromMouseEvent(t){return new w(t.screenX,t.screenY)}static pointFromTouchEvent(t){const e=t.targetTouches[0]||t.changedTouches[0];return new w(e.screenX,e.screenY)}}class y{constructor(...t){3===t.length?(({0:this.u,1:this.v,2:this.o}=t),this.w=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 f{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class E{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new w(0,0),this.velocity=new w(0,0),this.loop=this.loop.bind(this)}track(t){const e=Date.now();this.points=this.points.filter((t=>e-t.time<=100)),this.points.push(new f(t.x,t.y,e)),this.lastPoint=t}start(){if(0===this.points.length)return;const t=this.points[0],e=this.points[this.points.length-1],i=e.x-t.x,s=e.y-t.y,n=e.time-t.time;this.velocity=new w(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 M{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 M(e.v3.copy(this.target),e.v3.copy(this.eye),e.v3.copy(this.up))}}M.default=new M([0,0,0],[2,2,2],[0,1,0]);class P{constructor(t,i,s){this.isStarted=!1,this.pov=t,this.fov=d.degreesToRadians(i),this.orientationMatrix=e.m4.identity(),this.inertia=new E(this.motion.bind(this)),this.onMotion=s,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=d.degreesToRadians(window.orientation)||0,this.startPov=new M([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new w(0,0)}get orientedPov(){const t=e.v3.normalize(e.v3.cross(this.pov.up,this.pov.target)),i=new y(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 M(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=d.accelerate(i.x,1.3)/this.startSize.width*.2*Math.PI*1.5,n=d.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 y(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),l=e.m4.transformDirection(h,this.pov.up);e.v3.cross(l,[0,0,1])[0]>=0&&(this.pov.target=c,this.pov.up=l),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=d.degreesToRadians(window.orientation)||0,o=d.degreesToRadians(t),r=d.degreesToRadians(-i),a=d.degreesToRadians(-s),h=e.m4.rotationX(d.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 x{constructor(t,i,s,n){this.container=t,this.canvas=i,this.loader=s,this.images=[];const r=new M([0,0,1],[0,0,0],[0,1,0]),a=e.m4.rotationX(d.degreesToRadians(15));e.m4.transformDirection(a,r.target,r.target),e.m4.transformDirection(a,r.up,r.up),this.interaction=new P(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=o.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=o.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_matrix:e.m4.identity(),u_mix:0,u_texture_back:o.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:o.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 d.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=d.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,o.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(){o.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=a.getStandardAspectRatio(t,i),n=t/i,r=this.interaction.fov*(s/n),h=e.m4.inverse(e.m4.perspective(r,n,.5,100)),c=this.interaction.orientedPov,d=e.m4.lookAt(c.eye,c.target,c.up);this.uniforms.u_matrix=e.m4.multiply(d,h),this.gl.useProgram(this.programInfo.program),o.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),o.setUniforms(this.programInfo,this.uniforms),o.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(b.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(b.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class L{constructor(t,e,i,s){this.isStarted=!1,this.position=t,this.count=e,this.loop=i,this.onMotion=s,this.inertia=new E(this.motion.bind(this)),this.initPosition=this.position,this.startPosition=0,this.startPoint=new w(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=d.accelerate(e.x,1.3)/this.startSize.width*(this.count/4);let s=this.startPosition-Math.round(i);s=this.loop?d.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 S{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)}))}set initPosition(t){this.interaction.initPosition=t}get position(){return this.interaction.position}set position(t){this.interaction.position!==t&&(this.interaction.loop?this.interaction.position=d.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((s=>{const n=s.length;return this.images=new Array(n),this.interaction.count=n,this.interaction.loop=!!t.view.loop,e&&this.interaction.reset(),s.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,i,.05)}))})),s[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(b.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(b.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}var I,A,T,O;!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{-webkit-box-flex:1;display:-webkit-box;display:-ms-flexbox;display:flex;-ms-flex:1 0 auto;flex:1 0 auto;overflow:hidden;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.ls-viewer-container-image,.ls-viewer-container-video{cursor:default;pointer-events:none}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{opacity:0;position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");exports.WRAPIv2=void 0,I=exports.WRAPIv2||(exports.WRAPIv2={}),(A=I.SunShadowQualityMode||(I.SunShadowQualityMode={})).VeryLow="veryLow",A.Low="low",A.Medium="medium",A.Fine="fine",A.Ultra="ultra",(T=I.SunShadowSmoothnessMode||(I.SunShadowSmoothnessMode={})).None="none",T.Weak="weak",T.Normal="normal",T.Fine="fine",T.UltraFine="ultraFine",T.Max="max",(O=I.SunUseCaseMode||(I.SunUseCaseMode={})).Manual="manual",O.ExtractedFromEnv="extractedFromEnv",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=Object.assign({server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{}},e),this.options.events=Object.assign({onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{}},e.events),this.options.events.onLoadError=n.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 h,this.container.appendChild(this.canvas2D.element),this.canvas3D=new c,this.container.appendChild(this.canvas3D.element),this.video=new v,this.container.appendChild(this.video.element),this.loader=new u(this.options.server,this.options.api,this),this.resolution=new r(0,0),this.parameters={width:0,height:0,antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.widgetImage=new g(t,this.canvas2D,this.loader),this.widgetVideo=new p(t,this.video,this.loader),this.widgetVRCube=new x(t,this.canvas3D,this.loader,this.onVrcubeInteraction),this.widgetVRObject=new S(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=n.default(this.loadWidget,10),this.onResize=n.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(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(this.view.mode,i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>(this.scene=Array.isArray(t)?[...t]:[t],this.loadWidget(!1,!(e&&e.animation))))),i.catch((t=>{this.onLoadError(t)})),i}async setEncoder(t){this.encoder=Object.assign({},t);let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setParameters(t){this.parameters=Object.assign({},t),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height;let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}async setView(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>{let i=!0;return this.view=Object.assign({},t),this.view&&this.viewWidget instanceof S&&void 0!==(null==e?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){var e;const i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return(null===(e=i.view)||void 0===e?void 0:e.background)||(i.view.background="product"),this.widgetVideo.load(i)}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(){var t;switch(null===(t=this.view)||void 0===t?void 0:t.mode){case"image":default:return this.widgetImage;case"video":return this.widgetVideo;case"vrcube":return this.widgetVRCube;case"vrobject":return this.widgetVRObject}}checkResize(){if(this.isDestroyed)return;const t=this.container.clientWidth,e=this.container.clientHeight;t===this.containerWidth&&e===this.containerHeight||(this.containerWidth=t,this.containerHeight=e,this.onResize()),this.isDestroyed||requestAnimationFrame(this.checkResize)}onMouseDown(t){this.widget.onMouseDown(t)}onMouseEnter(t){this.widget.onMouseEnter(t)}onMouseMove(t){this.widget.onMouseMove(t)}onMouseUp(t){this.widget.onMouseUp(t)}onTouchStart(t){this.widget.onTouchStart(t)}onTouchMove(t){this.widget.onTouchMove(t)}onTouchEnd(t){this.widget.onTouchEnd(t)}onDeviceOrientation(t){this.widget.onDeviceOrientation(t)}onResize(){const t=window.devicePixelRatio,e=this.container.clientWidth*t,i=this.container.clientHeight*t;this.resolution=a.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=g,exports.WidgetVRCube=x,exports.WidgetVRObject=S,exports.WidgetVideo=p; | ||
function(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}(t,["accessory","decor"]);return e}))}static renderParameters(t){return Object.assign(Object.assign({},t.parameters),{superSampling:t.parameters.superSampling.toString()})}static encoder(t){switch(t.encoder.format){case"jpeg":return{jpeg:{quality:t.encoder.quality}};case"png":return{png:{compression:t.encoder.compression}};case"webp":return{webp:{quality:t.encoder.quality}}}return{jpeg:{quality:80}}}static async fetch(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.map((t=>t.url))))}static async fetchOne(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.url))}async image(t){const e={scene:m.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetchOne(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:m.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return e.renderParameters.width=Math.max(e.renderParameters.width,e.renderParameters.height),e.renderParameters.height=Math.max(e.renderParameters.width,e.renderParameters.height),m.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:m.scene(t),mode:e,renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetch(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:m.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:m.renderParameters(t),encoder:m.encoder(t)};return m.fetch(`${this.server}/Snapshot`,e)}}class u{constructor(t,e,i){switch(e){case"v1":default:this.webrender=new l(t);break;case"v2":this.webrender=new m(t)}this.delegate=i,this.loadingId=0,this.loaded=0,this.total=0,this.onLoadStart=i&&i.onLoadStart?i.onLoadStart:()=>{},this.onLoadProgress=i&&i.onLoadProgress?i.onLoadProgress:()=>{},this.onLoadEnd=i&&i.onLoadEnd?i.onLoadEnd:()=>{}}get progress(){return this.total?this.loaded/this.total:0}async loadImageSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.image(t).then((t=>this.loadImage(t,e))).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVideoSnapshot(t,e){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:i}=this;return this.webrender.video(e).then((s=>this.loadVideo(t,s,!!e.view.loop,i))).then((()=>(this.onLoadEnd(this.progress),t)))}async loadVRCubeSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.vrCube(t).then((t=>{this.total=t.length;const i=t.map((t=>this.loadImage(t,e)));return Promise.all(i)})).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVRObjectSnapshot(t,e){var i;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:s}=this;return t.view.animation?"mp4"===(null===(i=t.encoder)||void 0===i?void 0:i.format)?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,s))):this.webrender.animation(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s))):this.webrender.vrObject(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s)))}async loadImage(t,e){const i=new Image;i.crossOrigin="anonymous";const s=new Promise(((s,n)=>{i.addEventListener("load",(()=>{e===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),s(i))}),{once:!0}),i.addEventListener("error",(i=>{e===this.loadingId&&n(`${i.type} : ${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?d.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(((i,n)=>{t.addEventListener("canplaythrough",(()=>{s===this.loadingId&&(this.loaded+=1,this.onLoadProgress(this.progress),i())}),{once:!0}),t.addEventListener("error",(t=>{s===this.loadingId&&n(`${t.type} : ${e}`)}),{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 v{constructor(){this.element=document.createElement("video"),this.element.classList.add("ls-viewer-video"),this.element.style.opacity="0",this.element.setAttribute("muted",""),this.element.setAttribute("playsinline",""),this.element.setAttribute("preload","auto")}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(t,e,i,s){const n=a.fit(i,new r(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 g{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i}destroy(){}show(){this.canvas.show(!1),this.container.classList.add("ls-viewer-container-image")}hide(){this.canvas.hide(!1),this.container.classList.remove("ls-viewer-container-image")}async goto(t){return Promise.resolve()}async load(t,e,i){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 p{constructor(t,e,i){this.container=t,this.loader=i,this.video=e}destroy(){}show(){this.video.show(),this.container.classList.add("ls-viewer-container-video")}hide(){this.video.hide(),this.container.classList.remove("ls-viewer-container-video")}async goto(t){return Promise.resolve()}async load(t){const e=JSON.stringify(t);return e===this.hash?(this.video.element.load(),Promise.resolve()):(this.hash=e,this.loader.loadVideoSnapshot(this.video.element,t))}snapshot(t,e){return"data:image/gif;base64,R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="}async play(){return new Promise(((t,e)=>{this.video.element.addEventListener("ended",(()=>{t()}),{once:!0});const i=this.video.element.play();i&&i.catch((()=>{e()})),this.show()}))}onMouseDown(t){}onMouseMove(t){}onMouseUp(t){}onMouseEnter(t){}onTouchStart(t){}onTouchMove(t){}onTouchEnd(t){}onDeviceOrientation(t){}}class w{constructor(t,e){this.x=t,this.y=e}clone(){return new w(this.x,this.y)}}class b{static pointFromMouseEvent(t){return new w(t.screenX,t.screenY)}static pointFromTouchEvent(t){const e=t.targetTouches[0]||t.changedTouches[0];return new w(e.screenX,e.screenY)}}class y{constructor(...t){3===t.length?(({0:this.u,1:this.v,2:this.o}=t),this.w=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 f{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class E{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new w(0,0),this.velocity=new w(0,0),this.loop=this.loop.bind(this)}destroy(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}track(t){const e=Date.now();this.points=this.points.filter((t=>e-t.time<=100)),this.points.push(new f(t.x,t.y,e)),this.lastPoint=t}start(){if(0===this.points.length)return;const t=this.points[0],e=this.points[this.points.length-1],i=e.x-t.x,s=e.y-t.y,n=e.time-t.time;this.velocity=new w(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 M{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 M(e.v3.copy(this.target),e.v3.copy(this.eye),e.v3.copy(this.up))}}M.default=new M([0,0,0],[2,2,2],[0,1,0]);class P{constructor(t,i,s){this.isStarted=!1,this.pov=t,this.fov=d.degreesToRadians(i),this.orientationMatrix=e.m4.identity(),this.inertia=new E(this.motion.bind(this)),this.onMotion=s,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=d.degreesToRadians(window.orientation)||0,this.startPov=new M([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new w(0,0)}destroy(){this.inertia.destroy()}get orientedPov(){const t=e.v3.normalize(e.v3.cross(this.pov.up,this.pov.target)),i=new y(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 M(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=d.accelerate(i.x,1.3)/this.startSize.width*.2*Math.PI*1.5,n=d.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 y(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),l=e.m4.transformDirection(h,this.pov.up);e.v3.cross(l,[0,0,1])[0]>=0&&(this.pov.target=c,this.pov.up=l),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=d.degreesToRadians(window.orientation)||0,o=d.degreesToRadians(t),r=d.degreesToRadians(-i),a=d.degreesToRadians(-s),h=e.m4.rotationX(d.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 r=new M([0,0,1],[0,0,0],[0,1,0]),a=e.m4.rotationX(d.degreesToRadians(15));e.m4.transformDirection(a,r.target,r.target),e.m4.transformDirection(a,r.up,r.up),this.interaction=new P(r,60,(()=>{this.animationFrameId=requestAnimationFrame(this.render),this.onInteraction({pov:this.interaction.pov.clone(),fov:this.interaction.fov})})),this.onInteraction=n,this.gl=this.canvas.context,this.programInfo=o.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=o.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_matrix:e.m4.identity(),u_mix:0,u_texture_back:o.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:o.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1})},this.render=this.render.bind(this)}destroy(){this.interaction.destroy(),this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}show(){this.canvas.show(),this.container.classList.add("ls-viewer-container-vrcube")}hide(){this.canvas.hide(),this.container.classList.remove("ls-viewer-container-vrcube")}async goto(t){return Promise.resolve()}get pov(){return this.interaction.pov}set pov(t){this.interaction.pov.eye.every(((e,i)=>e===t.eye[i]))&&this.interaction.pov.target.every(((e,i)=>e===t.target[i]))&&this.interaction.pov.up.every(((e,i)=>e===t.up[i]))||(this.interaction.pov=t.clone(),this.animationFrameId=requestAnimationFrame(this.render))}get fov(){return d.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=d.degreesToRadians(t),this.animationFrameId=requestAnimationFrame(this.render))}async load(t,e,i){const s=JSON.stringify(t);return s===this.hash?(this.animationFrameId=requestAnimationFrame(this.render),Promise.resolve()):(this.hash=s,this.images=[],this.animationFrameId=requestAnimationFrame(this.render),this.loader.loadVRCubeSnapshot(t).then((t=>{this.images=t,o.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,this.animationFrameId=requestAnimationFrame(this.render))}))})))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}render(){o.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=a.getStandardAspectRatio(t,i),n=t/i,r=this.interaction.fov*(s/n),h=e.m4.inverse(e.m4.perspective(r,n,.5,100)),c=this.interaction.orientedPov,d=e.m4.lookAt(c.eye,c.target,c.up);this.uniforms.u_matrix=e.m4.multiply(d,h),this.gl.useProgram(this.programInfo.program),o.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),o.setUniforms(this.programInfo,this.uniforms),o.drawBufferInfo(this.gl,this.quad),this.uniforms.u_mix<1&&(this.uniforms.u_mix=Math.min(this.uniforms.u_mix+.05,1),this.animationFrameId=requestAnimationFrame(this.render))}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(b.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(b.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(b.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class x{constructor(t,e,i,s){this.isStarted=!1,this.position=t,this.count=e,this.loop=i,this.onMotion=s,this.inertia=new E(this.motion.bind(this)),this.initPosition=this.position,this.startPosition=0,this.startPoint=new w(0,0),this.startSize={width:0,height:0}}destroy(){this.inertia.destroy()}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=d.accelerate(e.x,1.3)/this.startSize.width*(this.count/4);let s=this.startPosition-Math.round(i);s=this.loop?d.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 L{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.interaction=new x(0,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:this.interaction.position})})),this.onInteraction=s}destroy(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}show(){this.canvas.show(!1),this.container.classList.add("ls-viewer-container-vrobject")}hide(){this.canvas.hide(!1),this.container.classList.remove("ls-viewer-container-vrobject")}async goto(t){return new Promise((e=>{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),this.animationFrameId=requestAnimationFrame(s)}};this.animationFrameId=requestAnimationFrame(s)}))}set initPosition(t){this.interaction.initPosition=t}get position(){return this.interaction.position}set position(t){this.interaction.position!==t&&(this.interaction.loop?this.interaction.position=d.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((s=>{const n=s.length;return this.images=new Array(n),this.interaction.count=n,this.interaction.loop=!!t.view.loop,e&&this.interaction.reset(),s.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,i,.05)}))})),s[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(b.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(b.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(b.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(b.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}var A,S,T,F;!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{-webkit-box-flex:1;display:-webkit-box;display:-ms-flexbox;display:flex;-ms-flex:1 0 auto;flex:1 0 auto;overflow:hidden;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.ls-viewer-container-image,.ls-viewer-container-video{cursor:default;pointer-events:none}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{opacity:0;position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");exports.WRAPIv2=void 0,A=exports.WRAPIv2||(exports.WRAPIv2={}),(S=A.SunShadowQualityMode||(A.SunShadowQualityMode={})).VeryLow="veryLow",S.Low="low",S.Medium="medium",S.Fine="fine",S.Ultra="ultra",(T=A.SunShadowSmoothnessMode||(A.SunShadowSmoothnessMode={})).None="none",T.Weak="weak",T.Normal="normal",T.Fine="fine",T.UltraFine="ultraFine",T.Max="max",(F=A.SunUseCaseMode||(A.SunUseCaseMode={})).Manual="manual",F.ExtractedFromEnv="extractedFromEnv",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=Object.assign({server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{}},e),this.options.events=Object.assign({onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{}},e.events),this.options.events.onLoadError=n.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 h,this.container.appendChild(this.canvas2D.element),this.canvas3D=new c,this.container.appendChild(this.canvas3D.element),this.video=new v,this.container.appendChild(this.video.element),this.loader=new u(this.options.server,this.options.api,this),this.resolution=new r(0,0),this.parameters={width:0,height:0,antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.widgetImage=new g(t,this.canvas2D,this.loader),this.widgetVideo=new p(t,this.video,this.loader),this.widgetVRCube=new I(t,this.canvas3D,this.loader,this.onVrcubeInteraction),this.widgetVRObject=new L(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=n.default(this.loadWidget,10),this.onResize=n.default(this.onResize,250)}destroy(){this.canvas2D.destroy(),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mouseenter",this.onMouseEnter),this.container.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("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(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(this.view.mode,i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>(this.scene=Array.isArray(t)?[...t]:[t],this.loadWidget(!1,!(e&&e.animation))))),i.catch((t=>{this.onLoadError(t)})),i}async setEncoder(t){this.encoder=Object.assign({},t);let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}setParameters(t){this.parameters=Object.assign({},t),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height;let e=Promise.resolve();return e=e.then((()=>this.loadWidget(!1,!0))),e.catch((t=>{this.onLoadError(t)})),e}async setView(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&(i=i.then((()=>this.viewWidget.goto(e.fromPosition)))),(null==e?void 0:e.animation)&&(i=i.then((()=>this.widgetVideo.play()))),i=i.then((()=>{let i=!0;return this.view=Object.assign({},t),this.view&&this.viewWidget instanceof L&&void 0!==(null==e?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){var e;const i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return(null===(e=i.view)||void 0===e?void 0:e.background)||(i.view.background="product"),this.widgetVideo.load(i)}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(){var t;switch(null===(t=this.view)||void 0===t?void 0:t.mode){case"image":default:return this.widgetImage;case"video":return this.widgetVideo;case"vrcube":return this.widgetVRCube;case"vrobject":return this.widgetVRObject}}checkResize(){if(this.isDestroyed)return;const t=this.container.clientWidth,e=this.container.clientHeight;t===this.containerWidth&&e===this.containerHeight||(this.containerWidth=t,this.containerHeight=e,this.onResize()),this.isDestroyed||requestAnimationFrame(this.checkResize)}onMouseDown(t){this.widget.onMouseDown(t)}onMouseEnter(t){this.widget.onMouseEnter(t)}onMouseMove(t){this.widget.onMouseMove(t)}onMouseUp(t){this.widget.onMouseUp(t)}onTouchStart(t){this.widget.onTouchStart(t)}onTouchMove(t){this.widget.onTouchMove(t)}onTouchEnd(t){this.widget.onTouchEnd(t)}onDeviceOrientation(t){this.widget.onDeviceOrientation(t)}onResize(){const t=window.devicePixelRatio,e=this.container.clientWidth*t,i=this.container.clientHeight*t;this.resolution=a.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=g,exports.WidgetVRCube=I,exports.WidgetVRObject=L,exports.WidgetVideo=p; | ||
//# sourceMappingURL=index.js.map |
@@ -9,2 +9,3 @@ import { Point } from './Point'; | ||
constructor(onMotion: (point: Point) => void); | ||
destroy(): void; | ||
track(point: Point): void; | ||
@@ -11,0 +12,0 @@ start(): void; |
@@ -18,2 +18,3 @@ import { Point } from './Point'; | ||
constructor(pov: PointOfView, fov: number, onMotion: () => void); | ||
destroy(): void; | ||
get orientedPov(): PointOfView; | ||
@@ -20,0 +21,0 @@ reset(): void; |
@@ -15,2 +15,3 @@ import { Point } from './Point'; | ||
constructor(position: number, count: number, loop: boolean, onMotion: () => void); | ||
destroy(): void; | ||
reset(): void; | ||
@@ -17,0 +18,0 @@ start(point: Point, size: Size): void; |
import { Snapshot } from './Snapshot'; | ||
export interface Widget { | ||
destroy(): void; | ||
show(): void; | ||
@@ -4,0 +5,0 @@ hide(): void; |
@@ -12,2 +12,3 @@ import { Canvas2D } from './Canvas2D'; | ||
constructor(container: HTMLElement, canvas: Canvas2D, loader: Loader); | ||
destroy(): void; | ||
show(): void; | ||
@@ -14,0 +15,0 @@ hide(): void; |
@@ -11,2 +11,3 @@ import { Loader } from './Loader'; | ||
constructor(container: HTMLElement, video: Video, loader: Loader); | ||
destroy(): void; | ||
show(): void; | ||
@@ -13,0 +14,0 @@ hide(): void; |
@@ -18,3 +18,5 @@ import { Canvas3D } from './Canvas3D'; | ||
private hash?; | ||
private animationFrameId?; | ||
constructor(container: HTMLElement, canvas: Canvas3D, loader: Loader, onInteraction: (...args: any[]) => void); | ||
destroy(): void; | ||
show(): void; | ||
@@ -21,0 +23,0 @@ hide(): void; |
@@ -13,3 +13,5 @@ import { Canvas2D } from './Canvas2D'; | ||
private hash?; | ||
private animationFrameId?; | ||
constructor(container: HTMLElement, canvas: Canvas2D, loader: Loader, onInteraction: (...args: any[]) => void); | ||
destroy(): void; | ||
show(): void; | ||
@@ -16,0 +18,0 @@ hide(): void; |
{ | ||
"name": "@lumiscaphe/viewer", | ||
"version": "3.0.9", | ||
"version": "3.0.10", | ||
"description": "Lumiscaphe 3D Viewer", | ||
@@ -23,6 +23,6 @@ "main": "dist/index.js", | ||
"@types/debounce-promise": "~3.1.3", | ||
"@typescript-eslint/eslint-plugin": "~5.4.0", | ||
"@typescript-eslint/parser": "~5.4.0", | ||
"@typescript-eslint/eslint-plugin": "~5.8.0", | ||
"@typescript-eslint/parser": "~5.8.0", | ||
"cross-env": "~7.0.0", | ||
"eslint": "~8.3.0", | ||
"eslint": "~8.5.0", | ||
"husky": "~7.0.0", | ||
@@ -32,3 +32,3 @@ "postcss": "~8.4.0", | ||
"postcss-reporter": "~7.0.0", | ||
"rollup": "~2.60.0", | ||
"rollup": "~2.62.0", | ||
"rollup-plugin-commonjs": "~10.1.0", | ||
@@ -41,3 +41,3 @@ "rollup-plugin-copy": "~3.4.0", | ||
"rollup-plugin-terser": "~7.0.0", | ||
"stylelint": "~14.1.0", | ||
"stylelint": "~14.2.0", | ||
"stylelint-config-standard": "~24.0.0", | ||
@@ -44,0 +44,0 @@ "typescript": "~4.5.0", |
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
386786
1785