@customyai/cli 0.7.1 → 0.10.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/CHANGELOG.md +83 -0
- package/LICENSE +2 -1
- package/README.md +77 -0
- package/dist/bin.cjs +6 -2
- package/dist/bin.mjs +5 -1
- package/dist/chunk-2A6WFLXS.cjs +235 -0
- package/dist/chunk-3M6ZLCSN.mjs +237 -0
- package/dist/chunk-57NNDUEX.mjs +3246 -0
- package/dist/chunk-6X3AX6PB.cjs +3266 -0
- package/dist/chunk-ABK4QQWW.cjs +244 -0
- package/dist/chunk-BYMLRMNS.mjs +27 -0
- package/dist/chunk-MFJL3NO5.cjs +31 -0
- package/dist/chunk-QKIF4C5R.mjs +226 -0
- package/dist/index.cjs +32 -11
- package/dist/index.d.cts +63 -1
- package/dist/index.d.ts +63 -1
- package/dist/index.mjs +2 -1
- package/dist/json-NETFQXLJ.mjs +67 -0
- package/dist/json-NSJMTBPP.cjs +70 -0
- package/dist/po-AKWHAYBL.mjs +387 -0
- package/dist/po-IJGMXNVY.cjs +394 -0
- package/dist/pseudo-CKYMJJBX.mjs +101 -0
- package/dist/pseudo-LBLMBD2T.cjs +106 -0
- package/dist/quality-6SEZNA6Q.cjs +207 -0
- package/dist/quality-ILK6IA5O.mjs +199 -0
- package/dist/xliff-DEJHB2SY.mjs +512 -0
- package/dist/xliff-DXICWMWC.cjs +518 -0
- package/package.json +9 -3
- package/dist/chunk-6KGKN5HN.cjs +0 -1108
- package/dist/chunk-KDUW3KTG.mjs +0 -1093
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkMFJL3NO5_cjs = require('./chunk-MFJL3NO5.cjs');
|
|
4
|
+
var chunk2A6WFLXS_cjs = require('./chunk-2A6WFLXS.cjs');
|
|
5
|
+
var chunkABK4QQWW_cjs = require('./chunk-ABK4QQWW.cjs');
|
|
6
|
+
|
|
7
|
+
// src/vendor/i18n-tools/xml.ts
|
|
8
|
+
var DEFAULT_XML_LIMITS = { maxBytes: 4 * 1024 * 1024, maxDepth: 32, maxNodes: 2e5, maxAttributes: 32, maxNameLength: 128 };
|
|
9
|
+
var XML_NS = "http://www.w3.org/XML/1998/namespace";
|
|
10
|
+
var INVALID_CHAR = /[^\u0009\u000A\u000D --�\u{10000}-\u{10FFFF}]/u;
|
|
11
|
+
var NAME_RE = /[\p{L}_:][\p{L}\p{N}._:\-·]*/uy;
|
|
12
|
+
var NCNAME = /^[\p{L}_][\p{L}\p{N}._\-·]*$/u;
|
|
13
|
+
var fail = (code, text, src, pos) => {
|
|
14
|
+
let line = 1;
|
|
15
|
+
let last = -1;
|
|
16
|
+
for (let k = src.indexOf("\n"); k !== -1 && k < pos; k = src.indexOf("\n", k + 1)) {
|
|
17
|
+
line += 1;
|
|
18
|
+
last = k;
|
|
19
|
+
}
|
|
20
|
+
throw new chunkMFJL3NO5_cjs.I18nToolsError(code, `${text} (l\xEDnea ${line}, columna ${pos - last})`);
|
|
21
|
+
};
|
|
22
|
+
function isXmlChar(cp) {
|
|
23
|
+
return cp === 9 || cp === 10 || cp === 13 || cp >= 32 && cp <= 55295 || cp >= 57344 && cp <= 65533 || cp >= 65536 && cp <= 1114111;
|
|
24
|
+
}
|
|
25
|
+
function decodeEntities(raw, src, pos) {
|
|
26
|
+
if (!raw.includes("&")) return raw;
|
|
27
|
+
let out = "";
|
|
28
|
+
let i = 0;
|
|
29
|
+
while (i < raw.length) {
|
|
30
|
+
const amp = raw.indexOf("&", i);
|
|
31
|
+
if (amp === -1) {
|
|
32
|
+
out += raw.slice(i);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
out += raw.slice(i, amp);
|
|
36
|
+
const semi = raw.indexOf(";", amp + 1);
|
|
37
|
+
if (semi === -1 || semi - amp > 12) return fail("malformed-xml", "referencia a entidad sin cerrar", src, pos + amp);
|
|
38
|
+
const body = raw.slice(amp + 1, semi);
|
|
39
|
+
if (body === "amp") out += "&";
|
|
40
|
+
else if (body === "lt") out += "<";
|
|
41
|
+
else if (body === "gt") out += ">";
|
|
42
|
+
else if (body === "quot") out += '"';
|
|
43
|
+
else if (body === "apos") out += "'";
|
|
44
|
+
else if (/^#x[0-9A-Fa-f]{1,6}$/.test(body) || /^#[0-9]{1,7}$/.test(body)) {
|
|
45
|
+
const cp = body[1] === "x" ? Number.parseInt(body.slice(2), 16) : Number.parseInt(body.slice(1), 10);
|
|
46
|
+
if (!isXmlChar(cp)) return fail("invalid-char", `la referencia &${body}; no es un car\xE1cter XML v\xE1lido`, src, pos + amp);
|
|
47
|
+
out += String.fromCodePoint(cp);
|
|
48
|
+
} else return fail("undefined-entity", `entidad no definida &${body}; (no se admiten entidades propias ni externas)`, src, pos + amp);
|
|
49
|
+
i = semi + 1;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
function decodeXmlBytes(input, maxBytes) {
|
|
54
|
+
if (typeof input === "string") {
|
|
55
|
+
if (input.length > maxBytes || chunkMFJL3NO5_cjs.utf8ByteLength(input) > maxBytes) throw new chunkMFJL3NO5_cjs.I18nToolsError("too-large", `el documento pasa de ${maxBytes} bytes`);
|
|
56
|
+
return input.charCodeAt(0) === 65279 ? input.slice(1) : input;
|
|
57
|
+
}
|
|
58
|
+
if (input.length > maxBytes) throw new chunkMFJL3NO5_cjs.I18nToolsError("too-large", `el documento pasa de ${maxBytes} bytes`);
|
|
59
|
+
if (input.length >= 2 && (input[0] === 255 && input[1] === 254 || input[0] === 254 && input[1] === 255)) {
|
|
60
|
+
throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-encoding", "solo se admite UTF-8 (se detect\xF3 UTF-16)");
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: false }).decode(input).replace(/^\uFEFF/, "");
|
|
64
|
+
} catch {
|
|
65
|
+
throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-encoding", "el documento no es UTF-8 v\xE1lido");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function parseXml(input, limits = {}) {
|
|
69
|
+
const lim = { ...DEFAULT_XML_LIMITS, ...limits };
|
|
70
|
+
const decoded = decodeXmlBytes(input, lim.maxBytes);
|
|
71
|
+
const bad = INVALID_CHAR.exec(decoded);
|
|
72
|
+
if (bad) fail("invalid-char", `car\xE1cter no permitido en XML (U+${(bad[0].codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(4, "0")})`, decoded, bad.index);
|
|
73
|
+
const src = decoded.replace(/\r\n?/g, "\n");
|
|
74
|
+
const n = src.length;
|
|
75
|
+
let pos = 0;
|
|
76
|
+
let nodes = 0;
|
|
77
|
+
const skipWs = () => {
|
|
78
|
+
while (pos < n && (src[pos] === " " || src[pos] === " " || src[pos] === "\n")) pos += 1;
|
|
79
|
+
};
|
|
80
|
+
const count = () => {
|
|
81
|
+
nodes += 1;
|
|
82
|
+
if (nodes > lim.maxNodes) fail("too-many-nodes", `m\xE1s de ${lim.maxNodes} nodos`, src, pos);
|
|
83
|
+
};
|
|
84
|
+
const readName = (what) => {
|
|
85
|
+
NAME_RE.lastIndex = pos;
|
|
86
|
+
const m = NAME_RE.exec(src);
|
|
87
|
+
if (!m) return fail("malformed-xml", `se esperaba ${what}`, src, pos);
|
|
88
|
+
if (m[0].length > lim.maxNameLength) fail("too-large", "nombre demasiado largo", src, pos);
|
|
89
|
+
pos += m[0].length;
|
|
90
|
+
return m[0];
|
|
91
|
+
};
|
|
92
|
+
if (src.startsWith("<?xml") && /\s/.test(src[5] ?? "")) {
|
|
93
|
+
const end = src.indexOf("?>");
|
|
94
|
+
if (end === -1) fail("malformed-xml", "declaraci\xF3n XML sin cerrar", src, 0);
|
|
95
|
+
const decl = src.slice(5, end);
|
|
96
|
+
const version = /\bversion\s*=\s*(?:"([^"]*)"|'([^']*)')/.exec(decl);
|
|
97
|
+
if (!version || (version[1] ?? version[2]) !== "1.0") fail("malformed-xml", "solo se admite XML 1.0", src, 0);
|
|
98
|
+
const enc = /\bencoding\s*=\s*(?:"([^"]*)"|'([^']*)')/.exec(decl);
|
|
99
|
+
if (enc && (enc[1] ?? enc[2] ?? "").toLowerCase() !== "utf-8") fail("invalid-encoding", 'solo se admite encoding="UTF-8"', src, 0);
|
|
100
|
+
if (!/^(?:\s+(?:version|encoding|standalone)\s*=\s*(?:"[^"]*"|'[^']*'))+\s*$/.test(decl)) fail("malformed-xml", "declaraci\xF3n XML mal formada", src, 0);
|
|
101
|
+
pos = end + 2;
|
|
102
|
+
}
|
|
103
|
+
const skipMisc = () => {
|
|
104
|
+
for (; ; ) {
|
|
105
|
+
skipWs();
|
|
106
|
+
if (src.startsWith("<!--", pos)) {
|
|
107
|
+
const end = src.indexOf("-->", pos + 4);
|
|
108
|
+
if (end === -1) fail("malformed-xml", "comentario sin cerrar", src, pos);
|
|
109
|
+
if (src.slice(pos + 4, end).includes("--")) fail("malformed-xml", "\xAB--\xBB dentro de un comentario", src, pos);
|
|
110
|
+
pos = end + 3;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const rejectBang = () => {
|
|
117
|
+
if (/^<!DOCTYPE/i.test(src.slice(pos, pos + 9))) return fail("doctype-forbidden", "DOCTYPE no permitido (sin DTD ni entidades externas)", src, pos);
|
|
118
|
+
return fail("forbidden-construct", "construcci\xF3n \xAB<!\u2026\xBB no permitida", src, pos);
|
|
119
|
+
};
|
|
120
|
+
skipMisc();
|
|
121
|
+
if (pos >= n) fail("malformed-xml", "documento vac\xEDo", src, pos);
|
|
122
|
+
if (src.startsWith("<!", pos) && !src.startsWith("<!--", pos)) rejectBang();
|
|
123
|
+
if (src.startsWith("<?", pos)) fail("forbidden-construct", "instrucciones de proceso no permitidas", src, pos);
|
|
124
|
+
if (src[pos] !== "<") fail("malformed-xml", "se esperaba el elemento ra\xEDz", src, pos);
|
|
125
|
+
const stack = [];
|
|
126
|
+
let root = null;
|
|
127
|
+
let text = [];
|
|
128
|
+
const flushText = () => {
|
|
129
|
+
if (text.length === 0) return;
|
|
130
|
+
const top = stack[stack.length - 1];
|
|
131
|
+
const joined = text.join("");
|
|
132
|
+
text = [];
|
|
133
|
+
if (!top || joined === "") return;
|
|
134
|
+
count();
|
|
135
|
+
top.children.push(joined);
|
|
136
|
+
};
|
|
137
|
+
while (pos < n) {
|
|
138
|
+
if (stack.length === 0 && root) {
|
|
139
|
+
skipMisc();
|
|
140
|
+
if (pos < n) {
|
|
141
|
+
if (src.startsWith("<!", pos)) rejectBang();
|
|
142
|
+
fail("malformed-xml", "contenido despu\xE9s del elemento ra\xEDz", src, pos);
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
if (src[pos] !== "<") {
|
|
147
|
+
let end = src.indexOf("<", pos);
|
|
148
|
+
if (end === -1) end = n;
|
|
149
|
+
const chunk = src.slice(pos, end);
|
|
150
|
+
if (chunk.includes("]]>")) fail("malformed-xml", "\xAB]]>\xBB no permitido en el texto", src, pos);
|
|
151
|
+
text.push(decodeEntities(chunk, src, pos));
|
|
152
|
+
pos = end;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (src.startsWith("<!--", pos)) {
|
|
156
|
+
const end = src.indexOf("-->", pos + 4);
|
|
157
|
+
if (end === -1) fail("malformed-xml", "comentario sin cerrar", src, pos);
|
|
158
|
+
if (src.slice(pos + 4, end).includes("--")) fail("malformed-xml", "\xAB--\xBB dentro de un comentario", src, pos);
|
|
159
|
+
pos = end + 3;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (src.startsWith("<![CDATA[", pos)) {
|
|
163
|
+
const end = src.indexOf("]]>", pos + 9);
|
|
164
|
+
if (end === -1) fail("malformed-xml", "CDATA sin cerrar", src, pos);
|
|
165
|
+
text.push(src.slice(pos + 9, end));
|
|
166
|
+
pos = end + 3;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (src.startsWith("<!", pos)) rejectBang();
|
|
170
|
+
if (src.startsWith("<?", pos)) fail("forbidden-construct", "instrucciones de proceso no permitidas", src, pos);
|
|
171
|
+
if (src[pos + 1] === "/") {
|
|
172
|
+
flushText();
|
|
173
|
+
const open = stack.pop();
|
|
174
|
+
pos += 2;
|
|
175
|
+
if (!open) return fail("malformed-xml", "etiqueta de cierre sin abrir", src, pos);
|
|
176
|
+
const name2 = readName("el nombre de la etiqueta de cierre");
|
|
177
|
+
if (name2 !== open.name) fail("malformed-xml", `se esperaba </${open.name}> y apareci\xF3 </${name2}>`, src, pos);
|
|
178
|
+
skipWs();
|
|
179
|
+
if (src[pos] !== ">") fail("malformed-xml", "etiqueta de cierre mal formada", src, pos);
|
|
180
|
+
pos += 1;
|
|
181
|
+
const el = { name: open.name, prefix: open.prefix, local: open.local, ns: open.ns, attrs: open.attrs, children: open.children };
|
|
182
|
+
const parent2 = stack[stack.length - 1];
|
|
183
|
+
if (parent2) parent2.children.push(el);
|
|
184
|
+
else root = el;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
flushText();
|
|
188
|
+
if (stack.length >= lim.maxDepth) fail("too-deep", `anidamiento de m\xE1s de ${lim.maxDepth} niveles`, src, pos);
|
|
189
|
+
count();
|
|
190
|
+
pos += 1;
|
|
191
|
+
const name = readName("el nombre del elemento");
|
|
192
|
+
const attrs = /* @__PURE__ */ Object.create(null);
|
|
193
|
+
let attrCount = 0;
|
|
194
|
+
let selfClose = false;
|
|
195
|
+
for (; ; ) {
|
|
196
|
+
const before = pos;
|
|
197
|
+
skipWs();
|
|
198
|
+
if (src[pos] === ">") {
|
|
199
|
+
pos += 1;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
if (src[pos] === "/" && src[pos + 1] === ">") {
|
|
203
|
+
pos += 2;
|
|
204
|
+
selfClose = true;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
if (pos === before) fail("malformed-xml", "falta un espacio entre atributos", src, pos);
|
|
208
|
+
if (pos >= n) fail("malformed-xml", "etiqueta sin cerrar", src, pos);
|
|
209
|
+
const an = readName("el nombre del atributo");
|
|
210
|
+
skipWs();
|
|
211
|
+
if (src[pos] !== "=") fail("malformed-xml", `el atributo ${an} necesita \xAB=\xBB`, src, pos);
|
|
212
|
+
pos += 1;
|
|
213
|
+
skipWs();
|
|
214
|
+
const q = src[pos];
|
|
215
|
+
if (q !== '"' && q !== "'") return fail("malformed-xml", `el valor de ${an} necesita comillas`, src, pos);
|
|
216
|
+
const end = src.indexOf(q, pos + 1);
|
|
217
|
+
if (end === -1) return fail("malformed-xml", "valor de atributo sin cerrar", src, pos);
|
|
218
|
+
const raw = src.slice(pos + 1, end);
|
|
219
|
+
if (raw.includes("<")) fail("malformed-xml", "\xAB<\xBB no permitido en un valor de atributo", src, pos);
|
|
220
|
+
if (Object.hasOwn(attrs, an)) fail("malformed-xml", `atributo repetido ${an}`, src, pos);
|
|
221
|
+
attrCount += 1;
|
|
222
|
+
if (attrCount > lim.maxAttributes) fail("too-many-nodes", `m\xE1s de ${lim.maxAttributes} atributos`, src, pos);
|
|
223
|
+
attrs[an] = decodeEntities(raw.replace(/[\t\n]/g, " "), src, pos + 1);
|
|
224
|
+
pos = end + 1;
|
|
225
|
+
}
|
|
226
|
+
const parent = stack[stack.length - 1];
|
|
227
|
+
const scope = /* @__PURE__ */ Object.create(null);
|
|
228
|
+
if (parent) Object.assign(scope, parent.scope);
|
|
229
|
+
else scope["xml"] = XML_NS;
|
|
230
|
+
for (const [an, av] of Object.entries(attrs)) {
|
|
231
|
+
if (an === "xmlns") scope[""] = av;
|
|
232
|
+
else if (an.startsWith("xmlns:")) {
|
|
233
|
+
const p = an.slice(6);
|
|
234
|
+
if (!NCNAME.test(p) || p === "xmlns" || p === "xml") fail("malformed-xml", `prefijo de espacio de nombres no permitido ${p}`, src, pos);
|
|
235
|
+
if (av === "") fail("malformed-xml", `el prefijo ${p} no puede quedar vac\xEDo`, src, pos);
|
|
236
|
+
scope[p] = av;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const colon = name.indexOf(":");
|
|
240
|
+
const prefix = colon === -1 ? null : name.slice(0, colon);
|
|
241
|
+
const local = colon === -1 ? name : name.slice(colon + 1);
|
|
242
|
+
if (colon !== -1 && (!NCNAME.test(prefix ?? "") || !NCNAME.test(local))) fail("malformed-xml", `nombre calificado no v\xE1lido ${name}`, src, pos);
|
|
243
|
+
for (const an of Object.keys(attrs)) {
|
|
244
|
+
const c = an.indexOf(":");
|
|
245
|
+
if (c > 0 && !an.startsWith("xmlns:") && !Object.hasOwn(scope, an.slice(0, c))) fail("malformed-xml", `prefijo no declarado en el atributo ${an}`, src, pos);
|
|
246
|
+
}
|
|
247
|
+
let ns;
|
|
248
|
+
if (prefix === null) ns = scope[""] ? scope[""] : null;
|
|
249
|
+
else {
|
|
250
|
+
const uri = scope[prefix];
|
|
251
|
+
if (uri === void 0) return fail("malformed-xml", `prefijo no declarado ${prefix}`, src, pos);
|
|
252
|
+
ns = uri;
|
|
253
|
+
}
|
|
254
|
+
const frame = { name, prefix, local, ns, attrs, children: [], scope };
|
|
255
|
+
if (selfClose) {
|
|
256
|
+
const el = { name, prefix, local, ns, attrs, children: [] };
|
|
257
|
+
if (parent) parent.children.push(el);
|
|
258
|
+
else root = el;
|
|
259
|
+
} else stack.push(frame);
|
|
260
|
+
}
|
|
261
|
+
if (stack.length > 0) fail("malformed-xml", `falta cerrar <${stack[stack.length - 1]?.name ?? ""}>`, src, pos);
|
|
262
|
+
if (!root) fail("malformed-xml", "sin elemento ra\xEDz", src, pos);
|
|
263
|
+
return root;
|
|
264
|
+
}
|
|
265
|
+
function elementText(el) {
|
|
266
|
+
let out = "";
|
|
267
|
+
for (const c of el.children) if (typeof c === "string") out += c;
|
|
268
|
+
return out;
|
|
269
|
+
}
|
|
270
|
+
var escapeXmlText = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\r/g, " ");
|
|
271
|
+
var escapeXmlAttr = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/\t/g, "	").replace(/\n/g, " ").replace(/\r/g, " ");
|
|
272
|
+
|
|
273
|
+
// src/vendor/i18n-tools/xliff.ts
|
|
274
|
+
var XLIFF_NS = "urn:oasis:names:tc:xliff:document:2.1";
|
|
275
|
+
var XLIFF_NS_20 = "urn:oasis:names:tc:xliff:document:2.0";
|
|
276
|
+
var XLIFF_STATES = ["initial", "translated", "reviewed", "final"];
|
|
277
|
+
var STATE_RANK = { initial: 0, translated: 1, reviewed: 2, final: 3 };
|
|
278
|
+
var SYNTAX_NOTE = "customy:syntax";
|
|
279
|
+
var attrSafe = (s) => escapeXmlAttr(s.replace(/[^\u0009\u000A\u000D --�\u{10000}-\u{10FFFF}]/gu, "\uFFFD"));
|
|
280
|
+
function encodeText(text) {
|
|
281
|
+
let out = "";
|
|
282
|
+
let run = "";
|
|
283
|
+
const flush = () => {
|
|
284
|
+
if (run) {
|
|
285
|
+
out += escapeXmlText(run);
|
|
286
|
+
run = "";
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
for (const ch of text) {
|
|
290
|
+
const cp = ch.codePointAt(0) ?? 0;
|
|
291
|
+
const valid = cp === 9 || cp === 10 || cp === 13 || cp >= 32 && cp <= 55295 || cp >= 57344 && cp <= 65533 || cp >= 65536 && cp <= 1114111;
|
|
292
|
+
if (valid) run += ch;
|
|
293
|
+
else {
|
|
294
|
+
flush();
|
|
295
|
+
out += `<cp hex="${cp.toString(16).toUpperCase().padStart(4, "0")}"/>`;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
flush();
|
|
299
|
+
return out;
|
|
300
|
+
}
|
|
301
|
+
var InlineIds = class {
|
|
302
|
+
n = 0;
|
|
303
|
+
dataByRaw = /* @__PURE__ */ new Map();
|
|
304
|
+
sourceIds = /* @__PURE__ */ new Map();
|
|
305
|
+
data = [];
|
|
306
|
+
dataId(raw) {
|
|
307
|
+
let id = this.dataByRaw.get(raw);
|
|
308
|
+
if (!id) {
|
|
309
|
+
id = `d${this.dataByRaw.size + 1}`;
|
|
310
|
+
this.dataByRaw.set(raw, id);
|
|
311
|
+
this.data.push({ id, raw });
|
|
312
|
+
}
|
|
313
|
+
return id;
|
|
314
|
+
}
|
|
315
|
+
/** `side` "source" reserva ids nuevos; "target" reutiliza los del origen por orden de aparición. */
|
|
316
|
+
phId(raw, side, seen) {
|
|
317
|
+
if (side === "source") {
|
|
318
|
+
this.n += 1;
|
|
319
|
+
const id = String(this.n);
|
|
320
|
+
const list = this.sourceIds.get(raw) ?? [];
|
|
321
|
+
list.push(id);
|
|
322
|
+
this.sourceIds.set(raw, list);
|
|
323
|
+
return id;
|
|
324
|
+
}
|
|
325
|
+
const k = seen.get(raw) ?? 0;
|
|
326
|
+
seen.set(raw, k + 1);
|
|
327
|
+
const existing = this.sourceIds.get(raw)?.[k];
|
|
328
|
+
if (existing) return existing;
|
|
329
|
+
this.n += 1;
|
|
330
|
+
return String(this.n);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
function encodeInline(tokens, ids, side) {
|
|
334
|
+
const seen = /* @__PURE__ */ new Map();
|
|
335
|
+
let out = "";
|
|
336
|
+
for (const t of tokens) {
|
|
337
|
+
if (t.kind === "text") {
|
|
338
|
+
out += encodeText(t.text);
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
const dataId = ids.dataId(t.raw);
|
|
342
|
+
out += `<ph id="${ids.phId(t.raw, side, seen)}" dataRef="${dataId}" equiv="${attrSafe(t.raw)}"/>`;
|
|
343
|
+
}
|
|
344
|
+
return out;
|
|
345
|
+
}
|
|
346
|
+
function exportXliff(options) {
|
|
347
|
+
const { source, target } = options;
|
|
348
|
+
if (!chunk2A6WFLXS_cjs.CATALOG_LOCALE.test(source.locale)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-locale", `idioma de origen no v\xE1lido \xAB${source.locale}\xBB`);
|
|
349
|
+
const trgLang = target?.locale ?? options.targetLocale ?? null;
|
|
350
|
+
if (trgLang !== null && !chunk2A6WFLXS_cjs.CATALOG_LOCALE.test(trgLang)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-locale", `idioma de destino no v\xE1lido \xAB${trgLang}\xBB`);
|
|
351
|
+
if (target && target.namespace !== source.namespace) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-input", "origen y destino son de espacios de nombres distintos");
|
|
352
|
+
const dnt = new Set(options.doNotTranslate ?? []);
|
|
353
|
+
const keys = Object.keys(source.messages).sort(chunkMFJL3NO5_cjs.compareCodeUnits);
|
|
354
|
+
const out = [];
|
|
355
|
+
out.push('<?xml version="1.0" encoding="UTF-8"?>');
|
|
356
|
+
out.push(`<xliff xmlns="${XLIFF_NS}" version="2.1" srcLang="${escapeXmlAttr(source.locale)}"${trgLang ? ` trgLang="${escapeXmlAttr(trgLang)}"` : ""}>`);
|
|
357
|
+
out.push(` <file id="f1" original="${escapeXmlAttr(source.namespace)}">`);
|
|
358
|
+
out.push(` <notes><note category="${SYNTAX_NOTE}">${escapeXmlText(source.syntax)}</note></notes>`);
|
|
359
|
+
for (const key of keys) {
|
|
360
|
+
if (!chunk2A6WFLXS_cjs.CATALOG_KEY.test(key)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-key", `clave no v\xE1lida \xAB${key}\xBB`);
|
|
361
|
+
const src = source.messages[key] ?? "";
|
|
362
|
+
const trg = target ? target.messages[key] : void 0;
|
|
363
|
+
const ids = new InlineIds();
|
|
364
|
+
const srcXml = encodeInline(chunkABK4QQWW_cjs.tokenizeIcu(src), ids, "source");
|
|
365
|
+
const trgXml = trg !== void 0 ? encodeInline(chunkABK4QQWW_cjs.tokenizeIcu(trg), ids, "target") : null;
|
|
366
|
+
const state = options.states?.[key] ?? (trg !== void 0 ? "translated" : "initial");
|
|
367
|
+
if (!XLIFF_STATES.includes(state)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-state", `estado no v\xE1lido \xAB${state}\xBB para ${key}`);
|
|
368
|
+
out.push(` <unit id="${escapeXmlAttr(key)}"${dnt.has(key) ? ' translate="no"' : ""} xml:space="preserve">`);
|
|
369
|
+
const notes = [];
|
|
370
|
+
const ctx = options.contexts?.[key];
|
|
371
|
+
if (ctx) notes.push(`<note category="context">${encodeText(ctx)}</note>`);
|
|
372
|
+
for (const note of options.notes?.[key] ?? []) notes.push(`<note>${encodeText(note)}</note>`);
|
|
373
|
+
if (notes.length > 0) out.push(` <notes>${notes.join("")}</notes>`);
|
|
374
|
+
if (ids.data.length > 0) out.push(` <originalData>${ids.data.map((d) => `<data id="${d.id}">${encodeText(d.raw)}</data>`).join("")}</originalData>`);
|
|
375
|
+
out.push(` <segment state="${state}" canResegment="no">`);
|
|
376
|
+
out.push(` <source>${srcXml}</source>`);
|
|
377
|
+
if (trgXml !== null) out.push(` <target>${trgXml}</target>`);
|
|
378
|
+
out.push(" </segment>");
|
|
379
|
+
out.push(" </unit>");
|
|
380
|
+
}
|
|
381
|
+
out.push(" </file>", "</xliff>", "");
|
|
382
|
+
return out.join("\n");
|
|
383
|
+
}
|
|
384
|
+
var inXliff = (el, local) => el.local === local && (el.ns === XLIFF_NS || el.ns === XLIFF_NS_20);
|
|
385
|
+
var kids = (el, local) => el.children.filter((c) => typeof c !== "string" && inXliff(c, local));
|
|
386
|
+
function decodeContent(el, data, what) {
|
|
387
|
+
let out = "";
|
|
388
|
+
for (const c of el.children) {
|
|
389
|
+
if (typeof c === "string") {
|
|
390
|
+
out += c;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (c.ns !== XLIFF_NS && c.ns !== XLIFF_NS_20) continue;
|
|
394
|
+
if (c.local === "cp") {
|
|
395
|
+
const hex = c.attrs["hex"] ?? "";
|
|
396
|
+
if (!/^[0-9A-Fa-f]{4,6}$/.test(hex)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", `<cp hex> no v\xE1lido en ${what}`);
|
|
397
|
+
const cp = Number.parseInt(hex, 16);
|
|
398
|
+
if (cp > 1114111) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", `<cp hex> fuera de rango en ${what}`);
|
|
399
|
+
out += String.fromCodePoint(cp);
|
|
400
|
+
} else if (c.local === "ph") {
|
|
401
|
+
if (c.children.length > 0) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", `<ph> debe ser un elemento vac\xEDo (${what})`);
|
|
402
|
+
const ref = c.attrs["dataRef"];
|
|
403
|
+
if (ref !== void 0) {
|
|
404
|
+
const raw = data.get(ref);
|
|
405
|
+
if (raw === void 0) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", `dataRef \xAB${ref}\xBB sin <data> en ${what}`);
|
|
406
|
+
out += raw;
|
|
407
|
+
} else if (c.attrs["equiv"] !== void 0) out += c.attrs["equiv"];
|
|
408
|
+
else throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", `<ph> sin dataRef ni equiv en ${what}`);
|
|
409
|
+
} else throw new chunkMFJL3NO5_cjs.I18nToolsError("unsupported-inline", `elemento en l\xEDnea <${c.local}> no admitido en ${what} (solo <ph> y <cp>)`);
|
|
410
|
+
}
|
|
411
|
+
return out;
|
|
412
|
+
}
|
|
413
|
+
function importXliff(input, options = {}) {
|
|
414
|
+
const root = parseXml(input, options.limits);
|
|
415
|
+
if (!inXliff(root, "xliff")) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", "la ra\xEDz no es <xliff> de XLIFF 2.x");
|
|
416
|
+
const version = root.attrs["version"];
|
|
417
|
+
if (version !== "2.1" && version !== "2.0") throw new chunkMFJL3NO5_cjs.I18nToolsError("unsupported-version", `solo se admite XLIFF 2.0/2.1 (version=${version ?? "ausente"})`);
|
|
418
|
+
const srcLang = root.attrs["srcLang"];
|
|
419
|
+
if (!srcLang || !chunk2A6WFLXS_cjs.CATALOG_LOCALE.test(srcLang)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-locale", `srcLang no v\xE1lido \xAB${srcLang ?? ""}\xBB`);
|
|
420
|
+
const trgLang = root.attrs["trgLang"] ?? null;
|
|
421
|
+
if (trgLang !== null && !chunk2A6WFLXS_cjs.CATALOG_LOCALE.test(trgLang)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-locale", `trgLang no v\xE1lido \xAB${trgLang}\xBB`);
|
|
422
|
+
const files = kids(root, "file");
|
|
423
|
+
if (files.length !== 1) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", `se espera exactamente un <file> (hay ${files.length})`);
|
|
424
|
+
const file = files[0];
|
|
425
|
+
const original = file.attrs["original"];
|
|
426
|
+
const namespace = original && chunk2A6WFLXS_cjs.CATALOG_NAMESPACE.test(original) ? original : options.namespace;
|
|
427
|
+
if (!namespace || !chunk2A6WFLXS_cjs.CATALOG_NAMESPACE.test(namespace)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-input", "falta un espacio de nombres v\xE1lido (file/@original o options.namespace)");
|
|
428
|
+
let syntax = "icu1";
|
|
429
|
+
for (const notes of kids(file, "notes")) {
|
|
430
|
+
for (const note of kids(notes, "note")) {
|
|
431
|
+
if (note.attrs["category"] === SYNTAX_NOTE) {
|
|
432
|
+
const value = elementText(note).trim();
|
|
433
|
+
if (value !== "icu1" && value !== "mf2") throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", `sintaxis desconocida \xAB${value}\xBB`);
|
|
434
|
+
syntax = value;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
const strict = options.strictKeys !== false;
|
|
439
|
+
const units = [];
|
|
440
|
+
const seen = /* @__PURE__ */ new Set();
|
|
441
|
+
const elementChildren = (el) => el.children.filter((c) => typeof c !== "string");
|
|
442
|
+
const order = [];
|
|
443
|
+
const walk = elementChildren(file).reverse();
|
|
444
|
+
while (walk.length > 0) {
|
|
445
|
+
const c = walk.pop();
|
|
446
|
+
if (inXliff(c, "unit")) order.push(c);
|
|
447
|
+
else if (inXliff(c, "group")) walk.push(...elementChildren(c).reverse());
|
|
448
|
+
}
|
|
449
|
+
for (const u of order) {
|
|
450
|
+
const key = u.attrs["id"];
|
|
451
|
+
if (!key) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", "<unit> sin id");
|
|
452
|
+
if (strict && !chunk2A6WFLXS_cjs.CATALOG_KEY.test(key)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-key", `clave no v\xE1lida \xAB${key}\xBB`);
|
|
453
|
+
if (seen.has(key)) throw new chunkMFJL3NO5_cjs.I18nToolsError("duplicate-key", `clave repetida \xAB${key}\xBB`);
|
|
454
|
+
seen.add(key);
|
|
455
|
+
const data = /* @__PURE__ */ new Map();
|
|
456
|
+
for (const od of kids(u, "originalData")) {
|
|
457
|
+
for (const d of kids(od, "data")) {
|
|
458
|
+
const id = d.attrs["id"];
|
|
459
|
+
if (!id) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", `<data> sin id en ${key}`);
|
|
460
|
+
data.set(id, decodeContent(d, /* @__PURE__ */ new Map(), `${key}/data`));
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
let context = null;
|
|
464
|
+
const notes = [];
|
|
465
|
+
for (const group of kids(u, "notes")) {
|
|
466
|
+
for (const note of kids(group, "note")) {
|
|
467
|
+
const text = decodeContent(note, /* @__PURE__ */ new Map(), `${key}/note`);
|
|
468
|
+
if (note.attrs["category"] === "context" && context === null) context = text;
|
|
469
|
+
else notes.push(text);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
let source = "";
|
|
473
|
+
let target = null;
|
|
474
|
+
let hasSegment = false;
|
|
475
|
+
let state = "final";
|
|
476
|
+
let sawTarget = false;
|
|
477
|
+
for (const c of u.children) {
|
|
478
|
+
if (typeof c === "string" || !inXliff(c, "segment") && !inXliff(c, "ignorable")) continue;
|
|
479
|
+
const src = kids(c, "source")[0];
|
|
480
|
+
if (!src) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", `<segment> sin <source> en ${key}`);
|
|
481
|
+
source += decodeContent(src, data, `${key}/source`);
|
|
482
|
+
const trg = kids(c, "target")[0];
|
|
483
|
+
if (trg) {
|
|
484
|
+
sawTarget = true;
|
|
485
|
+
target = (target ?? "") + decodeContent(trg, data, `${key}/target`);
|
|
486
|
+
}
|
|
487
|
+
if (inXliff(c, "segment")) {
|
|
488
|
+
hasSegment = true;
|
|
489
|
+
const st = c.attrs["state"] ?? "initial";
|
|
490
|
+
if (!XLIFF_STATES.includes(st)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-state", `estado no v\xE1lido \xAB${st}\xBB en ${key}`);
|
|
491
|
+
if (STATE_RANK[st] < STATE_RANK[state]) state = st;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (!hasSegment) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-xliff", `<unit> sin <segment> en ${key}`);
|
|
495
|
+
if (!sawTarget || target === "" && state === "initial") target = null;
|
|
496
|
+
units.push({ key, source, target, state, context, notes, translate: u.attrs["translate"] !== "no" });
|
|
497
|
+
}
|
|
498
|
+
return { srcLang, trgLang, namespace, syntax, units };
|
|
499
|
+
}
|
|
500
|
+
function xliffToCatalogs(doc) {
|
|
501
|
+
const sourceMessages = {};
|
|
502
|
+
const targetMessages = {};
|
|
503
|
+
const states = {};
|
|
504
|
+
for (const u of doc.units) {
|
|
505
|
+
sourceMessages[u.key] = u.source;
|
|
506
|
+
states[u.key] = u.state;
|
|
507
|
+
if (u.target !== null) targetMessages[u.key] = u.target;
|
|
508
|
+
}
|
|
509
|
+
const source = { version: chunk2A6WFLXS_cjs.CATALOG_DOC_VERSION, namespace: doc.namespace, locale: doc.srcLang, syntax: doc.syntax, messages: sourceMessages };
|
|
510
|
+
const target = doc.trgLang ? { version: chunk2A6WFLXS_cjs.CATALOG_DOC_VERSION, namespace: doc.namespace, locale: doc.trgLang, syntax: doc.syntax, messages: targetMessages } : null;
|
|
511
|
+
return { source, target, states };
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
exports.XLIFF_NS = XLIFF_NS;
|
|
515
|
+
exports.XLIFF_STATES = XLIFF_STATES;
|
|
516
|
+
exports.exportXliff = exportXliff;
|
|
517
|
+
exports.importXliff = importXliff;
|
|
518
|
+
exports.xliffToCatalogs = xliffToCatalogs;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@customyai/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Customy CLI: validate, type and sync customy.app.json (customy apps ...)
|
|
3
|
+
"version": "0.10.1",
|
|
4
|
+
"description": "Customy CLI: validate, type and sync customy.app.json (customy apps ...), provision TEST users (customy users | audit | policy | whoami), operate Customy WhatsApp (customy whatsapp numbers | send | messages | templates | findings | webhooks | broadcasts | flows) and manage Customy Experience translation catalogs and releases (customy experience pull | push | export | import | status | signing | ...). Also usable as a library.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Customy <hello@customy.ai>",
|
|
7
7
|
"repository": {
|
|
@@ -19,7 +19,11 @@
|
|
|
19
19
|
"codegen",
|
|
20
20
|
"sdk",
|
|
21
21
|
"provisioning",
|
|
22
|
-
"test-users"
|
|
22
|
+
"test-users",
|
|
23
|
+
"whatsapp",
|
|
24
|
+
"experience",
|
|
25
|
+
"i18n",
|
|
26
|
+
"translations"
|
|
23
27
|
],
|
|
24
28
|
"type": "module",
|
|
25
29
|
"main": "./dist/index.cjs",
|
|
@@ -56,7 +60,9 @@
|
|
|
56
60
|
"test": "vitest run"
|
|
57
61
|
},
|
|
58
62
|
"dependencies": {
|
|
63
|
+
"@customyai/core": "^0.3.1",
|
|
59
64
|
"@customyai/provisioning": "^0.1.2",
|
|
65
|
+
"@customyai/whatsapp": "^0.3.0",
|
|
60
66
|
"zod": "^3.23.8"
|
|
61
67
|
},
|
|
62
68
|
"devDependencies": {
|