@bleedingdev/modern-js-plugin-i18n 3.5.0-ultramodern.3 → 3.5.0-ultramodern.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/index.js +2 -1
- package/dist/cjs/runtime/Link.js +8 -89
- package/dist/cjs/runtime/context.js +18 -82
- package/dist/cjs/runtime/contextHelpers.js +137 -0
- package/dist/cjs/runtime/core.js +29 -132
- package/dist/cjs/runtime/i18n/detection/cache.js +149 -0
- package/dist/cjs/runtime/i18n/detection/detector.js +100 -0
- package/dist/cjs/runtime/i18n/detection/index.js +8 -263
- package/dist/cjs/runtime/i18n/detection/initOptions.js +69 -0
- package/dist/cjs/runtime/i18n/detection/language.js +62 -0
- package/dist/cjs/runtime/i18n/detection/path.js +49 -0
- package/dist/cjs/runtime/i18n/detection/priority.js +66 -0
- package/dist/cjs/runtime/i18n/detection/ssr.js +70 -0
- package/dist/cjs/runtime/i18n/detection/types.js +18 -0
- package/dist/cjs/runtime/linkHelpers.js +148 -0
- package/dist/cjs/runtime/pluginSetup.js +102 -0
- package/dist/cjs/runtime/providerComposition.js +113 -0
- package/dist/cjs/runtime/reactI18next.js +43 -0
- package/dist/cjs/server/apiPrefix.js +72 -0
- package/dist/cjs/server/detectorOptions.js +97 -0
- package/dist/cjs/server/index.js +17 -144
- package/dist/cjs/server/redirectPolicy.js +102 -0
- package/dist/cjs/shared/localisedUrls/config.js +49 -0
- package/dist/cjs/shared/localisedUrls/index.js +75 -0
- package/dist/cjs/shared/localisedUrls/normalise.js +87 -0
- package/dist/cjs/shared/localisedUrls/pathname.js +65 -0
- package/dist/cjs/shared/localisedUrls/patterns.js +130 -0
- package/dist/cjs/shared/localisedUrls/resolve.js +91 -0
- package/dist/cjs/shared/localisedUrls/routes.js +129 -0
- package/dist/cjs/shared/localisedUrls/types.js +18 -0
- package/dist/cjs/shared/localisedUrls.js +13 -294
- package/dist/esm/cli/index.mjs +2 -1
- package/dist/esm/runtime/Link.mjs +1 -82
- package/dist/esm/runtime/context.mjs +18 -82
- package/dist/esm/runtime/contextHelpers.mjs +84 -0
- package/dist/esm/runtime/core.mjs +30 -133
- package/dist/esm/runtime/i18n/detection/cache.mjs +102 -0
- package/dist/esm/runtime/i18n/detection/detector.mjs +62 -0
- package/dist/esm/runtime/i18n/detection/index.mjs +4 -260
- package/dist/esm/runtime/i18n/detection/initOptions.mjs +28 -0
- package/dist/esm/runtime/i18n/detection/language.mjs +21 -0
- package/dist/esm/runtime/i18n/detection/path.mjs +11 -0
- package/dist/esm/runtime/i18n/detection/priority.mjs +28 -0
- package/dist/esm/runtime/i18n/detection/ssr.mjs +26 -0
- package/dist/esm/runtime/i18n/detection/types.mjs +0 -0
- package/dist/esm/runtime/linkHelpers.mjs +98 -0
- package/dist/esm/runtime/pluginSetup.mjs +64 -0
- package/dist/esm/runtime/providerComposition.mjs +75 -0
- package/dist/esm/runtime/reactI18next.mjs +5 -0
- package/dist/esm/server/apiPrefix.mjs +31 -0
- package/dist/esm/server/detectorOptions.mjs +59 -0
- package/dist/esm/server/index.mjs +6 -133
- package/dist/esm/server/redirectPolicy.mjs +52 -0
- package/dist/esm/shared/localisedUrls/config.mjs +11 -0
- package/dist/esm/shared/localisedUrls/index.mjs +6 -0
- package/dist/esm/shared/localisedUrls/normalise.mjs +37 -0
- package/dist/esm/shared/localisedUrls/pathname.mjs +24 -0
- package/dist/esm/shared/localisedUrls/patterns.mjs +86 -0
- package/dist/esm/shared/localisedUrls/resolve.mjs +50 -0
- package/dist/esm/shared/localisedUrls/routes.mjs +88 -0
- package/dist/esm/shared/localisedUrls/types.mjs +0 -0
- package/dist/esm/shared/localisedUrls.mjs +1 -283
- package/dist/esm-node/cli/index.mjs +2 -1
- package/dist/esm-node/runtime/Link.mjs +1 -82
- package/dist/esm-node/runtime/context.mjs +18 -82
- package/dist/esm-node/runtime/contextHelpers.mjs +85 -0
- package/dist/esm-node/runtime/core.mjs +30 -133
- package/dist/esm-node/runtime/i18n/detection/cache.mjs +103 -0
- package/dist/esm-node/runtime/i18n/detection/detector.mjs +63 -0
- package/dist/esm-node/runtime/i18n/detection/index.mjs +4 -260
- package/dist/esm-node/runtime/i18n/detection/initOptions.mjs +29 -0
- package/dist/esm-node/runtime/i18n/detection/language.mjs +22 -0
- package/dist/esm-node/runtime/i18n/detection/path.mjs +12 -0
- package/dist/esm-node/runtime/i18n/detection/priority.mjs +29 -0
- package/dist/esm-node/runtime/i18n/detection/ssr.mjs +27 -0
- package/dist/esm-node/runtime/i18n/detection/types.mjs +1 -0
- package/dist/esm-node/runtime/linkHelpers.mjs +99 -0
- package/dist/esm-node/runtime/pluginSetup.mjs +65 -0
- package/dist/esm-node/runtime/providerComposition.mjs +76 -0
- package/dist/esm-node/runtime/reactI18next.mjs +6 -0
- package/dist/esm-node/server/apiPrefix.mjs +32 -0
- package/dist/esm-node/server/detectorOptions.mjs +60 -0
- package/dist/esm-node/server/index.mjs +6 -133
- package/dist/esm-node/server/redirectPolicy.mjs +53 -0
- package/dist/esm-node/shared/localisedUrls/config.mjs +12 -0
- package/dist/esm-node/shared/localisedUrls/index.mjs +7 -0
- package/dist/esm-node/shared/localisedUrls/normalise.mjs +38 -0
- package/dist/esm-node/shared/localisedUrls/pathname.mjs +25 -0
- package/dist/esm-node/shared/localisedUrls/patterns.mjs +87 -0
- package/dist/esm-node/shared/localisedUrls/resolve.mjs +51 -0
- package/dist/esm-node/shared/localisedUrls/routes.mjs +89 -0
- package/dist/esm-node/shared/localisedUrls/types.mjs +1 -0
- package/dist/esm-node/shared/localisedUrls.mjs +1 -283
- package/dist/types/runtime/Link.d.ts +3 -7
- package/dist/types/runtime/context.d.ts +2 -2
- package/dist/types/runtime/contextHelpers.d.ts +28 -0
- package/dist/types/runtime/core.d.ts +3 -7
- package/dist/types/runtime/hooks.d.ts +5 -0
- package/dist/types/runtime/i18n/detection/cache.d.ts +14 -0
- package/dist/types/runtime/i18n/detection/detector.d.ts +8 -0
- package/dist/types/runtime/i18n/detection/index.d.ts +5 -50
- package/dist/types/runtime/i18n/detection/initOptions.d.ts +10 -0
- package/dist/types/runtime/i18n/detection/language.d.ts +11 -0
- package/dist/types/runtime/i18n/detection/path.d.ts +5 -0
- package/dist/types/runtime/i18n/detection/priority.d.ts +10 -0
- package/dist/types/runtime/i18n/detection/ssr.d.ts +9 -0
- package/dist/types/runtime/i18n/detection/types.d.ts +29 -0
- package/dist/types/runtime/i18n/react-i18next.d.ts +1 -6
- package/dist/types/runtime/linkHelpers.d.ts +17 -0
- package/dist/types/runtime/pluginSetup.d.ts +32 -0
- package/dist/types/runtime/providerComposition.d.ts +15 -0
- package/dist/types/runtime/reactI18next.d.ts +7 -0
- package/dist/types/runtime/utils.d.ts +7 -2
- package/dist/types/server/apiPrefix.d.ts +7 -0
- package/dist/types/server/detectorOptions.d.ts +21 -0
- package/dist/types/server/index.d.ts +1 -6
- package/dist/types/server/redirectPolicy.d.ts +16 -0
- package/dist/types/shared/localisedUrls/config.d.ts +9 -0
- package/dist/types/shared/localisedUrls/index.d.ts +7 -0
- package/dist/types/shared/localisedUrls/normalise.d.ts +10 -0
- package/dist/types/shared/localisedUrls/pathname.d.ts +3 -0
- package/dist/types/shared/localisedUrls/patterns.d.ts +5 -0
- package/dist/types/shared/localisedUrls/resolve.d.ts +8 -0
- package/dist/types/shared/localisedUrls/routes.d.ts +3 -0
- package/dist/types/shared/localisedUrls/types.d.ts +14 -0
- package/dist/types/shared/localisedUrls.d.ts +2 -36
- package/package.json +10 -10
- package/src/cli/index.ts +3 -2
- package/src/runtime/Link.tsx +11 -138
- package/src/runtime/context.tsx +42 -196
- package/src/runtime/contextHelpers.ts +232 -0
- package/src/runtime/core.tsx +43 -274
- package/src/runtime/hooks.ts +3 -0
- package/src/runtime/i18n/detection/cache.ts +175 -0
- package/src/runtime/i18n/detection/detector.ts +157 -0
- package/src/runtime/i18n/detection/index.ts +10 -641
- package/src/runtime/i18n/detection/initOptions.ts +74 -0
- package/src/runtime/i18n/detection/language.ts +64 -0
- package/src/runtime/i18n/detection/path.ts +41 -0
- package/src/runtime/i18n/detection/priority.ts +82 -0
- package/src/runtime/i18n/detection/ssr.ts +47 -0
- package/src/runtime/i18n/detection/types.ts +33 -0
- package/src/runtime/i18n/react-i18next.ts +1 -6
- package/src/runtime/linkHelpers.ts +174 -0
- package/src/runtime/pluginSetup.ts +189 -0
- package/src/runtime/providerComposition.tsx +142 -0
- package/src/runtime/reactI18next.ts +20 -0
- package/src/runtime/utils.ts +7 -5
- package/src/server/apiPrefix.ts +67 -0
- package/src/server/detectorOptions.ts +105 -0
- package/src/server/index.ts +14 -319
- package/src/server/redirectPolicy.ts +152 -0
- package/src/shared/localisedUrls/config.ts +18 -0
- package/src/shared/localisedUrls/index.ts +13 -0
- package/src/shared/localisedUrls/normalise.ts +67 -0
- package/src/shared/localisedUrls/pathname.ts +57 -0
- package/src/shared/localisedUrls/patterns.ts +160 -0
- package/src/shared/localisedUrls/resolve.ts +118 -0
- package/src/shared/localisedUrls/routes.ts +226 -0
- package/src/shared/localisedUrls/types.ts +18 -0
- package/src/shared/localisedUrls.ts +20 -623
- package/tests/link.test.tsx +111 -0
- package/tests/linkTypes.test.ts +15 -4
- package/tests/localisedUrls.test.ts +54 -2
- package/tests/reactI18nextRuntimeBoundary.test.ts +6 -3
- package/tests/routerAdapter.test.tsx +56 -0
- package/tests/type-fixture/fixture-globals.d.ts +11 -0
- package/tests/type-fixture/tsconfig.json +1 -0
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
const LOCALE_PARAM_NAMES = new Set([
|
|
31
|
+
'lang',
|
|
32
|
+
'locale',
|
|
33
|
+
'language'
|
|
34
|
+
]);
|
|
35
|
+
const normaliseSlashes = (path)=>{
|
|
36
|
+
const withoutDuplicateSlashes = path.replace(/\/+/g, '/');
|
|
37
|
+
const withLeadingSlash = withoutDuplicateSlashes.startsWith('/') ? withoutDuplicateSlashes : `/${withoutDuplicateSlashes}`;
|
|
38
|
+
return withLeadingSlash.length > 1 ? withLeadingSlash.replace(/\/+$/, '') : withLeadingSlash;
|
|
39
|
+
};
|
|
40
|
+
const normalisePathPattern = (path)=>normaliseSlashes(path).replace(/\[(.+?)\]/g, ':$1');
|
|
41
|
+
const normalisePathname = (pathname)=>normaliseSlashes(pathname);
|
|
42
|
+
const normaliseRoutePath = (path)=>{
|
|
43
|
+
const normalized = normalisePathPattern(path);
|
|
44
|
+
return '/' === normalized ? '' : normalized.slice(1);
|
|
45
|
+
};
|
|
46
|
+
const getLocaleParamSegment = (segment)=>{
|
|
47
|
+
if (!segment.startsWith(':')) return null;
|
|
48
|
+
const paramName = segment.slice(1).replace(/\?$/, '');
|
|
49
|
+
return LOCALE_PARAM_NAMES.has(paramName) ? segment : null;
|
|
50
|
+
};
|
|
51
|
+
const splitPathSegments = (path)=>{
|
|
52
|
+
if (!path) return [];
|
|
53
|
+
return normalisePathPattern(path).split('/').filter(Boolean);
|
|
54
|
+
};
|
|
55
|
+
const stripLeadingLocaleParam = (path)=>{
|
|
56
|
+
const segments = splitPathSegments(path);
|
|
57
|
+
const leadingLocaleParam = getLocaleParamSegment(segments[0] || '');
|
|
58
|
+
if (!leadingLocaleParam) return path;
|
|
59
|
+
const remainingPath = segments.slice(1).join('/');
|
|
60
|
+
return remainingPath ? `/${remainingPath}` : void 0;
|
|
61
|
+
};
|
|
62
|
+
const getLeadingLocaleParam = (path)=>{
|
|
63
|
+
const segments = splitPathSegments(path);
|
|
64
|
+
return getLocaleParamSegment(segments[0] || '');
|
|
65
|
+
};
|
|
66
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
67
|
+
getLeadingLocaleParam: getLeadingLocaleParam,
|
|
68
|
+
normalisePathPattern: normalisePathPattern,
|
|
69
|
+
normalisePathname: normalisePathname,
|
|
70
|
+
normaliseRoutePath: normaliseRoutePath,
|
|
71
|
+
stripLeadingLocaleParam: stripLeadingLocaleParam
|
|
72
|
+
});
|
|
73
|
+
exports.getLeadingLocaleParam = __webpack_exports__.getLeadingLocaleParam;
|
|
74
|
+
exports.normalisePathPattern = __webpack_exports__.normalisePathPattern;
|
|
75
|
+
exports.normalisePathname = __webpack_exports__.normalisePathname;
|
|
76
|
+
exports.normaliseRoutePath = __webpack_exports__.normaliseRoutePath;
|
|
77
|
+
exports.stripLeadingLocaleParam = __webpack_exports__.stripLeadingLocaleParam;
|
|
78
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
79
|
+
"getLeadingLocaleParam",
|
|
80
|
+
"normalisePathPattern",
|
|
81
|
+
"normalisePathname",
|
|
82
|
+
"normaliseRoutePath",
|
|
83
|
+
"stripLeadingLocaleParam"
|
|
84
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
85
|
+
Object.defineProperty(exports, '__esModule', {
|
|
86
|
+
value: true
|
|
87
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
canonicalTargetPathname: ()=>canonicalTargetPathname,
|
|
32
|
+
localiseTargetPathname: ()=>localiseTargetPathname
|
|
33
|
+
});
|
|
34
|
+
const external_config_js_namespaceObject = require("./config.js");
|
|
35
|
+
const external_resolve_js_namespaceObject = require("./resolve.js");
|
|
36
|
+
const stripLanguagePrefix = (pathname, languages)=>{
|
|
37
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
38
|
+
const firstSegment = segments[0]?.toLowerCase();
|
|
39
|
+
if (firstSegment && languages.some((language)=>language.toLowerCase() === firstSegment)) return `/${segments.slice(1).join('/')}`;
|
|
40
|
+
return pathname || '/';
|
|
41
|
+
};
|
|
42
|
+
const localiseTargetPathname = (pathname, language, languages, localisedUrls)=>{
|
|
43
|
+
const pathWithoutLanguage = stripLanguagePrefix(pathname, languages);
|
|
44
|
+
const localisedUrlsConfig = (0, external_config_js_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
|
|
45
|
+
const resolvedPath = localisedUrlsConfig.enabled ? (0, external_resolve_js_namespaceObject.resolveLocalisedPath)(pathWithoutLanguage, language, languages, localisedUrlsConfig.map) : pathWithoutLanguage;
|
|
46
|
+
const resolvedSegments = resolvedPath.split('/').filter(Boolean);
|
|
47
|
+
return `/${[
|
|
48
|
+
language,
|
|
49
|
+
...resolvedSegments
|
|
50
|
+
].join('/')}`;
|
|
51
|
+
};
|
|
52
|
+
const canonicalTargetPathname = (pathname, languages, localisedUrls)=>{
|
|
53
|
+
const pathWithoutLanguage = stripLanguagePrefix(pathname, languages);
|
|
54
|
+
const localisedUrlsConfig = (0, external_config_js_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
|
|
55
|
+
return localisedUrlsConfig.enabled ? (0, external_resolve_js_namespaceObject.resolveCanonicalLocalisedPath)(pathWithoutLanguage, languages, localisedUrlsConfig.map) : pathWithoutLanguage;
|
|
56
|
+
};
|
|
57
|
+
exports.canonicalTargetPathname = __webpack_exports__.canonicalTargetPathname;
|
|
58
|
+
exports.localiseTargetPathname = __webpack_exports__.localiseTargetPathname;
|
|
59
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
60
|
+
"canonicalTargetPathname",
|
|
61
|
+
"localiseTargetPathname"
|
|
62
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
63
|
+
Object.defineProperty(exports, '__esModule', {
|
|
64
|
+
value: true
|
|
65
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
buildPathFromPattern: ()=>buildPathFromPattern,
|
|
32
|
+
matchPathPattern: ()=>matchPathPattern,
|
|
33
|
+
sortPatternsBySpecificity: ()=>sortPatternsBySpecificity
|
|
34
|
+
});
|
|
35
|
+
const external_normalise_js_namespaceObject = require("./normalise.js");
|
|
36
|
+
const escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
37
|
+
const getParamName = (segment)=>segment.slice(1).replace(/\?$/, '');
|
|
38
|
+
const compiledPathPatternCache = new Map();
|
|
39
|
+
const compilePathPattern = (pattern)=>{
|
|
40
|
+
const normalizedPattern = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern);
|
|
41
|
+
const cached = compiledPathPatternCache.get(normalizedPattern);
|
|
42
|
+
if (cached) return cached;
|
|
43
|
+
const names = [];
|
|
44
|
+
const segments = normalizedPattern.split('/').filter(Boolean);
|
|
45
|
+
const source = segments.map((segment)=>{
|
|
46
|
+
if (segment.startsWith(':')) {
|
|
47
|
+
names.push(getParamName(segment));
|
|
48
|
+
const paramPattern = '([^/]+)';
|
|
49
|
+
return segment.endsWith('?') ? `(?:/${paramPattern})?` : `/${paramPattern}`;
|
|
50
|
+
}
|
|
51
|
+
if ('*' === segment) {
|
|
52
|
+
names.push('*');
|
|
53
|
+
return '/(.*)';
|
|
54
|
+
}
|
|
55
|
+
return `/${escapeRegExp(segment)}`;
|
|
56
|
+
}).join('');
|
|
57
|
+
const compiled = {
|
|
58
|
+
names,
|
|
59
|
+
regexp: new RegExp(`^${source || '/'}$`)
|
|
60
|
+
};
|
|
61
|
+
compiledPathPatternCache.set(normalizedPattern, compiled);
|
|
62
|
+
return compiled;
|
|
63
|
+
};
|
|
64
|
+
const getPatternSpecificity = (pattern)=>{
|
|
65
|
+
const segments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean);
|
|
66
|
+
let staticSegments = 0;
|
|
67
|
+
let dynamicSegments = 0;
|
|
68
|
+
let splatSegments = 0;
|
|
69
|
+
for (const segment of segments)if ('*' === segment) splatSegments++;
|
|
70
|
+
else if (segment.startsWith(':')) dynamicSegments++;
|
|
71
|
+
else staticSegments++;
|
|
72
|
+
return {
|
|
73
|
+
staticSegments,
|
|
74
|
+
dynamicSegments,
|
|
75
|
+
splatSegments,
|
|
76
|
+
totalSegments: segments.length
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const comparePatternSpecificity = (left, right)=>{
|
|
80
|
+
const a = getPatternSpecificity(left);
|
|
81
|
+
const b = getPatternSpecificity(right);
|
|
82
|
+
return b.staticSegments - a.staticSegments || b.totalSegments - a.totalSegments || a.splatSegments - b.splatSegments || a.dynamicSegments - b.dynamicSegments;
|
|
83
|
+
};
|
|
84
|
+
const sortPatternsBySpecificity = (patterns)=>patterns.map((pattern, index)=>({
|
|
85
|
+
pattern,
|
|
86
|
+
index
|
|
87
|
+
})).sort((left, right)=>comparePatternSpecificity(left.pattern.pattern, right.pattern.pattern) || left.index - right.index).map(({ pattern })=>pattern);
|
|
88
|
+
const decodePathParam = (value)=>{
|
|
89
|
+
try {
|
|
90
|
+
return decodeURIComponent(value);
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const encodeSplatParam = (value)=>value.split('/').map(encodeURIComponent).join('/');
|
|
96
|
+
const matchPathPattern = (pathname, pattern)=>{
|
|
97
|
+
const { names, regexp } = compilePathPattern(pattern);
|
|
98
|
+
const match = regexp.exec((0, external_normalise_js_namespaceObject.normalisePathname)(pathname));
|
|
99
|
+
if (!match) return null;
|
|
100
|
+
const params = {};
|
|
101
|
+
for(let index = 0; index < names.length; index++){
|
|
102
|
+
const decoded = decodePathParam(match[index + 1] || '');
|
|
103
|
+
if (null === decoded) return null;
|
|
104
|
+
params[names[index]] = decoded;
|
|
105
|
+
}
|
|
106
|
+
return params;
|
|
107
|
+
};
|
|
108
|
+
const buildPathFromPattern = (pattern, params)=>{
|
|
109
|
+
const segments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean);
|
|
110
|
+
const path = segments.map((segment)=>{
|
|
111
|
+
if (segment.startsWith(':')) {
|
|
112
|
+
const param = params[getParamName(segment)];
|
|
113
|
+
return param ? encodeURIComponent(param) : '';
|
|
114
|
+
}
|
|
115
|
+
if ('*' === segment) return encodeSplatParam(params['*'] || '');
|
|
116
|
+
return segment;
|
|
117
|
+
}).filter(Boolean).join('/');
|
|
118
|
+
return `/${path}`;
|
|
119
|
+
};
|
|
120
|
+
exports.buildPathFromPattern = __webpack_exports__.buildPathFromPattern;
|
|
121
|
+
exports.matchPathPattern = __webpack_exports__.matchPathPattern;
|
|
122
|
+
exports.sortPatternsBySpecificity = __webpack_exports__.sortPatternsBySpecificity;
|
|
123
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
124
|
+
"buildPathFromPattern",
|
|
125
|
+
"matchPathPattern",
|
|
126
|
+
"sortPatternsBySpecificity"
|
|
127
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
128
|
+
Object.defineProperty(exports, '__esModule', {
|
|
129
|
+
value: true
|
|
130
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
resolveCanonicalLocalisedPath: ()=>resolveCanonicalLocalisedPath,
|
|
32
|
+
resolveLocalisedPath: ()=>resolveLocalisedPath
|
|
33
|
+
});
|
|
34
|
+
const external_normalise_js_namespaceObject = require("./normalise.js");
|
|
35
|
+
const external_patterns_js_namespaceObject = require("./patterns.js");
|
|
36
|
+
const resolveLocalisedPath = (pathname, targetLanguage, languages, localisedUrls)=>{
|
|
37
|
+
const normalizedPathname = (0, external_normalise_js_namespaceObject.normalisePathname)(pathname);
|
|
38
|
+
const canonicalCandidates = (0, external_patterns_js_namespaceObject.sortPatternsBySpecificity)(Object.entries(localisedUrls).map(([canonicalPattern, localisedUrlEntry])=>({
|
|
39
|
+
pattern: canonicalPattern,
|
|
40
|
+
canonicalPattern,
|
|
41
|
+
localisedUrlEntry
|
|
42
|
+
})));
|
|
43
|
+
for (const { canonicalPattern, localisedUrlEntry } of canonicalCandidates){
|
|
44
|
+
const targetPattern = localisedUrlEntry[targetLanguage];
|
|
45
|
+
if (!targetPattern) continue;
|
|
46
|
+
const params = (0, external_patterns_js_namespaceObject.matchPathPattern)(normalizedPathname, canonicalPattern);
|
|
47
|
+
if (params) return (0, external_patterns_js_namespaceObject.buildPathFromPattern)(targetPattern, params);
|
|
48
|
+
}
|
|
49
|
+
const localisedCandidates = (0, external_patterns_js_namespaceObject.sortPatternsBySpecificity)(Object.values(localisedUrls).flatMap((localisedUrlEntry)=>{
|
|
50
|
+
const targetPattern = localisedUrlEntry[targetLanguage];
|
|
51
|
+
if (!targetPattern) return [];
|
|
52
|
+
return languages.map((language)=>localisedUrlEntry[language]).filter((sourcePattern)=>Boolean(sourcePattern)).map((sourcePattern)=>({
|
|
53
|
+
pattern: sourcePattern,
|
|
54
|
+
sourcePattern,
|
|
55
|
+
targetPattern
|
|
56
|
+
}));
|
|
57
|
+
}));
|
|
58
|
+
for (const { sourcePattern, targetPattern } of localisedCandidates){
|
|
59
|
+
const params = (0, external_patterns_js_namespaceObject.matchPathPattern)(normalizedPathname, sourcePattern);
|
|
60
|
+
if (params) return (0, external_patterns_js_namespaceObject.buildPathFromPattern)(targetPattern, params);
|
|
61
|
+
}
|
|
62
|
+
return normalizedPathname;
|
|
63
|
+
};
|
|
64
|
+
const resolveCanonicalLocalisedPath = (pathname, languages, localisedUrls)=>{
|
|
65
|
+
const normalizedPathname = (0, external_normalise_js_namespaceObject.normalisePathname)(pathname);
|
|
66
|
+
const canonicalCandidates = (0, external_patterns_js_namespaceObject.sortPatternsBySpecificity)(Object.entries(localisedUrls).map(([canonicalPattern, localisedUrlEntry])=>({
|
|
67
|
+
pattern: canonicalPattern,
|
|
68
|
+
canonicalPattern,
|
|
69
|
+
localisedUrlEntry
|
|
70
|
+
})));
|
|
71
|
+
for (const { canonicalPattern, localisedUrlEntry } of canonicalCandidates){
|
|
72
|
+
const canonicalParams = (0, external_patterns_js_namespaceObject.matchPathPattern)(normalizedPathname, canonicalPattern);
|
|
73
|
+
if (canonicalParams) return (0, external_patterns_js_namespaceObject.buildPathFromPattern)(canonicalPattern, canonicalParams);
|
|
74
|
+
for (const language of languages){
|
|
75
|
+
const sourcePattern = localisedUrlEntry[language];
|
|
76
|
+
if (!sourcePattern) continue;
|
|
77
|
+
const params = (0, external_patterns_js_namespaceObject.matchPathPattern)(normalizedPathname, sourcePattern);
|
|
78
|
+
if (params) return (0, external_patterns_js_namespaceObject.buildPathFromPattern)(canonicalPattern, params);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return normalizedPathname;
|
|
82
|
+
};
|
|
83
|
+
exports.resolveCanonicalLocalisedPath = __webpack_exports__.resolveCanonicalLocalisedPath;
|
|
84
|
+
exports.resolveLocalisedPath = __webpack_exports__.resolveLocalisedPath;
|
|
85
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
86
|
+
"resolveCanonicalLocalisedPath",
|
|
87
|
+
"resolveLocalisedPath"
|
|
88
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
89
|
+
Object.defineProperty(exports, '__esModule', {
|
|
90
|
+
value: true
|
|
91
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
applyLocalisedUrlsToRoutes: ()=>applyLocalisedUrlsToRoutes,
|
|
32
|
+
validateLocalisedUrls: ()=>validateLocalisedUrls
|
|
33
|
+
});
|
|
34
|
+
const external_normalise_js_namespaceObject = require("./normalise.js");
|
|
35
|
+
const isLocalisableRoutePath = (path)=>{
|
|
36
|
+
const pathWithoutLocale = (0, external_normalise_js_namespaceObject.stripLeadingLocaleParam)(path);
|
|
37
|
+
if (!pathWithoutLocale || '/' === pathWithoutLocale || '*' === pathWithoutLocale) return false;
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
const joinPath = (parentPath, routePath)=>{
|
|
41
|
+
if (!isLocalisableRoutePath(routePath)) return parentPath;
|
|
42
|
+
const segment = (0, external_normalise_js_namespaceObject.normaliseRoutePath)((0, external_normalise_js_namespaceObject.stripLeadingLocaleParam)(routePath) || '');
|
|
43
|
+
return (0, external_normalise_js_namespaceObject.normalisePathPattern)(`${parentPath}/${segment}`);
|
|
44
|
+
};
|
|
45
|
+
const ensureLocalisedUrlsForPath = (canonicalPath, languages, localisedUrls)=>{
|
|
46
|
+
const entry = localisedUrls[canonicalPath];
|
|
47
|
+
if (!entry) throw new Error(`localisedUrls is enabled, but route "${canonicalPath}" does not define localised URLs for languages: ${languages.join(', ')}. Add localisedUrls["${canonicalPath}"] or set localeDetection.localisedUrls to false.`);
|
|
48
|
+
const missingLanguages = languages.filter((language)=>!entry[language]);
|
|
49
|
+
if (missingLanguages.length > 0) throw new Error(`localisedUrls["${canonicalPath}"] is missing languages: ${missingLanguages.join(', ')}. Every configured language must have a localised URL.`);
|
|
50
|
+
return entry;
|
|
51
|
+
};
|
|
52
|
+
const validateLocalisedUrls = (routes, languages, localisedUrls)=>{
|
|
53
|
+
const visit = (route, parentPath)=>{
|
|
54
|
+
const canonicalPath = joinPath(parentPath, route.path);
|
|
55
|
+
if (isLocalisableRoutePath(route.path)) ensureLocalisedUrlsForPath(canonicalPath, languages, localisedUrls);
|
|
56
|
+
if ('children' in route && route.children) route.children.forEach((child)=>visit(child, canonicalPath));
|
|
57
|
+
};
|
|
58
|
+
routes.forEach((route)=>visit(route, ''));
|
|
59
|
+
};
|
|
60
|
+
const getLocalisedRoutePaths = (canonicalPath, parentLocalisedPaths, languages, entry)=>{
|
|
61
|
+
const paths = languages.map((language)=>{
|
|
62
|
+
const fullPath = (0, external_normalise_js_namespaceObject.normalisePathPattern)(entry[language]);
|
|
63
|
+
const parentPath = (0, external_normalise_js_namespaceObject.normalisePathPattern)(parentLocalisedPaths[language] || '/');
|
|
64
|
+
if ('/' === parentPath) return (0, external_normalise_js_namespaceObject.normaliseRoutePath)(fullPath) || void 0;
|
|
65
|
+
const parentPrefix = `${parentPath}/`;
|
|
66
|
+
if (!fullPath.startsWith(parentPrefix)) throw new Error(`localisedUrls["${canonicalPath}"].${language} must be nested under "${parentPath}" because its parent route is localised there.`);
|
|
67
|
+
return (0, external_normalise_js_namespaceObject.normaliseRoutePath)(fullPath.slice(parentPath.length));
|
|
68
|
+
});
|
|
69
|
+
return Array.from(new Set(paths.filter(Boolean)));
|
|
70
|
+
};
|
|
71
|
+
const transformLocalisedRoute = (route, parentCanonicalPath, parentLocalisedPaths, languages, localisedUrls)=>{
|
|
72
|
+
const canonicalPath = joinPath(parentCanonicalPath, route.path);
|
|
73
|
+
const localisedUrlEntry = isLocalisableRoutePath(route.path) ? ensureLocalisedUrlsForPath(canonicalPath, languages, localisedUrls) : void 0;
|
|
74
|
+
const routeLocalisedPaths = localisedUrlEntry ? languages.reduce((acc, language)=>{
|
|
75
|
+
acc[language] = (0, external_normalise_js_namespaceObject.normalisePathPattern)(localisedUrlEntry[language]);
|
|
76
|
+
return acc;
|
|
77
|
+
}, {}) : parentLocalisedPaths;
|
|
78
|
+
const children = 'children' in route && route.children ? route.children.flatMap((child)=>transformLocalisedRoute(child, canonicalPath, routeLocalisedPaths, languages, localisedUrls)) : void 0;
|
|
79
|
+
const baseRoute = {
|
|
80
|
+
...route,
|
|
81
|
+
...children ? {
|
|
82
|
+
children
|
|
83
|
+
} : {}
|
|
84
|
+
};
|
|
85
|
+
if (!localisedUrlEntry) return [
|
|
86
|
+
baseRoute
|
|
87
|
+
];
|
|
88
|
+
return getLocalisedRoutePaths(canonicalPath, parentLocalisedPaths, languages, localisedUrlEntry).map((localisedPath, index)=>cloneRouteWithLocalisedPath(baseRoute, localisedPath, index, canonicalPath));
|
|
89
|
+
};
|
|
90
|
+
const legalRouteIdPart = (value)=>value.replace(/[^a-zA-Z0-9_$-]+/g, '_').replace(/^_+|_+$/g, '') || 'index';
|
|
91
|
+
const suffixRouteIds = (route, suffix)=>{
|
|
92
|
+
const children = 'children' in route && route.children ? route.children.map((child)=>suffixRouteIds(child, suffix)) : void 0;
|
|
93
|
+
return {
|
|
94
|
+
...route,
|
|
95
|
+
...route.id ? {
|
|
96
|
+
id: `${route.id}__localised_${suffix}`
|
|
97
|
+
} : {},
|
|
98
|
+
...children ? {
|
|
99
|
+
children
|
|
100
|
+
} : {}
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
const cloneRouteWithLocalisedPath = (route, path, index, canonicalPath)=>{
|
|
104
|
+
const leadingLocaleParam = (0, external_normalise_js_namespaceObject.getLeadingLocaleParam)(route.path);
|
|
105
|
+
const localisedPath = leadingLocaleParam ? (0, external_normalise_js_namespaceObject.normaliseRoutePath)(`${leadingLocaleParam}/${path}`) : path;
|
|
106
|
+
const routeWithPath = {
|
|
107
|
+
...route,
|
|
108
|
+
path: localisedPath
|
|
109
|
+
};
|
|
110
|
+
routeWithPath.modernCanonicalPath = canonicalPath;
|
|
111
|
+
return 0 === index ? routeWithPath : suffixRouteIds(routeWithPath, legalRouteIdPart(localisedPath));
|
|
112
|
+
};
|
|
113
|
+
const applyLocalisedUrlsToRoutes = (routes, languages, localisedUrls)=>{
|
|
114
|
+
const rootLocalisedPaths = languages.reduce((acc, language)=>{
|
|
115
|
+
acc[language] = '/';
|
|
116
|
+
return acc;
|
|
117
|
+
}, {});
|
|
118
|
+
validateLocalisedUrls(routes, languages, localisedUrls);
|
|
119
|
+
return routes.flatMap((route)=>transformLocalisedRoute(route, '', rootLocalisedPaths, languages, localisedUrls));
|
|
120
|
+
};
|
|
121
|
+
exports.applyLocalisedUrlsToRoutes = __webpack_exports__.applyLocalisedUrlsToRoutes;
|
|
122
|
+
exports.validateLocalisedUrls = __webpack_exports__.validateLocalisedUrls;
|
|
123
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
124
|
+
"applyLocalisedUrlsToRoutes",
|
|
125
|
+
"validateLocalisedUrls"
|
|
126
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
127
|
+
Object.defineProperty(exports, '__esModule', {
|
|
128
|
+
value: true
|
|
129
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|