@widget-js/core 0.0.5 → 0.0.7

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,190 @@
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
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ElectronApi = void 0;
40
+ var Keys_1 = require("./Keys");
41
+ var ElectronApi = /** @class */ (function () {
42
+ function ElectronApi() {
43
+ }
44
+ ElectronApi.openAddWidgetWindow = function () {
45
+ if (this.hasElectronApi()) {
46
+ // @ts-ignore
47
+ window.electronAPI.invokeIpc("openAddWidgetWindow");
48
+ }
49
+ };
50
+ ElectronApi.registerWidgets = function (widgets) {
51
+ return __awaiter(this, void 0, void 0, function () {
52
+ var data;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
57
+ data = JSON.parse(JSON.stringify(widgets.map(function (item) { return JSON.stringify(item); })));
58
+ // @ts-ignore
59
+ return [4 /*yield*/, window.electronAPI.invokeIpc("registerWidgets", data)];
60
+ case 1:
61
+ // @ts-ignore
62
+ _a.sent();
63
+ _a.label = 2;
64
+ case 2: return [2 /*return*/];
65
+ }
66
+ });
67
+ });
68
+ };
69
+ ElectronApi.setConfig = function (key, value) {
70
+ return __awaiter(this, void 0, void 0, function () {
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0:
74
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
75
+ // @ts-ignore
76
+ return [4 /*yield*/, window.electronAPI.invokeIpc("setConfig", { key: key, value: value })];
77
+ case 1:
78
+ // @ts-ignore
79
+ _a.sent();
80
+ _a.label = 2;
81
+ case 2: return [2 /*return*/];
82
+ }
83
+ });
84
+ });
85
+ };
86
+ ElectronApi.sendBroadcastEvent = function (event) {
87
+ return __awaiter(this, void 0, void 0, function () {
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0:
91
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
92
+ // @ts-ignore
93
+ return [4 /*yield*/, window.electronAPI.invokeIpc(Keys_1.Keys.BROADCAST_EVENT, JSON.stringify(event))];
94
+ case 1:
95
+ // @ts-ignore
96
+ _a.sent();
97
+ _a.label = 2;
98
+ case 2: return [2 /*return*/];
99
+ }
100
+ });
101
+ });
102
+ };
103
+ ElectronApi.registerBroadcast = function (callback) {
104
+ return __awaiter(this, void 0, void 0, function () {
105
+ return __generator(this, function (_a) {
106
+ switch (_a.label) {
107
+ case 0: return [4 /*yield*/, this.addIpcListener(Keys_1.Keys.BROADCAST_EVENT, function (json) {
108
+ callback(JSON.parse(json));
109
+ })];
110
+ case 1:
111
+ _a.sent();
112
+ return [2 /*return*/];
113
+ }
114
+ });
115
+ });
116
+ };
117
+ ElectronApi.unregisterBroadcast = function () {
118
+ return __awaiter(this, void 0, void 0, function () {
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0: return [4 /*yield*/, this.removeIpcListener(Keys_1.Keys.BROADCAST_EVENT)];
122
+ case 1:
123
+ _a.sent();
124
+ return [2 /*return*/];
125
+ }
126
+ });
127
+ });
128
+ };
129
+ ElectronApi.addIpcListener = function (key, f) {
130
+ return __awaiter(this, void 0, void 0, function () {
131
+ return __generator(this, function (_a) {
132
+ switch (_a.label) {
133
+ case 0:
134
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
135
+ // @ts-ignore
136
+ return [4 /*yield*/, window.electronAPI.addIpcListener(key, f)];
137
+ case 1:
138
+ // @ts-ignore
139
+ _a.sent();
140
+ _a.label = 2;
141
+ case 2: return [2 /*return*/];
142
+ }
143
+ });
144
+ });
145
+ };
146
+ ElectronApi.removeIpcListener = function (key) {
147
+ return __awaiter(this, void 0, void 0, function () {
148
+ return __generator(this, function (_a) {
149
+ switch (_a.label) {
150
+ case 0:
151
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
152
+ // @ts-ignore
153
+ return [4 /*yield*/, window.electronAPI.removeIpcListener(key)];
154
+ case 1:
155
+ // @ts-ignore
156
+ _a.sent();
157
+ _a.label = 2;
158
+ case 2: return [2 /*return*/];
159
+ }
160
+ });
161
+ });
162
+ };
163
+ ElectronApi.getConfig = function (key, defaultValue) {
164
+ return __awaiter(this, void 0, void 0, function () {
165
+ var value;
166
+ return __generator(this, function (_a) {
167
+ switch (_a.label) {
168
+ case 0:
169
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
170
+ return [4 /*yield*/, window.electronAPI.invokeIpc("getConfig", key)];
171
+ case 1:
172
+ value = _a.sent();
173
+ if (value === null || value === undefined) {
174
+ return [2 /*return*/, defaultValue];
175
+ }
176
+ if (typeof defaultValue == "boolean") {
177
+ return [2 /*return*/, value === "true"];
178
+ }
179
+ return [2 /*return*/, value];
180
+ case 2: return [2 /*return*/];
181
+ }
182
+ });
183
+ });
184
+ };
185
+ ElectronApi.hasElectronApi = function () {
186
+ return Reflect.has(window, "electronAPI");
187
+ };
188
+ return ElectronApi;
189
+ }());
190
+ exports.ElectronApi = ElectronApi;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Keys = void 0;
4
+ var Keys = /** @class */ (function () {
5
+ function Keys() {
6
+ }
7
+ Keys.CONFIG_LAUNCH_AT_STARTUP = "LAUNCH_AT_STARTUP";
8
+ Keys.CONFIG_WIDGET_SHADOW = "WIDGET_SHADOW";
9
+ Keys.CHANNEL_MAIN = "WeiZ5kaKijae";
10
+ Keys.EVENT_WIDGET_UPDATED = "WIDGET_SHADOW";
11
+ Keys.BROADCAST_EVENT = "sendBroadcastEvent";
12
+ return Keys;
13
+ }());
14
+ exports.Keys = Keys;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./model/Widget"), exports);
18
+ __exportStar(require("./model/BroadcastEvent"), exports);
19
+ __exportStar(require("./model/WidgetData"), exports);
20
+ __exportStar(require("./api/ElectronApi"), exports);
21
+ __exportStar(require("./api/Keys"), exports);
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BroadcastEvent = void 0;
4
+ var BroadcastEvent = /** @class */ (function () {
5
+ function BroadcastEvent(type, from, payload) {
6
+ this.type = type;
7
+ this.from = from;
8
+ this.payload = payload;
9
+ }
10
+ return BroadcastEvent;
11
+ }());
12
+ exports.BroadcastEvent = BroadcastEvent;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SocialInfo = void 0;
4
+ var SocialInfo = /** @class */ (function () {
5
+ function SocialInfo(name, url) {
6
+ this.name = name;
7
+ this.content = url;
8
+ }
9
+ return SocialInfo;
10
+ }());
11
+ exports.SocialInfo = SocialInfo;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WidgetKeyword = exports.Widget = void 0;
4
+ var Widget = /** @class */ (function () {
5
+ function Widget(options) {
6
+ var _a, _b, _c, _d, _e;
7
+ /**
8
+ * 组件默认语言
9
+ */
10
+ this.lang = "zh";
11
+ this.name = options.name;
12
+ this.title = options.title;
13
+ this.description = options.description;
14
+ this.keywords = options.keywords;
15
+ this.lang = options.lang;
16
+ this.w = options.w;
17
+ this.h = options.h;
18
+ this.maxW = (_a = options.maxW) !== null && _a !== void 0 ? _a : options.w;
19
+ this.maxH = (_b = options.maxH) !== null && _b !== void 0 ? _b : options.h;
20
+ this.minW = (_c = options.minW) !== null && _c !== void 0 ? _c : options.w;
21
+ this.minH = (_d = options.minH) !== null && _d !== void 0 ? _d : options.h;
22
+ this.url = options.url;
23
+ this.configUrl = options.configUrl;
24
+ this.extraUrl = (_e = options.extraUrl) !== null && _e !== void 0 ? _e : new Map();
25
+ }
26
+ /**
27
+ * 获取组件标题
28
+ * @param lang 语言环境,不传则获取默认语言
29
+ */
30
+ Widget.prototype.getTitle = function (lang) {
31
+ return lang ? this.title.get(lang) : this.title.get(this.lang);
32
+ };
33
+ /**
34
+ * 获取组件标描述
35
+ * @param lang 语言环境,不传则获取默认标题
36
+ */
37
+ Widget.prototype.getDescription = function (lang) {
38
+ return lang ? this.description.get(lang) : this.description.get(this.lang);
39
+ };
40
+ Widget.prototype.toJSON = function () {
41
+ return {
42
+ name: this.name,
43
+ title: Object.fromEntries(this.title),
44
+ description: Object.fromEntries(this.description),
45
+ keywords: this.keywords,
46
+ lang: this.lang,
47
+ w: this.w,
48
+ h: this.h,
49
+ maxW: this.maxW,
50
+ maxH: this.maxH,
51
+ minW: this.minW,
52
+ minH: this.minH,
53
+ url: this.url,
54
+ configUrl: this.configUrl,
55
+ extraUrl: Object.fromEntries(this.extraUrl),
56
+ };
57
+ };
58
+ Widget.parse = function (json) {
59
+ var object = JSON.parse(json);
60
+ return new Widget({
61
+ configUrl: object["configUrl"],
62
+ description: new Map(Object.entries(object["description"])),
63
+ extraUrl: new Map(Object.entries(object["extraUrl"])),
64
+ h: object["h"],
65
+ keywords: object["keywords"],
66
+ lang: object["lang"],
67
+ maxH: object["maxH"],
68
+ maxW: object["maxW"],
69
+ minH: object["minH"],
70
+ minW: object["minW"],
71
+ name: object["name"],
72
+ title: new Map(Object.entries(object["title"])),
73
+ url: object["url"],
74
+ w: object["w"]
75
+ });
76
+ };
77
+ return Widget;
78
+ }());
79
+ exports.Widget = Widget;
80
+ var WidgetKeyword;
81
+ (function (WidgetKeyword) {
82
+ WidgetKeyword["RECOMMEND"] = "recommend";
83
+ WidgetKeyword["TOOLS"] = "tools";
84
+ WidgetKeyword["EFFICIENCY"] = "efficiency";
85
+ WidgetKeyword["PICTURE"] = "picture";
86
+ WidgetKeyword["LIFE"] = "life";
87
+ WidgetKeyword["SHORTCUT"] = "shortcut";
88
+ WidgetKeyword["COUNTDOWN"] = "countdown";
89
+ WidgetKeyword["TIMER"] = "timer";
90
+ WidgetKeyword["INFO"] = "info";
91
+ WidgetKeyword["DASHBOARD"] = "dashboard";
92
+ })(WidgetKeyword = exports.WidgetKeyword || (exports.WidgetKeyword = {}));
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * 组件配置数据,用于存储组件自定义页面所设置的数据
5
+ */
6
+ var WidgetData = /** @class */ (function () {
7
+ function WidgetData(name, id) {
8
+ this.id = id;
9
+ this.name = name;
10
+ }
11
+ return WidgetData;
12
+ }());
13
+ exports.default = WidgetData;
@@ -0,0 +1,187 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { Keys } from "./Keys";
38
+ var ElectronApi = /** @class */ (function () {
39
+ function ElectronApi() {
40
+ }
41
+ ElectronApi.openAddWidgetWindow = function () {
42
+ if (this.hasElectronApi()) {
43
+ // @ts-ignore
44
+ window.electronAPI.invokeIpc("openAddWidgetWindow");
45
+ }
46
+ };
47
+ ElectronApi.registerWidgets = function (widgets) {
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var data;
50
+ return __generator(this, function (_a) {
51
+ switch (_a.label) {
52
+ case 0:
53
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
54
+ data = JSON.parse(JSON.stringify(widgets.map(function (item) { return JSON.stringify(item); })));
55
+ // @ts-ignore
56
+ return [4 /*yield*/, window.electronAPI.invokeIpc("registerWidgets", data)];
57
+ case 1:
58
+ // @ts-ignore
59
+ _a.sent();
60
+ _a.label = 2;
61
+ case 2: return [2 /*return*/];
62
+ }
63
+ });
64
+ });
65
+ };
66
+ ElectronApi.setConfig = function (key, value) {
67
+ return __awaiter(this, void 0, void 0, function () {
68
+ return __generator(this, function (_a) {
69
+ switch (_a.label) {
70
+ case 0:
71
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
72
+ // @ts-ignore
73
+ return [4 /*yield*/, window.electronAPI.invokeIpc("setConfig", { key: key, value: value })];
74
+ case 1:
75
+ // @ts-ignore
76
+ _a.sent();
77
+ _a.label = 2;
78
+ case 2: return [2 /*return*/];
79
+ }
80
+ });
81
+ });
82
+ };
83
+ ElectronApi.sendBroadcastEvent = function (event) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
89
+ // @ts-ignore
90
+ return [4 /*yield*/, window.electronAPI.invokeIpc(Keys.BROADCAST_EVENT, JSON.stringify(event))];
91
+ case 1:
92
+ // @ts-ignore
93
+ _a.sent();
94
+ _a.label = 2;
95
+ case 2: return [2 /*return*/];
96
+ }
97
+ });
98
+ });
99
+ };
100
+ ElectronApi.registerBroadcast = function (callback) {
101
+ return __awaiter(this, void 0, void 0, function () {
102
+ return __generator(this, function (_a) {
103
+ switch (_a.label) {
104
+ case 0: return [4 /*yield*/, this.addIpcListener(Keys.BROADCAST_EVENT, function (json) {
105
+ callback(JSON.parse(json));
106
+ })];
107
+ case 1:
108
+ _a.sent();
109
+ return [2 /*return*/];
110
+ }
111
+ });
112
+ });
113
+ };
114
+ ElectronApi.unregisterBroadcast = function () {
115
+ return __awaiter(this, void 0, void 0, function () {
116
+ return __generator(this, function (_a) {
117
+ switch (_a.label) {
118
+ case 0: return [4 /*yield*/, this.removeIpcListener(Keys.BROADCAST_EVENT)];
119
+ case 1:
120
+ _a.sent();
121
+ return [2 /*return*/];
122
+ }
123
+ });
124
+ });
125
+ };
126
+ ElectronApi.addIpcListener = function (key, f) {
127
+ return __awaiter(this, void 0, void 0, function () {
128
+ return __generator(this, function (_a) {
129
+ switch (_a.label) {
130
+ case 0:
131
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
132
+ // @ts-ignore
133
+ return [4 /*yield*/, window.electronAPI.addIpcListener(key, f)];
134
+ case 1:
135
+ // @ts-ignore
136
+ _a.sent();
137
+ _a.label = 2;
138
+ case 2: return [2 /*return*/];
139
+ }
140
+ });
141
+ });
142
+ };
143
+ ElectronApi.removeIpcListener = function (key) {
144
+ return __awaiter(this, void 0, void 0, function () {
145
+ return __generator(this, function (_a) {
146
+ switch (_a.label) {
147
+ case 0:
148
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
149
+ // @ts-ignore
150
+ return [4 /*yield*/, window.electronAPI.removeIpcListener(key)];
151
+ case 1:
152
+ // @ts-ignore
153
+ _a.sent();
154
+ _a.label = 2;
155
+ case 2: return [2 /*return*/];
156
+ }
157
+ });
158
+ });
159
+ };
160
+ ElectronApi.getConfig = function (key, defaultValue) {
161
+ return __awaiter(this, void 0, void 0, function () {
162
+ var value;
163
+ return __generator(this, function (_a) {
164
+ switch (_a.label) {
165
+ case 0:
166
+ if (!this.hasElectronApi()) return [3 /*break*/, 2];
167
+ return [4 /*yield*/, window.electronAPI.invokeIpc("getConfig", key)];
168
+ case 1:
169
+ value = _a.sent();
170
+ if (value === null || value === undefined) {
171
+ return [2 /*return*/, defaultValue];
172
+ }
173
+ if (typeof defaultValue == "boolean") {
174
+ return [2 /*return*/, value === "true"];
175
+ }
176
+ return [2 /*return*/, value];
177
+ case 2: return [2 /*return*/];
178
+ }
179
+ });
180
+ });
181
+ };
182
+ ElectronApi.hasElectronApi = function () {
183
+ return Reflect.has(window, "electronAPI");
184
+ };
185
+ return ElectronApi;
186
+ }());
187
+ export { ElectronApi };
@@ -0,0 +1,11 @@
1
+ var Keys = /** @class */ (function () {
2
+ function Keys() {
3
+ }
4
+ Keys.CONFIG_LAUNCH_AT_STARTUP = "LAUNCH_AT_STARTUP";
5
+ Keys.CONFIG_WIDGET_SHADOW = "WIDGET_SHADOW";
6
+ Keys.CHANNEL_MAIN = "WeiZ5kaKijae";
7
+ Keys.EVENT_WIDGET_UPDATED = "WIDGET_SHADOW";
8
+ Keys.BROADCAST_EVENT = "sendBroadcastEvent";
9
+ return Keys;
10
+ }());
11
+ export { Keys };
@@ -0,0 +1,5 @@
1
+ export * from "./model/Widget";
2
+ export * from "./model/BroadcastEvent";
3
+ export * from "./model/WidgetData";
4
+ export * from "./api/ElectronApi";
5
+ export * from "./api/Keys";
@@ -0,0 +1,9 @@
1
+ var BroadcastEvent = /** @class */ (function () {
2
+ function BroadcastEvent(type, from, payload) {
3
+ this.type = type;
4
+ this.from = from;
5
+ this.payload = payload;
6
+ }
7
+ return BroadcastEvent;
8
+ }());
9
+ export { BroadcastEvent };
@@ -0,0 +1,8 @@
1
+ var SocialInfo = /** @class */ (function () {
2
+ function SocialInfo(name, url) {
3
+ this.name = name;
4
+ this.content = url;
5
+ }
6
+ return SocialInfo;
7
+ }());
8
+ export { SocialInfo };
@@ -0,0 +1,89 @@
1
+ var Widget = /** @class */ (function () {
2
+ function Widget(options) {
3
+ var _a, _b, _c, _d, _e;
4
+ /**
5
+ * 组件默认语言
6
+ */
7
+ this.lang = "zh";
8
+ this.name = options.name;
9
+ this.title = options.title;
10
+ this.description = options.description;
11
+ this.keywords = options.keywords;
12
+ this.lang = options.lang;
13
+ this.w = options.w;
14
+ this.h = options.h;
15
+ this.maxW = (_a = options.maxW) !== null && _a !== void 0 ? _a : options.w;
16
+ this.maxH = (_b = options.maxH) !== null && _b !== void 0 ? _b : options.h;
17
+ this.minW = (_c = options.minW) !== null && _c !== void 0 ? _c : options.w;
18
+ this.minH = (_d = options.minH) !== null && _d !== void 0 ? _d : options.h;
19
+ this.url = options.url;
20
+ this.configUrl = options.configUrl;
21
+ this.extraUrl = (_e = options.extraUrl) !== null && _e !== void 0 ? _e : new Map();
22
+ }
23
+ /**
24
+ * 获取组件标题
25
+ * @param lang 语言环境,不传则获取默认语言
26
+ */
27
+ Widget.prototype.getTitle = function (lang) {
28
+ return lang ? this.title.get(lang) : this.title.get(this.lang);
29
+ };
30
+ /**
31
+ * 获取组件标描述
32
+ * @param lang 语言环境,不传则获取默认标题
33
+ */
34
+ Widget.prototype.getDescription = function (lang) {
35
+ return lang ? this.description.get(lang) : this.description.get(this.lang);
36
+ };
37
+ Widget.prototype.toJSON = function () {
38
+ return {
39
+ name: this.name,
40
+ title: Object.fromEntries(this.title),
41
+ description: Object.fromEntries(this.description),
42
+ keywords: this.keywords,
43
+ lang: this.lang,
44
+ w: this.w,
45
+ h: this.h,
46
+ maxW: this.maxW,
47
+ maxH: this.maxH,
48
+ minW: this.minW,
49
+ minH: this.minH,
50
+ url: this.url,
51
+ configUrl: this.configUrl,
52
+ extraUrl: Object.fromEntries(this.extraUrl),
53
+ };
54
+ };
55
+ Widget.parse = function (json) {
56
+ var object = JSON.parse(json);
57
+ return new Widget({
58
+ configUrl: object["configUrl"],
59
+ description: new Map(Object.entries(object["description"])),
60
+ extraUrl: new Map(Object.entries(object["extraUrl"])),
61
+ h: object["h"],
62
+ keywords: object["keywords"],
63
+ lang: object["lang"],
64
+ maxH: object["maxH"],
65
+ maxW: object["maxW"],
66
+ minH: object["minH"],
67
+ minW: object["minW"],
68
+ name: object["name"],
69
+ title: new Map(Object.entries(object["title"])),
70
+ url: object["url"],
71
+ w: object["w"]
72
+ });
73
+ };
74
+ return Widget;
75
+ }());
76
+ export { Widget };
77
+ export var WidgetKeyword;
78
+ (function (WidgetKeyword) {
79
+ WidgetKeyword["RECOMMEND"] = "recommend";
80
+ WidgetKeyword["TOOLS"] = "tools";
81
+ WidgetKeyword["EFFICIENCY"] = "efficiency";
82
+ WidgetKeyword["PICTURE"] = "picture";
83
+ WidgetKeyword["LIFE"] = "life";
84
+ WidgetKeyword["SHORTCUT"] = "shortcut";
85
+ WidgetKeyword["COUNTDOWN"] = "countdown";
86
+ WidgetKeyword["TIMER"] = "timer";
87
+ WidgetKeyword["INFO"] = "info";
88
+ WidgetKeyword["DASHBOARD"] = "dashboard";
89
+ })(WidgetKeyword || (WidgetKeyword = {}));
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 组件配置数据,用于存储组件自定义页面所设置的数据
3
+ */
4
+ var WidgetData = /** @class */ (function () {
5
+ function WidgetData(name, id) {
6
+ this.id = id;
7
+ this.name = name;
8
+ }
9
+ return WidgetData;
10
+ }());
11
+ export default WidgetData;
@@ -0,0 +1,14 @@
1
+ import { Widget } from "../model/Widget";
2
+ import { BroadcastEvent } from "../model/BroadcastEvent";
3
+ export declare class ElectronApi {
4
+ static openAddWidgetWindow(): void;
5
+ static registerWidgets(widgets: Widget[]): Promise<void>;
6
+ static setConfig(key: string, value: string | number | boolean): Promise<void>;
7
+ static sendBroadcastEvent(event: BroadcastEvent): Promise<void>;
8
+ static registerBroadcast(callback: (event: BroadcastEvent) => void): Promise<void>;
9
+ static unregisterBroadcast(): Promise<void>;
10
+ static addIpcListener(key: String, f: Function): Promise<void>;
11
+ static removeIpcListener(key: String): Promise<void>;
12
+ static getConfig(key: string, defaultValue: string | number | boolean): Promise<any>;
13
+ static hasElectronApi(): boolean;
14
+ }
@@ -0,0 +1,7 @@
1
+ export declare class Keys {
2
+ static readonly CONFIG_LAUNCH_AT_STARTUP = "LAUNCH_AT_STARTUP";
3
+ static readonly CONFIG_WIDGET_SHADOW = "WIDGET_SHADOW";
4
+ static readonly CHANNEL_MAIN = "WeiZ5kaKijae";
5
+ static readonly EVENT_WIDGET_UPDATED = "WIDGET_SHADOW";
6
+ static readonly BROADCAST_EVENT = "sendBroadcastEvent";
7
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./model/Widget";
2
+ export * from "./model/BroadcastEvent";
3
+ export * from "./model/WidgetData";
4
+ export * from "./api/ElectronApi";
5
+ export * from "./api/Keys";
@@ -0,0 +1,6 @@
1
+ export declare class BroadcastEvent {
2
+ type: string;
3
+ from: string;
4
+ payload: any;
5
+ constructor(type: string, from: string, payload: any);
6
+ }
@@ -0,0 +1,6 @@
1
+ export type SocialInfoType = "qq" | "wechat" | "qq-group" | "discord" | "telegram" | "tiktok" | "douyin" | "youtube" | "instagram" | "twitter" | "facebook" | "kuaishou" | "bilibili" | "github" | "email" | "gitee" | "homepage";
2
+ export declare class SocialInfo {
3
+ name: SocialInfoType;
4
+ content: string;
5
+ constructor(name: SocialInfoType, url: string);
6
+ }
@@ -0,0 +1,92 @@
1
+ type WidgetOptions = {
2
+ name: string;
3
+ title: Map<string, string>;
4
+ description: Map<string, string>;
5
+ keywords: WidgetKeyword[];
6
+ lang: string;
7
+ w: number;
8
+ h: number;
9
+ maxW?: number;
10
+ maxH?: number;
11
+ minW?: number;
12
+ minH?: number;
13
+ url: string;
14
+ configUrl?: string;
15
+ extraUrl?: Map<string, string>;
16
+ };
17
+ export declare class Widget {
18
+ readonly name: string;
19
+ /**
20
+ * 组件标题,显示在界面上的,
21
+ * https://zh.m.wikipedia.org/zh-hans/ISO_639-1
22
+ */
23
+ readonly title: Map<string, string>;
24
+ /**
25
+ * 组件介绍
26
+ */
27
+ readonly description: Map<string, string>;
28
+ readonly keywords: WidgetKeyword[];
29
+ /**
30
+ * 组件默认语言
31
+ */
32
+ readonly lang: string;
33
+ readonly w: number;
34
+ readonly h: number;
35
+ readonly maxW: number;
36
+ readonly maxH: number;
37
+ readonly minW: number;
38
+ readonly minH: number;
39
+ readonly url: string;
40
+ readonly configUrl?: string | null;
41
+ /**
42
+ * 组件其他页面的url在这注册
43
+ */
44
+ readonly extraUrl: Map<string, string>;
45
+ constructor(options: WidgetOptions);
46
+ /**
47
+ * 获取组件标题
48
+ * @param lang 语言环境,不传则获取默认语言
49
+ */
50
+ getTitle(lang?: string): string | undefined;
51
+ /**
52
+ * 获取组件标描述
53
+ * @param lang 语言环境,不传则获取默认标题
54
+ */
55
+ getDescription(lang?: string): string | undefined;
56
+ toJSON(): {
57
+ name: string;
58
+ title: {
59
+ [k: string]: string;
60
+ };
61
+ description: {
62
+ [k: string]: string;
63
+ };
64
+ keywords: WidgetKeyword[];
65
+ lang: string;
66
+ w: number;
67
+ h: number;
68
+ maxW: number;
69
+ maxH: number;
70
+ minW: number;
71
+ minH: number;
72
+ url: string;
73
+ configUrl: string | null | undefined;
74
+ extraUrl: {
75
+ [k: string]: string;
76
+ };
77
+ };
78
+ static parse(json: string): Widget;
79
+ }
80
+ export declare enum WidgetKeyword {
81
+ RECOMMEND = "recommend",
82
+ TOOLS = "tools",
83
+ EFFICIENCY = "efficiency",
84
+ PICTURE = "picture",
85
+ LIFE = "life",
86
+ SHORTCUT = "shortcut",
87
+ COUNTDOWN = "countdown",
88
+ TIMER = "timer",
89
+ INFO = "info",
90
+ DASHBOARD = "dashboard"
91
+ }
92
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 组件配置数据,用于存储组件自定义页面所设置的数据
3
+ */
4
+ export default class WidgetData {
5
+ id: string;
6
+ name: string;
7
+ title?: string;
8
+ backgroundColor?: string;
9
+ color?: string;
10
+ fontSize?: number;
11
+ borderRadius?: number;
12
+ date?: string;
13
+ /**
14
+ * 其他数据,以JSON格式放在这里
15
+ */
16
+ extraJSON?: any;
17
+ constructor(name: string, id: string);
18
+ }
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.exampleTypescriptPackage=t():e.exampleTypescriptPackage=t()}(this,(()=>(()=>{"use strict";var e={991:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function s(e){try{a(i.next(e))}catch(e){o(e)}}function c(e){try{a(i.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((i=i.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(s=0)),s;)try{if(n=1,i&&(r=2&c[0]?i.return:c[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,c[1])).done)return r;switch(i=0,r&&(c=[2&c[0],r.value]),c[0]){case 0:case 1:r=c;break;case 4:return s.label++,{value:c[1],done:!1};case 5:s.label++,i=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!((r=(r=s.trys).length>0&&r[r.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!r||c[1]>r[0]&&c[1]<r[3])){s.label=c[1];break}if(6===c[0]&&s.label<r[1]){s.label=r[1],r=c;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(c);break}r[2]&&s.ops.pop(),s.trys.pop();continue}c=t.call(e,s)}catch(e){c=[6,e],i=0}finally{n=r=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.ElectronApi=void 0;var o=n(873),s=function(){function e(){}return e.openAddWidgetWindow=function(){this.hasElectronApi()&&window.electronAPI.invokeIpc("openAddWidgetWindow")},e.registerWidgets=function(e){return i(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return this.hasElectronApi()?(t=JSON.parse(JSON.stringify(e.map((function(e){return JSON.stringify(e)})))),[4,window.electronAPI.invokeIpc("registerWidgets",t)]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))},e.setConfig=function(e,t){return i(this,void 0,void 0,(function(){return r(this,(function(n){switch(n.label){case 0:return this.hasElectronApi()?[4,window.electronAPI.invokeIpc("setConfig",{key:e,value:t})]:[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))},e.sendBroadcastEvent=function(e){return i(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.hasElectronApi()?[4,window.electronAPI.invokeIpc(o.Keys.BROADCAST_EVENT,JSON.stringify(e))]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))},e.registerBroadcast=function(e){return i(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.addIpcListener(o.Keys.BROADCAST_EVENT,(function(t){e(JSON.parse(t))}))];case 1:return t.sent(),[2]}}))}))},e.unregisterBroadcast=function(){return i(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.removeIpcListener(o.Keys.BROADCAST_EVENT)];case 1:return e.sent(),[2]}}))}))},e.addIpcListener=function(e,t){return i(this,void 0,void 0,(function(){return r(this,(function(n){switch(n.label){case 0:return this.hasElectronApi()?[4,window.electronAPI.addIpcListener(e,t)]:[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))},e.removeIpcListener=function(e){return i(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.hasElectronApi()?[4,window.electronAPI.removeIpcListener(e)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))},e.getConfig=function(e,t){return i(this,void 0,void 0,(function(){var n;return r(this,(function(i){switch(i.label){case 0:return this.hasElectronApi()?[4,window.electronAPI.invokeIpc("getConfig",e)]:[3,2];case 1:return null==(n=i.sent())?[2,t]:"boolean"==typeof t?[2,"true"===n]:[2,n];case 2:return[2]}}))}))},e.hasElectronApi=function(){return Reflect.has(window,"electronAPI")},e}();t.ElectronApi=s},873:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Keys=void 0;var n=function(){function e(){}return e.CONFIG_LAUNCH_AT_STARTUP="LAUNCH_AT_STARTUP",e.CONFIG_WIDGET_SHADOW="WIDGET_SHADOW",e.CHANNEL_MAIN="WeiZ5kaKijae",e.EVENT_WIDGET_UPDATED="WIDGET_SHADOW",e.BROADCAST_EVENT="sendBroadcastEvent",e}();t.Keys=n},432:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,r)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),r(n(203),t),r(n(982),t),r(n(791),t),r(n(991),t),r(n(873),t)},982:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BroadcastEvent=void 0;t.BroadcastEvent=function(e,t,n){this.type=e,this.from=t,this.payload=n}},203:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WidgetKeyword=t.Widget=void 0;var n,i=function(){function e(e){var t,n,i,r,o;this.lang="zh",this.name=e.name,this.title=e.title,this.description=e.description,this.keywords=e.keywords,this.lang=e.lang,this.w=e.w,this.h=e.h,this.maxW=null!==(t=e.maxW)&&void 0!==t?t:e.w,this.maxH=null!==(n=e.maxH)&&void 0!==n?n:e.h,this.minW=null!==(i=e.minW)&&void 0!==i?i:e.w,this.minH=null!==(r=e.minH)&&void 0!==r?r:e.h,this.url=e.url,this.configUrl=e.configUrl,this.extraUrl=null!==(o=e.extraUrl)&&void 0!==o?o:new Map}return e.prototype.getTitle=function(e){return e?this.title.get(e):this.title.get(this.lang)},e.prototype.getDescription=function(e){return e?this.description.get(e):this.description.get(this.lang)},e.prototype.toJSON=function(){return{name:this.name,title:Object.fromEntries(this.title),description:Object.fromEntries(this.description),keywords:this.keywords,lang:this.lang,w:this.w,h:this.h,maxW:this.maxW,maxH:this.maxH,minW:this.minW,minH:this.minH,url:this.url,configUrl:this.configUrl,extraUrl:Object.fromEntries(this.extraUrl)}},e.parse=function(t){var n=JSON.parse(t);return new e({configUrl:n.configUrl,description:new Map(Object.entries(n.description)),extraUrl:new Map(Object.entries(n.extraUrl)),h:n.h,keywords:n.keywords,lang:n.lang,maxH:n.maxH,maxW:n.maxW,minH:n.minH,minW:n.minW,name:n.name,title:new Map(Object.entries(n.title)),url:n.url,w:n.w})},e}();t.Widget=i,(n=t.WidgetKeyword||(t.WidgetKeyword={})).RECOMMEND="recommend",n.TOOLS="tools",n.EFFICIENCY="efficiency",n.PICTURE="picture",n.LIFE="life",n.SHORTCUT="shortcut",n.COUNTDOWN="countdown",n.TIMER="timer",n.INFO="info",n.DASHBOARD="dashboard"},791:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e,t){this.id=t,this.name=e}}},t={};return function n(i){var r=t[i];if(void 0!==r)return r.exports;var o=t[i]={exports:{}};return e[i].call(o.exports,o,o.exports,n),o.exports}(432)})()));
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@widget-js/core",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "types": "./dist/types/index.d.ts",
9
- "exports": "./dist/esm",
9
+ "exports": "./dist/umd/index.js",
10
10
  "scripts": {
11
11
  "prepublishOnly": "pinst --disable",
12
12
  "test": "jest --no-cache --runInBand",
13
13
  "test:cov": "jest --coverage --no-cache --runInBand",
14
- "build": "npm run build:cjs && npm run build:esm && npm run build:umd && npm run build:types",
14
+ "build": "npm run build:esm && npm run build:types && npm run build:cjs && npm run build:umd",
15
+ "build:update": "npm run build && yarn --cwd ../../../ upgrade @widget-js/core && yarn --cwd ../../../electron upgrade @widget-js/core",
15
16
  "build:cjs": "node tools/cleanup cjs && tsc -p config/tsconfig.cjs.json",
16
17
  "build:esm": "node tools/cleanup esm && tsc -p config/tsconfig.esm.json",
17
18
  "build:umd": "node tools/cleanup umd && webpack --config config/webpack.config.js",
@@ -30,7 +31,7 @@
30
31
  "url": "https://github.com/widom-widget/core/issues"
31
32
  },
32
33
  "files": [
33
- "src"
34
+ "dist"
34
35
  ],
35
36
  "devDependencies": {
36
37
  "@babel/cli": "^7.19.3",
@@ -1,22 +0,0 @@
1
- import {Widget} from "../model/Widget"
2
-
3
- export class ElectronApi {
4
- static openAddWidgetWindow() {
5
- if (this.hasElectronApi()) {
6
- // @ts-ignore
7
- window.electronAPI.invokeIpc("openAddWidgetWindow");
8
- }
9
- }
10
-
11
- static async registerWidgets(widgets: Widget[]) {
12
- if (this.hasElectronApi()) {
13
- const data = JSON.parse(JSON.stringify(widgets.map(item => item.stringify())));
14
- // @ts-ignore
15
- await window.electronAPI.invokeIpc("registerWidgets", data);
16
- }
17
- }
18
-
19
- static hasElectronApi(): boolean {
20
- return Reflect.has(window, "electronAPI")
21
- }
22
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./model/Widget";
2
- export * from "./api/ElectronApi";
3
-
@@ -1,85 +0,0 @@
1
- export class Widget {
2
- //组件名称,名称与包名类似,e.g. com.example.countdown
3
- readonly name: string;
4
-
5
- /**
6
- * 组件标题,显示在界面上的,
7
- * https://zh.m.wikipedia.org/zh-hans/ISO_639-1
8
- */
9
- readonly title: Map<string, string>;
10
- /**
11
- * 组件介绍
12
- */
13
- readonly desc: Map<string, string>;
14
- readonly keywords: WidgetKeyword[];
15
- /**
16
- * 组件默认语言
17
- */
18
- readonly lang: string = "zh";
19
- readonly w: number;
20
- readonly h: number;
21
- readonly maxW: number;
22
- readonly maxH: number;
23
- readonly minW: number;
24
- readonly minH: number;
25
- readonly url: string;
26
- //组件配置url
27
- readonly configUrl?: string | null;
28
- readonly debugUrl?: string;
29
-
30
- constructor(name: string, title: Map<string, string>, desc: Map<string, string>, keywords: WidgetKeyword[], lang: string, w: number, h: number, maxW: number, maxH: number, minW: number, minH: number, url: string, configUrl?: string | null, debugUrl?: string) {
31
- this.name = name;
32
- this.title = title;
33
- this.desc = desc;
34
- this.keywords = keywords;
35
- this.lang = lang;
36
- this.w = w;
37
- this.h = h;
38
- this.maxW = maxW;
39
- this.maxH = maxH;
40
- this.minW = minW;
41
- this.minH = minH;
42
- this.url = url;
43
- this.configUrl = configUrl;
44
- this.debugUrl = debugUrl;
45
- }
46
-
47
- /**
48
- * 获取组件标题
49
- * @param lang 语言环境,不传则获取默认语言
50
- */
51
- getTitle(lang?: string): string | undefined {
52
- return lang ? this.title.get(lang) : this.title.get(this.lang);
53
- }
54
-
55
- /**
56
- * 获取组件标描述
57
- * @param lang 语言环境,不传则获取默认标题
58
- */
59
- getDesc(lang?: string): string | undefined {
60
- return lang ? this.desc.get(lang) : this.desc.get(this.lang);
61
- }
62
-
63
- stringify(): string {
64
- const jsonObject = JSON.parse(JSON.stringify(this));
65
- jsonObject["title"] = Object.fromEntries(this.title);
66
- jsonObject["desc"] = Object.fromEntries(this.desc);
67
- return JSON.stringify(jsonObject);
68
- }
69
- }
70
-
71
-
72
- export enum WidgetKeyword {
73
- RECOMMEND = "recommend",
74
- TOOLS = "tools",
75
- EFFICIENCY = "efficiency",
76
- PICTURE = "picture",
77
- LIFE = "life",
78
- SHORTCUT = "shortcut",
79
- COUNTDOWN = "countdown",
80
- TIMER = "timer",
81
- INFO = "info",
82
- DASHBOARD = "dashboard",
83
- }
84
-
85
-