@manyducks.co/dolla 2.0.0-alpha.61 → 2.0.0-alpha.63
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 +20 -26
- package/dist/core/context.d.ts +23 -4
- package/dist/core/index.d.ts +5 -3
- package/dist/core/markup.d.ts +6 -11
- package/dist/core/nodes/dynamic.d.ts +3 -3
- package/dist/core/nodes/element.d.ts +2 -0
- package/dist/core/nodes/repeat.d.ts +1 -1
- package/dist/core/nodes/view.d.ts +4 -4
- package/dist/core/scheduler.d.ts +17 -0
- package/dist/core/signals.d.ts +48 -14
- package/dist/core/views/default-crash-view.d.ts +1 -1
- package/dist/core/views/for.d.ts +23 -0
- package/dist/core/views/show.d.ts +26 -0
- package/dist/hooks/index.d.ts +5 -8
- package/dist/hooks.js +26 -31
- package/dist/hooks.js.map +1 -1
- package/dist/i18n.js +23 -23
- package/dist/i18n.js.map +1 -1
- package/dist/index.js +69 -53
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +1 -1
- package/dist/jsx-runtime.js +1 -1
- package/dist/logger-B7RBYtzP.js +82 -0
- package/dist/logger-B7RBYtzP.js.map +1 -0
- package/dist/{markup-CX27GJ1M.js → markup-CW_lWDfq.js} +410 -325
- package/dist/markup-CW_lWDfq.js.map +1 -0
- package/dist/router/router.d.ts +10 -5
- package/dist/{router-CjCkk4dA.js → router-CBGsADQ4.js} +100 -100
- package/dist/router-CBGsADQ4.js.map +1 -0
- package/dist/router.js +1 -1
- package/dist/{signals-gCwiIe5X.js → signals-DbDmN2gr.js} +190 -161
- package/dist/signals-DbDmN2gr.js.map +1 -0
- package/docs/signals.md +16 -14
- package/notes/scratch.md +23 -1
- package/package.json +3 -2
- package/dist/logger-Bl496yfY.js +0 -91
- package/dist/logger-Bl496yfY.js.map +0 -1
- package/dist/markup-CX27GJ1M.js.map +0 -1
- package/dist/router-CjCkk4dA.js.map +0 -1
- package/dist/signals-gCwiIe5X.js.map +0 -1
package/dist/i18n.js
CHANGED
|
@@ -5,11 +5,11 @@ var D = (o) => {
|
|
|
5
5
|
var J = (o, t, e) => t in o ? B(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
6
6
|
var O = (o, t, e) => J(o, typeof t != "symbol" ? t + "" : t, e), _ = (o, t, e) => t.has(o) || D("Cannot " + e);
|
|
7
7
|
var r = (o, t, e) => (_(o, t, "read from private field"), e ? e.call(o) : t.get(o)), m = (o, t, e) => t.has(o) ? D("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 { c as K } from "./logger-
|
|
9
|
-
import {
|
|
10
|
-
import { b as C, i as j, c as
|
|
8
|
+
import { c as K } from "./logger-B7RBYtzP.js";
|
|
9
|
+
import { w as Q, m as k, d as U, g as x } from "./signals-DbDmN2gr.js";
|
|
10
|
+
import { b as C, i as j, c as W, t as P } from "./typeChecking-CbltMOUt.js";
|
|
11
11
|
var I, F, p, S, G;
|
|
12
|
-
class
|
|
12
|
+
class X {
|
|
13
13
|
constructor(t) {
|
|
14
14
|
m(this, p);
|
|
15
15
|
O(this, "config");
|
|
@@ -22,7 +22,7 @@ class W {
|
|
|
22
22
|
if (!r(this, I)) {
|
|
23
23
|
if (j(this.config.strings))
|
|
24
24
|
t = this.config.strings;
|
|
25
|
-
else if (
|
|
25
|
+
else if (W(this.config.fetch)) {
|
|
26
26
|
if (t = await this.config.fetch(), !j(t))
|
|
27
27
|
throw new Error(`Fetch function did not return an object of language strings: ${t}`);
|
|
28
28
|
} else if (C(this.config.path)) {
|
|
@@ -80,7 +80,7 @@ I = new WeakMap(), F = new WeakMap(), p = new WeakSet(), S = function(t, e = [])
|
|
|
80
80
|
segments: []
|
|
81
81
|
};
|
|
82
82
|
let a = "", s = 0, i = 0, c, w, l;
|
|
83
|
-
const
|
|
83
|
+
const $ = () => {
|
|
84
84
|
c = {
|
|
85
85
|
type: 1,
|
|
86
86
|
name: "",
|
|
@@ -99,7 +99,7 @@ I = new WeakMap(), F = new WeakMap(), p = new WeakSet(), S = function(t, e = [])
|
|
|
99
99
|
}
|
|
100
100
|
switch (i) {
|
|
101
101
|
case 0:
|
|
102
|
-
t[s] === "{" && t[s + 1] === "{" ? (i = 1, s += 2, a.length > 0 && (n.segments.push({ type: 0, text: a }), a = ""),
|
|
102
|
+
t[s] === "{" && t[s + 1] === "{" ? (i = 1, s += 2, a.length > 0 && (n.segments.push({ type: 0, text: a }), a = ""), $()) : (a += t[s], s++);
|
|
103
103
|
break;
|
|
104
104
|
case 1:
|
|
105
105
|
t[s] === "|" ? (i = 2, s += 1, c.name = a, a = "", y()) : t[s] === "}" && t[s + 1] === "}" ? (i = 0, s += 2, c.name = a, a = "", n.segments.push(c)) : (a += t[s], s++);
|
|
@@ -121,7 +121,7 @@ I = new WeakMap(), F = new WeakMap(), p = new WeakSet(), S = function(t, e = [])
|
|
|
121
121
|
return i === 0 && a.length > 0 && n.segments.push({ type: 0, text: a }), n;
|
|
122
122
|
};
|
|
123
123
|
var b, h, E, T, v, d, u, H, L, V, M, A;
|
|
124
|
-
class
|
|
124
|
+
class Y {
|
|
125
125
|
constructor() {
|
|
126
126
|
m(this, u);
|
|
127
127
|
m(this, b);
|
|
@@ -129,8 +129,8 @@ class X {
|
|
|
129
129
|
m(this, E, []);
|
|
130
130
|
m(this, T, /* @__PURE__ */ new Map());
|
|
131
131
|
m(this, v, "auto");
|
|
132
|
-
m(this, d,
|
|
133
|
-
O(this, "$locale",
|
|
132
|
+
m(this, d, Q("en"));
|
|
133
|
+
O(this, "$locale", k(r(this, d)));
|
|
134
134
|
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, M).call(this, e, n));
|
|
135
135
|
}
|
|
136
136
|
get locales() {
|
|
@@ -138,7 +138,7 @@ class X {
|
|
|
138
138
|
}
|
|
139
139
|
async setup(t) {
|
|
140
140
|
if (t.translations.forEach((e) => {
|
|
141
|
-
r(this, h).set(e.locale, new
|
|
141
|
+
r(this, h).set(e.locale, new X(e));
|
|
142
142
|
}), t.locale && t.locale !== "auto") {
|
|
143
143
|
if (!t.translations.some((n) => n.locale === t.locale))
|
|
144
144
|
throw new Error(`Initial locale '${t.locale}' is not registered in the locales array.`);
|
|
@@ -169,7 +169,7 @@ class X {
|
|
|
169
169
|
throw new Error(`Locale '${t}' has no translation.`);
|
|
170
170
|
const n = r(this, h).get(e);
|
|
171
171
|
try {
|
|
172
|
-
await n.load(), N(this, E, []), r(this, d).
|
|
172
|
+
await n.load(), N(this, E, []), r(this, d).set(e), r(this, b).info("set language to " + e);
|
|
173
173
|
} catch (s) {
|
|
174
174
|
s instanceof Error && r(this, b).crash(s);
|
|
175
175
|
}
|
|
@@ -188,7 +188,7 @@ class X {
|
|
|
188
188
|
throw new Error(
|
|
189
189
|
`The 't' function cannot be destructured. If you need a standalone version you can import it like so: 'import { t } from "@manyducks.co/dolla"'`
|
|
190
190
|
);
|
|
191
|
-
return
|
|
191
|
+
return k(() => {
|
|
192
192
|
const n = {};
|
|
193
193
|
for (const a in e)
|
|
194
194
|
n[a] = x(e[a]);
|
|
@@ -227,7 +227,7 @@ class X {
|
|
|
227
227
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
|
|
228
228
|
*/
|
|
229
229
|
number(t, e) {
|
|
230
|
-
return
|
|
230
|
+
return k(() => g(this, u, L).call(this, x(t), e));
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
233
233
|
* Formats a date for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
@@ -239,7 +239,7 @@ class X {
|
|
|
239
239
|
* const $formatted = Dolla.i18n.dateTime(date, { dateFormat: "short" });
|
|
240
240
|
*/
|
|
241
241
|
dateTime(t, e) {
|
|
242
|
-
return
|
|
242
|
+
return k(() => g(this, u, V).call(this, x(t), e));
|
|
243
243
|
}
|
|
244
244
|
/**
|
|
245
245
|
* Formats a list for the current locale. Uses `Intl.ListFormat` under the hood.
|
|
@@ -251,7 +251,7 @@ class X {
|
|
|
251
251
|
* const $formatted = Dolla.i18n.list(list, { });
|
|
252
252
|
*/
|
|
253
253
|
list(t, e) {
|
|
254
|
-
return
|
|
254
|
+
return k(() => g(this, u, M).call(this, x(t), e));
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
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) {
|
|
@@ -273,7 +273,7 @@ b = new WeakMap(), h = new WeakMap(), E = new WeakMap(), T = new WeakMap(), v =
|
|
|
273
273
|
if (l.type === 0)
|
|
274
274
|
c += l.text;
|
|
275
275
|
else if (l.type === 1) {
|
|
276
|
-
let
|
|
276
|
+
let $ = Z(n, l.name);
|
|
277
277
|
const y = ((w = n.formatOverrides) == null ? void 0 : w[l.name]) ?? [...l.formats];
|
|
278
278
|
l.name === "count" && y.length === 0 && y.push({ name: "number", options: {} });
|
|
279
279
|
for (const f of y) {
|
|
@@ -284,9 +284,9 @@ b = new WeakMap(), h = new WeakMap(), E = new WeakMap(), T = new WeakMap(), v =
|
|
|
284
284
|
);
|
|
285
285
|
throw r(this, b).crash(z), z;
|
|
286
286
|
}
|
|
287
|
-
|
|
287
|
+
$ = R(t, $, f.options);
|
|
288
288
|
}
|
|
289
|
-
c +=
|
|
289
|
+
c += $;
|
|
290
290
|
}
|
|
291
291
|
return c;
|
|
292
292
|
}, L = function(t, e) {
|
|
@@ -298,10 +298,10 @@ b = new WeakMap(), h = new WeakMap(), E = new WeakMap(), T = new WeakMap(), v =
|
|
|
298
298
|
}, // relativeTime(date?: MaybeSignal<string | number | Date | undefined>): Signal<string> {}
|
|
299
299
|
A = function(t, e) {
|
|
300
300
|
for (const n of r(this, E))
|
|
301
|
-
if (n[0] === t &&
|
|
301
|
+
if (n[0] === t && U(n[1], e))
|
|
302
302
|
return n[2];
|
|
303
303
|
};
|
|
304
|
-
function
|
|
304
|
+
function Z(o, t) {
|
|
305
305
|
const e = String(t).split(/[\.\[\]]/).filter((a) => a.trim() !== "");
|
|
306
306
|
let n = o;
|
|
307
307
|
for (; e.length > 0; ) {
|
|
@@ -310,9 +310,9 @@ function Y(o, t) {
|
|
|
310
310
|
}
|
|
311
311
|
return n;
|
|
312
312
|
}
|
|
313
|
-
const q = new
|
|
313
|
+
const q = new Y(), at = q.t.bind(q);
|
|
314
314
|
export {
|
|
315
315
|
q as i18n,
|
|
316
|
-
|
|
316
|
+
at as t
|
|
317
317
|
};
|
|
318
318
|
//# sourceMappingURL=i18n.js.map
|
package/dist/i18n.js.map
CHANGED
|
@@ -1 +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(date?: MaybeSignal<string | number | Date | undefined>): Signal<string> {}\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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AA,SAAce,GAAwBhB,GAA4C;AAEzE,SAAA,IAAI,KAAK,aAAavC,EAAA,MAAKkC,GAAL,YAAgBK,CAAO,EAAE,OAAOgB,CAAK;AAAA,GAmBpEd,IAAA,SAAgBe,GAA+BjB,GAA8C;AAE3F,SAAO,IAAI,KAAK,eAAevC,EAAA,MAAKkC,GAAL,YAAgBK,CAAO,EAAE,OAAOpC,EAASqD,CAAI,IAAI,IAAI,KAAKA,CAAI,IAAIA,CAAI;AAAA,GAgBvGd,IAAA,SAAYe,GAAwBlB,GAA0C;AAErE,SAAA,IAAI,KAAK,WAAWvC,EAAA,MAAKkC,GAAL,YAAgBK,CAAO,EAAE,OAAOkB,CAAI;AAAA;AAKjEG,IAAA,SAAWhD,GAAauC,GAAkD;AAC7D,aAAA1C,KAAST,EAAA,MAAK+B;AACnB,QAAAtB,EAAM,CAAC,MAAMG,KAAOsD,EAAUzD,EAAM,CAAC,GAAG0C,CAAM;AAChD,aAAO1C,EAAM,CAAC;AAElB;AAIJ,SAASsD,EAAQI,GAAavD,GAAa;AACzC,QAAMM,IAAS,OAAON,CAAG,EACtB,MAAM,UAAU,EAChB,OAAO,CAACwD,MAASA,EAAK,KAAA,MAAW,EAAE;AACtC,MAAI9B,IAAQ6B;AAEL,SAAAjD,EAAO,SAAS,KAAG;AAClB,UAAAkD,IAAOlD,EAAO,MAAM;AAE1B,IAAIoB,KAAS,OACXA,IAAQA,EAAM8B,CAAI,IAEV9B,IAAA;AAAA,EACV;AAGK,SAAAA;AACT;AAEa,MAAA+B,IAAO,IAAI1C,EAAK,GAChB2C,KAAID,EAAK,EAAE,KAAKA,CAAI;"}
|
|
1
|
+
{"version":3,"file":"i18n.js","sources":["../src/i18n/index.ts"],"sourcesContent":["import { createLogger, type Logger } from \"../core/logger.js\";\nimport { writable, get, type MaybeSignal, type Signal, memo } 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 = writable<string>(\"en\");\n\n readonly $locale = memo(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.set(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 memo(() => {\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 memo(() => 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 memo(() => 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 memo(() => 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(date?: MaybeSignal<string | number | Date | undefined>): Signal<string> {}\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","writable","memo","__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,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B,IAAQ6B;AAEL,SAAAnD,EAAO,SAAS,KAAG;AAClB,UAAAoD,IAAOpD,EAAO,MAAM;AAE1B,IAAIsB,KAAS,OACXA,IAAQA,EAAM8B,CAAI,IAEV9B,IAAA;AAAA,EACV;AAGK,SAAAA;AACT;AAEa,MAAA+B,IAAO,IAAI5C,EAAK,GAChB6C,KAAID,EAAK,EAAE,KAAKA,CAAI;"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { r as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { g as m } from "./signals-DbDmN2gr.js";
|
|
2
|
+
import { $ as q, b as S, d as _, e as $, c as B, m as W, f as z, s as A, a as G, u as K, w as P } from "./signals-DbDmN2gr.js";
|
|
3
|
+
import { R as g, D as w, m as n, w as y, C as s, L as c, V as f } from "./markup-CW_lWDfq.js";
|
|
4
|
+
import { M as H, a as J, c as Q, p as X, r as Y, b as Z, u as p } from "./markup-CW_lWDfq.js";
|
|
5
|
+
import { r as ae } from "./ref-BD79iqlg.js";
|
|
6
|
+
import { R as N, M as b, U as x } from "./router-CBGsADQ4.js";
|
|
7
|
+
import { a as L } from "./typeChecking-CbltMOUt.js";
|
|
8
|
+
import { o as M } from "./logger-B7RBYtzP.js";
|
|
9
|
+
import { c as ne, s as re, a as se } from "./logger-B7RBYtzP.js";
|
|
10
|
+
const k = (e) => e;
|
|
11
|
+
function E(e, t) {
|
|
12
|
+
return new g(t, e.each, e.key ?? k, e.children);
|
|
13
|
+
}
|
|
14
|
+
function F(e, t) {
|
|
15
|
+
return new w(t, () => {
|
|
16
|
+
let a = !0;
|
|
17
|
+
return e.when != null && e.unless != null ? a = m(e.when) && !m(e.unless) : e.when != null ? a = m(e.when) : e.unless != null && (a = !m(e.unless)), a ? e.children : e.fallback;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function U(e) {
|
|
21
|
+
return n("div", {
|
|
11
22
|
style: {
|
|
12
23
|
backgroundColor: "#880000",
|
|
13
24
|
color: "#fff",
|
|
@@ -17,17 +28,17 @@ function N(e) {
|
|
|
17
28
|
fontSize: "20px"
|
|
18
29
|
},
|
|
19
30
|
children: [
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
n("h1", { style: { marginBottom: "0.5rem" }, children: "The app has crashed" }),
|
|
32
|
+
n("p", {
|
|
22
33
|
style: { marginBottom: "0.25rem" },
|
|
23
34
|
children: [
|
|
24
|
-
|
|
35
|
+
n("span", {
|
|
25
36
|
style: { fontFamily: "monospace" },
|
|
26
37
|
children: e.loggerName
|
|
27
38
|
}),
|
|
28
|
-
|
|
39
|
+
y(
|
|
29
40
|
e.tag,
|
|
30
|
-
|
|
41
|
+
n("span", {
|
|
31
42
|
style: { fontFamily: "monospace", opacity: 0.5 },
|
|
32
43
|
children: ` [${e.tagName ? `${e.tagName}: ` : ""}${e.tag}]`
|
|
33
44
|
})
|
|
@@ -35,7 +46,7 @@ function N(e) {
|
|
|
35
46
|
" says:"
|
|
36
47
|
]
|
|
37
48
|
}),
|
|
38
|
-
|
|
49
|
+
n("blockquote", {
|
|
39
50
|
style: {
|
|
40
51
|
backgroundColor: "#991111",
|
|
41
52
|
padding: "0.25em",
|
|
@@ -44,7 +55,7 @@ function N(e) {
|
|
|
44
55
|
marginBottom: "1rem"
|
|
45
56
|
},
|
|
46
57
|
children: [
|
|
47
|
-
|
|
58
|
+
n("span", {
|
|
48
59
|
style: {
|
|
49
60
|
display: "inline-block",
|
|
50
61
|
backgroundColor: "red",
|
|
@@ -59,48 +70,53 @@ function N(e) {
|
|
|
59
70
|
e.error.message
|
|
60
71
|
]
|
|
61
72
|
}),
|
|
62
|
-
|
|
73
|
+
n("p", { children: "Please see the browser console for details." })
|
|
63
74
|
]
|
|
64
75
|
});
|
|
65
76
|
}
|
|
66
|
-
let
|
|
67
|
-
async function
|
|
68
|
-
if (
|
|
77
|
+
let l = !1;
|
|
78
|
+
async function V(e, t, a) {
|
|
79
|
+
if (L(Element, t, "Expected an element or a selector string. Got type: %t, value: %v"), l)
|
|
69
80
|
throw new Error("A Dolla app is already mounted.");
|
|
70
|
-
let
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}), s.emit(
|
|
75
|
-
async function
|
|
76
|
-
|
|
81
|
+
let o, i, d = (a == null ? void 0 : a.crashView) ?? U;
|
|
82
|
+
const r = (a == null ? void 0 : a.context) ?? new s("App");
|
|
83
|
+
M((h) => {
|
|
84
|
+
l && u(), new f(r, d, h).mount(t);
|
|
85
|
+
}), s.emit(r, c.WILL_MOUNT), e instanceof N ? (i = e, o = await i[b](t, r)) : o = new f(r, e, {}), o.mount(t), l = !0, s.emit(r, c.DID_MOUNT);
|
|
86
|
+
async function u() {
|
|
87
|
+
l && (s.emit(r, c.WILL_UNMOUNT), o.unmount(!1), i && await i[x](), l = !1, s.emit(r, c.DID_UNMOUNT));
|
|
77
88
|
}
|
|
78
|
-
return
|
|
89
|
+
return u;
|
|
79
90
|
}
|
|
80
91
|
export {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
q as $,
|
|
93
|
+
E as For,
|
|
94
|
+
H as Markup,
|
|
95
|
+
J as MarkupNode,
|
|
96
|
+
F as Show,
|
|
97
|
+
S as batch,
|
|
98
|
+
Q as createContext,
|
|
99
|
+
ne as createLogger,
|
|
100
|
+
_ as deepEqual,
|
|
101
|
+
$ as effect,
|
|
102
|
+
m as get,
|
|
103
|
+
B as getEnv,
|
|
104
|
+
n as m,
|
|
105
|
+
W as memo,
|
|
106
|
+
V as mount,
|
|
107
|
+
M as onLoggerCrash,
|
|
108
|
+
X as portal,
|
|
109
|
+
ae as ref,
|
|
110
|
+
Y as render,
|
|
111
|
+
Z as repeat,
|
|
112
|
+
z as setEnv,
|
|
113
|
+
re as setLogFilter,
|
|
114
|
+
se as setLogLevels,
|
|
115
|
+
A as shallowEqual,
|
|
116
|
+
G as strictEqual,
|
|
117
|
+
p as unless,
|
|
118
|
+
K as untracked,
|
|
119
|
+
y as when,
|
|
120
|
+
P as writable
|
|
105
121
|
};
|
|
106
122
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/core/views/default-crash-view.ts","../src/core/mount.ts"],"sourcesContent":["import { when, m } from \"../markup.js\";\n\n/**\n * Props passed to the crash view when a crash occurs.\n */\nexport interface CrashViewProps {\n /**\n * JavaScript Error object.\n */\n error: Error;\n\n /**\n * A string to identify the logger that reported this error.\n */\n loggerName: string;\n\n /**\n * Unique identifier to pinpoint the specific view that reported the crash.\n */\n tag?: string;\n\n /**\n * Label for the tag.\n */\n tagName?: string;\n}\n\n/**\n * The crash view displayed unless you specify your own.\n */\nexport function DefaultCrashView(props: CrashViewProps) {\n return m(\"div\", {\n style: {\n backgroundColor: \"#880000\",\n color: \"#fff\",\n padding: \"2rem\",\n position: \"fixed\",\n inset: 0,\n fontSize: \"20px\",\n },\n children: [\n m(\"h1\", { style: { marginBottom: \"0.5rem\" }, children: \"The app has crashed\" }),\n m(\"p\", {\n style: { marginBottom: \"0.25rem\" },\n children: [\n m(\"span\", {\n style: { fontFamily: \"monospace\" },\n children: props.loggerName,\n }),\n when(\n props.tag,\n m(\"span\", {\n style: { fontFamily: \"monospace\", opacity: 0.5 },\n children: ` [${props.tagName ? `${props.tagName}: ` : \"\"}${props.tag}]`,\n }),\n ),\n \" says:\",\n ],\n }),\n m(\"blockquote\", {\n style: {\n backgroundColor: \"#991111\",\n padding: \"0.25em\",\n borderRadius: \"6px\",\n fontFamily: \"monospace\",\n marginBottom: \"1rem\",\n },\n children: [\n m(\"span\", {\n style: {\n display: \"inline-block\",\n backgroundColor: \"red\",\n padding: \"0.1em 0.4em\",\n marginRight: \"0.5em\",\n borderRadius: \"4px\",\n fontSize: \"0.9em\",\n fontWeight: \"bold\",\n },\n children: props.error.name,\n }),\n props.error.message,\n ],\n }),\n m(\"p\", { children: \"Please see the browser console for details.\" }),\n ],\n });\n}\n","import { MOUNT, Router, UNMOUNT } from \"../router/router\";\nimport { assertInstanceOf } from \"../typeChecking\";\nimport type { View } from \"../types\";\nimport { Context, LifecycleEvent } from \"./context\";\nimport { type LoggerCrashProps, onLoggerCrash } from \"./logger\";\nimport { type MarkupNode } from \"./markup\";\nimport { ViewNode } from \"./nodes/view\";\nimport { DefaultCrashView } from \"./views/default-crash-view\";\n\nlet isMounted = false;\n\nexport type UnmountFn = () => Promise<void>;\nexport interface MountOptions {\n crashView?: View<LoggerCrashProps>;\n\n /**\n * An existing Context to use as the root, otherwise a new one will be created.\n * Use this to provide top-level stores and state to the whole app.\n */\n context?: Context;\n}\n\nexport async function mount(view: View<{}>, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\nexport async function mount(router: Router, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\n\nexport async function mount(view: any, rootElement: Element, options?: MountOptions): Promise<UnmountFn> {\n assertInstanceOf(Element, rootElement, \"Expected an element or a selector string. Got type: %t, value: %v\");\n\n if (isMounted) {\n throw new Error(`A Dolla app is already mounted.`);\n }\n\n let rootView: MarkupNode;\n let router: Router | undefined;\n let crashView = options?.crashView ?? DefaultCrashView;\n\n const rootContext = options?.context ?? new Context(\"App\");\n\n onLoggerCrash((props) => {\n if (isMounted) {\n unmount();\n }\n\n // Mount the crash page\n new ViewNode(rootContext, crashView, props).mount(rootElement);\n });\n\n Context.emit(rootContext, LifecycleEvent.WILL_MOUNT);\n\n if (view instanceof Router) {\n // Store router reference so we can unmount it with the app.\n router = view;\n rootView = await router[MOUNT](rootElement, rootContext);\n } else {\n rootView = new ViewNode(rootContext, view, {});\n }\n rootView.mount(rootElement);\n isMounted = true;\n\n Context.emit(rootContext, LifecycleEvent.DID_MOUNT);\n\n async function unmount() {\n if (!isMounted) return;\n\n Context.emit(rootContext, LifecycleEvent.WILL_UNMOUNT);\n\n rootView.unmount(false);\n if (router) {\n await router[UNMOUNT]();\n }\n isMounted = false;\n\n Context.emit(rootContext, LifecycleEvent.DID_UNMOUNT);\n }\n\n return unmount;\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/core/views/for.ts","../src/core/views/show.ts","../src/core/views/default-crash-view.ts","../src/core/mount.ts"],"sourcesContent":["import type { Renderable } from \"../../types\";\nimport type { Context } from \"../context\";\nimport { type Key, RepeatNode } from \"../nodes/repeat\";\nimport { type Signal } from \"../signals\";\n\nexport interface ForProps<T> {\n /**\n * An array of items to render.\n */\n each: Signal<T[]>;\n /**\n * A function to extract a unique key that identifies each item.\n * If no `key` function is passed, object identity (===) will be used.\n */\n key?: (item: T, index: number) => Key;\n /**\n * A render function. Takes the item and its index in signal form and returns something to display for each item.\n */\n children: (item: Signal<T>, index: Signal<number>, ctx: Context) => Renderable;\n}\n\nconst defaultKeyFn = (x: any) => x;\n\n/**\n *\n */\nexport function For<T>(props: ForProps<T>, context: Context) {\n return new RepeatNode(context, props.each, props.key ?? defaultKeyFn, props.children);\n}\n","import type { Renderable } from \"../../types\";\nimport type { Context } from \"../context\";\nimport { DynamicNode } from \"../nodes/dynamic\";\nimport { get, type Signal } from \"../signals\";\n\nexport interface ShowProps {\n /**\n * If present, children will be rendered only when this signal holds a truthy value.\n */\n when?: Signal<any>;\n\n /**\n * If present, children will be rendered only when this signal holds a falsy value.\n */\n unless?: Signal<any>;\n\n /**\n * Content to render if conditions permit.\n */\n children: Renderable;\n\n /**\n * Content to render when conditions don't permit `children` to render.\n */\n fallback?: Renderable;\n}\n\n/**\n * Conditionally display children.\n */\nexport function Show(props: ShowProps, context: Context) {\n return new DynamicNode(context, () => {\n let shouldShow = true;\n\n if (props.when != null && props.unless != null) {\n shouldShow = get(props.when) && !get(props.unless);\n } else if (props.when != null) {\n shouldShow = get(props.when);\n } else if (props.unless != null) {\n shouldShow = !get(props.unless);\n }\n\n if (shouldShow) {\n return props.children;\n } else {\n return props.fallback;\n }\n });\n}\n","import { when, m } from \"../markup.js\";\n\n/**\n * Props passed to the crash view when a crash occurs.\n */\nexport interface CrashViewProps {\n /**\n * JavaScript Error object.\n */\n error: Error;\n\n /**\n * A string to identify the logger that reported this error.\n */\n loggerName: string;\n\n /**\n * Unique identifier to pinpoint the specific view that reported the crash.\n */\n tag?: string;\n\n /**\n * Label for the tag.\n */\n tagName?: string;\n}\n\n/**\n * The crash view displayed unless you specify your own.\n */\nexport function DefaultCrashView(props: CrashViewProps) {\n return m(\"div\", {\n style: {\n backgroundColor: \"#880000\",\n color: \"#fff\",\n padding: \"2rem\",\n position: \"fixed\",\n inset: 0,\n fontSize: \"20px\",\n },\n children: [\n m(\"h1\", { style: { marginBottom: \"0.5rem\" }, children: \"The app has crashed\" }),\n m(\"p\", {\n style: { marginBottom: \"0.25rem\" },\n children: [\n m(\"span\", {\n style: { fontFamily: \"monospace\" },\n children: props.loggerName,\n }),\n when(\n props.tag,\n m(\"span\", {\n style: { fontFamily: \"monospace\", opacity: 0.5 },\n children: ` [${props.tagName ? `${props.tagName}: ` : \"\"}${props.tag}]`,\n }),\n ),\n \" says:\",\n ],\n }),\n m(\"blockquote\", {\n style: {\n backgroundColor: \"#991111\",\n padding: \"0.25em\",\n borderRadius: \"6px\",\n fontFamily: \"monospace\",\n marginBottom: \"1rem\",\n },\n children: [\n m(\"span\", {\n style: {\n display: \"inline-block\",\n backgroundColor: \"red\",\n padding: \"0.1em 0.4em\",\n marginRight: \"0.5em\",\n borderRadius: \"4px\",\n fontSize: \"0.9em\",\n fontWeight: \"bold\",\n },\n children: props.error.name,\n }),\n props.error.message,\n ],\n }),\n m(\"p\", { children: \"Please see the browser console for details.\" }),\n ],\n });\n}\n","import { MOUNT, Router, UNMOUNT } from \"../router/router\";\nimport { assertInstanceOf } from \"../typeChecking\";\nimport type { View } from \"../types\";\nimport { Context, LifecycleEvent } from \"./context\";\nimport { type LoggerCrashProps, onLoggerCrash } from \"./logger\";\nimport { type MarkupNode } from \"./markup\";\nimport { ViewNode } from \"./nodes/view\";\nimport { DefaultCrashView } from \"./views/default-crash-view\";\n\nlet isMounted = false;\n\nexport type UnmountFn = () => Promise<void>;\nexport interface MountOptions {\n crashView?: View<LoggerCrashProps>;\n\n /**\n * An existing Context to use as the root, otherwise a new one will be created.\n * Use this to provide top-level stores and state to the whole app.\n */\n context?: Context;\n}\n\nexport async function mount(view: View<{}>, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\nexport async function mount(router: Router, domNode: Element, options?: MountOptions): Promise<UnmountFn>;\n\nexport async function mount(view: any, rootElement: Element, options?: MountOptions): Promise<UnmountFn> {\n assertInstanceOf(Element, rootElement, \"Expected an element or a selector string. Got type: %t, value: %v\");\n\n if (isMounted) {\n throw new Error(`A Dolla app is already mounted.`);\n }\n\n let rootView: MarkupNode;\n let router: Router | undefined;\n let crashView = options?.crashView ?? DefaultCrashView;\n\n const rootContext = options?.context ?? new Context(\"App\");\n\n onLoggerCrash((props) => {\n if (isMounted) {\n unmount();\n }\n\n // Mount the crash page\n new ViewNode(rootContext, crashView, props).mount(rootElement);\n });\n\n Context.emit(rootContext, LifecycleEvent.WILL_MOUNT);\n\n if (view instanceof Router) {\n // Store router reference so we can unmount it with the app.\n router = view;\n rootView = await router[MOUNT](rootElement, rootContext);\n } else {\n rootView = new ViewNode(rootContext, view, {});\n }\n rootView.mount(rootElement);\n isMounted = true;\n\n Context.emit(rootContext, LifecycleEvent.DID_MOUNT);\n\n async function unmount() {\n if (!isMounted) return;\n\n Context.emit(rootContext, LifecycleEvent.WILL_UNMOUNT);\n\n rootView.unmount(false);\n if (router) {\n await router[UNMOUNT]();\n }\n isMounted = false;\n\n Context.emit(rootContext, LifecycleEvent.DID_UNMOUNT);\n }\n\n return unmount;\n}\n"],"names":["defaultKeyFn","x","For","props","context","RepeatNode","Show","DynamicNode","shouldShow","get","DefaultCrashView","m","when","isMounted","mount","view","rootElement","options","assertInstanceOf","rootView","router","crashView","rootContext","Context","onLoggerCrash","unmount","ViewNode","LifecycleEvent","Router","MOUNT","UNMOUNT"],"mappings":";;;;;;;;;AAqBA,MAAMA,IAAe,CAACC,MAAWA;AAKjB,SAAAC,EAAOC,GAAoBC,GAAkB;AACpD,SAAA,IAAIC,EAAWD,GAASD,EAAM,MAAMA,EAAM,OAAOH,GAAcG,EAAM,QAAQ;AACtF;ACEgB,SAAAG,EAAKH,GAAkBC,GAAkB;AAChD,SAAA,IAAIG,EAAYH,GAAS,MAAM;AACpC,QAAII,IAAa;AAUjB,WARIL,EAAM,QAAQ,QAAQA,EAAM,UAAU,OACxCK,IAAaC,EAAIN,EAAM,IAAI,KAAK,CAACM,EAAIN,EAAM,MAAM,IACxCA,EAAM,QAAQ,OACVK,IAAAC,EAAIN,EAAM,IAAI,IAClBA,EAAM,UAAU,SACZK,IAAA,CAACC,EAAIN,EAAM,MAAM,IAG5BK,IACKL,EAAM,WAENA,EAAM;AAAA,EACf,CACD;AACH;AClBO,SAASO,EAAiBP,GAAuB;AACtD,SAAOQ,EAAE,OAAO;AAAA,IACd,OAAO;AAAA,MACL,iBAAiB;AAAA,MACjB,OAAO;AAAA,MACP,SAAS;AAAA,MACT,UAAU;AAAA,MACV,OAAO;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,IACA,UAAU;AAAA,MACRA,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,SAAS,GAAG,UAAU,uBAAuB;AAAA,MAC9EA,EAAE,KAAK;AAAA,QACL,OAAO,EAAE,cAAc,UAAU;AAAA,QACjC,UAAU;AAA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J,GAAaD,GAAWlB,CAAK,EAAE,MAAMa,CAAW;AAAA,EAAA,CAC9D,GAEOO,EAAA,KAAKD,GAAaK,EAAe,UAAU,GAE/CZ,aAAgBa,KAETR,IAAAL,GACTI,IAAW,MAAMC,EAAOS,CAAK,EAAEb,GAAaM,CAAW,KAEvDH,IAAW,IAAIO,EAASJ,GAAaP,GAAM,CAAA,CAAE,GAE/CI,EAAS,MAAMH,CAAW,GACdH,IAAA,IAEJU,EAAA,KAAKD,GAAaK,EAAe,SAAS;AAElD,iBAAeF,IAAU;AACvB,IAAKZ,MAEGU,EAAA,KAAKD,GAAaK,EAAe,YAAY,GAErDR,EAAS,QAAQ,EAAK,GAClBC,KACI,MAAAA,EAAOU,CAAO,EAAE,GAEZjB,IAAA,IAEJU,EAAA,KAAKD,GAAaK,EAAe,WAAW;AAAA,EAAA;AAG/C,SAAAF;AACT;"}
|
package/dist/jsx-dev-runtime.js
CHANGED
package/dist/jsx-runtime.js
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { b as d } from "./typeChecking-CbltMOUt.js";
|
|
2
|
+
import { g as w, u as i, c as m, l as o, n as b, p as h } from "./signals-DbDmN2gr.js";
|
|
3
|
+
let g = {
|
|
4
|
+
info: "development",
|
|
5
|
+
log: "development",
|
|
6
|
+
warn: "development",
|
|
7
|
+
error: !0
|
|
8
|
+
}, s = o("*,-dolla.*"), f = [], u = !1;
|
|
9
|
+
function $(r) {
|
|
10
|
+
return f.push(r), function() {
|
|
11
|
+
f.splice(f.indexOf(r), 1);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function k(r, e) {
|
|
15
|
+
const c = (e == null ? void 0 : e.console) ?? v(), t = (a) => {
|
|
16
|
+
let n = i(r);
|
|
17
|
+
if (g[a] === !1 || d(g[a]) && g[a] !== m() || !s(n))
|
|
18
|
+
return b;
|
|
19
|
+
{
|
|
20
|
+
let l = `%c${n}`;
|
|
21
|
+
return e != null && e.tag ? e.tagName ? l += ` %c[${e.tagName}: %c${e.tag}%c]` : l += ` %c[%c${e.tag}%c]` : l += "%c%c%c", c[a].bind(
|
|
22
|
+
c,
|
|
23
|
+
l,
|
|
24
|
+
`color:${h(l)};font-weight:bold`,
|
|
25
|
+
"color:#777",
|
|
26
|
+
"color:#aaa",
|
|
27
|
+
"color:#777"
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
get info() {
|
|
33
|
+
return t("info");
|
|
34
|
+
},
|
|
35
|
+
get log() {
|
|
36
|
+
return t("log");
|
|
37
|
+
},
|
|
38
|
+
get warn() {
|
|
39
|
+
return t("warn");
|
|
40
|
+
},
|
|
41
|
+
get error() {
|
|
42
|
+
return t("error");
|
|
43
|
+
},
|
|
44
|
+
crash(a) {
|
|
45
|
+
if (!u) {
|
|
46
|
+
u = !0;
|
|
47
|
+
const n = {
|
|
48
|
+
error: a,
|
|
49
|
+
loggerName: w(r),
|
|
50
|
+
tag: e == null ? void 0 : e.tag,
|
|
51
|
+
tagName: e == null ? void 0 : e.tagName
|
|
52
|
+
};
|
|
53
|
+
for (const l of f)
|
|
54
|
+
l(n);
|
|
55
|
+
throw a;
|
|
56
|
+
}
|
|
57
|
+
return a;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function x(r) {
|
|
62
|
+
s = o(r);
|
|
63
|
+
}
|
|
64
|
+
function y(r) {
|
|
65
|
+
for (const e in r) {
|
|
66
|
+
const c = r[e];
|
|
67
|
+
c && (g[e] = c);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function v() {
|
|
71
|
+
if (typeof window < "u" && window.console)
|
|
72
|
+
return window.console;
|
|
73
|
+
if (typeof global < "u" && global.console)
|
|
74
|
+
return global.console;
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
y as a,
|
|
78
|
+
k as c,
|
|
79
|
+
$ as o,
|
|
80
|
+
x as s
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=logger-B7RBYtzP.js.map
|