@open-pioneer/test-utils 4.9.0-dev.20261002130116 → 4.9.0
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.
- package/CHANGELOG.md +20 -17
- package/README.md +7 -6
- package/package.json +7 -6
- package/react.d.ts +8 -0
- package/react.js +3 -0
- package/react.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
# @open-pioneer/test-utils
|
|
2
2
|
|
|
3
|
-
## 4.9.0
|
|
3
|
+
## 4.9.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
7
|
- 6145961: Update `@formatjs/intl` to version 6.
|
|
8
|
+
- 31f8961: Add the `chakraSystemConfig` prop to `PackageContextProvider`.
|
|
9
|
+
It takes a chakra `SystemConfig`, like the `chakraSystemConfig` option of `createCustomElement()`, so tests can render components with a custom theme.
|
|
8
10
|
|
|
9
11
|
### Patch Changes
|
|
10
12
|
|
|
11
13
|
- 6b160f3: `PackageContextProvider` keeps its package context stable across re-renders with equal props, so `useIntl()` and `useService()` return the same objects.
|
|
14
|
+
- 42ca366: Update dependencies
|
|
12
15
|
|
|
13
16
|
## 4.8.0
|
|
14
17
|
|
|
@@ -66,20 +69,20 @@
|
|
|
66
69
|
- 9fa7f7c: The `createService` helper no longer returns a promise.
|
|
67
70
|
It can now be used in a synchronous fashion (no `await`).
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
Note that this change is backwards compatible.
|
|
73
|
+
But if you have been using this function in your code, you can simply remove the `await`.
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
It originally returned a promise to support (future) asynchronous initialization of services,
|
|
76
|
+
which has not been implemented and seems not to be needed.
|
|
74
77
|
|
|
75
|
-
|
|
78
|
+
Example:
|
|
76
79
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
```ts
|
|
81
|
+
// In your unit tests:
|
|
82
|
+
import { createService } from "@open-pioneer/test-utils/services";
|
|
80
83
|
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
const service = createService(MyServiceClass, options);
|
|
85
|
+
```
|
|
83
86
|
|
|
84
87
|
- 1b95a62: Update chakra-ui to 3.28.0
|
|
85
88
|
|
|
@@ -115,13 +118,13 @@
|
|
|
115
118
|
### Major Changes
|
|
116
119
|
|
|
117
120
|
- 9477e54: Update dependencies
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
- React 19
|
|
122
|
+
- Vite 6
|
|
123
|
+
- FormatJS 3
|
|
124
|
+
- Open Pioneer Build Tools
|
|
125
|
+
- ...
|
|
123
126
|
|
|
124
|
-
|
|
127
|
+
For more details, see https://github.com/open-pioneer/trails-core-packages/pull/81
|
|
125
128
|
|
|
126
129
|
## 2.4.0
|
|
127
130
|
|
package/README.md
CHANGED
|
@@ -14,10 +14,11 @@ Example:
|
|
|
14
14
|
/**
|
|
15
15
|
* @vitest-environment happy-dom
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
import { createElement } from "react";
|
|
17
|
+
|
|
19
18
|
import { createCustomElement } from "@open-pioneer/runtime";
|
|
20
19
|
import { renderComponentShadowDOM } from "@open-pioneer/test-utils/web-components";
|
|
20
|
+
import { createElement } from "react";
|
|
21
|
+
import { it, expect } from "vitest";
|
|
21
22
|
|
|
22
23
|
it("should render a custom component into the dom", async () => {
|
|
23
24
|
// Define a custom element class.
|
|
@@ -40,15 +41,15 @@ Take a look at the tests in this package for more examples.
|
|
|
40
41
|
|
|
41
42
|
Provides helpers to make testing of react components easier that use the hooks from the `"open-pioneer:react-hooks"` module (e.g. `useService`).
|
|
42
43
|
|
|
43
|
-
The developer can provide custom service implementations, properties etc. using a simple parent component.
|
|
44
|
+
The developer can provide custom service implementations, properties, a chakra theme, etc. using a simple parent component.
|
|
44
45
|
|
|
45
46
|
Example:
|
|
46
47
|
|
|
47
48
|
```js
|
|
48
|
-
import { expect, it } from "vitest";
|
|
49
|
-
import { screen, render } from "@testing-library/react";
|
|
50
49
|
import { PackageContextProvider } from "@open-pioneer/test-utils/react";
|
|
50
|
+
import { screen, render } from "@testing-library/react";
|
|
51
51
|
import { useProperties, useService, useServices } from "open-pioneer:react-hooks";
|
|
52
|
+
import { expect, it } from "vitest";
|
|
52
53
|
|
|
53
54
|
it("should allow injection of service from the test", async () => {
|
|
54
55
|
// A simple component that uses a service.
|
|
@@ -90,8 +91,8 @@ References to other service instances can be mocked with user defined test value
|
|
|
90
91
|
Example:
|
|
91
92
|
|
|
92
93
|
```js
|
|
93
|
-
import { expect, it } from "vitest";
|
|
94
94
|
import { createService } from "@open-pioneer/test-utils/services";
|
|
95
|
+
import { expect, it } from "vitest";
|
|
95
96
|
import { MyService } from "./MyService"; // User defined service
|
|
96
97
|
|
|
97
98
|
it("creates a new service instance with the defined references", async () => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/test-utils",
|
|
4
|
-
"version": "4.9.0
|
|
4
|
+
"version": "4.9.0",
|
|
5
5
|
"description": "Contains test utilities that make it easier to test parts of an Open Pioneer Trails application.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
"directory": "src/packages/test-utils"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
17
|
+
"@chakra-ui/react": "^3.37.0",
|
|
18
|
+
"@conterra/reactivity-core": "^0.8.9",
|
|
19
|
+
"@formatjs/intl": "^6.1.4",
|
|
20
|
+
"@open-pioneer/runtime": "4.9.0",
|
|
20
21
|
"@testing-library/dom": "^10.4.2",
|
|
21
22
|
"@testing-library/react": "^16.3.3",
|
|
22
|
-
"react": "^19.3.
|
|
23
|
-
"react-dom": "^19.3.
|
|
23
|
+
"react": "^19.3.1",
|
|
24
|
+
"react-dom": "^19.3.1"
|
|
24
25
|
},
|
|
25
26
|
"publishConfig": {
|
|
26
27
|
"directory": "dist",
|
package/react.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SystemConfig as ChakraSystemConfig } from "@chakra-ui/react";
|
|
1
2
|
import type { ColorModeValue, Service } from "@open-pioneer/runtime";
|
|
2
3
|
import { FC, ReactNode } from "react";
|
|
3
4
|
/** Any service instance. The type is relaxed on purpose to allow test mocks. */
|
|
@@ -28,6 +29,13 @@ export interface PackageContextProviderProps {
|
|
|
28
29
|
* The color mode.
|
|
29
30
|
*/
|
|
30
31
|
colorMode?: ColorModeValue;
|
|
32
|
+
/**
|
|
33
|
+
* Chakra styled system object.
|
|
34
|
+
*
|
|
35
|
+
* Used to configure chakra's theme, like `chakraSystemConfig` of `createCustomElement()`.
|
|
36
|
+
* Defaults to the trails base theme.
|
|
37
|
+
*/
|
|
38
|
+
chakraSystemConfig?: ChakraSystemConfig;
|
|
31
39
|
/**
|
|
32
40
|
* I18n messages for packages
|
|
33
41
|
*/
|
package/react.js
CHANGED
|
@@ -12,8 +12,10 @@ const PackageContextProvider = (props) => {
|
|
|
12
12
|
properties,
|
|
13
13
|
locale: localeProp,
|
|
14
14
|
colorMode: colorModeProp,
|
|
15
|
+
chakraSystemConfig,
|
|
15
16
|
messages
|
|
16
17
|
} = props;
|
|
18
|
+
const config = useMemo(() => constant(chakraSystemConfig), [chakraSystemConfig]);
|
|
17
19
|
const [locale, colorMode, contextMethods] = useMemo(
|
|
18
20
|
() => createPackageContextMethods({
|
|
19
21
|
services,
|
|
@@ -38,6 +40,7 @@ const PackageContextProvider = (props) => {
|
|
|
38
40
|
appRoot: document.body,
|
|
39
41
|
locale,
|
|
40
42
|
colorMode,
|
|
43
|
+
config,
|
|
41
44
|
children: /* @__PURE__ */ jsx(PackageContext.Provider, { value: contextMethods, children })
|
|
42
45
|
}
|
|
43
46
|
);
|
package/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sources":["react.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { constant, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport type { ColorModeValue, PackageIntl, Service } from \"@open-pioneer/runtime\";\nimport {\n APP_ROOT_CLASS,\n CustomChakraProvider,\n PackageContext,\n PackageContextMethods\n} from \"@open-pioneer/runtime/test-support\";\nimport { FC, ReactNode, useInsertionEffect, useMemo } from \"react\";\nimport { createIntl } from \"./vanilla\";\n\n/** Any service instance. The type is relaxed on purpose to allow test mocks. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyService = Service<any>;\n\n/** Props of {@link PackageContextProvider}. */\nexport interface PackageContextProviderProps {\n /** Interface implementations, keyed by interface name. */\n services?: {\n [interfaceName: string]: AnyService;\n };\n\n /** Interface implementations, keyed by interface name and then by qualifier. */\n qualifiedServices?: {\n [interfaceName: string]: {\n [qualifier: string]: AnyService;\n };\n };\n\n /** Package properties (keyed by package name). */\n properties?: {\n [packageName: string]: Record<string, unknown>;\n };\n\n /**\n * The locale for i18n messages and formatting.\n *\n * @default \"en\"\n */\n locale?: string;\n\n /**\n * The color mode.\n */\n colorMode?: ColorModeValue;\n\n /**\n * I18n messages for packages\n */\n messages?: {\n /**\n * I18n messages as (messageId, message) entries.\n *\n * @default {}\n */\n [packageName: string]: Record<string, string>;\n };\n\n /** Children to render */\n children?: ReactNode;\n}\n\n/**\n * Injects services and properties into the component tree.\n * React components using Open Pioneer Trails hooks like `useService` and `useProperties`\n * will receive the mocked properties here instead.\n * Currently also wrapped with the CustomChakraProvider to support chakra-ui elements\n */\nexport const PackageContextProvider: FC<PackageContextProviderProps> = (props) => {\n const {\n children,\n services,\n qualifiedServices,\n properties,\n locale: localeProp,\n colorMode: colorModeProp,\n messages\n } = props;\n const [locale, colorMode, contextMethods] = useMemo(\n () =>\n createPackageContextMethods({\n services,\n qualifiedServices,\n properties,\n locale: localeProp,\n colorMode: colorModeProp,\n messages\n }),\n [services, qualifiedServices, properties, localeProp, colorModeProp, messages]\n );\n\n useInsertionEffect(() => {\n // Needed for chakra tokens / theme etc. to be applied correctly.\n // In real applications, this is done as part of the web component startup code.\n // In test scenarios, the body is used as the root node (see props below).\n document.body.classList.add(APP_ROOT_CLASS);\n return () => {\n document.body.classList.remove(APP_ROOT_CLASS);\n };\n }, []);\n\n return (\n <CustomChakraProvider\n rootNode={document}\n appRoot={document.body}\n locale={locale}\n colorMode={colorMode}\n >\n <PackageContext.Provider value={contextMethods}>{children}</PackageContext.Provider>\n </CustomChakraProvider>\n );\n};\n\nfunction createPackageContextMethods(\n options: Omit<PackageContextProviderProps, \"children\">\n): [\n locale: ReadonlyReactive<string>,\n colorMode: ReadonlyReactive<ColorModeValue>,\n methods: PackageContextMethods\n] {\n const services = options?.services ?? {};\n const qualifiedServices = options?.qualifiedServices ?? {};\n const properties = options?.properties ?? {};\n const locale = options?.locale ?? \"en\";\n const messages = options?.messages ?? {};\n const cachedIntl: Record<string, PackageIntl> = {};\n const colorMode = constant<ColorModeValue>(options?.colorMode ?? \"light\");\n const methods: PackageContextMethods = {\n getService(packageName, interfaceName, options) {\n if (!options.qualifier) {\n const service = services[interfaceName];\n if (service) {\n return service;\n }\n const qualified = qualifiedServices[interfaceName];\n if (qualified) {\n for (const value of Object.values(qualified)) {\n return value; // Return any implementation\n }\n }\n throw new Error(\n `Interface name not bound for testing: '${interfaceName}'. Update the configuration of PackageContextProvider.`\n );\n }\n\n const qualifiedService = qualifiedServices[interfaceName]?.[options.qualifier];\n if (!qualifiedService) {\n throw new Error(\n `Interface name not bound for testing: '${interfaceName}' (qualifier '${options.qualifier}'). Update the configuration of PackageContextProvider.`\n );\n }\n return qualifiedService;\n },\n getServices(packageName, interfaceName) {\n const unqualified = services[interfaceName];\n const results = Object.values(qualifiedServices[interfaceName] ?? {});\n if (unqualified) {\n results.push(unqualified);\n }\n return results;\n },\n getProperties(packageName) {\n const packageProperties = properties[packageName];\n if (!packageProperties) {\n throw new Error(\n `No properties for package '${packageName}' bound for testing. Update the configuration of PackageContextProvider.`\n );\n }\n return packageProperties;\n },\n getIntl(packageName) {\n const initIntl = () => {\n const packageMessages = messages[packageName];\n return createIntl({\n locale: locale,\n messages: packageMessages\n });\n };\n return (cachedIntl[packageName] ??= initIntl());\n }\n };\n return [constant(locale), colorMode, methods];\n}\n"],"names":["options"],"mappings":";;;;;;AAuEO,MAAM,sBAAA,GAA0D,CAAC,KAAA,KAAU;AAC9E,EAAA,MAAM;AAAA,IACF,QAAA;AAAA,IACA,QAAA;AAAA,IACA,iBAAA;AAAA,IACA,UAAA;AAAA,IACA,MAAA,EAAQ,UAAA;AAAA,IACR,SAAA,EAAW,aAAA;AAAA,IACX;AAAA,GACJ,GAAI,KAAA;AACJ,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAA,EAAW,cAAc,CAAA,GAAI,OAAA;AAAA,IACxC,MACI,2BAAA,CAA4B;AAAA,MACxB,QAAA;AAAA,MACA,iBAAA;AAAA,MACA,UAAA;AAAA,MACA,MAAA,EAAQ,UAAA;AAAA,MACR,SAAA,EAAW,aAAA;AAAA,MACX;AAAA,KACH,CAAA;AAAA,IACL,CAAC,QAAA,EAAU,iBAAA,EAAmB,UAAA,EAAY,UAAA,EAAY,eAAe,QAAQ;AAAA,GACjF;AAEA,EAAA,kBAAA,CAAmB,MAAM;AAIrB,IAAA,QAAA,CAAS,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,cAAc,CAAA;AAC1C,IAAA,OAAO,MAAM;AACT,MAAA,QAAA,CAAS,IAAA,CAAK,SAAA,CAAU,MAAA,CAAO,cAAc,CAAA;AAAA,IACjD,CAAA;AAAA,EACJ,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,uBACI,GAAA;AAAA,IAAC,oBAAA;AAAA,IAA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file":"react.js","sources":["react.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { SystemConfig as ChakraSystemConfig } from \"@chakra-ui/react\";\nimport { constant, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport type { ColorModeValue, PackageIntl, Service } from \"@open-pioneer/runtime\";\nimport {\n APP_ROOT_CLASS,\n CustomChakraProvider,\n PackageContext,\n PackageContextMethods\n} from \"@open-pioneer/runtime/test-support\";\nimport { FC, ReactNode, useInsertionEffect, useMemo } from \"react\";\nimport { createIntl } from \"./vanilla\";\n\n/** Any service instance. The type is relaxed on purpose to allow test mocks. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyService = Service<any>;\n\n/** Props of {@link PackageContextProvider}. */\nexport interface PackageContextProviderProps {\n /** Interface implementations, keyed by interface name. */\n services?: {\n [interfaceName: string]: AnyService;\n };\n\n /** Interface implementations, keyed by interface name and then by qualifier. */\n qualifiedServices?: {\n [interfaceName: string]: {\n [qualifier: string]: AnyService;\n };\n };\n\n /** Package properties (keyed by package name). */\n properties?: {\n [packageName: string]: Record<string, unknown>;\n };\n\n /**\n * The locale for i18n messages and formatting.\n *\n * @default \"en\"\n */\n locale?: string;\n\n /**\n * The color mode.\n */\n colorMode?: ColorModeValue;\n\n /**\n * Chakra styled system object.\n *\n * Used to configure chakra's theme, like `chakraSystemConfig` of `createCustomElement()`.\n * Defaults to the trails base theme.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n\n /**\n * I18n messages for packages\n */\n messages?: {\n /**\n * I18n messages as (messageId, message) entries.\n *\n * @default {}\n */\n [packageName: string]: Record<string, string>;\n };\n\n /** Children to render */\n children?: ReactNode;\n}\n\n/**\n * Injects services and properties into the component tree.\n * React components using Open Pioneer Trails hooks like `useService` and `useProperties`\n * will receive the mocked properties here instead.\n * Currently also wrapped with the CustomChakraProvider to support chakra-ui elements\n */\nexport const PackageContextProvider: FC<PackageContextProviderProps> = (props) => {\n const {\n children,\n services,\n qualifiedServices,\n properties,\n locale: localeProp,\n colorMode: colorModeProp,\n chakraSystemConfig,\n messages\n } = props;\n const config = useMemo(() => constant(chakraSystemConfig), [chakraSystemConfig]);\n const [locale, colorMode, contextMethods] = useMemo(\n () =>\n createPackageContextMethods({\n services,\n qualifiedServices,\n properties,\n locale: localeProp,\n colorMode: colorModeProp,\n messages\n }),\n [services, qualifiedServices, properties, localeProp, colorModeProp, messages]\n );\n\n useInsertionEffect(() => {\n // Needed for chakra tokens / theme etc. to be applied correctly.\n // In real applications, this is done as part of the web component startup code.\n // In test scenarios, the body is used as the root node (see props below).\n document.body.classList.add(APP_ROOT_CLASS);\n return () => {\n document.body.classList.remove(APP_ROOT_CLASS);\n };\n }, []);\n\n return (\n <CustomChakraProvider\n rootNode={document}\n appRoot={document.body}\n locale={locale}\n colorMode={colorMode}\n config={config}\n >\n <PackageContext.Provider value={contextMethods}>{children}</PackageContext.Provider>\n </CustomChakraProvider>\n );\n};\n\nfunction createPackageContextMethods(\n options: Omit<PackageContextProviderProps, \"children\">\n): [\n locale: ReadonlyReactive<string>,\n colorMode: ReadonlyReactive<ColorModeValue>,\n methods: PackageContextMethods\n] {\n const services = options?.services ?? {};\n const qualifiedServices = options?.qualifiedServices ?? {};\n const properties = options?.properties ?? {};\n const locale = options?.locale ?? \"en\";\n const messages = options?.messages ?? {};\n const cachedIntl: Record<string, PackageIntl> = {};\n const colorMode = constant<ColorModeValue>(options?.colorMode ?? \"light\");\n const methods: PackageContextMethods = {\n getService(packageName, interfaceName, options) {\n if (!options.qualifier) {\n const service = services[interfaceName];\n if (service) {\n return service;\n }\n const qualified = qualifiedServices[interfaceName];\n if (qualified) {\n for (const value of Object.values(qualified)) {\n return value; // Return any implementation\n }\n }\n throw new Error(\n `Interface name not bound for testing: '${interfaceName}'. Update the configuration of PackageContextProvider.`\n );\n }\n\n const qualifiedService = qualifiedServices[interfaceName]?.[options.qualifier];\n if (!qualifiedService) {\n throw new Error(\n `Interface name not bound for testing: '${interfaceName}' (qualifier '${options.qualifier}'). Update the configuration of PackageContextProvider.`\n );\n }\n return qualifiedService;\n },\n getServices(packageName, interfaceName) {\n const unqualified = services[interfaceName];\n const results = Object.values(qualifiedServices[interfaceName] ?? {});\n if (unqualified) {\n results.push(unqualified);\n }\n return results;\n },\n getProperties(packageName) {\n const packageProperties = properties[packageName];\n if (!packageProperties) {\n throw new Error(\n `No properties for package '${packageName}' bound for testing. Update the configuration of PackageContextProvider.`\n );\n }\n return packageProperties;\n },\n getIntl(packageName) {\n const initIntl = () => {\n const packageMessages = messages[packageName];\n return createIntl({\n locale: locale,\n messages: packageMessages\n });\n };\n return (cachedIntl[packageName] ??= initIntl());\n }\n };\n return [constant(locale), colorMode, methods];\n}\n"],"names":["options"],"mappings":";;;;;;AAgFO,MAAM,sBAAA,GAA0D,CAAC,KAAA,KAAU;AAC9E,EAAA,MAAM;AAAA,IACF,QAAA;AAAA,IACA,QAAA;AAAA,IACA,iBAAA;AAAA,IACA,UAAA;AAAA,IACA,MAAA,EAAQ,UAAA;AAAA,IACR,SAAA,EAAW,aAAA;AAAA,IACX,kBAAA;AAAA,IACA;AAAA,GACJ,GAAI,KAAA;AACJ,EAAA,MAAM,MAAA,GAAS,QAAQ,MAAM,QAAA,CAAS,kBAAkB,CAAA,EAAG,CAAC,kBAAkB,CAAC,CAAA;AAC/E,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAA,EAAW,cAAc,CAAA,GAAI,OAAA;AAAA,IACxC,MACI,2BAAA,CAA4B;AAAA,MACxB,QAAA;AAAA,MACA,iBAAA;AAAA,MACA,UAAA;AAAA,MACA,MAAA,EAAQ,UAAA;AAAA,MACR,SAAA,EAAW,aAAA;AAAA,MACX;AAAA,KACH,CAAA;AAAA,IACL,CAAC,QAAA,EAAU,iBAAA,EAAmB,UAAA,EAAY,UAAA,EAAY,eAAe,QAAQ;AAAA,GACjF;AAEA,EAAA,kBAAA,CA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