@i18n-micro/solid 1.2.16 → 2.0.0

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,99 +1,128 @@
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);
1
+ import { FormatService as e, defaultPlural as t, externalLinkHref as n, interpolate as r, interpolate as i, isActiveLink as a, isPlainClick as o, localeIsoMap as s, ownValue as c, resolveText as l } from "@i18n-micro/core";
2
+ import { Dynamic as u, className as d, createComponent as f, delegateEvents as p, effect as m, insert as h, memo as g, mergeProps as _, setAttribute as v, spread as y, style as b, template as x, use as ee } from "solid-js/web";
3
+ import { For as S, Show as te, batch as C, createComputed as w, createContext as T, createMemo as E, createRoot as D, createSignal as O, getOwner as k, mergeProps as A, onCleanup as j, onMount as M, splitProps as N, useContext as P } from "solid-js";
4
+ import { SWITCHER_STYLES as F, foldTemplate as I } from "@i18n-micro/core/render";
5
+ import { I18n as L } from "@i18n-micro/runtime";
6
+ // src/injection.ts
7
+ var R = T(), z = () => {
8
+ let e = P(R);
8
9
  if (!e) throw Error("[i18n-micro] I18nContext not found. Make sure I18nProvider is used.");
9
10
  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
- };
11
+ }, B = () => z().i18n, ne = () => P(R)?.locales, V = () => P(R)?.defaultLocale, H = () => P(R)?.router, U = /*#__PURE__*/ x("<div>"), W = (e) => {
12
+ let t = B(), [n, r] = N(e, [
13
+ "prefix",
14
+ "groupClass",
15
+ "class",
16
+ "children"
17
+ ]), i = (e, r) => t.ts(`${n.prefix}.${e}`, r), a = E(() => [
18
+ "i18n-group",
19
+ n.groupClass,
20
+ n.class
21
+ ].filter(Boolean).join(" "));
23
22
  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({
23
+ var e = U();
24
+ return y(e, _({ get class() {
25
+ return a();
26
+ } }, r), !1, !0), h(e, (() => {
27
+ var e = g(() => typeof n.children == "function");
28
+ return () => e() ? n.children({
30
29
  prefix: n.prefix,
31
30
  t: i
32
- }) : e.children;
33
- })()), t;
31
+ }) : n.children;
32
+ })()), e;
34
33
  })();
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, [
34
+ }, G = (e) => typeof e == "string" ? e : e.path || "/";
35
+ function K(e, t) {
36
+ let n = e.i18n, r = () => t?.locales ?? e.locales ?? [], i = (t, r) => {
37
+ let i = e.router?.resolvePath;
38
+ return i ? i(t, r || n.locale) : t;
39
+ };
40
+ return {
41
+ instance: n,
42
+ locale: n.localeAccessor,
43
+ getLocales: r,
44
+ defaultLocale: () => t?.defaultLocale ?? e.defaultLocale ?? n.fallbackLocale,
45
+ getLocaleName: () => r().find((e) => e.code === n.locale)?.displayName || null,
46
+ localeRoute: i,
47
+ localePath: (e, t) => G(i(e, t)),
48
+ switchLocale: (t) => {
49
+ n.locale = t;
50
+ let r = e.router;
51
+ r && r.push({ path: G(i(r.getCurrentPath(), t)) });
52
+ },
53
+ t: n.t.bind(n),
54
+ ts: n.ts.bind(n),
55
+ tc: n.tc.bind(n),
56
+ tn: n.tn.bind(n),
57
+ td: n.td.bind(n),
58
+ tdr: n.tdr.bind(n),
59
+ has: n.has.bind(n),
60
+ setRoute: n.setRoute.bind(n),
61
+ getRoute: () => n.currentRoute,
62
+ getLocale: () => n.locale,
63
+ addTranslations: n.addTranslations.bind(n),
64
+ addRouteTranslations: n.addRouteTranslations.bind(n),
65
+ resolveTranslations: n.resolveTranslations.bind(n),
66
+ setTranslation: n.setTranslation.bind(n),
67
+ clearCache: n.clearCache.bind(n)
68
+ };
69
+ }
70
+ function q(e) {
71
+ let t = z();
72
+ return e?.locales || e?.defaultLocale ? K(t, e) : t.api ??= K(t);
73
+ }
74
+ // src/components/merge-styles.ts
75
+ var J = (e) => typeof e == "string" ? e : Object.entries(e ?? {}).map(([e, t]) => `${e}:${t}`).join(";");
76
+ function Y(...e) {
77
+ return e.some((e) => typeof e == "string") ? e.map(J).filter(Boolean).join(";") : Object.assign({}, ...e);
78
+ }
79
+ // src/components/I18nLink.tsx
80
+ function X(e, t) {
81
+ typeof e == "function" ? e(t) : e && e[0](e[1], t);
82
+ }
83
+ var Z = (e) => {
84
+ let t = z(), r = t.i18n, i = q(), [s, c] = N(e, [
37
85
  "to",
38
86
  "localeRoute",
39
87
  "activeStyle",
40
88
  "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({
89
+ "onClick"
90
+ ]), l = E(() => n(s.to)), d = E(() => G((s.localeRoute ?? i.localeRoute)(s.to, r.locale))), p = E(() => {
91
+ let e = t.router;
92
+ if (!e || !s.activeStyle || l() !== void 0) return !1;
93
+ let n = [
94
+ r.locale,
95
+ i.defaultLocale(),
96
+ r.fallbackLocale,
97
+ ...i.getLocales().map((e) => e.code)
98
+ ];
99
+ return a(e.getCurrentPath(), d(), n);
100
+ }), m = (e) => {
101
+ X(s.onClick, e);
102
+ let n = t.router;
103
+ n && l() === void 0 && o(e) && (e.preventDefault(), n.push({ path: d() }));
104
+ }, h = () => l() === void 0 && t.router?.linkComponent !== void 0, v = A(c, {
74
105
  get href() {
75
- return o();
106
+ return l() ?? d();
76
107
  },
77
108
  get style() {
78
- return p();
109
+ return p() ? Y(s.style, s.activeStyle) : s.style;
110
+ },
111
+ get onClick() {
112
+ return h() ? s.onClick : m;
113
+ },
114
+ get target() {
115
+ return l() === void 0 ? void 0 : c.target ?? "_blank";
116
+ },
117
+ get rel() {
118
+ return l() === void 0 ? void 0 : c.rel ?? "noopener noreferrer";
79
119
  }
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, [
120
+ });
121
+ return f(u, _({ get component() {
122
+ return g(() => !!h())() ? t.router.linkComponent : "a";
123
+ } }, v));
124
+ }, re = /*#__PURE__*/ x("<ul class=i18n-switcher-dropdown>"), ie = /*#__PURE__*/ x("<div><button type=button class=\"i18n-switcher-button language-switcher\"><span></span> <span>▾"), ae = /*#__PURE__*/ x("<li><a>"), Q = (e) => Object.fromEntries(Object.entries(e).map(([e, t]) => [e.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), t])), oe = /*#__PURE__*/ Q(F.wrapper), se = /*#__PURE__*/ Q(F.button), ce = /*#__PURE__*/ Q(F.dropdown), le = /*#__PURE__*/ Q(F.item), ue = /*#__PURE__*/ Q(F.link), de = /*#__PURE__*/ Q(F.activeLink), fe = /*#__PURE__*/ Q(F.icon), pe = /*#__PURE__*/ Q(F.openIcon), me = (e) => {
125
+ let t = q(), n = z(), [r, i] = N(e, [
97
126
  "locales",
98
127
  "currentLocale",
99
128
  "getLocaleName",
@@ -107,135 +136,92 @@ var D = v(), O = v(), k = v(), A = v(), j = () => {
107
136
  "customLinkStyle",
108
137
  "customActiveLinkStyle",
109
138
  "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;
139
+ "customIconStyle",
140
+ "class",
141
+ "style"
142
+ ]), [a, s] = O(!1), l, u = E(() => r.locales ?? n.locales ?? []), p = E(() => {
143
+ let e = r.currentLocale;
144
+ return typeof e == "function" ? e() : e ?? t.locale();
145
+ }), g = E(() => u().find((e) => e.code === p())), x = (e) => r.customLabels && c(r.customLabels, e.code) || e.displayName || e.code, C = (e) => {
146
+ let t = n.router, i = t?.getCurrentPath() ?? (typeof window > "u" ? "/" : window.location.pathname + window.location.search + window.location.hash);
147
+ return r.localeRoute ? G(r.localeRoute(i, e)) : t ? G(t.resolvePath ? t.resolvePath(i, e) : i) : "#";
148
+ }, w = (e, i) => {
149
+ if (o(e)) {
150
+ if ((r.switchLocale || n.router || !r.localeRoute) && e.preventDefault(), s(!1), r.switchLocale) return r.switchLocale(i);
151
+ if (!r.localeRoute) return t.switchLocale(i);
152
+ t.instance.locale = i, n.router?.push({ path: C(i) });
120
153
  }
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);
154
+ }, T = (e) => {
155
+ a() && !l?.contains(e.target) && s(!1);
156
+ }, D = (e) => {
157
+ e.key === "Escape" && s(!1);
180
158
  };
181
- return C(() => {
182
- document.addEventListener("click", K);
183
- }), S(() => {
184
- document.removeEventListener("click", K);
159
+ return M(() => {
160
+ document.addEventListener("click", T), document.addEventListener("keydown", D), j(() => {
161
+ document.removeEventListener("click", T), document.removeEventListener("keydown", D);
162
+ });
185
163
  }), (() => {
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
164
+ var e = ie(), t = e.firstChild, n = t.firstChild, o = n.nextSibling.nextSibling;
165
+ return ee((e) => {
166
+ l = e;
167
+ }, e), y(e, _(i, {
168
+ get class() {
169
+ return ["i18n-switcher-wrapper", r.class].filter(Boolean).join(" ");
170
+ },
171
+ get style() {
172
+ return Y(oe, r.customWrapperStyle, r.style);
173
+ }
174
+ }), !1, !0), t.$$click = () => s(!a()), h(n, () => r.getLocaleName?.() || x(g() ?? { code: p() })), h(e, f(te, {
175
+ get when() {
176
+ return a();
177
+ },
178
+ get children() {
179
+ var e = re();
180
+ return h(e, f(S, {
181
+ get each() {
182
+ return u().filter((e) => !e.disabled);
183
+ },
184
+ children: (e) => {
185
+ let t = () => e.code === p(), n = e.iso || e.code;
186
+ return (() => {
187
+ var i = ae(), a = i.firstChild;
188
+ return a.$$click = (t) => w(t, e.code), v(a, "hreflang", n), v(a, "lang", n), h(a, () => x(e)), m((n) => {
189
+ var o = {
190
+ ...le,
191
+ ...r.customItemStyle
192
+ }, s = `switcher-locale-${e.code}`, c = C(e.code), l = e.dir, u = t() ? "page" : void 0, f = {
193
+ ...ue,
194
+ ...t() ? de : void 0,
195
+ ...r.customLinkStyle,
196
+ ...t() ? r.customActiveLinkStyle : void 0
197
+ };
198
+ return n.e = b(i, o, n.e), s !== n.t && d(a, n.t = s), c !== n.a && v(a, "href", n.a = c), l !== n.o && v(a, "dir", n.o = l), u !== n.i && v(a, "aria-current", n.i = u), n.n = b(a, f, n.n), n;
199
+ }, {
200
+ e: void 0,
201
+ t: void 0,
202
+ a: void 0,
203
+ o: void 0,
204
+ i: void 0,
205
+ n: void 0
206
+ }), i;
207
+ })();
208
+ }
209
+ })), m((t) => b(e, {
210
+ ...ce,
211
+ ...r.customDropdownStyle
226
212
  }, t)), e;
227
- })();
228
- })(), null), l((e) => {
213
+ }
214
+ }), null), m((e) => {
229
215
  var n = {
230
- ...I,
231
- ...i.customButtonStyle,
232
- ...E() ? i.customDisabledLinkStyle : {}
233
- }, r = s(), a = {
234
- ...W,
235
- ...s() ? G : {},
236
- ...i.customIconStyle
216
+ ...se,
217
+ ...r.customButtonStyle,
218
+ ...g()?.disabled ? r.customDisabledLinkStyle : void 0
219
+ }, i = a(), s = {
220
+ ...fe,
221
+ ...a() ? pe : void 0,
222
+ ...r.customIconStyle
237
223
  };
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;
224
+ return e.e = b(t, n, e.e), i !== e.t && v(t, "aria-expanded", e.t = i), e.a = b(o, s, e.a), e;
239
225
  }, {
240
226
  e: void 0,
241
227
  t: void 0,
@@ -243,253 +229,140 @@ var D = v(), O = v(), k = v(), A = v(), j = () => {
243
229
  }), e;
244
230
  })();
245
231
  };
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;
232
+ p(["click"]);
233
+ // src/components/I18nT.tsx
234
+ var he = /*#__PURE__*/ x("<span>"), ge = [
235
+ "keypath",
236
+ "params",
237
+ "tag",
238
+ "plural",
239
+ "defaultValue",
240
+ "html",
241
+ "hideIfEmpty",
242
+ "customPluralRule",
243
+ "number",
244
+ "date",
245
+ "relativeDate",
246
+ "components",
247
+ "children"
248
+ ], _e = [
249
+ "innerHTML",
250
+ "textContent",
251
+ "dangerouslySetInnerHTML",
252
+ "prop:innerHTML",
253
+ "prop:textContent"
254
+ ], ve = (e) => e == null || typeof e == "boolean";
255
+ function ye(e) {
256
+ let t = Object.create(null);
257
+ for (let n of Object.keys(e ?? {})) {
258
+ let r = e[n];
259
+ r !== void 0 && (t[n] = typeof r == "function" ? r : () => r);
260
+ }
261
+ return t;
262
+ }
263
+ var be = (e) => {
264
+ let t = B(), [n, , r] = N(e, ge, _e), a = E(() => (t.localeAccessor(), l(t, n))), o = () => {
265
+ let { template: e, params: t } = a();
266
+ return i(e, t);
267
+ }, s = E(() => {
268
+ let e = /* @__PURE__ */ new Map();
269
+ return j(() => {
270
+ for (let t of e.values()) t.dispose();
271
+ }), {
272
+ slots: ye(n.components),
273
+ nodes: e,
274
+ owner: k()
275
+ };
276
+ }), c = (e, t) => {
277
+ let { nodes: n, owner: r } = s();
278
+ return n.has(t) || n.set(t, D((t) => ({
279
+ node: e({}),
280
+ dispose: t
281
+ }), r)), n.get(t).node;
282
+ }, d = () => {
283
+ let { template: e, params: t } = a(), { slots: n, nodes: r } = s(), i = /* @__PURE__ */ new Set(), o = I((e, t) => (i.add(t), c(e, t)), e, t, n);
284
+ for (let [e, t] of r) i.has(e) || (t.dispose(), r.delete(e));
285
+ return o;
286
+ }, p = () => {
287
+ let e = n.children;
288
+ return typeof e == "function" ? e({ translation: o() }) : ve(e) ? d() : e;
289
+ }, m = (e) => {
290
+ let t = A(r, e);
291
+ return n.tag ? f(u, _({ get component() {
292
+ return n.tag;
293
+ } }, t)) : (() => {
294
+ var e = he();
295
+ return y(e, t, !1, !1), e;
296
+ })();
297
+ }, h = { get innerHTML() {
298
+ return o();
299
+ } }, v = { get children() {
300
+ return p();
301
+ } };
302
+ return g(() => g(() => a() === null)() ? n.defaultValue : g(() => !!n.html)() ? m(h) : m(v));
303
+ }, xe = (e) => {
304
+ let t = P(R), n = {
305
+ get i18n() {
306
+ let n = e.i18n ?? t?.i18n;
307
+ if (!n) throw Error("[i18n-micro] I18nProvider needs an `i18n` instance or an outer provider.");
308
+ return n;
309
+ },
310
+ get locales() {
311
+ return e.locales ?? t?.locales;
313
312
  },
313
+ get defaultLocale() {
314
+ return e.defaultLocale ?? t?.defaultLocale;
315
+ },
316
+ get router() {
317
+ return e.routingStrategy ?? t?.router;
318
+ }
319
+ };
320
+ return w(() => {
321
+ e.locales && n.i18n.addLocaleIso(s(e.locales));
322
+ }), f(R.Provider, {
323
+ value: n,
314
324
  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)];
325
+ return e.children;
335
326
  }
336
327
  });
337
- }, K = class extends e {
338
- store;
339
- _localeSignal;
340
- _setLocaleSignal;
341
- _routeSignal;
342
- _setRouteSignal;
343
- _fallbackSignal;
344
- storage;
328
+ }, $ = class extends L {
329
+ revision;
330
+ localeSignal;
331
+ fallbackSignal;
332
+ routeSignal;
333
+ localeAccessor = () => this.locale;
334
+ routeAccessor = () => this.currentRoute;
345
335
  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
336
+ super(e);
337
+ let [t, n] = O(0), [r, i] = O(this.getLocale()), [a, o] = O(this.getFallbackLocale()), [s, c] = O(this.getRoute());
338
+ this.revision = t, this.localeSignal = r, this.fallbackSignal = a, this.routeSignal = s, this.subscribe(() => {
339
+ C(() => {
340
+ i(this.getLocale()), o(this.getFallbackLocale()), c(this.getRoute()), n((e) => e + 1);
341
+ });
355
342
  });
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
343
  }
367
- getRoute() {
368
- return this.store.getRoute();
369
- }
370
- set locale(e) {
371
- this.store.setLocale(e), this._setLocaleSignal(e), this.notifyListeners();
344
+ touch() {
345
+ this.revision();
372
346
  }
373
347
  get locale() {
374
- return this._localeSignal();
348
+ return this.localeSignal();
375
349
  }
376
- get localeAccessor() {
377
- return this._localeSignal;
350
+ set locale(e) {
351
+ super.locale = e;
378
352
  }
379
353
  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();
354
+ return this.fallbackSignal();
396
355
  }
397
- clearCache() {
398
- super.clearCache(), this.store.notify(), this.notifyListeners();
356
+ set fallbackLocale(e) {
357
+ super.fallbackLocale = e;
399
358
  }
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());
359
+ get currentRoute() {
360
+ return this.routeSignal();
412
361
  }
413
362
  };
414
- function q(e) {
415
- return new K(e);
416
- }
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
- }
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
- };
363
+ function Se(e) {
364
+ return new $(e);
491
365
  }
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 };
366
+ export { e as FormatService, R as I18nContext, W as I18nGroup, Z as I18nLink, xe as I18nProvider, me as I18nSwitcher, be as I18nT, $ as SolidI18n, Se as createI18n, t as defaultPlural, r as interpolate, q as useI18n, B as useI18nContext, V as useI18nDefaultLocale, ne as useI18nLocales, H as useI18nRouter };
494
367
 
495
368
  //# sourceMappingURL=index.mjs.map