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