@widget-js/core 0.7.2 → 0.7.3

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 +2084 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.ts +1507 -0
  4. package/dist/index.js +1995 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +15 -15
  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
@@ -0,0 +1,1507 @@
1
+ import { FileTypeResult } from 'file-type';
2
+
3
+ /**
4
+ * @deprecated use DeployedMode instead
5
+ */
6
+ declare enum HostedMode {
7
+ NORMAL = 1,
8
+ /**
9
+ * 悬浮窗
10
+ */
11
+ OVERLAP = 16,
12
+ WALLPAPER = 256,
13
+ SCREEN = 4096,
14
+ /**
15
+ * 后台组件,没有界面,一般在后台执行定时任务
16
+ */
17
+ BACKGROUND = 65536,
18
+ /**
19
+ * 页面
20
+ */
21
+ PAGE = 1048576,
22
+ ALL = 1118481
23
+ }
24
+ declare enum DeployedMode {
25
+ NORMAL = 1,
26
+ /**
27
+ * 悬浮窗
28
+ */
29
+ OVERLAP = 16,
30
+ BACKGROUND = 65536,
31
+ ALL = 1118481
32
+ }
33
+
34
+ type WidgetPermission = 'keyboard' | 'mouse' | 'clipboard' | 'notification' | 'storage' | 'network' | 'cpu' | 'system-info';
35
+
36
+ interface Language {
37
+ locale: string;
38
+ language: string;
39
+ code: string;
40
+ }
41
+ interface ILanguageMap {
42
+ 'ar-SA': Language;
43
+ 'bn-BD': Language;
44
+ 'en-US': Language;
45
+ 'de-DE': Language;
46
+ 'el-GR': Language;
47
+ 'es-ES': Language;
48
+ 'fi-FI': Language;
49
+ 'fil-PH': Language;
50
+ 'fr-FR': Language;
51
+ 'hi-IN': Language;
52
+ 'hu-HU': Language;
53
+ 'id-ID': Language;
54
+ 'it-IT': Language;
55
+ 'ja-JP': Language;
56
+ 'ko-KR': Language;
57
+ 'nl-NL': Language;
58
+ 'pl-PL': Language;
59
+ 'pt-BR': Language;
60
+ 'pt-PT': Language;
61
+ 'ro-RO': Language;
62
+ 'ru-RU': Language;
63
+ 'sv-SE': Language;
64
+ 'ta-IN': Language;
65
+ 'tr-TR': Language;
66
+ 'uk-UA': Language;
67
+ 'vi-VN': Language;
68
+ 'zh-CN': Language;
69
+ 'zh-TW': Language;
70
+ }
71
+ type LanguageCode = keyof ILanguageMap;
72
+ type LanguageTextMap = {
73
+ [key in LanguageCode]?: string;
74
+ };
75
+
76
+ type MetaInfo = {
77
+ [key: string]: string | number | boolean;
78
+ };
79
+ interface IWindowSize {
80
+ width: number;
81
+ height: number;
82
+ maxWidth?: number;
83
+ maxHeight?: number;
84
+ minWidth?: number;
85
+ minHeight?: number;
86
+ }
87
+ interface IWindowOptions extends IWindowSize {
88
+ name: string;
89
+ title: LanguageTextMap;
90
+ description: LanguageTextMap;
91
+ keywords: WidgetKeyword[];
92
+ lang: LanguageCode;
93
+ packageName?: string;
94
+ previewImage: string;
95
+ /**
96
+ * 是否在搜索中显示
97
+ */
98
+ showInSearch?: boolean;
99
+ /**
100
+ * 悬浮窗模式 是否可移动
101
+ */
102
+ movable?: boolean;
103
+ resizable?: boolean;
104
+ backgroundThrottling?: boolean;
105
+ url: string;
106
+ /**
107
+ * 是否只能添加一次
108
+ */
109
+ singleton?: boolean;
110
+ meta?: MetaInfo;
111
+ broadcastChannels?: string[];
112
+ }
113
+ interface IPage {
114
+ readonly name: string;
115
+ /**
116
+ * 窗口标题,显示在界面上的,
117
+ * https://zh.m.wikipedia.org/zh-hans/ISO_639-1
118
+ */
119
+ readonly title: LanguageTextMap;
120
+ /**
121
+ * 窗口介绍
122
+ */
123
+ readonly description: LanguageTextMap;
124
+ readonly keywords: WidgetKeyword[];
125
+ /**
126
+ * 组件默认语言
127
+ */
128
+ readonly lang: LanguageCode;
129
+ readonly width: number;
130
+ packageName?: string | null;
131
+ readonly height: number;
132
+ readonly maxWidth: number;
133
+ readonly maxHeight: number;
134
+ readonly minWidth: number;
135
+ readonly minHeight: number;
136
+ readonly movable: boolean;
137
+ readonly singleton: boolean;
138
+ readonly resizable: boolean;
139
+ readonly url: string;
140
+ readonly meta: {
141
+ [key: string]: string | number | boolean;
142
+ };
143
+ readonly backgroundThrottling: boolean;
144
+ /**
145
+ * 预览图片,可以是GIF
146
+ */
147
+ readonly previewImage: string;
148
+ }
149
+ declare class Page implements IPage {
150
+ readonly name: string;
151
+ /**
152
+ * 窗口标题,显示在界面上的,
153
+ * https://zh.m.wikipedia.org/zh-hans/ISO_639-1
154
+ */
155
+ readonly title: LanguageTextMap;
156
+ /**
157
+ * 窗口介绍
158
+ */
159
+ readonly description: LanguageTextMap;
160
+ readonly keywords: WidgetKeyword[];
161
+ /**
162
+ * 组件默认语言
163
+ */
164
+ readonly lang: LanguageCode;
165
+ readonly width: number;
166
+ packageName?: string | null;
167
+ readonly height: number;
168
+ readonly maxWidth: number;
169
+ readonly maxHeight: number;
170
+ readonly minWidth: number;
171
+ readonly minHeight: number;
172
+ readonly movable: boolean;
173
+ readonly singleton: boolean;
174
+ readonly resizable: boolean;
175
+ readonly url: string;
176
+ readonly meta: {
177
+ [key: string]: string | number | boolean;
178
+ };
179
+ readonly backgroundThrottling: boolean;
180
+ /**
181
+ * 预览图片,可以是GIF
182
+ */
183
+ readonly previewImage: string;
184
+ constructor(options: IWindowOptions);
185
+ /**
186
+ * 获取组件标题
187
+ * @param lang 语言环境,不传则获取默认语言
188
+ */
189
+ getTitle(lang?: LanguageCode): string | undefined;
190
+ /**
191
+ * 获取组件描述
192
+ * @param lang 语言环境,不传则获取默认标题
193
+ */
194
+ getDescription(lang?: LanguageCode): string | undefined;
195
+ static parseJSON(json: string): Page;
196
+ static parseObject(obj: any): Page;
197
+ isResizable(): boolean;
198
+ }
199
+
200
+ interface IWidgetOptions extends IWindowSize, IWindowOptions {
201
+ /**
202
+ * @deprecated use deployedMode instead
203
+ */
204
+ supportHostedMode?: DeployedMode;
205
+ supportDeployedMode?: DeployedMode;
206
+ /**
207
+ * 组件拉伸后,是否强制刷新组件
208
+ * @deprecated
209
+ */
210
+ refreshWhenResided?: boolean;
211
+ /**
212
+ * @deprecated
213
+ */
214
+ routes: WidgetRoute[];
215
+ /**
216
+ * @deprecated
217
+ */
218
+ permissions?: WidgetPermission[];
219
+ }
220
+ declare class Widget extends Page {
221
+ readonly supportHostedMode: number;
222
+ readonly supportDeployedMode: number;
223
+ /**
224
+ * @deprecated
225
+ */
226
+ readonly refreshWhenResided: boolean;
227
+ /**
228
+ * 组件其他页面的url在这注册
229
+ * @deprecated
230
+ */
231
+ readonly routes: WidgetRoute[];
232
+ /**
233
+ * @deprecated
234
+ */
235
+ readonly permissions: WidgetPermission[];
236
+ constructor(options: IWidgetOptions);
237
+ getIndexRoute(): WidgetRoute;
238
+ getConfigRoute(): WidgetRoute | undefined;
239
+ isConfigurable(): boolean;
240
+ static parseJSON(json: string): Widget;
241
+ static parseObject(obj: any): Widget;
242
+ /**
243
+ * 是否支持悬浮窗
244
+ */
245
+ isSupportOverlap(): boolean;
246
+ isSupportBackground(): boolean;
247
+ /**
248
+ * 是否支持普通模式
249
+ */
250
+ isSupportNormal(): boolean;
251
+ }
252
+ interface WidgetRoute {
253
+ name: string;
254
+ url: string;
255
+ meta?: {
256
+ [key: string]: string;
257
+ };
258
+ /**
259
+ * 使用自定义悬浮窗样式
260
+ */
261
+ customOverlapView?: boolean;
262
+ }
263
+ declare enum WidgetKeyword {
264
+ RECOMMEND = "recommend",
265
+ TOOLS = "tools",
266
+ EFFICIENCY = "efficiency",
267
+ PICTURE = "picture",
268
+ LIFE = "life",
269
+ SHORTCUT = "shortcut",
270
+ COUNTDOWN = "countdown",
271
+ TIMER = "timer",
272
+ INFO = "info",
273
+ DASHBOARD = "dashboard"
274
+ }
275
+
276
+ interface LocalPackageUrlInfo {
277
+ /**
278
+ * 入口文件,默认为index.html,也可以是/
279
+ * @example remote package: https://rtugeek.gitee.io/hotspot/index.html
280
+ * @example local package: index.html
281
+ */
282
+ entry?: string;
283
+ /**
284
+ * 是否使用hash路由
285
+ */
286
+ hash: boolean;
287
+ }
288
+ interface RemotePackageUrlInfo extends LocalPackageUrlInfo {
289
+ /**
290
+ * 部署到服务器的base path,只在远程组件包中生效,需以/开始
291
+ * @example /hotspot
292
+ */
293
+ base?: string;
294
+ }
295
+ interface WidgetPackageOptions extends LocalPackageUrlInfo {
296
+ name: string;
297
+ version?: string;
298
+ author: string;
299
+ homepage?: string;
300
+ title: LanguageTextMap;
301
+ permissions?: WidgetPermission[];
302
+ description: LanguageTextMap;
303
+ remoteEntry?: string;
304
+ remotePackage?: string;
305
+ remote?: RemotePackageUrlInfo;
306
+ icon?: string;
307
+ lang?: LanguageCode;
308
+ widgets?: Widget[];
309
+ devOptions?: DevOptions;
310
+ }
311
+ declare class WidgetPackage implements RemotePackageUrlInfo {
312
+ /**
313
+ * 组件包名,一般为域名倒写,e.g. com.example
314
+ */
315
+ readonly name: string;
316
+ /**
317
+ * 组件包版本,可以为空,默认采用package.json里的版本
318
+ * e.g. 1.0.2
319
+ */
320
+ version?: string;
321
+ /**
322
+ * 组件作者署名
323
+ */
324
+ readonly author: string;
325
+ /**
326
+ * 组件首页
327
+ */
328
+ readonly homepage?: string;
329
+ /**
330
+ * 组件描述
331
+ */
332
+ readonly title: {
333
+ [key: LanguageCode | string]: string;
334
+ };
335
+ /**
336
+ * 组件描述
337
+ */
338
+ readonly description: {
339
+ [key: LanguageCode | string]: string;
340
+ };
341
+ /**
342
+ * 组件入口文件,通常为 index.html
343
+ */
344
+ entry: string | 'index.html';
345
+ /**
346
+ * 组件包的远程入口地址,
347
+ */
348
+ remoteEntry?: string;
349
+ readonly remotePackage?: string;
350
+ readonly local?: LocalPackageUrlInfo;
351
+ readonly remote?: RemotePackageUrlInfo;
352
+ /**
353
+ * 组件包图标
354
+ */
355
+ readonly icon?: string;
356
+ /**
357
+ * Hash路由模式,默认为true
358
+ */
359
+ readonly hash: boolean;
360
+ /**
361
+ * 可能是网络地址,或者本地路径(解压后的文件夹路径),
362
+ * 网络地址:https://www.bilibili.com
363
+ * 本地地址:file:///C:/Users/neo/Desktop
364
+ * 在测试时。地址通常为: http://127.0.0.1:8080
365
+ */
366
+ url: string;
367
+ readonly widgets: Widget[];
368
+ readonly pages: Page[];
369
+ devOptions?: DevOptions;
370
+ constructor(options: WidgetPackageOptions);
371
+ static parseJSON(json: string): WidgetPackage;
372
+ static parseObject(obj: any): WidgetPackage;
373
+ /**
374
+ * 获取组件包标题
375
+ * @param lang 语言环境,不传则获取默认语言
376
+ */
377
+ getTitle(lang?: LanguageCode): string | undefined;
378
+ /**
379
+ * 获取组件包描述
380
+ * @param lang 语言环境,不传则获取默认标题
381
+ */
382
+ getDescription(lang?: LanguageCode): string | undefined;
383
+ /**
384
+ * 获取组件完整路径
385
+ * 如果url是http链接,直接返回链接
386
+ * 如果是本地组件:file://链接,则返回 url+entry,
387
+ * 如果是远程组件:http://链接,则返回 entry,
388
+ * @example file://C:/users/neo/desktop/index.html#
389
+ * @example file://C:/users/neo/desktop/index.html#
390
+ */
391
+ getIndexUrl(hash?: boolean): string;
392
+ }
393
+ type DevOptions = {
394
+ folder?: string;
395
+ route?: boolean;
396
+ devUrl?: string;
397
+ remoteEntry?: string;
398
+ };
399
+
400
+ declare class WidgetParams {
401
+ static readonly PARAM_PREFIX = "w_";
402
+ static readonly PARAM_ID = "id";
403
+ static readonly PARAM_WIDTH = "width";
404
+ static readonly PARAM_HEIGHT = "height";
405
+ static readonly PARAM_WIDTH_PX = "width_px";
406
+ static readonly PARAM_HEIGHT_PX = "height_px";
407
+ static readonly PARAM_X = "x";
408
+ static readonly PARAM_Y = "y";
409
+ static readonly PARAM_LANG = "lang";
410
+ static readonly PARAM_THEME = "theme";
411
+ static readonly PARAM_MODE = "mode";
412
+ static readonly PARAM_RADIUS = "radius";
413
+ static readonly PARAM_NAME = "name";
414
+ static readonly PARAM_TITLE = "title";
415
+ static readonly PARAM_PREVIEW = "preview";
416
+ static readonly PARAMS: string[];
417
+ id?: string;
418
+ width?: number;
419
+ widthPx?: number;
420
+ heightPx?: number;
421
+ height?: number;
422
+ x?: number;
423
+ y?: number;
424
+ preview?: boolean;
425
+ lang?: string;
426
+ theme?: ThemeMode;
427
+ mode?: DeployedMode;
428
+ radius?: number;
429
+ name?: string;
430
+ title?: string;
431
+ /**
432
+ * 将组件参数转为url参数
433
+ * @param object
434
+ * @return URLSearchParams w_w=2&w_h=2&w_id=21&w_width=156&w_height=156
435
+ */
436
+ toUrlParams(): URLSearchParams;
437
+ getPersistKey(): string;
438
+ /**
439
+ * 从当前地址解析组件参数:
440
+ * http://localhost:8080/#/widget/config/labor_progress?w_w=2&w_h=2&w_width=156&w_height=156
441
+ * =>
442
+ * {width:2,height:2,id:21,width_px:156,height_px:156}
443
+ */
444
+ static fromCurrentLocation(): WidgetParams;
445
+ static fromLocation(url: string): WidgetParams;
446
+ private static setValue;
447
+ /**
448
+ * 从对象键值对中初始化组件参数
449
+ * {w_width:2,w_height:2,w_id:21,w_width_px:156,w_height_px:156}=>
450
+ * {width:2,height:2,id:21,width_px:156,height_px:156}
451
+ * @param object
452
+ */
453
+ static fromObject(object: any): WidgetParams;
454
+ }
455
+ declare enum ThemeMode {
456
+ AUTO = "auto",
457
+ LIGHT = "LIGHT",
458
+ DARK = "DARK"
459
+ }
460
+
461
+ declare abstract class BaseApi<T extends string> {
462
+ abstract getChannel(): string;
463
+ protected invokeMethod(method: T, ...args: any[]): Promise<any>;
464
+ protected invoke(...args: any[]): Promise<any>;
465
+ }
466
+
467
+ interface IWidgetApi {
468
+ registerWidgets(widgets: Widget[]): Promise<void>;
469
+ registerWidgetPackage(widgetPackage: WidgetPackage): Promise<void>;
470
+ getWidgets(): Promise<Widget[]>;
471
+ getWidget(name: string): Promise<Widget>;
472
+ getWidgetPackage(name: string): Promise<WidgetPackage>;
473
+ getWidgetPackages(): Promise<WidgetPackage[]>;
474
+ getWidgetUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
475
+ getWidgetPackageIndexUrl(packageName: string, hash?: boolean): Promise<string | null>;
476
+ getWidgetConfigUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
477
+ getWidgetPackageUrl(packageName: string): Promise<string | null>;
478
+ }
479
+ type WidgetApiMethods = keyof IWidgetApi;
480
+ declare enum WidgetApiEvent {
481
+ DATA_CHANGED = "event::cn.widgetjs.core.widget.data-changed",
482
+ EDIT_DESKTOP_WIDGETS = "event::cn.widgetjs.core.widget.desktop.edit"
483
+ }
484
+ declare class WidgetApiImpl extends BaseApi<WidgetApiMethods> implements IWidgetApi {
485
+ getChannel(): string;
486
+ registerWidgets(widgets: Widget[]): Promise<any>;
487
+ registerWidgetPackage(widgetPackage: WidgetPackage): Promise<any>;
488
+ getWidgets(): Promise<Widget[]>;
489
+ getWidgetPackages(): Promise<WidgetPackage[]>;
490
+ /**
491
+ *
492
+ * @param name package name
493
+ */
494
+ getWidget(name: string): Promise<Widget>;
495
+ /**
496
+ *
497
+ * @param name package name
498
+ */
499
+ getWidgetPackage(name: string): Promise<WidgetPackage>;
500
+ /**
501
+ * 获取组件配置地址
502
+ * @param widgetName
503
+ */
504
+ getWidgetConfigUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
505
+ getWidgetUrl(widgetName: string, widgetParams: WidgetParams): Promise<string | null>;
506
+ getWidgetPackageIndexUrl(packageName: string, hash?: boolean): Promise<string | null>;
507
+ getWidgetPackageUrl(packageName: string): Promise<string | null>;
508
+ }
509
+ declare const WidgetApi: WidgetApiImpl;
510
+
511
+ interface IAppApi {
512
+ setConfig(key: string, value: string | number | boolean): Promise<void>;
513
+ getConfig(key: string, defaultValue: string | number | boolean): Promise<string | number | boolean>;
514
+ getVersion(): Promise<string>;
515
+ getPreloadPath(): Promise<string>;
516
+ openAddWidgetWindow(): Promise<void>;
517
+ openSettingWindow(): Promise<void>;
518
+ getIconFile(): Promise<string>;
519
+ }
520
+ type AppApiMethods = keyof IAppApi;
521
+ declare enum AppApiEvent {
522
+ CONFIG_CHANGED = "event::cn.widgetjs.core.app.config.changed"
523
+ }
524
+ declare enum AppApiConstants {
525
+ CONFIG_GRID_CELL_SIZE = "cn.widgetjs.config.grid.size"
526
+ }
527
+ declare const AppApi: IAppApi;
528
+
529
+ interface BroadcastEventOptions {
530
+ event: WidgetApiEvent | AppApiEvent | string;
531
+ /**
532
+ * 发送人,用于标记发送源,一般为组件名,如:com.example.widgets.countdown
533
+ */
534
+ sender?: string;
535
+ /**
536
+ * 广播事件携带的数据,只支持部分数据类型。
537
+ * 情见:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
538
+ */
539
+ payload?: any;
540
+ }
541
+ declare class BroadcastEvent {
542
+ readonly event: string;
543
+ readonly sender?: string;
544
+ payload?: any;
545
+ constructor(options: BroadcastEventOptions);
546
+ }
547
+
548
+ declare enum WebSocketEventType {
549
+ RESISTER_PACKAGE = "ws::cn.widgetjs.core.resister_package"
550
+ }
551
+ declare class WebSocketEvent {
552
+ type: WebSocketEventType;
553
+ payload: any;
554
+ constructor(type: WebSocketEventType, payload: any);
555
+ }
556
+
557
+ /**
558
+ * 组件配置数据,用于存储组件自定义页面所设置的数据
559
+ */
560
+ declare class WidgetData {
561
+ /**
562
+ * 组件id
563
+ */
564
+ id?: string;
565
+ /**
566
+ * 组件名
567
+ */
568
+ name: string;
569
+ /**
570
+ * 背景颜色
571
+ */
572
+ backgroundColor?: string;
573
+ /**
574
+ * 文字颜色
575
+ */
576
+ color?: string;
577
+ /**
578
+ * 字体大小
579
+ */
580
+ fontSize?: number;
581
+ /**
582
+ * 字体
583
+ */
584
+ fontFamily?: string;
585
+ /**
586
+ * 圆角半径
587
+ */
588
+ borderRadius?: number;
589
+ constructor(name: string, id?: string);
590
+ parseJSON(json: {}): void;
591
+ }
592
+
593
+ type NotificationType = "countdown" | "advance-countdown" | "error" | "success" | "warning" | "info" | "reminder" | "url" | "call";
594
+ declare enum NotificationSize {
595
+ SMALL = "small",
596
+ NORMAL = "normal",
597
+ LARGE = "large"
598
+ }
599
+ interface NotificationOption {
600
+ type?: NotificationType;
601
+ title?: string;
602
+ message: string;
603
+ targetTime?: string;
604
+ duration?: number;
605
+ /**
606
+ * 图片名,目前只支持mingcute图标。
607
+ * https://www.mingcute.com/
608
+ */
609
+ icon?: string;
610
+ color?: string;
611
+ confirmButtonText?: string;
612
+ cancelButtonText?: string;
613
+ cancelBroadcast?: string;
614
+ confirmBroadcast?: string;
615
+ size?: NotificationSize;
616
+ url?: string;
617
+ avatar?: string;
618
+ audio?: string;
619
+ lyric?: string;
620
+ backgroundColor?: string;
621
+ }
622
+ declare class AppNotification {
623
+ type: NotificationType;
624
+ message: string;
625
+ title?: string;
626
+ targetTime?: string;
627
+ duration: number;
628
+ icon?: string;
629
+ color?: string;
630
+ backgroundColor?: string;
631
+ confirmButtonText?: string;
632
+ cancelButtonText?: string;
633
+ cancelBroadcast?: string;
634
+ confirmBroadcast?: string;
635
+ size: NotificationSize;
636
+ url?: string;
637
+ avatar?: string;
638
+ audio?: string;
639
+ lyric?: string;
640
+ createdAt: string;
641
+ constructor(option: NotificationOption);
642
+ }
643
+
644
+ interface IDeployedPage {
645
+ id: string;
646
+ name: string;
647
+ packageName: string;
648
+ x: number;
649
+ y: number;
650
+ height: number;
651
+ width: number;
652
+ proxy?: string;
653
+ }
654
+ declare class DeployedPage implements IDeployedPage {
655
+ name: string;
656
+ packageName: string;
657
+ x: number;
658
+ y: number;
659
+ height: number;
660
+ width: number;
661
+ proxy?: string;
662
+ id: string;
663
+ }
664
+
665
+ declare class BrowserWindowStatus {
666
+ height: number;
667
+ width: number;
668
+ x?: number;
669
+ y?: number;
670
+ isAlwaysOnTop: boolean;
671
+ isAutoHide: boolean;
672
+ constructor(width: number, height: number);
673
+ }
674
+
675
+ /**
676
+ * @deprecated
677
+ */
678
+ declare class HostedWidget extends DeployedPage {
679
+ /**
680
+ * @deprecated
681
+ */
682
+ widgetName: string;
683
+ x: number;
684
+ y: number;
685
+ /**
686
+ * @deprecated
687
+ */
688
+ browserWindowStatus?: BrowserWindowStatus;
689
+ shortcut?: string;
690
+ /**
691
+ * @deprecated use deployedMode instead
692
+ */
693
+ hostedMode: number;
694
+ deployedMode: number;
695
+ isOverlap(): boolean;
696
+ }
697
+ declare class DeployedWidget extends DeployedPage {
698
+ shortcut?: string;
699
+ hostedMode: number;
700
+ isOverlap(): boolean;
701
+ }
702
+
703
+ interface Rectangle {
704
+ /**
705
+ * The height of the rectangle (must be an integer).
706
+ */
707
+ height: number;
708
+ /**
709
+ * The width of the rectangle (must be an integer).
710
+ */
711
+ width: number;
712
+ /**
713
+ * The x coordinate of the origin of the rectangle (must be an integer).
714
+ */
715
+ x: number;
716
+ /**
717
+ * The y coordinate of the origin of the rectangle (must be an integer).
718
+ */
719
+ y: number;
720
+ }
721
+
722
+ interface Point {
723
+ x: number;
724
+ y: number;
725
+ }
726
+ type Position = {
727
+ x: number;
728
+ y: number;
729
+ };
730
+ declare enum Gravity {
731
+ TOP = "TOP",
732
+ LEFT = "LEFT",
733
+ RIGHT = "RIGHT",
734
+ BOTTOM = "BOTTOM"
735
+ }
736
+
737
+ interface NativeKeyboardEvent {
738
+ name: string;
739
+ keyCode: number;
740
+ scanCode: number;
741
+ isKeyUp: boolean;
742
+ }
743
+
744
+ interface AppMouseEvent {
745
+ handled: boolean;
746
+ wheelScrolled: boolean;
747
+ clicked: boolean;
748
+ isMouseButtonDown: boolean;
749
+ isMouseButtonUp: boolean;
750
+ timestamp: number;
751
+ button: number;
752
+ clicks: number;
753
+ x: number;
754
+ y: number;
755
+ delta: number;
756
+ location: string;
757
+ }
758
+
759
+ declare class ElectronUtils {
760
+ static hasElectronApi(): boolean;
761
+ /**
762
+ * 获取ElectronAPI
763
+ * windows api
764
+ */
765
+ static getAPI(): any;
766
+ static invokeMethod(channel: string, method: string, ...args: any[]): Promise<any>;
767
+ static invoke(channel: string, ...args: any[]): Promise<any>;
768
+ }
769
+
770
+ declare class WidgetUrlUtils {
771
+ static getWidgetUrl(widgetUrl: string, widgetPackage: WidgetPackage, widgetParams: WidgetParams): string;
772
+ static getWidgetPackageUrl(url: string, entry: string, hash: boolean): string;
773
+ }
774
+
775
+ /**
776
+ * Possible values in normalized {@link LocationQuery}. `null` renders the query
777
+ * param but without an `=`.
778
+ *
779
+ * @example
780
+ * ```
781
+ * ?isNull&isEmpty=&other=other
782
+ * gives
783
+ * `{ isNull: null, isEmpty: '', other: 'other' }`.
784
+ * ```
785
+ *
786
+ * @internal
787
+ */
788
+ type LocationQueryValue = string | null;
789
+ /**
790
+ * Possible values when defining a query.
791
+ *
792
+ * @internal
793
+ */
794
+ type LocationQueryValueRaw = LocationQueryValue | number | undefined;
795
+ /**
796
+ * Normalized query object that appears in {@link RouteLocationNormalized}
797
+ *
798
+ * @public
799
+ */
800
+ type LocationQuery = Record<string, LocationQueryValue | LocationQueryValue[]>;
801
+ /**
802
+ * Loose {@link LocationQuery} object that can be passed to functions like
803
+ * {@link Router.push} and {@link Router.replace} or anywhere when creating a
804
+ * {@link RouteLocationRaw}
805
+ *
806
+ * @public
807
+ */
808
+ type LocationQueryRaw = Record<string | number, LocationQueryValueRaw | LocationQueryValueRaw[]>;
809
+ /**
810
+ * Transforms a queryString into a {@link LocationQuery} object. Accept both, a
811
+ * version with the leading `?` and without Should work as URLSearchParams
812
+ * @internal
813
+ *
814
+ * @param search - search string to parse
815
+ * @returns a query object
816
+ */
817
+ declare function parseQuery(search: string): LocationQuery;
818
+ /**
819
+ * Stringifies a {@link LocationQueryRaw} object. Like `URLSearchParams`, it
820
+ * doesn't prepend a `?`
821
+ *
822
+ * @internal
823
+ *
824
+ * @param query - query object to stringify
825
+ * @returns string version of the query without the leading `?`
826
+ */
827
+ declare function stringifyQuery(query: LocationQueryRaw): string;
828
+
829
+ type NormalizeOptions = {
830
+ /**
831
+ @default 'http'
832
+ */
833
+ defaultProtocol?: string | 'http' | 'https';
834
+ /**
835
+ Prepends `defaultProtocol` to the URL if it's protocol-relative.
836
+
837
+ @default true
838
+
839
+ @example
840
+ ```
841
+ normalizeUrl('//sindresorhus.com');
842
+ //=> 'http://sindresorhus.com'
843
+
844
+ normalizeUrl('//sindresorhus.com', {normalizeProtocol: false});
845
+ //=> '//sindresorhus.com'
846
+ ```
847
+ */
848
+ readonly normalizeProtocol?: boolean;
849
+ /**
850
+ Normalizes HTTPS URLs to HTTP.
851
+
852
+ @default false
853
+
854
+ @example
855
+ ```
856
+ normalizeUrl('https://sindresorhus.com');
857
+ //=> 'https://sindresorhus.com'
858
+
859
+ normalizeUrl('https://sindresorhus.com', {forceHttp: true});
860
+ //=> 'http://sindresorhus.com'
861
+ ```
862
+ */
863
+ readonly forceHttp?: boolean;
864
+ /**
865
+ Normalizes HTTP URLs to HTTPS.
866
+
867
+ This option cannot be used with the `forceHttp` option at the same time.
868
+
869
+ @default false
870
+
871
+ @example
872
+ ```
873
+ normalizeUrl('http://sindresorhus.com');
874
+ //=> 'http://sindresorhus.com'
875
+
876
+ normalizeUrl('http://sindresorhus.com', {forceHttps: true});
877
+ //=> 'https://sindresorhus.com'
878
+ ```
879
+ */
880
+ readonly forceHttps?: boolean;
881
+ /**
882
+ Strip the [authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) part of a URL.
883
+
884
+ @default true
885
+
886
+ @example
887
+ ```
888
+ normalizeUrl('https://user:password@sindresorhus.com');
889
+ //=> 'https://sindresorhus.com'
890
+
891
+ normalizeUrl('https://user:password@sindresorhus.com', {stripAuthentication: false});
892
+ //=> 'https://user:password@sindresorhus.com'
893
+ ```
894
+ */
895
+ readonly stripAuthentication?: boolean;
896
+ /**
897
+ Removes hash from the URL.
898
+
899
+ @default false
900
+
901
+ @example
902
+ ```
903
+ normalizeUrl('sindresorhus.com/about.html#contact');
904
+ //=> 'http://sindresorhus.com/about.html#contact'
905
+
906
+ normalizeUrl('sindresorhus.com/about.html#contact', {stripHash: true});
907
+ //=> 'http://sindresorhus.com/about.html'
908
+ ```
909
+ */
910
+ readonly stripHash?: boolean;
911
+ /**
912
+ Remove the protocol from the URL: `http://sindresorhus.com` → `sindresorhus.com`.
913
+
914
+ It will only remove `https://` and `http://` protocols.
915
+
916
+ @default false
917
+
918
+ @example
919
+ ```
920
+ normalizeUrl('https://sindresorhus.com');
921
+ //=> 'https://sindresorhus.com'
922
+
923
+ normalizeUrl('sindresorhus.com', {stripProtocol: true});
924
+ //=> 'sindresorhus.com'
925
+ ```
926
+ */
927
+ readonly stripProtocol?: boolean;
928
+ /**
929
+ Strip the [text fragment](https://web.dev/text-fragments/) part of the URL
930
+
931
+ __Note:__ The text fragment will always be removed if the `stripHash` option is set to `true`, as the hash contains the text fragment.
932
+
933
+ @default true
934
+
935
+ @example
936
+ ```
937
+ normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello');
938
+ //=> 'http://sindresorhus.com/about.html#'
939
+
940
+ normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello');
941
+ //=> 'http://sindresorhus.com/about.html#section'
942
+
943
+ normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello', {stripTextFragment: false});
944
+ //=> 'http://sindresorhus.com/about.html#:~:text=hello'
945
+
946
+ normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello', {stripTextFragment: false});
947
+ //=> 'http://sindresorhus.com/about.html#section:~:text=hello'
948
+ ```
949
+ */
950
+ readonly stripTextFragment?: boolean;
951
+ /**
952
+ Removes `www.` from the URL.
953
+
954
+ @default true
955
+
956
+ @example
957
+ ```
958
+ normalizeUrl('http://www.sindresorhus.com');
959
+ //=> 'http://sindresorhus.com'
960
+
961
+ normalizeUrl('http://www.sindresorhus.com', {stripWWW: false});
962
+ //=> 'http://www.sindresorhus.com'
963
+ ```
964
+ */
965
+ readonly stripWWW?: boolean;
966
+ /**
967
+ Removes query parameters that matches any of the provided strings or regexes.
968
+
969
+ @default [/^utm_\w+/i]
970
+
971
+ @example
972
+ ```
973
+ normalizeUrl('www.sindresorhus.com?foo=bar&ref=test_ref', {
974
+ removeQueryParameters: ['ref']
975
+ });
976
+ //=> 'http://sindresorhus.com/?foo=bar'
977
+ ```
978
+
979
+ If a boolean is provided, `true` will remove all the query parameters.
980
+
981
+ ```
982
+ normalizeUrl('www.sindresorhus.com?foo=bar', {
983
+ removeQueryParameters: true
984
+ });
985
+ //=> 'http://sindresorhus.com'
986
+ ```
987
+
988
+ `false` will not remove any query parameter.
989
+
990
+ ```
991
+ normalizeUrl('www.sindresorhus.com?foo=bar&utm_medium=test&ref=test_ref', {
992
+ removeQueryParameters: false
993
+ });
994
+ //=> 'http://www.sindresorhus.com/?foo=bar&ref=test_ref&utm_medium=test'
995
+ ```
996
+ */
997
+ readonly removeQueryParameters?: ReadonlyArray<RegExp | string> | boolean;
998
+ /**
999
+ Keeps only query parameters that matches any of the provided strings or regexes.
1000
+
1001
+ __Note__: It overrides the `removeQueryParameters` option.
1002
+
1003
+ @default undefined
1004
+
1005
+ @example
1006
+ ```
1007
+ normalizeUrl('https://sindresorhus.com?foo=bar&ref=unicorn', {
1008
+ keepQueryParameters: ['ref']
1009
+ });
1010
+ //=> 'https://sindresorhus.com/?ref=unicorn'
1011
+ ```
1012
+ */
1013
+ readonly keepQueryParameters?: ReadonlyArray<RegExp | string>;
1014
+ /**
1015
+ Removes trailing slash.
1016
+
1017
+ __Note__: Trailing slash is always removed if the URL doesn't have a pathname unless the `removeSingleSlash` option is set to `false`.
1018
+
1019
+ @default true
1020
+
1021
+ @example
1022
+ ```
1023
+ normalizeUrl('http://sindresorhus.com/redirect/');
1024
+ //=> 'http://sindresorhus.com/redirect'
1025
+
1026
+ normalizeUrl('http://sindresorhus.com/redirect/', {removeTrailingSlash: false});
1027
+ //=> 'http://sindresorhus.com/redirect/'
1028
+
1029
+ normalizeUrl('http://sindresorhus.com/', {removeTrailingSlash: false});
1030
+ //=> 'http://sindresorhus.com'
1031
+ ```
1032
+ */
1033
+ readonly removeTrailingSlash?: boolean;
1034
+ /**
1035
+ Remove a sole `/` pathname in the output. This option is independent of `removeTrailingSlash`.
1036
+
1037
+ @default true
1038
+
1039
+ @example
1040
+ ```
1041
+ normalizeUrl('https://sindresorhus.com/');
1042
+ //=> 'https://sindresorhus.com'
1043
+
1044
+ normalizeUrl('https://sindresorhus.com/', {removeSingleSlash: false});
1045
+ //=> 'https://sindresorhus.com/'
1046
+ ```
1047
+ */
1048
+ readonly removeSingleSlash?: boolean;
1049
+ /**
1050
+ Removes the default directory index file from path that matches any of the provided strings or regexes.
1051
+ When `true`, the regex `/^index\.[a-z]+$/` is used.
1052
+
1053
+ @default false
1054
+
1055
+ @example
1056
+ ```
1057
+ normalizeUrl('www.sindresorhus.com/foo/default.php', {
1058
+ removeDirectoryIndex: [/^default\.[a-z]+$/]
1059
+ });
1060
+ //=> 'http://sindresorhus.com/foo'
1061
+ ```
1062
+ */
1063
+ removeDirectoryIndex?: boolean | ReadonlyArray<RegExp | string>;
1064
+ /**
1065
+ Removes an explicit port number from the URL.
1066
+
1067
+ Port 443 is always removed from HTTPS URLs and 80 is always removed from HTTP URLs regardless of this option.
1068
+
1069
+ @default false
1070
+
1071
+ @example
1072
+ ```
1073
+ normalizeUrl('sindresorhus.com:123', {
1074
+ removeExplicitPort: true
1075
+ });
1076
+ //=> 'http://sindresorhus.com'
1077
+ ```
1078
+ */
1079
+ readonly removeExplicitPort?: boolean;
1080
+ /**
1081
+ Sorts the query parameters alphabetically by key.
1082
+
1083
+ @default true
1084
+
1085
+ @example
1086
+ ```
1087
+ normalizeUrl('www.sindresorhus.com?b=two&a=one&c=three', {
1088
+ sortQueryParameters: false
1089
+ });
1090
+ //=> 'http://sindresorhus.com/?b=two&a=one&c=three'
1091
+ ```
1092
+ */
1093
+ readonly sortQueryParameters?: boolean;
1094
+ };
1095
+ declare function normalizeUrl(urlString: string, options?: NormalizeOptions): string;
1096
+
1097
+ interface IGridRect {
1098
+ top: number;
1099
+ left: number;
1100
+ width: number;
1101
+ height: number;
1102
+ }
1103
+ declare class GridRect implements IGridRect {
1104
+ top: number;
1105
+ left: number;
1106
+ width: number;
1107
+ height: number;
1108
+ constructor(left: number, top: number, width: number, height: number);
1109
+ get right(): number;
1110
+ get bottom(): number;
1111
+ }
1112
+ declare class GridSystem extends GridRect {
1113
+ cellSize: number;
1114
+ horizontalCellCount: number;
1115
+ verticalCellCount: number;
1116
+ screenWidth: number;
1117
+ screenHeight: number;
1118
+ /**
1119
+ *
1120
+ * @param cellSize
1121
+ * @param padding 至少保留的边距
1122
+ * @param screenWidth
1123
+ * @param screenHeight
1124
+ */
1125
+ constructor(cellSize: number, padding: number, screenWidth: number, screenHeight: number);
1126
+ /**
1127
+ * 将坐标对齐到网格上
1128
+ * @param x
1129
+ * @param y
1130
+ */
1131
+ snapPosition(x: number, y: number): number[];
1132
+ snapSize(width: number, height: number): number[];
1133
+ /**
1134
+ * 将矩形对齐到网格上
1135
+ * @param rect
1136
+ * @param minWidth
1137
+ * @param maxWidth
1138
+ * @param minHeight
1139
+ * @param maxHeight
1140
+ */
1141
+ snapRect(rect: GridRect, minWidth: number, maxWidth: number, minHeight: number, maxHeight: number): IGridRect;
1142
+ private getRangeValue;
1143
+ getWidth(): number;
1144
+ getHeight(): number;
1145
+ }
1146
+
1147
+ declare class ElectronApi {
1148
+ static addIpcListener(key: String, f: Function): Promise<void>;
1149
+ static removeIpcListener(key: String): Promise<void>;
1150
+ }
1151
+
1152
+ interface SaveWidgetOption {
1153
+ sendBroadcast?: boolean;
1154
+ id?: string;
1155
+ }
1156
+ interface IWidgetDataApi {
1157
+ findByName<T extends WidgetData>(name: string, type: {
1158
+ new (name: string, id?: string): T;
1159
+ }): Promise<T | undefined>;
1160
+ findByName<T extends WidgetData>(data: T): Promise<T | undefined>;
1161
+ save(data: WidgetData): Promise<string>;
1162
+ getStore(name: string): LocalForage;
1163
+ saveByName<T extends WidgetData>(data: T, options?: SaveWidgetOption): Promise<string>;
1164
+ find<T extends WidgetData>(name: string, id: string, type: {
1165
+ new (name: string, id?: string): T;
1166
+ }): Promise<T | undefined>;
1167
+ }
1168
+ type WidgetDataApiMethods = keyof IWidgetDataApi;
1169
+ declare class WidgetDataApiImpl implements IWidgetDataApi {
1170
+ private stores;
1171
+ /**
1172
+ * 保存组件数据
1173
+ * @param data
1174
+ */
1175
+ save(data: WidgetData): Promise<string>;
1176
+ /**
1177
+ * 获取组件 LocalForage 存储实例
1178
+ * @param name
1179
+ */
1180
+ getStore(name: string): LocalForage;
1181
+ /**
1182
+ * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
1183
+ * @param data
1184
+ * @param options
1185
+ */
1186
+ saveByName<T extends WidgetData>(data: T, options?: SaveWidgetOption): Promise<string>;
1187
+ findByName<T extends WidgetData>(...args: any[]): Promise<T | undefined>;
1188
+ find<T extends WidgetData>(name: string, id: string, type: {
1189
+ new (name: string, id?: string): T;
1190
+ }): Promise<T | undefined>;
1191
+ private getKey;
1192
+ }
1193
+ declare const WidgetDataApi: IWidgetDataApi;
1194
+
1195
+ interface IBrowserWindowApi {
1196
+ setIgnoreMouseEvent(ignore: boolean): Promise<void>;
1197
+ show(): Promise<void>;
1198
+ hide(): Promise<void>;
1199
+ showInactive(): Promise<void>;
1200
+ center(): Promise<void>;
1201
+ startDraggingWindow(): Promise<void>;
1202
+ minimize(): Promise<void>;
1203
+ restore(): Promise<void>;
1204
+ isMinimized(): Promise<boolean>;
1205
+ isMaximized(): Promise<boolean>;
1206
+ maximize(): Promise<void>;
1207
+ stopDraggingWindow(): Promise<void>;
1208
+ setAlwaysOnTop(alwaysOnTop: boolean): Promise<void>;
1209
+ isAlwaysOnTop(): Promise<boolean>;
1210
+ openUrl(url: string, option?: OpenUrlOptions): Promise<void>;
1211
+ moveTop(): Promise<void>;
1212
+ unmaximize(): Promise<void>;
1213
+ reload(): Promise<void>;
1214
+ setSize(width: number, height: number, animate?: boolean): Promise<void>;
1215
+ openDevTools(): Promise<void>;
1216
+ setPosition(options: SetPositionOptions): Promise<void>;
1217
+ getPosition(): Promise<Position>;
1218
+ blur(): Promise<void>;
1219
+ focus(): Promise<void>;
1220
+ setResizable(resizable: boolean): Promise<void>;
1221
+ setMovable(movable: boolean): Promise<void>;
1222
+ getBounds(): Promise<Rectangle>;
1223
+ setBounds(bounds: Partial<Rectangle>, animate: boolean): Promise<void>;
1224
+ alignToScreen(align: AlignPosition): Promise<void>;
1225
+ existsByUrl(url: string): Promise<boolean>;
1226
+ getMaximumSize(): Promise<number[]>;
1227
+ getMinimumSize(): Promise<number[]>;
1228
+ setMaximumSize(width: number, height: number): Promise<void>;
1229
+ setMinimumSize(width: number, height: number): Promise<void>;
1230
+ setZoomLevel(level: number): Promise<void>;
1231
+ isFocused(): Promise<boolean>;
1232
+ }
1233
+ type BrowserWindowApiMethods = keyof IBrowserWindowApi;
1234
+ type AlignPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
1235
+ interface OpenUrlOptions {
1236
+ partition?: string;
1237
+ external?: boolean;
1238
+ }
1239
+ interface SetPositionOptions {
1240
+ x?: number;
1241
+ y?: number;
1242
+ /**
1243
+ * 只有在 macOS 上有效
1244
+ */
1245
+ animation?: boolean;
1246
+ }
1247
+ declare enum BrowserWindowApiEvent {
1248
+ BLUR = "event::cn.widgetjs.core.browser-window.blur",
1249
+ FOCUS = "event::cn.widgetjs.core.browser-window.focus",
1250
+ SNAP_TO_EDGE = "event::cn.widgetjs.core.browser-window.snap_to_edge",
1251
+ RESIZE = "event::cn.widgetjs.core.browser-window.resize",
1252
+ CANCEL_SNAP_TO_EDGE = "event::cn.widgetjs.core.browser-window.cancel_snap_to_edge"
1253
+ }
1254
+ declare class BrowserWindowApiImpl extends BaseApi<BrowserWindowApiMethods> implements IBrowserWindowApi {
1255
+ getChannel(): string;
1256
+ setIgnoreMouseEvent(ignore: boolean): Promise<void>;
1257
+ show(): Promise<void>;
1258
+ showInactive(): Promise<void>;
1259
+ hide(): Promise<void>;
1260
+ center(): Promise<void>;
1261
+ setAlwaysOnTop(alwaysOnTop: boolean): Promise<void>;
1262
+ isAlwaysOnTop(): Promise<boolean>;
1263
+ openUrl(url: string, option?: OpenUrlOptions): Promise<void>;
1264
+ moveTop(): Promise<void>;
1265
+ openDevTools(): Promise<void>;
1266
+ setPosition(options: SetPositionOptions): Promise<void>;
1267
+ getPosition(): Promise<Position>;
1268
+ blur(): Promise<any>;
1269
+ focus(): Promise<any>;
1270
+ /**
1271
+ * 设置窗口是否可以拉伸
1272
+ * @param resizable
1273
+ */
1274
+ setResizable(resizable: boolean): Promise<any>;
1275
+ getBounds(): Promise<Rectangle>;
1276
+ setBounds(bounds: Partial<Rectangle>, animate?: boolean): Promise<void>;
1277
+ alignToScreen(align: AlignPosition): Promise<any>;
1278
+ startDraggingWindow(): Promise<any>;
1279
+ stopDraggingWindow(): Promise<any>;
1280
+ /**
1281
+ * 通过url检测窗口是否存在
1282
+ * @param url
1283
+ */
1284
+ existsByUrl(url: string): Promise<boolean>;
1285
+ getMaximumSize(): Promise<number[]>;
1286
+ minimize(): Promise<void>;
1287
+ maximize(): Promise<void>;
1288
+ isMaximized(): Promise<boolean>;
1289
+ isMinimized(): Promise<boolean>;
1290
+ restore(): Promise<void>;
1291
+ unmaximize(): Promise<void>;
1292
+ setZoomLevel(level: number): Promise<void>;
1293
+ reload(): Promise<void>;
1294
+ setMovable(movable: boolean): Promise<void>;
1295
+ setSize(width: number, height: number, animate?: boolean): Promise<void>;
1296
+ isFocused(): Promise<boolean>;
1297
+ setMaximumSize(width: number, height: number): Promise<void>;
1298
+ setMinimumSize(width: number, height: number): Promise<void>;
1299
+ getMinimumSize(): Promise<number[]>;
1300
+ }
1301
+ declare const BrowserWindowApi: BrowserWindowApiImpl;
1302
+
1303
+ interface INotificationApi {
1304
+ send(notification: AppNotification): Promise<void>;
1305
+ hide(): Promise<void>;
1306
+ }
1307
+ type NotificationApiMethods = keyof INotificationApi;
1308
+ declare enum NotificationApiEvent {
1309
+ CONFIRM = "event::cn.widgetjs.core.notification.confirm",
1310
+ CANCEL = "event::cn.widgetjs.core.notification.cancel",
1311
+ HIDE = "event::cn.widgetjs.core.notification.hide"
1312
+ }
1313
+ declare class NotificationApiImpl extends BaseApi<NotificationApiMethods> implements INotificationApi {
1314
+ /**
1315
+ * 来电
1316
+ * @param avatar 头像地址
1317
+ * @param audio 音频地址
1318
+ * @param title 标题文件
1319
+ * @param message 初始消息
1320
+ * @param lyric 歌词字符串
1321
+ */
1322
+ call(avatar: string, audio: string, title: string, message: string, lyric: string): Promise<void>;
1323
+ send(notification: AppNotification): Promise<any>;
1324
+ reminder(title: string, message: string, icon: string, cancelButtonText: string, confirmButtonText: string, cancelBroadcast: string, confirmBroadcast: string, duration?: number): Promise<any>;
1325
+ advanceCountdown(message: string, targetTime: string, title?: string): Promise<any>;
1326
+ countdown(message: string, targetTime: string): Promise<void>;
1327
+ success(message: string, duration?: number): Promise<void>;
1328
+ error(message: string, duration?: number): Promise<void>;
1329
+ warning(message: string, duration?: number): Promise<void>;
1330
+ info(message: string, duration?: number): Promise<void>;
1331
+ /**
1332
+ * 隐藏通知
1333
+ */
1334
+ hide(): Promise<void>;
1335
+ getChannel(): string;
1336
+ }
1337
+ declare const NotificationApi: NotificationApiImpl;
1338
+
1339
+ interface IHostedWidgetApi {
1340
+ removeHostedWidget(id: string): Promise<void>;
1341
+ removeHostedWidgetByName(name: string): Promise<HostedWidget[]>;
1342
+ getHostedWidgets(): Promise<HostedWidget[]>;
1343
+ openDevTools(id: string): Promise<void>;
1344
+ openConfigRoute(id: string): Promise<void>;
1345
+ registerActiveShortcut(id: string, shortcut: string): Promise<boolean>;
1346
+ setProxy(id: string, proxy: string): Promise<boolean>;
1347
+ getHostedWidget(id: string): Promise<HostedWidget>;
1348
+ addWidget(widgetName: string, hostMode: DeployedMode): Promise<Widget[]>;
1349
+ }
1350
+ type HostedWidgetApiMethods = keyof IHostedWidgetApi;
1351
+ declare class HostedWidgetApiImpl extends BaseApi<HostedWidgetApiMethods> implements IHostedWidgetApi {
1352
+ getChannel(): string;
1353
+ /**
1354
+ * 移除组件
1355
+ * @param id
1356
+ */
1357
+ removeHostedWidget(id: string): Promise<any>;
1358
+ addWidget(widgetName: string, hostMode: DeployedMode): Promise<Widget[]>;
1359
+ /**
1360
+ * 通过组件名移除已添加的组件
1361
+ * @param name 组件名
1362
+ */
1363
+ removeHostedWidgetByName(name: string): Promise<HostedWidget[]>;
1364
+ /**
1365
+ * 获取已添加的组件
1366
+ * @param name 组件名,可以不传
1367
+ */
1368
+ getHostedWidgets(name?: string): Promise<HostedWidget[]>;
1369
+ getHostedWidget(id: string): Promise<HostedWidget>;
1370
+ /**
1371
+ * Opens the dev tools for a widget with the specified ID.
1372
+ *
1373
+ * @param {string} widgetId - The ID of the widget to open the dev tools for.
1374
+ * @return {Promise} A Promise that resolves when the dev tools are opened.
1375
+ */
1376
+ openDevTools(widgetId: string): Promise<any>;
1377
+ openConfigRoute(widgetId: string, params?: WidgetParams): Promise<any>;
1378
+ /**
1379
+ * 注册激活、呼出、置顶组件快捷键
1380
+ * @param widgetId 组件id
1381
+ * @param shortcut 如果传空或者不传,则会取消快捷键。更多快捷键配置,请查看Accelerator用法
1382
+ * https://www.electronjs.org/docs/latest/api/accelerator
1383
+ */
1384
+ registerActiveShortcut(widgetId: string, shortcut?: string): Promise<boolean>;
1385
+ setProxy(widgetId: string, proxy: string): Promise<boolean>;
1386
+ }
1387
+ declare const HostedWidgetApi: HostedWidgetApiImpl;
1388
+
1389
+ interface IDeviceApi {
1390
+ getCursorScreenPoint(): Promise<Point>;
1391
+ isAllKeyReleased(): Promise<boolean>;
1392
+ }
1393
+ type DeviceApiMethods = keyof IDeviceApi;
1394
+ declare class DeviceApiImpl extends BaseApi<DeviceApiMethods> implements IDeviceApi {
1395
+ /**
1396
+ * 获取当前鼠标位置
1397
+ */
1398
+ getCursorScreenPoint(): Promise<Point>;
1399
+ /**
1400
+ * 判断是否所有按键都已经释放
1401
+ */
1402
+ isAllKeyReleased(): Promise<boolean>;
1403
+ getChannel(): string;
1404
+ }
1405
+ declare const DeviceApi: IDeviceApi;
1406
+
1407
+ declare enum Channel {
1408
+ NOTIFICATION = "channel::cn.widgetjs.core.notification",
1409
+ BROWSER_WINDOW = "channel::cn.widgetjs.core.browser_window",
1410
+ BROADCAST = "channel::cn.widgetjs.core.broadcast",
1411
+ WIDGET = "channel::cn.widgetjs.core.widget",
1412
+ HOSTED_WIDGET = "channel::cn.widgetjs.core.hosted_widget",
1413
+ APP = "channel::cn.widgetjs.core.app",
1414
+ DIALOG = "channel::cn.widgetjs.core.dialog",
1415
+ CLIPBOARD = "channel::cn.widgetjs.core.clipboard",
1416
+ FILE = "channel::cn.widgetjs.core.file",
1417
+ SCREEN = "channel::cn.widgetjs.core.screen",
1418
+ SHORTCUT = "channel::cn.widgetjs.core.shortcut",
1419
+ LOG = "channel::cn.widgetjs.core.log",
1420
+ DEVICE = "channel::cn.widgetjs.core.device",
1421
+ MOUSE = "channel::cn.widgetjs.core.mouse",
1422
+ KEYBOARD = "channel::cn.widgetjs.core.keyboard",
1423
+ STORE = "channel::cn.widgetjs.core.store"
1424
+ }
1425
+
1426
+ interface IClipboardApi {
1427
+ getSelectedText(): Promise<string | undefined>;
1428
+ getText(): Promise<string | undefined>;
1429
+ }
1430
+ type ClipboardApiMethods = keyof IClipboardApi;
1431
+ declare enum ClipboardApiEvent {
1432
+ CHANGED = "clipboard-changed"
1433
+ }
1434
+ declare const ClipboardApi: IClipboardApi;
1435
+
1436
+ declare class ApiConstants {
1437
+ static readonly CONFIG_LAUNCH_AT_STARTUP = "CONFIG_LAUNCH_AT_STARTUP";
1438
+ static readonly CONFIG_WIDGET_TITLE_COLOR = "CONFIG_WIDGET_TITLE_COLOR";
1439
+ static readonly CONFIG_DEBUG_MODE = "cn.widgetjs.config.debug";
1440
+ static readonly CONFIG_GRID_CELL_SIZE = "cn.widgetjs.config.grid.size";
1441
+ static readonly SHORTCUT_PIN_DESKTOP_WIDGETS = "cn.widgetjs.config.shortcut.pin_desktop_widgets";
1442
+ }
1443
+
1444
+ interface IShortcutApi {
1445
+ register(shortcut: string): void;
1446
+ unregister(shortcut: string): void;
1447
+ }
1448
+ type ShortcutApiMethods = keyof IShortcutApi;
1449
+ declare enum ShortcutApiEvent {
1450
+ TRIGGERED = "channel::cn.widgetjs.core.shortcut.triggered"
1451
+ }
1452
+ declare const ShortcutApi: IShortcutApi;
1453
+
1454
+ type BroadcastEventType = WidgetApiEvent | BrowserWindowApiEvent | ShortcutApiEvent | ClipboardApiEvent | string;
1455
+ interface IBroadcastApi {
1456
+ send(event: BroadcastEvent): Promise<void>;
1457
+ register(...event: BroadcastEventType[]): Promise<void>;
1458
+ unregister(...event: BroadcastEventType[]): Promise<void>;
1459
+ }
1460
+ type BroadcastApiMethods = keyof IBroadcastApi;
1461
+ declare class BroadcastApiImpl extends BaseApi<BroadcastApiMethods> implements IBroadcastApi {
1462
+ send(event: BroadcastEvent): Promise<void>;
1463
+ register(...event: BroadcastEventType[]): Promise<void>;
1464
+ unregister(...event: BroadcastEventType[]): Promise<void>;
1465
+ getChannel(): string;
1466
+ }
1467
+ declare const BroadcastApi: IBroadcastApi;
1468
+
1469
+ interface IDialogApi {
1470
+ pickFile(extensions?: string[]): Promise<string | undefined>;
1471
+ pickFolder(): Promise<string | undefined>;
1472
+ }
1473
+ type DialogApiMethods = keyof IDialogApi;
1474
+ declare const DialogApi: IDialogApi;
1475
+
1476
+ type BaseType = string | number | boolean;
1477
+ interface IStoreApi {
1478
+ get<T extends BaseType>(key: string, defaultValue?: T): Promise<T | null>;
1479
+ set(key: string, value: BaseType | object): Promise<string>;
1480
+ getObject<T>(key: string, defaultValue?: T): Promise<T | undefined>;
1481
+ delete(key: string): Promise<void>;
1482
+ }
1483
+ type StoreApiMethods = keyof IStoreApi;
1484
+ declare const StoreApi: IStoreApi;
1485
+
1486
+ interface ILogApi {
1487
+ info(...data: any[]): void;
1488
+ error(...data: any[]): void;
1489
+ warn(...data: any[]): void;
1490
+ log(...data: any[]): void;
1491
+ }
1492
+ type LogApiMethods = keyof ILogApi;
1493
+ declare const LogApi: ILogApi;
1494
+
1495
+ interface ReadDirOptions {
1496
+ ignoreDir?: boolean;
1497
+ traverseDir?: boolean;
1498
+ }
1499
+ interface IFileApi {
1500
+ readDirectory(path: string, options?: ReadDirOptions): Promise<string[]>;
1501
+ isDirectory(filePath: string): Promise<boolean>;
1502
+ getFileType(filePath: string): Promise<FileTypeResult>;
1503
+ }
1504
+ type FileApiMethods = keyof IFileApi;
1505
+ declare const FileApi: IFileApi;
1506
+
1507
+ export { AlignPosition, ApiConstants, AppApi, AppApiConstants, AppApiEvent, AppApiMethods, AppMouseEvent, AppNotification, BaseApi, BroadcastApi, BroadcastApiImpl, BroadcastApiMethods, BroadcastEvent, BroadcastEventType, BrowserWindowApi, BrowserWindowApiEvent, BrowserWindowApiImpl, BrowserWindowApiMethods, Channel, ClipboardApi, ClipboardApiEvent, ClipboardApiMethods, DeployedMode, DeployedPage, DeployedWidget, DevOptions, DeviceApi, DeviceApiImpl, DeviceApiMethods, DialogApi, DialogApiMethods, ElectronApi, ElectronUtils, FileApi, FileApiMethods, Gravity, GridRect, GridSystem, HostedMode, HostedWidget, HostedWidgetApi, HostedWidgetApiImpl, HostedWidgetApiMethods, IGridRect, IPage, IWidgetDataApi, IWidgetOptions, IWindowOptions, IWindowSize, LanguageCode, LanguageTextMap, LocalPackageUrlInfo, LocationQuery, LocationQueryRaw, LocationQueryValue, LocationQueryValueRaw, LogApi, LogApiMethods, MetaInfo, NativeKeyboardEvent, NormalizeOptions, NotificationApi, NotificationApiEvent, NotificationApiMethods, NotificationOption, NotificationSize, NotificationType, OpenUrlOptions, Page, Point, Position, ReadDirOptions, Rectangle, RemotePackageUrlInfo, SaveWidgetOption, SetPositionOptions, ShortcutApi, ShortcutApiEvent, ShortcutApiMethods, StoreApi, StoreApiMethods, ThemeMode, WebSocketEvent, WebSocketEventType, Widget, WidgetApi, WidgetApiEvent, WidgetApiMethods, WidgetData, WidgetDataApi, WidgetDataApiImpl, WidgetDataApiMethods, WidgetKeyword, WidgetPackage, WidgetPackageOptions, WidgetParams, WidgetPermission, WidgetRoute, WidgetUrlUtils, normalizeUrl, parseQuery, stringifyQuery };