@tsdraw/core 0.8.1 → 0.8.2

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
@@ -1166,6 +1166,7 @@ var GeometricDrawingState = class extends StateNode {
1166
1166
  }
1167
1167
  // If user dragged, use the drag extents for the final shape
1168
1168
  // If they just clicked without dragging, use default-sized shape
1169
+ // If they dragged just a bit (most likely a click), remove the shape and go back to idle
1169
1170
  completeShape() {
1170
1171
  const activeShape = this.getActiveShape();
1171
1172
  const config = this.getConfig();
@@ -1175,7 +1176,15 @@ var GeometricDrawingState = class extends StateNode {
1175
1176
  }
1176
1177
  const originPoint = this.editor.input.getOriginPagePoint();
1177
1178
  const cursorPoint = this.editor.input.getCurrentPagePoint();
1178
- const finalizedBounds = this.editor.input.getIsDragging() ? this.editor.input.getShiftKey() ? config.buildConstrainedBounds(originPoint.x, originPoint.y, cursorPoint.x, cursorPoint.y) : config.buildUnconstrainedBounds(originPoint.x, originPoint.y, cursorPoint.x, cursorPoint.y) : config.buildDefaultBounds(originPoint.x, originPoint.y);
1179
+ const dx = cursorPoint.x - originPoint.x;
1180
+ const dy = cursorPoint.y - originPoint.y;
1181
+ const draggedFarEnough = dx * dx + dy * dy > this.editor.options.dragDistanceSquared;
1182
+ if (!draggedFarEnough) {
1183
+ this.removeCurrentShape();
1184
+ this.ctx.transition(config.idleStateId, this.startedAt);
1185
+ return;
1186
+ }
1187
+ const finalizedBounds = this.editor.input.getShiftKey() ? config.buildConstrainedBounds(originPoint.x, originPoint.y, cursorPoint.x, cursorPoint.y) : config.buildUnconstrainedBounds(originPoint.x, originPoint.y, cursorPoint.x, cursorPoint.y);
1179
1188
  this.editor.store.updateShape(activeShape.id, {
1180
1189
  x: finalizedBounds.x,
1181
1190
  y: finalizedBounds.y,
@@ -1205,10 +1214,6 @@ var GeometricDrawingState = class extends StateNode {
1205
1214
 
1206
1215
  // src/tools/geometric/geometricShapeHelpers.ts
1207
1216
  var MIN_SIDE_LENGTH = 1;
1208
- var DEFAULT_RECTANGLE_WIDTH = 180;
1209
- var DEFAULT_RECTANGLE_HEIGHT = 120;
1210
- var DEFAULT_ELLIPSE_WIDTH = 180;
1211
- var DEFAULT_ELLIPSE_HEIGHT = 120;
1212
1217
  function toSizedBounds(anchorX, anchorY, cursorX, cursorY, forceEqualSides) {
1213
1218
  const rawDeltaX = cursorX - anchorX;
1214
1219
  const rawDeltaY = cursorY - anchorY;
@@ -1233,16 +1238,6 @@ function buildSquareBounds(anchorX, anchorY, cursorX, cursorY) {
1233
1238
  function buildRectangleBounds(anchorX, anchorY, cursorX, cursorY) {
1234
1239
  return toSizedBounds(anchorX, anchorY, cursorX, cursorY, false);
1235
1240
  }
1236
- function buildDefaultCenteredRectangleBounds(centerX, centerY) {
1237
- const halfWidth = DEFAULT_RECTANGLE_WIDTH / 2;
1238
- const halfHeight = DEFAULT_RECTANGLE_HEIGHT / 2;
1239
- return {
1240
- x: centerX - halfWidth,
1241
- y: centerY - halfHeight,
1242
- width: DEFAULT_RECTANGLE_WIDTH,
1243
- height: DEFAULT_RECTANGLE_HEIGHT
1244
- };
1245
- }
1246
1241
  function buildRectangleSegments(width, height) {
1247
1242
  const topLeft = { x: 0, y: 0, z: 0.5 };
1248
1243
  const topRight = { x: width, y: 0, z: 0.5 };
@@ -1261,16 +1256,6 @@ function buildCircleBounds(anchorX, anchorY, cursorX, cursorY) {
1261
1256
  function buildEllipseBounds(anchorX, anchorY, cursorX, cursorY) {
1262
1257
  return toSizedBounds(anchorX, anchorY, cursorX, cursorY, false);
1263
1258
  }
1264
- function buildDefaultCenteredEllipseBounds(centerX, centerY) {
1265
- const halfWidth = DEFAULT_ELLIPSE_WIDTH / 2;
1266
- const halfHeight = DEFAULT_ELLIPSE_HEIGHT / 2;
1267
- return {
1268
- x: centerX - halfWidth,
1269
- y: centerY - halfHeight,
1270
- width: DEFAULT_ELLIPSE_WIDTH,
1271
- height: DEFAULT_ELLIPSE_HEIGHT
1272
- };
1273
- }
1274
1259
  function buildEllipseSegments(width, height) {
1275
1260
  const centerX = width / 2;
1276
1261
  const centerY = height / 2;
@@ -1298,7 +1283,6 @@ var SquareDrawingState = class extends GeometricDrawingState {
1298
1283
  idleStateId: "square_idle",
1299
1284
  buildConstrainedBounds: buildSquareBounds,
1300
1285
  buildUnconstrainedBounds: buildRectangleBounds,
1301
- buildDefaultBounds: buildDefaultCenteredRectangleBounds,
1302
1286
  buildSegments: buildRectangleSegments
1303
1287
  };
1304
1288
  }
@@ -1320,7 +1304,6 @@ var CircleDrawingState = class extends GeometricDrawingState {
1320
1304
  idleStateId: "circle_idle",
1321
1305
  buildConstrainedBounds: buildCircleBounds,
1322
1306
  buildUnconstrainedBounds: buildEllipseBounds,
1323
- buildDefaultBounds: buildDefaultCenteredEllipseBounds,
1324
1307
  buildSegments: buildEllipseSegments
1325
1308
  };
1326
1309
  }