@leafer-in/resize 1.0.1 → 1.0.2
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 +29 -7
- package/dist/resize.esm.js +30 -8
- package/dist/resize.esm.min.js +1 -1
- package/dist/resize.js +29 -7
- package/dist/resize.min.cjs +1 -1
- package/dist/resize.min.js +1 -1
- package/package.json +3 -3
- package/src/scaler.ts +36 -7
package/dist/resize.cjs
CHANGED
|
@@ -82,6 +82,7 @@ const PathScaler = {
|
|
|
82
82
|
const { scalePoints } = PathScaler;
|
|
83
83
|
|
|
84
84
|
const matrix = draw.MatrixHelper.get();
|
|
85
|
+
const { topLeft, top, topRight, right, bottom, left } = draw.Direction9;
|
|
85
86
|
function scaleResize(leaf, scaleX, scaleY) {
|
|
86
87
|
if (leaf.pathInputed) {
|
|
87
88
|
scaleResizePath(leaf, scaleX, scaleY);
|
|
@@ -94,14 +95,35 @@ function scaleResize(leaf, scaleX, scaleY) {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
function scaleResizeFontSize(leaf, scaleX, scaleY) {
|
|
97
|
-
const {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
const { app } = leaf;
|
|
99
|
+
const editor = app && app.editor;
|
|
100
|
+
if (editor.editing) {
|
|
101
|
+
const layout = leaf.__layout;
|
|
102
|
+
let { width, height } = layout.boxBounds;
|
|
103
|
+
width *= (scaleY - scaleX) * (leaf.scaleX < 0 ? -1 : 1);
|
|
104
|
+
height *= (scaleX - scaleY) * (leaf.scaleY < 0 ? -1 : 1);
|
|
105
|
+
switch (editor.resizeDirection) {
|
|
106
|
+
case top:
|
|
107
|
+
case bottom:
|
|
108
|
+
leaf.fontSize *= scaleY;
|
|
109
|
+
layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
|
|
110
|
+
break;
|
|
111
|
+
case left:
|
|
112
|
+
case right:
|
|
113
|
+
leaf.fontSize *= scaleX;
|
|
114
|
+
layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
|
|
115
|
+
break;
|
|
116
|
+
case topLeft:
|
|
117
|
+
case topRight:
|
|
118
|
+
leaf.fontSize *= scaleX;
|
|
119
|
+
layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
|
|
120
|
+
break;
|
|
121
|
+
default:
|
|
122
|
+
leaf.fontSize *= scaleX;
|
|
123
|
+
}
|
|
101
124
|
}
|
|
102
|
-
else
|
|
103
|
-
leaf.fontSize *=
|
|
104
|
-
leaf.x -= width * (scaleY - scaleX) / 2;
|
|
125
|
+
else {
|
|
126
|
+
leaf.fontSize *= scaleX;
|
|
105
127
|
}
|
|
106
128
|
}
|
|
107
129
|
function scaleResizePath(leaf, scaleX, scaleY) {
|
package/dist/resize.esm.js
CHANGED
|
@@ -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 = {
|
|
@@ -80,6 +80,7 @@ const PathScaler = {
|
|
|
80
80
|
const { scalePoints } = PathScaler;
|
|
81
81
|
|
|
82
82
|
const matrix = MatrixHelper.get();
|
|
83
|
+
const { topLeft, top, topRight, right, bottom, left } = Direction9;
|
|
83
84
|
function scaleResize(leaf, scaleX, scaleY) {
|
|
84
85
|
if (leaf.pathInputed) {
|
|
85
86
|
scaleResizePath(leaf, scaleX, scaleY);
|
|
@@ -92,14 +93,35 @@ function scaleResize(leaf, scaleX, scaleY) {
|
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
function scaleResizeFontSize(leaf, scaleX, scaleY) {
|
|
95
|
-
const {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
const { app } = leaf;
|
|
97
|
+
const editor = app && app.editor;
|
|
98
|
+
if (editor.editing) {
|
|
99
|
+
const layout = leaf.__layout;
|
|
100
|
+
let { width, height } = layout.boxBounds;
|
|
101
|
+
width *= (scaleY - scaleX) * (leaf.scaleX < 0 ? -1 : 1);
|
|
102
|
+
height *= (scaleX - scaleY) * (leaf.scaleY < 0 ? -1 : 1);
|
|
103
|
+
switch (editor.resizeDirection) {
|
|
104
|
+
case top:
|
|
105
|
+
case bottom:
|
|
106
|
+
leaf.fontSize *= scaleY;
|
|
107
|
+
layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
|
|
108
|
+
break;
|
|
109
|
+
case left:
|
|
110
|
+
case right:
|
|
111
|
+
leaf.fontSize *= scaleX;
|
|
112
|
+
layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
|
|
113
|
+
break;
|
|
114
|
+
case topLeft:
|
|
115
|
+
case topRight:
|
|
116
|
+
leaf.fontSize *= scaleX;
|
|
117
|
+
layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
leaf.fontSize *= scaleX;
|
|
121
|
+
}
|
|
99
122
|
}
|
|
100
|
-
else
|
|
101
|
-
leaf.fontSize *=
|
|
102
|
-
leaf.x -= width * (scaleY - scaleX) / 2;
|
|
123
|
+
else {
|
|
124
|
+
leaf.fontSize *= scaleX;
|
|
103
125
|
}
|
|
104
126
|
}
|
|
105
127
|
function scaleResizePath(leaf, scaleX, scaleY) {
|
package/dist/resize.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PathCommandMap as t,MatrixHelper as e,
|
|
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};
|
package/dist/resize.js
CHANGED
|
@@ -82,6 +82,7 @@ this.LeaferIN.resize = (function (exports, draw) {
|
|
|
82
82
|
const { scalePoints } = PathScaler;
|
|
83
83
|
|
|
84
84
|
const matrix = draw.MatrixHelper.get();
|
|
85
|
+
const { topLeft, top, topRight, right, bottom, left } = draw.Direction9;
|
|
85
86
|
function scaleResize(leaf, scaleX, scaleY) {
|
|
86
87
|
if (leaf.pathInputed) {
|
|
87
88
|
scaleResizePath(leaf, scaleX, scaleY);
|
|
@@ -94,14 +95,35 @@ this.LeaferIN.resize = (function (exports, draw) {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
function scaleResizeFontSize(leaf, scaleX, scaleY) {
|
|
97
|
-
const {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
const { app } = leaf;
|
|
99
|
+
const editor = app && app.editor;
|
|
100
|
+
if (editor.editing) {
|
|
101
|
+
const layout = leaf.__layout;
|
|
102
|
+
let { width, height } = layout.boxBounds;
|
|
103
|
+
width *= (scaleY - scaleX) * (leaf.scaleX < 0 ? -1 : 1);
|
|
104
|
+
height *= (scaleX - scaleY) * (leaf.scaleY < 0 ? -1 : 1);
|
|
105
|
+
switch (editor.resizeDirection) {
|
|
106
|
+
case top:
|
|
107
|
+
case bottom:
|
|
108
|
+
leaf.fontSize *= scaleY;
|
|
109
|
+
layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
|
|
110
|
+
break;
|
|
111
|
+
case left:
|
|
112
|
+
case right:
|
|
113
|
+
leaf.fontSize *= scaleX;
|
|
114
|
+
layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
|
|
115
|
+
break;
|
|
116
|
+
case topLeft:
|
|
117
|
+
case topRight:
|
|
118
|
+
leaf.fontSize *= scaleX;
|
|
119
|
+
layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
|
|
120
|
+
break;
|
|
121
|
+
default:
|
|
122
|
+
leaf.fontSize *= scaleX;
|
|
123
|
+
}
|
|
101
124
|
}
|
|
102
|
-
else
|
|
103
|
-
leaf.fontSize *=
|
|
104
|
-
leaf.x -= width * (scaleY - scaleX) / 2;
|
|
125
|
+
else {
|
|
126
|
+
leaf.fontSize *= scaleX;
|
|
105
127
|
}
|
|
106
128
|
}
|
|
107
129
|
function scaleResizePath(leaf, scaleX, scaleY) {
|
package/dist/resize.min.cjs
CHANGED
|
@@ -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:
|
|
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;
|
package/dist/resize.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.resize=function(e,t){"use strict";const{M:
|
|
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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/resize",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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.
|
|
38
|
-
"@leafer-ui/interface": "1.0.
|
|
37
|
+
"@leafer-ui/draw": "^1.0.2",
|
|
38
|
+
"@leafer-ui/interface": "^1.0.2"
|
|
39
39
|
}
|
|
40
40
|
}
|
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,13 +18,41 @@ 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 {
|
|
21
|
-
|
|
21
|
+
const { app } = leaf
|
|
22
|
+
const editor = app && app.editor
|
|
23
|
+
|
|
24
|
+
if (editor.editing) {
|
|
25
|
+
|
|
26
|
+
const layout = leaf.__layout
|
|
27
|
+
|
|
28
|
+
let { width, height } = layout.boxBounds
|
|
29
|
+
width *= (scaleY - scaleX) * (leaf.scaleX < 0 ? -1 : 1)
|
|
30
|
+
height *= (scaleX - scaleY) * (leaf.scaleY < 0 ? -1 : 1)
|
|
31
|
+
|
|
32
|
+
switch (editor.resizeDirection) {
|
|
33
|
+
case top:
|
|
34
|
+
case bottom:
|
|
35
|
+
leaf.fontSize *= scaleY
|
|
36
|
+
layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2
|
|
37
|
+
break
|
|
38
|
+
case left:
|
|
39
|
+
case right:
|
|
40
|
+
leaf.fontSize *= scaleX
|
|
41
|
+
layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2
|
|
42
|
+
break
|
|
43
|
+
case topLeft:
|
|
44
|
+
case topRight:
|
|
45
|
+
leaf.fontSize *= scaleX
|
|
46
|
+
layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height
|
|
47
|
+
break
|
|
48
|
+
default: // bottomLeft / bottomRight / other
|
|
49
|
+
leaf.fontSize *= scaleX
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
} else {
|
|
53
|
+
|
|
22
54
|
leaf.fontSize *= scaleX
|
|
23
|
-
|
|
24
|
-
} else if (scaleY !== 1) {
|
|
25
|
-
leaf.fontSize *= scaleY
|
|
26
|
-
leaf.x -= width * (scaleY - scaleX) / 2
|
|
55
|
+
|
|
27
56
|
}
|
|
28
57
|
}
|
|
29
58
|
|