@leafer/core 1.0.5 → 1.0.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/core.cjs CHANGED
@@ -554,6 +554,12 @@ const PointHelper = {
554
554
  to.y = t.y + sin$2(r) * distance;
555
555
  return to;
556
556
  },
557
+ toNumberPoints(originPoints) {
558
+ let points = originPoints;
559
+ if (typeof originPoints[0] === 'object')
560
+ points = [], originPoints.forEach(p => points.push(p.x, p.y));
561
+ return points;
562
+ },
557
563
  reset(t) {
558
564
  P$5.reset(t);
559
565
  }
@@ -1544,7 +1550,10 @@ const { assign } = DataHelper;
1544
1550
 
1545
1551
  class LeafData {
1546
1552
  get __useNaturalRatio() { return true; }
1547
- get __isLinePath() { return this.path && this.path.length === 6; }
1553
+ get __isLinePath() {
1554
+ const { path } = this;
1555
+ return path && path.length === 6 && path[0] === 1;
1556
+ }
1548
1557
  get __blendMode() {
1549
1558
  if (this.eraser && this.eraser !== 'path')
1550
1559
  return 'destination-out';
@@ -2307,11 +2316,12 @@ const RectHelper = {
2307
2316
 
2308
2317
  const { sin: sin$1, cos: cos$1, atan2: atan2$1, ceil, abs: abs$1, PI, sqrt: sqrt$1, pow } = Math;
2309
2318
  const { setPoint: setPoint$1, addPoint: addPoint$1 } = TwoPointBoundsHelper;
2310
- const { set } = PointHelper;
2319
+ const { set, toNumberPoints } = PointHelper;
2311
2320
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$5 } = PathCommandMap;
2312
2321
  const tempPoint$1 = {};
2313
2322
  const BezierHelper = {
2314
- points(data, points, curve, close) {
2323
+ points(data, originPoints, curve, close) {
2324
+ let points = toNumberPoints(originPoints);
2315
2325
  data.push(M$5, points[0], points[1]);
2316
2326
  if (curve && points.length > 5) {
2317
2327
  let aX, aY, bX, bY, cX, cY, c1X, c1Y, c2X, c2Y;
@@ -2820,6 +2830,27 @@ const PathConvert = {
2820
2830
  }
2821
2831
  return data;
2822
2832
  },
2833
+ objectToCanvasData(list) {
2834
+ const data = [];
2835
+ list.forEach(item => {
2836
+ switch (item.name) {
2837
+ case 'M':
2838
+ data.push(M$4, item.x, item.y);
2839
+ break;
2840
+ case 'L':
2841
+ data.push(L$5, item.x, item.y);
2842
+ break;
2843
+ case 'C':
2844
+ data.push(C$4, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2845
+ break;
2846
+ case 'Q':
2847
+ data.push(Q$3, item.x1, item.y1, item.x, item.y);
2848
+ break;
2849
+ case 'Z': data.push(Z$4);
2850
+ }
2851
+ });
2852
+ return data;
2853
+ },
2823
2854
  copyData(data, old, index, count) {
2824
2855
  for (let i = index, end = index + count; i < end; i++) {
2825
2856
  data.push(old[i]);
@@ -4397,13 +4428,10 @@ class LeafLayout {
4397
4428
  update() {
4398
4429
  const { leafer } = this.leaf;
4399
4430
  if (leafer) {
4400
- if (leafer.ready) {
4401
- if (leafer.watcher.changed)
4402
- leafer.layouter.layout();
4403
- }
4404
- else {
4431
+ if (leafer.ready)
4432
+ leafer.watcher.changed && leafer.layouter.layout();
4433
+ else
4405
4434
  leafer.start();
4406
- }
4407
4435
  }
4408
4436
  else {
4409
4437
  let root = this.leaf;
@@ -5161,7 +5189,7 @@ const LeafRender = {
5161
5189
  if (this.__worldOpacity) {
5162
5190
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5163
5191
  this.__drawRenderPath(canvas);
5164
- this.__.windingRule ? canvas.clip(this.__.windingRule) : canvas.clip();
5192
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
5165
5193
  }
5166
5194
  },
5167
5195
  __updateWorldOpacity() {
@@ -5678,11 +5706,17 @@ exports.Branch = class Branch extends exports.Leaf {
5678
5706
  add(child, index) {
5679
5707
  if (child === this)
5680
5708
  return;
5681
- child.__ || (child = UICreator.get(child.tag, child));
5709
+ const noIndex = index === undefined;
5710
+ if (!child.__) {
5711
+ if (child instanceof Array)
5712
+ return child.forEach(item => { this.add(item, index); noIndex || index++; });
5713
+ else
5714
+ child = UICreator.get(child.tag, child);
5715
+ }
5682
5716
  if (child.parent)
5683
5717
  child.parent.remove(child);
5684
5718
  child.parent = this;
5685
- index === undefined ? this.children.push(child) : this.children.splice(index, 0, child);
5719
+ noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
5686
5720
  if (child.isBranch)
5687
5721
  this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
5688
5722
  child.__layout.boxChanged || child.__layout.boxChange();
@@ -5696,9 +5730,7 @@ exports.Branch = class Branch extends exports.Leaf {
5696
5730
  }
5697
5731
  this.__layout.affectChildrenSort && this.__layout.childrenSortChange();
5698
5732
  }
5699
- addMany(...children) {
5700
- children.forEach(child => this.add(child));
5701
- }
5733
+ addMany(...children) { this.add(children); }
5702
5734
  remove(child, destroy) {
5703
5735
  if (child) {
5704
5736
  if (child.__) {
@@ -5926,7 +5958,7 @@ class LeafLevelList {
5926
5958
  }
5927
5959
  }
5928
5960
 
5929
- const version = "1.0.5";
5961
+ const version = "1.0.7";
5930
5962
 
5931
5963
  exports.AlignHelper = AlignHelper;
5932
5964
  exports.AroundHelper = AroundHelper;
package/lib/core.esm.js CHANGED
@@ -552,6 +552,12 @@ const PointHelper = {
552
552
  to.y = t.y + sin$2(r) * distance;
553
553
  return to;
554
554
  },
555
+ toNumberPoints(originPoints) {
556
+ let points = originPoints;
557
+ if (typeof originPoints[0] === 'object')
558
+ points = [], originPoints.forEach(p => points.push(p.x, p.y));
559
+ return points;
560
+ },
555
561
  reset(t) {
556
562
  P$5.reset(t);
557
563
  }
@@ -1542,7 +1548,10 @@ const { assign } = DataHelper;
1542
1548
 
1543
1549
  class LeafData {
1544
1550
  get __useNaturalRatio() { return true; }
1545
- get __isLinePath() { return this.path && this.path.length === 6; }
1551
+ get __isLinePath() {
1552
+ const { path } = this;
1553
+ return path && path.length === 6 && path[0] === 1;
1554
+ }
1546
1555
  get __blendMode() {
1547
1556
  if (this.eraser && this.eraser !== 'path')
1548
1557
  return 'destination-out';
@@ -2305,11 +2314,12 @@ const RectHelper = {
2305
2314
 
2306
2315
  const { sin: sin$1, cos: cos$1, atan2: atan2$1, ceil, abs: abs$1, PI, sqrt: sqrt$1, pow } = Math;
2307
2316
  const { setPoint: setPoint$1, addPoint: addPoint$1 } = TwoPointBoundsHelper;
2308
- const { set } = PointHelper;
2317
+ const { set, toNumberPoints } = PointHelper;
2309
2318
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$5 } = PathCommandMap;
2310
2319
  const tempPoint$1 = {};
2311
2320
  const BezierHelper = {
2312
- points(data, points, curve, close) {
2321
+ points(data, originPoints, curve, close) {
2322
+ let points = toNumberPoints(originPoints);
2313
2323
  data.push(M$5, points[0], points[1]);
2314
2324
  if (curve && points.length > 5) {
2315
2325
  let aX, aY, bX, bY, cX, cY, c1X, c1Y, c2X, c2Y;
@@ -2818,6 +2828,27 @@ const PathConvert = {
2818
2828
  }
2819
2829
  return data;
2820
2830
  },
2831
+ objectToCanvasData(list) {
2832
+ const data = [];
2833
+ list.forEach(item => {
2834
+ switch (item.name) {
2835
+ case 'M':
2836
+ data.push(M$4, item.x, item.y);
2837
+ break;
2838
+ case 'L':
2839
+ data.push(L$5, item.x, item.y);
2840
+ break;
2841
+ case 'C':
2842
+ data.push(C$4, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2843
+ break;
2844
+ case 'Q':
2845
+ data.push(Q$3, item.x1, item.y1, item.x, item.y);
2846
+ break;
2847
+ case 'Z': data.push(Z$4);
2848
+ }
2849
+ });
2850
+ return data;
2851
+ },
2821
2852
  copyData(data, old, index, count) {
2822
2853
  for (let i = index, end = index + count; i < end; i++) {
2823
2854
  data.push(old[i]);
@@ -4395,13 +4426,10 @@ class LeafLayout {
4395
4426
  update() {
4396
4427
  const { leafer } = this.leaf;
4397
4428
  if (leafer) {
4398
- if (leafer.ready) {
4399
- if (leafer.watcher.changed)
4400
- leafer.layouter.layout();
4401
- }
4402
- else {
4429
+ if (leafer.ready)
4430
+ leafer.watcher.changed && leafer.layouter.layout();
4431
+ else
4403
4432
  leafer.start();
4404
- }
4405
4433
  }
4406
4434
  else {
4407
4435
  let root = this.leaf;
@@ -5159,7 +5187,7 @@ const LeafRender = {
5159
5187
  if (this.__worldOpacity) {
5160
5188
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5161
5189
  this.__drawRenderPath(canvas);
5162
- this.__.windingRule ? canvas.clip(this.__.windingRule) : canvas.clip();
5190
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
5163
5191
  }
5164
5192
  },
5165
5193
  __updateWorldOpacity() {
@@ -5676,11 +5704,17 @@ let Branch = class Branch extends Leaf {
5676
5704
  add(child, index) {
5677
5705
  if (child === this)
5678
5706
  return;
5679
- child.__ || (child = UICreator.get(child.tag, child));
5707
+ const noIndex = index === undefined;
5708
+ if (!child.__) {
5709
+ if (child instanceof Array)
5710
+ return child.forEach(item => { this.add(item, index); noIndex || index++; });
5711
+ else
5712
+ child = UICreator.get(child.tag, child);
5713
+ }
5680
5714
  if (child.parent)
5681
5715
  child.parent.remove(child);
5682
5716
  child.parent = this;
5683
- index === undefined ? this.children.push(child) : this.children.splice(index, 0, child);
5717
+ noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
5684
5718
  if (child.isBranch)
5685
5719
  this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
5686
5720
  child.__layout.boxChanged || child.__layout.boxChange();
@@ -5694,9 +5728,7 @@ let Branch = class Branch extends Leaf {
5694
5728
  }
5695
5729
  this.__layout.affectChildrenSort && this.__layout.childrenSortChange();
5696
5730
  }
5697
- addMany(...children) {
5698
- children.forEach(child => this.add(child));
5699
- }
5731
+ addMany(...children) { this.add(children); }
5700
5732
  remove(child, destroy) {
5701
5733
  if (child) {
5702
5734
  if (child.__) {
@@ -5924,6 +5956,6 @@ class LeafLevelList {
5924
5956
  }
5925
5957
  }
5926
5958
 
5927
- const version = "1.0.5";
5959
+ const version = "1.0.7";
5928
5960
 
5929
5961
  export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, FileHelper, ImageEvent, ImageManager, IncrementId, LayoutEvent, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, LeaferCanvasBase, LeaferEvent, LeaferImage, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isNull, layoutProcessor, maskType, naturalBoundsType, needPlugin, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, useModule, version, visibleType };