@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 +10 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -5
- package/dist/index.d.ts +0 -5
- package/dist/index.js +10 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -429,18 +429,15 @@ interface ShapeBounds {
|
|
|
429
429
|
}
|
|
430
430
|
declare function buildSquareBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
431
431
|
declare function buildRectangleBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
432
|
-
declare function buildDefaultCenteredRectangleBounds(centerX: number, centerY: number): ShapeBounds;
|
|
433
432
|
declare function buildRectangleSegments(width: number, height: number): DrawSegment[];
|
|
434
433
|
declare function buildCircleBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
435
434
|
declare function buildEllipseBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
436
|
-
declare function buildDefaultCenteredEllipseBounds(centerX: number, centerY: number): ShapeBounds;
|
|
437
435
|
declare function buildEllipseSegments(width: number, height: number): DrawSegment[];
|
|
438
436
|
|
|
439
437
|
interface GeometricDrawingStateConfig {
|
|
440
438
|
idleStateId: string;
|
|
441
439
|
buildConstrainedBounds: (anchorX: number, anchorY: number, cursorX: number, cursorY: number) => ShapeBounds;
|
|
442
440
|
buildUnconstrainedBounds: (anchorX: number, anchorY: number, cursorX: number, cursorY: number) => ShapeBounds;
|
|
443
|
-
buildDefaultBounds: (centerX: number, centerY: number) => ShapeBounds;
|
|
444
441
|
buildSegments: (width: number, height: number) => DrawSegment[];
|
|
445
442
|
}
|
|
446
443
|
declare abstract class GeometricDrawingState extends StateNode {
|
|
@@ -465,7 +462,6 @@ declare class SquareDrawingState extends GeometricDrawingState {
|
|
|
465
462
|
idleStateId: string;
|
|
466
463
|
buildConstrainedBounds: typeof buildSquareBounds;
|
|
467
464
|
buildUnconstrainedBounds: typeof buildRectangleBounds;
|
|
468
|
-
buildDefaultBounds: typeof buildDefaultCenteredRectangleBounds;
|
|
469
465
|
buildSegments: typeof buildRectangleSegments;
|
|
470
466
|
};
|
|
471
467
|
}
|
|
@@ -481,7 +477,6 @@ declare class CircleDrawingState extends GeometricDrawingState {
|
|
|
481
477
|
idleStateId: string;
|
|
482
478
|
buildConstrainedBounds: typeof buildCircleBounds;
|
|
483
479
|
buildUnconstrainedBounds: typeof buildEllipseBounds;
|
|
484
|
-
buildDefaultBounds: typeof buildDefaultCenteredEllipseBounds;
|
|
485
480
|
buildSegments: typeof buildEllipseSegments;
|
|
486
481
|
};
|
|
487
482
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -429,18 +429,15 @@ interface ShapeBounds {
|
|
|
429
429
|
}
|
|
430
430
|
declare function buildSquareBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
431
431
|
declare function buildRectangleBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
432
|
-
declare function buildDefaultCenteredRectangleBounds(centerX: number, centerY: number): ShapeBounds;
|
|
433
432
|
declare function buildRectangleSegments(width: number, height: number): DrawSegment[];
|
|
434
433
|
declare function buildCircleBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
435
434
|
declare function buildEllipseBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
436
|
-
declare function buildDefaultCenteredEllipseBounds(centerX: number, centerY: number): ShapeBounds;
|
|
437
435
|
declare function buildEllipseSegments(width: number, height: number): DrawSegment[];
|
|
438
436
|
|
|
439
437
|
interface GeometricDrawingStateConfig {
|
|
440
438
|
idleStateId: string;
|
|
441
439
|
buildConstrainedBounds: (anchorX: number, anchorY: number, cursorX: number, cursorY: number) => ShapeBounds;
|
|
442
440
|
buildUnconstrainedBounds: (anchorX: number, anchorY: number, cursorX: number, cursorY: number) => ShapeBounds;
|
|
443
|
-
buildDefaultBounds: (centerX: number, centerY: number) => ShapeBounds;
|
|
444
441
|
buildSegments: (width: number, height: number) => DrawSegment[];
|
|
445
442
|
}
|
|
446
443
|
declare abstract class GeometricDrawingState extends StateNode {
|
|
@@ -465,7 +462,6 @@ declare class SquareDrawingState extends GeometricDrawingState {
|
|
|
465
462
|
idleStateId: string;
|
|
466
463
|
buildConstrainedBounds: typeof buildSquareBounds;
|
|
467
464
|
buildUnconstrainedBounds: typeof buildRectangleBounds;
|
|
468
|
-
buildDefaultBounds: typeof buildDefaultCenteredRectangleBounds;
|
|
469
465
|
buildSegments: typeof buildRectangleSegments;
|
|
470
466
|
};
|
|
471
467
|
}
|
|
@@ -481,7 +477,6 @@ declare class CircleDrawingState extends GeometricDrawingState {
|
|
|
481
477
|
idleStateId: string;
|
|
482
478
|
buildConstrainedBounds: typeof buildCircleBounds;
|
|
483
479
|
buildUnconstrainedBounds: typeof buildEllipseBounds;
|
|
484
|
-
buildDefaultBounds: typeof buildDefaultCenteredEllipseBounds;
|
|
485
480
|
buildSegments: typeof buildEllipseSegments;
|
|
486
481
|
};
|
|
487
482
|
}
|
package/dist/index.js
CHANGED
|
@@ -1164,6 +1164,7 @@ var GeometricDrawingState = class extends StateNode {
|
|
|
1164
1164
|
}
|
|
1165
1165
|
// If user dragged, use the drag extents for the final shape
|
|
1166
1166
|
// If they just clicked without dragging, use default-sized shape
|
|
1167
|
+
// If they dragged just a bit (most likely a click), remove the shape and go back to idle
|
|
1167
1168
|
completeShape() {
|
|
1168
1169
|
const activeShape = this.getActiveShape();
|
|
1169
1170
|
const config = this.getConfig();
|
|
@@ -1173,7 +1174,15 @@ var GeometricDrawingState = class extends StateNode {
|
|
|
1173
1174
|
}
|
|
1174
1175
|
const originPoint = this.editor.input.getOriginPagePoint();
|
|
1175
1176
|
const cursorPoint = this.editor.input.getCurrentPagePoint();
|
|
1176
|
-
const
|
|
1177
|
+
const dx = cursorPoint.x - originPoint.x;
|
|
1178
|
+
const dy = cursorPoint.y - originPoint.y;
|
|
1179
|
+
const draggedFarEnough = dx * dx + dy * dy > this.editor.options.dragDistanceSquared;
|
|
1180
|
+
if (!draggedFarEnough) {
|
|
1181
|
+
this.removeCurrentShape();
|
|
1182
|
+
this.ctx.transition(config.idleStateId, this.startedAt);
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
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);
|
|
1177
1186
|
this.editor.store.updateShape(activeShape.id, {
|
|
1178
1187
|
x: finalizedBounds.x,
|
|
1179
1188
|
y: finalizedBounds.y,
|
|
@@ -1203,10 +1212,6 @@ var GeometricDrawingState = class extends StateNode {
|
|
|
1203
1212
|
|
|
1204
1213
|
// src/tools/geometric/geometricShapeHelpers.ts
|
|
1205
1214
|
var MIN_SIDE_LENGTH = 1;
|
|
1206
|
-
var DEFAULT_RECTANGLE_WIDTH = 180;
|
|
1207
|
-
var DEFAULT_RECTANGLE_HEIGHT = 120;
|
|
1208
|
-
var DEFAULT_ELLIPSE_WIDTH = 180;
|
|
1209
|
-
var DEFAULT_ELLIPSE_HEIGHT = 120;
|
|
1210
1215
|
function toSizedBounds(anchorX, anchorY, cursorX, cursorY, forceEqualSides) {
|
|
1211
1216
|
const rawDeltaX = cursorX - anchorX;
|
|
1212
1217
|
const rawDeltaY = cursorY - anchorY;
|
|
@@ -1231,16 +1236,6 @@ function buildSquareBounds(anchorX, anchorY, cursorX, cursorY) {
|
|
|
1231
1236
|
function buildRectangleBounds(anchorX, anchorY, cursorX, cursorY) {
|
|
1232
1237
|
return toSizedBounds(anchorX, anchorY, cursorX, cursorY, false);
|
|
1233
1238
|
}
|
|
1234
|
-
function buildDefaultCenteredRectangleBounds(centerX, centerY) {
|
|
1235
|
-
const halfWidth = DEFAULT_RECTANGLE_WIDTH / 2;
|
|
1236
|
-
const halfHeight = DEFAULT_RECTANGLE_HEIGHT / 2;
|
|
1237
|
-
return {
|
|
1238
|
-
x: centerX - halfWidth,
|
|
1239
|
-
y: centerY - halfHeight,
|
|
1240
|
-
width: DEFAULT_RECTANGLE_WIDTH,
|
|
1241
|
-
height: DEFAULT_RECTANGLE_HEIGHT
|
|
1242
|
-
};
|
|
1243
|
-
}
|
|
1244
1239
|
function buildRectangleSegments(width, height) {
|
|
1245
1240
|
const topLeft = { x: 0, y: 0, z: 0.5 };
|
|
1246
1241
|
const topRight = { x: width, y: 0, z: 0.5 };
|
|
@@ -1259,16 +1254,6 @@ function buildCircleBounds(anchorX, anchorY, cursorX, cursorY) {
|
|
|
1259
1254
|
function buildEllipseBounds(anchorX, anchorY, cursorX, cursorY) {
|
|
1260
1255
|
return toSizedBounds(anchorX, anchorY, cursorX, cursorY, false);
|
|
1261
1256
|
}
|
|
1262
|
-
function buildDefaultCenteredEllipseBounds(centerX, centerY) {
|
|
1263
|
-
const halfWidth = DEFAULT_ELLIPSE_WIDTH / 2;
|
|
1264
|
-
const halfHeight = DEFAULT_ELLIPSE_HEIGHT / 2;
|
|
1265
|
-
return {
|
|
1266
|
-
x: centerX - halfWidth,
|
|
1267
|
-
y: centerY - halfHeight,
|
|
1268
|
-
width: DEFAULT_ELLIPSE_WIDTH,
|
|
1269
|
-
height: DEFAULT_ELLIPSE_HEIGHT
|
|
1270
|
-
};
|
|
1271
|
-
}
|
|
1272
1257
|
function buildEllipseSegments(width, height) {
|
|
1273
1258
|
const centerX = width / 2;
|
|
1274
1259
|
const centerY = height / 2;
|
|
@@ -1296,7 +1281,6 @@ var SquareDrawingState = class extends GeometricDrawingState {
|
|
|
1296
1281
|
idleStateId: "square_idle",
|
|
1297
1282
|
buildConstrainedBounds: buildSquareBounds,
|
|
1298
1283
|
buildUnconstrainedBounds: buildRectangleBounds,
|
|
1299
|
-
buildDefaultBounds: buildDefaultCenteredRectangleBounds,
|
|
1300
1284
|
buildSegments: buildRectangleSegments
|
|
1301
1285
|
};
|
|
1302
1286
|
}
|
|
@@ -1318,7 +1302,6 @@ var CircleDrawingState = class extends GeometricDrawingState {
|
|
|
1318
1302
|
idleStateId: "circle_idle",
|
|
1319
1303
|
buildConstrainedBounds: buildCircleBounds,
|
|
1320
1304
|
buildUnconstrainedBounds: buildEllipseBounds,
|
|
1321
|
-
buildDefaultBounds: buildDefaultCenteredEllipseBounds,
|
|
1322
1305
|
buildSegments: buildEllipseSegments
|
|
1323
1306
|
};
|
|
1324
1307
|
}
|