@leafer/core 1.0.0-rc.23 → 1.0.0-rc.24

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.esm.js CHANGED
@@ -1485,6 +1485,8 @@ const DataHelper = {
1485
1485
  const { assign } = DataHelper;
1486
1486
 
1487
1487
  class LeafData {
1488
+ get __useNaturalRatio() { return true; }
1489
+ get __isLinePath() { return this.path && this.path.length === 6; }
1488
1490
  get __blendMode() {
1489
1491
  if (this.eraser && this.eraser !== 'path')
1490
1492
  return 'destination-out';
@@ -1982,6 +1984,11 @@ class LeaferCanvasBase extends Canvas {
1982
1984
  }
1983
1985
  updateViewSize() { }
1984
1986
  updateClientBounds() { }
1987
+ getClientBounds(update) {
1988
+ if (update)
1989
+ this.updateClientBounds();
1990
+ return this.clientBounds || this.bounds;
1991
+ }
1985
1992
  startAutoLayout(_autoBounds, _listener) { }
1986
1993
  stopAutoLayout() { }
1987
1994
  setCursor(_cursor) { }
@@ -2530,11 +2537,15 @@ const PathConvert = {
2530
2537
  char = pathString[i];
2531
2538
  if (StringNumberMap[char]) {
2532
2539
  if (char === '.') {
2533
- current.dot++;
2534
- if (current.dot > 1) {
2540
+ if (current.dot) {
2535
2541
  pushData(data, num);
2536
2542
  num = '';
2537
2543
  }
2544
+ current.dot++;
2545
+ }
2546
+ if (num === '0' && char !== '.') {
2547
+ pushData(data, num);
2548
+ num = '';
2538
2549
  }
2539
2550
  num += char;
2540
2551
  }
@@ -3624,7 +3635,9 @@ class LeaferImage {
3624
3635
  }
3625
3636
  }
3626
3637
 
3627
- function defineKey(target, key, descriptor) {
3638
+ function defineKey(target, key, descriptor, noConfigurable) {
3639
+ if (!noConfigurable)
3640
+ descriptor.configurable = descriptor.enumerable = true;
3628
3641
  Object.defineProperty(target, key, descriptor);
3629
3642
  }
3630
3643
  function getDescriptor(object, name) {
@@ -3643,9 +3656,7 @@ function attr(partDescriptor) {
3643
3656
  function defineLeafAttr(target, key, defaultValue, partDescriptor) {
3644
3657
  const defaultDescriptor = {
3645
3658
  get() { return this.__getAttr(key); },
3646
- set(value) { this.__setAttr(key, value); },
3647
- configurable: true,
3648
- enumerable: true
3659
+ set(value) { this.__setAttr(key, value); }
3649
3660
  };
3650
3661
  defineKey(target, key, Object.assign(defaultDescriptor, partDescriptor || {}));
3651
3662
  defineDataProcessor(target, key, defaultValue);
@@ -3656,35 +3667,33 @@ function dataType(defaultValue) {
3656
3667
  function positionType(defaultValue, checkFiniteNumber) {
3657
3668
  return decorateLeafAttr(defaultValue, (key) => attr({
3658
3669
  set(value) {
3659
- this.__setAttr(key, value, checkFiniteNumber);
3660
- this.__layout.matrixChanged || this.__layout.matrixChange();
3670
+ this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.matrixChanged || this.__layout.matrixChange());
3661
3671
  }
3662
3672
  }));
3663
3673
  }
3664
3674
  function autoLayoutType(defaultValue) {
3665
3675
  return decorateLeafAttr(defaultValue, (key) => attr({
3666
3676
  set(value) {
3667
- this.__setAttr(key, value);
3668
- this.__layout.matrixChanged || this.__layout.matrixChange();
3669
- this.__hasAutoLayout = !!value;
3670
- if (!this.__local)
3671
- this.__layout.createLocal();
3677
+ if (this.__setAttr(key, value)) {
3678
+ this.__layout.matrixChanged || this.__layout.matrixChange();
3679
+ this.__hasAutoLayout = !!value;
3680
+ if (!this.__local)
3681
+ this.__layout.createLocal();
3682
+ }
3672
3683
  }
3673
3684
  }));
3674
3685
  }
3675
3686
  function scaleType(defaultValue, checkFiniteNumber) {
3676
3687
  return decorateLeafAttr(defaultValue, (key) => attr({
3677
3688
  set(value) {
3678
- this.__setAttr(key, value, checkFiniteNumber);
3679
- this.__layout.scaleChanged || this.__layout.scaleChange();
3689
+ this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.scaleChanged || this.__layout.scaleChange());
3680
3690
  }
3681
3691
  }));
3682
3692
  }
3683
3693
  function rotationType(defaultValue, checkFiniteNumber) {
3684
3694
  return decorateLeafAttr(defaultValue, (key) => attr({
3685
3695
  set(value) {
3686
- this.__setAttr(key, value, checkFiniteNumber);
3687
- this.__layout.rotationChanged || this.__layout.rotationChange();
3696
+ this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.rotationChanged || this.__layout.rotationChange());
3688
3697
  }
3689
3698
  }));
3690
3699
  }
@@ -3698,9 +3707,7 @@ function boundsType(defaultValue, checkFiniteNumber) {
3698
3707
  function naturalBoundsType(defaultValue) {
3699
3708
  return decorateLeafAttr(defaultValue, (key) => attr({
3700
3709
  set(value) {
3701
- this.__setAttr(key, value);
3702
- doBoundsType(this);
3703
- this.__.__removeNaturalSize();
3710
+ this.__setAttr(key, value) && (doBoundsType(this), this.__.__removeNaturalSize());
3704
3711
  }
3705
3712
  }));
3706
3713
  }
@@ -3712,8 +3719,11 @@ function doBoundsType(leaf) {
3712
3719
  function pathInputType(defaultValue) {
3713
3720
  return decorateLeafAttr(defaultValue, (key) => attr({
3714
3721
  set(value) {
3715
- if (this.__.__pathInputed !== 2)
3716
- this.__.__pathInputed = value ? 1 : 0;
3722
+ const data = this.__;
3723
+ if (data.__pathInputed !== 2)
3724
+ data.__pathInputed = value ? 1 : 0;
3725
+ if (!value)
3726
+ data.__pathForRender = undefined;
3717
3727
  this.__setAttr(key, value);
3718
3728
  doBoundsType(this);
3719
3729
  }
@@ -3744,56 +3754,66 @@ function affectRenderBoundsType(defaultValue) {
3744
3754
  function surfaceType(defaultValue) {
3745
3755
  return decorateLeafAttr(defaultValue, (key) => attr({
3746
3756
  set(value) {
3747
- this.__setAttr(key, value);
3748
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3757
+ this.__setAttr(key, value) && (this.__layout.surfaceChanged || this.__layout.surfaceChange());
3749
3758
  }
3750
3759
  }));
3751
3760
  }
3752
3761
  function opacityType(defaultValue) {
3753
3762
  return decorateLeafAttr(defaultValue, (key) => attr({
3754
3763
  set(value) {
3755
- this.__setAttr(key, value);
3756
- this.__layout.opacityChanged || this.__layout.opacityChange();
3764
+ this.__setAttr(key, value) && (this.__layout.opacityChanged || this.__layout.opacityChange());
3765
+ }
3766
+ }));
3767
+ }
3768
+ function visibleType(defaultValue) {
3769
+ return decorateLeafAttr(defaultValue, (key) => attr({
3770
+ set(value) {
3771
+ const oldValue = this.visible;
3772
+ if (this.__setAttr(key, value)) {
3773
+ this.__layout.opacityChanged || this.__layout.opacityChange();
3774
+ if (oldValue === 0 || value === 0)
3775
+ doBoundsType(this);
3776
+ }
3757
3777
  }
3758
3778
  }));
3759
3779
  }
3760
3780
  function sortType(defaultValue) {
3761
3781
  return decorateLeafAttr(defaultValue, (key) => attr({
3762
3782
  set(value) {
3763
- this.__setAttr(key, value);
3764
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3765
- this.waitParent(() => { this.parent.__layout.childrenSortChange(); });
3783
+ if (this.__setAttr(key, value)) {
3784
+ this.__layout.surfaceChanged || this.__layout.surfaceChange();
3785
+ this.waitParent(() => { this.parent.__layout.childrenSortChange(); });
3786
+ }
3766
3787
  }
3767
3788
  }));
3768
3789
  }
3769
3790
  function maskType(defaultValue) {
3770
3791
  return decorateLeafAttr(defaultValue, (key) => attr({
3771
3792
  set(value) {
3772
- this.__setAttr(key, value);
3773
- this.__layout.boxChanged || this.__layout.boxChange();
3774
- this.waitParent(() => { this.parent.__updateMask(value); });
3775
- if (typeof value === 'string')
3776
- this.maskType = value;
3793
+ if (this.__setAttr(key, value)) {
3794
+ this.__layout.boxChanged || this.__layout.boxChange();
3795
+ this.waitParent(() => { this.parent.__updateMask(value); });
3796
+ }
3777
3797
  }
3778
3798
  }));
3779
3799
  }
3780
3800
  function eraserType(defaultValue) {
3781
3801
  return decorateLeafAttr(defaultValue, (key) => attr({
3782
3802
  set(value) {
3783
- this.__setAttr(key, value);
3784
- this.waitParent(() => { this.parent.__updateEraser(value); });
3803
+ this.__setAttr(key, value) && this.waitParent(() => { this.parent.__updateEraser(value); });
3785
3804
  }
3786
3805
  }));
3787
3806
  }
3788
3807
  function hitType(defaultValue) {
3789
3808
  return decorateLeafAttr(defaultValue, (key) => attr({
3790
3809
  set(value) {
3791
- this.__setAttr(key, value);
3792
- if (Debug.showHitView) {
3793
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3810
+ if (this.__setAttr(key, value)) {
3811
+ if (Debug.showHitView) {
3812
+ this.__layout.surfaceChanged || this.__layout.surfaceChange();
3813
+ }
3814
+ if (this.leafer)
3815
+ this.leafer.updateCursor();
3794
3816
  }
3795
- if (this.leafer)
3796
- this.leafer.updateCursor();
3797
3817
  }
3798
3818
  }));
3799
3819
  }
@@ -3834,9 +3854,7 @@ function defineDataProcessor(target, key, defaultValue) {
3834
3854
  },
3835
3855
  set(value) {
3836
3856
  this[computedKey] = value;
3837
- },
3838
- configurable: true,
3839
- enumerable: true
3857
+ }
3840
3858
  };
3841
3859
  if (defaultValue === undefined) {
3842
3860
  property.get = function () { return this[computedKey]; };
@@ -3844,13 +3862,25 @@ function defineDataProcessor(target, key, defaultValue) {
3844
3862
  else if (key === 'width') {
3845
3863
  property.get = function () {
3846
3864
  const v = this[computedKey];
3847
- return v === undefined ? (this.__naturalWidth || defaultValue) : v;
3865
+ if (v === undefined) {
3866
+ const t = this;
3867
+ return t._height && t.__naturalWidth && t.__useNaturalRatio ? t._height * t.__naturalWidth / t.__naturalHeight : t.__naturalWidth || defaultValue;
3868
+ }
3869
+ else {
3870
+ return v;
3871
+ }
3848
3872
  };
3849
3873
  }
3850
3874
  else if (key === 'height') {
3851
3875
  property.get = function () {
3852
3876
  const v = this[computedKey];
3853
- return v === undefined ? (this.__naturalHeight || defaultValue) : v;
3877
+ if (v === undefined) {
3878
+ const t = this;
3879
+ return t._width && t.__naturalHeight && t.__useNaturalRatio ? t._width * t.__naturalHeight / t.__naturalWidth : t.__naturalHeight || defaultValue;
3880
+ }
3881
+ else {
3882
+ return v;
3883
+ }
3854
3884
  };
3855
3885
  }
3856
3886
  let descriptor, find = data;
@@ -3864,7 +3894,7 @@ function defineDataProcessor(target, key, defaultValue) {
3864
3894
  property.set = data[setMethodName];
3865
3895
  delete data[setMethodName];
3866
3896
  }
3867
- Object.defineProperty(data, key, property);
3897
+ defineKey(data, key, property);
3868
3898
  }
3869
3899
 
3870
3900
  const debug$1 = new Debug('rewrite');
@@ -4065,13 +4095,6 @@ const LeafHelper = {
4065
4095
  return true;
4066
4096
  p = p.parent;
4067
4097
  }
4068
- },
4069
- hasParentAutoLayout(p) {
4070
- while (p.parent) {
4071
- p = p.parent;
4072
- if (p.__hasAutoLayout)
4073
- return true;
4074
- }
4075
4098
  }
4076
4099
  };
4077
4100
  const L = LeafHelper;
@@ -4091,13 +4114,13 @@ const LeafBoundsHelper = {
4091
4114
  return target.__world;
4092
4115
  },
4093
4116
  localBoxBounds(target) {
4094
- return target.__.eraser ? null : (target.__local || target.__layout);
4117
+ return target.__.eraser || target.__.visible === 0 ? null : (target.__local || target.__layout);
4095
4118
  },
4096
4119
  localStrokeBounds(target) {
4097
- return target.__.eraser ? null : target.__layout.localStrokeBounds;
4120
+ return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localStrokeBounds;
4098
4121
  },
4099
4122
  localRenderBounds(target) {
4100
- return target.__.eraser ? null : target.__layout.localRenderBounds;
4123
+ return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localRenderBounds;
4101
4124
  },
4102
4125
  maskLocalBoxBounds(target) {
4103
4126
  return target.__.mask ? target.__localBoxBounds : null;
@@ -4828,7 +4851,7 @@ const LeafMatrix = {
4828
4851
  }
4829
4852
  };
4830
4853
 
4831
- const { updateMatrix, updateAllMatrix, hasParentAutoLayout } = LeafHelper;
4854
+ const { updateMatrix, updateAllMatrix } = LeafHelper;
4832
4855
  const { updateBounds } = BranchHelper;
4833
4856
  const { toOuterOf: toOuterOf$1, copyAndSpread, copy: copy$1 } = BoundsHelper;
4834
4857
  const { toBounds } = PathBounds;
@@ -4847,7 +4870,6 @@ const LeafBounds = {
4847
4870
  this.__updatePath();
4848
4871
  this.__updateRenderPath();
4849
4872
  this.__updateBoxBounds();
4850
- layout.boxChanged = false;
4851
4873
  layout.resized = true;
4852
4874
  }
4853
4875
  if (layout.localBoxChanged) {
@@ -4861,12 +4883,12 @@ const LeafBounds = {
4861
4883
  if (this.parent)
4862
4884
  this.parent.__layout.boxChange();
4863
4885
  }
4886
+ layout.boxChanged = false;
4864
4887
  if (layout.strokeChanged) {
4865
4888
  layout.strokeSpread = this.__updateStrokeSpread();
4866
4889
  if (layout.strokeSpread) {
4867
- if (layout.strokeBounds === layout.boxBounds) {
4890
+ if (layout.strokeBounds === layout.boxBounds)
4868
4891
  layout.spreadStroke();
4869
- }
4870
4892
  this.__updateStrokeBounds();
4871
4893
  this.__updateLocalStrokeBounds();
4872
4894
  }
@@ -4874,7 +4896,7 @@ const LeafBounds = {
4874
4896
  layout.spreadStrokeCancel();
4875
4897
  }
4876
4898
  layout.strokeChanged = false;
4877
- if (layout.renderSpread)
4899
+ if (layout.renderSpread || layout.strokeSpread !== layout.strokeBoxSpread)
4878
4900
  layout.renderChanged = true;
4879
4901
  if (this.parent)
4880
4902
  this.parent.__layout.strokeChange();
@@ -4883,9 +4905,8 @@ const LeafBounds = {
4883
4905
  if (layout.renderChanged) {
4884
4906
  layout.renderSpread = this.__updateRenderSpread();
4885
4907
  if (layout.renderSpread) {
4886
- if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds) {
4908
+ if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds)
4887
4909
  layout.spreadRender();
4888
- }
4889
4910
  this.__updateRenderBounds();
4890
4911
  this.__updateLocalRenderBounds();
4891
4912
  }
@@ -4925,12 +4946,15 @@ const LeafBounds = {
4925
4946
  __updateAutoLayout() {
4926
4947
  this.__layout.matrixChanged = true;
4927
4948
  if (this.isBranch) {
4928
- if (this.leafer)
4949
+ if (this.leafer && this.leafer.ready)
4929
4950
  this.leafer.layouter.addExtra(this);
4930
- if (this.__.flow)
4931
- this.__updateFlowLayout();
4932
- if (hasParentAutoLayout(this)) {
4933
- updateMatrix(this);
4951
+ if (this.__.flow) {
4952
+ if (this.__layout.boxChanged)
4953
+ this.__updateFlowLayout();
4954
+ updateAllMatrix(this);
4955
+ updateBounds(this, this);
4956
+ if (this.__.__autoSide)
4957
+ this.__updateBoxBounds();
4934
4958
  }
4935
4959
  else {
4936
4960
  updateAllMatrix(this);
@@ -4947,12 +4971,13 @@ const LeafBounds = {
4947
4971
  data.__naturalHeight = layout.boxBounds.height;
4948
4972
  },
4949
4973
  __updateStrokeBounds() {
4950
- copyAndSpread(this.__layout.strokeBounds, this.__layout.boxBounds, this.__layout.strokeSpread);
4974
+ const layout = this.__layout;
4975
+ copyAndSpread(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
4951
4976
  },
4952
4977
  __updateRenderBounds() {
4953
- const { renderSpread, strokeBounds, renderBounds } = this.__layout;
4954
- renderSpread > 0 ? copyAndSpread(renderBounds, strokeBounds, renderSpread) : copy$1(renderBounds, strokeBounds);
4955
- },
4978
+ const layout = this.__layout;
4979
+ layout.renderSpread > 0 ? copyAndSpread(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$1(layout.renderBounds, layout.strokeBounds);
4980
+ }
4956
4981
  };
4957
4982
 
4958
4983
  const LeafRender = {
@@ -5072,7 +5097,7 @@ let Leaf = class Leaf {
5072
5097
  get __worldFlipped() { return this.__world.scaleX < 0 || this.__world.scaleY < 0; }
5073
5098
  get __onlyHitMask() { return this.__hasMask && !this.__.hitChildren; }
5074
5099
  get __ignoreHitWorld() { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren; }
5075
- get pathInputed() { return !!this.__.__pathInputed; }
5100
+ get pathInputed() { return this.__.__pathInputed; }
5076
5101
  constructor(data) {
5077
5102
  this.innerId = create(LEAF);
5078
5103
  this.reset(data);
@@ -5684,4 +5709,7 @@ class LeafLevelList {
5684
5709
  }
5685
5710
  }
5686
5711
 
5687
- export { AlignHelper, AnimateEvent, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, 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, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, useModule };
5712
+ const version = "1.0.0-rc.24";
5713
+ const inviteCode = {};
5714
+
5715
+ export { AlignHelper, AnimateEvent, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, 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, inviteCode, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, useModule, version, visibleType };