{"version":3,"file":"locale.mjs","names":["computed","inject","provide","ref","defaultRtl","createVuetifyAdapter","LocaleSymbol","Symbol","for","isLocaleInstance","obj","name","createLocale","options","i18n","adapter","rtl","createRtl","useLocale","locale","Error","provideLocale","props","provideRtl","data","RtlSymbol","isRtl","value","current","rtlClasses","useRtl"],"sources":["../../src/composables/locale.ts"],"sourcesContent":["// Utilities\nimport { computed, inject, provide, ref } from 'vue'\nimport { defaultRtl } from '@/locale'\nimport { createVuetifyAdapter } from '@/locale/adapters/vuetify'\n\n// Types\nimport type { InjectionKey, Ref } from 'vue'\n\nexport interface LocaleMessages {\n [key: string]: LocaleMessages | string\n}\n\nexport interface LocaleOptions {\n messages?: LocaleMessages\n locale?: string\n fallback?: string\n adapter?: LocaleInstance\n}\n\nexport interface LocaleInstance {\n name: string\n messages: Ref\n current: Ref\n fallback: Ref\n t: (key: string, ...params: unknown[]) => string\n n: (value: number) => string\n provide: (props: LocaleOptions) => LocaleInstance\n}\n\nexport const LocaleSymbol: InjectionKey = Symbol.for('vuetify:locale')\n\nfunction isLocaleInstance (obj: any): obj is LocaleInstance {\n return obj.name != null\n}\n\nexport function createLocale (options?: LocaleOptions & RtlOptions) {\n const i18n = options?.adapter && isLocaleInstance(options?.adapter) ? options?.adapter : createVuetifyAdapter(options)\n const rtl = createRtl(i18n, options)\n\n return { ...i18n, ...rtl }\n}\n\nexport function useLocale () {\n const locale = inject(LocaleSymbol)\n\n if (!locale) throw new Error('[Vuetify] Could not find injected locale instance')\n\n return locale\n}\n\nexport function provideLocale (props: LocaleOptions & RtlProps) {\n const locale = inject(LocaleSymbol)\n\n if (!locale) throw new Error('[Vuetify] Could not find injected locale instance')\n\n const i18n = locale.provide(props)\n const rtl = provideRtl(i18n, locale.rtl, props)\n\n const data = { ...i18n, ...rtl }\n\n provide(LocaleSymbol, data)\n\n return data\n}\n\n// RTL\n\nexport interface RtlOptions {\n rtl?: Record\n}\n\nexport interface RtlProps {\n rtl?: boolean\n}\n\nexport interface RtlInstance {\n isRtl: Ref\n rtl: Ref>\n rtlClasses: Ref\n}\n\nexport const RtlSymbol: InjectionKey = Symbol.for('vuetify:rtl')\n\nexport function createRtl (i18n: LocaleInstance, options?: RtlOptions): RtlInstance {\n const rtl = ref>(options?.rtl ?? defaultRtl)\n const isRtl = computed(() => rtl.value[i18n.current.value] ?? false)\n\n return {\n isRtl,\n rtl,\n rtlClasses: computed(() => `v-locale--is-${isRtl.value ? 'rtl' : 'ltr'}`),\n }\n}\n\nexport function provideRtl (locale: LocaleInstance, rtl: RtlInstance['rtl'], props: RtlProps): RtlInstance {\n const isRtl = computed(() => props.rtl ?? rtl.value[locale.current.value] ?? false)\n\n return {\n isRtl,\n rtl,\n rtlClasses: computed(() => `v-locale--is-${isRtl.value ? 'rtl' : 'ltr'}`),\n }\n}\n\nexport function useRtl () {\n const locale = inject(LocaleSymbol)\n\n if (!locale) throw new Error('[Vuetify] Could not find injected rtl instance')\n\n return { isRtl: locale.isRtl, rtlClasses: locale.rtlClasses }\n}\n"],"mappings":"AAAA;AACA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,OAAO,EAAEC,GAAG,QAAQ,KAAK;AAAA,SAC3CC,UAAU;AAAA,SACVC,oBAAoB,0CAE7B;AAwBA,OAAO,MAAMC,YAAwD,GAAGC,MAAM,CAACC,GAAG,CAAC,gBAAgB,CAAC;AAEpG,SAASC,gBAAgBA,CAAEC,GAAQ,EAAyB;EAC1D,OAAOA,GAAG,CAACC,IAAI,IAAI,IAAI;AACzB;AAEA,OAAO,SAASC,YAAYA,CAAEC,OAAoC,EAAE;EAClE,MAAMC,IAAI,GAAGD,OAAO,EAAEE,OAAO,IAAIN,gBAAgB,CAACI,OAAO,EAAEE,OAAO,CAAC,GAAGF,OAAO,EAAEE,OAAO,GAAGV,oBAAoB,CAACQ,OAAO,CAAC;EACtH,MAAMG,GAAG,GAAGC,SAAS,CAACH,IAAI,EAAED,OAAO,CAAC;EAEpC,OAAO;IAAE,GAAGC,IAAI;IAAE,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