@bleedingdev/modern-js-plugin-i18n 3.2.0-ultramodern.11 → 3.2.0-ultramodern.110

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 (97) hide show
  1. package/dist/cjs/cli/index.js +32 -5
  2. package/dist/cjs/runtime/I18nLink.js +21 -22
  3. package/dist/cjs/runtime/context.js +41 -10
  4. package/dist/cjs/runtime/hooks.js +17 -10
  5. package/dist/cjs/runtime/i18n/backend/config.js +9 -5
  6. package/dist/cjs/runtime/i18n/backend/defaults.js +15 -10
  7. package/dist/cjs/runtime/i18n/backend/defaults.node.js +16 -11
  8. package/dist/cjs/runtime/i18n/backend/index.js +9 -5
  9. package/dist/cjs/runtime/i18n/backend/middleware.common.js +9 -5
  10. package/dist/cjs/runtime/i18n/backend/middleware.js +9 -5
  11. package/dist/cjs/runtime/i18n/backend/middleware.node.js +13 -9
  12. package/dist/cjs/runtime/i18n/backend/sdk-backend.js +9 -5
  13. package/dist/cjs/runtime/i18n/backend/sdk-event.js +16 -11
  14. package/dist/cjs/runtime/i18n/detection/config.js +9 -5
  15. package/dist/cjs/runtime/i18n/detection/index.js +9 -5
  16. package/dist/cjs/runtime/i18n/detection/middleware.js +9 -5
  17. package/dist/cjs/runtime/i18n/detection/middleware.node.js +9 -5
  18. package/dist/cjs/runtime/i18n/index.js +9 -5
  19. package/dist/cjs/runtime/i18n/instance.js +17 -37
  20. package/dist/cjs/runtime/i18n/react-i18next.js +53 -0
  21. package/dist/cjs/runtime/i18n/utils.js +9 -17
  22. package/dist/cjs/runtime/index.js +27 -15
  23. package/dist/cjs/runtime/routerAdapter.js +167 -0
  24. package/dist/cjs/runtime/utils.js +72 -99
  25. package/dist/cjs/server/index.js +69 -13
  26. package/dist/cjs/shared/deepMerge.js +12 -8
  27. package/dist/cjs/shared/detection.js +9 -5
  28. package/dist/cjs/shared/localisedUrls.js +241 -0
  29. package/dist/cjs/shared/utils.js +15 -11
  30. package/dist/esm/cli/index.mjs +23 -0
  31. package/dist/esm/runtime/I18nLink.mjs +12 -17
  32. package/dist/esm/runtime/context.mjs +34 -7
  33. package/dist/esm/runtime/hooks.mjs +9 -6
  34. package/dist/esm/runtime/i18n/backend/defaults.mjs +1 -1
  35. package/dist/esm/runtime/i18n/backend/defaults.node.mjs +2 -2
  36. package/dist/esm/runtime/i18n/backend/middleware.node.mjs +3 -3
  37. package/dist/esm/runtime/i18n/instance.mjs +1 -19
  38. package/dist/esm/runtime/i18n/react-i18next.mjs +15 -0
  39. package/dist/esm/runtime/i18n/utils.mjs +0 -12
  40. package/dist/esm/runtime/index.mjs +19 -11
  41. package/dist/esm/runtime/routerAdapter.mjs +129 -0
  42. package/dist/esm/runtime/utils.mjs +11 -30
  43. package/dist/esm/server/index.mjs +53 -7
  44. package/dist/esm/shared/localisedUrls.mjs +191 -0
  45. package/dist/esm-node/cli/index.mjs +23 -0
  46. package/dist/esm-node/runtime/I18nLink.mjs +12 -17
  47. package/dist/esm-node/runtime/context.mjs +34 -7
  48. package/dist/esm-node/runtime/hooks.mjs +9 -6
  49. package/dist/esm-node/runtime/i18n/backend/defaults.mjs +1 -1
  50. package/dist/esm-node/runtime/i18n/backend/defaults.node.mjs +2 -2
  51. package/dist/esm-node/runtime/i18n/backend/middleware.node.mjs +3 -3
  52. package/dist/esm-node/runtime/i18n/instance.mjs +1 -19
  53. package/dist/esm-node/runtime/i18n/react-i18next.mjs +16 -0
  54. package/dist/esm-node/runtime/i18n/utils.mjs +0 -12
  55. package/dist/esm-node/runtime/index.mjs +19 -11
  56. package/dist/esm-node/runtime/routerAdapter.mjs +130 -0
  57. package/dist/esm-node/runtime/utils.mjs +11 -30
  58. package/dist/esm-node/server/index.mjs +53 -7
  59. package/dist/esm-node/shared/localisedUrls.mjs +192 -0
  60. package/dist/types/cli/index.d.ts +1 -0
  61. package/dist/types/runtime/I18nLink.d.ts +15 -0
  62. package/dist/types/runtime/context.d.ts +3 -0
  63. package/dist/types/runtime/hooks.d.ts +4 -2
  64. package/dist/types/runtime/i18n/backend/middleware.node.d.ts +1 -1
  65. package/dist/types/runtime/i18n/instance.d.ts +4 -6
  66. package/dist/types/runtime/i18n/react-i18next.d.ts +7 -0
  67. package/dist/types/runtime/index.d.ts +1 -0
  68. package/dist/types/runtime/routerAdapter.d.ts +26 -0
  69. package/dist/types/runtime/types.d.ts +1 -1
  70. package/dist/types/runtime/utils.d.ts +2 -7
  71. package/dist/types/server/index.d.ts +6 -0
  72. package/dist/types/shared/localisedUrls.d.ts +13 -0
  73. package/dist/types/shared/type.d.ts +12 -0
  74. package/package.json +23 -27
  75. package/rstest.config.mts +39 -0
  76. package/src/cli/index.ts +44 -1
  77. package/src/runtime/I18nLink.tsx +13 -17
  78. package/src/runtime/context.tsx +45 -7
  79. package/src/runtime/hooks.ts +13 -4
  80. package/src/runtime/i18n/backend/defaults.node.ts +2 -2
  81. package/src/runtime/i18n/backend/defaults.ts +3 -1
  82. package/src/runtime/i18n/backend/middleware.node.ts +1 -1
  83. package/src/runtime/i18n/instance.ts +3 -30
  84. package/src/runtime/i18n/react-i18next.ts +25 -0
  85. package/src/runtime/i18n/utils.ts +4 -26
  86. package/src/runtime/index.tsx +23 -10
  87. package/src/runtime/routerAdapter.tsx +333 -0
  88. package/src/runtime/types.ts +1 -1
  89. package/src/runtime/utils.ts +22 -34
  90. package/src/server/index.ts +117 -10
  91. package/src/shared/localisedUrls.ts +393 -0
  92. package/src/shared/type.ts +12 -0
  93. package/tests/i18nUtils.test.ts +52 -0
  94. package/tests/localisedUrls.test.ts +312 -0
  95. package/tests/routerAdapter.test.tsx +452 -0
  96. package/dist/esm/rslib-runtime.mjs +0 -18
  97. package/dist/esm-node/rslib-runtime.mjs +0 -19
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
10
10
  };
11
11
  })();
12
12
  (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
18
22
  };
19
23
  })();
20
24
  (()=>{
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -23,16 +27,6 @@ var __webpack_require__ = {};
23
27
  })();
24
28
  var __webpack_exports__ = {};
25
29
  __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- getActualI18nextInstance: ()=>getActualI18nextInstance,
28
- getI18nInstance: ()=>getI18nInstance,
29
- getI18nWrapperI18nextInstance: ()=>getI18nWrapperI18nextInstance,
30
- getI18nextInstanceForProvider: ()=>getI18nextInstanceForProvider,
31
- getI18nextProvider: ()=>getI18nextProvider,
32
- getInitReactI18next: ()=>getInitReactI18next,
33
- isI18nInstance: ()=>isI18nInstance,
34
- isI18nWrapperInstance: ()=>isI18nWrapperInstance
35
- });
36
30
  function isI18nWrapperInstance(obj) {
37
31
  if (!obj || 'object' != typeof obj) return false;
38
32
  if (!obj.i18nInstance || 'object' != typeof obj.i18nInstance) return false;
@@ -75,14 +69,6 @@ async function createI18nextInstance() {
75
69
  return null;
76
70
  }
77
71
  }
78
- async function tryImportReactI18next() {
79
- try {
80
- const reactI18next = await import("react-i18next");
81
- return reactI18next;
82
- } catch (error) {
83
- return null;
84
- }
85
- }
86
72
  function getI18nextInstanceForProvider(instance) {
87
73
  if (isI18nWrapperInstance(instance)) {
88
74
  const i18nextInstance = getI18nWrapperI18nextInstance(instance);
@@ -99,22 +85,18 @@ async function getI18nInstance(userInstance) {
99
85
  if (i18nextInstance) return i18nextInstance;
100
86
  throw new Error('No i18n instance found');
101
87
  }
102
- async function getInitReactI18next() {
103
- const reactI18nextModule = await tryImportReactI18next();
104
- if (reactI18nextModule) return reactI18nextModule.initReactI18next;
105
- return null;
106
- }
107
- async function getI18nextProvider() {
108
- const reactI18nextModule = await tryImportReactI18next();
109
- if (reactI18nextModule) return reactI18nextModule.I18nextProvider;
110
- return null;
111
- }
88
+ __webpack_require__.d(__webpack_exports__, {
89
+ getActualI18nextInstance: ()=>getActualI18nextInstance,
90
+ getI18nInstance: ()=>getI18nInstance,
91
+ getI18nWrapperI18nextInstance: ()=>getI18nWrapperI18nextInstance,
92
+ getI18nextInstanceForProvider: ()=>getI18nextInstanceForProvider,
93
+ isI18nInstance: ()=>isI18nInstance,
94
+ isI18nWrapperInstance: ()=>isI18nWrapperInstance
95
+ });
112
96
  exports.getActualI18nextInstance = __webpack_exports__.getActualI18nextInstance;
113
97
  exports.getI18nInstance = __webpack_exports__.getI18nInstance;
114
98
  exports.getI18nWrapperI18nextInstance = __webpack_exports__.getI18nWrapperI18nextInstance;
115
99
  exports.getI18nextInstanceForProvider = __webpack_exports__.getI18nextInstanceForProvider;
116
- exports.getI18nextProvider = __webpack_exports__.getI18nextProvider;
117
- exports.getInitReactI18next = __webpack_exports__.getInitReactI18next;
118
100
  exports.isI18nInstance = __webpack_exports__.isI18nInstance;
119
101
  exports.isI18nWrapperInstance = __webpack_exports__.isI18nWrapperInstance;
120
102
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -122,8 +104,6 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
122
104
  "getI18nInstance",
123
105
  "getI18nWrapperI18nextInstance",
124
106
  "getI18nextInstanceForProvider",
125
- "getI18nextProvider",
126
- "getInitReactI18next",
127
107
  "isI18nInstance",
128
108
  "isI18nWrapperInstance"
129
109
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ async function tryImportReactI18next() {
31
+ try {
32
+ return await import("react-i18next");
33
+ } catch (error) {
34
+ return null;
35
+ }
36
+ }
37
+ async function getReactI18nextIntegration() {
38
+ const reactI18nextModule = await tryImportReactI18next();
39
+ return {
40
+ I18nextProvider: reactI18nextModule?.I18nextProvider ?? null,
41
+ initReactI18next: reactI18nextModule?.initReactI18next ?? null
42
+ };
43
+ }
44
+ __webpack_require__.d(__webpack_exports__, {
45
+ getReactI18nextIntegration: ()=>getReactI18nextIntegration
46
+ });
47
+ exports.getReactI18nextIntegration = __webpack_exports__.getReactI18nextIntegration;
48
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
49
+ "getReactI18nextIntegration"
50
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
51
+ Object.defineProperty(exports, '__esModule', {
52
+ value: true
53
+ });
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -133,18 +137,6 @@ const initializeI18nInstance = async (i18nInstance, finalLanguage, fallbackLangu
133
137
  };
134
138
  }
135
139
  }
136
- if (mergedBackend && hasOptions(i18nInstance)) {
137
- const defaultNS = initOptions.defaultNS || initOptions.ns || 'translation';
138
- const ns = Array.isArray(defaultNS) ? defaultNS[0] : defaultNS;
139
- let retries = 20;
140
- while(retries > 0){
141
- const actualInstance = (0, external_instance_js_namespaceObject.getActualI18nextInstance)(i18nInstance);
142
- const store = actualInstance.store;
143
- if (store?.data?.[finalLanguage]?.[ns]) break;
144
- await new Promise((resolve)=>setTimeout(resolve, 100));
145
- retries--;
146
- }
147
- }
148
140
  }
149
141
  };
150
142
  function hasOptions(instance) {
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -49,19 +53,24 @@ const external_I18nLink_js_namespaceObject = require("./I18nLink.js");
49
53
  const i18nPlugin = (options)=>({
50
54
  name: '@modern-js/plugin-i18n',
51
55
  setup: (api)=>{
52
- const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend, htmlLangAttr = false } = options;
53
- const { localePathRedirect = false, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes } = localeDetection || {};
56
+ const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend, htmlLangAttr = false, reactI18next = true } = options;
57
+ const { localePathRedirect = false, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes, localisedUrls } = localeDetection || {};
54
58
  const { enabled: backendEnabled = false } = backend || {};
55
59
  let latestI18nInstance;
56
60
  let I18nextProvider;
61
+ const loadReactI18nextIntegration = async ()=>{
62
+ if (!reactI18next) return null;
63
+ const { getReactI18nextIntegration } = await import("./i18n/react-i18next.js");
64
+ return getReactI18nextIntegration();
65
+ };
57
66
  api.onBeforeRender(async (context)=>{
58
67
  let i18nInstance = await (0, index_js_namespaceObject.getI18nInstance)(userI18nInstance);
59
68
  const { i18n: otherConfig } = api.getRuntimeConfig();
60
69
  const { initOptions: otherInitOptions } = otherConfig || {};
61
70
  const userInitOptions = (0, merge_namespaceObject.merge)(otherInitOptions || {}, initOptions || {});
62
- const initReactI18next = await (0, instance_js_namespaceObject.getInitReactI18next)();
63
- I18nextProvider = await (0, instance_js_namespaceObject.getI18nextProvider)();
64
- if (initReactI18next) i18nInstance.use(initReactI18next);
71
+ const reactI18nextIntegration = await loadReactI18nextIntegration();
72
+ I18nextProvider = reactI18nextIntegration?.I18nextProvider ?? null;
73
+ if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
65
74
  const pathname = (0, external_utils_js_namespaceObject.getPathname)(context);
66
75
  if (i18nextDetector) (0, detection_middleware_js_namespaceObject.useI18nextLanguageDetector)(i18nInstance);
67
76
  const mergedDetection = (0, detection_index_js_namespaceObject.mergeDetectionOptions)(i18nextDetector, detection, localePathRedirect, userInitOptions);
@@ -121,16 +130,18 @@ const i18nPlugin = (options)=>({
121
130
  ]);
122
131
  (0, external_hooks_js_namespaceObject.useSdkResourcesLoader)(i18nInstance, setForceUpdate);
123
132
  (0, external_hooks_js_namespaceObject.useLanguageSync)(i18nInstance, localePathRedirect, languages, runtimeContextRef, prevLangRef, setLang);
124
- (0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes);
125
- const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, setLang), [
133
+ (0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls);
134
+ const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, localisedUrls, setLang), [
126
135
  lang,
127
136
  i18nInstance,
128
137
  entryName,
129
138
  languages,
130
139
  localePathRedirect,
131
140
  ignoreRedirectRoutes,
141
+ localisedUrls,
132
142
  forceUpdate
133
143
  ]);
144
+ const children = props.children;
134
145
  const appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
135
146
  children: [
136
147
  Boolean(htmlLangAttr) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(head_namespaceObject.Helmet, {
@@ -140,9 +151,10 @@ const i18nPlugin = (options)=>({
140
151
  }),
141
152
  /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
142
153
  value: contextValue,
143
- children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
144
- ...props
145
- })
154
+ children: App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
155
+ ...props,
156
+ children: children
157
+ }) : children
146
158
  })
147
159
  ]
148
160
  });
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ useI18nRouterAdapter: ()=>useI18nRouterAdapter
32
+ });
33
+ const runtime_namespaceObject = require("@modern-js/runtime");
34
+ const context_namespaceObject = require("@modern-js/runtime/context");
35
+ const router_namespaceObject = require("@modern-js/runtime/router");
36
+ const external_react_namespaceObject = require("react");
37
+ const normalizeUrlPart = (value, prefix)=>{
38
+ if ('string' != typeof value || !value) return '';
39
+ return value.startsWith(prefix) ? value : `${prefix}${value}`;
40
+ };
41
+ const normalizeLocation = (location)=>{
42
+ if (!location || 'object' != typeof location) return null;
43
+ const locationValue = location;
44
+ if ('string' != typeof locationValue.pathname) return null;
45
+ return {
46
+ pathname: locationValue.pathname,
47
+ search: normalizeUrlPart('string' == typeof locationValue.search ? locationValue.search : locationValue.searchStr, '?'),
48
+ hash: normalizeUrlPart(locationValue.hash, '#')
49
+ };
50
+ };
51
+ const getWindowLocation = ()=>{
52
+ if (!(0, runtime_namespaceObject.isBrowser)()) return null;
53
+ return {
54
+ pathname: window.location.pathname,
55
+ search: window.location.search,
56
+ hash: window.location.hash
57
+ };
58
+ };
59
+ const getRouterFramework = (runtimeContext, internalContext, inReactRouter)=>{
60
+ const framework = internalContext.routerFramework || internalContext.routerRuntime?.framework || runtimeContext.routerFramework;
61
+ if (framework) return framework;
62
+ if (internalContext.router?.useRouter || runtimeContext.router?.useRouter) return 'tanstack';
63
+ if (internalContext.router?.useLocation || internalContext.router?.useHref || runtimeContext.router?.useLocation || runtimeContext.router?.useHref) return 'react-router';
64
+ if (inReactRouter) return 'react-router';
65
+ };
66
+ const getRouterInstance = (internalContext, contextRouter)=>{
67
+ if (contextRouter) return contextRouter;
68
+ const router = internalContext.routerInstance || internalContext.routerRuntime?.instance;
69
+ if (!router || 'object' != typeof router) return null;
70
+ return router;
71
+ };
72
+ const getRouterStateLocation = (internalContext, contextRouter)=>{
73
+ const router = getRouterInstance(internalContext, contextRouter);
74
+ return normalizeLocation(router?.stores?.location?.get?.()) || normalizeLocation(router?.state?.location);
75
+ };
76
+ const getRouterParams = (internalContext, contextRouter)=>{
77
+ const router = getRouterInstance(internalContext, contextRouter);
78
+ const matches = router?.stores?.matches?.get?.() || router?.state?.matches;
79
+ if (!Array.isArray(matches)) return {};
80
+ return matches.reduce((params, match)=>{
81
+ if (match?.params) Object.assign(params, match.params);
82
+ return params;
83
+ }, {});
84
+ };
85
+ const useI18nRouterAdapter = ()=>{
86
+ const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
87
+ const internalContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
88
+ const inReactRouter = (0, router_namespaceObject.useInRouterContext)();
89
+ const reactRouterNavigate = inReactRouter ? (0, router_namespaceObject.useNavigate)() : null;
90
+ const reactRouterLocation = inReactRouter ? (0, router_namespaceObject.useLocation)() : null;
91
+ const reactRouterParams = inReactRouter ? (0, router_namespaceObject.useParams)() : {};
92
+ const framework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
93
+ const contextUseRouter = inReactRouter || 'tanstack' !== framework ? void 0 : internalContext.router?.useRouter || runtimeContext.router?.useRouter;
94
+ const contextRouter = contextUseRouter ? contextUseRouter({
95
+ warn: false
96
+ }) : null;
97
+ const [, setRouterVersion] = (0, external_react_namespaceObject.useState)(0);
98
+ const hasRouter = 'tanstack' === framework || 'react-router' === framework || Boolean(reactRouterNavigate);
99
+ (0, external_react_namespaceObject.useEffect)(()=>{
100
+ if ('tanstack' !== framework) return;
101
+ const router = getRouterInstance(internalContext, contextRouter);
102
+ if (!router) return;
103
+ const update = ()=>setRouterVersion((version)=>version + 1);
104
+ const unsubscribers = [];
105
+ if ('function' == typeof router.stores?.location?.subscribe) {
106
+ const unsubscribe = router.stores.location.subscribe(update);
107
+ if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
108
+ }
109
+ if ('function' == typeof router.subscribe) for (const eventType of [
110
+ 'onBeforeNavigate',
111
+ 'onBeforeLoad'
112
+ ]){
113
+ const unsubscribe = router.subscribe(eventType, update);
114
+ if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
115
+ }
116
+ return ()=>{
117
+ for (const unsubscribe of unsubscribers)unsubscribe();
118
+ };
119
+ }, [
120
+ contextRouter,
121
+ framework,
122
+ internalContext
123
+ ]);
124
+ const navigate = (0, external_react_namespaceObject.useCallback)((href, options)=>{
125
+ const router = getRouterInstance(internalContext, contextRouter);
126
+ const activeFramework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
127
+ if ('tanstack' === activeFramework) {
128
+ if ('function' == typeof router?.navigate) return router.navigate({
129
+ to: href,
130
+ replace: options?.replace,
131
+ ...options?.state === void 0 ? {} : {
132
+ state: options.state
133
+ }
134
+ });
135
+ throw new Error('TanStack router instance is not available.');
136
+ }
137
+ if (reactRouterNavigate) return reactRouterNavigate(href, options);
138
+ if ('react-router' === activeFramework) {
139
+ if ('function' == typeof router?.navigate) return router.navigate(href, options);
140
+ throw new Error('React Router instance is not available.');
141
+ }
142
+ }, [
143
+ contextRouter,
144
+ internalContext,
145
+ inReactRouter,
146
+ reactRouterNavigate,
147
+ runtimeContext
148
+ ]);
149
+ const location = (reactRouterLocation ? normalizeLocation(reactRouterLocation) : getRouterStateLocation(internalContext, contextRouter)) || getWindowLocation();
150
+ const params = inReactRouter ? reactRouterParams : getRouterParams(internalContext, contextRouter);
151
+ const Link = 'tanstack' === framework ? internalContext.router?.Link || runtimeContext.router?.Link || null : 'react-router' === framework || inReactRouter ? router_namespaceObject.Link : null;
152
+ return {
153
+ framework,
154
+ hasRouter,
155
+ location,
156
+ navigate: hasRouter ? navigate : null,
157
+ Link,
158
+ params
159
+ };
160
+ };
161
+ exports.useI18nRouterAdapter = __webpack_exports__.useI18nRouterAdapter;
162
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
163
+ "useI18nRouterAdapter"
164
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
165
+ Object.defineProperty(exports, '__esModule', {
166
+ value: true
167
+ });