!function(e){var n={};function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)t.d(o,r,function(n){return e[n]}.bind(null,r));return o},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=1)}([function(e,n,t){"use strict";var o=()=>{const e=[];let n=!1;return{destroy(t){n=!0,e.forEach(e=>{e(t)})},onDestroy(t){n?t():e.push(t)}}};const r={"http:":"80","https:":"443"},i=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,c=["file:","data:"];var s,a,d,l,u,f=e=>(...n)=>{e&&console.log("[Penpal]",...n)};!function(e){e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack"}(s||(s={})),function(e){e.Fulfilled="fulfilled",e.Rejected="rejected"}(a||(a={})),function(e){e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NotInIframe="NotInIframe",e.NoIframeSrc="NoIframeSrc"}(d||(d={})),function(e){e.DataCloneError="DataCloneError"}(l||(l={})),function(e){e.Message="message"}(u||(u={}));const m=({name:e,message:n,stack:t})=>({name:e,message:n,stack:t});var p=(e,n,t)=>{const{localName:o,local:r,remote:i,originForSending:c,originForReceiving:d}=e;let f=!1;const p=e=>{if(e.source!==i||e.data.penpal!==s.Call)return;if(e.origin!==d)return void t(`${o} received message from origin ${e.origin} which did not match expected origin ${d}`);const r=e.data,{methodName:u,args:p,id:g}=r;t(`${o}: Received ${u}() call`);const h=e=>n=>{if(t(`${o}: Sending ${u}() reply`),f)return void t(`${o}: Unable to send ${u}() reply due to destroyed connection`);const r={penpal:s.Reply,id:g,resolution:e,returnValue:n};e===a.Rejected&&n instanceof Error&&(r.returnValue=m(n),r.returnValueIsError=!0);try{i.postMessage(r,c)}catch(e){if(e.name===l.DataCloneError){const n={penpal:s.Reply,id:g,resolution:a.Rejected,returnValue:m(e),returnValueIsError:!0};i.postMessage(n,c)}throw e}};new Promise(e=>e(n[u].apply(n,p))).then(h(a.Fulfilled),h(a.Rejected))};return r.addEventListener(u.Message,p),()=>{f=!0,r.removeEventListener(u.Message,p)}};let g=0;var h=(e,n,t,o,r)=>{const{localName:i,local:c,remote:l,originForSending:f,originForReceiving:m}=n;let p=!1;r(i+": Connecting call sender");const h=e=>(...n)=>{let t;r(`${i}: Sending ${e}() call`);try{l.closed&&(t=!0)}catch(e){t=!0}if(t&&o(),p){const n=new Error(`Unable to send ${e}() call due to destroyed connection`);throw n.code=d.ConnectionDestroyed,n}return new Promise((t,o)=>{const d=++g,p=n=>{if(n.source!==l||n.data.penpal!==s.Reply||n.data.id!==d)return;if(n.origin!==m)return void r(`${i} received message from origin ${n.origin} which did not match expected origin ${m}`);const f=n.data;r(`${i}: Received ${e}() reply`),c.removeEventListener(u.Message,p);let g=f.returnValue;f.returnValueIsError&&(g=(e=>{const n=new Error;return Object.keys(e).forEach(t=>n[t]=e[t]),n})(g)),(f.resolution===a.Fulfilled?t:o)(g)};c.addEventListener(u.Message,p);const h={penpal:s.Call,id:d,methodName:e,args:n};l.postMessage(h,f)})};return t.reduce((e,n)=>(e[n]=h(n),e),e),()=>{p=!0}};var y=(e,n)=>{let t;return void 0!==e&&(t=window.setTimeout(()=>{const t=new Error(`Connection timed out after ${e}ms`);t.code=d.ConnectionTimeout,n(t)},e)),()=>{clearTimeout(t)}},w=e=>{let{iframe:n,methods:t={},childOrigin:a,timeout:l,debug:m=!1}=e;const g=f(m),w=o(),{onDestroy:v,destroy:b}=w;a||((e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=d.NoIframeSrc,e}})(n),a=(e=>{if(e&&c.find(n=>e.startsWith(n)))return"null";const n=document.location,t=i.exec(e);let o,s,a;t?(o=t[1]?t[1]:n.protocol,s=t[2],a=t[4]):(o=n.protocol,s=n.hostname,a=n.port);return`${o}//${s}${a&&a!==r[o]?":"+a:""}`})(n.src));const S="null"===a?"*":a,E=((e,n,t,o)=>r=>{if(r.origin!==t)return void e(`Parent: Handshake - Received SYN message from origin ${r.origin} which did not match expected origin ${t}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const i={penpal:s.SynAck,methodNames:Object.keys(n)};r.source.postMessage(i,o)})(g,t,a,S),C=((e,n,t,o,r)=>{const{destroy:i,onDestroy:c}=o;let s,a;const d={};return o=>{if(o.origin!==n)return void r(`Parent: Handshake - Received ACK message from origin ${o.origin} which did not match expected origin ${n}`);r("Parent: Handshake - Received ACK");const l={localName:"Parent",local:window,remote:o.source,originForSending:t,originForReceiving:n};s&&s(),s=p(l,e,r),c(s),a&&a.forEach(e=>{delete d[e]}),a=o.data.methodNames;const u=h(d,l,a,i,r);return c(u),d}})(t,a,S,w,g);return{promise:new Promise((e,t)=>{const o=y(l,b),r=t=>{if(t.source===n.contentWindow&&t.data)if(t.data.penpal!==s.Syn)if(t.data.penpal!==s.Ack);else{const n=C(t);n&&(o(),e(n))}else E(t)};window.addEventListener(u.Message,r),g("Parent: Awaiting handshake"),((e,n)=>{const{destroy:t,onDestroy:o}=n,r=setInterval(()=>{document.contains(e)||(clearInterval(r),t())},6e4);o(()=>{clearInterval(r)})})(n,w),v(e=>{window.removeEventListener(u.Message,r),e||((e=new Error("Connection destroyed")).code=d.ConnectionDestroyed),t(e)})}),destroy(){b()}}};var v=(e={})=>{const{parentOrigin:n="*",methods:t={},timeout:r,debug:i=!1}=e,c=f(i),a=o(),{destroy:l,onDestroy:m}=a;(()=>{if(window===window.top){const e=new Error("connectToParent() must be called within an iframe");throw e.code=d.NotInIframe,e}})();const g=((e,n,t,o)=>{const{destroy:r,onDestroy:i}=t;return t=>{if(!(e instanceof RegExp?e.test(t.origin):"*"===e||e===t.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${t.origin} which did not match expected origin ${e}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");const c="null"===t.origin?"*":t.origin,a={penpal:s.Ack,methodNames:Object.keys(n)};window.parent.postMessage(a,c);const d={localName:"Child",local:window,remote:window.parent,originForSending:c,originForReceiving:t.origin},l=p(d,n,o);i(l);const u={},f=h(u,d,t.data.methodNames,r,o);return i(f),u}})(n,t,a,c);return{promise:new Promise((e,t)=>{const o=y(r,l),i=n=>{if((()=>{try{clearTimeout()}catch(e){return!1}return!0})()&&n.source===parent&&n.data&&n.data.penpal===s.SynAck){const t=g(n);t&&(window.removeEventListener(u.Message,i),o(),e(t))}};window.addEventListener(u.Message,i),(()=>{c("Child: Handshake - Sending SYN");const e={penpal:s.Syn},t=n instanceof RegExp?"*":n;window.parent.postMessage(e,t)})(),m(e=>{window.removeEventListener(u.Message,i),e||((e=new Error("Connection destroyed")).code=d.ConnectionDestroyed),t(e)})}),destroy(){l()}}};t.d(n,"a",(function(){return w})),t.d(n,"b",(function(){return v}))},function(e,n,t){"use strict";t.r(n),function(e){var n,o,r=t(0); /*! * StreamBIM widget API * * A JavaScript library for interacting with * StreamBIM from within an embedded widget * https://github.com/streambim * * MIT License | (c) Rendra AS 2019 */n=window,o=function(){return{connect(e={}){return this._connection=Object(r.b)({methods:e}),this._connection.promise.then(e=>{this._connection=e,Object.keys(e).forEach(e=>{this[e]=n=>(console.assert(this._connection,"StreamBIM parent frame not found"),this._connection[e](n))})})},connectToChild(e,n={}){return this._connection=Object(r.a)({iframe:e,methods:n}),this._connection.promise.then(e=>{this._connection=e,Object.keys(e).forEach(e=>{this[e]=n=>(console.assert(this._connection,"StreamBIM child frame not found"),this._connection[e](n))})})}}},e.exports?e.exports=o():"function"==typeof define&&t(3)?define("StreamBIM",o):n.StreamBIM=o()}.call(this,t(2)(e))},function(e,n){e.exports=function(e){if(!e.webpackPolyfill){var n=Object.create(e);n.children||(n.children=[]),Object.defineProperty(n,"loaded",{enumerable:!0,get:function(){return n.l}}),Object.defineProperty(n,"id",{enumerable:!0,get:function(){return n.i}}),Object.defineProperty(n,"exports",{enumerable:!0}),n.webpackPolyfill=1}return n}},function(e,n){(function(n){e.exports=n}).call(this,{})}]);