hexa-viewer-communicator
Version:
A simple API for <hexa-viewer>
2 lines • 35.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 o=t();for(var i in o)("object"==typeof exports?exports:e)[i]=o[i]}}(self,(()=>(()=>{var e={958:e=>{var t=function(e){"use strict";var t,o=Object.prototype,i=o.hasOwnProperty,n=Object.defineProperty||function(e,t,o){e[t]=o.value},r="function"==typeof Symbol?Symbol:{},a=r.iterator||"@@iterator",s=r.asyncIterator||"@@asyncIterator",d=r.toStringTag||"@@toStringTag";function c(e,t,o){return Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,o){return e[t]=o}}function l(e,t,o,i){var r=t&&t.prototype instanceof f?t:f,a=Object.create(r.prototype),s=new M(i||[]);return n(a,"_invoke",{value:N(e,o,s)}),a}function h(e,t,o){try{return{type:"normal",arg:e.call(t,o)}}catch(e){return{type:"throw",arg:e}}}e.wrap=l;var u="suspendedStart",v="suspendedYield",m="executing",_="completed",p={};function f(){}function E(){}function g(){}var O={};c(O,a,(function(){return this}));var y=Object.getPrototypeOf,b=y&&y(y(x([])));b&&b!==o&&i.call(b,a)&&(O=b);var w=g.prototype=f.prototype=Object.create(O);function T(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function R(e,t){function o(n,r,a,s){var d=h(e[n],e,r);if("throw"!==d.type){var c=d.arg,l=c.value;return l&&"object"==typeof l&&i.call(l,"__await")?t.resolve(l.__await).then((function(e){o("next",e,a,s)}),(function(e){o("throw",e,a,s)})):t.resolve(l).then((function(e){c.value=e,a(c)}),(function(e){return o("throw",e,a,s)}))}s(d.arg)}var r;n(this,"_invoke",{value:function(e,i){function n(){return new t((function(t,n){o(e,i,t,n)}))}return r=r?r.then(n,n):n()}})}function N(e,o,i){var n=u;return function(r,a){if(n===m)throw new Error("Generator is already running");if(n===_){if("throw"===r)throw a;return{value:t,done:!0}}for(i.method=r,i.arg=a;;){var s=i.delegate;if(s){var d=S(s,i);if(d){if(d===p)continue;return d}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(n===u)throw n=_,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);n=m;var c=h(e,o,i);if("normal"===c.type){if(n=i.done?_:v,c.arg===p)continue;return{value:c.arg,done:i.done}}"throw"===c.type&&(n=_,i.method="throw",i.arg=c.arg)}}}function S(e,o){var i=o.method,n=e.iterator[i];if(n===t)return o.delegate=null,"throw"===i&&e.iterator.return&&(o.method="return",o.arg=t,S(e,o),"throw"===o.method)||"return"!==i&&(o.method="throw",o.arg=new TypeError("The iterator does not provide a '"+i+"' method")),p;var r=h(n,e.iterator,o.arg);if("throw"===r.type)return o.method="throw",o.arg=r.arg,o.delegate=null,p;var a=r.arg;return a?a.done?(o[e.resultName]=a.value,o.next=e.nextLoc,"return"!==o.method&&(o.method="next",o.arg=t),o.delegate=null,p):a:(o.method="throw",o.arg=new TypeError("iterator result is not an object"),o.delegate=null,p)}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 x(e){if(null!=e){var o=e[a];if(o)return o.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,r=function o(){for(;++n<e.length;)if(i.call(e,n))return o.value=e[n],o.done=!1,o;return o.value=t,o.done=!0,o};return r.next=r}}throw new TypeError(typeof e+" is not iterable")}return E.prototype=g,n(w,"constructor",{value:g,configurable:!0}),n(g,"constructor",{value:E,configurable:!0}),E.displayName=c(g,d,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===E||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,g):(e.__proto__=g,c(e,d,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},T(R.prototype),c(R.prototype,s,(function(){return this})),e.AsyncIterator=R,e.async=function(t,o,i,n,r){void 0===r&&(r=Promise);var a=new R(l(t,o,i,n),r);return e.isGeneratorFunction(o)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},T(w),c(w,d,"Generator"),c(w,a,(function(){return this})),c(w,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),o=[];for(var i in t)o.push(i);return o.reverse(),function e(){for(;o.length;){var i=o.pop();if(i in t)return e.value=i,e.done=!1,e}return e.done=!0,e}},e.values=x,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 o in this)"t"===o.charAt(0)&&i.call(this,o)&&!isNaN(+o.slice(1))&&(this[o]=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 o=this;function n(i,n){return s.type="throw",s.arg=e,o.next=i,n&&(o.method="next",o.arg=t),!!n}for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r],s=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var d=i.call(a,"catchLoc"),c=i.call(a,"finallyLoc");if(d&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(d){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(e,t){for(var o=this.tryEntries.length-1;o>=0;--o){var n=this.tryEntries[o];if(n.tryLoc<=this.prev&&i.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 a=r?r.completion:{};return a.type=e,a.arg=t,r?(this.method="next",this.next=r.finallyLoc,p):this.complete(a)},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),p},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var o=this.tryEntries[t];if(o.finallyLoc===e)return this.complete(o.completion,o.afterLoc),I(o),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var o=this.tryEntries[t];if(o.tryLoc===e){var i=o.completion;if("throw"===i.type){var n=i.arg;I(o)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(e,o,i){return this.delegate={iterator:x(e),resultName:o,nextLoc:i},"next"===this.method&&(this.arg=t),p}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}},492:(e,t,o)=>{"use strict";var i,n,r,a,s,d,c,l,h,u;o.d(t,{Dl:()=>l,dJ:()=>i,gX:()=>u,oz:()=>h}),function(e){e[e.TOP=1]="TOP",e[e.MAIN=2]="MAIN",e[e.WORKER=3]="WORKER",e[e.IGNORE=4]="IGNORE"}(i||(i={})),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"}(a||(a={})),function(e){e[e.HOT_SPOT=1]="HOT_SPOT"}(s||(s={})),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"}(l||(l={})),function(e){e[e.IMAGE=1]="IMAGE",e[e.VIDEO=2]="VIDEO"}(h||(h={})),function(e){e[e.IMAGE=1]="IMAGE",e[e.VIDEO=2]="VIDEO"}(u||(u={}))},516:(e,t,o)=>{"use strict";var i;o.d(t,{ViewerCommunicator:()=>l}),o(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"}(i||(i={}));var n=o(492),r=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function a(e){try{d(i.next(e))}catch(e){r(e)}}function s(e){try{d(i.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,s)}d((i=i.apply(e,t||[])).next())}))};class a{constructor(e){this.comm=e}preloadConfigurator(e,t){return r(this,void 0,void 0,(function*(){yield this.comm.onModelLoaded(),this.comm.sendToViewer({action:"configuratorPreload",data:[e,t],to:n.dJ.WORKER})}))}setConfigurator(e){return r(this,void 0,void 0,(function*(){yield this.comm.onModelLoaded(),this.comm.sendToViewer({action:"setConfigurator",data:[e],to:n.dJ.WORKER})}))}toggleConfiguratorUI(e){return r(this,void 0,void 0,(function*(){yield this.comm.onModelLoaded(),this.comm.sendToViewer({action:"toggleConfiguratorUI",data:[e],to:n.dJ.WORKER})}))}selectConfigurator(e){return r(this,void 0,void 0,(function*(){return new Promise(((t,o)=>r(this,void 0,void 0,(function*(){yield this.comm.onModelLoaded(),this.comm.eventObservable.add(i.ON_CONFIGURATOR_SELECT_DONE,t),this.comm.sendToViewer({action:"onConfiguratorSelect",data:[e],to:n.dJ.WORKER})}))))}))}setConfiguratorEffect(e){return r(this,void 0,void 0,(function*(){yield this.comm.onModelLoaded(),this.comm.sendToViewer({action:"setConfiguratorEffect",data:[e],to:n.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,o){this._stack[e]||this.initStock(e),o?this._stack[e].forEach((e=>e(...o))):this._stack[e].forEach((e=>e())),t&&this.initStock(e)}destroy(){this._stack={}}}class d{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 o=new Image;o.onload=()=>{this.canvas.width=o.naturalWidth,this.canvas.height=o.naturalHeight,this.start(),this.anim()},o.src=this.images[0]}))}setTimeout(e){return new Promise(((t,o)=>{setTimeout((()=>{t()}),e)}))}anim(){const e=new Image;e.onload=()=>{return t=this,o=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((i=void 0)||(i=Promise))((function(e,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(t){var o;t.done?e(t.value):(o=t.value,o instanceof i?o:new i((function(e){e(o)}))).then(a,s)}d((n=n.apply(t,o||[])).next())}));var t,o,i,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 c=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function a(e){try{d(i.next(e))}catch(e){r(e)}}function s(e){try{d(i.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,s)}d((i=i.apply(e,t||[])).next())}))};class l{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 a(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(e){this._isViewerListening=e,this._isViewerListening&&this._eventObservable.invoke(i.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(e){var t;const o=this.safeParse(e.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(i.ON_COLLISIONS,!1,[o.data]);break;case"setSceneSummary":(null===(t=o.data)||void 0===t?void 0:t.autoAdjustScene)&&this._eventObservable.invoke(i.ON_ADJUDT_SCENE,!0,[o.data]),this._eventObservable.invoke(i.ON_SET_SCENE_SUMMARY,!0,[o.data]);break;case"setAttachJsonScene":this._eventObservable.invoke(i.ON_APPLY_PRESET,!0);break;case"create_images_by_tour":this._eventObservable.invoke(i.ON_CREATE_IMAGES_BY_TOUR,!0,[o.data]);break;case"onLightsSummary":this._eventObservable.invoke(i.ON_LIGHTS_SUMMARY,!0,[o.data]);break;case"onConfiguratorSelectDone":this._eventObservable.invoke(i.ON_CONFIGURATOR_SELECT_DONE,!0,[o.data]);break;case"onModelInteraction":this._eventObservable.invoke(i.ON_MODEL_INTERACTION,!1,[o.data.type]);break;case"setViewerFullyLoaded":this._eventObservable.invoke(i.ON_SET_VIEWER_FULLY_LOADED,!0,[o.data]);break;case"setCurrentScreenshot":this._eventObservable.invoke(i.ON_SCREENSHOT,!0,[o.data]);break;case"onScreenshotsSequence":this._eventObservable.invoke(i.ON_SCREENSHOTS_SEQUENCE,!0,[o.data.images]);break;case"setModel":this._eventObservable.invoke(i.ON_EXPORT,!0,[o.data]);break;case"setBoundingBox":this._eventObservable.invoke(i.ON_BOUNDING_BOX,!0,[o.data]);break;case"setMaterials":this._eventObservable.invoke(i.ON_GET_MATERIALS,!0,[o.data]);break;case"setDiamondEffectOptions":this._eventObservable.invoke(i.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(i.ON_MODEL_LOADED,!0)}_onAnimateEnterEnd(){this._isAnimateEnterEnd=!0,this._checkModelLoaded(),this._eventObservable.invoke(i.ON_ANIMATE_ENTER_END,!0)}_onModelLoaded(){this._isModelLoaded=!0,this._checkModelLoaded()}_onViewerFullyLoaded(){this._isModelLoaded=!0,this._isViewerLoaded=!0,this._eventObservable.invoke(i.ON_VIEWER_LOADED,!0),this._checkModelLoaded()}_onMeshesData(e){this._meshesData=e,this.isModelLoaded=!0,this._eventObservable.invoke(i.ON_GET_MESHES_DATA,!0,[this._meshesData])}_onMeshAnimations(e){this._mesheAnimations=e,this._eventObservable.invoke(i.ON_GET_MESHE_ANIMATIONS,!0,[this._mesheAnimations])}_updateViewerFullyLoaded(){return new Promise(((e,t)=>{this._eventObservable.add(i.ON_SET_VIEWER_FULLY_LOADED,(t=>{this._isViewerLoaded=t,this._isViewerLoaded&&(this.onModelLoaded(),this._isViewerListening=!0,this._onViewerFullyLoaded()),e()}));const o={action:"broadcastViewerFullyLoaded",to:n.dJ.WORKER};this.sendToViewer(o)}))}onModelLoaded(){return new Promise(((e,t)=>{this._isViewerLoaded?e():this._eventObservable.add(i.ON_VIEWER_LOADED,e)}))}onModelReady(){return new Promise(((e,t)=>{this._isModelLoaded?e():this._eventObservable.add(i.ON_MODEL_LOADED,e)}))}onViewerListening(){return new Promise(((e,t)=>{this._isViewerListening?e():this._eventObservable.add(i.ON_VIEWER_LISTENING,e)}))}onAnimateEnterEnd(){return new Promise(((e,t)=>{this._isAnimateEnterEnd?e():this._eventObservable.add(i.ON_ANIMATE_ENTER_END,e)}))}getMeshesData(){return new Promise(((e,t)=>{this._eventObservable.add(i.ON_GET_MESHES_DATA,e);const o={action:"getMeshesData",to:n.dJ.WORKER};this.sendToViewer(o)}))}getMeshAnimations(){return new Promise(((e,t)=>{this._eventObservable.add(i.ON_GET_MESHE_ANIMATIONS,e);const o={action:"broadcastMeshAnimations",to:n.dJ.WORKER};this.sendToViewer(o)}))}getMaterials(){return new Promise(((e,t)=>{this._eventObservable.add(i.ON_GET_MATERIALS,e);const o={action:"broadcastMaterials",to:n.dJ.WORKER};this.sendToViewer(o)}))}updateMeshAnimations(e){this.sendToViewer({action:"updateMeshAnimations",to:n.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 o=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?o:3&o|8).toString(16)}))}materializeMesh(e,t){const o={action:"materializeMesh",to:n.dJ.WORKER,value:{name:e,config:t}};this.sendToViewer(o)}sendToViewer(e){this._frameID&&(e.id=this._frameID),self.postMessage(e,location.origin)}createInstanceFromUrl(e,t={},o){return c(this,void 0,void 0,(function*(){o=o||{};var i=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()),o.enableWebXR&&(yield this.isWebXrSupported())&&(r.offscreen="false"),o.themeColor&&(r["theme-color"]=o.themeColor);for(let e in r)e&&i.setAttribute(e,null===r[e]?"":r[e]);return this.initFrameID(i),i}))}getUrlParams(e){let t={},o="";if(e.indexOf("?")>-1&&(o=e.substring(e.indexOf("?")+1)),!o)return t;o=o.split("+").join(" ");let i=o.split("&");for(let e=0;e<i.length;e++){let o=i[e].split("=");if(void 0===t[o[0]])t[o[0]]=o[1]?decodeURIComponent(o[1]):null;else if("string"==typeof t[o[0]]){let e=[t[o[0]],decodeURIComponent(o[1])];t[o[0]]=e}else t[o[0]].push(decodeURIComponent(o[1]))}return t}togglePicInPic(e){const t={action:"togglePicInPic",to:n.dJ.MAIN,value:e};this.sendToViewer(t)}toggleWireframe(e){const t={action:"toggleWireframe",to:n.dJ.WORKER,value:e};this.sendToViewer(t)}toggleUvMode(e){const t={action:"toggleUvMode",to:n.dJ.WORKER,value:e};this.sendToViewer(t)}toggleMatcapMode(e,t){const o={action:"toggleMatcapMode",data:t,to:n.dJ.WORKER,value:e};this.sendToViewer(o)}toggleHideBottom(e){const t={action:"toggleHideBottom",to:n.dJ.WORKER,value:e};this.sendToViewer(t)}isWebXrSupported(){return new Promise(((e,t)=>{if("boolean"==typeof this._xrSupport)return void e(this._xrSupport);const o=navigator;if(!o.xr||!o.xr.isSessionSupported)return this._xrSupport=!1,void e(this._xrSupport);try{o.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 o={action:"toggleXr",obj:{state:e,value:t,showIcon:!0}};this.sendToViewer(o)}toggleAR(e,t=!0){const o={action:"toggleAR",obj:{state:e,value:t}};this.sendToViewer(o)}waitForCollisions(){return new Promise(((e,t)=>{this._eventObservable.add(i.ON_COLLISIONS,e)}))}toggleCollision(e,t){this.sendToViewer({action:"toggleCollision",to:n.dJ.WORKER,value:{value:e,color:t}})}deleteCollision(e,t){this.sendToViewer({action:"spliceCollision",to:n.dJ.WORKER,value:{value:e,count:t}})}removeAllCollisions(){this.sendToViewer({action:"removeAllCollisions",to:n.dJ.WORKER})}adjustScene(){return new Promise(((e,t)=>c(this,void 0,void 0,(function*(){this._eventObservable.add(i.ON_ADJUDT_SCENE,e),yield this.onModelLoaded(),this.sendToViewer({action:"adjustScene",to:n.dJ.WORKER})}))))}applyPreset(e){return new Promise(((t,o)=>c(this,void 0,void 0,(function*(){this._eventObservable.add(i.ON_APPLY_PRESET,t),yield this.onModelLoaded(),this.sendToViewer({action:"attachJsonScene",to:n.dJ.WORKER,data:e})}))))}applyHDRI(e){this.sendToViewer({action:"setHDR",to:n.dJ.WORKER,value:e.type,options:e})}applyShadowPlane(e){this.sendToViewer({action:"togglePlane",to:n.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(e){return new Promise(((t,o)=>{this._eventObservable.add(i.ON_SET_SCENE_SUMMARY,t),this.sendToViewer({action:"broadcastSceneSummary",to:n.dJ.WORKER,value:e})}))}setLightsByJson(e){return new Promise(((t,o)=>{this._eventObservable.add(i.ON_LIGHTS_SUMMARY,t),this.sendToViewer({action:"setLightsByJson",value:e,to:n.dJ.WORKER})}))}onCreateImagesByTour(){return new Promise(((e,t)=>c(this,void 0,void 0,(function*(){this._eventObservable.add(i.ON_CREATE_IMAGES_BY_TOUR,e)}))))}setMeshProps(e){const t={name:e.mesh.name,props:{}};t.props[e.key]=e.value,this._meshesData[t.name]||(this._meshesData[t.name]={}),this._meshesData[t.name][e.key]=e.value,this.sendToViewer({action:"setMeshProps",to:n.dJ.WORKER,value:t})}appendDynamicElement(e,t,o=".body"){this.sendToViewer({action:"appendElement",to:n.dJ.MAIN,obj:{obj:e,events:t,selectorToAppend:o}})}controlsTutorial(e){this.sendToViewer({action:"startZoomTutorial",to:n.dJ.WORKER,value:e})}toggleAutoRotate(e){this.sendToViewer({action:"toggleAutoRotate",to:n.dJ.WORKER,data:e})}onModelInteraction(e){return new Promise(((t,o)=>{this._eventObservable.add(i.ON_MODEL_INTERACTION,(o=>{e&&e(o),t(o)}))}))}goToInitialCamPos(){this.sendToViewer({action:"goToInitialCamPos",to:n.dJ.WORKER})}getCurrentScreenshot(){return new Promise(((e,t)=>c(this,void 0,void 0,(function*(){this._eventObservable.add(i.ON_SCREENSHOT,e),yield this.onAnimateEnterEnd(),this.sendToViewer({action:"getCurrentScreenshot",to:n.dJ.WORKER})}))))}expotModel(e){return new Promise(((t,o)=>c(this,void 0,void 0,(function*(){e.downloadFile||this._eventObservable.add(i.ON_EXPORT,t),yield this.onModelReady();let o="",r=null;switch(e.type){case n.Dl.GLB:case n.Dl.glTF:o="broadcastGLTF",r={binary:e.type===n.Dl.GLB,trs:!1,onlyVisible:!0,truncateDrawRange:!1,embedImages:!0,forceIndices:!0,forcePowerOfTwoTextures:!0,imagesFileType:null,normalImagesFileType:null,mroImagesFileType:null,imagesCompressionFactor:null,downloadFile:e.downloadFile,maxTexturesSize:null,maxDiffuseTexturesSize:null,maxNormalTexturesSize:null,maxMroTexturesSize:null,optipng:e.compressPNG,simplify:!1,deleteUV2:!1};break;case n.Dl.USDZ:o="broadcastUSDZ";break;case n.Dl.OBJ:o="broadcastOBJ";break;default:o="broadcastGLTF"}this.sendToViewer({action:o,value:r,to:n.dJ.WORKER}),e.downloadFile&&t(null)}))))}getScreenshotsSequence(e){return new Promise(((t,o)=>c(this,void 0,void 0,(function*(){this._eventObservable.add(i.ON_SCREENSHOTS_SEQUENCE,(o=>c(this,void 0,void 0,(function*(){if(e.format===n.oz.VIDEO){const i=new d(o);e.codec&&(i.codecs=e.codec),t(yield i.getVideo())}else t(o)})))),yield this.onModelReady(),yield this.onAnimateEnterEnd();const o={};e&&(o.ggNumOfFrames=e.numOfFrames),o.msgObj={data:{},action:"onScreenshotsSequence",to:n.dJ.TOP,from:n.dJ.WORKER},this.sendToViewer({action:"broadcastGifSequence",to:n.dJ.WORKER,data:{options:o}})}))))}applyTexture(e){this.sendToViewer({action:"mapTextureToMaterial",to:n.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===n.gX.VIDEO?e.src:null}}})}setMaterialProps(e){this.sendToViewer({action:"setMaterialProps",to:n.dJ.WORKER,value:{name:e.materialName,props:e.props}})}swapMaterialType(e){this.sendToViewer({action:"swapMaterialType",to:n.dJ.WORKER,value:{name:e.materialName,newType:e.type}})}displayFiles(e){this.sendToViewer({action:"displayFiles",to:n.dJ.MAIN,value:{files:e}})}getBoundingBox(){return new Promise(((e,t)=>c(this,void 0,void 0,(function*(){yield this.onModelReady(),this._eventObservable.add(i.ON_BOUNDING_BOX,e),this.sendToViewer({action:"broadcastBoundingBox",to:n.dJ.WORKER})}))))}toggleNoDistanceLimit(e){return c(this,void 0,void 0,(function*(){yield this.onModelReady(),this.sendToViewer({action:"toggleNoDistanceLimit",to:n.dJ.WORKER,value:e})}))}toggleCloseup(e){return c(this,void 0,void 0,(function*(){yield this.onModelReady(),this.sendToViewer({action:"toggleCloseup",to:n.dJ.WORKER,value:e})}))}setCameraPosition(e){return c(this,void 0,void 0,(function*(){yield this.onModelReady(),this.sendToViewer({action:"setCameraPosition",to:n.dJ.WORKER,value:e})}))}setDiamonds(e,t,o){return c(this,void 0,void 0,(function*(){yield this.onModelReady(),this.sendToViewer({action:"toggleDiamond",to:n.dJ.WORKER,value:{state:e,meshes:t,options:o}})}))}getDiamondsOptions(){return new Promise(((e,t)=>{this._eventObservable.add(i.ON_GET_DIAMONDS_OPTIONS,e);const o={action:"broadcastDiamondEffectOptions",to:n.dJ.WORKER};this.sendToViewer(o)}))}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)}}}},t={};function o(i){var n=t[i];if(void 0!==n)return n.exports;var r=t[i]={exports:{}};return e[i](r,r.exports,o),r.exports}o.d=(e,t)=>{for(var i in t)o.o(t,i)&&!o.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{"use strict";o.r(i);var e=o(516),t=o(492),n=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function a(e){try{d(i.next(e))}catch(e){r(e)}}function s(e){try{d(i.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,s)}d((i=i.apply(e,t||[])).next())}))};const r=new e.ViewerCommunicator({hexaViewer:document.querySelector("hexa-viewer")});!function(){let e=!1,o=!1,i=!1,a=!1,s=!1,d=document.getElementById("materialize");document.getElementById("config-single").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){let e=[{thumbnail:"https://www.tami4.co.il/sites/default/files/2021-04/edge_cream_front_552x820.png",asset:"http://localhost:9000/index.html?load=https://cdn.creators3d.com/models/3811692498551105_raw.glb&auto-adjust=1&debug=1&tv=162"},{thumbnail:"https://www.tami4.co.il/sites/default/files/2021-04/edge_black_front_552x820.png",asset:"https://v.hexa3d.io/index.html?load=%2Fviews%2Fproduction%2Fitem%2F2022427%2F4697126561495946%2F4697126561495946.glb&autorotate=true&json-data=1651045292244&decrypt=1&tv=162&br=true&watermark=1"}];e=[e[o?1:0]],o=!o,r.configurator.setConfigurator(e),r.configurator.toggleConfiguratorUI(!1),r.configurator.selectConfigurator(0)})))),d.addEventListener("click",(()=>n(this,void 0,void 0,(function*(){c({RGB:[178,121,51],roughness:.1,metalness:1,transparent:!1,environment:{type:9,intensity:1.3,blur:!1},exposure:1})}))),!1),document.getElementById("wireframe").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){e=!e,r.toggleWireframe(e)}))),!1),document.getElementById("uv").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){i=!i,r.toggleUvMode(i)}))),!1),document.getElementById("matcap").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){a=!a,r.toggleMatcapMode(a,{color:"#ff0068"})}))),!1),document.getElementById("expotModel").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){const e=yield r.expotModel({compressPNG:!1,downloadFile:!1,type:t.Dl.GLB});console.log(e)})))),document.getElementById("screenshotsSequence").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){const e=yield r.getScreenshotsSequence({numOfFrames:96,format:t.oz.VIDEO}),o=document.createElement("video");o.autoplay=!0,o.muted=!0,o.loop=!0,document.body.appendChild(o);const i=URL.createObjectURL(e);o.onended=function(){URL.revokeObjectURL(i)},o.src=i}))),!1),document.getElementById("export").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){const e=yield r.expotModel({compressPNG:!1,downloadFile:!0,type:t.Dl.GLB});console.log(e)}))),!1);const c=e=>n(this,void 0,void 0,(function*(){yield r.onModelLoaded();let t=yield r.getMeshesData();for(let o in t)r.materializeMesh(o,e)}));(()=>{const t=[{thumbnail:"https://www.tami4.co.il/sites/default/files/2021-04/edge_cream_front_552x820.png",asset:"https://v.hexa3d.io/index.html?load=%2Fviews%2Fproduction%2Fitem%2F2022427%2F1785766613823082%2F1785766613823082.glb&autorotate=true&json-data=1651045050192&decrypt=1&tv=135&br=true&watermark=1&pv=https://cdn.hexa3d.io/hotlink-ok/2022427/50526c5d853941f395e47913e9852ab3.png"},{thumbnail:"https://www.tami4.co.il/sites/default/files/2021-04/edge_black_front_552x820.png",asset:"https://v.hexa3d.io/index.html?load=%2Fviews%2Fproduction%2Fitem%2F2022427%2F4697126561495946%2F4697126561495946.glb&autorotate=true&json-data=1651045292244&decrypt=1&tv=135&br=true&watermark=1&pv=https://cdn.hexa3d.io/hotlink-ok/2022427/73fb4cb1d06f491fa6d8393f4704f816.png"},{thumbnail:"https://www.tami4.co.il/sites/default/files/2021-04/edge_white_front_552x820.png",asset:"https://v.hexa3d.io/index.html?load=%2Fviews%2Fproduction%2Fitem%2F2022427%2F6769057538255978%2F6769057538255978.glb&autorotate=true&json-data=1651046028136&decrypt=1&tv=135&br=true&watermark=1&pv=https://cdn.hexa3d.io/hotlink-ok/2022427/e93b62f0f99e41c09c7b9c85a027e071.png"},{thumbnail:"https://www.tami4.co.il/sites/default/files/2021-04/edge_red_front_552x820_0.png",asset:"https://v.hexa3d.io/index.html?load=%2Fviews%2Fproduction%2Fitem%2F2022427%2F3370851792395505%2F3370851792395505.glb&autorotate=true&json-data=1651045321141&decrypt=1&tv=135&br=true&watermark=1&pv=https://cdn.hexa3d.io/hotlink-ok/2022427/cc75a12053354011ae8b9a382f95eeb5.png"},{color:"rgb(229, 222, 204)",asset:"https://v.hexa3d.io/index.html?load=%2Fviews%2Fproduction%2Fitem%2F2022427%2F1785766613823082%2F1785766613823082.glb&autorotate=true&json-data=1651045050192&decrypt=1&tv=135&br=true&watermark=1&pv=https://cdn.hexa3d.io/hotlink-ok/2022427/50526c5d853941f395e47913e9852ab3.png"},{color:"rgb(0, 0, 0)",asset:"https://v.hexa3d.io/index.html?load=%2Fviews%2Fproduction%2Fitem%2F2022427%2F4697126561495946%2F4697126561495946.glb&autorotate=true&json-data=1651045292244&decrypt=1&tv=135&br=true&watermark=1&pv=https://cdn.hexa3d.io/hotlink-ok/2022427/73fb4cb1d06f491fa6d8393f4704f816.png"},{color:"rgb(255, 255, 255)",asset:"https://v.hexa3d.io/index.html?load=%2Fviews%2Fproduction%2Fitem%2F2022427%2F6769057538255978%2F6769057538255978.glb&autorotate=true&json-data=1651046028136&decrypt=1&tv=135&br=true&watermark=1&pv=https://cdn.hexa3d.io/hotlink-ok/2022427/e93b62f0f99e41c09c7b9c85a027e071.png"},{color:"rgb(220, 39, 25)",asset:"https://v.hexa3d.io/index.html?load=%2Fviews%2Fproduction%2Fitem%2F2022427%2F3370851792395505%2F3370851792395505.glb&autorotate=true&json-data=1651045321141&decrypt=1&tv=135&br=true&watermark=1&pv=https://cdn.hexa3d.io/hotlink-ok/2022427/cc75a12053354011ae8b9a382f95eeb5.png"}];document.getElementById("configurator-init").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){r.configurator.setConfigurator(t),t.forEach(((e,t)=>r.configurator.preloadConfigurator(e,2e3*(t+1)))),r.configurator.toggleConfiguratorUI(!0)}))),!1),document.getElementById("configurator-select").addEventListener("change",(t=>n(this,void 0,void 0,(function*(){r.configurator.selectConfigurator(parseInt(t.target.value)),e=!1})))),document.getElementById("pic-in-pic").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){r.togglePicInPic(!document.pictureInPictureElement)}))),!1),document.getElementById("webxr").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){(yield r.isWebXrSupported())?r.toggleWebXR(!0,!0):alert("This browser doesn't support WebXR")}))),!1),document.getElementById("collision-init").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){yield r.onModelLoaded(),r.toggleCollision(!0,"#ff0000");const e=yield r.waitForCollisions();console.log(e)}))),!1),document.getElementById("preset").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){r.applyPreset({hdri:{background:!0,blur:!1,format:"hdr",intensity:1,type:9}})}))),!1),document.getElementById("sync-clock").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){const e=yield r.getMeshesData(),t="Arrow_Min",o="Arrow_Sec",i="Arrow_Hr",n=()=>{setTimeout(n.bind(this),1e3);const a=new Date;let s=a.getHours(),d=a.getMinutes(),c=a.getSeconds();s>12&&(s-=12),s*=6,d*=6,c*=6,e[o].rotation.y=c*(Math.PI/180),e[t].rotation.y=d*(Math.PI/180),e[i].rotation.y=s*(Math.PI/180),r.setMeshProps({mesh:e[o],key:"rotation",value:e[o].rotation}),r.setMeshProps({mesh:e[t],key:"rotation",value:e[t].rotation}),r.setMeshProps({mesh:e[i],key:"rotation",value:e[i].rotation})};n()}))),!1)})();const l=()=>n(this,void 0,void 0,(function*(){yield r.onModelLoaded(),r.applyTexture({mapType:"map",materialName:"Display_MAT",mimeType:t.gX.VIDEO,src:"#video"})}));document.getElementById("apply-texture").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){l()})))),document.getElementById("hide-buttom").addEventListener("click",(()=>n(this,void 0,void 0,(function*(){s=!s,r.toggleHideBottom(s)})))),document.getElementById("file").addEventListener("change",(e=>{r.displayFiles(e.target.files)}),!1),r.getBoundingBox().then((e=>{console.log(e)}))}()})(),i})()));
//# sourceMappingURL=main.bundle.js.map