@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.cjs CHANGED
@@ -1115,14 +1115,26 @@ var GridSystem = class extends GridRect {
1115
1115
  verticalCellCount;
1116
1116
  screenWidth;
1117
1117
  screenHeight;
1118
+ /**
1119
+ * 屏幕x坐标,用于解决多块屏幕坐标计算问题
1120
+ */
1121
+ screenLeft;
1122
+ /**
1123
+ * 屏幕y坐标,用于解决多块屏幕坐标计算问题
1124
+ */
1125
+ screenTop;
1126
+ canvasScreenTop;
1127
+ canvasScreenLeft;
1118
1128
  /**
1119
1129
  *
1120
1130
  * @param cellSize
1121
1131
  * @param padding 至少保留的边距
1122
1132
  * @param screenWidth
1123
1133
  * @param screenHeight
1134
+ * @param screenX
1135
+ * @param screenY
1124
1136
  */
1125
- constructor(cellSize, padding, screenWidth, screenHeight) {
1137
+ constructor(cellSize, padding, screenWidth, screenHeight, screenX, screenY) {
1126
1138
  let gridMaxWidth = screenWidth - padding * 2;
1127
1139
  let gridMaxHeight = screenHeight - padding * 2;
1128
1140
  let horizontalPadding = gridMaxWidth % cellSize / 2 + padding;
@@ -1130,20 +1142,28 @@ var GridSystem = class extends GridRect {
1130
1142
  const horizontalCellCount = Math.floor(gridMaxWidth / cellSize);
1131
1143
  const verticalCellCount = Math.floor(gridMaxHeight / cellSize);
1132
1144
  super(horizontalPadding, verticalPadding, horizontalCellCount * cellSize, verticalCellCount * cellSize);
1145
+ this.canvasScreenLeft = horizontalPadding + (screenX ?? 0);
1146
+ this.canvasScreenTop = verticalPadding + (screenY ?? 0);
1133
1147
  this.cellSize = cellSize;
1134
1148
  this.screenWidth = screenWidth;
1135
1149
  this.screenHeight = screenHeight;
1136
1150
  this.horizontalCellCount = horizontalCellCount;
1137
1151
  this.verticalCellCount = verticalCellCount;
1152
+ this.screenLeft = screenX;
1153
+ this.screenTop = screenY;
1138
1154
  }
1139
1155
  /**
1140
1156
  * 将坐标对齐到网格上
1141
1157
  * @param x
1142
1158
  * @param y
1159
+ * @param gridSystem
1143
1160
  */
1144
- snapPosition(x, y) {
1145
- let newX = this.getRangeValue(x - this.left, 0, this.width);
1146
- let newY = this.getRangeValue(y - this.top, 0, this.height);
1161
+ snapCanvasPosition(x, y) {
1162
+ let newX = this.getRangeValue(x - this.left, 0, this.right);
1163
+ let newY = this.getRangeValue(y - this.top, 0, this.bottom);
1164
+ return this.snapPosition(newX, newY);
1165
+ }
1166
+ snapPosition(newX, newY) {
1147
1167
  const diffX = newX % this.cellSize;
1148
1168
  if (diffX >= this.cellSize / 2) {
1149
1169
  newX = newX + this.cellSize - diffX;
@@ -1183,8 +1203,11 @@ var GridSystem = class extends GridRect {
1183
1203
  * @param minHeight
1184
1204
  * @param maxHeight
1185
1205
  */
1186
- snapRect(rect, minWidth, maxWidth, minHeight, maxHeight) {
1187
- let [newX, newY] = this.snapPosition(rect.left, rect.top);
1206
+ snapCanvasRect(rect, minWidth, maxWidth, minHeight, maxHeight) {
1207
+ let [newX, newY] = this.snapCanvasPosition(rect.left, rect.top);
1208
+ return this.snapRect(rect, minWidth, maxWidth, minHeight, maxHeight, newX, newY);
1209
+ }
1210
+ snapRect(rect, minWidth, maxWidth, minHeight, maxHeight, newX, newY) {
1188
1211
  let [newWidth, newHeight] = this.snapSize(rect.width, rect.height);
1189
1212
  newWidth = this.getRangeValue(newWidth, minWidth, maxWidth);
1190
1213
  newHeight = this.getRangeValue(newHeight, minHeight, maxHeight);
@@ -1196,6 +1219,32 @@ var GridSystem = class extends GridRect {
1196
1219
  }
1197
1220
  return new GridRect(newX, newY, newWidth, newHeight);
1198
1221
  }
1222
+ /**
1223
+ * 将矩形对齐到网格上,与snapRect的区别是,这个会加上屏幕x和y坐标,用于适配多个显示器
1224
+ * @param rect
1225
+ * @param minWidth
1226
+ * @param maxWidth
1227
+ * @param minHeight
1228
+ * @param maxHeight
1229
+ */
1230
+ snapWindow(rect, minWidth, maxWidth, minHeight, maxHeight) {
1231
+ rect.left = rect.left - (this.screenLeft ?? 0);
1232
+ rect.top = rect.top - (this.screenTop ?? 0);
1233
+ let result = this.snapCanvasRect(rect, minWidth, maxWidth, minHeight, maxHeight);
1234
+ return new GridRect(
1235
+ result.left + (this.screenLeft ?? 0),
1236
+ result.top + (this.screenTop ?? 0),
1237
+ result.width,
1238
+ result.height
1239
+ );
1240
+ }
1241
+ /**
1242
+ * 限制值不超出屏幕
1243
+ * @param value
1244
+ * @param min
1245
+ * @param max
1246
+ * @private
1247
+ */
1199
1248
  getRangeValue(value, min, max) {
1200
1249
  if (value < min) {
1201
1250
  return min;
@@ -1206,10 +1255,10 @@ var GridSystem = class extends GridRect {
1206
1255
  return value;
1207
1256
  }
1208
1257
  getWidth() {
1209
- return this.right - this.left;
1258
+ return this.width;
1210
1259
  }
1211
1260
  getHeight() {
1212
- return this.bottom - this.top;
1261
+ return this.height;
1213
1262
  }
1214
1263
  };
1215
1264
 
@@ -2066,6 +2115,15 @@ var FileApiImpl = class extends BaseApi {
2066
2115
  readDirectory(path, options) {
2067
2116
  return this.invokeMethod("readDirectory", path, options);
2068
2117
  }
2118
+ delete(filePath) {
2119
+ return this.invokeMethod("delete", filePath);
2120
+ }
2121
+ downloadUrl(url) {
2122
+ return this.invokeMethod("downloadUrl", url);
2123
+ }
2124
+ exists(filePath) {
2125
+ return this.invokeMethod("exists", filePath);
2126
+ }
2069
2127
  };
2070
2128
  var FileApi = new FileApiImpl();
2071
2129
  // Annotate the CommonJS export names for ESM import in node: