@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/README.md +66 -190
- package/dist/generate.d.cts +33 -0
- package/dist/generate.d.ts +33 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.mjs +403 -517
- package/dist/paths.d.cts +32 -0
- package/dist/paths.d.ts +32 -0
- package/dist/route-generator.d.cts +58 -0
- package/dist/route-generator.d.ts +35 -36
- package/dist/rules.d.cts +35 -0
- package/dist/rules.d.ts +35 -0
- package/package.json +21 -21
- package/dist/core/alias.d.ts +0 -6
- package/dist/core/builder.d.ts +0 -20
- package/dist/core/context.d.ts +0 -53
- package/dist/core/localization-disabled.d.ts +0 -3
- package/dist/core/localized-paths.d.ts +0 -20
- package/dist/locale-route-access.d.ts +0 -6
- package/dist/strategies/abstract.d.ts +0 -30
- package/dist/strategies/factory.d.ts +0 -3
- package/dist/strategies/no-prefix.d.ts +0 -13
- package/dist/strategies/prefix-and-default.d.ts +0 -8
- package/dist/strategies/prefix-except-default.d.ts +0 -12
- package/dist/strategies/prefix.d.ts +0 -7
- package/dist/strategies/types.d.ts +0 -17
- package/dist/utils/common.d.ts +0 -9
- package/dist/utils/index.d.cts +0 -3
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/locales.d.ts +0 -9
- package/dist/utils/path.d.ts +0 -8
package/dist/index.mjs
CHANGED
|
@@ -1,573 +1,459 @@
|
|
|
1
|
-
import { isInternalPath as e } from "@i18n-micro/utils/app-path";
|
|
2
|
-
import
|
|
3
|
-
import { existsSync as
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
27
|
-
return
|
|
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
|
-
|
|
36
|
-
|
|
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
|
|
39
|
-
return
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
50
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
function
|
|
76
|
-
let
|
|
77
|
-
return
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
|
162
|
-
let i =
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
211
|
-
let
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
285
|
-
let
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
|
|
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
|
-
|
|
307
|
-
let
|
|
308
|
-
|
|
309
|
-
let r =
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
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
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
407
|
-
|
|
408
|
-
|
|
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
|
|
412
|
-
|
|
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
|
-
|
|
429
|
-
return
|
|
347
|
+
get(e, t) {
|
|
348
|
+
return this.rules.get(f(e)) ?? (t ? this.byName.get(t) : void 0);
|
|
430
349
|
}
|
|
431
|
-
|
|
432
|
-
|
|
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
|
-
|
|
457
|
-
return
|
|
353
|
+
disableMeta(e, t) {
|
|
354
|
+
return this.noMeta.get(f(e)) ?? (t ? this.noMetaByName.get(t) : void 0);
|
|
458
355
|
}
|
|
459
|
-
|
|
460
|
-
let
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
474
|
-
|
|
361
|
+
customPath(e, t) {
|
|
362
|
+
let n = this.rules.get(f(e));
|
|
363
|
+
return n ? n[t] : void 0;
|
|
475
364
|
}
|
|
476
365
|
};
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
|
494
|
-
this.locales =
|
|
495
|
-
let
|
|
496
|
-
|
|
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
|
-
|
|
514
|
-
|
|
515
|
-
defaultLocaleCode: this.defaultLocale.code,
|
|
402
|
+
this.localizedPaths = /* @__PURE__ */ new Map();
|
|
403
|
+
let t = D(e, {
|
|
516
404
|
strategy: this.strategy,
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
});
|
|
528
|
-
|
|
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 =
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
-
|
|
561
|
-
let r
|
|
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
|
-
|
|
566
|
-
let
|
|
567
|
-
|
|
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
|
-
|
|
573
|
-
|
|
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 };
|