@leafer-in/resize
Version:
3 lines (2 loc) • 3.32 kB
JavaScript
"use strict";var t=require("@leafer-ui/draw");const{M:e,L:i,C:s,Q:o,Z:a,N:n,D:c,X:h,G:r,F:l,O:_,P:p,U:f}=t.PathCommandMap,u={scale(t,u,z){if(!t)return;let g,b=0,x=t.length;for(;b<x;)switch(g=t[b],g){case e:case i:d(t,u,z,b,1),b+=3;break;case s:d(t,u,z,b,3),b+=7;break;case o:d(t,u,z,b,2),b+=5;break;case a:b+=1;break;case n:d(t,u,z,b,2),b+=5;break;case c:d(t,u,z,b,2),b+=9;break;case h:d(t,u,z,b,2),b+=6;break;case r:d(t,u,z,b,2),b+=9;break;case l:d(t,u,z,b,2),b+=5;break;case _:t[b]=r,t.splice(b+4,0,t[b+3],0),d(t,u,z,b,2),b+=9,x+=2;break;case p:t[b]=l,t.splice(b+4,0,t[b+3]),d(t,u,z,b,2),b+=5,x+=1;break;case f:d(t,u,z,b,2),b+=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:d}=u,z=t.MatrixHelper.get(),{topLeft:g,top:b,topRight:x,right:R,bottom:y,left:k}=t.Direction9;function P(t,e,i){t.pathInputed?m(t,e,i):(1!==e&&(t.width*=e),1!==i&&(t.height*=i))}function S(t,e,i,s){let o=e;if(void 0!==s){const a=t.__layout;let{width:n,height:c}=a.boxBounds;switch(n*=i-e,c*=e-i,s){case b:case y:o=i,a.affectScaleOrRotation?t.moveInner(-n/2,0):t.x-=n/2;break;case k:case R:a.affectScaleOrRotation?t.moveInner(0,-c/2):t.y-=c/2;break;case g:case x:a.affectScaleOrRotation?t.moveInner(0,-c):t.y-=c}}t.fontSize*=o;const a=t.__,{padding:n}=a;n&&(t.padding=n instanceof Array?n.map((t=>t*o)):n*o),a.__autoWidth||(t.width*=o),a.__autoHeight||(t.height*=o)}function m(t,e,i){u.scale(t.__.path,e,i),t.path=t.__.path}function w(t,e,i){const{points:s}=t;"object"==typeof s[0]?s.forEach((t=>{t.x*=e,t.y*=i})):u.scalePoints(s,e,i),t.points=s}function B(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)z.a=e,z.d=i,s[t].transform(z,!0)}const C=t.Leaf.prototype;C.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))},C.__scaleResize=function(t,e){P(this,t,e)},C.resizeWidth=function(t){const e=t/this.getBounds("box","local").width||1;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},C.resizeHeight=function(t){const e=t/this.getBounds("box","local").height||1;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},t.Text.prototype.__scaleResize=function(t,e){const{app:i,editConfig:s}=this,o=i&&i.editor,a=o&&o.dragPoint,{__autoWidth:n,__autoHeight:c,textAlign:h,verticalAlign:r}=this.__,{boxBounds:l}=this.__layout;n&&"left"!==h&&1!==t&&(this.x+=l.x),c&&"top"!==r&&1!==e&&(this.y+=l.y),this.__.resizeFontSize||s&&"font-size"===s.editSize||a&&"font-size"===o.mergedConfig.editSize?S(this,t,e,a&&a.direction):P(this,t,e)},t.Path.prototype.__scaleResize=function(t,e){m(this,t,e)},t.Line.prototype.__scaleResize=function(t,e){this.pathInputed?m(this,t,e):this.points?w(this,t,e):this.width*=t},t.Polygon.prototype.__scaleResize=function(t,e){this.pathInputed?m(this,t,e):this.points?w(this,t,e):P(this,t,e)},t.Group.prototype.__scaleResize=function(t,e){B(this,t,e)},t.Box.prototype.__scaleResize=function(t,e){const{resizeChildren:i,__autoSize:s}=this.__;s&&i||P(this,t,e),i&&B(this,t,e)},t.Plugin.add("resize"),exports.PathScaler=u,exports.scaleResize=P,exports.scaleResizeFontSize=S,exports.scaleResizeGroup=B,exports.scaleResizePath=m,exports.scaleResizePoints=w;
//# sourceMappingURL=resize.min.cjs.map