{"version":3,"sources":["lib/appContext/appContext.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,uCAAuC,CAAC;AAE/D,OAAO,qCAAqC,CAAC;AAC7C,OAAO,iCAAiC,CAAC;AAEzC,OAAO,wCAAwC,CAAC;AAEhD,OAAO,WAAW,CAAC;AAGnB;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;IAC/C;;;SAGK;IACL,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAIxC;IAED;;;OAGG;IACH,IAAI,UAAU,IAAI,MAAM,EAAE,CAMzB;IAED,iDAAiD;IACjD,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC,CAE/B;IAED,OAAO,CAAC,SAAS,CAgCf;IAEK,iBAAiB,IAAI,IAAI;CAGjC;AAID,eAAe,UAAU,CAAC;AAC1B,cAAc,uCAAuC,CAAC","file":"../../../lib/appContext/appContext.d.ts","sourcesContent":["import AppContext from '../../common/appContext/appContext.js';\nimport { ConsoleLogger } from '../../common/appContext/consoleLogger.js';\nimport '../../common/appContext/eventBus.js';\nimport '../../common/appContext/i18n.js';\nimport { aliasName as loggingAlias } from '../../common/appContext/logging.js';\nimport '../../common/appContext/sharedState.js';\nimport { once } from '../../common/mutexHelper.js';\nimport './i18n.js';\nimport { loadConfig } from './simpleLoader.js';\n\n/**\n * Custom element for configuring the application\n * context.\n */\nexport class LittleAppContext extends HTMLElement {\n  /**\n     *  Monitor the 'name' attribute for changes, see:\n     *     https://developer.mozilla.org/en-US/docs/Web/Web_Components/Custom_Elements\n     */\n  static get observedAttributes(): string[] {\n    return [\n      // \"config-href\"\n    ];\n  }\n\n  /**\n   * Property backed by \"config-href\" attribute,\n   * filtered to replace HOSTNAME with globalThis.location.hostname\n   */\n  get configHref(): string[] {\n    const attr = this.getAttribute('config-href');\n    if (attr) {\n      return attr.split(/,\\s*/).filter((it) => it.match(/\\S/)).map((it) => it.replace(/HOSTNAME/g, globalThis.location.hostname));\n    }\n    return [];\n  }\n\n  /** Property backed by \"main-module\" attribute */\n  get mainModule(): string {\n    return this.getAttribute('main-module');\n  }\n\n  get appCx(): Promise<AppContext> {\n    return this.bootstrap();\n  }\n\n  private bootstrap: () => Promise<AppContext> = once(\n    () => AppContext.build(\n      {\n        configHref: this.configHref,\n        loadConfig,\n      },\n    ).then(\n      (cx) => {\n        const mainMod = this.mainModule;\n        if (!mainMod) {\n          // assume the caller will load the module herself,\n          // and start the context\n          return cx;\n        }\n        let modPath = mainMod;\n        if (mainMod.startsWith('.')) {\n          // assume it's a path relative to globalThis.location.href\n          modPath = `${new URL(globalThis.location.href).pathname.replace(/\\/[^/]+$/, '')}/${mainMod}`;\n        }\n        return import(modPath).then(() => cx);\n      },\n    ).then(\n      // clear the loading shell if present\n      (cx) => {\n        const shellPromise = globalThis.littleShell\n          ? globalThis.littleShell.clear() as Promise<string>\n          : Promise.resolve('ok');\n        return shellPromise.then(() => cx);\n      },\n    ).then(\n      (cx) => cx.start().then(() => cx),\n    ),\n  );\n\n  public connectedCallback(): void {\n    this.bootstrap();\n  }\n}\n\nwindow.customElements.define('lw-app-context', LittleAppContext);\n\nexport default AppContext;\nexport * from '../../common/appContext/appContext.js';\n\nAppContext.get().then(\n  (cx) => {\n    cx.putAlias(loggingAlias, ConsoleLogger.providerName);\n  },\n);\n\n(() => {\n  const workerPath = `${new URL(import .meta.url).pathname.replace(/\\/[^/]+$/, '')}/service-worker.js`;\n  navigator.serviceWorker.register(workerPath);\n})();\n"]}