@fluenti/vite-plugin 0.1.3 → 0.2.1
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/README.md +51 -117
- package/dist/build-transform.d.ts.map +1 -0
- package/dist/dev-runner.d.ts +28 -0
- package/dist/dev-runner.d.ts.map +1 -0
- package/dist/index.cjs +31 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +347 -486
- package/dist/index.js.map +1 -1
- package/dist/mode-detect.d.ts.map +1 -0
- package/dist/route-resolve.d.ts.map +1 -0
- package/dist/scope-transform.d.ts.map +1 -0
- package/dist/sfc-transform.cjs +2 -0
- package/dist/sfc-transform.cjs.map +1 -0
- package/dist/sfc-transform.d.ts.map +1 -0
- package/dist/sfc-transform.js +195 -0
- package/dist/sfc-transform.js.map +1 -0
- package/dist/trans-transform.d.ts.map +1 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/virtual-modules.d.ts +16 -0
- package/dist/virtual-modules.d.ts.map +1 -0
- package/dist/vt-transform.d.ts.map +1 -0
- package/package.json +12 -2
- package/dist/src/build-transform.d.ts.map +0 -1
- package/dist/src/framework-detect.d.ts +0 -2
- package/dist/src/framework-detect.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/mode-detect.d.ts.map +0 -1
- package/dist/src/route-resolve.d.ts.map +0 -1
- package/dist/src/scope-transform.d.ts.map +0 -1
- package/dist/src/sfc-transform.d.ts.map +0 -1
- package/dist/src/solid-jsx-transform.d.ts +0 -6
- package/dist/src/solid-jsx-transform.d.ts.map +0 -1
- package/dist/src/trans-transform.d.ts.map +0 -1
- package/dist/src/types.d.ts +0 -19
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/virtual-modules.d.ts +0 -33
- package/dist/src/virtual-modules.d.ts.map +0 -1
- package/dist/src/vt-transform.d.ts.map +0 -1
- package/dist/tests/build-transform.test.d.ts +0 -2
- package/dist/tests/build-transform.test.d.ts.map +0 -1
- package/dist/tests/framework-detect.test.d.ts +0 -2
- package/dist/tests/framework-detect.test.d.ts.map +0 -1
- package/dist/tests/mode-detect.test.d.ts +0 -2
- package/dist/tests/mode-detect.test.d.ts.map +0 -1
- package/dist/tests/per-route-splitting.test.d.ts +0 -2
- package/dist/tests/per-route-splitting.test.d.ts.map +0 -1
- package/dist/tests/route-resolve.test.d.ts +0 -2
- package/dist/tests/route-resolve.test.d.ts.map +0 -1
- package/dist/tests/scope-transform.test.d.ts +0 -2
- package/dist/tests/scope-transform.test.d.ts.map +0 -1
- package/dist/tests/sfc-transform.test.d.ts +0 -2
- package/dist/tests/sfc-transform.test.d.ts.map +0 -1
- package/dist/tests/solid-jsx-transform.test.d.ts +0 -2
- package/dist/tests/solid-jsx-transform.test.d.ts.map +0 -1
- package/dist/tests/trans-transform.test.d.ts +0 -2
- package/dist/tests/trans-transform.test.d.ts.map +0 -1
- package/dist/tests/virtual-modules.test.d.ts +0 -2
- package/dist/tests/virtual-modules.test.d.ts.map +0 -1
- package/dist/tests/vite-plugin.test.d.ts +0 -2
- package/dist/tests/vite-plugin.test.d.ts.map +0 -1
- package/dist/tests/vt-transform.test.d.ts +0 -2
- package/dist/tests/vt-transform.test.d.ts.map +0 -1
- package/dist/vite.config.d.ts +0 -3
- package/dist/vite.config.d.ts.map +0 -1
- /package/dist/{src/build-transform.d.ts → build-transform.d.ts} +0 -0
- /package/dist/{src/mode-detect.d.ts → mode-detect.d.ts} +0 -0
- /package/dist/{src/route-resolve.d.ts → route-resolve.d.ts} +0 -0
- /package/dist/{src/scope-transform.d.ts → scope-transform.d.ts} +0 -0
- /package/dist/{src/sfc-transform.d.ts → sfc-transform.d.ts} +0 -0
- /package/dist/{src/trans-transform.d.ts → trans-transform.d.ts} +0 -0
- /package/dist/{src/vt-transform.d.ts → vt-transform.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,95 +1,158 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { dirname as e, join as t, resolve as n } from "node:path";
|
|
2
|
+
import { exec as r } from "node:child_process";
|
|
3
|
+
import { existsSync as i, readFileSync as a } from "node:fs";
|
|
4
|
+
import { createRequire as o } from "node:module";
|
|
5
|
+
import { hashMessage as s, validateLocale as c } from "@fluenti/core";
|
|
6
|
+
import { parseSourceModule as l, scopeTransform as u, transformTransComponents as ee, walkSourceAst as d } from "@fluenti/core/internal";
|
|
5
7
|
//#region src/mode-detect.ts
|
|
6
|
-
var
|
|
7
|
-
function
|
|
8
|
-
|
|
8
|
+
var f = "dev";
|
|
9
|
+
function p(e) {
|
|
10
|
+
f = e === "build" ? "build" : "dev";
|
|
11
|
+
}
|
|
12
|
+
function m(e) {
|
|
13
|
+
return e?.mode === "build" || f === "build" || process.env.NODE_ENV === "production";
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/dev-runner.ts
|
|
17
|
+
function h(t) {
|
|
18
|
+
let r = t;
|
|
19
|
+
for (;;) {
|
|
20
|
+
let t = n(r, "node_modules/.bin/fluenti");
|
|
21
|
+
if (i(t)) return t;
|
|
22
|
+
let a = e(r);
|
|
23
|
+
if (a === r) break;
|
|
24
|
+
r = a;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
async function g(e) {
|
|
29
|
+
if (e.compileOnly) try {
|
|
30
|
+
let { runCompile: n } = o(t(e.cwd, "package.json"))("@fluenti/cli");
|
|
31
|
+
await n(e.cwd), console.log("[fluenti] Compiling... done"), e.onSuccess?.();
|
|
32
|
+
return;
|
|
33
|
+
} catch (t) {
|
|
34
|
+
let n = t instanceof Error ? t : Error(String(t));
|
|
35
|
+
if (e.throwOnError) throw n;
|
|
36
|
+
console.warn("[fluenti] Compile failed:", n.message), e.onError?.(n);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
let n = h(e.cwd);
|
|
40
|
+
if (!n) {
|
|
41
|
+
let t = "[fluenti] CLI not found — skipping auto-compile. Install @fluenti/cli as a devDependency.";
|
|
42
|
+
return e.throwOnError ? Promise.reject(Error(t)) : (console.warn(t), Promise.resolve());
|
|
43
|
+
}
|
|
44
|
+
let i = `${n} extract && ${n} compile`;
|
|
45
|
+
return new Promise((t, n) => {
|
|
46
|
+
r(i, { cwd: e.cwd }, (r, i, a) => {
|
|
47
|
+
if (r) {
|
|
48
|
+
let t = Error(a || r.message);
|
|
49
|
+
if (e.throwOnError) {
|
|
50
|
+
n(t);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
console.warn("[fluenti] Extract/compile failed:", t.message), e.onError?.(t);
|
|
54
|
+
} else console.log("[fluenti] Extracting and compiling... done"), e.onSuccess?.();
|
|
55
|
+
t();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
9
58
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
59
|
+
function te(e, t = 300) {
|
|
60
|
+
let n = null, r = !1, i = !1;
|
|
61
|
+
async function a() {
|
|
62
|
+
r = !0;
|
|
63
|
+
try {
|
|
64
|
+
await g(e);
|
|
65
|
+
} finally {
|
|
66
|
+
r = !1, i && (i = !1, o());
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function o() {
|
|
70
|
+
n !== null && clearTimeout(n), n = setTimeout(() => {
|
|
71
|
+
n = null, r ? i = !0 : a();
|
|
72
|
+
}, t);
|
|
73
|
+
}
|
|
74
|
+
return o;
|
|
12
75
|
}
|
|
13
76
|
//#endregion
|
|
14
77
|
//#region src/build-transform.ts
|
|
15
|
-
function
|
|
16
|
-
return
|
|
78
|
+
function ne(e) {
|
|
79
|
+
return _(e, "dynamic");
|
|
17
80
|
}
|
|
18
|
-
function
|
|
19
|
-
return
|
|
81
|
+
function re(e) {
|
|
82
|
+
return _(e, "static");
|
|
20
83
|
}
|
|
21
|
-
function
|
|
22
|
-
let
|
|
23
|
-
if (!
|
|
84
|
+
function _(e, t) {
|
|
85
|
+
let n = l(e);
|
|
86
|
+
if (!n || n.type !== "Program") return {
|
|
24
87
|
code: e,
|
|
25
88
|
needsCatalogImport: !1,
|
|
26
89
|
usedHashes: /* @__PURE__ */ new Set()
|
|
27
90
|
};
|
|
28
|
-
let
|
|
29
|
-
if (
|
|
30
|
-
let
|
|
31
|
-
if (
|
|
32
|
-
|
|
91
|
+
let r = v(n), i = [], a = /* @__PURE__ */ new Set();
|
|
92
|
+
if (d(n, (n) => {
|
|
93
|
+
let o = b(e, n, r, t, a);
|
|
94
|
+
if (o) {
|
|
95
|
+
i.push(o);
|
|
33
96
|
return;
|
|
34
97
|
}
|
|
35
|
-
|
|
36
|
-
}),
|
|
98
|
+
ie(n, a);
|
|
99
|
+
}), i.length === 0) return {
|
|
37
100
|
code: e,
|
|
38
101
|
needsCatalogImport: !1,
|
|
39
|
-
usedHashes:
|
|
102
|
+
usedHashes: a
|
|
40
103
|
};
|
|
41
|
-
let
|
|
42
|
-
for (let e =
|
|
43
|
-
let { start: t, end: n, replacement: r } =
|
|
44
|
-
|
|
104
|
+
let o = e;
|
|
105
|
+
for (let e = i.length - 1; e >= 0; e--) {
|
|
106
|
+
let { start: t, end: n, replacement: r } = i[e];
|
|
107
|
+
o = o.slice(0, t) + r + o.slice(n);
|
|
45
108
|
}
|
|
46
109
|
return {
|
|
47
|
-
code:
|
|
110
|
+
code: o,
|
|
48
111
|
needsCatalogImport: !0,
|
|
49
|
-
usedHashes:
|
|
112
|
+
usedHashes: a
|
|
50
113
|
};
|
|
51
114
|
}
|
|
52
|
-
function
|
|
115
|
+
function v(e) {
|
|
53
116
|
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 (
|
|
55
|
-
if (!
|
|
56
|
-
let t =
|
|
117
|
+
for (let t of e.body) if (se(t)) for (let e of t.specifiers) {
|
|
118
|
+
if (!ce(e)) continue;
|
|
119
|
+
let t = H(e);
|
|
57
120
|
t && (t === "useI18n" && n.add(e.local.name), t === "getI18n" && r.add(e.local.name), t === "unref" && i.add(e.local.name));
|
|
58
121
|
}
|
|
59
|
-
return
|
|
60
|
-
if (!
|
|
61
|
-
if (
|
|
62
|
-
|
|
122
|
+
return d(e, (e) => {
|
|
123
|
+
if (!N(e) || !e.init || !P(e.id)) return;
|
|
124
|
+
if (L(e.init) && z(e.init.callee) && n.has(e.init.callee.name)) {
|
|
125
|
+
y(e.id, t);
|
|
63
126
|
return;
|
|
64
127
|
}
|
|
65
128
|
let i = e.init.type === "AwaitExpression" ? e.init.argument : null;
|
|
66
|
-
i &&
|
|
129
|
+
i && L(i) && z(i.callee) && r.has(i.callee.name) && y(e.id, t);
|
|
67
130
|
}), {
|
|
68
131
|
tracked: t,
|
|
69
132
|
unref: i
|
|
70
133
|
};
|
|
71
134
|
}
|
|
72
|
-
function
|
|
73
|
-
for (let n of e.properties) !
|
|
135
|
+
function y(e, t) {
|
|
136
|
+
for (let n of e.properties) !I(n) || n.computed || !z(n.key) || n.key.name !== "t" || z(n.value) && t.add(n.value.name);
|
|
74
137
|
}
|
|
75
|
-
function
|
|
76
|
-
if (!
|
|
77
|
-
let a =
|
|
138
|
+
function b(e, t, n, r, i) {
|
|
139
|
+
if (!L(t) || t.start == null || t.end == null) return;
|
|
140
|
+
let a = x(e, t, n);
|
|
78
141
|
if (!a) return;
|
|
79
|
-
let { catalogId:
|
|
80
|
-
i.add(
|
|
81
|
-
let c = o
|
|
142
|
+
let { catalogId: o } = a;
|
|
143
|
+
i.add(o);
|
|
144
|
+
let c = s(o), l = r === "dynamic" ? `__catalog[${JSON.stringify(o)}]` : `_${c}`, u = a.valuesSource ? `${l}(${a.valuesSource})` : l;
|
|
82
145
|
return {
|
|
83
146
|
start: t.start,
|
|
84
147
|
end: t.end,
|
|
85
148
|
replacement: u
|
|
86
149
|
};
|
|
87
150
|
}
|
|
88
|
-
function
|
|
151
|
+
function x(e, t, n) {
|
|
89
152
|
if (t.arguments.length === 0) return;
|
|
90
|
-
let r = t.callee, i =
|
|
153
|
+
let r = t.callee, i = z(r) && (n.tracked.has(r.name) || r.name === "$t"), a = R(r) && !r.computed && z(r.property) && (r.property.name === "$t" || r.property.name === "t" && z(r.object) && (r.object.name === "_ctx" || r.object.name === "$setup")), o = L(r) && z(r.callee) && n.unref.has(r.callee.name) && r.arguments.length === 1 && z(r.arguments[0]) && n.tracked.has(r.arguments[0].name);
|
|
91
154
|
if (!i && !a && !o) return;
|
|
92
|
-
let s =
|
|
155
|
+
let s = S(t.arguments[0]);
|
|
93
156
|
if (!s) return;
|
|
94
157
|
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
158
|
return c === void 0 ? { catalogId: s } : {
|
|
@@ -97,69 +160,69 @@ function v(e, t, n) {
|
|
|
97
160
|
valuesSource: c
|
|
98
161
|
};
|
|
99
162
|
}
|
|
100
|
-
function
|
|
101
|
-
let t =
|
|
102
|
-
if (t !== void 0) return
|
|
103
|
-
if (!
|
|
163
|
+
function S(e) {
|
|
164
|
+
let t = j(e);
|
|
165
|
+
if (t !== void 0) return s(t);
|
|
166
|
+
if (!F(e)) return;
|
|
104
167
|
let n, r, i;
|
|
105
168
|
for (let t of e.properties) {
|
|
106
|
-
if (!
|
|
107
|
-
let e =
|
|
169
|
+
if (!I(t) || t.computed) continue;
|
|
170
|
+
let e = M(t.key);
|
|
108
171
|
if (!e) continue;
|
|
109
|
-
let a =
|
|
172
|
+
let a = j(t.value);
|
|
110
173
|
a !== void 0 && (e === "id" && (n = a), e === "message" && (r = a), e === "context" && (i = a));
|
|
111
174
|
}
|
|
112
175
|
if (n) return n;
|
|
113
|
-
if (r) return
|
|
176
|
+
if (r) return s(r, i);
|
|
114
177
|
}
|
|
115
|
-
function
|
|
116
|
-
if (!
|
|
117
|
-
let n =
|
|
178
|
+
function ie(e, t) {
|
|
179
|
+
if (!B(e)) return;
|
|
180
|
+
let n = oe(e.openingElement.name);
|
|
118
181
|
if (n) {
|
|
119
182
|
if (n === "Trans") {
|
|
120
|
-
let n =
|
|
183
|
+
let n = O(e.openingElement, "__id") ?? O(e.openingElement, "id");
|
|
121
184
|
if (n) {
|
|
122
185
|
t.add(n);
|
|
123
186
|
return;
|
|
124
187
|
}
|
|
125
|
-
let r =
|
|
126
|
-
r && t.add(
|
|
188
|
+
let r = O(e.openingElement, "__message"), i = O(e.openingElement, "context");
|
|
189
|
+
r && t.add(s(r, i));
|
|
127
190
|
return;
|
|
128
191
|
}
|
|
129
192
|
if (n === "Plural") {
|
|
130
|
-
let n =
|
|
193
|
+
let n = C(e.openingElement);
|
|
131
194
|
n && t.add(n);
|
|
132
195
|
return;
|
|
133
196
|
}
|
|
134
197
|
if (n === "Select") {
|
|
135
|
-
let n =
|
|
198
|
+
let n = w(e.openingElement);
|
|
136
199
|
n && t.add(n);
|
|
137
200
|
}
|
|
138
201
|
}
|
|
139
202
|
}
|
|
140
|
-
function
|
|
141
|
-
let t =
|
|
203
|
+
function C(e) {
|
|
204
|
+
let t = O(e, "id");
|
|
142
205
|
if (t) return t;
|
|
143
|
-
let n =
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
206
|
+
let n = O(e, "context"), r = ae(e, "offset"), i = [
|
|
207
|
+
O(e, "zero") === void 0 ? void 0 : `=0 {${O(e, "zero")}}`,
|
|
208
|
+
O(e, "one") === void 0 ? void 0 : `one {${O(e, "one")}}`,
|
|
209
|
+
O(e, "two") === void 0 ? void 0 : `two {${O(e, "two")}}`,
|
|
210
|
+
O(e, "few") === void 0 ? void 0 : `few {${O(e, "few")}}`,
|
|
211
|
+
O(e, "many") === void 0 ? void 0 : `many {${O(e, "many")}}`,
|
|
212
|
+
O(e, "other") === void 0 ? void 0 : `other {${O(e, "other")}}`
|
|
150
213
|
].filter(Boolean);
|
|
151
|
-
if (i.length !== 0) return
|
|
214
|
+
if (i.length !== 0) return s(`{count, plural,${typeof r == "number" ? ` offset:${r}` : ""} ${i.join(" ")}}`, n);
|
|
152
215
|
}
|
|
153
|
-
function
|
|
154
|
-
let t =
|
|
216
|
+
function w(e) {
|
|
217
|
+
let t = O(e, "id");
|
|
155
218
|
if (t) return t;
|
|
156
|
-
let n =
|
|
157
|
-
if (!(!r || r.other === void 0)) return
|
|
219
|
+
let n = O(e, "context"), r = T(e);
|
|
220
|
+
if (!(!r || r.other === void 0)) return s(`{value, select, ${[...Object.keys(r).filter((e) => e !== "other").sort(), "other"].map((e) => `${e} {${r[e]}}`).join(" ")}}`, n);
|
|
158
221
|
}
|
|
159
|
-
function
|
|
160
|
-
let t =
|
|
222
|
+
function T(e) {
|
|
223
|
+
let t = D(e, "options");
|
|
161
224
|
if (t) {
|
|
162
|
-
let n =
|
|
225
|
+
let n = O(e, "other");
|
|
163
226
|
return {
|
|
164
227
|
...t,
|
|
165
228
|
...n === void 0 ? {} : { other: n }
|
|
@@ -167,7 +230,7 @@ function C(e) {
|
|
|
167
230
|
}
|
|
168
231
|
let n = {};
|
|
169
232
|
for (let t of e.attributes) {
|
|
170
|
-
if (!
|
|
233
|
+
if (!V(t)) continue;
|
|
171
234
|
let e = t.name.name;
|
|
172
235
|
if ([
|
|
173
236
|
"value",
|
|
@@ -176,128 +239,149 @@ function C(e) {
|
|
|
176
239
|
"comment",
|
|
177
240
|
"options"
|
|
178
241
|
].includes(e)) continue;
|
|
179
|
-
let r =
|
|
242
|
+
let r = A(t);
|
|
180
243
|
r !== void 0 && (n[e] = r);
|
|
181
244
|
}
|
|
182
245
|
return Object.keys(n).length > 0 ? n : void 0;
|
|
183
246
|
}
|
|
184
|
-
function
|
|
185
|
-
if (!
|
|
247
|
+
function E(e) {
|
|
248
|
+
if (!F(e)) return;
|
|
186
249
|
let t = {};
|
|
187
250
|
for (let n of e.properties) {
|
|
188
|
-
if (!
|
|
189
|
-
let e =
|
|
251
|
+
if (!I(n) || n.computed) return;
|
|
252
|
+
let e = M(n.key), r = j(n.value);
|
|
190
253
|
if (!e || r === void 0) return;
|
|
191
254
|
t[e] = r;
|
|
192
255
|
}
|
|
193
256
|
return t;
|
|
194
257
|
}
|
|
195
|
-
function
|
|
196
|
-
let n =
|
|
197
|
-
if (n?.value && n.value.type === "JSXExpressionContainer") return
|
|
258
|
+
function D(e, t) {
|
|
259
|
+
let n = k(e, t);
|
|
260
|
+
if (n?.value && n.value.type === "JSXExpressionContainer") return E(n.value.expression);
|
|
198
261
|
}
|
|
199
|
-
function
|
|
200
|
-
return
|
|
262
|
+
function O(e, t) {
|
|
263
|
+
return A(k(e, t));
|
|
201
264
|
}
|
|
202
|
-
function
|
|
203
|
-
let n =
|
|
265
|
+
function ae(e, t) {
|
|
266
|
+
let n = k(e, t);
|
|
204
267
|
if (!n?.value || n.value.type !== "JSXExpressionContainer") return;
|
|
205
268
|
let r = n.value.expression;
|
|
206
269
|
return r.type === "NumericLiteral" ? r.value : void 0;
|
|
207
270
|
}
|
|
208
|
-
function
|
|
209
|
-
return e.attributes.find((e) =>
|
|
271
|
+
function k(e, t) {
|
|
272
|
+
return e.attributes.find((e) => V(e) && e.name.name === t);
|
|
210
273
|
}
|
|
211
|
-
function
|
|
274
|
+
function A(e) {
|
|
212
275
|
if (e?.value) {
|
|
213
276
|
if (e.value.type === "StringLiteral") return e.value.value;
|
|
214
|
-
if (e.value.type === "JSXExpressionContainer") return
|
|
277
|
+
if (e.value.type === "JSXExpressionContainer") return j(e.value.expression);
|
|
215
278
|
}
|
|
216
279
|
}
|
|
217
|
-
function
|
|
280
|
+
function oe(e) {
|
|
218
281
|
return e.type === "JSXIdentifier" ? e.name : void 0;
|
|
219
282
|
}
|
|
220
|
-
function
|
|
283
|
+
function j(e) {
|
|
221
284
|
if (e.type === "StringLiteral") return e.value;
|
|
222
285
|
if (e.type === "TemplateLiteral") {
|
|
223
286
|
let t = e;
|
|
224
287
|
if (t.expressions.length === 0 && t.quasis.length === 1) return t.quasis[0].value.cooked ?? t.quasis[0].value.raw;
|
|
225
288
|
}
|
|
226
289
|
}
|
|
227
|
-
function
|
|
228
|
-
if (
|
|
290
|
+
function M(e) {
|
|
291
|
+
if (z(e)) return e.name;
|
|
229
292
|
if (e.type === "StringLiteral") return e.value;
|
|
230
293
|
}
|
|
231
|
-
function
|
|
294
|
+
function se(e) {
|
|
232
295
|
return e.type === "ImportDeclaration";
|
|
233
296
|
}
|
|
234
|
-
function
|
|
297
|
+
function ce(e) {
|
|
235
298
|
return e.type === "ImportSpecifier";
|
|
236
299
|
}
|
|
237
|
-
function
|
|
300
|
+
function N(e) {
|
|
238
301
|
return e.type === "VariableDeclarator";
|
|
239
302
|
}
|
|
240
|
-
function
|
|
303
|
+
function P(e) {
|
|
241
304
|
return e.type === "ObjectPattern";
|
|
242
305
|
}
|
|
243
|
-
function
|
|
306
|
+
function F(e) {
|
|
244
307
|
return e.type === "ObjectExpression";
|
|
245
308
|
}
|
|
246
|
-
function
|
|
309
|
+
function I(e) {
|
|
247
310
|
return e.type === "ObjectProperty";
|
|
248
311
|
}
|
|
249
|
-
function
|
|
312
|
+
function L(e) {
|
|
250
313
|
return e.type === "CallExpression";
|
|
251
314
|
}
|
|
252
|
-
function
|
|
315
|
+
function R(e) {
|
|
253
316
|
return e.type === "MemberExpression";
|
|
254
317
|
}
|
|
255
|
-
function
|
|
318
|
+
function z(e) {
|
|
256
319
|
return e?.type === "Identifier";
|
|
257
320
|
}
|
|
258
|
-
function
|
|
321
|
+
function B(e) {
|
|
259
322
|
return e.type === "JSXElement";
|
|
260
323
|
}
|
|
261
|
-
function
|
|
324
|
+
function V(e) {
|
|
262
325
|
return e.type === "JSXAttribute";
|
|
263
326
|
}
|
|
264
|
-
function
|
|
327
|
+
function H(e) {
|
|
265
328
|
let t = e.imported;
|
|
266
329
|
if (t.type === "Identifier") return t.name;
|
|
267
330
|
if (t.type === "StringLiteral") return t.value;
|
|
268
331
|
}
|
|
269
|
-
function
|
|
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) => `_${
|
|
332
|
+
function U(e, t, n) {
|
|
333
|
+
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) => `_${s(e)}`).join(", ")} } from 'virtual:fluenti/messages';\n${e}`;
|
|
271
334
|
}
|
|
272
335
|
//#endregion
|
|
273
336
|
//#region src/virtual-modules.ts
|
|
274
|
-
var
|
|
275
|
-
function
|
|
276
|
-
if (e ===
|
|
277
|
-
if (e ===
|
|
278
|
-
if (e ===
|
|
279
|
-
}
|
|
280
|
-
function
|
|
281
|
-
if (e ===
|
|
282
|
-
if (e ===
|
|
283
|
-
if (e ===
|
|
284
|
-
}
|
|
285
|
-
function
|
|
286
|
-
let {
|
|
287
|
-
for (let e of
|
|
288
|
-
|
|
337
|
+
var W = "virtual:fluenti/runtime", G = "virtual:fluenti/messages", le = "virtual:fluenti/route-runtime", K = "\0virtual:fluenti/runtime", q = "\0virtual:fluenti/messages", J = "\0virtual:fluenti/route-runtime";
|
|
338
|
+
function Y(e) {
|
|
339
|
+
if (e === W) return K;
|
|
340
|
+
if (e === G) return q;
|
|
341
|
+
if (e === le) return J;
|
|
342
|
+
}
|
|
343
|
+
function X(e, t) {
|
|
344
|
+
if (e === K) return ue(t);
|
|
345
|
+
if (e === q) return de(t);
|
|
346
|
+
if (e === J) return fe(t);
|
|
347
|
+
}
|
|
348
|
+
function ue(e) {
|
|
349
|
+
let { locales: t, runtimeGenerator: n } = e;
|
|
350
|
+
for (let e of t) c(e, "vite-plugin");
|
|
351
|
+
return n ? n.generateRuntime(Z(e)) : pe(e);
|
|
352
|
+
}
|
|
353
|
+
function de(e) {
|
|
354
|
+
let { catalogDir: t, defaultBuildLocale: r, sourceLocale: i } = e, a = r || i;
|
|
355
|
+
return `export * from '${n(process.cwd(), t)}/${a}.js'\n`;
|
|
356
|
+
}
|
|
357
|
+
function fe(e) {
|
|
358
|
+
let { locales: t, runtimeGenerator: n } = e;
|
|
359
|
+
for (let e of t) c(e, "vite-plugin");
|
|
360
|
+
return n ? n.generateRouteRuntime(Z(e)) : me(e);
|
|
361
|
+
}
|
|
362
|
+
function Z(e) {
|
|
363
|
+
let { catalogDir: t, locales: n, sourceLocale: r, defaultBuildLocale: i } = e;
|
|
364
|
+
return {
|
|
365
|
+
catalogDir: t,
|
|
366
|
+
locales: n,
|
|
367
|
+
sourceLocale: r,
|
|
368
|
+
defaultBuildLocale: i
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function pe(e) {
|
|
372
|
+
let { catalogDir: t, locales: r, sourceLocale: i, defaultBuildLocale: a, framework: o } = e, s = a || i, c = n(process.cwd(), t), l = `fluenti.runtime.${o}`, u = r.filter((e) => e !== s);
|
|
289
373
|
return o === "react" ? `
|
|
290
|
-
import __defaultMsgs from '${
|
|
374
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
291
375
|
|
|
292
376
|
const __catalog = { ...__defaultMsgs }
|
|
293
|
-
let __currentLocale = '${
|
|
294
|
-
const __loadedLocales = new Set(['${
|
|
377
|
+
let __currentLocale = '${s}'
|
|
378
|
+
const __loadedLocales = new Set(['${s}'])
|
|
295
379
|
let __loading = false
|
|
296
380
|
const __cache = new Map()
|
|
297
381
|
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
298
382
|
|
|
299
383
|
const __loaders = {
|
|
300
|
-
${
|
|
384
|
+
${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
|
|
301
385
|
}
|
|
302
386
|
|
|
303
387
|
async function __switchLocale(locale) {
|
|
@@ -327,22 +411,22 @@ async function __preloadLocale(locale) {
|
|
|
327
411
|
} catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
|
|
328
412
|
}
|
|
329
413
|
|
|
330
|
-
globalThis[Symbol.for('${
|
|
414
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
331
415
|
|
|
332
416
|
export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
|
|
333
417
|
` : o === "vue" ? `
|
|
334
418
|
import { shallowReactive, triggerRef, ref } from 'vue'
|
|
335
|
-
import __defaultMsgs from '${
|
|
419
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
336
420
|
|
|
337
421
|
const __catalog = shallowReactive({ ...__defaultMsgs })
|
|
338
|
-
const __currentLocale = ref('${
|
|
339
|
-
const __loadedLocales = new Set(['${
|
|
422
|
+
const __currentLocale = ref('${s}')
|
|
423
|
+
const __loadedLocales = new Set(['${s}'])
|
|
340
424
|
const __loading = ref(false)
|
|
341
425
|
const __cache = new Map()
|
|
342
426
|
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
343
427
|
|
|
344
428
|
const __loaders = {
|
|
345
|
-
${
|
|
429
|
+
${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
|
|
346
430
|
}
|
|
347
431
|
|
|
348
432
|
async function __switchLocale(locale) {
|
|
@@ -372,23 +456,23 @@ async function __preloadLocale(locale) {
|
|
|
372
456
|
} catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
|
|
373
457
|
}
|
|
374
458
|
|
|
375
|
-
globalThis[Symbol.for('${
|
|
459
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
376
460
|
|
|
377
461
|
export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
|
|
378
462
|
` : `
|
|
379
463
|
import { createSignal } from 'solid-js'
|
|
380
464
|
import { createStore, reconcile } from 'solid-js/store'
|
|
381
|
-
import __defaultMsgs from '${
|
|
465
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
382
466
|
|
|
383
467
|
const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
|
|
384
|
-
const [__currentLocale, __setCurrentLocale] = createSignal('${
|
|
385
|
-
const __loadedLocales = new Set(['${
|
|
468
|
+
const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
|
|
469
|
+
const __loadedLocales = new Set(['${s}'])
|
|
386
470
|
const [__loading, __setLoading] = createSignal(false)
|
|
387
471
|
const __cache = new Map()
|
|
388
472
|
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
389
473
|
|
|
390
474
|
const __loaders = {
|
|
391
|
-
${
|
|
475
|
+
${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
|
|
392
476
|
}
|
|
393
477
|
|
|
394
478
|
async function __switchLocale(locale) {
|
|
@@ -418,33 +502,27 @@ async function __preloadLocale(locale) {
|
|
|
418
502
|
} catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
|
|
419
503
|
}
|
|
420
504
|
|
|
421
|
-
globalThis[Symbol.for('${
|
|
505
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
422
506
|
|
|
423
507
|
export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
|
|
424
508
|
`;
|
|
425
509
|
}
|
|
426
|
-
function
|
|
427
|
-
let { catalogDir:
|
|
428
|
-
return `export * from '${e(process.cwd(), n)}/${a}.js'\n`;
|
|
429
|
-
}
|
|
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);
|
|
510
|
+
function me(e) {
|
|
511
|
+
let { catalogDir: t, locales: r, sourceLocale: i, defaultBuildLocale: a, framework: o } = e, s = a || i, c = n(process.cwd(), t), l = `fluenti.runtime.${o}`, u = r.filter((e) => e !== s);
|
|
434
512
|
return o === "vue" ? `
|
|
435
513
|
import { shallowReactive, ref } from 'vue'
|
|
436
|
-
import __defaultMsgs from '${
|
|
514
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
437
515
|
|
|
438
516
|
const __catalog = shallowReactive({ ...__defaultMsgs })
|
|
439
|
-
const __currentLocale = ref('${
|
|
440
|
-
const __loadedLocales = new Set(['${
|
|
517
|
+
const __currentLocale = ref('${s}')
|
|
518
|
+
const __loadedLocales = new Set(['${s}'])
|
|
441
519
|
const __loading = ref(false)
|
|
442
520
|
const __cache = new Map()
|
|
443
521
|
const __loadedRoutes = new Set()
|
|
444
522
|
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
445
523
|
|
|
446
524
|
const __loaders = {
|
|
447
|
-
${
|
|
525
|
+
${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
|
|
448
526
|
}
|
|
449
527
|
|
|
450
528
|
const __routeLoaders = {}
|
|
@@ -491,24 +569,24 @@ async function __preloadLocale(locale) {
|
|
|
491
569
|
} catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
|
|
492
570
|
}
|
|
493
571
|
|
|
494
|
-
globalThis[Symbol.for('${
|
|
572
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
495
573
|
|
|
496
574
|
export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
|
|
497
575
|
` : `
|
|
498
576
|
import { createSignal } from 'solid-js'
|
|
499
577
|
import { createStore, reconcile } from 'solid-js/store'
|
|
500
|
-
import __defaultMsgs from '${
|
|
578
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
501
579
|
|
|
502
580
|
const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
|
|
503
|
-
const [__currentLocale, __setCurrentLocale] = createSignal('${
|
|
504
|
-
const __loadedLocales = new Set(['${
|
|
581
|
+
const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
|
|
582
|
+
const __loadedLocales = new Set(['${s}'])
|
|
505
583
|
const [__loading, __setLoading] = createSignal(false)
|
|
506
584
|
const __cache = new Map()
|
|
507
585
|
const __loadedRoutes = new Set()
|
|
508
586
|
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
509
587
|
|
|
510
588
|
const __loaders = {
|
|
511
|
-
${
|
|
589
|
+
${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
|
|
512
590
|
}
|
|
513
591
|
|
|
514
592
|
const __routeLoaders = {}
|
|
@@ -555,18 +633,18 @@ async function __preloadLocale(locale) {
|
|
|
555
633
|
} catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
|
|
556
634
|
}
|
|
557
635
|
|
|
558
|
-
globalThis[Symbol.for('${
|
|
636
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
559
637
|
|
|
560
638
|
export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
|
|
561
639
|
`;
|
|
562
640
|
}
|
|
563
641
|
//#endregion
|
|
564
642
|
//#region src/route-resolve.ts
|
|
565
|
-
function
|
|
643
|
+
function Q(e) {
|
|
566
644
|
let t = (e.includes("/") ? e.slice(e.lastIndexOf("/") + 1) : e).replace(/\.[^.]+$/, "");
|
|
567
645
|
return t.replace(/-[a-zA-Z0-9]{4,}$/, "") || t;
|
|
568
646
|
}
|
|
569
|
-
function
|
|
647
|
+
function he(e) {
|
|
570
648
|
let t = /* @__PURE__ */ new Map(), n = e.split("\n");
|
|
571
649
|
for (let e = 0; e < n.length; e++) {
|
|
572
650
|
let r = n[e], i = r.match(/^(?:\/\*.*?\*\/\s*)?export\s+const\s+_([a-z0-9]+)\s*=\s*/);
|
|
@@ -583,345 +661,130 @@ function ue(e) {
|
|
|
583
661
|
}
|
|
584
662
|
return t;
|
|
585
663
|
}
|
|
586
|
-
function
|
|
664
|
+
function $(e, t) {
|
|
587
665
|
let n = [], r = [];
|
|
588
666
|
for (let i of e) {
|
|
589
|
-
let e =
|
|
590
|
-
a && (n.push(a), r.push(` '${
|
|
667
|
+
let e = s(i), a = t.get(e);
|
|
668
|
+
a && (n.push(a), r.push(` '${_e(i)}': _${e},`));
|
|
591
669
|
}
|
|
592
670
|
return r.length > 0 && n.push("", "export default {", ...r, "}"), n.join("\n") + "\n";
|
|
593
671
|
}
|
|
594
|
-
function
|
|
672
|
+
function ge(e, t) {
|
|
595
673
|
try {
|
|
596
|
-
return
|
|
674
|
+
return a(n(e, `${t}.js`), "utf-8");
|
|
597
675
|
} catch {
|
|
598
676
|
return;
|
|
599
677
|
}
|
|
600
678
|
}
|
|
601
|
-
function fe(e) {
|
|
602
|
-
return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
|
|
603
|
-
}
|
|
604
|
-
//#endregion
|
|
605
|
-
//#region src/framework-detect.ts
|
|
606
|
-
function Y(e, t) {
|
|
607
|
-
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";
|
|
608
|
-
}
|
|
609
|
-
//#endregion
|
|
610
|
-
//#region src/sfc-transform.ts
|
|
611
|
-
function X(e) {
|
|
612
|
-
return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
613
|
-
}
|
|
614
|
-
function Z(e, t) {
|
|
615
|
-
return `{ id: '${X(t?.id ?? o(e, t?.context))}', message: '${X(e)}' }`;
|
|
616
|
-
}
|
|
617
|
-
function pe(e) {
|
|
618
|
-
let t = e.match(/<template(\s[^>]*)?>/);
|
|
619
|
-
if (!t) return e;
|
|
620
|
-
let n = t.index + t[0].length, r = e.lastIndexOf("</template>");
|
|
621
|
-
if (r < 0) return e;
|
|
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);
|
|
623
|
-
return !s && !c && !l ? e : (s && (a = me(a), a = ge(a)), c && (a = _e(a)), l && (a = Q(a)), i + a + o);
|
|
624
|
-
}
|
|
625
|
-
function me(e) {
|
|
626
|
-
return e.replace(/<(\w+)(\s[^>]*?)\bv-t\.(\w+)\b([^>]*?)>/g, (e, t, n, r, i) => {
|
|
627
|
-
if (r === "plural") return e;
|
|
628
|
-
let a = n + i, o = RegExp(`\\b${r}="([^"]*)"`), s = a.match(o);
|
|
629
|
-
if (!s) return e;
|
|
630
|
-
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}="[^"]*"`);
|
|
631
|
-
return u = u.replace(f, ""), d = d.replace(f, ""), `<${t}${u} :${r}="$t(${l})"${d}>`;
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
function he(e) {
|
|
635
|
-
let t = [];
|
|
636
|
-
return {
|
|
637
|
-
message: e.replace(/\{\{\s*([^}]+?)\s*\}\}/g, (e, n) => {
|
|
638
|
-
let r = n.trim(), i;
|
|
639
|
-
if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(r)) i = r;
|
|
640
|
-
else if (/^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(r) && !r.endsWith(".")) {
|
|
641
|
-
let e = r.split(".");
|
|
642
|
-
i = e[e.length - 1];
|
|
643
|
-
} else i = String(t.length);
|
|
644
|
-
return t.push(`${i}: ${r}`), `{${i}}`;
|
|
645
|
-
}),
|
|
646
|
-
vars: t
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
function ge(e) {
|
|
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) => {
|
|
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/, "");
|
|
652
|
-
if (s && i) {
|
|
653
|
-
let e = o.trim().split("|").map((e) => e.trim());
|
|
654
|
-
return `<${t}${c}${l}>{{ $t(${Z(`{${i}, plural, ${(e.length === 2 ? ["one", "other"] : [
|
|
655
|
-
"one",
|
|
656
|
-
"other",
|
|
657
|
-
"zero",
|
|
658
|
-
"few",
|
|
659
|
-
"many"
|
|
660
|
-
].slice(0, e.length)).map((t, n) => `${t} {${e[n] ?? ""}}`).join(" ")}}`, { id: r })}, { ${i} }) }}</${t}>`;
|
|
661
|
-
}
|
|
662
|
-
let u = o.trim();
|
|
663
|
-
if (/<(\w+)(\s[^>]*)?>[\s\S]*?<\/\1>/g.test(u)) {
|
|
664
|
-
let e = [], n = 0;
|
|
665
|
-
return `<${t}${c}${l} v-html="$vtRich(${Z(u.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g, (t, r, i, a) => {
|
|
666
|
-
let o = n++, s = {}, c = /(\w+)="([^"]*)"/g, l;
|
|
667
|
-
for (; (l = c.exec(i)) !== null;) s[l[1]] = l[2];
|
|
668
|
-
return e.push({
|
|
669
|
-
tag: r,
|
|
670
|
-
attrs: s
|
|
671
|
-
}), `<${o}>${a}</${o}>`;
|
|
672
|
-
}), { id: r })}, ${`[${e.map((e) => {
|
|
673
|
-
let t = Object.entries(e.attrs).map(([e, t]) => `${e}: '${X(t)}'`).join(", ");
|
|
674
|
-
return `{ tag: '${e.tag}', attrs: { ${t} } }`;
|
|
675
|
-
}).join(", ")}]`})"></${t}>`;
|
|
676
|
-
}
|
|
677
|
-
let { message: d, vars: f } = he(u), p = Z(d, { id: r });
|
|
678
|
-
return f.length > 0 ? `<${t}${c}${l}>{{ $t(${p}, { ${f.join(", ")} }) }}</${t}>` : `<${t}${c}${l}>{{ $t(${p}) }}</${t}>`;
|
|
679
|
-
});
|
|
680
|
-
}
|
|
681
679
|
function _e(e) {
|
|
682
|
-
return e.replace(
|
|
683
|
-
let r = t ?? "";
|
|
684
|
-
if (/\bmessage\s*=/.test(r)) return e;
|
|
685
|
-
let i = $(r, "id");
|
|
686
|
-
if (i.kind === "dynamic") return e;
|
|
687
|
-
let a = $(r, "context");
|
|
688
|
-
if (!i.value && a.kind === "dynamic") return e;
|
|
689
|
-
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();
|
|
690
|
-
if (/<(\w+)(\s[^>]*)?>[\s\S]*?<\/\1>/g.test(c)) {
|
|
691
|
-
let e = [], t = 0;
|
|
692
|
-
return `<${o}${s} v-html="$vtRich(${Z(c.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g, (n, r, i, a) => {
|
|
693
|
-
let o = t++, s = {}, c = /(\w[\w-]*)="([^"]*)"/g, l;
|
|
694
|
-
for (; (l = c.exec(i)) !== null;) s[l[1]] = l[2];
|
|
695
|
-
return e.push({
|
|
696
|
-
tag: r,
|
|
697
|
-
attrs: s
|
|
698
|
-
}), `<${o}>${a}</${o}>`;
|
|
699
|
-
}), {
|
|
700
|
-
id: i.value,
|
|
701
|
-
context: a.value
|
|
702
|
-
})}, ${`[${e.map((e) => {
|
|
703
|
-
let t = Object.entries(e.attrs).map(([e, t]) => `${e}: '${X(t)}'`).join(", ");
|
|
704
|
-
return `{ tag: '${e.tag}', attrs: { ${t} } }`;
|
|
705
|
-
}).join(", ")}]`})"></${o}>`;
|
|
706
|
-
}
|
|
707
|
-
return `<${o}${s}>{{ $t(${Z(c, {
|
|
708
|
-
id: i.value,
|
|
709
|
-
context: a.value
|
|
710
|
-
})}) }}</${o}>`;
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
function Q(e) {
|
|
714
|
-
return e = e.replace(/<Plural(\s[^>]*?)>([\s\S]*?)<\/Plural>/g, (e, t, n) => {
|
|
715
|
-
let r = t ?? "", i = $(r, "id"), a = $(r, "context");
|
|
716
|
-
if (i.kind === "dynamic" || !i.value && a.kind === "dynamic") return e;
|
|
717
|
-
let o = /<template\s+#(\w+)\s*>([\s\S]*?)<\/template>/g, s = [], c;
|
|
718
|
-
for (; (c = o.exec(n)) !== null;) s.push({
|
|
719
|
-
cat: c[1],
|
|
720
|
-
content: c[2].trim()
|
|
721
|
-
});
|
|
722
|
-
if (s.length === 0) return e;
|
|
723
|
-
let l = r.match(/:value\s*=\s*"([^"]*)"/);
|
|
724
|
-
if (!l) return e;
|
|
725
|
-
let u = l[1], d = r.match(/\btag\s*=\s*"([^"]*)"/)?.[1] ?? "span", f = [
|
|
726
|
-
"zero",
|
|
727
|
-
"one",
|
|
728
|
-
"two",
|
|
729
|
-
"few",
|
|
730
|
-
"many",
|
|
731
|
-
"other"
|
|
732
|
-
], p = [], m = [];
|
|
733
|
-
for (let e of f) {
|
|
734
|
-
let t = s.find((t) => t.cat === e);
|
|
735
|
-
if (!t) continue;
|
|
736
|
-
let n = t.content, r = /<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g, i = n;
|
|
737
|
-
if (r.test(n)) {
|
|
738
|
-
let e = p.length, t = 0;
|
|
739
|
-
i = n.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g, (n, r, i, a) => {
|
|
740
|
-
let o = e + t++, s = {}, c = /(\w[\w-]*)="([^"]*)"/g, l;
|
|
741
|
-
for (; (l = c.exec(i)) !== null;) s[l[1]] = l[2];
|
|
742
|
-
return p.push({
|
|
743
|
-
tag: r,
|
|
744
|
-
attrs: s
|
|
745
|
-
}), `<${o}>${a}</${o}>`;
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
let a = e === "zero" ? "=0" : e;
|
|
749
|
-
m.push(`${a} {${i}}`);
|
|
750
|
-
}
|
|
751
|
-
if (m.length === 0) return e;
|
|
752
|
-
let h = Z(`{count, plural, ${m.join(" ")}}`, {
|
|
753
|
-
id: i.value,
|
|
754
|
-
context: a.value
|
|
755
|
-
}), g = r;
|
|
756
|
-
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();
|
|
757
|
-
let _ = g ? ` ${g}` : "";
|
|
758
|
-
return p.length > 0 ? `<${d}${_} v-html="$vtRich(${h}, ${`[${p.map((e) => {
|
|
759
|
-
let t = Object.entries(e.attrs).map(([e, t]) => `${e}: '${X(t)}'`).join(", ");
|
|
760
|
-
return `{ tag: '${e.tag}', attrs: { ${t} } }`;
|
|
761
|
-
}).join(", ")}]`}, { count: ${u} })"></${d}>` : `<${d}${_} v-text="$t(${h}, { count: ${u} })"></${d}>`;
|
|
762
|
-
}), e.replace(/<Plural(\s[^>]*?)\/?>(?:<\/Plural>)?/g, (e, t) => {
|
|
763
|
-
let n = t ?? "", r = $(n, "id"), i = $(n, "context");
|
|
764
|
-
if (r.kind === "dynamic" || !r.value && i.kind === "dynamic") return e;
|
|
765
|
-
let a = n.match(/:value\s*=\s*"([^"]*)"/);
|
|
766
|
-
if (!a) return e;
|
|
767
|
-
let o = a[1], s = n.match(/\btag\s*=\s*"([^"]*)"/)?.[1] ?? "span", c = [
|
|
768
|
-
"zero",
|
|
769
|
-
"one",
|
|
770
|
-
"two",
|
|
771
|
-
"few",
|
|
772
|
-
"many",
|
|
773
|
-
"other"
|
|
774
|
-
], l = [];
|
|
775
|
-
for (let e of c) {
|
|
776
|
-
let t = RegExp(`(?<!:)\\b${e}\\s*=\\s*"([^"]*)"`), r = n.match(t);
|
|
777
|
-
if (r) {
|
|
778
|
-
let t = e === "zero" ? "=0" : e;
|
|
779
|
-
l.push(`${t} {${r[1]}}`);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
if (l.length === 0) return e;
|
|
783
|
-
let u = Z(`{count, plural, ${l.join(" ")}}`, {
|
|
784
|
-
id: r.value,
|
|
785
|
-
context: i.value
|
|
786
|
-
}), d = n;
|
|
787
|
-
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*"[^"]*"/, "");
|
|
788
|
-
for (let e of c) d = d.replace(RegExp(`(?<!:)\\b${e}\\s*=\\s*"[^"]*"`), "");
|
|
789
|
-
return d = d.replace(/\s+/g, " ").trim(), `<${s}${d ? ` ${d}` : ""} v-text="$t(${u}, { count: ${o} })"></${s}>`;
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
|
-
function $(e, t) {
|
|
793
|
-
if (RegExp(`(?:^|\\s):${t}\\s*=`).test(e)) return { kind: "dynamic" };
|
|
794
|
-
let n = e.match(RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`));
|
|
795
|
-
return n ? {
|
|
796
|
-
kind: "static",
|
|
797
|
-
value: n[1] ?? ""
|
|
798
|
-
} : { kind: "missing" };
|
|
799
|
-
}
|
|
800
|
-
//#endregion
|
|
801
|
-
//#region src/solid-jsx-transform.ts
|
|
802
|
-
function ve(e) {
|
|
803
|
-
return {
|
|
804
|
-
code: e,
|
|
805
|
-
changed: !1
|
|
806
|
-
};
|
|
680
|
+
return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
|
|
807
681
|
}
|
|
808
682
|
//#endregion
|
|
809
683
|
//#region src/index.ts
|
|
810
|
-
var
|
|
811
|
-
function
|
|
812
|
-
let
|
|
684
|
+
var ve = "virtual:fluenti/messages/", ye = "\0virtual:fluenti/messages/";
|
|
685
|
+
function be(e, t, r) {
|
|
686
|
+
let i = e.catalogDir ?? "src/locales/compiled", a = e.framework, o = e.splitting ?? !1, s = e.sourceLocale ?? "en", c = e.locales ?? [s], l = e.defaultBuildLocale ?? s, d = {
|
|
813
687
|
name: "fluenti:virtual",
|
|
814
688
|
configResolved(e) {
|
|
815
|
-
|
|
689
|
+
p(e.command);
|
|
816
690
|
},
|
|
817
691
|
resolveId(e) {
|
|
818
|
-
if (e.startsWith(
|
|
819
|
-
if (
|
|
820
|
-
let t =
|
|
692
|
+
if (e.startsWith(ve)) return "\0" + e;
|
|
693
|
+
if (o) {
|
|
694
|
+
let t = Y(e);
|
|
821
695
|
if (t) return t;
|
|
822
696
|
}
|
|
823
697
|
},
|
|
824
698
|
load(e) {
|
|
825
|
-
if (e.startsWith(
|
|
826
|
-
if (
|
|
827
|
-
let t =
|
|
828
|
-
catalogDir:
|
|
829
|
-
locales:
|
|
830
|
-
sourceLocale:
|
|
831
|
-
defaultBuildLocale:
|
|
832
|
-
framework:
|
|
699
|
+
if (e.startsWith(ye)) return `export { default } from '${`${i}/${e.slice(26)}.js`}'`;
|
|
700
|
+
if (o) {
|
|
701
|
+
let t = X(e, {
|
|
702
|
+
catalogDir: i,
|
|
703
|
+
locales: c,
|
|
704
|
+
sourceLocale: s,
|
|
705
|
+
defaultBuildLocale: l,
|
|
706
|
+
framework: a,
|
|
707
|
+
runtimeGenerator: r
|
|
833
708
|
});
|
|
834
709
|
if (t) return t;
|
|
835
710
|
}
|
|
836
711
|
}
|
|
837
|
-
},
|
|
838
|
-
name: "fluenti:vue-template",
|
|
839
|
-
enforce: "pre",
|
|
840
|
-
transform(e, t) {
|
|
841
|
-
if (!t.endsWith(".vue") || !/\bv-t\b/.test(e) && !/<Trans[\s>]/.test(e) && !/<Plural[\s/>]/.test(e)) return;
|
|
842
|
-
let n = pe(e);
|
|
843
|
-
if (n !== e) return {
|
|
844
|
-
code: n,
|
|
845
|
-
map: null
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
|
-
}, v = {
|
|
712
|
+
}, f = {
|
|
849
713
|
name: "fluenti:script-transform",
|
|
850
714
|
enforce: "pre",
|
|
851
715
|
transform(e, t) {
|
|
852
716
|
if (t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/) || t.includes(".vue") && !t.includes("type=script")) return;
|
|
853
|
-
let n = e,
|
|
717
|
+
let n = e, r = !1;
|
|
854
718
|
if (t.match(/\.[jt]sx(\?|$)/) && /<Trans[\s>]/.test(n)) {
|
|
855
|
-
let e =
|
|
856
|
-
e.transformed && (n = e.code,
|
|
719
|
+
let e = ee(n);
|
|
720
|
+
e.transformed && (n = e.code, r = !0);
|
|
857
721
|
}
|
|
858
722
|
if (Se(n)) {
|
|
859
|
-
let e =
|
|
860
|
-
framework:
|
|
861
|
-
allowTopLevelImportedT:
|
|
723
|
+
let e = u(n, {
|
|
724
|
+
framework: a,
|
|
725
|
+
allowTopLevelImportedT: a === "vue" && t.includes(".vue")
|
|
862
726
|
});
|
|
863
|
-
if (
|
|
864
|
-
code:
|
|
727
|
+
if (e.transformed) return {
|
|
728
|
+
code: e.code,
|
|
865
729
|
map: null
|
|
866
730
|
};
|
|
867
731
|
}
|
|
868
|
-
return
|
|
732
|
+
return r ? {
|
|
869
733
|
code: n,
|
|
870
734
|
map: null
|
|
871
735
|
} : void 0;
|
|
872
736
|
}
|
|
873
|
-
},
|
|
737
|
+
}, h = /* @__PURE__ */ new Map(), _ = {
|
|
874
738
|
name: "fluenti:build-split",
|
|
875
739
|
transform(e, t) {
|
|
876
|
-
if (!
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
let i = s === "per-route" ? "per-route" : n;
|
|
740
|
+
if (!o || !m(this.environment) || t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)) return;
|
|
741
|
+
let n = o === "static" ? "static" : "dynamic", r = n === "static" ? re(e) : ne(e);
|
|
742
|
+
if (o === "per-route" && r.usedHashes.size > 0 && h.set(t, r.usedHashes), !r.needsCatalogImport) return;
|
|
743
|
+
let i = o === "per-route" ? "per-route" : n;
|
|
881
744
|
return {
|
|
882
|
-
code:
|
|
745
|
+
code: U(r.code, i, r.usedHashes),
|
|
883
746
|
map: null
|
|
884
747
|
};
|
|
885
748
|
},
|
|
886
|
-
generateBundle(
|
|
887
|
-
if (
|
|
749
|
+
generateBundle(e, t) {
|
|
750
|
+
if (o !== "per-route" || h.size === 0) return;
|
|
888
751
|
let r = /* @__PURE__ */ new Map();
|
|
889
|
-
for (let [e,
|
|
890
|
-
if (
|
|
891
|
-
let
|
|
892
|
-
for (let e of Object.keys(
|
|
893
|
-
let
|
|
894
|
-
if (
|
|
752
|
+
for (let [e, n] of Object.entries(t)) {
|
|
753
|
+
if (n.type !== "chunk") continue;
|
|
754
|
+
let t = /* @__PURE__ */ new Set();
|
|
755
|
+
for (let e of Object.keys(n.modules)) {
|
|
756
|
+
let n = h.get(e);
|
|
757
|
+
if (n) for (let e of n) t.add(e);
|
|
895
758
|
}
|
|
896
|
-
|
|
759
|
+
t.size > 0 && r.set(e, t);
|
|
897
760
|
}
|
|
898
761
|
if (r.size === 0) return;
|
|
899
|
-
let
|
|
762
|
+
let a = /* @__PURE__ */ new Map();
|
|
900
763
|
for (let [e, t] of r) for (let n of t) {
|
|
901
|
-
let t =
|
|
902
|
-
t.push(e),
|
|
764
|
+
let t = a.get(n) ?? [];
|
|
765
|
+
t.push(e), a.set(n, t);
|
|
903
766
|
}
|
|
904
|
-
let
|
|
905
|
-
for (let [e, t] of
|
|
767
|
+
let s = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Map();
|
|
768
|
+
for (let [e, t] of a) if (t.length > 1) s.add(e);
|
|
906
769
|
else {
|
|
907
|
-
let n =
|
|
908
|
-
r.add(e),
|
|
770
|
+
let n = Q(t[0]), r = l.get(n) ?? /* @__PURE__ */ new Set();
|
|
771
|
+
r.add(e), l.set(n, r);
|
|
909
772
|
}
|
|
910
|
-
let u =
|
|
911
|
-
for (let e of
|
|
912
|
-
let t =
|
|
773
|
+
let u = n(process.cwd(), i);
|
|
774
|
+
for (let e of c) {
|
|
775
|
+
let t = ge(u, e);
|
|
913
776
|
if (!t) continue;
|
|
914
|
-
let n =
|
|
915
|
-
if (
|
|
916
|
-
let t =
|
|
777
|
+
let n = he(t);
|
|
778
|
+
if (s.size > 0) {
|
|
779
|
+
let t = $(s, n);
|
|
917
780
|
this.emitFile({
|
|
918
781
|
type: "asset",
|
|
919
782
|
fileName: `_fluenti/shared-${e}.js`,
|
|
920
783
|
source: t
|
|
921
784
|
});
|
|
922
785
|
}
|
|
923
|
-
for (let [t, r] of
|
|
924
|
-
let i =
|
|
786
|
+
for (let [t, r] of l) {
|
|
787
|
+
let i = $(r, n);
|
|
925
788
|
this.emitFile({
|
|
926
789
|
type: "asset",
|
|
927
790
|
fileName: `_fluenti/${t}-${e}.js`,
|
|
@@ -930,55 +793,53 @@ function xe(n) {
|
|
|
930
793
|
}
|
|
931
794
|
}
|
|
932
795
|
}
|
|
933
|
-
},
|
|
934
|
-
name: "fluenti:
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
map: null
|
|
942
|
-
};
|
|
796
|
+
}, v = e.buildAutoCompile ?? !0, y = {
|
|
797
|
+
name: "fluenti:build-compile",
|
|
798
|
+
async buildStart() {
|
|
799
|
+
!m(this.environment) || !v || await g({
|
|
800
|
+
cwd: process.cwd(),
|
|
801
|
+
throwOnError: !0,
|
|
802
|
+
compileOnly: !0
|
|
803
|
+
});
|
|
943
804
|
}
|
|
944
|
-
},
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
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
|
-
},
|
|
969
|
-
hotUpdate({ file: e }) {
|
|
970
|
-
if (e.includes(a)) {
|
|
971
|
-
let e = [...this.environment.moduleGraph.urlToModuleMap.entries()].filter(([e]) => e.includes("virtual:fluenti")).map(([, e]) => e);
|
|
972
|
-
if (e.length > 0) return e;
|
|
973
|
-
}
|
|
805
|
+
}, b = e.devAutoCompile ?? !0, x = e.include ?? ["src/**/*.{vue,tsx,jsx,ts,js}"], S = {
|
|
806
|
+
name: "fluenti:dev",
|
|
807
|
+
configureServer(e) {
|
|
808
|
+
if (!b) return;
|
|
809
|
+
let t = te({
|
|
810
|
+
cwd: e.config.root,
|
|
811
|
+
onSuccess: () => {}
|
|
812
|
+
});
|
|
813
|
+
t(), e.watcher.on("change", (e) => {
|
|
814
|
+
xe(e, x) && !e.includes(i) && t();
|
|
815
|
+
});
|
|
816
|
+
},
|
|
817
|
+
hotUpdate({ file: e }) {
|
|
818
|
+
if (e.includes(i)) {
|
|
819
|
+
let e = [...this.environment.moduleGraph.urlToModuleMap.entries()].filter(([e]) => e.includes("virtual:fluenti")).map(([, e]) => e);
|
|
820
|
+
if (e.length > 0) return e;
|
|
974
821
|
}
|
|
975
822
|
}
|
|
823
|
+
};
|
|
824
|
+
return [
|
|
825
|
+
d,
|
|
826
|
+
...t,
|
|
827
|
+
f,
|
|
828
|
+
y,
|
|
829
|
+
_,
|
|
830
|
+
S
|
|
976
831
|
];
|
|
977
832
|
}
|
|
833
|
+
function xe(e, t) {
|
|
834
|
+
return !/\.(vue|tsx|jsx|ts|js)$/.test(e) || e.includes("node_modules") ? !1 : t.some((t) => {
|
|
835
|
+
let n = t.split("*")[0] ?? "";
|
|
836
|
+
return n === "" || e.includes(n.replace("./", ""));
|
|
837
|
+
});
|
|
838
|
+
}
|
|
978
839
|
function Se(e) {
|
|
979
840
|
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);
|
|
980
841
|
}
|
|
981
842
|
//#endregion
|
|
982
|
-
export {
|
|
843
|
+
export { be as createFluentiPlugins, m as isBuildMode, X as loadVirtualSplitModule, Y as resolveVirtualSplitId, p as setResolvedMode };
|
|
983
844
|
|
|
984
845
|
//# sourceMappingURL=index.js.map
|