atriusmaps-node-sdk
Version:
This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information
2 lines (1 loc) • 2.95 kB
JavaScript
import{map as e,mergeDeepRight as t}from"ramda";import n from"zousan-plus";import o from"../package.json.js";import i from"./debugTools.js";import{buildEnv as a}from"./env.js";import{create as r}from"./extModules/bustle.js";import{initLog as s}from"./extModules/log.js";import l from"./utils/i18n.js";const u="undefined"!=typeof window;async function c(e,t,n){let o=t;if(o.includes("/")){const e=o.split("/");o=e[e.length-1]}return void 0!==n.active&&(!1===n.active||"notLocalhost"===n.active&&e.env.isLocalhost())?(e.log.info(`Plugin ${t} explicitly deativated`),null):import(`../plugins/${t}/src/${o}.js`).then((o=>(e.log.info(`Creating plugin ${t}`),o.create(e,n))))}async function g(e){return u?import(`./configs/${e}.json`):import(`./configs/${e}.json.js`)}async function d(e,n){let o={};const i=await Promise.all(n.map(g));for(const e of i){let n=e.default;n=n.extends?await d(n,n.extends):n,o=t(o,n)}return o=t(o,e),o}const p=e=>t=>import(`./configs/postproc-${e}.js`).then((e=>e.process(t)));async function m(t){const g=Object.create(null);let m=t.extends?await d(t,t.extends):t;m.plugins.monitoring&&await import("../_virtual/_empty_module_placeholder.js").then((e=>e.activate(m.plugins.monitoring))),m=await(async e=>e.configPostProc?n.series(e,...e.configPostProc.map(p)):e)(m);const f=(e=>{const t=e.supportedLanguages||["ar","de","en","es","fr","hi","is","it","ja","ko","pl","pt","zh-Hans","zh-Hant","el-GR","th"];if("undefined"!=typeof window){let e=new URLSearchParams(location.search).get("lang")||navigator.language;for(;e;){if(e&&t.includes(e))return e;e=e.substring(0,e.lastIndexOf("-"))}}return e.defaultLanguage||"en"})(m),h=await l(f,{debug:m.debug});g.i18n=()=>h,g.gt=()=>h.t.bind(h),g.config=m,g.plugins={};const w=s("web-engine",{enabled:!!m.debug,isBrowser:u,color:"cyan",logFilter:m.logFilter,truncateObjects:!u,trace:false});if(g.log=w.sublog(m.name),g.bus=r({showEvents:!0,reportAllErrors:!0,log:w}),g.info={wePkg:o},"undefined"!=typeof window&&(m.debug?(g.debug=e((e=>e.bind(g)),i),i.dndGo.call(g)):g.debug={},window._app=g,window.document&&window.document.title&&m.setWindowTitle&&(document.title=m.name)),g.env=a(g),m.theme?await n.evaluate({name:"ThemeManagerModule",value:import("../_virtual/_empty_module_placeholder.js")},{name:"HistoryManager",value:import("./historyManager.js")},{name:"LayerManager",value:import("../_virtual/_empty_module_placeholder.js")}).then((async({LayerManager:e,HistoryManager:t,ThemeManagerModule:n})=>{const o=n.initThemeManager(g);g.themePack=await o.buildTheme(m.theme,m.defaultTheme),e.initLayerManager(g),t.initHistoryManager(g),g.destroy=()=>e.destroy(g)})):g.destroy=()=>{},m.plugins){for(const e in m.plugins)try{const t=m.plugins[e];if(g.plugins[e])throw Error(`Duplicate plugin name "${e}"`);const n=await c(g,e,t);n&&(g.plugins[e]=n)}catch(t){w.error("Error instantiating plugin "+e),w.error(t)}for(const e in g.plugins)g.plugins[e].init()}return g}export{m as create};