@puzzle-ui/i18n 0.0.0-stage → 0.16.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.
- package/README.md +94 -2
- package/ai/instructions.md +141 -0
- package/ai/manifest.json +10 -0
- package/dist/LICENSE +21 -0
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/adapters/next.cjs +11 -0
- package/dist/adapters/next.cjs.map +1 -0
- package/dist/adapters/next.d.cts +7 -0
- package/dist/adapters/next.d.ts +7 -0
- package/dist/adapters/next.js +10 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/adapters/react-router.cjs +13 -0
- package/dist/adapters/react-router.cjs.map +1 -0
- package/dist/adapters/react-router.d.cts +10 -0
- package/dist/adapters/react-router.d.ts +10 -0
- package/dist/adapters/react-router.js +12 -0
- package/dist/adapters/react-router.js.map +1 -0
- package/dist/adapters/request.cjs +67 -0
- package/dist/adapters/request.cjs.map +1 -0
- package/dist/adapters/request.d.cts +16 -0
- package/dist/adapters/request.d.ts +16 -0
- package/dist/adapters/request.js +65 -0
- package/dist/adapters/request.js.map +1 -0
- package/dist/adapters/tanstack.cjs +13 -0
- package/dist/adapters/tanstack.cjs.map +1 -0
- package/dist/adapters/tanstack.d.cts +10 -0
- package/dist/adapters/tanstack.d.ts +10 -0
- package/dist/adapters/tanstack.js +12 -0
- package/dist/adapters/tanstack.js.map +1 -0
- package/dist/ai/index.cjs +205 -0
- package/dist/ai/index.cjs.map +1 -0
- package/dist/ai/index.d.cts +75 -0
- package/dist/ai/index.d.ts +75 -0
- package/dist/ai/index.js +195 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/review.cjs +319 -0
- package/dist/ai/review.cjs.map +1 -0
- package/dist/ai/review.d.cts +91 -0
- package/dist/ai/review.d.ts +91 -0
- package/dist/ai/review.js +315 -0
- package/dist/ai/review.js.map +1 -0
- package/dist/cli/bin.cjs +10 -0
- package/dist/cli/bin.cjs.map +1 -0
- package/dist/cli/bin.d.cts +1 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +12 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/index.cjs +310 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +7 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.js +309 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/compiler/index.cjs +218 -0
- package/dist/compiler/index.cjs.map +1 -0
- package/dist/compiler/index.d.cts +18 -0
- package/dist/compiler/index.d.ts +18 -0
- package/dist/compiler/index.js +210 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/typescript.cjs +251 -0
- package/dist/compiler/typescript.cjs.map +1 -0
- package/dist/compiler/typescript.d.cts +27 -0
- package/dist/compiler/typescript.d.ts +27 -0
- package/dist/compiler/typescript.js +247 -0
- package/dist/compiler/typescript.js.map +1 -0
- package/dist/compiler/vite.cjs +94 -0
- package/dist/compiler/vite.cjs.map +1 -0
- package/dist/compiler/vite.d.cts +13 -0
- package/dist/compiler/vite.d.ts +13 -0
- package/dist/compiler/vite.js +92 -0
- package/dist/compiler/vite.js.map +1 -0
- package/dist/content/index.cjs +156 -0
- package/dist/content/index.cjs.map +1 -0
- package/dist/content/index.d.cts +75 -0
- package/dist/content/index.d.ts +75 -0
- package/dist/content/index.js +151 -0
- package/dist/content/index.js.map +1 -0
- package/dist/content/sanity.cjs +74 -0
- package/dist/content/sanity.cjs.map +1 -0
- package/dist/content/sanity.d.cts +19 -0
- package/dist/content/sanity.d.ts +19 -0
- package/dist/content/sanity.js +73 -0
- package/dist/content/sanity.js.map +1 -0
- package/dist/devtools/index.cjs +77 -0
- package/dist/devtools/index.cjs.map +1 -0
- package/dist/devtools/index.d.cts +29 -0
- package/dist/devtools/index.d.ts +29 -0
- package/dist/devtools/index.js +75 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/format.cjs +17 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.cts +9 -0
- package/dist/format.d.ts +9 -0
- package/dist/format.js +13 -0
- package/dist/format.js.map +1 -0
- package/dist/index.cjs +20 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/locale.cjs +158 -0
- package/dist/locale.cjs.map +1 -0
- package/dist/locale.d.cts +42 -0
- package/dist/locale.d.ts +42 -0
- package/dist/locale.js +155 -0
- package/dist/locale.js.map +1 -0
- package/dist/react/index.cjs +239 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +105 -0
- package/dist/react/index.d.ts +105 -0
- package/dist/react/index.js +238 -0
- package/dist/react/index.js.map +1 -0
- package/dist/routing/index.cjs +381 -0
- package/dist/routing/index.cjs.map +1 -0
- package/dist/routing/index.d.cts +44 -0
- package/dist/routing/index.d.ts +44 -0
- package/dist/routing/index.js +380 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/runtime.cjs +261 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +74 -0
- package/dist/runtime.d.ts +74 -0
- package/dist/runtime.js +257 -0
- package/dist/runtime.js.map +1 -0
- package/dist/seo/index.cjs +212 -0
- package/dist/seo/index.cjs.map +1 -0
- package/dist/seo/index.d.cts +52 -0
- package/dist/seo/index.d.ts +52 -0
- package/dist/seo/index.js +209 -0
- package/dist/seo/index.js.map +1 -0
- package/dist/seo/origin.cjs +27 -0
- package/dist/seo/origin.cjs.map +1 -0
- package/dist/seo/origin.js +26 -0
- package/dist/seo/origin.js.map +1 -0
- package/dist/seo/sitemap.cjs +74 -0
- package/dist/seo/sitemap.cjs.map +1 -0
- package/dist/seo/sitemap.d.cts +16 -0
- package/dist/seo/sitemap.d.ts +16 -0
- package/dist/seo/sitemap.js +72 -0
- package/dist/seo/sitemap.js.map +1 -0
- package/dist/sources/index.cjs +227 -0
- package/dist/sources/index.cjs.map +1 -0
- package/dist/sources/index.d.cts +41 -0
- package/dist/sources/index.d.ts +41 -0
- package/dist/sources/index.js +222 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/node.cjs +50 -0
- package/dist/sources/node.cjs.map +1 -0
- package/dist/sources/node.d.cts +5 -0
- package/dist/sources/node.d.ts +5 -0
- package/dist/sources/node.js +49 -0
- package/dist/sources/node.js.map +1 -0
- package/package.json +256 -4
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
// src/routing/index.ts
|
|
2
|
+
const INTERNAL_ORIGIN = "https://puzzle-i18n.invalid";
|
|
3
|
+
const MALFORMED_ESCAPE = /%(?![\da-f]{2})/i;
|
|
4
|
+
const ENCODED_PATH_SEPARATOR = /%(?:2f|5c)/i;
|
|
5
|
+
const CONTROL_CHARACTER = /[\u0000-\u001f\u007f]/;
|
|
6
|
+
const PARAMETER_SEGMENT = /^:([A-Za-z][A-Za-z0-9_]*)$/;
|
|
7
|
+
const invalidPath = () => /* @__PURE__ */ new Error("Localized routes must be safe, same-origin absolute paths or configured locale origins.");
|
|
8
|
+
const validatePercentEscapes = (value) => {
|
|
9
|
+
if (MALFORMED_ESCAPE.test(value)) throw invalidPath();
|
|
10
|
+
};
|
|
11
|
+
const validatePathname = (pathname) => {
|
|
12
|
+
if (!pathname.startsWith("/") || pathname.startsWith("//") || pathname.includes("//") || pathname.includes("\\") || CONTROL_CHARACTER.test(pathname) || ENCODED_PATH_SEPARATOR.test(pathname)) throw invalidPath();
|
|
13
|
+
validatePercentEscapes(pathname);
|
|
14
|
+
for (const segment of pathname.split("/")) {
|
|
15
|
+
let decoded;
|
|
16
|
+
try {
|
|
17
|
+
decoded = decodeURIComponent(segment);
|
|
18
|
+
} catch {
|
|
19
|
+
throw invalidPath();
|
|
20
|
+
}
|
|
21
|
+
const validateDecodedSegment = (value) => {
|
|
22
|
+
if (value === "." || value === ".." || value.includes("/") || value.includes("\\") || CONTROL_CHARACTER.test(value)) throw invalidPath();
|
|
23
|
+
};
|
|
24
|
+
validateDecodedSegment(decoded);
|
|
25
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
26
|
+
if (!/%[\da-f]{2}/i.test(decoded)) break;
|
|
27
|
+
let nested;
|
|
28
|
+
try {
|
|
29
|
+
nested = decodeURIComponent(decoded);
|
|
30
|
+
} catch {
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
if (nested === decoded) break;
|
|
34
|
+
validateDecodedSegment(nested);
|
|
35
|
+
decoded = nested;
|
|
36
|
+
}
|
|
37
|
+
if (/%[\da-f]{2}/i.test(decoded)) throw invalidPath();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const normalizeBasePath = (value) => {
|
|
41
|
+
if (value === void 0 || value === "" || value === "/") return "";
|
|
42
|
+
if (value.includes("?") || value.includes("#") || /\/{2,}/.test(value)) throw new Error("Localized routing basePath must be a safe pathname.");
|
|
43
|
+
validatePathname(value);
|
|
44
|
+
return value.replace(/\/+$/, "");
|
|
45
|
+
};
|
|
46
|
+
const stripBasePath = (pathname, basePath) => {
|
|
47
|
+
if (!basePath) return pathname;
|
|
48
|
+
if (pathname === basePath) return "/";
|
|
49
|
+
if (!pathname.startsWith(`${basePath}/`)) throw new Error(`Localized route path must be within the configured basePath "${basePath}".`);
|
|
50
|
+
return pathname.slice(basePath.length);
|
|
51
|
+
};
|
|
52
|
+
const rawPathname = (input, isAbsoluteUrl) => {
|
|
53
|
+
if (!isAbsoluteUrl) return input.split(/[?#]/, 1)[0] ?? "/";
|
|
54
|
+
const schemeEnd = input.indexOf("://") + 3;
|
|
55
|
+
const authorityEndOffset = input.slice(schemeEnd).search(/[/?#]/);
|
|
56
|
+
const authorityEnd = authorityEndOffset === -1 ? input.length : schemeEnd + authorityEndOffset;
|
|
57
|
+
const suffix = input.slice(authorityEnd);
|
|
58
|
+
if (!suffix.startsWith("/")) return "/";
|
|
59
|
+
return suffix.split(/[?#]/, 1)[0] ?? "/";
|
|
60
|
+
};
|
|
61
|
+
const parseInternalPath = (path, originsByOrigin) => {
|
|
62
|
+
if (typeof path !== "string") throw invalidPath();
|
|
63
|
+
const absoluteUrl = /^https?:\/\//i.test(path);
|
|
64
|
+
if (CONTROL_CHARACTER.test(path) || path.includes("\\") || !absoluteUrl && (!path.startsWith("/") || path.startsWith("//"))) throw invalidPath();
|
|
65
|
+
validatePercentEscapes(path);
|
|
66
|
+
validatePathname(rawPathname(path, absoluteUrl));
|
|
67
|
+
let url;
|
|
68
|
+
try {
|
|
69
|
+
url = new URL(path, INTERNAL_ORIGIN);
|
|
70
|
+
} catch {
|
|
71
|
+
throw invalidPath();
|
|
72
|
+
}
|
|
73
|
+
if (url.protocol !== "https:" && url.protocol !== "http:" || url.username || url.password) throw invalidPath();
|
|
74
|
+
const originLocale = originsByOrigin.get(url.origin);
|
|
75
|
+
if (absoluteUrl && (url.origin === INTERNAL_ORIGIN || !originLocale)) {
|
|
76
|
+
if (originsByOrigin.size === 0) throw invalidPath();
|
|
77
|
+
throw new Error("Localized routes must not contain an external origin.");
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
url,
|
|
81
|
+
originLocale
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
const normalizeOrigin = (value) => {
|
|
85
|
+
if (value.includes("\\") || !/^https?:\/\/[^/?#]+\/?$/i.test(value)) throw new Error("Locale origins must be bare HTTP(S) origins without credentials, paths, queries, or hashes.");
|
|
86
|
+
let url;
|
|
87
|
+
try {
|
|
88
|
+
url = new URL(value);
|
|
89
|
+
} catch {
|
|
90
|
+
throw new Error(`Invalid locale origin "${value}".`);
|
|
91
|
+
}
|
|
92
|
+
if (url.protocol !== "https:" && url.protocol !== "http:" || url.username || url.password || url.origin === INTERNAL_ORIGIN) throw new Error(`Invalid locale origin "${value}".`);
|
|
93
|
+
return url.origin;
|
|
94
|
+
};
|
|
95
|
+
const compilePattern = (path) => {
|
|
96
|
+
if (path.includes("?") || path.includes("#") || CONTROL_CHARACTER.test(path)) throw new Error("Localized route patterns must contain only a pathname.");
|
|
97
|
+
validatePathname(path);
|
|
98
|
+
const parameterNames = [];
|
|
99
|
+
return {
|
|
100
|
+
path,
|
|
101
|
+
segments: path.split("/").map((segment) => {
|
|
102
|
+
const parameter = PARAMETER_SEGMENT.exec(segment);
|
|
103
|
+
if (!parameter) {
|
|
104
|
+
if (segment.startsWith(":")) throw new Error(`Invalid route parameter segment "${segment}".`);
|
|
105
|
+
return {
|
|
106
|
+
kind: "literal",
|
|
107
|
+
value: decodeURIComponent(segment)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const name = parameter[1];
|
|
111
|
+
if (!name || parameterNames.includes(name)) throw new Error(`Invalid or duplicate route parameter "${name}".`);
|
|
112
|
+
parameterNames.push(name);
|
|
113
|
+
return {
|
|
114
|
+
kind: "parameter",
|
|
115
|
+
name
|
|
116
|
+
};
|
|
117
|
+
}),
|
|
118
|
+
parameterNames: Object.freeze(parameterNames)
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
const patternKey = (pattern) => JSON.stringify(pattern.segments.map((segment) => segment.kind === "parameter" ? ":" : segment.value));
|
|
122
|
+
const routePathParts = (value) => {
|
|
123
|
+
if (typeof value === "string") return {
|
|
124
|
+
path: value,
|
|
125
|
+
aliases: []
|
|
126
|
+
};
|
|
127
|
+
if (!value || typeof value !== "object" || typeof value.path !== "string" || value.aliases !== void 0 && (!Array.isArray(value.aliases) || value.aliases.some((alias) => typeof alias !== "string"))) throw new Error("Localized route definitions must provide a path.");
|
|
128
|
+
return {
|
|
129
|
+
path: value.path,
|
|
130
|
+
aliases: value.aliases ?? []
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
const compileRoutes = (routes, registry) => {
|
|
134
|
+
const result = /* @__PURE__ */ new Map();
|
|
135
|
+
const pathsByLocale = /* @__PURE__ */ new Map();
|
|
136
|
+
for (const definition of registry.locales) pathsByLocale.set(definition.locale, /* @__PURE__ */ new Map());
|
|
137
|
+
for (const [routeId, route] of Object.entries(routes)) {
|
|
138
|
+
if (!routeId || !route || typeof route !== "object") throw new Error("Localized route maps must use non-empty route IDs.");
|
|
139
|
+
const locales = /* @__PURE__ */ new Map();
|
|
140
|
+
for (const [inputLocale, value] of Object.entries(route)) {
|
|
141
|
+
const locale = registry.resolve(inputLocale);
|
|
142
|
+
if (!locale) throw new Error(`Route "${routeId}" uses unsupported locale "${inputLocale}".`);
|
|
143
|
+
if (locales.has(locale)) throw new Error(`Route "${routeId}" defines locale "${locale}" more than once.`);
|
|
144
|
+
const { path, aliases } = routePathParts(value);
|
|
145
|
+
const canonical = compilePattern(path);
|
|
146
|
+
const compiledAliases = aliases.map(compilePattern);
|
|
147
|
+
for (const alias of compiledAliases) if (alias.parameterNames.length !== canonical.parameterNames.length) throw new Error(`Route aliases for "${routeId}" must use the same number of parameters as the canonical path.`);
|
|
148
|
+
const patterns = [canonical, ...compiledAliases];
|
|
149
|
+
const localePaths = pathsByLocale.get(locale);
|
|
150
|
+
if (!localePaths) throw new Error(`Unsupported route locale "${locale}".`);
|
|
151
|
+
for (const pattern of patterns) {
|
|
152
|
+
const key = patternKey(pattern);
|
|
153
|
+
const existing = localePaths.get(key);
|
|
154
|
+
if (existing) throw new Error(`Route path "${pattern.path}" is ambiguous between "${existing}" and "${routeId}" for locale "${locale}".`);
|
|
155
|
+
localePaths.set(key, routeId);
|
|
156
|
+
}
|
|
157
|
+
locales.set(locale, Object.freeze({
|
|
158
|
+
canonical,
|
|
159
|
+
aliases: Object.freeze(compiledAliases)
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
for (const definition of registry.locales) if (!locales.has(definition.locale)) throw new Error(`Route "${routeId}" is missing a path for locale "${definition.locale}".`);
|
|
163
|
+
const defaultRoute = locales.get(registry.defaultLocale);
|
|
164
|
+
if (defaultRoute && [...locales.values()].some((localeRoute) => localeRoute.canonical.parameterNames.length !== defaultRoute.canonical.parameterNames.length)) throw new Error(`Route "${routeId}" must use the same number of parameters for every locale.`);
|
|
165
|
+
result.set(routeId, locales);
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
};
|
|
169
|
+
const localePathMatch = (parsed, registry, basePath) => {
|
|
170
|
+
const segments = stripBasePath(parsed.url.pathname, basePath).split("/");
|
|
171
|
+
let pathLocale;
|
|
172
|
+
try {
|
|
173
|
+
pathLocale = segments[1] ? registry.resolve(decodeURIComponent(segments[1])) : void 0;
|
|
174
|
+
} catch {
|
|
175
|
+
pathLocale = void 0;
|
|
176
|
+
}
|
|
177
|
+
if (pathLocale) segments.splice(1, 1);
|
|
178
|
+
if (pathLocale && parsed.originLocale && pathLocale !== parsed.originLocale) throw new Error("The locale path prefix does not match the configured locale origin.");
|
|
179
|
+
const pathname = segments.join("/") || "/";
|
|
180
|
+
if (pathname.startsWith("//")) throw invalidPath();
|
|
181
|
+
return {
|
|
182
|
+
locale: pathLocale ?? parsed.originLocale ?? registry.defaultLocale,
|
|
183
|
+
pathname: pathname.startsWith("/") ? pathname : `/${pathname}`,
|
|
184
|
+
search: parsed.url.search,
|
|
185
|
+
hash: parsed.url.hash,
|
|
186
|
+
matchedPrefix: pathLocale !== void 0
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
const matchPattern = (pattern, pathname) => {
|
|
190
|
+
const pathSegments = pathname.split("/");
|
|
191
|
+
if (pathSegments.length !== pattern.segments.length) return;
|
|
192
|
+
const params = {};
|
|
193
|
+
for (const [index, segment] of pattern.segments.entries()) {
|
|
194
|
+
const pathSegment = pathSegments[index];
|
|
195
|
+
if (pathSegment === void 0) return;
|
|
196
|
+
let decoded;
|
|
197
|
+
try {
|
|
198
|
+
decoded = decodeURIComponent(pathSegment);
|
|
199
|
+
} catch {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (segment.kind === "literal") {
|
|
203
|
+
if (decoded !== segment.value) return;
|
|
204
|
+
} else {
|
|
205
|
+
if (decoded.length === 0) return;
|
|
206
|
+
params[segment.name] = decoded;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return Object.freeze(params);
|
|
210
|
+
};
|
|
211
|
+
const remapParameters = (source, params, target) => {
|
|
212
|
+
const result = {};
|
|
213
|
+
for (const [index, name] of target.parameterNames.entries()) {
|
|
214
|
+
const sourceName = source.parameterNames[index];
|
|
215
|
+
const value = sourceName ? params[sourceName] : void 0;
|
|
216
|
+
if (value === void 0) throw new Error(`Missing route parameter "${sourceName ?? name}".`);
|
|
217
|
+
result[name] = value;
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
};
|
|
221
|
+
const normalizeSuffix = (options = {}) => {
|
|
222
|
+
const search = options.search ?? "";
|
|
223
|
+
const hash = options.hash ?? "";
|
|
224
|
+
if (search && !search.startsWith("?") || search.includes("#") || hash && !hash.startsWith("#") || hash.includes("?") || CONTROL_CHARACTER.test(search) || CONTROL_CHARACTER.test(hash)) throw new Error("Route search and hash values must be safe URL suffixes.");
|
|
225
|
+
validatePercentEscapes(search);
|
|
226
|
+
validatePercentEscapes(hash);
|
|
227
|
+
return {
|
|
228
|
+
search,
|
|
229
|
+
hash
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
const fillPattern = (pattern, params = {}) => {
|
|
233
|
+
const expected = new Set(pattern.parameterNames);
|
|
234
|
+
for (const key of Object.keys(params)) if (!expected.has(key)) throw new Error(`Unknown route parameter "${key}".`);
|
|
235
|
+
return pattern.segments.map((segment) => {
|
|
236
|
+
if (segment.kind === "literal") return encodeURIComponent(segment.value).replace(/%2F/gi, "/");
|
|
237
|
+
const value = params[segment.name];
|
|
238
|
+
if (typeof value !== "string" && typeof value !== "number" || !Number.isFinite(typeof value === "number" ? value : 0)) throw new Error(`Missing route parameter "${segment.name}".`);
|
|
239
|
+
const normalized = String(value);
|
|
240
|
+
if (normalized.length === 0 || normalized === "." || normalized === ".." || normalized.includes("/") || normalized.includes("\\") || CONTROL_CHARACTER.test(normalized)) throw new Error(`Unsafe value for route parameter "${segment.name}".`);
|
|
241
|
+
try {
|
|
242
|
+
const encoded = encodeURIComponent(normalized);
|
|
243
|
+
validatePathname(`/${encoded}`);
|
|
244
|
+
return encoded;
|
|
245
|
+
} catch {
|
|
246
|
+
throw new Error(`Unsafe value for route parameter "${segment.name}".`);
|
|
247
|
+
}
|
|
248
|
+
}).join("/") || "/";
|
|
249
|
+
};
|
|
250
|
+
const createLocalizedRouting = (options) => {
|
|
251
|
+
const { registry } = options;
|
|
252
|
+
const prefixDefaultLocale = options.prefixDefaultLocale ?? false;
|
|
253
|
+
const basePath = normalizeBasePath(options.basePath);
|
|
254
|
+
const originsByLocale = /* @__PURE__ */ new Map();
|
|
255
|
+
const originsByOrigin = /* @__PURE__ */ new Map();
|
|
256
|
+
for (const [inputLocale, originInput] of Object.entries(options.origins ?? {})) {
|
|
257
|
+
const locale = registry.resolve(inputLocale);
|
|
258
|
+
if (!locale) throw new Error(`Unsupported origin locale "${inputLocale}".`);
|
|
259
|
+
if (originsByLocale.has(locale)) throw new Error(`Origin for locale "${locale}" is defined more than once.`);
|
|
260
|
+
const origin = normalizeOrigin(originInput);
|
|
261
|
+
const existingLocale = originsByOrigin.get(origin);
|
|
262
|
+
if (existingLocale) throw new Error(`Origin "${origin}" is shared by locales "${existingLocale}" and "${locale}".`);
|
|
263
|
+
originsByLocale.set(locale, origin);
|
|
264
|
+
originsByOrigin.set(origin, locale);
|
|
265
|
+
}
|
|
266
|
+
const routes = compileRoutes(options.routes ?? {}, registry);
|
|
267
|
+
const parse = (path) => parseInternalPath(path, originsByOrigin);
|
|
268
|
+
const match = (path) => localePathMatch(parse(path), registry, basePath);
|
|
269
|
+
const buildLocalizedPath = (pathname, search, hash, locale) => {
|
|
270
|
+
const origin = originsByLocale.get(locale);
|
|
271
|
+
const shouldPrefix = !origin && (locale !== registry.defaultLocale || prefixDefaultLocale);
|
|
272
|
+
const localizedPath = pathname === "/" ? shouldPrefix ? `/${locale}` : "/" : shouldPrefix ? `/${locale}${pathname}` : pathname;
|
|
273
|
+
const pathWithSuffix = `${(basePath ? `${basePath}${localizedPath === "/" ? "" : localizedPath}` : localizedPath) || "/"}${search}${hash}`;
|
|
274
|
+
return origin ? `${origin}${pathWithSuffix}` : pathWithSuffix;
|
|
275
|
+
};
|
|
276
|
+
const getRouteMatch = (path) => {
|
|
277
|
+
const parsed = parse(path);
|
|
278
|
+
const localeMatch = localePathMatch(parsed, registry, basePath);
|
|
279
|
+
for (const [routeId, routeLocales] of routes) {
|
|
280
|
+
const route = routeLocales.get(localeMatch.locale);
|
|
281
|
+
if (!route) continue;
|
|
282
|
+
const canonicalParams = matchPattern(route.canonical, localeMatch.pathname);
|
|
283
|
+
if (canonicalParams) return {
|
|
284
|
+
routeId,
|
|
285
|
+
localeMatch,
|
|
286
|
+
parsed,
|
|
287
|
+
params: canonicalParams,
|
|
288
|
+
sourcePattern: route.canonical,
|
|
289
|
+
canonicalPattern: route.canonical,
|
|
290
|
+
isAlias: false
|
|
291
|
+
};
|
|
292
|
+
for (const alias of route.aliases) {
|
|
293
|
+
const params = matchPattern(alias, localeMatch.pathname);
|
|
294
|
+
if (params) return {
|
|
295
|
+
routeId,
|
|
296
|
+
localeMatch,
|
|
297
|
+
parsed,
|
|
298
|
+
params,
|
|
299
|
+
sourcePattern: alias,
|
|
300
|
+
canonicalPattern: route.canonical,
|
|
301
|
+
isAlias: true
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
const localizeRoute = (routeId, inputLocale, params = {}, outputOptions = {}) => {
|
|
307
|
+
const locale = registry.resolve(inputLocale);
|
|
308
|
+
if (!locale) throw new Error(`Unsupported locale "${inputLocale}".`);
|
|
309
|
+
const localeRoute = routes.get(routeId)?.get(locale);
|
|
310
|
+
if (!localeRoute) throw new Error(`Route "${routeId}" has no path for locale "${locale}".`);
|
|
311
|
+
const suffix = normalizeSuffix(outputOptions);
|
|
312
|
+
const pathname = fillPattern(localeRoute.canonical, params);
|
|
313
|
+
return buildLocalizedPath(pathname, suffix.search, suffix.hash, locale);
|
|
314
|
+
};
|
|
315
|
+
const localize = (path, inputLocale) => {
|
|
316
|
+
const locale = registry.resolve(inputLocale);
|
|
317
|
+
if (!locale) throw new Error(`Unsupported locale "${inputLocale}".`);
|
|
318
|
+
const routeMatch = getRouteMatch(path);
|
|
319
|
+
if (routeMatch) {
|
|
320
|
+
const target = routes.get(routeMatch.routeId)?.get(locale);
|
|
321
|
+
if (!target) throw new Error(`Route "${routeMatch.routeId}" has no path for locale "${locale}".`);
|
|
322
|
+
const params = remapParameters(routeMatch.sourcePattern, routeMatch.params, target.canonical);
|
|
323
|
+
return localizeRoute(routeMatch.routeId, locale, params, {
|
|
324
|
+
search: routeMatch.localeMatch.search,
|
|
325
|
+
hash: routeMatch.localeMatch.hash
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
const current = match(path);
|
|
329
|
+
return buildLocalizedPath(current.pathname, current.search, current.hash, locale);
|
|
330
|
+
};
|
|
331
|
+
const alternatePaths = (path) => {
|
|
332
|
+
const result = {};
|
|
333
|
+
for (const locale of registry.locales) result[locale.locale] = localize(path, locale.locale);
|
|
334
|
+
return result;
|
|
335
|
+
};
|
|
336
|
+
const matchRoute = (path) => {
|
|
337
|
+
const routeMatch = getRouteMatch(path);
|
|
338
|
+
if (!routeMatch) return;
|
|
339
|
+
const canonicalParams = remapParameters(routeMatch.sourcePattern, routeMatch.params, routeMatch.canonicalPattern);
|
|
340
|
+
const canonicalPath = buildLocalizedPath(fillPattern(routeMatch.canonicalPattern, canonicalParams), routeMatch.localeMatch.search, routeMatch.localeMatch.hash, routeMatch.localeMatch.locale);
|
|
341
|
+
const originalPath = routeMatch.parsed.url.origin === INTERNAL_ORIGIN ? `${routeMatch.parsed.url.pathname}${routeMatch.parsed.url.search}${routeMatch.parsed.url.hash}` : `${routeMatch.parsed.url.origin}${routeMatch.parsed.url.pathname}${routeMatch.parsed.url.search}${routeMatch.parsed.url.hash}`;
|
|
342
|
+
const redirectTo = routeMatch.isAlias || canonicalPath !== originalPath ? canonicalPath : void 0;
|
|
343
|
+
return {
|
|
344
|
+
...routeMatch.localeMatch,
|
|
345
|
+
routeId: routeMatch.routeId,
|
|
346
|
+
params: routeMatch.params,
|
|
347
|
+
isAlias: routeMatch.isAlias,
|
|
348
|
+
canonicalPath,
|
|
349
|
+
...redirectTo ? { redirectTo } : {}
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
const alternateRoutePaths = (routeId, params = {}, outputOptions = {}) => {
|
|
353
|
+
const result = {};
|
|
354
|
+
const sourceRoute = routes.get(routeId)?.get(registry.defaultLocale);
|
|
355
|
+
for (const locale of registry.locales) {
|
|
356
|
+
const targetRoute = routes.get(routeId)?.get(locale.locale);
|
|
357
|
+
if (!sourceRoute || !targetRoute) throw new Error(`Route "${routeId}" has no path for locale "${locale.locale}".`);
|
|
358
|
+
const sourceParams = {};
|
|
359
|
+
for (const [key, value] of Object.entries(params)) {
|
|
360
|
+
if (!sourceRoute.canonical.parameterNames.includes(key)) throw new Error(`Unknown route parameter "${key}".`);
|
|
361
|
+
if (typeof value === "number" && !Number.isFinite(value)) throw new Error(`Invalid value for route parameter "${key}".`);
|
|
362
|
+
sourceParams[key] = String(value);
|
|
363
|
+
}
|
|
364
|
+
const localizedParams = remapParameters(sourceRoute.canonical, sourceParams, targetRoute.canonical);
|
|
365
|
+
result[locale.locale] = localizeRoute(routeId, locale.locale, localizedParams, outputOptions);
|
|
366
|
+
}
|
|
367
|
+
return Object.freeze(result);
|
|
368
|
+
};
|
|
369
|
+
return Object.freeze({
|
|
370
|
+
match,
|
|
371
|
+
localize,
|
|
372
|
+
alternatePaths,
|
|
373
|
+
matchRoute,
|
|
374
|
+
localizeRoute,
|
|
375
|
+
alternateRoutePaths
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
export { createLocalizedRouting };
|
|
379
|
+
|
|
380
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/routing/index.ts"],"sourcesContent":["import type { LocaleRegistry } from \"../locale\";\n\nconst INTERNAL_ORIGIN = \"https://puzzle-i18n.invalid\";\nconst MALFORMED_ESCAPE = /%(?![\\da-f]{2})/i;\nconst ENCODED_PATH_SEPARATOR = /%(?:2f|5c)/i;\nconst CONTROL_CHARACTER = /[\\u0000-\\u001f\\u007f]/;\nconst PARAMETER_SEGMENT = /^:([A-Za-z][A-Za-z0-9_]*)$/;\n\nexport interface LocalizedRouteMatch {\n locale: string;\n pathname: string;\n search: string;\n hash: string;\n matchedPrefix: boolean;\n}\n\nexport interface LocalizedRoutePathDefinition {\n path: string;\n aliases?: readonly string[];\n}\n\nexport type LocalizedRoutePath =\n | string\n | LocalizedRoutePathDefinition;\n\nexport type LocalizedRouteMap = Readonly<\n Record<string, Readonly<Record<string, LocalizedRoutePath>>>\n>;\n\nexport interface LocalizedRoutingOptions<\n Routes extends LocalizedRouteMap = LocalizedRouteMap,\n> {\n registry: LocaleRegistry;\n prefixDefaultLocale?: boolean;\n basePath?: string;\n routes?: Routes;\n origins?: Readonly<Record<string, string>>;\n}\n\nexport interface LocalizedRouteOutputOptions {\n search?: string;\n hash?: string;\n}\n\nexport interface MatchedLocalizedRoute<\n RouteId extends string = string,\n> extends LocalizedRouteMatch {\n routeId: RouteId;\n params: Readonly<Record<string, string>>;\n isAlias: boolean;\n canonicalPath: string;\n redirectTo?: string;\n}\n\ntype RouteIds<Routes extends LocalizedRouteMap> = Extract<\n keyof Routes,\n string\n>;\ntype RouteLocales<\n Routes extends LocalizedRouteMap,\n RouteId extends RouteIds<Routes>,\n> = Extract<keyof Routes[RouteId], string>;\n\nexport interface LocalizedRouting<\n Routes extends LocalizedRouteMap = LocalizedRouteMap,\n> {\n match(path: string): LocalizedRouteMatch;\n localize(path: string, locale: string): string;\n alternatePaths(path: string): Readonly<Record<string, string>>;\n matchRoute(path: string): MatchedLocalizedRoute<RouteIds<Routes>> | undefined;\n localizeRoute<RouteId extends RouteIds<Routes>>(\n routeId: RouteId,\n locale: RouteLocales<Routes, RouteId>,\n params?: Readonly<Record<string, string | number>>,\n options?: LocalizedRouteOutputOptions,\n ): string;\n alternateRoutePaths<RouteId extends RouteIds<Routes>>(\n routeId: RouteId,\n params?: Readonly<Record<string, string | number>>,\n options?: LocalizedRouteOutputOptions,\n ): Readonly<Record<string, string>>;\n}\n\ninterface ParsedPath {\n url: URL;\n originLocale?: string;\n}\n\ninterface LocalePathMatch {\n locale: string;\n pathname: string;\n search: string;\n hash: string;\n matchedPrefix: boolean;\n}\n\ninterface CompiledPattern {\n path: string;\n segments: readonly RouteSegment[];\n parameterNames: readonly string[];\n}\n\ntype RouteSegment =\n | { kind: \"literal\"; value: string }\n | { kind: \"parameter\"; name: string };\n\ninterface CompiledRouteLocale {\n canonical: CompiledPattern;\n aliases: readonly CompiledPattern[];\n}\n\ninterface CompiledRouteMatch {\n routeId: string;\n localeMatch: LocalePathMatch;\n parsed: ParsedPath;\n params: Readonly<Record<string, string>>;\n sourcePattern: CompiledPattern;\n canonicalPattern: CompiledPattern;\n isAlias: boolean;\n}\n\ntype RuntimeRouteMap = Readonly<\n Record<string, Readonly<Record<string, LocalizedRoutePath>>>\n>;\n\nconst invalidPath = (): Error =>\n new Error(\n \"Localized routes must be safe, same-origin absolute paths or configured locale origins.\",\n );\n\nconst validatePercentEscapes = (value: string): void => {\n if (MALFORMED_ESCAPE.test(value)) {\n throw invalidPath();\n }\n};\n\nconst validatePathname = (pathname: string): void => {\n if (\n !pathname.startsWith(\"/\") ||\n pathname.startsWith(\"//\") ||\n pathname.includes(\"//\") ||\n pathname.includes(\"\\\\\") ||\n CONTROL_CHARACTER.test(pathname) ||\n ENCODED_PATH_SEPARATOR.test(pathname)\n ) {\n throw invalidPath();\n }\n\n validatePercentEscapes(pathname);\n\n for (const segment of pathname.split(\"/\")) {\n let decoded: string;\n\n try {\n decoded = decodeURIComponent(segment);\n } catch {\n throw invalidPath();\n }\n\n const validateDecodedSegment = (value: string): void => {\n if (\n value === \".\" ||\n value === \"..\" ||\n value.includes(\"/\") ||\n value.includes(\"\\\\\") ||\n CONTROL_CHARACTER.test(value)\n ) {\n throw invalidPath();\n }\n };\n\n validateDecodedSegment(decoded);\n\n for (let depth = 0; depth < 8; depth += 1) {\n if (!/%[\\da-f]{2}/i.test(decoded)) {\n break;\n }\n\n let nested: string;\n\n try {\n nested = decodeURIComponent(decoded);\n } catch {\n break;\n }\n\n if (nested === decoded) {\n break;\n }\n\n validateDecodedSegment(nested);\n decoded = nested;\n }\n\n if (/%[\\da-f]{2}/i.test(decoded)) {\n throw invalidPath();\n }\n }\n};\n\nconst normalizeBasePath = (value: string | undefined): string => {\n if (value === undefined || value === \"\" || value === \"/\") {\n return \"\";\n }\n\n if (value.includes(\"?\") || value.includes(\"#\") || /\\/{2,}/.test(value)) {\n throw new Error(\"Localized routing basePath must be a safe pathname.\");\n }\n\n validatePathname(value);\n return value.replace(/\\/+$/, \"\");\n};\n\nconst stripBasePath = (pathname: string, basePath: string): string => {\n if (!basePath) {\n return pathname;\n }\n\n if (pathname === basePath) {\n return \"/\";\n }\n\n if (!pathname.startsWith(`${basePath}/`)) {\n throw new Error(\n `Localized route path must be within the configured basePath \"${basePath}\".`,\n );\n }\n\n return pathname.slice(basePath.length);\n};\n\nconst rawPathname = (input: string, isAbsoluteUrl: boolean): string => {\n if (!isAbsoluteUrl) {\n return input.split(/[?#]/, 1)[0] ?? \"/\";\n }\n\n const schemeEnd = input.indexOf(\"://\") + 3;\n const authorityEndOffset = input.slice(schemeEnd).search(/[/?#]/);\n const authorityEnd =\n authorityEndOffset === -1\n ? input.length\n : schemeEnd + authorityEndOffset;\n const suffix = input.slice(authorityEnd);\n\n if (!suffix.startsWith(\"/\")) {\n return \"/\";\n }\n\n return suffix.split(/[?#]/, 1)[0] ?? \"/\";\n};\n\nconst parseInternalPath = (\n path: string,\n originsByOrigin: ReadonlyMap<string, string>,\n): ParsedPath => {\n if (typeof path !== \"string\") {\n throw invalidPath();\n }\n\n const absoluteUrl = /^https?:\\/\\//i.test(path);\n\n if (\n CONTROL_CHARACTER.test(path) ||\n path.includes(\"\\\\\") ||\n (!absoluteUrl && (!path.startsWith(\"/\") || path.startsWith(\"//\")))\n ) {\n throw invalidPath();\n }\n\n validatePercentEscapes(path);\n validatePathname(rawPathname(path, absoluteUrl));\n\n let url: URL;\n\n try {\n url = new URL(path, INTERNAL_ORIGIN);\n } catch {\n throw invalidPath();\n }\n\n if (\n (url.protocol !== \"https:\" && url.protocol !== \"http:\") ||\n url.username ||\n url.password\n ) {\n throw invalidPath();\n }\n\n const originLocale = originsByOrigin.get(url.origin);\n\n if (\n absoluteUrl &&\n (url.origin === INTERNAL_ORIGIN || !originLocale)\n ) {\n if (originsByOrigin.size === 0) {\n throw invalidPath();\n }\n\n throw new Error(\"Localized routes must not contain an external origin.\");\n }\n\n return { url, originLocale };\n};\n\nconst normalizeOrigin = (value: string): string => {\n if (\n value.includes(\"\\\\\") ||\n !/^https?:\\/\\/[^/?#]+\\/?$/i.test(value)\n ) {\n throw new Error(\n \"Locale origins must be bare HTTP(S) origins without credentials, paths, queries, or hashes.\",\n );\n }\n\n let url: URL;\n\n try {\n url = new URL(value);\n } catch {\n throw new Error(`Invalid locale origin \"${value}\".`);\n }\n\n if (\n (url.protocol !== \"https:\" && url.protocol !== \"http:\") ||\n url.username ||\n url.password ||\n url.origin === INTERNAL_ORIGIN\n ) {\n throw new Error(`Invalid locale origin \"${value}\".`);\n }\n\n return url.origin;\n};\n\nconst compilePattern = (path: string): CompiledPattern => {\n if (\n path.includes(\"?\") ||\n path.includes(\"#\") ||\n CONTROL_CHARACTER.test(path)\n ) {\n throw new Error(\"Localized route patterns must contain only a pathname.\");\n }\n\n validatePathname(path);\n\n const parameterNames: string[] = [];\n const segments = path.split(\"/\").map((segment): RouteSegment => {\n const parameter = PARAMETER_SEGMENT.exec(segment);\n\n if (!parameter) {\n if (segment.startsWith(\":\")) {\n throw new Error(`Invalid route parameter segment \"${segment}\".`);\n }\n\n return {\n kind: \"literal\",\n value: decodeURIComponent(segment),\n };\n }\n\n const name = parameter[1];\n\n if (!name || parameterNames.includes(name)) {\n throw new Error(`Invalid or duplicate route parameter \"${name}\".`);\n }\n\n parameterNames.push(name);\n return { kind: \"parameter\", name };\n });\n\n return {\n path,\n segments,\n parameterNames: Object.freeze(parameterNames),\n };\n};\n\nconst patternKey = (pattern: CompiledPattern): string =>\n JSON.stringify(\n pattern.segments.map((segment) =>\n segment.kind === \"parameter\" ? \":\" : segment.value,\n ),\n );\n\nconst routePathParts = (\n value: LocalizedRoutePath,\n): { path: string; aliases: readonly string[] } => {\n if (typeof value === \"string\") {\n return { path: value, aliases: [] };\n }\n\n if (\n !value ||\n typeof value !== \"object\" ||\n typeof value.path !== \"string\" ||\n (value.aliases !== undefined &&\n (!Array.isArray(value.aliases) ||\n value.aliases.some((alias) => typeof alias !== \"string\")))\n ) {\n throw new Error(\"Localized route definitions must provide a path.\");\n }\n\n return {\n path: value.path,\n aliases: value.aliases ?? [],\n };\n};\n\nconst compileRoutes = (\n routes: RuntimeRouteMap,\n registry: LocaleRegistry,\n): ReadonlyMap<string, ReadonlyMap<string, CompiledRouteLocale>> => {\n const result = new Map<string, ReadonlyMap<string, CompiledRouteLocale>>();\n const pathsByLocale = new Map<string, Map<string, string>>();\n\n for (const definition of registry.locales) {\n pathsByLocale.set(definition.locale, new Map());\n }\n\n for (const [routeId, route] of Object.entries(routes)) {\n if (!routeId || !route || typeof route !== \"object\") {\n throw new Error(\"Localized route maps must use non-empty route IDs.\");\n }\n\n const locales = new Map<string, CompiledRouteLocale>();\n\n for (const [inputLocale, value] of Object.entries(route)) {\n const locale = registry.resolve(inputLocale);\n\n if (!locale) {\n throw new Error(\n `Route \"${routeId}\" uses unsupported locale \"${inputLocale}\".`,\n );\n }\n\n if (locales.has(locale)) {\n throw new Error(\n `Route \"${routeId}\" defines locale \"${locale}\" more than once.`,\n );\n }\n\n const { path, aliases } = routePathParts(value);\n const canonical = compilePattern(path);\n const compiledAliases = aliases.map(compilePattern);\n\n for (const alias of compiledAliases) {\n if (alias.parameterNames.length !== canonical.parameterNames.length) {\n throw new Error(\n `Route aliases for \"${routeId}\" must use the same number of parameters as the canonical path.`,\n );\n }\n }\n\n const patterns = [canonical, ...compiledAliases];\n const localePaths = pathsByLocale.get(locale);\n\n if (!localePaths) {\n throw new Error(`Unsupported route locale \"${locale}\".`);\n }\n\n for (const pattern of patterns) {\n const key = patternKey(pattern);\n const existing = localePaths.get(key);\n\n if (existing) {\n throw new Error(\n `Route path \"${pattern.path}\" is ambiguous between \"${existing}\" and \"${routeId}\" for locale \"${locale}\".`,\n );\n }\n\n localePaths.set(key, routeId);\n }\n\n locales.set(\n locale,\n Object.freeze({\n canonical,\n aliases: Object.freeze(compiledAliases),\n }),\n );\n }\n\n for (const definition of registry.locales) {\n if (!locales.has(definition.locale)) {\n throw new Error(\n `Route \"${routeId}\" is missing a path for locale \"${definition.locale}\".`,\n );\n }\n }\n\n const defaultRoute = locales.get(registry.defaultLocale);\n\n if (\n defaultRoute &&\n [...locales.values()].some(\n (localeRoute) =>\n localeRoute.canonical.parameterNames.length !==\n defaultRoute.canonical.parameterNames.length,\n )\n ) {\n throw new Error(\n `Route \"${routeId}\" must use the same number of parameters for every locale.`,\n );\n }\n\n result.set(routeId, locales);\n }\n\n return result;\n};\n\nconst localePathMatch = (\n parsed: ParsedPath,\n registry: LocaleRegistry,\n basePath: string,\n): LocalePathMatch => {\n const mountedPathname = stripBasePath(parsed.url.pathname, basePath);\n const segments = mountedPathname.split(\"/\");\n let pathLocale: string | undefined;\n\n try {\n pathLocale = segments[1]\n ? registry.resolve(decodeURIComponent(segments[1]))\n : undefined;\n } catch {\n pathLocale = undefined;\n }\n\n if (pathLocale) {\n segments.splice(1, 1);\n }\n\n if (\n pathLocale &&\n parsed.originLocale &&\n pathLocale !== parsed.originLocale\n ) {\n throw new Error(\n \"The locale path prefix does not match the configured locale origin.\",\n );\n }\n\n const pathname = segments.join(\"/\") || \"/\";\n\n if (pathname.startsWith(\"//\")) {\n throw invalidPath();\n }\n\n return {\n locale: pathLocale ?? parsed.originLocale ?? registry.defaultLocale,\n pathname: pathname.startsWith(\"/\") ? pathname : `/${pathname}`,\n search: parsed.url.search,\n hash: parsed.url.hash,\n matchedPrefix: pathLocale !== undefined,\n };\n};\n\nconst matchPattern = (\n pattern: CompiledPattern,\n pathname: string,\n): Readonly<Record<string, string>> | undefined => {\n const pathSegments = pathname.split(\"/\");\n\n if (pathSegments.length !== pattern.segments.length) {\n return undefined;\n }\n\n const params: Record<string, string> = {};\n\n for (const [index, segment] of pattern.segments.entries()) {\n const pathSegment = pathSegments[index];\n\n if (pathSegment === undefined) {\n return undefined;\n }\n\n let decoded: string;\n\n try {\n decoded = decodeURIComponent(pathSegment);\n } catch {\n return undefined;\n }\n\n if (segment.kind === \"literal\") {\n if (decoded !== segment.value) {\n return undefined;\n }\n } else {\n if (decoded.length === 0) {\n return undefined;\n }\n\n params[segment.name] = decoded;\n }\n }\n\n return Object.freeze(params);\n};\n\nconst remapParameters = (\n source: CompiledPattern,\n params: Readonly<Record<string, string>>,\n target: CompiledPattern,\n): Readonly<Record<string, string>> => {\n const result: Record<string, string> = {};\n\n for (const [index, name] of target.parameterNames.entries()) {\n const sourceName = source.parameterNames[index];\n const value = sourceName ? params[sourceName] : undefined;\n\n if (value === undefined) {\n throw new Error(`Missing route parameter \"${sourceName ?? name}\".`);\n }\n\n result[name] = value;\n }\n\n return result;\n};\n\nconst normalizeSuffix = (\n options: LocalizedRouteOutputOptions = {},\n): { search: string; hash: string } => {\n const search = options.search ?? \"\";\n const hash = options.hash ?? \"\";\n\n if (\n (search && !search.startsWith(\"?\")) ||\n search.includes(\"#\") ||\n (hash && !hash.startsWith(\"#\")) ||\n hash.includes(\"?\") ||\n CONTROL_CHARACTER.test(search) ||\n CONTROL_CHARACTER.test(hash)\n ) {\n throw new Error(\"Route search and hash values must be safe URL suffixes.\");\n }\n\n validatePercentEscapes(search);\n validatePercentEscapes(hash);\n return { search, hash };\n};\n\nconst fillPattern = (\n pattern: CompiledPattern,\n params: Readonly<Record<string, string | number>> = {},\n): string => {\n const expected = new Set(pattern.parameterNames);\n\n for (const key of Object.keys(params)) {\n if (!expected.has(key)) {\n throw new Error(`Unknown route parameter \"${key}\".`);\n }\n }\n\n const path = pattern.segments\n .map((segment) => {\n if (segment.kind === \"literal\") {\n return encodeURIComponent(segment.value).replace(/%2F/gi, \"/\");\n }\n\n const value = params[segment.name];\n\n if (\n (typeof value !== \"string\" && typeof value !== \"number\") ||\n !Number.isFinite(typeof value === \"number\" ? value : 0)\n ) {\n throw new Error(`Missing route parameter \"${segment.name}\".`);\n }\n\n const normalized = String(value);\n\n if (\n normalized.length === 0 ||\n normalized === \".\" ||\n normalized === \"..\" ||\n normalized.includes(\"/\") ||\n normalized.includes(\"\\\\\") ||\n CONTROL_CHARACTER.test(normalized)\n ) {\n throw new Error(`Unsafe value for route parameter \"${segment.name}\".`);\n }\n\n try {\n const encoded = encodeURIComponent(normalized);\n validatePathname(`/${encoded}`);\n return encoded;\n } catch {\n throw new Error(`Unsafe value for route parameter \"${segment.name}\".`);\n }\n })\n .join(\"/\");\n\n return path || \"/\";\n};\n\nexport const createLocalizedRouting = <\n const Routes extends LocalizedRouteMap = LocalizedRouteMap,\n>(\n options: LocalizedRoutingOptions<Routes>,\n): LocalizedRouting<Routes> => {\n const { registry } = options;\n const prefixDefaultLocale = options.prefixDefaultLocale ?? false;\n const basePath = normalizeBasePath(options.basePath);\n const originsByLocale = new Map<string, string>();\n const originsByOrigin = new Map<string, string>();\n\n for (const [inputLocale, originInput] of Object.entries(options.origins ?? {})) {\n const locale = registry.resolve(inputLocale);\n\n if (!locale) {\n throw new Error(`Unsupported origin locale \"${inputLocale}\".`);\n }\n\n if (originsByLocale.has(locale)) {\n throw new Error(`Origin for locale \"${locale}\" is defined more than once.`);\n }\n\n const origin = normalizeOrigin(originInput);\n const existingLocale = originsByOrigin.get(origin);\n\n if (existingLocale) {\n throw new Error(\n `Origin \"${origin}\" is shared by locales \"${existingLocale}\" and \"${locale}\".`,\n );\n }\n\n originsByLocale.set(locale, origin);\n originsByOrigin.set(origin, locale);\n }\n\n const routes = compileRoutes(\n (options.routes ?? {}) as RuntimeRouteMap,\n registry,\n );\n\n const parse = (path: string): ParsedPath =>\n parseInternalPath(path, originsByOrigin);\n\n const match = (path: string): LocalizedRouteMatch =>\n localePathMatch(parse(path), registry, basePath);\n\n const buildLocalizedPath = (\n pathname: string,\n search: string,\n hash: string,\n locale: string,\n ): string => {\n const origin = originsByLocale.get(locale);\n const shouldPrefix =\n !origin && (locale !== registry.defaultLocale || prefixDefaultLocale);\n const localizedPath =\n pathname === \"/\"\n ? shouldPrefix\n ? `/${locale}`\n : \"/\"\n : shouldPrefix\n ? `/${locale}${pathname}`\n : pathname;\n const rootedPath = basePath\n ? `${basePath}${localizedPath === \"/\" ? \"\" : localizedPath}`\n : localizedPath;\n const pathWithSuffix = `${rootedPath || \"/\"}${search}${hash}`;\n\n return origin ? `${origin}${pathWithSuffix}` : pathWithSuffix;\n };\n\n const getRouteMatch = (path: string): CompiledRouteMatch | undefined => {\n const parsed = parse(path);\n const localeMatch = localePathMatch(parsed, registry, basePath);\n\n for (const [routeId, routeLocales] of routes) {\n const route = routeLocales.get(localeMatch.locale);\n\n if (!route) {\n continue;\n }\n\n const canonicalParams = matchPattern(\n route.canonical,\n localeMatch.pathname,\n );\n\n if (canonicalParams) {\n return {\n routeId,\n localeMatch,\n parsed,\n params: canonicalParams,\n sourcePattern: route.canonical,\n canonicalPattern: route.canonical,\n isAlias: false,\n };\n }\n\n for (const alias of route.aliases) {\n const params = matchPattern(alias, localeMatch.pathname);\n\n if (params) {\n return {\n routeId,\n localeMatch,\n parsed,\n params,\n sourcePattern: alias,\n canonicalPattern: route.canonical,\n isAlias: true,\n };\n }\n }\n }\n\n return undefined;\n };\n\n const localizeRoute = <\n RouteId extends RouteIds<Routes>,\n >(\n routeId: RouteId,\n inputLocale: RouteLocales<Routes, RouteId>,\n params: Readonly<Record<string, string | number>> = {},\n outputOptions: LocalizedRouteOutputOptions = {},\n ): string => {\n const locale = registry.resolve(inputLocale);\n\n if (!locale) {\n throw new Error(`Unsupported locale \"${inputLocale}\".`);\n }\n\n const route = routes.get(routeId);\n const localeRoute = route?.get(locale);\n\n if (!localeRoute) {\n throw new Error(\n `Route \"${routeId}\" has no path for locale \"${locale}\".`,\n );\n }\n\n const suffix = normalizeSuffix(outputOptions);\n const pathname = fillPattern(localeRoute.canonical, params);\n\n return buildLocalizedPath(pathname, suffix.search, suffix.hash, locale);\n };\n\n const localize = (path: string, inputLocale: string): string => {\n const locale = registry.resolve(inputLocale);\n\n if (!locale) {\n throw new Error(`Unsupported locale \"${inputLocale}\".`);\n }\n\n const routeMatch = getRouteMatch(path);\n\n if (routeMatch) {\n const target = routes.get(routeMatch.routeId)?.get(locale);\n\n if (!target) {\n throw new Error(\n `Route \"${routeMatch.routeId}\" has no path for locale \"${locale}\".`,\n );\n }\n\n const params = remapParameters(\n routeMatch.sourcePattern,\n routeMatch.params,\n target.canonical,\n );\n\n return localizeRoute(\n routeMatch.routeId as RouteIds<Routes>,\n locale as RouteLocales<Routes, RouteIds<Routes>>,\n params,\n {\n search: routeMatch.localeMatch.search,\n hash: routeMatch.localeMatch.hash,\n },\n );\n }\n\n const current = match(path);\n return buildLocalizedPath(\n current.pathname,\n current.search,\n current.hash,\n locale,\n );\n };\n\n const alternatePaths = (\n path: string,\n ): Readonly<Record<string, string>> => {\n const result: Record<string, string> = {};\n\n for (const locale of registry.locales) {\n result[locale.locale] = localize(path, locale.locale);\n }\n\n return result;\n };\n\n const matchRoute = (\n path: string,\n ): MatchedLocalizedRoute<RouteIds<Routes>> | undefined => {\n const routeMatch = getRouteMatch(path);\n\n if (!routeMatch) {\n return undefined;\n }\n\n const canonicalParams = remapParameters(\n routeMatch.sourcePattern,\n routeMatch.params,\n routeMatch.canonicalPattern,\n );\n const canonicalPath = buildLocalizedPath(\n fillPattern(routeMatch.canonicalPattern, canonicalParams),\n routeMatch.localeMatch.search,\n routeMatch.localeMatch.hash,\n routeMatch.localeMatch.locale,\n );\n const originalPath = routeMatch.parsed.url.origin === INTERNAL_ORIGIN\n ? `${routeMatch.parsed.url.pathname}${routeMatch.parsed.url.search}${routeMatch.parsed.url.hash}`\n : `${routeMatch.parsed.url.origin}${routeMatch.parsed.url.pathname}${routeMatch.parsed.url.search}${routeMatch.parsed.url.hash}`;\n const redirectTo =\n routeMatch.isAlias || canonicalPath !== originalPath\n ? canonicalPath\n : undefined;\n\n return {\n ...routeMatch.localeMatch,\n routeId: routeMatch.routeId as RouteIds<Routes>,\n params: routeMatch.params,\n isAlias: routeMatch.isAlias,\n canonicalPath,\n ...(redirectTo ? { redirectTo } : {}),\n };\n };\n\n const alternateRoutePaths = <RouteId extends RouteIds<Routes>>(\n routeId: RouteId,\n params: Readonly<Record<string, string | number>> = {},\n outputOptions: LocalizedRouteOutputOptions = {},\n ): Readonly<Record<string, string>> => {\n const result: Record<string, string> = {};\n const sourceRoute = routes.get(routeId)?.get(registry.defaultLocale);\n\n for (const locale of registry.locales) {\n const targetRoute = routes.get(routeId)?.get(locale.locale);\n\n if (!sourceRoute || !targetRoute) {\n throw new Error(\n `Route \"${routeId}\" has no path for locale \"${locale.locale}\".`,\n );\n }\n\n const sourceParams: Record<string, string> = {};\n\n for (const [key, value] of Object.entries(params)) {\n if (!sourceRoute.canonical.parameterNames.includes(key)) {\n throw new Error(`Unknown route parameter \"${key}\".`);\n }\n\n if (typeof value === \"number\" && !Number.isFinite(value)) {\n throw new Error(`Invalid value for route parameter \"${key}\".`);\n }\n\n sourceParams[key] = String(value);\n }\n\n const localizedParams = remapParameters(\n sourceRoute.canonical,\n sourceParams,\n targetRoute.canonical,\n );\n\n result[locale.locale] = localizeRoute(\n routeId,\n locale.locale as RouteLocales<Routes, RouteId>,\n localizedParams,\n outputOptions,\n );\n }\n\n return Object.freeze(result);\n };\n\n return Object.freeze({\n match,\n localize,\n alternatePaths,\n matchRoute,\n localizeRoute,\n alternateRoutePaths,\n });\n};\n"],"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