verbaly 0.35.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -239,22 +239,31 @@ function localeName(locale, displayIn = locale) {
239
239
  }
240
240
  function localePath(locale, options) {
241
241
  const { supported, sourceLocale } = options;
242
+ const base = normalizeBase(options.base);
242
243
  const full = options.path ?? currentPath() ?? "/";
243
244
  const cut = full.search(/[?#]/);
244
- const path = cut < 0 ? full : full.slice(0, cut);
245
+ const path = stripBase(cut < 0 ? full : full.slice(0, cut), base);
245
246
  const rest = cut < 0 ? "" : full.slice(cut);
246
247
  const segments = path.split("/").filter(Boolean);
247
- if (segments[0] && matchSupported(segments[0], supported)) segments.shift();
248
+ if (segments[0] && matchPathSegment(segments[0], supported)) segments.shift();
248
249
  if (locale !== sourceLocale) segments.unshift(locale);
249
250
  const trailing = segments.length && path.endsWith("/") ? "/" : "";
250
- return `/${segments.join("/")}${trailing}${rest}`;
251
+ return `${base}/${segments.join("/")}${trailing}${rest}`;
252
+ }
253
+ function localeFromPath(options) {
254
+ const path = options.path ?? currentPath();
255
+ if (path === void 0) return void 0;
256
+ const segment = stripBase(path, normalizeBase(options.base)).split("/").find(Boolean);
257
+ return segment ? matchPathSegment(segment, options.supported) : void 0;
251
258
  }
252
259
  function resolveLocale(options) {
253
260
  const { supported, fallback = supported[0] ?? "en", storageKey = LOCALE_STORAGE_KEY } = options;
254
- const path = options.path ?? currentPath();
255
- if (path) {
256
- const segment = path.split("/").find(Boolean);
257
- const match = segment && matchSupported(segment, supported);
261
+ if (options.path !== false) {
262
+ const match = localeFromPath({
263
+ supported,
264
+ path: options.path,
265
+ base: options.base
266
+ });
258
267
  if (match) return match;
259
268
  }
260
269
  if (storageKey) {
@@ -268,6 +277,21 @@ function resolveLocale(options) {
268
277
  }
269
278
  return fallback;
270
279
  }
280
+ function normalizeBase(base) {
281
+ const trimmed = base?.replace(/^\/+/, "").replace(/\/+$/, "");
282
+ return trimmed ? `/${trimmed}` : "";
283
+ }
284
+ function stripBase(path, base) {
285
+ if (!base || !path.startsWith(base)) return path;
286
+ const rest = path.slice(base.length);
287
+ if (rest === "") return "/";
288
+ return rest.startsWith("/") ? rest : path;
289
+ }
290
+ const LOCALE_SEGMENT = /^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|\d{3}))?$/i;
291
+ function matchPathSegment(segment, supported) {
292
+ if (supported.includes(segment)) return segment;
293
+ return LOCALE_SEGMENT.test(segment) ? matchSupported(segment, supported) : void 0;
294
+ }
271
295
  function matchSupported(lang, supported) {
272
296
  for (const candidate of narrowLocales(lang)) if (supported.includes(candidate)) return candidate;
273
297
  }
@@ -716,11 +740,17 @@ function createVerbaly(options = {}) {
716
740
  version += 1;
717
741
  for (const fn of listeners) fn();
718
742
  }
743
+ autoLoad(locale);
719
744
  const t = ((first, ...rest) => {
720
745
  if (isTemplateStrings(first)) return tagged(first, rest);
721
746
  return translate(first, rest[0]);
722
747
  });
723
748
  t.id = () => (strings, ...values) => tagged(strings, values);
749
+ function autoLoad(target) {
750
+ loadLocale(target).catch(() => {
751
+ warnOnce(`failed to load catalog for "${target}"`);
752
+ });
753
+ }
724
754
  function pendingLoader(target) {
725
755
  for (const candidate of narrowLocales(target)) if (loaders[candidate]) return loaded.has(candidate) ? void 0 : candidate;
726
756
  }
@@ -759,9 +789,7 @@ function createVerbaly(options = {}) {
759
789
  },
760
790
  t,
761
791
  setLocale(next) {
762
- loadLocale(next).catch(() => {
763
- warnOnce(`failed to load catalog for "${next}"`);
764
- });
792
+ autoLoad(next);
765
793
  if (next === locale) return;
766
794
  locale = next;
767
795
  chainCache = null;
@@ -1021,7 +1049,7 @@ function bindDom(instance, options = {}) {
1021
1049
  function warnOnLangMismatch(locale) {
1022
1050
  const lang = document.documentElement.lang;
1023
1051
  if (!lang || narrowLocales(lang).includes(locale) || narrowLocales(locale).includes(lang)) return;
1024
- warnOnce(`the page is <html lang="${lang}"> and this instance is in "${locale}", so bindDom is about to translate it away: resolve the locale from the url (resolveLocale reads it) before binding`);
1052
+ warnOnce(`the page is <html lang="${lang}"> and this instance is in "${locale}", so bindDom is about to translate it away: read the url with localeFromPath when it carries the locale, and call persistLocale first when it does not`);
1025
1053
  }
1026
1054
  function parseArgs(raw) {
1027
1055
  if (!raw) return void 0;
@@ -1040,6 +1068,7 @@ exports.bindDom = bindDom;
1040
1068
  exports.createVerbaly = createVerbaly;
1041
1069
  exports.flatten = flatten;
1042
1070
  exports.localeDirection = localeDirection;
1071
+ exports.localeFromPath = localeFromPath;
1043
1072
  exports.localeName = localeName;
1044
1073
  exports.localePath = localePath;
1045
1074
  exports.negotiateLocale = negotiateLocale;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/warn.ts","../src/flatten.ts","../src/intl.ts","../src/format.ts","../src/locale.ts","../src/icu.ts","../src/parse.ts","../src/instance.ts","../src/tags.ts","../src/dom.ts"],"sourcesContent":["// one warn-once for the whole runtime: the set is unbounded, so a message never carries a value\nconst warned = new Set<string>();\n\nexport function warnOnce(message: string): void {\n if (warned.has(message)) return;\n warned.add(message);\n console.warn(`[verbaly] ${message}`);\n}\n","import type { MessageTree } from './types';\nimport { warnOnce } from './warn';\n\nexport function flatten(\n tree: MessageTree,\n prefix = '',\n out: Record<string, string> = {},\n): Record<string, string> {\n // a catalog is untrusted input: a lazy loader, addMessages or a CMS never crosses the build gate\n if (!isGroup(tree)) return out;\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 if (isGroup(value)) flatten(value, path, out);\n else warnOnce(`catalog value at \"${path}\" is not text, so the key renders as itself`);\n }\n return out;\n}\n\nfunction isGroup(value: unknown): value is MessageTree {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\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>();\nconst dnCache = new Map<string, Intl.DisplayNames>();\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\nexport function displayNames(locale: string): Intl.DisplayNames {\n return cached(dnCache, locale, () => new Intl.DisplayNames(locale, { type: 'language' }));\n}\n","import { dateTimeFormat, listFormat, numberFormat, pluralRules, relativeTimeFormat } from './intl';\nimport type { MessageNode, ParamNode } from './parse';\nimport type { Formatter, Params } from './types';\nimport { warnOnce } from './warn';\n\ninterface FormatContext {\n locale: string;\n params: Params | undefined;\n formatters: Record<string, Formatter>;\n hashValue?: unknown;\n key?: string;\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, ctx);\n else out += formatParam(node, ctx);\n }\n return out;\n}\n\n// every warn names its message: keying on the param alone silenced the second message with the gap\nfunction where(ctx: FormatContext): string {\n return ctx.key ? ` in \"${ctx.key}\"` : '';\n}\n\nfunction formatParam(node: ParamNode, ctx: FormatContext): string {\n const value = ctx.params?.[node.name];\n if (value === undefined) {\n warnOnce(`missing param \"${node.name}\"${where(ctx)}`);\n return `{${node.name}}`;\n }\n\n if (node.variants) {\n const chosen = pickVariant(node.variants, value, ctx.locale, node.ordinal);\n // the value is left out of the warn on purpose: a counter walking 0..N must not grow the dedupe\n if (!chosen) {\n warnOnce(`no case matched for {${node.name}}${where(ctx)}, add an \"other\" case`);\n return '';\n }\n return formatNodes(chosen, { ...ctx, hashValue: value });\n }\n if (node.format) return applyFormat(value, node, ctx);\n return autoFormat(value, ctx.locale, ctx);\n}\n\n// the type of the offending value, never the value: the dedupe set must stay bounded\nfunction describe(value: unknown): string {\n if (value instanceof Date) return Number.isNaN(value.getTime()) ? 'an invalid Date' : 'a Date';\n if (Array.isArray(value)) return 'an array';\n if (value === null) return 'null';\n if (value === undefined) return 'undefined';\n const type = typeof value;\n return type === 'object' ? 'an object' : `a ${type}`;\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(value: unknown, node: ParamNode, ctx: FormatContext): string {\n const { name, arg } = node;\n const format = node.format!;\n const custom = ctx.formatters[format];\n if (custom) return custom(value, ctx.locale, arg);\n\n const { locale } = ctx;\n // a format missing its argument degrades like an invalid one: with a warn, never in silence\n const degrade = (problem: string): string => {\n warnOnce(`{${name}:${format}}${where(ctx)} ${problem}`);\n return String(value);\n };\n\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 degrade('needs an argument like /USD');\n try {\n return numberFormat(locale, { style: 'currency', currency: arg }).format(Number(value));\n } catch {\n return degrade(`does not know the currency \"${arg}\"`);\n }\n case 'date':\n try {\n return dateTimeFormat(\n locale,\n arg ? { dateStyle: arg as Intl.DateTimeFormatOptions['dateStyle'] } : undefined,\n ).format(toDate(value));\n } catch {\n return degrade(`cannot format ${describe(value)}${arg ? ` with style \"${arg}\"` : ''}`);\n }\n case 'time':\n try {\n return dateTimeFormat(locale, {\n timeStyle: (arg ?? 'short') as Intl.DateTimeFormatOptions['timeStyle'],\n }).format(toDate(value));\n } catch {\n return degrade(`cannot format ${describe(value)} with style \"${arg ?? 'short'}\"`);\n }\n case 'relative':\n if (typeof value === 'number' && !arg) return degrade('needs an argument like /day');\n if (typeof value !== 'number' && !(value instanceof Date))\n return degrade('needs a number or a Date');\n return formatRelative(value, node, ctx);\n case 'list': {\n if (!Array.isArray(value)) return degrade('needs an array');\n const type = arg === 'or' ? 'disjunction' : arg === 'unit' ? 'unit' : 'conjunction';\n return listFormat(locale, type).format(value.map((item) => autoFormat(item, locale, ctx)));\n }\n case 'unit':\n if (!arg) return degrade('needs an argument like /kilometer');\n try {\n return numberFormat(locale, { style: 'unit', unit: arg }).format(Number(value));\n } catch {\n return degrade(`does not know the unit \"${arg}\"`);\n }\n default:\n return degrade('is not a format verbaly knows');\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: number | Date, node: ParamNode, ctx: FormatContext): string {\n const { arg } = node;\n try {\n const fmt = relativeTimeFormat(ctx.locale);\n if (typeof value === 'number') return fmt.format(value, arg as Intl.RelativeTimeFormatUnit);\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 fmt.format(Math.round(diffSec / per), arg as Intl.RelativeTimeFormatUnit);\n }\n const [unit, per] = REL_UNITS.find(([, s]) => Math.abs(diffSec) >= s) ?? ['second', 1];\n return fmt.format(Math.round(diffSec / per), unit);\n } catch {\n // an invalid Date lands here too, so the warn names both suspects instead of blaming the unit\n warnOnce(`{${node.name}:relative}${where(ctx)} cannot format ${describe(value)} as \"${arg}\"`);\n return String(value);\n }\n}\n\nexport function autoFormat(value: unknown, locale: string, ctx?: FormatContext): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'number') return numberFormat(locale).format(value);\n if (value instanceof Date) {\n // an invalid Date makes Intl throw: degrade like every other bad format input\n if (Number.isNaN(value.getTime())) {\n warnOnce(`an invalid Date${ctx ? where(ctx) : ''} renders as plain text`);\n return String(value);\n }\n return dateTimeFormat(locale).format(value);\n }\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 { displayNames } from './intl';\nimport type { Verbaly } from './types';\n\nexport interface ResolveLocaleOptions {\n supported: string[];\n fallback?: string;\n storageKey?: string | false;\n path?: string | false;\n}\n\n// shared identity: localStorage key (browser) + cookie name (SSR integrations)\nexport const LOCALE_STORAGE_KEY = 'verbaly-locale';\n\n// zh-Hant-TW → [zh-Hant-TW, zh-Hant, zh]\nexport function narrowLocales(lang: string): string[] {\n const out: string[] = [];\n const parts = lang.split('-');\n while (parts.length > 0) {\n out.push(parts.join('-'));\n parts.pop();\n }\n return out;\n}\n\n// fallback tables for engines without Intl.Locale getTextInfo (Firefox)\nconst RTL_SCRIPTS = /^(Arab|Aran|Hebr|Thaa|Nkoo|Syrc|Samr|Mand|Adlm|Rohg|Yezi)$/;\nconst RTL_LANGS = /^(ar|he|fa|ur|ps|sd|ug|yi|dv|ckb)$/;\n\ninterface TextInfoLocale extends Intl.Locale {\n getTextInfo?(): { direction?: string };\n textInfo?: { direction?: string };\n}\n\nexport function localeDirection(locale: string): 'ltr' | 'rtl' {\n try {\n const loc = new Intl.Locale(locale) as TextInfoLocale;\n const direction = (loc.getTextInfo?.() ?? loc.textInfo)?.direction;\n if (direction === 'rtl' || direction === 'ltr') return direction;\n const script = loc.script ?? loc.maximize().script;\n if (script) return RTL_SCRIPTS.test(script) ? 'rtl' : 'ltr';\n return RTL_LANGS.test(loc.language) ? 'rtl' : 'ltr';\n } catch {\n // malformed tag: best effort on the primary subtag, never throw\n return RTL_LANGS.test(locale.split('-')[0]!.toLowerCase()) ? 'rtl' : 'ltr';\n }\n}\n\n// localized language name for locale switchers; defaults to the endonym\nexport function localeName(locale: string, displayIn: string = locale): string {\n try {\n return displayNames(displayIn).of(locale) ?? locale;\n } catch {\n return locale; // unknown tag or missing Intl data: the code beats a crash\n }\n}\n\nexport interface LocalePathOptions {\n supported: string[];\n sourceLocale?: string;\n path?: string;\n}\n\n// the inverse of what render writes: /es/docs → /pt/docs, and the source locale keeps no prefix\nexport function localePath(locale: string, options: LocalePathOptions): string {\n const { supported, sourceLocale } = options;\n const full = options.path ?? currentPath() ?? '/';\n const cut = full.search(/[?#]/);\n const path = cut < 0 ? full : full.slice(0, cut);\n const rest = cut < 0 ? '' : full.slice(cut);\n\n const segments = path.split('/').filter(Boolean);\n if (segments[0] && matchSupported(segments[0], supported)) segments.shift();\n if (locale !== sourceLocale) segments.unshift(locale);\n const trailing = segments.length && path.endsWith('/') ? '/' : '';\n return `/${segments.join('/')}${trailing}${rest}`;\n}\n\nexport function resolveLocale(options: ResolveLocaleOptions): string {\n const { supported, fallback = supported[0] ?? 'en', storageKey = LOCALE_STORAGE_KEY } = options;\n\n // the document you are looking at wins: render put the page under that prefix already translated\n const path = options.path ?? currentPath();\n if (path) {\n const segment = path.split('/').find(Boolean);\n const match = segment && matchSupported(segment, supported);\n if (match) return match;\n }\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 progressive BCP-47 narrowing (zh-Hant-TW → zh-Hant → zh)\nfunction matchSupported(lang: string, supported: string[]): string | undefined {\n for (const candidate of narrowLocales(lang)) {\n if (supported.includes(candidate)) return candidate;\n }\n return 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 for (const candidate of narrowLocales(lang.toLowerCase())) {\n const match = supported.find((s) => s.toLowerCase() === candidate);\n if (match) return match;\n }\n return undefined;\n}\n\n// per-request negotiation shared by SSR integrations: cookie value → Accept-Language → fallback\nexport interface RequestLocaleOptions {\n supported: string[];\n cookie?: string | null;\n header?: string | null;\n fallback?: string;\n}\n\nexport function resolveRequestLocale(options: RequestLocaleOptions): string {\n const { supported, cookie, header, fallback = supported[0] ?? 'en' } = options;\n if (cookie) {\n // '' sentinel = no match → fall through to the header\n const match = negotiateLocale(cookie, supported, '');\n if (match) return match;\n }\n return negotiateLocale(header, supported, fallback);\n}\n\nexport interface SwitchLocaleOptions {\n cookie?: string | false;\n maxAge?: number;\n}\n\nconst YEAR = 31536000;\n\n// shared by the SSR integrations: catalog first (no flash), then locale, then persistence\nexport async function switchLocale(\n instance: Pick<Verbaly, 'loadLocale' | 'setLocale'>,\n locale: string,\n options: SwitchLocaleOptions = {},\n): Promise<void> {\n const { cookie = LOCALE_STORAGE_KEY, maxAge = YEAR } = options;\n await instance.loadLocale(locale);\n instance.setLocale(locale);\n if (typeof document === 'undefined') return; // SSR-safe no-op\n if (cookie) {\n document.cookie = `${cookie}=${encodeURIComponent(locale)}; path=/; max-age=${maxAge}; samesite=lax`;\n }\n document.documentElement.lang = locale;\n document.documentElement.dir = localeDirection(locale);\n}\n\nexport function persistLocale(\n locale: string,\n storageKey: string | false = LOCALE_STORAGE_KEY,\n): void {\n if (storageKey) getStorage()?.setItem(storageKey, locale);\n if (typeof document !== 'undefined') {\n document.documentElement.lang = locale;\n document.documentElement.dir = localeDirection(locale);\n }\n}\n\nfunction currentPath(): string | undefined {\n // require document like every other browser check: a server has no page to read a prefix from\n return typeof document !== 'undefined' && typeof location !== 'undefined'\n ? location.pathname\n : undefined;\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","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' || style === 'percent' || style === 'currency' ? style : '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 { narrowLocales } from './locale';\nimport { parse } from './parse';\nimport { warnOnce } from './warn';\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 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 = narrowLocales(locale);\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) {\n warnOnce(`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, key });\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 for (const candidate of narrowLocales(target)) {\n if (loaders[candidate]) return loaded.has(candidate) ? undefined : candidate;\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 void loadLocale(next).catch(() => {\n warnOnce(`failed to load catalog for \"${next}\"`);\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 ? { from: 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\n// text runs only, post-tokenize: decoded braces/angles never re-enter a parser\nconst ENTITY = /&(?:(lt|gt|amp)|#(\\d+)|#[xX]([0-9a-fA-F]+));/g;\nconst ENTITY_MAP: Record<string, string> = { lt: '<', gt: '>', amp: '&' };\nconst decodeEntities = (s: string): string =>\n s.replace(ENTITY, (full, name?: string, dec?: string, hex?: string) => {\n if (name) return ENTITY_MAP[name]!;\n const code = dec ? parseInt(dec, 10) : parseInt(hex!, 16);\n return code <= 0x10ffff ? String.fromCodePoint(code) : full;\n });\n\nexport function parseTags(text: string): TagNode[] {\n TAG.lastIndex = 0;\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(decodeEntities(s));\n };\n\n let last = 0;\n let m: RegExpExecArray | null;\n while ((m = TAG.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 { narrowLocales } from './locale';\nimport { parseTags, type TagNode } from './tags';\nimport type { DictionaryInput, Params, Verbaly } from './types';\nimport { warnOnce } from './warn';\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;\nconst URL_ATTR = /^(href|src|xlink:href|action|formaction)$/;\nconst BLOCKED_ATTR = /^(style|srcdoc)$/;\n\nexport function safeHref(href: string): string | undefined {\n if (UNSAFE_HREF.test(href)) {\n warnOnce(`blocked unsafe href: ${href}`);\n return undefined;\n }\n return href;\n}\n\n// one link normalization for core + every adapter (applies safeHref)\nexport function normalizeLink(link: RichLink): { href?: string; target?: string; rel?: string } {\n const { href, target, rel } = typeof link === 'string' ? { href: link } : link;\n return { href: safeHref(href), target, rel };\n}\n\n// one attribute guard for bindDom + render, a catalog is untrusted input: undefined = skip\nexport function safeAttribute(name: string, value: string): string | undefined {\n const lower = name.toLowerCase();\n if (lower.startsWith('on') || BLOCKED_ATTR.test(lower)) return undefined;\n if (URL_ATTR.test(lower)) return safeHref(value);\n return value;\n}\n\n// children never reach a void element: a browser parses <br></br> as two <br>, hydration as one\nexport const VOID_TAGS = [\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\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; value: Params | undefined }>();\n const linksCache = new WeakMap<\n Element,\n { raw: string | null; value: Record<string, RichLink> | undefined }\n >();\n const attrsCache = new WeakMap<Element, { raw: string | null; value: Params | undefined }>();\n\n function fromCache<T>(\n cache: WeakMap<Element, { raw: string | null; value: T }>,\n el: Element,\n raw: string | null,\n compute: () => T,\n ): T {\n const hit = cache.get(el);\n if (hit && hit.raw === raw) return hit.value;\n const value = compute();\n cache.set(el, { raw, value });\n return value;\n }\n\n function cachedArgs(el: Element): Params | undefined {\n const raw = el.getAttribute(argsAttr);\n return fromCache(argsCache, el, raw, () => parseArgs(raw));\n }\n\n function cachedLinks(el: Element): Record<string, RichLink> | undefined {\n const raw = el.getAttribute(linksAttr);\n if (!raw) return globalLinks;\n return fromCache(linksCache, el, raw, () => {\n const own = parseArgs(raw) as Record<string, RichLink> | undefined;\n return own ? (globalLinks ? { ...globalLinks, ...own } : own) : globalLinks;\n });\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 continue;\n }\n const link = links?.[node.name];\n if (link !== undefined) {\n const { href, target, rel } = normalizeLink(link);\n const a = el.ownerDocument.createElement('a');\n if (href !== undefined) a.setAttribute('href', href);\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 if (!VOID_TAGS.includes(node.name)) 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 // pre-rendered html wins until this locale resolves: repainting it is the flash render kills\n let trustServerHtml = true;\n\n function holdBack(key: string, current: string | null): boolean {\n if (!trustServerHtml || !current?.trim()) return false;\n return instance.inspect(key)?.from !== instance.locale;\n }\n\n function render(el: Element): void {\n const args = cachedArgs(el);\n const key = el.getAttribute(attr);\n if (key && !holdBack(key, el.textContent)) {\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 rawAttrs = el.getAttribute(attrsAttr);\n const attrMap = fromCache(attrsCache, el, rawAttrs, () => parseArgs(rawAttrs));\n if (attrMap) {\n for (const [name, attrKey] of Object.entries(attrMap)) {\n if (typeof attrKey !== 'string') continue;\n if (holdBack(attrKey, el.getAttribute(name))) continue;\n const value = safeAttribute(name, t(attrKey, args));\n if (value !== undefined) el.setAttribute(name, value);\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 warnOnLangMismatch(instance.locale);\n renderAll(root);\n // from here the dom is ours: a stale value from a previous locale must not survive a switch\n trustServerHtml = false;\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\n// render writes <html lang>, so a disagreement here means the page is about to be translated away\nfunction warnOnLangMismatch(locale: string): void {\n const lang = document.documentElement.lang;\n if (!lang || narrowLocales(lang).includes(locale) || narrowLocales(locale).includes(lang)) return;\n warnOnce(\n `the page is <html lang=\"${lang}\"> and this instance is in \"${locale}\", so bindDom is about to ` +\n `translate it away: resolve the locale from the url (resolveLocale reads it) before binding`,\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 warnOnce(`invalid args JSON: ${raw}`);\n return undefined;\n }\n}\n"],"mappings":";;AACA,MAAM,yBAAS,IAAI,IAAY;AAE/B,SAAgB,SAAS,SAAuB;CAC9C,IAAI,OAAO,IAAI,OAAO,GAAG;CACzB,OAAO,IAAI,OAAO;CAClB,QAAQ,KAAK,aAAa,SAAS;AACrC;;;ACJA,SAAgB,QACd,MACA,SAAS,IACT,MAA8B,CAAC,GACP;CAExB,IAAI,CAAC,QAAQ,IAAI,GAAG,OAAO;CAC3B,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,IAAI,QAAQ,KAAK,GAAG,QAAQ,OAAO,MAAM,GAAG;OAC5C,SAAS,qBAAqB,KAAK,4CAA4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IAAI,CAAC,CAAC,SAAS,MAAM,KAAK,cAAc,MAAM,CAAC,CAAC,SAAS,IAAI,GAAG;CAC3F,SACE,2BAA2B,KAAK,8BAA8B,OAAO,qHAEvE;AACF;AAEA,SAAS,UAAU,KAAwC;CACzD,IAAI,CAAC,KAAK,OAAO,KAAA;CACjB,IAAI;EACF,OAAO,KAAK,MAAM,GAAG;CACvB,QAAQ;EACN,SAAS,sBAAsB,KAAK;EACpC;CACF;AACF"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/warn.ts","../src/flatten.ts","../src/intl.ts","../src/format.ts","../src/locale.ts","../src/icu.ts","../src/parse.ts","../src/instance.ts","../src/tags.ts","../src/dom.ts"],"sourcesContent":["// one warn-once for the whole runtime: the set is unbounded, so a message never carries a value\nconst warned = new Set<string>();\n\nexport function warnOnce(message: string): void {\n if (warned.has(message)) return;\n warned.add(message);\n console.warn(`[verbaly] ${message}`);\n}\n","import type { MessageTree } from './types';\nimport { warnOnce } from './warn';\n\nexport function flatten(\n tree: MessageTree,\n prefix = '',\n out: Record<string, string> = {},\n): Record<string, string> {\n // a catalog is untrusted input: a lazy loader, addMessages or a CMS never crosses the build gate\n if (!isGroup(tree)) return out;\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 if (isGroup(value)) flatten(value, path, out);\n else warnOnce(`catalog value at \"${path}\" is not text, so the key renders as itself`);\n }\n return out;\n}\n\nfunction isGroup(value: unknown): value is MessageTree {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\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>();\nconst dnCache = new Map<string, Intl.DisplayNames>();\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\nexport function displayNames(locale: string): Intl.DisplayNames {\n return cached(dnCache, locale, () => new Intl.DisplayNames(locale, { type: 'language' }));\n}\n","import { dateTimeFormat, listFormat, numberFormat, pluralRules, relativeTimeFormat } from './intl';\nimport type { MessageNode, ParamNode } from './parse';\nimport type { Formatter, Params } from './types';\nimport { warnOnce } from './warn';\n\ninterface FormatContext {\n locale: string;\n params: Params | undefined;\n formatters: Record<string, Formatter>;\n hashValue?: unknown;\n key?: string;\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, ctx);\n else out += formatParam(node, ctx);\n }\n return out;\n}\n\n// every warn names its message: keying on the param alone silenced the second message with the gap\nfunction where(ctx: FormatContext): string {\n return ctx.key ? ` in \"${ctx.key}\"` : '';\n}\n\nfunction formatParam(node: ParamNode, ctx: FormatContext): string {\n const value = ctx.params?.[node.name];\n if (value === undefined) {\n warnOnce(`missing param \"${node.name}\"${where(ctx)}`);\n return `{${node.name}}`;\n }\n\n if (node.variants) {\n const chosen = pickVariant(node.variants, value, ctx.locale, node.ordinal);\n // the value is left out of the warn on purpose: a counter walking 0..N must not grow the dedupe\n if (!chosen) {\n warnOnce(`no case matched for {${node.name}}${where(ctx)}, add an \"other\" case`);\n return '';\n }\n return formatNodes(chosen, { ...ctx, hashValue: value });\n }\n if (node.format) return applyFormat(value, node, ctx);\n return autoFormat(value, ctx.locale, ctx);\n}\n\n// the type of the offending value, never the value: the dedupe set must stay bounded\nfunction describe(value: unknown): string {\n if (value instanceof Date) return Number.isNaN(value.getTime()) ? 'an invalid Date' : 'a Date';\n if (Array.isArray(value)) return 'an array';\n if (value === null) return 'null';\n if (value === undefined) return 'undefined';\n const type = typeof value;\n return type === 'object' ? 'an object' : `a ${type}`;\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(value: unknown, node: ParamNode, ctx: FormatContext): string {\n const { name, arg } = node;\n const format = node.format!;\n const custom = ctx.formatters[format];\n if (custom) return custom(value, ctx.locale, arg);\n\n const { locale } = ctx;\n // a format missing its argument degrades like an invalid one: with a warn, never in silence\n const degrade = (problem: string): string => {\n warnOnce(`{${name}:${format}}${where(ctx)} ${problem}`);\n return String(value);\n };\n\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 degrade('needs an argument like /USD');\n try {\n return numberFormat(locale, { style: 'currency', currency: arg }).format(Number(value));\n } catch {\n return degrade(`does not know the currency \"${arg}\"`);\n }\n case 'date':\n try {\n return dateTimeFormat(\n locale,\n arg ? { dateStyle: arg as Intl.DateTimeFormatOptions['dateStyle'] } : undefined,\n ).format(toDate(value));\n } catch {\n return degrade(`cannot format ${describe(value)}${arg ? ` with style \"${arg}\"` : ''}`);\n }\n case 'time':\n try {\n return dateTimeFormat(locale, {\n timeStyle: (arg ?? 'short') as Intl.DateTimeFormatOptions['timeStyle'],\n }).format(toDate(value));\n } catch {\n return degrade(`cannot format ${describe(value)} with style \"${arg ?? 'short'}\"`);\n }\n case 'relative':\n if (typeof value === 'number' && !arg) return degrade('needs an argument like /day');\n if (typeof value !== 'number' && !(value instanceof Date))\n return degrade('needs a number or a Date');\n return formatRelative(value, node, ctx);\n case 'list': {\n if (!Array.isArray(value)) return degrade('needs an array');\n const type = arg === 'or' ? 'disjunction' : arg === 'unit' ? 'unit' : 'conjunction';\n return listFormat(locale, type).format(value.map((item) => autoFormat(item, locale, ctx)));\n }\n case 'unit':\n if (!arg) return degrade('needs an argument like /kilometer');\n try {\n return numberFormat(locale, { style: 'unit', unit: arg }).format(Number(value));\n } catch {\n return degrade(`does not know the unit \"${arg}\"`);\n }\n default:\n return degrade('is not a format verbaly knows');\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: number | Date, node: ParamNode, ctx: FormatContext): string {\n const { arg } = node;\n try {\n const fmt = relativeTimeFormat(ctx.locale);\n if (typeof value === 'number') return fmt.format(value, arg as Intl.RelativeTimeFormatUnit);\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 fmt.format(Math.round(diffSec / per), arg as Intl.RelativeTimeFormatUnit);\n }\n const [unit, per] = REL_UNITS.find(([, s]) => Math.abs(diffSec) >= s) ?? ['second', 1];\n return fmt.format(Math.round(diffSec / per), unit);\n } catch {\n // an invalid Date lands here too, so the warn names both suspects instead of blaming the unit\n warnOnce(`{${node.name}:relative}${where(ctx)} cannot format ${describe(value)} as \"${arg}\"`);\n return String(value);\n }\n}\n\nexport function autoFormat(value: unknown, locale: string, ctx?: FormatContext): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'number') return numberFormat(locale).format(value);\n if (value instanceof Date) {\n // an invalid Date makes Intl throw: degrade like every other bad format input\n if (Number.isNaN(value.getTime())) {\n warnOnce(`an invalid Date${ctx ? where(ctx) : ''} renders as plain text`);\n return String(value);\n }\n return dateTimeFormat(locale).format(value);\n }\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 { displayNames } from './intl';\nimport type { Verbaly } from './types';\n\nexport interface ResolveLocaleOptions {\n supported: string[];\n fallback?: string;\n storageKey?: string | false;\n path?: string | false;\n base?: string;\n}\n\nexport interface LocaleFromPathOptions {\n supported: string[];\n path?: string;\n base?: string;\n}\n\n// shared identity: localStorage key (browser) + cookie name (SSR integrations)\nexport const LOCALE_STORAGE_KEY = 'verbaly-locale';\n\n// zh-Hant-TW → [zh-Hant-TW, zh-Hant, zh]\nexport function narrowLocales(lang: string): string[] {\n const out: string[] = [];\n const parts = lang.split('-');\n while (parts.length > 0) {\n out.push(parts.join('-'));\n parts.pop();\n }\n return out;\n}\n\n// fallback tables for engines without Intl.Locale getTextInfo (Firefox)\nconst RTL_SCRIPTS = /^(Arab|Aran|Hebr|Thaa|Nkoo|Syrc|Samr|Mand|Adlm|Rohg|Yezi)$/;\nconst RTL_LANGS = /^(ar|he|fa|ur|ps|sd|ug|yi|dv|ckb)$/;\n\ninterface TextInfoLocale extends Intl.Locale {\n getTextInfo?(): { direction?: string };\n textInfo?: { direction?: string };\n}\n\nexport function localeDirection(locale: string): 'ltr' | 'rtl' {\n try {\n const loc = new Intl.Locale(locale) as TextInfoLocale;\n const direction = (loc.getTextInfo?.() ?? loc.textInfo)?.direction;\n if (direction === 'rtl' || direction === 'ltr') return direction;\n const script = loc.script ?? loc.maximize().script;\n if (script) return RTL_SCRIPTS.test(script) ? 'rtl' : 'ltr';\n return RTL_LANGS.test(loc.language) ? 'rtl' : 'ltr';\n } catch {\n // malformed tag: best effort on the primary subtag, never throw\n return RTL_LANGS.test(locale.split('-')[0]!.toLowerCase()) ? 'rtl' : 'ltr';\n }\n}\n\n// localized language name for locale switchers; defaults to the endonym\nexport function localeName(locale: string, displayIn: string = locale): string {\n try {\n return displayNames(displayIn).of(locale) ?? locale;\n } catch {\n return locale; // unknown tag or missing Intl data: the code beats a crash\n }\n}\n\nexport interface LocalePathOptions {\n supported: string[];\n sourceLocale?: string;\n path?: string;\n base?: string;\n}\n\n// the inverse of what render writes: /es/docs → /pt/docs, and the source locale keeps no prefix\nexport function localePath(locale: string, options: LocalePathOptions): string {\n const { supported, sourceLocale } = options;\n const base = normalizeBase(options.base);\n const full = options.path ?? currentPath() ?? '/';\n const cut = full.search(/[?#]/);\n const path = stripBase(cut < 0 ? full : full.slice(0, cut), base);\n const rest = cut < 0 ? '' : full.slice(cut);\n\n const segments = path.split('/').filter(Boolean);\n if (segments[0] && matchPathSegment(segments[0], supported)) segments.shift();\n if (locale !== sourceLocale) segments.unshift(locale);\n const trailing = segments.length && path.endsWith('/') ? '/' : '';\n return `${base}/${segments.join('/')}${trailing}${rest}`;\n}\n\n// which tree this page belongs to: a fact of the url, so it answers undefined instead of guessing\nexport function localeFromPath(options: LocaleFromPathOptions): string | undefined {\n const path = options.path ?? currentPath();\n if (path === undefined) return undefined;\n const segment = stripBase(path, normalizeBase(options.base)).split('/').find(Boolean);\n return segment ? matchPathSegment(segment, options.supported) : undefined;\n}\n\nexport function resolveLocale(options: ResolveLocaleOptions): string {\n const { supported, fallback = supported[0] ?? 'en', storageKey = LOCALE_STORAGE_KEY } = options;\n\n // the document you are looking at wins: render put the page under that prefix already translated\n if (options.path !== false) {\n const match = localeFromPath({ supported, path: options.path, base: options.base });\n if (match) return match;\n }\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// 'app', '/app' and '/app/' all read as '/app'; nothing means the site sits at the root\nfunction normalizeBase(base: string | undefined): string {\n const trimmed = base?.replace(/^\\/+/, '').replace(/\\/+$/, '');\n return trimmed ? `/${trimmed}` : '';\n}\n\n// the boundary check is what keeps base /app from swallowing /application\nfunction stripBase(path: string, base: string): string {\n if (!base || !path.startsWith(base)) return path;\n const rest = path.slice(base.length);\n if (rest === '') return '/';\n return rest.startsWith('/') ? rest : path;\n}\n\n// language, optional script, optional region: what render writes, never a slug like pt-and-friends\nconst LOCALE_SEGMENT = /^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|\\d{3}))?$/i;\n\n// a segment is narrowed only when it is shaped like a tag: a slug must never become a locale\nfunction matchPathSegment(segment: string, supported: string[]): string | undefined {\n if (supported.includes(segment)) return segment;\n return LOCALE_SEGMENT.test(segment) ? matchSupported(segment, supported) : undefined;\n}\n\n// exact, then progressive BCP-47 narrowing (zh-Hant-TW → zh-Hant → zh)\nfunction matchSupported(lang: string, supported: string[]): string | undefined {\n for (const candidate of narrowLocales(lang)) {\n if (supported.includes(candidate)) return candidate;\n }\n return 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 for (const candidate of narrowLocales(lang.toLowerCase())) {\n const match = supported.find((s) => s.toLowerCase() === candidate);\n if (match) return match;\n }\n return undefined;\n}\n\n// per-request negotiation shared by SSR integrations: cookie value → Accept-Language → fallback\nexport interface RequestLocaleOptions {\n supported: string[];\n cookie?: string | null;\n header?: string | null;\n fallback?: string;\n}\n\nexport function resolveRequestLocale(options: RequestLocaleOptions): string {\n const { supported, cookie, header, fallback = supported[0] ?? 'en' } = options;\n if (cookie) {\n // '' sentinel = no match → fall through to the header\n const match = negotiateLocale(cookie, supported, '');\n if (match) return match;\n }\n return negotiateLocale(header, supported, fallback);\n}\n\nexport interface SwitchLocaleOptions {\n cookie?: string | false;\n maxAge?: number;\n}\n\nconst YEAR = 31536000;\n\n// shared by the SSR integrations: catalog first (no flash), then locale, then persistence\nexport async function switchLocale(\n instance: Pick<Verbaly, 'loadLocale' | 'setLocale'>,\n locale: string,\n options: SwitchLocaleOptions = {},\n): Promise<void> {\n const { cookie = LOCALE_STORAGE_KEY, maxAge = YEAR } = options;\n await instance.loadLocale(locale);\n instance.setLocale(locale);\n if (typeof document === 'undefined') return; // SSR-safe no-op\n if (cookie) {\n document.cookie = `${cookie}=${encodeURIComponent(locale)}; path=/; max-age=${maxAge}; samesite=lax`;\n }\n document.documentElement.lang = locale;\n document.documentElement.dir = localeDirection(locale);\n}\n\nexport function persistLocale(\n locale: string,\n storageKey: string | false = LOCALE_STORAGE_KEY,\n): void {\n if (storageKey) getStorage()?.setItem(storageKey, locale);\n if (typeof document !== 'undefined') {\n document.documentElement.lang = locale;\n document.documentElement.dir = localeDirection(locale);\n }\n}\n\nfunction currentPath(): string | undefined {\n // require document like every other browser check: a server has no page to read a prefix from\n return typeof document !== 'undefined' && typeof location !== 'undefined'\n ? location.pathname\n : undefined;\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","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' || style === 'percent' || style === 'currency' ? style : '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 { narrowLocales } from './locale';\nimport { parse } from './parse';\nimport { warnOnce } from './warn';\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 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 = narrowLocales(locale);\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) {\n warnOnce(`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, key });\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 autoLoad(locale);\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 // fire and forget: the UI re-renders when it lands, and a failure reports instead of rejecting\n function autoLoad(target: string): void {\n void loadLocale(target).catch(() => {\n warnOnce(`failed to load catalog for \"${target}\"`);\n });\n }\n\n function pendingLoader(target: string): string | undefined {\n for (const candidate of narrowLocales(target)) {\n if (loaders[candidate]) return loaded.has(candidate) ? undefined : candidate;\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 autoLoad(next);\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 ? { from: 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\n// text runs only, post-tokenize: decoded braces/angles never re-enter a parser\nconst ENTITY = /&(?:(lt|gt|amp)|#(\\d+)|#[xX]([0-9a-fA-F]+));/g;\nconst ENTITY_MAP: Record<string, string> = { lt: '<', gt: '>', amp: '&' };\nconst decodeEntities = (s: string): string =>\n s.replace(ENTITY, (full, name?: string, dec?: string, hex?: string) => {\n if (name) return ENTITY_MAP[name]!;\n const code = dec ? parseInt(dec, 10) : parseInt(hex!, 16);\n return code <= 0x10ffff ? String.fromCodePoint(code) : full;\n });\n\nexport function parseTags(text: string): TagNode[] {\n TAG.lastIndex = 0;\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(decodeEntities(s));\n };\n\n let last = 0;\n let m: RegExpExecArray | null;\n while ((m = TAG.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 { narrowLocales } from './locale';\nimport { parseTags, type TagNode } from './tags';\nimport type { DictionaryInput, Params, Verbaly } from './types';\nimport { warnOnce } from './warn';\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;\nconst URL_ATTR = /^(href|src|xlink:href|action|formaction)$/;\nconst BLOCKED_ATTR = /^(style|srcdoc)$/;\n\nexport function safeHref(href: string): string | undefined {\n if (UNSAFE_HREF.test(href)) {\n warnOnce(`blocked unsafe href: ${href}`);\n return undefined;\n }\n return href;\n}\n\n// one link normalization for core + every adapter (applies safeHref)\nexport function normalizeLink(link: RichLink): { href?: string; target?: string; rel?: string } {\n const { href, target, rel } = typeof link === 'string' ? { href: link } : link;\n return { href: safeHref(href), target, rel };\n}\n\n// one attribute guard for bindDom + render, a catalog is untrusted input: undefined = skip\nexport function safeAttribute(name: string, value: string): string | undefined {\n const lower = name.toLowerCase();\n if (lower.startsWith('on') || BLOCKED_ATTR.test(lower)) return undefined;\n if (URL_ATTR.test(lower)) return safeHref(value);\n return value;\n}\n\n// children never reach a void element: a browser parses <br></br> as two <br>, hydration as one\nexport const VOID_TAGS = [\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\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; value: Params | undefined }>();\n const linksCache = new WeakMap<\n Element,\n { raw: string | null; value: Record<string, RichLink> | undefined }\n >();\n const attrsCache = new WeakMap<Element, { raw: string | null; value: Params | undefined }>();\n\n function fromCache<T>(\n cache: WeakMap<Element, { raw: string | null; value: T }>,\n el: Element,\n raw: string | null,\n compute: () => T,\n ): T {\n const hit = cache.get(el);\n if (hit && hit.raw === raw) return hit.value;\n const value = compute();\n cache.set(el, { raw, value });\n return value;\n }\n\n function cachedArgs(el: Element): Params | undefined {\n const raw = el.getAttribute(argsAttr);\n return fromCache(argsCache, el, raw, () => parseArgs(raw));\n }\n\n function cachedLinks(el: Element): Record<string, RichLink> | undefined {\n const raw = el.getAttribute(linksAttr);\n if (!raw) return globalLinks;\n return fromCache(linksCache, el, raw, () => {\n const own = parseArgs(raw) as Record<string, RichLink> | undefined;\n return own ? (globalLinks ? { ...globalLinks, ...own } : own) : globalLinks;\n });\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 continue;\n }\n const link = links?.[node.name];\n if (link !== undefined) {\n const { href, target, rel } = normalizeLink(link);\n const a = el.ownerDocument.createElement('a');\n if (href !== undefined) a.setAttribute('href', href);\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 if (!VOID_TAGS.includes(node.name)) 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 // pre-rendered html wins until this locale resolves: repainting it is the flash render kills\n let trustServerHtml = true;\n\n function holdBack(key: string, current: string | null): boolean {\n if (!trustServerHtml || !current?.trim()) return false;\n return instance.inspect(key)?.from !== instance.locale;\n }\n\n function render(el: Element): void {\n const args = cachedArgs(el);\n const key = el.getAttribute(attr);\n if (key && !holdBack(key, el.textContent)) {\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 rawAttrs = el.getAttribute(attrsAttr);\n const attrMap = fromCache(attrsCache, el, rawAttrs, () => parseArgs(rawAttrs));\n if (attrMap) {\n for (const [name, attrKey] of Object.entries(attrMap)) {\n if (typeof attrKey !== 'string') continue;\n if (holdBack(attrKey, el.getAttribute(name))) continue;\n const value = safeAttribute(name, t(attrKey, args));\n if (value !== undefined) el.setAttribute(name, value);\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 warnOnLangMismatch(instance.locale);\n renderAll(root);\n // from here the dom is ours: a stale value from a previous locale must not survive a switch\n trustServerHtml = false;\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\n// render writes <html lang>, so a disagreement here means the page is about to be translated away\nfunction warnOnLangMismatch(locale: string): void {\n const lang = document.documentElement.lang;\n if (!lang || narrowLocales(lang).includes(locale) || narrowLocales(locale).includes(lang)) return;\n warnOnce(\n `the page is <html lang=\"${lang}\"> and this instance is in \"${locale}\", so bindDom is about to ` +\n `translate it away: read the url with localeFromPath when it carries the locale, and call ` +\n `persistLocale first when it does not`,\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 warnOnce(`invalid args JSON: ${raw}`);\n return undefined;\n }\n}\n"],"mappings":";;AACA,MAAM,yBAAS,IAAI,IAAY;AAE/B,SAAgB,SAAS,SAAuB;CAC9C,IAAI,OAAO,IAAI,OAAO,GAAG;CACzB,OAAO,IAAI,OAAO;CAClB,QAAQ,KAAK,aAAa,SAAS;AACrC;;;ACJA,SAAgB,QACd,MACA,SAAS,IACT,MAA8B,CAAC,GACP;CAExB,IAAI,CAAC,QAAQ,IAAI,GAAG,OAAO;CAC3B,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,IAAI,QAAQ,KAAK,GAAG,QAAQ,OAAO,MAAM,GAAG;OAC5C,SAAS,qBAAqB,KAAK,4CAA4C;CACtF;CACA,OAAO;AACT;AAEA,SAAS,QAAQ,OAAsC;CACrD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;;;ACrBA,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;AACjD,MAAM,0BAAU,IAAI,IAA+B;AAEnD,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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M;OACf,IAAI,OAAO,SAAS,aACpB;QAAA,MAAM,QAAQ,OAAO,YACxB,IAAI,gBAAgB,SAAS,UAAU,IAAI;EAAA;CAInD,CAAC;CAED,SAAS,QAAQ,gBAAgB,WAAW,KAAK,kBAAmB,MAAe;EACjF,WAAW;EACX,SAAS;EACT,YAAY;EACZ,iBAAiB;GAAC;GAAM;GAAU;GAAW;GAAU;EAAS;CAClE,CAAC;CAED,aAAa;EACX,YAAY;EACZ,SAAS,WAAW;CACtB;AACF;AAGA,SAAS,mBAAmB,QAAsB;CAChD,MAAM,OAAO,SAAS,gBAAgB;CACtC,IAAI,CAAC,QAAQ,cAAc,IAAI,CAAC,CAAC,SAAS,MAAM,KAAK,cAAc,MAAM,CAAC,CAAC,SAAS,IAAI,GAAG;CAC3F,SACE,2BAA2B,KAAK,8BAA8B,OAAO,wJAGvE;AACF;AAEA,SAAS,UAAU,KAAwC;CACzD,IAAI,CAAC,KAAK,OAAO,KAAA;CACjB,IAAI;EACF,OAAO,KAAK,MAAM,GAAG;CACvB,QAAQ;EACN,SAAS,sBAAsB,KAAK;EACpC;CACF;AACF"}
package/dist/index.d.cts CHANGED
@@ -31,6 +31,12 @@ interface ResolveLocaleOptions {
31
31
  fallback?: string;
32
32
  storageKey?: string | false;
33
33
  path?: string | false;
34
+ base?: string;
35
+ }
36
+ interface LocaleFromPathOptions {
37
+ supported: string[];
38
+ path?: string;
39
+ base?: string;
34
40
  }
35
41
  declare const LOCALE_STORAGE_KEY = "verbaly-locale";
36
42
  declare function localeDirection(locale: string): 'ltr' | 'rtl';
@@ -39,8 +45,10 @@ interface LocalePathOptions {
39
45
  supported: string[];
40
46
  sourceLocale?: string;
41
47
  path?: string;
48
+ base?: string;
42
49
  }
43
50
  declare function localePath(locale: string, options: LocalePathOptions): string;
51
+ declare function localeFromPath(options: LocaleFromPathOptions): string | undefined;
44
52
  declare function resolveLocale(options: ResolveLocaleOptions): string;
45
53
  declare function negotiateLocale(header: string | null | undefined, supported: string[], fallback?: string): string;
46
54
  interface RequestLocaleOptions {
@@ -84,5 +92,5 @@ type TagNode = string | {
84
92
  };
85
93
  declare function parseTags(text: string): TagNode[];
86
94
  //#endregion
87
- export { type BindDomOptions, type DictionaryInput, type FlatKeys, type Formatter, type KeysOf, LOCALE_STORAGE_KEY, type LocaleLoader, type LocalePathOptions, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, RICH_TAGS, type RequestLocaleOptions, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type SwitchLocaleOptions, type TArgs, type TFunction, type TagNode, VOID_TAGS, type Verbaly, type VerbalyOptions, bindDom, createVerbaly, flatten, localeDirection, localeName, localePath, negotiateLocale, normalizeLink, parse, parseTags, persistLocale, resolveLocale, resolveRequestLocale, safeAttribute, safeHref, switchLocale };
95
+ export { type BindDomOptions, type DictionaryInput, type FlatKeys, type Formatter, type KeysOf, LOCALE_STORAGE_KEY, type LocaleFromPathOptions, type LocaleLoader, type LocalePathOptions, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, RICH_TAGS, type RequestLocaleOptions, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type SwitchLocaleOptions, type TArgs, type TFunction, type TagNode, VOID_TAGS, type Verbaly, type VerbalyOptions, bindDom, createVerbaly, flatten, localeDirection, localeFromPath, localeName, localePath, negotiateLocale, normalizeLink, parse, parseTags, persistLocale, resolveLocale, resolveRequestLocale, safeAttribute, safeHref, switchLocale };
88
96
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -31,6 +31,12 @@ interface ResolveLocaleOptions {
31
31
  fallback?: string;
32
32
  storageKey?: string | false;
33
33
  path?: string | false;
34
+ base?: string;
35
+ }
36
+ interface LocaleFromPathOptions {
37
+ supported: string[];
38
+ path?: string;
39
+ base?: string;
34
40
  }
35
41
  declare const LOCALE_STORAGE_KEY = "verbaly-locale";
36
42
  declare function localeDirection(locale: string): 'ltr' | 'rtl';
@@ -39,8 +45,10 @@ interface LocalePathOptions {
39
45
  supported: string[];
40
46
  sourceLocale?: string;
41
47
  path?: string;
48
+ base?: string;
42
49
  }
43
50
  declare function localePath(locale: string, options: LocalePathOptions): string;
51
+ declare function localeFromPath(options: LocaleFromPathOptions): string | undefined;
44
52
  declare function resolveLocale(options: ResolveLocaleOptions): string;
45
53
  declare function negotiateLocale(header: string | null | undefined, supported: string[], fallback?: string): string;
46
54
  interface RequestLocaleOptions {
@@ -84,5 +92,5 @@ type TagNode = string | {
84
92
  };
85
93
  declare function parseTags(text: string): TagNode[];
86
94
  //#endregion
87
- export { type BindDomOptions, type DictionaryInput, type FlatKeys, type Formatter, type KeysOf, LOCALE_STORAGE_KEY, type LocaleLoader, type LocalePathOptions, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, RICH_TAGS, type RequestLocaleOptions, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type SwitchLocaleOptions, type TArgs, type TFunction, type TagNode, VOID_TAGS, type Verbaly, type VerbalyOptions, bindDom, createVerbaly, flatten, localeDirection, localeName, localePath, negotiateLocale, normalizeLink, parse, parseTags, persistLocale, resolveLocale, resolveRequestLocale, safeAttribute, safeHref, switchLocale };
95
+ export { type BindDomOptions, type DictionaryInput, type FlatKeys, type Formatter, type KeysOf, LOCALE_STORAGE_KEY, type LocaleFromPathOptions, type LocaleLoader, type LocalePathOptions, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, RICH_TAGS, type RequestLocaleOptions, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type SwitchLocaleOptions, type TArgs, type TFunction, type TagNode, VOID_TAGS, type Verbaly, type VerbalyOptions, bindDom, createVerbaly, flatten, localeDirection, localeFromPath, localeName, localePath, negotiateLocale, normalizeLink, parse, parseTags, persistLocale, resolveLocale, resolveRequestLocale, safeAttribute, safeHref, switchLocale };
88
96
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -238,22 +238,31 @@ function localeName(locale, displayIn = locale) {
238
238
  }
239
239
  function localePath(locale, options) {
240
240
  const { supported, sourceLocale } = options;
241
+ const base = normalizeBase(options.base);
241
242
  const full = options.path ?? currentPath() ?? "/";
242
243
  const cut = full.search(/[?#]/);
243
- const path = cut < 0 ? full : full.slice(0, cut);
244
+ const path = stripBase(cut < 0 ? full : full.slice(0, cut), base);
244
245
  const rest = cut < 0 ? "" : full.slice(cut);
245
246
  const segments = path.split("/").filter(Boolean);
246
- if (segments[0] && matchSupported(segments[0], supported)) segments.shift();
247
+ if (segments[0] && matchPathSegment(segments[0], supported)) segments.shift();
247
248
  if (locale !== sourceLocale) segments.unshift(locale);
248
249
  const trailing = segments.length && path.endsWith("/") ? "/" : "";
249
- return `/${segments.join("/")}${trailing}${rest}`;
250
+ return `${base}/${segments.join("/")}${trailing}${rest}`;
251
+ }
252
+ function localeFromPath(options) {
253
+ const path = options.path ?? currentPath();
254
+ if (path === void 0) return void 0;
255
+ const segment = stripBase(path, normalizeBase(options.base)).split("/").find(Boolean);
256
+ return segment ? matchPathSegment(segment, options.supported) : void 0;
250
257
  }
251
258
  function resolveLocale(options) {
252
259
  const { supported, fallback = supported[0] ?? "en", storageKey = LOCALE_STORAGE_KEY } = options;
253
- const path = options.path ?? currentPath();
254
- if (path) {
255
- const segment = path.split("/").find(Boolean);
256
- const match = segment && matchSupported(segment, supported);
260
+ if (options.path !== false) {
261
+ const match = localeFromPath({
262
+ supported,
263
+ path: options.path,
264
+ base: options.base
265
+ });
257
266
  if (match) return match;
258
267
  }
259
268
  if (storageKey) {
@@ -267,6 +276,21 @@ function resolveLocale(options) {
267
276
  }
268
277
  return fallback;
269
278
  }
279
+ function normalizeBase(base) {
280
+ const trimmed = base?.replace(/^\/+/, "").replace(/\/+$/, "");
281
+ return trimmed ? `/${trimmed}` : "";
282
+ }
283
+ function stripBase(path, base) {
284
+ if (!base || !path.startsWith(base)) return path;
285
+ const rest = path.slice(base.length);
286
+ if (rest === "") return "/";
287
+ return rest.startsWith("/") ? rest : path;
288
+ }
289
+ const LOCALE_SEGMENT = /^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|\d{3}))?$/i;
290
+ function matchPathSegment(segment, supported) {
291
+ if (supported.includes(segment)) return segment;
292
+ return LOCALE_SEGMENT.test(segment) ? matchSupported(segment, supported) : void 0;
293
+ }
270
294
  function matchSupported(lang, supported) {
271
295
  for (const candidate of narrowLocales(lang)) if (supported.includes(candidate)) return candidate;
272
296
  }
@@ -715,11 +739,17 @@ function createVerbaly(options = {}) {
715
739
  version += 1;
716
740
  for (const fn of listeners) fn();
717
741
  }
742
+ autoLoad(locale);
718
743
  const t = ((first, ...rest) => {
719
744
  if (isTemplateStrings(first)) return tagged(first, rest);
720
745
  return translate(first, rest[0]);
721
746
  });
722
747
  t.id = () => (strings, ...values) => tagged(strings, values);
748
+ function autoLoad(target) {
749
+ loadLocale(target).catch(() => {
750
+ warnOnce(`failed to load catalog for "${target}"`);
751
+ });
752
+ }
723
753
  function pendingLoader(target) {
724
754
  for (const candidate of narrowLocales(target)) if (loaders[candidate]) return loaded.has(candidate) ? void 0 : candidate;
725
755
  }
@@ -758,9 +788,7 @@ function createVerbaly(options = {}) {
758
788
  },
759
789
  t,
760
790
  setLocale(next) {
761
- loadLocale(next).catch(() => {
762
- warnOnce(`failed to load catalog for "${next}"`);
763
- });
791
+ autoLoad(next);
764
792
  if (next === locale) return;
765
793
  locale = next;
766
794
  chainCache = null;
@@ -1020,7 +1048,7 @@ function bindDom(instance, options = {}) {
1020
1048
  function warnOnLangMismatch(locale) {
1021
1049
  const lang = document.documentElement.lang;
1022
1050
  if (!lang || narrowLocales(lang).includes(locale) || narrowLocales(locale).includes(lang)) return;
1023
- warnOnce(`the page is <html lang="${lang}"> and this instance is in "${locale}", so bindDom is about to translate it away: resolve the locale from the url (resolveLocale reads it) before binding`);
1051
+ warnOnce(`the page is <html lang="${lang}"> and this instance is in "${locale}", so bindDom is about to translate it away: read the url with localeFromPath when it carries the locale, and call persistLocale first when it does not`);
1024
1052
  }
1025
1053
  function parseArgs(raw) {
1026
1054
  if (!raw) return void 0;
@@ -1032,6 +1060,6 @@ function parseArgs(raw) {
1032
1060
  }
1033
1061
  }
1034
1062
  //#endregion
1035
- export { LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, bindDom, createVerbaly, flatten, localeDirection, localeName, localePath, negotiateLocale, normalizeLink, parse, parseTags, persistLocale, resolveLocale, resolveRequestLocale, safeAttribute, safeHref, switchLocale };
1063
+ export { LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, bindDom, createVerbaly, flatten, localeDirection, localeFromPath, localeName, localePath, negotiateLocale, normalizeLink, parse, parseTags, persistLocale, resolveLocale, resolveRequestLocale, safeAttribute, safeHref, switchLocale };
1036
1064
 
1037
1065
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/warn.ts","../src/flatten.ts","../src/intl.ts","../src/format.ts","../src/locale.ts","../src/icu.ts","../src/parse.ts","../src/instance.ts","../src/tags.ts","../src/dom.ts"],"sourcesContent":["// one warn-once for the whole runtime: the set is unbounded, so a message never carries a value\nconst warned = new Set<string>();\n\nexport function warnOnce(message: string): void {\n if (warned.has(message)) return;\n warned.add(message);\n console.warn(`[verbaly] ${message}`);\n}\n","import type { MessageTree } from './types';\nimport { warnOnce } from './warn';\n\nexport function flatten(\n tree: MessageTree,\n prefix = '',\n out: Record<string, string> = {},\n): Record<string, string> {\n // a catalog is untrusted input: a lazy loader, addMessages or a CMS never crosses the build gate\n if (!isGroup(tree)) return out;\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 if (isGroup(value)) flatten(value, path, out);\n else warnOnce(`catalog value at \"${path}\" is not text, so the key renders as itself`);\n }\n return out;\n}\n\nfunction isGroup(value: unknown): value is MessageTree {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\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>();\nconst dnCache = new Map<string, Intl.DisplayNames>();\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\nexport function displayNames(locale: string): Intl.DisplayNames {\n return cached(dnCache, locale, () => new Intl.DisplayNames(locale, { type: 'language' }));\n}\n","import { dateTimeFormat, listFormat, numberFormat, pluralRules, relativeTimeFormat } from './intl';\nimport type { MessageNode, ParamNode } from './parse';\nimport type { Formatter, Params } from './types';\nimport { warnOnce } from './warn';\n\ninterface FormatContext {\n locale: string;\n params: Params | undefined;\n formatters: Record<string, Formatter>;\n hashValue?: unknown;\n key?: string;\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, ctx);\n else out += formatParam(node, ctx);\n }\n return out;\n}\n\n// every warn names its message: keying on the param alone silenced the second message with the gap\nfunction where(ctx: FormatContext): string {\n return ctx.key ? ` in \"${ctx.key}\"` : '';\n}\n\nfunction formatParam(node: ParamNode, ctx: FormatContext): string {\n const value = ctx.params?.[node.name];\n if (value === undefined) {\n warnOnce(`missing param \"${node.name}\"${where(ctx)}`);\n return `{${node.name}}`;\n }\n\n if (node.variants) {\n const chosen = pickVariant(node.variants, value, ctx.locale, node.ordinal);\n // the value is left out of the warn on purpose: a counter walking 0..N must not grow the dedupe\n if (!chosen) {\n warnOnce(`no case matched for {${node.name}}${where(ctx)}, add an \"other\" case`);\n return '';\n }\n return formatNodes(chosen, { ...ctx, hashValue: value });\n }\n if (node.format) return applyFormat(value, node, ctx);\n return autoFormat(value, ctx.locale, ctx);\n}\n\n// the type of the offending value, never the value: the dedupe set must stay bounded\nfunction describe(value: unknown): string {\n if (value instanceof Date) return Number.isNaN(value.getTime()) ? 'an invalid Date' : 'a Date';\n if (Array.isArray(value)) return 'an array';\n if (value === null) return 'null';\n if (value === undefined) return 'undefined';\n const type = typeof value;\n return type === 'object' ? 'an object' : `a ${type}`;\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(value: unknown, node: ParamNode, ctx: FormatContext): string {\n const { name, arg } = node;\n const format = node.format!;\n const custom = ctx.formatters[format];\n if (custom) return custom(value, ctx.locale, arg);\n\n const { locale } = ctx;\n // a format missing its argument degrades like an invalid one: with a warn, never in silence\n const degrade = (problem: string): string => {\n warnOnce(`{${name}:${format}}${where(ctx)} ${problem}`);\n return String(value);\n };\n\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 degrade('needs an argument like /USD');\n try {\n return numberFormat(locale, { style: 'currency', currency: arg }).format(Number(value));\n } catch {\n return degrade(`does not know the currency \"${arg}\"`);\n }\n case 'date':\n try {\n return dateTimeFormat(\n locale,\n arg ? { dateStyle: arg as Intl.DateTimeFormatOptions['dateStyle'] } : undefined,\n ).format(toDate(value));\n } catch {\n return degrade(`cannot format ${describe(value)}${arg ? ` with style \"${arg}\"` : ''}`);\n }\n case 'time':\n try {\n return dateTimeFormat(locale, {\n timeStyle: (arg ?? 'short') as Intl.DateTimeFormatOptions['timeStyle'],\n }).format(toDate(value));\n } catch {\n return degrade(`cannot format ${describe(value)} with style \"${arg ?? 'short'}\"`);\n }\n case 'relative':\n if (typeof value === 'number' && !arg) return degrade('needs an argument like /day');\n if (typeof value !== 'number' && !(value instanceof Date))\n return degrade('needs a number or a Date');\n return formatRelative(value, node, ctx);\n case 'list': {\n if (!Array.isArray(value)) return degrade('needs an array');\n const type = arg === 'or' ? 'disjunction' : arg === 'unit' ? 'unit' : 'conjunction';\n return listFormat(locale, type).format(value.map((item) => autoFormat(item, locale, ctx)));\n }\n case 'unit':\n if (!arg) return degrade('needs an argument like /kilometer');\n try {\n return numberFormat(locale, { style: 'unit', unit: arg }).format(Number(value));\n } catch {\n return degrade(`does not know the unit \"${arg}\"`);\n }\n default:\n return degrade('is not a format verbaly knows');\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: number | Date, node: ParamNode, ctx: FormatContext): string {\n const { arg } = node;\n try {\n const fmt = relativeTimeFormat(ctx.locale);\n if (typeof value === 'number') return fmt.format(value, arg as Intl.RelativeTimeFormatUnit);\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 fmt.format(Math.round(diffSec / per), arg as Intl.RelativeTimeFormatUnit);\n }\n const [unit, per] = REL_UNITS.find(([, s]) => Math.abs(diffSec) >= s) ?? ['second', 1];\n return fmt.format(Math.round(diffSec / per), unit);\n } catch {\n // an invalid Date lands here too, so the warn names both suspects instead of blaming the unit\n warnOnce(`{${node.name}:relative}${where(ctx)} cannot format ${describe(value)} as \"${arg}\"`);\n return String(value);\n }\n}\n\nexport function autoFormat(value: unknown, locale: string, ctx?: FormatContext): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'number') return numberFormat(locale).format(value);\n if (value instanceof Date) {\n // an invalid Date makes Intl throw: degrade like every other bad format input\n if (Number.isNaN(value.getTime())) {\n warnOnce(`an invalid Date${ctx ? where(ctx) : ''} renders as plain text`);\n return String(value);\n }\n return dateTimeFormat(locale).format(value);\n }\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 { displayNames } from './intl';\nimport type { Verbaly } from './types';\n\nexport interface ResolveLocaleOptions {\n supported: string[];\n fallback?: string;\n storageKey?: string | false;\n path?: string | false;\n}\n\n// shared identity: localStorage key (browser) + cookie name (SSR integrations)\nexport const LOCALE_STORAGE_KEY = 'verbaly-locale';\n\n// zh-Hant-TW → [zh-Hant-TW, zh-Hant, zh]\nexport function narrowLocales(lang: string): string[] {\n const out: string[] = [];\n const parts = lang.split('-');\n while (parts.length > 0) {\n out.push(parts.join('-'));\n parts.pop();\n }\n return out;\n}\n\n// fallback tables for engines without Intl.Locale getTextInfo (Firefox)\nconst RTL_SCRIPTS = /^(Arab|Aran|Hebr|Thaa|Nkoo|Syrc|Samr|Mand|Adlm|Rohg|Yezi)$/;\nconst RTL_LANGS = /^(ar|he|fa|ur|ps|sd|ug|yi|dv|ckb)$/;\n\ninterface TextInfoLocale extends Intl.Locale {\n getTextInfo?(): { direction?: string };\n textInfo?: { direction?: string };\n}\n\nexport function localeDirection(locale: string): 'ltr' | 'rtl' {\n try {\n const loc = new Intl.Locale(locale) as TextInfoLocale;\n const direction = (loc.getTextInfo?.() ?? loc.textInfo)?.direction;\n if (direction === 'rtl' || direction === 'ltr') return direction;\n const script = loc.script ?? loc.maximize().script;\n if (script) return RTL_SCRIPTS.test(script) ? 'rtl' : 'ltr';\n return RTL_LANGS.test(loc.language) ? 'rtl' : 'ltr';\n } catch {\n // malformed tag: best effort on the primary subtag, never throw\n return RTL_LANGS.test(locale.split('-')[0]!.toLowerCase()) ? 'rtl' : 'ltr';\n }\n}\n\n// localized language name for locale switchers; defaults to the endonym\nexport function localeName(locale: string, displayIn: string = locale): string {\n try {\n return displayNames(displayIn).of(locale) ?? locale;\n } catch {\n return locale; // unknown tag or missing Intl data: the code beats a crash\n }\n}\n\nexport interface LocalePathOptions {\n supported: string[];\n sourceLocale?: string;\n path?: string;\n}\n\n// the inverse of what render writes: /es/docs → /pt/docs, and the source locale keeps no prefix\nexport function localePath(locale: string, options: LocalePathOptions): string {\n const { supported, sourceLocale } = options;\n const full = options.path ?? currentPath() ?? '/';\n const cut = full.search(/[?#]/);\n const path = cut < 0 ? full : full.slice(0, cut);\n const rest = cut < 0 ? '' : full.slice(cut);\n\n const segments = path.split('/').filter(Boolean);\n if (segments[0] && matchSupported(segments[0], supported)) segments.shift();\n if (locale !== sourceLocale) segments.unshift(locale);\n const trailing = segments.length && path.endsWith('/') ? '/' : '';\n return `/${segments.join('/')}${trailing}${rest}`;\n}\n\nexport function resolveLocale(options: ResolveLocaleOptions): string {\n const { supported, fallback = supported[0] ?? 'en', storageKey = LOCALE_STORAGE_KEY } = options;\n\n // the document you are looking at wins: render put the page under that prefix already translated\n const path = options.path ?? currentPath();\n if (path) {\n const segment = path.split('/').find(Boolean);\n const match = segment && matchSupported(segment, supported);\n if (match) return match;\n }\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 progressive BCP-47 narrowing (zh-Hant-TW → zh-Hant → zh)\nfunction matchSupported(lang: string, supported: string[]): string | undefined {\n for (const candidate of narrowLocales(lang)) {\n if (supported.includes(candidate)) return candidate;\n }\n return 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 for (const candidate of narrowLocales(lang.toLowerCase())) {\n const match = supported.find((s) => s.toLowerCase() === candidate);\n if (match) return match;\n }\n return undefined;\n}\n\n// per-request negotiation shared by SSR integrations: cookie value → Accept-Language → fallback\nexport interface RequestLocaleOptions {\n supported: string[];\n cookie?: string | null;\n header?: string | null;\n fallback?: string;\n}\n\nexport function resolveRequestLocale(options: RequestLocaleOptions): string {\n const { supported, cookie, header, fallback = supported[0] ?? 'en' } = options;\n if (cookie) {\n // '' sentinel = no match → fall through to the header\n const match = negotiateLocale(cookie, supported, '');\n if (match) return match;\n }\n return negotiateLocale(header, supported, fallback);\n}\n\nexport interface SwitchLocaleOptions {\n cookie?: string | false;\n maxAge?: number;\n}\n\nconst YEAR = 31536000;\n\n// shared by the SSR integrations: catalog first (no flash), then locale, then persistence\nexport async function switchLocale(\n instance: Pick<Verbaly, 'loadLocale' | 'setLocale'>,\n locale: string,\n options: SwitchLocaleOptions = {},\n): Promise<void> {\n const { cookie = LOCALE_STORAGE_KEY, maxAge = YEAR } = options;\n await instance.loadLocale(locale);\n instance.setLocale(locale);\n if (typeof document === 'undefined') return; // SSR-safe no-op\n if (cookie) {\n document.cookie = `${cookie}=${encodeURIComponent(locale)}; path=/; max-age=${maxAge}; samesite=lax`;\n }\n document.documentElement.lang = locale;\n document.documentElement.dir = localeDirection(locale);\n}\n\nexport function persistLocale(\n locale: string,\n storageKey: string | false = LOCALE_STORAGE_KEY,\n): void {\n if (storageKey) getStorage()?.setItem(storageKey, locale);\n if (typeof document !== 'undefined') {\n document.documentElement.lang = locale;\n document.documentElement.dir = localeDirection(locale);\n }\n}\n\nfunction currentPath(): string | undefined {\n // require document like every other browser check: a server has no page to read a prefix from\n return typeof document !== 'undefined' && typeof location !== 'undefined'\n ? location.pathname\n : undefined;\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","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' || style === 'percent' || style === 'currency' ? style : '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 { narrowLocales } from './locale';\nimport { parse } from './parse';\nimport { warnOnce } from './warn';\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 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 = narrowLocales(locale);\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) {\n warnOnce(`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, key });\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 for (const candidate of narrowLocales(target)) {\n if (loaders[candidate]) return loaded.has(candidate) ? undefined : candidate;\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 void loadLocale(next).catch(() => {\n warnOnce(`failed to load catalog for \"${next}\"`);\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 ? { from: 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\n// text runs only, post-tokenize: decoded braces/angles never re-enter a parser\nconst ENTITY = /&(?:(lt|gt|amp)|#(\\d+)|#[xX]([0-9a-fA-F]+));/g;\nconst ENTITY_MAP: Record<string, string> = { lt: '<', gt: '>', amp: '&' };\nconst decodeEntities = (s: string): string =>\n s.replace(ENTITY, (full, name?: string, dec?: string, hex?: string) => {\n if (name) return ENTITY_MAP[name]!;\n const code = dec ? parseInt(dec, 10) : parseInt(hex!, 16);\n return code <= 0x10ffff ? String.fromCodePoint(code) : full;\n });\n\nexport function parseTags(text: string): TagNode[] {\n TAG.lastIndex = 0;\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(decodeEntities(s));\n };\n\n let last = 0;\n let m: RegExpExecArray | null;\n while ((m = TAG.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 { narrowLocales } from './locale';\nimport { parseTags, type TagNode } from './tags';\nimport type { DictionaryInput, Params, Verbaly } from './types';\nimport { warnOnce } from './warn';\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;\nconst URL_ATTR = /^(href|src|xlink:href|action|formaction)$/;\nconst BLOCKED_ATTR = /^(style|srcdoc)$/;\n\nexport function safeHref(href: string): string | undefined {\n if (UNSAFE_HREF.test(href)) {\n warnOnce(`blocked unsafe href: ${href}`);\n return undefined;\n }\n return href;\n}\n\n// one link normalization for core + every adapter (applies safeHref)\nexport function normalizeLink(link: RichLink): { href?: string; target?: string; rel?: string } {\n const { href, target, rel } = typeof link === 'string' ? { href: link } : link;\n return { href: safeHref(href), target, rel };\n}\n\n// one attribute guard for bindDom + render, a catalog is untrusted input: undefined = skip\nexport function safeAttribute(name: string, value: string): string | undefined {\n const lower = name.toLowerCase();\n if (lower.startsWith('on') || BLOCKED_ATTR.test(lower)) return undefined;\n if (URL_ATTR.test(lower)) return safeHref(value);\n return value;\n}\n\n// children never reach a void element: a browser parses <br></br> as two <br>, hydration as one\nexport const VOID_TAGS = [\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\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; value: Params | undefined }>();\n const linksCache = new WeakMap<\n Element,\n { raw: string | null; value: Record<string, RichLink> | undefined }\n >();\n const attrsCache = new WeakMap<Element, { raw: string | null; value: Params | undefined }>();\n\n function fromCache<T>(\n cache: WeakMap<Element, { raw: string | null; value: T }>,\n el: Element,\n raw: string | null,\n compute: () => T,\n ): T {\n const hit = cache.get(el);\n if (hit && hit.raw === raw) return hit.value;\n const value = compute();\n cache.set(el, { raw, value });\n return value;\n }\n\n function cachedArgs(el: Element): Params | undefined {\n const raw = el.getAttribute(argsAttr);\n return fromCache(argsCache, el, raw, () => parseArgs(raw));\n }\n\n function cachedLinks(el: Element): Record<string, RichLink> | undefined {\n const raw = el.getAttribute(linksAttr);\n if (!raw) return globalLinks;\n return fromCache(linksCache, el, raw, () => {\n const own = parseArgs(raw) as Record<string, RichLink> | undefined;\n return own ? (globalLinks ? { ...globalLinks, ...own } : own) : globalLinks;\n });\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 continue;\n }\n const link = links?.[node.name];\n if (link !== undefined) {\n const { href, target, rel } = normalizeLink(link);\n const a = el.ownerDocument.createElement('a');\n if (href !== undefined) a.setAttribute('href', href);\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 if (!VOID_TAGS.includes(node.name)) 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 // pre-rendered html wins until this locale resolves: repainting it is the flash render kills\n let trustServerHtml = true;\n\n function holdBack(key: string, current: string | null): boolean {\n if (!trustServerHtml || !current?.trim()) return false;\n return instance.inspect(key)?.from !== instance.locale;\n }\n\n function render(el: Element): void {\n const args = cachedArgs(el);\n const key = el.getAttribute(attr);\n if (key && !holdBack(key, el.textContent)) {\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 rawAttrs = el.getAttribute(attrsAttr);\n const attrMap = fromCache(attrsCache, el, rawAttrs, () => parseArgs(rawAttrs));\n if (attrMap) {\n for (const [name, attrKey] of Object.entries(attrMap)) {\n if (typeof attrKey !== 'string') continue;\n if (holdBack(attrKey, el.getAttribute(name))) continue;\n const value = safeAttribute(name, t(attrKey, args));\n if (value !== undefined) el.setAttribute(name, value);\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 warnOnLangMismatch(instance.locale);\n renderAll(root);\n // from here the dom is ours: a stale value from a previous locale must not survive a switch\n trustServerHtml = false;\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\n// render writes <html lang>, so a disagreement here means the page is about to be translated away\nfunction warnOnLangMismatch(locale: string): void {\n const lang = document.documentElement.lang;\n if (!lang || narrowLocales(lang).includes(locale) || narrowLocales(locale).includes(lang)) return;\n warnOnce(\n `the page is <html lang=\"${lang}\"> and this instance is in \"${locale}\", so bindDom is about to ` +\n `translate it away: resolve the locale from the url (resolveLocale reads it) before binding`,\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 warnOnce(`invalid args JSON: ${raw}`);\n return undefined;\n }\n}\n"],"mappings":";AACA,MAAM,yBAAS,IAAI,IAAY;AAE/B,SAAgB,SAAS,SAAuB;CAC9C,IAAI,OAAO,IAAI,OAAO,GAAG;CACzB,OAAO,IAAI,OAAO;CAClB,QAAQ,KAAK,aAAa,SAAS;AACrC;;;ACJA,SAAgB,QACd,MACA,SAAS,IACT,MAA8B,CAAC,GACP;CAExB,IAAI,CAAC,QAAQ,IAAI,GAAG,OAAO;CAC3B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAAI,GAAG;EAC/C,MAAM,OAAO,SAAS,GAAG,O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AClE,CAAC;CAED,aAAa;EACX,YAAY;EACZ,SAAS,WAAW;CACtB;AACF;AAGA,SAAS,mBAAmB,QAAsB;CAChD,MAAM,OAAO,SAAS,gBAAgB;CACtC,IAAI,CAAC,QAAQ,cAAc,IAAI,CAAC,CAAC,SAAS,MAAM,KAAK,cAAc,MAAM,CAAC,CAAC,SAAS,IAAI,GAAG;CAC3F,SACE,2BAA2B,KAAK,8BAA8B,OAAO,qHAEvE;AACF;AAEA,SAAS,UAAU,KAAwC;CACzD,IAAI,CAAC,KAAK,OAAO,KAAA;CACjB,IAAI;EACF,OAAO,KAAK,MAAM,GAAG;CACvB,QAAQ;EACN,SAAS,sBAAsB,KAAK;EACpC;CACF;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/warn.ts","../src/flatten.ts","../src/intl.ts","../src/format.ts","../src/locale.ts","../src/icu.ts","../src/parse.ts","../src/instance.ts","../src/tags.ts","../src/dom.ts"],"sourcesContent":["// one warn-once for the whole runtime: the set is unbounded, so a message never carries a value\nconst warned = new Set<string>();\n\nexport function warnOnce(message: string): void {\n if (warned.has(message)) return;\n warned.add(message);\n console.warn(`[verbaly] ${message}`);\n}\n","import type { MessageTree } from './types';\nimport { warnOnce } from './warn';\n\nexport function flatten(\n tree: MessageTree,\n prefix = '',\n out: Record<string, string> = {},\n): Record<string, string> {\n // a catalog is untrusted input: a lazy loader, addMessages or a CMS never crosses the build gate\n if (!isGroup(tree)) return out;\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 if (isGroup(value)) flatten(value, path, out);\n else warnOnce(`catalog value at \"${path}\" is not text, so the key renders as itself`);\n }\n return out;\n}\n\nfunction isGroup(value: unknown): value is MessageTree {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\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>();\nconst dnCache = new Map<string, Intl.DisplayNames>();\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\nexport function displayNames(locale: string): Intl.DisplayNames {\n return cached(dnCache, locale, () => new Intl.DisplayNames(locale, { type: 'language' }));\n}\n","import { dateTimeFormat, listFormat, numberFormat, pluralRules, relativeTimeFormat } from './intl';\nimport type { MessageNode, ParamNode } from './parse';\nimport type { Formatter, Params } from './types';\nimport { warnOnce } from './warn';\n\ninterface FormatContext {\n locale: string;\n params: Params | undefined;\n formatters: Record<string, Formatter>;\n hashValue?: unknown;\n key?: string;\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, ctx);\n else out += formatParam(node, ctx);\n }\n return out;\n}\n\n// every warn names its message: keying on the param alone silenced the second message with the gap\nfunction where(ctx: FormatContext): string {\n return ctx.key ? ` in \"${ctx.key}\"` : '';\n}\n\nfunction formatParam(node: ParamNode, ctx: FormatContext): string {\n const value = ctx.params?.[node.name];\n if (value === undefined) {\n warnOnce(`missing param \"${node.name}\"${where(ctx)}`);\n return `{${node.name}}`;\n }\n\n if (node.variants) {\n const chosen = pickVariant(node.variants, value, ctx.locale, node.ordinal);\n // the value is left out of the warn on purpose: a counter walking 0..N must not grow the dedupe\n if (!chosen) {\n warnOnce(`no case matched for {${node.name}}${where(ctx)}, add an \"other\" case`);\n return '';\n }\n return formatNodes(chosen, { ...ctx, hashValue: value });\n }\n if (node.format) return applyFormat(value, node, ctx);\n return autoFormat(value, ctx.locale, ctx);\n}\n\n// the type of the offending value, never the value: the dedupe set must stay bounded\nfunction describe(value: unknown): string {\n if (value instanceof Date) return Number.isNaN(value.getTime()) ? 'an invalid Date' : 'a Date';\n if (Array.isArray(value)) return 'an array';\n if (value === null) return 'null';\n if (value === undefined) return 'undefined';\n const type = typeof value;\n return type === 'object' ? 'an object' : `a ${type}`;\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(value: unknown, node: ParamNode, ctx: FormatContext): string {\n const { name, arg } = node;\n const format = node.format!;\n const custom = ctx.formatters[format];\n if (custom) return custom(value, ctx.locale, arg);\n\n const { locale } = ctx;\n // a format missing its argument degrades like an invalid one: with a warn, never in silence\n const degrade = (problem: string): string => {\n warnOnce(`{${name}:${format}}${where(ctx)} ${problem}`);\n return String(value);\n };\n\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 degrade('needs an argument like /USD');\n try {\n return numberFormat(locale, { style: 'currency', currency: arg }).format(Number(value));\n } catch {\n return degrade(`does not know the currency \"${arg}\"`);\n }\n case 'date':\n try {\n return dateTimeFormat(\n locale,\n arg ? { dateStyle: arg as Intl.DateTimeFormatOptions['dateStyle'] } : undefined,\n ).format(toDate(value));\n } catch {\n return degrade(`cannot format ${describe(value)}${arg ? ` with style \"${arg}\"` : ''}`);\n }\n case 'time':\n try {\n return dateTimeFormat(locale, {\n timeStyle: (arg ?? 'short') as Intl.DateTimeFormatOptions['timeStyle'],\n }).format(toDate(value));\n } catch {\n return degrade(`cannot format ${describe(value)} with style \"${arg ?? 'short'}\"`);\n }\n case 'relative':\n if (typeof value === 'number' && !arg) return degrade('needs an argument like /day');\n if (typeof value !== 'number' && !(value instanceof Date))\n return degrade('needs a number or a Date');\n return formatRelative(value, node, ctx);\n case 'list': {\n if (!Array.isArray(value)) return degrade('needs an array');\n const type = arg === 'or' ? 'disjunction' : arg === 'unit' ? 'unit' : 'conjunction';\n return listFormat(locale, type).format(value.map((item) => autoFormat(item, locale, ctx)));\n }\n case 'unit':\n if (!arg) return degrade('needs an argument like /kilometer');\n try {\n return numberFormat(locale, { style: 'unit', unit: arg }).format(Number(value));\n } catch {\n return degrade(`does not know the unit \"${arg}\"`);\n }\n default:\n return degrade('is not a format verbaly knows');\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: number | Date, node: ParamNode, ctx: FormatContext): string {\n const { arg } = node;\n try {\n const fmt = relativeTimeFormat(ctx.locale);\n if (typeof value === 'number') return fmt.format(value, arg as Intl.RelativeTimeFormatUnit);\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 fmt.format(Math.round(diffSec / per), arg as Intl.RelativeTimeFormatUnit);\n }\n const [unit, per] = REL_UNITS.find(([, s]) => Math.abs(diffSec) >= s) ?? ['second', 1];\n return fmt.format(Math.round(diffSec / per), unit);\n } catch {\n // an invalid Date lands here too, so the warn names both suspects instead of blaming the unit\n warnOnce(`{${node.name}:relative}${where(ctx)} cannot format ${describe(value)} as \"${arg}\"`);\n return String(value);\n }\n}\n\nexport function autoFormat(value: unknown, locale: string, ctx?: FormatContext): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'number') return numberFormat(locale).format(value);\n if (value instanceof Date) {\n // an invalid Date makes Intl throw: degrade like every other bad format input\n if (Number.isNaN(value.getTime())) {\n warnOnce(`an invalid Date${ctx ? where(ctx) : ''} renders as plain text`);\n return String(value);\n }\n return dateTimeFormat(locale).format(value);\n }\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 { displayNames } from './intl';\nimport type { Verbaly } from './types';\n\nexport interface ResolveLocaleOptions {\n supported: string[];\n fallback?: string;\n storageKey?: string | false;\n path?: string | false;\n base?: string;\n}\n\nexport interface LocaleFromPathOptions {\n supported: string[];\n path?: string;\n base?: string;\n}\n\n// shared identity: localStorage key (browser) + cookie name (SSR integrations)\nexport const LOCALE_STORAGE_KEY = 'verbaly-locale';\n\n// zh-Hant-TW → [zh-Hant-TW, zh-Hant, zh]\nexport function narrowLocales(lang: string): string[] {\n const out: string[] = [];\n const parts = lang.split('-');\n while (parts.length > 0) {\n out.push(parts.join('-'));\n parts.pop();\n }\n return out;\n}\n\n// fallback tables for engines without Intl.Locale getTextInfo (Firefox)\nconst RTL_SCRIPTS = /^(Arab|Aran|Hebr|Thaa|Nkoo|Syrc|Samr|Mand|Adlm|Rohg|Yezi)$/;\nconst RTL_LANGS = /^(ar|he|fa|ur|ps|sd|ug|yi|dv|ckb)$/;\n\ninterface TextInfoLocale extends Intl.Locale {\n getTextInfo?(): { direction?: string };\n textInfo?: { direction?: string };\n}\n\nexport function localeDirection(locale: string): 'ltr' | 'rtl' {\n try {\n const loc = new Intl.Locale(locale) as TextInfoLocale;\n const direction = (loc.getTextInfo?.() ?? loc.textInfo)?.direction;\n if (direction === 'rtl' || direction === 'ltr') return direction;\n const script = loc.script ?? loc.maximize().script;\n if (script) return RTL_SCRIPTS.test(script) ? 'rtl' : 'ltr';\n return RTL_LANGS.test(loc.language) ? 'rtl' : 'ltr';\n } catch {\n // malformed tag: best effort on the primary subtag, never throw\n return RTL_LANGS.test(locale.split('-')[0]!.toLowerCase()) ? 'rtl' : 'ltr';\n }\n}\n\n// localized language name for locale switchers; defaults to the endonym\nexport function localeName(locale: string, displayIn: string = locale): string {\n try {\n return displayNames(displayIn).of(locale) ?? locale;\n } catch {\n return locale; // unknown tag or missing Intl data: the code beats a crash\n }\n}\n\nexport interface LocalePathOptions {\n supported: string[];\n sourceLocale?: string;\n path?: string;\n base?: string;\n}\n\n// the inverse of what render writes: /es/docs → /pt/docs, and the source locale keeps no prefix\nexport function localePath(locale: string, options: LocalePathOptions): string {\n const { supported, sourceLocale } = options;\n const base = normalizeBase(options.base);\n const full = options.path ?? currentPath() ?? '/';\n const cut = full.search(/[?#]/);\n const path = stripBase(cut < 0 ? full : full.slice(0, cut), base);\n const rest = cut < 0 ? '' : full.slice(cut);\n\n const segments = path.split('/').filter(Boolean);\n if (segments[0] && matchPathSegment(segments[0], supported)) segments.shift();\n if (locale !== sourceLocale) segments.unshift(locale);\n const trailing = segments.length && path.endsWith('/') ? '/' : '';\n return `${base}/${segments.join('/')}${trailing}${rest}`;\n}\n\n// which tree this page belongs to: a fact of the url, so it answers undefined instead of guessing\nexport function localeFromPath(options: LocaleFromPathOptions): string | undefined {\n const path = options.path ?? currentPath();\n if (path === undefined) return undefined;\n const segment = stripBase(path, normalizeBase(options.base)).split('/').find(Boolean);\n return segment ? matchPathSegment(segment, options.supported) : undefined;\n}\n\nexport function resolveLocale(options: ResolveLocaleOptions): string {\n const { supported, fallback = supported[0] ?? 'en', storageKey = LOCALE_STORAGE_KEY } = options;\n\n // the document you are looking at wins: render put the page under that prefix already translated\n if (options.path !== false) {\n const match = localeFromPath({ supported, path: options.path, base: options.base });\n if (match) return match;\n }\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// 'app', '/app' and '/app/' all read as '/app'; nothing means the site sits at the root\nfunction normalizeBase(base: string | undefined): string {\n const trimmed = base?.replace(/^\\/+/, '').replace(/\\/+$/, '');\n return trimmed ? `/${trimmed}` : '';\n}\n\n// the boundary check is what keeps base /app from swallowing /application\nfunction stripBase(path: string, base: string): string {\n if (!base || !path.startsWith(base)) return path;\n const rest = path.slice(base.length);\n if (rest === '') return '/';\n return rest.startsWith('/') ? rest : path;\n}\n\n// language, optional script, optional region: what render writes, never a slug like pt-and-friends\nconst LOCALE_SEGMENT = /^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|\\d{3}))?$/i;\n\n// a segment is narrowed only when it is shaped like a tag: a slug must never become a locale\nfunction matchPathSegment(segment: string, supported: string[]): string | undefined {\n if (supported.includes(segment)) return segment;\n return LOCALE_SEGMENT.test(segment) ? matchSupported(segment, supported) : undefined;\n}\n\n// exact, then progressive BCP-47 narrowing (zh-Hant-TW → zh-Hant → zh)\nfunction matchSupported(lang: string, supported: string[]): string | undefined {\n for (const candidate of narrowLocales(lang)) {\n if (supported.includes(candidate)) return candidate;\n }\n return 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 for (const candidate of narrowLocales(lang.toLowerCase())) {\n const match = supported.find((s) => s.toLowerCase() === candidate);\n if (match) return match;\n }\n return undefined;\n}\n\n// per-request negotiation shared by SSR integrations: cookie value → Accept-Language → fallback\nexport interface RequestLocaleOptions {\n supported: string[];\n cookie?: string | null;\n header?: string | null;\n fallback?: string;\n}\n\nexport function resolveRequestLocale(options: RequestLocaleOptions): string {\n const { supported, cookie, header, fallback = supported[0] ?? 'en' } = options;\n if (cookie) {\n // '' sentinel = no match → fall through to the header\n const match = negotiateLocale(cookie, supported, '');\n if (match) return match;\n }\n return negotiateLocale(header, supported, fallback);\n}\n\nexport interface SwitchLocaleOptions {\n cookie?: string | false;\n maxAge?: number;\n}\n\nconst YEAR = 31536000;\n\n// shared by the SSR integrations: catalog first (no flash), then locale, then persistence\nexport async function switchLocale(\n instance: Pick<Verbaly, 'loadLocale' | 'setLocale'>,\n locale: string,\n options: SwitchLocaleOptions = {},\n): Promise<void> {\n const { cookie = LOCALE_STORAGE_KEY, maxAge = YEAR } = options;\n await instance.loadLocale(locale);\n instance.setLocale(locale);\n if (typeof document === 'undefined') return; // SSR-safe no-op\n if (cookie) {\n document.cookie = `${cookie}=${encodeURIComponent(locale)}; path=/; max-age=${maxAge}; samesite=lax`;\n }\n document.documentElement.lang = locale;\n document.documentElement.dir = localeDirection(locale);\n}\n\nexport function persistLocale(\n locale: string,\n storageKey: string | false = LOCALE_STORAGE_KEY,\n): void {\n if (storageKey) getStorage()?.setItem(storageKey, locale);\n if (typeof document !== 'undefined') {\n document.documentElement.lang = locale;\n document.documentElement.dir = localeDirection(locale);\n }\n}\n\nfunction currentPath(): string | undefined {\n // require document like every other browser check: a server has no page to read a prefix from\n return typeof document !== 'undefined' && typeof location !== 'undefined'\n ? location.pathname\n : undefined;\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","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' || style === 'percent' || style === 'currency' ? style : '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 { narrowLocales } from './locale';\nimport { parse } from './parse';\nimport { warnOnce } from './warn';\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 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 = narrowLocales(locale);\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) {\n warnOnce(`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, key });\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 autoLoad(locale);\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 // fire and forget: the UI re-renders when it lands, and a failure reports instead of rejecting\n function autoLoad(target: string): void {\n void loadLocale(target).catch(() => {\n warnOnce(`failed to load catalog for \"${target}\"`);\n });\n }\n\n function pendingLoader(target: string): string | undefined {\n for (const candidate of narrowLocales(target)) {\n if (loaders[candidate]) return loaded.has(candidate) ? undefined : candidate;\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 autoLoad(next);\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 ? { from: 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\n// text runs only, post-tokenize: decoded braces/angles never re-enter a parser\nconst ENTITY = /&(?:(lt|gt|amp)|#(\\d+)|#[xX]([0-9a-fA-F]+));/g;\nconst ENTITY_MAP: Record<string, string> = { lt: '<', gt: '>', amp: '&' };\nconst decodeEntities = (s: string): string =>\n s.replace(ENTITY, (full, name?: string, dec?: string, hex?: string) => {\n if (name) return ENTITY_MAP[name]!;\n const code = dec ? parseInt(dec, 10) : parseInt(hex!, 16);\n return code <= 0x10ffff ? String.fromCodePoint(code) : full;\n });\n\nexport function parseTags(text: string): TagNode[] {\n TAG.lastIndex = 0;\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(decodeEntities(s));\n };\n\n let last = 0;\n let m: RegExpExecArray | null;\n while ((m = TAG.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 { narrowLocales } from './locale';\nimport { parseTags, type TagNode } from './tags';\nimport type { DictionaryInput, Params, Verbaly } from './types';\nimport { warnOnce } from './warn';\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;\nconst URL_ATTR = /^(href|src|xlink:href|action|formaction)$/;\nconst BLOCKED_ATTR = /^(style|srcdoc)$/;\n\nexport function safeHref(href: string): string | undefined {\n if (UNSAFE_HREF.test(href)) {\n warnOnce(`blocked unsafe href: ${href}`);\n return undefined;\n }\n return href;\n}\n\n// one link normalization for core + every adapter (applies safeHref)\nexport function normalizeLink(link: RichLink): { href?: string; target?: string; rel?: string } {\n const { href, target, rel } = typeof link === 'string' ? { href: link } : link;\n return { href: safeHref(href), target, rel };\n}\n\n// one attribute guard for bindDom + render, a catalog is untrusted input: undefined = skip\nexport function safeAttribute(name: string, value: string): string | undefined {\n const lower = name.toLowerCase();\n if (lower.startsWith('on') || BLOCKED_ATTR.test(lower)) return undefined;\n if (URL_ATTR.test(lower)) return safeHref(value);\n return value;\n}\n\n// children never reach a void element: a browser parses <br></br> as two <br>, hydration as one\nexport const VOID_TAGS = [\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\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; value: Params | undefined }>();\n const linksCache = new WeakMap<\n Element,\n { raw: string | null; value: Record<string, RichLink> | undefined }\n >();\n const attrsCache = new WeakMap<Element, { raw: string | null; value: Params | undefined }>();\n\n function fromCache<T>(\n cache: WeakMap<Element, { raw: string | null; value: T }>,\n el: Element,\n raw: string | null,\n compute: () => T,\n ): T {\n const hit = cache.get(el);\n if (hit && hit.raw === raw) return hit.value;\n const value = compute();\n cache.set(el, { raw, value });\n return value;\n }\n\n function cachedArgs(el: Element): Params | undefined {\n const raw = el.getAttribute(argsAttr);\n return fromCache(argsCache, el, raw, () => parseArgs(raw));\n }\n\n function cachedLinks(el: Element): Record<string, RichLink> | undefined {\n const raw = el.getAttribute(linksAttr);\n if (!raw) return globalLinks;\n return fromCache(linksCache, el, raw, () => {\n const own = parseArgs(raw) as Record<string, RichLink> | undefined;\n return own ? (globalLinks ? { ...globalLinks, ...own } : own) : globalLinks;\n });\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 continue;\n }\n const link = links?.[node.name];\n if (link !== undefined) {\n const { href, target, rel } = normalizeLink(link);\n const a = el.ownerDocument.createElement('a');\n if (href !== undefined) a.setAttribute('href', href);\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 if (!VOID_TAGS.includes(node.name)) 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 // pre-rendered html wins until this locale resolves: repainting it is the flash render kills\n let trustServerHtml = true;\n\n function holdBack(key: string, current: string | null): boolean {\n if (!trustServerHtml || !current?.trim()) return false;\n return instance.inspect(key)?.from !== instance.locale;\n }\n\n function render(el: Element): void {\n const args = cachedArgs(el);\n const key = el.getAttribute(attr);\n if (key && !holdBack(key, el.textContent)) {\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 rawAttrs = el.getAttribute(attrsAttr);\n const attrMap = fromCache(attrsCache, el, rawAttrs, () => parseArgs(rawAttrs));\n if (attrMap) {\n for (const [name, attrKey] of Object.entries(attrMap)) {\n if (typeof attrKey !== 'string') continue;\n if (holdBack(attrKey, el.getAttribute(name))) continue;\n const value = safeAttribute(name, t(attrKey, args));\n if (value !== undefined) el.setAttribute(name, value);\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 warnOnLangMismatch(instance.locale);\n renderAll(root);\n // from here the dom is ours: a stale value from a previous locale must not survive a switch\n trustServerHtml = false;\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\n// render writes <html lang>, so a disagreement here means the page is about to be translated away\nfunction warnOnLangMismatch(locale: string): void {\n const lang = document.documentElement.lang;\n if (!lang || narrowLocales(lang).includes(locale) || narrowLocales(locale).includes(lang)) return;\n warnOnce(\n `the page is <html lang=\"${lang}\"> and this instance is in \"${locale}\", so bindDom is about to ` +\n `translate it away: read the url with localeFromPath when it carries the locale, and call ` +\n `persistLocale first when it does not`,\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 warnOnce(`invalid args JSON: ${raw}`);\n return undefined;\n }\n}\n"],"mappings":";AACA,MAAM,yBAAS,IAAI,IAAY;AAE/B,SAAgB,SAAS,SAAuB;CAC9C,IAAI,OAAO,IAAI,OAAO,GAAG;CACzB,OAAO,IAAI,OAAO;CAClB,QAAQ,KAAK,aAAa,SAAS;AACrC;;;ACJA,SAAgB,QACd,MACA,SAAS,IACT,MAA8B,CAAC,GACP;CAExB,IAAI,CAAC,QAAQ,IAAI,GAAG,OAAO;CAC3B,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,IAAI,QAAQ,KAAK,GAAG,QAAQ,OAAO,MAAM,GAAG;OAC5C,SAAS,qBAAqB,KAAK,4CAA4C;CACtF;CACA,OAAO;AACT;AAEA,SAAS,QAAQ,OAAsC;CACrD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;;;ACrBA,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;AACjD,MAAM,0BAAU,IAAI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AU,IAAI,CAAC;CAE5D,MAAM,WAAW,IAAI,kBAAkB,YAAY;EACjD,KAAK,MAAM,UAAU,SACnB,IAAI,OAAO,SAAS,gBAAgB,OAAO,kBAAkB,SAC3D,OAAO,OAAO,MAAM;OACf,IAAI,OAAO,SAAS,aACpB;QAAA,MAAM,QAAQ,OAAO,YACxB,IAAI,gBAAgB,SAAS,UAAU,IAAI;EAAA;CAInD,CAAC;CAED,SAAS,QAAQ,gBAAgB,WAAW,KAAK,kBAAmB,MAAe;EACjF,WAAW;EACX,SAAS;EACT,YAAY;EACZ,iBAAiB;GAAC;GAAM;GAAU;GAAW;GAAU;EAAS;CAClE,CAAC;CAED,aAAa;EACX,YAAY;EACZ,SAAS,WAAW;CACtB;AACF;AAGA,SAAS,mBAAmB,QAAsB;CAChD,MAAM,OAAO,SAAS,gBAAgB;CACtC,IAAI,CAAC,QAAQ,cAAc,IAAI,CAAC,CAAC,SAAS,MAAM,KAAK,cAAc,MAAM,CAAC,CAAC,SAAS,IAAI,GAAG;CAC3F,SACE,2BAA2B,KAAK,8BAA8B,OAAO,wJAGvE;AACF;AAEA,SAAS,UAAU,KAAwC;CACzD,IAAI,CAAC,KAAK,OAAO,KAAA;CACjB,IAAI;EACF,OAAO,KAAK,MAAM,GAAG;CACvB,QAAQ;EACN,SAAS,sBAAsB,KAAK;EACpC;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verbaly",
3
- "version": "0.35.0",
3
+ "version": "0.37.0",
4
4
  "description": "Effortless i18n: write natural text, ship type-safe, tree-shakeable translations.",
5
5
  "keywords": [
6
6
  "i18n",