@tsdraw/core 0.7.0 → 0.8.1
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 +72 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +72 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -63,6 +63,7 @@ interface TsdrawSessionStateSnapshot {
|
|
|
63
63
|
x: number;
|
|
64
64
|
y: number;
|
|
65
65
|
zoom: number;
|
|
66
|
+
rotation?: number;
|
|
66
67
|
};
|
|
67
68
|
currentToolId: string;
|
|
68
69
|
drawStyle: {
|
|
@@ -221,6 +222,7 @@ interface Viewport {
|
|
|
221
222
|
x: number;
|
|
222
223
|
y: number;
|
|
223
224
|
zoom: number;
|
|
225
|
+
rotation: number;
|
|
224
226
|
}
|
|
225
227
|
declare function createViewport(): Viewport;
|
|
226
228
|
declare function screenToPage(viewport: Viewport, screenX: number, screenY: number): {
|
|
@@ -235,9 +237,11 @@ declare function setViewport(viewport: Viewport, updater: {
|
|
|
235
237
|
x?: number;
|
|
236
238
|
y?: number;
|
|
237
239
|
zoom?: number;
|
|
240
|
+
rotation?: number;
|
|
238
241
|
}): Viewport;
|
|
239
242
|
declare function panViewport(viewport: Viewport, dx: number, dy: number): Viewport;
|
|
240
243
|
declare function zoomViewport(viewport: Viewport, factor: number, centerX?: number, centerY?: number): Viewport;
|
|
244
|
+
declare function rotateViewport(viewport: Viewport, delta: number, centerX?: number, centerY?: number): Viewport;
|
|
241
245
|
|
|
242
246
|
type TsdrawRenderTheme = 'light' | 'dark';
|
|
243
247
|
declare function resolveThemeColor(colorStyle: string, theme: TsdrawRenderTheme): string;
|
|
@@ -343,6 +347,9 @@ declare class Editor {
|
|
|
343
347
|
}>): void;
|
|
344
348
|
setViewport(partial: Partial<Viewport>): void;
|
|
345
349
|
panBy(dx: number, dy: number): void;
|
|
350
|
+
zoomAt(factor: number, screenX: number, screenY: number): void;
|
|
351
|
+
rotateAt(delta: number, screenX: number, screenY: number): void;
|
|
352
|
+
deleteShapes(ids: ShapeId[]): void;
|
|
346
353
|
getDocumentSnapshot(): TsdrawDocumentSnapshot;
|
|
347
354
|
loadDocumentSnapshot(snapshot: TsdrawDocumentSnapshot): void;
|
|
348
355
|
getSessionStateSnapshot(args?: {
|
|
@@ -628,4 +635,4 @@ declare function decodePathToPoints(segments: {
|
|
|
628
635
|
y: number;
|
|
629
636
|
}[];
|
|
630
637
|
|
|
631
|
-
export { type Bounds, CanvasRenderer, CircleDrawingState, CircleIdleState, type ColorStyle, DEFAULT_COLORS, DRAG_DISTANCE_SQUARED, type DashStyle, type DefaultToolId, DocumentStore, type DocumentStoreSnapshot, type DrawSegment, type DrawShape, ERASER_MARGIN, Editor, type EditorOptions, EraserErasingState, EraserIdleState, EraserPointingState, type FillStyle, HandDraggingState, HandIdleState, type ICanvasRenderer, type IEditor, InputManager, MAX_POINTS_PER_SHAPE, type PageState, PenDrawingState, PenIdleState, type PointerInput, type ResizeHandle, STROKE_WIDTHS, type SegmentType, SelectIdleState, type SelectionBounds, type Shape, type ShapeId, type SizeStyle, SquareDrawingState, SquareIdleState, StateNode, type StateNodeConstructor, type ToolDefinition, type ToolId, type ToolKeyInfo, ToolManager, type ToolPointerDownInfo, type ToolPointerMoveInfo, type ToolStateContext, type ToolStateTransitionInfo, type TransformSnapshot, type TsdrawDocumentSnapshot, type TsdrawEditorSnapshot, type TsdrawHistorySnapshot, type TsdrawPageRecord, type TsdrawPersistedRecord, type TsdrawRenderTheme, type TsdrawSessionStateSnapshot, type TsdrawShapeRecord, type Vec3, type Viewport, applyMove, applyResize, applyRotation, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, resolveThemeColor, rotatePoint, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, zoomViewport };
|
|
638
|
+
export { type Bounds, CanvasRenderer, CircleDrawingState, CircleIdleState, type ColorStyle, DEFAULT_COLORS, DRAG_DISTANCE_SQUARED, type DashStyle, type DefaultToolId, DocumentStore, type DocumentStoreSnapshot, type DrawSegment, type DrawShape, ERASER_MARGIN, Editor, type EditorOptions, EraserErasingState, EraserIdleState, EraserPointingState, type FillStyle, HandDraggingState, HandIdleState, type ICanvasRenderer, type IEditor, InputManager, MAX_POINTS_PER_SHAPE, type PageState, PenDrawingState, PenIdleState, type PointerInput, type ResizeHandle, STROKE_WIDTHS, type SegmentType, SelectIdleState, type SelectionBounds, type Shape, type ShapeId, type SizeStyle, SquareDrawingState, SquareIdleState, StateNode, type StateNodeConstructor, type ToolDefinition, type ToolId, type ToolKeyInfo, ToolManager, type ToolPointerDownInfo, type ToolPointerMoveInfo, type ToolStateContext, type ToolStateTransitionInfo, type TransformSnapshot, type TsdrawDocumentSnapshot, type TsdrawEditorSnapshot, type TsdrawHistorySnapshot, type TsdrawPageRecord, type TsdrawPersistedRecord, type TsdrawRenderTheme, type TsdrawSessionStateSnapshot, type TsdrawShapeRecord, type Vec3, type Viewport, applyMove, applyResize, applyRotation, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, resolveThemeColor, rotatePoint, rotateViewport, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, zoomViewport };
|
package/dist/index.d.ts
CHANGED
|
@@ -63,6 +63,7 @@ interface TsdrawSessionStateSnapshot {
|
|
|
63
63
|
x: number;
|
|
64
64
|
y: number;
|
|
65
65
|
zoom: number;
|
|
66
|
+
rotation?: number;
|
|
66
67
|
};
|
|
67
68
|
currentToolId: string;
|
|
68
69
|
drawStyle: {
|
|
@@ -221,6 +222,7 @@ interface Viewport {
|
|
|
221
222
|
x: number;
|
|
222
223
|
y: number;
|
|
223
224
|
zoom: number;
|
|
225
|
+
rotation: number;
|
|
224
226
|
}
|
|
225
227
|
declare function createViewport(): Viewport;
|
|
226
228
|
declare function screenToPage(viewport: Viewport, screenX: number, screenY: number): {
|
|
@@ -235,9 +237,11 @@ declare function setViewport(viewport: Viewport, updater: {
|
|
|
235
237
|
x?: number;
|
|
236
238
|
y?: number;
|
|
237
239
|
zoom?: number;
|
|
240
|
+
rotation?: number;
|
|
238
241
|
}): Viewport;
|
|
239
242
|
declare function panViewport(viewport: Viewport, dx: number, dy: number): Viewport;
|
|
240
243
|
declare function zoomViewport(viewport: Viewport, factor: number, centerX?: number, centerY?: number): Viewport;
|
|
244
|
+
declare function rotateViewport(viewport: Viewport, delta: number, centerX?: number, centerY?: number): Viewport;
|
|
241
245
|
|
|
242
246
|
type TsdrawRenderTheme = 'light' | 'dark';
|
|
243
247
|
declare function resolveThemeColor(colorStyle: string, theme: TsdrawRenderTheme): string;
|
|
@@ -343,6 +347,9 @@ declare class Editor {
|
|
|
343
347
|
}>): void;
|
|
344
348
|
setViewport(partial: Partial<Viewport>): void;
|
|
345
349
|
panBy(dx: number, dy: number): void;
|
|
350
|
+
zoomAt(factor: number, screenX: number, screenY: number): void;
|
|
351
|
+
rotateAt(delta: number, screenX: number, screenY: number): void;
|
|
352
|
+
deleteShapes(ids: ShapeId[]): void;
|
|
346
353
|
getDocumentSnapshot(): TsdrawDocumentSnapshot;
|
|
347
354
|
loadDocumentSnapshot(snapshot: TsdrawDocumentSnapshot): void;
|
|
348
355
|
getSessionStateSnapshot(args?: {
|
|
@@ -628,4 +635,4 @@ declare function decodePathToPoints(segments: {
|
|
|
628
635
|
y: number;
|
|
629
636
|
}[];
|
|
630
637
|
|
|
631
|
-
export { type Bounds, CanvasRenderer, CircleDrawingState, CircleIdleState, type ColorStyle, DEFAULT_COLORS, DRAG_DISTANCE_SQUARED, type DashStyle, type DefaultToolId, DocumentStore, type DocumentStoreSnapshot, type DrawSegment, type DrawShape, ERASER_MARGIN, Editor, type EditorOptions, EraserErasingState, EraserIdleState, EraserPointingState, type FillStyle, HandDraggingState, HandIdleState, type ICanvasRenderer, type IEditor, InputManager, MAX_POINTS_PER_SHAPE, type PageState, PenDrawingState, PenIdleState, type PointerInput, type ResizeHandle, STROKE_WIDTHS, type SegmentType, SelectIdleState, type SelectionBounds, type Shape, type ShapeId, type SizeStyle, SquareDrawingState, SquareIdleState, StateNode, type StateNodeConstructor, type ToolDefinition, type ToolId, type ToolKeyInfo, ToolManager, type ToolPointerDownInfo, type ToolPointerMoveInfo, type ToolStateContext, type ToolStateTransitionInfo, type TransformSnapshot, type TsdrawDocumentSnapshot, type TsdrawEditorSnapshot, type TsdrawHistorySnapshot, type TsdrawPageRecord, type TsdrawPersistedRecord, type TsdrawRenderTheme, type TsdrawSessionStateSnapshot, type TsdrawShapeRecord, type Vec3, type Viewport, applyMove, applyResize, applyRotation, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, resolveThemeColor, rotatePoint, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, zoomViewport };
|
|
638
|
+
export { type Bounds, CanvasRenderer, CircleDrawingState, CircleIdleState, type ColorStyle, DEFAULT_COLORS, DRAG_DISTANCE_SQUARED, type DashStyle, type DefaultToolId, DocumentStore, type DocumentStoreSnapshot, type DrawSegment, type DrawShape, ERASER_MARGIN, Editor, type EditorOptions, EraserErasingState, EraserIdleState, EraserPointingState, type FillStyle, HandDraggingState, HandIdleState, type ICanvasRenderer, type IEditor, InputManager, MAX_POINTS_PER_SHAPE, type PageState, PenDrawingState, PenIdleState, type PointerInput, type ResizeHandle, STROKE_WIDTHS, type SegmentType, SelectIdleState, type SelectionBounds, type Shape, type ShapeId, type SizeStyle, SquareDrawingState, SquareIdleState, StateNode, type StateNodeConstructor, type ToolDefinition, type ToolId, type ToolKeyInfo, ToolManager, type ToolPointerDownInfo, type ToolPointerMoveInfo, type ToolStateContext, type ToolStateTransitionInfo, type TransformSnapshot, type TsdrawDocumentSnapshot, type TsdrawEditorSnapshot, type TsdrawHistorySnapshot, type TsdrawPageRecord, type TsdrawPersistedRecord, type TsdrawRenderTheme, type TsdrawSessionStateSnapshot, type TsdrawShapeRecord, type Vec3, type Viewport, applyMove, applyResize, applyRotation, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, resolveThemeColor, rotatePoint, rotateViewport, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, zoomViewport };
|
package/dist/index.js
CHANGED
|
@@ -223,25 +223,34 @@ var StateNode = class {
|
|
|
223
223
|
|
|
224
224
|
// src/canvas/viewport.ts
|
|
225
225
|
function createViewport() {
|
|
226
|
-
return { x: 0, y: 0, zoom: 1 };
|
|
226
|
+
return { x: 0, y: 0, zoom: 1, rotation: 0 };
|
|
227
227
|
}
|
|
228
228
|
function screenToPage(viewport, screenX, screenY) {
|
|
229
|
+
const tx = screenX - viewport.x;
|
|
230
|
+
const ty = screenY - viewport.y;
|
|
231
|
+
const cos = Math.cos(viewport.rotation);
|
|
232
|
+
const sin = Math.sin(viewport.rotation);
|
|
229
233
|
return {
|
|
230
|
-
x: (
|
|
231
|
-
y: (
|
|
234
|
+
x: (tx * cos + ty * sin) / viewport.zoom,
|
|
235
|
+
y: (-tx * sin + ty * cos) / viewport.zoom
|
|
232
236
|
};
|
|
233
237
|
}
|
|
234
238
|
function pageToScreen(viewport, pageX, pageY) {
|
|
239
|
+
const scaledX = pageX * viewport.zoom;
|
|
240
|
+
const scaledY = pageY * viewport.zoom;
|
|
241
|
+
const cos = Math.cos(viewport.rotation);
|
|
242
|
+
const sin = Math.sin(viewport.rotation);
|
|
235
243
|
return {
|
|
236
|
-
x:
|
|
237
|
-
y:
|
|
244
|
+
x: scaledX * cos - scaledY * sin + viewport.x,
|
|
245
|
+
y: scaledX * sin + scaledY * cos + viewport.y
|
|
238
246
|
};
|
|
239
247
|
}
|
|
240
248
|
function setViewport(viewport, updater) {
|
|
241
249
|
return {
|
|
242
250
|
x: updater.x ?? viewport.x,
|
|
243
251
|
y: updater.y ?? viewport.y,
|
|
244
|
-
zoom: updater.zoom ?? viewport.zoom
|
|
252
|
+
zoom: updater.zoom ?? viewport.zoom,
|
|
253
|
+
rotation: updater.rotation ?? viewport.rotation
|
|
245
254
|
};
|
|
246
255
|
}
|
|
247
256
|
function panViewport(viewport, dx, dy) {
|
|
@@ -253,9 +262,23 @@ function zoomViewport(viewport, factor, centerX, centerY) {
|
|
|
253
262
|
return { ...viewport, zoom };
|
|
254
263
|
}
|
|
255
264
|
const pageBefore = screenToPage(viewport, centerX, centerY);
|
|
256
|
-
const
|
|
257
|
-
const
|
|
258
|
-
|
|
265
|
+
const cos = Math.cos(viewport.rotation);
|
|
266
|
+
const sin = Math.sin(viewport.rotation);
|
|
267
|
+
const x = centerX - (pageBefore.x * zoom * cos - pageBefore.y * zoom * sin);
|
|
268
|
+
const y = centerY - (pageBefore.x * zoom * sin + pageBefore.y * zoom * cos);
|
|
269
|
+
return { x, y, zoom, rotation: viewport.rotation };
|
|
270
|
+
}
|
|
271
|
+
function rotateViewport(viewport, delta, centerX, centerY) {
|
|
272
|
+
const rotation = viewport.rotation + delta;
|
|
273
|
+
if (centerX == null || centerY == null) {
|
|
274
|
+
return { ...viewport, rotation };
|
|
275
|
+
}
|
|
276
|
+
const pageBefore = screenToPage(viewport, centerX, centerY);
|
|
277
|
+
const cos = Math.cos(rotation);
|
|
278
|
+
const sin = Math.sin(rotation);
|
|
279
|
+
const x = centerX - (pageBefore.x * viewport.zoom * cos - pageBefore.y * viewport.zoom * sin);
|
|
280
|
+
const y = centerY - (pageBefore.x * viewport.zoom * sin + pageBefore.y * viewport.zoom * cos);
|
|
281
|
+
return { x, y, zoom: viewport.zoom, rotation };
|
|
259
282
|
}
|
|
260
283
|
|
|
261
284
|
// src/utils/colors.ts
|
|
@@ -288,6 +311,7 @@ var CanvasRenderer = class {
|
|
|
288
311
|
render(ctx, viewport, shapes) {
|
|
289
312
|
ctx.save();
|
|
290
313
|
ctx.translate(viewport.x, viewport.y);
|
|
314
|
+
ctx.rotate(viewport.rotation);
|
|
291
315
|
ctx.scale(viewport.zoom, viewport.zoom);
|
|
292
316
|
for (const shape of shapes) {
|
|
293
317
|
if (shape.type === "draw") {
|
|
@@ -448,9 +472,6 @@ function flattenSegments(shape) {
|
|
|
448
472
|
}
|
|
449
473
|
out.push(D);
|
|
450
474
|
}
|
|
451
|
-
if (out.length > 0 && !shape.props.isPen) {
|
|
452
|
-
for (const p of out) p.pressure = 0.5;
|
|
453
|
-
}
|
|
454
475
|
return out;
|
|
455
476
|
}
|
|
456
477
|
function getLineDash(dash, width) {
|
|
@@ -580,6 +601,7 @@ var ToolManager = class {
|
|
|
580
601
|
getCurrentState() {
|
|
581
602
|
return this.currentState;
|
|
582
603
|
}
|
|
604
|
+
// Transition between states within the same tool (ex. pen_idle -> pen_drawing)
|
|
583
605
|
transition(stateId, info) {
|
|
584
606
|
const next = this.states.get(stateId);
|
|
585
607
|
if (!next) return;
|
|
@@ -781,8 +803,8 @@ var PenDrawingState = class extends StateNode {
|
|
|
781
803
|
const penActive = inputs.getIsPen();
|
|
782
804
|
const z = this._startInfo?.point?.z ?? 0.5;
|
|
783
805
|
this._isPenDevice = penActive;
|
|
784
|
-
this._hasPressure = penActive
|
|
785
|
-
const pressure = this._hasPressure ? toFixed(z
|
|
806
|
+
this._hasPressure = penActive || z !== 0.5;
|
|
807
|
+
const pressure = this._hasPressure ? toFixed(z) : 0.5;
|
|
786
808
|
this._phase = inputs.getShiftKey() ? "straight" : "free";
|
|
787
809
|
this._extending = false;
|
|
788
810
|
this._lastSample = { ...origin };
|
|
@@ -877,8 +899,15 @@ var PenDrawingState = class extends StateNode {
|
|
|
877
899
|
const { id, props: { size, scale } } = target;
|
|
878
900
|
const { segments } = shape.props;
|
|
879
901
|
const curPt = inputs.getCurrentPagePoint();
|
|
902
|
+
if (!this._hasPressure) {
|
|
903
|
+
const liveZ = curPt.z ?? 0.5;
|
|
904
|
+
if (liveZ !== 0.5 || inputs.getIsPen()) {
|
|
905
|
+
this._hasPressure = true;
|
|
906
|
+
this.editor.updateShapes([{ id, type: "draw", props: { isPen: true } }]);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
880
909
|
const local = this.editor.getPointInShapeSpace(shape, curPt);
|
|
881
|
-
const pressure = this._hasPressure ? toFixed(
|
|
910
|
+
const pressure = this._hasPressure ? toFixed(curPt.z ?? 0.5) : 0.5;
|
|
882
911
|
const pt = { x: toFixed(local.x), y: toFixed(local.y), z: pressure };
|
|
883
912
|
switch (this._phase) {
|
|
884
913
|
case "starting_straight": {
|
|
@@ -1024,7 +1053,7 @@ var PenDrawingState = class extends StateNode {
|
|
|
1024
1053
|
const firstPt = {
|
|
1025
1054
|
x: 0,
|
|
1026
1055
|
y: 0,
|
|
1027
|
-
z: this._hasPressure ? toFixed(
|
|
1056
|
+
z: this._hasPressure ? toFixed(curPage.z ?? 0.5) : 0.5
|
|
1028
1057
|
};
|
|
1029
1058
|
this._activePts = [firstPt];
|
|
1030
1059
|
this.editor.createShape({
|
|
@@ -1099,6 +1128,7 @@ var GeometricDrawingState = class extends StateNode {
|
|
|
1099
1128
|
});
|
|
1100
1129
|
this.currentShapeId = nextShapeId;
|
|
1101
1130
|
}
|
|
1131
|
+
// Shift key switches between constrained and unconstrained bounds
|
|
1102
1132
|
onPointerMove() {
|
|
1103
1133
|
const activeShape = this.getActiveShape();
|
|
1104
1134
|
if (!activeShape) return;
|
|
@@ -1132,6 +1162,8 @@ var GeometricDrawingState = class extends StateNode {
|
|
|
1132
1162
|
onKeyUp() {
|
|
1133
1163
|
this.onPointerMove();
|
|
1134
1164
|
}
|
|
1165
|
+
// If user dragged, use the drag extents for the final shape
|
|
1166
|
+
// If they just clicked without dragging, use default-sized shape
|
|
1135
1167
|
completeShape() {
|
|
1136
1168
|
const activeShape = this.getActiveShape();
|
|
1137
1169
|
const config = this.getConfig();
|
|
@@ -1452,6 +1484,8 @@ var EraserErasingState = class extends StateNode {
|
|
|
1452
1484
|
onCancel() {
|
|
1453
1485
|
this.ctx.transition("eraser_idle");
|
|
1454
1486
|
}
|
|
1487
|
+
// On every pointer move, test the line from previous pointer position to current one against nearby shapes
|
|
1488
|
+
// Only select shapes whose bounding box overlaps the sweep area to avoid testing all shapes
|
|
1455
1489
|
sweep() {
|
|
1456
1490
|
const zoom = this.editor.getZoomLevel();
|
|
1457
1491
|
const tolerance = ERASER_MARGIN / zoom;
|
|
@@ -1470,6 +1504,7 @@ var EraserErasingState = class extends StateNode {
|
|
|
1470
1504
|
this._marked = [...hitIds];
|
|
1471
1505
|
this.editor.setErasingShapes(this._marked);
|
|
1472
1506
|
}
|
|
1507
|
+
// Delete marked shapes and reset, then go back to idle
|
|
1473
1508
|
finish() {
|
|
1474
1509
|
const ids = this.editor.getErasingShapeIds();
|
|
1475
1510
|
if (ids.length > 0) {
|
|
@@ -1734,7 +1769,8 @@ var Editor = class {
|
|
|
1734
1769
|
this.viewport = {
|
|
1735
1770
|
x: partial.x ?? this.viewport.x,
|
|
1736
1771
|
y: partial.y ?? this.viewport.y,
|
|
1737
|
-
zoom: Math.max(0.1, Math.min(4, rawZoom))
|
|
1772
|
+
zoom: Math.max(0.1, Math.min(4, rawZoom)),
|
|
1773
|
+
rotation: partial.rotation ?? this.viewport.rotation
|
|
1738
1774
|
};
|
|
1739
1775
|
this.emitChange();
|
|
1740
1776
|
}
|
|
@@ -1744,6 +1780,18 @@ var Editor = class {
|
|
|
1744
1780
|
y: this.viewport.y + dy
|
|
1745
1781
|
});
|
|
1746
1782
|
}
|
|
1783
|
+
zoomAt(factor, screenX, screenY) {
|
|
1784
|
+
this.viewport = zoomViewport(this.viewport, factor, screenX, screenY);
|
|
1785
|
+
this.emitChange();
|
|
1786
|
+
}
|
|
1787
|
+
rotateAt(delta, screenX, screenY) {
|
|
1788
|
+
this.viewport = rotateViewport(this.viewport, delta, screenX, screenY);
|
|
1789
|
+
this.emitChange();
|
|
1790
|
+
}
|
|
1791
|
+
deleteShapes(ids) {
|
|
1792
|
+
if (ids.length === 0) return;
|
|
1793
|
+
this.store.deleteShapes(ids);
|
|
1794
|
+
}
|
|
1747
1795
|
getDocumentSnapshot() {
|
|
1748
1796
|
return {
|
|
1749
1797
|
records: documentSnapshotToRecords(this.store.getSnapshot())
|
|
@@ -1762,7 +1810,8 @@ var Editor = class {
|
|
|
1762
1810
|
viewport: {
|
|
1763
1811
|
x: this.viewport.x,
|
|
1764
1812
|
y: this.viewport.y,
|
|
1765
|
-
zoom: this.viewport.zoom
|
|
1813
|
+
zoom: this.viewport.zoom,
|
|
1814
|
+
rotation: this.viewport.rotation
|
|
1766
1815
|
},
|
|
1767
1816
|
currentToolId: this.getCurrentToolId(),
|
|
1768
1817
|
drawStyle: this.getCurrentDrawStyle(),
|
|
@@ -1770,7 +1819,10 @@ var Editor = class {
|
|
|
1770
1819
|
};
|
|
1771
1820
|
}
|
|
1772
1821
|
loadSessionStateSnapshot(snapshot) {
|
|
1773
|
-
this.setViewport(
|
|
1822
|
+
this.setViewport({
|
|
1823
|
+
...snapshot.viewport,
|
|
1824
|
+
rotation: snapshot.viewport.rotation ?? 0
|
|
1825
|
+
});
|
|
1774
1826
|
this.setCurrentDrawStyle({
|
|
1775
1827
|
color: snapshot.drawStyle.color,
|
|
1776
1828
|
dash: snapshot.drawStyle.dash,
|
|
@@ -2157,6 +2209,6 @@ function applyResize(editor, handle, startBounds, startShapes, pointer, lockAspe
|
|
|
2157
2209
|
}
|
|
2158
2210
|
}
|
|
2159
2211
|
|
|
2160
|
-
export { CanvasRenderer, CircleDrawingState, CircleIdleState, DEFAULT_COLORS, DRAG_DISTANCE_SQUARED, DocumentStore, ERASER_MARGIN, Editor, EraserErasingState, EraserIdleState, EraserPointingState, HandDraggingState, HandIdleState, InputManager, MAX_POINTS_PER_SHAPE, PenDrawingState, PenIdleState, STROKE_WIDTHS, SelectIdleState, SquareDrawingState, SquareIdleState, StateNode, ToolManager, applyMove, applyResize, applyRotation, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds2 as getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, resolveThemeColor, rotatePoint, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, zoomViewport };
|
|
2212
|
+
export { CanvasRenderer, CircleDrawingState, CircleIdleState, DEFAULT_COLORS, DRAG_DISTANCE_SQUARED, DocumentStore, ERASER_MARGIN, Editor, EraserErasingState, EraserIdleState, EraserPointingState, HandDraggingState, HandIdleState, InputManager, MAX_POINTS_PER_SHAPE, PenDrawingState, PenIdleState, STROKE_WIDTHS, SelectIdleState, SquareDrawingState, SquareIdleState, StateNode, ToolManager, applyMove, applyResize, applyRotation, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds2 as getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, resolveThemeColor, rotatePoint, rotateViewport, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, zoomViewport };
|
|
2161
2213
|
//# sourceMappingURL=index.js.map
|
|
2162
2214
|
//# sourceMappingURL=index.js.map
|