clickgo 3.0.0-dev
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/LICENSE +201 -0
- package/README.md +75 -0
- package/dist/app/demo/config.json +106 -0
- package/dist/app/demo/form/control/block/block.css +1 -0
- package/dist/app/demo/form/control/block/block.scss +17 -0
- package/dist/app/demo/form/control/block/block.xml +7 -0
- package/dist/app/demo/form/control/button/button.css +1 -0
- package/dist/app/demo/form/control/button/button.js +27 -0
- package/dist/app/demo/form/control/button/button.scss +18 -0
- package/dist/app/demo/form/control/button/button.xml +126 -0
- package/dist/app/demo/form/control/check/check.js +12 -0
- package/dist/app/demo/form/control/check/check.xml +13 -0
- package/dist/app/demo/form/control/dialog/dialog.js +8 -0
- package/dist/app/demo/form/control/dialog/dialog.xml +26 -0
- package/dist/app/demo/form/control/file/file.js +23 -0
- package/dist/app/demo/form/control/file/file.xml +25 -0
- package/dist/app/demo/form/control/form/form.css +1 -0
- package/dist/app/demo/form/control/form/form.js +38 -0
- package/dist/app/demo/form/control/form/form.scss +9 -0
- package/dist/app/demo/form/control/form/form.xml +28 -0
- package/dist/app/demo/form/control/greatview/greatview.css +1 -0
- package/dist/app/demo/form/control/greatview/greatview.js +92 -0
- package/dist/app/demo/form/control/greatview/greatview.scss +22 -0
- package/dist/app/demo/form/control/greatview/greatview.xml +89 -0
- package/dist/app/demo/form/control/img/img.xml +16 -0
- package/dist/app/demo/form/control/label/label.xml +11 -0
- package/dist/app/demo/form/control/list/list.css +1 -0
- package/dist/app/demo/form/control/list/list.js +194 -0
- package/dist/app/demo/form/control/list/list.scss +7 -0
- package/dist/app/demo/form/control/list/list.xml +91 -0
- package/dist/app/demo/form/control/loading/loading.xml +8 -0
- package/dist/app/demo/form/control/marquee/marquee.js +30 -0
- package/dist/app/demo/form/control/marquee/marquee.xml +36 -0
- package/dist/app/demo/form/control/menu/menu.js +8 -0
- package/dist/app/demo/form/control/menu/menu.xml +122 -0
- package/dist/app/demo/form/control/monaco/monaco.js +113 -0
- package/dist/app/demo/form/control/monaco/monaco.xml +27 -0
- package/dist/app/demo/form/control/overflow/overflow.css +1 -0
- package/dist/app/demo/form/control/overflow/overflow.js +70 -0
- package/dist/app/demo/form/control/overflow/overflow.scss +18 -0
- package/dist/app/demo/form/control/overflow/overflow.xml +98 -0
- package/dist/app/demo/form/control/property/property.js +129 -0
- package/dist/app/demo/form/control/property/property.xml +6 -0
- package/dist/app/demo/form/control/radio/radio.js +7 -0
- package/dist/app/demo/form/control/radio/radio.xml +12 -0
- package/dist/app/demo/form/control/scroll/scroll.js +14 -0
- package/dist/app/demo/form/control/scroll/scroll.xml +35 -0
- package/dist/app/demo/form/control/select/select.js +91 -0
- package/dist/app/demo/form/control/select/select.xml +74 -0
- package/dist/app/demo/form/control/tab/tab.js +75 -0
- package/dist/app/demo/form/control/tab/tab.xml +22 -0
- package/dist/app/demo/form/control/text/text.js +53 -0
- package/dist/app/demo/form/control/text/text.xml +37 -0
- package/dist/app/demo/form/control/view/view.css +1 -0
- package/dist/app/demo/form/control/view/view.js +73 -0
- package/dist/app/demo/form/control/view/view.scss +18 -0
- package/dist/app/demo/form/control/view/view.xml +94 -0
- package/dist/app/demo/form/event/form/form.css +1 -0
- package/dist/app/demo/form/event/form/form.js +129 -0
- package/dist/app/demo/form/event/form/form.scss +24 -0
- package/dist/app/demo/form/event/form/form.xml +16 -0
- package/dist/app/demo/form/event/screen/screen.js +51 -0
- package/dist/app/demo/form/event/screen/screen.xml +9 -0
- package/dist/app/demo/form/event/task/task.js +78 -0
- package/dist/app/demo/form/event/task/task.xml +20 -0
- package/dist/app/demo/form/main.css +1 -0
- package/dist/app/demo/form/main.js +25 -0
- package/dist/app/demo/form/main.scss +9 -0
- package/dist/app/demo/form/main.xml +49 -0
- package/dist/app/demo/form/method/core/core.js +25 -0
- package/dist/app/demo/form/method/core/core.xml +7 -0
- package/dist/app/demo/form/method/dom/dom.css +1 -0
- package/dist/app/demo/form/method/dom/dom.js +163 -0
- package/dist/app/demo/form/method/dom/dom.scss +10 -0
- package/dist/app/demo/form/method/dom/dom.xml +55 -0
- package/dist/app/demo/form/method/form/form.css +1 -0
- package/dist/app/demo/form/method/form/form.js +217 -0
- package/dist/app/demo/form/method/form/form.scss +3 -0
- package/dist/app/demo/form/method/form/form.xml +56 -0
- package/dist/app/demo/form/method/form/test.xml +5 -0
- package/dist/app/demo/form/method/fs/fs.js +88 -0
- package/dist/app/demo/form/method/fs/fs.xml +8 -0
- package/dist/app/demo/form/method/fs/text.js +15 -0
- package/dist/app/demo/form/method/fs/text.xml +3 -0
- package/dist/app/demo/form/method/task/locale1.json +3 -0
- package/dist/app/demo/form/method/task/locale2.json +3 -0
- package/dist/app/demo/form/method/task/task.js +153 -0
- package/dist/app/demo/form/method/task/task.xml +57 -0
- package/dist/app/demo/form/method/theme/theme.js +74 -0
- package/dist/app/demo/form/method/theme/theme.xml +9 -0
- package/dist/app/demo/form/method/tool/tool.js +64 -0
- package/dist/app/demo/form/method/tool/tool.xml +26 -0
- package/dist/app/demo/form/method/zip/zip.js +99 -0
- package/dist/app/demo/form/method/zip/zip.xml +12 -0
- package/dist/app/demo/global.css +3 -0
- package/dist/app/demo/res/icon.svg +1 -0
- package/dist/app/demo/res/img.jpg +0 -0
- package/dist/app/demo/res/r-1.svg +1 -0
- package/dist/app/demo/res/r-2.svg +1 -0
- package/dist/app/demo/res/sql.svg +1 -0
- package/dist/app/demo/res/txt.svg +1 -0
- package/dist/app/demo/res/zip.svg +1 -0
- package/dist/app/task/config.json +29 -0
- package/dist/app/task/form/bar/bar.js +299 -0
- package/dist/app/task/form/bar/bar.xml +47 -0
- package/dist/app/task/form/desktop/desktop.xml +1 -0
- package/dist/app/task/locale/en.json +11 -0
- package/dist/app/task/locale/ja.json +11 -0
- package/dist/app/task/locale/sc.json +11 -0
- package/dist/app/task/locale/tc.json +11 -0
- package/dist/clickgo.js +41 -0
- package/dist/clickgo.ts +51 -0
- package/dist/control/common.cgc +0 -0
- package/dist/control/form.cgc +0 -0
- package/dist/control/monaco.cgc +0 -0
- package/dist/control/property.cgc +0 -0
- package/dist/control/task.cgc +0 -0
- package/dist/global.css +1 -0
- package/dist/icon.png +0 -0
- package/dist/index.js +88 -0
- package/dist/index.ts +92 -0
- package/dist/lib/control.js +365 -0
- package/dist/lib/control.ts +428 -0
- package/dist/lib/core.js +668 -0
- package/dist/lib/core.ts +732 -0
- package/dist/lib/dom.js +1471 -0
- package/dist/lib/dom.ts +1785 -0
- package/dist/lib/form.js +2101 -0
- package/dist/lib/form.ts +2496 -0
- package/dist/lib/fs.js +849 -0
- package/dist/lib/fs.ts +995 -0
- package/dist/lib/native.js +138 -0
- package/dist/lib/native.ts +219 -0
- package/dist/lib/task.js +686 -0
- package/dist/lib/task.ts +842 -0
- package/dist/lib/theme.js +159 -0
- package/dist/lib/theme.ts +196 -0
- package/dist/lib/tool.js +501 -0
- package/dist/lib/tool.ts +620 -0
- package/dist/lib/zip.js +352 -0
- package/dist/lib/zip.ts +434 -0
- package/dist/theme/familiar.cgt +0 -0
- package/package.json +27 -0
- package/types/dev.d.ts +30 -0
- package/types/index.d.ts +673 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.clearGlobal = exports.setGlobal = exports.clear = exports.remove = exports.load = exports.read = exports.global = void 0;
|
|
13
|
+
const zip = require("./zip");
|
|
14
|
+
const tool = require("./tool");
|
|
15
|
+
const task = require("./task");
|
|
16
|
+
const dom = require("./dom");
|
|
17
|
+
exports.global = null;
|
|
18
|
+
function read(blob) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const z = yield zip.get(blob);
|
|
21
|
+
if (!z) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const configContent = yield z.getContent('config.json');
|
|
25
|
+
if (!configContent) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const config = JSON.parse(configContent);
|
|
29
|
+
const files = {};
|
|
30
|
+
for (const file of config.files) {
|
|
31
|
+
const mime = tool.getMimeByPath(file);
|
|
32
|
+
if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
|
|
33
|
+
const fab = yield z.getContent(file, 'string');
|
|
34
|
+
if (!fab) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
files[file] = fab.replace(/^\ufeff/, '');
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const fab = yield z.getContent(file, 'arraybuffer');
|
|
41
|
+
if (!fab) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
files[file] = new Blob([fab], {
|
|
45
|
+
'type': mime.mime
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
'type': 'theme',
|
|
51
|
+
'config': config,
|
|
52
|
+
'files': files
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
exports.read = read;
|
|
57
|
+
function load(theme, taskId) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
if (!taskId) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const t = task.list[taskId];
|
|
63
|
+
if (!t) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const isGlobal = theme ? false : true;
|
|
67
|
+
if (t.customTheme && isGlobal) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (!theme) {
|
|
71
|
+
if (!exports.global) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
theme = exports.global;
|
|
75
|
+
}
|
|
76
|
+
let style = theme.files[theme.config.style + '.css'];
|
|
77
|
+
if (!style) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
style = tool.stylePrepend(style, `cg-theme-task${taskId}-`).style;
|
|
81
|
+
style = yield tool.styleUrl2DataUrl(theme.config.style, style, theme.files);
|
|
82
|
+
style = style.replace(/\[CGTMP-GLOBAL\] +::selection/g, `#cg-form-list > [data-task-id="${taskId}"] ::selection, #cg-pop-list > [class^="cg-theme-task${taskId}-"] ::selection`);
|
|
83
|
+
style = style.replace(/\[CGTMP-GLOBAL\]/g, `#cg-form-list > [data-task-id="${taskId}"], #cg-pop-list > [class^="cg-theme-task${taskId}-"]`);
|
|
84
|
+
if (!t.customTheme) {
|
|
85
|
+
if (!isGlobal) {
|
|
86
|
+
t.customTheme = true;
|
|
87
|
+
}
|
|
88
|
+
dom.removeStyle(taskId, 'theme');
|
|
89
|
+
}
|
|
90
|
+
dom.pushStyle(taskId, style, 'theme', theme.config.name);
|
|
91
|
+
return true;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports.load = load;
|
|
95
|
+
function remove(name, taskId) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
if (!taskId) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const t = task.list[taskId];
|
|
101
|
+
if (!t) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!t.customTheme) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
dom.removeStyle(taskId, 'theme', name);
|
|
108
|
+
if (dom.getStyleCount(taskId, 'theme') === 0) {
|
|
109
|
+
t.customTheme = false;
|
|
110
|
+
if (exports.global) {
|
|
111
|
+
yield load(undefined, taskId);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
exports.remove = remove;
|
|
117
|
+
function clear(taskId) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
if (!taskId) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const t = task.list[taskId];
|
|
123
|
+
if (!t) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (!t.customTheme) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
dom.removeStyle(taskId, 'theme');
|
|
130
|
+
t.customTheme = false;
|
|
131
|
+
if (exports.global) {
|
|
132
|
+
yield load(undefined, taskId);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
exports.clear = clear;
|
|
137
|
+
function setGlobal(theme) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
exports.global = theme;
|
|
140
|
+
for (const taskId in task.list) {
|
|
141
|
+
yield load(undefined, parseInt(taskId));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
exports.setGlobal = setGlobal;
|
|
146
|
+
function clearGlobal() {
|
|
147
|
+
if (!exports.global) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
exports.global = null;
|
|
151
|
+
for (const taskId in task.list) {
|
|
152
|
+
const t = task.list[taskId];
|
|
153
|
+
if (t.customTheme) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
dom.removeStyle(t.id, 'theme');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.clearGlobal = clearGlobal;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2022 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 types from '../../types';
|
|
17
|
+
import * as zip from './zip';
|
|
18
|
+
import * as tool from './tool';
|
|
19
|
+
import * as task from './task';
|
|
20
|
+
import * as dom from './dom';
|
|
21
|
+
|
|
22
|
+
/** --- 当前全局主题 --- */
|
|
23
|
+
export let global: types.ITheme | null = null;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* --- cgt 文件 blob 转 IThemePkg 对象,会自动创建 object url,请注意释放 ---
|
|
27
|
+
* @param blob blob 对象
|
|
28
|
+
*/
|
|
29
|
+
export async function read(blob: Blob): Promise<types.ITheme | false> {
|
|
30
|
+
const z = await zip.get(blob);
|
|
31
|
+
if (!z) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const configContent = await z.getContent('config.json');
|
|
35
|
+
if (!configContent) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const config: types.IThemeConfig = JSON.parse(configContent);
|
|
39
|
+
// --- 开始读取文件 ---
|
|
40
|
+
const files: Record<string, Blob | string> = {};
|
|
41
|
+
for (const file of config.files) {
|
|
42
|
+
const mime = tool.getMimeByPath(file);
|
|
43
|
+
if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
|
|
44
|
+
const fab = await z.getContent(file, 'string');
|
|
45
|
+
if (!fab) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
files[file] = fab.replace(/^\ufeff/, '');
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const fab = await z.getContent(file, 'arraybuffer');
|
|
52
|
+
if (!fab) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
files[file] = new Blob([fab], {
|
|
56
|
+
'type': mime.mime
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
'type': 'theme',
|
|
62
|
+
'config': config,
|
|
63
|
+
'files': files
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* --- 加载 theme 给任务(App 模式下必须设置 theme,不能用来加载所谓的全局主题) ---
|
|
69
|
+
* @param theme ITheme 对象,undefined 代表加载全局的默认主题,但 App 模式下必须设置此项
|
|
70
|
+
* @param taskId 要给某任务 ID 加载主题,App 模式下无效
|
|
71
|
+
*/
|
|
72
|
+
export async function load(theme?: types.ITheme, taskId?: number): Promise<boolean> {
|
|
73
|
+
if (!taskId) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const t = task.list[taskId];
|
|
77
|
+
if (!t) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
/** --- 是否加载全局的主题到本任务 --- */
|
|
81
|
+
const isGlobal = theme ? false : true;
|
|
82
|
+
// --- 如果当前是自定,来设置的是全局,则不修改 ---
|
|
83
|
+
if (t.customTheme && isGlobal) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (!theme) {
|
|
87
|
+
// --- 等同于 if (isGlobal) { ---
|
|
88
|
+
// --- 设置系统主题 ---
|
|
89
|
+
if (!global) {
|
|
90
|
+
// --- 但系统主题不存在,也算设置成功了 ---
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
// --- 当前任务非自定,可以设置为系统主题 ---
|
|
94
|
+
theme = global;
|
|
95
|
+
}
|
|
96
|
+
let style = theme.files[theme.config.style + '.css'] as string;
|
|
97
|
+
if (!style) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
style = tool.stylePrepend(style, `cg-theme-task${taskId}-`).style;
|
|
101
|
+
style = await tool.styleUrl2DataUrl(theme.config.style, style, theme.files);
|
|
102
|
+
// --- 替换 [CGTMP-GLOBAL] ---
|
|
103
|
+
style = style.replace(/\[CGTMP-GLOBAL\] +::selection/g, `#cg-form-list > [data-task-id="${taskId}"] ::selection, #cg-pop-list > [class^="cg-theme-task${taskId}-"] ::selection`);
|
|
104
|
+
style = style.replace(/\[CGTMP-GLOBAL\]/g, `#cg-form-list > [data-task-id="${taskId}"], #cg-pop-list > [class^="cg-theme-task${taskId}-"]`);
|
|
105
|
+
if (!t.customTheme) {
|
|
106
|
+
// --- 如果当前 task 不是自定主题 ---
|
|
107
|
+
if (!isGlobal) {
|
|
108
|
+
// --- 但当前设置为自定,则任务标识设置为自定 ---
|
|
109
|
+
t.customTheme = true;
|
|
110
|
+
}
|
|
111
|
+
// --- 只要 task 之前是全局主题,本次就要清除原主题所有内容 ---
|
|
112
|
+
dom.removeStyle(taskId, 'theme');
|
|
113
|
+
}
|
|
114
|
+
dom.pushStyle(taskId, style, 'theme', theme.config.name);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* --- 移除当前 task 的 theme(只能移除自定的) ---
|
|
120
|
+
* @param 要移除的主题 name
|
|
121
|
+
* @param taskId 任务 ID,App 模式下无效
|
|
122
|
+
*/
|
|
123
|
+
export async function remove(name: string, taskId?: number): Promise<void> {
|
|
124
|
+
if (!taskId) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const t = task.list[taskId];
|
|
128
|
+
if (!t) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (!t.customTheme) {
|
|
132
|
+
// --- 当前是系统主题,无权限移除 ---
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
dom.removeStyle(taskId, 'theme', name);
|
|
136
|
+
// --- 判断是否所有自定主题都被移除干净 ---
|
|
137
|
+
if (dom.getStyleCount(taskId, 'theme') === 0) {
|
|
138
|
+
// --- 全部干净了,切换为系统主题 ---
|
|
139
|
+
t.customTheme = false;
|
|
140
|
+
if (global) {
|
|
141
|
+
await load(undefined, taskId);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* --- 清除一个 task 中所有加载的 theme(只能清除自定) ---
|
|
148
|
+
* @param taskId 要清除的任务 id,App 模式下无效
|
|
149
|
+
*/
|
|
150
|
+
export async function clear(taskId?: number): Promise<void> {
|
|
151
|
+
if (!taskId) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const t = task.list[taskId];
|
|
155
|
+
if (!t) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// --- 当前自定才可清除 ---
|
|
159
|
+
if (!t.customTheme) {
|
|
160
|
+
// --- 当前是系统,则不许清除 ---
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
dom.removeStyle(taskId, 'theme');
|
|
164
|
+
t.customTheme = false;
|
|
165
|
+
if (global) {
|
|
166
|
+
await load(undefined, taskId);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* --- 将 cgt 主题设置到全局所有任务 ---
|
|
172
|
+
* @param theme 主题对象
|
|
173
|
+
*/
|
|
174
|
+
export async function setGlobal(theme: types.ITheme): Promise<void> {
|
|
175
|
+
global = theme;
|
|
176
|
+
for (const taskId in task.list) {
|
|
177
|
+
await load(undefined, parseInt(taskId));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* --- 清除全局主题 ---
|
|
183
|
+
*/
|
|
184
|
+
export function clearGlobal(): void {
|
|
185
|
+
if (!global) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
global = null;
|
|
189
|
+
for (const taskId in task.list) {
|
|
190
|
+
const t = task.list[taskId];
|
|
191
|
+
if (t.customTheme) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
dom.removeStyle(t.id, 'theme');
|
|
195
|
+
}
|
|
196
|
+
}
|