@fluenti/vite-plugin 0.1.1 → 0.1.3

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/dist/index.cjs CHANGED
@@ -1,15 +1,15 @@
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`?`
2
- import __defaultMsgs from '${c}/${s}.js'
1
+ let e=require(`node:path`),t=require(`@fluenti/core/internal`),n=require(`@fluenti/core`),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,n){let r=(0,t.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,t.walkSourceAst)(r,t=>{let r=f(e,t,i,n,o);if(r){a.push(r);return}h(t,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 n=new Set,r=new Set,i=new Set,a=new Set;for(let t of e.body)if(O(t))for(let e of t.specifiers){if(!k(e))continue;let t=ie(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,t.walkSourceAst)(e,e=>{if(!ee(e)||!e.init||!te(e.id))return;if(M(e.init)&&N(e.init.callee)&&r.has(e.init.callee.name)){d(e.id,n);return}let t=e.init.type===`AwaitExpression`?e.init.argument:null;t&&M(t)&&N(t.callee)&&i.has(t.callee.name)&&d(e.id,n)}),{tracked:n,unref:a}}function d(e,t){for(let n of e.properties)!j(n)||n.computed||!N(n.key)||n.key.name!==`t`||N(n.value)&&t.add(n.value.name)}function f(e,t,r,i,a){if(!M(t)||t.start==null||t.end==null)return;let o=p(e,t,r);if(!o)return;let{catalogId:s}=o;a.add(s);let c=(0,n.hashMessage)(s),l=i===`dynamic`?`__catalog[${JSON.stringify(s)}]`:`_${c}`,u=o.valuesSource?`${l}(${o.valuesSource})`:l;return{start:t.start,end:t.end,replacement:u}}function p(e,t,n){if(t.arguments.length===0)return;let r=t.callee,i=N(r)&&(n.tracked.has(r.name)||r.name===`$t`),a=ne(r)&&!r.computed&&N(r.property)&&(r.property.name===`$t`||r.property.name===`t`&&N(r.object)&&(r.object.name===`_ctx`||r.object.name===`$setup`)),o=M(r)&&N(r.callee)&&n.unref.has(r.callee.name)&&r.arguments.length===1&&N(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 t=E(e);if(t!==void 0)return(0,n.hashMessage)(t);if(!A(e))return;let r,i,a;for(let t of e.properties){if(!j(t)||t.computed)continue;let e=D(t.key);if(!e)continue;let n=E(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,n.hashMessage)(i,a)}function h(e,t){if(!re(e))return;let r=T(e.openingElement.name);if(r){if(r===`Trans`){let r=x(e.openingElement,`__id`)??x(e.openingElement,`id`);if(r){t.add(r);return}let i=x(e.openingElement,`__message`),a=x(e.openingElement,`context`);i&&t.add((0,n.hashMessage)(i,a));return}if(r===`Plural`){let n=g(e.openingElement);n&&t.add(n);return}if(r===`Select`){let n=_(e.openingElement);n&&t.add(n)}}}function g(e){let t=x(e,`id`);if(t)return t;let r=x(e,`context`),i=S(e,`offset`),a=[x(e,`zero`)===void 0?void 0:`=0 {${x(e,`zero`)}}`,x(e,`one`)===void 0?void 0:`one {${x(e,`one`)}}`,x(e,`two`)===void 0?void 0:`two {${x(e,`two`)}}`,x(e,`few`)===void 0?void 0:`few {${x(e,`few`)}}`,x(e,`many`)===void 0?void 0:`many {${x(e,`many`)}}`,x(e,`other`)===void 0?void 0:`other {${x(e,`other`)}}`].filter(Boolean);if(a.length!==0)return(0,n.hashMessage)(`{count, plural,${typeof i==`number`?` offset:${i}`:``} ${a.join(` `)}}`,r)}function _(e){let t=x(e,`id`);if(t)return t;let r=x(e,`context`),i=v(e);if(!(!i||i.other===void 0))return(0,n.hashMessage)(`{value, select, ${[...Object.keys(i).filter(e=>e!==`other`).sort(),`other`].map(e=>`${e} {${i[e]}}`).join(` `)}}`,r)}function v(e){let t=b(e,`options`);if(t){let n=x(e,`other`);return{...t,...n===void 0?{}:{other:n}}}let n={};for(let t of e.attributes){if(!P(t))continue;let e=t.name.name;if([`value`,`id`,`context`,`comment`,`options`].includes(e))continue;let r=w(t);r!==void 0&&(n[e]=r)}return Object.keys(n).length>0?n:void 0}function y(e){if(!A(e))return;let t={};for(let n of e.properties){if(!j(n)||n.computed)return;let e=D(n.key),r=E(n.value);if(!e||r===void 0)return;t[e]=r}return t}function b(e,t){let n=C(e,t);if(n?.value&&n.value.type===`JSXExpressionContainer`)return y(n.value.expression)}function x(e,t){return w(C(e,t))}function S(e,t){let n=C(e,t);if(!n?.value||n.value.type!==`JSXExpressionContainer`)return;let r=n.value.expression;return r.type===`NumericLiteral`?r.value:void 0}function C(e,t){return e.attributes.find(e=>P(e)&&e.name.name===t)}function w(e){if(e?.value){if(e.value.type===`StringLiteral`)return e.value.value;if(e.value.type===`JSXExpressionContainer`)return E(e.value.expression)}}function T(e){return e.type===`JSXIdentifier`?e.name:void 0}function E(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 D(e){if(N(e))return e.name;if(e.type===`StringLiteral`)return e.value}function O(e){return e.type===`ImportDeclaration`}function k(e){return e.type===`ImportSpecifier`}function ee(e){return e.type===`VariableDeclarator`}function te(e){return e.type===`ObjectPattern`}function A(e){return e.type===`ObjectExpression`}function j(e){return e.type===`ObjectProperty`}function M(e){return e.type===`CallExpression`}function ne(e){return e.type===`MemberExpression`}function N(e){return e?.type===`Identifier`}function re(e){return e.type===`JSXElement`}function P(e){return e.type===`JSXAttribute`}function ie(e){let t=e.imported;if(t.type===`Identifier`)return t.name;if(t.type===`StringLiteral`)return t.value}function ae(e,t,r){return t===`dynamic`?`import { __catalog } from 'virtual:fluenti/runtime';\n${e}`:t===`per-route`?`import { __catalog } from 'virtual:fluenti/route-runtime';\n${e}`:`import { ${[...r].map(e=>`_${(0,n.hashMessage)(e)}`).join(`, `)} } from 'virtual:fluenti/messages';\n${e}`}var F=`virtual:fluenti/runtime`,I=`virtual:fluenti/messages`,L=`virtual:fluenti/route-runtime`,R=`\0virtual:fluenti/runtime`,z=`\0virtual:fluenti/messages`,B=`\0virtual:fluenti/route-runtime`;function V(e){if(e===F)return R;if(e===I)return z;if(e===L)return B}function H(e,t){if(e===R)return U(t);if(e===z)return W(t);if(e===B)return G(t)}function U(t){let{catalogDir:r,locales:i,sourceLocale:a,defaultBuildLocale:o,framework:s}=t;for(let e of i)(0,n.validateLocale)(e,`vite-plugin`);let c=o||a,l=(0,e.resolve)(process.cwd(),r),u=`fluenti.runtime.${s}`,d=i.filter(e=>e!==c);return s===`react`?`
2
+ import __defaultMsgs from '${l}/${c}.js'
3
3
 
4
4
  const __catalog = { ...__defaultMsgs }
5
- let __currentLocale = '${s}'
6
- const __loadedLocales = new Set(['${s}'])
5
+ let __currentLocale = '${c}'
6
+ const __loadedLocales = new Set(['${c}'])
7
7
  let __loading = false
8
8
  const __cache = new Map()
9
9
  const __normalizeMessages = (mod) => mod.default ?? mod
10
10
 
11
11
  const __loaders = {
12
- ${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
12
+ ${d.map(e=>` '${e}': () => import('${l}/${e}.js'),`).join(`
13
13
  `)}
14
14
  }
15
15
 
@@ -37,25 +37,25 @@ 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
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
43
+ globalThis[Symbol.for('${u}')] = { __switchLocale, __preloadLocale }
44
44
 
45
45
  export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
46
- `:o===`vue`?`
46
+ `:s===`vue`?`
47
47
  import { shallowReactive, triggerRef, ref } from 'vue'
48
- import __defaultMsgs from '${c}/${s}.js'
48
+ import __defaultMsgs from '${l}/${c}.js'
49
49
 
50
50
  const __catalog = shallowReactive({ ...__defaultMsgs })
51
- const __currentLocale = ref('${s}')
52
- const __loadedLocales = new Set(['${s}'])
51
+ const __currentLocale = ref('${c}')
52
+ const __loadedLocales = new Set(['${c}'])
53
53
  const __loading = ref(false)
54
54
  const __cache = new Map()
55
55
  const __normalizeMessages = (mod) => mod.default ?? mod
56
56
 
57
57
  const __loaders = {
58
- ${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
58
+ ${d.map(e=>` '${e}': () => import('${l}/${e}.js'),`).join(`
59
59
  `)}
60
60
  }
61
61
 
@@ -83,26 +83,26 @@ 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
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
89
+ globalThis[Symbol.for('${u}')] = { __switchLocale, __preloadLocale }
90
90
 
91
91
  export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
92
92
  `:`
93
93
  import { createSignal } from 'solid-js'
94
94
  import { createStore, reconcile } from 'solid-js/store'
95
- import __defaultMsgs from '${c}/${s}.js'
95
+ import __defaultMsgs from '${l}/${c}.js'
96
96
 
97
97
  const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
98
- const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
99
- const __loadedLocales = new Set(['${s}'])
98
+ const [__currentLocale, __setCurrentLocale] = createSignal('${c}')
99
+ const __loadedLocales = new Set(['${c}'])
100
100
  const [__loading, __setLoading] = createSignal(false)
101
101
  const __cache = new Map()
102
102
  const __normalizeMessages = (mod) => mod.default ?? mod
103
103
 
104
104
  const __loaders = {
105
- ${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
105
+ ${d.map(e=>` '${e}': () => import('${l}/${e}.js'),`).join(`
106
106
  `)}
107
107
  }
108
108
 
@@ -130,26 +130,26 @@ 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
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
136
+ globalThis[Symbol.for('${u}')] = { __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 W(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 G(t){let{catalogDir:r,locales:i,sourceLocale:a,defaultBuildLocale:o,framework:s}=t;for(let e of i)(0,n.validateLocale)(e,`vite-plugin`);let c=o||a,l=(0,e.resolve)(process.cwd(),r),u=`fluenti.runtime.${s}`,d=i.filter(e=>e!==c);return s===`vue`?`
140
140
  import { shallowReactive, ref } from 'vue'
141
- import __defaultMsgs from '${c}/${s}.js'
141
+ import __defaultMsgs from '${l}/${c}.js'
142
142
 
143
143
  const __catalog = shallowReactive({ ...__defaultMsgs })
144
- const __currentLocale = ref('${s}')
145
- const __loadedLocales = new Set(['${s}'])
144
+ const __currentLocale = ref('${c}')
145
+ const __loadedLocales = new Set(['${c}'])
146
146
  const __loading = ref(false)
147
147
  const __cache = new Map()
148
148
  const __loadedRoutes = new Set()
149
149
  const __normalizeMessages = (mod) => mod.default ?? mod
150
150
 
151
151
  const __loaders = {
152
- ${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
152
+ ${d.map(e=>` '${e}': () => import('${l}/${e}.js'),`).join(`
153
153
  `)}
154
154
  }
155
155
 
@@ -194,27 +194,27 @@ 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
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
200
+ globalThis[Symbol.for('${u}')] = { __switchLocale, __preloadLocale }
201
201
 
202
202
  export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
203
203
  `:`
204
204
  import { createSignal } from 'solid-js'
205
205
  import { createStore, reconcile } from 'solid-js/store'
206
- import __defaultMsgs from '${c}/${s}.js'
206
+ import __defaultMsgs from '${l}/${c}.js'
207
207
 
208
208
  const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
209
- const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
210
- const __loadedLocales = new Set(['${s}'])
209
+ const [__currentLocale, __setCurrentLocale] = createSignal('${c}')
210
+ const __loadedLocales = new Set(['${c}'])
211
211
  const [__loading, __setLoading] = createSignal(false)
212
212
  const __cache = new Map()
213
213
  const __loadedRoutes = new Set()
214
214
  const __normalizeMessages = (mod) => mod.default ?? mod
215
215
 
216
216
  const __loaders = {
217
- ${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
217
+ ${d.map(e=>` '${e}': () => import('${l}/${e}.js'),`).join(`
218
218
  `)}
219
219
  }
220
220
 
@@ -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
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
265
+ globalThis[Symbol.for('${u}')] = { __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 K(e){let t=(e.includes(`/`)?e.slice(e.lastIndexOf(`/`)+1):e).replace(/\.[^.]+$/,``);return t.replace(/-[a-zA-Z0-9]{4,}$/,``)||t}function q(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 J(e,t){let r=[],i=[];for(let a of e){let e=(0,n.hashMessage)(a),o=t.get(e);o&&(r.push(o),i.push(` '${se(a)}': _${e},`))}return i.length>0&&r.push(``,`export default {`,...i,`}`),r.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 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,t){return`{ id: '${X(t?.id??(0,n.hashMessage)(e,t?.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(n){let r=n?.catalogDir??`src/locales/compiled`,i=n?.framework??`auto`,l=n?.splitting??!1,u=n?.sourceLocale??`en`,d=n?.locales??[u],f=n?.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=V(e);if(t)return t}},load(e){if(e.startsWith(he))return`export { default } from '${`${r}/${e.slice(26)}.js`}'`;if(l){let t=H(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,n){if(n.includes(`node_modules`)||!n.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)||n.includes(`.vue`)&&!n.includes(`type=script`))return;let r=e,a=!1;if(n.match(/\.[jt]sx(\?|$)/)&&/<Trans[\s>]/.test(r)){let e=(0,t.transformTransComponents)(r);e.transformed&&(r=e.code,a=!0)}if(_e(r)){let e=i===`auto`?Y(n,r):i,a=(0,t.scopeTransform)(r,{framework:e,allowTopLevelImportedT:e===`vue`&&n.includes(`.vue`)});if(a.transformed)return{code:a.code,map:null}}return a?{code:r,map:null}:void 0}},_=new Map,v={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:ae(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=K(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=q(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})}}}},y={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}}},b=n?.devAutoCompile??!0,x=n?.include??[`src/**/*.{vue,tsx,jsx,ts,js}`];function S(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(`./`,``))})}return[m,h,y,g,v,{name:`fluenti:dev`,configureServer(e){if(!b)return;let n=(0,t.createDebouncedRunner)({cwd:e.config.root,onSuccess:()=>{}});n(),e.watcher.on(`change`,e=>{S(e,x)&&!e.includes(r)&&n()})},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)/.test(e)}module.exports=ge;
273
273
  //# sourceMappingURL=index.cjs.map