@widget-js/core 0.10.27 → 0.11.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.
package/dist/index.d.ts CHANGED
@@ -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
- snapPosition(x: number, y: number): number[];
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
- snapRect(rect: GridRect, minWidth: number, maxWidth: number, minHeight: number, maxHeight: number): IGridRect;
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;
@@ -1412,7 +1443,14 @@ declare class ApiConstants {
1412
1443
  }
1413
1444
 
1414
1445
  interface IShortcutApi {
1415
- register(shortcut: string): void;
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>;
1416
1454
  unregister(shortcut: string): void;
1417
1455
  }
1418
1456
  type ShortcutApiMethods = keyof IShortcutApi;
@@ -1474,16 +1512,33 @@ interface ILogApi {
1474
1512
  type LogApiMethods = keyof ILogApi;
1475
1513
  declare const LogApi: ILogApi;
1476
1514
 
1515
+ interface SystemFile {
1516
+ isDir: boolean;
1517
+ name: string;
1518
+ absolutePath: string;
1519
+ /**
1520
+ * mine type
1521
+ */
1522
+ type: string;
1523
+ children?: SystemFile[];
1524
+ /**
1525
+ * 上传后的ID
1526
+ */
1527
+ uploadId?: string;
1528
+ }
1477
1529
  interface ReadDirOptions {
1478
1530
  ignoreDir?: boolean;
1479
1531
  traverseDir?: boolean;
1480
1532
  }
1481
1533
  interface IFileApi {
1482
- readDirectory(path: string, options?: ReadDirOptions): Promise<string[]>;
1534
+ readDirectory(path: string, options?: ReadDirOptions): Promise<SystemFile[]>;
1483
1535
  isDirectory(filePath: string): Promise<boolean>;
1484
1536
  getFileType(filePath: string): Promise<FileTypeResult>;
1537
+ downloadUrl(url: string): Promise<string>;
1538
+ exists(filePath: string): Promise<boolean>;
1539
+ delete(filePath: string): Promise<boolean>;
1485
1540
  }
1486
1541
  type FileApiMethods = keyof IFileApi;
1487
1542
  declare const FileApi: IFileApi;
1488
1543
 
1489
- export { AlignPosition, ApiConstants, AppApi, AppApiConstants, AppApiEvent, AppApiMethods, AppMouseEvent, AppNotification, BaseApi, BroadcastApi, BroadcastApiMethods, BroadcastEvent, BroadcastEventType, BrowserWindowApi, BrowserWindowApiEvent, BrowserWindowApiMethods, Channel, ClipboardApi, ClipboardApiEvent, ClipboardApiMethods, DeployMode, DeployedPage, DeployedWidget, DeployedWidgetApi, DeployedWidgetApiMethods, DevOptions, DeviceApi, DeviceApiMethods, DialogApi, DialogApiMethods, ElectronApi, ElectronUtils, FileApi, FileApiMethods, Gravity, GridRect, GridSystem, HostedMode, IGridRect, IPage, IPageOptions, IWidgetDataApi, IWidgetOptions, IWindowSize, LanguageCode, LanguageTextMap, LocalPackageUrlInfo, LocationQuery, LocationQueryRaw, LocationQueryValue, LocationQueryValueRaw, LogApi, LogApiMethods, MetaInfo, NativeKeyboardEvent, NormalizeOptions, NotificationApi, NotificationApiEvent, NotificationApiMethods, NotificationOption, NotificationSize, NotificationType, OpenUrlOptions, Page, Point, Position, ProcessApi, ProcessApiMethods, ReadDirOptions, Rectangle, RemotePackageUrlInfo, SaveWidgetOption, SetPositionOptions, ShortcutApi, ShortcutApiEvent, ShortcutApiMethods, StoreApi, StoreApiMethods, ThemeMode, WebSocketEvent, WebSocketEventType, Widget, WidgetApi, WidgetApiEvent, WidgetApiMethods, WidgetData, WidgetDataApi, WidgetDataApiMethods, WidgetKeyword, WidgetPackage, WidgetPackageOptions, WidgetParams, WidgetPermission, WidgetRoute, WidgetUrlUtils, getTextByLanguageCode, normalizeUrl, parseQuery, stringifyQuery };
1544
+ export { AlignPosition, ApiConstants, AppApi, AppApiConstants, AppApiEvent, AppApiMethods, AppMouseEvent, AppNotification, BaseApi, BroadcastApi, BroadcastApiMethods, BroadcastEvent, BroadcastEventType, BrowserWindowApi, BrowserWindowApiEvent, BrowserWindowApiMethods, Channel, ClipboardApi, ClipboardApiEvent, ClipboardApiMethods, DeployMode, DeployedPage, DeployedWidget, DeployedWidgetApi, DeployedWidgetApiMethods, DevOptions, DeviceApi, DeviceApiMethods, DialogApi, DialogApiMethods, ElectronApi, ElectronUtils, FileApi, FileApiMethods, Gravity, GridRect, GridSystem, HostedMode, IGridRect, IPage, IPageOptions, IWidgetDataApi, IWidgetOptions, IWindowSize, LanguageCode, LanguageTextMap, LocalPackageUrlInfo, LocationQuery, LocationQueryRaw, LocationQueryValue, LocationQueryValueRaw, LogApi, LogApiMethods, MetaInfo, NativeKeyboardEvent, NormalizeOptions, NotificationApi, NotificationApiEvent, NotificationApiMethods, NotificationOption, NotificationSize, NotificationType, OpenUrlOptions, Page, Point, Position, ProcessApi, ProcessApiMethods, ReadDirOptions, Rectangle, RemotePackageUrlInfo, SaveWidgetOption, SetPositionOptions, ShortcutApi, ShortcutApiEvent, ShortcutApiMethods, StoreApi, StoreApiMethods, SystemFile, ThemeMode, WebSocketEvent, WebSocketEventType, Widget, WidgetApi, WidgetApiEvent, WidgetApiMethods, WidgetData, WidgetDataApi, WidgetDataApiMethods, WidgetKeyword, WidgetPackage, WidgetPackageOptions, WidgetParams, WidgetPermission, WidgetRoute, WidgetUrlUtils, getTextByLanguageCode, normalizeUrl, parseQuery, stringifyQuery };
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
- snapPosition(x, y) {
1061
- let newX = this.getRangeValue(x - this.left, 0, this.width);
1062
- let newY = this.getRangeValue(y - this.top, 0, this.height);
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
- snapRect(rect, minWidth, maxWidth, minHeight, maxHeight) {
1103
- let [newX, newY] = this.snapPosition(rect.left, rect.top);
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.right - this.left;
1174
+ return this.width;
1126
1175
  }
1127
1176
  getHeight() {
1128
- return this.bottom - this.top;
1177
+ return this.height;
1129
1178
  }
1130
1179
  };
1131
1180
 
@@ -1982,6 +2031,15 @@ var FileApiImpl = class extends BaseApi {
1982
2031
  readDirectory(path, options) {
1983
2032
  return this.invokeMethod("readDirectory", path, options);
1984
2033
  }
2034
+ delete(filePath) {
2035
+ return this.invokeMethod("delete", filePath);
2036
+ }
2037
+ downloadUrl(url) {
2038
+ return this.invokeMethod("downloadUrl", url);
2039
+ }
2040
+ exists(filePath) {
2041
+ return this.invokeMethod("exists", filePath);
2042
+ }
1985
2043
  };
1986
2044
  var FileApi = new FileApiImpl();
1987
2045
  export {