@i18n-micro/solid 1.2.9 → 1.2.10

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