hexa-viewer-communicator
Version:
A simple API for <hexa-viewer>
2 lines • 27.4 kB
JavaScript
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i=t();for(var o in i)("object"==typeof exports?exports:e)[o]=i[o]}}(self,(()=>(()=>{var e={958:e=>{var t=function(e){"use strict";var t,i=Object.prototype,o=i.hasOwnProperty,n=Object.defineProperty||function(e,t,i){e[t]=i.value},r="function"==typeof Symbol?Symbol:{},s=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",d=r.toStringTag||"@@toStringTag";function c(e,t,i){return Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,i){return e[t]=i}}function h(e,t,i,o){var r=t&&t.prototype instanceof f?t:f,s=Object.create(r.prototype),a=new M(o||[]);return n(s,"_invoke",{value:R(e,i,a)}),s}function l(e,t,i){try{return{type:"normal",arg:e.call(t,i)}}catch(e){return{type:"throw",arg:e}}}e.wrap=h;var u="suspendedStart",_="suspendedYield",E="executing",v="completed",O={};function f(){}function m(){}function p(){}var g={};c(g,s,(function(){return this}));var T=Object.getPrototypeOf,y=T&&T(T(A([])));y&&y!==i&&o.call(y,s)&&(g=y);var w=p.prototype=f.prototype=Object.create(g);function b(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function N(e,t){function i(n,r,s,a){var d=l(e[n],e,r);if("throw"!==d.type){var c=d.arg,h=c.value;return h&&"object"==typeof h&&o.call(h,"__await")?t.resolve(h.__await).then((function(e){i("next",e,s,a)}),(function(e){i("throw",e,s,a)})):t.resolve(h).then((function(e){c.value=e,s(c)}),(function(e){return i("throw",e,s,a)}))}a(d.arg)}var r;n(this,"_invoke",{value:function(e,o){function n(){return new t((function(t,n){i(e,o,t,n)}))}return r=r?r.then(n,n):n()}})}function R(e,i,o){var n=u;return function(r,s){if(n===E)throw new Error("Generator is already running");if(n===v){if("throw"===r)throw s;return{value:t,done:!0}}for(o.method=r,o.arg=s;;){var a=o.delegate;if(a){var d=S(a,o);if(d){if(d===O)continue;return d}}if("next"===o.method)o.sent=o._sent=o.arg;else if("throw"===o.method){if(n===u)throw n=v,o.arg;o.dispatchException(o.arg)}else"return"===o.method&&o.abrupt("return",o.arg);n=E;var c=l(e,i,o);if("normal"===c.type){if(n=o.done?v:_,c.arg===O)continue;return{value:c.arg,done:o.done}}"throw"===c.type&&(n=v,o.method="throw",o.arg=c.arg)}}}function S(e,i){var o=i.method,n=e.iterator[o];if(n===t)return i.delegate=null,"throw"===o&&e.iterator.return&&(i.method="return",i.arg=t,S(e,i),"throw"===i.method)||"return"!==o&&(i.method="throw",i.arg=new TypeError("The iterator does not provide a '"+o+"' method")),O;var r=l(n,e.iterator,i.arg);if("throw"===r.type)return i.method="throw",i.arg=r.arg,i.delegate=null,O;var s=r.arg;return s?s.done?(i[e.resultName]=s.value,i.next=e.nextLoc,"return"!==i.method&&(i.method="next",i.arg=t),i.delegate=null,O):s:(i.method="throw",i.arg=new TypeError("iterator result is not an object"),i.delegate=null,O)}function L(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function M(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(L,this),this.reset(!0)}function A(e){if(null!=e){var i=e[s];if(i)return i.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,r=function i(){for(;++n<e.length;)if(o.call(e,n))return i.value=e[n],i.done=!1,i;return i.value=t,i.done=!0,i};return r.next=r}}throw new TypeError(typeof e+" is not iterable")}return m.prototype=p,n(w,"constructor",{value:p,configurable:!0}),n(p,"constructor",{value:m,configurable:!0}),m.displayName=c(p,d,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,c(e,d,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},b(N.prototype),c(N.prototype,a,(function(){return this})),e.AsyncIterator=N,e.async=function(t,i,o,n,r){void 0===r&&(r=Promise);var s=new N(h(t,i,o,n),r);return e.isGeneratorFunction(i)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},b(w),c(w,d,"Generator"),c(w,s,(function(){return this})),c(w,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),i=[];for(var o in t)i.push(o);return i.reverse(),function e(){for(;i.length;){var o=i.pop();if(o in t)return e.value=o,e.done=!1,e}return e.done=!0,e}},e.values=A,M.prototype={constructor:M,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(I),!e)for(var i in this)"t"===i.charAt(0)&&o.call(this,i)&&!isNaN(+i.slice(1))&&(this[i]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var i=this;function n(o,n){return a.type="throw",a.arg=e,i.next=o,n&&(i.method="next",i.arg=t),!!n}for(var r=this.tryEntries.length-1;r>=0;--r){var s=this.tryEntries[r],a=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var d=o.call(s,"catchLoc"),c=o.call(s,"finallyLoc");if(d&&c){if(this.prev<s.catchLoc)return n(s.catchLoc,!0);if(this.prev<s.finallyLoc)return n(s.finallyLoc)}else if(d){if(this.prev<s.catchLoc)return n(s.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return n(s.finallyLoc)}}}},abrupt:function(e,t){for(var i=this.tryEntries.length-1;i>=0;--i){var n=this.tryEntries[i];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var r=n;break}}r&&("break"===e||"continue"===e)&&r.tryLoc<=t&&t<=r.finallyLoc&&(r=null);var s=r?r.completion:{};return s.type=e,s.arg=t,r?(this.method="next",this.next=r.finallyLoc,O):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),O},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.finallyLoc===e)return this.complete(i.completion,i.afterLoc),I(i),O}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.tryLoc===e){var o=i.completion;if("throw"===o.type){var n=o.arg;I(i)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(e,i,o){return this.delegate={iterator:A(e),resultName:i,nextLoc:o},"next"===this.method&&(this.arg=t),O}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}},492:(e,t,i)=>{"use strict";var o,n,r,s,a,d,c,h,l,u;i.d(t,{Dl:()=>h,dJ:()=>o,gX:()=>u,oz:()=>l}),function(e){e[e.TOP=1]="TOP",e[e.MAIN=2]="MAIN",e[e.WORKER=3]="WORKER",e[e.IGNORE=4]="IGNORE"}(o||(o={})),function(e){e[e.INCH=1]="INCH",e[e.CM=2]="CM"}(n||(n={})),function(e){e[e.Z_INDEX=1]="Z_INDEX",e[e.REVERSE_PAINTRE_SORT_STABLE=2]="REVERSE_PAINTRE_SORT_STABLE",e[e.PAINTER_SORT_STABLE=3]="PAINTER_SORT_STABLE"}(r||(r={})),function(e){e[e.RepeatWrapping=1e3]="RepeatWrapping",e[e.ClampToEdgeWrapping=1001]="ClampToEdgeWrapping",e[e.MirroredRepeatWrapping=1002]="MirroredRepeatWrapping"}(s||(s={})),function(e){e[e.HOT_SPOT=1]="HOT_SPOT"}(a||(a={})),function(e){e[e.SCOPE=1]="SCOPE",e[e.EVAL=2]="EVAL"}(d||(d={})),function(e){e[e.LEGACY_ZOOM=1]="LEGACY_ZOOM",e[e.LEGACY_ROTATE=2]="LEGACY_ROTATE",e[e.INTERACTIVE_ROTATE=3]="INTERACTIVE_ROTATE"}(c||(c={})),function(e){e[e.glTF=1]="glTF",e[e.GLB=2]="GLB",e[e.OBJ=3]="OBJ",e[e.USDZ=4]="USDZ"}(h||(h={})),function(e){e[e.IMAGE=1]="IMAGE",e[e.VIDEO=2]="VIDEO"}(l||(l={})),function(e){e[e.IMAGE=1]="IMAGE",e[e.VIDEO=2]="VIDEO"}(u||(u={}))}},t={};function i(o){var n=t[o];if(void 0!==n)return n.exports;var r=t[o]={exports:{}};return e[o](r,r.exports,i),r.exports}i.d=(e,t)=>{for(var o in t)i.o(t,o)&&!i.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{"use strict";var e;i.r(o),i.d(o,{ViewerCommunicator:()=>c}),i(958),function(e){e[e.ON_VIEWER_LOADED=1]="ON_VIEWER_LOADED",e[e.ON_GET_MESHES_DATA=2]="ON_GET_MESHES_DATA",e[e.ON_COLLISIONS=3]="ON_COLLISIONS",e[e.ON_ADJUDT_SCENE=4]="ON_ADJUDT_SCENE",e[e.ON_APPLY_PRESET=5]="ON_APPLY_PRESET",e[e.ON_SET_SCENE_SUMMARY=6]="ON_SET_SCENE_SUMMARY",e[e.ON_CREATE_IMAGES_BY_TOUR=7]="ON_CREATE_IMAGES_BY_TOUR",e[e.ON_LIGHTS_SUMMARY=8]="ON_LIGHTS_SUMMARY",e[e.ON_CONFIGURATOR_SELECT_DONE=9]="ON_CONFIGURATOR_SELECT_DONE",e[e.ON_MODEL_INTERACTION=10]="ON_MODEL_INTERACTION",e[e.ON_SET_VIEWER_FULLY_LOADED=11]="ON_SET_VIEWER_FULLY_LOADED",e[e.ON_SCREENSHOT=12]="ON_SCREENSHOT",e[e.ON_MODEL_LOADED=13]="ON_MODEL_LOADED",e[e.ON_EXPORT=14]="ON_EXPORT",e[e.ON_SCREENSHOTS_SEQUENCE=15]="ON_SCREENSHOTS_SEQUENCE",e[e.ON_ANIMATE_ENTER_END=16]="ON_ANIMATE_ENTER_END",e[e.ON_BOUNDING_BOX=17]="ON_BOUNDING_BOX",e[e.ON_GET_MESHE_ANIMATIONS=18]="ON_GET_MESHE_ANIMATIONS",e[e.ON_GET_MATERIALS=19]="ON_GET_MATERIALS",e[e.ON_GET_DIAMONDS_OPTIONS=20]="ON_GET_DIAMONDS_OPTIONS",e[e.ON_VIEWER_LISTENING=21]="ON_VIEWER_LISTENING"}(e||(e={}));var t=i(492),n=function(e,t,i,o){return new(i||(i=Promise))((function(n,r){function s(e){try{d(o.next(e))}catch(e){r(e)}}function a(e){try{d(o.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))};class r{constructor(e){this.comm=e}preloadConfigurator(e,i){return n(this,void 0,void 0,(function*(){yield this.comm.onModelLoaded(),this.comm.sendToViewer({action:"configuratorPreload",data:[e,i],to:t.dJ.WORKER})}))}setConfigurator(e){return n(this,void 0,void 0,(function*(){yield this.comm.onModelLoaded(),this.comm.sendToViewer({action:"setConfigurator",data:[e],to:t.dJ.WORKER})}))}toggleConfiguratorUI(e){return n(this,void 0,void 0,(function*(){yield this.comm.onModelLoaded(),this.comm.sendToViewer({action:"toggleConfiguratorUI",data:[e],to:t.dJ.WORKER})}))}selectConfigurator(i){return n(this,void 0,void 0,(function*(){return new Promise(((o,r)=>n(this,void 0,void 0,(function*(){yield this.comm.onModelLoaded(),this.comm.eventObservable.add(e.ON_CONFIGURATOR_SELECT_DONE,o),this.comm.sendToViewer({action:"onConfiguratorSelect",data:[i],to:t.dJ.WORKER})}))))}))}setConfiguratorEffect(e){return n(this,void 0,void 0,(function*(){yield this.comm.onModelLoaded(),this.comm.sendToViewer({action:"setConfiguratorEffect",data:[e],to:t.dJ.WORKER})}))}}class s{constructor(){this._stack={}}initStock(e){this._stack[e]=[]}add(e,t){this._stack[e]||this.initStock(e),this._stack[e].push(t)}invoke(e,t,i){this._stack[e]||this.initStock(e),i?this._stack[e].forEach((e=>e(...i))):this._stack[e].forEach((e=>e())),t&&this.initStock(e)}destroy(){this._stack={}}}class a{constructor(e){this._codecs="h264",this.images=e,this.chunks=[],this.FPS=this.images.length/15,this.wrap=document.createElement("div"),this.wrap.style.cssText="\n position: absolute;\n top: 0;\n left: 0;\n overflow: hidden;\n opacity: 0.01;\n z-index: -9999999;\n max-width: 100%;\n ",this.canvas=document.createElement("canvas"),this.wrap.appendChild(this.canvas)}get codecs(){return this._codecs}set codecs(e){this._codecs=e}getVideo(){return new Promise(((e,t)=>{this.resolve=e,document.body.appendChild(this.wrap),this.frame=0,this.ctx=this.canvas.getContext("2d",{alpha:!0});const i=new Image;i.onload=()=>{this.canvas.width=i.naturalWidth,this.canvas.height=i.naturalHeight,this.start(),this.anim()},i.src=this.images[0]}))}setTimeout(e){return new Promise(((t,i)=>{setTimeout((()=>{t()}),e)}))}anim(){const e=new Image;e.onload=()=>{return t=this,i=void 0,n=function*(){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.drawImage(e,0,0),++this.frame<this.images.length?(yield this.setTimeout(1e3/this.FPS),requestAnimationFrame(this.anim.bind(this))):this.stopRecording()},new((o=void 0)||(o=Promise))((function(e,r){function s(e){try{d(n.next(e))}catch(e){r(e)}}function a(e){try{d(n.throw(e))}catch(e){r(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o((function(e){e(i)}))).then(s,a)}d((n=n.apply(t,i||[])).next())}));var t,i,o,n},e.src=this.images[this.frame]}start(){this.cStream=this.canvas.captureStream(30);const e={mimeType:`video/webm;codecs=${this.codecs}`};this.recorder=new MediaRecorder(this.cStream,e),this.recorder.start(),this.recorder.ondataavailable=this.saveChunks.bind(this),this.recorder.onstop=this.exportStream.bind(this)}saveChunks(e){this.chunks.push(e.data)}stopRecording(){this.recorder.stop()}exportStream(e){var t=new Blob(this.chunks,{type:"video/webm"});this.resolve(t),this.wrap.remove()}}var d=function(e,t,i,o){return new(i||(i=Promise))((function(n,r){function s(e){try{d(o.next(e))}catch(e){r(e)}}function a(e){try{d(o.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))};class c{constructor(e){this._hasDestroyed=!1,e=e||{},this._hexaViewer=e.hexaViewer,this._isViewerLoaded=!1,this._isModelLoaded=!1,this._isAnimateEnterEnd=!1,this._onLoadingProgress=[],this.initFrameID(),this.attachEvents(),this.initEventObservable(),this.configurator=new r(this),this._updateViewerFullyLoaded()}get hexaViewer(){return this._hexaViewer}set hexaViewer(e){this.attachInstance(e)}get eventObservable(){return this._eventObservable}get isModelLoaded(){return this._isViewerLoaded}get hasDestroyed(){return this._hasDestroyed}get isViewerListening(){return this._isViewerListening}set isViewerListening(t){this._isViewerListening=t,this._isViewerListening&&this._eventObservable.invoke(e.ON_VIEWER_LISTENING,!1)}set isModelLoaded(e){e?this._onViewerFullyLoaded():this._isViewerLoaded=e}initEventObservable(){this._eventObservable=new s}attachInstance(e){this._hexaViewer=e,this.initFrameID()}initFrameID(e){(e=e||this._hexaViewer)&&(this._frameID=e.getAttribute("frame-id"),this._frameID||(this._frameID=this.generateUUID(),e.setAttribute("frame-id",this._frameID)))}attachEvents(){this._onMessageBind=this.onMessage.bind(this),self.addEventListener("message",this._onMessageBind,!1)}onMessage(t){var i;const o=this.safeParse(t.data);if(o){if(this._frameID&&o.id&&this._frameID!==o.id)return;switch(o.action){case"viewerListening":this.isViewerListening=!0;break;case"viewerFullyLoaded":this._onViewerFullyLoaded();break;case"onModelLoaded":this._onModelLoaded();break;case"onAnimateEnterEnd":this._onAnimateEnterEnd();break;case"setMeshesData":this._onMeshesData(o.data);break;case"setMeshAnimations":this._onMeshAnimations(o.data);break;case"setCollisions":this._eventObservable.invoke(e.ON_COLLISIONS,!1,[o.data]);break;case"setSceneSummary":(null===(i=o.data)||void 0===i?void 0:i.autoAdjustScene)&&this._eventObservable.invoke(e.ON_ADJUDT_SCENE,!0,[o.data]),this._eventObservable.invoke(e.ON_SET_SCENE_SUMMARY,!0,[o.data]);break;case"setAttachJsonScene":this._eventObservable.invoke(e.ON_APPLY_PRESET,!0);break;case"create_images_by_tour":this._eventObservable.invoke(e.ON_CREATE_IMAGES_BY_TOUR,!0,[o.data]);break;case"onLightsSummary":this._eventObservable.invoke(e.ON_LIGHTS_SUMMARY,!0,[o.data]);break;case"onConfiguratorSelectDone":this._eventObservable.invoke(e.ON_CONFIGURATOR_SELECT_DONE,!0,[o.data]);break;case"onModelInteraction":this._eventObservable.invoke(e.ON_MODEL_INTERACTION,!1,[o.data.type]);break;case"setViewerFullyLoaded":this._eventObservable.invoke(e.ON_SET_VIEWER_FULLY_LOADED,!0,[o.data]);break;case"setCurrentScreenshot":this._eventObservable.invoke(e.ON_SCREENSHOT,!0,[o.data]);break;case"onScreenshotsSequence":this._eventObservable.invoke(e.ON_SCREENSHOTS_SEQUENCE,!0,[o.data.images]);break;case"setModel":this._eventObservable.invoke(e.ON_EXPORT,!0,[o.data]);break;case"setBoundingBox":this._eventObservable.invoke(e.ON_BOUNDING_BOX,!0,[o.data]);break;case"setMaterials":this._eventObservable.invoke(e.ON_GET_MATERIALS,!0,[o.data]);break;case"setDiamondEffectOptions":this._eventObservable.invoke(e.ON_GET_DIAMONDS_OPTIONS,!0,[o.data]);break;case"setLoadingPercentage":this._onLoadingProgress.forEach((e=>e(o.data)))}}}_checkModelLoaded(){this._isViewerLoaded&&(this._isModelLoaded||this._isAnimateEnterEnd)&&this._eventObservable.invoke(e.ON_MODEL_LOADED,!0)}_onAnimateEnterEnd(){this._isAnimateEnterEnd=!0,this._checkModelLoaded(),this._eventObservable.invoke(e.ON_ANIMATE_ENTER_END,!0)}_onModelLoaded(){this._isModelLoaded=!0,this._checkModelLoaded()}_onViewerFullyLoaded(){this._isModelLoaded=!0,this._isViewerLoaded=!0,this._eventObservable.invoke(e.ON_VIEWER_LOADED,!0),this._checkModelLoaded()}_onMeshesData(t){this._meshesData=t,this.isModelLoaded=!0,this._eventObservable.invoke(e.ON_GET_MESHES_DATA,!0,[this._meshesData])}_onMeshAnimations(t){this._mesheAnimations=t,this._eventObservable.invoke(e.ON_GET_MESHE_ANIMATIONS,!0,[this._mesheAnimations])}_updateViewerFullyLoaded(){return new Promise(((i,o)=>{this._eventObservable.add(e.ON_SET_VIEWER_FULLY_LOADED,(e=>{this._isViewerLoaded=e,this._isViewerLoaded&&(this.onModelLoaded(),this._isViewerListening=!0,this._onViewerFullyLoaded()),i()}));const n={action:"broadcastViewerFullyLoaded",to:t.dJ.WORKER};this.sendToViewer(n)}))}onModelLoaded(){return new Promise(((t,i)=>{this._isViewerLoaded?t():this._eventObservable.add(e.ON_VIEWER_LOADED,t)}))}onModelReady(){return new Promise(((t,i)=>{this._isModelLoaded?t():this._eventObservable.add(e.ON_MODEL_LOADED,t)}))}onViewerListening(){return new Promise(((t,i)=>{this._isViewerListening?t():this._eventObservable.add(e.ON_VIEWER_LISTENING,t)}))}onAnimateEnterEnd(){return new Promise(((t,i)=>{this._isAnimateEnterEnd?t():this._eventObservable.add(e.ON_ANIMATE_ENTER_END,t)}))}getMeshesData(){return new Promise(((i,o)=>{this._eventObservable.add(e.ON_GET_MESHES_DATA,i);const n={action:"getMeshesData",to:t.dJ.WORKER};this.sendToViewer(n)}))}getMeshAnimations(){return new Promise(((i,o)=>{this._eventObservable.add(e.ON_GET_MESHE_ANIMATIONS,i);const n={action:"broadcastMeshAnimations",to:t.dJ.WORKER};this.sendToViewer(n)}))}getMaterials(){return new Promise(((i,o)=>{this._eventObservable.add(e.ON_GET_MATERIALS,i);const n={action:"broadcastMaterials",to:t.dJ.WORKER};this.sendToViewer(n)}))}updateMeshAnimations(e){this.sendToViewer({action:"updateMeshAnimations",to:t.dJ.WORKER,value:{meshAnimations:e}})}safeParse(e){if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e}generateUUID(){var e=(new Date).getTime();return window.performance&&"function"==typeof window.performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{var i=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?i:3&i|8).toString(16)}))}materializeMesh(e,i){const o={action:"materializeMesh",to:t.dJ.WORKER,value:{name:e,config:i}};this.sendToViewer(o)}sendToViewer(e){this._frameID&&(e.id=this._frameID),self.postMessage(e,location.origin)}createInstanceFromUrl(e,t={},i){return d(this,void 0,void 0,(function*(){i=i||{};var o=document.createElement("hexa-viewer"),n=this.getUrlParams(e),r=Object.assign(n,t);void 0===r.server&&(r.server="1"),void 0===r["frame-id"]&&(r["frame-id"]=this.generateUUID()),i.enableWebXR&&(yield this.isWebXrSupported())&&(r.offscreen="false"),i.themeColor&&(r["theme-color"]=i.themeColor);for(let e in r)e&&o.setAttribute(e,null===r[e]?"":r[e]);return this.initFrameID(o),o}))}getUrlParams(e){let t={},i="";if(e.indexOf("?")>-1&&(i=e.substring(e.indexOf("?")+1)),!i)return t;i=i.split("+").join(" ");let o=i.split("&");for(let e=0;e<o.length;e++){let i=o[e].split("=");if(void 0===t[i[0]])t[i[0]]=i[1]?decodeURIComponent(i[1]):null;else if("string"==typeof t[i[0]]){let e=[t[i[0]],decodeURIComponent(i[1])];t[i[0]]=e}else t[i[0]].push(decodeURIComponent(i[1]))}return t}togglePicInPic(e){const i={action:"togglePicInPic",to:t.dJ.MAIN,value:e};this.sendToViewer(i)}toggleWireframe(e){const i={action:"toggleWireframe",to:t.dJ.WORKER,value:e};this.sendToViewer(i)}toggleUvMode(e){const i={action:"toggleUvMode",to:t.dJ.WORKER,value:e};this.sendToViewer(i)}toggleMatcapMode(e,i){const o={action:"toggleMatcapMode",data:i,to:t.dJ.WORKER,value:e};this.sendToViewer(o)}toggleHideBottom(e){const i={action:"toggleHideBottom",to:t.dJ.WORKER,value:e};this.sendToViewer(i)}isWebXrSupported(){return new Promise(((e,t)=>{if("boolean"==typeof this._xrSupport)return void e(this._xrSupport);const i=navigator;if(!i.xr||!i.xr.isSessionSupported)return this._xrSupport=!1,void e(this._xrSupport);try{i.xr.isSessionSupported("immersive-ar").then((t=>{this._xrSupport=t,e(this._xrSupport)}),(t=>{this._xrSupport=!1,e(this._xrSupport)}))}catch(t){this._xrSupport=!1,e(this._xrSupport)}}))}toggleWebXR(e,t=!0){const i={action:"toggleXr",obj:{state:e,value:t,showIcon:!0}};this.sendToViewer(i)}toggleAR(e,t=!0){const i={action:"toggleAR",obj:{state:e,value:t}};this.sendToViewer(i)}waitForCollisions(){return new Promise(((t,i)=>{this._eventObservable.add(e.ON_COLLISIONS,t)}))}toggleCollision(e,i){this.sendToViewer({action:"toggleCollision",to:t.dJ.WORKER,value:{value:e,color:i}})}deleteCollision(e,i){this.sendToViewer({action:"spliceCollision",to:t.dJ.WORKER,value:{value:e,count:i}})}removeAllCollisions(){this.sendToViewer({action:"removeAllCollisions",to:t.dJ.WORKER})}adjustScene(){return new Promise(((i,o)=>d(this,void 0,void 0,(function*(){this._eventObservable.add(e.ON_ADJUDT_SCENE,i),yield this.onModelLoaded(),this.sendToViewer({action:"adjustScene",to:t.dJ.WORKER})}))))}applyPreset(i){return new Promise(((o,n)=>d(this,void 0,void 0,(function*(){this._eventObservable.add(e.ON_APPLY_PRESET,o),yield this.onModelLoaded(),this.sendToViewer({action:"attachJsonScene",to:t.dJ.WORKER,data:i})}))))}applyHDRI(e){this.sendToViewer({action:"setHDR",to:t.dJ.WORKER,value:e.type,options:e})}applyShadowPlane(e){this.sendToViewer({action:"togglePlane",to:t.dJ.WORKER,value:e.opacity,options:{active:e.active,color:e.color,opacity:e.opacity,physical:e.physical,physicalOptions:e.physicalOptions,reflector:e.reflector,side:e.side}})}broadcastSceneSummary(i){return new Promise(((o,n)=>{this._eventObservable.add(e.ON_SET_SCENE_SUMMARY,o),this.sendToViewer({action:"broadcastSceneSummary",to:t.dJ.WORKER,value:i})}))}setLightsByJson(i){return new Promise(((o,n)=>{this._eventObservable.add(e.ON_LIGHTS_SUMMARY,o),this.sendToViewer({action:"setLightsByJson",value:i,to:t.dJ.WORKER})}))}onCreateImagesByTour(){return new Promise(((t,i)=>d(this,void 0,void 0,(function*(){this._eventObservable.add(e.ON_CREATE_IMAGES_BY_TOUR,t)}))))}setMeshProps(e){const i={name:e.mesh.name,props:{}};i.props[e.key]=e.value,this._meshesData[i.name]||(this._meshesData[i.name]={}),this._meshesData[i.name][e.key]=e.value,this.sendToViewer({action:"setMeshProps",to:t.dJ.WORKER,value:i})}appendDynamicElement(e,i,o=".body"){this.sendToViewer({action:"appendElement",to:t.dJ.MAIN,obj:{obj:e,events:i,selectorToAppend:o}})}controlsTutorial(e){this.sendToViewer({action:"startZoomTutorial",to:t.dJ.WORKER,value:e})}toggleAutoRotate(e){this.sendToViewer({action:"toggleAutoRotate",to:t.dJ.WORKER,data:e})}onModelInteraction(t){return new Promise(((i,o)=>{this._eventObservable.add(e.ON_MODEL_INTERACTION,(e=>{t&&t(e),i(e)}))}))}goToInitialCamPos(){this.sendToViewer({action:"goToInitialCamPos",to:t.dJ.WORKER})}getCurrentScreenshot(){return new Promise(((i,o)=>d(this,void 0,void 0,(function*(){this._eventObservable.add(e.ON_SCREENSHOT,i),yield this.onAnimateEnterEnd(),this.sendToViewer({action:"getCurrentScreenshot",to:t.dJ.WORKER})}))))}expotModel(i){return new Promise(((o,n)=>d(this,void 0,void 0,(function*(){i.downloadFile||this._eventObservable.add(e.ON_EXPORT,o),yield this.onModelReady();let n="",r=null;switch(i.type){case t.Dl.GLB:case t.Dl.glTF:n="broadcastGLTF",r={binary:i.type===t.Dl.GLB,trs:!1,onlyVisible:!0,truncateDrawRange:!1,embedImages:!0,forceIndices:!0,forcePowerOfTwoTextures:!0,imagesFileType:null,normalImagesFileType:null,mroImagesFileType:null,imagesCompressionFactor:null,downloadFile:i.downloadFile,maxTexturesSize:null,maxDiffuseTexturesSize:null,maxNormalTexturesSize:null,maxMroTexturesSize:null,optipng:i.compressPNG,simplify:!1,deleteUV2:!1};break;case t.Dl.USDZ:n="broadcastUSDZ";break;case t.Dl.OBJ:n="broadcastOBJ";break;default:n="broadcastGLTF"}this.sendToViewer({action:n,value:r,to:t.dJ.WORKER}),i.downloadFile&&o(null)}))))}getScreenshotsSequence(i){return new Promise(((o,n)=>d(this,void 0,void 0,(function*(){this._eventObservable.add(e.ON_SCREENSHOTS_SEQUENCE,(e=>d(this,void 0,void 0,(function*(){if(i.format===t.oz.VIDEO){const t=new a(e);i.codec&&(t.codecs=i.codec),o(yield t.getVideo())}else o(e)})))),yield this.onModelReady(),yield this.onAnimateEnterEnd();const n={};i&&(n.ggNumOfFrames=i.numOfFrames),n.msgObj={data:{},action:"onScreenshotsSequence",to:t.dJ.TOP,from:t.dJ.WORKER},this.sendToViewer({action:"broadcastGifSequence",to:t.dJ.WORKER,data:{options:n}})}))))}applyTexture(e){this.sendToViewer({action:"mapTextureToMaterial",to:t.dJ.WORKER,value:{texture:e.src,material:e.materialName,options:{map:e.mapType,intensity:e.intensity,textureSrc:e.src,srcChange:!!e.src,color:e.color,videoSrc:e.mimeType===t.gX.VIDEO?e.src:null}}})}setMaterialProps(e){this.sendToViewer({action:"setMaterialProps",to:t.dJ.WORKER,value:{name:e.materialName,props:e.props}})}swapMaterialType(e){this.sendToViewer({action:"swapMaterialType",to:t.dJ.WORKER,value:{name:e.materialName,newType:e.type}})}displayFiles(e){this.sendToViewer({action:"displayFiles",to:t.dJ.MAIN,value:{files:e}})}getBoundingBox(){return new Promise(((i,o)=>d(this,void 0,void 0,(function*(){yield this.onModelReady(),this._eventObservable.add(e.ON_BOUNDING_BOX,i),this.sendToViewer({action:"broadcastBoundingBox",to:t.dJ.WORKER})}))))}toggleNoDistanceLimit(e){return d(this,void 0,void 0,(function*(){yield this.onModelReady(),this.sendToViewer({action:"toggleNoDistanceLimit",to:t.dJ.WORKER,value:e})}))}toggleCloseup(e){return d(this,void 0,void 0,(function*(){yield this.onModelReady(),this.sendToViewer({action:"toggleCloseup",to:t.dJ.WORKER,value:e})}))}setCameraPosition(e){return d(this,void 0,void 0,(function*(){yield this.onModelReady(),this.sendToViewer({action:"setCameraPosition",to:t.dJ.WORKER,value:e})}))}setDiamonds(e,i,o){return d(this,void 0,void 0,(function*(){yield this.onModelReady(),this.sendToViewer({action:"toggleDiamond",to:t.dJ.WORKER,value:{state:e,meshes:i,options:o}})}))}getDiamondsOptions(){return new Promise(((i,o)=>{this._eventObservable.add(e.ON_GET_DIAMONDS_OPTIONS,i);const n={action:"broadcastDiamondEffectOptions",to:t.dJ.WORKER};this.sendToViewer(n)}))}registerForLoadingProgress(e){this._onLoadingProgress.push(e)}destroy(){this._hasDestroyed=!0,this._eventObservable.destroy(),this._isViewerListening=!1,this._isViewerLoaded=!1,this._isModelLoaded=!1,this._isAnimateEnterEnd=!1,this._onLoadingProgress=[],self.removeEventListener("message",this._onMessageBind,!1)}}})(),o})()));
//# sourceMappingURL=viewer-communicator.bundle.js.map