@i18n-micro/preact 1.2.7 → 1.2.9
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.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -3
- package/dist/index.d.ts +16 -3
- package/dist/index.mjs +397 -476
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1,482 +1,403 @@
|
|
|
1
|
-
import { BaseI18n as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
{ value: s },
|
|
15
|
-
t ? p(
|
|
16
|
-
O.Provider,
|
|
17
|
-
{ value: t },
|
|
18
|
-
o ? p(
|
|
19
|
-
V.Provider,
|
|
20
|
-
{ value: o },
|
|
21
|
-
e ? p(q.Provider, { value: e }, r) : r
|
|
22
|
-
) : r
|
|
23
|
-
) : r
|
|
24
|
-
);
|
|
1
|
+
import { BaseI18n as e, FormatService as t, createReactiveI18nStore as n, defaultPlural as r, interpolate as i } from "@i18n-micro/core";
|
|
2
|
+
import { Fragment as a, createContext as o, h as s } from "preact";
|
|
3
|
+
import { useContext as c, useEffect as l, useRef as u, useState as d } from "preact/hooks";
|
|
4
|
+
//#region src/injection.ts
|
|
5
|
+
var f = o(null), p = o(null), m = o(null), h = o(null), g = () => {
|
|
6
|
+
let e = c(f);
|
|
7
|
+
if (!e) throw Error("[i18n-micro] I18nContext not found. Make sure I18nProvider is used.");
|
|
8
|
+
return e;
|
|
9
|
+
}, _ = () => c(p), v = () => c(m), y = () => c(h);
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/context.tsx
|
|
12
|
+
function b({ i18n: e, locales: t, defaultLocale: n, routingStrategy: r, children: i }) {
|
|
13
|
+
return s(f.Provider, { value: e }, t ? s(p.Provider, { value: t }, n ? s(m.Provider, { value: n }, r ? s(h.Provider, { value: r }, i) : i) : i) : i);
|
|
25
14
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const v = l, w = {
|
|
131
|
-
...h,
|
|
132
|
-
href: x,
|
|
133
|
-
style: k
|
|
134
|
-
};
|
|
135
|
-
return p(v, w, m);
|
|
136
|
-
}
|
|
137
|
-
return p(
|
|
138
|
-
"a",
|
|
139
|
-
{
|
|
140
|
-
...h,
|
|
141
|
-
href: x,
|
|
142
|
-
style: k,
|
|
143
|
-
onClick: T
|
|
144
|
-
},
|
|
145
|
-
m
|
|
146
|
-
);
|
|
15
|
+
var x = (e) => {
|
|
16
|
+
let t = g(), n = y(), r = _(), i = v(), [, a] = d(0);
|
|
17
|
+
l(() => t.subscribe(() => {
|
|
18
|
+
a((e) => e + 1);
|
|
19
|
+
}), [t]);
|
|
20
|
+
let o = e?.locales || r || [], s = e?.defaultLocale || i || t.locale, c = (e, r) => n?.resolvePath ? n.resolvePath(e, r || t.locale) : e;
|
|
21
|
+
return {
|
|
22
|
+
t: t.t.bind(t),
|
|
23
|
+
ts: t.ts.bind(t),
|
|
24
|
+
tc: t.tc.bind(t),
|
|
25
|
+
tn: t.tn.bind(t),
|
|
26
|
+
td: t.td.bind(t),
|
|
27
|
+
tdr: t.tdr.bind(t),
|
|
28
|
+
has: t.has.bind(t),
|
|
29
|
+
get locale() {
|
|
30
|
+
return t.locale;
|
|
31
|
+
},
|
|
32
|
+
get fallbackLocale() {
|
|
33
|
+
return t.fallbackLocale;
|
|
34
|
+
},
|
|
35
|
+
get currentRoute() {
|
|
36
|
+
return t.currentRoute;
|
|
37
|
+
},
|
|
38
|
+
setLocale: (e) => {
|
|
39
|
+
t.locale = e;
|
|
40
|
+
},
|
|
41
|
+
setRoute: t.setRoute.bind(t),
|
|
42
|
+
getRoute: t.getRoute.bind(t),
|
|
43
|
+
getLocales: () => o,
|
|
44
|
+
defaultLocale: () => s,
|
|
45
|
+
getLocaleName: () => o.find((e) => e.code === t.locale)?.displayName || null,
|
|
46
|
+
switchLocale: (e) => {
|
|
47
|
+
if (t.locale = e, n) {
|
|
48
|
+
let t = n.getCurrentPath(), r = c(t, e);
|
|
49
|
+
n.push(typeof r == "string" ? { path: r } : { path: r.path || "/" });
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
localeRoute: c,
|
|
53
|
+
localePath: (e, t) => {
|
|
54
|
+
let n = c(e, t);
|
|
55
|
+
return typeof n == "string" ? n : n.path || "/";
|
|
56
|
+
},
|
|
57
|
+
addTranslations: t.addTranslations.bind(t),
|
|
58
|
+
addRouteTranslations: t.addRouteTranslations.bind(t),
|
|
59
|
+
clearCache: t.clearCache.bind(t)
|
|
60
|
+
};
|
|
61
|
+
}, S = (e) => {
|
|
62
|
+
let { prefix: t, groupClass: n, children: r, ...i } = e, { t: a, getRoute: o } = x(), c = (e, n) => {
|
|
63
|
+
let r = a(`${t}.${e}`, n, void 0, o());
|
|
64
|
+
return typeof r == "string" ? r : String(r);
|
|
65
|
+
}, l = ["i18n-group", n].filter(Boolean).join(" "), u = typeof r == "function" ? r({
|
|
66
|
+
prefix: t,
|
|
67
|
+
t: c
|
|
68
|
+
}) : r;
|
|
69
|
+
return s("div", {
|
|
70
|
+
...i,
|
|
71
|
+
className: l
|
|
72
|
+
}, u);
|
|
73
|
+
}, C = (e) => {
|
|
74
|
+
let t = x(), n = y(), { to: r, activeStyle: i, localeRoute: a, children: o, ...c } = e, l = a || t.localeRoute, u = () => typeof r == "string" && /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(r), d = () => {
|
|
75
|
+
if (u() && typeof r == "string") return /^https?:\/\//.test(r) ? r : `https://${r}`;
|
|
76
|
+
}, f = () => {
|
|
77
|
+
if (u()) return typeof r == "string" ? r : r?.path || "/";
|
|
78
|
+
if (l) {
|
|
79
|
+
let e = l(r);
|
|
80
|
+
return typeof e == "string" ? e : e.path || "/";
|
|
81
|
+
}
|
|
82
|
+
if (!n?.resolvePath) return typeof r == "string" ? r : r.path || "/";
|
|
83
|
+
let e = n.resolvePath(r, t.locale);
|
|
84
|
+
return typeof e == "string" ? e : e.path || "/";
|
|
85
|
+
}, p = (() => {
|
|
86
|
+
if (u() || !n) return !1;
|
|
87
|
+
let e = n.getCurrentPath(), t = f(), r = e.replace(/\/$/, ""), i = t.replace(/\/$/, "");
|
|
88
|
+
return !!(r === i || r.startsWith(`${i}/`));
|
|
89
|
+
})() && i || {}, m = f(), h = (t) => {
|
|
90
|
+
e.onClick && e.onClick(t), !t.defaultPrevented && !t.button && !t.metaKey && !t.ctrlKey && n && !u() && (t.preventDefault(), n.push({ path: m }));
|
|
91
|
+
};
|
|
92
|
+
if (u()) return s("a", {
|
|
93
|
+
...c,
|
|
94
|
+
href: d(),
|
|
95
|
+
style: p,
|
|
96
|
+
target: "_blank",
|
|
97
|
+
rel: "noopener noreferrer"
|
|
98
|
+
}, o);
|
|
99
|
+
if (n?.linkComponent) {
|
|
100
|
+
let e = n.linkComponent;
|
|
101
|
+
if (typeof e == "string") return s(e, {
|
|
102
|
+
...c,
|
|
103
|
+
href: m,
|
|
104
|
+
style: p
|
|
105
|
+
}, o);
|
|
106
|
+
let t = e, r = {
|
|
107
|
+
...c,
|
|
108
|
+
href: m,
|
|
109
|
+
style: p
|
|
110
|
+
};
|
|
111
|
+
return s(t, r, o);
|
|
112
|
+
}
|
|
113
|
+
return s("a", {
|
|
114
|
+
...c,
|
|
115
|
+
href: m,
|
|
116
|
+
style: p,
|
|
117
|
+
onClick: h
|
|
118
|
+
}, o);
|
|
147
119
|
};
|
|
148
|
-
|
|
149
|
-
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/components/I18nSwitcher.tsx
|
|
122
|
+
function w(e, t) {
|
|
123
|
+
return typeof e == "function" ? e() : typeof e == "string" ? e : t;
|
|
150
124
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
125
|
+
var T = (e) => {
|
|
126
|
+
let { locales: t, currentLocale: n, getLocaleName: r, switchLocale: i, localeRoute: a, customLabels: o = {}, customWrapperStyle: c, customButtonStyle: f, customDropdownStyle: p, customItemStyle: m, customLinkStyle: h, customActiveLinkStyle: v, customDisabledLinkStyle: b = {}, customIconStyle: S, ...C } = e, T = x(), E = g(), D = y(), O = _(), [k, A] = d(!1), j = u(null), M = t || O || T.getLocales() || [], N = M.filter((e) => !e.disabled), P = w(n, T.locale), F = M.some((e) => e.code === P && e.disabled), I = r ? r() : T.getLocaleName(), L = (e) => {
|
|
127
|
+
e && (e.stopPropagation(), e.preventDefault()), A(!k);
|
|
128
|
+
}, R = (e) => o[e.code] || e.displayName || e.code, z = () => {
|
|
129
|
+
let e = N.find((e) => e.code === P);
|
|
130
|
+
return e ? R(e) : I || P;
|
|
131
|
+
}, B = (t) => {
|
|
132
|
+
if (A(!1), i) {
|
|
133
|
+
i(t);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (E.locale = t, !D) return;
|
|
137
|
+
let n = D.getCurrentPath(), r = e.localeRoute ? (() => {
|
|
138
|
+
let r = e.localeRoute(n, t);
|
|
139
|
+
return typeof r == "string" ? r : r.path || "/";
|
|
140
|
+
})() : D?.resolvePath ? (() => {
|
|
141
|
+
let e = D.resolvePath(n, t);
|
|
142
|
+
return typeof e == "string" ? e : e.path || "/";
|
|
143
|
+
})() : n;
|
|
144
|
+
D.push({ path: r });
|
|
145
|
+
}, V = {
|
|
146
|
+
position: "relative",
|
|
147
|
+
display: "inline-block",
|
|
148
|
+
verticalAlign: "middle"
|
|
149
|
+
}, H = {
|
|
150
|
+
padding: "4px 12px",
|
|
151
|
+
fontSize: "16px",
|
|
152
|
+
cursor: "pointer",
|
|
153
|
+
backgroundColor: "#fff",
|
|
154
|
+
border: "1px solid #333",
|
|
155
|
+
transition: "background-color 0.3s ease",
|
|
156
|
+
display: "flex",
|
|
157
|
+
alignItems: "center",
|
|
158
|
+
justifyContent: "space-between"
|
|
159
|
+
}, U = {
|
|
160
|
+
position: "absolute",
|
|
161
|
+
top: "100%",
|
|
162
|
+
left: "0",
|
|
163
|
+
zIndex: 1e3,
|
|
164
|
+
backgroundColor: "#fff",
|
|
165
|
+
border: "1px solid #333",
|
|
166
|
+
listStyle: "none",
|
|
167
|
+
padding: "0",
|
|
168
|
+
margin: "4px 0 0 0",
|
|
169
|
+
minWidth: "150px",
|
|
170
|
+
boxShadow: "0 2px 8px rgba(0,0,0,0.15)"
|
|
171
|
+
}, W = {
|
|
172
|
+
margin: "0",
|
|
173
|
+
padding: "0"
|
|
174
|
+
}, G = {
|
|
175
|
+
display: "block",
|
|
176
|
+
padding: "8px 12px",
|
|
177
|
+
color: "#333",
|
|
178
|
+
textDecoration: "none",
|
|
179
|
+
transition: "background-color 0.3s ease",
|
|
180
|
+
cursor: "pointer"
|
|
181
|
+
}, K = {
|
|
182
|
+
fontWeight: "bold",
|
|
183
|
+
color: "#007bff",
|
|
184
|
+
cursor: "not-allowed"
|
|
185
|
+
}, q = {
|
|
186
|
+
marginLeft: "8px",
|
|
187
|
+
display: "inline-block",
|
|
188
|
+
transition: "transform 0.3s ease"
|
|
189
|
+
}, J = { transform: "rotate(180deg)" };
|
|
190
|
+
l(() => {
|
|
191
|
+
if (!k) return;
|
|
192
|
+
let e = (e) => {
|
|
193
|
+
if (!k) return;
|
|
194
|
+
let t = e.target;
|
|
195
|
+
if (!t || !j.current) return;
|
|
196
|
+
let n = j.current.contains(t), r = t.closest(".i18n-switcher-button") !== null;
|
|
197
|
+
!n && !r && A(!1);
|
|
198
|
+
};
|
|
199
|
+
return document.addEventListener("click", e), () => {
|
|
200
|
+
document.removeEventListener("click", e);
|
|
201
|
+
};
|
|
202
|
+
}, [k]);
|
|
203
|
+
let Y = {
|
|
204
|
+
...V,
|
|
205
|
+
...c
|
|
206
|
+
}, X = {
|
|
207
|
+
...H,
|
|
208
|
+
...f,
|
|
209
|
+
...F ? b : {}
|
|
210
|
+
}, Z = {
|
|
211
|
+
...U,
|
|
212
|
+
...p
|
|
213
|
+
}, Q = {
|
|
214
|
+
...W,
|
|
215
|
+
...m
|
|
216
|
+
}, $ = {
|
|
217
|
+
...q,
|
|
218
|
+
...k ? J : {},
|
|
219
|
+
...S
|
|
220
|
+
}, ee = N.map((e) => {
|
|
221
|
+
let t = e.code === P, n = {
|
|
222
|
+
...G,
|
|
223
|
+
...t ? K : {},
|
|
224
|
+
...h,
|
|
225
|
+
...t ? v : {},
|
|
226
|
+
width: "100%",
|
|
227
|
+
textAlign: "left",
|
|
228
|
+
border: "none",
|
|
229
|
+
background: "transparent"
|
|
230
|
+
};
|
|
231
|
+
return s("li", {
|
|
232
|
+
key: e.code,
|
|
233
|
+
style: Q
|
|
234
|
+
}, s("button", {
|
|
235
|
+
type: "button",
|
|
236
|
+
className: `switcher-locale-${e.code}`,
|
|
237
|
+
style: n,
|
|
238
|
+
onClick: (t) => {
|
|
239
|
+
t.preventDefault(), t.stopPropagation(), B(e.code);
|
|
240
|
+
}
|
|
241
|
+
}, R(e)));
|
|
242
|
+
});
|
|
243
|
+
return s("div", {
|
|
244
|
+
ref: j,
|
|
245
|
+
className: "i18n-switcher-wrapper",
|
|
246
|
+
style: Y,
|
|
247
|
+
...C
|
|
248
|
+
}, s("button", {
|
|
249
|
+
type: "button",
|
|
250
|
+
className: "i18n-switcher-button",
|
|
251
|
+
style: X,
|
|
252
|
+
onClick: (e) => {
|
|
253
|
+
e.preventDefault(), e.stopPropagation(), L(e);
|
|
254
|
+
},
|
|
255
|
+
"aria-haspopup": "true",
|
|
256
|
+
"aria-expanded": k
|
|
257
|
+
}, s("span", null, z()), s("span", { style: $ }, "▼")), k ? s("ul", {
|
|
258
|
+
className: "i18n-switcher-dropdown",
|
|
259
|
+
style: Z
|
|
260
|
+
}, ...ee) : null);
|
|
261
|
+
}, E = (e) => {
|
|
262
|
+
let { t, tc: n, tn: r, td: i, tdr: o, locale: c, getRoute: l } = x(), { keypath: u, params: d, tag: f = "span", plural: p, defaultValue: m, html: h = !1, hideIfEmpty: g = !1, customPluralRule: _, number: v, date: y, relativeDate: b, ...S } = e, C = l(), w = (e, t, n) => s(e, t, n);
|
|
263
|
+
if (v !== void 0) {
|
|
264
|
+
let e = t(u, {
|
|
265
|
+
number: r(Number(v)),
|
|
266
|
+
...d || {}
|
|
267
|
+
}, void 0, C), n = typeof e == "string" ? e : String(e);
|
|
268
|
+
return h ? w(f, {
|
|
269
|
+
...S,
|
|
270
|
+
dangerouslySetInnerHTML: { __html: n }
|
|
271
|
+
}, void 0) : w(f, S, n);
|
|
272
|
+
}
|
|
273
|
+
if (y !== void 0) {
|
|
274
|
+
let e = t(u, {
|
|
275
|
+
date: i(y),
|
|
276
|
+
...d || {}
|
|
277
|
+
}, void 0, C), n = typeof e == "string" ? e : String(e);
|
|
278
|
+
return h ? w(f, {
|
|
279
|
+
...S,
|
|
280
|
+
dangerouslySetInnerHTML: { __html: n }
|
|
281
|
+
}, void 0) : w(f, S, n);
|
|
282
|
+
}
|
|
283
|
+
if (b !== void 0) {
|
|
284
|
+
let e = t(u, {
|
|
285
|
+
relativeDate: o(b),
|
|
286
|
+
...d || {}
|
|
287
|
+
}, void 0, C), n = typeof e == "string" ? e : String(e);
|
|
288
|
+
return h ? w(f, {
|
|
289
|
+
...S,
|
|
290
|
+
dangerouslySetInnerHTML: { __html: n }
|
|
291
|
+
}, void 0) : w(f, S, n);
|
|
292
|
+
}
|
|
293
|
+
if (p !== void 0) {
|
|
294
|
+
let e = Number.parseInt(p.toString(), 10), r;
|
|
295
|
+
return r = _ ? _(u, e, d || {}, c, (e, n, r) => {
|
|
296
|
+
let i = t(e, n, r, C);
|
|
297
|
+
return typeof i == "string" ? i : String(i);
|
|
298
|
+
}) || "" : n(u, {
|
|
299
|
+
count: e,
|
|
300
|
+
...d || {}
|
|
301
|
+
}, m), h ? w(f, {
|
|
302
|
+
...S,
|
|
303
|
+
dangerouslySetInnerHTML: { __html: r }
|
|
304
|
+
}, void 0) : w(f, S, r);
|
|
305
|
+
}
|
|
306
|
+
let T = t(u, d, m, C), E = typeof T == "string" ? T : String(T);
|
|
307
|
+
return g && !E.trim() ? m ? s(a, null, m) : null : h ? w(f, {
|
|
308
|
+
...S,
|
|
309
|
+
dangerouslySetInnerHTML: { __html: E }
|
|
310
|
+
}, void 0) : w(f, S, E);
|
|
311
|
+
}, D = class extends e {
|
|
312
|
+
store;
|
|
313
|
+
storage;
|
|
314
|
+
constructor(e) {
|
|
315
|
+
let t = { translations: /* @__PURE__ */ new Map() };
|
|
316
|
+
if (super({
|
|
317
|
+
storage: t,
|
|
318
|
+
plural: e.plural,
|
|
319
|
+
missingWarn: e.missingWarn,
|
|
320
|
+
missingHandler: e.missingHandler
|
|
321
|
+
}), this.storage = t, this.store = n({
|
|
322
|
+
locale: e.locale,
|
|
323
|
+
fallbackLocale: e.fallbackLocale || e.locale
|
|
324
|
+
}), e.messages) for (let [t, n] of Object.entries(e.messages)) this.helper.loadTranslations(t, n);
|
|
325
|
+
}
|
|
326
|
+
subscribe = (e) => this.store.subscribe(e);
|
|
327
|
+
getSnapshot = () => this.store.getSnapshot();
|
|
328
|
+
get locale() {
|
|
329
|
+
return this.store.getLocale();
|
|
330
|
+
}
|
|
331
|
+
set locale(e) {
|
|
332
|
+
this.store.setLocale(e);
|
|
333
|
+
}
|
|
334
|
+
get fallbackLocale() {
|
|
335
|
+
return this.store.getFallbackLocale();
|
|
336
|
+
}
|
|
337
|
+
set fallbackLocale(e) {
|
|
338
|
+
this.store.setFallbackLocale(e);
|
|
339
|
+
}
|
|
340
|
+
get currentRoute() {
|
|
341
|
+
return this.store.getRoute();
|
|
342
|
+
}
|
|
343
|
+
setRoute(e) {
|
|
344
|
+
this.store.setRoute(e);
|
|
345
|
+
}
|
|
346
|
+
getLocale() {
|
|
347
|
+
return this.store.getLocale();
|
|
348
|
+
}
|
|
349
|
+
getFallbackLocale() {
|
|
350
|
+
return this.store.getFallbackLocale();
|
|
351
|
+
}
|
|
352
|
+
getRoute() {
|
|
353
|
+
return this.store.getRoute();
|
|
354
|
+
}
|
|
355
|
+
addTranslations(e, t, n = !0) {
|
|
356
|
+
super.loadTranslationsCore(e, t, n), this.store.notify();
|
|
357
|
+
}
|
|
358
|
+
addRouteTranslations(e, t, n, r = !0) {
|
|
359
|
+
super.loadRouteTranslationsCore(e, t, n, r), this.store.notify();
|
|
360
|
+
}
|
|
361
|
+
clearCache() {
|
|
362
|
+
super.clearCache(), this.store.notify();
|
|
363
|
+
}
|
|
364
|
+
onTranslationsChanged() {
|
|
365
|
+
this.store.notify();
|
|
366
|
+
}
|
|
366
367
|
};
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
storage;
|
|
370
|
-
constructor(t) {
|
|
371
|
-
const o = {
|
|
372
|
-
translations: /* @__PURE__ */ new Map()
|
|
373
|
-
};
|
|
374
|
-
if (super({
|
|
375
|
-
storage: o,
|
|
376
|
-
plural: t.plural,
|
|
377
|
-
missingWarn: t.missingWarn,
|
|
378
|
-
missingHandler: t.missingHandler
|
|
379
|
-
}), this.storage = o, this.store = dt({
|
|
380
|
-
locale: t.locale,
|
|
381
|
-
fallbackLocale: t.fallbackLocale || t.locale
|
|
382
|
-
}), t.messages)
|
|
383
|
-
for (const [e, r] of Object.entries(t.messages))
|
|
384
|
-
this.helper.loadTranslations(e, r);
|
|
385
|
-
}
|
|
386
|
-
subscribe = (t) => this.store.subscribe(t);
|
|
387
|
-
getSnapshot = () => this.store.getSnapshot();
|
|
388
|
-
get locale() {
|
|
389
|
-
return this.store.getLocale();
|
|
390
|
-
}
|
|
391
|
-
set locale(t) {
|
|
392
|
-
this.store.setLocale(t);
|
|
393
|
-
}
|
|
394
|
-
get fallbackLocale() {
|
|
395
|
-
return this.store.getFallbackLocale();
|
|
396
|
-
}
|
|
397
|
-
set fallbackLocale(t) {
|
|
398
|
-
this.store.setFallbackLocale(t);
|
|
399
|
-
}
|
|
400
|
-
get currentRoute() {
|
|
401
|
-
return this.store.getRoute();
|
|
402
|
-
}
|
|
403
|
-
setRoute(t) {
|
|
404
|
-
this.store.setRoute(t);
|
|
405
|
-
}
|
|
406
|
-
getLocale() {
|
|
407
|
-
return this.store.getLocale();
|
|
408
|
-
}
|
|
409
|
-
getFallbackLocale() {
|
|
410
|
-
return this.store.getFallbackLocale();
|
|
411
|
-
}
|
|
412
|
-
getRoute() {
|
|
413
|
-
return this.store.getRoute();
|
|
414
|
-
}
|
|
415
|
-
addTranslations(t, o, e = !0) {
|
|
416
|
-
super.loadTranslationsCore(t, o, e), this.store.notify();
|
|
417
|
-
}
|
|
418
|
-
addRouteTranslations(t, o, e, r = !0) {
|
|
419
|
-
super.loadRouteTranslationsCore(t, o, e, r), this.store.notify();
|
|
420
|
-
}
|
|
421
|
-
clearCache() {
|
|
422
|
-
super.clearCache(), this.store.notify();
|
|
423
|
-
}
|
|
424
|
-
onTranslationsChanged() {
|
|
425
|
-
this.store.notify();
|
|
426
|
-
}
|
|
368
|
+
function O(e) {
|
|
369
|
+
return new D(e);
|
|
427
370
|
}
|
|
428
|
-
|
|
429
|
-
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region src/router/adapter.tsx
|
|
373
|
+
function k(e, t) {
|
|
374
|
+
let n = e.map((e) => e.code), r = (e, r) => {
|
|
375
|
+
let i = (typeof e == "string" ? e : e.path || "/").split("/").filter(Boolean), a = i[0];
|
|
376
|
+
a !== void 0 && n.includes(a) && i.shift();
|
|
377
|
+
let o = `/${i.join("/")}`;
|
|
378
|
+
return r === t ? o : `/${r}${o === "/" ? "" : o}`;
|
|
379
|
+
};
|
|
380
|
+
return {
|
|
381
|
+
linkComponent: void 0,
|
|
382
|
+
getCurrentPath: () => typeof window < "u" ? window.location.pathname : "/",
|
|
383
|
+
push: (e) => {
|
|
384
|
+
typeof window < "u" && (window.history.pushState({}, "", e.path), window.dispatchEvent(new Event("popstate")));
|
|
385
|
+
},
|
|
386
|
+
replace: (e) => {
|
|
387
|
+
typeof window < "u" && (window.history.replaceState({}, "", e.path), window.dispatchEvent(new Event("popstate")));
|
|
388
|
+
},
|
|
389
|
+
resolvePath: (e, t) => r(e, t),
|
|
390
|
+
getRoute: () => typeof window < "u" ? {
|
|
391
|
+
fullPath: window.location.pathname + window.location.search,
|
|
392
|
+
query: Object.fromEntries(new URLSearchParams(window.location.search))
|
|
393
|
+
} : {
|
|
394
|
+
fullPath: "/",
|
|
395
|
+
query: {}
|
|
396
|
+
}
|
|
397
|
+
};
|
|
430
398
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
return L === t ? c : `/${L}${c === "/" ? "" : c}`;
|
|
437
|
-
};
|
|
438
|
-
return {
|
|
439
|
-
// Просто рендерим <a>, навигацию перехватит onClick в I18nLink
|
|
440
|
-
linkComponent: void 0,
|
|
441
|
-
getCurrentPath: () => typeof window < "u" ? window.location.pathname : "/",
|
|
442
|
-
push: (r) => {
|
|
443
|
-
typeof window < "u" && (window.history.pushState({}, "", r.path), window.dispatchEvent(new Event("popstate")));
|
|
444
|
-
},
|
|
445
|
-
replace: (r) => {
|
|
446
|
-
typeof window < "u" && (window.history.replaceState({}, "", r.path), window.dispatchEvent(new Event("popstate")));
|
|
447
|
-
},
|
|
448
|
-
resolvePath: (r, L) => e(r, L),
|
|
449
|
-
getRoute: () => typeof window < "u" ? {
|
|
450
|
-
fullPath: window.location.pathname + window.location.search,
|
|
451
|
-
query: Object.fromEntries(new URLSearchParams(window.location.search))
|
|
452
|
-
} : {
|
|
453
|
-
fullPath: "/",
|
|
454
|
-
query: {}
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
const xt = yt;
|
|
459
|
-
export {
|
|
460
|
-
Tt as FormatService,
|
|
461
|
-
F as I18nContext,
|
|
462
|
-
V as I18nDefaultLocaleContext,
|
|
463
|
-
Pt as I18nGroup,
|
|
464
|
-
St as I18nLink,
|
|
465
|
-
O as I18nLocalesContext,
|
|
466
|
-
wt as I18nProvider,
|
|
467
|
-
q as I18nRouterContext,
|
|
468
|
-
kt as I18nSwitcher,
|
|
469
|
-
Ct as I18nT,
|
|
470
|
-
mt as PreactI18n,
|
|
471
|
-
yt as createBrowserHistoryAdapter,
|
|
472
|
-
Rt as createI18n,
|
|
473
|
-
xt as createPreactRouterAdapter,
|
|
474
|
-
Nt as defaultPlural,
|
|
475
|
-
Et as interpolate,
|
|
476
|
-
$ as useI18n,
|
|
477
|
-
K as useI18nContext,
|
|
478
|
-
ht as useI18nDefaultLocale,
|
|
479
|
-
U as useI18nLocales,
|
|
480
|
-
M as useI18nRouter
|
|
481
|
-
};
|
|
482
|
-
//# sourceMappingURL=index.mjs.map
|
|
399
|
+
var A = k;
|
|
400
|
+
//#endregion
|
|
401
|
+
export { t as FormatService, f as I18nContext, m as I18nDefaultLocaleContext, S as I18nGroup, C as I18nLink, p as I18nLocalesContext, b as I18nProvider, h as I18nRouterContext, T as I18nSwitcher, E as I18nT, D as PreactI18n, k as createBrowserHistoryAdapter, O as createI18n, A as createPreactRouterAdapter, r as defaultPlural, i as interpolate, x as useI18n, g as useI18nContext, v as useI18nDefaultLocale, _ as useI18nLocales, y as useI18nRouter };
|
|
402
|
+
|
|
403
|
+
//# sourceMappingURL=index.mjs.map
|