@fluenti/vue 0.3.3 → 0.4.0-rc.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/use-i18n.ts","../src/components/rich-text.ts","../src/components/Trans.ts","../src/components/Plural.ts","../src/components/Select.ts","../src/components/DateTime.ts","../src/components/NumberFormat.ts","../src/plugin.ts","../src/compile-time-t.ts"],"sourcesContent":["import { inject } from 'vue'\nimport { FLUENTI_KEY, type FluentiContext } from './plugin'\n\n/**\n * Composable that returns the Fluenti i18n context.\n *\n * Must be called inside a component whose ancestor app has installed the\n * `createFluenti()` plugin.\n *\n * @throws If the plugin has not been installed\n */\nexport function useI18n(): FluentiContext {\n const ctx = inject(FLUENTI_KEY)\n if (!ctx) {\n throw new Error('[fluenti] useI18n() requires createFluenti plugin')\n }\n return ctx\n}\n","import { Comment, Text, h, isVNode, type VNode, type VNodeChild } from 'vue'\nimport { offsetIndices } from '@fluenti/core/internal'\n\nexport function extractMessage(children: VNodeChild | VNodeChild[] | undefined): {\n message: string\n components: VNode[]\n} {\n const components: VNode[] = []\n let message = ''\n\n function visit(node: VNodeChild | VNodeChild[] | undefined): void {\n if (node === null || node === undefined || typeof node === 'boolean') return\n if (Array.isArray(node)) {\n for (const child of node) visit(child)\n return\n }\n if (typeof node === 'string' || typeof node === 'number') {\n message += String(node)\n return\n }\n if (!isVNode(node) || node.type === Comment) return\n if (node.type === Text) {\n message += typeof node.children === 'string' ? node.children : ''\n return\n }\n\n const idx = components.length\n const inner = extractMessage(node.children as VNodeChild | VNodeChild[] | undefined)\n components.push(node)\n components.push(...inner.components)\n message += `<${idx}>${offsetIndices(inner.message, idx + 1)}</${idx}>`\n }\n\n visit(children)\n return { message, components }\n}\n\nexport function reconstruct(\n translated: string,\n components: VNode[],\n): VNodeChild {\n const tagRe = /<(\\d+)>([\\s\\S]*?)<\\/\\1>/g\n const result: VNodeChild[] = []\n let lastIndex = 0\n let match: RegExpExecArray | null\n\n tagRe.lastIndex = 0\n match = tagRe.exec(translated)\n while (match !== null) {\n if (match.index > lastIndex) {\n result.push(translated.slice(lastIndex, match.index))\n }\n\n const idx = Number(match[1])\n const component = components[idx]\n const innerContent = reconstruct(match[2]!, components)\n if (component) {\n result.push(h(component.type as never, component.props ?? {}, Array.isArray(innerContent) ? innerContent : [innerContent]))\n } else {\n result.push(match[2]!)\n }\n\n lastIndex = tagRe.lastIndex\n match = tagRe.exec(translated)\n }\n\n if (lastIndex < translated.length) {\n result.push(translated.slice(lastIndex))\n }\n\n return result.length <= 1 ? (result[0] ?? '') : result\n}\n\nexport function serializeRichForms<T extends string>(\n keys: readonly T[],\n forms: Partial<Record<T, VNodeChild>> & Record<string, VNodeChild | undefined>,\n): {\n messages: Record<string, string>\n components: VNode[]\n} {\n const messages: Record<string, string> = {}\n const components: VNode[] = []\n\n for (const key of keys) {\n const value = forms[key]\n if (value === undefined) continue\n const extracted = extractMessage(value)\n messages[key] = offsetIndices(extracted.message, components.length)\n components.push(...extracted.components)\n }\n\n for (const [key, value] of Object.entries(forms)) {\n if (keys.includes(key as T) || value === undefined) continue\n const extracted = extractMessage(value)\n messages[key] = offsetIndices(extracted.message, components.length)\n components.push(...extracted.components)\n }\n\n return { messages, components }\n}\n\n","import { defineComponent, h } from 'vue'\nimport type { ExtractPropTypes } from 'vue'\nimport { useI18n } from '../use-i18n'\nimport { extractMessage, reconstruct } from './rich-text'\n\n/**\n * `<Trans>` component for rich text with Vue components.\n *\n * @example\n * ```vue\n * <Trans>\n * Visit our <a href=\"/docs\">documentation</a> to learn more.\n * </Trans>\n * ```\n *\n * @example\n * ```vue\n * <Trans>\n * Click <RouterLink to=\"/next\">here</RouterLink> to continue.\n * </Trans>\n * ```\n */\nconst transProps = {\n /** Override auto-generated hash ID */\n id: String,\n /** Message context used for identity and translator disambiguation */\n context: String,\n /** Translator-facing note preserved in extraction catalogs */\n comment: String,\n /** Wrapper element tag name. Defaults to no wrapper (Fragment). */\n tag: { type: String, default: undefined },\n} as const\n\nexport type FluentiTransProps = Readonly<ExtractPropTypes<typeof transProps>>\n\nexport const Trans = defineComponent({\n name: 'Trans',\n props: transProps,\n setup(props, { slots }) {\n const { t } = useI18n()\n\n return () => {\n const defaultSlot = slots['default']?.()\n if (!defaultSlot) return null\n const { message, components } = extractMessage(defaultSlot)\n const translated = t({\n ...(props.id !== undefined ? { id: props.id } : {}),\n message,\n ...(props.context !== undefined ? { context: props.context } : {}),\n ...(props.comment !== undefined ? { comment: props.comment } : {}),\n })\n const result = components.length > 0 ? reconstruct(translated, components) : translated\n if (Array.isArray(result)) {\n if (result.length === 1) return result[0]!\n return props.tag ? h(props.tag, null, result) : result\n }\n return result\n }\n },\n})\n","import { defineComponent, h } from 'vue'\nimport type { ExtractPropTypes, SetupContext, VNodeChild } from 'vue'\nimport { hashMessage, buildICUPluralMessage, PLURAL_CATEGORIES, type PluralCategory } from '@fluenti/core/internal'\nimport { useI18n } from '../use-i18n'\nimport { reconstruct, serializeRichForms } from './rich-text'\n\n/**\n * `<Plural>` component — shorthand for ICU plural patterns.\n *\n * Plural form props (`zero`, `one`, `two`, `few`, `many`, `other`) are treated\n * as source-language messages. The component builds an ICU plural message,\n * looks it up via `t()` in the catalog, and interpolates the translated result.\n *\n * When no catalog translation exists, the component falls back to interpolating\n * the source-language ICU message directly via the `message` field of the\n * MessageDescriptor.\n *\n * Rich text is supported via named slots:\n * ```vue\n * <Plural :value=\"count\">\n * <template #zero>No <strong>items</strong></template>\n * <template #one><em>1</em> item</template>\n * <template #other><strong>{{ count }}</strong> items</template>\n * </Plural>\n * ```\n *\n * String props still work (backward compatible):\n * ```vue\n * <Plural :value=\"count\" zero=\"No items\" one=\"# item\" other=\"# items\" />\n * ```\n */\nconst pluralProps = {\n /** The numeric value to pluralise on */\n value: { type: Number, required: true },\n /** Override the auto-generated synthetic ICU message id */\n id: String,\n /** Message context used for identity and translator disambiguation */\n context: String,\n /** Translator-facing note preserved in extraction catalogs */\n comment: String,\n /** Text for zero items (maps to `=0`) */\n zero: String,\n /** Text for singular (maps to `one`) */\n one: String,\n /** Text for dual (maps to `two`) */\n two: String,\n /** Text for few (maps to `few`) */\n few: String,\n /** Text for many (maps to `many`) */\n many: String,\n /** Text for the default/other category */\n other: { type: String, required: true },\n /** Offset from value before selecting form */\n offset: Number,\n /** Wrapper element tag name. Defaults to no wrapper (Fragment). */\n tag: { type: String, default: undefined },\n} as const\n\nexport type FluentiPluralProps = Readonly<ExtractPropTypes<typeof pluralProps>>\n\nexport const Plural = defineComponent({\n name: 'Plural',\n props: pluralProps,\n setup(props, { slots }: SetupContext) {\n const { t } = useI18n()\n\n return () => {\n const forms: Partial<Record<PluralCategory, VNodeChild>> & Record<string, VNodeChild | undefined> = {\n zero: props.zero,\n one: props.one,\n two: props.two,\n few: props.few,\n many: props.many,\n other: props.other,\n }\n\n for (const cat of PLURAL_CATEGORIES) {\n const slot = slots[cat]\n if (slot) {\n forms[cat] = slot({ count: '#' })\n }\n }\n\n const { messages, components } = serializeRichForms(PLURAL_CATEGORIES, forms)\n const icuMessage = buildICUPluralMessage(\n {\n ...(messages['zero'] !== undefined && { zero: messages['zero'] }),\n ...(messages['one'] !== undefined && { one: messages['one'] }),\n ...(messages['two'] !== undefined && { two: messages['two'] }),\n ...(messages['few'] !== undefined && { few: messages['few'] }),\n ...(messages['many'] !== undefined && { many: messages['many'] }),\n other: messages['other'] ?? '',\n },\n props.offset,\n )\n const translated = t(\n {\n id: props.id ?? (props.context === undefined ? icuMessage : hashMessage(icuMessage, props.context)),\n message: icuMessage,\n ...(props.context !== undefined ? { context: props.context } : {}),\n ...(props.comment !== undefined ? { comment: props.comment } : {}),\n },\n { count: props.value },\n )\n\n const result = components.length > 0 ? reconstruct(translated, components) : translated\n if (props.tag) return h(props.tag, undefined, result ?? undefined)\n return result ?? null\n }\n },\n})\n","import { defineComponent, h } from 'vue'\nimport type { ExtractPropTypes, PropType, SetupContext, VNodeChild } from 'vue'\nimport { hashMessage, buildICUSelectMessage, normalizeSelectForms } from '@fluenti/core/internal'\nimport { useI18n } from '../use-i18n'\nimport { reconstruct, serializeRichForms } from './rich-text'\n\n/**\n * `<Select>` component — shorthand for ICU select patterns.\n *\n * Accepts a `value` string that selects among named options. Options can be\n * provided via the type-safe `options` prop (recommended), as direct attrs\n * (convenience), or as named slots (rich text).\n *\n * Falls back to `other` when no match is found.\n *\n * @example Type-safe usage (recommended):\n * ```vue\n * <Select\n * :value=\"gender\"\n * :options=\"{ male: 'He liked it', female: 'She liked it' }\"\n * other=\"They liked it\"\n * />\n * ```\n *\n * @example Rich text via named slots:\n * ```vue\n * <Select :value=\"gender\">\n * <template #male><strong>He</strong> liked this</template>\n * <template #female><strong>She</strong> liked this</template>\n * <template #other><em>They</em> liked this</template>\n * </Select>\n * ```\n */\nconst selectProps = {\n /** The value to select on (e.g. `\"male\"`, `\"female\"`) */\n value: { type: String, required: true },\n /** Override the auto-generated synthetic ICU message id */\n id: String,\n /** Message context used for identity and translator disambiguation */\n context: String,\n /** Translator-facing note preserved in extraction catalogs */\n comment: String,\n /** Fallback text when no option matches `value` */\n other: { type: String, required: true },\n /**\n * Named options map. Keys are match values, values are display strings.\n * Takes precedence over attrs when both are provided.\n *\n * @example `{ male: 'He', female: 'She' }`\n */\n options: {\n type: Object as PropType<Record<string, string>>,\n default: undefined,\n },\n /** Wrapper element tag name. Defaults to no wrapper (Fragment). */\n tag: { type: String, default: undefined },\n} as const\n\nexport type FluentiSelectProps = Readonly<ExtractPropTypes<typeof selectProps>>\n\nexport const Select = defineComponent({\n name: 'Select',\n inheritAttrs: false,\n props: selectProps,\n setup(props, { attrs, slots }: SetupContext) {\n const { t } = useI18n()\n\n return () => {\n const forms: Record<string, VNodeChild | undefined> = {}\n\n if (props.options !== undefined) {\n for (const [key, value] of Object.entries(props.options)) {\n forms[key] = value\n }\n forms['other'] = props.other\n } else {\n for (const [key, value] of Object.entries(attrs)) {\n if (typeof value === 'string') {\n forms[key] = value\n }\n }\n forms['other'] = props.other\n }\n\n for (const [key, slot] of Object.entries(slots)) {\n if (key === 'default' || !slot) continue\n forms[key] = slot({ value: '{value}' })\n }\n\n const orderedKeys = [...Object.keys(forms).filter(key => key !== 'other'), 'other'] as const\n const { messages, components } = serializeRichForms(orderedKeys, forms)\n const normalized = normalizeSelectForms(\n Object.fromEntries(\n [...orderedKeys].map((key) => [key, messages[key] ?? '']),\n ),\n )\n const icuMessage = buildICUSelectMessage(normalized.forms)\n const translated = t(\n {\n id: props.id ?? (props.context === undefined ? icuMessage : hashMessage(icuMessage, props.context)),\n message: icuMessage,\n ...(props.context !== undefined ? { context: props.context } : {}),\n ...(props.comment !== undefined ? { comment: props.comment } : {}),\n },\n { value: normalized.valueMap[props.value] ?? 'other' },\n )\n const result = components.length > 0 ? reconstruct(translated, components) : translated\n if (props.tag) return h(props.tag, undefined, result ?? undefined)\n return result ?? null\n }\n },\n})\n","import { defineComponent, h } from 'vue'\nimport type { ExtractPropTypes, PropType } from 'vue'\nimport { useI18n } from '../use-i18n'\n\n/**\n * `<DateTime>` component for formatting dates according to locale.\n *\n * @example\n * ```vue\n * <DateTime :value=\"new Date()\" />\n * <DateTime :value=\"Date.now()\" style=\"short\" />\n * <DateTime :value=\"event.date\" style=\"long\" tag=\"time\" />\n * ```\n */\nconst dateTimeProps = {\n value: { type: [Date, Number] as PropType<Date | number>, required: true },\n style: { type: String, default: undefined },\n tag: { type: String, default: 'span' },\n} as const\n\nexport type FluentiDateTimeProps = Readonly<ExtractPropTypes<typeof dateTimeProps>>\n\nexport const DateTime = defineComponent({\n name: 'DateTime',\n props: dateTimeProps,\n setup(props) {\n const { d } = useI18n()\n return () => h(props.tag, d(props.value as Date | number, props.style))\n },\n})\n","import { defineComponent, h } from 'vue'\nimport type { ExtractPropTypes } from 'vue'\nimport { useI18n } from '../use-i18n'\n\n/**\n * `<NumberFormat>` component for formatting numbers according to locale.\n *\n * @example\n * ```vue\n * <NumberFormat :value=\"1234.56\" />\n * <NumberFormat :value=\"0.75\" style=\"percent\" />\n * <NumberFormat :value=\"99.99\" style=\"currency\" tag=\"strong\" />\n * ```\n */\nconst numberFormatProps = {\n value: { type: Number, required: true },\n style: { type: String, default: undefined },\n tag: { type: String, default: 'span' },\n} as const\n\nexport type FluentiNumberFormatProps = Readonly<ExtractPropTypes<typeof numberFormatProps>>\n\nexport const NumberFormat = defineComponent({\n name: 'NumberFormat',\n props: numberFormatProps,\n setup(props) {\n const { n } = useI18n()\n return () => h(props.tag, n(props.value, props.style))\n },\n})\n","import { type App, type InjectionKey, type Ref, ref, shallowReactive } from 'vue'\nimport type { AllMessages, Locale, LocalizedString, Messages, CompiledMessage, MessageDescriptor, DiagnosticsConfig } from '@fluenti/core'\nimport { createDiagnostics, formatDate, formatNumber } from '@fluenti/core'\nimport { interpolate, buildICUMessage, resolveDescriptorId } from '@fluenti/core/internal'\nimport { Trans } from './components/Trans'\nimport { Plural } from './components/Plural'\nimport { Select } from './components/Select'\nimport { DateTime } from './components/DateTime'\nimport { NumberFormat } from './components/NumberFormat'\n\n/** Escape HTML special characters to prevent XSS. @internal */\nfunction escapeHtml(str: string): string {\n return str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\n}\n\n/** Compiled message chunk loader for lazy locale loading */\nexport type ChunkLoader = (\n locale: string,\n) => Promise<Record<string, CompiledMessage> | { default: Record<string, CompiledMessage> }>\n\ninterface SplitRuntimeModule {\n __switchLocale?: (locale: string) => Promise<void>\n __preloadLocale?: (locale: string) => Promise<void>\n}\n\nconst SPLIT_RUNTIME_KEY = Symbol.for('fluenti.runtime.vue.v1')\n\nfunction getSplitRuntimeModule(): SplitRuntimeModule | null {\n const runtime = (globalThis as Record<PropertyKey, unknown>)[SPLIT_RUNTIME_KEY]\n return typeof runtime === 'object' && runtime !== null\n ? runtime as SplitRuntimeModule\n : null\n}\n\nfunction resolveChunkMessages(\n loaded: Record<string, CompiledMessage> | { default: Record<string, CompiledMessage> },\n): Record<string, CompiledMessage> {\n return typeof loaded === 'object' && loaded !== null && 'default' in loaded\n ? (loaded as { default: Record<string, CompiledMessage> }).default\n : loaded\n}\n\n/** Context object returned by `useI18n()` and available as `$t` etc. on globalProperties */\nexport interface FluentiContext {\n /** Translate a message by id or MessageDescriptor, with optional interpolation values */\n t(id: string | MessageDescriptor, values?: Record<string, unknown>): LocalizedString\n /** Tagged template form: t`Hello ${name}` */\n t(strings: TemplateStringsArray, ...exprs: unknown[]): LocalizedString\n /** Reactive ref for current locale */\n locale: Readonly<Ref<Locale>>\n /** Change the active locale (async when lazy locale loading is enabled) */\n setLocale(locale: Locale): Promise<void>\n /** Dynamically load messages for a locale */\n loadMessages(locale: Locale, messages: Messages): void\n /** Get all locales that have loaded messages */\n getLocales(): Locale[]\n /** Format a date value according to locale */\n d(value: Date | number, style?: string): LocalizedString\n /** Format a number according to locale */\n n(value: number, style?: string): LocalizedString\n /** Format an ICU message string directly (no catalog lookup) */\n format(message: string, values?: Record<string, unknown>): LocalizedString\n /** Whether a locale chunk is currently being loaded */\n isLoading: Readonly<Ref<boolean>>\n /** Set of locales whose messages have been loaded */\n loadedLocales: Readonly<Ref<ReadonlySet<string>>>\n /** Preload a locale in the background without switching to it */\n preloadLocale(locale: string): void\n /** Check if a translation key exists in the catalog */\n te(key: string, locale?: string): boolean\n /** Get the raw compiled message without interpolation */\n tm(key: string, locale?: string): CompiledMessage | undefined\n}\n\n/** Injection key for providing/injecting fluenti context */\nexport const FLUENTI_KEY: InjectionKey<FluentiContext> = Symbol('fluenti')\n\n/** Options for creating the Fluenti Vue plugin */\nexport interface FluentiConfig {\n locale: string\n fallbackLocale?: string\n messages: AllMessages\n missing?: (locale: string, id: string) => string | undefined\n dateFormats?: Record<string, Intl.DateTimeFormatOptions | 'relative'>\n numberFormats?: Record<string, Intl.NumberFormatOptions | ((locale: string) => Intl.NumberFormatOptions)>\n fallbackChain?: Record<string, string[]>\n /** Async chunk loader for lazy locale loading */\n chunkLoader?: ChunkLoader\n /** Enable lazy locale loading through chunkLoader */\n lazyLocaleLoading?: boolean\n /**\n * Prefix for globally registered components (Trans, Plural, Select).\n *\n * Set this to avoid naming conflicts with other libraries.\n *\n * @example\n * componentPrefix: 'I18n'\n * // Registers: I18nTrans, I18nPlural, I18nSelect\n *\n * @example\n * componentPrefix: 'Fluenti'\n * // Registers: FluentiTrans, FluentiPlural, FluentiSelect\n *\n * @default '' (no prefix — Trans, Plural, Select)\n */\n componentPrefix?: string\n /**\n * Whether to inject `$t`, `$d`, `$n`, `$vtRich` onto `app.config.globalProperties`.\n *\n * Set to `false` to avoid polluting the global namespace (e.g. when migrating from vue-i18n\n * or when using composition API exclusively via `useI18n()`).\n *\n * @default true\n */\n injectGlobalProperties?: boolean\n /** Runtime diagnostics configuration */\n diagnostics?: DiagnosticsConfig\n}\n\n/** Return value of `createFluenti()` */\nexport interface FluentiPlugin {\n /** Vue plugin install method */\n install(app: App): void\n /** The global fluenti context (same as what useI18n returns) */\n global: FluentiContext\n}\n\n/**\n * Resolve a compiled message to a string, applying values if needed.\n * @internal\n */\nfunction resolveMessage(\n compiled: CompiledMessage,\n values?: Record<string, unknown>,\n locale?: string,\n): LocalizedString {\n if (typeof compiled === 'function') {\n return compiled(values) as LocalizedString\n }\n // Use core interpolate for ICU message parsing (handles plural, select, etc.)\n return interpolate(compiled, values, locale) as LocalizedString\n}\n\n/** Extract the attribute name from v-t modifiers (e.g., v-t.alt → 'alt') */\nfunction getModifierAttr(modifiers: Partial<Record<string, boolean>>): string | undefined {\n const keys = Object.keys(modifiers).filter((k) => k !== 'plural')\n return keys.length > 0 ? keys[0] : undefined\n}\n\n/**\n * Create a Fluenti Vue plugin (SSR-safe, per-request instance).\n *\n * Each invocation creates entirely fresh state — no module-level singletons —\n * so it is safe to call once per SSR request.\n */\nexport function createFluenti(options: FluentiConfig): FluentiPlugin {\n const lazyLocaleLoading = options.lazyLocaleLoading\n ?? (options as FluentiConfig & { splitting?: boolean }).splitting\n ?? false\n const diagnostics = options.diagnostics ? createDiagnostics(options.diagnostics) : undefined\n const locale = ref(options.locale)\n // Intentional mutation: Vue's shallowReactive API requires in-place property assignment for reactivity\n const catalogs = shallowReactive<AllMessages>({ ...options.messages })\n const isLoading = ref(false)\n const loadedLocalesSet = new Set<string>([options.locale])\n const loadedLocales = ref<ReadonlySet<string>>(new Set(loadedLocalesSet))\n\n function lookup(\n loc: Locale,\n id: string,\n ): CompiledMessage | undefined {\n const msgs = catalogs[loc]\n if (!msgs) return undefined\n return msgs[id]\n }\n\n function t(strings: TemplateStringsArray, ...exprs: unknown[]): LocalizedString\n function t(id: string | MessageDescriptor, values?: Record<string, unknown>): LocalizedString\n function t(idOrStrings: string | MessageDescriptor | TemplateStringsArray, ...rest: unknown[]): LocalizedString {\n // Tagged template form: t`Hello ${name}`\n if (Array.isArray(idOrStrings) && 'raw' in idOrStrings) {\n const strings = idOrStrings as TemplateStringsArray\n const icu = buildICUMessage(strings, rest)\n const values = Object.fromEntries(rest.map((v, i) => [`arg${i}`, v]))\n // Delegate to the function-call path with the ICU string as the id\n return t(icu, values)\n }\n\n // Function call form\n const id = idOrStrings as string | MessageDescriptor\n const values = rest[0] as Record<string, unknown> | undefined\n\n // Handle MessageDescriptor objects (from msg``)\n let messageId: string\n let fallbackMessage: string | undefined\n if (typeof id === 'object' && id !== null) {\n messageId = resolveDescriptorId(id) ?? ''\n fallbackMessage = id.message\n } else {\n messageId = id\n }\n\n // Read locale.value to register a Vue reactive dependency\n const currentLocale = locale.value\n\n // Build the chain of locales to try\n const chain: Locale[] = [currentLocale]\n\n if (options.fallbackLocale && !chain.includes(options.fallbackLocale)) {\n chain.push(options.fallbackLocale)\n }\n\n if (options.fallbackChain?.[currentLocale]) {\n for (const fallback of options.fallbackChain[currentLocale]) {\n if (!chain.includes(fallback)) {\n chain.push(fallback)\n }\n }\n } else if (options.fallbackChain?.['*']) {\n for (const fallback of options.fallbackChain['*']) {\n if (!chain.includes(fallback)) {\n chain.push(fallback)\n }\n }\n }\n\n for (const loc of chain) {\n const compiled = lookup(loc, messageId)\n if (compiled !== undefined) {\n if (loc !== currentLocale) {\n diagnostics?.fallbackUsed(currentLocale, loc, messageId)\n }\n return resolveMessage(compiled, values, loc)\n }\n }\n\n // Report missing key via diagnostics\n diagnostics?.missingKey(currentLocale, messageId)\n\n // Try the missing handler\n if (options.missing) {\n const result = options.missing(currentLocale, messageId)\n if (result !== undefined) return result as LocalizedString\n }\n\n // If we have a fallback message from a MessageDescriptor, interpolate it\n if (fallbackMessage) {\n return interpolate(fallbackMessage, values, currentLocale) as LocalizedString\n }\n\n // Final fallback — if the id looks like an ICU message, interpolate it\n // (compile-time transforms like <Plural> emit inline ICU as t() arguments)\n if (messageId.includes('{')) {\n return interpolate(messageId, values, currentLocale) as LocalizedString\n }\n return messageId as LocalizedString\n }\n\n let _localeRequestId = 0\n\n async function setLocale(newLocale: Locale): Promise<void> {\n if (!lazyLocaleLoading || !options.chunkLoader) {\n locale.value = newLocale\n return\n }\n\n const splitRuntime = getSplitRuntimeModule()\n\n if (loadedLocalesSet.has(newLocale)) {\n // Already loaded, instant switch\n if (splitRuntime?.__switchLocale) {\n await splitRuntime.__switchLocale(newLocale)\n }\n locale.value = newLocale\n return\n }\n\n // Race-condition protection: track request ID\n const thisRequest = ++_localeRequestId\n isLoading.value = true\n try {\n const messages = resolveChunkMessages(await options.chunkLoader(newLocale))\n // Stale request — a newer setLocale call superseded this one\n if (thisRequest !== _localeRequestId) return\n // Intentional mutation: Vue's shallowReactive API requires in-place property assignment for reactivity\n catalogs[newLocale] = { ...catalogs[newLocale], ...messages }\n loadedLocalesSet.add(newLocale)\n loadedLocales.value = new Set(loadedLocalesSet)\n if (splitRuntime?.__switchLocale) {\n await splitRuntime.__switchLocale(newLocale)\n }\n locale.value = newLocale\n } finally {\n if (thisRequest === _localeRequestId) {\n isLoading.value = false\n }\n }\n }\n\n function loadMessages(loc: Locale, messages: Messages): void {\n // Intentional mutation: Vue's shallowReactive API requires in-place property assignment for reactivity\n catalogs[loc] = { ...catalogs[loc], ...messages }\n loadedLocalesSet.add(loc)\n loadedLocales.value = new Set(loadedLocalesSet)\n }\n\n const _preloadInFlight = new Set<string>()\n\n function preloadLocale(loc: string): void {\n if (!lazyLocaleLoading || loadedLocalesSet.has(loc) || !options.chunkLoader || _preloadInFlight.has(loc)) return\n _preloadInFlight.add(loc)\n const splitRuntime = getSplitRuntimeModule()\n options.chunkLoader(loc).then(async (loaded) => {\n const messages = resolveChunkMessages(loaded)\n // Intentional mutation: Vue's shallowReactive API requires in-place property assignment for reactivity\n catalogs[loc] = { ...catalogs[loc], ...messages }\n loadedLocalesSet.add(loc)\n loadedLocales.value = new Set(loadedLocalesSet)\n if (splitRuntime?.__preloadLocale) {\n await splitRuntime.__preloadLocale(loc)\n }\n }).catch((e: unknown) => {\n console.warn('[fluenti] preload failed:', loc, e)\n }).finally(() => {\n _preloadInFlight.delete(loc)\n })\n }\n\n function getLocales(): Locale[] {\n return Object.keys(catalogs)\n }\n\n function d(value: Date | number, style?: string): LocalizedString {\n const currentLocale = locale.value\n return formatDate(value, currentLocale, style, options.dateFormats) as LocalizedString\n }\n\n function n(value: number, style?: string): LocalizedString {\n const currentLocale = locale.value\n return formatNumber(value, currentLocale, style, options.numberFormats) as LocalizedString\n }\n\n function format(message: string, values?: Record<string, unknown>): LocalizedString {\n return resolveMessage(message, values, locale.value)\n }\n\n /**\n * Rich text helper for v-t with child elements.\n * Translates the message (which contains `<0>content</0>` placeholders),\n * then replaces each placeholder with the original HTML element.\n * Used via `v-html=\"$vtRich('msg', elements)\"` in compile-time transforms.\n * @internal\n */\n function vtRich(\n message: string | MessageDescriptor,\n elements: Array<{ tag: string; attrs?: Record<string, string>; rawAttrs?: string }>,\n values?: Record<string, unknown>,\n ): string {\n const translated = values ? t(message, values) : t(message)\n // Escape the entire translated string first to neutralise any injected HTML\n const escaped = escapeHtml(translated)\n\n // Helper to build attribute string from element.\n // Both rawAttrs and attrs are escaped to prevent XSS — even though rawAttrs\n // originates from compile-time transforms, $vtRich is exposed on globalProperties\n // so we apply defence-in-depth.\n function buildAttrs(el: { attrs?: Record<string, string>; rawAttrs?: string }): string {\n if (el.rawAttrs != null && el.rawAttrs !== '') {\n // Parse rawAttrs back into key/value pairs and escape each one.\n // Handles: key=\"val\", key='val', and bare key (boolean attribute).\n const parts: string[] = []\n const attrRe = /([\\w:@.!-]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'))?/g\n let m: RegExpExecArray | null\n while ((m = attrRe.exec(el.rawAttrs)) !== null) {\n const key = escapeHtml(m[1]!)\n const val = m[2] ?? m[3]\n parts.push(val !== undefined ? `${key}=\"${escapeHtml(val)}\"` : key)\n }\n return parts.join(' ')\n }\n if (!el.attrs) return ''\n return Object.entries(el.attrs)\n .map(([k, v]) => v ? `${escapeHtml(k)}=\"${escapeHtml(v)}\"` : escapeHtml(k))\n .join(' ')\n }\n\n // First: handle self-closing <idx/> (escaped as &lt;idx/&gt;)\n let result = escaped.replace(/&lt;(\\d+)\\/&gt;/g, (_match, idxStr: string) => {\n const el = elements[Number(idxStr)]\n if (!el) return ''\n const tag = escapeHtml(el.tag)\n const attrs = buildAttrs(el)\n return `<${tag}${attrs ? ' ' + attrs : ''} />`\n })\n\n // Then: handle paired <idx>content</idx>\n result = result.replace(/&lt;(\\d+)&gt;([\\s\\S]*?)&lt;\\/\\1&gt;/g, (_match, idxStr: string, content: string) => {\n const el = elements[Number(idxStr)]\n if (!el) return content\n const tag = escapeHtml(el.tag)\n const attrs = buildAttrs(el)\n return `<${tag}${attrs ? ' ' + attrs : ''}>${content}</${tag}>`\n })\n\n return result\n }\n\n function te(key: string, loc?: string): boolean {\n const targetLocale = loc ?? locale.value\n return lookup(targetLocale, key) !== undefined\n }\n\n function tm(key: string, loc?: string): CompiledMessage | undefined {\n const targetLocale = loc ?? locale.value\n return lookup(targetLocale, key)\n }\n\n const context: FluentiContext = {\n t,\n locale,\n setLocale,\n loadMessages,\n getLocales,\n d,\n n,\n format,\n isLoading,\n loadedLocales,\n preloadLocale,\n te,\n tm,\n }\n\n return {\n install(app: App) {\n app.provide(FLUENTI_KEY, context)\n const prefix = options.componentPrefix ?? ''\n app.component(`${prefix}Trans`, Trans)\n app.component(`${prefix}Plural`, Plural)\n app.component(`${prefix}Select`, Select)\n app.component(`${prefix}DateTime`, DateTime)\n app.component(`${prefix}NumberFormat`, NumberFormat)\n if (options.injectGlobalProperties !== false) {\n app.config.globalProperties['$t'] = t\n app.config.globalProperties['$d'] = d\n app.config.globalProperties['$n'] = n\n app.config.globalProperties['$vtRich'] = vtRich\n }\n\n // Runtime v-t directive (fallback when compile-time transform is not used)\n const vtOriginalIds = new WeakMap<HTMLElement, string>()\n app.directive('t', {\n mounted(el, binding) {\n const attrName = getModifierAttr(binding.modifiers)\n if (attrName) {\n // v-t.alt, v-t.placeholder, etc. — translate the attribute\n const original = el.getAttribute(attrName) ?? ''\n vtOriginalIds.set(el, original)\n el.setAttribute(attrName, t(original))\n } else {\n // v-t or v-t:id — translate text content\n const id = binding.arg ?? el.textContent ?? ''\n vtOriginalIds.set(el, id.trim())\n el.textContent = t(id.trim(), binding.value != null ? { ...binding.value } : undefined)\n }\n },\n updated(el, binding) {\n const attrName = getModifierAttr(binding.modifiers)\n if (attrName) {\n const original = vtOriginalIds.get(el) ?? el.getAttribute(attrName) ?? ''\n el.setAttribute(attrName, t(original))\n } else {\n const id = binding.arg ?? vtOriginalIds.get(el) ?? ''\n el.textContent = t(id.trim(), binding.value != null ? { ...binding.value } : undefined)\n }\n },\n })\n },\n global: context,\n }\n}\n","import type { CompileTimeT } from '@fluenti/core'\n\nexport const t: CompileTimeT = ((..._args: unknown[]) => {\n throw new Error(\n \"[fluenti] `t` imported from '@fluenti/vue' is a compile-time API. \" +\n 'Use it only with the Fluenti build transform inside <script setup> or setup(). ' +\n 'For runtime lookups, use useI18n().t(...).',\n )\n}) as CompileTimeT\n"],"mappings":"uJ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":["../src/plugin.ts","../src/compile-time-t.ts"],"sourcesContent":["import { type App, type Ref, ref, shallowReactive } from 'vue'\nimport type { AllMessages, Locale, LocalizedString, Messages, CompiledMessage, MessageDescriptor, DiagnosticsConfig, CustomFormatter } from '@fluenti/core'\nimport { createFluentiCore } from '@fluenti/core'\nimport { FLUENTI_KEY } from './injection-key'\n// Components are in @fluenti/vue/components subpath.\n// Global component registration is opt-in via `components` config option.\n\n/** Escape HTML special characters to prevent XSS. @internal */\nfunction escapeHtml(str: string): string {\n return str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\n}\n\n/** Compiled message chunk loader for lazy locale loading */\nexport type ChunkLoader = (\n locale: string,\n) => Promise<Record<string, CompiledMessage> | { default: Record<string, CompiledMessage> }>\n\ninterface SplitRuntimeModule {\n __switchLocale?: (locale: string) => Promise<void>\n __preloadLocale?: (locale: string) => Promise<void>\n}\n\nconst SPLIT_RUNTIME_KEY = Symbol.for('fluenti.runtime.vue.v1')\n\nfunction getSplitRuntimeModule(): SplitRuntimeModule | null {\n const runtime = (globalThis as Record<PropertyKey, unknown>)[SPLIT_RUNTIME_KEY]\n return typeof runtime === 'object' && runtime !== null\n ? runtime as SplitRuntimeModule\n : null\n}\n\nfunction resolveChunkMessages(\n loaded: Record<string, CompiledMessage> | { default: Record<string, CompiledMessage> },\n): Record<string, CompiledMessage> {\n return typeof loaded === 'object' && loaded !== null && 'default' in loaded\n ? (loaded as { default: Record<string, CompiledMessage> }).default\n : loaded\n}\n\n/** Context object returned by `useI18n()` and available as `$t` etc. on globalProperties */\nexport interface FluentiContext {\n /** Translate a message by id or MessageDescriptor, with optional interpolation values */\n t(id: string | MessageDescriptor, values?: Record<string, unknown>): LocalizedString\n /** Tagged template form: t`Hello ${name}` */\n t(strings: TemplateStringsArray, ...exprs: unknown[]): LocalizedString\n /** Reactive ref for current locale */\n locale: Readonly<Ref<Locale>>\n /** Change the active locale (async when lazy locale loading is enabled) */\n setLocale(locale: Locale): Promise<void>\n /** Dynamically load messages for a locale */\n loadMessages(locale: Locale, messages: Messages): void\n /** Get all locales that have loaded messages */\n getLocales(): Locale[]\n /** Format a date value according to locale */\n d(value: Date | number, style?: string): LocalizedString\n /** Format a number according to locale */\n n(value: number, style?: string): LocalizedString\n /** Format an ICU message string directly (no catalog lookup) */\n format(message: string, values?: Record<string, unknown>): LocalizedString\n /** Whether a locale chunk is currently being loaded */\n isLoading: Readonly<Ref<boolean>>\n /** Set of locales whose messages have been loaded */\n loadedLocales: Readonly<Ref<ReadonlySet<string>>>\n /** Preload a locale in the background without switching to it */\n preloadLocale(locale: string): void\n /** Check if a translation key exists in the catalog */\n te(key: string, locale?: string): boolean\n /** Get the raw compiled message without interpolation */\n tm(key: string, locale?: string): CompiledMessage | undefined\n}\n\n/** Injection key for providing/injecting fluenti context */\nexport { FLUENTI_KEY } from './injection-key'\n\n/** Options for creating the Fluenti Vue plugin */\nexport interface FluentiConfig {\n locale: string\n fallbackLocale?: string\n messages: AllMessages\n missing?: (locale: string, id: string) => string | undefined\n dateFormats?: Record<string, Intl.DateTimeFormatOptions | 'relative'>\n numberFormats?: Record<string, Intl.NumberFormatOptions | ((locale: string) => Intl.NumberFormatOptions)>\n fallbackChain?: Record<string, string[]>\n /** Async chunk loader for lazy locale loading */\n chunkLoader?: ChunkLoader\n /** Enable lazy locale loading through chunkLoader */\n lazyLocaleLoading?: boolean\n /**\n * Prefix for globally registered components (Trans, Plural, Select).\n *\n * Set this to avoid naming conflicts with other libraries.\n *\n * @example\n * componentPrefix: 'I18n'\n * // Registers: I18nTrans, I18nPlural, I18nSelect\n *\n * @example\n * componentPrefix: 'Fluenti'\n * // Registers: FluentiTrans, FluentiPlural, FluentiSelect\n *\n * @default '' (no prefix — Trans, Plural, Select)\n */\n componentPrefix?: string\n /**\n * Whether to inject `$t`, `$d`, `$n`, `$vtRich` onto `app.config.globalProperties`.\n *\n * Set to `false` to avoid polluting the global namespace (e.g. when migrating from vue-i18n\n * or when using composition API exclusively via `useI18n()`).\n *\n * @default true\n */\n injectGlobalProperties?: boolean\n /** Runtime diagnostics configuration or pre-created instance */\n diagnostics?: DiagnosticsConfig | { missingKey: (locale: string, id: string) => void; fallbackUsed: (locale: string, fallbackLocale: string, id: string) => void; enabled: boolean }\n /**\n * Custom message interpolation function.\n *\n * By default, the runtime uses a lightweight `{key}` replacer.\n * Pass the full `interpolate` from `@fluenti/core/internal` for\n * runtime ICU MessageFormat parsing (adds ~2.5 KB gzip).\n *\n * @example\n * ```ts\n * import { interpolate } from '@fluenti/core/internal'\n * createFluenti({ interpolate, ... })\n * ```\n */\n interpolate?: (\n message: string,\n values: Record<string, unknown> | undefined,\n locale: string,\n formatters?: Record<string, CustomFormatter>,\n ) => string\n /**\n * Components to register globally via `app.component()`.\n *\n * Import from `@fluenti/vue/components` and pass here to enable global\n * component registration without bloating the default bundle.\n *\n * @example\n * ```ts\n * import * as components from '@fluenti/vue/components'\n * app.use(createFluenti({ components, ... }))\n * ```\n */\n components?: Record<string, unknown>\n}\n\n/** Return value of `createFluenti()` */\nexport interface FluentiPlugin {\n /** Vue plugin install method */\n install(app: App): void\n /** The global fluenti context (same as what useI18n returns) */\n global: FluentiContext\n}\n\n/** Extract the attribute name from v-t modifiers (e.g., v-t.alt → 'alt') */\nfunction getModifierAttr(modifiers: Partial<Record<string, boolean>>): string | undefined {\n const keys = Object.keys(modifiers).filter((k) => k !== 'plural')\n return keys.length > 0 ? keys[0] : undefined\n}\n\n/**\n * Create a Fluenti Vue plugin (SSR-safe, per-request instance).\n *\n * Each invocation creates entirely fresh state — no module-level singletons —\n * so it is safe to call once per SSR request.\n *\n * @example\n * ```ts\n * import { createFluenti } from '@fluenti/vue'\n * import messages from './locales/compiled/en.js'\n *\n * const fluenti = createFluenti({\n * locale: 'en',\n * messages: { en: messages },\n * })\n *\n * app.use(fluenti)\n * ```\n */\nexport function createFluenti(options: FluentiConfig): FluentiPlugin {\n const lazyLocaleLoading = options.lazyLocaleLoading\n ?? (options as FluentiConfig & { splitting?: boolean }).splitting\n ?? false\n\n // Create the core i18n instance — delegates t/d/n/format/loadMessages/getLocales\n // Build config incrementally to satisfy exactOptionalPropertyTypes —\n // optional properties must not receive `undefined` as a value.\n const coreConfig: Parameters<typeof createFluentiCore>[0] = {\n locale: options.locale,\n messages: options.messages ?? {},\n }\n if (options.fallbackLocale !== undefined) coreConfig.fallbackLocale = options.fallbackLocale\n if (options.fallbackChain !== undefined) coreConfig.fallbackChain = options.fallbackChain\n if (options.dateFormats !== undefined) coreConfig.dateFormats = options.dateFormats\n if (options.numberFormats !== undefined) coreConfig.numberFormats = options.numberFormats\n if (options.missing !== undefined) coreConfig.missing = options.missing\n if (options.diagnostics !== undefined) coreConfig.diagnostics = options.diagnostics as Parameters<typeof createFluentiCore>[0]['diagnostics']\n if (options.interpolate !== undefined) coreConfig.interpolate = options.interpolate\n const i18n = createFluentiCore(coreConfig)\n\n const locale = ref(options.locale)\n // Intentional mutation: Vue's shallowReactive API requires in-place property assignment for reactivity\n const catalogs = shallowReactive<AllMessages>({ ...options.messages })\n const isLoading = ref(false)\n const loadedLocalesSet = new Set<string>([options.locale])\n const loadedLocales = ref<ReadonlySet<string>>(new Set(loadedLocalesSet))\n\n /** Local catalog lookup for te/tm (core doesn't expose raw catalog access) */\n function lookup(\n loc: Locale,\n id: string,\n ): CompiledMessage | undefined {\n const msgs = catalogs[loc]\n if (!msgs) return undefined\n return msgs[id]\n }\n\n /** Sync Vue reactive locale to core before delegation */\n function syncLocale(): void {\n if (i18n.locale !== locale.value) {\n i18n.locale = locale.value\n }\n }\n\n function t(strings: TemplateStringsArray, ...exprs: unknown[]): LocalizedString\n function t(id: string | MessageDescriptor, values?: Record<string, unknown>): LocalizedString\n function t(idOrStrings: string | MessageDescriptor | TemplateStringsArray, ...rest: unknown[]): LocalizedString {\n // Read locale.value and catalogs to register Vue reactive dependencies\n // so components re-render when locale or messages change\n const currentLocale = locale.value\n void catalogs[currentLocale]\n syncLocale()\n // Dispatch to the correct overload based on input type\n if (Array.isArray(idOrStrings) && 'raw' in idOrStrings) {\n return i18n.t(idOrStrings as TemplateStringsArray, ...rest)\n }\n return i18n.t(idOrStrings as string | MessageDescriptor, rest[0] as Record<string, unknown> | undefined)\n }\n\n let _localeRequestId = 0\n\n async function setLocale(newLocale: Locale): Promise<void> {\n if (!lazyLocaleLoading || !options.chunkLoader) {\n i18n.locale = newLocale\n locale.value = newLocale\n return\n }\n\n const splitRuntime = getSplitRuntimeModule()\n\n if (loadedLocalesSet.has(newLocale)) {\n // Already loaded, instant switch\n if (splitRuntime?.__switchLocale) {\n await splitRuntime.__switchLocale(newLocale)\n }\n i18n.locale = newLocale\n locale.value = newLocale\n return\n }\n\n // Race-condition protection: track request ID\n const thisRequest = ++_localeRequestId\n isLoading.value = true\n try {\n const messages = resolveChunkMessages(await options.chunkLoader(newLocale))\n // Stale request — a newer setLocale call superseded this one\n if (thisRequest !== _localeRequestId) return\n // Intentional mutation: Vue's shallowReactive API requires in-place property assignment for reactivity\n catalogs[newLocale] = { ...catalogs[newLocale], ...messages }\n i18n.loadMessages(newLocale, messages)\n loadedLocalesSet.add(newLocale)\n loadedLocales.value = new Set(loadedLocalesSet)\n if (splitRuntime?.__switchLocale) {\n await splitRuntime.__switchLocale(newLocale)\n }\n // Re-check after async __switchLocale — a newer setLocale() may have superseded this one\n if (thisRequest !== _localeRequestId) return\n i18n.locale = newLocale\n locale.value = newLocale\n } finally {\n if (thisRequest === _localeRequestId) {\n isLoading.value = false\n }\n }\n }\n\n function loadMessages(loc: Locale, messages: Messages): void {\n // Intentional mutation: Vue's shallowReactive API requires in-place property assignment for reactivity\n catalogs[loc] = { ...catalogs[loc], ...messages }\n i18n.loadMessages(loc, messages)\n loadedLocalesSet.add(loc)\n loadedLocales.value = new Set(loadedLocalesSet)\n }\n\n const _preloadInFlight = new Set<string>()\n\n function preloadLocale(loc: string): void {\n if (!lazyLocaleLoading || loadedLocalesSet.has(loc) || !options.chunkLoader || _preloadInFlight.has(loc)) return\n _preloadInFlight.add(loc)\n const splitRuntime = getSplitRuntimeModule()\n options.chunkLoader(loc).then(async (loaded) => {\n const messages = resolveChunkMessages(loaded)\n // Intentional mutation: Vue's shallowReactive API requires in-place property assignment for reactivity\n catalogs[loc] = { ...catalogs[loc], ...messages }\n i18n.loadMessages(loc, messages)\n loadedLocalesSet.add(loc)\n loadedLocales.value = new Set(loadedLocalesSet)\n if (splitRuntime?.__preloadLocale) {\n await splitRuntime.__preloadLocale(loc)\n }\n }).catch((e: unknown) => {\n console.warn('[fluenti] preload failed:', loc, e)\n }).finally(() => {\n _preloadInFlight.delete(loc)\n })\n }\n\n function getLocales(): Locale[] {\n syncLocale()\n return i18n.getLocales()\n }\n\n function d(value: Date | number, style?: string): LocalizedString {\n // Read locale.value to register a Vue reactive dependency\n void locale.value\n syncLocale()\n return i18n.d(value, style)\n }\n\n function n(value: number, style?: string): LocalizedString {\n // Read locale.value to register a Vue reactive dependency\n void locale.value\n syncLocale()\n return i18n.n(value, style)\n }\n\n function format(message: string, values?: Record<string, unknown>): LocalizedString {\n // Read locale.value to register a Vue reactive dependency\n void locale.value\n syncLocale()\n return i18n.format(message, values)\n }\n\n /**\n * Rich text helper for v-t with child elements.\n * Translates the message (which contains `<0>content</0>` placeholders),\n * then replaces each placeholder with the original HTML element.\n * Used via `v-html=\"$vtRich('msg', elements)\"` in compile-time transforms.\n * @internal\n */\n function vtRich(\n message: string | MessageDescriptor,\n elements: Array<{ tag: string; attrs?: Record<string, string>; rawAttrs?: string }>,\n values?: Record<string, unknown>,\n ): string {\n const translated = values ? t(message, values) : t(message)\n // Escape the entire translated string first to neutralise any injected HTML\n const escaped = escapeHtml(translated)\n\n // Helper to build attribute string from element.\n // Both rawAttrs and attrs are escaped to prevent XSS — even though rawAttrs\n // originates from compile-time transforms, $vtRich is exposed on globalProperties\n // so we apply defence-in-depth.\n function buildAttrs(el: { attrs?: Record<string, string>; rawAttrs?: string }): string {\n if (el.rawAttrs != null && el.rawAttrs !== '') {\n // Parse rawAttrs back into key/value pairs and escape each one.\n // Handles: key=\"val\", key='val', and bare key (boolean attribute).\n const parts: string[] = []\n const attrRe = /([\\w:@.!-]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'))?/g\n let m: RegExpExecArray | null\n while ((m = attrRe.exec(el.rawAttrs)) !== null) {\n const key = escapeHtml(m[1]!)\n const val = m[2] ?? m[3]\n parts.push(val !== undefined ? `${key}=\"${escapeHtml(val)}\"` : key)\n }\n return parts.join(' ')\n }\n if (!el.attrs) return ''\n return Object.entries(el.attrs)\n .map(([k, v]) => v ? `${escapeHtml(k)}=\"${escapeHtml(v)}\"` : escapeHtml(k))\n .join(' ')\n }\n\n // First: handle self-closing <idx/> (escaped as &lt;idx/&gt;)\n let result = escaped.replace(/&lt;(\\d+)\\/&gt;/g, (_match, idxStr: string) => {\n const el = elements[Number(idxStr)]\n if (!el) return ''\n const tag = escapeHtml(el.tag)\n const attrs = buildAttrs(el)\n return `<${tag}${attrs ? ' ' + attrs : ''} />`\n })\n\n // Then: handle paired <idx>content</idx>\n result = result.replace(/&lt;(\\d+)&gt;([\\s\\S]*?)&lt;\\/\\1&gt;/g, (_match, idxStr: string, content: string) => {\n const el = elements[Number(idxStr)]\n if (!el) return content\n const tag = escapeHtml(el.tag)\n const attrs = buildAttrs(el)\n return `<${tag}${attrs ? ' ' + attrs : ''}>${content}</${tag}>`\n })\n\n return result\n }\n\n function te(key: string, loc?: string): boolean {\n const targetLocale = loc ?? locale.value\n return lookup(targetLocale, key) !== undefined\n }\n\n function tm(key: string, loc?: string): CompiledMessage | undefined {\n const targetLocale = loc ?? locale.value\n return lookup(targetLocale, key)\n }\n\n const context: FluentiContext = {\n t,\n locale,\n setLocale,\n loadMessages,\n getLocales,\n d,\n n,\n format,\n isLoading,\n loadedLocales,\n preloadLocale,\n te,\n tm,\n }\n\n return {\n install(app: App) {\n app.provide(FLUENTI_KEY, context)\n // Register components globally if provided via config\n if (options.components) {\n const prefix = options.componentPrefix ?? ''\n const comps = options.components as Record<string, unknown>\n if (comps['Trans']) app.component(`${prefix}Trans`, comps['Trans'] as any)\n if (comps['Plural']) app.component(`${prefix}Plural`, comps['Plural'] as any)\n if (comps['Select']) app.component(`${prefix}Select`, comps['Select'] as any)\n if (comps['DateTime']) app.component(`${prefix}DateTime`, comps['DateTime'] as any)\n if (comps['NumberFormat']) app.component(`${prefix}NumberFormat`, comps['NumberFormat'] as any)\n }\n if (options.injectGlobalProperties !== false) {\n app.config.globalProperties['$t'] = t\n app.config.globalProperties['$d'] = d\n app.config.globalProperties['$n'] = n\n app.config.globalProperties['$vtRich'] = vtRich\n }\n\n // Runtime v-t directive (fallback when compile-time transform is not used)\n const vtOriginalIds = new WeakMap<HTMLElement, string>()\n app.directive('t', {\n mounted(el, binding) {\n const attrName = getModifierAttr(binding.modifiers)\n if (attrName) {\n // v-t.alt, v-t.placeholder, etc. — translate the attribute\n const original = el.getAttribute(attrName) ?? ''\n vtOriginalIds.set(el, original)\n el.setAttribute(attrName, t(original))\n } else {\n // v-t or v-t:id — translate text content\n const id = binding.arg ?? el.textContent ?? ''\n vtOriginalIds.set(el, id.trim())\n el.textContent = t(id.trim(), binding.value != null ? { ...binding.value } : undefined)\n }\n },\n updated(el, binding) {\n const attrName = getModifierAttr(binding.modifiers)\n if (attrName) {\n const original = vtOriginalIds.get(el) ?? el.getAttribute(attrName) ?? ''\n el.setAttribute(attrName, t(original))\n } else {\n const id = binding.arg ?? vtOriginalIds.get(el) ?? ''\n el.textContent = t(id.trim(), binding.value != null ? { ...binding.value } : undefined)\n }\n },\n })\n },\n global: context,\n }\n}\n","import type { CompileTimeT } from '@fluenti/core'\n\nexport const t: CompileTimeT = ((..._args: unknown[]) => {\n throw new Error(\n \"[fluenti] `t` imported from '@fluenti/vue' is a compile-time API. \" +\n 'Use it only with the Fluenti build transform inside <script setup> or setup(). ' +\n 'For runtime lookups, use useI18n().t(...).',\n )\n}) as Compile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AG,aAAa,EAAU,EAAE,EAAS,CAAC,MAGtC,EAAG,YAAc,GADN,EAAQ,KAAO,EAAc,IAAI,EAAG,EAAI,IAC7B,MAAM,CAAE,EAAQ,OAAS,KAA8B,IAAA,GAAvB,CAAE,GAAG,EAAQ,MAAO,CAAa,EAG5F,CAAC,EAEJ,OAAQ,EACT,CCheH,IAAa,IAAoB,GAAG,IAAqB,CACvD,MAAU,MACR,8LAGD"}
package/dist/index.d.ts CHANGED
@@ -2,15 +2,10 @@ export { createFluenti, FLUENTI_KEY } from './plugin';
2
2
  export type { FluentiConfig, FluentiPlugin, FluentiContext } from './plugin';
3
3
  export { useI18n } from './use-i18n';
4
4
  export { t } from './compile-time-t';
5
- export { Trans } from './components/Trans';
5
+ export { msg } from './msg';
6
6
  export type { FluentiTransProps } from './components/Trans';
7
- export { Plural } from './components/Plural';
8
7
  export type { FluentiPluralProps } from './components/Plural';
9
- export { Select } from './components/Select';
10
8
  export type { FluentiSelectProps } from './components/Select';
11
- export { DateTime } from './components/DateTime';
12
9
  export type { FluentiDateTimeProps } from './components/DateTime';
13
- export { NumberFormat } from './components/NumberFormat';
14
10
  export type { FluentiNumberFormatProps } from './components/NumberFormat';
15
- export { msg } from './msg';
16
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACrD,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,MAAM,EAA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