@tsdraw/core 0.6.0 → 0.6.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
@@ -150,6 +150,12 @@ var DocumentStore = class {
150
150
  loadSnapshot(snapshot) {
151
151
  const pageState = cloneValue(snapshot.page);
152
152
  const normalizedOrder = [...snapshot.order].filter((shapeId) => pageState.shapes[shapeId] != null);
153
+ const orderedSet = new Set(normalizedOrder);
154
+ for (const shapeId of Object.keys(pageState.shapes)) {
155
+ if (!orderedSet.has(shapeId)) {
156
+ normalizedOrder.push(shapeId);
157
+ }
158
+ }
153
159
  this.state = {
154
160
  id: pageState.id,
155
161
  shapes: pageState.shapes,
@@ -865,13 +871,14 @@ var PenDrawingState = class extends StateNode {
865
871
  type: "straight",
866
872
  path: encodePoints([prevEnd, { ...anchorPt, z: pressure }])
867
873
  };
874
+ const withStraightSeg = [...segments, seg];
868
875
  this.editor.updateShapes([
869
876
  {
870
877
  id,
871
878
  type: "draw",
872
879
  props: {
873
- segments: [...segments, seg],
874
- isClosed: this.detectClosure(segments, size, scale)
880
+ segments: withStraightSeg,
881
+ isClosed: this.detectClosure(withStraightSeg, size, scale)
875
882
  }
876
883
  }
877
884
  ]);
@@ -947,7 +954,7 @@ var PenDrawingState = class extends StateNode {
947
954
  type: "draw",
948
955
  props: {
949
956
  segments: updated,
950
- isClosed: this.detectClosure(segments, size, scale)
957
+ isClosed: this.detectClosure(updated, size, scale)
951
958
  }
952
959
  }
953
960
  ]);
@@ -1463,10 +1470,11 @@ var Editor = class {
1463
1470
  this.emitChange();
1464
1471
  }
1465
1472
  setViewport(partial) {
1473
+ const rawZoom = partial.zoom ?? this.viewport.zoom;
1466
1474
  this.viewport = {
1467
1475
  x: partial.x ?? this.viewport.x,
1468
1476
  y: partial.y ?? this.viewport.y,
1469
- zoom: partial.zoom ?? this.viewport.zoom
1477
+ zoom: Math.max(0.1, Math.min(4, rawZoom))
1470
1478
  };
1471
1479
  this.emitChange();
1472
1480
  }