@leafer-in/editor 1.0.0-rc.21 → 1.0.0-rc.22

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 c,Paint as d,Rect as g,Answer as u,Bounds as f,LeafList as p,PointHelper as y,AroundHelper as w,MathHelper as L,getPointData as v,Matrix as k,DataHelper as _,RenderEvent as m}from"@leafer-ui/draw";import{PointerEvent as b,DragEvent as x,MoveEvent as M,ZoomEvent as E,RotateEvent as S,KeyEvent as V,Creator as T}from"@leafer-ui/core";const{M:H,L:O,C:P,Q:D,Z:R,N:A,D:Z,X:B,G:z,F:W,O:I,P:X,U:Y}=t,C={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case H:case O:F(t,e,i,o,1),o+=3;break;case P:F(t,e,i,o,3),o+=7;break;case D:F(t,e,i,o,2),o+=5;break;case R:o+=1;break;case A:F(t,e,i,o,2),o+=5;break;case Z:F(t,e,i,o,2),o+=9;break;case B:F(t,e,i,o,2),o+=6;break;case z:F(t,e,i,o,2),o+=9;break;case W:F(t,e,i,o,2),o+=5;break;case I:t[o]=z,t.splice(o+4,0,t[o+3],0),F(t,e,i,o,2),o+=9,n+=2;break;case X:t[o]=W,t.splice(o+4,0,t[o+3]),F(t,e,i,o,2),o+=5,n+=1;break;case Y:F(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:F}=C;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){C.scale(this.__.path,t,e),this.path=this.__.path},s.prototype.__scaleResize=function(t,e){if(this.points)C.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?(C.scalePoints(this.__.points,t,e),this.points=this.__.points):K(this,t,e)};const U=n.get();function j(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)U.a=e,U.d=i,s[t].transform(U,!0)}function N(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 G(t){return t?t instanceof Array?t:[t]:[]}r.prototype.__scaleResize=function(t,e){j(this,t,e)},a.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?j(this,t,e):K(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class $ extends l{get list(){return G(this.value)}get oldList(){return G(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}$.SELECT="editor.select",$.HOVER="editor.hover";class Q extends ${constructor(t,e){super(t,e)}}Q.MOVE="editor.move";class q extends ${constructor(t,e){super(t,e)}}q.SCALE="editor.scale";class J extends ${constructor(t,e){super(t,e)}}J.ROTATE="editor.rotate";class tt extends ${constructor(t,e){super(t,e)}}function et(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))}})}}tt.SKEW="editor.skew";const it=n.get(),{abs:st}=Math,{copy:ot,scale:nt}=n;class rt extends c{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){const{stroke:i,strokeWidth:s}=e;this.set({stroke:i,strokeWidth:s}),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let s;const{stroke:o,strokeWidth:n}=this.__,{bounds:r}=e;for(let a=0;a<i.length;a++)if(s=i[a],r&&r.hit(s.__world,e.matrix)){let i;if("scale"===s.__.editSize){const o=st(s.__world.scaleX),r=st(s.__world.scaleY);if(o!==r){ot(it,s.__world),nt(it,1/o,1/r),t.setWorld(it,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:a,y:l,width:h,height:c}=s.__layout.boxBounds;t.rect(a*o,l*r,h*o,c*r),i=!0}}i||(t.setWorld(s.__world,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),this.__.strokeWidth=n/st(s.__world.scaleX)),"string"==typeof o?d.stroke(o,this,t):d.strokes(o,this,t)}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}N([et((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],rt.prototype,"target",void 0);class at 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:lt,Yes:ht,NoAndSkip:ct,YesAndSkip:dt}=u,gt={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?dt:ct;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?dt:lt;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return ht}return lt}return t.isBranch?ct:lt}},{findOne:ut}=gt;class ft extends r{get dragging(){return!!this.originList}get running(){return this.editor.hittable&&this.editor.config.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new rt,this.targetStroker=new rt,this.bounds=new f,this.selectArea=new at,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}=t.config;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,{stroke:e,strokeWidth:i})}}onSelect(){if(this.running){const{config: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.running&&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=t.shiftKey?this.findDeepOne(t):ut(t.path);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.config;"press"===e&&this.checkAndSelect(t,!0)}onTap(t){const{editor:e}=this,{select:i,continuousSelect:s}=e.config;if("tap"===i&&this.checkAndSelect(t),!this.running||!t.shiftKey&&!s||t.middle||this.lastDownLeaf)this.isMoveMode&&(e.target=null);else{const i=this.findDeepOne(t);i?e.shiftItem(i):!t.shiftKey&&s&&(e.target=null)}this.lastDownLeaf=null}checkAndSelect(t,e){if(this.running&&!this.isMoveMode&&!t.middle){const{editor:i}=this,s=this.lastDownLeaf=ut(t.path);s?(t.shiftKey||i.config.continuousSelect?i.shiftItem(s):i.target=s,e&&(i.updateLayout(),s.locked||this.app.interaction.updateDownData(t,{findList:[i.editBox.rect]},i.config.dualEvent))):this.allow(t.target)&&(t.shiftKey||(i.target=null))}}onDragStart(t){if(this.running&&this.allowDrag(t)){const{editor:e}=this,{stroke:i,strokeWidth:s,area:o}=e.config,{x:n,y:r}=t.getInner(this);this.bounds.set(n,r),this.selectArea.setStyle({visible:!0,stroke:i,strokeWidth:s,x:n,y:r},o),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(gt.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.editor.config.boxSelect||t.target.draggable)&&(!this.editor.hasTarget&&this.allow(t.target)||t.shiftKey&&!ut(t.path))}findDeepOne(t){const e={exclude:new p(this.editor.editBox.rect)};return ut(t.target.leafer.interaction.findPath(t,e))}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_($.HOVER,this.onHover,this),t.on_($.SELECT,this.onSelect,this),e.on_(b.MOVE,this.onPointerMove,this),e.on_(b.BEFORE_DOWN,this.onBeforeDown,this),e.on_(b.TAP,this.onTap,this),e.on_(x.START,this.onDragStart,this),e.on_(x.DRAG,this.onDrag,this),e.on_(x.END,this.onDragEnd,this),e.on_(M.MOVE,this.onAutoMove,this),e.on_([E.ZOOM,M.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.lastDownLeaf=null,this.__removeListenEvents(),super.destroy()}}var pt;!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"}(pt||(pt={}));const{topLeft:yt,top:wt,topRight:Lt,right:vt,bottomRight:kt,bottom:_t,bottomLeft:mt,left:bt}=pt,{toPoint:xt}=w,Mt={getScaleData(t,e,i,s,o){let n,r=1,a=1;const{width:l,height:h}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===l&&(i.x+=.1),Math.abs(i.y)===h&&(i.y+=.1);const c=(-i.y+h)/h,d=(i.x+l)/l,g=(i.y+h)/h,u=(-i.x+l)/l;switch(e){case wt:a=c,n={x:.5,y:1};break;case vt:r=d,n={x:0,y:.5};break;case _t:a=g,n={x:.5,y:0};break;case bt:r=u,n={x:1,y:.5};break;case yt:a=c,r=u,n={x:1,y:1};break;case Lt:a=c,r=d,n={x:0,y:1};break;case kt:a=g,r=d,n={x:0,y:0};break;case mt:a=g,r=u,n={x:1,y:0}}if(s){"corner"===s&&e%2||(1!==a?r=a:a=r)}return xt(o||n,t,n),{origin:n,scaleX:r,scaleY:a,direction:e,lockRatio:s,around:o}},getRotateData(t,e,i,s,o){let n;switch(e){case yt:n={x:1,y:1};break;case Lt:n={x:0,y:1};break;case kt:n={x:0,y:0};break;case mt:n={x:1,y:0};break;default:n={x:.5,y:.5}}return xt(o||n,t,n),{origin:n,rotation:y.getRotation(s,n,i)}},getSkewData(t,e,i,s){let o,n,r=0,a=0;switch(e){case wt:n={x:.5,y:0},o={x:.5,y:1},r=1;break;case _t:n={x:.5,y:1},o={x:.5,y:0},r=1;break;case bt:n={x:0,y:.5},o={x:1,y:.5},a=1;break;case vt:n={x:1,y:.5},o={x:0,y:.5},a=1}const{x:l,y:h,width:c,height:d}=t;n.x=l+n.x*c,n.y=h+n.y*d,xt(s||o,t,o);const g=y.getRotation(n,o,{x:n.x+(r?i.x:0),y:n.y+(a?i.y:0)});return r?r=-g:a=g,{origin:o,skewX:r,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 bt:t=vt;break;case yt:t=Lt;break;case mt:t=kt;break;case vt:t=bt;break;case Lt:t=yt;break;case kt:t=mt}if(i)switch(t){case wt:t=_t;break;case yt:t=mt;break;case Lt:t=kt;break;case _t:t=wt;break;case mt:t=yt;break;case kt:t=Lt}return t}},Et={};function St(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.hasTarget||!i.visible)return;if("circle"===s.name)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:l,rotateable:h,skewable:c}=t.config,{pointType:d}=s,{flippedX:g,flippedY:u}=i;let f="resize"===d;f&&h&&(e.metaKey||e.ctrlKey||!l)&&(f=!1);const p=c&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(Mt.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(L.formatRotation(o,!0)/2);const{url:y,x:w,y:v}=p,k=y+o;Et[k]?s.cursor=Et[k]:Et[k]=s.cursor={url:Tt(y,o),x:w,y:v}}function Vt(t){t.editBox.rect.cursor=t.config.moveCursor}function Tt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Ht extends a{}const Ot=["top","right","bottom","left"];class Pt 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.rect=new a({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Ht({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{resizePoints:s,rotatePoints:o,resizeLines:n,rect:r,circle:a,buttons:l}=this,h=[{x:1,y:1},{x:.5,y:1},{x:0,y:1},{x:0,y:.5},{x:0,y:0},{x:.5,y:0},{x:1,y:0},{x:1,y:.5}];for(let r=0;r<8;r++)t=new Ht({name:"rotate-point",around:h[r],width:15,height:15,hitFill:"all"}),o.push(t),this.listenPointEvents(t,"rotate",r),r%2&&(e=new Ht({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",r)),i=new Ht({name:"resize-point",around:"center",strokeAlign:"center",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",r);l.add(a),this.listenPointEvents(a,"rotate",2),this.addMany(...o,r,l,...n,...s)}update(t){const{config:e,list:i}=this.editor,{width:s,height:o}=t,{rect:n,circle:r,resizePoints:a,rotatePoints:l,resizeLines:h}=this,{middlePoint:c,resizeable:d,rotateable:g,stroke:u,strokeWidth:f,hideOnSmall:p}=e,y=this.getPointsStyle(),L=this.getMiddlePointsStyle(),v="number"==typeof p?p:10,k=!(p&&s<v&&o<v);this.visible=i[0]&&!i[0].locked;let _,m,b,x,M={};for(let i=0;i<8;i++)w.toPoint(w.directionData[i],t,M),_=this.getPointStyle(i%2?L[(i-1)/2%L.length]:y[i/2%y.length]),b=a[i],m=l[i],x=h[Math.floor(i/2)],b.set(_),b.set(M),m.set(M),x.set(M),b.visible=x.visible=k&&(d||g),m.visible=k&&g&&d&&!e.rotatePoint,i%2?(b.visible=m.visible=k&&!!c,(i+1)/2%2?(x.width=s,b.width>s-30&&(b.visible=!1)):(x.height=o,b.rotation=90,b.width>o-30&&(b.visible=!1))):b.rotation=i/2*90;r.visible=k&&g&&!!e.rotatePoint,r.set(this.getPointStyle(e.rotatePoint||y[0])),n.set(Object.assign({stroke:u,strokeWidth:f},e.rect||{})),n.set(Object.assign(Object.assign({},t),{visible:!0})),n.hittable=e.moveable,this.buttons.visible=k,this.layoutButtons()}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.config,{flippedX:r,flippedY:a}=this;let l=Ot.indexOf(i);(l%2&&r||(l+1)%2&&a)&&s&&(l=(l+2)%4);const h=s?Mt.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,c=e[2*h+1],d=h%2,g=h&&3!==h?1:-1,u=(o+(l%2?(n?c.width:0)+t.boxBounds.width:(n?c.height:0)+t.boxBounds.height)/2)*g;d?(t.x=c.x+u,t.y=c.y):(t.x=c.x,t.y=c.y+u),s&&(t.rotation=90*(h-l),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.config,r={fill:s,stroke:e,strokeWidth:i,width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.config;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.config;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onDragStart(t){this.dragging=!0,"rect"===t.target.name&&(this.moving=!0,this.editor.opacity=this.editor.config.hideOnMove?0:1)}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.target.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.config.resizeable?e.config.rotateable&&e.onRotate(t):e.onScale(t),St(e,t)}onArrow(t){if(this.editor.hasTarget&&this.editor.config.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}(e.x||e.y)&&this.editor.move(e.x,e.y)}}onDoubleClick(){const{editor:t}=this;t.single&&t.element.isBranch}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(x.START,this.onDragStart,this),t.on_(x.DRAG,this.onDrag,this),t.on_(x.END,this.onDragEnd,this),t.on_(b.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(b.ENTER,(e=>{this.enterPoint=t,St(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_($.SELECT,(()=>{this.visible=e.hasTarget})),t.on_(x.START,this.onDragStart,this),t.on_(x.DRAG,e.onMove,e),t.on_(x.END,this.onDragEnd,this),t.on_(b.ENTER,(()=>Vt(e))),t.on_(b.DOUBLE_CLICK,this.onDoubleClick,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:"auto",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",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};class At{constructor(){this.tag="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()}update(t){const{simulateTarget:e,element:i}=t;t.multiple&&e.parent.updateLayout();const{x:s,y:o,scaleX:n,scaleY:r,rotation:a,skewX:l,skewY:h,width:c,height:d}=i.getLayoutBounds("box",t,!0);t.editBox.set({x:s,y:o,scaleX:n,scaleY:r,rotation:a,skewX:l,skewY:h}),t.editBox.update({x:0,y:0,width:c,height:d})}}At.list=[];const{left:Zt,right:Bt}=pt;class zt extends At{constructor(){super(...arguments),this.tag="LineEditTool",this.scaleOfEvent=!0}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=v(),{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===Zt?(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){}update(t){const{rotatePoints:e,resizeLines:i,resizePoints:s}=t.editBox;super.update(t);for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),s[t].visible=e[t].visible=t===Zt||t===Bt}}const Wt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),It=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Xt={group(t,e,i){t.sort(It);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(Wt);const a=new k(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(Wt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(It),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}};class Yt extends r{get list(){return this.leafList.list}get hasTarget(){return!!this.list.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}get dragging(){return this.editBox.dragging}constructor(t,e){super(e),this.config=Rt,this.leafList=new p,this.simulateTarget=new g({visible:!1}),this.editBox=new Pt(this),this.selector=new ft(this),this.targetEventIds=[],t&&(this.config=_.default(t,this.config)),this.addMany(this.selector,this.editBox)}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.hasTarget&&(this.editTool&&this.editTool.update(this),this.selector.update())}updateEditTool(){this.editTool=function(t){if(1===t.length){const e=t[0];return e instanceof s&&!e.points?new zt:new At}return new At}(this.list)}getEditSize(t){let{editSize:e}=this.config;return"auto"===e?t.editSize:e}onMove(t){const e=t.getLocalMove(this.element),{lockMove:i}=this.config;"x"===i?e.y=0:"y"===i?e.x=0:t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(e.x,e.y)}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.config;t.shiftKey&&(o=!0);const n=Mt.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,Mt.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.config,{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 S)l=t.rotation,a=r.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},s=Mt.getRotateData(r.boxBounds,o,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");l=s.rotation,a=s.origin}l=L.getGapRotation(l,s,r.rotation),l&&(r.scaleX*r.scaleY<0&&(l=-l),this.rotateOf(a,L.float(l,2)))}onSkew(t){const{element:e}=this,{around:i}=this.config,{origin:s,skewX:o,skewY:n}=Mt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Mt.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e){if(!this.config.moveable)return;const{element:i}=this,s=i.getWorldPointByLocal({x:t,y:e},null,!0),o=new Q(Q.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 q(q.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 k(o.worldTransform);o.scaleOf(t,e,i),r=new k(o.worldTransform).divide(s)}const a=new q(q.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 k(i.worldTransform);i.rotateOf(t,e),o=new k(i.worldTransform).divide(s)}const n=new J(J.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 k(o.worldTransform);o.skewOf(t,e,i),r=new k(o.worldTransform).divide(s)}const a=new tt(tt.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=Xt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=Xt.ungroup(this.list)),this.list}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(Xt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Xt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(m.START,this.update,this),t.on_([V.HOLD,V.UP],(t=>{St(this,t)})),t.on_(V.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(),this.target=this.hoverTarget=this.simulateTarget=null,super.destroy())}}N([et((function(t,e){t.emitEvent(new $($.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Yt.prototype,"hoverTarget",void 0),N([et((function(t,e){const{target:i}=t;i?t.leafList=i instanceof p?i:new p(i):t.leafList.reset(),t.emitEvent(new $($.SELECT,{editor:t,value:i,oldValue:e})),t.hasTarget?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:c,f:d}=a.__world;e.reset({x:(s-c)/l,y:(o-d)/h,width:n/l,height:r/h})}(t),Vt(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):t.removeTargetEvents()}))],Yt.prototype,"target",void 0),T.editor=function(t){return new Yt(t)};export{Pt as EditBox,Mt as EditDataHelper,Ht as EditPoint,ft as EditSelect,gt as EditSelectHelper,At as EditTool,Yt as Editor,$ as EditorEvent,Xt as EditorHelper,Q as EditorMoveEvent,J as EditorRotateEvent,q as EditorScaleEvent,tt as EditorSkewEvent,zt as LineEditTool,at as SelectArea,rt as Stroker};
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 y,Direction9 as v,MathHelper as L,Matrix as w,Debug as b,DataHelper as _,LeafHelper as k,RenderEvent as x,getPointData as E,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)){let i;if("scale"===s.__.editSize){const o=rt(s.__world.scaleX),r=rt(s.__world.scaleY);if(o!==r){at(nt,s.__world),lt(nt,1/o,1/r),t.setWorld(nt,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:a,y:l,width:h,height:d}=s.__layout.boxBounds;t.rect(a*o,l*r,h*o,d*r),i=!0}}i||(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 yt 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:vt,top:Lt,topRight:wt,right:bt,bottomRight:_t,bottom:kt,bottomLeft:xt,left:Et}=v,{toPoint:Mt}=y,St={getScaleData(t,e,i,s,o){let n,r=1,a=1;const{width:l,height:h}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===l&&(i.x+=.1),Math.abs(i.y)===h&&(i.y+=.1);const d=(-i.y+h)/h,c=(i.x+l)/l,g=(i.y+h)/h,u=(-i.x+l)/l;switch(e){case Lt:a=d,n={x:.5,y:1};break;case bt:r=c,n={x:0,y:.5};break;case kt:a=g,n={x:.5,y:0};break;case Et:r=u,n={x:1,y:.5};break;case vt:a=d,r=u,n={x:1,y:1};break;case wt:a=d,r=c,n={x:0,y:1};break;case _t:a=g,r=c,n={x:0,y:0};break;case xt:a=g,r=u,n={x:1,y:0}}if(s){"corner"===s&&e%2||(r=a=Math.sqrt(r*a))}return Mt(o||n,t,n),{origin:n,scaleX:r,scaleY:a,direction:e,lockRatio:s,around:o}},getRotateData(t,e,i,s,o){let n;switch(e){case vt:n={x:1,y:1};break;case wt:n={x:0,y:1};break;case _t:n={x:0,y:0};break;case xt:n={x:1,y:0};break;default:n={x:.5,y:.5}}return Mt(o||n,t,n),{origin:n,rotation:m.getRotation(s,n,i)}},getSkewData(t,e,i,s){let o,n,r=0,a=0;switch(e){case Lt:n={x:.5,y:0},o={x:.5,y:1},r=1;break;case kt:n={x:.5,y:1},o={x:.5,y:0},r=1;break;case Et:n={x:0,y:.5},o={x:1,y:.5},a=1;break;case bt:n={x:1,y:.5},o={x:0,y:.5},a=1}const{x:l,y:h,width:d,height:c}=t;n.x=l+n.x*d,n.y=h+n.y*c,Mt(s||o,t,o);const g=m.getRotation(n,o,{x:n.x+(r?i.x:0),y:n.y+(a?i.y:0)});return r?r=-g:a=g,{origin:o,skewX:r,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 Et:t=bt;break;case vt:t=wt;break;case xt:t=_t;break;case bt:t=Et;break;case wt:t=vt;break;case _t:t=xt}if(i)switch(t){case Lt:t=kt;break;case vt:t=xt;break;case wt:t=_t;break;case kt:t=Lt;break;case xt:t=vt;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(L.formatRotation(o,!0)/2);const{url:m,x:y,y:v}=p,w=m+o;Tt[w]?s.cursor=Tt[w]:Tt[w]=s.cursor={url:Ht(m,o),x:y,y:v}}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=[{x:1,y:1},{x:.5,y:1},{x:0,y:1},{x:0,y:.5},{x:0,y:0},{x:.5,y:0},{x:1,y:0},{x:1,y:.5}];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,v,L={};for(let o=0;o<8;o++)y.toPoint(y.directionData[o],t,L),m=r[o],p=a[o],v=l[Math.floor(o/2)],m.set(L),p.set(L),v.set(L),m.visible=v.visible=f&&(d||c),p.visible=f&&c&&d&&!e.rotatePoint,o%2&&(m.visible=p.visible=f&&!!h,(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.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:"auto",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=b.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 yt(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){let{editSize:e}=this.mergeConfig;return"auto"===e?t.editSize:e}onMove(t){const e={x:t.totalX,y:t.totalY},{lockMove:i}=this.mergeConfig;"x"===i?e.y=0:"y"===i?e.x=0: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=L.getGapRotation(l,s,r.rotation),l&&(r.scaleX*r.scaleY<0&&(l=-l),this.rotateOf(a,L.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)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_(x.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}=v;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=E(),{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,yt 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};