@leafer/core 1.0.0-rc.17 → 1.0.0-rc.19

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
@@ -38,6 +38,18 @@ const MathHelper = {
38
38
  value = max;
39
39
  return value;
40
40
  },
41
+ minus(value, isFourNumber) {
42
+ if (value instanceof Array) {
43
+ if (isFourNumber)
44
+ value = MathHelper.fourNumber(value);
45
+ for (let i = 0; i < value.length; i++)
46
+ value[i] = -value[i];
47
+ }
48
+ else {
49
+ value = -value;
50
+ }
51
+ return value;
52
+ },
41
53
  fourNumber(num, maxValue) {
42
54
  let data;
43
55
  if (num instanceof Array) {
@@ -721,7 +733,7 @@ const { addPoint: addPoint$3 } = TwoPointBoundsHelper;
721
733
 
722
734
  const { tempPointBounds: tempPointBounds$1, setPoint: setPoint$2, addPoint: addPoint$2, toBounds: toBounds$2 } = TwoPointBoundsHelper;
723
735
  const { toOuterPoint: toOuterPoint$1 } = MatrixHelper;
724
- const { float } = MathHelper;
736
+ const { float, fourNumber } = MathHelper;
725
737
  const { floor, ceil: ceil$1 } = Math;
726
738
  let right, bottom, boundsRight, boundsBottom;
727
739
  const point = {};
@@ -741,9 +753,15 @@ const BoundsHelper = {
741
753
  t.height = bounds.height;
742
754
  },
743
755
  copyAndSpread(t, bounds, spreadX, spreadY) {
744
- if (!spreadY)
745
- spreadY = spreadX;
746
- B.set(t, bounds.x - spreadX, bounds.y - spreadY, bounds.width + spreadX * 2, bounds.height + spreadY * 2);
756
+ if (spreadX instanceof Array) {
757
+ const four = fourNumber(spreadX);
758
+ B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
759
+ }
760
+ else {
761
+ if (!spreadY)
762
+ spreadY = spreadX;
763
+ B.set(t, bounds.x - spreadX, bounds.y - spreadY, bounds.width + spreadX * 2, bounds.height + spreadY * 2);
764
+ }
747
765
  },
748
766
  minX(t) { return t.width > 0 ? t.x : t.x + t.width; },
749
767
  minY(t) { return t.height > 0 ? t.y : t.y + t.height; },
@@ -1021,8 +1039,12 @@ class Bounds {
1021
1039
  getFitMatrix(put) {
1022
1040
  return BoundsHelper.getFitMatrix(this, put);
1023
1041
  }
1024
- spread(spreadX, spreadY) {
1025
- BoundsHelper.spread(this, spreadX, spreadY);
1042
+ spread(fourNumber, spreadY) {
1043
+ BoundsHelper.spread(this, fourNumber, spreadY);
1044
+ return this;
1045
+ }
1046
+ shrink(fourNumber) {
1047
+ BoundsHelper.spread(this, MathHelper.minus(fourNumber, true));
1026
1048
  return this;
1027
1049
  }
1028
1050
  ceil() {
@@ -1447,17 +1469,30 @@ class LeafData {
1447
1469
  if (this.__input && this.__input[name] !== undefined)
1448
1470
  this.__input[name] = undefined;
1449
1471
  }
1450
- __getInputData() {
1451
- const data = { tag: this.__leaf.tag }, { __input } = this;
1452
- let value, inputValue;
1453
- for (let key in this) {
1454
- if (key[0] !== '_') {
1455
- value = this['_' + key];
1456
- if (value !== undefined) {
1457
- if (key === 'path' && !this.__pathInputed)
1458
- continue;
1459
- inputValue = __input ? __input[key] : undefined;
1460
- data[key] = (inputValue === undefined) ? value : inputValue;
1472
+ __getInputData(names) {
1473
+ const data = {};
1474
+ if (names) {
1475
+ if (names instanceof Array) {
1476
+ for (let name of names)
1477
+ data[name] = this.__getInput(name);
1478
+ }
1479
+ else {
1480
+ for (let name in names)
1481
+ data[name] = this.__getInput(name);
1482
+ }
1483
+ }
1484
+ else {
1485
+ let value, inputValue, { __input } = this;
1486
+ data.tag = this.__leaf.tag;
1487
+ for (let key in this) {
1488
+ if (key[0] !== '_') {
1489
+ value = this['_' + key];
1490
+ if (value !== undefined) {
1491
+ if (key === 'path' && !this.__pathInputed)
1492
+ continue;
1493
+ inputValue = __input ? __input[key] : undefined;
1494
+ data[key] = (inputValue === undefined) ? value : inputValue;
1495
+ }
1461
1496
  }
1462
1497
  }
1463
1498
  }
@@ -2818,12 +2853,16 @@ class PathCreator {
2818
2853
  set path(value) { this.__path = value; }
2819
2854
  get path() { return this.__path; }
2820
2855
  constructor(path) {
2856
+ this.set(path);
2857
+ }
2858
+ set(path) {
2821
2859
  if (path) {
2822
2860
  this.__path = typeof path === 'string' ? PathHelper.parse(path) : path;
2823
2861
  }
2824
2862
  else {
2825
2863
  this.__path = [];
2826
2864
  }
2865
+ return this;
2827
2866
  }
2828
2867
  beginPath() {
2829
2868
  beginPath(this.__path);
@@ -3137,6 +3176,7 @@ const PathCorner = {
3137
3176
  PathHelper.creator = new PathCreator();
3138
3177
  PathHelper.parse = PathConvert.parse;
3139
3178
  PathHelper.convertToCanvasData = PathConvert.toCanvasData;
3179
+ const pen = new PathCreator();
3140
3180
 
3141
3181
  const { drawRoundRect } = RectHelper;
3142
3182
  function roundRect(drawer) {
@@ -3421,7 +3461,7 @@ const ImageManager = {
3421
3461
  },
3422
3462
  clearRecycled() {
3423
3463
  const list = I.recycledList;
3424
- if (list.length) {
3464
+ if (list.length > 100) {
3425
3465
  list.forEach(image => {
3426
3466
  if (!image.use && image.url) {
3427
3467
  delete I.map[image.url];
@@ -3673,6 +3713,8 @@ function affectStrokeBoundsType(defaultValue) {
3673
3713
  }
3674
3714
  function doStrokeType(leaf) {
3675
3715
  leaf.__layout.strokeChanged || leaf.__layout.strokeChange();
3716
+ if (leaf.__.__useArrow)
3717
+ doBoundsType(leaf);
3676
3718
  }
3677
3719
  const strokeType = affectStrokeBoundsType;
3678
3720
  function affectRenderBoundsType(defaultValue) {
@@ -3876,133 +3918,413 @@ function registerUIEvent() {
3876
3918
  };
3877
3919
  }
3878
3920
 
3879
- const tempMatrix = new Matrix();
3880
- const { toOuterOf: toOuterOf$2, getPoints, copy: copy$2 } = BoundsHelper;
3881
- class LeafLayout {
3882
- get strokeBounds() { return this._strokeBounds || this.boxBounds; }
3883
- get renderBounds() { return this._renderBounds || this.boxBounds; }
3884
- get localStrokeBounds() { return this._localStrokeBounds || this; }
3885
- get localRenderBounds() { return this._localRenderBounds || this; }
3886
- get a() { return 1; }
3887
- get b() { return 0; }
3888
- get c() { return 0; }
3889
- get d() { return 1; }
3890
- get e() { return this.leaf.__.x; }
3891
- get f() { return this.leaf.__.y; }
3892
- get x() { return this.e + this.boxBounds.x; }
3893
- get y() { return this.f + this.boxBounds.y; }
3894
- get width() { return this.boxBounds.width; }
3895
- get height() { return this.boxBounds.height; }
3896
- constructor(leaf) {
3897
- this.leaf = leaf;
3898
- this.boxBounds = { x: 0, y: 0, width: 0, height: 0 };
3899
- if (this.leaf.__local)
3900
- this._localRenderBounds = this._localStrokeBounds = this.leaf.__local;
3901
- this.boxChange();
3902
- this.matrixChange();
3903
- }
3904
- createLocal() {
3905
- const local = this.leaf.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 };
3906
- if (!this._localStrokeBounds)
3907
- this._localStrokeBounds = local;
3908
- if (!this._localRenderBounds)
3909
- this._localRenderBounds = local;
3910
- }
3911
- update() {
3912
- const { leafer } = this.leaf;
3913
- if (leafer) {
3914
- if (leafer.ready) {
3915
- if (leafer.watcher.changed)
3916
- leafer.layouter.layout();
3921
+ const { copy: copy$2, toInnerPoint: toInnerPoint$1, scaleOfOuter, rotateOfOuter, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3922
+ const matrix = {};
3923
+ const LeafHelper = {
3924
+ updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
3925
+ if (checkAutoLayout && leaf.__hasAutoLayout && leaf.__layout.matrixChanged)
3926
+ waitAutoLayout = true;
3927
+ updateMatrix$1(leaf, checkAutoLayout, waitAutoLayout);
3928
+ if (leaf.isBranch) {
3929
+ const { children } = leaf;
3930
+ for (let i = 0, len = children.length; i < len; i++) {
3931
+ updateAllMatrix$1(children[i], checkAutoLayout, waitAutoLayout);
3917
3932
  }
3918
- else {
3919
- leafer.start();
3933
+ }
3934
+ },
3935
+ updateMatrix(leaf, checkAutoLayout, waitAutoLayout) {
3936
+ const layout = leaf.__layout;
3937
+ if (checkAutoLayout) {
3938
+ if (waitAutoLayout) {
3939
+ layout.waitAutoLayout = true;
3940
+ if (leaf.__hasAutoLayout)
3941
+ layout.matrixChanged = false;
3920
3942
  }
3921
3943
  }
3922
- else {
3923
- let root = this.leaf;
3924
- while (root.parent && !root.parent.leafer) {
3925
- root = root.parent;
3944
+ else if (layout.waitAutoLayout) {
3945
+ layout.waitAutoLayout = false;
3946
+ }
3947
+ if (layout.matrixChanged)
3948
+ leaf.__updateLocalMatrix();
3949
+ if (!layout.waitAutoLayout)
3950
+ leaf.__updateWorldMatrix();
3951
+ },
3952
+ updateBounds(leaf) {
3953
+ const layout = leaf.__layout;
3954
+ if (layout.boundsChanged)
3955
+ leaf.__updateLocalBounds();
3956
+ if (!layout.waitAutoLayout)
3957
+ leaf.__updateWorldBounds();
3958
+ },
3959
+ updateAllWorldOpacity(leaf) {
3960
+ leaf.__updateWorldOpacity();
3961
+ if (leaf.isBranch) {
3962
+ const { children } = leaf;
3963
+ for (let i = 0, len = children.length; i < len; i++) {
3964
+ updateAllWorldOpacity(children[i]);
3926
3965
  }
3927
- Platform.layout(root);
3928
3966
  }
3929
- }
3930
- getTransform(relative = 'world') {
3931
- this.update();
3932
- switch (relative) {
3933
- case 'world':
3934
- return this.leaf.__world;
3935
- case 'local':
3936
- return this.leaf.__localMatrix;
3937
- case 'inner':
3938
- return MatrixHelper.defaultMatrix;
3939
- default:
3940
- return new Matrix(this.leaf.__world).divideParent(relative.__world);
3967
+ },
3968
+ updateAllChange(leaf) {
3969
+ updateAllWorldOpacity(leaf);
3970
+ leaf.__updateChange();
3971
+ if (leaf.isBranch) {
3972
+ const { children } = leaf;
3973
+ for (let i = 0, len = children.length; i < len; i++) {
3974
+ updateAllChange(children[i]);
3975
+ }
3941
3976
  }
3942
- }
3943
- getBounds(type, relative = 'world') {
3944
- this.update();
3945
- switch (relative) {
3946
- case 'world':
3947
- return this.getWorldBounds(type);
3948
- case 'local':
3949
- return this.getLocalBounds(type);
3950
- case 'inner':
3951
- return this.getInnerBounds(type);
3952
- default:
3953
- return new Bounds(this.getInnerBounds(type)).toOuterOf(this.getTransform(relative));
3977
+ },
3978
+ worldHittable(t) {
3979
+ while (t) {
3980
+ if (!t.__.hittable)
3981
+ return false;
3982
+ t = t.parent;
3954
3983
  }
3955
- }
3956
- getInnerBounds(type = 'box') {
3957
- switch (type) {
3958
- case 'render':
3959
- return this.renderBounds;
3960
- case 'content':
3961
- if (this.contentBounds)
3962
- return this.contentBounds;
3963
- case 'margin':
3964
- case 'box':
3965
- return this.boxBounds;
3966
- case 'stroke':
3967
- return this.strokeBounds;
3984
+ return true;
3985
+ },
3986
+ moveWorld(t, x, y) {
3987
+ const local = { x, y };
3988
+ if (t.parent)
3989
+ toInnerPoint$1(t.parent.worldTransform, local, local, true);
3990
+ L.moveLocal(t, local.x, local.y);
3991
+ },
3992
+ moveLocal(t, x, y = 0) {
3993
+ t.x += x;
3994
+ t.y += y;
3995
+ },
3996
+ zoomOfWorld(t, origin, scaleX, scaleY, resize) {
3997
+ L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
3998
+ },
3999
+ zoomOfLocal(t, origin, scaleX, scaleY = scaleX, resize) {
4000
+ copy$2(matrix, t.__localMatrix);
4001
+ scaleOfOuter(matrix, origin, scaleX, scaleY);
4002
+ moveByMatrix(t, matrix);
4003
+ t.scaleResize(scaleX, scaleY, resize !== true);
4004
+ },
4005
+ rotateOfWorld(t, origin, angle) {
4006
+ L.rotateOfLocal(t, getTempLocal(t, origin), angle);
4007
+ },
4008
+ rotateOfLocal(t, origin, angle) {
4009
+ copy$2(matrix, t.__localMatrix);
4010
+ rotateOfOuter(matrix, origin, angle);
4011
+ moveByMatrix(t, matrix);
4012
+ t.rotation = MathHelper.formatRotation(t.rotation + angle);
4013
+ },
4014
+ skewOfWorld(t, origin, skewX, skewY, resize) {
4015
+ L.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY, resize);
4016
+ },
4017
+ skewOfLocal(t, origin, skewX, skewY = 0, resize) {
4018
+ copy$2(matrix, t.__localMatrix);
4019
+ skewOfOuter(matrix, origin, skewX, skewY);
4020
+ L.setTransform(t, matrix, resize);
4021
+ },
4022
+ transformWorld(t, transform, resize) {
4023
+ copy$2(matrix, t.worldTransform);
4024
+ multiplyParent$2(matrix, transform);
4025
+ if (t.parent)
4026
+ divideParent(matrix, t.parent.worldTransform);
4027
+ L.setTransform(t, matrix, resize);
4028
+ },
4029
+ transform(t, transform, resize) {
4030
+ copy$2(matrix, t.localTransform);
4031
+ multiplyParent$2(matrix, transform);
4032
+ L.setTransform(t, matrix, resize);
4033
+ },
4034
+ setTransform(t, transform, resize) {
4035
+ const layout = getLayout(transform);
4036
+ if (resize) {
4037
+ t.scaleResize(layout.scaleX / t.scaleX, layout.scaleY / t.scaleY, resize !== true);
4038
+ delete layout.scaleX;
4039
+ delete layout.scaleY;
3968
4040
  }
3969
- }
3970
- getLocalBounds(type = 'box') {
3971
- switch (type) {
3972
- case 'render':
3973
- return this.localRenderBounds;
3974
- case 'stroke':
3975
- return this.localStrokeBounds;
3976
- case 'margin':
3977
- case 'content':
3978
- case 'box':
3979
- return this.leaf.__localBoxBounds;
4041
+ t.set(layout);
4042
+ },
4043
+ getRelativeWorld(t, relative, temp) {
4044
+ copy$2(matrix, t.worldTransform);
4045
+ divideParent(matrix, relative.worldTransform);
4046
+ return temp ? matrix : Object.assign({}, matrix);
4047
+ },
4048
+ drop(t, parent, index, resize) {
4049
+ t.setTransform(L.getRelativeWorld(t, parent, true), resize);
4050
+ parent.add(t, index);
4051
+ },
4052
+ hasParent(p, parent) {
4053
+ if (!parent)
4054
+ return false;
4055
+ while (p) {
4056
+ if (parent === p)
4057
+ return true;
4058
+ p = p.parent;
3980
4059
  }
3981
- }
3982
- getWorldBounds(type = 'box') {
3983
- switch (type) {
3984
- case 'render':
3985
- return this.leaf.__world;
3986
- case 'content':
3987
- if (this.contentBounds)
3988
- return this.getWorldContentBounds();
3989
- case 'margin':
3990
- case 'box':
3991
- return this.getWorldBoxBounds();
3992
- case 'margin':
3993
- case 'stroke':
3994
- return this.getWorldStrokeBounds();
4060
+ },
4061
+ hasParentAutoLayout(p) {
4062
+ while (p.parent) {
4063
+ p = p.parent;
4064
+ if (p.__hasAutoLayout)
4065
+ return true;
3995
4066
  }
3996
4067
  }
3997
- getLayoutBounds(type, relative = 'world', unscale) {
3998
- const { leaf } = this;
3999
- let point, matrix, bounds = this.getInnerBounds(type);
4000
- switch (relative) {
4001
- case 'world':
4002
- point = leaf.getWorldPoint(bounds);
4003
- matrix = leaf.__world;
4004
- break;
4005
- case 'local':
4068
+ };
4069
+ const L = LeafHelper;
4070
+ const { updateAllMatrix: updateAllMatrix$1, updateMatrix: updateMatrix$1, updateAllWorldOpacity, updateAllChange } = L;
4071
+ function moveByMatrix(t, matrix) {
4072
+ const { e, f } = t.__localMatrix;
4073
+ t.x += matrix.e - e;
4074
+ t.y += matrix.f - f;
4075
+ }
4076
+ function getTempLocal(t, world) {
4077
+ t.__layout.update();
4078
+ return t.parent ? PointHelper.tempToInnerOf(world, t.parent.__world) : world;
4079
+ }
4080
+
4081
+ const LeafBoundsHelper = {
4082
+ worldBounds(target) {
4083
+ return target.__world;
4084
+ },
4085
+ localBoxBounds(target) {
4086
+ return target.__.eraser ? null : (target.__local || target.__layout);
4087
+ },
4088
+ localStrokeBounds(target) {
4089
+ return target.__.eraser ? null : target.__layout.localStrokeBounds;
4090
+ },
4091
+ localRenderBounds(target) {
4092
+ return target.__.eraser ? null : target.__layout.localRenderBounds;
4093
+ },
4094
+ maskLocalBoxBounds(target) {
4095
+ return target.__.mask ? target.__localBoxBounds : null;
4096
+ },
4097
+ maskLocalStrokeBounds(target) {
4098
+ return target.__.mask ? target.__layout.localStrokeBounds : null;
4099
+ },
4100
+ maskLocalRenderBounds(target) {
4101
+ return target.__.mask ? target.__layout.localRenderBounds : null;
4102
+ },
4103
+ excludeRenderBounds(child, options) {
4104
+ if (options.bounds && !options.bounds.hit(child.__world, options.matrix))
4105
+ return true;
4106
+ if (options.hideBounds && options.hideBounds.includes(child.__world, options.matrix))
4107
+ return true;
4108
+ return false;
4109
+ }
4110
+ };
4111
+
4112
+ const { updateBounds: updateBounds$1 } = LeafHelper;
4113
+ const BranchHelper = {
4114
+ sort(a, b) {
4115
+ return (a.__.zIndex === b.__.zIndex) ? (a.__tempNumber - b.__tempNumber) : (a.__.zIndex - b.__.zIndex);
4116
+ },
4117
+ pushAllChildBranch(branch, leafList) {
4118
+ branch.__tempNumber = 1;
4119
+ if (branch.__.__childBranchNumber) {
4120
+ const { children } = branch;
4121
+ for (let i = 0, len = children.length; i < len; i++) {
4122
+ branch = children[i];
4123
+ if (branch.isBranch) {
4124
+ branch.__tempNumber = 1;
4125
+ leafList.add(branch);
4126
+ pushAllChildBranch(branch, leafList);
4127
+ }
4128
+ }
4129
+ }
4130
+ },
4131
+ pushAllParent(leaf, leafList) {
4132
+ const { keys } = leafList;
4133
+ if (keys) {
4134
+ while (leaf.parent) {
4135
+ if (keys[leaf.parent.innerId] === undefined) {
4136
+ leafList.add(leaf.parent);
4137
+ leaf = leaf.parent;
4138
+ }
4139
+ else {
4140
+ break;
4141
+ }
4142
+ }
4143
+ }
4144
+ else {
4145
+ while (leaf.parent) {
4146
+ leafList.add(leaf.parent);
4147
+ leaf = leaf.parent;
4148
+ }
4149
+ }
4150
+ },
4151
+ pushAllBranchStack(branch, pushList) {
4152
+ let start = pushList.length;
4153
+ const { children } = branch;
4154
+ for (let i = 0, len = children.length; i < len; i++) {
4155
+ if (children[i].isBranch) {
4156
+ pushList.push(children[i]);
4157
+ }
4158
+ }
4159
+ for (let i = start, len = pushList.length; i < len; i++) {
4160
+ pushAllBranchStack(pushList[i], pushList);
4161
+ }
4162
+ },
4163
+ updateBounds(branch, exclude) {
4164
+ const branchStack = [branch];
4165
+ pushAllBranchStack(branch, branchStack);
4166
+ updateBoundsByBranchStack(branchStack, exclude);
4167
+ },
4168
+ updateBoundsByBranchStack(branchStack, exclude) {
4169
+ let branch, children;
4170
+ for (let i = branchStack.length - 1; i > -1; i--) {
4171
+ branch = branchStack[i];
4172
+ children = branch.children;
4173
+ for (let j = 0, len = children.length; j < len; j++) {
4174
+ updateBounds$1(children[j]);
4175
+ }
4176
+ if (exclude && exclude === branch)
4177
+ continue;
4178
+ updateBounds$1(branch);
4179
+ }
4180
+ }
4181
+ };
4182
+ const { pushAllChildBranch, pushAllBranchStack, updateBoundsByBranchStack } = BranchHelper;
4183
+
4184
+ const WaitHelper = {
4185
+ run(wait) {
4186
+ if (wait.length) {
4187
+ const len = wait.length;
4188
+ for (let i = 0; i < len; i++) {
4189
+ wait[i]();
4190
+ }
4191
+ wait.length === len ? wait.length = 0 : wait.splice(0, len);
4192
+ }
4193
+ }
4194
+ };
4195
+
4196
+ const { getRelativeWorld: getRelativeWorld$1 } = LeafHelper;
4197
+ const { toOuterOf: toOuterOf$2, getPoints, copy: copy$1 } = BoundsHelper;
4198
+ class LeafLayout {
4199
+ get strokeBounds() { return this._strokeBounds || this.boxBounds; }
4200
+ get renderBounds() { return this._renderBounds || this.boxBounds; }
4201
+ get localStrokeBounds() { return this._localStrokeBounds || this; }
4202
+ get localRenderBounds() { return this._localRenderBounds || this; }
4203
+ get a() { return 1; }
4204
+ get b() { return 0; }
4205
+ get c() { return 0; }
4206
+ get d() { return 1; }
4207
+ get e() { return this.leaf.__.x; }
4208
+ get f() { return this.leaf.__.y; }
4209
+ get x() { return this.e + this.boxBounds.x; }
4210
+ get y() { return this.f + this.boxBounds.y; }
4211
+ get width() { return this.boxBounds.width; }
4212
+ get height() { return this.boxBounds.height; }
4213
+ constructor(leaf) {
4214
+ this.leaf = leaf;
4215
+ this.boxBounds = { x: 0, y: 0, width: 0, height: 0 };
4216
+ if (this.leaf.__local)
4217
+ this._localRenderBounds = this._localStrokeBounds = this.leaf.__local;
4218
+ this.boxChange();
4219
+ this.matrixChange();
4220
+ }
4221
+ createLocal() {
4222
+ const local = this.leaf.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 };
4223
+ if (!this._localStrokeBounds)
4224
+ this._localStrokeBounds = local;
4225
+ if (!this._localRenderBounds)
4226
+ this._localRenderBounds = local;
4227
+ }
4228
+ update() {
4229
+ const { leafer } = this.leaf;
4230
+ if (leafer) {
4231
+ if (leafer.ready) {
4232
+ if (leafer.watcher.changed)
4233
+ leafer.layouter.layout();
4234
+ }
4235
+ else {
4236
+ leafer.start();
4237
+ }
4238
+ }
4239
+ else {
4240
+ let root = this.leaf;
4241
+ while (root.parent && !root.parent.leafer) {
4242
+ root = root.parent;
4243
+ }
4244
+ Platform.layout(root);
4245
+ }
4246
+ }
4247
+ getTransform(relative = 'world') {
4248
+ this.update();
4249
+ const { leaf } = this;
4250
+ switch (relative) {
4251
+ case 'world':
4252
+ return leaf.__world;
4253
+ case 'local':
4254
+ return leaf.__localMatrix;
4255
+ case 'inner':
4256
+ return MatrixHelper.defaultMatrix;
4257
+ case 'page':
4258
+ relative = leaf.zoomLayer;
4259
+ default:
4260
+ return getRelativeWorld$1(leaf, relative);
4261
+ }
4262
+ }
4263
+ getBounds(type, relative = 'world') {
4264
+ this.update();
4265
+ switch (relative) {
4266
+ case 'world':
4267
+ return this.getWorldBounds(type);
4268
+ case 'local':
4269
+ return this.getLocalBounds(type);
4270
+ case 'inner':
4271
+ return this.getInnerBounds(type);
4272
+ case 'page':
4273
+ relative = this.leaf.zoomLayer;
4274
+ default:
4275
+ return new Bounds(this.getInnerBounds(type)).toOuterOf(this.getTransform(relative));
4276
+ }
4277
+ }
4278
+ getInnerBounds(type = 'box') {
4279
+ switch (type) {
4280
+ case 'render':
4281
+ return this.renderBounds;
4282
+ case 'content':
4283
+ if (this.contentBounds)
4284
+ return this.contentBounds;
4285
+ case 'margin':
4286
+ case 'box':
4287
+ return this.boxBounds;
4288
+ case 'stroke':
4289
+ return this.strokeBounds;
4290
+ }
4291
+ }
4292
+ getLocalBounds(type = 'box') {
4293
+ switch (type) {
4294
+ case 'render':
4295
+ return this.localRenderBounds;
4296
+ case 'stroke':
4297
+ return this.localStrokeBounds;
4298
+ case 'margin':
4299
+ case 'content':
4300
+ case 'box':
4301
+ return this.leaf.__localBoxBounds;
4302
+ }
4303
+ }
4304
+ getWorldBounds(type = 'box') {
4305
+ switch (type) {
4306
+ case 'render':
4307
+ return this.leaf.__world;
4308
+ case 'content':
4309
+ if (this.contentBounds)
4310
+ return this.getWorldContentBounds();
4311
+ case 'margin':
4312
+ case 'box':
4313
+ return this.getWorldBoxBounds();
4314
+ case 'margin':
4315
+ case 'stroke':
4316
+ return this.getWorldStrokeBounds();
4317
+ }
4318
+ }
4319
+ getLayoutBounds(type, relative = 'world', unscale) {
4320
+ const { leaf } = this;
4321
+ let point, matrix, bounds = this.getInnerBounds(type);
4322
+ switch (relative) {
4323
+ case 'world':
4324
+ point = leaf.getWorldPoint(bounds);
4325
+ matrix = leaf.__world;
4326
+ break;
4327
+ case 'local':
4006
4328
  point = leaf.getLocalPointByInner(bounds);
4007
4329
  matrix = leaf.__localMatrix;
4008
4330
  break;
@@ -4010,12 +4332,14 @@ class LeafLayout {
4010
4332
  point = bounds;
4011
4333
  matrix = MatrixHelper.defaultMatrix;
4012
4334
  break;
4335
+ case 'page':
4336
+ relative = leaf.zoomLayer;
4013
4337
  default:
4014
4338
  point = leaf.getWorldPoint(bounds, relative);
4015
- matrix = tempMatrix.set(leaf.__world).divideParent(relative.__world);
4339
+ matrix = getRelativeWorld$1(leaf, relative, true);
4016
4340
  }
4017
4341
  const layoutBounds = MatrixHelper.getLayout(matrix);
4018
- copy$2(layoutBounds, bounds);
4342
+ copy$1(layoutBounds, bounds);
4019
4343
  PointHelper.copy(layoutBounds, point);
4020
4344
  if (unscale) {
4021
4345
  const { scaleX, scaleY } = layoutBounds;
@@ -4043,6 +4367,8 @@ class LeafLayout {
4043
4367
  break;
4044
4368
  case 'inner':
4045
4369
  break;
4370
+ case 'page':
4371
+ relative = leaf.zoomLayer;
4046
4372
  default:
4047
4373
  relativeLeaf = relative;
4048
4374
  }
@@ -4303,438 +4629,166 @@ class PropertyEvent extends Event {
4303
4629
  this.newValue = newValue;
4304
4630
  }
4305
4631
  }
4306
- PropertyEvent.CHANGE = 'property.change';
4307
- PropertyEvent.LEAFER_CHANGE = 'property.leafer_change';
4308
-
4309
- class ImageEvent extends Event {
4310
- constructor(type, data) {
4311
- super(type);
4312
- Object.assign(this, data);
4313
- }
4314
- }
4315
- ImageEvent.LOAD = 'image.load';
4316
- ImageEvent.LOADED = 'image.loaded';
4317
- ImageEvent.ERROR = 'image.error';
4318
-
4319
- class ResizeEvent extends Event {
4320
- get bigger() {
4321
- if (!this.old)
4322
- return true;
4323
- const { width, height } = this.old;
4324
- return this.width >= width && this.height >= height;
4325
- }
4326
- get smaller() {
4327
- return !this.bigger;
4328
- }
4329
- get samePixelRatio() {
4330
- if (!this.old)
4331
- return true;
4332
- return this.pixelRatio === this.old.pixelRatio;
4333
- }
4334
- constructor(size, oldSize) {
4335
- if (typeof size === 'object') {
4336
- super(ResizeEvent.RESIZE);
4337
- Object.assign(this, size);
4338
- }
4339
- else {
4340
- super(size);
4341
- }
4342
- this.old = oldSize;
4343
- }
4344
- }
4345
- ResizeEvent.RESIZE = 'resize';
4346
-
4347
- class WatchEvent extends Event {
4348
- constructor(type, data) {
4349
- super(type);
4350
- this.data = data;
4351
- }
4352
- }
4353
- WatchEvent.REQUEST = 'watch.request';
4354
- WatchEvent.DATA = 'watch.data';
4355
-
4356
- class LayoutEvent extends Event {
4357
- constructor(type, data, times) {
4358
- super(type);
4359
- if (data) {
4360
- this.data = data;
4361
- this.times = times;
4362
- }
4363
- }
4364
- }
4365
- LayoutEvent.CHECK_UPDATE = 'layout.check_update';
4366
- LayoutEvent.REQUEST = 'layout.request';
4367
- LayoutEvent.START = 'layout.start';
4368
- LayoutEvent.BEFORE = 'layout.before';
4369
- LayoutEvent.LAYOUT = 'layout';
4370
- LayoutEvent.AFTER = 'layout.after';
4371
- LayoutEvent.AGAIN = 'layout.again';
4372
- LayoutEvent.END = 'layout.end';
4373
-
4374
- class AnimateEvent extends Event {
4375
- }
4376
- AnimateEvent.FRAME = 'animate.frame';
4377
-
4378
- class RenderEvent extends Event {
4379
- constructor(type, times, bounds, options) {
4380
- super(type);
4381
- if (times)
4382
- this.times = times;
4383
- if (bounds) {
4384
- this.renderBounds = bounds;
4385
- this.renderOptions = options;
4386
- }
4387
- }
4388
- }
4389
- RenderEvent.REQUEST = 'render.request';
4390
- RenderEvent.START = 'render.start';
4391
- RenderEvent.BEFORE = 'render.before';
4392
- RenderEvent.RENDER = 'render';
4393
- RenderEvent.AFTER = 'render.after';
4394
- RenderEvent.AGAIN = 'render.again';
4395
- RenderEvent.END = 'render.end';
4396
- RenderEvent.NEXT = 'render.next';
4397
-
4398
- class LeaferEvent extends Event {
4399
- }
4400
- LeaferEvent.START = 'leafer.start';
4401
- LeaferEvent.BEFORE_READY = 'leafer.before_ready';
4402
- LeaferEvent.READY = 'leafer.ready';
4403
- LeaferEvent.AFTER_READY = 'leafer.after_ready';
4404
- LeaferEvent.VIEW_READY = 'leafer.view_ready';
4405
- LeaferEvent.VIEW_COMPLETED = 'leafer.view_completed';
4406
- LeaferEvent.STOP = 'leafer.stop';
4407
- LeaferEvent.RESTART = 'leafer.restart';
4408
- LeaferEvent.END = 'leafer.end';
4409
-
4410
- const LeafDataProxy = {
4411
- __setAttr(name, newValue) {
4412
- if (this.leafer && this.leafer.created) {
4413
- const oldValue = this.__.__getInput(name);
4414
- if (typeof newValue === 'object' || oldValue !== newValue) {
4415
- this.__[name] = newValue;
4416
- if (this.__proxyData)
4417
- this.setProxyAttr(name, newValue);
4418
- const { CHANGE } = PropertyEvent;
4419
- const event = new PropertyEvent(CHANGE, this, name, oldValue, newValue);
4420
- if (this.isLeafer) {
4421
- this.emitEvent(new PropertyEvent(PropertyEvent.LEAFER_CHANGE, this, name, oldValue, newValue));
4422
- }
4423
- else {
4424
- if (this.hasEvent(CHANGE))
4425
- this.emitEvent(event);
4426
- }
4427
- this.leafer.emitEvent(event);
4428
- }
4429
- }
4430
- else {
4431
- this.__[name] = newValue;
4432
- if (this.__proxyData)
4433
- this.setProxyAttr(name, newValue);
4434
- }
4435
- },
4436
- __getAttr(name) {
4437
- if (this.__proxyData)
4438
- return this.getProxyAttr(name);
4439
- return this.__.__get(name);
4440
- }
4441
- };
4442
-
4443
- const { setLayout, multiplyParent: multiplyParent$2, translateInner, defaultWorld } = MatrixHelper;
4444
- const { toPoint, tempPoint } = AroundHelper;
4445
- const LeafMatrix = {
4446
- __updateWorldMatrix() {
4447
- multiplyParent$2(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__);
4448
- },
4449
- __updateLocalMatrix() {
4450
- if (this.__local) {
4451
- const layout = this.__layout, local = this.__local, data = this.__;
4452
- if (layout.affectScaleOrRotation) {
4453
- if (layout.scaleChanged || layout.rotationChanged) {
4454
- setLayout(local, data, null, layout.affectRotation);
4455
- layout.scaleChanged = layout.rotationChanged = false;
4456
- }
4457
- }
4458
- local.e = data.x;
4459
- local.f = data.y;
4460
- if (data.around) {
4461
- toPoint(data.around, layout.boxBounds, tempPoint);
4462
- translateInner(local, -tempPoint.x, -tempPoint.y);
4463
- }
4464
- }
4465
- this.__layout.matrixChanged = false;
4466
- }
4467
- };
4468
-
4469
- const { copy: copy$1, toInnerPoint: toInnerPoint$1, scaleOfOuter, rotateOfOuter, skewOfOuter, multiplyParent: multiplyParent$1, divideParent, getLayout } = MatrixHelper;
4470
- const matrix = {};
4471
- const LeafHelper = {
4472
- updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
4473
- if (checkAutoLayout && leaf.__hasAutoLayout && leaf.__layout.matrixChanged)
4474
- waitAutoLayout = true;
4475
- updateMatrix$1(leaf, checkAutoLayout, waitAutoLayout);
4476
- if (leaf.isBranch) {
4477
- const { children } = leaf;
4478
- for (let i = 0, len = children.length; i < len; i++) {
4479
- updateAllMatrix$1(children[i], checkAutoLayout, waitAutoLayout);
4480
- }
4481
- }
4482
- },
4483
- updateMatrix(leaf, checkAutoLayout, waitAutoLayout) {
4484
- const layout = leaf.__layout;
4485
- if (checkAutoLayout) {
4486
- if (waitAutoLayout) {
4487
- layout.waitAutoLayout = true;
4488
- if (leaf.__hasAutoLayout)
4489
- layout.matrixChanged = false;
4490
- }
4491
- }
4492
- else if (layout.waitAutoLayout) {
4493
- layout.waitAutoLayout = false;
4494
- }
4495
- if (layout.matrixChanged)
4496
- leaf.__updateLocalMatrix();
4497
- if (!layout.waitAutoLayout)
4498
- leaf.__updateWorldMatrix();
4499
- },
4500
- updateBounds(leaf) {
4501
- const layout = leaf.__layout;
4502
- if (layout.boundsChanged)
4503
- leaf.__updateLocalBounds();
4504
- if (!layout.waitAutoLayout)
4505
- leaf.__updateWorldBounds();
4506
- },
4507
- updateAllWorldOpacity(leaf) {
4508
- leaf.__updateWorldOpacity();
4509
- if (leaf.isBranch) {
4510
- const { children } = leaf;
4511
- for (let i = 0, len = children.length; i < len; i++) {
4512
- updateAllWorldOpacity(children[i]);
4513
- }
4514
- }
4515
- },
4516
- updateAllChange(leaf) {
4517
- updateAllWorldOpacity(leaf);
4518
- leaf.__updateChange();
4519
- if (leaf.isBranch) {
4520
- const { children } = leaf;
4521
- for (let i = 0, len = children.length; i < len; i++) {
4522
- updateAllChange(children[i]);
4523
- }
4524
- }
4525
- },
4526
- worldHittable(t) {
4527
- while (t) {
4528
- if (!t.__.hittable)
4529
- return false;
4530
- t = t.parent;
4531
- }
4532
- return true;
4533
- },
4534
- moveWorld(t, x, y) {
4535
- const local = { x, y };
4536
- if (t.parent)
4537
- toInnerPoint$1(t.parent.worldTransform, local, local, true);
4538
- L.moveLocal(t, local.x, local.y);
4539
- },
4540
- moveLocal(t, x, y = 0) {
4541
- t.x += x;
4542
- t.y += y;
4543
- },
4544
- zoomOfWorld(t, origin, scaleX, scaleY, resize) {
4545
- L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
4546
- },
4547
- zoomOfLocal(t, origin, scaleX, scaleY = scaleX, resize) {
4548
- copy$1(matrix, t.__localMatrix);
4549
- scaleOfOuter(matrix, origin, scaleX, scaleY);
4550
- moveByMatrix(t, matrix);
4551
- t.scaleResize(scaleX, scaleY, resize !== true);
4552
- },
4553
- rotateOfWorld(t, origin, angle) {
4554
- L.rotateOfLocal(t, getTempLocal(t, origin), angle);
4555
- },
4556
- rotateOfLocal(t, origin, angle) {
4557
- copy$1(matrix, t.__localMatrix);
4558
- rotateOfOuter(matrix, origin, angle);
4559
- moveByMatrix(t, matrix);
4560
- t.rotation = MathHelper.formatRotation(t.rotation + angle);
4561
- },
4562
- skewOfWorld(t, origin, skewX, skewY, resize) {
4563
- L.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY, resize);
4564
- },
4565
- skewOfLocal(t, origin, skewX, skewY = 0, resize) {
4566
- copy$1(matrix, t.__localMatrix);
4567
- skewOfOuter(matrix, origin, skewX, skewY);
4568
- L.setTransform(t, matrix, resize);
4569
- },
4570
- transformWorld(t, transform, resize) {
4571
- copy$1(matrix, t.worldTransform);
4572
- multiplyParent$1(matrix, transform);
4573
- if (t.parent)
4574
- divideParent(matrix, t.parent.worldTransform);
4575
- L.setTransform(t, matrix, resize);
4576
- },
4577
- transform(t, transform, resize) {
4578
- copy$1(matrix, t.localTransform);
4579
- multiplyParent$1(matrix, transform);
4580
- L.setTransform(t, matrix, resize);
4581
- },
4582
- setTransform(t, transform, resize) {
4583
- const layout = getLayout(transform);
4584
- if (resize) {
4585
- t.scaleResize(layout.scaleX / t.scaleX, layout.scaleY / t.scaleY, resize !== true);
4586
- delete layout.scaleX;
4587
- delete layout.scaleY;
4588
- }
4589
- t.set(layout);
4590
- },
4591
- drop(t, parent, index, resize) {
4592
- copy$1(matrix, t.worldTransform);
4593
- divideParent(matrix, parent.worldTransform);
4594
- t.setTransform(matrix, resize);
4595
- parent.add(t, index);
4596
- },
4597
- hasParent(p, parent) {
4598
- if (!parent)
4599
- return false;
4600
- while (p) {
4601
- if (parent === p)
4602
- return true;
4603
- p = p.parent;
4604
- }
4605
- },
4606
- hasParentAutoLayout(p) {
4607
- while (p.parent) {
4608
- p = p.parent;
4609
- if (p.__hasAutoLayout)
4610
- return true;
4611
- }
4612
- }
4613
- };
4614
- const L = LeafHelper;
4615
- const { updateAllMatrix: updateAllMatrix$1, updateMatrix: updateMatrix$1, updateAllWorldOpacity, updateAllChange } = L;
4616
- function moveByMatrix(t, matrix) {
4617
- const { e, f } = t.__localMatrix;
4618
- t.x += matrix.e - e;
4619
- t.y += matrix.f - f;
4620
- }
4621
- function getTempLocal(t, world) {
4622
- t.__layout.update();
4623
- return t.parent ? PointHelper.tempToInnerOf(world, t.parent.__world) : world;
4632
+ PropertyEvent.CHANGE = 'property.change';
4633
+ PropertyEvent.LEAFER_CHANGE = 'property.leafer_change';
4634
+
4635
+ class ImageEvent extends Event {
4636
+ constructor(type, data) {
4637
+ super(type);
4638
+ Object.assign(this, data);
4639
+ }
4624
4640
  }
4641
+ ImageEvent.LOAD = 'image.load';
4642
+ ImageEvent.LOADED = 'image.loaded';
4643
+ ImageEvent.ERROR = 'image.error';
4625
4644
 
4626
- const LeafBoundsHelper = {
4627
- worldBounds(target) {
4628
- return target.__world;
4629
- },
4630
- localBoxBounds(target) {
4631
- return target.__.eraser ? null : (target.__local || target.__layout);
4632
- },
4633
- localStrokeBounds(target) {
4634
- return target.__.eraser ? null : target.__layout.localStrokeBounds;
4635
- },
4636
- localRenderBounds(target) {
4637
- return target.__.eraser ? null : target.__layout.localRenderBounds;
4638
- },
4639
- maskLocalBoxBounds(target) {
4640
- return target.__.mask ? target.__localBoxBounds : null;
4641
- },
4642
- maskLocalStrokeBounds(target) {
4643
- return target.__.mask ? target.__layout.localStrokeBounds : null;
4644
- },
4645
- maskLocalRenderBounds(target) {
4646
- return target.__.mask ? target.__layout.localRenderBounds : null;
4647
- },
4648
- excludeRenderBounds(child, options) {
4649
- if (options.bounds && !options.bounds.hit(child.__world, options.matrix))
4645
+ class ResizeEvent extends Event {
4646
+ get bigger() {
4647
+ if (!this.old)
4650
4648
  return true;
4651
- if (options.hideBounds && options.hideBounds.includes(child.__world, options.matrix))
4649
+ const { width, height } = this.old;
4650
+ return this.width >= width && this.height >= height;
4651
+ }
4652
+ get smaller() {
4653
+ return !this.bigger;
4654
+ }
4655
+ get samePixelRatio() {
4656
+ if (!this.old)
4652
4657
  return true;
4653
- return false;
4658
+ return this.pixelRatio === this.old.pixelRatio;
4654
4659
  }
4655
- };
4660
+ constructor(size, oldSize) {
4661
+ if (typeof size === 'object') {
4662
+ super(ResizeEvent.RESIZE);
4663
+ Object.assign(this, size);
4664
+ }
4665
+ else {
4666
+ super(size);
4667
+ }
4668
+ this.old = oldSize;
4669
+ }
4670
+ }
4671
+ ResizeEvent.RESIZE = 'resize';
4656
4672
 
4657
- const { updateBounds: updateBounds$1 } = LeafHelper;
4658
- const BranchHelper = {
4659
- sort(a, b) {
4660
- return (a.__.zIndex === b.__.zIndex) ? (a.__tempNumber - b.__tempNumber) : (a.__.zIndex - b.__.zIndex);
4661
- },
4662
- pushAllChildBranch(branch, leafList) {
4663
- branch.__tempNumber = 1;
4664
- if (branch.__.__childBranchNumber) {
4665
- const { children } = branch;
4666
- for (let i = 0, len = children.length; i < len; i++) {
4667
- branch = children[i];
4668
- if (branch.isBranch) {
4669
- branch.__tempNumber = 1;
4670
- leafList.add(branch);
4671
- pushAllChildBranch(branch, leafList);
4672
- }
4673
- }
4673
+ class WatchEvent extends Event {
4674
+ constructor(type, data) {
4675
+ super(type);
4676
+ this.data = data;
4677
+ }
4678
+ }
4679
+ WatchEvent.REQUEST = 'watch.request';
4680
+ WatchEvent.DATA = 'watch.data';
4681
+
4682
+ class LayoutEvent extends Event {
4683
+ constructor(type, data, times) {
4684
+ super(type);
4685
+ if (data) {
4686
+ this.data = data;
4687
+ this.times = times;
4674
4688
  }
4675
- },
4676
- pushAllParent(leaf, leafList) {
4677
- const { keys } = leafList;
4678
- if (keys) {
4679
- while (leaf.parent) {
4680
- if (keys[leaf.parent.innerId] === undefined) {
4681
- leafList.add(leaf.parent);
4682
- leaf = leaf.parent;
4689
+ }
4690
+ }
4691
+ LayoutEvent.CHECK_UPDATE = 'layout.check_update';
4692
+ LayoutEvent.REQUEST = 'layout.request';
4693
+ LayoutEvent.START = 'layout.start';
4694
+ LayoutEvent.BEFORE = 'layout.before';
4695
+ LayoutEvent.LAYOUT = 'layout';
4696
+ LayoutEvent.AFTER = 'layout.after';
4697
+ LayoutEvent.AGAIN = 'layout.again';
4698
+ LayoutEvent.END = 'layout.end';
4699
+
4700
+ class AnimateEvent extends Event {
4701
+ }
4702
+ AnimateEvent.FRAME = 'animate.frame';
4703
+
4704
+ class RenderEvent extends Event {
4705
+ constructor(type, times, bounds, options) {
4706
+ super(type);
4707
+ if (times)
4708
+ this.times = times;
4709
+ if (bounds) {
4710
+ this.renderBounds = bounds;
4711
+ this.renderOptions = options;
4712
+ }
4713
+ }
4714
+ }
4715
+ RenderEvent.REQUEST = 'render.request';
4716
+ RenderEvent.START = 'render.start';
4717
+ RenderEvent.BEFORE = 'render.before';
4718
+ RenderEvent.RENDER = 'render';
4719
+ RenderEvent.AFTER = 'render.after';
4720
+ RenderEvent.AGAIN = 'render.again';
4721
+ RenderEvent.END = 'render.end';
4722
+ RenderEvent.NEXT = 'render.next';
4723
+
4724
+ class LeaferEvent extends Event {
4725
+ }
4726
+ LeaferEvent.START = 'leafer.start';
4727
+ LeaferEvent.BEFORE_READY = 'leafer.before_ready';
4728
+ LeaferEvent.READY = 'leafer.ready';
4729
+ LeaferEvent.AFTER_READY = 'leafer.after_ready';
4730
+ LeaferEvent.VIEW_READY = 'leafer.view_ready';
4731
+ LeaferEvent.VIEW_COMPLETED = 'leafer.view_completed';
4732
+ LeaferEvent.STOP = 'leafer.stop';
4733
+ LeaferEvent.RESTART = 'leafer.restart';
4734
+ LeaferEvent.END = 'leafer.end';
4735
+
4736
+ const LeafDataProxy = {
4737
+ __setAttr(name, newValue) {
4738
+ if (this.leafer && this.leafer.created) {
4739
+ const oldValue = this.__.__getInput(name);
4740
+ if (typeof newValue === 'object' || oldValue !== newValue) {
4741
+ this.__[name] = newValue;
4742
+ if (this.__proxyData)
4743
+ this.setProxyAttr(name, newValue);
4744
+ const { CHANGE } = PropertyEvent;
4745
+ const event = new PropertyEvent(CHANGE, this, name, oldValue, newValue);
4746
+ if (this.isLeafer) {
4747
+ this.emitEvent(new PropertyEvent(PropertyEvent.LEAFER_CHANGE, this, name, oldValue, newValue));
4683
4748
  }
4684
4749
  else {
4685
- break;
4750
+ if (this.hasEvent(CHANGE))
4751
+ this.emitEvent(event);
4686
4752
  }
4753
+ this.leafer.emitEvent(event);
4687
4754
  }
4688
4755
  }
4689
4756
  else {
4690
- while (leaf.parent) {
4691
- leafList.add(leaf.parent);
4692
- leaf = leaf.parent;
4693
- }
4694
- }
4695
- },
4696
- pushAllBranchStack(branch, pushList) {
4697
- let start = pushList.length;
4698
- const { children } = branch;
4699
- for (let i = 0, len = children.length; i < len; i++) {
4700
- if (children[i].isBranch) {
4701
- pushList.push(children[i]);
4702
- }
4703
- }
4704
- for (let i = start, len = pushList.length; i < len; i++) {
4705
- pushAllBranchStack(pushList[i], pushList);
4757
+ this.__[name] = newValue;
4758
+ if (this.__proxyData)
4759
+ this.setProxyAttr(name, newValue);
4706
4760
  }
4707
4761
  },
4708
- updateBounds(branch, exclude) {
4709
- const branchStack = [branch];
4710
- pushAllBranchStack(branch, branchStack);
4711
- updateBoundsByBranchStack(branchStack, exclude);
4712
- },
4713
- updateBoundsByBranchStack(branchStack, exclude) {
4714
- let branch, children;
4715
- for (let i = branchStack.length - 1; i > -1; i--) {
4716
- branch = branchStack[i];
4717
- children = branch.children;
4718
- for (let j = 0, len = children.length; j < len; j++) {
4719
- updateBounds$1(children[j]);
4720
- }
4721
- if (exclude && exclude === branch)
4722
- continue;
4723
- updateBounds$1(branch);
4724
- }
4762
+ __getAttr(name) {
4763
+ if (this.__proxyData)
4764
+ return this.getProxyAttr(name);
4765
+ return this.__.__get(name);
4725
4766
  }
4726
4767
  };
4727
- const { pushAllChildBranch, pushAllBranchStack, updateBoundsByBranchStack } = BranchHelper;
4728
4768
 
4729
- const WaitHelper = {
4730
- run(wait) {
4731
- if (wait.length) {
4732
- const len = wait.length;
4733
- for (let i = 0; i < len; i++) {
4734
- wait[i]();
4769
+ const { setLayout, multiplyParent: multiplyParent$1, translateInner, defaultWorld } = MatrixHelper;
4770
+ const { toPoint, tempPoint } = AroundHelper;
4771
+ const LeafMatrix = {
4772
+ __updateWorldMatrix() {
4773
+ multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__);
4774
+ },
4775
+ __updateLocalMatrix() {
4776
+ if (this.__local) {
4777
+ const layout = this.__layout, local = this.__local, data = this.__;
4778
+ if (layout.affectScaleOrRotation) {
4779
+ if (layout.scaleChanged || layout.rotationChanged) {
4780
+ setLayout(local, data, null, layout.affectRotation);
4781
+ layout.scaleChanged = layout.rotationChanged = false;
4782
+ }
4783
+ }
4784
+ local.e = data.x;
4785
+ local.f = data.y;
4786
+ if (data.around) {
4787
+ toPoint(data.around, layout.boxBounds, tempPoint);
4788
+ translateInner(local, -tempPoint.x, -tempPoint.y);
4735
4789
  }
4736
- wait.length === len ? wait.length = 0 : wait.splice(0, len);
4737
4790
  }
4791
+ this.__layout.matrixChanged = false;
4738
4792
  }
4739
4793
  };
4740
4794
 
@@ -4951,7 +5005,7 @@ const { LEAF, create } = IncrementId;
4951
5005
  const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper;
4952
5006
  const { toOuterOf } = BoundsHelper;
4953
5007
  const { tempToOuterOf, copy } = PointHelper;
4954
- const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, transform, setTransform, drop } = LeafHelper;
5008
+ const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getRelativeWorld, drop } = LeafHelper;
4955
5009
  let Leaf = class Leaf {
4956
5010
  get tag() { return this.__tag; }
4957
5011
  set tag(_value) { }
@@ -4989,21 +5043,31 @@ let Leaf = class Leaf {
4989
5043
  this.__layout = new this.__LayoutProcessor(this);
4990
5044
  if (this.__level)
4991
5045
  this.resetCustom();
4992
- if (data)
5046
+ if (data) {
5047
+ if (data.__)
5048
+ data = data.toJSON();
4993
5049
  data.children ? this.set(data) : Object.assign(this, data);
5050
+ }
4994
5051
  }
4995
5052
  resetCustom() {
4996
5053
  this.__hasMask = this.__hasEraser = null;
4997
5054
  this.forceUpdate();
4998
5055
  }
4999
- waitParent(item) {
5056
+ waitParent(item, bind) {
5057
+ if (bind)
5058
+ item = item.bind(bind);
5000
5059
  this.parent ? item() : (this.__parentWait ? this.__parentWait.push(item) : this.__parentWait = [item]);
5001
5060
  }
5002
- waitLeafer(item) {
5061
+ waitLeafer(item, bind) {
5062
+ if (bind)
5063
+ item = item.bind(bind);
5003
5064
  this.leafer ? item() : (this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item]);
5004
5065
  }
5005
- nextRender(item, off) {
5006
- this.leafer ? this.leafer.nextRender(item, off) : this.waitLeafer(() => this.leafer.nextRender(item, off));
5066
+ nextRender(item, bind, off) {
5067
+ this.leafer ? this.leafer.nextRender(item, bind, off) : this.waitLeafer(() => this.leafer.nextRender(item, bind, off));
5068
+ }
5069
+ removeNextRender(item) {
5070
+ this.nextRender(item, null, 'off');
5007
5071
  }
5008
5072
  __bindLeafer(leafer) {
5009
5073
  if (this.isLeafer) {
@@ -5040,6 +5104,7 @@ let Leaf = class Leaf {
5040
5104
  getProxyAttr(_attrName) { return undefined; }
5041
5105
  find(_condition, _options) { return undefined; }
5042
5106
  findOne(_condition, _options) { return undefined; }
5107
+ focus(_value) { }
5043
5108
  forceUpdate(attrName) {
5044
5109
  if (attrName === undefined)
5045
5110
  attrName = 'width';
@@ -5095,6 +5160,9 @@ let Leaf = class Leaf {
5095
5160
  return this.__world.f;
5096
5161
  return this.getLayoutBounds()[attrName];
5097
5162
  }
5163
+ getTransform(relative) {
5164
+ return this.__layout.getTransform(relative || 'local');
5165
+ }
5098
5166
  getBounds(type, relative) {
5099
5167
  return this.__layout.getBounds(type, relative);
5100
5168
  }
@@ -5104,6 +5172,12 @@ let Leaf = class Leaf {
5104
5172
  getLayoutPoints(type, relative) {
5105
5173
  return this.__layout.getLayoutPoints(type, relative);
5106
5174
  }
5175
+ getWorldBounds(inner, relative, change) {
5176
+ const matrix = relative ? getRelativeWorld(this, relative) : this.worldTransform;
5177
+ const to = change ? inner : {};
5178
+ toOuterOf(inner, matrix, to);
5179
+ return to;
5180
+ }
5107
5181
  worldToLocal(world, to, distance, relative) {
5108
5182
  if (this.parent) {
5109
5183
  this.parent.worldToInner(world, to, distance, relative);
@@ -5186,6 +5260,21 @@ let Leaf = class Leaf {
5186
5260
  skewOf(origin, skewX, skewY, resize) {
5187
5261
  skewOfLocal(this, tempToOuterOf(origin, this.localTransform), skewX, skewY, resize);
5188
5262
  }
5263
+ transformWorld(worldTransform, resize) {
5264
+ transformWorld(this, worldTransform, resize);
5265
+ }
5266
+ moveWorld(x, y) {
5267
+ moveWorld(this, x, y);
5268
+ }
5269
+ scaleOfWorld(worldOrigin, scaleX, scaleY, resize) {
5270
+ zoomOfWorld(this, worldOrigin, scaleX, scaleY, resize);
5271
+ }
5272
+ rotateOfWorld(worldOrigin, rotation) {
5273
+ rotateOfWorld(this, worldOrigin, rotation);
5274
+ }
5275
+ skewOfWorld(worldOrigin, skewX, skewY, resize) {
5276
+ skewOfWorld(this, worldOrigin, skewX, skewY, resize);
5277
+ }
5189
5278
  scaleResize(scaleX, scaleY = scaleX, _noResize) {
5190
5279
  this.scaleX *= scaleX;
5191
5280
  this.scaleY *= scaleY;
@@ -5317,7 +5406,8 @@ let Branch = class Branch extends Leaf {
5317
5406
  index === undefined ? this.children.push(child) : this.children.splice(index, 0, child);
5318
5407
  if (child.isBranch)
5319
5408
  this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
5320
- child.__layout.boundsChanged || child.__layout.matrixChange();
5409
+ child.__layout.boxChanged || child.__layout.boxChange();
5410
+ child.__layout.matrixChanged || child.__layout.matrixChange();
5321
5411
  if (child.__parentWait)
5322
5412
  WaitHelper.run(child.__parentWait);
5323
5413
  if (this.leafer) {
@@ -5548,4 +5638,4 @@ class LeafLevelList {
5548
5638
  }
5549
5639
  }
5550
5640
 
5551
- export { 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, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, useModule };
5641
+ export { 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, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, useModule };