@manyducks.co/dolla 2.0.0-alpha.54 → 2.0.0-alpha.55
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 +1 -12
- package/dist/core/context.d.ts +80 -54
- package/dist/core/index.d.ts +8 -8
- package/dist/core/logger.d.ts +1 -1
- package/dist/core/markup.d.ts +10 -10
- package/dist/core/mount.d.ts +11 -6
- package/dist/core/nodes/dynamic.d.ts +3 -3
- package/dist/core/nodes/html.d.ts +5 -5
- package/dist/core/nodes/outlet.d.ts +3 -4
- package/dist/core/nodes/portal.d.ts +2 -2
- package/dist/core/nodes/repeat.d.ts +6 -6
- package/dist/core/nodes/view.d.ts +13 -81
- package/dist/core/symbols.d.ts +0 -2
- package/dist/core/views/fragment.d.ts +2 -2
- package/dist/fragment-VXM-P2tT.js +7 -0
- package/dist/fragment-VXM-P2tT.js.map +1 -0
- package/dist/http.js +1 -1
- package/dist/i18n.js +14 -14
- package/dist/i18n.js.map +1 -1
- package/dist/index.js +45 -59
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +8 -8
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.js +9 -9
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/{logger-CBfhf3fA.js → logger-CXdzxt1e.js} +74 -73
- package/dist/{logger-CBfhf3fA.js.map → logger-CXdzxt1e.js.map} +1 -1
- package/dist/markup-yTuFdC0t.js +923 -0
- package/dist/markup-yTuFdC0t.js.map +1 -0
- package/dist/router/router.d.ts +9 -6
- package/dist/router-B-rtBG7i.js +488 -0
- package/dist/router-B-rtBG7i.js.map +1 -0
- package/dist/router.js +1 -1
- package/dist/router.js.map +1 -1
- package/dist/{typeChecking-EAVNeFyB.js → typeChecking-lgllKIVq.js} +5 -5
- package/dist/{typeChecking-EAVNeFyB.js.map → typeChecking-lgllKIVq.js.map} +1 -1
- package/dist/types.d.ts +1 -1
- package/docs/mixins.md +1 -1
- package/docs/ref.md +93 -0
- package/notes/scratch.md +24 -0
- package/package.json +2 -2
- package/dist/core/mixin.d.ts +0 -62
- package/dist/core/store.d.ts +0 -57
- package/dist/core/views/passthrough.d.ts +0 -5
- package/dist/fragment-CmWsN-4Y.js +0 -8
- package/dist/fragment-CmWsN-4Y.js.map +0 -1
- package/dist/router-BoJac1lD.js +0 -482
- package/dist/router-BoJac1lD.js.map +0 -1
- package/dist/view-BKpHFpWG.js +0 -1044
- package/dist/view-BKpHFpWG.js.map +0 -1
package/dist/i18n.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var B = Object.defineProperty;
|
|
2
|
-
var
|
|
2
|
+
var D = (o) => {
|
|
3
3
|
throw TypeError(o);
|
|
4
4
|
};
|
|
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
|
-
var O = (o, t, e) => J(o, typeof t != "symbol" ? t + "" : t, e), _ = (o, t, e) => t.has(o) ||
|
|
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) ?
|
|
8
|
-
import { $, f as K, d as Q, g as x } from "./logger-
|
|
9
|
-
import {
|
|
6
|
+
var O = (o, t, e) => J(o, typeof t != "symbol" ? t + "" : t, e), _ = (o, t, e) => t.has(o) || D("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) ? 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 { $, f as K, d as Q, g as x } from "./logger-CXdzxt1e.js";
|
|
9
|
+
import { b as C, i as j, c as U, t as P } from "./typeChecking-lgllKIVq.js";
|
|
10
10
|
var I, F, p, S, G;
|
|
11
11
|
class W {
|
|
12
12
|
constructor(t) {
|
|
@@ -119,7 +119,7 @@ I = new WeakMap(), F = new WeakMap(), p = new WeakSet(), S = function(t, e = [])
|
|
|
119
119
|
}
|
|
120
120
|
return r === 0 && a.length > 0 && n.segments.push({ type: 0, text: a }), n;
|
|
121
121
|
};
|
|
122
|
-
var b, h, E, T, v, d, u, H, L, V,
|
|
122
|
+
var b, h, E, T, v, d, u, H, L, V, M, A;
|
|
123
123
|
class X {
|
|
124
124
|
constructor() {
|
|
125
125
|
m(this, u);
|
|
@@ -130,7 +130,7 @@ class X {
|
|
|
130
130
|
m(this, v, "auto");
|
|
131
131
|
m(this, d, $("en"));
|
|
132
132
|
O(this, "$locale", $(i(this, d)));
|
|
133
|
-
N(this, b, K("
|
|
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, M).call(this, e, n));
|
|
134
134
|
}
|
|
135
135
|
get locales() {
|
|
136
136
|
return [...i(this, h).keys()];
|
|
@@ -250,7 +250,7 @@ class X {
|
|
|
250
250
|
* const $formatted = Dolla.i18n.list(list, { });
|
|
251
251
|
*/
|
|
252
252
|
list(t, e) {
|
|
253
|
-
return $(() => g(this, u,
|
|
253
|
+
return $(() => g(this, u, M).call(this, x(t), e));
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
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) {
|
|
@@ -276,14 +276,14 @@ b = new WeakMap(), h = new WeakMap(), E = new WeakMap(), T = new WeakMap(), v =
|
|
|
276
276
|
const y = ((w = n.formatOverrides) == null ? void 0 : w[l.name]) ?? [...l.formats];
|
|
277
277
|
l.name === "count" && y.length === 0 && y.push({ name: "number", options: {} });
|
|
278
278
|
for (const f of y) {
|
|
279
|
-
const
|
|
280
|
-
if (
|
|
281
|
-
const
|
|
279
|
+
const R = i(this, T).get(f.name);
|
|
280
|
+
if (R == null) {
|
|
281
|
+
const z = new Error(
|
|
282
282
|
`Failed to load format '${f.name}' when processing '${e}', template: ${r}`
|
|
283
283
|
);
|
|
284
|
-
throw i(this, b).crash(
|
|
284
|
+
throw i(this, b).crash(z), z;
|
|
285
285
|
}
|
|
286
|
-
k =
|
|
286
|
+
k = R(t, k, f.options);
|
|
287
287
|
}
|
|
288
288
|
c += k;
|
|
289
289
|
}
|
|
@@ -292,7 +292,7 @@ b = new WeakMap(), h = new WeakMap(), E = new WeakMap(), T = new WeakMap(), v =
|
|
|
292
292
|
return new Intl.NumberFormat(i(this, d).call(this), e).format(t);
|
|
293
293
|
}, V = function(t, e) {
|
|
294
294
|
return new Intl.DateTimeFormat(i(this, d).call(this), e).format(C(t) ? new Date(t) : t);
|
|
295
|
-
},
|
|
295
|
+
}, M = function(t, e) {
|
|
296
296
|
return new Intl.ListFormat(i(this, d).call(this), e).format(t);
|
|
297
297
|
}, // relativeTime(): State<string> {
|
|
298
298
|
// }
|
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(): 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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P,GAAQpB,GAAOf,EAAO,OAAO;AAAA,MAAA;AAGhC,MAAAuC,KAAAxB;AAAA,IAAA;AAIP,SAAAwB;AAAA,GAwCTtB,IAAA,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;AAAA;AAOjEG,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 { $, 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","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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;"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { o as
|
|
2
|
-
import { $ as L, f as
|
|
3
|
-
import { m as
|
|
4
|
-
import {
|
|
5
|
-
import { R as
|
|
6
|
-
import {
|
|
1
|
+
import { o as g } from "./logger-CXdzxt1e.js";
|
|
2
|
+
import { $ as L, f as T, d as _, e as q, g as B, b as V, p as $, c as v, h as O, i as P, s as S, a as z } from "./logger-CXdzxt1e.js";
|
|
3
|
+
import { m as t, w as d, C as y, r as m } from "./markup-yTuFdC0t.js";
|
|
4
|
+
import { c as D, p as Y, a as G, u as I } from "./markup-yTuFdC0t.js";
|
|
5
|
+
import { R as h, M as w, U as p } from "./router-B-rtBG7i.js";
|
|
6
|
+
import { a as b } from "./typeChecking-lgllKIVq.js";
|
|
7
7
|
const f = Symbol("Ref.EMPTY");
|
|
8
|
-
function
|
|
8
|
+
function k(e = f) {
|
|
9
9
|
return function() {
|
|
10
10
|
if (arguments.length === 0) {
|
|
11
11
|
if (e === f)
|
|
@@ -17,8 +17,8 @@ function N(e = f) {
|
|
|
17
17
|
return e;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
return
|
|
20
|
+
function x(e) {
|
|
21
|
+
return t(
|
|
22
22
|
"div",
|
|
23
23
|
{
|
|
24
24
|
style: {
|
|
@@ -30,14 +30,14 @@ function R(e) {
|
|
|
30
30
|
fontSize: "20px"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
t("h1", { style: { marginBottom: "0.5rem" } }, "The app has crashed"),
|
|
34
|
+
t(
|
|
35
35
|
"p",
|
|
36
36
|
{ style: { marginBottom: "0.25rem" } },
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
t("span", { style: { fontFamily: "monospace" } }, e.loggerName),
|
|
38
|
+
d(
|
|
39
39
|
e.tag,
|
|
40
|
-
|
|
40
|
+
t(
|
|
41
41
|
"span",
|
|
42
42
|
{ style: { fontFamily: "monospace", opacity: 0.5 } },
|
|
43
43
|
` [${e.tagName ? `${e.tagName}: ` : ""}${e.tag}]`
|
|
@@ -45,7 +45,7 @@ function R(e) {
|
|
|
45
45
|
),
|
|
46
46
|
" says:"
|
|
47
47
|
),
|
|
48
|
-
|
|
48
|
+
t(
|
|
49
49
|
"blockquote",
|
|
50
50
|
{
|
|
51
51
|
style: {
|
|
@@ -56,7 +56,7 @@ function R(e) {
|
|
|
56
56
|
marginBottom: "1rem"
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
|
-
|
|
59
|
+
t(
|
|
60
60
|
"span",
|
|
61
61
|
{
|
|
62
62
|
style: {
|
|
@@ -73,58 +73,44 @@ function R(e) {
|
|
|
73
73
|
),
|
|
74
74
|
e.error.message
|
|
75
75
|
),
|
|
76
|
-
|
|
76
|
+
t("p", {}, "Please see the browser console for details.")
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
|
-
let
|
|
80
|
-
async function
|
|
81
|
-
if (
|
|
79
|
+
let o = !1;
|
|
80
|
+
async function N(e, n, r) {
|
|
81
|
+
if (b(Element, n, "Expected an element or a selector string. Got type: %t, value: %v"), o)
|
|
82
82
|
throw new Error("A Dolla app is already mounted.");
|
|
83
|
-
let
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
u(Element, e, "Expected an element or a selector string. Got type: %t, value: %v"), o = e;
|
|
89
|
-
if (n instanceof y)
|
|
90
|
-
r = n, l = n[E];
|
|
91
|
-
else {
|
|
92
|
-
const t = a(n);
|
|
93
|
-
l = c(t.type, t.props);
|
|
94
|
-
}
|
|
95
|
-
d((t) => {
|
|
96
|
-
s && (i(), c(g, t).mount(o));
|
|
97
|
-
});
|
|
98
|
-
for (const t of p.stores.values())
|
|
99
|
-
t.handleMount();
|
|
100
|
-
r && await r[w](o), l.mount(o), s = !0;
|
|
83
|
+
let s, l, c = (r == null ? void 0 : r.crashView) ?? x;
|
|
84
|
+
const a = (r == null ? void 0 : r.context) ?? new y("App");
|
|
85
|
+
g((u) => {
|
|
86
|
+
o && i(), m(t(c, u), a).mount(n);
|
|
87
|
+
}), a._lifecycle.willMount(), e instanceof h ? (l = e, s = await l[w](n, a)) : s = m(t(e), a), s.mount(n), o = !0, a._lifecycle.didMount();
|
|
101
88
|
async function i() {
|
|
102
|
-
|
|
89
|
+
o && (a._lifecycle.willUnmount(), s.unmount(!1), l && await l[p](), o = !1, a._lifecycle.didUnmount());
|
|
103
90
|
}
|
|
104
91
|
return i;
|
|
105
92
|
}
|
|
106
93
|
export {
|
|
107
94
|
L as $,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
P as deepEqual,
|
|
113
|
-
$ as effect,
|
|
95
|
+
D as createContext,
|
|
96
|
+
T as createLogger,
|
|
97
|
+
_ as deepEqual,
|
|
98
|
+
q as effect,
|
|
114
99
|
B as get,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
100
|
+
V as getEnv,
|
|
101
|
+
t as m,
|
|
102
|
+
N as mount,
|
|
103
|
+
$ as peek,
|
|
104
|
+
Y as portal,
|
|
105
|
+
k as ref,
|
|
106
|
+
m as render,
|
|
107
|
+
G as repeat,
|
|
108
|
+
v as setEnv,
|
|
109
|
+
O as setLogFilter,
|
|
110
|
+
P as setLogLevels,
|
|
111
|
+
S as shallowEqual,
|
|
112
|
+
z as strictEqual,
|
|
113
|
+
I as unless,
|
|
114
|
+
d as when
|
|
129
115
|
};
|
|
130
116
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/core/ref.ts","../src/core/views/default-crash-view.ts","../src/core/mount.ts"],"sourcesContent":["const EMPTY_REF = Symbol(\"Ref.EMPTY\");\n\n/**\n * A hybrid getter/setter function that stores the last value it was called with.\n * Guarantees a value is held at runtime by throwing an error if no value is set.\n */\nexport interface Ref<T> {\n /**\n * Returns the currently stored value of the ref, or throws an error if no value has been set.\n */\n (): T;\n\n /**\n * Stores a new value to the ref and returns that value.\n */\n (value: T): T;\n}\n\n/**\n * Creates a ref with no initial value.\n */\nexport function ref<T>(): Ref<T>;\n\n/**\n * Creates a ref with an initial value.\n */\nexport function ref<T>(value: T): Ref<T>;\n\nexport function ref(value = EMPTY_REF) {\n return function () {\n if (arguments.length === 0) {\n if (value === EMPTY_REF) {\n throw new Error(`Ref getter was called, but ref has no value! Be sure to set your refs before accessing them.`);\n }\n } else if (arguments.length === 1) {\n value = arguments[0];\n } else {\n throw new Error(`Ref called with too many arguments. Expected 0 or 1 arguments.`);\n }\n\n return value;\n };\n}\n","import { when,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/core/ref.ts","../src/core/views/default-crash-view.ts","../src/core/mount.ts"],"sourcesContent":["const EMPTY_REF = Symbol(\"Ref.EMPTY\");\n\n/**\n * A hybrid getter/setter function that stores the last value it was called with.\n * Guarantees a value is held at runtime by throwing an error if no value is set.\n */\nexport interface Ref<T> {\n /**\n * Returns the currently stored value of the ref, or throws an error if no value has been set.\n */\n (): T;\n\n /**\n * Stores a new value to the ref and returns that value.\n */\n (value: T): T;\n}\n\n/**\n * Creates a ref with no initial value.\n */\nexport function ref<T>(): Ref<T>;\n\n/**\n * Creates a ref with an initial value.\n */\nexport function ref<T>(value: T): Ref<T>;\n\nexport function ref(value = EMPTY_REF) {\n return function () {\n if (arguments.length === 0) {\n if (value === EMPTY_REF) {\n throw new Error(`Ref getter was called, but ref has no value! Be sure to set your refs before accessing them.`);\n }\n } else if (arguments.length === 1) {\n value = arguments[0];\n } else {\n throw new Error(`Ref called with too many arguments. Expected 0 or 1 arguments.`);\n }\n\n return value;\n };\n}\n","import { when, m } from \"../markup.js\";\n\n/**\n * Props passed to the crash view when a crash occurs.\n */\nexport type 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\nexport function DefaultCrashView(props: CrashViewProps) {\n return m(\n \"div\",\n {\n style: {\n backgroundColor: \"#880000\",\n color: \"#fff\",\n padding: \"2rem\",\n position: \"fixed\",\n inset: 0,\n fontSize: \"20px\",\n },\n },\n m(\"h1\", { style: { marginBottom: \"0.5rem\" } }, \"The app has crashed\"),\n m(\n \"p\",\n { style: { marginBottom: \"0.25rem\" } },\n m(\"span\", { style: { fontFamily: \"monospace\" } }, props.loggerName),\n when(\n props.tag,\n m(\n \"span\",\n { style: { fontFamily: \"monospace\", opacity: 0.5 } },\n ` [${props.tagName ? `${props.tagName}: ` : \"\"}${props.tag}]`,\n ),\n ),\n \" says:\",\n ),\n m(\n \"blockquote\",\n {\n style: {\n backgroundColor: \"#991111\",\n padding: \"0.25em\",\n borderRadius: \"6px\",\n fontFamily: \"monospace\",\n marginBottom: \"1rem\",\n },\n },\n m(\n \"span\",\n {\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 },\n props.error.name,\n ),\n props.error.message,\n ),\n m(\"p\", {}, \"Please see the browser console for details.\"),\n );\n}\n","import { MOUNT, ROOT_VIEW, Router, UNMOUNT } from \"../router/router\";\nimport { assertInstanceOf } from \"../typeChecking\";\nimport { Context } from \"./context\";\nimport { type LoggerErrorContext, onLoggerCrash } from \"./logger\";\nimport { m, type MarkupElement, render } from \"./markup\";\nimport { type View } 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<LoggerErrorContext>;\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: MarkupElement;\n let router: Router | undefined;\n let crashView = options?.crashView ?? DefaultCrashView;\n\n const rootContext = options?.context ?? new Context(\"App\");\n\n onLoggerCrash((ctx) => {\n if (isMounted) {\n unmount();\n }\n\n // Mount the crash page\n render(m(crashView, ctx), rootContext).mount(rootElement);\n });\n\n rootContext._lifecycle.willMount();\n\n if (view instanceof Router) {\n router = view;\n rootView = await router[MOUNT](rootElement, rootContext);\n } else {\n // First, initialize the root view. The router store needs this to connect the initial route.\n rootView = render(m(view), rootContext);\n }\n\n rootView.mount(rootElement);\n isMounted = true;\n\n rootContext._lifecycle.didMount();\n\n async function unmount() {\n if (!isMounted) return;\n\n rootContext._lifecycle.willUnmount();\n\n rootView.unmount(false);\n\n if (router) {\n await router[UNMOUNT]();\n }\n\n isMounted = false;\n\n rootContext._lifecycle.didUnmount();\n }\n\n return unmount;\n}\n"],"names":["EMPTY_REF","ref","value","DefaultCrashView","props","m","when","isMounted","mount","view","rootElement","options","assertInstanceOf","rootView","router","crashView","rootContext","Context","onLoggerCrash","ctx","unmount","render","Router","MOUNT","UNMOUNT"],"mappings":";;;;;;AAAA,MAAMA,IAAY,OAAO,WAAW;AA4BpB,SAAAC,EAAIC,IAAQF,GAAW;AACrC,SAAO,WAAY;AACb,QAAA,UAAU,WAAW;AACvB,UAAIE,MAAUF;AACN,cAAA,IAAI,MAAM,8FAA8F;AAAA,eAEvG,UAAU,WAAW;AAC9B,MAAAE,IAAQ,UAAU,CAAC;AAAA;AAEb,YAAA,IAAI,MAAM,gEAAgE;AAG3E,WAAAA;AAAA,EACT;AACF;ACfO,SAASC,EAAiBC,GAAuB;AAC/C,SAAAC;AAAA,IACL;AAAA,IACA;AAAA,MACE,OAAO;AAAA,QACL,iBAAiB;AAAA,QACjB,OAAO;AAAA,QACP,SAAS;AAAA,QACT,UAAU;AAAA,QACV,OAAO;AAAA,QACP,UAAU;AAAA,MAAA;AAAA,IAEd;AAAA,IACAA,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,SAAA,EAAW,GAAG,qBAAqB;AAAA,IACpEA;AAAA,MACE;AAAA,MACA,EAAE,OAAO,EAAE,cAAc,YAAY;AAAA,MACrCA,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,YAAY,EAAA,GAAKD,EAAM,UAAU;AAAA,MAClEE;AAAA,QACEF,EAAM;AAAA,QACNC;AAAA,UACE;AAAA,UACA,EAAE,OAAO,EAAE,YAAY,aAAa,SAAS,MAAM;AAAA,UACnD,KAAKD,EAAM,UAAU,GAAGA,EAAM,OAAO,OAAO,EAAE,GAAGA,EAAM,GAAG;AAAA,QAAA;AAAA,MAE9D;AAAA,MACA;AAAA,IACF;AAAA,IACAC;AAAA,MACE;AAAA,MACA;AAAA,QACE,OAAO;AAAA,UACL,iBAAiB;AAAA,UACjB,SAAS;AAAA,UACT,cAAc;AAAA,UACd,YAAY;AAAA,UACZ,cA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HANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { m as
|
|
2
|
-
import { F as
|
|
3
|
-
function
|
|
4
|
-
const i = { ...
|
|
5
|
-
return
|
|
1
|
+
import { m as o } from "./markup-yTuFdC0t.js";
|
|
2
|
+
import { F as m } from "./fragment-VXM-P2tT.js";
|
|
3
|
+
function f(e, r, t, n, l, u) {
|
|
4
|
+
const i = { ...s(["children", "key"], r) }, c = Array.isArray(r.children) ? r.children : [r.children];
|
|
5
|
+
return o(e, i, ...c);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function s(e, r) {
|
|
8
8
|
const t = {};
|
|
9
9
|
for (const n in r)
|
|
10
10
|
e.includes(n) || (t[n] = r[n]);
|
|
11
11
|
return t;
|
|
12
12
|
}
|
|
13
13
|
export {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
m as Fragment,
|
|
15
|
+
f as jsxDEV
|
|
16
16
|
};
|
|
17
17
|
//# sourceMappingURL=jsx-dev-runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-dev-runtime.js","sources":["../src/jsx-dev-runtime.js"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"jsx-dev-runtime.js","sources":["../src/jsx-dev-runtime.js"],"sourcesContent":["import { m } from \"./core/markup\";\nexport { Fragment } from \"./core/views/fragment\";\n\nexport function jsxDEV(element, props, key, isStaticChildren, source, self) {\n const attributes = { ...omit([\"children\", \"key\"], props) };\n const children = Array.isArray(props.children) ? props.children : [props.children];\n\n // return new _Markup(element, attributes, children);\n return m(element, attributes, ...children);\n}\n\nfunction omit(keys, object) {\n const result = {};\n for (const key in object) {\n if (!keys.includes(key)) {\n result[key] = object[key];\n }\n }\n return result;\n}\n"],"names":["jsxDEV","element","props","key","isStaticChildren","source","self","attributes","omit","children","m","keys","object","result"],"mappings":";;AAGO,SAASA,EAAOC,GAASC,GAAOC,GAAKC,GAAkBC,GAAQC,GAAM;AAC1E,QAAMC,IAAa,EAAE,GAAGC,EAAK,CAAC,YAAY,KAAK,GAAGN,CAAK,EAAG,GACpDO,IAAW,MAAM,QAAQP,EAAM,QAAQ,IAAIA,EAAM,WAAW,CAACA,EAAM,QAAQ;AAGjF,SAAOQ,EAAET,GAASM,GAAY,GAAGE,CAAQ;AAC3C;AAEA,SAASD,EAAKG,GAAMC,GAAQ;AAC1B,QAAMC,IAAS,CAAE;AACjB,aAAWV,KAAOS;AAChB,IAAKD,EAAK,SAASR,CAAG,MACpBU,EAAOV,CAAG,IAAIS,EAAOT,CAAG;AAG5B,SAAOU;AACT;"}
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { m as t } from "./
|
|
2
|
-
import { F as
|
|
3
|
-
function d(e, n,
|
|
1
|
+
import { m as t } from "./markup-yTuFdC0t.js";
|
|
2
|
+
import { F as m } from "./fragment-VXM-P2tT.js";
|
|
3
|
+
function d(e, n, i) {
|
|
4
4
|
return t(e, n ? { ...u(["children", "key"], n) } : void 0, n.children);
|
|
5
5
|
}
|
|
6
|
-
function f(e, n,
|
|
6
|
+
function f(e, n, i) {
|
|
7
7
|
return t(e, n ? { ...u(["children", "key"], n) } : void 0, n.children);
|
|
8
8
|
}
|
|
9
9
|
function u(e, n) {
|
|
10
|
-
const
|
|
11
|
-
for (const
|
|
12
|
-
e.includes(
|
|
13
|
-
return
|
|
10
|
+
const i = {};
|
|
11
|
+
for (const r in n)
|
|
12
|
+
e.includes(r) || (i[r] = n[r]);
|
|
13
|
+
return i;
|
|
14
14
|
}
|
|
15
15
|
export {
|
|
16
|
-
|
|
16
|
+
m as Fragment,
|
|
17
17
|
d as jsx,
|
|
18
18
|
f as jsxs
|
|
19
19
|
};
|
package/dist/jsx-runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-runtime.js","sources":["../src/jsx-runtime.js"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"jsx-runtime.js","sources":["../src/jsx-runtime.js"],"sourcesContent":["import { m } from \"./core/markup\";\nexport { Fragment } from \"./core/views/fragment\";\n\n/**\n * JSX function for elements with dynamic children.\n */\nexport function jsx(element, props, key) {\n return m(element, props ? { ...omit([\"children\", \"key\"], props) } : undefined, ...[props.children]);\n}\n\n/**\n * JSX function for elements with static children.\n */\nexport function jsxs(element, props, key) {\n return m(element, props ? { ...omit([\"children\", \"key\"], props) } : undefined, props.children);\n}\n\nfunction omit(keys, object) {\n const result = {};\n for (const key in object) {\n if (!keys.includes(key)) {\n result[key] = object[key];\n }\n }\n return result;\n}\n"],"names":["jsx","element","props","key","m","omit","jsxs","keys","object","result"],"mappings":";;AAMO,SAASA,EAAIC,GAASC,GAAOC,GAAK;AACvC,SAAOC,EAAEH,GAASC,IAAQ,EAAE,GAAGG,EAAK,CAAC,YAAY,KAAK,GAAGH,CAAK,EAAC,IAAK,QAAeA,EAAM,QAAS;AACpG;AAKO,SAASI,EAAKL,GAASC,GAAOC,GAAK;AACxC,SAAOC,EAAEH,GAASC,IAAQ,EAAE,GAAGG,EAAK,CAAC,YAAY,KAAK,GAAGH,CAAK,EAAC,IAAK,QAAWA,EAAM,QAAQ;AAC/F;AAEA,SAASG,EAAKE,GAAMC,GAAQ;AAC1B,QAAMC,IAAS,CAAE;AACjB,aAAWN,KAAOK;AAChB,IAAKD,EAAK,SAASJ,CAAG,MACpBM,EAAON,CAAG,IAAIK,EAAOL,CAAG;AAG5B,SAAOM;AACT;"}
|