@tsdraw/core 0.8.2 → 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.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;
@@ -630,4 +625,4 @@ declare function decodePathToPoints(segments: {
630
625
  y: number;
631
626
  }[];
632
627
 
633
- 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 };
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;
@@ -630,4 +625,4 @@ declare function decodePathToPoints(segments: {
630
625
  y: number;
631
626
  }[];
632
627
 
633
- 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 };
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, rotation: 0 };
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: (tx * cos + ty * sin) / viewport.zoom,
235
- y: (-tx * sin + ty * cos) / viewport.zoom
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: scaledX * cos - scaledY * sin + viewport.x,
245
- y: scaledX * sin + scaledY * cos + viewport.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 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 };
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
  }
@@ -1752,8 +1727,7 @@ var Editor = class {
1752
1727
  this.viewport = {
1753
1728
  x: partial.x ?? this.viewport.x,
1754
1729
  y: partial.y ?? this.viewport.y,
1755
- zoom: Math.max(0.1, Math.min(4, rawZoom)),
1756
- rotation: partial.rotation ?? this.viewport.rotation
1730
+ zoom: Math.max(0.1, Math.min(4, rawZoom))
1757
1731
  };
1758
1732
  this.emitChange();
1759
1733
  }
@@ -1767,10 +1741,6 @@ var Editor = class {
1767
1741
  this.viewport = zoomViewport(this.viewport, factor, screenX, screenY);
1768
1742
  this.emitChange();
1769
1743
  }
1770
- rotateAt(delta, screenX, screenY) {
1771
- this.viewport = rotateViewport(this.viewport, delta, screenX, screenY);
1772
- this.emitChange();
1773
- }
1774
1744
  deleteShapes(ids) {
1775
1745
  if (ids.length === 0) return;
1776
1746
  this.store.deleteShapes(ids);
@@ -1793,8 +1763,7 @@ var Editor = class {
1793
1763
  viewport: {
1794
1764
  x: this.viewport.x,
1795
1765
  y: this.viewport.y,
1796
- zoom: this.viewport.zoom,
1797
- rotation: this.viewport.rotation
1766
+ zoom: this.viewport.zoom
1798
1767
  },
1799
1768
  currentToolId: this.getCurrentToolId(),
1800
1769
  drawStyle: this.getCurrentDrawStyle(),
@@ -1802,10 +1771,7 @@ var Editor = class {
1802
1771
  };
1803
1772
  }
1804
1773
  loadSessionStateSnapshot(snapshot) {
1805
- this.setViewport({
1806
- ...snapshot.viewport,
1807
- rotation: snapshot.viewport.rotation ?? 0
1808
- });
1774
+ this.setViewport(snapshot.viewport);
1809
1775
  this.setCurrentDrawStyle({
1810
1776
  color: snapshot.drawStyle.color,
1811
1777
  dash: snapshot.drawStyle.dash,
@@ -2192,6 +2158,6 @@ function applyResize(editor, handle, startBounds, startShapes, pointer, lockAspe
2192
2158
  }
2193
2159
  }
2194
2160
 
2195
- 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
+ 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 };
2196
2162
  //# sourceMappingURL=index.js.map
2197
2163
  //# sourceMappingURL=index.js.map