@bleedingdev/modern-js-i18n-runtime-extensions 3.9.0-ultramodern.2 → 3.9.0-ultramodern.21

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 (77) hide show
  1. package/dist/cjs/index.js +15 -8
  2. package/dist/cjs/localeRedirectPolicy.js +96 -0
  3. package/dist/cjs/paths.js +56 -0
  4. package/dist/cjs/router-navigation/adapter.js +93 -0
  5. package/dist/cjs/{localisedUrls/config.js → router-navigation/index.js} +5 -14
  6. package/dist/esm/index.mjs +2 -1
  7. package/dist/esm/localeRedirectPolicy.mjs +46 -0
  8. package/dist/esm/paths.mjs +12 -0
  9. package/dist/esm/router-navigation/adapter.mjs +55 -0
  10. package/dist/esm/router-navigation/index.mjs +1 -0
  11. package/dist/esm-node/index.mjs +2 -1
  12. package/dist/esm-node/localeRedirectPolicy.mjs +47 -0
  13. package/dist/esm-node/paths.mjs +13 -0
  14. package/dist/esm-node/router-navigation/adapter.mjs +56 -0
  15. package/dist/esm-node/router-navigation/index.mjs +2 -0
  16. package/dist/types/index.d.ts +2 -1
  17. package/dist/types/localeRedirectPolicy.d.ts +22 -0
  18. package/dist/types/paths.d.ts +9 -0
  19. package/dist/types/router-navigation/adapter.d.ts +23 -0
  20. package/dist/types/router-navigation/index.d.ts +1 -0
  21. package/package.json +33 -9
  22. package/src/index.ts +2 -1
  23. package/src/localeRedirectPolicy.ts +127 -0
  24. package/src/paths.ts +37 -0
  25. package/src/router-navigation/adapter.tsx +120 -0
  26. package/src/router-navigation/index.ts +6 -0
  27. package/tests/languageSyncController.test.ts +0 -77
  28. package/tests/localeRedirectPolicy.test.ts +173 -0
  29. package/tests/paths.test.ts +24 -0
  30. package/tests/reactLanguageSync.test.tsx +21 -2
  31. package/tests/routerNavigation.test.tsx +80 -0
  32. package/dist/cjs/localisedUrls/index.js +0 -91
  33. package/dist/cjs/localisedUrls/normalise.js +0 -87
  34. package/dist/cjs/localisedUrls/pathname.js +0 -68
  35. package/dist/cjs/localisedUrls/patterns.js +0 -214
  36. package/dist/cjs/localisedUrls/redirect.js +0 -103
  37. package/dist/cjs/localisedUrls/resolve.js +0 -78
  38. package/dist/cjs/localisedUrls/routes.js +0 -202
  39. package/dist/cjs/localisedUrls/types.js +0 -18
  40. package/dist/esm/localisedUrls/config.mjs +0 -11
  41. package/dist/esm/localisedUrls/index.mjs +0 -7
  42. package/dist/esm/localisedUrls/normalise.mjs +0 -37
  43. package/dist/esm/localisedUrls/pathname.mjs +0 -24
  44. package/dist/esm/localisedUrls/patterns.mjs +0 -152
  45. package/dist/esm/localisedUrls/redirect.mjs +0 -56
  46. package/dist/esm/localisedUrls/resolve.mjs +0 -37
  47. package/dist/esm/localisedUrls/routes.mjs +0 -161
  48. package/dist/esm/localisedUrls/types.mjs +0 -0
  49. package/dist/esm-node/localisedUrls/config.mjs +0 -12
  50. package/dist/esm-node/localisedUrls/index.mjs +0 -8
  51. package/dist/esm-node/localisedUrls/normalise.mjs +0 -38
  52. package/dist/esm-node/localisedUrls/pathname.mjs +0 -25
  53. package/dist/esm-node/localisedUrls/patterns.mjs +0 -153
  54. package/dist/esm-node/localisedUrls/redirect.mjs +0 -57
  55. package/dist/esm-node/localisedUrls/resolve.mjs +0 -38
  56. package/dist/esm-node/localisedUrls/routes.mjs +0 -162
  57. package/dist/esm-node/localisedUrls/types.mjs +0 -1
  58. package/dist/types/localisedUrls/config.d.ts +0 -9
  59. package/dist/types/localisedUrls/index.d.ts +0 -9
  60. package/dist/types/localisedUrls/normalise.d.ts +0 -10
  61. package/dist/types/localisedUrls/pathname.d.ts +0 -4
  62. package/dist/types/localisedUrls/patterns.d.ts +0 -11
  63. package/dist/types/localisedUrls/redirect.d.ts +0 -11
  64. package/dist/types/localisedUrls/resolve.d.ts +0 -7
  65. package/dist/types/localisedUrls/routes.d.ts +0 -3
  66. package/dist/types/localisedUrls/types.d.ts +0 -14
  67. package/src/localisedUrls/config.ts +0 -18
  68. package/src/localisedUrls/index.ts +0 -24
  69. package/src/localisedUrls/normalise.ts +0 -62
  70. package/src/localisedUrls/pathname.ts +0 -60
  71. package/src/localisedUrls/patterns.ts +0 -283
  72. package/src/localisedUrls/redirect.ts +0 -93
  73. package/src/localisedUrls/resolve.ts +0 -106
  74. package/src/localisedUrls/routes.ts +0 -422
  75. package/src/localisedUrls/types.ts +0 -18
  76. package/tests/clientRedirectIntegration.test.tsx +0 -74
  77. package/tests/localisedUrls.test.ts +0 -673
package/dist/cjs/index.js CHANGED
@@ -6,8 +6,11 @@ var __webpack_modules__ = {
6
6
  "./language-sync/react" (module) {
7
7
  module.exports = require("./language-sync/react.js");
8
8
  },
9
- "./localisedUrls/index" (module) {
10
- module.exports = require("./localisedUrls/index.js");
9
+ "./localeRedirectPolicy" (module) {
10
+ module.exports = require("./localeRedirectPolicy.js");
11
+ },
12
+ "@modern-js/runtime-extensions/localised-urls" (module) {
13
+ module.exports = require("@modern-js/runtime-extensions/localised-urls");
11
14
  }
12
15
  };
13
16
  var __webpack_module_cache__ = {};
@@ -57,17 +60,21 @@ function __webpack_require__(moduleId) {
57
60
  var __webpack_exports__ = {};
58
61
  (()=>{
59
62
  __webpack_require__.r(__webpack_exports__);
60
- var _language_sync_controller__rspack_import_0 = __webpack_require__("./language-sync/controller");
63
+ var _modern_js_runtime_extensions_localised_urls__rspack_import_0 = __webpack_require__("@modern-js/runtime-extensions/localised-urls");
64
+ var __rspack_reexport = {};
65
+ for(const __rspack_import_key in _modern_js_runtime_extensions_localised_urls__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_modern_js_runtime_extensions_localised_urls__rspack_import_0[__rspack_import_key];
66
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
67
+ var _language_sync_controller__rspack_import_1 = __webpack_require__("./language-sync/controller");
61
68
  var __rspack_reexport = {};
62
- for(const __rspack_import_key in _language_sync_controller__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_language_sync_controller__rspack_import_0[__rspack_import_key];
69
+ for(const __rspack_import_key in _language_sync_controller__rspack_import_1)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_language_sync_controller__rspack_import_1[__rspack_import_key];
63
70
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
64
- var _language_sync_react__rspack_import_1 = __webpack_require__("./language-sync/react");
71
+ var _language_sync_react__rspack_import_2 = __webpack_require__("./language-sync/react");
65
72
  var __rspack_reexport = {};
66
- for(const __rspack_import_key in _language_sync_react__rspack_import_1)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_language_sync_react__rspack_import_1[__rspack_import_key];
73
+ for(const __rspack_import_key in _language_sync_react__rspack_import_2)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_language_sync_react__rspack_import_2[__rspack_import_key];
67
74
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
68
- var _localisedUrls_index__rspack_import_2 = __webpack_require__("./localisedUrls/index");
75
+ var _localeRedirectPolicy__rspack_import_3 = __webpack_require__("./localeRedirectPolicy");
69
76
  var __rspack_reexport = {};
70
- for(const __rspack_import_key in _localisedUrls_index__rspack_import_2)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_localisedUrls_index__rspack_import_2[__rspack_import_key];
77
+ for(const __rspack_import_key in _localeRedirectPolicy__rspack_import_3)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_localeRedirectPolicy__rspack_import_3[__rspack_import_key];
71
78
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
72
79
  })();
73
80
  for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -0,0 +1,96 @@
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
+ buildLocalizedUrl: ()=>buildLocalizedUrl,
32
+ createLocaleRedirectResponse: ()=>createLocaleRedirectResponse,
33
+ getLanguageFromPath: ()=>getLanguageFromPath,
34
+ isStaticResourceRequest: ()=>isStaticResourceRequest,
35
+ shouldIgnoreRedirect: ()=>shouldIgnoreRedirect
36
+ });
37
+ const localised_urls_namespaceObject = require("@modern-js/runtime-extensions/localised-urls");
38
+ const stripUrlPathPrefix = (pathname, urlPath)=>{
39
+ const basePath = urlPath.replace('/*', '');
40
+ if (!basePath || '/' === basePath) return pathname;
41
+ const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
42
+ return remainingPath || '/';
43
+ };
44
+ const shouldIgnoreRedirect = (pathname, urlPath, ignoreRedirectRoutes)=>{
45
+ const remainingPath = stripUrlPathPrefix(pathname, urlPath);
46
+ return (0, localised_urls_namespaceObject.shouldSkipLocaleRedirect)(remainingPath, [], ignoreRedirectRoutes);
47
+ };
48
+ const isStaticResourceRequest = (pathname, staticRoutePrefixes, languages = [])=>{
49
+ if ((0, localised_urls_namespaceObject.isDefaultLocaleRedirectSkipPath)(pathname, languages)) return true;
50
+ const matchesStaticRoutePrefix = (targetPathname)=>staticRoutePrefixes.some((prefix)=>(0, localised_urls_namespaceObject.matchesPathPrefix)(targetPathname, prefix));
51
+ if (matchesStaticRoutePrefix(pathname)) return true;
52
+ const pathWithoutLanguage = (0, localised_urls_namespaceObject.stripLanguagePrefix)(pathname, languages);
53
+ return pathWithoutLanguage !== pathname && matchesStaticRoutePrefix(pathWithoutLanguage);
54
+ };
55
+ const getLanguageFromPath = (req, urlPath, languages)=>{
56
+ const url = new URL(req.url, `http://${req.header().host}`);
57
+ const pathname = url.pathname;
58
+ const remainingPath = stripUrlPathPrefix(pathname, urlPath);
59
+ const segments = remainingPath.split('/').filter(Boolean);
60
+ const firstSegment = segments[0];
61
+ if (languages.includes(firstSegment)) return firstSegment;
62
+ return null;
63
+ };
64
+ const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
65
+ const url = new URL(req.url);
66
+ const pathname = url.pathname;
67
+ const basePath = urlPath.replace('/*', '');
68
+ const remainingPath = stripUrlPathPrefix(pathname, urlPath);
69
+ const newPathname = (0, localised_urls_namespaceObject.localiseTargetPathname)(remainingPath, language, languages, localisedUrls);
70
+ const suffix = `${url.search}${url.hash}`;
71
+ const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
72
+ return localizedUrl;
73
+ };
74
+ const createLocaleRedirectResponse = (location)=>new Response(null, {
75
+ status: 302,
76
+ headers: {
77
+ 'Cache-Control': 'private, no-store',
78
+ Location: location,
79
+ Vary: 'Accept-Language, Cookie'
80
+ }
81
+ });
82
+ exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
83
+ exports.createLocaleRedirectResponse = __webpack_exports__.createLocaleRedirectResponse;
84
+ exports.getLanguageFromPath = __webpack_exports__.getLanguageFromPath;
85
+ exports.isStaticResourceRequest = __webpack_exports__.isStaticResourceRequest;
86
+ exports.shouldIgnoreRedirect = __webpack_exports__.shouldIgnoreRedirect;
87
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
88
+ "buildLocalizedUrl",
89
+ "createLocaleRedirectResponse",
90
+ "getLanguageFromPath",
91
+ "isStaticResourceRequest",
92
+ "shouldIgnoreRedirect"
93
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
94
+ Object.defineProperty(exports, '__esModule', {
95
+ value: true
96
+ });
@@ -0,0 +1,56 @@
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
+ buildLocalizedUrl: ()=>buildLocalizedUrl,
32
+ canonicalPath: ()=>canonicalPath,
33
+ localizePath: ()=>localizePath
34
+ });
35
+ const localised_urls_namespaceObject = require("@modern-js/runtime-extensions/localised-urls");
36
+ const url_namespaceObject = require("@modern-js/runtime-utils/url");
37
+ const buildLocalizedUrl = (target, language, languages, localisedUrls)=>{
38
+ const { pathname, search, hash } = (0, url_namespaceObject.splitUrlTarget)(target);
39
+ return `${(0, localised_urls_namespaceObject.localiseTargetPathname)(pathname, language, languages, localisedUrls)}${search}${hash}`;
40
+ };
41
+ const localizePath = (target, language, config)=>buildLocalizedUrl(target, language, config.languages, config.localisedUrls);
42
+ const canonicalPath = (target, config)=>{
43
+ const { pathname, search, hash } = (0, url_namespaceObject.splitUrlTarget)(target);
44
+ return `${(0, localised_urls_namespaceObject.canonicalTargetPathname)(pathname, config.languages, config.localisedUrls)}${search}${hash}`;
45
+ };
46
+ exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
47
+ exports.canonicalPath = __webpack_exports__.canonicalPath;
48
+ exports.localizePath = __webpack_exports__.localizePath;
49
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
50
+ "buildLocalizedUrl",
51
+ "canonicalPath",
52
+ "localizePath"
53
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
54
+ Object.defineProperty(exports, '__esModule', {
55
+ value: true
56
+ });
@@ -0,0 +1,93 @@
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
+ createI18nRouterNavigation: ()=>createI18nRouterNavigation
32
+ });
33
+ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
34
+ const runtime_namespaceObject = require("@modern-js/runtime");
35
+ const context_namespaceObject = require("@modern-js/runtime/context");
36
+ const router_state_namespaceObject = require("@modern-js/runtime-extensions/router-state");
37
+ const external_react_namespaceObject = require("react");
38
+ const subscribeNone = ()=>()=>{};
39
+ const getEmptySnapshot = ()=>null;
40
+ const createI18nRouterNavigation = ({ I18nNavigationProvider, useNativeI18nRouterAdapter })=>{
41
+ const NavigationProvider = I18nNavigationProvider;
42
+ const useIntegratedRouterAdapter = ()=>{
43
+ const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
44
+ const internalContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
45
+ const native = useNativeI18nRouterAdapter();
46
+ const getCapability = (0, external_react_namespaceObject.useCallback)(()=>(0, router_state_namespaceObject.getRouterRuntimeState)(internalContext)?.navigation ?? (0, router_state_namespaceObject.getRouterRuntimeState)(runtimeContext)?.navigation, [
47
+ internalContext,
48
+ runtimeContext
49
+ ]);
50
+ const subscribeCapability = (0, external_react_namespaceObject.useCallback)((update)=>{
51
+ const stopInternal = (0, router_state_namespaceObject.subscribeRouterRuntimeState)(internalContext, update);
52
+ const stopPublic = internalContext === runtimeContext ? void 0 : (0, router_state_namespaceObject.subscribeRouterRuntimeState)(runtimeContext, update);
53
+ return ()=>{
54
+ stopInternal();
55
+ stopPublic?.();
56
+ };
57
+ }, [
58
+ internalContext,
59
+ runtimeContext
60
+ ]);
61
+ const capability = (0, external_react_namespaceObject.useSyncExternalStore)(subscribeCapability, getCapability, getCapability);
62
+ const snapshot = (0, external_react_namespaceObject.useSyncExternalStore)(capability?.subscribe ?? subscribeNone, capability?.getSnapshot ?? getEmptySnapshot, capability?.getSnapshot ?? getEmptySnapshot);
63
+ if (native.hasRouter || !capability || !snapshot) return native;
64
+ const internalState = (0, router_state_namespaceObject.getRouterRuntimeState)(internalContext);
65
+ return {
66
+ framework: internalState?.navigation === capability ? internalState.framework : (0, router_state_namespaceObject.getRouterRuntimeState)(runtimeContext)?.framework,
67
+ hasRouter: true,
68
+ ...snapshot,
69
+ navigate: capability.navigate,
70
+ Link: capability.Link,
71
+ createLinkProps: capability.createLinkProps
72
+ };
73
+ };
74
+ const I18nRouterNavigationProvider = ({ children })=>{
75
+ const value = useIntegratedRouterAdapter();
76
+ const native = useNativeI18nRouterAdapter();
77
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(NavigationProvider, {
78
+ value: value.hasRouter && !native.hasRouter ? value : null,
79
+ children: children
80
+ });
81
+ };
82
+ return {
83
+ useIntegratedRouterAdapter,
84
+ I18nRouterNavigationProvider
85
+ };
86
+ };
87
+ exports.createI18nRouterNavigation = __webpack_exports__.createI18nRouterNavigation;
88
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
89
+ "createI18nRouterNavigation"
90
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
91
+ Object.defineProperty(exports, '__esModule', {
92
+ value: true
93
+ });
@@ -27,22 +27,13 @@ var __webpack_require__ = {};
27
27
  })();
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
- const resolveLocalisedUrlsConfig = (option)=>{
31
- if (option && 'object' == typeof option && Object.keys(option).length > 0) return {
32
- enabled: true,
33
- map: option
34
- };
35
- return {
36
- enabled: false,
37
- map: {}
38
- };
39
- };
40
- __webpack_require__.d(__webpack_exports__, {}, {
41
- resolveLocalisedUrlsConfig: resolveLocalisedUrlsConfig
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ createI18nRouterNavigation: ()=>external_adapter_js_namespaceObject.createI18nRouterNavigation
42
32
  });
43
- exports.resolveLocalisedUrlsConfig = __webpack_exports__.resolveLocalisedUrlsConfig;
33
+ const external_adapter_js_namespaceObject = require("./adapter.js");
34
+ exports.createI18nRouterNavigation = __webpack_exports__.createI18nRouterNavigation;
44
35
  for(var __rspack_i in __webpack_exports__)if (-1 === [
45
- "resolveLocalisedUrlsConfig"
36
+ "createI18nRouterNavigation"
46
37
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
47
38
  Object.defineProperty(exports, '__esModule', {
48
39
  value: true
@@ -1,3 +1,4 @@
1
+ export * from "@modern-js/runtime-extensions/localised-urls";
1
2
  export * from "./language-sync/controller.mjs";
2
3
  export * from "./language-sync/react.mjs";
3
- export * from "./localisedUrls/index.mjs";
4
+ export * from "./localeRedirectPolicy.mjs";
@@ -0,0 +1,46 @@
1
+ import { isDefaultLocaleRedirectSkipPath, localiseTargetPathname, matchesPathPrefix, shouldSkipLocaleRedirect, stripLanguagePrefix } from "@modern-js/runtime-extensions/localised-urls";
2
+ const stripUrlPathPrefix = (pathname, urlPath)=>{
3
+ const basePath = urlPath.replace('/*', '');
4
+ if (!basePath || '/' === basePath) return pathname;
5
+ const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
6
+ return remainingPath || '/';
7
+ };
8
+ const shouldIgnoreRedirect = (pathname, urlPath, ignoreRedirectRoutes)=>{
9
+ const remainingPath = stripUrlPathPrefix(pathname, urlPath);
10
+ return shouldSkipLocaleRedirect(remainingPath, [], ignoreRedirectRoutes);
11
+ };
12
+ const isStaticResourceRequest = (pathname, staticRoutePrefixes, languages = [])=>{
13
+ if (isDefaultLocaleRedirectSkipPath(pathname, languages)) return true;
14
+ const matchesStaticRoutePrefix = (targetPathname)=>staticRoutePrefixes.some((prefix)=>matchesPathPrefix(targetPathname, prefix));
15
+ if (matchesStaticRoutePrefix(pathname)) return true;
16
+ const pathWithoutLanguage = stripLanguagePrefix(pathname, languages);
17
+ return pathWithoutLanguage !== pathname && matchesStaticRoutePrefix(pathWithoutLanguage);
18
+ };
19
+ const getLanguageFromPath = (req, urlPath, languages)=>{
20
+ const url = new URL(req.url, `http://${req.header().host}`);
21
+ const pathname = url.pathname;
22
+ const remainingPath = stripUrlPathPrefix(pathname, urlPath);
23
+ const segments = remainingPath.split('/').filter(Boolean);
24
+ const firstSegment = segments[0];
25
+ if (languages.includes(firstSegment)) return firstSegment;
26
+ return null;
27
+ };
28
+ const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
29
+ const url = new URL(req.url);
30
+ const pathname = url.pathname;
31
+ const basePath = urlPath.replace('/*', '');
32
+ const remainingPath = stripUrlPathPrefix(pathname, urlPath);
33
+ const newPathname = localiseTargetPathname(remainingPath, language, languages, localisedUrls);
34
+ const suffix = `${url.search}${url.hash}`;
35
+ const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
36
+ return localizedUrl;
37
+ };
38
+ const createLocaleRedirectResponse = (location)=>new Response(null, {
39
+ status: 302,
40
+ headers: {
41
+ 'Cache-Control': 'private, no-store',
42
+ Location: location,
43
+ Vary: 'Accept-Language, Cookie'
44
+ }
45
+ });
46
+ export { buildLocalizedUrl, createLocaleRedirectResponse, getLanguageFromPath, isStaticResourceRequest, shouldIgnoreRedirect };
@@ -0,0 +1,12 @@
1
+ import { canonicalTargetPathname, localiseTargetPathname } from "@modern-js/runtime-extensions/localised-urls";
2
+ import { splitUrlTarget } from "@modern-js/runtime-utils/url";
3
+ const buildLocalizedUrl = (target, language, languages, localisedUrls)=>{
4
+ const { pathname, search, hash } = splitUrlTarget(target);
5
+ return `${localiseTargetPathname(pathname, language, languages, localisedUrls)}${search}${hash}`;
6
+ };
7
+ const localizePath = (target, language, config)=>buildLocalizedUrl(target, language, config.languages, config.localisedUrls);
8
+ const canonicalPath = (target, config)=>{
9
+ const { pathname, search, hash } = splitUrlTarget(target);
10
+ return `${canonicalTargetPathname(pathname, config.languages, config.localisedUrls)}${search}${hash}`;
11
+ };
12
+ export { buildLocalizedUrl, canonicalPath, localizePath };
@@ -0,0 +1,55 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { RuntimeContext } from "@modern-js/runtime";
3
+ import { InternalRuntimeContext } from "@modern-js/runtime/context";
4
+ import { getRouterRuntimeState, subscribeRouterRuntimeState } from "@modern-js/runtime-extensions/router-state";
5
+ import { useCallback, useContext, useSyncExternalStore } from "react";
6
+ const subscribeNone = ()=>()=>{};
7
+ const getEmptySnapshot = ()=>null;
8
+ const createI18nRouterNavigation = ({ I18nNavigationProvider, useNativeI18nRouterAdapter })=>{
9
+ const NavigationProvider = I18nNavigationProvider;
10
+ const useIntegratedRouterAdapter = ()=>{
11
+ const runtimeContext = useContext(RuntimeContext);
12
+ const internalContext = useContext(InternalRuntimeContext);
13
+ const native = useNativeI18nRouterAdapter();
14
+ const getCapability = useCallback(()=>getRouterRuntimeState(internalContext)?.navigation ?? getRouterRuntimeState(runtimeContext)?.navigation, [
15
+ internalContext,
16
+ runtimeContext
17
+ ]);
18
+ const subscribeCapability = useCallback((update)=>{
19
+ const stopInternal = subscribeRouterRuntimeState(internalContext, update);
20
+ const stopPublic = internalContext === runtimeContext ? void 0 : subscribeRouterRuntimeState(runtimeContext, update);
21
+ return ()=>{
22
+ stopInternal();
23
+ stopPublic?.();
24
+ };
25
+ }, [
26
+ internalContext,
27
+ runtimeContext
28
+ ]);
29
+ const capability = useSyncExternalStore(subscribeCapability, getCapability, getCapability);
30
+ const snapshot = useSyncExternalStore(capability?.subscribe ?? subscribeNone, capability?.getSnapshot ?? getEmptySnapshot, capability?.getSnapshot ?? getEmptySnapshot);
31
+ if (native.hasRouter || !capability || !snapshot) return native;
32
+ const internalState = getRouterRuntimeState(internalContext);
33
+ return {
34
+ framework: internalState?.navigation === capability ? internalState.framework : getRouterRuntimeState(runtimeContext)?.framework,
35
+ hasRouter: true,
36
+ ...snapshot,
37
+ navigate: capability.navigate,
38
+ Link: capability.Link,
39
+ createLinkProps: capability.createLinkProps
40
+ };
41
+ };
42
+ const I18nRouterNavigationProvider = ({ children })=>{
43
+ const value = useIntegratedRouterAdapter();
44
+ const native = useNativeI18nRouterAdapter();
45
+ return /*#__PURE__*/ jsx(NavigationProvider, {
46
+ value: value.hasRouter && !native.hasRouter ? value : null,
47
+ children: children
48
+ });
49
+ };
50
+ return {
51
+ useIntegratedRouterAdapter,
52
+ I18nRouterNavigationProvider
53
+ };
54
+ };
55
+ export { createI18nRouterNavigation };
@@ -0,0 +1 @@
1
+ export { createI18nRouterNavigation } from "./adapter.mjs";
@@ -1,4 +1,5 @@
1
1
  import "node:module";
2
+ export * from "@modern-js/runtime-extensions/localised-urls";
2
3
  export * from "./language-sync/controller.mjs";
3
4
  export * from "./language-sync/react.mjs";
4
- export * from "./localisedUrls/index.mjs";
5
+ export * from "./localeRedirectPolicy.mjs";
@@ -0,0 +1,47 @@
1
+ import "node:module";
2
+ import { isDefaultLocaleRedirectSkipPath, localiseTargetPathname, matchesPathPrefix, shouldSkipLocaleRedirect, stripLanguagePrefix } from "@modern-js/runtime-extensions/localised-urls";
3
+ const stripUrlPathPrefix = (pathname, urlPath)=>{
4
+ const basePath = urlPath.replace('/*', '');
5
+ if (!basePath || '/' === basePath) return pathname;
6
+ const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
7
+ return remainingPath || '/';
8
+ };
9
+ const shouldIgnoreRedirect = (pathname, urlPath, ignoreRedirectRoutes)=>{
10
+ const remainingPath = stripUrlPathPrefix(pathname, urlPath);
11
+ return shouldSkipLocaleRedirect(remainingPath, [], ignoreRedirectRoutes);
12
+ };
13
+ const isStaticResourceRequest = (pathname, staticRoutePrefixes, languages = [])=>{
14
+ if (isDefaultLocaleRedirectSkipPath(pathname, languages)) return true;
15
+ const matchesStaticRoutePrefix = (targetPathname)=>staticRoutePrefixes.some((prefix)=>matchesPathPrefix(targetPathname, prefix));
16
+ if (matchesStaticRoutePrefix(pathname)) return true;
17
+ const pathWithoutLanguage = stripLanguagePrefix(pathname, languages);
18
+ return pathWithoutLanguage !== pathname && matchesStaticRoutePrefix(pathWithoutLanguage);
19
+ };
20
+ const getLanguageFromPath = (req, urlPath, languages)=>{
21
+ const url = new URL(req.url, `http://${req.header().host}`);
22
+ const pathname = url.pathname;
23
+ const remainingPath = stripUrlPathPrefix(pathname, urlPath);
24
+ const segments = remainingPath.split('/').filter(Boolean);
25
+ const firstSegment = segments[0];
26
+ if (languages.includes(firstSegment)) return firstSegment;
27
+ return null;
28
+ };
29
+ const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
30
+ const url = new URL(req.url);
31
+ const pathname = url.pathname;
32
+ const basePath = urlPath.replace('/*', '');
33
+ const remainingPath = stripUrlPathPrefix(pathname, urlPath);
34
+ const newPathname = localiseTargetPathname(remainingPath, language, languages, localisedUrls);
35
+ const suffix = `${url.search}${url.hash}`;
36
+ const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
37
+ return localizedUrl;
38
+ };
39
+ const createLocaleRedirectResponse = (location)=>new Response(null, {
40
+ status: 302,
41
+ headers: {
42
+ 'Cache-Control': 'private, no-store',
43
+ Location: location,
44
+ Vary: 'Accept-Language, Cookie'
45
+ }
46
+ });
47
+ export { buildLocalizedUrl, createLocaleRedirectResponse, getLanguageFromPath, isStaticResourceRequest, shouldIgnoreRedirect };
@@ -0,0 +1,13 @@
1
+ import "node:module";
2
+ import { canonicalTargetPathname, localiseTargetPathname } from "@modern-js/runtime-extensions/localised-urls";
3
+ import { splitUrlTarget } from "@modern-js/runtime-utils/url";
4
+ const buildLocalizedUrl = (target, language, languages, localisedUrls)=>{
5
+ const { pathname, search, hash } = splitUrlTarget(target);
6
+ return `${localiseTargetPathname(pathname, language, languages, localisedUrls)}${search}${hash}`;
7
+ };
8
+ const localizePath = (target, language, config)=>buildLocalizedUrl(target, language, config.languages, config.localisedUrls);
9
+ const canonicalPath = (target, config)=>{
10
+ const { pathname, search, hash } = splitUrlTarget(target);
11
+ return `${canonicalTargetPathname(pathname, config.languages, config.localisedUrls)}${search}${hash}`;
12
+ };
13
+ export { buildLocalizedUrl, canonicalPath, localizePath };
@@ -0,0 +1,56 @@
1
+ import "node:module";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { RuntimeContext } from "@modern-js/runtime";
4
+ import { InternalRuntimeContext } from "@modern-js/runtime/context";
5
+ import { getRouterRuntimeState, subscribeRouterRuntimeState } from "@modern-js/runtime-extensions/router-state";
6
+ import { useCallback, useContext, useSyncExternalStore } from "react";
7
+ const subscribeNone = ()=>()=>{};
8
+ const getEmptySnapshot = ()=>null;
9
+ const createI18nRouterNavigation = ({ I18nNavigationProvider, useNativeI18nRouterAdapter })=>{
10
+ const NavigationProvider = I18nNavigationProvider;
11
+ const useIntegratedRouterAdapter = ()=>{
12
+ const runtimeContext = useContext(RuntimeContext);
13
+ const internalContext = useContext(InternalRuntimeContext);
14
+ const native = useNativeI18nRouterAdapter();
15
+ const getCapability = useCallback(()=>getRouterRuntimeState(internalContext)?.navigation ?? getRouterRuntimeState(runtimeContext)?.navigation, [
16
+ internalContext,
17
+ runtimeContext
18
+ ]);
19
+ const subscribeCapability = useCallback((update)=>{
20
+ const stopInternal = subscribeRouterRuntimeState(internalContext, update);
21
+ const stopPublic = internalContext === runtimeContext ? void 0 : subscribeRouterRuntimeState(runtimeContext, update);
22
+ return ()=>{
23
+ stopInternal();
24
+ stopPublic?.();
25
+ };
26
+ }, [
27
+ internalContext,
28
+ runtimeContext
29
+ ]);
30
+ const capability = useSyncExternalStore(subscribeCapability, getCapability, getCapability);
31
+ const snapshot = useSyncExternalStore(capability?.subscribe ?? subscribeNone, capability?.getSnapshot ?? getEmptySnapshot, capability?.getSnapshot ?? getEmptySnapshot);
32
+ if (native.hasRouter || !capability || !snapshot) return native;
33
+ const internalState = getRouterRuntimeState(internalContext);
34
+ return {
35
+ framework: internalState?.navigation === capability ? internalState.framework : getRouterRuntimeState(runtimeContext)?.framework,
36
+ hasRouter: true,
37
+ ...snapshot,
38
+ navigate: capability.navigate,
39
+ Link: capability.Link,
40
+ createLinkProps: capability.createLinkProps
41
+ };
42
+ };
43
+ const I18nRouterNavigationProvider = ({ children })=>{
44
+ const value = useIntegratedRouterAdapter();
45
+ const native = useNativeI18nRouterAdapter();
46
+ return /*#__PURE__*/ jsx(NavigationProvider, {
47
+ value: value.hasRouter && !native.hasRouter ? value : null,
48
+ children: children
49
+ });
50
+ };
51
+ return {
52
+ useIntegratedRouterAdapter,
53
+ I18nRouterNavigationProvider
54
+ };
55
+ };
56
+ export { createI18nRouterNavigation };
@@ -0,0 +1,2 @@
1
+ import "node:module";
2
+ export { createI18nRouterNavigation } from "./adapter.mjs";
@@ -1,3 +1,4 @@
1
+ export * from '@modern-js/runtime-extensions/localised-urls';
1
2
  export * from './language-sync/controller.js';
2
3
  export * from './language-sync/react.js';
3
- export * from './localisedUrls/index.js';
4
+ export * from './localeRedirectPolicy.js';
@@ -0,0 +1,22 @@
1
+ import type { LocalisedUrlsOption } from '@modern-js/runtime-extensions/localised-urls';
2
+ interface LocaleRedirectRequest {
3
+ url: string;
4
+ header: () => {
5
+ host?: string;
6
+ };
7
+ }
8
+ /**
9
+ * Check if pathname should ignore automatic locale redirect.
10
+ */
11
+ export declare const shouldIgnoreRedirect: (pathname: string, urlPath: string, ignoreRedirectRoutes?: string[] | ((pathname: string) => boolean)) => boolean;
12
+ /**
13
+ * Check if pathname is a static or federation resource request.
14
+ *
15
+ * This includes configured staticRoutePrefixes, the shared default skip policy
16
+ * from ADR-0002, and language-prefixed variants such as /en/static/app.js.
17
+ */
18
+ export declare const isStaticResourceRequest: (pathname: string, staticRoutePrefixes: string[], languages?: string[]) => boolean;
19
+ export declare const getLanguageFromPath: (req: LocaleRedirectRequest, urlPath: string, languages: string[]) => string | null;
20
+ export declare const buildLocalizedUrl: (req: LocaleRedirectRequest, urlPath: string, language: string, languages: string[], localisedUrls?: LocalisedUrlsOption) => string;
21
+ export declare const createLocaleRedirectResponse: (location: string) => Response;
22
+ export {};
@@ -0,0 +1,9 @@
1
+ import { type LocalisedUrlsOption } from '@modern-js/runtime-extensions/localised-urls';
2
+ export interface LocalizedPathsConfig {
3
+ languages: string[];
4
+ localisedUrls?: LocalisedUrlsOption;
5
+ }
6
+ /** Synchronous mapped URL construction, independent of React/plugin setup. */
7
+ export declare const buildLocalizedUrl: (target: string, language: string, languages: string[], localisedUrls?: LocalisedUrlsOption) => string;
8
+ export declare const localizePath: (target: string, language: string, config: LocalizedPathsConfig) => string;
9
+ export declare const canonicalPath: (target: string, config: LocalizedPathsConfig) => string;
@@ -0,0 +1,23 @@
1
+ import { type RouterLinkTarget, type RouterNavigationCapability, type RouterNavigationSnapshot } from '@modern-js/runtime-extensions/router-state';
2
+ import type React from 'react';
3
+ export interface I18nRouterNavigationDependencies<Adapter extends I18nRouterAdapterShape> {
4
+ I18nNavigationProvider: React.ComponentType<React.PropsWithChildren<{
5
+ value: Adapter;
6
+ }>>;
7
+ useNativeI18nRouterAdapter: () => Adapter;
8
+ }
9
+ export type I18nRouterLinkTarget = RouterLinkTarget;
10
+ export interface I18nRouterAdapterShape {
11
+ framework?: string;
12
+ hasRouter: boolean;
13
+ location: RouterNavigationSnapshot['location'] | null;
14
+ navigate: RouterNavigationCapability['navigate'] | null;
15
+ Link: RouterNavigationCapability['Link'] | null;
16
+ params: Record<string, string>;
17
+ createLinkProps?: RouterNavigationCapability['createLinkProps'];
18
+ }
19
+ /** The router provider owns navigation; this seam only observes its capability. */
20
+ export declare const createI18nRouterNavigation: <Adapter extends I18nRouterAdapterShape>({ I18nNavigationProvider, useNativeI18nRouterAdapter, }: I18nRouterNavigationDependencies<Adapter>) => {
21
+ useIntegratedRouterAdapter: () => Adapter;
22
+ I18nRouterNavigationProvider: ({ children, }: React.PropsWithChildren) => React.JSX.Element;
23
+ };
@@ -0,0 +1 @@
1
+ export { createI18nRouterNavigation, type I18nRouterAdapterShape, type I18nRouterLinkTarget, type I18nRouterNavigationDependencies, } from './adapter.js';