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