@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 +31 -12
- package/dist/resize.esm.js +32 -13
- package/dist/resize.esm.min.js +1 -1
- package/dist/resize.js +31 -12
- package/dist/resize.min.cjs +1 -1
- package/dist/resize.min.js +1 -1
- package/package.json +3 -3
- package/src/PathScaler.ts +0 -3
- package/src/resize.ts +1 -1
- package/src/scaler.ts +38 -8
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 {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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.__.
|
|
170
|
+
if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
|
|
152
171
|
scaleResizeFontSize(this, scaleX, scaleY);
|
|
153
172
|
}
|
|
154
173
|
else {
|
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 = {
|
|
@@ -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 {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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.__.
|
|
168
|
+
if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
|
|
150
169
|
scaleResizeFontSize(this, scaleX, scaleY);
|
|
151
170
|
}
|
|
152
171
|
else {
|
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: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 {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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.__.
|
|
170
|
+
if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
|
|
152
171
|
scaleResizeFontSize(this, scaleX, scaleY);
|
|
153
172
|
}
|
|
154
173
|
else {
|
package/dist/resize.min.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@leafer-ui/draw");const{M:t,L:
|
|
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;
|
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: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.
|
|
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.
|
|
38
|
-
"@leafer-ui/interface": "1.0.
|
|
37
|
+
"@leafer-ui/draw": "^1.0.3",
|
|
38
|
+
"@leafer-ui/interface": "^1.0.3"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/PathScaler.ts
CHANGED
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.__.
|
|
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 {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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 {
|