!function(){"use strict";var e=window.hostConfig||{APIHost:"https://api.bimface.com",resourceHost:"https://m.bimface.com",staticHost:"https://static.bimface.com",dataEnvType:"BIMFACE",securityApi:!0};void 0===Object.assign&&(Object.assign=function(e){if(null==e)throw new TypeError("Cannot convert undefined or null to object");for(var t=Object(e),o=1;o-1){a=0;var f=n.options;f.build,t.Release;var h=c(n);return s(f.staticHost,h),void d(h,o)}++a==r?o():u(e[a],i)};u(e[a],i)},l=[],u=function(e,t){if(!(l.indexOf(e.split("/").pop())>-1)){var o,n=document.getElementsByTagName("head")[0];return e.indexOf(".css")>-1?((o=document.createElement("link")).setAttribute("href",e),o.setAttribute("rel","stylesheet")):(o=document.createElement("script")).setAttribute("src",e),o.url=e,n.appendChild(o),o.addEventListener("load",(function(){l.push(this.url.split("/").pop()),t&&t({message:"success"})})),o.addEventListener("error",(function(){t&&t({element:e,message:"error"})})),o}t()};window.loadResource=d;class f extends class{constructor(e){this.indexedDB=window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB||window.msIndexedDB,this.indexedDB||console.log("IndexedDB not supported"),this._db=null,this._opt=e}open(e,t){const o=e||this._opt.name,n=t||this._opt.version||1,r=this.indexedDB.open(o,n);return new Promise(((e,t)=>{r.onsuccess=t=>{this._db=r.result,e(this._db)},r.onupgradeneeded=e=>{let t=this._db=e.target.result;(this._opt.storeList||[]).forEach((e=>!t.objectStoreNames.contains(e)&&t.createObjectStore(e)))},r.onerror=e=>{t(e)}}))}getDB(){return new Promise(((e,t)=>{this._db?e(this._db):this.open().then(e).catch(t)}))}addObject(e,t,o){return new Promise(((n,r)=>{this.getDB().then((a=>{const i=a.transaction(e,"readwrite");i.objectStore(e).put(t,o).onsuccess=e=>{n(e.target.result)},i.onerror=e=>{r(e)}})).catch(r)}))}getObject(e,t){return new Promise(((o,n)=>{this.getDB().then((r=>{const a=r.transaction(e,"readonly");a.objectStore(e).get(t).onsuccess=e=>{let t=e.target.result;t?o(t):n(e)},a.onerror=e=>{n(e)}})).catch(n)}))}deleteObject(e,t){return new Promise(((o,n)=>{this.getDB().then((r=>{const a=r.transaction(e,"readwrite");a.objectStore(e).delete(t).onsuccess=e=>{o(e.target.result)},a.onerror=e=>{n(e)}})).catch(n)}))}clearStore(e){return new Promise(((t,o)=>{this.getDB().then((n=>{const r=n.transaction(e,"readwrite");r.objectStore(e).clear().onsuccess=e=>{t(e.target.result)},r.onerror=e=>{o(e)}})).catch(o)}))}deleteDB(e){return new Promise((t=>{this.indexedDB.deleteDatabase(e),t()}))}getAllKeys(e){return new Promise(((t,o)=>{this.getDB().then((n=>{const r=n.transaction(e,"readonly");r.objectStore(e).getAllKeys().onsuccess=e=>t(e.target.result),r.onerror=o})).catch(o)}))}getAll(e){return new Promise(((t,o)=>{this.getDB().then((n=>{const r=n.transaction(e,"readonly");r.objectStore(e).getAll().onsuccess=e=>t(e.target.result),r.onerror=o})).catch(o)}))}}{constructor(){super({name:"Bf_Loader",version:1,storeList:["d","t"]})}getDatabagInfo(e,t){return new Promise(((o,n)=>{t?this.getObject("d",e).then((e=>this.addTemp(e,t).then((()=>o(e))).catch(n))).catch(n):this.getObject("d",e).then(o).catch(n)}))}addDatabagInfo(e,t){return new Promise(((o,n)=>{const r=e.modelId,a=()=>Promise.all([this.addObject("d",e,r),this.addTemp(e,t)]).then(o).catch(n);this.getDatabagInfo(r).then((t=>{t.databagId!==e.databagId&&this.deleteDB(`Bf_${data.databagId}`),a()})).catch((()=>{a()}))}))}deleteDatabagInfo(e){return new Promise(((t,o)=>{this.deleteObject("d",e).then(t).catch(o)}))}addTemp(e,t){return new Promise(((o,n)=>{this.clearStore("t").then((()=>{this.addObject("t",e,t).then(o).catch(n)})).catch(n)}))}getTemp(e){return new Promise(((t,o)=>{this.getObject("t",e).then(t).catch(o)}))}deleteStorageByModelId(e){return new Promise((t=>{this.getDatabagInfo(e).then((o=>{let n="gisView"===o.renderType?`Bg_${o.modelId}`:`Bf_${o.databagId}`;Promise.allSettled([this.deleteDB(n),this.deleteDatabagInfo(e)]).then(t)})).catch(t)}))}getStoredModelIds(){return this.getAllKeys("d")}getStoredModelInfo(){return new Promise(((e,t)=>{this.getAll("d").then((t=>{let o=t.map((e=>{let{modelId:t,name:o,renderType:n}=e;return{modelId:t,name:o,type:n}}));e(o)})).catch(t)}))}}var h=function(e,t,o){if(e.metadata)return o(e.metadata);const r=n=>{if(e.enableStorage&&e.modelId){(new f).getDatabagInfo(e.modelId,e.viewToken).then((e=>o&&o(e))).catch((()=>{console.error("[BIMFACE ERROR]: failed get model info from storage"),t&&t(n)}))}else t&&t(n)};if(!e.viewToken&&"Local"!==e.dataEnvType)return void r();const a=e.dataEnvType!==n.Local,i=a&&e.securityApi;!function(e){var t,o=Object.assign({type:"get",data:null,success:null,failure:null},e);(t=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP")).onreadystatechange=function(){if(4==t.readyState){var e=t.status;e>=200&&e<300||304==e||0===e&&"file:"===window.location.protocol?o.success&&o.success(t.responseText,t.responseXML):o.failure&&o.failure(e)}},t.open(o.type,o.url,o.async),t.send(o.data)}({type:i?"post":"get",url:a&&!i?`${e.url}?viewToken=${e.viewToken}`:e.url,async:!0,data:i?e.data:void 0,requestHeader:e.requestHeader,success:function(t){var n=JSON.parse(t);if("Local"!==e.dataEnvType&&"success"!==n.code)return n.message&&console.error(`[BIMFACE ERROR]: ${n.message}`),void r(t);if(n=n.data||n,e.enableStorage){(new f).addDatabagInfo(n,e.viewToken).then((()=>o&&o(n))).catch((()=>o&&o(n)))}else o&&o(n)},failure:r})},p=function(e,t,n){h(e,n,(function(n){var r=function(e,t){let n,r=t.version;if(e.renderVersion,/\d+?\.\d+?\.\d+/.test(r)&&r.split(".")[0]>=3){window.bimfaceSdkVersion=r;const[e,t,o]=r.split(".");"6"===t&&Number(o)<143&&(r=`Bimface@${r}`)}else if("Debug"==t.build)r="Bimface",n="Application";else if(t.sdkPath)r=n="bimface";else if(t.viewType==o.DrawingView&&"drawingView"!=e.renderType){var a=e.subRenders;if(a&&0!=a.length)for(var i=0;i{if("3DView"==e.viewType){const c=document.createElement("div");c.style.width="1px",c.style.height="1px",c.style.opacity="0",c.style.position="absolute",c.style.zIndex="-1",c.style.top="0px",c.style.left="0px",document.body.appendChild(c);const u=new Glodon.Bimface.Viewer.Viewer3DConfig;u.domElement=c,u.enableStorage=!0,u.enableViewHouse=!1,u.enableCSMShadow=!1,u.enableSSAO=!1,u.enableLogarithmicDepthBuffer=!1;const f=new Glodon.Bimface.Viewer.Viewer3D(u),h=new Promise((t=>{const r=()=>{requestAnimationFrame((()=>{f.destroy(),document.body.removeChild(c),t()}))};if("true"==e.config.toBimtiles)return f.addModel(e,null,{forceLoadBIMTiles:!0}),f.getViewer().registerEventListener(CLOUD.EVENTS.ON_LOAD_PROGRESS,(function(e){var t=e.progress,o=t.loaded/t.total*100;a(o)})),void f.getViewer().registerEventListener(CLOUD.EVENTS.ON_MODEL_CACHE_COMPLETE,(function(e){r()}));f.addModel(e),d||f.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ViewLoading,(e=>a(e.progress)));let i=!1;f.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ViewAdded,(()=>{if(i)return;const e=()=>{i=!0;const e=f.getDefaultModel(),t=e.getCloudViewer().getModelManager().getModel(e.modelId),n=[...t._handler.layerProvider.getAllLayerIdxData().layerKeys],s=[...t._handler.layerProvider.getLayerKeyAttributes()];let c=0;const d={},u=()=>{if(a(Math.floor(100*(c+1)/n.length)),c===n.length)return void r();n[c].split("-").forEach(((e,t)=>d[s[t]]=e));const e=f.getDefaultModel();e&&e.destroy();const t=isNaN(l)?2e3:Number(l);setTimeout((()=>{f.addView(o)}),t),c++};f.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ModelAdded,(()=>{f.showExclusiveComponentsByObjectData([d],null,u)})),u()};n?f.loadMaterialOverrideSet(f.getModel().modelId,o,(function(){s?f.showExclusiveComponentsByObjectData(s,null,r):d?e():(f.showAllComponents(),f.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.DemandLoaded,r))})):s?f.showExclusiveComponentsByObjectData(s,null,r):d?e():r()}))}));Promise.all([h,f._storeData(t)]).then(r).catch(i)}})).catch()}},m=function(){return m=Object.assign||function(e){for(var t,o=1,n=arguments.length;o0&&r[r.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]=200&&o<300||304==o||0===o&&"file:"===window.location.protocol){var r=void 0;try{r=JSON.parse(n.responseText)}catch(e){throw e}e({json:r,responseText:n.responseText,responseXML:n.responseXML})}else t(o)}},n.open(o.type,o.url,o.async),n.send(o.data)}))).then((function(e){e.json.data?o(e.json.data):n(e.json)}))}))},e.prototype.loadScript=function(e){return new Promise((function(t,o){var n=document.createElement("script");n.setAttribute("src",e),n.onload=function(){t(!0)},n.onerror=function(e){o(e),console.error(e)},document.getElementsByTagName("head")[0].append(n)}))},e.prototype.loadCss=function(e){return new Promise((function(t,o){var n=document.createElement("link");n.setAttribute("href",e),n.setAttribute("rel","stylesheet"),n.onload=function(){t(!0)},n.onerror=function(e){o(e),console.error(e)},document.getElementsByTagName("head")[0].append(n)}))},e.prototype.getStaticMainSrc=function(e){return this._config.staticHost+"/Glodon/"+("Debug"===this._config.build?"Bimface":e)},e.prototype.loadSDKLoader=function(){var e=this;return new Promise((function(t,o){if(window.BimfaceSDKLoader)t(!0);else{var n=e._config.staticHost+"/BimfaceSDKLoader/BimfaceSDKLoader@latest-release.js";e.loadScript(n).then((function(){return t(!0)})).catch((function(){return o()}))}}))},e.prototype.loadUIComponents=function(e){var t=this;return new Promise((function(o,n){var r,a,i;if(null===(i=null===(a=null===(r=window.Glodon)||void 0===r?void 0:r.Bimface)||void 0===a?void 0:a.Tiles)||void 0===i?void 0:i.UI)return o(!0);var s=t.getStaticMainSrc(e)+"/bimface.ui.css";t.loadCss(s).then((function(){return o(!0)})).catch((function(){return n()}))}))},e}(),B=window.Glodon||{};window.Glodon=B;var T=B.Bimface=B.Bimface||{},S=T.Module=T.Module||{},E=function(){function e(e){this._loadedModule={},this._config=e,this._helper=new D(e)}return e.prototype.loadModule=function(e){return b(this,void 0,void 0,(function(){var t,o,n,r,a;return v(this,(function(i){switch(i.label){case 0:return t=new window.BimfaceSDKLoaderConfig,(t=m(m({},t),this._config)).viewToken=e.viewToken,[4,window.BimfaceSDKLoader.load(t).catch((function(e){return console.log(e)}))];case 1:return i.sent(),[4,this._helper.loadSDKLoader()];case 2:return i.sent(),[4,this._helper.getModuleData(e.viewToken)];case 3:return"moduleData"!=(o=i.sent()).modelType&&"clashDetective"!=o.modelType?[2,Promise.reject("[BIMFACE ERROR]: Invalid ViewToken, viewToken: ["+e.viewToken+"]")]:(o.viewToken=e.viewToken,n=o.jsSDKVersion,[4,this._helper.loadUIComponents(n)]);case 4:return i.sent(),this._loadedModule[e.moduleType]?[3,6]:(this._helper.loadCss(this._helper.getStaticMainSrc(n)+"/modules/"+e.moduleType+".css"),[4,import(this._helper.getStaticMainSrc(n)+"/modules/"+e.moduleType+".js")]);case 5:r=i.sent(),this._loadedModule[e.moduleType]=r.default,i.label=6;case 6:for(a in this._loadedModule[e.moduleType])this._loadedModule[e.moduleType][a].setCurrentModuleData&&this._loadedModule[e.moduleType][a].setCurrentModuleData(o);return[2,o]}}))}))},e}();S.ModuleManager=E,S.ModuleManagerConfig=y;var P={Version:"2024-10-16-16-6",load:function(e,o,r){window.BimfaceLoaderConfig=e,null==e.build&&(e.build=t.Release);var a=function(e){let o=Object.assign({},e),r="/Glodon";return e.path?(o.dataEnvType=n.Local,o.url=o.path,o.staticHost=o.sdkPath||i(o.path),o.resourcePath=i(o.path),o.path=i(o.path),r=o.sdkPath?"":"/jssdk"):e.resourcePath?(o.dataEnvType=n.Local,o.url=o.resourcePath,o.resourcePath=i(o.resourcePath)):(o.sdkPath&&(r="",o.staticHost=o.sdkPath),o.data=e.viewToken,o.url=`${e.APIHost}/inside/databag`),o.staticHost+=r,e.build!=t.Debug&&o.configuration!=t.Release||(o.configuration=""),o.configuration=o.configuration?`-${o.configuration.toLowerCase()}`:"",o}(e);if(!o&&!r)return new Promise(((t,o)=>{p(a,(function(o){t(g(o,e))}),o)}));p(a,(function(t){o&&o(g(t,e))}),(function(e){r&&r()}))},Storage:w};window.BimfaceSDKLoader=P}();