@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
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WidgetDataApi = exports.WidgetDataApiImpl = void 0;
7
- const localforage_1 = __importDefault(require("localforage"));
8
- const BroadcastEvent_1 = require("../model/event/BroadcastEvent");
9
- const BroadcastApi_1 = require("./BroadcastApi");
10
- const WidgetApi_1 = require("./WidgetApi");
11
- class WidgetDataApiImpl {
12
- constructor() {
13
- this.stores = new Map();
14
- }
15
- /**
16
- * 保存组件数据
17
- * @param data
18
- */
19
- async save(data) {
20
- let store = this.getStore(data.name);
21
- let json = JSON.stringify(data);
22
- const result = await store.setItem(this.getKey(data.name, data.id), json);
23
- const broadcastEvent = new BroadcastEvent_1.BroadcastEvent({
24
- event: WidgetApi_1.WidgetApiEvent.DATA_CHANGED, payload: { name: data.name, json }
25
- });
26
- await BroadcastApi_1.BroadcastApi.send(broadcastEvent);
27
- return result;
28
- }
29
- /**
30
- * 获取组件 LocalForage 存储实例
31
- * @param name
32
- */
33
- getStore(name) {
34
- if (this.stores.has(name)) {
35
- return this.stores.get(name);
36
- }
37
- const store = localforage_1.default.createInstance({ name: name });
38
- this.stores.set(name, store);
39
- return store;
40
- }
41
- /**
42
- * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
43
- * @param data
44
- * @param options
45
- */
46
- async saveByName(data, options = { sendBroadcast: true }) {
47
- const store = this.getStore(data.name);
48
- const json = JSON.stringify(data);
49
- const result = await store.setItem(data.name, json);
50
- if (options === null || options === void 0 ? void 0 : options.sendBroadcast) {
51
- const broadcastEvent = new BroadcastEvent_1.BroadcastEvent({
52
- event: WidgetApi_1.WidgetApiEvent.DATA_CHANGED, payload: { name: data.name, json }
53
- });
54
- await BroadcastApi_1.BroadcastApi.send(broadcastEvent);
55
- }
56
- return result;
57
- }
58
- async findByName(...args) {
59
- let name = '';
60
- let dbStr = '';
61
- let data;
62
- if (args.length === 2) {
63
- name = args[0];
64
- const type = args[1];
65
- data = new type(name);
66
- }
67
- else {
68
- data = args[0];
69
- name = data.name;
70
- }
71
- let store = this.getStore(name);
72
- dbStr = await store.getItem(name);
73
- if (dbStr) {
74
- data.parseJSON(JSON.parse(dbStr));
75
- return data;
76
- }
77
- return undefined;
78
- }
79
- async find(name, id, type) {
80
- let store = this.getStore(name);
81
- let result = await store.getItem(this.getKey(name, id));
82
- if (result) {
83
- const widgetData = new type(name, id);
84
- widgetData.parseJSON(JSON.parse(result));
85
- return widgetData;
86
- }
87
- return undefined;
88
- }
89
- getKey(name, id) {
90
- return `${name}@${id}`;
91
- }
92
- }
93
- exports.WidgetDataApiImpl = WidgetDataApiImpl;
94
- const WidgetDataApi = new WidgetDataApiImpl();
95
- exports.WidgetDataApi = WidgetDataApi;
package/dist/cjs/index.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./model/Widget"), exports);
18
- __exportStar(require("./model/event/BroadcastEvent"), exports);
19
- __exportStar(require("./model/event/WebSocketEvent"), exports);
20
- __exportStar(require("./model/WidgetData"), exports);
21
- __exportStar(require("./model/WidgetParams"), exports);
22
- __exportStar(require("./model/AppNotification"), exports);
23
- __exportStar(require("./model/HostedMode"), exports);
24
- __exportStar(require("./model/HostedWidget"), exports);
25
- __exportStar(require("./model/interface/Rectangle"), exports);
26
- __exportStar(require("./model/msic/graphics"), exports);
27
- __exportStar(require("./model/event/NativeKeyboardEvent"), exports);
28
- __exportStar(require("./model/event/AppMouseEvent"), exports);
29
- __exportStar(require("./model/WidgetPackage"), exports);
30
- __exportStar(require("./api/ElectronApi"), exports);
31
- __exportStar(require("./api/WidgetDataApi"), exports);
32
- __exportStar(require("./api/BrowserWindowApi"), exports);
33
- __exportStar(require("./lang/LanguageCode"), exports);
34
- __exportStar(require("./api/NotificationApi"), exports);
35
- __exportStar(require("./api/HostedWidgetApi"), exports);
36
- __exportStar(require("./api/DeviceApi"), exports);
37
- __exportStar(require("./api/Channel"), exports);
38
- __exportStar(require("./api/ClipboardApi"), exports);
39
- __exportStar(require("./api/WidgetApi"), exports);
40
- __exportStar(require("./api/ApiConstants"), exports);
41
- __exportStar(require("./api/ShortcutApi"), exports);
42
- __exportStar(require("./api/BroadcastApi"), exports);
43
- __exportStar(require("./api/AppApi"), exports);
44
- __exportStar(require("./api/DialogApi"), exports);
45
- __exportStar(require("./api/StoreApi"), exports);
46
- __exportStar(require("./utils/ElectronUtils"), exports);
47
- __exportStar(require("./api/FileApi"), exports);
48
- __exportStar(require("./utils/UrlUtils"), exports);
49
- __exportStar(require("./router/query"), exports);
50
- __exportStar(require("./api/LogApi"), exports);
51
- __exportStar(require("./permission/permission"), exports);
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class LanguageMapImpl {
4
- constructor() {
5
- this['ar-SA'] = { locale: 'ar-SA', language: 'العربية', code: 'ar' };
6
- this['bn-BD'] = { locale: 'bn-BD', language: 'বাংলা', code: 'bn' };
7
- this['en-US'] = { locale: 'en-US', language: 'English', code: 'en' };
8
- this['de-DE'] = { locale: 'de-DE', language: 'Deutsch', code: 'de' };
9
- this['el-GR'] = { locale: 'el-GR', language: 'Ελληνικά', code: 'el' };
10
- this['es-ES'] = { locale: 'es-ES', language: 'Español', code: 'es-ES' };
11
- this['fi-FI'] = { locale: 'fi-FI', language: 'Suomalainen', code: 'fi' };
12
- this['fil-PH'] = { locale: 'fil-PH', language: 'Filipino', code: 'fil' };
13
- this['fr-FR'] = { locale: 'fr-FR', language: 'Français', code: 'fr' };
14
- this['hi-IN'] = { locale: 'hi-IN', language: 'हिंदी', code: 'hi' };
15
- this['hu-HU'] = { locale: 'hu-HU', language: 'Magyar', code: 'hu' };
16
- this['id-ID'] = { locale: 'id-ID', language: 'Bahasa Indonesia', code: 'id' };
17
- this['it-IT'] = { locale: 'it-IT', language: 'Italiano', code: 'it' };
18
- this['ja-JP'] = { locale: 'ja-JP', language: '日本語', code: 'ja' };
19
- this['ko-KR'] = { locale: 'ko-KR', language: '한국어', code: 'ko' };
20
- this['nl-NL'] = { locale: 'nl-NL', language: 'Nederlands', code: 'nl' };
21
- this['pl-PL'] = { locale: 'pl-PL', language: 'Polski', code: 'pl' };
22
- this['pt-BR'] = { locale: 'pt-BR', language: 'Português (Brazil)', code: 'pt-br' };
23
- this['pt-PT'] = { locale: 'pt-PT', language: 'Português', code: 'pt-pt' };
24
- this['ro-RO'] = { locale: 'ro-RO', language: 'Română', code: 'ro' };
25
- this['ru-RU'] = { locale: 'ru-RU', language: 'Русский', code: 'ru' };
26
- this['sv-SE'] = { locale: 'sv-SE', language: 'Svenska', code: 'sv' };
27
- this['ta-IN'] = { locale: 'ta-IN', language: 'தமிழ்', code: 'ta' };
28
- this['tr-TR'] = { locale: 'tr-TR', language: 'Türkçe', code: 'tr' };
29
- this['uk-UA'] = { locale: 'uk-UA', language: 'Українська', code: 'uk' };
30
- this['vi-VN'] = { locale: 'vi-VN', language: 'Tiếng Việt', code: 'vi' };
31
- this['zh-CN'] = { locale: 'zh-CN', language: '简体中文', code: 'zh-cn' };
32
- this['zh-TW'] = { locale: 'zh-TW', language: '繁體中文', code: 'zh-tw' };
33
- }
34
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppNotification = exports.NotificationSize = void 0;
4
- var NotificationSize;
5
- (function (NotificationSize) {
6
- NotificationSize["SMALL"] = "small";
7
- NotificationSize["NORMAL"] = "normal";
8
- NotificationSize["LARGE"] = "large";
9
- })(NotificationSize = exports.NotificationSize || (exports.NotificationSize = {}));
10
- class AppNotification {
11
- constructor(option) {
12
- var _a, _b, _c, _d, _e;
13
- this.type = "info";
14
- this.createdAt = new Date().toISOString();
15
- this.type = (_a = option.type) !== null && _a !== void 0 ? _a : "info";
16
- this.title = option.title;
17
- this.message = option.message;
18
- this.targetTime = option.targetTime;
19
- this.duration = (_b = option.duration) !== null && _b !== void 0 ? _b : 5000;
20
- this.icon = option.icon;
21
- this.color = (_c = option.color) !== null && _c !== void 0 ? _c : "#5D8AC8";
22
- this.confirmButtonText = option.confirmButtonText;
23
- this.cancelButtonText = option.cancelButtonText;
24
- this.cancelBroadcast = option.cancelBroadcast;
25
- this.confirmBroadcast = option.confirmBroadcast;
26
- this.size = (_d = option.size) !== null && _d !== void 0 ? _d : NotificationSize.NORMAL;
27
- this.audio = option.audio;
28
- this.avatar = option.avatar;
29
- this.lyric = option.lyric;
30
- this.backgroundColor = (_e = option.backgroundColor) !== null && _e !== void 0 ? _e : '#000000';
31
- }
32
- }
33
- exports.AppNotification = AppNotification;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class BrowserWindowStatus {
4
- constructor(width, height) {
5
- this.isAlwaysOnTop = false;
6
- this.isAutoHide = false;
7
- this.height = height;
8
- this.width = width;
9
- }
10
- }
11
- exports.default = BrowserWindowStatus;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HostedMode = void 0;
4
- var HostedMode;
5
- (function (HostedMode) {
6
- HostedMode[HostedMode["NORMAL"] = 1] = "NORMAL";
7
- /**
8
- * 悬浮窗
9
- */
10
- HostedMode[HostedMode["OVERLAP"] = 16] = "OVERLAP";
11
- HostedMode[HostedMode["WALLPAPER"] = 256] = "WALLPAPER";
12
- HostedMode[HostedMode["SCREEN"] = 4096] = "SCREEN";
13
- /**
14
- * 后台组件,没有界面,一般在后台执行定时任务
15
- */
16
- HostedMode[HostedMode["BACKGROUND"] = 65536] = "BACKGROUND";
17
- HostedMode[HostedMode["ALL"] = 69905] = "ALL";
18
- })(HostedMode = exports.HostedMode || (exports.HostedMode = {}));
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HostedWidget = void 0;
4
- const HostedMode_1 = require("./HostedMode");
5
- class HostedWidget {
6
- constructor() {
7
- this.x = 0;
8
- this.y = 0;
9
- }
10
- isOverlap() {
11
- return (this.hostedMode & HostedMode_1.HostedMode.OVERLAP) > 0;
12
- }
13
- }
14
- exports.HostedWidget = HostedWidget;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SocialInfo = void 0;
4
- class SocialInfo {
5
- constructor(name, url) {
6
- this.name = name;
7
- this.content = url;
8
- }
9
- }
10
- exports.SocialInfo = SocialInfo;
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WidgetKeyword = exports.Widget = void 0;
4
- const HostedMode_1 = require("./HostedMode");
5
- const LanguageUtils_1 = require("../utils/LanguageUtils");
6
- class Widget {
7
- constructor(options) {
8
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
9
- /**
10
- * 组件默认语言
11
- */
12
- this.lang = "zh-CN";
13
- this.name = options.name;
14
- this.title = options.title;
15
- this.description = options.description;
16
- this.keywords = options.keywords;
17
- this.lang = options.lang;
18
- this.width = options.width;
19
- this.height = options.height;
20
- this.movable = (_a = options.movable) !== null && _a !== void 0 ? _a : true;
21
- this.permissions = (_b = options.permissions) !== null && _b !== void 0 ? _b : [];
22
- this.maxWidth = (_c = options.maxWidth) !== null && _c !== void 0 ? _c : options.width;
23
- this.maxHeight = (_d = options.maxHeight) !== null && _d !== void 0 ? _d : options.height;
24
- this.minWidth = (_e = options.minWidth) !== null && _e !== void 0 ? _e : options.width;
25
- this.minHeight = (_f = options.minHeight) !== null && _f !== void 0 ? _f : options.height;
26
- this.backgroundThrottling = (_g = options.backgroundThrottling) !== null && _g !== void 0 ? _g : true;
27
- this.packageName = options.packageName;
28
- this.previewImage = options.previewImage;
29
- this.shortcut = options.shortcut;
30
- this.refreshWhenResided = (_h = options.refreshWhenResided) !== null && _h !== void 0 ? _h : false;
31
- this.hideWhenBlur = options.hideWhenBlur == null ? false : options.hideWhenBlur;
32
- this.supportHostedMode = (_j = options.supportHostedMode) !== null && _j !== void 0 ? _j : HostedMode_1.HostedMode.NORMAL | HostedMode_1.HostedMode.OVERLAP;
33
- this.routes = options.routes;
34
- }
35
- getIndexRoute() {
36
- const result = this.routes.find((it) => it.name.toLowerCase() == 'index');
37
- return result;
38
- }
39
- getConfigRoute() {
40
- return this.routes.find((it) => it.name.toLowerCase() == 'config');
41
- }
42
- isConfigurable() {
43
- return this.getConfigRoute() != null;
44
- }
45
- /**
46
- * 获取组件标题
47
- * @param lang 语言环境,不传则获取默认语言
48
- */
49
- getTitle(lang) {
50
- return (0, LanguageUtils_1.getTextByLanguageCode)(this.title, lang);
51
- }
52
- /**
53
- * 获取组件描述
54
- * @param lang 语言环境,不传则获取默认标题
55
- */
56
- getDescription(lang) {
57
- return (0, LanguageUtils_1.getTextByLanguageCode)(this.description, lang);
58
- }
59
- static parseJSON(json) {
60
- const object = JSON.parse(json);
61
- return this.parseObject(object);
62
- }
63
- static parseObject(obj) {
64
- let widget = new Widget({
65
- description: {},
66
- height: 0,
67
- keywords: [],
68
- lang: "zh-CN",
69
- name: "",
70
- routes: [],
71
- title: {},
72
- width: 0
73
- });
74
- Object.assign(widget, obj);
75
- return widget;
76
- }
77
- /**
78
- * 是否支持悬浮窗
79
- */
80
- isSupportOverlap() {
81
- return (this.supportHostedMode & HostedMode_1.HostedMode.OVERLAP) > 0;
82
- }
83
- isResizable() {
84
- return !(this.minWidth == this.width &&
85
- this.maxWidth == this.width &&
86
- this.minHeight == this.height &&
87
- this.maxHeight == this.height);
88
- }
89
- isSupportBackground() {
90
- return (this.supportHostedMode & HostedMode_1.HostedMode.BACKGROUND) > 0;
91
- }
92
- /**
93
- * 是否支持普通模式
94
- */
95
- isSupportNormal() {
96
- return (this.supportHostedMode & HostedMode_1.HostedMode.NORMAL) > 0;
97
- }
98
- isSupportWallpaper() {
99
- return (this.supportHostedMode & HostedMode_1.HostedMode.WALLPAPER) > 0;
100
- }
101
- isSupportScreen() {
102
- return (this.supportHostedMode & HostedMode_1.HostedMode.SCREEN) > 0;
103
- }
104
- }
105
- exports.Widget = Widget;
106
- var WidgetKeyword;
107
- (function (WidgetKeyword) {
108
- WidgetKeyword["RECOMMEND"] = "recommend";
109
- WidgetKeyword["TOOLS"] = "tools";
110
- WidgetKeyword["EFFICIENCY"] = "efficiency";
111
- WidgetKeyword["PICTURE"] = "picture";
112
- WidgetKeyword["LIFE"] = "life";
113
- WidgetKeyword["SHORTCUT"] = "shortcut";
114
- WidgetKeyword["COUNTDOWN"] = "countdown";
115
- WidgetKeyword["TIMER"] = "timer";
116
- WidgetKeyword["INFO"] = "info";
117
- WidgetKeyword["DASHBOARD"] = "dashboard";
118
- })(WidgetKeyword = exports.WidgetKeyword || (exports.WidgetKeyword = {}));
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WidgetData = void 0;
4
- /**
5
- * 组件配置数据,用于存储组件自定义页面所设置的数据
6
- */
7
- class WidgetData {
8
- constructor(name, id) {
9
- this.id = id;
10
- this.name = name;
11
- }
12
- parseJSON(json) {
13
- Object.assign(this, json);
14
- }
15
- }
16
- exports.WidgetData = WidgetData;
@@ -1,98 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WidgetPackage = void 0;
4
- const Widget_1 = require("./Widget");
5
- const UrlUtils_1 = require("../utils/UrlUtils");
6
- const LanguageUtils_1 = require("../utils/LanguageUtils");
7
- class WidgetPackage {
8
- constructor(options) {
9
- /**
10
- * Hash路由模式,默认为true
11
- */
12
- this.hash = true;
13
- this.widgets = [];
14
- this.name = options.name;
15
- this.version = options.version;
16
- this.author = options.author;
17
- this.homepage = options.homepage;
18
- this.title = options.title;
19
- this.description = options.description;
20
- this.entry = options.entry;
21
- this.remoteEntry = options.remoteEntry;
22
- this.remotePackage = options.remotePackage;
23
- this.hash = options.hash;
24
- this.url = options.url;
25
- this.icon = options.icon;
26
- this.devOptions = options.devOptions;
27
- if (options.widgets) {
28
- for (let widget of options.widgets) {
29
- this.widgets.push(widget);
30
- }
31
- }
32
- }
33
- static parseJSON(json) {
34
- const object = JSON.parse(json);
35
- return this.parseObject(object);
36
- }
37
- static parseObject(obj) {
38
- let widgetPackage = new WidgetPackage({
39
- author: "",
40
- description: {
41
- "zh-CN": "",
42
- },
43
- entry: "",
44
- hash: false,
45
- homepage: "",
46
- name: "",
47
- title: {
48
- "zh-CN": "",
49
- },
50
- url: "",
51
- version: ""
52
- });
53
- Object.assign(widgetPackage, obj);
54
- const widgets = [];
55
- if (widgetPackage.widgets) {
56
- for (let jsonWidget of widgetPackage.widgets) {
57
- let widget = new Widget_1.Widget({
58
- description: { "zh-CN": "" },
59
- height: 0,
60
- keywords: [],
61
- lang: "zh-CN",
62
- name: '',
63
- routes: [],
64
- title: { "zh-CN": "" },
65
- width: 0
66
- });
67
- Object.assign(widget, jsonWidget);
68
- widgets.push(widget);
69
- }
70
- }
71
- widgetPackage.widgets.splice(0, widgetPackage.widgets.length);
72
- widgetPackage.widgets.push(...widgets);
73
- return widgetPackage;
74
- }
75
- /**
76
- * 获取组件包标题
77
- * @param lang 语言环境,不传则获取默认语言
78
- */
79
- getTitle(lang) {
80
- return (0, LanguageUtils_1.getTextByLanguageCode)(this.title, lang);
81
- }
82
- /**
83
- * 获取组件包描述
84
- * @param lang 语言环境,不传则获取默认标题
85
- */
86
- getDescription(lang) {
87
- return (0, LanguageUtils_1.getTextByLanguageCode)(this.description, lang);
88
- }
89
- /**
90
- * 获取组件完整路径
91
- * 如果url是http链接,直接返回链接
92
- * 如果是本地组件:file://链接,则返回 url+entry,e.g. file://C:\users\neo\desktop\index.html#
93
- */
94
- getIndexUrl(hash) {
95
- return UrlUtils_1.UrlUtils.getWidgetPackageIndexUrl(this.url, this.entry, hash == null ? this.hash : hash);
96
- }
97
- }
98
- exports.WidgetPackage = WidgetPackage;
@@ -1,151 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ThemeMode = exports.WidgetParams = void 0;
4
- /**
5
- * 组件参数,如宽,高,id,语言等环境参数
6
- */
7
- const query_1 = require("../router/query");
8
- const change_case_1 = require("change-case");
9
- class WidgetParams {
10
- /**
11
- * 将组件参数转为url参数
12
- * @param object
13
- * @return URLSearchParams w_w=2&w_h=2&w_id=21&w_width=156&w_height=156
14
- */
15
- toUrlParams() {
16
- const urlParams = new URLSearchParams();
17
- const ownPropertyNames = Object.getOwnPropertyNames(this);
18
- for (let ownPropertyName of ownPropertyNames) {
19
- const key = ownPropertyName;
20
- const value = this[key];
21
- if (value) {
22
- urlParams.append(WidgetParams.PARAM_PREFIX + (0, change_case_1.snakeCase)(ownPropertyName), value.toString());
23
- }
24
- }
25
- return urlParams;
26
- }
27
- getPersistKey() {
28
- return `${this.name}-${this.id}`;
29
- }
30
- /**
31
- * 从当前地址解析组件参数:
32
- * http://localhost:8080/#/widget/config/labor_progress?w_w=2&w_h=2&w_width=156&w_height=156
33
- * =>
34
- * {width:2,height:2,id:21,width_px:156,height_px:156}
35
- */
36
- static fromCurrentLocation() {
37
- const href = window.location.href;
38
- let strings = href.split("?");
39
- if (strings.length > 1) {
40
- let queryString = strings[1];
41
- return this.fromObject((0, query_1.parseQuery)(queryString));
42
- }
43
- return new WidgetParams();
44
- }
45
- static fromLocation(url) {
46
- let strings = url.split("?");
47
- if (strings.length > 1) {
48
- let queryString = strings[1];
49
- return this.fromObject((0, query_1.parseQuery)(queryString));
50
- }
51
- return new WidgetParams();
52
- }
53
- static setValue(widgetEnv, key, value) {
54
- const keyWithoutPrefix = key.replace(this.PARAM_PREFIX, "");
55
- if (keyWithoutPrefix == WidgetParams.PARAM_ID) {
56
- widgetEnv.id = value;
57
- }
58
- else if (keyWithoutPrefix == WidgetParams.PARAM_X) {
59
- widgetEnv.x = parseInt(value);
60
- }
61
- else if (keyWithoutPrefix == WidgetParams.PARAM_Y) {
62
- widgetEnv.y = parseInt(value);
63
- }
64
- else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT) {
65
- widgetEnv.height = parseInt(value);
66
- }
67
- else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH) {
68
- widgetEnv.width = parseInt(value);
69
- }
70
- else if (keyWithoutPrefix == WidgetParams.PARAM_LANG) {
71
- widgetEnv.lang = value;
72
- }
73
- else if (keyWithoutPrefix == WidgetParams.PARAM_THEME) {
74
- widgetEnv.theme = value;
75
- }
76
- else if (keyWithoutPrefix == WidgetParams.PARAM_MODE) {
77
- widgetEnv.mode = parseInt(value);
78
- }
79
- else if (keyWithoutPrefix == WidgetParams.PARAM_RADIUS) {
80
- widgetEnv.radius = parseInt(value);
81
- }
82
- else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH_PX) {
83
- widgetEnv.widthPx = parseInt(value);
84
- }
85
- else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT_PX) {
86
- widgetEnv.heightPx = parseInt(value);
87
- }
88
- else if (keyWithoutPrefix == WidgetParams.PARAM_NAME) {
89
- widgetEnv.name = value;
90
- }
91
- else if (keyWithoutPrefix == WidgetParams.PARAM_TITLE) {
92
- widgetEnv.title = value;
93
- }
94
- else if (keyWithoutPrefix == WidgetParams.PARAM_PREVIEW) {
95
- widgetEnv.preview = (value === 'true');
96
- }
97
- }
98
- /**
99
- * 从对象键值对中初始化组件参数
100
- * {w_width:2,w_height:2,w_id:21,w_width_px:156,w_height_px:156}=>
101
- * {width:2,height:2,id:21,width_px:156,height_px:156}
102
- * @param object
103
- */
104
- static fromObject(object) {
105
- const widgetEnv = new WidgetParams();
106
- const ownPropertyNames = Object.getOwnPropertyNames(object);
107
- for (let ownPropertyName of ownPropertyNames) {
108
- const key = ownPropertyName;
109
- const value = object[key];
110
- this.setValue(widgetEnv, key, value);
111
- }
112
- return widgetEnv;
113
- }
114
- }
115
- exports.WidgetParams = WidgetParams;
116
- WidgetParams.PARAM_PREFIX = "w_";
117
- WidgetParams.PARAM_ID = "id";
118
- WidgetParams.PARAM_WIDTH = "width";
119
- WidgetParams.PARAM_HEIGHT = "height";
120
- WidgetParams.PARAM_WIDTH_PX = "width_px";
121
- WidgetParams.PARAM_HEIGHT_PX = "height_px";
122
- WidgetParams.PARAM_X = "x";
123
- WidgetParams.PARAM_Y = "y";
124
- WidgetParams.PARAM_LANG = "lang";
125
- WidgetParams.PARAM_THEME = "theme";
126
- WidgetParams.PARAM_MODE = "mode";
127
- WidgetParams.PARAM_RADIUS = "radius";
128
- WidgetParams.PARAM_NAME = "name";
129
- WidgetParams.PARAM_TITLE = "title";
130
- WidgetParams.PARAM_PREVIEW = "preview";
131
- WidgetParams.PARAMS = [
132
- WidgetParams.PARAM_ID,
133
- WidgetParams.PARAM_WIDTH,
134
- WidgetParams.PARAM_HEIGHT,
135
- WidgetParams.PARAM_X,
136
- WidgetParams.PARAM_Y,
137
- WidgetParams.PARAM_LANG,
138
- WidgetParams.PARAM_THEME,
139
- WidgetParams.PARAM_MODE,
140
- WidgetParams.PARAM_WIDTH_PX,
141
- WidgetParams.PARAM_HEIGHT_PX,
142
- WidgetParams.PARAM_NAME,
143
- WidgetParams.PARAM_TITLE,
144
- WidgetParams.PARAM_PREVIEW,
145
- ];
146
- var ThemeMode;
147
- (function (ThemeMode) {
148
- ThemeMode["AUTO"] = "auto";
149
- ThemeMode["LIGHT"] = "LIGHT";
150
- ThemeMode["DARK"] = "DARK";
151
- })(ThemeMode = exports.ThemeMode || (exports.ThemeMode = {}));
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BroadcastEvent = void 0;
4
- class BroadcastEvent {
5
- constructor(options) {
6
- this.event = options.event;
7
- this.sender = options.sender;
8
- this.payload = options.payload;
9
- }
10
- }
11
- exports.BroadcastEvent = BroadcastEvent;