@leafer-ui/core 1.0.0-rc.6 → 1.0.0-rc.8

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/core.cjs CHANGED
@@ -40,7 +40,7 @@ function design(leafer) {
40
40
  if (leafer.isApp)
41
41
  return;
42
42
  leafer.__eventIds.push(leafer.on_(core.MoveEvent.BEFORE_MOVE, (e) => { core.LeafHelper.moveWorld(leafer.zoomLayer, e.moveX, e.moveY); }), leafer.on_(core.ZoomEvent.BEFORE_ZOOM, (e) => {
43
- const { scaleX } = leafer.zoomLayer.__, { min, max } = leafer.config.zoom;
43
+ const { scaleX } = leafer.zoomLayer.__, { min, max } = leafer.app.config.zoom;
44
44
  let { scale } = e;
45
45
  if (scale * Math.abs(scaleX) < min)
46
46
  scale = min / scaleX;
@@ -87,6 +87,9 @@ const Export = {};
87
87
  const emptyPaint = {};
88
88
  const debug$1 = core.Debug.get('UIData');
89
89
  class UIData extends core.LeafData {
90
+ get __autoWidth() { return !this._width; }
91
+ get __autoHeight() { return !this._height; }
92
+ get __autoBounds() { return !this._width && !this._height; }
90
93
  setVisible(value) {
91
94
  if (this.__leaf.leafer)
92
95
  this.__leaf.leafer.watcher.hasVisible = true;
@@ -263,6 +266,9 @@ class TextData extends UIData {
263
266
  class ImageData extends RectData {
264
267
  }
265
268
 
269
+ class CanvasData extends RectData {
270
+ }
271
+
266
272
  function effectType(defaultValue) {
267
273
  return (target, key) => {
268
274
  core.defineLeafAttr(target, key, defaultValue, {
@@ -473,6 +479,7 @@ const RectRender = {
473
479
 
474
480
  var UI_1;
475
481
  exports.UI = UI_1 = class UI extends core.Leaf {
482
+ get app() { return this.leafer && this.leafer.app; }
476
483
  set scale(value) {
477
484
  if (typeof value === 'number') {
478
485
  this.scaleX = this.scaleY = value;
@@ -486,22 +493,25 @@ exports.UI = UI_1 = class UI extends core.Leaf {
486
493
  const { scaleX, scaleY } = this;
487
494
  return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX;
488
495
  }
496
+ constructor(data) {
497
+ super(data);
498
+ }
489
499
  reset(_data) { }
490
500
  set(data) {
491
501
  Object.assign(this, data);
492
502
  }
493
- get(options) {
494
- return this.__.__getInputData(options);
503
+ get() {
504
+ return this.__.__getInputData();
495
505
  }
496
- getProxyData() { return undefined; }
497
- find(condition) {
498
- return this.leafer ? this.leafer.selector.getBy(condition, this) : [];
506
+ createProxyData() { return undefined; }
507
+ find(condition, options) {
508
+ return this.leafer ? this.leafer.selector.getBy(condition, this, false, options) : [];
499
509
  }
500
- findOne(condition) {
501
- return this.leafer ? this.leafer.selector.getBy(condition, this, true) : null;
510
+ findOne(condition, options) {
511
+ return this.leafer ? this.leafer.selector.getBy(condition, this, true, options) : null;
502
512
  }
503
513
  getPath(curve) {
504
- const path = this.__.path;
514
+ const { path } = this.__;
505
515
  if (!path)
506
516
  return [];
507
517
  return curve ? core.PathConvert.toCanvasData(path, true) : path;
@@ -533,6 +543,15 @@ exports.UI = UI_1 = class UI extends core.Leaf {
533
543
  this.__drawPathByData(canvas, this.__.path);
534
544
  }
535
545
  __drawPathByData(_drawer, _data) { }
546
+ __drawPathByBox(drawer) {
547
+ const { x, y, width, height } = this.__layout.boxBounds;
548
+ if (this.__.cornerRadius) {
549
+ drawer.roundRect(x, y, width, height, this.__.cornerRadius);
550
+ }
551
+ else {
552
+ drawer.rect(x, y, width, height);
553
+ }
554
+ }
536
555
  export(filename, options) {
537
556
  return Export.export(this, filename, options);
538
557
  }
@@ -574,12 +593,12 @@ __decorate([
574
593
  __decorate([
575
594
  core.eraserType(false)
576
595
  ], exports.UI.prototype, "isEraser", void 0);
596
+ __decorate([
597
+ core.dataType(false)
598
+ ], exports.UI.prototype, "locked", void 0);
577
599
  __decorate([
578
600
  core.sortType(0)
579
601
  ], exports.UI.prototype, "zIndex", void 0);
580
- __decorate([
581
- core.dataType()
582
- ], exports.UI.prototype, "locked", void 0);
583
602
  __decorate([
584
603
  core.positionType(0)
585
604
  ], exports.UI.prototype, "x", void 0);
@@ -608,11 +627,17 @@ __decorate([
608
627
  core.rotationType(0)
609
628
  ], exports.UI.prototype, "skewY", void 0);
610
629
  __decorate([
611
- core.positionType()
630
+ core.autoLayoutType()
612
631
  ], exports.UI.prototype, "around", void 0);
613
632
  __decorate([
614
633
  core.dataType(false)
615
634
  ], exports.UI.prototype, "draggable", void 0);
635
+ __decorate([
636
+ core.dataType(false)
637
+ ], exports.UI.prototype, "editable", void 0);
638
+ __decorate([
639
+ core.dataType('size')
640
+ ], exports.UI.prototype, "editSize", void 0);
616
641
  __decorate([
617
642
  core.hitType(true)
618
643
  ], exports.UI.prototype, "hittable", void 0);
@@ -665,7 +690,7 @@ __decorate([
665
690
  core.strokeType(10)
666
691
  ], exports.UI.prototype, "miterLimit", void 0);
667
692
  __decorate([
668
- core.pathType()
693
+ core.pathType(0)
669
694
  ], exports.UI.prototype, "cornerRadius", void 0);
670
695
  __decorate([
671
696
  core.pathType()
@@ -698,9 +723,9 @@ exports.UI = UI_1 = __decorate([
698
723
  core.rewriteAble()
699
724
  ], exports.UI);
700
725
 
726
+ const matrix = core.MatrixHelper.get();
701
727
  exports.Group = class Group extends exports.UI {
702
728
  get __tag() { return 'Group'; }
703
- get resizeable() { return false; }
704
729
  set mask(child) {
705
730
  if (this.__hasMask)
706
731
  this.__removeMask();
@@ -748,6 +773,14 @@ exports.Group = class Group extends exports.UI {
748
773
  data.children = this.children.map(child => child.toJSON());
749
774
  return data;
750
775
  }
776
+ __scaleResize(scaleX, scaleY) {
777
+ const { children } = this;
778
+ for (let i = 0; i < children.length; i++) {
779
+ matrix.a = scaleX;
780
+ matrix.d = scaleY;
781
+ children[i].transform(matrix, true);
782
+ }
783
+ }
751
784
  addAt(child, index) {
752
785
  this.add(child, index);
753
786
  }
@@ -775,21 +808,17 @@ exports.Rect = class Rect extends exports.UI {
775
808
  constructor(data) {
776
809
  super(data);
777
810
  }
778
- __drawPathByData(drawer, _data) {
779
- const { width, height, cornerRadius } = this.__;
780
- if (cornerRadius) {
781
- drawer.roundRect(0, 0, width, height, cornerRadius);
782
- }
783
- else {
784
- drawer.rect(0, 0, width, height);
785
- }
786
- }
811
+ __drawPathByData(_drawer, _data) { }
787
812
  };
788
813
  __decorate([
789
814
  core.dataProcessor(RectData)
790
815
  ], exports.Rect.prototype, "__", void 0);
816
+ __decorate([
817
+ core.rewrite(exports.UI.prototype.__drawPathByBox)
818
+ ], exports.Rect.prototype, "__drawPathByData", null);
791
819
  exports.Rect = __decorate([
792
820
  core.useModule(RectRender),
821
+ core.rewriteAble(),
793
822
  core.registerUI()
794
823
  ], exports.Rect);
795
824
 
@@ -799,12 +828,20 @@ const bounds = {};
799
828
  const { copy, add } = core.BoundsHelper;
800
829
  exports.Box = class Box extends exports.Group {
801
830
  get __tag() { return 'Box'; }
802
- get resizeable() { return true; }
803
831
  constructor(data) {
804
832
  super(data);
805
833
  this.isBranchLeaf = true;
806
834
  this.__layout.renderChanged || this.__layout.renderChange();
807
835
  }
836
+ __scaleResize(scaleX, scaleY) {
837
+ if (this.__.__autoBounds && this.children.length) {
838
+ super.__scaleResize(scaleX, scaleY);
839
+ }
840
+ else {
841
+ this.width *= scaleX;
842
+ this.height *= scaleY;
843
+ }
844
+ }
808
845
  __updateStrokeSpread() { return 0; }
809
846
  __updateRectRenderSpread() { return 0; }
810
847
  __updateRenderSpread() {
@@ -814,7 +851,15 @@ exports.Box = class Box extends exports.Group {
814
851
  width = this.__.__drawAfterFill ? 0 : 1;
815
852
  return width;
816
853
  }
817
- __updateBoxBounds() { }
854
+ __updateRectBoxBounds() { }
855
+ __updateBoxBounds() {
856
+ if (this.__.__autoBounds && this.children.length) {
857
+ super.__updateBoxBounds();
858
+ }
859
+ else {
860
+ this.__updateRectBoxBounds();
861
+ }
862
+ }
818
863
  __updateStrokeBounds() { }
819
864
  __updateRenderBounds() {
820
865
  this.__updateRectRenderBounds();
@@ -866,7 +911,7 @@ __decorate([
866
911
  ], exports.Box.prototype, "__updateRectRenderSpread", null);
867
912
  __decorate([
868
913
  core.rewrite(rect.__updateBoxBounds)
869
- ], exports.Box.prototype, "__updateBoxBounds", null);
914
+ ], exports.Box.prototype, "__updateRectBoxBounds", null);
870
915
  __decorate([
871
916
  core.rewrite(rect.__updateStrokeBounds)
872
917
  ], exports.Box.prototype, "__updateStrokeBounds", null);
@@ -894,6 +939,7 @@ exports.Frame = class Frame extends exports.Box {
894
939
  get __tag() { return 'Frame'; }
895
940
  constructor(data) {
896
941
  super(data);
942
+ this.isFrame = true;
897
943
  if (!this.__.fill)
898
944
  this.__.fill = '#FFFFFF';
899
945
  }
@@ -934,7 +980,7 @@ exports.Ellipse = class Ellipse extends exports.UI {
934
980
  ellipse(path, rx, ry, rx, ry, 0, 360, 0, true);
935
981
  }
936
982
  if (core.Platform.ellipseToCurve)
937
- this.__.path = core.PathConvert.toCanvasData(path, true);
983
+ this.__.path = this.getPath(true);
938
984
  }
939
985
  else {
940
986
  if (startAngle || endAngle) {
@@ -964,47 +1010,118 @@ exports.Ellipse = __decorate([
964
1010
  core.registerUI()
965
1011
  ], exports.Ellipse);
966
1012
 
967
- const { sin: sin$1, cos: cos$1, PI: PI$1 } = Math;
968
- const { moveTo: moveTo$2, lineTo: lineTo$2, closePath: closePath$1, drawPoints: drawPoints$1 } = core.PathCommandDataHelper;
969
- const { toBounds: toBounds$2 } = core.PathBounds;
970
- exports.Polygon = class Polygon extends exports.UI {
971
- get __tag() { return 'Polygon'; }
972
- get resizeable() { return !this.points; }
1013
+ const { moveTo: moveTo$2, lineTo: lineTo$2, drawPoints: drawPoints$1 } = core.PathCommandDataHelper;
1014
+ const { rotate, getAngle, getDistance, defaultPoint } = core.PointHelper;
1015
+ const { toBounds: toBounds$1 } = core.PathBounds;
1016
+ exports.Line = class Line extends exports.UI {
1017
+ get __tag() { return 'Line'; }
1018
+ get toPoint() {
1019
+ const { width, rotation } = this.__;
1020
+ const to = { x: 0, y: 0 };
1021
+ if (width)
1022
+ to.x = width;
1023
+ if (rotation)
1024
+ rotate(to, rotation);
1025
+ return to;
1026
+ }
1027
+ set toPoint(value) {
1028
+ this.width = getDistance(defaultPoint, value);
1029
+ this.rotation = getAngle(defaultPoint, value);
1030
+ if (this.height)
1031
+ this.height = 0;
1032
+ }
973
1033
  constructor(data) {
974
1034
  super(data);
975
1035
  }
976
1036
  __updatePath() {
977
1037
  const path = this.__.path = [];
978
1038
  if (this.__.points) {
979
- drawPoints$1(path, this.__.points, false, true);
1039
+ drawPoints$1(path, this.__.points, false);
980
1040
  }
981
1041
  else {
982
- const { width, height, sides } = this.__;
983
- const rx = width / 2, ry = height / 2;
984
- moveTo$2(path, rx, 0);
985
- for (let i = 1; i < sides; i++) {
986
- lineTo$2(path, rx + rx * sin$1((i * 2 * PI$1) / sides), ry - ry * cos$1((i * 2 * PI$1) / sides));
987
- }
1042
+ moveTo$2(path, 0, 0);
1043
+ lineTo$2(path, this.width, 0);
988
1044
  }
989
- closePath$1(path);
990
1045
  }
991
1046
  __updateRenderPath() {
992
1047
  if (this.__.points && this.__.curve) {
993
- drawPoints$1(this.__.__pathForRender = [], this.__.points, this.__.curve, true);
1048
+ drawPoints$1(this.__.__pathForRender = [], this.__.points, this.__.curve, this.__tag !== 'Line');
994
1049
  }
995
1050
  else {
996
1051
  super.__updateRenderPath();
997
1052
  }
998
1053
  }
999
1054
  __updateBoxBounds() {
1000
- if (this.__.points) {
1001
- toBounds$2(this.__.__pathForRender, this.__layout.boxBounds);
1002
- this.__updateNaturalSize();
1055
+ if (this.points) {
1056
+ toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
1003
1057
  }
1004
1058
  else {
1005
1059
  super.__updateBoxBounds();
1006
1060
  }
1007
1061
  }
1062
+ __scaleResize(scaleX, scaleY) {
1063
+ if (this.points) {
1064
+ core.PathScaler.scalePoints(this.__.points, scaleX, scaleY);
1065
+ this.points = this.__.points;
1066
+ }
1067
+ else {
1068
+ if (this.__tag === 'Line') {
1069
+ const point = this.toPoint;
1070
+ point.x *= scaleX;
1071
+ point.y *= scaleY;
1072
+ this.toPoint = point;
1073
+ }
1074
+ else {
1075
+ super.__scaleResize(scaleX, scaleY);
1076
+ }
1077
+ }
1078
+ }
1079
+ };
1080
+ __decorate([
1081
+ core.dataProcessor(LineData)
1082
+ ], exports.Line.prototype, "__", void 0);
1083
+ __decorate([
1084
+ core.affectStrokeBoundsType('center')
1085
+ ], exports.Line.prototype, "strokeAlign", void 0);
1086
+ __decorate([
1087
+ core.boundsType(0)
1088
+ ], exports.Line.prototype, "height", void 0);
1089
+ __decorate([
1090
+ core.pathType()
1091
+ ], exports.Line.prototype, "points", void 0);
1092
+ __decorate([
1093
+ core.pathType(0)
1094
+ ], exports.Line.prototype, "curve", void 0);
1095
+ exports.Line = __decorate([
1096
+ core.registerUI()
1097
+ ], exports.Line);
1098
+
1099
+ const { sin: sin$1, cos: cos$1, PI: PI$1 } = Math;
1100
+ const { moveTo: moveTo$1, lineTo: lineTo$1, closePath: closePath$1, drawPoints } = core.PathCommandDataHelper;
1101
+ const line = exports.Line.prototype;
1102
+ exports.Polygon = class Polygon extends exports.UI {
1103
+ get __tag() { return 'Polygon'; }
1104
+ constructor(data) {
1105
+ super(data);
1106
+ }
1107
+ __updatePath() {
1108
+ const path = this.__.path = [];
1109
+ if (this.__.points) {
1110
+ drawPoints(path, this.__.points, false, true);
1111
+ }
1112
+ else {
1113
+ const { width, height, sides } = this.__;
1114
+ const rx = width / 2, ry = height / 2;
1115
+ moveTo$1(path, rx, 0);
1116
+ for (let i = 1; i < sides; i++) {
1117
+ lineTo$1(path, rx + rx * sin$1((i * 2 * PI$1) / sides), ry - ry * cos$1((i * 2 * PI$1) / sides));
1118
+ }
1119
+ }
1120
+ closePath$1(path);
1121
+ }
1122
+ __updateRenderPath() { }
1123
+ __updateBoxBounds() { }
1124
+ __scaleResize(_scaleX, _scaleY) { }
1008
1125
  };
1009
1126
  __decorate([
1010
1127
  core.dataProcessor(PolygonData)
@@ -1018,12 +1135,22 @@ __decorate([
1018
1135
  __decorate([
1019
1136
  core.pathType(0)
1020
1137
  ], exports.Polygon.prototype, "curve", void 0);
1138
+ __decorate([
1139
+ core.rewrite(line.__updateRenderPath)
1140
+ ], exports.Polygon.prototype, "__updateRenderPath", null);
1141
+ __decorate([
1142
+ core.rewrite(line.__updateBoxBounds)
1143
+ ], exports.Polygon.prototype, "__updateBoxBounds", null);
1144
+ __decorate([
1145
+ core.rewrite(line.__scaleResize)
1146
+ ], exports.Polygon.prototype, "__scaleResize", null);
1021
1147
  exports.Polygon = __decorate([
1148
+ core.rewriteAble(),
1022
1149
  core.registerUI()
1023
1150
  ], exports.Polygon);
1024
1151
 
1025
1152
  const { sin, cos, PI } = Math;
1026
- const { moveTo: moveTo$1, lineTo: lineTo$1, closePath } = core.PathCommandDataHelper;
1153
+ const { moveTo, lineTo, closePath } = core.PathCommandDataHelper;
1027
1154
  exports.Star = class Star extends exports.UI {
1028
1155
  get __tag() { return 'Star'; }
1029
1156
  constructor(data) {
@@ -1033,9 +1160,9 @@ exports.Star = class Star extends exports.UI {
1033
1160
  const { width, height, corners, innerRadius } = this.__;
1034
1161
  const rx = width / 2, ry = height / 2;
1035
1162
  const path = this.__.path = [];
1036
- moveTo$1(path, rx, 0);
1163
+ moveTo(path, rx, 0);
1037
1164
  for (let i = 1; i < corners * 2; i++) {
1038
- 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));
1165
+ lineTo(path, rx + (i % 2 === 0 ? rx : rx * innerRadius) * sin((i * PI) / corners), ry - (i % 2 === 0 ? ry : ry * innerRadius) * cos((i * PI) / corners));
1039
1166
  }
1040
1167
  closePath(path);
1041
1168
  }
@@ -1053,77 +1180,6 @@ exports.Star = __decorate([
1053
1180
  core.registerUI()
1054
1181
  ], exports.Star);
1055
1182
 
1056
- const { moveTo, lineTo, drawPoints } = core.PathCommandDataHelper;
1057
- const { rotate, getAngle, getDistance, defaultPoint } = core.PointHelper;
1058
- const { toBounds: toBounds$1 } = core.PathBounds;
1059
- exports.Line = class Line extends exports.UI {
1060
- get __tag() { return 'Line'; }
1061
- get resizeable() { return !this.points; }
1062
- get toPoint() {
1063
- const { width, rotation } = this.__;
1064
- const to = { x: 0, y: 0 };
1065
- if (width)
1066
- to.x = width;
1067
- if (rotation)
1068
- rotate(to, rotation);
1069
- return to;
1070
- }
1071
- set toPoint(value) {
1072
- this.width = getDistance(defaultPoint, value);
1073
- this.rotation = getAngle(defaultPoint, value);
1074
- if (this.height)
1075
- this.height = 0;
1076
- }
1077
- constructor(data) {
1078
- super(data);
1079
- }
1080
- __updatePath() {
1081
- const path = this.__.path = [];
1082
- if (this.__.points) {
1083
- drawPoints(path, this.__.points, false);
1084
- }
1085
- else {
1086
- moveTo(path, 0, 0);
1087
- lineTo(path, this.width, 0);
1088
- }
1089
- }
1090
- __updateRenderPath() {
1091
- if (this.__.points && this.__.curve) {
1092
- drawPoints(this.__.__pathForRender = [], this.__.points, this.__.curve, false);
1093
- }
1094
- else {
1095
- super.__updateRenderPath();
1096
- }
1097
- }
1098
- __updateBoxBounds() {
1099
- if (this.points) {
1100
- toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
1101
- this.__updateNaturalSize();
1102
- }
1103
- else {
1104
- super.__updateBoxBounds();
1105
- }
1106
- }
1107
- };
1108
- __decorate([
1109
- core.dataProcessor(LineData)
1110
- ], exports.Line.prototype, "__", void 0);
1111
- __decorate([
1112
- core.affectStrokeBoundsType('center')
1113
- ], exports.Line.prototype, "strokeAlign", void 0);
1114
- __decorate([
1115
- core.boundsType(0)
1116
- ], exports.Line.prototype, "height", void 0);
1117
- __decorate([
1118
- core.pathType()
1119
- ], exports.Line.prototype, "points", void 0);
1120
- __decorate([
1121
- core.pathType(0)
1122
- ], exports.Line.prototype, "curve", void 0);
1123
- exports.Line = __decorate([
1124
- core.registerUI()
1125
- ], exports.Line);
1126
-
1127
1183
  exports.Image = class Image extends exports.Rect {
1128
1184
  get __tag() { return 'Image'; }
1129
1185
  get ready() { return this.image ? this.image.ready : false; }
@@ -1174,7 +1230,7 @@ exports.Canvas = class Canvas extends exports.Rect {
1174
1230
  this.__.__drawAfterFill = true;
1175
1231
  }
1176
1232
  draw(ui, offset, scale, rotation) {
1177
- ui.__layout.checkUpdate();
1233
+ ui.__layout.update();
1178
1234
  const matrix = new core.Matrix(ui.__world);
1179
1235
  matrix.invert();
1180
1236
  const m = new core.Matrix();
@@ -1184,7 +1240,7 @@ exports.Canvas = class Canvas extends exports.Rect {
1184
1240
  typeof scale === 'number' ? m.scale(scale) : m.scale(scale.x, scale.y);
1185
1241
  if (rotation)
1186
1242
  m.rotate(rotation);
1187
- matrix.preMultiply(m);
1243
+ matrix.multiplyParent(m);
1188
1244
  ui.__render(this.canvas, { matrix });
1189
1245
  this.paint();
1190
1246
  }
@@ -1244,11 +1300,11 @@ exports.Canvas = __decorate([
1244
1300
  core.registerUI()
1245
1301
  ], exports.Canvas);
1246
1302
 
1247
- const { copyAndSpread, includes, spread, setByList } = core.BoundsHelper;
1303
+ const { copyAndSpread, includes, spread, setList } = core.BoundsHelper;
1248
1304
  exports.Text = class Text extends exports.UI {
1249
1305
  get __tag() { return 'Text'; }
1250
1306
  get textDrawData() {
1251
- this.__layout.checkUpdate();
1307
+ this.__layout.update();
1252
1308
  return this.__.__textDrawData;
1253
1309
  }
1254
1310
  constructor(data) {
@@ -1278,34 +1334,46 @@ exports.Text = class Text extends exports.UI {
1278
1334
  __updateBoxBounds() {
1279
1335
  const data = this.__;
1280
1336
  const layout = this.__layout;
1281
- const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow } = data;
1282
- const width = data.__getInput('width');
1283
- const height = data.__getInput('height');
1337
+ const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data;
1338
+ const autoWidth = data.__autoWidth;
1339
+ const autoHeight = data.__autoHeight;
1284
1340
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
1285
1341
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
1342
+ data.__padding = padding ? core.MathHelper.fourNumber(padding) : undefined;
1286
1343
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
1287
1344
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
1288
- data.__clipText = textOverflow !== 'show' && (width || height);
1345
+ data.__clipText = textOverflow !== 'show' && !data.__autoBounds;
1289
1346
  this.__updateTextDrawData();
1290
1347
  const { bounds } = data.__textDrawData;
1291
1348
  const b = layout.boxBounds;
1292
1349
  if (data.__lineHeight < fontSize)
1293
1350
  spread(bounds, fontSize / 2);
1294
- if (width && height) {
1295
- super.__updateBoxBounds();
1351
+ if (autoWidth || autoHeight) {
1352
+ b.x = autoWidth ? bounds.x : 0;
1353
+ b.y = autoHeight ? bounds.y : 0;
1354
+ b.width = autoWidth ? bounds.width : data.width;
1355
+ b.height = autoHeight ? bounds.height : data.height;
1356
+ if (padding) {
1357
+ const [top, right, bottom, left] = data.__padding;
1358
+ if (autoWidth) {
1359
+ b.x -= left;
1360
+ b.width += (right + left);
1361
+ }
1362
+ if (autoHeight) {
1363
+ b.y -= top;
1364
+ b.height += (bottom + top);
1365
+ }
1366
+ }
1367
+ this.__updateNaturalSize();
1296
1368
  }
1297
1369
  else {
1298
- b.x = width ? 0 : bounds.x;
1299
- b.y = height ? 0 : bounds.y;
1300
- b.width = width ? width : bounds.width;
1301
- b.height = height ? height : bounds.height;
1302
- this.__updateNaturalSize();
1370
+ super.__updateBoxBounds();
1303
1371
  }
1304
1372
  const contentBounds = includes(b, bounds) ? b : bounds;
1305
1373
  if (contentBounds !== layout.contentBounds) {
1306
1374
  layout.contentBounds = contentBounds;
1307
1375
  layout.renderChanged = true;
1308
- setByList(data.__textBoxBounds = {}, [b, bounds]);
1376
+ setList(data.__textBoxBounds = {}, [b, bounds]);
1309
1377
  }
1310
1378
  else {
1311
1379
  data.__textBoxBounds = contentBounds;
@@ -1333,6 +1401,9 @@ __decorate([
1333
1401
  __decorate([
1334
1402
  core.boundsType(0)
1335
1403
  ], exports.Text.prototype, "padding", void 0);
1404
+ __decorate([
1405
+ core.surfaceType('#000000')
1406
+ ], exports.Text.prototype, "fill", void 0);
1336
1407
  __decorate([
1337
1408
  core.affectStrokeBoundsType('outside')
1338
1409
  ], exports.Text.prototype, "strokeAlign", void 0);
@@ -1391,13 +1462,15 @@ exports.Text = __decorate([
1391
1462
  const { toBounds } = core.PathBounds;
1392
1463
  exports.Path = class Path extends exports.UI {
1393
1464
  get __tag() { return 'Path'; }
1394
- get resizeable() { return false; }
1395
1465
  constructor(data) {
1396
1466
  super(data);
1397
1467
  }
1468
+ __scaleResize(scaleX, scaleY) {
1469
+ core.PathScaler.scale(this.__.path, scaleX, scaleY);
1470
+ this.path = this.__.path;
1471
+ }
1398
1472
  __updateBoxBounds() {
1399
1473
  toBounds(this.__.path, this.__layout.boxBounds);
1400
- this.__updateNaturalSize();
1401
1474
  }
1402
1475
  };
1403
1476
  __decorate([
@@ -1466,6 +1539,8 @@ exports.Leafer = class Leafer extends exports.Group {
1466
1539
  get __tag() { return 'Leafer'; }
1467
1540
  get isApp() { return false; }
1468
1541
  get app() { return this.parent || this; }
1542
+ get imageReady() { return this.viewReady && core.ImageManager.isComplete; }
1543
+ get layoutLocked() { return !this.layouter.running; }
1469
1544
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
1470
1545
  constructor(userConfig, data) {
1471
1546
  super(data);
@@ -1558,13 +1633,18 @@ exports.Leafer = class Leafer extends exports.Group {
1558
1633
  this.emitLeafer(core.LeaferEvent.STOP);
1559
1634
  }
1560
1635
  }
1636
+ unlockLayout() {
1637
+ this.layouter.start();
1638
+ this.updateLayout();
1639
+ }
1640
+ lockLayout() {
1641
+ this.updateLayout();
1642
+ this.layouter.stop();
1643
+ }
1561
1644
  resize(size) {
1562
1645
  const data = core.DataHelper.copyAttrs({}, size, core.canvasSizeAttrs);
1563
1646
  Object.keys(data).forEach(key => this[key] = data[key]);
1564
1647
  }
1565
- forceLayout() {
1566
- this.__layout.checkUpdate(true);
1567
- }
1568
1648
  forceFullRender() {
1569
1649
  this.renderer.addBlock(this.canvas.bounds);
1570
1650
  if (this.viewReady)
@@ -1662,23 +1742,26 @@ exports.Leafer = class Leafer extends exports.Group {
1662
1742
  this.emitLeafer(core.LeaferEvent.VIEW_READY);
1663
1743
  core.WaitHelper.run(this.__viewReadyWait);
1664
1744
  }
1665
- __onRenderEnd(_e) {
1666
- if (!this.viewReady)
1667
- this.__onViewReady();
1668
- const completed = this.__checkViewCompleted();
1669
- if (completed)
1670
- this.__onViewCompleted();
1671
- this.viewCompleted = completed;
1672
- core.WaitHelper.run(this.__nextRenderWait);
1673
- }
1674
- __checkViewCompleted() {
1675
- return this.viewReady && !this.watcher.changed && core.ImageManager.isComplete;
1676
- }
1677
- __onViewCompleted() {
1678
- if (!this.viewCompleted) {
1679
- this.emitLeafer(core.LeaferEvent.VIEW_COMPLETED);
1680
- core.WaitHelper.run(this.__viewCompletedWait);
1681
- }
1745
+ __onAnimateFrame() {
1746
+ if (this.viewReady) {
1747
+ if (this.__nextRenderWait.length)
1748
+ core.WaitHelper.run(this.__nextRenderWait);
1749
+ const { imageReady } = this;
1750
+ if (imageReady && !this.viewCompleted)
1751
+ this.__checkViewCompleted();
1752
+ if (!imageReady)
1753
+ this.viewCompleted = false;
1754
+ }
1755
+ }
1756
+ __checkViewCompleted(emit = true) {
1757
+ this.nextRender(() => {
1758
+ if (this.imageReady) {
1759
+ if (emit)
1760
+ this.emitLeafer(core.LeaferEvent.VIEW_COMPLETED);
1761
+ core.WaitHelper.run(this.__viewCompletedWait);
1762
+ this.viewCompleted = true;
1763
+ }
1764
+ });
1682
1765
  }
1683
1766
  __onWatchData() {
1684
1767
  if (this.watcher.childrenChanged && this.interaction) {
@@ -1692,25 +1775,20 @@ exports.Leafer = class Leafer extends exports.Group {
1692
1775
  this.viewReady ? item() : this.__viewReadyWait.push(item);
1693
1776
  }
1694
1777
  waitViewCompleted(item) {
1778
+ this.__viewCompletedWait.push(item);
1695
1779
  if (this.viewCompleted) {
1696
- item();
1780
+ this.__checkViewCompleted(false);
1697
1781
  }
1698
1782
  else {
1699
- this.__viewCompletedWait.push(item);
1700
1783
  if (!this.running)
1701
1784
  this.start();
1702
1785
  }
1703
1786
  }
1704
1787
  nextRender(item) {
1705
- if (this.watcher && !this.watcher.changed) {
1706
- item();
1707
- }
1708
- else {
1709
- this.__nextRenderWait.push(item);
1710
- }
1788
+ this.__nextRenderWait.push(item);
1711
1789
  }
1712
1790
  __checkUpdateLayout() {
1713
- this.__layout.checkUpdate();
1791
+ this.__layout.update();
1714
1792
  }
1715
1793
  emitLeafer(type) {
1716
1794
  this.emitEvent(new core.LeaferEvent(type, this));
@@ -1720,7 +1798,8 @@ exports.Leafer = class Leafer extends exports.Group {
1720
1798
  this.once(core.LeaferEvent.START, () => core.Run.end(runId));
1721
1799
  this.once(core.LayoutEvent.END, () => this.__onReady());
1722
1800
  this.once(core.RenderEvent.START, () => this.__onCreated());
1723
- this.__eventIds.push(this.on_(core.WatchEvent.DATA, this.__onWatchData, this), this.on_(core.RenderEvent.END, this.__onRenderEnd, this), this.on_(core.LayoutEvent.CHECK_UPDATE, this.__checkUpdateLayout, this));
1801
+ this.once(core.RenderEvent.END, () => this.__onViewReady());
1802
+ this.__eventIds.push(this.on_(core.WatchEvent.DATA, this.__onWatchData, this), this.on_(core.AnimateEvent.FRAME, this.__onAnimateFrame, this), this.on_(core.LayoutEvent.CHECK_UPDATE, this.__checkUpdateLayout, this));
1724
1803
  }
1725
1804
  __removeListenEvents() {
1726
1805
  this.off_(this.__eventIds);
@@ -1770,6 +1849,22 @@ exports.Leafer = __decorate([
1770
1849
  exports.App = class App extends exports.Leafer {
1771
1850
  get __tag() { return 'App'; }
1772
1851
  get isApp() { return true; }
1852
+ constructor(userConfig, data) {
1853
+ super(userConfig, data);
1854
+ if (userConfig) {
1855
+ const { ground, tree, sky, editor } = userConfig;
1856
+ if (ground)
1857
+ this.ground = this.addLeafer(ground);
1858
+ if (tree || editor)
1859
+ this.tree = this.addLeafer(tree);
1860
+ if (sky || editor)
1861
+ this.sky = this.addLeafer(sky || { type: 'draw', usePartRender: false });
1862
+ if (editor) {
1863
+ this.editor = core.Creator.editor(editor);
1864
+ this.sky.add(this.editor);
1865
+ }
1866
+ }
1867
+ }
1773
1868
  __setApp() {
1774
1869
  const { canvas } = this;
1775
1870
  const { realCanvas, view } = this.config;
@@ -1786,12 +1881,20 @@ exports.App = class App extends exports.Leafer {
1786
1881
  }
1787
1882
  start() {
1788
1883
  super.start();
1789
- this.children.forEach(leafer => { leafer.start(); });
1884
+ this.children.forEach(leafer => leafer.start());
1790
1885
  }
1791
1886
  stop() {
1792
- this.children.forEach(leafer => { leafer.stop(); });
1887
+ this.children.forEach(leafer => leafer.stop());
1793
1888
  super.stop();
1794
1889
  }
1890
+ unlockLayout() {
1891
+ super.unlockLayout();
1892
+ this.children.forEach(leafer => leafer.unlockLayout());
1893
+ }
1894
+ lockLayout() {
1895
+ super.lockLayout();
1896
+ this.children.forEach(leafer => leafer.lockLayout());
1897
+ }
1795
1898
  addLeafer(merge) {
1796
1899
  const leafer = new exports.Leafer(merge);
1797
1900
  this.add(leafer);
@@ -1810,7 +1913,7 @@ exports.App = class App extends exports.Leafer {
1810
1913
  }
1811
1914
  __onPropertyChange() {
1812
1915
  if (core.Debug.showHitView)
1813
- this.children.forEach(leafer => { leafer.forceUpdate('surface'); });
1916
+ this.children.forEach(leafer => leafer.forceUpdate('surface'));
1814
1917
  }
1815
1918
  __onCreated() {
1816
1919
  this.created = this.children.every(child => child.created);
@@ -1823,23 +1926,20 @@ exports.App = class App extends exports.Leafer {
1823
1926
  if (this.children.every(child => child.viewReady))
1824
1927
  super.__onViewReady();
1825
1928
  }
1826
- __checkViewCompleted() {
1827
- return this.children.every(item => item.viewCompleted);
1828
- }
1829
1929
  __onChildRenderEnd(e) {
1830
1930
  this.renderer.addBlock(e.renderBounds);
1831
1931
  if (this.viewReady)
1832
1932
  this.renderer.update();
1833
1933
  }
1834
1934
  __render(canvas, _options) {
1835
- this.children.forEach(leafer => { canvas.copyWorld(leafer.canvas); });
1935
+ this.children.forEach(leafer => canvas.copyWorld(leafer.canvas));
1836
1936
  }
1837
1937
  __onResize(event) {
1838
- this.children.forEach(leafer => { leafer.resize(event); });
1938
+ this.children.forEach(leafer => leafer.resize(event));
1839
1939
  super.__onResize(event);
1840
1940
  }
1841
1941
  __checkUpdateLayout() {
1842
- this.children.forEach(leafer => { leafer.__layout.checkUpdate(); });
1942
+ this.children.forEach(leafer => leafer.__layout.update());
1843
1943
  }
1844
1944
  __getChildConfig(userConfig) {
1845
1945
  let config = Object.assign({}, this.config);
@@ -1855,7 +1955,7 @@ exports.App = class App extends exports.Leafer {
1855
1955
  __listenChildEvents(leafer) {
1856
1956
  leafer.once(core.LayoutEvent.END, () => this.__onReady());
1857
1957
  leafer.once(core.RenderEvent.START, () => this.__onCreated());
1858
- leafer.once(core.RenderEvent.END, (e) => this.__onRenderEnd(e));
1958
+ leafer.once(core.RenderEvent.END, () => this.__onViewReady());
1859
1959
  if (this.realCanvas)
1860
1960
  this.__eventIds.push(leafer.on_(core.RenderEvent.END, this.__onChildRenderEnd, this));
1861
1961
  }
@@ -1865,16 +1965,32 @@ exports.App = __decorate([
1865
1965
  ], exports.App);
1866
1966
 
1867
1967
  exports.Animate = Animate;
1968
+ exports.BoxData = BoxData;
1969
+ exports.CanvasData = CanvasData;
1868
1970
  exports.ColorConvert = ColorConvert;
1869
1971
  exports.Effect = Effect;
1972
+ exports.EllipseData = EllipseData;
1870
1973
  exports.Export = Export;
1974
+ exports.FrameData = FrameData;
1975
+ exports.GroupData = GroupData;
1976
+ exports.ImageData = ImageData;
1977
+ exports.LeaferData = LeaferData;
1871
1978
  exports.LeaferTypeCreator = LeaferTypeCreator;
1979
+ exports.LineData = LineData;
1872
1980
  exports.Paint = Paint;
1981
+ exports.PathData = PathData;
1982
+ exports.PenData = PenData;
1983
+ exports.PolygonData = PolygonData;
1984
+ exports.RectData = RectData;
1873
1985
  exports.RectRender = RectRender;
1986
+ exports.StarData = StarData;
1874
1987
  exports.TextConvert = TextConvert;
1988
+ exports.TextData = TextData;
1875
1989
  exports.UIBounds = UIBounds;
1990
+ exports.UIData = UIData;
1876
1991
  exports.UIHit = UIHit;
1877
1992
  exports.UIRender = UIRender;
1993
+ exports.UnitConvert = UnitConvert;
1878
1994
  exports.effectType = effectType;
1879
1995
  exports.resizeType = resizeType;
1880
1996
  Object.keys(core).forEach(function (k) {