@tsdraw/core 0.8.1 → 0.8.3
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 +27 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -11
- package/dist/index.d.ts +1 -11
- package/dist/index.js +28 -79
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -63,7 +63,6 @@ interface TsdrawSessionStateSnapshot {
|
|
|
63
63
|
x: number;
|
|
64
64
|
y: number;
|
|
65
65
|
zoom: number;
|
|
66
|
-
rotation?: number;
|
|
67
66
|
};
|
|
68
67
|
currentToolId: string;
|
|
69
68
|
drawStyle: {
|
|
@@ -222,7 +221,6 @@ interface Viewport {
|
|
|
222
221
|
x: number;
|
|
223
222
|
y: number;
|
|
224
223
|
zoom: number;
|
|
225
|
-
rotation: number;
|
|
226
224
|
}
|
|
227
225
|
declare function createViewport(): Viewport;
|
|
228
226
|
declare function screenToPage(viewport: Viewport, screenX: number, screenY: number): {
|
|
@@ -237,11 +235,9 @@ declare function setViewport(viewport: Viewport, updater: {
|
|
|
237
235
|
x?: number;
|
|
238
236
|
y?: number;
|
|
239
237
|
zoom?: number;
|
|
240
|
-
rotation?: number;
|
|
241
238
|
}): Viewport;
|
|
242
239
|
declare function panViewport(viewport: Viewport, dx: number, dy: number): Viewport;
|
|
243
240
|
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;
|
|
245
241
|
|
|
246
242
|
type TsdrawRenderTheme = 'light' | 'dark';
|
|
247
243
|
declare function resolveThemeColor(colorStyle: string, theme: TsdrawRenderTheme): string;
|
|
@@ -348,7 +344,6 @@ declare class Editor {
|
|
|
348
344
|
setViewport(partial: Partial<Viewport>): void;
|
|
349
345
|
panBy(dx: number, dy: number): void;
|
|
350
346
|
zoomAt(factor: number, screenX: number, screenY: number): void;
|
|
351
|
-
rotateAt(delta: number, screenX: number, screenY: number): void;
|
|
352
347
|
deleteShapes(ids: ShapeId[]): void;
|
|
353
348
|
getDocumentSnapshot(): TsdrawDocumentSnapshot;
|
|
354
349
|
loadDocumentSnapshot(snapshot: TsdrawDocumentSnapshot): void;
|
|
@@ -429,18 +424,15 @@ interface ShapeBounds {
|
|
|
429
424
|
}
|
|
430
425
|
declare function buildSquareBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
431
426
|
declare function buildRectangleBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
432
|
-
declare function buildDefaultCenteredRectangleBounds(centerX: number, centerY: number): ShapeBounds;
|
|
433
427
|
declare function buildRectangleSegments(width: number, height: number): DrawSegment[];
|
|
434
428
|
declare function buildCircleBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
435
429
|
declare function buildEllipseBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
436
|
-
declare function buildDefaultCenteredEllipseBounds(centerX: number, centerY: number): ShapeBounds;
|
|
437
430
|
declare function buildEllipseSegments(width: number, height: number): DrawSegment[];
|
|
438
431
|
|
|
439
432
|
interface GeometricDrawingStateConfig {
|
|
440
433
|
idleStateId: string;
|
|
441
434
|
buildConstrainedBounds: (anchorX: number, anchorY: number, cursorX: number, cursorY: number) => ShapeBounds;
|
|
442
435
|
buildUnconstrainedBounds: (anchorX: number, anchorY: number, cursorX: number, cursorY: number) => ShapeBounds;
|
|
443
|
-
buildDefaultBounds: (centerX: number, centerY: number) => ShapeBounds;
|
|
444
436
|
buildSegments: (width: number, height: number) => DrawSegment[];
|
|
445
437
|
}
|
|
446
438
|
declare abstract class GeometricDrawingState extends StateNode {
|
|
@@ -465,7 +457,6 @@ declare class SquareDrawingState extends GeometricDrawingState {
|
|
|
465
457
|
idleStateId: string;
|
|
466
458
|
buildConstrainedBounds: typeof buildSquareBounds;
|
|
467
459
|
buildUnconstrainedBounds: typeof buildRectangleBounds;
|
|
468
|
-
buildDefaultBounds: typeof buildDefaultCenteredRectangleBounds;
|
|
469
460
|
buildSegments: typeof buildRectangleSegments;
|
|
470
461
|
};
|
|
471
462
|
}
|
|
@@ -481,7 +472,6 @@ declare class CircleDrawingState extends GeometricDrawingState {
|
|
|
481
472
|
idleStateId: string;
|
|
482
473
|
buildConstrainedBounds: typeof buildCircleBounds;
|
|
483
474
|
buildUnconstrainedBounds: typeof buildEllipseBounds;
|
|
484
|
-
buildDefaultBounds: typeof buildDefaultCenteredEllipseBounds;
|
|
485
475
|
buildSegments: typeof buildEllipseSegments;
|
|
486
476
|
};
|
|
487
477
|
}
|
|
@@ -635,4 +625,4 @@ declare function decodePathToPoints(segments: {
|
|
|
635
625
|
y: number;
|
|
636
626
|
}[];
|
|
637
627
|
|
|
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,
|
|
628
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -63,7 +63,6 @@ interface TsdrawSessionStateSnapshot {
|
|
|
63
63
|
x: number;
|
|
64
64
|
y: number;
|
|
65
65
|
zoom: number;
|
|
66
|
-
rotation?: number;
|
|
67
66
|
};
|
|
68
67
|
currentToolId: string;
|
|
69
68
|
drawStyle: {
|
|
@@ -222,7 +221,6 @@ interface Viewport {
|
|
|
222
221
|
x: number;
|
|
223
222
|
y: number;
|
|
224
223
|
zoom: number;
|
|
225
|
-
rotation: number;
|
|
226
224
|
}
|
|
227
225
|
declare function createViewport(): Viewport;
|
|
228
226
|
declare function screenToPage(viewport: Viewport, screenX: number, screenY: number): {
|
|
@@ -237,11 +235,9 @@ declare function setViewport(viewport: Viewport, updater: {
|
|
|
237
235
|
x?: number;
|
|
238
236
|
y?: number;
|
|
239
237
|
zoom?: number;
|
|
240
|
-
rotation?: number;
|
|
241
238
|
}): Viewport;
|
|
242
239
|
declare function panViewport(viewport: Viewport, dx: number, dy: number): Viewport;
|
|
243
240
|
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;
|
|
245
241
|
|
|
246
242
|
type TsdrawRenderTheme = 'light' | 'dark';
|
|
247
243
|
declare function resolveThemeColor(colorStyle: string, theme: TsdrawRenderTheme): string;
|
|
@@ -348,7 +344,6 @@ declare class Editor {
|
|
|
348
344
|
setViewport(partial: Partial<Viewport>): void;
|
|
349
345
|
panBy(dx: number, dy: number): void;
|
|
350
346
|
zoomAt(factor: number, screenX: number, screenY: number): void;
|
|
351
|
-
rotateAt(delta: number, screenX: number, screenY: number): void;
|
|
352
347
|
deleteShapes(ids: ShapeId[]): void;
|
|
353
348
|
getDocumentSnapshot(): TsdrawDocumentSnapshot;
|
|
354
349
|
loadDocumentSnapshot(snapshot: TsdrawDocumentSnapshot): void;
|
|
@@ -429,18 +424,15 @@ interface ShapeBounds {
|
|
|
429
424
|
}
|
|
430
425
|
declare function buildSquareBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
431
426
|
declare function buildRectangleBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
432
|
-
declare function buildDefaultCenteredRectangleBounds(centerX: number, centerY: number): ShapeBounds;
|
|
433
427
|
declare function buildRectangleSegments(width: number, height: number): DrawSegment[];
|
|
434
428
|
declare function buildCircleBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
435
429
|
declare function buildEllipseBounds(anchorX: number, anchorY: number, cursorX: number, cursorY: number): ShapeBounds;
|
|
436
|
-
declare function buildDefaultCenteredEllipseBounds(centerX: number, centerY: number): ShapeBounds;
|
|
437
430
|
declare function buildEllipseSegments(width: number, height: number): DrawSegment[];
|
|
438
431
|
|
|
439
432
|
interface GeometricDrawingStateConfig {
|
|
440
433
|
idleStateId: string;
|
|
441
434
|
buildConstrainedBounds: (anchorX: number, anchorY: number, cursorX: number, cursorY: number) => ShapeBounds;
|
|
442
435
|
buildUnconstrainedBounds: (anchorX: number, anchorY: number, cursorX: number, cursorY: number) => ShapeBounds;
|
|
443
|
-
buildDefaultBounds: (centerX: number, centerY: number) => ShapeBounds;
|
|
444
436
|
buildSegments: (width: number, height: number) => DrawSegment[];
|
|
445
437
|
}
|
|
446
438
|
declare abstract class GeometricDrawingState extends StateNode {
|
|
@@ -465,7 +457,6 @@ declare class SquareDrawingState extends GeometricDrawingState {
|
|
|
465
457
|
idleStateId: string;
|
|
466
458
|
buildConstrainedBounds: typeof buildSquareBounds;
|
|
467
459
|
buildUnconstrainedBounds: typeof buildRectangleBounds;
|
|
468
|
-
buildDefaultBounds: typeof buildDefaultCenteredRectangleBounds;
|
|
469
460
|
buildSegments: typeof buildRectangleSegments;
|
|
470
461
|
};
|
|
471
462
|
}
|
|
@@ -481,7 +472,6 @@ declare class CircleDrawingState extends GeometricDrawingState {
|
|
|
481
472
|
idleStateId: string;
|
|
482
473
|
buildConstrainedBounds: typeof buildCircleBounds;
|
|
483
474
|
buildUnconstrainedBounds: typeof buildEllipseBounds;
|
|
484
|
-
buildDefaultBounds: typeof buildDefaultCenteredEllipseBounds;
|
|
485
475
|
buildSegments: typeof buildEllipseSegments;
|
|
486
476
|
};
|
|
487
477
|
}
|
|
@@ -635,4 +625,4 @@ declare function decodePathToPoints(segments: {
|
|
|
635
625
|
y: number;
|
|
636
626
|
}[];
|
|
637
627
|
|
|
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,
|
|
628
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -223,34 +223,25 @@ 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 };
|
|
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);
|
|
233
229
|
return {
|
|
234
|
-
x: (
|
|
235
|
-
y: (-
|
|
230
|
+
x: (screenX - viewport.x) / viewport.zoom,
|
|
231
|
+
y: (screenY - viewport.y) / viewport.zoom
|
|
236
232
|
};
|
|
237
233
|
}
|
|
238
234
|
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);
|
|
243
235
|
return {
|
|
244
|
-
x:
|
|
245
|
-
y:
|
|
236
|
+
x: pageX * viewport.zoom + viewport.x,
|
|
237
|
+
y: pageY * viewport.zoom + viewport.y
|
|
246
238
|
};
|
|
247
239
|
}
|
|
248
240
|
function setViewport(viewport, updater) {
|
|
249
241
|
return {
|
|
250
242
|
x: updater.x ?? viewport.x,
|
|
251
243
|
y: updater.y ?? viewport.y,
|
|
252
|
-
zoom: updater.zoom ?? viewport.zoom
|
|
253
|
-
rotation: updater.rotation ?? viewport.rotation
|
|
244
|
+
zoom: updater.zoom ?? viewport.zoom
|
|
254
245
|
};
|
|
255
246
|
}
|
|
256
247
|
function panViewport(viewport, dx, dy) {
|
|
@@ -262,23 +253,9 @@ function zoomViewport(viewport, factor, centerX, centerY) {
|
|
|
262
253
|
return { ...viewport, zoom };
|
|
263
254
|
}
|
|
264
255
|
const pageBefore = screenToPage(viewport, centerX, centerY);
|
|
265
|
-
const
|
|
266
|
-
const
|
|
267
|
-
|
|
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 };
|
|
256
|
+
const x = centerX - pageBefore.x * zoom;
|
|
257
|
+
const y = centerY - pageBefore.y * zoom;
|
|
258
|
+
return { x, y, zoom };
|
|
282
259
|
}
|
|
283
260
|
|
|
284
261
|
// src/utils/colors.ts
|
|
@@ -311,7 +288,6 @@ var CanvasRenderer = class {
|
|
|
311
288
|
render(ctx, viewport, shapes) {
|
|
312
289
|
ctx.save();
|
|
313
290
|
ctx.translate(viewport.x, viewport.y);
|
|
314
|
-
ctx.rotate(viewport.rotation);
|
|
315
291
|
ctx.scale(viewport.zoom, viewport.zoom);
|
|
316
292
|
for (const shape of shapes) {
|
|
317
293
|
if (shape.type === "draw") {
|
|
@@ -804,7 +780,7 @@ var PenDrawingState = class extends StateNode {
|
|
|
804
780
|
const z = this._startInfo?.point?.z ?? 0.5;
|
|
805
781
|
this._isPenDevice = penActive;
|
|
806
782
|
this._hasPressure = penActive || z !== 0.5;
|
|
807
|
-
const pressure = this._hasPressure ? toFixed(z) : 0.5;
|
|
783
|
+
const pressure = this._hasPressure ? toFixed(z * 1.25) : 0.5;
|
|
808
784
|
this._phase = inputs.getShiftKey() ? "straight" : "free";
|
|
809
785
|
this._extending = false;
|
|
810
786
|
this._lastSample = { ...origin };
|
|
@@ -901,13 +877,12 @@ var PenDrawingState = class extends StateNode {
|
|
|
901
877
|
const curPt = inputs.getCurrentPagePoint();
|
|
902
878
|
if (!this._hasPressure) {
|
|
903
879
|
const liveZ = curPt.z ?? 0.5;
|
|
904
|
-
if (liveZ !== 0.5 || inputs.getIsPen()) {
|
|
880
|
+
if (liveZ > 0 && liveZ !== 0.5 || inputs.getIsPen()) {
|
|
905
881
|
this._hasPressure = true;
|
|
906
|
-
this.editor.updateShapes([{ id, type: "draw", props: { isPen: true } }]);
|
|
907
882
|
}
|
|
908
883
|
}
|
|
909
884
|
const local = this.editor.getPointInShapeSpace(shape, curPt);
|
|
910
|
-
const pressure = this._hasPressure ? toFixed(curPt.z ?? 0.5) : 0.5;
|
|
885
|
+
const pressure = this._hasPressure ? toFixed((curPt.z ?? 0.5) * 1.25) : 0.5;
|
|
911
886
|
const pt = { x: toFixed(local.x), y: toFixed(local.y), z: pressure };
|
|
912
887
|
switch (this._phase) {
|
|
913
888
|
case "starting_straight": {
|
|
@@ -1053,7 +1028,7 @@ var PenDrawingState = class extends StateNode {
|
|
|
1053
1028
|
const firstPt = {
|
|
1054
1029
|
x: 0,
|
|
1055
1030
|
y: 0,
|
|
1056
|
-
z: this._hasPressure ? toFixed(curPage.z ?? 0.5) : 0.5
|
|
1031
|
+
z: this._hasPressure ? toFixed((curPage.z ?? 0.5) * 1.25) : 0.5
|
|
1057
1032
|
};
|
|
1058
1033
|
this._activePts = [firstPt];
|
|
1059
1034
|
this.editor.createShape({
|
|
@@ -1085,7 +1060,7 @@ var PenDrawingState = class extends StateNode {
|
|
|
1085
1060
|
endStroke() {
|
|
1086
1061
|
if (!this._target) return;
|
|
1087
1062
|
this.editor.updateShapes([
|
|
1088
|
-
{ id: this._target.id, type: "draw", props: { isComplete: true } }
|
|
1063
|
+
{ id: this._target.id, type: "draw", props: { isComplete: true, isPen: this._hasPressure } }
|
|
1089
1064
|
]);
|
|
1090
1065
|
this.ctx.transition("pen_idle");
|
|
1091
1066
|
}
|
|
@@ -1164,6 +1139,7 @@ var GeometricDrawingState = class extends StateNode {
|
|
|
1164
1139
|
}
|
|
1165
1140
|
// If user dragged, use the drag extents for the final shape
|
|
1166
1141
|
// If they just clicked without dragging, use default-sized shape
|
|
1142
|
+
// If they dragged just a bit (most likely a click), remove the shape and go back to idle
|
|
1167
1143
|
completeShape() {
|
|
1168
1144
|
const activeShape = this.getActiveShape();
|
|
1169
1145
|
const config = this.getConfig();
|
|
@@ -1173,7 +1149,15 @@ var GeometricDrawingState = class extends StateNode {
|
|
|
1173
1149
|
}
|
|
1174
1150
|
const originPoint = this.editor.input.getOriginPagePoint();
|
|
1175
1151
|
const cursorPoint = this.editor.input.getCurrentPagePoint();
|
|
1176
|
-
const
|
|
1152
|
+
const dx = cursorPoint.x - originPoint.x;
|
|
1153
|
+
const dy = cursorPoint.y - originPoint.y;
|
|
1154
|
+
const draggedFarEnough = dx * dx + dy * dy > this.editor.options.dragDistanceSquared;
|
|
1155
|
+
if (!draggedFarEnough) {
|
|
1156
|
+
this.removeCurrentShape();
|
|
1157
|
+
this.ctx.transition(config.idleStateId, this.startedAt);
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
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
1161
|
this.editor.store.updateShape(activeShape.id, {
|
|
1178
1162
|
x: finalizedBounds.x,
|
|
1179
1163
|
y: finalizedBounds.y,
|
|
@@ -1203,10 +1187,6 @@ var GeometricDrawingState = class extends StateNode {
|
|
|
1203
1187
|
|
|
1204
1188
|
// src/tools/geometric/geometricShapeHelpers.ts
|
|
1205
1189
|
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
1190
|
function toSizedBounds(anchorX, anchorY, cursorX, cursorY, forceEqualSides) {
|
|
1211
1191
|
const rawDeltaX = cursorX - anchorX;
|
|
1212
1192
|
const rawDeltaY = cursorY - anchorY;
|
|
@@ -1231,16 +1211,6 @@ function buildSquareBounds(anchorX, anchorY, cursorX, cursorY) {
|
|
|
1231
1211
|
function buildRectangleBounds(anchorX, anchorY, cursorX, cursorY) {
|
|
1232
1212
|
return toSizedBounds(anchorX, anchorY, cursorX, cursorY, false);
|
|
1233
1213
|
}
|
|
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
1214
|
function buildRectangleSegments(width, height) {
|
|
1245
1215
|
const topLeft = { x: 0, y: 0, z: 0.5 };
|
|
1246
1216
|
const topRight = { x: width, y: 0, z: 0.5 };
|
|
@@ -1259,16 +1229,6 @@ function buildCircleBounds(anchorX, anchorY, cursorX, cursorY) {
|
|
|
1259
1229
|
function buildEllipseBounds(anchorX, anchorY, cursorX, cursorY) {
|
|
1260
1230
|
return toSizedBounds(anchorX, anchorY, cursorX, cursorY, false);
|
|
1261
1231
|
}
|
|
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
1232
|
function buildEllipseSegments(width, height) {
|
|
1273
1233
|
const centerX = width / 2;
|
|
1274
1234
|
const centerY = height / 2;
|
|
@@ -1296,7 +1256,6 @@ var SquareDrawingState = class extends GeometricDrawingState {
|
|
|
1296
1256
|
idleStateId: "square_idle",
|
|
1297
1257
|
buildConstrainedBounds: buildSquareBounds,
|
|
1298
1258
|
buildUnconstrainedBounds: buildRectangleBounds,
|
|
1299
|
-
buildDefaultBounds: buildDefaultCenteredRectangleBounds,
|
|
1300
1259
|
buildSegments: buildRectangleSegments
|
|
1301
1260
|
};
|
|
1302
1261
|
}
|
|
@@ -1318,7 +1277,6 @@ var CircleDrawingState = class extends GeometricDrawingState {
|
|
|
1318
1277
|
idleStateId: "circle_idle",
|
|
1319
1278
|
buildConstrainedBounds: buildCircleBounds,
|
|
1320
1279
|
buildUnconstrainedBounds: buildEllipseBounds,
|
|
1321
|
-
buildDefaultBounds: buildDefaultCenteredEllipseBounds,
|
|
1322
1280
|
buildSegments: buildEllipseSegments
|
|
1323
1281
|
};
|
|
1324
1282
|
}
|
|
@@ -1769,8 +1727,7 @@ var Editor = class {
|
|
|
1769
1727
|
this.viewport = {
|
|
1770
1728
|
x: partial.x ?? this.viewport.x,
|
|
1771
1729
|
y: partial.y ?? this.viewport.y,
|
|
1772
|
-
zoom: Math.max(0.1, Math.min(4, rawZoom))
|
|
1773
|
-
rotation: partial.rotation ?? this.viewport.rotation
|
|
1730
|
+
zoom: Math.max(0.1, Math.min(4, rawZoom))
|
|
1774
1731
|
};
|
|
1775
1732
|
this.emitChange();
|
|
1776
1733
|
}
|
|
@@ -1784,10 +1741,6 @@ var Editor = class {
|
|
|
1784
1741
|
this.viewport = zoomViewport(this.viewport, factor, screenX, screenY);
|
|
1785
1742
|
this.emitChange();
|
|
1786
1743
|
}
|
|
1787
|
-
rotateAt(delta, screenX, screenY) {
|
|
1788
|
-
this.viewport = rotateViewport(this.viewport, delta, screenX, screenY);
|
|
1789
|
-
this.emitChange();
|
|
1790
|
-
}
|
|
1791
1744
|
deleteShapes(ids) {
|
|
1792
1745
|
if (ids.length === 0) return;
|
|
1793
1746
|
this.store.deleteShapes(ids);
|
|
@@ -1810,8 +1763,7 @@ var Editor = class {
|
|
|
1810
1763
|
viewport: {
|
|
1811
1764
|
x: this.viewport.x,
|
|
1812
1765
|
y: this.viewport.y,
|
|
1813
|
-
zoom: this.viewport.zoom
|
|
1814
|
-
rotation: this.viewport.rotation
|
|
1766
|
+
zoom: this.viewport.zoom
|
|
1815
1767
|
},
|
|
1816
1768
|
currentToolId: this.getCurrentToolId(),
|
|
1817
1769
|
drawStyle: this.getCurrentDrawStyle(),
|
|
@@ -1819,10 +1771,7 @@ var Editor = class {
|
|
|
1819
1771
|
};
|
|
1820
1772
|
}
|
|
1821
1773
|
loadSessionStateSnapshot(snapshot) {
|
|
1822
|
-
this.setViewport(
|
|
1823
|
-
...snapshot.viewport,
|
|
1824
|
-
rotation: snapshot.viewport.rotation ?? 0
|
|
1825
|
-
});
|
|
1774
|
+
this.setViewport(snapshot.viewport);
|
|
1826
1775
|
this.setCurrentDrawStyle({
|
|
1827
1776
|
color: snapshot.drawStyle.color,
|
|
1828
1777
|
dash: snapshot.drawStyle.dash,
|
|
@@ -2209,6 +2158,6 @@ function applyResize(editor, handle, startBounds, startShapes, pointer, lockAspe
|
|
|
2209
2158
|
}
|
|
2210
2159
|
}
|
|
2211
2160
|
|
|
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,
|
|
2161
|
+
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 };
|
|
2213
2162
|
//# sourceMappingURL=index.js.map
|
|
2214
2163
|
//# sourceMappingURL=index.js.map
|