@manyducks.co/dolla 2.0.0-alpha.51 → 2.0.0-alpha.52
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/README.md +15 -11
- package/dist/core/context.d.ts +7 -3
- package/dist/core/env.d.ts +9 -0
- package/dist/core/index.d.ts +23 -0
- package/dist/core/logger.d.ts +34 -0
- package/dist/core/markup.d.ts +6 -11
- package/dist/core/mount.d.ts +10 -0
- package/dist/core/nodes/dynamic.d.ts +1 -1
- package/dist/core/nodes/fragment.d.ts +1 -1
- package/dist/core/nodes/outlet.d.ts +1 -1
- package/dist/core/nodes/repeat.d.ts +1 -1
- package/dist/core/nodes/view.d.ts +11 -6
- package/dist/core/signals.d.ts +43 -2
- package/dist/core/store.d.ts +10 -5
- package/dist/{fragment-Bvuvw3ue.js → fragment-DSGTP-XE.js} +2 -2
- package/dist/{fragment-Bvuvw3ue.js.map → fragment-DSGTP-XE.js.map} +1 -1
- package/dist/http.js +163 -0
- package/dist/http.js.map +1 -0
- package/dist/{translate → i18n}/index.d.ts +7 -6
- package/dist/i18n.js +318 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.js +63 -1190
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-runtime.js +2 -2
- package/dist/logger-CSRDjb4e.js +623 -0
- package/dist/logger-CSRDjb4e.js.map +1 -0
- package/dist/router/index.d.ts +1 -144
- package/dist/router/router.d.ts +139 -0
- package/dist/router-BYOH-To5.js +482 -0
- package/dist/router-BYOH-To5.js.map +1 -0
- package/dist/router.js +8 -0
- package/dist/router.js.map +1 -0
- package/dist/typeChecking-EAVNeFyB.js +75 -0
- package/dist/typeChecking-EAVNeFyB.js.map +1 -0
- package/dist/types.d.ts +9 -1
- package/dist/view-CY19Cf0X.js +932 -0
- package/dist/view-CY19Cf0X.js.map +1 -0
- package/docs/markup.md +16 -0
- package/notes/stores.md +26 -0
- package/package.json +14 -2
- package/vite.config.js +4 -5
- package/dist/core/dolla.d.ts +0 -128
- package/dist/core/signals-api.d.ts +0 -42
- package/dist/index.d.ts +0 -26
- package/dist/markup-QqAGIoYP.js +0 -1501
- package/dist/markup-QqAGIoYP.js.map +0 -1
- /package/dist/core/{signals-api.test.d.ts → signals.test.d.ts} +0 -0
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
var B = Object.defineProperty;
|
|
2
|
+
var z = (o) => {
|
|
3
|
+
throw TypeError(o);
|
|
4
|
+
};
|
|
5
|
+
var J = (o, t, e) => t in o ? B(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
6
|
+
var O = (o, t, e) => J(o, typeof t != "symbol" ? t + "" : t, e), _ = (o, t, e) => t.has(o) || z("Cannot " + e);
|
|
7
|
+
var i = (o, t, e) => (_(o, t, "read from private field"), e ? e.call(o) : t.get(o)), m = (o, t, e) => t.has(o) ? z("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(o) : t.set(o, e), N = (o, t, e, n) => (_(o, t, "write to private field"), n ? n.call(o, e) : t.set(o, e), e), g = (o, t, e) => (_(o, t, "access private method"), e);
|
|
8
|
+
import { $, f as K, d as Q, g as x } from "./logger-CSRDjb4e.js";
|
|
9
|
+
import { i as C, b as j, c as U, t as P } from "./typeChecking-EAVNeFyB.js";
|
|
10
|
+
var I, F, p, S, G;
|
|
11
|
+
class W {
|
|
12
|
+
constructor(t) {
|
|
13
|
+
m(this, p);
|
|
14
|
+
O(this, "config");
|
|
15
|
+
m(this, I, !1);
|
|
16
|
+
m(this, F, /* @__PURE__ */ new Map());
|
|
17
|
+
this.config = t;
|
|
18
|
+
}
|
|
19
|
+
async load() {
|
|
20
|
+
let t;
|
|
21
|
+
if (!i(this, I)) {
|
|
22
|
+
if (j(this.config.strings))
|
|
23
|
+
t = this.config.strings;
|
|
24
|
+
else if (U(this.config.fetch)) {
|
|
25
|
+
if (t = await this.config.fetch(), !j(t))
|
|
26
|
+
throw new Error(`Fetch function did not return an object of language strings: ${t}`);
|
|
27
|
+
} else if (C(this.config.path)) {
|
|
28
|
+
const e = await fetch(this.config.path);
|
|
29
|
+
if (e.ok) {
|
|
30
|
+
const n = await e.json();
|
|
31
|
+
if (j(n))
|
|
32
|
+
t = n;
|
|
33
|
+
else
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Language path '${this.config.path}' did not return an object of language strings: ${n}`
|
|
36
|
+
);
|
|
37
|
+
} else
|
|
38
|
+
throw new Error("HTTP request failed.");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (t) {
|
|
42
|
+
const e = g(this, p, S).call(this, t);
|
|
43
|
+
for (const n of e)
|
|
44
|
+
i(this, F).set(n[0], n[1]);
|
|
45
|
+
} else
|
|
46
|
+
throw new Error("Language could not be loaded.");
|
|
47
|
+
}
|
|
48
|
+
getTemplate(t) {
|
|
49
|
+
return i(this, F).get(t) ?? {
|
|
50
|
+
segments: [{ type: 0, text: `[MISSING: ${t}]` }]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
hasTemplate(t) {
|
|
54
|
+
return i(this, F).has(t);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
I = new WeakMap(), F = new WeakMap(), p = new WeakSet(), S = function(t, e = []) {
|
|
58
|
+
const n = [];
|
|
59
|
+
for (const a in t)
|
|
60
|
+
switch (P(t[a])) {
|
|
61
|
+
case "string":
|
|
62
|
+
n.push([[...e, a].join("."), g(this, p, G).call(this, t[a])]);
|
|
63
|
+
break;
|
|
64
|
+
case "object":
|
|
65
|
+
n.push(...g(this, p, S).call(this, t[a], [...e, a]));
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Expected to find a string or object at ${[...e, a].join(".")}. Got: ${P(t[a])}`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return n;
|
|
73
|
+
}, G = function(t) {
|
|
74
|
+
let e;
|
|
75
|
+
((f) => {
|
|
76
|
+
f[f.Static = 0] = "Static", f[f.ValueName = 1] = "ValueName", f[f.FormatName = 2] = "FormatName", f[f.FormatOptionName = 3] = "FormatOptionName", f[f.FormatOptionValue = 4] = "FormatOptionValue", f[f.FormatOptionEnd = 5] = "FormatOptionEnd";
|
|
77
|
+
})(e || (e = {}));
|
|
78
|
+
const n = {
|
|
79
|
+
segments: []
|
|
80
|
+
};
|
|
81
|
+
let a = "", s = 0, r = 0, c, w, l;
|
|
82
|
+
const k = () => {
|
|
83
|
+
c = {
|
|
84
|
+
type: 1,
|
|
85
|
+
name: "",
|
|
86
|
+
formats: []
|
|
87
|
+
};
|
|
88
|
+
}, y = () => {
|
|
89
|
+
w = {
|
|
90
|
+
name: "",
|
|
91
|
+
options: {}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
for (; s < t.length; ) {
|
|
95
|
+
if (r !== 0 && t[s] === " ") {
|
|
96
|
+
s++;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
switch (r) {
|
|
100
|
+
case 0:
|
|
101
|
+
t[s] === "{" && t[s + 1] === "{" ? (r = 1, s += 2, a.length > 0 && (n.segments.push({ type: 0, text: a }), a = ""), k()) : (a += t[s], s++);
|
|
102
|
+
break;
|
|
103
|
+
case 1:
|
|
104
|
+
t[s] === "|" ? (r = 2, s += 1, c.name = a, a = "", y()) : t[s] === "}" && t[s + 1] === "}" ? (r = 0, s += 2, c.name = a, a = "", n.segments.push(c)) : (a += t[s], s++);
|
|
105
|
+
break;
|
|
106
|
+
case 2:
|
|
107
|
+
t[s] === "(" ? (r = 3, s += 1, w.name = a, a = "") : t[s] === "}" && t[s + 1] === "}" ? (r = 0, s += 2, c.formats.push(w), n.segments.push(c)) : (a += t[s], s++);
|
|
108
|
+
break;
|
|
109
|
+
case 3:
|
|
110
|
+
t[s] === ")" || (t[s] === ":" ? (r = 4, s += 1, l = a, a = "") : t[s] === "}" && t[s + 1] === "}" || (a += t[s], s++));
|
|
111
|
+
break;
|
|
112
|
+
case 4:
|
|
113
|
+
t[s] === ")" ? (r = 5, s += 1, w.options[l] = a, a = "", c.formats.push(w)) : t[s] === "," ? (r = 3, s += 1, w.options[l] = a, a = "") : t[s] === "}" && t[s + 1] === "}" || (a += t[s], s++);
|
|
114
|
+
break;
|
|
115
|
+
case 5:
|
|
116
|
+
t[s] === "|" ? (r = 2, s += 1, y()) : t[s] === "}" && t[s + 1] === "}" && (r = 0, s += 2, n.segments.push(c));
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return r === 0 && a.length > 0 && n.segments.push({ type: 0, text: a }), n;
|
|
121
|
+
};
|
|
122
|
+
var b, h, E, T, v, d, u, H, L, V, D, A;
|
|
123
|
+
class X {
|
|
124
|
+
constructor() {
|
|
125
|
+
m(this, u);
|
|
126
|
+
m(this, b);
|
|
127
|
+
m(this, h, /* @__PURE__ */ new Map());
|
|
128
|
+
m(this, E, []);
|
|
129
|
+
m(this, T, /* @__PURE__ */ new Map());
|
|
130
|
+
m(this, v, "auto");
|
|
131
|
+
m(this, d, $("en"));
|
|
132
|
+
O(this, "$locale", $(i(this, d)));
|
|
133
|
+
N(this, b, K("Dolla.i18n")), this.addFormat("number", (t, e, n) => g(this, u, L).call(this, Number(e), n)), this.addFormat("datetime", (t, e, n) => g(this, u, V).call(this, e, n)), this.addFormat("list", (t, e, n) => g(this, u, D).call(this, e, n));
|
|
134
|
+
}
|
|
135
|
+
get locales() {
|
|
136
|
+
return [...i(this, h).keys()];
|
|
137
|
+
}
|
|
138
|
+
async setup(t) {
|
|
139
|
+
if (t.translations.forEach((e) => {
|
|
140
|
+
i(this, h).set(e.locale, new W(e));
|
|
141
|
+
}), t.locale && t.locale !== "auto") {
|
|
142
|
+
if (!t.translations.some((n) => n.locale === t.locale))
|
|
143
|
+
throw new Error(`Initial locale '${t.locale}' is not registered in the locales array.`);
|
|
144
|
+
N(this, v, t.locale);
|
|
145
|
+
}
|
|
146
|
+
i(this, b).info(
|
|
147
|
+
`${i(this, h).size} language${i(this, h).size === 1 ? "" : "s"} supported: '${[...i(this, h).keys()].join("', '")}'`
|
|
148
|
+
), i(this, h).size > 0 && await this.setLocale(i(this, v));
|
|
149
|
+
}
|
|
150
|
+
async setLocale(t) {
|
|
151
|
+
var a;
|
|
152
|
+
let e;
|
|
153
|
+
if (t === "auto") {
|
|
154
|
+
let s = [];
|
|
155
|
+
if (typeof navigator < "u") {
|
|
156
|
+
const r = navigator;
|
|
157
|
+
((a = r.languages) == null ? void 0 : a.length) > 0 ? s.push(...r.languages) : r.language ? s.push(r.language) : r.browserLanguage ? s.push(r.browserLanguage) : r.userLanguage && s.push(r.userLanguage);
|
|
158
|
+
}
|
|
159
|
+
for (const r of s)
|
|
160
|
+
i(this, h).has(r) && (e = r);
|
|
161
|
+
} else
|
|
162
|
+
i(this, h).has(t) && (e = t);
|
|
163
|
+
if (e == null) {
|
|
164
|
+
const s = i(this, h).keys().next().value;
|
|
165
|
+
s && (e = s);
|
|
166
|
+
}
|
|
167
|
+
if (!e || !i(this, h).has(e))
|
|
168
|
+
throw new Error(`Locale '${t}' has no translation.`);
|
|
169
|
+
const n = i(this, h).get(e);
|
|
170
|
+
try {
|
|
171
|
+
await n.load(), N(this, E, []), i(this, d).call(this, e), i(this, b).info("set language to " + e);
|
|
172
|
+
} catch (s) {
|
|
173
|
+
s instanceof Error && i(this, b).crash(s);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Returns a State containing the value at `key`.
|
|
178
|
+
|
|
179
|
+
* @param selector - Key to the translated value.
|
|
180
|
+
* @param options - A map of `{{placeholder}}` names and the values to replace them with.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* const $value = t("your.key.here", { count: 5 });
|
|
184
|
+
*/
|
|
185
|
+
t(t, e) {
|
|
186
|
+
if (this === void 0)
|
|
187
|
+
throw new Error(
|
|
188
|
+
`The 't' function cannot be destructured. If you need a standalone version you can import it like so: 'import { t } from "@manyducks.co/dolla"'`
|
|
189
|
+
);
|
|
190
|
+
return $(() => {
|
|
191
|
+
const n = {};
|
|
192
|
+
for (const a in e)
|
|
193
|
+
n[a] = x(e[a]);
|
|
194
|
+
return g(this, u, H).call(this, i(this, d).call(this), t, n);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Add a custom format callback.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* Dolla.i18n.addFormat("uppercase", (locale, value, options) => {
|
|
202
|
+
* return value.toUpperCase();
|
|
203
|
+
* });
|
|
204
|
+
*
|
|
205
|
+
* {
|
|
206
|
+
* "greeting": "Hello, {{name|uppercase}}!"
|
|
207
|
+
* }
|
|
208
|
+
*
|
|
209
|
+
* t("greeting", {name: "world"}); // State<"Hello, WORLD!">
|
|
210
|
+
*/
|
|
211
|
+
addFormat(t, e) {
|
|
212
|
+
i(this, T).set(t, e);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Creates an `Intl.Collator` configured for the current locale.
|
|
216
|
+
* NOTE: The locale is tracked if called within a signal tracking context.
|
|
217
|
+
*
|
|
218
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
|
|
219
|
+
*/
|
|
220
|
+
collator(t) {
|
|
221
|
+
return new Intl.Collator(i(this, d).call(this), t);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Formats a number for the current locale. Uses `Intl.NumberFormat` under the hood.
|
|
225
|
+
*
|
|
226
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
|
|
227
|
+
*/
|
|
228
|
+
number(t, e) {
|
|
229
|
+
return $(() => g(this, u, L).call(this, x(t), e));
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Formats a date for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
233
|
+
*
|
|
234
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* const date = new Date();
|
|
238
|
+
* const $formatted = Dolla.i18n.dateTime(date, { dateFormat: "short" });
|
|
239
|
+
*/
|
|
240
|
+
dateTime(t, e) {
|
|
241
|
+
return $(() => g(this, u, V).call(this, x(t), e));
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Formats a list for the current locale. Uses `Intl.ListFormat` under the hood.
|
|
245
|
+
*
|
|
246
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* const list = new Date();
|
|
250
|
+
* const $formatted = Dolla.i18n.list(list, { });
|
|
251
|
+
*/
|
|
252
|
+
list(t, e) {
|
|
253
|
+
return $(() => g(this, u, D).call(this, x(t), e));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
b = new WeakMap(), h = new WeakMap(), E = new WeakMap(), T = new WeakMap(), v = new WeakMap(), d = new WeakMap(), u = new WeakSet(), H = function(t, e, n) {
|
|
257
|
+
var w;
|
|
258
|
+
const a = g(this, u, A).call(this, e, n);
|
|
259
|
+
if (a) return a;
|
|
260
|
+
const s = i(this, h).get(t);
|
|
261
|
+
if (n.context != null && (e += "_" + n.context), n.count != null)
|
|
262
|
+
if (n.ordinal) {
|
|
263
|
+
const l = `${e}_ordinal_(=${n.count})`;
|
|
264
|
+
s.hasTemplate(l) ? e = l : e += "_ordinal_" + new Intl.PluralRules(t, { type: "ordinal" }).select(n.count);
|
|
265
|
+
} else {
|
|
266
|
+
const l = `${e}_(=${n.count})`;
|
|
267
|
+
s.hasTemplate(l) ? e = l : e += "_" + new Intl.PluralRules(t).select(n.count);
|
|
268
|
+
}
|
|
269
|
+
const r = s.getTemplate(e);
|
|
270
|
+
let c = "";
|
|
271
|
+
for (const l of r.segments)
|
|
272
|
+
if (l.type === 0)
|
|
273
|
+
c += l.text;
|
|
274
|
+
else if (l.type === 1) {
|
|
275
|
+
let k = Y(n, l.name);
|
|
276
|
+
const y = ((w = n.formatOverrides) == null ? void 0 : w[l.name]) ?? [...l.formats];
|
|
277
|
+
l.name === "count" && y.length === 0 && y.push({ name: "number", options: {} });
|
|
278
|
+
for (const f of y) {
|
|
279
|
+
const M = i(this, T).get(f.name);
|
|
280
|
+
if (M == null) {
|
|
281
|
+
const R = new Error(
|
|
282
|
+
`Failed to load format '${f.name}' when processing '${e}', template: ${r}`
|
|
283
|
+
);
|
|
284
|
+
throw i(this, b).crash(R), R;
|
|
285
|
+
}
|
|
286
|
+
k = M(t, k, f.options);
|
|
287
|
+
}
|
|
288
|
+
c += k;
|
|
289
|
+
}
|
|
290
|
+
return c;
|
|
291
|
+
}, L = function(t, e) {
|
|
292
|
+
return new Intl.NumberFormat(i(this, d).call(this), e).format(t);
|
|
293
|
+
}, V = function(t, e) {
|
|
294
|
+
return new Intl.DateTimeFormat(i(this, d).call(this), e).format(C(t) ? new Date(t) : t);
|
|
295
|
+
}, D = function(t, e) {
|
|
296
|
+
return new Intl.ListFormat(i(this, d).call(this), e).format(t);
|
|
297
|
+
}, // relativeTime(): State<string> {
|
|
298
|
+
// }
|
|
299
|
+
A = function(t, e) {
|
|
300
|
+
for (const n of i(this, E))
|
|
301
|
+
if (n[0] === t && Q(n[1], e))
|
|
302
|
+
return n[2];
|
|
303
|
+
};
|
|
304
|
+
function Y(o, t) {
|
|
305
|
+
const e = String(t).split(/[\.\[\]]/).filter((a) => a.trim() !== "");
|
|
306
|
+
let n = o;
|
|
307
|
+
for (; e.length > 0; ) {
|
|
308
|
+
const a = e.shift();
|
|
309
|
+
n != null ? n = n[a] : n = void 0;
|
|
310
|
+
}
|
|
311
|
+
return n;
|
|
312
|
+
}
|
|
313
|
+
const q = new X(), st = q.t.bind(q);
|
|
314
|
+
export {
|
|
315
|
+
q as i18n,
|
|
316
|
+
st as t
|
|
317
|
+
};
|
|
318
|
+
//# sourceMappingURL=i18n.js.map
|
package/dist/i18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","sources":["../src/i18n/index.ts"],"sourcesContent":["import { createLogger, type Logger } from \"../core/logger.js\";\nimport { $, get, type MaybeSignal, type Signal } from \"../core/signals.js\";\nimport { isFunction, isObject, isString, typeOf } from \"../typeChecking.js\";\nimport { deepEqual } from \"../utils.js\";\n\n// ----- Types ----- //\n\n/**\n * A JSON object of translated strings. Values can be string templates or nested objects.\n */\ninterface LocalizedStrings extends Record<string, string | LocalizedStrings> {}\n\nenum SegmentType {\n Static,\n Variable,\n}\ntype StringTemplate = { segments: (StaticSegment | VariableSegment)[] };\n/**\n * A string segment with literal text to be appended without processing.\n */\ntype StaticSegment = {\n type: SegmentType.Static;\n text: string;\n};\n/**\n * A variable passed to the t() function. Needs to be formatted before it is appended.\n */\ntype VariableSegment = {\n type: SegmentType.Variable;\n name: string;\n formats: Format[];\n};\n/**\n * A formatter to be applied to a variable.\n */\ntype Format = {\n name: string;\n options: Record<string, any>;\n};\n\nexport interface TranslationConfig {\n /**\n * Name of the locale this translation is for (BCP 47 locale names recommended).\n */\n locale: string;\n\n /**\n * An object with translated strings for this language.\n */\n strings?: LocalizedStrings;\n\n /**\n * A callback function that returns a Promise that resolves to the translation object for this language.\n */\n fetch?: () => Promise<LocalizedStrings>;\n\n /**\n * Path to a JSON file with translated strings for this language.\n */\n path?: string;\n}\n\nexport type I18nSetupOptions = {\n /**\n * Default locale to load on startup\n */\n locale?: string | null;\n\n translations: TranslationConfig[];\n};\n\nexport type TOptions = {\n /**\n *\n */\n count?: MaybeSignal<number>;\n\n /**\n *\n */\n context?: MaybeSignal<string>;\n\n /**\n * Override formats specified in the template with the ones in the array for each named variable.\n *\n * @example\n * t(\"example_key\", {\n * count: 5,\n * formatOverrides: {\n * count: [ { name: \"datetime\", options: { style: \"currency\", currency: \"JPY\" } } ]\n * }\n * });\n */\n formatOverrides?: MaybeSignal<Record<string, Record<string, Format[]>>>;\n\n [value: string]: MaybeSignal<any>;\n};\n\nexport type Formatter = (locale: string, value: unknown, options: Record<string, any>) => string;\n\n// ----- Code ----- //\n\nclass Translation {\n config: TranslationConfig;\n\n #isLoaded = false;\n\n #templates = new Map<string, StringTemplate>();\n\n constructor(config: TranslationConfig) {\n this.config = config;\n }\n\n async load(): Promise<void> {\n let strings: LocalizedStrings | undefined;\n\n if (!this.#isLoaded) {\n if (isObject(this.config.strings)) {\n strings = this.config.strings;\n } else if (isFunction(this.config.fetch)) {\n strings = await this.config.fetch();\n if (!isObject(strings)) {\n throw new Error(`Fetch function did not return an object of language strings: ${strings}`);\n }\n } else if (isString(this.config.path)) {\n const res = await fetch(this.config.path);\n if (res.ok) {\n const body = await res.json();\n if (isObject(body)) {\n strings = body as LocalizedStrings;\n } else {\n throw new Error(\n `Language path '${this.config.path}' did not return an object of language strings: ${body}`,\n );\n }\n } else {\n throw new Error(`HTTP request failed.`);\n }\n }\n }\n\n if (strings) {\n const entries = this.#compile(strings);\n for (const entry of entries) {\n this.#templates.set(entry[0], entry[1]);\n }\n } else {\n throw new Error(`Language could not be loaded.`);\n }\n }\n\n getTemplate(selector: string): StringTemplate {\n return (\n this.#templates.get(selector) ?? {\n segments: [{ type: SegmentType.Static, text: `[MISSING: ${selector}]` }],\n }\n );\n }\n\n hasTemplate(selector: string): boolean {\n return this.#templates.has(selector);\n }\n\n #compile(strings: { [key: string]: any }, path: string[] = []): [string, StringTemplate][] {\n const entries: [string, StringTemplate][] = [];\n\n for (const key in strings) {\n switch (typeOf(strings[key])) {\n case \"string\":\n entries.push([[...path, key].join(\".\"), this.#parseTemplate(strings[key])]);\n break;\n case \"object\":\n entries.push(...this.#compile(strings[key], [...path, key]));\n break;\n default:\n throw new Error(\n `Expected to find a string or object at ${[...path, key].join(\".\")}. Got: ${typeOf(strings[key])}`,\n );\n }\n }\n\n return entries;\n }\n\n #parseTemplate(template: string): StringTemplate {\n // \"{{itemName}} costs {{amount | number(style: currency, currency: USD)}}.\"\n\n enum Loc {\n /**\n * Outside value braces.\n */\n Static,\n /**\n * Inside value braces; currently parsing the name of the value. e.g. `{{ [name] | number(style: currency, currency: USD) }}`\n */\n ValueName,\n /**\n * Inside value braces; currently parsing the name of a format function. e.g. `{{ name | [number](style: currency, currency: USD) }}`\n */\n FormatName,\n /**\n * Inside value braces; currently parsing the name of a format option. e.g. `{{ name | number([style]: currency, currency: USD) }}`\n */\n FormatOptionName,\n /**\n * Inside value braces; currently parsing the value of a format option. e.g. `{{ name | number(style: [currency], currency: USD ) }}`\n */\n FormatOptionValue,\n /**\n * Inside value braces; just reached the closing bracket of a format option. e.g. `{{ name | number(style: [currency], currency: USD) [] }}`\n */\n FormatOptionEnd,\n }\n\n const parsed: StringTemplate = {\n segments: [],\n };\n\n let buffer = \"\";\n let i = 0;\n let loc: Loc = Loc.Static;\n let segment!: VariableSegment;\n let format!: VariableSegment[\"formats\"][0];\n\n let formatOptionName!: string;\n\n const startSegment = () => {\n segment = {\n type: SegmentType.Variable,\n name: \"\",\n formats: [],\n };\n };\n\n const startFormat = () => {\n format = {\n name: \"\",\n options: {},\n };\n };\n\n while (i < template.length) {\n // Skip spaces (unless we're in static)\n if (loc !== Loc.Static && template[i] === \" \") {\n i++;\n continue;\n }\n\n switch (loc) {\n case Loc.Static:\n if (template[i] === \"{\" && template[i + 1] === \"{\") {\n loc = Loc.ValueName;\n i += 2;\n // close static segment\n if (buffer.length > 0) {\n parsed.segments.push({ type: SegmentType.Static, text: buffer });\n buffer = \"\";\n }\n startSegment();\n } else {\n buffer += template[i];\n i++;\n }\n break;\n case Loc.ValueName:\n if (template[i] === \"|\") {\n loc = Loc.FormatName;\n i += 1;\n // add name to value segment\n segment.name = buffer;\n buffer = \"\";\n startFormat();\n } else if (template[i] === \"}\" && template[i + 1] === \"}\") {\n loc = Loc.Static;\n i += 2;\n // close value segment\n segment.name = buffer;\n buffer = \"\";\n parsed.segments.push(segment);\n } else {\n buffer += template[i];\n i++;\n }\n break;\n case Loc.FormatName:\n if (template[i] === \"(\") {\n loc = Loc.FormatOptionName;\n i += 1;\n // add name to format object\n format.name = buffer;\n buffer = \"\";\n } else if (template[i] === \"}\" && template[i + 1] === \"}\") {\n loc = Loc.Static;\n i += 2;\n // close format and value segment\n segment.formats.push(format);\n parsed.segments.push(segment);\n } else {\n buffer += template[i];\n i++;\n }\n break;\n case Loc.FormatOptionName:\n if (template[i] === \")\") {\n // TODO: error - no value provided for option\n } else if (template[i] === \":\") {\n loc = Loc.FormatOptionValue;\n i += 1;\n // add name to format option object\n formatOptionName = buffer;\n buffer = \"\";\n } else if (template[i] === \"}\" && template[i + 1] === \"}\") {\n // TODO: error - format options parenthesis not closed\n } else {\n buffer += template[i];\n i++;\n }\n break;\n case Loc.FormatOptionValue:\n if (template[i] === \")\") {\n loc = Loc.FormatOptionEnd;\n i += 1;\n // add value to format option object\n // add format option to format object; we're done with this format\n format.options[formatOptionName] = buffer;\n buffer = \"\";\n segment.formats.push(format);\n } else if (template[i] === \",\") {\n loc = Loc.FormatOptionName;\n i += 1;\n // add value to format option object\n // add format option to format object; we're adding another option\n format.options[formatOptionName] = buffer;\n buffer = \"\";\n } else if (template[i] === \"}\" && template[i + 1] === \"}\") {\n // TODO: error - format options parenthesis not closed\n } else {\n buffer += template[i];\n i++;\n }\n break;\n case Loc.FormatOptionEnd:\n if (template[i] === \"|\") {\n loc = Loc.FormatName;\n i += 1;\n startFormat();\n } else if (template[i] === \"}\" && template[i + 1] === \"}\") {\n loc = Loc.Static;\n i += 2;\n // add value segment\n parsed.segments.push(segment);\n } else {\n // TODO: error - no other valid characters\n }\n break;\n }\n }\n\n if (loc === Loc.Static && buffer.length > 0) {\n parsed.segments.push({ type: SegmentType.Static, text: buffer });\n }\n\n return parsed;\n }\n}\n\n/**\n * Dolla's I(nternationalizatio)n module. Manages language translations and locale-based formatting.\n */\nclass I18n {\n #logger: Logger;\n #translations = new Map<string, Translation>();\n #cache: [key: string, values: Record<string, any> | undefined, output: string][] = [];\n #formats = new Map<string, Formatter>();\n\n #initialLocale = \"auto\";\n\n #locale = $<string>(\"en\");\n\n readonly $locale = $(this.#locale);\n\n constructor() {\n this.#logger = createLogger(\"Dolla.i18n\");\n\n this.addFormat(\"number\", (_, value, options) => {\n return this.#formatNumber(Number(value), options);\n });\n this.addFormat(\"datetime\", (_, value, options) => {\n return this.#formatDateTime(value as any, options);\n });\n this.addFormat(\"list\", (_, value, options) => {\n return this.#formatList(value as any, options);\n });\n }\n\n get locales() {\n return [...this.#translations.keys()];\n }\n\n async setup(options: I18nSetupOptions) {\n // Convert languages into Language instances.\n options.translations.forEach((entry) => {\n this.#translations.set(entry.locale, new Translation(entry));\n });\n\n // Check that initialLanguage is actually registered.\n if (options.locale && options.locale !== \"auto\") {\n const isRegistered = options.translations.some((entry) => entry.locale === options.locale);\n if (!isRegistered) {\n throw new Error(`Initial locale '${options.locale}' is not registered in the locales array.`);\n }\n this.#initialLocale = options.locale;\n }\n\n this.#logger.info(\n `${this.#translations.size} language${this.#translations.size === 1 ? \"\" : \"s\"} supported: '${[...this.#translations.keys()].join(\"', '\")}'`,\n );\n\n if (this.#translations.size > 0) {\n await this.setLocale(this.#initialLocale);\n }\n }\n\n async setLocale(name: string) {\n let realName!: string;\n\n if (name === \"auto\") {\n let names = [];\n\n if (typeof navigator !== \"undefined\") {\n const nav = navigator as any;\n\n if (nav.languages?.length > 0) {\n names.push(...nav.languages);\n } else if (nav.language) {\n names.push(nav.language);\n } else if (nav.browserLanguage) {\n names.push(nav.browserLanguage);\n } else if (nav.userLanguage) {\n names.push(nav.userLanguage);\n }\n }\n\n for (const name of names) {\n if (this.#translations.has(name)) {\n // Found a matching language.\n realName = name;\n }\n }\n } else {\n // Tag is the actual tag to set.\n if (this.#translations.has(name)) {\n realName = name;\n }\n }\n\n if (realName == null) {\n const firstLanguage = this.#translations.keys().next().value;\n if (firstLanguage) {\n realName = firstLanguage;\n }\n }\n\n if (!realName || !this.#translations.has(realName)) {\n throw new Error(`Locale '${name}' has no translation.`);\n }\n\n const translation = this.#translations.get(realName)!;\n\n try {\n await translation.load();\n\n this.#cache = [];\n this.#locale(realName);\n\n this.#logger.info(\"set language to \" + realName);\n } catch (error) {\n if (error instanceof Error) {\n this.#logger.crash(error);\n }\n }\n }\n\n /**\n * Returns a State containing the value at `key`.\n\n * @param selector - Key to the translated value.\n * @param options - A map of `{{placeholder}}` names and the values to replace them with.\n *\n * @example\n * const $value = t(\"your.key.here\", { count: 5 });\n */\n t(selector: string, options?: TOptions): Signal<string> {\n if (this === undefined) {\n throw new Error(\n `The 't' function cannot be destructured. If you need a standalone version you can import it like so: 'import { t } from \"@manyducks.co/dolla\"'`,\n );\n }\n\n return $(() => {\n const values: Record<string, any> = {};\n\n // Track all option values.\n for (const key in options) {\n values[key] = get(options[key]);\n }\n\n return this.#getValue(this.#locale(), selector, values);\n });\n }\n\n #getValue(locale: string, selector: string, options: Record<string, any>): string {\n const cached = this.#getCached(selector, options);\n if (cached) return cached;\n\n const translation = this.#translations.get(locale)!;\n\n // Handle count (pluralization) and context. Keys become \"key_context_pluralization\".\n\n if (options.context != null) {\n selector += \"_\" + options.context;\n }\n if (options.count != null) {\n if (options.ordinal) {\n // Try to match the exact number key if there is one (e.g. \"myExampleKey_ordinal_(=2)\" when count is 2).\n const exact = `${selector}_ordinal_(=${options.count})`;\n if (translation.hasTemplate(exact)) {\n selector = exact;\n } else {\n selector += \"_ordinal_\" + new Intl.PluralRules(locale, { type: \"ordinal\" }).select(options.count);\n }\n } else {\n // Try to match the exact number key if there is one (e.g. \"myExampleKey_(=2)\" when count is 2).\n const exact = `${selector}_(=${options.count})`;\n if (translation.hasTemplate(exact)) {\n selector = exact;\n } else {\n selector += \"_\" + new Intl.PluralRules(locale).select(options.count);\n }\n }\n }\n\n const template = translation.getTemplate(selector);\n let output = \"\";\n\n for (const segment of template.segments) {\n if (segment.type === SegmentType.Static) {\n output += segment.text;\n } else if (segment.type === SegmentType.Variable) {\n let value = resolve(options, segment.name);\n\n const formats = options.formatOverrides?.[segment.name] ?? [...segment.formats];\n\n if (segment.name === \"count\" && formats.length === 0) {\n formats.push({ name: \"number\", options: {} });\n }\n\n for (const format of formats) {\n const fn = this.#formats.get(format.name);\n if (fn == null) {\n const error = new Error(\n `Failed to load format '${format.name}' when processing '${selector}', template: ${template}`,\n );\n this.#logger.crash(error);\n throw error;\n }\n value = fn(locale, value, format.options);\n }\n\n output += value;\n }\n }\n\n return output;\n }\n\n /**\n * Add a custom format callback.\n *\n * @example\n * Dolla.i18n.addFormat(\"uppercase\", (locale, value, options) => {\n * return value.toUpperCase();\n * });\n *\n * {\n * \"greeting\": \"Hello, {{name|uppercase}}!\"\n * }\n *\n * t(\"greeting\", {name: \"world\"}); // State<\"Hello, WORLD!\">\n */\n addFormat(name: string, callback: (locale: string, value: unknown, options: Record<string, any>) => string) {\n this.#formats.set(name, callback);\n }\n\n /**\n * Creates an `Intl.Collator` configured for the current locale.\n * NOTE: The locale is tracked if called within a signal tracking context.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options\n */\n collator(options?: Intl.CollatorOptions) {\n return new Intl.Collator(this.#locale(), options);\n }\n\n /**\n * Formats a number for the current locale. Uses `Intl.NumberFormat` under the hood.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options\n */\n number(count: MaybeSignal<number | bigint>, options?: Intl.NumberFormatOptions): Signal<string> {\n return $(() => this.#formatNumber(get(count), options));\n }\n\n #formatNumber(count: number | bigint, options?: Intl.NumberFormatOptions): string {\n // NOTE: Locale is tracked if called within a tracking context.\n return new Intl.NumberFormat(this.#locale(), options).format(count);\n }\n\n /**\n * Formats a date for the current locale. Uses `Intl.DateTimeFormat` under the hood.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options\n *\n * @example\n * const date = new Date();\n * const $formatted = Dolla.i18n.dateTime(date, { dateFormat: \"short\" });\n */\n dateTime(\n date?: MaybeSignal<string | number | Date | undefined>,\n options?: Intl.DateTimeFormatOptions,\n ): Signal<string> {\n return $(() => this.#formatDateTime(get(date), options));\n }\n\n #formatDateTime(date?: string | number | Date, options?: Intl.DateTimeFormatOptions): string {\n // NOTE: Locale is tracked if called within a tracking context.\n return new Intl.DateTimeFormat(this.#locale(), options).format(isString(date) ? new Date(date) : date);\n }\n\n /**\n * Formats a list for the current locale. Uses `Intl.ListFormat` under the hood.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options\n *\n * @example\n * const list = new Date();\n * const $formatted = Dolla.i18n.list(list, { });\n */\n list(list: MaybeSignal<Iterable<string>>, options?: Intl.ListFormatOptions): Signal<string> {\n return $(() => this.#formatList(get(list), options));\n }\n\n #formatList(list: Iterable<string>, options?: Intl.ListFormatOptions): string {\n // NOTE: Locale is tracked if called within a tracking context.\n return new Intl.ListFormat(this.#locale(), options).format(list);\n }\n\n // relativeTime(): State<string> {\n\n // }\n\n #getCached(key: string, values?: Record<string, any>): string | undefined {\n for (const entry of this.#cache) {\n if (entry[0] === key && deepEqual(entry[1], values)) {\n return entry[2];\n }\n }\n }\n}\n\nfunction resolve(object: any, key: string) {\n const parsed = String(key)\n .split(/[\\.\\[\\]]/)\n .filter((part) => part.trim() !== \"\");\n let value = object;\n\n while (parsed.length > 0) {\n const part = parsed.shift()!;\n\n if (value != null) {\n value = value[part];\n } else {\n value = undefined;\n }\n }\n\n return value;\n}\n\nexport const i18n = new I18n();\nexport const t = i18n.t.bind(i18n);\n"],"names":["Translation","config","__privateAdd","_Translation_instances","__publicField","_isLoaded","_templates","strings","__privateGet","isObject","isFunction","isString","res","body","entries","__privateMethod","compile_fn","entry","selector","path","key","typeOf","parseTemplate_fn","template","Loc","Loc2","parsed","buffer","i","loc","segment","format","formatOptionName","startSegment","startFormat","I18n","_I18n_instances","_logger","_translations","_cache","_formats","_initialLocale","_locale","__privateSet","createLogger","_","value","options","formatNumber_fn","formatDateTime_fn","formatList_fn","name","realName","names","nav","_a","firstLanguage","translation","error","values","get","getValue_fn","callback","count","date","list","locale","cached","getCached_fn","exact","output","resolve","formats","fn","deepEqual","object","part","i18n","t"],"mappings":";;;;;;;;;;AAsGA,MAAMA,EAAY;AAAA,EAOhB,YAAYC,GAA2B;AAPzC,IAAAC,EAAA,MAAAC;AACE,IAAAC,EAAA;AAEA,IAAAF,EAAA,MAAAG,GAAY;AAEZ,IAAAH,EAAA,MAAAI,uBAAiB,IAA4B;AAG3C,SAAK,SAASL;AAAA,EAAA;AAAA,EAGhB,MAAM,OAAsB;AACtB,QAAAM;AAEA,QAAA,CAACC,EAAA,MAAKH;AACR,UAAII,EAAS,KAAK,OAAO,OAAO;AAC9B,QAAAF,IAAU,KAAK,OAAO;AAAA,eACbG,EAAW,KAAK,OAAO,KAAK;AAEjC,YADMH,IAAA,MAAM,KAAK,OAAO,MAAM,GAC9B,CAACE,EAASF,CAAO;AACnB,gBAAM,IAAI,MAAM,gEAAgEA,CAAO,EAAE;AAAA,iBAElFI,EAAS,KAAK,OAAO,IAAI,GAAG;AACrC,cAAMC,IAAM,MAAM,MAAM,KAAK,OAAO,IAAI;AACxC,YAAIA,EAAI,IAAI;AACJ,gBAAAC,IAAO,MAAMD,EAAI,KAAK;AACxB,cAAAH,EAASI,CAAI;AACL,YAAAN,IAAAM;AAAA;AAEV,kBAAM,IAAI;AAAA,cACR,kBAAkB,KAAK,OAAO,IAAI,mDAAmDA,CAAI;AAAA,YAC3F;AAAA,QACF;AAEM,gBAAA,IAAI,MAAM,sBAAsB;AAAA,MACxC;AAAA;AAIJ,QAAIN,GAAS;AACL,YAAAO,IAAUC,EAAA,MAAKZ,GAAAa,GAAL,WAAcT;AAC9B,iBAAWU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