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\"./pack.js\";\n\n/**\n * Global registries for language packs and fallbacks.\n *\n * Importing a language subpath (`import \"i18n-inflect/hu\"`) registers its\n * pack here as a side effect; fallbacks (e.g. `@i18n-inflect/neural`) are\n * registered explicitly by the application.\n */\n\nconst packs = new Map<string, LanguagePack>();\nconst fallbacks = new Map<string, InflectionFallback>();\n\n/**\n * Reduce a BCP 47 tag to its primary language subtag: `\"hu-HU\"` → `\"hu\"`.\n * Falls back to naive splitting when `Intl.Locale` rejects the input.\n */\nexport function resolveLocale(locale: string): string {\n  try {\n    return new Intl.Locale(locale).language;\n  } catch {\n    return locale.split(/[-_]/, 1)[0]?.toLowerCase() ?? locale.toLowerCase();\n  }\n}\n\n/** Register (or replace) a language pack. */\nexport function registerLanguage(pack: LanguagePack): void {\n  packs.set(pack.locale, pack);\n}\n\n/** Register (or replace) a fallback oracle for its locale. */\nexport function registerFallback(fallback: InflectionFallback): void {\n  fallbacks.set(fallback.locale, fallback);\n}\n\n/** Look up the pack serving a locale (accepts full BCP 47 tags). */\nexport function getLanguage(locale: string): LanguagePack | undefined {\n  return packs.get(resolveLocale(locale));\n}\n\n/** Look up the fallback serving a locale (accepts full BCP 47 tags). */\nexport function getFallback(locale: string): InflectionFallback | undefined {\n  return fallbacks.get(resolveLocale(locale));\n}\n\n/** List the registered language subtags (mainly for diagnostics/tests). */\nexport function registeredLocales(): string[] {\n  return [...packs.keys()];\n}\n\n/**\n * Remove every registered pack and fallback.\n *\n * Intended for test isolation only — applications never need this.\n */\nexport function resetRegistry(): void {\n  packs.clear();\n  fallbacks.clear();\n}\n","/**\n * Whitespace-preserving phrase tokenization shared by the language packs.\n *\n * A phrase is split into alternating word/separator parts so packs can\n * rewrite individual words (head noun, article, adjectives) and reassemble\n * the phrase without disturbing its original spacing.\n */\n\n/** A phrase split into parts; `words[i]` sits between separators. */\nexport interface SplitPhrase {\n  /** The word tokens, in order. */\n  words: string[];\n  /**\n   * All parts (words and whitespace runs) in original order. Rewriting\n   * `parts[wordIndexes[i]]` and joining reproduces the phrase.\n   */\n  parts: string[];\n  /** Index into `parts` for each entry of `words`. */\n  wordIndexes: number[];\n}\n\n/** Split a phrase, keeping whitespace runs as separate parts. */\nexport function splitPhrase(phrase: string): SplitPhrase {\n  const parts = phrase.split(/(\\s+)/);\n  const words: string[] = [];\n  const wordIndexes: number[] = [];\n  for (let i = 0; i < parts.length; i++) {\n    const part = parts[i];\n    if (part !== undefined && part.length > 0 && !/^\\s+$/.test(part)) {\n      words.push(part);\n      wordIndexes.push(i);\n    }\n  }\n  return { words, parts, wordIndexes };\n}\n\n/** Reassemble a phrase after rewriting some of its `parts`. */\nexport function joinPhrase(split: SplitPhrase): string {\n  return split.parts.join(\"\");\n}\n\n/**\n * Split a token into its core and trailing punctuation\n * (`\"ász!\"` → `[\"ász\", \"!\"]`) so suffixes attach to the word itself.\n */\nexport function splitTrailingPunctuation(token: string): [core: string, punctuation: string] {\n  const match = /^(.*?)([.,;:!?…)»”'\"]*)$/.exec(token);\n  return match ? [match[1] ?? token, match[2] ?? \"\"] : [token, \"\"];\n}\n\n/** True when `word`'s first letter is uppercase (locale-independent check). */\nexport function isCapitalized(word: string): boolean {\n  const first = word[0];\n  return first !== undefined && first !== first.toLowerCase();\n}\n\n/** Capitalize the first letter of `word`. */\nexport function capitalize(word: string): string {\n  return word.length === 0 ? word : (word[0] as string).toUpperCase() + word.slice(1);\n}\n"]}