@widget-js/core 0.10.21 → 0.10.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/electron.d.ts +19543 -0
- package/dist/index.cjs +62 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +47 -7
- package/dist/index.js +62 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CPUUsage, IOCounters, BlinkMemoryInfo, HeapStatistics, ProcessMemoryInfo, SystemMemoryInfo } from 'electron';
|
|
1
|
+
import { Config, CPUUsage, IOCounters, BlinkMemoryInfo, HeapStatistics, ProcessMemoryInfo, SystemMemoryInfo } from 'electron';
|
|
2
2
|
import { FileTypeResult } from 'file-type';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -514,7 +514,7 @@ declare class WidgetApiImpl extends BaseApi<WidgetApiMethods> implements IWidget
|
|
|
514
514
|
declare const WidgetApi: WidgetApiImpl;
|
|
515
515
|
|
|
516
516
|
interface IAppApi {
|
|
517
|
-
setConfig(key: string, value: string | number | boolean): Promise<
|
|
517
|
+
setConfig(key: string, value: string | number | boolean): Promise<any>;
|
|
518
518
|
getConfig(key: string, defaultValue: string | number | boolean): Promise<string | number | boolean>;
|
|
519
519
|
getVersion(): Promise<string>;
|
|
520
520
|
getPreloadPath(): Promise<string>;
|
|
@@ -1099,20 +1099,34 @@ declare class GridSystem extends GridRect {
|
|
|
1099
1099
|
verticalCellCount: number;
|
|
1100
1100
|
screenWidth: number;
|
|
1101
1101
|
screenHeight: number;
|
|
1102
|
+
/**
|
|
1103
|
+
* 屏幕x坐标,用于解决多块屏幕坐标计算问题
|
|
1104
|
+
*/
|
|
1105
|
+
screenLeft?: number;
|
|
1106
|
+
/**
|
|
1107
|
+
* 屏幕y坐标,用于解决多块屏幕坐标计算问题
|
|
1108
|
+
*/
|
|
1109
|
+
screenTop?: number;
|
|
1110
|
+
canvasScreenTop: number;
|
|
1111
|
+
canvasScreenLeft: number;
|
|
1102
1112
|
/**
|
|
1103
1113
|
*
|
|
1104
1114
|
* @param cellSize
|
|
1105
1115
|
* @param padding 至少保留的边距
|
|
1106
1116
|
* @param screenWidth
|
|
1107
1117
|
* @param screenHeight
|
|
1118
|
+
* @param screenX
|
|
1119
|
+
* @param screenY
|
|
1108
1120
|
*/
|
|
1109
|
-
constructor(cellSize: number, padding: number, screenWidth: number, screenHeight: number);
|
|
1121
|
+
constructor(cellSize: number, padding: number, screenWidth: number, screenHeight: number, screenX?: number, screenY?: number);
|
|
1110
1122
|
/**
|
|
1111
1123
|
* 将坐标对齐到网格上
|
|
1112
1124
|
* @param x
|
|
1113
1125
|
* @param y
|
|
1126
|
+
* @param gridSystem
|
|
1114
1127
|
*/
|
|
1115
|
-
|
|
1128
|
+
snapCanvasPosition(x: number, y: number): number[];
|
|
1129
|
+
private snapPosition;
|
|
1116
1130
|
snapSize(width: number, height: number): number[];
|
|
1117
1131
|
/**
|
|
1118
1132
|
* 将矩形对齐到网格上
|
|
@@ -1122,7 +1136,24 @@ declare class GridSystem extends GridRect {
|
|
|
1122
1136
|
* @param minHeight
|
|
1123
1137
|
* @param maxHeight
|
|
1124
1138
|
*/
|
|
1125
|
-
|
|
1139
|
+
snapCanvasRect(rect: GridRect, minWidth: number, maxWidth: number, minHeight: number, maxHeight: number): IGridRect;
|
|
1140
|
+
private snapRect;
|
|
1141
|
+
/**
|
|
1142
|
+
* 将矩形对齐到网格上,与snapRect的区别是,这个会加上屏幕x和y坐标,用于适配多个显示器
|
|
1143
|
+
* @param rect
|
|
1144
|
+
* @param minWidth
|
|
1145
|
+
* @param maxWidth
|
|
1146
|
+
* @param minHeight
|
|
1147
|
+
* @param maxHeight
|
|
1148
|
+
*/
|
|
1149
|
+
snapWindow(rect: GridRect, minWidth: number, maxWidth: number, minHeight: number, maxHeight: number): IGridRect;
|
|
1150
|
+
/**
|
|
1151
|
+
* 限制值不超出屏幕
|
|
1152
|
+
* @param value
|
|
1153
|
+
* @param min
|
|
1154
|
+
* @param max
|
|
1155
|
+
* @private
|
|
1156
|
+
*/
|
|
1126
1157
|
private getRangeValue;
|
|
1127
1158
|
getWidth(): number;
|
|
1128
1159
|
getHeight(): number;
|
|
@@ -1190,6 +1221,7 @@ interface IBrowserWindowApi {
|
|
|
1190
1221
|
setMinimumSize(width: number, height: number): Promise<void>;
|
|
1191
1222
|
setZoomLevel(level: number): Promise<void>;
|
|
1192
1223
|
setZoomFactor(factor: number): Promise<void>;
|
|
1224
|
+
setProxy(config: Config): Promise<void>;
|
|
1193
1225
|
isFocused(): Promise<boolean>;
|
|
1194
1226
|
}
|
|
1195
1227
|
type BrowserWindowApiMethods = keyof IBrowserWindowApi;
|
|
@@ -1275,6 +1307,7 @@ declare class BrowserWindowApiImpl extends BaseApi<BrowserWindowApiMethods> impl
|
|
|
1275
1307
|
close(): Promise<void>;
|
|
1276
1308
|
setZoomFactor(factor: number): Promise<void>;
|
|
1277
1309
|
setup(options: SetupOptions): Promise<void>;
|
|
1310
|
+
setProxy(config: Config): Promise<void>;
|
|
1278
1311
|
}
|
|
1279
1312
|
declare const BrowserWindowApi: BrowserWindowApiImpl;
|
|
1280
1313
|
|
|
@@ -1376,7 +1409,7 @@ declare enum Channel {
|
|
|
1376
1409
|
BROWSER_WINDOW = "channel::cn.widgetjs.core.browser_window",
|
|
1377
1410
|
BROADCAST = "channel::cn.widgetjs.core.broadcast",
|
|
1378
1411
|
WIDGET = "channel::cn.widgetjs.core.widget",
|
|
1379
|
-
|
|
1412
|
+
DEPLOYED_WIDGET = "channel::cn.widgetjs.core.deployed_widget",
|
|
1380
1413
|
APP = "channel::cn.widgetjs.core.app",
|
|
1381
1414
|
DIALOG = "channel::cn.widgetjs.core.dialog",
|
|
1382
1415
|
CLIPBOARD = "channel::cn.widgetjs.core.clipboard",
|
|
@@ -1410,7 +1443,14 @@ declare class ApiConstants {
|
|
|
1410
1443
|
}
|
|
1411
1444
|
|
|
1412
1445
|
interface IShortcutApi {
|
|
1413
|
-
|
|
1446
|
+
/**
|
|
1447
|
+
* register shortcut for widget, if registered successful, {@link BroadcastEvent} will be sent once shortcut hits
|
|
1448
|
+
* @see https://www.electronjs.org/docs/latest/api/accelerator
|
|
1449
|
+
* @example Ctrl+Meta+Y, Meta for windows key
|
|
1450
|
+
* @param shortcut
|
|
1451
|
+
* @return true if register success
|
|
1452
|
+
*/
|
|
1453
|
+
register(shortcut: string): Promise<boolean>;
|
|
1414
1454
|
unregister(shortcut: string): void;
|
|
1415
1455
|
}
|
|
1416
1456
|
type ShortcutApiMethods = keyof IShortcutApi;
|
package/dist/index.js
CHANGED
|
@@ -1031,14 +1031,26 @@ var GridSystem = class extends GridRect {
|
|
|
1031
1031
|
verticalCellCount;
|
|
1032
1032
|
screenWidth;
|
|
1033
1033
|
screenHeight;
|
|
1034
|
+
/**
|
|
1035
|
+
* 屏幕x坐标,用于解决多块屏幕坐标计算问题
|
|
1036
|
+
*/
|
|
1037
|
+
screenLeft;
|
|
1038
|
+
/**
|
|
1039
|
+
* 屏幕y坐标,用于解决多块屏幕坐标计算问题
|
|
1040
|
+
*/
|
|
1041
|
+
screenTop;
|
|
1042
|
+
canvasScreenTop;
|
|
1043
|
+
canvasScreenLeft;
|
|
1034
1044
|
/**
|
|
1035
1045
|
*
|
|
1036
1046
|
* @param cellSize
|
|
1037
1047
|
* @param padding 至少保留的边距
|
|
1038
1048
|
* @param screenWidth
|
|
1039
1049
|
* @param screenHeight
|
|
1050
|
+
* @param screenX
|
|
1051
|
+
* @param screenY
|
|
1040
1052
|
*/
|
|
1041
|
-
constructor(cellSize, padding, screenWidth, screenHeight) {
|
|
1053
|
+
constructor(cellSize, padding, screenWidth, screenHeight, screenX, screenY) {
|
|
1042
1054
|
let gridMaxWidth = screenWidth - padding * 2;
|
|
1043
1055
|
let gridMaxHeight = screenHeight - padding * 2;
|
|
1044
1056
|
let horizontalPadding = gridMaxWidth % cellSize / 2 + padding;
|
|
@@ -1046,20 +1058,28 @@ var GridSystem = class extends GridRect {
|
|
|
1046
1058
|
const horizontalCellCount = Math.floor(gridMaxWidth / cellSize);
|
|
1047
1059
|
const verticalCellCount = Math.floor(gridMaxHeight / cellSize);
|
|
1048
1060
|
super(horizontalPadding, verticalPadding, horizontalCellCount * cellSize, verticalCellCount * cellSize);
|
|
1061
|
+
this.canvasScreenLeft = horizontalPadding + (screenX ?? 0);
|
|
1062
|
+
this.canvasScreenTop = verticalPadding + (screenY ?? 0);
|
|
1049
1063
|
this.cellSize = cellSize;
|
|
1050
1064
|
this.screenWidth = screenWidth;
|
|
1051
1065
|
this.screenHeight = screenHeight;
|
|
1052
1066
|
this.horizontalCellCount = horizontalCellCount;
|
|
1053
1067
|
this.verticalCellCount = verticalCellCount;
|
|
1068
|
+
this.screenLeft = screenX;
|
|
1069
|
+
this.screenTop = screenY;
|
|
1054
1070
|
}
|
|
1055
1071
|
/**
|
|
1056
1072
|
* 将坐标对齐到网格上
|
|
1057
1073
|
* @param x
|
|
1058
1074
|
* @param y
|
|
1075
|
+
* @param gridSystem
|
|
1059
1076
|
*/
|
|
1060
|
-
|
|
1061
|
-
let newX = this.getRangeValue(x - this.left, 0, this.
|
|
1062
|
-
let newY = this.getRangeValue(y - this.top, 0, this.
|
|
1077
|
+
snapCanvasPosition(x, y) {
|
|
1078
|
+
let newX = this.getRangeValue(x - this.left, 0, this.right);
|
|
1079
|
+
let newY = this.getRangeValue(y - this.top, 0, this.bottom);
|
|
1080
|
+
return this.snapPosition(newX, newY);
|
|
1081
|
+
}
|
|
1082
|
+
snapPosition(newX, newY) {
|
|
1063
1083
|
const diffX = newX % this.cellSize;
|
|
1064
1084
|
if (diffX >= this.cellSize / 2) {
|
|
1065
1085
|
newX = newX + this.cellSize - diffX;
|
|
@@ -1099,8 +1119,11 @@ var GridSystem = class extends GridRect {
|
|
|
1099
1119
|
* @param minHeight
|
|
1100
1120
|
* @param maxHeight
|
|
1101
1121
|
*/
|
|
1102
|
-
|
|
1103
|
-
let [newX, newY] = this.
|
|
1122
|
+
snapCanvasRect(rect, minWidth, maxWidth, minHeight, maxHeight) {
|
|
1123
|
+
let [newX, newY] = this.snapCanvasPosition(rect.left, rect.top);
|
|
1124
|
+
return this.snapRect(rect, minWidth, maxWidth, minHeight, maxHeight, newX, newY);
|
|
1125
|
+
}
|
|
1126
|
+
snapRect(rect, minWidth, maxWidth, minHeight, maxHeight, newX, newY) {
|
|
1104
1127
|
let [newWidth, newHeight] = this.snapSize(rect.width, rect.height);
|
|
1105
1128
|
newWidth = this.getRangeValue(newWidth, minWidth, maxWidth);
|
|
1106
1129
|
newHeight = this.getRangeValue(newHeight, minHeight, maxHeight);
|
|
@@ -1112,6 +1135,32 @@ var GridSystem = class extends GridRect {
|
|
|
1112
1135
|
}
|
|
1113
1136
|
return new GridRect(newX, newY, newWidth, newHeight);
|
|
1114
1137
|
}
|
|
1138
|
+
/**
|
|
1139
|
+
* 将矩形对齐到网格上,与snapRect的区别是,这个会加上屏幕x和y坐标,用于适配多个显示器
|
|
1140
|
+
* @param rect
|
|
1141
|
+
* @param minWidth
|
|
1142
|
+
* @param maxWidth
|
|
1143
|
+
* @param minHeight
|
|
1144
|
+
* @param maxHeight
|
|
1145
|
+
*/
|
|
1146
|
+
snapWindow(rect, minWidth, maxWidth, minHeight, maxHeight) {
|
|
1147
|
+
rect.left = rect.left - (this.screenLeft ?? 0);
|
|
1148
|
+
rect.top = rect.top - (this.screenTop ?? 0);
|
|
1149
|
+
let result = this.snapCanvasRect(rect, minWidth, maxWidth, minHeight, maxHeight);
|
|
1150
|
+
return new GridRect(
|
|
1151
|
+
result.left + (this.screenLeft ?? 0),
|
|
1152
|
+
result.top + (this.screenTop ?? 0),
|
|
1153
|
+
result.width,
|
|
1154
|
+
result.height
|
|
1155
|
+
);
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* 限制值不超出屏幕
|
|
1159
|
+
* @param value
|
|
1160
|
+
* @param min
|
|
1161
|
+
* @param max
|
|
1162
|
+
* @private
|
|
1163
|
+
*/
|
|
1115
1164
|
getRangeValue(value, min, max) {
|
|
1116
1165
|
if (value < min) {
|
|
1117
1166
|
return min;
|
|
@@ -1122,10 +1171,10 @@ var GridSystem = class extends GridRect {
|
|
|
1122
1171
|
return value;
|
|
1123
1172
|
}
|
|
1124
1173
|
getWidth() {
|
|
1125
|
-
return this.
|
|
1174
|
+
return this.width;
|
|
1126
1175
|
}
|
|
1127
1176
|
getHeight() {
|
|
1128
|
-
return this.
|
|
1177
|
+
return this.height;
|
|
1129
1178
|
}
|
|
1130
1179
|
};
|
|
1131
1180
|
|
|
@@ -1148,7 +1197,7 @@ var Channel = /* @__PURE__ */ ((Channel2) => {
|
|
|
1148
1197
|
Channel2["BROWSER_WINDOW"] = "channel::cn.widgetjs.core.browser_window";
|
|
1149
1198
|
Channel2["BROADCAST"] = "channel::cn.widgetjs.core.broadcast";
|
|
1150
1199
|
Channel2["WIDGET"] = "channel::cn.widgetjs.core.widget";
|
|
1151
|
-
Channel2["
|
|
1200
|
+
Channel2["DEPLOYED_WIDGET"] = "channel::cn.widgetjs.core.deployed_widget";
|
|
1152
1201
|
Channel2["APP"] = "channel::cn.widgetjs.core.app";
|
|
1153
1202
|
Channel2["DIALOG"] = "channel::cn.widgetjs.core.dialog";
|
|
1154
1203
|
Channel2["CLIPBOARD"] = "channel::cn.widgetjs.core.clipboard";
|
|
@@ -1563,6 +1612,9 @@ var BrowserWindowApiImpl = class extends BaseApi {
|
|
|
1563
1612
|
await this.center();
|
|
1564
1613
|
}
|
|
1565
1614
|
}
|
|
1615
|
+
async setProxy(config) {
|
|
1616
|
+
return await this.invokeMethod("setProxy", config);
|
|
1617
|
+
}
|
|
1566
1618
|
};
|
|
1567
1619
|
var BrowserWindowApi = new BrowserWindowApiImpl();
|
|
1568
1620
|
|
|
@@ -1680,7 +1732,7 @@ var NotificationApi = new NotificationApiImpl();
|
|
|
1680
1732
|
// src/api/DeployedWidgetApi.ts
|
|
1681
1733
|
var DeployedWidgetApiImpl = class extends BaseApi {
|
|
1682
1734
|
getChannel() {
|
|
1683
|
-
return "channel::cn.widgetjs.core.
|
|
1735
|
+
return "channel::cn.widgetjs.core.deployed_widget" /* DEPLOYED_WIDGET */;
|
|
1684
1736
|
}
|
|
1685
1737
|
/**
|
|
1686
1738
|
* 移除组件
|