@fluenti/vite-plugin 0.2.0 → 0.3.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/client.d.ts CHANGED
@@ -1,9 +1,3 @@
1
- /**
2
- * Global tagged template function transformed by @fluenti/vite-plugin.
3
- * Transforms `t`message`` into compiled i18n calls at build time.
4
- *
5
- * @deprecated Prefer `const { t } = useI18n()` which provides the same
6
- * tagged template support without a magic global. The plugin will optimize
7
- * tagged templates via AST scope analysis when `t` comes from `useI18n()`.
8
- */
9
- declare function t(strings: TemplateStringsArray, ...values: unknown[]): string
1
+ // @fluenti/vite-plugin client types
2
+ // Virtual module declarations are generated at build time.
3
+ export {}
@@ -4,15 +4,20 @@
4
4
  * Strategy 'dynamic': rewrites supported translation calls to __catalog._<hash> references.
5
5
  * Strategy 'static': rewrites to direct named imports from compiled locale modules.
6
6
  */
7
+ export type HashFunction = (message: string, context?: string) => string;
7
8
  export interface BuildTransformResult {
8
9
  code: string;
9
10
  needsCatalogImport: boolean;
10
11
  usedHashes: Set<string>;
11
12
  }
12
- export declare function transformForDynamicSplit(code: string): BuildTransformResult;
13
- export declare function transformForStaticSplit(code: string): BuildTransformResult;
13
+ export interface BuildTransformOptions {
14
+ /** Custom hash function for message IDs (defaults to @fluenti/core hashMessage) */
15
+ hashFn?: HashFunction;
16
+ }
17
+ export declare function transformForDynamicSplit(code: string, options?: BuildTransformOptions): BuildTransformResult;
18
+ export declare function transformForStaticSplit(code: string, options?: BuildTransformOptions): BuildTransformResult;
14
19
  /**
15
20
  * Inject the catalog import statement at the top of the module.
16
21
  */
17
- export declare function injectCatalogImport(code: string, strategy: 'dynamic' | 'static' | 'per-route', hashes: Set<string>): string;
22
+ export declare function injectCatalogImport(code: string, strategy: 'dynamic' | 'static' | 'per-route', hashes: Set<string>, hashFn?: HashFunction): string;
18
23
  //# sourceMappingURL=build-transform.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"build-transform.d.ts","sourceRoot":"","sources":["../src/build-transform.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;AAExE,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAA;IACZ,kBAAkB,EAAE,OAAO,CAAA;IAC3B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,mFAAmF;IACnF,MAAM,CAAC,EAAE,YAAY,CAAA;CACtB;AAmID,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,oBAAoB,CAE5G;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,oBAAoB,CAE3G;AAkbD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,MAAM,CAalJ"}
@@ -6,6 +6,12 @@ export interface DevRunnerOptions {
6
6
  throwOnError?: boolean;
7
7
  /** Run only compile (skip extract). Useful for production builds where source is unchanged. */
8
8
  compileOnly?: boolean;
9
+ /** Enable parallel compilation across locales using worker threads */
10
+ parallelCompile?: boolean;
11
+ /** Called before compile runs. Return false to skip compilation. */
12
+ onBeforeCompile?: () => boolean | void | Promise<boolean | void>;
13
+ /** Called after compile completes successfully */
14
+ onAfterCompile?: () => void | Promise<void>;
9
15
  }
10
16
  /**
11
17
  * Walk up from `cwd` to find `node_modules/.bin/fluenti`.
@@ -1 +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"}
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;IACrB,sEAAsE;IACtE,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,oEAAoE;IACpE,eAAe,CAAC,EAAE,MAAM,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAChE,kDAAkD;IAClD,cAAc,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5C;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,CA8FhF;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EACzB,KAAK,SAAM,GACV,MAAM,IAAI,CAiCZ"}
package/dist/index.cjs CHANGED
@@ -1,273 +1,6 @@
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
- import __defaultMsgs from '${c}/${s}.js'
3
-
4
- const __catalog = { ...__defaultMsgs }
5
- let __currentLocale = '${s}'
6
- const __loadedLocales = new Set(['${s}'])
7
- let __loading = false
8
- const __cache = new Map()
9
- const __normalizeMessages = (mod) => mod.default ?? mod
10
-
11
- const __loaders = {
12
- ${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
13
- `)}
14
- }
15
-
16
- async function __switchLocale(locale) {
17
- if (__loadedLocales.has(locale)) {
18
- Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)
19
- __currentLocale = locale
20
- return
21
- }
22
- __loading = true
23
- try {
24
- const mod = __normalizeMessages(await __loaders[locale]())
25
- __cache.set(locale, mod)
26
- __loadedLocales.add(locale)
27
- Object.assign(__catalog, mod)
28
- __currentLocale = locale
29
- } finally {
30
- __loading = false
31
- }
32
- }
33
-
34
- async function __preloadLocale(locale) {
35
- if (__loadedLocales.has(locale) || !__loaders[locale]) return
36
- try {
37
- const mod = __normalizeMessages(await __loaders[locale]())
38
- __cache.set(locale, mod)
39
- __loadedLocales.add(locale)
40
- } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
41
- }
42
-
43
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
44
-
45
- export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
46
- `:o===`vue`?`
47
- import { shallowReactive, triggerRef, ref } from 'vue'
48
- import __defaultMsgs from '${c}/${s}.js'
49
-
50
- const __catalog = shallowReactive({ ...__defaultMsgs })
51
- const __currentLocale = ref('${s}')
52
- const __loadedLocales = new Set(['${s}'])
53
- const __loading = ref(false)
54
- const __cache = new Map()
55
- const __normalizeMessages = (mod) => mod.default ?? mod
56
-
57
- const __loaders = {
58
- ${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
59
- `)}
60
- }
61
-
62
- async function __switchLocale(locale) {
63
- if (__loadedLocales.has(locale)) {
64
- Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)
65
- __currentLocale.value = locale
66
- return
67
- }
68
- __loading.value = true
69
- try {
70
- const mod = __normalizeMessages(await __loaders[locale]())
71
- __cache.set(locale, mod)
72
- __loadedLocales.add(locale)
73
- Object.assign(__catalog, mod)
74
- __currentLocale.value = locale
75
- } finally {
76
- __loading.value = false
77
- }
78
- }
79
-
80
- async function __preloadLocale(locale) {
81
- if (__loadedLocales.has(locale) || !__loaders[locale]) return
82
- try {
83
- const mod = __normalizeMessages(await __loaders[locale]())
84
- __cache.set(locale, mod)
85
- __loadedLocales.add(locale)
86
- } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
87
- }
88
-
89
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
90
-
91
- export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
92
- `:`
93
- import { createSignal } from 'solid-js'
94
- import { createStore, reconcile } from 'solid-js/store'
95
- import __defaultMsgs from '${c}/${s}.js'
96
-
97
- const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
98
- const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
99
- const __loadedLocales = new Set(['${s}'])
100
- const [__loading, __setLoading] = createSignal(false)
101
- const __cache = new Map()
102
- const __normalizeMessages = (mod) => mod.default ?? mod
103
-
104
- const __loaders = {
105
- ${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
106
- `)}
107
- }
108
-
109
- async function __switchLocale(locale) {
110
- if (__loadedLocales.has(locale)) {
111
- __setCatalog(reconcile(__cache.get(locale) || __defaultMsgs))
112
- __setCurrentLocale(locale)
113
- return
114
- }
115
- __setLoading(true)
116
- try {
117
- const mod = __normalizeMessages(await __loaders[locale]())
118
- __cache.set(locale, mod)
119
- __loadedLocales.add(locale)
120
- __setCatalog(reconcile(mod))
121
- __setCurrentLocale(locale)
122
- } finally {
123
- __setLoading(false)
124
- }
125
- }
126
-
127
- async function __preloadLocale(locale) {
128
- if (__loadedLocales.has(locale) || !__loaders[locale]) return
129
- try {
130
- const mod = __normalizeMessages(await __loaders[locale]())
131
- __cache.set(locale, mod)
132
- __loadedLocales.add(locale)
133
- } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
134
- }
135
-
136
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
137
-
138
- export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
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
- import { shallowReactive, ref } from 'vue'
141
- import __defaultMsgs from '${c}/${s}.js'
142
-
143
- const __catalog = shallowReactive({ ...__defaultMsgs })
144
- const __currentLocale = ref('${s}')
145
- const __loadedLocales = new Set(['${s}'])
146
- const __loading = ref(false)
147
- const __cache = new Map()
148
- const __loadedRoutes = new Set()
149
- const __normalizeMessages = (mod) => mod.default ?? mod
150
-
151
- const __loaders = {
152
- ${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
153
- `)}
154
- }
155
-
156
- const __routeLoaders = {}
157
-
158
- function __registerRouteLoader(routeId, locale, loader) {
159
- const key = routeId + ':' + locale
160
- __routeLoaders[key] = loader
161
- }
162
-
163
- async function __loadRoute(routeId, locale) {
164
- const key = routeId + ':' + (locale || __currentLocale.value)
165
- if (__loadedRoutes.has(key)) return
166
- const loader = __routeLoaders[key]
167
- if (!loader) return
168
- const mod = __normalizeMessages(await loader())
169
- Object.assign(__catalog, mod)
170
- __loadedRoutes.add(key)
171
- }
172
-
173
- async function __switchLocale(locale) {
174
- if (locale === __currentLocale.value) return
175
- __loading.value = true
176
- try {
177
- if (__cache.has(locale)) {
178
- Object.assign(__catalog, __cache.get(locale))
179
- } else {
180
- const mod = __normalizeMessages(await __loaders[locale]())
181
- __cache.set(locale, mod)
182
- Object.assign(__catalog, mod)
183
- }
184
- __loadedLocales.add(locale)
185
- __currentLocale.value = locale
186
- } finally {
187
- __loading.value = false
188
- }
189
- }
190
-
191
- async function __preloadLocale(locale) {
192
- if (__cache.has(locale) || !__loaders[locale]) return
193
- try {
194
- const mod = __normalizeMessages(await __loaders[locale]())
195
- __cache.set(locale, mod)
196
- __loadedLocales.add(locale)
197
- } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
198
- }
199
-
200
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
201
-
202
- export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
203
- `:`
204
- import { createSignal } from 'solid-js'
205
- import { createStore, reconcile } from 'solid-js/store'
206
- import __defaultMsgs from '${c}/${s}.js'
207
-
208
- const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
209
- const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
210
- const __loadedLocales = new Set(['${s}'])
211
- const [__loading, __setLoading] = createSignal(false)
212
- const __cache = new Map()
213
- const __loadedRoutes = new Set()
214
- const __normalizeMessages = (mod) => mod.default ?? mod
215
-
216
- const __loaders = {
217
- ${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
218
- `)}
219
- }
220
-
221
- const __routeLoaders = {}
222
-
223
- function __registerRouteLoader(routeId, locale, loader) {
224
- const key = routeId + ':' + locale
225
- __routeLoaders[key] = loader
226
- }
227
-
228
- async function __loadRoute(routeId, locale) {
229
- const key = routeId + ':' + (locale || __currentLocale())
230
- if (__loadedRoutes.has(key)) return
231
- const loader = __routeLoaders[key]
232
- if (!loader) return
233
- const mod = __normalizeMessages(await loader())
234
- __setCatalog(reconcile({ ...__catalog, ...mod }))
235
- __loadedRoutes.add(key)
236
- }
237
-
238
- async function __switchLocale(locale) {
239
- if (locale === __currentLocale()) return
240
- __setLoading(true)
241
- try {
242
- if (__cache.has(locale)) {
243
- __setCatalog(reconcile(__cache.get(locale)))
244
- } else {
245
- const mod = __normalizeMessages(await __loaders[locale]())
246
- __cache.set(locale, mod)
247
- __setCatalog(reconcile(mod))
248
- }
249
- __loadedLocales.add(locale)
250
- __setCurrentLocale(locale)
251
- } finally {
252
- __setLoading(false)
253
- }
254
- }
255
-
256
- async function __preloadLocale(locale) {
257
- if (__cache.has(locale) || !__loaders[locale]) return
258
- try {
259
- const mod = __normalizeMessages(await __loaders[locale]())
260
- __cache.set(locale, mod)
261
- __loadedLocales.add(locale)
262
- } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
263
- }
264
-
265
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
266
-
267
- export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
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(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`vite`),t=require(`@fluenti/core/internal`),n=require(`node:path`),r=require(`node:module`),i=require(`node:child_process`),a=require(`node:fs`),o=require(`@fluenti/core/transform`),s=require(`@fluenti/core`);var c=`dev`;function l(e){c=e===`build`?`build`:`dev`}function u(e){if(typeof e==`object`&&e&&`environment`in e){let t=e.environment;if(typeof t==`object`&&t)return t}}function d(e){return e?.mode===`build`||c===`build`||process.env.NODE_ENV===`production`}function f(e){let t=e;for(;;){let e=(0,n.resolve)(t,`node_modules/.bin/fluenti`);if((0,a.existsSync)(e))return e;let r=(0,n.dirname)(t);if(r===t)break;t=r}return null}async function p(e){if(e.onBeforeCompile&&await e.onBeforeCompile()===!1)return;if(e.compileOnly)try{let{runCompile:t}=(0,r.createRequire)((0,n.join)(e.cwd,`package.json`))(`@fluenti/cli`);await t(e.cwd),console.log(`[fluenti] Compiling... done`),e.onAfterCompile&&await e.onAfterCompile(),e.onSuccess?.();return}catch(t){let n=t instanceof Error?t:Error(String(t));if(e.throwOnError)throw n;console.warn(`[fluenti] Compile failed:`,n.message),e.onError?.(n);return}try{let{runExtract:t,runCompile:i}=(0,r.createRequire)((0,n.join)(e.cwd,`package.json`))(`@fluenti/cli`);await t(e.cwd),await i(e.cwd,{parallel:e.parallelCompile}),console.log(`[fluenti] Extracting and compiling... done`),e.onAfterCompile&&await e.onAfterCompile(),e.onSuccess?.();return}catch{}let t=f(e.cwd);if(!t){let t=`[fluenti] CLI not found — skipping auto-compile. Install @fluenti/cli as a devDependency.`;return e.throwOnError?Promise.reject(Error(t)):(console.warn(t),Promise.resolve())}let a=e.parallelCompile?[`compile`,`--parallel`]:[`compile`];return new Promise((n,r)=>{(0,i.execFile)(t,[`extract`],{cwd:e.cwd},(o,s,c)=>{if(o){let t=Error(c||o.message);if(e.throwOnError){r(t);return}console.warn(`[fluenti] Extract/compile failed:`,t.message),e.onError?.(t),n();return}(0,i.execFile)(t,a,{cwd:e.cwd},(t,i,a)=>{if(t){let n=Error(a||t.message);if(e.throwOnError){r(n);return}console.warn(`[fluenti] Extract/compile failed:`,n.message),e.onError?.(n)}else console.log(`[fluenti] Extracting and compiling... done`),e.onAfterCompile&&Promise.resolve(e.onAfterCompile()).catch(()=>{}),e.onSuccess?.();n()})})})}function ee(e,t=300){let n=null,r=!1,i=!1;async function a(){r=!0;try{await p(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 te(e,t){return h(e,`dynamic`,t)}function m(e,t){return h(e,`static`,t)}function h(e,n,r){let i=r?.hashFn??t.hashMessage,a=(0,o.parseSourceModule)(e);if(!a||a.type!==`Program`)return{code:e,needsCatalogImport:!1,usedHashes:new Set};let s=g(a),c=[],l=new Set;if((0,o.walkSourceAst)(a,t=>{let r=v(e,t,s,n,l,i);if(r){c.push(r);return}x(t,l,i)}),c.length===0)return{code:e,needsCatalogImport:!1,usedHashes:l};let u=e;for(let e=c.length-1;e>=0;e--){let{start:t,end:n,replacement:r}=c[e];u=u.slice(0,t)+r+u.slice(n)}return{code:u,needsCatalogImport:!0,usedHashes:l}}function g(e){let t=new Set,n=new Set,r=new Set,i=new Set;for(let t of e.body)if(P(t))for(let e of t.specifiers){if(!ne(e))continue;let t=se(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,o.walkSourceAst)(e,e=>{if(!re(e)||!e.init||!ie(e.id))return;if(L(e.init)&&R(e.init.callee)&&n.has(e.init.callee.name)){_(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)&&_(e.id,t)}),{tracked:t,unref:i}}function _(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 v(e,t,n,r,i,a){if(!L(t)||t.start==null||t.end==null)return;let o=y(e,t,n,a);if(!o)return;let{catalogId:s}=o;i.add(s);let c=a(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 y(e,t,n,r){if(t.arguments.length===0)return;let i=t.callee,a=R(i)&&(n.tracked.has(i.name)||i.name===`$t`),o=ae(i)&&!i.computed&&R(i.property)&&(i.property.name===`$t`||i.property.name===`t`&&R(i.object)&&(i.object.name===`_ctx`||i.object.name===`$setup`)),s=L(i)&&R(i.callee)&&n.unref.has(i.callee.name)&&i.arguments.length===1&&R(i.arguments[0])&&n.tracked.has(i.arguments[0].name);if(!a&&!o&&!s)return;let c=b(t.arguments[0],r);if(!c)return;let l=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 l===void 0?{catalogId:c}:{catalogId:c,valuesSource:l}}function b(e,t){let n=M(e);if(n!==void 0)return t(n);if(!F(e))return;let r,i,a;for(let t of e.properties){if(!I(t)||t.computed)continue;let e=N(t.key);if(!e)continue;let n=M(t.value);n!==void 0&&(e===`id`&&(r=n),e===`message`&&(i=n),e===`context`&&(a=n))}if(r)return r;if(i)return t(i,a)}function x(e,t,n){if(!oe(e))return;let r=j(e.openingElement.name);if(r){if(r===`Trans`){let r=D(e.openingElement,`__id`)??D(e.openingElement,`id`);if(r){t.add(r);return}let i=D(e.openingElement,`__message`),a=D(e.openingElement,`context`);i&&t.add(n(i,a));return}if(r===`Plural`){let r=S(e.openingElement,n);r&&t.add(r);return}if(r===`Select`){let r=C(e.openingElement,n);r&&t.add(r)}}}function S(e,t){let n=D(e,`id`);if(n)return n;let r=D(e,`context`),i=O(e,`offset`),a=[D(e,`zero`)===void 0?void 0:`=0 {${D(e,`zero`)}}`,D(e,`one`)===void 0?void 0:`one {${D(e,`one`)}}`,D(e,`two`)===void 0?void 0:`two {${D(e,`two`)}}`,D(e,`few`)===void 0?void 0:`few {${D(e,`few`)}}`,D(e,`many`)===void 0?void 0:`many {${D(e,`many`)}}`,D(e,`other`)===void 0?void 0:`other {${D(e,`other`)}}`].filter(Boolean);if(a.length!==0)return t(`{count, plural,${typeof i==`number`?` offset:${i}`:``} ${a.join(` `)}}`,r)}function C(e,t){let n=D(e,`id`);if(n)return n;let r=D(e,`context`),i=w(e);if(!(!i||i.other===void 0))return t(`{value, select, ${[...Object.keys(i).filter(e=>e!==`other`).sort(),`other`].map(e=>`${e} {${i[e]}}`).join(` `)}}`,r)}function w(e){let t=E(e,`options`);if(t){let n=D(e,`other`);return{...t,...n===void 0?{}:{other:n}}}let n={};for(let t of e.attributes){if(!z(t))continue;let e=t.name.name;if([`value`,`id`,`context`,`comment`,`options`].includes(e))continue;let r=A(t);r!==void 0&&(n[e]=r)}return Object.keys(n).length>0?n:void 0}function T(e){if(!F(e))return;let t={};for(let n of e.properties){if(!I(n)||n.computed)return;let e=N(n.key),r=M(n.value);if(!e||r===void 0)return;t[e]=r}return t}function E(e,t){let n=k(e,t);if(n?.value&&n.value.type===`JSXExpressionContainer`)return T(n.value.expression)}function D(e,t){return A(k(e,t))}function O(e,t){let n=k(e,t);if(!n?.value||n.value.type!==`JSXExpressionContainer`)return;let r=n.value.expression;return r.type===`NumericLiteral`?r.value:void 0}function k(e,t){return e.attributes.find(e=>z(e)&&e.name.name===t)}function A(e){if(e?.value){if(e.value.type===`StringLiteral`)return e.value.value;if(e.value.type===`JSXExpressionContainer`)return M(e.value.expression)}}function j(e){return e.type===`JSXIdentifier`?e.name:void 0}function M(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 N(e){if(R(e))return e.name;if(e.type===`StringLiteral`)return e.value}function P(e){return e.type===`ImportDeclaration`}function ne(e){return e.type===`ImportSpecifier`}function re(e){return e.type===`VariableDeclarator`}function ie(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 ae(e){return e.type===`MemberExpression`}function R(e){return e?.type===`Identifier`}function oe(e){return e.type===`JSXElement`}function z(e){return e.type===`JSXAttribute`}function se(e){let t=e.imported;if(t.type===`Identifier`)return t.name;if(t.type===`StringLiteral`)return t.value}function ce(e,n,r,i){if(n===`dynamic`)return`import { __catalog } from 'virtual:fluenti/runtime';\n${e}`;if(n===`per-route`)return`import { __catalog } from 'virtual:fluenti/route-runtime';\n${e}`;let a=i??t.hashMessage;return`import { ${[...r].map(e=>`_${a(e)}`).join(`, `)} } from 'virtual:fluenti/messages';\n${e}`}function B(e){return JSON.stringify(e)}function V(e){if(e.includes("`")||e.includes(`$`))throw Error(`[fluenti] vite-plugin: catalogDir must not contain backticks or $ characters, got ${JSON.stringify(e)}`)}var H=`virtual:fluenti/runtime`,U=`virtual:fluenti/messages`,W=`virtual:fluenti/route-runtime`,G=`\0virtual:fluenti/runtime`,K=`\0virtual:fluenti/messages`,q=`\0virtual:fluenti/route-runtime`;function J(e){if(e===H)return G;if(e===U)return K;if(e===W)return q}function Y(e,t){if(e===G)return le(t);if(e===K)return ue(t);if(e===q)return de(t)}function le(e){let{locales:t,runtimeGenerator:n,catalogDir:r}=e;V(r);for(let e of t)(0,s.validateLocale)(e,`vite-plugin`);if(!n)throw Error(`[fluenti] vite-plugin: runtimeGenerator is required. Use a framework-specific plugin (e.g. @fluenti/vue/vite-plugin).`);return n.generateRuntime(X(e))}function ue(e){let{rootDir:t,catalogDir:r,catalogExtension:i,defaultBuildLocale:a,sourceLocale:o}=e,c=a||o;return(0,s.validateLocale)(c,`vite-plugin`),V(r),`export * from ${B((0,n.resolve)(t,r)+`/`+c+i)}\n`}function de(e){let{locales:t,runtimeGenerator:n,catalogDir:r}=e;V(r);for(let e of t)(0,s.validateLocale)(e,`vite-plugin`);if(!n)throw Error(`[fluenti] vite-plugin: runtimeGenerator is required. Use a framework-specific plugin (e.g. @fluenti/vue/vite-plugin).`);return n.generateRouteRuntime(X(e))}function X(e){let{rootDir:t,catalogDir:n,catalogExtension:r,locales:i,sourceLocale:a,defaultBuildLocale:o}=e;return{rootDir:t,catalogDir:n,catalogExtension:r,locales:i,sourceLocale:a,defaultBuildLocale:o}}function fe(e){let t=(e.includes(`/`)?e.slice(e.lastIndexOf(`/`)+1):e).replace(/\.[^.]+$/,``);return t.replace(/-[a-zA-Z0-9]{4,}$/,``)||t}function pe(e){let t=new Map,n=e.split(`
269
2
  `);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 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(`
3
+ `+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 Z(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(` '${he(a)}': _${e},`))}return i.length>0&&r.push(``,`export default {`,...i,`}`),r.join(`
271
4
  `)+`
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;
5
+ `}function me(e,t){try{return(0,a.readFileSync)((0,n.resolve)(e,`${t}.js`),`utf-8`)}catch{return}}function he(e){return e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/\r/g,`\\r`).replace(/\n/g,`\\n`)}var Q=(0,r.createRequire)({}.url),ge=`virtual:fluenti/messages/`,_e=`\0virtual:fluenti/messages/`;function $(e,t){if(typeof e==`object`){let{DEFAULT_FLUENTI_CONFIG:t}=Q(`@fluenti/core/config`);return{...t,...e}}let{loadConfigSync:n}=Q(`@fluenti/core/config`);return n(typeof e==`string`?e:void 0,t)}function ve(r,i,a){let s;function c(e){return s||=$(r.config,e),s}let f=$(r.config),h=f.compileOutDir.replace(/^\.\//,``),g=f.catalogExtension??`.js`,_=r.framework,v=f.splitting??!1,y=f.sourceLocale,b=(0,t.resolveLocaleCodes)(f.locales),x=f.defaultBuildLocale??y,S=f.idGenerator,C=f.onBeforeCompile,w=f.onAfterCompile,T=process.cwd(),E={name:`fluenti:virtual`,configResolved(e){T=e.root,l(e.command)},resolveId(e){if(e.startsWith(ge))return`\0`+e;if(v){let t=J(e);if(t)return t}},load(e){if(e.startsWith(_e))return`export { default } from '${`${h}/${e.slice(26)}${g}`}'`;if(v){let t=Y(e,{rootDir:T,catalogDir:h,catalogExtension:g,locales:b,sourceLocale:y,defaultBuildLocale:x,framework:_,runtimeGenerator:a});if(t)return t}}},D=(0,o.createTransformPipeline)({framework:_}),O={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=_===`vue`&&t.includes(`.vue`),r=e,i=!1;if(t.match(/\.[jt]sx(\?|$)/)&&/<Trans[\s>]/.test(r)){let e=D.transformTrans(r);e.transformed&&(r=e.code,i=!0)}if((0,o.hasScopeTransformCandidate)(r)){let e=D.transformScope(r,n?{allowTopLevelImportedT:!0}:void 0);if(e.transformed)return{code:e.code,map:null}}return i?{code:r,map:null}:void 0}},k=new Map,A={name:`fluenti:build-split`,transform(e,t){if(!v||!d(u(this))||t.includes(`node_modules`)||!t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/))return;let n=v===`static`?`static`:`dynamic`,r=S?{hashFn:S}:void 0,i=n===`static`?m(e,r):te(e,r);if(v===`per-route`&&i.usedHashes.size>0&&k.set(t,i.usedHashes),!i.needsCatalogImport)return;let a=v===`per-route`?`per-route`:n;return{code:ce(i.code,a,i.usedHashes,S),map:null}},generateBundle(e,t){if(v!==`per-route`||k.size===0)return;let r=new Map;for(let[e,n]of Object.entries(t)){if(n.type!==`chunk`)continue;let t=new Set;for(let e of Object.keys(n.modules)){let n=k.get(e);if(n)for(let e of n)t.add(e)}t.size>0&&r.set(e,t)}if(r.size===0)return;let i=new Map;for(let[e,t]of r)for(let n of t){let t=i.get(n)??[];t.push(e),i.set(n,t)}let a=new Set,o=new Map;for(let[e,t]of i)if(t.length>1)a.add(e);else{let n=fe(t[0]),r=o.get(n)??new Set;r.add(e),o.set(n,r)}let s=(0,n.resolve)(T,h);for(let e of b){let t=me(s,e);if(!t)continue;let n=pe(t);if(a.size>0){let t=Z(a,n);this.emitFile({type:`asset`,fileName:`_fluenti/shared-${e}.js`,source:t})}for(let[t,r]of o){let i=Z(r,n);this.emitFile({type:`asset`,fileName:`_fluenti/${t}-${e}.js`,source:i})}}}},j=f.buildAutoCompile??!0,M={name:`fluenti:build-compile`,async buildStart(){!d(u(this))||!j||C&&await C()===!1||(await p({cwd:T,throwOnError:!0,compileOnly:!0}),w&&await w())}},N=f.devAutoCompile??!0,P={name:`fluenti:dev`,configureServer(t){if(!N)return;let n=c(t.config.root),r=(0,e.createFilter)(n.include??[`src/**/*.{vue,tsx,jsx,ts,js}`],[...n.exclude??[],`**/node_modules/**`,`**/${h}/**`]),i={cwd:t.config.root,onSuccess:()=>{}};f.parallelCompile&&(i.parallelCompile=!0),C&&(i.onBeforeCompile=C),w&&(i.onAfterCompile=w);let a=ee(i,f.devAutoCompileDelay??500);a(),t.watcher.on(`change`,e=>{r(e)&&a()})},hotUpdate({file:e}){if(e.includes(h)){let e=[...this.environment.moduleGraph.urlToModuleMap.entries()].filter(([e])=>e.includes(`virtual:fluenti`)).map(([,e])=>e);if(e.length>0)return e}}};return[E,...i,O,M,A,P]}exports.createFluentiPlugins=ve,Object.defineProperty(exports,`createRuntimeGenerator`,{enumerable:!0,get:function(){return o.createRuntimeGenerator}}),exports.getPluginEnvironment=u,exports.isBuildMode=d,exports.loadVirtualSplitModule=Y,exports.resolveVirtualSplitId=J,exports.setResolvedMode=l;
273
6
  //# sourceMappingURL=index.cjs.map