@i18n-micro/route-strategy 1.1.17 → 1.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,871 +1,573 @@
1
- import w from "node:path";
2
- import { existsSync as K, mkdirSync as I, writeFileSync as U } from "node:fs";
3
- import { isPrefixAndDefaultStrategy as O, isPrefixStrategy as D } from "@i18n-micro/core";
4
- const $ = (l) => l.map((e) => ({ ...e })), q = (l) => !!(l.redirect && !l.file), j = (l, e, t, a = "localized-") => t ? `${a}${l}-${e}` : `${a}${l}`, b = (l, e) => l ?? (e ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, ""), H = (l, e, t) => t && l !== e.code, J = (l, e) => (typeof l == "string" ? l : l.code) === e.code, Q = [
5
- /^\/sitemap.*\.xml$/,
6
- /^\/sitemap\.xml$/,
7
- /^\/robots\.txt$/,
8
- /^\/favicon\.ico$/,
9
- /^\/apple-touch-icon.*\.png$/,
10
- /^\/manifest\.json$/,
11
- /^\/sw\.js$/,
12
- /^\/workbox-.*\.js$/,
13
- /\.(xml|txt|ico|json|js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/
14
- ];
15
- function M(l, e) {
16
- if (/(?:^|\/)__[^/]+/.test(l))
17
- return !0;
18
- for (const t of Q)
19
- if (t.test(l))
20
- return !0;
21
- if (e) {
22
- for (const t of e)
23
- if (typeof t == "string") {
24
- if (t.includes("*") || t.includes("?")) {
25
- if (new RegExp(t.replace(/\*/g, ".*").replace(/\?/g, ".")).test(l)) return !0;
26
- } else if (l === t || l.startsWith(t))
27
- return !0;
28
- } else if (t instanceof RegExp && t.test(l))
29
- return !0;
30
- }
31
- return !1;
1
+ import { isInternalPath as e } from "@i18n-micro/utils/app-path";
2
+ import t from "node:path";
3
+ import { existsSync as n, mkdirSync as r, writeFileSync as i } from "node:fs";
4
+ import { isPrefixAndDefaultStrategy as a, isPrefixStrategy as o } from "@i18n-micro/core";
5
+ //#region src/utils/common.ts
6
+ var s = (e) => e.map((e) => ({ ...e })), c = (e) => !(!e.redirect || e.file), l = (e, t, n, r = "localized-") => n ? `${r}${e}-${t}` : `${r}${e}`, u = (e, t) => e ?? (t ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, ""), d = (e, t, n) => n && e !== t.code, f = (e, t) => (typeof e == "string" ? e : e.code) === t.code;
7
+ //#endregion
8
+ //#region src/utils/locales.ts
9
+ function p(e, t) {
10
+ let n = e.reduce((e, t) => {
11
+ let n = e.find((e) => e.code === t.code);
12
+ return n ? Object.assign(n, t) : e.push(t), e;
13
+ }, []).filter((e) => !e.disabled);
14
+ return {
15
+ locales: n,
16
+ defaultLocale: n.find((e) => e.code === t) ?? { code: t }
17
+ };
32
18
  }
33
- function X(l, e) {
34
- const t = l.reduce((o, s) => {
35
- const r = o.find((i) => i.code === s.code);
36
- return r ? Object.assign(r, s) : o.push(s), o;
37
- }, []).filter((o) => !o.disabled), a = t.find((o) => o.code === e) ?? { code: e };
38
- return { locales: t, defaultLocale: a };
19
+ //#endregion
20
+ //#region src/utils/path.ts
21
+ function m(e) {
22
+ return e.split("/").map((e) => e.startsWith("[...") && e.endsWith("]") ? `:${e.substring(4, e.length - 1)}(.*)*` : e.startsWith("[") && e.endsWith("]") ? `:${e.substring(1, e.length - 1)}` : e.replace(/:([^()/]+)\(\)/g, ":$1")).join("/");
39
23
  }
40
- function N(l) {
41
- return l.split("/").map((e) => e.startsWith("[...") && e.endsWith("]") ? `:${e.substring(4, e.length - 1)}(.*)*` : e.startsWith("[") && e.endsWith("]") ? `:${e.substring(1, e.length - 1)}` : e).join("/");
24
+ var h = (e) => {
25
+ if (!e) return "";
26
+ let n = t.posix.normalize(e).replace(/\/+$/, "");
27
+ return n === "." ? "" : n;
28
+ }, g = (e) => e.startsWith("/") ? e.slice(1) : e;
29
+ function _(...e) {
30
+ return t.posix.join(...e);
42
31
  }
43
- const R = (l) => {
44
- if (!l)
45
- return "";
46
- const e = w.posix.normalize(l).replace(/\/+$/, "");
47
- return e === "." ? "" : e;
48
- }, g = (l) => l.startsWith("/") ? l.slice(1) : l;
49
- function G(...l) {
50
- return w.posix.join(...l);
32
+ function v(e) {
33
+ if (e !== void 0) return e.startsWith("/") && e.endsWith("/") ? e?.slice(1, -1) : e;
51
34
  }
52
- function Y(l) {
53
- if (!(typeof l > "u"))
54
- return l.startsWith("/") && l.endsWith("/") ? l?.slice(1, -1) : l;
35
+ function y(e) {
36
+ return e;
55
37
  }
56
- function Z(l) {
57
- return !l || !/[\u0080-\uFFFF]/.test(l) ? l : l.split("/").map((e) => !e || e.startsWith(":") || !/[\u0080-\uFFFF]/.test(e) ? e : encodeURI(e)).join("/");
38
+ function b(e) {
39
+ return !e || !/[\u0080-\uFFFF]/.test(e) ? e : e.split("/").map((e) => !e || e.startsWith(":") || !/[\u0080-\uFFFF]/.test(e) ? e : encodeURI(e)).join("/");
58
40
  }
59
- function ee(l) {
60
- const e = Z(l);
61
- return e !== l ? [e] : [];
41
+ function x(e) {
42
+ let t = b(e);
43
+ return t === e ? [] : [t];
62
44
  }
63
- function x(l, e, t) {
64
- const a = Y(t?.toString()), o = a || (Array.isArray(l) ? l.join("|") : l), s = e;
65
- return R(w.posix.join("/", `:locale(${o})`, s));
45
+ function S(e, n, r) {
46
+ let i = v(r?.toString()) || (Array.isArray(e) ? e.join("|") : e), a = y(n);
47
+ return h(t.posix.join("/", `:locale(${i})`, a));
66
48
  }
67
- function te(l) {
68
- const e = l;
69
- return R(e);
49
+ function C(e) {
50
+ return h(y(e));
70
51
  }
71
- const ae = (l, e) => l ?? (e ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, "");
72
- function F(l) {
73
- return g(l) || "/";
52
+ //#endregion
53
+ //#region src/core/localized-paths.ts
54
+ var w = (e, t) => e ?? (t ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, "");
55
+ function T(e) {
56
+ return g(e) || "/";
74
57
  }
75
- function _(l, e, t, a = "") {
76
- const o = {};
77
- return l.forEach((s) => {
78
- const r = ae(s.name, s.path), i = R(G(a, s.path ?? "")), n = F(i), f = N(i), c = e[n] || e[f] || e[r];
79
- if (c)
80
- typeof c == "object" && (o[n] = c);
81
- else {
82
- const h = t[r];
83
- h && typeof h == "object" && !Array.isArray(h) && (o[n] = h);
84
- }
85
- if (s.children?.length) {
86
- const h = R(G(a, s.path ?? ""));
87
- Object.assign(o, _(s.children, e, t, h));
88
- }
89
- }), o;
58
+ function E(e, t, n, r = "") {
59
+ let i = {};
60
+ return e.forEach((e) => {
61
+ let a = w(e.name, e.path), o = h(_(r, e.path ?? "")), s = T(o), c = m(o), l = g(c) || "/", u = t[s] || t[c] || t[l] || t[a];
62
+ if (u) typeof u == "object" && (i[s] = u);
63
+ else {
64
+ let e = n[a];
65
+ e && typeof e == "object" && !Array.isArray(e) && (i[s] = e);
66
+ }
67
+ if (e.children?.length) {
68
+ let a = h(_(r, e.path ?? ""));
69
+ Object.assign(i, E(e.children, t, n, a));
70
+ }
71
+ }), i;
90
72
  }
91
- function S(l, e, t) {
92
- const a = N(e), o = F(e);
93
- return l[t] === !1 || l[a] === !1 || l[o] === !1 || l[g(a)] === !1;
73
+ //#endregion
74
+ //#region src/core/localization-disabled.ts
75
+ function D(e, t, n) {
76
+ let r = m(t), i = T(t);
77
+ return e[n] === !1 || e[r] === !1 || e[i] === !1 || e[g(r)] === !1;
94
78
  }
95
- function Pe(l, e, t, a) {
96
- if (!l || Object.keys(l).length === 0)
97
- return !0;
98
- const o = N(t), s = g(o) || "/", r = s === "/" ? "/" : s, i = l[o] ?? l[t] ?? l[s] ?? l[r] ?? (s !== "/" ? l[`/${s}`] : void 0);
99
- if (!Array.isArray(i) || i.length === 0)
100
- return !0;
101
- const n = e.map((c) => c.code), f = i.filter((c) => n.includes(c));
102
- return f.length === 0 ? !0 : f.includes(a);
79
+ //#endregion
80
+ //#region src/locale-route-access.ts
81
+ function O(e, t, n, r) {
82
+ if (!e || Object.keys(e).length === 0) return !0;
83
+ let i = m(n), a = g(i) || "/", o = a === "/" ? "/" : a, s = e[i] ?? e[n] ?? e[a] ?? e[o] ?? (a === "/" ? void 0 : e[`/${a}`]);
84
+ if (!Array.isArray(s) || s.length === 0) return !0;
85
+ let c = t.map((e) => e.code), l = s.filter((e) => c.includes(e));
86
+ return l.length === 0 || l.includes(r);
103
87
  }
104
- function se(l) {
105
- const e = {};
106
- if (!l) return e;
107
- for (const t in l) {
108
- const a = N(t), o = l[t];
109
- if (typeof o == "object") {
110
- const s = {};
111
- for (const r in o) {
112
- const i = o[r];
113
- i && (s[r] = N(i));
114
- }
115
- e[a] = s;
116
- } else
117
- e[a] = o;
118
- }
119
- return e;
88
+ //#endregion
89
+ //#region src/core/context.ts
90
+ function k(e) {
91
+ let t = {};
92
+ if (!e) return t;
93
+ for (let n in e) {
94
+ let r = m(n), i = e[n];
95
+ if (typeof i == "object") {
96
+ let e = {};
97
+ for (let t in i) {
98
+ let n = i[t];
99
+ n && (e[t] = m(n));
100
+ }
101
+ t[r] = e;
102
+ } else t[r] = i;
103
+ }
104
+ return t;
120
105
  }
121
- class oe {
122
- constructor(e) {
123
- this.locales = e.locales, this.defaultLocale = this.findLocaleByCode(e.locales, e.defaultLocaleCode) ?? { code: e.defaultLocaleCode }, this.strategy = e.strategy, this.globalLocaleRoutes = se(e.globalLocaleRoutes ?? {}), this.filesLocaleRoutes = e.filesLocaleRoutes ?? {}, this.routeLocales = e.routeLocales ?? {}, this.localizedPaths = _(e.pages, this.globalLocaleRoutes, this.filesLocaleRoutes), this.activeLocaleCodes = this.locales.filter((t) => t.code !== this.defaultLocale.code || O(this.strategy) || D(this.strategy)).map((t) => t.code), this.excludePatterns = e.excludePatterns, this.customRegex = e.customRegex, this.noPrefixRedirect = e.noPrefixRedirect ?? !1, this.localizedRouteNamePrefix = e.localizedRouteNamePrefix ?? "localized-", this.fallbackRedirectComponentPath = e.fallbackRedirectComponentPath, this.rawGlobalLocaleRoutes = e.rawGlobalLocaleRoutes;
124
- }
125
- findLocaleByCode(e, t) {
126
- return e.find((a) => a.code === t);
127
- }
128
- /**
129
- * Returns the list of locale codes allowed for a page (respecting routeLocales).
130
- */
131
- getAllowedLocales(e, t) {
132
- const a = this.routeLocales[e] ?? this.routeLocales[t];
133
- return a?.length ? a.filter((o) => this.locales.some((s) => s.code === o)) : this.locales.map((o) => o.code);
134
- }
135
- /**
136
- * Returns a custom path for a given locale by original page path, if any.
137
- */
138
- getCustomPath(e, t) {
139
- const a = F(e);
140
- return this.localizedPaths[a]?.[t];
141
- }
142
- /**
143
- * Returns a map of custom paths (locale → path) for a page by path key or name.
144
- */
145
- getCustomPathsForPage(e, t) {
146
- const a = F(e);
147
- return this.localizedPaths[a] ?? this.localizedPaths[t];
148
- }
149
- hasLocaleRestrictions(e, t) {
150
- return !!(this.routeLocales[e] ?? this.routeLocales[t]);
151
- }
152
- filterLocaleCodesWithoutCustomPaths(e) {
153
- const t = F(e);
154
- return this.activeLocaleCodes.filter((a) => !this.localizedPaths[t]?.[a]);
155
- }
156
- }
157
- function y(l, e) {
158
- const t = (e ?? "").trim();
159
- return t.startsWith("/") ? R(t) : R(w.posix.join(l || "", t));
160
- }
161
- function z(l, e) {
162
- const { path: t, name: a, children: o, meta: s, alias: r } = e, i = {
163
- ...l,
164
- path: t
165
- };
166
- return a !== void 0 && (i.name = a), o !== void 0 && (i.children = o), s !== void 0 && (i.meta = { ...l.meta, ...s }), r !== void 0 ? (i.alias = r, i.meta = { ...i.meta, alias: r }) : "alias" in e && (i.alias = void 0, i.meta = { ...i.meta, alias: void 0 }), i;
167
- }
168
- function le(l) {
169
- const e = l.alias, t = l.meta?.alias, a = e ?? t;
170
- return Array.isArray(a) ? a : [];
171
- }
172
- function W(l, e, t, a = "localized-") {
173
- const o = le(l);
174
- if (!o.length) return [];
175
- const s = [];
176
- for (const r of o) {
177
- const i = x(e, r, t);
178
- s.push(
179
- z(l, {
180
- path: i,
181
- name: `${a}${l.name ?? ""}`,
182
- alias: void 0,
183
- meta: { alias: void 0 },
184
- // Important: if the source page has children, the alias route
185
- // must keep the same children tree so that /alias/child does not 404.
186
- // createRoute takes care of cloning/adjusting children correctly.
187
- children: l.children
188
- })
189
- );
190
- }
191
- return s;
192
- }
193
- class k {
194
- processPage(e, t) {
195
- if (e.path === void 0)
196
- throw new Error("page.path is required");
197
- if (q(e))
198
- return [e];
199
- if (e.path && M(e.path, t.excludePatterns))
200
- return [e];
201
- const a = e.path ?? "", o = b(e.name, e.path);
202
- return S(t.globalLocaleRoutes, a, o) ? [e] : this.generateVariants(e, t);
203
- }
204
- postProcess(e, t) {
205
- return e;
206
- }
207
- /**
208
- * Recursive localization for children: for a given locale, builds:
209
- * - parentOriginalPath used for Context lookups,
210
- * - parentLocalizedPath used for the final path,
211
- * and returns an array of localized child routes.
212
- */
213
- localizeChildren(e, t, a, o, s, r) {
214
- return e.flatMap((i) => this.localizeChild(i, t, a, o, s, r));
215
- }
216
- /**
217
- * Variant for a single route with :locale(locale1|locale2) — without custom paths.
218
- * Returns a single child route with a relative path and recursively localized children.
219
- */
220
- localizeChildrenAllLocales(e, t, a, o, s) {
221
- return e.flatMap((r) => this.localizeChildAllLocales(r, t, a, o, s));
222
- }
223
- localizeChildAllLocales(e, t, a, o, s) {
224
- const r = y(a, e.path ?? ""), i = b(e.name, e.path);
225
- if (S(s.globalLocaleRoutes, r, i))
226
- return [e];
227
- const n = y(t, e.path ?? ""), f = F(n), c = s.localizedPaths[f];
228
- if (c)
229
- return o.flatMap((P) => {
230
- const p = c[P] ?? y(t, e.path ?? "");
231
- return this.localizeChild(e, p, a, P, s, !0);
232
- });
233
- const h = R(e.path ?? ""), u = g(h), m = this.localizeChildrenAllLocales($(e.children ?? []), n, r, o, s), d = `${s.localizedRouteNamePrefix}${e.name ?? ""}`;
234
- return [
235
- z(e, {
236
- path: u,
237
- name: d,
238
- children: m
239
- })
240
- ];
241
- }
242
- localizeChild(e, t, a, o, s, r) {
243
- const i = y(a, e.path ?? ""), n = b(e.name, e.path);
244
- if (S(s.globalLocaleRoutes, i, n))
245
- return [e];
246
- const f = s.getCustomPath(i, o), c = g(R(f || (e.path ?? ""))), h = f ?? y(t, e.path ?? ""), u = this.localizeChildren($(e.children ?? []), h, i, o, s, r), m = b(e.name, e.path), d = `${s.localizedRouteNamePrefix}${m}-${o}`;
247
- return [
248
- z(e, {
249
- path: c,
250
- name: d,
251
- children: u
252
- })
253
- ];
254
- }
255
- /**
256
- * Shared helper for strategies that build prefix-based paths (:locale(...)):
257
- * - for custom paths, decides whether a prefix is required,
258
- * - for regular paths, always uses buildFullPath.
259
- *
260
- * The logic matches what used to be duplicated in each strategy's buildRoutePath.
261
- */
262
- buildRoutePathForLocales(e, t, a, o, s, r, i) {
263
- if (o) {
264
- const n = e.includes(i);
265
- return r || !n ? x(e, a, s) : R(a);
266
- }
267
- return x(e, t, s);
268
- }
269
- }
270
- class ie extends k {
271
- generateVariants(e, t) {
272
- const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [];
273
- if (n.push(e), r)
274
- for (const f of s) {
275
- const c = r[f];
276
- if (!c) continue;
277
- const h = R(c), u = R(a);
278
- if (h === u)
279
- continue;
280
- const m = te(c), d = j(o, f, !0), P = this.localizeChildrenForNoPrefix(i, h, a, a, f, t, 1);
281
- n.push(
282
- z(e, {
283
- path: m,
284
- name: d,
285
- children: P,
286
- alias: [],
287
- meta: { alias: [] }
288
- })
289
- ), t.noPrefixRedirect && f === t.defaultLocale.code && h !== u && (e.redirect = h);
290
- }
291
- return n.push(...W(e, s, t.customRegex, t.localizedRouteNamePrefix)), n;
292
- }
293
- /**
294
- * Localizes the children tree for the no_prefix strategy.
295
- * Mirrors the behavior of the legacy RouteGenerator:
296
- * - on the first level, custom paths (globalLocaleRoutes/filesLocaleRoutes) are applied;
297
- * - on deeper levels, path stays as a segment (item, detail, etc.).
298
- */
299
- localizeChildrenForNoPrefix(e, t, a, o, s, r, i) {
300
- return e.map((n) => {
301
- const f = y(a, n.path ?? "");
302
- let c, h;
303
- if (i === 1) {
304
- const P = r.getCustomPath(f, s);
305
- if (P) {
306
- const p = R(P);
307
- c = g(p), h = p;
308
- } else {
309
- const p = R(n.path ?? "");
310
- c = g(p), h = y(t, n.path ?? "");
311
- }
312
- } else {
313
- const P = R(n.path ?? "");
314
- c = g(P), h = y(t, n.path ?? "");
315
- }
316
- const u = this.localizeChildrenForNoPrefix(
317
- $(n.children ?? []),
318
- h,
319
- f,
320
- o,
321
- s,
322
- r,
323
- i + 1
324
- ), m = b(n.name, n.path), d = j(m, s, !0);
325
- return z(n, {
326
- path: c,
327
- name: d,
328
- children: u
329
- });
330
- });
331
- }
332
- }
333
- function re(l) {
334
- const e = l.alias ?? l.meta?.alias;
335
- return Array.isArray(e) ? e : [];
106
+ var A = class {
107
+ constructor(e) {
108
+ this.locales = e.locales, this.defaultLocale = this.findLocaleByCode(e.locales, e.defaultLocaleCode) ?? { code: e.defaultLocaleCode }, this.strategy = e.strategy, this.globalLocaleRoutes = k(e.globalLocaleRoutes ?? {}), this.filesLocaleRoutes = e.filesLocaleRoutes ?? {}, this.routeLocales = e.routeLocales ?? {}, this.localizedPaths = E(e.pages, this.globalLocaleRoutes, this.filesLocaleRoutes), this.activeLocaleCodes = this.locales.filter((e) => e.code !== this.defaultLocale.code || a(this.strategy) || o(this.strategy)).map((e) => e.code), this.excludePatterns = e.excludePatterns, this.customRegex = e.customRegex, this.noPrefixRedirect = e.noPrefixRedirect ?? !1, this.localizedRouteNamePrefix = e.localizedRouteNamePrefix ?? "localized-", this.fallbackRedirectComponentPath = e.fallbackRedirectComponentPath, this.rawGlobalLocaleRoutes = e.rawGlobalLocaleRoutes;
109
+ }
110
+ findLocaleByCode(e, t) {
111
+ return e.find((e) => e.code === t);
112
+ }
113
+ getAllowedLocales(e, t) {
114
+ let n = this.routeLocales[e] ?? this.routeLocales[t];
115
+ return n?.length ? n.filter((e) => this.locales.some((t) => t.code === e)) : this.locales.map((e) => e.code);
116
+ }
117
+ getCustomPath(e, t) {
118
+ let n = T(e);
119
+ return this.localizedPaths[n]?.[t];
120
+ }
121
+ getCustomPathsForPage(e, t) {
122
+ let n = T(e);
123
+ return this.localizedPaths[n] ?? this.localizedPaths[t];
124
+ }
125
+ hasLocaleRestrictions(e, t) {
126
+ return !!(this.routeLocales[e] ?? this.routeLocales[t]);
127
+ }
128
+ filterLocaleCodesWithoutCustomPaths(e) {
129
+ let t = T(e);
130
+ return this.activeLocaleCodes.filter((e) => !this.localizedPaths[t]?.[e]);
131
+ }
132
+ };
133
+ //#endregion
134
+ //#region src/core/builder.ts
135
+ function j(e, n) {
136
+ let r = (n ?? "").trim();
137
+ return r.startsWith("/") ? h(r) : h(t.posix.join(e || "", r));
336
138
  }
337
- class ne extends k {
338
- generateVariants(e, t) {
339
- const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [];
340
- if (r)
341
- for (const c of s) {
342
- const h = r[c], u = h ? R(h) : a, m = x(c, u, t.customRegex), d = j(o, c, !!h, t.localizedRouteNamePrefix), P = h ?? a, p = this.localizeChildren(i, P, a, c, t, !0), L = ee(m);
343
- n.push(
344
- z(e, {
345
- path: m,
346
- name: d,
347
- children: p,
348
- alias: L.length ? L : void 0,
349
- meta: { alias: L.length ? L : [] }
350
- })
351
- );
352
- }
353
- else {
354
- const c = x(s, a, t.customRegex), h = j(o, s[0], !1, t.localizedRouteNamePrefix), u = this.localizeChildrenAllLocales(i, a, a, s, t);
355
- n.push(
356
- z(e, {
357
- path: c,
358
- name: h,
359
- children: u,
360
- alias: [],
361
- meta: { alias: [] }
362
- })
363
- );
364
- }
365
- const f = re(e);
366
- if (f.length)
367
- for (const c of f) {
368
- const h = x(s, c, t.customRegex);
369
- n.push(
370
- z(e, {
371
- path: h,
372
- name: `${t.localizedRouteNamePrefix}${e.name ?? ""}`,
373
- alias: void 0,
374
- meta: { alias: void 0 }
375
- })
376
- );
377
- }
378
- return n;
379
- }
380
- postProcess(e, t) {
381
- const a = e.filter((s) => {
382
- if (s.name === "index" && s.path === "/") return !1;
383
- const r = s.path ?? "";
384
- return !!(r && M(r, t.excludePatterns) || S(t.globalLocaleRoutes, r, s.name ?? "") || /^\/:locale/.test(r) || r === "/");
385
- }), o = t.defaultLocale.code;
386
- for (const [s, r] of Object.entries(t.globalLocaleRoutes)) {
387
- if (r === !1 || typeof r != "object") continue;
388
- const i = r[o];
389
- if (!i) continue;
390
- const n = s.startsWith("/") ? s : `/${s}`, f = `/${o}${i.startsWith("/") ? i : `/${i}`}`;
391
- n !== f && a.push({
392
- path: n,
393
- name: `redirect-${s.replace(/\//g, "-")}`,
394
- redirect: f
395
- });
396
- }
397
- return t.fallbackRedirectComponentPath && a.push({
398
- path: "/:pathMatch(.*)*",
399
- name: "custom-fallback-route",
400
- file: t.fallbackRedirectComponentPath,
401
- meta: {
402
- globalLocaleRoutes: t.rawGlobalLocaleRoutes ?? t.globalLocaleRoutes
403
- }
404
- }), a;
405
- }
139
+ function M(e, t) {
140
+ let { path: n, name: r, children: i, meta: a, alias: o } = t, s = {
141
+ ...e,
142
+ path: n
143
+ };
144
+ return r !== void 0 && (s.name = r), i !== void 0 && (s.children = i), a !== void 0 && (s.meta = {
145
+ ...e.meta,
146
+ ...a
147
+ }), o === void 0 ? "alias" in t && (s.alias = void 0, s.meta = {
148
+ ...s.meta,
149
+ alias: void 0
150
+ }) : (s.alias = o, s.meta = {
151
+ ...s.meta,
152
+ alias: o
153
+ }), s;
406
154
  }
407
- class ce extends k {
408
- generateVariants(e, t) {
409
- const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [], f = t.defaultLocale.code;
410
- n.push(e);
411
- const c = t.locales.filter((u) => s.includes(u.code));
412
- if (c.length > 0)
413
- if (r)
414
- for (const u of c) {
415
- const m = r[u.code];
416
- if (m)
417
- if (u.code === f) {
418
- const d = this.createLocalizedRoute(
419
- e,
420
- [u.code],
421
- i,
422
- !0,
423
- m,
424
- t.customRegex,
425
- !1,
426
- u.code,
427
- a,
428
- t
429
- );
430
- d && n.push(d);
431
- const P = this.createLocalizedRoute(
432
- e,
433
- [u.code],
434
- i,
435
- !0,
436
- m,
437
- t.customRegex,
438
- !0,
439
- u.code,
440
- a,
441
- t
442
- );
443
- P && n.push(P);
444
- } else {
445
- const d = this.createLocalizedRoute(
446
- e,
447
- [u.code],
448
- i,
449
- !0,
450
- m,
451
- t.customRegex,
452
- !1,
453
- u.code,
454
- a,
455
- t
456
- );
457
- d && n.push(d);
458
- }
459
- else {
460
- const d = this.createLocalizedRoute(
461
- e,
462
- [u.code],
463
- i,
464
- !1,
465
- "",
466
- t.customRegex,
467
- !1,
468
- u.code,
469
- a,
470
- t
471
- );
472
- d && n.push(d);
473
- }
474
- }
475
- else {
476
- const u = c.map((d) => d.code), m = this.createLocalizedRoute(
477
- e,
478
- u,
479
- i,
480
- !1,
481
- "",
482
- t.customRegex,
483
- !1,
484
- !0,
485
- a,
486
- t
487
- );
488
- m && n.push(m);
489
- }
490
- const h = W(e, s, t.customRegex, t.localizedRouteNamePrefix);
491
- return h.length && n.push(...h), n;
492
- }
493
- postProcess(e, t) {
494
- const a = [], o = [];
495
- for (const s of e) {
496
- const r = s.name ?? "";
497
- typeof r == "string" && r.startsWith(t.localizedRouteNamePrefix) ? o.push(s) : a.push(s);
498
- }
499
- return [...a, ...o];
500
- }
501
- createLocalizedRoute(e, t, a, o, s = "", r, i = !1, n = !1, f, c) {
502
- const h = this.buildRoutePathForLocales(
503
- t,
504
- e.path ?? "",
505
- s,
506
- o,
507
- r,
508
- i,
509
- c.defaultLocale.code
510
- );
511
- if (!h || !(o && s) && h === e.path || t.length === 0) return null;
512
- const m = t[0];
513
- if (!m) return null;
514
- const d = f ?? e.path ?? "", P = j(
515
- b(e.name ?? "", d),
516
- m,
517
- o,
518
- c.localizedRouteNamePrefix
519
- ), p = i || m !== c.defaultLocale.code, L = t.length === 1 ? this.localizeChildren(a, h, d, m, c, p) : this.localizeChildrenAllLocales(a, h, d, t, c);
520
- return z(e, {
521
- path: h,
522
- name: P,
523
- children: L,
524
- alias: [],
525
- meta: { alias: [] }
526
- });
527
- }
155
+ //#endregion
156
+ //#region src/core/alias.ts
157
+ function N(e) {
158
+ let t = e.alias, n = e.meta?.alias, r = t ?? n;
159
+ return Array.isArray(r) ? r : [];
528
160
  }
529
- class ue extends k {
530
- generateVariants(e, t) {
531
- const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [], f = t.defaultLocale.code;
532
- if (s.includes(f)) {
533
- const u = r?.[f], m = u ? R(u) : a, d = u ? { [f]: u } : {}, P = this.createLocalizedChildren(
534
- i,
535
- a,
536
- [f],
537
- !1,
538
- !1,
539
- !1,
540
- d,
541
- t
542
- );
543
- n.push(
544
- z(e, {
545
- path: m,
546
- name: e.name,
547
- children: P
548
- })
549
- );
550
- }
551
- const c = t.locales.filter((u) => s.includes(u.code) && u.code !== f);
552
- if (c.length)
553
- if (r)
554
- for (const u of c) {
555
- const m = r[u.code];
556
- if (m) {
557
- const d = this.createLocalizedRoute(
558
- e,
559
- [u.code],
560
- i,
561
- !0,
562
- m,
563
- t.customRegex,
564
- !1,
565
- u.code,
566
- a,
567
- t
568
- );
569
- d && n.push(d);
570
- } else {
571
- const d = this.createLocalizedRoute(
572
- e,
573
- [u.code],
574
- i,
575
- !1,
576
- "",
577
- t.customRegex,
578
- !1,
579
- u.code,
580
- a,
581
- t
582
- );
583
- d && n.push(d);
584
- }
585
- }
586
- else {
587
- const u = c.map((d) => d.code), m = this.createLocalizedRoute(
588
- e,
589
- u,
590
- i,
591
- !1,
592
- "",
593
- t.customRegex,
594
- !1,
595
- !0,
596
- a,
597
- t
598
- );
599
- m && n.push(m);
600
- }
601
- const h = W(e, s, t.customRegex, t.localizedRouteNamePrefix);
602
- return h.length && n.push(...h), n;
603
- }
604
- postProcess(e, t) {
605
- const a = [], o = [];
606
- for (const r of e) {
607
- const i = r.name ?? "";
608
- typeof i == "string" && i.startsWith(t.localizedRouteNamePrefix) ? o.push(r) : a.push(r);
609
- }
610
- const s = [...a, ...o];
611
- return t.fallbackRedirectComponentPath && s.push({
612
- path: "/:pathMatch(.*)*",
613
- name: "custom-fallback-route",
614
- file: t.fallbackRedirectComponentPath,
615
- meta: {
616
- globalLocaleRoutes: t.rawGlobalLocaleRoutes ?? t.globalLocaleRoutes
617
- }
618
- }), s;
619
- }
620
- createLocalizedChildren(e, t, a, o = !0, s = !1, r = !1, i = {}, n) {
621
- return e.flatMap(
622
- (f) => this.createLocalizedVariants(f, t, a, o, s, r, i, n)
623
- );
624
- }
625
- createLocalizedVariants(e, t, a, o, s, r = !1, i, n) {
626
- const f = R(e.path ?? ""), c = y(t, e.path ?? ""), h = F(c), u = n.localizedPaths[h], m = !!u, d = [];
627
- if (!m) {
628
- const P = g(f), p = this.createLocalizedChildren(
629
- $(e.children ?? []),
630
- y(t, e.path ?? ""),
631
- a,
632
- o,
633
- s,
634
- r,
635
- i,
636
- n
637
- ), L = this.buildChildRouteName(e.name, r, n);
638
- return d.push(
639
- z(e, {
640
- path: P,
641
- name: L,
642
- children: p
643
- })
644
- ), d;
645
- }
646
- for (const P of a) {
647
- const p = i?.[P], L = !!p, C = u?.[P];
648
- let A = R(C || (e.path ?? ""));
649
- L && p && (C ? A = R(C) : A = y(p, e.path ?? ""));
650
- const v = H(P, n.defaultLocale, s) ? x(P, A, n.customRegex) : A, T = g(v), E = C ? R(C) : L ? p : y(t, e.path ?? ""), V = this.createLocalizedChildren(
651
- $(e.children ?? []),
652
- E,
653
- [P],
654
- o,
655
- s,
656
- P,
657
- {
658
- ...i,
659
- [P]: E
660
- },
661
- n
662
- ), B = this.buildLocalizedRouteName(
663
- b(e.name, e.path),
664
- P,
665
- o,
666
- !!u,
667
- n
668
- );
669
- d.push(
670
- z(e, {
671
- path: T,
672
- name: B,
673
- children: V
674
- })
675
- );
676
- }
677
- return d;
678
- }
679
- buildChildRouteName(e, t, a) {
680
- return t === !0 ? `${a.localizedRouteNamePrefix}${e}` : typeof t == "string" ? `${a.localizedRouteNamePrefix}${e}-${t}` : e;
681
- }
682
- createLocalizedRoute(e, t, a, o, s = "", r, i = !1, n = !1, f, c) {
683
- const h = this.buildRoutePathForLocales(
684
- t,
685
- e.path ?? "",
686
- s,
687
- o,
688
- r,
689
- i,
690
- c.defaultLocale.code
691
- );
692
- if (!h || h === e.path || t.length === 0) return null;
693
- const u = t[0];
694
- if (!u) return null;
695
- const m = f ?? e.path ?? "", d = j(
696
- b(e.name ?? "", m),
697
- u,
698
- o,
699
- c.localizedRouteNamePrefix
700
- );
701
- return z(e, {
702
- path: h,
703
- name: d,
704
- children: this.createLocalizedChildren(
705
- a,
706
- m,
707
- t,
708
- !0,
709
- !1,
710
- n,
711
- { [u]: s },
712
- c
713
- ),
714
- alias: [],
715
- meta: { alias: [] }
716
- });
717
- }
718
- buildLocalizedRouteName(e, t, a, o = !1, s) {
719
- return a ? o ? `${s.localizedRouteNamePrefix}${e}-${t}` : t && !J(t, s.defaultLocale) ? `${s.localizedRouteNamePrefix}${e}-${t}` : `${s.localizedRouteNamePrefix}${e}` : e;
720
- }
161
+ function P(e, t, n, r = "localized-") {
162
+ let i = N(e);
163
+ if (!i.length) return [];
164
+ let a = [];
165
+ for (let o of i) {
166
+ let i = S(t, o, n);
167
+ a.push(M(e, {
168
+ path: i,
169
+ name: `${r}${e.name ?? ""}`,
170
+ alias: void 0,
171
+ meta: { alias: void 0 },
172
+ children: e.children
173
+ }));
174
+ }
175
+ return a;
721
176
  }
722
- function he(l) {
723
- switch (l) {
724
- case "no_prefix":
725
- return new ie();
726
- case "prefix":
727
- return new ne();
728
- case "prefix_and_default":
729
- return new ce();
730
- case "prefix_except_default":
731
- return new ue();
732
- default:
733
- throw new Error(`Unknown route strategy: ${l}`);
734
- }
177
+ //#endregion
178
+ //#region src/strategies/abstract.ts
179
+ var F = class {
180
+ processPage(t, n) {
181
+ if (t.path === void 0) throw Error("page.path is required");
182
+ if (c(t) || t.path && e(t.path, n.excludePatterns)) return [t];
183
+ let r = t.path ?? "", i = u(t.name, t.path);
184
+ return D(n.globalLocaleRoutes, r, i) ? [t] : this.generateVariants(t, n);
185
+ }
186
+ postProcess(e, t) {
187
+ return e;
188
+ }
189
+ localizeChildren(e, t, n, r, i, a) {
190
+ return e.flatMap((e) => this.localizeChild(e, t, n, r, i, a));
191
+ }
192
+ localizeChildrenAllLocales(e, t, n, r, i) {
193
+ return e.flatMap((e) => this.localizeChildAllLocales(e, t, n, r, i));
194
+ }
195
+ localizeChildAllLocales(e, t, n, r, i) {
196
+ let a = j(n, e.path ?? ""), o = u(e.name, e.path);
197
+ if (D(i.globalLocaleRoutes, a, o)) return [e];
198
+ let c = j(t, e.path ?? ""), l = T(c), d = i.localizedPaths[l];
199
+ if (d) return r.flatMap((r) => {
200
+ let a = d[r] ?? j(t, e.path ?? "");
201
+ return this.localizeChild(e, a, n, r, i, !0);
202
+ });
203
+ let f = g(h(e.path ?? "")), p = this.localizeChildrenAllLocales(s(e.children ?? []), c, a, r, i);
204
+ return [M(e, {
205
+ path: f,
206
+ name: `${i.localizedRouteNamePrefix}${e.name ?? ""}`,
207
+ children: p
208
+ })];
209
+ }
210
+ localizeChild(e, t, n, r, i, a) {
211
+ let o = j(n, e.path ?? ""), c = u(e.name, e.path);
212
+ if (D(i.globalLocaleRoutes, o, c)) return [e];
213
+ let l = i.getCustomPath(o, r), d = g(h(l || (e.path ?? ""))), f = l ?? j(t, e.path ?? ""), p = this.localizeChildren(s(e.children ?? []), f, o, r, i, a), m = u(e.name, e.path);
214
+ return [M(e, {
215
+ path: d,
216
+ name: `${i.localizedRouteNamePrefix}${m}-${r}`,
217
+ children: p
218
+ })];
219
+ }
220
+ buildRoutePathForLocales(e, t, n, r, i, a, o) {
221
+ if (r) {
222
+ let t = e.includes(o);
223
+ return a || !t ? S(e, n, i) : h(n);
224
+ }
225
+ return S(e, t, i);
226
+ }
227
+ }, I = class extends F {
228
+ generateVariants(e, t) {
229
+ let n = e.path ?? "", r = u(e.name, e.path), i = t.getAllowedLocales(n, r), a = t.getCustomPathsForPage(n, r), o = s(e.children ?? []), c = [];
230
+ if (c.push(e), a) for (let s of i) {
231
+ let i = a[s];
232
+ if (!i) continue;
233
+ let u = h(i), d = h(n);
234
+ if (u === d) continue;
235
+ let f = C(i), p = l(r, s, !0), m = this.localizeChildrenForNoPrefix(o, u, n, n, s, t, 1);
236
+ c.push(M(e, {
237
+ path: f,
238
+ name: p,
239
+ children: m,
240
+ alias: [],
241
+ meta: { alias: [] }
242
+ })), t.noPrefixRedirect && s === t.defaultLocale.code && u !== d && (e.redirect = u);
243
+ }
244
+ return c.push(...P(e, i, t.customRegex, t.localizedRouteNamePrefix)), c;
245
+ }
246
+ localizeChildrenForNoPrefix(e, t, n, r, i, a, o) {
247
+ return e.map((e) => {
248
+ let c = j(n, e.path ?? ""), d, f;
249
+ if (o === 1) {
250
+ let n = a.getCustomPath(c, i);
251
+ if (n) {
252
+ let e = h(n);
253
+ d = g(e), f = e;
254
+ } else d = g(h(e.path ?? "")), f = j(t, e.path ?? "");
255
+ } else d = g(h(e.path ?? "")), f = j(t, e.path ?? "");
256
+ let p = this.localizeChildrenForNoPrefix(s(e.children ?? []), f, c, r, i, a, o + 1), m = l(u(e.name, e.path), i, !0);
257
+ return M(e, {
258
+ path: d,
259
+ name: m,
260
+ children: p
261
+ });
262
+ });
263
+ }
264
+ };
265
+ //#endregion
266
+ //#region src/strategies/prefix.ts
267
+ function L(e) {
268
+ let t = e.alias ?? e.meta?.alias;
269
+ return Array.isArray(t) ? t : [];
735
270
  }
736
- class Re {
737
- constructor(e) {
738
- this.localizedPaths = {};
739
- const {
740
- locales: t,
741
- defaultLocaleCode: a,
742
- strategy: o,
743
- globalLocaleRoutes: s,
744
- filesLocaleRoutes: r = {},
745
- routeLocales: i = {},
746
- noPrefixRedirect: n,
747
- excludePatterns: f,
748
- localizedRouteNamePrefix: c = "localized-",
749
- customRegexMatcher: h,
750
- fallbackRedirectComponentPath: u
751
- } = e, m = X(t, a);
752
- this.locales = m.locales, this.defaultLocale = m.defaultLocale, this.strategy = o, this.noPrefixRedirect = n, this.excludePatterns = f, this.localizedRouteNamePrefix = c, this.customRegex = h, this.fallbackRedirectComponentPath = u, this.activeLocaleCodes = this.computeActiveLocaleCodes();
753
- const d = {};
754
- for (const P in s) {
755
- const p = N(P), L = s[P];
756
- if (typeof L == "object") {
757
- const C = {};
758
- for (const A in L) {
759
- const v = L[A];
760
- v && (C[A] = N(v));
761
- }
762
- d[p] = C;
763
- } else
764
- d[p] = L;
765
- }
766
- this.globalLocaleRoutes = d, this.rawGlobalLocaleRoutes = s ?? {}, this.filesLocaleRoutes = r ?? {}, this.routeLocales = i ?? {};
767
- }
768
- computeActiveLocaleCodes() {
769
- return this.locales.filter((e) => e.code !== this.defaultLocale.code || O(this.strategy) || D(this.strategy)).map((e) => e.code);
770
- }
771
- extendPages(e) {
772
- const t = new oe({
773
- locales: this.locales,
774
- defaultLocaleCode: this.defaultLocale.code,
775
- strategy: this.strategy,
776
- globalLocaleRoutes: this.globalLocaleRoutes,
777
- filesLocaleRoutes: this.filesLocaleRoutes,
778
- routeLocales: this.routeLocales,
779
- pages: e,
780
- excludePatterns: this.excludePatterns,
781
- customRegex: this.customRegex,
782
- noPrefixRedirect: this.noPrefixRedirect,
783
- localizedRouteNamePrefix: this.localizedRouteNamePrefix,
784
- fallbackRedirectComponentPath: this.fallbackRedirectComponentPath,
785
- rawGlobalLocaleRoutes: this.rawGlobalLocaleRoutes
786
- });
787
- this.localizedPaths = t.localizedPaths;
788
- const a = he(this.strategy), o = [...e], s = [];
789
- for (const i of o)
790
- s.push(...a.processPage(i, t));
791
- const r = a.postProcess(s, t);
792
- e.length = 0, e.push(...r);
793
- }
794
- extractLocalizedPaths(e, t = "") {
795
- return _(e, this.globalLocaleRoutes, this.filesLocaleRoutes, t);
796
- }
797
- /**
798
- * Creates global and per-page translation JSON files for the current resolved locales.
799
- */
800
- ensureTranslationFilesExist(e, t, a, o) {
801
- this.locales.forEach((s) => {
802
- const r = w.join(a, t, `${s.code}.json`);
803
- this.ensureFileExists(r), o || e.forEach((i) => {
804
- const n = w.join(a, t, "pages", `${i}/${s.code}.json`);
805
- this.ensureFileExists(n);
806
- });
807
- });
808
- }
809
- ensureFileExists(e) {
810
- try {
811
- const t = w.dirname(e);
812
- K(t) || I(t, { recursive: !0 }), K(e) || U(e, JSON.stringify({}), "utf-8");
813
- } catch {
814
- }
815
- }
816
- /**
817
- * Returns the localized path for a given URL and locale,
818
- * respecting strategy and globalLocaleRoutes (custom paths).
819
- * Used by nitro:config and prerender so route rules work with custom paths (e.g. /de/ueber-uns).
820
- */
821
- resolveLocalizedPath(e, t) {
822
- const a = N(e), o = g(a) || "/";
823
- let s;
824
- const r = this.globalLocaleRoutes[o], i = this.globalLocaleRoutes[a];
825
- r && typeof r == "object" && !Array.isArray(r) ? s = r[t] : i && typeof i == "object" && !Array.isArray(i) && (s = i[t]);
826
- const n = !!s, f = s ? R(s) : R(a) || "";
827
- let c = !1;
828
- if (this.strategy === "no_prefix" ? c = !1 : this.strategy === "prefix" || this.strategy === "prefix_and_default" ? c = !0 : this.strategy === "prefix_except_default" && (c = t !== this.defaultLocale.code), t === this.defaultLocale.code && !n && (this.strategy === "prefix_except_default" || this.strategy === "no_prefix") && (c = !1), !c)
829
- return R(f) || "/";
830
- const h = g(f);
831
- return h ? R(`/${t}/${h}`) : `/${t}`;
832
- }
833
- /**
834
- * Generates the list of data.json routes for prerender.
835
- * When disablePageLocales is true, only index routes are generated (all pages share root translations).
836
- * Otherwise, generates index + per-page routes for each locale.
837
- */
838
- generateDataRoutes(e, t, a) {
839
- const o = [], s = this.collectPageNames(e);
840
- for (const r of this.locales)
841
- if (o.push(`/${t}/index/${r.code}/data.json`), !a)
842
- for (const i of s)
843
- o.push(`/${t}/${i}/${r.code}/data.json`);
844
- return o;
845
- }
846
- collectPageNames(e) {
847
- const t = /* @__PURE__ */ new Set(), a = (o) => {
848
- for (const s of o)
849
- typeof s.name == "string" && s.name.length > 0 && t.add(s.name), s.children && s.children.length > 0 && a(s.children);
850
- };
851
- return a(e), [...t];
852
- }
271
+ var R = class extends F {
272
+ generateVariants(e, t) {
273
+ let n = e.path ?? "", r = u(e.name, e.path), i = t.getAllowedLocales(n, r), a = t.getCustomPathsForPage(n, r), o = s(e.children ?? []), c = [];
274
+ if (a) for (let s of i) {
275
+ let i = a[s], u = S(s, i ? h(i) : n, t.customRegex), d = l(r, s, !!i, t.localizedRouteNamePrefix), f = i ?? n, p = this.localizeChildren(o, f, n, s, t, !0), m = x(u);
276
+ c.push(M(e, {
277
+ path: u,
278
+ name: d,
279
+ children: p,
280
+ alias: m.length ? m : void 0,
281
+ meta: { alias: m.length ? m : [] }
282
+ }));
283
+ }
284
+ else {
285
+ let a = S(i, n, t.customRegex), s = l(r, i[0], !1, t.localizedRouteNamePrefix), u = this.localizeChildrenAllLocales(o, n, n, i, t);
286
+ c.push(M(e, {
287
+ path: a,
288
+ name: s,
289
+ children: u,
290
+ alias: [],
291
+ meta: { alias: [] }
292
+ }));
293
+ }
294
+ let d = L(e);
295
+ if (d.length) for (let n of d) {
296
+ let r = S(i, n, t.customRegex);
297
+ c.push(M(e, {
298
+ path: r,
299
+ name: `${t.localizedRouteNamePrefix}${e.name ?? ""}`,
300
+ alias: void 0,
301
+ meta: { alias: void 0 }
302
+ }));
303
+ }
304
+ return c;
305
+ }
306
+ postProcess(t, n) {
307
+ let r = t.filter((t) => {
308
+ if (t.name === "index" && t.path === "/") return !1;
309
+ let r = t.path ?? "";
310
+ return !!(r && e(r, n.excludePatterns) || D(n.globalLocaleRoutes, r, t.name ?? "") || /^\/:locale/.test(r) || r === "/");
311
+ }), i = n.defaultLocale.code;
312
+ for (let [e, t] of Object.entries(n.globalLocaleRoutes)) {
313
+ if (t === !1 || typeof t != "object") continue;
314
+ let n = t[i];
315
+ if (!n) continue;
316
+ let a = e.startsWith("/") ? e : `/${e}`, o = `/${i}${n.startsWith("/") ? n : `/${n}`}`;
317
+ a !== o && r.push({
318
+ path: a,
319
+ name: `redirect-${e.replace(/\//g, "-")}`,
320
+ redirect: o
321
+ });
322
+ }
323
+ return n.fallbackRedirectComponentPath && r.push({
324
+ path: "/:pathMatch(.*)*",
325
+ name: "custom-fallback-route",
326
+ file: n.fallbackRedirectComponentPath,
327
+ meta: { globalLocaleRoutes: n.rawGlobalLocaleRoutes ?? n.globalLocaleRoutes }
328
+ }), r;
329
+ }
330
+ }, z = class extends F {
331
+ generateVariants(e, t) {
332
+ let n = e.path ?? "", r = u(e.name, e.path), i = t.getAllowedLocales(n, r), a = t.getCustomPathsForPage(n, r), o = s(e.children ?? []), c = [], l = t.defaultLocale.code;
333
+ c.push(e);
334
+ let d = t.locales.filter((e) => i.includes(e.code));
335
+ if (d.length > 0) {
336
+ if (a) for (let r of d) {
337
+ let i = a[r.code];
338
+ if (i) {
339
+ if (r.code === l) {
340
+ let a = this.createLocalizedRoute(e, [r.code], o, !0, i, t.customRegex, !1, r.code, n, t);
341
+ a && c.push(a);
342
+ let s = this.createLocalizedRoute(e, [r.code], o, !0, i, t.customRegex, !0, r.code, n, t);
343
+ s && c.push(s);
344
+ } else {
345
+ let a = this.createLocalizedRoute(e, [r.code], o, !0, i, t.customRegex, !1, r.code, n, t);
346
+ a && c.push(a);
347
+ }
348
+ } else {
349
+ let i = this.createLocalizedRoute(e, [r.code], o, !1, "", t.customRegex, !1, r.code, n, t);
350
+ i && c.push(i);
351
+ }
352
+ }
353
+ else {
354
+ let r = d.map((e) => e.code), i = this.createLocalizedRoute(e, r, o, !1, "", t.customRegex, !1, !0, n, t);
355
+ i && c.push(i);
356
+ }
357
+ }
358
+ let f = P(e, i, t.customRegex, t.localizedRouteNamePrefix);
359
+ return f.length && c.push(...f), c;
360
+ }
361
+ postProcess(e, t) {
362
+ let n = [], r = [];
363
+ for (let i of e) {
364
+ let e = i.name ?? "";
365
+ typeof e == "string" && e.startsWith(t.localizedRouteNamePrefix) ? r.push(i) : n.push(i);
366
+ }
367
+ return [...n, ...r];
368
+ }
369
+ createLocalizedRoute(e, t, n, r, i = "", a, o = !1, s = !1, c, d) {
370
+ let f = this.buildRoutePathForLocales(t, e.path ?? "", i, r, a, o, d.defaultLocale.code);
371
+ if (!f || !(r && i) && f === e.path || t.length === 0) return null;
372
+ let p = t[0];
373
+ if (!p) return null;
374
+ let m = c ?? e.path ?? "", h = l(u(e.name ?? "", m), p, r, d.localizedRouteNamePrefix), g = o || p !== d.defaultLocale.code;
375
+ return M(e, {
376
+ path: f,
377
+ name: h,
378
+ children: t.length === 1 ? this.localizeChildren(n, f, m, p, d, g) : this.localizeChildrenAllLocales(n, f, m, t, d),
379
+ alias: [],
380
+ meta: { alias: [] }
381
+ });
382
+ }
383
+ }, B = class extends F {
384
+ generateVariants(e, t) {
385
+ let n = e.path ?? "", r = u(e.name, e.path), i = t.getAllowedLocales(n, r), a = t.getCustomPathsForPage(n, r), o = s(e.children ?? []), c = [], l = t.defaultLocale.code;
386
+ if (i.includes(l)) {
387
+ let r = a?.[l], i = r ? h(r) : n, s = r ? { [l]: r } : {}, u = this.createLocalizedChildren(o, n, [l], !1, !1, !1, s, t);
388
+ c.push(M(e, {
389
+ path: i,
390
+ name: e.name,
391
+ children: u
392
+ }));
393
+ }
394
+ let d = t.locales.filter((e) => i.includes(e.code) && e.code !== l);
395
+ if (d.length) {
396
+ if (a) for (let r of d) {
397
+ let i = a[r.code];
398
+ if (i) {
399
+ let a = this.createLocalizedRoute(e, [r.code], o, !0, i, t.customRegex, !1, r.code, n, t);
400
+ a && c.push(a);
401
+ } else {
402
+ let i = this.createLocalizedRoute(e, [r.code], o, !1, "", t.customRegex, !1, r.code, n, t);
403
+ i && c.push(i);
404
+ }
405
+ }
406
+ else {
407
+ let r = d.map((e) => e.code), i = this.createLocalizedRoute(e, r, o, !1, "", t.customRegex, !1, !0, n, t);
408
+ i && c.push(i);
409
+ }
410
+ }
411
+ let f = P(e, i, t.customRegex, t.localizedRouteNamePrefix);
412
+ return f.length && c.push(...f), c;
413
+ }
414
+ postProcess(e, t) {
415
+ let n = [], r = [];
416
+ for (let i of e) {
417
+ let e = i.name ?? "";
418
+ typeof e == "string" && e.startsWith(t.localizedRouteNamePrefix) ? r.push(i) : n.push(i);
419
+ }
420
+ let i = [...n, ...r];
421
+ return t.fallbackRedirectComponentPath && i.push({
422
+ path: "/:pathMatch(.*)*",
423
+ name: "custom-fallback-route",
424
+ file: t.fallbackRedirectComponentPath,
425
+ meta: { globalLocaleRoutes: t.rawGlobalLocaleRoutes ?? t.globalLocaleRoutes }
426
+ }), i;
427
+ }
428
+ createLocalizedChildren(e, t, n, r = !0, i = !1, a = !1, o = {}, s) {
429
+ return e.flatMap((e) => this.createLocalizedVariants(e, t, n, r, i, a, o, s));
430
+ }
431
+ createLocalizedVariants(e, t, n, r, i, a = !1, o, c) {
432
+ let l = h(e.path ?? ""), f = T(j(t, e.path ?? "")), p = c.localizedPaths[f], m = !!p, _ = [];
433
+ if (!m) {
434
+ let u = g(l), d = this.createLocalizedChildren(s(e.children ?? []), j(t, e.path ?? ""), n, r, i, a, o, c), f = this.buildChildRouteName(e.name, a, c);
435
+ return _.push(M(e, {
436
+ path: u,
437
+ name: f,
438
+ children: d
439
+ })), _;
440
+ }
441
+ for (let a of n) {
442
+ let n = o?.[a], l = !!n, f = p?.[a], m = h(f || (e.path ?? ""));
443
+ l && n && (m = f ? h(f) : j(n, e.path ?? ""));
444
+ let v = g(d(a, c.defaultLocale, i) ? S(a, m, c.customRegex) : m), y = f ? h(f) : l ? n : j(t, e.path ?? ""), b = this.createLocalizedChildren(s(e.children ?? []), y, [a], r, i, a, {
445
+ ...o,
446
+ [a]: y
447
+ }, c), x = this.buildLocalizedRouteName(u(e.name, e.path), a, r, !!p, c);
448
+ _.push(M(e, {
449
+ path: v,
450
+ name: x,
451
+ children: b
452
+ }));
453
+ }
454
+ return _;
455
+ }
456
+ buildChildRouteName(e, t, n) {
457
+ return t === !0 ? `${n.localizedRouteNamePrefix}${e}` : typeof t == "string" ? `${n.localizedRouteNamePrefix}${e}-${t}` : e;
458
+ }
459
+ createLocalizedRoute(e, t, n, r, i = "", a, o = !1, s = !1, c, d) {
460
+ let f = this.buildRoutePathForLocales(t, e.path ?? "", i, r, a, o, d.defaultLocale.code);
461
+ if (!f || f === e.path || t.length === 0) return null;
462
+ let p = t[0];
463
+ if (!p) return null;
464
+ let m = c ?? e.path ?? "";
465
+ return M(e, {
466
+ path: f,
467
+ name: l(u(e.name ?? "", m), p, r, d.localizedRouteNamePrefix),
468
+ children: this.createLocalizedChildren(n, m, t, !0, !1, s, { [p]: i }, d),
469
+ alias: [],
470
+ meta: { alias: [] }
471
+ });
472
+ }
473
+ buildLocalizedRouteName(e, t, n, r = !1, i) {
474
+ return n ? r || t && !f(t, i.defaultLocale) ? `${i.localizedRouteNamePrefix}${e}-${t}` : `${i.localizedRouteNamePrefix}${e}` : e;
475
+ }
476
+ };
477
+ //#endregion
478
+ //#region src/strategies/factory.ts
479
+ function V(e) {
480
+ switch (e) {
481
+ case "no_prefix": return new I();
482
+ case "prefix": return new R();
483
+ case "prefix_and_default": return new z();
484
+ case "prefix_except_default": return new B();
485
+ default: throw Error(`Unknown route strategy: ${e}`);
486
+ }
853
487
  }
854
- export {
855
- Re as RouteGenerator,
856
- ee as buildEncodedPathAliases,
857
- x as buildFullPath,
858
- te as buildFullPathNoPrefix,
859
- j as buildRouteName,
860
- $ as cloneArray,
861
- _ as extractLocalizedPaths,
862
- M as isInternalPath,
863
- Pe as isLocaleAllowedForUnlocalizedRoute,
864
- J as isLocaleDefault,
865
- S as isLocalizationDisabledForPage,
866
- q as isPageRedirectOnly,
867
- R as normalizePath,
868
- N as normalizeRouteKey,
869
- g as removeLeadingSlash,
870
- H as shouldAddLocalePrefix
488
+ //#endregion
489
+ //#region src/route-generator.ts
490
+ var H = class {
491
+ constructor(e) {
492
+ this.localizedPaths = {};
493
+ let { locales: t, defaultLocaleCode: n, strategy: r, globalLocaleRoutes: i, filesLocaleRoutes: a = {}, routeLocales: o = {}, noPrefixRedirect: s, excludePatterns: c, localizedRouteNamePrefix: l = "localized-", customRegexMatcher: u, fallbackRedirectComponentPath: d } = e, f = p(t, n);
494
+ this.locales = f.locales, this.defaultLocale = f.defaultLocale, this.strategy = r, this.noPrefixRedirect = s, this.excludePatterns = c, this.localizedRouteNamePrefix = l, this.customRegex = u, this.fallbackRedirectComponentPath = d, this.activeLocaleCodes = this.computeActiveLocaleCodes();
495
+ let h = {};
496
+ for (let e in i) {
497
+ let t = m(e), n = i[e];
498
+ if (typeof n == "object") {
499
+ let e = {};
500
+ for (let t in n) {
501
+ let r = n[t];
502
+ r && (e[t] = m(r));
503
+ }
504
+ h[t] = e;
505
+ } else h[t] = n;
506
+ }
507
+ this.globalLocaleRoutes = h, this.rawGlobalLocaleRoutes = i ?? {}, this.filesLocaleRoutes = a ?? {}, this.routeLocales = o ?? {};
508
+ }
509
+ computeActiveLocaleCodes() {
510
+ return this.locales.filter((e) => e.code !== this.defaultLocale.code || a(this.strategy) || o(this.strategy)).map((e) => e.code);
511
+ }
512
+ extendPages(e) {
513
+ let t = new A({
514
+ locales: this.locales,
515
+ defaultLocaleCode: this.defaultLocale.code,
516
+ strategy: this.strategy,
517
+ globalLocaleRoutes: this.globalLocaleRoutes,
518
+ filesLocaleRoutes: this.filesLocaleRoutes,
519
+ routeLocales: this.routeLocales,
520
+ pages: e,
521
+ excludePatterns: this.excludePatterns,
522
+ customRegex: this.customRegex,
523
+ noPrefixRedirect: this.noPrefixRedirect,
524
+ localizedRouteNamePrefix: this.localizedRouteNamePrefix,
525
+ fallbackRedirectComponentPath: this.fallbackRedirectComponentPath,
526
+ rawGlobalLocaleRoutes: this.rawGlobalLocaleRoutes
527
+ });
528
+ this.localizedPaths = t.localizedPaths;
529
+ let n = V(this.strategy), r = [...e], i = [];
530
+ for (let e of r) i.push(...n.processPage(e, t));
531
+ let a = n.postProcess(i, t);
532
+ e.length = 0, e.push(...a);
533
+ }
534
+ extractLocalizedPaths(e, t = "") {
535
+ return E(e, this.globalLocaleRoutes, this.filesLocaleRoutes, t);
536
+ }
537
+ ensureTranslationFilesExist(e, n, r, i) {
538
+ this.locales.forEach((a) => {
539
+ let o = t.join(r, n, `${a.code}.json`);
540
+ this.ensureFileExists(o), i || e.forEach((e) => {
541
+ let i = t.join(r, n, "pages", `${e}/${a.code}.json`);
542
+ this.ensureFileExists(i);
543
+ });
544
+ });
545
+ }
546
+ ensureFileExists(e) {
547
+ try {
548
+ let a = t.dirname(e);
549
+ n(a) || r(a, { recursive: !0 }), n(e) || i(e, JSON.stringify({}), "utf-8");
550
+ } catch {}
551
+ }
552
+ resolveLocalizedPath(e, t) {
553
+ let n = m(e), r = g(n) || "/", i, a = this.globalLocaleRoutes[r], o = this.globalLocaleRoutes[n];
554
+ a && typeof a == "object" && !Array.isArray(a) ? i = a[t] : o && typeof o == "object" && !Array.isArray(o) && (i = o[t]);
555
+ let s = !!i, c = i ? h(i) : h(n) || "", l = !1;
556
+ if (this.strategy === "no_prefix" ? l = !1 : this.strategy === "prefix" || this.strategy === "prefix_and_default" ? l = !0 : this.strategy === "prefix_except_default" && (l = t !== this.defaultLocale.code), t === this.defaultLocale.code && !s && (this.strategy === "prefix_except_default" || this.strategy === "no_prefix") && (l = !1), !l) return h(c) || "/";
557
+ let u = g(c);
558
+ return u ? h(`/${t}/${u}`) : `/${t}`;
559
+ }
560
+ generateDataRoutes(e, t, n) {
561
+ let r = [], i = this.collectPageNames(e);
562
+ for (let e of this.locales) if (r.push(`/${t}/index/${e.code}/data.json`), !n) for (let n of i) r.push(`/${t}/${n}/${e.code}/data.json`);
563
+ return r;
564
+ }
565
+ collectPageNames(e) {
566
+ let t = /* @__PURE__ */ new Set(), n = (e) => {
567
+ for (let r of e) typeof r.name == "string" && r.name.length > 0 && t.add(r.name), r.children && r.children.length > 0 && n(r.children);
568
+ };
569
+ return n(e), [...t];
570
+ }
871
571
  };
572
+ //#endregion
573
+ export { H as RouteGenerator, x as buildEncodedPathAliases, S as buildFullPath, C as buildFullPathNoPrefix, l as buildRouteName, s as cloneArray, E as extractLocalizedPaths, e as isInternalPath, O as isLocaleAllowedForUnlocalizedRoute, f as isLocaleDefault, D as isLocalizationDisabledForPage, c as isPageRedirectOnly, h as normalizePath, m as normalizeRouteKey, g as removeLeadingSlash, d as shouldAddLocalePrefix };