@open-pioneer/runtime 4.8.0 → 4.9.0-dev.20261002130116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +189 -173
  2. package/CustomElement.d.ts +5 -5
  3. package/CustomElement.js +1 -3
  4. package/CustomElement.js.map +1 -1
  5. package/README.md +14 -6
  6. package/Service.d.ts +2 -2
  7. package/Service.js.map +1 -1
  8. package/_virtual/source-info.js +7 -5
  9. package/_virtual/source-info.js.map +1 -1
  10. package/api.d.ts +7 -8
  11. package/app/AppInstance.js +10 -6
  12. package/app/AppInstance.js.map +1 -1
  13. package/app/gatherConfig.d.ts +13 -4
  14. package/app/gatherConfig.js +23 -12
  15. package/app/gatherConfig.js.map +1 -1
  16. package/app/logErrors.js +1 -1
  17. package/builtin-services/ApplicationContextImpl.js +7 -1
  18. package/builtin-services/ApplicationContextImpl.js.map +1 -1
  19. package/builtin-services/{ApplicationLifecycleEventService.d.ts → ApplicationLifecycleEventServiceImpl.d.ts} +1 -1
  20. package/builtin-services/{ApplicationLifecycleEventService.js → ApplicationLifecycleEventServiceImpl.js} +4 -4
  21. package/builtin-services/ApplicationLifecycleEventServiceImpl.js.map +1 -0
  22. package/builtin-services/NumberParserServiceImpl.d.ts +1 -1
  23. package/builtin-services/NumberParserServiceImpl.js +3 -3
  24. package/builtin-services/NumberParserServiceImpl.js.map +1 -1
  25. package/builtin-services/index.js +2 -2
  26. package/builtin-services/index.js.map +1 -1
  27. package/dom/index.d.ts +0 -1
  28. package/dom/index.js +1 -1
  29. package/dom/index.js.map +1 -1
  30. package/i18n/AppIntl.d.ts +1 -1
  31. package/i18n/AppIntl.js +5 -10
  32. package/i18n/AppIntl.js.map +1 -1
  33. package/i18n/PackageIntl.js +2 -5
  34. package/i18n/PackageIntl.js.map +1 -1
  35. package/metadata/ObservableBox.d.ts +1 -1
  36. package/metadata/ObservableBox.js.map +1 -1
  37. package/package.json +6 -6
  38. package/react-integration/PackageContext.d.ts +1 -1
  39. package/react-integration/PackageContext.js.map +1 -1
  40. package/react-integration/hooks.d.ts +4 -4
  41. package/react-integration/hooks.js +6 -7
  42. package/react-integration/hooks.js.map +1 -1
  43. package/service-layer/PackageRepr.d.ts +1 -1
  44. package/service-layer/PackageRepr.js +1 -1
  45. package/service-layer/PackageRepr.js.map +1 -1
  46. package/service-layer/ServiceLayer.d.ts +3 -2
  47. package/service-layer/ServiceLayer.js +4 -3
  48. package/service-layer/ServiceLayer.js.map +1 -1
  49. package/service-layer/ServiceLookup.d.ts +4 -3
  50. package/service-layer/ServiceLookup.js +3 -3
  51. package/service-layer/ServiceLookup.js.map +1 -1
  52. package/service-layer/ServiceRepr.d.ts +2 -2
  53. package/service-layer/ServiceRepr.js +7 -5
  54. package/service-layer/ServiceRepr.js.map +1 -1
  55. package/builtin-services/ApplicationLifecycleEventService.js.map +0 -1
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # @open-pioneer/runtime
2
2
 
3
3
  Implements the runtime environment for Open Pioneer Trails apps.
4
- Additionally, the package provides some services that provide useful functionalities for app development.
4
+ The package also provides services for app development.
5
5
 
6
6
  ## Quick start
7
7
 
8
8
  Import the `createCustomElement` function from this package to create your application as a Web Component:
9
9
 
10
10
  ```js
11
- // my-app/app.js
11
+ // my-app/app.ts
12
12
  import { createCustomElement } from "@open-pioneer/runtime";
13
13
  import * as appMetadata from "open-pioneer:app";
14
14
  import { AppUI } from "./AppUI";
@@ -22,7 +22,7 @@ customElements.define("my-app", Element);
22
22
  ```
23
23
 
24
24
  In this example, `Element` is a custom web component class registered as `<my-app>`.
25
- The application renders the `AppUI` (a React component) and automatically contains services, styles etc. its package dependencies.
25
+ The application renders the `AppUI` (a React component) and automatically contains the services, styles etc. of its package dependencies.
26
26
  HTML sites or JavaScript code can now instantiate the application by creating a DOM-Element:
27
27
 
28
28
  ```html
@@ -41,9 +41,9 @@ HTML sites or JavaScript code can now instantiate the application by creating a
41
41
 
42
42
  If a hard error occurs on application start, the `AppUI` cannot be rendered but an error screen is shown instead.
43
43
  The error screen shows a message to the user that an error occurred on application start.
44
- The error screen is available in english (fallback) and german.
44
+ The error screen is available in English (fallback) and German.
45
45
 
46
- If the application was started in DEV-mode, the error screen shows additional information about the error and the stack trace.
46
+ If the application was started in development mode, the error screen shows additional information about the error and the stack trace.
47
47
 
48
48
  ## Provided services
49
49
 
@@ -52,7 +52,15 @@ For details, see the API description of the respective service.
52
52
 
53
53
  ### ApplicationContext
54
54
 
55
- The ApplicationContext provides access to global application values. E.g. the web component's host element and the current locale.
55
+ The ApplicationContext provides access to global application values, e.g. the web component's host element and the root node.
56
+
57
+ ### LocaleService
58
+
59
+ The LocaleService provides the current locale and the supported message locales, and switches the locale at runtime.
60
+
61
+ ### ThemeService
62
+
63
+ The ThemeService controls the color mode and the Chakra system config of the app.
56
64
 
57
65
  ### NumberParserService
58
66
 
package/Service.d.ts CHANGED
@@ -3,8 +3,8 @@ import { PackageIntl } from "./i18n";
3
3
  /** Lifecycle hooks supported by the service interface. */
4
4
  export interface ServiceLifecycleHooks {
5
5
  /**
6
- * Destroys the component.
7
- * Should clean up all resources used by the component.
6
+ * Destroys the service.
7
+ * Should clean up all resources used by the service.
8
8
  */
9
9
  destroy?(): void;
10
10
  toString(): string;
package/Service.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Service.js","sources":["Service.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { PackageIntl } from \"./i18n\";\n\n/** Lifecycle hooks supported by the service interface. */\nexport interface ServiceLifecycleHooks {\n /**\n * Destroys the component.\n * Should clean up all resources used by the component.\n */\n destroy?(): void;\n\n /*\n * Just used so that this interface is not empty.\n * TypeScript would otherwise throw an 'no common properties' error\n * if one tries to implement this interface without providing any\n * lifecycle hooks.\n */\n toString(): string;\n}\n\nexport type Service<Interface extends {} = {}> = ServiceLifecycleHooks & Interface;\n\n/**\n * Represents metadata for an injected reference.\n */\nexport interface ReferenceMeta {\n /**\n * The unique service id of the injected service.\n */\n serviceId: string;\n}\n\n/**\n * Contains metadata about injected references.\n * The key for the reference metadata is the reference's name.\n */\nexport type ReferencesMeta<References extends {}> = {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n [referenceName in keyof References]: References[referenceName] extends any[]\n ? ReferenceMeta[]\n : ReferenceMeta;\n};\n\n/**\n * Options passed to a service's constructor.\n */\nexport type ServiceOptions<References extends {} = {}> = {\n /**\n * References to other services.\n * These are injected by the runtime and match the declared references of the service.\n */\n references: References;\n\n /**\n * Metadata about the injected references.\n * The object contains one entry for every reference injected via `references` (under the same key).\n *\n * If a single service has been injected, `referencesMeta[key]` will be of type {@link ReferenceMeta}.\n * If multiple services have been injected, an array of {@link ReferenceMeta} will be provided instead,\n * where the indices match the order in the injected references array.\n */\n referencesMeta: ReferencesMeta<References>;\n\n /**\n * Configuration properties.\n *\n * Default values are taken from the package's configuration, but these can be overridden\n * by the application.\n */\n properties: Record<string, unknown>;\n\n /**\n * A constant reference to the shared i18n object of the current package.\n *\n * @deprecated use `currentIntl` instead, which is a signal that returns the current i18n object and updates when it changes at runtime. Be aware to implement a watch for yourself\n */\n intl: PackageIntl;\n\n /**\n * A signal that returns the current i18n object of the service's package.\n *\n * The i18n object may change at runtime (for example to implement hot reloading during development,\n * or to implement language changes while the application is running).\n */\n currentIntl: ReadonlyReactive<PackageIntl>;\n};\n\n/**\n * A service constructor returns a service instance when calling `new`.\n */\nexport type ServiceConstructor<References extends {} = {}, Interface extends {} = {}> = {\n new (options: ServiceOptions<References>): Service<Interface>;\n};\n\n/**\n * A service factory is an object that has a method to create a service instance.\n * The service factory itself can also implement lifecycle hooks, which will be called by the runtime\n * when the factory is destroyed.\n */\nexport type ServiceFactory<Interface extends {} = {}> = {\n /**\n * Method to create a service instance.\n * It is directly called by the runtime after constructing the factory.\n * NOTE: the service.destroy lifecycle hook is not called by the runtime.\n */\n createService(): Interface;\n /**\n * Optional method to destroy a service instance created by this factory.\n * If provided, this method will be called by the runtime when the service instance is destroyed.\n * A factory instance exists per service, this method invocation means that the factory is no longer used by the runtime.\n */\n destroyService?(service: Interface): void;\n};\n\n/**\n * A constructor type for a service factory.\n * The service factory is an object that has a method to create a service instance,\n * this allows for more flexibility in service construction.\n */\nexport type ServiceFactoryConstructor<References extends {} = {}, Interface extends {} = {}> = {\n new (options: ServiceOptions<References>): ServiceFactory<Interface>;\n};\n\n/**\n * Symbol used to detect if a constructor function is a service factory constructor.\n */\nconst IS_SERVICE_FACTORY = Symbol(\"runtime.IS_SERVICE_FACTORY\");\nexport { IS_SERVICE_FACTORY };\n\n/**\n * A service factory constructor must be marked\n * with the `IS_SERVICE_FACTORY` symbol to be recognized by the runtime as such.\n */\nexport type MarkedServiceFactoryConstructor<\n References extends {} = {},\n Interface extends {} = {}\n> = ServiceFactoryConstructor<References, Interface> & {\n [IS_SERVICE_FACTORY]: true;\n};\n\n/**\n * Utility function to mark a constructor as a service factory constructor.\n * @param ctr normal constructor function for a service factory.\n * @returns the same constructor function, but marked with the `IS_SERVICE_FACTORY` symbol so that the runtime recognizes it as a service factory constructor.\n */\nexport function defineServiceFactory(\n ctr: ServiceFactoryConstructor\n): MarkedServiceFactoryConstructor {\n const markedCtr = ctr as MarkedServiceFactoryConstructor;\n markedCtr[IS_SERVICE_FACTORY] = true;\n return markedCtr;\n}\n"],"names":[],"mappings":"AAiIA,MAAM,kBAAA,0BAA4B,4BAA4B;AAmBvD,SAAS,qBACZ,GAAA,EAC+B;AAC/B,EAAA,MAAM,SAAA,GAAY,GAAA;AAClB,EAAA,SAAA,CAAU,kBAAkB,CAAA,GAAI,IAAA;AAChC,EAAA,OAAO,SAAA;AACX;;"}
1
+ {"version":3,"file":"Service.js","sources":["Service.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { PackageIntl } from \"./i18n\";\n\n/** Lifecycle hooks supported by the service interface. */\nexport interface ServiceLifecycleHooks {\n /**\n * Destroys the service.\n * Should clean up all resources used by the service.\n */\n destroy?(): void;\n\n /*\n * Just used so that this interface is not empty.\n * TypeScript would otherwise throw an 'no common properties' error\n * if one tries to implement this interface without providing any\n * lifecycle hooks.\n */\n toString(): string;\n}\n\nexport type Service<Interface extends {} = {}> = ServiceLifecycleHooks & Interface;\n\n/**\n * Represents metadata for an injected reference.\n */\nexport interface ReferenceMeta {\n /**\n * The unique service id of the injected service.\n */\n serviceId: string;\n}\n\n/**\n * Contains metadata about injected references.\n * The key for the reference metadata is the reference's name.\n */\nexport type ReferencesMeta<References extends {}> = {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n [referenceName in keyof References]: References[referenceName] extends any[]\n ? ReferenceMeta[]\n : ReferenceMeta;\n};\n\n/**\n * Options passed to a service's constructor.\n */\nexport type ServiceOptions<References extends {} = {}> = {\n /**\n * References to other services.\n * These are injected by the runtime and match the declared references of the service.\n */\n references: References;\n\n /**\n * Metadata about the injected references.\n * The object contains one entry for every reference injected via `references` (under the same key).\n *\n * If a single service has been injected, `referencesMeta[key]` will be of type {@link ReferenceMeta}.\n * If multiple services have been injected, an array of {@link ReferenceMeta} will be provided instead,\n * where the indices match the order in the injected references array.\n */\n referencesMeta: ReferencesMeta<References>;\n\n /**\n * Configuration properties.\n *\n * Default values are taken from the package's configuration, but these can be overridden\n * by the application.\n */\n properties: Record<string, unknown>;\n\n /**\n * A constant reference to the shared i18n object of the current package.\n *\n * @deprecated use `currentIntl` instead, which is a signal that returns the current i18n object and updates when it changes at runtime. Be aware to implement a watch for yourself\n */\n intl: PackageIntl;\n\n /**\n * A signal that returns the current i18n object of the service's package.\n *\n * The i18n object may change at runtime (for example to implement hot reloading during development,\n * or to implement language changes while the application is running).\n */\n currentIntl: ReadonlyReactive<PackageIntl>;\n};\n\n/**\n * A service constructor returns a service instance when calling `new`.\n */\nexport type ServiceConstructor<References extends {} = {}, Interface extends {} = {}> = {\n new (options: ServiceOptions<References>): Service<Interface>;\n};\n\n/**\n * A service factory is an object that has a method to create a service instance.\n * The service factory itself can also implement lifecycle hooks, which will be called by the runtime\n * when the factory is destroyed.\n */\nexport type ServiceFactory<Interface extends {} = {}> = {\n /**\n * Method to create a service instance.\n * It is directly called by the runtime after constructing the factory.\n * NOTE: the service.destroy lifecycle hook is not called by the runtime.\n */\n createService(): Interface;\n /**\n * Optional method to destroy a service instance created by this factory.\n * If provided, this method will be called by the runtime when the service instance is destroyed.\n * A factory instance exists per service, this method invocation means that the factory is no longer used by the runtime.\n */\n destroyService?(service: Interface): void;\n};\n\n/**\n * A constructor type for a service factory.\n * The service factory is an object that has a method to create a service instance,\n * this allows for more flexibility in service construction.\n */\nexport type ServiceFactoryConstructor<References extends {} = {}, Interface extends {} = {}> = {\n new (options: ServiceOptions<References>): ServiceFactory<Interface>;\n};\n\n/**\n * Symbol used to detect if a constructor function is a service factory constructor.\n */\nconst IS_SERVICE_FACTORY = Symbol(\"runtime.IS_SERVICE_FACTORY\");\nexport { IS_SERVICE_FACTORY };\n\n/**\n * A service factory constructor must be marked\n * with the `IS_SERVICE_FACTORY` symbol to be recognized by the runtime as such.\n */\nexport type MarkedServiceFactoryConstructor<\n References extends {} = {},\n Interface extends {} = {}\n> = ServiceFactoryConstructor<References, Interface> & {\n [IS_SERVICE_FACTORY]: true;\n};\n\n/**\n * Utility function to mark a constructor as a service factory constructor.\n * @param ctr normal constructor function for a service factory.\n * @returns the same constructor function, but marked with the `IS_SERVICE_FACTORY` symbol so that the runtime recognizes it as a service factory constructor.\n */\nexport function defineServiceFactory(\n ctr: ServiceFactoryConstructor\n): MarkedServiceFactoryConstructor {\n const markedCtr = ctr as MarkedServiceFactoryConstructor;\n markedCtr[IS_SERVICE_FACTORY] = true;\n return markedCtr;\n}\n"],"names":[],"mappings":"AAiIA,MAAM,kBAAA,0BAA4B,4BAA4B;AAmBvD,SAAS,qBACZ,GAAA,EAC+B;AAC/B,EAAA,MAAM,SAAA,GAAY,GAAA;AAClB,EAAA,SAAA,CAAU,kBAAkB,CAAA,GAAI,IAAA;AAChC,EAAA,OAAO,SAAA;AACX;;"}
@@ -1,12 +1,14 @@
1
- const sourceId$7 = "@open-pioneer/runtime/CustomElement";
1
+ const sourceId$8 = "@open-pioneer/runtime/CustomElement";
2
2
 
3
- const sourceId$6 = "@open-pioneer/runtime/app/AppInstance";
3
+ const sourceId$7 = "@open-pioneer/runtime/app/AppInstance";
4
4
 
5
- const sourceId$5 = "@open-pioneer/runtime/i18n/AppIntl";
5
+ const sourceId$6 = "@open-pioneer/runtime/i18n/AppIntl";
6
+
7
+ const sourceId$5 = "@open-pioneer/runtime/service-layer/ServiceRepr";
6
8
 
7
9
  const sourceId$4 = "@open-pioneer/runtime/builtin-services/ApplicationContextImpl";
8
10
 
9
- const sourceId$3 = "@open-pioneer/runtime/builtin-services/ApplicationLifecycleEventService";
11
+ const sourceId$3 = "@open-pioneer/runtime/builtin-services/ApplicationLifecycleEventServiceImpl";
10
12
 
11
13
  const sourceId$2 = "@open-pioneer/runtime/builtin-services/NumberParserServiceImpl";
12
14
 
@@ -14,5 +16,5 @@ const sourceId$1 = "@open-pioneer/runtime/service-layer/ServiceLayer";
14
16
 
15
17
  const sourceId = "@open-pioneer/runtime/app/logErrors";
16
18
 
17
- export { sourceId$5 as sourceId, sourceId$4 as sourceId$1, sourceId$3 as sourceId$2, sourceId$2 as sourceId$3, sourceId$1 as sourceId$4, sourceId as sourceId$5, sourceId$6, sourceId$7 };
19
+ export { sourceId$6 as sourceId, sourceId$5 as sourceId$1, sourceId$4 as sourceId$2, sourceId$3, sourceId$2 as sourceId$4, sourceId$1 as sourceId$5, sourceId as sourceId$6, sourceId$7, sourceId$8 };
18
20
  //# sourceMappingURL=source-info.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"source-info.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"source-info.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
package/api.d.ts CHANGED
@@ -34,7 +34,7 @@ export interface ApplicationContext extends DeclaredService<"runtime.Application
34
34
  */
35
35
  getHostElement(): HTMLElement;
36
36
  /**
37
- * A root node that resolves to the the shadow root or the site's document.
37
+ * A root node that resolves to the shadow root or the site's document.
38
38
  *
39
39
  * For example:
40
40
  *
@@ -50,7 +50,7 @@ export interface ApplicationContext extends DeclaredService<"runtime.Application
50
50
  *
51
51
  * NOTE: This method returns undefined if the application does not use a shadow root.
52
52
  *
53
- * See also {@link ApplicationConfig.disableShadowRoot} and {@link getRoot()}.
53
+ * See also {@link AdvancedCustomElementOptions.enableShadowRoot} and {@link getRoot}.
54
54
  */
55
55
  getShadowRoot(): ShadowRoot | undefined;
56
56
  /**
@@ -136,7 +136,9 @@ export interface LocaleService extends DeclaredService<"runtime.LocaleService">
136
136
  readonly supportsLiveChanges: boolean;
137
137
  /**
138
138
  * Switches to `locale`. Best-fit match against {@link supportedMessageLocales};
139
- * throws `UNSUPPORTED_LOCALE` on no match. `undefined` enables automatic picking.
139
+ * The promise rejects with the error id `runtime:unsupported-locale` on no match.
140
+ *
141
+ * Use `undefined` to pick the default locale.
140
142
  */
141
143
  changeLocale(locale: Intl.Locale | undefined): Promise<void>;
142
144
  /**
@@ -185,10 +187,7 @@ export type ColorModeValueSupplier = () => ColorModeValue;
185
187
  */
186
188
  export type ChakraSystemConfigSupplier = () => ChakraSystemConfig | undefined;
187
189
  /**
188
- * A Theme Service that provides methods to interact with the chakra theme.
189
- *
190
- * e.g. change the color mode of the application.
191
- * or update the system config of the application.
190
+ * A service that controls the color mode and the Chakra system config of the app.
192
191
  */
193
192
  export interface ThemeService extends DeclaredService<"runtime.ThemeService"> {
194
193
  /**
@@ -198,7 +197,7 @@ export interface ThemeService extends DeclaredService<"runtime.ThemeService"> {
198
197
  /**
199
198
  * The currently active color mode.
200
199
  * It is reactive.
201
- * Defaults to `"light".
200
+ * Defaults to `"light"`.
202
201
  */
203
202
  readonly colorMode: ColorModeValue;
204
203
  /**
@@ -1,6 +1,6 @@
1
1
  import { watchValue, computed, constant, reactive, effect } from '@conterra/reactivity-core';
2
2
  import { createLogger, Error, createAbortError, destroyResource, createManualPromise, throwAbortError } from '@open-pioneer/core';
3
- import { sourceId$6 as sourceId } from '../_virtual/source-info.js';
3
+ import { sourceId$7 as sourceId } from '../_virtual/source-info.js';
4
4
  import { createElement } from 'react';
5
5
  import { createBuiltinPackage, RUNTIME_THEME_SERVICE, RUNTIME_API_SERVICE, RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE, RUNTIME_LOCALE_SERVICE, RUNTIME_AUTO_START } from '../builtin-services/index.js';
6
6
  import { DEFAULT_INITIAL_COLOR_MODE } from '../builtin-services/ThemeServiceImpl.js';
@@ -70,10 +70,7 @@ class AppInstance {
70
70
  return;
71
71
  }
72
72
  if (this.#state === "started") {
73
- try {
74
- this.#triggerApplicationLifecycleEvent("before-stop");
75
- } catch (e) {
76
- }
73
+ this.#triggerApplicationLifecycleEvent("before-stop");
77
74
  }
78
75
  this.#state = "destroyed";
79
76
  this.#reset();
@@ -94,6 +91,9 @@ class AppInstance {
94
91
  if (this.#api) {
95
92
  return Promise.resolve(this.#api);
96
93
  }
94
+ if (this.#state === "destroyed" || this.#state === "error") {
95
+ return Promise.reject(createAbortError());
96
+ }
97
97
  const apiPromise = this.#apiPromise ??= createManualPromise();
98
98
  return apiPromise.promise;
99
99
  }
@@ -111,14 +111,18 @@ class AppInstance {
111
111
  const chakraSystemConfig = themeService2?.systemConfig;
112
112
  restart({ locale: locale?.baseName, colorMode, chakraSystemConfig });
113
113
  };
114
- const i18n = this.#i18n = await AppIntl.create({
114
+ const i18n = await AppIntl.create({
115
115
  appMetadata: elementOptions.appMetadata,
116
116
  forcedLocale: config.locale,
117
117
  restrictSupportedLocales: config.supportedLocales,
118
118
  supportsLiveChanges: enableLiveLocaleChanges,
119
119
  restartWithLocale
120
120
  });
121
+ if (this.#state === "destroyed") {
122
+ i18n.destroy();
123
+ }
121
124
  this.#checkAbort();
125
+ this.#i18n = i18n;
122
126
  const appRoot = this.#appRoot = createAppRoot();
123
127
  this.#localeWatch = watchValue(
124
128
  () => i18n.locale.baseName,
@@ -1 +1 @@
1
- {"version":3,"file":"AppInstance.js","sources":["AppInstance.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { SystemConfig } from \"@chakra-ui/react\";\nimport {\n computed,\n constant,\n effect,\n reactive,\n ReadonlyReactive,\n watchValue\n} from \"@conterra/reactivity-core\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { createElement } from \"react\";\nimport { ApiMethods, ApiService, ColorModeValue, ThemeService } from \"../api\";\nimport {\n createBuiltinPackage,\n RUNTIME_API_SERVICE,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n RUNTIME_AUTO_START,\n RUNTIME_LOCALE_SERVICE,\n RUNTIME_THEME_SERVICE\n} from \"../builtin-services\";\nimport { ApplicationLifecycleEventService } from \"../builtin-services/ApplicationLifecycleEventService\";\nimport { DEFAULT_INITIAL_COLOR_MODE } from \"../builtin-services/ThemeServiceImpl\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { createAppRoot, isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, createPackageIntl, getBrowserLocales, LocalePicker, parseLocale } from \"../i18n\";\nimport { PackageMetadata } from \"../metadata\";\nimport { ErrorScreen, MESSAGES_BY_LOCALE } from \"../react-integration/ErrorScreen\";\nimport { EmptyComponent, ReactIntegration } from \"../react-integration/ReactIntegration\";\nimport { ReferenceSpec } from \"../service-layer/InterfaceSpec\";\nimport { createPackages, PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { gatherConfig } from \"./gatherConfig\";\nimport { logError } from \"./logErrors\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface AppOptions {\n /** The root node that contains the application. */\n rootNode: RootNode;\n\n /** The HTML element that embeds the application. */\n hostElement: HTMLElement;\n\n /** Trails options for the application. */\n elementOptions: CustomElementOptions;\n\n /** These have higher priority than the options in `elementOptions`. */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * A callback to restart the application with new options.\n * Currently only used for reloading with a certain locale.\n */\n restart: (overrides?: ApplicationOverrides) => void;\n}\n\nexport type AppState = \"not-started\" | \"starting\" | \"started\" | \"destroyed\" | \"error\";\n\nexport class AppInstance {\n #options: AppOptions;\n\n // Public API\n #apiPromise: ManualPromise<ApiMethods> | undefined; // Present when callers are waiting for the API\n #api: ApiMethods | undefined; // Present once started\n\n #state: AppState = \"not-started\";\n #rootNode: RootNode;\n #container: HTMLElement | ShadowRoot; // parent of .pioneer-root\n #i18n: AppIntl | undefined;\n\n // Unused on purpose for easier debugging.\n // oxlint-disable-next-line no-unused-private-class-members\n #appRoot: HTMLDivElement | undefined; // .pioneer-root\n\n // Unused on purpose for easier debugging.\n // oxlint-disable-next-line no-unused-private-class-members\n #config: ApplicationConfig | undefined;\n\n #serviceLayer: ServiceLayer | undefined;\n #lifecycleEvents: ApplicationLifecycleEventService | undefined;\n #themeService: ThemeService | undefined;\n #reactIntegration: ReactIntegration | undefined;\n\n #stylesWatch: Resource | undefined;\n #localeWatch: Resource | undefined;\n\n constructor(options: AppOptions) {\n this.#options = options;\n this.#container = isShadowRoot(options.rootNode) ? options.rootNode : options.hostElement;\n this.#rootNode = options.rootNode;\n }\n\n /** Current lifecycle state. Exposed (read-only) for tests/debugging via `$inspectElementState`. */\n get state(): AppState {\n return this.#state;\n }\n\n start() {\n if (this.#state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, `Cannot start element in state '${this.#state}'`);\n }\n\n this.#state = \"starting\";\n this.#startImpl().catch((e) => {\n if (this.#state === \"destroyed\") return;\n\n logError(e);\n this.#reset();\n this.#state = \"error\";\n this.#showErrorScreen(e);\n });\n }\n\n destroy() {\n if (this.#state === \"destroyed\") {\n return;\n }\n\n // Only call event listener when 'started' was also signalled.\n if (this.#state === \"started\") {\n try {\n this.#triggerApplicationLifecycleEvent(\"before-stop\");\n } catch (e) {\n void e; // Ignored\n }\n }\n this.#state = \"destroyed\";\n this.#reset();\n }\n\n #reset() {\n this.#apiPromise?.reject(createAbortError());\n this.#reactIntegration = destroyResource(this.#reactIntegration);\n this.#container.replaceChildren();\n this.#appRoot = undefined;\n this.#lifecycleEvents = undefined;\n this.#themeService = undefined;\n this.#i18n = destroyResource(this.#i18n);\n this.#serviceLayer = destroyResource(this.#serviceLayer);\n this.#stylesWatch = destroyResource(this.#stylesWatch);\n this.#localeWatch = destroyResource(this.#localeWatch);\n }\n\n whenAPI(): Promise<ApiMethods> {\n if (this.#api) {\n return Promise.resolve(this.#api);\n }\n\n const apiPromise = (this.#apiPromise ??= createManualPromise());\n return apiPromise.promise;\n }\n\n async #startImpl() {\n const { hostElement, elementOptions, overrides } = this.#options;\n const root = this.#rootNode;\n\n // Resolve custom application config\n const config = (this.#config = await gatherConfig(hostElement, elementOptions, overrides));\n this.#checkAbort();\n LOG.debug(\"Application config is\", config);\n\n // TODO (next major): always true (option can be removed).\n // Currently false by default (needs to be enabled) to preserve backwards compatibility.\n const enableLiveLocaleChanges = elementOptions.advanced?.enableLiveLocaleChanges ?? false;\n\n // TODO (next major): Remove restarting code!\n const restartWithLocale = (locale: Intl.Locale | undefined) => {\n // this code is triggered, when the app calls changeLocale while reactive switching is disabled.\n const restart = this.#options.restart;\n const themeService = this.#themeService;\n const colorMode = themeService?.colorMode;\n const chakraSystemConfig = themeService?.systemConfig;\n restart({ locale: locale?.baseName, colorMode, chakraSystemConfig });\n };\n\n // Decide on locale and load i18n messages (if any).\n const i18n = (this.#i18n = await AppIntl.create({\n appMetadata: elementOptions.appMetadata,\n forcedLocale: config.locale,\n restrictSupportedLocales: config.supportedLocales,\n supportsLiveChanges: enableLiveLocaleChanges,\n restartWithLocale\n }));\n this.#checkAbort();\n\n // Setup application root node in the shadow dom\n const appRoot = (this.#appRoot = createAppRoot());\n this.#localeWatch = watchValue(\n () => i18n.locale.baseName,\n (locale) => {\n appRoot.lang = locale;\n },\n {\n immediate: true\n }\n );\n this.#container.appendChild(appRoot);\n\n const styles = this.#initStylesSignal();\n\n // Launch the service layer\n const { serviceLayer, packages } = this.#initServiceLayer({\n container: appRoot,\n properties: config.properties,\n i18n,\n initialColorMode: config.colorMode,\n initialSystemConfig: config.chakraSystemConfig\n });\n this.#lifecycleEvents = getInternalService<ApplicationLifecycleEventService>(\n serviceLayer,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n );\n const themeService = (this.#themeService = getInternalService<ThemeService>(\n serviceLayer,\n RUNTIME_THEME_SERVICE\n ));\n\n // init api, but do not wait for it\n const apiPromise = this.#initAPI(serviceLayer);\n this.#checkAbort();\n\n // Launch react\n this.#reactIntegration = ReactIntegration.createForApp({\n rootNode: root,\n hostNode: hostElement,\n appRoot: appRoot,\n serviceLayer,\n packages,\n locale: computed(() => i18n.locale.baseName),\n config: computed(() => themeService.systemConfig),\n styles,\n colorMode: computed(() => themeService.colorMode)\n });\n const component = this.#options.elementOptions.component ?? EmptyComponent;\n this.#reactIntegration.render(createElement(component));\n\n // wait for api, to ensure that the \"started\" state is only reached after the API is available.\n // but do not block the react rendering, to allow for a fast Time to Interactive and to show potential errors in the UI even if the API fails.\n await apiPromise;\n this.#checkAbort();\n\n this.#state = \"started\";\n\n this.#triggerApplicationLifecycleEvent(\"after-start\");\n LOG.debug(\"Application started\");\n }\n\n /**\n * Returns a signal that contains the application's styles.\n * During development, the signal is updated when the user edits .css files.\n * In production, the signal is static.\n */\n #initStylesSignal(): ReadonlyReactive<string> {\n const stylesBox = this.#options.elementOptions.appMetadata?.styles;\n if (!stylesBox) {\n return constant(\"\");\n }\n\n const signal = reactive(stylesBox.value);\n if (import.meta.hot) {\n this.#stylesWatch = effect(\n () => {\n signal.value = stylesBox.value;\n LOG.debug(\"Application styles changed\");\n },\n { dispatch: \"sync\" }\n );\n }\n return signal;\n }\n\n #initServiceLayer(config: {\n container: HTMLDivElement;\n properties: ApplicationProperties;\n i18n: AppIntl;\n initialColorMode: ColorModeValue | \"system\" | undefined;\n initialSystemConfig: SystemConfig | undefined;\n }) {\n const { hostElement, rootNode: shadowRoot, elementOptions } = this.#options;\n const { container, properties, i18n, initialColorMode, initialSystemConfig } = config;\n\n const packageMetadata = elementOptions.appMetadata?.packages ?? {};\n const builtinPackage = createBuiltinPackage({\n host: hostElement,\n rootNode: shadowRoot,\n container: container,\n initialColorMode,\n initialSystemConfig,\n appIntl: i18n\n });\n const { serviceLayer, packages } = createServiceLayer({\n packageMetadata,\n builtinPackage,\n properties,\n i18n\n });\n this.#serviceLayer = serviceLayer;\n\n if (LOG.isDebug()) {\n LOG.debug(\"Launching service layer with packages\", Object.fromEntries(packages));\n }\n serviceLayer.start();\n return { serviceLayer, packages };\n }\n\n async #initAPI(serviceLayer: ServiceLayer) {\n const apiService = getInternalService<ApiService>(serviceLayer, RUNTIME_API_SERVICE);\n try {\n const api = await apiService.getApi();\n this.#checkAbort();\n this.#api = api;\n LOG.debug(\"Application API initialized to\", api);\n this.#apiPromise?.resolve(api);\n } catch (e) {\n const ex = new Error(\n ErrorId.INTERNAL,\n \"Failed to gather the application's API methods.\",\n {\n cause: e\n }\n );\n if (!this.#apiPromise) {\n // no one is waiting yet.\n // keep the error for when they do\n this.#apiPromise = createManualPromise();\n // prevent unhandled rejection if no one is waiting for the API\n this.#apiPromise.promise.catch(() => {});\n }\n this.#apiPromise.reject(ex);\n throw ex;\n }\n }\n\n #triggerApplicationLifecycleEvent(event: \"after-start\" | \"before-stop\") {\n this.#lifecycleEvents?.emitLifecycleEvent(event);\n }\n\n #checkAbort() {\n if (this.#state === \"destroyed\") {\n throwAbortError();\n }\n }\n\n #showErrorScreen(error: globalThis.Error) {\n const userLocales = getBrowserLocales();\n const localePicker = new LocalePicker(\n Object.keys(MESSAGES_BY_LOCALE).map((tag) => parseLocale(tag))\n );\n const { locale, messageLocale } = localePicker.pickSupportedLocale(undefined, userLocales);\n const messages =\n MESSAGES_BY_LOCALE[messageLocale.baseName as keyof typeof MESSAGES_BY_LOCALE] ??\n MESSAGES_BY_LOCALE[\"en\"];\n const intl = createPackageIntl(locale.baseName, messages);\n\n const appRoot = (this.#appRoot = createAppRoot());\n appRoot.lang = locale.baseName;\n appRoot.classList.add(\"pioneer-root-error-screen\");\n this.#container.appendChild(appRoot);\n\n const styles = this.#initStylesSignal();\n\n this.#reactIntegration = ReactIntegration.createForErrorScreen({\n rootNode: this.#rootNode,\n hostNode: this.#options.hostElement,\n appRoot: appRoot,\n locale: constant(locale.baseName),\n config: constant(this.#options.elementOptions.chakraSystemConfig),\n styles,\n colorMode: constant(DEFAULT_INITIAL_COLOR_MODE)\n });\n this.#reactIntegration.render(createElement(ErrorScreen, { intl, error }));\n }\n}\n\nfunction createServiceLayer(config: {\n packageMetadata: Record<string, PackageMetadata> | undefined;\n properties: ApplicationProperties;\n builtinPackage: PackageRepr;\n i18n: AppIntl;\n}) {\n const { packageMetadata, properties, builtinPackage, i18n } = config;\n\n let packages: PackageRepr[];\n try {\n packages = createPackages(packageMetadata ?? {}, i18n, properties);\n } catch (e) {\n throw new Error(ErrorId.INVALID_METADATA, \"Failed to parse package metadata.\", {\n cause: e\n });\n }\n\n // Add builtin services defined within this package.\n {\n const index = packages.findIndex((pkg) => pkg.name === builtinPackage.name);\n if (index >= 0) {\n packages.splice(index, 1);\n }\n packages.push(builtinPackage);\n }\n\n // Automatically required references (-> forces services to start)\n const forcedReferences: ReferenceSpec[] = [\n {\n interfaceName: RUNTIME_API_SERVICE\n },\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n },\n {\n interfaceName: RUNTIME_LOCALE_SERVICE\n },\n {\n interfaceName: RUNTIME_THEME_SERVICE\n },\n {\n interfaceName: RUNTIME_AUTO_START,\n all: true\n }\n ];\n const serviceLayer = new ServiceLayer(packages, forcedReferences);\n return {\n packages: new Map(packages.map((pkg) => [pkg.name, pkg])),\n serviceLayer: serviceLayer\n };\n}\n\nfunction getInternalService<T = unknown>(serviceLayer: ServiceLayer, interfaceName: string) {\n const result = serviceLayer.getService(\n \"@open-pioneer/runtime\",\n {\n interfaceName\n },\n { ignoreDeclarationCheck: true }\n );\n if (result.type !== \"found\") {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find instance of '${interfaceName}' (result type '${result.type}').` +\n ` This is a builtin service that must be present exactly once.`\n );\n }\n\n return result.value.getInstanceOrThrow() as T;\n}\n"],"names":["themeService"],"mappings":";;;;;;;;;;;;;;;;;;;AAqDA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAwB1B,MAAM,WAAA,CAAY;AAAA,EACrB,QAAA;AAAA;AAAA,EAGA,WAAA;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EAEA,MAAA,GAAmB,aAAA;AAAA,EACnB,SAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA,KAAA;AAAA;AAAA;AAAA,EAIA,QAAA;AAAA;AAAA;AAAA;AAAA,EAIA,OAAA;AAAA,EAEA,aAAA;AAAA,EACA,gBAAA;AAAA,EACA,aAAA;AAAA,EACA,iBAAA;AAAA,EAEA,YAAA;AAAA,EACA,YAAA;AAAA,EAEA,YAAY,OAAA,EAAqB;AAC7B,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAChB,IAAA,IAAA,CAAK,aAAa,YAAA,CAAa,OAAA,CAAQ,QAA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A,GACJ;AACJ;AAEA,SAAS,kBAAA,CAAgC,cAA4B,aAAA,EAAuB;AACxF,EAAA,MAAM,SAAS,YAAA,CAAa,UAAA;AAAA,IACxB,uBAAA;AAAA,IACA;AAAA,MACI;AAAA,KACJ;AAAA,IACA,EAAE,wBAAwB,IAAA;AAAK,GACnC;AACA,EAAA,IAAI,MAAA,CAAO,SAAS,OAAA,EAAS;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,CAAA,4BAAA,EAA+B,aAAa,CAAA,gBAAA,EAAmB,MAAA,CAAO,IAAI,CAAA,gEAAA;AAAA,KAE9E;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA,CAAO,MAAM,kBAAA,EAAmB;AAC3C;;"}
1
+ {"version":3,"file":"AppInstance.js","sources":["AppInstance.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { SystemConfig } from \"@chakra-ui/react\";\nimport {\n computed,\n constant,\n effect,\n reactive,\n ReadonlyReactive,\n watchValue\n} from \"@conterra/reactivity-core\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { createElement } from \"react\";\nimport { ApiMethods, ApiService, ColorModeValue, ThemeService } from \"../api\";\nimport {\n createBuiltinPackage,\n RUNTIME_API_SERVICE,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n RUNTIME_AUTO_START,\n RUNTIME_LOCALE_SERVICE,\n RUNTIME_THEME_SERVICE\n} from \"../builtin-services\";\nimport { ApplicationLifecycleEventServiceImpl } from \"../builtin-services/ApplicationLifecycleEventServiceImpl\";\nimport { DEFAULT_INITIAL_COLOR_MODE } from \"../builtin-services/ThemeServiceImpl\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { createAppRoot, isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, createPackageIntl, getBrowserLocales, LocalePicker, parseLocale } from \"../i18n\";\nimport { PackageMetadata } from \"../metadata\";\nimport { ErrorScreen, MESSAGES_BY_LOCALE } from \"../react-integration/ErrorScreen\";\nimport { EmptyComponent, ReactIntegration } from \"../react-integration/ReactIntegration\";\nimport { ReferenceSpec } from \"../service-layer/InterfaceSpec\";\nimport { createPackages, PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { gatherConfig } from \"./gatherConfig\";\nimport { logError } from \"./logErrors\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface AppOptions {\n /** The root node that contains the application. */\n rootNode: RootNode;\n\n /** The HTML element that embeds the application. */\n hostElement: HTMLElement;\n\n /** Trails options for the application. */\n elementOptions: CustomElementOptions;\n\n /** These have higher priority than the options in `elementOptions`. */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * A callback to restart the application with new options.\n * Currently only used for reloading with a certain locale.\n */\n restart: (overrides?: ApplicationOverrides) => void;\n}\n\nexport type AppState = \"not-started\" | \"starting\" | \"started\" | \"destroyed\" | \"error\";\n\nexport class AppInstance {\n #options: AppOptions;\n\n // Public API\n #apiPromise: ManualPromise<ApiMethods> | undefined; // Present when callers are waiting for the API\n #api: ApiMethods | undefined; // Present once started\n\n #state: AppState = \"not-started\";\n #rootNode: RootNode;\n #container: HTMLElement | ShadowRoot; // parent of .pioneer-root\n #i18n: AppIntl | undefined;\n\n // Unused on purpose for easier debugging.\n // oxlint-disable-next-line no-unused-private-class-members\n #appRoot: HTMLDivElement | undefined; // .pioneer-root\n\n // Unused on purpose for easier debugging.\n // oxlint-disable-next-line no-unused-private-class-members\n #config: ApplicationConfig | undefined;\n\n #serviceLayer: ServiceLayer | undefined;\n #lifecycleEvents: ApplicationLifecycleEventServiceImpl | undefined;\n #themeService: ThemeService | undefined;\n #reactIntegration: ReactIntegration | undefined;\n\n #stylesWatch: Resource | undefined;\n #localeWatch: Resource | undefined;\n\n constructor(options: AppOptions) {\n this.#options = options;\n this.#container = isShadowRoot(options.rootNode) ? options.rootNode : options.hostElement;\n this.#rootNode = options.rootNode;\n }\n\n /** Current lifecycle state. Exposed (read-only) for tests/debugging via `$inspectElementState`. */\n get state(): AppState {\n return this.#state;\n }\n\n start() {\n if (this.#state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, `Cannot start element in state '${this.#state}'`);\n }\n\n this.#state = \"starting\";\n this.#startImpl().catch((e) => {\n if (this.#state === \"destroyed\") return;\n\n logError(e);\n this.#reset();\n this.#state = \"error\";\n this.#showErrorScreen(e);\n });\n }\n\n destroy() {\n if (this.#state === \"destroyed\") {\n return;\n }\n\n // Only call event listener when 'started' was also signalled.\n if (this.#state === \"started\") {\n this.#triggerApplicationLifecycleEvent(\"before-stop\");\n }\n this.#state = \"destroyed\";\n this.#reset();\n }\n\n #reset() {\n this.#apiPromise?.reject(createAbortError());\n this.#reactIntegration = destroyResource(this.#reactIntegration);\n this.#container.replaceChildren();\n this.#appRoot = undefined;\n this.#lifecycleEvents = undefined;\n this.#themeService = undefined;\n this.#i18n = destroyResource(this.#i18n);\n this.#serviceLayer = destroyResource(this.#serviceLayer);\n this.#stylesWatch = destroyResource(this.#stylesWatch);\n this.#localeWatch = destroyResource(this.#localeWatch);\n }\n\n whenAPI(): Promise<ApiMethods> {\n if (this.#api) {\n return Promise.resolve(this.#api);\n }\n if (this.#state === \"destroyed\" || this.#state === \"error\") {\n // The API will never become available. Callers that were already waiting\n // have been rejected with the same error in #reset().\n return Promise.reject(createAbortError());\n }\n\n const apiPromise = (this.#apiPromise ??= createManualPromise());\n return apiPromise.promise;\n }\n\n async #startImpl() {\n const { hostElement, elementOptions, overrides } = this.#options;\n const root = this.#rootNode;\n\n // Resolve custom application config\n const config = (this.#config = await gatherConfig(hostElement, elementOptions, overrides));\n this.#checkAbort();\n LOG.debug(\"Application config is\", config);\n\n // TODO (next major): always true (option can be removed).\n // Currently false by default (needs to be enabled) to preserve backwards compatibility.\n const enableLiveLocaleChanges = elementOptions.advanced?.enableLiveLocaleChanges ?? false;\n\n // TODO (next major): Remove restarting code!\n const restartWithLocale = (locale: Intl.Locale | undefined) => {\n // this code is triggered, when the app calls changeLocale while reactive switching is disabled.\n const restart = this.#options.restart;\n const themeService = this.#themeService;\n const colorMode = themeService?.colorMode;\n const chakraSystemConfig = themeService?.systemConfig;\n restart({ locale: locale?.baseName, colorMode, chakraSystemConfig });\n };\n\n // Decide on locale and load i18n messages (if any).\n const i18n = await AppIntl.create({\n appMetadata: elementOptions.appMetadata,\n forcedLocale: config.locale,\n restrictSupportedLocales: config.supportedLocales,\n supportsLiveChanges: enableLiveLocaleChanges,\n restartWithLocale\n });\n if (this.#state === \"destroyed\") {\n i18n.destroy();\n }\n this.#checkAbort();\n this.#i18n = i18n;\n\n // Setup application root node in the shadow dom\n const appRoot = (this.#appRoot = createAppRoot());\n this.#localeWatch = watchValue(\n () => i18n.locale.baseName,\n (locale) => {\n appRoot.lang = locale;\n },\n {\n immediate: true\n }\n );\n this.#container.appendChild(appRoot);\n\n const styles = this.#initStylesSignal();\n\n // Launch the service layer\n const { serviceLayer, packages } = this.#initServiceLayer({\n container: appRoot,\n properties: config.properties,\n i18n,\n initialColorMode: config.colorMode,\n initialSystemConfig: config.chakraSystemConfig\n });\n this.#lifecycleEvents = getInternalService<ApplicationLifecycleEventServiceImpl>(\n serviceLayer,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n );\n const themeService = (this.#themeService = getInternalService<ThemeService>(\n serviceLayer,\n RUNTIME_THEME_SERVICE\n ));\n\n // init api, but do not wait for it\n const apiPromise = this.#initAPI(serviceLayer);\n this.#checkAbort();\n\n // Launch react\n this.#reactIntegration = ReactIntegration.createForApp({\n rootNode: root,\n hostNode: hostElement,\n appRoot: appRoot,\n serviceLayer,\n packages,\n locale: computed(() => i18n.locale.baseName),\n config: computed(() => themeService.systemConfig),\n styles,\n colorMode: computed(() => themeService.colorMode)\n });\n const component = this.#options.elementOptions.component ?? EmptyComponent;\n this.#reactIntegration.render(createElement(component));\n\n // wait for api, to ensure that the \"started\" state is only reached after the API is available.\n // but do not block the react rendering, to allow for a fast Time to Interactive and to show potential errors in the UI even if the API fails.\n await apiPromise;\n this.#checkAbort();\n\n this.#state = \"started\";\n\n this.#triggerApplicationLifecycleEvent(\"after-start\");\n LOG.debug(\"Application started\");\n }\n\n /**\n * Returns a signal that contains the application's styles.\n * During development, the signal is updated when the user edits .css files.\n * In production, the signal is static.\n */\n #initStylesSignal(): ReadonlyReactive<string> {\n const stylesBox = this.#options.elementOptions.appMetadata?.styles;\n if (!stylesBox) {\n return constant(\"\");\n }\n\n const signal = reactive(stylesBox.value);\n if (import.meta.hot) {\n this.#stylesWatch = effect(\n () => {\n signal.value = stylesBox.value;\n LOG.debug(\"Application styles changed\");\n },\n { dispatch: \"sync\" }\n );\n }\n return signal;\n }\n\n #initServiceLayer(config: {\n container: HTMLDivElement;\n properties: ApplicationProperties;\n i18n: AppIntl;\n initialColorMode: ColorModeValue | \"system\" | undefined;\n initialSystemConfig: SystemConfig | undefined;\n }) {\n const { hostElement, rootNode: shadowRoot, elementOptions } = this.#options;\n const { container, properties, i18n, initialColorMode, initialSystemConfig } = config;\n\n const packageMetadata = elementOptions.appMetadata?.packages ?? {};\n const builtinPackage = createBuiltinPackage({\n host: hostElement,\n rootNode: shadowRoot,\n container: container,\n initialColorMode,\n initialSystemConfig,\n appIntl: i18n\n });\n const { serviceLayer, packages } = createServiceLayer({\n packageMetadata,\n builtinPackage,\n properties,\n i18n\n });\n this.#serviceLayer = serviceLayer;\n\n if (LOG.isDebug()) {\n LOG.debug(\"Launching service layer with packages\", Object.fromEntries(packages));\n }\n serviceLayer.start();\n return { serviceLayer, packages };\n }\n\n async #initAPI(serviceLayer: ServiceLayer) {\n const apiService = getInternalService<ApiService>(serviceLayer, RUNTIME_API_SERVICE);\n try {\n const api = await apiService.getApi();\n this.#checkAbort();\n this.#api = api;\n LOG.debug(\"Application API initialized to\", api);\n this.#apiPromise?.resolve(api);\n } catch (e) {\n const ex = new Error(\n ErrorId.INTERNAL,\n \"Failed to gather the application's API methods.\",\n {\n cause: e\n }\n );\n if (!this.#apiPromise) {\n // no one is waiting yet.\n // keep the error for when they do\n this.#apiPromise = createManualPromise();\n // prevent unhandled rejection if no one is waiting for the API\n this.#apiPromise.promise.catch(() => {});\n }\n this.#apiPromise.reject(ex);\n throw ex;\n }\n }\n\n #triggerApplicationLifecycleEvent(event: \"after-start\" | \"before-stop\") {\n this.#lifecycleEvents?.emitLifecycleEvent(event);\n }\n\n #checkAbort() {\n if (this.#state === \"destroyed\") {\n throwAbortError();\n }\n }\n\n #showErrorScreen(error: globalThis.Error) {\n const userLocales = getBrowserLocales();\n const localePicker = new LocalePicker(\n Object.keys(MESSAGES_BY_LOCALE).map((tag) => parseLocale(tag))\n );\n const { locale, messageLocale } = localePicker.pickSupportedLocale(undefined, userLocales);\n const messages =\n MESSAGES_BY_LOCALE[messageLocale.baseName as keyof typeof MESSAGES_BY_LOCALE] ??\n MESSAGES_BY_LOCALE[\"en\"];\n const intl = createPackageIntl(locale.baseName, messages);\n\n const appRoot = (this.#appRoot = createAppRoot());\n appRoot.lang = locale.baseName;\n appRoot.classList.add(\"pioneer-root-error-screen\");\n this.#container.appendChild(appRoot);\n\n const styles = this.#initStylesSignal();\n\n this.#reactIntegration = ReactIntegration.createForErrorScreen({\n rootNode: this.#rootNode,\n hostNode: this.#options.hostElement,\n appRoot: appRoot,\n locale: constant(locale.baseName),\n config: constant(this.#options.elementOptions.chakraSystemConfig),\n styles,\n colorMode: constant(DEFAULT_INITIAL_COLOR_MODE)\n });\n this.#reactIntegration.render(createElement(ErrorScreen, { intl, error }));\n }\n}\n\nfunction createServiceLayer(config: {\n packageMetadata: Record<string, PackageMetadata> | undefined;\n properties: ApplicationProperties;\n builtinPackage: PackageRepr;\n i18n: AppIntl;\n}) {\n const { packageMetadata, properties, builtinPackage, i18n } = config;\n\n let packages: PackageRepr[];\n try {\n packages = createPackages(packageMetadata ?? {}, i18n, properties);\n } catch (e) {\n throw new Error(ErrorId.INVALID_METADATA, \"Failed to parse package metadata.\", {\n cause: e\n });\n }\n\n // Add builtin services defined within this package.\n {\n const index = packages.findIndex((pkg) => pkg.name === builtinPackage.name);\n if (index >= 0) {\n packages.splice(index, 1);\n }\n packages.push(builtinPackage);\n }\n\n // Automatically required references (-> forces services to start)\n const forcedReferences: ReferenceSpec[] = [\n {\n interfaceName: RUNTIME_API_SERVICE\n },\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n },\n {\n interfaceName: RUNTIME_LOCALE_SERVICE\n },\n {\n interfaceName: RUNTIME_THEME_SERVICE\n },\n {\n interfaceName: RUNTIME_AUTO_START,\n all: true\n }\n ];\n const serviceLayer = new ServiceLayer(packages, forcedReferences);\n return {\n packages: new Map(packages.map((pkg) => [pkg.name, pkg])),\n serviceLayer: serviceLayer\n };\n}\n\nfunction getInternalService<T = unknown>(serviceLayer: ServiceLayer, interfaceName: string) {\n const result = serviceLayer.getService(\n \"@open-pioneer/runtime\",\n {\n interfaceName\n },\n { ignoreDeclarationCheck: true }\n );\n if (result.type !== \"found\") {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find instance of '${interfaceName}' (result type '${result.type}').` +\n ` This is a builtin service that must be present exactly once.`\n );\n }\n\n return result.value.getInstanceOrThrow() as T;\n}\n"],"names":["themeService"],"mappings":";;;;;;;;;;;;;;;;;;;AAqDA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAwB1B,MAAM,WAAA,CAAY;AAAA,EACrB,QAAA;AAAA;AAAA,EAGA,WAAA;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EAEA,MAAA,GAAmB,aAAA;AAAA,EACnB,SAAA;AA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cAAc,CAAA;AAAA,EAChC;AAGA,EAAA,MAAM,gBAAA,GAAoC;AAAA,IACtC;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe,kBAAA;AAAA,MACf,GAAA,EAAK;AAAA;AACT,GACJ;AACA,EAAA,MAAM,YAAA,GAAe,IAAI,YAAA,CAAa,QAAA,EAAU,gBAAgB,CAAA;AAChE,EAAA,OAAO;AAAA,IACH,QAAA,EAAU,IAAI,GAAA,CAAI,QAAA,CAAS,GAAA,CAAI,CAAC,GAAA,KAAQ,CAAC,GAAA,CAAI,IAAA,EAAM,GAAG,CAAC,CAAC,CAAA;AAAA,IACxD;AAAA,GACJ;AACJ;AAEA,SAAS,kBAAA,CAAgC,cAA4B,aAAA,EAAuB;AACxF,EAAA,MAAM,SAAS,YAAA,CAAa,UAAA;AAAA,IACxB,uBAAA;AAAA,IACA;AAAA,MACI;AAAA,KACJ;AAAA,IACA,EAAE,wBAAwB,IAAA;AAAK,GACnC;AACA,EAAA,IAAI,MAAA,CAAO,SAAS,OAAA,EAAS;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,CAAA,4BAAA,EAA+B,aAAa,CAAA,gBAAA,EAAmB,MAAA,CAAO,IAAI,CAAA,gEAAA;AAAA,KAE9E;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA,CAAO,MAAM,kBAAA,EAAmB;AAC3C;;"}
@@ -1,6 +1,15 @@
1
- import { ApplicationConfig, ApplicationOverrides, CustomElementOptions } from "../CustomElement";
1
+ import { ApplicationConfig, ApplicationOverrides, ApplicationProperties, CustomElementOptions } from "../CustomElement";
2
2
  /**
3
- * Gathers application properties by reading them from the options object
4
- * and by (optionally) invoking the `resolveProperties` hook.
3
+ * Gathers the application config by reading it from the options object
4
+ * and by (optionally) invoking the `resolveConfig` hook.
5
5
  */
6
- export declare function gatherConfig(hostElement: HTMLElement, options: CustomElementOptions, overrides?: ApplicationOverrides): Promise<Required<ApplicationConfig>>;
6
+ export declare function gatherConfig(hostElement: HTMLElement, options: CustomElementOptions, overrides?: ApplicationOverrides): Promise<ResolvedApplicationConfig>;
7
+ /**
8
+ * The application config after merging all sources.
9
+ * Every key is present, but values might be `undefined`.
10
+ */
11
+ export type ResolvedApplicationConfig = {
12
+ [K in keyof Required<ApplicationConfig>]: ApplicationConfig[K] | undefined;
13
+ } & {
14
+ properties: ApplicationProperties;
15
+ };
@@ -22,7 +22,7 @@ async function gatherConfig(hostElement, options, overrides) {
22
22
  } catch (e) {
23
23
  throw new Error(
24
24
  ErrorId.CONFIG_RESOLUTION_FAILED,
25
- "Failed to resolve application properties.",
25
+ "Failed to resolve the application config.",
26
26
  {
27
27
  cause: e
28
28
  }
@@ -43,17 +43,28 @@ async function gatherConfig(hostElement, options, overrides) {
43
43
  return merged;
44
44
  }
45
45
  function mergeConfigs(configs) {
46
- const mergedConfig = Object.assign(
47
- {
48
- locale: void 0,
49
- supportedLocales: void 0,
50
- chakraSystemConfig: void 0,
51
- colorMode: void 0,
52
- properties: {}
53
- },
54
- ...configs
55
- );
56
- const mergedProperties = mergedConfig.properties = {};
46
+ const mergedConfig = {
47
+ locale: void 0,
48
+ supportedLocales: void 0,
49
+ chakraSystemConfig: void 0,
50
+ colorMode: void 0,
51
+ properties: {}
52
+ };
53
+ for (const config of configs) {
54
+ if (config.locale !== void 0) {
55
+ mergedConfig.locale = config.locale;
56
+ }
57
+ if (config.supportedLocales !== void 0) {
58
+ mergedConfig.supportedLocales = config.supportedLocales;
59
+ }
60
+ if (config.chakraSystemConfig !== void 0) {
61
+ mergedConfig.chakraSystemConfig = config.chakraSystemConfig;
62
+ }
63
+ if (config.colorMode !== void 0) {
64
+ mergedConfig.colorMode = config.colorMode;
65
+ }
66
+ }
67
+ const mergedProperties = mergedConfig.properties;
57
68
  for (const config of configs) {
58
69
  for (const [packageName, packageProperties] of Object.entries(config.properties ?? {})) {
59
70
  const mergedPackageProps = mergedProperties[packageName] ??= {};
@@ -1 +1 @@
1
- {"version":3,"file":"gatherConfig.js","sources":["gatherConfig.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Error } from \"@open-pioneer/core\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\n\n/**\n * Gathers application properties by reading them from the options object\n * and by (optionally) invoking the `resolveProperties` hook.\n */\nexport async function gatherConfig(\n hostElement: HTMLElement,\n options: CustomElementOptions,\n overrides?: ApplicationOverrides\n): Promise<Required<ApplicationConfig>> {\n let configs: ApplicationConfig[];\n try {\n const staticConfig = options.config ?? {};\n const dynamicConfig =\n (await options.resolveConfig?.({\n hostElement,\n getAttribute(name) {\n return hostElement.getAttribute(name) ?? undefined;\n },\n overrides\n })) ?? {};\n\n configs = [\n {\n chakraSystemConfig: options.chakraSystemConfig\n },\n staticConfig,\n dynamicConfig\n ];\n } catch (e) {\n throw new Error(\n ErrorId.CONFIG_RESOLUTION_FAILED,\n \"Failed to resolve application properties.\",\n {\n cause: e\n }\n );\n }\n\n const merged = mergeConfigs(configs);\n if (overrides) {\n if (overrides.locale) {\n merged.locale = overrides.locale;\n }\n if (overrides.colorMode) {\n merged.colorMode = overrides.colorMode;\n }\n if (overrides.chakraSystemConfig) {\n merged.chakraSystemConfig = overrides.chakraSystemConfig;\n }\n }\n\n return merged;\n}\n\n/**\n * Merges application configurations into a single object.\n * Properties / config parameters at a later position overwrite properties from earlier ones.\n */\nfunction mergeConfigs(configs: ApplicationConfig[]): Required<ApplicationConfig> {\n // Merge simple values by assigning them in order\n const mergedConfig: Required<ApplicationConfig> = Object.assign(\n {\n locale: undefined,\n supportedLocales: undefined,\n chakraSystemConfig: undefined,\n colorMode: undefined,\n properties: {}\n } satisfies ApplicationConfig,\n ...configs\n );\n\n // Deep merge for application properties\n const mergedProperties: ApplicationProperties = (mergedConfig.properties = {});\n for (const config of configs) {\n for (const [packageName, packageProperties] of Object.entries(config.properties ?? {})) {\n const mergedPackageProps = (mergedProperties[packageName] ??= {});\n Object.assign(mergedPackageProps, packageProperties);\n }\n }\n\n return mergedConfig;\n}\n"],"names":[],"mappings":";;;AAgBA,eAAsB,YAAA,CAClB,WAAA,EACA,OAAA,EACA,SAAA,EACoC;AACpC,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACA,IAAA,MAAM,YAAA,GAAe,OAAA,CAAQ,MAAA,IAAU,EAAC;AACxC,IAAA,MAAM,aAAA,GACD,MAAM,OAAA,CAAQ,aAAA,GAAgB;AAAA,MAC3B,WAAA;AAAA,MACA,aAAa,IAAA,EAAM;AACf,QAAA,OAAO,WAAA,CAAY,YAAA,CAAa,IAAI,CAAA,IAAK,KAAA,CAAA;AAAA,MAC7C,CAAA;AAAA,MACA;AAAA,KACH,KAAM,EAAC;AAEZ,IAAA,OAAA,GAAU;AAAA,MACN;AAAA,QACI,oBAAoB,OAAA,CAAQ;AAAA,OAChC;AAAA,MACA,YAAA;AAAA,MACA;AAAA,KACJ;AAAA,EACJ,SAAS,CAAA,EAAG;AACR,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,wBAAA;AAAA,MACR,2CAAA;AAAA,MACA;AAAA,QACI,KAAA,EAAO;AAAA;AACX,KACJ;AAAA,EACJ;AAEA,EAAA,MAAM,MAAA,GAAS,aAAa,OAAO,CAAA;AACnC,EAAA,IAAI,SAAA,EAAW;AACX,IAAA,IAAI,UAAU,MAAA,EAAQ;AAClB,MAAA,MAAA,CAAO,SAAS,SAAA,CAAU,MAAA;AAAA,IAC9B;AACA,IAAA,IAAI,UAAU,SAAA,EAAW;AACrB,MAAA,MAAA,CAAO,YAAY,SAAA,CAAU,SAAA;AAAA,IACjC;AACA,IAAA,IAAI,UAAU,kBAAA,EAAoB;AAC9B,MAAA,MAAA,CAAO,qBAAqB,SAAA,CAAU,kBAAA;AAAA,IAC1C;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA;AACX;AAMA,SAAS,aAAa,OAAA,EAA2D;AAE7E,EAAA,MAAM,eAA4C,MAAA,CAAO,MAAA;AAAA,IACrD;AAAA,MACI,MAAA,EAAQ,MAAA;AAAA,MACR,gBAAA,EAAkB,MAAA;AAAA,MAClB,kBAAA,EAAoB,MAAA;AAAA,MACpB,SAAA,EAAW,MAAA;AAAA,MACX,YAAY;AAAC,KACjB;AAAA,IACA,GAAG;AAAA,GACP;AAGA,EAAA,MAAM,gBAAA,GAA2C,YAAA,CAAa,UAAA,GAAa,EAAC;AAC5E,EAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC1B,IAAA,KAAA,MAAW,CAAC,WAAA,EAAa,iBAAiB,CAAA,IAAK,MAAA,CAAO,QAAQ,MAAA,CAAO,UAAA,IAAc,EAAE,CAAA,EAAG;AACpF,MAAA,MAAM,kBAAA,GAAsB,gBAAA,CAAiB,WAAW,CAAA,KAAM,EAAC;AAC/D,MAAA,MAAA,CAAO,MAAA,CAAO,oBAAoB,iBAAiB,CAAA;AAAA,IACvD;AAAA,EACJ;AAEA,EAAA,OAAO,YAAA;AACX;;"}
1
+ {"version":3,"file":"gatherConfig.js","sources":["gatherConfig.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Error } from \"@open-pioneer/core\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\n\n/**\n * Gathers the application config by reading it from the options object\n * and by (optionally) invoking the `resolveConfig` hook.\n */\nexport async function gatherConfig(\n hostElement: HTMLElement,\n options: CustomElementOptions,\n overrides?: ApplicationOverrides\n): Promise<ResolvedApplicationConfig> {\n let configs: ApplicationConfig[];\n try {\n const staticConfig = options.config ?? {};\n const dynamicConfig =\n (await options.resolveConfig?.({\n hostElement,\n getAttribute(name) {\n return hostElement.getAttribute(name) ?? undefined;\n },\n overrides\n })) ?? {};\n\n configs = [\n {\n chakraSystemConfig: options.chakraSystemConfig\n },\n staticConfig,\n dynamicConfig\n ];\n } catch (e) {\n throw new Error(\n ErrorId.CONFIG_RESOLUTION_FAILED,\n \"Failed to resolve the application config.\",\n {\n cause: e\n }\n );\n }\n\n const merged = mergeConfigs(configs);\n if (overrides) {\n if (overrides.locale) {\n merged.locale = overrides.locale;\n }\n if (overrides.colorMode) {\n merged.colorMode = overrides.colorMode;\n }\n if (overrides.chakraSystemConfig) {\n merged.chakraSystemConfig = overrides.chakraSystemConfig;\n }\n }\n\n return merged;\n}\n\n/**\n * The application config after merging all sources.\n * Every key is present, but values might be `undefined`.\n */\nexport type ResolvedApplicationConfig = {\n [K in keyof Required<ApplicationConfig>]: ApplicationConfig[K] | undefined;\n} & {\n properties: ApplicationProperties;\n};\n\n/**\n * Merges application configurations into a single object.\n *\n * Properties / config parameters at a later position overwrite properties from earlier ones. *\n * A key whose value is `undefined` does not override a previous value.\n */\nfunction mergeConfigs(configs: ApplicationConfig[]): ResolvedApplicationConfig {\n const mergedConfig: ResolvedApplicationConfig = {\n locale: undefined,\n supportedLocales: undefined,\n chakraSystemConfig: undefined,\n colorMode: undefined,\n properties: {}\n };\n for (const config of configs) {\n if (config.locale !== undefined) {\n mergedConfig.locale = config.locale;\n }\n if (config.supportedLocales !== undefined) {\n mergedConfig.supportedLocales = config.supportedLocales;\n }\n if (config.chakraSystemConfig !== undefined) {\n mergedConfig.chakraSystemConfig = config.chakraSystemConfig;\n }\n if (config.colorMode !== undefined) {\n mergedConfig.colorMode = config.colorMode;\n }\n }\n\n // Deep merge for application properties\n const mergedProperties = mergedConfig.properties;\n for (const config of configs) {\n for (const [packageName, packageProperties] of Object.entries(config.properties ?? {})) {\n const mergedPackageProps = (mergedProperties[packageName] ??= {});\n Object.assign(mergedPackageProps, packageProperties);\n }\n }\n\n return mergedConfig;\n}\n"],"names":[],"mappings":";;;AAgBA,eAAsB,YAAA,CAClB,WAAA,EACA,OAAA,EACA,SAAA,EACkC;AAClC,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACA,IAAA,MAAM,YAAA,GAAe,OAAA,CAAQ,MAAA,IAAU,EAAC;AACxC,IAAA,MAAM,aAAA,GACD,MAAM,OAAA,CAAQ,aAAA,GAAgB;AAAA,MAC3B,WAAA;AAAA,MACA,aAAa,IAAA,EAAM;AACf,QAAA,OAAO,WAAA,CAAY,YAAA,CAAa,IAAI,CAAA,IAAK,KAAA,CAAA;AAAA,MAC7C,CAAA;AAAA,MACA;AAAA,KACH,KAAM,EAAC;AAEZ,IAAA,OAAA,GAAU;AAAA,MACN;AAAA,QACI,oBAAoB,OAAA,CAAQ;AAAA,OAChC;AAAA,MACA,YAAA;AAAA,MACA;AAAA,KACJ;AAAA,EACJ,SAAS,CAAA,EAAG;AACR,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,wBAAA;AAAA,MACR,2CAAA;AAAA,MACA;AAAA,QACI,KAAA,EAAO;AAAA;AACX,KACJ;AAAA,EACJ;AAEA,EAAA,MAAM,MAAA,GAAS,aAAa,OAAO,CAAA;AACnC,EAAA,IAAI,SAAA,EAAW;AACX,IAAA,IAAI,UAAU,MAAA,EAAQ;AAClB,MAAA,MAAA,CAAO,SAAS,SAAA,CAAU,MAAA;AAAA,IAC9B;AACA,IAAA,IAAI,UAAU,SAAA,EAAW;AACrB,MAAA,MAAA,CAAO,YAAY,SAAA,CAAU,SAAA;AAAA,IACjC;AACA,IAAA,IAAI,UAAU,kBAAA,EAAoB;AAC9B,MAAA,MAAA,CAAO,qBAAqB,SAAA,CAAU,kBAAA;AAAA,IAC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pioneer/core';
2
- import { sourceId$5 as sourceId } from '../_virtual/source-info.js';
2
+ import { sourceId$6 as sourceId } from '../_virtual/source-info.js';
3
3
 
4
4
  const LOG = createLogger(sourceId);
5
5
  function logError(e) {
@@ -1,5 +1,5 @@
1
1
  import { createLogger, deprecated, Error, isAbortError } from '@open-pioneer/core';
2
- import { sourceId$1 as sourceId } from '../_virtual/source-info.js';
2
+ import { sourceId$2 as sourceId } from '../_virtual/source-info.js';
3
3
  import { isShadowRoot } from '../dom/index.js';
4
4
  import { ErrorId } from '../errors.js';
5
5
  import '../i18n/AppIntl.js';
@@ -59,6 +59,12 @@ class ApplicationContextImpl {
59
59
  setLocale(locale) {
60
60
  setLocaleDeprecationMessage();
61
61
  const targetLocale = tryParseLocale(locale);
62
+ if (locale != null && !targetLocale) {
63
+ throw new Error(
64
+ ErrorId.UNSUPPORTED_LOCALE,
65
+ `Unsupported locale '${locale}': not a valid BCP 47 language tag.`
66
+ );
67
+ }
62
68
  if (targetLocale && !this.#localeService.supportsLocale(targetLocale)) {
63
69
  const localesList = this.#localeService.supportedMessageLocales.map((l) => l.baseName).join(", ");
64
70
  throw new Error(
@@ -1 +1 @@
1
- {"version":3,"file":"ApplicationContextImpl.js","sources":["ApplicationContextImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger, Error, deprecated, isAbortError } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ApplicationContext, LocaleService } from \"../api\";\nimport { isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { tryParseLocale } from \"../i18n\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface ApplicationContextProperties {\n host: HTMLElement;\n rootNode: RootNode;\n container: HTMLElement;\n}\n\ninterface ServiceReferences {\n localeService: LocaleService;\n}\n\nexport type ApplicationContextServiceOptions = ServiceOptions<ServiceReferences>;\n\nconst setLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.setLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.changeLocale` instead.\"\n});\nconst getLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.getLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.locale` instead.\"\n});\nconst getSupportedLocalesDeprecationMessage = deprecated({\n name: \"ApplicationContext.getSupportedLocales\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.supportedMessageLocales` instead.\"\n});\n\nexport class ApplicationContextImpl implements ApplicationContext {\n #host: HTMLElement;\n #rootNode: RootNode;\n #container: HTMLElement;\n #localeService: LocaleService;\n\n constructor(\n options: ApplicationContextServiceOptions,\n properties: ApplicationContextProperties\n ) {\n this.#host = properties.host;\n this.#rootNode = properties.rootNode;\n this.#container = properties.container;\n this.#localeService = options.references.localeService;\n }\n\n getHostElement(): HTMLElement {\n return this.#host;\n }\n\n getRoot(): RootNode {\n return this.#rootNode;\n }\n\n getShadowRoot(): ShadowRoot | undefined {\n return isShadowRoot(this.#rootNode) ? this.#rootNode : undefined;\n }\n\n getApplicationContainer(): HTMLElement {\n return this.#container;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getLocale(): string {\n getLocaleDeprecationMessage();\n return this.#localeService.locale.baseName;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n setLocale(locale: string | undefined): void {\n setLocaleDeprecationMessage();\n const targetLocale = tryParseLocale(locale);\n // to be backwards compatible, we check here synchronously\n // same check is done in AppIntl.changeLocale\n if (targetLocale && !this.#localeService.supportsLocale(targetLocale)) {\n const localesList = this.#localeService.supportedMessageLocales\n .map((l) => l.baseName)\n .join(\", \");\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${targetLocale.baseName}' (supported locales: ${localesList}).`\n );\n }\n this.#localeService.changeLocale(targetLocale).catch((e) => {\n if (!isAbortError(e)) {\n LOG.error(`Failed to switch locale to '${targetLocale?.baseName}'.`, e);\n }\n });\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getSupportedLocales(): readonly string[] {\n getSupportedLocalesDeprecationMessage();\n return this.#localeService.supportedMessageLocales.map((l) => l.baseName);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAWA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAcjC,MAAM,8BAA8B,UAAA,CAAW;AAAA,EAC3C,IAAA,EAAM,8BAAA;AAAA,EACN,WAAA,EAAa,uBAAA;AAAA,EACb,KAAA,EAAO,QAAA;AAAA,EACP,WAAA,EAAa;AACjB,CAAC,CAAA;AACD,MAAM,8BAA8B,UAAA,CAAW;AAAA,EAC3C,IAAA,EAAM,8BAAA;AAAA,EACN,WAAA,EAAa,uBAAA;AAAA,EACb,KAAA,EAAO,QAAA;AAAA,EACP,WAAA,EAAa;AACjB,CAAC,CAAA;AACD,MAAM,wCAAwC,UAAA,CAAW;AAAA,EACrD,IAAA,EAAM,wCAAA;AAAA,EACN,WAAA,EAAa,uBAAA;AAAA,EACb,KAAA,EAAO,QAAA;AAAA,EACP,WAAA,EAAa;AACjB,CAAC,CAAA;AAEM,MAAM,sBAAA,CAAqD;AAAA,EAC9D,KAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EAEA,WAAA,CACI,SACA,UAAA,EACF;AACE,IAAA,IAAA,CAAK,QAAQ,UAAA,CAAW,IAAA;AACxB,IAAA,IAAA,CAAK,YAAY,UAAA,CAAW,QAAA;AAC5B,IAAA,IAAA,CAAK,aAAa,UAAA,CAAW,SAAA;AAC7B,IAAA,IAAA,CAAK,cAAA,GAAiB,QAAQ,UAAA,CAAW,aAAA;AAAA,EAC7C;AAAA,EAEA,cAAA,GAA8B;AAC1B,IAAA,O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AAAA,EACL;AAAA;AAAA,EAGA,mBAAA,GAAyC;AACrC,IAAA,qCAAA,EAAsC;AACtC,IAAA,OAAO,KAAK,cAAA,CAAe,uBAAA,CAAwB,IAAI,CAAC,CAAA,KAAM,EAAE,QAAQ,CAAA;AAAA,EAC5E;AACJ;;"}
1
+ {"version":3,"file":"ApplicationContextImpl.js","sources":["ApplicationContextImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger, Error, deprecated, isAbortError } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ApplicationContext, LocaleService } from \"../api\";\nimport { isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { tryParseLocale } from \"../i18n\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface ApplicationContextProperties {\n host: HTMLElement;\n rootNode: RootNode;\n container: HTMLElement;\n}\n\ninterface ServiceReferences {\n localeService: LocaleService;\n}\n\nexport type ApplicationContextServiceOptions = ServiceOptions<ServiceReferences>;\n\nconst setLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.setLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.changeLocale` instead.\"\n});\nconst getLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.getLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.locale` instead.\"\n});\nconst getSupportedLocalesDeprecationMessage = deprecated({\n name: \"ApplicationContext.getSupportedLocales\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.supportedMessageLocales` instead.\"\n});\n\nexport class ApplicationContextImpl implements ApplicationContext {\n #host: HTMLElement;\n #rootNode: RootNode;\n #container: HTMLElement;\n #localeService: LocaleService;\n\n constructor(\n options: ApplicationContextServiceOptions,\n properties: ApplicationContextProperties\n ) {\n this.#host = properties.host;\n this.#rootNode = properties.rootNode;\n this.#container = properties.container;\n this.#localeService = options.references.localeService;\n }\n\n getHostElement(): HTMLElement {\n return this.#host;\n }\n\n getRoot(): RootNode {\n return this.#rootNode;\n }\n\n getShadowRoot(): ShadowRoot | undefined {\n return isShadowRoot(this.#rootNode) ? this.#rootNode : undefined;\n }\n\n getApplicationContainer(): HTMLElement {\n return this.#container;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getLocale(): string {\n getLocaleDeprecationMessage();\n return this.#localeService.locale.baseName;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n setLocale(locale: string | undefined): void {\n setLocaleDeprecationMessage();\n const targetLocale = tryParseLocale(locale);\n if (locale != null && !targetLocale) {\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${locale}': not a valid BCP 47 language tag.`\n );\n }\n // to be backwards compatible, we check here synchronously\n // same check is done in AppIntl.changeLocale\n if (targetLocale && !this.#localeService.supportsLocale(targetLocale)) {\n const localesList = this.#localeService.supportedMessageLocales\n .map((l) => l.baseName)\n .join(\", \");\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${targetLocale.baseName}' (supported locales: ${localesList}).`\n );\n }\n this.#localeService.changeLocale(targetLocale).catch((e) => {\n if (!isAbortError(e)) {\n LOG.error(`Failed to switch locale to '${targetLocale?.baseName}'.`, e);\n }\n });\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getSupportedLocales(): readonly string[] {\n getSupportedLocalesDeprecationMessage();\n return this.#localeService.supportedMessageLocales.map((l) => l.baseName);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAWA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAcjC,MAAM,8BAA8B,UAAA,CAAW;AAAA,EAC3C,IAAA,EAAM,8BAAA;AAAA,EACN,WAAA,EAAa,u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ners: ApplicationLifecycleListener[];
5
5
  }
6
- export declare class ApplicationLifecycleEventService {
6
+ export declare class ApplicationLifecycleEventServiceImpl {
7
7
  #private;
8
8
  constructor(options: ServiceOptions<References>);
9
9
  /** @internal */
@@ -1,9 +1,9 @@
1
1
  import { createLogger, Error } from '@open-pioneer/core';
2
- import { sourceId$2 as sourceId } from '../_virtual/source-info.js';
2
+ import { sourceId$3 as sourceId } from '../_virtual/source-info.js';
3
3
  import { ErrorId } from '../errors.js';
4
4
 
5
5
  const LOG = createLogger(sourceId);
6
- class ApplicationLifecycleEventService {
6
+ class ApplicationLifecycleEventServiceImpl {
7
7
  #listeners;
8
8
  constructor(options) {
9
9
  const listeners = options.references.listeners;
@@ -36,5 +36,5 @@ class ApplicationLifecycleEventService {
36
36
  }
37
37
  }
38
38
 
39
- export { ApplicationLifecycleEventService };
40
- //# sourceMappingURL=ApplicationLifecycleEventService.js.map
39
+ export { ApplicationLifecycleEventServiceImpl };
40
+ //# sourceMappingURL=ApplicationLifecycleEventServiceImpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApplicationLifecycleEventServiceImpl.js","sources":["ApplicationLifecycleEventServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ApplicationLifecycleListener } from \"../api\";\nimport { ErrorId } from \"../errors\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\ninterface References {\n listeners: ApplicationLifecycleListener[];\n}\n\nexport class ApplicationLifecycleEventServiceImpl {\n #listeners: [serviceId: string, listener: ApplicationLifecycleListener][];\n\n constructor(options: ServiceOptions<References>) {\n const listeners = options.references.listeners;\n const listenersMeta = options.referencesMeta.listeners;\n this.#listeners = listeners.map((listener, index) => [\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n listenersMeta[index]!.serviceId,\n listener\n ]);\n }\n\n /** @internal */\n emitLifecycleEvent(event: \"after-start\" | \"before-stop\"): void {\n const methodName = (() => {\n switch (event) {\n case \"after-start\":\n return \"afterApplicationStart\";\n case \"before-stop\":\n return \"beforeApplicationStop\";\n default:\n throw new Error(ErrorId.INTERNAL, `Invalid event '${event}'`);\n }\n })();\n for (const [serviceId, listener] of this.#listeners) {\n try {\n listener[methodName]?.();\n } catch (e) {\n LOG.error(`Unexpected error from application lifecycle listener ${serviceId}`, e);\n }\n }\n }\n}\n"],"names":[],"mappings":";;;;AASA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAM1B,MAAM,oCAAA,CAAqC;AAAA,EAC9C,UAAA;AAAA,EAEA,YAAY,OAAA,EAAqC;AAC7C,IAAA,MAAM,SAAA,GAAY,QAAQ,UAAA,CAAW,SAAA;AACrC,IAAA,MAAM,aAAA,GAAgB,QAAQ,cAAA,CAAe,SAAA;AAC7C,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA,CAAU,GAAA,CAAI,CAAC,UAAU,KAAA,KAAU;AAAA;AAAA,MAEjD,aAAA,CAAc,KAAK,CAAA,CAAG,SAAA;AAAA,MACtB;AAAA,KACH,CAAA;AAAA,EACL;AAAA;AAAA,EAGA,mBAAmB,KAAA,EAA4C;AAC3D,IAAA,MAAM,cAAc,MAAM;AACtB,MAAA,QAAQ,KAAA;AAAO,QACX,KAAK,aAAA;AACD,UAAA,OAAO,uBAAA;AAAA,QACX,KAAK,aAAA;AACD,UAAA,OAAO,uBAAA;AAAA,QACX;AACI,UAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,QAAA,EAAU,CAAA,eAAA,EAAkB,KAAK,CAAA,CAAA,CAAG,CAAA;AAAA;AACpE,IACJ,CAAA,GAAG;AACH,IAAA,KAAA,MAAW,CAAC,SAAA,EAAW,QAAQ,CAAA,IAAK,KAAK,UAAA,EAAY;AACjD,MAAA,IAAI;AACA,QAAA,QAAA,CAAS,UAAU,CAAA,IAAI;AAAA,MAC3B,SAAS,CAAA,EAAG;AACR,QAAA,GAAA,CAAI,KAAA,CAAM,CAAA,qDAAA,EAAwD,SAAS,CAAA,CAAA,EAAI,CAAC,CAAA;AAAA,MACpF;AAAA,IACJ;AAAA,EACJ;AACJ;;"}
@@ -6,7 +6,7 @@ interface ServiceReferences {
6
6
  export type NumberParserServiceOptions = ServiceOptions<ServiceReferences>;
7
7
  export declare class NumberParserServiceImpl implements NumberParserService {
8
8
  #private;
9
- constructor(_serviceOptions: NumberParserServiceOptions);
9
+ constructor(options: NumberParserServiceOptions);
10
10
  parseNumber(numberString: string): number;
11
11
  }
12
12
  export {};
@@ -1,12 +1,12 @@
1
1
  import { computed } from '@conterra/reactivity-core';
2
2
  import { createLogger, NumberParser } from '@open-pioneer/core';
3
- import { sourceId$3 as sourceId } from '../_virtual/source-info.js';
3
+ import { sourceId$4 as sourceId } from '../_virtual/source-info.js';
4
4
 
5
5
  const LOG = createLogger(sourceId);
6
6
  class NumberParserServiceImpl {
7
7
  #numberParser;
8
- constructor(_serviceOptions) {
9
- const localeService = _serviceOptions.references.localeService;
8
+ constructor(options) {
9
+ const localeService = options.references.localeService;
10
10
  this.#numberParser = computed(() => {
11
11
  const tag = localeService.locale.baseName;
12
12
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"NumberParserServiceImpl.js","sources":["NumberParserServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { computed, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { createLogger, NumberParser } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { LocaleService, NumberParserService } from \"../api\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\ninterface ServiceReferences {\n localeService: Pick<LocaleService, \"locale\">;\n}\n\nexport type NumberParserServiceOptions = ServiceOptions<ServiceReferences>;\n\nexport class NumberParserServiceImpl implements NumberParserService {\n #numberParser: ReadonlyReactive<NumberParser>;\n\n constructor(_serviceOptions: NumberParserServiceOptions) {\n const localeService = _serviceOptions.references.localeService;\n this.#numberParser = computed(() => {\n // reactive\n const tag = localeService.locale.baseName;\n try {\n return new NumberParser(tag);\n } catch (e) {\n LOG.warn(\n `Failed to create NumberParser with locale '${tag}'. Falling back to 'en-US'.`,\n e\n );\n return new NumberParser(\"en-US\");\n }\n });\n }\n\n parseNumber(numberString: string): number {\n return this.#numberParser.value.parse(numberString);\n }\n}\n"],"names":[],"mappings":";;;;AASA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAQ1B,MAAM,uBAAA,CAAuD;AAAA,EAChE,aAAA;AAAA,EAEA,YAAY,eAAA,EAA6C;AACrD,IAAA,MAAM,aAAA,GAAgB,gBAAgB,UAAA,CAAW,aAAA;AACjD,IAAA,IAAA,CAAK,aAAA,GAAgB,SAAS,MAAM;AAEhC,MAAA,MAAM,GAAA,GAAM,cAAc,MAAA,CAAO,QAAA;AACjC,MAAA,IAAI;AACA,QAAA,OAAO,IAAI,aAAa,GAAG,CAAA;AAAA,MAC/B,SAAS,CAAA,EAAG;AACR,QAAA,GAAA,CAAI,IAAA;AAAA,UACA,8CAA8C,GAAG,CAAA,2BAAA,CAAA;AAAA,UACjD;AAAA,SACJ;AACA,QAAA,OAAO,IAAI,aAAa,OAAO,CAAA;AAAA,MACnC;AAAA,IACJ,CAAC,CAAA;AAAA,EACL;AAAA,EAEA,YAAY,YAAA,EAA8B;AACtC,IAAA,OAAO,IAAA,CAAK,aAAA,CAAc,KAAA,CAAM,KAAA,CAAM,YAAY,CAAA;AAAA,EACtD;AACJ;;"}
1
+ {"version":3,"file":"NumberParserServiceImpl.js","sources":["NumberParserServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { computed, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { createLogger, NumberParser } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { LocaleService, NumberParserService } from \"../api\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\ninterface ServiceReferences {\n localeService: Pick<LocaleService, \"locale\">;\n}\n\nexport type NumberParserServiceOptions = ServiceOptions<ServiceReferences>;\n\nexport class NumberParserServiceImpl implements NumberParserService {\n #numberParser: ReadonlyReactive<NumberParser>;\n\n constructor(options: NumberParserServiceOptions) {\n const localeService = options.references.localeService;\n this.#numberParser = computed(() => {\n const tag = localeService.locale.baseName;\n try {\n return new NumberParser(tag);\n } catch (e) {\n LOG.warn(\n `Failed to create NumberParser with locale '${tag}'. Falling back to 'en-US'.`,\n e\n );\n return new NumberParser(\"en-US\");\n }\n });\n }\n\n parseNumber(numberString: string): number {\n return this.#numberParser.value.parse(numberString);\n }\n}\n"],"names":[],"mappings":";;;;AASA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAQ1B,MAAM,uBAAA,CAAuD;AAAA,EAChE,aAAA;AAAA,EAEA,YAAY,OAAA,EAAqC;AAC7C,IAAA,MAAM,aAAA,GAAgB,QAAQ,UAAA,CAAW,aAAA;AACzC,IAAA,IAAA,CAAK,aAAA,GAAgB,SAAS,MAAM;AAChC,MAAA,MAAM,GAAA,GAAM,cAAc,MAAA,CAAO,QAAA;AACjC,MAAA,IAAI;AACA,QAAA,OAAO,IAAI,aAAa,GAAG,CAAA;AAAA,MAC/B,SAAS,CAAA,EAAG;AACR,QAAA,GAAA,CAAI,IAAA;AAAA,UACA,8CAA8C,GAAG,CAAA,2BAAA,CAAA;AAAA,UACjD;AAAA,SACJ;AACA,QAAA,OAAO,IAAI,aAAa,OAAO,CAAA;AAAA,MACnC;AAAA,IACJ,CAAC,CAAA;AAAA,EACL;AAAA,EAEA,YAAY,YAAA,EAA8B;AACtC,IAAA,OAAO,IAAA,CAAK,aAAA,CAAc,KAAA,CAAM,KAAA,CAAM,YAAY,CAAA;AAAA,EACtD;AACJ;;"}