@roomle/embedding-lib 5.7.0-alpha.1 → 5.7.0-debug.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
- var R=Object.defineProperty,S=(s,e,t)=>e in s?R(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,c=(s,e,t)=>S(s,typeof e!="symbol"?e+"":e,t);class A{constructor(e,t,r,i){c(this,"_side"),c(this,"_incomingMessageBus"),c(this,"_outgoingMessageBus",null),c(this,"_execMessage",null),this._side=e,this._incomingMessageBus=t,this._outgoingMessageBus=r,this._execMessage=i,this._incomingMessageBus.addEventListener("message",this._handleMessage.bind(this))}setOutgoingMessageBus(e){this._outgoingMessageBus=e}setMessageExecution(e){this._execMessage=e}sendMessage(e,t=[]){return new Promise((r,i)=>{const n=new MessageChannel;n.port1.onmessage=o=>{if(!o||!o.data)return n.port1.close(),n.port2.close(),i(new Error(this._side+" received message but response can not be interpreted"));let a;try{a=JSON.parse(o.data)}catch(l){return n.port1.close(),n.port2.close(),this._prepareError(l),i(l)}a.error?i(a.error):a.result!==void 0?r(a.result):r(void 0),n.port1.close(),n.port2.close()};let u="";try{u=JSON.stringify({message:e,args:t})}catch{return i(new Error(this._side+": can not create command because it is not JSON.stringify able"))}if(!this._outgoingMessageBus)return i(new Error(this._side+": outgoing bus not set yet"));this._outgoingMessageBus.postMessage(u,"*",[n.port2])})}_handleMessage(e){const t=e.ports&&Array.isArray(e.ports)&&e.ports.length>0?e.ports[0]:null;if(e.data&&t)try{const r=JSON.parse(e.data);if(!this._execMessage)return t.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(r.args)||(r.args=[r.args]);const i=this._execMessage(r,e);if(i===void 0)return;i.then((n={})=>{let u,o;typeof n=="object"&&n!==null&&(u=n.error,o=n.result),u?t.postMessage(JSON.stringify({error:u})):o!==void 0?t.postMessage(JSON.stringify({result:o})):t.postMessage(JSON.stringify({result:n}))},n=>{t.postMessage(JSON.stringify({error:this._prepareError(n)}))})}catch(r){t.postMessage(JSON.stringify({error:this._prepareError(r)}))}}_prepareError(e){if(typeof e=="string"){const t=this._side+": "+e;return console.error(t),t}return e.message=this._side+": "+e.message,console.error(e),e.message}}const p=".",w={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},P=async(s,e)=>{if(typeof s!="string")throw new Error('Configurator ID is not a string type: "'+typeof s+'"');const t=e.customApiUrl?e.customApiUrl:"https://api.roomle.com/v2",r=e.overrideTenant||9,i=t+"/configurators/"+s,n="roomle_portal_v2",u="03-"+window.btoa(new Date().toISOString()+";anonymous;"+n),o=()=>{const d={apiKey:n,currentTenant:r,locale:"en",language:"en",device:1,token:u,platform:"web"};return new Headers(d)},a=new Request(i,{method:"GET",headers:o(),mode:"cors",cache:"default"}),l=await fetch(a),{configurator:g}=await l.json();return g},F=()=>{try{return window.self!==window.top}catch{return!0}},U=["127.0.0.1","localhost","0.0.0.0"],H=()=>{const s=F();let e=window.location.href;if(s){if(!document.referrer)return null;e=document.referrer}const{hostname:t}=new URL(e);return t},B=s=>!!(U.includes(s)||s.endsWith("roomle.com")||s.endsWith("gitlab.io")||s.endsWith("gitlab.com")),E=["language","browserLanguage","userLanguage","systemLanguage"],k=(s=null)=>{const e=window.navigator;if(s)return s.substr(0,2);if(Array.isArray(e.languages)&&e.languages.length>0)return e.languages[0].substr(0,2);for(let t=0,r=E.length;t<r;t++){const i=e[E[t]];if(i)return i.substr(0,2)}return"en"},x=(s,e)=>{const t=JSON.parse(JSON.stringify(s));return y(t,e)},y=(s,e)=>{for(const t in e)try{e[t].constructor===Object?s[t]=y(s[t],e[t]):s[t]=e[t]}catch{s[t]=e[t]}return s};var W={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const C={mobileLandscape:!0,floorMaterialRootTag:"materials_root",buttons:{renderimage:!0,requestproduct:!0,requestplan:!0,load_product:!0,partlist_print:!0},helpcenter:{roomdesigner:!0,configurator:!1,disable:!1},firstPersonView:!0,saveToIdb:!0,featureFlags:{mocAr:!0,wallAutoHeight:!1},rotationSnapDegrees:10},J="(idle)",$=s=>(b(s),s!=null&&s.customApiUrl&&(s.customApiUrl=decodeURIComponent(s.customApiUrl)),s.shareUrl&&(s.deeplink=s.shareUrl.replace(j,G)),s),b=s=>{if(!s)return;const e=Object.keys(s);for(const t of e){const r=s[t];if(!Array.isArray(r)&&typeof r=="object"&&r!==null&&b(r),Array.isArray(r))for(const i of r)b(i);(r==="true"||r==="false")&&(s[t]=r==="true")}},V=(s,e)=>{e.configuratorId=s.id;const t=s.settings||{};return!e.overrideTenant&&s.tenant&&(e.overrideTenant=s.tenant),x(t,e)},z=()=>{const s={...C};s.locale||(s.locale=k()),s.id===J&&delete s.id;const e=H();return e&&B(e)&&(s.configuratorId="demoConfigurator"),s.customApiUrl=W.VITE_RAPI_URL,s.emails=!1,s},j="<CONF_ID>",G="#CONFIGURATIONID#",v=()=>/(android)/i.test(navigator.userAgent),T=(s,e,t)=>{let r=null;Object.defineProperty(s,e,{get(){return r||t},set(i){i!=null&&i.mute?r=i.value:(console.warn("You override Roomle defined behaviour. To disalbe this warning pass in an object with the following properties"),console.warn("{ mute: true, value: () => void }"),r=i)}})},L=()=>window.innerHeight*.01+"px",D=s=>{s&&setTimeout(()=>s.style.setProperty(I,L()),0)},M="rml-styles",q=450,I="--rml-full-height",h={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},O=new Map;class Y{constructor(e,t,r,i,n){if(c(this,"ui",{callbacks:null}),c(this,"extended",{callbacks:null}),c(this,"configurator",{callbacks:null}),c(this,"analytics",{callbacks:{}}),c(this,"global",{callbacks:{}}),c(this,"plugins",{}),c(this,"_waitForIframe"),c(this,"_container"),c(this,"_messageHandler"),c(this,"_configuratorSettings"),c(this,"_initData",{}),c(this,"_iframe"),c(this,"pluginsLoaded",[]),!e||typeof e.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(O.has(t))throw new Error("There is already an instance on this DOM element");if(!document.getElementById(M)){const o=r.zIndex||9999999,a=document.createElement("style");a.type="text/css",a.id=M;const l="transition:all ease-in-out "+q+"ms;",g=["-webkit-","-o-"].reduce((f,m)=>f+=m+l,"")+l,d=L();a.innerHTML=`
2
- .${h.CONTAINER}{${I}:${d};}
3
- .${h.POSITION}{position:fixed;top:0;left:0;z-index:${o};opacity:0}
4
- .${h.TRANSITION}{${g}}
5
- .${h.FILL}{width:100%;height:100%;opacity:1}
6
- .${h.ANDROID_HEIGHT}{height:calc(var(${I},1vh)*100)}
7
- .${h.OVERFLOW_HIDDEN}{overflow:hidden}
8
- `,document.head.appendChild(a)}this._onResize=this._onResize.bind(this),v()&&window.addEventListener("resize",this._onResize),this._container=t,this._initData=r,this._configuratorSettings=e;const u=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._executeMessage=this._executeMessage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._messageHandler=new A("website",window,null,this._executeMessage),this._waitForIframe=n,this._container.appendChild(u),this._iframe=u;for(const o of i)typeof o=="string"&&o==="dragIn"?this.pluginsLoaded.push(new Promise((a,l)=>{try{import("./drag-in-BKrnFtmJ.mjs").then(({DragIn:g})=>{const d=new g(this._iframe);d.setInstance(this.ui),this.plugins.dragIn=d,a()})}catch(g){l(g)}})):o.name&&o.loader&&this.pluginsLoaded.push(new Promise((a,l)=>{try{o.loader().then(g=>{const d=new g(this._iframe);d.setInstance(this.ui),this.plugins[o.name]=d,a()})}catch(g){l(g)}}));O.set(t,!0)}static createPlanner(e,t,r,i=[]){return this._create(e,t,r,i)}static createConfigurator(e,t,r,i=[]){return this._create(e,t,r,i)}static create(e,t,r,i){return this._create(e,t,r,i)}static createViewer(e,t,r,i=[]){return this._create(e,t,r,i)}static async _create(e,t,r,i){return new Promise(async(n,u)=>{try{const o=y(z(),$(r));o.featureFlags||(o.featureFlags={}),typeof o.featureFlags.realPartList!="boolean"&&(o.featureFlags.realPartList=!0),typeof o.featureFlags.globalCallbacks!="boolean"&&(o.featureFlags.globalCallbacks=!0),typeof o.featureFlags.mocAr!="boolean"&&(o.featureFlags.mocAr=!1);const a=await P(e,o);r=V(a,o);const l=new this(a,t,r,i,n);return console.info(l),await Promise.allSettled(l.pluginsLoaded),l}catch(o){return u(o)}})}teardown(){this._container&&O.delete(this._container);const e=this._container.querySelector("iframe");e&&this._container.removeChild(e),window.removeEventListener("resize",this._onResize)}_createIframe(){var e;const t=document.createElement("iframe");let r=((e=this._configuratorSettings)==null?void 0:e.url)||"https://www.roomle.com/t/cp/";return this._initData.useLocalRoomle&&(r=location.href.replace("embedding.html","")),location.href.includes("roomle.gitlab.io")&&(r=location.href.replace("embedding.html","index.html")),this._initData.overrideServerUrl&&(r=this._initData.overrideServerUrl),t.src=r,t.classList.add(h.CONTAINER),t.classList.add(h.FILL),t}_onResize(){D(this._iframe)}_onUseFullPage(){this._iframe.classList.add(h.POSITION),document.documentElement.classList.add(h.OVERFLOW_HIDDEN),window.document.body.classList.add(h.OVERFLOW_HIDDEN),v()&&(D(this._iframe),this._iframe.classList.add(h.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(h.POSITION),this._iframe.classList.remove(h.ANDROID_HEIGHT),document.documentElement.classList.remove(h.OVERFLOW_HIDDEN),window.document.body.classList.remove(h.OVERFLOW_HIDDEN)}_executeMessage({message:e,args:t},r){var i;if(!r.source||r.source!==((i=this._iframe)==null?void 0:i.contentWindow))return;if(e===w.REQUEST_BOOT)return this._messageHandler.setOutgoingMessageBus(r.source),Promise.resolve({result:this._initData});if(e===w.SETUP){const{methods:l,callbacks:g}=t[0];return l.forEach(d=>{const f=d.split(p),m=f[0],_=f[1];this[m]||(this[m]={}),this[m][_]=function(){return this._messageHandler.sendMessage(d,[...arguments])}.bind(this)}),g.forEach(d=>{const f=d.split(p),m=f[0],_=f[1],N=f[2];this[m]||(this[m]={}),this[m][_]||(this[m][_]={}),this[m][_][N]=()=>{}}),T(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),T(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>this._messageHandler.sendMessage(w.WEBSITE_READY),0),Promise.resolve({result:null})}const n=e.split(p),u=n[0],o=n[1],a=n.length===3?n[2]:null;if(a&&this[u][o][a]){const l=this[u][o][a](...t);return l instanceof Promise?l.then(g=>({result:g})):l!==void 0?Promise.resolve({result:l}):Promise.resolve({result:null})}return Promise.reject('Message "'+e+'" is unkown')}}export{Y as default};
1
+ var H=Object.defineProperty,A=(r,e,t)=>e in r?H(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,c=(r,e,t)=>A(r,typeof e!="symbol"?e+"":e,t);class b{constructor(e,t,s,i){c(this,"_side"),c(this,"_incomingMessageBus",null),c(this,"_outgoingMessageBus",null),c(this,"_execMessage",null),this._side=e,this._incomingMessageBus=t,this._outgoingMessageBus=s,this._execMessage=i,this._incomingMessageBus&&this._incomingMessageBus.addEventListener("message",this._handleMessage.bind(this))}setOutgoingMessageBus(e){this._outgoingMessageBus=e}setMessageExecution(e){this._execMessage=e}sendMessage(e,t=[]){return new Promise((s,i)=>{if(this._incomingMessageBus===this._outgoingMessageBus)return s(void 0);const o=new MessageChannel;o.port1.onmessage=n=>{if(!n||!n.data)return o.port1.close(),o.port2.close(),i(new Error(this._side+" received message but response can not be interpreted"));let l;try{l=JSON.parse(n.data)}catch(u){return o.port1.close(),o.port2.close(),this._prepareError(u),i(u)}l.error?i(l.error):l.result!==void 0?s(l.result):s(void 0),o.port1.close(),o.port2.close()};let a="";try{a=JSON.stringify({message:e,args:t})}catch{return i(new Error(this._side+": can not create command because it is not JSON.stringify able"))}if(!this._outgoingMessageBus)return i(new Error(this._side+": outgoing bus not set yet"));this._outgoingMessageBus.postMessage(a,"*",[o.port2])})}_handleMessage(e){const t=e.ports&&Array.isArray(e.ports)&&e.ports.length>0?e.ports[0]:null;if(e.data&&t)try{const s=JSON.parse(e.data);if(!this._execMessage)return t.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(s.args)||(s.args=[s.args]);const i=this._execMessage(s,e);if(i===void 0)return;i.then((o={})=>{let a,n;typeof o=="object"&&o!==null&&(a=o.error,n=o.result),a?t.postMessage(JSON.stringify({error:a})):n!==void 0?t.postMessage(JSON.stringify({result:n})):t.postMessage(JSON.stringify({result:o}))},o=>{t.postMessage(JSON.stringify({error:this._prepareError(o)}))})}catch(s){t.postMessage(JSON.stringify({error:this._prepareError(s)}))}}_prepareError(e){if(typeof e=="string"){const t=this._side+": "+e;return console.error(t),t}return e.message=this._side+": "+e.message,console.error(e),e.message}}const p=".",f={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},_={GET_METHODS:"getMethods",RETURN_METHODS:"returnMethods",REGISTER_CUSTOM_VIEW:"registerCustomView",REGISTER_CUSTOM_VIEW_DONE:"registerCustomViewDone"},U=async(r,e)=>{if(typeof r!="string")throw new Error('Configurator ID is not a string type: "'+typeof r+'"');const t=e.customApiUrl?e.customApiUrl:"https://api.roomle.com/v2",s=e.overrideTenant||9,i=t+"/configurators/"+r,o="roomle_portal_v2",a="03-"+window.btoa(new Date().toISOString()+";anonymous;"+o),n=()=>{const d={apiKey:o,currentTenant:s,locale:"en",language:"en",device:1,token:a,platform:"web"};return new Headers(d)},l=new Request(i,{method:"GET",headers:n(),mode:"cors",cache:"default"}),u=await fetch(l),{configurator:h}=await u.json();return h},F=()=>{try{return window.self!==window.top}catch{return!0}},B=["127.0.0.1","localhost","0.0.0.0"],x=()=>{const r=F();let e=window.location.href;if(r){if(!document.referrer)return null;e=document.referrer}const{hostname:t}=new URL(e);return t},C=r=>!!(B.includes(r)||r.endsWith("roomle.com")||r.endsWith("gitlab.io")||r.endsWith("gitlab.com")),I=["language","browserLanguage","userLanguage","systemLanguage"],W=(r=null)=>{const e=window.navigator;if(r)return r.substr(0,2);if(Array.isArray(e.languages)&&e.languages.length>0)return e.languages[0].substr(0,2);for(let t=0,s=I.length;t<s;t++){const i=e[I[t]];if(i)return i.substr(0,2)}return"en"},k=(r,e)=>{const t=JSON.parse(JSON.stringify(r));return w(t,e)},w=(r,e)=>{for(const t in e)try{e[t].constructor===Object?r[t]=w(r[t],e[t]):r[t]=e[t]}catch{r[t]=e[t]}return r};var V={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const G={mobileLandscape:!0,floorMaterialRootTag:"materials_root",buttons:{renderimage:!0,requestproduct:!0,requestplan:!0,load_product:!0,partlist_print:!0},helpcenter:{roomdesigner:!0,configurator:!1,disable:!1},firstPersonView:!0,saveToIdb:!0,featureFlags:{mocAr:!0,wallAutoHeight:!1},rotationSnapDegrees:10},J="(idle)",$=r=>(E(r),r!=null&&r.customApiUrl&&(r.customApiUrl=decodeURIComponent(r.customApiUrl)),r.shareUrl&&(r.deeplink=r.shareUrl.replace(q,Y)),r),E=r=>{if(!r)return;const e=Object.keys(r);for(const t of e){const s=r[t];if(!Array.isArray(s)&&typeof s=="object"&&s!==null&&E(s),Array.isArray(s))for(const i of s)E(i);(s==="true"||s==="false")&&(r[t]=s==="true")}},j=(r,e)=>{e.configuratorId=r.id;const t=r.settings||{};return!e.overrideTenant&&r.tenant&&(e.overrideTenant=r.tenant),k(t,e)},z=()=>{const r={...G};r.locale||(r.locale=W()),r.id===J&&delete r.id;const e=x();return e&&C(e)&&(r.configuratorId="demoConfigurator"),r.customApiUrl=V.VITE_RAPI_URL,r.emails=!1,r},q="<CONF_ID>",Y="#CONFIGURATIONID#",M=()=>/(android)/i.test(navigator.userAgent);class v{constructor(){c(this,"_messageHandler",null),c(this,"isSetupDone",!1),c(this,"viewName","main"),c(this,"plugins",{}),c(this,"pluginsLoaded",[]),c(this,"ui",{callbacks:null}),c(this,"extended",{callbacks:null}),c(this,"configurator",{callbacks:null}),c(this,"analytics",{callbacks:{}}),c(this,"global",{callbacks:{}})}setMessageHandler(e){this._messageHandler=e}handleSetup(e){const{methods:t,callbacks:s}=e;t.forEach(i=>{const o=i.split(p),a=o[0],n=o[1];this[a]||(this[a]={}),this[a][n]=function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(i,[...arguments])}.bind(this)}),s.forEach(i=>{const o=i.split(p),a=o[0],n=o[1],l=o[2];this[a]||(this[a]={}),this[a][n]||(this[a][n]={}),this[a][n][l]=()=>{}}),this.isSetupDone=!0}executeMessage({message:e,args:t}){const s=e.split(p),i=s[0],o=s[1],a=s.length===3?s[2]:null;if(a&&this[i][o][a]){const n=this[i][o][a](...t);return n instanceof Promise?n.then(l=>({result:l})):n!==void 0?Promise.resolve({result:n}):Promise.resolve({result:null})}return Promise.reject('Message "'+e+'" is unkown')}setupPlugins(e,t,s="website"){for(const i of e)typeof i=="string"&&i==="dragIn"?this.pluginsLoaded.push(new Promise((o,a)=>{try{import("./drag-in-sE43chRN.mjs").then(n=>n.l).then(({DragIn:n})=>{const l=new n(this.ui,t,s,this.viewName);l.init().then(()=>{this.plugins.dragIn=l,o()},a)})}catch(n){a(n)}})):i.name&&i.loader&&this.pluginsLoaded.push(new Promise((o,a)=>{try{i.loader().then(n=>{const l=new n(this.ui,t,s,this.viewName);l.init().then(()=>{this.plugins[i.name]=l,o()},a)})}catch(n){a(n)}}))}}const T=()=>{let r,e;return{promise:new Promise((t,s)=>{r=t,e=s}),resolve:r,reject:e}},S=(r,e,t)=>{let s=null;Object.defineProperty(r,e,{get(){return s||t},set(i){i!=null&&i.mute?s=i.value:(console.warn("You override Roomle defined behaviour. To disalbe this warning pass in an object with the following properties"),console.warn("{ mute: true, value: () => void }"),s=i)}})},R=()=>window.innerHeight*.01+"px",D=r=>{r&&setTimeout(()=>r.style.setProperty(y,R()),0)},N="rml-styles",Q=450,y="--rml-full-height",g={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},O=new Map;class K extends v{constructor(e,t,s,i,o){if(super(),c(this,"_waitForIframe"),c(this,"_container"),c(this,"_configuratorSettings"),c(this,"_initData",{}),c(this,"_iframe"),!e||typeof e.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(O.has(t))throw new Error("There is already an instance on this DOM element");if(!document.getElementById(N)){const l=s.zIndex||9999999,u=document.createElement("style");u.type="text/css",u.id=N;const h="transition:all ease-in-out "+Q+"ms;",d=["-webkit-","-o-"].reduce((L,P)=>L+=P+h,"")+h,m=R();u.innerHTML=`
2
+ .${g.CONTAINER}{${y}:${m};}
3
+ .${g.POSITION}{position:fixed;top:0;left:0;z-index:${l};opacity:0}
4
+ .${g.TRANSITION}{${d}}
5
+ .${g.FILL}{width:100%;height:100%;opacity:1}
6
+ .${g.ANDROID_HEIGHT}{height:calc(var(${y},1vh)*100)}
7
+ .${g.OVERFLOW_HIDDEN}{overflow:hidden}
8
+ `,document.head.appendChild(u)}this._executeMessage=this._executeMessage.bind(this);const a=new b("website",window,null,this._executeMessage);this.setMessageHandler(a),this._onResize=this._onResize.bind(this),M()&&window.addEventListener("resize",this._onResize),this._container=t,this._initData=s,this._configuratorSettings=e;const n=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=o,this._container.appendChild(n),this._iframe=n,this.setupPlugins(i,this._iframe),O.set(t,!0)}static createPlanner(e,t,s,i=[]){return this._create(e,t,s,i)}static async connect(e,t=[]){const s=new v;s.viewName=e;const{resolve:i,promise:o}=T(),{resolve:a,promise:n}=T(),l=({message:d,args:m})=>{if(d===_.REGISTER_CUSTOM_VIEW_DONE){i();return}if(d===_.RETURN_METHODS){s.handleSetup(m[0]),a();return}if(s.isSetupDone)return s.executeMessage({message:d,args:m})},u=new b("custom-view-"+e,window,window.parent,l);s.setMessageHandler(u);const h=[e];return u.sendMessage(_.REGISTER_CUSTOM_VIEW,h),await o,u.sendMessage(_.GET_METHODS,h),await n,s.setupPlugins(t,document.body,"custom-view"),await Promise.allSettled(s.pluginsLoaded),s}static createConfigurator(e,t,s,i=[]){return this._create(e,t,s,i)}static create(e,t,s,i){return this._create(e,t,s,i)}static createViewer(e,t,s,i=[]){return this._create(e,t,s,i)}static async _create(e,t,s,i){return new Promise(async(o,a)=>{try{const n=w(z(),$(s));n.featureFlags||(n.featureFlags={}),typeof n.featureFlags.realPartList!="boolean"&&(n.featureFlags.realPartList=!0),typeof n.featureFlags.globalCallbacks!="boolean"&&(n.featureFlags.globalCallbacks=!0),typeof n.featureFlags.mocAr!="boolean"&&(n.featureFlags.mocAr=!1);const l=await U(e,n);s=j(l,n);const u=new this(l,t,s,i,o);return await Promise.allSettled(u.pluginsLoaded),u}catch(n){return a(n)}})}teardown(){this._container&&O.delete(this._container);const e=this._container.querySelector("iframe");e&&this._container.removeChild(e),window.removeEventListener("resize",this._onResize)}_createIframe(){var e;const t=document.createElement("iframe");let s=((e=this._configuratorSettings)==null?void 0:e.url)||"https://www.roomle.com/t/cp/";return this._initData.useLocalRoomle&&(s=location.href.replace("embedding.html","")),location.href.includes("roomle.gitlab.io")&&(s=location.href.replace("embedding.html","index.html")),this._initData.overrideServerUrl&&(s=this._initData.overrideServerUrl),t.src=s,t.classList.add(g.CONTAINER),t.classList.add(g.FILL),t}_onResize(){D(this._iframe)}_onUseFullPage(){this._iframe.classList.add(g.POSITION),document.documentElement.classList.add(g.OVERFLOW_HIDDEN),window.document.body.classList.add(g.OVERFLOW_HIDDEN),M()&&(D(this._iframe),this._iframe.classList.add(g.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(g.POSITION),this._iframe.classList.remove(g.ANDROID_HEIGHT),document.documentElement.classList.remove(g.OVERFLOW_HIDDEN),window.document.body.classList.remove(g.OVERFLOW_HIDDEN)}_executeMessage({message:e,args:t},s){var i;if(s.source&&s.source===((i=this._iframe)==null?void 0:i.contentWindow))return e===f.REQUEST_BOOT?this._messageHandler?(this._messageHandler.setOutgoingMessageBus(s.source),Promise.resolve({result:this._initData})):(console.error("MessageHandler not set"),Promise.resolve({error:"MessageHandler not set"})):e===f.SETUP?(this.handleSetup(t[0]),S(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),S(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>{if(!this._messageHandler){console.error("MessageHandler not set");return}this._messageHandler.sendMessage(f.WEBSITE_READY)},0),Promise.resolve({result:null})):this.executeMessage({message:e,args:t})}}export{K as default};
@@ -1,14 +1,17 @@
1
- (function(m,p){typeof exports=="object"&&typeof module<"u"?module.exports=p():typeof define=="function"&&define.amd?define(p):(m=typeof globalThis<"u"?globalThis:m||self,m["roomle-embedding-lib"]=m["roomle-embedding-lib"]||{},m["roomle-embedding-lib"].umd=m["roomle-embedding-lib"].umd||{},m["roomle-embedding-lib"].umd.js=p())})(this,function(){"use strict";var Te=Object.defineProperty;var Ee=(m,p,T)=>p in m?Te(m,p,{enumerable:!0,configurable:!0,writable:!0,value:T}):m[p]=T;var l=(m,p,T)=>Ee(m,typeof p!="symbol"?p+"":p,T);class m{constructor(e,t,r,n){l(this,"_side");l(this,"_incomingMessageBus");l(this,"_outgoingMessageBus",null);l(this,"_execMessage",null);this._side=e,this._incomingMessageBus=t,this._outgoingMessageBus=r,this._execMessage=n,this._incomingMessageBus.addEventListener("message",this._handleMessage.bind(this))}setOutgoingMessageBus(e){this._outgoingMessageBus=e}setMessageExecution(e){this._execMessage=e}sendMessage(e,t=[]){return new Promise((r,n)=>{const o=new MessageChannel;o.port1.onmessage=c=>{if(!c||!c.data)return o.port1.close(),o.port2.close(),n(new Error(this._side+" received message but response can not be interpreted"));let u;try{u=JSON.parse(c.data)}catch(i){return o.port1.close(),o.port2.close(),this._prepareError(i),n(i)}u.error?n(u.error):u.result!==void 0?r(u.result):r(void 0),o.port1.close(),o.port2.close()};let a="";try{a=JSON.stringify({message:e,args:t})}catch{return n(new Error(this._side+": can not create command because it is not JSON.stringify able"))}if(!this._outgoingMessageBus)return n(new Error(this._side+": outgoing bus not set yet"));this._outgoingMessageBus.postMessage(a,"*",[o.port2])})}_handleMessage(e){const t=e.ports&&Array.isArray(e.ports)&&e.ports.length>0?e.ports[0]:null;if(e.data&&t)try{const r=JSON.parse(e.data);if(!this._execMessage)return t.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(r.args)||(r.args=[r.args]);const n=this._execMessage(r,e);if(n===void 0)return;n.then((o={})=>{let a,c;typeof o=="object"&&o!==null&&(a=o.error,c=o.result),a?t.postMessage(JSON.stringify({error:a})):c!==void 0?t.postMessage(JSON.stringify({result:c})):t.postMessage(JSON.stringify({result:o}))},o=>{t.postMessage(JSON.stringify({error:this._prepareError(o)}))})}catch(r){t.postMessage(JSON.stringify({error:this._prepareError(r)}))}}_prepareError(e){if(typeof e=="string"){const t=this._side+": "+e;return console.error(t),t}return e.message=this._side+": "+e.message,console.error(e),e.message}}const p=".",T={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},q=async(s,e)=>{if(typeof s!="string")throw new Error('Configurator ID is not a string type: "'+typeof s+'"');const t=e.customApiUrl?e.customApiUrl:"https://api.roomle.com/v2",r=e.overrideTenant||9,n=t+"/configurators/"+s,o="roomle_portal_v2",a="03-"+window.btoa(new Date().toISOString()+";anonymous;"+o),c=()=>{const h={apiKey:o,currentTenant:r,locale:"en",language:"en",device:1,token:a,platform:"web"};return new Headers(h)},u=new Request(n,{method:"GET",headers:c(),mode:"cors",cache:"default"}),i=await fetch(u),{configurator:d}=await i.json();return d},K=()=>{try{return window.self!==window.top}catch{return!0}},j=["127.0.0.1","localhost","0.0.0.0"],Q=()=>{const s=K();let e=window.location.href;if(s){if(!document.referrer)return null;e=document.referrer}const{hostname:t}=new URL(e);return t},Z=s=>!!(j.includes(s)||s.endsWith("roomle.com")||s.endsWith("gitlab.io")||s.endsWith("gitlab.com")),P=["language","browserLanguage","userLanguage","systemLanguage"],ee=(s=null)=>{const e=window.navigator;if(s)return s.substr(0,2);if(Array.isArray(e.languages)&&e.languages.length>0)return e.languages[0].substr(0,2);for(let t=0,r=P.length;t<r;t++){const n=e[P[t]];if(n)return n.substr(0,2)}return"en"},te=(s,e)=>{const t=JSON.parse(JSON.stringify(s));return S(t,e)},S=(s,e)=>{for(const t in e)try{e[t].constructor===Object?s[t]=S(s[t],e[t]):s[t]=e[t]}catch{s[t]=e[t]}return s};var se={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const re={mobileLandscape:!0,floorMaterialRootTag:"materials_root",buttons:{renderimage:!0,requestproduct:!0,requestplan:!0,load_product:!0,partlist_print:!0},helpcenter:{roomdesigner:!0,configurator:!1,disable:!1},firstPersonView:!0,saveToIdb:!0,featureFlags:{mocAr:!0,wallAutoHeight:!1},rotationSnapDegrees:10},ne="(idle)",oe=s=>(w(s),s!=null&&s.customApiUrl&&(s.customApiUrl=decodeURIComponent(s.customApiUrl)),s.shareUrl&&(s.deeplink=s.shareUrl.replace(ce,le)),s),w=s=>{if(!s)return;const e=Object.keys(s);for(const t of e){const r=s[t];if(!Array.isArray(r)&&typeof r=="object"&&r!==null&&w(r),Array.isArray(r))for(const n of r)w(n);(r==="true"||r==="false")&&(s[t]=r==="true")}},ie=(s,e)=>{e.configuratorId=s.id;const t=s.settings||{};return!e.overrideTenant&&s.tenant&&(e.overrideTenant=s.tenant),te(t,e)},ae=()=>{const s={...re};s.locale||(s.locale=ee()),s.id===ne&&delete s.id;const e=Q();return e&&Z(e)&&(s.configuratorId="demoConfigurator"),s.customApiUrl=se.VITE_RAPI_URL,s.emails=!1,s},ce="<CONF_ID>",le="#CONFIGURATIONID#",F=()=>/(android)/i.test(navigator.userAgent),H=(s,e,t)=>{let r=null;Object.defineProperty(s,e,{get(){return r||t},set(n){n!=null&&n.mute?r=n.value:(console.warn("You override Roomle defined behaviour. To disalbe this warning pass in an object with the following properties"),console.warn("{ mute: true, value: () => void }"),r=n)}})},U=()=>window.innerHeight*.01+"px",Y=s=>{s&&setTimeout(()=>s.style.setProperty(A,U()),0)},k="rml-styles",ue=450,A="--rml-full-height",_={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},O=new Map;class he{constructor(e,t,r,n,o){l(this,"ui",{callbacks:null});l(this,"extended",{callbacks:null});l(this,"configurator",{callbacks:null});l(this,"analytics",{callbacks:{}});l(this,"global",{callbacks:{}});l(this,"plugins",{});l(this,"_waitForIframe");l(this,"_container");l(this,"_messageHandler");l(this,"_configuratorSettings");l(this,"_initData",{});l(this,"_iframe");l(this,"pluginsLoaded",[]);if(!e||typeof e.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(O.has(t))throw new Error("There is already an instance on this DOM element");if(!!!document.getElementById(k)){const u=r.zIndex||9999999,i=document.createElement("style");i.type="text/css",i.id=k;const d="transition:all ease-in-out "+ue+"ms;",h=["-webkit-","-o-"].reduce((g,y)=>g+=y+d,"")+d,f=U();i.innerHTML=`
2
- .${_.CONTAINER}{${A}:${f};}
1
+ (function(g,f){typeof exports=="object"&&typeof module<"u"?module.exports=f():typeof define=="function"&&define.amd?define(f):(g=typeof globalThis<"u"?globalThis:g||self,g["roomle-embedding-lib"]=g["roomle-embedding-lib"]||{},g["roomle-embedding-lib"].umd=g["roomle-embedding-lib"].umd||{},g["roomle-embedding-lib"].umd.js=f())})(this,function(){"use strict";var jt=Object.defineProperty;var Qt=(g,f,E)=>f in g?jt(g,f,{enumerable:!0,configurable:!0,writable:!0,value:E}):g[f]=E;var a=(g,f,E)=>Qt(g,typeof f!="symbol"?f+"":f,E);class g{constructor(e,t,s,r){a(this,"_side");a(this,"_incomingMessageBus",null);a(this,"_outgoingMessageBus",null);a(this,"_execMessage",null);this._side=e,this._incomingMessageBus=t,this._outgoingMessageBus=s,this._execMessage=r,this._incomingMessageBus&&this._incomingMessageBus.addEventListener("message",this._handleMessage.bind(this))}setOutgoingMessageBus(e){this._outgoingMessageBus=e}setMessageExecution(e){this._execMessage=e}sendMessage(e,t=[]){return new Promise((s,r)=>{if(this._incomingMessageBus===this._outgoingMessageBus)return s(void 0);const i=new MessageChannel;i.port1.onmessage=c=>{if(!c||!c.data)return i.port1.close(),i.port2.close(),r(new Error(this._side+" received message but response can not be interpreted"));let l;try{l=JSON.parse(c.data)}catch(h){return i.port1.close(),i.port2.close(),this._prepareError(h),r(h)}l.error?r(l.error):l.result!==void 0?s(l.result):s(void 0),i.port1.close(),i.port2.close()};let o="";try{o=JSON.stringify({message:e,args:t})}catch{return r(new Error(this._side+": can not create command because it is not JSON.stringify able"))}if(!this._outgoingMessageBus)return r(new Error(this._side+": outgoing bus not set yet"));this._outgoingMessageBus.postMessage(o,"*",[i.port2])})}_handleMessage(e){const t=e.ports&&Array.isArray(e.ports)&&e.ports.length>0?e.ports[0]:null;if(e.data&&t)try{const s=JSON.parse(e.data);if(!this._execMessage)return t.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(s.args)||(s.args=[s.args]);const r=this._execMessage(s,e);if(r===void 0)return;r.then((i={})=>{let o,c;typeof i=="object"&&i!==null&&(o=i.error,c=i.result),o?t.postMessage(JSON.stringify({error:o})):c!==void 0?t.postMessage(JSON.stringify({result:c})):t.postMessage(JSON.stringify({result:i}))},i=>{t.postMessage(JSON.stringify({error:this._prepareError(i)}))})}catch(s){t.postMessage(JSON.stringify({error:this._prepareError(s)}))}}_prepareError(e){if(typeof e=="string"){const t=this._side+": "+e;return console.error(t),t}return e.message=this._side+": "+e.message,console.error(e),e.message}}const f=".",E={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},w={GET_METHODS:"getMethods",RETURN_METHODS:"returnMethods",REGISTER_CUSTOM_VIEW:"registerCustomView",REGISTER_CUSTOM_VIEW_DONE:"registerCustomViewDone"},mt=async(n,e)=>{if(typeof n!="string")throw new Error('Configurator ID is not a string type: "'+typeof n+'"');const t=e.customApiUrl?e.customApiUrl:"https://api.roomle.com/v2",s=e.overrideTenant||9,r=t+"/configurators/"+n,i="roomle_portal_v2",o="03-"+window.btoa(new Date().toISOString()+";anonymous;"+i),c=()=>{const d={apiKey:i,currentTenant:s,locale:"en",language:"en",device:1,token:o,platform:"web"};return new Headers(d)},l=new Request(r,{method:"GET",headers:c(),mode:"cors",cache:"default"}),h=await fetch(l),{configurator:u}=await h.json();return u},ft=()=>{try{return window.self!==window.top}catch{return!0}},pt=["127.0.0.1","localhost","0.0.0.0"],yt=()=>{const n=ft();let e=window.location.href;if(n){if(!document.referrer)return null;e=document.referrer}const{hostname:t}=new URL(e);return t},Et=n=>!!(pt.includes(n)||n.endsWith("roomle.com")||n.endsWith("gitlab.io")||n.endsWith("gitlab.com")),k=["language","browserLanguage","userLanguage","systemLanguage"],Dt=(n=null)=>{const e=window.navigator;if(n)return n.substr(0,2);if(Array.isArray(e.languages)&&e.languages.length>0)return e.languages[0].substr(0,2);for(let t=0,s=k.length;t<s;t++){const r=e[k[t]];if(r)return r.substr(0,2)}return"en"},St=(n,e)=>{const t=JSON.parse(JSON.stringify(n));return L(t,e)},L=(n,e)=>{for(const t in e)try{e[t].constructor===Object?n[t]=L(n[t],e[t]):n[t]=e[t]}catch{n[t]=e[t]}return n};var Tt={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const It={mobileLandscape:!0,floorMaterialRootTag:"materials_root",buttons:{renderimage:!0,requestproduct:!0,requestplan:!0,load_product:!0,partlist_print:!0},helpcenter:{roomdesigner:!0,configurator:!1,disable:!1},firstPersonView:!0,saveToIdb:!0,featureFlags:{mocAr:!0,wallAutoHeight:!1},rotationSnapDegrees:10},wt="(idle)",At=n=>(C(n),n!=null&&n.customApiUrl&&(n.customApiUrl=decodeURIComponent(n.customApiUrl)),n.shareUrl&&(n.deeplink=n.shareUrl.replace(vt,Mt)),n),C=n=>{if(!n)return;const e=Object.keys(n);for(const t of e){const s=n[t];if(!Array.isArray(s)&&typeof s=="object"&&s!==null&&C(s),Array.isArray(s))for(const r of s)C(r);(s==="true"||s==="false")&&(n[t]=s==="true")}},bt=(n,e)=>{e.configuratorId=n.id;const t=n.settings||{};return!e.overrideTenant&&n.tenant&&(e.overrideTenant=n.tenant),St(t,e)},Ot=()=>{const n={...It};n.locale||(n.locale=Dt()),n.id===wt&&delete n.id;const e=yt();return e&&Et(e)&&(n.configuratorId="demoConfigurator"),n.customApiUrl=Tt.VITE_RAPI_URL,n.emails=!1,n},vt="<CONF_ID>",Mt="#CONFIGURATIONID#",$=()=>/(android)/i.test(navigator.userAgent);class z{constructor(){a(this,"_messageHandler",null);a(this,"isSetupDone",!1);a(this,"viewName","main");a(this,"plugins",{});a(this,"pluginsLoaded",[]);a(this,"ui",{callbacks:null});a(this,"extended",{callbacks:null});a(this,"configurator",{callbacks:null});a(this,"analytics",{callbacks:{}});a(this,"global",{callbacks:{}})}setMessageHandler(e){this._messageHandler=e}handleSetup(e){const{methods:t,callbacks:s}=e;t.forEach(r=>{const i=r.split(f),o=i[0],c=i[1];this[o]||(this[o]={}),this[o][c]=(function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(r,[...arguments])}).bind(this)}),s.forEach(r=>{const i=r.split(f),o=i[0],c=i[1],l=i[2];this[o]||(this[o]={}),this[o][c]||(this[o][c]={}),this[o][c][l]=()=>{}}),this.isSetupDone=!0}executeMessage({message:e,args:t}){const s=e.split(f),r=s[0],i=s[1],o=s.length===3?s[2]:null;if(o&&this[r][i][o]){const c=this[r][i][o](...t);return c instanceof Promise?c.then(l=>({result:l})):c!==void 0?Promise.resolve({result:c}):Promise.resolve({result:null})}return Promise.reject('Message "'+e+'" is unkown')}setupPlugins(e,t,s="website"){for(const r of e)typeof r=="string"&&r==="dragIn"?this.pluginsLoaded.push(new Promise((i,o)=>{try{Promise.resolve().then(()=>xt).then(({DragIn:c})=>{const l=new c(this.ui,t,s,this.viewName);l.init().then(()=>{this.plugins.dragIn=l,i()},o)})}catch(c){o(c)}})):r.name&&r.loader&&this.pluginsLoaded.push(new Promise((i,o)=>{try{r.loader().then(c=>{const l=new c(this.ui,t,s,this.viewName);l.init().then(()=>{this.plugins[r.name]=l,i()},o)})}catch(c){o(c)}}))}}const V=()=>{let n,e;return{promise:new Promise((s,r)=>{n=s,e=r}),resolve:n,reject:e}},q=(n,e,t)=>{let s=null;Object.defineProperty(n,e,{get(){return s||t},set(r){r!=null&&r.mute?s=r.value:(console.warn("You override Roomle defined behaviour. To disalbe this warning pass in an object with the following properties"),console.warn("{ mute: true, value: () => void }"),s=r)}})},K=()=>window.innerHeight*.01+"px",J=n=>{n&&setTimeout(()=>n.style.setProperty(N,K()),0)},j="rml-styles",Rt=450,N="--rml-full-height",_={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},x=new Map;class Lt extends z{constructor(t,s,r,i,o){super();a(this,"_waitForIframe");a(this,"_container");a(this,"_configuratorSettings");a(this,"_initData",{});a(this,"_iframe");if(!t||typeof t.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(x.has(s))throw new Error("There is already an instance on this DOM element");if(!!!document.getElementById(j)){const u=r.zIndex||9999999,d=document.createElement("style");d.type="text/css",d.id=j;const p="transition:all ease-in-out "+Rt+"ms;",m=["-webkit-","-o-"].reduce((S,I)=>S+=I+p,"")+p,y=K();d.innerHTML=`
2
+ .${_.CONTAINER}{${N}:${y};}
3
3
  .${_.POSITION}{position:fixed;top:0;left:0;z-index:${u};opacity:0}
4
- .${_.TRANSITION}{${h}}
4
+ .${_.TRANSITION}{${m}}
5
5
  .${_.FILL}{width:100%;height:100%;opacity:1}
6
- .${_.ANDROID_HEIGHT}{height:calc(var(${A},1vh)*100)}
6
+ .${_.ANDROID_HEIGHT}{height:calc(var(${N},1vh)*100)}
7
7
  .${_.OVERFLOW_HIDDEN}{overflow:hidden}
8
- `,document.head.appendChild(i)}this._onResize=this._onResize.bind(this),F()&&window.addEventListener("resize",this._onResize),this._container=t,this._initData=r,this._configuratorSettings=e;const c=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._executeMessage=this._executeMessage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._messageHandler=new m("website",window,null,this._executeMessage),this._waitForIframe=o,this._container.appendChild(c),this._iframe=c;for(const u of n)typeof u=="string"&&u==="dragIn"?this.pluginsLoaded.push(new Promise((i,d)=>{try{Promise.resolve().then(()=>pe).then(({DragIn:h})=>{const f=new h(this._iframe);f.setInstance(this.ui),this.plugins.dragIn=f,i()})}catch(h){d(h)}})):u.name&&u.loader&&this.pluginsLoaded.push(new Promise((i,d)=>{try{u.loader().then(h=>{const f=new h(this._iframe);f.setInstance(this.ui),this.plugins[u.name]=f,i()})}catch(h){d(h)}}));O.set(t,!0)}static createPlanner(e,t,r,n=[]){return this._create(e,t,r,n)}static createConfigurator(e,t,r,n=[]){return this._create(e,t,r,n)}static create(e,t,r,n){return this._create(e,t,r,n)}static createViewer(e,t,r,n=[]){return this._create(e,t,r,n)}static async _create(e,t,r,n){return new Promise(async(o,a)=>{try{const c=S(ae(),oe(r));c.featureFlags||(c.featureFlags={}),typeof c.featureFlags.realPartList!="boolean"&&(c.featureFlags.realPartList=!0),typeof c.featureFlags.globalCallbacks!="boolean"&&(c.featureFlags.globalCallbacks=!0),typeof c.featureFlags.mocAr!="boolean"&&(c.featureFlags.mocAr=!1);const u=await q(e,c);r=ie(u,c);const i=new this(u,t,r,n,o);return console.info(i),await Promise.allSettled(i.pluginsLoaded),i}catch(c){return a(c)}})}teardown(){this._container&&O.delete(this._container);const e=this._container.querySelector("iframe");e&&this._container.removeChild(e),window.removeEventListener("resize",this._onResize)}_createIframe(){var r;const e=document.createElement("iframe");let t=((r=this._configuratorSettings)==null?void 0:r.url)||"https://www.roomle.com/t/cp/";return this._initData.useLocalRoomle&&(t=location.href.replace("embedding.html","")),location.href.includes("roomle.gitlab.io")&&(t=location.href.replace("embedding.html","index.html")),this._initData.overrideServerUrl&&(t=this._initData.overrideServerUrl),e.src=t,e.classList.add(_.CONTAINER),e.classList.add(_.FILL),e}_onResize(){Y(this._iframe)}_onUseFullPage(){this._iframe.classList.add(_.POSITION),document.documentElement.classList.add(_.OVERFLOW_HIDDEN),window.document.body.classList.add(_.OVERFLOW_HIDDEN),F()&&(Y(this._iframe),this._iframe.classList.add(_.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(_.POSITION),this._iframe.classList.remove(_.ANDROID_HEIGHT),document.documentElement.classList.remove(_.OVERFLOW_HIDDEN),window.document.body.classList.remove(_.OVERFLOW_HIDDEN)}_executeMessage({message:e,args:t},r){var u;if(!r.source||r.source!==((u=this._iframe)==null?void 0:u.contentWindow))return;if(e===T.REQUEST_BOOT)return this._messageHandler.setOutgoingMessageBus(r.source),Promise.resolve({result:this._initData});if(e===T.SETUP){const{methods:i,callbacks:d}=t[0];return i.forEach(h=>{const f=h.split(p),g=f[0],y=f[1];this[g]||(this[g]={}),this[g][y]=(function(){return this._messageHandler.sendMessage(h,[...arguments])}).bind(this)}),d.forEach(h=>{const f=h.split(p),g=f[0],y=f[1],v=f[2];this[g]||(this[g]={}),this[g][y]||(this[g][y]={}),this[g][y][v]=()=>{}}),H(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),H(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>this._messageHandler.sendMessage(T.WEBSITE_READY),0),Promise.resolve({result:null})}const n=e.split(p),o=n[0],a=n[1],c=n.length===3?n[2]:null;if(c&&this[o][a][c]){const i=this[o][a][c](...t);return i instanceof Promise?i.then(d=>({result:d})):i!==void 0?Promise.resolve({result:i}):Promise.resolve({result:null})}return Promise.reject('Message "'+e+'" is unkown')}}class de{constructor(e=16){l(this,"_computedStyleCache",new Map);l(this,"_maxLifetime",16);l(this,"_cacheCleanInterval",null);this._maxLifetime=e}get(e){const t=this._computedStyleCache.get(e),r=Date.now();if(t&&r-t.updated<this._maxLifetime)return t.style;const n=getComputedStyle(e);return this._computedStyleCache.set(e,{style:n,updated:r}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),n}_cleanUpCache(){const e=Date.now();for(const[t,{updated:r}]of this._computedStyleCache.entries())e-r>=this._maxLifetime&&this._computedStyleCache.delete(t);this._computedStyleCache.size===0&&this._cacheCleanInterval&&(clearInterval(this._cacheCleanInterval),this._cacheCleanInterval=null)}}const B=s=>window.TouchEvent&&s instanceof window.TouchEvent;let b;const E=s=>(b||(b=new de),b.get(s)),$=(s,e,t)=>{const r=parseFloat(s),n=window.devicePixelRatio||1;if(e==="px")return r;if(e==="%"){const a=t===document.documentElement?window.innerWidth:t.offsetWidth;return r/100*a}if(e==="rem"){const a=parseFloat(E(document.documentElement).fontSize);return r*a}if(e==="em"){const a=parseFloat(E(t).fontSize);return r*a}if(e==="vh"||e==="vw"||e==="vmin"||e==="vmax"){const a={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return r/100*a[e]}const o={cm:37.7952755906,mm:3.77952755906,in:96};return e in o?r*o[e]*n:(console.warn("Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"),0)},G=(s,e,t={x:0,y:0})=>{const r=s.getBoundingClientRect(),o=E(s).transform;let a=0,c=0;if(o!=="none"){const f=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,g=o.match(f);g&&(a=$(g[1],g[2],s),c=$(g[3],g[4],s))}const{clientX:u,clientY:i}=L(e,t),d=u-r.left-a+s.scrollLeft,h=i-r.top-c+s.scrollTop;return{x:d,y:h}},L=(s,e)=>{const{clientX:t,clientY:r}=B(s)?fe(s):s,n=t||e.x,o=r||e.y;return{clientX:n,clientY:o}},fe=s=>{if(s.touches.length){let{clientX:t,clientY:r}=s.touches[0];if(s.touches.length>1){const n=s.touches[1],o=n.clientX,a=n.clientY;t=(t+o)/2,r=(r+a)/2}return{clientX:t,clientY:r}}const e=s.changedTouches[0];return{clientX:e.clientX,clientY:e.clientY}},X=500,z=10;class ge{constructor(e,{onTouchDragStart:t},r={}){l(this,"_touchDragTimeOut");l(this,"_onTouchDragStart");l(this,"_payload",null);l(this,"_delay",X);l(this,"_firstTouch",null);l(this,"_lastTouch",null);l(this,"_epsilon",z);this._payload=e,this._onTouchDragStart=t,this._delay=r.delay||X,this._epsilon=r.epsilon||z}onTouchStart(e){var t;!e||!((t=e==null?void 0:e.touches)!=null&&t.length)||this._touchDragTimeOut||(this._firstTouch=e.touches[e.touches.length-1],this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=e.touches[0]),this._checkXDistance(e)()},this._delay))}onTouchEnd(){this._resetTouches()}onTouchMove(e){var t;!e||!((t=e==null?void 0:e.touches)!=null&&t.length)||(this._lastTouch=e.touches[0])}_clearTimeout(){this._touchDragTimeOut&&(clearTimeout(this._touchDragTimeOut),this._touchDragTimeOut=null)}_resetTouches(){this._clearTimeout(),this._lastTouch=null,this._firstTouch=null,this._payload=null}_checkXDistance(e){return()=>{if(!this._firstTouch||!this._lastTouch)return;let t=!1;t=Math.abs(this._firstTouch.clientX-this._lastTouch.clientX)<this._epsilon,t&&(this._onTouchDragStart(this._payload,e),this._resetTouches())}}}const W="rml-drag-in-styles",_e="rml-drag-in-drag-element",I="rml-drag-in-overlay",D="rml-drag-in-drag-ghost",N="rml-drag-in-fade-in",V="rml-drag-in-fade-out",R={DISPLAY_NONE:"rml-display-none"},J=.5,x="250ms",M="forwards",C=s=>s?!0:(console.warn("No instance set, cancel drag-in"),!1);class me{constructor(e){l(this,"_iframe");l(this,"_currentDrag",{});l(this,"_currentTouch",null);l(this,"_firefoxDragPosition",{x:0,y:0});l(this,"_instance",null);l(this,"options",{});l(this,"_firefoxFallback",e=>{if(!this._currentDrag.event)return;const t=e||window.event;this._firefoxDragPosition.x=t.pageX||0,this._firefoxDragPosition.y=t.pageY||0});this._iframe=e,this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!!!document.getElementById(W)){const t=document.createElement("style");t.type="text/css",t.id=W,t.innerHTML=`
9
- .${R.DISPLAY_NONE}{display:none}
10
- .${I}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
11
- .${D}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
12
- @keyframes ${N} {from{opacity: 0;}to {opacity: ${J};}}
13
- @keyframes ${V} {from{opacity: ${J};}to {opacity: 0;}}
14
- `,document.head.appendChild(t)}}_initializeDragGhost(){const e=this._iframe.parentNode;let t=e.querySelector("."+D);t||(t=document.createElement("div"),t.classList.add(D),t.innerText=" ",e.appendChild(t))}setInstance(e){this._instance=e}dragStart(e,t,r="rml_id"){const n=this._iframe.parentNode;if(E(n).position!=="relative"){console.warn("Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly");return}this._iframe.style.pointerEvents="none";let a=n.querySelector("."+I);a||(a=document.createElement("div"),a.classList.add(I),n.appendChild(a)),a.classList.remove(R.DISPLAY_NONE),t.target.getAttribute("draggable")||console.warn(`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`);const u=n.querySelector("."+D);this._currentDrag.event=t;const i=t.target.cloneNode();i.style.position="fixed",i.style.pointerEvents="none",i.style.opacity="0",i.style.animation=`${N} ${x} ${M}`,i.id=_e,i.style.zIndex="9999",document.body.appendChild(i),this._currentDrag.element=i;const d=t.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0});const{clientX:h,clientY:f}=L(t,this._firefoxDragPosition);this._currentDrag.offset.x=h-d.left,this._currentDrag.offset.y=f-d.top,i.style.top=f+"px",i.style.left=h+"px",t instanceof DragEvent&&t.dataTransfer&&t.dataTransfer.setDragImage&&t.dataTransfer.setDragImage(u,0,0);const{x:g,y}=G(n,this._currentDrag.event||t,this._firefoxDragPosition),v=Math.max(1,g),ye=Math.max(1,y);C(this._instance)&&this._instance.dragInObject(e,v,ye,r)}dragUpdate(e){var c,u;const t=this._iframe.parentNode,{x:r,y:n}=G(t,e,this._firefoxDragPosition);if(r===0&&n===0)return;const o=Math.max(1,r),a=Math.max(1,n);if(this._currentDrag.element){const{clientX:i,clientY:d}=L(e,this._firefoxDragPosition),h=((c=this._currentDrag.offset)==null?void 0:c.x)||0,f=((u=this._currentDrag.offset)==null?void 0:u.y)||0;this._currentDrag.element.style.left=`${i-h}px`,this._currentDrag.element.style.top=`${d-f}px`;const g=(this.options.dragInOverlapX||0)+1,y=(this.options.dragInOverlapY||0)+1;o>g&&a>y?this._currentDrag.element.style.animation=`${V} ${x} ${M}`:this._currentDrag.element.style.animation=`${N} ${x} ${M}`}if(!(o===1&&a===1)&&C(this._instance)){let i=o,d=a;if(B(e)){const h=this.options.fingerSize||0;i=Math.max(2,o+h),d=Math.max(2,a-h)}this._instance.updateDrag(i,d)}}dragEnd(){this._iframe.style.pointerEvents="all";const e=this._iframe.parentNode;C(this._instance)&&this._instance.dragInObjectEnd(),this._currentDrag.element&&document.body.removeChild(this._currentDrag.element),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const t=e.querySelector("."+I);t&&t.classList.add(R.DISPLAY_NONE)}touchStart(e,t,r="rml_id"){var a,c;t.preventDefault();const n=(u,i)=>{this.dragStart(e,i,r)},o={};typeof((a=this.options)==null?void 0:a.touchDragDelay)=="number"&&(o.delay=this.options.touchDragDelay),(c=this.options)!=null&&c.touchDragEpsilon&&(o.epsilon=this.options.touchDragEpsilon),this._currentTouch=new ge(void 0,{onTouchDragStart:n},o),this._currentTouch.onTouchStart(t)}touchMove(e){this._currentTouch&&this._currentTouch.onTouchMove(e),this._currentDrag.event&&this.dragUpdate(e)}touchEnd(){this._currentTouch&&this._currentTouch.onTouchEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}}const pe=Object.freeze(Object.defineProperty({__proto__:null,DragIn:me},Symbol.toStringTag,{value:"Module"}));return he});
8
+ `,document.head.appendChild(d)}this._executeMessage=this._executeMessage.bind(this);const l=new g("website",window,null,this._executeMessage);this.setMessageHandler(l),this._onResize=this._onResize.bind(this),$()&&window.addEventListener("resize",this._onResize),this._container=s,this._initData=r,this._configuratorSettings=t;const h=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=o,this._container.appendChild(h),this._iframe=h,this.setupPlugins(i,this._iframe),x.set(s,!0)}static createPlanner(t,s,r,i=[]){return this._create(t,s,r,i)}static async connect(t,s=[]){const r=new z;r.viewName=t;const{resolve:i,promise:o}=V(),{resolve:c,promise:l}=V(),h=({message:p,args:m})=>{if(p===w.REGISTER_CUSTOM_VIEW_DONE){i();return}if(p===w.RETURN_METHODS){r.handleSetup(m[0]),c();return}if(r.isSetupDone)return r.executeMessage({message:p,args:m})},u=new g("custom-view-"+t,window,window.parent,h);r.setMessageHandler(u);const d=[t];return u.sendMessage(w.REGISTER_CUSTOM_VIEW,d),await o,u.sendMessage(w.GET_METHODS,d),await l,r.setupPlugins(s,document.body,"custom-view"),await Promise.allSettled(r.pluginsLoaded),r}static createConfigurator(t,s,r,i=[]){return this._create(t,s,r,i)}static create(t,s,r,i){return this._create(t,s,r,i)}static createViewer(t,s,r,i=[]){return this._create(t,s,r,i)}static async _create(t,s,r,i){return new Promise(async(o,c)=>{try{const l=L(Ot(),At(r));l.featureFlags||(l.featureFlags={}),typeof l.featureFlags.realPartList!="boolean"&&(l.featureFlags.realPartList=!0),typeof l.featureFlags.globalCallbacks!="boolean"&&(l.featureFlags.globalCallbacks=!0),typeof l.featureFlags.mocAr!="boolean"&&(l.featureFlags.mocAr=!1);const h=await mt(t,l);r=bt(h,l);const u=new this(h,s,r,i,o);return await Promise.allSettled(u.pluginsLoaded),u}catch(l){return c(l)}})}teardown(){this._container&&x.delete(this._container);const t=this._container.querySelector("iframe");t&&this._container.removeChild(t),window.removeEventListener("resize",this._onResize)}_createIframe(){var r;const t=document.createElement("iframe");let s=((r=this._configuratorSettings)==null?void 0:r.url)||"https://www.roomle.com/t/cp/";return this._initData.useLocalRoomle&&(s=location.href.replace("embedding.html","")),location.href.includes("roomle.gitlab.io")&&(s=location.href.replace("embedding.html","index.html")),this._initData.overrideServerUrl&&(s=this._initData.overrideServerUrl),t.src=s,t.classList.add(_.CONTAINER),t.classList.add(_.FILL),t}_onResize(){J(this._iframe)}_onUseFullPage(){this._iframe.classList.add(_.POSITION),document.documentElement.classList.add(_.OVERFLOW_HIDDEN),window.document.body.classList.add(_.OVERFLOW_HIDDEN),$()&&(J(this._iframe),this._iframe.classList.add(_.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(_.POSITION),this._iframe.classList.remove(_.ANDROID_HEIGHT),document.documentElement.classList.remove(_.OVERFLOW_HIDDEN),window.document.body.classList.remove(_.OVERFLOW_HIDDEN)}_executeMessage({message:t,args:s},r){var i;if(r.source&&r.source===((i=this._iframe)==null?void 0:i.contentWindow))return t===E.REQUEST_BOOT?this._messageHandler?(this._messageHandler.setOutgoingMessageBus(r.source),Promise.resolve({result:this._initData})):(console.error("MessageHandler not set"),Promise.resolve({error:"MessageHandler not set"})):t===E.SETUP?(this.handleSetup(s[0]),q(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),q(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>{if(!this._messageHandler){console.error("MessageHandler not set");return}this._messageHandler.sendMessage(E.WEBSITE_READY)},0),Promise.resolve({result:null})):this.executeMessage({message:t,args:s})}}class Ct{constructor(e,t,s,r){a(this,"_mainDomElement");a(this,"_instance");a(this,"_mode","website");a(this,"_viewName","main");this._instance=e,this._mainDomElement=t,this._mode=s,this._viewName=r}async init(){return Promise.resolve()}}const A="rml-drag-in-styles",b="rml-drag-in-drag-element",O="rml-drag-in-overlay",v="rml-drag-in-drag-ghost",Q="rml-drag-in-fade-in",Z="rml-drag-in-fade-out",G={DISPLAY_NONE:"rml-display-none"},tt=.5,et="250ms",st="forwards",rt=`@keyframes ${Q} {from{opacity: 0;}to {opacity: ${tt};}}`,nt=`@keyframes ${Z} {from{opacity: ${tt};}to {opacity: 0;}}`,it=`${Q} ${et} ${st}`,ot=`${Z} ${et} ${st}`,M="https://res.cloudinary.com/roomle/image/upload/v1729679975/fallback_afpyqr.jpg",F=112,P=112;class Nt extends Ct{constructor(t,s,r,i){super(t,s,r,i);a(this,"options",{});a(this,"_customDragSignal",new AbortController);this._mainDomElement=s,this._injectStyles(),this._initializeDragGhost()}_injectStyles(){if(!!!document.getElementById(A)){const s=document.createElement("style");s.type="text/css",s.id=A,s.innerHTML=`
9
+ .${G.DISPLAY_NONE}{display:none}
10
+ .${O}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
11
+ .${v}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
12
+ ${rt}
13
+ ${nt}
14
+ `,document.head.appendChild(s)}}_initializeDragGhost(){const t=this._mainDomElement.parentNode;let s=t.querySelector("."+v);s||(s=document.createElement("div"),s.classList.add(v),s.innerText=" ",t.appendChild(s))}async init(){if(await super.init(),this._mode==="website"){const{DragInFromWebsiteStrategy:t}=await Promise.resolve().then(()=>Xt);this._strategy=new t(this._instance,this._mainDomElement,this.options)}else if(this._mode==="custom-view"){const{DragInFromCustomViewStrategy:t}=await Promise.resolve().then(()=>Kt);this._strategy=new t(this._instance,this.options,this._viewName)}else throw new Error("Unsupported mode")}get isDragging(){return this._strategy.isDragging}dragStart(t,s,r="rml_id"){this._strategy.dragStart(t,s,r)}dragUpdate(t){this._strategy.dragUpdate(t)}dragEnd(){this._strategy.dragEnd()}touchStart(t,s,r="rml_id"){this._strategy.touchStart(t,s,r)}touchMove(t){this._strategy.touchMove(t)}touchEnd(){this._strategy.touchEnd()}dispose(){this._strategy.dispose()}beforeUpdateGhost(t){this._strategy.beforeUpdateGhost(t)}registerCustomDrag({customDragStart:t,customDragEnd:s,customDragUpdate:r,beforeUpdateGhost:i}){i&&this._strategy.beforeUpdateGhost(i);const o=this._customDragSignal.signal,c=u=>{u.target.getAttribute("data-rml-draggable")==="true"&&t(u)},l=u=>{this._strategy.releaseInput(u),this._strategy.isDragging&&s(u)},h=u=>{r(u)};document.querySelectorAll('[data-rml-draggable="true"]').forEach(u=>{u.draggable=!1}),document.addEventListener("mousedown",c,{signal:o}),document.addEventListener("mouseup",l,{signal:o}),document.addEventListener("mousemove",h,{signal:o}),document.addEventListener("mouseleave",l,{signal:o}),document.addEventListener("touchstart",c,{signal:o}),document.addEventListener("touchend",l,{signal:o}),document.addEventListener("touchmove",h,{signal:o})}unregisterCustomDrag(){this._customDragSignal.abort(),this._customDragSignal=new AbortController}releaseInput(t){this._strategy.releaseInput(t)}}const xt=Object.freeze(Object.defineProperty({__proto__:null,DragIn:Nt},Symbol.toStringTag,{value:"Module"}));class Gt{constructor(e=16){a(this,"_computedStyleCache",new Map);a(this,"_maxLifetime",16);a(this,"_cacheCleanInterval",null);this._maxLifetime=e}get(e){const t=this._computedStyleCache.get(e),s=Date.now();if(t&&s-t.updated<this._maxLifetime)return t.style;const r=getComputedStyle(e);return this._computedStyleCache.set(e,{style:r,updated:s}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),r}_cleanUpCache(){const e=Date.now();for(const[t,{updated:s}]of this._computedStyleCache.entries())e-s>=this._maxLifetime&&this._computedStyleCache.delete(t);this._computedStyleCache.size===0&&this._cacheCleanInterval&&(clearInterval(this._cacheCleanInterval),this._cacheCleanInterval=null)}}const D=n=>window.TouchEvent&&n instanceof window.TouchEvent;let H;const R=n=>(H||(H=new Gt),H.get(n)),at=(n,e,t)=>{const s=parseFloat(n),r=window.devicePixelRatio||1;if(e==="px")return s;if(e==="%"){const o=t===document.documentElement?window.innerWidth:t.offsetWidth;return s/100*o}if(e==="rem"){const o=parseFloat(R(document.documentElement).fontSize);return s*o}if(e==="em"){const o=parseFloat(R(t).fontSize);return s*o}if(e==="vh"||e==="vw"||e==="vmin"||e==="vmax"){const o={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return s/100*o[e]}const i={cm:37.7952755906,mm:3.77952755906,in:96};return e in i?s*i[e]*r:(console.warn("Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"),0)},ct=(n,e,t={x:0,y:0})=>{const s=n.getBoundingClientRect(),i=R(n).transform;let o=0,c=0;if(i!=="none"){const p=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,m=i.match(p);m&&(o=at(m[1],m[2],n),c=at(m[3],m[4],n))}const{clientX:l,clientY:h}=T(e,t),u=l-s.left-o+n.scrollLeft,d=h-s.top-c+n.scrollTop;return{x:u,y:d}},T=(n,e=null)=>{const{clientX:t,clientY:s}=D(n)?Ft(n):n,r=t>0?t:e?e.x:t,i=s>0?s:e?e.y:s;return{clientX:r,clientY:i}},Ft=n=>{if(n.touches.length){let{clientX:t,clientY:s}=n.touches[0];if(n.touches.length>1){const r=n.touches[1],i=r.clientX,o=r.clientY;t=(t+i)/2,s=(s+o)/2}return{clientX:t,clientY:s}}const e=n.changedTouches[0];return{clientX:e.clientX,clientY:e.clientY}},U=500,B=10,lt=100,ht=15,Y=(n,e=0)=>D(n)?{clientX:n.touches[e].clientX,clientY:n.touches[e].clientY}:{clientX:n.clientX,clientY:n.clientY},ut=n=>n&&D(n)?n.touches.length>0:!0;class dt{constructor(e,{onTouchDragStart:t},s={}){a(this,"_touchDragTimeOut");a(this,"_onTouchDragStart");a(this,"_payload",null);a(this,"_delay",U);a(this,"_firstTouch",null);a(this,"_lastTouch",null);a(this,"_epsilon",B);this._payload=e,this._onTouchDragStart=t,this._delay=typeof s.delay=="number"?s.delay:U,this._epsilon=typeof s.epsilon=="number"?s.epsilon:B}onStart(e){ut(e)&&(this._touchDragTimeOut||(this._firstTouch=Y(e,D(e)?e.touches.length-1:0),this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=Y(e)),this._checkXDistance(e)()},this._delay)))}onEnd(){this._resetTouches()}onMove(e){ut(e)&&(this._lastTouch=Y(e))}_clearTimeout(){this._touchDragTimeOut&&(clearTimeout(this._touchDragTimeOut),this._touchDragTimeOut=null)}_resetTouches(){this._clearTimeout(),this._lastTouch=null,this._firstTouch=null,this._payload=null}_checkXDistance(e){return()=>{if(!this._firstTouch||!this._lastTouch)return;let t=!1;t=Math.abs(this._firstTouch.clientX-this._lastTouch.clientX)<this._epsilon,t&&(this._onTouchDragStart(this._payload,e),this._resetTouches())}}}const gt=(n,e,t=0,s=0)=>{const r=e.x+e.width+t,i=e.x-t,o=e.y+e.height+s,c=e.y-s,{x:l,y:h}=n;return l>=i&&l<=r&&h>=c&&h<=o},Pt=()=>{if(!!!document.getElementById(A)){const e=document.createElement("style");e.type="text/css",e.id=A,e.innerHTML=`
15
+ ${rt}
16
+ ${nt}
17
+ `,document.head.appendChild(e)}},Ht=({x:n,y:e},t,s)=>{var i,o,c,l;let r=document.getElementById(b);if(!r){if(r=document.createElement("div"),(i=t.ghost)!=null&&i.element)r.appendChild(t.ghost.element);else{const h=document.createElement("img");h.src=((o=t.ghost)==null?void 0:o.url)||M,h.width=((c=t.ghost)==null?void 0:c.width)||F,h.height=((l=t.ghost)==null?void 0:l.height)||P,r.appendChild(h)}r.id=b,r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.willChange="transform",r.style.transform="translate3d(0, 0, 0)",r.style.zIndex="9999",r.style.opacity="0.5",t.ghost&&t.ghost.visibleIn&&!gt({x:n,y:e},t.ghost.visibleIn,s.dragInOverlapX,s.dragInOverlapY)&&(r.style.display="none"),r.style.pointerEvents="none",document.body.appendChild(r)}},Ut=({x:n,y:e},t,s)=>{var h,u;const r=document.getElementById(b);if(!r)return;let i=(h=t.ghost)==null?void 0:h.width,o=(u=t.ghost)==null?void 0:u.height;typeof i>"u"&&(i=r.getBoundingClientRect().width||F),typeof o>"u"&&(o=r.getBoundingClientRect().height||P);const c=n-i/2,l=e-o/2;r.style.transform=`translate3d(${c}px, ${l}px, 0)`,t.ghost&&(!t.ghost.visibleIn||gt({x:n,y:e},t.ghost.visibleIn,s.dragInOverlapX,s.dragInOverlapY)?r.style.animation!=it&&(r.style.animation=it):r.style.animation!=ot&&(r.style.animation=ot))};class Bt{constructor(e=null){a(this,"_dragGhostAnimationFrameId",null);a(this,"_dragGhostRemoveAnimationFrameId",null);a(this,"_dragGhostElement",null);this._dragGhostElement=e}updateDragGhost(e,t,s={},r={}){var i;this._dragGhostRemoveAnimationFrameId&&(cancelAnimationFrame(this._dragGhostRemoveAnimationFrameId),this._dragGhostRemoveAnimationFrameId=null),!((i=s.ghost)!=null&&i.external)&&s.ghost&&(this._dragGhostAnimationFrameId||(this._dragGhostAnimationFrameId=requestAnimationFrame(()=>{Pt();const o={x:e,y:t};!s.ghost&&this._dragGhostElement&&(s.ghost={}),s.ghost&&!s.ghost.element&&this._dragGhostElement&&(s.ghost.element=this._dragGhostElement),Ht(o,s,r),Ut(o,s,r),this._dragGhostAnimationFrameId=null})))}removeDragGhost(){this._dragGhostAnimationFrameId&&(cancelAnimationFrame(this._dragGhostAnimationFrameId),this._dragGhostAnimationFrameId=null),this._dragGhostRemoveAnimationFrameId||(this._dragGhostRemoveAnimationFrameId=requestAnimationFrame(()=>{const e=document.getElementById(b);e&&document.body.removeChild(e),this._dragGhostRemoveAnimationFrameId=null}))}}class Yt{constructor(e,t,s){a(this,"_options",{});a(this,"_instance");a(this,"_mainDomElement");a(this,"_currentDrag",{});a(this,"_currentTouch",null);a(this,"_firefoxDragPosition",{x:0,y:0});a(this,"_onBeforeUpdateDrag",()=>({}));a(this,"isDragging",!1);a(this,"_firefoxFallback",e=>{if(!this._currentDrag.event)return;const t=e||window.event;this._firefoxDragPosition.x=t.pageX||0,this._firefoxDragPosition.y=t.pageY||0});this._instance=e,this._mainDomElement=t,this._options=s||{},this._firefoxFallback=this._firefoxFallback.bind(this),document.addEventListener("dragover",this._firefoxFallback)}beforeUpdateGhost(e){this._onBeforeUpdateDrag=e}dragStart(e,t,s="rml_id"){const r=this._mainDomElement.parentNode;if(R(r).position!=="relative"){console.warn("Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly");return}this._mainDomElement.style.pointerEvents="none";let o=r.querySelector("."+O);o||(o=document.createElement("div"),o.classList.add(O),r.appendChild(o)),o.classList.remove(G.DISPLAY_NONE),t.target.getAttribute("draggable")||console.warn(`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`);const l=r.querySelector("."+v);this._currentDrag.event=t;const h=t.target,u=h.cloneNode(),d=h.getBoundingClientRect();u.style.width=`${d.width}px`,u.style.height=`${d.height}px`,this._currentDrag.ghost=new Bt(u),this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0});const{clientX:p,clientY:m}=T(t,this._firefoxDragPosition);this._currentDrag.offset.x=p-d.left,this._currentDrag.offset.y=m-d.top,t instanceof DragEvent&&t.dataTransfer&&t.dataTransfer.setDragImage&&t.dataTransfer.setDragImage(l,0,0);const{x:y,y:S}=ct(r,this._currentDrag.event||t,this._firefoxDragPosition),I=Math.max(1,y),Jt=Math.max(1,S);this.isDragging=!0,this._instance.dragInObject(e,I,Jt,s)}dragUpdate(e){const t=this._mainDomElement.parentNode,{x:s,y:r}=ct(t,e,this._firefoxDragPosition);if(s===0&&r===0)return;const i=Math.max(1,s),o=Math.max(1,r);if(i===1&&o===1)return;let c=i,l=o;if(D(e)){const y=this._options.fingerSize||0;c=Math.max(2,i+y),l=Math.max(2,o-y)}const{x:h,y:u,options:d}=this._onBeforeUpdateDrag(c,l,{}),p=typeof h=="number"?h:c,m=typeof u=="number"?u:l;if(this._currentDrag.ghost){const{clientX:y,clientY:S}=T(e,this._firefoxDragPosition);console.log("dragin","dragupdate is here: ",location.href),this._currentDrag.ghost.updateDragGhost(y,S,d||{},this._options||{})}this._instance.updateDrag(p,m,{})}dragEnd(){this._mainDomElement.style.pointerEvents="all";const e=this._mainDomElement.parentNode;this.isDragging=!1,this._instance.dragInObjectEnd(),this._currentDrag.ghost&&(this._currentDrag.ghost.removeDragGhost(),this._currentDrag.ghost=null),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const t=e.querySelector("."+O);t&&t.classList.add(G.DISPLAY_NONE)}touchStart(e,t,s="rml_id"){var o,c;t.preventDefault();const r=(l,h)=>{this.dragStart(e,h,s)},i={};typeof((o=this._options)==null?void 0:o.touchDragDelay)=="number"&&(i.delay=this._options.touchDragDelay),(c=this._options)!=null&&c.touchDragEpsilon&&(i.epsilon=this._options.touchDragEpsilon),this._currentTouch=new dt(void 0,{onTouchDragStart:r},i),this._currentTouch.onStart(t)}touchMove(e){this._currentTouch&&this._currentTouch.onMove(e),this._currentDrag.event&&this.dragUpdate(e)}touchEnd(){this._currentTouch&&this._currentTouch.onEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}releaseInput(e){}}const Xt=Object.freeze(Object.defineProperty({__proto__:null,DragInFromWebsiteStrategy:Yt},Symbol.toStringTag,{value:"Module"})),Wt=n=>`[data-rml-custom-view="${n}"]`,X=n=>{n.preventDefault(),n.stopPropagation()},kt=(n,e,t,s)=>{const r=t-n,i=s-e;return Math.sqrt(r*r+i*i)};class $t{constructor({onCustomDragStart:e},t={}){a(this,"_startX",0);a(this,"_startY",0);a(this,"_lastX",0);a(this,"_lastY",0);a(this,"_delay");a(this,"_epsilon");a(this,"_isStarted",!1);a(this,"_isEnded",!1);a(this,"_isWaiting",!1);a(this,"_onCustomDragStart");this._delay=typeof t.delay=="number"?t.delay:lt,this._epsilon=typeof t.epsilon=="number"?t.epsilon:ht,this._onCustomDragStart=e}onMove(e){this._lastX=e.clientX,this._lastY=e.clientY,this._isWaiting&&kt(this._startX,this._startY,this._lastX,this._lastY)>this._epsilon&&(this._onCustomDragStart(e),this._isWaiting=!1)}onStart(e){this._startX=e.clientX,this._startY=e.clientY,this.onMove(e),this._isWaiting=!0}onEnd(){this._reset()}_reset(){this._startX=0,this._startY=0,this._lastX=0,this._lastY=0,this._isWaiting=!1}}const W="data-rml-old-draggable",zt=void 0,_t=(n,e)=>{const t=D(n),s={delay:t?U:lt,epsilon:t?B:ht};if(!e)return s;if(!t&&!(n instanceof MouseEvent))return console.warn("Unsupported event! It is not TouchEvent and also not MouseEvent"),s;const{delayKey:r,epsilonKey:i}=t?{delayKey:"touchDragDelay",epsilonKey:"touchDragEpsilon"}:{delayKey:"customDragDelay",epsilonKey:"customDragEpsilon"};return typeof e[r]=="number"&&(s.delay=e.touchDragDelay),typeof e[i]=="number"&&(s.epsilon=e.touchDragEpsilon),s},Vt=n=>{let e="",t=F,s=P;if(!n)return{url:M,width:t,height:s};const r=n;if(r instanceof HTMLElement){const i=r.getBoundingClientRect(),o=r.getAttribute("data-rml-ghost-url"),c=r.getAttribute("data-rml-ghost-width"),l=r.getAttribute("data-rml-ghost-height");o?e=o:!o&&r instanceof HTMLImageElement&&r.src&&(e=r.src),e?(t=i.width,s=i.height):e=M,t=c?parseInt(c,10):t,s=l?parseInt(l,10):s}return{url:e||M,width:t,height:s}};class qt{constructor(e,t,s){a(this,"_options",{});a(this,"_instance");a(this,"_viewName");a(this,"_currentCustomDrag",null);a(this,"_currentBb",null);a(this,"_startTarget",null);a(this,"_onBeforeUpdateDrag",()=>({}));a(this,"isDragging",!1);this._instance=e,this._options=t||{},this._viewName=s}beforeUpdateGhost(e){this._onBeforeUpdateDrag=e}async _dragStart(e,t,s="rml_id"){this._startTarget&&(this._startTarget.style.pointerEvents="none",this._startTarget.style.userSelect="none",this._startTarget.setAttribute(W,this._startTarget.draggable.toString()),this._startTarget.draggable=!1,this._startTarget.removeEventListener("dragstart",X),this._startTarget.addEventListener("dragstart",X)),this._currentBb=await this._instance.getBoundingClientRect(Wt(this._viewName));const{clientX:r,clientY:i}=T(t),o=this._currentBb.x+r,c=this._currentBb.y+i;this.isDragging=!0,this._instance.dragInObject(e,o,c,s)}_dragUpdate(e){if(document.body.focus(),this._currentCustomDrag&&this._currentCustomDrag.onMove(e),!this._currentBb||!this.isDragging)return;const{clientX:t,clientY:s}=T(e),{url:r,width:i,height:o}=Vt(this._startTarget),c=this._currentBb.x+t,l=this._currentBb.y+s,h=this._options||{},u={ghost:{visibleIn:{x:this._currentBb.x-(h.dragInOverlapX||0),y:this._currentBb.y+(h.dragInOverlapY||0),width:this._currentBb.width+(h.dragInOverlapX||0),height:this._currentBb.height+(h.dragInOverlapY||0)},url:r,width:i,height:o}},{x:d,y:p,options:m}=this._onBeforeUpdateDrag(c,l,u),y=typeof d=="number"?d:c,S=typeof p=="number"?p:l,I=m||u;this._instance.updateDrag(y,S,I)}_dragEnd(){this._currentCustomDrag&&this._currentCustomDrag.onEnd(),this._currentCustomDrag=null,this.isDragging=!1,this._currentBb=null,this._resetStartTarget(),this._instance.enableEvents(),this._instance.dragInObjectEnd()}dragStart(e,t,s){this._instance.disableEvents(),this._startTarget=t.target;const r=(i,o)=>{this._dragStart(e,o,s)};this._currentCustomDrag=D(t)?new dt(zt,{onTouchDragStart:r},_t(t,this._options)):new $t({onCustomDragStart:i=>this._dragStart(e,i,s)},_t(t,this._options)),this._currentCustomDrag.onStart(t)}dragEnd(){this._dragEnd()}dragUpdate(e){this._dragUpdate(e)}touchStart(e,t,s="rml_id"){this.dragStart(e,t,s)}touchMove(e){this.dragUpdate(e)}touchEnd(){this.dragEnd()}dispose(){}_resetStartTarget(){this._startTarget&&(this._startTarget.style.pointerEvents="",this._startTarget.style.userSelect="",this._startTarget.draggable=this._startTarget.getAttribute(W)==="true",this._startTarget.removeAttribute(W),this._startTarget.removeEventListener("dragstart",X))}releaseInput(e){this._currentCustomDrag&&this._currentCustomDrag.onEnd(),this._resetStartTarget()}}const Kt=Object.freeze(Object.defineProperty({__proto__:null,DragInFromCustomViewStrategy:qt},Symbol.toStringTag,{value:"Module"}));return Lt});
@@ -1,14 +1,17 @@
1
- (function(_,y){typeof exports=="object"&&typeof module<"u"?module.exports=y():typeof define=="function"&&define.amd?define(y):(_=typeof globalThis<"u"?globalThis:_||self,_["roomle-embedding-lib"]=_["roomle-embedding-lib"]||{},_["roomle-embedding-lib"].umd=_["roomle-embedding-lib"].umd||{},_["roomle-embedding-lib"].umd.min=_["roomle-embedding-lib"].umd.min||{},_["roomle-embedding-lib"].umd.min.js=y())})(this,function(){"use strict";var _=Object.defineProperty,y=(i,e,t)=>e in i?_(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,l=(i,e,t)=>y(i,typeof e!="symbol"?e+"":e,t);class q{constructor(e,t,s,r){l(this,"_side"),l(this,"_incomingMessageBus"),l(this,"_outgoingMessageBus",null),l(this,"_execMessage",null),this._side=e,this._incomingMessageBus=t,this._outgoingMessageBus=s,this._execMessage=r,this._incomingMessageBus.addEventListener("message",this._handleMessage.bind(this))}setOutgoingMessageBus(e){this._outgoingMessageBus=e}setMessageExecution(e){this._execMessage=e}sendMessage(e,t=[]){return new Promise((s,r)=>{const o=new MessageChannel;o.port1.onmessage=n=>{if(!n||!n.data)return o.port1.close(),o.port2.close(),r(new Error(this._side+" received message but response can not be interpreted"));let c;try{c=JSON.parse(n.data)}catch(h){return o.port1.close(),o.port2.close(),this._prepareError(h),r(h)}c.error?r(c.error):c.result!==void 0?s(c.result):s(void 0),o.port1.close(),o.port2.close()};let a="";try{a=JSON.stringify({message:e,args:t})}catch{return r(new Error(this._side+": can not create command because it is not JSON.stringify able"))}if(!this._outgoingMessageBus)return r(new Error(this._side+": outgoing bus not set yet"));this._outgoingMessageBus.postMessage(a,"*",[o.port2])})}_handleMessage(e){const t=e.ports&&Array.isArray(e.ports)&&e.ports.length>0?e.ports[0]:null;if(e.data&&t)try{const s=JSON.parse(e.data);if(!this._execMessage)return t.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(s.args)||(s.args=[s.args]);const r=this._execMessage(s,e);if(r===void 0)return;r.then((o={})=>{let a,n;typeof o=="object"&&o!==null&&(a=o.error,n=o.result),a?t.postMessage(JSON.stringify({error:a})):n!==void 0?t.postMessage(JSON.stringify({result:n})):t.postMessage(JSON.stringify({result:o}))},o=>{t.postMessage(JSON.stringify({error:this._prepareError(o)}))})}catch(s){t.postMessage(JSON.stringify({error:this._prepareError(s)}))}}_prepareError(e){if(typeof e=="string"){const t=this._side+": "+e;return console.error(t),t}return e.message=this._side+": "+e.message,console.error(e),e.message}}const D=".",T={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},G=async(i,e)=>{if(typeof i!="string")throw new Error('Configurator ID is not a string type: "'+typeof i+'"');const t=e.customApiUrl?e.customApiUrl:"https://api.roomle.com/v2",s=e.overrideTenant||9,r=t+"/configurators/"+i,o="roomle_portal_v2",a="03-"+window.btoa(new Date().toISOString()+";anonymous;"+o),n=()=>{const d={apiKey:o,currentTenant:s,locale:"en",language:"en",device:1,token:a,platform:"web"};return new Headers(d)},c=new Request(r,{method:"GET",headers:n(),mode:"cors",cache:"default"}),h=await fetch(c),{configurator:u}=await h.json();return u},Q=()=>{try{return window.self!==window.top}catch{return!0}},K=["127.0.0.1","localhost","0.0.0.0"],Z=()=>{const i=Q();let e=window.location.href;if(i){if(!document.referrer)return null;e=document.referrer}const{hostname:t}=new URL(e);return t},ee=i=>!!(K.includes(i)||i.endsWith("roomle.com")||i.endsWith("gitlab.io")||i.endsWith("gitlab.com")),C=["language","browserLanguage","userLanguage","systemLanguage"],te=(i=null)=>{const e=window.navigator;if(i)return i.substr(0,2);if(Array.isArray(e.languages)&&e.languages.length>0)return e.languages[0].substr(0,2);for(let t=0,s=C.length;t<s;t++){const r=e[C[t]];if(r)return r.substr(0,2)}return"en"},ie=(i,e)=>{const t=JSON.parse(JSON.stringify(i));return E(t,e)},E=(i,e)=>{for(const t in e)try{e[t].constructor===Object?i[t]=E(i[t],e[t]):i[t]=e[t]}catch{i[t]=e[t]}return i};var se={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const re={mobileLandscape:!0,floorMaterialRootTag:"materials_root",buttons:{renderimage:!0,requestproduct:!0,requestplan:!0,load_product:!0,partlist_print:!0},helpcenter:{roomdesigner:!0,configurator:!1,disable:!1},firstPersonView:!0,saveToIdb:!0,featureFlags:{mocAr:!0,wallAutoHeight:!1},rotationSnapDegrees:10},ne="(idle)",oe=i=>(I(i),i!=null&&i.customApiUrl&&(i.customApiUrl=decodeURIComponent(i.customApiUrl)),i.shareUrl&&(i.deeplink=i.shareUrl.replace(ce,he)),i),I=i=>{if(!i)return;const e=Object.keys(i);for(const t of e){const s=i[t];if(!Array.isArray(s)&&typeof s=="object"&&s!==null&&I(s),Array.isArray(s))for(const r of s)I(r);(s==="true"||s==="false")&&(i[t]=s==="true")}},ae=(i,e)=>{e.configuratorId=i.id;const t=i.settings||{};return!e.overrideTenant&&i.tenant&&(e.overrideTenant=i.tenant),ie(t,e)},le=()=>{const i={...re};i.locale||(i.locale=te()),i.id===ne&&delete i.id;const e=Z();return e&&ee(e)&&(i.configuratorId="demoConfigurator"),i.customApiUrl=se.VITE_RAPI_URL,i.emails=!1,i},ce="<CONF_ID>",he="#CONFIGURATIONID#",F=()=>/(android)/i.test(navigator.userAgent),k=(i,e,t)=>{let s=null;Object.defineProperty(i,e,{get(){return s||t},set(r){r!=null&&r.mute?s=r.value:(console.warn("You override Roomle defined behaviour. To disalbe this warning pass in an object with the following properties"),console.warn("{ mute: true, value: () => void }"),s=r)}})},U=()=>window.innerHeight*.01+"px",$=i=>{i&&setTimeout(()=>i.style.setProperty(x,U()),0)},H="rml-styles",ue=450,x="--rml-full-height",m={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},O=new Map;class de{constructor(e,t,s,r,o){if(l(this,"ui",{callbacks:null}),l(this,"extended",{callbacks:null}),l(this,"configurator",{callbacks:null}),l(this,"analytics",{callbacks:{}}),l(this,"global",{callbacks:{}}),l(this,"plugins",{}),l(this,"_waitForIframe"),l(this,"_container"),l(this,"_messageHandler"),l(this,"_configuratorSettings"),l(this,"_initData",{}),l(this,"_iframe"),l(this,"pluginsLoaded",[]),!e||typeof e.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(O.has(t))throw new Error("There is already an instance on this DOM element");if(!document.getElementById(H)){const n=s.zIndex||9999999,c=document.createElement("style");c.type="text/css",c.id=H;const h="transition:all ease-in-out "+ue+"ms;",u=["-webkit-","-o-"].reduce((g,f)=>g+=f+h,"")+h,d=U();c.innerHTML=`
2
- .${m.CONTAINER}{${x}:${d};}
3
- .${m.POSITION}{position:fixed;top:0;left:0;z-index:${n};opacity:0}
4
- .${m.TRANSITION}{${u}}
5
- .${m.FILL}{width:100%;height:100%;opacity:1}
6
- .${m.ANDROID_HEIGHT}{height:calc(var(${x},1vh)*100)}
7
- .${m.OVERFLOW_HIDDEN}{overflow:hidden}
8
- `,document.head.appendChild(c)}this._onResize=this._onResize.bind(this),F()&&window.addEventListener("resize",this._onResize),this._container=t,this._initData=s,this._configuratorSettings=e;const a=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._executeMessage=this._executeMessage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._messageHandler=new q("website",window,null,this._executeMessage),this._waitForIframe=o,this._container.appendChild(a),this._iframe=a;for(const n of r)typeof n=="string"&&n==="dragIn"?this.pluginsLoaded.push(new Promise((c,h)=>{try{Promise.resolve().then(()=>ye).then(({DragIn:u})=>{const d=new u(this._iframe);d.setInstance(this.ui),this.plugins.dragIn=d,c()})}catch(u){h(u)}})):n.name&&n.loader&&this.pluginsLoaded.push(new Promise((c,h)=>{try{n.loader().then(u=>{const d=new u(this._iframe);d.setInstance(this.ui),this.plugins[n.name]=d,c()})}catch(u){h(u)}}));O.set(t,!0)}static createPlanner(e,t,s,r=[]){return this._create(e,t,s,r)}static createConfigurator(e,t,s,r=[]){return this._create(e,t,s,r)}static create(e,t,s,r){return this._create(e,t,s,r)}static createViewer(e,t,s,r=[]){return this._create(e,t,s,r)}static async _create(e,t,s,r){return new Promise(async(o,a)=>{try{const n=E(le(),oe(s));n.featureFlags||(n.featureFlags={}),typeof n.featureFlags.realPartList!="boolean"&&(n.featureFlags.realPartList=!0),typeof n.featureFlags.globalCallbacks!="boolean"&&(n.featureFlags.globalCallbacks=!0),typeof n.featureFlags.mocAr!="boolean"&&(n.featureFlags.mocAr=!1);const c=await G(e,n);s=ae(c,n);const h=new this(c,t,s,r,o);return console.info(h),await Promise.allSettled(h.pluginsLoaded),h}catch(n){return a(n)}})}teardown(){this._container&&O.delete(this._container);const e=this._container.querySelector("iframe");e&&this._container.removeChild(e),window.removeEventListener("resize",this._onResize)}_createIframe(){var e;const t=document.createElement("iframe");let s=((e=this._configuratorSettings)==null?void 0:e.url)||"https://www.roomle.com/t/cp/";return this._initData.useLocalRoomle&&(s=location.href.replace("embedding.html","")),location.href.includes("roomle.gitlab.io")&&(s=location.href.replace("embedding.html","index.html")),this._initData.overrideServerUrl&&(s=this._initData.overrideServerUrl),t.src=s,t.classList.add(m.CONTAINER),t.classList.add(m.FILL),t}_onResize(){$(this._iframe)}_onUseFullPage(){this._iframe.classList.add(m.POSITION),document.documentElement.classList.add(m.OVERFLOW_HIDDEN),window.document.body.classList.add(m.OVERFLOW_HIDDEN),F()&&($(this._iframe),this._iframe.classList.add(m.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(m.POSITION),this._iframe.classList.remove(m.ANDROID_HEIGHT),document.documentElement.classList.remove(m.OVERFLOW_HIDDEN),window.document.body.classList.remove(m.OVERFLOW_HIDDEN)}_executeMessage({message:e,args:t},s){var r;if(!s.source||s.source!==((r=this._iframe)==null?void 0:r.contentWindow))return;if(e===T.REQUEST_BOOT)return this._messageHandler.setOutgoingMessageBus(s.source),Promise.resolve({result:this._initData});if(e===T.SETUP){const{methods:h,callbacks:u}=t[0];return h.forEach(d=>{const g=d.split(D),f=g[0],p=g[1];this[f]||(this[f]={}),this[f][p]=function(){return this._messageHandler.sendMessage(d,[...arguments])}.bind(this)}),u.forEach(d=>{const g=d.split(D),f=g[0],p=g[1],ve=g[2];this[f]||(this[f]={}),this[f][p]||(this[f][p]={}),this[f][p][ve]=()=>{}}),k(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),k(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>this._messageHandler.sendMessage(T.WEBSITE_READY),0),Promise.resolve({result:null})}const o=e.split(D),a=o[0],n=o[1],c=o.length===3?o[2]:null;if(c&&this[a][n][c]){const h=this[a][n][c](...t);return h instanceof Promise?h.then(u=>({result:u})):h!==void 0?Promise.resolve({result:h}):Promise.resolve({result:null})}return Promise.reject('Message "'+e+'" is unkown')}}class ge{constructor(e=16){l(this,"_computedStyleCache",new Map),l(this,"_maxLifetime",16),l(this,"_cacheCleanInterval",null),this._maxLifetime=e}get(e){const t=this._computedStyleCache.get(e),s=Date.now();if(t&&s-t.updated<this._maxLifetime)return t.style;const r=getComputedStyle(e);return this._computedStyleCache.set(e,{style:r,updated:s}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),r}_cleanUpCache(){const e=Date.now();for(const[t,{updated:s}]of this._computedStyleCache.entries())e-s>=this._maxLifetime&&this._computedStyleCache.delete(t);this._computedStyleCache.size===0&&this._cacheCleanInterval&&(clearInterval(this._cacheCleanInterval),this._cacheCleanInterval=null)}}const B=i=>window.TouchEvent&&i instanceof window.TouchEvent;let S;const v=i=>(S||(S=new ge),S.get(i)),W=(i,e,t)=>{const s=parseFloat(i),r=window.devicePixelRatio||1;if(e==="px")return s;if(e==="%"){const a=t===document.documentElement?window.innerWidth:t.offsetWidth;return s/100*a}if(e==="rem"){const a=parseFloat(v(document.documentElement).fontSize);return s*a}if(e==="em"){const a=parseFloat(v(t).fontSize);return s*a}if(e==="vh"||e==="vw"||e==="vmin"||e==="vmax"){const a={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return s/100*a[e]}const o={cm:37.7952755906,mm:3.77952755906,in:96};return e in o?s*o[e]*r:(console.warn("Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"),0)},z=(i,e,t={x:0,y:0})=>{const s=i.getBoundingClientRect(),r=v(i).transform;let o=0,a=0;if(r!=="none"){const d=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,g=r.match(d);g&&(o=W(g[1],g[2],i),a=W(g[3],g[4],i))}const{clientX:n,clientY:c}=L(e,t),h=n-s.left-o+i.scrollLeft,u=c-s.top-a+i.scrollTop;return{x:h,y:u}},L=(i,e)=>{const{clientX:t,clientY:s}=B(i)?me(i):i,r=t||e.x,o=s||e.y;return{clientX:r,clientY:o}},me=i=>{if(i.touches.length){let{clientX:t,clientY:s}=i.touches[0];if(i.touches.length>1){const r=i.touches[1],o=r.clientX,a=r.clientY;t=(t+o)/2,s=(s+a)/2}return{clientX:t,clientY:s}}const e=i.changedTouches[0];return{clientX:e.clientX,clientY:e.clientY}},Y=500,j=10;class fe{constructor(e,{onTouchDragStart:t},s={}){l(this,"_touchDragTimeOut"),l(this,"_onTouchDragStart"),l(this,"_payload",null),l(this,"_delay",Y),l(this,"_firstTouch",null),l(this,"_lastTouch",null),l(this,"_epsilon",j),this._payload=e,this._onTouchDragStart=t,this._delay=s.delay||Y,this._epsilon=s.epsilon||j}onTouchStart(e){var t;!e||!((t=e?.touches)!=null&&t.length)||this._touchDragTimeOut||(this._firstTouch=e.touches[e.touches.length-1],this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=e.touches[0]),this._checkXDistance(e)()},this._delay))}onTouchEnd(){this._resetTouches()}onTouchMove(e){var t;!e||!((t=e?.touches)!=null&&t.length)||(this._lastTouch=e.touches[0])}_clearTimeout(){this._touchDragTimeOut&&(clearTimeout(this._touchDragTimeOut),this._touchDragTimeOut=null)}_resetTouches(){this._clearTimeout(),this._lastTouch=null,this._firstTouch=null,this._payload=null}_checkXDistance(e){return()=>{if(!this._firstTouch||!this._lastTouch)return;let t=!1;t=Math.abs(this._firstTouch.clientX-this._lastTouch.clientX)<this._epsilon,t&&(this._onTouchDragStart(this._payload,e),this._resetTouches())}}}const X="rml-drag-in-styles",_e="rml-drag-in-drag-element",w="rml-drag-in-overlay",b="rml-drag-in-drag-ghost",M="rml-drag-in-fade-in",J="rml-drag-in-fade-out",N={DISPLAY_NONE:"rml-display-none"},V=.5,P="250ms",R="forwards",A=i=>i?!0:(console.warn("No instance set, cancel drag-in"),!1);class pe{constructor(e){l(this,"_iframe"),l(this,"_currentDrag",{}),l(this,"_currentTouch",null),l(this,"_firefoxDragPosition",{x:0,y:0}),l(this,"_instance",null),l(this,"options",{}),l(this,"_firefoxFallback",t=>{if(!this._currentDrag.event)return;const s=t||window.event;this._firefoxDragPosition.x=s.pageX||0,this._firefoxDragPosition.y=s.pageY||0}),this._iframe=e,this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!document.getElementById(X)){const e=document.createElement("style");e.type="text/css",e.id=X,e.innerHTML=`
9
- .${N.DISPLAY_NONE}{display:none}
10
- .${w}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
11
- .${b}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
12
- @keyframes ${M} {from{opacity: 0;}to {opacity: ${V};}}
13
- @keyframes ${J} {from{opacity: ${V};}to {opacity: 0;}}
14
- `,document.head.appendChild(e)}}_initializeDragGhost(){const e=this._iframe.parentNode;let t=e.querySelector("."+b);t||(t=document.createElement("div"),t.classList.add(b),t.innerText=" ",e.appendChild(t))}setInstance(e){this._instance=e}dragStart(e,t,s="rml_id"){const r=this._iframe.parentNode;if(v(r).position!=="relative"){console.warn("Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly");return}this._iframe.style.pointerEvents="none";let o=r.querySelector("."+w);o||(o=document.createElement("div"),o.classList.add(w),r.appendChild(o)),o.classList.remove(N.DISPLAY_NONE),t.target.getAttribute("draggable")||console.warn(`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`);const a=r.querySelector("."+b);this._currentDrag.event=t;const n=t.target.cloneNode();n.style.position="fixed",n.style.pointerEvents="none",n.style.opacity="0",n.style.animation=`${M} ${P} ${R}`,n.id=_e,n.style.zIndex="9999",document.body.appendChild(n),this._currentDrag.element=n;const c=t.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0});const{clientX:h,clientY:u}=L(t,this._firefoxDragPosition);this._currentDrag.offset.x=h-c.left,this._currentDrag.offset.y=u-c.top,n.style.top=u+"px",n.style.left=h+"px",t instanceof DragEvent&&t.dataTransfer&&t.dataTransfer.setDragImage&&t.dataTransfer.setDragImage(a,0,0);const{x:d,y:g}=z(r,this._currentDrag.event||t,this._firefoxDragPosition),f=Math.max(1,d),p=Math.max(1,g);A(this._instance)&&this._instance.dragInObject(e,f,p,s)}dragUpdate(e){var t,s;const r=this._iframe.parentNode,{x:o,y:a}=z(r,e,this._firefoxDragPosition);if(o===0&&a===0)return;const n=Math.max(1,o),c=Math.max(1,a);if(this._currentDrag.element){const{clientX:h,clientY:u}=L(e,this._firefoxDragPosition),d=((t=this._currentDrag.offset)==null?void 0:t.x)||0,g=((s=this._currentDrag.offset)==null?void 0:s.y)||0;this._currentDrag.element.style.left=`${h-d}px`,this._currentDrag.element.style.top=`${u-g}px`;const f=(this.options.dragInOverlapX||0)+1,p=(this.options.dragInOverlapY||0)+1;n>f&&c>p?this._currentDrag.element.style.animation=`${J} ${P} ${R}`:this._currentDrag.element.style.animation=`${M} ${P} ${R}`}if(!(n===1&&c===1)&&A(this._instance)){let h=n,u=c;if(B(e)){const d=this.options.fingerSize||0;h=Math.max(2,n+d),u=Math.max(2,c-d)}this._instance.updateDrag(h,u)}}dragEnd(){this._iframe.style.pointerEvents="all";const e=this._iframe.parentNode;A(this._instance)&&this._instance.dragInObjectEnd(),this._currentDrag.element&&document.body.removeChild(this._currentDrag.element),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const t=e.querySelector("."+w);t&&t.classList.add(N.DISPLAY_NONE)}touchStart(e,t,s="rml_id"){var r,o;t.preventDefault();const a=(c,h)=>{this.dragStart(e,h,s)},n={};typeof((r=this.options)==null?void 0:r.touchDragDelay)=="number"&&(n.delay=this.options.touchDragDelay),(o=this.options)!=null&&o.touchDragEpsilon&&(n.epsilon=this.options.touchDragEpsilon),this._currentTouch=new fe(void 0,{onTouchDragStart:a},n),this._currentTouch.onTouchStart(t)}touchMove(e){this._currentTouch&&this._currentTouch.onTouchMove(e),this._currentDrag.event&&this.dragUpdate(e)}touchEnd(){this._currentTouch&&this._currentTouch.onTouchEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}}const ye=Object.freeze(Object.defineProperty({__proto__:null,DragIn:pe},Symbol.toStringTag,{value:"Module"}));return de});
1
+ (function(_,v){typeof exports=="object"&&typeof module<"u"?module.exports=v():typeof define=="function"&&define.amd?define(v):(_=typeof globalThis<"u"?globalThis:_||self,_["roomle-embedding-lib"]=_["roomle-embedding-lib"]||{},_["roomle-embedding-lib"].umd=_["roomle-embedding-lib"].umd||{},_["roomle-embedding-lib"].umd.min=_["roomle-embedding-lib"].umd.min||{},_["roomle-embedding-lib"].umd.min.js=v())})(this,function(){"use strict";var _=Object.defineProperty,v=(i,t,e)=>t in i?_(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,h=(i,t,e)=>v(i,typeof t!="symbol"?t+"":t,e);class ${constructor(t,e,s,r){h(this,"_side"),h(this,"_incomingMessageBus",null),h(this,"_outgoingMessageBus",null),h(this,"_execMessage",null),this._side=t,this._incomingMessageBus=e,this._outgoingMessageBus=s,this._execMessage=r,this._incomingMessageBus&&this._incomingMessageBus.addEventListener("message",this._handleMessage.bind(this))}setOutgoingMessageBus(t){this._outgoingMessageBus=t}setMessageExecution(t){this._execMessage=t}sendMessage(t,e=[]){return new Promise((s,r)=>{if(this._incomingMessageBus===this._outgoingMessageBus)return s(void 0);const n=new MessageChannel;n.port1.onmessage=a=>{if(!a||!a.data)return n.port1.close(),n.port2.close(),r(new Error(this._side+" received message but response can not be interpreted"));let l;try{l=JSON.parse(a.data)}catch(c){return n.port1.close(),n.port2.close(),this._prepareError(c),r(c)}l.error?r(l.error):l.result!==void 0?s(l.result):s(void 0),n.port1.close(),n.port2.close()};let o="";try{o=JSON.stringify({message:t,args:e})}catch{return r(new Error(this._side+": can not create command because it is not JSON.stringify able"))}if(!this._outgoingMessageBus)return r(new Error(this._side+": outgoing bus not set yet"));this._outgoingMessageBus.postMessage(o,"*",[n.port2])})}_handleMessage(t){const e=t.ports&&Array.isArray(t.ports)&&t.ports.length>0?t.ports[0]:null;if(t.data&&e)try{const s=JSON.parse(t.data);if(!this._execMessage)return e.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(s.args)||(s.args=[s.args]);const r=this._execMessage(s,t);if(r===void 0)return;r.then((n={})=>{let o,a;typeof n=="object"&&n!==null&&(o=n.error,a=n.result),o?e.postMessage(JSON.stringify({error:o})):a!==void 0?e.postMessage(JSON.stringify({result:a})):e.postMessage(JSON.stringify({result:n}))},n=>{e.postMessage(JSON.stringify({error:this._prepareError(n)}))})}catch(s){e.postMessage(JSON.stringify({error:this._prepareError(s)}))}}_prepareError(t){if(typeof t=="string"){const e=this._side+": "+t;return console.error(e),e}return t.message=this._side+": "+t.message,console.error(t),t.message}}const M=".",C={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},w={GET_METHODS:"getMethods",RETURN_METHODS:"returnMethods",REGISTER_CUSTOM_VIEW:"registerCustomView",REGISTER_CUSTOM_VIEW_DONE:"registerCustomViewDone"},pt=async(i,t)=>{if(typeof i!="string")throw new Error('Configurator ID is not a string type: "'+typeof i+'"');const e=t.customApiUrl?t.customApiUrl:"https://api.roomle.com/v2",s=t.overrideTenant||9,r=e+"/configurators/"+i,n="roomle_portal_v2",o="03-"+window.btoa(new Date().toISOString()+";anonymous;"+n),a=()=>{const m={apiKey:n,currentTenant:s,locale:"en",language:"en",device:1,token:o,platform:"web"};return new Headers(m)},l=new Request(r,{method:"GET",headers:a(),mode:"cors",cache:"default"}),c=await fetch(l),{configurator:u}=await c.json();return u},ft=()=>{try{return window.self!==window.top}catch{return!0}},yt=["127.0.0.1","localhost","0.0.0.0"],vt=()=>{const i=ft();let t=window.location.href;if(i){if(!document.referrer)return null;t=document.referrer}const{hostname:e}=new URL(t);return e},Dt=i=>!!(yt.includes(i)||i.endsWith("roomle.com")||i.endsWith("gitlab.io")||i.endsWith("gitlab.com")),k=["language","browserLanguage","userLanguage","systemLanguage"],bt=(i=null)=>{const t=window.navigator;if(i)return i.substr(0,2);if(Array.isArray(t.languages)&&t.languages.length>0)return t.languages[0].substr(0,2);for(let e=0,s=k.length;e<s;e++){const r=t[k[e]];if(r)return r.substr(0,2)}return"en"},wt=(i,t)=>{const e=JSON.parse(JSON.stringify(i));return L(e,t)},L=(i,t)=>{for(const e in t)try{t[e].constructor===Object?i[e]=L(i[e],t[e]):i[e]=t[e]}catch{i[e]=t[e]}return i};var Et={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const Tt={mobileLandscape:!0,floorMaterialRootTag:"materials_root",buttons:{renderimage:!0,requestproduct:!0,requestplan:!0,load_product:!0,partlist_print:!0},helpcenter:{roomdesigner:!0,configurator:!1,disable:!1},firstPersonView:!0,saveToIdb:!0,featureFlags:{mocAr:!0,wallAutoHeight:!1},rotationSnapDegrees:10},It="(idle)",St=i=>(A(i),i!=null&&i.customApiUrl&&(i.customApiUrl=decodeURIComponent(i.customApiUrl)),i.shareUrl&&(i.deeplink=i.shareUrl.replace(Mt,Ct)),i),A=i=>{if(!i)return;const t=Object.keys(i);for(const e of t){const s=i[e];if(!Array.isArray(s)&&typeof s=="object"&&s!==null&&A(s),Array.isArray(s))for(const r of s)A(r);(s==="true"||s==="false")&&(i[e]=s==="true")}},Ot=(i,t)=>{t.configuratorId=i.id;const e=i.settings||{};return!t.overrideTenant&&i.tenant&&(t.overrideTenant=i.tenant),wt(e,t)},xt=()=>{const i={...Tt};i.locale||(i.locale=bt()),i.id===It&&delete i.id;const t=vt();return t&&Dt(t)&&(i.configuratorId="demoConfigurator"),i.customApiUrl=Et.VITE_RAPI_URL,i.emails=!1,i},Mt="<CONF_ID>",Ct="#CONFIGURATIONID#",j=()=>/(android)/i.test(navigator.userAgent);class z{constructor(){h(this,"_messageHandler",null),h(this,"isSetupDone",!1),h(this,"viewName","main"),h(this,"plugins",{}),h(this,"pluginsLoaded",[]),h(this,"ui",{callbacks:null}),h(this,"extended",{callbacks:null}),h(this,"configurator",{callbacks:null}),h(this,"analytics",{callbacks:{}}),h(this,"global",{callbacks:{}})}setMessageHandler(t){this._messageHandler=t}handleSetup(t){const{methods:e,callbacks:s}=t;e.forEach(r=>{const n=r.split(M),o=n[0],a=n[1];this[o]||(this[o]={}),this[o][a]=function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(r,[...arguments])}.bind(this)}),s.forEach(r=>{const n=r.split(M),o=n[0],a=n[1],l=n[2];this[o]||(this[o]={}),this[o][a]||(this[o][a]={}),this[o][a][l]=()=>{}}),this.isSetupDone=!0}executeMessage({message:t,args:e}){const s=t.split(M),r=s[0],n=s[1],o=s.length===3?s[2]:null;if(o&&this[r][n][o]){const a=this[r][n][o](...e);return a instanceof Promise?a.then(l=>({result:l})):a!==void 0?Promise.resolve({result:a}):Promise.resolve({result:null})}return Promise.reject('Message "'+t+'" is unkown')}setupPlugins(t,e,s="website"){for(const r of t)typeof r=="string"&&r==="dragIn"?this.pluginsLoaded.push(new Promise((n,o)=>{try{Promise.resolve().then(()=>Pt).then(({DragIn:a})=>{const l=new a(this.ui,e,s,this.viewName);l.init().then(()=>{this.plugins.dragIn=l,n()},o)})}catch(a){o(a)}})):r.name&&r.loader&&this.pluginsLoaded.push(new Promise((n,o)=>{try{r.loader().then(a=>{const l=new a(this.ui,e,s,this.viewName);l.init().then(()=>{this.plugins[r.name]=l,n()},o)})}catch(a){o(a)}}))}}const V=()=>{let i,t;return{promise:new Promise((e,s)=>{i=e,t=s}),resolve:i,reject:t}},q=(i,t,e)=>{let s=null;Object.defineProperty(i,t,{get(){return s||e},set(r){r!=null&&r.mute?s=r.value:(console.warn("You override Roomle defined behaviour. To disalbe this warning pass in an object with the following properties"),console.warn("{ mute: true, value: () => void }"),s=r)}})},J=()=>window.innerHeight*.01+"px",K=i=>{i&&setTimeout(()=>i.style.setProperty(N,J()),0)},Q="rml-styles",Lt=450,N="--rml-full-height",g={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},R=new Map;class At extends z{constructor(t,e,s,r,n){if(super(),h(this,"_waitForIframe"),h(this,"_container"),h(this,"_configuratorSettings"),h(this,"_initData",{}),h(this,"_iframe"),!t||typeof t.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(R.has(e))throw new Error("There is already an instance on this DOM element");if(!document.getElementById(Q)){const l=s.zIndex||9999999,c=document.createElement("style");c.type="text/css",c.id=Q;const u="transition:all ease-in-out "+Lt+"ms;",m=["-webkit-","-o-"].reduce((y,p)=>y+=p+u,"")+u,d=J();c.innerHTML=`
2
+ .${g.CONTAINER}{${N}:${d};}
3
+ .${g.POSITION}{position:fixed;top:0;left:0;z-index:${l};opacity:0}
4
+ .${g.TRANSITION}{${m}}
5
+ .${g.FILL}{width:100%;height:100%;opacity:1}
6
+ .${g.ANDROID_HEIGHT}{height:calc(var(${N},1vh)*100)}
7
+ .${g.OVERFLOW_HIDDEN}{overflow:hidden}
8
+ `,document.head.appendChild(c)}this._executeMessage=this._executeMessage.bind(this);const o=new $("website",window,null,this._executeMessage);this.setMessageHandler(o),this._onResize=this._onResize.bind(this),j()&&window.addEventListener("resize",this._onResize),this._container=e,this._initData=s,this._configuratorSettings=t;const a=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=n,this._container.appendChild(a),this._iframe=a,this.setupPlugins(r,this._iframe),R.set(e,!0)}static createPlanner(t,e,s,r=[]){return this._create(t,e,s,r)}static async connect(t,e=[]){const s=new z;s.viewName=t;const{resolve:r,promise:n}=V(),{resolve:o,promise:a}=V(),l=({message:m,args:d})=>{if(m===w.REGISTER_CUSTOM_VIEW_DONE){r();return}if(m===w.RETURN_METHODS){s.handleSetup(d[0]),o();return}if(s.isSetupDone)return s.executeMessage({message:m,args:d})},c=new $("custom-view-"+t,window,window.parent,l);s.setMessageHandler(c);const u=[t];return c.sendMessage(w.REGISTER_CUSTOM_VIEW,u),await n,c.sendMessage(w.GET_METHODS,u),await a,s.setupPlugins(e,document.body,"custom-view"),await Promise.allSettled(s.pluginsLoaded),s}static createConfigurator(t,e,s,r=[]){return this._create(t,e,s,r)}static create(t,e,s,r){return this._create(t,e,s,r)}static createViewer(t,e,s,r=[]){return this._create(t,e,s,r)}static async _create(t,e,s,r){return new Promise(async(n,o)=>{try{const a=L(xt(),St(s));a.featureFlags||(a.featureFlags={}),typeof a.featureFlags.realPartList!="boolean"&&(a.featureFlags.realPartList=!0),typeof a.featureFlags.globalCallbacks!="boolean"&&(a.featureFlags.globalCallbacks=!0),typeof a.featureFlags.mocAr!="boolean"&&(a.featureFlags.mocAr=!1);const l=await pt(t,a);s=Ot(l,a);const c=new this(l,e,s,r,n);return await Promise.allSettled(c.pluginsLoaded),c}catch(a){return o(a)}})}teardown(){this._container&&R.delete(this._container);const t=this._container.querySelector("iframe");t&&this._container.removeChild(t),window.removeEventListener("resize",this._onResize)}_createIframe(){var t;const e=document.createElement("iframe");let s=((t=this._configuratorSettings)==null?void 0:t.url)||"https://www.roomle.com/t/cp/";return this._initData.useLocalRoomle&&(s=location.href.replace("embedding.html","")),location.href.includes("roomle.gitlab.io")&&(s=location.href.replace("embedding.html","index.html")),this._initData.overrideServerUrl&&(s=this._initData.overrideServerUrl),e.src=s,e.classList.add(g.CONTAINER),e.classList.add(g.FILL),e}_onResize(){K(this._iframe)}_onUseFullPage(){this._iframe.classList.add(g.POSITION),document.documentElement.classList.add(g.OVERFLOW_HIDDEN),window.document.body.classList.add(g.OVERFLOW_HIDDEN),j()&&(K(this._iframe),this._iframe.classList.add(g.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(g.POSITION),this._iframe.classList.remove(g.ANDROID_HEIGHT),document.documentElement.classList.remove(g.OVERFLOW_HIDDEN),window.document.body.classList.remove(g.OVERFLOW_HIDDEN)}_executeMessage({message:t,args:e},s){var r;if(s.source&&s.source===((r=this._iframe)==null?void 0:r.contentWindow))return t===C.REQUEST_BOOT?this._messageHandler?(this._messageHandler.setOutgoingMessageBus(s.source),Promise.resolve({result:this._initData})):(console.error("MessageHandler not set"),Promise.resolve({error:"MessageHandler not set"})):t===C.SETUP?(this.handleSetup(e[0]),q(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),q(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>{if(!this._messageHandler){console.error("MessageHandler not set");return}this._messageHandler.sendMessage(C.WEBSITE_READY)},0),Promise.resolve({result:null})):this.executeMessage({message:t,args:e})}}class Nt{constructor(t,e,s,r){h(this,"_mainDomElement"),h(this,"_instance"),h(this,"_mode","website"),h(this,"_viewName","main"),this._instance=t,this._mainDomElement=e,this._mode=s,this._viewName=r}async init(){return Promise.resolve()}}const E="rml-drag-in-styles",T="rml-drag-in-drag-element",I="rml-drag-in-overlay",S="rml-drag-in-drag-ghost",Z="rml-drag-in-fade-in",tt="rml-drag-in-fade-out",P={DISPLAY_NONE:"rml-display-none"},et=.5,st="250ms",it="forwards",rt=`@keyframes ${Z} {from{opacity: 0;}to {opacity: ${et};}}`,nt=`@keyframes ${tt} {from{opacity: ${et};}to {opacity: 0;}}`,ot=`${Z} ${st} ${it}`,at=`${tt} ${st} ${it}`,O="https://res.cloudinary.com/roomle/image/upload/v1729679975/fallback_afpyqr.jpg",F=112,U=112;class Rt extends Nt{constructor(t,e,s,r){super(t,e,s,r),h(this,"options",{}),h(this,"_customDragSignal",new AbortController),this._mainDomElement=e,this._injectStyles(),this._initializeDragGhost()}_injectStyles(){if(!document.getElementById(E)){const t=document.createElement("style");t.type="text/css",t.id=E,t.innerHTML=`
9
+ .${P.DISPLAY_NONE}{display:none}
10
+ .${I}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
11
+ .${S}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
12
+ ${rt}
13
+ ${nt}
14
+ `,document.head.appendChild(t)}}_initializeDragGhost(){const t=this._mainDomElement.parentNode;let e=t.querySelector("."+S);e||(e=document.createElement("div"),e.classList.add(S),e.innerText=" ",t.appendChild(e))}async init(){if(await super.init(),this._mode==="website"){const{DragInFromWebsiteStrategy:t}=await Promise.resolve().then(()=>Wt);this._strategy=new t(this._instance,this._mainDomElement,this.options)}else if(this._mode==="custom-view"){const{DragInFromCustomViewStrategy:t}=await Promise.resolve().then(()=>Jt);this._strategy=new t(this._instance,this.options,this._viewName)}else throw new Error("Unsupported mode")}get isDragging(){return this._strategy.isDragging}dragStart(t,e,s="rml_id"){this._strategy.dragStart(t,e,s)}dragUpdate(t){this._strategy.dragUpdate(t)}dragEnd(){this._strategy.dragEnd()}touchStart(t,e,s="rml_id"){this._strategy.touchStart(t,e,s)}touchMove(t){this._strategy.touchMove(t)}touchEnd(){this._strategy.touchEnd()}dispose(){this._strategy.dispose()}beforeUpdateGhost(t){this._strategy.beforeUpdateGhost(t)}registerCustomDrag({customDragStart:t,customDragEnd:e,customDragUpdate:s,beforeUpdateGhost:r}){r&&this._strategy.beforeUpdateGhost(r);const n=this._customDragSignal.signal,o=c=>{c.target.getAttribute("data-rml-draggable")==="true"&&t(c)},a=c=>{this._strategy.releaseInput(c),this._strategy.isDragging&&e(c)},l=c=>{s(c)};document.querySelectorAll('[data-rml-draggable="true"]').forEach(c=>{c.draggable=!1}),document.addEventListener("mousedown",o,{signal:n}),document.addEventListener("mouseup",a,{signal:n}),document.addEventListener("mousemove",l,{signal:n}),document.addEventListener("mouseleave",a,{signal:n}),document.addEventListener("touchstart",o,{signal:n}),document.addEventListener("touchend",a,{signal:n}),document.addEventListener("touchmove",l,{signal:n})}unregisterCustomDrag(){this._customDragSignal.abort(),this._customDragSignal=new AbortController}releaseInput(t){this._strategy.releaseInput(t)}}const Pt=Object.freeze(Object.defineProperty({__proto__:null,DragIn:Rt},Symbol.toStringTag,{value:"Module"}));class Ft{constructor(t=16){h(this,"_computedStyleCache",new Map),h(this,"_maxLifetime",16),h(this,"_cacheCleanInterval",null),this._maxLifetime=t}get(t){const e=this._computedStyleCache.get(t),s=Date.now();if(e&&s-e.updated<this._maxLifetime)return e.style;const r=getComputedStyle(t);return this._computedStyleCache.set(t,{style:r,updated:s}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),r}_cleanUpCache(){const t=Date.now();for(const[e,{updated:s}]of this._computedStyleCache.entries())t-s>=this._maxLifetime&&this._computedStyleCache.delete(e);this._computedStyleCache.size===0&&this._cacheCleanInterval&&(clearInterval(this._cacheCleanInterval),this._cacheCleanInterval=null)}}const f=i=>window.TouchEvent&&i instanceof window.TouchEvent;let B;const x=i=>(B||(B=new Ft),B.get(i)),lt=(i,t,e)=>{const s=parseFloat(i),r=window.devicePixelRatio||1;if(t==="px")return s;if(t==="%"){const o=e===document.documentElement?window.innerWidth:e.offsetWidth;return s/100*o}if(t==="rem"){const o=parseFloat(x(document.documentElement).fontSize);return s*o}if(t==="em"){const o=parseFloat(x(e).fontSize);return s*o}if(t==="vh"||t==="vw"||t==="vmin"||t==="vmax"){const o={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return s/100*o[t]}const n={cm:37.7952755906,mm:3.77952755906,in:96};return t in n?s*n[t]*r:(console.warn("Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"),0)},ht=(i,t,e={x:0,y:0})=>{const s=i.getBoundingClientRect(),r=x(i).transform;let n=0,o=0;if(r!=="none"){const m=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,d=r.match(m);d&&(n=lt(d[1],d[2],i),o=lt(d[3],d[4],i))}const{clientX:a,clientY:l}=D(t,e),c=a-s.left-n+i.scrollLeft,u=l-s.top-o+i.scrollTop;return{x:c,y:u}},D=(i,t=null)=>{const{clientX:e,clientY:s}=f(i)?Ut(i):i,r=e>0?e:t?t.x:e,n=s>0?s:t?t.y:s;return{clientX:r,clientY:n}},Ut=i=>{if(i.touches.length){let{clientX:e,clientY:s}=i.touches[0];if(i.touches.length>1){const r=i.touches[1],n=r.clientX,o=r.clientY;e=(e+n)/2,s=(s+o)/2}return{clientX:e,clientY:s}}const t=i.changedTouches[0];return{clientX:t.clientX,clientY:t.clientY}},H=500,G=10,ct=100,ut=15,Y=(i,t=0)=>f(i)?{clientX:i.touches[t].clientX,clientY:i.touches[t].clientY}:{clientX:i.clientX,clientY:i.clientY},dt=i=>i&&f(i)?i.touches.length>0:!0;class gt{constructor(t,{onTouchDragStart:e},s={}){h(this,"_touchDragTimeOut"),h(this,"_onTouchDragStart"),h(this,"_payload",null),h(this,"_delay",H),h(this,"_firstTouch",null),h(this,"_lastTouch",null),h(this,"_epsilon",G),this._payload=t,this._onTouchDragStart=e,this._delay=typeof s.delay=="number"?s.delay:H,this._epsilon=typeof s.epsilon=="number"?s.epsilon:G}onStart(t){dt(t)&&(this._touchDragTimeOut||(this._firstTouch=Y(t,f(t)?t.touches.length-1:0),this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=Y(t)),this._checkXDistance(t)()},this._delay)))}onEnd(){this._resetTouches()}onMove(t){dt(t)&&(this._lastTouch=Y(t))}_clearTimeout(){this._touchDragTimeOut&&(clearTimeout(this._touchDragTimeOut),this._touchDragTimeOut=null)}_resetTouches(){this._clearTimeout(),this._lastTouch=null,this._firstTouch=null,this._payload=null}_checkXDistance(t){return()=>{if(!this._firstTouch||!this._lastTouch)return;let e=!1;e=Math.abs(this._firstTouch.clientX-this._lastTouch.clientX)<this._epsilon,e&&(this._onTouchDragStart(this._payload,t),this._resetTouches())}}}const mt=(i,t,e=0,s=0)=>{const r=t.x+t.width+e,n=t.x-e,o=t.y+t.height+s,a=t.y-s,{x:l,y:c}=i;return l>=n&&l<=r&&c>=a&&c<=o},Bt=()=>{if(!document.getElementById(E)){const i=document.createElement("style");i.type="text/css",i.id=E,i.innerHTML=`
15
+ ${rt}
16
+ ${nt}
17
+ `,document.head.appendChild(i)}},Ht=({x:i,y:t},e,s)=>{var r,n,o,a;let l=document.getElementById(T);if(!l){if(l=document.createElement("div"),(r=e.ghost)!=null&&r.element)l.appendChild(e.ghost.element);else{const c=document.createElement("img");c.src=((n=e.ghost)==null?void 0:n.url)||O,c.width=((o=e.ghost)==null?void 0:o.width)||F,c.height=((a=e.ghost)==null?void 0:a.height)||U,l.appendChild(c)}l.id=T,l.style.position="fixed",l.style.top="0",l.style.left="0",l.style.willChange="transform",l.style.transform="translate3d(0, 0, 0)",l.style.zIndex="9999",l.style.opacity="0.5",e.ghost&&e.ghost.visibleIn&&!mt({x:i,y:t},e.ghost.visibleIn,s.dragInOverlapX,s.dragInOverlapY)&&(l.style.display="none"),l.style.pointerEvents="none",document.body.appendChild(l)}},Gt=({x:i,y:t},e,s)=>{var r,n;const o=document.getElementById(T);if(!o)return;let a=(r=e.ghost)==null?void 0:r.width,l=(n=e.ghost)==null?void 0:n.height;typeof a>"u"&&(a=o.getBoundingClientRect().width||F),typeof l>"u"&&(l=o.getBoundingClientRect().height||U);const c=i-a/2,u=t-l/2;o.style.transform=`translate3d(${c}px, ${u}px, 0)`,e.ghost&&(!e.ghost.visibleIn||mt({x:i,y:t},e.ghost.visibleIn,s.dragInOverlapX,s.dragInOverlapY)?o.style.animation!=ot&&(o.style.animation=ot):o.style.animation!=at&&(o.style.animation=at))};class Yt{constructor(t=null){h(this,"_dragGhostAnimationFrameId",null),h(this,"_dragGhostRemoveAnimationFrameId",null),h(this,"_dragGhostElement",null),this._dragGhostElement=t}updateDragGhost(t,e,s={},r={}){var n;this._dragGhostRemoveAnimationFrameId&&(cancelAnimationFrame(this._dragGhostRemoveAnimationFrameId),this._dragGhostRemoveAnimationFrameId=null),!((n=s.ghost)!=null&&n.external)&&s.ghost&&(this._dragGhostAnimationFrameId||(this._dragGhostAnimationFrameId=requestAnimationFrame(()=>{Bt();const o={x:t,y:e};!s.ghost&&this._dragGhostElement&&(s.ghost={}),s.ghost&&!s.ghost.element&&this._dragGhostElement&&(s.ghost.element=this._dragGhostElement),Ht(o,s,r),Gt(o,s,r),this._dragGhostAnimationFrameId=null})))}removeDragGhost(){this._dragGhostAnimationFrameId&&(cancelAnimationFrame(this._dragGhostAnimationFrameId),this._dragGhostAnimationFrameId=null),this._dragGhostRemoveAnimationFrameId||(this._dragGhostRemoveAnimationFrameId=requestAnimationFrame(()=>{const t=document.getElementById(T);t&&document.body.removeChild(t),this._dragGhostRemoveAnimationFrameId=null}))}}class Xt{constructor(t,e,s){h(this,"_options",{}),h(this,"_instance"),h(this,"_mainDomElement"),h(this,"_currentDrag",{}),h(this,"_currentTouch",null),h(this,"_firefoxDragPosition",{x:0,y:0}),h(this,"_onBeforeUpdateDrag",()=>({})),h(this,"isDragging",!1),h(this,"_firefoxFallback",r=>{if(!this._currentDrag.event)return;const n=r||window.event;this._firefoxDragPosition.x=n.pageX||0,this._firefoxDragPosition.y=n.pageY||0}),this._instance=t,this._mainDomElement=e,this._options=s||{},this._firefoxFallback=this._firefoxFallback.bind(this),document.addEventListener("dragover",this._firefoxFallback)}beforeUpdateGhost(t){this._onBeforeUpdateDrag=t}dragStart(t,e,s="rml_id"){const r=this._mainDomElement.parentNode;if(x(r).position!=="relative"){console.warn("Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly");return}this._mainDomElement.style.pointerEvents="none";let n=r.querySelector("."+I);n||(n=document.createElement("div"),n.classList.add(I),r.appendChild(n)),n.classList.remove(P.DISPLAY_NONE),e.target.getAttribute("draggable")||console.warn(`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`);const o=r.querySelector("."+S);this._currentDrag.event=e;const a=e.target,l=a.cloneNode(),c=a.getBoundingClientRect();l.style.width=`${c.width}px`,l.style.height=`${c.height}px`,this._currentDrag.ghost=new Yt(l),this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0});const{clientX:u,clientY:m}=D(e,this._firefoxDragPosition);this._currentDrag.offset.x=u-c.left,this._currentDrag.offset.y=m-c.top,e instanceof DragEvent&&e.dataTransfer&&e.dataTransfer.setDragImage&&e.dataTransfer.setDragImage(o,0,0);const{x:d,y}=ht(r,this._currentDrag.event||e,this._firefoxDragPosition),p=Math.max(1,d),b=Math.max(1,y);this.isDragging=!0,this._instance.dragInObject(t,p,b,s)}dragUpdate(t){const e=this._mainDomElement.parentNode,{x:s,y:r}=ht(e,t,this._firefoxDragPosition);if(s===0&&r===0)return;const n=Math.max(1,s),o=Math.max(1,r);if(n===1&&o===1)return;let a=n,l=o;if(f(t)){const p=this._options.fingerSize||0;a=Math.max(2,n+p),l=Math.max(2,o-p)}const{x:c,y:u,options:m}=this._onBeforeUpdateDrag(a,l,{}),d=typeof c=="number"?c:a,y=typeof u=="number"?u:l;if(this._currentDrag.ghost){const{clientX:p,clientY:b}=D(t,this._firefoxDragPosition);console.log("dragin","dragupdate is here: ",location.href),this._currentDrag.ghost.updateDragGhost(p,b,m||{},this._options||{})}this._instance.updateDrag(d,y,{})}dragEnd(){this._mainDomElement.style.pointerEvents="all";const t=this._mainDomElement.parentNode;this.isDragging=!1,this._instance.dragInObjectEnd(),this._currentDrag.ghost&&(this._currentDrag.ghost.removeDragGhost(),this._currentDrag.ghost=null),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const e=t.querySelector("."+I);e&&e.classList.add(P.DISPLAY_NONE)}touchStart(t,e,s="rml_id"){var r,n;e.preventDefault();const o=(l,c)=>{this.dragStart(t,c,s)},a={};typeof((r=this._options)==null?void 0:r.touchDragDelay)=="number"&&(a.delay=this._options.touchDragDelay),(n=this._options)!=null&&n.touchDragEpsilon&&(a.epsilon=this._options.touchDragEpsilon),this._currentTouch=new gt(void 0,{onTouchDragStart:o},a),this._currentTouch.onStart(e)}touchMove(t){this._currentTouch&&this._currentTouch.onMove(t),this._currentDrag.event&&this.dragUpdate(t)}touchEnd(){this._currentTouch&&this._currentTouch.onEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}releaseInput(t){}}const Wt=Object.freeze(Object.defineProperty({__proto__:null,DragInFromWebsiteStrategy:Xt},Symbol.toStringTag,{value:"Module"})),$t=i=>`[data-rml-custom-view="${i}"]`,X=i=>{i.preventDefault(),i.stopPropagation()},kt=(i,t,e,s)=>{const r=e-i,n=s-t;return Math.sqrt(r*r+n*n)};class jt{constructor({onCustomDragStart:t},e={}){h(this,"_startX",0),h(this,"_startY",0),h(this,"_lastX",0),h(this,"_lastY",0),h(this,"_delay"),h(this,"_epsilon"),h(this,"_isStarted",!1),h(this,"_isEnded",!1),h(this,"_isWaiting",!1),h(this,"_onCustomDragStart"),this._delay=typeof e.delay=="number"?e.delay:ct,this._epsilon=typeof e.epsilon=="number"?e.epsilon:ut,this._onCustomDragStart=t}onMove(t){this._lastX=t.clientX,this._lastY=t.clientY,this._isWaiting&&kt(this._startX,this._startY,this._lastX,this._lastY)>this._epsilon&&(this._onCustomDragStart(t),this._isWaiting=!1)}onStart(t){this._startX=t.clientX,this._startY=t.clientY,this.onMove(t),this._isWaiting=!0}onEnd(){this._reset()}_reset(){this._startX=0,this._startY=0,this._lastX=0,this._lastY=0,this._isWaiting=!1}}const W="data-rml-old-draggable",zt=void 0,_t=(i,t)=>{const e=f(i),s={delay:e?H:ct,epsilon:e?G:ut};if(!t)return s;if(!e&&!(i instanceof MouseEvent))return console.warn("Unsupported event! It is not TouchEvent and also not MouseEvent"),s;const{delayKey:r,epsilonKey:n}=e?{delayKey:"touchDragDelay",epsilonKey:"touchDragEpsilon"}:{delayKey:"customDragDelay",epsilonKey:"customDragEpsilon"};return typeof t[r]=="number"&&(s.delay=t.touchDragDelay),typeof t[n]=="number"&&(s.epsilon=t.touchDragEpsilon),s},Vt=i=>{let t="",e=F,s=U;if(!i)return{url:O,width:e,height:s};const r=i;if(r instanceof HTMLElement){const n=r.getBoundingClientRect(),o=r.getAttribute("data-rml-ghost-url"),a=r.getAttribute("data-rml-ghost-width"),l=r.getAttribute("data-rml-ghost-height");o?t=o:!o&&r instanceof HTMLImageElement&&r.src&&(t=r.src),t?(e=n.width,s=n.height):t=O,e=a?parseInt(a,10):e,s=l?parseInt(l,10):s}return{url:t||O,width:e,height:s}};class qt{constructor(t,e,s){h(this,"_options",{}),h(this,"_instance"),h(this,"_viewName"),h(this,"_currentCustomDrag",null),h(this,"_currentBb",null),h(this,"_startTarget",null),h(this,"_onBeforeUpdateDrag",()=>({})),h(this,"isDragging",!1),this._instance=t,this._options=e||{},this._viewName=s}beforeUpdateGhost(t){this._onBeforeUpdateDrag=t}async _dragStart(t,e,s="rml_id"){this._startTarget&&(this._startTarget.style.pointerEvents="none",this._startTarget.style.userSelect="none",this._startTarget.setAttribute(W,this._startTarget.draggable.toString()),this._startTarget.draggable=!1,this._startTarget.removeEventListener("dragstart",X),this._startTarget.addEventListener("dragstart",X)),this._currentBb=await this._instance.getBoundingClientRect($t(this._viewName));const{clientX:r,clientY:n}=D(e),o=this._currentBb.x+r,a=this._currentBb.y+n;this.isDragging=!0,this._instance.dragInObject(t,o,a,s)}_dragUpdate(t){if(document.body.focus(),this._currentCustomDrag&&this._currentCustomDrag.onMove(t),!this._currentBb||!this.isDragging)return;const{clientX:e,clientY:s}=D(t),{url:r,width:n,height:o}=Vt(this._startTarget),a=this._currentBb.x+e,l=this._currentBb.y+s,c=this._options||{},u={ghost:{visibleIn:{x:this._currentBb.x-(c.dragInOverlapX||0),y:this._currentBb.y+(c.dragInOverlapY||0),width:this._currentBb.width+(c.dragInOverlapX||0),height:this._currentBb.height+(c.dragInOverlapY||0)},url:r,width:n,height:o}},{x:m,y:d,options:y}=this._onBeforeUpdateDrag(a,l,u),p=typeof m=="number"?m:a,b=typeof d=="number"?d:l,Kt=y||u;this._instance.updateDrag(p,b,Kt)}_dragEnd(){this._currentCustomDrag&&this._currentCustomDrag.onEnd(),this._currentCustomDrag=null,this.isDragging=!1,this._currentBb=null,this._resetStartTarget(),this._instance.enableEvents(),this._instance.dragInObjectEnd()}dragStart(t,e,s){this._instance.disableEvents(),this._startTarget=e.target;const r=(n,o)=>{this._dragStart(t,o,s)};this._currentCustomDrag=f(e)?new gt(zt,{onTouchDragStart:r},_t(e,this._options)):new jt({onCustomDragStart:n=>this._dragStart(t,n,s)},_t(e,this._options)),this._currentCustomDrag.onStart(e)}dragEnd(){this._dragEnd()}dragUpdate(t){this._dragUpdate(t)}touchStart(t,e,s="rml_id"){this.dragStart(t,e,s)}touchMove(t){this.dragUpdate(t)}touchEnd(){this.dragEnd()}dispose(){}_resetStartTarget(){this._startTarget&&(this._startTarget.style.pointerEvents="",this._startTarget.style.userSelect="",this._startTarget.draggable=this._startTarget.getAttribute(W)==="true",this._startTarget.removeAttribute(W),this._startTarget.removeEventListener("dragstart",X))}releaseInput(t){this._currentCustomDrag&&this._currentCustomDrag.onEnd(),this._resetStartTarget()}}const Jt=Object.freeze(Object.defineProperty({__proto__:null,DragInFromCustomViewStrategy:qt},Symbol.toStringTag,{value:"Module"}));return At});