@jayfong/x-utils 1.0.0-202407012223

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.
Files changed (77) hide show
  1. package/_cjs/ai.js +80 -0
  2. package/_cjs/cli.js +51 -0
  3. package/_cjs/clipboard.js +65 -0
  4. package/_cjs/cmd.js +42 -0
  5. package/_cjs/crawler.js +341 -0
  6. package/_cjs/csv.js +97 -0
  7. package/_cjs/data_set.js +115 -0
  8. package/_cjs/env.js +63 -0
  9. package/_cjs/fs.js +35 -0
  10. package/_cjs/html.js +62 -0
  11. package/_cjs/http_server.js +56 -0
  12. package/_cjs/json.js +49 -0
  13. package/_cjs/ksb.js +217 -0
  14. package/_cjs/number.js +39 -0
  15. package/_cjs/ocr.js +74 -0
  16. package/_cjs/path.js +35 -0
  17. package/_cjs/pinyin.js +32 -0
  18. package/_cjs/puppeteer.js +271 -0
  19. package/_cjs/runner.js +88 -0
  20. package/_cjs/task.js +41 -0
  21. package/_cjs/text.js +136 -0
  22. package/_cjs/unicode/lib_unicode.js +58643 -0
  23. package/_cjs/unicode/unicode.js +441 -0
  24. package/_cjs/upload.js +100 -0
  25. package/_cjs/yaml.js +52 -0
  26. package/ai.d.ts +26 -0
  27. package/ai.js +60 -0
  28. package/cli.d.ts +14 -0
  29. package/cli.js +21 -0
  30. package/clipboard.d.ts +6 -0
  31. package/clipboard.js +35 -0
  32. package/cmd.d.ts +5 -0
  33. package/cmd.js +22 -0
  34. package/crawler.d.ts +162 -0
  35. package/crawler.js +332 -0
  36. package/csv.d.ts +14 -0
  37. package/csv.js +67 -0
  38. package/data_set.d.ts +22 -0
  39. package/data_set.js +85 -0
  40. package/env.d.ts +4 -0
  41. package/env.js +32 -0
  42. package/fs.d.ts +2 -0
  43. package/fs.js +5 -0
  44. package/html.d.ts +7 -0
  45. package/html.js +45 -0
  46. package/http_server.d.ts +10 -0
  47. package/http_server.js +26 -0
  48. package/json.d.ts +6 -0
  49. package/json.js +19 -0
  50. package/ksb.d.ts +32 -0
  51. package/ksb.js +197 -0
  52. package/number.d.ts +3 -0
  53. package/number.js +9 -0
  54. package/ocr.d.ts +10 -0
  55. package/ocr.js +54 -0
  56. package/ofd.d.ts +1 -0
  57. package/package.json +158 -0
  58. package/path.d.ts +2 -0
  59. package/path.js +5 -0
  60. package/pinyin.d.ts +3 -0
  61. package/pinyin.js +12 -0
  62. package/puppeteer.d.ts +38 -0
  63. package/puppeteer.js +241 -0
  64. package/runner.d.ts +13 -0
  65. package/runner.js +58 -0
  66. package/task.d.ts +6 -0
  67. package/task.js +21 -0
  68. package/text.d.ts +63 -0
  69. package/text.js +119 -0
  70. package/unicode/lib_unicode.d.ts +4 -0
  71. package/unicode/lib_unicode.js +58623 -0
  72. package/unicode/unicode.d.ts +347 -0
  73. package/unicode/unicode.js +426 -0
  74. package/upload.d.ts +22 -0
  75. package/upload.js +70 -0
  76. package/yaml.d.ts +6 -0
  77. package/yaml.js +22 -0
@@ -0,0 +1,441 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var unicode_exports = {};
20
+ __export(unicode_exports, {
21
+ XUnicode: () => XUnicode
22
+ });
23
+ module.exports = __toCommonJS(unicode_exports);
24
+ var import_vtils = require("vtils");
25
+ var import_puppeteer = require("../puppeteer.js");
26
+ var import_text = require("../text.js");
27
+ var import_lib_unicode = require("./lib_unicode.js");
28
+ const ublockMap = {
29
+ // @index('./lib_unicode.js', /BlockStart\[(\d+)\]\s*=\s*"(.+?)";\s*\/\/\s*([^\(\r\n]+)\b/g, m => `'${m[3]}': ${m[1]},`)
30
+ "Basic Latin": 0,
31
+ "Latin-1 Supplement": 1,
32
+ "Latin Extended-A": 2,
33
+ "Latin Extended-B": 3,
34
+ "IPA Extensions": 4,
35
+ "Spacing Modifier Letters": 5,
36
+ "Combining Diacritical Marks": 6,
37
+ "Greek and Coptic": 7,
38
+ Cyrillic: 8,
39
+ "Cyrillic Supplement": 9,
40
+ Armenian: 10,
41
+ Hebrew: 11,
42
+ Arabic: 12,
43
+ Syriac: 13,
44
+ "Arabic Supplement": 14,
45
+ Thaana: 15,
46
+ NKo: 16,
47
+ Samaritan: 17,
48
+ Mandaic: 18,
49
+ "Syriac Supplement": 19,
50
+ "Arabic Extended-B": 20,
51
+ "Arabic Extended-A": 21,
52
+ Devanagari: 22,
53
+ Bengali: 23,
54
+ Gurmukhi: 24,
55
+ Gujarati: 25,
56
+ Oriya: 26,
57
+ Tamil: 27,
58
+ Telugu: 28,
59
+ Kannada: 29,
60
+ Malayalam: 30,
61
+ Sinhala: 31,
62
+ Thai: 32,
63
+ Lao: 33,
64
+ Tibetan: 34,
65
+ Myanmar: 35,
66
+ Georgian: 36,
67
+ "Hangul Jamo": 37,
68
+ Ethiopic: 38,
69
+ "Ethiopic Supplement": 39,
70
+ Cherokee: 40,
71
+ "Unified Canadian Aboriginal Syllabics": 41,
72
+ Ogham: 42,
73
+ Runic: 43,
74
+ Tagalog: 44,
75
+ Hanunoo: 45,
76
+ Buhid: 46,
77
+ Tagbanwa: 47,
78
+ Khmer: 48,
79
+ Mongolian: 49,
80
+ "Unified Canadian Aboriginal Syllabics Extended": 50,
81
+ Limbu: 51,
82
+ "Tai Le": 52,
83
+ "New Tai Lue": 53,
84
+ "Khmer Symbols": 54,
85
+ Buginese: 55,
86
+ "Tai Tham": 56,
87
+ "Combining Diacritical Marks Extended": 57,
88
+ Balinese: 58,
89
+ Sundanese: 59,
90
+ Batak: 60,
91
+ Lepcha: 61,
92
+ "Ol Chiki": 62,
93
+ "Cyrillic Extended-C": 63,
94
+ "Georgian Extended": 64,
95
+ "Sundanese Supplement": 65,
96
+ "Vedic Extensions": 66,
97
+ "Phonetic Extensions": 67,
98
+ "Phonetic Extensions Supplement": 68,
99
+ "Combining Diacritical Marks Supplement": 69,
100
+ "Latin Extended Additional": 70,
101
+ "Greek Extended": 71,
102
+ "General Punctuation": 72,
103
+ "Superscripts and Subscripts": 73,
104
+ "Currency Symbols": 74,
105
+ "Combining Diacritical Marks for Symbols": 75,
106
+ "Letterlike Symbols": 76,
107
+ "Number Forms": 77,
108
+ Arrows: 78,
109
+ "Mathematical Operators": 79,
110
+ "Miscellaneous Technical": 80,
111
+ "Control Pictures": 81,
112
+ "Optical Character Recognition": 82,
113
+ "Enclosed Alphanumerics": 83,
114
+ "Box Drawing": 84,
115
+ "Block Elements": 85,
116
+ "Geometric Shapes": 86,
117
+ "Miscellaneous Symbols": 87,
118
+ Dingbats: 88,
119
+ "Miscellaneous Mathematical Symbols-A": 89,
120
+ "Supplemental Arrows-A": 90,
121
+ "Braille Patterns": 91,
122
+ "Supplemental Arrows-B": 92,
123
+ "Miscellaneous Mathematical Symbols-B": 93,
124
+ "Supplemental Mathematical Operators": 94,
125
+ "Miscellaneous Symbols and Arrows": 95,
126
+ Glagolitic: 96,
127
+ "Latin Extended-C": 97,
128
+ Coptic: 98,
129
+ "Georgian Supplement": 99,
130
+ Tifinagh: 100,
131
+ "Ethiopic Extended": 101,
132
+ "Cyrillic Extended-A": 102,
133
+ "Supplemental Punctuation": 103,
134
+ "CJK Radicals Supplement": 104,
135
+ "Kangxi Radicals": 105,
136
+ "Ideographic Description Characters": 106,
137
+ "CJK Symbols and Punctuation": 107,
138
+ Hiragana: 108,
139
+ Katakana: 109,
140
+ Bopomofo: 110,
141
+ "Hangul Compatibility Jamo": 111,
142
+ Kanbun: 112,
143
+ "Bopomofo Extended": 113,
144
+ "CJK Strokes": 114,
145
+ "Katakana Phonetic Extensions": 115,
146
+ "Enclosed CJK Letters and Months": 116,
147
+ "CJK Compatibility": 117,
148
+ "CJK Unified Ideographs Extension A": 118,
149
+ "Yijing Hexagram Symbols": 119,
150
+ "CJK Unified Ideographs": 120,
151
+ "Yi Syllables": 121,
152
+ "Yi Radicals": 122,
153
+ Lisu: 123,
154
+ Vai: 124,
155
+ "Cyrillic Extended-B": 125,
156
+ Bamum: 126,
157
+ "Modifier Tone Letters": 127,
158
+ "Latin Extended-D": 128,
159
+ "Syloti Nagri": 129,
160
+ "Common Indic Number Forms": 130,
161
+ "Phags-pa": 131,
162
+ Saurashtra: 132,
163
+ "Devanagari Extended": 133,
164
+ "Kayah Li": 134,
165
+ Rejang: 135,
166
+ "Hangul Jamo Extended-A": 136,
167
+ Javanese: 137,
168
+ "Myanmar Extended-B": 138,
169
+ Cham: 139,
170
+ "Myanmar Extended-A": 140,
171
+ "Tai Viet": 141,
172
+ "Meetei Mayek Extensions": 142,
173
+ "Ethiopic Extended-A": 143,
174
+ "Latin Extended-E": 144,
175
+ "Cherokee Supplement": 145,
176
+ "Meetei Mayek": 146,
177
+ "Hangul Syllables": 147,
178
+ "Hangul Jamo Extended-B": 148,
179
+ "Private Use Area": 149,
180
+ "CJK Compatibility Ideographs": 150,
181
+ "Alphabetic Presentation Forms": 151,
182
+ "Arabic Presentation Forms-A": 152,
183
+ "Variation Selectors": 153,
184
+ "Vertical Forms": 154,
185
+ "Combining Half Marks": 155,
186
+ "CJK Compatibility Forms": 156,
187
+ "Small Form Variants": 157,
188
+ "Arabic Presentation Forms-B": 158,
189
+ "Halfwidth and Fullwidth Forms": 159,
190
+ Specials: 160,
191
+ "Linear B Syllabary": 161,
192
+ "Linear B Ideograms": 162,
193
+ "Aegean Numbers": 163,
194
+ "Ancient Greek Numbers": 164,
195
+ "Ancient Symbols": 165,
196
+ "Phaistos Disc": 166,
197
+ Lycian: 167,
198
+ Carian: 168,
199
+ "Coptic Epact Numbers": 169,
200
+ "Old Italic": 170,
201
+ Gothic: 171,
202
+ "Old Permic": 172,
203
+ Ugaritic: 173,
204
+ "Old Persian": 174,
205
+ Deseret: 175,
206
+ Shavian: 176,
207
+ Osmanya: 177,
208
+ Osage: 178,
209
+ Elbasan: 179,
210
+ "Caucasian Albanian": 180,
211
+ Vithkuqi: 181,
212
+ "Linear A": 182,
213
+ "Latin Extended-F": 183,
214
+ "Cypriot Syllabary": 184,
215
+ "Imperial Aramaic": 185,
216
+ Palmyrene: 186,
217
+ Nabataean: 187,
218
+ Hatran: 188,
219
+ Phoenician: 189,
220
+ Lydian: 190,
221
+ "Meroitic Hieroglyphs": 191,
222
+ "Meroitic Cursive": 192,
223
+ Kharoshthi: 193,
224
+ "Old South Arabian": 194,
225
+ "Old North Arabian": 195,
226
+ Manichaean: 196,
227
+ Avestan: 197,
228
+ "Inscriptional Parthian": 198,
229
+ "Inscriptional Pahlavi": 199,
230
+ "Psalter Pahlavi": 200,
231
+ "Old Turkic": 201,
232
+ "Old Hungarian": 202,
233
+ "Hanifi Rohingya": 203,
234
+ "Rumi Numeral Symbols": 204,
235
+ Yezidi: 205,
236
+ "Arabic Extended-C": 206,
237
+ "Old Sogdian": 207,
238
+ Sogdian: 208,
239
+ "Old Uyghur": 209,
240
+ Chorasmian: 210,
241
+ Elymaic: 211,
242
+ Brahmi: 212,
243
+ Kaithi: 213,
244
+ "Sora Sompeng": 214,
245
+ Chakma: 215,
246
+ Mahajani: 216,
247
+ Sharada: 217,
248
+ "Sinhala Archaic Numbers": 218,
249
+ Khojki: 219,
250
+ Multani: 220,
251
+ Khudawadi: 221,
252
+ Grantha: 222,
253
+ Newa: 223,
254
+ Tirhuta: 224,
255
+ Siddham: 225,
256
+ Modi: 226,
257
+ "Mongolian Supplement": 227,
258
+ Takri: 228,
259
+ Ahom: 229,
260
+ Dogra: 230,
261
+ "Warang Citi": 231,
262
+ "Dives Akuru": 232,
263
+ Nandinagari: 233,
264
+ "Zanabazar Square": 234,
265
+ Soyombo: 235,
266
+ "Unified Canadian Aboriginal Syllabics Extended-A": 236,
267
+ "Pau Cin Hau": 237,
268
+ "Devanagari Extended-A": 238,
269
+ Bhaiksuki: 239,
270
+ Marchen: 240,
271
+ "Masaram Gondi": 241,
272
+ "Gunjala Gondi": 242,
273
+ Makasar: 243,
274
+ Kawi: 244,
275
+ "Lisu Supplement": 245,
276
+ "Tamil Supplement": 246,
277
+ Cuneiform: 247,
278
+ "Cuneiform Numbers and Punctuation": 248,
279
+ "Early Dynastic Cuneiform": 249,
280
+ "Cypro-Minoan": 250,
281
+ "Egyptian Hieroglyphs": 251,
282
+ "Egyptian Hieroglyph Format Controls": 252,
283
+ "Anatolian Hieroglyphs": 253,
284
+ "Bamum Supplement": 254,
285
+ Mro: 255,
286
+ Tangsa: 256,
287
+ "Bassa Vah": 257,
288
+ "Pahawh Hmong": 258,
289
+ Medefaidrin: 259,
290
+ Miao: 260,
291
+ "Ideographic Symbols and Punctuation": 261,
292
+ Tangut: 262,
293
+ "Tangut Components": 263,
294
+ "Khitan Small Script": 264,
295
+ "Tangut Supplement": 265,
296
+ "Kana Extended-B": 266,
297
+ "Kana Supplement": 267,
298
+ "Kana Extended-A": 268,
299
+ "Small Kana Extension": 269,
300
+ Nushu: 270,
301
+ Duployan: 271,
302
+ "Shorthand Format Controls": 272,
303
+ "Znamenny Musical Notation": 273,
304
+ "Byzantine Musical Symbols": 274,
305
+ "Musical Symbols": 275,
306
+ "Ancient Greek Musical Notation": 276,
307
+ "Kaktovik Numerals": 277,
308
+ "Mayan Numerals": 278,
309
+ "Tai Xuan Jing Symbols": 279,
310
+ "Counting Rod Numerals": 280,
311
+ "Mathematical Alphanumeric Symbols": 281,
312
+ "Sutton SignWriting": 282,
313
+ "Latin Extended-G": 283,
314
+ "Glagolitic Supplement": 284,
315
+ "Cyrillic Extended-D": 285,
316
+ "Nyiakeng Puachue Hmong": 286,
317
+ Toto: 287,
318
+ Wancho: 288,
319
+ "Nag Mundari": 289,
320
+ "Ethiopic Extended-B": 290,
321
+ "Mende Kikakui": 291,
322
+ Adlam: 292,
323
+ "Indic Siyaq Numbers": 293,
324
+ "Ottoman Siyaq Numbers": 294,
325
+ "Arabic Mathematical Alphabetic Symbols": 295,
326
+ "Mahjong Tiles": 296,
327
+ "Domino Tiles": 297,
328
+ "Playing Cards": 298,
329
+ "Enclosed Alphanumeric Supplement": 299,
330
+ "Enclosed Ideographic Supplement": 300,
331
+ "Miscellaneous Symbols and Pictographs": 301,
332
+ Emoticons: 302,
333
+ "Ornamental Dingbats": 303,
334
+ "Transport and Map Symbols": 304,
335
+ "Alchemical Symbols": 305,
336
+ "Geometric Shapes Extended": 306,
337
+ "Supplemental Arrows-C": 307,
338
+ "Supplemental Symbols and Pictographs": 308,
339
+ "Chess Symbols": 309,
340
+ "Symbols and Pictographs Extended-A": 310,
341
+ "Symbols for Legacy Computing": 311,
342
+ "CJK Unified Ideographs Extension B": 312,
343
+ "CJK Unified Ideographs Extension C": 313,
344
+ "CJK Unified Ideographs Extension D": 314,
345
+ "CJK Unified Ideographs Extension E": 315,
346
+ "CJK Unified Ideographs Extension F": 316,
347
+ "CJK Unified Ideographs Extension I": 317,
348
+ "CJK Compatibility Ideographs Supplement": 318,
349
+ "CJK Unified Ideographs Extension G": 319,
350
+ "CJK Unified Ideographs Extension H": 320,
351
+ Tags: 321,
352
+ "Variation Selectors Supplement": 322,
353
+ "Supplementary Private Use Area-A": 323,
354
+ "Supplementary Private Use Area-B": 324
355
+ // @endindex
356
+ };
357
+ class XUnicode {
358
+ static getBlockNames() {
359
+ return (0, import_vtils.keysStrict)(ublockMap).sort();
360
+ }
361
+ static getCharName(char) {
362
+ return (0, import_lib_unicode.ToCharacterNames)(char, false, true).trim().replace(/[\r\n]+/g, ";");
363
+ }
364
+ static getBlockChars(blockName) {
365
+ const ublock = ublockMap[blockName];
366
+ const start = (0, import_lib_unicode.GetBlockStart)(ublock);
367
+ const end = parseInt(import_lib_unicode.BlockEnd[ublock], 16);
368
+ const chars = [];
369
+ for (let char = start; char <= end; char++) {
370
+ if ((0, import_lib_unicode.GetCharacterName)(ublock, char, true)) {
371
+ chars.push(String.fromCodePoint(char));
372
+ }
373
+ }
374
+ return chars;
375
+ }
376
+ static isCharVisibleId = 0;
377
+ static isCharVisibleGetCharBuffer = async (char, page) => {
378
+ const id = `_${XUnicode.isCharVisibleId++}`;
379
+ await page.evaluate(
380
+ (char2, id2) => {
381
+ const el = document.createElement("span");
382
+ el.innerText = char2;
383
+ el.id = id2;
384
+ document.body.appendChild(el);
385
+ },
386
+ char,
387
+ id
388
+ );
389
+ const charEl = await page.$(`#${id}`);
390
+ const charBuffer = await charEl.screenshot();
391
+ await page.evaluate((id2) => {
392
+ document.querySelector(`#${id2}`)?.remove();
393
+ }, id);
394
+ return charBuffer;
395
+ };
396
+ static isCharVisibleBrowsers = [];
397
+ static isCharVisibleInit = (0, import_vtils.memoize)(
398
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
399
+ async (flag) => {
400
+ const { html } = import_text.XText;
401
+ const browser = await import_puppeteer.XPuppeteer.openBrowser();
402
+ XUnicode.isCharVisibleBrowsers.push(browser);
403
+ const page = await browser.openPage(html`
404
+ <html>
405
+ <head>
406
+ <style>
407
+ span {
408
+ display: inline-block;
409
+ width: 100px;
410
+ height: 100px;
411
+ font-size: 40px;
412
+ color: red;
413
+ }
414
+ </style>
415
+ </head>
416
+ <body></body>
417
+ </html>
418
+ `);
419
+ const invisibleCharBuffer = await XUnicode.isCharVisibleGetCharBuffer(
420
+ "\u{18BE8}",
421
+ page
422
+ );
423
+ return {
424
+ browser,
425
+ page,
426
+ invisibleCharBuffer
427
+ };
428
+ },
429
+ (flag) => flag
430
+ );
431
+ static async isCharVisibleDispose() {
432
+ await Promise.all(
433
+ XUnicode.isCharVisibleBrowsers.map((browser) => browser.close())
434
+ );
435
+ }
436
+ static async isCharVisible(char, flag = 0) {
437
+ const { page, invisibleCharBuffer } = await XUnicode.isCharVisibleInit(flag);
438
+ const charBuffer = await XUnicode.isCharVisibleGetCharBuffer(char, page);
439
+ return !charBuffer.equals(invisibleCharBuffer);
440
+ }
441
+ }
package/_cjs/upload.js ADDED
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var upload_exports = {};
30
+ __export(upload_exports, {
31
+ XUpload: () => XUpload
32
+ });
33
+ module.exports = __toCommonJS(upload_exports);
34
+ var import_x_request = require("@jayfong/x-request");
35
+ var import_file_type = require("file-type");
36
+ var fs = __toESM(require("node:fs"), 1);
37
+ var import_sharp = __toESM(require("sharp"), 1);
38
+ var import_vtils = require("vtils");
39
+ var import_env = require("./env.js");
40
+ class XUpload {
41
+ /**
42
+ * 上传文件
43
+ *
44
+ * @param file 文件本地路径、文件 URL、文件 Buffer
45
+ * @param options 选项
46
+ * @param options.provider 默认 auto
47
+ * @param options.source 默认 my-auto-tasks
48
+ */
49
+ static async upload(file, {
50
+ serverUrl,
51
+ serverToken,
52
+ provider = "auto",
53
+ source = "my-auto-tasks",
54
+ compress = false
55
+ } = {}) {
56
+ if (serverUrl == null) {
57
+ serverUrl = await import_env.XEnv.getEnvVar("X_UPLOAD_SERVER_URL");
58
+ }
59
+ if (serverToken == null) {
60
+ serverToken = await import_env.XEnv.getEnvVar("X_UPLOAD_SERVER_TOKEN");
61
+ }
62
+ if (typeof file === "string") {
63
+ if ((0, import_vtils.isUrl)(file)) {
64
+ const { data: data2 } = await import_x_request.xr.get({
65
+ url: file,
66
+ autoReferer: true
67
+ });
68
+ file = data2;
69
+ } else {
70
+ file = await fs.promises.readFile(file);
71
+ }
72
+ }
73
+ const { ext: fileExt } = await (0, import_file_type.fileTypeFromBuffer)(file);
74
+ const imageExts = ["jpg", "png", "gif"];
75
+ const isImage = imageExts.includes(fileExt);
76
+ provider = provider === "auto" ? isImage ? "image" : "file" : provider;
77
+ if (isImage && compress) {
78
+ const compressor = (0, import_sharp.default)(file);
79
+ file = fileExt === "png" ? await compressor.png({
80
+ quality: 80,
81
+ compressionLevel: 6
82
+ }).toBuffer() : fileExt === "jpg" ? await compressor.jpeg({
83
+ quality: 80
84
+ }).toBuffer() : file;
85
+ }
86
+ const { data } = await import_x_request.xr.postJson({
87
+ url: serverUrl,
88
+ data: import_x_request.xr.formData({
89
+ token: serverToken,
90
+ provider,
91
+ returnRawUrl: 1,
92
+ source,
93
+ file: import_x_request.xr.formFile(file, {
94
+ name: `xxx.${fileExt}`
95
+ })
96
+ })
97
+ });
98
+ return data;
99
+ }
100
+ }
package/_cjs/yaml.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var yaml_exports = {};
30
+ __export(yaml_exports, {
31
+ XYaml: () => XYaml
32
+ });
33
+ module.exports = __toCommonJS(yaml_exports);
34
+ var fs = __toESM(require("node:fs"), 1);
35
+ var import_yaml = __toESM(require("yaml"), 1);
36
+ class XYaml {
37
+ static parse(value) {
38
+ return import_yaml.default.parse(value);
39
+ }
40
+ static stringify(value) {
41
+ return import_yaml.default.stringify(value, {
42
+ blockQuote: "literal"
43
+ });
44
+ }
45
+ static async read(file) {
46
+ const value = await fs.promises.readFile(file, "utf8");
47
+ return XYaml.parse(value);
48
+ }
49
+ static async write(file, value) {
50
+ await fs.promises.writeFile(file, XYaml.stringify(value));
51
+ }
52
+ }
package/ai.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /// <reference types="lodash" />
2
+ declare abstract class AiProvider {
3
+ abstract prepare(): Promise<void>;
4
+ abstract ask(question: string): Promise<string>;
5
+ }
6
+ export declare class CozeAiProvider extends AiProvider {
7
+ private options;
8
+ private xp;
9
+ private page;
10
+ constructor(options: {
11
+ botUrl: string;
12
+ });
13
+ prepare(): Promise<void>;
14
+ ask(question: string): Promise<string>;
15
+ }
16
+ export type XAiOptions = {
17
+ provider: AiProvider;
18
+ };
19
+ export declare class XAi {
20
+ private options;
21
+ private provider;
22
+ constructor(options: XAiOptions);
23
+ prepare: (() => Promise<void>) & import("lodash").MemoizedFunction;
24
+ ask(question: string): Promise<string>;
25
+ }
26
+ export {};
package/ai.js ADDED
@@ -0,0 +1,60 @@
1
+ import { loopUntil, memoize, wait } from "vtils";
2
+ import { XPuppeteer } from "./puppeteer.js";
3
+ class AiProvider {
4
+ }
5
+ class CozeAiProvider extends AiProvider {
6
+ constructor(options) {
7
+ super();
8
+ this.options = options;
9
+ }
10
+ xp;
11
+ page;
12
+ async prepare() {
13
+ this.xp = new XPuppeteer();
14
+ await this.xp.connectSystemBrowser();
15
+ this.page = await this.xp.openPage(this.options.botUrl);
16
+ }
17
+ async ask(question) {
18
+ const page = this.page;
19
+ await page.evaluate(
20
+ () => document.querySelector("textarea:not([placeholder])").parentElement.parentElement.previousElementSibling.firstElementChild.click()
21
+ );
22
+ await wait(300);
23
+ await this.page.type("textarea:not([placeholder])", question);
24
+ await wait(500);
25
+ await this.page.keyboard.press("Enter");
26
+ await wait(1e3);
27
+ await loopUntil(
28
+ () => page.$$eval(
29
+ "button",
30
+ (els) => !els.find((el) => el.textContent.includes("Stop Responding"))?.parentElement.getBoundingClientRect().height
31
+ ),
32
+ {
33
+ retryDelay: 300
34
+ }
35
+ );
36
+ await wait(300);
37
+ const code = await page.$$eval(
38
+ 'div[class^="code-area"]',
39
+ (els) => els.pop().querySelector('[class^="content"]').textContent
40
+ );
41
+ return code;
42
+ }
43
+ }
44
+ class XAi {
45
+ constructor(options) {
46
+ this.options = options;
47
+ this.provider = options.provider;
48
+ }
49
+ provider;
50
+ prepare = memoize(() => this.provider.prepare());
51
+ async ask(question) {
52
+ await this.prepare();
53
+ const answer = await this.provider.ask(question);
54
+ return answer;
55
+ }
56
+ }
57
+ export {
58
+ CozeAiProvider,
59
+ XAi
60
+ };
package/cli.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export type XCliPromptType = 'confirm' | 'input';
2
+ export type XCliPromptResult = {
3
+ confirm: boolean;
4
+ input: string;
5
+ };
6
+ export type XCliPromptOptions<T extends XCliPromptType> = {
7
+ message: string;
8
+ type: T;
9
+ default?: XCliPromptResult[T];
10
+ };
11
+ export declare class XCli {
12
+ static prompt<T extends XCliPromptType>(options: XCliPromptOptions<T>): Promise<XCliPromptResult[T]>;
13
+ static table(data: any[][]): string;
14
+ }