@fluenti/solid 0.1.3 → 0.2.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.
package/README.md CHANGED
@@ -23,7 +23,7 @@ Fluenti compiles your messages at build time and pairs them with Solid's fine-gr
23
23
 
24
24
  ```bash
25
25
  pnpm add @fluenti/core @fluenti/solid
26
- pnpm add -D @fluenti/cli @fluenti/vite-plugin
26
+ pnpm add -D @fluenti/cli
27
27
  ```
28
28
 
29
29
  ### 2. Configure Vite
@@ -31,10 +31,10 @@ pnpm add -D @fluenti/cli @fluenti/vite-plugin
31
31
  ```ts
32
32
  // vite.config.ts
33
33
  import solidPlugin from 'vite-plugin-solid'
34
- import fluenti from '@fluenti/vite-plugin'
34
+ import fluentiSolid from '@fluenti/solid/vite-plugin'
35
35
 
36
36
  export default {
37
- plugins: [solidPlugin(), fluenti({ framework: 'solid' })],
37
+ plugins: [solidPlugin(), fluentiSolid()],
38
38
  }
39
39
  ```
40
40
 
@@ -0,0 +1,3 @@
1
+ import { RuntimeGenerator } from '@fluenti/vite-plugin';
2
+ export declare const solidRuntimeGenerator: RuntimeGenerator;
3
+ //# sourceMappingURL=solid-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solid-runtime.d.ts","sourceRoot":"","sources":["../src/solid-runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAA2B,MAAM,sBAAsB,CAAA;AAErF,eAAO,MAAM,qBAAqB,EAAE,gBAkInC,CAAA"}
@@ -0,0 +1,114 @@
1
+ let e=require(`@fluenti/vite-plugin`),t=require(`node:path`);var n={generateRuntime(e){let{catalogDir:n,locales:r,sourceLocale:i,defaultBuildLocale:a}=e,o=a||i,s=(0,t.resolve)(process.cwd(),n);return`
2
+ import { createSignal } from 'solid-js'
3
+ import { createStore, reconcile } from 'solid-js/store'
4
+ import __defaultMsgs from '${s}/${o}.js'
5
+
6
+ const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
7
+ const [__currentLocale, __setCurrentLocale] = createSignal('${o}')
8
+ const __loadedLocales = new Set(['${o}'])
9
+ const [__loading, __setLoading] = createSignal(false)
10
+ const __cache = new Map()
11
+ const __normalizeMessages = (mod) => mod.default ?? mod
12
+
13
+ const __loaders = {
14
+ ${r.filter(e=>e!==o).map(e=>` '${e}': () => import('${s}/${e}.js'),`).join(`
15
+ `)}
16
+ }
17
+
18
+ async function __switchLocale(locale) {
19
+ if (__loadedLocales.has(locale)) {
20
+ __setCatalog(reconcile(__cache.get(locale) || __defaultMsgs))
21
+ __setCurrentLocale(locale)
22
+ return
23
+ }
24
+ __setLoading(true)
25
+ try {
26
+ const mod = __normalizeMessages(await __loaders[locale]())
27
+ __cache.set(locale, mod)
28
+ __loadedLocales.add(locale)
29
+ __setCatalog(reconcile(mod))
30
+ __setCurrentLocale(locale)
31
+ } finally {
32
+ __setLoading(false)
33
+ }
34
+ }
35
+
36
+ async function __preloadLocale(locale) {
37
+ if (__loadedLocales.has(locale) || !__loaders[locale]) return
38
+ try {
39
+ const mod = __normalizeMessages(await __loaders[locale]())
40
+ __cache.set(locale, mod)
41
+ __loadedLocales.add(locale)
42
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
43
+ }
44
+
45
+ globalThis[Symbol.for('fluenti.runtime.solid')] = { __switchLocale, __preloadLocale }
46
+
47
+ export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
48
+ `},generateRouteRuntime(e){let{catalogDir:n,locales:r,sourceLocale:i,defaultBuildLocale:a}=e,o=a||i,s=(0,t.resolve)(process.cwd(),n);return`
49
+ import { createSignal } from 'solid-js'
50
+ import { createStore, reconcile } from 'solid-js/store'
51
+ import __defaultMsgs from '${s}/${o}.js'
52
+
53
+ const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
54
+ const [__currentLocale, __setCurrentLocale] = createSignal('${o}')
55
+ const __loadedLocales = new Set(['${o}'])
56
+ const [__loading, __setLoading] = createSignal(false)
57
+ const __cache = new Map()
58
+ const __loadedRoutes = new Set()
59
+ const __normalizeMessages = (mod) => mod.default ?? mod
60
+
61
+ const __loaders = {
62
+ ${r.filter(e=>e!==o).map(e=>` '${e}': () => import('${s}/${e}.js'),`).join(`
63
+ `)}
64
+ }
65
+
66
+ const __routeLoaders = {}
67
+
68
+ function __registerRouteLoader(routeId, locale, loader) {
69
+ const key = routeId + ':' + locale
70
+ __routeLoaders[key] = loader
71
+ }
72
+
73
+ async function __loadRoute(routeId, locale) {
74
+ const key = routeId + ':' + (locale || __currentLocale())
75
+ if (__loadedRoutes.has(key)) return
76
+ const loader = __routeLoaders[key]
77
+ if (!loader) return
78
+ const mod = __normalizeMessages(await loader())
79
+ __setCatalog(reconcile({ ...__catalog, ...mod }))
80
+ __loadedRoutes.add(key)
81
+ }
82
+
83
+ async function __switchLocale(locale) {
84
+ if (locale === __currentLocale()) return
85
+ __setLoading(true)
86
+ try {
87
+ if (__cache.has(locale)) {
88
+ __setCatalog(reconcile(__cache.get(locale)))
89
+ } else {
90
+ const mod = __normalizeMessages(await __loaders[locale]())
91
+ __cache.set(locale, mod)
92
+ __setCatalog(reconcile(mod))
93
+ }
94
+ __loadedLocales.add(locale)
95
+ __setCurrentLocale(locale)
96
+ } finally {
97
+ __setLoading(false)
98
+ }
99
+ }
100
+
101
+ async function __preloadLocale(locale) {
102
+ if (__cache.has(locale) || !__loaders[locale]) return
103
+ try {
104
+ const mod = __normalizeMessages(await __loaders[locale]())
105
+ __cache.set(locale, mod)
106
+ __loadedLocales.add(locale)
107
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
108
+ }
109
+
110
+ globalThis[Symbol.for('fluenti.runtime.solid')] = { __switchLocale, __preloadLocale }
111
+
112
+ export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
113
+ `}};function r(t){return(0,e.createFluentiPlugins)({...t,framework:`solid`},[],n)}module.exports=r;
114
+ //# sourceMappingURL=vite-plugin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.cjs","names":[],"sources":["../src/solid-runtime.ts","../src/vite-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path'\nimport type { RuntimeGenerator, RuntimeGeneratorOptions } from '@fluenti/vite-plugin'\n\nexport const solidRuntimeGenerator: 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.solid'\n const lazyLocales = locales.filter((locale) => locale !== defaultLocale)\n\n return `\nimport { createSignal } from 'solid-js'\nimport { createStore, reconcile } from 'solid-js/store'\nimport __defaultMsgs from '${absoluteCatalogDir}/${defaultLocale}.js'\n\nconst [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })\nconst [__currentLocale, __setCurrentLocale] = createSignal('${defaultLocale}')\nconst __loadedLocales = new Set(['${defaultLocale}'])\nconst [__loading, __setLoading] = createSignal(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 __setCatalog(reconcile(__cache.get(locale) || __defaultMsgs))\n __setCurrentLocale(locale)\n return\n }\n __setLoading(true)\n try {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n __loadedLocales.add(locale)\n __setCatalog(reconcile(mod))\n __setCurrentLocale(locale)\n } finally {\n __setLoading(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.solid'\n const lazyLocales = locales.filter((locale) => locale !== defaultLocale)\n\n return `\nimport { createSignal } from 'solid-js'\nimport { createStore, reconcile } from 'solid-js/store'\nimport __defaultMsgs from '${absoluteCatalogDir}/${defaultLocale}.js'\n\nconst [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })\nconst [__currentLocale, __setCurrentLocale] = createSignal('${defaultLocale}')\nconst __loadedLocales = new Set(['${defaultLocale}'])\nconst [__loading, __setLoading] = createSignal(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())\n if (__loadedRoutes.has(key)) return\n const loader = __routeLoaders[key]\n if (!loader) return\n const mod = __normalizeMessages(await loader())\n __setCatalog(reconcile({ ...__catalog, ...mod }))\n __loadedRoutes.add(key)\n}\n\nasync function __switchLocale(locale) {\n if (locale === __currentLocale()) return\n __setLoading(true)\n try {\n if (__cache.has(locale)) {\n __setCatalog(reconcile(__cache.get(locale)))\n } else {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n __setCatalog(reconcile(mod))\n }\n __loadedLocales.add(locale)\n __setCurrentLocale(locale)\n } finally {\n __setLoading(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 { solidRuntimeGenerator } from './solid-runtime'\n\nexport type { FluentiPluginOptions as FluentiSolidOptions } from '@fluenti/vite-plugin'\n\nexport default function fluentiSolid(options?: FluentiPluginOptions): Plugin[] {\n return createFluentiPlugins(\n { ...options, framework: 'solid' },\n [],\n solidRuntimeGenerator,\n )\n}\n"],"mappings":"6DAGA,IAAa,EAA0C,CACrD,gBAAgB,EAA0C,CACxD,GAAM,CAAE,aAAY,UAAS,eAAc,sBAAuB,EAC5D,EAAgB,GAAsB,EACtC,GAAA,EAAA,EAAA,SAA6B,QAAQ,KAAK,CAAE,EAAW,CAI7D,MAAO;;;6BAGkB,EAAmB,GAAG,EAAc;;;8DAGH,EAAc;oCACxC,EAAc;;;;;;EAT1B,EAAQ,OAAQ,GAAW,IAAW,EAAc,CAe9D,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;;;6BAGkB,EAAmB,GAAG,EAAc;;;8DAGH,EAAc;oCACxC,EAAc;;;;;;;EAT1B,EAAQ,OAAQ,GAAW,IAAW,EAAc,CAgB9D,IAAK,GAAM,MAAM,EAAE,mBAAmB,EAAmB,GAAG,EAAE,QAAQ,CAAC,KAAK;EAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoD/F,CC9HD,SAAwB,EAAa,EAA0C,CAC7E,OAAA,EAAA,EAAA,sBACE,CAAE,GAAG,EAAS,UAAW,QAAS,CAClC,EAAE,CACF,EACD"}
@@ -0,0 +1,5 @@
1
+ import { Plugin } from 'vite';
2
+ import { FluentiPluginOptions } from '@fluenti/vite-plugin';
3
+ export type { FluentiPluginOptions as FluentiSolidOptions } from '@fluenti/vite-plugin';
4
+ export default function fluentiSolid(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;AAIhE,YAAY,EAAE,oBAAoB,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAEvF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,EAAE,CAM7E"}
@@ -0,0 +1,135 @@
1
+ import { createFluentiPlugins as e } from "@fluenti/vite-plugin";
2
+ import { resolve as t } from "node:path";
3
+ //#region src/solid-runtime.ts
4
+ var n = {
5
+ generateRuntime(e) {
6
+ let { catalogDir: n, locales: r, sourceLocale: i, defaultBuildLocale: a } = e, o = a || i, s = t(process.cwd(), n);
7
+ return `
8
+ import { createSignal } from 'solid-js'
9
+ import { createStore, reconcile } from 'solid-js/store'
10
+ import __defaultMsgs from '${s}/${o}.js'
11
+
12
+ const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
13
+ const [__currentLocale, __setCurrentLocale] = createSignal('${o}')
14
+ const __loadedLocales = new Set(['${o}'])
15
+ const [__loading, __setLoading] = createSignal(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
+ __setCatalog(reconcile(__cache.get(locale) || __defaultMsgs))
26
+ __setCurrentLocale(locale)
27
+ return
28
+ }
29
+ __setLoading(true)
30
+ try {
31
+ const mod = __normalizeMessages(await __loaders[locale]())
32
+ __cache.set(locale, mod)
33
+ __loadedLocales.add(locale)
34
+ __setCatalog(reconcile(mod))
35
+ __setCurrentLocale(locale)
36
+ } finally {
37
+ __setLoading(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.solid')] = { __switchLocale, __preloadLocale }
51
+
52
+ export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
53
+ `;
54
+ },
55
+ generateRouteRuntime(e) {
56
+ let { catalogDir: n, locales: r, sourceLocale: i, defaultBuildLocale: a } = e, o = a || i, s = t(process.cwd(), n);
57
+ return `
58
+ import { createSignal } from 'solid-js'
59
+ import { createStore, reconcile } from 'solid-js/store'
60
+ import __defaultMsgs from '${s}/${o}.js'
61
+
62
+ const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
63
+ const [__currentLocale, __setCurrentLocale] = createSignal('${o}')
64
+ const __loadedLocales = new Set(['${o}'])
65
+ const [__loading, __setLoading] = createSignal(false)
66
+ const __cache = new Map()
67
+ const __loadedRoutes = new Set()
68
+ const __normalizeMessages = (mod) => mod.default ?? mod
69
+
70
+ const __loaders = {
71
+ ${r.filter((e) => e !== o).map((e) => ` '${e}': () => import('${s}/${e}.js'),`).join("\n")}
72
+ }
73
+
74
+ const __routeLoaders = {}
75
+
76
+ function __registerRouteLoader(routeId, locale, loader) {
77
+ const key = routeId + ':' + locale
78
+ __routeLoaders[key] = loader
79
+ }
80
+
81
+ async function __loadRoute(routeId, locale) {
82
+ const key = routeId + ':' + (locale || __currentLocale())
83
+ if (__loadedRoutes.has(key)) return
84
+ const loader = __routeLoaders[key]
85
+ if (!loader) return
86
+ const mod = __normalizeMessages(await loader())
87
+ __setCatalog(reconcile({ ...__catalog, ...mod }))
88
+ __loadedRoutes.add(key)
89
+ }
90
+
91
+ async function __switchLocale(locale) {
92
+ if (locale === __currentLocale()) return
93
+ __setLoading(true)
94
+ try {
95
+ if (__cache.has(locale)) {
96
+ __setCatalog(reconcile(__cache.get(locale)))
97
+ } else {
98
+ const mod = __normalizeMessages(await __loaders[locale]())
99
+ __cache.set(locale, mod)
100
+ __setCatalog(reconcile(mod))
101
+ }
102
+ __loadedLocales.add(locale)
103
+ __setCurrentLocale(locale)
104
+ } finally {
105
+ __setLoading(false)
106
+ }
107
+ }
108
+
109
+ async function __preloadLocale(locale) {
110
+ if (__cache.has(locale) || !__loaders[locale]) return
111
+ try {
112
+ const mod = __normalizeMessages(await __loaders[locale]())
113
+ __cache.set(locale, mod)
114
+ __loadedLocales.add(locale)
115
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
116
+ }
117
+
118
+ globalThis[Symbol.for('fluenti.runtime.solid')] = { __switchLocale, __preloadLocale }
119
+
120
+ export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
121
+ `;
122
+ }
123
+ };
124
+ //#endregion
125
+ //#region src/vite-plugin.ts
126
+ function r(t) {
127
+ return e({
128
+ ...t,
129
+ framework: "solid"
130
+ }, [], n);
131
+ }
132
+ //#endregion
133
+ export { r as default };
134
+
135
+ //# sourceMappingURL=vite-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.js","names":[],"sources":["../src/solid-runtime.ts","../src/vite-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path'\nimport type { RuntimeGenerator, RuntimeGeneratorOptions } from '@fluenti/vite-plugin'\n\nexport const solidRuntimeGenerator: 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.solid'\n const lazyLocales = locales.filter((locale) => locale !== defaultLocale)\n\n return `\nimport { createSignal } from 'solid-js'\nimport { createStore, reconcile } from 'solid-js/store'\nimport __defaultMsgs from '${absoluteCatalogDir}/${defaultLocale}.js'\n\nconst [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })\nconst [__currentLocale, __setCurrentLocale] = createSignal('${defaultLocale}')\nconst __loadedLocales = new Set(['${defaultLocale}'])\nconst [__loading, __setLoading] = createSignal(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 __setCatalog(reconcile(__cache.get(locale) || __defaultMsgs))\n __setCurrentLocale(locale)\n return\n }\n __setLoading(true)\n try {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n __loadedLocales.add(locale)\n __setCatalog(reconcile(mod))\n __setCurrentLocale(locale)\n } finally {\n __setLoading(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.solid'\n const lazyLocales = locales.filter((locale) => locale !== defaultLocale)\n\n return `\nimport { createSignal } from 'solid-js'\nimport { createStore, reconcile } from 'solid-js/store'\nimport __defaultMsgs from '${absoluteCatalogDir}/${defaultLocale}.js'\n\nconst [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })\nconst [__currentLocale, __setCurrentLocale] = createSignal('${defaultLocale}')\nconst __loadedLocales = new Set(['${defaultLocale}'])\nconst [__loading, __setLoading] = createSignal(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())\n if (__loadedRoutes.has(key)) return\n const loader = __routeLoaders[key]\n if (!loader) return\n const mod = __normalizeMessages(await loader())\n __setCatalog(reconcile({ ...__catalog, ...mod }))\n __loadedRoutes.add(key)\n}\n\nasync function __switchLocale(locale) {\n if (locale === __currentLocale()) return\n __setLoading(true)\n try {\n if (__cache.has(locale)) {\n __setCatalog(reconcile(__cache.get(locale)))\n } else {\n const mod = __normalizeMessages(await __loaders[locale]())\n __cache.set(locale, mod)\n __setCatalog(reconcile(mod))\n }\n __loadedLocales.add(locale)\n __setCurrentLocale(locale)\n } finally {\n __setLoading(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 { solidRuntimeGenerator } from './solid-runtime'\n\nexport type { FluentiPluginOptions as FluentiSolidOptions } from '@fluenti/vite-plugin'\n\nexport default function fluentiSolid(options?: FluentiPluginOptions): Plugin[] {\n return createFluentiPlugins(\n { ...options, framework: 'solid' },\n [],\n solidRuntimeGenerator,\n )\n}\n"],"mappings":";;;AAGA,IAAa,IAA0C;CACrD,gBAAgB,GAA0C;EACxD,IAAM,EAAE,eAAY,YAAS,iBAAc,0BAAuB,GAC5D,IAAgB,KAAsB,GACtC,IAAqB,EAAQ,QAAQ,KAAK,EAAE,EAAW;AAI7D,SAAO;;;6BAGkB,EAAmB,GAAG,EAAc;;;8DAGH,EAAc;oCACxC,EAAc;;;;;;EAT1B,EAAQ,QAAQ,MAAW,MAAW,EAAc,CAe9D,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;;;6BAGkB,EAAmB,GAAG,EAAc;;;8DAGH,EAAc;oCACxC,EAAc;;;;;;;EAT1B,EAAQ,QAAQ,MAAW,MAAW,EAAc,CAgB9D,KAAK,MAAM,MAAM,EAAE,mBAAmB,EAAmB,GAAG,EAAE,QAAQ,CAAC,KAAK,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoD/F;;;AC9HD,SAAwB,EAAa,GAA0C;AAC7E,QAAO,EACL;EAAE,GAAG;EAAS,WAAW;EAAS,EAClC,EAAE,EACF,EACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluenti/solid",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "SolidJS compile-time i18n — Trans/Plural/Select components, I18nProvider, useI18n",
6
6
  "homepage": "https://fluenti.dev",
@@ -43,6 +43,16 @@
43
43
  "types": "./dist/index.d.ts",
44
44
  "default": "./dist/index.cjs"
45
45
  }
46
+ },
47
+ "./vite-plugin": {
48
+ "import": {
49
+ "types": "./dist/vite-plugin.d.ts",
50
+ "default": "./dist/vite-plugin.js"
51
+ },
52
+ "require": {
53
+ "types": "./dist/vite-plugin.d.ts",
54
+ "default": "./dist/vite-plugin.cjs"
55
+ }
46
56
  }
47
57
  },
48
58
  "files": [
@@ -50,10 +60,17 @@
50
60
  "src"
51
61
  ],
52
62
  "peerDependencies": {
53
- "solid-js": "^1.8"
63
+ "solid-js": "^1.8",
64
+ "vite": "^5 || ^6 || ^8"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "vite": {
68
+ "optional": true
69
+ }
54
70
  },
55
71
  "dependencies": {
56
- "@fluenti/core": "0.1.3"
72
+ "@fluenti/core": "0.2.0",
73
+ "@fluenti/vite-plugin": "0.2.0"
57
74
  },
58
75
  "devDependencies": {
59
76
  "@solidjs/testing-library": "^0.8",
@@ -0,0 +1,134 @@
1
+ import { resolve } from 'node:path'
2
+ import type { RuntimeGenerator, RuntimeGeneratorOptions } from '@fluenti/vite-plugin'
3
+
4
+ export const solidRuntimeGenerator: RuntimeGenerator = {
5
+ generateRuntime(options: RuntimeGeneratorOptions): string {
6
+ const { catalogDir, locales, sourceLocale, defaultBuildLocale } = options
7
+ const defaultLocale = defaultBuildLocale || sourceLocale
8
+ const absoluteCatalogDir = resolve(process.cwd(), catalogDir)
9
+ const runtimeKey = 'fluenti.runtime.solid'
10
+ const lazyLocales = locales.filter((locale) => locale !== defaultLocale)
11
+
12
+ return `
13
+ import { createSignal } from 'solid-js'
14
+ import { createStore, reconcile } from 'solid-js/store'
15
+ import __defaultMsgs from '${absoluteCatalogDir}/${defaultLocale}.js'
16
+
17
+ const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
18
+ const [__currentLocale, __setCurrentLocale] = createSignal('${defaultLocale}')
19
+ const __loadedLocales = new Set(['${defaultLocale}'])
20
+ const [__loading, __setLoading] = createSignal(false)
21
+ const __cache = new Map()
22
+ const __normalizeMessages = (mod) => mod.default ?? mod
23
+
24
+ const __loaders = {
25
+ ${lazyLocales.map((l) => ` '${l}': () => import('${absoluteCatalogDir}/${l}.js'),`).join('\n')}
26
+ }
27
+
28
+ async function __switchLocale(locale) {
29
+ if (__loadedLocales.has(locale)) {
30
+ __setCatalog(reconcile(__cache.get(locale) || __defaultMsgs))
31
+ __setCurrentLocale(locale)
32
+ return
33
+ }
34
+ __setLoading(true)
35
+ try {
36
+ const mod = __normalizeMessages(await __loaders[locale]())
37
+ __cache.set(locale, mod)
38
+ __loadedLocales.add(locale)
39
+ __setCatalog(reconcile(mod))
40
+ __setCurrentLocale(locale)
41
+ } finally {
42
+ __setLoading(false)
43
+ }
44
+ }
45
+
46
+ async function __preloadLocale(locale) {
47
+ if (__loadedLocales.has(locale) || !__loaders[locale]) return
48
+ try {
49
+ const mod = __normalizeMessages(await __loaders[locale]())
50
+ __cache.set(locale, mod)
51
+ __loadedLocales.add(locale)
52
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
53
+ }
54
+
55
+ globalThis[Symbol.for('${runtimeKey}')] = { __switchLocale, __preloadLocale }
56
+
57
+ export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
58
+ `
59
+ },
60
+
61
+ generateRouteRuntime(options: RuntimeGeneratorOptions): string {
62
+ const { catalogDir, locales, sourceLocale, defaultBuildLocale } = options
63
+ const defaultLocale = defaultBuildLocale || sourceLocale
64
+ const absoluteCatalogDir = resolve(process.cwd(), catalogDir)
65
+ const runtimeKey = 'fluenti.runtime.solid'
66
+ const lazyLocales = locales.filter((locale) => locale !== defaultLocale)
67
+
68
+ return `
69
+ import { createSignal } from 'solid-js'
70
+ import { createStore, reconcile } from 'solid-js/store'
71
+ import __defaultMsgs from '${absoluteCatalogDir}/${defaultLocale}.js'
72
+
73
+ const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
74
+ const [__currentLocale, __setCurrentLocale] = createSignal('${defaultLocale}')
75
+ const __loadedLocales = new Set(['${defaultLocale}'])
76
+ const [__loading, __setLoading] = createSignal(false)
77
+ const __cache = new Map()
78
+ const __loadedRoutes = new Set()
79
+ const __normalizeMessages = (mod) => mod.default ?? mod
80
+
81
+ const __loaders = {
82
+ ${lazyLocales.map((l) => ` '${l}': () => import('${absoluteCatalogDir}/${l}.js'),`).join('\n')}
83
+ }
84
+
85
+ const __routeLoaders = {}
86
+
87
+ function __registerRouteLoader(routeId, locale, loader) {
88
+ const key = routeId + ':' + locale
89
+ __routeLoaders[key] = loader
90
+ }
91
+
92
+ async function __loadRoute(routeId, locale) {
93
+ const key = routeId + ':' + (locale || __currentLocale())
94
+ if (__loadedRoutes.has(key)) return
95
+ const loader = __routeLoaders[key]
96
+ if (!loader) return
97
+ const mod = __normalizeMessages(await loader())
98
+ __setCatalog(reconcile({ ...__catalog, ...mod }))
99
+ __loadedRoutes.add(key)
100
+ }
101
+
102
+ async function __switchLocale(locale) {
103
+ if (locale === __currentLocale()) return
104
+ __setLoading(true)
105
+ try {
106
+ if (__cache.has(locale)) {
107
+ __setCatalog(reconcile(__cache.get(locale)))
108
+ } else {
109
+ const mod = __normalizeMessages(await __loaders[locale]())
110
+ __cache.set(locale, mod)
111
+ __setCatalog(reconcile(mod))
112
+ }
113
+ __loadedLocales.add(locale)
114
+ __setCurrentLocale(locale)
115
+ } finally {
116
+ __setLoading(false)
117
+ }
118
+ }
119
+
120
+ async function __preloadLocale(locale) {
121
+ if (__cache.has(locale) || !__loaders[locale]) return
122
+ try {
123
+ const mod = __normalizeMessages(await __loaders[locale]())
124
+ __cache.set(locale, mod)
125
+ __loadedLocales.add(locale)
126
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
127
+ }
128
+
129
+ globalThis[Symbol.for('${runtimeKey}')] = { __switchLocale, __preloadLocale }
130
+
131
+ export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
132
+ `
133
+ },
134
+ }
@@ -0,0 +1,14 @@
1
+ import type { Plugin } from 'vite'
2
+ import type { FluentiPluginOptions } from '@fluenti/vite-plugin'
3
+ import { createFluentiPlugins } from '@fluenti/vite-plugin'
4
+ import { solidRuntimeGenerator } from './solid-runtime'
5
+
6
+ export type { FluentiPluginOptions as FluentiSolidOptions } from '@fluenti/vite-plugin'
7
+
8
+ export default function fluentiSolid(options?: FluentiPluginOptions): Plugin[] {
9
+ return createFluentiPlugins(
10
+ { ...options, framework: 'solid' },
11
+ [],
12
+ solidRuntimeGenerator,
13
+ )
14
+ }