@fluenti/vite-plugin 0.5.0 → 0.6.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 (37) hide show
  1. package/dist/index.cjs +2 -2
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +176 -173
  4. package/dist/index.js.map +1 -1
  5. package/dist/sfc-transform.cjs +1 -1
  6. package/dist/sfc-transform.cjs.map +1 -1
  7. package/dist/sfc-transform.js +1 -1
  8. package/dist/sfc-transform.js.map +1 -1
  9. package/dist/vite-plugin/src/build-transform.d.ts.map +1 -0
  10. package/dist/vite-plugin/src/dev-runner.d.ts.map +1 -0
  11. package/dist/vite-plugin/src/index.d.ts.map +1 -0
  12. package/dist/vite-plugin/src/mode-detect.d.ts.map +1 -0
  13. package/dist/vite-plugin/src/runtime-template.d.ts +3 -0
  14. package/dist/vite-plugin/src/runtime-template.d.ts.map +1 -0
  15. package/dist/vite-plugin/src/sfc-transform.d.ts.map +1 -0
  16. package/dist/{types.d.ts → vite-plugin/src/types.d.ts} +2 -2
  17. package/dist/vite-plugin/src/types.d.ts.map +1 -0
  18. package/dist/vite-plugin/src/virtual-modules.d.ts.map +1 -0
  19. package/dist/vite-plugin/src/vt-transform.d.ts.map +1 -0
  20. package/package.json +2 -2
  21. package/dist/build-transform.d.ts.map +0 -1
  22. package/dist/dev-runner.d.ts.map +0 -1
  23. package/dist/index.d.ts.map +0 -1
  24. package/dist/mode-detect.d.ts.map +0 -1
  25. package/dist/runtime-template.d.ts +0 -3
  26. package/dist/runtime-template.d.ts.map +0 -1
  27. package/dist/sfc-transform.d.ts.map +0 -1
  28. package/dist/types.d.ts.map +0 -1
  29. package/dist/virtual-modules.d.ts.map +0 -1
  30. package/dist/vt-transform.d.ts.map +0 -1
  31. /package/dist/{build-transform.d.ts → vite-plugin/src/build-transform.d.ts} +0 -0
  32. /package/dist/{dev-runner.d.ts → vite-plugin/src/dev-runner.d.ts} +0 -0
  33. /package/dist/{index.d.ts → vite-plugin/src/index.d.ts} +0 -0
  34. /package/dist/{mode-detect.d.ts → vite-plugin/src/mode-detect.d.ts} +0 -0
  35. /package/dist/{sfc-transform.d.ts → vite-plugin/src/sfc-transform.d.ts} +0 -0
  36. /package/dist/{virtual-modules.d.ts → vite-plugin/src/virtual-modules.d.ts} +0 -0
  37. /package/dist/{vt-transform.d.ts → vite-plugin/src/vt-transform.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,39 +1,40 @@
1
1
  import { createFilter as e } from "vite";
2
- import { hashMessage as t, resolveLocaleCodes as n } from "@fluenti/core/internal";
3
- import { createRequire as r } from "node:module";
4
- import { join as i, resolve as a } from "node:path";
5
- import { existsSync as o, mkdirSync as s } from "node:fs";
6
- import { createRuntimeGenerator as c, createTransformPipeline as l, hasScopeTransformCandidate as u, parseSourceModule as d, walkSourceAst as f } from "@fluenti/core/transform";
7
- import { validateLocale as p } from "@fluenti/core";
2
+ import { hashMessage as t, resolveLocaleCodes as n } from "@fluenti/core/compiler";
3
+ import { DEFAULT_FLUENTI_CONFIG as r, loadConfigSync as i } from "@fluenti/core/config";
4
+ import { join as a, resolve as o } from "node:path";
5
+ import { createRequire as s } from "node:module";
6
+ import { existsSync as c, mkdirSync as l } from "node:fs";
7
+ import { createRuntimeGenerator as u, createTransformPipeline as ee, hasScopeTransformCandidate as d, parseSourceModule as f, walkSourceAst as p } from "@fluenti/core/transform";
8
+ import { validateLocale as m } from "@fluenti/core";
8
9
  //#region src/mode-detect.ts
9
- var m = "dev";
10
- function h(e) {
11
- m = e === "build" ? "build" : "dev";
12
- }
10
+ var h = "dev";
13
11
  function g(e) {
12
+ h = e === "build" ? "build" : "dev";
13
+ }
14
+ function _(e) {
14
15
  if (typeof e == "object" && e && "environment" in e) {
15
16
  let t = e.environment;
16
17
  if (typeof t == "object" && t) return t;
17
18
  }
18
19
  }
19
- function _(e) {
20
- return e?.mode === "build" || m === "build" || process.env.NODE_ENV === "production";
20
+ function v(e) {
21
+ return e?.mode === "build" || h === "build" || process.env.NODE_ENV === "production";
21
22
  }
22
23
  //#endregion
23
24
  //#region src/dev-runner.ts
24
- async function v(e) {
25
+ async function y(e) {
25
26
  try {
26
- let { DEFAULT_FLUENTI_CONFIG: t, loadConfigSync: n } = r(i(e.cwd, "package.json"))("@fluenti/core/config"), o;
27
+ let { DEFAULT_FLUENTI_CONFIG: t, loadConfigSync: n } = s(a(e.cwd, "package.json"))("@fluenti/core/config"), r;
27
28
  try {
28
- o = n(void 0, e.cwd);
29
+ r = n(void 0, e.cwd);
29
30
  } catch {
30
- o = t;
31
+ r = t;
31
32
  }
32
- s(a(e.cwd, o.compileOutDir), { recursive: !0 }), s(a(e.cwd, o.catalogDir), { recursive: !0 });
33
+ l(o(e.cwd, r.compileOutDir), { recursive: !0 }), l(o(e.cwd, r.catalogDir), { recursive: !0 });
33
34
  } catch {}
34
35
  if (!(e.onBeforeCompile && await e.onBeforeCompile() === !1)) {
35
36
  if (e.compileOnly) try {
36
- let { runCompile: t } = r(i(e.cwd, "package.json"))("@fluenti/cli");
37
+ let { runCompile: t } = s(a(e.cwd, "package.json"))("@fluenti/cli");
37
38
  await t(e.cwd), console.log("[fluenti] Compiling... done"), e.onAfterCompile && await e.onAfterCompile(), e.onSuccess?.();
38
39
  return;
39
40
  } catch (t) {
@@ -43,7 +44,7 @@ async function v(e) {
43
44
  return;
44
45
  }
45
46
  try {
46
- let { runExtract: t, runCompile: n } = r(i(e.cwd, "package.json"))("@fluenti/cli");
47
+ let { runExtract: t, runCompile: n } = s(a(e.cwd, "package.json"))("@fluenti/cli");
47
48
  await t(e.cwd), await n(e.cwd, { parallel: e.parallelCompile }), console.log("[fluenti] Extracting and compiling... done"), e.onAfterCompile && await e.onAfterCompile(), e.onSuccess?.();
48
49
  return;
49
50
  } catch (t) {
@@ -59,12 +60,12 @@ async function v(e) {
59
60
  }
60
61
  }
61
62
  }
62
- function ee(e, t = 300) {
63
+ function b(e, t = 300) {
63
64
  let n = null, r = !1, i = !1;
64
65
  async function a() {
65
66
  r = !0;
66
67
  try {
67
- await v(e);
68
+ await y(e);
68
69
  } finally {
69
70
  r = !1, i && (i = !1, o());
70
71
  }
@@ -78,27 +79,27 @@ function ee(e, t = 300) {
78
79
  }
79
80
  //#endregion
80
81
  //#region src/build-transform.ts
81
- function y(e, t) {
82
- return b(e, "dynamic", t);
82
+ function x(e, t) {
83
+ return C(e, "dynamic", t);
83
84
  }
84
- function te(e, t) {
85
- return b(e, "static", t);
85
+ function S(e, t) {
86
+ return C(e, "static", t);
86
87
  }
87
- function b(e, n, r) {
88
- let i = r?.hashFn ?? t, a = d(e);
88
+ function C(e, n, r) {
89
+ let i = r?.hashFn ?? t, a = f(e);
89
90
  if (!a || a.type !== "Program") return {
90
91
  code: e,
91
92
  needsCatalogImport: !1,
92
93
  usedHashes: /* @__PURE__ */ new Set()
93
94
  };
94
- let o = x(a), s = [], c = /* @__PURE__ */ new Set();
95
- if (f(a, (t) => {
96
- let r = ne(e, t, o, n, c, i);
95
+ let o = w(a), s = [], c = /* @__PURE__ */ new Set();
96
+ if (p(a, (t) => {
97
+ let r = E(e, t, o, n, c, i);
97
98
  if (r) {
98
99
  s.push(r);
99
100
  return;
100
101
  }
101
- ie(t, c, i);
102
+ k(t, c, i);
102
103
  }), s.length === 0) return {
103
104
  code: e,
104
105
  needsCatalogImport: !1,
@@ -115,32 +116,32 @@ function b(e, n, r) {
115
116
  usedHashes: c
116
117
  };
117
118
  }
118
- function x(e) {
119
+ function w(e) {
119
120
  let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
120
- for (let t of e.body) if (P(t)) for (let e of t.specifiers) {
121
- if (!F(e)) continue;
122
- let t = G(e);
121
+ for (let t of e.body) if (L(t)) for (let e of t.specifiers) {
122
+ if (!R(e)) continue;
123
+ let t = oe(e);
123
124
  t && (t === "useI18n" && n.add(e.local.name), t === "getI18n" && r.add(e.local.name), t === "unref" && i.add(e.local.name));
124
125
  }
125
- return f(e, (e) => {
126
- if (!I(e) || !e.init || !L(e.id)) return;
127
- if (B(e.init) && H(e.init.callee) && n.has(e.init.callee.name)) {
128
- S(e.id, t);
126
+ return p(e, (e) => {
127
+ if (!z(e) || !e.init || !B(e.id)) return;
128
+ if (U(e.init) && G(e.init.callee) && n.has(e.init.callee.name)) {
129
+ T(e.id, t);
129
130
  return;
130
131
  }
131
132
  let i = e.init.type === "AwaitExpression" ? e.init.argument : null;
132
- i && B(i) && H(i.callee) && r.has(i.callee.name) && S(e.id, t);
133
+ i && U(i) && G(i.callee) && r.has(i.callee.name) && T(e.id, t);
133
134
  }), {
134
135
  tracked: t,
135
136
  unref: i
136
137
  };
137
138
  }
138
- function S(e, t) {
139
- for (let n of e.properties) !z(n) || n.computed || !H(n.key) || n.key.name !== "t" || H(n.value) && t.add(n.value.name);
139
+ function T(e, t) {
140
+ for (let n of e.properties) !H(n) || n.computed || !G(n.key) || n.key.name !== "t" || G(n.value) && t.add(n.value.name);
140
141
  }
141
- function ne(e, t, n, r, i, a) {
142
- if (!B(t) || t.start == null || t.end == null) return;
143
- let o = C(e, t, n, a);
142
+ function E(e, t, n, r, i, a) {
143
+ if (!U(t) || t.start == null || t.end == null) return;
144
+ let o = D(e, t, n, a);
144
145
  if (!o) return;
145
146
  let { catalogId: s } = o;
146
147
  i.add(s);
@@ -151,11 +152,11 @@ function ne(e, t, n, r, i, a) {
151
152
  replacement: u
152
153
  };
153
154
  }
154
- function C(e, t, n, r) {
155
+ function D(e, t, n, r) {
155
156
  if (t.arguments.length === 0) return;
156
- let i = t.callee, a = H(i) && (n.tracked.has(i.name) || i.name === "$t"), o = V(i) && !i.computed && H(i.property) && (i.property.name === "$t" || i.property.name === "t" && H(i.object) && (i.object.name === "_ctx" || i.object.name === "$setup")), s = B(i) && H(i.callee) && n.unref.has(i.callee.name) && i.arguments.length === 1 && H(i.arguments[0]) && n.tracked.has(i.arguments[0].name);
157
+ let i = t.callee, a = G(i) && (n.tracked.has(i.name) || i.name === "$t"), o = W(i) && !i.computed && G(i.property) && (i.property.name === "$t" || i.property.name === "t" && G(i.object) && (i.object.name === "_ctx" || i.object.name === "$setup")), s = U(i) && G(i.callee) && n.unref.has(i.callee.name) && i.arguments.length === 1 && G(i.arguments[0]) && n.tracked.has(i.arguments[0].name);
157
158
  if (!a && !o && !s) return;
158
- let c = re(t.arguments[0], r);
159
+ let c = O(t.arguments[0], r);
159
160
  if (!c) return;
160
161
  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;
161
162
  return l === void 0 ? { catalogId: c } : {
@@ -163,69 +164,69 @@ function C(e, t, n, r) {
163
164
  valuesSource: l
164
165
  };
165
166
  }
166
- function re(e, t) {
167
- let n = M(e);
167
+ function O(e, t) {
168
+ let n = F(e);
168
169
  if (n !== void 0) return t(n);
169
- if (!R(e)) return;
170
+ if (!V(e)) return;
170
171
  let r, i, a;
171
172
  for (let t of e.properties) {
172
- if (!z(t) || t.computed) continue;
173
- let e = N(t.key);
173
+ if (!H(t) || t.computed) continue;
174
+ let e = I(t.key);
174
175
  if (!e) continue;
175
- let n = M(t.value);
176
+ let n = F(t.value);
176
177
  n !== void 0 && (e === "id" && (r = n), e === "message" && (i = n), e === "context" && (a = n));
177
178
  }
178
179
  if (r) return r;
179
180
  if (i) return t(i, a);
180
181
  }
181
- function ie(e, t, n) {
182
- if (!U(e)) return;
183
- let r = oe(e.openingElement.name);
182
+ function k(e, t, n) {
183
+ if (!K(e)) return;
184
+ let r = P(e.openingElement.name);
184
185
  if (r) {
185
186
  if (r === "Trans") {
186
- let r = k(e.openingElement, "__id") ?? k(e.openingElement, "id");
187
+ let r = j(e.openingElement, "__id") ?? j(e.openingElement, "id");
187
188
  if (r) {
188
189
  t.add(r);
189
190
  return;
190
191
  }
191
- let i = k(e.openingElement, "__message"), a = k(e.openingElement, "context");
192
+ let i = j(e.openingElement, "__message"), a = j(e.openingElement, "context");
192
193
  i && t.add(n(i, a));
193
194
  return;
194
195
  }
195
196
  if (r === "Plural") {
196
- let r = w(e.openingElement, n);
197
+ let r = A(e.openingElement, n);
197
198
  r && t.add(r);
198
199
  return;
199
200
  }
200
201
  if (r === "Select") {
201
- let r = T(e.openingElement, n);
202
+ let r = te(e.openingElement, n);
202
203
  r && t.add(r);
203
204
  }
204
205
  }
205
206
  }
206
- function w(e, t) {
207
- let n = k(e, "id");
207
+ function A(e, t) {
208
+ let n = j(e, "id");
208
209
  if (n) return n;
209
- let r = k(e, "context"), i = ae(e, "offset"), a = [
210
- k(e, "zero") === void 0 ? void 0 : `=0 {${k(e, "zero")}}`,
211
- k(e, "one") === void 0 ? void 0 : `one {${k(e, "one")}}`,
212
- k(e, "two") === void 0 ? void 0 : `two {${k(e, "two")}}`,
213
- k(e, "few") === void 0 ? void 0 : `few {${k(e, "few")}}`,
214
- k(e, "many") === void 0 ? void 0 : `many {${k(e, "many")}}`,
215
- k(e, "other") === void 0 ? void 0 : `other {${k(e, "other")}}`
210
+ let r = j(e, "context"), i = ae(e, "offset"), a = [
211
+ j(e, "zero") === void 0 ? void 0 : `=0 {${j(e, "zero")}}`,
212
+ j(e, "one") === void 0 ? void 0 : `one {${j(e, "one")}}`,
213
+ j(e, "two") === void 0 ? void 0 : `two {${j(e, "two")}}`,
214
+ j(e, "few") === void 0 ? void 0 : `few {${j(e, "few")}}`,
215
+ j(e, "many") === void 0 ? void 0 : `many {${j(e, "many")}}`,
216
+ j(e, "other") === void 0 ? void 0 : `other {${j(e, "other")}}`
216
217
  ].filter(Boolean);
217
218
  if (a.length !== 0) return t(`{count, plural,${typeof i == "number" ? ` offset:${i}` : ""} ${a.join(" ")}}`, r);
218
219
  }
219
- function T(e, t) {
220
- let n = k(e, "id");
220
+ function te(e, t) {
221
+ let n = j(e, "id");
221
222
  if (n) return n;
222
- let r = k(e, "context"), i = E(e);
223
+ let r = j(e, "context"), i = ne(e);
223
224
  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);
224
225
  }
225
- function E(e) {
226
- let t = O(e, "options");
226
+ function ne(e) {
227
+ let t = ie(e, "options");
227
228
  if (t) {
228
- let n = k(e, "other");
229
+ let n = j(e, "other");
229
230
  return {
230
231
  ...t,
231
232
  ...n === void 0 ? {} : { other: n }
@@ -233,7 +234,7 @@ function E(e) {
233
234
  }
234
235
  let n = {};
235
236
  for (let t of e.attributes) {
236
- if (!W(t)) continue;
237
+ if (!q(t)) continue;
237
238
  let e = t.name.name;
238
239
  if ([
239
240
  "value",
@@ -242,132 +243,132 @@ function E(e) {
242
243
  "comment",
243
244
  "options"
244
245
  ].includes(e)) continue;
245
- let r = j(t);
246
+ let r = N(t);
246
247
  r !== void 0 && (n[e] = r);
247
248
  }
248
249
  return Object.keys(n).length > 0 ? n : void 0;
249
250
  }
250
- function D(e) {
251
- if (!R(e)) return;
251
+ function re(e) {
252
+ if (!V(e)) return;
252
253
  let t = {};
253
254
  for (let n of e.properties) {
254
- if (!z(n) || n.computed) return;
255
- let e = N(n.key), r = M(n.value);
255
+ if (!H(n) || n.computed) return;
256
+ let e = I(n.key), r = F(n.value);
256
257
  if (!e || r === void 0) return;
257
258
  t[e] = r;
258
259
  }
259
260
  return t;
260
261
  }
261
- function O(e, t) {
262
- let n = A(e, t);
263
- if (n?.value && n.value.type === "JSXExpressionContainer") return D(n.value.expression);
262
+ function ie(e, t) {
263
+ let n = M(e, t);
264
+ if (n?.value && n.value.type === "JSXExpressionContainer") return re(n.value.expression);
264
265
  }
265
- function k(e, t) {
266
- return j(A(e, t));
266
+ function j(e, t) {
267
+ return N(M(e, t));
267
268
  }
268
269
  function ae(e, t) {
269
- let n = A(e, t);
270
+ let n = M(e, t);
270
271
  if (!n?.value || n.value.type !== "JSXExpressionContainer") return;
271
272
  let r = n.value.expression;
272
273
  return r.type === "NumericLiteral" ? r.value : void 0;
273
274
  }
274
- function A(e, t) {
275
- return e.attributes.find((e) => W(e) && e.name.name === t);
275
+ function M(e, t) {
276
+ return e.attributes.find((e) => q(e) && e.name.name === t);
276
277
  }
277
- function j(e) {
278
+ function N(e) {
278
279
  if (e?.value) {
279
280
  if (e.value.type === "StringLiteral") return e.value.value;
280
- if (e.value.type === "JSXExpressionContainer") return M(e.value.expression);
281
+ if (e.value.type === "JSXExpressionContainer") return F(e.value.expression);
281
282
  }
282
283
  }
283
- function oe(e) {
284
+ function P(e) {
284
285
  return e.type === "JSXIdentifier" ? e.name : void 0;
285
286
  }
286
- function M(e) {
287
+ function F(e) {
287
288
  if (e.type === "StringLiteral") return e.value;
288
289
  if (e.type === "TemplateLiteral") {
289
290
  let t = e;
290
291
  if (t.expressions.length === 0 && t.quasis.length === 1) return t.quasis[0].value.cooked ?? t.quasis[0].value.raw;
291
292
  }
292
293
  }
293
- function N(e) {
294
- if (H(e)) return e.name;
294
+ function I(e) {
295
+ if (G(e)) return e.name;
295
296
  if (e.type === "StringLiteral") return e.value;
296
297
  }
297
- function P(e) {
298
+ function L(e) {
298
299
  return e.type === "ImportDeclaration";
299
300
  }
300
- function F(e) {
301
+ function R(e) {
301
302
  return e.type === "ImportSpecifier";
302
303
  }
303
- function I(e) {
304
+ function z(e) {
304
305
  return e.type === "VariableDeclarator";
305
306
  }
306
- function L(e) {
307
+ function B(e) {
307
308
  return e.type === "ObjectPattern";
308
309
  }
309
- function R(e) {
310
+ function V(e) {
310
311
  return e.type === "ObjectExpression";
311
312
  }
312
- function z(e) {
313
+ function H(e) {
313
314
  return e.type === "ObjectProperty";
314
315
  }
315
- function B(e) {
316
+ function U(e) {
316
317
  return e.type === "CallExpression";
317
318
  }
318
- function V(e) {
319
+ function W(e) {
319
320
  return e.type === "MemberExpression";
320
321
  }
321
- function H(e) {
322
+ function G(e) {
322
323
  return e?.type === "Identifier";
323
324
  }
324
- function U(e) {
325
+ function K(e) {
325
326
  return e.type === "JSXElement";
326
327
  }
327
- function W(e) {
328
+ function q(e) {
328
329
  return e.type === "JSXAttribute";
329
330
  }
330
- function G(e) {
331
+ function oe(e) {
331
332
  let t = e.imported;
332
333
  if (t.type === "Identifier") return t.name;
333
334
  if (t.type === "StringLiteral") return t.value;
334
335
  }
335
- function K(e, n, r, i) {
336
+ function se(e, n, r, i) {
336
337
  if (n === "dynamic") return `import { __catalog } from 'virtual:fluenti/runtime';\n${e}`;
337
338
  let a = i ?? t;
338
339
  return `import { ${[...r].map((e) => `_${a(e)}`).join(", ")} } from 'virtual:fluenti/messages';\n${e}`;
339
340
  }
340
341
  //#endregion
341
342
  //#region src/virtual-modules.ts
342
- function se(e) {
343
+ function ce(e) {
343
344
  return JSON.stringify(e);
344
345
  }
345
- function q(e) {
346
+ function J(e) {
346
347
  if (e.includes("`") || e.includes("$")) throw Error(`[fluenti] vite-plugin: catalogDir must not contain backticks or $ characters, got ${JSON.stringify(e)}`);
347
348
  }
348
- var ce = "virtual:fluenti/runtime", le = "virtual:fluenti/messages", J = "\0virtual:fluenti/runtime", Y = "\0virtual:fluenti/messages";
349
- function X(e) {
350
- if (e === ce) return J;
349
+ var le = "virtual:fluenti/runtime", ue = "virtual:fluenti/messages", Y = "\0virtual:fluenti/runtime", X = "\0virtual:fluenti/messages";
350
+ function Z(e) {
351
351
  if (e === le) return Y;
352
+ if (e === ue) return X;
352
353
  }
353
- function Z(e, t) {
354
- if (e === J) return ue(t);
354
+ function Q(e, t) {
355
355
  if (e === Y) return de(t);
356
+ if (e === X) return fe(t);
356
357
  }
357
- function ue(e) {
358
+ function de(e) {
358
359
  let { locales: t, runtimeGenerator: n, catalogDir: r } = e;
359
- q(r);
360
- for (let e of t) p(e, "vite-plugin");
360
+ J(r);
361
+ for (let e of t) m(e, "vite-plugin");
361
362
  if (!n) throw Error("[fluenti] vite-plugin: runtimeGenerator is required. Use a framework-specific plugin (e.g. @fluenti/vue/vite-plugin).");
362
- return n.generateRuntime(fe(e));
363
- }
364
- function de(e) {
365
- let { rootDir: t, catalogDir: n, catalogExtension: r, defaultBuildLocale: i, sourceLocale: s } = e, c = i || s;
366
- p(c, "vite-plugin"), q(n);
367
- let l = a(a(t, n), c + r);
368
- return o(l) || console.warn(`[fluenti] Compiled catalog for locale "${c}" not found at ${l}. Run "fluenti compile" first.`), `export * from ${se(l)}\n`;
363
+ return n.generateRuntime(pe(e));
369
364
  }
370
365
  function fe(e) {
366
+ let { rootDir: t, catalogDir: n, catalogExtension: r, defaultBuildLocale: i, sourceLocale: a } = e, s = i || a;
367
+ m(s, "vite-plugin"), J(n);
368
+ let l = o(o(t, n), s + r);
369
+ return c(l) || console.warn(`[fluenti] Compiled catalog for locale "${s}" not found at ${l}. Run "fluenti compile" first.`), `export * from ${ce(l)}\n`;
370
+ }
371
+ function pe(e) {
371
372
  let { rootDir: t, catalogDir: n, catalogExtension: r, locales: i, sourceLocale: a, defaultBuildLocale: o } = e;
372
373
  return {
373
374
  rootDir: t,
@@ -380,26 +381,21 @@ function fe(e) {
380
381
  }
381
382
  //#endregion
382
383
  //#region src/index.ts
383
- var Q = r(typeof __filename < "u" ? __filename : import.meta.url), pe = "virtual:fluenti/messages/", me = "\0virtual:fluenti/messages/";
384
+ var me = "virtual:fluenti/messages/", he = "\0virtual:fluenti/messages/";
384
385
  function $(e, t) {
385
- if (typeof e == "object") {
386
- let { DEFAULT_FLUENTI_CONFIG: t } = Q("@fluenti/core/config");
387
- return {
388
- ...t,
389
- ...e
390
- };
391
- }
392
- let { loadConfigSync: n } = Q("@fluenti/core/config");
393
- return n(typeof e == "string" ? e : void 0, t);
386
+ return typeof e == "object" ? {
387
+ ...r,
388
+ ...e
389
+ } : i(typeof e == "string" ? e : void 0, t);
394
390
  }
395
- function he(t, r, i) {
391
+ function ge(t, r, i) {
396
392
  let a, o = process.cwd();
397
393
  function s(e) {
398
394
  let n = e ?? o;
399
395
  return a ||= $(t.config, n), a;
400
396
  }
401
397
  let c = t.framework;
402
- function d(e) {
398
+ function l(e) {
403
399
  let t = s(e), r = t.compileOutDir.replace(/^\.\//, ""), i = t.catalogExtension ?? ".js", a = t.splitting ?? !1;
404
400
  a && a !== "dynamic" && a !== "static" && console.warn(`[fluenti] Invalid splitting value "${a}". Expected 'dynamic', 'static', or false. Falling back to 'dynamic'.`);
405
401
  let o = a === "static" ? "static" : a ? "dynamic" : !1, c = t.sourceLocale;
@@ -413,86 +409,93 @@ function he(t, r, i) {
413
409
  defaultBuildLocale: t.defaultBuildLocale ?? c
414
410
  };
415
411
  }
416
- let f = {
412
+ let u = {
417
413
  name: "fluenti:virtual",
418
414
  configResolved(e) {
419
- o = e.root, a = $(t.config, o), h(e.command);
415
+ o = e.root, a = $(t.config, o), g(e.command);
420
416
  },
421
417
  resolveId(e) {
422
- if (e.startsWith(pe)) return "\0" + e;
423
- let { splitting: t } = d();
418
+ if (e.startsWith(me)) return "\0" + e;
419
+ let { splitting: t } = l();
424
420
  if (t) {
425
- let t = X(e);
421
+ let t = Z(e);
426
422
  if (t) return t;
427
423
  }
428
424
  },
429
425
  load(e) {
430
- let { catalogDir: t, catalogExtension: n, splitting: r, localeCodes: a, sourceLocale: s, defaultBuildLocale: l } = d();
431
- if (e.startsWith(me)) {
426
+ let { catalogDir: t, catalogExtension: n, splitting: r, localeCodes: a, sourceLocale: s, defaultBuildLocale: u } = l();
427
+ if (e.startsWith(he)) {
432
428
  let r = e.slice(26);
433
429
  return a.includes(r) ? `export { default } from '${`${t}/${r}${n}`}'` : void 0;
434
430
  }
435
431
  if (r) {
436
- let r = Z(e, {
432
+ let r = Q(e, {
437
433
  rootDir: o,
438
434
  catalogDir: t,
439
435
  catalogExtension: n,
440
436
  locales: a,
441
437
  sourceLocale: s,
442
- defaultBuildLocale: l,
438
+ defaultBuildLocale: u,
443
439
  framework: c,
444
440
  runtimeGenerator: i
445
441
  });
446
442
  if (r) return r;
447
443
  }
448
444
  }
449
- }, p = l({ framework: c }), m = {
445
+ }, f = ee({ framework: c }), p = {
450
446
  name: "fluenti:script-transform",
451
447
  enforce: "pre",
452
448
  transform(e, t) {
453
449
  if (t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/) || t.includes(".vue") && !t.includes("type=script")) return;
454
- let n = c === "vue" && t.includes(".vue"), r = e, i = !1;
455
- if (t.match(/\.[jt]sx(\?|$)/) && /<Trans[\s>]/.test(r)) {
456
- let e = p.transformTrans(r);
457
- e.transformed && (r = e.code, i = !0);
450
+ let n = c === "vue" && t.includes(".vue"), r = `@fluenti/${c}/components`, i = e, a = !1;
451
+ if (t.match(/\.[jt]sx(\?|$)/) && /<Trans[\s>]/.test(i)) {
452
+ let e = f.transformTrans(i);
453
+ e.transformed && (i = e.code, a = !0);
454
+ }
455
+ if (t.match(/\.[jt]sx(\?|$)/) && (c === "react" || c === "solid") && /<(Plural|Select)[\s/>]/.test(i)) {
456
+ let e = f.transformPluralSelect(i, r);
457
+ e.transformed && (i = e.code, a = !0);
458
458
  }
459
- if (u(r)) {
460
- let e = p.transformScope(r, n ? { allowTopLevelImportedT: !0 } : void 0);
459
+ if (d(i)) {
460
+ let e = f.transformScope(i, {
461
+ componentModuleImport: r,
462
+ ...n ? { allowTopLevelImportedT: !0 } : {}
463
+ });
461
464
  if (e.transformed) return {
462
465
  code: e.code,
463
466
  map: null
464
467
  };
465
468
  }
466
- return i ? {
467
- code: r,
469
+ return a ? {
470
+ code: i,
468
471
  map: null
469
472
  } : void 0;
470
473
  }
471
- }, b = {
474
+ }, m = {
472
475
  name: "fluenti:build-split",
473
476
  transform(e, t) {
474
- let { splitting: n, config: r } = d();
475
- if (!n || !_(g(this)) || t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)) return;
476
- let i = n === "static" ? "static" : "dynamic", a = r.idGenerator ? { hashFn: r.idGenerator } : void 0, o = i === "static" ? te(e, a) : y(e, a);
477
+ let { splitting: n, config: r } = l();
478
+ if (!n || !v(_(this)) || t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)) return;
479
+ let i = n === "static" ? "static" : "dynamic", a = r.idGenerator ? { hashFn: r.idGenerator } : void 0, o = i === "static" ? S(e, a) : x(e, a);
477
480
  if (o.needsCatalogImport) return {
478
- code: K(o.code, i, o.usedHashes, r.idGenerator),
481
+ code: se(o.code, i, o.usedHashes, r.idGenerator),
479
482
  map: null
480
483
  };
481
484
  }
482
- }, x = {
485
+ }, h = {
483
486
  name: "fluenti:build-compile",
484
487
  async buildStart() {
485
- let { config: e } = d();
486
- _(g(this)) && (e.buildAutoCompile ?? !0) && (e.onBeforeCompile && await e.onBeforeCompile() === !1 || (await v({
488
+ let { config: e } = l();
489
+ v(_(this)) && (e.buildAutoCompile ?? !0) && (e.onBeforeCompile && await e.onBeforeCompile() === !1 || (await y({
487
490
  cwd: o,
488
491
  throwOnError: !0,
489
492
  compileOnly: !0
490
493
  }), e.onAfterCompile && await e.onAfterCompile()));
491
494
  }
492
- }, S = {
495
+ }, C = {
493
496
  name: "fluenti:dev",
494
497
  configureServer(t) {
495
- let { config: n, catalogDir: r } = d(t.config.root);
498
+ let { config: n, catalogDir: r } = l(t.config.root);
496
499
  if (!(n.devAutoCompile ?? !0)) return;
497
500
  let i = e(n.include ?? ["src/**/*.{vue,tsx,jsx,ts,js}"], [
498
501
  ...n.exclude ?? [],
@@ -503,13 +506,13 @@ function he(t, r, i) {
503
506
  onSuccess: () => {}
504
507
  };
505
508
  n.parallelCompile && (a.parallelCompile = !0), n.onBeforeCompile && (a.onBeforeCompile = n.onBeforeCompile), n.onAfterCompile && (a.onAfterCompile = n.onAfterCompile);
506
- let o = ee(a, n.devAutoCompileDelay ?? 500);
509
+ let o = b(a, n.devAutoCompileDelay ?? 500);
507
510
  o(), t.watcher.on("change", (e) => {
508
511
  i(e) && o();
509
512
  });
510
513
  },
511
514
  hotUpdate({ file: e }) {
512
- let { catalogDir: t } = d();
515
+ let { catalogDir: t } = l();
513
516
  if (e.includes(t)) {
514
517
  let e = [...this.environment.moduleGraph.urlToModuleMap.entries()].filter(([e]) => e.includes("virtual:fluenti")).map(([, e]) => e);
515
518
  if (e.length > 0) return e;
@@ -517,15 +520,15 @@ function he(t, r, i) {
517
520
  }
518
521
  };
519
522
  return [
520
- f,
523
+ u,
521
524
  ...r,
525
+ p,
526
+ h,
522
527
  m,
523
- x,
524
- b,
525
- S
528
+ C
526
529
  ];
527
530
  }
528
531
  //#endregion
529
- export { he as createFluentiPlugins, c as createRuntimeGenerator, g as getPluginEnvironment, _ as isBuildMode, Z as loadVirtualSplitModule, X as resolveVirtualSplitId, h as setResolvedMode };
532
+ export { ge as createFluentiPlugins, u as createRuntimeGenerator, _ as getPluginEnvironment, v as isBuildMode, Q as loadVirtualSplitModule, Z as resolveVirtualSplitId, g as setResolvedMode };
530
533
 
531
534
  //# sourceMappingURL=index.js.map