@roomle/embedding-lib 5.5.0-alpha.2 → 5.5.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 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 a;try{a=JSON.parse(n.data)}catch(l){return o.port1.close(),o.port2.close(),this._prepareError(l),i(l)}a.error?i(a.error):a.result!==void 0?r(a.result):r(void 0),o.port1.close(),o.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,"*",[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 i=this._execMessage(r,e);if(i===void 0)return;i.then((o={})=>{let u,n;typeof o=="object"&&o!==null&&(u=o.error,n=o.result),u?t.postMessage(JSON.stringify({error:u})):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(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,o="roomle_portal_v2",u="03-"+window.btoa(new Date().toISOString()+";anonymous;"+o),n=()=>{const d={apiKey:o,currentTenant:r,locale:"en",language:"en",device:1,token:u,platform:"web"};return new Headers(d)},a=new Request(i,{method:"GET",headers:n(),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"],B=()=>{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},H=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},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=B();return e&&H(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,o){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 n=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:${n};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=o,this._container.appendChild(u),this._iframe=u;for(const n of i)typeof n=="string"&&n==="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)}})):n.name&&n.loader&&this.pluginsLoaded.push(new Promise((a,l)=>{try{n.loader().then(g=>{const d=new g(this._iframe);d.setInstance(this.ui),this.plugins[n.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(o,u)=>{try{const n=y(z(),$(r));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 a=await P(e,n);r=V(a,n);const l=new this(a,t,r,i,o);return await Promise.allSettled(l.pluginsLoaded),l}catch(n){return u(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 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 o=e.split(p),u=o[0],n=o[1],a=o.length===3?o[2]:null;if(a&&this[u][n][a]){const l=this[u][n][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 O{constructor(e,t,s,i){c(this,"_side"),c(this,"_incomingMessageBus"),c(this,"_outgoingMessageBus",null),c(this,"_execMessage",null),this._side=e,this._incomingMessageBus=t,this._outgoingMessageBus=s,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((s,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 l;try{l=JSON.parse(o.data)}catch(u){return n.port1.close(),n.port2.close(),this._prepareError(u),i(u)}l.error?i(l.error):l.result!==void 0?s(l.result):s(void 0),n.port1.close(),n.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,"*",[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 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((n={})=>{let a,o;typeof n=="object"&&n!==null&&(a=n.error,o=n.result),a?t.postMessage(JSON.stringify({error:a})):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(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,n="roomle_portal_v2",a="03-"+window.btoa(new Date().toISOString()+";anonymous;"+n),o=()=>{const h={apiKey:n,currentTenant:s,locale:"en",language:"en",device:1,token:a,platform:"web"};return new Headers(h)},l=new Request(i,{method:"GET",headers:o(),mode:"cors",cache:"default"}),u=await fetch(l),{configurator:d}=await u.json();return d},F=()=>{try{return window.self!==window.top}catch{return!0}},x=["127.0.0.1","localhost","0.0.0.0"],B=()=>{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=>!!(x.includes(r)||r.endsWith("roomle.com")||r.endsWith("gitlab.io")||r.endsWith("gitlab.com")),b=["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=b.length;t<s;t++){const i=e[b[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},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=B();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 n=i.split(p),a=n[0],o=n[1];this[a]||(this[a]={}),this[a][o]=function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(i,[...arguments])}.bind(this)}),s.forEach(i=>{const n=i.split(p),a=n[0],o=n[1],l=n[2];this[a]||(this[a]={}),this[a][o]||(this[a][o]={}),this[a][o][l]=()=>{}}),this.isSetupDone=!0}executeMessage({message:e,args:t}){const s=e.split(p),i=s[0],n=s[1],a=s.length===3?s[2]:null;if(a&&this[i][n][a]){const o=this[i][n][a](...t);return o instanceof Promise?o.then(l=>({result:l})):o!==void 0?Promise.resolve({result:o}):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((n,a)=>{try{import("./drag-in-qIN6j-1p.mjs").then(({DragIn:o})=>{const l=new o(t);l.setInstance(this.ui),l.setMode(s),l.setViewName(this.viewName),this.plugins.dragIn=l,n()})}catch(o){a(o)}})):i.name&&i.loader&&this.pluginsLoaded.push(new Promise((n,a)=>{try{i.loader().then(o=>{const l=new o(t);l.setInstance(this.ui),l.setMode(s),l.setViewName(this.viewName),this.plugins[i.name]=l,n()})}catch(o){a(o)}}))}}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",N=r=>{r&&setTimeout(()=>r.style.setProperty(y,R()),0)},D="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"},I=new Map;class K extends v{constructor(e,t,s,i,n){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(I.has(t))throw new Error("There is already an instance on this DOM element");if(!document.getElementById(D)){const l=s.zIndex||9999999,u=document.createElement("style");u.type="text/css",u.id=D;const d="transition:all ease-in-out "+Q+"ms;",h=["-webkit-","-o-"].reduce((L,P)=>L+=P+d,"")+d,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}{${h}}
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 O("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 o=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=n,this._container.appendChild(o),this._iframe=o,this.setupPlugins(i,this._iframe),I.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:n}=T(),{resolve:a,promise:o}=T(),l=({message:h,args:m})=>{if(h===_.REGISTER_CUSTOM_VIEW_DONE){i();return}if(h===_.RETURN_METHODS){s.handleSetup(m[0]),a();return}if(s.isSetupDone)return s.executeMessage({message:h,args:m})},u=new O("custom-view",window,window.parent,l);s.setMessageHandler(u);const d=[e];return u.sendMessage(_.REGISTER_CUSTOM_VIEW,d),await n,u.sendMessage(_.GET_METHODS,d),await o,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(n,a)=>{try{const o=w(z(),$(s));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 l=await U(e,o);s=j(l,o);const u=new this(l,t,s,i,n);return await Promise.allSettled(u.pluginsLoaded),u}catch(o){return a(o)}})}teardown(){this._container&&I.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(){N(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()&&(N(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,14 @@
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},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};}
3
- .${_.POSITION}{position:fixed;top:0;left:0;z-index:${u};opacity:0}
4
- .${_.TRANSITION}{${h}}
5
- .${_.FILL}{width:100%;height:100%;opacity:1}
6
- .${_.ANDROID_HEIGHT}{height:calc(var(${A},1vh)*100)}
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 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});
1
+ (function(m,_){typeof exports=="object"&&typeof module<"u"?module.exports=_():typeof define=="function"&&define.amd?define(_):(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=_())})(this,function(){"use strict";var Ne=Object.defineProperty;var xe=(m,_,w)=>_ in m?Ne(m,_,{enumerable:!0,configurable:!0,writable:!0,value:w}):m[_]=w;var l=(m,_,w)=>xe(m,typeof _!="symbol"?_+"":_,w);class m{constructor(t,e,s,n){l(this,"_side");l(this,"_incomingMessageBus");l(this,"_outgoingMessageBus",null);l(this,"_execMessage",null);this._side=t,this._incomingMessageBus=e,this._outgoingMessageBus=s,this._execMessage=n,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,n)=>{const i=new MessageChannel;i.port1.onmessage=c=>{if(!c||!c.data)return i.port1.close(),i.port2.close(),n(new Error(this._side+" received message but response can not be interpreted"));let a;try{a=JSON.parse(c.data)}catch(h){return i.port1.close(),i.port2.close(),this._prepareError(h),n(h)}a.error?n(a.error):a.result!==void 0?s(a.result):s(void 0),i.port1.close(),i.port2.close()};let r="";try{r=JSON.stringify({message:t,args:e})}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(r,"*",[i.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 n=this._execMessage(s,t);if(n===void 0)return;n.then((i={})=>{let r,c;typeof i=="object"&&i!==null&&(r=i.error,c=i.result),r?e.postMessage(JSON.stringify({error:r})):c!==void 0?e.postMessage(JSON.stringify({result:c})):e.postMessage(JSON.stringify({result:i}))},i=>{e.postMessage(JSON.stringify({error:this._prepareError(i)}))})}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 _=".",w={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},M={GET_METHODS:"getMethods",RETURN_METHODS:"returnMethods",REGISTER_CUSTOM_VIEW:"registerCustomView",REGISTER_CUSTOM_VIEW_DONE:"registerCustomViewDone"},oe=async(o,t)=>{if(typeof o!="string")throw new Error('Configurator ID is not a string type: "'+typeof o+'"');const e=t.customApiUrl?t.customApiUrl:"https://api.roomle.com/v2",s=t.overrideTenant||9,n=e+"/configurators/"+o,i="roomle_portal_v2",r="03-"+window.btoa(new Date().toISOString()+";anonymous;"+i),c=()=>{const d={apiKey:i,currentTenant:s,locale:"en",language:"en",device:1,token:r,platform:"web"};return new Headers(d)},a=new Request(n,{method:"GET",headers:c(),mode:"cors",cache:"default"}),h=await fetch(a),{configurator:u}=await h.json();return u},ie=()=>{try{return window.self!==window.top}catch{return!0}},re=["127.0.0.1","localhost","0.0.0.0"],ae=()=>{const o=ie();let t=window.location.href;if(o){if(!document.referrer)return null;t=document.referrer}const{hostname:e}=new URL(t);return e},ce=o=>!!(re.includes(o)||o.endsWith("roomle.com")||o.endsWith("gitlab.io")||o.endsWith("gitlab.com")),G=["language","browserLanguage","userLanguage","systemLanguage"],le=(o=null)=>{const t=window.navigator;if(o)return o.substr(0,2);if(Array.isArray(t.languages)&&t.languages.length>0)return t.languages[0].substr(0,2);for(let e=0,s=G.length;e<s;e++){const n=t[G[e]];if(n)return n.substr(0,2)}return"en"},ue=(o,t)=>{const e=JSON.parse(JSON.stringify(o));return L(e,t)},L=(o,t)=>{for(const e in t)try{t[e].constructor===Object?o[e]=L(o[e],t[e]):o[e]=t[e]}catch{o[e]=t[e]}return o};var he={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const de={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},rotationSnapDegrees:10},ge="(idle)",me=o=>(v(o),o!=null&&o.customApiUrl&&(o.customApiUrl=decodeURIComponent(o.customApiUrl)),o.shareUrl&&(o.deeplink=o.shareUrl.replace(pe,ye)),o),v=o=>{if(!o)return;const t=Object.keys(o);for(const e of t){const s=o[e];if(!Array.isArray(s)&&typeof s=="object"&&s!==null&&v(s),Array.isArray(s))for(const n of s)v(n);(s==="true"||s==="false")&&(o[e]=s==="true")}},fe=(o,t)=>{t.configuratorId=o.id;const e=o.settings||{};return!t.overrideTenant&&o.tenant&&(t.overrideTenant=o.tenant),ue(e,t)},_e=()=>{const o={...de};o.locale||(o.locale=le()),o.id===ge&&delete o.id;const t=ae();return t&&ce(t)&&(o.configuratorId="demoConfigurator"),o.customApiUrl=he.VITE_RAPI_URL,o.emails=!1,o},pe="<CONF_ID>",ye="#CONFIGURATIONID#",$=()=>/(android)/i.test(navigator.userAgent);class B{constructor(){l(this,"_messageHandler",null);l(this,"isSetupDone",!1);l(this,"viewName","main");l(this,"plugins",{});l(this,"pluginsLoaded",[]);l(this,"ui",{callbacks:null});l(this,"extended",{callbacks:null});l(this,"configurator",{callbacks:null});l(this,"analytics",{callbacks:{}});l(this,"global",{callbacks:{}})}setMessageHandler(t){this._messageHandler=t}handleSetup(t){const{methods:e,callbacks:s}=t;e.forEach(n=>{const i=n.split(_),r=i[0],c=i[1];this[r]||(this[r]={}),this[r][c]=(function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(n,[...arguments])}).bind(this)}),s.forEach(n=>{const i=n.split(_),r=i[0],c=i[1],a=i[2];this[r]||(this[r]={}),this[r][c]||(this[r][c]={}),this[r][c][a]=()=>{}}),this.isSetupDone=!0}executeMessage({message:t,args:e}){const s=t.split(_),n=s[0],i=s[1],r=s.length===3?s[2]:null;if(r&&this[n][i][r]){const c=this[n][i][r](...e);return c instanceof Promise?c.then(a=>({result:a})):c!==void 0?Promise.resolve({result:c}):Promise.resolve({result:null})}return Promise.reject('Message "'+t+'" is unkown')}setupPlugins(t,e,s="website"){for(const n of t)typeof n=="string"&&n==="dragIn"?this.pluginsLoaded.push(new Promise((i,r)=>{try{Promise.resolve().then(()=>be).then(({DragIn:c})=>{const a=new c(e);a.setInstance(this.ui),a.setMode(s),a.setViewName(this.viewName),this.plugins.dragIn=a,i()})}catch(c){r(c)}})):n.name&&n.loader&&this.pluginsLoaded.push(new Promise((i,r)=>{try{n.loader().then(c=>{const a=new c(e);a.setInstance(this.ui),a.setMode(s),a.setViewName(this.viewName),this.plugins[n.name]=a,i()})}catch(c){r(c)}}))}}const W=()=>{let o,t;return{promise:new Promise((s,n)=>{o=s,t=n}),resolve:o,reject:t}},X=(o,t,e)=>{let s=null;Object.defineProperty(o,t,{get(){return s||e},set(n){n!=null&&n.mute?s=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 }"),s=n)}})},z=()=>window.innerHeight*.01+"px",V=o=>{o&&setTimeout(()=>o.style.setProperty(C,z()),0)},J="rml-styles",we=450,C="--rml-full-height",f={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},P=new Map;class Ee extends B{constructor(e,s,n,i,r){super();l(this,"_waitForIframe");l(this,"_container");l(this,"_configuratorSettings");l(this,"_initData",{});l(this,"_iframe");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(P.has(s))throw new Error("There is already an instance on this DOM element");if(!!!document.getElementById(J)){const u=n.zIndex||9999999,d=document.createElement("style");d.type="text/css",d.id=J;const p="transition:all ease-in-out "+we+"ms;",g=["-webkit-","-o-"].reduce((T,I)=>T+=I+p,"")+p,E=z();d.innerHTML=`
2
+ .${f.CONTAINER}{${C}:${E};}
3
+ .${f.POSITION}{position:fixed;top:0;left:0;z-index:${u};opacity:0}
4
+ .${f.TRANSITION}{${g}}
5
+ .${f.FILL}{width:100%;height:100%;opacity:1}
6
+ .${f.ANDROID_HEIGHT}{height:calc(var(${C},1vh)*100)}
7
+ .${f.OVERFLOW_HIDDEN}{overflow:hidden}
8
+ `,document.head.appendChild(d)}this._executeMessage=this._executeMessage.bind(this);const a=new m("website",window,null,this._executeMessage);this.setMessageHandler(a),this._onResize=this._onResize.bind(this),$()&&window.addEventListener("resize",this._onResize),this._container=s,this._initData=n,this._configuratorSettings=e;const h=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=r,this._container.appendChild(h),this._iframe=h,this.setupPlugins(i,this._iframe),P.set(s,!0)}static createPlanner(e,s,n,i=[]){return this._create(e,s,n,i)}static async connect(e,s=[]){const n=new B;n.viewName=e;const{resolve:i,promise:r}=W(),{resolve:c,promise:a}=W(),h=({message:p,args:g})=>{if(p===M.REGISTER_CUSTOM_VIEW_DONE){i();return}if(p===M.RETURN_METHODS){n.handleSetup(g[0]),c();return}if(n.isSetupDone)return n.executeMessage({message:p,args:g})},u=new m("custom-view",window,window.parent,h);n.setMessageHandler(u);const d=[e];return u.sendMessage(M.REGISTER_CUSTOM_VIEW,d),await r,u.sendMessage(M.GET_METHODS,d),await a,n.setupPlugins(s,document.body,"custom-view"),await Promise.allSettled(n.pluginsLoaded),n}static createConfigurator(e,s,n,i=[]){return this._create(e,s,n,i)}static create(e,s,n,i){return this._create(e,s,n,i)}static createViewer(e,s,n,i=[]){return this._create(e,s,n,i)}static async _create(e,s,n,i){return new Promise(async(r,c)=>{try{const a=L(_e(),me(n));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 h=await oe(e,a);n=fe(h,a);const u=new this(h,s,n,i,r);return await Promise.allSettled(u.pluginsLoaded),u}catch(a){return c(a)}})}teardown(){this._container&&P.delete(this._container);const e=this._container.querySelector("iframe");e&&this._container.removeChild(e),window.removeEventListener("resize",this._onResize)}_createIframe(){var n;const e=document.createElement("iframe");let s=((n=this._configuratorSettings)==null?void 0:n.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(f.CONTAINER),e.classList.add(f.FILL),e}_onResize(){V(this._iframe)}_onUseFullPage(){this._iframe.classList.add(f.POSITION),document.documentElement.classList.add(f.OVERFLOW_HIDDEN),window.document.body.classList.add(f.OVERFLOW_HIDDEN),$()&&(V(this._iframe),this._iframe.classList.add(f.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(f.POSITION),this._iframe.classList.remove(f.ANDROID_HEIGHT),document.documentElement.classList.remove(f.OVERFLOW_HIDDEN),window.document.body.classList.remove(f.OVERFLOW_HIDDEN)}_executeMessage({message:e,args:s},n){var i;if(n.source&&n.source===((i=this._iframe)==null?void 0:i.contentWindow))return e===w.REQUEST_BOOT?this._messageHandler?(this._messageHandler.setOutgoingMessageBus(n.source),Promise.resolve({result:this._initData})):(console.error("MessageHandler not set"),Promise.resolve({error:"MessageHandler not set"})):e===w.SETUP?(this.handleSetup(s[0]),X(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),X(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>{if(!this._messageHandler){console.error("MessageHandler not set");return}this._messageHandler.sendMessage(w.WEBSITE_READY)},0),Promise.resolve({result:null})):this.executeMessage({message:e,args:s})}}class Te{constructor(t=16){l(this,"_computedStyleCache",new Map);l(this,"_maxLifetime",16);l(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 n=getComputedStyle(t);return this._computedStyleCache.set(t,{style:n,updated:s}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),n}_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 q=o=>window.TouchEvent&&o instanceof window.TouchEvent;let H;const A=o=>(H||(H=new Te),H.get(o)),K=(o,t,e)=>{const s=parseFloat(o),n=window.devicePixelRatio||1;if(t==="px")return s;if(t==="%"){const r=e===document.documentElement?window.innerWidth:e.offsetWidth;return s/100*r}if(t==="rem"){const r=parseFloat(A(document.documentElement).fontSize);return s*r}if(t==="em"){const r=parseFloat(A(e).fontSize);return s*r}if(t==="vh"||t==="vw"||t==="vmin"||t==="vmax"){const r={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return s/100*r[t]}const i={cm:37.7952755906,mm:3.77952755906,in:96};return t in i?s*i[t]*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)},j=(o,t,e={x:0,y:0})=>{const s=o.getBoundingClientRect(),i=A(o).transform;let r=0,c=0;if(i!=="none"){const p=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,g=i.match(p);g&&(r=K(g[1],g[2],o),c=K(g[3],g[4],o))}const{clientX:a,clientY:h}=b(t,e),u=a-s.left-r+o.scrollLeft,d=h-s.top-c+o.scrollTop;return{x:u,y:d}},b=(o,t)=>{const{clientX:e,clientY:s}=q(o)?Se(o):o,n=e>0?e:t.x,i=s>0?s:t.y;return{clientX:n,clientY:i}},Se=o=>{if(o.touches.length){let{clientX:e,clientY:s}=o.touches[0];if(o.touches.length>1){const n=o.touches[1],i=n.clientX,r=n.clientY;e=(e+i)/2,s=(s+r)/2}return{clientX:e,clientY:s}}const t=o.changedTouches[0];return{clientX:t.clientX,clientY:t.clientY}},De=(o,t)=>{const e=t.x+t.width,s=t.x,n=t.y+t.height,i=t.y,{x:r,y:c}=o;return r>=s&&r<=e&&c>=i&&c<=n},Q=500,Z=10;class Ie{constructor(t,{onTouchDragStart:e},s={}){l(this,"_touchDragTimeOut");l(this,"_onTouchDragStart");l(this,"_payload",null);l(this,"_delay",Q);l(this,"_firstTouch",null);l(this,"_lastTouch",null);l(this,"_epsilon",Z);this._payload=t,this._onTouchDragStart=e,this._delay=s.delay||Q,this._epsilon=s.epsilon||Z}onTouchStart(t){var e;!t||!((e=t==null?void 0:t.touches)!=null&&e.length)||this._touchDragTimeOut||(this._firstTouch=t.touches[t.touches.length-1],this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=t.touches[0]),this._checkXDistance(t)()},this._delay))}onTouchEnd(){this._resetTouches()}onTouchMove(t){var e;!t||!((e=t==null?void 0:t.touches)!=null&&e.length)||(this._lastTouch=t.touches[0])}_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())}}}class Oe{constructor(){l(this,"_instance",null);l(this,"_mode","website");l(this,"_viewName","main")}setInstance(t){this._instance=t}setMode(t){this._mode=t}setViewName(t){this._viewName=t}}const ee="rml-drag-in-styles",Me="rml-drag-in-drag-element",N="rml-drag-in-overlay",x="rml-drag-in-drag-ghost",F="rml-drag-in-fade-in",te="rml-drag-in-fade-out",U={DISPLAY_NONE:"rml-display-none"},se=.5,Y="250ms",k="forwards",D=o=>o?!0:(console.warn("No instance set, cancel drag-in"),!1);class Ae extends Oe{constructor(e){super();l(this,"_mainDomElement");l(this,"_currentDrag",{});l(this,"_currentTouch",null);l(this,"_firefoxDragPosition",{x:0,y:0});l(this,"options",{});l(this,"_firefoxFallback",e=>{if(!this._currentDrag.event)return;const s=e||window.event;this._firefoxDragPosition.x=s.pageX||0,this._firefoxDragPosition.y=s.pageY||0});this._mainDomElement=e,this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!!!document.getElementById(ee)){const s=document.createElement("style");s.type="text/css",s.id=ee,s.innerHTML=`
9
+ .${U.DISPLAY_NONE}{display:none}
10
+ .${N}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
11
+ .${x}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
12
+ @keyframes ${F} {from{opacity: 0;}to {opacity: ${se};}}
13
+ @keyframes ${te} {from{opacity: ${se};}to {opacity: 0;}}
14
+ `,document.head.appendChild(s)}}_initializeDragGhost(){const e=this._mode==="custom-view"?document.body:this._mainDomElement.parentNode;let s=e.querySelector("."+x);s||(s=document.createElement("div"),s.classList.add(x),s.innerText=" ",e.appendChild(s))}setInstance(e){this._instance=e}setMode(e){this._mode=e}async dragStart(e,s,n="rml_id"){const i=this._mainDomElement.parentNode,r=i.querySelector("."+x);if(s instanceof DragEvent&&s.dataTransfer&&s.dataTransfer.setDragImage&&s.dataTransfer.setDragImage(r,0,0),this._mode==="custom-view"&&D(this._instance)){const S=await this._instance.getBoundingClientRect("iframe"),y=this.options.domContainer;if(!y)throw new Error("No container set, can not expand custom view");y.style.position="absolute",y.style.top=`${S.top}px`,y.style.left=`${S.left}px`,y.style.width=`${S.width}px`,y.style.height=`${S.height}px`,await this._instance.expandCustomView(this._viewName)}const c=A(i);if(this._mode==="website"&&c.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 a=i.querySelector("."+N);a||(a=document.createElement("div"),a.classList.add(N),i.appendChild(a)),a.classList.remove(U.DISPLAY_NONE),s.target.getAttribute("draggable")||console.warn(`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`),this._currentDrag.event=s;const u=s.target.cloneNode();u.style.position="fixed",u.style.pointerEvents="none",u.style.opacity="0",u.style.animation=`${F} ${Y} ${k}`,u.id=Me,u.style.zIndex="9999",document.body.appendChild(u),this._currentDrag.element=u;const d=s.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0});const{clientX:p,clientY:g}=b(s,this._firefoxDragPosition);this._currentDrag.offset.x=this._mode==="website"?p-d.left:d.width/2,this._currentDrag.offset.y=this._mode==="website"?g-d.top:d.height/2,u.style.top=g+"px",u.style.left=p+"px";const{x:E,y:T}=j(i,this._currentDrag.event||s,this._firefoxDragPosition),I=Math.max(1,E),O=Math.max(1,T);D(this._instance)&&this._instance.dragInObject(e,I,O,n)}dragUpdate(e){var d,p;const{clientX:s,clientY:n}=b(e,this._firefoxDragPosition),i=s<=0||n<=0;if(this._mode==="custom-view"&&i)return;const r=this._mainDomElement.parentNode,{x:c,y:a}=j(r,e,this._firefoxDragPosition);if(c===0&&a===0)return;const h=Math.max(1,c),u=Math.max(1,a);if(this._currentDrag.element){const{clientX:g,clientY:E}=b(e,this._firefoxDragPosition),T=((d=this._currentDrag.offset)==null?void 0:d.x)||0,I=((p=this._currentDrag.offset)==null?void 0:p.y)||0;this._currentDrag.element.style.left=`${g-T}px`,this._currentDrag.element.style.top=`${E-I}px`;const O=(this.options.dragInOverlapX||0)+1,S=(this.options.dragInOverlapY||0)+1;let y=h>O&&u>S;if(this._mode==="custom-view"){const ne=this.options.domContainer;if(!ne)throw new Error("No container set, can not fade in/out drag ghost");const R=ne.getBoundingClientRect();y=!De({x:h,y:u},{x:R.left-O,y:R.top-S,width:R.width+O,height:R.height+S})}y?this._currentDrag.element.style.animation=`${te} ${Y} ${k}`:this._currentDrag.element.style.animation=`${F} ${Y} ${k}`}if(!(h===1&&u===1)&&D(this._instance)){let g=h,E=u;if(q(e)){const T=this.options.fingerSize||0;g=Math.max(2,h+T),E=Math.max(2,u-T)}this._instance.updateDrag(g,E)}}async dragEnd(){if(D(this._instance)){await this._instance.collapseCustomView(this._viewName);const n=this.options.domContainer;if(!n)throw new Error("No container set, can not collapse custom view");n.style.position="",n.style.top="",n.style.left="",n.style.width="",n.style.height=""}this._mainDomElement.style.pointerEvents="all";const e=this._mainDomElement.parentNode;D(this._instance)&&this._instance.dragInObjectEnd(),this._currentDrag.element&&document.body.removeChild(this._currentDrag.element),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const s=e.querySelector("."+N);s&&s.classList.add(U.DISPLAY_NONE)}touchStart(e,s,n="rml_id"){var c,a;s.preventDefault();const i=(h,u)=>{this.dragStart(e,u,n)},r={};typeof((c=this.options)==null?void 0:c.touchDragDelay)=="number"&&(r.delay=this.options.touchDragDelay),(a=this.options)!=null&&a.touchDragEpsilon&&(r.epsilon=this.options.touchDragEpsilon),this._currentTouch=new Ie(void 0,{onTouchDragStart:i},r),this._currentTouch.onTouchStart(s)}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 be=Object.freeze(Object.defineProperty({__proto__:null,DragIn:Ae},Symbol.toStringTag,{value:"Module"}));return Ee});
@@ -1,14 +1,14 @@
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")),A=["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=A.length;t<s;t++){const r=e[A[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},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}}
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,e,t)=>e in i?_(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,c=(i,e,t)=>v(i,typeof e!="symbol"?e+"":e,t);class k{constructor(e,t,s,n){c(this,"_side"),c(this,"_incomingMessageBus"),c(this,"_outgoingMessageBus",null),c(this,"_execMessage",null),this._side=e,this._incomingMessageBus=t,this._outgoingMessageBus=s,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((s,n)=>{const o=new MessageChannel;o.port1.onmessage=r=>{if(!r||!r.data)return o.port1.close(),o.port2.close(),n(new Error(this._side+" received message but response can not be interpreted"));let l;try{l=JSON.parse(r.data)}catch(h){return o.port1.close(),o.port2.close(),this._prepareError(h),n(h)}l.error?n(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 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 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 n=this._execMessage(s,e);if(n===void 0)return;n.then((o={})=>{let a,r;typeof o=="object"&&o!==null&&(a=o.error,r=o.result),a?t.postMessage(JSON.stringify({error:a})):r!==void 0?t.postMessage(JSON.stringify({result:r})):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 O=".",M={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},E={GET_METHODS:"getMethods",RETURN_METHODS:"returnMethods",REGISTER_CUSTOM_VIEW:"registerCustomView",REGISTER_CUSTOM_VIEW_DONE:"registerCustomViewDone"},re=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,n=t+"/configurators/"+i,o="roomle_portal_v2",a="03-"+window.btoa(new Date().toISOString()+";anonymous;"+o),r=()=>{const d={apiKey:o,currentTenant:s,locale:"en",language:"en",device:1,token:a,platform:"web"};return new Headers(d)},l=new Request(n,{method:"GET",headers:r(),mode:"cors",cache:"default"}),h=await fetch(l),{configurator:u}=await h.json();return u},oe=()=>{try{return window.self!==window.top}catch{return!0}},ae=["127.0.0.1","localhost","0.0.0.0"],le=()=>{const i=oe();let e=window.location.href;if(i){if(!document.referrer)return null;e=document.referrer}const{hostname:t}=new URL(e);return t},ce=i=>!!(ae.includes(i)||i.endsWith("roomle.com")||i.endsWith("gitlab.io")||i.endsWith("gitlab.com")),B=["language","browserLanguage","userLanguage","systemLanguage"],he=(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=B.length;t<s;t++){const n=e[B[t]];if(n)return n.substr(0,2)}return"en"},ue=(i,e)=>{const t=JSON.parse(JSON.stringify(i));return N(t,e)},N=(i,e)=>{for(const t in e)try{e[t].constructor===Object?i[t]=N(i[t],e[t]):i[t]=e[t]}catch{i[t]=e[t]}return i};var de={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const ge={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},rotationSnapDegrees:10},me="(idle)",_e=i=>(L(i),i!=null&&i.customApiUrl&&(i.customApiUrl=decodeURIComponent(i.customApiUrl)),i.shareUrl&&(i.deeplink=i.shareUrl.replace(ye,we)),i),L=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&&L(s),Array.isArray(s))for(const n of s)L(n);(s==="true"||s==="false")&&(i[t]=s==="true")}},fe=(i,e)=>{e.configuratorId=i.id;const t=i.settings||{};return!e.overrideTenant&&i.tenant&&(e.overrideTenant=i.tenant),ue(t,e)},pe=()=>{const i={...ge};i.locale||(i.locale=he()),i.id===me&&delete i.id;const e=le();return e&&ce(e)&&(i.configuratorId="demoConfigurator"),i.customApiUrl=de.VITE_RAPI_URL,i.emails=!1,i},ye="<CONF_ID>",we="#CONFIGURATIONID#",W=()=>/(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(n=>{const o=n.split(O),a=o[0],r=o[1];this[a]||(this[a]={}),this[a][r]=function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(n,[...arguments])}.bind(this)}),s.forEach(n=>{const o=n.split(O),a=o[0],r=o[1],l=o[2];this[a]||(this[a]={}),this[a][r]||(this[a][r]={}),this[a][r][l]=()=>{}}),this.isSetupDone=!0}executeMessage({message:e,args:t}){const s=e.split(O),n=s[0],o=s[1],a=s.length===3?s[2]:null;if(a&&this[n][o][a]){const r=this[n][o][a](...t);return r instanceof Promise?r.then(l=>({result:l})):r!==void 0?Promise.resolve({result:r}):Promise.resolve({result:null})}return Promise.reject('Message "'+e+'" is unkown')}setupPlugins(e,t,s="website"){for(const n of e)typeof n=="string"&&n==="dragIn"?this.pluginsLoaded.push(new Promise((o,a)=>{try{Promise.resolve().then(()=>Me).then(({DragIn:r})=>{const l=new r(t);l.setInstance(this.ui),l.setMode(s),l.setViewName(this.viewName),this.plugins.dragIn=l,o()})}catch(r){a(r)}})):n.name&&n.loader&&this.pluginsLoaded.push(new Promise((o,a)=>{try{n.loader().then(r=>{const l=new r(t);l.setInstance(this.ui),l.setMode(s),l.setViewName(this.viewName),this.plugins[n.name]=l,o()})}catch(r){a(r)}}))}}const Y=()=>{let i,e;return{promise:new Promise((t,s)=>{i=t,e=s}),resolve:i,reject:e}},z=(i,e,t)=>{let s=null;Object.defineProperty(i,e,{get(){return s||t},set(n){n!=null&&n.mute?s=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 }"),s=n)}})},j=()=>window.innerHeight*.01+"px",X=i=>{i&&setTimeout(()=>i.style.setProperty(P,j()),0)},G="rml-styles",ve=450,P="--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"},R=new Map;class De extends V{constructor(e,t,s,n,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(R.has(t))throw new Error("There is already an instance on this DOM element");if(!document.getElementById(G)){const l=s.zIndex||9999999,h=document.createElement("style");h.type="text/css",h.id=G;const u="transition:all ease-in-out "+ve+"ms;",d=["-webkit-","-o-"].reduce((p,y)=>p+=y+u,"")+u,g=j();h.innerHTML=`
2
+ .${m.CONTAINER}{${P}:${g};}
3
+ .${m.POSITION}{position:fixed;top:0;left:0;z-index:${l};opacity:0}
4
+ .${m.TRANSITION}{${d}}
5
5
  .${m.FILL}{width:100%;height:100%;opacity:1}
6
- .${m.ANDROID_HEIGHT}{height:calc(var(${x},1vh)*100)}
6
+ .${m.ANDROID_HEIGHT}{height:calc(var(${P},1vh)*100)}
7
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 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",C=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);C(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)&&C(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;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("."+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});
8
+ `,document.head.appendChild(h)}this._executeMessage=this._executeMessage.bind(this);const a=new k("website",window,null,this._executeMessage);this.setMessageHandler(a),this._onResize=this._onResize.bind(this),W()&&window.addEventListener("resize",this._onResize),this._container=t,this._initData=s,this._configuratorSettings=e;const r=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=o,this._container.appendChild(r),this._iframe=r,this.setupPlugins(n,this._iframe),R.set(t,!0)}static createPlanner(e,t,s,n=[]){return this._create(e,t,s,n)}static async connect(e,t=[]){const s=new V;s.viewName=e;const{resolve:n,promise:o}=Y(),{resolve:a,promise:r}=Y(),l=({message:d,args:g})=>{if(d===E.REGISTER_CUSTOM_VIEW_DONE){n();return}if(d===E.RETURN_METHODS){s.handleSetup(g[0]),a();return}if(s.isSetupDone)return s.executeMessage({message:d,args:g})},h=new k("custom-view",window,window.parent,l);s.setMessageHandler(h);const u=[e];return h.sendMessage(E.REGISTER_CUSTOM_VIEW,u),await o,h.sendMessage(E.GET_METHODS,u),await r,s.setupPlugins(t,document.body,"custom-view"),await Promise.allSettled(s.pluginsLoaded),s}static createConfigurator(e,t,s,n=[]){return this._create(e,t,s,n)}static create(e,t,s,n){return this._create(e,t,s,n)}static createViewer(e,t,s,n=[]){return this._create(e,t,s,n)}static async _create(e,t,s,n){return new Promise(async(o,a)=>{try{const r=N(pe(),_e(s));r.featureFlags||(r.featureFlags={}),typeof r.featureFlags.realPartList!="boolean"&&(r.featureFlags.realPartList=!0),typeof r.featureFlags.globalCallbacks!="boolean"&&(r.featureFlags.globalCallbacks=!0),typeof r.featureFlags.mocAr!="boolean"&&(r.featureFlags.mocAr=!1);const l=await re(e,r);s=fe(l,r);const h=new this(l,t,s,n,o);return await Promise.allSettled(h.pluginsLoaded),h}catch(r){return a(r)}})}teardown(){this._container&&R.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(){X(this._iframe)}_onUseFullPage(){this._iframe.classList.add(m.POSITION),document.documentElement.classList.add(m.OVERFLOW_HIDDEN),window.document.body.classList.add(m.OVERFLOW_HIDDEN),W()&&(X(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 n;if(s.source&&s.source===((n=this._iframe)==null?void 0:n.contentWindow))return e===M.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===M.SETUP?(this.handleSetup(t[0]),z(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),z(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>{if(!this._messageHandler){console.error("MessageHandler not set");return}this._messageHandler.sendMessage(M.WEBSITE_READY)},0),Promise.resolve({result:null})):this.executeMessage({message:e,args:t})}}class Ee{constructor(e=16){c(this,"_computedStyleCache",new Map),c(this,"_maxLifetime",16),c(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 n=getComputedStyle(e);return this._computedStyleCache.set(e,{style:n,updated:s}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),n}_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 J=i=>window.TouchEvent&&i instanceof window.TouchEvent;let C;const T=i=>(C||(C=new Ee),C.get(i)),q=(i,e,t)=>{const s=parseFloat(i),n=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(T(document.documentElement).fontSize);return s*a}if(e==="em"){const a=parseFloat(T(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]*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)},Q=(i,e,t={x:0,y:0})=>{const s=i.getBoundingClientRect(),n=T(i).transform;let o=0,a=0;if(n!=="none"){const d=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,g=n.match(d);g&&(o=q(g[1],g[2],i),a=q(g[3],g[4],i))}const{clientX:r,clientY:l}=b(e,t),h=r-s.left-o+i.scrollLeft,u=l-s.top-a+i.scrollTop;return{x:h,y:u}},b=(i,e)=>{const{clientX:t,clientY:s}=J(i)?Te(i):i,n=t>0?t:e.x,o=s>0?s:e.y;return{clientX:n,clientY:o}},Te=i=>{if(i.touches.length){let{clientX:t,clientY:s}=i.touches[0];if(i.touches.length>1){const n=i.touches[1],o=n.clientX,a=n.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}},be=(i,e)=>{const t=e.x+e.width,s=e.x,n=e.y+e.height,o=e.y,{x:a,y:r}=i;return a>=s&&a<=t&&r>=o&&r<=n},K=500,Z=10;class Ie{constructor(e,{onTouchDragStart:t},s={}){c(this,"_touchDragTimeOut"),c(this,"_onTouchDragStart"),c(this,"_payload",null),c(this,"_delay",K),c(this,"_firstTouch",null),c(this,"_lastTouch",null),c(this,"_epsilon",Z),this._payload=e,this._onTouchDragStart=t,this._delay=s.delay||K,this._epsilon=s.epsilon||Z}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())}}}class xe{constructor(){c(this,"_instance",null),c(this,"_mode","website"),c(this,"_viewName","main")}setInstance(e){this._instance=e}setMode(e){this._mode=e}setViewName(e){this._viewName=e}}const ee="rml-drag-in-styles",Se="rml-drag-in-drag-element",I="rml-drag-in-overlay",x="rml-drag-in-drag-ghost",A="rml-drag-in-fade-in",te="rml-drag-in-fade-out",H={DISPLAY_NONE:"rml-display-none"},se=.5,F="250ms",U="forwards",D=i=>i?!0:(console.warn("No instance set, cancel drag-in"),!1);class Oe extends xe{constructor(e){super(),c(this,"_mainDomElement"),c(this,"_currentDrag",{}),c(this,"_currentTouch",null),c(this,"_firefoxDragPosition",{x:0,y:0}),c(this,"options",{}),c(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._mainDomElement=e,this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!document.getElementById(ee)){const e=document.createElement("style");e.type="text/css",e.id=ee,e.innerHTML=`
9
+ .${H.DISPLAY_NONE}{display:none}
10
+ .${I}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
11
+ .${x}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
12
+ @keyframes ${A} {from{opacity: 0;}to {opacity: ${se};}}
13
+ @keyframes ${te} {from{opacity: ${se};}to {opacity: 0;}}
14
+ `,document.head.appendChild(e)}}_initializeDragGhost(){const e=this._mode==="custom-view"?document.body:this._mainDomElement.parentNode;let t=e.querySelector("."+x);t||(t=document.createElement("div"),t.classList.add(x),t.innerText=" ",e.appendChild(t))}setInstance(e){this._instance=e}setMode(e){this._mode=e}async dragStart(e,t,s="rml_id"){const n=this._mainDomElement.parentNode,o=n.querySelector("."+x);if(t instanceof DragEvent&&t.dataTransfer&&t.dataTransfer.setDragImage&&t.dataTransfer.setDragImage(o,0,0),this._mode==="custom-view"&&D(this._instance)){const w=await this._instance.getBoundingClientRect("iframe"),f=this.options.domContainer;if(!f)throw new Error("No container set, can not expand custom view");f.style.position="absolute",f.style.top=`${w.top}px`,f.style.left=`${w.left}px`,f.style.width=`${w.width}px`,f.style.height=`${w.height}px`,await this._instance.expandCustomView(this._viewName)}const a=T(n);if(this._mode==="website"&&a.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 r=n.querySelector("."+I);r||(r=document.createElement("div"),r.classList.add(I),n.appendChild(r)),r.classList.remove(H.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`),this._currentDrag.event=t;const l=t.target.cloneNode();l.style.position="fixed",l.style.pointerEvents="none",l.style.opacity="0",l.style.animation=`${A} ${F} ${U}`,l.id=Se,l.style.zIndex="9999",document.body.appendChild(l),this._currentDrag.element=l;const h=t.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0});const{clientX:u,clientY:d}=b(t,this._firefoxDragPosition);this._currentDrag.offset.x=this._mode==="website"?u-h.left:h.width/2,this._currentDrag.offset.y=this._mode==="website"?d-h.top:h.height/2,l.style.top=d+"px",l.style.left=u+"px";const{x:g,y:p}=Q(n,this._currentDrag.event||t,this._firefoxDragPosition),y=Math.max(1,g),$=Math.max(1,p);D(this._instance)&&this._instance.dragInObject(e,y,$,s)}dragUpdate(e){var t,s;const{clientX:n,clientY:o}=b(e,this._firefoxDragPosition),a=n<=0||o<=0;if(this._mode==="custom-view"&&a)return;const r=this._mainDomElement.parentNode,{x:l,y:h}=Q(r,e,this._firefoxDragPosition);if(l===0&&h===0)return;const u=Math.max(1,l),d=Math.max(1,h);if(this._currentDrag.element){const{clientX:g,clientY:p}=b(e,this._firefoxDragPosition),y=((t=this._currentDrag.offset)==null?void 0:t.x)||0,$=((s=this._currentDrag.offset)==null?void 0:s.y)||0;this._currentDrag.element.style.left=`${g-y}px`,this._currentDrag.element.style.top=`${p-$}px`;const w=(this.options.dragInOverlapX||0)+1,f=(this.options.dragInOverlapY||0)+1;let ie=u>w&&d>f;if(this._mode==="custom-view"){const ne=this.options.domContainer;if(!ne)throw new Error("No container set, can not fade in/out drag ghost");const S=ne.getBoundingClientRect();ie=!be({x:u,y:d},{x:S.left-w,y:S.top-f,width:S.width+w,height:S.height+f})}ie?this._currentDrag.element.style.animation=`${te} ${F} ${U}`:this._currentDrag.element.style.animation=`${A} ${F} ${U}`}if(!(u===1&&d===1)&&D(this._instance)){let g=u,p=d;if(J(e)){const y=this.options.fingerSize||0;g=Math.max(2,u+y),p=Math.max(2,d-y)}this._instance.updateDrag(g,p)}}async dragEnd(){if(D(this._instance)){await this._instance.collapseCustomView(this._viewName);const s=this.options.domContainer;if(!s)throw new Error("No container set, can not collapse custom view");s.style.position="",s.style.top="",s.style.left="",s.style.width="",s.style.height=""}this._mainDomElement.style.pointerEvents="all";const e=this._mainDomElement.parentNode;D(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(H.DISPLAY_NONE)}touchStart(e,t,s="rml_id"){var n,o;t.preventDefault();const a=(l,h)=>{this.dragStart(e,h,s)},r={};typeof((n=this.options)==null?void 0:n.touchDragDelay)=="number"&&(r.delay=this.options.touchDragDelay),(o=this.options)!=null&&o.touchDragEpsilon&&(r.epsilon=this.options.touchDragEpsilon),this._currentTouch=new Ie(void 0,{onTouchDragStart:a},r),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 Me=Object.freeze(Object.defineProperty({__proto__:null,DragIn:Oe},Symbol.toStringTag,{value:"Module"}));return De});
@@ -1,7 +0,0 @@
1
- var O=Object.defineProperty,P=(i,t,e)=>t in i?O(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,c=(i,t,e)=>P(i,typeof t!="symbol"?t+"":t,e);class N{constructor(t=16){c(this,"_computedStyleCache",new Map),c(this,"_maxLifetime",16),c(this,"_cacheCleanInterval",null),this._maxLifetime=t}get(t){const e=this._computedStyleCache.get(t),n=Date.now();if(e&&n-e.updated<this._maxLifetime)return e.style;const o=getComputedStyle(t);return this._computedStyleCache.set(t,{style:o,updated:n}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),o}_cleanUpCache(){const t=Date.now();for(const[e,{updated:n}]of this._computedStyleCache.entries())t-n>=this._maxLifetime&&this._computedStyleCache.delete(e);this._computedStyleCache.size===0&&this._cacheCleanInterval&&(clearInterval(this._cacheCleanInterval),this._cacheCleanInterval=null)}}const E=i=>window.TouchEvent&&i instanceof window.TouchEvent;let D;const f=i=>(D||(D=new N),D.get(i)),C=(i,t,e)=>{const n=parseFloat(i),o=window.devicePixelRatio||1;if(t==="px")return n;if(t==="%"){const a=e===document.documentElement?window.innerWidth:e.offsetWidth;return n/100*a}if(t==="rem"){const a=parseFloat(f(document.documentElement).fontSize);return n*a}if(t==="em"){const a=parseFloat(f(e).fontSize);return n*a}if(t==="vh"||t==="vw"||t==="vmin"||t==="vmax"){const a={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return n/100*a[t]}const s={cm:37.7952755906,mm:3.77952755906,in:96};return t in s?n*s[t]*o:(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)},I=(i,t,e={x:0,y:0})=>{const n=i.getBoundingClientRect(),o=f(i).transform;let s=0,a=0;if(o!=="none"){const _=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,d=o.match(_);d&&(s=C(d[1],d[2],i),a=C(d[3],d[4],i))}const{clientX:r,clientY:l}=v(t,e),h=r-n.left-s+i.scrollLeft,u=l-n.top-a+i.scrollTop;return{x:h,y:u}},v=(i,t)=>{const{clientX:e,clientY:n}=E(i)?k(i):i,o=e||t.x,s=n||t.y;return{clientX:o,clientY:s}},k=i=>{if(i.touches.length){let{clientX:e,clientY:n}=i.touches[0];if(i.touches.length>1){const o=i.touches[1],s=o.clientX,a=o.clientY;e=(e+s)/2,n=(n+a)/2}return{clientX:e,clientY:n}}const t=i.changedTouches[0];return{clientX:t.clientX,clientY:t.clientY}},$=500,L=10;class z{constructor(t,{onTouchDragStart:e},n={}){c(this,"_touchDragTimeOut"),c(this,"_onTouchDragStart"),c(this,"_payload",null),c(this,"_delay",$),c(this,"_firstTouch",null),c(this,"_lastTouch",null),c(this,"_epsilon",L),this._payload=t,this._onTouchDragStart=e,this._delay=n.delay||$,this._epsilon=n.epsilon||L}onTouchStart(t){var e;!t||!((e=t?.touches)!=null&&e.length)||this._touchDragTimeOut||(this._firstTouch=t.touches[t.touches.length-1],this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=t.touches[0]),this._checkXDistance(t)()},this._delay))}onTouchEnd(){this._resetTouches()}onTouchMove(t){var e;!t||!((e=t?.touches)!=null&&e.length)||(this._lastTouch=t.touches[0])}_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 X="rml-drag-in-styles",F="rml-drag-in-drag-element",g="rml-drag-in-overlay",m="rml-drag-in-drag-ghost",x="rml-drag-in-fade-in",Y="rml-drag-in-fade-out",T={DISPLAY_NONE:"rml-display-none"},M=.5,w="250ms",S="forwards",b=i=>i?!0:(console.warn("No instance set, cancel drag-in"),!1);class A{constructor(t){c(this,"_iframe"),c(this,"_currentDrag",{}),c(this,"_currentTouch",null),c(this,"_firefoxDragPosition",{x:0,y:0}),c(this,"_instance",null),c(this,"options",{}),c(this,"_firefoxFallback",e=>{if(!this._currentDrag.event)return;const n=e||window.event;this._firefoxDragPosition.x=n.pageX||0,this._firefoxDragPosition.y=n.pageY||0}),this._iframe=t,this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!document.getElementById(X)){const t=document.createElement("style");t.type="text/css",t.id=X,t.innerHTML=`
2
- .${T.DISPLAY_NONE}{display:none}
3
- .${g}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
4
- .${m}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
5
- @keyframes ${x} {from{opacity: 0;}to {opacity: ${M};}}
6
- @keyframes ${Y} {from{opacity: ${M};}to {opacity: 0;}}
7
- `,document.head.appendChild(t)}}_initializeDragGhost(){const t=this._iframe.parentNode;let e=t.querySelector("."+m);e||(e=document.createElement("div"),e.classList.add(m),e.innerText=" ",t.appendChild(e))}setInstance(t){this._instance=t}dragStart(t,e,n="rml_id"){const o=this._iframe.parentNode;if(f(o).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 s=o.querySelector("."+g);s||(s=document.createElement("div"),s.classList.add(g),o.appendChild(s)),s.classList.remove(T.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 a=o.querySelector("."+m);this._currentDrag.event=e;const r=e.target.cloneNode();r.style.position="fixed",r.style.pointerEvents="none",r.style.opacity="0",r.style.animation=`${x} ${w} ${S}`,r.id=F,r.style.zIndex="9999",document.body.appendChild(r),this._currentDrag.element=r;const l=e.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0});const{clientX:h,clientY:u}=v(e,this._firefoxDragPosition);this._currentDrag.offset.x=h-l.left,this._currentDrag.offset.y=u-l.top,r.style.top=u+"px",r.style.left=h+"px",e instanceof DragEvent&&e.dataTransfer&&e.dataTransfer.setDragImage&&e.dataTransfer.setDragImage(a,0,0);const{x:_,y:d}=I(o,this._currentDrag.event||e,this._firefoxDragPosition),p=Math.max(1,_),y=Math.max(1,d);b(this._instance)&&this._instance.dragInObject(t,p,y,n)}dragUpdate(t){var e,n;const o=this._iframe.parentNode,{x:s,y:a}=I(o,t,this._firefoxDragPosition);if(s===0&&a===0)return;const r=Math.max(1,s),l=Math.max(1,a);if(this._currentDrag.element){const{clientX:h,clientY:u}=v(t,this._firefoxDragPosition),_=((e=this._currentDrag.offset)==null?void 0:e.x)||0,d=((n=this._currentDrag.offset)==null?void 0:n.y)||0;this._currentDrag.element.style.left=`${h-_}px`,this._currentDrag.element.style.top=`${u-d}px`;const p=(this.options.dragInOverlapX||0)+1,y=(this.options.dragInOverlapY||0)+1;r>p&&l>y?this._currentDrag.element.style.animation=`${Y} ${w} ${S}`:this._currentDrag.element.style.animation=`${x} ${w} ${S}`}if(!(r===1&&l===1)&&b(this._instance)){let h=r,u=l;if(E(t)){const _=this.options.fingerSize||0;h=Math.max(2,r+_),u=Math.max(2,l-_)}this._instance.updateDrag(h,u)}}dragEnd(){this._iframe.style.pointerEvents="all";const t=this._iframe.parentNode;b(this._instance)&&this._instance.dragInObjectEnd(),this._currentDrag.element&&document.body.removeChild(this._currentDrag.element),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const e=t.querySelector("."+g);e&&e.classList.add(T.DISPLAY_NONE)}touchStart(t,e,n="rml_id"){var o,s;e.preventDefault();const a=(l,h)=>{this.dragStart(t,h,n)},r={};typeof((o=this.options)==null?void 0:o.touchDragDelay)=="number"&&(r.delay=this.options.touchDragDelay),(s=this.options)!=null&&s.touchDragEpsilon&&(r.epsilon=this.options.touchDragEpsilon),this._currentTouch=new z(void 0,{onTouchDragStart:a},r),this._currentTouch.onTouchStart(e)}touchMove(t){this._currentTouch&&this._currentTouch.onTouchMove(t),this._currentDrag.event&&this.dragUpdate(t)}touchEnd(){this._currentTouch&&this._currentTouch.onTouchEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}}export{A as DragIn};