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