@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.mjs CHANGED
@@ -1,482 +1,403 @@
1
- import { BaseI18n as ut, createReactiveI18nStore as dt } from "@i18n-micro/core";
2
- import { FormatService as Tt, defaultPlural as Nt, interpolate as Et } from "@i18n-micro/core";
3
- import { createContext as A, h as p, Fragment as ft } from "preact";
4
- import { useContext as H, useState as W, useEffect as z, useRef as pt } from "preact/hooks";
5
- const F = A(null), O = A(null), V = A(null), q = A(null), K = () => {
6
- const s = H(F);
7
- if (!s)
8
- throw new Error("[i18n-micro] I18nContext not found. Make sure I18nProvider is used.");
9
- return s;
10
- }, U = () => H(O), ht = () => H(V), M = () => H(q);
11
- function wt({ i18n: s, locales: t, defaultLocale: o, routingStrategy: e, children: r }) {
12
- return p(
13
- F.Provider,
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
- const $ = (s) => {
27
- const t = K(), o = M(), e = U(), r = ht(), [, L] = W(0);
28
- z(() => t.subscribe(() => {
29
- L((d) => d + 1);
30
- }), [t]);
31
- const m = s?.locales || e || [], h = s?.defaultLocale || r || t.locale, u = (a, d) => o?.resolvePath ? o.resolvePath(a, d || t.locale) : a, c = (a) => {
32
- if (t.locale = a, o) {
33
- const d = o.getCurrentPath(), f = u(d, a);
34
- o.push(typeof f == "string" ? { path: f } : { path: f.path || "/" });
35
- }
36
- };
37
- return {
38
- // Translation methods
39
- t: t.t.bind(t),
40
- ts: t.ts.bind(t),
41
- tc: t.tc.bind(t),
42
- tn: t.tn.bind(t),
43
- td: t.td.bind(t),
44
- tdr: t.tdr.bind(t),
45
- has: t.has.bind(t),
46
- // Locale management
47
- get locale() {
48
- return t.locale;
49
- },
50
- get fallbackLocale() {
51
- return t.fallbackLocale;
52
- },
53
- get currentRoute() {
54
- return t.currentRoute;
55
- },
56
- setLocale: (a) => {
57
- t.locale = a;
58
- },
59
- // Route management
60
- setRoute: t.setRoute.bind(t),
61
- getRoute: t.getRoute.bind(t),
62
- getLocales: () => m,
63
- defaultLocale: () => h,
64
- getLocaleName: () => m.find((d) => d.code === t.locale)?.displayName || null,
65
- // Router methods (always available, but navigation handled by components)
66
- switchLocale: c,
67
- localeRoute: u,
68
- localePath: (a, d) => {
69
- const f = u(a, d);
70
- return typeof f == "string" ? f : f.path || "/";
71
- },
72
- // Translation management
73
- addTranslations: t.addTranslations.bind(t),
74
- addRouteTranslations: t.addRouteTranslations.bind(t),
75
- clearCache: t.clearCache.bind(t)
76
- };
77
- }, Pt = (s) => {
78
- const { prefix: t, groupClass: o, children: e, ...r } = s, { t: L, getRoute: m } = $(), h = (a, d) => {
79
- const f = L(`${t}.${a}`, d, void 0, m());
80
- return typeof f == "string" ? f : String(f);
81
- }, u = ["i18n-group", o].filter(Boolean).join(" "), c = typeof e == "function" ? e({ prefix: t, t: h }) : e;
82
- return p("div", { ...r, className: u }, c);
83
- }, St = (s) => {
84
- const t = $(), o = M(), { to: e, activeStyle: r, localeRoute: L, children: m, ...h } = s, u = L || t.localeRoute, c = () => typeof e == "string" ? /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(e) : !1, a = () => {
85
- if (c() && typeof e == "string")
86
- return /^https?:\/\//.test(e) ? e : `https://${e}`;
87
- }, d = () => {
88
- if (c())
89
- return typeof e == "string" ? e : e?.path || "/";
90
- if (u) {
91
- const v = u(e);
92
- return typeof v == "string" ? v : v.path || "/";
93
- }
94
- if (!o?.resolvePath)
95
- return typeof e == "string" ? e : e.path || "/";
96
- const l = o.resolvePath(e, t.locale);
97
- return typeof l == "string" ? l : l.path || "/";
98
- }, k = (() => {
99
- if (c() || !o)
100
- return !1;
101
- const l = o.getCurrentPath(), v = d(), w = l.replace(/\/$/, ""), g = v.replace(/\/$/, "");
102
- return !!(w === g || w.startsWith(`${g}/`));
103
- })() ? r || {} : {}, x = d(), T = (l) => {
104
- s.onClick && s.onClick(l), !l.defaultPrevented && !l.button && !l.metaKey && !l.ctrlKey && o && !c() && (l.preventDefault(), o.push({ path: x }));
105
- };
106
- if (c())
107
- return p(
108
- "a",
109
- {
110
- ...h,
111
- href: a(),
112
- style: k,
113
- target: "_blank",
114
- rel: "noopener noreferrer"
115
- },
116
- m
117
- );
118
- if (o?.linkComponent) {
119
- const l = o.linkComponent;
120
- if (typeof l == "string")
121
- return p(
122
- l,
123
- {
124
- ...h,
125
- href: x,
126
- style: k
127
- },
128
- m
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
- function gt(s, t) {
149
- return typeof s == "function" ? s() : typeof s == "string" ? s : t;
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
- const kt = (s) => {
152
- const {
153
- locales: t,
154
- currentLocale: o,
155
- getLocaleName: e,
156
- switchLocale: r,
157
- localeRoute: L,
158
- customLabels: m = {},
159
- customWrapperStyle: h,
160
- customButtonStyle: u,
161
- customDropdownStyle: c,
162
- customItemStyle: a,
163
- customLinkStyle: d,
164
- customActiveLinkStyle: f,
165
- customDisabledLinkStyle: k = {},
166
- customIconStyle: x,
167
- ...T
168
- } = s, l = $(), v = K(), w = M(), g = U(), [P, y] = W(!1), I = pt(null), N = t || g || l.getLocales() || [], S = N.filter((n) => !n.disabled), i = gt(o, l.locale), b = N.some((n) => n.code === i && n.disabled), E = e ? e() : l.getLocaleName(), B = (n) => {
169
- n && (n.stopPropagation(), n.preventDefault()), y(!P);
170
- }, j = (n) => m[n.code] || n.displayName || n.code, _ = () => {
171
- const n = S.find((R) => R.code === i);
172
- return n ? j(n) : E || i;
173
- }, Z = (n) => {
174
- if (y(!1), r) {
175
- r(n);
176
- return;
177
- }
178
- if (v.locale = n, !w)
179
- return;
180
- const R = w.getCurrentPath(), D = s.localeRoute ? (() => {
181
- const C = s.localeRoute(R, n);
182
- return typeof C == "string" ? C : C.path || "/";
183
- })() : w?.resolvePath ? (() => {
184
- const C = w.resolvePath(R, n);
185
- return typeof C == "string" ? C : C.path || "/";
186
- })() : R;
187
- w.push({ path: D });
188
- }, G = {
189
- position: "relative",
190
- display: "inline-block",
191
- verticalAlign: "middle"
192
- }, J = {
193
- padding: "4px 12px",
194
- fontSize: "16px",
195
- cursor: "pointer",
196
- backgroundColor: "#fff",
197
- border: "1px solid #333",
198
- transition: "background-color 0.3s ease",
199
- display: "flex",
200
- alignItems: "center",
201
- justifyContent: "space-between"
202
- }, Q = {
203
- position: "absolute",
204
- top: "100%",
205
- left: "0",
206
- zIndex: 1e3,
207
- backgroundColor: "#fff",
208
- border: "1px solid #333",
209
- listStyle: "none",
210
- padding: "0",
211
- margin: "4px 0 0 0",
212
- minWidth: "150px",
213
- boxShadow: "0 2px 8px rgba(0,0,0,0.15)"
214
- }, X = {
215
- margin: "0",
216
- padding: "0"
217
- }, Y = {
218
- display: "block",
219
- padding: "8px 12px",
220
- color: "#333",
221
- textDecoration: "none",
222
- transition: "background-color 0.3s ease",
223
- cursor: "pointer"
224
- }, tt = {
225
- fontWeight: "bold",
226
- color: "#007bff",
227
- cursor: "not-allowed"
228
- }, et = {
229
- marginLeft: "8px",
230
- display: "inline-block",
231
- transition: "transform 0.3s ease"
232
- }, nt = {
233
- transform: "rotate(180deg)"
234
- };
235
- z(() => {
236
- if (!P) return;
237
- const n = (R) => {
238
- if (!P) return;
239
- const D = R.target;
240
- if (!D || !I.current) return;
241
- const C = I.current.contains(D), it = D.closest(".i18n-switcher-button") !== null;
242
- !C && !it && y(!1);
243
- };
244
- return document.addEventListener("click", n), () => {
245
- document.removeEventListener("click", n);
246
- };
247
- }, [P]);
248
- const ot = { ...G, ...h }, rt = {
249
- ...J,
250
- ...u,
251
- ...b ? k : {}
252
- }, st = { ...Q, ...c }, at = { ...X, ...a }, lt = {
253
- ...et,
254
- ...P ? nt : {},
255
- ...x
256
- }, ct = S.map((n) => {
257
- const R = n.code === i, D = {
258
- ...Y,
259
- ...R ? tt : {},
260
- ...d,
261
- ...R ? f : {},
262
- width: "100%",
263
- textAlign: "left",
264
- border: "none",
265
- background: "transparent"
266
- };
267
- return p(
268
- "li",
269
- {
270
- key: n.code,
271
- style: at
272
- },
273
- p(
274
- "button",
275
- {
276
- type: "button",
277
- className: `switcher-locale-${n.code}`,
278
- style: D,
279
- onClick: (C) => {
280
- C.preventDefault(), C.stopPropagation(), Z(n.code);
281
- }
282
- },
283
- j(n)
284
- )
285
- );
286
- });
287
- return p(
288
- "div",
289
- {
290
- ref: I,
291
- className: "i18n-switcher-wrapper",
292
- style: ot,
293
- ...T
294
- },
295
- p(
296
- "button",
297
- {
298
- type: "button",
299
- className: "i18n-switcher-button",
300
- style: rt,
301
- onClick: (n) => {
302
- n.preventDefault(), n.stopPropagation(), B(n);
303
- },
304
- "aria-haspopup": "true",
305
- "aria-expanded": P
306
- },
307
- p("span", null, _()),
308
- p("span", { style: lt }, "▼")
309
- ),
310
- P ? p(
311
- "ul",
312
- {
313
- className: "i18n-switcher-dropdown",
314
- style: st
315
- },
316
- ...ct
317
- ) : null
318
- );
319
- }, Ct = (s) => {
320
- const { t, tc: o, tn: e, td: r, tdr: L, locale: m, getRoute: h } = $(), {
321
- keypath: u,
322
- params: c,
323
- tag: a = "span",
324
- plural: d,
325
- defaultValue: f,
326
- html: k = !1,
327
- hideIfEmpty: x = !1,
328
- customPluralRule: T,
329
- number: l,
330
- date: v,
331
- relativeDate: w,
332
- ...g
333
- } = s, P = h(), y = (S, i, b) => p(
334
- S,
335
- i,
336
- b
337
- );
338
- if (l !== void 0) {
339
- const S = Number(l), i = e(S), b = t(u, { number: i, ...c || {} }, void 0, P), E = typeof b == "string" ? b : String(b);
340
- return k ? y(a, { ...g, dangerouslySetInnerHTML: { __html: E } }, void 0) : y(a, g, E);
341
- }
342
- if (v !== void 0) {
343
- const S = r(v), i = t(u, { date: S, ...c || {} }, void 0, P), b = typeof i == "string" ? i : String(i);
344
- return k ? y(a, { ...g, dangerouslySetInnerHTML: { __html: b } }, void 0) : y(a, g, b);
345
- }
346
- if (w !== void 0) {
347
- const S = L(w), i = t(u, { relativeDate: S, ...c || {} }, void 0, P), b = typeof i == "string" ? i : String(i);
348
- return k ? y(a, { ...g, dangerouslySetInnerHTML: { __html: b } }, void 0) : y(a, g, b);
349
- }
350
- if (d !== void 0) {
351
- const S = Number.parseInt(d.toString(), 10);
352
- let i;
353
- return T ? i = T(
354
- u,
355
- S,
356
- c || {},
357
- m,
358
- (E, B, j) => {
359
- const _ = t(E, B, j, P);
360
- return typeof _ == "string" ? _ : String(_);
361
- }
362
- ) || "" : i = o(u, { count: S, ...c || {} }, f), k ? y(a, { ...g, dangerouslySetInnerHTML: { __html: i } }, void 0) : y(a, g, i);
363
- }
364
- const I = t(u, c, f, P), N = typeof I == "string" ? I : String(I);
365
- return x && !N.trim() ? f ? p(ft, null, f) : null : k ? y(a, { ...g, dangerouslySetInnerHTML: { __html: N } }, void 0) : y(a, g, N);
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
- class mt extends ut {
368
- store;
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
- function Rt(s) {
429
- return new mt(s);
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
- function yt(s, t) {
432
- const o = s.map((r) => r.code), e = (r, L) => {
433
- const h = (typeof r == "string" ? r : r.path || "/").split("/").filter(Boolean), u = h[0];
434
- u !== void 0 && o.includes(u) && h.shift();
435
- const c = `/${h.join("/")}`;
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