@leafer-in/resize
Version:
3 lines (2 loc) • 3.34 kB
JavaScript
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 r,Plugin as l}from"@leafer-ui/draw";const{M:_,L:f,C:p,Q:d,Z:u,N:g,D:z,X:b,G:y,F:k,O:R,P:x,U:m}=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 _:case f:w(t,e,i,o,1),o+=3;break;case p:w(t,e,i,o,3),o+=7;break;case d:w(t,e,i,o,2),o+=5;break;case u:o+=1;break;case g: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 y:w(t,e,i,o,2),o+=9;break;case k:w(t,e,i,o,2),o+=5;break;case R:t[o]=y,t.splice(o+4,0,t[o+3],0),w(t,e,i,o,2),o+=9,a+=2;break;case x:t[o]=k,t.splice(o+4,0,t[o+3]),w(t,e,i,o,2),o+=5,a+=1;break;case m: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}=S,B=e.get(),{topLeft:C,top:I,topRight:O,right:v,bottom:P,left:A}=i;function H(t,e,i){t.pathInputed?X(t,e,i):(1!==e&&(t.width*=e),1!==i&&(t.height*=i))}function W(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 I:case P:o=i,a.affectScaleOrRotation?t.moveInner(-n/2,0):t.x-=n/2;break;case A:case v:a.affectScaleOrRotation?t.moveInner(0,-c/2):t.y-=c/2;break;case C:case O: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 X(t,e,i){S.scale(t.__.path,e,i),t.path=t.__.path}function F(t,e,i){const{points:s}=t;"object"==typeof s[0]?s.forEach((t=>{t.x*=e,t.y*=i})):S.scalePoints(s,e,i),t.points=s}function L(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)B.a=e,B.d=i,s[t].transform(B,!0)}const Y=s.prototype;Y.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))},Y.__scaleResize=function(t,e){H(this,t,e)},Y.resizeWidth=function(t){const e=t/this.getBounds("box","local").width||1;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},Y.resizeHeight=function(t){const e=t/this.getBounds("box","local").height||1;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},o.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?W(this,t,e,a&&a.direction):H(this,t,e)},a.prototype.__scaleResize=function(t,e){X(this,t,e)},n.prototype.__scaleResize=function(t,e){this.pathInputed?X(this,t,e):this.points?F(this,t,e):this.width*=t},c.prototype.__scaleResize=function(t,e){this.pathInputed?X(this,t,e):this.points?F(this,t,e):H(this,t,e)},h.prototype.__scaleResize=function(t,e){L(this,t,e)},r.prototype.__scaleResize=function(t,e){const{resizeChildren:i,__autoSize:s}=this.__;s&&i||H(this,t,e),i&&L(this,t,e)},l.add("resize");export{S as PathScaler,H as scaleResize,W as scaleResizeFontSize,L as scaleResizeGroup,X as scaleResizePath,F as scaleResizePoints};
//# sourceMappingURL=resize.esm.min.js.map