@fluenti/vite-plugin 0.1.2 → 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.
Files changed (67) hide show
  1. package/README.md +51 -117
  2. package/dist/build-transform.d.ts.map +1 -0
  3. package/dist/dev-runner.d.ts +28 -0
  4. package/dist/dev-runner.d.ts.map +1 -0
  5. package/dist/index.cjs +10 -10
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +11 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +371 -491
  10. package/dist/index.js.map +1 -1
  11. package/dist/mode-detect.d.ts.map +1 -0
  12. package/dist/route-resolve.d.ts.map +1 -0
  13. package/dist/scope-transform.d.ts.map +1 -0
  14. package/dist/sfc-transform.cjs +2 -0
  15. package/dist/sfc-transform.cjs.map +1 -0
  16. package/dist/sfc-transform.d.ts.map +1 -0
  17. package/dist/sfc-transform.js +195 -0
  18. package/dist/sfc-transform.js.map +1 -0
  19. package/dist/trans-transform.d.ts.map +1 -0
  20. package/dist/types.d.ts +55 -0
  21. package/dist/types.d.ts.map +1 -0
  22. package/dist/virtual-modules.d.ts +16 -0
  23. package/dist/virtual-modules.d.ts.map +1 -0
  24. package/dist/vt-transform.d.ts.map +1 -0
  25. package/package.json +12 -2
  26. package/dist/src/build-transform.d.ts.map +0 -1
  27. package/dist/src/framework-detect.d.ts +0 -2
  28. package/dist/src/framework-detect.d.ts.map +0 -1
  29. package/dist/src/index.d.ts +0 -6
  30. package/dist/src/index.d.ts.map +0 -1
  31. package/dist/src/mode-detect.d.ts.map +0 -1
  32. package/dist/src/route-resolve.d.ts.map +0 -1
  33. package/dist/src/scope-transform.d.ts.map +0 -1
  34. package/dist/src/sfc-transform.d.ts.map +0 -1
  35. package/dist/src/solid-jsx-transform.d.ts +0 -6
  36. package/dist/src/solid-jsx-transform.d.ts.map +0 -1
  37. package/dist/src/trans-transform.d.ts.map +0 -1
  38. package/dist/src/types.d.ts +0 -15
  39. package/dist/src/types.d.ts.map +0 -1
  40. package/dist/src/virtual-modules.d.ts +0 -33
  41. package/dist/src/virtual-modules.d.ts.map +0 -1
  42. package/dist/src/vt-transform.d.ts.map +0 -1
  43. package/dist/tests/build-transform.test.d.ts +0 -2
  44. package/dist/tests/build-transform.test.d.ts.map +0 -1
  45. package/dist/tests/mode-detect.test.d.ts +0 -2
  46. package/dist/tests/mode-detect.test.d.ts.map +0 -1
  47. package/dist/tests/per-route-splitting.test.d.ts +0 -2
  48. package/dist/tests/per-route-splitting.test.d.ts.map +0 -1
  49. package/dist/tests/route-resolve.test.d.ts +0 -2
  50. package/dist/tests/route-resolve.test.d.ts.map +0 -1
  51. package/dist/tests/scope-transform.test.d.ts +0 -2
  52. package/dist/tests/scope-transform.test.d.ts.map +0 -1
  53. package/dist/tests/trans-transform.test.d.ts +0 -2
  54. package/dist/tests/trans-transform.test.d.ts.map +0 -1
  55. package/dist/tests/virtual-modules.test.d.ts +0 -2
  56. package/dist/tests/virtual-modules.test.d.ts.map +0 -1
  57. package/dist/tests/vite-plugin.test.d.ts +0 -2
  58. package/dist/tests/vite-plugin.test.d.ts.map +0 -1
  59. package/dist/vite.config.d.ts +0 -3
  60. package/dist/vite.config.d.ts.map +0 -1
  61. /package/dist/{src/build-transform.d.ts → build-transform.d.ts} +0 -0
  62. /package/dist/{src/mode-detect.d.ts → mode-detect.d.ts} +0 -0
  63. /package/dist/{src/route-resolve.d.ts → route-resolve.d.ts} +0 -0
  64. /package/dist/{src/scope-transform.d.ts → scope-transform.d.ts} +0 -0
  65. /package/dist/{src/sfc-transform.d.ts → sfc-transform.d.ts} +0 -0
  66. /package/dist/{src/trans-transform.d.ts → trans-transform.d.ts} +0 -0
  67. /package/dist/{src/vt-transform.d.ts → vt-transform.d.ts} +0 -0
package/README.md CHANGED
@@ -4,119 +4,74 @@
4
4
  [![bundle size](https://img.shields.io/bundlephobia/minzip/@fluenti/vite-plugin?color=16a34a&label=size)](https://bundlephobia.com/package/@fluenti/vite-plugin)
5
5
  [![license](https://img.shields.io/npm/l/@fluenti/vite-plugin?color=737373)](https://github.com/usefluenti/fluenti/blob/main/LICENSE)
6
6
 
7
- **The build-time engine behind Fluenti.** This plugin compiles away i18n at build time so your production bundle ships zero runtime interpretation overhead. It uses internal virtual modules to wire locale chunks automatically, so app code can stay on Fluenti's public authoring and runtime APIs.
7
+ **The build-time engine behind Fluenti.** This is an internal package that provides the core Vite plugin infrastructure. Users should install the framework-specific packages instead.
8
8
 
9
- ## How It Works
9
+ ## Usage
10
10
 
11
- Traditional i18n libraries parse and evaluate message strings at runtime. Fluenti takes a different approach: **everything happens at build time**.
11
+ This package is not meant to be used directly. Install your framework package instead:
12
12
 
13
- During Vite's transform pipeline, `@fluenti/vite-plugin` rewrites your i18n patterns directly in the AST:
14
-
15
- - **`v-t` directive** is a Vue compiler `nodeTransform`, not a runtime directive. It rewrites `<h1 v-t>Hello</h1>` into `<h1>{{ $t('abc123') }}</h1>` during template compilation.
16
- - **`<Trans>`, `<Plural>`, `<Select>` components** are compiled into optimized render calls -- no component overhead at runtime.
17
- - **Direct-import `t`** -- `import { t } from '@fluenti/react' | '@fluenti/vue' | '@fluenti/solid'` is the primary compile-time path
18
-
19
- The result: your users get fully resolved translations with the same performance as hardcoded strings.
20
-
21
- ## Quick Start
13
+ ```bash
14
+ # Vue
15
+ pnpm add @fluenti/vue
22
16
 
23
- ### 1. Install
17
+ # React
18
+ pnpm add @fluenti/react
24
19
 
25
- ```bash
26
- pnpm add @fluenti/vite-plugin
20
+ # Solid
21
+ pnpm add @fluenti/solid
27
22
  ```
28
23
 
29
- ### 2. Configure
24
+ Then import the Vite plugin from the framework package's subpath export:
30
25
 
31
26
  ```ts
32
- // vite.config.ts
33
- import fluenti from '@fluenti/vite-plugin'
27
+ // Vue — vite.config.ts
28
+ import vue from '@vitejs/plugin-vue'
29
+ import fluentiVue from '@fluenti/vue/vite-plugin'
34
30
 
35
31
  export default {
36
32
  plugins: [
37
- fluenti({
38
- framework: 'vue', // 'vue' | 'react' | 'solid' | 'auto'
33
+ vue(),
34
+ fluentiVue({
39
35
  sourceLocale: 'en',
40
36
  locales: ['en', 'ja', 'zh-CN'],
41
- splitting: 'dynamic', // 'dynamic' | 'static' | false
37
+ splitting: 'dynamic',
42
38
  }),
43
39
  ],
44
40
  }
45
41
  ```
46
42
 
47
- That's it. The plugin auto-detects your framework when set to `'auto'`, manages locale chunks internally, and handles HMR during development.
48
-
49
- ## Features
50
-
51
- ### Internal virtual modules
52
-
53
- The plugin uses Vite virtual modules under the hood to connect transformed message lookups to the compiled locale catalogs. Those modules are internal implementation details; application code should stay on `import { t }`, `useI18n()`, `setLocale()`, `preloadLocale()`, `loadMessages()`, and framework-level `chunkLoader` APIs.
54
-
55
- ### Code Splitting
56
-
57
- Control how message catalogs are bundled with the `splitting` option:
58
-
59
- | Strategy | Behavior | Best For |
60
- |----------|----------|----------|
61
- | `'dynamic'` | Default locale loaded statically; others lazy-loaded on `switchLocale()` (default) | SPAs with multiple locales |
62
- | `'static'` | All messages for a single locale inlined at build time | SSR, static site generation |
63
- | `false` | All messages bundled in a single chunk | Small apps, simple setups |
64
-
65
- ### Vue Template Transform
66
-
67
- The `v-t` directive is compiled away during Vue template compilation via a `nodeTransform` injected into `@vitejs/plugin-vue`:
68
-
69
- ```vue
70
- <!-- What you write -->
71
- <p v-t>Welcome back</p>
72
- <img v-t.alt alt="Profile photo" />
73
- <span v-t.plural="count">one apple | {count} apples</span>
43
+ ```ts
44
+ // React — vite.config.ts
45
+ import react from '@vitejs/plugin-react'
46
+ import fluentiReact from '@fluenti/react/vite-plugin'
74
47
 
75
- <!-- What ships to the browser -->
76
- <p>{{ $t('a1b2c3') }}</p>
77
- <img :alt="$t('d4e5f6')" />
78
- <span>{{ $t('g7h8i9', { count }) }}</span>
48
+ export default {
49
+ plugins: [
50
+ fluentiReact({ splitting: 'dynamic' }),
51
+ react(),
52
+ ],
53
+ }
79
54
  ```
80
55
 
81
- Rich text with nested elements is supported through `$vtRich()`, and `<Trans>`, `<Plural>`, `<Select>` components are all compiled into optimized output.
82
-
83
- ### Client-Side `t` Transform
84
-
85
- The plugin uses **AST scope analysis** to detect Fluenti's direct-import `t` inside supported component/setup scopes and rewrites it to the runtime `useI18n()` binding:
86
-
87
- ```tsx
88
- // What you write
89
- import { t } from '@fluenti/react'
90
- const msg = t`Hello, ${name}`
56
+ ```ts
57
+ // Solid — vite.config.ts
58
+ import solidPlugin from 'vite-plugin-solid'
59
+ import fluentiSolid from '@fluenti/solid/vite-plugin'
91
60
 
92
- // What ships to the browser
93
- const { t } = useI18n()
94
- const msg = t('Hello, {name}', { name })
61
+ export default {
62
+ plugins: [
63
+ solidPlugin(),
64
+ fluentiSolid({ splitting: 'dynamic' }),
65
+ ],
66
+ }
95
67
  ```
96
68
 
97
- Supported direct-import shapes:
98
-
99
- - `` t`Hello, ${name}` ``
100
- - `t({ message: 'Hello {name}', context: 'hero' }, { name })`
101
-
102
- Unsupported direct-import shapes are compile-time errors:
103
-
104
- - `t('message.id')`
105
- - `t('Hello {name}', { name })`
106
- - module-top-level usage outside supported component/setup scopes
107
-
108
- ### HMR for Catalogs
69
+ ## Plugin Options
109
70
 
110
- During development, editing a message catalog triggers instant hot module replacement. The plugin watches your `catalogDir` and invalidates the relevant virtual modules so translations update in the browser without a full page reload.
111
-
112
- ## Configuration
71
+ All framework plugins accept the same options:
113
72
 
114
73
  ```ts
115
74
  interface FluentiPluginOptions {
116
- /** Framework mode — set to 'auto' to detect from source code.
117
- * @default 'auto' */
118
- framework?: 'vue' | 'react' | 'solid' | 'auto'
119
-
120
75
  /** Directory containing compiled message catalogs.
121
76
  * @default 'src/locales/compiled' */
122
77
  catalogDir?: string
@@ -130,51 +85,30 @@ interface FluentiPluginOptions {
130
85
  locales?: string[]
131
86
 
132
87
  /** Code splitting strategy.
133
- * @default 'dynamic' */
88
+ * @default false */
134
89
  splitting?: 'dynamic' | 'static' | false
135
90
 
136
91
  /** Locale used for static build-time inlining.
137
92
  * @default sourceLocale */
138
93
  defaultBuildLocale?: string
139
-
140
94
  }
141
95
  ```
142
96
 
143
- ### Examples
97
+ ## What It Provides
144
98
 
145
- **Vue with dynamic splitting:**
99
+ For framework package authors, this package exports:
146
100
 
147
- ```ts
148
- import vue from '@vitejs/plugin-vue'
149
- import fluenti from '@fluenti/vite-plugin'
101
+ - `createFluentiPlugins(options, frameworkPlugins, runtimeGenerator)` — factory function to build the Vite plugin pipeline
102
+ - `FluentiPluginOptions` user-facing options type
103
+ - `RuntimeGenerator` / `RuntimeGeneratorOptions` — interface for framework-specific virtual module runtime generation
150
104
 
151
- export default {
152
- plugins: [
153
- vue(),
154
- fluenti({
155
- framework: 'vue',
156
- sourceLocale: 'en',
157
- locales: ['en', 'ja', 'zh-CN'],
158
- splitting: 'dynamic',
159
- }),
160
- ],
161
- }
162
- ```
163
-
164
- **SSR with static inlining:**
105
+ ## Code Splitting
165
106
 
166
- ```ts
167
- import fluenti from '@fluenti/vite-plugin'
168
-
169
- export default {
170
- plugins: [
171
- fluenti({
172
- splitting: 'static',
173
- defaultBuildLocale: 'en',
174
- }),
175
- ],
176
- }
177
- ```
107
+ | Strategy | Behavior | Best For |
108
+ |----------|----------|----------|
109
+ | `'dynamic'` | Default locale loaded statically; others lazy-loaded on `switchLocale()` | SPAs with multiple locales |
110
+ | `'static'` | All messages for a single locale inlined at build time | SSR, static site generation |
111
+ | `false` | All messages bundled in a single chunk | Small apps, simple setups |
178
112
 
179
113
  ## Peer Dependencies
180
114
 
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-transform.d.ts","sourceRoot":"","sources":["../src/build-transform.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAA;IACZ,kBAAkB,EAAE,OAAO,CAAA;IAC3B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACxB;AAmID,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAE3E;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAE1E;AA8aD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAY3H"}
@@ -0,0 +1,28 @@
1
+ export interface DevRunnerOptions {
2
+ cwd: string;
3
+ onSuccess?: () => void;
4
+ onError?: (err: Error) => void;
5
+ /** If true, reject the promise on failure instead of swallowing the error */
6
+ throwOnError?: boolean;
7
+ /** Run only compile (skip extract). Useful for production builds where source is unchanged. */
8
+ compileOnly?: boolean;
9
+ }
10
+ /**
11
+ * Walk up from `cwd` to find `node_modules/.bin/fluenti`.
12
+ * Returns the absolute path or null if not found.
13
+ */
14
+ export declare function resolveCliBin(cwd: string): string | null;
15
+ /**
16
+ * Run compile in-process via `@fluenti/cli` (for compileOnly mode),
17
+ * or fall back to shell-out for extract + compile (dev mode).
18
+ */
19
+ export declare function runExtractCompile(options: DevRunnerOptions): Promise<void>;
20
+ /**
21
+ * Create a debounced runner that collapses rapid calls.
22
+ *
23
+ * - If called while idle, schedules a run after `delay` ms.
24
+ * - If called while a run is in progress, marks a pending rerun.
25
+ * - Never runs concurrently.
26
+ */
27
+ export declare function createDebouncedRunner(options: DevRunnerOptions, delay?: number): () => void;
28
+ //# sourceMappingURL=dev-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-runner.d.ts","sourceRoot":"","sources":["../src/dev-runner.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAA;IAC9B,6EAA6E;IAC7E,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,+FAA+F;IAC/F,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUxD;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuDhF;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EACzB,KAAK,SAAM,GACV,MAAM,IAAI,CAiCZ"}
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- let e=require(`node:path`),t=require(`@fluenti/core`),n=require(`@fluenti/core/internal`),r=require(`node:fs`);var i=`dev`;function a(e){i=e===`build`?`build`:`dev`}function o(e){return e?.mode===`build`||i===`build`||process.env.NODE_ENV===`production`}function s(e){return l(e,`dynamic`)}function c(e){return l(e,`static`)}function l(e,t){let r=(0,n.parseSourceModule)(e);if(!r||r.type!==`Program`)return{code:e,needsCatalogImport:!1,usedHashes:new Set};let i=u(r),a=[],o=new Set;if((0,n.walkSourceAst)(r,n=>{let r=f(e,n,i,t,o);if(r){a.push(r);return}h(n,o)}),a.length===0)return{code:e,needsCatalogImport:!1,usedHashes:o};let s=e;for(let e=a.length-1;e>=0;e--){let{start:t,end:n,replacement:r}=a[e];s=s.slice(0,t)+r+s.slice(n)}return{code:s,needsCatalogImport:!0,usedHashes:o}}function u(e){let t=new Set,r=new Set,i=new Set,a=new Set;for(let t of e.body)if(w(t))for(let e of t.specifiers){if(!T(e))continue;let t=P(e);t&&(t===`useI18n`&&r.add(e.local.name),t===`getI18n`&&i.add(e.local.name),t===`unref`&&a.add(e.local.name))}return(0,n.walkSourceAst)(e,e=>{if(!E(e)||!e.init||!D(e.id))return;if(A(e.init)&&j(e.init.callee)&&r.has(e.init.callee.name)){d(e.id,t);return}let n=e.init.type===`AwaitExpression`?e.init.argument:null;n&&A(n)&&j(n.callee)&&i.has(n.callee.name)&&d(e.id,t)}),{tracked:t,unref:a}}function d(e,t){for(let n of e.properties)!k(n)||n.computed||!j(n.key)||n.key.name!==`t`||j(n.value)&&t.add(n.value.name)}function f(e,n,r,i,a){if(!A(n)||n.start==null||n.end==null)return;let o=p(e,n,r);if(!o)return;let{catalogId:s}=o;a.add(s);let c=(0,t.hashMessage)(s),l=i===`dynamic`?`__catalog[${JSON.stringify(s)}]`:`_${c}`,u=o.valuesSource?`${l}(${o.valuesSource})`:l;return{start:n.start,end:n.end,replacement:u}}function p(e,t,n){if(t.arguments.length===0)return;let r=t.callee,i=j(r)&&(n.tracked.has(r.name)||r.name===`$t`),a=ie(r)&&!r.computed&&j(r.property)&&(r.property.name===`$t`||r.property.name===`t`&&j(r.object)&&(r.object.name===`_ctx`||r.object.name===`$setup`)),o=A(r)&&j(r.callee)&&n.unref.has(r.callee.name)&&r.arguments.length===1&&j(r.arguments[0])&&n.tracked.has(r.arguments[0].name);if(!i&&!a&&!o)return;let s=m(t.arguments[0]);if(!s)return;let c=t.arguments[1]&&t.arguments[1].start!=null&&t.arguments[1].end!=null?e.slice(t.arguments[1].start,t.arguments[1].end):void 0;return c===void 0?{catalogId:s}:{catalogId:s,valuesSource:c}}function m(e){let n=S(e);if(n!==void 0)return(0,t.hashMessage)(n);if(!O(e))return;let r,i,a;for(let t of e.properties){if(!k(t)||t.computed)continue;let e=C(t.key);if(!e)continue;let n=S(t.value);n!==void 0&&(e===`id`&&(r=n),e===`message`&&(i=n),e===`context`&&(a=n))}if(r)return r;if(i)return(0,t.hashMessage)(i,a)}function h(e,n){if(!M(e))return;let r=re(e.openingElement.name);if(r){if(r===`Trans`){let r=v(e.openingElement,`__id`)??v(e.openingElement,`id`);if(r){n.add(r);return}let i=v(e.openingElement,`__message`),a=v(e.openingElement,`context`);i&&n.add((0,t.hashMessage)(i,a));return}if(r===`Plural`){let t=g(e.openingElement);t&&n.add(t);return}if(r===`Select`){let t=_(e.openingElement);t&&n.add(t)}}}function g(e){let n=v(e,`id`);if(n)return n;let r=v(e,`context`),i=y(e,`offset`),a=[v(e,`zero`)===void 0?void 0:`=0 {${v(e,`zero`)}}`,v(e,`one`)===void 0?void 0:`one {${v(e,`one`)}}`,v(e,`two`)===void 0?void 0:`two {${v(e,`two`)}}`,v(e,`few`)===void 0?void 0:`few {${v(e,`few`)}}`,v(e,`many`)===void 0?void 0:`many {${v(e,`many`)}}`,v(e,`other`)===void 0?void 0:`other {${v(e,`other`)}}`].filter(Boolean);if(a.length!==0)return(0,t.hashMessage)(`{count, plural,${typeof i==`number`?` offset:${i}`:``} ${a.join(` `)}}`,r)}function _(e){let n=v(e,`id`);if(n)return n;let r=v(e,`context`),i=ee(e);if(!(!i||i.other===void 0))return(0,t.hashMessage)(`{value, select, ${[...Object.keys(i).filter(e=>e!==`other`).sort(),`other`].map(e=>`${e} {${i[e]}}`).join(` `)}}`,r)}function ee(e){let t=ne(e,`options`);if(t){let n=v(e,`other`);return{...t,...n===void 0?{}:{other:n}}}let n={};for(let t of e.attributes){if(!N(t))continue;let e=t.name.name;if([`value`,`id`,`context`,`comment`,`options`].includes(e))continue;let r=x(t);r!==void 0&&(n[e]=r)}return Object.keys(n).length>0?n:void 0}function te(e){if(!O(e))return;let t={};for(let n of e.properties){if(!k(n)||n.computed)return;let e=C(n.key),r=S(n.value);if(!e||r===void 0)return;t[e]=r}return t}function ne(e,t){let n=b(e,t);if(n?.value&&n.value.type===`JSXExpressionContainer`)return te(n.value.expression)}function v(e,t){return x(b(e,t))}function y(e,t){let n=b(e,t);if(!n?.value||n.value.type!==`JSXExpressionContainer`)return;let r=n.value.expression;return r.type===`NumericLiteral`?r.value:void 0}function b(e,t){return e.attributes.find(e=>N(e)&&e.name.name===t)}function x(e){if(e?.value){if(e.value.type===`StringLiteral`)return e.value.value;if(e.value.type===`JSXExpressionContainer`)return S(e.value.expression)}}function re(e){return e.type===`JSXIdentifier`?e.name:void 0}function S(e){if(e.type===`StringLiteral`)return e.value;if(e.type===`TemplateLiteral`){let t=e;if(t.expressions.length===0&&t.quasis.length===1)return t.quasis[0].value.cooked??t.quasis[0].value.raw}}function C(e){if(j(e))return e.name;if(e.type===`StringLiteral`)return e.value}function w(e){return e.type===`ImportDeclaration`}function T(e){return e.type===`ImportSpecifier`}function E(e){return e.type===`VariableDeclarator`}function D(e){return e.type===`ObjectPattern`}function O(e){return e.type===`ObjectExpression`}function k(e){return e.type===`ObjectProperty`}function A(e){return e.type===`CallExpression`}function ie(e){return e.type===`MemberExpression`}function j(e){return e?.type===`Identifier`}function M(e){return e.type===`JSXElement`}function N(e){return e.type===`JSXAttribute`}function P(e){let t=e.imported;if(t.type===`Identifier`)return t.name;if(t.type===`StringLiteral`)return t.value}function F(e,n,r){return n===`dynamic`?`import { __catalog } from 'virtual:fluenti/runtime';\n${e}`:n===`per-route`?`import { __catalog } from 'virtual:fluenti/route-runtime';\n${e}`:`import { ${[...r].map(e=>`_${(0,t.hashMessage)(e)}`).join(`, `)} } from 'virtual:fluenti/messages';\n${e}`}var I=`virtual:fluenti/runtime`,L=`virtual:fluenti/messages`,R=`virtual:fluenti/route-runtime`,z=`\0virtual:fluenti/runtime`,B=`\0virtual:fluenti/messages`,V=`\0virtual:fluenti/route-runtime`;function H(e){if(e===I)return z;if(e===L)return B;if(e===R)return V}function U(e,t){if(e===z)return W(t);if(e===B)return G(t);if(e===V)return K(t)}function W(t){let{catalogDir:n,locales:r,sourceLocale:i,defaultBuildLocale:a,framework:o}=t,s=a||i,c=(0,e.resolve)(process.cwd(),n),l=`fluenti.runtime.${o}`,u=r.filter(e=>e!==s);return o===`react`?`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`node:path`),t=require(`node:child_process`),n=require(`node:fs`),r=require(`node:module`),i=require(`@fluenti/core`),a=require(`@fluenti/core/internal`);var o=`dev`;function s(e){o=e===`build`?`build`:`dev`}function c(e){return e?.mode===`build`||o===`build`||process.env.NODE_ENV===`production`}function l(t){let r=t;for(;;){let t=(0,e.resolve)(r,`node_modules/.bin/fluenti`);if((0,n.existsSync)(t))return t;let i=(0,e.dirname)(r);if(i===r)break;r=i}return null}async function u(n){if(n.compileOnly)try{let{runCompile:t}=(0,r.createRequire)((0,e.join)(n.cwd,`package.json`))(`@fluenti/cli`);await t(n.cwd),console.log(`[fluenti] Compiling... done`),n.onSuccess?.();return}catch(e){let t=e instanceof Error?e:Error(String(e));if(n.throwOnError)throw t;console.warn(`[fluenti] Compile failed:`,t.message),n.onError?.(t);return}let i=l(n.cwd);if(!i){let e=`[fluenti] CLI not found — skipping auto-compile. Install @fluenti/cli as a devDependency.`;return n.throwOnError?Promise.reject(Error(e)):(console.warn(e),Promise.resolve())}let a=`${i} extract && ${i} compile`;return new Promise((e,r)=>{(0,t.exec)(a,{cwd:n.cwd},(t,i,a)=>{if(t){let e=Error(a||t.message);if(n.throwOnError){r(e);return}console.warn(`[fluenti] Extract/compile failed:`,e.message),n.onError?.(e)}else console.log(`[fluenti] Extracting and compiling... done`),n.onSuccess?.();e()})})}function ee(e,t=300){let n=null,r=!1,i=!1;async function a(){r=!0;try{await u(e)}finally{r=!1,i&&(i=!1,o())}}function o(){n!==null&&clearTimeout(n),n=setTimeout(()=>{n=null,r?i=!0:a()},t)}return o}function d(e){return p(e,`dynamic`)}function f(e){return p(e,`static`)}function p(e,t){let n=(0,a.parseSourceModule)(e);if(!n||n.type!==`Program`)return{code:e,needsCatalogImport:!1,usedHashes:new Set};let r=m(n),i=[],o=new Set;if((0,a.walkSourceAst)(n,n=>{let a=g(e,n,r,t,o);if(a){i.push(a);return}y(n,o)}),i.length===0)return{code:e,needsCatalogImport:!1,usedHashes:o};let s=e;for(let e=i.length-1;e>=0;e--){let{start:t,end:n,replacement:r}=i[e];s=s.slice(0,t)+r+s.slice(n)}return{code:s,needsCatalogImport:!0,usedHashes:o}}function m(e){let t=new Set,n=new Set,r=new Set,i=new Set;for(let t of e.body)if(j(t))for(let e of t.specifiers){if(!M(e))continue;let t=V(e);t&&(t===`useI18n`&&n.add(e.local.name),t===`getI18n`&&r.add(e.local.name),t===`unref`&&i.add(e.local.name))}return(0,a.walkSourceAst)(e,e=>{if(!N(e)||!e.init||!P(e.id))return;if(L(e.init)&&R(e.init.callee)&&n.has(e.init.callee.name)){h(e.id,t);return}let i=e.init.type===`AwaitExpression`?e.init.argument:null;i&&L(i)&&R(i.callee)&&r.has(i.callee.name)&&h(e.id,t)}),{tracked:t,unref:i}}function h(e,t){for(let n of e.properties)!I(n)||n.computed||!R(n.key)||n.key.name!==`t`||R(n.value)&&t.add(n.value.name)}function g(e,t,n,r,a){if(!L(t)||t.start==null||t.end==null)return;let o=_(e,t,n);if(!o)return;let{catalogId:s}=o;a.add(s);let c=(0,i.hashMessage)(s),l=r===`dynamic`?`__catalog[${JSON.stringify(s)}]`:`_${c}`,u=o.valuesSource?`${l}(${o.valuesSource})`:l;return{start:t.start,end:t.end,replacement:u}}function _(e,t,n){if(t.arguments.length===0)return;let r=t.callee,i=R(r)&&(n.tracked.has(r.name)||r.name===`$t`),a=ne(r)&&!r.computed&&R(r.property)&&(r.property.name===`$t`||r.property.name===`t`&&R(r.object)&&(r.object.name===`_ctx`||r.object.name===`$setup`)),o=L(r)&&R(r.callee)&&n.unref.has(r.callee.name)&&r.arguments.length===1&&R(r.arguments[0])&&n.tracked.has(r.arguments[0].name);if(!i&&!a&&!o)return;let s=v(t.arguments[0]);if(!s)return;let c=t.arguments[1]&&t.arguments[1].start!=null&&t.arguments[1].end!=null?e.slice(t.arguments[1].start,t.arguments[1].end):void 0;return c===void 0?{catalogId:s}:{catalogId:s,valuesSource:c}}function v(e){let t=k(e);if(t!==void 0)return(0,i.hashMessage)(t);if(!F(e))return;let n,r,a;for(let t of e.properties){if(!I(t)||t.computed)continue;let e=A(t.key);if(!e)continue;let i=k(t.value);i!==void 0&&(e===`id`&&(n=i),e===`message`&&(r=i),e===`context`&&(a=i))}if(n)return n;if(r)return(0,i.hashMessage)(r,a)}function y(e,t){if(!z(e))return;let n=te(e.openingElement.name);if(n){if(n===`Trans`){let n=T(e.openingElement,`__id`)??T(e.openingElement,`id`);if(n){t.add(n);return}let r=T(e.openingElement,`__message`),a=T(e.openingElement,`context`);r&&t.add((0,i.hashMessage)(r,a));return}if(n===`Plural`){let n=b(e.openingElement);n&&t.add(n);return}if(n===`Select`){let n=x(e.openingElement);n&&t.add(n)}}}function b(e){let t=T(e,`id`);if(t)return t;let n=T(e,`context`),r=E(e,`offset`),a=[T(e,`zero`)===void 0?void 0:`=0 {${T(e,`zero`)}}`,T(e,`one`)===void 0?void 0:`one {${T(e,`one`)}}`,T(e,`two`)===void 0?void 0:`two {${T(e,`two`)}}`,T(e,`few`)===void 0?void 0:`few {${T(e,`few`)}}`,T(e,`many`)===void 0?void 0:`many {${T(e,`many`)}}`,T(e,`other`)===void 0?void 0:`other {${T(e,`other`)}}`].filter(Boolean);if(a.length!==0)return(0,i.hashMessage)(`{count, plural,${typeof r==`number`?` offset:${r}`:``} ${a.join(` `)}}`,n)}function x(e){let t=T(e,`id`);if(t)return t;let n=T(e,`context`),r=S(e);if(!(!r||r.other===void 0))return(0,i.hashMessage)(`{value, select, ${[...Object.keys(r).filter(e=>e!==`other`).sort(),`other`].map(e=>`${e} {${r[e]}}`).join(` `)}}`,n)}function S(e){let t=w(e,`options`);if(t){let n=T(e,`other`);return{...t,...n===void 0?{}:{other:n}}}let n={};for(let t of e.attributes){if(!B(t))continue;let e=t.name.name;if([`value`,`id`,`context`,`comment`,`options`].includes(e))continue;let r=O(t);r!==void 0&&(n[e]=r)}return Object.keys(n).length>0?n:void 0}function C(e){if(!F(e))return;let t={};for(let n of e.properties){if(!I(n)||n.computed)return;let e=A(n.key),r=k(n.value);if(!e||r===void 0)return;t[e]=r}return t}function w(e,t){let n=D(e,t);if(n?.value&&n.value.type===`JSXExpressionContainer`)return C(n.value.expression)}function T(e,t){return O(D(e,t))}function E(e,t){let n=D(e,t);if(!n?.value||n.value.type!==`JSXExpressionContainer`)return;let r=n.value.expression;return r.type===`NumericLiteral`?r.value:void 0}function D(e,t){return e.attributes.find(e=>B(e)&&e.name.name===t)}function O(e){if(e?.value){if(e.value.type===`StringLiteral`)return e.value.value;if(e.value.type===`JSXExpressionContainer`)return k(e.value.expression)}}function te(e){return e.type===`JSXIdentifier`?e.name:void 0}function k(e){if(e.type===`StringLiteral`)return e.value;if(e.type===`TemplateLiteral`){let t=e;if(t.expressions.length===0&&t.quasis.length===1)return t.quasis[0].value.cooked??t.quasis[0].value.raw}}function A(e){if(R(e))return e.name;if(e.type===`StringLiteral`)return e.value}function j(e){return e.type===`ImportDeclaration`}function M(e){return e.type===`ImportSpecifier`}function N(e){return e.type===`VariableDeclarator`}function P(e){return e.type===`ObjectPattern`}function F(e){return e.type===`ObjectExpression`}function I(e){return e.type===`ObjectProperty`}function L(e){return e.type===`CallExpression`}function ne(e){return e.type===`MemberExpression`}function R(e){return e?.type===`Identifier`}function z(e){return e.type===`JSXElement`}function B(e){return e.type===`JSXAttribute`}function V(e){let t=e.imported;if(t.type===`Identifier`)return t.name;if(t.type===`StringLiteral`)return t.value}function H(e,t,n){return t===`dynamic`?`import { __catalog } from 'virtual:fluenti/runtime';\n${e}`:t===`per-route`?`import { __catalog } from 'virtual:fluenti/route-runtime';\n${e}`:`import { ${[...n].map(e=>`_${(0,i.hashMessage)(e)}`).join(`, `)} } from 'virtual:fluenti/messages';\n${e}`}var U=`virtual:fluenti/runtime`,W=`virtual:fluenti/messages`,G=`virtual:fluenti/route-runtime`,K=`\0virtual:fluenti/runtime`,q=`\0virtual:fluenti/messages`,J=`\0virtual:fluenti/route-runtime`;function Y(e){if(e===U)return K;if(e===W)return q;if(e===G)return J}function X(e,t){if(e===K)return re(t);if(e===q)return ie(t);if(e===J)return ae(t)}function re(e){let{locales:t,runtimeGenerator:n}=e;for(let e of t)(0,i.validateLocale)(e,`vite-plugin`);return n?n.generateRuntime(Z(e)):oe(e)}function ie(t){let{catalogDir:n,defaultBuildLocale:r,sourceLocale:i}=t,a=r||i;return`export * from '${(0,e.resolve)(process.cwd(),n)}/${a}.js'\n`}function ae(e){let{locales:t,runtimeGenerator:n}=e;for(let e of t)(0,i.validateLocale)(e,`vite-plugin`);return n?n.generateRouteRuntime(Z(e)):se(e)}function Z(e){let{catalogDir:t,locales:n,sourceLocale:r,defaultBuildLocale:i}=e;return{catalogDir:t,locales:n,sourceLocale:r,defaultBuildLocale:i}}function oe(t){let{catalogDir:n,locales:r,sourceLocale:i,defaultBuildLocale:a,framework:o}=t,s=a||i,c=(0,e.resolve)(process.cwd(),n),l=`fluenti.runtime.${o}`,u=r.filter(e=>e!==s);return o===`react`?`
2
2
  import __defaultMsgs from '${c}/${s}.js'
3
3
 
4
4
  const __catalog = { ...__defaultMsgs }
@@ -37,7 +37,7 @@ async function __preloadLocale(locale) {
37
37
  const mod = __normalizeMessages(await __loaders[locale]())
38
38
  __cache.set(locale, mod)
39
39
  __loadedLocales.add(locale)
40
- } catch {}
40
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
41
41
  }
42
42
 
43
43
  globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
@@ -83,7 +83,7 @@ async function __preloadLocale(locale) {
83
83
  const mod = __normalizeMessages(await __loaders[locale]())
84
84
  __cache.set(locale, mod)
85
85
  __loadedLocales.add(locale)
86
- } catch {}
86
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
87
87
  }
88
88
 
89
89
  globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
@@ -130,13 +130,13 @@ async function __preloadLocale(locale) {
130
130
  const mod = __normalizeMessages(await __loaders[locale]())
131
131
  __cache.set(locale, mod)
132
132
  __loadedLocales.add(locale)
133
- } catch {}
133
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
134
134
  }
135
135
 
136
136
  globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
137
137
 
138
138
  export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
139
- `}function G(t){let{catalogDir:n,defaultBuildLocale:r,sourceLocale:i}=t,a=r||i;return`export * from '${(0,e.resolve)(process.cwd(),n)}/${a}.js'\n`}function K(t){let{catalogDir:n,locales:r,sourceLocale:i,defaultBuildLocale:a,framework:o}=t,s=a||i,c=(0,e.resolve)(process.cwd(),n),l=`fluenti.runtime.${o}`,u=r.filter(e=>e!==s);return o===`vue`?`
139
+ `}function se(t){let{catalogDir:n,locales:r,sourceLocale:i,defaultBuildLocale:a,framework:o}=t,s=a||i,c=(0,e.resolve)(process.cwd(),n),l=`fluenti.runtime.${o}`,u=r.filter(e=>e!==s);return o===`vue`?`
140
140
  import { shallowReactive, ref } from 'vue'
141
141
  import __defaultMsgs from '${c}/${s}.js'
142
142
 
@@ -194,7 +194,7 @@ async function __preloadLocale(locale) {
194
194
  const mod = __normalizeMessages(await __loaders[locale]())
195
195
  __cache.set(locale, mod)
196
196
  __loadedLocales.add(locale)
197
- } catch {}
197
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
198
198
  }
199
199
 
200
200
  globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
@@ -259,15 +259,15 @@ async function __preloadLocale(locale) {
259
259
  const mod = __normalizeMessages(await __loaders[locale]())
260
260
  __cache.set(locale, mod)
261
261
  __loadedLocales.add(locale)
262
- } catch {}
262
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
263
263
  }
264
264
 
265
265
  globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
266
266
 
267
267
  export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
268
- `}function q(e){let t=(e.includes(`/`)?e.slice(e.lastIndexOf(`/`)+1):e).replace(/\.[^.]+$/,``);return t.replace(/-[a-zA-Z0-9]{4,}$/,``)||t}function ae(e){let t=new Map,n=e.split(`
268
+ `}function ce(e){let t=(e.includes(`/`)?e.slice(e.lastIndexOf(`/`)+1):e).replace(/\.[^.]+$/,``);return t.replace(/-[a-zA-Z0-9]{4,}$/,``)||t}function le(e){let t=new Map,n=e.split(`
269
269
  `);for(let e=0;e<n.length;e++){let r=n[e],i=r.match(/^(?:\/\*.*?\*\/\s*)?export\s+const\s+_([a-z0-9]+)\s*=\s*/);if(!i)continue;let a=i[1],o=r,s=0,c=0,l=0;for(let e of r.slice(i[0].length))e===`{`&&s++,e===`}`&&s--,e===`(`&&c++,e===`)`&&c--,e==="`"&&(l=l===0?1:0);for(;(s>0||c>0||l>0)&&e+1<n.length;){e++;let t=n[e];o+=`
270
- `+t;for(let e of t)e===`{`&&s++,e===`}`&&s--,e===`(`&&c++,e===`)`&&c--,e==="`"&&(l=l===0?1:0)}t.set(a,o)}return t}function J(e,n){let r=[],i=[];for(let a of e){let e=(0,t.hashMessage)(a),o=n.get(e);o&&(r.push(o),i.push(` '${se(a)}': _${e},`))}return i.length>0&&r.push(``,`export default {`,...i,`}`),r.join(`
270
+ `+t;for(let e of t)e===`{`&&s++,e===`}`&&s--,e===`(`&&c++,e===`)`&&c--,e==="`"&&(l=l===0?1:0)}t.set(a,o)}return t}function Q(e,t){let n=[],r=[];for(let a of e){let e=(0,i.hashMessage)(a),o=t.get(e);o&&(n.push(o),r.push(` '${$(a)}': _${e},`))}return r.length>0&&n.push(``,`export default {`,...r,`}`),n.join(`
271
271
  `)+`
272
- `}function oe(t,n){try{return(0,r.readFileSync)((0,e.resolve)(t,`${n}.js`),`utf-8`)}catch{return}}function se(e){return e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/\r/g,`\\r`).replace(/\n/g,`\\n`)}function Y(e,t){return e.endsWith(`.vue`)?`vue`:t.includes(`@fluenti/solid`)||t.includes(`solid-js`)||t.includes(`createSignal`)||t.includes(`createMemo`)?`solid`:t.includes(`@fluenti/react`)||t.includes(`react`)||t.includes(`useState`)||t.includes(`useEffect`)||t.includes(`jsx`)?`react`:`vue`}function X(e){return e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`)}function Z(e,n){return`{ id: '${X(n?.id??(0,t.hashMessage)(e,n?.context))}', message: '${X(e)}' }`}function ce(e){let t=e.match(/<template(\s[^>]*)?>/);if(!t)return e;let n=t.index+t[0].length,r=e.lastIndexOf(`</template>`);if(r<0)return e;let i=e.slice(0,n),a=e.slice(n,r),o=e.slice(r),s=/\bv-t\b/.test(a),c=/<Trans[\s>]/.test(a),l=/<Plural[\s/>]/.test(a);return!s&&!c&&!l?e:(s&&(a=le(a),a=de(a)),c&&(a=fe(a)),l&&(a=pe(a)),i+a+o)}function le(e){return e.replace(/<(\w+)(\s[^>]*?)\bv-t\.(\w+)\b([^>]*?)>/g,(e,t,n,r,i)=>{if(r===`plural`)return e;let a=n+i,o=RegExp(`\\b${r}="([^"]*)"`),s=a.match(o);if(!s)return e;let c=s[1],l=Z(c),u=n.replace(/\s*\bv-t\.\w+\b/,``),d=i.replace(/\s*\bv-t\.\w+\b/,``),f=RegExp(`\\s*\\b${r}="[^"]*"`);return u=u.replace(f,``),d=d.replace(f,``),`<${t}${u} :${r}="$t(${l})"${d}>`})}function ue(e){let t=[];return{message:e.replace(/\{\{\s*([^}]+?)\s*\}\}/g,(e,n)=>{let r=n.trim(),i;if(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(r))i=r;else if(/^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(r)&&!r.endsWith(`.`)){let e=r.split(`.`);i=e[e.length-1]}else i=String(t.length);return t.push(`${i}: ${r}`),`{${i}}`}),vars:t}}function de(e){return e.replace(/<(\w+)(\s[^>]*?)\bv-t(?::([a-zA-Z0-9_.]+))?(?:\.plural)?(?:="([^"]*)")?\b([^>]*)>([\s\S]*?)<\/\1>/g,(e,t,n,r,i,a,o)=>{let s=e.includes(`v-t.plural`),c=n.replace(/\s*\bv-t(?::[a-zA-Z0-9_.]+)?(?:\.plural)?(?:="[^"]*")?\b/,``),l=a.replace(/\s*\bv-t(?::[a-zA-Z0-9_.]+)?(?:\.plural)?(?:="[^"]*")?\b/,``);if(s&&i){let e=o.trim().split(`|`).map(e=>e.trim());return`<${t}${c}${l}>{{ $t(${Z(`{${i}, plural, ${(e.length===2?[`one`,`other`]:[`one`,`other`,`zero`,`few`,`many`].slice(0,e.length)).map((t,n)=>`${t} {${e[n]??``}}`).join(` `)}}`,{id:r})}, { ${i} }) }}</${t}>`}let u=o.trim();if(/<(\w+)(\s[^>]*)?>[\s\S]*?<\/\1>/g.test(u)){let e=[],n=0;return`<${t}${c}${l} v-html="$vtRich(${Z(u.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g,(t,r,i,a)=>{let o=n++,s={},c=/(\w+)="([^"]*)"/g,l;for(;(l=c.exec(i))!==null;)s[l[1]]=l[2];return e.push({tag:r,attrs:s}),`<${o}>${a}</${o}>`}),{id:r})}, ${`[${e.map(e=>{let t=Object.entries(e.attrs).map(([e,t])=>`${e}: '${X(t)}'`).join(`, `);return`{ tag: '${e.tag}', attrs: { ${t} } }`}).join(`, `)}]`})"></${t}>`}let{message:d,vars:f}=ue(u),p=Z(d,{id:r});return f.length>0?`<${t}${c}${l}>{{ $t(${p}, { ${f.join(`, `)} }) }}</${t}>`:`<${t}${c}${l}>{{ $t(${p}) }}</${t}>`})}function fe(e){return e.replace(/<Trans(\s[^>]*)?>(?!\s*$)([\s\S]*?)<\/Trans>/g,(e,t,n)=>{let r=t??``;if(/\bmessage\s*=/.test(r))return e;let i=Q(r,`id`);if(i.kind===`dynamic`)return e;let a=Q(r,`context`);if(!i.value&&a.kind===`dynamic`)return e;let o=r.match(/\btag\s*=\s*"([^"]*)"/)?.[1]??`span`,s=r.replace(/\s*\btag\s*=\s*"[^"]*"/,``).replace(/\s*\bid\s*=\s*"[^"]*"/,``).replace(/\s*:id\s*=\s*"[^"]*"/,``).replace(/\s*\bcontext\s*=\s*"[^"]*"/,``).replace(/\s*:context\s*=\s*"[^"]*"/,``).replace(/\s*\bcomment\s*=\s*"[^"]*"/,``).replace(/\s*:comment\s*=\s*"[^"]*"/,``),c=n.trim();if(/<(\w+)(\s[^>]*)?>[\s\S]*?<\/\1>/g.test(c)){let e=[],t=0;return`<${o}${s} v-html="$vtRich(${Z(c.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g,(n,r,i,a)=>{let o=t++,s={},c=/(\w[\w-]*)="([^"]*)"/g,l;for(;(l=c.exec(i))!==null;)s[l[1]]=l[2];return e.push({tag:r,attrs:s}),`<${o}>${a}</${o}>`}),{id:i.value,context:a.value})}, ${`[${e.map(e=>{let t=Object.entries(e.attrs).map(([e,t])=>`${e}: '${X(t)}'`).join(`, `);return`{ tag: '${e.tag}', attrs: { ${t} } }`}).join(`, `)}]`})"></${o}>`}return`<${o}${s}>{{ $t(${Z(c,{id:i.value,context:a.value})}) }}</${o}>`})}function pe(e){return e=e.replace(/<Plural(\s[^>]*?)>([\s\S]*?)<\/Plural>/g,(e,t,n)=>{let r=t??``,i=Q(r,`id`),a=Q(r,`context`);if(i.kind===`dynamic`||!i.value&&a.kind===`dynamic`)return e;let o=/<template\s+#(\w+)\s*>([\s\S]*?)<\/template>/g,s=[],c;for(;(c=o.exec(n))!==null;)s.push({cat:c[1],content:c[2].trim()});if(s.length===0)return e;let l=r.match(/:value\s*=\s*"([^"]*)"/);if(!l)return e;let u=l[1],d=r.match(/\btag\s*=\s*"([^"]*)"/)?.[1]??`span`,f=[`zero`,`one`,`two`,`few`,`many`,`other`],p=[],m=[];for(let e of f){let t=s.find(t=>t.cat===e);if(!t)continue;let n=t.content,r=/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g,i=n;if(r.test(n)){let e=p.length,t=0;i=n.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g,(n,r,i,a)=>{let o=e+ t++,s={},c=/(\w[\w-]*)="([^"]*)"/g,l;for(;(l=c.exec(i))!==null;)s[l[1]]=l[2];return p.push({tag:r,attrs:s}),`<${o}>${a}</${o}>`})}let a=e===`zero`?`=0`:e;m.push(`${a} {${i}}`)}if(m.length===0)return e;let h=Z(`{count, plural, ${m.join(` `)}}`,{id:i.value,context:a.value}),g=r;g=g.replace(/:value\s*=\s*"[^"]*"/,``),g=g.replace(/\btag\s*=\s*"[^"]*"/,``),g=g.replace(/\s*\bid\s*=\s*"[^"]*"/,``),g=g.replace(/\s*:id\s*=\s*"[^"]*"/,``),g=g.replace(/\s*\bcontext\s*=\s*"[^"]*"/,``),g=g.replace(/\s*:context\s*=\s*"[^"]*"/,``),g=g.replace(/\s*\bcomment\s*=\s*"[^"]*"/,``),g=g.replace(/\s*:comment\s*=\s*"[^"]*"/,``),g=g.replace(/\s+/g,` `).trim();let _=g?` ${g}`:``;return p.length>0?`<${d}${_} v-html="$vtRich(${h}, ${`[${p.map(e=>{let t=Object.entries(e.attrs).map(([e,t])=>`${e}: '${X(t)}'`).join(`, `);return`{ tag: '${e.tag}', attrs: { ${t} } }`}).join(`, `)}]`}, { count: ${u} })"></${d}>`:`<${d}${_} v-text="$t(${h}, { count: ${u} })"></${d}>`}),e.replace(/<Plural(\s[^>]*?)\/?>(?:<\/Plural>)?/g,(e,t)=>{let n=t??``,r=Q(n,`id`),i=Q(n,`context`);if(r.kind===`dynamic`||!r.value&&i.kind===`dynamic`)return e;let a=n.match(/:value\s*=\s*"([^"]*)"/);if(!a)return e;let o=a[1],s=n.match(/\btag\s*=\s*"([^"]*)"/)?.[1]??`span`,c=[`zero`,`one`,`two`,`few`,`many`,`other`],l=[];for(let e of c){let t=RegExp(`(?<!:)\\b${e}\\s*=\\s*"([^"]*)"`),r=n.match(t);if(r){let t=e===`zero`?`=0`:e;l.push(`${t} {${r[1]}}`)}}if(l.length===0)return e;let u=Z(`{count, plural, ${l.join(` `)}}`,{id:r.value,context:i.value}),d=n;d=d.replace(/:value\s*=\s*"[^"]*"/,``),d=d.replace(/\btag\s*=\s*"[^"]*"/,``),d=d.replace(/\s*\bid\s*=\s*"[^"]*"/,``),d=d.replace(/\s*:id\s*=\s*"[^"]*"/,``),d=d.replace(/\s*\bcontext\s*=\s*"[^"]*"/,``),d=d.replace(/\s*:context\s*=\s*"[^"]*"/,``),d=d.replace(/\s*\bcomment\s*=\s*"[^"]*"/,``),d=d.replace(/\s*:comment\s*=\s*"[^"]*"/,``);for(let e of c)d=d.replace(RegExp(`(?<!:)\\b${e}\\s*=\\s*"[^"]*"`),``);return d=d.replace(/\s+/g,` `).trim(),`<${s}${d?` ${d}`:``} v-text="$t(${u}, { count: ${o} })"></${s}>`})}function Q(e,t){if(RegExp(`(?:^|\\s):${t}\\s*=`).test(e))return{kind:`dynamic`};let n=e.match(RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`));return n?{kind:`static`,value:n[1]??``}:{kind:`missing`}}function $(e){return{code:e,changed:!1}}var me=`virtual:fluenti/messages/`,he=`\0virtual:fluenti/messages/`;function ge(t){let r=t?.catalogDir??`src/locales/compiled`,i=t?.framework??`auto`,l=t?.splitting??!1,u=t?.sourceLocale??`en`,d=t?.locales??[u],f=t?.defaultBuildLocale??u,p=`vue`,m={name:`fluenti:virtual`,configResolved(e){a(e.command)},resolveId(e){if(e.startsWith(me))return`\0`+e;if(l){let t=H(e);if(t)return t}},load(e){if(e.startsWith(he))return`export { default } from '${`${r}/${e.slice(26)}.js`}'`;if(l){let t=U(e,{catalogDir:r,locales:d,sourceLocale:u,defaultBuildLocale:f,framework:p});if(t)return t}}},h={name:`fluenti:vue-template`,enforce:`pre`,transform(e,t){if(!t.endsWith(`.vue`)||!/\bv-t\b/.test(e)&&!/<Trans[\s>]/.test(e)&&!/<Plural[\s/>]/.test(e))return;let n=ce(e);if(n!==e)return{code:n,map:null}}},g={name:`fluenti:script-transform`,enforce:`pre`,transform(e,t){if(t.includes(`node_modules`)||!t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)||t.includes(`.vue`)&&!t.includes(`type=script`))return;let r=e,a=!1;if(t.match(/\.[jt]sx(\?|$)/)&&/<Trans[\s>]/.test(r)){let e=(0,n.transformTransComponents)(r);e.transformed&&(r=e.code,a=!0)}if(_e(r)){let e=i===`auto`?Y(t,r):i,a=(0,n.scopeTransform)(r,{framework:e,allowTopLevelImportedT:e===`vue`&&t.includes(`.vue`)});if(a.transformed)return{code:a.code,map:null}}return a?{code:r,map:null}:void 0}},_=new Map;return[m,h,{name:`fluenti:solid-jsx`,enforce:`pre`,transform(e,t){if(!t.match(/\.[tj]sx(\?|$)/)||t.includes(`node_modules`)||!/<Trans[\s>]/.test(e)&&!/<Plural[\s/>]/.test(e)||(i===`auto`?Y(t,e):i)!==`solid`)return;let n=$(e);if(n.changed)return{code:n.code,map:null}}},g,{name:`fluenti:build-split`,transform(e,t){if(!l||!o(this.environment)||t.includes(`node_modules`)||!t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/))return;p=i===`auto`?Y(t,e):i;let n=l===`static`?`static`:`dynamic`,r=n===`static`?c(e):s(e);if(l===`per-route`&&r.usedHashes.size>0&&_.set(t,r.usedHashes),!r.needsCatalogImport)return;let a=l===`per-route`?`per-route`:n;return{code:F(r.code,a,r.usedHashes),map:null}},generateBundle(t,n){if(l!==`per-route`||_.size===0)return;let i=new Map;for(let[e,t]of Object.entries(n)){if(t.type!==`chunk`)continue;let n=new Set;for(let e of Object.keys(t.modules)){let t=_.get(e);if(t)for(let e of t)n.add(e)}n.size>0&&i.set(e,n)}if(i.size===0)return;let a=new Map;for(let[e,t]of i)for(let n of t){let t=a.get(n)??[];t.push(e),a.set(n,t)}let o=new Set,s=new Map;for(let[e,t]of a)if(t.length>1)o.add(e);else{let n=q(t[0]),r=s.get(n)??new Set;r.add(e),s.set(n,r)}let c=(0,e.resolve)(process.cwd(),r);for(let e of d){let t=oe(c,e);if(!t)continue;let n=ae(t);if(o.size>0){let t=J(o,n);this.emitFile({type:`asset`,fileName:`_fluenti/shared-${e}.js`,source:t})}for(let[t,r]of s){let i=J(r,n);this.emitFile({type:`asset`,fileName:`_fluenti/${t}-${e}.js`,source:i})}}}},{name:`fluenti:dev`,configureServer(e){},hotUpdate({file:e}){if(e.includes(r)){let e=[...this.environment.moduleGraph.urlToModuleMap.entries()].filter(([e])=>e.includes(`virtual:fluenti`)).map(([,e])=>e);if(e.length>0)return e}}}]}function _e(e){return/(?<![.\w$])t\(\s*['"]/.test(e)||/[A-Za-z_$][\w$]*\(\s*\{/.test(e)||/[A-Za-z_$][\w$]*`/.test(e)&&(e.includes(`useI18n`)||e.includes(`getI18n`))?!0:/import\s*\{[^}]*\bt(?:\s+as\s+[A-Za-z_$][\w$]*)?\b[^}]*\}/.test(e)&&/@fluenti\/(react|vue|solid|next\/__generated)/.test(e)}module.exports=ge;
272
+ `}function ue(t,r){try{return(0,n.readFileSync)((0,e.resolve)(t,`${r}.js`),`utf-8`)}catch{return}}function $(e){return e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/\r/g,`\\r`).replace(/\n/g,`\\n`)}var de=`virtual:fluenti/messages/`,fe=`\0virtual:fluenti/messages/`;function pe(t,n,r){let i=t.catalogDir??`src/locales/compiled`,o=t.framework,l=t.splitting??!1,p=t.sourceLocale??`en`,m=t.locales??[p],h=t.defaultBuildLocale??p,g={name:`fluenti:virtual`,configResolved(e){s(e.command)},resolveId(e){if(e.startsWith(de))return`\0`+e;if(l){let t=Y(e);if(t)return t}},load(e){if(e.startsWith(fe))return`export { default } from '${`${i}/${e.slice(26)}.js`}'`;if(l){let t=X(e,{catalogDir:i,locales:m,sourceLocale:p,defaultBuildLocale:h,framework:o,runtimeGenerator:r});if(t)return t}}},_={name:`fluenti:script-transform`,enforce:`pre`,transform(e,t){if(t.includes(`node_modules`)||!t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)||t.includes(`.vue`)&&!t.includes(`type=script`))return;let n=e,r=!1;if(t.match(/\.[jt]sx(\?|$)/)&&/<Trans[\s>]/.test(n)){let e=(0,a.transformTransComponents)(n);e.transformed&&(n=e.code,r=!0)}if(he(n)){let e=(0,a.scopeTransform)(n,{framework:o,allowTopLevelImportedT:o===`vue`&&t.includes(`.vue`)});if(e.transformed)return{code:e.code,map:null}}return r?{code:n,map:null}:void 0}},v=new Map,y={name:`fluenti:build-split`,transform(e,t){if(!l||!c(this.environment)||t.includes(`node_modules`)||!t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/))return;let n=l===`static`?`static`:`dynamic`,r=n===`static`?f(e):d(e);if(l===`per-route`&&r.usedHashes.size>0&&v.set(t,r.usedHashes),!r.needsCatalogImport)return;let i=l===`per-route`?`per-route`:n;return{code:H(r.code,i,r.usedHashes),map:null}},generateBundle(t,n){if(l!==`per-route`||v.size===0)return;let r=new Map;for(let[e,t]of Object.entries(n)){if(t.type!==`chunk`)continue;let n=new Set;for(let e of Object.keys(t.modules)){let t=v.get(e);if(t)for(let e of t)n.add(e)}n.size>0&&r.set(e,n)}if(r.size===0)return;let a=new Map;for(let[e,t]of r)for(let n of t){let t=a.get(n)??[];t.push(e),a.set(n,t)}let o=new Set,s=new Map;for(let[e,t]of a)if(t.length>1)o.add(e);else{let n=ce(t[0]),r=s.get(n)??new Set;r.add(e),s.set(n,r)}let c=(0,e.resolve)(process.cwd(),i);for(let e of m){let t=ue(c,e);if(!t)continue;let n=le(t);if(o.size>0){let t=Q(o,n);this.emitFile({type:`asset`,fileName:`_fluenti/shared-${e}.js`,source:t})}for(let[t,r]of s){let i=Q(r,n);this.emitFile({type:`asset`,fileName:`_fluenti/${t}-${e}.js`,source:i})}}}},b=t.buildAutoCompile??!0,x={name:`fluenti:build-compile`,async buildStart(){!c(this.environment)||!b||await u({cwd:process.cwd(),throwOnError:!0,compileOnly:!0})}},S=t.devAutoCompile??!0,C=t.include??[`src/**/*.{vue,tsx,jsx,ts,js}`],w={name:`fluenti:dev`,configureServer(e){if(!S)return;let t=ee({cwd:e.config.root,onSuccess:()=>{}});t(),e.watcher.on(`change`,e=>{me(e,C)&&!e.includes(i)&&t()})},hotUpdate({file:e}){if(e.includes(i)){let e=[...this.environment.moduleGraph.urlToModuleMap.entries()].filter(([e])=>e.includes(`virtual:fluenti`)).map(([,e])=>e);if(e.length>0)return e}}};return[g,...n,_,x,y,w]}function me(e,t){return!/\.(vue|tsx|jsx|ts|js)$/.test(e)||e.includes(`node_modules`)?!1:t.some(t=>{let n=t.split(`*`)[0]??``;return n===``||e.includes(n.replace(`./`,``))})}function he(e){return/(?<![.\w$])t\(\s*['"]/.test(e)||/[A-Za-z_$][\w$]*\(\s*\{/.test(e)||/[A-Za-z_$][\w$]*`/.test(e)&&(e.includes(`useI18n`)||e.includes(`getI18n`))?!0:/import\s*\{[^}]*\bt(?:\s+as\s+[A-Za-z_$][\w$]*)?\b[^}]*\}/.test(e)&&/@fluenti\/(react|vue|solid|next)/.test(e)}exports.createFluentiPlugins=pe,exports.isBuildMode=c,exports.loadVirtualSplitModule=X,exports.resolveVirtualSplitId=Y,exports.setResolvedMode=s;
273
273
  //# sourceMappingURL=index.cjs.map