@leafer-in/resize 1.0.2 → 1.0.4

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;
@@ -97,34 +94,34 @@ function scaleResize(leaf, scaleX, scaleY) {
97
94
  function scaleResizeFontSize(leaf, scaleX, scaleY) {
98
95
  const { app } = leaf;
99
96
  const editor = app && app.editor;
97
+ let fontScale = scaleX;
100
98
  if (editor.editing) {
101
99
  const layout = leaf.__layout;
102
100
  let { width, height } = layout.boxBounds;
103
- width *= (scaleY - scaleX) * (leaf.scaleX < 0 ? -1 : 1);
104
- height *= (scaleX - scaleY) * (leaf.scaleY < 0 ? -1 : 1);
101
+ width *= scaleY - scaleX;
102
+ height *= scaleX - scaleY;
105
103
  switch (editor.resizeDirection) {
106
104
  case top:
107
105
  case bottom:
108
- leaf.fontSize *= scaleY;
106
+ fontScale = scaleY;
109
107
  layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
110
108
  break;
111
109
  case left:
112
110
  case right:
113
- leaf.fontSize *= scaleX;
114
111
  layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
115
112
  break;
116
113
  case topLeft:
117
114
  case topRight:
118
- leaf.fontSize *= scaleX;
119
115
  layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
120
116
  break;
121
- default:
122
- leaf.fontSize *= scaleX;
123
117
  }
124
118
  }
125
- else {
126
- leaf.fontSize *= scaleX;
127
- }
119
+ leaf.fontSize *= fontScale;
120
+ const data = leaf.__;
121
+ if (!data.__autoWidth)
122
+ leaf.width *= fontScale;
123
+ if (!data.__autoHeight)
124
+ leaf.height *= fontScale;
128
125
  }
129
126
  function scaleResizePath(leaf, scaleX, scaleY) {
130
127
  PathScaler.scale(leaf.__.path, scaleX, scaleY);
@@ -170,7 +167,7 @@ leaf.resizeHeight = function (height) {
170
167
  this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
171
168
  };
172
169
  draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
173
- if (this.__.__autoSize && (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size'))) {
170
+ if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
174
171
  scaleResizeFontSize(this, scaleX, scaleY);
175
172
  }
176
173
  else {
@@ -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;
@@ -95,34 +92,34 @@ function scaleResize(leaf, scaleX, scaleY) {
95
92
  function scaleResizeFontSize(leaf, scaleX, scaleY) {
96
93
  const { app } = leaf;
97
94
  const editor = app && app.editor;
95
+ let fontScale = scaleX;
98
96
  if (editor.editing) {
99
97
  const layout = leaf.__layout;
100
98
  let { width, height } = layout.boxBounds;
101
- width *= (scaleY - scaleX) * (leaf.scaleX < 0 ? -1 : 1);
102
- height *= (scaleX - scaleY) * (leaf.scaleY < 0 ? -1 : 1);
99
+ width *= scaleY - scaleX;
100
+ height *= scaleX - scaleY;
103
101
  switch (editor.resizeDirection) {
104
102
  case top:
105
103
  case bottom:
106
- leaf.fontSize *= scaleY;
104
+ fontScale = scaleY;
107
105
  layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
108
106
  break;
109
107
  case left:
110
108
  case right:
111
- leaf.fontSize *= scaleX;
112
109
  layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
113
110
  break;
114
111
  case topLeft:
115
112
  case topRight:
116
- leaf.fontSize *= scaleX;
117
113
  layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
118
114
  break;
119
- default:
120
- leaf.fontSize *= scaleX;
121
115
  }
122
116
  }
123
- else {
124
- leaf.fontSize *= scaleX;
125
- }
117
+ leaf.fontSize *= fontScale;
118
+ const data = leaf.__;
119
+ if (!data.__autoWidth)
120
+ leaf.width *= fontScale;
121
+ if (!data.__autoHeight)
122
+ leaf.height *= fontScale;
126
123
  }
127
124
  function scaleResizePath(leaf, scaleX, scaleY) {
128
125
  PathScaler.scale(leaf.__.path, scaleX, scaleY);
@@ -168,7 +165,7 @@ leaf.resizeHeight = function (height) {
168
165
  this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
169
166
  };
170
167
  Text.prototype.__scaleResize = function (scaleX, scaleY) {
171
- if (this.__.__autoSize && (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size'))) {
168
+ if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
172
169
  scaleResizeFontSize(this, scaleX, scaleY);
173
170
  }
174
171
  else {
@@ -1 +1 @@
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:z,X:b,G:g,F:k,O:R,P:S,U:y}=t,m={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 _:w(t,e,i,o,1),o+=3;break;case f:w(t,e,i,o,3),o+=7;break;case p:w(t,e,i,o,2),o+=5;break;case u:o+=1;break;case d:w(t,e,i,o,2),o+=5;break;case z:w(t,e,i,o,2),o+=9;break;case b:w(t,e,i,o,2),o+=6;break;case g:w(t,e,i,o,2),o+=9;break;case k:w(t,e,i,o,2),o+=5;break;case R:t[o]=g,t.splice(o+4,0,t[o+3],0),w(t,e,i,o,2),o+=9,a+=2;break;case S:t[o]=k,t.splice(o+4,0,t[o+3]),w(t,e,i,o,2),o+=5,a+=1;break;case y:w(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:w}=m,x=e.get(),{topLeft:C,top:I,topRight:O,right:B,bottom:P,left:X}=i;function v(t,e,i){t.pathInputed?D(t,e,i):(1!==e&&(t.width*=e),1!==i&&(t.height*=i))}function Y(t,e,i){const{app:s}=t,o=s&&s.editor;if(o.editing){const s=t.__layout;let{width:a,height:n}=s.boxBounds;switch(a*=(i-e)*(t.scaleX<0?-1:1),n*=(e-i)*(t.scaleY<0?-1:1),o.resizeDirection){case I:case P:t.fontSize*=i,s.affectScaleOrRotation?t.moveInner(-a/2,0):t.x-=a/2;break;case X:case B:t.fontSize*=e,s.affectScaleOrRotation?t.moveInner(0,-n/2):t.y-=n/2;break;case C:case O:t.fontSize*=e,s.affectScaleOrRotation?t.moveInner(0,-n):t.y-=n;break;default:t.fontSize*=e}}else t.fontSize*=e}function D(t,e,i){m.scale(t.__.path,e,i),t.path=t.__.path}function F(t,e,i){m.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 G=s.prototype;G.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))},G.__scaleResize=function(t,e){v(this,t,e)},G.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},G.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.__.__autoSize&&(this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize)?Y(this,t,e):v(this,t,e)},a.prototype.__scaleResize=function(t,e){D(this,t,e)},n.prototype.__scaleResize=function(t,e){this.pathInputed?D(this,t,e):this.points?F(this,t,e):this.width*=t},c.prototype.__scaleResize=function(t,e){this.pathInputed?D(this,t,e):this.points?F(this,t,e):v(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):(v(this,t,e),this.__.resizeChildren&&L(this,t,e))};export{m as PathScaler,v as scaleResize,Y as scaleResizeFontSize,L as scaleResizeGroup,D as scaleResizePath,F 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;
@@ -97,34 +94,34 @@ this.LeaferIN.resize = (function (exports, draw) {
97
94
  function scaleResizeFontSize(leaf, scaleX, scaleY) {
98
95
  const { app } = leaf;
99
96
  const editor = app && app.editor;
97
+ let fontScale = scaleX;
100
98
  if (editor.editing) {
101
99
  const layout = leaf.__layout;
102
100
  let { width, height } = layout.boxBounds;
103
- width *= (scaleY - scaleX) * (leaf.scaleX < 0 ? -1 : 1);
104
- height *= (scaleX - scaleY) * (leaf.scaleY < 0 ? -1 : 1);
101
+ width *= scaleY - scaleX;
102
+ height *= scaleX - scaleY;
105
103
  switch (editor.resizeDirection) {
106
104
  case top:
107
105
  case bottom:
108
- leaf.fontSize *= scaleY;
106
+ fontScale = scaleY;
109
107
  layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
110
108
  break;
111
109
  case left:
112
110
  case right:
113
- leaf.fontSize *= scaleX;
114
111
  layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
115
112
  break;
116
113
  case topLeft:
117
114
  case topRight:
118
- leaf.fontSize *= scaleX;
119
115
  layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
120
116
  break;
121
- default:
122
- leaf.fontSize *= scaleX;
123
117
  }
124
118
  }
125
- else {
126
- leaf.fontSize *= scaleX;
127
- }
119
+ leaf.fontSize *= fontScale;
120
+ const data = leaf.__;
121
+ if (!data.__autoWidth)
122
+ leaf.width *= fontScale;
123
+ if (!data.__autoHeight)
124
+ leaf.height *= fontScale;
128
125
  }
129
126
  function scaleResizePath(leaf, scaleX, scaleY) {
130
127
  PathScaler.scale(leaf.__.path, scaleX, scaleY);
@@ -170,7 +167,7 @@ this.LeaferIN.resize = (function (exports, draw) {
170
167
  this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
171
168
  };
172
169
  draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
173
- if (this.__.__autoSize && (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size'))) {
170
+ if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
174
171
  scaleResizeFontSize(this, scaleX, scaleY);
175
172
  }
176
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:r,F:l,O:_,P:p,U:f}=e.PathCommandMap,u={scale(e,u,d){if(!e)return;let b,R=0,g=e.length;for(;R<g;)switch(b=e[R],b){case t:case s:z(e,u,d,R,1),R+=3;break;case i:z(e,u,d,R,3),R+=7;break;case o:z(e,u,d,R,2),R+=5;break;case a:R+=1;break;case n:z(e,u,d,R,2),R+=5;break;case c:z(e,u,d,R,2),R+=9;break;case h:z(e,u,d,R,2),R+=6;break;case r:z(e,u,d,R,2),R+=9;break;case l:z(e,u,d,R,2),R+=5;break;case _:e[R]=r,e.splice(R+4,0,e[R+3],0),z(e,u,d,R,2),R+=9,g+=2;break;case p:e[R]=l,e.splice(R+4,0,e[R+3]),z(e,u,d,R,2),R+=5,g+=1;break;case f:z(e,u,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}=u,d=e.MatrixHelper.get(),{topLeft:b,top:R,topRight:g,right:k,bottom:x,left:S}=e.Direction9;function y(e,t,s){e.pathInputed?m(e,t,s):(1!==t&&(e.width*=t),1!==s&&(e.height*=s))}function P(e,t,s){const{app:i}=e,o=i&&i.editor;if(o.editing){const i=e.__layout;let{width:a,height:n}=i.boxBounds;switch(a*=(s-t)*(e.scaleX<0?-1:1),n*=(t-s)*(e.scaleY<0?-1:1),o.resizeDirection){case R:case x:e.fontSize*=s,i.affectScaleOrRotation?e.moveInner(-a/2,0):e.x-=a/2;break;case S:case k:e.fontSize*=t,i.affectScaleOrRotation?e.moveInner(0,-n/2):e.y-=n/2;break;case b:case g:e.fontSize*=t,i.affectScaleOrRotation?e.moveInner(0,-n):e.y-=n;break;default:e.fontSize*=t}}else e.fontSize*=t}function m(e,t,s){u.scale(e.__.path,t,s),e.path=e.__.path}function w(e,t,s){u.scalePoints(e.__.points,t,s),e.points=e.__.points}function C(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 B=e.Leaf.prototype;B.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))},B.__scaleResize=function(e,t){y(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.__.__autoSize&&(this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize)?P(this,e,t):y(this,e,t)},e.Path.prototype.__scaleResize=function(e,t){m(this,e,t)},e.Line.prototype.__scaleResize=function(e,t){this.pathInputed?m(this,e,t):this.points?w(this,e,t):this.width*=e},e.Polygon.prototype.__scaleResize=function(e,t){this.pathInputed?m(this,e,t):this.points?w(this,e,t):y(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):(y(this,e,t),this.__.resizeChildren&&C(this,e,t))},exports.PathScaler=u,exports.scaleResize=y,exports.scaleResizeFontSize=P,exports.scaleResizeGroup=C,exports.scaleResizePath=m,exports.scaleResizePoints=w;
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:i,L:s,C:o,Q:a,Z:n,N:c,D:h,X:l,G:r,F:f,O:_,P:p,U:u}=t.PathCommandMap,z={scale(e,t,z){if(!e)return;let b,R=0,g=e.length;for(;R<g;)switch(b=e[R],b){case i:case s: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 r:d(e,t,z,R,2),R+=9;break;case f:d(e,t,z,R,2),R+=5;break;case _:e[R]=r,e.splice(R+4,0,e[R+3],0),d(e,t,z,R,2),R+=9,g+=2;break;case p:e[R]=f,e.splice(R+4,0,e[R+3]),d(e,t,z,R,2),R+=5,g+=1;break;case u:d(e,t,z,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:d}=z,b=t.MatrixHelper.get(),{topLeft:R,top:g,topRight:k,right:S,bottom:y,left:I}=t.Direction9;function P(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;if(o.editing){const s=e.__layout;let{width:a,height:n}=s.boxBounds;switch(a*=(i-t)*(e.scaleX<0?-1:1),n*=(t-i)*(e.scaleY<0?-1:1),o.resizeDirection){case g:case y:e.fontSize*=i,s.affectScaleOrRotation?e.moveInner(-a/2,0):e.x-=a/2;break;case I:case S:e.fontSize*=t,s.affectScaleOrRotation?e.moveInner(0,-n/2):e.y-=n/2;break;case R:case k:e.fontSize*=t,s.affectScaleOrRotation?e.moveInner(0,-n):e.y-=n;break;default:e.fontSize*=t}}else e.fontSize*=t}function L(e,t,i){z.scale(e.__.path,t,i),e.path=e.__.path}function m(e,t,i){z.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++)b.a=t,b.d=i,s[e].transform(b,!0)}const w=t.Leaf.prototype;return w.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))},w.__scaleResize=function(e,t){P(this,e,t)},w.resizeWidth=function(e){const t=e/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,t,this.__.lockRatio?t:1,!0)},w.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)?x(this,e,t):P(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):P(this,e,t)},t.Group.prototype.__scaleResize=function(e,t){C(this,e,t)},t.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))},e.PathScaler=z,e.scaleResize=P,e.scaleResizeFontSize=x,e.scaleResizeGroup=C,e.scaleResizePath=L,e.scaleResizePoints=m,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.2",
3
+ "version": "1.0.4",
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.2",
38
- "@leafer-ui/interface": "^1.0.2"
37
+ "@leafer-ui/draw": "^1.0.4",
38
+ "@leafer-ui/interface": "^1.0.4"
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
@@ -21,39 +21,40 @@ export function scaleResizeFontSize(leaf: IText, scaleX: number, scaleY: number)
21
21
  const { app } = leaf
22
22
  const editor = app && app.editor
23
23
 
24
+ let fontScale = scaleX
25
+
24
26
  if (editor.editing) {
25
27
 
26
28
  const layout = leaf.__layout
27
29
 
28
30
  let { width, height } = layout.boxBounds
29
- width *= (scaleY - scaleX) * (leaf.scaleX < 0 ? -1 : 1)
30
- height *= (scaleX - scaleY) * (leaf.scaleY < 0 ? -1 : 1)
31
+ width *= scaleY - scaleX
32
+ height *= scaleX - scaleY
31
33
 
32
34
  switch (editor.resizeDirection) {
33
35
  case top:
34
36
  case bottom:
35
- leaf.fontSize *= scaleY
37
+ fontScale = scaleY
36
38
  layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2
37
39
  break
38
40
  case left:
39
41
  case right:
40
- leaf.fontSize *= scaleX
41
42
  layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2
42
43
  break
43
44
  case topLeft:
44
45
  case topRight:
45
- leaf.fontSize *= scaleX
46
46
  layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height
47
47
  break
48
- default: // bottomLeft / bottomRight / other
49
- leaf.fontSize *= scaleX
50
48
  }
51
49
 
52
- } else {
50
+ }
53
51
 
54
- leaf.fontSize *= scaleX
52
+ leaf.fontSize *= fontScale
53
+
54
+ const data = leaf.__
55
+ if (!data.__autoWidth) leaf.width *= fontScale
56
+ if (!data.__autoHeight) leaf.height *= fontScale
55
57
 
56
- }
57
58
  }
58
59
 
59
60
  export function scaleResizePath(leaf: ILeaf, scaleX: number, scaleY: number): void {