mage-obsidian 2.0.0 → 2.2.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.
Files changed (113) hide show
  1. package/dist/cli/buildThemes.d.ts +3 -0
  2. package/dist/cli/buildThemes.d.ts.map +1 -0
  3. package/{src/cli/buildThemes.ts → dist/cli/buildThemes.js} +77 -121
  4. package/dist/cli/buildThemes.js.map +1 -0
  5. package/dist/config/default.d.ts +16 -0
  6. package/dist/config/default.d.ts.map +1 -0
  7. package/{src/config/default.ts → dist/config/default.js} +2 -11
  8. package/dist/config/default.js.map +1 -0
  9. package/dist/core/configResolver.d.ts +38 -0
  10. package/dist/core/configResolver.d.ts.map +1 -0
  11. package/{src/core/configResolver.ts → dist/core/configResolver.js} +21 -60
  12. package/dist/core/configResolver.js.map +1 -0
  13. package/dist/core/contractValidator.d.ts +16 -0
  14. package/dist/core/contractValidator.d.ts.map +1 -0
  15. package/{src/core/contractValidator.ts → dist/core/contractValidator.js} +3 -10
  16. package/dist/core/contractValidator.js.map +1 -0
  17. package/dist/core/cssResolver.d.ts +5 -0
  18. package/dist/core/cssResolver.d.ts.map +1 -0
  19. package/{src/core/cssResolver.ts → dist/core/cssResolver.js} +26 -53
  20. package/dist/core/cssResolver.js.map +1 -0
  21. package/dist/core/generateInterceptors.d.ts +10 -0
  22. package/dist/core/generateInterceptors.d.ts.map +1 -0
  23. package/{src/core/generateInterceptors.ts → dist/core/generateInterceptors.js} +55 -109
  24. package/dist/core/generateInterceptors.js.map +1 -0
  25. package/dist/core/generateJsconfig.d.ts +45 -0
  26. package/dist/core/generateJsconfig.d.ts.map +1 -0
  27. package/{src/core/generateJsconfig.ts → dist/core/generateJsconfig.js} +32 -55
  28. package/dist/core/generateJsconfig.js.map +1 -0
  29. package/dist/core/moduleResolver.d.ts +22 -0
  30. package/dist/core/moduleResolver.d.ts.map +1 -0
  31. package/{src/core/moduleResolver.ts → dist/core/moduleResolver.js} +28 -62
  32. package/dist/core/moduleResolver.js.map +1 -0
  33. package/dist/core/preCompileFiles.d.ts +6 -0
  34. package/dist/core/preCompileFiles.d.ts.map +1 -0
  35. package/{src/core/preCompileFiles.ts → dist/core/preCompileFiles.js} +22 -48
  36. package/dist/core/preCompileFiles.js.map +1 -0
  37. package/dist/core/preCompileMagentoFiles.d.ts +3 -0
  38. package/dist/core/preCompileMagentoFiles.d.ts.map +1 -0
  39. package/{src/core/preCompileMagentoFiles.ts → dist/core/preCompileMagentoFiles.js} +4 -10
  40. package/dist/core/preCompileMagentoFiles.js.map +1 -0
  41. package/dist/core/themeResolverSync.d.ts +6 -0
  42. package/dist/core/themeResolverSync.d.ts.map +1 -0
  43. package/{src/core/themeResolverSync.ts → dist/core/themeResolverSync.js} +25 -26
  44. package/dist/core/themeResolverSync.js.map +1 -0
  45. package/dist/runtime/i18nCore.d.ts +71 -0
  46. package/dist/runtime/i18nCore.d.ts.map +1 -0
  47. package/{src/runtime/i18nCore.ts → dist/runtime/i18nCore.js} +47 -49
  48. package/dist/runtime/i18nCore.js.map +1 -0
  49. package/dist/runtime/interceptorManager.d.ts +45 -0
  50. package/dist/runtime/interceptorManager.d.ts.map +1 -0
  51. package/{src/runtime/interceptorManager.ts → dist/runtime/interceptorManager.js} +14 -72
  52. package/dist/runtime/interceptorManager.js.map +1 -0
  53. package/dist/runtime/islands.d.ts +45 -0
  54. package/dist/runtime/islands.d.ts.map +1 -0
  55. package/{src/runtime/islands.ts → dist/runtime/islands.js} +5 -30
  56. package/dist/runtime/islands.js.map +1 -0
  57. package/dist/runtime/sectionStoreCore.d.ts +108 -0
  58. package/dist/runtime/sectionStoreCore.d.ts.map +1 -0
  59. package/{src/runtime/sectionStoreCore.ts → dist/runtime/sectionStoreCore.js} +23 -93
  60. package/dist/runtime/sectionStoreCore.js.map +1 -0
  61. package/dist/utils/findComponents.d.ts +17 -0
  62. package/dist/utils/findComponents.d.ts.map +1 -0
  63. package/dist/utils/findComponents.js +66 -0
  64. package/dist/utils/findComponents.js.map +1 -0
  65. package/dist/utils/runWithConcurrency.d.ts +10 -0
  66. package/dist/utils/runWithConcurrency.d.ts.map +1 -0
  67. package/{src/utils/runWithConcurrency.ts → dist/utils/runWithConcurrency.js} +3 -9
  68. package/dist/utils/runWithConcurrency.js.map +1 -0
  69. package/dist/vite/defaultNodeResolver.d.ts +9 -0
  70. package/dist/vite/defaultNodeResolver.d.ts.map +1 -0
  71. package/{src/vite/defaultNodeResolver.ts → dist/vite/defaultNodeResolver.js} +3 -1
  72. package/dist/vite/defaultNodeResolver.js.map +1 -0
  73. package/dist/vite/inheritAssetsModuleResolver.d.ts +8 -0
  74. package/dist/vite/inheritAssetsModuleResolver.d.ts.map +1 -0
  75. package/{src/vite/inheritAssetsModuleResolver.ts → dist/vite/inheritAssetsModuleResolver.js} +6 -20
  76. package/dist/vite/inheritAssetsModuleResolver.js.map +1 -0
  77. package/dist/vite/inheritModuleResolver.d.ts +8 -0
  78. package/dist/vite/inheritModuleResolver.d.ts.map +1 -0
  79. package/{src/vite/inheritModuleResolver.ts → dist/vite/inheritModuleResolver.js} +4 -9
  80. package/dist/vite/inheritModuleResolver.js.map +1 -0
  81. package/dist/vite/interceptorsPlugin.d.ts +10 -0
  82. package/dist/vite/interceptorsPlugin.d.ts.map +1 -0
  83. package/{src/vite/interceptorsPlugin.ts → dist/vite/interceptorsPlugin.js} +12 -29
  84. package/dist/vite/interceptorsPlugin.js.map +1 -0
  85. package/dist/vite/magentoHrmRewrite.d.ts +6 -0
  86. package/dist/vite/magentoHrmRewrite.d.ts.map +1 -0
  87. package/{src/vite/magentoHrmRewrite.ts → dist/vite/magentoHrmRewrite.js} +16 -15
  88. package/dist/vite/magentoHrmRewrite.js.map +1 -0
  89. package/dist/vite/sharedPlugins.d.ts +35 -0
  90. package/dist/vite/sharedPlugins.d.ts.map +1 -0
  91. package/{src/vite/sharedPlugins.ts → dist/vite/sharedPlugins.js} +7 -9
  92. package/dist/vite/sharedPlugins.js.map +1 -0
  93. package/dist/vite/themeSourceWatcher.d.ts +16 -0
  94. package/dist/vite/themeSourceWatcher.d.ts.map +1 -0
  95. package/{src/vite/themeSourceWatcher.ts → dist/vite/themeSourceWatcher.js} +19 -24
  96. package/dist/vite/themeSourceWatcher.js.map +1 -0
  97. package/dist/vite/unresolvedModuleGuard.d.ts +17 -0
  98. package/dist/vite/unresolvedModuleGuard.d.ts.map +1 -0
  99. package/{src/vite/unresolvedModuleGuard.ts → dist/vite/unresolvedModuleGuard.js} +27 -27
  100. package/dist/vite/unresolvedModuleGuard.js.map +1 -0
  101. package/package.json +60 -10
  102. package/.github/workflows/ci.yml +0 -38
  103. package/.github/workflows/publish.yml +0 -36
  104. package/.oxlintrc.json +0 -19
  105. package/.prettierignore +0 -7
  106. package/.prettierrc.json +0 -7
  107. package/eslint.config.js +0 -24
  108. package/pnpm-workspace.yaml +0 -4
  109. package/src/utils/findComponents.ts +0 -83
  110. package/tsconfig.json +0 -34
  111. package/vitest.config.js +0 -18
  112. /package/{src → dist}/config/eslint.js +0 -0
  113. /package/{src → dist}/templates/base_main_js_file.js +0 -0
@@ -1,21 +1,14 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs/promises";
3
- import {
4
- precompileCss,
5
- precompileJs,
6
- precompileJsconfig,
7
- precompileTsconfig,
8
- } from "./preCompileFiles.ts";
9
- import configResolver from "./configResolver.ts";
10
- import { PRECOMPILED_FOLDER } from "../config/default.ts";
11
-
3
+ import { precompileCss, precompileJs, precompileJsconfig, precompileTsconfig, } from "./preCompileFiles.js";
4
+ import configResolver from "./configResolver.js";
5
+ import { PRECOMPILED_FOLDER } from "../config/default.js";
12
6
  // Guard per (theme, contract hash): repeated calls within one process (Vite
13
7
  // re-invokes the config) skip the work, while a different theme — or the same
14
8
  // theme after the contract changed (e.g. a module enabled/disabled mid dev
15
9
  // server) — re-precompiles. Keying on the hash, not just the theme name, makes
16
10
  // the invalidation dimension explicit instead of relying on process isolation.
17
11
  const precompiledByTheme = new Map();
18
-
19
12
  export default async (themeName) => {
20
13
  const contractHash = configResolver.getContractHash();
21
14
  if (precompiledByTheme.get(themeName) === contractHash) {
@@ -32,3 +25,4 @@ export default async (themeName) => {
32
25
  await precompileTsconfig(themeName);
33
26
  precompiledByTheme.set(themeName, contractHash);
34
27
  };
28
+ //# sourceMappingURL=preCompileMagentoFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preCompileMagentoFiles.js","sourceRoot":"","sources":["../../src/core/preCompileMagentoFiles.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EACH,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,+EAA+E;AAC/E,+EAA+E;AAC/E,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;AAErC,eAAe,KAAK,EAAE,SAAS,EAAE,EAAE;IAC/B,MAAM,YAAY,GAAG,cAAc,CAAC,eAAe,EAAE,CAAC;IACtD,IAAI,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,YAAY,EAAE,CAAC;QACrD,OAAO;IACX,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;IAC7D,wEAAwE;IACxE,wEAAwE;IACxE,MAAM,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,MAAM,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,MAAM,YAAY,CAAC,SAAS,CAAC,CAAC;IAC9B,MAAM,aAAa,CAAC,SAAS,CAAC,CAAC;IAC/B,MAAM,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACpC,MAAM,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACpC,kBAAkB,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AACpD,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare function getThemeConfig(themeName: any): Promise<any>;
2
+ declare const _default: {
3
+ getThemeConfig: typeof getThemeConfig;
4
+ };
5
+ export default _default;
6
+ //# sourceMappingURL=themeResolverSync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themeResolverSync.d.ts","sourceRoot":"","sources":["../../src/core/themeResolverSync.ts"],"names":[],"mappings":"AA0CA,wBAAsB,cAAc,CAAC,SAAS,KAAA,gBAkB7C;;;;AAGD,wBAEE"}
@@ -1,54 +1,53 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
1
9
  import path from "path";
2
10
  import fs from "fs";
3
11
  import deepmerge from "deepmerge";
4
- import { THEME_MODULE_WEB_PATH } from "../config/default.ts";
5
- import configResolver from "./configResolver.ts";
6
-
12
+ import { THEME_MODULE_WEB_PATH } from "../config/default.js";
13
+ import configResolver from "./configResolver.js";
7
14
  const themeConfigCache = new Map();
8
15
  const themeConfigPlainCache = new Map();
9
-
10
16
  function getThemeConfigPath(themeSrc) {
11
- return path.join(
12
- themeSrc,
13
- THEME_MODULE_WEB_PATH,
14
- configResolver.getMagentoConfig().THEME_CONFIG_FILE,
15
- );
17
+ return path.join(themeSrc, THEME_MODULE_WEB_PATH, configResolver.getMagentoConfig().THEME_CONFIG_FILE);
16
18
  }
17
-
18
19
  async function loadThemeConfig(themeDefinition, themeName) {
19
- if (!themeDefinition) return null;
20
- if (themeConfigPlainCache.has(themeName)) return themeConfigPlainCache.get(themeName);
21
-
20
+ if (!themeDefinition)
21
+ return null;
22
+ if (themeConfigPlainCache.has(themeName))
23
+ return themeConfigPlainCache.get(themeName);
22
24
  try {
23
25
  const configPath = getThemeConfigPath(themeDefinition.src);
24
26
  fs.accessSync(configPath, fs.constants.F_OK);
25
-
26
- let themeConfig = await import(pathToFileUrl(configPath));
27
+ let themeConfig = await import(__rewriteRelativeImportExtension(pathToFileUrl(configPath)));
27
28
  themeConfig = themeConfig.default ?? themeConfig;
28
-
29
29
  themeConfigPlainCache.set(themeName, themeConfig);
30
30
  return deepmerge({}, themeConfig);
31
- } catch (error) {
31
+ }
32
+ catch (error) {
32
33
  console.error(`Failed to load configuration for theme "${themeName}":`, error.message);
33
34
  return null;
34
35
  }
35
36
  }
36
-
37
37
  function pathToFileUrl(filePath) {
38
38
  const resolvedPath = path.resolve(filePath);
39
39
  const fileUrl = new URL(`file://${resolvedPath}`);
40
40
  return fileUrl.href;
41
41
  }
42
-
43
42
  export async function getThemeConfig(themeName) {
44
- if (themeConfigCache.has(themeName)) return themeConfigCache.get(themeName);
45
-
43
+ if (themeConfigCache.has(themeName))
44
+ return themeConfigCache.get(themeName);
46
45
  const themeDefinition = configResolver.getMagentoConfig().themes[themeName];
47
- if (!themeDefinition) return null;
48
-
46
+ if (!themeDefinition)
47
+ return null;
49
48
  let themeConfig = await loadThemeConfig(themeDefinition, themeName);
50
- if (!themeConfig) return null;
51
-
49
+ if (!themeConfig)
50
+ return null;
52
51
  themeConfig.includeCssSourceFromParentThemes ??= true;
53
52
  themeConfig.ignoredCssFromModules ??= [];
54
53
  themeConfig.exposeNpmPackages ??= [];
@@ -59,8 +58,8 @@ export async function getThemeConfig(themeName) {
59
58
  themeConfigCache.set(themeName, themeConfig);
60
59
  return themeConfig;
61
60
  }
62
-
63
61
  // Export default con todo
64
62
  export default {
65
63
  getThemeConfig,
66
64
  };
65
+ //# sourceMappingURL=themeResolverSync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themeResolverSync.js","sourceRoot":"","sources":["../../src/core/themeResolverSync.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,cAAc,MAAM,qBAAqB,CAAC;AAEjD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;AACnC,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAE,CAAC;AAExC,SAAS,kBAAkB,CAAC,QAAQ;IAChC,OAAO,IAAI,CAAC,IAAI,CACZ,QAAQ,EACR,qBAAqB,EACrB,cAAc,CAAC,gBAAgB,EAAE,CAAC,iBAAiB,CACtD,CAAC;AACN,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,eAAe,EAAE,SAAS;IACrD,IAAI,CAAC,eAAe;QAAE,OAAO,IAAI,CAAC;IAClC,IAAI,qBAAqB,CAAC,GAAG,CAAC,SAAS,CAAC;QAAE,OAAO,qBAAqB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAEtF,IAAI,CAAC;QACD,MAAM,UAAU,GAAG,kBAAkB,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAC3D,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAE7C,IAAI,WAAW,GAAG,MAAM,MAAM,kCAAC,aAAa,CAAC,UAAU,CAAC,EAAC,CAAC;QAC1D,WAAW,GAAG,WAAW,CAAC,OAAO,IAAI,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E,EAAE,WAAW,CAAC,CAAC;IAC7D,CAAC;IACD,gBAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC7C,OAAO,WAAW,CAAC;AACvB,CAAC;AAED,0BAA0B;AAC1B,eAAe;IACX,cAAc;CACjB,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Framework i18n core — Magento-parity phrase translation for the Vue/ESM side.
3
+ *
4
+ * Mirrors Magento's `$t` / `$.mage.__`: a phrase is looked up in the dictionary
5
+ * (the per-locale `js-translation.json` Magento already generates during static
6
+ * deploy) and falls back to the original phrase when absent; then `%1`, `%2`, …
7
+ * placeholders are substituted positionally.
8
+ *
9
+ * Kept free of Vue and the DOM so it is unit-testable in isolation — the Vue
10
+ * plugin (shipped as a module web asset) wraps these primitives.
11
+ */
12
+ export interface I18nConfig {
13
+ locale?: string;
14
+ dictionaryUrl?: string;
15
+ }
16
+ interface I18nScope {
17
+ __MAGE_OBSIDIAN_I18N__?: I18nConfig;
18
+ }
19
+ export type Dictionary = Record<string, string>;
20
+ declare global {
21
+ interface Window {
22
+ __MAGE_OBSIDIAN_I18N__?: I18nConfig;
23
+ }
24
+ }
25
+ /**
26
+ * Replace `%1`, `%2`, … with positional args. An out-of-range placeholder is
27
+ * left untouched so a malformed phrase never throws or yields "undefined".
28
+ */
29
+ export declare function interpolate(text: string, args?: unknown[]): string;
30
+ /**
31
+ * Translate a phrase against a dictionary, falling back to the phrase itself,
32
+ * then interpolate placeholders.
33
+ */
34
+ export declare function translatePhrase(dictionary: Dictionary | null | undefined, phrase: string, args?: unknown[]): string;
35
+ /**
36
+ * Read the runtime i18n config published by PHP as `window.__MAGE_OBSIDIAN_I18N__`.
37
+ * Returns sane defaults when absent so the layer degrades to passthrough.
38
+ */
39
+ export declare function readI18nConfig(scope?: I18nScope | undefined): {
40
+ locale: string;
41
+ dictionaryUrl: string | null;
42
+ };
43
+ /**
44
+ * Fetch and cache a dictionary by URL. The fetch happens at most once per URL
45
+ * regardless of how many Vue apps request it. Magento emits `[]` for an empty
46
+ * dictionary, which is normalized to `{}`; any failure degrades to `{}` so the
47
+ * UI keeps rendering original phrases.
48
+ */
49
+ export declare function loadDictionary(url: string | null | undefined, fetchImpl?: typeof fetch | undefined): Promise<Dictionary>;
50
+ /**
51
+ * Test-only: clear the dictionary cache between cases.
52
+ */
53
+ export declare function _resetDictionaryCache(): void;
54
+ /**
55
+ * i18n facade for plain (non-Vue) ESM enhancers. Translation is exposed as a
56
+ * `$t` METHOD on purpose: minifiers preserve property names, so the compiled
57
+ * bundle keeps the literal `$t("…")` call that Magento's native JS translation
58
+ * scanner discovers (`Magento\Translation\Model\Js\Config`). A bare imported
59
+ * function would be renamed to a single letter and the phrase would never reach
60
+ * `js-translation.json`. The dictionary loads once (shared cache with the Vue
61
+ * runtime) and translation degrades to the original phrase until it resolves.
62
+ */
63
+ export declare const i18n: {
64
+ $t(phrase: string, ...args: unknown[]): string;
65
+ };
66
+ /**
67
+ * Test-only: reset the facade dictionary state between cases.
68
+ */
69
+ export declare function _resetI18nFacade(): void;
70
+ export {};
71
+ //# sourceMappingURL=i18nCore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18nCore.d.ts","sourceRoot":"","sources":["../../src/runtime/i18nCore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,UAAU;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,UAAU,SAAS;IACf,sBAAsB,CAAC,EAAE,UAAU,CAAC;CACvC;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAGhD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,sBAAsB,CAAC,EAAE,UAAU,CAAC;KACvC;CACJ;AAID;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,OAAO,EAAO,GAAG,MAAM,CAQtE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC3B,UAAU,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,EACzC,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,OAAO,EAAO,GACrB,MAAM,CAIR;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC1B,KAAK,GAAE,SAAS,GAAG,SAA8D,GAClF;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAMlD;AAID;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC9B,SAAS,GAAE,OAAO,KAAK,GAAG,SAA4D,GACvF,OAAO,CAAC,UAAU,CAAC,CAoBrB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAgBD;;;;;;;;GAQG;AACH,eAAO,MAAM,IAAI;eACF,MAAM,WAAW,OAAO,EAAE,GAAG,MAAM;CAIjD,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC"}
@@ -9,32 +9,12 @@
9
9
  * Kept free of Vue and the DOM so it is unit-testable in isolation — the Vue
10
10
  * plugin (shipped as a module web asset) wraps these primitives.
11
11
  */
12
-
13
- export interface I18nConfig {
14
- locale?: string;
15
- dictionaryUrl?: string;
16
- }
17
-
18
- interface I18nScope {
19
- __MAGE_OBSIDIAN_I18N__?: I18nConfig;
20
- }
21
-
22
- export type Dictionary = Record<string, string>;
23
-
24
- // Published by PHP on the page before the ESM runtime loads.
25
- declare global {
26
- interface Window {
27
- __MAGE_OBSIDIAN_I18N__?: I18nConfig;
28
- }
29
- }
30
-
31
12
  const PLACEHOLDER = /%(\d+)/g;
32
-
33
13
  /**
34
14
  * Replace `%1`, `%2`, … with positional args. An out-of-range placeholder is
35
15
  * left untouched so a malformed phrase never throws or yields "undefined".
36
16
  */
37
- export function interpolate(text: string, args: unknown[] = []): string {
17
+ export function interpolate(text, args = []) {
38
18
  if (typeof text !== "string" || !args || args.length === 0) {
39
19
  return text;
40
20
  }
@@ -43,47 +23,34 @@ export function interpolate(text: string, args: unknown[] = []): string {
43
23
  return value === undefined ? match : String(value);
44
24
  });
45
25
  }
46
-
47
26
  /**
48
27
  * Translate a phrase against a dictionary, falling back to the phrase itself,
49
28
  * then interpolate placeholders.
50
29
  */
51
- export function translatePhrase(
52
- dictionary: Dictionary | null | undefined,
53
- phrase: string,
54
- args: unknown[] = [],
55
- ): string {
30
+ export function translatePhrase(dictionary, phrase, args = []) {
56
31
  const dict = dictionary && typeof dictionary === "object" ? dictionary : {};
57
32
  const translated = Object.prototype.hasOwnProperty.call(dict, phrase) ? dict[phrase] : phrase;
58
33
  return interpolate(translated, args);
59
34
  }
60
-
61
35
  /**
62
36
  * Read the runtime i18n config published by PHP as `window.__MAGE_OBSIDIAN_I18N__`.
63
37
  * Returns sane defaults when absent so the layer degrades to passthrough.
64
38
  */
65
- export function readI18nConfig(
66
- scope: I18nScope | undefined = typeof window !== "undefined" ? window : undefined,
67
- ): { locale: string; dictionaryUrl: string | null } {
39
+ export function readI18nConfig(scope = typeof window !== "undefined" ? window : undefined) {
68
40
  const config = scope && scope.__MAGE_OBSIDIAN_I18N__;
69
41
  return {
70
42
  locale: (config && config.locale) || "en_US",
71
43
  dictionaryUrl: (config && config.dictionaryUrl) || null,
72
44
  };
73
45
  }
74
-
75
- const dictionaryCache = new Map<string, Promise<Dictionary>>();
76
-
46
+ const dictionaryCache = new Map();
77
47
  /**
78
48
  * Fetch and cache a dictionary by URL. The fetch happens at most once per URL
79
49
  * regardless of how many Vue apps request it. Magento emits `[]` for an empty
80
50
  * dictionary, which is normalized to `{}`; any failure degrades to `{}` so the
81
51
  * UI keeps rendering original phrases.
82
52
  */
83
- export function loadDictionary(
84
- url: string | null | undefined,
85
- fetchImpl: typeof fetch | undefined = typeof fetch !== "undefined" ? fetch : undefined,
86
- ): Promise<Dictionary> {
53
+ export function loadDictionary(url, fetchImpl = typeof fetch !== "undefined" ? fetch : undefined) {
87
54
  if (!url) {
88
55
  return Promise.resolve({});
89
56
  }
@@ -91,23 +58,54 @@ export function loadDictionary(
91
58
  if (typeof fetchImpl !== "function") {
92
59
  return Promise.resolve({});
93
60
  }
94
- const promise: Promise<Dictionary> = fetchImpl(url)
61
+ const promise = fetchImpl(url)
95
62
  .then((res) => (res && res.ok ? res.json() : {}))
96
- .then(
97
- (data: unknown): Dictionary =>
98
- data && typeof data === "object" && !Array.isArray(data)
99
- ? (data as Dictionary)
100
- : {},
101
- )
102
- .catch((): Dictionary => ({}));
63
+ .then((data) => data && typeof data === "object" && !Array.isArray(data)
64
+ ? data
65
+ : {})
66
+ .catch(() => ({}));
103
67
  dictionaryCache.set(url, promise);
104
68
  }
105
- return dictionaryCache.get(url)!;
69
+ return dictionaryCache.get(url);
106
70
  }
107
-
108
71
  /**
109
72
  * Test-only: clear the dictionary cache between cases.
110
73
  */
111
- export function _resetDictionaryCache(): void {
74
+ export function _resetDictionaryCache() {
112
75
  dictionaryCache.clear();
113
76
  }
77
+ let facadeDictionary = {};
78
+ let facadeLoadStarted = false;
79
+ function ensureFacadeDictionary() {
80
+ if (facadeLoadStarted) {
81
+ return;
82
+ }
83
+ facadeLoadStarted = true;
84
+ const { dictionaryUrl } = readI18nConfig();
85
+ loadDictionary(dictionaryUrl).then((loaded) => {
86
+ facadeDictionary = loaded;
87
+ });
88
+ }
89
+ /**
90
+ * i18n facade for plain (non-Vue) ESM enhancers. Translation is exposed as a
91
+ * `$t` METHOD on purpose: minifiers preserve property names, so the compiled
92
+ * bundle keeps the literal `$t("…")` call that Magento's native JS translation
93
+ * scanner discovers (`Magento\Translation\Model\Js\Config`). A bare imported
94
+ * function would be renamed to a single letter and the phrase would never reach
95
+ * `js-translation.json`. The dictionary loads once (shared cache with the Vue
96
+ * runtime) and translation degrades to the original phrase until it resolves.
97
+ */
98
+ export const i18n = {
99
+ $t(phrase, ...args) {
100
+ ensureFacadeDictionary();
101
+ return translatePhrase(facadeDictionary, phrase, args);
102
+ },
103
+ };
104
+ /**
105
+ * Test-only: reset the facade dictionary state between cases.
106
+ */
107
+ export function _resetI18nFacade() {
108
+ facadeDictionary = {};
109
+ facadeLoadStarted = false;
110
+ }
111
+ //# sourceMappingURL=i18nCore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18nCore.js","sourceRoot":"","sources":["../../src/runtime/i18nCore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoBH,MAAM,WAAW,GAAG,SAAS,CAAC;AAE9B;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,OAAkB,EAAE;IAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QACtC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC3B,UAAyC,EACzC,MAAc,EACd,OAAkB,EAAE;IAEpB,MAAM,IAAI,GAAG,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5E,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,M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I,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YACpD,CAAC,CAAE,IAAmB;YACtB,CAAC,CAAC,EAAE,CACf;aACA,KAAK,CAAC,GAAe,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACnC,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACjC,eAAe,CAAC,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,IAAI,gBAAgB,GAAe,EAAE,CAAC;AACtC,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B,SAAS,sBAAsB;IAC3B,IAAI,iBAAiB,EAAE,CAAC;QACpB,OAAO;IACX,CAAC;IACD,iBAAiB,GAAG,IAAI,CAAC;IACzB,MAAM,EAAE,aAAa,EAAE,GAAG,cAAc,EAAE,CAAC;IAC3C,cAAc,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QAC1C,gBAAgB,GAAG,MAAM,CAAC;IAC9B,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAChB,EAAE,CAAC,MAAc,EAAE,GAAG,IAAe;QACjC,sBAAsB,EAAE,CAAC;QACzB,OAAO,eAAe,CAAC,gBAAgB,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC5B,gBAAgB,GAAG,EAAE,CAAC;IACtB,iBAAiB,GAAG,KAAK,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,45 @@
1
+ export type InterceptorType = "before" | "around" | "after";
2
+ export type InterceptorHandler = (subject: any, ...rest: any[]) => any;
3
+ export interface InterceptorEntry {
4
+ name: string;
5
+ handler: InterceptorHandler;
6
+ sortOrder: number;
7
+ }
8
+ type InterceptorBuckets = Record<InterceptorType, InterceptorEntry[]>;
9
+ declare class InterceptorManager {
10
+ interceptors: Record<string, InterceptorBuckets>;
11
+ constructor();
12
+ /**
13
+ * Register an interceptor. `target` is the function/method name to wrap;
14
+ * `name` is a unique id; `sortOrder` controls execution order.
15
+ */
16
+ addInterceptor(target: string, name: string, type: InterceptorType, handler: InterceptorHandler, sortOrder?: number): void;
17
+ /**
18
+ * Execute the intercepted method chain synchronously.
19
+ *
20
+ * Handlers receive the intercepted module exports as an explicit `subject`
21
+ * first argument (Magento plugin parity): before(subject, ...args),
22
+ * around(subject, proceed, ...args), after(subject, result, ...args).
23
+ * `this` is still bound to the same object, so handlers written against the
24
+ * legacy `this`-based access keep working (arrow functions now have a path
25
+ * to the subject they could not reach via `this`).
26
+ */
27
+ executeSync(target: string, originalMethod: (...args: any[]) => any, context: any, ...args: any[]): any;
28
+ /**
29
+ * Execute the intercepted method chain.
30
+ *
31
+ * Same `subject`-first contract as {@link executeSync}: before(subject,
32
+ * ...args), around(subject, proceed, ...args), after(subject, result,
33
+ * ...args), with `this` still bound to the subject for backward compat.
34
+ */
35
+ execute(target: string, originalMethod: (...args: any[]) => any, context: any, ...args: any[]): Promise<any>;
36
+ /**
37
+ * Create a proxy that intercepts method calls on an object (e.g. module
38
+ * exports). `namespace` scopes the interceptor keys; `useAsync` picks the
39
+ * async or sync chain.
40
+ */
41
+ intercept(target: object, namespace: string, useAsync?: boolean): any;
42
+ }
43
+ declare const _default: InterceptorManager;
44
+ export default _default;
45
+ //# sourceMappingURL=interceptorManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interceptorManager.d.ts","sourceRoot":"","sources":["../../src/runtime/interceptorManager.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAI5D,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAEvE,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,kBAAkB,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,KAAK,kBAAkB,GAAG,MAAM,CAAC,eAAe,EAAE,gBAAgB,EAAE,CAAC,CAAC;AAQtE,cAAM,kBAAkB;IAGZ,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;;IAMzD;;;OAGG;IACH,cAAc,CACV,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,kBAAkB,EAC3B,SAAS,GAAE,MAAW;IAY1B;;;;;;;;;OASG;IACH,WAAW,CACP,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACvC,OAAO,EAAE,GAAG,EACZ,GAAG,IAAI,EAAE,GAAG,EAAE,GACf,GAAG;IAoCN;;;;;;OAMG;IACG,OAAO,CACT,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACvC,OAAO,EAAE,GAAG,EACZ,GAAG,IAAI,EAAE,GAAG,EAAE,GACf,OAAO,CAAC,GAAG,CAAC;IA6Cf;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAc;CAoBxE;;AAED,wBAAwC"}
@@ -1,43 +1,16 @@
1
- export type InterceptorType = "before" | "around" | "after";
2
-
3
- // Handlers receive the intercepted subject first (Magento plugin parity); the
4
- // remaining shape varies per type, so the tail stays `any[]`.
5
- export type InterceptorHandler = (subject: any, ...rest: any[]) => any;
6
-
7
- export interface InterceptorEntry {
8
- name: string;
9
- handler: InterceptorHandler;
10
- sortOrder: number;
11
- }
12
-
13
- type InterceptorBuckets = Record<InterceptorType, InterceptorEntry[]>;
14
-
15
- const TYPES: readonly InterceptorType[] = ["before", "around", "after"];
16
-
17
- function emptyBuckets(): InterceptorBuckets {
1
+ const TYPES = ["before", "around", "after"];
2
+ function emptyBuckets() {
18
3
  return { before: [], around: [], after: [] };
19
4
  }
20
-
21
5
  class InterceptorManager {
22
- // `declare` keeps this type-only (erasable): the runtime field is created by
23
- // the constructor assignment below, type-stripping emits nothing for this.
24
- declare interceptors: Record<string, InterceptorBuckets>;
25
-
26
6
  constructor() {
27
7
  this.interceptors = {};
28
8
  }
29
-
30
9
  /**
31
10
  * Register an interceptor. `target` is the function/method name to wrap;
32
11
  * `name` is a unique id; `sortOrder` controls execution order.
33
12
  */
34
- addInterceptor(
35
- target: string,
36
- name: string,
37
- type: InterceptorType,
38
- handler: InterceptorHandler,
39
- sortOrder: number = 10,
40
- ) {
13
+ addInterceptor(target, name, type, handler, sortOrder = 10) {
41
14
  if (!this.interceptors[target]) {
42
15
  this.interceptors[target] = emptyBuckets();
43
16
  }
@@ -47,7 +20,6 @@ class InterceptorManager {
47
20
  this.interceptors[target][type].push({ name, handler, sortOrder });
48
21
  this.interceptors[target][type].sort((a, b) => a.sortOrder - b.sortOrder);
49
22
  }
50
-
51
23
  /**
52
24
  * Execute the intercepted method chain synchronously.
53
25
  *
@@ -58,14 +30,8 @@ class InterceptorManager {
58
30
  * legacy `this`-based access keep working (arrow functions now have a path
59
31
  * to the subject they could not reach via `this`).
60
32
  */
61
- executeSync(
62
- target: string,
63
- originalMethod: (...args: any[]) => any,
64
- context: any,
65
- ...args: any[]
66
- ): any {
33
+ executeSync(target, originalMethod, context, ...args) {
67
34
  const interceptors = this.interceptors[target] || emptyBuckets();
68
-
69
35
  // Execute 'before' interceptors
70
36
  for (const interceptor of interceptors.before) {
71
37
  const result = interceptor.handler.apply(context, [context, ...args]);
@@ -73,32 +39,26 @@ class InterceptorManager {
73
39
  args = result;
74
40
  }
75
41
  }
76
-
77
42
  // Execute 'around' interceptors
78
- let methodToExecute = (...currentArgs: any[]) => {
43
+ let methodToExecute = (...currentArgs) => {
79
44
  return originalMethod.apply(context, currentArgs);
80
45
  };
81
-
82
46
  if (interceptors.around.length > 0) {
83
47
  const aroundInterceptors = [...interceptors.around].reverse();
84
48
  for (const interceptor of aroundInterceptors) {
85
49
  const next = methodToExecute;
86
- methodToExecute = (...currentArgs: any[]) => {
50
+ methodToExecute = (...currentArgs) => {
87
51
  return interceptor.handler.apply(context, [context, next, ...currentArgs]);
88
52
  };
89
53
  }
90
54
  }
91
-
92
55
  let result = methodToExecute(...args);
93
-
94
56
  // Execute 'after' interceptors
95
57
  for (const interceptor of interceptors.after) {
96
58
  result = interceptor.handler.apply(context, [context, result, ...args]);
97
59
  }
98
-
99
60
  return result;
100
61
  }
101
-
102
62
  /**
103
63
  * Execute the intercepted method chain.
104
64
  *
@@ -106,14 +66,8 @@ class InterceptorManager {
106
66
  * ...args), around(subject, proceed, ...args), after(subject, result,
107
67
  * ...args), with `this` still bound to the subject for backward compat.
108
68
  */
109
- async execute(
110
- target: string,
111
- originalMethod: (...args: any[]) => any,
112
- context: any,
113
- ...args: any[]
114
- ): Promise<any> {
69
+ async execute(target, originalMethod, context, ...args) {
115
70
  const interceptors = this.interceptors[target] || emptyBuckets();
116
-
117
71
  // Execute 'before' interceptors
118
72
  // Before interceptors receive (subject, ...args) and can modify args by
119
73
  // returning an array of the (subject-less) args.
@@ -123,19 +77,17 @@ class InterceptorManager {
123
77
  args = result;
124
78
  }
125
79
  }
126
-
127
80
  // Execute 'around' interceptors
128
81
  // Around interceptors receive (subject, proceed, ...args)
129
- let methodToExecute = async (...currentArgs: any[]) => {
82
+ let methodToExecute = async (...currentArgs) => {
130
83
  return await originalMethod.apply(context, currentArgs);
131
84
  };
132
-
133
85
  // Wrap around interceptors: first registered is outer-most
134
86
  if (interceptors.around.length > 0) {
135
87
  const aroundInterceptors = [...interceptors.around].reverse();
136
88
  for (const interceptor of aroundInterceptors) {
137
89
  const next = methodToExecute;
138
- methodToExecute = async (...currentArgs: any[]) => {
90
+ methodToExecute = async (...currentArgs) => {
139
91
  return await interceptor.handler.apply(context, [
140
92
  context,
141
93
  next,
@@ -144,37 +96,27 @@ class InterceptorManager {
144
96
  };
145
97
  }
146
98
  }
147
-
148
99
  let result = await methodToExecute(...args);
149
-
150
100
  // Execute 'after' interceptors
151
101
  // After interceptors receive (subject, result, ...args) and must return result
152
102
  for (const interceptor of interceptors.after) {
153
103
  result = await interceptor.handler.apply(context, [context, result, ...args]);
154
104
  }
155
-
156
105
  return result;
157
106
  }
158
-
159
107
  /**
160
108
  * Create a proxy that intercepts method calls on an object (e.g. module
161
109
  * exports). `namespace` scopes the interceptor keys; `useAsync` picks the
162
110
  * async or sync chain.
163
111
  */
164
- intercept(target: object, namespace: string, useAsync: boolean = true) {
112
+ intercept(target, namespace, useAsync = true) {
165
113
  return new Proxy(target, {
166
- get: (obj: any, prop) => {
114
+ get: (obj, prop) => {
167
115
  const value = obj[prop];
168
116
  if (typeof value === "function") {
169
- return (...args: any[]) => {
117
+ return (...args) => {
170
118
  const method = useAsync ? this.execute : this.executeSync;
171
- return method.call(
172
- this,
173
- `${namespace}::${String(prop)}`,
174
- value,
175
- obj,
176
- ...args,
177
- );
119
+ return method.call(this, `${namespace}::${String(prop)}`, value, obj, ...args);
178
120
  };
179
121
  }
180
122
  return value;
@@ -182,5 +124,5 @@ class InterceptorManager {
182
124
  });
183
125
  }
184
126
  }
185
-
186
127
  export default new InterceptorManager();
128
+ //# sourceMappingURL=interceptorManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interceptorManager.js","sourceRoot":"","sources":["../../src/runtime/interceptorManager.ts"],"names":[],"mappings":"AAcA,MAAM,KAAK,GAA+B,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAExE,SAAS,YAAY;IACjB,OAAO,E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