@leafer-in/resize 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/resize.cjs CHANGED
@@ -13,9 +13,6 @@ const PathScaler = {
13
13
  command = data[i];
14
14
  switch (command) {
15
15
  case M:
16
- scalePoints(data, scaleX, scaleY, i, 1);
17
- i += 3;
18
- break;
19
16
  case L:
20
17
  scalePoints(data, scaleX, scaleY, i, 1);
21
18
  i += 3;
@@ -82,6 +79,7 @@ const PathScaler = {
82
79
  const { scalePoints } = PathScaler;
83
80
 
84
81
  const matrix = draw.MatrixHelper.get();
82
+ const { topLeft, top, topRight, right, bottom, left } = draw.Direction9;
85
83
  function scaleResize(leaf, scaleX, scaleY) {
86
84
  if (leaf.pathInputed) {
87
85
  scaleResizePath(leaf, scaleX, scaleY);
@@ -94,15 +92,36 @@ function scaleResize(leaf, scaleX, scaleY) {
94
92
  }
95
93
  }
96
94
  function scaleResizeFontSize(leaf, scaleX, scaleY) {
97
- const { width, height } = leaf.__localBoxBounds;
98
- if (scaleX !== 1) {
99
- leaf.fontSize *= scaleX;
100
- leaf.y -= height * (scaleX - scaleY) / 2;
101
- }
102
- else if (scaleY !== 1) {
103
- leaf.fontSize *= scaleY;
104
- leaf.x -= width * (scaleY - scaleX) / 2;
95
+ const { app } = leaf;
96
+ const editor = app && app.editor;
97
+ let fontScale = scaleX;
98
+ if (editor.editing) {
99
+ const layout = leaf.__layout;
100
+ let { width, height } = layout.boxBounds;
101
+ width *= scaleY - scaleX;
102
+ height *= scaleX - scaleY;
103
+ switch (editor.resizeDirection) {
104
+ case top:
105
+ case bottom:
106
+ fontScale = scaleY;
107
+ layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
108
+ break;
109
+ case left:
110
+ case right:
111
+ layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
112
+ break;
113
+ case topLeft:
114
+ case topRight:
115
+ layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
116
+ break;
117
+ }
105
118
  }
119
+ leaf.fontSize *= fontScale;
120
+ const data = leaf.__;
121
+ if (!data.__autoWidth)
122
+ leaf.width *= fontScale;
123
+ if (!data.__autoHeight)
124
+ leaf.height *= fontScale;
106
125
  }
107
126
  function scaleResizePath(leaf, scaleX, scaleY) {
108
127
  PathScaler.scale(leaf.__.path, scaleX, scaleY);
@@ -148,7 +167,7 @@ leaf.resizeHeight = function (height) {
148
167
  this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
149
168
  };
150
169
  draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
151
- if (this.__.__autoSize && (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size'))) {
170
+ if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
152
171
  scaleResizeFontSize(this, scaleX, scaleY);
153
172
  }
154
173
  else {
@@ -1,4 +1,4 @@
1
- import { PathCommandMap, MatrixHelper, Leaf, Text, Path, Line, Polygon, Group, Box } from '@leafer-ui/draw';
1
+ import { PathCommandMap, MatrixHelper, Direction9, Leaf, Text, Path, Line, Polygon, Group, Box } from '@leafer-ui/draw';
2
2
 
3
3
  const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = PathCommandMap;
4
4
  const PathScaler = {
@@ -11,9 +11,6 @@ const PathScaler = {
11
11
  command = data[i];
12
12
  switch (command) {
13
13
  case M:
14
- scalePoints(data, scaleX, scaleY, i, 1);
15
- i += 3;
16
- break;
17
14
  case L:
18
15
  scalePoints(data, scaleX, scaleY, i, 1);
19
16
  i += 3;
@@ -80,6 +77,7 @@ const PathScaler = {
80
77
  const { scalePoints } = PathScaler;
81
78
 
82
79
  const matrix = MatrixHelper.get();
80
+ const { topLeft, top, topRight, right, bottom, left } = Direction9;
83
81
  function scaleResize(leaf, scaleX, scaleY) {
84
82
  if (leaf.pathInputed) {
85
83
  scaleResizePath(leaf, scaleX, scaleY);
@@ -92,15 +90,36 @@ function scaleResize(leaf, scaleX, scaleY) {
92
90
  }
93
91
  }
94
92
  function scaleResizeFontSize(leaf, scaleX, scaleY) {
95
- const { width, height } = leaf.__localBoxBounds;
96
- if (scaleX !== 1) {
97
- leaf.fontSize *= scaleX;
98
- leaf.y -= height * (scaleX - scaleY) / 2;
99
- }
100
- else if (scaleY !== 1) {
101
- leaf.fontSize *= scaleY;
102
- leaf.x -= width * (scaleY - scaleX) / 2;
93
+ const { app } = leaf;
94
+ const editor = app && app.editor;
95
+ let fontScale = scaleX;
96
+ if (editor.editing) {
97
+ const layout = leaf.__layout;
98
+ let { width, height } = layout.boxBounds;
99
+ width *= scaleY - scaleX;
100
+ height *= scaleX - scaleY;
101
+ switch (editor.resizeDirection) {
102
+ case top:
103
+ case bottom:
104
+ fontScale = scaleY;
105
+ layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
106
+ break;
107
+ case left:
108
+ case right:
109
+ layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
110
+ break;
111
+ case topLeft:
112
+ case topRight:
113
+ layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
114
+ break;
115
+ }
103
116
  }
117
+ leaf.fontSize *= fontScale;
118
+ const data = leaf.__;
119
+ if (!data.__autoWidth)
120
+ leaf.width *= fontScale;
121
+ if (!data.__autoHeight)
122
+ leaf.height *= fontScale;
104
123
  }
105
124
  function scaleResizePath(leaf, scaleX, scaleY) {
106
125
  PathScaler.scale(leaf.__.path, scaleX, scaleY);
@@ -146,7 +165,7 @@ leaf.resizeHeight = function (height) {
146
165
  this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
147
166
  };
148
167
  Text.prototype.__scaleResize = function (scaleX, scaleY) {
149
- if (this.__.__autoSize && (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size'))) {
168
+ if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
150
169
  scaleResizeFontSize(this, scaleX, scaleY);
151
170
  }
152
171
  else {
@@ -1 +1 @@
1
- import{PathCommandMap as t,MatrixHelper as e,Leaf as i,Text as s,Path as o,Line as n,Polygon as c,Group as a,Box as h}from"@leafer-ui/draw";const{M:_,L:l,C:r,Q:p,Z:f,N:u,D:d,X:z,G:b,F:g,O:k,P:R,U:y}=t,x={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case _:case l:S(t,e,i,o,1),o+=3;break;case r:S(t,e,i,o,3),o+=7;break;case p:S(t,e,i,o,2),o+=5;break;case f:o+=1;break;case u:S(t,e,i,o,2),o+=5;break;case d:S(t,e,i,o,2),o+=9;break;case z:S(t,e,i,o,2),o+=6;break;case b:S(t,e,i,o,2),o+=9;break;case g:S(t,e,i,o,2),o+=5;break;case k:t[o]=b,t.splice(o+4,0,t[o+3],0),S(t,e,i,o,2),o+=9,n+=2;break;case R:t[o]=g,t.splice(o+4,0,t[o+3]),S(t,e,i,o,2),o+=5,n+=1;break;case y:S(t,e,i,o,2),o+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,c=o?n+2*o:t.length;n<c;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:S}=x,w=e.get();function B(t,e,i){t.pathInputed?P(t,e,i):(1!==e&&(t.width*=e),1!==i&&(t.height*=i))}function C(t,e,i){const{width:s,height:o}=t.__localBoxBounds;1!==e?(t.fontSize*=e,t.y-=o*(e-i)/2):1!==i&&(t.fontSize*=i,t.x-=s*(i-e)/2)}function P(t,e,i){x.scale(t.__.path,e,i),t.path=t.__.path}function m(t,e,i){x.scalePoints(t.__.points,e,i),t.points=t.__.points}function I(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)w.a=e,w.d=i,s[t].transform(w,!0)}const O=i.prototype;O.scaleResize=function(t,e=t,i){const s=this;i||s.editConfig&&"scale"===s.editConfig.editSize?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},O.__scaleResize=function(t,e){B(this,t,e)},O.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},O.resizeHeight=function(t){const e=t/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},s.prototype.__scaleResize=function(t,e){this.__.__autoSize&&(this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize)?C(this,t,e):B(this,t,e)},o.prototype.__scaleResize=function(t,e){P(this,t,e)},n.prototype.__scaleResize=function(t,e){this.pathInputed?P(this,t,e):this.points?m(this,t,e):this.width*=t},c.prototype.__scaleResize=function(t,e){this.pathInputed?P(this,t,e):this.points?m(this,t,e):B(this,t,e)},a.prototype.__scaleResize=function(t,e){I(this,t,e)},h.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?I(this,t,e):(B(this,t,e),this.__.resizeChildren&&I(this,t,e))};export{x as PathScaler,B as scaleResize,C as scaleResizeFontSize,I as scaleResizeGroup,P as scaleResizePath,m as scaleResizePoints};
1
+ import{PathCommandMap as t,MatrixHelper as e,Direction9 as i,Leaf as s,Text as o,Path as a,Line as n,Polygon as c,Group as h,Box as l}from"@leafer-ui/draw";const{M:r,L:_,C:f,Q:p,Z:u,N:d,D:g,X:z,G:b,F:k,O:R,P:y,U:w}=t,S={scale(t,e,i){if(!t)return;let s,o=0,a=t.length;for(;o<a;)switch(s=t[o],s){case r:case _:m(t,e,i,o,1),o+=3;break;case f:m(t,e,i,o,3),o+=7;break;case p:m(t,e,i,o,2),o+=5;break;case u:o+=1;break;case d:m(t,e,i,o,2),o+=5;break;case g:m(t,e,i,o,2),o+=9;break;case z:m(t,e,i,o,2),o+=6;break;case b:m(t,e,i,o,2),o+=9;break;case k:m(t,e,i,o,2),o+=5;break;case R:t[o]=b,t.splice(o+4,0,t[o+3],0),m(t,e,i,o,2),o+=9,a+=2;break;case y:t[o]=k,t.splice(o+4,0,t[o+3]),m(t,e,i,o,2),o+=5,a+=1;break;case w:m(t,e,i,o,2),o+=6}},scalePoints(t,e,i,s,o){for(let a=o?s+1:0,n=o?a+2*o:t.length;a<n;a+=2)t[a]*=e,t[a+1]*=i}},{scalePoints:m}=S,x=e.get(),{topLeft:C,top:I,topRight:O,right:B,bottom:P,left:v}=i;function X(t,e,i){t.pathInputed?F(t,e,i):(1!==e&&(t.width*=e),1!==i&&(t.height*=i))}function D(t,e,i){const{app:s}=t,o=s&&s.editor;let a=e;if(o.editing){const s=t.__layout;let{width:n,height:c}=s.boxBounds;switch(n*=i-e,c*=e-i,o.resizeDirection){case I:case P:a=i,s.affectScaleOrRotation?t.moveInner(-n/2,0):t.x-=n/2;break;case v:case B:s.affectScaleOrRotation?t.moveInner(0,-c/2):t.y-=c/2;break;case C:case O:s.affectScaleOrRotation?t.moveInner(0,-c):t.y-=c}}t.fontSize*=a;const n=t.__;n.__autoWidth||(t.width*=a),n.__autoHeight||(t.height*=a)}function F(t,e,i){S.scale(t.__.path,e,i),t.path=t.__.path}function H(t,e,i){S.scalePoints(t.__.points,e,i),t.points=t.__.points}function L(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)x.a=e,x.d=i,s[t].transform(x,!0)}const W=s.prototype;W.scaleResize=function(t,e=t,i){const s=this;i||s.editConfig&&"scale"===s.editConfig.editSize?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},W.__scaleResize=function(t,e){X(this,t,e)},W.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},W.resizeHeight=function(t){const e=t/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},o.prototype.__scaleResize=function(t,e){this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize?D(this,t,e):X(this,t,e)},a.prototype.__scaleResize=function(t,e){F(this,t,e)},n.prototype.__scaleResize=function(t,e){this.pathInputed?F(this,t,e):this.points?H(this,t,e):this.width*=t},c.prototype.__scaleResize=function(t,e){this.pathInputed?F(this,t,e):this.points?H(this,t,e):X(this,t,e)},h.prototype.__scaleResize=function(t,e){L(this,t,e)},l.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?L(this,t,e):(X(this,t,e),this.__.resizeChildren&&L(this,t,e))};export{S as PathScaler,X as scaleResize,D as scaleResizeFontSize,L as scaleResizeGroup,F as scaleResizePath,H as scaleResizePoints};
package/dist/resize.js CHANGED
@@ -13,9 +13,6 @@ this.LeaferIN.resize = (function (exports, draw) {
13
13
  command = data[i];
14
14
  switch (command) {
15
15
  case M:
16
- scalePoints(data, scaleX, scaleY, i, 1);
17
- i += 3;
18
- break;
19
16
  case L:
20
17
  scalePoints(data, scaleX, scaleY, i, 1);
21
18
  i += 3;
@@ -82,6 +79,7 @@ this.LeaferIN.resize = (function (exports, draw) {
82
79
  const { scalePoints } = PathScaler;
83
80
 
84
81
  const matrix = draw.MatrixHelper.get();
82
+ const { topLeft, top, topRight, right, bottom, left } = draw.Direction9;
85
83
  function scaleResize(leaf, scaleX, scaleY) {
86
84
  if (leaf.pathInputed) {
87
85
  scaleResizePath(leaf, scaleX, scaleY);
@@ -94,15 +92,36 @@ this.LeaferIN.resize = (function (exports, draw) {
94
92
  }
95
93
  }
96
94
  function scaleResizeFontSize(leaf, scaleX, scaleY) {
97
- const { width, height } = leaf.__localBoxBounds;
98
- if (scaleX !== 1) {
99
- leaf.fontSize *= scaleX;
100
- leaf.y -= height * (scaleX - scaleY) / 2;
101
- }
102
- else if (scaleY !== 1) {
103
- leaf.fontSize *= scaleY;
104
- leaf.x -= width * (scaleY - scaleX) / 2;
95
+ const { app } = leaf;
96
+ const editor = app && app.editor;
97
+ let fontScale = scaleX;
98
+ if (editor.editing) {
99
+ const layout = leaf.__layout;
100
+ let { width, height } = layout.boxBounds;
101
+ width *= scaleY - scaleX;
102
+ height *= scaleX - scaleY;
103
+ switch (editor.resizeDirection) {
104
+ case top:
105
+ case bottom:
106
+ fontScale = scaleY;
107
+ layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
108
+ break;
109
+ case left:
110
+ case right:
111
+ layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
112
+ break;
113
+ case topLeft:
114
+ case topRight:
115
+ layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
116
+ break;
117
+ }
105
118
  }
119
+ leaf.fontSize *= fontScale;
120
+ const data = leaf.__;
121
+ if (!data.__autoWidth)
122
+ leaf.width *= fontScale;
123
+ if (!data.__autoHeight)
124
+ leaf.height *= fontScale;
106
125
  }
107
126
  function scaleResizePath(leaf, scaleX, scaleY) {
108
127
  PathScaler.scale(leaf.__.path, scaleX, scaleY);
@@ -148,7 +167,7 @@ this.LeaferIN.resize = (function (exports, draw) {
148
167
  this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
149
168
  };
150
169
  draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
151
- if (this.__.__autoSize && (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size'))) {
170
+ if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
152
171
  scaleResizeFontSize(this, scaleX, scaleY);
153
172
  }
154
173
  else {
@@ -1 +1 @@
1
- "use strict";var e=require("@leafer-ui/draw");const{M:t,L:s,C:i,Q:o,Z:a,N:n,D:c,X:h,G:l,F:r,O:_,P:p,U:u}=e.PathCommandMap,f={scale(e,f,d){if(!e)return;let g,R=0,b=e.length;for(;R<b;)switch(g=e[R],g){case t:case s:z(e,f,d,R,1),R+=3;break;case i:z(e,f,d,R,3),R+=7;break;case o:z(e,f,d,R,2),R+=5;break;case a:R+=1;break;case n:z(e,f,d,R,2),R+=5;break;case c:z(e,f,d,R,2),R+=9;break;case h:z(e,f,d,R,2),R+=6;break;case l:z(e,f,d,R,2),R+=9;break;case r:z(e,f,d,R,2),R+=5;break;case _:e[R]=l,e.splice(R+4,0,e[R+3],0),z(e,f,d,R,2),R+=9,b+=2;break;case p:e[R]=r,e.splice(R+4,0,e[R+3]),z(e,f,d,R,2),R+=5,b+=1;break;case u:z(e,f,d,R,2),R+=6}},scalePoints(e,t,s,i,o){for(let a=o?i+1:0,n=o?a+2*o:e.length;a<n;a+=2)e[a]*=t,e[a+1]*=s}},{scalePoints:z}=f,d=e.MatrixHelper.get();function g(e,t,s){e.pathInputed?b(e,t,s):(1!==t&&(e.width*=t),1!==s&&(e.height*=s))}function R(e,t,s){const{width:i,height:o}=e.__localBoxBounds;1!==t?(e.fontSize*=t,e.y-=o*(t-s)/2):1!==s&&(e.fontSize*=s,e.x-=i*(s-t)/2)}function b(e,t,s){f.scale(e.__.path,t,s),e.path=e.__.path}function x(e,t,s){f.scalePoints(e.__.points,t,s),e.points=e.__.points}function k(e,t,s){const{children:i}=e;for(let e=0;e<i.length;e++)d.a=t,d.d=s,i[e].transform(d,!0)}const y=e.Leaf.prototype;y.scaleResize=function(e,t=e,s){const i=this;s||i.editConfig&&"scale"===i.editConfig.editSize?(i.scaleX*=e,i.scaleY*=t):(e<0&&(i.scaleX*=-1,e=-e),t<0&&(i.scaleY*=-1,t=-t),this.__scaleResize(e,t))},y.__scaleResize=function(e,t){g(this,e,t)},y.resizeWidth=function(e){const t=e/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,t,this.__.lockRatio?t:1,!0)},y.resizeHeight=function(e){const t=e/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?t:1,t,!0)},e.Text.prototype.__scaleResize=function(e,t){this.__.__autoSize&&(this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize)?R(this,e,t):g(this,e,t)},e.Path.prototype.__scaleResize=function(e,t){b(this,e,t)},e.Line.prototype.__scaleResize=function(e,t){this.pathInputed?b(this,e,t):this.points?x(this,e,t):this.width*=e},e.Polygon.prototype.__scaleResize=function(e,t){this.pathInputed?b(this,e,t):this.points?x(this,e,t):g(this,e,t)},e.Group.prototype.__scaleResize=function(e,t){k(this,e,t)},e.Box.prototype.__scaleResize=function(e,t){this.__.__autoSize&&this.children.length?k(this,e,t):(g(this,e,t),this.__.resizeChildren&&k(this,e,t))},exports.PathScaler=f,exports.scaleResize=g,exports.scaleResizeFontSize=R,exports.scaleResizeGroup=k,exports.scaleResizePath=b,exports.scaleResizePoints=x;
1
+ "use strict";var e=require("@leafer-ui/draw");const{M:t,L:i,C:s,Q:o,Z:a,N:c,D:n,X:h,G:r,F:l,O:_,P:p,U:f}=e.PathCommandMap,u={scale(e,u,z){if(!e)return;let g,R=0,b=e.length;for(;R<b;)switch(g=e[R],g){case t:case i:d(e,u,z,R,1),R+=3;break;case s:d(e,u,z,R,3),R+=7;break;case o:d(e,u,z,R,2),R+=5;break;case a:R+=1;break;case c:d(e,u,z,R,2),R+=5;break;case n:d(e,u,z,R,2),R+=9;break;case h:d(e,u,z,R,2),R+=6;break;case r:d(e,u,z,R,2),R+=9;break;case l:d(e,u,z,R,2),R+=5;break;case _:e[R]=r,e.splice(R+4,0,e[R+3],0),d(e,u,z,R,2),R+=9,b+=2;break;case p:e[R]=l,e.splice(R+4,0,e[R+3]),d(e,u,z,R,2),R+=5,b+=1;break;case f:d(e,u,z,R,2),R+=6}},scalePoints(e,t,i,s,o){for(let a=o?s+1:0,c=o?a+2*o:e.length;a<c;a+=2)e[a]*=t,e[a+1]*=i}},{scalePoints:d}=u,z=e.MatrixHelper.get(),{topLeft:g,top:R,topRight:b,right:k,bottom:x,left:y}=e.Direction9;function P(e,t,i){e.pathInputed?w(e,t,i):(1!==t&&(e.width*=t),1!==i&&(e.height*=i))}function S(e,t,i){const{app:s}=e,o=s&&s.editor;let a=t;if(o.editing){const s=e.__layout;let{width:c,height:n}=s.boxBounds;switch(c*=i-t,n*=t-i,o.resizeDirection){case R:case x:a=i,s.affectScaleOrRotation?e.moveInner(-c/2,0):e.x-=c/2;break;case y:case k:s.affectScaleOrRotation?e.moveInner(0,-n/2):e.y-=n/2;break;case g:case b:s.affectScaleOrRotation?e.moveInner(0,-n):e.y-=n}}e.fontSize*=a;const c=e.__;c.__autoWidth||(e.width*=a),c.__autoHeight||(e.height*=a)}function w(e,t,i){u.scale(e.__.path,t,i),e.path=e.__.path}function m(e,t,i){u.scalePoints(e.__.points,t,i),e.points=e.__.points}function C(e,t,i){const{children:s}=e;for(let e=0;e<s.length;e++)z.a=t,z.d=i,s[e].transform(z,!0)}const B=e.Leaf.prototype;B.scaleResize=function(e,t=e,i){const s=this;i||s.editConfig&&"scale"===s.editConfig.editSize?(s.scaleX*=e,s.scaleY*=t):(e<0&&(s.scaleX*=-1,e=-e),t<0&&(s.scaleY*=-1,t=-t),this.__scaleResize(e,t))},B.__scaleResize=function(e,t){P(this,e,t)},B.resizeWidth=function(e){const t=e/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,t,this.__.lockRatio?t:1,!0)},B.resizeHeight=function(e){const t=e/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?t:1,t,!0)},e.Text.prototype.__scaleResize=function(e,t){this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize?S(this,e,t):P(this,e,t)},e.Path.prototype.__scaleResize=function(e,t){w(this,e,t)},e.Line.prototype.__scaleResize=function(e,t){this.pathInputed?w(this,e,t):this.points?m(this,e,t):this.width*=e},e.Polygon.prototype.__scaleResize=function(e,t){this.pathInputed?w(this,e,t):this.points?m(this,e,t):P(this,e,t)},e.Group.prototype.__scaleResize=function(e,t){C(this,e,t)},e.Box.prototype.__scaleResize=function(e,t){this.__.__autoSize&&this.children.length?C(this,e,t):(P(this,e,t),this.__.resizeChildren&&C(this,e,t))},exports.PathScaler=u,exports.scaleResize=P,exports.scaleResizeFontSize=S,exports.scaleResizeGroup=C,exports.scaleResizePath=w,exports.scaleResizePoints=m;
@@ -1 +1 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.resize=function(e,t){"use strict";const{M:s,L:i,C:o,Q:a,Z:n,N:c,D:h,X:l,G:_,F:r,O:f,P:p,U:u}=t.PathCommandMap,z={scale(e,t,z){if(!e)return;let g,R=0,b=e.length;for(;R<b;)switch(g=e[R],g){case s:case i:d(e,t,z,R,1),R+=3;break;case o:d(e,t,z,R,3),R+=7;break;case a:d(e,t,z,R,2),R+=5;break;case n:R+=1;break;case c:d(e,t,z,R,2),R+=5;break;case h:d(e,t,z,R,2),R+=9;break;case l:d(e,t,z,R,2),R+=6;break;case _:d(e,t,z,R,2),R+=9;break;case r:d(e,t,z,R,2),R+=5;break;case f:e[R]=_,e.splice(R+4,0,e[R+3],0),d(e,t,z,R,2),R+=9,b+=2;break;case p:e[R]=r,e.splice(R+4,0,e[R+3]),d(e,t,z,R,2),R+=5,b+=1;break;case u:d(e,t,z,R,2),R+=6}},scalePoints(e,t,s,i,o){for(let a=o?i+1:0,n=o?a+2*o:e.length;a<n;a+=2)e[a]*=t,e[a+1]*=s}},{scalePoints:d}=z,g=t.MatrixHelper.get();function R(e,t,s){e.pathInputed?k(e,t,s):(1!==t&&(e.width*=t),1!==s&&(e.height*=s))}function b(e,t,s){const{width:i,height:o}=e.__localBoxBounds;1!==t?(e.fontSize*=t,e.y-=o*(t-s)/2):1!==s&&(e.fontSize*=s,e.x-=i*(s-t)/2)}function k(e,t,s){z.scale(e.__.path,t,s),e.path=e.__.path}function y(e,t,s){z.scalePoints(e.__.points,t,s),e.points=e.__.points}function P(e,t,s){const{children:i}=e;for(let e=0;e<i.length;e++)g.a=t,g.d=s,i[e].transform(g,!0)}const x=t.Leaf.prototype;return x.scaleResize=function(e,t=e,s){const i=this;s||i.editConfig&&"scale"===i.editConfig.editSize?(i.scaleX*=e,i.scaleY*=t):(e<0&&(i.scaleX*=-1,e=-e),t<0&&(i.scaleY*=-1,t=-t),this.__scaleResize(e,t))},x.__scaleResize=function(e,t){R(this,e,t)},x.resizeWidth=function(e){const t=e/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,t,this.__.lockRatio?t:1,!0)},x.resizeHeight=function(e){const t=e/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?t:1,t,!0)},t.Text.prototype.__scaleResize=function(e,t){this.__.__autoSize&&(this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize)?b(this,e,t):R(this,e,t)},t.Path.prototype.__scaleResize=function(e,t){k(this,e,t)},t.Line.prototype.__scaleResize=function(e,t){this.pathInputed?k(this,e,t):this.points?y(this,e,t):this.width*=e},t.Polygon.prototype.__scaleResize=function(e,t){this.pathInputed?k(this,e,t):this.points?y(this,e,t):R(this,e,t)},t.Group.prototype.__scaleResize=function(e,t){P(this,e,t)},t.Box.prototype.__scaleResize=function(e,t){this.__.__autoSize&&this.children.length?P(this,e,t):(R(this,e,t),this.__.resizeChildren&&P(this,e,t))},e.PathScaler=z,e.scaleResize=R,e.scaleResizeFontSize=b,e.scaleResizeGroup=P,e.scaleResizePath=k,e.scaleResizePoints=y,e}({},LeaferUI);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.resize=function(e,t){"use strict";const{M:i,L:s,C:o,Q:a,Z:n,N:c,D:h,X:r,G:l,F:_,O:f,P:p,U:u}=t.PathCommandMap,d={scale(e,t,d){if(!e)return;let g,R=0,b=e.length;for(;R<b;)switch(g=e[R],g){case i:case s:z(e,t,d,R,1),R+=3;break;case o:z(e,t,d,R,3),R+=7;break;case a:z(e,t,d,R,2),R+=5;break;case n:R+=1;break;case c:z(e,t,d,R,2),R+=5;break;case h:z(e,t,d,R,2),R+=9;break;case r:z(e,t,d,R,2),R+=6;break;case l:z(e,t,d,R,2),R+=9;break;case _:z(e,t,d,R,2),R+=5;break;case f:e[R]=l,e.splice(R+4,0,e[R+3],0),z(e,t,d,R,2),R+=9,b+=2;break;case p:e[R]=_,e.splice(R+4,0,e[R+3]),z(e,t,d,R,2),R+=5,b+=1;break;case u:z(e,t,d,R,2),R+=6}},scalePoints(e,t,i,s,o){for(let a=o?s+1:0,n=o?a+2*o:e.length;a<n;a+=2)e[a]*=t,e[a+1]*=i}},{scalePoints:z}=d,g=t.MatrixHelper.get(),{topLeft:R,top:b,topRight:k,right:y,bottom:I,left:P}=t.Direction9;function S(e,t,i){e.pathInputed?L(e,t,i):(1!==t&&(e.width*=t),1!==i&&(e.height*=i))}function x(e,t,i){const{app:s}=e,o=s&&s.editor;let a=t;if(o.editing){const s=e.__layout;let{width:n,height:c}=s.boxBounds;switch(n*=i-t,c*=t-i,o.resizeDirection){case b:case I:a=i,s.affectScaleOrRotation?e.moveInner(-n/2,0):e.x-=n/2;break;case P:case y:s.affectScaleOrRotation?e.moveInner(0,-c/2):e.y-=c/2;break;case R:case k:s.affectScaleOrRotation?e.moveInner(0,-c):e.y-=c}}e.fontSize*=a;const n=e.__;n.__autoWidth||(e.width*=a),n.__autoHeight||(e.height*=a)}function L(e,t,i){d.scale(e.__.path,t,i),e.path=e.__.path}function m(e,t,i){d.scalePoints(e.__.points,t,i),e.points=e.__.points}function w(e,t,i){const{children:s}=e;for(let e=0;e<s.length;e++)g.a=t,g.d=i,s[e].transform(g,!0)}const C=t.Leaf.prototype;return C.scaleResize=function(e,t=e,i){const s=this;i||s.editConfig&&"scale"===s.editConfig.editSize?(s.scaleX*=e,s.scaleY*=t):(e<0&&(s.scaleX*=-1,e=-e),t<0&&(s.scaleY*=-1,t=-t),this.__scaleResize(e,t))},C.__scaleResize=function(e,t){S(this,e,t)},C.resizeWidth=function(e){const t=e/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,t,this.__.lockRatio?t:1,!0)},C.resizeHeight=function(e){const t=e/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?t:1,t,!0)},t.Text.prototype.__scaleResize=function(e,t){this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize?x(this,e,t):S(this,e,t)},t.Path.prototype.__scaleResize=function(e,t){L(this,e,t)},t.Line.prototype.__scaleResize=function(e,t){this.pathInputed?L(this,e,t):this.points?m(this,e,t):this.width*=e},t.Polygon.prototype.__scaleResize=function(e,t){this.pathInputed?L(this,e,t):this.points?m(this,e,t):S(this,e,t)},t.Group.prototype.__scaleResize=function(e,t){w(this,e,t)},t.Box.prototype.__scaleResize=function(e,t){this.__.__autoSize&&this.children.length?w(this,e,t):(S(this,e,t),this.__.resizeChildren&&w(this,e,t))},e.PathScaler=d,e.scaleResize=S,e.scaleResizeFontSize=x,e.scaleResizeGroup=w,e.scaleResizePath=L,e.scaleResizePoints=m,e}({},LeaferUI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/resize",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "@leafer-in/resize",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "dependencies": {
37
- "@leafer-ui/draw": "1.0.1",
38
- "@leafer-ui/interface": "1.0.1"
37
+ "@leafer-ui/draw": "^1.0.3",
38
+ "@leafer-ui/interface": "^1.0.3"
39
39
  }
40
40
  }
package/src/PathScaler.ts CHANGED
@@ -17,9 +17,6 @@ export const PathScaler = {
17
17
  command = data[i]
18
18
  switch (command) {
19
19
  case M: //moveto(x, y)
20
- scalePoints(data, scaleX, scaleY, i, 1)
21
- i += 3
22
- break
23
20
  case L: //lineto(x, y)
24
21
  scalePoints(data, scaleX, scaleY, i, 1)
25
22
  i += 3
package/src/resize.ts CHANGED
@@ -41,7 +41,7 @@ leaf.resizeHeight = function (height: number): void {
41
41
  // UI
42
42
 
43
43
  Text.prototype.__scaleResize = function (scaleX: number, scaleY: number): void {
44
- if (this.__.__autoSize && (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size'))) {
44
+ if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
45
45
  scaleResizeFontSize(this, scaleX, scaleY)
46
46
  } else {
47
47
  scaleResize(this, scaleX, scaleY)
package/src/scaler.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { IBranch, ILeaf, ILine, IPolygon, IText } from '@leafer-ui/interface'
2
- import { MatrixHelper } from '@leafer-ui/draw'
2
+ import { Direction9, MatrixHelper } from '@leafer-ui/draw'
3
3
 
4
4
  import { PathScaler } from './PathScaler'
5
5
 
6
6
 
7
7
  const matrix = MatrixHelper.get()
8
+ const { topLeft, top, topRight, right, bottom, left } = Direction9
8
9
 
9
10
  export function scaleResize(leaf: ILeaf, scaleX: number, scaleY: number): void {
10
11
  if (leaf.pathInputed) {
@@ -17,14 +18,43 @@ export function scaleResize(leaf: ILeaf, scaleX: number, scaleY: number): void {
17
18
  }
18
19
 
19
20
  export function scaleResizeFontSize(leaf: IText, scaleX: number, scaleY: number): void {
20
- const { width, height } = leaf.__localBoxBounds
21
- if (scaleX !== 1) {
22
- leaf.fontSize *= scaleX
23
- leaf.y -= height * (scaleX - scaleY) / 2
24
- } else if (scaleY !== 1) {
25
- leaf.fontSize *= scaleY
26
- leaf.x -= width * (scaleY - scaleX) / 2
21
+ const { app } = leaf
22
+ const editor = app && app.editor
23
+
24
+ let fontScale = scaleX
25
+
26
+ if (editor.editing) {
27
+
28
+ const layout = leaf.__layout
29
+
30
+ let { width, height } = layout.boxBounds
31
+ width *= scaleY - scaleX
32
+ height *= scaleX - scaleY
33
+
34
+ switch (editor.resizeDirection) {
35
+ case top:
36
+ case bottom:
37
+ fontScale = scaleY
38
+ layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2
39
+ break
40
+ case left:
41
+ case right:
42
+ layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2
43
+ break
44
+ case topLeft:
45
+ case topRight:
46
+ layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height
47
+ break
48
+ }
49
+
27
50
  }
51
+
52
+ leaf.fontSize *= fontScale
53
+
54
+ const data = leaf.__
55
+ if (!data.__autoWidth) leaf.width *= fontScale
56
+ if (!data.__autoHeight) leaf.height *= fontScale
57
+
28
58
  }
29
59
 
30
60
  export function scaleResizePath(leaf: ILeaf, scaleX: number, scaleY: number): void {