@leafer-in/editor 1.0.0-rc.3 → 1.0.0-rc.30

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.
Files changed (41) hide show
  1. package/dist/editor.cjs +1937 -0
  2. package/dist/editor.esm.js +1822 -422
  3. package/dist/editor.esm.min.js +1 -1
  4. package/dist/editor.js +1848 -428
  5. package/dist/editor.min.cjs +1 -0
  6. package/dist/editor.min.js +1 -1
  7. package/package.json +12 -9
  8. package/src/Editor.ts +396 -145
  9. package/src/config.ts +38 -0
  10. package/src/decorator/data.ts +16 -0
  11. package/src/display/EditBox.ts +342 -0
  12. package/src/display/EditMask.ts +37 -0
  13. package/src/display/EditPoint.ts +9 -0
  14. package/src/display/EditSelect.ts +255 -0
  15. package/src/display/SelectArea.ts +30 -0
  16. package/src/display/Stroker.ts +92 -0
  17. package/src/editor/cursor.ts +45 -0
  18. package/src/editor/simulate.ts +14 -0
  19. package/src/editor/target.ts +39 -0
  20. package/src/event/EditorEvent.ts +33 -0
  21. package/src/event/EditorGroupEvent.ts +23 -0
  22. package/src/event/EditorMoveEvent.ts +17 -0
  23. package/src/event/EditorRotateEvent.ts +4 -10
  24. package/src/event/EditorScaleEvent.ts +28 -0
  25. package/src/event/EditorSkewEvent.ts +18 -0
  26. package/src/event/InnerEditorEvent.ts +23 -0
  27. package/src/helper/EditDataHelper.ts +183 -0
  28. package/src/helper/EditSelectHelper.ts +34 -0
  29. package/src/helper/EditorHelper.ts +73 -0
  30. package/src/index.ts +50 -3
  31. package/src/svg.ts +54 -0
  32. package/src/tool/EditTool.ts +99 -0
  33. package/src/tool/EditToolCreator.ts +32 -0
  34. package/src/tool/InnerEditor.ts +68 -0
  35. package/src/tool/LineEditTool.ts +135 -0
  36. package/types/index.d.ts +293 -45
  37. package/src/cursor.ts +0 -57
  38. package/src/event/EditorResizeEvent.ts +0 -34
  39. package/src/resize.ts +0 -87
  40. package/src/tool/LineTool.ts +0 -88
  41. package/src/tool/RectTool.ts +0 -139
@@ -1 +1 @@
1
- import{MatrixHelper as t,Bounds as e,Matrix as i,Event as s,Group as o,Rect as r,Polygon as n,DataHelper as a,RotateEvent as h,PointHelper as l,MathHelper as c,DragEvent as g,PointerEvent as y,RenderEvent as d,KeyEvent as u}from"@leafer-ui/core";var _;!function(t){t[t.topLeft=0]="topLeft",t[t.top=1]="top",t[t.topRight=2]="topRight",t[t.right=3]="right",t[t.bottomRight=4]="bottomRight",t[t.bottom=5]="bottom",t[t.bottomLeft=6]="bottomLeft",t[t.left=7]="left"}(_||(_={}));const{scaleOfOuter:x,reset:b}=t,{topLeft:v,top:f,topRight:p,right:z,bottomRight:R,bottom:w,bottomLeft:m,left:E}=_,M={};const{topLeft:P,top:T,topRight:L,right:k,bottomRight:I,bottom:F,bottomLeft:O,left:D}=_;function X(t,e){const i=t.enterPoint;if(!i||!t.target||!t.visible)return;let{rotation:s}=t,{resizeCursor:o,rotateCursor:r,resizeable:n}=t.config;const a=t.tool.getMirrorData(t),{__direction:h,__isResizePoint:l}=i.__;t.enterPoint=i,l&&(e.metaKey||e.ctrlKey||!n)&&(o=r),(a.x||a.y)&&(Y(o=[...o],a.x,a.y),Y(r=[...r],a.y,a.x),a.x+a.y===1&&(s=-s));let c=(h+Math.round(s/45))%8;c<0&&(c+=8),i.cursor=l?o[c]:r[c]}function Y(t,e,i){if(e){const e=t[T],i=t[P],s=t[L];t[T]=t[F],t[P]=t[O],t[L]=t[I],t[F]=e,t[O]=i,t[I]=s}if(i){const e=t[D],i=t[P],s=t[O];t[D]=t[k],t[P]=t[L],t[O]=t[I],t[k]=e,t[L]=i,t[I]=s}}const A={name:"RectTool",getMirrorData(t){const{scaleX:e,scaleY:i}=t.target;return{x:e<0?1:0,y:i<0?1:0}},resize(t){const{target:e,bounds:i,resizeType:s,old:o}=t,{x:r,y:n,width:a,height:h}=i,l={x:r-o.x,y:n-o.y};e.innerToWorld(l,null,!0,e.parent),e.x+=l.x,e.y+=l.y,"scale"===s?(e.scaleX*=a/o.width,e.scaleY*=h/o.height):(a<0?(e.width=-a,e.scaleX*=-1):e.width!==a&&(e.width=a),h<0?(e.height=-h,e.scaleY*=-1):e.height!==h&&(e.height=h))},rotate(t){const{target:e,rotation:i,origin:s}=t;e.rotateOf(s,i)},update(t){const{target:s,config:o,rotatePoints:r,targetRect:n,rect:a,circle:h,resizeLines:l,resizePoints:c}=t,{type:g,resizeable:y,rotateable:d,stroke:u,pointFill:_,pointSize:x,pointRadius:b}=o,v={fill:_,stroke:u,width:x,height:x,cornerRadius:b},f=o.point instanceof Array?o.point:[o.point||v],p=new e(s.boxBounds),z=s.worldTransform,R=t.parent.worldTransform,w=new i(z);w.divide(R);const m=w.e,E=w.f;let{scaleX:M,scaleY:P,rotation:T,skewX:L,skewY:k}=z;M/=R.scaleX,P/=R.scaleY,T-=R.rotation,L-=R.skewX,k-=R.skewY;const{x:I,y:F,width:O,height:D}=p.scale(M,P);t.set({x:m,y:E,rotation:T,skewX:L,skewY:k}),n.set({x:I,y:F,width:p.width/M,height:p.height/P,scaleX:M,scaleY:P,visible:!0});const X=[{x:I,y:F},{x:I+O/2,y:F},{x:I+O,y:F},{x:I+O,y:F+D/2},{x:I+O,y:F+D},{x:I+O/2,y:F+D},{x:I,y:F+D},{x:I,y:F+D/2}],Y=[];let A,C,K,B,S;for(let t=0;t<8;t++)A=X[t],C=f[t%f.length],B=c[t],S=l[Math.floor(t/2)],K=r[t],B.set(C),B.x=K.x=S.x=A.x,B.y=K.y=S.y=A.y,B.visible=S.visible=y||d,K.visible=d&&y,t%2?((t+1)/2%2?(S.width=Math.abs(O),K.width=Math.max(10,Math.abs(O)-30)):(S.height=Math.abs(D),K.height=Math.max(10,Math.abs(D)-30)),B.rotation=90,B.visible="mobile"===g):Y.push(A.x,A.y);C=o.rotatePoint||C,h.set(C),h.x=I+O/2,C.y||(h.y=F-(10+(B.height+h.height)/2)*(this.getMirrorData(t).y?-1:1)),h.visible=d&&"mobile"===g,a.set(o.rect||{stroke:u}),a.points=Y,a.visible=!0}},{left:C,right:K}=_,B={name:"LineTool",getMirrorData:t=>({x:0,y:0}),resize(t){const{direction:e,dragEvent:i,lockRatio:s,around:o}=t,r=t.target,n={x:0,y:0},{toPoint:a}=r;r.rotation=0;let{x:h,y:l}=i.getInnerMove(r);s&&(Math.abs(h)>Math.abs(l)?l=0:h=0),e===C?(n.x+=h,n.y+=l,o&&(a.x-=h,a.y-=l)):(o&&(n.x-=h,n.y-=l),a.x+=h,a.y+=l),r.getLocalPointByInner(n,null,null,!0),r.getLocalPointByInner(a,null,null,!0),r.x=n.x,r.y=n.y,r.getInnerPointByLocal(a,null,null,!0),r.toPoint=a},rotate(t){A.rotate(t)},update(t){const{rotatePoints:e,circle:i,resizeLines:s,resizePoints:o}=t;A.update(t);for(let t=0;t<8;t++)t<4&&(s[t].visible=!1),o[t].visible=e[t].visible=t===C||t===K;i.visible=!1}};class S extends s{constructor(t,e){super(t),e&&Object.assign(this,e)}}S.RESIZE="editor.resize";class j extends s{constructor(t,e){super(t),e&&Object.assign(this,e)}}j.ROTATE="editor.rotate";class G extends o{get target(){return this._target}set target(t){this.__removeTargetEvents(),this.visible=!!t,this._target=t,t&&this.onTarget()}constructor(t,e){super(e),this.config={type:"pc",stroke:"#836DFF",pointFill:"#FFFFFF",pointSize:10,pointRadius:10,rotateGap:90,hideOnMove:!1,moveCursor:"move",resizeType:"auto",resizeCursor:["nwse-resize","ns-resize","nesw-resize","ew-resize","nwse-resize","ns-resize","nesw-resize","ew-resize"],rotateCursor:["ne-resize","e-resize","se-resize","s-resize","sw-resize","w-resize","nw-resize","n-resize"],resizeable:!0,rotateable:!0},this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.targetRect=new r({hitFill:"all",hitRadius:5}),this.rect=new n({hittable:!1,strokeAlign:"center"}),this.circle=new r({around:"center",hitRadius:10}),this.__eventIds=[],this.__targetEventIds=[],t&&(this.config=a.default(t,this.config)),this.init()}init(){let t,e,i;const{resizePoints:s,rotatePoints:o,resizeLines:n}=this;for(let a=0;a<8;a++)t=new r({around:"center",width:30,height:30,hitRadius:10,hitFill:"all"}),o.push(t),this.__listenPointEvents(t,"rotate",a),a%2&&(e=new r({around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.__listenPointEvents(e,"resize",a)),i=new r({around:"center",hitRadius:5}),s.push(i),this.__listenPointEvents(i,"resize",a);this.__listenPointEvents(this.circle,"rotate",1),this.addMany(...o,this.targetRect,this.rect,this.circle,...n,...s),this.__listenEvents()}onTarget(){this.tool=this.getTool(this.target),this.waitLeafer((()=>{this.update(),this.updateMoveCursor(),this.__listenTargetEvents()}))}getTool(t){return"Line"===t.tag&&t.resizeable?B:A}update(){this.target&&this.tool.update(this)}onDrag(t){const{resizeable:e,rotateable:i}=this.config;t.metaKey||t.ctrlKey||!e?i&&this.onRotate(t):this.onResize(t)}onMove(t){const{target:e}=this,{x:i,y:s}=t.getLocalMove(e);t.shiftKey?Math.abs(i)>Math.abs(s)?e.x+=i:e.y+=s:(e.x+=i,e.y+=s)}onRotate(t){const{target:e}=this,{rotateGap:i}=this.config,{x:s,y:o,width:r,height:n}=e.boxBounds,a={x:s+r/2,y:o+n/2};let g;if(t instanceof h)g=t.rotation;else{const i=t,s={x:i.x-t.moveX,y:i.y-t.moveY};g=l.getChangeAngle(s,e.getWorldPoint(a),i)}g=c.getGapRotation(e.rotation+g,i)-e.rotation;const y=new j(j.ROTATE,{editor:this,target:e,origin:a,rotation:g});this.tool.rotate(y),e.emitEvent(y)}onResize(t){const{target:e}=this,{__direction:i}=t.current.__;let{resizeType:s,around:o,lockRatio:r}=this.config;t.shiftKey&&(r=!0),t.altKey&&!o&&(o="center"),"auto"===s&&(s=e.resizeable?"size":"scale");const n=function(t,e,i,s,o){o&&(i.x*=2,i.y*=2);let r,n=1,a=1;const{x:h,y:l,width:c,height:g}=t,y=(-i.y+g)/g,d=(i.x+c)/c,u=(i.y+g)/g,_=(-i.x+c)/c;switch(e){case f:a=y,s&&(n=a),r={x:h+c/2,y:l+g};break;case z:n=d,s&&(a=n),r={x:h,y:l+g/2};break;case w:a=u,s&&(n=a),r={x:h+c/2,y:l};break;case E:n=_,s&&(a=n),r={x:h+c,y:l+g/2};break;case v:a=y,n=_,s&&(n=a),r={x:h+c,y:l+g};break;case p:a=y,n=d,s&&(n=a),r={x:h,y:l+g};break;case R:a=u,n=d,s&&(n=a),r={x:h,y:l};break;case m:a=u,n=_,s&&(n=a),r={x:h+c,y:l}}return o&&(r="object"==typeof o?{x:h+c/o.x,y:l+g/o.y}:{x:h+c/2,y:l+g/2}),b(M),x(M,r,n,a),{bounds:{x:t.x+M.e,y:t.y+M.f,width:c*n,height:g*a},old:t,origin:r,scaleX:n,scaleY:a,direction:e,lockRatio:s,around:o}}(e.boxBounds,i,t.getInnerMove(this.targetRect),r,o),a=new S(S.RESIZE,Object.assign(Object.assign({},n),{target:e,editor:this,dragEvent:t,resizeType:s}));this.tool.resize(a),e.emitEvent(a)}updateMoveCursor(){this.targetRect.cursor=this.config.moveCursor}__listenEvents(){this.__eventIds=[this.targetRect.on_(g.START,(()=>{this.opacity=this.config.hideOnMove?0:1})),this.targetRect.on_(g.DRAG,this.onMove,this),this.targetRect.on_(g.END,(()=>{this.opacity=1})),this.targetRect.on_(y.ENTER,this.updateMoveCursor,this)]}__removeListenEvents(){this.targetRect.off_(this.__eventIds),this.__eventIds.length=0}__listenPointEvents(t,e,i){t.__.__direction=i;const s=t.__.__isResizePoint="resize"===e;t.on_(g.DRAG,s?this.onDrag:this.onRotate,this),t.on_(y.LEAVE,(()=>this.enterPoint=null)),t.on_(y.ENTER,(e=>{this.enterPoint=t,X(this,e)}))}__listenTargetEvents(){if(this.target){const{leafer:t}=this.target;this.__targetEventIds=[t.on_(d.START,this.update,this),t.on_([u.HOLD,u.UP],(t=>{X(this,t)}))]}}__removeTargetEvents(){if(this.__targetEventIds.length){const{leafer:t}=this.target;t&&t.off_(this.__targetEventIds),this.__targetEventIds.length=0}}destroy(){this.__removeListenEvents(),this._target=null,super.destroy()}}export{G as Editor,S as EditorResizeEvent,j as EditorRotateEvent,B as LineTool,A as RectTool};
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 h,Box as a,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 _,Direction9 as y,MathHelper as b,Matrix as w,Debug as L,DataHelper as E,LeafHelper as k,RenderEvent as x,getPointData as O,Creator as M}from"@leafer-ui/draw";import{PointerEvent as S,DragEvent as T,MoveEvent as P,ZoomEvent as V,RotateEvent as C,KeyEvent as I}from"@leafer-ui/core";const{M:R,L:H,C:B,Q:D,Z:z,N:A,D:Z,X:W,G:F,F:G,O:U,P:X,U:Y}=t,N={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case R:case H:j(t,e,i,o,1),o+=3;break;case B:j(t,e,i,o,3),o+=7;break;case D:j(t,e,i,o,2),o+=5;break;case z:o+=1;break;case A:j(t,e,i,o,2),o+=5;break;case Z:j(t,e,i,o,2),o+=9;break;case W:j(t,e,i,o,2),o+=6;break;case F:j(t,e,i,o,2),o+=9;break;case G:j(t,e,i,o,2),o+=5;break;case U:t[o]=F,t.splice(o+4,0,t[o+3],0),j(t,e,i,o,2),o+=9,n+=2;break;case X:t[o]=G,t.splice(o+4,0,t[o+3]),j(t,e,i,o,2),o+=5,n+=1;break;case Y: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}=N,K=e.get();function $(t,e,i){t.pathInputed?Q(t,e,i):(1!==e&&(t.width*=e),1!==i&&(t.height*=i))}function q(t,e,i){const{width:s,height:o}=t.__localBoxBounds;1!==e?(t.fontSize*=e,t.y-=o*(e-i)/2):1!==i&&(t.fontSize*=i,t.x-=s*(i-e)/2)}function Q(t,e,i){N.scale(t.__.path,e,i),t.path=t.__.path}function J(t,e,i){N.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++)K.a=e,K.d=i,s[t].transform(K,!0)}const et=i.prototype;function it(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 h=t.length-1;h>=0;h--)(o=t[h])&&(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 st(t){return t?t instanceof Array?t:[t]:[]}et.scaleResize=function(t,e=t,i){const s=this;i||s.editConfig&&"scale"===s.editConfig.editSize?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},et.__scaleResize=function(t,e){$(this,t,e)},et.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},et.resizeHeight=function(t){const e=t/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},s.prototype.__scaleResize=function(t,e){this.__.__autoSize&&(this.__.resizeFontSize||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){this.pathInputed?Q(this,t,e):this.points?J(this,t,e):this.width*=t},r.prototype.__scaleResize=function(t,e){this.pathInputed?Q(this,t,e):this.points?J(this,t,e):$(this,t,e)},h.prototype.__scaleResize=function(t,e){tt(this,t,e)},a.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?tt(this,t,e):($(this,t,e),this.__.resizeChildren&&tt(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;class ot extends l{get list(){return st(this.value)}get oldList(){return st(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}ot.SELECT="editor.select",ot.HOVER="editor.hover";class nt extends ot{constructor(t,e){super(t,e)}}nt.MOVE="editor.move";class rt extends ot{constructor(t,e){super(t,e)}}rt.SCALE="editor.scale";class ht extends ot{constructor(t,e){super(t,e)}}ht.ROTATE="editor.rotate";class at extends ot{constructor(t,e){super(t,e)}}function lt(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 dt=e.get(),{abs:ct}=Math,{copy:gt,scale:ut}=e;class ft 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:h}=e;for(let a=0;a<i.length;a++)if(s=i[a],h&&h.hit(s.__world,e.matrix)){const i=ct(s.__world.scaleX),h=ct(s.__world.scaleY);if(i!==h){gt(dt,s.__world),ut(dt,1/i,1/h),t.setWorld(dt,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:o,y:r,width:a,height:l}=s.__layout.boxBounds;t.rect(o*i,r*h,a*i,l*h)}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/ct(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()}}it([lt((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],ft.prototype,"target",void 0);class pt extends h{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:mt,Yes:vt,NoAndSkip:_t,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:_t;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?yt:mt;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return vt}return mt}return t.isBranch?_t:mt}},{findOne:wt}=bt;class Lt extends h{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 ft,this.targetStroker=new ft,this.bounds=new p,this.selectArea=new pt,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_(ot.HOVER,this.onHover,this),t.on_(ot.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_(P.MOVE,this.onAutoMove,this),e.on_([V.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:Et,top:kt,topRight:xt,right:Ot,bottomRight:Mt,bottom:St,bottomLeft:Tt,left:Pt}=y,{toPoint:Vt}=_,Ct={getScaleData(t,e,i,s,o){let n,r={},h=1,a=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:a=c,n="bottom";break;case Ot:h=g,n="left";break;case St:a=u,n="top";break;case Pt:h=f,n="right";break;case Et:a=c,h=f,n="bottom-right";break;case xt:a=c,h=g,n="bottom-left";break;case Mt:a=u,h=g,n="top-left";break;case Tt:a=u,h=f,n="top-right"}if(s){if(!("corner"===s&&e%2)){const t=Math.sqrt(Math.abs(h*a));h=h<0?-t:t,a=a<0?-t:t}}return Vt(o||n,t,r),{origin:r,scaleX:h,scaleY:a,direction:e,lockRatio:s,around:o}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case Et: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 Vt(o||n,t,r),{origin:r,rotation:v.getRotation(s,r,i)}},getSkewData(t,e,i,s){let o,n,r={},h=0,a=0;switch(e){case kt:n={x:.5,y:0},o="bottom",h=1;break;case St:n={x:.5,y:1},o="top",h=1;break;case Pt:n={x:0,y:.5},o="right",a=1;break;case Ot:n={x:1,y:.5},o="left",a=1}const{x:l,y:d,width:c,height:g}=t;n.x=l+n.x*c,n.y=d+n.y*g,Vt(s||o,t,r);const u=v.getRotation(n,r,{x:n.x+(h?i.x:0),y:n.y+(a?i.y:0)});return h?h=-u:a=u,{origin:r,skewX:h,skewY:a}},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 Pt:t=Ot;break;case Et:t=xt;break;case Tt:t=Mt;break;case Ot:t=Pt;break;case xt:t=Et;break;case Mt:t=Tt}if(i)switch(t){case kt:t=St;break;case Et:t=Tt;break;case xt:t=Mt;break;case St:t=kt;break;case Tt:t=Et;break;case Mt:t=xt}return t}},It={};function Rt(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:h,resizeable:a,rotateable:l,skewable:d}=t.mergeConfig,{pointType:c}=s,{flippedX:g,flippedY:u}=i;let f="resize"===c;f&&l&&(e.metaKey||e.ctrlKey||!a)&&(f=!1);const p=d&&!f&&"resize-line"===s.name?h:f?n:r;o+=45*(Ct.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(b.formatRotation(o,!0)/2);const{url:m,x:v,y:_}=p,y=m+o;It[y]?s.cursor=It[y]:It[y]=s.cursor={url:Bt(m,o),x:v,y:_}}function Ht(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function Bt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Dt extends a{}const zt=["top","right","bottom","left"];class At extends h{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 h,this.rect=new a({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Dt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new h({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.rect.syncEventer=t,this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:h,circle:a,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 Dt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Dt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Dt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);l.add(a),this.listenPointEvents(a,"rotate",2),s.addMany(...n,h,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:h,moveable:a}=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:h},t.rect||{})),s.hittable=!i&&a,e.syncEventer=i&&a?s:null,this.app.interaction.bottomList=i&&a?[{target:s,proxy:e}]:null}update(t){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:e}=this.editor,{width:i,height:s}=t,{rect:o,circle:n,resizePoints:r,rotatePoints:h,resizeLines:a}=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,y={};for(let o=0;o<8;o++)_.toPoint(_.directionData[o],t,y),m=r[o],p=h[o],v=a[Math.floor(o/2)],m.set(y),p.set(y),v.set(y),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 b=f&&(n.visible||this.buttons.children.length>1);this.buttons.visible=b,b&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.mergeConfig,{flippedX:r,flippedY:h}=this;let a=zt.indexOf(i);(a%2&&r||(a+1)%2&&h)&&s&&(a=(a+2)%4);const l=s?Ct.getRotateDirection(a,this.flippedOne?this.rotation:-this.rotation,4):a,d=e[2*l+1],c=l%2,g=l&&3!==l?1:-1,u=(o+(a%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-a),t.scaleX=r?-1:1,t.scaleY=h?-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=null,this.app&&(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),Rt(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,Rt(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(ot.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_(V.BEFORE_ZOOM,e.onScale,e,!0),t.on_(C.BEFORE_ROTATE,e.onRotate,e,!0),t.on_(S.ENTER,(()=>Ht(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()}}class Zt extends c{constructor(t){super(),this.editor=t,this.hittable=!1}__draw(t,e){const{editor:i}=this,{mask:s}=i.mergeConfig;if(s&&i.list.length){const{rect:o}=i.editBox,{width:n,height:r}=o.__;t.resetTransform(),t.fillWorld(t.bounds,s),t.setWorld(o.__world,e.matrix),t.clearRect(0,0,n,r)}}destroy(){this.editor=null,super.destroy()}}const Wt='\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"/>',Ft={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${Wt}\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${Wt}\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${Wt}\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};function Gt(t){const{simulateTarget:e,leafList:i}=t,{x:s,y:o,width:n,height:r}=(new p).setListWithFn(i.list,(t=>t.worldBoxBounds)),h=e.parent=i.list[0].leafer.zoomLayer,{scaleX:a,scaleY:l,e:d,f:c}=h.__world;e.reset({x:(s-d)/a,y:(o-c)/l,width:n/a,height:r/l})}const Ut=(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 h(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(Ut);const r=new w(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(Ut),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Xt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},Nt=L.get("EditToolCreator");function jt(){return t=>{$t.register(t)}}const Kt=jt,$t={list:{},register(t){const{tag:e}=t.prototype;qt[e]?Nt.repeat(e):qt[e]=t},get:(t,e)=>new qt[t](e)},{list:qt}=$t;class Qt extends ot{constructor(t,e){super(t,e)}}Qt.BEFORE_OPEN="innerEditor.before_open",Qt.OPEN="innerEditor.open",Qt.BEFORE_CLOSE="innerEditor.before_close",Qt.CLOSE="innerEditor.close";class Jt extends ot{constructor(t,e){super(t,e)}}Jt.GROUP="editor.group",Jt.BEFORE_UNGROUP="editor.before_ungroup",Jt.UNGROUP="editor.ungroup",Jt.OPEN="editor.open_group",Jt.CLOSE="editor.close_group";class te extends h{get mergeConfig(){const{element:t,config:e}=this;return this.single&&t.editConfig?Object.assign(Object.assign({},e),t.editConfig):e}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=Ft,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.editMask=new Zt(this),this.targetEventIds=[],t&&(this.config=E.default(t,this.config)),this.addMany(this.editMask,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())}updateEditBox(){this.multiple&&Gt(this),this.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]||$t.get(t,this),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;if(t instanceof V)"zoom"===this.mergeConfig.resizeable&&(t.stop(),this.scaleOf(e.getInnerPoint(t),t.scale,t.scale));else{const{direction:i}=t.current;let{around:s,lockRatio:o}=this.mergeConfig;(t.shiftKey||e.lockRatio)&&(o=!0);const n=Ct.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,Ct.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 h,a;if(t instanceof C){if("rotate"!==this.mergeConfig.rotateable)return;t.stop(),a=t.rotation,h=r.getInnerPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},s=Ct.getRotateData(r.boxBounds,o,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");a=s.rotation,h=s.origin}a=b.getGapRotation(a,s,r.rotation),a&&(r.scaleX*r.scaleY<0&&(a=-a),this.rotateOf(h,b.float(a,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=Ct.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Ct.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 nt(nt.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){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:e}=this,i=e.getWorldPoint(t.origin),s=new rt(rt.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){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:o}=this,n=o.getWorldPoint(k.getInnerOrigin(o,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 h=new rt(rt.SCALE,{target:o,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(h),this.emitEvent(h)}rotateOf(t,e){if(!this.mergeConfig.rotateable||this.element.locked)return;const{element:i}=this,s=i.getWorldPoint(k.getInnerOrigin(i,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 ht(ht.ROTATE,{target:i,editor:this,worldOrigin:s,rotation:e,transform:o});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,s){if(!this.mergeConfig.skewable||this.element.locked)return;const{element:o}=this,n=o.getWorldPoint(k.getInnerOrigin(o,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 h=new at(at.SKEW,{target:o,editor:this,skewX:e,skewY:i,transform:r,worldOrigin:n});this.editTool.onSkew(h),this.emitEvent(h)}group(t){return this.multiple&&(this.target=Yt.group(this.list,this.element,t),this.emitGroupEvent(Jt.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(Jt.BEFORE_UNGROUP,t))),this.target=Yt.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(Jt.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Jt.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Jt.CLOSE,t)}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)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new Jt(t,{editTarget:e});this.emitEvent(i),e.emitEvent(i)}openInnerEditor(t){if(t&&(this.target=t),this.single){const t=this.element,e=t.editInner;e&&$t.list[e]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[e]||$t.get(e,this),this.innerEditor.editTarget=t,this.emitInnerEvent(Qt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Qt.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Qt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Qt.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Qt(t,{editTarget:i,innerEditor:e});this.emitEvent(s),i.emitEvent(s)}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_(x.START,this.update,this),t.on_([I.HOLD,I.UP],(t=>{Rt(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())}}it([lt((function(t,e){t.emitEvent(new ot(ot.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],te.prototype,"hoverTarget",void 0),it([lt((function(t,e){const{target:i}=t;i?t.leafList=i instanceof m?i:new m(i):t.leafList.reset(),t.emitEvent(new ot(ot.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&Gt(t),Ht(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],te.prototype,"target",void 0);class ee{static registerInnerEditor(){$t.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new h,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 ie=class extends ee{static registerEditTool(){$t.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:h}=n;r.lockLayout(),h.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:h}=n;r.lockLayout(),h.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:h,rotation:a,skewX:l,skewY:d,width:c,height:g}=s.getLayoutBounds("box",t,!0);e.set({x:o,y:n,scaleX:r,scaleY:h,rotation:a,skewX:l,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};ie=it([jt()],ie);const{left:se,right:oe}=y,{move:ne,copy:re}=v;let he=class extends ie{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===se;if(n.pathInputed){const{path:t}=n.__,{from:i,to:h}=this.getFromToByPath(t);this.dragPoint(i,h,r,o,this.getInnerMove(n,e,s)),t[1]=i.x,t[2]=i.y,t[4]=h.x,t[5]=h.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:h}=this.getFromToByPoints(t);this.dragPoint(i,h,r,o,this.getInnerMove(n,e,s)),t[0]=i.x,t[1]=i.y,t[2]=h.x,t[3]=h.y,n.points=t}else{const t=O(),{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?(ne(t,n,r),s&&ne(e,-n,-r)):(s&&ne(t,-n,-r),ne(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,h;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:h}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(h,h,!1,t),o.pen.clearPath().moveTo(i.x,i.y).lineTo(h.x,h.y),re(s[7],i),re(e[7],i),re(s[3],h),re(e[3],h)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),h=t===se||t===oe,s[t].visible=h,e[t].visible=!r&&h}};he=it([jt()],he),M.editor=function(t){return new te(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,Ct as EditDataHelper,Dt as EditPoint,Lt as EditSelect,bt as EditSelectHelper,ie as EditTool,$t as EditToolCreator,te as Editor,ot as EditorEvent,Jt as EditorGroupEvent,Yt as EditorHelper,nt as EditorMoveEvent,ht as EditorRotateEvent,rt as EditorScaleEvent,at as EditorSkewEvent,ee as InnerEditor,Qt as InnerEditorEvent,he as LineEditTool,N as PathScaler,pt as SelectArea,ft as Stroker,jt as registerEditTool,Kt as registerInnerEditor,$ as scaleResize,q as scaleResizeFontSize,tt as scaleResizeGroup,Q as scaleResizePath,J as scaleResizePoints};