@fluenti/vite-plugin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +189 -0
- package/client.d.ts +9 -0
- package/dist/index.cjs +273 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +965 -0
- package/dist/index.js.map +1 -0
- package/dist/src/build-transform.d.ts +18 -0
- package/dist/src/build-transform.d.ts.map +1 -0
- package/dist/src/framework-detect.d.ts +2 -0
- package/dist/src/framework-detect.d.ts.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/mode-detect.d.ts +17 -0
- package/dist/src/mode-detect.d.ts.map +1 -0
- package/dist/src/route-resolve.d.ts +41 -0
- package/dist/src/route-resolve.d.ts.map +1 -0
- package/dist/src/scope-transform.d.ts +3 -0
- package/dist/src/scope-transform.d.ts.map +1 -0
- package/dist/src/sfc-transform.d.ts +2 -0
- package/dist/src/sfc-transform.d.ts.map +1 -0
- package/dist/src/solid-jsx-transform.d.ts +6 -0
- package/dist/src/solid-jsx-transform.d.ts.map +1 -0
- package/dist/src/trans-transform.d.ts +3 -0
- package/dist/src/trans-transform.d.ts.map +1 -0
- package/dist/src/types.d.ts +15 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/virtual-modules.d.ts +33 -0
- package/dist/src/virtual-modules.d.ts.map +1 -0
- package/dist/src/vt-transform.d.ts +57 -0
- package/dist/src/vt-transform.d.ts.map +1 -0
- package/dist/tests/build-transform.test.d.ts +2 -0
- package/dist/tests/build-transform.test.d.ts.map +1 -0
- package/dist/tests/mode-detect.test.d.ts +2 -0
- package/dist/tests/mode-detect.test.d.ts.map +1 -0
- package/dist/tests/per-route-splitting.test.d.ts +2 -0
- package/dist/tests/per-route-splitting.test.d.ts.map +1 -0
- package/dist/tests/route-resolve.test.d.ts +2 -0
- package/dist/tests/route-resolve.test.d.ts.map +1 -0
- package/dist/tests/scope-transform.test.d.ts +2 -0
- package/dist/tests/scope-transform.test.d.ts.map +1 -0
- package/dist/tests/trans-transform.test.d.ts +2 -0
- package/dist/tests/trans-transform.test.d.ts.map +1 -0
- package/dist/tests/virtual-modules.test.d.ts +2 -0
- package/dist/tests/virtual-modules.test.d.ts.map +1 -0
- package/dist/tests/vite-plugin.test.d.ts +2 -0
- package/dist/tests/vite-plugin.test.d.ts.map +1 -0
- package/dist/vite.config.d.ts +3 -0
- package/dist/vite.config.d.ts.map +1 -0
- package/package.json +72 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,965 @@
|
|
|
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";
|
|
5
|
+
//#region src/mode-detect.ts
|
|
6
|
+
var s = "dev";
|
|
7
|
+
function c(e) {
|
|
8
|
+
s = e === "build" ? "build" : "dev";
|
|
9
|
+
}
|
|
10
|
+
function l(e) {
|
|
11
|
+
return e?.mode === "build" || s === "build" || process.env.NODE_ENV === "production";
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/build-transform.ts
|
|
15
|
+
function u(e) {
|
|
16
|
+
return f(e, "dynamic");
|
|
17
|
+
}
|
|
18
|
+
function d(e) {
|
|
19
|
+
return f(e, "static");
|
|
20
|
+
}
|
|
21
|
+
function f(e, t) {
|
|
22
|
+
let r = n(e);
|
|
23
|
+
if (!r || r.type !== "Program") return {
|
|
24
|
+
code: e,
|
|
25
|
+
needsCatalogImport: !1,
|
|
26
|
+
usedHashes: /* @__PURE__ */ new Set()
|
|
27
|
+
};
|
|
28
|
+
let i = p(r), o = [], s = /* @__PURE__ */ new Set();
|
|
29
|
+
if (a(r, (n) => {
|
|
30
|
+
let r = h(e, n, i, t, s);
|
|
31
|
+
if (r) {
|
|
32
|
+
o.push(r);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
v(n, s);
|
|
36
|
+
}), o.length === 0) return {
|
|
37
|
+
code: e,
|
|
38
|
+
needsCatalogImport: !1,
|
|
39
|
+
usedHashes: s
|
|
40
|
+
};
|
|
41
|
+
let c = e;
|
|
42
|
+
for (let e = o.length - 1; e >= 0; e--) {
|
|
43
|
+
let { start: t, end: n, replacement: r } = o[e];
|
|
44
|
+
c = c.slice(0, t) + r + c.slice(n);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
code: c,
|
|
48
|
+
needsCatalogImport: !0,
|
|
49
|
+
usedHashes: s
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function p(e) {
|
|
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) {
|
|
55
|
+
if (!re(e)) continue;
|
|
56
|
+
let t = I(e);
|
|
57
|
+
t && (t === "useI18n" && n.add(e.local.name), t === "getI18n" && r.add(e.local.name), t === "unref" && i.add(e.local.name));
|
|
58
|
+
}
|
|
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);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
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);
|
|
67
|
+
}), {
|
|
68
|
+
tracked: t,
|
|
69
|
+
unref: i
|
|
70
|
+
};
|
|
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;
|
|
82
|
+
return {
|
|
83
|
+
start: n.start,
|
|
84
|
+
end: n.end,
|
|
85
|
+
replacement: u
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function g(e, t, n) {
|
|
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);
|
|
91
|
+
if (!i && !a && !o) return;
|
|
92
|
+
let s = _(t.arguments[0]);
|
|
93
|
+
if (!s) return;
|
|
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
|
+
return c === void 0 ? { catalogId: s } : {
|
|
96
|
+
catalogId: s,
|
|
97
|
+
valuesSource: c
|
|
98
|
+
};
|
|
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;
|
|
105
|
+
for (let t of e.properties) {
|
|
106
|
+
if (!A(t) || t.computed) continue;
|
|
107
|
+
let e = D(t.key);
|
|
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));
|
|
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);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
let i = S(e.openingElement, "__message"), a = S(e.openingElement, "context");
|
|
126
|
+
i && n.add(t(i, a));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (r === "Plural") {
|
|
130
|
+
let t = ee(e.openingElement);
|
|
131
|
+
t && n.add(t);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (r === "Select") {
|
|
135
|
+
let t = te(e.openingElement);
|
|
136
|
+
t && n.add(t);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
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")}}`
|
|
150
|
+
].filter(Boolean);
|
|
151
|
+
if (a.length !== 0) return t(`{count, plural,${typeof i == "number" ? ` offset:${i}` : ""} ${a.join(" ")}}`, r);
|
|
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);
|
|
158
|
+
}
|
|
159
|
+
function y(e) {
|
|
160
|
+
let t = x(e, "options");
|
|
161
|
+
if (t) {
|
|
162
|
+
let n = S(e, "other");
|
|
163
|
+
return {
|
|
164
|
+
...t,
|
|
165
|
+
...n === void 0 ? {} : { other: n }
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
let n = {};
|
|
169
|
+
for (let t of e.attributes) {
|
|
170
|
+
if (!F(t)) continue;
|
|
171
|
+
let e = t.name.name;
|
|
172
|
+
if ([
|
|
173
|
+
"value",
|
|
174
|
+
"id",
|
|
175
|
+
"context",
|
|
176
|
+
"comment",
|
|
177
|
+
"options"
|
|
178
|
+
].includes(e)) continue;
|
|
179
|
+
let r = w(t);
|
|
180
|
+
r !== void 0 && (n[e] = r);
|
|
181
|
+
}
|
|
182
|
+
return Object.keys(n).length > 0 ? n : void 0;
|
|
183
|
+
}
|
|
184
|
+
function b(e) {
|
|
185
|
+
if (!k(e)) return;
|
|
186
|
+
let t = {};
|
|
187
|
+
for (let n of e.properties) {
|
|
188
|
+
if (!A(n) || n.computed) return;
|
|
189
|
+
let e = D(n.key), r = E(n.value);
|
|
190
|
+
if (!e || r === void 0) return;
|
|
191
|
+
t[e] = r;
|
|
192
|
+
}
|
|
193
|
+
return t;
|
|
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);
|
|
198
|
+
}
|
|
199
|
+
function S(e, t) {
|
|
200
|
+
return w(C(e, t));
|
|
201
|
+
}
|
|
202
|
+
function ne(e, t) {
|
|
203
|
+
let n = C(e, t);
|
|
204
|
+
if (!n?.value || n.value.type !== "JSXExpressionContainer") return;
|
|
205
|
+
let r = n.value.expression;
|
|
206
|
+
return r.type === "NumericLiteral" ? r.value : void 0;
|
|
207
|
+
}
|
|
208
|
+
function C(e, t) {
|
|
209
|
+
return e.attributes.find((e) => F(e) && e.name.name === t);
|
|
210
|
+
}
|
|
211
|
+
function w(e) {
|
|
212
|
+
if (e?.value) {
|
|
213
|
+
if (e.value.type === "StringLiteral") return e.value.value;
|
|
214
|
+
if (e.value.type === "JSXExpressionContainer") return E(e.value.expression);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function T(e) {
|
|
218
|
+
return e.type === "JSXIdentifier" ? e.name : void 0;
|
|
219
|
+
}
|
|
220
|
+
function E(e) {
|
|
221
|
+
if (e.type === "StringLiteral") return e.value;
|
|
222
|
+
if (e.type === "TemplateLiteral") {
|
|
223
|
+
let t = e;
|
|
224
|
+
if (t.expressions.length === 0 && t.quasis.length === 1) return t.quasis[0].value.cooked ?? t.quasis[0].value.raw;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function D(e) {
|
|
228
|
+
if (N(e)) return e.name;
|
|
229
|
+
if (e.type === "StringLiteral") return e.value;
|
|
230
|
+
}
|
|
231
|
+
function O(e) {
|
|
232
|
+
return e.type === "ImportDeclaration";
|
|
233
|
+
}
|
|
234
|
+
function re(e) {
|
|
235
|
+
return e.type === "ImportSpecifier";
|
|
236
|
+
}
|
|
237
|
+
function ie(e) {
|
|
238
|
+
return e.type === "VariableDeclarator";
|
|
239
|
+
}
|
|
240
|
+
function ae(e) {
|
|
241
|
+
return e.type === "ObjectPattern";
|
|
242
|
+
}
|
|
243
|
+
function k(e) {
|
|
244
|
+
return e.type === "ObjectExpression";
|
|
245
|
+
}
|
|
246
|
+
function A(e) {
|
|
247
|
+
return e.type === "ObjectProperty";
|
|
248
|
+
}
|
|
249
|
+
function j(e) {
|
|
250
|
+
return e.type === "CallExpression";
|
|
251
|
+
}
|
|
252
|
+
function M(e) {
|
|
253
|
+
return e.type === "MemberExpression";
|
|
254
|
+
}
|
|
255
|
+
function N(e) {
|
|
256
|
+
return e?.type === "Identifier";
|
|
257
|
+
}
|
|
258
|
+
function P(e) {
|
|
259
|
+
return e.type === "JSXElement";
|
|
260
|
+
}
|
|
261
|
+
function F(e) {
|
|
262
|
+
return e.type === "JSXAttribute";
|
|
263
|
+
}
|
|
264
|
+
function I(e) {
|
|
265
|
+
let t = e.imported;
|
|
266
|
+
if (t.type === "Identifier") return t.name;
|
|
267
|
+
if (t.type === "StringLiteral") return t.value;
|
|
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}`;
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
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;
|
|
277
|
+
if (e === z) return H;
|
|
278
|
+
if (e === B) return U;
|
|
279
|
+
}
|
|
280
|
+
function G(e, t) {
|
|
281
|
+
if (e === V) return K(t);
|
|
282
|
+
if (e === H) return q(t);
|
|
283
|
+
if (e === U) return oe(t);
|
|
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);
|
|
287
|
+
return o === "react" ? `
|
|
288
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
289
|
+
|
|
290
|
+
const __catalog = { ...__defaultMsgs }
|
|
291
|
+
let __currentLocale = '${s}'
|
|
292
|
+
const __loadedLocales = new Set(['${s}'])
|
|
293
|
+
let __loading = false
|
|
294
|
+
const __cache = new Map()
|
|
295
|
+
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
296
|
+
|
|
297
|
+
const __loaders = {
|
|
298
|
+
${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
async function __switchLocale(locale) {
|
|
302
|
+
if (__loadedLocales.has(locale)) {
|
|
303
|
+
Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)
|
|
304
|
+
__currentLocale = locale
|
|
305
|
+
return
|
|
306
|
+
}
|
|
307
|
+
__loading = true
|
|
308
|
+
try {
|
|
309
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
310
|
+
__cache.set(locale, mod)
|
|
311
|
+
__loadedLocales.add(locale)
|
|
312
|
+
Object.assign(__catalog, mod)
|
|
313
|
+
__currentLocale = locale
|
|
314
|
+
} finally {
|
|
315
|
+
__loading = false
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
async function __preloadLocale(locale) {
|
|
320
|
+
if (__loadedLocales.has(locale) || !__loaders[locale]) return
|
|
321
|
+
try {
|
|
322
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
323
|
+
__cache.set(locale, mod)
|
|
324
|
+
__loadedLocales.add(locale)
|
|
325
|
+
} catch {}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
329
|
+
|
|
330
|
+
export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
|
|
331
|
+
` : o === "vue" ? `
|
|
332
|
+
import { shallowReactive, triggerRef, ref } from 'vue'
|
|
333
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
334
|
+
|
|
335
|
+
const __catalog = shallowReactive({ ...__defaultMsgs })
|
|
336
|
+
const __currentLocale = ref('${s}')
|
|
337
|
+
const __loadedLocales = new Set(['${s}'])
|
|
338
|
+
const __loading = ref(false)
|
|
339
|
+
const __cache = new Map()
|
|
340
|
+
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
341
|
+
|
|
342
|
+
const __loaders = {
|
|
343
|
+
${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async function __switchLocale(locale) {
|
|
347
|
+
if (__loadedLocales.has(locale)) {
|
|
348
|
+
Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)
|
|
349
|
+
__currentLocale.value = locale
|
|
350
|
+
return
|
|
351
|
+
}
|
|
352
|
+
__loading.value = true
|
|
353
|
+
try {
|
|
354
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
355
|
+
__cache.set(locale, mod)
|
|
356
|
+
__loadedLocales.add(locale)
|
|
357
|
+
Object.assign(__catalog, mod)
|
|
358
|
+
__currentLocale.value = locale
|
|
359
|
+
} finally {
|
|
360
|
+
__loading.value = false
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
async function __preloadLocale(locale) {
|
|
365
|
+
if (__loadedLocales.has(locale) || !__loaders[locale]) return
|
|
366
|
+
try {
|
|
367
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
368
|
+
__cache.set(locale, mod)
|
|
369
|
+
__loadedLocales.add(locale)
|
|
370
|
+
} catch {}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
374
|
+
|
|
375
|
+
export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
|
|
376
|
+
` : `
|
|
377
|
+
import { createSignal } from 'solid-js'
|
|
378
|
+
import { createStore, reconcile } from 'solid-js/store'
|
|
379
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
380
|
+
|
|
381
|
+
const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
|
|
382
|
+
const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
|
|
383
|
+
const __loadedLocales = new Set(['${s}'])
|
|
384
|
+
const [__loading, __setLoading] = createSignal(false)
|
|
385
|
+
const __cache = new Map()
|
|
386
|
+
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
387
|
+
|
|
388
|
+
const __loaders = {
|
|
389
|
+
${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async function __switchLocale(locale) {
|
|
393
|
+
if (__loadedLocales.has(locale)) {
|
|
394
|
+
__setCatalog(reconcile(__cache.get(locale) || __defaultMsgs))
|
|
395
|
+
__setCurrentLocale(locale)
|
|
396
|
+
return
|
|
397
|
+
}
|
|
398
|
+
__setLoading(true)
|
|
399
|
+
try {
|
|
400
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
401
|
+
__cache.set(locale, mod)
|
|
402
|
+
__loadedLocales.add(locale)
|
|
403
|
+
__setCatalog(reconcile(mod))
|
|
404
|
+
__setCurrentLocale(locale)
|
|
405
|
+
} finally {
|
|
406
|
+
__setLoading(false)
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
async function __preloadLocale(locale) {
|
|
411
|
+
if (__loadedLocales.has(locale) || !__loaders[locale]) return
|
|
412
|
+
try {
|
|
413
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
414
|
+
__cache.set(locale, mod)
|
|
415
|
+
__loadedLocales.add(locale)
|
|
416
|
+
} catch {}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
420
|
+
|
|
421
|
+
export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
|
|
422
|
+
`;
|
|
423
|
+
}
|
|
424
|
+
function q(t) {
|
|
425
|
+
let { catalogDir: n, defaultBuildLocale: r, sourceLocale: i } = t, a = r || i;
|
|
426
|
+
return `export * from '${e(process.cwd(), n)}/${a}.js'\n`;
|
|
427
|
+
}
|
|
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
|
+
return o === "vue" ? `
|
|
431
|
+
import { shallowReactive, ref } from 'vue'
|
|
432
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
433
|
+
|
|
434
|
+
const __catalog = shallowReactive({ ...__defaultMsgs })
|
|
435
|
+
const __currentLocale = ref('${s}')
|
|
436
|
+
const __loadedLocales = new Set(['${s}'])
|
|
437
|
+
const __loading = ref(false)
|
|
438
|
+
const __cache = new Map()
|
|
439
|
+
const __loadedRoutes = new Set()
|
|
440
|
+
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
441
|
+
|
|
442
|
+
const __loaders = {
|
|
443
|
+
${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const __routeLoaders = {}
|
|
447
|
+
|
|
448
|
+
function __registerRouteLoader(routeId, locale, loader) {
|
|
449
|
+
const key = routeId + ':' + locale
|
|
450
|
+
__routeLoaders[key] = loader
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
async function __loadRoute(routeId, locale) {
|
|
454
|
+
const key = routeId + ':' + (locale || __currentLocale.value)
|
|
455
|
+
if (__loadedRoutes.has(key)) return
|
|
456
|
+
const loader = __routeLoaders[key]
|
|
457
|
+
if (!loader) return
|
|
458
|
+
const mod = __normalizeMessages(await loader())
|
|
459
|
+
Object.assign(__catalog, mod)
|
|
460
|
+
__loadedRoutes.add(key)
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
async function __switchLocale(locale) {
|
|
464
|
+
if (locale === __currentLocale.value) return
|
|
465
|
+
__loading.value = true
|
|
466
|
+
try {
|
|
467
|
+
if (__cache.has(locale)) {
|
|
468
|
+
Object.assign(__catalog, __cache.get(locale))
|
|
469
|
+
} else {
|
|
470
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
471
|
+
__cache.set(locale, mod)
|
|
472
|
+
Object.assign(__catalog, mod)
|
|
473
|
+
}
|
|
474
|
+
__loadedLocales.add(locale)
|
|
475
|
+
__currentLocale.value = locale
|
|
476
|
+
} finally {
|
|
477
|
+
__loading.value = false
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
async function __preloadLocale(locale) {
|
|
482
|
+
if (__cache.has(locale) || !__loaders[locale]) return
|
|
483
|
+
try {
|
|
484
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
485
|
+
__cache.set(locale, mod)
|
|
486
|
+
__loadedLocales.add(locale)
|
|
487
|
+
} catch {}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
491
|
+
|
|
492
|
+
export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
|
|
493
|
+
` : `
|
|
494
|
+
import { createSignal } from 'solid-js'
|
|
495
|
+
import { createStore, reconcile } from 'solid-js/store'
|
|
496
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
497
|
+
|
|
498
|
+
const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
|
|
499
|
+
const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
|
|
500
|
+
const __loadedLocales = new Set(['${s}'])
|
|
501
|
+
const [__loading, __setLoading] = createSignal(false)
|
|
502
|
+
const __cache = new Map()
|
|
503
|
+
const __loadedRoutes = new Set()
|
|
504
|
+
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
505
|
+
|
|
506
|
+
const __loaders = {
|
|
507
|
+
${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const __routeLoaders = {}
|
|
511
|
+
|
|
512
|
+
function __registerRouteLoader(routeId, locale, loader) {
|
|
513
|
+
const key = routeId + ':' + locale
|
|
514
|
+
__routeLoaders[key] = loader
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
async function __loadRoute(routeId, locale) {
|
|
518
|
+
const key = routeId + ':' + (locale || __currentLocale())
|
|
519
|
+
if (__loadedRoutes.has(key)) return
|
|
520
|
+
const loader = __routeLoaders[key]
|
|
521
|
+
if (!loader) return
|
|
522
|
+
const mod = __normalizeMessages(await loader())
|
|
523
|
+
__setCatalog(reconcile({ ...__catalog, ...mod }))
|
|
524
|
+
__loadedRoutes.add(key)
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
async function __switchLocale(locale) {
|
|
528
|
+
if (locale === __currentLocale()) return
|
|
529
|
+
__setLoading(true)
|
|
530
|
+
try {
|
|
531
|
+
if (__cache.has(locale)) {
|
|
532
|
+
__setCatalog(reconcile(__cache.get(locale)))
|
|
533
|
+
} else {
|
|
534
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
535
|
+
__cache.set(locale, mod)
|
|
536
|
+
__setCatalog(reconcile(mod))
|
|
537
|
+
}
|
|
538
|
+
__loadedLocales.add(locale)
|
|
539
|
+
__setCurrentLocale(locale)
|
|
540
|
+
} finally {
|
|
541
|
+
__setLoading(false)
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
async function __preloadLocale(locale) {
|
|
546
|
+
if (__cache.has(locale) || !__loaders[locale]) return
|
|
547
|
+
try {
|
|
548
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
549
|
+
__cache.set(locale, mod)
|
|
550
|
+
__loadedLocales.add(locale)
|
|
551
|
+
} catch {}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
555
|
+
|
|
556
|
+
export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
|
|
557
|
+
`;
|
|
558
|
+
}
|
|
559
|
+
//#endregion
|
|
560
|
+
//#region src/route-resolve.ts
|
|
561
|
+
function se(e) {
|
|
562
|
+
let t = (e.includes("/") ? e.slice(e.lastIndexOf("/") + 1) : e).replace(/\.[^.]+$/, "");
|
|
563
|
+
return t.replace(/-[a-zA-Z0-9]{4,}$/, "") || t;
|
|
564
|
+
}
|
|
565
|
+
function ce(e) {
|
|
566
|
+
let t = /* @__PURE__ */ new Map(), n = e.split("\n");
|
|
567
|
+
for (let e = 0; e < n.length; e++) {
|
|
568
|
+
let r = n[e], i = r.match(/^(?:\/\*.*?\*\/\s*)?export\s+const\s+_([a-z0-9]+)\s*=\s*/);
|
|
569
|
+
if (!i) continue;
|
|
570
|
+
let a = i[1], o = r, s = 0, c = 0, l = 0;
|
|
571
|
+
for (let e of r.slice(i[0].length)) e === "{" && s++, e === "}" && s--, e === "(" && c++, e === ")" && c--, e === "`" && (l = l === 0 ? 1 : 0);
|
|
572
|
+
for (; (s > 0 || c > 0 || l > 0) && e + 1 < n.length;) {
|
|
573
|
+
e++;
|
|
574
|
+
let t = n[e];
|
|
575
|
+
o += "\n" + t;
|
|
576
|
+
for (let e of t) e === "{" && s++, e === "}" && s--, e === "(" && c++, e === ")" && c--, e === "`" && (l = l === 0 ? 1 : 0);
|
|
577
|
+
}
|
|
578
|
+
t.set(a, o);
|
|
579
|
+
}
|
|
580
|
+
return t;
|
|
581
|
+
}
|
|
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},`));
|
|
587
|
+
}
|
|
588
|
+
return i.length > 0 && r.push("", "export default {", ...i, "}"), r.join("\n") + "\n";
|
|
589
|
+
}
|
|
590
|
+
function le(t, n) {
|
|
591
|
+
try {
|
|
592
|
+
return o(e(t, `${n}.js`), "utf-8");
|
|
593
|
+
} catch {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function ue(e) {
|
|
598
|
+
return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
|
|
599
|
+
}
|
|
600
|
+
//#endregion
|
|
601
|
+
//#region src/framework-detect.ts
|
|
602
|
+
function Y(e, t) {
|
|
603
|
+
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";
|
|
604
|
+
}
|
|
605
|
+
//#endregion
|
|
606
|
+
//#region src/sfc-transform.ts
|
|
607
|
+
function X(e) {
|
|
608
|
+
return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
609
|
+
}
|
|
610
|
+
function Z(e, n) {
|
|
611
|
+
return `{ id: '${X(n?.id ?? t(e, n?.context))}', message: '${X(e)}' }`;
|
|
612
|
+
}
|
|
613
|
+
function de(e) {
|
|
614
|
+
let t = e.match(/<template(\s[^>]*)?>/);
|
|
615
|
+
if (!t) return e;
|
|
616
|
+
let n = t.index + t[0].length, r = e.lastIndexOf("</template>");
|
|
617
|
+
if (r < 0) return e;
|
|
618
|
+
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);
|
|
620
|
+
}
|
|
621
|
+
function fe(e) {
|
|
622
|
+
return e.replace(/<(\w+)(\s[^>]*?)\bv-t\.(\w+)\b([^>]*?)>/g, (e, t, n, r, i) => {
|
|
623
|
+
if (r === "plural") return e;
|
|
624
|
+
let a = n + i, o = RegExp(`\\b${r}="([^"]*)"`), s = a.match(o);
|
|
625
|
+
if (!s) return e;
|
|
626
|
+
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}="[^"]*"`);
|
|
627
|
+
return u = u.replace(f, ""), d = d.replace(f, ""), `<${t}${u} :${r}="$t(${l})"${d}>`;
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
function pe(e) {
|
|
631
|
+
let t = [];
|
|
632
|
+
return {
|
|
633
|
+
message: e.replace(/\{\{\s*([^}]+?)\s*\}\}/g, (e, n) => {
|
|
634
|
+
let r = n.trim(), i;
|
|
635
|
+
if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(r)) i = r;
|
|
636
|
+
else if (/^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(r) && !r.endsWith(".")) {
|
|
637
|
+
let e = r.split(".");
|
|
638
|
+
i = e[e.length - 1];
|
|
639
|
+
} else i = String(t.length);
|
|
640
|
+
return t.push(`${i}: ${r}`), `{${i}}`;
|
|
641
|
+
}),
|
|
642
|
+
vars: t
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
function me(e) {
|
|
646
|
+
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
|
+
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
|
+
if (s && i) {
|
|
649
|
+
let e = o.trim().split("|").map((e) => e.trim());
|
|
650
|
+
return `<${t}${c}${l}>{{ $t(${Z(`{${i}, plural, ${(e.length === 2 ? ["one", "other"] : [
|
|
651
|
+
"one",
|
|
652
|
+
"other",
|
|
653
|
+
"zero",
|
|
654
|
+
"few",
|
|
655
|
+
"many"
|
|
656
|
+
].slice(0, e.length)).map((t, n) => `${t} {${e[n] ?? ""}}`).join(" ")}}`, { id: r })}, { ${i} }) }}</${t}>`;
|
|
657
|
+
}
|
|
658
|
+
let u = o.trim();
|
|
659
|
+
if (/<(\w+)(\s[^>]*)?>[\s\S]*?<\/\1>/g.test(u)) {
|
|
660
|
+
let e = [], n = 0;
|
|
661
|
+
return `<${t}${c}${l} v-html="$vtRich(${Z(u.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g, (t, r, i, a) => {
|
|
662
|
+
let o = n++, s = {}, c = /(\w+)="([^"]*)"/g, l;
|
|
663
|
+
for (; (l = c.exec(i)) !== null;) s[l[1]] = l[2];
|
|
664
|
+
return e.push({
|
|
665
|
+
tag: r,
|
|
666
|
+
attrs: s
|
|
667
|
+
}), `<${o}>${a}</${o}>`;
|
|
668
|
+
}), { id: r })}, ${`[${e.map((e) => {
|
|
669
|
+
let t = Object.entries(e.attrs).map(([e, t]) => `${e}: '${X(t)}'`).join(", ");
|
|
670
|
+
return `{ tag: '${e.tag}', attrs: { ${t} } }`;
|
|
671
|
+
}).join(", ")}]`})"></${t}>`;
|
|
672
|
+
}
|
|
673
|
+
let { message: d, vars: f } = pe(u), p = Z(d, { id: r });
|
|
674
|
+
return f.length > 0 ? `<${t}${c}${l}>{{ $t(${p}, { ${f.join(", ")} }) }}</${t}>` : `<${t}${c}${l}>{{ $t(${p}) }}</${t}>`;
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
function Q(e) {
|
|
678
|
+
return e.replace(/<Trans(\s[^>]*)?>(?!\s*$)([\s\S]*?)<\/Trans>/g, (e, t, n) => {
|
|
679
|
+
let r = t ?? "";
|
|
680
|
+
if (/\bmessage\s*=/.test(r)) return e;
|
|
681
|
+
let i = $(r, "id");
|
|
682
|
+
if (i.kind === "dynamic") return e;
|
|
683
|
+
let a = $(r, "context");
|
|
684
|
+
if (!i.value && a.kind === "dynamic") return e;
|
|
685
|
+
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();
|
|
686
|
+
if (/<(\w+)(\s[^>]*)?>[\s\S]*?<\/\1>/g.test(c)) {
|
|
687
|
+
let e = [], t = 0;
|
|
688
|
+
return `<${o}${s} v-html="$vtRich(${Z(c.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g, (n, r, i, a) => {
|
|
689
|
+
let o = t++, s = {}, c = /(\w[\w-]*)="([^"]*)"/g, l;
|
|
690
|
+
for (; (l = c.exec(i)) !== null;) s[l[1]] = l[2];
|
|
691
|
+
return e.push({
|
|
692
|
+
tag: r,
|
|
693
|
+
attrs: s
|
|
694
|
+
}), `<${o}>${a}</${o}>`;
|
|
695
|
+
}), {
|
|
696
|
+
id: i.value,
|
|
697
|
+
context: a.value
|
|
698
|
+
})}, ${`[${e.map((e) => {
|
|
699
|
+
let t = Object.entries(e.attrs).map(([e, t]) => `${e}: '${X(t)}'`).join(", ");
|
|
700
|
+
return `{ tag: '${e.tag}', attrs: { ${t} } }`;
|
|
701
|
+
}).join(", ")}]`})"></${o}>`;
|
|
702
|
+
}
|
|
703
|
+
return `<${o}${s}>{{ $t(${Z(c, {
|
|
704
|
+
id: i.value,
|
|
705
|
+
context: a.value
|
|
706
|
+
})}) }}</${o}>`;
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
function he(e) {
|
|
710
|
+
return e = e.replace(/<Plural(\s[^>]*?)>([\s\S]*?)<\/Plural>/g, (e, t, n) => {
|
|
711
|
+
let r = t ?? "", i = $(r, "id"), a = $(r, "context");
|
|
712
|
+
if (i.kind === "dynamic" || !i.value && a.kind === "dynamic") return e;
|
|
713
|
+
let o = /<template\s+#(\w+)\s*>([\s\S]*?)<\/template>/g, s = [], c;
|
|
714
|
+
for (; (c = o.exec(n)) !== null;) s.push({
|
|
715
|
+
cat: c[1],
|
|
716
|
+
content: c[2].trim()
|
|
717
|
+
});
|
|
718
|
+
if (s.length === 0) return e;
|
|
719
|
+
let l = r.match(/:value\s*=\s*"([^"]*)"/);
|
|
720
|
+
if (!l) return e;
|
|
721
|
+
let u = l[1], d = r.match(/\btag\s*=\s*"([^"]*)"/)?.[1] ?? "span", f = [
|
|
722
|
+
"zero",
|
|
723
|
+
"one",
|
|
724
|
+
"two",
|
|
725
|
+
"few",
|
|
726
|
+
"many",
|
|
727
|
+
"other"
|
|
728
|
+
], p = [], m = [];
|
|
729
|
+
for (let e of f) {
|
|
730
|
+
let t = s.find((t) => t.cat === e);
|
|
731
|
+
if (!t) continue;
|
|
732
|
+
let n = t.content, r = /<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g, i = n;
|
|
733
|
+
if (r.test(n)) {
|
|
734
|
+
let e = p.length, t = 0;
|
|
735
|
+
i = n.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g, (n, r, i, a) => {
|
|
736
|
+
let o = e + t++, s = {}, c = /(\w[\w-]*)="([^"]*)"/g, l;
|
|
737
|
+
for (; (l = c.exec(i)) !== null;) s[l[1]] = l[2];
|
|
738
|
+
return p.push({
|
|
739
|
+
tag: r,
|
|
740
|
+
attrs: s
|
|
741
|
+
}), `<${o}>${a}</${o}>`;
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
let a = e === "zero" ? "=0" : e;
|
|
745
|
+
m.push(`${a} {${i}}`);
|
|
746
|
+
}
|
|
747
|
+
if (m.length === 0) return e;
|
|
748
|
+
let h = Z(`{count, plural, ${m.join(" ")}}`, {
|
|
749
|
+
id: i.value,
|
|
750
|
+
context: a.value
|
|
751
|
+
}), g = r;
|
|
752
|
+
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();
|
|
753
|
+
let _ = g ? ` ${g}` : "";
|
|
754
|
+
return p.length > 0 ? `<${d}${_} v-html="$vtRich(${h}, ${`[${p.map((e) => {
|
|
755
|
+
let t = Object.entries(e.attrs).map(([e, t]) => `${e}: '${X(t)}'`).join(", ");
|
|
756
|
+
return `{ tag: '${e.tag}', attrs: { ${t} } }`;
|
|
757
|
+
}).join(", ")}]`}, { count: ${u} })"></${d}>` : `<${d}${_} v-text="$t(${h}, { count: ${u} })"></${d}>`;
|
|
758
|
+
}), e.replace(/<Plural(\s[^>]*?)\/?>(?:<\/Plural>)?/g, (e, t) => {
|
|
759
|
+
let n = t ?? "", r = $(n, "id"), i = $(n, "context");
|
|
760
|
+
if (r.kind === "dynamic" || !r.value && i.kind === "dynamic") return e;
|
|
761
|
+
let a = n.match(/:value\s*=\s*"([^"]*)"/);
|
|
762
|
+
if (!a) return e;
|
|
763
|
+
let o = a[1], s = n.match(/\btag\s*=\s*"([^"]*)"/)?.[1] ?? "span", c = [
|
|
764
|
+
"zero",
|
|
765
|
+
"one",
|
|
766
|
+
"two",
|
|
767
|
+
"few",
|
|
768
|
+
"many",
|
|
769
|
+
"other"
|
|
770
|
+
], l = [];
|
|
771
|
+
for (let e of c) {
|
|
772
|
+
let t = RegExp(`(?<!:)\\b${e}\\s*=\\s*"([^"]*)"`), r = n.match(t);
|
|
773
|
+
if (r) {
|
|
774
|
+
let t = e === "zero" ? "=0" : e;
|
|
775
|
+
l.push(`${t} {${r[1]}}`);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
if (l.length === 0) return e;
|
|
779
|
+
let u = Z(`{count, plural, ${l.join(" ")}}`, {
|
|
780
|
+
id: r.value,
|
|
781
|
+
context: i.value
|
|
782
|
+
}), d = n;
|
|
783
|
+
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*"[^"]*"/, "");
|
|
784
|
+
for (let e of c) d = d.replace(RegExp(`(?<!:)\\b${e}\\s*=\\s*"[^"]*"`), "");
|
|
785
|
+
return d = d.replace(/\s+/g, " ").trim(), `<${s}${d ? ` ${d}` : ""} v-text="$t(${u}, { count: ${o} })"></${s}>`;
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
function $(e, t) {
|
|
789
|
+
if (RegExp(`(?:^|\\s):${t}\\s*=`).test(e)) return { kind: "dynamic" };
|
|
790
|
+
let n = e.match(RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`));
|
|
791
|
+
return n ? {
|
|
792
|
+
kind: "static",
|
|
793
|
+
value: n[1] ?? ""
|
|
794
|
+
} : { kind: "missing" };
|
|
795
|
+
}
|
|
796
|
+
//#endregion
|
|
797
|
+
//#region src/solid-jsx-transform.ts
|
|
798
|
+
function ge(e) {
|
|
799
|
+
return {
|
|
800
|
+
code: e,
|
|
801
|
+
changed: !1
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
//#endregion
|
|
805
|
+
//#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 = {
|
|
809
|
+
name: "fluenti:virtual",
|
|
810
|
+
configResolved(e) {
|
|
811
|
+
c(e.command);
|
|
812
|
+
},
|
|
813
|
+
resolveId(e) {
|
|
814
|
+
if (e.startsWith(_e)) return "\0" + e;
|
|
815
|
+
if (o) {
|
|
816
|
+
let t = W(e);
|
|
817
|
+
if (t) return t;
|
|
818
|
+
}
|
|
819
|
+
},
|
|
820
|
+
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
|
|
829
|
+
});
|
|
830
|
+
if (t) return t;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}, g = {
|
|
834
|
+
name: "fluenti:vue-template",
|
|
835
|
+
enforce: "pre",
|
|
836
|
+
transform(e, t) {
|
|
837
|
+
if (!t.endsWith(".vue") || !/\bv-t\b/.test(e) && !/<Trans[\s>]/.test(e) && !/<Plural[\s/>]/.test(e)) return;
|
|
838
|
+
let n = de(e);
|
|
839
|
+
if (n !== e) return {
|
|
840
|
+
code: n,
|
|
841
|
+
map: null
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
}, _ = {
|
|
845
|
+
name: "fluenti:script-transform",
|
|
846
|
+
enforce: "pre",
|
|
847
|
+
transform(e, t) {
|
|
848
|
+
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;
|
|
850
|
+
if (t.match(/\.[jt]sx(\?|$)/) && /<Trans[\s>]/.test(n)) {
|
|
851
|
+
let e = i(n);
|
|
852
|
+
e.transformed && (n = e.code, o = !0);
|
|
853
|
+
}
|
|
854
|
+
if (be(n)) {
|
|
855
|
+
let e = a === "auto" ? Y(t, n) : a, i = r(n, {
|
|
856
|
+
framework: e,
|
|
857
|
+
allowTopLevelImportedT: e === "vue" && t.includes(".vue")
|
|
858
|
+
});
|
|
859
|
+
if (i.transformed) return {
|
|
860
|
+
code: i.code,
|
|
861
|
+
map: null
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
return o ? {
|
|
865
|
+
code: n,
|
|
866
|
+
map: null
|
|
867
|
+
} : void 0;
|
|
868
|
+
}
|
|
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
|
+
}
|
|
884
|
+
},
|
|
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);
|
|
916
|
+
}
|
|
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);
|
|
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
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
name: "fluenti:dev",
|
|
949
|
+
configureServer(e) {},
|
|
950
|
+
hotUpdate({ file: e }) {
|
|
951
|
+
if (e.includes(n)) {
|
|
952
|
+
let e = [...this.environment.moduleGraph.urlToModuleMap.entries()].filter(([e]) => e.includes("virtual:fluenti")).map(([, e]) => e);
|
|
953
|
+
if (e.length > 0) return e;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
];
|
|
958
|
+
}
|
|
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);
|
|
961
|
+
}
|
|
962
|
+
//#endregion
|
|
963
|
+
export { ye as default };
|
|
964
|
+
|
|
965
|
+
//# sourceMappingURL=index.js.map
|