@widget-js/core 0.7.2 → 0.7.4

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 (137) hide show
  1. package/dist/index.cjs +2027 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.ts +1396 -0
  4. package/dist/index.js +1944 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +15 -16
  7. package/dist/cjs/AppPermission.js +0 -8
  8. package/dist/cjs/api/ApiConstants.js +0 -11
  9. package/dist/cjs/api/AppApi.js +0 -51
  10. package/dist/cjs/api/BaseApi.js +0 -13
  11. package/dist/cjs/api/BroadcastApi.js +0 -22
  12. package/dist/cjs/api/BrowserWindowApi.js +0 -144
  13. package/dist/cjs/api/Channel.js +0 -22
  14. package/dist/cjs/api/ClipboardApi.js +0 -23
  15. package/dist/cjs/api/DeviceApi.js +0 -25
  16. package/dist/cjs/api/DialogApi.js +0 -22
  17. package/dist/cjs/api/ElectronApi.js +0 -15
  18. package/dist/cjs/api/FileApi.js +0 -21
  19. package/dist/cjs/api/HostedWidgetApi.js +0 -64
  20. package/dist/cjs/api/LogApi.js +0 -28
  21. package/dist/cjs/api/NotificationApi.js +0 -117
  22. package/dist/cjs/api/ShortcutApi.js +0 -23
  23. package/dist/cjs/api/StoreApi.js +0 -38
  24. package/dist/cjs/api/WidgetApi.js +0 -92
  25. package/dist/cjs/api/WidgetDataApi.js +0 -95
  26. package/dist/cjs/index.js +0 -51
  27. package/dist/cjs/lang/LanguageCode.js +0 -34
  28. package/dist/cjs/model/AppNotification.js +0 -33
  29. package/dist/cjs/model/BrowserWindowStatus.js +0 -11
  30. package/dist/cjs/model/HostedMode.js +0 -18
  31. package/dist/cjs/model/HostedWidget.js +0 -14
  32. package/dist/cjs/model/SocialInfo.js +0 -10
  33. package/dist/cjs/model/Widget.js +0 -118
  34. package/dist/cjs/model/WidgetData.js +0 -16
  35. package/dist/cjs/model/WidgetPackage.js +0 -98
  36. package/dist/cjs/model/WidgetParams.js +0 -151
  37. package/dist/cjs/model/event/AppMouseEvent.js +0 -2
  38. package/dist/cjs/model/event/BroadcastEvent.js +0 -11
  39. package/dist/cjs/model/event/NativeKeyboardEvent.js +0 -2
  40. package/dist/cjs/model/event/WebSocketEvent.js +0 -14
  41. package/dist/cjs/model/interface/IHostedWidget.js +0 -2
  42. package/dist/cjs/model/interface/Rectangle.js +0 -2
  43. package/dist/cjs/model/msic/graphics.js +0 -10
  44. package/dist/cjs/permission/permission.js +0 -2
  45. package/dist/cjs/router/encoding.js +0 -144
  46. package/dist/cjs/router/query.js +0 -84
  47. package/dist/cjs/utils/ElectronUtils.js +0 -32
  48. package/dist/cjs/utils/LanguageUtils.js +0 -36
  49. package/dist/cjs/utils/UrlUtils.js +0 -36
  50. package/dist/esm/AppPermission.js +0 -5
  51. package/dist/esm/api/ApiConstants.js +0 -7
  52. package/dist/esm/api/AppApi.js +0 -47
  53. package/dist/esm/api/BaseApi.js +0 -9
  54. package/dist/esm/api/BroadcastApi.js +0 -18
  55. package/dist/esm/api/BrowserWindowApi.js +0 -139
  56. package/dist/esm/api/Channel.js +0 -19
  57. package/dist/esm/api/ClipboardApi.js +0 -19
  58. package/dist/esm/api/DeviceApi.js +0 -21
  59. package/dist/esm/api/DialogApi.js +0 -19
  60. package/dist/esm/api/ElectronApi.js +0 -11
  61. package/dist/esm/api/FileApi.js +0 -18
  62. package/dist/esm/api/HostedWidgetApi.js +0 -60
  63. package/dist/esm/api/LogApi.js +0 -25
  64. package/dist/esm/api/NotificationApi.js +0 -113
  65. package/dist/esm/api/ShortcutApi.js +0 -19
  66. package/dist/esm/api/StoreApi.js +0 -35
  67. package/dist/esm/api/WidgetApi.js +0 -88
  68. package/dist/esm/api/WidgetDataApi.js +0 -88
  69. package/dist/esm/index.js +0 -35
  70. package/dist/esm/lang/LanguageCode.js +0 -33
  71. package/dist/esm/model/AppNotification.js +0 -29
  72. package/dist/esm/model/BrowserWindowStatus.js +0 -8
  73. package/dist/esm/model/HostedMode.js +0 -15
  74. package/dist/esm/model/HostedWidget.js +0 -10
  75. package/dist/esm/model/SocialInfo.js +0 -6
  76. package/dist/esm/model/Widget.js +0 -114
  77. package/dist/esm/model/WidgetData.js +0 -12
  78. package/dist/esm/model/WidgetPackage.js +0 -94
  79. package/dist/esm/model/WidgetParams.js +0 -147
  80. package/dist/esm/model/event/AppMouseEvent.js +0 -1
  81. package/dist/esm/model/event/BroadcastEvent.js +0 -7
  82. package/dist/esm/model/event/NativeKeyboardEvent.js +0 -1
  83. package/dist/esm/model/event/WebSocketEvent.js +0 -10
  84. package/dist/esm/model/interface/IHostedWidget.js +0 -1
  85. package/dist/esm/model/interface/Rectangle.js +0 -1
  86. package/dist/esm/model/msic/graphics.js +0 -7
  87. package/dist/esm/permission/permission.js +0 -1
  88. package/dist/esm/router/encoding.js +0 -135
  89. package/dist/esm/router/query.js +0 -79
  90. package/dist/esm/utils/ElectronUtils.js +0 -28
  91. package/dist/esm/utils/LanguageUtils.js +0 -32
  92. package/dist/esm/utils/UrlUtils.js +0 -32
  93. package/dist/types/AppPermission.d.ts +0 -4
  94. package/dist/types/api/ApiConstants.d.ts +0 -7
  95. package/dist/types/api/AppApi.d.ts +0 -29
  96. package/dist/types/api/BaseApi.d.ts +0 -5
  97. package/dist/types/api/BroadcastApi.d.ts +0 -21
  98. package/dist/types/api/BrowserWindowApi.d.ts +0 -111
  99. package/dist/types/api/Channel.d.ts +0 -18
  100. package/dist/types/api/ClipboardApi.d.ts +0 -10
  101. package/dist/types/api/DeviceApi.d.ts +0 -20
  102. package/dist/types/api/DialogApi.d.ts +0 -7
  103. package/dist/types/api/ElectronApi.d.ts +0 -4
  104. package/dist/types/api/FileApi.d.ts +0 -13
  105. package/dist/types/api/HostedWidgetApi.d.ts +0 -55
  106. package/dist/types/api/LogApi.d.ts +0 -9
  107. package/dist/types/api/NotificationApi.d.ts +0 -38
  108. package/dist/types/api/ShortcutApi.d.ts +0 -10
  109. package/dist/types/api/StoreApi.d.ts +0 -10
  110. package/dist/types/api/WidgetApi.d.ts +0 -48
  111. package/dist/types/api/WidgetDataApi.d.ts +0 -44
  112. package/dist/types/index.d.ts +0 -35
  113. package/dist/types/lang/LanguageCode.d.ts +0 -40
  114. package/dist/types/model/AppNotification.d.ts +0 -50
  115. package/dist/types/model/BrowserWindowStatus.d.ts +0 -9
  116. package/dist/types/model/HostedMode.d.ts +0 -14
  117. package/dist/types/model/HostedWidget.d.ts +0 -13
  118. package/dist/types/model/SocialInfo.d.ts +0 -6
  119. package/dist/types/model/Widget.d.ts +0 -136
  120. package/dist/types/model/WidgetData.d.ts +0 -35
  121. package/dist/types/model/WidgetPackage.d.ts +0 -101
  122. package/dist/types/model/WidgetParams.d.ts +0 -61
  123. package/dist/types/model/event/AppMouseEvent.d.ts +0 -14
  124. package/dist/types/model/event/BroadcastEvent.d.ts +0 -21
  125. package/dist/types/model/event/NativeKeyboardEvent.d.ts +0 -6
  126. package/dist/types/model/event/WebSocketEvent.d.ts +0 -8
  127. package/dist/types/model/interface/IHostedWidget.d.ts +0 -13
  128. package/dist/types/model/interface/Rectangle.d.ts +0 -18
  129. package/dist/types/model/msic/graphics.d.ts +0 -14
  130. package/dist/types/permission/permission.d.ts +0 -1
  131. package/dist/types/router/encoding.d.ts +0 -62
  132. package/dist/types/router/query.d.ts +0 -53
  133. package/dist/types/utils/ElectronUtils.d.ts +0 -10
  134. package/dist/types/utils/LanguageUtils.d.ts +0 -8
  135. package/dist/types/utils/UrlUtils.d.ts +0 -6
  136. package/dist/umd/index.js +0 -2
  137. package/dist/umd/index.js.LICENSE.txt +0 -6
package/dist/index.cjs ADDED
@@ -0,0 +1,2027 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => {
31
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ return value;
33
+ };
34
+
35
+ // src/index.ts
36
+ var src_exports = {};
37
+ __export(src_exports, {
38
+ ApiConstants: () => ApiConstants,
39
+ AppApi: () => AppApi,
40
+ AppApiConstants: () => AppApiConstants,
41
+ AppApiEvent: () => AppApiEvent,
42
+ AppNotification: () => AppNotification,
43
+ BaseApi: () => BaseApi,
44
+ BroadcastApi: () => BroadcastApi,
45
+ BroadcastEvent: () => BroadcastEvent,
46
+ BrowserWindowApi: () => BrowserWindowApi,
47
+ BrowserWindowApiEvent: () => BrowserWindowApiEvent,
48
+ Channel: () => Channel,
49
+ ClipboardApi: () => ClipboardApi,
50
+ ClipboardApiEvent: () => ClipboardApiEvent,
51
+ DeployMode: () => DeployMode,
52
+ DeployedPage: () => DeployedPage,
53
+ DeployedWidget: () => DeployedWidget,
54
+ DeployedWidgetApi: () => DeployedWidgetApi,
55
+ DeviceApi: () => DeviceApi,
56
+ DialogApi: () => DialogApi,
57
+ ElectronApi: () => ElectronApi,
58
+ ElectronUtils: () => ElectronUtils,
59
+ FileApi: () => FileApi,
60
+ Gravity: () => Gravity,
61
+ GridRect: () => GridRect,
62
+ GridSystem: () => GridSystem,
63
+ HostedMode: () => HostedMode,
64
+ LogApi: () => LogApi,
65
+ NotificationApi: () => NotificationApi,
66
+ NotificationApiEvent: () => NotificationApiEvent,
67
+ NotificationSize: () => NotificationSize,
68
+ Page: () => Page,
69
+ ShortcutApi: () => ShortcutApi,
70
+ ShortcutApiEvent: () => ShortcutApiEvent,
71
+ StoreApi: () => StoreApi,
72
+ ThemeMode: () => ThemeMode,
73
+ WebSocketEvent: () => WebSocketEvent,
74
+ WebSocketEventType: () => WebSocketEventType,
75
+ Widget: () => Widget,
76
+ WidgetApi: () => WidgetApi,
77
+ WidgetApiEvent: () => WidgetApiEvent,
78
+ WidgetData: () => WidgetData,
79
+ WidgetDataApi: () => WidgetDataApi,
80
+ WidgetKeyword: () => WidgetKeyword,
81
+ WidgetPackage: () => WidgetPackage,
82
+ WidgetParams: () => WidgetParams,
83
+ WidgetUrlUtils: () => WidgetUrlUtils,
84
+ normalizeUrl: () => normalizeUrl,
85
+ parseQuery: () => parseQuery,
86
+ stringifyQuery: () => stringifyQuery
87
+ });
88
+ module.exports = __toCommonJS(src_exports);
89
+
90
+ // src/model/DeployMode.ts
91
+ var HostedMode = /* @__PURE__ */ ((HostedMode2) => {
92
+ HostedMode2[HostedMode2["NORMAL"] = 1] = "NORMAL";
93
+ HostedMode2[HostedMode2["OVERLAP"] = 16] = "OVERLAP";
94
+ HostedMode2[HostedMode2["WALLPAPER"] = 256] = "WALLPAPER";
95
+ HostedMode2[HostedMode2["SCREEN"] = 4096] = "SCREEN";
96
+ HostedMode2[HostedMode2["BACKGROUND"] = 65536] = "BACKGROUND";
97
+ HostedMode2[HostedMode2["PAGE"] = 1048576] = "PAGE";
98
+ HostedMode2[HostedMode2["ALL"] = 1118481] = "ALL";
99
+ return HostedMode2;
100
+ })(HostedMode || {});
101
+ var DeployMode = /* @__PURE__ */ ((DeployMode2) => {
102
+ DeployMode2[DeployMode2["NORMAL"] = 1] = "NORMAL";
103
+ DeployMode2[DeployMode2["OVERLAP"] = 16] = "OVERLAP";
104
+ DeployMode2[DeployMode2["BACKGROUND"] = 65536] = "BACKGROUND";
105
+ DeployMode2[DeployMode2["ALL"] = 1118481] = "ALL";
106
+ return DeployMode2;
107
+ })(DeployMode || {});
108
+
109
+ // src/utils/LanguageUtils.ts
110
+ function getTextByLanguageCode(langMap, langCode, fallbackToBrowser = true) {
111
+ let result;
112
+ if (langCode) {
113
+ if (langCode in langMap) {
114
+ return langMap[langCode];
115
+ }
116
+ }
117
+ if (result == void 0 && fallbackToBrowser) {
118
+ if (typeof navigator != "undefined" && navigator.languages) {
119
+ const langCode2 = navigator.language;
120
+ result = getTextByLanguageCode(langMap, langCode2, false);
121
+ if (result != void 0) {
122
+ return result;
123
+ }
124
+ }
125
+ }
126
+ if (result == void 0) {
127
+ let langCode2 = Object.keys(langMap);
128
+ if (langCode2.length > 0) {
129
+ return langMap[langCode2[0]];
130
+ }
131
+ }
132
+ return void 0;
133
+ }
134
+
135
+ // src/model/Page.ts
136
+ var Page = class {
137
+ //窗口名称,名称与包名类似,e.g. com.example.countdown
138
+ name;
139
+ /**
140
+ * 窗口标题,显示在界面上的,
141
+ * https://zh.m.wikipedia.org/zh-hans/ISO_639-1
142
+ */
143
+ title;
144
+ /**
145
+ * 窗口介绍
146
+ */
147
+ description;
148
+ keywords;
149
+ /**
150
+ * 组件默认语言
151
+ */
152
+ lang;
153
+ width;
154
+ packageName;
155
+ height;
156
+ maxWidth;
157
+ maxHeight;
158
+ minWidth;
159
+ minHeight;
160
+ movable;
161
+ singleton;
162
+ resizable;
163
+ path;
164
+ meta;
165
+ backgroundThrottling;
166
+ /**
167
+ * 预览图片,可以是GIF
168
+ */
169
+ previewImage;
170
+ constructor(options) {
171
+ this.name = options.name;
172
+ this.title = options.title;
173
+ this.description = options.description;
174
+ this.keywords = options.keywords;
175
+ this.lang = options.lang;
176
+ this.width = options.width;
177
+ this.height = options.height;
178
+ this.movable = options.movable ?? true;
179
+ this.resizable = options.resizable ?? true;
180
+ this.maxWidth = options.maxWidth ?? options.width;
181
+ this.maxHeight = options.maxHeight ?? options.height;
182
+ this.minWidth = options.minWidth ?? options.width;
183
+ this.minHeight = options.minHeight ?? options.height;
184
+ this.backgroundThrottling = options.backgroundThrottling ?? true;
185
+ this.packageName = options.packageName;
186
+ this.singleton = options.singleton ?? false;
187
+ this.previewImage = options.previewImage;
188
+ this.path = options.path;
189
+ this.meta = options.meta ?? {};
190
+ }
191
+ /**
192
+ * 获取组件标题
193
+ * @param lang 语言环境,不传则获取默认语言
194
+ */
195
+ getTitle(lang) {
196
+ return getTextByLanguageCode(this.title, lang);
197
+ }
198
+ /**
199
+ * 获取组件描述
200
+ * @param lang 语言环境,不传则获取默认标题
201
+ */
202
+ getDescription(lang) {
203
+ return getTextByLanguageCode(this.description, lang);
204
+ }
205
+ static parseJSON(json) {
206
+ const object = JSON.parse(json);
207
+ return this.parseObject(object);
208
+ }
209
+ static parseObject(obj) {
210
+ let widget = new Page({
211
+ path: "",
212
+ description: {},
213
+ height: 0,
214
+ keywords: [],
215
+ lang: "zh-CN",
216
+ name: "",
217
+ previewImage: "",
218
+ title: {},
219
+ width: 0
220
+ });
221
+ Object.assign(widget, obj);
222
+ return widget;
223
+ }
224
+ isResizable() {
225
+ return this.resizable || !(this.minWidth == this.width && this.maxWidth == this.width && this.minHeight == this.height && this.maxHeight == this.height);
226
+ }
227
+ };
228
+
229
+ // src/model/Widget.ts
230
+ var Widget = class extends Page {
231
+ supportDeployMode;
232
+ /**
233
+ * 配置页面路径,没有则不能修改
234
+ */
235
+ configPagePath;
236
+ constructor(options) {
237
+ super(options);
238
+ this.configPagePath = options.configPagePath;
239
+ this.supportDeployMode = options.supportDeployMode ?? 1 /* NORMAL */ | 16 /* OVERLAP */;
240
+ }
241
+ static parseJSON(json) {
242
+ const object = JSON.parse(json);
243
+ return this.parseObject(object);
244
+ }
245
+ static parseObject(obj) {
246
+ let widget = new Widget({
247
+ path: "",
248
+ description: {},
249
+ height: 0,
250
+ keywords: [],
251
+ lang: "zh-CN",
252
+ name: "",
253
+ previewImage: "",
254
+ title: {},
255
+ width: 0
256
+ });
257
+ Object.assign(widget, obj);
258
+ return widget;
259
+ }
260
+ /**
261
+ * 是否支持悬浮窗
262
+ */
263
+ isSupportOverlap() {
264
+ return (this.supportDeployMode & 16 /* OVERLAP */) > 0;
265
+ }
266
+ isSupportBackground() {
267
+ return (this.supportDeployMode & 65536 /* BACKGROUND */) > 0;
268
+ }
269
+ /**
270
+ * 是否支持普通模式
271
+ */
272
+ isSupportNormal() {
273
+ return (this.supportDeployMode & 1 /* NORMAL */) > 0;
274
+ }
275
+ };
276
+ var WidgetKeyword = /* @__PURE__ */ ((WidgetKeyword2) => {
277
+ WidgetKeyword2["RECOMMEND"] = "recommend";
278
+ WidgetKeyword2["TOOLS"] = "tools";
279
+ WidgetKeyword2["EFFICIENCY"] = "efficiency";
280
+ WidgetKeyword2["PICTURE"] = "picture";
281
+ WidgetKeyword2["LIFE"] = "life";
282
+ WidgetKeyword2["SHORTCUT"] = "shortcut";
283
+ WidgetKeyword2["COUNTDOWN"] = "countdown";
284
+ WidgetKeyword2["TIMER"] = "timer";
285
+ WidgetKeyword2["INFO"] = "info";
286
+ WidgetKeyword2["DASHBOARD"] = "dashboard";
287
+ return WidgetKeyword2;
288
+ })(WidgetKeyword || {});
289
+
290
+ // src/model/event/BroadcastEvent.ts
291
+ var BroadcastEvent = class {
292
+ event;
293
+ sender;
294
+ payload;
295
+ constructor(options) {
296
+ this.event = options.event;
297
+ this.sender = options.sender;
298
+ this.payload = options.payload;
299
+ }
300
+ };
301
+
302
+ // src/model/event/WebSocketEvent.ts
303
+ var WebSocketEventType = /* @__PURE__ */ ((WebSocketEventType2) => {
304
+ WebSocketEventType2["RESISTER_PACKAGE"] = "ws::cn.widgetjs.core.resister_package";
305
+ return WebSocketEventType2;
306
+ })(WebSocketEventType || {});
307
+ var WebSocketEvent = class {
308
+ //类型
309
+ type;
310
+ payload;
311
+ constructor(type, payload) {
312
+ this.type = type;
313
+ this.payload = payload;
314
+ }
315
+ };
316
+
317
+ // src/model/WidgetData.ts
318
+ var WidgetData = class {
319
+ /**
320
+ * 组件id
321
+ */
322
+ id;
323
+ /**
324
+ * 组件名
325
+ */
326
+ name;
327
+ /**
328
+ * 背景颜色
329
+ */
330
+ backgroundColor;
331
+ /**
332
+ * 文字颜色
333
+ */
334
+ color;
335
+ /**
336
+ * 字体大小
337
+ */
338
+ fontSize;
339
+ /**
340
+ * 字体
341
+ */
342
+ fontFamily;
343
+ /**
344
+ * 圆角半径
345
+ */
346
+ borderRadius;
347
+ constructor(name, id) {
348
+ this.id = id;
349
+ this.name = name;
350
+ }
351
+ parseJSON(json) {
352
+ Object.assign(this, json);
353
+ }
354
+ };
355
+
356
+ // src/router/encoding.ts
357
+ var HASH_RE = /#/g;
358
+ var AMPERSAND_RE = /&/g;
359
+ var EQUAL_RE = /=/g;
360
+ var PLUS_RE = /\+/g;
361
+ var ENC_BRACKET_OPEN_RE = /%5B/g;
362
+ var ENC_BRACKET_CLOSE_RE = /%5D/g;
363
+ var ENC_CARET_RE = /%5E/g;
364
+ var ENC_BACKTICK_RE = /%60/g;
365
+ var ENC_CURLY_OPEN_RE = /%7B/g;
366
+ var ENC_PIPE_RE = /%7C/g;
367
+ var ENC_CURLY_CLOSE_RE = /%7D/g;
368
+ var ENC_SPACE_RE = /%20/g;
369
+ function commonEncode(text) {
370
+ return encodeURI("" + text).replace(ENC_PIPE_RE, "|").replace(ENC_BRACKET_OPEN_RE, "[").replace(ENC_BRACKET_CLOSE_RE, "]");
371
+ }
372
+ function encodeQueryValue(text) {
373
+ return commonEncode(text).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
374
+ }
375
+ function encodeQueryKey(text) {
376
+ return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
377
+ }
378
+ function decode(text) {
379
+ try {
380
+ return decodeURIComponent("" + text);
381
+ } catch (err) {
382
+ }
383
+ return "" + text;
384
+ }
385
+
386
+ // src/router/query.ts
387
+ var isArray = Array.isArray;
388
+ function parseQuery(search) {
389
+ const query = {};
390
+ if (search === "" || search === "?")
391
+ return query;
392
+ const hasLeadingIM = search[0] === "?";
393
+ const searchParams = (hasLeadingIM ? search.slice(1) : search).split("&");
394
+ for (let i = 0; i < searchParams.length; ++i) {
395
+ const searchParam = searchParams[i].replace(PLUS_RE, " ");
396
+ const eqPos = searchParam.indexOf("=");
397
+ const key = decode(eqPos < 0 ? searchParam : searchParam.slice(0, eqPos));
398
+ const value = eqPos < 0 ? null : decode(searchParam.slice(eqPos + 1));
399
+ if (key in query) {
400
+ let currentValue = query[key];
401
+ if (!isArray(currentValue)) {
402
+ currentValue = query[key] = [currentValue];
403
+ }
404
+ ;
405
+ currentValue.push(value);
406
+ } else {
407
+ query[key] = value;
408
+ }
409
+ }
410
+ return query;
411
+ }
412
+ function stringifyQuery(query) {
413
+ let search = "";
414
+ for (let key in query) {
415
+ const value = query[key];
416
+ key = encodeQueryKey(key);
417
+ if (value == null) {
418
+ if (value !== void 0) {
419
+ search += (search.length ? "&" : "") + key;
420
+ }
421
+ continue;
422
+ }
423
+ const values = isArray(value) ? value.map((v) => v && encodeQueryValue(v)) : [value && encodeQueryValue(value)];
424
+ values.forEach((value2) => {
425
+ if (value2 !== void 0) {
426
+ search += (search.length ? "&" : "") + key;
427
+ if (value2 != null)
428
+ search += "=" + value2;
429
+ }
430
+ });
431
+ }
432
+ return search;
433
+ }
434
+
435
+ // src/model/WidgetParams.ts
436
+ var import_change_case = require("change-case");
437
+ var _WidgetParams = class {
438
+ //组件id
439
+ id;
440
+ //网格宽度,1就代表宽度占用1格
441
+ width;
442
+ //宽度,单位px
443
+ widthPx;
444
+ //宽度,单位px
445
+ heightPx;
446
+ //网格高度,2就代表高度占用2格
447
+ height;
448
+ x;
449
+ y;
450
+ //是否是预览模式,添加组件时,预览状态
451
+ preview;
452
+ //语言环境:zh,en,jp...
453
+ lang;
454
+ //主题:浅色,深色
455
+ theme;
456
+ //
457
+ mode;
458
+ //系统设置的组件圆角半径
459
+ radius;
460
+ //组件名
461
+ name;
462
+ title;
463
+ /**
464
+ * 将组件参数转为url参数
465
+ * @param object
466
+ * @return URLSearchParams w_w=2&w_h=2&w_id=21&w_width=156&w_height=156
467
+ */
468
+ toUrlParams() {
469
+ const urlParams = new URLSearchParams();
470
+ const ownPropertyNames = Object.getOwnPropertyNames(this);
471
+ for (let ownPropertyName of ownPropertyNames) {
472
+ const key = ownPropertyName;
473
+ const value = this[key];
474
+ if (value) {
475
+ urlParams.append(_WidgetParams.PARAM_PREFIX + (0, import_change_case.snakeCase)(ownPropertyName), value.toString());
476
+ }
477
+ }
478
+ return urlParams;
479
+ }
480
+ getPersistKey() {
481
+ return `${this.name}-${this.id}`;
482
+ }
483
+ /**
484
+ * 从当前地址解析组件参数:
485
+ * http://localhost:8080/#/widget/config/labor_progress?w_w=2&w_h=2&w_width=156&w_height=156
486
+ * =>
487
+ * {width:2,height:2,id:21,width_px:156,height_px:156}
488
+ */
489
+ static fromCurrentLocation() {
490
+ const href = window.location.href;
491
+ let strings = href.split("?");
492
+ if (strings.length > 1) {
493
+ let queryString = strings[1];
494
+ return this.fromObject(parseQuery(queryString));
495
+ }
496
+ return new _WidgetParams();
497
+ }
498
+ static fromLocation(url) {
499
+ let strings = url.split("?");
500
+ if (strings.length > 1) {
501
+ let queryString = strings[1];
502
+ return this.fromObject(parseQuery(queryString));
503
+ }
504
+ return new _WidgetParams();
505
+ }
506
+ static setValue(widgetEnv, key, value) {
507
+ const keyWithoutPrefix = key.replace(this.PARAM_PREFIX, "");
508
+ if (keyWithoutPrefix == _WidgetParams.PARAM_ID) {
509
+ widgetEnv.id = value;
510
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_X) {
511
+ widgetEnv.x = parseInt(value);
512
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_Y) {
513
+ widgetEnv.y = parseInt(value);
514
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_HEIGHT) {
515
+ widgetEnv.height = parseInt(value);
516
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_WIDTH) {
517
+ widgetEnv.width = parseInt(value);
518
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_LANG) {
519
+ widgetEnv.lang = value;
520
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_THEME) {
521
+ widgetEnv.theme = value;
522
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_MODE) {
523
+ widgetEnv.mode = parseInt(value);
524
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_RADIUS) {
525
+ widgetEnv.radius = parseInt(value);
526
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_WIDTH_PX) {
527
+ widgetEnv.widthPx = parseInt(value);
528
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_HEIGHT_PX) {
529
+ widgetEnv.heightPx = parseInt(value);
530
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_NAME) {
531
+ widgetEnv.name = value;
532
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_TITLE) {
533
+ widgetEnv.title = value;
534
+ } else if (keyWithoutPrefix == _WidgetParams.PARAM_PREVIEW) {
535
+ widgetEnv.preview = value === "true";
536
+ }
537
+ }
538
+ /**
539
+ * 从对象键值对中初始化组件参数
540
+ * {w_width:2,w_height:2,w_id:21,w_width_px:156,w_height_px:156}=>
541
+ * {width:2,height:2,id:21,width_px:156,height_px:156}
542
+ * @param object
543
+ */
544
+ static fromObject(object) {
545
+ const widgetEnv = new _WidgetParams();
546
+ const ownPropertyNames = Object.getOwnPropertyNames(object);
547
+ for (let ownPropertyName of ownPropertyNames) {
548
+ const key = ownPropertyName;
549
+ const value = object[key];
550
+ this.setValue(widgetEnv, key, value);
551
+ }
552
+ return widgetEnv;
553
+ }
554
+ };
555
+ var WidgetParams = _WidgetParams;
556
+ __publicField(WidgetParams, "PARAM_PREFIX", "w_");
557
+ __publicField(WidgetParams, "PARAM_ID", "id");
558
+ __publicField(WidgetParams, "PARAM_WIDTH", "width");
559
+ __publicField(WidgetParams, "PARAM_HEIGHT", "height");
560
+ __publicField(WidgetParams, "PARAM_WIDTH_PX", "width_px");
561
+ __publicField(WidgetParams, "PARAM_HEIGHT_PX", "height_px");
562
+ __publicField(WidgetParams, "PARAM_X", "x");
563
+ __publicField(WidgetParams, "PARAM_Y", "y");
564
+ __publicField(WidgetParams, "PARAM_LANG", "lang");
565
+ __publicField(WidgetParams, "PARAM_THEME", "theme");
566
+ __publicField(WidgetParams, "PARAM_MODE", "mode");
567
+ __publicField(WidgetParams, "PARAM_RADIUS", "radius");
568
+ __publicField(WidgetParams, "PARAM_NAME", "name");
569
+ __publicField(WidgetParams, "PARAM_TITLE", "title");
570
+ __publicField(WidgetParams, "PARAM_PREVIEW", "preview");
571
+ __publicField(WidgetParams, "PARAMS", [
572
+ _WidgetParams.PARAM_ID,
573
+ _WidgetParams.PARAM_WIDTH,
574
+ _WidgetParams.PARAM_HEIGHT,
575
+ _WidgetParams.PARAM_X,
576
+ _WidgetParams.PARAM_Y,
577
+ _WidgetParams.PARAM_LANG,
578
+ _WidgetParams.PARAM_THEME,
579
+ _WidgetParams.PARAM_MODE,
580
+ _WidgetParams.PARAM_WIDTH_PX,
581
+ _WidgetParams.PARAM_HEIGHT_PX,
582
+ _WidgetParams.PARAM_NAME,
583
+ _WidgetParams.PARAM_TITLE,
584
+ _WidgetParams.PARAM_PREVIEW
585
+ ]);
586
+ var ThemeMode = /* @__PURE__ */ ((ThemeMode2) => {
587
+ ThemeMode2["AUTO"] = "auto";
588
+ ThemeMode2["LIGHT"] = "LIGHT";
589
+ ThemeMode2["DARK"] = "DARK";
590
+ return ThemeMode2;
591
+ })(ThemeMode || {});
592
+
593
+ // src/model/AppNotification.ts
594
+ var NotificationSize = /* @__PURE__ */ ((NotificationSize2) => {
595
+ NotificationSize2["SMALL"] = "small";
596
+ NotificationSize2["NORMAL"] = "normal";
597
+ NotificationSize2["LARGE"] = "large";
598
+ return NotificationSize2;
599
+ })(NotificationSize || {});
600
+ var AppNotification = class {
601
+ type = "info";
602
+ message;
603
+ title;
604
+ targetTime;
605
+ duration;
606
+ icon;
607
+ color;
608
+ backgroundColor;
609
+ confirmButtonText;
610
+ cancelButtonText;
611
+ cancelBroadcast;
612
+ confirmBroadcast;
613
+ size;
614
+ url;
615
+ avatar;
616
+ audio;
617
+ lyric;
618
+ createdAt;
619
+ constructor(option) {
620
+ this.createdAt = (/* @__PURE__ */ new Date()).toISOString();
621
+ this.type = option.type ?? "info";
622
+ this.title = option.title;
623
+ this.message = option.message;
624
+ this.targetTime = option.targetTime;
625
+ this.duration = option.duration ?? 5e3;
626
+ this.icon = option.icon;
627
+ this.color = option.color ?? "#5D8AC8";
628
+ this.confirmButtonText = option.confirmButtonText;
629
+ this.cancelButtonText = option.cancelButtonText;
630
+ this.cancelBroadcast = option.cancelBroadcast;
631
+ this.confirmBroadcast = option.confirmBroadcast;
632
+ this.size = option.size ?? "normal" /* NORMAL */;
633
+ this.audio = option.audio;
634
+ this.avatar = option.avatar;
635
+ this.lyric = option.lyric;
636
+ this.backgroundColor = option.backgroundColor ?? "#000000";
637
+ }
638
+ };
639
+
640
+ // src/model/DeployedPage.ts
641
+ var DeployedPage = class {
642
+ name;
643
+ packageName;
644
+ x = 0;
645
+ y = 0;
646
+ height = 600;
647
+ width = 800;
648
+ proxy;
649
+ id;
650
+ };
651
+
652
+ // src/model/DeployedWidget.ts
653
+ var DeployedWidget = class extends DeployedPage {
654
+ shortcut;
655
+ deployMode;
656
+ isOverlap() {
657
+ return (this.deployMode & 16 /* OVERLAP */) > 0;
658
+ }
659
+ };
660
+
661
+ // src/model/msic/graphics.ts
662
+ var Gravity = /* @__PURE__ */ ((Gravity2) => {
663
+ Gravity2["TOP"] = "TOP";
664
+ Gravity2["LEFT"] = "LEFT";
665
+ Gravity2["RIGHT"] = "RIGHT";
666
+ Gravity2["BOTTOM"] = "BOTTOM";
667
+ return Gravity2;
668
+ })(Gravity || {});
669
+
670
+ // src/utils/normalizeUrl.ts
671
+ var DATA_URL_DEFAULT_MIME_TYPE = "text/plain";
672
+ var DATA_URL_DEFAULT_CHARSET = "us-ascii";
673
+ var testParameter = (name, filters) => filters.some((filter) => filter instanceof RegExp ? filter.test(name) : filter === name);
674
+ var supportedProtocols = /* @__PURE__ */ new Set([
675
+ "https:",
676
+ "http:",
677
+ "file:"
678
+ ]);
679
+ var hasCustomProtocol = (urlString) => {
680
+ try {
681
+ const { protocol } = new URL(urlString);
682
+ return protocol.endsWith(":") && !supportedProtocols.has(protocol);
683
+ } catch {
684
+ return false;
685
+ }
686
+ };
687
+ var normalizeDataURL = (urlString, option) => {
688
+ const match = /^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(urlString);
689
+ if (!match) {
690
+ throw new Error(`Invalid URL: ${urlString}`);
691
+ }
692
+ let { type, data, hash } = match.groups;
693
+ const mediaType = type.split(";");
694
+ hash = option.stripHash ? "" : hash;
695
+ let isBase64 = false;
696
+ if (mediaType[mediaType.length - 1] === "base64") {
697
+ mediaType.pop();
698
+ isBase64 = true;
699
+ }
700
+ const mimeType = mediaType.shift()?.toLowerCase() ?? "";
701
+ const attributes = mediaType.map((attribute) => {
702
+ let [key, value = ""] = attribute.split("=").map((item) => item.trim());
703
+ if (key === "charset") {
704
+ value = value.toLowerCase();
705
+ if (value === DATA_URL_DEFAULT_CHARSET) {
706
+ return "";
707
+ }
708
+ }
709
+ return `${key}${value ? `=${value}` : ""}`;
710
+ }).filter(Boolean);
711
+ const normalizedMediaType = [
712
+ ...attributes
713
+ ];
714
+ if (isBase64) {
715
+ normalizedMediaType.push("base64");
716
+ }
717
+ if (normalizedMediaType.length > 0 || mimeType && mimeType !== DATA_URL_DEFAULT_MIME_TYPE) {
718
+ normalizedMediaType.unshift(mimeType);
719
+ }
720
+ return `data:${normalizedMediaType.join(";")},${isBase64 ? data.trim() : data}${hash ? `#${hash}` : ""}`;
721
+ };
722
+ function normalizeUrl(urlString, options) {
723
+ options = {
724
+ defaultProtocol: "http",
725
+ normalizeProtocol: true,
726
+ forceHttp: false,
727
+ forceHttps: false,
728
+ stripAuthentication: true,
729
+ stripHash: false,
730
+ stripTextFragment: true,
731
+ stripWWW: true,
732
+ removeQueryParameters: [/^utm_\w+/i],
733
+ removeTrailingSlash: true,
734
+ removeSingleSlash: true,
735
+ removeDirectoryIndex: false,
736
+ removeExplicitPort: false,
737
+ sortQueryParameters: true,
738
+ ...options
739
+ };
740
+ urlString = urlString.replace("\\\\", "//");
741
+ if (typeof options.defaultProtocol === "string" && !options.defaultProtocol.endsWith(":")) {
742
+ options.defaultProtocol = `${options.defaultProtocol}:`;
743
+ }
744
+ urlString = urlString.trim();
745
+ if (/^data:/i.test(urlString)) {
746
+ return normalizeDataURL(urlString, { stripHash: options.stripHash ?? false });
747
+ }
748
+ if (hasCustomProtocol(urlString)) {
749
+ return urlString;
750
+ }
751
+ const hasRelativeProtocol = urlString.startsWith("//");
752
+ const isRelativeUrl = !hasRelativeProtocol && /^\.*\//.test(urlString);
753
+ if (!isRelativeUrl) {
754
+ urlString = urlString.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, options.defaultProtocol);
755
+ }
756
+ const urlObject = new URL(urlString);
757
+ if (options.forceHttp && options.forceHttps) {
758
+ throw new Error("The `forceHttp` and `forceHttps` options cannot be used together");
759
+ }
760
+ if (options.forceHttp && urlObject.protocol === "https:") {
761
+ urlObject.protocol = "http:";
762
+ }
763
+ if (options.forceHttps && urlObject.protocol === "http:") {
764
+ urlObject.protocol = "https:";
765
+ }
766
+ if (options.stripAuthentication) {
767
+ urlObject.username = "";
768
+ urlObject.password = "";
769
+ }
770
+ if (options.stripHash) {
771
+ urlObject.hash = "";
772
+ } else if (options.stripTextFragment) {
773
+ urlObject.hash = urlObject.hash.replace(/#?:~:text.*?$/i, "");
774
+ }
775
+ if (urlObject.pathname) {
776
+ const protocolRegex = /\b[a-z][a-z\d+\-.]{1,50}:\/\//g;
777
+ let lastIndex = 0;
778
+ let result = "";
779
+ for (; ; ) {
780
+ const match = protocolRegex.exec(urlObject.pathname);
781
+ if (!match) {
782
+ break;
783
+ }
784
+ const protocol = match[0];
785
+ const protocolAtIndex = match.index;
786
+ const intermediate = urlObject.pathname.slice(lastIndex, protocolAtIndex);
787
+ result += intermediate.replace(/\/{2,}/g, "/");
788
+ result += protocol;
789
+ lastIndex = protocolAtIndex + protocol.length;
790
+ }
791
+ const remnant = urlObject.pathname.slice(lastIndex, urlObject.pathname.length);
792
+ result += remnant.replace(/\/{2,}/g, "/");
793
+ urlObject.pathname = result;
794
+ }
795
+ if (urlObject.pathname) {
796
+ try {
797
+ urlObject.pathname = decodeURI(urlObject.pathname);
798
+ } catch {
799
+ }
800
+ }
801
+ if (options.removeDirectoryIndex === true) {
802
+ options.removeDirectoryIndex = [/^index\.[a-z]+$/];
803
+ }
804
+ if (Array.isArray(options.removeDirectoryIndex) && options.removeDirectoryIndex.length > 0) {
805
+ let pathComponents = urlObject.pathname.split("/");
806
+ const lastComponent = pathComponents[pathComponents.length - 1];
807
+ if (testParameter(lastComponent, options.removeDirectoryIndex)) {
808
+ pathComponents = pathComponents.slice(0, -1);
809
+ urlObject.pathname = pathComponents.slice(1).join("/") + "/";
810
+ }
811
+ }
812
+ if (urlObject.hostname) {
813
+ urlObject.hostname = urlObject.hostname.replace(/\.$/, "");
814
+ if (options.stripWWW && /^www\.(?!www\.)[a-z\-\d]{1,63}\.[a-z.\-\d]{2,63}$/.test(urlObject.hostname)) {
815
+ urlObject.hostname = urlObject.hostname.replace(/^www\./, "");
816
+ }
817
+ }
818
+ if (Array.isArray(options.removeQueryParameters)) {
819
+ for (const key of [...urlObject.searchParams.keys()]) {
820
+ if (testParameter(key, options.removeQueryParameters)) {
821
+ urlObject.searchParams.delete(key);
822
+ }
823
+ }
824
+ }
825
+ if (!Array.isArray(options.keepQueryParameters) && options.removeQueryParameters === true) {
826
+ urlObject.search = "";
827
+ }
828
+ if (Array.isArray(options.keepQueryParameters) && options.keepQueryParameters.length > 0) {
829
+ for (const key of [...urlObject.searchParams.keys()]) {
830
+ if (!testParameter(key, options.keepQueryParameters)) {
831
+ urlObject.searchParams.delete(key);
832
+ }
833
+ }
834
+ }
835
+ if (options.sortQueryParameters) {
836
+ urlObject.searchParams.sort();
837
+ try {
838
+ urlObject.search = decodeURIComponent(urlObject.search);
839
+ } catch {
840
+ }
841
+ }
842
+ if (options.removeTrailingSlash) {
843
+ urlObject.pathname = urlObject.pathname.replace(/\/$/, "");
844
+ }
845
+ if (options.removeExplicitPort && urlObject.port) {
846
+ urlObject.port = "";
847
+ }
848
+ const oldUrlString = urlString;
849
+ urlString = urlObject.toString();
850
+ if (!options.removeSingleSlash && urlObject.pathname === "/" && !oldUrlString.endsWith("/") && urlObject.hash === "") {
851
+ urlString = urlString.replace(/\/$/, "");
852
+ }
853
+ if ((options.removeTrailingSlash || urlObject.pathname === "/") && urlObject.hash === "" && options.removeSingleSlash) {
854
+ urlString = urlString.replace(/\/$/, "");
855
+ }
856
+ if (hasRelativeProtocol && !options.normalizeProtocol) {
857
+ urlString = urlString.replace(/^http:\/\//, "//");
858
+ }
859
+ if (options.stripProtocol) {
860
+ urlString = urlString.replace(/^(?:https?:)?\/\//, "");
861
+ }
862
+ return urlString;
863
+ }
864
+
865
+ // src/utils/WidgetUrlUtils.ts
866
+ var WidgetUrlUtils = class {
867
+ static getWidgetUrl(widgetUrl, widgetPackage, widgetParams) {
868
+ let url = "";
869
+ const arr = [];
870
+ if (widgetUrl.startsWith("http")) {
871
+ url = widgetUrl;
872
+ } else {
873
+ url = widgetPackage.getIndexUrl() + widgetUrl;
874
+ }
875
+ arr.push(url);
876
+ if (url.includes("?")) {
877
+ arr.push("&");
878
+ } else {
879
+ arr.push("?");
880
+ }
881
+ arr.push(widgetParams.toUrlParams().toString());
882
+ return normalizeUrl(arr.join("")).replaceAll("//", "/");
883
+ }
884
+ static getWidgetPackageUrl(url, entry, hash) {
885
+ const arr = [url];
886
+ if (url.startsWith("http")) {
887
+ if (hash) {
888
+ arr.push("#");
889
+ }
890
+ } else {
891
+ arr.push(`/${entry}`);
892
+ if (hash) {
893
+ arr.push("#/");
894
+ }
895
+ }
896
+ return normalizeUrl(arr.join("")).replaceAll("//", "/");
897
+ ;
898
+ }
899
+ };
900
+
901
+ // src/model/WidgetPackage.ts
902
+ var WidgetPackage = class {
903
+ /**
904
+ * 组件包名,一般为域名倒写,e.g. com.example
905
+ */
906
+ name;
907
+ /**
908
+ * 组件包版本,可以为空,默认采用package.json里的版本
909
+ * e.g. 1.0.2
910
+ */
911
+ version;
912
+ /**
913
+ * 组件作者署名
914
+ */
915
+ author;
916
+ /**
917
+ * 组件首页
918
+ */
919
+ homepage;
920
+ /**
921
+ * 组件描述
922
+ */
923
+ title;
924
+ /**
925
+ * 组件描述
926
+ */
927
+ description;
928
+ /**
929
+ * 组件入口文件,通常为 index.html
930
+ */
931
+ entry;
932
+ /**
933
+ * 组件包的远程入口地址,
934
+ */
935
+ remoteEntry;
936
+ remotePackage;
937
+ local;
938
+ remote;
939
+ /**
940
+ * 组件包图标
941
+ */
942
+ icon;
943
+ /**
944
+ * Hash路由模式,默认为true
945
+ */
946
+ hash = true;
947
+ /**
948
+ * 可能是网络地址,或者本地路径(解压后的文件夹路径),
949
+ * 网络地址:https://www.bilibili.com
950
+ * 本地地址:file:///C:/Users/neo/Desktop
951
+ * 在测试时。地址通常为: http://127.0.0.1:8080
952
+ */
953
+ url;
954
+ widgets = [];
955
+ pages = [];
956
+ devOptions;
957
+ constructor(options) {
958
+ this.name = options.name;
959
+ this.version = options.version;
960
+ this.author = options.author;
961
+ this.homepage = options.homepage;
962
+ this.title = options.title;
963
+ this.description = options.description;
964
+ this.entry = options.entry ?? "index.html";
965
+ this.remoteEntry = options.remoteEntry;
966
+ this.remotePackage = options.remotePackage;
967
+ this.hash = options.hash;
968
+ this.url = "";
969
+ this.icon = options.icon;
970
+ this.devOptions = options.devOptions;
971
+ this.remote = options.remote;
972
+ if (options.widgets) {
973
+ for (let widget of options.widgets) {
974
+ this.widgets.push(widget);
975
+ }
976
+ }
977
+ }
978
+ static parseJSON(json) {
979
+ const object = JSON.parse(json);
980
+ return this.parseObject(object);
981
+ }
982
+ static parseObject(obj) {
983
+ let widgetPackage = new WidgetPackage({
984
+ author: "",
985
+ description: {
986
+ "zh-CN": ""
987
+ },
988
+ entry: "",
989
+ hash: false,
990
+ homepage: "",
991
+ name: "",
992
+ title: {
993
+ "zh-CN": ""
994
+ },
995
+ version: ""
996
+ });
997
+ Object.assign(widgetPackage, obj);
998
+ const widgets = [];
999
+ if (widgetPackage.widgets) {
1000
+ for (let jsonWidget of widgetPackage.widgets) {
1001
+ let widget = new Widget({
1002
+ previewImage: "",
1003
+ path: "",
1004
+ description: { "zh-CN": "" },
1005
+ height: 0,
1006
+ keywords: [],
1007
+ lang: "zh-CN",
1008
+ name: "",
1009
+ title: { "zh-CN": "" },
1010
+ width: 0
1011
+ });
1012
+ Object.assign(widget, jsonWidget);
1013
+ widgets.push(widget);
1014
+ }
1015
+ }
1016
+ widgetPackage.widgets.splice(0, widgetPackage.widgets.length);
1017
+ widgetPackage.widgets.push(...widgets);
1018
+ return widgetPackage;
1019
+ }
1020
+ /**
1021
+ * 获取组件包标题
1022
+ * @param lang 语言环境,不传则获取默认语言
1023
+ */
1024
+ getTitle(lang) {
1025
+ return getTextByLanguageCode(this.title, lang);
1026
+ }
1027
+ /**
1028
+ * 获取组件包描述
1029
+ * @param lang 语言环境,不传则获取默认标题
1030
+ */
1031
+ getDescription(lang) {
1032
+ return getTextByLanguageCode(this.description, lang);
1033
+ }
1034
+ /**
1035
+ * 获取组件完整路径
1036
+ * 如果url是http链接,直接返回链接
1037
+ * 如果是本地组件:file://链接,则返回 url+entry,
1038
+ * 如果是远程组件:http://链接,则返回 entry,
1039
+ * @example file://C:/users/neo/desktop/index.html#
1040
+ * @example file://C:/users/neo/desktop/index.html#
1041
+ */
1042
+ getIndexUrl(hash) {
1043
+ return WidgetUrlUtils.getWidgetPackageUrl(this.url, this.entry, hash == null ? this.hash : hash);
1044
+ }
1045
+ };
1046
+
1047
+ // src/utils/ElectronUtils.ts
1048
+ var ElectronUtils = class {
1049
+ static hasElectronApi() {
1050
+ return this.getAPI() != null;
1051
+ }
1052
+ /**
1053
+ * 获取ElectronAPI
1054
+ * windows api
1055
+ */
1056
+ static getAPI() {
1057
+ if (Reflect.has(window, "electronAPI")) {
1058
+ return window.electronAPI;
1059
+ } else if (Reflect.has(window.parent, "electronAPI")) {
1060
+ return window.parent.electronAPI;
1061
+ }
1062
+ return null;
1063
+ }
1064
+ static async invokeMethod(channel, method, ...args) {
1065
+ return this.getAPI()?.invoke(channel, method, ...args);
1066
+ }
1067
+ static async invoke(channel, ...args) {
1068
+ return this.getAPI()?.invoke(channel, ...args);
1069
+ }
1070
+ };
1071
+
1072
+ // src/grid/GridSystem.ts
1073
+ var GridRect = class {
1074
+ top;
1075
+ left;
1076
+ width;
1077
+ height;
1078
+ constructor(left, top, width, height) {
1079
+ this.top = top;
1080
+ this.left = left;
1081
+ this.width = width;
1082
+ this.height = height;
1083
+ }
1084
+ get right() {
1085
+ return this.left + this.width;
1086
+ }
1087
+ get bottom() {
1088
+ return this.top + this.height;
1089
+ }
1090
+ };
1091
+ var GridSystem = class extends GridRect {
1092
+ cellSize;
1093
+ horizontalCellCount;
1094
+ verticalCellCount;
1095
+ screenWidth;
1096
+ screenHeight;
1097
+ /**
1098
+ *
1099
+ * @param cellSize
1100
+ * @param padding 至少保留的边距
1101
+ * @param screenWidth
1102
+ * @param screenHeight
1103
+ */
1104
+ constructor(cellSize, padding, screenWidth, screenHeight) {
1105
+ let gridMaxWidth = screenWidth - padding * 2;
1106
+ let gridMaxHeight = screenHeight - padding * 2;
1107
+ let horizontalPadding = gridMaxWidth % cellSize / 2 + padding;
1108
+ let verticalPadding = gridMaxHeight % cellSize / 2 + padding;
1109
+ const horizontalCellCount = Math.floor(gridMaxWidth / cellSize);
1110
+ const verticalCellCount = Math.floor(gridMaxHeight / cellSize);
1111
+ super(horizontalPadding, verticalPadding, horizontalCellCount * cellSize, verticalCellCount * cellSize);
1112
+ this.cellSize = cellSize;
1113
+ this.screenWidth = screenWidth;
1114
+ this.screenHeight = screenHeight;
1115
+ this.horizontalCellCount = horizontalCellCount;
1116
+ this.verticalCellCount = verticalCellCount;
1117
+ }
1118
+ /**
1119
+ * 将坐标对齐到网格上
1120
+ * @param x
1121
+ * @param y
1122
+ */
1123
+ snapPosition(x, y) {
1124
+ let newX = this.getRangeValue(x - this.left, 0, this.width);
1125
+ let newY = this.getRangeValue(y - this.top, 0, this.height);
1126
+ const diffX = newX % this.cellSize;
1127
+ if (diffX >= this.cellSize / 2) {
1128
+ newX = newX + this.cellSize - diffX;
1129
+ } else {
1130
+ newX = newX - diffX;
1131
+ }
1132
+ const diffY = newY % this.cellSize;
1133
+ if (diffY >= this.cellSize / 2) {
1134
+ newY = newY + this.cellSize - diffY;
1135
+ } else {
1136
+ newY = newY - diffY;
1137
+ }
1138
+ return [newX + this.left, newY + this.top];
1139
+ }
1140
+ snapSize(width, height) {
1141
+ let newWidth = Math.floor(width);
1142
+ let newHeight = Math.floor(height);
1143
+ let diffWidth = newWidth % this.cellSize;
1144
+ let diffHeight = newHeight % this.cellSize;
1145
+ if (diffWidth > this.cellSize / 2) {
1146
+ newWidth = width + this.cellSize - diffWidth;
1147
+ } else {
1148
+ newWidth = width - diffWidth;
1149
+ }
1150
+ if (diffHeight > this.cellSize / 2) {
1151
+ newHeight = height + this.cellSize - diffHeight;
1152
+ } else {
1153
+ newHeight = height - diffHeight;
1154
+ }
1155
+ return [newWidth, newHeight];
1156
+ }
1157
+ /**
1158
+ * 将矩形对齐到网格上
1159
+ * @param rect
1160
+ * @param minWidth
1161
+ * @param maxWidth
1162
+ * @param minHeight
1163
+ * @param maxHeight
1164
+ */
1165
+ snapRect(rect, minWidth, maxWidth, minHeight, maxHeight) {
1166
+ let [newX, newY] = this.snapPosition(rect.left, rect.top);
1167
+ let [newWidth, newHeight] = this.snapSize(rect.width, rect.height);
1168
+ newWidth = this.getRangeValue(newWidth, minWidth, maxWidth);
1169
+ newHeight = this.getRangeValue(newHeight, minHeight, maxHeight);
1170
+ if (newX + newWidth > this.right) {
1171
+ newX = this.right - newWidth;
1172
+ }
1173
+ if (newY + newHeight > this.bottom) {
1174
+ newY = this.bottom - newHeight;
1175
+ }
1176
+ return new GridRect(newX, newY, newWidth, newHeight);
1177
+ }
1178
+ getRangeValue(value, min, max) {
1179
+ if (value < min) {
1180
+ return min;
1181
+ }
1182
+ if (value > max) {
1183
+ return max;
1184
+ }
1185
+ return value;
1186
+ }
1187
+ getWidth() {
1188
+ return this.right - this.left;
1189
+ }
1190
+ getHeight() {
1191
+ return this.bottom - this.top;
1192
+ }
1193
+ };
1194
+
1195
+ // src/api/ElectronApi.ts
1196
+ var ElectronApi = class {
1197
+ static async addIpcListener(key, f) {
1198
+ await ElectronUtils.getAPI()?.addIpcListener(key, f);
1199
+ }
1200
+ static async removeIpcListener(key) {
1201
+ await ElectronUtils.getAPI()?.removeIpcListener(key);
1202
+ }
1203
+ };
1204
+
1205
+ // src/api/WidgetDataApi.ts
1206
+ var import_localforage = __toESM(require("localforage"), 1);
1207
+
1208
+ // src/api/Channel.ts
1209
+ var Channel = /* @__PURE__ */ ((Channel2) => {
1210
+ Channel2["NOTIFICATION"] = "channel::cn.widgetjs.core.notification";
1211
+ Channel2["BROWSER_WINDOW"] = "channel::cn.widgetjs.core.browser_window";
1212
+ Channel2["BROADCAST"] = "channel::cn.widgetjs.core.broadcast";
1213
+ Channel2["WIDGET"] = "channel::cn.widgetjs.core.widget";
1214
+ Channel2["HOSTED_WIDGET"] = "channel::cn.widgetjs.core.hosted_widget";
1215
+ Channel2["APP"] = "channel::cn.widgetjs.core.app";
1216
+ Channel2["DIALOG"] = "channel::cn.widgetjs.core.dialog";
1217
+ Channel2["CLIPBOARD"] = "channel::cn.widgetjs.core.clipboard";
1218
+ Channel2["FILE"] = "channel::cn.widgetjs.core.file";
1219
+ Channel2["SCREEN"] = "channel::cn.widgetjs.core.screen";
1220
+ Channel2["SHORTCUT"] = "channel::cn.widgetjs.core.shortcut";
1221
+ Channel2["LOG"] = "channel::cn.widgetjs.core.log";
1222
+ Channel2["DEVICE"] = "channel::cn.widgetjs.core.device";
1223
+ Channel2["MOUSE"] = "channel::cn.widgetjs.core.mouse";
1224
+ Channel2["KEYBOARD"] = "channel::cn.widgetjs.core.keyboard";
1225
+ Channel2["STORE"] = "channel::cn.widgetjs.core.store";
1226
+ return Channel2;
1227
+ })(Channel || {});
1228
+
1229
+ // src/api/BaseApi.ts
1230
+ var BaseApi = class {
1231
+ async invokeMethod(method, ...args) {
1232
+ return await ElectronUtils.invokeMethod(this.getChannel(), method, ...args);
1233
+ }
1234
+ async invoke(...args) {
1235
+ return await ElectronUtils.invoke(this.getChannel(), ...args);
1236
+ }
1237
+ };
1238
+
1239
+ // src/api/BroadcastApi.ts
1240
+ var BroadcastApiImpl = class extends BaseApi {
1241
+ async send(event) {
1242
+ await this.invokeMethod("send", event);
1243
+ }
1244
+ async register(...event) {
1245
+ await this.invokeMethod("register", event);
1246
+ }
1247
+ async unregister(...event) {
1248
+ await this.invokeMethod("unregister", event);
1249
+ }
1250
+ getChannel() {
1251
+ return "channel::cn.widgetjs.core.broadcast" /* BROADCAST */;
1252
+ }
1253
+ };
1254
+ var BroadcastApi = new BroadcastApiImpl();
1255
+
1256
+ // src/api/WidgetApi.ts
1257
+ var WidgetApiEvent = /* @__PURE__ */ ((WidgetApiEvent2) => {
1258
+ WidgetApiEvent2["DATA_CHANGED"] = "event::cn.widgetjs.core.widget.data-changed";
1259
+ WidgetApiEvent2["EDIT_DESKTOP_WIDGETS"] = "event::cn.widgetjs.core.widget.desktop.edit";
1260
+ return WidgetApiEvent2;
1261
+ })(WidgetApiEvent || {});
1262
+ var WidgetApiImpl = class extends BaseApi {
1263
+ getChannel() {
1264
+ return "channel::cn.widgetjs.core.widget" /* WIDGET */;
1265
+ }
1266
+ async registerWidgets(widgets) {
1267
+ return this.invokeMethod("registerWidgets", JSON.stringify(widgets));
1268
+ }
1269
+ async registerWidgetPackage(widgetPackage) {
1270
+ return this.invokeMethod("registerWidgetPackage", JSON.stringify(widgetPackage));
1271
+ }
1272
+ async getWidgets() {
1273
+ const data = await this.invokeMethod("getWidgets");
1274
+ const widgets = [];
1275
+ if (data) {
1276
+ for (const item of data) {
1277
+ widgets.push(Widget.parseObject(item));
1278
+ }
1279
+ }
1280
+ return widgets;
1281
+ }
1282
+ async getWidgetPackages() {
1283
+ return await this.invokeMethod("getWidgetPackages");
1284
+ }
1285
+ /**
1286
+ *
1287
+ * @param name package name
1288
+ */
1289
+ async getWidget(name) {
1290
+ return Widget.parseObject(await this.invokeMethod("getWidget", name));
1291
+ }
1292
+ /**
1293
+ *
1294
+ * @param name package name
1295
+ */
1296
+ async getWidgetPackage(name) {
1297
+ return WidgetPackage.parseObject(await this.invokeMethod("getWidgetPackage", name));
1298
+ }
1299
+ /**
1300
+ * 获取组件配置地址
1301
+ * @param widgetName
1302
+ */
1303
+ async getWidgetConfigUrl(widgetName, widgetParams) {
1304
+ const widget = await this.getWidget(widgetName);
1305
+ if (!widget)
1306
+ return null;
1307
+ const configPagePath = widget.configPagePath;
1308
+ if (!configPagePath)
1309
+ return null;
1310
+ const widgetPackage = await this.getWidgetPackage(widget.packageName);
1311
+ if (!widgetPackage)
1312
+ return null;
1313
+ return WidgetUrlUtils.getWidgetUrl(configPagePath, widgetPackage, widgetParams);
1314
+ }
1315
+ async getWidgetUrl(widgetName, widgetParams) {
1316
+ const widget = await this.getWidget(widgetName);
1317
+ if (!widget)
1318
+ return null;
1319
+ const widgetPackage = await this.getWidgetPackage(widget.packageName);
1320
+ if (!widgetPackage)
1321
+ return null;
1322
+ return WidgetUrlUtils.getWidgetUrl(widget.path, widgetPackage, widgetParams);
1323
+ }
1324
+ async getWidgetPackageIndexUrl(packageName, hash) {
1325
+ const widgetPackage = await this.getWidgetPackage(packageName);
1326
+ if (!widgetPackage)
1327
+ return null;
1328
+ return widgetPackage.getIndexUrl(hash);
1329
+ }
1330
+ async getWidgetPackageUrl(packageName) {
1331
+ const widgetPackage = await this.getWidgetPackage(packageName);
1332
+ if (!widgetPackage)
1333
+ return null;
1334
+ return widgetPackage.url;
1335
+ }
1336
+ // /**
1337
+ // * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
1338
+ // * @param data
1339
+ // * @param options
1340
+ // */
1341
+ // public async saveDataByName<T extends WidgetData>(data: T, options: SaveWidgetOption = {sendBroadcast: true}) {
1342
+ // const store = this.getStore(data.name);
1343
+ // const json = JSON.stringify(data);
1344
+ // const result = await store.setItem(data.name, json);
1345
+ // if (options.sendBroadcast) {
1346
+ // const broadcastEvent = new BroadcastEvent({
1347
+ // event: WidgetApiEvent.DATA_CHANGED,
1348
+ // payload: {
1349
+ // name: data.name,
1350
+ // id: options.id,
1351
+ // json
1352
+ // }
1353
+ // });
1354
+ // await BroadcastApi.send(broadcastEvent);
1355
+ // }
1356
+ // return result;
1357
+ // }
1358
+ //
1359
+ // private stores = new Map<string, LocalForage>()
1360
+ //
1361
+ // /**
1362
+ // * 获取组件 LocalForage 存储实例
1363
+ // * @param name
1364
+ // */
1365
+ // public getStore(name: string): LocalForage {
1366
+ // if (this.stores.has(name)) {
1367
+ // return this.stores.get(name)!
1368
+ // }
1369
+ // const store = localforage.createInstance({name: name});
1370
+ // this.stores.set(name, store);
1371
+ // return store;
1372
+ // }
1373
+ };
1374
+ var WidgetApi = new WidgetApiImpl();
1375
+
1376
+ // src/api/WidgetDataApi.ts
1377
+ var WidgetDataApiImpl = class {
1378
+ stores = /* @__PURE__ */ new Map();
1379
+ /**
1380
+ * 保存组件数据
1381
+ * @param data
1382
+ */
1383
+ async save(data) {
1384
+ let store = this.getStore(data.name);
1385
+ let json = JSON.stringify(data);
1386
+ const result = await store.setItem(this.getKey(data.name, data.id), json);
1387
+ const broadcastEvent = new BroadcastEvent({
1388
+ event: "event::cn.widgetjs.core.widget.data-changed" /* DATA_CHANGED */,
1389
+ payload: { name: data.name, json }
1390
+ });
1391
+ await BroadcastApi.send(broadcastEvent);
1392
+ return result;
1393
+ }
1394
+ /**
1395
+ * 获取组件 LocalForage 存储实例
1396
+ * @param name
1397
+ */
1398
+ getStore(name) {
1399
+ if (this.stores.has(name)) {
1400
+ return this.stores.get(name);
1401
+ }
1402
+ const store = import_localforage.default.createInstance({ name });
1403
+ this.stores.set(name, store);
1404
+ return store;
1405
+ }
1406
+ /**
1407
+ * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
1408
+ * @param data
1409
+ * @param options
1410
+ */
1411
+ async saveByName(data, options = { sendBroadcast: true }) {
1412
+ const store = this.getStore(data.name);
1413
+ const json = JSON.stringify(data);
1414
+ const result = await store.setItem(data.name, json);
1415
+ if (options?.sendBroadcast) {
1416
+ const broadcastEvent = new BroadcastEvent({
1417
+ event: "event::cn.widgetjs.core.widget.data-changed" /* DATA_CHANGED */,
1418
+ payload: { name: data.name, json }
1419
+ });
1420
+ await BroadcastApi.send(broadcastEvent);
1421
+ }
1422
+ return result;
1423
+ }
1424
+ async findByName(...args) {
1425
+ let name = "";
1426
+ let dbStr = "";
1427
+ let data;
1428
+ if (args.length === 2) {
1429
+ name = args[0];
1430
+ const type = args[1];
1431
+ data = new type(name);
1432
+ } else {
1433
+ data = args[0];
1434
+ name = data.name;
1435
+ }
1436
+ let store = this.getStore(name);
1437
+ dbStr = await store.getItem(name);
1438
+ if (dbStr) {
1439
+ data.parseJSON(JSON.parse(dbStr));
1440
+ return data;
1441
+ }
1442
+ return void 0;
1443
+ }
1444
+ async find(name, id, type) {
1445
+ let store = this.getStore(name);
1446
+ let result = await store.getItem(this.getKey(name, id));
1447
+ if (result) {
1448
+ const widgetData = new type(name, id);
1449
+ widgetData.parseJSON(JSON.parse(result));
1450
+ return widgetData;
1451
+ }
1452
+ return void 0;
1453
+ }
1454
+ getKey(name, id) {
1455
+ return `${name}@${id}`;
1456
+ }
1457
+ };
1458
+ var WidgetDataApi = new WidgetDataApiImpl();
1459
+
1460
+ // src/api/BrowserWindowApi.ts
1461
+ var BrowserWindowApiEvent = /* @__PURE__ */ ((BrowserWindowApiEvent2) => {
1462
+ BrowserWindowApiEvent2["BLUR"] = "event::cn.widgetjs.core.browser-window.blur";
1463
+ BrowserWindowApiEvent2["MOVED"] = "event::cn.widgetjs.core.browser-window.moved";
1464
+ BrowserWindowApiEvent2["FOCUS"] = "event::cn.widgetjs.core.browser-window.focus";
1465
+ BrowserWindowApiEvent2["SNAP_TO_EDGE"] = "event::cn.widgetjs.core.browser-window.snap_to_edge";
1466
+ BrowserWindowApiEvent2["RESIZED"] = "event::cn.widgetjs.core.browser-window.resized";
1467
+ BrowserWindowApiEvent2["CANCEL_SNAP_TO_EDGE"] = "event::cn.widgetjs.core.browser-window.cancel_snap_to_edge";
1468
+ return BrowserWindowApiEvent2;
1469
+ })(BrowserWindowApiEvent || {});
1470
+ var BrowserWindowApiImpl = class extends BaseApi {
1471
+ getChannel() {
1472
+ return "channel::cn.widgetjs.core.browser_window" /* BROWSER_WINDOW */;
1473
+ }
1474
+ async setIgnoreMouseEvent(ignore) {
1475
+ await this.invokeMethod("setIgnoreMouseEvent", ignore);
1476
+ }
1477
+ async show() {
1478
+ await this.invokeMethod("show", true);
1479
+ }
1480
+ async showInactive() {
1481
+ await this.invokeMethod("showInactive", true);
1482
+ }
1483
+ async hide() {
1484
+ await this.invokeMethod("hide", false);
1485
+ }
1486
+ async center() {
1487
+ await this.invokeMethod("center", false);
1488
+ }
1489
+ async setAlwaysOnTop(alwaysOnTop) {
1490
+ await this.invokeMethod("setAlwaysOnTop", alwaysOnTop);
1491
+ }
1492
+ async isAlwaysOnTop() {
1493
+ return await this.invokeMethod("isAlwaysOnTop");
1494
+ }
1495
+ async openUrl(url, option) {
1496
+ if (ElectronUtils.hasElectronApi()) {
1497
+ await this.invokeMethod("openUrl", url, option);
1498
+ } else {
1499
+ window.open(url, "_blank");
1500
+ }
1501
+ }
1502
+ async moveTop() {
1503
+ await this.invokeMethod("moveTop");
1504
+ }
1505
+ async openDevTools() {
1506
+ await this.invokeMethod("openDevTools");
1507
+ }
1508
+ async setPosition(options) {
1509
+ await this.invokeMethod("setPosition", options);
1510
+ }
1511
+ async getPosition() {
1512
+ return await this.invokeMethod("getPosition");
1513
+ }
1514
+ async blur() {
1515
+ return await this.invokeMethod("blur");
1516
+ }
1517
+ async focus() {
1518
+ return await this.invokeMethod("focus");
1519
+ }
1520
+ /**
1521
+ * 设置窗口是否可以拉伸
1522
+ * @param resizable
1523
+ */
1524
+ async setResizable(resizable) {
1525
+ return await this.invokeMethod("setResizable", resizable);
1526
+ }
1527
+ async getBounds() {
1528
+ return await this.invokeMethod("getBounds");
1529
+ }
1530
+ async setBounds(bounds, animate) {
1531
+ return await this.invokeMethod("setBounds", bounds, animate);
1532
+ }
1533
+ async alignToScreen(align) {
1534
+ return await this.invokeMethod("alignToScreen", align);
1535
+ }
1536
+ async startDraggingWindow() {
1537
+ return await this.invokeMethod("startDraggingWindow");
1538
+ }
1539
+ async stopDraggingWindow() {
1540
+ return await this.invokeMethod("stopDraggingWindow");
1541
+ }
1542
+ /**
1543
+ * 通过url检测窗口是否存在
1544
+ * @param url
1545
+ */
1546
+ async existsByUrl(url) {
1547
+ return await this.invokeMethod("existsByUrl", url);
1548
+ }
1549
+ async getMaximumSize() {
1550
+ return await this.invokeMethod("getMaximumSize");
1551
+ }
1552
+ async minimize() {
1553
+ return await this.invokeMethod("minimize");
1554
+ }
1555
+ async maximize() {
1556
+ return await this.invokeMethod("maximize");
1557
+ }
1558
+ async isMaximized() {
1559
+ return await this.invokeMethod("isMaximized");
1560
+ }
1561
+ async isMinimized() {
1562
+ return await this.invokeMethod("isMinimized");
1563
+ }
1564
+ async restore() {
1565
+ return await this.invokeMethod("restore");
1566
+ }
1567
+ async unmaximize() {
1568
+ return await this.invokeMethod("unmaximize");
1569
+ }
1570
+ async setZoomLevel(level) {
1571
+ return await this.invokeMethod("setZoomLevel");
1572
+ }
1573
+ async reload() {
1574
+ return await this.invokeMethod("reload");
1575
+ }
1576
+ async setMovable(movable) {
1577
+ return await this.invokeMethod("setMovable", movable);
1578
+ }
1579
+ async setSize(width, height, animate) {
1580
+ return this.invokeMethod("setSize", width, height, animate);
1581
+ }
1582
+ async isFocused() {
1583
+ return this.invokeMethod("isFocused");
1584
+ }
1585
+ async setMaximumSize(width, height) {
1586
+ return this.invokeMethod("setMaximumSize", width, height);
1587
+ }
1588
+ async setMinimumSize(width, height) {
1589
+ return this.invokeMethod("setMinimumSize", width, height);
1590
+ }
1591
+ getMinimumSize() {
1592
+ return this.invokeMethod("getMinimumSize");
1593
+ }
1594
+ };
1595
+ var BrowserWindowApi = new BrowserWindowApiImpl();
1596
+
1597
+ // src/api/NotificationApi.ts
1598
+ var NotificationApiEvent = /* @__PURE__ */ ((NotificationApiEvent2) => {
1599
+ NotificationApiEvent2["CONFIRM"] = "event::cn.widgetjs.core.notification.confirm";
1600
+ NotificationApiEvent2["CANCEL"] = "event::cn.widgetjs.core.notification.cancel";
1601
+ NotificationApiEvent2["HIDE"] = "event::cn.widgetjs.core.notification.hide";
1602
+ return NotificationApiEvent2;
1603
+ })(NotificationApiEvent || {});
1604
+ var NotificationApiImpl = class extends BaseApi {
1605
+ // static async url(url: string, duration: number = -1) {
1606
+ // this.invoke(Channel.NOTIFICATION, new AppNotification({
1607
+ // url, message: "",
1608
+ // duration,
1609
+ // type: "url",
1610
+ // }));
1611
+ // }
1612
+ /**
1613
+ * 来电
1614
+ * @param avatar 头像地址
1615
+ * @param audio 音频地址
1616
+ * @param title 标题文件
1617
+ * @param message 初始消息
1618
+ * @param lyric 歌词字符串
1619
+ */
1620
+ async call(avatar, audio, title, message, lyric) {
1621
+ await this.invoke(new AppNotification({
1622
+ avatar,
1623
+ audio,
1624
+ message,
1625
+ title,
1626
+ duration: -1,
1627
+ lyric,
1628
+ type: "call"
1629
+ }));
1630
+ }
1631
+ async send(notification) {
1632
+ return this.invokeMethod("send", notification);
1633
+ }
1634
+ async reminder(title, message, icon, cancelButtonText, confirmButtonText, cancelBroadcast, confirmBroadcast, duration = 5e3) {
1635
+ return await this.send(new AppNotification({
1636
+ icon,
1637
+ message,
1638
+ title,
1639
+ duration,
1640
+ cancelButtonText,
1641
+ confirmButtonText,
1642
+ cancelBroadcast,
1643
+ confirmBroadcast,
1644
+ type: "reminder"
1645
+ }));
1646
+ }
1647
+ async advanceCountdown(message, targetTime, title) {
1648
+ return await this.send(new AppNotification({
1649
+ title,
1650
+ message,
1651
+ targetTime,
1652
+ type: "advance-countdown"
1653
+ }));
1654
+ }
1655
+ async countdown(message, targetTime) {
1656
+ await this.send(new AppNotification({
1657
+ message,
1658
+ targetTime,
1659
+ backgroundColor: "rgba(0,0,0,0.5)",
1660
+ duration: -1,
1661
+ type: "countdown"
1662
+ }));
1663
+ }
1664
+ async success(message, duration = 5e3) {
1665
+ await this.send(new AppNotification({
1666
+ message,
1667
+ type: "success",
1668
+ icon: "check_circle_line",
1669
+ duration
1670
+ }));
1671
+ }
1672
+ async error(message, duration = 5e3) {
1673
+ await this.send(new AppNotification({
1674
+ message,
1675
+ type: "error",
1676
+ icon: "close_circle_line",
1677
+ duration
1678
+ }));
1679
+ }
1680
+ async warning(message, duration = 5e3) {
1681
+ await this.send(new AppNotification({
1682
+ message,
1683
+ type: "warning",
1684
+ icon: "warning_line",
1685
+ duration
1686
+ }));
1687
+ }
1688
+ async info(message, duration = 5e3) {
1689
+ await this.send(new AppNotification({
1690
+ message,
1691
+ type: "info",
1692
+ icon: "information_line",
1693
+ duration
1694
+ }));
1695
+ }
1696
+ /**
1697
+ * 隐藏通知
1698
+ */
1699
+ async hide() {
1700
+ await this.invokeMethod("hide");
1701
+ }
1702
+ getChannel() {
1703
+ return "channel::cn.widgetjs.core.notification" /* NOTIFICATION */;
1704
+ }
1705
+ };
1706
+ var NotificationApi = new NotificationApiImpl();
1707
+
1708
+ // src/api/HostedWidgetApi.ts
1709
+ var DeployedWidgetApiImpl = class extends BaseApi {
1710
+ getChannel() {
1711
+ return "channel::cn.widgetjs.core.hosted_widget" /* HOSTED_WIDGET */;
1712
+ }
1713
+ /**
1714
+ * 移除组件
1715
+ * @param id
1716
+ */
1717
+ async removeDeployedWidget(id) {
1718
+ return this.invokeMethod("removeDeployedWidget", id);
1719
+ }
1720
+ addWidget(widgetName, hostMode) {
1721
+ return this.invokeMethod("addWidget", widgetName, hostMode);
1722
+ }
1723
+ /**
1724
+ * 通过组件名移除已添加的组件
1725
+ * @param name 组件名
1726
+ */
1727
+ async removeDeployedWidgetByName(name) {
1728
+ return this.invokeMethod("removeDeployedWidgetByName", name);
1729
+ }
1730
+ /**
1731
+ * 获取已添加的组件
1732
+ * @param name 组件名,可以不传
1733
+ */
1734
+ async getDeployedWidgets(name) {
1735
+ return this.invokeMethod("getDeployedWidgets", name);
1736
+ }
1737
+ async getDeployedWidget(id) {
1738
+ return this.invokeMethod("getDeployedWidget", id);
1739
+ }
1740
+ /**
1741
+ * Opens the dev tools for a widget with the specified ID.
1742
+ *
1743
+ * @param {string} widgetId - The ID of the widget to open the dev tools for.
1744
+ * @return {Promise} A Promise that resolves when the dev tools are opened.
1745
+ */
1746
+ async openDevTools(widgetId) {
1747
+ return this.invokeMethod("openDevTools", widgetId);
1748
+ }
1749
+ async openConfigRoute(widgetId, params) {
1750
+ return this.invokeMethod("openConfigRoute", widgetId, params);
1751
+ }
1752
+ /**
1753
+ * 注册激活、呼出、置顶组件快捷键
1754
+ * @param widgetId 组件id
1755
+ * @param shortcut 如果传空或者不传,则会取消快捷键。更多快捷键配置,请查看Accelerator用法
1756
+ * https://www.electronjs.org/docs/latest/api/accelerator
1757
+ */
1758
+ async registerActiveShortcut(widgetId, shortcut) {
1759
+ return this.invokeMethod("registerActiveShortcut", widgetId, shortcut);
1760
+ }
1761
+ async setProxy(widgetId, proxy) {
1762
+ return this.invokeMethod("setProxy", widgetId, proxy);
1763
+ }
1764
+ };
1765
+ var DeployedWidgetApi = new DeployedWidgetApiImpl();
1766
+
1767
+ // src/api/DeviceApi.ts
1768
+ var DeviceApiImpl = class extends BaseApi {
1769
+ /**
1770
+ * 获取当前鼠标位置
1771
+ */
1772
+ async getCursorScreenPoint() {
1773
+ return this.invokeMethod("getCursorScreenPoint");
1774
+ }
1775
+ /**
1776
+ * 判断是否所有按键都已经释放
1777
+ */
1778
+ async isAllKeyReleased() {
1779
+ return this.invokeMethod("isAllKeyReleased");
1780
+ }
1781
+ getChannel() {
1782
+ return "channel::cn.widgetjs.core.device" /* DEVICE */;
1783
+ }
1784
+ };
1785
+ var DeviceApi = new DeviceApiImpl();
1786
+
1787
+ // src/api/ClipboardApi.ts
1788
+ var ClipboardApiEvent = /* @__PURE__ */ ((ClipboardApiEvent2) => {
1789
+ ClipboardApiEvent2["CHANGED"] = "clipboard-changed";
1790
+ return ClipboardApiEvent2;
1791
+ })(ClipboardApiEvent || {});
1792
+ var ClipboardApiImpl = class extends BaseApi {
1793
+ async getSelectedText() {
1794
+ return this.invokeMethod("getSelectedText");
1795
+ }
1796
+ async getText() {
1797
+ return this.invokeMethod("getText");
1798
+ }
1799
+ getChannel() {
1800
+ return "channel::cn.widgetjs.core.clipboard" /* CLIPBOARD */;
1801
+ }
1802
+ };
1803
+ var ClipboardApi = new ClipboardApiImpl();
1804
+
1805
+ // src/api/ApiConstants.ts
1806
+ var ApiConstants = class {
1807
+ };
1808
+ __publicField(ApiConstants, "CONFIG_LAUNCH_AT_STARTUP", "CONFIG_LAUNCH_AT_STARTUP");
1809
+ __publicField(ApiConstants, "CONFIG_WIDGET_TITLE_COLOR", "CONFIG_WIDGET_TITLE_COLOR");
1810
+ __publicField(ApiConstants, "CONFIG_DEBUG_MODE", "cn.widgetjs.config.debug");
1811
+ __publicField(ApiConstants, "CONFIG_GRID_CELL_SIZE", "cn.widgetjs.config.grid.size");
1812
+ __publicField(ApiConstants, "SHORTCUT_PIN_DESKTOP_WIDGETS", "cn.widgetjs.config.shortcut.pin_desktop_widgets");
1813
+
1814
+ // src/api/ShortcutApi.ts
1815
+ var ShortcutApiEvent = /* @__PURE__ */ ((ShortcutApiEvent2) => {
1816
+ ShortcutApiEvent2["TRIGGERED"] = "channel::cn.widgetjs.core.shortcut.triggered";
1817
+ return ShortcutApiEvent2;
1818
+ })(ShortcutApiEvent || {});
1819
+ var ShortcutApiImpl = class extends BaseApi {
1820
+ getChannel() {
1821
+ return "channel::cn.widgetjs.core.shortcut" /* SHORTCUT */;
1822
+ }
1823
+ async register(shortcut) {
1824
+ return await this.invokeMethod("register", shortcut);
1825
+ }
1826
+ async unregister(shortcut) {
1827
+ return await this.invokeMethod("unregister", shortcut);
1828
+ }
1829
+ };
1830
+ var ShortcutApi = new ShortcutApiImpl();
1831
+
1832
+ // src/api/AppApi.ts
1833
+ var AppApiEvent = /* @__PURE__ */ ((AppApiEvent2) => {
1834
+ AppApiEvent2["CONFIG_CHANGED"] = "event::cn.widgetjs.core.app.config.changed";
1835
+ AppApiEvent2["MOVING_GRID_WINDOW"] = "event::cn.widgetjs.core.app.moving.grid.window";
1836
+ return AppApiEvent2;
1837
+ })(AppApiEvent || {});
1838
+ var AppApiConstants = /* @__PURE__ */ ((AppApiConstants2) => {
1839
+ AppApiConstants2["CONFIG_GRID_CELL_SIZE"] = "cn.widgetjs.config.grid.size";
1840
+ return AppApiConstants2;
1841
+ })(AppApiConstants || {});
1842
+ var AppApiImpl = class extends BaseApi {
1843
+ async getIconFile() {
1844
+ return this.invokeMethod("getIconFile");
1845
+ }
1846
+ getChannel() {
1847
+ return "channel::cn.widgetjs.core.app" /* APP */;
1848
+ }
1849
+ async setConfig(key, value) {
1850
+ return await this.invokeMethod("setConfig", key, value);
1851
+ }
1852
+ async getConfig(key, defaultValue) {
1853
+ const value = await this.invokeMethod("getConfig", key);
1854
+ if (value === null || value === void 0) {
1855
+ return defaultValue;
1856
+ }
1857
+ if (typeof defaultValue == "boolean") {
1858
+ return value === "true";
1859
+ }
1860
+ if (typeof defaultValue == "number") {
1861
+ return Number(value);
1862
+ }
1863
+ return value;
1864
+ }
1865
+ async openAddWidgetWindow() {
1866
+ return this.invokeMethod("openAddWidgetWindow");
1867
+ }
1868
+ /**
1869
+ * 获取应用版本号,格式为 x.y.z
1870
+ */
1871
+ async getVersion() {
1872
+ return this.invokeMethod("getVersion");
1873
+ }
1874
+ async getPreloadPath() {
1875
+ return this.invokeMethod("getPreloadPath");
1876
+ }
1877
+ async openSettingWindow() {
1878
+ return this.invokeMethod("openSettingWindow");
1879
+ }
1880
+ };
1881
+ var AppApi = new AppApiImpl();
1882
+
1883
+ // src/api/DialogApi.ts
1884
+ var DialogApiImpl = class extends BaseApi {
1885
+ getChannel() {
1886
+ return "channel::cn.widgetjs.core.dialog" /* DIALOG */;
1887
+ }
1888
+ /**
1889
+ * 选取单个文件
1890
+ * @param extensions 允许的文件后缀格式,如:["txt","docx","gif"]
1891
+ */
1892
+ pickFile(extensions) {
1893
+ return this.invokeMethod("pickFile", extensions);
1894
+ }
1895
+ pickFolder() {
1896
+ return this.invokeMethod("pickFolder");
1897
+ }
1898
+ };
1899
+ var DialogApi = new DialogApiImpl();
1900
+
1901
+ // src/api/StoreApi.ts
1902
+ var StoreApiImpl = class extends BaseApi {
1903
+ getChannel() {
1904
+ return "channel::cn.widgetjs.core.store" /* STORE */;
1905
+ }
1906
+ async delete(key) {
1907
+ return this.invokeMethod("delete", key);
1908
+ }
1909
+ async get(key, defaultValue) {
1910
+ const result = await this.invokeMethod("get", key);
1911
+ if (result == null && defaultValue != void 0) {
1912
+ return defaultValue;
1913
+ }
1914
+ return result;
1915
+ }
1916
+ async getObject(key, defaultValue) {
1917
+ const result = await this.invokeMethod("get", key);
1918
+ if (result) {
1919
+ return JSON.parse(result);
1920
+ }
1921
+ if (defaultValue != void 0) {
1922
+ return defaultValue;
1923
+ }
1924
+ return void 0;
1925
+ }
1926
+ async set(key, value) {
1927
+ if (typeof value == "object") {
1928
+ return this.invokeMethod("set", key, JSON.stringify(value));
1929
+ }
1930
+ return this.invokeMethod("set", key, value);
1931
+ }
1932
+ };
1933
+ var StoreApi = new StoreApiImpl();
1934
+
1935
+ // src/api/LogApi.ts
1936
+ var LogApiImpl = class extends BaseApi {
1937
+ getChannel() {
1938
+ return "channel::cn.widgetjs.core.log" /* LOG */;
1939
+ }
1940
+ info(...data) {
1941
+ console.info(...data);
1942
+ this.invokeMethod("info", ...data);
1943
+ }
1944
+ error(...data) {
1945
+ console.error(...data);
1946
+ this.invokeMethod("error", ...data);
1947
+ }
1948
+ warn(...data) {
1949
+ console.warn(...data);
1950
+ this.invokeMethod("warn", ...data);
1951
+ }
1952
+ log(...data) {
1953
+ console.log(...data);
1954
+ this.invokeMethod("log", ...data);
1955
+ }
1956
+ };
1957
+ var LogApi = new LogApiImpl();
1958
+
1959
+ // src/api/FileApi.ts
1960
+ var FileApiImpl = class extends BaseApi {
1961
+ getFileType(filePath) {
1962
+ return this.invokeMethod("getFileType", filePath);
1963
+ }
1964
+ isDirectory(filePath) {
1965
+ return this.invokeMethod("isDirectory", filePath);
1966
+ }
1967
+ getChannel() {
1968
+ return "channel::cn.widgetjs.core.file" /* FILE */;
1969
+ }
1970
+ readDirectory(path, options) {
1971
+ return this.invokeMethod("readDirectory", path, options);
1972
+ }
1973
+ };
1974
+ var FileApi = new FileApiImpl();
1975
+ // Annotate the CommonJS export names for ESM import in node:
1976
+ 0 && (module.exports = {
1977
+ ApiConstants,
1978
+ AppApi,
1979
+ AppApiConstants,
1980
+ AppApiEvent,
1981
+ AppNotification,
1982
+ BaseApi,
1983
+ BroadcastApi,
1984
+ BroadcastEvent,
1985
+ BrowserWindowApi,
1986
+ BrowserWindowApiEvent,
1987
+ Channel,
1988
+ ClipboardApi,
1989
+ ClipboardApiEvent,
1990
+ DeployMode,
1991
+ DeployedPage,
1992
+ DeployedWidget,
1993
+ DeployedWidgetApi,
1994
+ DeviceApi,
1995
+ DialogApi,
1996
+ ElectronApi,
1997
+ ElectronUtils,
1998
+ FileApi,
1999
+ Gravity,
2000
+ GridRect,
2001
+ GridSystem,
2002
+ HostedMode,
2003
+ LogApi,
2004
+ NotificationApi,
2005
+ NotificationApiEvent,
2006
+ NotificationSize,
2007
+ Page,
2008
+ ShortcutApi,
2009
+ ShortcutApiEvent,
2010
+ StoreApi,
2011
+ ThemeMode,
2012
+ WebSocketEvent,
2013
+ WebSocketEventType,
2014
+ Widget,
2015
+ WidgetApi,
2016
+ WidgetApiEvent,
2017
+ WidgetData,
2018
+ WidgetDataApi,
2019
+ WidgetKeyword,
2020
+ WidgetPackage,
2021
+ WidgetParams,
2022
+ WidgetUrlUtils,
2023
+ normalizeUrl,
2024
+ parseQuery,
2025
+ stringifyQuery
2026
+ });
2027
+ //# sourceMappingURL=index.cjs.map