UNPKG

@leafer-in/resize

Version:
3 lines (2 loc) 3.34 kB
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:r,G:l,F:_,O:f,P:p,U:u}=t.PathCommandMap,d={scale(e,t,d){if(!e)return;let g,b=0,R=e.length;for(;b<R;)switch(g=e[b],g){case i:case s:z(e,t,d,b,1),b+=3;break;case o:z(e,t,d,b,3),b+=7;break;case a:z(e,t,d,b,2),b+=5;break;case n:b+=1;break;case c:z(e,t,d,b,2),b+=5;break;case h:z(e,t,d,b,2),b+=9;break;case r:z(e,t,d,b,2),b+=6;break;case l:z(e,t,d,b,2),b+=9;break;case _:z(e,t,d,b,2),b+=5;break;case f:e[b]=l,e.splice(b+4,0,e[b+3],0),z(e,t,d,b,2),b+=9,R+=2;break;case p:e[b]=_,e.splice(b+4,0,e[b+3]),z(e,t,d,b,2),b+=5,R+=1;break;case u:z(e,t,d,b,2),b+=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:z}=d,g=t.MatrixHelper.get(),{topLeft:b,top:R,topRight:y,right:k,bottom:x,left:P}=t.Direction9;function S(e,t,i){e.pathInputed?m(e,t,i):(1!==t&&(e.width*=t),1!==i&&(e.height*=i))}function I(e,t,i,s){let o=t;if(void 0!==s){const a=e.__layout;let{width:n,height:c}=a.boxBounds;switch(n*=i-t,c*=t-i,s){case R:case x:o=i,a.affectScaleOrRotation?e.moveInner(-n/2,0):e.x-=n/2;break;case P:case k:a.affectScaleOrRotation?e.moveInner(0,-c/2):e.y-=c/2;break;case b:case y:a.affectScaleOrRotation?e.moveInner(0,-c):e.y-=c}}e.fontSize*=o;const a=e.__,{padding:n}=a;n&&(e.padding=n instanceof Array?n.map((e=>e*o)):n*o),a.__autoWidth||(e.width*=o),a.__autoHeight||(e.height*=o)}function m(e,t,i){d.scale(e.__.path,t,i),e.path=e.__.path}function L(e,t,i){const{points:s}=e;"object"==typeof s[0]?s.forEach((e=>{e.x*=t,e.y*=i})):d.scalePoints(s,t,i),e.points=s}function w(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 B=t.Leaf.prototype;return B.scaleResize=function(e,t=e,i){const s=this;i||s.editConfig&&"scale"===s.editConfig.editSize?(s.scaleX*=e,s.scaleY*=t):(e<0&&(s.scaleX*=-1,e=-e),t<0&&(s.scaleY*=-1,t=-t),this.__scaleResize(e,t))},B.__scaleResize=function(e,t){S(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,{__autoWidth:n,__autoHeight:c,textAlign:h,verticalAlign:r}=this.__,{boxBounds:l}=this.__layout;n&&"left"!==h&&1!==e&&(this.x+=l.x),c&&"top"!==r&&1!==t&&(this.y+=l.y),this.__.resizeFontSize||s&&"font-size"===s.editSize||a&&"font-size"===o.mergedConfig.editSize?I(this,e,t,a&&a.direction):S(this,e,t)},t.Path.prototype.__scaleResize=function(e,t){m(this,e,t)},t.Line.prototype.__scaleResize=function(e,t){this.pathInputed?m(this,e,t):this.points?L(this,e,t):this.width*=e},t.Polygon.prototype.__scaleResize=function(e,t){this.pathInputed?m(this,e,t):this.points?L(this,e,t):S(this,e,t)},t.Group.prototype.__scaleResize=function(e,t){w(this,e,t)},t.Box.prototype.__scaleResize=function(e,t){const{resizeChildren:i,__autoSize:s}=this.__;s&&i||S(this,e,t),i&&w(this,e,t)},t.Plugin.add("resize"),e.PathScaler=d,e.scaleResize=S,e.scaleResizeFontSize=I,e.scaleResizeGroup=w,e.scaleResizePath=m,e.scaleResizePoints=L,e}({},LeaferUI); //# sourceMappingURL=resize.min.js.map