@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.js CHANGED
@@ -1,38 +1,38 @@
1
1
  import { resolve as e } from "node:path";
2
- import { hashMessage as t } from "@fluenti/core";
3
- import { parseSourceModule as n, scopeTransform as r, transformTransComponents as i, walkSourceAst as a } from "@fluenti/core/internal";
4
- import { readFileSync as o } from "node:fs";
2
+ import { createDebouncedRunner as t, parseSourceModule as n, scopeTransform as r, transformTransComponents as i, walkSourceAst as a } from "@fluenti/core/internal";
3
+ import { hashMessage as o, validateLocale as s } from "@fluenti/core";
4
+ import { readFileSync as c } from "node:fs";
5
5
  //#region src/mode-detect.ts
6
- var s = "dev";
7
- function c(e) {
8
- s = e === "build" ? "build" : "dev";
6
+ var l = "dev";
7
+ function u(e) {
8
+ l = e === "build" ? "build" : "dev";
9
9
  }
10
- function l(e) {
11
- return e?.mode === "build" || s === "build" || process.env.NODE_ENV === "production";
10
+ function d(e) {
11
+ return e?.mode === "build" || l === "build" || process.env.NODE_ENV === "production";
12
12
  }
13
13
  //#endregion
14
14
  //#region src/build-transform.ts
15
- function u(e) {
16
- return f(e, "dynamic");
15
+ function f(e) {
16
+ return m(e, "dynamic");
17
17
  }
18
- function d(e) {
19
- return f(e, "static");
18
+ function p(e) {
19
+ return m(e, "static");
20
20
  }
21
- function f(e, t) {
21
+ function m(e, t) {
22
22
  let r = n(e);
23
23
  if (!r || r.type !== "Program") return {
24
24
  code: e,
25
25
  needsCatalogImport: !1,
26
26
  usedHashes: /* @__PURE__ */ new Set()
27
27
  };
28
- let i = p(r), o = [], s = /* @__PURE__ */ new Set();
28
+ let i = h(r), o = [], s = /* @__PURE__ */ new Set();
29
29
  if (a(r, (n) => {
30
- let r = h(e, n, i, t, s);
30
+ let r = _(e, n, i, t, s);
31
31
  if (r) {
32
32
  o.push(r);
33
33
  return;
34
34
  }
35
- v(n, s);
35
+ b(n, s);
36
36
  }), o.length === 0) return {
37
37
  code: e,
38
38
  needsCatalogImport: !1,
@@ -49,47 +49,47 @@ function f(e, t) {
49
49
  usedHashes: s
50
50
  };
51
51
  }
52
- function p(e) {
52
+ function h(e) {
53
53
  let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
54
- for (let t of e.body) if (O(t)) for (let e of t.specifiers) {
54
+ for (let t of e.body) if (ne(t)) for (let e of t.specifiers) {
55
55
  if (!re(e)) continue;
56
- let t = I(e);
56
+ let t = oe(e);
57
57
  t && (t === "useI18n" && n.add(e.local.name), t === "getI18n" && r.add(e.local.name), t === "unref" && i.add(e.local.name));
58
58
  }
59
59
  return a(e, (e) => {
60
- if (!ie(e) || !e.init || !ae(e.id)) return;
61
- if (j(e.init) && N(e.init.callee) && n.has(e.init.callee.name)) {
62
- m(e.id, t);
60
+ if (!j(e) || !e.init || !M(e.id)) return;
61
+ if (F(e.init) && I(e.init.callee) && n.has(e.init.callee.name)) {
62
+ g(e.id, t);
63
63
  return;
64
64
  }
65
65
  let i = e.init.type === "AwaitExpression" ? e.init.argument : null;
66
- i && j(i) && N(i.callee) && r.has(i.callee.name) && m(e.id, t);
66
+ i && F(i) && I(i.callee) && r.has(i.callee.name) && g(e.id, t);
67
67
  }), {
68
68
  tracked: t,
69
69
  unref: i
70
70
  };
71
71
  }
72
- function m(e, t) {
73
- for (let n of e.properties) !A(n) || n.computed || !N(n.key) || n.key.name !== "t" || N(n.value) && t.add(n.value.name);
74
- }
75
- function h(e, n, r, i, a) {
76
- if (!j(n) || n.start == null || n.end == null) return;
77
- let o = g(e, n, r);
78
- if (!o) return;
79
- let { catalogId: s } = o;
80
- a.add(s);
81
- let c = t(s), l = i === "dynamic" ? `__catalog[${JSON.stringify(s)}]` : `_${c}`, u = o.valuesSource ? `${l}(${o.valuesSource})` : l;
72
+ function g(e, t) {
73
+ for (let n of e.properties) !P(n) || n.computed || !I(n.key) || n.key.name !== "t" || I(n.value) && t.add(n.value.name);
74
+ }
75
+ function _(e, t, n, r, i) {
76
+ if (!F(t) || t.start == null || t.end == null) return;
77
+ let a = v(e, t, n);
78
+ if (!a) return;
79
+ let { catalogId: s } = a;
80
+ i.add(s);
81
+ let c = o(s), l = r === "dynamic" ? `__catalog[${JSON.stringify(s)}]` : `_${c}`, u = a.valuesSource ? `${l}(${a.valuesSource})` : l;
82
82
  return {
83
- start: n.start,
84
- end: n.end,
83
+ start: t.start,
84
+ end: t.end,
85
85
  replacement: u
86
86
  };
87
87
  }
88
- function g(e, t, n) {
88
+ function v(e, t, n) {
89
89
  if (t.arguments.length === 0) return;
90
- let r = t.callee, i = N(r) && (n.tracked.has(r.name) || r.name === "$t"), a = M(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 = j(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);
90
+ let r = t.callee, i = I(r) && (n.tracked.has(r.name) || r.name === "$t"), a = ie(r) && !r.computed && I(r.property) && (r.property.name === "$t" || r.property.name === "t" && I(r.object) && (r.object.name === "_ctx" || r.object.name === "$setup")), o = F(r) && I(r.callee) && n.unref.has(r.callee.name) && r.arguments.length === 1 && I(r.arguments[0]) && n.tracked.has(r.arguments[0].name);
91
91
  if (!i && !a && !o) return;
92
- let s = _(t.arguments[0]);
92
+ let s = y(t.arguments[0]);
93
93
  if (!s) return;
94
94
  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;
95
95
  return c === void 0 ? { catalogId: s } : {
@@ -97,69 +97,69 @@ function g(e, t, n) {
97
97
  valuesSource: c
98
98
  };
99
99
  }
100
- function _(e) {
101
- let n = E(e);
102
- if (n !== void 0) return t(n);
103
- if (!k(e)) return;
104
- let r, i, a;
100
+ function y(e) {
101
+ let t = k(e);
102
+ if (t !== void 0) return o(t);
103
+ if (!N(e)) return;
104
+ let n, r, i;
105
105
  for (let t of e.properties) {
106
- if (!A(t) || t.computed) continue;
107
- let e = D(t.key);
106
+ if (!P(t) || t.computed) continue;
107
+ let e = A(t.key);
108
108
  if (!e) continue;
109
- let n = E(t.value);
110
- n !== void 0 && (e === "id" && (r = n), e === "message" && (i = n), e === "context" && (a = n));
109
+ let a = k(t.value);
110
+ a !== void 0 && (e === "id" && (n = a), e === "message" && (r = a), e === "context" && (i = a));
111
111
  }
112
- if (r) return r;
113
- if (i) return t(i, a);
114
- }
115
- function v(e, n) {
116
- if (!P(e)) return;
117
- let r = T(e.openingElement.name);
118
- if (r) {
119
- if (r === "Trans") {
120
- let r = S(e.openingElement, "__id") ?? S(e.openingElement, "id");
121
- if (r) {
122
- n.add(r);
112
+ if (n) return n;
113
+ if (r) return o(r, i);
114
+ }
115
+ function b(e, t) {
116
+ if (!ae(e)) return;
117
+ let n = O(e.openingElement.name);
118
+ if (n) {
119
+ if (n === "Trans") {
120
+ let n = T(e.openingElement, "__id") ?? T(e.openingElement, "id");
121
+ if (n) {
122
+ t.add(n);
123
123
  return;
124
124
  }
125
- let i = S(e.openingElement, "__message"), a = S(e.openingElement, "context");
126
- i && n.add(t(i, a));
125
+ let r = T(e.openingElement, "__message"), i = T(e.openingElement, "context");
126
+ r && t.add(o(r, i));
127
127
  return;
128
128
  }
129
- if (r === "Plural") {
130
- let t = ee(e.openingElement);
131
- t && n.add(t);
129
+ if (n === "Plural") {
130
+ let n = x(e.openingElement);
131
+ n && t.add(n);
132
132
  return;
133
133
  }
134
- if (r === "Select") {
135
- let t = te(e.openingElement);
136
- t && n.add(t);
134
+ if (n === "Select") {
135
+ let n = S(e.openingElement);
136
+ n && t.add(n);
137
137
  }
138
138
  }
139
139
  }
140
- function ee(e) {
141
- let n = S(e, "id");
142
- if (n) return n;
143
- let r = S(e, "context"), i = ne(e, "offset"), a = [
144
- S(e, "zero") === void 0 ? void 0 : `=0 {${S(e, "zero")}}`,
145
- S(e, "one") === void 0 ? void 0 : `one {${S(e, "one")}}`,
146
- S(e, "two") === void 0 ? void 0 : `two {${S(e, "two")}}`,
147
- S(e, "few") === void 0 ? void 0 : `few {${S(e, "few")}}`,
148
- S(e, "many") === void 0 ? void 0 : `many {${S(e, "many")}}`,
149
- S(e, "other") === void 0 ? void 0 : `other {${S(e, "other")}}`
140
+ function x(e) {
141
+ let t = T(e, "id");
142
+ if (t) return t;
143
+ let n = T(e, "context"), r = te(e, "offset"), i = [
144
+ T(e, "zero") === void 0 ? void 0 : `=0 {${T(e, "zero")}}`,
145
+ T(e, "one") === void 0 ? void 0 : `one {${T(e, "one")}}`,
146
+ T(e, "two") === void 0 ? void 0 : `two {${T(e, "two")}}`,
147
+ T(e, "few") === void 0 ? void 0 : `few {${T(e, "few")}}`,
148
+ T(e, "many") === void 0 ? void 0 : `many {${T(e, "many")}}`,
149
+ T(e, "other") === void 0 ? void 0 : `other {${T(e, "other")}}`
150
150
  ].filter(Boolean);
151
- if (a.length !== 0) return t(`{count, plural,${typeof i == "number" ? ` offset:${i}` : ""} ${a.join(" ")}}`, r);
151
+ if (i.length !== 0) return o(`{count, plural,${typeof r == "number" ? ` offset:${r}` : ""} ${i.join(" ")}}`, n);
152
152
  }
153
- function te(e) {
154
- let n = S(e, "id");
155
- if (n) return n;
156
- let r = S(e, "context"), i = y(e);
157
- 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);
153
+ function S(e) {
154
+ let t = T(e, "id");
155
+ if (t) return t;
156
+ let n = T(e, "context"), r = C(e);
157
+ if (!(!r || r.other === void 0)) return o(`{value, select, ${[...Object.keys(r).filter((e) => e !== "other").sort(), "other"].map((e) => `${e} {${r[e]}}`).join(" ")}}`, n);
158
158
  }
159
- function y(e) {
160
- let t = x(e, "options");
159
+ function C(e) {
160
+ let t = ee(e, "options");
161
161
  if (t) {
162
- let n = S(e, "other");
162
+ let n = T(e, "other");
163
163
  return {
164
164
  ...t,
165
165
  ...n === void 0 ? {} : { other: n }
@@ -167,7 +167,7 @@ function y(e) {
167
167
  }
168
168
  let n = {};
169
169
  for (let t of e.attributes) {
170
- if (!F(t)) continue;
170
+ if (!L(t)) continue;
171
171
  let e = t.name.name;
172
172
  if ([
173
173
  "value",
@@ -176,126 +176,128 @@ function y(e) {
176
176
  "comment",
177
177
  "options"
178
178
  ].includes(e)) continue;
179
- let r = w(t);
179
+ let r = D(t);
180
180
  r !== void 0 && (n[e] = r);
181
181
  }
182
182
  return Object.keys(n).length > 0 ? n : void 0;
183
183
  }
184
- function b(e) {
185
- if (!k(e)) return;
184
+ function w(e) {
185
+ if (!N(e)) return;
186
186
  let t = {};
187
187
  for (let n of e.properties) {
188
- if (!A(n) || n.computed) return;
189
- let e = D(n.key), r = E(n.value);
188
+ if (!P(n) || n.computed) return;
189
+ let e = A(n.key), r = k(n.value);
190
190
  if (!e || r === void 0) return;
191
191
  t[e] = r;
192
192
  }
193
193
  return t;
194
194
  }
195
- function x(e, t) {
196
- let n = C(e, t);
197
- if (n?.value && n.value.type === "JSXExpressionContainer") return b(n.value.expression);
195
+ function ee(e, t) {
196
+ let n = E(e, t);
197
+ if (n?.value && n.value.type === "JSXExpressionContainer") return w(n.value.expression);
198
198
  }
199
- function S(e, t) {
200
- return w(C(e, t));
199
+ function T(e, t) {
200
+ return D(E(e, t));
201
201
  }
202
- function ne(e, t) {
203
- let n = C(e, t);
202
+ function te(e, t) {
203
+ let n = E(e, t);
204
204
  if (!n?.value || n.value.type !== "JSXExpressionContainer") return;
205
205
  let r = n.value.expression;
206
206
  return r.type === "NumericLiteral" ? r.value : void 0;
207
207
  }
208
- function C(e, t) {
209
- return e.attributes.find((e) => F(e) && e.name.name === t);
208
+ function E(e, t) {
209
+ return e.attributes.find((e) => L(e) && e.name.name === t);
210
210
  }
211
- function w(e) {
211
+ function D(e) {
212
212
  if (e?.value) {
213
213
  if (e.value.type === "StringLiteral") return e.value.value;
214
- if (e.value.type === "JSXExpressionContainer") return E(e.value.expression);
214
+ if (e.value.type === "JSXExpressionContainer") return k(e.value.expression);
215
215
  }
216
216
  }
217
- function T(e) {
217
+ function O(e) {
218
218
  return e.type === "JSXIdentifier" ? e.name : void 0;
219
219
  }
220
- function E(e) {
220
+ function k(e) {
221
221
  if (e.type === "StringLiteral") return e.value;
222
222
  if (e.type === "TemplateLiteral") {
223
223
  let t = e;
224
224
  if (t.expressions.length === 0 && t.quasis.length === 1) return t.quasis[0].value.cooked ?? t.quasis[0].value.raw;
225
225
  }
226
226
  }
227
- function D(e) {
228
- if (N(e)) return e.name;
227
+ function A(e) {
228
+ if (I(e)) return e.name;
229
229
  if (e.type === "StringLiteral") return e.value;
230
230
  }
231
- function O(e) {
231
+ function ne(e) {
232
232
  return e.type === "ImportDeclaration";
233
233
  }
234
234
  function re(e) {
235
235
  return e.type === "ImportSpecifier";
236
236
  }
237
- function ie(e) {
237
+ function j(e) {
238
238
  return e.type === "VariableDeclarator";
239
239
  }
240
- function ae(e) {
240
+ function M(e) {
241
241
  return e.type === "ObjectPattern";
242
242
  }
243
- function k(e) {
243
+ function N(e) {
244
244
  return e.type === "ObjectExpression";
245
245
  }
246
- function A(e) {
246
+ function P(e) {
247
247
  return e.type === "ObjectProperty";
248
248
  }
249
- function j(e) {
249
+ function F(e) {
250
250
  return e.type === "CallExpression";
251
251
  }
252
- function M(e) {
252
+ function ie(e) {
253
253
  return e.type === "MemberExpression";
254
254
  }
255
- function N(e) {
255
+ function I(e) {
256
256
  return e?.type === "Identifier";
257
257
  }
258
- function P(e) {
258
+ function ae(e) {
259
259
  return e.type === "JSXElement";
260
260
  }
261
- function F(e) {
261
+ function L(e) {
262
262
  return e.type === "JSXAttribute";
263
263
  }
264
- function I(e) {
264
+ function oe(e) {
265
265
  let t = e.imported;
266
266
  if (t.type === "Identifier") return t.name;
267
267
  if (t.type === "StringLiteral") return t.value;
268
268
  }
269
- function L(e, n, r) {
270
- 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) => `_${t(e)}`).join(", ")} } from 'virtual:fluenti/messages';\n${e}`;
269
+ function R(e, t, n) {
270
+ 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) => `_${o(e)}`).join(", ")} } from 'virtual:fluenti/messages';\n${e}`;
271
271
  }
272
272
  //#endregion
273
273
  //#region src/virtual-modules.ts
274
- var R = "virtual:fluenti/runtime", z = "virtual:fluenti/messages", B = "virtual:fluenti/route-runtime", V = "\0virtual:fluenti/runtime", H = "\0virtual:fluenti/messages", U = "\0virtual:fluenti/route-runtime";
275
- function W(e) {
276
- if (e === R) return V;
274
+ var z = "virtual:fluenti/runtime", B = "virtual:fluenti/messages", V = "virtual:fluenti/route-runtime", H = "\0virtual:fluenti/runtime", U = "\0virtual:fluenti/messages", W = "\0virtual:fluenti/route-runtime";
275
+ function G(e) {
277
276
  if (e === z) return H;
278
277
  if (e === B) return U;
278
+ if (e === V) return W;
279
279
  }
280
- function G(e, t) {
281
- if (e === V) return K(t);
280
+ function K(e, t) {
282
281
  if (e === H) return q(t);
283
- if (e === U) return oe(t);
282
+ if (e === U) return se(t);
283
+ if (e === W) return ce(t);
284
284
  }
285
- function K(t) {
286
- let { catalogDir: n, locales: r, sourceLocale: i, defaultBuildLocale: a, framework: o } = t, s = a || i, c = e(process.cwd(), n), l = `fluenti.runtime.${o}`, u = r.filter((e) => e !== s);
285
+ function q(t) {
286
+ let { catalogDir: n, locales: r, sourceLocale: i, defaultBuildLocale: a, framework: o } = t;
287
+ for (let e of r) s(e, "vite-plugin");
288
+ let c = a || i, l = e(process.cwd(), n), u = `fluenti.runtime.${o}`, d = r.filter((e) => e !== c);
287
289
  return o === "react" ? `
288
- import __defaultMsgs from '${c}/${s}.js'
290
+ import __defaultMsgs from '${l}/${c}.js'
289
291
 
290
292
  const __catalog = { ...__defaultMsgs }
291
- let __currentLocale = '${s}'
292
- const __loadedLocales = new Set(['${s}'])
293
+ let __currentLocale = '${c}'
294
+ const __loadedLocales = new Set(['${c}'])
293
295
  let __loading = false
294
296
  const __cache = new Map()
295
297
  const __normalizeMessages = (mod) => mod.default ?? mod
296
298
 
297
299
  const __loaders = {
298
- ${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
300
+ ${d.map((e) => ` '${e}': () => import('${l}/${e}.js'),`).join("\n")}
299
301
  }
300
302
 
301
303
  async function __switchLocale(locale) {
@@ -322,25 +324,25 @@ async function __preloadLocale(locale) {
322
324
  const mod = __normalizeMessages(await __loaders[locale]())
323
325
  __cache.set(locale, mod)
324
326
  __loadedLocales.add(locale)
325
- } catch {}
327
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
326
328
  }
327
329
 
328
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
330
+ globalThis[Symbol.for('${u}')] = { __switchLocale, __preloadLocale }
329
331
 
330
332
  export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
331
333
  ` : o === "vue" ? `
332
334
  import { shallowReactive, triggerRef, ref } from 'vue'
333
- import __defaultMsgs from '${c}/${s}.js'
335
+ import __defaultMsgs from '${l}/${c}.js'
334
336
 
335
337
  const __catalog = shallowReactive({ ...__defaultMsgs })
336
- const __currentLocale = ref('${s}')
337
- const __loadedLocales = new Set(['${s}'])
338
+ const __currentLocale = ref('${c}')
339
+ const __loadedLocales = new Set(['${c}'])
338
340
  const __loading = ref(false)
339
341
  const __cache = new Map()
340
342
  const __normalizeMessages = (mod) => mod.default ?? mod
341
343
 
342
344
  const __loaders = {
343
- ${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
345
+ ${d.map((e) => ` '${e}': () => import('${l}/${e}.js'),`).join("\n")}
344
346
  }
345
347
 
346
348
  async function __switchLocale(locale) {
@@ -367,26 +369,26 @@ async function __preloadLocale(locale) {
367
369
  const mod = __normalizeMessages(await __loaders[locale]())
368
370
  __cache.set(locale, mod)
369
371
  __loadedLocales.add(locale)
370
- } catch {}
372
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
371
373
  }
372
374
 
373
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
375
+ globalThis[Symbol.for('${u}')] = { __switchLocale, __preloadLocale }
374
376
 
375
377
  export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
376
378
  ` : `
377
379
  import { createSignal } from 'solid-js'
378
380
  import { createStore, reconcile } from 'solid-js/store'
379
- import __defaultMsgs from '${c}/${s}.js'
381
+ import __defaultMsgs from '${l}/${c}.js'
380
382
 
381
383
  const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
382
- const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
383
- const __loadedLocales = new Set(['${s}'])
384
+ const [__currentLocale, __setCurrentLocale] = createSignal('${c}')
385
+ const __loadedLocales = new Set(['${c}'])
384
386
  const [__loading, __setLoading] = createSignal(false)
385
387
  const __cache = new Map()
386
388
  const __normalizeMessages = (mod) => mod.default ?? mod
387
389
 
388
390
  const __loaders = {
389
- ${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
391
+ ${d.map((e) => ` '${e}': () => import('${l}/${e}.js'),`).join("\n")}
390
392
  }
391
393
 
392
394
  async function __switchLocale(locale) {
@@ -413,34 +415,36 @@ async function __preloadLocale(locale) {
413
415
  const mod = __normalizeMessages(await __loaders[locale]())
414
416
  __cache.set(locale, mod)
415
417
  __loadedLocales.add(locale)
416
- } catch {}
418
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
417
419
  }
418
420
 
419
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
421
+ globalThis[Symbol.for('${u}')] = { __switchLocale, __preloadLocale }
420
422
 
421
423
  export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
422
424
  `;
423
425
  }
424
- function q(t) {
426
+ function se(t) {
425
427
  let { catalogDir: n, defaultBuildLocale: r, sourceLocale: i } = t, a = r || i;
426
428
  return `export * from '${e(process.cwd(), n)}/${a}.js'\n`;
427
429
  }
428
- function oe(t) {
429
- let { catalogDir: n, locales: r, sourceLocale: i, defaultBuildLocale: a, framework: o } = t, s = a || i, c = e(process.cwd(), n), l = `fluenti.runtime.${o}`, u = r.filter((e) => e !== s);
430
+ function ce(t) {
431
+ let { catalogDir: n, locales: r, sourceLocale: i, defaultBuildLocale: a, framework: o } = t;
432
+ for (let e of r) s(e, "vite-plugin");
433
+ let c = a || i, l = e(process.cwd(), n), u = `fluenti.runtime.${o}`, d = r.filter((e) => e !== c);
430
434
  return o === "vue" ? `
431
435
  import { shallowReactive, ref } from 'vue'
432
- import __defaultMsgs from '${c}/${s}.js'
436
+ import __defaultMsgs from '${l}/${c}.js'
433
437
 
434
438
  const __catalog = shallowReactive({ ...__defaultMsgs })
435
- const __currentLocale = ref('${s}')
436
- const __loadedLocales = new Set(['${s}'])
439
+ const __currentLocale = ref('${c}')
440
+ const __loadedLocales = new Set(['${c}'])
437
441
  const __loading = ref(false)
438
442
  const __cache = new Map()
439
443
  const __loadedRoutes = new Set()
440
444
  const __normalizeMessages = (mod) => mod.default ?? mod
441
445
 
442
446
  const __loaders = {
443
- ${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
447
+ ${d.map((e) => ` '${e}': () => import('${l}/${e}.js'),`).join("\n")}
444
448
  }
445
449
 
446
450
  const __routeLoaders = {}
@@ -484,27 +488,27 @@ async function __preloadLocale(locale) {
484
488
  const mod = __normalizeMessages(await __loaders[locale]())
485
489
  __cache.set(locale, mod)
486
490
  __loadedLocales.add(locale)
487
- } catch {}
491
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
488
492
  }
489
493
 
490
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
494
+ globalThis[Symbol.for('${u}')] = { __switchLocale, __preloadLocale }
491
495
 
492
496
  export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
493
497
  ` : `
494
498
  import { createSignal } from 'solid-js'
495
499
  import { createStore, reconcile } from 'solid-js/store'
496
- import __defaultMsgs from '${c}/${s}.js'
500
+ import __defaultMsgs from '${l}/${c}.js'
497
501
 
498
502
  const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
499
- const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
500
- const __loadedLocales = new Set(['${s}'])
503
+ const [__currentLocale, __setCurrentLocale] = createSignal('${c}')
504
+ const __loadedLocales = new Set(['${c}'])
501
505
  const [__loading, __setLoading] = createSignal(false)
502
506
  const __cache = new Map()
503
507
  const __loadedRoutes = new Set()
504
508
  const __normalizeMessages = (mod) => mod.default ?? mod
505
509
 
506
510
  const __loaders = {
507
- ${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
511
+ ${d.map((e) => ` '${e}': () => import('${l}/${e}.js'),`).join("\n")}
508
512
  }
509
513
 
510
514
  const __routeLoaders = {}
@@ -548,21 +552,21 @@ async function __preloadLocale(locale) {
548
552
  const mod = __normalizeMessages(await __loaders[locale]())
549
553
  __cache.set(locale, mod)
550
554
  __loadedLocales.add(locale)
551
- } catch {}
555
+ } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
552
556
  }
553
557
 
554
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
558
+ globalThis[Symbol.for('${u}')] = { __switchLocale, __preloadLocale }
555
559
 
556
560
  export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
557
561
  `;
558
562
  }
559
563
  //#endregion
560
564
  //#region src/route-resolve.ts
561
- function se(e) {
565
+ function le(e) {
562
566
  let t = (e.includes("/") ? e.slice(e.lastIndexOf("/") + 1) : e).replace(/\.[^.]+$/, "");
563
567
  return t.replace(/-[a-zA-Z0-9]{4,}$/, "") || t;
564
568
  }
565
- function ce(e) {
569
+ function ue(e) {
566
570
  let t = /* @__PURE__ */ new Map(), n = e.split("\n");
567
571
  for (let e = 0; e < n.length; e++) {
568
572
  let r = n[e], i = r.match(/^(?:\/\*.*?\*\/\s*)?export\s+const\s+_([a-z0-9]+)\s*=\s*/);
@@ -579,22 +583,22 @@ function ce(e) {
579
583
  }
580
584
  return t;
581
585
  }
582
- function J(e, n) {
583
- let r = [], i = [];
584
- for (let a of e) {
585
- let e = t(a), o = n.get(e);
586
- o && (r.push(o), i.push(` '${ue(a)}': _${e},`));
586
+ function J(e, t) {
587
+ let n = [], r = [];
588
+ for (let i of e) {
589
+ let e = o(i), a = t.get(e);
590
+ a && (n.push(a), r.push(` '${fe(i)}': _${e},`));
587
591
  }
588
- return i.length > 0 && r.push("", "export default {", ...i, "}"), r.join("\n") + "\n";
592
+ return r.length > 0 && n.push("", "export default {", ...r, "}"), n.join("\n") + "\n";
589
593
  }
590
- function le(t, n) {
594
+ function de(t, n) {
591
595
  try {
592
- return o(e(t, `${n}.js`), "utf-8");
596
+ return c(e(t, `${n}.js`), "utf-8");
593
597
  } catch {
594
598
  return;
595
599
  }
596
600
  }
597
- function ue(e) {
601
+ function fe(e) {
598
602
  return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
599
603
  }
600
604
  //#endregion
@@ -607,18 +611,18 @@ function Y(e, t) {
607
611
  function X(e) {
608
612
  return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
609
613
  }
610
- function Z(e, n) {
611
- return `{ id: '${X(n?.id ?? t(e, n?.context))}', message: '${X(e)}' }`;
614
+ function Z(e, t) {
615
+ return `{ id: '${X(t?.id ?? o(e, t?.context))}', message: '${X(e)}' }`;
612
616
  }
613
- function de(e) {
617
+ function pe(e) {
614
618
  let t = e.match(/<template(\s[^>]*)?>/);
615
619
  if (!t) return e;
616
620
  let n = t.index + t[0].length, r = e.lastIndexOf("</template>");
617
621
  if (r < 0) return e;
618
622
  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);
619
- return !s && !c && !l ? e : (s && (a = fe(a), a = me(a)), c && (a = Q(a)), l && (a = he(a)), i + a + o);
623
+ return !s && !c && !l ? e : (s && (a = me(a), a = ge(a)), c && (a = _e(a)), l && (a = Q(a)), i + a + o);
620
624
  }
621
- function fe(e) {
625
+ function me(e) {
622
626
  return e.replace(/<(\w+)(\s[^>]*?)\bv-t\.(\w+)\b([^>]*?)>/g, (e, t, n, r, i) => {
623
627
  if (r === "plural") return e;
624
628
  let a = n + i, o = RegExp(`\\b${r}="([^"]*)"`), s = a.match(o);
@@ -627,7 +631,7 @@ function fe(e) {
627
631
  return u = u.replace(f, ""), d = d.replace(f, ""), `<${t}${u} :${r}="$t(${l})"${d}>`;
628
632
  });
629
633
  }
630
- function pe(e) {
634
+ function he(e) {
631
635
  let t = [];
632
636
  return {
633
637
  message: e.replace(/\{\{\s*([^}]+?)\s*\}\}/g, (e, n) => {
@@ -642,7 +646,7 @@ function pe(e) {
642
646
  vars: t
643
647
  };
644
648
  }
645
- function me(e) {
649
+ function ge(e) {
646
650
  return e.replace(/<(\w+)(\s[^>]*?)\bv-t(?::([a-zA-Z0-9_.]+))?(?:\.plural)?(?:="([^"]*)")?\b([^>]*)>([\s\S]*?)<\/\1>/g, (e, t, n, r, i, a, o) => {
647
651
  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/, "");
648
652
  if (s && i) {
@@ -670,11 +674,11 @@ function me(e) {
670
674
  return `{ tag: '${e.tag}', attrs: { ${t} } }`;
671
675
  }).join(", ")}]`})"></${t}>`;
672
676
  }
673
- let { message: d, vars: f } = pe(u), p = Z(d, { id: r });
677
+ let { message: d, vars: f } = he(u), p = Z(d, { id: r });
674
678
  return f.length > 0 ? `<${t}${c}${l}>{{ $t(${p}, { ${f.join(", ")} }) }}</${t}>` : `<${t}${c}${l}>{{ $t(${p}) }}</${t}>`;
675
679
  });
676
680
  }
677
- function Q(e) {
681
+ function _e(e) {
678
682
  return e.replace(/<Trans(\s[^>]*)?>(?!\s*$)([\s\S]*?)<\/Trans>/g, (e, t, n) => {
679
683
  let r = t ?? "";
680
684
  if (/\bmessage\s*=/.test(r)) return e;
@@ -706,7 +710,7 @@ function Q(e) {
706
710
  })}) }}</${o}>`;
707
711
  });
708
712
  }
709
- function he(e) {
713
+ function Q(e) {
710
714
  return e = e.replace(/<Plural(\s[^>]*?)>([\s\S]*?)<\/Plural>/g, (e, t, n) => {
711
715
  let r = t ?? "", i = $(r, "id"), a = $(r, "context");
712
716
  if (i.kind === "dynamic" || !i.value && a.kind === "dynamic") return e;
@@ -795,7 +799,7 @@ function $(e, t) {
795
799
  }
796
800
  //#endregion
797
801
  //#region src/solid-jsx-transform.ts
798
- function ge(e) {
802
+ function ve(e) {
799
803
  return {
800
804
  code: e,
801
805
  changed: !1
@@ -803,56 +807,56 @@ function ge(e) {
803
807
  }
804
808
  //#endregion
805
809
  //#region src/index.ts
806
- var _e = "virtual:fluenti/messages/", ve = "\0virtual:fluenti/messages/";
807
- function ye(t) {
808
- let n = t?.catalogDir ?? "src/locales/compiled", a = t?.framework ?? "auto", o = t?.splitting ?? !1, s = t?.sourceLocale ?? "en", f = t?.locales ?? [s], p = t?.defaultBuildLocale ?? s, m = "vue", h = {
810
+ var ye = "virtual:fluenti/messages/", be = "\0virtual:fluenti/messages/";
811
+ function xe(n) {
812
+ let a = n?.catalogDir ?? "src/locales/compiled", o = n?.framework ?? "auto", s = n?.splitting ?? !1, c = n?.sourceLocale ?? "en", l = n?.locales ?? [c], m = n?.defaultBuildLocale ?? c, h = "vue", g = {
809
813
  name: "fluenti:virtual",
810
814
  configResolved(e) {
811
- c(e.command);
815
+ u(e.command);
812
816
  },
813
817
  resolveId(e) {
814
- if (e.startsWith(_e)) return "\0" + e;
815
- if (o) {
816
- let t = W(e);
818
+ if (e.startsWith(ye)) return "\0" + e;
819
+ if (s) {
820
+ let t = G(e);
817
821
  if (t) return t;
818
822
  }
819
823
  },
820
824
  load(e) {
821
- if (e.startsWith(ve)) return `export { default } from '${`${n}/${e.slice(26)}.js`}'`;
822
- if (o) {
823
- let t = G(e, {
824
- catalogDir: n,
825
- locales: f,
826
- sourceLocale: s,
827
- defaultBuildLocale: p,
828
- framework: m
825
+ if (e.startsWith(be)) return `export { default } from '${`${a}/${e.slice(26)}.js`}'`;
826
+ if (s) {
827
+ let t = K(e, {
828
+ catalogDir: a,
829
+ locales: l,
830
+ sourceLocale: c,
831
+ defaultBuildLocale: m,
832
+ framework: h
829
833
  });
830
834
  if (t) return t;
831
835
  }
832
836
  }
833
- }, g = {
837
+ }, _ = {
834
838
  name: "fluenti:vue-template",
835
839
  enforce: "pre",
836
840
  transform(e, t) {
837
841
  if (!t.endsWith(".vue") || !/\bv-t\b/.test(e) && !/<Trans[\s>]/.test(e) && !/<Plural[\s/>]/.test(e)) return;
838
- let n = de(e);
842
+ let n = pe(e);
839
843
  if (n !== e) return {
840
844
  code: n,
841
845
  map: null
842
846
  };
843
847
  }
844
- }, _ = {
848
+ }, v = {
845
849
  name: "fluenti:script-transform",
846
850
  enforce: "pre",
847
851
  transform(e, t) {
848
852
  if (t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/) || t.includes(".vue") && !t.includes("type=script")) return;
849
- let n = e, o = !1;
853
+ let n = e, a = !1;
850
854
  if (t.match(/\.[jt]sx(\?|$)/) && /<Trans[\s>]/.test(n)) {
851
855
  let e = i(n);
852
- e.transformed && (n = e.code, o = !0);
856
+ e.transformed && (n = e.code, a = !0);
853
857
  }
854
- if (be(n)) {
855
- let e = a === "auto" ? Y(t, n) : a, i = r(n, {
858
+ if (Se(n)) {
859
+ let e = o === "auto" ? Y(t, n) : o, i = r(n, {
856
860
  framework: e,
857
861
  allowTopLevelImportedT: e === "vue" && t.includes(".vue")
858
862
  });
@@ -861,94 +865,109 @@ function ye(t) {
861
865
  map: null
862
866
  };
863
867
  }
864
- return o ? {
868
+ return a ? {
865
869
  code: n,
866
870
  map: null
867
871
  } : void 0;
868
872
  }
869
- }, v = /* @__PURE__ */ new Map();
870
- return [
871
- h,
872
- g,
873
- {
874
- name: "fluenti:solid-jsx",
875
- enforce: "pre",
876
- transform(e, t) {
877
- if (!t.match(/\.[tj]sx(\?|$)/) || t.includes("node_modules") || !/<Trans[\s>]/.test(e) && !/<Plural[\s/>]/.test(e) || (a === "auto" ? Y(t, e) : a) !== "solid") return;
878
- let n = ge(e);
879
- if (n.changed) return {
880
- code: n.code,
881
- map: null
882
- };
883
- }
873
+ }, y = /* @__PURE__ */ new Map(), b = {
874
+ name: "fluenti:build-split",
875
+ transform(e, t) {
876
+ if (!s || !d(this.environment) || t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)) return;
877
+ h = o === "auto" ? Y(t, e) : o;
878
+ let n = s === "static" ? "static" : "dynamic", r = n === "static" ? p(e) : f(e);
879
+ if (s === "per-route" && r.usedHashes.size > 0 && y.set(t, r.usedHashes), !r.needsCatalogImport) return;
880
+ let i = s === "per-route" ? "per-route" : n;
881
+ return {
882
+ code: R(r.code, i, r.usedHashes),
883
+ map: null
884
+ };
884
885
  },
885
- _,
886
- {
887
- name: "fluenti:build-split",
888
- transform(e, t) {
889
- if (!o || !l(this.environment) || t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)) return;
890
- m = a === "auto" ? Y(t, e) : a;
891
- let n = o === "static" ? "static" : "dynamic", r = n === "static" ? d(e) : u(e);
892
- if (o === "per-route" && r.usedHashes.size > 0 && v.set(t, r.usedHashes), !r.needsCatalogImport) return;
893
- let i = o === "per-route" ? "per-route" : n;
894
- return {
895
- code: L(r.code, i, r.usedHashes),
896
- map: null
897
- };
898
- },
899
- generateBundle(t, r) {
900
- if (o !== "per-route" || v.size === 0) return;
901
- let i = /* @__PURE__ */ new Map();
902
- for (let [e, t] of Object.entries(r)) {
903
- if (t.type !== "chunk") continue;
904
- let n = /* @__PURE__ */ new Set();
905
- for (let e of Object.keys(t.modules)) {
906
- let t = v.get(e);
907
- if (t) for (let e of t) n.add(e);
908
- }
909
- n.size > 0 && i.set(e, n);
910
- }
911
- if (i.size === 0) return;
912
- let a = /* @__PURE__ */ new Map();
913
- for (let [e, t] of i) for (let n of t) {
914
- let t = a.get(n) ?? [];
915
- t.push(e), a.set(n, t);
886
+ generateBundle(t, n) {
887
+ if (s !== "per-route" || y.size === 0) return;
888
+ let r = /* @__PURE__ */ new Map();
889
+ for (let [e, t] of Object.entries(n)) {
890
+ if (t.type !== "chunk") continue;
891
+ let n = /* @__PURE__ */ new Set();
892
+ for (let e of Object.keys(t.modules)) {
893
+ let t = y.get(e);
894
+ if (t) for (let e of t) n.add(e);
916
895
  }
917
- let s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Map();
918
- for (let [e, t] of a) if (t.length > 1) s.add(e);
919
- else {
920
- let n = se(t[0]), r = c.get(n) ?? /* @__PURE__ */ new Set();
921
- r.add(e), c.set(n, r);
896
+ n.size > 0 && r.set(e, n);
897
+ }
898
+ if (r.size === 0) return;
899
+ let i = /* @__PURE__ */ new Map();
900
+ for (let [e, t] of r) for (let n of t) {
901
+ let t = i.get(n) ?? [];
902
+ t.push(e), i.set(n, t);
903
+ }
904
+ let o = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Map();
905
+ for (let [e, t] of i) if (t.length > 1) o.add(e);
906
+ else {
907
+ let n = le(t[0]), r = c.get(n) ?? /* @__PURE__ */ new Set();
908
+ r.add(e), c.set(n, r);
909
+ }
910
+ let u = e(process.cwd(), a);
911
+ for (let e of l) {
912
+ let t = de(u, e);
913
+ if (!t) continue;
914
+ let n = ue(t);
915
+ if (o.size > 0) {
916
+ let t = J(o, n);
917
+ this.emitFile({
918
+ type: "asset",
919
+ fileName: `_fluenti/shared-${e}.js`,
920
+ source: t
921
+ });
922
922
  }
923
- let l = e(process.cwd(), n);
924
- for (let e of f) {
925
- let t = le(l, e);
926
- if (!t) continue;
927
- let n = ce(t);
928
- if (s.size > 0) {
929
- let t = J(s, n);
930
- this.emitFile({
931
- type: "asset",
932
- fileName: `_fluenti/shared-${e}.js`,
933
- source: t
934
- });
935
- }
936
- for (let [t, r] of c) {
937
- let i = J(r, n);
938
- this.emitFile({
939
- type: "asset",
940
- fileName: `_fluenti/${t}-${e}.js`,
941
- source: i
942
- });
943
- }
923
+ for (let [t, r] of c) {
924
+ let i = J(r, n);
925
+ this.emitFile({
926
+ type: "asset",
927
+ fileName: `_fluenti/${t}-${e}.js`,
928
+ source: i
929
+ });
944
930
  }
945
931
  }
946
- },
932
+ }
933
+ }, x = {
934
+ name: "fluenti:solid-jsx",
935
+ enforce: "pre",
936
+ transform(e, t) {
937
+ if (!t.match(/\.[tj]sx(\?|$)/) || t.includes("node_modules") || !/<Trans[\s>]/.test(e) && !/<Plural[\s/>]/.test(e) || (o === "auto" ? Y(t, e) : o) !== "solid") return;
938
+ let n = ve(e);
939
+ if (n.changed) return {
940
+ code: n.code,
941
+ map: null
942
+ };
943
+ }
944
+ }, S = n?.devAutoCompile ?? !0, C = n?.include ?? ["src/**/*.{vue,tsx,jsx,ts,js}"];
945
+ function w(e, t) {
946
+ return !/\.(vue|tsx|jsx|ts|js)$/.test(e) || e.includes("node_modules") ? !1 : t.some((t) => {
947
+ let n = t.split("*")[0] ?? "";
948
+ return n === "" || e.includes(n.replace("./", ""));
949
+ });
950
+ }
951
+ return [
952
+ g,
953
+ _,
954
+ x,
955
+ v,
956
+ b,
947
957
  {
948
958
  name: "fluenti:dev",
949
- configureServer(e) {},
959
+ configureServer(e) {
960
+ if (!S) return;
961
+ let n = t({
962
+ cwd: e.config.root,
963
+ onSuccess: () => {}
964
+ });
965
+ n(), e.watcher.on("change", (e) => {
966
+ w(e, C) && !e.includes(a) && n();
967
+ });
968
+ },
950
969
  hotUpdate({ file: e }) {
951
- if (e.includes(n)) {
970
+ if (e.includes(a)) {
952
971
  let e = [...this.environment.moduleGraph.urlToModuleMap.entries()].filter(([e]) => e.includes("virtual:fluenti")).map(([, e]) => e);
953
972
  if (e.length > 0) return e;
954
973
  }
@@ -956,10 +975,10 @@ function ye(t) {
956
975
  }
957
976
  ];
958
977
  }
959
- function be(e) {
960
- 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);
978
+ function Se(e) {
979
+ 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);
961
980
  }
962
981
  //#endregion
963
- export { ye as default };
982
+ export { xe as default };
964
983
 
965
984
  //# sourceMappingURL=index.js.map