@fluenti/cli 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.
@@ -0,0 +1,733 @@
1
+ import { parse as e } from "@vue/compiler-sfc";
2
+ import { createMessageId as t, isSourceNode as n, parseSourceModule as r, walkSourceAst as i } from "@fluenti/core/internal";
3
+ import { hashMessage as a, parse as o } from "@fluenti/core";
4
+ import * as s from "gettext-parser";
5
+ //#region src/tsx-extractor.ts
6
+ var c = new Set([
7
+ "@fluenti/react",
8
+ "@fluenti/vue",
9
+ "@fluenti/solid",
10
+ "@fluenti/next/__generated"
11
+ ]);
12
+ function l(e) {
13
+ let t = e.trim();
14
+ if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t)) return t;
15
+ if (/^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(t) && !t.endsWith(".")) {
16
+ let e = t.split(".");
17
+ return e[e.length - 1];
18
+ }
19
+ return "";
20
+ }
21
+ function u(e, t) {
22
+ let n = "", r = 0;
23
+ for (let i = 0; i < e.length; i++) {
24
+ if (n += e[i], i >= t.length) continue;
25
+ let a = l(t[i]);
26
+ if (a === "") {
27
+ n += `{${r}}`, r++;
28
+ continue;
29
+ }
30
+ n += `{${a}}`;
31
+ }
32
+ return n;
33
+ }
34
+ function d(e, t, n) {
35
+ if (!e.message) return;
36
+ let r = n.loc?.start.line ?? 1, i = (n.loc?.start.column ?? 0) + 1;
37
+ return {
38
+ id: e.id,
39
+ message: e.message,
40
+ ...e.context === void 0 ? {} : { context: e.context },
41
+ ...e.comment === void 0 ? {} : { comment: e.comment },
42
+ origin: {
43
+ file: t,
44
+ line: r,
45
+ column: i
46
+ }
47
+ };
48
+ }
49
+ function f(e) {
50
+ if (e.message) return {
51
+ id: e.id ?? t(e.message, e.context),
52
+ message: e.message,
53
+ ...e.context === void 0 ? {} : { context: e.context },
54
+ ...e.comment === void 0 ? {} : { comment: e.comment }
55
+ };
56
+ }
57
+ function p(e) {
58
+ if (e.type === "StringLiteral") return f({ message: e.value });
59
+ if (e.type === "TemplateLiteral") {
60
+ let t = e;
61
+ return t.expressions.length === 0 ? f({ message: t.quasis.map((e) => e.value.cooked ?? e.value.raw).join("") }) : void 0;
62
+ }
63
+ if (e.type !== "ObjectExpression") return;
64
+ let t = {};
65
+ for (let n of e.properties) {
66
+ if (n.type !== "ObjectProperty") continue;
67
+ let e = n;
68
+ if (e.computed || !E(e.key)) continue;
69
+ let r = e.key.name;
70
+ if (![
71
+ "id",
72
+ "message",
73
+ "context",
74
+ "comment"
75
+ ].includes(r)) continue;
76
+ let i = g(e.value);
77
+ i !== void 0 && (t[r] = i);
78
+ }
79
+ if (t.message) return f(t);
80
+ }
81
+ function ee(e) {
82
+ let t = [
83
+ "zero",
84
+ "one",
85
+ "two",
86
+ "few",
87
+ "many",
88
+ "other"
89
+ ], n = e.value ?? e.count ?? "count", r = [], i = e.offset;
90
+ for (let n of t) {
91
+ let t = e[n];
92
+ if (t === void 0) continue;
93
+ let i = n === "zero" ? "=0" : n;
94
+ r.push(`${i} {${t}}`);
95
+ }
96
+ return r.length === 0 ? "" : `{${n}, plural, ${i ? `offset:${i} ` : ""}${r.join(" ")}}`;
97
+ }
98
+ function m(e) {
99
+ let t = 0;
100
+ function n(e) {
101
+ let r = "";
102
+ for (let i of e) {
103
+ if (i.type === "JSXText") {
104
+ r += h(i.value);
105
+ continue;
106
+ }
107
+ if (i.type === "JSXElement") {
108
+ let e = t++, a = n(i.children);
109
+ if (a === void 0) return;
110
+ r += `<${e}>${a}</${e}>`;
111
+ continue;
112
+ }
113
+ if (i.type === "JSXFragment") {
114
+ let e = n(i.children);
115
+ if (e === void 0) return;
116
+ r += e;
117
+ continue;
118
+ }
119
+ if (i.type === "JSXExpressionContainer") {
120
+ let e = i.expression;
121
+ if (e.type === "StringLiteral") {
122
+ r += e.value;
123
+ continue;
124
+ }
125
+ if (e.type === "NumericLiteral") {
126
+ r += String(e.value);
127
+ continue;
128
+ }
129
+ return;
130
+ }
131
+ }
132
+ return r;
133
+ }
134
+ let r = n(e);
135
+ if (r !== void 0) return r.replace(/\s+/g, " ").trim() || void 0;
136
+ }
137
+ function h(e) {
138
+ return e.replace(/\s+/g, " ");
139
+ }
140
+ function g(e) {
141
+ if (e.type === "StringLiteral") return e.value;
142
+ if (e.type === "NumericLiteral") return String(e.value);
143
+ if (e.type === "JSXExpressionContainer") return g(e.expression);
144
+ if (e.type === "TemplateLiteral") {
145
+ let t = e;
146
+ if (t.expressions.length === 0) return t.quasis.map((e) => e.value.cooked ?? e.value.raw).join("");
147
+ }
148
+ }
149
+ function _(e, t) {
150
+ if (!(e.start == null || e.end == null)) return e.type === "JSXExpressionContainer" ? _(e.expression, t) : t.slice(e.start, e.end).trim();
151
+ }
152
+ function v(e, t) {
153
+ for (let n of e.attributes) {
154
+ if (n.type !== "JSXAttribute") continue;
155
+ let e = n;
156
+ if (e.name.type === "JSXIdentifier" && e.name.name === t) return e;
157
+ }
158
+ }
159
+ function te(e, t) {
160
+ let n = {};
161
+ for (let r of [
162
+ "id",
163
+ "value",
164
+ "count",
165
+ "offset",
166
+ "zero",
167
+ "one",
168
+ "two",
169
+ "few",
170
+ "many",
171
+ "other"
172
+ ]) {
173
+ let i = v(e, r);
174
+ if (!i?.value) continue;
175
+ let a = g(i.value);
176
+ if (a !== void 0) {
177
+ n[r] = a;
178
+ continue;
179
+ }
180
+ let o = _(i.value, t);
181
+ o !== void 0 && (r === "value" || r === "count" || r === "offset") && (n[r] = o);
182
+ }
183
+ return n;
184
+ }
185
+ function ne(e, n) {
186
+ let r = u(n.quasi.quasis.map((e) => e.value.cooked ?? e.value.raw), n.quasi.expressions.map((t) => t.start == null || t.end == null ? "" : e.slice(t.start, t.end)));
187
+ return {
188
+ id: t(r),
189
+ message: r
190
+ };
191
+ }
192
+ function y(e) {
193
+ let t = /* @__PURE__ */ new Set(), n = Array.isArray(e.body) ? e.body : [];
194
+ for (let e of n) if (x(e) && c.has(e.source.value)) for (let n of e.specifiers) S(n) && C(n) === "t" && t.add(n.local.name);
195
+ return t;
196
+ }
197
+ function b(e, n) {
198
+ let a = r(e);
199
+ if (!a) return [];
200
+ let o = [], s = y(a);
201
+ return i(a, (r) => {
202
+ if (r.type === "TaggedTemplateExpression") {
203
+ let t = r;
204
+ if (E(t.tag) && (t.tag.name === "t" || s.has(t.tag.name))) {
205
+ let r = d(ne(e, t), n, t);
206
+ r && o.push(r);
207
+ }
208
+ return;
209
+ }
210
+ if (r.type === "CallExpression") {
211
+ let e = r;
212
+ if (E(e.callee) && (e.callee.name === "t" || s.has(e.callee.name))) {
213
+ if (s.has(e.callee.name) && e.arguments[0]?.type !== "ObjectExpression") return;
214
+ let t = e.arguments[0] ? p(e.arguments[0]) : void 0, r = t ? d(t, n, e) : void 0;
215
+ r && o.push(r);
216
+ }
217
+ return;
218
+ }
219
+ if (r.type !== "JSXElement") return;
220
+ let i = r, a = i.openingElement, c = w(a.name);
221
+ if (c === "Trans") {
222
+ let e = v(a, "message"), t = v(a, "id"), r = v(a, "context"), s = v(a, "comment"), c = e?.value ? T({
223
+ id: t?.value ? g(t.value) : void 0,
224
+ message: g(e.value),
225
+ context: r?.value ? g(r.value) : void 0,
226
+ comment: s?.value ? g(s.value) : void 0
227
+ }) : T({
228
+ id: t?.value ? g(t.value) : void 0,
229
+ message: m(i.children),
230
+ context: r?.value ? g(r.value) : void 0,
231
+ comment: s?.value ? g(s.value) : void 0
232
+ }), l = c ? d(c, n, i) : void 0;
233
+ l && o.push(l);
234
+ return;
235
+ }
236
+ if (c === "Plural") {
237
+ let r = te(a, e), s = ee(r);
238
+ if (!s) return;
239
+ let c = d({
240
+ id: r.id ?? t(s),
241
+ message: s
242
+ }, n, i);
243
+ c && o.push(c);
244
+ }
245
+ }), o;
246
+ }
247
+ function x(e) {
248
+ return n(e) && e.type === "ImportDeclaration";
249
+ }
250
+ function S(e) {
251
+ return n(e) && e.type === "ImportSpecifier";
252
+ }
253
+ function C(e) {
254
+ if (e.imported.type === "Identifier") return e.imported.name;
255
+ if (e.imported.type === "StringLiteral") return e.imported.value;
256
+ }
257
+ function w(e) {
258
+ if (e.type === "JSXIdentifier") return String(e.name);
259
+ }
260
+ function T(e) {
261
+ let t = {};
262
+ return e.id !== void 0 && (t.id = e.id), e.message !== void 0 && (t.message = e.message), e.context !== void 0 && (t.context = e.context), e.comment !== void 0 && (t.comment = e.comment), f(t);
263
+ }
264
+ function E(e) {
265
+ return n(e) && e.type === "Identifier";
266
+ }
267
+ //#endregion
268
+ //#region src/vue-extractor.ts
269
+ var D = 1, O = 2, k = 7, A = 6;
270
+ function j(e) {
271
+ return e.filter((e) => e.type === O).map((e) => (e.content ?? "").trim()).join("");
272
+ }
273
+ function M(e, t) {
274
+ let n = e.split("|").map((e) => e.trim()), r = [
275
+ "one",
276
+ "other",
277
+ "zero",
278
+ "few",
279
+ "many"
280
+ ], i = [];
281
+ if (n.length === 2) i.push(`one {${n[0]}}`), i.push(`other {${n[1]}}`);
282
+ else for (let e = 0; e < n.length && e < r.length; e++) i.push(`${r[e]} {${n[e]}}`);
283
+ return `{${t}, plural, ${i.join(" ")}}`;
284
+ }
285
+ function N(e) {
286
+ let t = e.count ?? "count", n = [
287
+ "zero",
288
+ "one",
289
+ "two",
290
+ "few",
291
+ "many",
292
+ "other"
293
+ ], r = [], i = e.offset;
294
+ for (let t of n) if (e[t] !== void 0) {
295
+ let n = t === "zero" ? "=0" : t;
296
+ r.push(`${n} {${e[t]}}`);
297
+ }
298
+ return r.length === 0 ? "" : `{${t}, plural, ${i ? `offset:${i} ` : ""}${r.join(" ")}}`;
299
+ }
300
+ function P(e, n, r) {
301
+ if (e.type === D) {
302
+ let i = e.props?.find((e) => e.type === k && I(e) === "t");
303
+ if (i) {
304
+ let a = new Set(["plural"]), o = (i.modifiers ?? []).map((e) => typeof e == "string" ? e : e.content), s = o.includes("plural"), c = o.filter((e) => !a.has(e)), l = i.arg?.content, u = l ? [l, ...c].join(".") : void 0, d = j(e.children ?? []);
305
+ if (s) {
306
+ let e = M(d, i.exp?.content ?? "count"), a = u ?? t(e);
307
+ r.push({
308
+ id: a,
309
+ message: e,
310
+ origin: {
311
+ file: n,
312
+ line: i.loc.start.line,
313
+ column: i.loc.start.column
314
+ }
315
+ });
316
+ } else if (d) {
317
+ let e = u ?? t(d);
318
+ r.push({
319
+ id: e,
320
+ message: d,
321
+ origin: {
322
+ file: n,
323
+ line: i.loc.start.line,
324
+ column: i.loc.start.column
325
+ }
326
+ });
327
+ }
328
+ }
329
+ if (e.tag === "Trans") {
330
+ let i = e.props?.find((e) => e.type === A && I(e) === "message"), a = e.props?.find((e) => e.type === A && I(e) === "id"), o = e.props?.find((e) => e.type === A && I(e) === "context"), s = e.props?.find((e) => e.type === A && I(e) === "comment"), c = o?.value?.content, l = s?.value?.content;
331
+ if (i?.value) {
332
+ let o = i.value.content, s = a?.value?.content ?? t(o, c);
333
+ r.push({
334
+ id: s,
335
+ message: o,
336
+ ...c === void 0 ? {} : { context: c },
337
+ ...l === void 0 ? {} : { comment: l },
338
+ origin: {
339
+ file: n,
340
+ line: e.loc.start.line,
341
+ column: e.loc.start.column
342
+ }
343
+ });
344
+ } else if (e.children && e.children.length > 0) {
345
+ let i = F(e.children);
346
+ if (i.message) {
347
+ let o = a?.value?.content ?? t(i.message, c);
348
+ r.push({
349
+ id: o,
350
+ message: i.message,
351
+ ...c === void 0 ? {} : { context: c },
352
+ ...l === void 0 ? {} : { comment: l },
353
+ origin: {
354
+ file: n,
355
+ line: e.loc.start.line,
356
+ column: e.loc.start.column
357
+ }
358
+ });
359
+ }
360
+ }
361
+ }
362
+ if (e.tag === "Plural") {
363
+ let i = {}, a, o;
364
+ for (let t of e.props ?? []) t.type === A && t.value && (i[I(t)] = t.value.content), t.type === k && I(t) === "bind" && t.arg?.content === "value" && t.exp && (a = t.exp.content), t.type === k && I(t) === "bind" && t.arg?.content === "offset" && t.exp && (o = t.exp.content);
365
+ let s = a ?? i.count ?? "count", c = o ?? i.offset, l = N({
366
+ ...i,
367
+ count: s,
368
+ ...c === void 0 ? {} : { offset: c }
369
+ });
370
+ if (l) {
371
+ let a = i.id ?? t(l);
372
+ r.push({
373
+ id: a,
374
+ message: l,
375
+ origin: {
376
+ file: n,
377
+ line: e.loc.start.line,
378
+ column: e.loc.start.column
379
+ }
380
+ });
381
+ }
382
+ }
383
+ }
384
+ if (e.children) for (let t of e.children) P(t, n, r);
385
+ }
386
+ function F(e) {
387
+ let t = 0, n = !1;
388
+ return {
389
+ message: e.map((e) => {
390
+ if (e.type === O) return (e.content ?? "").trim() ? e.content ?? "" : "";
391
+ if (e.type === D && e.tag) {
392
+ n = !0;
393
+ let r = t++;
394
+ return `<${r}>${F(e.children ?? []).message}</${r}>`;
395
+ }
396
+ return "";
397
+ }).join("").trim(),
398
+ hasElements: n
399
+ };
400
+ }
401
+ function I(e) {
402
+ return typeof e.name == "string" ? e.name : e.name.content;
403
+ }
404
+ function L(e, t) {
405
+ let n = [], r = /\{\{([\s\S]*?)\}\}/g, i;
406
+ for (; (i = r.exec(e)) !== null;) {
407
+ let r = i[1]?.trim();
408
+ if (!r) continue;
409
+ let a = b(r, t);
410
+ if (a.length === 0) continue;
411
+ let o = e.slice(0, i.index).split("\n").length - 1;
412
+ for (let e of a) n.push({
413
+ ...e,
414
+ origin: {
415
+ ...e.origin,
416
+ line: e.origin.line + o
417
+ }
418
+ });
419
+ }
420
+ return n;
421
+ }
422
+ function R(t, n) {
423
+ let r = [], { descriptor: i } = e(t, { filename: n });
424
+ if (i.template?.ast && P(i.template.ast, n, r), i.template?.content) {
425
+ let e = b(i.template.content, n), t = i.template.loc.start.line - 1, a = new Set(r.map((e) => e.id));
426
+ for (let n of e) a.has(n.id) || r.push({
427
+ ...n,
428
+ origin: {
429
+ ...n.origin,
430
+ line: n.origin.line + t
431
+ }
432
+ });
433
+ let o = L(i.template.content, n);
434
+ for (let e of o) a.has(e.id) || r.push({
435
+ ...e,
436
+ origin: {
437
+ ...e.origin,
438
+ line: e.origin.line + t
439
+ }
440
+ });
441
+ }
442
+ if (i.scriptSetup?.content) {
443
+ let e = b(i.scriptSetup.content, n), t = i.scriptSetup.loc.start.line - 1;
444
+ for (let n of e) r.push({
445
+ ...n,
446
+ origin: {
447
+ ...n.origin,
448
+ line: n.origin.line + t
449
+ }
450
+ });
451
+ }
452
+ if (i.script?.content) {
453
+ let e = b(i.script.content, n), t = i.script.loc.start.line - 1;
454
+ for (let n of e) r.push({
455
+ ...n,
456
+ origin: {
457
+ ...n.origin,
458
+ line: n.origin.line + t
459
+ }
460
+ });
461
+ }
462
+ return r;
463
+ }
464
+ //#endregion
465
+ //#region src/catalog.ts
466
+ function z(e, t) {
467
+ let n = new Set(t.map((e) => e.id)), r = /* @__PURE__ */ new Set(), i = {}, a = 0, o = 0, s = 0;
468
+ for (let n of t) {
469
+ let t = e[n.id], s = t ? void 0 : B(e, n, r), c = `${n.origin.file}:${n.origin.line}`, l = t ?? s?.entry;
470
+ s && r.add(s.id), l ? (i[n.id] = {
471
+ ...l,
472
+ message: n.message ?? l.message,
473
+ context: n.context,
474
+ comment: n.comment,
475
+ origin: c,
476
+ obsolete: !1
477
+ }, o++) : (i[n.id] = {
478
+ message: n.message,
479
+ context: n.context,
480
+ comment: n.comment,
481
+ origin: c
482
+ }, a++);
483
+ }
484
+ for (let [t, r] of Object.entries(e)) n.has(t) || (i[t] = {
485
+ ...r,
486
+ obsolete: !0
487
+ }, s++);
488
+ return {
489
+ catalog: i,
490
+ result: {
491
+ added: a,
492
+ unchanged: o,
493
+ obsolete: s
494
+ }
495
+ };
496
+ }
497
+ function B(e, t, n) {
498
+ if (!t.context) return;
499
+ let r = `${t.origin.file}:${t.origin.line}`;
500
+ for (let [i, a] of Object.entries(e)) if (!n.has(i) && a.context === void 0 && a.message === t.message && V(a.origin, r)) return {
501
+ id: i,
502
+ entry: a
503
+ };
504
+ }
505
+ function V(e, t) {
506
+ return e ? e === t ? !0 : H(e) === H(t) : !1;
507
+ }
508
+ function H(e) {
509
+ return e.match(/^(.*):\d+$/)?.[1] ?? e;
510
+ }
511
+ //#endregion
512
+ //#region src/json-format.ts
513
+ function U(e) {
514
+ let t = JSON.parse(e), n = {};
515
+ for (let [e, r] of Object.entries(t)) if (typeof r == "object" && r) {
516
+ let t = r;
517
+ n[e] = {
518
+ message: typeof t.message == "string" ? t.message : void 0,
519
+ context: typeof t.context == "string" ? t.context : void 0,
520
+ comment: typeof t.comment == "string" ? t.comment : void 0,
521
+ translation: typeof t.translation == "string" ? t.translation : void 0,
522
+ origin: typeof t.origin == "string" ? t.origin : void 0,
523
+ obsolete: typeof t.obsolete == "boolean" ? t.obsolete : void 0
524
+ };
525
+ }
526
+ return n;
527
+ }
528
+ function W(e) {
529
+ let t = {};
530
+ for (let [n, r] of Object.entries(e)) {
531
+ let e = {};
532
+ r.message !== void 0 && (e.message = r.message), r.context !== void 0 && (e.context = r.context), r.comment !== void 0 && (e.comment = r.comment), r.translation !== void 0 && (e.translation = r.translation), r.origin !== void 0 && (e.origin = r.origin), r.obsolete && (e.obsolete = !0), t[n] = e;
533
+ }
534
+ return JSON.stringify(t, null, 2) + "\n";
535
+ }
536
+ //#endregion
537
+ //#region src/po-format.ts
538
+ var G = "fluenti-id:";
539
+ function re(e) {
540
+ let t = s.po.parse(e), n = {}, r = t.translations ?? {};
541
+ for (let [e, t] of Object.entries(r)) for (let [r, i] of Object.entries(t)) {
542
+ if (!r) continue;
543
+ let t = e || i.msgctxt || void 0, o = i.msgstr?.[0] ?? void 0, s = i.comments?.reference ?? void 0, c = i.comments?.flag?.includes("fuzzy") ?? !1, { comment: l, customId: u, sourceMessage: d } = q(i.comments?.extracted), f = d && a(d, t) === r ? d : void 0, p = u ?? (f ? r : a(r, t));
544
+ n[p] = {
545
+ message: f ?? r,
546
+ ...t === void 0 ? {} : { context: t },
547
+ ...l === void 0 ? {} : { comment: l },
548
+ ...o ? { translation: o } : {},
549
+ ...s === void 0 ? {} : { origin: s },
550
+ ...c ? { obsolete: c } : {}
551
+ };
552
+ }
553
+ return n;
554
+ }
555
+ function K(e) {
556
+ let t = { "": { "": {
557
+ msgid: "",
558
+ msgstr: ["Content-Type: text/plain; charset=UTF-8\n"]
559
+ } } };
560
+ for (let [n, r] of Object.entries(e)) {
561
+ let e = {
562
+ msgid: r.message ?? n,
563
+ ...r.context === void 0 ? {} : { msgctxt: r.context },
564
+ msgstr: [r.translation ?? ""]
565
+ }, i = {};
566
+ r.origin && (i.reference = r.origin);
567
+ let a = Y(n, r.message ?? n, r.context, r.comment);
568
+ a && (i.extracted = a), r.obsolete && (i.flag = "fuzzy"), (i.reference || i.extracted || i.flag) && (e.comments = i);
569
+ let o = r.context ?? "";
570
+ t[o] ??= {}, t[o][e.msgid] = e;
571
+ }
572
+ let n = {
573
+ headers: { "Content-Type": "text/plain; charset=UTF-8" },
574
+ translations: t
575
+ };
576
+ return s.po.compile(n).toString();
577
+ }
578
+ function q(e) {
579
+ if (!e) return {};
580
+ let t = e.split("\n").map((e) => e.trim()).filter(Boolean), n, r, i = [];
581
+ for (let e of t) {
582
+ if (e.startsWith(G)) {
583
+ n = e.slice(11).trim() || void 0;
584
+ continue;
585
+ }
586
+ if (e.startsWith("msg`") && e.endsWith("`")) {
587
+ r = e.slice(4, -1);
588
+ continue;
589
+ }
590
+ if (e.startsWith("Trans: ")) {
591
+ r = J(e.slice(7));
592
+ continue;
593
+ }
594
+ i.push(e);
595
+ }
596
+ return {
597
+ ...i.length > 0 ? { comment: i.join("\n") } : {},
598
+ ...n ? { customId: n } : {},
599
+ ...r ? { sourceMessage: r } : {}
600
+ };
601
+ }
602
+ function J(e) {
603
+ let t = [], n = 0;
604
+ return e.replace(/<\/?([a-zA-Z][\w-]*)>/g, (e, r) => {
605
+ let i = r;
606
+ if (e.startsWith("</")) {
607
+ for (let e = t.length - 1; e >= 0; e--) {
608
+ let n = t[e];
609
+ if (n?.tag === i) return t.splice(e, 1), `</${n.index}>`;
610
+ }
611
+ return e;
612
+ }
613
+ let a = n++;
614
+ return t.push({
615
+ tag: i,
616
+ index: a
617
+ }), `<${a}>`;
618
+ });
619
+ }
620
+ function Y(e, t, n, r) {
621
+ let i = [];
622
+ return r && i.push(r), e !== a(t, n) && i.push(`${G} ${e}`), i.length > 0 ? i.join("\n") : void 0;
623
+ }
624
+ //#endregion
625
+ //#region src/compile.ts
626
+ var X = /\{(\w+)\}/g;
627
+ function ie(e) {
628
+ return X.test(e);
629
+ }
630
+ function Z(e) {
631
+ return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
632
+ }
633
+ function ae(e) {
634
+ return e.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
635
+ }
636
+ function oe(e) {
637
+ return e.replace(X, (e, t) => `\${v.${t}}`);
638
+ }
639
+ var se = /\{(\w+),\s*(plural|select|selectordinal)\s*,/;
640
+ function ce(e) {
641
+ return se.test(e);
642
+ }
643
+ function Q(e, t) {
644
+ if (e.length === 0) return "''";
645
+ let n = e.map((e) => le(e, t));
646
+ return n.length === 1 ? n[0] : n.join(" + ");
647
+ }
648
+ function le(e, t) {
649
+ switch (e.type) {
650
+ case "text": return `'${Z(e.value)}'`;
651
+ case "variable": return e.name === "#" ? "String(__c)" : `String(v.${e.name} ?? '{${e.name}}')`;
652
+ case "plural": return $(e, t);
653
+ case "select": return ue(e, t);
654
+ case "function": return `String(v.${e.variable} ?? '')`;
655
+ }
656
+ }
657
+ function $(e, t) {
658
+ let n = e.offset ?? 0, r = n ? `(v.${e.variable} - ${n})` : `v.${e.variable}`, i = [];
659
+ i.push("((c) => { const __c = c; ");
660
+ let a = Object.keys(e.options).filter((e) => e.startsWith("="));
661
+ if (a.length > 0) for (let n of a) {
662
+ let r = n.slice(1), a = Q(e.options[n], t);
663
+ i.push(`if (c === ${r}) return ${a}; `);
664
+ }
665
+ let o = Object.keys(e.options).filter((e) => !e.startsWith("="));
666
+ if (o.length > 1 || o.length === 1 && o[0] !== "other") {
667
+ i.push(`const __cat = new Intl.PluralRules('${t}').select(c); `);
668
+ for (let n of o) {
669
+ if (n === "other") continue;
670
+ let r = Q(e.options[n], t);
671
+ i.push(`if (__cat === '${n}') return ${r}; `);
672
+ }
673
+ }
674
+ let s = e.options.other ? Q(e.options.other, t) : "''";
675
+ return i.push(`return ${s}; `), i.push(`})(${r})`), i.join("");
676
+ }
677
+ function ue(e, t) {
678
+ let n = [];
679
+ n.push("((s) => { ");
680
+ let r = Object.keys(e.options).filter((e) => e !== "other");
681
+ for (let i of r) {
682
+ let r = Q(e.options[i], t);
683
+ n.push(`if (s === '${Z(i)}') return ${r}; `);
684
+ }
685
+ let i = e.options.other ? Q(e.options.other, t) : "''";
686
+ return n.push(`return ${i}; `), n.push(`})(String(v.${e.variable} ?? ''))`), n.join("");
687
+ }
688
+ function de(e, t, n, r) {
689
+ let i = [];
690
+ i.push("// @fluenti/compiled v1");
691
+ let s = [];
692
+ for (let c of n) {
693
+ let n = `_${a(c)}`, l = e[c], u = fe(l, c, t, r);
694
+ if (u === void 0) i.push(`/* @__PURE__ */ export const ${n} = undefined`);
695
+ else if (ce(u)) {
696
+ let e = Q(o(u), t);
697
+ i.push(`/* @__PURE__ */ export const ${n} = (v) => ${e}`);
698
+ } else if (ie(u)) {
699
+ let e = oe(ae(u));
700
+ i.push(`/* @__PURE__ */ export const ${n} = (v) => \`${e}\``);
701
+ } else i.push(`/* @__PURE__ */ export const ${n} = '${Z(u)}'`);
702
+ s.push({
703
+ id: c,
704
+ exportName: n
705
+ });
706
+ }
707
+ if (s.length === 0) return "// @fluenti/compiled v1\n// empty catalog\nexport default {}\n";
708
+ i.push(""), i.push("export default {");
709
+ for (let { id: e, exportName: t } of s) i.push(` '${Z(e)}': ${t},`);
710
+ return i.push("}"), i.push(""), i.join("\n");
711
+ }
712
+ function fe(e, t, n, r) {
713
+ let i = r ?? n;
714
+ if (e) {
715
+ if (e.translation !== void 0 && e.translation.length > 0) return e.translation;
716
+ if (n === i) return e.message ?? t;
717
+ }
718
+ }
719
+ function pe(e, t) {
720
+ let n = [];
721
+ n.push(`export const locales = ${JSON.stringify(e)}`), n.push(""), n.push("export const loaders = {");
722
+ for (let t of e) n.push(` '${Z(t)}': () => import('./${t}.js'),`);
723
+ return n.push("}"), n.push(""), n.join("\n");
724
+ }
725
+ function me(e) {
726
+ let t = /* @__PURE__ */ new Set();
727
+ for (let n of Object.values(e)) for (let [e, r] of Object.entries(n)) r.obsolete || t.add(e);
728
+ return [...t].sort();
729
+ }
730
+ //#endregion
731
+ export { K as a, z as c, re as i, R as l, de as n, U as o, pe as r, W as s, me as t, b as u };
732
+
733
+ //# sourceMappingURL=compile-McMlpGSK.js.map