@leafer-in/editor 1.0.0 → 1.0.1

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,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};
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 _,MathHelper as b,Direction9 as y,Matrix as w,Debug as L,DataHelper as E,LeafHelper as k,RenderEvent as x,getPointData as O,Creator as S}from"@leafer-ui/draw";import{PointerEvent as T,DragEvent as M,MoveEvent as P,ZoomEvent as C,RotateEvent as V,KeyEvent as B}from"@leafer-ui/core";const{M:R,L:H,C:I,Q:z,Z:D,N:A,D:Z,X:W,G:F,F:X,O:Y,P:G,U:U}=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 I:j(t,e,i,o,3),o+=7;break;case z:j(t,e,i,o,2),o+=5;break;case D: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 X:j(t,e,i,o,2),o+=5;break;case Y:t[o]=F,t.splice(o+4,0,t[o+3],0),j(t,e,i,o,2),o+=9,n+=2;break;case G:t[o]=X,t.splice(o+4,0,t[o+3]),j(t,e,i,o,2),o+=5,n+=1;break;case U: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:bt}=f,yt={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?bt:_t;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?bt:mt;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return vt}return mt}return t.isBranch?_t:mt}},{findOne:wt}=yt;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.interaction.canHover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){if(t.multiTouch)return;const{select:e}=this.editor.mergeConfig;"press"===e&&(this.app.config.mobile?this.waitSelect=()=>this.checkAndSelect(t):this.checkAndSelect(t))}onTap(t){if(t.multiTouch)return;const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i?this.checkAndSelect(t):this.waitSelect&&this.waitSelect(),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(!t.multiTouch&&(this.waitSelect&&this.waitSelect(),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(!t.multiTouch){if(this.editor.dragging)return this.onDragEnd(t);if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new m(e.app.find(yt.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(t){t.multiTouch||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_(T.MOVE,this.onPointerMove,this),e.on_(T.BEFORE_DOWN,this.onBeforeDown,this),e.on_(T.TAP,this.onTap,this),e.on_(M.START,this.onDragStart,this,!0),e.on_(M.DRAG,this.onDrag,this),e.on_(M.END,this.onDragEnd,this),e.on_(P.MOVE,this.onAutoMove,this),e.on_([C.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:St,bottom:Tt,bottomLeft:Mt,left:Pt}=y,{toPoint:Ct}=_,{within:Vt}=b,Bt={getScaleData(t,e,i,s,o,n,r,h){let a,l={},d=1,c=1;const{boxBounds:g,widthRange:u,heightRange:f}=t,{width:p,height:m}=e;n&&(s.x*=2,s.y*=2);const v=t.scaleX/e.scaleX,_=t.scaleY/e.scaleY,b=v<0?-1:1,y=_<0?-1:1,w=h?v:b*g.width/p,L=h?_:y*g.height/m;s.x*=h?v:b,s.y*=h?_:y,Math.abs(s.x)===p&&(s.x+=.1),Math.abs(s.y)===m&&(s.y+=.1);const E=(-s.y+m)/m,k=(s.x+p)/p,x=(s.y+m)/m,O=(-s.x+p)/p;switch(i){case kt:c=E,a="bottom";break;case Ot:d=k,a="left";break;case Tt:c=x,a="top";break;case Pt:d=O,a="right";break;case Et:c=E,d=O,a="bottom-right";break;case xt:c=E,d=k,a="bottom-left";break;case St:c=x,d=k,a="top-left";break;case Mt:c=x,d=O,a="top-right"}if(o){if(!("corner"===o&&i%2)){const t=Math.sqrt(Math.abs(d*c));d=d<0?-t:t,c=c<0?-t:t}}if(d/=w,c/=L,!r){const{worldTransform:e}=t;d<0&&(d=1/g.width/e.scaleX),c<0&&(c=1/g.height/e.scaleY)}if(u){const e=g.width*t.scaleX;d=Vt(e*d,u)/e}if(f){const e=g.height*t.scaleY;c=Vt(e*c,f)/e}return Ct(n||a,g,l),{origin:l,scaleX:d,scaleY:c,direction:i,lockRatio:o,around:n}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case Et:n="bottom-right";break;case xt:n="bottom-left";break;case St:n="top-left";break;case Mt:n="top-right";break;default:n="center"}return Ct(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 Tt: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,Ct(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 Mt:t=St;break;case Ot:t=Pt;break;case xt:t=Et;break;case St:t=Mt}if(i)switch(t){case kt:t=Tt;break;case Et:t=Mt;break;case xt:t=St;break;case Tt:t=kt;break;case Mt:t=Et;break;case St:t=xt}return t}},Rt={};function Ht(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.editing||!i.visible)return;if("circle"===s.name)return;if("button"===s.pointType)return void(s.cursor||(s.cursor="pointer"));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*(Bt.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;Rt[y]?s.cursor=Rt[y]:Rt[y]=s.cursor={url:zt(m,o),x:v,y:_}}function It(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function zt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Dt extends a{}const At=["top","right","bottom","left"];class Zt 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);this.listenPointEvents(a,"rotate",2),s.addMany(...n,h,a,l,...r,...o),this.add(s)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth: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.circle||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,buttons:r,resizePoints:h,rotatePoints:a,resizeLines:l}=this,{middlePoint:d,resizeable:c,rotateable:g,hideOnSmall:u}=e,f="number"==typeof u?u:10,p=!(u&&i<f&&s<f);let m,v,b,y={};for(let o=0;o<8;o++)_.toPoint(_.directionData[o],t,y),v=h[o],m=a[o],b=l[Math.floor(o/2)],v.set(y),m.set(y),b.set(y),v.visible=b.visible=p&&!(!c&&!g),m.visible=p&&g&&c&&!e.rotatePoint,o%2&&(v.visible=m.visible=p&&!!d,(o+1)/2%2?(b.width=i,v.width>i-30&&(v.visible=!1)):(b.height=s,v.rotation=90,v.width>s-30&&(v.visible=!1)));n.visible=p&&g&&!(!e.circle&&!e.rotatePoint),n.visible&&this.layoutCircle(e),o.path&&(o.path=null),o.set(Object.assign(Object.assign({},t),{visible:!0})),r.visible=p&&r.children.length>0,r.visible&&this.layoutButtons(e)}}layoutCircle(t){const{circleDirection:e,circleMargin:i,buttonsMargin:s,buttonsDirection:o,middlePoint:n}=t,r=At.indexOf(e||(this.buttons.children.length&&"bottom"===o?"top":"bottom"));this.setButtonPosition(this.circle,r,i||s,!!n)}layoutButtons(t){const{buttons:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=t,{flippedX:r,flippedY:h}=this;let a=At.indexOf(i);(a%2&&r||(a+1)%2&&h)&&s&&(a=(a+2)%4);const l=s?Bt.getRotateDirection(a,this.flippedOne?this.rotation:-this.rotation,4):a;this.setButtonPosition(e,l,o,!!n),s&&(e.rotation=90*(l-a)),e.scaleX=r?-1:1,e.scaleY=h?-1:1}setButtonPosition(t,e,i,s){const o=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,h=(i+(e%2?(s?o.width:0)+t.boxBounds.width:(s?o.height:0)+t.boxBounds.height)/2)*r;n?(t.x=o.x+h,t.y=o.y):(t.x=o.x,t.y=o.y+h)}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){this.dragging=!0;const{editor:e}=this;"rect"===t.current.name?(this.moving=!0,e.dragStartPoint={x:e.element.x,y:e.element.y},e.opacity=e.mergeConfig.hideOnMove?0:1):"resize"===t.current.pointType&&(e.dragStartBounds=Object.assign({},e.element.getLayoutBounds("box","local")))}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this,i=this.enterPoint=t.current;"rotate"===i.pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):"resize"===i.pointType&&e.onScale(t),Ht(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_(M.START,this.onDragStart,this),t.on_(M.DRAG,this.onDrag,this),t.on_(M.END,this.onDragEnd,this),t.on_(T.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(T.ENTER,(e=>{this.enterPoint=t,Ht(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(ot.SELECT,this.onSelect,this),t.on_(M.START,this.onDragStart,this),t.on_(M.DRAG,e.onMove,e),t.on_(M.END,this.onDragEnd,this),t.on_(T.ENTER,(()=>It(e))),t.on_(T.DOUBLE_TAP,this.onDoubleTap,this),t.on_(T.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}class Wt 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,!0===s?"rgba(0,0,0,0.8)":s),t.setWorld(o.__world,e.matrix),t.clearRect(0,0,n,r)}}destroy(){this.editor=null,super.destroy()}}const Ft='\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"/>',Xt={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${Ft}\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${Ft}\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${Ft}\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,flipable:!0,rotateable:!0,skewable:!0};function Yt(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 Gt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Ut=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Nt={group(t,e,i){t.sort(Ut);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(Gt);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(Gt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Ut),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},jt=L.get("EditToolCreator");function Kt(){return t=>{qt.register(t)}}const $t=Kt,qt={list:{},register(t){const{tag:e}=t.prototype;Qt[e]?jt.repeat(e):Qt[e]=t},get:(t,e)=>new Qt[t](e)},{list:Qt}=qt;class Jt extends ot{constructor(t,e){super(t,e)}}Jt.BEFORE_OPEN="innerEditor.before_open",Jt.OPEN="innerEditor.open",Jt.BEFORE_CLOSE="innerEditor.before_close",Jt.CLOSE="innerEditor.close";class te extends ot{constructor(t,e){super(t,e)}}te.GROUP="editor.group",te.BEFORE_UNGROUP="editor.before_ungroup",te.UNGROUP="editor.ungroup",te.OPEN="editor.open_group",te.CLOSE="editor.close_group";class ee 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=Xt,this.leafList=new m,this.openedGroupList=new m,this.simulateTarget=new u({visible:!1}),this.editBox=new Zt(this),this.editToolList={},this.selector=new Lt(this),this.editMask=new Wt(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&&Yt(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]||qt.get(t,this),this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){if(t instanceof P){if("drag"!==t.moveType){const{moveable:e,resizeable:i}=this.mergeConfig,s=t.getLocalMove(this.element);"move"===e?(t.stop(),this.move(s.x,s.y)):"zoom"===i&&t.stop()}}else{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(M.getValidMove(this.element,this.dragStartPoint,e))}}onScale(t){const{element:e}=this;let{around:i,lockRatio:s,resizeable:o,flipable:n,editSize:r}=this.mergeConfig;if(t instanceof C)"zoom"===o&&(t.stop(),this.scaleOf(e.getInnerPoint(t),t.scale,t.scale));else{const{direction:o}=t.current;(t.shiftKey||e.lockRatio)&&(s=!0);const h=Bt.getScaleData(e,this.dragStartBounds,o,t.getInnerTotal(e),s,Bt.getAround(i,t.altKey),n,this.multiple||"scale"===r);this.editTool.onScaleWithDrag?(h.drag=t,this.scaleWithDrag(h)):this.scaleOf(h.origin,h.scaleX,h.scaleY)}}onRotate(t){const{skewable:e,rotateable:i,around:s,rotateGap:o}=this.mergeConfig,{direction:n,name:r}=t.current;if(e&&"resize-line"===r)return this.onSkew(t);const{element:h}=this;let a,l;if(t instanceof V){if("rotate"!==i)return;t.stop(),l=t.rotation,a=h.getInnerPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=Bt.getRotateData(h.boxBounds,n,t.getInner(h),h.getInnerPoint(e),t.shiftKey?null:h.around||h.origin||s||"center");l=i.rotation,a=i.origin}l=b.getGapRotation(l,o,h.rotation),l&&(h.scaleX*h.scaleY<0&&(l=-l),this.rotateOf(a,b.float(l,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=Bt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Bt.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=new rt(rt.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:e.getWorldPoint(t.origin)}));this.editTool.onScaleWithDrag(i),this.emitEvent(i)}scaleOf(t,e,i=e,s){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:o}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>o.scaleOf(t,e,i))),h=new rt(rt.SCALE,{target:o,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(h),this.emitEvent(h)}flip(t){if(this.element.locked)return;const{element:e}=this,i=this.getWorldOrigin("center"),s=this.multiple?this.getChangedTransform((()=>e.flip(t))):new w(k.getFlipTransform(e,t)),o=new rt(rt.SCALE,{target:e,editor:this,worldOrigin:i,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:s});this.editTool.onScale(o),this.emitEvent(o)}rotateOf(t,e){if(!this.mergeConfig.rotateable||this.element.locked)return;const{element:i}=this,s=this.getWorldOrigin(t),o=this.multiple&&this.getChangedTransform((()=>i.rotateOf(t,e))),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=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>o.skewOf(t,e,i))),h=new at(at.SKEW,{target:o,editor:this,worldOrigin:n,skewX:e,skewY:i,transform:r});this.editTool.onSkew(h),this.emitEvent(h)}getWorldOrigin(t){return this.element.getWorldPoint(k.getInnerOrigin(this.element,t))}getChangedTransform(t){const{element:e}=this,i=new w(e.worldTransform);return t(),new w(e.worldTransform).divide(i)}group(t){return this.multiple&&(this.target=Nt.group(this.list,this.element,t),this.emitGroupEvent(te.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(te.BEFORE_UNGROUP,t))),this.target=Nt.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(te.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(te.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(te.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 te(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&&qt.list[e]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[e]||qt.get(e,this),this.innerEditor.editTarget=t,this.emitInnerEvent(Jt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Jt.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Jt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Jt.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Jt(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&&(Nt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Nt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[this.app.on_(P.BEFORE_MOVE,this.onMove,this,!0),this.app.on_(C.BEFORE_ZOOM,this.onScale,this,!0),this.app.on_(V.BEFORE_ROTATE,this.onRotate,this,!0),t.on_(x.START,this.update,this),t.on_([B.HOLD,B.UP],(t=>{Ht(this,t)})),t.on_(B.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}))}))],ee.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&&Yt(t),It(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],ee.prototype,"target",void 0);class ie{static registerInnerEditor(){qt.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 se=class extends ie{static registerEditTool(){qt.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()}};se=it([Kt()],se);const{left:oe,right:ne}=y,{move:re,copy:he}=v;let ae=class extends se{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===oe;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?(re(t,n,r),s&&re(e,-n,-r)):(s&&re(t,-n,-r),re(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),he(s[7],i),he(e[7],i),he(s[3],h),he(e[3],h)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),h=t===oe||t===ne,s[t].visible=h,e[t].visible=!r&&h}};ae=it([Kt()],ae),S.editor=function(t){return new ee(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{Zt as EditBox,Bt as EditDataHelper,Dt as EditPoint,Lt as EditSelect,yt as EditSelectHelper,se as EditTool,qt as EditToolCreator,ee as Editor,ot as EditorEvent,te as EditorGroupEvent,Nt as EditorHelper,nt as EditorMoveEvent,ht as EditorRotateEvent,rt as EditorScaleEvent,at as EditorSkewEvent,ie as InnerEditor,Jt as InnerEditorEvent,ae as LineEditTool,N as PathScaler,pt as SelectArea,ft as Stroker,Kt as registerEditTool,$t as registerInnerEditor,$ as scaleResize,q as scaleResizeFontSize,tt as scaleResizeGroup,Q as scaleResizePath,J as scaleResizePoints};