@leafer-ui/draw 1.9.5 → 1.9.7

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/lib/draw.cjs CHANGED
@@ -366,8 +366,6 @@ class TextData extends UIData {
366
366
  if (!boxStyle) box.parent = t, box.__world = t.__world, boxLayout.boxBounds = layout.boxBounds;
367
367
  box.set(value);
368
368
  if (boxLayout.strokeChanged) layout.strokeChange();
369
- if (boxLayout.renderChanged) layout.renderChange();
370
- box.__updateChange();
371
369
  } else if (box) {
372
370
  t.__box = box.parent = null;
373
371
  box.destroy();
@@ -437,7 +435,7 @@ const UIBounds = {
437
435
  __updateRenderSpread() {
438
436
  let width = 0;
439
437
  const {shadow: shadow, innerShadow: innerShadow, blur: blur, backgroundBlur: backgroundBlur, filter: filter, renderSpread: renderSpread} = this.__;
440
- if (shadow) shadow.forEach(item => width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5));
438
+ if (shadow) width = Effect.getShadowSpread(this, shadow);
441
439
  if (blur) width = Math.max(width, blur);
442
440
  if (filter) width += Filter.getSpread(filter);
443
441
  if (renderSpread) width += renderSpread;
@@ -450,36 +448,69 @@ const UIBounds = {
450
448
  }
451
449
  };
452
450
 
451
+ const {float: float} = core.MathHelper;
452
+
453
+ const tempContent = new core.Bounds, tempMerge = new core.Bounds, tempIntersect = new core.Bounds;
454
+
453
455
  const DragBoundsHelper = {
456
+ limitMove(leaf, move) {
457
+ const {dragBounds: dragBounds, dragBoundsType: dragBoundsType} = leaf;
458
+ if (dragBounds) D.getValidMove(leaf.__localBoxBounds, D.getDragBounds(leaf), dragBoundsType, move, true);
459
+ D.axisMove(leaf, move);
460
+ },
461
+ limitScaleOf(leaf, origin, scale) {
462
+ const {dragBounds: dragBounds, dragBoundsType: dragBoundsType} = leaf;
463
+ if (dragBounds) D.getValidScaleOf(leaf.__localBoxBounds, D.getDragBounds(leaf), dragBoundsType, leaf.getLocalPointByInner(leaf.getInnerPointByBox(origin)), scale, true);
464
+ },
465
+ axisMove(leaf, move) {
466
+ const {draggable: draggable} = leaf;
467
+ if (draggable === "x") move.y = 0;
468
+ if (draggable === "y") move.x = 0;
469
+ },
470
+ getDragBounds(leaf) {
471
+ const {dragBounds: dragBounds} = leaf;
472
+ return dragBounds === "parent" ? leaf.parent.boxBounds : dragBounds;
473
+ },
474
+ isInnerMode(content, dragBounds, dragBoundsType, sideType) {
475
+ return dragBoundsType === "inner" || dragBoundsType === "auto" && content[sideType] > dragBounds[sideType];
476
+ },
454
477
  getValidMove(content, dragBounds, dragBoundsType, move, change) {
455
478
  const x = content.x + move.x, y = content.y + move.y, right = x + content.width, bottom = y + content.height;
456
479
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
457
480
  if (!change) move = Object.assign({}, move);
458
- const isBiggerWidth = content.width > dragBounds.width;
459
- const isBiggerHeight = content.height > dragBounds.height;
460
- if (isBiggerWidth && dragBoundsType !== "outer") {
481
+ if (D.isInnerMode(content, dragBounds, dragBoundsType, "width")) {
461
482
  if (x > dragBounds.x) move.x += dragBounds.x - x; else if (right < boundsRight) move.x += boundsRight - right;
462
483
  } else {
463
484
  if (x < dragBounds.x) move.x += dragBounds.x - x; else if (right > boundsRight) move.x += boundsRight - right;
464
485
  }
465
- if (isBiggerHeight && dragBoundsType !== "outer") {
486
+ if (D.isInnerMode(content, dragBounds, dragBoundsType, "height")) {
466
487
  if (y > dragBounds.y) move.y += dragBounds.y - y; else if (bottom < boundsBottom) move.y += boundsBottom - bottom;
467
488
  } else {
468
489
  if (y < dragBounds.y) move.y += dragBounds.y - y; else if (bottom > boundsBottom) move.y += boundsBottom - bottom;
469
490
  }
470
- move.x = core.MathHelper.float(move.x);
471
- move.y = core.MathHelper.float(move.y);
491
+ move.x = float(move.x);
492
+ move.y = float(move.y);
472
493
  return move;
473
494
  },
474
- axisMove(leaf, move) {
475
- const {draggable: draggable} = leaf;
476
- if (draggable === "x") move.y = 0;
477
- if (draggable === "y") move.x = 0;
478
- },
479
- limitMove(leaf, move) {
480
- const {dragBounds: dragBounds, dragBoundsType: dragBoundsType} = leaf;
481
- if (dragBounds) D.getValidMove(leaf.__localBoxBounds, dragBounds === "parent" ? leaf.parent.boxBounds : dragBounds, dragBoundsType, move, true);
482
- D.axisMove(leaf, move);
495
+ getValidScaleOf(content, dragBounds, dragBoundsType, origin, scale, change) {
496
+ if (!change) scale = Object.assign({}, scale);
497
+ let fitScaleX, fitScaleY;
498
+ tempContent.set(content).scaleOf(origin, scale.x, scale.y).unsign();
499
+ tempMerge.set(tempContent).add(dragBounds);
500
+ tempIntersect.set(tempContent).intersect(dragBounds);
501
+ if (D.isInnerMode(content, dragBounds, dragBoundsType, "width")) {
502
+ fitScaleX = tempMerge.width / tempContent.width;
503
+ } else {
504
+ fitScaleX = tempIntersect.width / tempContent.width;
505
+ }
506
+ if (D.isInnerMode(content, dragBounds, dragBoundsType, "height")) {
507
+ fitScaleY = tempMerge.height / tempContent.height;
508
+ } else {
509
+ fitScaleY = tempIntersect.height / tempContent.height;
510
+ }
511
+ scale.x = float(tempIntersect.width) ? scale.x * fitScaleX : 1;
512
+ scale.y = float(tempIntersect.height) ? scale.y * fitScaleY : 1;
513
+ return scale;
483
514
  }
484
515
  };
485
516
 
@@ -497,7 +528,7 @@ const UIRender = {
497
528
  }
498
529
  if (data.__useEffect) {
499
530
  const {shadow: shadow, fill: fill, stroke: stroke} = data, otherEffect = data.innerShadow || data.blur || data.backgroundBlur || data.filter;
500
- stintSet(data, "__isFastShadow", shadow && !otherEffect && shadow.length < 2 && !shadow[0].spread && fill && !data.__isTransparentFill && !(core.isArray(fill) && fill.length > 1) && (this.useFastShadow || !stroke || stroke && data.strokeAlign === "inside"));
531
+ stintSet(data, "__isFastShadow", shadow && !otherEffect && shadow.length < 2 && !shadow[0].spread && !Effect.isTransformShadow(shadow[0]) && fill && !data.__isTransparentFill && !(core.isArray(fill) && fill.length > 1) && (this.useFastShadow || !stroke || stroke && data.strokeAlign === "inside"));
501
532
  data.__useEffect = !!(shadow || otherEffect);
502
533
  }
503
534
  data.__checkSingle();
@@ -757,9 +788,9 @@ __decorate([ core.visibleType(true) ], exports.UI.prototype, "visible", void 0);
757
788
 
758
789
  __decorate([ core.surfaceType(false) ], exports.UI.prototype, "locked", void 0);
759
790
 
760
- __decorate([ core.surfaceType(false) ], exports.UI.prototype, "dim", void 0);
791
+ __decorate([ core.dimType(false) ], exports.UI.prototype, "dim", void 0);
761
792
 
762
- __decorate([ core.surfaceType(false) ], exports.UI.prototype, "dimskip", void 0);
793
+ __decorate([ core.dimType(false) ], exports.UI.prototype, "dimskip", void 0);
763
794
 
764
795
  __decorate([ core.sortType(0) ], exports.UI.prototype, "zIndex", void 0);
765
796
 
@@ -1135,7 +1166,9 @@ exports.Leafer = Leafer_1 = class Leafer extends exports.Group {
1135
1166
  } else if (attrName === "zIndex") {
1136
1167
  this.canvas.zIndex = newValue;
1137
1168
  setTimeout(() => this.parent && this.parent.__updateSortChildren());
1138
- }
1169
+ } else if (attrName === "mode") this.emit(core.LeaferEvent.UPDATE_MODE, {
1170
+ mode: newValue
1171
+ });
1139
1172
  }
1140
1173
  return super.__setAttr(attrName, newValue);
1141
1174
  }
@@ -1318,6 +1351,8 @@ __decorate([ core.dataProcessor(LeaferData) ], exports.Leafer.prototype, "__", v
1318
1351
 
1319
1352
  __decorate([ core.boundsType() ], exports.Leafer.prototype, "pixelRatio", void 0);
1320
1353
 
1354
+ __decorate([ core.dataType("normal") ], exports.Leafer.prototype, "mode", void 0);
1355
+
1321
1356
  exports.Leafer = Leafer_1 = __decorate([ core.registerUI() ], exports.Leafer);
1322
1357
 
1323
1358
  exports.Rect = class Rect extends exports.UI {
@@ -1510,57 +1545,9 @@ __decorate([ core.pathType(0) ], exports.Ellipse.prototype, "endAngle", void 0);
1510
1545
 
1511
1546
  exports.Ellipse = __decorate([ core.registerUI() ], exports.Ellipse);
1512
1547
 
1513
- const {moveTo: moveTo$2, lineTo: lineTo$2, drawPoints: drawPoints$1} = core.PathCommandDataHelper;
1514
-
1515
- const {rotate: rotate, getAngle: getAngle, getDistance: getDistance, defaultPoint: defaultPoint} = core.PointHelper;
1516
-
1517
- exports.Line = class Line extends exports.UI {
1518
- get __tag() {
1519
- return "Line";
1520
- }
1521
- get toPoint() {
1522
- const {width: width, rotation: rotation} = this.__;
1523
- const to = core.getPointData();
1524
- if (width) to.x = width;
1525
- if (rotation) rotate(to, rotation);
1526
- return to;
1527
- }
1528
- set toPoint(value) {
1529
- this.width = getDistance(defaultPoint, value);
1530
- this.rotation = getAngle(defaultPoint, value);
1531
- if (this.height) this.height = 0;
1532
- }
1533
- __updatePath() {
1534
- const data = this.__;
1535
- const path = data.path = [];
1536
- if (data.points) {
1537
- drawPoints$1(path, data.points, data.curve, data.closed);
1538
- } else {
1539
- moveTo$2(path, 0, 0);
1540
- lineTo$2(path, this.width, 0);
1541
- }
1542
- }
1543
- };
1544
-
1545
- __decorate([ core.dataProcessor(LineData) ], exports.Line.prototype, "__", void 0);
1546
-
1547
- __decorate([ core.affectStrokeBoundsType("center") ], exports.Line.prototype, "strokeAlign", void 0);
1548
-
1549
- __decorate([ core.boundsType(0) ], exports.Line.prototype, "height", void 0);
1550
-
1551
- __decorate([ core.pathType() ], exports.Line.prototype, "points", void 0);
1552
-
1553
- __decorate([ core.pathType(0) ], exports.Line.prototype, "curve", void 0);
1554
-
1555
- __decorate([ core.pathType(false) ], exports.Line.prototype, "closed", void 0);
1556
-
1557
- exports.Line = __decorate([ core.registerUI() ], exports.Line);
1558
-
1559
1548
  const {sin: sin$1, cos: cos$1, PI: PI$1} = Math;
1560
1549
 
1561
- const {moveTo: moveTo$1, lineTo: lineTo$1, closePath: closePath$1, drawPoints: drawPoints} = core.PathCommandDataHelper;
1562
-
1563
- const line = exports.Line.prototype;
1550
+ const {moveTo: moveTo$2, lineTo: lineTo$2, closePath: closePath$1, drawPoints: drawPoints$1} = core.PathCommandDataHelper;
1564
1551
 
1565
1552
  exports.Polygon = class Polygon extends exports.UI {
1566
1553
  get __tag() {
@@ -1570,19 +1557,17 @@ exports.Polygon = class Polygon extends exports.UI {
1570
1557
  const data = this.__;
1571
1558
  const path = data.path = [];
1572
1559
  if (data.points) {
1573
- drawPoints(path, data.points, data.curve, true);
1560
+ drawPoints$1(path, data.points, data.curve, true);
1574
1561
  } else {
1575
1562
  const {width: width, height: height, sides: sides} = data;
1576
1563
  const rx = width / 2, ry = height / 2;
1577
- moveTo$1(path, rx, 0);
1564
+ moveTo$2(path, rx, 0);
1578
1565
  for (let i = 1; i < sides; i++) {
1579
- lineTo$1(path, rx + rx * sin$1(i * 2 * PI$1 / sides), ry - ry * cos$1(i * 2 * PI$1 / sides));
1566
+ lineTo$2(path, rx + rx * sin$1(i * 2 * PI$1 / sides), ry - ry * cos$1(i * 2 * PI$1 / sides));
1580
1567
  }
1581
1568
  closePath$1(path);
1582
1569
  }
1583
1570
  }
1584
- __updateRenderPath() {}
1585
- __updateBoxBounds() {}
1586
1571
  };
1587
1572
 
1588
1573
  __decorate([ core.dataProcessor(PolygonData) ], exports.Polygon.prototype, "__", void 0);
@@ -1593,15 +1578,11 @@ __decorate([ core.pathType() ], exports.Polygon.prototype, "points", void 0);
1593
1578
 
1594
1579
  __decorate([ core.pathType(0) ], exports.Polygon.prototype, "curve", void 0);
1595
1580
 
1596
- __decorate([ core.rewrite(line.__updateRenderPath) ], exports.Polygon.prototype, "__updateRenderPath", null);
1597
-
1598
- __decorate([ core.rewrite(line.__updateBoxBounds) ], exports.Polygon.prototype, "__updateBoxBounds", null);
1599
-
1600
1581
  exports.Polygon = __decorate([ core.rewriteAble(), core.registerUI() ], exports.Polygon);
1601
1582
 
1602
1583
  const {sin: sin, cos: cos, PI: PI} = Math;
1603
1584
 
1604
- const {moveTo: moveTo, lineTo: lineTo, closePath: closePath} = core.PathCommandDataHelper;
1585
+ const {moveTo: moveTo$1, lineTo: lineTo$1, closePath: closePath} = core.PathCommandDataHelper;
1605
1586
 
1606
1587
  exports.Star = class Star extends exports.UI {
1607
1588
  get __tag() {
@@ -1611,9 +1592,9 @@ exports.Star = class Star extends exports.UI {
1611
1592
  const {width: width, height: height, corners: corners, innerRadius: innerRadius} = this.__;
1612
1593
  const rx = width / 2, ry = height / 2;
1613
1594
  const path = this.__.path = [];
1614
- moveTo(path, rx, 0);
1595
+ moveTo$1(path, rx, 0);
1615
1596
  for (let i = 1; i < corners * 2; i++) {
1616
- lineTo(path, rx + (i % 2 === 0 ? rx : rx * innerRadius) * sin(i * PI / corners), ry - (i % 2 === 0 ? ry : ry * innerRadius) * cos(i * PI / corners));
1597
+ lineTo$1(path, rx + (i % 2 === 0 ? rx : rx * innerRadius) * sin(i * PI / corners), ry - (i % 2 === 0 ? ry : ry * innerRadius) * cos(i * PI / corners));
1617
1598
  }
1618
1599
  closePath(path);
1619
1600
  }
@@ -1627,6 +1608,52 @@ __decorate([ core.pathType(.382) ], exports.Star.prototype, "innerRadius", void
1627
1608
 
1628
1609
  exports.Star = __decorate([ core.registerUI() ], exports.Star);
1629
1610
 
1611
+ const {moveTo: moveTo, lineTo: lineTo, drawPoints: drawPoints} = core.PathCommandDataHelper;
1612
+
1613
+ const {rotate: rotate, getAngle: getAngle, getDistance: getDistance, defaultPoint: defaultPoint} = core.PointHelper;
1614
+
1615
+ exports.Line = class Line extends exports.UI {
1616
+ get __tag() {
1617
+ return "Line";
1618
+ }
1619
+ get toPoint() {
1620
+ const {width: width, rotation: rotation} = this.__;
1621
+ const to = core.getPointData();
1622
+ if (width) to.x = width;
1623
+ if (rotation) rotate(to, rotation);
1624
+ return to;
1625
+ }
1626
+ set toPoint(value) {
1627
+ this.width = getDistance(defaultPoint, value);
1628
+ this.rotation = getAngle(defaultPoint, value);
1629
+ if (this.height) this.height = 0;
1630
+ }
1631
+ __updatePath() {
1632
+ const data = this.__;
1633
+ const path = data.path = [];
1634
+ if (data.points) {
1635
+ drawPoints(path, data.points, data.curve, data.closed);
1636
+ } else {
1637
+ moveTo(path, 0, 0);
1638
+ lineTo(path, this.width, 0);
1639
+ }
1640
+ }
1641
+ };
1642
+
1643
+ __decorate([ core.dataProcessor(LineData) ], exports.Line.prototype, "__", void 0);
1644
+
1645
+ __decorate([ core.affectStrokeBoundsType("center") ], exports.Line.prototype, "strokeAlign", void 0);
1646
+
1647
+ __decorate([ core.boundsType(0) ], exports.Line.prototype, "height", void 0);
1648
+
1649
+ __decorate([ core.pathType() ], exports.Line.prototype, "points", void 0);
1650
+
1651
+ __decorate([ core.pathType(0) ], exports.Line.prototype, "curve", void 0);
1652
+
1653
+ __decorate([ core.pathType(false) ], exports.Line.prototype, "closed", void 0);
1654
+
1655
+ exports.Line = __decorate([ core.registerUI() ], exports.Line);
1656
+
1630
1657
  exports.Image = class Image extends exports.Rect {
1631
1658
  get __tag() {
1632
1659
  return "Image";
@@ -1774,10 +1801,6 @@ exports.Text = class Text extends exports.UI {
1774
1801
  core.DataHelper.stintSet(this, "isOverflow", !includes(b, contentBounds));
1775
1802
  if (this.isOverflow) setList(data.__textBoxBounds = {}, [ b, contentBounds ]), layout.renderChanged = true; else data.__textBoxBounds = b;
1776
1803
  }
1777
- __onUpdateSize() {
1778
- if (this.__box) this.__box.__onUpdateSize();
1779
- super.__onUpdateSize();
1780
- }
1781
1804
  __updateRenderSpread() {
1782
1805
  let width = super.__updateRenderSpread();
1783
1806
  if (!width) width = this.isOverflow ? 1 : 0;
@@ -1788,6 +1811,11 @@ exports.Text = class Text extends exports.UI {
1788
1811
  copyAndSpread(renderBounds, this.__.__textBoxBounds, renderSpread);
1789
1812
  if (this.__box) this.__box.__layout.renderBounds = renderBounds;
1790
1813
  }
1814
+ __updateChange() {
1815
+ super.__updateChange();
1816
+ const box = this.__box;
1817
+ if (box) box.__onUpdateSize(), box.__updateChange();
1818
+ }
1791
1819
  __drawRenderPath(canvas) {
1792
1820
  canvas.font = this.__.__font;
1793
1821
  }
package/lib/draw.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineKey, decorateLeafAttr, attr, createDescriptor, Plugin, isObject, PathConvert, DataHelper, Debug, LeafData, isString, isUndefined, isArray, canvasSizeAttrs, UICreator, MathHelper, dataProcessor, dataType, surfaceType, opacityType, visibleType, sortType, maskType, eraserType, positionType, boundsType, scaleType, rotationType, scrollType, autoLayoutType, naturalBoundsType, affectRenderBoundsType, pathInputType, pathType, hitType, strokeType, cursorType, rewrite, Leaf, useModule, rewriteAble, pen, PathCorner, PathDrawer, isNumber, registerUI, Branch, LeafList, Resource, getBoundsData, Creator, CanvasManager, WaitHelper, LeaferEvent, Bounds, ResizeEvent, AutoBounds, Run, LayoutEvent, RenderEvent, WatchEvent, ImageManager, BoundsHelper, PathCommandDataHelper, Platform, PointHelper, affectStrokeBoundsType, getPointData, LeaferImage, ImageEvent, Matrix, PathCreator } from "@leafer/core";
1
+ import { defineKey, decorateLeafAttr, attr, createDescriptor, Plugin, isObject, PathConvert, DataHelper, Debug, LeafData, isString, isUndefined, isArray, canvasSizeAttrs, UICreator, MathHelper, Bounds, dataProcessor, dataType, surfaceType, opacityType, visibleType, dimType, sortType, maskType, eraserType, positionType, boundsType, scaleType, rotationType, scrollType, autoLayoutType, naturalBoundsType, affectRenderBoundsType, pathInputType, pathType, hitType, strokeType, cursorType, rewrite, Leaf, useModule, rewriteAble, pen, PathCorner, PathDrawer, isNumber, registerUI, Branch, LeafList, Resource, getBoundsData, Creator, CanvasManager, WaitHelper, LeaferEvent, ResizeEvent, AutoBounds, Run, LayoutEvent, RenderEvent, WatchEvent, ImageManager, BoundsHelper, PathCommandDataHelper, Platform, PointHelper, affectStrokeBoundsType, getPointData, LeaferImage, ImageEvent, Matrix, PathCreator } from "@leafer/core";
2
2
 
3
3
  export * from "@leafer/core";
4
4
 
@@ -366,8 +366,6 @@ class TextData extends UIData {
366
366
  if (!boxStyle) box.parent = t, box.__world = t.__world, boxLayout.boxBounds = layout.boxBounds;
367
367
  box.set(value);
368
368
  if (boxLayout.strokeChanged) layout.strokeChange();
369
- if (boxLayout.renderChanged) layout.renderChange();
370
- box.__updateChange();
371
369
  } else if (box) {
372
370
  t.__box = box.parent = null;
373
371
  box.destroy();
@@ -437,7 +435,7 @@ const UIBounds = {
437
435
  __updateRenderSpread() {
438
436
  let width = 0;
439
437
  const {shadow: shadow, innerShadow: innerShadow, blur: blur, backgroundBlur: backgroundBlur, filter: filter, renderSpread: renderSpread} = this.__;
440
- if (shadow) shadow.forEach(item => width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5));
438
+ if (shadow) width = Effect.getShadowSpread(this, shadow);
441
439
  if (blur) width = Math.max(width, blur);
442
440
  if (filter) width += Filter.getSpread(filter);
443
441
  if (renderSpread) width += renderSpread;
@@ -450,36 +448,69 @@ const UIBounds = {
450
448
  }
451
449
  };
452
450
 
451
+ const {float: float} = MathHelper;
452
+
453
+ const tempContent = new Bounds, tempMerge = new Bounds, tempIntersect = new Bounds;
454
+
453
455
  const DragBoundsHelper = {
456
+ limitMove(leaf, move) {
457
+ const {dragBounds: dragBounds, dragBoundsType: dragBoundsType} = leaf;
458
+ if (dragBounds) D.getValidMove(leaf.__localBoxBounds, D.getDragBounds(leaf), dragBoundsType, move, true);
459
+ D.axisMove(leaf, move);
460
+ },
461
+ limitScaleOf(leaf, origin, scale) {
462
+ const {dragBounds: dragBounds, dragBoundsType: dragBoundsType} = leaf;
463
+ if (dragBounds) D.getValidScaleOf(leaf.__localBoxBounds, D.getDragBounds(leaf), dragBoundsType, leaf.getLocalPointByInner(leaf.getInnerPointByBox(origin)), scale, true);
464
+ },
465
+ axisMove(leaf, move) {
466
+ const {draggable: draggable} = leaf;
467
+ if (draggable === "x") move.y = 0;
468
+ if (draggable === "y") move.x = 0;
469
+ },
470
+ getDragBounds(leaf) {
471
+ const {dragBounds: dragBounds} = leaf;
472
+ return dragBounds === "parent" ? leaf.parent.boxBounds : dragBounds;
473
+ },
474
+ isInnerMode(content, dragBounds, dragBoundsType, sideType) {
475
+ return dragBoundsType === "inner" || dragBoundsType === "auto" && content[sideType] > dragBounds[sideType];
476
+ },
454
477
  getValidMove(content, dragBounds, dragBoundsType, move, change) {
455
478
  const x = content.x + move.x, y = content.y + move.y, right = x + content.width, bottom = y + content.height;
456
479
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
457
480
  if (!change) move = Object.assign({}, move);
458
- const isBiggerWidth = content.width > dragBounds.width;
459
- const isBiggerHeight = content.height > dragBounds.height;
460
- if (isBiggerWidth && dragBoundsType !== "outer") {
481
+ if (D.isInnerMode(content, dragBounds, dragBoundsType, "width")) {
461
482
  if (x > dragBounds.x) move.x += dragBounds.x - x; else if (right < boundsRight) move.x += boundsRight - right;
462
483
  } else {
463
484
  if (x < dragBounds.x) move.x += dragBounds.x - x; else if (right > boundsRight) move.x += boundsRight - right;
464
485
  }
465
- if (isBiggerHeight && dragBoundsType !== "outer") {
486
+ if (D.isInnerMode(content, dragBounds, dragBoundsType, "height")) {
466
487
  if (y > dragBounds.y) move.y += dragBounds.y - y; else if (bottom < boundsBottom) move.y += boundsBottom - bottom;
467
488
  } else {
468
489
  if (y < dragBounds.y) move.y += dragBounds.y - y; else if (bottom > boundsBottom) move.y += boundsBottom - bottom;
469
490
  }
470
- move.x = MathHelper.float(move.x);
471
- move.y = MathHelper.float(move.y);
491
+ move.x = float(move.x);
492
+ move.y = float(move.y);
472
493
  return move;
473
494
  },
474
- axisMove(leaf, move) {
475
- const {draggable: draggable} = leaf;
476
- if (draggable === "x") move.y = 0;
477
- if (draggable === "y") move.x = 0;
478
- },
479
- limitMove(leaf, move) {
480
- const {dragBounds: dragBounds, dragBoundsType: dragBoundsType} = leaf;
481
- if (dragBounds) D.getValidMove(leaf.__localBoxBounds, dragBounds === "parent" ? leaf.parent.boxBounds : dragBounds, dragBoundsType, move, true);
482
- D.axisMove(leaf, move);
495
+ getValidScaleOf(content, dragBounds, dragBoundsType, origin, scale, change) {
496
+ if (!change) scale = Object.assign({}, scale);
497
+ let fitScaleX, fitScaleY;
498
+ tempContent.set(content).scaleOf(origin, scale.x, scale.y).unsign();
499
+ tempMerge.set(tempContent).add(dragBounds);
500
+ tempIntersect.set(tempContent).intersect(dragBounds);
501
+ if (D.isInnerMode(content, dragBounds, dragBoundsType, "width")) {
502
+ fitScaleX = tempMerge.width / tempContent.width;
503
+ } else {
504
+ fitScaleX = tempIntersect.width / tempContent.width;
505
+ }
506
+ if (D.isInnerMode(content, dragBounds, dragBoundsType, "height")) {
507
+ fitScaleY = tempMerge.height / tempContent.height;
508
+ } else {
509
+ fitScaleY = tempIntersect.height / tempContent.height;
510
+ }
511
+ scale.x = float(tempIntersect.width) ? scale.x * fitScaleX : 1;
512
+ scale.y = float(tempIntersect.height) ? scale.y * fitScaleY : 1;
513
+ return scale;
483
514
  }
484
515
  };
485
516
 
@@ -497,7 +528,7 @@ const UIRender = {
497
528
  }
498
529
  if (data.__useEffect) {
499
530
  const {shadow: shadow, fill: fill, stroke: stroke} = data, otherEffect = data.innerShadow || data.blur || data.backgroundBlur || data.filter;
500
- stintSet(data, "__isFastShadow", shadow && !otherEffect && shadow.length < 2 && !shadow[0].spread && fill && !data.__isTransparentFill && !(isArray(fill) && fill.length > 1) && (this.useFastShadow || !stroke || stroke && data.strokeAlign === "inside"));
531
+ stintSet(data, "__isFastShadow", shadow && !otherEffect && shadow.length < 2 && !shadow[0].spread && !Effect.isTransformShadow(shadow[0]) && fill && !data.__isTransparentFill && !(isArray(fill) && fill.length > 1) && (this.useFastShadow || !stroke || stroke && data.strokeAlign === "inside"));
501
532
  data.__useEffect = !!(shadow || otherEffect);
502
533
  }
503
534
  data.__checkSingle();
@@ -757,9 +788,9 @@ __decorate([ visibleType(true) ], UI.prototype, "visible", void 0);
757
788
 
758
789
  __decorate([ surfaceType(false) ], UI.prototype, "locked", void 0);
759
790
 
760
- __decorate([ surfaceType(false) ], UI.prototype, "dim", void 0);
791
+ __decorate([ dimType(false) ], UI.prototype, "dim", void 0);
761
792
 
762
- __decorate([ surfaceType(false) ], UI.prototype, "dimskip", void 0);
793
+ __decorate([ dimType(false) ], UI.prototype, "dimskip", void 0);
763
794
 
764
795
  __decorate([ sortType(0) ], UI.prototype, "zIndex", void 0);
765
796
 
@@ -1135,7 +1166,9 @@ let Leafer = Leafer_1 = class Leafer extends Group {
1135
1166
  } else if (attrName === "zIndex") {
1136
1167
  this.canvas.zIndex = newValue;
1137
1168
  setTimeout(() => this.parent && this.parent.__updateSortChildren());
1138
- }
1169
+ } else if (attrName === "mode") this.emit(LeaferEvent.UPDATE_MODE, {
1170
+ mode: newValue
1171
+ });
1139
1172
  }
1140
1173
  return super.__setAttr(attrName, newValue);
1141
1174
  }
@@ -1318,6 +1351,8 @@ __decorate([ dataProcessor(LeaferData) ], Leafer.prototype, "__", void 0);
1318
1351
 
1319
1352
  __decorate([ boundsType() ], Leafer.prototype, "pixelRatio", void 0);
1320
1353
 
1354
+ __decorate([ dataType("normal") ], Leafer.prototype, "mode", void 0);
1355
+
1321
1356
  Leafer = Leafer_1 = __decorate([ registerUI() ], Leafer);
1322
1357
 
1323
1358
  let Rect = class Rect extends UI {
@@ -1510,57 +1545,9 @@ __decorate([ pathType(0) ], Ellipse.prototype, "endAngle", void 0);
1510
1545
 
1511
1546
  Ellipse = __decorate([ registerUI() ], Ellipse);
1512
1547
 
1513
- const {moveTo: moveTo$2, lineTo: lineTo$2, drawPoints: drawPoints$1} = PathCommandDataHelper;
1514
-
1515
- const {rotate: rotate, getAngle: getAngle, getDistance: getDistance, defaultPoint: defaultPoint} = PointHelper;
1516
-
1517
- let Line = class Line extends UI {
1518
- get __tag() {
1519
- return "Line";
1520
- }
1521
- get toPoint() {
1522
- const {width: width, rotation: rotation} = this.__;
1523
- const to = getPointData();
1524
- if (width) to.x = width;
1525
- if (rotation) rotate(to, rotation);
1526
- return to;
1527
- }
1528
- set toPoint(value) {
1529
- this.width = getDistance(defaultPoint, value);
1530
- this.rotation = getAngle(defaultPoint, value);
1531
- if (this.height) this.height = 0;
1532
- }
1533
- __updatePath() {
1534
- const data = this.__;
1535
- const path = data.path = [];
1536
- if (data.points) {
1537
- drawPoints$1(path, data.points, data.curve, data.closed);
1538
- } else {
1539
- moveTo$2(path, 0, 0);
1540
- lineTo$2(path, this.width, 0);
1541
- }
1542
- }
1543
- };
1544
-
1545
- __decorate([ dataProcessor(LineData) ], Line.prototype, "__", void 0);
1546
-
1547
- __decorate([ affectStrokeBoundsType("center") ], Line.prototype, "strokeAlign", void 0);
1548
-
1549
- __decorate([ boundsType(0) ], Line.prototype, "height", void 0);
1550
-
1551
- __decorate([ pathType() ], Line.prototype, "points", void 0);
1552
-
1553
- __decorate([ pathType(0) ], Line.prototype, "curve", void 0);
1554
-
1555
- __decorate([ pathType(false) ], Line.prototype, "closed", void 0);
1556
-
1557
- Line = __decorate([ registerUI() ], Line);
1558
-
1559
1548
  const {sin: sin$1, cos: cos$1, PI: PI$1} = Math;
1560
1549
 
1561
- const {moveTo: moveTo$1, lineTo: lineTo$1, closePath: closePath$1, drawPoints: drawPoints} = PathCommandDataHelper;
1562
-
1563
- const line = Line.prototype;
1550
+ const {moveTo: moveTo$2, lineTo: lineTo$2, closePath: closePath$1, drawPoints: drawPoints$1} = PathCommandDataHelper;
1564
1551
 
1565
1552
  let Polygon = class Polygon extends UI {
1566
1553
  get __tag() {
@@ -1570,19 +1557,17 @@ let Polygon = class Polygon extends UI {
1570
1557
  const data = this.__;
1571
1558
  const path = data.path = [];
1572
1559
  if (data.points) {
1573
- drawPoints(path, data.points, data.curve, true);
1560
+ drawPoints$1(path, data.points, data.curve, true);
1574
1561
  } else {
1575
1562
  const {width: width, height: height, sides: sides} = data;
1576
1563
  const rx = width / 2, ry = height / 2;
1577
- moveTo$1(path, rx, 0);
1564
+ moveTo$2(path, rx, 0);
1578
1565
  for (let i = 1; i < sides; i++) {
1579
- lineTo$1(path, rx + rx * sin$1(i * 2 * PI$1 / sides), ry - ry * cos$1(i * 2 * PI$1 / sides));
1566
+ lineTo$2(path, rx + rx * sin$1(i * 2 * PI$1 / sides), ry - ry * cos$1(i * 2 * PI$1 / sides));
1580
1567
  }
1581
1568
  closePath$1(path);
1582
1569
  }
1583
1570
  }
1584
- __updateRenderPath() {}
1585
- __updateBoxBounds() {}
1586
1571
  };
1587
1572
 
1588
1573
  __decorate([ dataProcessor(PolygonData) ], Polygon.prototype, "__", void 0);
@@ -1593,15 +1578,11 @@ __decorate([ pathType() ], Polygon.prototype, "points", void 0);
1593
1578
 
1594
1579
  __decorate([ pathType(0) ], Polygon.prototype, "curve", void 0);
1595
1580
 
1596
- __decorate([ rewrite(line.__updateRenderPath) ], Polygon.prototype, "__updateRenderPath", null);
1597
-
1598
- __decorate([ rewrite(line.__updateBoxBounds) ], Polygon.prototype, "__updateBoxBounds", null);
1599
-
1600
1581
  Polygon = __decorate([ rewriteAble(), registerUI() ], Polygon);
1601
1582
 
1602
1583
  const {sin: sin, cos: cos, PI: PI} = Math;
1603
1584
 
1604
- const {moveTo: moveTo, lineTo: lineTo, closePath: closePath} = PathCommandDataHelper;
1585
+ const {moveTo: moveTo$1, lineTo: lineTo$1, closePath: closePath} = PathCommandDataHelper;
1605
1586
 
1606
1587
  let Star = class Star extends UI {
1607
1588
  get __tag() {
@@ -1611,9 +1592,9 @@ let Star = class Star extends UI {
1611
1592
  const {width: width, height: height, corners: corners, innerRadius: innerRadius} = this.__;
1612
1593
  const rx = width / 2, ry = height / 2;
1613
1594
  const path = this.__.path = [];
1614
- moveTo(path, rx, 0);
1595
+ moveTo$1(path, rx, 0);
1615
1596
  for (let i = 1; i < corners * 2; i++) {
1616
- lineTo(path, rx + (i % 2 === 0 ? rx : rx * innerRadius) * sin(i * PI / corners), ry - (i % 2 === 0 ? ry : ry * innerRadius) * cos(i * PI / corners));
1597
+ lineTo$1(path, rx + (i % 2 === 0 ? rx : rx * innerRadius) * sin(i * PI / corners), ry - (i % 2 === 0 ? ry : ry * innerRadius) * cos(i * PI / corners));
1617
1598
  }
1618
1599
  closePath(path);
1619
1600
  }
@@ -1627,6 +1608,52 @@ __decorate([ pathType(.382) ], Star.prototype, "innerRadius", void 0);
1627
1608
 
1628
1609
  Star = __decorate([ registerUI() ], Star);
1629
1610
 
1611
+ const {moveTo: moveTo, lineTo: lineTo, drawPoints: drawPoints} = PathCommandDataHelper;
1612
+
1613
+ const {rotate: rotate, getAngle: getAngle, getDistance: getDistance, defaultPoint: defaultPoint} = PointHelper;
1614
+
1615
+ let Line = class Line extends UI {
1616
+ get __tag() {
1617
+ return "Line";
1618
+ }
1619
+ get toPoint() {
1620
+ const {width: width, rotation: rotation} = this.__;
1621
+ const to = getPointData();
1622
+ if (width) to.x = width;
1623
+ if (rotation) rotate(to, rotation);
1624
+ return to;
1625
+ }
1626
+ set toPoint(value) {
1627
+ this.width = getDistance(defaultPoint, value);
1628
+ this.rotation = getAngle(defaultPoint, value);
1629
+ if (this.height) this.height = 0;
1630
+ }
1631
+ __updatePath() {
1632
+ const data = this.__;
1633
+ const path = data.path = [];
1634
+ if (data.points) {
1635
+ drawPoints(path, data.points, data.curve, data.closed);
1636
+ } else {
1637
+ moveTo(path, 0, 0);
1638
+ lineTo(path, this.width, 0);
1639
+ }
1640
+ }
1641
+ };
1642
+
1643
+ __decorate([ dataProcessor(LineData) ], Line.prototype, "__", void 0);
1644
+
1645
+ __decorate([ affectStrokeBoundsType("center") ], Line.prototype, "strokeAlign", void 0);
1646
+
1647
+ __decorate([ boundsType(0) ], Line.prototype, "height", void 0);
1648
+
1649
+ __decorate([ pathType() ], Line.prototype, "points", void 0);
1650
+
1651
+ __decorate([ pathType(0) ], Line.prototype, "curve", void 0);
1652
+
1653
+ __decorate([ pathType(false) ], Line.prototype, "closed", void 0);
1654
+
1655
+ Line = __decorate([ registerUI() ], Line);
1656
+
1630
1657
  let Image = class Image extends Rect {
1631
1658
  get __tag() {
1632
1659
  return "Image";
@@ -1774,10 +1801,6 @@ let Text = class Text extends UI {
1774
1801
  DataHelper.stintSet(this, "isOverflow", !includes(b, contentBounds));
1775
1802
  if (this.isOverflow) setList(data.__textBoxBounds = {}, [ b, contentBounds ]), layout.renderChanged = true; else data.__textBoxBounds = b;
1776
1803
  }
1777
- __onUpdateSize() {
1778
- if (this.__box) this.__box.__onUpdateSize();
1779
- super.__onUpdateSize();
1780
- }
1781
1804
  __updateRenderSpread() {
1782
1805
  let width = super.__updateRenderSpread();
1783
1806
  if (!width) width = this.isOverflow ? 1 : 0;
@@ -1788,6 +1811,11 @@ let Text = class Text extends UI {
1788
1811
  copyAndSpread(renderBounds, this.__.__textBoxBounds, renderSpread);
1789
1812
  if (this.__box) this.__box.__layout.renderBounds = renderBounds;
1790
1813
  }
1814
+ __updateChange() {
1815
+ super.__updateChange();
1816
+ const box = this.__box;
1817
+ if (box) box.__onUpdateSize(), box.__updateChange();
1818
+ }
1791
1819
  __drawRenderPath(canvas) {
1792
1820
  canvas.font = this.__.__font;
1793
1821
  }