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
@@ -1,236 +0,0 @@
1
- /**
2
- * Copyright 2024 Han Guoshuai <zohegs@gmail.com>
3
-
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * https://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import * as clickgo from '../clickgo';
17
-
18
- const token = (Math.random() * 100000000000000 * (100 + Math.round(Math.random() * (999 - 100)))).toString(32);
19
- /**
20
- * --- 获取 native 通讯 token,app 模式下无效 ---
21
- */
22
- export function getToken(): string {
23
- return token;
24
- }
25
-
26
- // ---------------------------
27
- // --- 供 native 调用的部分 ---
28
- // ---------------------------
29
-
30
- /** --- 用户添加的监听 --- */
31
- const methods: Record<string,
32
- Record<string, {
33
- 'once': boolean;
34
- 'handler': (...param: any[]) => any | Promise<any>;
35
- }>
36
- > = {
37
-
38
- };
39
-
40
- // --- 供 native 调用的 web 上的对象 ---
41
- (window as any).clickgoNativeWeb = {
42
- invoke: function(name: string, ...param: any[]) {
43
- for (const taskId in methods) {
44
- for (const n in methods[taskId]) {
45
- if (!n.startsWith(name + '-')) {
46
- continue;
47
- }
48
- methods[taskId][n].handler(...param);
49
- if (methods[taskId][n].once) {
50
- delete methods[taskId][n];
51
- if (!Object.keys(methods[taskId]).length) {
52
- delete methods[taskId];
53
- }
54
- }
55
- }
56
- }
57
- }
58
- };
59
-
60
- /**
61
- * --- 监听 native 传输过来的事件 ---
62
- * @param name 事件名
63
- * @param handler 回调函数
64
- * @param once 是否只监听一次
65
- * @param formId 限定某个窗体
66
- * @param taskId 绑定到任务,App 模式下无效
67
- */
68
- export function on(
69
- name: string,
70
- handler: (...param: any[]) => any | Promise<any>,
71
- once: boolean = false,
72
- formId?: number,
73
- taskId?: number
74
- ): void {
75
- if (!taskId) {
76
- return;
77
- }
78
- if (!methods[taskId]) {
79
- methods[taskId] = {};
80
- }
81
- methods[taskId][name + '-' + (formId ? formId.toString() : '0')] = {
82
- 'once': once,
83
- 'handler': handler
84
- };
85
- }
86
-
87
- /**
88
- * --- 监听 native 传输过来的事件(仅一次) ---
89
- */
90
- export function once(
91
- name: string,
92
- handler: (...param: any[]) => any | Promise<any>,
93
- formId?: number,
94
- taskId?: number
95
- ): void {
96
- on(name, handler, true, formId, taskId);
97
- }
98
-
99
- /**
100
- * --- 解绑监听的方法 ---
101
- * @param name 方法名
102
- * @param formId 要清除的窗体的 ID
103
- * @param taskId 所属的任务 ID,App 模式下无效
104
- */
105
- export function off(name: string, formId?: number, taskId?: number): void {
106
- if (!taskId) {
107
- return;
108
- }
109
- if (!methods[taskId]) {
110
- return;
111
- }
112
- const key = name + '-' + (formId ? formId.toString() : '0');
113
- if (!methods[taskId][key]) {
114
- return;
115
- }
116
- delete methods[taskId][key];
117
- }
118
-
119
- /**
120
- * --- 清除某个窗体或某个任务的所有事件监听 ---
121
- * @param formId 窗体 ID,留空为清除任务的所有事件
122
- * @param taskId 要清楚的任务 ID,App 模式下无效
123
- */
124
- export function clear(formId?: number, taskId?: number): void {
125
- if (!taskId) {
126
- return;
127
- }
128
- if (!methods[taskId]) {
129
- return;
130
- }
131
- if (!formId) {
132
- delete methods[taskId];
133
- return;
134
- }
135
- for (const key in methods[taskId]) {
136
- if (!key.endsWith('-' + formId.toString())) {
137
- continue;
138
- }
139
- delete methods[taskId][key];
140
- }
141
- }
142
-
143
- /**
144
- * --- 获取监听 native 事件的监听统计信息列表 ---
145
- * @param taskId 为 0 或 undefined 则返回所有
146
- */
147
- export function getListenerList(taskId?: number): Record<string, Record<string, Record<string, number>>> {
148
- const rtn: Record<string,
149
- Record<string, Record<string, number>>
150
- > = {};
151
- for (const tid in methods) {
152
- if (taskId) {
153
- if (tid !== taskId.toString()) {
154
- continue;
155
- }
156
- }
157
- rtn[tid] = {};
158
- for (const key in methods[tid]) {
159
- const lio = key.lastIndexOf('-');
160
- const name = key.slice(0, lio);
161
- const id = key.slice(lio + 1);
162
- if (!rtn[tid][id]) {
163
- rtn[tid][id] = {};
164
- }
165
- if (rtn[tid][id][name]) {
166
- ++rtn[tid][id][name];
167
- }
168
- else {
169
- rtn[tid][id][name] = 1;
170
- }
171
- }
172
- }
173
- return rtn;
174
- }
175
-
176
- // ---------------------------
177
- // --- 向 native 发送的部分 ---
178
- // ---------------------------
179
-
180
- /**
181
- * --- 向 native 发送指令 ---
182
- * @param name 指令名
183
- * @param param 参数
184
- */
185
- export async function invoke(name: string, ...param: any[]): Promise<any> {
186
- if (!clickgo.isNative()) {
187
- return;
188
- }
189
- return (window as any).clickgoNative.invoke(name, ...param) as Promise<any>;
190
- }
191
-
192
- invoke('cg-init', token) as any;
193
-
194
- // --- 常见向 native 发送的操作 ---
195
-
196
- export async function quit(): Promise<void> {
197
- await invoke('cg-quit', token);
198
- }
199
-
200
- export async function size(width: number, height: number): Promise<void> {
201
- await invoke('cg-set-size', token, width, height);
202
- }
203
-
204
- export async function max(): Promise<void> {
205
- await invoke('cg-set-state', token, 'max');
206
- }
207
-
208
- export async function min(): Promise<void> {
209
- await invoke('cg-set-state', token, 'min');
210
- }
211
-
212
- export async function restore(): Promise<void> {
213
- await invoke('cg-set-state', token, 'restore');
214
- }
215
-
216
- export async function activate(): Promise<void> {
217
- await invoke('cg-activate', token);
218
- }
219
-
220
- export async function close(): Promise<void> {
221
- await invoke('cg-close', token);
222
- }
223
-
224
- export async function maximizable(val: boolean): Promise<void> {
225
- await invoke('cg-maximizable', token, val);
226
- }
227
-
228
- // --- 以下无需 token ---
229
-
230
- export async function ping(val: string): Promise<string> {
231
- return invoke('cg-ping', val);
232
- }
233
-
234
- export async function isMax(): Promise<boolean> {
235
- return invoke('cg-is-max');
236
- }
@@ -1,229 +0,0 @@
1
- /**
2
- * Copyright 2024 Han Guoshuai <zohegs@gmail.com>
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * https://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import * as task from './task';
17
- import * as form from './form';
18
- import * as core from './core';
19
- import * as tool from './tool';
20
-
21
- /** --- storage lib 用到的语言包 --- */
22
- const localeData: Record<string, {
23
- // eslint-disable-next-line @typescript-eslint/naming-convention
24
- 'sure-clear': string;
25
- }> = {
26
- 'en': {
27
- 'sure-clear': 'Are you sure you want to clear all temporary storage for the app "?"?'
28
- },
29
- 'sc': {
30
- 'sure-clear': '确定清除应用“?”的所有临时存储吗?'
31
- },
32
- 'tc': {
33
- 'sure-clear': '確定清除應用程式「?」的所有臨時儲存嗎?'
34
- },
35
- 'ja': {
36
- 'sure-clear': 'アプリ「?」の一時的な保存データをすべて削除しますか?'
37
- },
38
- 'ko': {
39
- 'sure-clear': '"?" 앱의 모든 임시 저장소를 지우시겠습니까?'
40
- },
41
- 'th': {
42
- 'sure-clear': 'คุณแน่ใจหรือไม่ที่ต้องการล้างพื้นที่จัดเก็บชั่วคราวของแอป "?" ทั้งหมดหรือไม่?'
43
- },
44
- 'es': {
45
- 'sure-clear': '¿Estás seguro de que quieres borrar todo el almacenamiento temporal de la aplicación "?"?'
46
- },
47
- 'de': {
48
- 'sure-clear': 'Möchten Sie wirklich alle temporären Speicher für die App "?" löschen?'
49
- },
50
- 'fr': {
51
- 'sure-clear': 'Êtes-vous sûr de vouloir effacer tous les stockages temporaires de l\'application "?" ?'
52
- },
53
- 'pt': {
54
- 'sure-clear': 'Tem a certeza de que pretende limpar todo o armazenamento temporário da aplicação "?"?'
55
- },
56
- 'ru': {
57
- 'sure-clear': 'Вы уверены, что хотите очистить все временные хранилища для приложения "?"?'
58
- },
59
- 'vi': {
60
- 'sure-clear': 'Bạn có chắc chắn muốn xóa tất cả lưu trữ tạm thời cho ứng dụng "?" không?'
61
- }
62
- };
63
-
64
- const textEncoder = new TextEncoder();
65
-
66
- /**
67
- * --- 获取小型存储数据 ---
68
- * @param key 存储键
69
- * @param taskId 要读取的 task id,APP 模式下无效
70
- */
71
- export function get(key: string, taskId?: number): any {
72
- if (!taskId) {
73
- return null;
74
- }
75
- const t = task.list[taskId];
76
- if (!t) {
77
- return null;
78
- }
79
- const v = localStorage.getItem('clickgo-item-' + t.path + '-' + key);
80
- if (v === null) {
81
- return null;
82
- }
83
- try {
84
- return JSON.parse(v);
85
- }
86
- catch {
87
- return null;
88
- }
89
- }
90
-
91
- /**
92
- * --- 存储小型存储数据,单应用最大存储 1M ---
93
- * @param key 存储键
94
- * @param val 存储值
95
- * @param taskId 要读取的 task id,APP 模式下无效
96
- */
97
- export function set(key: string, val: string | number | any[] | Record<string, any>, taskId?: number): boolean {
98
- if (!taskId) {
99
- return false;
100
- }
101
- const t = task.list[taskId];
102
- if (!t) {
103
- return false;
104
- }
105
- if (val === undefined) {
106
- return false;
107
- }
108
- const v = JSON.stringify(val);
109
- const vsize = textEncoder.encode(v).length;
110
- /** --- 当前 app 的 key 所占用的 size 列表 --- */
111
- const sizes = localStorage.getItem('clickgo-size-' + t.path);
112
- if (sizes === null) {
113
- if (vsize > 1048576) {
114
- return false;
115
- }
116
- localStorage.setItem('clickgo-size-' + t.path, JSON.stringify({
117
- [key]: vsize
118
- }));
119
- }
120
- else {
121
- const sizeso: Record<string, number> = JSON.parse(sizes);
122
- sizeso[key] = vsize;
123
- const allsize = Object.values(sizeso).reduce((a, c) => { return a + c; }, 0);
124
- if (allsize > 1048576) {
125
- return false;
126
- }
127
- localStorage.setItem('clickgo-size-' + t.path, JSON.stringify(sizeso));
128
- }
129
- localStorage.setItem('clickgo-item-' + t.path + '-' + key, v);
130
- return true;
131
- }
132
-
133
- /**
134
- * --- 移除某个小型存储数据 ---
135
- * @param key 要移除的键
136
- * @param taskId 要移除的 task id,APP 模式下无效
137
- */
138
- export function remove(key: string, taskId?: number): boolean {
139
- if (!taskId) {
140
- return false;
141
- }
142
- const t = task.list[taskId];
143
- if (!t) {
144
- return false;
145
- }
146
- const sizes = localStorage.getItem('clickgo-size-' + t.path);
147
- if (sizes === null) {
148
- return true;
149
- }
150
- const sizeso: Record<string, number> = JSON.parse(sizes);
151
- if (sizeso[key] === undefined) {
152
- return true;
153
- }
154
- delete sizeso[key];
155
- if (Object.keys(sizeso).length) {
156
- localStorage.setItem('clickgo-size-' + t.path, JSON.stringify(sizeso));
157
- }
158
- else {
159
- localStorage.removeItem('clickgo-size-' + t.path);
160
- }
161
- localStorage.removeItem('clickgo-item-' + t.path + '-' + key);
162
- return true;
163
- }
164
-
165
- /**
166
- * --- 获取当前任务的所有存储列表,key: size ---
167
- * @param taskId 要获取的 task id,APP 模式下无效
168
- */
169
- export function list(taskId?: number): Record<string, number> {
170
- if (!taskId) {
171
- return {};
172
- }
173
- const t = task.list[taskId];
174
- if (!t) {
175
- return {};
176
- }
177
- const sizes = localStorage.getItem('clickgo-size-' + t.path);
178
- if (sizes === null) {
179
- return {};
180
- }
181
- return JSON.parse(sizes);
182
- }
183
-
184
- /**
185
- * --- 获取所有存储在本地的应用列表,以 path: size 返回 ---
186
- */
187
- export function all(): Record<string, number> {
188
- const rtn: Record<string, number> = {};
189
- for (let i = 0; i < localStorage.length; i++) {
190
- const key = localStorage.key(i);
191
- if (!key?.startsWith('clickgo-size-')) {
192
- continue;
193
- }
194
- const sizes = localStorage.getItem(key);
195
- if (!sizes) {
196
- continue;
197
- }
198
- const sizeso: Record<string, number> = JSON.parse(sizes);
199
- const allsize = Object.values(sizeso).reduce((a, c) => { return a + c; }, 0);
200
- rtn[key.slice(13)] = allsize;
201
- }
202
- return rtn;
203
- }
204
-
205
- /**
206
- * --- 移除某个应用的所有临时存储 ---
207
- * @param path 要移除的应用的 path(末尾 .cga 或带 / 的路径)
208
- */
209
- export async function clear(path: string): Promise<number> {
210
- if (!path) {
211
- return 0;
212
- }
213
- const loc = localeData[core.config.locale]?.['sure-clear'] ?? localeData['en']['sure-clear'];
214
- if (!await form.superConfirm(loc.replace('?', tool.escapeHTML(path)))) {
215
- return 0;
216
- }
217
- let count = 0;
218
- localStorage.removeItem('clickgo-size-' + path);
219
- const pre = 'clickgo-item-' + path + '-';
220
- for (let i = 0; i < localStorage.length; i++) {
221
- const key = localStorage.key(i);
222
- if (!key?.startsWith(pre)) {
223
- continue;
224
- }
225
- localStorage.removeItem(key);
226
- ++count;
227
- }
228
- return count;
229
- }