next-intl 3.17.6 → 3.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/development/middleware/getAlternateLinksHeaderValue.js +10 -10
  2. package/dist/development/middleware/middleware.js +33 -28
  3. package/dist/development/middleware/resolveLocale.js +17 -14
  4. package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +3 -3
  5. package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +8 -8
  6. package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +3 -3
  7. package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +6 -6
  8. package/dist/development/routing/config.js +7 -7
  9. package/dist/development/routing/defineRouting.js +9 -0
  10. package/dist/development/routing.js +7 -0
  11. package/dist/esm/middleware/getAlternateLinksHeaderValue.js +1 -1
  12. package/dist/esm/middleware/middleware.js +1 -1
  13. package/dist/esm/middleware/resolveLocale.js +1 -1
  14. package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  15. package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  16. package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  17. package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  18. package/dist/esm/routing/config.js +1 -1
  19. package/dist/esm/routing/defineRouting.js +1 -0
  20. package/dist/esm/routing.js +1 -1
  21. package/dist/production/middleware/getAlternateLinksHeaderValue.js +1 -1
  22. package/dist/production/middleware/middleware.js +1 -1
  23. package/dist/production/middleware/resolveLocale.js +1 -1
  24. package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  25. package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  26. package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  27. package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  28. package/dist/production/routing/config.js +1 -1
  29. package/dist/production/routing/defineRouting.js +1 -0
  30. package/dist/production/routing.js +1 -1
  31. package/dist/types/src/middleware/config.d.ts +2 -13
  32. package/dist/types/src/middleware/getAlternateLinksHeaderValue.d.ts +3 -3
  33. package/dist/types/src/middleware/middleware.d.ts +3 -2
  34. package/dist/types/src/middleware/resolveLocale.d.ts +3 -2
  35. package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +6 -6
  36. package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +2 -2
  37. package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +3 -3
  38. package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +2 -2
  39. package/dist/types/src/routing/config.d.ts +36 -10
  40. package/dist/types/src/routing/defineRouting.d.ts +3 -0
  41. package/dist/types/src/routing/defineRouting.test.d.ts +1 -0
  42. package/dist/types/src/routing/index.d.ts +1 -0
  43. package/package.json +3 -3
  44. package/dist/development/middleware/config.js +0 -17
  45. package/dist/development/navigation/shared/config.js +0 -30
  46. package/dist/esm/middleware/config.js +0 -1
  47. package/dist/esm/navigation/shared/config.js +0 -1
  48. package/dist/production/middleware/config.js +0 -1
  49. package/dist/production/navigation/shared/config.js +0 -1
  50. package/dist/types/src/navigation/shared/config.d.ts +0 -24
@@ -11,10 +11,10 @@ var utils = require('./utils.js');
11
11
  function getAlternateLinksHeaderValue(_ref) {
12
12
  var _request$headers$get;
13
13
  let {
14
- config,
15
14
  localizedPathnames,
16
15
  request,
17
- resolvedLocale
16
+ resolvedLocale,
17
+ routing
18
18
  } = _ref;
19
19
  const normalizedUrl = request.nextUrl.clone();
20
20
  const host = utils.getHost(request.headers);
@@ -23,7 +23,7 @@ function getAlternateLinksHeaderValue(_ref) {
23
23
  normalizedUrl.host = host;
24
24
  }
25
25
  normalizedUrl.protocol = (_request$headers$get = request.headers.get('x-forwarded-proto')) !== null && _request$headers$get !== void 0 ? _request$headers$get : normalizedUrl.protocol;
26
- normalizedUrl.pathname = utils.getNormalizedPathname(normalizedUrl.pathname, config.locales, config.localePrefix);
26
+ normalizedUrl.pathname = utils.getNormalizedPathname(normalizedUrl.pathname, routing.locales, routing.localePrefix);
27
27
  function getAlternateEntry(url, locale) {
28
28
  url.pathname = utils$1.normalizeTrailingSlash(url.pathname);
29
29
  if (request.nextUrl.basePath) {
@@ -39,7 +39,7 @@ function getAlternateLinksHeaderValue(_ref) {
39
39
  return pathname;
40
40
  }
41
41
  }
42
- const links = utils.getLocalePrefixes(config.locales, config.localePrefix).flatMap(_ref2 => {
42
+ const links = utils.getLocalePrefixes(routing.locales, routing.localePrefix).flatMap(_ref2 => {
43
43
  let [locale, prefix] = _ref2;
44
44
  function prefixPathname(pathname) {
45
45
  if (pathname === '/') {
@@ -49,8 +49,8 @@ function getAlternateLinksHeaderValue(_ref) {
49
49
  }
50
50
  }
51
51
  let url;
52
- if (config.domains) {
53
- const domainConfigs = config.domains.filter(cur => utils.isLocaleSupportedOnDomain(locale, cur)) || [];
52
+ if (routing.domains) {
53
+ const domainConfigs = routing.domains.filter(cur => utils.isLocaleSupportedOnDomain(locale, cur)) || [];
54
54
  return domainConfigs.map(domainConfig => {
55
55
  url = new URL(normalizedUrl);
56
56
  url.port = '';
@@ -59,7 +59,7 @@ function getAlternateLinksHeaderValue(_ref) {
59
59
  // Important: Use `normalizedUrl` here, as `url` potentially uses
60
60
  // a `basePath` that automatically gets applied to the pathname
61
61
  url.pathname = getLocalizedPathname(normalizedUrl.pathname, locale);
62
- if (locale !== domainConfig.defaultLocale || config.localePrefix.mode === 'always') {
62
+ if (locale !== domainConfig.defaultLocale || routing.localePrefix.mode === 'always') {
63
63
  url.pathname = prefixPathname(url.pathname);
64
64
  }
65
65
  return getAlternateEntry(url, locale);
@@ -71,7 +71,7 @@ function getAlternateLinksHeaderValue(_ref) {
71
71
  } else {
72
72
  pathname = normalizedUrl.pathname;
73
73
  }
74
- if (locale !== config.defaultLocale || config.localePrefix.mode === 'always') {
74
+ if (locale !== routing.defaultLocale || routing.localePrefix.mode === 'always') {
75
75
  pathname = prefixPathname(pathname);
76
76
  }
77
77
  url = new URL(pathname, normalizedUrl);
@@ -82,9 +82,9 @@ function getAlternateLinksHeaderValue(_ref) {
82
82
  // Add x-default entry
83
83
  const shouldAddXDefault =
84
84
  // For domain-based routing there is no reasonable x-default
85
- !config.domains && (config.localePrefix.mode !== 'always' || normalizedUrl.pathname === '/');
85
+ !routing.domains && (routing.localePrefix.mode !== 'always' || normalizedUrl.pathname === '/');
86
86
  if (shouldAddXDefault) {
87
- const url = new URL(getLocalizedPathname(normalizedUrl.pathname, config.defaultLocale), normalizedUrl);
87
+ const url = new URL(getLocalizedPathname(normalizedUrl.pathname, routing.defaultLocale), normalizedUrl);
88
88
  links.push(getAlternateEntry(url, 'x-default'));
89
89
  }
90
90
  return links.join(', ');
@@ -3,18 +3,23 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var server = require('next/server');
6
+ var config = require('../routing/config.js');
6
7
  var constants = require('../shared/constants.js');
7
8
  var utils$1 = require('../shared/utils.js');
8
- var config = require('./config.js');
9
9
  var getAlternateLinksHeaderValue = require('./getAlternateLinksHeaderValue.js');
10
10
  var resolveLocale = require('./resolveLocale.js');
11
11
  var syncCookie = require('./syncCookie.js');
12
12
  var utils = require('./utils.js');
13
13
 
14
- function createMiddleware(input) {
15
- const config$1 = config.receiveConfig(input);
14
+ function createMiddleware(routing, options) {
15
+ var _ref, _options$alternateLin, _ref2, _options$localeDetect;
16
+ const resolvedRouting = config.receiveRoutingConfig(routing);
17
+ const resolvedOptions = {
18
+ alternateLinks: (_ref = (_options$alternateLin = options === null || options === void 0 ? void 0 : options.alternateLinks) !== null && _options$alternateLin !== void 0 ? _options$alternateLin : routing.alternateLinks) !== null && _ref !== void 0 ? _ref : true,
19
+ localeDetection: (_ref2 = (_options$localeDetect = options === null || options === void 0 ? void 0 : options.localeDetection) !== null && _options$localeDetect !== void 0 ? _options$localeDetect : routing === null || routing === void 0 ? void 0 : routing.localeDetection) !== null && _ref2 !== void 0 ? _ref2 : true
20
+ };
16
21
  return function middleware(request) {
17
- var _config$domains;
22
+ var _resolvedRouting$doma;
18
23
  // Resolve potential foreign symbols (e.g. /ja/%E7%B4%84 → /ja/約))
19
24
  const unsafeExternalPathname = decodeURI(request.nextUrl.pathname);
20
25
 
@@ -24,10 +29,10 @@ function createMiddleware(input) {
24
29
  const {
25
30
  domain,
26
31
  locale
27
- } = resolveLocale.default(config$1, request.headers, request.cookies, externalPathname);
28
- const hasMatchedDefaultLocale = domain ? domain.defaultLocale === locale : locale === config$1.defaultLocale;
29
- const domainsConfig = ((_config$domains = config$1.domains) === null || _config$domains === void 0 ? void 0 : _config$domains.filter(curDomain => utils.isLocaleSupportedOnDomain(locale, curDomain))) || [];
30
- const hasUnknownHost = config$1.domains != null && !domain;
32
+ } = resolveLocale.default(resolvedRouting, resolvedOptions, request.headers, request.cookies, externalPathname);
33
+ const hasMatchedDefaultLocale = domain ? domain.defaultLocale === locale : locale === resolvedRouting.defaultLocale;
34
+ const domainsConfig = ((_resolvedRouting$doma = resolvedRouting.domains) === null || _resolvedRouting$doma === void 0 ? void 0 : _resolvedRouting$doma.filter(curDomain => utils.isLocaleSupportedOnDomain(locale, curDomain))) || [];
35
+ const hasUnknownHost = resolvedRouting.domains != null && !domain;
31
36
  function rewrite(url) {
32
37
  const urlObj = new URL(url, request.url);
33
38
  if (request.nextUrl.basePath) {
@@ -47,8 +52,8 @@ function createMiddleware(input) {
47
52
  const bestMatchingDomain = utils.getBestMatchingDomain(domain, locale, domainsConfig);
48
53
  if (bestMatchingDomain) {
49
54
  redirectDomain = bestMatchingDomain.domain;
50
- if (bestMatchingDomain.defaultLocale === locale && config$1.localePrefix.mode === 'as-needed') {
51
- urlObj.pathname = utils.getNormalizedPathname(urlObj.pathname, config$1.locales, config$1.localePrefix);
55
+ if (bestMatchingDomain.defaultLocale === locale && resolvedRouting.localePrefix.mode === 'as-needed') {
56
+ urlObj.pathname = utils.getNormalizedPathname(urlObj.pathname, resolvedRouting.locales, resolvedRouting.localePrefix);
52
57
  }
53
58
  }
54
59
  }
@@ -65,20 +70,20 @@ function createMiddleware(input) {
65
70
  }
66
71
  return server.NextResponse.redirect(urlObj.toString());
67
72
  }
68
- const unprefixedExternalPathname = utils.getNormalizedPathname(externalPathname, config$1.locales, config$1.localePrefix);
69
- const pathnameMatch = utils.getPathnameMatch(externalPathname, config$1.locales, config$1.localePrefix);
73
+ const unprefixedExternalPathname = utils.getNormalizedPathname(externalPathname, resolvedRouting.locales, resolvedRouting.localePrefix);
74
+ const pathnameMatch = utils.getPathnameMatch(externalPathname, resolvedRouting.locales, resolvedRouting.localePrefix);
70
75
  const hasLocalePrefix = pathnameMatch != null;
71
- const isUnprefixedRouting = config$1.localePrefix.mode === 'never' || hasMatchedDefaultLocale && config$1.localePrefix.mode === 'as-needed';
76
+ const isUnprefixedRouting = resolvedRouting.localePrefix.mode === 'never' || hasMatchedDefaultLocale && resolvedRouting.localePrefix.mode === 'as-needed';
72
77
  let response;
73
78
  let internalTemplateName;
74
79
  let unprefixedInternalPathname = unprefixedExternalPathname;
75
- if (config$1.pathnames) {
80
+ if ('pathnames' in resolvedRouting) {
76
81
  let resolvedTemplateLocale;
77
- [resolvedTemplateLocale, internalTemplateName] = utils.getInternalTemplate(config$1.pathnames, unprefixedExternalPathname, locale);
82
+ [resolvedTemplateLocale, internalTemplateName] = utils.getInternalTemplate(resolvedRouting.pathnames, unprefixedExternalPathname, locale);
78
83
  if (internalTemplateName) {
79
- const pathnameConfig = config$1.pathnames[internalTemplateName];
84
+ const pathnameConfig = resolvedRouting.pathnames[internalTemplateName];
80
85
  const localeTemplate = typeof pathnameConfig === 'string' ? pathnameConfig :
81
- // @ts-expect-error This is ok
86
+ // @ts-expect-error -- This is fine
82
87
  pathnameConfig[locale];
83
88
  if (utils$1.matchesPathname(localeTemplate, unprefixedExternalPathname)) {
84
89
  unprefixedInternalPathname = utils.formatTemplatePathname(unprefixedExternalPathname, localeTemplate, internalTemplateName);
@@ -87,14 +92,14 @@ function createMiddleware(input) {
87
92
  if (resolvedTemplateLocale) {
88
93
  // A localized pathname from another locale has matched
89
94
  sourceTemplate = typeof pathnameConfig === 'string' ? pathnameConfig :
90
- // @ts-expect-error This is ok
95
+ // @ts-expect-error -- This is fine
91
96
  pathnameConfig[resolvedTemplateLocale];
92
97
  } else {
93
98
  // An internal pathname has matched that
94
99
  // doesn't have a localized pathname
95
100
  sourceTemplate = internalTemplateName;
96
101
  }
97
- const localePrefix = isUnprefixedRouting ? undefined : utils$1.getLocalePrefix(locale, config$1.localePrefix);
102
+ const localePrefix = isUnprefixedRouting ? undefined : utils$1.getLocalePrefix(locale, resolvedRouting.localePrefix);
98
103
  const template = utils.formatTemplatePathname(unprefixedExternalPathname, sourceTemplate, localeTemplate);
99
104
  response = redirect(utils.formatPathname(template, localePrefix, request.nextUrl.search));
100
105
  }
@@ -105,19 +110,19 @@ function createMiddleware(input) {
105
110
  if (isUnprefixedRouting) {
106
111
  response = rewrite(utils.formatPathname(unprefixedInternalPathname, utils.getLocaleAsPrefix(locale), request.nextUrl.search));
107
112
  } else {
108
- response = redirect(utils.formatPathname(unprefixedExternalPathname, utils$1.getLocalePrefix(locale, config$1.localePrefix), request.nextUrl.search));
113
+ response = redirect(utils.formatPathname(unprefixedExternalPathname, utils$1.getLocalePrefix(locale, resolvedRouting.localePrefix), request.nextUrl.search));
109
114
  }
110
115
  } else {
111
116
  const internalHref = utils.formatPathname(unprefixedInternalPathname, utils.getLocaleAsPrefix(locale), request.nextUrl.search);
112
117
  if (hasLocalePrefix) {
113
118
  const externalHref = utils.formatPathname(unprefixedExternalPathname, pathnameMatch.prefix, request.nextUrl.search);
114
- if (config$1.localePrefix.mode === 'never') {
119
+ if (resolvedRouting.localePrefix.mode === 'never') {
115
120
  response = redirect(utils.formatPathname(unprefixedExternalPathname, undefined, request.nextUrl.search));
116
121
  } else if (pathnameMatch.exact) {
117
122
  if (hasMatchedDefaultLocale && isUnprefixedRouting) {
118
123
  response = redirect(utils.formatPathname(unprefixedExternalPathname, undefined, request.nextUrl.search));
119
124
  } else {
120
- if (config$1.domains) {
125
+ if (resolvedRouting.domains) {
121
126
  const pathDomain = utils.getBestMatchingDomain(domain, pathnameMatch.locale, domainsConfig);
122
127
  if ((domain === null || domain === void 0 ? void 0 : domain.domain) !== (pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain) && !hasUnknownHost) {
123
128
  response = redirect(externalHref, pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain);
@@ -135,19 +140,19 @@ function createMiddleware(input) {
135
140
  if (isUnprefixedRouting) {
136
141
  response = rewrite(internalHref);
137
142
  } else {
138
- response = redirect(utils.formatPathname(unprefixedExternalPathname, utils$1.getLocalePrefix(locale, config$1.localePrefix), request.nextUrl.search));
143
+ response = redirect(utils.formatPathname(unprefixedExternalPathname, utils$1.getLocalePrefix(locale, resolvedRouting.localePrefix), request.nextUrl.search));
139
144
  }
140
145
  }
141
146
  }
142
147
  }
143
- if (config$1.localeDetection) {
148
+ if (resolvedOptions.localeDetection) {
144
149
  syncCookie.default(request, response, locale);
145
150
  }
146
- if (config$1.localePrefix.mode !== 'never' && config$1.alternateLinks && config$1.locales.length > 1) {
147
- var _config$pathnames;
151
+ if (resolvedRouting.localePrefix.mode !== 'never' && resolvedOptions.alternateLinks && resolvedRouting.locales.length > 1) {
152
+ var _resolvedRouting$path;
148
153
  response.headers.set('Link', getAlternateLinksHeaderValue.default({
149
- config: config$1,
150
- localizedPathnames: internalTemplateName != null ? (_config$pathnames = config$1.pathnames) === null || _config$pathnames === void 0 ? void 0 : _config$pathnames[internalTemplateName] : undefined,
154
+ routing: resolvedRouting,
155
+ localizedPathnames: internalTemplateName != null && 'pathnames' in resolvedRouting ? (_resolvedRouting$path = resolvedRouting.pathnames) === null || _resolvedRouting$path === void 0 ? void 0 : _resolvedRouting$path[internalTemplateName] : undefined,
151
156
  request,
152
157
  resolvedLocale: locale
153
158
  }));
@@ -50,13 +50,15 @@ function getLocaleFromCookie(requestCookies, locales) {
50
50
  }
51
51
  }
52
52
  }
53
- function resolveLocaleFromPrefix(_ref, requestHeaders, requestCookies, pathname) {
53
+ function resolveLocaleFromPrefix(_ref, _ref2, requestHeaders, requestCookies, pathname) {
54
54
  let {
55
55
  defaultLocale,
56
- localeDetection,
57
56
  localePrefix,
58
57
  locales
59
58
  } = _ref;
59
+ let {
60
+ localeDetection
61
+ } = _ref2;
60
62
  let locale;
61
63
 
62
64
  // Prio 1: Use route prefix
@@ -81,12 +83,12 @@ function resolveLocaleFromPrefix(_ref, requestHeaders, requestCookies, pathname)
81
83
  }
82
84
  return locale;
83
85
  }
84
- function resolveLocaleFromDomain(config, requestHeaders, requestCookies, pathname) {
85
- const domains = config.domains;
86
+ function resolveLocaleFromDomain(routing, options, requestHeaders, requestCookies, pathname) {
87
+ const domains = routing.domains;
86
88
  const domain = findDomainFromHost(requestHeaders, domains);
87
89
  if (!domain) {
88
90
  return {
89
- locale: resolveLocaleFromPrefix(config, requestHeaders, requestCookies, pathname)
91
+ locale: resolveLocaleFromPrefix(routing, options, requestHeaders, requestCookies, pathname)
90
92
  };
91
93
  }
92
94
  let locale;
@@ -94,7 +96,7 @@ function resolveLocaleFromDomain(config, requestHeaders, requestCookies, pathnam
94
96
  // Prio 1: Use route prefix
95
97
  if (pathname) {
96
98
  var _getPathnameMatch2;
97
- const prefixLocale = (_getPathnameMatch2 = utils.getPathnameMatch(pathname, config.locales, config.localePrefix)) === null || _getPathnameMatch2 === void 0 ? void 0 : _getPathnameMatch2.locale;
99
+ const prefixLocale = (_getPathnameMatch2 = utils.getPathnameMatch(pathname, routing.locales, routing.localePrefix)) === null || _getPathnameMatch2 === void 0 ? void 0 : _getPathnameMatch2.locale;
98
100
  if (prefixLocale) {
99
101
  if (utils.isLocaleSupportedOnDomain(prefixLocale, domain)) {
100
102
  locale = prefixLocale;
@@ -109,8 +111,8 @@ function resolveLocaleFromDomain(config, requestHeaders, requestCookies, pathnam
109
111
  }
110
112
 
111
113
  // Prio 2: Use existing cookie
112
- if (!locale && config.localeDetection && requestCookies) {
113
- const cookieLocale = getLocaleFromCookie(requestCookies, config.locales);
114
+ if (!locale && options.localeDetection && requestCookies) {
115
+ const cookieLocale = getLocaleFromCookie(requestCookies, routing.locales);
114
116
  if (cookieLocale) {
115
117
  if (utils.isLocaleSupportedOnDomain(cookieLocale, domain)) {
116
118
  locale = cookieLocale;
@@ -119,8 +121,8 @@ function resolveLocaleFromDomain(config, requestHeaders, requestCookies, pathnam
119
121
  }
120
122
 
121
123
  // Prio 3: Use the `accept-language` header
122
- if (!locale && config.localeDetection && requestHeaders) {
123
- const headerLocale = getAcceptLanguageLocale(requestHeaders, domain.locales || config.locales, domain.defaultLocale);
124
+ if (!locale && options.localeDetection && requestHeaders) {
125
+ const headerLocale = getAcceptLanguageLocale(requestHeaders, domain.locales || routing.locales, domain.defaultLocale);
124
126
  if (headerLocale) {
125
127
  locale = headerLocale;
126
128
  }
@@ -135,12 +137,13 @@ function resolveLocaleFromDomain(config, requestHeaders, requestCookies, pathnam
135
137
  domain
136
138
  };
137
139
  }
138
- function resolveLocale(config, requestHeaders, requestCookies, pathname) {
139
- if (config.domains) {
140
- return resolveLocaleFromDomain(config, requestHeaders, requestCookies, pathname);
140
+ function resolveLocale(routing, options, requestHeaders, requestCookies, pathname) {
141
+ if (routing.domains) {
142
+ const routingWithDomains = routing;
143
+ return resolveLocaleFromDomain(routingWithDomains, options, requestHeaders, requestCookies, pathname);
141
144
  } else {
142
145
  return {
143
- locale: resolveLocaleFromPrefix(config, requestHeaders, requestCookies, pathname)
146
+ locale: resolveLocaleFromPrefix(routing, options, requestHeaders, requestCookies, pathname)
144
147
  };
145
148
  }
146
149
  }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
7
  var useLocale = require('../../react-client/useLocale.js');
8
- var config = require('../shared/config.js');
8
+ var config = require('../../routing/config.js');
9
9
  var utils = require('../shared/utils.js');
10
10
  var ClientLink = require('./ClientLink.js');
11
11
  var redirects = require('./redirects.js');
@@ -16,8 +16,8 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
16
 
17
17
  var React__default = /*#__PURE__*/_interopDefault(React);
18
18
 
19
- function createLocalizedPathnamesNavigation(input) {
20
- const config$1 = config.receiveLocalizedNavigationRoutingConfig(input);
19
+ function createLocalizedPathnamesNavigation(routing) {
20
+ const config$1 = config.receiveRoutingConfig(routing);
21
21
  function useTypedLocale() {
22
22
  const locale = useLocale.default();
23
23
  const isValid = config$1.locales.includes(locale);
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
- var config = require('../shared/config.js');
7
+ var config = require('../../routing/config.js');
8
8
  var ClientLink = require('./ClientLink.js');
9
9
  var redirects = require('./redirects.js');
10
10
  var useBasePathname = require('./useBasePathname.js');
@@ -14,12 +14,12 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
15
  var React__default = /*#__PURE__*/_interopDefault(React);
16
16
 
17
- function createSharedPathnamesNavigation(input) {
18
- const config$1 = config.receiveSharedNavigationRoutingConfig(input);
17
+ function createSharedPathnamesNavigation(routing) {
18
+ const localePrefix = config.receiveLocalePrefixConfig(routing === null || routing === void 0 ? void 0 : routing.localePrefix);
19
19
  function Link(props, ref) {
20
20
  return /*#__PURE__*/React__default.default.createElement(ClientLink.default, _rollupPluginBabelHelpers.extends({
21
21
  ref: ref,
22
- localePrefix: config$1.localePrefix
22
+ localePrefix: localePrefix
23
23
  }, props));
24
24
  }
25
25
  const LinkWithRef = /*#__PURE__*/React.forwardRef(Link);
@@ -30,7 +30,7 @@ function createSharedPathnamesNavigation(input) {
30
30
  }
31
31
  return redirects.clientRedirect({
32
32
  pathname,
33
- localePrefix: config$1.localePrefix
33
+ localePrefix
34
34
  }, ...args);
35
35
  }
36
36
  function permanentRedirect(pathname) {
@@ -39,16 +39,16 @@ function createSharedPathnamesNavigation(input) {
39
39
  }
40
40
  return redirects.clientPermanentRedirect({
41
41
  pathname,
42
- localePrefix: config$1.localePrefix
42
+ localePrefix
43
43
  }, ...args);
44
44
  }
45
45
  function usePathname() {
46
- const result = useBasePathname.default(config$1.localePrefix);
46
+ const result = useBasePathname.default(localePrefix);
47
47
  // @ts-expect-error -- Mirror the behavior from Next.js, where `null` is returned when `usePathname` is used outside of Next, but the types indicate that a string is always returned.
48
48
  return result;
49
49
  }
50
50
  function useRouter() {
51
- return useBaseRouter.default(config$1.localePrefix);
51
+ return useBaseRouter.default(localePrefix);
52
52
  }
53
53
  return {
54
54
  Link: LinkWithRef,
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
+ var config = require('../../routing/config.js');
7
8
  var RequestLocale = require('../../server/react-server/RequestLocale.js');
8
- var config = require('../shared/config.js');
9
9
  var utils = require('../shared/utils.js');
10
10
  var ServerLink = require('./ServerLink.js');
11
11
  var redirects = require('./redirects.js');
@@ -14,8 +14,8 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
15
  var React__default = /*#__PURE__*/_interopDefault(React);
16
16
 
17
- function createLocalizedPathnamesNavigation(input) {
18
- const config$1 = config.receiveLocalizedNavigationRoutingConfig(input);
17
+ function createLocalizedPathnamesNavigation(routing) {
18
+ const config$1 = config.receiveRoutingConfig(routing);
19
19
  function Link(_ref) {
20
20
  let {
21
21
  href,
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
- var config = require('../shared/config.js');
7
+ var config = require('../../routing/config.js');
8
8
  var ServerLink = require('./ServerLink.js');
9
9
  var redirects = require('./redirects.js');
10
10
 
@@ -12,8 +12,8 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
12
 
13
13
  var React__default = /*#__PURE__*/_interopDefault(React);
14
14
 
15
- function createSharedPathnamesNavigation(input) {
16
- const config$1 = config.receiveSharedNavigationRoutingConfig(input);
15
+ function createSharedPathnamesNavigation(routing) {
16
+ const localePrefix = config.receiveLocalePrefixConfig(routing === null || routing === void 0 ? void 0 : routing.localePrefix);
17
17
  function notSupported(hookName) {
18
18
  return () => {
19
19
  throw new Error("`".concat(hookName, "` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."));
@@ -21,7 +21,7 @@ function createSharedPathnamesNavigation(input) {
21
21
  }
22
22
  function Link(props) {
23
23
  return /*#__PURE__*/React__default.default.createElement(ServerLink.default, _rollupPluginBabelHelpers.extends({
24
- localePrefix: config$1.localePrefix
24
+ localePrefix: localePrefix
25
25
  }, props));
26
26
  }
27
27
  function redirect(pathname) {
@@ -30,7 +30,7 @@ function createSharedPathnamesNavigation(input) {
30
30
  }
31
31
  return redirects.serverRedirect({
32
32
  pathname,
33
- localePrefix: config$1.localePrefix
33
+ localePrefix
34
34
  }, ...args);
35
35
  }
36
36
  function permanentRedirect(pathname) {
@@ -39,7 +39,7 @@ function createSharedPathnamesNavigation(input) {
39
39
  }
40
40
  return redirects.serverPermanentRedirect({
41
41
  pathname,
42
- localePrefix: config$1.localePrefix
42
+ localePrefix
43
43
  }, ...args);
44
44
  }
45
45
  return {
@@ -2,13 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /**
6
- * Maintainer note: The config that is accepted by the middleware, the shared
7
- * and the localized pathnames navigation factory function is slightly
8
- * different. This type declares the shared base config that is accepted by all
9
- * of them. Properties that are different are declared in consuming types.
10
- */
11
-
5
+ function receiveRoutingConfig(input) {
6
+ return {
7
+ ...input,
8
+ localePrefix: receiveLocalePrefixConfig(input.localePrefix)
9
+ };
10
+ }
12
11
  function receiveLocalePrefixConfig(localePrefix) {
13
12
  return typeof localePrefix === 'object' ? localePrefix : {
14
13
  mode: localePrefix || 'always'
@@ -16,3 +15,4 @@ function receiveLocalePrefixConfig(localePrefix) {
16
15
  }
17
16
 
18
17
  exports.receiveLocalePrefixConfig = receiveLocalePrefixConfig;
18
+ exports.receiveRoutingConfig = receiveRoutingConfig;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function defineRouting(config) {
6
+ return config;
7
+ }
8
+
9
+ exports.default = defineRouting;
@@ -1,2 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var defineRouting = require('./routing/defineRouting.js');
6
+
7
+
8
+
9
+ exports.defineRouting = defineRouting.default;
@@ -1 +1 @@
1
- import{normalizeTrailingSlash as e}from"../shared/utils.js";import{getHost as a,getNormalizedPathname as t,getLocalePrefixes as o,isLocaleSupportedOnDomain as n,applyBasePath as l,formatTemplatePathname as r}from"./utils.js";function c(c){var m;let{config:p,localizedPathnames:s,request:f,resolvedLocale:i}=c;const h=f.nextUrl.clone(),d=a(f.headers);function u(a,t){return a.pathname=e(a.pathname),f.nextUrl.basePath&&((a=new URL(a)).pathname=l(a.pathname,f.nextUrl.basePath)),"<".concat(a.toString(),'>; rel="alternate"; hreflang="').concat(t,'"')}function x(e,a){return s&&"object"==typeof s?r(e,s[i],s[a]):e}d&&(h.port="",h.host=d),h.protocol=null!==(m=f.headers.get("x-forwarded-proto"))&&void 0!==m?m:h.protocol,h.pathname=t(h.pathname,p.locales,p.localePrefix);const w=o(p.locales,p.localePrefix).flatMap((e=>{let a,[t,o]=e;function l(e){return"/"===e?o:o+e}if(p.domains){return(p.domains.filter((e=>n(t,e)))||[]).map((e=>(a=new URL(h),a.port="",a.host=e.domain,a.pathname=x(h.pathname,t),t===e.defaultLocale&&"always"!==p.localePrefix.mode||(a.pathname=l(a.pathname)),u(a,t))))}{let e;e=s&&"object"==typeof s?x(h.pathname,t):h.pathname,t===p.defaultLocale&&"always"!==p.localePrefix.mode||(e=l(e)),a=new URL(e,h)}return u(a,t)}));if(!p.domains&&("always"!==p.localePrefix.mode||"/"===h.pathname)){const e=new URL(x(h.pathname,p.defaultLocale),h);w.push(u(e,"x-default"))}return w.join(", ")}export{c as default};
1
+ import{normalizeTrailingSlash as e}from"../shared/utils.js";import{getHost as a,getNormalizedPathname as t,getLocalePrefixes as o,isLocaleSupportedOnDomain as n,applyBasePath as l,formatTemplatePathname as r}from"./utils.js";function c(c){var m;let{localizedPathnames:p,request:s,resolvedLocale:i,routing:f}=c;const h=s.nextUrl.clone(),u=a(s.headers);function d(a,t){return a.pathname=e(a.pathname),s.nextUrl.basePath&&((a=new URL(a)).pathname=l(a.pathname,s.nextUrl.basePath)),"<".concat(a.toString(),'>; rel="alternate"; hreflang="').concat(t,'"')}function x(e,a){return p&&"object"==typeof p?r(e,p[i],p[a]):e}u&&(h.port="",h.host=u),h.protocol=null!==(m=s.headers.get("x-forwarded-proto"))&&void 0!==m?m:h.protocol,h.pathname=t(h.pathname,f.locales,f.localePrefix);const w=o(f.locales,f.localePrefix).flatMap((e=>{let a,[t,o]=e;function l(e){return"/"===e?o:o+e}if(f.domains){return(f.domains.filter((e=>n(t,e)))||[]).map((e=>(a=new URL(h),a.port="",a.host=e.domain,a.pathname=x(h.pathname,t),t===e.defaultLocale&&"always"!==f.localePrefix.mode||(a.pathname=l(a.pathname)),d(a,t))))}{let e;e=p&&"object"==typeof p?x(h.pathname,t):h.pathname,t===f.defaultLocale&&"always"!==f.localePrefix.mode||(e=l(e)),a=new URL(e,h)}return d(a,t)}));if(!f.domains&&("always"!==f.localePrefix.mode||"/"===h.pathname)){const e=new URL(x(h.pathname,f.defaultLocale),h);w.push(d(e,"x-default"))}return w.join(", ")}export{c as default};
@@ -1 +1 @@
1
- import{NextResponse as e}from"next/server";import{HEADER_LOCALE_NAME as o}from"../shared/constants.js";import{matchesPathname as l,normalizeTrailingSlash as r,getLocalePrefix as t}from"../shared/utils.js";import{receiveConfig as a}from"./config.js";import n from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import i from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as h,formatTemplatePathname as x,formatPathname as u,getBestMatchingDomain as p,applyBasePath as v,getLocaleAsPrefix as U}from"./utils.js";function P(P){const g=a(P);return function(a){var P;const L=decodeURI(a.nextUrl.pathname),j=c(L),{domain:w,locale:k}=s(g,a.headers,a.cookies,j),b=w?w.defaultLocale===k:k===g.defaultLocale,y=(null===(P=g.domains)||void 0===P?void 0:P.filter((e=>d(k,e))))||[],R=null!=g.domains&&!w;function q(l){const r=new URL(l,a.url);a.nextUrl.basePath&&(r.pathname=v(r.pathname,a.nextUrl.basePath));const t=new Headers(a.headers);return t.set(o,k),e.rewrite(r,{request:{headers:t}})}function H(o,l){const t=new URL(r(o),a.url);if(y.length>0&&!l){const e=p(w,k,y);e&&(l=e.domain,e.defaultLocale===k&&"as-needed"===g.localePrefix.mode&&(t.pathname=f(t.pathname,g.locales,g.localePrefix)))}var n,s;l&&(t.host=l,a.headers.get("x-forwarded-host")&&(t.protocol=null!==(n=a.headers.get("x-forwarded-proto"))&&void 0!==n?n:a.nextUrl.protocol,t.port=null!==(s=a.headers.get("x-forwarded-port"))&&void 0!==s?s:""));return a.nextUrl.basePath&&(t.pathname=v(t.pathname,a.nextUrl.basePath)),e.redirect(t.toString())}const z=f(j,g.locales,g.localePrefix),A=m(j,g.locales,g.localePrefix),C=null!=A,D="never"===g.localePrefix.mode||b&&"as-needed"===g.localePrefix.mode;let I,S,V=z;if(g.pathnames){let e;if([e,S]=h(g.pathnames,z,k),S){const o=g.pathnames[S],r="string"==typeof o?o:o[k];if(l(r,z))V=x(z,r,S);else{let l;l=e?"string"==typeof o?o:o[e]:S;const n=D?void 0:t(k,g.localePrefix),s=x(z,l,r);I=H(u(s,n,a.nextUrl.search))}}}if(!I)if("/"!==V||C){const e=u(V,U(k),a.nextUrl.search);if(C){const o=u(z,A.prefix,a.nextUrl.search);if("never"===g.localePrefix.mode)I=H(u(z,void 0,a.nextUrl.search));else if(A.exact)if(b&&D)I=H(u(z,void 0,a.nextUrl.search));else if(g.domains){const l=p(w,A.locale,y);I=(null==w?void 0:w.domain)===(null==l?void 0:l.domain)||R?q(e):H(o,null==l?void 0:l.domain)}else I=q(e);else I=H(o)}else I=D?q(e):H(u(z,t(k,g.localePrefix),a.nextUrl.search))}else I=D?q(u(V,U(k),a.nextUrl.search)):H(u(z,t(k,g.localePrefix),a.nextUrl.search));var B;(g.localeDetection&&i(a,I,k),"never"!==g.localePrefix.mode&&g.alternateLinks&&g.locales.length>1)&&I.headers.set("Link",n({config:g,localizedPathnames:null!=S?null===(B=g.pathnames)||void 0===B?void 0:B[S]:void 0,request:a,resolvedLocale:k}));return I}}export{P as default};
1
+ import{NextResponse as e}from"next/server";import{receiveRoutingConfig as l}from"../routing/config.js";import{HEADER_LOCALE_NAME as o}from"../shared/constants.js";import{matchesPathname as t,normalizeTrailingSlash as a,getLocalePrefix as n}from"../shared/utils.js";import r from"./getAlternateLinksHeaderValue.js";import i from"./resolveLocale.js";import s from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as h,formatTemplatePathname as u,formatPathname as x,getBestMatchingDomain as v,applyBasePath as p,getLocaleAsPrefix as U}from"./utils.js";function P(P,L){var g,k,j,w;const b=l(P),D={alternateLinks:null===(g=null!==(k=null==L?void 0:L.alternateLinks)&&void 0!==k?k:P.alternateLinks)||void 0===g||g,localeDetection:null===(j=null!==(w=null==L?void 0:L.localeDetection)&&void 0!==w?w:null==P?void 0:P.localeDetection)||void 0===j||j};return function(l){var P;const L=decodeURI(l.nextUrl.pathname),g=c(L),{domain:k,locale:j}=i(b,D,l.headers,l.cookies,g),w=k?k.defaultLocale===j:j===b.defaultLocale,y=(null===(P=b.domains)||void 0===P?void 0:P.filter((e=>d(j,e))))||[],R=null!=b.domains&&!k;function q(t){const a=new URL(t,l.url);l.nextUrl.basePath&&(a.pathname=p(a.pathname,l.nextUrl.basePath));const n=new Headers(l.headers);return n.set(o,j),e.rewrite(a,{request:{headers:n}})}function H(o,t){const n=new URL(a(o),l.url);if(y.length>0&&!t){const e=v(k,j,y);e&&(t=e.domain,e.defaultLocale===j&&"as-needed"===b.localePrefix.mode&&(n.pathname=f(n.pathname,b.locales,b.localePrefix)))}var r,i;t&&(n.host=t,l.headers.get("x-forwarded-host")&&(n.protocol=null!==(r=l.headers.get("x-forwarded-proto"))&&void 0!==r?r:l.nextUrl.protocol,n.port=null!==(i=l.headers.get("x-forwarded-port"))&&void 0!==i?i:""));return l.nextUrl.basePath&&(n.pathname=p(n.pathname,l.nextUrl.basePath)),e.redirect(n.toString())}const z=f(g,b.locales,b.localePrefix),A=m(g,b.locales,b.localePrefix),C=null!=A,I="never"===b.localePrefix.mode||w&&"as-needed"===b.localePrefix.mode;let S,V,B=z;if("pathnames"in b){let e;if([e,V]=h(b.pathnames,z,j),V){const o=b.pathnames[V],a="string"==typeof o?o:o[j];if(t(a,z))B=u(z,a,V);else{let t;t=e?"string"==typeof o?o:o[e]:V;const r=I?void 0:n(j,b.localePrefix),i=u(z,t,a);S=H(x(i,r,l.nextUrl.search))}}}if(!S)if("/"!==B||C){const e=x(B,U(j),l.nextUrl.search);if(C){const o=x(z,A.prefix,l.nextUrl.search);if("never"===b.localePrefix.mode)S=H(x(z,void 0,l.nextUrl.search));else if(A.exact)if(w&&I)S=H(x(z,void 0,l.nextUrl.search));else if(b.domains){const l=v(k,A.locale,y);S=(null==k?void 0:k.domain)===(null==l?void 0:l.domain)||R?q(e):H(o,null==l?void 0:l.domain)}else S=q(e);else S=H(o)}else S=I?q(e):H(x(z,n(j,b.localePrefix),l.nextUrl.search))}else S=I?q(x(B,U(j),l.nextUrl.search)):H(x(z,n(j,b.localePrefix),l.nextUrl.search));var E;(D.localeDetection&&s(l,S,j),"never"!==b.localePrefix.mode&&D.alternateLinks&&b.locales.length>1)&&S.headers.set("Link",r({routing:b,localizedPathnames:null!=V&&"pathnames"in b?null===(E=b.pathnames)||void 0===E?void 0:E[V]:void 0,request:l,resolvedLocale:j}));return S}}export{P as default};
@@ -1 +1 @@
1
- import{match as e}from"@formatjs/intl-localematcher";import o from"negotiator";import{COOKIE_LOCALE_NAME as l}from"../shared/constants.js";import{getPathnameMatch as t,isLocaleSupportedOnDomain as n,getHost as a}from"./utils.js";function c(l,t,n){let a;const c=new o({headers:{"accept-language":l.get("accept-language")||void 0}}).languages();try{const o=function(e){return e.slice().sort(((e,o)=>o.length-e.length))}(t);a=e(c,o,n)}catch(e){}return a}function i(e,o){if(e.has(l)){var t;const n=null===(t=e.get(l))||void 0===t?void 0:t.value;if(n&&o.includes(n))return n}}function r(e,o,l,n){let a,{defaultLocale:r,localeDetection:u,localePrefix:f,locales:s}=e;var d;n&&(a=null===(d=t(n,s,f))||void 0===d?void 0:d.locale);return!a&&u&&l&&(a=i(l,s)),!a&&u&&o&&(a=c(o,s,r)),a||(a=r),a}function u(e,o,l,u){const f=function(e,o){var l;let t=a(e);if(t=null===(l=t)||void 0===l?void 0:l.replace(/:\d+$/,""),t&&o)return o.find((e=>e.domain===t))}(o,e.domains);if(!f)return{locale:r(e,o,l,u)};let s;if(u){var d;const o=null===(d=t(u,e.locales,e.localePrefix))||void 0===d?void 0:d.locale;if(o){if(!n(o,f))return{locale:o,domain:f};s=o}}if(!s&&e.localeDetection&&l){const o=i(l,e.locales);o&&n(o,f)&&(s=o)}if(!s&&e.localeDetection&&o){const l=c(o,f.locales||e.locales,f.defaultLocale);l&&(s=l)}return s||(s=f.defaultLocale),{locale:s,domain:f}}function f(e,o,l,t){return e.domains?u(e,o,l,t):{locale:r(e,o,l,t)}}export{f as default,c as getAcceptLanguageLocale};
1
+ import{match as e}from"@formatjs/intl-localematcher";import o from"negotiator";import{COOKIE_LOCALE_NAME as l}from"../shared/constants.js";import{getPathnameMatch as t,isLocaleSupportedOnDomain as n,getHost as a}from"./utils.js";function c(l,t,n){let a;const c=new o({headers:{"accept-language":l.get("accept-language")||void 0}}).languages();try{const o=function(e){return e.slice().sort(((e,o)=>o.length-e.length))}(t);a=e(c,o,n)}catch(e){}return a}function i(e,o){if(e.has(l)){var t;const n=null===(t=e.get(l))||void 0===t?void 0:t.value;if(n&&o.includes(n))return n}}function r(e,o,l,n,a){let r,{defaultLocale:u,localePrefix:f,locales:s}=e,{localeDetection:d}=o;var m;a&&(r=null===(m=t(a,s,f))||void 0===m?void 0:m.locale);return!r&&d&&n&&(r=i(n,s)),!r&&d&&l&&(r=c(l,s,u)),r||(r=u),r}function u(e,o,l,u,f){const s=function(e,o){var l;let t=a(e);if(t=null===(l=t)||void 0===l?void 0:l.replace(/:\d+$/,""),t&&o)return o.find((e=>e.domain===t))}(l,e.domains);if(!s)return{locale:r(e,o,l,u,f)};let d;if(f){var m;const o=null===(m=t(f,e.locales,e.localePrefix))||void 0===m?void 0:m.locale;if(o){if(!n(o,s))return{locale:o,domain:s};d=o}}if(!d&&o.localeDetection&&u){const o=i(u,e.locales);o&&n(o,s)&&(d=o)}if(!d&&o.localeDetection&&l){const o=c(l,s.locales||e.locales,s.defaultLocale);o&&(d=o)}return d||(d=s.defaultLocale),{locale:d,domain:s}}function f(e,o,l,t,n){if(e.domains){return u(e,o,l,t,n)}return{locale:r(e,o,l,t,n)}}export{f as default,c as getAcceptLanguageLocale};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o,useMemo as t}from"react";import n from"../../react-client/useLocale.js";import{receiveLocalizedNavigationRoutingConfig as a}from"../shared/config.js";import{getRoute as l,compileLocalizedPathname as c,normalizeNameOrNameWithParams as i}from"../shared/utils.js";import s from"./ClientLink.js";import{clientRedirect as f,clientPermanentRedirect as u}from"./redirects.js";import m from"./useBasePathname.js";import h from"./useBaseRouter.js";function p(p){const d=a(p);function v(){const e=n();if(!d.locales.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `i18n.ts`.'));return e}function P(o,t){let{href:n,locale:a,...l}=o;const i=v(),f=a||i;return r.createElement(s,e({ref:t,href:c({locale:f,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:d.pathnames}),locale:a,localePrefix:d.localePrefix},l))}const x=o(P);function j(e){let{href:r,locale:o}=e;return c({...i(r),locale:o,pathnames:d.pathnames})}return x.displayName="Link",{Link:x,redirect:function(e){const r=j({href:e,locale:v()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return f({pathname:r,localePrefix:d.localePrefix},...t)},permanentRedirect:function(e){const r=j({href:e,locale:v()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return u({pathname:r,localePrefix:d.localePrefix},...t)},usePathname:function(){const e=m(d.localePrefix),r=v();return t((()=>e?l(r,e,d.pathnames):e),[r,e])},useRouter:function(){const e=h(d.localePrefix),r=v();return t((()=>({...e,push(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=j({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.push(c,...a)},replace(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=j({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.replace(c,...a)},prefetch(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=j({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(c,...a)}})),[e,r])},getPathname:j}}export{p as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o,useMemo as t}from"react";import n from"../../react-client/useLocale.js";import{receiveRoutingConfig as a}from"../../routing/config.js";import{getRoute as l,compileLocalizedPathname as c,normalizeNameOrNameWithParams as i}from"../shared/utils.js";import s from"./ClientLink.js";import{clientRedirect as f,clientPermanentRedirect as u}from"./redirects.js";import m from"./useBasePathname.js";import h from"./useBaseRouter.js";function p(p){const d=a(p);function v(){const e=n();if(!d.locales.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `i18n.ts`.'));return e}function P(o,t){let{href:n,locale:a,...l}=o;const i=v(),f=a||i;return r.createElement(s,e({ref:t,href:c({locale:f,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:d.pathnames}),locale:a,localePrefix:d.localePrefix},l))}const x=o(P);function g(e){let{href:r,locale:o}=e;return c({...i(r),locale:o,pathnames:d.pathnames})}return x.displayName="Link",{Link:x,redirect:function(e){const r=g({href:e,locale:v()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return f({pathname:r,localePrefix:d.localePrefix},...t)},permanentRedirect:function(e){const r=g({href:e,locale:v()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return u({pathname:r,localePrefix:d.localePrefix},...t)},usePathname:function(){const e=m(d.localePrefix),r=v();return t((()=>e?l(r,e,d.pathnames):e),[r,e])},useRouter:function(){const e=h(d.localePrefix),r=v();return t((()=>({...e,push(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=g({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.push(c,...a)},replace(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=g({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.replace(c,...a)},prefetch(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=g({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(c,...a)}})),[e,r])},getPathname:g}}export{p as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import{receiveSharedNavigationRoutingConfig as n}from"../shared/config.js";import o from"./ClientLink.js";import{clientRedirect as a,clientPermanentRedirect as i}from"./redirects.js";import l from"./useBasePathname.js";import f from"./useBaseRouter.js";function c(c){const u=n(c);function m(t,n){return r.createElement(o,e({ref:n,localePrefix:u.localePrefix},t))}const s=t(m);return s.displayName="Link",{Link:s,redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return a({pathname:e,localePrefix:u.localePrefix},...t)},permanentRedirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return i({pathname:e,localePrefix:u.localePrefix},...t)},usePathname:function(){return l(u.localePrefix)},useRouter:function(){return f(u.localePrefix)}}}export{c as default};
1
+ import{extends as r}from"../../_virtual/_rollupPluginBabelHelpers.js";import e,{forwardRef as t}from"react";import{receiveLocalePrefixConfig as n}from"../../routing/config.js";import o from"./ClientLink.js";import{clientRedirect as i,clientPermanentRedirect as a}from"./redirects.js";import u from"./useBasePathname.js";import f from"./useBaseRouter.js";function l(l){const m=n(null==l?void 0:l.localePrefix);function s(t,n){return e.createElement(o,r({ref:n,localePrefix:m},t))}const c=t(s);return c.displayName="Link",{Link:c,redirect:function(r){for(var e=arguments.length,t=new Array(e>1?e-1:0),n=1;n<e;n++)t[n-1]=arguments[n];return i({pathname:r,localePrefix:m},...t)},permanentRedirect:function(r){for(var e=arguments.length,t=new Array(e>1?e-1:0),n=1;n<e;n++)t[n-1]=arguments[n];return a({pathname:r,localePrefix:m},...t)},usePathname:function(){return u(m)},useRouter:function(){return f(m)}}}export{l as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{getRequestLocale as t}from"../../server/react-server/RequestLocale.js";import{receiveLocalizedNavigationRoutingConfig as o}from"../shared/config.js";import{compileLocalizedPathname as n,normalizeNameOrNameWithParams as a}from"../shared/utils.js";import l from"./ServerLink.js";import{serverRedirect as c,serverPermanentRedirect as s}from"./redirects.js";function i(i){const m=o(i);function f(e){let{href:r,locale:t}=e;return n({...a(r),locale:t,pathnames:m.pathnames})}function u(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(o){let{href:a,locale:c,...s}=o;const i=t(),f=c||i;return r.createElement(l,e({href:n({locale:f,pathname:a,params:"object"==typeof a?a.params:void 0,pathnames:m.pathnames}),locale:c,localePrefix:m.localePrefix},s))},redirect:function(e){const r=f({href:e,locale:t()});for(var o=arguments.length,n=new Array(o>1?o-1:0),a=1;a<o;a++)n[a-1]=arguments[a];return c({localePrefix:m.localePrefix,pathname:r},...n)},permanentRedirect:function(e){const r=f({href:e,locale:t()});for(var o=arguments.length,n=new Array(o>1?o-1:0),a=1;a<o;a++)n[a-1]=arguments[a];return s({localePrefix:m.localePrefix,pathname:r},...n)},getPathname:f,usePathname:u("usePathname"),useRouter:u("useRouter")}}export{i as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{receiveRoutingConfig as t}from"../../routing/config.js";import{getRequestLocale as o}from"../../server/react-server/RequestLocale.js";import{compileLocalizedPathname as n,normalizeNameOrNameWithParams as a}from"../shared/utils.js";import l from"./ServerLink.js";import{serverRedirect as c,serverPermanentRedirect as i}from"./redirects.js";function s(s){const m=t(s);function f(e){let{href:r,locale:t}=e;return n({...a(r),locale:t,pathnames:m.pathnames})}function u(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(t){let{href:a,locale:c,...i}=t;const s=o(),f=c||s;return r.createElement(l,e({href:n({locale:f,pathname:a,params:"object"==typeof a?a.params:void 0,pathnames:m.pathnames}),locale:c,localePrefix:m.localePrefix},i))},redirect:function(e){const r=f({href:e,locale:o()});for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return c({localePrefix:m.localePrefix,pathname:r},...n)},permanentRedirect:function(e){const r=f({href:e,locale:o()});for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return i({localePrefix:m.localePrefix,pathname:r},...n)},getPathname:f,usePathname:u("usePathname"),useRouter:u("useRouter")}}export{s as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{receiveSharedNavigationRoutingConfig as t}from"../shared/config.js";import o from"./ServerLink.js";import{serverRedirect as n,serverPermanentRedirect as a}from"./redirects.js";function i(i){const u=t(i);function c(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(t){return r.createElement(o,e({localePrefix:u.localePrefix},t))},redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),o=1;o<r;o++)t[o-1]=arguments[o];return n({pathname:e,localePrefix:u.localePrefix},...t)},permanentRedirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),o=1;o<r;o++)t[o-1]=arguments[o];return a({pathname:e,localePrefix:u.localePrefix},...t)},usePathname:c("usePathname"),useRouter:c("useRouter")}}export{i as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{receiveLocalePrefixConfig as t}from"../../routing/config.js";import n from"./ServerLink.js";import{serverRedirect as o,serverPermanentRedirect as i}from"./redirects.js";function a(a){const u=t(null==a?void 0:a.localePrefix);function c(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(t){return r.createElement(n,e({localePrefix:u},t))},redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return o({pathname:e,localePrefix:u},...t)},permanentRedirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return i({pathname:e,localePrefix:u},...t)},usePathname:c("usePathname"),useRouter:c("useRouter")}}export{a as default};
@@ -1 +1 @@
1
- function e(e){return"object"==typeof e?e:{mode:e||"always"}}export{e as receiveLocalePrefixConfig};
1
+ function e(e){return{...e,localePrefix:o(e.localePrefix)}}function o(e){return"object"==typeof e?e:{mode:e||"always"}}export{o as receiveLocalePrefixConfig,e as receiveRoutingConfig};
@@ -0,0 +1 @@
1
+ function t(t){return t}export{t as default};
@@ -1 +1 @@
1
-
1
+ export{default as defineRouting}from"./routing/defineRouting.js";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js"),a=require("./utils.js");exports.default=function(t){var o;let{config:n,localizedPathnames:l,request:r,resolvedLocale:s}=t;const i=r.nextUrl.clone(),c=a.getHost(r.headers);function p(t,o){return t.pathname=e.normalizeTrailingSlash(t.pathname),r.nextUrl.basePath&&((t=new URL(t)).pathname=a.applyBasePath(t.pathname,r.nextUrl.basePath)),"<".concat(t.toString(),'>; rel="alternate"; hreflang="').concat(o,'"')}function m(e,t){return l&&"object"==typeof l?a.formatTemplatePathname(e,l[s],l[t]):e}c&&(i.port="",i.host=c),i.protocol=null!==(o=r.headers.get("x-forwarded-proto"))&&void 0!==o?o:i.protocol,i.pathname=a.getNormalizedPathname(i.pathname,n.locales,n.localePrefix);const h=a.getLocalePrefixes(n.locales,n.localePrefix).flatMap((e=>{let t,[o,r]=e;function s(e){return"/"===e?r:r+e}if(n.domains){return(n.domains.filter((e=>a.isLocaleSupportedOnDomain(o,e)))||[]).map((e=>(t=new URL(i),t.port="",t.host=e.domain,t.pathname=m(i.pathname,o),o===e.defaultLocale&&"always"!==n.localePrefix.mode||(t.pathname=s(t.pathname)),p(t,o))))}{let e;e=l&&"object"==typeof l?m(i.pathname,o):i.pathname,o===n.defaultLocale&&"always"!==n.localePrefix.mode||(e=s(e)),t=new URL(e,i)}return p(t,o)}));if(!n.domains&&("always"!==n.localePrefix.mode||"/"===i.pathname)){const e=new URL(m(i.pathname,n.defaultLocale),i);h.push(p(e,"x-default"))}return h.join(", ")};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js"),a=require("./utils.js");exports.default=function(t){var o;let{localizedPathnames:n,request:l,resolvedLocale:r,routing:s}=t;const i=l.nextUrl.clone(),c=a.getHost(l.headers);function p(t,o){return t.pathname=e.normalizeTrailingSlash(t.pathname),l.nextUrl.basePath&&((t=new URL(t)).pathname=a.applyBasePath(t.pathname,l.nextUrl.basePath)),"<".concat(t.toString(),'>; rel="alternate"; hreflang="').concat(o,'"')}function m(e,t){return n&&"object"==typeof n?a.formatTemplatePathname(e,n[r],n[t]):e}c&&(i.port="",i.host=c),i.protocol=null!==(o=l.headers.get("x-forwarded-proto"))&&void 0!==o?o:i.protocol,i.pathname=a.getNormalizedPathname(i.pathname,s.locales,s.localePrefix);const h=a.getLocalePrefixes(s.locales,s.localePrefix).flatMap((e=>{let t,[o,l]=e;function r(e){return"/"===e?l:l+e}if(s.domains){return(s.domains.filter((e=>a.isLocaleSupportedOnDomain(o,e)))||[]).map((e=>(t=new URL(i),t.port="",t.host=e.domain,t.pathname=m(i.pathname,o),o===e.defaultLocale&&"always"!==s.localePrefix.mode||(t.pathname=r(t.pathname)),p(t,o))))}{let e;e=n&&"object"==typeof n?m(i.pathname,o):i.pathname,o===s.defaultLocale&&"always"!==s.localePrefix.mode||(e=r(e)),t=new URL(e,i)}return p(t,o)}));if(!s.domains&&("always"!==s.localePrefix.mode||"/"===i.pathname)){const e=new URL(m(i.pathname,s.defaultLocale),i);h.push(p(e,"x-default"))}return h.join(", ")};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),a=require("../shared/constants.js"),t=require("../shared/utils.js"),r=require("./config.js"),l=require("./getAlternateLinksHeaderValue.js"),o=require("./resolveLocale.js"),n=require("./syncCookie.js"),s=require("./utils.js");exports.default=function(i){const c=r.receiveConfig(i);return function(r){var i;const d=decodeURI(r.nextUrl.pathname),m=s.sanitizePathname(d),{domain:f,locale:h}=o.default(c,r.headers,r.cookies,m),u=f?f.defaultLocale===h:h===c.defaultLocale,x=(null===(i=c.domains)||void 0===i?void 0:i.filter((e=>s.isLocaleSupportedOnDomain(h,e))))||[],P=null!=c.domains&&!f;function p(t){const l=new URL(t,r.url);r.nextUrl.basePath&&(l.pathname=s.applyBasePath(l.pathname,r.nextUrl.basePath));const o=new Headers(r.headers);return o.set(a.HEADER_LOCALE_NAME,h),e.NextResponse.rewrite(l,{request:{headers:o}})}function g(a,l){const o=new URL(t.normalizeTrailingSlash(a),r.url);if(x.length>0&&!l){const e=s.getBestMatchingDomain(f,h,x);e&&(l=e.domain,e.defaultLocale===h&&"as-needed"===c.localePrefix.mode&&(o.pathname=s.getNormalizedPathname(o.pathname,c.locales,c.localePrefix)))}var n,i;l&&(o.host=l,r.headers.get("x-forwarded-host")&&(o.protocol=null!==(n=r.headers.get("x-forwarded-proto"))&&void 0!==n?n:r.nextUrl.protocol,o.port=null!==(i=r.headers.get("x-forwarded-port"))&&void 0!==i?i:""));return r.nextUrl.basePath&&(o.pathname=s.applyBasePath(o.pathname,r.nextUrl.basePath)),e.NextResponse.redirect(o.toString())}const v=s.getNormalizedPathname(m,c.locales,c.localePrefix),L=s.getPathnameMatch(m,c.locales,c.localePrefix),U=null!=L,q="never"===c.localePrefix.mode||u&&"as-needed"===c.localePrefix.mode;let j,w,y=v;if(c.pathnames){let e;if([e,w]=s.getInternalTemplate(c.pathnames,v,h),w){const a=c.pathnames[w],l="string"==typeof a?a:a[h];if(t.matchesPathname(l,v))y=s.formatTemplatePathname(v,l,w);else{let o;o=e?"string"==typeof a?a:a[e]:w;const n=q?void 0:t.getLocalePrefix(h,c.localePrefix),i=s.formatTemplatePathname(v,o,l);j=g(s.formatPathname(i,n,r.nextUrl.search))}}}if(!j)if("/"!==y||U){const e=s.formatPathname(y,s.getLocaleAsPrefix(h),r.nextUrl.search);if(U){const a=s.formatPathname(v,L.prefix,r.nextUrl.search);if("never"===c.localePrefix.mode)j=g(s.formatPathname(v,void 0,r.nextUrl.search));else if(L.exact)if(u&&q)j=g(s.formatPathname(v,void 0,r.nextUrl.search));else if(c.domains){const t=s.getBestMatchingDomain(f,L.locale,x);j=(null==f?void 0:f.domain)===(null==t?void 0:t.domain)||P?p(e):g(a,null==t?void 0:t.domain)}else j=p(e);else j=g(a)}else j=q?p(e):g(s.formatPathname(v,t.getLocalePrefix(h,c.localePrefix),r.nextUrl.search))}else j=q?p(s.formatPathname(y,s.getLocaleAsPrefix(h),r.nextUrl.search)):g(s.formatPathname(v,t.getLocalePrefix(h,c.localePrefix),r.nextUrl.search));var A;(c.localeDetection&&n.default(r,j,h),"never"!==c.localePrefix.mode&&c.alternateLinks&&c.locales.length>1)&&j.headers.set("Link",l.default({config:c,localizedPathnames:null!=w?null===(A=c.pathnames)||void 0===A?void 0:A[w]:void 0,request:r,resolvedLocale:h}));return j}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),a=require("../routing/config.js"),t=require("../shared/constants.js"),l=require("../shared/utils.js"),n=require("./getAlternateLinksHeaderValue.js"),o=require("./resolveLocale.js"),r=require("./syncCookie.js"),i=require("./utils.js");exports.default=function(s,c){var d,m,h,f;const u=a.receiveRoutingConfig(s),x={alternateLinks:null===(d=null!==(m=null==c?void 0:c.alternateLinks)&&void 0!==m?m:s.alternateLinks)||void 0===d||d,localeDetection:null===(h=null!==(f=null==c?void 0:c.localeDetection)&&void 0!==f?f:null==s?void 0:s.localeDetection)||void 0===h||h};return function(a){var s;const c=decodeURI(a.nextUrl.pathname),d=i.sanitizePathname(c),{domain:m,locale:h}=o.default(u,x,a.headers,a.cookies,d),f=m?m.defaultLocale===h:h===u.defaultLocale,P=(null===(s=u.domains)||void 0===s?void 0:s.filter((e=>i.isLocaleSupportedOnDomain(h,e))))||[],p=null!=u.domains&&!m;function v(l){const n=new URL(l,a.url);a.nextUrl.basePath&&(n.pathname=i.applyBasePath(n.pathname,a.nextUrl.basePath));const o=new Headers(a.headers);return o.set(t.HEADER_LOCALE_NAME,h),e.NextResponse.rewrite(n,{request:{headers:o}})}function g(t,n){const o=new URL(l.normalizeTrailingSlash(t),a.url);if(P.length>0&&!n){const e=i.getBestMatchingDomain(m,h,P);e&&(n=e.domain,e.defaultLocale===h&&"as-needed"===u.localePrefix.mode&&(o.pathname=i.getNormalizedPathname(o.pathname,u.locales,u.localePrefix)))}var r,s;n&&(o.host=n,a.headers.get("x-forwarded-host")&&(o.protocol=null!==(r=a.headers.get("x-forwarded-proto"))&&void 0!==r?r:a.nextUrl.protocol,o.port=null!==(s=a.headers.get("x-forwarded-port"))&&void 0!==s?s:""));return a.nextUrl.basePath&&(o.pathname=i.applyBasePath(o.pathname,a.nextUrl.basePath)),e.NextResponse.redirect(o.toString())}const L=i.getNormalizedPathname(d,u.locales,u.localePrefix),U=i.getPathnameMatch(d,u.locales,u.localePrefix),q=null!=U,j="never"===u.localePrefix.mode||f&&"as-needed"===u.localePrefix.mode;let k,D,w=L;if("pathnames"in u){let e;if([e,D]=i.getInternalTemplate(u.pathnames,L,h),D){const t=u.pathnames[D],n="string"==typeof t?t:t[h];if(l.matchesPathname(n,L))w=i.formatTemplatePathname(L,n,D);else{let o;o=e?"string"==typeof t?t:t[e]:D;const r=j?void 0:l.getLocalePrefix(h,u.localePrefix),s=i.formatTemplatePathname(L,o,n);k=g(i.formatPathname(s,r,a.nextUrl.search))}}}if(!k)if("/"!==w||q){const e=i.formatPathname(w,i.getLocaleAsPrefix(h),a.nextUrl.search);if(q){const t=i.formatPathname(L,U.prefix,a.nextUrl.search);if("never"===u.localePrefix.mode)k=g(i.formatPathname(L,void 0,a.nextUrl.search));else if(U.exact)if(f&&j)k=g(i.formatPathname(L,void 0,a.nextUrl.search));else if(u.domains){const a=i.getBestMatchingDomain(m,U.locale,P);k=(null==m?void 0:m.domain)===(null==a?void 0:a.domain)||p?v(e):g(t,null==a?void 0:a.domain)}else k=v(e);else k=g(t)}else k=j?v(e):g(i.formatPathname(L,l.getLocalePrefix(h,u.localePrefix),a.nextUrl.search))}else k=j?v(i.formatPathname(w,i.getLocaleAsPrefix(h),a.nextUrl.search)):g(i.formatPathname(L,l.getLocalePrefix(h,u.localePrefix),a.nextUrl.search));var R;(x.localeDetection&&r.default(a,k,h),"never"!==u.localePrefix.mode&&x.alternateLinks&&u.locales.length>1)&&k.headers.set("Link",n.default({routing:u,localizedPathnames:null!=D&&"pathnames"in u?null===(R=u.pathnames)||void 0===R?void 0:R[D]:void 0,request:a,resolvedLocale:h}));return k}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@formatjs/intl-localematcher"),t=require("negotiator"),l=require("../shared/constants.js"),o=require("./utils.js");function a(e){return e&&e.__esModule?e:{default:e}}var n=a(t);function c(t,l,o){let a;const c=new n.default({headers:{"accept-language":t.get("accept-language")||void 0}}).languages();try{const t=function(e){return e.slice().sort(((e,t)=>t.length-e.length))}(l);a=e.match(c,t,o)}catch(e){}return a}function i(e,t){if(e.has(l.COOKIE_LOCALE_NAME)){var o;const a=null===(o=e.get(l.COOKIE_LOCALE_NAME))||void 0===o?void 0:o.value;if(a&&t.includes(a))return a}}function r(e,t,l,a){let n,{defaultLocale:r,localeDetection:u,localePrefix:s,locales:d}=e;var f;a&&(n=null===(f=o.getPathnameMatch(a,d,s))||void 0===f?void 0:f.locale);return!n&&u&&l&&(n=i(l,d)),!n&&u&&t&&(n=c(t,d,r)),n||(n=r),n}function u(e,t,l,a){const n=function(e,t){var l;let a=o.getHost(e);if(a=null===(l=a)||void 0===l?void 0:l.replace(/:\d+$/,""),a&&t)return t.find((e=>e.domain===a))}(t,e.domains);if(!n)return{locale:r(e,t,l,a)};let u;if(a){var s;const t=null===(s=o.getPathnameMatch(a,e.locales,e.localePrefix))||void 0===s?void 0:s.locale;if(t){if(!o.isLocaleSupportedOnDomain(t,n))return{locale:t,domain:n};u=t}}if(!u&&e.localeDetection&&l){const t=i(l,e.locales);t&&o.isLocaleSupportedOnDomain(t,n)&&(u=t)}if(!u&&e.localeDetection&&t){const l=c(t,n.locales||e.locales,n.defaultLocale);l&&(u=l)}return u||(u=n.defaultLocale),{locale:u,domain:n}}exports.default=function(e,t,l,o){return e.domains?u(e,t,l,o):{locale:r(e,t,l,o)}},exports.getAcceptLanguageLocale=c;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@formatjs/intl-localematcher"),t=require("negotiator"),l=require("../shared/constants.js"),o=require("./utils.js");function a(e){return e&&e.__esModule?e:{default:e}}var n=a(t);function c(t,l,o){let a;const c=new n.default({headers:{"accept-language":t.get("accept-language")||void 0}}).languages();try{const t=function(e){return e.slice().sort(((e,t)=>t.length-e.length))}(l);a=e.match(c,t,o)}catch(e){}return a}function r(e,t){if(e.has(l.COOKIE_LOCALE_NAME)){var o;const a=null===(o=e.get(l.COOKIE_LOCALE_NAME))||void 0===o?void 0:o.value;if(a&&t.includes(a))return a}}function i(e,t,l,a,n){let i,{defaultLocale:u,localePrefix:s,locales:d}=e,{localeDetection:f}=t;var g;n&&(i=null===(g=o.getPathnameMatch(n,d,s))||void 0===g?void 0:g.locale);return!i&&f&&a&&(i=r(a,d)),!i&&f&&l&&(i=c(l,d,u)),i||(i=u),i}function u(e,t,l,a,n){const u=function(e,t){var l;let a=o.getHost(e);if(a=null===(l=a)||void 0===l?void 0:l.replace(/:\d+$/,""),a&&t)return t.find((e=>e.domain===a))}(l,e.domains);if(!u)return{locale:i(e,t,l,a,n)};let s;if(n){var d;const t=null===(d=o.getPathnameMatch(n,e.locales,e.localePrefix))||void 0===d?void 0:d.locale;if(t){if(!o.isLocaleSupportedOnDomain(t,u))return{locale:t,domain:u};s=t}}if(!s&&t.localeDetection&&a){const t=r(a,e.locales);t&&o.isLocaleSupportedOnDomain(t,u)&&(s=t)}if(!s&&t.localeDetection&&l){const t=c(l,u.locales||e.locales,u.defaultLocale);t&&(s=t)}return s||(s=u.defaultLocale),{locale:s,domain:u}}exports.default=function(e,t,l,o,a){if(e.domains){return u(e,t,l,o,a)}return{locale:i(e,t,l,o,a)}},exports.getAcceptLanguageLocale=c;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),a=require("../../react-client/useLocale.js"),t=require("../shared/config.js"),l=require("../shared/utils.js"),n=require("./ClientLink.js"),o=require("./redirects.js"),c=require("./useBasePathname.js"),i=require("./useBaseRouter.js");function u(e){return e&&e.__esModule?e:{default:e}}var s=u(r);exports.default=function(u){const f=t.receiveLocalizedNavigationRoutingConfig(u);function h(){const e=a.default();if(!f.locales.includes(e))throw new Error(void 0);return e}function d(r,a){let{href:t,locale:o,...c}=r;const i=h(),u=o||i;return s.default.createElement(n.default,e.extends({ref:a,href:l.compileLocalizedPathname({locale:u,pathname:t,params:"object"==typeof t?t.params:void 0,pathnames:f.pathnames}),locale:o,localePrefix:f.localePrefix},c))}const m=r.forwardRef(d);function p(e){let{href:r,locale:a}=e;return l.compileLocalizedPathname({...l.normalizeNameOrNameWithParams(r),locale:a,pathnames:f.pathnames})}return m.displayName="Link",{Link:m,redirect:function(e){const r=p({href:e,locale:h()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientRedirect({pathname:r,localePrefix:f.localePrefix},...t)},permanentRedirect:function(e){const r=p({href:e,locale:h()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientPermanentRedirect({pathname:r,localePrefix:f.localePrefix},...t)},usePathname:function(){const e=c.default(f.localePrefix),a=h();return r.useMemo((()=>e?l.getRoute(a,e,f.pathnames):e),[a,e])},useRouter:function(){const e=i.default(f.localePrefix),a=h();return r.useMemo((()=>({...e,push(r){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=p({href:r,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||a});return e.push(c,...n)},replace(r){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=p({href:r,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||a});return e.replace(c,...n)},prefetch(r){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=p({href:r,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||a});return e.prefetch(c,...n)}})),[e,a])},getPathname:p}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../react-client/useLocale.js"),a=require("../../routing/config.js"),l=require("../shared/utils.js"),n=require("./ClientLink.js"),o=require("./redirects.js"),c=require("./useBasePathname.js"),i=require("./useBaseRouter.js");function u(e){return e&&e.__esModule?e:{default:e}}var s=u(r);exports.default=function(u){const f=a.receiveRoutingConfig(u);function h(){const e=t.default();if(!f.locales.includes(e))throw new Error(void 0);return e}function d(r,t){let{href:a,locale:o,...c}=r;const i=h(),u=o||i;return s.default.createElement(n.default,e.extends({ref:t,href:l.compileLocalizedPathname({locale:u,pathname:a,params:"object"==typeof a?a.params:void 0,pathnames:f.pathnames}),locale:o,localePrefix:f.localePrefix},c))}const m=r.forwardRef(d);function p(e){let{href:r,locale:t}=e;return l.compileLocalizedPathname({...l.normalizeNameOrNameWithParams(r),locale:t,pathnames:f.pathnames})}return m.displayName="Link",{Link:m,redirect:function(e){const r=p({href:e,locale:h()});for(var t=arguments.length,a=new Array(t>1?t-1:0),l=1;l<t;l++)a[l-1]=arguments[l];return o.clientRedirect({pathname:r,localePrefix:f.localePrefix},...a)},permanentRedirect:function(e){const r=p({href:e,locale:h()});for(var t=arguments.length,a=new Array(t>1?t-1:0),l=1;l<t;l++)a[l-1]=arguments[l];return o.clientPermanentRedirect({pathname:r,localePrefix:f.localePrefix},...a)},usePathname:function(){const e=c.default(f.localePrefix),t=h();return r.useMemo((()=>e?l.getRoute(t,e,f.pathnames):e),[t,e])},useRouter:function(){const e=i.default(f.localePrefix),t=h();return r.useMemo((()=>({...e,push(r){for(var a,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=p({href:r,locale:(null===(a=n[0])||void 0===a?void 0:a.locale)||t});return e.push(c,...n)},replace(r){for(var a,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=p({href:r,locale:(null===(a=n[0])||void 0===a?void 0:a.locale)||t});return e.replace(c,...n)},prefetch(r){for(var a,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=p({href:r,locale:(null===(a=n[0])||void 0===a?void 0:a.locale)||t});return e.prefetch(c,...n)}})),[e,t])},getPathname:p}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../shared/config.js"),n=require("./ClientLink.js"),a=require("./redirects.js"),i=require("./useBasePathname.js"),u=require("./useBaseRouter.js");function l(e){return e&&e.__esModule?e:{default:e}}var o=l(r);exports.default=function(l){const c=t.receiveSharedNavigationRoutingConfig(l);function f(r,t){return o.default.createElement(n.default,e.extends({ref:t,localePrefix:c.localePrefix},r))}const s=r.forwardRef(f);return s.displayName="Link",{Link:s,redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return a.clientRedirect({pathname:e,localePrefix:c.localePrefix},...t)},permanentRedirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return a.clientPermanentRedirect({pathname:e,localePrefix:c.localePrefix},...t)},usePathname:function(){return i.default(c.localePrefix)},useRouter:function(){return u.default(c.localePrefix)}}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../routing/config.js"),n=require("./ClientLink.js"),u=require("./redirects.js"),i=require("./useBasePathname.js"),a=require("./useBaseRouter.js");function l(e){return e&&e.__esModule?e:{default:e}}var o=l(r);exports.default=function(l){const c=t.receiveLocalePrefixConfig(null==l?void 0:l.localePrefix);function f(r,t){return o.default.createElement(n.default,e.extends({ref:t,localePrefix:c},r))}const s=r.forwardRef(f);return s.displayName="Link",{Link:s,redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return u.clientRedirect({pathname:e,localePrefix:c},...t)},permanentRedirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return u.clientPermanentRedirect({pathname:e,localePrefix:c},...t)},usePathname:function(){return i.default(c)},useRouter:function(){return a.default(c)}}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../server/react-server/RequestLocale.js"),a=require("../shared/config.js"),n=require("../shared/utils.js"),o=require("./ServerLink.js"),l=require("./redirects.js");function c(e){return e&&e.__esModule?e:{default:e}}var i=c(r);exports.default=function(r){const c=a.receiveLocalizedNavigationRoutingConfig(r);function u(e){let{href:r,locale:t}=e;return n.compileLocalizedPathname({...n.normalizeNameOrNameWithParams(r),locale:t,pathnames:c.pathnames})}function s(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(r){let{href:a,locale:l,...u}=r;const s=t.getRequestLocale(),f=l||s;return i.default.createElement(o.default,e.extends({href:n.compileLocalizedPathname({locale:f,pathname:a,params:"object"==typeof a?a.params:void 0,pathnames:c.pathnames}),locale:l,localePrefix:c.localePrefix},u))},redirect:function(e){const r=u({href:e,locale:t.getRequestLocale()});for(var a=arguments.length,n=new Array(a>1?a-1:0),o=1;o<a;o++)n[o-1]=arguments[o];return l.serverRedirect({localePrefix:c.localePrefix,pathname:r},...n)},permanentRedirect:function(e){const r=u({href:e,locale:t.getRequestLocale()});for(var a=arguments.length,n=new Array(a>1?a-1:0),o=1;o<a;o++)n[o-1]=arguments[o];return l.serverPermanentRedirect({localePrefix:c.localePrefix,pathname:r},...n)},getPathname:u,usePathname:s("usePathname"),useRouter:s("useRouter")}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../routing/config.js"),a=require("../../server/react-server/RequestLocale.js"),n=require("../shared/utils.js"),o=require("./ServerLink.js"),l=require("./redirects.js");function c(e){return e&&e.__esModule?e:{default:e}}var i=c(r);exports.default=function(r){const c=t.receiveRoutingConfig(r);function u(e){let{href:r,locale:t}=e;return n.compileLocalizedPathname({...n.normalizeNameOrNameWithParams(r),locale:t,pathnames:c.pathnames})}function s(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(r){let{href:t,locale:l,...u}=r;const s=a.getRequestLocale(),f=l||s;return i.default.createElement(o.default,e.extends({href:n.compileLocalizedPathname({locale:f,pathname:t,params:"object"==typeof t?t.params:void 0,pathnames:c.pathnames}),locale:l,localePrefix:c.localePrefix},u))},redirect:function(e){const r=u({href:e,locale:a.getRequestLocale()});for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return l.serverRedirect({localePrefix:c.localePrefix,pathname:r},...n)},permanentRedirect:function(e){const r=u({href:e,locale:a.getRequestLocale()});for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return l.serverPermanentRedirect({localePrefix:c.localePrefix,pathname:r},...n)},getPathname:u,usePathname:s("usePathname"),useRouter:s("useRouter")}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../shared/config.js"),n=require("./ServerLink.js"),o=require("./redirects.js");function i(e){return e&&e.__esModule?e:{default:e}}var u=i(r);exports.default=function(r){const i=t.receiveSharedNavigationRoutingConfig(r);function a(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(r){return u.default.createElement(n.default,e.extends({localePrefix:i.localePrefix},r))},redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return o.serverRedirect({pathname:e,localePrefix:i.localePrefix},...t)},permanentRedirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return o.serverPermanentRedirect({pathname:e,localePrefix:i.localePrefix},...t)},usePathname:a("usePathname"),useRouter:a("useRouter")}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../routing/config.js"),n=require("./ServerLink.js"),o=require("./redirects.js");function u(e){return e&&e.__esModule?e:{default:e}}var i=u(r);exports.default=function(r){const u=t.receiveLocalePrefixConfig(null==r?void 0:r.localePrefix);function a(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(r){return i.default.createElement(n.default,e.extends({localePrefix:u},r))},redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return o.serverRedirect({pathname:e,localePrefix:u},...t)},permanentRedirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return o.serverPermanentRedirect({pathname:e,localePrefix:u},...t)},usePathname:a("usePathname"),useRouter:a("useRouter")}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.receiveLocalePrefixConfig=function(e){return"object"==typeof e?e:{mode:e||"always"}};
1
+ "use strict";function e(e){return"object"==typeof e?e:{mode:e||"always"}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.receiveLocalePrefixConfig=e,exports.receiveRoutingConfig=function(o){return{...o,localePrefix:e(o.localePrefix)}};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(e){return e};
@@ -1 +1 @@
1
- "use strict";
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./routing/defineRouting.js");exports.defineRouting=e.default;
@@ -1,18 +1,7 @@
1
- import { RoutingBaseConfigInput } from '../routing/config';
2
- import { Locales, LocalePrefixConfigVerbose, Pathnames } from '../routing/types';
3
- export type MiddlewareRoutingConfigInput<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>> = RoutingBaseConfigInput<AppLocales> & {
4
- locales: AppLocales;
5
- defaultLocale: AppLocales[number];
1
+ export type MiddlewareOptions = {
6
2
  /** Sets the `Link` response header to notify search engines about content in other languages (defaults to `true`). See https://developers.google.com/search/docs/specialty/international/localized-versions#http */
7
3
  alternateLinks?: boolean;
8
4
  /** By setting this to `false`, the cookie as well as the `accept-language` header will no longer be used for locale detection. */
9
5
  localeDetection?: boolean;
10
- /** Maps internal pathnames to external ones which can be localized per locale. */
11
- pathnames?: AppPathnames;
12
6
  };
13
- export type MiddlewareRoutingConfig<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>> = Omit<MiddlewareRoutingConfigInput<AppLocales, AppPathnames>, 'alternateLinks' | 'localeDetection' | 'localePrefix'> & {
14
- alternateLinks: boolean;
15
- localeDetection: boolean;
16
- localePrefix: LocalePrefixConfigVerbose<AppLocales>;
17
- };
18
- export declare function receiveConfig<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(input: MiddlewareRoutingConfigInput<AppLocales, AppPathnames>): MiddlewareRoutingConfig<AppLocales, AppPathnames>;
7
+ export type ResolvedMiddlewareOptions = Required<MiddlewareOptions>;
@@ -1,11 +1,11 @@
1
1
  import { NextRequest } from 'next/server';
2
+ import { ResolvedRoutingConfig } from '../routing/config';
2
3
  import { Locales, Pathnames } from '../routing/types';
3
- import { MiddlewareRoutingConfig } from './config';
4
4
  /**
5
5
  * See https://developers.google.com/search/docs/specialty/international/localized-versions
6
6
  */
7
- export default function getAlternateLinksHeaderValue<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>({ config, localizedPathnames, request, resolvedLocale }: {
8
- config: MiddlewareRoutingConfig<AppLocales, AppPathnames>;
7
+ export default function getAlternateLinksHeaderValue<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales> = never>({ localizedPathnames, request, resolvedLocale, routing }: {
8
+ routing: ResolvedRoutingConfig<AppLocales, AppPathnames>;
9
9
  request: NextRequest;
10
10
  resolvedLocale: AppLocales[number];
11
11
  localizedPathnames?: Pathnames<AppLocales>[string];
@@ -1,4 +1,5 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
+ import { RoutingConfig } from '../routing/config';
2
3
  import { Locales, Pathnames } from '../routing/types';
3
- import { MiddlewareRoutingConfigInput } from './config';
4
- export default function createMiddleware<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(input: MiddlewareRoutingConfigInput<AppLocales, AppPathnames>): (request: NextRequest) => NextResponse<unknown>;
4
+ import { MiddlewareOptions } from './config';
5
+ export default function createMiddleware<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales> = never>(routing: RoutingConfig<AppLocales, AppPathnames> & MiddlewareOptions, options?: MiddlewareOptions): (request: NextRequest) => NextResponse<unknown>;
@@ -1,8 +1,9 @@
1
1
  import { RequestCookies } from 'next/dist/server/web/spec-extension/cookies';
2
+ import { ResolvedRoutingConfig } from '../routing/config';
2
3
  import { Locales, Pathnames, DomainConfig } from '../routing/types';
3
- import { MiddlewareRoutingConfig } from './config';
4
+ import { ResolvedMiddlewareOptions } from './config';
4
5
  export declare function getAcceptLanguageLocale<AppLocales extends Locales>(requestHeaders: Headers, locales: AppLocales, defaultLocale: string): string | undefined;
5
- export default function resolveLocale<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(config: MiddlewareRoutingConfig<AppLocales, AppPathnames>, requestHeaders: Headers, requestCookies: RequestCookies, pathname: string): {
6
+ export default function resolveLocale<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales> = never>(routing: ResolvedRoutingConfig<AppLocales, AppPathnames>, options: ResolvedMiddlewareOptions, requestHeaders: Headers, requestCookies: RequestCookies, pathname: string): {
6
7
  locale: AppLocales[number];
7
8
  domain?: DomainConfig<AppLocales>;
8
9
  };
@@ -1,9 +1,9 @@
1
1
  import React, { ComponentProps, ReactElement } from 'react';
2
+ import { RoutingConfigLocalizedNavigation } from '../../routing/config';
2
3
  import { Locales, Pathnames } from '../../routing/types';
3
- import { LocalizedNavigationRoutingConfigInput } from '../shared/config';
4
4
  import { HrefOrHrefWithParams } from '../shared/utils';
5
5
  import ClientLink from './ClientLink';
6
- export default function createLocalizedPathnamesNavigation<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(input: LocalizedNavigationRoutingConfigInput<AppLocales, AppPathnames>): {
6
+ export default function createLocalizedPathnamesNavigation<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(routing: RoutingConfigLocalizedNavigation<AppLocales, AppPathnames>): {
7
7
  Link: <Pathname extends keyof AppPathnames>(props: (Omit<Omit<Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
8
8
  href: string | import("url").UrlObject;
9
9
  as?: string | import("url").UrlObject;
@@ -41,7 +41,7 @@ export default function createLocalizedPathnamesNavigation<AppLocales extends Lo
41
41
  localePrefix: import("../../routing/types").LocalePrefixConfigVerbose<Locales>;
42
42
  } & {
43
43
  ref?: React.LegacyRef<HTMLAnchorElement> | undefined;
44
- }, "href" | "localePrefix" | "name"> & {
44
+ }, "localePrefix" | "href" | "name"> & {
45
45
  href: Pathname extends `${string}[[...${string}` ? Pathname | ({
46
46
  pathname: Pathname;
47
47
  params?: import("../shared/StrictParams").default<Pathname> | undefined;
@@ -60,13 +60,13 @@ export default function createLocalizedPathnamesNavigation<AppLocales extends Lo
60
60
  usePathname: () => keyof AppPathnames;
61
61
  useRouter: () => {
62
62
  push<Pathname extends keyof AppPathnames>(href: HrefOrHrefWithParams<Pathname>, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").NavigateOptions & {
63
- locale?: AppLocales[number] | undefined;
63
+ locale?: string | undefined;
64
64
  }) | undefined): void;
65
65
  replace<Pathname extends keyof AppPathnames>(href: HrefOrHrefWithParams<Pathname>, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").NavigateOptions & {
66
- locale?: AppLocales[number] | undefined;
66
+ locale?: string | undefined;
67
67
  }) | undefined): void;
68
68
  prefetch<Pathname extends keyof AppPathnames>(href: HrefOrHrefWithParams<Pathname>, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").PrefetchOptions & {
69
- locale?: AppLocales[number] | undefined;
69
+ locale?: string | undefined;
70
70
  }) | undefined): void;
71
71
  back(): void;
72
72
  forward(): void;
@@ -1,7 +1,7 @@
1
1
  import React, { ReactElement } from 'react';
2
+ import { RoutingConfigSharedNavigation } from '../../routing/config';
2
3
  import { Locales } from '../../routing/types';
3
- import { SharedNavigationRoutingConfigInput } from '../shared/config';
4
- export default function createSharedPathnamesNavigation<const AppLocales extends Locales>(input?: SharedNavigationRoutingConfigInput<AppLocales>): {
4
+ export default function createSharedPathnamesNavigation<const AppLocales extends Locales>(routing?: RoutingConfigSharedNavigation<AppLocales, never>): {
5
5
  Link: (props: Omit<Omit<Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
6
6
  href: string | import("url").UrlObject;
7
7
  as?: string | import("url").UrlObject;
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
+ import { RoutingConfigLocalizedNavigation } from '../../routing/config';
2
3
  import { Locales, Pathnames } from '../../routing/types';
3
- import { LocalizedNavigationRoutingConfigInput } from '../shared/config';
4
4
  import { HrefOrHrefWithParams } from '../shared/utils';
5
- export default function createLocalizedPathnamesNavigation<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(input: LocalizedNavigationRoutingConfigInput<AppLocales, AppPathnames>): {
5
+ export default function createLocalizedPathnamesNavigation<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(routing: RoutingConfigLocalizedNavigation<AppLocales, AppPathnames>): {
6
6
  Link: <Pathname extends keyof AppPathnames>({ href, locale, ...rest }: Omit<Omit<Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
7
7
  href: string | import("url").UrlObject;
8
8
  as?: string | import("url").UrlObject;
@@ -38,7 +38,7 @@ export default function createLocalizedPathnamesNavigation<AppLocales extends Lo
38
38
  }, "ref"> & React.RefAttributes<HTMLAnchorElement>, "locale" | "prefix" | "localePrefixMode"> & {
39
39
  locale?: string | undefined;
40
40
  localePrefix: import("../../routing/types").LocalePrefixConfigVerbose<Locales>;
41
- }, "href" | "localePrefix" | "name"> & {
41
+ }, "localePrefix" | "href" | "name"> & {
42
42
  href: Pathname extends `${string}[[...${string}` ? Pathname | ({
43
43
  pathname: Pathname;
44
44
  params?: import("../shared/StrictParams").default<Pathname> | undefined;
@@ -1,8 +1,8 @@
1
1
  import React, { ComponentProps } from 'react';
2
+ import { RoutingConfigSharedNavigation } from '../../routing/config';
2
3
  import { Locales } from '../../routing/types';
3
- import { SharedNavigationRoutingConfigInput } from '../shared/config';
4
4
  import ServerLink from './ServerLink';
5
- export default function createSharedPathnamesNavigation<AppLocales extends Locales>(input?: SharedNavigationRoutingConfigInput<AppLocales>): {
5
+ export default function createSharedPathnamesNavigation<AppLocales extends Locales>(routing?: RoutingConfigSharedNavigation<AppLocales, never>): {
6
6
  Link: (props: Omit<ComponentProps<typeof ServerLink<AppLocales>>, "localePrefix" | "locales">) => React.JSX.Element;
7
7
  redirect: (pathname: string, type?: import("next/navigation").RedirectType | undefined) => never;
8
8
  permanentRedirect: (pathname: string, type?: import("next/navigation").RedirectType | undefined) => never;
@@ -1,14 +1,40 @@
1
- import { Locales, LocalePrefix, LocalePrefixConfigVerbose, DomainsConfig } from './types';
2
- /**
3
- * Maintainer note: The config that is accepted by the middleware, the shared
4
- * and the localized pathnames navigation factory function is slightly
5
- * different. This type declares the shared base config that is accepted by all
6
- * of them. Properties that are different are declared in consuming types.
7
- */
8
- export type RoutingBaseConfigInput<AppLocales extends Locales> = {
9
- /** @see https://next-intl-docs.vercel.app/docs/routing#locale-prefix */
1
+ import { Locales, LocalePrefix, LocalePrefixConfigVerbose, DomainsConfig, Pathnames } from './types';
2
+ export type RoutingConfig<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>> = {
3
+ /**
4
+ * All available locales.
5
+ * @see https://next-intl-docs.vercel.app/docs/routing
6
+ */
7
+ locales: AppLocales;
8
+ /**
9
+ * Used when no locale matches.
10
+ * @see https://next-intl-docs.vercel.app/docs/routing
11
+ */
12
+ defaultLocale: AppLocales[number];
13
+ /**
14
+ * Configures whether and which prefix is shown for a given locale.
15
+ * @see https://next-intl-docs.vercel.app/docs/routing#locale-prefix
16
+ **/
10
17
  localePrefix?: LocalePrefix<AppLocales>;
11
- /** Can be used to change the locale handling per domain. */
18
+ /**
19
+ * Can be used to change the locale handling per domain.
20
+ * @see https://next-intl-docs.vercel.app/docs/routing#domains
21
+ **/
12
22
  domains?: DomainsConfig<AppLocales>;
23
+ } & ([AppPathnames] extends [never] ? {} : {
24
+ /**
25
+ * A map of localized pathnames per locale.
26
+ * @see https://next-intl-docs.vercel.app/docs/routing#pathnames
27
+ **/
28
+ pathnames: AppPathnames;
29
+ });
30
+ export type RoutingConfigSharedNavigation<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>> = Omit<RoutingConfig<AppLocales, AppPathnames>, 'defaultLocale' | 'locales' | 'pathnames'> & Partial<Pick<RoutingConfig<AppLocales, AppPathnames>, 'defaultLocale' | 'locales'>>;
31
+ export type RoutingConfigLocalizedNavigation<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>> = Omit<RoutingConfig<AppLocales, AppPathnames>, 'defaultLocale' | 'pathnames'> & Partial<Pick<RoutingConfig<AppLocales, AppPathnames>, 'defaultLocale'>> & {
32
+ pathnames: AppPathnames;
33
+ };
34
+ export type ResolvedRoutingConfig<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales> = never> = Omit<RoutingConfig<AppLocales, AppPathnames>, 'localePrefix'> & {
35
+ localePrefix: LocalePrefixConfigVerbose<AppLocales>;
36
+ };
37
+ export declare function receiveRoutingConfig<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>, Config extends Partial<RoutingConfig<AppLocales, AppPathnames>>>(input: Config): Config & {
38
+ localePrefix: LocalePrefixConfigVerbose<AppLocales>;
13
39
  };
14
40
  export declare function receiveLocalePrefixConfig<AppLocales extends Locales>(localePrefix?: LocalePrefix<AppLocales>): LocalePrefixConfigVerbose<AppLocales>;
@@ -0,0 +1,3 @@
1
+ import { RoutingConfig } from './config';
2
+ import { Locales, Pathnames } from './types';
3
+ export default function defineRouting<const AppLocales extends Locales, const AppPathnames extends Pathnames<AppLocales> = never>(config: RoutingConfig<AppLocales, AppPathnames>): RoutingConfig<AppLocales, AppPathnames>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1,2 @@
1
1
  export type { Pathnames, LocalePrefix, DomainsConfig } from './types';
2
+ export { default as defineRouting } from './defineRouting';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.17.6",
3
+ "version": "3.18.0",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -87,11 +87,11 @@
87
87
  "dependencies": {
88
88
  "@formatjs/intl-localematcher": "^0.5.4",
89
89
  "negotiator": "^0.6.3",
90
- "use-intl": "^3.17.6"
90
+ "use-intl": "^3.18.0"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
94
94
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
95
95
  },
96
- "gitHead": "9d9d53c9e55f80ce5c6f5cb9bb5f1be04e4d302c"
96
+ "gitHead": "3d31fab161181e2a22198cab152d697bf87b191f"
97
97
  }
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var config = require('../routing/config.js');
6
-
7
- function receiveConfig(input) {
8
- var _input$alternateLinks, _input$localeDetectio;
9
- return {
10
- ...input,
11
- alternateLinks: (_input$alternateLinks = input === null || input === void 0 ? void 0 : input.alternateLinks) !== null && _input$alternateLinks !== void 0 ? _input$alternateLinks : true,
12
- localeDetection: (_input$localeDetectio = input === null || input === void 0 ? void 0 : input.localeDetection) !== null && _input$localeDetectio !== void 0 ? _input$localeDetectio : true,
13
- localePrefix: config.receiveLocalePrefixConfig(input === null || input === void 0 ? void 0 : input.localePrefix)
14
- };
15
- }
16
-
17
- exports.receiveConfig = receiveConfig;
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var config = require('../../routing/config.js');
6
-
7
- /**
8
- * Shared pathnames
9
- */
10
-
11
- function receiveSharedNavigationRoutingConfig(input) {
12
- return {
13
- ...input,
14
- localePrefix: config.receiveLocalePrefixConfig(input === null || input === void 0 ? void 0 : input.localePrefix)
15
- };
16
- }
17
-
18
- /**
19
- * Localized pathnames
20
- */
21
-
22
- function receiveLocalizedNavigationRoutingConfig(input) {
23
- return {
24
- ...input,
25
- localePrefix: config.receiveLocalePrefixConfig(input === null || input === void 0 ? void 0 : input.localePrefix)
26
- };
27
- }
28
-
29
- exports.receiveLocalizedNavigationRoutingConfig = receiveLocalizedNavigationRoutingConfig;
30
- exports.receiveSharedNavigationRoutingConfig = receiveSharedNavigationRoutingConfig;
@@ -1 +0,0 @@
1
- import{receiveLocalePrefixConfig as l}from"../routing/config.js";function o(o){var e,n;return{...o,alternateLinks:null===(e=null==o?void 0:o.alternateLinks)||void 0===e||e,localeDetection:null===(n=null==o?void 0:o.localeDetection)||void 0===n||n,localePrefix:l(null==o?void 0:o.localePrefix)}}export{o as receiveConfig};
@@ -1 +0,0 @@
1
- import{receiveLocalePrefixConfig as o}from"../../routing/config.js";function l(l){return{...l,localePrefix:o(null==l?void 0:l.localePrefix)}}function r(l){return{...l,localePrefix:o(null==l?void 0:l.localePrefix)}}export{r as receiveLocalizedNavigationRoutingConfig,l as receiveSharedNavigationRoutingConfig};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../routing/config.js");exports.receiveConfig=function(l){var i,o;return{...l,alternateLinks:null===(i=null==l?void 0:l.alternateLinks)||void 0===i||i,localeDetection:null===(o=null==l?void 0:l.localeDetection)||void 0===o||o,localePrefix:e.receiveLocalePrefixConfig(null==l?void 0:l.localePrefix)}};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../routing/config.js");exports.receiveLocalizedNavigationRoutingConfig=function(i){return{...i,localePrefix:e.receiveLocalePrefixConfig(null==i?void 0:i.localePrefix)}},exports.receiveSharedNavigationRoutingConfig=function(i){return{...i,localePrefix:e.receiveLocalePrefixConfig(null==i?void 0:i.localePrefix)}};
@@ -1,24 +0,0 @@
1
- import { RoutingBaseConfigInput } from '../../routing/config';
2
- import { Locales, LocalePrefixConfigVerbose, Pathnames } from '../../routing/types';
3
- /**
4
- * Shared pathnames
5
- */
6
- export type SharedNavigationRoutingConfigInput<AppLocales extends Locales> = RoutingBaseConfigInput<AppLocales> & {
7
- locales?: AppLocales;
8
- };
9
- export type SharedNavigationRoutingConfig<AppLocales extends Locales> = SharedNavigationRoutingConfigInput<AppLocales> & {
10
- localePrefix: LocalePrefixConfigVerbose<AppLocales>;
11
- };
12
- export declare function receiveSharedNavigationRoutingConfig<AppLocales extends Locales>(input?: SharedNavigationRoutingConfigInput<AppLocales>): SharedNavigationRoutingConfig<AppLocales>;
13
- /**
14
- * Localized pathnames
15
- */
16
- export type LocalizedNavigationRoutingConfigInput<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>> = RoutingBaseConfigInput<AppLocales> & {
17
- locales: AppLocales;
18
- /** Maps internal pathnames to external ones which can be localized per locale. */
19
- pathnames: AppPathnames;
20
- };
21
- export type LocalizedNavigationRoutingConfig<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>> = LocalizedNavigationRoutingConfigInput<AppLocales, AppPathnames> & {
22
- localePrefix: LocalePrefixConfigVerbose<AppLocales>;
23
- };
24
- export declare function receiveLocalizedNavigationRoutingConfig<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(input: LocalizedNavigationRoutingConfigInput<AppLocales, AppPathnames>): LocalizedNavigationRoutingConfig<AppLocales, AppPathnames>;