@i18n-micro/preact 1.2.0 → 1.2.3

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