@leafer-in/editor 1.0.0-rc.23 → 1.0.0-rc.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{PathCommandMap as t,Leaf as e,Path as i,Line as s,Polygon as o,MatrixHelper as n,Group as r,Box as a,Event as l,defineKey as h,UI as d,Paint as c,Rect as g,Answer as u,Bounds as f,LeafList as p,PointHelper as m,AroundHelper as v,Direction9 as L,MathHelper as b,Matrix as w,Debug as y,DataHelper as _,LeafHelper as k,RenderEvent as E,getPointData as x,Creator as M}from"@leafer-ui/draw";import{PointerEvent as S,DragEvent as T,MoveEvent as V,ZoomEvent as O,RotateEvent as H,KeyEvent as P}from"@leafer-ui/core";const{M:C,L:I,C:D,Q:R,Z:A,N:B,D:Z,X:z,G:W,F:X,O:Y,P:U,U:F}=t,G={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case C:case I:j(t,e,i,o,1),o+=3;break;case D:j(t,e,i,o,3),o+=7;break;case R:j(t,e,i,o,2),o+=5;break;case A:o+=1;break;case B:j(t,e,i,o,2),o+=5;break;case Z:j(t,e,i,o,2),o+=9;break;case z:j(t,e,i,o,2),o+=6;break;case W:j(t,e,i,o,2),o+=9;break;case X:j(t,e,i,o,2),o+=5;break;case Y:t[o]=W,t.splice(o+4,0,t[o+3],0),j(t,e,i,o,2),o+=9,n+=2;break;case U:t[o]=X,t.splice(o+4,0,t[o+3]),j(t,e,i,o,2),o+=5,n+=1;break;case F:j(t,e,i,o,2),o+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:j}=G;function K(t,e,i){1!==e&&(t.width*=e),1!==i&&(t.height*=i)}e.prototype.scaleResize=function(t,e=t,i){const s=this;i?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},e.prototype.__scaleResize=function(t,e){K(this,t,e)},i.prototype.__scaleResize=function(t,e){G.scale(this.__.path,t,e),this.path=this.__.path},s.prototype.__scaleResize=function(t,e){if(this.points)G.scalePoints(this.__.points,t,e),this.points=this.__.points;else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},o.prototype.__scaleResize=function(t,e){this.points?(G.scalePoints(this.__.points,t,e),this.points=this.__.points):K(this,t,e)};const N=n.get();function $(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)N.a=e,N.d=i,s[t].transform(N,!0)}function q(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function Q(t){return t?t instanceof Array?t:[t]:[]}r.prototype.__scaleResize=function(t,e){$(this,t,e)},a.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?$(this,t,e):K(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class J extends l{get list(){return Q(this.value)}get oldList(){return Q(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}J.SELECT="editor.select",J.HOVER="editor.hover";class tt extends J{constructor(t,e){super(t,e)}}tt.MOVE="editor.move";class et extends J{constructor(t,e){super(t,e)}}et.SCALE="editor.scale";class it extends J{constructor(t,e){super(t,e)}}it.ROTATE="editor.rotate";class st extends J{constructor(t,e){super(t,e)}}function ot(t){return(e,i)=>{const s="_"+i;h(e,i,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}st.SKEW="editor.skew";const nt=n.get(),{abs:rt}=Math,{copy:at,scale:lt}=n;class ht extends d{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let s;const{stroke:o,strokeWidth:n,fill:r}=this.__,{bounds:a}=e;for(let l=0;l<i.length;l++)if(s=i[l],a&&a.hit(s.__world,e.matrix)){const i=rt(s.__world.scaleX),a=rt(s.__world.scaleY);if(i!==a){at(nt,s.__world),lt(nt,1/i,1/a),t.setWorld(nt,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:o,y:r,width:l,height:h}=s.__layout.boxBounds;t.rect(o*i,r*a,l*i,h*a)}else t.setWorld(s.__world,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),this.__.strokeWidth=n/rt(s.__world.scaleX);o&&("string"==typeof o?c.stroke(o,this,t):c.strokes(o,this,t)),r&&("string"==typeof r?c.fill(r,this,t):c.fills(r,this,t))}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}q([ot((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],ht.prototype,"target",void 0);class dt extends r{constructor(t){super(t),this.strokeArea=new g({strokeAlign:"center"}),this.fillArea=new g,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:ct,Yes:gt,NoAndSkip:ut,YesAndSkip:ft}=u,pt={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?ft:ut;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?ft:ct;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return gt}return ct}return t.isBranch?ut:ct}},{findOne:mt}=pt;class vt extends r{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new ht,this.targetStroker=new ht,this.bounds=new f,this.selectArea=new dt,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:s,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.mergeConfig;"press"===e&&this.checkAndSelect(t)}onTap(t){const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i&&this.checkAndSelect(t),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(this.allowDrag(t)){const{editor:e}=this,{stroke:i,area:s}=e.mergeConfig,{x:o,y:n}=t.getInner(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new p(e.app.find(pt.findBounds,s));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(s.get()),o.length){const t=[];this.originList.forEach((e=>{o.has(e)||t.push(e)})),o.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list}}onDragEnd(){this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!mt(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new p(this.editor.editBox.rect)};return mt(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):mt(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(J.HOVER,this.onHover,this),t.on_(J.SELECT,this.onSelect,this),e.on_(S.MOVE,this.onPointerMove,this),e.on_(S.BEFORE_DOWN,this.onBeforeDown,this),e.on_(S.TAP,this.onTap,this),e.on_(T.START,this.onDragStart,this),e.on_(T.DRAG,this.onDrag,this),e.on_(T.END,this.onDragEnd,this),e.on_(V.MOVE,this.onAutoMove,this),e.on_([O.ZOOM,V.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:Lt,top:bt,topRight:wt,right:yt,bottomRight:_t,bottom:kt,bottomLeft:Et,left:xt}=L,{toPoint:Mt}=v,St={getScaleData(t,e,i,s,o){let n,r={},a=1,l=1;const{width:h,height:d}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===h&&(i.x+=.1),Math.abs(i.y)===d&&(i.y+=.1);const c=(-i.y+d)/d,g=(i.x+h)/h,u=(i.y+d)/d,f=(-i.x+h)/h;switch(e){case bt:l=c,n="bottom";break;case yt:a=g,n="left";break;case kt:l=u,n="top";break;case xt:a=f,n="right";break;case Lt:l=c,a=f,n="bottom-right";break;case wt:l=c,a=g,n="bottom-left";break;case _t:l=u,a=g,n="top-left";break;case Et:l=u,a=f,n="top-right"}if(s){if(!("corner"===s&&e%2)){const t=Math.sqrt(Math.abs(a*l));a=a<0?-t:t,l=l<0?-t:t}}return Mt(o||n,t,r),{origin:r,scaleX:a,scaleY:l,direction:e,lockRatio:s,around:o}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case Lt:n="bottom-right";break;case wt:n="bottom-left";break;case _t:n="top-left";break;case Et:n="top-right";break;default:n="center"}return Mt(o||n,t,r),{origin:r,rotation:m.getRotation(s,r,i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,l=0;switch(e){case bt:n={x:.5,y:0},o="bottom",a=1;break;case kt:n={x:.5,y:1},o="top",a=1;break;case xt:n={x:0,y:.5},o="right",l=1;break;case yt:n={x:1,y:.5},o="left",l=1}const{x:h,y:d,width:c,height:g}=t;n.x=h+n.x*c,n.y=d+n.y*g,Mt(s||o,t,r);const u=m.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(l?i.y:0)});return a?a=-u:l=u,{origin:r,skewX:a,skewY:l}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case xt:t=yt;break;case Lt:t=wt;break;case Et:t=_t;break;case yt:t=xt;break;case wt:t=Lt;break;case _t:t=Et}if(i)switch(t){case bt:t=kt;break;case Lt:t=Et;break;case wt:t=_t;break;case kt:t=bt;break;case Et:t=Lt;break;case _t:t=wt}return t}},Tt={};function Vt(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.editing||!i.visible)return;if("circle"===s.name)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:l,rotateable:h,skewable:d}=t.mergeConfig,{pointType:c}=s,{flippedX:g,flippedY:u}=i;let f="resize"===c;f&&h&&(e.metaKey||e.ctrlKey||!l)&&(f=!1);const p=d&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(St.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(b.formatRotation(o,!0)/2);const{url:m,x:v,y:L}=p,w=m+o;Tt[w]?s.cursor=Tt[w]:Tt[w]=s.cursor={url:Ht(m,o),x:v,y:L}}function Ot(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function Ht(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Pt extends a{}const Ct=["top","right","bottom","left"];class It extends r{get flipped(){return this.flippedX||this.flippedY}get flippedX(){return this.scaleX<0}get flippedY(){return this.scaleY<0}get flippedOne(){return this.scaleX*this.scaleY<0}constructor(t){super(),this.view=new r,this.rect=new a({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Pt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new r({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:l,buttons:h}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new Pt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Pt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Pt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);h.add(l),this.listenPointEvents(l,"rotate",2),s.addMany(...n,a,h,...r,...o),this.add(s)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth:a,moveable:l}=t,h=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:h[t/2%h.length])),t%2||(c.rotation=t/2*90);o.set(this.getPointStyle(t.rotatePoint||h[0])),s.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),s.hittable=!i&&l,e.syncEventer=i&&l?s:null,this.app.interaction.bottomList=i&&l?[{target:s,proxy:e}]:null,this.visible=!e.locked}update(t){if(this.view.worldOpacity){const{mergeConfig:e}=this.editor,{width:i,height:s}=t,{rect:o,circle:n,resizePoints:r,rotatePoints:a,resizeLines:l}=this,{middlePoint:h,resizeable:d,rotateable:c,hideOnSmall:g}=e,u="number"==typeof g?g:10,f=!(g&&i<u&&s<u);let p,m,L,b={};for(let o=0;o<8;o++)v.toPoint(v.directionData[o],t,b),m=r[o],p=a[o],L=l[Math.floor(o/2)],m.set(b),p.set(b),L.set(b),m.visible=L.visible=f&&(d||c),p.visible=f&&c&&d&&!e.rotatePoint,o%2&&(m.visible=p.visible=f&&!!h,(o+1)/2%2?(L.width=i,m.width>i-30&&(m.visible=!1)):(L.height=s,m.rotation=90,m.width>s-30&&(m.visible=!1)));n.visible=f&&c&&!!e.rotatePoint,o.set(Object.assign(Object.assign({},t),{visible:!0}));const w=f&&(n.visible||this.buttons.children.length>1);this.buttons.visible=w,w&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.mergeConfig,{flippedX:r,flippedY:a}=this;let l=Ct.indexOf(i);(l%2&&r||(l+1)%2&&a)&&s&&(l=(l+2)%4);const h=s?St.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,d=e[2*h+1],c=h%2,g=h&&3!==h?1:-1,u=(o+(l%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),s&&(t.rotation=90*(h-l),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.mergeConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=this.app.interaction.bottomList=null)}onDragStart(t){if(this.dragging=!0,"rect"===t.current.name){const{editor:t}=this;this.moving=!0,t.dragStartPoint={x:t.element.x,y:t.element.y},t.opacity=t.mergeConfig.hideOnMove?0:1}}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):e.onScale(t),Vt(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(T.START,this.onDragStart,this),t.on_(T.DRAG,this.onDrag,this),t.on_(T.END,this.onDragEnd,this),t.on_(S.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(S.ENTER,(e=>{this.enterPoint=t,Vt(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(J.SELECT,this.onSelect,this),t.on_(T.START,this.onDragStart,this),t.on_(T.DRAG,e.onMove,e),t.on_(T.END,this.onDragEnd,this),t.on_(S.ENTER,(()=>Ot(e))),t.on_(S.DOUBLE_TAP,this.onDoubleTap,this),t.on_(S.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Dt='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',Rt={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${Dt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},rotateCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(135,12,12),rotate({{rotation}},12,12)">\n<path d="M20.4 8H21.4L20.8 7.1L17.3 2.6L17 2.1L16.6 2.6L13.1 7.1L12.5 8H13.5H15.4C14.9 11.8 11.8 14.9 8 15.4V13.5V12.5L7.1 13.1L2.6 16.6L2.1 17L2.6 17.3L7.1 20.8L8 21.4V20.4V18.4C13.5 17.9 17.9 13.5 18.4 8H20.4Z" stroke="white"/>\n<path fill-rule="evenodd" d="M17 3L20.4 7.5H17.9C17.7 13.1 13.1 17.7 7.5 17.9V20.4L3 17L7.5 13.5V15.9C12.0 15.7 15.7 12.0 15.9 7.5H13.5L17 3Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">\n${Dt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},skewCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(90,12,12),rotate({{rotation}},12,12)">\n<path d="M21 10.4L21 11.4L23.8 11.4L21.6 9.6L21 10.4ZM17 10.4V11.4L17 11.4L17 10.4ZM15.5 6L16.1 5.2L14.5 3.9V6H15.5ZM15.5 8.4V9.4H16.5V8.4H15.5ZM6 8.4V7.4H5V8.4H6ZM6 10.4H5V11.4H6V10.4ZM7 14.4V13.4L7 13.4L7 14.4ZM3 14.4L3 13.4L0.1 13.4L2.3 15.2L3 14.4ZM8.5 18.9L7.8 19.7L9.5 21.0V18.9H8.5ZM8.5 16.4V15.4H7.5V16.4H8.5ZM19 16.4V17.4H20V16.4H19ZM19 14.4H20V13.4H19V14.4ZM21 9.4L17 9.4L17 11.4L21 11.4L21 9.4ZM14.8 6.7L20.3 11.2L21.6 9.6L16.1 5.2L14.8 6.7ZM16.5 8.4V6H14.5V8.4H16.5ZM6 9.4H15.5V7.4H6V9.4ZM7 10.4V8.4H5V10.4H7ZM15.5 9.4H6V11.4H15.5V9.4ZM17 9.4H15.5V11.4H17V9.4ZM7 15.4H8.5V13.4H7V15.4ZM3 15.4L7 15.4L7 13.4L3 13.4L3 15.4ZM9.1 18.1L3.6 13.6L2.3 15.2L7.8 19.7L9.1 18.1ZM7.5 16.4V18.9H9.5V16.4H7.5ZM19 15.4H8.5V17.4H19V15.4ZM18 14.4V16.4H20V14.4H18ZM8.5 15.4H19V13.4H8.5V15.4Z" fill="white"/>\n<path fill-rule="evenodd" d="M17 10.4L21 10.4L15.5 6V8.4H6V10.4H15.5H17ZM8.5 14.4H7L3 14.4L8.5 18.9V16.4H19V14.4H8.5Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >\n${Dt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};const At=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Bt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Zt={group(t,e,i){t.sort(Bt);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new r(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(At);const a=new w(e.worldTransform);return a.divideParent(o.worldTransform),n.setTransform(a),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(At),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Bt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},zt=y.get("EditToolCreator");function Wt(){return t=>{Yt.register(t)}}const Xt=Wt,Yt={list:{},register(t){const{tag:e}=t.prototype;Ut[e]?zt.repeat(e):Ut[e]=t},get:(t,e)=>new Ut[t](e)},{list:Ut}=Yt;class Ft extends r{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,e){super(e),this.config=Rt,this.mergeConfig=Rt,this.leafList=new p,this.openedGroupList=new p,this.simulateTarget=new g({visible:!1}),this.editBox=new It(this),this.editToolList={},this.selector=new vt(this),this.targetEventIds=[],t&&(this.config=_.default(t,this.config)),this.addMany(this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||Yt.get(t,this);const{editConfig:e}=this.element;this.mergeConfig=this.single&&e?Object.assign(Object.assign({},this.mergeConfig),e):this.config,this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){const e={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(T.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.mergeConfig;t.shiftKey&&(o=!0);const n=St.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,St.getAround(s,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}onRotate(t){const{skewable:e,around:i,rotateGap:s}=this.mergeConfig,{direction:o,name:n}=t.current;if(e&&"resize-line"===n)return this.onSkew(t);const{element:r}=this;let a,l;if(t instanceof H)l=t.rotation,a=r.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},s=St.getRotateData(r.boxBounds,o,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");l=s.rotation,a=s.origin}l=b.getGapRotation(l,s,r.rotation),l&&(r.scaleX*r.scaleY<0&&(l=-l),this.rotateOf(a,b.float(l,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=St.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),St.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e=0){if(!this.mergeConfig.moveable||this.element.locked)return;const{element:i}=this,s=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),o=new tt(tt.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o),this.multiple&&i.move(t,e)}scaleWithDrag(t){const{element:e}=this,i=e.getWorldPoint(t.origin),s=new et(et.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(s),this.emitEvent(s)}scaleOf(t,e,i=e,s){const{element:o}=this,n=o.getWorldPoint(t);let r;if(this.multiple){const s=new w(o.worldTransform);o.scaleOf(t,e,i),r=new w(o.worldTransform).divide(s)}const a=new et(et.SCALE,{target:o,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(a),this.emitEvent(a)}rotateOf(t,e){const{element:i}=this,s=i.getWorldPoint(t);let o;if(this.multiple){const s=new w(i.worldTransform);i.rotateOf(t,e),o=new w(i.worldTransform).divide(s)}const n=new it(it.ROTATE,{target:i,editor:this,worldOrigin:s,rotation:e,transform:o});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,s){const{element:o}=this,n=o.getWorldPoint(t);let r;if(this.multiple){const s=new w(o.worldTransform);o.skewOf(t,e,i),r=new w(o.worldTransform).divide(s)}const a=new st(st.SKEW,{target:o,editor:this,skewX:e,skewY:i,transform:r,worldOrigin:n});this.editTool.onSkew(a),this.emitEvent(a)}group(t){return this.multiple&&(this.target=Zt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=Zt.ungroup(this.list)),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!k.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}}openInnerEditor(){if(this.single){const t=this.element.editInner;t&&Yt.list[t]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[t]||Yt.get(t,this),this.innerEditor.load())}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.innerEditor.unload(),this.editTool.load(),this.innerEditor=null)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(Zt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Zt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(E.START,this.update,this),t.on_([P.HOLD,P.UP],(t=>{Vt(this,t)})),t.on_(P.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}q([ot((function(t,e){t.emitEvent(new J(J.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Ft.prototype,"hoverTarget",void 0),q([ot((function(t,e){const{target:i}=t;i?t.leafList=i instanceof p?i:new p(i):t.leafList.reset(),t.emitEvent(new J(J.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:i}=t,{x:s,y:o,width:n,height:r}=(new f).setListWithFn(i.list,(t=>t.worldBoxBounds)),a=e.parent=i.list[0].leafer.zoomLayer,{scaleX:l,scaleY:h,e:d,f:c}=a.__world;e.reset({x:(s-d)/l,y:(o-c)/h,width:n/l,height:r/h})}(t),Ot(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],Ft.prototype,"target",void 0);class Gt{static registerInnerEditor(){Yt.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new r,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let jt=class extends Gt{static registerEditTool(){Yt.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="size"===o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{simulateTarget:i,element:s}=t;t.multiple&&i.parent.updateLayout();const{x:o,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d,width:c,height:g}=s.getLayoutBounds("box",t,!0);e.set({x:o,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};jt=q([Wt()],jt);const{left:Kt,right:Nt}=L;let $t=class extends jt{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=x(),{toPoint:a}=n;n.rotation=0;let{x:l,y:h}=e.getInnerMove(n);s&&(Math.abs(l)>Math.abs(h)?h=0:l=0),i===Kt?(r.x+=l,r.y+=h,o&&(a.x-=l,a.y-=h)):(o&&(r.x-=l,r.y-=h),a.x+=l,a.y+=h),n.getLocalPointByInner(r,null,null,!0),n.getLocalPointByInner(a,null,null,!0),n.x=r.x,n.y=r.y,n.getInnerPointByLocal(a,null,null,!0),n.toPoint=a}onSkew(t){}onUpdate(){const{rotatePoints:t,resizeLines:e,resizePoints:i}=this.editor.editBox;for(let s=0;s<8;s++)s<4&&(e[s].visible=!1),i[s].visible=t[s].visible=s===Kt||s===Nt}};$t=q([Wt()],$t),M.editor=function(t){return new Ft(t)},d.setEditConfig=function(t){h(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},d.setEditOuter=function(t){h(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},d.setEditInner=function(t){h(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})},s.setEditOuter((function(t){return t.points||t.pathInputed?"EditTool":"LineEditTool"}));export{It as EditBox,St as EditDataHelper,Pt as EditPoint,vt as EditSelect,pt as EditSelectHelper,jt as EditTool,Yt as EditToolCreator,Ft as Editor,J as EditorEvent,Zt as EditorHelper,tt as EditorMoveEvent,it as EditorRotateEvent,et as EditorScaleEvent,st as EditorSkewEvent,Gt as InnerEditor,$t as LineEditTool,dt as SelectArea,ht as Stroker,Wt as registerEditTool,Xt as registerInnerEditor};
1
+ import{PathCommandMap as t,MatrixHelper as e,Leaf as i,Text as s,Path as o,Line as n,Polygon as r,Group as a,Box as h,Event as l,defineKey as d,UI as c,Paint as g,Rect as u,Answer as f,Bounds as p,LeafList as m,PointHelper as v,AroundHelper as y,Direction9 as b,MathHelper as w,Matrix as L,Debug as _,DataHelper as k,LeafHelper as x,RenderEvent as E,getPointData as M,Creator as S}from"@leafer-ui/draw";import{PointerEvent as T,DragEvent as V,MoveEvent as P,ZoomEvent as O,RotateEvent as H,KeyEvent as I}from"@leafer-ui/core";const{M:C,L:B,C:R,Q:D,Z:A,N:Z,D:z,X:W,G:X,F:Y,O:F,P:U,U:G}=t,j={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case C:case B:K(t,e,i,o,1),o+=3;break;case R:K(t,e,i,o,3),o+=7;break;case D:K(t,e,i,o,2),o+=5;break;case A:o+=1;break;case Z:K(t,e,i,o,2),o+=5;break;case z:K(t,e,i,o,2),o+=9;break;case W:K(t,e,i,o,2),o+=6;break;case X:K(t,e,i,o,2),o+=9;break;case Y:K(t,e,i,o,2),o+=5;break;case F:t[o]=X,t.splice(o+4,0,t[o+3],0),K(t,e,i,o,2),o+=9,n+=2;break;case U:t[o]=Y,t.splice(o+4,0,t[o+3]),K(t,e,i,o,2),o+=5,n+=1;break;case G:K(t,e,i,o,2),o+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:K}=j,N=e.get();function $(t,e,i){t.pathInputed?Q(t,e,i):(t.width*=e,t.height*=i)}function q(t,e,i){1!==e?t.fontSize*=e:1!==i&&(t.fontSize*=i)}function Q(t,e,i){j.scale(t.__.path,e,i),t.path=t.__.path}function J(t,e,i){j.scalePoints(t.__.points,e,i),t.points=t.__.points}function tt(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)N.a=e,N.d=i,s[t].transform(N,!0)}function et(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function it(t){return t?t instanceof Array?t:[t]:[]}i.prototype.scaleResize=function(t,e=t,i){const s=this;i?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},i.prototype.__scaleResize=function(t,e){$(this,t,e)},s.prototype.__scaleResize=function(t,e){this.editConfig&&"font-size"===this.editConfig.editSize?q(this,t,e):$(this,t,e)},o.prototype.__scaleResize=function(t,e){Q(this,t,e)},n.prototype.__scaleResize=function(t,e){if(this.pathInputed)Q(this,t,e);else if(this.points)J(this,t,e);else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},r.prototype.__scaleResize=function(t,e){this.pathInputed?Q(this,t,e):this.points?J(this,t,e):$(this,t,e)},a.prototype.__scaleResize=function(t,e){tt(this,t,e)},h.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?tt(this,t,e):$(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class st extends l{get list(){return it(this.value)}get oldList(){return it(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}st.SELECT="editor.select",st.HOVER="editor.hover";class ot extends st{constructor(t,e){super(t,e)}}ot.MOVE="editor.move";class nt extends st{constructor(t,e){super(t,e)}}nt.SCALE="editor.scale";class rt extends st{constructor(t,e){super(t,e)}}rt.ROTATE="editor.rotate";class at extends st{constructor(t,e){super(t,e)}}function ht(t){return(e,i)=>{const s="_"+i;d(e,i,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}at.SKEW="editor.skew";const lt=e.get(),{abs:dt}=Math,{copy:ct,scale:gt}=e;class ut extends c{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let s;const{stroke:o,strokeWidth:n,fill:r}=this.__,{bounds:a}=e;for(let h=0;h<i.length;h++)if(s=i[h],a&&a.hit(s.__world,e.matrix)){const i=dt(s.__world.scaleX),a=dt(s.__world.scaleY);if(i!==a){ct(lt,s.__world),gt(lt,1/i,1/a),t.setWorld(lt,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:o,y:r,width:h,height:l}=s.__layout.boxBounds;t.rect(o*i,r*a,h*i,l*a)}else t.setWorld(s.__world,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),this.__.strokeWidth=n/dt(s.__world.scaleX);o&&("string"==typeof o?g.stroke(o,this,t):g.strokes(o,this,t)),r&&("string"==typeof r?g.fill(r,this,t):g.fills(r,this,t))}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}et([ht((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],ut.prototype,"target",void 0);class ft extends a{constructor(t){super(t),this.strokeArea=new u({strokeAlign:"center"}),this.fillArea=new u,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:pt,Yes:mt,NoAndSkip:vt,YesAndSkip:yt}=f,bt={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?yt:vt;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?yt:pt;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return mt}return pt}return t.isBranch?vt:pt}},{findOne:wt}=bt;class Lt extends a{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new ut,this.targetStroker=new ut,this.bounds=new p,this.selectArea=new ft,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:s,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.mergeConfig;"press"===e&&this.checkAndSelect(t)}onTap(t){const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i&&this.checkAndSelect(t),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(this.allowDrag(t)){const{editor:e}=this,{stroke:i,area:s}=e.mergeConfig,{x:o,y:n}=t.getInner(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new m(e.app.find(bt.findBounds,s));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(s.get()),o.length){const t=[];this.originList.forEach((e=>{o.has(e)||t.push(e)})),o.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list}}onDragEnd(){this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!wt(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new m(this.editor.editBox.rect)};return wt(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):wt(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(st.HOVER,this.onHover,this),t.on_(st.SELECT,this.onSelect,this),e.on_(T.MOVE,this.onPointerMove,this),e.on_(T.BEFORE_DOWN,this.onBeforeDown,this),e.on_(T.TAP,this.onTap,this),e.on_(V.START,this.onDragStart,this),e.on_(V.DRAG,this.onDrag,this),e.on_(V.END,this.onDragEnd,this),e.on_(P.MOVE,this.onAutoMove,this),e.on_([O.ZOOM,P.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:_t,top:kt,topRight:xt,right:Et,bottomRight:Mt,bottom:St,bottomLeft:Tt,left:Vt}=b,{toPoint:Pt}=y,Ot={getScaleData(t,e,i,s,o){let n,r={},a=1,h=1;const{width:l,height:d}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===l&&(i.x+=.1),Math.abs(i.y)===d&&(i.y+=.1);const c=(-i.y+d)/d,g=(i.x+l)/l,u=(i.y+d)/d,f=(-i.x+l)/l;switch(e){case kt:h=c,n="bottom";break;case Et:a=g,n="left";break;case St:h=u,n="top";break;case Vt:a=f,n="right";break;case _t:h=c,a=f,n="bottom-right";break;case xt:h=c,a=g,n="bottom-left";break;case Mt:h=u,a=g,n="top-left";break;case Tt:h=u,a=f,n="top-right"}if(s){if(!("corner"===s&&e%2)){const t=Math.sqrt(Math.abs(a*h));a=a<0?-t:t,h=h<0?-t:t}}return Pt(o||n,t,r),{origin:r,scaleX:a,scaleY:h,direction:e,lockRatio:s,around:o}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case _t:n="bottom-right";break;case xt:n="bottom-left";break;case Mt:n="top-left";break;case Tt:n="top-right";break;default:n="center"}return Pt(o||n,t,r),{origin:r,rotation:v.getRotation(s,r,i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case kt:n={x:.5,y:0},o="bottom",a=1;break;case St:n={x:.5,y:1},o="top",a=1;break;case Vt:n={x:0,y:.5},o="right",h=1;break;case Et:n={x:1,y:.5},o="left",h=1}const{x:l,y:d,width:c,height:g}=t;n.x=l+n.x*c,n.y=d+n.y*g,Pt(s||o,t,r);const u=v.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(h?i.y:0)});return a?a=-u:h=u,{origin:r,skewX:a,skewY:h}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case Vt:t=Et;break;case _t:t=xt;break;case Tt:t=Mt;break;case Et:t=Vt;break;case xt:t=_t;break;case Mt:t=Tt}if(i)switch(t){case kt:t=St;break;case _t:t=Tt;break;case xt:t=Mt;break;case St:t=kt;break;case Tt:t=_t;break;case Mt:t=xt}return t}},Ht={};function It(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.editing||!i.visible)return;if("circle"===s.name)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:h,rotateable:l,skewable:d}=t.mergeConfig,{pointType:c}=s,{flippedX:g,flippedY:u}=i;let f="resize"===c;f&&l&&(e.metaKey||e.ctrlKey||!h)&&(f=!1);const p=d&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(Ot.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(w.formatRotation(o,!0)/2);const{url:m,x:v,y:y}=p,b=m+o;Ht[b]?s.cursor=Ht[b]:Ht[b]=s.cursor={url:Bt(m,o),x:v,y:y}}function Ct(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function Bt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Rt extends h{}const Dt=["top","right","bottom","left"];class At extends a{get flipped(){return this.flippedX||this.flippedY}get flippedX(){return this.scaleX<0}get flippedY(){return this.scaleY<0}get flippedOne(){return this.scaleX*this.scaleY<0}constructor(t){super(),this.view=new a,this.rect=new h({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Rt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new a({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:h,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new Rt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Rt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Rt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);l.add(h),this.listenPointEvents(h,"rotate",2),s.addMany(...n,a,l,...r,...o),this.add(s)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth:a,moveable:h}=t,l=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:l[t/2%l.length])),t%2||(c.rotation=t/2*90);o.set(this.getPointStyle(t.rotatePoint||l[0])),s.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),s.hittable=!i&&h,e.syncEventer=i&&h?s:null,this.app.interaction.bottomList=i&&h?[{target:s,proxy:e}]:null,this.visible=!e.locked}update(t){if(this.view.worldOpacity){const{mergeConfig:e}=this.editor,{width:i,height:s}=t,{rect:o,circle:n,resizePoints:r,rotatePoints:a,resizeLines:h}=this,{middlePoint:l,resizeable:d,rotateable:c,hideOnSmall:g}=e,u="number"==typeof g?g:10,f=!(g&&i<u&&s<u);let p,m,v,b={};for(let o=0;o<8;o++)y.toPoint(y.directionData[o],t,b),m=r[o],p=a[o],v=h[Math.floor(o/2)],m.set(b),p.set(b),v.set(b),m.visible=v.visible=f&&(d||c),p.visible=f&&c&&d&&!e.rotatePoint,o%2&&(m.visible=p.visible=f&&!!l,(o+1)/2%2?(v.width=i,m.width>i-30&&(m.visible=!1)):(v.height=s,m.rotation=90,m.width>s-30&&(m.visible=!1)));n.visible=f&&c&&!!e.rotatePoint,o.path&&(o.path=null),o.set(Object.assign(Object.assign({},t),{visible:!0}));const w=f&&(n.visible||this.buttons.children.length>1);this.buttons.visible=w,w&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.mergeConfig,{flippedX:r,flippedY:a}=this;let h=Dt.indexOf(i);(h%2&&r||(h+1)%2&&a)&&s&&(h=(h+2)%4);const l=s?Ot.getRotateDirection(h,this.flippedOne?this.rotation:-this.rotation,4):h,d=e[2*l+1],c=l%2,g=l&&3!==l?1:-1,u=(o+(h%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),s&&(t.rotation=90*(l-h),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.mergeConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=this.app.interaction.bottomList=null)}onDragStart(t){if(this.dragging=!0,"rect"===t.current.name){const{editor:t}=this;this.moving=!0,t.dragStartPoint={x:t.element.x,y:t.element.y},t.opacity=t.mergeConfig.hideOnMove?0:1}}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):e.onScale(t),It(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(V.START,this.onDragStart,this),t.on_(V.DRAG,this.onDrag,this),t.on_(V.END,this.onDragEnd,this),t.on_(T.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(T.ENTER,(e=>{this.enterPoint=t,It(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(st.SELECT,this.onSelect,this),t.on_(V.START,this.onDragStart,this),t.on_(V.DRAG,e.onMove,e),t.on_(V.END,this.onDragEnd,this),t.on_(T.ENTER,(()=>Ct(e))),t.on_(T.DOUBLE_TAP,this.onDoubleTap,this),t.on_(T.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Zt='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',zt={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${Zt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},rotateCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(135,12,12),rotate({{rotation}},12,12)">\n<path d="M20.4 8H21.4L20.8 7.1L17.3 2.6L17 2.1L16.6 2.6L13.1 7.1L12.5 8H13.5H15.4C14.9 11.8 11.8 14.9 8 15.4V13.5V12.5L7.1 13.1L2.6 16.6L2.1 17L2.6 17.3L7.1 20.8L8 21.4V20.4V18.4C13.5 17.9 17.9 13.5 18.4 8H20.4Z" stroke="white"/>\n<path fill-rule="evenodd" d="M17 3L20.4 7.5H17.9C17.7 13.1 13.1 17.7 7.5 17.9V20.4L3 17L7.5 13.5V15.9C12.0 15.7 15.7 12.0 15.9 7.5H13.5L17 3Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">\n${Zt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},skewCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(90,12,12),rotate({{rotation}},12,12)">\n<path d="M21 10.4L21 11.4L23.8 11.4L21.6 9.6L21 10.4ZM17 10.4V11.4L17 11.4L17 10.4ZM15.5 6L16.1 5.2L14.5 3.9V6H15.5ZM15.5 8.4V9.4H16.5V8.4H15.5ZM6 8.4V7.4H5V8.4H6ZM6 10.4H5V11.4H6V10.4ZM7 14.4V13.4L7 13.4L7 14.4ZM3 14.4L3 13.4L0.1 13.4L2.3 15.2L3 14.4ZM8.5 18.9L7.8 19.7L9.5 21.0V18.9H8.5ZM8.5 16.4V15.4H7.5V16.4H8.5ZM19 16.4V17.4H20V16.4H19ZM19 14.4H20V13.4H19V14.4ZM21 9.4L17 9.4L17 11.4L21 11.4L21 9.4ZM14.8 6.7L20.3 11.2L21.6 9.6L16.1 5.2L14.8 6.7ZM16.5 8.4V6H14.5V8.4H16.5ZM6 9.4H15.5V7.4H6V9.4ZM7 10.4V8.4H5V10.4H7ZM15.5 9.4H6V11.4H15.5V9.4ZM17 9.4H15.5V11.4H17V9.4ZM7 15.4H8.5V13.4H7V15.4ZM3 15.4L7 15.4L7 13.4L3 13.4L3 15.4ZM9.1 18.1L3.6 13.6L2.3 15.2L7.8 19.7L9.1 18.1ZM7.5 16.4V18.9H9.5V16.4H7.5ZM19 15.4H8.5V17.4H19V15.4ZM18 14.4V16.4H20V14.4H18ZM8.5 15.4H19V13.4H8.5V15.4Z" fill="white"/>\n<path fill-rule="evenodd" d="M17 10.4L21 10.4L15.5 6V8.4H6V10.4H15.5H17ZM8.5 14.4H7L3 14.4L8.5 18.9V16.4H19V14.4H8.5Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >\n${Zt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};const Wt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Xt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Yt={group(t,e,i){t.sort(Xt);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new a(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(Wt);const r=new L(e.worldTransform);return r.divideParent(o.worldTransform),n.setTransform(r),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(Wt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Xt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},Ft=_.get("EditToolCreator");function Ut(){return t=>{jt.register(t)}}const Gt=Ut,jt={list:{},register(t){const{tag:e}=t.prototype;Kt[e]?Ft.repeat(e):Kt[e]=t},get:(t,e)=>new Kt[t](e)},{list:Kt}=jt;class Nt extends a{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,e){super(e),this.config=zt,this.mergeConfig=zt,this.leafList=new m,this.openedGroupList=new m,this.simulateTarget=new u({visible:!1}),this.editBox=new At(this),this.editToolList={},this.selector=new Lt(this),this.targetEventIds=[],t&&(this.config=k.default(t,this.config)),this.addMany(this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||jt.get(t,this);const{editConfig:e}=this.element;this.mergeConfig=this.single&&e?Object.assign(Object.assign({},this.mergeConfig),e):this.config,this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){const e={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(V.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.mergeConfig;t.shiftKey&&(o=!0);const n=Ot.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,Ot.getAround(s,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}onRotate(t){const{skewable:e,around:i,rotateGap:s}=this.mergeConfig,{direction:o,name:n}=t.current;if(e&&"resize-line"===n)return this.onSkew(t);const{element:r}=this;let a,h;if(t instanceof H)h=t.rotation,a=r.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},s=Ot.getRotateData(r.boxBounds,o,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");h=s.rotation,a=s.origin}h=w.getGapRotation(h,s,r.rotation),h&&(r.scaleX*r.scaleY<0&&(h=-h),this.rotateOf(a,w.float(h,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=Ot.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Ot.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e=0){if(!this.mergeConfig.moveable||this.element.locked)return;const{element:i}=this,s=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),o=new ot(ot.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o),this.multiple&&i.move(t,e)}scaleWithDrag(t){const{element:e}=this,i=e.getWorldPoint(t.origin),s=new nt(nt.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(s),this.emitEvent(s)}scaleOf(t,e,i=e,s){const{element:o}=this,n=o.getWorldPoint(t);let r;if(this.multiple){const s=new L(o.worldTransform);o.scaleOf(t,e,i),r=new L(o.worldTransform).divide(s)}const a=new nt(nt.SCALE,{target:o,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(a),this.emitEvent(a)}rotateOf(t,e){const{element:i}=this,s=i.getWorldPoint(t);let o;if(this.multiple){const s=new L(i.worldTransform);i.rotateOf(t,e),o=new L(i.worldTransform).divide(s)}const n=new rt(rt.ROTATE,{target:i,editor:this,worldOrigin:s,rotation:e,transform:o});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,s){const{element:o}=this,n=o.getWorldPoint(t);let r;if(this.multiple){const s=new L(o.worldTransform);o.skewOf(t,e,i),r=new L(o.worldTransform).divide(s)}const a=new at(at.SKEW,{target:o,editor:this,skewX:e,skewY:i,transform:r,worldOrigin:n});this.editTool.onSkew(a),this.emitEvent(a)}group(t){return this.multiple&&(this.target=Yt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=Yt.ungroup(this.list)),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!x.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}}openInnerEditor(){if(this.single){const t=this.element.editInner;t&&jt.list[t]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[t]||jt.get(t,this),this.innerEditor.load())}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.innerEditor.unload(),this.editTool.load(),this.innerEditor=null)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(Yt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Yt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(E.START,this.update,this),t.on_([I.HOLD,I.UP],(t=>{It(this,t)})),t.on_(I.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}et([ht((function(t,e){t.emitEvent(new st(st.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Nt.prototype,"hoverTarget",void 0),et([ht((function(t,e){const{target:i}=t;i?t.leafList=i instanceof m?i:new m(i):t.leafList.reset(),t.emitEvent(new st(st.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:i}=t,{x:s,y:o,width:n,height:r}=(new p).setListWithFn(i.list,(t=>t.worldBoxBounds)),a=e.parent=i.list[0].leafer.zoomLayer,{scaleX:h,scaleY:l,e:d,f:c}=a.__world;e.reset({x:(s-d)/h,y:(o-c)/l,width:n/h,height:r/l})}(t),Ct(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],Nt.prototype,"target",void 0);class $t{static registerInnerEditor(){jt.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new a,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let qt=class extends $t{static registerEditTool(){jt.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="scale"!==o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{simulateTarget:i,element:s}=t;t.multiple&&i.parent.updateLayout();const{x:o,y:n,scaleX:r,scaleY:a,rotation:h,skewX:l,skewY:d,width:c,height:g}=s.getLayoutBounds("box",t,!0);e.set({x:o,y:n,scaleX:r,scaleY:a,rotation:h,skewX:l,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};qt=et([Ut()],qt);const{left:Qt,right:Jt}=b,{move:te,copy:ee}=v;let ie=class extends qt{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=i===Qt;if(n.pathInputed){const{path:t}=n.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,n.points=t}else{const t=M(),{toPoint:i}=n;n.rotation=0,this.dragPoint(t,i,r,o,this.getInnerMove(n,e,s)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(i,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(i,null,null,!0),n.toPoint=i}}getInnerMove(t,e,i){const s=e.getInnerMove(t);return i&&(Math.abs(s.x)>Math.abs(s.y)?s.y=0:s.x=0),s}getFromToByPath(t){return{from:{x:t[1],y:t[2]},to:{x:t[4],y:t[5]}}}getFromToByPoints(t){return{from:{x:t[0],y:t[1]},to:{x:t[2],y:t[3]}}}dragPoint(t,e,i,s,o){const{x:n,y:r}=o;i?(te(t,n,r),s&&te(e,-n,-r)):(s&&te(t,-n,-r),te(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,n=this.editor.element;let r,a;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:a}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(a,a,!1,t),o.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),ee(s[7],i),ee(e[7],i),ee(s[3],a),ee(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===Qt||t===Jt,s[t].visible=a,e[t].visible=!r&&a}};ie=et([Ut()],ie),S.editor=function(t){return new Nt(t)},c.setEditConfig=function(t){d(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},c.setEditOuter=function(t){d(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},c.setEditInner=function(t){d(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})};export{At as EditBox,Ot as EditDataHelper,Rt as EditPoint,Lt as EditSelect,bt as EditSelectHelper,qt as EditTool,jt as EditToolCreator,Nt as Editor,st as EditorEvent,Yt as EditorHelper,ot as EditorMoveEvent,rt as EditorRotateEvent,nt as EditorScaleEvent,at as EditorSkewEvent,$t as InnerEditor,ie as LineEditTool,j as PathScaler,ft as SelectArea,ut as Stroker,Ut as registerEditTool,Gt as registerInnerEditor,$ as scaleResize,q as scaleResizeFont,tt as scaleResizeGroup,Q as scaleResizePath,J as scaleResizePoints};
package/dist/editor.js CHANGED
@@ -81,6 +81,39 @@ this.LeaferIN.editor = (function (exports, draw, core) {
81
81
  };
82
82
  const { scalePoints } = PathScaler;
83
83
 
84
+ const matrix$1 = draw.MatrixHelper.get();
85
+ function scaleResize(leaf, scaleX, scaleY) {
86
+ if (leaf.pathInputed) {
87
+ scaleResizePath(leaf, scaleX, scaleY);
88
+ }
89
+ else {
90
+ leaf.width *= scaleX;
91
+ leaf.height *= scaleY;
92
+ }
93
+ }
94
+ function scaleResizeFont(leaf, scaleX, scaleY) {
95
+ if (scaleX !== 1)
96
+ leaf.fontSize *= scaleX;
97
+ else if (scaleY !== 1)
98
+ leaf.fontSize *= scaleY;
99
+ }
100
+ function scaleResizePath(leaf, scaleX, scaleY) {
101
+ PathScaler.scale(leaf.__.path, scaleX, scaleY);
102
+ leaf.path = leaf.__.path;
103
+ }
104
+ function scaleResizePoints(leaf, scaleX, scaleY) {
105
+ PathScaler.scalePoints(leaf.__.points, scaleX, scaleY);
106
+ leaf.points = leaf.__.points;
107
+ }
108
+ function scaleResizeGroup(group, scaleX, scaleY) {
109
+ const { children } = group;
110
+ for (let i = 0; i < children.length; i++) {
111
+ matrix$1.a = scaleX;
112
+ matrix$1.d = scaleY;
113
+ children[i].transform(matrix$1, true);
114
+ }
115
+ }
116
+
84
117
  draw.Leaf.prototype.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
85
118
  const data = this;
86
119
  if (noResize) {
@@ -95,23 +128,26 @@ this.LeaferIN.editor = (function (exports, draw, core) {
95
128
  this.__scaleResize(scaleX, scaleY);
96
129
  }
97
130
  };
98
- function scaleResize(leaf, scaleX, scaleY) {
99
- if (scaleX !== 1)
100
- leaf.width *= scaleX;
101
- if (scaleY !== 1)
102
- leaf.height *= scaleY;
103
- }
104
131
  draw.Leaf.prototype.__scaleResize = function (scaleX, scaleY) {
105
132
  scaleResize(this, scaleX, scaleY);
106
133
  };
134
+ draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
135
+ if (this.editConfig && this.editConfig.editSize === 'font-size') {
136
+ scaleResizeFont(this, scaleX, scaleY);
137
+ }
138
+ else {
139
+ scaleResize(this, scaleX, scaleY);
140
+ }
141
+ };
107
142
  draw.Path.prototype.__scaleResize = function (scaleX, scaleY) {
108
- PathScaler.scale(this.__.path, scaleX, scaleY);
109
- this.path = this.__.path;
143
+ scaleResizePath(this, scaleX, scaleY);
110
144
  };
111
145
  draw.Line.prototype.__scaleResize = function (scaleX, scaleY) {
112
- if (this.points) {
113
- PathScaler.scalePoints(this.__.points, scaleX, scaleY);
114
- this.points = this.__.points;
146
+ if (this.pathInputed) {
147
+ scaleResizePath(this, scaleX, scaleY);
148
+ }
149
+ else if (this.points) {
150
+ scaleResizePoints(this, scaleX, scaleY);
115
151
  }
116
152
  else {
117
153
  const point = this.toPoint;
@@ -121,29 +157,22 @@ this.LeaferIN.editor = (function (exports, draw, core) {
121
157
  }
122
158
  };
123
159
  draw.Polygon.prototype.__scaleResize = function (scaleX, scaleY) {
124
- if (this.points) {
125
- PathScaler.scalePoints(this.__.points, scaleX, scaleY);
126
- this.points = this.__.points;
160
+ if (this.pathInputed) {
161
+ scaleResizePath(this, scaleX, scaleY);
162
+ }
163
+ else if (this.points) {
164
+ scaleResizePoints(this, scaleX, scaleY);
127
165
  }
128
166
  else {
129
167
  scaleResize(this, scaleX, scaleY);
130
168
  }
131
169
  };
132
- const matrix$1 = draw.MatrixHelper.get();
133
- function groupScaleResize(group, scaleX, scaleY) {
134
- const { children } = group;
135
- for (let i = 0; i < children.length; i++) {
136
- matrix$1.a = scaleX;
137
- matrix$1.d = scaleY;
138
- children[i].transform(matrix$1, true);
139
- }
140
- }
141
170
  draw.Group.prototype.__scaleResize = function (scaleX, scaleY) {
142
- groupScaleResize(this, scaleX, scaleY);
171
+ scaleResizeGroup(this, scaleX, scaleY);
143
172
  };
144
173
  draw.Box.prototype.__scaleResize = function (scaleX, scaleY) {
145
174
  if (this.__.__autoSize && this.children.length) {
146
- groupScaleResize(this, scaleX, scaleY);
175
+ scaleResizeGroup(this, scaleX, scaleY);
147
176
  }
148
177
  else {
149
178
  scaleResize(this, scaleX, scaleY);
@@ -238,7 +267,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
238
267
 
239
268
  const matrix = draw.MatrixHelper.get();
240
269
  const { abs } = Math;
241
- const { copy, scale } = draw.MatrixHelper;
270
+ const { copy: copy$1, scale } = draw.MatrixHelper;
242
271
  class Stroker extends draw.UI {
243
272
  constructor() {
244
273
  super();
@@ -261,7 +290,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
261
290
  if (bounds && bounds.hit(leaf.__world, options.matrix)) {
262
291
  const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
263
292
  if (aScaleX !== aScaleY) {
264
- copy(matrix, leaf.__world);
293
+ copy$1(matrix, leaf.__world);
265
294
  scale(matrix, 1 / aScaleX, 1 / aScaleY);
266
295
  canvas.setWorld(matrix, options.matrix);
267
296
  canvas.beginPath();
@@ -854,6 +883,8 @@ this.LeaferIN.editor = (function (exports, draw, core) {
854
883
  }
855
884
  }
856
885
  circle.visible = showPoints && rotateable && !!mergeConfig.rotatePoint;
886
+ if (rect.path)
887
+ rect.path = null;
857
888
  rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
858
889
  const buttonVisible = showPoints && (circle.visible || this.buttons.children.length > 1);
859
890
  this.buttons.visible = buttonVisible;
@@ -1554,7 +1585,7 @@ ${filterStyle}
1554
1585
  const { app, list } = editor;
1555
1586
  app.lockLayout();
1556
1587
  list.forEach(target => {
1557
- const resize = editor.getEditSize(target) === 'size';
1588
+ const resize = editor.getEditSize(target) !== 'scale';
1558
1589
  if (transform) {
1559
1590
  target.transformWorld(transform, resize);
1560
1591
  }
@@ -1569,7 +1600,7 @@ ${filterStyle}
1569
1600
  const { app, list } = editor;
1570
1601
  app.lockLayout();
1571
1602
  list.forEach(target => {
1572
- const resize = editor.getEditSize(target) === 'size';
1603
+ const resize = editor.getEditSize(target) !== 'scale';
1573
1604
  if (transform) {
1574
1605
  target.transformWorld(transform, resize);
1575
1606
  }
@@ -1584,7 +1615,7 @@ ${filterStyle}
1584
1615
  const { app, list } = editor;
1585
1616
  app.lockLayout();
1586
1617
  list.forEach(target => {
1587
- const resize = editor.getEditSize(target) === 'size';
1618
+ const resize = editor.getEditSize(target) !== 'scale';
1588
1619
  if (transform) {
1589
1620
  target.transformWorld(transform, resize);
1590
1621
  }
@@ -1618,6 +1649,7 @@ ${filterStyle}
1618
1649
  ], exports.EditTool);
1619
1650
 
1620
1651
  const { left, right } = draw.Direction9;
1652
+ const { move, copy } = draw.PointHelper;
1621
1653
  exports.LineEditTool = class LineEditTool extends exports.EditTool {
1622
1654
  constructor() {
1623
1655
  super(...arguments);
@@ -1626,50 +1658,100 @@ ${filterStyle}
1626
1658
  get tag() { return 'LineEditTool'; }
1627
1659
  onScaleWithDrag(e) {
1628
1660
  const { drag, direction, lockRatio, around } = e;
1629
- const target = e.target;
1630
- const fromPoint = draw.getPointData();
1631
- const { toPoint } = target;
1632
- target.rotation = 0;
1633
- let { x, y } = drag.getInnerMove(target);
1661
+ const line = e.target;
1662
+ const isDragFrom = direction === left;
1663
+ if (line.pathInputed) {
1664
+ const { path } = line.__;
1665
+ const { from, to } = this.getFromToByPath(path);
1666
+ this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
1667
+ path[1] = from.x, path[2] = from.y;
1668
+ path[4] = to.x, path[5] = to.y;
1669
+ line.path = path;
1670
+ }
1671
+ else if (line.points) {
1672
+ const { points } = line;
1673
+ const { from, to } = this.getFromToByPoints(points);
1674
+ this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
1675
+ points[0] = from.x, points[1] = from.y;
1676
+ points[2] = to.x, points[3] = to.y;
1677
+ line.points = points;
1678
+ }
1679
+ else {
1680
+ const from = draw.getPointData();
1681
+ const { toPoint } = line;
1682
+ line.rotation = 0;
1683
+ this.dragPoint(from, toPoint, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
1684
+ line.getLocalPointByInner(from, null, null, true);
1685
+ line.getLocalPointByInner(toPoint, null, null, true);
1686
+ line.x = from.x;
1687
+ line.y = from.y;
1688
+ line.getInnerPointByLocal(toPoint, null, null, true);
1689
+ line.toPoint = toPoint;
1690
+ }
1691
+ }
1692
+ getInnerMove(ui, event, lockRatio) {
1693
+ const movePoint = event.getInnerMove(ui);
1634
1694
  if (lockRatio) {
1635
- if (Math.abs(x) > Math.abs(y)) {
1636
- y = 0;
1695
+ if (Math.abs(movePoint.x) > Math.abs(movePoint.y)) {
1696
+ movePoint.y = 0;
1637
1697
  }
1638
1698
  else {
1639
- x = 0;
1699
+ movePoint.x = 0;
1640
1700
  }
1641
1701
  }
1642
- if (direction === left) {
1643
- fromPoint.x += x;
1644
- fromPoint.y += y;
1645
- if (around) {
1646
- toPoint.x -= x;
1647
- toPoint.y -= y;
1648
- }
1702
+ return movePoint;
1703
+ }
1704
+ getFromToByPath(path) {
1705
+ return {
1706
+ from: { x: path[1], y: path[2] },
1707
+ to: { x: path[4], y: path[5] }
1708
+ };
1709
+ }
1710
+ getFromToByPoints(points) {
1711
+ return {
1712
+ from: { x: points[0], y: points[1] },
1713
+ to: { x: points[2], y: points[3] }
1714
+ };
1715
+ }
1716
+ dragPoint(fromPoint, toPoint, isDragFrom, around, movePoint) {
1717
+ const { x, y } = movePoint;
1718
+ if (isDragFrom) {
1719
+ move(fromPoint, x, y);
1720
+ if (around)
1721
+ move(toPoint, -x, -y);
1649
1722
  }
1650
1723
  else {
1651
- if (around) {
1652
- fromPoint.x -= x;
1653
- fromPoint.y -= y;
1654
- }
1655
- toPoint.x += x;
1656
- toPoint.y += y;
1724
+ if (around)
1725
+ move(fromPoint, -x, -y);
1726
+ move(toPoint, x, y);
1657
1727
  }
1658
- target.getLocalPointByInner(fromPoint, null, null, true);
1659
- target.getLocalPointByInner(toPoint, null, null, true);
1660
- target.x = fromPoint.x;
1661
- target.y = fromPoint.y;
1662
- target.getInnerPointByLocal(toPoint, null, null, true);
1663
- target.toPoint = toPoint;
1664
1728
  }
1665
1729
  onSkew(_e) {
1666
1730
  }
1667
1731
  onUpdate() {
1668
- const { rotatePoints, resizeLines, resizePoints } = this.editor.editBox;
1732
+ const { editBox } = this, { rotatePoints, resizeLines, resizePoints, rect } = editBox;
1733
+ const line = this.editor.element;
1734
+ let fromTo, leftOrRight;
1735
+ if (line.pathInputed)
1736
+ fromTo = this.getFromToByPath(line.__.path);
1737
+ else if (line.points)
1738
+ fromTo = this.getFromToByPoints(line.__.points);
1739
+ if (fromTo) {
1740
+ const { from, to } = fromTo;
1741
+ line.innerToWorld(from, from, false, editBox);
1742
+ line.innerToWorld(to, to, false, editBox);
1743
+ rect.pen.clearPath().moveTo(from.x, from.y).lineTo(to.x, to.y);
1744
+ copy(resizePoints[7], from);
1745
+ copy(rotatePoints[7], from);
1746
+ copy(resizePoints[3], to);
1747
+ copy(rotatePoints[3], to);
1748
+ }
1669
1749
  for (let i = 0; i < 8; i++) {
1670
1750
  if (i < 4)
1671
1751
  resizeLines[i].visible = false;
1672
- resizePoints[i].visible = rotatePoints[i].visible = (i === left || i === right);
1752
+ leftOrRight = i === left || i === right;
1753
+ resizePoints[i].visible = leftOrRight;
1754
+ rotatePoints[i].visible = fromTo ? false : leftOrRight;
1673
1755
  }
1674
1756
  }
1675
1757
  };
@@ -1693,9 +1775,6 @@ ${filterStyle}
1693
1775
  get() { return typeof editorName === 'string' ? editorName : editorName(this); }
1694
1776
  });
1695
1777
  };
1696
- draw.Line.setEditOuter(function (line) {
1697
- return (line.points || line.pathInputed) ? 'EditTool' : 'LineEditTool';
1698
- });
1699
1778
 
1700
1779
  exports.EditBox = EditBox;
1701
1780
  exports.EditDataHelper = EditDataHelper;
@@ -1711,10 +1790,16 @@ ${filterStyle}
1711
1790
  exports.EditorScaleEvent = EditorScaleEvent;
1712
1791
  exports.EditorSkewEvent = EditorSkewEvent;
1713
1792
  exports.InnerEditor = InnerEditor;
1793
+ exports.PathScaler = PathScaler;
1714
1794
  exports.SelectArea = SelectArea;
1715
1795
  exports.Stroker = Stroker;
1716
1796
  exports.registerEditTool = registerEditTool;
1717
1797
  exports.registerInnerEditor = registerInnerEditor;
1798
+ exports.scaleResize = scaleResize;
1799
+ exports.scaleResizeFont = scaleResizeFont;
1800
+ exports.scaleResizeGroup = scaleResizeGroup;
1801
+ exports.scaleResizePath = scaleResizePath;
1802
+ exports.scaleResizePoints = scaleResizePoints;
1718
1803
 
1719
1804
  return exports;
1720
1805