@leafer-in/resize
Version:
3 lines (2 loc) • 3.87 kB
JavaScript
"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:r,F:l,O:p,P:_,U:f}=e.PathCommandMap,u={scale(e,u,g){if(!e)return;let x,z=0,y=e.length;for(;z<y;)switch(x=e[z],x){case t:case i:d(e,u,g,z,1),z+=3;break;case s:d(e,u,g,z,3),z+=7;break;case o:d(e,u,g,z,2),z+=5;break;case a:z+=1;break;case n:d(e,u,g,z,2),z+=5;break;case c:d(e,u,g,z,2),z+=9;break;case h:d(e,u,g,z,2),z+=6;break;case r:d(e,u,g,z,2),z+=9;break;case l:d(e,u,g,z,2),z+=5;break;case p:e[z]=r,e.splice(z+4,0,e[z+3],0),d(e,u,g,z,2),z+=9,y+=2;break;case _:e[z]=l,e.splice(z+4,0,e[z+3]),d(e,u,g,z,2),z+=5,y+=1;break;case f:d(e,u,g,z,2),z+=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}=u,g=e.MatrixHelper.get(),{topLeft:x,top:z,topRight:y,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 z: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 y:e.affectScaleOrRotation?t.moveInner(0,-c):t.y-=c}}t.fontSize*=a;const n=t.__,{padding:c,lineHeight:h,letterSpacing:r}=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(r)?"px"===r.type&&(n.letterSpacing={type:"px",value:r.value*a}):r&&(n.letterSpacing=r*a)}function w(e,t,i){u.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}):u.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,H={},B={},{copy:C,scale:I,toOuterPoint:M}=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{if(e<0&&(o.scaleX*=-1,e=-e),t<0&&(o.scaleY*=-1,t=-t),"stroke"===s){C(B,this.__localMatrix),e<0&&I(B,-1,1),t<0&&I(B,1,-1);const{boxBounds:i,strokeBounds:s}=this.__layout,{x:o,y:a,width:n,height:c}=s;H.x=(o-i.x)*(e-1),H.y=(a-i.y)*(t-1),M(B,H,H,!0),this.x+=H.x,this.y+=H.y,e=(n*e-(n-i.width))/i.width,t=(c*t-(c-i.height))/i.height}this.__scaleResize(e,t)}},v.__scaleResize=function(e,t){S(this,e,t)},v.resizeWidth=function(e,t="inner"){const i=e/this.getBounds("box",t).width||1;this.scaleOf("top-left",i,this.__.lockRatio?i:1,!0)},v.resizeHeight=function(e,t="inner"){const i=e/this.getBounds("box",t).height||1;this.scaleOf("top-left",this.__.lockRatio?i:1,i,!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=u,exports.scaleResize=S,exports.scaleResizeFontSize=P,exports.scaleResizeGroup=m,exports.scaleResizePath=w,exports.scaleResizePoints=O;
//# sourceMappingURL=resize.min.cjs.map