clickgo 3.16.16 → 3.16.18

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 (63) hide show
  1. package/README.md +1 -1
  2. package/dist/app/demo/form/method/native/native.js +26 -0
  3. package/dist/app/demo/form/method/native/native.xml +2 -0
  4. package/dist/clickgo.d.ts +17 -0
  5. package/dist/clickgo.js +1 -1
  6. package/dist/control/arteditor.cgc +0 -0
  7. package/dist/control/box.cgc +0 -0
  8. package/dist/control/captcha.cgc +0 -0
  9. package/dist/control/common.cgc +0 -0
  10. package/dist/control/desc.cgc +0 -0
  11. package/dist/control/drawer.cgc +0 -0
  12. package/dist/control/echarts.cgc +0 -0
  13. package/dist/control/form.cgc +0 -0
  14. package/dist/control/iconview.cgc +0 -0
  15. package/dist/control/jodit.cgc +0 -0
  16. package/dist/control/map.cgc +0 -0
  17. package/dist/control/monaco.cgc +0 -0
  18. package/dist/control/mpegts.cgc +0 -0
  19. package/dist/control/nav.cgc +0 -0
  20. package/dist/control/page.cgc +0 -0
  21. package/dist/control/pdf.cgc +0 -0
  22. package/dist/control/property.cgc +0 -0
  23. package/dist/control/qrcode.cgc +0 -0
  24. package/dist/control/table.cgc +0 -0
  25. package/dist/control/task.cgc +0 -0
  26. package/dist/control/tplink.cgc +0 -0
  27. package/dist/control/tuieditor.cgc +0 -0
  28. package/dist/control/tuiviewer.cgc +0 -0
  29. package/dist/control/xterm.cgc +0 -0
  30. package/dist/index.d.ts +51 -0
  31. package/dist/lib/control.d.ts +53 -0
  32. package/dist/lib/core.d.ts +47 -0
  33. package/dist/lib/dom.d.ts +74 -0
  34. package/dist/lib/dom.js +7 -7
  35. package/dist/lib/form.d.ts +222 -0
  36. package/dist/lib/fs.d.ts +35 -0
  37. package/dist/lib/fs.js +2 -2
  38. package/dist/lib/native.d.ts +36 -0
  39. package/dist/lib/native.js +8 -0
  40. package/dist/lib/storage.d.ts +6 -0
  41. package/dist/lib/task.d.ts +32 -0
  42. package/dist/lib/task.js +7 -1
  43. package/dist/lib/theme.d.ts +8 -0
  44. package/dist/lib/tool.d.ts +120 -0
  45. package/dist/lib/zip.d.ts +40 -0
  46. package/dist/theme/blue.cgt +0 -0
  47. package/dist/theme/byterun.cgt +0 -0
  48. package/dist/theme/light.cgt +0 -0
  49. package/package.json +7 -5
  50. package/dist/clickgo.ts +0 -68
  51. package/dist/index.ts +0 -282
  52. package/dist/lib/control.ts +0 -751
  53. package/dist/lib/core.ts +0 -1145
  54. package/dist/lib/dom.ts +0 -2728
  55. package/dist/lib/form.ts +0 -3829
  56. package/dist/lib/fs.ts +0 -1324
  57. package/dist/lib/native.ts +0 -236
  58. package/dist/lib/storage.ts +0 -229
  59. package/dist/lib/task.ts +0 -2160
  60. package/dist/lib/theme.ts +0 -199
  61. package/dist/lib/tool.ts +0 -1278
  62. package/dist/lib/zip.ts +0 -444
  63. package/eslint.config.js +0 -22
package/dist/lib/zip.ts DELETED
@@ -1,444 +0,0 @@
1
- import jszip from 'jszip';
2
- import * as types from '../../types';
3
- import * as tool from './tool';
4
-
5
- export class Zip {
6
-
7
- /** --- zip 对象 --- */
8
- private readonly _zip!: jszip;
9
-
10
- /** --- 当前路径,以 / 开头以 / 结尾 --- */
11
- private _path: string = '/';
12
-
13
- public constructor(zip: jszip) {
14
- this._zip = zip;
15
- this._refreshList();
16
- }
17
-
18
- public async getContent(path: string): Promise<string | null>;
19
- public async getContent<T extends types.TZipOutputType>(
20
- path: string,
21
- type: T): Promise<types.IZipOutputByType[T] | null>;
22
- /**
23
- * --- 读取完整文件 ---
24
- * @param path 文件路径
25
- * @param type 返回类型
26
- */
27
- public async getContent<T extends types.TZipOutputType>(path: string, type: T = 'string' as T): Promise<types.IZipOutputByType[T] | string | null> {
28
- path = tool.urlResolve(this._path, path);
29
- const f = this._zip.file(path.slice(1));
30
- if (!f) {
31
- return null;
32
- }
33
- if (type === 'string') {
34
- return f.async('string');
35
- }
36
- else {
37
- return f.async(type);
38
- }
39
- }
40
-
41
- /**
42
- * --- 写入文件内容 ---
43
- * @param path 文件路径
44
- * @param data 要写入的内容
45
- * @param options 选项
46
- */
47
- public putContent<T extends types.TZipInputType>(path: string, data: types.IZipInputByType[T], options: { 'base64'?: boolean; 'binary'?: boolean; 'date'?: Date; } = {}): void {
48
- path = tool.urlResolve(this._path, path);
49
- this._zip.file(path.slice(1), data as jszip.InputType, {
50
- 'base64': options.base64,
51
- 'binary': options.binary,
52
- 'date': options.date
53
- });
54
- this._refreshList();
55
- }
56
-
57
- /**
58
- * --- 删除一个文件/文件夹(深度删除) ---
59
- * @param path 要删除的文件路径
60
- */
61
- public unlink(path: string): void {
62
- path = tool.urlResolve(this._path, path);
63
- this._zip.remove(path.slice(1));
64
- this._refreshList();
65
- }
66
-
67
- /**
68
- * --- 获取对象是否存在,存在则返回 stats 对象,否则返回 null ---
69
- * @param path 对象路径
70
- * @param options 选项
71
- */
72
- public stats(path: string): types.IZipStats | null {
73
- path = tool.urlResolve(this._path, path);
74
- let dirpath = path.endsWith('/') ? path : path + '/';
75
- if (!this._list[dirpath]) {
76
- // --- 可能是文件 ---
77
- if (path.endsWith('/')) {
78
- // --- 不可能是文件 ---
79
- return null;
80
- }
81
- const lio = path.lastIndexOf('/') + 1;
82
- const dpath = path.slice(0, lio);
83
- const fname = path.slice(lio);
84
- if (!this._list[dpath]) {
85
- // --- 上层目录不存在 ---
86
- return null;
87
- }
88
- const file = this._list[dpath][fname];
89
- if (!file) {
90
- return null;
91
- }
92
- return {
93
- 'compressedSize': file.compressedSize,
94
- 'uncompressedSize': file.uncompressedSize,
95
- 'date': file.date,
96
- 'isFile': true,
97
- 'isDirectory': false
98
- };
99
- }
100
- else {
101
- // --- 文件夹 ---
102
- if (dirpath === '/') {
103
- return {
104
- 'compressedSize': 0,
105
- 'uncompressedSize': 0,
106
- 'date': new Date(),
107
- 'isFile': false,
108
- 'isDirectory': true
109
- };
110
- }
111
- dirpath = dirpath.slice(0, -1);
112
- const lio = dirpath.lastIndexOf('/') + 1;
113
- const dpath = dirpath.slice(0, lio);
114
- const fname = dirpath.slice(lio);
115
- const pfolder = this._list[dpath];
116
- const folder = pfolder[fname];
117
- return {
118
- 'compressedSize': 0,
119
- 'uncompressedSize': 0,
120
- 'date': folder.date,
121
- 'isFile': false,
122
- 'isDirectory': true
123
- };
124
- }
125
- }
126
-
127
- /**
128
- * --- 判断是否是目录或目录是否存在,是的话返回 stats ---
129
- * @param path 判断路径
130
- */
131
- public isDir(path: string): types.IZipStats | false {
132
- const pstats = this.stats(path);
133
- if (!pstats?.isDirectory) {
134
- return false;
135
- }
136
- return pstats;
137
- }
138
-
139
- /**
140
- * --- 判断是否是文件或文件是否存在,是的话返回 stats ---
141
- * @param path 判断路径
142
- */
143
- public isFile(path: string): types.IZipStats | false {
144
- const pstats = this.stats(path);
145
- if (!pstats?.isFile) {
146
- return false;
147
- }
148
- return pstats;
149
- }
150
-
151
- /** --- 读取目录,hasChildren: false, hasDir: true, pathAsKey: false --- */
152
- public readDir(path?: string, opt?: { 'hasChildren'?: boolean; 'hasDir'?: boolean; 'pathAsKey'?: false; }): types.IZipItem[];
153
- public readDir(path?: string, opt?: { 'hasChildren'?: boolean; 'hasDir'?: boolean; 'pathAsKey': true; }): Record<string, types.IZipItem>;
154
- /**
155
- * --- 获取文件夹下文件列表 ---
156
- * @param path 文件夹路径
157
- * @param opt 选项
158
- */
159
- public readDir(path?: string, opt: { 'hasChildren'?: boolean; 'hasDir'?: boolean; 'pathAsKey'?: boolean; } = {}): Record<string, types.IZipItem> | types.IZipItem[] {
160
- if (opt.hasChildren === undefined) {
161
- opt.hasChildren = false;
162
- }
163
- if (opt.hasDir === undefined) {
164
- opt.hasDir = true;
165
- }
166
- if (opt.pathAsKey === undefined) {
167
- opt.pathAsKey = false;
168
- }
169
-
170
- if (!path) {
171
- path = this._path;
172
- }
173
- else {
174
- path = tool.urlResolve(this._path, path);
175
- }
176
- if (!path.endsWith('/')) {
177
- path += '/';
178
- }
179
- const folder = this._zip.folder(path.slice(1));
180
- if (!folder) {
181
- return opt.pathAsKey ? {} : [];
182
- }
183
- if (!this._list[path]) {
184
- return opt.pathAsKey ? {} : [];
185
- }
186
- if (!opt.hasChildren) {
187
- if (opt.pathAsKey) {
188
- return this._list[path];
189
- }
190
- const list: types.IZipItem[] = [];
191
- for (const k in this._list[path]) {
192
- list.push(this._list[path][k]);
193
- }
194
- return list;
195
- }
196
- // --- 定义 list ---
197
- if (opt.pathAsKey) {
198
- const list: Record<string, types.IZipItem> = {};
199
- // --- 遍历子项 ---
200
- for (const k in this._list[path]) {
201
- const item = this._list[path][k];
202
- if (item.isFile || opt.hasDir) {
203
- list[item.path + item.name] = item;
204
- }
205
- if (item.isDirectory) {
206
- Object.assign(list, this._readDir(item, {
207
- 'hasDir': opt.hasDir,
208
- 'pathAsKey': opt.pathAsKey
209
- }));
210
- }
211
- }
212
- return list;
213
- }
214
- else {
215
- let list: types.IZipItem[] = [];
216
- // --- 遍历子项 ---
217
- for (const k in this._list[path]) {
218
- const item = this._list[path][k];
219
- if (item.isFile || opt.hasDir) {
220
- list.push(item);
221
- }
222
- if (item.isDirectory) {
223
- list = list.concat(this._readDir(item, {
224
- 'hasDir': opt.hasDir,
225
- 'pathAsKey': opt.pathAsKey
226
- }));
227
- }
228
- }
229
- return list;
230
- }
231
- }
232
-
233
- private _readDir(item: types.IZipItem, opt: { 'hasDir'?: boolean; 'pathAsKey'?: false; }): types.IZipItem[];
234
- private _readDir(item: types.IZipItem, opt: { 'hasDir'?: boolean; 'pathAsKey': true; }): Record<string, types.IZipItem>;
235
- /**
236
- * --- 根据 item 文件夹读取子层及所有子层项 ---
237
- * @param item 文件夹
238
- */
239
- private _readDir(item: types.IZipItem, opt: { 'hasDir'?: boolean; 'pathAsKey'?: boolean; }): Record<string, types.IZipItem> | types.IZipItem[] {
240
- if (opt.pathAsKey) {
241
- const list: Record<string, types.IZipItem> = {};
242
- if (!this._list[item.path + item.name + '/']) {
243
- return {};
244
- }
245
- for (const k in this._list[item.path + item.name + '/']) {
246
- const it = this._list[item.path + item.name + '/'][k];
247
- if (it.isFile || opt.hasDir) {
248
- list[it.path + it.name] = it;
249
- }
250
- if (it.isDirectory) {
251
- Object.assign(list, this._readDir(it, {
252
- 'hasDir': opt.hasDir,
253
- 'pathAsKey': opt.pathAsKey
254
- }));
255
- }
256
- }
257
- return list;
258
- }
259
- else {
260
- let list: types.IZipItem[] = [];
261
- if (!this._list[item.path + item.name + '/']) {
262
- return [];
263
- }
264
- for (const k in this._list[item.path + item.name + '/']) {
265
- const it = this._list[item.path + item.name + '/'][k];
266
- if (it.isFile || opt.hasDir) {
267
- list.push(it);
268
- }
269
- if (it.isDirectory) {
270
- list = list.concat(this._readDir(it, {
271
- 'hasDir': opt.hasDir,
272
- 'pathAsKey': opt.pathAsKey
273
- }));
274
- }
275
- }
276
- return list;
277
- }
278
- }
279
-
280
- /** --- 目录列表缓存 --- */
281
- private _list: Record<string, Record<string, types.IZipItem>> = {};
282
-
283
- /**
284
- * --- 重建目录列表缓存 ---
285
- */
286
- private _refreshList(): void {
287
- const list: Record<string, Record<string, types.IZipItem>> = {};
288
- // eslint-disable-next-line @litert/rules/disable-for-each-method
289
- this._zip.forEach(function(relativePath: string, item: jszip.JSZipObject) {
290
- if (relativePath.startsWith('/')) {
291
- relativePath = relativePath.slice(1);
292
- }
293
- let parentPath = '/';
294
- let name = '';
295
- let s: number;
296
- if (item.dir) {
297
- s = relativePath.slice(0, -1).lastIndexOf('/');
298
- }
299
- else {
300
- s = relativePath.lastIndexOf('/');
301
- }
302
- if (s !== -1) {
303
- parentPath = '/' + relativePath.slice(0, s + 1);
304
- name = relativePath.slice(s + 1);
305
- }
306
- else {
307
- name = relativePath;
308
- }
309
- if (item.dir) {
310
- name = name.slice(0, -1);
311
- }
312
- if (!list[parentPath]) {
313
- list[parentPath] = {};
314
- }
315
- list[parentPath][name] = {
316
- 'name': name,
317
- 'compressedSize': (item as any)._data.compressedSize ?? 0,
318
- 'uncompressedSize': (item as any)._data.uncompressedSize ?? 0,
319
- 'date': item.date,
320
- 'isFile': !item.dir,
321
- 'isDirectory': item.dir,
322
- 'path': parentPath
323
- };
324
- });
325
- this._list = list;
326
- }
327
-
328
- /**
329
- * --- 获取当前目录,末尾不带 / ---
330
- * @return string
331
- */
332
- public pwd(): string {
333
- return this._path.slice(0, -1);
334
- }
335
-
336
- /**
337
- * --- 进入一个目录(不存在也能进入,需要自行判断) ---
338
- * --- 返回进入后的路径值 ---
339
- * @param dir 相对路径或绝对路径
340
- */
341
- public cd(dir: string): string {
342
- this._path = tool.urlResolve(this._path, dir);
343
- if (!this._path.endsWith('/')) {
344
- this._path += '/';
345
- }
346
- return this._path;
347
- }
348
-
349
- /**
350
- * --- 打包 zip ---
351
- * @param options 选项
352
- */
353
- public generate<T extends types.TZipOutputType>(options: { 'type'?: T; 'level'?: number; 'onUpdate'?: (percent: number, currentFile: string | null) => void; } = {}): Promise<types.IZipOutputByType[T]> {
354
- const opt: any = {};
355
- if (options.type === undefined) {
356
- opt.type = 'blob' as T;
357
- }
358
- else {
359
- opt.type = options.type;
360
- }
361
- if (options.level === undefined) {
362
- options.level = 9;
363
- }
364
- else if (options.level > 9) {
365
- options.level = 9;
366
- }
367
- if (options.level > 0) {
368
- opt.compression = 'DEFLATE';
369
- }
370
- return this._zip.generateAsync(opt, function(meta: types.IZipMetadata): void {
371
- options.onUpdate?.(meta.percent, meta.currentFile);
372
- });
373
- }
374
-
375
- /**
376
- * --- 获取 path 和 string/Blob 对应的文件列表 ---
377
- */
378
- public getList(): Promise<Record<string, Blob | string>> {
379
- return new Promise((resolve) => {
380
- const files: Record<string, Blob | string> = {};
381
- const list = this.readDir('/', {
382
- 'hasChildren': true,
383
- 'hasDir': false
384
- });
385
- let loaded = 0;
386
- for (const file of list) {
387
- const mime = tool.getMimeByPath(file.name);
388
- if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
389
- this.getContent(file.path + file.name, 'string').then(function(fb) {
390
- if (fb) {
391
- files[file.path + file.name] = fb;
392
- }
393
- ++loaded;
394
- if (loaded === list.length) {
395
- resolve(files);
396
- }
397
- }).catch(function() {
398
- ++loaded;
399
- if (loaded === list.length) {
400
- resolve(files);
401
- }
402
- });
403
- }
404
- else {
405
- this.getContent(file.path + file.name, 'arraybuffer').then(function(fb) {
406
- if (fb) {
407
- files[file.path + file.name] = new Blob([fb], {
408
- 'type': mime.mime
409
- });
410
- }
411
- ++loaded;
412
- if (loaded === list.length) {
413
- resolve(files);
414
- }
415
- }).catch(function() {
416
- ++loaded;
417
- if (loaded === list.length) {
418
- resolve(files);
419
- }
420
- });
421
- }
422
- }
423
- return files;
424
- });
425
- }
426
-
427
- }
428
-
429
- /**
430
- * --- 获取 zip 对象 ---
431
- * @param data 对象数据
432
- */
433
- export async function get(data?: types.TZipInputFileFormat): Promise<Zip | null> {
434
- const z = jszip();
435
- try {
436
- if (data) {
437
- await z.loadAsync(data);
438
- }
439
- return new Zip(z);
440
- }
441
- catch {
442
- return null;
443
- }
444
- }
package/eslint.config.js DELETED
@@ -1,22 +0,0 @@
1
- // eslint.config.js
2
- const rules = require('@litert/eslint-plugin-recommended-rules');
3
-
4
- module.exports = [
5
- ...rules.typescript,
6
- {
7
- files: [
8
- '**/*.ts', // don't add `./` before the path
9
- ],
10
- languageOptions: {
11
- parserOptions: {
12
- project: 'tsconfig.json',
13
- tsconfigRootDir: __dirname,
14
- },
15
- },
16
- rules: {
17
- '@typescript-eslint/no-explicit-any': 'off',
18
- '@typescript-eslint/explicit-module-boundary-types': 'off',
19
- 'max-lines': ['warn', 5000]
20
- }
21
- }
22
- ];