@fluenti/vue 0.1.3 → 0.2.1

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/README.md CHANGED
@@ -60,7 +60,7 @@ const formatted = t('You have {count} items', { count: 42 })
60
60
  ### 1. Install
61
61
 
62
62
  ```bash
63
- pnpm add @fluenti/core @fluenti/vue @fluenti/vite-plugin
63
+ pnpm add @fluenti/core @fluenti/vue
64
64
  ```
65
65
 
66
66
  ### 2. Configure Vite
@@ -68,10 +68,10 @@ pnpm add @fluenti/core @fluenti/vue @fluenti/vite-plugin
68
68
  ```ts
69
69
  // vite.config.ts
70
70
  import vue from '@vitejs/plugin-vue'
71
- import fluenti from '@fluenti/vite-plugin'
71
+ import fluentiVue from '@fluenti/vue/vite-plugin'
72
72
 
73
73
  export default {
74
- plugins: [vue(), fluenti({ framework: 'vue' })],
74
+ plugins: [vue(), fluentiVue()],
75
75
  }
76
76
  ```
77
77
 
@@ -0,0 +1,112 @@
1
+ let e=require(`@fluenti/vite-plugin`),t=require(`@fluenti/vite-plugin/sfc-transform`),n=require(`node:path`);var r={generateRuntime(e){let{catalogDir:t,locales:r,sourceLocale:i,defaultBuildLocale:a}=e,o=a||i,s=(0,n.resolve)(process.cwd(),t);return`
2
+ import { shallowReactive, ref } from 'vue'
3
+ import __defaultMsgs from '${s}/${o}.js'
4
+
5
+ const __catalog = shallowReactive({ ...__defaultMsgs })
6
+ const __currentLocale = ref('${o}')
7
+ const __loadedLocales = new Set(['${o}'])
8
+ const __loading = ref(false)
9
+ const __cache = new Map()
10
+ const __normalizeMessages = (mod) => mod.default ?? mod
11
+
12
+ const __loaders = {
13
+ ${r.filter(e=>e!==o).map(e=>` '${e}': () => import('${s}/${e}.js'),`).join(`
14
+ `)}
15
+ }
16
+
17
+ async function __switchLocale(locale) {
18
+ if (__loadedLocales.has(locale)) {
19
+ Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)
20
+ __currentLocale.value = locale
21
+ return
22
+ }
23
+ __loading.value = true
24
+ try {
25
+ const mod = __normalizeMessages(await __loaders[locale]())
26
+ __cache.set(locale, mod)
27
+ __loadedLocales.add(locale)
28
+ Object.assign(__catalog, mod)
29
+ __currentLocale.value = locale
30
+ } finally {
31
+ __loading.value = false
32
+ }
33
+ }
34
+
35
+ async function __preloadLocale(locale) {
36
+ if (__loadedLocales.has(locale) || !__loaders[locale]) return
37
+ try {
38
+ const mod = __normalizeMessages(await __loaders[locale]())
39
+ __cache.set(locale, mod)
40
+ __loadedLocales.add(locale)
41
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
42
+ }
43
+
44
+ globalThis[Symbol.for('fluenti.runtime.vue')] = { __switchLocale, __preloadLocale }
45
+
46
+ export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
47
+ `},generateRouteRuntime(e){let{catalogDir:t,locales:r,sourceLocale:i,defaultBuildLocale:a}=e,o=a||i,s=(0,n.resolve)(process.cwd(),t);return`
48
+ import { shallowReactive, ref } from 'vue'
49
+ import __defaultMsgs from '${s}/${o}.js'
50
+
51
+ const __catalog = shallowReactive({ ...__defaultMsgs })
52
+ const __currentLocale = ref('${o}')
53
+ const __loadedLocales = new Set(['${o}'])
54
+ const __loading = ref(false)
55
+ const __cache = new Map()
56
+ const __loadedRoutes = new Set()
57
+ const __normalizeMessages = (mod) => mod.default ?? mod
58
+
59
+ const __loaders = {
60
+ ${r.filter(e=>e!==o).map(e=>` '${e}': () => import('${s}/${e}.js'),`).join(`
61
+ `)}
62
+ }
63
+
64
+ const __routeLoaders = {}
65
+
66
+ function __registerRouteLoader(routeId, locale, loader) {
67
+ const key = routeId + ':' + locale
68
+ __routeLoaders[key] = loader
69
+ }
70
+
71
+ async function __loadRoute(routeId, locale) {
72
+ const key = routeId + ':' + (locale || __currentLocale.value)
73
+ if (__loadedRoutes.has(key)) return
74
+ const loader = __routeLoaders[key]
75
+ if (!loader) return
76
+ const mod = __normalizeMessages(await loader())
77
+ Object.assign(__catalog, mod)
78
+ __loadedRoutes.add(key)
79
+ }
80
+
81
+ async function __switchLocale(locale) {
82
+ if (locale === __currentLocale.value) return
83
+ __loading.value = true
84
+ try {
85
+ if (__cache.has(locale)) {
86
+ Object.assign(__catalog, __cache.get(locale))
87
+ } else {
88
+ const mod = __normalizeMessages(await __loaders[locale]())
89
+ __cache.set(locale, mod)
90
+ Object.assign(__catalog, mod)
91
+ }
92
+ __loadedLocales.add(locale)
93
+ __currentLocale.value = locale
94
+ } finally {
95
+ __loading.value = false
96
+ }
97
+ }
98
+
99
+ async function __preloadLocale(locale) {
100
+ if (__cache.has(locale) || !__loaders[locale]) return
101
+ try {
102
+ const mod = __normalizeMessages(await __loaders[locale]())
103
+ __cache.set(locale, mod)
104
+ __loadedLocales.add(locale)
105
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
106
+ }
107
+
108
+ globalThis[Symbol.for('fluenti.runtime.vue')] = { __switchLocale, __preloadLocale }
109
+
110
+ export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
111
+ `}};function i(n){let i={name:`fluenti:vue-template`,enforce:`pre`,transform(e,n){if(!n.endsWith(`.vue`)||!/\bv-t\b/.test(e)&&!/<Trans[\s>]/.test(e)&&!/<Plural[\s/>]/.test(e))return;let r=(0,t.transformVtDirectives)(e);if(r!==e)return{code:r,map:null}}};return(0,e.createFluentiPlugins)({...n,framework:`vue`},[i],r)}module.exports=i;
112
+ //# sourceMappingURL=vite-plugin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.cjs","names":[],"sources":["../src/vue-runtime.ts","../src/vite-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path'\nimport type { RuntimeGenerator, RuntimeGeneratorOptions } from '@fluenti/vite-plugin'\n\nexport const vueRuntimeGenerator: RuntimeGenerator = {\n generateRuntime(options: RuntimeGeneratorOptions): string {\n const { catalogDir, locales, sourceLocale, defaultBuildLocale } = options\n const defaultLocale = defaultBuildLocale || sourceLocale\n const absoluteCatalogDir = resolve(process.cwd(), catalogDir)\n const runtimeKey = 'fluenti.runtime.vue'\n const lazyLocales = locales.filter((locale) => locale !== defaultLocale)\n\n return `\nimport { shallowReactive, ref } from 'vue'\nimport __defaultMsgs from '${absoluteCatalogDir}/${defaultLocale}.js'\n\nconst __catalog = shallowReactive({ ...__defaultMsgs })\nconst __currentLocale = ref('${defaultLocale}')\nconst __loadedLocales = new Set(['${defaultLocale}'])\nconst __loading = ref(false)\nconst __cache = new Map()\nconst __normalizeMessages = (mod) => mod.default ?? mod\n\nconst __loaders = {\n${lazyLocales.map((l) => ` '${l}': () => import('${absoluteCatalogDir}/${l}.js'),`).join('\\n')}\n}\n\nasync function __switchLocale(locale) {\n if (__loadedLocales.has(locale)) {\n Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)\n __currentLocale.value = locale\n return\n }\n __loading.value = true\n try {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n __loadedLocales.add(locale)\n Object.assign(__catalog, mod)\n __currentLocale.value = locale\n } finally {\n __loading.value = false\n }\n}\n\nasync function __preloadLocale(locale) {\n if (__loadedLocales.has(locale) || !__loaders[locale]) return\n try {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n __loadedLocales.add(locale)\n } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }\n}\n\nglobalThis[Symbol.for('${runtimeKey}')] = { __switchLocale, __preloadLocale }\n\nexport { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }\n`\n },\n\n generateRouteRuntime(options: RuntimeGeneratorOptions): string {\n const { catalogDir, locales, sourceLocale, defaultBuildLocale } = options\n const defaultLocale = defaultBuildLocale || sourceLocale\n const absoluteCatalogDir = resolve(process.cwd(), catalogDir)\n const runtimeKey = 'fluenti.runtime.vue'\n const lazyLocales = locales.filter((locale) => locale !== defaultLocale)\n\n return `\nimport { shallowReactive, ref } from 'vue'\nimport __defaultMsgs from '${absoluteCatalogDir}/${defaultLocale}.js'\n\nconst __catalog = shallowReactive({ ...__defaultMsgs })\nconst __currentLocale = ref('${defaultLocale}')\nconst __loadedLocales = new Set(['${defaultLocale}'])\nconst __loading = ref(false)\nconst __cache = new Map()\nconst __loadedRoutes = new Set()\nconst __normalizeMessages = (mod) => mod.default ?? mod\n\nconst __loaders = {\n${lazyLocales.map((l) => ` '${l}': () => import('${absoluteCatalogDir}/${l}.js'),`).join('\\n')}\n}\n\nconst __routeLoaders = {}\n\nfunction __registerRouteLoader(routeId, locale, loader) {\n const key = routeId + ':' + locale\n __routeLoaders[key] = loader\n}\n\nasync function __loadRoute(routeId, locale) {\n const key = routeId + ':' + (locale || __currentLocale.value)\n if (__loadedRoutes.has(key)) return\n const loader = __routeLoaders[key]\n if (!loader) return\n const mod = __normalizeMessages(await loader())\n Object.assign(__catalog, mod)\n __loadedRoutes.add(key)\n}\n\nasync function __switchLocale(locale) {\n if (locale === __currentLocale.value) return\n __loading.value = true\n try {\n if (__cache.has(locale)) {\n Object.assign(__catalog, __cache.get(locale))\n } else {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n Object.assign(__catalog, mod)\n }\n __loadedLocales.add(locale)\n __currentLocale.value = locale\n } finally {\n __loading.value = false\n }\n}\n\nasync function __preloadLocale(locale) {\n if (__cache.has(locale) || !__loaders[locale]) return\n try {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n __loadedLocales.add(locale)\n } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }\n}\n\nglobalThis[Symbol.for('${runtimeKey}')] = { __switchLocale, __preloadLocale }\n\nexport { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }\n`\n },\n}\n","import type { Plugin } from 'vite'\nimport type { FluentiPluginOptions } from '@fluenti/vite-plugin'\nimport { createFluentiPlugins } from '@fluenti/vite-plugin'\nimport { transformVtDirectives } from '@fluenti/vite-plugin/sfc-transform'\nimport { vueRuntimeGenerator } from './vue-runtime'\n\nexport type { FluentiPluginOptions as FluentiVueOptions } from '@fluenti/vite-plugin'\n\nexport default function fluentiVue(options?: FluentiPluginOptions): Plugin[] {\n const vueTemplatePlugin: Plugin = {\n name: 'fluenti:vue-template',\n enforce: 'pre',\n transform(code, id) {\n if (!id.endsWith('.vue')) return undefined\n if (!/\\bv-t\\b/.test(code) && !/<Trans[\\s>]/.test(code) && !/<Plural[\\s/>]/.test(code)) return undefined\n\n const transformed = transformVtDirectives(code)\n if (transformed === code) return undefined\n\n return { code: transformed, map: null }\n },\n }\n\n return createFluentiPlugins(\n { ...options, framework: 'vue' },\n [vueTemplatePlugin],\n vueRuntimeGenerator,\n )\n}\n"],"mappings":"6GAGA,IAAa,EAAwC,CACnD,gBAAgB,EAA0C,CACxD,GAAM,CAAE,aAAY,UAAS,eAAc,sBAAuB,EAC5D,EAAgB,GAAsB,EACtC,GAAA,EAAA,EAAA,SAA6B,QAAQ,KAAK,CAAE,EAAW,CAI7D,MAAO;;6BAEkB,EAAmB,GAAG,EAAc;;;+BAGlC,EAAc;oCACT,EAAc;;;;;;EAR1B,EAAQ,OAAQ,GAAW,IAAW,EAAc,CAc9D,IAAK,GAAM,MAAM,EAAE,mBAAmB,EAAmB,GAAG,EAAE,QAAQ,CAAC,KAAK;EAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoC9F,qBAAqB,EAA0C,CAC7D,GAAM,CAAE,aAAY,UAAS,eAAc,sBAAuB,EAC5D,EAAgB,GAAsB,EACtC,GAAA,EAAA,EAAA,SAA6B,QAAQ,KAAK,CAAE,EAAW,CAI7D,MAAO;;6BAEkB,EAAmB,GAAG,EAAc;;;+BAGlC,EAAc;oCACT,EAAc;;;;;;;EAR1B,EAAQ,OAAQ,GAAW,IAAW,EAAc,CAe9D,IAAK,GAAM,MAAM,EAAE,mBAAmB,EAAmB,GAAG,EAAE,QAAQ,CAAC,KAAK;EAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoD/F,CC3HD,SAAwB,EAAW,EAA0C,CAC3E,IAAM,EAA4B,CAChC,KAAM,uBACN,QAAS,MACT,UAAU,EAAM,EAAI,CAElB,GADI,CAAC,EAAG,SAAS,OAAO,EACpB,CAAC,UAAU,KAAK,EAAK,EAAI,CAAC,cAAc,KAAK,EAAK,EAAI,CAAC,gBAAgB,KAAK,EAAK,CAAE,OAEvF,IAAM,GAAA,EAAA,EAAA,uBAAoC,EAAK,CAC3C,OAAgB,EAEpB,MAAO,CAAE,KAAM,EAAa,IAAK,KAAM,EAE1C,CAED,OAAA,EAAA,EAAA,sBACE,CAAE,GAAG,EAAS,UAAW,MAAO,CAChC,CAAC,EAAkB,CACnB,EACD"}
@@ -0,0 +1,5 @@
1
+ import { Plugin } from 'vite';
2
+ import { FluentiPluginOptions } from '@fluenti/vite-plugin';
3
+ export type { FluentiPluginOptions as FluentiVueOptions } from '@fluenti/vite-plugin';
4
+ export default function fluentiVue(options?: FluentiPluginOptions): Plugin[];
5
+ //# sourceMappingURL=vite-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAKhE,YAAY,EAAE,oBAAoB,IAAI,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAErF,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,EAAE,CAoB3E"}
@@ -0,0 +1,146 @@
1
+ import { createFluentiPlugins as e } from "@fluenti/vite-plugin";
2
+ import { transformVtDirectives as t } from "@fluenti/vite-plugin/sfc-transform";
3
+ import { resolve as n } from "node:path";
4
+ //#region src/vue-runtime.ts
5
+ var r = {
6
+ generateRuntime(e) {
7
+ let { catalogDir: t, locales: r, sourceLocale: i, defaultBuildLocale: a } = e, o = a || i, s = n(process.cwd(), t);
8
+ return `
9
+ import { shallowReactive, ref } from 'vue'
10
+ import __defaultMsgs from '${s}/${o}.js'
11
+
12
+ const __catalog = shallowReactive({ ...__defaultMsgs })
13
+ const __currentLocale = ref('${o}')
14
+ const __loadedLocales = new Set(['${o}'])
15
+ const __loading = ref(false)
16
+ const __cache = new Map()
17
+ const __normalizeMessages = (mod) => mod.default ?? mod
18
+
19
+ const __loaders = {
20
+ ${r.filter((e) => e !== o).map((e) => ` '${e}': () => import('${s}/${e}.js'),`).join("\n")}
21
+ }
22
+
23
+ async function __switchLocale(locale) {
24
+ if (__loadedLocales.has(locale)) {
25
+ Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)
26
+ __currentLocale.value = locale
27
+ return
28
+ }
29
+ __loading.value = true
30
+ try {
31
+ const mod = __normalizeMessages(await __loaders[locale]())
32
+ __cache.set(locale, mod)
33
+ __loadedLocales.add(locale)
34
+ Object.assign(__catalog, mod)
35
+ __currentLocale.value = locale
36
+ } finally {
37
+ __loading.value = false
38
+ }
39
+ }
40
+
41
+ async function __preloadLocale(locale) {
42
+ if (__loadedLocales.has(locale) || !__loaders[locale]) return
43
+ try {
44
+ const mod = __normalizeMessages(await __loaders[locale]())
45
+ __cache.set(locale, mod)
46
+ __loadedLocales.add(locale)
47
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
48
+ }
49
+
50
+ globalThis[Symbol.for('fluenti.runtime.vue')] = { __switchLocale, __preloadLocale }
51
+
52
+ export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
53
+ `;
54
+ },
55
+ generateRouteRuntime(e) {
56
+ let { catalogDir: t, locales: r, sourceLocale: i, defaultBuildLocale: a } = e, o = a || i, s = n(process.cwd(), t);
57
+ return `
58
+ import { shallowReactive, ref } from 'vue'
59
+ import __defaultMsgs from '${s}/${o}.js'
60
+
61
+ const __catalog = shallowReactive({ ...__defaultMsgs })
62
+ const __currentLocale = ref('${o}')
63
+ const __loadedLocales = new Set(['${o}'])
64
+ const __loading = ref(false)
65
+ const __cache = new Map()
66
+ const __loadedRoutes = new Set()
67
+ const __normalizeMessages = (mod) => mod.default ?? mod
68
+
69
+ const __loaders = {
70
+ ${r.filter((e) => e !== o).map((e) => ` '${e}': () => import('${s}/${e}.js'),`).join("\n")}
71
+ }
72
+
73
+ const __routeLoaders = {}
74
+
75
+ function __registerRouteLoader(routeId, locale, loader) {
76
+ const key = routeId + ':' + locale
77
+ __routeLoaders[key] = loader
78
+ }
79
+
80
+ async function __loadRoute(routeId, locale) {
81
+ const key = routeId + ':' + (locale || __currentLocale.value)
82
+ if (__loadedRoutes.has(key)) return
83
+ const loader = __routeLoaders[key]
84
+ if (!loader) return
85
+ const mod = __normalizeMessages(await loader())
86
+ Object.assign(__catalog, mod)
87
+ __loadedRoutes.add(key)
88
+ }
89
+
90
+ async function __switchLocale(locale) {
91
+ if (locale === __currentLocale.value) return
92
+ __loading.value = true
93
+ try {
94
+ if (__cache.has(locale)) {
95
+ Object.assign(__catalog, __cache.get(locale))
96
+ } else {
97
+ const mod = __normalizeMessages(await __loaders[locale]())
98
+ __cache.set(locale, mod)
99
+ Object.assign(__catalog, mod)
100
+ }
101
+ __loadedLocales.add(locale)
102
+ __currentLocale.value = locale
103
+ } finally {
104
+ __loading.value = false
105
+ }
106
+ }
107
+
108
+ async function __preloadLocale(locale) {
109
+ if (__cache.has(locale) || !__loaders[locale]) return
110
+ try {
111
+ const mod = __normalizeMessages(await __loaders[locale]())
112
+ __cache.set(locale, mod)
113
+ __loadedLocales.add(locale)
114
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
115
+ }
116
+
117
+ globalThis[Symbol.for('fluenti.runtime.vue')] = { __switchLocale, __preloadLocale }
118
+
119
+ export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
120
+ `;
121
+ }
122
+ };
123
+ //#endregion
124
+ //#region src/vite-plugin.ts
125
+ function i(n) {
126
+ let i = {
127
+ name: "fluenti:vue-template",
128
+ enforce: "pre",
129
+ transform(e, n) {
130
+ if (!n.endsWith(".vue") || !/\bv-t\b/.test(e) && !/<Trans[\s>]/.test(e) && !/<Plural[\s/>]/.test(e)) return;
131
+ let r = t(e);
132
+ if (r !== e) return {
133
+ code: r,
134
+ map: null
135
+ };
136
+ }
137
+ };
138
+ return e({
139
+ ...n,
140
+ framework: "vue"
141
+ }, [i], r);
142
+ }
143
+ //#endregion
144
+ export { i as default };
145
+
146
+ //# sourceMappingURL=vite-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.js","names":[],"sources":["../src/vue-runtime.ts","../src/vite-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path'\nimport type { RuntimeGenerator, RuntimeGeneratorOptions } from '@fluenti/vite-plugin'\n\nexport const vueRuntimeGenerator: RuntimeGenerator = {\n generateRuntime(options: RuntimeGeneratorOptions): string {\n const { catalogDir, locales, sourceLocale, defaultBuildLocale } = options\n const defaultLocale = defaultBuildLocale || sourceLocale\n const absoluteCatalogDir = resolve(process.cwd(), catalogDir)\n const runtimeKey = 'fluenti.runtime.vue'\n const lazyLocales = locales.filter((locale) => locale !== defaultLocale)\n\n return `\nimport { shallowReactive, ref } from 'vue'\nimport __defaultMsgs from '${absoluteCatalogDir}/${defaultLocale}.js'\n\nconst __catalog = shallowReactive({ ...__defaultMsgs })\nconst __currentLocale = ref('${defaultLocale}')\nconst __loadedLocales = new Set(['${defaultLocale}'])\nconst __loading = ref(false)\nconst __cache = new Map()\nconst __normalizeMessages = (mod) => mod.default ?? mod\n\nconst __loaders = {\n${lazyLocales.map((l) => ` '${l}': () => import('${absoluteCatalogDir}/${l}.js'),`).join('\\n')}\n}\n\nasync function __switchLocale(locale) {\n if (__loadedLocales.has(locale)) {\n Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)\n __currentLocale.value = locale\n return\n }\n __loading.value = true\n try {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n __loadedLocales.add(locale)\n Object.assign(__catalog, mod)\n __currentLocale.value = locale\n } finally {\n __loading.value = false\n }\n}\n\nasync function __preloadLocale(locale) {\n if (__loadedLocales.has(locale) || !__loaders[locale]) return\n try {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n __loadedLocales.add(locale)\n } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }\n}\n\nglobalThis[Symbol.for('${runtimeKey}')] = { __switchLocale, __preloadLocale }\n\nexport { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }\n`\n },\n\n generateRouteRuntime(options: RuntimeGeneratorOptions): string {\n const { catalogDir, locales, sourceLocale, defaultBuildLocale } = options\n const defaultLocale = defaultBuildLocale || sourceLocale\n const absoluteCatalogDir = resolve(process.cwd(), catalogDir)\n const runtimeKey = 'fluenti.runtime.vue'\n const lazyLocales = locales.filter((locale) => locale !== defaultLocale)\n\n return `\nimport { shallowReactive, ref } from 'vue'\nimport __defaultMsgs from '${absoluteCatalogDir}/${defaultLocale}.js'\n\nconst __catalog = shallowReactive({ ...__defaultMsgs })\nconst __currentLocale = ref('${defaultLocale}')\nconst __loadedLocales = new Set(['${defaultLocale}'])\nconst __loading = ref(false)\nconst __cache = new Map()\nconst __loadedRoutes = new Set()\nconst __normalizeMessages = (mod) => mod.default ?? mod\n\nconst __loaders = {\n${lazyLocales.map((l) => ` '${l}': () => import('${absoluteCatalogDir}/${l}.js'),`).join('\\n')}\n}\n\nconst __routeLoaders = {}\n\nfunction __registerRouteLoader(routeId, locale, loader) {\n const key = routeId + ':' + locale\n __routeLoaders[key] = loader\n}\n\nasync function __loadRoute(routeId, locale) {\n const key = routeId + ':' + (locale || __currentLocale.value)\n if (__loadedRoutes.has(key)) return\n const loader = __routeLoaders[key]\n if (!loader) return\n const mod = __normalizeMessages(await loader())\n Object.assign(__catalog, mod)\n __loadedRoutes.add(key)\n}\n\nasync function __switchLocale(locale) {\n if (locale === __currentLocale.value) return\n __loading.value = true\n try {\n if (__cache.has(locale)) {\n Object.assign(__catalog, __cache.get(locale))\n } else {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n Object.assign(__catalog, mod)\n }\n __loadedLocales.add(locale)\n __currentLocale.value = locale\n } finally {\n __loading.value = false\n }\n}\n\nasync function __preloadLocale(locale) {\n if (__cache.has(locale) || !__loaders[locale]) return\n try {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n __loadedLocales.add(locale)\n } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }\n}\n\nglobalThis[Symbol.for('${runtimeKey}')] = { __switchLocale, __preloadLocale }\n\nexport { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }\n`\n },\n}\n","import type { Plugin } from 'vite'\nimport type { FluentiPluginOptions } from '@fluenti/vite-plugin'\nimport { createFluentiPlugins } from '@fluenti/vite-plugin'\nimport { transformVtDirectives } from '@fluenti/vite-plugin/sfc-transform'\nimport { vueRuntimeGenerator } from './vue-runtime'\n\nexport type { FluentiPluginOptions as FluentiVueOptions } from '@fluenti/vite-plugin'\n\nexport default function fluentiVue(options?: FluentiPluginOptions): Plugin[] {\n const vueTemplatePlugin: Plugin = {\n name: 'fluenti:vue-template',\n enforce: 'pre',\n transform(code, id) {\n if (!id.endsWith('.vue')) return undefined\n if (!/\\bv-t\\b/.test(code) && !/<Trans[\\s>]/.test(code) && !/<Plural[\\s/>]/.test(code)) return undefined\n\n const transformed = transformVtDirectives(code)\n if (transformed === code) return undefined\n\n return { code: transformed, map: null }\n },\n }\n\n return createFluentiPlugins(\n { ...options, framework: 'vue' },\n [vueTemplatePlugin],\n vueRuntimeGenerator,\n )\n}\n"],"mappings":";;;;AAGA,IAAa,IAAwC;CACnD,gBAAgB,GAA0C;EACxD,IAAM,EAAE,eAAY,YAAS,iBAAc,0BAAuB,GAC5D,IAAgB,KAAsB,GACtC,IAAqB,EAAQ,QAAQ,KAAK,EAAE,EAAW;AAI7D,SAAO;;6BAEkB,EAAmB,GAAG,EAAc;;;+BAGlC,EAAc;oCACT,EAAc;;;;;;EAR1B,EAAQ,QAAQ,MAAW,MAAW,EAAc,CAc9D,KAAK,MAAM,MAAM,EAAE,mBAAmB,EAAmB,GAAG,EAAE,QAAQ,CAAC,KAAK,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoC9F,qBAAqB,GAA0C;EAC7D,IAAM,EAAE,eAAY,YAAS,iBAAc,0BAAuB,GAC5D,IAAgB,KAAsB,GACtC,IAAqB,EAAQ,QAAQ,KAAK,EAAE,EAAW;AAI7D,SAAO;;6BAEkB,EAAmB,GAAG,EAAc;;;+BAGlC,EAAc;oCACT,EAAc;;;;;;;EAR1B,EAAQ,QAAQ,MAAW,MAAW,EAAc,CAe9D,KAAK,MAAM,MAAM,EAAE,mBAAmB,EAAmB,GAAG,EAAE,QAAQ,CAAC,KAAK,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoD/F;;;AC3HD,SAAwB,EAAW,GAA0C;CAC3E,IAAM,IAA4B;EAChC,MAAM;EACN,SAAS;EACT,UAAU,GAAM,GAAI;AAElB,OADI,CAAC,EAAG,SAAS,OAAO,IACpB,CAAC,UAAU,KAAK,EAAK,IAAI,CAAC,cAAc,KAAK,EAAK,IAAI,CAAC,gBAAgB,KAAK,EAAK,CAAE;GAEvF,IAAM,IAAc,EAAsB,EAAK;AAC3C,aAAgB,EAEpB,QAAO;IAAE,MAAM;IAAa,KAAK;IAAM;;EAE1C;AAED,QAAO,EACL;EAAE,GAAG;EAAS,WAAW;EAAO,EAChC,CAAC,EAAkB,EACnB,EACD"}
@@ -0,0 +1,3 @@
1
+ import { RuntimeGenerator } from '@fluenti/vite-plugin';
2
+ export declare const vueRuntimeGenerator: RuntimeGenerator;
3
+ //# sourceMappingURL=vue-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue-runtime.d.ts","sourceRoot":"","sources":["../src/vue-runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAA2B,MAAM,sBAAsB,CAAA;AAErF,eAAO,MAAM,mBAAmB,EAAE,gBAgIjC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluenti/vue",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "Vue 3 compile-time i18n — v-t directive, Trans/Plural/Select components, useI18n composable",
6
6
  "homepage": "https://fluenti.dev",
@@ -40,16 +40,33 @@
40
40
  "types": "./dist/index.d.ts",
41
41
  "default": "./dist/index.cjs"
42
42
  }
43
+ },
44
+ "./vite-plugin": {
45
+ "import": {
46
+ "types": "./dist/vite-plugin.d.ts",
47
+ "default": "./dist/vite-plugin.js"
48
+ },
49
+ "require": {
50
+ "types": "./dist/vite-plugin.d.ts",
51
+ "default": "./dist/vite-plugin.cjs"
52
+ }
43
53
  }
44
54
  },
45
55
  "files": [
46
56
  "dist"
47
57
  ],
48
58
  "peerDependencies": {
49
- "vue": "^3.5"
59
+ "vue": "^3.5",
60
+ "vite": "^5 || ^6 || ^8"
61
+ },
62
+ "peerDependenciesMeta": {
63
+ "vite": {
64
+ "optional": true
65
+ }
50
66
  },
51
67
  "dependencies": {
52
- "@fluenti/core": "0.1.3"
68
+ "@fluenti/core": "0.2.1",
69
+ "@fluenti/vite-plugin": "0.2.1"
53
70
  },
54
71
  "devDependencies": {
55
72
  "typescript": "^5.9",