{"version":3,"file":"ngx-runtime-i18n-core.mjs","sources":["../../../../libs/runtime-i18n/src/lib/icu.ts","../../../../libs/runtime-i18n/src/index.ts","../../../../libs/runtime-i18n/src/ngx-runtime-i18n-core.ts"],"sourcesContent":["/**\n * Very small ICU-like formatter with interpolation and plural basics.\n * Used by the Angular service and pipe. Replace with full ICU in a later minor.\n * @experimental\n */\nimport type { Catalog } from './types';\n\nexport function formatIcu(\n  _lang: string,\n  key: string,\n  cat: Catalog,\n  params: Record<string, unknown> = {},\n  onMissingKey?: (k: string) => string\n): string {\n  const raw = lookup(key, cat);\n  if (raw == null) return onMissingKey ? onMissingKey(key) : key;\n\n  let out = String(raw);\n\n  // 1) Resolve {x, plural, ...} with a brace-balanced scanner.\n  out = replacePluralBlocks(out, (arg, body) => {\n    const n = Number(params[arg] ?? 0);\n    const options = parsePluralBody(body);\n    if (Number.isFinite(n)) {\n      const exact = options[`=${n}`];\n      if (exact) return exact;\n      const one = options['one'];\n      if (n === 1 && one) return one;\n      const other = options['other'] ?? '';\n      return other.replace(/#/g, String(n));\n    }\n    return options['other'] ?? '';\n  });\n\n  // 2) Simple {name} interpolation AFTER plural branch selection.\n  out = out.replace(/\\{(\\w+)\\}/g, (_m: string, p1: string) =>\n    params[p1] != null ? String(params[p1]) : `{${p1}}`\n  );\n\n  return out;\n}\n\nfunction lookup(path: string, obj: any): any {\n  return path\n    .split('.')\n    .reduce((o: any, k: string) => (o && k in o ? o[k] : undefined), obj);\n}\n\n/**\n * Replace all `{arg, plural, ...}` blocks in `s` using a brace-balanced scan.\n */\nfunction replacePluralBlocks(\n  s: string,\n  render: (arg: string, body: string) => string\n): string {\n  let i = 0;\n  let out = '';\n\n  while (i < s.length) {\n    const start = s.indexOf('{', i);\n    if (start === -1) {\n      out += s.slice(i);\n      break;\n    }\n    out += s.slice(i, start);\n\n    // Try to match the prefix \"{arg, plural,\"\n    const prefixMatch = /\\{(\\w+),\\s*plural,\\s*/y;\n    prefixMatch.lastIndex = start;\n    const m = prefixMatch.exec(s);\n    if (!m) {\n      // Not a plural block; copy '{' and continue scanning after it.\n      out += '{';\n      i = start + 1;\n      continue;\n    }\n\n    const arg = m[1];\n    let j = prefixMatch.lastIndex; // position after the matched prefix\n\n    // Find the matching closing '}' for the whole plural block with nesting.\n    let depth = 1;\n    while (j < s.length && depth > 0) {\n      const ch = s.charAt(j++);\n      if (ch === '{') depth++;\n      else if (ch === '}') depth--;\n    }\n\n    if (depth !== 0) {\n      // Unbalanced; fall back to literal copy of the unmatched segment.\n      out += s.slice(start, j);\n      i = j;\n      continue;\n    }\n\n    // Body is the contents between prefix end and the final '}'.\n    const body = s.slice(prefixMatch.lastIndex, j - 1);\n    const rendered = render(arg, body);\n    out += rendered;\n    i = j; // continue after the closing brace\n  }\n\n  return out;\n}\n\n/** Parse a simple ICU plural clause body: e.g. `one {A} other {B} =0 {C}` */\nfunction parsePluralBody(body: string): Record<string, string> {\n  const map: Record<string, string> = {};\n  // Allow balanced inner {...} in the value (non-greedy over balanced chunks is complex;\n  // we approximate by accepting any sequence without unbalanced braces at top level).\n  const re = /(one|other|=\\d+)\\s*\\{((?:[^{}]|\\{[^{}]*\\})*)\\}/g;\n  let m: RegExpExecArray | null;\n  while ((m = re.exec(body)) !== null) {\n    const key = m[1] as string;\n    const val = (m[2] ?? '') as string;\n    map[key] = val;\n  }\n  return map;\n}\n","/**\n * @packageDocumentation\n * Core runtime i18n primitives.\n * Keep this surface minimal and stable.\n */\n\nexport type { Catalog, RuntimeI18nConfig } from './lib/types';\n\n/**\n * Lightweight ICU-style formatter used internally by the Angular service.\n * Exposed as @experimental for advanced users or custom integrations.\n * @experimental\n */\nexport { formatIcu } from './lib/icu';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"AAOM,SAAU,SAAS,CACvB,KAAa,EACb,GAAW,EACX,GAAY,EACZ,MAAA,GAAkC,EAAE,EACpC,YAAoC,EAAA;IAEpC,MAAM,GAAG,GAAG,MAAM,CA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