@i18n-micro/route-strategy 1.1.29 → 2.0.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/dist/index.mjs CHANGED
@@ -1,573 +1,459 @@
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
- };
18
- }
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("/");
23
- }
24
- var h = (e) => {
1
+ import { isInternalPath as e, trimTrailingSlashes as t } from "@i18n-micro/utils/app-path";
2
+ import n from "node:path";
3
+ import { existsSync as r, mkdirSync as i, writeFileSync as a } from "node:fs";
4
+ // src/paths.ts
5
+ function o(e) {
25
6
  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);
31
- }
32
- function v(e) {
33
- if (e !== void 0) return e.startsWith("/") && e.endsWith("/") ? e?.slice(1, -1) : e;
7
+ let r = t(n.posix.normalize(e));
8
+ return r === "." ? "" : r;
34
9
  }
35
- function y(e) {
36
- return e;
10
+ var s = (e) => e.startsWith("/") ? e.slice(1) : e, c = (e) => o(`/${s(e)}`) || "/";
11
+ function l(e, t) {
12
+ return t.startsWith("/") ? c(t) : c(n.posix.join(e, t));
37
13
  }
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("/");
14
+ function u(e) {
15
+ return e.split("/").map((e) => e.replace(/^\[\.\.\.(\w+)\]$/, ":$1(.*)*").replace(/\[\[(\w+)\]\]/g, ":$1?").replace(/\[(\w+)\]/g, ":$1").replace(/:(\w+)\(\)/g, ":$1")).join("/");
40
16
  }
41
- function x(e) {
42
- let t = b(e);
43
- return t === e ? [] : [t];
17
+ var d = /* @__PURE__ */ new Map();
18
+ function f(e) {
19
+ let t = d.get(e);
20
+ return t === void 0 && d.set(e, t = s(o(u(e))) || "/"), t;
44
21
  }
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));
22
+ function p(e, t) {
23
+ if (!t.startsWith("/")) return s(o(t));
24
+ let n = c(t), r = c(e);
25
+ if (r === "/") return s(n);
26
+ if (n === r) return "";
27
+ if (n.startsWith(`${r}/`)) return n.slice(r.length + 1);
28
+ let i = n.split("/").filter(Boolean), a = r.split("/").filter(Boolean), l = 0;
29
+ for (; l < i.length && i[l] === a[l];) l++;
30
+ return i.slice(l).join("/");
48
31
  }
49
- function C(e) {
50
- return h(y(e));
32
+ function m(e) {
33
+ let t = c(e).split("/").slice(1);
34
+ if (t[0]?.includes(":")) return null;
35
+ let n = t.findIndex((e) => e.endsWith("*") || e.endsWith("+") || e.endsWith("?"));
36
+ return `/${(n === -1 ? t : [...t.slice(0, n), "**"]).map((e) => e.replace(/^(:\w+)\(.*\)$/, "$1")).join("/")}`;
51
37
  }
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) || "/";
38
+ function h(e, t) {
39
+ if (!t.startsWith("/")) return !0;
40
+ let n = c(e), r = c(t);
41
+ return n === "/" || r === n || r.startsWith(`${n}/`);
57
42
  }
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;
43
+ var g = /[\u0080-￿ "<>`]/;
44
+ function _(e) {
45
+ if (!g.test(e)) return;
46
+ let t = e.split("/").map((e) => e.startsWith(":") || !g.test(e) ? e : encodeURI(e)).join("/");
47
+ return t === e ? void 0 : t;
72
48
  }
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;
49
+ // src/generate.ts
50
+ var v = (e) => Array.from(e.matchAll(/:(\w+)/g), (e) => e[1]).sort().join(","), y = (e) => !e.name && /(?:^|\/)component-stub(?:\.\w+)?$/.test(e.file ?? "");
51
+ function b(e) {
52
+ let t = f(e);
53
+ return t === "/" ? "index" : t.replace(/\/|:|\(.*?\)|[?*+]/g, (e) => e === "/" ? "-" : "");
78
54
  }
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);
55
+ function x(e, t, n = "", r = !0) {
56
+ return e.map((e) => {
57
+ let i = r ? c(e.path ?? "") : l(n, e.path ?? ""), a = e.children && x(e.children, t, i, !1), o = a ? {
58
+ ...e,
59
+ children: a
60
+ } : e;
61
+ if (e.name || !e.file || y(e) || e.children?.some((e) => !e.path)) return o;
62
+ let s = b(i);
63
+ return t.has(s) ? o : (t.add(s), {
64
+ ...o,
65
+ name: s
66
+ });
67
+ });
87
68
  }
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;
69
+ function S(e, t) {
70
+ for (let n of e) {
71
+ let { name: e } = n;
72
+ e !== void 0 && n.meta?.i18n?.name !== e && n.meta?.i18n !== void 0 && t.has(e) && (n.name = C(e, t)), n.name && t.add(n.name), S(n.children ?? [], t);
103
73
  }
104
- return t;
105
74
  }
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));
75
+ function C(e, t) {
76
+ let n = 2;
77
+ for (; t.has(`${e}-${n}`);) n++;
78
+ return `${e}-${n}`;
138
79
  }
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;
80
+ var w = (e) => e.flatMap((e) => [...e.name ? [e.name] : [], ...w(e.children ?? [])]);
81
+ function T(e) {
82
+ return e instanceof RegExp ? e.source : e.length > 1 && e[0] === "/" && e.endsWith("/") ? e.slice(1, -1) : e;
154
83
  }
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 : [];
84
+ function E(e, t) {
85
+ let n = RegExp(`^(?:${T(t)})$`);
86
+ return e.filter((e) => !n.test(e));
160
87
  }
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;
176
- }
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
- })];
88
+ function D(t, n, r = /* @__PURE__ */ new Map()) {
89
+ let { strategy: i, locales: a, defaultLocale: u, rules: d, namePrefix: m, hostDefaults: g = [] } = n, b = n.customRegex === void 0 ? void 0 : T(n.customRegex), C = (e, t) => o(`/:locale(${b ?? e.join("|")})/${s(t)}`), E = /* @__PURE__ */ new WeakMap();
90
+ function D(e, t, n) {
91
+ let r = E.get(e);
92
+ if (!r) {
93
+ let i = n ? c(e.path ?? "") : l(t, e.path ?? "");
94
+ r = {
95
+ original: i,
96
+ key: f(i),
97
+ rule: d.get(i, e.name),
98
+ allowed: d.allowedLocales(i, e.name),
99
+ noMeta: d.disableMeta(i, e.name)
100
+ }, E.set(e, r);
101
+ }
102
+ return r;
209
103
  }
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
- })];
104
+ function O(e) {
105
+ let t = E.get(e)?.noMeta;
106
+ return t === void 0 ? e : {
107
+ ...e,
108
+ meta: {
109
+ ...e.meta,
110
+ i18nNoMeta: t
111
+ }
112
+ };
219
113
  }
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);
114
+ let k = /* @__PURE__ */ new Set();
115
+ function A(e, t, n, r, i) {
116
+ k.has(`${e}\0${t}`) || (k.add(`${e}\0${t}`), console.warn(`[i18n] globalLocaleRoutes["${e}"].${t} = "${n}" is outside its parent "${r}": the page is served at "${i}".`));
117
+ }
118
+ function j(e, t, n, i, a, o) {
119
+ let s = e.path ?? "", { original: u, key: d, rule: f, allowed: m } = D(e, n, a);
120
+ if (f === !1) return o ? {
121
+ page: e,
122
+ path: s,
123
+ children: [],
124
+ raw: !0
125
+ } : null;
126
+ if (t && m && !m.includes(t)) return null;
127
+ let g = t && f ? f[t] : void 0, _ = g === void 0 ? s : a ? c(g) : p(i, g), v = a ? c(_) : l(i, _);
128
+ if (g !== void 0 && !a && !h(i, g) && A(d, t, g, i, v), t) {
129
+ let e = r.get(d);
130
+ e ? e[t] = v : r.set(d, { [t]: v });
224
131
  }
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);
132
+ let y = [];
133
+ for (let n of e.children ?? []) {
134
+ let e = j(n, t, u, v, !1, o);
135
+ e && y.push(e);
243
136
  }
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
- });
137
+ return {
138
+ page: e,
139
+ path: _,
140
+ children: y
141
+ };
263
142
  }
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 : [];
270
- }
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
- }));
143
+ let M = (e) => e.raw ? "!" : `${e.path}(${e.children.map(M).join(",")})`;
144
+ function N(e, t, n, r, i, a, o = !0) {
145
+ if (e.raw) return O(e.page);
146
+ let { page: s } = e, l = a ? i ? C(t, e.path) : c(e.path) : e.path, u = {
147
+ ...s,
148
+ path: l
149
+ };
150
+ if (s.name) {
151
+ u.name = r ? `${m}${s.name}${n}` : s.name;
152
+ let e = E.get(s)?.noMeta;
153
+ u.meta = {
154
+ ...s.meta,
155
+ i18n: {
156
+ name: s.name,
157
+ locales: t,
158
+ ...e === void 0 ? {} : { noMeta: e }
159
+ }
160
+ };
283
161
  }
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
- }));
162
+ if (s.children && (u.children = e.children.map((e) => N(e, t, n, r, i, !1))), a) {
163
+ let e = P(o ? s : { path: s.path }, l, i ? t : null);
164
+ u.alias = e, u.meta = {
165
+ ...u.meta,
166
+ alias: e
167
+ };
293
168
  }
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
- }));
169
+ return u;
170
+ }
171
+ function P(e, t, n) {
172
+ let r = e.alias ?? e.meta?.alias, i = (typeof r == "string" ? [r] : Array.isArray(r) ? r : []).filter((e) => typeof e == "string"), a = /* @__PURE__ */ new Set();
173
+ for (let e of [t, ...i.map((e) => n ? C(n, e) : c(e))]) {
174
+ e !== t && a.add(e);
175
+ let n = _(e);
176
+ n && a.add(n);
177
+ }
178
+ return [...a];
179
+ }
180
+ function F(e, t, n, r) {
181
+ let i = M(j(e, null, "", "", !0, L)), a = [], o, s = /* @__PURE__ */ new Map();
182
+ for (let e of t) {
183
+ let t = r.get(e);
184
+ if (!t) continue;
185
+ let c = M(t);
186
+ if (c === i) a.push(e), o ??= t;
187
+ else {
188
+ let t = n ? e : c;
189
+ s.set(t, [...s.get(t) ?? [], e]);
190
+ }
303
191
  }
304
- return c;
192
+ let c = [...s.values()].map((e) => N(r.get(e[0]), e, `-${e[0]}`, !0, n, !0, n));
193
+ return {
194
+ plain: a,
195
+ records: o && n ? [N(o, a, "", !0, !0, !0), ...c] : c
196
+ };
305
197
  }
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
198
+ function I(e) {
199
+ let t = /* @__PURE__ */ new Map();
200
+ for (let n of [u, ...g]) {
201
+ let r = e.get(n);
202
+ if (!r) continue;
203
+ let i = M(r);
204
+ t.set(i, [...t.get(i) ?? [], n]);
205
+ }
206
+ return [...t.values()];
207
+ }
208
+ let L = i === "prefix", R = [], z = [];
209
+ for (let r of x(t, new Set(w(t)))) {
210
+ let t = r.path ?? "";
211
+ if (r.redirect && !r.file || e(t, n.excludePatterns, n.apiBaseUrl) || D(r, "", !0).rule === !1) {
212
+ R.push(O(r));
213
+ continue;
214
+ }
215
+ if (y(r)) {
216
+ R.push({
217
+ ...r,
218
+ meta: {
219
+ ...r.meta,
220
+ i18nStub: !0
221
+ }
321
222
  });
223
+ continue;
322
224
  }
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);
225
+ let o = D(r, "", !0).allowed ?? a, s = o.includes(u), l = new Map(o.map((e) => [e, j(r, e, "", "", !0, L)]));
226
+ if (i === "no_prefix") {
227
+ let { plain: e, records: t } = F(r, o, !1, l), i = N(j(r, null, "", "", !0, !0), e, "", !1, !1, !0), a = t.find((e) => (e.meta?.i18n)?.locales.includes(u));
228
+ if (n.noPrefixRedirect && a && a.path !== i.path && !a.path.includes(":")) {
229
+ let e = t.flatMap((e) => e.path.includes(":") ? [] : e.meta.i18n.locales.map((t) => [t, e.path]));
230
+ i.meta = {
231
+ ...i.meta,
232
+ i18n: {
233
+ ...i.meta.i18n,
234
+ paths: Object.fromEntries(e)
347
235
  }
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
- }
236
+ };
352
237
  }
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);
238
+ R.push(i), z.push(...t);
239
+ continue;
240
+ }
241
+ if (i !== "prefix") for (let e of I(l)) {
242
+ let n = e[0] === u, a = N(j(r, e[0], "", "", !0, !0), e, n ? "" : `-${e[0]}-default`, !n, !1, !0, n), o = c(t);
243
+ n && i === "prefix_except_default" && a.path !== o && v(a.path) === v(o) && (a.alias = [
244
+ ...a.alias ?? [],
245
+ o,
246
+ ...[_(o) ?? []].flat()
247
+ ], a.meta = {
248
+ ...a.meta,
249
+ alias: a.alias,
250
+ i18n: {
251
+ ...a.meta.i18n,
252
+ original: o
253
+ }
254
+ }), R.push(a);
255
+ }
256
+ let d = F(r, i === "prefix_except_default" && !g.length ? o.filter((e) => e !== u) : o, !0, l).records;
257
+ if (z.push(...d), (i === "prefix" || i === "prefix_and_default") && s && r.name && !t.includes(":")) {
258
+ let e = c(l.get(u).path);
259
+ if (e !== c(t) && !e.includes(":")) {
260
+ if (i === "prefix" && n.redirects !== !1) R.push({
261
+ path: c(t),
262
+ name: `redirect-${r.name}`,
263
+ redirect: `/${u}${e === "/" ? "" : e}`,
264
+ meta: { i18n: {
265
+ name: r.name,
266
+ locales: []
267
+ } }
268
+ });
269
+ else {
270
+ let e = d.find((e) => e.meta.i18n.locales.includes(u));
271
+ e.meta = {
272
+ ...e.meta,
273
+ i18n: {
274
+ ...e.meta.i18n,
275
+ original: c(t)
276
+ }
277
+ };
278
+ }
356
279
  }
357
280
  }
358
- let f = P(e, i, t.customRegex, t.localizedRouteNamePrefix);
359
- return f.length && c.push(...f), c;
360
281
  }
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];
282
+ let B = [...R, ...z];
283
+ return S(B, /* @__PURE__ */ new Set()), B;
284
+ }
285
+ // ../utils/dist/domains.mjs
286
+ function O(e) {
287
+ let t = e.trim().toLowerCase();
288
+ return t.endsWith(":80") ? t.slice(0, -3) : t.endsWith(":443") ? t.slice(0, -4) : t;
289
+ }
290
+ function k(e) {
291
+ if (!e.baseUrl) return null;
292
+ try {
293
+ return O(new URL(e.baseUrl).host);
294
+ } catch {
295
+ return null;
368
296
  }
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
- });
297
+ }
298
+ function A(e) {
299
+ let t = /* @__PURE__ */ new Map();
300
+ for (let n of e) {
301
+ let e = k(n);
302
+ e && t.set(e, [...t.get(e) ?? [], n]);
382
303
  }
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
- }
304
+ return t;
305
+ }
306
+ var j = (e, t) => t.filter((t) => {
307
+ let n = k(t);
308
+ return !n || n === e || t.disabled;
309
+ });
310
+ function M(e, t, n) {
311
+ let r = e.filter((e) => !e.disabled), i = r.find((e) => e.baseDefault);
312
+ return i ? i.code : t.some((e) => e.code === n && !e.disabled) ? n : (r[0] ?? t.find((e) => !e.disabled))?.code;
313
+ }
314
+ function N(e, t) {
315
+ let n = /* @__PURE__ */ new Set();
316
+ for (let [r, i] of A(e)) {
317
+ let a = M(i, j(r, e), t);
318
+ i.some((e) => e.code === a) && n.add(a);
319
+ }
320
+ return e.map((e) => n.has(e.code) && !e.baseDefault ? Object.assign({}, e, { baseDefault: !0 }) : e);
321
+ }
322
+ // src/rules.ts
323
+ var P = class {
324
+ constructor(e = {}, t = {}, n = [], r = {}) {
325
+ this.rules = /* @__PURE__ */ new Map(), this.byName = /* @__PURE__ */ new Map(), this.restrictions = /* @__PURE__ */ new Map(), this.restrictionsByName = /* @__PURE__ */ new Map(), this.noMeta = /* @__PURE__ */ new Map(), this.noMetaByName = /* @__PURE__ */ new Map();
326
+ let i = new Set(n.map((e) => e.code)), a = F(this.rules, this.byName), s = F(this.restrictions, this.restrictionsByName), l = F(this.noMeta, this.noMetaByName);
327
+ for (let [e, t] of Object.entries(r)) l(e, t);
328
+ for (let [t, n] of Object.entries(e ?? {})) {
329
+ if (n === !1) {
330
+ a(t, !1);
331
+ continue;
405
332
  }
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);
333
+ if (!n || typeof n != "object") continue;
334
+ let e = {};
335
+ for (let [r, i] of Object.entries(n)) {
336
+ if (!i) continue;
337
+ let n = o(u(i)), a = c(n);
338
+ (a === `/${r}` || a.startsWith(`/${r}/`)) && console.warn(`[i18n] globalLocaleRoutes["${t}"].${r} = "${i}" starts with the locale code; the locale prefix is added automatically.`), e[r] = n;
409
339
  }
340
+ a(t, e);
410
341
  }
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);
342
+ for (let [e, n] of Object.entries(t)) {
343
+ let t = n.filter((e) => i.has(e));
344
+ t.length && s(e, t);
419
345
  }
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
346
  }
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));
347
+ get(e, t) {
348
+ return this.rules.get(f(e)) ?? (t ? this.byName.get(t) : void 0);
430
349
  }
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 _;
350
+ allowedLocales(e, t) {
351
+ return this.restrictions.get(f(e)) ?? (t ? this.restrictionsByName.get(t) : void 0);
455
352
  }
456
- buildChildRouteName(e, t, n) {
457
- return t === !0 ? `${n.localizedRouteNamePrefix}${e}` : typeof t == "string" ? `${n.localizedRouteNamePrefix}${e}-${t}` : e;
353
+ disableMeta(e, t) {
354
+ return this.noMeta.get(f(e)) ?? (t ? this.noMetaByName.get(t) : void 0);
458
355
  }
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
- });
356
+ customKeysUnder(e, t) {
357
+ let n = [];
358
+ for (let [r, i] of this.rules) (r === e || r.startsWith(`${e}/`)) && i && i[t] && n.push(r);
359
+ return n;
472
360
  }
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;
361
+ customPath(e, t) {
362
+ let n = this.rules.get(f(e));
363
+ return n ? n[t] : void 0;
475
364
  }
476
365
  };
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
- }
366
+ function F(e, t) {
367
+ let n = /* @__PURE__ */ new Set();
368
+ return (r, i) => {
369
+ let a = r.startsWith("/");
370
+ a || t.set(r, i);
371
+ let o = f(r);
372
+ a && e.has(o) && !n.has(o) || (e.set(o, i), a ? n.add(o) : n.delete(o));
373
+ };
374
+ }
375
+ function I(e, t, n, r) {
376
+ let i = new P({}, e, t).allowedLocales(n, void 0);
377
+ return !i || i.includes(r);
487
378
  }
488
- //#endregion
489
- //#region src/route-generator.ts
490
- var H = class {
379
+ // src/route-generator.ts
380
+ function L(e, t) {
381
+ let n = /* @__PURE__ */ new Map();
382
+ for (let t of e) n.set(t.code, {
383
+ ...t,
384
+ ...n.get(t.code)
385
+ });
386
+ let r = [...n.values()], i = r.filter((e) => !e.disabled);
387
+ return {
388
+ locales: i,
389
+ disabledLocales: r.filter((e) => e.disabled),
390
+ defaultLocale: i.find((e) => e.code === t) ?? { code: t }
391
+ };
392
+ }
393
+ var R = class {
491
394
  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);
395
+ this.localizedPaths = /* @__PURE__ */ new Map();
396
+ let t = L(e.locales, e.defaultLocaleCode);
397
+ this.locales = N(t.locales, e.defaultLocaleCode), this.disabledLocales = t.disabledLocales, this.defaultLocale = t.defaultLocale, this.strategy = e.strategy, this.routeLocales = e.routeLocales ?? {}, this.rules = new P(e.globalLocaleRoutes, this.routeLocales, this.locales, e.routeDisableMeta), this.options = e;
398
+ let n = e.strategy === "prefix_except_default" || e.strategy === "prefix_and_default";
399
+ this.hostDefaults = n ? this.locales.filter((e) => e.baseDefault && e.code !== this.defaultLocale.code).map((e) => e.code) : [], this.parentKeys = (e.parentPaths ?? []).map(f);
511
400
  }
512
401
  extendPages(e) {
513
- let t = new A({
514
- locales: this.locales,
515
- defaultLocaleCode: this.defaultLocale.code,
402
+ this.localizedPaths = /* @__PURE__ */ new Map();
403
+ let t = D(e, {
516
404
  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 {}
405
+ locales: this.locales.map((e) => e.code),
406
+ defaultLocale: this.defaultLocale.code,
407
+ rules: this.rules,
408
+ namePrefix: this.options.localizedRouteNamePrefix ?? "localized-",
409
+ customRegex: this.options.customRegexMatcher,
410
+ excludePatterns: this.options.excludePatterns,
411
+ apiBaseUrl: this.options.apiBaseUrl,
412
+ noPrefixRedirect: this.options.noPrefixRedirect,
413
+ redirects: this.options.redirects,
414
+ hostDefaults: this.hostDefaults
415
+ }, this.localizedPaths);
416
+ e.splice(0, e.length, ...t);
551
417
  }
552
418
  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}`;
419
+ let n = f(e);
420
+ return this.withPrefix(this.localizedPaths.get(n)?.[t] ?? this.rules.customPath(e, t) ?? e, t);
421
+ }
422
+ withPrefix(e, t) {
423
+ if (!(this.strategy === "prefix" || this.strategy === "prefix_and_default" || this.strategy === "prefix_except_default" && t !== this.defaultLocale.code)) return c(e);
424
+ let n = s(c(e));
425
+ return n ? `/${t}/${n}` : `/${t}`;
426
+ }
427
+ localizedKey(e, t) {
428
+ let n = this.rules.customPath(e, t), r = this.parentKeys.filter((t) => e.startsWith(`${t}/`)).sort((e, t) => t.length - e.length)[0];
429
+ if (!r) return c(n ?? e);
430
+ let i = this.localizedKey(r, t);
431
+ return l(i, n === void 0 ? e.slice(r.length + 1) : p(i, n));
432
+ }
433
+ resolveLocalizedRulePaths(e, t) {
434
+ let n = /* @__PURE__ */ new Set([this.resolveLocalizedPath(e, t)]);
435
+ if (e.endsWith("/**")) {
436
+ let r = f(e.slice(0, -3));
437
+ for (let e of this.rules.customKeysUnder(r, t)) {
438
+ let i = m(this.localizedKey(e, t));
439
+ i && n.add(this.withPrefix(e === r ? `${i}/**` : i, t));
440
+ }
441
+ }
442
+ if (this.hostDefaults.includes(t)) for (let e of [...n]) n.add(`/${e.split("/").slice(2).join("/")}`);
443
+ return [...n];
559
444
  }
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;
445
+ ensureTranslationFilesExist(e, t, r, i) {
446
+ for (let a of this.locales) if (z(n.join(r, t, `${a.code}.json`)), !i) for (let i of e) z(n.join(r, t, "pages", `${i}/${a.code}.json`));
564
447
  }
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];
448
+ generateDataRoutes(e, t, n) {
449
+ let r = new Set(w(e)), i = [];
450
+ for (let e of this.locales) if (i.push(`/${t}/index/${e.code}/data.json`), !n) for (let n of r) i.push(`/${t}/${n}/${e.code}/data.json`);
451
+ return i;
570
452
  }
571
453
  };
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 };
454
+ function z(e) {
455
+ try {
456
+ i(n.dirname(e), { recursive: !0 }), r(e) || a(e, "{}", "utf-8");
457
+ } catch {}
458
+ }
459
+ export { R as RouteGenerator, P as Rules, D as generateRoutes, I as isLocaleAllowedForUnlocalizedRoute, T as localeMatcherSource, E as localesOutsideMatcher, b as nameOfPath, o as normalizePath, u as normalizeRouteKey, w as pageNames, f as routeKey };