@leafer-in/editor 1.4.0 → 1.4.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/editor.cjs CHANGED
@@ -162,7 +162,7 @@ class Stroker extends draw.UI {
162
162
  }
163
163
  __decorate([
164
164
  targetAttr(onTarget$1)
165
- ], Stroker.prototype, "target", undefined);
165
+ ], Stroker.prototype, "target", void 0);
166
166
  function onTarget$1(stroker) {
167
167
  const value = stroker.target;
168
168
  stroker.list = value ? (value instanceof Array ? value : [value]) : [];
@@ -441,7 +441,7 @@ const { within } = draw.MathHelper;
441
441
  const EditDataHelper = {
442
442
  getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
443
443
  let align, origin = {}, scaleX = 1, scaleY = 1;
444
- const { boxBounds, widthRange, heightRange } = element;
444
+ const { boxBounds, widthRange, heightRange, dragBounds } = element;
445
445
  const { width, height } = startBounds;
446
446
  if (around) {
447
447
  totalMove.x *= 2;
@@ -529,6 +529,17 @@ const EditDataHelper = {
529
529
  if (scaleY < 0)
530
530
  scaleY = 1 / boxBounds.height / worldTransform.scaleY;
531
531
  }
532
+ toPoint(around || align, boxBounds, origin, true);
533
+ if (dragBounds) {
534
+ const allowBounds = dragBounds === 'parent' ? element.parent.boxBounds : dragBounds;
535
+ const localBounds = new draw.Bounds(element.__localBoxBounds);
536
+ localBounds.scaleOf(element.getLocalPointByInner(origin), scaleX, scaleY);
537
+ if (!draw.BoundsHelper.includes(allowBounds, localBounds)) {
538
+ const realBounds = localBounds.getIntersect(allowBounds);
539
+ scaleX *= realBounds.width / localBounds.width;
540
+ scaleY *= realBounds.height / localBounds.height;
541
+ }
542
+ }
532
543
  if (widthRange) {
533
544
  const nowWidth = boxBounds.width * element.scaleX;
534
545
  scaleX = within(nowWidth * scaleX, widthRange) / nowWidth;
@@ -537,7 +548,6 @@ const EditDataHelper = {
537
548
  const nowHeight = boxBounds.height * element.scaleY;
538
549
  scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
539
550
  }
540
- toPoint(around || align, boxBounds, origin, true);
541
551
  return { origin, scaleX, scaleY, direction, lockRatio, around };
542
552
  },
543
553
  getRotateData(bounds, direction, current, last, around) {
@@ -1084,7 +1094,14 @@ const bounds = new draw.Bounds();
1084
1094
  function simulate(editor) {
1085
1095
  const { simulateTarget, list } = editor;
1086
1096
  const { zoomLayer } = list[0].leafer.zoomLayer;
1087
- simulateTarget.safeChange(() => simulateTarget.reset(bounds.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page')).get()));
1097
+ simulateTarget.safeChange(() => {
1098
+ bounds.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page'));
1099
+ if (bounds.width === 0)
1100
+ bounds.width = 0.1;
1101
+ if (bounds.height === 0)
1102
+ bounds.height = 0.1;
1103
+ simulateTarget.reset(bounds.get());
1104
+ });
1088
1105
  zoomLayer.add(simulateTarget);
1089
1106
  }
1090
1107
 
@@ -1441,9 +1458,9 @@ class Editor extends draw.Group {
1441
1458
  this.skewOf(origin, skewX, skewY);
1442
1459
  }
1443
1460
  move(x, y = 0) {
1461
+ const { element } = this;
1444
1462
  if (!this.checkTransform('moveable'))
1445
1463
  return;
1446
- const { element } = this;
1447
1464
  const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
1448
1465
  if (this.multiple)
1449
1466
  element.safeChange(() => element.move(x, y));
@@ -1651,10 +1668,10 @@ class Editor extends draw.Group {
1651
1668
  }
1652
1669
  __decorate([
1653
1670
  targetAttr(onHover)
1654
- ], Editor.prototype, "hoverTarget", undefined);
1671
+ ], Editor.prototype, "hoverTarget", void 0);
1655
1672
  __decorate([
1656
1673
  targetAttr(onTarget)
1657
- ], Editor.prototype, "target", undefined);
1674
+ ], Editor.prototype, "target", void 0);
1658
1675
 
1659
1676
  class InnerEditor {
1660
1677
  static registerInnerEditor() {