Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lumiscaphe/viewer

Package Overview
Dependencies
Maintainers
4
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lumiscaphe/viewer - npm Package Compare versions

Comparing version 4.1.9 to 4.1.10

2

dist/index.es.js

@@ -1,2 +0,2 @@

import t from"debounce-promise";import*as e from"twgl.js";import{v3 as i,m4 as s}from"twgl.js";import n from"regression";class o{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 contains(t,e){return e.x>=0&&e.x<t.width&&e.y>=0&&e.y<t.height}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 project(t,e,i,s){const n=a.fit(t,e,i),o=n.width/t.width,r=n.height/t.height;return{x:Math.round(n.left+s.x*o),y:Math.round(n.top+s.y*r)}}static unproject(t,e,i,s){const n=a.fit(t,e,i),o=n.width/t.width,r=n.height/t.height;return{x:Math.round((s.x-n.left)/o),y:Math.round((s.y-n.top)/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 o(0,0);const i=a.getStandardAspectRatio(t,e);if(t<e){const s=a.getStandardQuality(Math.max(e*i,t));return new o(Math.round(s),Math.round(s/i))}const s=a.getStandardQuality(Math.max(t/i,e));return new o(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(t){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.element.width=0,this.element.height=0,this.context=this.element.getContext("2d"),this.backCanvas=document.createElement("canvas"),this.backContext=this.backCanvas.getContext("2d"),this.fit=t,this.pixelRatio=1}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"}get resolution(){return new o(this.element.width/this.pixelRatio,this.element.height/this.pixelRatio)}resize(t,e,i){this.element.width=t*i,this.element.height=e*i,this.element.style.width=`${t}px`,this.element.style.height=`${e}px`,this.backCanvas.width=t*i,this.backCanvas.height=e*i,this.pixelRatio=i}draw(t,e,i){if(!t)return;this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=void 0);const s=a.fit(new o(t.width,t.height),new o(this.element.width,this.element.height),this.fit);e?(this.backContext.drawImage(this.element,0,0),this.context.globalAlpha=0,this.fadeLoop(t,i||0)):(this.context.globalAlpha=1,this.context.drawImage(t,s.left,s.top,s.width,s.height)),this.image=t}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),s=a.fit(new o(t.width,t.height),new o(this.element.width,this.element.height),this.fit);this.context.clearRect(0,0,this.element.width,this.element.height),this.context.globalAlpha=1,this.context.drawImage(this.backCanvas,0,0),this.context.globalAlpha=i,this.context.drawImage(t,s.left,s.top,s.width,s.height),this.requestAnimationId=requestAnimationFrame((()=>{this.fadeLoop(t,e)}))}}class h{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.element.width=0,this.element.height=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(t,e,i){this.element.width=t*i,this.element.height=e*i,this.element.style.width=`${t}px`,this.element.style.height=`${e}px`}}class c{static accelerate(t,e){const i=e||1.5;return Math.abs(t)**i*(t>0?1:-1)}static clamp(t,e,i){return Math.max(Math.min(t,i),e)}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)}static perspectiveWithFovX(t,e,i,s,n){const o=Math.tan(t/2),a=o/e;return this.perspectiveWithLeft(-o,o,-a,a,i,s,n)}static perspectiveWithFovY(t,e,i,s,n){const o=i*Math.tan(t/2),a=o*e;return this.perspectiveWithLeft(-a,a,-o,o,i,s,n)}static perspectiveWithLeft(t,e,i,s,n,o,a){const r=e+t,h=e-t,c=s+i,d=s-i,l=o-n;return(a=a||new Float32Array(16))[0]=2*n/h,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=2*n/d,a[6]=0,a[7]=0,a[8]=r/h,a[9]=c/d,a[10]=-o/l,a[11]=-1,a[12]=0,a[13]=0,a[14]=-o*n/l,a[15]=0,a}}class d{static initCubeFace(t,e,s){let n=[0,0,0];const o=i.subtract(e,t),a=i.mulScalar([0,1,0],i.length(o)),r=i.mulScalar(i.normalize(i.cross(o,a)),i.length(o)),h=i.mulScalar(i.normalize(i.cross(a,r)),i.length(o));switch(s){case"front":e=i.add(t,h),n=i.normalize(a);break;case"right":e=i.add(t,r),n=i.normalize(a);break;case"back":e=i.subtract(t,h),n=i.normalize(a);break;case"left":e=i.subtract(t,r),n=i.normalize(a);break;case"up":e=i.add(t,a),n=i.normalize(i.mulScalar(h,-1));break;case"down":e=i.subtract(t,a),n=i.normalize(h)}return new d(e,t,n)}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 d(i.copy(this.target),i.copy(this.eye),i.copy(this.up))}}d.default=new d([0,0,0],[2,2,2],[0,1,0]);class l{constructor(t){this.target=t.target;const e=i.normalize(i.subtract(t.eye,t.target)),s=i.dot(e,[1,0,0]),n=i.dot(e,[0,1,0]),o=i.dot(e,[0,0,1]);this.longitude=Math.atan2(s,o),this.latitude=Math.atan2(n,Math.sqrt(s*s+o*o)),i.dot(t.up,[0,1,0])<0&&(this.longitude=Math.PI+this.longitude,this.latitude=Math.PI-this.latitude),this.distance=i.length(i.subtract(t.target,t.eye))}get vector(){const t=Math.cos(this.latitude)*this.distance,e=Math.sin(this.latitude)*this.distance;return[Math.cos(this.longitude)*t,e,Math.sin(this.longitude)*t]}pointOfView(t){const e=s.rotationY(this.longitude),n=s.rotationX(-this.latitude),o=s.rotationZ(0),a=s.multiply(e,s.multiply(n,o));let r=[0,0,-1];r=s.transformPoint(a,r);let h=[0,1,0];h=s.transformPoint(a,h);const c=i.subtract(t,i.mulScalar(r,this.distance));return new d(t,c,h)}}class m{constructor(){}async animation(t){return t.scene}async database(t){throw new Error("Unavailable")}async image(t){return t.scene}async video(t){return t.scene}async vrCube(t){return t.scene}async vrObject(t){return t.scene}}class u{constructor(t){this.xmlDoc=t}get id(){var t;return null===(t=this.xmlDoc.getElementsByTagName("Database")[0])||void 0===t?void 0:t.getAttribute("id")}getCameraId(t,e){var i,s;return e?null===(i=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${e}"] Camera[name="${t}"]`))||void 0===i?void 0:i.getAttribute("id"):null===(s=this.xmlDoc.querySelector(`RootCameraGroup Camera[name="${t}"]`))||void 0===s?void 0:s.getAttribute("id")}getCameraById(t,e){let i;return i=t&&e?this.xmlDoc.querySelector(`RootCameraGroup Group[id="${e}"] Camera[id="${t}"]`):this.xmlDoc.querySelector(`RootCameraGroup Camera[id="${t}"]`),i?this.mapElementToCamera(i):null}getCameraByName(t,e){let i;return i=e&&t?this.xmlDoc.querySelector(`RootCameraGroup Group[name="${e}"] Camera[name="${t}"]`):this.xmlDoc.querySelector(`RootCameraGroup Camera[name="${t}"]`),i?this.mapElementToCamera(i):null}getCameraGroupId(t){var e;return null===(e=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${t}"]`))||void 0===e?void 0:e.getAttribute("id")}getCameraGroupById(t){const e=this.xmlDoc.querySelector(`RootCameraGroup Group[id="${t}"]`);return e?this.mapElementToCameraGroup(e):null}getCameraGroupByName(t){const e=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${t}"]`);return e?this.mapElementToCameraGroup(e):null}mapElementToCamera(t){return{id:t.getAttribute("id"),name:t.getAttribute("name"),pointOfView:new d([parseFloat(t.querySelector("PointOfView Target").getAttribute("x")),parseFloat(t.querySelector("PointOfView Target").getAttribute("y")),parseFloat(t.querySelector("PointOfView Target").getAttribute("z"))],[parseFloat(t.querySelector("PointOfView Eye").getAttribute("x")),parseFloat(t.querySelector("PointOfView Eye").getAttribute("y")),parseFloat(t.querySelector("PointOfView Eye").getAttribute("z"))],[parseFloat(t.querySelector("PointOfView Up").getAttribute("x")),parseFloat(t.querySelector("PointOfView Up").getAttribute("y")),parseFloat(t.querySelector("PointOfView Up").getAttribute("z"))])}}mapElementToCameraGroup(t){return{id:t.getAttribute("id"),name:t.getAttribute("name"),cameras:[...t.querySelectorAll("Camera")].map((t=>this.mapElementToCamera(t)))}}}class p{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 s=t.scene,n=s.length>1?s.find((t=>t.accessory)):null,o=s.length>1?s.find((t=>t.decor)):null,a=s.find((t=>t!==n&&t!==o));return{databaseId:a.database,configuration:null==a?void 0:a.configuration,animations:null===(e=null==a?void 0:a.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(/&amp;/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({},p.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}),p.renderParameters(t)),p.encoderParameters(t)),i=p.buildQuery(e);return p.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async database(t){return fetch(`${this.server}/Database?databaseId=${t}`).then((t=>t.text())).then((t=>{const e=(new DOMParser).parseFromString(t,"application/xml");return new u(e)}))}async image(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},p.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),p.renderParameters(t)),p.encoderParameters(t)),i=p.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},p.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}),p.renderParameters(t)),p.encoderParameters(t)),i=p.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},p.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),p.renderParameters(t)),p.encoderParameters(t));e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=p.buildQuery(e);return p.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},p.sceneParameters(t)),{bookmarkSet:t.view.camera}),p.renderParameters(t)),p.encoderParameters(t)),i=p.buildQuery(e);return p.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}p.xmlRegex=/directUrl="([^"]*)"/g,"function"==typeof SuppressedError&&SuppressedError;class v{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const e=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 fetchFrame(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.url))}static async fetchFrameArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.map((t=>t.url))))}static async fetchHotspots(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json()))}static async fetchHotspotsArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json()))}static async fetchPick(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t[0]))}async database(t){return fetch(`${this.server}/Database?databaseId=${t}`).then((t=>t.text())).then((t=>{const e=(new DOMParser).parseFromString(t,"application/xml");return new u(e)}))}async image(t){const e={scene:v.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetchFrame(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:v.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return e.renderParameters.width=Math.max(e.renderParameters.width,e.renderParameters.height),e.renderParameters.height=Math.max(e.renderParameters.width,e.renderParameters.height),v.fetchFrameArray(`${this.server}/Snapshot`,e)}async vrObject(t){let e;e=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const i={scene:v.scene(t),mode:e,renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetchFrameArray(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:v.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetchFrameArray(`${this.server}/Snapshot`,e)}async imageHotspots(t,e){const i=Object.assign({scene:v.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:v.renderParameters(t)},this.hotspotsBody(e));return await v.fetchHotspots(`${this.server}/Hotspot`,i)}async imagePick(t,e){const i={scene:v.scene(t),camera:t.view.camera,renderParameters:v.renderParameters(t),positions:[e]};return await v.fetchPick(`${this.server}/Pick`,i)}async vrCubeHotspots(t,e){const i=Object.assign({scene:v.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:v.renderParameters(t)},this.hotspotsBody(e));return i.renderParameters.width=Math.max(i.renderParameters.width,i.renderParameters.height),i.renderParameters.height=Math.max(i.renderParameters.width,i.renderParameters.height),await v.fetchHotspotsArray(`${this.server}/Hotspot`,i)}async vrObjectHotspots(t,e){let i;i=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const s=Object.assign({scene:v.scene(t),mode:i,renderParameters:v.renderParameters(t)},this.hotspotsBody(e));return await v.fetchHotspotsArray(`${this.server}/Hotspot`,s)}hotspotsBody(t){return{positions:t.every((t=>"string"!=typeof t))?t:void 0,tags:t.every((t=>"string"==typeof t))?t:void 0}}}class g{constructor(t,e,i){switch(e){case"static":this.webrender=new m;break;case"v1":default:this.webrender=new p(t),this.webrenderV2=new v(t);break;case"v2":this.webrender=new v(t),this.webrenderV2=new v(t)}this.delegate=i,this.loadingId=0,this.loaded=0,this.total=0,this.databases=[],this.onLoadStart=i&&i.onLoadStart?i.onLoadStart:()=>{},this.onLoadProgress=i&&i.onLoadProgress?i.onLoadProgress:()=>{},this.onLoadEnd=i&&i.onLoadEnd?i.onLoadEnd:()=>{}}get progress(){return this.total?this.loaded/this.total:0}async loadImageSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.image(t).then((t=>this.loadImage(t,e))).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVideoSnapshot(t,e){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:i}=this;return this.webrender.video(e).then((s=>this.loadVideo(t,s,!!e.view.loop,i))).then((()=>(this.onLoadEnd(this.progress),t)))}async loadVRCubeSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.vrCube(t).then((t=>{this.total=t.length;const i=t.map((t=>this.loadImage(t,e)));return Promise.all(i)})).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVRObjectSnapshot(t,e){var i;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:s}=this;return t.view.animation?"mp4"===(null===(i=t.encoder)||void 0===i?void 0:i.format)?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,s))):this.webrender.animation(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s))):this.webrender.vrObject(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s)))}async loadImage(t,e){const i=new Image;i.crossOrigin="file:"!==location.protocol||g.isValidHttpUrl(t)?"anonymous":null;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,a=t.length;i<a;i+=1){const r=Math.ceil(i/2)*(i%2==0?1:-1),h=e?c.mod(o+r,a):i;n[h]=this.loadImage(t[h],s)}return Promise.all(n).then((()=>this.onLoadEnd(this.progress))).catch((()=>{})),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(((a,r)=>{const h=()=>{if(n!==this.loadingId)return;if(o!==s)return void(o+=1);t.removeEventListener("seeked",h);const r=document.createElement("canvas");r.width=t.videoWidth,r.height=t.videoHeight;r.getContext("2d").drawImage(t,0,0);const c=new Image;c.src=r.toDataURL(),a(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&&r(t)}),{once:!0})}))}loadVideoFrames(t,e,i,s){this.total=e;const n=new Array(e),o=document.createElement("video");for(let t=0,a=e;t<a;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))).catch((()=>{})),n}async loadImageHotspots(t,e){return this.webrenderV2?await this.webrenderV2.imageHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRCubeHotspots(t,e){return this.webrenderV2?await this.webrenderV2.vrCubeHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRObjectHotspots(t,e){return this.webrenderV2?await this.webrenderV2.vrObjectHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadImagePick(t,e){return this.webrenderV2?await this.webrenderV2.imagePick(await this.convert(t),e):Promise.reject(new Error("Picking only available with api V2"))}async loadVRObjectPick(t,e,i,s){return this.webrenderV2?await this.webrenderV2.imagePick(await this.vrObjectFrameSnapshot(t,i,s),e):Promise.reject(new Error("Picking only available with api V2"))}async loadVRCubePick(t,e,i){return this.webrenderV2?await this.webrenderV2.imagePick(await this.vrCubeFrameSnapshot(t,i),e):Promise.reject(new Error("Picking only available with api V2"))}async convert(t){var e;if(!this.webrenderV2)return t;if(this.webrender instanceof v)return t;if(!t.view.camera)return t;const i=t.scene.find((t=>!t.decor&&!t.accessory));if(!i)return t;let s=this.databases.find((t=>t.id===i.database));s&&s.xmlDoc||(s=await this.webrender.database(i.database),this.databases.push(s));const n=null===(e=t.view.camera)||void 0===e?void 0:e.split("/"),o=2===n.length?n[0]:void 0,a=2===n.length?n[1]:n[0],r=s.getCameraId(a,o);if(r)return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:r})});{const e=s.getCameraGroupId(a);return e?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{cameraGroup:e})}):t}}async vrObjectFrameSnapshot(t,e,i){if(!this.webrenderV2)return t;const s=t.scene.find((t=>!t.decor&&!t.accessory));if(!s)return t;let n=this.databases.find((t=>t.id===s.database));if(n||(n=await this.webrender.database(s.database),this.databases.push(n)),this.webrender instanceof p){if(!t.view.camera)return t;const i=n.getCameraGroupId(t.view.camera);if(!i)return t;const s=n.getCameraGroupById(i);if(!s)return t;const o=s.cameras[e];return o?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:o.id})}):t}if(this.webrender instanceof v){if(t.view.camera){const s=n.getCameraById(t.view.camera);if(!s)return t;const o=new l(s.pointOfView),a=2*Math.PI/i;o.longitude+=e*a%(2*Math.PI);const r=o.pointOfView(s.pointOfView.target);return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:{id:s.id,pov:{target:{x:r.target[0],y:r.target[1],z:r.target[2]},eye:{x:r.eye[0],y:r.eye[1],z:r.eye[2]},up:{x:r.up[0],y:r.up[1],z:r.up[2]}}}})})}if(t.view.cameraGroup){const i=n.getCameraGroupById(t.view.cameraGroup);if(!i)return t;const s=i.cameras[e];return s?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:s.id})}):t}return t}return t}async vrCubeFrameSnapshot(t,e){const i=t.scene.find((t=>!t.decor&&!t.accessory));if(!i)return t;let s,n=this.databases.find((t=>t.id===i.database));if(n||(n=await this.webrender.database(i.database),this.databases.push(n)),!t.view.camera)return t;if(this.webrender instanceof p){const e=t.view.camera.split("/"),i=2===e.length?e[0]:void 0,o=2===e.length?e[1]:e[0];s=n.getCameraId(o,i)}else this.webrender instanceof v&&(s=t.view.camera);if(!s)return t;const o=n.getCameraById(s);if(!o)return t;const a=d.initCubeFace(o.pointOfView.eye,o.pointOfView.target,e);return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:{id:o.id,pov:{target:{x:a.target[0],y:a.target[1],z:a.target[2]},eye:{x:a.eye[0],y:a.eye[1],z:a.eye[2]},up:{x:a.up[0],y:a.up[1],z:a.up[2]}},lens:{fov:90}}}),parameters:Object.assign(Object.assign({},t.parameters),{width:Math.max(t.parameters.width,t.parameters.height),height:Math.max(t.parameters.width,t.parameters.height)})})}onLoadStart(t){this.delegate&&this.delegate.onLoadStart(t)}onLoadProgress(t){this.delegate&&this.delegate.onLoadProgress(t)}onLoadEnd(t){this.delegate&&this.delegate.onLoadEnd(t)}static isValidHttpUrl(t){let e;try{e=new URL(t)}catch(t){return!1}return"http:"===e.protocol||"https:"===e.protocol}}class w{constructor(){this.element=document.createElement("video"),this.element.classList.add("ls-viewer-video"),this.element.style.opacity="0",this.element.width=0,this.element.height=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 o(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 b{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i,this.hotspotList=[]}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 load(t,e,i,s){let n=Promise.resolve();const o=JSON.stringify(t);n=o===this.snapshotHash&&this.image?n.then((()=>this.canvas.draw(this.image,s,.05))):n.then((()=>this.loader.loadImageSnapshot(t).then((t=>{this.canvas.draw(t,s,.05),this.image=t}))));const a=JSON.stringify(e);return o===this.snapshotHash&&a===this.hotspotsHash||(e.length?n=n.then((()=>this.loader.loadImageHotspots(t,e).then((t=>{this.hotspotList=t})))):this.hotspotList=[]),this.hotspotsHash=a,this.snapshotHash=o,n}async pick(t,e){const i=new o(t.parameters.width,t.parameters.height),s=a.unproject(i,this.canvas.resolution,this.canvas.fit,e);return this.loader.loadImagePick(t,s)}hotspots(t){return this.hotspotList.map((e=>Object.assign(Object.assign({},e),{position2D:a.project(t,this.canvas.resolution,this.canvas.fit,e.position2D)}))).map((t=>Object.assign(Object.assign({},t),{visibility:a.contains(this.canvas.resolution,t.position2D)?t.visibility:"OutOfFrustum"})))}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 y{constructor(t,e){this.x=t,this.y=e}clone(){return new y(this.x,this.y)}}class f{static pointFromMouseEvent(t){return new y(t.screenX,t.screenY)}static pointFromTouchEvent(t){const e=t.targetTouches[0]||t.changedTouches[0];return new y(e.screenX,e.screenY)}}class P{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 M{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class x{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new y(0,0),this.velocity=new y(0,0),this.loop=this.loop.bind(this)}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 M(t.x,t.y,e)),this.lastPoint=t}start(){if(0===this.points.length)return;const t=this.points[0],e=this.points[this.points.length-1],i=e.x-t.x,s=e.y-t.y,n=e.time-t.time;this.velocity=new y(0===n?0:i/(n/15),0===n?0:s/(n/15)),this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0),this.animationFrameId=requestAnimationFrame(this.loop)}stop(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0),this.points=[]}loop(){if(Math.abs(this.velocity.x)<1&&Math.abs(this.velocity.y)<1)return this.animationFrameId=void 0,void(this.points=[]);this.lastPoint.x+=this.velocity.x,this.lastPoint.y+=this.velocity.y,this.velocity.x*=.9,this.velocity.y*=.9,this.onMotion(this.lastPoint.clone()),this.animationFrameId=requestAnimationFrame(this.loop)}}class O{constructor(t,e,i){this.isStarted=!1,this.pov=t,this.fov=c.degreesToRadians(e),this.orientationMatrix=s.identity(),this.inertia=new x(this.motion.bind(this)),this.onMotion=i,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=c.degreesToRadians(window.orientation)||0,this.startPov=new d([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new y(0,0)}destroy(){this.inertia.destroy()}get orientedPov(){const t=i.normalize(i.cross(this.pov.up,this.pov.target)),e=new P(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),a=this.pov.eye,r=s.transformDirection(n,this.pov.up);return new d(o,a,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 e={x:t.x-this.previousPoint.x,y:t.y-this.previousPoint.y},n=c.accelerate(e.x,1.3)/this.startSize.width*.2*Math.PI*1.5,o=c.accelerate(e.y,1.3)/this.startSize.height*.2*Math.PI,a=s.multiply(s.rotationY(n),s.rotationX(-o)),r=i.normalize(i.cross(this.pov.up,this.pov.target)),h=new P(r,[0,1,0],this.pov.eye),d=s.identity();s.multiply(d,h.localToGlobalMatrix,d),s.multiply(d,a,d),s.multiply(d,h.globalToLocalMatrix,d);const l=s.transformPoint(d,this.pov.target),m=s.transformDirection(d,this.pov.up);i.cross(m,[0,0,1])[0]>=0&&(this.pov.target=l,this.pov.up=m),this.previousPoint=t,this.onMotion()}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}orientation(t,e,i){const n=c.degreesToRadians(window.orientation)||0,o=c.degreesToRadians(t),a=c.degreesToRadians(-e),r=c.degreesToRadians(-i),h=s.rotationX(c.degreesToRadians(90));s.rotateZ(h,this.initOrientation,h),s.rotateZ(h,o,h),s.rotateX(h,a,h),s.rotateY(h,r,h),s.rotateZ(h,-n,h),this.orientationMatrix=h,this.onMotion()}}class E{constructor(t,i,n,o){this.container=t,this.canvas=i,this.loader=n,this.images=[],this.hotspotsList=[[]];const a=new d([0,0,1],[0,0,0],[0,1,0]),r=s.rotationX(c.degreesToRadians(15));s.transformDirection(r,a.target,a.target),s.transformDirection(r,a.up,a.up),this.interaction=new O(a,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_mvpi;varying vec3 direction;void main(){direction=(u_mvpi*position).xyz;gl_Position=position;}\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_mvpi: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")}get pov(){return this.interaction.pov}set pov(t){this.interaction.pov.eye.every(((e,i)=>e===t.eye[i]))&&this.interaction.pov.target.every(((e,i)=>e===t.target[i]))&&this.interaction.pov.up.every(((e,i)=>e===t.up[i]))||(this.interaction.pov=t.clone(),this.animationFrameId=requestAnimationFrame(this.render))}get fov(){return c.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=c.degreesToRadians(t),this.animationFrameId=requestAnimationFrame(this.render))}async load(t,i,s,n){let o=Promise.resolve();{const e=this.gl.getExtension("WEBGL_debug_renderer_info");e&&"MacIntel"===navigator.platform&&navigator.userAgent.includes("Chrome")&&this.gl.getParameter(e.UNMASKED_RENDERER_WEBGL).includes("OpenGL")&&(t.parameters.width=Math.min(t.parameters.width,1812),t.parameters.height=Math.min(t.parameters.height,1812))}const a=JSON.stringify(t);a===this.snapshotHash?o=o.then((()=>(this.animationFrameId=requestAnimationFrame(this.render),Promise.resolve()))):(this.images=[],this.animationFrameId=requestAnimationFrame(this.render),o=o.then((()=>this.loader.loadVRCubeSnapshot(t).then((t=>{this.images=t,e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,min:this.gl.LINEAR_MIPMAP_LINEAR,minMag:this.gl.LINEAR,cubeFaceOrder:[this.gl.TEXTURE_CUBE_MAP_POSITIVE_Z,this.gl.TEXTURE_CUBE_MAP_POSITIVE_X,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_X,this.gl.TEXTURE_CUBE_MAP_POSITIVE_Y,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_Y],src:t},((t,e)=>{t||(s&&this.interaction.reset(),this.uniforms.u_mix=n?0:1,this.uniforms.u_texture_back=this.uniforms.u_texture,this.uniforms.u_texture=e,this.animationFrameId=requestAnimationFrame(this.render))}))})))));const r=JSON.stringify(i);return a===this.snapshotHash&&r===this.hotspotsHash||(i.length?o=o.then((()=>this.loader.loadVRCubeHotspots(t,i).then((t=>{this.hotspotsList=t})))):this.hotspotsList=[[]]),this.hotspotsHash=r,this.snapshotHash=a,o}async pick(t,e){const n=this.canvas.element.clientWidth,o=this.canvas.element.clientHeight,a=[2*e.x/n-1,2*(o-e.y)/o-1,0],r=this.modelViewProjectionMatrix,h=s.inverse(r),c=i.normalize(s.transformPoint(h,a)),d=Math.max(Math.abs(c[0]),Math.abs(c[1]),Math.abs(c[2]));let l="";l=Math.abs(c[0])===d?c[0]>0?"XPOS":"XNEG":Math.abs(c[1])===d?c[1]>0?"YPOS":"YNEG":c[2]>0?"ZPOS":"ZNEG";let m=0,u=0,p="";switch(l){case"XPOS":m=(-c[2]/Math.abs(c[0])+1)/2,u=(-c[1]/Math.abs(c[0])+1)/2,p="right";break;case"XNEG":m=(c[2]/Math.abs(c[0])+1)/2,u=(-c[1]/Math.abs(c[0])+1)/2,p="left";break;case"YPOS":m=(c[0]/Math.abs(c[1])+1)/2,u=(c[2]/Math.abs(c[1])+1)/2,p="up";break;case"YNEG":m=(c[0]/Math.abs(c[1])+1)/2,u=(-c[2]/Math.abs(c[1])+1)/2,p="down";break;case"ZPOS":m=(c[0]/Math.abs(c[2])+1)/2,u=(-c[1]/Math.abs(c[2])+1)/2,p="front";break;case"ZNEG":m=(-c[0]/Math.abs(c[2])+1)/2,u=(-c[1]/Math.abs(c[2])+1)/2,p="back"}const v={x:Math.round(m*Math.max(t.parameters.width,t.parameters.height)),y:Math.round(u*Math.max(t.parameters.width,t.parameters.height))};return this.loader.loadVRCubePick(t,v,p)}hotspots(){var t,e;const n=[];if(0===this.hotspotsList.length)return[];const r=null!==(e=null===(t=this.hotspotsList[0])||void 0===t?void 0:t.length)&&void 0!==e?e:0,h=this.modelViewProjectionMatrix;for(let t=0;t<r;t++){const e=this.hotspotsList.findIndex((e=>"OutOfFrustum"!==e[t].visibility));if(-1===e)continue;const r=Object.assign({},this.hotspotsList[e][t]),c=r.position2D.x/this.images[0].width,d=r.position2D.y/this.images[0].height;let l=0,m=0,u=0;switch(e){case 0:this.pov.target[2]<0&&(r.visibility="OutOfFrustum"),l=2*c-1,m=1-2*d,u=1;break;case 1:this.pov.target[0]>0&&(r.visibility="OutOfFrustum"),l=1,m=1-2*d,u=1-2*c;break;case 2:this.pov.target[2]>0&&(r.visibility="OutOfFrustum"),l=1-2*c,m=1-2*d,u=-1;break;case 3:this.pov.target[0]<0&&(r.visibility="OutOfFrustum"),l=-1,m=1-2*d,u=2*c-1;break;case 4:this.pov.target[1]<0&&(r.visibility="OutOfFrustum"),l=2*c-1,m=1,u=2*d-1;break;case 5:this.pov.target[1]>0&&(r.visibility="OutOfFrustum"),l=2*c-1,m=-1,u=1-2*d}const p=i.normalize([l,m,u]),v=s.transformPoint(h,p),g=this.canvas.element.clientWidth,w=this.canvas.element.clientHeight,b=.5*g*(v[0]+1),y=.5*w*(v[1]+1),f={x:Math.round(b),y:Math.round(w-y)},P=new o(g,w),M=a.contains(P,f)?r.visibility:"OutOfFrustum";n.push(Object.assign(Object.assign({},r),{position2D:f,visibility:M}))}return n}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}get modelViewProjectionMatrix(){const t=this.canvas.element.clientWidth,e=this.canvas.element.clientHeight,i=t>e?t/e:e/t,n=a.getStandardAspectRatio(t,e),o=this.interaction.fov*(n/i),r=s.setAxis(s.identity(),[-1,0,0],0),h=t>e?c.perspectiveWithFovY(o,t/e,.5,100):c.perspectiveWithFovX(o,t/e,.5,100),d=this.interaction.orientedPov,l=s.inverse(s.lookAt(d.eye,d.target,d.up));return s.multiply(s.multiply(h,l),r)}render(){this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.uniforms.u_mvpi=s.inverse(this.modelViewProjectionMatrix),this.gl.useProgram(this.programInfo.program),e.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),e.setUniforms(this.programInfo,this.uniforms),e.drawBufferInfo(this.gl,this.quad),this.uniforms.u_mix<1&&(this.uniforms.u_mix=Math.min(this.uniforms.u_mix+.05,1),this.animationFrameId=requestAnimationFrame(this.render))}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(f.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(f.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class I{constructor(t,e,i,s,n){this.isStarted=!1,this.position=t,this.frames=e,this.rows=i,this.loop=s,this.onMotion=n,this.inertia=new x(this.motion.bind(this)),this.initPosition=this.position,this.startPosition={x:0,y:0},this.startPoint=new y(0,0),this.startSize={width:0,height:0},this.lastPoints=[],this.lastPointsNumber=20}destroy(){this.inertia.destroy()}reset(){this.position=this.initPosition}get positionIndex(){return this.frames*this.position.y+this.position.x}set positionIndex(t){if(this.positionIndex===t)return;const e=this.loop?c.mod(t,this.frames*this.rows):Math.max(0,Math.min(t,this.frames*this.rows));this.position.x=c.mod(e,this.frames),this.position.y=Math.floor(e/this.frames)}start(t,e){this.isStarted=!0,this.startPosition=Object.assign({},this.position),this.startPoint=t,this.startSize=e,this.lastPoints=[],this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t),this.lastPoints.push({x:t.x,y:t.y}),this.lastPoints.splice(0,this.lastPoints.length-this.lastPointsNumber);const e=n.linear(this.lastPoints.map((t=>[t.x,t.y])));if(Math.abs(e.equation[0])<1){const e=c.accelerate(t.x-this.startPoint.x,1.3)/this.startSize.width*(this.frames/4);let i=this.startPosition.x-Math.round(e);i=this.loop?c.mod(i,this.frames):Math.max(0,Math.min(i,this.frames-1)),i!==this.position.x&&(this.position.x=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.x)));Math.max(...this.lastPoints.map((t=>t.x)))-s>25&&(this.startPoint.y=t.y,this.startPosition.y=this.position.y)}else{const e=c.accelerate(t.y-this.startPoint.y,1.7)/this.startSize.height*(this.rows/4);let i=this.startPosition.y+Math.round(e);i=Math.max(0,Math.min(i,this.rows-1)),i!==this.position.y&&(this.position.y=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.y)));Math.max(...this.lastPoints.map((t=>t.y)))-s>25&&(this.startPoint.x=t.x,this.startPosition.x=this.position.x)}}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}}class S{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.frames=24,this.hotspotsList=[[]],this.interaction=new I({x:0,y:0},1,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:this.interaction.positionIndex})})),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.positionIndex;const s=()=>{if(this.interaction.positionIndex===t)e();else{let e=i>t?-1:1;this.interaction.loop&&this.interaction.frames-i+t<Math.abs(t-i)&&(e*=-1),i+=.5*e,this.position=Math.floor(i),this.animationFrameId=requestAnimationFrame(s)}};this.animationFrameId=requestAnimationFrame(s)}))}get position(){return this.interaction.positionIndex}set position(t){this.interaction.positionIndex=t,this.canvas.draw(this.image,!0,.5)}get image(){return this.images[this.interaction.positionIndex]}async load(t,e,i,s){let n=Promise.resolve();i&&this.interaction.reset();const o=JSON.stringify(t);o===this.snapshotHash&&this.image?n=n.then((()=>this.canvas.draw(this.image,s,.05))):(this.images=[],n=n.then((()=>this.loader.loadVRObjectSnapshot(t,this.interaction.positionIndex).then((e=>{const n=e.length;return this.images=new Array(n),this.interaction.frames=t.view.frames||this.frames,this.interaction.rows=n/this.interaction.frames,this.interaction.loop=!!t.view.loop,i&&this.interaction.reset(),e.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,s,.05)})).catch((()=>{}))})),e[this.interaction.positionIndex].then((()=>Promise.resolve()))})))));const a=JSON.stringify(e);return o===this.snapshotHash&&a===this.hotspotsHash||(e.length?n=n.then((()=>this.loader.loadVRObjectHotspots(t,e).then((t=>{this.hotspotsList=t})))):this.hotspotsList=[[]]),this.hotspotsHash=a,this.snapshotHash=o,n}async pick(t,e){const i=new o(t.parameters.width,t.parameters.height),s=a.unproject(i,this.canvas.resolution,this.canvas.fit,e);return this.loader.loadVRObjectPick(t,s,this.position,this.frames)}hotspots(t){return(this.hotspotsList[this.interaction.positionIndex]||[]).map((e=>Object.assign(Object.assign({},e),{position2D:a.project(t,this.canvas.resolution,this.canvas.fit,e.position2D)}))).map((t=>Object.assign(Object.assign({},t),{visibility:a.contains(this.canvas.resolution,t.position2D)?t.visibility:"OutOfFrustum"})))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(f.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(f.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}class L{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 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))}async pick(t,e){return Promise.reject()}hotspots(t){return[]}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}),this.video.element.play().catch(e),this.show()}))}onMouseDown(t){}onMouseMove(t){}onMouseUp(t){}onMouseEnter(t){}onTouchStart(t){}onTouchMove(t){}onTouchEnd(t){}onDeviceOrientation(t){}}var j;!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&s.firstChild?s.insertBefore(n,s.firstChild):s.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}}(".ls-viewer-container{display:block;height:100%;overflow:hidden;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:100%}.ls-viewer-container-image,.ls-viewer-container-video{cursor:default;pointer-events:none}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{opacity:0;position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");class F{constructor(e,i){this.checkResize=this.checkResize.bind(this),this.onDeviceOrientation=this.onDeviceOrientation.bind(this),this.onResize=this.onResize.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onMouseEnter=this.onMouseEnter.bind(this),this.onTouchStart=this.onTouchStart.bind(this),this.onTouchMove=this.onTouchMove.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this),this.onLoadStart=this.onLoadStart.bind(this),this.onLoadProgress=this.onLoadProgress.bind(this),this.onLoadEnd=this.onLoadEnd.bind(this),this.onLoadError=this.onLoadError.bind(this),this.onHotspotsChange=this.onHotspotsChange.bind(this),this.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options=Object.assign({server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{}},i),this.options.events=Object.assign({onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{},onHotspotsChange:()=>{}},i.events),this.options.events.onLoadError=t(this.options.events.onLoadError,10),this.container=e,this.container.classList.add("ls-viewer-container"),this.containerWidth=0,this.containerHeight=0,this.canvas2D=new r(this.options.fit),this.container.prepend(this.canvas2D.element),this.canvas3D=new h,this.container.prepend(this.canvas3D.element),this.video=new w,this.container.prepend(this.video.element),this.loader=new g(this.options.server,this.options.api,this),this.resolution=new o(0,0),this.parameters={width:0,height:0,antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.hotspots=[],this.widgetImage=new b(e,this.canvas2D,this.loader),this.widgetVideo=new L(e,this.video,this.loader),this.widgetVRObject=new S(e,this.canvas2D,this.loader,this.onVrobjectInteraction),this.canvas3D.context&&(this.widgetVRCube=new E(e,this.canvas3D,this.loader,this.onVrcubeInteraction)),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.loadWidget=t(this.loadWidget,10),this.onResize=t(this.onResize,250),requestAnimationFrame(this.checkResize)}destroy(){this.canvas2D.destroy(),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mouseenter",this.onMouseEnter),this.container.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd),this.isDestroyed=!0}async load(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&this.viewWidget instanceof S&&(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}setHotspots(t){this.hotspots=t,this.loadWidget(!1,!1)}async setView(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&this.viewWidget instanceof S&&(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){this.widgetVRCube&&Object.assign(this.widgetVRCube,t)}setVrobject(t){Object.assign(this.widgetVRObject,t)}async loadAnimation(t){var e;const i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return(null===(e=i.view)||void 0===e?void 0:e.background)||(i.view.background="product"),this.widgetVideo.load(i).then((()=>Promise.resolve()))}async playAnimation(t){return this.loadAnimation(t).then((()=>this.widgetVideo.play())).catch((t=>{this.onLoadError(t)}))}stopAnimation(){this.widgetVideo.hide()}async pick(t){if(!this.scene)throw new Error("No scene set");if(!this.view)throw new Error("No view set");if(!this.view.camera&&!this.view.cameraGroup)throw new Error("No camera set");const e={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return await this.viewWidget.pick(e,t)}async pickHotspot(t){const e=await this.pick(t),s=Object.values(e.point),n=i.normalize(Object.values(e.normal)),o=i.add(s,i.mulScalar(n,.01));return e.point={x:o[0],y:o[1],z:o[2]},e}snapshot(t,e){return this.viewWidget.snapshot(t,e)}async loadWidget(t,e){if(!this.scene||!this.view)return Promise.resolve();if(!this.parameters.width||!this.parameters.height)return Promise.resolve();const i=this.viewWidget;if(!i)return Promise.reject(new Error("Unknown view mode"));const s={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return s.view.background||(s.view.background="product"),i.load(s,this.hotspots,t,e).then((()=>{this.widget.hide(),this.widget=i,this.widget.show(),this.widgetVideo.hide(),this.onHotspotsChange()}))}get viewWidget(){var t,e;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 null!==(e=this.widgetVRCube)&&void 0!==e?e:this.widgetImage;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=this.container.clientWidth,e=this.container.clientHeight;this.resolution=a.getStandardResolution(t*window.devicePixelRatio,e*window.devicePixelRatio),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height,this.canvas2D.resize(t,e,window.devicePixelRatio),this.canvas3D.resize(t,e,window.devicePixelRatio),this.video.resize(t,e,this.resolution,this.options.fit),this.loadWidget(!1,!1).then((()=>{this.onHotspotsChange()})).catch((t=>{this.onLoadError(t)}))}onVrcubeInteraction(...t){this.onHotspotsChange(),this.options.events.onInteraction(...t),this.options.events.onVrcubeInteraction(...t)}onVrobjectInteraction(t){this.onHotspotsChange(),this.options.events.onInteraction(t.position),this.options.events.onVrobjectInteraction(t.position)}onHotspotsChange(){const t=this.widget.hotspots(this.resolution);t.length&&this.options.events.onHotspotsChange(t)}onLoadStart(...t){this.container.classList.add("ls-viewer-container-loading"),this.options.events.onLoadStart(...t)}onLoadProgress(...t){this.options.events.onLoadProgress(...t)}onLoadEnd(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadEnd(...t)}onLoadError(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadError(...t)}}!function(t){var e,i,s;(e=t.SunShadowQualityMode||(t.SunShadowQualityMode={})).VeryLow="veryLow",e.Low="low",e.Medium="medium",e.Fine="fine",e.Ultra="ultra",(i=t.SunShadowSmoothnessMode||(t.SunShadowSmoothnessMode={})).None="none",i.Weak="weak",i.Normal="normal",i.Fine="fine",i.UltraFine="ultraFine",i.Max="max",(s=t.SunUseCaseMode||(t.SunUseCaseMode={})).Manual="manual",s.ExtractedFromEnv="extractedFromEnv"}(j||(j={}));export{F as Viewer,j as WRAPIv2,b as WidgetImage,E as WidgetVRCube,S as WidgetVRObject,L as WidgetVideo};
import t from"debounce-promise";import*as e from"twgl.js";import{v3 as i,m4 as s}from"twgl.js";import n from"regression";class o{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 contains(t,e){return e.x>=0&&e.x<t.width&&e.y>=0&&e.y<t.height}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 project(t,e,i,s){const n=a.fit(t,e,i),o=n.width/t.width,r=n.height/t.height;return{x:Math.round(n.left+s.x*o),y:Math.round(n.top+s.y*r)}}static unproject(t,e,i,s){const n=a.fit(t,e,i),o=n.width/t.width,r=n.height/t.height;return{x:Math.round((s.x-n.left)/o),y:Math.round((s.y-n.top)/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 o(0,0);const i=a.getStandardAspectRatio(t,e);if(t<e){const s=a.getStandardQuality(Math.max(e*i,t));return new o(Math.round(s),Math.round(s/i))}const s=a.getStandardQuality(Math.max(t/i,e));return new o(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(t){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.element.width=0,this.element.height=0,this.context=this.element.getContext("2d"),this.backCanvas=document.createElement("canvas"),this.backContext=this.backCanvas.getContext("2d"),this.fit=t,this.pixelRatio=1}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"}get resolution(){return new o(this.element.width/this.pixelRatio,this.element.height/this.pixelRatio)}resize(t,e,i){this.element.width=t*i,this.element.height=e*i,this.element.style.width=`${t}px`,this.element.style.height=`${e}px`,this.backCanvas.width=t*i,this.backCanvas.height=e*i,this.pixelRatio=i}draw(t,e,i){if(!t)return;this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=void 0);const s=a.fit(new o(t.width,t.height),new o(this.element.width,this.element.height),this.fit);e?(this.backContext.drawImage(this.element,0,0),this.context.globalAlpha=0,this.fadeLoop(t,i||0)):(this.context.globalAlpha=1,this.context.drawImage(t,s.left,s.top,s.width,s.height)),this.image=t}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),s=a.fit(new o(t.width,t.height),new o(this.element.width,this.element.height),this.fit);this.context.clearRect(0,0,this.element.width,this.element.height),this.context.globalAlpha=1,this.context.drawImage(this.backCanvas,0,0),this.context.globalAlpha=i,this.context.drawImage(t,s.left,s.top,s.width,s.height),this.requestAnimationId=requestAnimationFrame((()=>{this.fadeLoop(t,e)}))}}class h{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.element.width=0,this.element.height=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(t,e,i){this.element.width=t*i,this.element.height=e*i,this.element.style.width=`${t}px`,this.element.style.height=`${e}px`}}class c{static accelerate(t,e){const i=e||1.5;return Math.abs(t)**i*(t>0?1:-1)}static clamp(t,e,i){return Math.max(Math.min(t,i),e)}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)}static perspectiveWithFovX(t,e,i,s,n){const o=Math.tan(t/2),a=o/e;return this.perspectiveWithLeft(-o,o,-a,a,i,s,n)}static perspectiveWithFovY(t,e,i,s,n){const o=i*Math.tan(t/2),a=o*e;return this.perspectiveWithLeft(-a,a,-o,o,i,s,n)}static perspectiveWithLeft(t,e,i,s,n,o,a){const r=e+t,h=e-t,c=s+i,d=s-i,l=o-n;return(a=a||new Float32Array(16))[0]=2*n/h,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=2*n/d,a[6]=0,a[7]=0,a[8]=r/h,a[9]=c/d,a[10]=-o/l,a[11]=-1,a[12]=0,a[13]=0,a[14]=-o*n/l,a[15]=0,a}}class d{static initCubeFace(t,e,s){let n=[0,0,0];const o=i.subtract(e,t),a=i.mulScalar([0,1,0],i.length(o)),r=i.mulScalar(i.normalize(i.cross(o,a)),i.length(o)),h=i.mulScalar(i.normalize(i.cross(a,r)),i.length(o));switch(s){case"front":e=i.add(t,h),n=i.normalize(a);break;case"right":e=i.add(t,r),n=i.normalize(a);break;case"back":e=i.subtract(t,h),n=i.normalize(a);break;case"left":e=i.subtract(t,r),n=i.normalize(a);break;case"up":e=i.add(t,a),n=i.normalize(i.mulScalar(h,-1));break;case"down":e=i.subtract(t,a),n=i.normalize(h)}return new d(e,t,n)}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 d(i.copy(this.target),i.copy(this.eye),i.copy(this.up))}}d.default=new d([0,0,0],[2,2,2],[0,1,0]);class l{constructor(t){this.target=t.target;const e=i.normalize(i.subtract(t.eye,t.target)),s=i.dot(e,[1,0,0]),n=i.dot(e,[0,1,0]),o=i.dot(e,[0,0,1]);this.longitude=Math.atan2(s,o),this.latitude=Math.atan2(n,Math.sqrt(s*s+o*o)),i.dot(t.up,[0,1,0])<0&&(this.longitude=Math.PI+this.longitude,this.latitude=Math.PI-this.latitude),this.distance=i.length(i.subtract(t.target,t.eye))}get vector(){const t=Math.cos(this.latitude)*this.distance,e=Math.sin(this.latitude)*this.distance;return[Math.cos(this.longitude)*t,e,Math.sin(this.longitude)*t]}pointOfView(t){const e=s.rotationY(this.longitude),n=s.rotationX(-this.latitude),o=s.rotationZ(0),a=s.multiply(e,s.multiply(n,o));let r=[0,0,-1];r=s.transformPoint(a,r);let h=[0,1,0];h=s.transformPoint(a,h);const c=i.subtract(t,i.mulScalar(r,this.distance));return new d(t,c,h)}}class m{constructor(){}async animation(t){return t.scene}async database(t){throw new Error("Unavailable")}async image(t){return t.scene}async video(t){return t.scene}async vrCube(t){return t.scene}async vrObject(t){return t.scene}}class u{constructor(t){this.xmlDoc=t}get id(){var t;return null===(t=this.xmlDoc.getElementsByTagName("Database")[0])||void 0===t?void 0:t.getAttribute("id")}getCameraId(t,e){var i,s;return e?null===(i=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${e}"] Camera[name="${t}"]`))||void 0===i?void 0:i.getAttribute("id"):null===(s=this.xmlDoc.querySelector(`RootCameraGroup Camera[name="${t}"]`))||void 0===s?void 0:s.getAttribute("id")}getCameraById(t,e){let i;return i=t&&e?this.xmlDoc.querySelector(`RootCameraGroup Group[id="${e}"] Camera[id="${t}"]`):this.xmlDoc.querySelector(`RootCameraGroup Camera[id="${t}"]`),i?this.mapElementToCamera(i):null}getCameraByName(t,e){let i;return i=e&&t?this.xmlDoc.querySelector(`RootCameraGroup Group[name="${e}"] Camera[name="${t}"]`):this.xmlDoc.querySelector(`RootCameraGroup Camera[name="${t}"]`),i?this.mapElementToCamera(i):null}getCameraGroupId(t){var e;return null===(e=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${t}"]`))||void 0===e?void 0:e.getAttribute("id")}getCameraGroupById(t){const e=this.xmlDoc.querySelector(`RootCameraGroup Group[id="${t}"]`);return e?this.mapElementToCameraGroup(e):null}getCameraGroupByName(t){const e=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${t}"]`);return e?this.mapElementToCameraGroup(e):null}mapElementToCamera(t){return{id:t.getAttribute("id"),name:t.getAttribute("name"),pointOfView:new d([parseFloat(t.querySelector("PointOfView Target").getAttribute("x")),parseFloat(t.querySelector("PointOfView Target").getAttribute("y")),parseFloat(t.querySelector("PointOfView Target").getAttribute("z"))],[parseFloat(t.querySelector("PointOfView Eye").getAttribute("x")),parseFloat(t.querySelector("PointOfView Eye").getAttribute("y")),parseFloat(t.querySelector("PointOfView Eye").getAttribute("z"))],[parseFloat(t.querySelector("PointOfView Up").getAttribute("x")),parseFloat(t.querySelector("PointOfView Up").getAttribute("y")),parseFloat(t.querySelector("PointOfView Up").getAttribute("z"))])}}mapElementToCameraGroup(t){return{id:t.getAttribute("id"),name:t.getAttribute("name"),cameras:[...t.querySelectorAll("Camera")].map((t=>this.mapElementToCamera(t)))}}}class p{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 s=t.scene,n=s.length>1?s.find((t=>t.accessory)):null,o=s.length>1?s.find((t=>t.decor)):null,a=s.find((t=>t!==n&&t!==o));return{databaseId:a.database,configuration:null==a?void 0:a.configuration,animations:null===(e=null==a?void 0:a.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(/&amp;/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({},p.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}),p.renderParameters(t)),p.encoderParameters(t)),i=p.buildQuery(e);return p.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async database(t){return fetch(`${this.server}/Database?databaseId=${t}`).then((t=>t.text())).then((t=>{const e=(new DOMParser).parseFromString(t,"application/xml");return new u(e)}))}async image(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},p.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),p.renderParameters(t)),p.encoderParameters(t)),i=p.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},p.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}),p.renderParameters(t)),p.encoderParameters(t)),i=p.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},p.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),p.renderParameters(t)),p.encoderParameters(t));e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=p.buildQuery(e);return p.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},p.sceneParameters(t)),{bookmarkSet:t.view.camera}),p.renderParameters(t)),p.encoderParameters(t)),i=p.buildQuery(e);return p.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}p.xmlRegex=/directUrl="([^"]*)"/g,"function"==typeof SuppressedError&&SuppressedError;class v{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const e=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 fetchFrame(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.url))}static async fetchFrameArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.map((t=>t.url))))}static async fetchHotspots(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json()))}static async fetchHotspotsArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json()))}static async fetchPick(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t[0]))}async database(t){return fetch(`${this.server}/Database?databaseId=${t}`).then((t=>t.text())).then((t=>{const e=(new DOMParser).parseFromString(t,"application/xml");return new u(e)}))}async image(t){const e={scene:v.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetchFrame(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:v.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return e.renderParameters.width=Math.max(e.renderParameters.width,e.renderParameters.height),e.renderParameters.height=Math.max(e.renderParameters.width,e.renderParameters.height),v.fetchFrameArray(`${this.server}/Snapshot`,e)}async vrObject(t){let e;e=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const i={scene:v.scene(t),mode:e,renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetchFrameArray(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:v.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:v.renderParameters(t),encoder:v.encoder(t)};return v.fetchFrameArray(`${this.server}/Snapshot`,e)}async imageHotspots(t,e){const i=Object.assign({scene:v.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:v.renderParameters(t)},this.hotspotsBody(e));return await v.fetchHotspots(`${this.server}/Hotspot`,i)}async imagePick(t,e){const i={scene:v.scene(t),camera:t.view.camera,renderParameters:v.renderParameters(t),positions:[e]};return await v.fetchPick(`${this.server}/Pick`,i)}async vrCubeHotspots(t,e){const i=Object.assign({scene:v.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:v.renderParameters(t)},this.hotspotsBody(e));return i.renderParameters.width=Math.max(i.renderParameters.width,i.renderParameters.height),i.renderParameters.height=Math.max(i.renderParameters.width,i.renderParameters.height),await v.fetchHotspotsArray(`${this.server}/Hotspot`,i)}async vrObjectHotspots(t,e){let i;i=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const s=Object.assign({scene:v.scene(t),mode:i,renderParameters:v.renderParameters(t)},this.hotspotsBody(e));return await v.fetchHotspotsArray(`${this.server}/Hotspot`,s)}hotspotsBody(t){return{positions:t.every((t=>"string"!=typeof t))?t:void 0,tags:t.every((t=>"string"==typeof t))?t:void 0}}}class g{constructor(t,e,i){switch(e){case"static":this.webrender=new m;break;case"v1":default:this.webrender=new p(t),this.webrenderV2=new v(t);break;case"v2":this.webrender=new v(t),this.webrenderV2=new v(t)}this.delegate=i,this.loadingId=0,this.loaded=0,this.total=0,this.databases=[],this.onLoadStart=i&&i.onLoadStart?i.onLoadStart:()=>{},this.onLoadProgress=i&&i.onLoadProgress?i.onLoadProgress:()=>{},this.onLoadEnd=i&&i.onLoadEnd?i.onLoadEnd:()=>{}}get progress(){return this.total?this.loaded/this.total:0}async loadImageSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.image(t).then((t=>this.loadImage(t,e))).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVideoSnapshot(t,e){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:i}=this;return this.webrender.video(e).then((s=>this.loadVideo(t,s,!!e.view.loop,i))).then((()=>(this.onLoadEnd(this.progress),t)))}async loadVRCubeSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.vrCube(t).then((t=>{this.total=t.length;const i=t.map((t=>this.loadImage(t,e)));return Promise.all(i)})).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVRObjectSnapshot(t,e){var i;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:s}=this;return t.view.animation?"mp4"===(null===(i=t.encoder)||void 0===i?void 0:i.format)?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,s))):this.webrender.animation(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s))):this.webrender.vrObject(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s)))}async loadImage(t,e){const i=new Image;i.crossOrigin="file:"!==location.protocol||g.isValidHttpUrl(t)?"anonymous":null;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,a=t.length;i<a;i+=1){const r=Math.ceil(i/2)*(i%2==0?1:-1),h=e?c.mod(o+r,a):i;n[h]=this.loadImage(t[h],s)}return Promise.all(n).then((()=>this.onLoadEnd(this.progress))).catch((()=>{})),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(((a,r)=>{const h=()=>{if(n!==this.loadingId)return;if(o!==s)return void(o+=1);t.removeEventListener("seeked",h);const r=document.createElement("canvas");r.width=t.videoWidth,r.height=t.videoHeight;r.getContext("2d").drawImage(t,0,0);const c=new Image;c.src=r.toDataURL(),a(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&&r(t)}),{once:!0})}))}loadVideoFrames(t,e,i,s){this.total=e;const n=new Array(e),o=document.createElement("video");for(let t=0,a=e;t<a;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))).catch((()=>{})),n}async loadImageHotspots(t,e){return this.webrenderV2?await this.webrenderV2.imageHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRCubeHotspots(t,e){return this.webrenderV2?await this.webrenderV2.vrCubeHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRObjectHotspots(t,e){return this.webrenderV2?await this.webrenderV2.vrObjectHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadImagePick(t,e){return this.webrenderV2?await this.webrenderV2.imagePick(await this.convert(t),e):Promise.reject(new Error("Picking only available with api V2"))}async loadVRObjectPick(t,e,i,s){return this.webrenderV2?await this.webrenderV2.imagePick(await this.vrObjectFrameSnapshot(t,i,s),e):Promise.reject(new Error("Picking only available with api V2"))}async loadVRCubePick(t,e,i){return this.webrenderV2?await this.webrenderV2.imagePick(await this.vrCubeFrameSnapshot(t,i),e):Promise.reject(new Error("Picking only available with api V2"))}async convert(t){var e;if(!this.webrenderV2)return t;if(this.webrender instanceof v)return t;if(!t.view.camera)return t;const i=t.scene.find((t=>!t.decor&&!t.accessory));if(!i)return t;let s=this.databases.find((t=>t.id===i.database));s&&s.xmlDoc||(s=await this.webrender.database(i.database),this.databases.push(s));const n=null===(e=t.view.camera)||void 0===e?void 0:e.split("/"),o=2===n.length?n[0]:void 0,a=2===n.length?n[1]:n[0],r=s.getCameraId(a,o);if(r)return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:r})});{const e=s.getCameraGroupId(a);return e?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{cameraGroup:e})}):t}}async vrObjectFrameSnapshot(t,e,i){if(!this.webrenderV2)return t;const s=t.scene.find((t=>!t.decor&&!t.accessory));if(!s)return t;let n=this.databases.find((t=>t.id===s.database));if(n||(n=await this.webrender.database(s.database),this.databases.push(n)),this.webrender instanceof p){if(!t.view.camera)return t;const i=n.getCameraGroupId(t.view.camera);if(!i)return t;const s=n.getCameraGroupById(i);if(!s)return t;const o=s.cameras[e];return o?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:o.id})}):t}if(this.webrender instanceof v){if(t.view.camera){const s=n.getCameraById(t.view.camera);if(!s)return t;const o=new l(s.pointOfView),a=2*Math.PI/i;o.longitude+=e*a%(2*Math.PI);const r=o.pointOfView(s.pointOfView.target);return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:{id:s.id,pov:{target:{x:r.target[0],y:r.target[1],z:r.target[2]},eye:{x:r.eye[0],y:r.eye[1],z:r.eye[2]},up:{x:r.up[0],y:r.up[1],z:r.up[2]}}}})})}if(t.view.cameraGroup){const i=n.getCameraGroupById(t.view.cameraGroup);if(!i)return t;const s=i.cameras[e];return s?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:s.id})}):t}return t}return t}async vrCubeFrameSnapshot(t,e){const i=t.scene.find((t=>!t.decor&&!t.accessory));if(!i)return t;let s,n=this.databases.find((t=>t.id===i.database));if(n||(n=await this.webrender.database(i.database),this.databases.push(n)),!t.view.camera)return t;if(this.webrender instanceof p){const e=t.view.camera.split("/"),i=2===e.length?e[0]:void 0,o=2===e.length?e[1]:e[0];s=n.getCameraId(o,i)}else this.webrender instanceof v&&(s=t.view.camera);if(!s)return t;const o=n.getCameraById(s);if(!o)return t;const a=d.initCubeFace(o.pointOfView.eye,o.pointOfView.target,e);return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:{id:o.id,pov:{target:{x:a.target[0],y:a.target[1],z:a.target[2]},eye:{x:a.eye[0],y:a.eye[1],z:a.eye[2]},up:{x:a.up[0],y:a.up[1],z:a.up[2]}},lens:{fov:90}}}),parameters:Object.assign(Object.assign({},t.parameters),{width:Math.max(t.parameters.width,t.parameters.height),height:Math.max(t.parameters.width,t.parameters.height)})})}onLoadStart(t){this.delegate&&this.delegate.onLoadStart(t)}onLoadProgress(t){this.delegate&&this.delegate.onLoadProgress(t)}onLoadEnd(t){this.delegate&&this.delegate.onLoadEnd(t)}static isValidHttpUrl(t){let e;try{e=new URL(t)}catch(t){return!1}return"http:"===e.protocol||"https:"===e.protocol}}class w{constructor(){this.element=document.createElement("video"),this.element.classList.add("ls-viewer-video"),this.element.style.opacity="0",this.element.width=0,this.element.height=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 o(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 b{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i,this.hotspotList=[]}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 load(t,e,i,s){let n=Promise.resolve();const o=JSON.stringify(t);n=o===this.snapshotHash&&this.image?n.then((()=>this.canvas.draw(this.image,s,.05))):n.then((()=>this.loader.loadImageSnapshot(t).then((t=>{this.canvas.draw(t,s,.05),this.image=t}))));const a=JSON.stringify(e);return o===this.snapshotHash&&a===this.hotspotsHash||(e.length?n=n.then((()=>this.loader.loadImageHotspots(t,e).then((t=>{this.hotspotList=t})))):this.hotspotList=[]),this.hotspotsHash=a,this.snapshotHash=o,n}async pick(t,e){const i=new o(t.parameters.width,t.parameters.height),s=a.unproject(i,this.canvas.resolution,this.canvas.fit,e);return this.loader.loadImagePick(t,s)}hotspots(t){return this.hotspotList.map((e=>Object.assign(Object.assign({},e),{position2D:a.project(t,this.canvas.resolution,this.canvas.fit,e.position2D)}))).map((t=>Object.assign(Object.assign({},t),{visibility:a.contains(this.canvas.resolution,t.position2D)?t.visibility:"OutOfFrustum"})))}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 y{constructor(t,e){this.x=t,this.y=e}clone(){return new y(this.x,this.y)}}class f{static pointFromMouseEvent(t){return new y(t.screenX,t.screenY)}static pointFromTouchEvent(t){const e=t.targetTouches[0]||t.changedTouches[0];return new y(e.screenX,e.screenY)}}class P{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 M{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class x{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new y(0,0),this.velocity=new y(0,0),this.loop=this.loop.bind(this)}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 M(t.x,t.y,e)),this.lastPoint=t}start(){if(0===this.points.length)return;const t=this.points[0],e=this.points[this.points.length-1],i=e.x-t.x,s=e.y-t.y,n=e.time-t.time;this.velocity=new y(0===n?0:i/(n/15),0===n?0:s/(n/15)),this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0),this.animationFrameId=requestAnimationFrame(this.loop)}stop(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0),this.points=[]}loop(){if(Math.abs(this.velocity.x)<1&&Math.abs(this.velocity.y)<1)return this.animationFrameId=void 0,void(this.points=[]);this.lastPoint.x+=this.velocity.x,this.lastPoint.y+=this.velocity.y,this.velocity.x*=.9,this.velocity.y*=.9,this.onMotion(this.lastPoint.clone()),this.animationFrameId=requestAnimationFrame(this.loop)}}class O{constructor(t,e,i){this.isStarted=!1,this.pov=t,this.fov=c.degreesToRadians(e),this.orientationMatrix=s.identity(),this.inertia=new x(this.motion.bind(this)),this.onMotion=i,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=c.degreesToRadians(window.orientation)||0,this.startPov=new d([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new y(0,0)}destroy(){this.inertia.destroy()}get orientedPov(){const t=i.normalize(i.cross(this.pov.up,this.pov.target)),e=new P(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),a=this.pov.eye,r=s.transformDirection(n,this.pov.up);return new d(o,a,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 e={x:t.x-this.previousPoint.x,y:t.y-this.previousPoint.y},n=c.accelerate(e.x,1.3)/this.startSize.width*.2*Math.PI*1.5,o=c.accelerate(e.y,1.3)/this.startSize.height*.2*Math.PI,a=s.multiply(s.rotationY(n),s.rotationX(-o)),r=i.normalize(i.cross(this.pov.up,this.pov.target)),h=new P(r,[0,1,0],this.pov.eye),d=s.identity();s.multiply(d,h.localToGlobalMatrix,d),s.multiply(d,a,d),s.multiply(d,h.globalToLocalMatrix,d);const l=s.transformPoint(d,this.pov.target),m=s.transformDirection(d,this.pov.up);i.cross(m,[0,0,1])[0]>=0&&(this.pov.target=l,this.pov.up=m),this.previousPoint=t,this.onMotion()}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}orientation(t,e,i){const n=c.degreesToRadians(window.orientation)||0,o=c.degreesToRadians(t),a=c.degreesToRadians(-e),r=c.degreesToRadians(-i),h=s.rotationX(c.degreesToRadians(90));s.rotateZ(h,this.initOrientation,h),s.rotateZ(h,o,h),s.rotateX(h,a,h),s.rotateY(h,r,h),s.rotateZ(h,-n,h),this.orientationMatrix=h,this.onMotion()}}class E{constructor(t,i,n,o){this.container=t,this.canvas=i,this.loader=n,this.images=[],this.hotspotsList=[[]];const a=new d([0,0,1],[0,0,0],[0,1,0]),r=s.rotationX(c.degreesToRadians(15));s.transformDirection(r,a.target,a.target),s.transformDirection(r,a.up,a.up),this.interaction=new O(a,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_mvpi;varying vec3 direction;void main(){direction=(u_mvpi*position).xyz;gl_Position=position;}\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_mvpi: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")}get pov(){return this.interaction.pov}set pov(t){this.interaction.pov.eye.every(((e,i)=>e===t.eye[i]))&&this.interaction.pov.target.every(((e,i)=>e===t.target[i]))&&this.interaction.pov.up.every(((e,i)=>e===t.up[i]))||(this.interaction.pov=t.clone(),this.animationFrameId=requestAnimationFrame(this.render))}get fov(){return c.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=c.degreesToRadians(t),this.animationFrameId=requestAnimationFrame(this.render))}async load(t,i,s,n){let o=Promise.resolve();{const e=this.gl.getExtension("WEBGL_debug_renderer_info");e&&"MacIntel"===navigator.platform&&navigator.userAgent.includes("Chrome")&&this.gl.getParameter(e.UNMASKED_RENDERER_WEBGL).includes("OpenGL")&&(t.parameters.width=Math.min(t.parameters.width,1812),t.parameters.height=Math.min(t.parameters.height,1812))}const a=JSON.stringify(t);a===this.snapshotHash?o=o.then((()=>(this.animationFrameId=requestAnimationFrame(this.render),Promise.resolve()))):(this.images=[],this.animationFrameId=requestAnimationFrame(this.render),o=o.then((()=>this.loader.loadVRCubeSnapshot(t).then((t=>{this.images=t,e.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,min:this.gl.LINEAR_MIPMAP_LINEAR,minMag:this.gl.LINEAR,cubeFaceOrder:[this.gl.TEXTURE_CUBE_MAP_POSITIVE_Z,this.gl.TEXTURE_CUBE_MAP_POSITIVE_X,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_X,this.gl.TEXTURE_CUBE_MAP_POSITIVE_Y,this.gl.TEXTURE_CUBE_MAP_NEGATIVE_Y],src:t},((t,e)=>{t||(s&&this.interaction.reset(),this.uniforms.u_mix=n?0:1,this.uniforms.u_texture_back=this.uniforms.u_texture,this.uniforms.u_texture=e,this.animationFrameId=requestAnimationFrame(this.render))}))})))));const r=JSON.stringify(i);return a===this.snapshotHash&&r===this.hotspotsHash||(i.length?o=o.then((()=>this.loader.loadVRCubeHotspots(t,i).then((t=>{this.hotspotsList=t})))):this.hotspotsList=[[]]),this.hotspotsHash=r,this.snapshotHash=a,o}async pick(t,e){const n=this.canvas.element.clientWidth,o=this.canvas.element.clientHeight,a=[2*e.x/n-1,2*(o-e.y)/o-1,0],r=this.modelViewProjectionMatrix,h=s.inverse(r),c=i.normalize(s.transformPoint(h,a)),d=Math.max(Math.abs(c[0]),Math.abs(c[1]),Math.abs(c[2]));let l="";l=Math.abs(c[0])===d?c[0]>0?"XPOS":"XNEG":Math.abs(c[1])===d?c[1]>0?"YPOS":"YNEG":c[2]>0?"ZPOS":"ZNEG";let m=0,u=0,p="";switch(l){case"XPOS":m=(-c[2]/Math.abs(c[0])+1)/2,u=(-c[1]/Math.abs(c[0])+1)/2,p="right";break;case"XNEG":m=(c[2]/Math.abs(c[0])+1)/2,u=(-c[1]/Math.abs(c[0])+1)/2,p="left";break;case"YPOS":m=(c[0]/Math.abs(c[1])+1)/2,u=(c[2]/Math.abs(c[1])+1)/2,p="up";break;case"YNEG":m=(c[0]/Math.abs(c[1])+1)/2,u=(-c[2]/Math.abs(c[1])+1)/2,p="down";break;case"ZPOS":m=(c[0]/Math.abs(c[2])+1)/2,u=(-c[1]/Math.abs(c[2])+1)/2,p="front";break;case"ZNEG":m=(-c[0]/Math.abs(c[2])+1)/2,u=(-c[1]/Math.abs(c[2])+1)/2,p="back"}const v={x:Math.round(m*Math.max(t.parameters.width,t.parameters.height)),y:Math.round(u*Math.max(t.parameters.width,t.parameters.height))};return this.loader.loadVRCubePick(t,v,p)}hotspots(){var t,e;const n=[];if(0===this.hotspotsList.length)return[];const r=null!==(e=null===(t=this.hotspotsList[0])||void 0===t?void 0:t.length)&&void 0!==e?e:0,h=this.modelViewProjectionMatrix;for(let t=0;t<r;t++){const e=this.hotspotsList.findIndex((e=>"OutOfFrustum"!==e[t].visibility));if(-1===e)continue;const r=Object.assign({},this.hotspotsList[e][t]),c=r.position2D.x/this.images[0].width,d=r.position2D.y/this.images[0].height;let l=0,m=0,u=0;switch(e){case 0:this.pov.target[2]<0&&(r.visibility="OutOfFrustum"),l=2*c-1,m=1-2*d,u=1;break;case 1:this.pov.target[0]>0&&(r.visibility="OutOfFrustum"),l=1,m=1-2*d,u=1-2*c;break;case 2:this.pov.target[2]>0&&(r.visibility="OutOfFrustum"),l=1-2*c,m=1-2*d,u=-1;break;case 3:this.pov.target[0]<0&&(r.visibility="OutOfFrustum"),l=-1,m=1-2*d,u=2*c-1;break;case 4:this.pov.target[1]<0&&(r.visibility="OutOfFrustum"),l=2*c-1,m=1,u=2*d-1;break;case 5:this.pov.target[1]>0&&(r.visibility="OutOfFrustum"),l=2*c-1,m=-1,u=1-2*d}const p=i.normalize([l,m,u]),v=s.transformPoint(h,p),g=this.canvas.element.clientWidth,w=this.canvas.element.clientHeight,b=.5*g*(v[0]+1),y=.5*w*(v[1]+1),f={x:Math.round(b),y:Math.round(w-y)},P=new o(g,w),M=a.contains(P,f)?r.visibility:"OutOfFrustum";n.push(Object.assign(Object.assign({},r),{position2D:f,visibility:M}))}return n}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}get modelViewProjectionMatrix(){const t=this.canvas.element.clientWidth,e=this.canvas.element.clientHeight,i=t>e?t/e:e/t,n=a.getStandardAspectRatio(t,e),o=this.interaction.fov*(n/i),r=s.setAxis(s.identity(),[-1,0,0],0),h=t>e?c.perspectiveWithFovY(o,t/e,.5,100):c.perspectiveWithFovX(o,t/e,.5,100),d=this.interaction.orientedPov,l=s.inverse(s.lookAt(d.eye,d.target,d.up));return s.multiply(s.multiply(h,l),r)}render(){this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.uniforms.u_mvpi=s.inverse(this.modelViewProjectionMatrix),this.gl.useProgram(this.programInfo.program),e.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),e.setUniforms(this.programInfo,this.uniforms),e.drawBufferInfo(this.gl,this.quad),this.uniforms.u_mix<1&&(this.uniforms.u_mix=Math.min(this.uniforms.u_mix+.05,1),this.animationFrameId=requestAnimationFrame(this.render))}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(f.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(f.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(f.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class I{constructor(t,e,i,s,n){this.isStarted=!1,this.position=t,this.frames=e,this.rows=i,this.loop=s,this.onMotion=n,this.inertia=new x(this.motion.bind(this)),this.initPosition=Object.assign({},this.position),this.startPosition={x:0,y:0},this.startPoint=new y(0,0),this.startSize={width:0,height:0},this.lastPoints=[],this.lastPointsNumber=20}destroy(){this.inertia.destroy()}reset(){this.position=Object.assign({},this.initPosition)}get positionIndex(){return this.frames*this.position.y+this.position.x}set positionIndex(t){if(this.positionIndex===t)return;const e=this.loop?c.mod(t,this.frames*this.rows):Math.max(0,Math.min(t,this.frames*this.rows));this.position.x=c.mod(e,this.frames),this.position.y=Math.floor(e/this.frames)}start(t,e){this.isStarted=!0,this.startPosition=Object.assign({},this.position),this.startPoint=t,this.startSize=e,this.lastPoints=[],this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t),this.lastPoints.push({x:t.x,y:t.y}),this.lastPoints.splice(0,this.lastPoints.length-this.lastPointsNumber);const e=n.linear(this.lastPoints.map((t=>[t.x,t.y])));if(Math.abs(e.equation[0])<1){const e=c.accelerate(t.x-this.startPoint.x,1.3)/this.startSize.width*(this.frames/4);let i=this.startPosition.x-Math.round(e);i=this.loop?c.mod(i,this.frames):Math.max(0,Math.min(i,this.frames-1)),i!==this.position.x&&(this.position.x=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.x)));Math.max(...this.lastPoints.map((t=>t.x)))-s>25&&(this.startPoint.y=t.y,this.startPosition.y=this.position.y)}else{const e=c.accelerate(t.y-this.startPoint.y,1.7)/this.startSize.height*(this.rows/4);let i=this.startPosition.y+Math.round(e);i=Math.max(0,Math.min(i,this.rows-1)),i!==this.position.y&&(this.position.y=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.y)));Math.max(...this.lastPoints.map((t=>t.y)))-s>25&&(this.startPoint.x=t.x,this.startPosition.x=this.position.x)}}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}}class S{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.frames=24,this.hotspotsList=[[]],this.interaction=new I({x:0,y:0},1,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:this.interaction.positionIndex})})),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.positionIndex;const s=()=>{if(this.interaction.positionIndex===t)e();else{let e=i>t?-1:1;this.interaction.loop&&this.interaction.frames-i+t<Math.abs(t-i)&&(e*=-1),i+=.5*e,this.position=Math.floor(i),this.animationFrameId=requestAnimationFrame(s)}};this.animationFrameId=requestAnimationFrame(s)}))}get position(){return this.interaction.positionIndex}set position(t){this.interaction.positionIndex=t,this.canvas.draw(this.image,!0,.5)}get image(){return this.images[this.interaction.positionIndex]}async load(t,e,i,s){let n=Promise.resolve();i&&this.interaction.reset();const o=JSON.stringify(t);o===this.snapshotHash&&this.image?n=n.then((()=>this.canvas.draw(this.image,s,.05))):(this.images=[],n=n.then((()=>this.loader.loadVRObjectSnapshot(t,this.interaction.positionIndex).then((e=>{var n,o;const a=e.length;return this.images=new Array(a),this.interaction.frames=null!==(o=null!==(n=t.view.frames)&&void 0!==n?n:t.view.panFrames)&&void 0!==o?o:this.frames,this.interaction.rows=a/this.interaction.frames,this.interaction.loop=!!t.view.loop,i&&this.interaction.reset(),e.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,s,.05)})).catch((()=>{}))})),e[this.interaction.positionIndex].then((()=>Promise.resolve()))})))));const a=JSON.stringify(e);return o===this.snapshotHash&&a===this.hotspotsHash||(e.length?n=n.then((()=>this.loader.loadVRObjectHotspots(t,e).then((t=>{this.hotspotsList=t})))):this.hotspotsList=[[]]),this.hotspotsHash=a,this.snapshotHash=o,n}async pick(t,e){const i=new o(t.parameters.width,t.parameters.height),s=a.unproject(i,this.canvas.resolution,this.canvas.fit,e);return this.loader.loadVRObjectPick(t,s,this.position,this.frames)}hotspots(t){return(this.hotspotsList[this.interaction.positionIndex]||[]).map((e=>Object.assign(Object.assign({},e),{position2D:a.project(t,this.canvas.resolution,this.canvas.fit,e.position2D)}))).map((t=>Object.assign(Object.assign({},t),{visibility:a.contains(this.canvas.resolution,t.position2D)?t.visibility:"OutOfFrustum"})))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(f.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(f.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(f.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(f.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}class L{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 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))}async pick(t,e){return Promise.reject()}hotspots(t){return[]}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}),this.video.element.play().catch(e),this.show()}))}onMouseDown(t){}onMouseMove(t){}onMouseUp(t){}onMouseEnter(t){}onTouchStart(t){}onTouchMove(t){}onTouchEnd(t){}onDeviceOrientation(t){}}var j;!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&s.firstChild?s.insertBefore(n,s.firstChild):s.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}}(".ls-viewer-container{display:block;height:100%;overflow:hidden;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:100%}.ls-viewer-container-image,.ls-viewer-container-video{cursor:default;pointer-events:none}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{opacity:0;position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");class F{constructor(e,i){this.checkResize=this.checkResize.bind(this),this.onDeviceOrientation=this.onDeviceOrientation.bind(this),this.onResize=this.onResize.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onMouseEnter=this.onMouseEnter.bind(this),this.onTouchStart=this.onTouchStart.bind(this),this.onTouchMove=this.onTouchMove.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this),this.onLoadStart=this.onLoadStart.bind(this),this.onLoadProgress=this.onLoadProgress.bind(this),this.onLoadEnd=this.onLoadEnd.bind(this),this.onLoadError=this.onLoadError.bind(this),this.onHotspotsChange=this.onHotspotsChange.bind(this),this.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options=Object.assign({server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{}},i),this.options.events=Object.assign({onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{},onHotspotsChange:()=>{}},i.events),this.options.events.onLoadError=t(this.options.events.onLoadError,10),this.container=e,this.container.classList.add("ls-viewer-container"),this.containerWidth=0,this.containerHeight=0,this.canvas2D=new r(this.options.fit),this.container.prepend(this.canvas2D.element),this.canvas3D=new h,this.container.prepend(this.canvas3D.element),this.video=new w,this.container.prepend(this.video.element),this.loader=new g(this.options.server,this.options.api,this),this.resolution=new o(0,0),this.parameters={width:0,height:0,antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.hotspots=[],this.widgetImage=new b(e,this.canvas2D,this.loader),this.widgetVideo=new L(e,this.video,this.loader),this.widgetVRObject=new S(e,this.canvas2D,this.loader,this.onVrobjectInteraction),this.canvas3D.context&&(this.widgetVRCube=new E(e,this.canvas3D,this.loader,this.onVrcubeInteraction)),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.loadWidget=t(this.loadWidget,10),this.onResize=t(this.onResize,250),requestAnimationFrame(this.checkResize)}destroy(){this.canvas2D.destroy(),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mouseenter",this.onMouseEnter),this.container.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd),this.isDestroyed=!0}async load(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&this.viewWidget instanceof S&&(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}setHotspots(t){this.hotspots=t,this.loadWidget(!1,!1)}async setView(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&this.viewWidget instanceof S&&(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){this.widgetVRCube&&Object.assign(this.widgetVRCube,t)}setVrobject(t){Object.assign(this.widgetVRObject,t)}async loadAnimation(t){var e;const i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return(null===(e=i.view)||void 0===e?void 0:e.background)||(i.view.background="product"),this.widgetVideo.load(i).then((()=>Promise.resolve()))}async playAnimation(t){return this.loadAnimation(t).then((()=>this.widgetVideo.play())).catch((t=>{this.onLoadError(t)}))}stopAnimation(){this.widgetVideo.hide()}async pick(t){if(!this.scene)throw new Error("No scene set");if(!this.view)throw new Error("No view set");if(!this.view.camera&&!this.view.cameraGroup)throw new Error("No camera set");const e={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return await this.viewWidget.pick(e,t)}async pickHotspot(t){const e=await this.pick(t),s=Object.values(e.point),n=i.normalize(Object.values(e.normal)),o=i.add(s,i.mulScalar(n,.01));return e.point={x:o[0],y:o[1],z:o[2]},e}snapshot(t,e){return this.viewWidget.snapshot(t,e)}async loadWidget(t,e){if(!this.scene||!this.view)return Promise.resolve();if(!this.parameters.width||!this.parameters.height)return Promise.resolve();const i=this.viewWidget;if(!i)return Promise.reject(new Error("Unknown view mode"));const s={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return s.view.background||(s.view.background="product"),i.load(s,this.hotspots,t,e).then((()=>{this.widget.hide(),this.widget=i,this.widget.show(),this.widgetVideo.hide(),this.onHotspotsChange()}))}get viewWidget(){var t,e;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 null!==(e=this.widgetVRCube)&&void 0!==e?e:this.widgetImage;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=this.container.clientWidth,e=this.container.clientHeight;this.resolution=a.getStandardResolution(t*window.devicePixelRatio,e*window.devicePixelRatio),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height,this.canvas2D.resize(t,e,window.devicePixelRatio),this.canvas3D.resize(t,e,window.devicePixelRatio),this.video.resize(t,e,this.resolution,this.options.fit),this.loadWidget(!1,!1).then((()=>{this.onHotspotsChange()})).catch((t=>{this.onLoadError(t)}))}onVrcubeInteraction(...t){this.onHotspotsChange(),this.options.events.onInteraction(...t),this.options.events.onVrcubeInteraction(...t)}onVrobjectInteraction(t){this.onHotspotsChange(),this.options.events.onInteraction(t.position),this.options.events.onVrobjectInteraction(t.position)}onHotspotsChange(){const t=this.widget.hotspots(this.resolution);t.length&&this.options.events.onHotspotsChange(t)}onLoadStart(...t){this.container.classList.add("ls-viewer-container-loading"),this.options.events.onLoadStart(...t)}onLoadProgress(...t){this.options.events.onLoadProgress(...t)}onLoadEnd(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadEnd(...t)}onLoadError(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadError(...t)}}!function(t){var e,i,s;(e=t.SunShadowQualityMode||(t.SunShadowQualityMode={})).VeryLow="veryLow",e.Low="low",e.Medium="medium",e.Fine="fine",e.Ultra="ultra",(i=t.SunShadowSmoothnessMode||(t.SunShadowSmoothnessMode={})).None="none",i.Weak="weak",i.Normal="normal",i.Fine="fine",i.UltraFine="ultraFine",i.Max="max",(s=t.SunUseCaseMode||(t.SunUseCaseMode={})).Manual="manual",s.ExtractedFromEnv="extractedFromEnv"}(j||(j={}));export{F as Viewer,j as WRAPIv2,b as WidgetImage,E as WidgetVRCube,S as WidgetVRObject,L as WidgetVideo};
//# sourceMappingURL=index.es.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("debounce-promise"),e=require("twgl.js"),i=require("regression");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function n(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var o=s(t),a=n(e),r=s(i);class h{constructor(t,e){this.width=t,this.height=e}get aspect(){return this.width/this.height}}class c{constructor(t,e,i,s){this.top=t,this.left=e,this.width=i,this.height=s}static contains(t,e){return e.x>=0&&e.x<t.width&&e.y>=0&&e.y<t.height}static fit(t,e,i){const s=t.aspect,n=e.aspect;let o=0,a=0;switch(i){case"contain":o=n<s?e.width:e.height*s,a=n<s?e.width/s:e.height;break;case"cover":default:o=n<s?e.height*s:e.width,a=n<s?e.height:e.width/s;break;case"fill":o=e.width,a=e.height}const r=(e.height-a)/2,h=(e.width-o)/2;return new c(r,h,o,a)}static project(t,e,i,s){const n=c.fit(t,e,i),o=n.width/t.width,a=n.height/t.height;return{x:Math.round(n.left+s.x*o),y:Math.round(n.top+s.y*a)}}static unproject(t,e,i,s){const n=c.fit(t,e,i),o=n.width/t.width,a=n.height/t.height;return{x:Math.round((s.x-n.left)/o),y:Math.round((s.y-n.top)/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 h(0,0);const i=c.getStandardAspectRatio(t,e);if(t<e){const s=c.getStandardQuality(Math.max(e*i,t));return new h(Math.round(s),Math.round(s/i))}const s=c.getStandardQuality(Math.max(t/i,e));return new h(Math.round(s*i),Math.round(s))}static getStandardQuality(t){return t<=240?240:t<=360?360:t<=480?480:t<=720?720:1080}}class d{constructor(t){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.element.width=0,this.element.height=0,this.context=this.element.getContext("2d"),this.backCanvas=document.createElement("canvas"),this.backContext=this.backCanvas.getContext("2d"),this.fit=t,this.pixelRatio=1}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"}get resolution(){return new h(this.element.width/this.pixelRatio,this.element.height/this.pixelRatio)}resize(t,e,i){this.element.width=t*i,this.element.height=e*i,this.element.style.width=`${t}px`,this.element.style.height=`${e}px`,this.backCanvas.width=t*i,this.backCanvas.height=e*i,this.pixelRatio=i}draw(t,e,i){if(!t)return;this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=void 0);const s=c.fit(new h(t.width,t.height),new h(this.element.width,this.element.height),this.fit);e?(this.backContext.drawImage(this.element,0,0),this.context.globalAlpha=0,this.fadeLoop(t,i||0)):(this.context.globalAlpha=1,this.context.drawImage(t,s.left,s.top,s.width,s.height)),this.image=t}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),s=c.fit(new h(t.width,t.height),new h(this.element.width,this.element.height),this.fit);this.context.clearRect(0,0,this.element.width,this.element.height),this.context.globalAlpha=1,this.context.drawImage(this.backCanvas,0,0),this.context.globalAlpha=i,this.context.drawImage(t,s.left,s.top,s.width,s.height),this.requestAnimationId=requestAnimationFrame((()=>{this.fadeLoop(t,e)}))}}class l{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.element.width=0,this.element.height=0,this.context=a.getContext(this.element,{preserveDrawingBuffer:!0}),a.setDefaultTextureColor([1,1,1,1])}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(t,e,i){this.element.width=t*i,this.element.height=e*i,this.element.style.width=`${t}px`,this.element.style.height=`${e}px`}}class m{static accelerate(t,e){const i=e||1.5;return Math.abs(t)**i*(t>0?1:-1)}static clamp(t,e,i){return Math.max(Math.min(t,i),e)}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)}static perspectiveWithFovX(t,e,i,s,n){const o=Math.tan(t/2),a=o/e;return this.perspectiveWithLeft(-o,o,-a,a,i,s,n)}static perspectiveWithFovY(t,e,i,s,n){const o=i*Math.tan(t/2),a=o*e;return this.perspectiveWithLeft(-a,a,-o,o,i,s,n)}static perspectiveWithLeft(t,e,i,s,n,o,a){const r=e+t,h=e-t,c=s+i,d=s-i,l=o-n;return(a=a||new Float32Array(16))[0]=2*n/h,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=2*n/d,a[6]=0,a[7]=0,a[8]=r/h,a[9]=c/d,a[10]=-o/l,a[11]=-1,a[12]=0,a[13]=0,a[14]=-o*n/l,a[15]=0,a}}class u{static initCubeFace(t,i,s){let n=[0,0,0];const o=e.v3.subtract(i,t),a=e.v3.mulScalar([0,1,0],e.v3.length(o)),r=e.v3.mulScalar(e.v3.normalize(e.v3.cross(o,a)),e.v3.length(o)),h=e.v3.mulScalar(e.v3.normalize(e.v3.cross(a,r)),e.v3.length(o));switch(s){case"front":i=e.v3.add(t,h),n=e.v3.normalize(a);break;case"right":i=e.v3.add(t,r),n=e.v3.normalize(a);break;case"back":i=e.v3.subtract(t,h),n=e.v3.normalize(a);break;case"left":i=e.v3.subtract(t,r),n=e.v3.normalize(a);break;case"up":i=e.v3.add(t,a),n=e.v3.normalize(e.v3.mulScalar(h,-1));break;case"down":i=e.v3.subtract(t,a),n=e.v3.normalize(h)}return new u(i,t,n)}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 u(e.v3.copy(this.target),e.v3.copy(this.eye),e.v3.copy(this.up))}}u.default=new u([0,0,0],[2,2,2],[0,1,0]);class v{constructor(t){this.target=t.target;const i=e.v3.normalize(e.v3.subtract(t.eye,t.target)),s=e.v3.dot(i,[1,0,0]),n=e.v3.dot(i,[0,1,0]),o=e.v3.dot(i,[0,0,1]);this.longitude=Math.atan2(s,o),this.latitude=Math.atan2(n,Math.sqrt(s*s+o*o)),e.v3.dot(t.up,[0,1,0])<0&&(this.longitude=Math.PI+this.longitude,this.latitude=Math.PI-this.latitude),this.distance=e.v3.length(e.v3.subtract(t.target,t.eye))}get vector(){const t=Math.cos(this.latitude)*this.distance,e=Math.sin(this.latitude)*this.distance;return[Math.cos(this.longitude)*t,e,Math.sin(this.longitude)*t]}pointOfView(t){const i=e.m4.rotationY(this.longitude),s=e.m4.rotationX(-this.latitude),n=e.m4.rotationZ(0),o=e.m4.multiply(i,e.m4.multiply(s,n));let a=[0,0,-1];a=e.m4.transformPoint(o,a);let r=[0,1,0];r=e.m4.transformPoint(o,r);const h=e.v3.subtract(t,e.v3.mulScalar(a,this.distance));return new u(t,h,r)}}class p{constructor(){}async animation(t){return t.scene}async database(t){throw new Error("Unavailable")}async image(t){return t.scene}async video(t){return t.scene}async vrCube(t){return t.scene}async vrObject(t){return t.scene}}class g{constructor(t){this.xmlDoc=t}get id(){var t;return null===(t=this.xmlDoc.getElementsByTagName("Database")[0])||void 0===t?void 0:t.getAttribute("id")}getCameraId(t,e){var i,s;return e?null===(i=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${e}"] Camera[name="${t}"]`))||void 0===i?void 0:i.getAttribute("id"):null===(s=this.xmlDoc.querySelector(`RootCameraGroup Camera[name="${t}"]`))||void 0===s?void 0:s.getAttribute("id")}getCameraById(t,e){let i;return i=t&&e?this.xmlDoc.querySelector(`RootCameraGroup Group[id="${e}"] Camera[id="${t}"]`):this.xmlDoc.querySelector(`RootCameraGroup Camera[id="${t}"]`),i?this.mapElementToCamera(i):null}getCameraByName(t,e){let i;return i=e&&t?this.xmlDoc.querySelector(`RootCameraGroup Group[name="${e}"] Camera[name="${t}"]`):this.xmlDoc.querySelector(`RootCameraGroup Camera[name="${t}"]`),i?this.mapElementToCamera(i):null}getCameraGroupId(t){var e;return null===(e=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${t}"]`))||void 0===e?void 0:e.getAttribute("id")}getCameraGroupById(t){const e=this.xmlDoc.querySelector(`RootCameraGroup Group[id="${t}"]`);return e?this.mapElementToCameraGroup(e):null}getCameraGroupByName(t){const e=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${t}"]`);return e?this.mapElementToCameraGroup(e):null}mapElementToCamera(t){return{id:t.getAttribute("id"),name:t.getAttribute("name"),pointOfView:new u([parseFloat(t.querySelector("PointOfView Target").getAttribute("x")),parseFloat(t.querySelector("PointOfView Target").getAttribute("y")),parseFloat(t.querySelector("PointOfView Target").getAttribute("z"))],[parseFloat(t.querySelector("PointOfView Eye").getAttribute("x")),parseFloat(t.querySelector("PointOfView Eye").getAttribute("y")),parseFloat(t.querySelector("PointOfView Eye").getAttribute("z"))],[parseFloat(t.querySelector("PointOfView Up").getAttribute("x")),parseFloat(t.querySelector("PointOfView Up").getAttribute("y")),parseFloat(t.querySelector("PointOfView Up").getAttribute("z"))])}}mapElementToCameraGroup(t){return{id:t.getAttribute("id"),name:t.getAttribute("name"),cameras:[...t.querySelectorAll("Camera")].map((t=>this.mapElementToCamera(t)))}}}class w{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 s=t.scene,n=s.length>1?s.find((t=>t.accessory)):null,o=s.length>1?s.find((t=>t.decor)):null,a=s.find((t=>t!==n&&t!==o));return{databaseId:a.database,configuration:null==a?void 0:a.configuration,animations:null===(e=null==a?void 0:a.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(/&amp;/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({},w.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}),w.renderParameters(t)),w.encoderParameters(t)),i=w.buildQuery(e);return w.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async database(t){return fetch(`${this.server}/Database?databaseId=${t}`).then((t=>t.text())).then((t=>{const e=(new DOMParser).parseFromString(t,"application/xml");return new g(e)}))}async image(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},w.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),w.renderParameters(t)),w.encoderParameters(t)),i=w.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},w.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}),w.renderParameters(t)),w.encoderParameters(t)),i=w.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},w.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),w.renderParameters(t)),w.encoderParameters(t));e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=w.buildQuery(e);return w.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},w.sceneParameters(t)),{bookmarkSet:t.view.camera}),w.renderParameters(t)),w.encoderParameters(t)),i=w.buildQuery(e);return w.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}w.xmlRegex=/directUrl="([^"]*)"/g,"function"==typeof SuppressedError&&SuppressedError;class b{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const e=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 fetchFrame(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.url))}static async fetchFrameArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.map((t=>t.url))))}static async fetchHotspots(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json()))}static async fetchHotspotsArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json()))}static async fetchPick(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t[0]))}async database(t){return fetch(`${this.server}/Database?databaseId=${t}`).then((t=>t.text())).then((t=>{const e=(new DOMParser).parseFromString(t,"application/xml");return new g(e)}))}async image(t){const e={scene:b.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:b.renderParameters(t),encoder:b.encoder(t)};return b.fetchFrame(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:b.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:b.renderParameters(t),encoder:b.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),b.fetchFrameArray(`${this.server}/Snapshot`,e)}async vrObject(t){let e;e=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const i={scene:b.scene(t),mode:e,renderParameters:b.renderParameters(t),encoder:b.encoder(t)};return b.fetchFrameArray(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:b.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:b.renderParameters(t),encoder:b.encoder(t)};return b.fetchFrameArray(`${this.server}/Snapshot`,e)}async imageHotspots(t,e){const i=Object.assign({scene:b.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:b.renderParameters(t)},this.hotspotsBody(e));return await b.fetchHotspots(`${this.server}/Hotspot`,i)}async imagePick(t,e){const i={scene:b.scene(t),camera:t.view.camera,renderParameters:b.renderParameters(t),positions:[e]};return await b.fetchPick(`${this.server}/Pick`,i)}async vrCubeHotspots(t,e){const i=Object.assign({scene:b.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:b.renderParameters(t)},this.hotspotsBody(e));return i.renderParameters.width=Math.max(i.renderParameters.width,i.renderParameters.height),i.renderParameters.height=Math.max(i.renderParameters.width,i.renderParameters.height),await b.fetchHotspotsArray(`${this.server}/Hotspot`,i)}async vrObjectHotspots(t,e){let i;i=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const s=Object.assign({scene:b.scene(t),mode:i,renderParameters:b.renderParameters(t)},this.hotspotsBody(e));return await b.fetchHotspotsArray(`${this.server}/Hotspot`,s)}hotspotsBody(t){return{positions:t.every((t=>"string"!=typeof t))?t:void 0,tags:t.every((t=>"string"==typeof t))?t:void 0}}}class y{constructor(t,e,i){switch(e){case"static":this.webrender=new p;break;case"v1":default:this.webrender=new w(t),this.webrenderV2=new b(t);break;case"v2":this.webrender=new b(t),this.webrenderV2=new b(t)}this.delegate=i,this.loadingId=0,this.loaded=0,this.total=0,this.databases=[],this.onLoadStart=i&&i.onLoadStart?i.onLoadStart:()=>{},this.onLoadProgress=i&&i.onLoadProgress?i.onLoadProgress:()=>{},this.onLoadEnd=i&&i.onLoadEnd?i.onLoadEnd:()=>{}}get progress(){return this.total?this.loaded/this.total:0}async loadImageSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.image(t).then((t=>this.loadImage(t,e))).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVideoSnapshot(t,e){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:i}=this;return this.webrender.video(e).then((s=>this.loadVideo(t,s,!!e.view.loop,i))).then((()=>(this.onLoadEnd(this.progress),t)))}async loadVRCubeSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.vrCube(t).then((t=>{this.total=t.length;const i=t.map((t=>this.loadImage(t,e)));return Promise.all(i)})).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVRObjectSnapshot(t,e){var i;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:s}=this;return t.view.animation?"mp4"===(null===(i=t.encoder)||void 0===i?void 0:i.format)?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,s))):this.webrender.animation(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s))):this.webrender.vrObject(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s)))}async loadImage(t,e){const i=new Image;i.crossOrigin="file:"!==location.protocol||y.isValidHttpUrl(t)?"anonymous":null;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,a=t.length;i<a;i+=1){const r=Math.ceil(i/2)*(i%2==0?1:-1),h=e?m.mod(o+r,a):i;n[h]=this.loadImage(t[h],s)}return Promise.all(n).then((()=>this.onLoadEnd(this.progress))).catch((()=>{})),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(((a,r)=>{const h=()=>{if(n!==this.loadingId)return;if(o!==s)return void(o+=1);t.removeEventListener("seeked",h);const r=document.createElement("canvas");r.width=t.videoWidth,r.height=t.videoHeight;r.getContext("2d").drawImage(t,0,0);const c=new Image;c.src=r.toDataURL(),a(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&&r(t)}),{once:!0})}))}loadVideoFrames(t,e,i,s){this.total=e;const n=new Array(e),o=document.createElement("video");for(let t=0,a=e;t<a;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))).catch((()=>{})),n}async loadImageHotspots(t,e){return this.webrenderV2?await this.webrenderV2.imageHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRCubeHotspots(t,e){return this.webrenderV2?await this.webrenderV2.vrCubeHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRObjectHotspots(t,e){return this.webrenderV2?await this.webrenderV2.vrObjectHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadImagePick(t,e){return this.webrenderV2?await this.webrenderV2.imagePick(await this.convert(t),e):Promise.reject(new Error("Picking only available with api V2"))}async loadVRObjectPick(t,e,i,s){return this.webrenderV2?await this.webrenderV2.imagePick(await this.vrObjectFrameSnapshot(t,i,s),e):Promise.reject(new Error("Picking only available with api V2"))}async loadVRCubePick(t,e,i){return this.webrenderV2?await this.webrenderV2.imagePick(await this.vrCubeFrameSnapshot(t,i),e):Promise.reject(new Error("Picking only available with api V2"))}async convert(t){var e;if(!this.webrenderV2)return t;if(this.webrender instanceof b)return t;if(!t.view.camera)return t;const i=t.scene.find((t=>!t.decor&&!t.accessory));if(!i)return t;let s=this.databases.find((t=>t.id===i.database));s&&s.xmlDoc||(s=await this.webrender.database(i.database),this.databases.push(s));const n=null===(e=t.view.camera)||void 0===e?void 0:e.split("/"),o=2===n.length?n[0]:void 0,a=2===n.length?n[1]:n[0],r=s.getCameraId(a,o);if(r)return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:r})});{const e=s.getCameraGroupId(a);return e?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{cameraGroup:e})}):t}}async vrObjectFrameSnapshot(t,e,i){if(!this.webrenderV2)return t;const s=t.scene.find((t=>!t.decor&&!t.accessory));if(!s)return t;let n=this.databases.find((t=>t.id===s.database));if(n||(n=await this.webrender.database(s.database),this.databases.push(n)),this.webrender instanceof w){if(!t.view.camera)return t;const i=n.getCameraGroupId(t.view.camera);if(!i)return t;const s=n.getCameraGroupById(i);if(!s)return t;const o=s.cameras[e];return o?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:o.id})}):t}if(this.webrender instanceof b){if(t.view.camera){const s=n.getCameraById(t.view.camera);if(!s)return t;const o=new v(s.pointOfView),a=2*Math.PI/i;o.longitude+=e*a%(2*Math.PI);const r=o.pointOfView(s.pointOfView.target);return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:{id:s.id,pov:{target:{x:r.target[0],y:r.target[1],z:r.target[2]},eye:{x:r.eye[0],y:r.eye[1],z:r.eye[2]},up:{x:r.up[0],y:r.up[1],z:r.up[2]}}}})})}if(t.view.cameraGroup){const i=n.getCameraGroupById(t.view.cameraGroup);if(!i)return t;const s=i.cameras[e];return s?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:s.id})}):t}return t}return t}async vrCubeFrameSnapshot(t,e){const i=t.scene.find((t=>!t.decor&&!t.accessory));if(!i)return t;let s,n=this.databases.find((t=>t.id===i.database));if(n||(n=await this.webrender.database(i.database),this.databases.push(n)),!t.view.camera)return t;if(this.webrender instanceof w){const e=t.view.camera.split("/"),i=2===e.length?e[0]:void 0,o=2===e.length?e[1]:e[0];s=n.getCameraId(o,i)}else this.webrender instanceof b&&(s=t.view.camera);if(!s)return t;const o=n.getCameraById(s);if(!o)return t;const a=u.initCubeFace(o.pointOfView.eye,o.pointOfView.target,e);return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:{id:o.id,pov:{target:{x:a.target[0],y:a.target[1],z:a.target[2]},eye:{x:a.eye[0],y:a.eye[1],z:a.eye[2]},up:{x:a.up[0],y:a.up[1],z:a.up[2]}},lens:{fov:90}}}),parameters:Object.assign(Object.assign({},t.parameters),{width:Math.max(t.parameters.width,t.parameters.height),height:Math.max(t.parameters.width,t.parameters.height)})})}onLoadStart(t){this.delegate&&this.delegate.onLoadStart(t)}onLoadProgress(t){this.delegate&&this.delegate.onLoadProgress(t)}onLoadEnd(t){this.delegate&&this.delegate.onLoadEnd(t)}static isValidHttpUrl(t){let e;try{e=new URL(t)}catch(t){return!1}return"http:"===e.protocol||"https:"===e.protocol}}class f{constructor(){this.element=document.createElement("video"),this.element.classList.add("ls-viewer-video"),this.element.style.opacity="0",this.element.width=0,this.element.height=0,this.element.setAttribute("muted",""),this.element.setAttribute("playsinline",""),this.element.setAttribute("preload","auto")}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(t,e,i,s){const n=c.fit(i,new h(t,e),s);this.element.style.top=`${n.top}px`,this.element.style.left=`${n.left}px`,this.element.style.width=`${n.width}px`,this.element.style.height=`${n.height}px`,i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height)}}class P{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i,this.hotspotList=[]}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 load(t,e,i,s){let n=Promise.resolve();const o=JSON.stringify(t);n=o===this.snapshotHash&&this.image?n.then((()=>this.canvas.draw(this.image,s,.05))):n.then((()=>this.loader.loadImageSnapshot(t).then((t=>{this.canvas.draw(t,s,.05),this.image=t}))));const a=JSON.stringify(e);return o===this.snapshotHash&&a===this.hotspotsHash||(e.length?n=n.then((()=>this.loader.loadImageHotspots(t,e).then((t=>{this.hotspotList=t})))):this.hotspotList=[]),this.hotspotsHash=a,this.snapshotHash=o,n}async pick(t,e){const i=new h(t.parameters.width,t.parameters.height),s=c.unproject(i,this.canvas.resolution,this.canvas.fit,e);return this.loader.loadImagePick(t,s)}hotspots(t){return this.hotspotList.map((e=>Object.assign(Object.assign({},e),{position2D:c.project(t,this.canvas.resolution,this.canvas.fit,e.position2D)}))).map((t=>Object.assign(Object.assign({},t),{visibility:c.contains(this.canvas.resolution,t.position2D)?t.visibility:"OutOfFrustum"})))}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 M{constructor(t,e){this.x=t,this.y=e}clone(){return new M(this.x,this.y)}}class x{static pointFromMouseEvent(t){return new M(t.screenX,t.screenY)}static pointFromTouchEvent(t){const e=t.targetTouches[0]||t.changedTouches[0];return new M(e.screenX,e.screenY)}}class O{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 E{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class I{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new M(0,0),this.velocity=new M(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 E(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 M(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 S{constructor(t,i,s){this.isStarted=!1,this.pov=t,this.fov=m.degreesToRadians(i),this.orientationMatrix=e.m4.identity(),this.inertia=new I(this.motion.bind(this)),this.onMotion=s,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=m.degreesToRadians(window.orientation)||0,this.startPov=new u([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new M(0,0)}destroy(){this.inertia.destroy()}get orientedPov(){const t=e.v3.normalize(e.v3.cross(this.pov.up,this.pov.target)),i=new O(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,a=e.m4.transformDirection(s,this.pov.up);return new u(n,o,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 i={x:t.x-this.previousPoint.x,y:t.y-this.previousPoint.y},s=m.accelerate(i.x,1.3)/this.startSize.width*.2*Math.PI*1.5,n=m.accelerate(i.y,1.3)/this.startSize.height*.2*Math.PI,o=e.m4.multiply(e.m4.rotationY(s),e.m4.rotationX(-n)),a=e.v3.normalize(e.v3.cross(this.pov.up,this.pov.target)),r=new O(a,[0,1,0],this.pov.eye),h=e.m4.identity();e.m4.multiply(h,r.localToGlobalMatrix,h),e.m4.multiply(h,o,h),e.m4.multiply(h,r.globalToLocalMatrix,h);const c=e.m4.transformPoint(h,this.pov.target),d=e.m4.transformDirection(h,this.pov.up);e.v3.cross(d,[0,0,1])[0]>=0&&(this.pov.target=c,this.pov.up=d),this.previousPoint=t,this.onMotion()}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}orientation(t,i,s){const n=m.degreesToRadians(window.orientation)||0,o=m.degreesToRadians(t),a=m.degreesToRadians(-i),r=m.degreesToRadians(-s),h=e.m4.rotationX(m.degreesToRadians(90));e.m4.rotateZ(h,this.initOrientation,h),e.m4.rotateZ(h,o,h),e.m4.rotateX(h,a,h),e.m4.rotateY(h,r,h),e.m4.rotateZ(h,-n,h),this.orientationMatrix=h,this.onMotion()}}class j{constructor(t,i,s,n){this.container=t,this.canvas=i,this.loader=s,this.images=[],this.hotspotsList=[[]];const o=new u([0,0,1],[0,0,0],[0,1,0]),r=e.m4.rotationX(m.degreesToRadians(15));e.m4.transformDirection(r,o.target,o.target),e.m4.transformDirection(r,o.up,o.up),this.interaction=new S(o,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=a.createProgramInfo(this.gl,["attribute vec4 position;uniform mat4 u_mvpi;varying vec3 direction;void main(){direction=(u_mvpi*position).xyz;gl_Position=position;}\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=a.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_mvpi:e.m4.identity(),u_mix:0,u_texture_back:a.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:a.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")}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 m.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=m.degreesToRadians(t),this.animationFrameId=requestAnimationFrame(this.render))}async load(t,e,i,s){let n=Promise.resolve();{const e=this.gl.getExtension("WEBGL_debug_renderer_info");e&&"MacIntel"===navigator.platform&&navigator.userAgent.includes("Chrome")&&this.gl.getParameter(e.UNMASKED_RENDERER_WEBGL).includes("OpenGL")&&(t.parameters.width=Math.min(t.parameters.width,1812),t.parameters.height=Math.min(t.parameters.height,1812))}const o=JSON.stringify(t);o===this.snapshotHash?n=n.then((()=>(this.animationFrameId=requestAnimationFrame(this.render),Promise.resolve()))):(this.images=[],this.animationFrameId=requestAnimationFrame(this.render),n=n.then((()=>this.loader.loadVRCubeSnapshot(t).then((t=>{this.images=t,a.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,min:this.gl.LINEAR_MIPMAP_LINEAR,minMag:this.gl.LINEAR,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))}))})))));const r=JSON.stringify(e);return o===this.snapshotHash&&r===this.hotspotsHash||(e.length?n=n.then((()=>this.loader.loadVRCubeHotspots(t,e).then((t=>{this.hotspotsList=t})))):this.hotspotsList=[[]]),this.hotspotsHash=r,this.snapshotHash=o,n}async pick(t,i){const s=this.canvas.element.clientWidth,n=this.canvas.element.clientHeight,o=[2*i.x/s-1,2*(n-i.y)/n-1,0],a=this.modelViewProjectionMatrix,r=e.m4.inverse(a),h=e.v3.normalize(e.m4.transformPoint(r,o)),c=Math.max(Math.abs(h[0]),Math.abs(h[1]),Math.abs(h[2]));let d="";d=Math.abs(h[0])===c?h[0]>0?"XPOS":"XNEG":Math.abs(h[1])===c?h[1]>0?"YPOS":"YNEG":h[2]>0?"ZPOS":"ZNEG";let l=0,m=0,u="";switch(d){case"XPOS":l=(-h[2]/Math.abs(h[0])+1)/2,m=(-h[1]/Math.abs(h[0])+1)/2,u="right";break;case"XNEG":l=(h[2]/Math.abs(h[0])+1)/2,m=(-h[1]/Math.abs(h[0])+1)/2,u="left";break;case"YPOS":l=(h[0]/Math.abs(h[1])+1)/2,m=(h[2]/Math.abs(h[1])+1)/2,u="up";break;case"YNEG":l=(h[0]/Math.abs(h[1])+1)/2,m=(-h[2]/Math.abs(h[1])+1)/2,u="down";break;case"ZPOS":l=(h[0]/Math.abs(h[2])+1)/2,m=(-h[1]/Math.abs(h[2])+1)/2,u="front";break;case"ZNEG":l=(-h[0]/Math.abs(h[2])+1)/2,m=(-h[1]/Math.abs(h[2])+1)/2,u="back"}const v={x:Math.round(l*Math.max(t.parameters.width,t.parameters.height)),y:Math.round(m*Math.max(t.parameters.width,t.parameters.height))};return this.loader.loadVRCubePick(t,v,u)}hotspots(){var t,i;const s=[];if(0===this.hotspotsList.length)return[];const n=null!==(i=null===(t=this.hotspotsList[0])||void 0===t?void 0:t.length)&&void 0!==i?i:0,o=this.modelViewProjectionMatrix;for(let t=0;t<n;t++){const i=this.hotspotsList.findIndex((e=>"OutOfFrustum"!==e[t].visibility));if(-1===i)continue;const n=Object.assign({},this.hotspotsList[i][t]),a=n.position2D.x/this.images[0].width,r=n.position2D.y/this.images[0].height;let d=0,l=0,m=0;switch(i){case 0:this.pov.target[2]<0&&(n.visibility="OutOfFrustum"),d=2*a-1,l=1-2*r,m=1;break;case 1:this.pov.target[0]>0&&(n.visibility="OutOfFrustum"),d=1,l=1-2*r,m=1-2*a;break;case 2:this.pov.target[2]>0&&(n.visibility="OutOfFrustum"),d=1-2*a,l=1-2*r,m=-1;break;case 3:this.pov.target[0]<0&&(n.visibility="OutOfFrustum"),d=-1,l=1-2*r,m=2*a-1;break;case 4:this.pov.target[1]<0&&(n.visibility="OutOfFrustum"),d=2*a-1,l=1,m=2*r-1;break;case 5:this.pov.target[1]>0&&(n.visibility="OutOfFrustum"),d=2*a-1,l=-1,m=1-2*r}const u=e.v3.normalize([d,l,m]),v=e.m4.transformPoint(o,u),p=this.canvas.element.clientWidth,g=this.canvas.element.clientHeight,w=.5*p*(v[0]+1),b=.5*g*(v[1]+1),y={x:Math.round(w),y:Math.round(g-b)},f=new h(p,g),P=c.contains(f,y)?n.visibility:"OutOfFrustum";s.push(Object.assign(Object.assign({},n),{position2D:y,visibility:P}))}return s}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}get modelViewProjectionMatrix(){const t=this.canvas.element.clientWidth,i=this.canvas.element.clientHeight,s=t>i?t/i:i/t,n=c.getStandardAspectRatio(t,i),o=this.interaction.fov*(n/s),a=e.m4.setAxis(e.m4.identity(),[-1,0,0],0),r=t>i?m.perspectiveWithFovY(o,t/i,.5,100):m.perspectiveWithFovX(o,t/i,.5,100),h=this.interaction.orientedPov,d=e.m4.inverse(e.m4.lookAt(h.eye,h.target,h.up));return e.m4.multiply(e.m4.multiply(r,d),a)}render(){this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.uniforms.u_mvpi=e.m4.inverse(this.modelViewProjectionMatrix),this.gl.useProgram(this.programInfo.program),a.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),a.setUniforms(this.programInfo,this.uniforms),a.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(x.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(x.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(x.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(x.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(x.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(x.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(x.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class L{constructor(t,e,i,s,n){this.isStarted=!1,this.position=t,this.frames=e,this.rows=i,this.loop=s,this.onMotion=n,this.inertia=new I(this.motion.bind(this)),this.initPosition=this.position,this.startPosition={x:0,y:0},this.startPoint=new M(0,0),this.startSize={width:0,height:0},this.lastPoints=[],this.lastPointsNumber=20}destroy(){this.inertia.destroy()}reset(){this.position=this.initPosition}get positionIndex(){return this.frames*this.position.y+this.position.x}set positionIndex(t){if(this.positionIndex===t)return;const e=this.loop?m.mod(t,this.frames*this.rows):Math.max(0,Math.min(t,this.frames*this.rows));this.position.x=m.mod(e,this.frames),this.position.y=Math.floor(e/this.frames)}start(t,e){this.isStarted=!0,this.startPosition=Object.assign({},this.position),this.startPoint=t,this.startSize=e,this.lastPoints=[],this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t),this.lastPoints.push({x:t.x,y:t.y}),this.lastPoints.splice(0,this.lastPoints.length-this.lastPointsNumber);const e=r.default.linear(this.lastPoints.map((t=>[t.x,t.y])));if(Math.abs(e.equation[0])<1){const e=m.accelerate(t.x-this.startPoint.x,1.3)/this.startSize.width*(this.frames/4);let i=this.startPosition.x-Math.round(e);i=this.loop?m.mod(i,this.frames):Math.max(0,Math.min(i,this.frames-1)),i!==this.position.x&&(this.position.x=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.x)));Math.max(...this.lastPoints.map((t=>t.x)))-s>25&&(this.startPoint.y=t.y,this.startPosition.y=this.position.y)}else{const e=m.accelerate(t.y-this.startPoint.y,1.7)/this.startSize.height*(this.rows/4);let i=this.startPosition.y+Math.round(e);i=Math.max(0,Math.min(i,this.rows-1)),i!==this.position.y&&(this.position.y=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.y)));Math.max(...this.lastPoints.map((t=>t.y)))-s>25&&(this.startPoint.x=t.x,this.startPosition.x=this.position.x)}}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}}class A{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.frames=24,this.hotspotsList=[[]],this.interaction=new L({x:0,y:0},1,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:this.interaction.positionIndex})})),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.positionIndex;const s=()=>{if(this.interaction.positionIndex===t)e();else{let e=i>t?-1:1;this.interaction.loop&&this.interaction.frames-i+t<Math.abs(t-i)&&(e*=-1),i+=.5*e,this.position=Math.floor(i),this.animationFrameId=requestAnimationFrame(s)}};this.animationFrameId=requestAnimationFrame(s)}))}get position(){return this.interaction.positionIndex}set position(t){this.interaction.positionIndex=t,this.canvas.draw(this.image,!0,.5)}get image(){return this.images[this.interaction.positionIndex]}async load(t,e,i,s){let n=Promise.resolve();i&&this.interaction.reset();const o=JSON.stringify(t);o===this.snapshotHash&&this.image?n=n.then((()=>this.canvas.draw(this.image,s,.05))):(this.images=[],n=n.then((()=>this.loader.loadVRObjectSnapshot(t,this.interaction.positionIndex).then((e=>{const n=e.length;return this.images=new Array(n),this.interaction.frames=t.view.frames||this.frames,this.interaction.rows=n/this.interaction.frames,this.interaction.loop=!!t.view.loop,i&&this.interaction.reset(),e.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,s,.05)})).catch((()=>{}))})),e[this.interaction.positionIndex].then((()=>Promise.resolve()))})))));const a=JSON.stringify(e);return o===this.snapshotHash&&a===this.hotspotsHash||(e.length?n=n.then((()=>this.loader.loadVRObjectHotspots(t,e).then((t=>{this.hotspotsList=t})))):this.hotspotsList=[[]]),this.hotspotsHash=a,this.snapshotHash=o,n}async pick(t,e){const i=new h(t.parameters.width,t.parameters.height),s=c.unproject(i,this.canvas.resolution,this.canvas.fit,e);return this.loader.loadVRObjectPick(t,s,this.position,this.frames)}hotspots(t){return(this.hotspotsList[this.interaction.positionIndex]||[]).map((e=>Object.assign(Object.assign({},e),{position2D:c.project(t,this.canvas.resolution,this.canvas.fit,e.position2D)}))).map((t=>Object.assign(Object.assign({},t),{visibility:c.contains(this.canvas.resolution,t.position2D)?t.visibility:"OutOfFrustum"})))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(x.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(x.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(x.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(x.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(x.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(x.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(x.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}class F{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 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))}async pick(t,e){return Promise.reject()}hotspots(t){return[]}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}),this.video.element.play().catch(e),this.show()}))}onMouseDown(t){}onMouseMove(t){}onMouseUp(t){}onMouseEnter(t){}onTouchStart(t){}onTouchMove(t){}onTouchEnd(t){}onDeviceOrientation(t){}}var T,k,V,C;!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&s.firstChild?s.insertBefore(n,s.firstChild):s.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}}(".ls-viewer-container{display:block;height:100%;overflow:hidden;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:100%}.ls-viewer-container-image,.ls-viewer-container-video{cursor:default;pointer-events:none}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{opacity:0;position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");exports.WRAPIv2=void 0,T=exports.WRAPIv2||(exports.WRAPIv2={}),(k=T.SunShadowQualityMode||(T.SunShadowQualityMode={})).VeryLow="veryLow",k.Low="low",k.Medium="medium",k.Fine="fine",k.Ultra="ultra",(V=T.SunShadowSmoothnessMode||(T.SunShadowSmoothnessMode={})).None="none",V.Weak="weak",V.Normal="normal",V.Fine="fine",V.UltraFine="ultraFine",V.Max="max",(C=T.SunUseCaseMode||(T.SunUseCaseMode={})).Manual="manual",C.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.onHotspotsChange=this.onHotspotsChange.bind(this),this.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options=Object.assign({server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{}},e),this.options.events=Object.assign({onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{},onHotspotsChange:()=>{}},e.events),this.options.events.onLoadError=o.default(this.options.events.onLoadError,10),this.container=t,this.container.classList.add("ls-viewer-container"),this.containerWidth=0,this.containerHeight=0,this.canvas2D=new d(this.options.fit),this.container.prepend(this.canvas2D.element),this.canvas3D=new l,this.container.prepend(this.canvas3D.element),this.video=new f,this.container.prepend(this.video.element),this.loader=new y(this.options.server,this.options.api,this),this.resolution=new h(0,0),this.parameters={width:0,height:0,antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.hotspots=[],this.widgetImage=new P(t,this.canvas2D,this.loader),this.widgetVideo=new F(t,this.video,this.loader),this.widgetVRObject=new A(t,this.canvas2D,this.loader,this.onVrobjectInteraction),this.canvas3D.context&&(this.widgetVRCube=new j(t,this.canvas3D,this.loader,this.onVrcubeInteraction)),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.loadWidget=o.default(this.loadWidget,10),this.onResize=o.default(this.onResize,250),requestAnimationFrame(this.checkResize)}destroy(){this.canvas2D.destroy(),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mouseenter",this.onMouseEnter),this.container.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd),this.isDestroyed=!0}async load(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&this.viewWidget instanceof A&&(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}setHotspots(t){this.hotspots=t,this.loadWidget(!1,!1)}async setView(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&this.viewWidget instanceof A&&(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 A&&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){this.widgetVRCube&&Object.assign(this.widgetVRCube,t)}setVrobject(t){Object.assign(this.widgetVRObject,t)}async loadAnimation(t){var e;const i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return(null===(e=i.view)||void 0===e?void 0:e.background)||(i.view.background="product"),this.widgetVideo.load(i).then((()=>Promise.resolve()))}async playAnimation(t){return this.loadAnimation(t).then((()=>this.widgetVideo.play())).catch((t=>{this.onLoadError(t)}))}stopAnimation(){this.widgetVideo.hide()}async pick(t){if(!this.scene)throw new Error("No scene set");if(!this.view)throw new Error("No view set");if(!this.view.camera&&!this.view.cameraGroup)throw new Error("No camera set");const e={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return await this.viewWidget.pick(e,t)}async pickHotspot(t){const i=await this.pick(t),s=Object.values(i.point),n=e.v3.normalize(Object.values(i.normal)),o=e.v3.add(s,e.v3.mulScalar(n,.01));return i.point={x:o[0],y:o[1],z:o[2]},i}snapshot(t,e){return this.viewWidget.snapshot(t,e)}async loadWidget(t,e){if(!this.scene||!this.view)return Promise.resolve();if(!this.parameters.width||!this.parameters.height)return Promise.resolve();const i=this.viewWidget;if(!i)return Promise.reject(new Error("Unknown view mode"));const s={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return s.view.background||(s.view.background="product"),i.load(s,this.hotspots,t,e).then((()=>{this.widget.hide(),this.widget=i,this.widget.show(),this.widgetVideo.hide(),this.onHotspotsChange()}))}get viewWidget(){var t,e;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 null!==(e=this.widgetVRCube)&&void 0!==e?e:this.widgetImage;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=this.container.clientWidth,e=this.container.clientHeight;this.resolution=c.getStandardResolution(t*window.devicePixelRatio,e*window.devicePixelRatio),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height,this.canvas2D.resize(t,e,window.devicePixelRatio),this.canvas3D.resize(t,e,window.devicePixelRatio),this.video.resize(t,e,this.resolution,this.options.fit),this.loadWidget(!1,!1).then((()=>{this.onHotspotsChange()})).catch((t=>{this.onLoadError(t)}))}onVrcubeInteraction(...t){this.onHotspotsChange(),this.options.events.onInteraction(...t),this.options.events.onVrcubeInteraction(...t)}onVrobjectInteraction(t){this.onHotspotsChange(),this.options.events.onInteraction(t.position),this.options.events.onVrobjectInteraction(t.position)}onHotspotsChange(){const t=this.widget.hotspots(this.resolution);t.length&&this.options.events.onHotspotsChange(t)}onLoadStart(...t){this.container.classList.add("ls-viewer-container-loading"),this.options.events.onLoadStart(...t)}onLoadProgress(...t){this.options.events.onLoadProgress(...t)}onLoadEnd(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadEnd(...t)}onLoadError(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadError(...t)}},exports.WidgetImage=P,exports.WidgetVRCube=j,exports.WidgetVRObject=A,exports.WidgetVideo=F;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("debounce-promise"),e=require("twgl.js"),i=require("regression");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function n(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var o=s(t),a=n(e),r=s(i);class h{constructor(t,e){this.width=t,this.height=e}get aspect(){return this.width/this.height}}class c{constructor(t,e,i,s){this.top=t,this.left=e,this.width=i,this.height=s}static contains(t,e){return e.x>=0&&e.x<t.width&&e.y>=0&&e.y<t.height}static fit(t,e,i){const s=t.aspect,n=e.aspect;let o=0,a=0;switch(i){case"contain":o=n<s?e.width:e.height*s,a=n<s?e.width/s:e.height;break;case"cover":default:o=n<s?e.height*s:e.width,a=n<s?e.height:e.width/s;break;case"fill":o=e.width,a=e.height}const r=(e.height-a)/2,h=(e.width-o)/2;return new c(r,h,o,a)}static project(t,e,i,s){const n=c.fit(t,e,i),o=n.width/t.width,a=n.height/t.height;return{x:Math.round(n.left+s.x*o),y:Math.round(n.top+s.y*a)}}static unproject(t,e,i,s){const n=c.fit(t,e,i),o=n.width/t.width,a=n.height/t.height;return{x:Math.round((s.x-n.left)/o),y:Math.round((s.y-n.top)/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 h(0,0);const i=c.getStandardAspectRatio(t,e);if(t<e){const s=c.getStandardQuality(Math.max(e*i,t));return new h(Math.round(s),Math.round(s/i))}const s=c.getStandardQuality(Math.max(t/i,e));return new h(Math.round(s*i),Math.round(s))}static getStandardQuality(t){return t<=240?240:t<=360?360:t<=480?480:t<=720?720:1080}}class d{constructor(t){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.element.width=0,this.element.height=0,this.context=this.element.getContext("2d"),this.backCanvas=document.createElement("canvas"),this.backContext=this.backCanvas.getContext("2d"),this.fit=t,this.pixelRatio=1}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"}get resolution(){return new h(this.element.width/this.pixelRatio,this.element.height/this.pixelRatio)}resize(t,e,i){this.element.width=t*i,this.element.height=e*i,this.element.style.width=`${t}px`,this.element.style.height=`${e}px`,this.backCanvas.width=t*i,this.backCanvas.height=e*i,this.pixelRatio=i}draw(t,e,i){if(!t)return;this.requestAnimationId&&(cancelAnimationFrame(this.requestAnimationId),this.requestAnimationId=void 0);const s=c.fit(new h(t.width,t.height),new h(this.element.width,this.element.height),this.fit);e?(this.backContext.drawImage(this.element,0,0),this.context.globalAlpha=0,this.fadeLoop(t,i||0)):(this.context.globalAlpha=1,this.context.drawImage(t,s.left,s.top,s.width,s.height)),this.image=t}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),s=c.fit(new h(t.width,t.height),new h(this.element.width,this.element.height),this.fit);this.context.clearRect(0,0,this.element.width,this.element.height),this.context.globalAlpha=1,this.context.drawImage(this.backCanvas,0,0),this.context.globalAlpha=i,this.context.drawImage(t,s.left,s.top,s.width,s.height),this.requestAnimationId=requestAnimationFrame((()=>{this.fadeLoop(t,e)}))}}class l{constructor(){this.element=document.createElement("canvas"),this.element.classList.add("ls-viewer-canvas"),this.element.style.opacity="0",this.element.width=0,this.element.height=0,this.context=a.getContext(this.element,{preserveDrawingBuffer:!0}),a.setDefaultTextureColor([1,1,1,1])}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(t,e,i){this.element.width=t*i,this.element.height=e*i,this.element.style.width=`${t}px`,this.element.style.height=`${e}px`}}class m{static accelerate(t,e){const i=e||1.5;return Math.abs(t)**i*(t>0?1:-1)}static clamp(t,e,i){return Math.max(Math.min(t,i),e)}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)}static perspectiveWithFovX(t,e,i,s,n){const o=Math.tan(t/2),a=o/e;return this.perspectiveWithLeft(-o,o,-a,a,i,s,n)}static perspectiveWithFovY(t,e,i,s,n){const o=i*Math.tan(t/2),a=o*e;return this.perspectiveWithLeft(-a,a,-o,o,i,s,n)}static perspectiveWithLeft(t,e,i,s,n,o,a){const r=e+t,h=e-t,c=s+i,d=s-i,l=o-n;return(a=a||new Float32Array(16))[0]=2*n/h,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=2*n/d,a[6]=0,a[7]=0,a[8]=r/h,a[9]=c/d,a[10]=-o/l,a[11]=-1,a[12]=0,a[13]=0,a[14]=-o*n/l,a[15]=0,a}}class u{static initCubeFace(t,i,s){let n=[0,0,0];const o=e.v3.subtract(i,t),a=e.v3.mulScalar([0,1,0],e.v3.length(o)),r=e.v3.mulScalar(e.v3.normalize(e.v3.cross(o,a)),e.v3.length(o)),h=e.v3.mulScalar(e.v3.normalize(e.v3.cross(a,r)),e.v3.length(o));switch(s){case"front":i=e.v3.add(t,h),n=e.v3.normalize(a);break;case"right":i=e.v3.add(t,r),n=e.v3.normalize(a);break;case"back":i=e.v3.subtract(t,h),n=e.v3.normalize(a);break;case"left":i=e.v3.subtract(t,r),n=e.v3.normalize(a);break;case"up":i=e.v3.add(t,a),n=e.v3.normalize(e.v3.mulScalar(h,-1));break;case"down":i=e.v3.subtract(t,a),n=e.v3.normalize(h)}return new u(i,t,n)}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 u(e.v3.copy(this.target),e.v3.copy(this.eye),e.v3.copy(this.up))}}u.default=new u([0,0,0],[2,2,2],[0,1,0]);class v{constructor(t){this.target=t.target;const i=e.v3.normalize(e.v3.subtract(t.eye,t.target)),s=e.v3.dot(i,[1,0,0]),n=e.v3.dot(i,[0,1,0]),o=e.v3.dot(i,[0,0,1]);this.longitude=Math.atan2(s,o),this.latitude=Math.atan2(n,Math.sqrt(s*s+o*o)),e.v3.dot(t.up,[0,1,0])<0&&(this.longitude=Math.PI+this.longitude,this.latitude=Math.PI-this.latitude),this.distance=e.v3.length(e.v3.subtract(t.target,t.eye))}get vector(){const t=Math.cos(this.latitude)*this.distance,e=Math.sin(this.latitude)*this.distance;return[Math.cos(this.longitude)*t,e,Math.sin(this.longitude)*t]}pointOfView(t){const i=e.m4.rotationY(this.longitude),s=e.m4.rotationX(-this.latitude),n=e.m4.rotationZ(0),o=e.m4.multiply(i,e.m4.multiply(s,n));let a=[0,0,-1];a=e.m4.transformPoint(o,a);let r=[0,1,0];r=e.m4.transformPoint(o,r);const h=e.v3.subtract(t,e.v3.mulScalar(a,this.distance));return new u(t,h,r)}}class p{constructor(){}async animation(t){return t.scene}async database(t){throw new Error("Unavailable")}async image(t){return t.scene}async video(t){return t.scene}async vrCube(t){return t.scene}async vrObject(t){return t.scene}}class g{constructor(t){this.xmlDoc=t}get id(){var t;return null===(t=this.xmlDoc.getElementsByTagName("Database")[0])||void 0===t?void 0:t.getAttribute("id")}getCameraId(t,e){var i,s;return e?null===(i=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${e}"] Camera[name="${t}"]`))||void 0===i?void 0:i.getAttribute("id"):null===(s=this.xmlDoc.querySelector(`RootCameraGroup Camera[name="${t}"]`))||void 0===s?void 0:s.getAttribute("id")}getCameraById(t,e){let i;return i=t&&e?this.xmlDoc.querySelector(`RootCameraGroup Group[id="${e}"] Camera[id="${t}"]`):this.xmlDoc.querySelector(`RootCameraGroup Camera[id="${t}"]`),i?this.mapElementToCamera(i):null}getCameraByName(t,e){let i;return i=e&&t?this.xmlDoc.querySelector(`RootCameraGroup Group[name="${e}"] Camera[name="${t}"]`):this.xmlDoc.querySelector(`RootCameraGroup Camera[name="${t}"]`),i?this.mapElementToCamera(i):null}getCameraGroupId(t){var e;return null===(e=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${t}"]`))||void 0===e?void 0:e.getAttribute("id")}getCameraGroupById(t){const e=this.xmlDoc.querySelector(`RootCameraGroup Group[id="${t}"]`);return e?this.mapElementToCameraGroup(e):null}getCameraGroupByName(t){const e=this.xmlDoc.querySelector(`RootCameraGroup Group[name="${t}"]`);return e?this.mapElementToCameraGroup(e):null}mapElementToCamera(t){return{id:t.getAttribute("id"),name:t.getAttribute("name"),pointOfView:new u([parseFloat(t.querySelector("PointOfView Target").getAttribute("x")),parseFloat(t.querySelector("PointOfView Target").getAttribute("y")),parseFloat(t.querySelector("PointOfView Target").getAttribute("z"))],[parseFloat(t.querySelector("PointOfView Eye").getAttribute("x")),parseFloat(t.querySelector("PointOfView Eye").getAttribute("y")),parseFloat(t.querySelector("PointOfView Eye").getAttribute("z"))],[parseFloat(t.querySelector("PointOfView Up").getAttribute("x")),parseFloat(t.querySelector("PointOfView Up").getAttribute("y")),parseFloat(t.querySelector("PointOfView Up").getAttribute("z"))])}}mapElementToCameraGroup(t){return{id:t.getAttribute("id"),name:t.getAttribute("name"),cameras:[...t.querySelectorAll("Camera")].map((t=>this.mapElementToCamera(t)))}}}class w{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 s=t.scene,n=s.length>1?s.find((t=>t.accessory)):null,o=s.length>1?s.find((t=>t.decor)):null,a=s.find((t=>t!==n&&t!==o));return{databaseId:a.database,configuration:null==a?void 0:a.configuration,animations:null===(e=null==a?void 0:a.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(/&amp;/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({},w.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}),w.renderParameters(t)),w.encoderParameters(t)),i=w.buildQuery(e);return w.fetch(`${this.server}/ImagesFromAnimation?${i}`)}async database(t){return fetch(`${this.server}/Database?databaseId=${t}`).then((t=>t.text())).then((t=>{const e=(new DOMParser).parseFromString(t,"application/xml");return new g(e)}))}async image(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},w.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),w.renderParameters(t)),w.encoderParameters(t)),i=w.buildQuery(e);return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`)}async video(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},w.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}),w.renderParameters(t)),w.encoderParameters(t)),i=w.buildQuery(e);return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`)}async vrCube(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},w.sceneParameters(t)),{bookmarkSet:t.view.camera.split("/")[0],bookmark:t.view.camera.split("/")[1]}),w.renderParameters(t)),w.encoderParameters(t));e.width=Math.max(e.width,e.height),e.height=Math.max(e.width,e.height);const i=w.buildQuery(e);return w.fetch(`${this.server}/CubeFromBookmark?${i}`)}async vrObject(t){const e=Object.assign(Object.assign(Object.assign(Object.assign({},w.sceneParameters(t)),{bookmarkSet:t.view.camera}),w.renderParameters(t)),w.encoderParameters(t)),i=w.buildQuery(e);return w.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`)}}w.xmlRegex=/directUrl="([^"]*)"/g,"function"==typeof SuppressedError&&SuppressedError;class b{constructor(t){this.server=t}static scene(t){return t.scene.map((t=>{const e=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 fetchFrame(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.url))}static async fetchFrameArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t.map((t=>t.url))))}static async fetchHotspots(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json()))}static async fetchHotspotsArray(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json()))}static async fetchPick(t,e){return fetch(t,{method:"POST",body:JSON.stringify(e)}).then((t=>t.json())).then((t=>t[0]))}async database(t){return fetch(`${this.server}/Database?databaseId=${t}`).then((t=>t.text())).then((t=>{const e=(new DOMParser).parseFromString(t,"application/xml");return new g(e)}))}async image(t){const e={scene:b.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:b.renderParameters(t),encoder:b.encoder(t)};return b.fetchFrame(`${this.server}/Snapshot`,e)}async vrCube(t){const e={scene:b.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:b.renderParameters(t),encoder:b.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),b.fetchFrameArray(`${this.server}/Snapshot`,e)}async vrObject(t){let e;e=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const i={scene:b.scene(t),mode:e,renderParameters:b.renderParameters(t),encoder:b.encoder(t)};return b.fetchFrameArray(`${this.server}/Snapshot`,i)}async animation(t){const e={scene:b.scene(t),mode:{animation:{id:t.view.animation,camera:t.view.camera,fps:t.view.fps}},renderParameters:b.renderParameters(t),encoder:b.encoder(t)};return b.fetchFrameArray(`${this.server}/Snapshot`,e)}async imageHotspots(t,e){const i=Object.assign({scene:b.scene(t),mode:{image:{camera:t.view.camera}},renderParameters:b.renderParameters(t)},this.hotspotsBody(e));return await b.fetchHotspots(`${this.server}/Hotspot`,i)}async imagePick(t,e){const i={scene:b.scene(t),camera:t.view.camera,renderParameters:b.renderParameters(t),positions:[e]};return await b.fetchPick(`${this.server}/Pick`,i)}async vrCubeHotspots(t,e){const i=Object.assign({scene:b.scene(t),mode:{vrCube:{camera:t.view.camera}},renderParameters:b.renderParameters(t)},this.hotspotsBody(e));return i.renderParameters.width=Math.max(i.renderParameters.width,i.renderParameters.height),i.renderParameters.height=Math.max(i.renderParameters.width,i.renderParameters.height),await b.fetchHotspotsArray(`${this.server}/Hotspot`,i)}async vrObjectHotspots(t,e){let i;i=t.view.cameraGroup?{images:{cameraGroup:t.view.cameraGroup}}:t.view.frames?{vrObject:{camera:t.view.camera,frames:t.view.frames}}:{vrObject:{camera:t.view.camera,panFrames:t.view.panFrames||1,panFrom:t.view.panFrom||0,panTo:t.view.panTo||0,panLoop:t.view.panLoop||!1,tiltFrames:t.view.tiltFrames||1,tiltFrom:t.view.tiltFrom||0,tiltTo:t.view.tiltTo||0,tiltLoop:t.view.tiltLoop||!1}};const s=Object.assign({scene:b.scene(t),mode:i,renderParameters:b.renderParameters(t)},this.hotspotsBody(e));return await b.fetchHotspotsArray(`${this.server}/Hotspot`,s)}hotspotsBody(t){return{positions:t.every((t=>"string"!=typeof t))?t:void 0,tags:t.every((t=>"string"==typeof t))?t:void 0}}}class y{constructor(t,e,i){switch(e){case"static":this.webrender=new p;break;case"v1":default:this.webrender=new w(t),this.webrenderV2=new b(t);break;case"v2":this.webrender=new b(t),this.webrenderV2=new b(t)}this.delegate=i,this.loadingId=0,this.loaded=0,this.total=0,this.databases=[],this.onLoadStart=i&&i.onLoadStart?i.onLoadStart:()=>{},this.onLoadProgress=i&&i.onLoadProgress?i.onLoadProgress:()=>{},this.onLoadEnd=i&&i.onLoadEnd?i.onLoadEnd:()=>{}}get progress(){return this.total?this.loaded/this.total:0}async loadImageSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.image(t).then((t=>this.loadImage(t,e))).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVideoSnapshot(t,e){this.loadingId+=1,this.loaded=0,this.total=1,this.onLoadStart(this.progress);const{loadingId:i}=this;return this.webrender.video(e).then((s=>this.loadVideo(t,s,!!e.view.loop,i))).then((()=>(this.onLoadEnd(this.progress),t)))}async loadVRCubeSnapshot(t){this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:e}=this;return this.webrender.vrCube(t).then((t=>{this.total=t.length;const i=t.map((t=>this.loadImage(t,e)));return Promise.all(i)})).then((t=>(this.onLoadEnd(this.progress),t)))}async loadVRObjectSnapshot(t,e){var i;this.loadingId+=1,this.loaded=0,this.total=0,this.onLoadStart(this.progress);const{loadingId:s}=this;return t.view.animation?"mp4"===(null===(i=t.encoder)||void 0===i?void 0:i.format)?this.webrender.video(t).then((e=>this.loadVideoFrames(e,t.view.frames,30,s))):this.webrender.animation(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s))):this.webrender.vrObject(t).then((i=>this.loadImageFrames(i,t.view.loop,e,s)))}async loadImage(t,e){const i=new Image;i.crossOrigin="file:"!==location.protocol||y.isValidHttpUrl(t)?"anonymous":null;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,a=t.length;i<a;i+=1){const r=Math.ceil(i/2)*(i%2==0?1:-1),h=e?m.mod(o+r,a):i;n[h]=this.loadImage(t[h],s)}return Promise.all(n).then((()=>this.onLoadEnd(this.progress))).catch((()=>{})),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(((a,r)=>{const h=()=>{if(n!==this.loadingId)return;if(o!==s)return void(o+=1);t.removeEventListener("seeked",h);const r=document.createElement("canvas");r.width=t.videoWidth,r.height=t.videoHeight;r.getContext("2d").drawImage(t,0,0);const c=new Image;c.src=r.toDataURL(),a(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&&r(t)}),{once:!0})}))}loadVideoFrames(t,e,i,s){this.total=e;const n=new Array(e),o=document.createElement("video");for(let t=0,a=e;t<a;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))).catch((()=>{})),n}async loadImageHotspots(t,e){return this.webrenderV2?await this.webrenderV2.imageHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRCubeHotspots(t,e){return this.webrenderV2?await this.webrenderV2.vrCubeHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadVRObjectHotspots(t,e){return this.webrenderV2?await this.webrenderV2.vrObjectHotspots(await this.convert(t),e):Promise.reject(new Error("Hotspots only available with api V2"))}async loadImagePick(t,e){return this.webrenderV2?await this.webrenderV2.imagePick(await this.convert(t),e):Promise.reject(new Error("Picking only available with api V2"))}async loadVRObjectPick(t,e,i,s){return this.webrenderV2?await this.webrenderV2.imagePick(await this.vrObjectFrameSnapshot(t,i,s),e):Promise.reject(new Error("Picking only available with api V2"))}async loadVRCubePick(t,e,i){return this.webrenderV2?await this.webrenderV2.imagePick(await this.vrCubeFrameSnapshot(t,i),e):Promise.reject(new Error("Picking only available with api V2"))}async convert(t){var e;if(!this.webrenderV2)return t;if(this.webrender instanceof b)return t;if(!t.view.camera)return t;const i=t.scene.find((t=>!t.decor&&!t.accessory));if(!i)return t;let s=this.databases.find((t=>t.id===i.database));s&&s.xmlDoc||(s=await this.webrender.database(i.database),this.databases.push(s));const n=null===(e=t.view.camera)||void 0===e?void 0:e.split("/"),o=2===n.length?n[0]:void 0,a=2===n.length?n[1]:n[0],r=s.getCameraId(a,o);if(r)return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:r})});{const e=s.getCameraGroupId(a);return e?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{cameraGroup:e})}):t}}async vrObjectFrameSnapshot(t,e,i){if(!this.webrenderV2)return t;const s=t.scene.find((t=>!t.decor&&!t.accessory));if(!s)return t;let n=this.databases.find((t=>t.id===s.database));if(n||(n=await this.webrender.database(s.database),this.databases.push(n)),this.webrender instanceof w){if(!t.view.camera)return t;const i=n.getCameraGroupId(t.view.camera);if(!i)return t;const s=n.getCameraGroupById(i);if(!s)return t;const o=s.cameras[e];return o?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:o.id})}):t}if(this.webrender instanceof b){if(t.view.camera){const s=n.getCameraById(t.view.camera);if(!s)return t;const o=new v(s.pointOfView),a=2*Math.PI/i;o.longitude+=e*a%(2*Math.PI);const r=o.pointOfView(s.pointOfView.target);return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:{id:s.id,pov:{target:{x:r.target[0],y:r.target[1],z:r.target[2]},eye:{x:r.eye[0],y:r.eye[1],z:r.eye[2]},up:{x:r.up[0],y:r.up[1],z:r.up[2]}}}})})}if(t.view.cameraGroup){const i=n.getCameraGroupById(t.view.cameraGroup);if(!i)return t;const s=i.cameras[e];return s?Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:s.id})}):t}return t}return t}async vrCubeFrameSnapshot(t,e){const i=t.scene.find((t=>!t.decor&&!t.accessory));if(!i)return t;let s,n=this.databases.find((t=>t.id===i.database));if(n||(n=await this.webrender.database(i.database),this.databases.push(n)),!t.view.camera)return t;if(this.webrender instanceof w){const e=t.view.camera.split("/"),i=2===e.length?e[0]:void 0,o=2===e.length?e[1]:e[0];s=n.getCameraId(o,i)}else this.webrender instanceof b&&(s=t.view.camera);if(!s)return t;const o=n.getCameraById(s);if(!o)return t;const a=u.initCubeFace(o.pointOfView.eye,o.pointOfView.target,e);return Object.assign(Object.assign({},t),{view:Object.assign(Object.assign({},t.view),{camera:{id:o.id,pov:{target:{x:a.target[0],y:a.target[1],z:a.target[2]},eye:{x:a.eye[0],y:a.eye[1],z:a.eye[2]},up:{x:a.up[0],y:a.up[1],z:a.up[2]}},lens:{fov:90}}}),parameters:Object.assign(Object.assign({},t.parameters),{width:Math.max(t.parameters.width,t.parameters.height),height:Math.max(t.parameters.width,t.parameters.height)})})}onLoadStart(t){this.delegate&&this.delegate.onLoadStart(t)}onLoadProgress(t){this.delegate&&this.delegate.onLoadProgress(t)}onLoadEnd(t){this.delegate&&this.delegate.onLoadEnd(t)}static isValidHttpUrl(t){let e;try{e=new URL(t)}catch(t){return!1}return"http:"===e.protocol||"https:"===e.protocol}}class f{constructor(){this.element=document.createElement("video"),this.element.classList.add("ls-viewer-video"),this.element.style.opacity="0",this.element.width=0,this.element.height=0,this.element.setAttribute("muted",""),this.element.setAttribute("playsinline",""),this.element.setAttribute("preload","auto")}show(){this.element.style.opacity="1"}hide(){this.element.style.opacity="0"}resize(t,e,i,s){const n=c.fit(i,new h(t,e),s);this.element.style.top=`${n.top}px`,this.element.style.left=`${n.left}px`,this.element.style.width=`${n.width}px`,this.element.style.height=`${n.height}px`,i.width===this.element.width&&i.height===this.element.height||(this.element.width=i.width,this.element.height=i.height)}}class P{constructor(t,e,i){this.container=t,this.canvas=e,this.loader=i,this.hotspotList=[]}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 load(t,e,i,s){let n=Promise.resolve();const o=JSON.stringify(t);n=o===this.snapshotHash&&this.image?n.then((()=>this.canvas.draw(this.image,s,.05))):n.then((()=>this.loader.loadImageSnapshot(t).then((t=>{this.canvas.draw(t,s,.05),this.image=t}))));const a=JSON.stringify(e);return o===this.snapshotHash&&a===this.hotspotsHash||(e.length?n=n.then((()=>this.loader.loadImageHotspots(t,e).then((t=>{this.hotspotList=t})))):this.hotspotList=[]),this.hotspotsHash=a,this.snapshotHash=o,n}async pick(t,e){const i=new h(t.parameters.width,t.parameters.height),s=c.unproject(i,this.canvas.resolution,this.canvas.fit,e);return this.loader.loadImagePick(t,s)}hotspots(t){return this.hotspotList.map((e=>Object.assign(Object.assign({},e),{position2D:c.project(t,this.canvas.resolution,this.canvas.fit,e.position2D)}))).map((t=>Object.assign(Object.assign({},t),{visibility:c.contains(this.canvas.resolution,t.position2D)?t.visibility:"OutOfFrustum"})))}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 M{constructor(t,e){this.x=t,this.y=e}clone(){return new M(this.x,this.y)}}class x{static pointFromMouseEvent(t){return new M(t.screenX,t.screenY)}static pointFromTouchEvent(t){const e=t.targetTouches[0]||t.changedTouches[0];return new M(e.screenX,e.screenY)}}class O{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 E{constructor(t,e,i){this.x=t,this.y=e,this.time=i}}class I{constructor(t){this.points=[],this.onMotion=t,this.lastPoint=new M(0,0),this.velocity=new M(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 E(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 M(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 S{constructor(t,i,s){this.isStarted=!1,this.pov=t,this.fov=m.degreesToRadians(i),this.orientationMatrix=e.m4.identity(),this.inertia=new I(this.motion.bind(this)),this.onMotion=s,this.initPov=this.pov,this.initFov=this.fov,this.initOrientation=m.degreesToRadians(window.orientation)||0,this.startPov=new u([0,0,1],[0,0,0],[0,1,0]),this.startSize={width:0,height:0},this.previousPoint=new M(0,0)}destroy(){this.inertia.destroy()}get orientedPov(){const t=e.v3.normalize(e.v3.cross(this.pov.up,this.pov.target)),i=new O(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,a=e.m4.transformDirection(s,this.pov.up);return new u(n,o,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 i={x:t.x-this.previousPoint.x,y:t.y-this.previousPoint.y},s=m.accelerate(i.x,1.3)/this.startSize.width*.2*Math.PI*1.5,n=m.accelerate(i.y,1.3)/this.startSize.height*.2*Math.PI,o=e.m4.multiply(e.m4.rotationY(s),e.m4.rotationX(-n)),a=e.v3.normalize(e.v3.cross(this.pov.up,this.pov.target)),r=new O(a,[0,1,0],this.pov.eye),h=e.m4.identity();e.m4.multiply(h,r.localToGlobalMatrix,h),e.m4.multiply(h,o,h),e.m4.multiply(h,r.globalToLocalMatrix,h);const c=e.m4.transformPoint(h,this.pov.target),d=e.m4.transformDirection(h,this.pov.up);e.v3.cross(d,[0,0,1])[0]>=0&&(this.pov.target=c,this.pov.up=d),this.previousPoint=t,this.onMotion()}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}orientation(t,i,s){const n=m.degreesToRadians(window.orientation)||0,o=m.degreesToRadians(t),a=m.degreesToRadians(-i),r=m.degreesToRadians(-s),h=e.m4.rotationX(m.degreesToRadians(90));e.m4.rotateZ(h,this.initOrientation,h),e.m4.rotateZ(h,o,h),e.m4.rotateX(h,a,h),e.m4.rotateY(h,r,h),e.m4.rotateZ(h,-n,h),this.orientationMatrix=h,this.onMotion()}}class j{constructor(t,i,s,n){this.container=t,this.canvas=i,this.loader=s,this.images=[],this.hotspotsList=[[]];const o=new u([0,0,1],[0,0,0],[0,1,0]),r=e.m4.rotationX(m.degreesToRadians(15));e.m4.transformDirection(r,o.target,o.target),e.m4.transformDirection(r,o.up,o.up),this.interaction=new S(o,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=a.createProgramInfo(this.gl,["attribute vec4 position;uniform mat4 u_mvpi;varying vec3 direction;void main(){direction=(u_mvpi*position).xyz;gl_Position=position;}\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=a.primitives.createXYQuadBufferInfo(this.gl),this.uniforms={u_mvpi:e.m4.identity(),u_mix:0,u_texture_back:a.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,minMag:this.gl.LINEAR,width:1,height:1}),u_texture:a.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")}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 m.radiansToDegrees(this.interaction.fov)}set fov(t){this.interaction.fov!==t&&(this.interaction.fov=m.degreesToRadians(t),this.animationFrameId=requestAnimationFrame(this.render))}async load(t,e,i,s){let n=Promise.resolve();{const e=this.gl.getExtension("WEBGL_debug_renderer_info");e&&"MacIntel"===navigator.platform&&navigator.userAgent.includes("Chrome")&&this.gl.getParameter(e.UNMASKED_RENDERER_WEBGL).includes("OpenGL")&&(t.parameters.width=Math.min(t.parameters.width,1812),t.parameters.height=Math.min(t.parameters.height,1812))}const o=JSON.stringify(t);o===this.snapshotHash?n=n.then((()=>(this.animationFrameId=requestAnimationFrame(this.render),Promise.resolve()))):(this.images=[],this.animationFrameId=requestAnimationFrame(this.render),n=n.then((()=>this.loader.loadVRCubeSnapshot(t).then((t=>{this.images=t,a.createTexture(this.gl,{target:this.gl.TEXTURE_CUBE_MAP,min:this.gl.LINEAR_MIPMAP_LINEAR,minMag:this.gl.LINEAR,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))}))})))));const r=JSON.stringify(e);return o===this.snapshotHash&&r===this.hotspotsHash||(e.length?n=n.then((()=>this.loader.loadVRCubeHotspots(t,e).then((t=>{this.hotspotsList=t})))):this.hotspotsList=[[]]),this.hotspotsHash=r,this.snapshotHash=o,n}async pick(t,i){const s=this.canvas.element.clientWidth,n=this.canvas.element.clientHeight,o=[2*i.x/s-1,2*(n-i.y)/n-1,0],a=this.modelViewProjectionMatrix,r=e.m4.inverse(a),h=e.v3.normalize(e.m4.transformPoint(r,o)),c=Math.max(Math.abs(h[0]),Math.abs(h[1]),Math.abs(h[2]));let d="";d=Math.abs(h[0])===c?h[0]>0?"XPOS":"XNEG":Math.abs(h[1])===c?h[1]>0?"YPOS":"YNEG":h[2]>0?"ZPOS":"ZNEG";let l=0,m=0,u="";switch(d){case"XPOS":l=(-h[2]/Math.abs(h[0])+1)/2,m=(-h[1]/Math.abs(h[0])+1)/2,u="right";break;case"XNEG":l=(h[2]/Math.abs(h[0])+1)/2,m=(-h[1]/Math.abs(h[0])+1)/2,u="left";break;case"YPOS":l=(h[0]/Math.abs(h[1])+1)/2,m=(h[2]/Math.abs(h[1])+1)/2,u="up";break;case"YNEG":l=(h[0]/Math.abs(h[1])+1)/2,m=(-h[2]/Math.abs(h[1])+1)/2,u="down";break;case"ZPOS":l=(h[0]/Math.abs(h[2])+1)/2,m=(-h[1]/Math.abs(h[2])+1)/2,u="front";break;case"ZNEG":l=(-h[0]/Math.abs(h[2])+1)/2,m=(-h[1]/Math.abs(h[2])+1)/2,u="back"}const v={x:Math.round(l*Math.max(t.parameters.width,t.parameters.height)),y:Math.round(m*Math.max(t.parameters.width,t.parameters.height))};return this.loader.loadVRCubePick(t,v,u)}hotspots(){var t,i;const s=[];if(0===this.hotspotsList.length)return[];const n=null!==(i=null===(t=this.hotspotsList[0])||void 0===t?void 0:t.length)&&void 0!==i?i:0,o=this.modelViewProjectionMatrix;for(let t=0;t<n;t++){const i=this.hotspotsList.findIndex((e=>"OutOfFrustum"!==e[t].visibility));if(-1===i)continue;const n=Object.assign({},this.hotspotsList[i][t]),a=n.position2D.x/this.images[0].width,r=n.position2D.y/this.images[0].height;let d=0,l=0,m=0;switch(i){case 0:this.pov.target[2]<0&&(n.visibility="OutOfFrustum"),d=2*a-1,l=1-2*r,m=1;break;case 1:this.pov.target[0]>0&&(n.visibility="OutOfFrustum"),d=1,l=1-2*r,m=1-2*a;break;case 2:this.pov.target[2]>0&&(n.visibility="OutOfFrustum"),d=1-2*a,l=1-2*r,m=-1;break;case 3:this.pov.target[0]<0&&(n.visibility="OutOfFrustum"),d=-1,l=1-2*r,m=2*a-1;break;case 4:this.pov.target[1]<0&&(n.visibility="OutOfFrustum"),d=2*a-1,l=1,m=2*r-1;break;case 5:this.pov.target[1]>0&&(n.visibility="OutOfFrustum"),d=2*a-1,l=-1,m=1-2*r}const u=e.v3.normalize([d,l,m]),v=e.m4.transformPoint(o,u),p=this.canvas.element.clientWidth,g=this.canvas.element.clientHeight,w=.5*p*(v[0]+1),b=.5*g*(v[1]+1),y={x:Math.round(w),y:Math.round(g-b)},f=new h(p,g),P=c.contains(f,y)?n.visibility:"OutOfFrustum";s.push(Object.assign(Object.assign({},n),{position2D:y,visibility:P}))}return s}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}get modelViewProjectionMatrix(){const t=this.canvas.element.clientWidth,i=this.canvas.element.clientHeight,s=t>i?t/i:i/t,n=c.getStandardAspectRatio(t,i),o=this.interaction.fov*(n/s),a=e.m4.setAxis(e.m4.identity(),[-1,0,0],0),r=t>i?m.perspectiveWithFovY(o,t/i,.5,100):m.perspectiveWithFovX(o,t/i,.5,100),h=this.interaction.orientedPov,d=e.m4.inverse(e.m4.lookAt(h.eye,h.target,h.up));return e.m4.multiply(e.m4.multiply(r,d),a)}render(){this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.uniforms.u_mvpi=e.m4.inverse(this.modelViewProjectionMatrix),this.gl.useProgram(this.programInfo.program),a.setBuffersAndAttributes(this.gl,this.programInfo,this.quad),a.setUniforms(this.programInfo,this.uniforms),a.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(x.pointFromMouseEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(x.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(x.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(x.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrcube-grabbing"),this.interaction.start(x.pointFromTouchEvent(t),{width:this.gl.canvas.width,height:this.gl.canvas.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(x.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrcube-grabbing"),this.interaction.end(x.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){this.interaction.orientation(t.alpha,t.beta,t.gamma)}}class L{constructor(t,e,i,s,n){this.isStarted=!1,this.position=t,this.frames=e,this.rows=i,this.loop=s,this.onMotion=n,this.inertia=new I(this.motion.bind(this)),this.initPosition=Object.assign({},this.position),this.startPosition={x:0,y:0},this.startPoint=new M(0,0),this.startSize={width:0,height:0},this.lastPoints=[],this.lastPointsNumber=20}destroy(){this.inertia.destroy()}reset(){this.position=Object.assign({},this.initPosition)}get positionIndex(){return this.frames*this.position.y+this.position.x}set positionIndex(t){if(this.positionIndex===t)return;const e=this.loop?m.mod(t,this.frames*this.rows):Math.max(0,Math.min(t,this.frames*this.rows));this.position.x=m.mod(e,this.frames),this.position.y=Math.floor(e/this.frames)}start(t,e){this.isStarted=!0,this.startPosition=Object.assign({},this.position),this.startPoint=t,this.startSize=e,this.lastPoints=[],this.inertia.stop()}motion(t){this.isStarted&&this.inertia.track(t),this.lastPoints.push({x:t.x,y:t.y}),this.lastPoints.splice(0,this.lastPoints.length-this.lastPointsNumber);const e=r.default.linear(this.lastPoints.map((t=>[t.x,t.y])));if(Math.abs(e.equation[0])<1){const e=m.accelerate(t.x-this.startPoint.x,1.3)/this.startSize.width*(this.frames/4);let i=this.startPosition.x-Math.round(e);i=this.loop?m.mod(i,this.frames):Math.max(0,Math.min(i,this.frames-1)),i!==this.position.x&&(this.position.x=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.x)));Math.max(...this.lastPoints.map((t=>t.x)))-s>25&&(this.startPoint.y=t.y,this.startPosition.y=this.position.y)}else{const e=m.accelerate(t.y-this.startPoint.y,1.7)/this.startSize.height*(this.rows/4);let i=this.startPosition.y+Math.round(e);i=Math.max(0,Math.min(i,this.rows-1)),i!==this.position.y&&(this.position.y=i,this.onMotion());const s=Math.min(...this.lastPoints.map((t=>t.y)));Math.max(...this.lastPoints.map((t=>t.y)))-s>25&&(this.startPoint.x=t.x,this.startPosition.x=this.position.x)}}end(t,e){this.isStarted=!1,e&&(this.inertia.track(t),this.inertia.start())}}class F{constructor(t,e,i,s){this.container=t,this.canvas=e,this.loader=i,this.images=[],this.frames=24,this.hotspotsList=[[]],this.interaction=new L({x:0,y:0},1,1,!1,(()=>{this.canvas.draw(this.image,!0,.5),this.onInteraction({position:this.interaction.positionIndex})})),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.positionIndex;const s=()=>{if(this.interaction.positionIndex===t)e();else{let e=i>t?-1:1;this.interaction.loop&&this.interaction.frames-i+t<Math.abs(t-i)&&(e*=-1),i+=.5*e,this.position=Math.floor(i),this.animationFrameId=requestAnimationFrame(s)}};this.animationFrameId=requestAnimationFrame(s)}))}get position(){return this.interaction.positionIndex}set position(t){this.interaction.positionIndex=t,this.canvas.draw(this.image,!0,.5)}get image(){return this.images[this.interaction.positionIndex]}async load(t,e,i,s){let n=Promise.resolve();i&&this.interaction.reset();const o=JSON.stringify(t);o===this.snapshotHash&&this.image?n=n.then((()=>this.canvas.draw(this.image,s,.05))):(this.images=[],n=n.then((()=>this.loader.loadVRObjectSnapshot(t,this.interaction.positionIndex).then((e=>{var n,o;const a=e.length;return this.images=new Array(a),this.interaction.frames=null!==(o=null!==(n=t.view.frames)&&void 0!==n?n:t.view.panFrames)&&void 0!==o?o:this.frames,this.interaction.rows=a/this.interaction.frames,this.interaction.loop=!!t.view.loop,i&&this.interaction.reset(),e.forEach(((t,e)=>{t.then((t=>{this.images[e]=t,t===this.image&&this.canvas.draw(this.image,s,.05)})).catch((()=>{}))})),e[this.interaction.positionIndex].then((()=>Promise.resolve()))})))));const a=JSON.stringify(e);return o===this.snapshotHash&&a===this.hotspotsHash||(e.length?n=n.then((()=>this.loader.loadVRObjectHotspots(t,e).then((t=>{this.hotspotsList=t})))):this.hotspotsList=[[]]),this.hotspotsHash=a,this.snapshotHash=o,n}async pick(t,e){const i=new h(t.parameters.width,t.parameters.height),s=c.unproject(i,this.canvas.resolution,this.canvas.fit,e);return this.loader.loadVRObjectPick(t,s,this.position,this.frames)}hotspots(t){return(this.hotspotsList[this.interaction.positionIndex]||[]).map((e=>Object.assign(Object.assign({},e),{position2D:c.project(t,this.canvas.resolution,this.canvas.fit,e.position2D)}))).map((t=>Object.assign(Object.assign({},t),{visibility:c.contains(this.canvas.resolution,t.position2D)?t.visibility:"OutOfFrustum"})))}snapshot(t,e){return this.canvas.element.toDataURL(t,e)}onMouseDown(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(x.pointFromMouseEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onMouseMove(t){this.interaction.isStarted&&(this.interaction.motion(x.pointFromMouseEvent(t)),t.preventDefault())}onMouseUp(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(x.pointFromMouseEvent(t),!0))}onMouseEnter(t){this.interaction.isStarted&&0===t.buttons&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(x.pointFromMouseEvent(t),!1))}onTouchStart(t){this.container.classList.add("ls-viewer-container-vrobject-grabbing"),this.interaction.start(x.pointFromTouchEvent(t),{width:this.canvas.element.width,height:this.canvas.element.height})}onTouchMove(t){this.interaction.isStarted&&(this.interaction.motion(x.pointFromTouchEvent(t)),t.preventDefault())}onTouchEnd(t){this.interaction.isStarted&&(this.container.classList.remove("ls-viewer-container-vrobject-grabbing"),this.interaction.end(x.pointFromTouchEvent(t),!0))}onDeviceOrientation(t){}}class A{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 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))}async pick(t,e){return Promise.reject()}hotspots(t){return[]}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}),this.video.element.play().catch(e),this.show()}))}onMouseDown(t){}onMouseMove(t){}onMouseUp(t){}onMouseEnter(t){}onTouchStart(t){}onTouchMove(t){}onTouchEnd(t){}onDeviceOrientation(t){}}var T,k,V,C;!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&s.firstChild?s.insertBefore(n,s.firstChild):s.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}}(".ls-viewer-container{display:block;height:100%;overflow:hidden;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:100%}.ls-viewer-container-image,.ls-viewer-container-video{cursor:default;pointer-events:none}.ls-viewer-container-vrcube{cursor:pointer;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:-webkit-grab;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:-webkit-grabbing;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{opacity:0;position:absolute;-webkit-transition:opacity .5s;transition:opacity .5s}.ls-viewer-video{position:absolute}");exports.WRAPIv2=void 0,T=exports.WRAPIv2||(exports.WRAPIv2={}),(k=T.SunShadowQualityMode||(T.SunShadowQualityMode={})).VeryLow="veryLow",k.Low="low",k.Medium="medium",k.Fine="fine",k.Ultra="ultra",(V=T.SunShadowSmoothnessMode||(T.SunShadowSmoothnessMode={})).None="none",V.Weak="weak",V.Normal="normal",V.Fine="fine",V.UltraFine="ultraFine",V.Max="max",(C=T.SunUseCaseMode||(T.SunUseCaseMode={})).Manual="manual",C.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.onHotspotsChange=this.onHotspotsChange.bind(this),this.onVrcubeInteraction=this.onVrcubeInteraction.bind(this),this.onVrobjectInteraction=this.onVrobjectInteraction.bind(this),this.options=Object.assign({server:"localhost",api:"v1",fit:"cover",image:{},video:{},vrcube:{},vrobject:{},events:{}},e),this.options.events=Object.assign({onLoadStart:()=>{},onLoadProgress:()=>{},onLoadEnd:()=>{},onLoadError:()=>{},onInteraction:()=>{},onVrcubeInteraction:()=>{},onVrobjectInteraction:()=>{},onHotspotsChange:()=>{}},e.events),this.options.events.onLoadError=o.default(this.options.events.onLoadError,10),this.container=t,this.container.classList.add("ls-viewer-container"),this.containerWidth=0,this.containerHeight=0,this.canvas2D=new d(this.options.fit),this.container.prepend(this.canvas2D.element),this.canvas3D=new l,this.container.prepend(this.canvas3D.element),this.video=new f,this.container.prepend(this.video.element),this.loader=new y(this.options.server,this.options.api,this),this.resolution=new h(0,0),this.parameters={width:0,height:0,antialiasing:!1,superSampling:2},this.encoder={format:"jpeg",quality:80},this.hotspots=[],this.widgetImage=new P(t,this.canvas2D,this.loader),this.widgetVideo=new A(t,this.video,this.loader),this.widgetVRObject=new F(t,this.canvas2D,this.loader,this.onVrobjectInteraction),this.canvas3D.context&&(this.widgetVRCube=new j(t,this.canvas3D,this.loader,this.onVrcubeInteraction)),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.loadWidget=o.default(this.loadWidget,10),this.onResize=o.default(this.onResize,250),requestAnimationFrame(this.checkResize)}destroy(){this.canvas2D.destroy(),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mouseenter",this.onMouseEnter),this.container.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd),this.isDestroyed=!0}async load(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&this.viewWidget instanceof F&&(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}setHotspots(t){this.hotspots=t,this.loadWidget(!1,!1)}async setView(t,e){let i=Promise.resolve();return(null==e?void 0:e.animation)&&(i=i.then((()=>this.loadAnimation(e.animation)))),this.view&&void 0!==(null==e?void 0:e.fromPosition)&&this.viewWidget instanceof F&&(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 F&&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){this.widgetVRCube&&Object.assign(this.widgetVRCube,t)}setVrobject(t){Object.assign(this.widgetVRObject,t)}async loadAnimation(t){var e;const i={scene:this.scene,view:{animation:t.name,camera:t.camera,duration:t.duration,loop:t.loop,reverse:t.reverse},parameters:this.parameters,encoder:{format:"mp4"}};return(null===(e=i.view)||void 0===e?void 0:e.background)||(i.view.background="product"),this.widgetVideo.load(i).then((()=>Promise.resolve()))}async playAnimation(t){return this.loadAnimation(t).then((()=>this.widgetVideo.play())).catch((t=>{this.onLoadError(t)}))}stopAnimation(){this.widgetVideo.hide()}async pick(t){if(!this.scene)throw new Error("No scene set");if(!this.view)throw new Error("No view set");if(!this.view.camera&&!this.view.cameraGroup)throw new Error("No camera set");const e={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return await this.viewWidget.pick(e,t)}async pickHotspot(t){const i=await this.pick(t),s=Object.values(i.point),n=e.v3.normalize(Object.values(i.normal)),o=e.v3.add(s,e.v3.mulScalar(n,.01));return i.point={x:o[0],y:o[1],z:o[2]},i}snapshot(t,e){return this.viewWidget.snapshot(t,e)}async loadWidget(t,e){if(!this.scene||!this.view)return Promise.resolve();if(!this.parameters.width||!this.parameters.height)return Promise.resolve();const i=this.viewWidget;if(!i)return Promise.reject(new Error("Unknown view mode"));const s={scene:this.scene,view:this.view,parameters:this.parameters,encoder:this.encoder};return s.view.background||(s.view.background="product"),i.load(s,this.hotspots,t,e).then((()=>{this.widget.hide(),this.widget=i,this.widget.show(),this.widgetVideo.hide(),this.onHotspotsChange()}))}get viewWidget(){var t,e;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 null!==(e=this.widgetVRCube)&&void 0!==e?e:this.widgetImage;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=this.container.clientWidth,e=this.container.clientHeight;this.resolution=c.getStandardResolution(t*window.devicePixelRatio,e*window.devicePixelRatio),this.parameters.width=this.resolution.width,this.parameters.height=this.resolution.height,this.canvas2D.resize(t,e,window.devicePixelRatio),this.canvas3D.resize(t,e,window.devicePixelRatio),this.video.resize(t,e,this.resolution,this.options.fit),this.loadWidget(!1,!1).then((()=>{this.onHotspotsChange()})).catch((t=>{this.onLoadError(t)}))}onVrcubeInteraction(...t){this.onHotspotsChange(),this.options.events.onInteraction(...t),this.options.events.onVrcubeInteraction(...t)}onVrobjectInteraction(t){this.onHotspotsChange(),this.options.events.onInteraction(t.position),this.options.events.onVrobjectInteraction(t.position)}onHotspotsChange(){const t=this.widget.hotspots(this.resolution);t.length&&this.options.events.onHotspotsChange(t)}onLoadStart(...t){this.container.classList.add("ls-viewer-container-loading"),this.options.events.onLoadStart(...t)}onLoadProgress(...t){this.options.events.onLoadProgress(...t)}onLoadEnd(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadEnd(...t)}onLoadError(...t){this.container.classList.remove("ls-viewer-container-loading"),this.options.events.onLoadError(...t)}},exports.WidgetImage=P,exports.WidgetVRCube=j,exports.WidgetVRObject=F,exports.WidgetVideo=A;
//# sourceMappingURL=index.js.map
{
"name": "@lumiscaphe/viewer",
"version": "4.1.9",
"version": "4.1.10",
"description": "Lumiscaphe 3D Viewer",

@@ -22,3 +22,3 @@ "main": "dist/index.js",

"devDependencies": {
"@rollup/plugin-commonjs": "~25.0.0",
"@rollup/plugin-commonjs": "~26.0.0",
"@rollup/plugin-eslint": "~9.0.0",

@@ -30,4 +30,4 @@ "@rollup/plugin-node-resolve": "~15.2.0",

"@types/regression": "~2.0.0",
"@typescript-eslint/eslint-plugin": "~7.4.0",
"@typescript-eslint/parser": "~7.4.0",
"@typescript-eslint/eslint-plugin": "~7.12.0",
"@typescript-eslint/parser": "~7.12.0",
"cross-env": "~7.0.0",

@@ -34,0 +34,0 @@ "eslint": "~8.57.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc