@i18n-micro/solid 1.0.0 → 1.1.1

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,313 +1,96 @@
1
- import { createSignal as I, createContext as E, useContext as j, createMemo as S, splitProps as V, onMount as de, onCleanup as he, createEffect as fe } from "solid-js";
2
- import { createStore as pe } from "solid-js/store";
3
- import { BaseI18n as ge } from "@i18n-micro/core";
4
- import { FormatService as He, defaultPlural as Fe, interpolate as Ze } from "@i18n-micro/core";
5
- import { createComponent as C, memo as v, Dynamic as W, mergeProps as P, template as R, spread as T, insert as x, delegateEvents as me, use as ye, setAttribute as K, effect as H, style as A, className as ve } from "solid-js/web";
6
- import { A as Le } from "@solidjs/router";
7
- class be extends ge {
8
- // Реактивные примитивы Solid
9
- _locale;
10
- _setLocale;
11
- _fallbackLocale;
12
- _currentRoute;
13
- _setRoute;
14
- // Store для кэша.
15
- // Мы используем createStore для глубокой реактивности, чтобы при подгрузке
16
- // частичных переводов (mergeTranslation) интерфейс обновлялся.
17
- cacheStore;
18
- setCacheStore;
19
- // Слушатели для DevTools (аналог subscribe в React версии)
20
- listeners = /* @__PURE__ */ new Set();
21
- constructor(e) {
22
- const [t, o] = I(e.locale), [r] = I(e.fallbackLocale || e.locale), [d, f] = I("general"), [l, a] = pe({
23
- general: {},
24
- route: {}
25
- }), s = {
26
- // Solid Store Proxy is compatible with reading objects
27
- generalLocaleCache: { value: l.general },
28
- routeLocaleCache: { value: l.route },
29
- dynamicTranslationsCaches: { value: [] },
30
- serverTranslationCache: { value: {} }
31
- };
32
- if (super({
33
- cache: s,
34
- plural: e.plural,
35
- missingWarn: e.missingWarn,
36
- missingHandler: e.missingHandler
37
- }), this._locale = t, this._setLocale = o, this._fallbackLocale = r, this._currentRoute = d, this._setRoute = f, this.cacheStore = l, this.setCacheStore = a, e.messages)
38
- for (const [c, p] of Object.entries(e.messages))
39
- this.addTranslations(c, p);
40
- }
41
- // --- Abstract Implementation ---
42
- getLocale() {
43
- return this._locale();
44
- }
45
- getFallbackLocale() {
46
- return this._fallbackLocale();
47
- }
48
- getRoute() {
49
- return this._currentRoute();
50
- }
51
- // --- Setters ---
52
- set locale(e) {
53
- this._setLocale(e), this.notifyListeners();
54
- }
55
- get locale() {
56
- return this._locale();
57
- }
58
- // Публичный accessor для реактивности
59
- get localeAccessor() {
60
- return this._locale;
61
- }
62
- get fallbackLocale() {
63
- return this._fallbackLocale();
64
- }
65
- get currentRoute() {
66
- return this._currentRoute();
67
- }
68
- // Публичный accessor для реактивности
69
- get routeAccessor() {
70
- return this._currentRoute;
71
- }
72
- setRoute(e) {
73
- this._setRoute(e), this.notifyListeners();
74
- }
75
- // --- Overrides for Reactivity ---
76
- addTranslations(e, t, o = !0) {
77
- o ? this.setCacheStore("general", e, (r) => ({
78
- ...r || {},
79
- ...t
80
- })) : this.setCacheStore("general", e, t), this.notifyListeners();
81
- }
82
- addRouteTranslations(e, t, o, r = !0) {
83
- const d = `${e}:${t}`;
84
- r ? this.setCacheStore("route", d, (f) => ({
85
- ...f || {},
86
- ...o
87
- })) : this.setCacheStore("route", d, o), this.notifyListeners();
88
- }
89
- clearCache() {
90
- this.setCacheStore("general", {}), this.setCacheStore("route", {}), super.clearCache(), this.notifyListeners();
91
- }
92
- subscribe(e) {
93
- return this.listeners.add(e), () => this.listeners.delete(e);
94
- }
95
- notifyListeners() {
96
- this.listeners.forEach((e) => {
97
- e();
98
- });
99
- }
100
- }
101
- function Ne(n) {
102
- return new be(n);
103
- }
1
+ import { BaseI18n as dt } from "@i18n-micro/core";
2
+ import { FormatService as Ot, defaultPlural as Wt, interpolate as Ht } from "@i18n-micro/core";
3
+ import { spread as T, mergeProps as R, insert as x, memo as v, template as C, createComponent as k, delegateEvents as ft, use as ht, setAttribute as K, effect as W, style as I, className as pt, Dynamic as H } from "solid-js/web";
4
+ import { createContext as E, useContext as j, splitProps as V, createMemo as P, createSignal as A, onMount as gt, onCleanup as mt, createEffect as yt } from "solid-js";
5
+ import { A as vt } from "@solidjs/router";
104
6
  const Q = E(), U = E(), X = E(), Y = E(), D = () => {
105
- const n = j(Q);
106
- if (!n)
7
+ const r = j(Q);
8
+ if (!r)
107
9
  throw new Error("[i18n-micro] I18nContext not found. Make sure I18nProvider is used.");
108
- return n;
109
- }, ee = () => {
110
- const n = j(U);
111
- if (!n)
10
+ return r;
11
+ }, tt = () => {
12
+ const r = j(U);
13
+ if (!r)
112
14
  throw new Error("[i18n-micro] I18nLocalesContext not found. Make sure I18nLocalesContext is provided.");
113
- return n;
114
- }, Se = () => {
115
- const n = j(X);
116
- if (!n)
15
+ return r;
16
+ }, Lt = () => {
17
+ const r = j(X);
18
+ if (!r)
117
19
  throw new Error("[i18n-micro] I18nDefaultLocaleContext not found. Make sure I18nDefaultLocaleContext is provided.");
118
- return n;
119
- }, F = () => j(Y), Te = (n) => {
120
- const e = n.children;
121
- return (
122
- // @ts-expect-error - Provider components type conflict with Vue JSX
123
- C(Q.Provider, {
124
- get value() {
125
- return n.i18n;
126
- },
127
- get children() {
128
- return [v(() => v(() => !!n.locales)() && // @ts-expect-error - Provider components type conflict with Vue JSX
129
- C(U.Provider, {
130
- get value() {
131
- return n.locales;
132
- },
133
- get children() {
134
- return [v(() => v(() => !!n.defaultLocale)() && // @ts-expect-error - Provider components type conflict with Vue JSX
135
- C(X.Provider, {
136
- get value() {
137
- return n.defaultLocale;
138
- },
139
- get children() {
140
- return [v(() => v(() => !!n.routingStrategy)() && // @ts-expect-error - Provider components type conflict with Vue JSX
141
- C(Y.Provider, {
142
- get value() {
143
- return n.routingStrategy;
144
- },
145
- children: e
146
- })), v(() => !n.routingStrategy && e)];
147
- }
148
- })), v(() => !n.defaultLocale && e)];
149
- }
150
- })), v(() => !n.locales && e)];
151
- }
152
- })
153
- );
154
- };
155
- function Ee(n) {
156
- const e = D(), t = F(), o = ee(), r = Se(), d = n?.locales || o, f = n?.defaultLocale || r, l = (a, s) => t?.resolvePath ? t.resolvePath(a, s || e.getLocale()) : a;
157
- return {
158
- // Direct access to instance
159
- instance: e,
160
- // Locale (reactive) - используем accessor для отслеживания изменений
161
- locale: S(() => e.localeAccessor()),
162
- // Locale helpers
163
- getLocales: () => d,
164
- defaultLocale: () => f,
165
- getLocaleName: () => d.find((s) => s.code === e.localeAccessor())?.displayName || null,
166
- // Routing helpers
167
- localeRoute: l,
168
- localePath: (a, s) => {
169
- const c = l(a, s);
170
- return typeof c == "string" ? c : c.path || "/";
171
- },
172
- switchLocale: (a) => {
173
- if (e.locale = a, t) {
174
- const s = t.getCurrentPath(), c = l(s, a);
175
- t.push(typeof c == "string" ? { path: c } : { path: c.path || "/" });
176
- }
177
- },
178
- // Translation methods (delegate to instance)
179
- t: e.t.bind(e),
180
- ts: e.ts.bind(e),
181
- tc: e.tc.bind(e),
182
- tn: e.tn.bind(e),
183
- td: e.td.bind(e),
184
- tdr: e.tdr.bind(e),
185
- has: e.has.bind(e),
186
- // Route management
187
- setRoute: e.setRoute.bind(e),
188
- getRoute: e.getRoute.bind(e),
189
- getLocale: () => e.getLocale(),
190
- // Translation management
191
- addTranslations: e.addTranslations.bind(e),
192
- addRouteTranslations: e.addRouteTranslations.bind(e),
193
- clearCache: e.clearCache.bind(e)
20
+ return r;
21
+ }, F = () => j(Y);
22
+ var bt = /* @__PURE__ */ C("<div>");
23
+ const At = (r) => {
24
+ const t = D(), [e, o] = V(r, ["prefix", "groupClass"]), n = (f, h) => {
25
+ const c = t.t(`${e.prefix}.${f}`, h, void 0, t.getRoute());
26
+ return typeof c == "string" ? c : String(c);
194
27
  };
195
- }
196
- const je = (n) => {
197
- const e = D(), [t, o] = V(n, ["keypath", "params", "tag", "plural", "defaultValue", "html", "hideIfEmpty", "customPluralRule", "number", "date", "relativeDate"]), r = S(() => {
198
- const f = e.localeAccessor(), l = e.routeAccessor();
199
- if (t.number !== void 0) {
200
- const s = Number(t.number), c = e.tn(s), p = e.t(t.keypath, {
201
- number: c,
202
- ...t.params || {}
203
- }, void 0, l);
204
- return typeof p == "string" ? p : String(p);
205
- }
206
- if (t.date !== void 0) {
207
- const s = e.td(t.date), c = e.t(t.keypath, {
208
- date: s,
209
- ...t.params || {}
210
- }, void 0, l);
211
- return typeof c == "string" ? c : String(c);
212
- }
213
- if (t.relativeDate !== void 0) {
214
- const s = e.tdr(t.relativeDate), c = e.t(t.keypath, {
215
- relativeDate: s,
216
- ...t.params || {}
217
- }, void 0, l);
218
- return typeof c == "string" ? c : String(c);
219
- }
220
- if (t.plural !== void 0) {
221
- const s = Number.parseInt(t.plural.toString());
222
- return t.customPluralRule ? t.customPluralRule(t.keypath, s, t.params || {}, f, (p, i, g) => e.t(p, i, g, l)) || "" : e.tc(t.keypath, {
223
- count: s,
224
- ...t.params || {}
225
- }, t.defaultValue);
226
- }
227
- const a = (e.t(t.keypath, t.params, t.defaultValue, l) ?? "").toString();
228
- return t.hideIfEmpty && !a.trim() ? t.defaultValue || "" : a;
229
- });
230
- if (t.html)
231
- return (
232
- // @ts-expect-error - Dynamic component type conflict with Vue JSX
233
- C(W, P({
234
- get component() {
235
- return t.tag || "span";
236
- }
237
- }, o, {
238
- get innerHTML() {
239
- return r();
28
+ return (
29
+ // @ts-expect-error - Type conflict with Vue JSX in monorepo
30
+ (() => {
31
+ var f = bt();
32
+ return T(f, R({
33
+ get class() {
34
+ return ["i18n-group", e.groupClass].filter(Boolean).join(" ");
240
35
  }
241
- }))
242
- );
243
- const d = r();
244
- return t.hideIfEmpty && !d.trim() ? t.defaultValue ? C(W, P({
245
- get component() {
246
- return t.tag || "span";
247
- }
248
- }, o, {
249
- get children() {
250
- return t.defaultValue;
251
- }
252
- })) : null : (
253
- // @ts-expect-error - Dynamic component type conflict with Vue JSX
254
- C(W, P({
255
- get component() {
256
- return t.tag || "span";
257
- }
258
- }, o, {
259
- children: d
260
- }))
36
+ }, o), !1, !0), x(f, (() => {
37
+ var h = v(() => typeof r.children == "function");
38
+ return () => h() ? r.children({
39
+ prefix: e.prefix,
40
+ t: n
41
+ }) : r.children;
42
+ })()), f;
43
+ })()
261
44
  );
262
45
  };
263
- var Ce = /* @__PURE__ */ R('<a target=_blank rel="noopener noreferrer">'), Pe = /* @__PURE__ */ R("<a>");
264
- const Ve = (n) => {
265
- const e = F(), t = D(), [o, r] = V(n, ["to", "localeRoute", "activeStyle", "style", "children"]), f = e?.getCurrentPathAccessor, l = S(() => {
266
- const i = t.localeAccessor();
267
- let g;
46
+ var Pt = /* @__PURE__ */ C('<a target=_blank rel="noopener noreferrer">'), kt = /* @__PURE__ */ C("<a>");
47
+ const Dt = (r) => {
48
+ const t = F(), e = D(), [o, n] = V(r, ["to", "localeRoute", "activeStyle", "style", "children"]), h = t?.getCurrentPathAccessor, c = P(() => {
49
+ const i = e.localeAccessor();
50
+ let p;
268
51
  if (o.localeRoute) {
269
52
  const y = o.localeRoute(o.to, i);
270
- g = typeof y == "string" ? y : y?.path || "/";
271
- } else if (e?.resolvePath) {
272
- const y = e.resolvePath(o.to, i);
273
- g = typeof y == "string" ? y : y?.path || "/";
274
- } else typeof o.to == "string" ? g = o.to : g = o.to?.path || "/";
275
- return g;
276
- }), a = S(() => typeof o.to == "string" ? /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(o.to) : !1), s = S(() => {
53
+ p = typeof y == "string" ? y : y?.path || "/";
54
+ } else if (t?.resolvePath) {
55
+ const y = t.resolvePath(o.to, i);
56
+ p = typeof y == "string" ? y : y?.path || "/";
57
+ } else typeof o.to == "string" ? p = o.to : p = o.to?.path || "/";
58
+ return p;
59
+ }), a = P(() => typeof o.to == "string" ? /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(o.to) : !1), s = P(() => {
277
60
  if (a())
278
61
  return !1;
279
- const i = f ? f() : e ? e.getCurrentPath() : typeof window < "u" ? window.location.pathname : "/", g = l(), y = i === "/" ? "/" : i.replace(/\/$/, ""), B = g === "/" ? "/" : g.replace(/\/$/, "");
280
- return y === B;
281
- }), c = S(() => {
62
+ const i = h ? h() : t ? t.getCurrentPath() : typeof window < "u" ? window.location.pathname : "/", p = c(), y = i === "/" ? "/" : i.replace(/\/$/, ""), M = p === "/" ? "/" : p.replace(/\/$/, "");
63
+ return y === M;
64
+ }), l = P(() => {
282
65
  const i = o.style || {}, y = s() ? o.activeStyle || {} : {};
283
66
  return {
284
67
  ...typeof i == "object" ? i : {},
285
68
  ...typeof y == "object" ? y : {}
286
69
  };
287
- }), p = e?.linkComponent;
70
+ }), g = t?.linkComponent;
288
71
  return a() ? (
289
72
  // @ts-expect-error - Type conflict with Vue JSX
290
73
  (() => {
291
- var i = Ce();
292
- return T(i, P({
74
+ var i = Pt();
75
+ return T(i, R({
293
76
  get href() {
294
77
  return v(() => typeof o.to == "string")() ? o.to : "";
295
78
  },
296
79
  get style() {
297
- return c();
80
+ return l();
298
81
  }
299
- }, r), !1, !0), x(i, () => o.children), i;
82
+ }, n), !1, !0), x(i, () => o.children), i;
300
83
  })()
301
- ) : p ? (
84
+ ) : g ? (
302
85
  // @ts-expect-error - Type conflict with router component types
303
- C(p, P({
86
+ k(g, R({
304
87
  get href() {
305
- return l();
88
+ return c();
306
89
  },
307
90
  get style() {
308
- return c();
91
+ return l();
309
92
  }
310
- }, r, {
93
+ }, n, {
311
94
  get children() {
312
95
  return o.children;
313
96
  }
@@ -315,55 +98,55 @@ const Ve = (n) => {
315
98
  ) : (
316
99
  // @ts-expect-error - Type conflict with Vue JSX
317
100
  (() => {
318
- var i = Pe();
319
- return T(i, P({
101
+ var i = kt();
102
+ return T(i, R({
320
103
  get href() {
321
- return l();
104
+ return c();
322
105
  },
323
106
  get style() {
324
- return c();
107
+ return l();
325
108
  }
326
- }, r, {
327
- onClick: (g) => {
328
- e && !a() && (g.preventDefault(), e.push({
329
- path: l()
109
+ }, n, {
110
+ onClick: (p) => {
111
+ t && !a() && (p.preventDefault(), t.push({
112
+ path: c()
330
113
  }));
331
114
  }
332
115
  }), !1, !0), x(i, () => o.children), i;
333
116
  })()
334
117
  );
335
118
  };
336
- var ke = /* @__PURE__ */ R("<div class=i18n-switcher-wrapper><button type=button class=i18n-switcher-button aria-haspopup=true><span></span><span>▼"), xe = /* @__PURE__ */ R("<ul class=i18n-switcher-dropdown>"), Re = /* @__PURE__ */ R("<li><a>");
337
- const Be = (n) => {
338
- const e = D(), t = F(), o = ee(), [r, d] = V(n, ["locales", "currentLocale", "getLocaleName", "switchLocale", "localeRoute", "customLabels", "customWrapperStyle", "customButtonStyle", "customDropdownStyle", "customItemStyle", "customLinkStyle", "customActiveLinkStyle", "customDisabledLinkStyle", "customIconStyle"]), [f, l] = I(!1);
119
+ var Rt = /* @__PURE__ */ C("<div class=i18n-switcher-wrapper><button type=button class=i18n-switcher-button aria-haspopup=true><span></span><span>▼"), St = /* @__PURE__ */ C("<ul class=i18n-switcher-dropdown>"), xt = /* @__PURE__ */ C("<li><a>");
120
+ const Nt = (r) => {
121
+ const t = D(), e = F(), o = tt(), [n, f] = V(r, ["locales", "currentLocale", "getLocaleName", "switchLocale", "localeRoute", "customLabels", "customWrapperStyle", "customButtonStyle", "customDropdownStyle", "customItemStyle", "customLinkStyle", "customActiveLinkStyle", "customDisabledLinkStyle", "customIconStyle"]), [h, c] = A(!1);
339
122
  let a;
340
- const s = S(() => r.locales || o || []), c = S(() => r.currentLocale !== void 0 ? typeof r.currentLocale == "function" ? r.currentLocale() : r.currentLocale : e.localeAccessor()), p = S(() => r.getLocaleName ? r.getLocaleName() || null : s().find((m) => m.code === e.localeAccessor())?.displayName || null), i = (u) => {
341
- u && (u.stopPropagation(), u.preventDefault()), l(!f());
342
- }, g = (u) => r.customLabels?.[u.code] || u.displayName || u.code, y = S(() => {
343
- const u = s().find((m) => m.code === c());
344
- return u ? g(u) : p() || c();
345
- }), B = async (u) => {
346
- if (l(!1), r.switchLocale) {
347
- r.switchLocale(u);
123
+ const s = P(() => n.locales || o || []), l = P(() => n.currentLocale !== void 0 ? typeof n.currentLocale == "function" ? n.currentLocale() : n.currentLocale : t.localeAccessor()), g = P(() => n.getLocaleName ? n.getLocaleName() || null : s().find((m) => m.code === t.localeAccessor())?.displayName || null), i = (u) => {
124
+ u && (u.stopPropagation(), u.preventDefault()), c(!h());
125
+ }, p = (u) => n.customLabels?.[u.code] || u.displayName || u.code, y = P(() => {
126
+ const u = s().find((m) => m.code === l());
127
+ return u ? p(u) : g() || l();
128
+ }), M = async (u) => {
129
+ if (c(!1), n.switchLocale) {
130
+ n.switchLocale(u);
348
131
  return;
349
132
  }
350
- if (e.locale = u, !t)
133
+ if (t.locale = u, !e)
351
134
  return;
352
- const m = t, k = m.getCurrentPathAccessor ? m.getCurrentPathAccessor() : t.getCurrentPath(), w = r.localeRoute ? (() => {
353
- const h = r.localeRoute(k, u);
354
- return typeof h == "string" ? h : h.path || "/";
355
- })() : t?.resolvePath ? (() => {
356
- const h = t.resolvePath(k, u);
357
- return typeof h == "string" ? h : h.path || "/";
358
- })() : k;
359
- t.push({
135
+ const m = e, S = m.getCurrentPathAccessor ? m.getCurrentPathAccessor() : e.getCurrentPath(), w = n.localeRoute ? (() => {
136
+ const d = n.localeRoute(S, u);
137
+ return typeof d == "string" ? d : d.path || "/";
138
+ })() : e?.resolvePath ? (() => {
139
+ const d = e.resolvePath(S, u);
140
+ return typeof d == "string" ? d : d.path || "/";
141
+ })() : S;
142
+ e.push({
360
143
  path: w
361
144
  });
362
- }, te = {
145
+ }, et = {
363
146
  position: "relative",
364
147
  display: "inline-block",
365
148
  "vertical-align": "middle"
366
- }, re = {
149
+ }, rt = {
367
150
  padding: "4px 12px",
368
151
  "font-size": "16px",
369
152
  cursor: "pointer",
@@ -373,7 +156,7 @@ const Be = (n) => {
373
156
  display: "flex",
374
157
  "align-items": "center",
375
158
  "justify-content": "space-between"
376
- }, ne = {
159
+ }, nt = {
377
160
  position: "absolute",
378
161
  top: "100%",
379
162
  left: "0",
@@ -385,91 +168,91 @@ const Be = (n) => {
385
168
  margin: "4px 0 0 0",
386
169
  "min-width": "150px",
387
170
  "box-shadow": "0 2px 8px rgba(0,0,0,0.15)"
388
- }, oe = {
171
+ }, ot = {
389
172
  margin: "0",
390
173
  padding: "0"
391
- }, ae = {
174
+ }, at = {
392
175
  display: "block",
393
176
  padding: "8px 12px",
394
177
  color: "#333",
395
178
  "text-decoration": "none",
396
179
  transition: "background-color 0.3s ease",
397
180
  cursor: "pointer"
398
- }, se = {
181
+ }, st = {
399
182
  "font-weight": "bold",
400
183
  color: "#007bff"
401
- }, ce = {
184
+ }, lt = {
402
185
  "margin-left": "8px",
403
186
  display: "inline-block",
404
187
  transition: "transform 0.3s ease"
405
- }, le = {
188
+ }, ct = {
406
189
  transform: "rotate(180deg)"
407
190
  }, Z = (u) => {
408
- if (!f()) return;
191
+ if (!h()) return;
409
192
  const m = u.target;
410
193
  if (!m || !a) return;
411
- const k = a.contains(m), w = m.closest(".i18n-switcher-button") !== null;
412
- !k && !w && l(!1);
194
+ const S = a.contains(m), w = m.closest(".i18n-switcher-button") !== null;
195
+ !S && !w && c(!1);
413
196
  };
414
- return de(() => {
197
+ return gt(() => {
415
198
  document.addEventListener("click", Z);
416
- }), he(() => {
199
+ }), mt(() => {
417
200
  document.removeEventListener("click", Z);
418
201
  }), (() => {
419
- var u = ke(), m = u.firstChild, k = m.firstChild, w = k.nextSibling;
420
- return ye((h) => {
421
- a = h;
422
- }, u), T(u, P({
202
+ var u = Rt(), m = u.firstChild, S = m.firstChild, w = S.nextSibling;
203
+ return ht((d) => {
204
+ a = d;
205
+ }, u), T(u, R({
423
206
  get style() {
424
207
  return {
425
- ...te,
426
- ...r.customWrapperStyle
208
+ ...et,
209
+ ...n.customWrapperStyle
427
210
  };
428
211
  }
429
- }, d), !1, !0), m.$$click = (h) => {
430
- h.preventDefault(), h.stopPropagation(), i(h);
431
- }, x(k, y), x(u, (() => {
432
- var h = v(() => !!f());
433
- return () => h() && (() => {
434
- var _ = xe();
212
+ }, f), !1, !0), m.$$click = (d) => {
213
+ d.preventDefault(), d.stopPropagation(), i(d);
214
+ }, x(S, y), x(u, (() => {
215
+ var d = v(() => !!h());
216
+ return () => d() && (() => {
217
+ var _ = St();
435
218
  return x(_, () => s().map((L) => {
436
- const N = L.code === c(), q = t, M = q?.getCurrentPathAccessor ? q.getCurrentPathAccessor() : t?.getCurrentPath() || (typeof window < "u" ? window.location.pathname : "/"), z = r.localeRoute ? r.localeRoute(M, L.code) : t?.resolvePath ? t.resolvePath(M, L.code) : M, G = typeof z == "string" ? z : z?.path || "#";
219
+ const N = L.code === l(), q = e, B = q?.getCurrentPathAccessor ? q.getCurrentPathAccessor() : e?.getCurrentPath() || (typeof window < "u" ? window.location.pathname : "/"), z = n.localeRoute ? n.localeRoute(B, L.code) : e?.resolvePath ? e.resolvePath(B, L.code) : B, G = typeof z == "string" ? z : z?.path || "#";
437
220
  return (() => {
438
- var O = Re(), $ = O.firstChild;
221
+ var O = xt(), $ = O.firstChild;
439
222
  return $.$$click = (b) => {
440
- b.preventDefault(), b.stopPropagation(), B(L.code);
441
- }, K($, "href", typeof G == "string" ? G : "#"), x($, () => g(L)), H((b) => {
442
- var ie = {
443
- ...oe,
444
- ...r.customItemStyle
445
- }, J = `switcher-locale-${L.code}`, ue = {
446
- ...ae,
447
- ...N ? se : {},
448
- ...r.customLinkStyle,
449
- ...N ? r.customActiveLinkStyle : {}
223
+ b.preventDefault(), b.stopPropagation(), M(L.code);
224
+ }, K($, "href", typeof G == "string" ? G : "#"), x($, () => p(L)), W((b) => {
225
+ var it = {
226
+ ...ot,
227
+ ...n.customItemStyle
228
+ }, J = `switcher-locale-${L.code}`, ut = {
229
+ ...at,
230
+ ...N ? st : {},
231
+ ...n.customLinkStyle,
232
+ ...N ? n.customActiveLinkStyle : {}
450
233
  };
451
- return b.e = A(O, ie, b.e), J !== b.t && ve($, b.t = J), b.a = A($, ue, b.a), b;
234
+ return b.e = I(O, it, b.e), J !== b.t && pt($, b.t = J), b.a = I($, ut, b.a), b;
452
235
  }, {
453
236
  e: void 0,
454
237
  t: void 0,
455
238
  a: void 0
456
239
  }), O;
457
240
  })();
458
- })), H((L) => A(_, {
459
- ...ne,
460
- ...r.customDropdownStyle
241
+ })), W((L) => I(_, {
242
+ ...nt,
243
+ ...n.customDropdownStyle
461
244
  }, L)), _;
462
245
  })();
463
- })(), null), H((h) => {
246
+ })(), null), W((d) => {
464
247
  var _ = {
465
- ...re,
466
- ...r.customButtonStyle
467
- }, L = f(), N = {
468
- ...ce,
469
- ...f() ? le : {},
470
- ...r.customIconStyle
248
+ ...rt,
249
+ ...n.customButtonStyle
250
+ }, L = h(), N = {
251
+ ...lt,
252
+ ...h() ? ct : {},
253
+ ...n.customIconStyle
471
254
  };
472
- return h.e = A(m, _, h.e), L !== h.t && K(m, "aria-expanded", h.t = L), h.a = A(w, N, h.a), h;
255
+ return d.e = I(m, _, d.e), L !== d.t && K(m, "aria-expanded", d.t = L), d.a = I(w, N, d.a), d;
473
256
  }, {
474
257
  e: void 0,
475
258
  t: void 0,
@@ -477,99 +260,290 @@ const Be = (n) => {
477
260
  }), u;
478
261
  })();
479
262
  };
480
- me(["click"]);
481
- var we = /* @__PURE__ */ R("<div>");
482
- const Me = (n) => {
483
- const e = D(), [t, o] = V(n, ["prefix", "groupClass"]), r = (d, f) => {
484
- const l = e.t(`${t.prefix}.${d}`, f, void 0, e.getRoute());
485
- return typeof l == "string" ? l : String(l);
486
- };
487
- return (
488
- // @ts-expect-error - Type conflict with Vue JSX in monorepo
489
- (() => {
490
- var d = we();
491
- return T(d, P({
492
- get class() {
493
- return ["i18n-group", t.groupClass].filter(Boolean).join(" ");
263
+ ft(["click"]);
264
+ const Tt = (r) => {
265
+ const t = D(), [e, o] = V(r, ["keypath", "params", "tag", "plural", "defaultValue", "html", "hideIfEmpty", "customPluralRule", "number", "date", "relativeDate"]), n = P(() => {
266
+ const h = t.localeAccessor(), c = t.routeAccessor();
267
+ if (e.number !== void 0) {
268
+ const s = Number(e.number), l = t.tn(s), g = t.t(e.keypath, {
269
+ number: l,
270
+ ...e.params || {}
271
+ }, void 0, c);
272
+ return typeof g == "string" ? g : String(g);
273
+ }
274
+ if (e.date !== void 0) {
275
+ const s = t.td(e.date), l = t.t(e.keypath, {
276
+ date: s,
277
+ ...e.params || {}
278
+ }, void 0, c);
279
+ return typeof l == "string" ? l : String(l);
280
+ }
281
+ if (e.relativeDate !== void 0) {
282
+ const s = t.tdr(e.relativeDate), l = t.t(e.keypath, {
283
+ relativeDate: s,
284
+ ...e.params || {}
285
+ }, void 0, c);
286
+ return typeof l == "string" ? l : String(l);
287
+ }
288
+ if (e.plural !== void 0) {
289
+ const s = Number.parseInt(e.plural.toString(), 10);
290
+ return e.customPluralRule ? e.customPluralRule(e.keypath, s, e.params || {}, h, (g, i, p) => t.t(g, i, p, c)) || "" : t.tc(e.keypath, {
291
+ count: s,
292
+ ...e.params || {}
293
+ }, e.defaultValue);
294
+ }
295
+ const a = (t.t(e.keypath, e.params, e.defaultValue, c) ?? "").toString();
296
+ return e.hideIfEmpty && !a.trim() ? e.defaultValue || "" : a;
297
+ });
298
+ if (e.html)
299
+ return (
300
+ // @ts-expect-error - Dynamic component type conflict with Vue JSX
301
+ k(H, R({
302
+ get component() {
303
+ return e.tag || "span";
494
304
  }
495
- }, o), !1, !0), x(d, (() => {
496
- var f = v(() => typeof n.children == "function");
497
- return () => f() ? n.children({
498
- prefix: t.prefix,
499
- t: r
500
- }) : n.children;
501
- })()), d;
502
- })()
305
+ }, o, {
306
+ get innerHTML() {
307
+ return n();
308
+ }
309
+ }))
310
+ );
311
+ const f = n();
312
+ return e.hideIfEmpty && !f.trim() ? e.defaultValue ? k(H, R({
313
+ get component() {
314
+ return e.tag || "span";
315
+ }
316
+ }, o, {
317
+ get children() {
318
+ return e.defaultValue;
319
+ }
320
+ })) : null : (
321
+ // @ts-expect-error - Dynamic component type conflict with Vue JSX
322
+ k(H, R({
323
+ get component() {
324
+ return e.tag || "span";
325
+ }
326
+ }, o, {
327
+ children: f
328
+ }))
329
+ );
330
+ }, Et = (r) => {
331
+ const t = r.children;
332
+ return (
333
+ // @ts-expect-error - Provider components type conflict with Vue JSX
334
+ k(Q.Provider, {
335
+ get value() {
336
+ return r.i18n;
337
+ },
338
+ get children() {
339
+ return [v(() => v(() => !!r.locales)() && // @ts-expect-error - Provider components type conflict with Vue JSX
340
+ k(U.Provider, {
341
+ get value() {
342
+ return r.locales;
343
+ },
344
+ get children() {
345
+ return [v(() => v(() => !!r.defaultLocale)() && // @ts-expect-error - Provider components type conflict with Vue JSX
346
+ k(X.Provider, {
347
+ get value() {
348
+ return r.defaultLocale;
349
+ },
350
+ get children() {
351
+ return [v(() => v(() => !!r.routingStrategy)() && // @ts-expect-error - Provider components type conflict with Vue JSX
352
+ k(Y.Provider, {
353
+ get value() {
354
+ return r.routingStrategy;
355
+ },
356
+ children: t
357
+ })), v(() => !r.routingStrategy && t)];
358
+ }
359
+ })), v(() => !r.defaultLocale && t)];
360
+ }
361
+ })), v(() => !r.locales && t)];
362
+ }
363
+ })
503
364
  );
504
365
  };
505
- function ze(n, e, t, o) {
506
- const r = n.map((a) => a.code), [d, f] = I(o.pathname);
507
- fe(() => {
508
- f(o.pathname);
366
+ class Ct extends dt {
367
+ _locale;
368
+ _setLocale;
369
+ _fallbackLocale;
370
+ _currentRoute;
371
+ _setRoute;
372
+ storage;
373
+ listeners = /* @__PURE__ */ new Set();
374
+ constructor(t) {
375
+ const e = {
376
+ translations: /* @__PURE__ */ new Map()
377
+ };
378
+ super({
379
+ storage: e,
380
+ plural: t.plural,
381
+ missingWarn: t.missingWarn,
382
+ missingHandler: t.missingHandler
383
+ }), this.storage = e;
384
+ const [o, n] = A(t.locale), [f] = A(t.fallbackLocale || t.locale), [h, c] = A("general");
385
+ if (this._locale = o, this._setLocale = n, this._fallbackLocale = f, this._currentRoute = h, this._setRoute = c, t.messages)
386
+ for (const [a, s] of Object.entries(t.messages))
387
+ this.addTranslations(a, s);
388
+ }
389
+ getLocale() {
390
+ return this._locale();
391
+ }
392
+ getFallbackLocale() {
393
+ return this._fallbackLocale();
394
+ }
395
+ getRoute() {
396
+ return this._currentRoute();
397
+ }
398
+ set locale(t) {
399
+ this._setLocale(t), this.notifyListeners();
400
+ }
401
+ get locale() {
402
+ return this._locale();
403
+ }
404
+ get localeAccessor() {
405
+ return this._locale;
406
+ }
407
+ get fallbackLocale() {
408
+ return this._fallbackLocale();
409
+ }
410
+ get currentRoute() {
411
+ return this._currentRoute();
412
+ }
413
+ get routeAccessor() {
414
+ return this._currentRoute;
415
+ }
416
+ setRoute(t) {
417
+ this._setRoute(t), this.notifyListeners();
418
+ }
419
+ addTranslations(t, e, o = !0) {
420
+ super.loadTranslationsCore(t, e, o), this.notifyListeners();
421
+ }
422
+ addRouteTranslations(t, e, o, n = !0) {
423
+ super.loadRouteTranslationsCore(t, e, o, n), this.notifyListeners();
424
+ }
425
+ clearCache() {
426
+ super.clearCache(), this.notifyListeners();
427
+ }
428
+ subscribe(t) {
429
+ return this.listeners.add(t), () => this.listeners.delete(t);
430
+ }
431
+ notifyListeners() {
432
+ this.listeners.forEach((t) => t());
433
+ }
434
+ }
435
+ function jt(r) {
436
+ return new Ct(r);
437
+ }
438
+ function Vt(r, t, e, o) {
439
+ const n = r.map((a) => a.code), [f, h] = A(o.pathname);
440
+ yt(() => {
441
+ h(o.pathname);
509
442
  });
510
- const l = (a, s) => {
511
- const p = (typeof a == "string" ? a : a.path || "/").split("/").filter(Boolean);
512
- p.length > 0 && r.includes(p[0]) && p.shift();
513
- const i = "/" + p.join("/");
514
- return s === e ? i : `/${s}${i === "/" ? "" : i}`;
443
+ const c = (a, s) => {
444
+ const g = (typeof a == "string" ? a : a.path || "/").split("/").filter(Boolean);
445
+ g.length > 0 && n.includes(g[0]) && g.shift();
446
+ const i = `/${g.join("/")}`;
447
+ return s === t ? i : `/${s}${i === "/" ? "" : i}`;
515
448
  };
516
449
  return {
517
- getCurrentPath: () => d(),
450
+ getCurrentPath: () => f(),
518
451
  // Returns current value for compatibility
519
- getCurrentPathAccessor: d,
452
+ getCurrentPathAccessor: f,
520
453
  // Returns accessor for reactivity
521
454
  push: (a) => {
522
- t(a.path);
455
+ e(a.path);
523
456
  },
524
457
  replace: (a) => {
525
- t(a.path, {
458
+ e(a.path, {
526
459
  replace: !0
527
460
  });
528
461
  },
529
- resolvePath: (a, s) => l(a, s),
462
+ resolvePath: (a, s) => c(a, s),
530
463
  getRoute: () => ({
531
- fullPath: d(),
464
+ fullPath: f(),
532
465
  query: {}
533
466
  }),
534
467
  // Use A component from @solidjs/router
535
468
  linkComponent: ((a) => {
536
469
  const {
537
470
  href: s,
538
- children: c,
539
- class: p,
471
+ children: l,
472
+ class: g,
540
473
  style: i,
541
- ...g
474
+ ...p
542
475
  } = a;
543
- return C(Le, P({
476
+ return k(vt, R({
544
477
  href: s,
545
- class: p,
478
+ class: g,
546
479
  style: i
547
- }, g, {
548
- children: c
480
+ }, p, {
481
+ children: l
549
482
  }));
550
483
  })
551
484
  };
552
485
  }
486
+ function Mt(r) {
487
+ const t = D(), e = F(), o = tt(), n = Lt(), f = r?.locales || o, h = r?.defaultLocale || n, c = (a, s) => e?.resolvePath ? e.resolvePath(a, s || t.getLocale()) : a;
488
+ return {
489
+ // Direct access to instance
490
+ instance: t,
491
+ // Locale (reactive) - используем accessor для отслеживания изменений
492
+ locale: P(() => t.localeAccessor()),
493
+ // Locale helpers
494
+ getLocales: () => f,
495
+ defaultLocale: () => h,
496
+ getLocaleName: () => f.find((s) => s.code === t.localeAccessor())?.displayName || null,
497
+ // Routing helpers
498
+ localeRoute: c,
499
+ localePath: (a, s) => {
500
+ const l = c(a, s);
501
+ return typeof l == "string" ? l : l.path || "/";
502
+ },
503
+ switchLocale: (a) => {
504
+ if (t.locale = a, e) {
505
+ const s = e.getCurrentPath(), l = c(s, a);
506
+ e.push(typeof l == "string" ? { path: l } : { path: l.path || "/" });
507
+ }
508
+ },
509
+ // Translation methods (delegate to instance)
510
+ t: t.t.bind(t),
511
+ ts: t.ts.bind(t),
512
+ tc: t.tc.bind(t),
513
+ tn: t.tn.bind(t),
514
+ td: t.td.bind(t),
515
+ tdr: t.tdr.bind(t),
516
+ has: t.has.bind(t),
517
+ // Route management
518
+ setRoute: t.setRoute.bind(t),
519
+ getRoute: t.getRoute.bind(t),
520
+ getLocale: () => t.getLocale(),
521
+ // Translation management
522
+ addTranslations: t.addTranslations.bind(t),
523
+ addRouteTranslations: t.addRouteTranslations.bind(t),
524
+ clearCache: t.clearCache.bind(t)
525
+ };
526
+ }
553
527
  export {
554
- He as FormatService,
528
+ Ot as FormatService,
555
529
  Q as I18nContext,
556
530
  X as I18nDefaultLocaleContext,
557
- Me as I18nGroup,
558
- Ve as I18nLink,
531
+ At as I18nGroup,
532
+ Dt as I18nLink,
559
533
  U as I18nLocalesContext,
560
- Te as I18nProvider,
534
+ Et as I18nProvider,
561
535
  Y as I18nRouterContext,
562
- Be as I18nSwitcher,
563
- je as I18nT,
564
- be as SolidI18n,
565
- Ne as createI18n,
566
- ze as createSolidRouterAdapter,
567
- Fe as defaultPlural,
568
- Ze as interpolate,
569
- Ee as useI18n,
536
+ Nt as I18nSwitcher,
537
+ Tt as I18nT,
538
+ Ct as SolidI18n,
539
+ jt as createI18n,
540
+ Vt as createSolidRouterAdapter,
541
+ Wt as defaultPlural,
542
+ Ht as interpolate,
543
+ Mt as useI18n,
570
544
  D as useI18nContext,
571
- Se as useI18nDefaultLocale,
572
- ee as useI18nLocales,
545
+ Lt as useI18nDefaultLocale,
546
+ tt as useI18nLocales,
573
547
  F as useI18nRouter
574
548
  };
575
549
  //# sourceMappingURL=index.mjs.map