verbaly 0.14.5 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -7
- package/dist/index.cjs +35 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +35 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
Most i18n tools make you maintain key files by hand — keys drift from the code, no type-safety, heavy setup. **Verbaly inverts the flow:** write the source text in your code, a build plugin extracts stable keys, types and per-locale modules. Compiler-grade safety, a runtime under **~3KB**, zero dependencies.
|
|
20
20
|
|
|
21
|
-
```
|
|
21
|
+
```ts
|
|
22
22
|
// You write this:
|
|
23
23
|
t`Hello ${name}, you have ${count} messages`;
|
|
24
24
|
|
|
@@ -33,18 +33,18 @@ Missing a translation? **The build fails** — raw keys never reach production.
|
|
|
33
33
|
|
|
34
34
|
## 🚀 Try it in 30 seconds
|
|
35
35
|
|
|
36
|
-
```
|
|
36
|
+
```bash
|
|
37
37
|
pnpm add verbaly @verbaly/vite
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
```
|
|
40
|
+
```ts
|
|
41
41
|
// vite.config.ts
|
|
42
42
|
import verbaly from '@verbaly/vite';
|
|
43
43
|
|
|
44
44
|
export default { plugins: [verbaly({ locales: ['en', 'es', 'pt'] })] };
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
```
|
|
47
|
+
```ts
|
|
48
48
|
// anywhere in your app — extracted + typed on save
|
|
49
49
|
import { t, setLocale } from 'virtual:verbaly';
|
|
50
50
|
|
|
@@ -56,7 +56,7 @@ await setLocale('es'); // per-locale bundle loaded on demand
|
|
|
56
56
|
|
|
57
57
|
`verbaly` also works on its own for dynamic/CMS content:
|
|
58
58
|
|
|
59
|
-
```
|
|
59
|
+
```ts
|
|
60
60
|
import { createVerbaly } from 'verbaly';
|
|
61
61
|
|
|
62
62
|
const v = createVerbaly({
|
|
@@ -71,7 +71,7 @@ v.setLocale('es'); // auto-loads the catalog; or: await v.loadLocale('es') first
|
|
|
71
71
|
|
|
72
72
|
### 🌐 Plain HTML — no framework needed
|
|
73
73
|
|
|
74
|
-
```
|
|
74
|
+
```html
|
|
75
75
|
<h1 data-verbaly="home.title"></h1>
|
|
76
76
|
<p data-verbaly="home.intro" data-verbaly-rich></p>
|
|
77
77
|
<!-- rich: 'The build <em>gate</em>' renders a real <em> — whitelist, XSS-safe -->
|
|
@@ -83,7 +83,7 @@ v.setLocale('es'); // auto-loads the catalog; or: await v.loadLocale('es') first
|
|
|
83
83
|
<!-- links: 'See the <repo>repo</repo>' renders <a href> — hrefs from you, never from messages -->
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
```
|
|
86
|
+
```ts
|
|
87
87
|
import { bindDom, createVerbaly, persistLocale, resolveLocale } from 'verbaly';
|
|
88
88
|
|
|
89
89
|
const v = createVerbaly({
|
|
@@ -98,6 +98,14 @@ v.setLocale('es');
|
|
|
98
98
|
persistLocale('es'); // localStorage + <html lang>
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
```ts
|
|
102
|
+
// server-side (SSR): one instance per request, locale from the request itself
|
|
103
|
+
import { createVerbaly, negotiateLocale } from 'verbaly';
|
|
104
|
+
|
|
105
|
+
const locale = negotiateLocale(request.headers.get('accept-language'), ['en', 'es', 'pt']);
|
|
106
|
+
const v = createVerbaly({ locale, fallback: 'en', messages });
|
|
107
|
+
```
|
|
108
|
+
|
|
101
109
|
## ✨ What you get
|
|
102
110
|
|
|
103
111
|
- **Hybrid compiler + runtime** — static text compiled (types + tree-shaking), dynamic content via a real runtime path.
|
package/dist/index.cjs
CHANGED
|
@@ -818,6 +818,40 @@ function matchSupported(lang, supported) {
|
|
|
818
818
|
const base = lang.split("-")[0];
|
|
819
819
|
return supported.includes(base) ? base : void 0;
|
|
820
820
|
}
|
|
821
|
+
function negotiateLocale(header, supported, fallback = supported[0] ?? "en") {
|
|
822
|
+
if (!header) return fallback;
|
|
823
|
+
const ranges = [];
|
|
824
|
+
for (const part of header.split(",")) {
|
|
825
|
+
const [rawTag, ...params] = part.trim().split(";");
|
|
826
|
+
const tag = rawTag?.trim();
|
|
827
|
+
if (!tag || tag === "*") continue;
|
|
828
|
+
let q = 1;
|
|
829
|
+
for (const param of params) {
|
|
830
|
+
const [name, value] = param.split("=");
|
|
831
|
+
if (name?.trim().toLowerCase() === "q") {
|
|
832
|
+
const parsed = Number(value?.trim());
|
|
833
|
+
q = Number.isFinite(parsed) ? parsed : 1;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
if (q > 0) ranges.push({
|
|
837
|
+
tag,
|
|
838
|
+
q
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
ranges.sort((a, b) => b.q - a.q);
|
|
842
|
+
for (const { tag } of ranges) {
|
|
843
|
+
const match = matchSupportedLoose(tag, supported);
|
|
844
|
+
if (match) return match;
|
|
845
|
+
}
|
|
846
|
+
return fallback;
|
|
847
|
+
}
|
|
848
|
+
function matchSupportedLoose(lang, supported) {
|
|
849
|
+
const lower = lang.toLowerCase();
|
|
850
|
+
const exact = supported.find((s) => s.toLowerCase() === lower);
|
|
851
|
+
if (exact) return exact;
|
|
852
|
+
const base = lower.split("-")[0];
|
|
853
|
+
return supported.find((s) => s.toLowerCase() === base);
|
|
854
|
+
}
|
|
821
855
|
function persistLocale(locale, storageKey = DEFAULT_KEY) {
|
|
822
856
|
if (storageKey) getStorage()?.setItem(storageKey, locale);
|
|
823
857
|
if (typeof document !== "undefined") document.documentElement.lang = locale;
|
|
@@ -838,6 +872,7 @@ exports.RICH_TAGS = RICH_TAGS;
|
|
|
838
872
|
exports.bindDom = bindDom;
|
|
839
873
|
exports.createVerbaly = createVerbaly;
|
|
840
874
|
exports.flatten = flatten;
|
|
875
|
+
exports.negotiateLocale = negotiateLocale;
|
|
841
876
|
exports.parse = parse;
|
|
842
877
|
exports.parseTags = parseTags;
|
|
843
878
|
exports.persistLocale = persistLocale;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/flatten.ts","../src/intl.ts","../src/format.ts","../src/icu.ts","../src/parse.ts","../src/instance.ts","../src/tags.ts","../src/dom.ts","../src/locale.ts"],"sourcesContent":["import type { MessageTree } from './types';\n\nexport function flatten(\n tree: MessageTree,\n prefix = '',\n out: Record<string, string> = {},\n): Record<string, string> {\n for (const [key, value] of Object.entries(tree)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'string') out[path] = value;\n else flatten(value, path, out);\n }\n return out;\n}\n","const CACHE_CAP = 200; // dynamic locales/options can't grow unbounded\n\nconst nfCache = new Map<string, Intl.NumberFormat>();\nconst dtfCache = new Map<string, Intl.DateTimeFormat>();\nconst prCache = new Map<string, Intl.PluralRules>();\nconst rtfCache = new Map<string, Intl.RelativeTimeFormat>();\nconst lfCache = new Map<string, Intl.ListFormat>();\n\nfunction cached<T>(cache: Map<string, T>, key: string, make: () => T): T {\n let hit = cache.get(key);\n if (!hit) {\n if (cache.size >= CACHE_CAP) cache.delete(cache.keys().next().value as string);\n hit = make();\n cache.set(key, hit);\n }\n return hit;\n}\n\nexport function numberFormat(\n locale: string,\n options?: Intl.NumberFormatOptions,\n): Intl.NumberFormat {\n const key = locale + (options ? JSON.stringify(options) : '');\n return cached(nfCache, key, () => new Intl.NumberFormat(locale, options));\n}\n\nexport function dateTimeFormat(\n locale: string,\n options?: Intl.DateTimeFormatOptions,\n): Intl.DateTimeFormat {\n const key = locale + (options ? JSON.stringify(options) : '');\n return cached(dtfCache, key, () => new Intl.DateTimeFormat(locale, options));\n}\n\nexport function pluralRules(\n locale: string,\n type: Intl.PluralRuleType = 'cardinal',\n): Intl.PluralRules {\n return cached(prCache, locale + type, () => new Intl.PluralRules(locale, { type }));\n}\n\nexport function relativeTimeFormat(locale: string): Intl.RelativeTimeFormat {\n return cached(rtfCache, locale, () => new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }));\n}\n\nexport function listFormat(locale: string, type: Intl.ListFormatType): Intl.ListFormat {\n return cached(lfCache, locale + type, () => new Intl.ListFormat(locale, { type }));\n}\n","import { dateTimeFormat, listFormat, numberFormat, pluralRules, relativeTimeFormat } from './intl';\nimport type { MessageNode, ParamNode } from './parse';\nimport type { Formatter, Params } from './types';\n\ninterface FormatContext {\n locale: string;\n params: Params | undefined;\n formatters: Record<string, Formatter>;\n hashValue?: unknown;\n}\n\nexport function formatNodes(nodes: MessageNode[], ctx: FormatContext): string {\n let out = '';\n for (const node of nodes) {\n if (node.kind === 'text') out += node.value;\n else if (node.kind === 'hash') out += autoFormat(ctx.hashValue, ctx.locale);\n else out += formatParam(node, ctx);\n }\n return out;\n}\n\nfunction formatParam(node: ParamNode, ctx: FormatContext): string {\n const value = ctx.params?.[node.name];\n if (value === undefined) return `{${node.name}}`;\n\n if (node.variants) {\n const chosen = pickVariant(node.variants, value, ctx.locale, node.ordinal);\n if (!chosen) return '';\n return formatNodes(chosen, { ...ctx, hashValue: value });\n }\n if (node.format) return applyFormat(value, node.format, node.arg, ctx);\n return autoFormat(value, ctx.locale);\n}\n\nfunction pickVariant(\n variants: [string, MessageNode[]][],\n value: unknown,\n locale: string,\n ordinal?: boolean,\n): MessageNode[] | undefined {\n const raw = String(value);\n if (typeof value === 'number') {\n for (const [key, nodes] of variants) if (key === `=${raw}`) return nodes;\n const category = pluralRules(locale, ordinal ? 'ordinal' : 'cardinal').select(value);\n for (const [key, nodes] of variants) if (key === category) return nodes;\n } else {\n for (const [key, nodes] of variants) if (key === raw) return nodes;\n }\n for (const [key, nodes] of variants) if (key === 'other') return nodes;\n return undefined;\n}\n\nfunction applyFormat(\n value: unknown,\n format: string,\n arg: string | undefined,\n ctx: FormatContext,\n): string {\n const custom = ctx.formatters[format];\n if (custom) return custom(value, ctx.locale, arg);\n\n const { locale } = ctx;\n switch (format) {\n case 'number':\n return numberFormat(locale).format(Number(value));\n case 'integer':\n return numberFormat(locale, { maximumFractionDigits: 0 }).format(Number(value));\n case 'percent':\n return numberFormat(locale, { style: 'percent' }).format(Number(value));\n case 'currency':\n if (!arg) return String(value);\n return numberFormat(locale, { style: 'currency', currency: arg }).format(Number(value));\n case 'date':\n return dateTimeFormat(\n locale,\n arg ? { dateStyle: arg as Intl.DateTimeFormatOptions['dateStyle'] } : undefined,\n ).format(toDate(value));\n case 'time':\n return dateTimeFormat(locale, {\n timeStyle: (arg ?? 'short') as Intl.DateTimeFormatOptions['timeStyle'],\n }).format(toDate(value));\n case 'relative':\n return formatRelative(value, arg, locale);\n case 'list': {\n if (!Array.isArray(value)) return String(value);\n const type = arg === 'or' ? 'disjunction' : arg === 'unit' ? 'unit' : 'conjunction';\n return listFormat(locale, type).format(value.map((item) => autoFormat(item, locale)));\n }\n case 'unit':\n if (!arg) return String(value);\n try {\n return numberFormat(locale, { style: 'unit', unit: arg }).format(Number(value));\n } catch {\n warnOnce(`invalid unit \"${arg}\"`);\n return String(value);\n }\n default:\n warnOnce(`unknown format \"${format}\"`);\n return String(value);\n }\n}\n\n// seconds per unit, largest first (auto pick)\nconst REL_UNITS: [Intl.RelativeTimeFormatUnit, number][] = [\n ['year', 31536000],\n ['month', 2592000],\n ['week', 604800],\n ['day', 86400],\n ['hour', 3600],\n ['minute', 60],\n ['second', 1],\n];\n\nfunction formatRelative(value: unknown, arg: string | undefined, locale: string): string {\n try {\n if (typeof value === 'number' && arg) {\n return relativeTimeFormat(locale).format(value, arg as Intl.RelativeTimeFormatUnit);\n }\n if (value instanceof Date) {\n const diffSec = (value.getTime() - Date.now()) / 1000;\n if (arg) {\n const per = REL_UNITS.find(([unit]) => unit === arg)?.[1];\n if (!per) throw new RangeError(arg);\n return relativeTimeFormat(locale).format(\n Math.round(diffSec / per),\n arg as Intl.RelativeTimeFormatUnit,\n );\n }\n const [unit, per] = REL_UNITS.find(([, s]) => Math.abs(diffSec) >= s) ?? ['second', 1];\n return relativeTimeFormat(locale).format(Math.round(diffSec / per), unit);\n }\n } catch {\n warnOnce(`invalid relative unit \"${arg}\"`);\n }\n return String(value);\n}\n\nconst warned = new Set<string>();\nfunction warnOnce(msg: string): void {\n if (warned.has(msg)) return;\n warned.add(msg);\n console.warn(`[verbaly] ${msg}`);\n}\n\nexport function autoFormat(value: unknown, locale: string): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'number') return numberFormat(locale).format(value);\n if (value instanceof Date) return dateTimeFormat(locale).format(value);\n return String(value);\n}\n\nfunction toDate(value: unknown): Date {\n return value instanceof Date ? value : new Date(value as string | number);\n}\n","import type { MessageNode, ParamNode } from './parse';\n\n// ICU escape-hatch → native MessageNode AST\nconst ICU_ARG = /\\{\\s*[a-zA-Z0-9_]+\\s*,\\s*(?:plural|selectordinal|select|number|date|time)\\b/;\n\nexport function isIcu(message: string): boolean {\n return ICU_ARG.test(message);\n}\n\nexport function parseIcu(message: string): MessageNode[] {\n let i = 0;\n const at = (): string => message.charAt(i);\n const skipWs = (): void => {\n while (i < message.length && /\\s/.test(at())) i++;\n };\n const readIdent = (): string => {\n let s = '';\n while (i < message.length && /[a-zA-Z0-9_]/.test(at())) s += message[i++];\n return s;\n };\n\n function parseBody(inPlural: boolean): MessageNode[] {\n const nodes: MessageNode[] = [];\n let buf = '';\n const flush = (): void => {\n if (buf) nodes.push({ kind: 'text', value: buf });\n buf = '';\n };\n while (i < message.length) {\n const ch = at();\n if (ch === '}') break;\n if (ch === '{') {\n flush();\n nodes.push(parseArg());\n } else if (ch === '#' && inPlural) {\n flush();\n nodes.push({ kind: 'hash' });\n i++;\n } else if (ch === \"'\") {\n buf += readQuoted();\n } else {\n buf += ch;\n i++;\n }\n }\n flush();\n return nodes;\n }\n\n // ICU apostrophe quoting\n function readQuoted(): string {\n i++; // opening '\n if (at() === \"'\") {\n i++;\n return \"'\";\n }\n const next = at();\n if (next !== '{' && next !== '}' && next !== '#') return \"'\"; // lone apostrophe\n let out = '';\n while (i < message.length) {\n if (at() === \"'\") {\n if (message.charAt(i + 1) === \"'\") {\n out += \"'\";\n i += 2;\n continue;\n }\n i++; // closing '\n return out;\n }\n out += message[i++];\n }\n return out; // unterminated\n }\n\n function parseArg(): MessageNode {\n i++; // {\n skipWs();\n const name = readIdent();\n skipWs();\n if (at() === '}') {\n i++;\n return { kind: 'param', name };\n }\n if (at() === ',') i++;\n skipWs();\n const type = readIdent();\n const node: ParamNode = { kind: 'param', name };\n\n if (type === 'number' || type === 'date' || type === 'time') {\n skipWs();\n let style = '';\n if (at() === ',') {\n i++;\n skipWs();\n while (i < message.length && at() !== '}' && at() !== ',') style += message[i++];\n style = style.trim();\n }\n if (type === 'number') {\n node.format =\n style === 'integer'\n ? 'integer'\n : style === 'percent'\n ? 'percent'\n : style === 'currency'\n ? 'currency'\n : 'number';\n } else {\n node.format = type;\n if (style) node.arg = style;\n }\n skipToClose();\n return node;\n }\n\n if (type === 'plural' || type === 'selectordinal' || type === 'select') {\n if (type === 'selectordinal') node.ordinal = true;\n const variants: [string, MessageNode[]][] = [];\n skipWs();\n if (at() === ',') i++; // comma after the keyword\n skipWs();\n if (type !== 'select' && message.startsWith('offset:', i)) {\n i += 7;\n skipWs();\n while (i < message.length && /[0-9]/.test(at())) i++; // offset parsed, not applied (v1)\n skipWs();\n }\n while (i < message.length && at() !== '}') {\n const selector = readSelector();\n skipWs();\n if (at() !== '{') break;\n i++; // {\n const body = parseBody(type !== 'select');\n if (at() === '}') i++;\n variants.push([selector, body]);\n skipWs();\n }\n if (at() === '}') i++;\n node.variants = variants;\n return node;\n }\n\n // unknown type → simple param\n skipToClose();\n return node;\n }\n\n function readSelector(): string {\n if (at() === '=') {\n let s = '=';\n i++;\n while (i < message.length && /[0-9]/.test(at())) s += message[i++];\n return s;\n }\n let s = '';\n while (i < message.length && !/[\\s{]/.test(at())) s += message[i++];\n return s;\n }\n\n function skipToClose(): void {\n while (i < message.length && at() !== '}') i++;\n if (at() === '}') i++;\n }\n\n return parseBody(false);\n}\n","import { isIcu, parseIcu } from './icu';\n\nexport type MessageNode = { kind: 'text'; value: string } | { kind: 'hash' } | ParamNode;\n\nexport interface ParamNode {\n kind: 'param';\n name: string;\n format?: string;\n arg?: string;\n ordinal?: boolean;\n variants?: [string, MessageNode[]][];\n}\n\nconst astCache = new Map<string, MessageNode[]>();\nconst AST_CACHE_MAX = 2000; // dynamic/CMS messages can't grow it unbounded\n\nexport function parse(message: string): MessageNode[] {\n let cached = astCache.get(message);\n if (!cached) {\n if (astCache.size >= AST_CACHE_MAX) astCache.clear();\n cached = isIcu(message) ? parseIcu(message) : parseMessage(message, false);\n astCache.set(message, cached);\n }\n return cached;\n}\n\nfunction parseMessage(input: string, inVariant: boolean): MessageNode[] {\n const nodes: MessageNode[] = [];\n let buf = '';\n let i = 0;\n\n const flush = () => {\n if (buf) nodes.push({ kind: 'text', value: buf });\n buf = '';\n };\n\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n buf += '{';\n i += 2;\n continue;\n }\n const close = findClose(input, i);\n if (close < 0) {\n buf += input.slice(i);\n break;\n }\n flush();\n nodes.push(parsePlaceholder(input.slice(i + 1, close)));\n i = close + 1;\n } else if (ch === '}' && input[i + 1] === '}') {\n buf += '}';\n i += 2;\n } else if (inVariant && ch === '#') {\n if (input[i + 1] === '#') {\n buf += '#';\n i += 2;\n } else {\n flush();\n nodes.push({ kind: 'hash' });\n i += 1;\n }\n } else {\n buf += ch;\n i += 1;\n }\n }\n flush();\n return nodes;\n}\n\nfunction findClose(input: string, open: number): number {\n let depth = 0;\n let i = open;\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n i += 2;\n continue;\n }\n depth += 1;\n } else if (ch === '}') {\n if (input[i + 1] === '}') {\n i += 2;\n continue;\n }\n depth -= 1;\n if (depth === 0) return i;\n }\n i += 1;\n }\n return -1;\n}\n\nfunction parsePlaceholder(inner: string): MessageNode {\n const segments = splitTop(inner);\n const head = (segments[0] ?? '').trim();\n if (!head) return { kind: 'text', value: `{${inner}}` };\n\n const colon = head.indexOf(':');\n const name = (colon < 0 ? head : head.slice(0, colon)).trim();\n if (!name) return { kind: 'text', value: `{${inner}}` };\n\n const node: ParamNode = { kind: 'param', name };\n\n if (colon >= 0) {\n const fmtRaw = head.slice(colon + 1).trim();\n const slash = fmtRaw.indexOf('/');\n node.format = (slash < 0 ? fmtRaw : fmtRaw.slice(0, slash)).trim();\n if (slash >= 0) node.arg = fmtRaw.slice(slash + 1).trim();\n }\n\n if (segments.length > 1) {\n node.variants = [];\n for (const seg of segments.slice(1)) {\n const sep = seg.indexOf(':');\n if (sep < 0) continue;\n const key = seg.slice(0, sep).trim();\n const body = seg.slice(sep + 1).trim();\n if (key) node.variants.push([key, parseMessage(body, true)]);\n }\n }\n return node;\n}\n\nfunction splitTop(input: string): string[] {\n const parts: string[] = [];\n let buf = '';\n let depth = 0;\n let i = 0;\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n buf += '{{';\n i += 2;\n continue;\n }\n depth += 1;\n buf += ch;\n } else if (ch === '}') {\n if (input[i + 1] === '}') {\n buf += '}}';\n i += 2;\n continue;\n }\n depth -= 1;\n buf += ch;\n } else if (ch === '|' && depth === 0) {\n if (input[i + 1] === '|') {\n buf += '|';\n i += 2;\n continue;\n }\n parts.push(buf);\n buf = '';\n } else {\n buf += ch;\n }\n i += 1;\n }\n parts.push(buf);\n return parts;\n}\n","import { flatten } from './flatten';\nimport { autoFormat, formatNodes } from './format';\nimport { parse } from './parse';\nimport type {\n DictionaryInput,\n MessageTree,\n Params,\n TFunction,\n Verbaly,\n VerbalyOptions,\n} from './types';\n\nexport function createVerbaly<const D extends DictionaryInput = DictionaryInput>(\n options: VerbalyOptions<D> = {},\n): Verbaly<D> {\n const dict: Record<string, Record<string, string>> = {};\n const listeners = new Set<() => void>();\n const formatters = options.formatters ?? {};\n const loaders = options.loaders ?? {};\n const loaded = new Set<string>();\n const inFlight = new Map<string, Promise<void>>();\n const warned = new Set<string>();\n const fallbacks = options.fallback\n ? Array.isArray(options.fallback)\n ? options.fallback\n : [options.fallback]\n : [];\n\n let locale = options.locale ?? detectLocale();\n let version = 0;\n let chainCache: string[] | null = null;\n\n if (options.messages) {\n for (const [loc, tree] of Object.entries(options.messages)) {\n dict[loc] = flatten(tree);\n }\n }\n\n function chain(): string[] {\n if (chainCache) return chainCache;\n const result: string[] = [];\n // narrow BCP-47 subtags\n const parts = locale.split('-');\n while (parts.length > 0) {\n result.push(parts.join('-'));\n parts.pop();\n }\n for (const fb of fallbacks) if (!result.includes(fb)) result.push(fb);\n chainCache = result;\n return result;\n }\n\n function lookup(key: string): { msg: string; from: string } | undefined {\n for (const loc of chain()) {\n const msg = dict[loc]?.[key];\n // '' = untranslated (extract scaffolds it) → keep falling back\n if (msg) return { msg, from: loc };\n }\n return undefined;\n }\n\n function translate(key: string, params: Params | undefined): string {\n const hit = lookup(key);\n if (hit === undefined) {\n const replacement = options.onMissing?.(key, locale);\n const value = typeof replacement === 'string' ? replacement : key;\n if (typeof replacement !== 'string' && !options.onMissing && !warned.has(key)) {\n warned.add(key);\n console.warn(`[verbaly] missing key \"${key}\" (${locale})`);\n }\n options.onResolve?.({ key, locale, value, status: 'miss' });\n return value;\n }\n const value = formatNodes(parse(hit.msg), { locale, params, formatters });\n options.onResolve?.({\n key,\n locale,\n value,\n status: hit.from === locale ? 'hit' : 'fallback',\n from: hit.from,\n });\n return value;\n }\n\n function tagged(strings: TemplateStringsArray, values: unknown[]): string {\n let out = strings[0] ?? '';\n for (let i = 0; i < values.length; i++) {\n out += autoFormat(values[i], locale) + (strings[i + 1] ?? '');\n }\n return out;\n }\n\n function notify(): void {\n version += 1;\n for (const fn of listeners) fn();\n }\n\n const t = ((first: unknown, ...rest: unknown[]): string => {\n if (isTemplateStrings(first)) return tagged(first, rest);\n return translate(first as string, rest[0] as Params | undefined);\n }) as TFunction<D>;\n\n t.id =\n () =>\n (strings: TemplateStringsArray, ...values: unknown[]) =>\n tagged(strings, values);\n\n function pendingLoader(target: string): string | undefined {\n const parts = target.split('-');\n while (parts.length > 0) {\n const candidate = parts.join('-');\n if (loaders[candidate] && !loaded.has(candidate)) return candidate;\n if (loaders[candidate]) return undefined;\n parts.pop();\n }\n return undefined;\n }\n\n function loadLocale(target: string): Promise<void> {\n const pending = pendingLoader(target);\n if (!pending) return Promise.resolve();\n const running = inFlight.get(pending);\n if (running) return running;\n const load = loaders[pending]!()\n .then((mod) => {\n loaded.add(pending);\n inFlight.delete(pending);\n addMessages(\n pending,\n 'default' in mod ? (mod.default as MessageTree) : (mod as MessageTree),\n );\n })\n .catch((error: unknown) => {\n inFlight.delete(pending);\n throw error;\n });\n inFlight.set(pending, load);\n return load;\n }\n\n function addMessages(loc: string, messages: MessageTree): void {\n dict[loc] = { ...dict[loc], ...flatten(messages) };\n notify();\n }\n\n return {\n get locale() {\n return locale;\n },\n get locales() {\n return [...new Set([...Object.keys(dict), ...Object.keys(loaders)])];\n },\n get version() {\n return version;\n },\n t,\n setLocale(next: string) {\n // auto-load pending catalog; UI re-renders when it lands\n if (pendingLoader(next)) {\n void loadLocale(next).catch(() => {\n if (!warned.has(`load:${next}`)) {\n warned.add(`load:${next}`);\n console.warn(`[verbaly] failed to load catalog for \"${next}\"`);\n }\n });\n }\n if (next === locale) return;\n locale = next;\n chainCache = null;\n notify();\n },\n loadLocale,\n addMessages,\n subscribe(listener: () => void) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n has(key: string) {\n return lookup(key) !== undefined;\n },\n inspect(key: string) {\n const hit = lookup(key);\n return hit ? { locale: hit.from, source: hit.msg } : undefined;\n },\n };\n}\n\nfunction isTemplateStrings(value: unknown): value is TemplateStringsArray {\n return Array.isArray(value) && 'raw' in value;\n}\n\nfunction detectLocale(): string {\n // gate on document, not navigator — Node 21+ exposes a global navigator (OS locale)\n return typeof document !== 'undefined' && typeof navigator !== 'undefined' && navigator.language\n ? navigator.language\n : 'en';\n}\n","// Named-tag tokenizer for <Trans>\nexport type TagNode = string | { name: string; children: TagNode[] };\n\nconst TAG = /<(\\/?)([a-zA-Z][\\w-]*)(\\/?)>/g;\n\nexport function parseTags(text: string): TagNode[] {\n const re = new RegExp(TAG.source, 'g');\n const root: TagNode[] = [];\n const stack: { name: string; children: TagNode[] }[] = [];\n const top = (): TagNode[] => (stack.length ? stack[stack.length - 1]!.children : root);\n const pushText = (s: string): void => {\n if (s) top().push(s);\n };\n\n let last = 0;\n let m: RegExpExecArray | null;\n while ((m = re.exec(text)) !== null) {\n const [full, closing, name, selfClose] = m;\n pushText(text.slice(last, m.index));\n last = m.index + full.length;\n\n if (selfClose) {\n top().push({ name: name!, children: [] });\n } else if (closing) {\n if (stack.length && stack[stack.length - 1]!.name === name) {\n const node = stack.pop()!;\n top().push(node);\n } else {\n pushText(full); // stray closing tag → literal\n }\n } else {\n stack.push({ name: name!, children: [] });\n }\n }\n pushText(text.slice(last));\n\n // unclosed opens: drop wrapper\n while (stack.length) {\n const node = stack.pop()!;\n top().push(...node.children);\n }\n return root;\n}\n","import { parseTags, type TagNode } from './tags';\nimport type { DictionaryInput, Params, Verbaly } from './types';\n\n// hrefs come from the caller, never from messages\nexport type RichLink = string | { href: string; target?: string; rel?: string };\n\nexport interface BindDomOptions {\n root?: ParentNode;\n attribute?: string;\n richTags?: string[];\n richLinks?: Record<string, RichLink>;\n}\n\nconst UNSAFE_HREF = /^\\s*(javascript|data|vbscript):/i;\n\nexport function safeHref(href: string): string | undefined {\n if (UNSAFE_HREF.test(href)) {\n console.warn(`[verbaly] blocked unsafe href: ${href}`);\n return undefined;\n }\n return href;\n}\n\n// phrasing-only, attribute-less → XSS-safe\nexport const RICH_TAGS = [\n 'em',\n 'strong',\n 'code',\n 'b',\n 'i',\n 'u',\n 's',\n 'small',\n 'mark',\n 'sub',\n 'sup',\n 'span',\n 'kbd',\n 'abbr',\n 'br',\n 'wbr',\n];\n\nexport function bindDom<D extends DictionaryInput>(\n instance: Verbaly<D>,\n options: BindDomOptions = {},\n): () => void {\n if (typeof document === 'undefined') {\n throw new Error('[verbaly] bindDom requires a DOM');\n }\n const t = instance.t as unknown as (key: string, params?: Params) => string;\n const root = options.root ?? document.body;\n const attr = options.attribute ?? 'data-verbaly';\n const argsAttr = `${attr}-args`;\n const attrsAttr = `${attr}-attr`;\n const richAttr = `${attr}-rich`;\n const linksAttr = `${attr}-links`;\n const richTags = new Set(options.richTags ?? RICH_TAGS);\n const globalLinks = options.richLinks;\n const argsCache = new WeakMap<Element, { raw: string | null; params: Params | undefined }>();\n const linksCache = new WeakMap<\n Element,\n { raw: string | null; links: Record<string, RichLink> | undefined }\n >();\n\n function cachedArgs(el: Element): Params | undefined {\n const raw = el.getAttribute(argsAttr);\n const hit = argsCache.get(el);\n if (hit && hit.raw === raw) return hit.params;\n const params = parseArgs(raw);\n argsCache.set(el, { raw, params });\n return params;\n }\n\n function cachedLinks(el: Element): Record<string, RichLink> | undefined {\n const raw = el.getAttribute(linksAttr);\n if (!raw) return globalLinks;\n const hit = linksCache.get(el);\n if (hit && hit.raw === raw) return hit.links;\n const own = parseArgs(raw) as Record<string, RichLink> | undefined;\n const links = own ? (globalLinks ? { ...globalLinks, ...own } : own) : globalLinks;\n linksCache.set(el, { raw, links });\n return links;\n }\n\n function renderRich(\n el: Element,\n nodes: TagNode[],\n links: Record<string, RichLink> | undefined,\n ): void {\n for (const node of nodes) {\n if (typeof node === 'string') {\n el.append(node);\n } else if (links?.[node.name] !== undefined) {\n const link = links[node.name]!;\n const { href, target, rel }: Exclude<RichLink, string> =\n typeof link === 'string' ? { href: link } : link;\n const a = el.ownerDocument.createElement('a');\n const safe = safeHref(href);\n if (safe !== undefined) a.setAttribute('href', safe);\n if (target) a.setAttribute('target', target);\n if (rel) a.setAttribute('rel', rel);\n renderRich(a, node.children, links);\n el.append(a);\n } else if (richTags.has(node.name)) {\n const child = el.ownerDocument.createElement(node.name);\n renderRich(child, node.children, links);\n el.append(child);\n } else {\n renderRich(el, node.children, links); // unknown tag → unwrap\n }\n }\n }\n\n function render(el: Element): void {\n const args = cachedArgs(el);\n const key = el.getAttribute(attr);\n if (key) {\n const text = t(key, args);\n if (el.hasAttribute(richAttr)) {\n el.textContent = '';\n renderRich(el, parseTags(text), cachedLinks(el));\n } else {\n el.textContent = text;\n }\n }\n\n const attrMap = parseArgs(el.getAttribute(attrsAttr));\n if (attrMap) {\n for (const [name, attrKey] of Object.entries(attrMap)) {\n if (typeof attrKey !== 'string' || name.toLowerCase().startsWith('on')) continue;\n el.setAttribute(name, t(attrKey, args));\n }\n }\n }\n\n const selector = `[${attr}], [${attrsAttr}]`;\n\n function renderAll(scope: ParentNode | Element): void {\n if (scope instanceof Element && scope.matches(selector)) render(scope);\n for (const el of scope.querySelectorAll(selector)) render(el);\n }\n\n renderAll(root);\n const unsubscribe = instance.subscribe(() => renderAll(root));\n\n const observer = new MutationObserver((records) => {\n for (const record of records) {\n if (record.type === 'attributes' && record.target instanceof Element) {\n render(record.target);\n } else if (record.type === 'childList') {\n for (const node of record.addedNodes) {\n if (node instanceof Element) renderAll(node);\n }\n }\n }\n });\n\n observer.observe(root instanceof Document ? root.documentElement : (root as Node), {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [attr, argsAttr, attrsAttr, richAttr, linksAttr],\n });\n\n return () => {\n unsubscribe();\n observer.disconnect();\n };\n}\n\nfunction parseArgs(raw: string | null): Params | undefined {\n if (!raw) return undefined;\n try {\n return JSON.parse(raw) as Params;\n } catch {\n console.warn(`[verbaly] invalid args JSON: ${raw}`);\n return undefined;\n }\n}\n","// locale bootstrap helpers (SSR-safe)\nexport interface ResolveLocaleOptions {\n supported: string[];\n fallback?: string;\n storageKey?: string | false;\n}\n\nconst DEFAULT_KEY = 'verbaly-locale';\n\nexport function resolveLocale(options: ResolveLocaleOptions): string {\n const { supported, fallback = supported[0] ?? 'en', storageKey = DEFAULT_KEY } = options;\n\n if (storageKey) {\n const stored = getStorage()?.getItem(storageKey);\n const match = stored && matchSupported(stored, supported);\n if (match) return match;\n }\n\n for (const lang of preferredLanguages()) {\n const match = matchSupported(lang, supported);\n if (match) return match;\n }\n\n return fallback;\n}\n\n// exact, then BCP-47 base (es-PE → es)\nfunction matchSupported(lang: string, supported: string[]): string | undefined {\n if (supported.includes(lang)) return lang;\n const base = lang.split('-')[0]!;\n return supported.includes(base) ? base : undefined;\n}\n\nexport function persistLocale(locale: string, storageKey: string | false = DEFAULT_KEY): void {\n if (storageKey) getStorage()?.setItem(storageKey, locale);\n if (typeof document !== 'undefined') document.documentElement.lang = locale;\n}\n\nfunction preferredLanguages(): readonly string[] {\n // require document — Node 21+ has a global navigator whose language is the OS, not a user\n if (typeof document === 'undefined' || typeof navigator === 'undefined') return [];\n return navigator.languages?.length ? navigator.languages : [navigator.language];\n}\n\nfunction getStorage(): Storage | null {\n try {\n return typeof localStorage === 'undefined' ? null : localStorage;\n } catch {\n return null; // blocked storage (privacy mode)\n }\n}\n"],"mappings":";;AAEA,SAAgB,QACd,MACA,SAAS,IACT,MAA8B,CAAC,GACP;CACxB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAAI,GAAG;EAC/C,MAAM,OAAO,SAAS,GAAG,OAAO,GAAG,QAAQ;EAC3C,IAAI,OAAO,UAAU,UAAU,IAAI,QAAQ;OACtC,QAAQ,OAAO,MAAM,GAAG;CAC/B;CACA,OAAO;AACT;;;ACbA,MAAM,YAAY;AAElB,MAAM,0BAAU,IAAI,IAA+B;AACnD,MAAM,2BAAW,IAAI,IAAiC;AACtD,MAAM,0BAAU,IAAI,IAA8B;AAClD,MAAM,2BAAW,IAAI,IAAqC;AAC1D,MAAM,0BAAU,IAAI,IAA6B;AAEjD,SAAS,OAAU,OAAuB,KAAa,MAAkB;CACvE,IAAI,MAAM,MAAM,IAAI,GAAG;CACvB,IAAI,CAAC,KAAK;EACR,IAAI,MAAM,QAAQ,WAAW,MAAM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AAS,eAAe,MAAc,WAAyC;CAC7E,IAAI,UAAU,SAAS,IAAI,GAAG,OAAO;CACrC,MAAM,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC;CAC7B,OAAO,UAAU,SAAS,IAAI,IAAI,OAAO,KAAA;AAC3C;AAEA,SAAgB,cAAc,QAAgB,aAA6B,aAAmB;CAC5F,IAAI,YAAY,WAAW,CAAC,EAAE,QAAQ,YAAY,MAAM;CACxD,IAAI,OAAO,aAAa,aAAa,SAAS,gBAAgB,OAAO;AACvE;AAEA,SAAS,qBAAwC;CAE/C,IAAI,OAAO,aAAa,eAAe,OAAO,cAAc,aAAa,OAAO,CAAC;CACjF,OAAO,UAAU,WAAW,SAAS,UAAU,YAAY,CAAC,UAAU,QAAQ;AAChF;AAEA,SAAS,aAA6B;CACpC,IAAI;EACF,OAAO,OAAO,iBAAiB,cAAc,OAAO;CACtD,QAAQ;EACN,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/flatten.ts","../src/intl.ts","../src/format.ts","../src/icu.ts","../src/parse.ts","../src/instance.ts","../src/tags.ts","../src/dom.ts","../src/locale.ts"],"sourcesContent":["import type { MessageTree } from './types';\n\nexport function flatten(\n tree: MessageTree,\n prefix = '',\n out: Record<string, string> = {},\n): Record<string, string> {\n for (const [key, value] of Object.entries(tree)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'string') out[path] = value;\n else flatten(value, path, out);\n }\n return out;\n}\n","const CACHE_CAP = 200; // dynamic locales/options can't grow unbounded\n\nconst nfCache = new Map<string, Intl.NumberFormat>();\nconst dtfCache = new Map<string, Intl.DateTimeFormat>();\nconst prCache = new Map<string, Intl.PluralRules>();\nconst rtfCache = new Map<string, Intl.RelativeTimeFormat>();\nconst lfCache = new Map<string, Intl.ListFormat>();\n\nfunction cached<T>(cache: Map<string, T>, key: string, make: () => T): T {\n let hit = cache.get(key);\n if (!hit) {\n if (cache.size >= CACHE_CAP) cache.delete(cache.keys().next().value as string);\n hit = make();\n cache.set(key, hit);\n }\n return hit;\n}\n\nexport function numberFormat(\n locale: string,\n options?: Intl.NumberFormatOptions,\n): Intl.NumberFormat {\n const key = locale + (options ? JSON.stringify(options) : '');\n return cached(nfCache, key, () => new Intl.NumberFormat(locale, options));\n}\n\nexport function dateTimeFormat(\n locale: string,\n options?: Intl.DateTimeFormatOptions,\n): Intl.DateTimeFormat {\n const key = locale + (options ? JSON.stringify(options) : '');\n return cached(dtfCache, key, () => new Intl.DateTimeFormat(locale, options));\n}\n\nexport function pluralRules(\n locale: string,\n type: Intl.PluralRuleType = 'cardinal',\n): Intl.PluralRules {\n return cached(prCache, locale + type, () => new Intl.PluralRules(locale, { type }));\n}\n\nexport function relativeTimeFormat(locale: string): Intl.RelativeTimeFormat {\n return cached(rtfCache, locale, () => new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }));\n}\n\nexport function listFormat(locale: string, type: Intl.ListFormatType): Intl.ListFormat {\n return cached(lfCache, locale + type, () => new Intl.ListFormat(locale, { type }));\n}\n","import { dateTimeFormat, listFormat, numberFormat, pluralRules, relativeTimeFormat } from './intl';\nimport type { MessageNode, ParamNode } from './parse';\nimport type { Formatter, Params } from './types';\n\ninterface FormatContext {\n locale: string;\n params: Params | undefined;\n formatters: Record<string, Formatter>;\n hashValue?: unknown;\n}\n\nexport function formatNodes(nodes: MessageNode[], ctx: FormatContext): string {\n let out = '';\n for (const node of nodes) {\n if (node.kind === 'text') out += node.value;\n else if (node.kind === 'hash') out += autoFormat(ctx.hashValue, ctx.locale);\n else out += formatParam(node, ctx);\n }\n return out;\n}\n\nfunction formatParam(node: ParamNode, ctx: FormatContext): string {\n const value = ctx.params?.[node.name];\n if (value === undefined) return `{${node.name}}`;\n\n if (node.variants) {\n const chosen = pickVariant(node.variants, value, ctx.locale, node.ordinal);\n if (!chosen) return '';\n return formatNodes(chosen, { ...ctx, hashValue: value });\n }\n if (node.format) return applyFormat(value, node.format, node.arg, ctx);\n return autoFormat(value, ctx.locale);\n}\n\nfunction pickVariant(\n variants: [string, MessageNode[]][],\n value: unknown,\n locale: string,\n ordinal?: boolean,\n): MessageNode[] | undefined {\n const raw = String(value);\n if (typeof value === 'number') {\n for (const [key, nodes] of variants) if (key === `=${raw}`) return nodes;\n const category = pluralRules(locale, ordinal ? 'ordinal' : 'cardinal').select(value);\n for (const [key, nodes] of variants) if (key === category) return nodes;\n } else {\n for (const [key, nodes] of variants) if (key === raw) return nodes;\n }\n for (const [key, nodes] of variants) if (key === 'other') return nodes;\n return undefined;\n}\n\nfunction applyFormat(\n value: unknown,\n format: string,\n arg: string | undefined,\n ctx: FormatContext,\n): string {\n const custom = ctx.formatters[format];\n if (custom) return custom(value, ctx.locale, arg);\n\n const { locale } = ctx;\n switch (format) {\n case 'number':\n return numberFormat(locale).format(Number(value));\n case 'integer':\n return numberFormat(locale, { maximumFractionDigits: 0 }).format(Number(value));\n case 'percent':\n return numberFormat(locale, { style: 'percent' }).format(Number(value));\n case 'currency':\n if (!arg) return String(value);\n return numberFormat(locale, { style: 'currency', currency: arg }).format(Number(value));\n case 'date':\n return dateTimeFormat(\n locale,\n arg ? { dateStyle: arg as Intl.DateTimeFormatOptions['dateStyle'] } : undefined,\n ).format(toDate(value));\n case 'time':\n return dateTimeFormat(locale, {\n timeStyle: (arg ?? 'short') as Intl.DateTimeFormatOptions['timeStyle'],\n }).format(toDate(value));\n case 'relative':\n return formatRelative(value, arg, locale);\n case 'list': {\n if (!Array.isArray(value)) return String(value);\n const type = arg === 'or' ? 'disjunction' : arg === 'unit' ? 'unit' : 'conjunction';\n return listFormat(locale, type).format(value.map((item) => autoFormat(item, locale)));\n }\n case 'unit':\n if (!arg) return String(value);\n try {\n return numberFormat(locale, { style: 'unit', unit: arg }).format(Number(value));\n } catch {\n warnOnce(`invalid unit \"${arg}\"`);\n return String(value);\n }\n default:\n warnOnce(`unknown format \"${format}\"`);\n return String(value);\n }\n}\n\n// seconds per unit, largest first (auto pick)\nconst REL_UNITS: [Intl.RelativeTimeFormatUnit, number][] = [\n ['year', 31536000],\n ['month', 2592000],\n ['week', 604800],\n ['day', 86400],\n ['hour', 3600],\n ['minute', 60],\n ['second', 1],\n];\n\nfunction formatRelative(value: unknown, arg: string | undefined, locale: string): string {\n try {\n if (typeof value === 'number' && arg) {\n return relativeTimeFormat(locale).format(value, arg as Intl.RelativeTimeFormatUnit);\n }\n if (value instanceof Date) {\n const diffSec = (value.getTime() - Date.now()) / 1000;\n if (arg) {\n const per = REL_UNITS.find(([unit]) => unit === arg)?.[1];\n if (!per) throw new RangeError(arg);\n return relativeTimeFormat(locale).format(\n Math.round(diffSec / per),\n arg as Intl.RelativeTimeFormatUnit,\n );\n }\n const [unit, per] = REL_UNITS.find(([, s]) => Math.abs(diffSec) >= s) ?? ['second', 1];\n return relativeTimeFormat(locale).format(Math.round(diffSec / per), unit);\n }\n } catch {\n warnOnce(`invalid relative unit \"${arg}\"`);\n }\n return String(value);\n}\n\nconst warned = new Set<string>();\nfunction warnOnce(msg: string): void {\n if (warned.has(msg)) return;\n warned.add(msg);\n console.warn(`[verbaly] ${msg}`);\n}\n\nexport function autoFormat(value: unknown, locale: string): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'number') return numberFormat(locale).format(value);\n if (value instanceof Date) return dateTimeFormat(locale).format(value);\n return String(value);\n}\n\nfunction toDate(value: unknown): Date {\n return value instanceof Date ? value : new Date(value as string | number);\n}\n","import type { MessageNode, ParamNode } from './parse';\n\n// ICU escape-hatch → native MessageNode AST\nconst ICU_ARG = /\\{\\s*[a-zA-Z0-9_]+\\s*,\\s*(?:plural|selectordinal|select|number|date|time)\\b/;\n\nexport function isIcu(message: string): boolean {\n return ICU_ARG.test(message);\n}\n\nexport function parseIcu(message: string): MessageNode[] {\n let i = 0;\n const at = (): string => message.charAt(i);\n const skipWs = (): void => {\n while (i < message.length && /\\s/.test(at())) i++;\n };\n const readIdent = (): string => {\n let s = '';\n while (i < message.length && /[a-zA-Z0-9_]/.test(at())) s += message[i++];\n return s;\n };\n\n function parseBody(inPlural: boolean): MessageNode[] {\n const nodes: MessageNode[] = [];\n let buf = '';\n const flush = (): void => {\n if (buf) nodes.push({ kind: 'text', value: buf });\n buf = '';\n };\n while (i < message.length) {\n const ch = at();\n if (ch === '}') break;\n if (ch === '{') {\n flush();\n nodes.push(parseArg());\n } else if (ch === '#' && inPlural) {\n flush();\n nodes.push({ kind: 'hash' });\n i++;\n } else if (ch === \"'\") {\n buf += readQuoted();\n } else {\n buf += ch;\n i++;\n }\n }\n flush();\n return nodes;\n }\n\n // ICU apostrophe quoting\n function readQuoted(): string {\n i++; // opening '\n if (at() === \"'\") {\n i++;\n return \"'\";\n }\n const next = at();\n if (next !== '{' && next !== '}' && next !== '#') return \"'\"; // lone apostrophe\n let out = '';\n while (i < message.length) {\n if (at() === \"'\") {\n if (message.charAt(i + 1) === \"'\") {\n out += \"'\";\n i += 2;\n continue;\n }\n i++; // closing '\n return out;\n }\n out += message[i++];\n }\n return out; // unterminated\n }\n\n function parseArg(): MessageNode {\n i++; // {\n skipWs();\n const name = readIdent();\n skipWs();\n if (at() === '}') {\n i++;\n return { kind: 'param', name };\n }\n if (at() === ',') i++;\n skipWs();\n const type = readIdent();\n const node: ParamNode = { kind: 'param', name };\n\n if (type === 'number' || type === 'date' || type === 'time') {\n skipWs();\n let style = '';\n if (at() === ',') {\n i++;\n skipWs();\n while (i < message.length && at() !== '}' && at() !== ',') style += message[i++];\n style = style.trim();\n }\n if (type === 'number') {\n node.format =\n style === 'integer'\n ? 'integer'\n : style === 'percent'\n ? 'percent'\n : style === 'currency'\n ? 'currency'\n : 'number';\n } else {\n node.format = type;\n if (style) node.arg = style;\n }\n skipToClose();\n return node;\n }\n\n if (type === 'plural' || type === 'selectordinal' || type === 'select') {\n if (type === 'selectordinal') node.ordinal = true;\n const variants: [string, MessageNode[]][] = [];\n skipWs();\n if (at() === ',') i++; // comma after the keyword\n skipWs();\n if (type !== 'select' && message.startsWith('offset:', i)) {\n i += 7;\n skipWs();\n while (i < message.length && /[0-9]/.test(at())) i++; // offset parsed, not applied (v1)\n skipWs();\n }\n while (i < message.length && at() !== '}') {\n const selector = readSelector();\n skipWs();\n if (at() !== '{') break;\n i++; // {\n const body = parseBody(type !== 'select');\n if (at() === '}') i++;\n variants.push([selector, body]);\n skipWs();\n }\n if (at() === '}') i++;\n node.variants = variants;\n return node;\n }\n\n // unknown type → simple param\n skipToClose();\n return node;\n }\n\n function readSelector(): string {\n if (at() === '=') {\n let s = '=';\n i++;\n while (i < message.length && /[0-9]/.test(at())) s += message[i++];\n return s;\n }\n let s = '';\n while (i < message.length && !/[\\s{]/.test(at())) s += message[i++];\n return s;\n }\n\n function skipToClose(): void {\n while (i < message.length && at() !== '}') i++;\n if (at() === '}') i++;\n }\n\n return parseBody(false);\n}\n","import { isIcu, parseIcu } from './icu';\n\nexport type MessageNode = { kind: 'text'; value: string } | { kind: 'hash' } | ParamNode;\n\nexport interface ParamNode {\n kind: 'param';\n name: string;\n format?: string;\n arg?: string;\n ordinal?: boolean;\n variants?: [string, MessageNode[]][];\n}\n\nconst astCache = new Map<string, MessageNode[]>();\nconst AST_CACHE_MAX = 2000; // dynamic/CMS messages can't grow it unbounded\n\nexport function parse(message: string): MessageNode[] {\n let cached = astCache.get(message);\n if (!cached) {\n if (astCache.size >= AST_CACHE_MAX) astCache.clear();\n cached = isIcu(message) ? parseIcu(message) : parseMessage(message, false);\n astCache.set(message, cached);\n }\n return cached;\n}\n\nfunction parseMessage(input: string, inVariant: boolean): MessageNode[] {\n const nodes: MessageNode[] = [];\n let buf = '';\n let i = 0;\n\n const flush = () => {\n if (buf) nodes.push({ kind: 'text', value: buf });\n buf = '';\n };\n\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n buf += '{';\n i += 2;\n continue;\n }\n const close = findClose(input, i);\n if (close < 0) {\n buf += input.slice(i);\n break;\n }\n flush();\n nodes.push(parsePlaceholder(input.slice(i + 1, close)));\n i = close + 1;\n } else if (ch === '}' && input[i + 1] === '}') {\n buf += '}';\n i += 2;\n } else if (inVariant && ch === '#') {\n if (input[i + 1] === '#') {\n buf += '#';\n i += 2;\n } else {\n flush();\n nodes.push({ kind: 'hash' });\n i += 1;\n }\n } else {\n buf += ch;\n i += 1;\n }\n }\n flush();\n return nodes;\n}\n\nfunction findClose(input: string, open: number): number {\n let depth = 0;\n let i = open;\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n i += 2;\n continue;\n }\n depth += 1;\n } else if (ch === '}') {\n if (input[i + 1] === '}') {\n i += 2;\n continue;\n }\n depth -= 1;\n if (depth === 0) return i;\n }\n i += 1;\n }\n return -1;\n}\n\nfunction parsePlaceholder(inner: string): MessageNode {\n const segments = splitTop(inner);\n const head = (segments[0] ?? '').trim();\n if (!head) return { kind: 'text', value: `{${inner}}` };\n\n const colon = head.indexOf(':');\n const name = (colon < 0 ? head : head.slice(0, colon)).trim();\n if (!name) return { kind: 'text', value: `{${inner}}` };\n\n const node: ParamNode = { kind: 'param', name };\n\n if (colon >= 0) {\n const fmtRaw = head.slice(colon + 1).trim();\n const slash = fmtRaw.indexOf('/');\n node.format = (slash < 0 ? fmtRaw : fmtRaw.slice(0, slash)).trim();\n if (slash >= 0) node.arg = fmtRaw.slice(slash + 1).trim();\n }\n\n if (segments.length > 1) {\n node.variants = [];\n for (const seg of segments.slice(1)) {\n const sep = seg.indexOf(':');\n if (sep < 0) continue;\n const key = seg.slice(0, sep).trim();\n const body = seg.slice(sep + 1).trim();\n if (key) node.variants.push([key, parseMessage(body, true)]);\n }\n }\n return node;\n}\n\nfunction splitTop(input: string): string[] {\n const parts: string[] = [];\n let buf = '';\n let depth = 0;\n let i = 0;\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n buf += '{{';\n i += 2;\n continue;\n }\n depth += 1;\n buf += ch;\n } else if (ch === '}') {\n if (input[i + 1] === '}') {\n buf += '}}';\n i += 2;\n continue;\n }\n depth -= 1;\n buf += ch;\n } else if (ch === '|' && depth === 0) {\n if (input[i + 1] === '|') {\n buf += '|';\n i += 2;\n continue;\n }\n parts.push(buf);\n buf = '';\n } else {\n buf += ch;\n }\n i += 1;\n }\n parts.push(buf);\n return parts;\n}\n","import { flatten } from './flatten';\nimport { autoFormat, formatNodes } from './format';\nimport { parse } from './parse';\nimport type {\n DictionaryInput,\n MessageTree,\n Params,\n TFunction,\n Verbaly,\n VerbalyOptions,\n} from './types';\n\nexport function createVerbaly<const D extends DictionaryInput = DictionaryInput>(\n options: VerbalyOptions<D> = {},\n): Verbaly<D> {\n const dict: Record<string, Record<string, string>> = {};\n const listeners = new Set<() => void>();\n const formatters = options.formatters ?? {};\n const loaders = options.loaders ?? {};\n const loaded = new Set<string>();\n const inFlight = new Map<string, Promise<void>>();\n const warned = new Set<string>();\n const fallbacks = options.fallback\n ? Array.isArray(options.fallback)\n ? options.fallback\n : [options.fallback]\n : [];\n\n let locale = options.locale ?? detectLocale();\n let version = 0;\n let chainCache: string[] | null = null;\n\n if (options.messages) {\n for (const [loc, tree] of Object.entries(options.messages)) {\n dict[loc] = flatten(tree);\n }\n }\n\n function chain(): string[] {\n if (chainCache) return chainCache;\n const result: string[] = [];\n // narrow BCP-47 subtags\n const parts = locale.split('-');\n while (parts.length > 0) {\n result.push(parts.join('-'));\n parts.pop();\n }\n for (const fb of fallbacks) if (!result.includes(fb)) result.push(fb);\n chainCache = result;\n return result;\n }\n\n function lookup(key: string): { msg: string; from: string } | undefined {\n for (const loc of chain()) {\n const msg = dict[loc]?.[key];\n // '' = untranslated (extract scaffolds it) → keep falling back\n if (msg) return { msg, from: loc };\n }\n return undefined;\n }\n\n function translate(key: string, params: Params | undefined): string {\n const hit = lookup(key);\n if (hit === undefined) {\n const replacement = options.onMissing?.(key, locale);\n const value = typeof replacement === 'string' ? replacement : key;\n if (typeof replacement !== 'string' && !options.onMissing && !warned.has(key)) {\n warned.add(key);\n console.warn(`[verbaly] missing key \"${key}\" (${locale})`);\n }\n options.onResolve?.({ key, locale, value, status: 'miss' });\n return value;\n }\n const value = formatNodes(parse(hit.msg), { locale, params, formatters });\n options.onResolve?.({\n key,\n locale,\n value,\n status: hit.from === locale ? 'hit' : 'fallback',\n from: hit.from,\n });\n return value;\n }\n\n function tagged(strings: TemplateStringsArray, values: unknown[]): string {\n let out = strings[0] ?? '';\n for (let i = 0; i < values.length; i++) {\n out += autoFormat(values[i], locale) + (strings[i + 1] ?? '');\n }\n return out;\n }\n\n function notify(): void {\n version += 1;\n for (const fn of listeners) fn();\n }\n\n const t = ((first: unknown, ...rest: unknown[]): string => {\n if (isTemplateStrings(first)) return tagged(first, rest);\n return translate(first as string, rest[0] as Params | undefined);\n }) as TFunction<D>;\n\n t.id =\n () =>\n (strings: TemplateStringsArray, ...values: unknown[]) =>\n tagged(strings, values);\n\n function pendingLoader(target: string): string | undefined {\n const parts = target.split('-');\n while (parts.length > 0) {\n const candidate = parts.join('-');\n if (loaders[candidate] && !loaded.has(candidate)) return candidate;\n if (loaders[candidate]) return undefined;\n parts.pop();\n }\n return undefined;\n }\n\n function loadLocale(target: string): Promise<void> {\n const pending = pendingLoader(target);\n if (!pending) return Promise.resolve();\n const running = inFlight.get(pending);\n if (running) return running;\n const load = loaders[pending]!()\n .then((mod) => {\n loaded.add(pending);\n inFlight.delete(pending);\n addMessages(\n pending,\n 'default' in mod ? (mod.default as MessageTree) : (mod as MessageTree),\n );\n })\n .catch((error: unknown) => {\n inFlight.delete(pending);\n throw error;\n });\n inFlight.set(pending, load);\n return load;\n }\n\n function addMessages(loc: string, messages: MessageTree): void {\n dict[loc] = { ...dict[loc], ...flatten(messages) };\n notify();\n }\n\n return {\n get locale() {\n return locale;\n },\n get locales() {\n return [...new Set([...Object.keys(dict), ...Object.keys(loaders)])];\n },\n get version() {\n return version;\n },\n t,\n setLocale(next: string) {\n // auto-load pending catalog; UI re-renders when it lands\n if (pendingLoader(next)) {\n void loadLocale(next).catch(() => {\n if (!warned.has(`load:${next}`)) {\n warned.add(`load:${next}`);\n console.warn(`[verbaly] failed to load catalog for \"${next}\"`);\n }\n });\n }\n if (next === locale) return;\n locale = next;\n chainCache = null;\n notify();\n },\n loadLocale,\n addMessages,\n subscribe(listener: () => void) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n has(key: string) {\n return lookup(key) !== undefined;\n },\n inspect(key: string) {\n const hit = lookup(key);\n return hit ? { locale: hit.from, source: hit.msg } : undefined;\n },\n };\n}\n\nfunction isTemplateStrings(value: unknown): value is TemplateStringsArray {\n return Array.isArray(value) && 'raw' in value;\n}\n\nfunction detectLocale(): string {\n // gate on document, not navigator — Node 21+ exposes a global navigator (OS locale)\n return typeof document !== 'undefined' && typeof navigator !== 'undefined' && navigator.language\n ? navigator.language\n : 'en';\n}\n","// Named-tag tokenizer for <Trans>\nexport type TagNode = string | { name: string; children: TagNode[] };\n\nconst TAG = /<(\\/?)([a-zA-Z][\\w-]*)(\\/?)>/g;\n\nexport function parseTags(text: string): TagNode[] {\n const re = new RegExp(TAG.source, 'g');\n const root: TagNode[] = [];\n const stack: { name: string; children: TagNode[] }[] = [];\n const top = (): TagNode[] => (stack.length ? stack[stack.length - 1]!.children : root);\n const pushText = (s: string): void => {\n if (s) top().push(s);\n };\n\n let last = 0;\n let m: RegExpExecArray | null;\n while ((m = re.exec(text)) !== null) {\n const [full, closing, name, selfClose] = m;\n pushText(text.slice(last, m.index));\n last = m.index + full.length;\n\n if (selfClose) {\n top().push({ name: name!, children: [] });\n } else if (closing) {\n if (stack.length && stack[stack.length - 1]!.name === name) {\n const node = stack.pop()!;\n top().push(node);\n } else {\n pushText(full); // stray closing tag → literal\n }\n } else {\n stack.push({ name: name!, children: [] });\n }\n }\n pushText(text.slice(last));\n\n // unclosed opens: drop wrapper\n while (stack.length) {\n const node = stack.pop()!;\n top().push(...node.children);\n }\n return root;\n}\n","import { parseTags, type TagNode } from './tags';\nimport type { DictionaryInput, Params, Verbaly } from './types';\n\n// hrefs come from the caller, never from messages\nexport type RichLink = string | { href: string; target?: string; rel?: string };\n\nexport interface BindDomOptions {\n root?: ParentNode;\n attribute?: string;\n richTags?: string[];\n richLinks?: Record<string, RichLink>;\n}\n\nconst UNSAFE_HREF = /^\\s*(javascript|data|vbscript):/i;\n\nexport function safeHref(href: string): string | undefined {\n if (UNSAFE_HREF.test(href)) {\n console.warn(`[verbaly] blocked unsafe href: ${href}`);\n return undefined;\n }\n return href;\n}\n\n// phrasing-only, attribute-less → XSS-safe\nexport const RICH_TAGS = [\n 'em',\n 'strong',\n 'code',\n 'b',\n 'i',\n 'u',\n 's',\n 'small',\n 'mark',\n 'sub',\n 'sup',\n 'span',\n 'kbd',\n 'abbr',\n 'br',\n 'wbr',\n];\n\nexport function bindDom<D extends DictionaryInput>(\n instance: Verbaly<D>,\n options: BindDomOptions = {},\n): () => void {\n if (typeof document === 'undefined') {\n throw new Error('[verbaly] bindDom requires a DOM');\n }\n const t = instance.t as unknown as (key: string, params?: Params) => string;\n const root = options.root ?? document.body;\n const attr = options.attribute ?? 'data-verbaly';\n const argsAttr = `${attr}-args`;\n const attrsAttr = `${attr}-attr`;\n const richAttr = `${attr}-rich`;\n const linksAttr = `${attr}-links`;\n const richTags = new Set(options.richTags ?? RICH_TAGS);\n const globalLinks = options.richLinks;\n const argsCache = new WeakMap<Element, { raw: string | null; params: Params | undefined }>();\n const linksCache = new WeakMap<\n Element,\n { raw: string | null; links: Record<string, RichLink> | undefined }\n >();\n\n function cachedArgs(el: Element): Params | undefined {\n const raw = el.getAttribute(argsAttr);\n const hit = argsCache.get(el);\n if (hit && hit.raw === raw) return hit.params;\n const params = parseArgs(raw);\n argsCache.set(el, { raw, params });\n return params;\n }\n\n function cachedLinks(el: Element): Record<string, RichLink> | undefined {\n const raw = el.getAttribute(linksAttr);\n if (!raw) return globalLinks;\n const hit = linksCache.get(el);\n if (hit && hit.raw === raw) return hit.links;\n const own = parseArgs(raw) as Record<string, RichLink> | undefined;\n const links = own ? (globalLinks ? { ...globalLinks, ...own } : own) : globalLinks;\n linksCache.set(el, { raw, links });\n return links;\n }\n\n function renderRich(\n el: Element,\n nodes: TagNode[],\n links: Record<string, RichLink> | undefined,\n ): void {\n for (const node of nodes) {\n if (typeof node === 'string') {\n el.append(node);\n } else if (links?.[node.name] !== undefined) {\n const link = links[node.name]!;\n const { href, target, rel }: Exclude<RichLink, string> =\n typeof link === 'string' ? { href: link } : link;\n const a = el.ownerDocument.createElement('a');\n const safe = safeHref(href);\n if (safe !== undefined) a.setAttribute('href', safe);\n if (target) a.setAttribute('target', target);\n if (rel) a.setAttribute('rel', rel);\n renderRich(a, node.children, links);\n el.append(a);\n } else if (richTags.has(node.name)) {\n const child = el.ownerDocument.createElement(node.name);\n renderRich(child, node.children, links);\n el.append(child);\n } else {\n renderRich(el, node.children, links); // unknown tag → unwrap\n }\n }\n }\n\n function render(el: Element): void {\n const args = cachedArgs(el);\n const key = el.getAttribute(attr);\n if (key) {\n const text = t(key, args);\n if (el.hasAttribute(richAttr)) {\n el.textContent = '';\n renderRich(el, parseTags(text), cachedLinks(el));\n } else {\n el.textContent = text;\n }\n }\n\n const attrMap = parseArgs(el.getAttribute(attrsAttr));\n if (attrMap) {\n for (const [name, attrKey] of Object.entries(attrMap)) {\n if (typeof attrKey !== 'string' || name.toLowerCase().startsWith('on')) continue;\n el.setAttribute(name, t(attrKey, args));\n }\n }\n }\n\n const selector = `[${attr}], [${attrsAttr}]`;\n\n function renderAll(scope: ParentNode | Element): void {\n if (scope instanceof Element && scope.matches(selector)) render(scope);\n for (const el of scope.querySelectorAll(selector)) render(el);\n }\n\n renderAll(root);\n const unsubscribe = instance.subscribe(() => renderAll(root));\n\n const observer = new MutationObserver((records) => {\n for (const record of records) {\n if (record.type === 'attributes' && record.target instanceof Element) {\n render(record.target);\n } else if (record.type === 'childList') {\n for (const node of record.addedNodes) {\n if (node instanceof Element) renderAll(node);\n }\n }\n }\n });\n\n observer.observe(root instanceof Document ? root.documentElement : (root as Node), {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [attr, argsAttr, attrsAttr, richAttr, linksAttr],\n });\n\n return () => {\n unsubscribe();\n observer.disconnect();\n };\n}\n\nfunction parseArgs(raw: string | null): Params | undefined {\n if (!raw) return undefined;\n try {\n return JSON.parse(raw) as Params;\n } catch {\n console.warn(`[verbaly] invalid args JSON: ${raw}`);\n return undefined;\n }\n}\n","// locale bootstrap helpers (SSR-safe)\nexport interface ResolveLocaleOptions {\n supported: string[];\n fallback?: string;\n storageKey?: string | false;\n}\n\nconst DEFAULT_KEY = 'verbaly-locale';\n\nexport function resolveLocale(options: ResolveLocaleOptions): string {\n const { supported, fallback = supported[0] ?? 'en', storageKey = DEFAULT_KEY } = options;\n\n if (storageKey) {\n const stored = getStorage()?.getItem(storageKey);\n const match = stored && matchSupported(stored, supported);\n if (match) return match;\n }\n\n for (const lang of preferredLanguages()) {\n const match = matchSupported(lang, supported);\n if (match) return match;\n }\n\n return fallback;\n}\n\n// exact, then BCP-47 base (es-PE → es)\nfunction matchSupported(lang: string, supported: string[]): string | undefined {\n if (supported.includes(lang)) return lang;\n const base = lang.split('-')[0]!;\n return supported.includes(base) ? base : undefined;\n}\n\n// server-side Accept-Language negotiation (q-values, case-insensitive, BCP-47 base)\nexport function negotiateLocale(\n header: string | null | undefined,\n supported: string[],\n fallback: string = supported[0] ?? 'en',\n): string {\n if (!header) return fallback;\n\n const ranges: { tag: string; q: number }[] = [];\n for (const part of header.split(',')) {\n const [rawTag, ...params] = part.trim().split(';');\n const tag = rawTag?.trim();\n if (!tag || tag === '*') continue;\n let q = 1;\n for (const param of params) {\n const [name, value] = param.split('=');\n if (name?.trim().toLowerCase() === 'q') {\n const parsed = Number(value?.trim());\n q = Number.isFinite(parsed) ? parsed : 1;\n }\n }\n if (q > 0) ranges.push({ tag, q });\n }\n // stable sort — ties keep header order\n ranges.sort((a, b) => b.q - a.q);\n\n for (const { tag } of ranges) {\n const match = matchSupportedLoose(tag, supported);\n if (match) return match;\n }\n return fallback;\n}\n\n// case-insensitive matchSupported (headers arrive as en-US; configs as en)\nfunction matchSupportedLoose(lang: string, supported: string[]): string | undefined {\n const lower = lang.toLowerCase();\n const exact = supported.find((s) => s.toLowerCase() === lower);\n if (exact) return exact;\n const base = lower.split('-')[0]!;\n return supported.find((s) => s.toLowerCase() === base);\n}\n\nexport function persistLocale(locale: string, storageKey: string | false = DEFAULT_KEY): void {\n if (storageKey) getStorage()?.setItem(storageKey, locale);\n if (typeof document !== 'undefined') document.documentElement.lang = locale;\n}\n\nfunction preferredLanguages(): readonly string[] {\n // require document — Node 21+ has a global navigator whose language is the OS, not a user\n if (typeof document === 'undefined' || typeof navigator === 'undefined') return [];\n return navigator.languages?.length ? navigator.languages : [navigator.language];\n}\n\nfunction getStorage(): Storage | null {\n try {\n return typeof localStorage === 'undefined' ? null : localStorage;\n } catch {\n return null; // blocked storage (privacy mode)\n }\n}\n"],"mappings":";;AAEA,SAAgB,QACd,MACA,SAAS,IACT,MAA8B,CAAC,GACP;CACxB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAAI,GAAG;EAC/C,MAAM,OAAO,SAAS,GAAG,OAAO,GAAG,QAAQ;EAC3C,IAAI,OAAO,UAAU,UAAU,IAAI,QAAQ;OACtC,QAAQ,OAAO,MAAM,GAAG;CAC/B;CACA,OAAO;AACT;;;ACbA,MAAM,YAAY;AAElB,MAAM,0BAAU,IAAI,IAA+B;AACnD,MAAM,2BAAW,IAAI,IAAiC;AACtD,MAAM,0BAAU,IAAI,IAA8B;AAClD,MAAM,2BAAW,IAAI,IAAqC;AAC1D,MAAM,0BAAU,IAAI,IAA6B;AAEjD,SAAS,OAAU,OAAuB,KAAa,MAAkB;CACvE,IAAI,MAAM,MAAM,IAAI,GAAG;CACvB,IAAI,CAAC,KAAK;EACR,IAAI,MAAM,QAAQ,WAAW,MAAM,OAAO,MAAM,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAe;EAC7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AW,CAAC,EAAE,QAAQ,YAAY,MAAM;CACxD,IAAI,OAAO,aAAa,aAAa,SAAS,gBAAgB,OAAO;AACvE;AAEA,SAAS,qBAAwC;CAE/C,IAAI,OAAO,aAAa,eAAe,OAAO,cAAc,aAAa,OAAO,CAAC;CACjF,OAAO,UAAU,WAAW,SAAS,UAAU,YAAY,CAAC,UAAU,QAAQ;AAChF;AAEA,SAAS,aAA6B;CACpC,IAAI;EACF,OAAO,OAAO,iBAAiB,cAAc,OAAO;CACtD,QAAQ;EACN,OAAO;CACT;AACF"}
|
package/dist/index.d.cts
CHANGED
|
@@ -25,6 +25,7 @@ interface ResolveLocaleOptions {
|
|
|
25
25
|
storageKey?: string | false;
|
|
26
26
|
}
|
|
27
27
|
declare function resolveLocale(options: ResolveLocaleOptions): string;
|
|
28
|
+
declare function negotiateLocale(header: string | null | undefined, supported: string[], fallback?: string): string;
|
|
28
29
|
declare function persistLocale(locale: string, storageKey?: string | false): void;
|
|
29
30
|
//#endregion
|
|
30
31
|
//#region src/parse.d.ts
|
|
@@ -54,5 +55,5 @@ type TagNode = string | {
|
|
|
54
55
|
};
|
|
55
56
|
declare function parseTags(text: string): TagNode[];
|
|
56
57
|
//#endregion
|
|
57
|
-
export { type BindDomOptions, type DictionaryInput, type FlatKeys, type Formatter, type KeysOf, type LocaleLoader, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, RICH_TAGS, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type TArgs, type TFunction, type TagNode, type Verbaly, type VerbalyOptions, bindDom, createVerbaly, flatten, parse, parseTags, persistLocale, resolveLocale, safeHref };
|
|
58
|
+
export { type BindDomOptions, type DictionaryInput, type FlatKeys, type Formatter, type KeysOf, type LocaleLoader, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, RICH_TAGS, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type TArgs, type TFunction, type TagNode, type Verbaly, type VerbalyOptions, bindDom, createVerbaly, flatten, negotiateLocale, parse, parseTags, persistLocale, resolveLocale, safeHref };
|
|
58
59
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ interface ResolveLocaleOptions {
|
|
|
25
25
|
storageKey?: string | false;
|
|
26
26
|
}
|
|
27
27
|
declare function resolveLocale(options: ResolveLocaleOptions): string;
|
|
28
|
+
declare function negotiateLocale(header: string | null | undefined, supported: string[], fallback?: string): string;
|
|
28
29
|
declare function persistLocale(locale: string, storageKey?: string | false): void;
|
|
29
30
|
//#endregion
|
|
30
31
|
//#region src/parse.d.ts
|
|
@@ -54,5 +55,5 @@ type TagNode = string | {
|
|
|
54
55
|
};
|
|
55
56
|
declare function parseTags(text: string): TagNode[];
|
|
56
57
|
//#endregion
|
|
57
|
-
export { type BindDomOptions, type DictionaryInput, type FlatKeys, type Formatter, type KeysOf, type LocaleLoader, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, RICH_TAGS, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type TArgs, type TFunction, type TagNode, type Verbaly, type VerbalyOptions, bindDom, createVerbaly, flatten, parse, parseTags, persistLocale, resolveLocale, safeHref };
|
|
58
|
+
export { type BindDomOptions, type DictionaryInput, type FlatKeys, type Formatter, type KeysOf, type LocaleLoader, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, RICH_TAGS, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type TArgs, type TFunction, type TagNode, type Verbaly, type VerbalyOptions, bindDom, createVerbaly, flatten, negotiateLocale, parse, parseTags, persistLocale, resolveLocale, safeHref };
|
|
58
59
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -817,6 +817,40 @@ function matchSupported(lang, supported) {
|
|
|
817
817
|
const base = lang.split("-")[0];
|
|
818
818
|
return supported.includes(base) ? base : void 0;
|
|
819
819
|
}
|
|
820
|
+
function negotiateLocale(header, supported, fallback = supported[0] ?? "en") {
|
|
821
|
+
if (!header) return fallback;
|
|
822
|
+
const ranges = [];
|
|
823
|
+
for (const part of header.split(",")) {
|
|
824
|
+
const [rawTag, ...params] = part.trim().split(";");
|
|
825
|
+
const tag = rawTag?.trim();
|
|
826
|
+
if (!tag || tag === "*") continue;
|
|
827
|
+
let q = 1;
|
|
828
|
+
for (const param of params) {
|
|
829
|
+
const [name, value] = param.split("=");
|
|
830
|
+
if (name?.trim().toLowerCase() === "q") {
|
|
831
|
+
const parsed = Number(value?.trim());
|
|
832
|
+
q = Number.isFinite(parsed) ? parsed : 1;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
if (q > 0) ranges.push({
|
|
836
|
+
tag,
|
|
837
|
+
q
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
ranges.sort((a, b) => b.q - a.q);
|
|
841
|
+
for (const { tag } of ranges) {
|
|
842
|
+
const match = matchSupportedLoose(tag, supported);
|
|
843
|
+
if (match) return match;
|
|
844
|
+
}
|
|
845
|
+
return fallback;
|
|
846
|
+
}
|
|
847
|
+
function matchSupportedLoose(lang, supported) {
|
|
848
|
+
const lower = lang.toLowerCase();
|
|
849
|
+
const exact = supported.find((s) => s.toLowerCase() === lower);
|
|
850
|
+
if (exact) return exact;
|
|
851
|
+
const base = lower.split("-")[0];
|
|
852
|
+
return supported.find((s) => s.toLowerCase() === base);
|
|
853
|
+
}
|
|
820
854
|
function persistLocale(locale, storageKey = DEFAULT_KEY) {
|
|
821
855
|
if (storageKey) getStorage()?.setItem(storageKey, locale);
|
|
822
856
|
if (typeof document !== "undefined") document.documentElement.lang = locale;
|
|
@@ -833,6 +867,6 @@ function getStorage() {
|
|
|
833
867
|
}
|
|
834
868
|
}
|
|
835
869
|
//#endregion
|
|
836
|
-
export { RICH_TAGS, bindDom, createVerbaly, flatten, parse, parseTags, persistLocale, resolveLocale, safeHref };
|
|
870
|
+
export { RICH_TAGS, bindDom, createVerbaly, flatten, negotiateLocale, parse, parseTags, persistLocale, resolveLocale, safeHref };
|
|
837
871
|
|
|
838
872
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/flatten.ts","../src/intl.ts","../src/format.ts","../src/icu.ts","../src/parse.ts","../src/instance.ts","../src/tags.ts","../src/dom.ts","../src/locale.ts"],"sourcesContent":["import type { MessageTree } from './types';\n\nexport function flatten(\n tree: MessageTree,\n prefix = '',\n out: Record<string, string> = {},\n): Record<string, string> {\n for (const [key, value] of Object.entries(tree)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'string') out[path] = value;\n else flatten(value, path, out);\n }\n return out;\n}\n","const CACHE_CAP = 200; // dynamic locales/options can't grow unbounded\n\nconst nfCache = new Map<string, Intl.NumberFormat>();\nconst dtfCache = new Map<string, Intl.DateTimeFormat>();\nconst prCache = new Map<string, Intl.PluralRules>();\nconst rtfCache = new Map<string, Intl.RelativeTimeFormat>();\nconst lfCache = new Map<string, Intl.ListFormat>();\n\nfunction cached<T>(cache: Map<string, T>, key: string, make: () => T): T {\n let hit = cache.get(key);\n if (!hit) {\n if (cache.size >= CACHE_CAP) cache.delete(cache.keys().next().value as string);\n hit = make();\n cache.set(key, hit);\n }\n return hit;\n}\n\nexport function numberFormat(\n locale: string,\n options?: Intl.NumberFormatOptions,\n): Intl.NumberFormat {\n const key = locale + (options ? JSON.stringify(options) : '');\n return cached(nfCache, key, () => new Intl.NumberFormat(locale, options));\n}\n\nexport function dateTimeFormat(\n locale: string,\n options?: Intl.DateTimeFormatOptions,\n): Intl.DateTimeFormat {\n const key = locale + (options ? JSON.stringify(options) : '');\n return cached(dtfCache, key, () => new Intl.DateTimeFormat(locale, options));\n}\n\nexport function pluralRules(\n locale: string,\n type: Intl.PluralRuleType = 'cardinal',\n): Intl.PluralRules {\n return cached(prCache, locale + type, () => new Intl.PluralRules(locale, { type }));\n}\n\nexport function relativeTimeFormat(locale: string): Intl.RelativeTimeFormat {\n return cached(rtfCache, locale, () => new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }));\n}\n\nexport function listFormat(locale: string, type: Intl.ListFormatType): Intl.ListFormat {\n return cached(lfCache, locale + type, () => new Intl.ListFormat(locale, { type }));\n}\n","import { dateTimeFormat, listFormat, numberFormat, pluralRules, relativeTimeFormat } from './intl';\nimport type { MessageNode, ParamNode } from './parse';\nimport type { Formatter, Params } from './types';\n\ninterface FormatContext {\n locale: string;\n params: Params | undefined;\n formatters: Record<string, Formatter>;\n hashValue?: unknown;\n}\n\nexport function formatNodes(nodes: MessageNode[], ctx: FormatContext): string {\n let out = '';\n for (const node of nodes) {\n if (node.kind === 'text') out += node.value;\n else if (node.kind === 'hash') out += autoFormat(ctx.hashValue, ctx.locale);\n else out += formatParam(node, ctx);\n }\n return out;\n}\n\nfunction formatParam(node: ParamNode, ctx: FormatContext): string {\n const value = ctx.params?.[node.name];\n if (value === undefined) return `{${node.name}}`;\n\n if (node.variants) {\n const chosen = pickVariant(node.variants, value, ctx.locale, node.ordinal);\n if (!chosen) return '';\n return formatNodes(chosen, { ...ctx, hashValue: value });\n }\n if (node.format) return applyFormat(value, node.format, node.arg, ctx);\n return autoFormat(value, ctx.locale);\n}\n\nfunction pickVariant(\n variants: [string, MessageNode[]][],\n value: unknown,\n locale: string,\n ordinal?: boolean,\n): MessageNode[] | undefined {\n const raw = String(value);\n if (typeof value === 'number') {\n for (const [key, nodes] of variants) if (key === `=${raw}`) return nodes;\n const category = pluralRules(locale, ordinal ? 'ordinal' : 'cardinal').select(value);\n for (const [key, nodes] of variants) if (key === category) return nodes;\n } else {\n for (const [key, nodes] of variants) if (key === raw) return nodes;\n }\n for (const [key, nodes] of variants) if (key === 'other') return nodes;\n return undefined;\n}\n\nfunction applyFormat(\n value: unknown,\n format: string,\n arg: string | undefined,\n ctx: FormatContext,\n): string {\n const custom = ctx.formatters[format];\n if (custom) return custom(value, ctx.locale, arg);\n\n const { locale } = ctx;\n switch (format) {\n case 'number':\n return numberFormat(locale).format(Number(value));\n case 'integer':\n return numberFormat(locale, { maximumFractionDigits: 0 }).format(Number(value));\n case 'percent':\n return numberFormat(locale, { style: 'percent' }).format(Number(value));\n case 'currency':\n if (!arg) return String(value);\n return numberFormat(locale, { style: 'currency', currency: arg }).format(Number(value));\n case 'date':\n return dateTimeFormat(\n locale,\n arg ? { dateStyle: arg as Intl.DateTimeFormatOptions['dateStyle'] } : undefined,\n ).format(toDate(value));\n case 'time':\n return dateTimeFormat(locale, {\n timeStyle: (arg ?? 'short') as Intl.DateTimeFormatOptions['timeStyle'],\n }).format(toDate(value));\n case 'relative':\n return formatRelative(value, arg, locale);\n case 'list': {\n if (!Array.isArray(value)) return String(value);\n const type = arg === 'or' ? 'disjunction' : arg === 'unit' ? 'unit' : 'conjunction';\n return listFormat(locale, type).format(value.map((item) => autoFormat(item, locale)));\n }\n case 'unit':\n if (!arg) return String(value);\n try {\n return numberFormat(locale, { style: 'unit', unit: arg }).format(Number(value));\n } catch {\n warnOnce(`invalid unit \"${arg}\"`);\n return String(value);\n }\n default:\n warnOnce(`unknown format \"${format}\"`);\n return String(value);\n }\n}\n\n// seconds per unit, largest first (auto pick)\nconst REL_UNITS: [Intl.RelativeTimeFormatUnit, number][] = [\n ['year', 31536000],\n ['month', 2592000],\n ['week', 604800],\n ['day', 86400],\n ['hour', 3600],\n ['minute', 60],\n ['second', 1],\n];\n\nfunction formatRelative(value: unknown, arg: string | undefined, locale: string): string {\n try {\n if (typeof value === 'number' && arg) {\n return relativeTimeFormat(locale).format(value, arg as Intl.RelativeTimeFormatUnit);\n }\n if (value instanceof Date) {\n const diffSec = (value.getTime() - Date.now()) / 1000;\n if (arg) {\n const per = REL_UNITS.find(([unit]) => unit === arg)?.[1];\n if (!per) throw new RangeError(arg);\n return relativeTimeFormat(locale).format(\n Math.round(diffSec / per),\n arg as Intl.RelativeTimeFormatUnit,\n );\n }\n const [unit, per] = REL_UNITS.find(([, s]) => Math.abs(diffSec) >= s) ?? ['second', 1];\n return relativeTimeFormat(locale).format(Math.round(diffSec / per), unit);\n }\n } catch {\n warnOnce(`invalid relative unit \"${arg}\"`);\n }\n return String(value);\n}\n\nconst warned = new Set<string>();\nfunction warnOnce(msg: string): void {\n if (warned.has(msg)) return;\n warned.add(msg);\n console.warn(`[verbaly] ${msg}`);\n}\n\nexport function autoFormat(value: unknown, locale: string): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'number') return numberFormat(locale).format(value);\n if (value instanceof Date) return dateTimeFormat(locale).format(value);\n return String(value);\n}\n\nfunction toDate(value: unknown): Date {\n return value instanceof Date ? value : new Date(value as string | number);\n}\n","import type { MessageNode, ParamNode } from './parse';\n\n// ICU escape-hatch → native MessageNode AST\nconst ICU_ARG = /\\{\\s*[a-zA-Z0-9_]+\\s*,\\s*(?:plural|selectordinal|select|number|date|time)\\b/;\n\nexport function isIcu(message: string): boolean {\n return ICU_ARG.test(message);\n}\n\nexport function parseIcu(message: string): MessageNode[] {\n let i = 0;\n const at = (): string => message.charAt(i);\n const skipWs = (): void => {\n while (i < message.length && /\\s/.test(at())) i++;\n };\n const readIdent = (): string => {\n let s = '';\n while (i < message.length && /[a-zA-Z0-9_]/.test(at())) s += message[i++];\n return s;\n };\n\n function parseBody(inPlural: boolean): MessageNode[] {\n const nodes: MessageNode[] = [];\n let buf = '';\n const flush = (): void => {\n if (buf) nodes.push({ kind: 'text', value: buf });\n buf = '';\n };\n while (i < message.length) {\n const ch = at();\n if (ch === '}') break;\n if (ch === '{') {\n flush();\n nodes.push(parseArg());\n } else if (ch === '#' && inPlural) {\n flush();\n nodes.push({ kind: 'hash' });\n i++;\n } else if (ch === \"'\") {\n buf += readQuoted();\n } else {\n buf += ch;\n i++;\n }\n }\n flush();\n return nodes;\n }\n\n // ICU apostrophe quoting\n function readQuoted(): string {\n i++; // opening '\n if (at() === \"'\") {\n i++;\n return \"'\";\n }\n const next = at();\n if (next !== '{' && next !== '}' && next !== '#') return \"'\"; // lone apostrophe\n let out = '';\n while (i < message.length) {\n if (at() === \"'\") {\n if (message.charAt(i + 1) === \"'\") {\n out += \"'\";\n i += 2;\n continue;\n }\n i++; // closing '\n return out;\n }\n out += message[i++];\n }\n return out; // unterminated\n }\n\n function parseArg(): MessageNode {\n i++; // {\n skipWs();\n const name = readIdent();\n skipWs();\n if (at() === '}') {\n i++;\n return { kind: 'param', name };\n }\n if (at() === ',') i++;\n skipWs();\n const type = readIdent();\n const node: ParamNode = { kind: 'param', name };\n\n if (type === 'number' || type === 'date' || type === 'time') {\n skipWs();\n let style = '';\n if (at() === ',') {\n i++;\n skipWs();\n while (i < message.length && at() !== '}' && at() !== ',') style += message[i++];\n style = style.trim();\n }\n if (type === 'number') {\n node.format =\n style === 'integer'\n ? 'integer'\n : style === 'percent'\n ? 'percent'\n : style === 'currency'\n ? 'currency'\n : 'number';\n } else {\n node.format = type;\n if (style) node.arg = style;\n }\n skipToClose();\n return node;\n }\n\n if (type === 'plural' || type === 'selectordinal' || type === 'select') {\n if (type === 'selectordinal') node.ordinal = true;\n const variants: [string, MessageNode[]][] = [];\n skipWs();\n if (at() === ',') i++; // comma after the keyword\n skipWs();\n if (type !== 'select' && message.startsWith('offset:', i)) {\n i += 7;\n skipWs();\n while (i < message.length && /[0-9]/.test(at())) i++; // offset parsed, not applied (v1)\n skipWs();\n }\n while (i < message.length && at() !== '}') {\n const selector = readSelector();\n skipWs();\n if (at() !== '{') break;\n i++; // {\n const body = parseBody(type !== 'select');\n if (at() === '}') i++;\n variants.push([selector, body]);\n skipWs();\n }\n if (at() === '}') i++;\n node.variants = variants;\n return node;\n }\n\n // unknown type → simple param\n skipToClose();\n return node;\n }\n\n function readSelector(): string {\n if (at() === '=') {\n let s = '=';\n i++;\n while (i < message.length && /[0-9]/.test(at())) s += message[i++];\n return s;\n }\n let s = '';\n while (i < message.length && !/[\\s{]/.test(at())) s += message[i++];\n return s;\n }\n\n function skipToClose(): void {\n while (i < message.length && at() !== '}') i++;\n if (at() === '}') i++;\n }\n\n return parseBody(false);\n}\n","import { isIcu, parseIcu } from './icu';\n\nexport type MessageNode = { kind: 'text'; value: string } | { kind: 'hash' } | ParamNode;\n\nexport interface ParamNode {\n kind: 'param';\n name: string;\n format?: string;\n arg?: string;\n ordinal?: boolean;\n variants?: [string, MessageNode[]][];\n}\n\nconst astCache = new Map<string, MessageNode[]>();\nconst AST_CACHE_MAX = 2000; // dynamic/CMS messages can't grow it unbounded\n\nexport function parse(message: string): MessageNode[] {\n let cached = astCache.get(message);\n if (!cached) {\n if (astCache.size >= AST_CACHE_MAX) astCache.clear();\n cached = isIcu(message) ? parseIcu(message) : parseMessage(message, false);\n astCache.set(message, cached);\n }\n return cached;\n}\n\nfunction parseMessage(input: string, inVariant: boolean): MessageNode[] {\n const nodes: MessageNode[] = [];\n let buf = '';\n let i = 0;\n\n const flush = () => {\n if (buf) nodes.push({ kind: 'text', value: buf });\n buf = '';\n };\n\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n buf += '{';\n i += 2;\n continue;\n }\n const close = findClose(input, i);\n if (close < 0) {\n buf += input.slice(i);\n break;\n }\n flush();\n nodes.push(parsePlaceholder(input.slice(i + 1, close)));\n i = close + 1;\n } else if (ch === '}' && input[i + 1] === '}') {\n buf += '}';\n i += 2;\n } else if (inVariant && ch === '#') {\n if (input[i + 1] === '#') {\n buf += '#';\n i += 2;\n } else {\n flush();\n nodes.push({ kind: 'hash' });\n i += 1;\n }\n } else {\n buf += ch;\n i += 1;\n }\n }\n flush();\n return nodes;\n}\n\nfunction findClose(input: string, open: number): number {\n let depth = 0;\n let i = open;\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n i += 2;\n continue;\n }\n depth += 1;\n } else if (ch === '}') {\n if (input[i + 1] === '}') {\n i += 2;\n continue;\n }\n depth -= 1;\n if (depth === 0) return i;\n }\n i += 1;\n }\n return -1;\n}\n\nfunction parsePlaceholder(inner: string): MessageNode {\n const segments = splitTop(inner);\n const head = (segments[0] ?? '').trim();\n if (!head) return { kind: 'text', value: `{${inner}}` };\n\n const colon = head.indexOf(':');\n const name = (colon < 0 ? head : head.slice(0, colon)).trim();\n if (!name) return { kind: 'text', value: `{${inner}}` };\n\n const node: ParamNode = { kind: 'param', name };\n\n if (colon >= 0) {\n const fmtRaw = head.slice(colon + 1).trim();\n const slash = fmtRaw.indexOf('/');\n node.format = (slash < 0 ? fmtRaw : fmtRaw.slice(0, slash)).trim();\n if (slash >= 0) node.arg = fmtRaw.slice(slash + 1).trim();\n }\n\n if (segments.length > 1) {\n node.variants = [];\n for (const seg of segments.slice(1)) {\n const sep = seg.indexOf(':');\n if (sep < 0) continue;\n const key = seg.slice(0, sep).trim();\n const body = seg.slice(sep + 1).trim();\n if (key) node.variants.push([key, parseMessage(body, true)]);\n }\n }\n return node;\n}\n\nfunction splitTop(input: string): string[] {\n const parts: string[] = [];\n let buf = '';\n let depth = 0;\n let i = 0;\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n buf += '{{';\n i += 2;\n continue;\n }\n depth += 1;\n buf += ch;\n } else if (ch === '}') {\n if (input[i + 1] === '}') {\n buf += '}}';\n i += 2;\n continue;\n }\n depth -= 1;\n buf += ch;\n } else if (ch === '|' && depth === 0) {\n if (input[i + 1] === '|') {\n buf += '|';\n i += 2;\n continue;\n }\n parts.push(buf);\n buf = '';\n } else {\n buf += ch;\n }\n i += 1;\n }\n parts.push(buf);\n return parts;\n}\n","import { flatten } from './flatten';\nimport { autoFormat, formatNodes } from './format';\nimport { parse } from './parse';\nimport type {\n DictionaryInput,\n MessageTree,\n Params,\n TFunction,\n Verbaly,\n VerbalyOptions,\n} from './types';\n\nexport function createVerbaly<const D extends DictionaryInput = DictionaryInput>(\n options: VerbalyOptions<D> = {},\n): Verbaly<D> {\n const dict: Record<string, Record<string, string>> = {};\n const listeners = new Set<() => void>();\n const formatters = options.formatters ?? {};\n const loaders = options.loaders ?? {};\n const loaded = new Set<string>();\n const inFlight = new Map<string, Promise<void>>();\n const warned = new Set<string>();\n const fallbacks = options.fallback\n ? Array.isArray(options.fallback)\n ? options.fallback\n : [options.fallback]\n : [];\n\n let locale = options.locale ?? detectLocale();\n let version = 0;\n let chainCache: string[] | null = null;\n\n if (options.messages) {\n for (const [loc, tree] of Object.entries(options.messages)) {\n dict[loc] = flatten(tree);\n }\n }\n\n function chain(): string[] {\n if (chainCache) return chainCache;\n const result: string[] = [];\n // narrow BCP-47 subtags\n const parts = locale.split('-');\n while (parts.length > 0) {\n result.push(parts.join('-'));\n parts.pop();\n }\n for (const fb of fallbacks) if (!result.includes(fb)) result.push(fb);\n chainCache = result;\n return result;\n }\n\n function lookup(key: string): { msg: string; from: string } | undefined {\n for (const loc of chain()) {\n const msg = dict[loc]?.[key];\n // '' = untranslated (extract scaffolds it) → keep falling back\n if (msg) return { msg, from: loc };\n }\n return undefined;\n }\n\n function translate(key: string, params: Params | undefined): string {\n const hit = lookup(key);\n if (hit === undefined) {\n const replacement = options.onMissing?.(key, locale);\n const value = typeof replacement === 'string' ? replacement : key;\n if (typeof replacement !== 'string' && !options.onMissing && !warned.has(key)) {\n warned.add(key);\n console.warn(`[verbaly] missing key \"${key}\" (${locale})`);\n }\n options.onResolve?.({ key, locale, value, status: 'miss' });\n return value;\n }\n const value = formatNodes(parse(hit.msg), { locale, params, formatters });\n options.onResolve?.({\n key,\n locale,\n value,\n status: hit.from === locale ? 'hit' : 'fallback',\n from: hit.from,\n });\n return value;\n }\n\n function tagged(strings: TemplateStringsArray, values: unknown[]): string {\n let out = strings[0] ?? '';\n for (let i = 0; i < values.length; i++) {\n out += autoFormat(values[i], locale) + (strings[i + 1] ?? '');\n }\n return out;\n }\n\n function notify(): void {\n version += 1;\n for (const fn of listeners) fn();\n }\n\n const t = ((first: unknown, ...rest: unknown[]): string => {\n if (isTemplateStrings(first)) return tagged(first, rest);\n return translate(first as string, rest[0] as Params | undefined);\n }) as TFunction<D>;\n\n t.id =\n () =>\n (strings: TemplateStringsArray, ...values: unknown[]) =>\n tagged(strings, values);\n\n function pendingLoader(target: string): string | undefined {\n const parts = target.split('-');\n while (parts.length > 0) {\n const candidate = parts.join('-');\n if (loaders[candidate] && !loaded.has(candidate)) return candidate;\n if (loaders[candidate]) return undefined;\n parts.pop();\n }\n return undefined;\n }\n\n function loadLocale(target: string): Promise<void> {\n const pending = pendingLoader(target);\n if (!pending) return Promise.resolve();\n const running = inFlight.get(pending);\n if (running) return running;\n const load = loaders[pending]!()\n .then((mod) => {\n loaded.add(pending);\n inFlight.delete(pending);\n addMessages(\n pending,\n 'default' in mod ? (mod.default as MessageTree) : (mod as MessageTree),\n );\n })\n .catch((error: unknown) => {\n inFlight.delete(pending);\n throw error;\n });\n inFlight.set(pending, load);\n return load;\n }\n\n function addMessages(loc: string, messages: MessageTree): void {\n dict[loc] = { ...dict[loc], ...flatten(messages) };\n notify();\n }\n\n return {\n get locale() {\n return locale;\n },\n get locales() {\n return [...new Set([...Object.keys(dict), ...Object.keys(loaders)])];\n },\n get version() {\n return version;\n },\n t,\n setLocale(next: string) {\n // auto-load pending catalog; UI re-renders when it lands\n if (pendingLoader(next)) {\n void loadLocale(next).catch(() => {\n if (!warned.has(`load:${next}`)) {\n warned.add(`load:${next}`);\n console.warn(`[verbaly] failed to load catalog for \"${next}\"`);\n }\n });\n }\n if (next === locale) return;\n locale = next;\n chainCache = null;\n notify();\n },\n loadLocale,\n addMessages,\n subscribe(listener: () => void) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n has(key: string) {\n return lookup(key) !== undefined;\n },\n inspect(key: string) {\n const hit = lookup(key);\n return hit ? { locale: hit.from, source: hit.msg } : undefined;\n },\n };\n}\n\nfunction isTemplateStrings(value: unknown): value is TemplateStringsArray {\n return Array.isArray(value) && 'raw' in value;\n}\n\nfunction detectLocale(): string {\n // gate on document, not navigator — Node 21+ exposes a global navigator (OS locale)\n return typeof document !== 'undefined' && typeof navigator !== 'undefined' && navigator.language\n ? navigator.language\n : 'en';\n}\n","// Named-tag tokenizer for <Trans>\nexport type TagNode = string | { name: string; children: TagNode[] };\n\nconst TAG = /<(\\/?)([a-zA-Z][\\w-]*)(\\/?)>/g;\n\nexport function parseTags(text: string): TagNode[] {\n const re = new RegExp(TAG.source, 'g');\n const root: TagNode[] = [];\n const stack: { name: string; children: TagNode[] }[] = [];\n const top = (): TagNode[] => (stack.length ? stack[stack.length - 1]!.children : root);\n const pushText = (s: string): void => {\n if (s) top().push(s);\n };\n\n let last = 0;\n let m: RegExpExecArray | null;\n while ((m = re.exec(text)) !== null) {\n const [full, closing, name, selfClose] = m;\n pushText(text.slice(last, m.index));\n last = m.index + full.length;\n\n if (selfClose) {\n top().push({ name: name!, children: [] });\n } else if (closing) {\n if (stack.length && stack[stack.length - 1]!.name === name) {\n const node = stack.pop()!;\n top().push(node);\n } else {\n pushText(full); // stray closing tag → literal\n }\n } else {\n stack.push({ name: name!, children: [] });\n }\n }\n pushText(text.slice(last));\n\n // unclosed opens: drop wrapper\n while (stack.length) {\n const node = stack.pop()!;\n top().push(...node.children);\n }\n return root;\n}\n","import { parseTags, type TagNode } from './tags';\nimport type { DictionaryInput, Params, Verbaly } from './types';\n\n// hrefs come from the caller, never from messages\nexport type RichLink = string | { href: string; target?: string; rel?: string };\n\nexport interface BindDomOptions {\n root?: ParentNode;\n attribute?: string;\n richTags?: string[];\n richLinks?: Record<string, RichLink>;\n}\n\nconst UNSAFE_HREF = /^\\s*(javascript|data|vbscript):/i;\n\nexport function safeHref(href: string): string | undefined {\n if (UNSAFE_HREF.test(href)) {\n console.warn(`[verbaly] blocked unsafe href: ${href}`);\n return undefined;\n }\n return href;\n}\n\n// phrasing-only, attribute-less → XSS-safe\nexport const RICH_TAGS = [\n 'em',\n 'strong',\n 'code',\n 'b',\n 'i',\n 'u',\n 's',\n 'small',\n 'mark',\n 'sub',\n 'sup',\n 'span',\n 'kbd',\n 'abbr',\n 'br',\n 'wbr',\n];\n\nexport function bindDom<D extends DictionaryInput>(\n instance: Verbaly<D>,\n options: BindDomOptions = {},\n): () => void {\n if (typeof document === 'undefined') {\n throw new Error('[verbaly] bindDom requires a DOM');\n }\n const t = instance.t as unknown as (key: string, params?: Params) => string;\n const root = options.root ?? document.body;\n const attr = options.attribute ?? 'data-verbaly';\n const argsAttr = `${attr}-args`;\n const attrsAttr = `${attr}-attr`;\n const richAttr = `${attr}-rich`;\n const linksAttr = `${attr}-links`;\n const richTags = new Set(options.richTags ?? RICH_TAGS);\n const globalLinks = options.richLinks;\n const argsCache = new WeakMap<Element, { raw: string | null; params: Params | undefined }>();\n const linksCache = new WeakMap<\n Element,\n { raw: string | null; links: Record<string, RichLink> | undefined }\n >();\n\n function cachedArgs(el: Element): Params | undefined {\n const raw = el.getAttribute(argsAttr);\n const hit = argsCache.get(el);\n if (hit && hit.raw === raw) return hit.params;\n const params = parseArgs(raw);\n argsCache.set(el, { raw, params });\n return params;\n }\n\n function cachedLinks(el: Element): Record<string, RichLink> | undefined {\n const raw = el.getAttribute(linksAttr);\n if (!raw) return globalLinks;\n const hit = linksCache.get(el);\n if (hit && hit.raw === raw) return hit.links;\n const own = parseArgs(raw) as Record<string, RichLink> | undefined;\n const links = own ? (globalLinks ? { ...globalLinks, ...own } : own) : globalLinks;\n linksCache.set(el, { raw, links });\n return links;\n }\n\n function renderRich(\n el: Element,\n nodes: TagNode[],\n links: Record<string, RichLink> | undefined,\n ): void {\n for (const node of nodes) {\n if (typeof node === 'string') {\n el.append(node);\n } else if (links?.[node.name] !== undefined) {\n const link = links[node.name]!;\n const { href, target, rel }: Exclude<RichLink, string> =\n typeof link === 'string' ? { href: link } : link;\n const a = el.ownerDocument.createElement('a');\n const safe = safeHref(href);\n if (safe !== undefined) a.setAttribute('href', safe);\n if (target) a.setAttribute('target', target);\n if (rel) a.setAttribute('rel', rel);\n renderRich(a, node.children, links);\n el.append(a);\n } else if (richTags.has(node.name)) {\n const child = el.ownerDocument.createElement(node.name);\n renderRich(child, node.children, links);\n el.append(child);\n } else {\n renderRich(el, node.children, links); // unknown tag → unwrap\n }\n }\n }\n\n function render(el: Element): void {\n const args = cachedArgs(el);\n const key = el.getAttribute(attr);\n if (key) {\n const text = t(key, args);\n if (el.hasAttribute(richAttr)) {\n el.textContent = '';\n renderRich(el, parseTags(text), cachedLinks(el));\n } else {\n el.textContent = text;\n }\n }\n\n const attrMap = parseArgs(el.getAttribute(attrsAttr));\n if (attrMap) {\n for (const [name, attrKey] of Object.entries(attrMap)) {\n if (typeof attrKey !== 'string' || name.toLowerCase().startsWith('on')) continue;\n el.setAttribute(name, t(attrKey, args));\n }\n }\n }\n\n const selector = `[${attr}], [${attrsAttr}]`;\n\n function renderAll(scope: ParentNode | Element): void {\n if (scope instanceof Element && scope.matches(selector)) render(scope);\n for (const el of scope.querySelectorAll(selector)) render(el);\n }\n\n renderAll(root);\n const unsubscribe = instance.subscribe(() => renderAll(root));\n\n const observer = new MutationObserver((records) => {\n for (const record of records) {\n if (record.type === 'attributes' && record.target instanceof Element) {\n render(record.target);\n } else if (record.type === 'childList') {\n for (const node of record.addedNodes) {\n if (node instanceof Element) renderAll(node);\n }\n }\n }\n });\n\n observer.observe(root instanceof Document ? root.documentElement : (root as Node), {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [attr, argsAttr, attrsAttr, richAttr, linksAttr],\n });\n\n return () => {\n unsubscribe();\n observer.disconnect();\n };\n}\n\nfunction parseArgs(raw: string | null): Params | undefined {\n if (!raw) return undefined;\n try {\n return JSON.parse(raw) as Params;\n } catch {\n console.warn(`[verbaly] invalid args JSON: ${raw}`);\n return undefined;\n }\n}\n","// locale bootstrap helpers (SSR-safe)\nexport interface ResolveLocaleOptions {\n supported: string[];\n fallback?: string;\n storageKey?: string | false;\n}\n\nconst DEFAULT_KEY = 'verbaly-locale';\n\nexport function resolveLocale(options: ResolveLocaleOptions): string {\n const { supported, fallback = supported[0] ?? 'en', storageKey = DEFAULT_KEY } = options;\n\n if (storageKey) {\n const stored = getStorage()?.getItem(storageKey);\n const match = stored && matchSupported(stored, supported);\n if (match) return match;\n }\n\n for (const lang of preferredLanguages()) {\n const match = matchSupported(lang, supported);\n if (match) return match;\n }\n\n return fallback;\n}\n\n// exact, then BCP-47 base (es-PE → es)\nfunction matchSupported(lang: string, supported: string[]): string | undefined {\n if (supported.includes(lang)) return lang;\n const base = lang.split('-')[0]!;\n return supported.includes(base) ? base : undefined;\n}\n\nexport function persistLocale(locale: string, storageKey: string | false = DEFAULT_KEY): void {\n if (storageKey) getStorage()?.setItem(storageKey, locale);\n if (typeof document !== 'undefined') document.documentElement.lang = locale;\n}\n\nfunction preferredLanguages(): readonly string[] {\n // require document — Node 21+ has a global navigator whose language is the OS, not a user\n if (typeof document === 'undefined' || typeof navigator === 'undefined') return [];\n return navigator.languages?.length ? navigator.languages : [navigator.language];\n}\n\nfunction getStorage(): Storage | null {\n try {\n return typeof localStorage === 'undefined' ? null : localStorage;\n } catch {\n return null; // blocked storage (privacy mode)\n }\n}\n"],"mappings":";AAEA,SAAgB,QACd,MACA,SAAS,IACT,MAA8B,CAAC,GACP;CACxB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAAI,GAAG;EAC/C,MAAM,OAAO,SAAS,GAAG,OAAO,GAAG,QAAQ;EAC3C,IAAI,OAAO,UAAU,UAAU,IAAI,QAAQ;OACtC,QAAQ,OAAO,MAAM,GAAG;CAC/B;CACA,OAAO;AACT;;;ACbA,MAAM,YAAY;AAElB,MAAM,0BAAU,IAAI,IAA+B;AACnD,MAAM,2BAAW,IAAI,IAAiC;AACtD,MAAM,0BAAU,IAAI,IAA8B;AAClD,MAAM,2BAAW,IAAI,IAAqC;AAC1D,MAAM,0BAAU,IAAI,IAA6B;AAEjD,SAAS,OAAU,OAAuB,KAAa,MAAkB;CACvE,IAAI,MAAM,MAAM,IAAI,GAAG;C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S;EAC5C,IAAI,OAAO,OAAO;CACpB;CAEA,OAAO;AACT;AAGA,SAAS,eAAe,MAAc,WAAyC;CAC7E,IAAI,UAAU,SAAS,IAAI,GAAG,OAAO;CACrC,MAAM,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC;CAC7B,OAAO,UAAU,SAAS,IAAI,IAAI,OAAO,KAAA;AAC3C;AAEA,SAAgB,cAAc,QAAgB,aAA6B,aAAmB;CAC5F,IAAI,YAAY,WAAW,CAAC,EAAE,QAAQ,YAAY,MAAM;CACxD,IAAI,OAAO,aAAa,aAAa,SAAS,gBAAgB,OAAO;AACvE;AAEA,SAAS,qBAAwC;CAE/C,IAAI,OAAO,aAAa,eAAe,OAAO,cAAc,aAAa,OAAO,CAAC;CACjF,OAAO,UAAU,WAAW,SAAS,UAAU,YAAY,CAAC,UAAU,QAAQ;AAChF;AAEA,SAAS,aAA6B;CACpC,IAAI;EACF,OAAO,OAAO,iBAAiB,cAAc,OAAO;CACtD,QAAQ;EACN,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/flatten.ts","../src/intl.ts","../src/format.ts","../src/icu.ts","../src/parse.ts","../src/instance.ts","../src/tags.ts","../src/dom.ts","../src/locale.ts"],"sourcesContent":["import type { MessageTree } from './types';\n\nexport function flatten(\n tree: MessageTree,\n prefix = '',\n out: Record<string, string> = {},\n): Record<string, string> {\n for (const [key, value] of Object.entries(tree)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'string') out[path] = value;\n else flatten(value, path, out);\n }\n return out;\n}\n","const CACHE_CAP = 200; // dynamic locales/options can't grow unbounded\n\nconst nfCache = new Map<string, Intl.NumberFormat>();\nconst dtfCache = new Map<string, Intl.DateTimeFormat>();\nconst prCache = new Map<string, Intl.PluralRules>();\nconst rtfCache = new Map<string, Intl.RelativeTimeFormat>();\nconst lfCache = new Map<string, Intl.ListFormat>();\n\nfunction cached<T>(cache: Map<string, T>, key: string, make: () => T): T {\n let hit = cache.get(key);\n if (!hit) {\n if (cache.size >= CACHE_CAP) cache.delete(cache.keys().next().value as string);\n hit = make();\n cache.set(key, hit);\n }\n return hit;\n}\n\nexport function numberFormat(\n locale: string,\n options?: Intl.NumberFormatOptions,\n): Intl.NumberFormat {\n const key = locale + (options ? JSON.stringify(options) : '');\n return cached(nfCache, key, () => new Intl.NumberFormat(locale, options));\n}\n\nexport function dateTimeFormat(\n locale: string,\n options?: Intl.DateTimeFormatOptions,\n): Intl.DateTimeFormat {\n const key = locale + (options ? JSON.stringify(options) : '');\n return cached(dtfCache, key, () => new Intl.DateTimeFormat(locale, options));\n}\n\nexport function pluralRules(\n locale: string,\n type: Intl.PluralRuleType = 'cardinal',\n): Intl.PluralRules {\n return cached(prCache, locale + type, () => new Intl.PluralRules(locale, { type }));\n}\n\nexport function relativeTimeFormat(locale: string): Intl.RelativeTimeFormat {\n return cached(rtfCache, locale, () => new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }));\n}\n\nexport function listFormat(locale: string, type: Intl.ListFormatType): Intl.ListFormat {\n return cached(lfCache, locale + type, () => new Intl.ListFormat(locale, { type }));\n}\n","import { dateTimeFormat, listFormat, numberFormat, pluralRules, relativeTimeFormat } from './intl';\nimport type { MessageNode, ParamNode } from './parse';\nimport type { Formatter, Params } from './types';\n\ninterface FormatContext {\n locale: string;\n params: Params | undefined;\n formatters: Record<string, Formatter>;\n hashValue?: unknown;\n}\n\nexport function formatNodes(nodes: MessageNode[], ctx: FormatContext): string {\n let out = '';\n for (const node of nodes) {\n if (node.kind === 'text') out += node.value;\n else if (node.kind === 'hash') out += autoFormat(ctx.hashValue, ctx.locale);\n else out += formatParam(node, ctx);\n }\n return out;\n}\n\nfunction formatParam(node: ParamNode, ctx: FormatContext): string {\n const value = ctx.params?.[node.name];\n if (value === undefined) return `{${node.name}}`;\n\n if (node.variants) {\n const chosen = pickVariant(node.variants, value, ctx.locale, node.ordinal);\n if (!chosen) return '';\n return formatNodes(chosen, { ...ctx, hashValue: value });\n }\n if (node.format) return applyFormat(value, node.format, node.arg, ctx);\n return autoFormat(value, ctx.locale);\n}\n\nfunction pickVariant(\n variants: [string, MessageNode[]][],\n value: unknown,\n locale: string,\n ordinal?: boolean,\n): MessageNode[] | undefined {\n const raw = String(value);\n if (typeof value === 'number') {\n for (const [key, nodes] of variants) if (key === `=${raw}`) return nodes;\n const category = pluralRules(locale, ordinal ? 'ordinal' : 'cardinal').select(value);\n for (const [key, nodes] of variants) if (key === category) return nodes;\n } else {\n for (const [key, nodes] of variants) if (key === raw) return nodes;\n }\n for (const [key, nodes] of variants) if (key === 'other') return nodes;\n return undefined;\n}\n\nfunction applyFormat(\n value: unknown,\n format: string,\n arg: string | undefined,\n ctx: FormatContext,\n): string {\n const custom = ctx.formatters[format];\n if (custom) return custom(value, ctx.locale, arg);\n\n const { locale } = ctx;\n switch (format) {\n case 'number':\n return numberFormat(locale).format(Number(value));\n case 'integer':\n return numberFormat(locale, { maximumFractionDigits: 0 }).format(Number(value));\n case 'percent':\n return numberFormat(locale, { style: 'percent' }).format(Number(value));\n case 'currency':\n if (!arg) return String(value);\n return numberFormat(locale, { style: 'currency', currency: arg }).format(Number(value));\n case 'date':\n return dateTimeFormat(\n locale,\n arg ? { dateStyle: arg as Intl.DateTimeFormatOptions['dateStyle'] } : undefined,\n ).format(toDate(value));\n case 'time':\n return dateTimeFormat(locale, {\n timeStyle: (arg ?? 'short') as Intl.DateTimeFormatOptions['timeStyle'],\n }).format(toDate(value));\n case 'relative':\n return formatRelative(value, arg, locale);\n case 'list': {\n if (!Array.isArray(value)) return String(value);\n const type = arg === 'or' ? 'disjunction' : arg === 'unit' ? 'unit' : 'conjunction';\n return listFormat(locale, type).format(value.map((item) => autoFormat(item, locale)));\n }\n case 'unit':\n if (!arg) return String(value);\n try {\n return numberFormat(locale, { style: 'unit', unit: arg }).format(Number(value));\n } catch {\n warnOnce(`invalid unit \"${arg}\"`);\n return String(value);\n }\n default:\n warnOnce(`unknown format \"${format}\"`);\n return String(value);\n }\n}\n\n// seconds per unit, largest first (auto pick)\nconst REL_UNITS: [Intl.RelativeTimeFormatUnit, number][] = [\n ['year', 31536000],\n ['month', 2592000],\n ['week', 604800],\n ['day', 86400],\n ['hour', 3600],\n ['minute', 60],\n ['second', 1],\n];\n\nfunction formatRelative(value: unknown, arg: string | undefined, locale: string): string {\n try {\n if (typeof value === 'number' && arg) {\n return relativeTimeFormat(locale).format(value, arg as Intl.RelativeTimeFormatUnit);\n }\n if (value instanceof Date) {\n const diffSec = (value.getTime() - Date.now()) / 1000;\n if (arg) {\n const per = REL_UNITS.find(([unit]) => unit === arg)?.[1];\n if (!per) throw new RangeError(arg);\n return relativeTimeFormat(locale).format(\n Math.round(diffSec / per),\n arg as Intl.RelativeTimeFormatUnit,\n );\n }\n const [unit, per] = REL_UNITS.find(([, s]) => Math.abs(diffSec) >= s) ?? ['second', 1];\n return relativeTimeFormat(locale).format(Math.round(diffSec / per), unit);\n }\n } catch {\n warnOnce(`invalid relative unit \"${arg}\"`);\n }\n return String(value);\n}\n\nconst warned = new Set<string>();\nfunction warnOnce(msg: string): void {\n if (warned.has(msg)) return;\n warned.add(msg);\n console.warn(`[verbaly] ${msg}`);\n}\n\nexport function autoFormat(value: unknown, locale: string): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'number') return numberFormat(locale).format(value);\n if (value instanceof Date) return dateTimeFormat(locale).format(value);\n return String(value);\n}\n\nfunction toDate(value: unknown): Date {\n return value instanceof Date ? value : new Date(value as string | number);\n}\n","import type { MessageNode, ParamNode } from './parse';\n\n// ICU escape-hatch → native MessageNode AST\nconst ICU_ARG = /\\{\\s*[a-zA-Z0-9_]+\\s*,\\s*(?:plural|selectordinal|select|number|date|time)\\b/;\n\nexport function isIcu(message: string): boolean {\n return ICU_ARG.test(message);\n}\n\nexport function parseIcu(message: string): MessageNode[] {\n let i = 0;\n const at = (): string => message.charAt(i);\n const skipWs = (): void => {\n while (i < message.length && /\\s/.test(at())) i++;\n };\n const readIdent = (): string => {\n let s = '';\n while (i < message.length && /[a-zA-Z0-9_]/.test(at())) s += message[i++];\n return s;\n };\n\n function parseBody(inPlural: boolean): MessageNode[] {\n const nodes: MessageNode[] = [];\n let buf = '';\n const flush = (): void => {\n if (buf) nodes.push({ kind: 'text', value: buf });\n buf = '';\n };\n while (i < message.length) {\n const ch = at();\n if (ch === '}') break;\n if (ch === '{') {\n flush();\n nodes.push(parseArg());\n } else if (ch === '#' && inPlural) {\n flush();\n nodes.push({ kind: 'hash' });\n i++;\n } else if (ch === \"'\") {\n buf += readQuoted();\n } else {\n buf += ch;\n i++;\n }\n }\n flush();\n return nodes;\n }\n\n // ICU apostrophe quoting\n function readQuoted(): string {\n i++; // opening '\n if (at() === \"'\") {\n i++;\n return \"'\";\n }\n const next = at();\n if (next !== '{' && next !== '}' && next !== '#') return \"'\"; // lone apostrophe\n let out = '';\n while (i < message.length) {\n if (at() === \"'\") {\n if (message.charAt(i + 1) === \"'\") {\n out += \"'\";\n i += 2;\n continue;\n }\n i++; // closing '\n return out;\n }\n out += message[i++];\n }\n return out; // unterminated\n }\n\n function parseArg(): MessageNode {\n i++; // {\n skipWs();\n const name = readIdent();\n skipWs();\n if (at() === '}') {\n i++;\n return { kind: 'param', name };\n }\n if (at() === ',') i++;\n skipWs();\n const type = readIdent();\n const node: ParamNode = { kind: 'param', name };\n\n if (type === 'number' || type === 'date' || type === 'time') {\n skipWs();\n let style = '';\n if (at() === ',') {\n i++;\n skipWs();\n while (i < message.length && at() !== '}' && at() !== ',') style += message[i++];\n style = style.trim();\n }\n if (type === 'number') {\n node.format =\n style === 'integer'\n ? 'integer'\n : style === 'percent'\n ? 'percent'\n : style === 'currency'\n ? 'currency'\n : 'number';\n } else {\n node.format = type;\n if (style) node.arg = style;\n }\n skipToClose();\n return node;\n }\n\n if (type === 'plural' || type === 'selectordinal' || type === 'select') {\n if (type === 'selectordinal') node.ordinal = true;\n const variants: [string, MessageNode[]][] = [];\n skipWs();\n if (at() === ',') i++; // comma after the keyword\n skipWs();\n if (type !== 'select' && message.startsWith('offset:', i)) {\n i += 7;\n skipWs();\n while (i < message.length && /[0-9]/.test(at())) i++; // offset parsed, not applied (v1)\n skipWs();\n }\n while (i < message.length && at() !== '}') {\n const selector = readSelector();\n skipWs();\n if (at() !== '{') break;\n i++; // {\n const body = parseBody(type !== 'select');\n if (at() === '}') i++;\n variants.push([selector, body]);\n skipWs();\n }\n if (at() === '}') i++;\n node.variants = variants;\n return node;\n }\n\n // unknown type → simple param\n skipToClose();\n return node;\n }\n\n function readSelector(): string {\n if (at() === '=') {\n let s = '=';\n i++;\n while (i < message.length && /[0-9]/.test(at())) s += message[i++];\n return s;\n }\n let s = '';\n while (i < message.length && !/[\\s{]/.test(at())) s += message[i++];\n return s;\n }\n\n function skipToClose(): void {\n while (i < message.length && at() !== '}') i++;\n if (at() === '}') i++;\n }\n\n return parseBody(false);\n}\n","import { isIcu, parseIcu } from './icu';\n\nexport type MessageNode = { kind: 'text'; value: string } | { kind: 'hash' } | ParamNode;\n\nexport interface ParamNode {\n kind: 'param';\n name: string;\n format?: string;\n arg?: string;\n ordinal?: boolean;\n variants?: [string, MessageNode[]][];\n}\n\nconst astCache = new Map<string, MessageNode[]>();\nconst AST_CACHE_MAX = 2000; // dynamic/CMS messages can't grow it unbounded\n\nexport function parse(message: string): MessageNode[] {\n let cached = astCache.get(message);\n if (!cached) {\n if (astCache.size >= AST_CACHE_MAX) astCache.clear();\n cached = isIcu(message) ? parseIcu(message) : parseMessage(message, false);\n astCache.set(message, cached);\n }\n return cached;\n}\n\nfunction parseMessage(input: string, inVariant: boolean): MessageNode[] {\n const nodes: MessageNode[] = [];\n let buf = '';\n let i = 0;\n\n const flush = () => {\n if (buf) nodes.push({ kind: 'text', value: buf });\n buf = '';\n };\n\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n buf += '{';\n i += 2;\n continue;\n }\n const close = findClose(input, i);\n if (close < 0) {\n buf += input.slice(i);\n break;\n }\n flush();\n nodes.push(parsePlaceholder(input.slice(i + 1, close)));\n i = close + 1;\n } else if (ch === '}' && input[i + 1] === '}') {\n buf += '}';\n i += 2;\n } else if (inVariant && ch === '#') {\n if (input[i + 1] === '#') {\n buf += '#';\n i += 2;\n } else {\n flush();\n nodes.push({ kind: 'hash' });\n i += 1;\n }\n } else {\n buf += ch;\n i += 1;\n }\n }\n flush();\n return nodes;\n}\n\nfunction findClose(input: string, open: number): number {\n let depth = 0;\n let i = open;\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n i += 2;\n continue;\n }\n depth += 1;\n } else if (ch === '}') {\n if (input[i + 1] === '}') {\n i += 2;\n continue;\n }\n depth -= 1;\n if (depth === 0) return i;\n }\n i += 1;\n }\n return -1;\n}\n\nfunction parsePlaceholder(inner: string): MessageNode {\n const segments = splitTop(inner);\n const head = (segments[0] ?? '').trim();\n if (!head) return { kind: 'text', value: `{${inner}}` };\n\n const colon = head.indexOf(':');\n const name = (colon < 0 ? head : head.slice(0, colon)).trim();\n if (!name) return { kind: 'text', value: `{${inner}}` };\n\n const node: ParamNode = { kind: 'param', name };\n\n if (colon >= 0) {\n const fmtRaw = head.slice(colon + 1).trim();\n const slash = fmtRaw.indexOf('/');\n node.format = (slash < 0 ? fmtRaw : fmtRaw.slice(0, slash)).trim();\n if (slash >= 0) node.arg = fmtRaw.slice(slash + 1).trim();\n }\n\n if (segments.length > 1) {\n node.variants = [];\n for (const seg of segments.slice(1)) {\n const sep = seg.indexOf(':');\n if (sep < 0) continue;\n const key = seg.slice(0, sep).trim();\n const body = seg.slice(sep + 1).trim();\n if (key) node.variants.push([key, parseMessage(body, true)]);\n }\n }\n return node;\n}\n\nfunction splitTop(input: string): string[] {\n const parts: string[] = [];\n let buf = '';\n let depth = 0;\n let i = 0;\n while (i < input.length) {\n const ch = input[i];\n if (ch === '{') {\n if (input[i + 1] === '{') {\n buf += '{{';\n i += 2;\n continue;\n }\n depth += 1;\n buf += ch;\n } else if (ch === '}') {\n if (input[i + 1] === '}') {\n buf += '}}';\n i += 2;\n continue;\n }\n depth -= 1;\n buf += ch;\n } else if (ch === '|' && depth === 0) {\n if (input[i + 1] === '|') {\n buf += '|';\n i += 2;\n continue;\n }\n parts.push(buf);\n buf = '';\n } else {\n buf += ch;\n }\n i += 1;\n }\n parts.push(buf);\n return parts;\n}\n","import { flatten } from './flatten';\nimport { autoFormat, formatNodes } from './format';\nimport { parse } from './parse';\nimport type {\n DictionaryInput,\n MessageTree,\n Params,\n TFunction,\n Verbaly,\n VerbalyOptions,\n} from './types';\n\nexport function createVerbaly<const D extends DictionaryInput = DictionaryInput>(\n options: VerbalyOptions<D> = {},\n): Verbaly<D> {\n const dict: Record<string, Record<string, string>> = {};\n const listeners = new Set<() => void>();\n const formatters = options.formatters ?? {};\n const loaders = options.loaders ?? {};\n const loaded = new Set<string>();\n const inFlight = new Map<string, Promise<void>>();\n const warned = new Set<string>();\n const fallbacks = options.fallback\n ? Array.isArray(options.fallback)\n ? options.fallback\n : [options.fallback]\n : [];\n\n let locale = options.locale ?? detectLocale();\n let version = 0;\n let chainCache: string[] | null = null;\n\n if (options.messages) {\n for (const [loc, tree] of Object.entries(options.messages)) {\n dict[loc] = flatten(tree);\n }\n }\n\n function chain(): string[] {\n if (chainCache) return chainCache;\n const result: string[] = [];\n // narrow BCP-47 subtags\n const parts = locale.split('-');\n while (parts.length > 0) {\n result.push(parts.join('-'));\n parts.pop();\n }\n for (const fb of fallbacks) if (!result.includes(fb)) result.push(fb);\n chainCache = result;\n return result;\n }\n\n function lookup(key: string): { msg: string; from: string } | undefined {\n for (const loc of chain()) {\n const msg = dict[loc]?.[key];\n // '' = untranslated (extract scaffolds it) → keep falling back\n if (msg) return { msg, from: loc };\n }\n return undefined;\n }\n\n function translate(key: string, params: Params | undefined): string {\n const hit = lookup(key);\n if (hit === undefined) {\n const replacement = options.onMissing?.(key, locale);\n const value = typeof replacement === 'string' ? replacement : key;\n if (typeof replacement !== 'string' && !options.onMissing && !warned.has(key)) {\n warned.add(key);\n console.warn(`[verbaly] missing key \"${key}\" (${locale})`);\n }\n options.onResolve?.({ key, locale, value, status: 'miss' });\n return value;\n }\n const value = formatNodes(parse(hit.msg), { locale, params, formatters });\n options.onResolve?.({\n key,\n locale,\n value,\n status: hit.from === locale ? 'hit' : 'fallback',\n from: hit.from,\n });\n return value;\n }\n\n function tagged(strings: TemplateStringsArray, values: unknown[]): string {\n let out = strings[0] ?? '';\n for (let i = 0; i < values.length; i++) {\n out += autoFormat(values[i], locale) + (strings[i + 1] ?? '');\n }\n return out;\n }\n\n function notify(): void {\n version += 1;\n for (const fn of listeners) fn();\n }\n\n const t = ((first: unknown, ...rest: unknown[]): string => {\n if (isTemplateStrings(first)) return tagged(first, rest);\n return translate(first as string, rest[0] as Params | undefined);\n }) as TFunction<D>;\n\n t.id =\n () =>\n (strings: TemplateStringsArray, ...values: unknown[]) =>\n tagged(strings, values);\n\n function pendingLoader(target: string): string | undefined {\n const parts = target.split('-');\n while (parts.length > 0) {\n const candidate = parts.join('-');\n if (loaders[candidate] && !loaded.has(candidate)) return candidate;\n if (loaders[candidate]) return undefined;\n parts.pop();\n }\n return undefined;\n }\n\n function loadLocale(target: string): Promise<void> {\n const pending = pendingLoader(target);\n if (!pending) return Promise.resolve();\n const running = inFlight.get(pending);\n if (running) return running;\n const load = loaders[pending]!()\n .then((mod) => {\n loaded.add(pending);\n inFlight.delete(pending);\n addMessages(\n pending,\n 'default' in mod ? (mod.default as MessageTree) : (mod as MessageTree),\n );\n })\n .catch((error: unknown) => {\n inFlight.delete(pending);\n throw error;\n });\n inFlight.set(pending, load);\n return load;\n }\n\n function addMessages(loc: string, messages: MessageTree): void {\n dict[loc] = { ...dict[loc], ...flatten(messages) };\n notify();\n }\n\n return {\n get locale() {\n return locale;\n },\n get locales() {\n return [...new Set([...Object.keys(dict), ...Object.keys(loaders)])];\n },\n get version() {\n return version;\n },\n t,\n setLocale(next: string) {\n // auto-load pending catalog; UI re-renders when it lands\n if (pendingLoader(next)) {\n void loadLocale(next).catch(() => {\n if (!warned.has(`load:${next}`)) {\n warned.add(`load:${next}`);\n console.warn(`[verbaly] failed to load catalog for \"${next}\"`);\n }\n });\n }\n if (next === locale) return;\n locale = next;\n chainCache = null;\n notify();\n },\n loadLocale,\n addMessages,\n subscribe(listener: () => void) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n has(key: string) {\n return lookup(key) !== undefined;\n },\n inspect(key: string) {\n const hit = lookup(key);\n return hit ? { locale: hit.from, source: hit.msg } : undefined;\n },\n };\n}\n\nfunction isTemplateStrings(value: unknown): value is TemplateStringsArray {\n return Array.isArray(value) && 'raw' in value;\n}\n\nfunction detectLocale(): string {\n // gate on document, not navigator — Node 21+ exposes a global navigator (OS locale)\n return typeof document !== 'undefined' && typeof navigator !== 'undefined' && navigator.language\n ? navigator.language\n : 'en';\n}\n","// Named-tag tokenizer for <Trans>\nexport type TagNode = string | { name: string; children: TagNode[] };\n\nconst TAG = /<(\\/?)([a-zA-Z][\\w-]*)(\\/?)>/g;\n\nexport function parseTags(text: string): TagNode[] {\n const re = new RegExp(TAG.source, 'g');\n const root: TagNode[] = [];\n const stack: { name: string; children: TagNode[] }[] = [];\n const top = (): TagNode[] => (stack.length ? stack[stack.length - 1]!.children : root);\n const pushText = (s: string): void => {\n if (s) top().push(s);\n };\n\n let last = 0;\n let m: RegExpExecArray | null;\n while ((m = re.exec(text)) !== null) {\n const [full, closing, name, selfClose] = m;\n pushText(text.slice(last, m.index));\n last = m.index + full.length;\n\n if (selfClose) {\n top().push({ name: name!, children: [] });\n } else if (closing) {\n if (stack.length && stack[stack.length - 1]!.name === name) {\n const node = stack.pop()!;\n top().push(node);\n } else {\n pushText(full); // stray closing tag → literal\n }\n } else {\n stack.push({ name: name!, children: [] });\n }\n }\n pushText(text.slice(last));\n\n // unclosed opens: drop wrapper\n while (stack.length) {\n const node = stack.pop()!;\n top().push(...node.children);\n }\n return root;\n}\n","import { parseTags, type TagNode } from './tags';\nimport type { DictionaryInput, Params, Verbaly } from './types';\n\n// hrefs come from the caller, never from messages\nexport type RichLink = string | { href: string; target?: string; rel?: string };\n\nexport interface BindDomOptions {\n root?: ParentNode;\n attribute?: string;\n richTags?: string[];\n richLinks?: Record<string, RichLink>;\n}\n\nconst UNSAFE_HREF = /^\\s*(javascript|data|vbscript):/i;\n\nexport function safeHref(href: string): string | undefined {\n if (UNSAFE_HREF.test(href)) {\n console.warn(`[verbaly] blocked unsafe href: ${href}`);\n return undefined;\n }\n return href;\n}\n\n// phrasing-only, attribute-less → XSS-safe\nexport const RICH_TAGS = [\n 'em',\n 'strong',\n 'code',\n 'b',\n 'i',\n 'u',\n 's',\n 'small',\n 'mark',\n 'sub',\n 'sup',\n 'span',\n 'kbd',\n 'abbr',\n 'br',\n 'wbr',\n];\n\nexport function bindDom<D extends DictionaryInput>(\n instance: Verbaly<D>,\n options: BindDomOptions = {},\n): () => void {\n if (typeof document === 'undefined') {\n throw new Error('[verbaly] bindDom requires a DOM');\n }\n const t = instance.t as unknown as (key: string, params?: Params) => string;\n const root = options.root ?? document.body;\n const attr = options.attribute ?? 'data-verbaly';\n const argsAttr = `${attr}-args`;\n const attrsAttr = `${attr}-attr`;\n const richAttr = `${attr}-rich`;\n const linksAttr = `${attr}-links`;\n const richTags = new Set(options.richTags ?? RICH_TAGS);\n const globalLinks = options.richLinks;\n const argsCache = new WeakMap<Element, { raw: string | null; params: Params | undefined }>();\n const linksCache = new WeakMap<\n Element,\n { raw: string | null; links: Record<string, RichLink> | undefined }\n >();\n\n function cachedArgs(el: Element): Params | undefined {\n const raw = el.getAttribute(argsAttr);\n const hit = argsCache.get(el);\n if (hit && hit.raw === raw) return hit.params;\n const params = parseArgs(raw);\n argsCache.set(el, { raw, params });\n return params;\n }\n\n function cachedLinks(el: Element): Record<string, RichLink> | undefined {\n const raw = el.getAttribute(linksAttr);\n if (!raw) return globalLinks;\n const hit = linksCache.get(el);\n if (hit && hit.raw === raw) return hit.links;\n const own = parseArgs(raw) as Record<string, RichLink> | undefined;\n const links = own ? (globalLinks ? { ...globalLinks, ...own } : own) : globalLinks;\n linksCache.set(el, { raw, links });\n return links;\n }\n\n function renderRich(\n el: Element,\n nodes: TagNode[],\n links: Record<string, RichLink> | undefined,\n ): void {\n for (const node of nodes) {\n if (typeof node === 'string') {\n el.append(node);\n } else if (links?.[node.name] !== undefined) {\n const link = links[node.name]!;\n const { href, target, rel }: Exclude<RichLink, string> =\n typeof link === 'string' ? { href: link } : link;\n const a = el.ownerDocument.createElement('a');\n const safe = safeHref(href);\n if (safe !== undefined) a.setAttribute('href', safe);\n if (target) a.setAttribute('target', target);\n if (rel) a.setAttribute('rel', rel);\n renderRich(a, node.children, links);\n el.append(a);\n } else if (richTags.has(node.name)) {\n const child = el.ownerDocument.createElement(node.name);\n renderRich(child, node.children, links);\n el.append(child);\n } else {\n renderRich(el, node.children, links); // unknown tag → unwrap\n }\n }\n }\n\n function render(el: Element): void {\n const args = cachedArgs(el);\n const key = el.getAttribute(attr);\n if (key) {\n const text = t(key, args);\n if (el.hasAttribute(richAttr)) {\n el.textContent = '';\n renderRich(el, parseTags(text), cachedLinks(el));\n } else {\n el.textContent = text;\n }\n }\n\n const attrMap = parseArgs(el.getAttribute(attrsAttr));\n if (attrMap) {\n for (const [name, attrKey] of Object.entries(attrMap)) {\n if (typeof attrKey !== 'string' || name.toLowerCase().startsWith('on')) continue;\n el.setAttribute(name, t(attrKey, args));\n }\n }\n }\n\n const selector = `[${attr}], [${attrsAttr}]`;\n\n function renderAll(scope: ParentNode | Element): void {\n if (scope instanceof Element && scope.matches(selector)) render(scope);\n for (const el of scope.querySelectorAll(selector)) render(el);\n }\n\n renderAll(root);\n const unsubscribe = instance.subscribe(() => renderAll(root));\n\n const observer = new MutationObserver((records) => {\n for (const record of records) {\n if (record.type === 'attributes' && record.target instanceof Element) {\n render(record.target);\n } else if (record.type === 'childList') {\n for (const node of record.addedNodes) {\n if (node instanceof Element) renderAll(node);\n }\n }\n }\n });\n\n observer.observe(root instanceof Document ? root.documentElement : (root as Node), {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [attr, argsAttr, attrsAttr, richAttr, linksAttr],\n });\n\n return () => {\n unsubscribe();\n observer.disconnect();\n };\n}\n\nfunction parseArgs(raw: string | null): Params | undefined {\n if (!raw) return undefined;\n try {\n return JSON.parse(raw) as Params;\n } catch {\n console.warn(`[verbaly] invalid args JSON: ${raw}`);\n return undefined;\n }\n}\n","// locale bootstrap helpers (SSR-safe)\nexport interface ResolveLocaleOptions {\n supported: string[];\n fallback?: string;\n storageKey?: string | false;\n}\n\nconst DEFAULT_KEY = 'verbaly-locale';\n\nexport function resolveLocale(options: ResolveLocaleOptions): string {\n const { supported, fallback = supported[0] ?? 'en', storageKey = DEFAULT_KEY } = options;\n\n if (storageKey) {\n const stored = getStorage()?.getItem(storageKey);\n const match = stored && matchSupported(stored, supported);\n if (match) return match;\n }\n\n for (const lang of preferredLanguages()) {\n const match = matchSupported(lang, supported);\n if (match) return match;\n }\n\n return fallback;\n}\n\n// exact, then BCP-47 base (es-PE → es)\nfunction matchSupported(lang: string, supported: string[]): string | undefined {\n if (supported.includes(lang)) return lang;\n const base = lang.split('-')[0]!;\n return supported.includes(base) ? base : undefined;\n}\n\n// server-side Accept-Language negotiation (q-values, case-insensitive, BCP-47 base)\nexport function negotiateLocale(\n header: string | null | undefined,\n supported: string[],\n fallback: string = supported[0] ?? 'en',\n): string {\n if (!header) return fallback;\n\n const ranges: { tag: string; q: number }[] = [];\n for (const part of header.split(',')) {\n const [rawTag, ...params] = part.trim().split(';');\n const tag = rawTag?.trim();\n if (!tag || tag === '*') continue;\n let q = 1;\n for (const param of params) {\n const [name, value] = param.split('=');\n if (name?.trim().toLowerCase() === 'q') {\n const parsed = Number(value?.trim());\n q = Number.isFinite(parsed) ? parsed : 1;\n }\n }\n if (q > 0) ranges.push({ tag, q });\n }\n // stable sort — ties keep header order\n ranges.sort((a, b) => b.q - a.q);\n\n for (const { tag } of ranges) {\n const match = matchSupportedLoose(tag, supported);\n if (match) return match;\n }\n return fallback;\n}\n\n// case-insensitive matchSupported (headers arrive as en-US; configs as en)\nfunction matchSupportedLoose(lang: string, supported: string[]): string | undefined {\n const lower = lang.toLowerCase();\n const exact = supported.find((s) => s.toLowerCase() === lower);\n if (exact) return exact;\n const base = lower.split('-')[0]!;\n return supported.find((s) => s.toLowerCase() === base);\n}\n\nexport function persistLocale(locale: string, storageKey: string | false = DEFAULT_KEY): void {\n if (storageKey) getStorage()?.setItem(storageKey, locale);\n if (typeof document !== 'undefined') document.documentElement.lang = locale;\n}\n\nfunction preferredLanguages(): readonly string[] {\n // require document — Node 21+ has a global navigator whose language is the OS, not a user\n if (typeof document === 'undefined' || typeof navigator === 'undefined') return [];\n return navigator.languages?.length ? navigator.languages : [navigator.language];\n}\n\nfunction getStorage(): Storage | null {\n try {\n return typeof localStorage === 'undefined' ? null : localStorage;\n } catch {\n return null; // blocked storage (privacy mode)\n }\n}\n"],"mappings":";AAEA,SAAgB,QACd,MACA,SAAS,IACT,MAA8B,CAAC,GACP;CACxB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAAI,GAAG;EAC/C,MAAM,OAAO,SAAS,GAAG,OAAO,GAAG,QAAQ;EAC3C,IAAI,OAAO,UAAU,UAAU,IAAI,QAAQ;OACtC,QAAQ,OAAO,MAAM,GAAG;CAC/B;CACA,OAAO;AACT;;;ACbA,MAAM,YAAY;AAElB,MAAM,0BAAU,IAAI,IAA+B;AACnD,MAAM,2BAAW,IAAI,IAAiC;AACtD,MAAM,0BAAU,IAAI,IAA8B;AAClD,MAAM,2BAAW,IAAI,IAAqC;AAC1D,MAAM,0BAAU,IAAI,IAA6B;AAEjD,SAAS,OAAU,OAAuB,KAAa,MAAkB;CACvE,IAAI,MAAM,MAAM,IAAI,GAAG;CACvB,IAAI,CAAC,KAAK;EACR,IAAI,MAAM,QAAQ,WAAW,MAAM,OAAO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