!function(){"use strict";var e=window.hostConfig||{APIHost:"https://api.bimface.com",resourceHost:"https://m.bimface.com",staticHost:"https://static.bimface.com",dataEnvType:"BIMFACE"};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),n=1;n-1){r=0;var h=o.options;h.build,t.Release;var g=c(o);return s(h.staticHost,g),void d(g,n)}++r==a?n():u(e[r],i)};u(e[r],i)},l=[],u=function(e,t){if(!(l.indexOf(e.split("/").pop())>-1)){var n,o=document.getElementsByTagName("head")[0];return e.indexOf(".css")>-1?((n=document.createElement("link")).setAttribute("href",e),n.setAttribute("rel","stylesheet")):(n=document.createElement("script")).setAttribute("src",e),n.url=e,o.appendChild(n),n.addEventListener("load",(function(){l.push(this.url.split("/").pop()),t&&t({message:"success"})})),n.addEventListener("error",(function(){t&&t({element:e,message:"error"})})),n}t()};window.loadResource=d;class h 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 n=e||this._opt.name,o=t||this._opt.version||1,a=this.indexedDB.open(n,o);return new Promise(((e,t)=>{a.onsuccess=t=>{this._db=a.result,e(this._db)},a.onupgradeneeded=e=>{let t=this._db=e.target.result;(this._opt.storeList||[]).forEach((e=>!t.objectStoreNames.contains(e)&&t.createObjectStore(e)))},a.onerror=e=>{t(e)}}))}getDB(){return new Promise(((e,t)=>{this._db?e(this._db):this.open().then(e).catch(t)}))}addObject(e,t,n){return new Promise(((o,a)=>{this.getDB().then((r=>{const i=r.transaction(e,"readwrite");i.objectStore(e).put(t,n).onsuccess=e=>{o(e.target.result)},i.onerror=e=>{a(e)}})).catch(a)}))}getObject(e,t){return new Promise(((n,o)=>{this.getDB().then((a=>{const r=a.transaction(e,"readonly");r.objectStore(e).get(t).onsuccess=e=>{let t=e.target.result;t?n(t):o(e)},r.onerror=e=>{o(e)}})).catch(o)}))}deleteObject(e,t){return new Promise(((n,o)=>{this.getDB().then((a=>{const r=a.transaction(e,"readwrite");r.objectStore(e).delete(t).onsuccess=e=>{n(e.target.result)},r.onerror=e=>{o(e)}})).catch(o)}))}clearStore(e){return new Promise(((t,n)=>{this.getDB().then((o=>{const a=o.transaction(e,"readwrite");a.objectStore(e).clear().onsuccess=e=>{t(e.target.result)},a.onerror=e=>{n(e)}})).catch(n)}))}deleteDB(e){return new Promise((t=>{this.indexedDB.deleteDatabase(e),t()}))}getAllKeys(e){return new Promise(((t,n)=>{this.getDB().then((o=>{const a=o.transaction(e,"readonly");a.objectStore(e).getAllKeys().onsuccess=e=>t(e.target.result),a.onerror=n})).catch(n)}))}getAll(e){return new Promise(((t,n)=>{this.getDB().then((o=>{const a=o.transaction(e,"readonly");a.objectStore(e).getAll().onsuccess=e=>t(e.target.result),a.onerror=n})).catch(n)}))}}{constructor(){super({name:"Bf_Loader",version:1,storeList:["d","t"]})}getDatabagInfo(e,t){return new Promise(((n,o)=>{t?this.getObject("d",e).then((e=>this.addTemp(e,t).then((()=>n(e))).catch(o))).catch(o):this.getObject("d",e).then(n).catch(o)}))}addDatabagInfo(e,t){return new Promise(((n,o)=>{const a=e.modelId,r=()=>Promise.all([this.addObject("d",e,a),this.addTemp(e,t)]).then(n).catch(o);this.getDatabagInfo(a).then((t=>{t.databagId!==e.databagId&&this.deleteDB(`Bf_${data.databagId}`),r()})).catch((()=>{r()}))}))}deleteDatabagInfo(e){return new Promise(((t,n)=>{this.deleteObject("d",e).then(t).catch(n)}))}addTemp(e,t){return new Promise(((n,o)=>{this.clearStore("t").then((()=>{this.addObject("t",e,t).then(n).catch(o)})).catch(o)}))}getTemp(e){return new Promise(((t,n)=>{this.getObject("t",e).then(t).catch(n)}))}deleteStorageByModelId(e){return new Promise((t=>{this.getDatabagInfo(e).then((n=>{let o="gisView"===n.renderType?`Bg_${n.modelId}`:`Bf_${n.databagId}`;Promise.allSettled([this.deleteDB(o),this.deleteDatabagInfo(e)]).then(t)})).catch(t)}))}getStoredModelIds(){return this.getAllKeys("d")}getStoredModelInfo(){return new Promise(((e,t)=>{this.getAll("d").then((t=>{let n=t.map((e=>{let{modelId:t,name:n,renderType:o}=e;return{modelId:t,name:n,type:o}}));e(n)})).catch(t)}))}}var g=function(e,t,n){const o=o=>{if(e.enableStorage&&e.modelId){(new h).getDatabagInfo(e.modelId,e.viewToken).then((e=>n&&n(e))).catch((()=>{console.error("[BIMFACE ERROR]: failed get model info from storage"),t&&t(o)}))}else t&&t(o)};e.viewToken||"Local"===e.dataEnvType?function(e){var t,n=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?n.success&&n.success(t.responseText,t.responseXML):n.failure&&n.failure(e)}},t.open(n.type,n.url,n.async),t.send(n.data)}({url:e.url,async:!0,success:function(t){var a=JSON.parse(t);if("Local"!==e.dataEnvType&&"success"!==a.code)return a.message&&console.error(`[BIMFACE ERROR]: ${a.message}`),void o(t);if(a=a.data||a,e.enableStorage){(new h).addDatabagInfo(a,e.viewToken).then((()=>n&&n(a))).catch((()=>n&&n(a)))}else n&&n(a)},failure:o}):o()},f=function(e,t,o){g(e,o,(function(o){var a=function(e,t){let o,a=t.version;if(e.renderVersion,/\d+?\.\d+?\.\d+/.test(a)&&a.split(".")[0]>=3)a=`Bimface@${a}`;else if("Debug"==t.build)a="Bimface",o="Application";else if(t.sdkPath)a=o="bimface";else if(t.viewType==n.DrawingView&&"drawingView"!=e.renderType){var r=e.subRenders;if(r&&0!=r.length)for(var i=0;i{f(r,(function(n){t(w(n,e))}),n)}));f(r,(function(t){n&&n(w(t,e))}),(function(e){a&&a()}))},Storage:{getStorage(){return this.storage=this.storage||new h,this.storage},deleteStorageByModelId(e){return this.getStorage().deleteStorageByModelId(e)},getStoredModelIds(){return this.getStorage().getStoredModelIds()},getStoredModelInfo(){return this.getStorage().getStoredModelInfo()},store(e){let{url:t,viewToken:n,storeMaterialOverride:o,successCallback:a,progressCallback:r,errorCallback:i}=e;if(!n)return;t=t||[],a=a||function(){},r=r||function(){},i=i||function(){};const s=new BimfaceSDKLoaderConfig;s.enableStorage=!0,s.viewToken=n,BimfaceSDKLoader.load(s).then((e=>{if("3DView"==e.viewType){const s=document.createElement("div"),c=new Glodon.Bimface.Viewer.Viewer3DConfig;c.domElement=s,c.enableStorage=!0;const d=new Glodon.Bimface.Viewer.Viewer3D(c),l=new Promise((t=>{d.addModel(e),d.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ViewLoading,(e=>r(e.progress)));const a=()=>{requestAnimationFrame((()=>{d.destroy(),t()}))};d.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ViewAdded,(()=>{o?(d.loadMaterialOverrideSet(d.getModel().modelId,n,(function(){d.showAllComponents()})),d.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.DemandLoaded,a)):a()}))}));Promise.all([l,d._storeData(t)]).then(a).catch(i)}})).catch()}}};window.BimfaceSDKLoader=m}();