@customyai/cli 0.7.2 → 0.11.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,237 @@
1
+ // src/vendor/i18n-tools/icu.ts
2
+ var NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
3
+ var SIMPLE_TYPES = /* @__PURE__ */ new Set(["number", "date", "time"]);
4
+ var COMPLEX_TYPES = /* @__PURE__ */ new Set(["plural", "select", "selectordinal"]);
5
+ var MAX_NESTING = 16;
6
+ var WS = /\s/;
7
+ var Parser = class {
8
+ constructor(s) {
9
+ this.s = s;
10
+ }
11
+ s;
12
+ i = 0;
13
+ parseText(inPlural, depth) {
14
+ const { s } = this;
15
+ const out = [];
16
+ let buf = "";
17
+ const flush = () => {
18
+ if (buf) {
19
+ out.push({ t: "text", text: buf });
20
+ buf = "";
21
+ }
22
+ };
23
+ while (this.i < s.length) {
24
+ const c = s[this.i];
25
+ if (c === "'") {
26
+ const next = s[this.i + 1];
27
+ if (next === "'") {
28
+ flush();
29
+ out.push({ t: "quote", raw: "''" });
30
+ this.i += 2;
31
+ continue;
32
+ }
33
+ if (next === "{" || next === "}") {
34
+ const end = s.indexOf("'", this.i + 2);
35
+ const stop = end === -1 ? s.length : end + 1;
36
+ flush();
37
+ out.push({ t: "quote", raw: s.slice(this.i, stop) });
38
+ this.i = stop;
39
+ continue;
40
+ }
41
+ buf += c;
42
+ this.i += 1;
43
+ continue;
44
+ }
45
+ if (c === "}") {
46
+ if (depth > 0) break;
47
+ buf += c;
48
+ this.i += 1;
49
+ continue;
50
+ }
51
+ if (c === "{") {
52
+ const save = this.i;
53
+ const node = this.tryArgument(depth);
54
+ if (node) {
55
+ flush();
56
+ out.push(node);
57
+ continue;
58
+ }
59
+ this.i = save + 1;
60
+ buf += c;
61
+ continue;
62
+ }
63
+ if (c === "#" && inPlural) {
64
+ flush();
65
+ out.push({ t: "hash" });
66
+ this.i += 1;
67
+ continue;
68
+ }
69
+ buf += c;
70
+ this.i += 1;
71
+ }
72
+ flush();
73
+ return out;
74
+ }
75
+ /** Intenta leer un argumento desde `{`. Si no es válido devuelve null (quien llama restaura `i`). */
76
+ tryArgument(depth) {
77
+ const { s } = this;
78
+ const start = this.i;
79
+ let j = start + 1;
80
+ while (j < s.length && s[j] !== "}" && s[j] !== ",") j += 1;
81
+ if (j >= s.length) return null;
82
+ const name = s.slice(start + 1, j).trim();
83
+ if (!NAME.test(name)) return null;
84
+ if (s[j] === "}") {
85
+ this.i = j + 1;
86
+ return { t: "arg", raw: s.slice(start, j + 1), name, type: null };
87
+ }
88
+ let k = j + 1;
89
+ while (k < s.length && s[k] !== "}" && s[k] !== ",") k += 1;
90
+ if (k >= s.length) return null;
91
+ const type = s.slice(j + 1, k).trim();
92
+ const simple = SIMPLE_TYPES.has(type);
93
+ if (!simple && !COMPLEX_TYPES.has(type)) return null;
94
+ if (s[k] === "}") {
95
+ if (!simple) return null;
96
+ this.i = k + 1;
97
+ return { t: "arg", raw: s.slice(start, k + 1), name, type };
98
+ }
99
+ if (simple) {
100
+ const end = s.indexOf("}", k + 1);
101
+ if (end === -1) return null;
102
+ this.i = end + 1;
103
+ return { t: "arg", raw: s.slice(start, end + 1), name, type };
104
+ }
105
+ if (depth >= MAX_NESTING) return null;
106
+ let headEnd = k + 1;
107
+ if (type !== "select") {
108
+ const off = /^\s*offset:\s*\d+/.exec(s.slice(headEnd, headEnd + 40));
109
+ if (off) headEnd += off[0].length;
110
+ }
111
+ const head = s.slice(start, headEnd);
112
+ let p = headEnd;
113
+ const options = [];
114
+ for (; ; ) {
115
+ const wsStart = p;
116
+ while (p < s.length && WS.test(s[p])) p += 1;
117
+ if (p >= s.length) return null;
118
+ if (s[p] === "}") {
119
+ const tail = s.slice(wsStart, p + 1);
120
+ this.i = p + 1;
121
+ return { t: "complex", name, type, head, options, tail };
122
+ }
123
+ const selStart = p;
124
+ while (p < s.length && s[p] !== "{" && s[p] !== "}" && !WS.test(s[p])) p += 1;
125
+ const selector = s.slice(selStart, p);
126
+ while (p < s.length && WS.test(s[p])) p += 1;
127
+ if (!selector || s[p] !== "{") return null;
128
+ const open = s.slice(wsStart, p + 1);
129
+ this.i = p + 1;
130
+ const body = this.parseText(type !== "select", depth + 1);
131
+ if (this.i >= s.length || s[this.i] !== "}") return null;
132
+ p = this.i + 1;
133
+ options.push({ selector, open, body });
134
+ }
135
+ }
136
+ };
137
+ function parseIcu(message) {
138
+ const parser = new Parser(message);
139
+ return parser.parseText(false, 0);
140
+ }
141
+ function unparseIcu(nodes) {
142
+ let out = "";
143
+ for (const n of nodes) {
144
+ switch (n.t) {
145
+ case "text":
146
+ out += n.text;
147
+ break;
148
+ case "arg":
149
+ case "quote":
150
+ out += n.raw;
151
+ break;
152
+ case "hash":
153
+ out += "#";
154
+ break;
155
+ case "complex":
156
+ out += n.head;
157
+ for (const o of n.options) out += `${o.open}${unparseIcu(o.body)}}`;
158
+ out += n.tail;
159
+ break;
160
+ }
161
+ }
162
+ return out;
163
+ }
164
+ function tokenizeIcu(message) {
165
+ const tokens = [];
166
+ const push = (t) => {
167
+ const last = tokens[tokens.length - 1];
168
+ if (last && t.kind === "text" && last.kind === "text") {
169
+ tokens[tokens.length - 1] = { kind: "text", text: last.text + t.text };
170
+ return;
171
+ }
172
+ if (last && t.kind === "ph" && last.kind === "ph" && t.role === "syntax" && last.role === "syntax") {
173
+ tokens[tokens.length - 1] = { kind: "ph", raw: last.raw + t.raw, role: "syntax", name: last.name };
174
+ return;
175
+ }
176
+ tokens.push(t);
177
+ };
178
+ const walk = (nodes) => {
179
+ for (const n of nodes) {
180
+ switch (n.t) {
181
+ case "text":
182
+ push({ kind: "text", text: n.text });
183
+ break;
184
+ case "arg":
185
+ push({ kind: "ph", raw: n.raw, role: "arg", name: n.name });
186
+ break;
187
+ case "hash":
188
+ push({ kind: "ph", raw: "#", role: "hash", name: null });
189
+ break;
190
+ case "quote":
191
+ push({ kind: "ph", raw: n.raw, role: "quote", name: null });
192
+ break;
193
+ case "complex":
194
+ push({ kind: "ph", raw: n.head, role: "syntax", name: n.name });
195
+ for (const o of n.options) {
196
+ push({ kind: "ph", raw: o.open, role: "syntax", name: n.name });
197
+ walk(o.body);
198
+ push({ kind: "ph", raw: "}", role: "syntax", name: n.name });
199
+ }
200
+ push({ kind: "ph", raw: n.tail, role: "syntax", name: n.name });
201
+ break;
202
+ }
203
+ }
204
+ };
205
+ walk(parseIcu(message));
206
+ return tokens;
207
+ }
208
+ function collectComplex(message) {
209
+ const found = [];
210
+ const walk = (nodes) => {
211
+ for (const n of nodes) {
212
+ if (n.t !== "complex") continue;
213
+ found.push({ name: n.name, type: n.type, selectors: n.options.map((o) => o.selector) });
214
+ for (const o of n.options) walk(o.body);
215
+ }
216
+ };
217
+ walk(parseIcu(message));
218
+ return found;
219
+ }
220
+ var CATEGORY_ORDER = ["zero", "one", "two", "few", "many", "other"];
221
+ function pluralCategories(locale, type = "cardinal") {
222
+ try {
223
+ const cats = new Intl.PluralRules(locale, { type }).resolvedOptions().pluralCategories;
224
+ const set = new Set(cats);
225
+ const ordered = CATEGORY_ORDER.filter((c) => set.has(c));
226
+ return ordered.length > 0 ? ordered : ["other"];
227
+ } catch {
228
+ return ["one", "other"];
229
+ }
230
+ }
231
+ function plainText(message, placeholder = "\uFFFC") {
232
+ let out = "";
233
+ for (const t of tokenizeIcu(message)) out += t.kind === "text" ? t.text : placeholder;
234
+ return out;
235
+ }
236
+
237
+ export { collectComplex, parseIcu, plainText, pluralCategories, tokenizeIcu, unparseIcu };
@@ -0,0 +1,244 @@
1
+ 'use strict';
2
+
3
+ // src/vendor/i18n-tools/icu.ts
4
+ var NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
5
+ var SIMPLE_TYPES = /* @__PURE__ */ new Set(["number", "date", "time"]);
6
+ var COMPLEX_TYPES = /* @__PURE__ */ new Set(["plural", "select", "selectordinal"]);
7
+ var MAX_NESTING = 16;
8
+ var WS = /\s/;
9
+ var Parser = class {
10
+ constructor(s) {
11
+ this.s = s;
12
+ }
13
+ s;
14
+ i = 0;
15
+ parseText(inPlural, depth) {
16
+ const { s } = this;
17
+ const out = [];
18
+ let buf = "";
19
+ const flush = () => {
20
+ if (buf) {
21
+ out.push({ t: "text", text: buf });
22
+ buf = "";
23
+ }
24
+ };
25
+ while (this.i < s.length) {
26
+ const c = s[this.i];
27
+ if (c === "'") {
28
+ const next = s[this.i + 1];
29
+ if (next === "'") {
30
+ flush();
31
+ out.push({ t: "quote", raw: "''" });
32
+ this.i += 2;
33
+ continue;
34
+ }
35
+ if (next === "{" || next === "}") {
36
+ const end = s.indexOf("'", this.i + 2);
37
+ const stop = end === -1 ? s.length : end + 1;
38
+ flush();
39
+ out.push({ t: "quote", raw: s.slice(this.i, stop) });
40
+ this.i = stop;
41
+ continue;
42
+ }
43
+ buf += c;
44
+ this.i += 1;
45
+ continue;
46
+ }
47
+ if (c === "}") {
48
+ if (depth > 0) break;
49
+ buf += c;
50
+ this.i += 1;
51
+ continue;
52
+ }
53
+ if (c === "{") {
54
+ const save = this.i;
55
+ const node = this.tryArgument(depth);
56
+ if (node) {
57
+ flush();
58
+ out.push(node);
59
+ continue;
60
+ }
61
+ this.i = save + 1;
62
+ buf += c;
63
+ continue;
64
+ }
65
+ if (c === "#" && inPlural) {
66
+ flush();
67
+ out.push({ t: "hash" });
68
+ this.i += 1;
69
+ continue;
70
+ }
71
+ buf += c;
72
+ this.i += 1;
73
+ }
74
+ flush();
75
+ return out;
76
+ }
77
+ /** Intenta leer un argumento desde `{`. Si no es válido devuelve null (quien llama restaura `i`). */
78
+ tryArgument(depth) {
79
+ const { s } = this;
80
+ const start = this.i;
81
+ let j = start + 1;
82
+ while (j < s.length && s[j] !== "}" && s[j] !== ",") j += 1;
83
+ if (j >= s.length) return null;
84
+ const name = s.slice(start + 1, j).trim();
85
+ if (!NAME.test(name)) return null;
86
+ if (s[j] === "}") {
87
+ this.i = j + 1;
88
+ return { t: "arg", raw: s.slice(start, j + 1), name, type: null };
89
+ }
90
+ let k = j + 1;
91
+ while (k < s.length && s[k] !== "}" && s[k] !== ",") k += 1;
92
+ if (k >= s.length) return null;
93
+ const type = s.slice(j + 1, k).trim();
94
+ const simple = SIMPLE_TYPES.has(type);
95
+ if (!simple && !COMPLEX_TYPES.has(type)) return null;
96
+ if (s[k] === "}") {
97
+ if (!simple) return null;
98
+ this.i = k + 1;
99
+ return { t: "arg", raw: s.slice(start, k + 1), name, type };
100
+ }
101
+ if (simple) {
102
+ const end = s.indexOf("}", k + 1);
103
+ if (end === -1) return null;
104
+ this.i = end + 1;
105
+ return { t: "arg", raw: s.slice(start, end + 1), name, type };
106
+ }
107
+ if (depth >= MAX_NESTING) return null;
108
+ let headEnd = k + 1;
109
+ if (type !== "select") {
110
+ const off = /^\s*offset:\s*\d+/.exec(s.slice(headEnd, headEnd + 40));
111
+ if (off) headEnd += off[0].length;
112
+ }
113
+ const head = s.slice(start, headEnd);
114
+ let p = headEnd;
115
+ const options = [];
116
+ for (; ; ) {
117
+ const wsStart = p;
118
+ while (p < s.length && WS.test(s[p])) p += 1;
119
+ if (p >= s.length) return null;
120
+ if (s[p] === "}") {
121
+ const tail = s.slice(wsStart, p + 1);
122
+ this.i = p + 1;
123
+ return { t: "complex", name, type, head, options, tail };
124
+ }
125
+ const selStart = p;
126
+ while (p < s.length && s[p] !== "{" && s[p] !== "}" && !WS.test(s[p])) p += 1;
127
+ const selector = s.slice(selStart, p);
128
+ while (p < s.length && WS.test(s[p])) p += 1;
129
+ if (!selector || s[p] !== "{") return null;
130
+ const open = s.slice(wsStart, p + 1);
131
+ this.i = p + 1;
132
+ const body = this.parseText(type !== "select", depth + 1);
133
+ if (this.i >= s.length || s[this.i] !== "}") return null;
134
+ p = this.i + 1;
135
+ options.push({ selector, open, body });
136
+ }
137
+ }
138
+ };
139
+ function parseIcu(message) {
140
+ const parser = new Parser(message);
141
+ return parser.parseText(false, 0);
142
+ }
143
+ function unparseIcu(nodes) {
144
+ let out = "";
145
+ for (const n of nodes) {
146
+ switch (n.t) {
147
+ case "text":
148
+ out += n.text;
149
+ break;
150
+ case "arg":
151
+ case "quote":
152
+ out += n.raw;
153
+ break;
154
+ case "hash":
155
+ out += "#";
156
+ break;
157
+ case "complex":
158
+ out += n.head;
159
+ for (const o of n.options) out += `${o.open}${unparseIcu(o.body)}}`;
160
+ out += n.tail;
161
+ break;
162
+ }
163
+ }
164
+ return out;
165
+ }
166
+ function tokenizeIcu(message) {
167
+ const tokens = [];
168
+ const push = (t) => {
169
+ const last = tokens[tokens.length - 1];
170
+ if (last && t.kind === "text" && last.kind === "text") {
171
+ tokens[tokens.length - 1] = { kind: "text", text: last.text + t.text };
172
+ return;
173
+ }
174
+ if (last && t.kind === "ph" && last.kind === "ph" && t.role === "syntax" && last.role === "syntax") {
175
+ tokens[tokens.length - 1] = { kind: "ph", raw: last.raw + t.raw, role: "syntax", name: last.name };
176
+ return;
177
+ }
178
+ tokens.push(t);
179
+ };
180
+ const walk = (nodes) => {
181
+ for (const n of nodes) {
182
+ switch (n.t) {
183
+ case "text":
184
+ push({ kind: "text", text: n.text });
185
+ break;
186
+ case "arg":
187
+ push({ kind: "ph", raw: n.raw, role: "arg", name: n.name });
188
+ break;
189
+ case "hash":
190
+ push({ kind: "ph", raw: "#", role: "hash", name: null });
191
+ break;
192
+ case "quote":
193
+ push({ kind: "ph", raw: n.raw, role: "quote", name: null });
194
+ break;
195
+ case "complex":
196
+ push({ kind: "ph", raw: n.head, role: "syntax", name: n.name });
197
+ for (const o of n.options) {
198
+ push({ kind: "ph", raw: o.open, role: "syntax", name: n.name });
199
+ walk(o.body);
200
+ push({ kind: "ph", raw: "}", role: "syntax", name: n.name });
201
+ }
202
+ push({ kind: "ph", raw: n.tail, role: "syntax", name: n.name });
203
+ break;
204
+ }
205
+ }
206
+ };
207
+ walk(parseIcu(message));
208
+ return tokens;
209
+ }
210
+ function collectComplex(message) {
211
+ const found = [];
212
+ const walk = (nodes) => {
213
+ for (const n of nodes) {
214
+ if (n.t !== "complex") continue;
215
+ found.push({ name: n.name, type: n.type, selectors: n.options.map((o) => o.selector) });
216
+ for (const o of n.options) walk(o.body);
217
+ }
218
+ };
219
+ walk(parseIcu(message));
220
+ return found;
221
+ }
222
+ var CATEGORY_ORDER = ["zero", "one", "two", "few", "many", "other"];
223
+ function pluralCategories(locale, type = "cardinal") {
224
+ try {
225
+ const cats = new Intl.PluralRules(locale, { type }).resolvedOptions().pluralCategories;
226
+ const set = new Set(cats);
227
+ const ordered = CATEGORY_ORDER.filter((c) => set.has(c));
228
+ return ordered.length > 0 ? ordered : ["other"];
229
+ } catch {
230
+ return ["one", "other"];
231
+ }
232
+ }
233
+ function plainText(message, placeholder = "\uFFFC") {
234
+ let out = "";
235
+ for (const t of tokenizeIcu(message)) out += t.kind === "text" ? t.text : placeholder;
236
+ return out;
237
+ }
238
+
239
+ exports.collectComplex = collectComplex;
240
+ exports.parseIcu = parseIcu;
241
+ exports.plainText = plainText;
242
+ exports.pluralCategories = pluralCategories;
243
+ exports.tokenizeIcu = tokenizeIcu;
244
+ exports.unparseIcu = unparseIcu;
@@ -0,0 +1,27 @@
1
+ // src/vendor/i18n-tools/errors.ts
2
+ var I18nToolsError = class extends Error {
3
+ code;
4
+ constructor(code, message) {
5
+ super(message);
6
+ this.name = "I18nToolsError";
7
+ this.code = code;
8
+ }
9
+ };
10
+ function utf8ByteLength(text) {
11
+ let bytes = 0;
12
+ for (let i = 0; i < text.length; i += 1) {
13
+ const c = text.charCodeAt(i);
14
+ if (c < 128) bytes += 1;
15
+ else if (c < 2048) bytes += 2;
16
+ else if (c >= 55296 && c <= 56319 && i + 1 < text.length && (text.charCodeAt(i + 1) & 64512) === 56320) {
17
+ bytes += 4;
18
+ i += 1;
19
+ } else bytes += 3;
20
+ }
21
+ return bytes;
22
+ }
23
+ function compareCodeUnits(a, b) {
24
+ return a < b ? -1 : a > b ? 1 : 0;
25
+ }
26
+
27
+ export { I18nToolsError, compareCodeUnits, utf8ByteLength };
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ // src/vendor/i18n-tools/errors.ts
4
+ var I18nToolsError = class extends Error {
5
+ code;
6
+ constructor(code, message) {
7
+ super(message);
8
+ this.name = "I18nToolsError";
9
+ this.code = code;
10
+ }
11
+ };
12
+ function utf8ByteLength(text) {
13
+ let bytes = 0;
14
+ for (let i = 0; i < text.length; i += 1) {
15
+ const c = text.charCodeAt(i);
16
+ if (c < 128) bytes += 1;
17
+ else if (c < 2048) bytes += 2;
18
+ else if (c >= 55296 && c <= 56319 && i + 1 < text.length && (text.charCodeAt(i + 1) & 64512) === 56320) {
19
+ bytes += 4;
20
+ i += 1;
21
+ } else bytes += 3;
22
+ }
23
+ return bytes;
24
+ }
25
+ function compareCodeUnits(a, b) {
26
+ return a < b ? -1 : a > b ? 1 : 0;
27
+ }
28
+
29
+ exports.I18nToolsError = I18nToolsError;
30
+ exports.compareCodeUnits = compareCodeUnits;
31
+ exports.utf8ByteLength = utf8ByteLength;