UNPKG

@leafer-in/resize

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