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