@leafer-in/editor 1.4.1 → 1.5.0

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,2 +1,2 @@
1
- import{Event as t,defineKey as e,MatrixHelper as i,BoundsHelper as s,LeafBoundsHelper as o,getMatrixData as n,getBoundsData as r,UI as a,Paint as h,Group as l,Rect as d,Bounds as c,LeafList as g,Direction9 as u,AroundHelper as f,MathHelper as p,PointHelper as m,Box as v,Text as b,Matrix as y,Debug as w,LeafHelper as E,PropertyEvent as L,DataHelper as k,RenderEvent as x,getPointData as _,Plugin as T,Creator as O,dataType as M}from"@leafer-ui/draw";import{PointerEvent as S,DragEvent as P,MoveEvent as C,ZoomEvent as B,Plugin as V,RotateEvent as H,KeyEvent as I}from"@leafer-ui/core";import"@leafer-in/resize";function R(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 D(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class A extends t{get list(){return D(this.value)}get oldList(){return D(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}A.SELECT="editor.select",A.HOVER="editor.hover";class Z extends A{constructor(t,e){super(t,e)}}Z.MOVE="editor.move";class z extends A{constructor(t,e){super(t,e)}}z.SCALE="editor.scale";class W extends A{constructor(t,e){super(t,e)}}W.ROTATE="editor.rotate";class F extends A{constructor(t,e){super(t,e)}}function X(t){return(i,s)=>{const o="_"+s;e(i,s,{get(){return this[o]},set(e){const i=this[o];i!==e&&(this[o]=e,t(this,i))}})}}F.SKEW="editor.skew";const{abs:Y}=Math,{copy:G,scale:U}=i,{setListWithFn:N}=s,{worldBounds:j}=o,K=n(),$=r();class q extends a{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t,this.update()}update(){const{list:t}=this;t.length?(N($,t,j),this.set($)):this.width=this.height=1}__draw(t,e){const{list:i}=this;if(i.length){let s;const o=this.__,{stroke:n,strokeWidth:r,fill:a}=o,{bounds:l}=e;for(let d=0;d<i.length;d++){s=i[d];const{worldTransform:c,worldRenderBounds:g}=s;if(!l||l.hit(g,e.matrix)){const i=Y(c.scaleX),l=Y(c.scaleY);if(i!==l){G(K,c),U(K,1/i,1/l),t.setWorld(K,e.matrix),t.beginPath(),o.strokeWidth=r;const{x:n,y:a,width:h,height:d}=s.__layout.boxBounds;t.rect(n*i,a*l,h*i,d*l)}else t.setWorld(c,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),o.strokeWidth=r/Y(c.scaleX);n&&("string"==typeof n?h.stroke(n,this,t):h.strokes(n,this,t)),a&&("string"==typeof a?h.fill(a,this,t):h.fills(a,this,t))}}o.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}R([X((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[]}))],q.prototype,"target",void 0);class J extends l{constructor(t){super(t),this.strokeArea=new d({strokeAlign:"center"}),this.fillArea=new d,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 Q={findOne:t=>t.list.find((t=>t.editable)),findByBounds(t,e){const i=[];return tt([t],i,e),i}};function tt(t,e,i){let s,o;for(let n=0,r=t.length;n<r;n++)if(s=t[n],o=s.__,o.hittable&&o.visible&&!o.locked&&i.hit(s.__world)){if(o.editable){if(s.isBranch&&!o.hitChildren){o.hitSelf&&e.push(s);continue}if(s.isFrame){if(i.includes(s.__layout.boxBounds,s.__world)){e.push(s);continue}}else i.hit(s.__layout.boxBounds,s.__world)&&o.hitSelf&&e.push(s)}s.isBranch&&tt(s.children,e,i)}}const{findOne:et,findByBounds:it}=Q;class st extends l{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 q,this.targetStroker=new q,this.bounds=new c,this.selectArea=new J,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.hoverStroker.update(),this.targetStroker.update()}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.getInnerPoint(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 g(it(e.app,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&&!et(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new g(this.editor.editBox.rect)};return et(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):et(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_(A.HOVER,this.onHover,this),t.on_(A.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_(P.START,this.onDragStart,this,!0),e.on_(P.DRAG,this.onDrag,this),e.on_(P.END,this.onDragEnd,this),e.on_(C.MOVE,this.onAutoMove,this),e.on_([B.ZOOM,C.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:ot,top:nt,topRight:rt,right:at,bottomRight:ht,bottom:lt,bottomLeft:dt,left:ct}=u,{toPoint:gt}=f,{within:ut}=p,ft={getScaleData(t,e,i,o,n,r,a,h){let l,d={},g=1,u=1;const{boxBounds:f,widthRange:p,heightRange:m,dragBounds:v}=t,{width:b,height:y}=e;r&&(o.x*=2,o.y*=2);const w=t.scaleX/e.scaleX,E=t.scaleY/e.scaleY,L=w<0?-1:1,k=E<0?-1:1,x=h?w:L*f.width/b,_=h?E:k*f.height/y;o.x*=h?w:L,o.y*=h?E:k,Math.abs(o.x)===b&&(o.x+=.1),Math.abs(o.y)===y&&(o.y+=.1);const T=(-o.y+y)/y,O=(o.x+b)/b,M=(o.y+y)/y,S=(-o.x+b)/b;switch(i){case nt:u=T,l="bottom";break;case at:g=O,l="left";break;case lt:u=M,l="top";break;case ct:g=S,l="right";break;case ot:u=T,g=S,l="bottom-right";break;case rt:u=T,g=O,l="bottom-left";break;case ht:u=M,g=O,l="top-left";break;case dt:u=M,g=S,l="top-right"}if(n){if(!("corner"===n&&i%2)){let t;switch(i){case nt:case lt:t=u;break;case ct:case at:t=g;break;default:t=Math.sqrt(Math.abs(g*u))}g=g<0?-t:t,u=u<0?-t:t}}if(g/=x,u/=_,!a){const{worldTransform:e}=t;g<0&&(g=1/f.width/e.scaleX),u<0&&(u=1/f.height/e.scaleY)}if(gt(r||l,f,d,!0),v){const e="parent"===v?t.parent.boxBounds:v,i=new c(t.__localBoxBounds);if(i.scaleOf(t.getLocalPointByInner(d),g,u),!s.includes(e,i)){const t=i.getIntersect(e);g*=t.width/i.width,u*=t.height/i.height}}if(p){const e=f.width*t.scaleX;g=ut(e*g,p)/e}if(m){const e=f.height*t.scaleY;u=ut(e*u,m)/e}return{origin:d,scaleX:g,scaleY:u,direction:i,lockRatio:n,around:r}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case ot:n="bottom-right";break;case rt:n="bottom-left";break;case ht:n="top-left";break;case dt:n="top-right";break;default:n="center"}return gt(o||n,t,r,!0),{origin:r,rotation:m.getRotation(s,r,i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case nt:n={x:.5,y:0},o="bottom",a=1;break;case lt:n={x:.5,y:1},o="top",a=1;break;case ct:n={x:0,y:.5},o="right",h=1;break;case at:n={x:1,y:.5},o="left",h=1}const{width:l,height:d}=t;n.x=n.x*l,n.y=n.y*d,gt(s||o,t,r,!0);const c=m.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(h?i.y:0)});return a?a=-c:h=c,{origin:r,skewX:a,skewY:h}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case ct:t=at;break;case ot:t=rt;break;case dt:t=ht;break;case at:t=ct;break;case rt:t=ot;break;case ht:t=dt}if(i)switch(t){case nt:t=lt;break;case ot:t=dt;break;case rt:t=ht;break;case lt:t=nt;break;case dt:t=ot;break;case ht:t=rt}return t}},pt={};function mt(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:a,resizeable:h,rotateable:l,skewable:d}=t.mergeConfig,{pointType:c}=s,{flippedX:g,flippedY:u}=i;let f="resize"===c;f&&l&&(e.metaKey||e.ctrlKey||!h)&&(f=!1);const m=d&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(ft.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(p.formatRotation(o,!0)/2);const{url:v,x:b,y:y}=m,w=v+o;pt[w]?s.cursor=pt[w]:pt[w]=s.cursor={url:bt(v,o),x:b,y:y}}function vt(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.editBox.rect.cursor=i?e:void 0}function bt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class yt extends v{}const wt=["top","right","bottom","left"];class Et extends l{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 l,this.rect=new v({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new yt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new l({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:h,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new yt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new yt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new yt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);this.listenPointEvents(h,"rotate",2),s.addMany(...n,a,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:a}=t,h=this.getPointsStyle(),l=this.getMiddlePointsStyle();let d;for(let t=0;t<8;t++)d=n[t],d.set(this.getPointStyle(t%2?l[(t-1)/2%l.length]:h[t/2%h.length])),t%2||(d.rotation=t/2*90);o.set(this.getPointStyle(t.circle||t.rotatePoint||h[0])),s.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),s.hittable=!i,s.syncEventer=i&&this.editor,i&&(e.syncEventer=s,this.app.interaction.bottomList=[{target:s,proxy:e}])}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:a,rotatePoints:h,resizeLines:l}=this,{middlePoint:d,resizeable:c,rotateable:g,hideOnSmall:u}=e,p="number"==typeof u?u:10,m=!(u&&i<p&&s<p);let v,b,y,w={};for(let o=0;o<8;o++)f.toPoint(f.directionData[o],t,w),b=a[o],v=h[o],y=l[Math.floor(o/2)],b.set(w),v.set(w),y.set(w),b.visible=y.visible=m&&!(!c&&!g),v.visible=m&&g&&c&&!e.rotatePoint,o%2&&(b.visible=v.visible=m&&!!d,(o+1)/2%2?(y.width=i,b.width>i-30&&(b.visible=!1)):(y.height=s,b.rotation=90,b.width>s-30&&(b.visible=!1)));n.visible=m&&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=m&&r.children.length>0,r.visible&&this.layoutButtons(e)}}layoutCircle(t){const{circleDirection:e,circleMargin:i,buttonsMargin:s,buttonsDirection:o,middlePoint:n}=t,r=wt.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:a}=this;let h=wt.indexOf(i);(h%2&&r||(h+1)%2&&a)&&s&&(h=(h+2)%4);const l=s?ft.getRotateDirection(h,this.flippedOne?this.rotation:-this.rotation,4):h;this.setButtonPosition(e,l,o,!!n),s&&(e.rotation=90*(l-h)),e.scaleX=r?-1:1,e.scaleY=a?-1:1}setButtonPosition(t,e,i,s){const o=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,a=(i+(e%2?(s?o.width:0)+t.boxBounds.width:(s?o.height:0)+t.boxBounds.height)/2)*r;n?(t.x=o.x+a,t.y=o.y):(t.x=o.x,t.y=o.y+a)}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,offsetX:0,offsetY:0};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")),e.resizeDirection=t.current.direction)}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1),this.editor.resizeDirection=void 0}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),mt(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;if(i.locked)return;if(i.isBranch&&!i.editInner){if(i.textBox){const{children:t}=i,s=t.find((t=>t.editable&&t instanceof b))||t.find((t=>t instanceof b));if(s)return e.openInnerEditor(s)}e.openGroup(i),e.target=e.selector.findDeepOne(t)}else e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(P.START,this.onDragStart,this),t.on_(P.DRAG,this.onDrag,this),t.on_(P.END,this.onDragEnd,this),t.on_(S.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(S.ENTER,(e=>{this.enterPoint=t,mt(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(A.SELECT,this.onSelect,this),t.on_(P.START,this.onDragStart,this),t.on_(P.DRAG,e.onMove,e),t.on_(P.END,this.onDragEnd,this),t.on_(S.ENTER,(()=>vt(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 Lt extends a{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 kt='\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${kt}\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${kt}\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${kt}\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},_t=new c;function Tt(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer.zoomLayer;e.safeChange((()=>e.reset(_t.setListWithFn(i,(t=>t.getBounds("box","page"))).get()))),s.add(e)}const Ot=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Mt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),St={group(t,e,i){t.sort(Mt);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new l(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(Ot);const r=new y(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&&!t.isBranchLeaf){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(Ot),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Mt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},Pt=w.get("EditToolCreator");function Ct(){return t=>{Vt.register(t)}}const Bt=Ct,Vt={list:{},register(t){const{tag:e}=t.prototype;Ht[e]&&Pt.repeat(e),Ht[e]=t},get:(t,e)=>new Ht[t](e)},{list:Ht}=Vt;class It extends A{constructor(t,e){super(t,e)}}It.BEFORE_OPEN="innerEditor.before_open",It.OPEN="innerEditor.open",It.BEFORE_CLOSE="innerEditor.before_close",It.CLOSE="innerEditor.close";class Rt extends A{constructor(t,e){super(t,e)}}Rt.GROUP="editor.group",Rt.BEFORE_UNGROUP="editor.before_ungroup",Rt.UNGROUP="editor.ungroup",Rt.OPEN="editor.open_group",Rt.CLOSE="editor.close_group";const{updateMatrix:Dt}=E,At={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},Zt="top-left";class zt extends d{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.on(L.CHANGE,(e=>{if(this.checkChange&&At[e.attrName]){const{attrName:i,newValue:s,oldValue:o}=e,n="s"===i[0]?(s||1)/(o||1):(s||0)-(o||0);this.canChange=!1;const r=this.__;r[i]=o,Dt(this.parent),Dt(this);const a=new y(this.__world);switch(r[i]=s,this.__layout.rotationChange(),Dt(this),this.changedTransform=new y(this.__world).divide(a),i){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(Zt,n);break;case"scaleX":t.scaleOf(Zt,n,1);break;case"scaleY":t.scaleOf(Zt,1,n);break;case"skewX":t.skewOf(Zt,n,0);break;case"skewY":t.skewOf(Zt,0,n)}this.canChange=!0}}))}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class Wt extends l{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 dragHoverExclude(){return[this.editBox.rect]}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 moving(){return this.editBox.moving}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,e){super(e),this.config=k.clone(xt),this.leafList=new g,this.openedGroupList=new g,this.simulateTarget=new zt(this),this.editBox=new Et(this),this.editToolList={},this.selector=new st(this),this.editMask=new Lt(this),this.targetEventIds=[],t&&(this.config=k.default(t,this.config)),this.addMany(this.editMask,this.selector,this.editBox),V.has("resize")||(this.config.editSize="scale")}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(){if(this.editing){if(!this.element.parent)return this.cancel();this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update()}}updateEditBox(){this.multiple&&Tt(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]||Vt.get(t,this),this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){if(t instanceof C){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(P.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 B)"zoom"===o&&(t.stop(),this.scaleOf(e.getBoxPoint(t),t.scale,t.scale));else{const{direction:o}=t.current;(t.shiftKey||e.lockRatio)&&(s=!0);const a=ft.getScaleData(e,this.dragStartBounds,o,t.getInnerTotal(e),s,ft.getAround(i,t.altKey),n,this.multiple||"scale"===r);this.editTool.onScaleWithDrag?(a.drag=t,this.scaleWithDrag(a)):this.scaleOf(a.origin,a.scaleX,a.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:a}=this;let h,l;if(t instanceof H){if("rotate"!==i)return;t.stop(),l=t.rotation,h=a.getBoxPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=ft.getRotateData(a.boxBounds,n,t.getBoxPoint(a),a.getBoxPoint(e),t.shiftKey?null:a.around||a.origin||s||"center");l=i.rotation,h=i.origin}l=p.getGapRotation(l,o,a.rotation),l&&(a.scaleX*a.scaleY<0&&(l=-l),this.rotateOf(h,p.float(l,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=ft.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),ft.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e=0){const{element:i}=this;if(!this.checkTransform("moveable"))return;const s=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0);this.multiple&&i.safeChange((()=>i.move(t,e)));const o=new Z(Z.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o)}scaleWithDrag(t){if(!this.checkTransform("resizeable"))return;const{element:e}=this,i=new z(z.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.checkTransform("resizeable"))return;const{element:o}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>o.safeChange((()=>o.scaleOf(t,e,i))))),a=new z(z.SCALE,{target:o,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(a),this.emitEvent(a)}flip(t){if(!this.checkTransform("resizeable"))return;const{element:e}=this,i=this.getWorldOrigin("center"),s=this.multiple?this.getChangedTransform((()=>e.safeChange((()=>e.flip(t))))):new y(E.getFlipTransform(e,t)),o=new z(z.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.checkTransform("rotateable"))return;const{element:i}=this,s=this.getWorldOrigin(t),o=this.multiple&&this.getChangedTransform((()=>i.safeChange((()=>i.rotateOf(t,e))))),n=new W(W.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.checkTransform("skewable"))return;const{element:o}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>o.safeChange((()=>o.skewOf(t,e,i))))),a=new F(F.SKEW,{target:o,editor:this,worldOrigin:n,skewX:e,skewY:i,transform:r});this.editTool.onSkew(a),this.emitEvent(a)}checkTransform(t){return this.element&&!this.element.locked&&this.mergeConfig[t]}getWorldOrigin(t){return this.element.getWorldPoint(E.getInnerOrigin(this.element,t))}getChangedTransform(t){const{element:e}=this;if(this.multiple&&!e.canChange)return e.changedTransform;const i=new y(e.worldTransform);return t(),new y(e.worldTransform).divide(i)}group(t){return this.multiple&&(this.target=St.group(this.list,this.element,t),this.emitGroupEvent(Rt.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(Rt.BEFORE_UNGROUP,t))),this.target=St.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(Rt.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Rt.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Rt.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!E.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 Rt(t,{editTarget:e});this.emitEvent(i),e.emitEvent(i)}openInnerEditor(t,e){if(t&&e&&(this.target=t),this.single){const e=t||this.element,i=e.editInner;i&&Vt.list[i]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[i]||Vt.get(i,this),this.innerEditor.editTarget=e,this.emitInnerEvent(It.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(It.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(It.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(It.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new It(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&&(St.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(St.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{app:t,leafer:e}=this;this.targetEventIds=[e.on_(x.START,this.update,this),t.on_(x.CHILD_START,this.forceRender,this),t.on_(C.BEFORE_MOVE,this.onMove,this,!0),t.on_(B.BEFORE_ZOOM,this.onScale,this,!0),t.on_(H.BEFORE_ROTATE,this.onRotate,this,!0),t.on_([I.HOLD,I.UP],(t=>{mt(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.target=this.hoverTarget=null,Object.values(this.editToolList).forEach((t=>t.destroy())),this.simulateTarget.destroy(),this.editToolList={},this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}R([X((function(t,e){t.emitEvent(new A(A.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Wt.prototype,"hoverTarget",void 0),R([X((function(t,e){const{target:i}=t;i?(t.leafList=i instanceof g?i:new g(i),t.multiple&&Tt(t)):(t.simulateTarget.remove(),t.leafList.reset(),t.closeInnerEditor()),t.emitEvent(new A(A.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{vt(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],Wt.prototype,"target",void 0);class Ft{static registerInnerEditor(){Vt.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new l,this.onCreate()}onLoad(){}load(){const{editor:t}=this;t&&(t.app&&(t.selector.hittable=t.app.tree.hitChildren=!1),this.onLoad())}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){const{editor:t}=this;t&&(t.app&&(t.selector.hittable=t.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 Xt=class extends Ft{static registerEditTool(){Vt.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="scale"!==o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{x:i,y:s,scaleX:o,scaleY:n,rotation:r,skewX:a,skewY:h,width:l,height:d}=t.element.getLayoutBounds("box",t,!0);e.set({x:i,y:s,scaleX:o,scaleY:n,rotation:r,skewX:a,skewY:h}),e.update({x:0,y:0,width:l,height:d}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};Xt=R([Ct()],Xt);const{left:Yt,right:Gt}=u,{move:Ut,copy:Nt,toNumberPoints:jt}=m;let Kt=class extends Xt{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===Yt;if(n.pathInputed){const{path:t}=n.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,n.points=t}else{const t=_(),{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){const e=jt(t);return{from:{x:e[0],y:e[1]},to:{x:e[2],y:e[3]}}}dragPoint(t,e,i,s,o){const{x:n,y:r}=o;i?(Ut(t,n,r),s&&Ut(e,-n,-r)):(s&&Ut(t,-n,-r),Ut(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,n=this.editor.element;let r,a;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:a}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(a,a,!1,t),o.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),Nt(s[7],i),Nt(e[7],i),Nt(s[3],a),Nt(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===Yt||t===Gt,s[t].visible=a,e[t].visible=!r&&a}};Kt=R([Ct()],Kt),T.add("editor","resize"),O.editor=function(t){return new Wt(t)},M(!1)(v.prototype,"textBox"),e(a.prototype,"editOuter",{get(){return this.__.__isLinePath?"LineEditTool":"EditTool"}}),e(a.prototype,"editInner",{get:()=>"PathEditor"}),e(l.prototype,"editInner",{get:()=>""}),e(b.prototype,"editInner",{get:()=>"TextEditor"}),a.setEditConfig=function(t){e(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},a.setEditOuter=function(t){e(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},a.setEditInner=function(t){e(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})};export{Et as EditBox,ft as EditDataHelper,yt as EditPoint,st as EditSelect,Q as EditSelectHelper,Xt as EditTool,Vt as EditToolCreator,Wt as Editor,A as EditorEvent,Rt as EditorGroupEvent,St as EditorHelper,Z as EditorMoveEvent,W as EditorRotateEvent,z as EditorScaleEvent,F as EditorSkewEvent,Ft as InnerEditor,It as InnerEditorEvent,Kt as LineEditTool,J as SelectArea,q as Stroker,Ct as registerEditTool,Bt as registerInnerEditor};
1
+ import{Event as t,defineKey as e,MatrixHelper as i,BoundsHelper as s,LeafBoundsHelper as o,getMatrixData as n,getBoundsData as r,UI as a,Paint as h,Group as l,Rect as d,Bounds as c,LeafList as g,Direction9 as u,AroundHelper as f,MathHelper as p,PointHelper as m,Box as E,Text as v,Matrix as b,Debug as w,LeafHelper as L,PropertyEvent as y,isNull as k,DataHelper as _,RenderEvent as x,getPointData as O,Plugin as T,Creator as S,dataType as M}from"@leafer-ui/draw";import{PointerEvent as B,DragEvent as C,MoveEvent as P,ZoomEvent as R,Plugin as V,RotateEvent as H,KeyEvent as I}from"@leafer-ui/core";import"@leafer-in/resize";function A(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 D(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class F extends t{get list(){return D(this.value)}get oldList(){return D(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}F.SELECT="editor.select",F.HOVER="editor.hover";class Z extends F{constructor(t,e){super(t,e)}}Z.BEFORE_MOVE="editor.before_move",Z.MOVE="editor.move";class z extends F{constructor(t,e){super(t,e)}}z.BEFORE_SCALE="editor.before_scale",z.SCALE="editor.scale";class W extends F{constructor(t,e){super(t,e)}}W.BEFORE_ROTATE="editor.before_rotate",W.ROTATE="editor.rotate";class G extends F{constructor(t,e){super(t,e)}}function X(t){return(i,s)=>{const o="_"+s;e(i,s,{get(){return this[o]},set(e){const i=this[o];i!==e&&(this[o]=e,t(this,i))}})}}G.BEFORE_SKEW="editor.before_skew",G.SKEW="editor.skew";const{abs:Y}=Math,{copy:U,scale:N}=i,{setListWithFn:j}=s,{worldBounds:K}=o,$=n(),q=r();class J extends a{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t,this.update()}update(){const{list:t}=this;t.length?(j(q,t,K),this.set(q)):this.width=this.height=1}__draw(t,e){const{list:i}=this;if(i.length){let s;const o=this.__,{stroke:n,strokeWidth:r,fill:a}=o,{bounds:l}=e;for(let d=0;d<i.length;d++){s=i[d];const{worldTransform:c,worldRenderBounds:g}=s;if(g.width&&g.height&&(!l||l.hit(g,e.matrix))){const i=Y(c.scaleX),l=Y(c.scaleY);if(i!==l){U($,c),N($,1/i,1/l),t.setWorld($,e.matrix),t.beginPath(),o.strokeWidth=r;const{x:n,y:a,width:h,height:d}=s.__layout.boxBounds;t.rect(n*i,a*l,h*i,d*l)}else t.setWorld(c,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),o.strokeWidth=r/Y(c.scaleX);n&&("string"==typeof n?h.stroke(n,this,t):h.strokes(n,this,t)),a&&("string"==typeof a?h.fill(a,this,t):h.fills(a,this,t))}}o.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}A([X((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[]}))],J.prototype,"target",void 0);class Q extends l{constructor(t){super(t),this.strokeArea=new d({strokeAlign:"center"}),this.fillArea=new d,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 tt={findOne:t=>t.list.find((t=>t.editable)),findByBounds(t,e){const i=[];return et([t],i,e),i}};function et(t,e,i){let s,o;for(let n=0,r=t.length;n<r;n++)if(s=t[n],o=s.__,o.hittable&&o.visible&&!o.locked&&i.hit(s.__world)){if(o.editable){if(s.isBranch&&!o.hitChildren){o.hitSelf&&e.push(s);continue}if(s.isFrame){if(i.includes(s.__layout.boxBounds,s.__world)){e.push(s);continue}}else i.hit(s.__layout.boxBounds,s.__world)&&o.hitSelf&&e.push(s)}s.isBranch&&et(s.children,e,i)}}const{findOne:it,findByBounds:st}=tt;class ot extends l{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 J,this.targetStroker=new J,this.bounds=new c,this.selectArea=new Q,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,selectedStyle:o}=t;this.targetStroker.setTarget(e,Object.assign({stroke:i,strokeWidth:Math.max(1,s/2)},o||{})),this.hoverStroker.target=null}}update(){this.hoverStroker.update(),this.targetStroker.update()}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.getInnerPoint(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 g(st(e.app,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&&!it(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new g(this.editor.editBox.rect)};return it(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):it(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_(F.HOVER,this.onHover,this),t.on_(F.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_(C.START,this.onDragStart,this,!0),e.on_(C.DRAG,this.onDrag,this),e.on_(C.END,this.onDragEnd,this),e.on_(P.MOVE,this.onAutoMove,this),e.on_([R.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:nt,top:rt,topRight:at,right:ht,bottomRight:lt,bottom:dt,bottomLeft:ct,left:gt}=u,{toPoint:ut}=f,{within:ft}=p,pt={getScaleData(t,e,i,o,n,r,a,h){let l,d={},g=1,u=1;const{boxBounds:f,widthRange:p,heightRange:m,dragBounds:E,worldBoxBounds:v}=t,{width:b,height:w}=e;r&&(o.x*=2,o.y*=2);const L=t.scaleX/e.scaleX,y=t.scaleY/e.scaleY,k=L<0?-1:1,_=y<0?-1:1,x=h?L:k*f.width/b,O=h?y:_*f.height/w;o.x*=h?L:k,o.y*=h?y:_;const T=(-o.y+w)/w,S=(o.x+b)/b,M=(o.y+w)/w,B=(-o.x+b)/b;switch(i){case rt:u=T,l="bottom";break;case ht:g=S,l="left";break;case dt:u=M,l="top";break;case gt:g=B,l="right";break;case nt:u=T,g=B,l="bottom-right";break;case at:u=T,g=S,l="bottom-left";break;case lt:u=M,g=S,l="top-left";break;case ct:u=M,g=B,l="top-right"}if(n){if(!("corner"===n&&i%2)){let t;switch(i){case rt:case dt:t=u;break;case gt:case ht:t=g;break;default:t=Math.sqrt(Math.abs(g*u))}g=g<0?-t:t,u=u<0?-t:t}}if(g/=x,u/=O,!a){const{worldTransform:e}=t;g<0&&(g=1/f.width/e.scaleX),u<0&&(u=1/f.height/e.scaleY)}if(ut(r||l,f,d,!0),E){const e="parent"===E?t.parent.boxBounds:E,i=new c(t.__localBoxBounds);if(i.scaleOf(t.getLocalPointByInner(d),g,u),!s.includes(e,i)){const t=i.getIntersect(e);g*=t.width/i.width,u*=t.height/i.height}}if(p){const e=f.width*t.scaleX;g=ft(e*g,p)/e}if(m){const e=f.height*t.scaleY;u=ft(e*u,m)/e}return Math.abs(g*v.width)<1&&(g=(g<0?-1:1)/v.width),Math.abs(u*v.height)<1&&(u=(u<0?-1:1)/v.height),{origin:d,scaleX:g,scaleY:u,direction:i,lockRatio:n,around:r}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case nt:n="bottom-right";break;case at:n="bottom-left";break;case lt:n="top-left";break;case ct:n="top-right";break;default:n="center"}return ut(o||n,t,r,!0),{origin:r,rotation:m.getRotation(s,r,i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case rt:n={x:.5,y:0},o="bottom",a=1;break;case dt:n={x:.5,y:1},o="top",a=1;break;case gt:n={x:0,y:.5},o="right",h=1;break;case ht:n={x:1,y:.5},o="left",h=1}const{width:l,height:d}=t;n.x=n.x*l,n.y=n.y*d,ut(s||o,t,r,!0);const c=m.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(h?i.y:0)});return a?a=-c:h=c,{origin:r,skewX:a,skewY:h}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case gt:t=ht;break;case nt:t=at;break;case ct:t=lt;break;case ht:t=gt;break;case at:t=nt;break;case lt:t=ct}if(i)switch(t){case rt:t=dt;break;case nt:t=ct;break;case at:t=lt;break;case dt:t=rt;break;case ct:t=nt;break;case lt:t=at}return t}},mt={};function Et(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:a,resizeable:h,rotateable:l,skewable:d}=t.mergeConfig,{pointType:c}=s,{flippedX:g,flippedY:u}=i;let f=c.includes("resize");f&&l&&(e.metaKey||e.ctrlKey||!h)&&(f=!1);const m=d&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(pt.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(p.formatRotation(o,!0)/2);const{url:E,x:v,y:b}=m,w=E+o;mt[w]?s.cursor=mt[w]:mt[w]=s.cursor={url:bt(E,o),x:v,y:b}}function vt(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.editBox.rect.cursor=i?e:void 0}function bt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class wt extends E{}const Lt=["top","right","bottom","left"],yt=void 0;class kt extends l{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 l,this.rect=new E({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new wt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new l({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.dragStartData={},this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:h,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new wt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new wt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new wt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);this.listenPointEvents(h,"rotate",2),s.addMany(...n,a,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:a}=t,h=this.getPointsStyle(),l=this.getMiddlePointsStyle();let d;for(let t=0;t<8;t++)d=n[t],d.set(this.getPointStyle(t%2?l[(t-1)/2%l.length]:h[t/2%h.length])),t%2||(d.rotation=t/2*90);o.set(this.getPointStyle(t.circle||t.rotatePoint||h[0])),s.set(Object.assign({stroke:r,strokeWidth:a,editConfig:yt},t.rect||{})),s.hittable=!i,s.syncEventer=i&&this.editor,i&&(e.syncEventer=s,this.app.interaction.bottomList=[{target:s,proxy:e}])}update(t){const{mergeConfig:e,element:i,multiple:s}=this.editor,{middlePoint:o,resizeable:n,rotateable:r,hideOnSmall:a,editBox:h}=e;if(this.visible=!i.locked,this.view.worldOpacity){const{width:i,height:l}=t,{rect:d,circle:c,buttons:g,resizePoints:u,rotatePoints:p,resizeLines:m}=this,E="number"==typeof a?a:10,v=h&&!(a&&i<E&&l<E);let b,w,L,y={};for(let s=0;s<8;s++)f.toPoint(f.directionData[s],t,y),w=u[s],b=p[s],L=m[Math.floor(s/2)],w.set(y),b.set(y),L.set(y),w.visible=L.visible=v&&!(!n&&!r),b.visible=v&&r&&n&&!e.rotatePoint,s%2&&(w.visible=b.visible=v&&!!o,(s+1)/2%2?(L.width=i,a&&2*w.width>i&&(w.visible=!1)):(L.height=l,w.rotation=90,a&&2*w.width>l&&(w.visible=!1)));c.visible=v&&r&&!(!e.circle&&!e.rotatePoint),c.visible&&this.layoutCircle(e),d.path&&(d.path=null),d.set(Object.assign(Object.assign({},t),{visible:!!s||h})),g.visible=v&&g.children.length>0,g.visible&&this.layoutButtons(e)}}layoutCircle(t){const{circleDirection:e,circleMargin:i,buttonsMargin:s,buttonsDirection:o,middlePoint:n}=t,r=Lt.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:a}=this;let h=Lt.indexOf(i);(h%2&&r||(h+1)%2&&a)&&s&&(h=(h+2)%4);const l=s?pt.getRotateDirection(h,this.flippedOne?this.rotation:-this.rotation,4):h;this.setButtonPosition(e,l,o,!!n),s&&(e.rotation=90*(l-h)),e.scaleX=r?-1:1,e.scaleY=a?-1:1}setButtonPosition(t,e,i,s){const o=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,a=(i+(e%2?(s?o.width:0)+t.boxBounds.width:(s?o.height:0)+t.boxBounds.height)/2)*r;n?(t.x=o.x+a,t.y=o.y):(t.x=o.x,t.y=o.y+a)}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,offsetX:0,offsetY:0,editConfig:yt};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 e=this.dragPoint=t.current,{editor:i,dragStartData:s}=this,{element:o}=i;"rect"===e.name&&(this.moving=!0,i.opacity=i.mergeConfig.hideOnMove?0:1),s.x=t.x,s.y=t.y,s.point={x:o.x,y:o.y},s.bounds=Object.assign({},o.getLayoutBounds("box","local")),s.rotation=o.rotation}onDragEnd(t){this.dragging=!1,this.dragPoint=null,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this,{pointType:i}=this.enterPoint=t.current;(i.includes("rotate")||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable)&&e.onRotate(t),i.includes("resize")&&e.onScale(t),Et(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;if(i.locked)return;if(i.isBranch&&!i.editInner){if(i.textBox){const{children:t}=i,s=t.find((t=>t.editable&&t instanceof v))||t.find((t=>t instanceof v));if(s)return e.openInnerEditor(s)}e.openGroup(i),e.target=e.selector.findDeepOne(t)}else e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(C.START,this.onDragStart,this),t.on_(C.DRAG,this.onDrag,this),t.on_(C.END,this.onDragEnd,this),t.on_(B.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(B.ENTER,(e=>{this.enterPoint=t,Et(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(F.SELECT,this.onSelect,this),t.on_(C.START,this.onDragStart,this),t.on_(C.DRAG,e.onMove,e),t.on_(C.END,this.onDragEnd,this),t.on_(B.ENTER,(()=>vt(e))),t.on_(B.DOUBLE_TAP,this.onDoubleTap,this),t.on_(B.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}class _t extends a{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 xt='\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"/>',Ot={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${xt}\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${xt}\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${xt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,editBox:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,flipable:!0,rotateable:!0,skewable:!0},Tt=new c;function St(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer.zoomLayer;e.safeChange((()=>{Tt.setListWithFn(i,(t=>t.getBounds("box","page"))),0===Tt.width&&(Tt.width=.1),0===Tt.height&&(Tt.height=.1),e.reset(Tt.get())})),s.add(e)}function Mt(t){return t.editable&&!t.locked}const Bt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Ct=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Pt={group(t,e,i){t.sort(Ct);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new l(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(Bt);const r=new b(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&&!t.isBranchLeaf){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(Bt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Ct),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},Rt=w.get("EditToolCreator");function Vt(){return t=>{It.register(t)}}const Ht=Vt,It={list:{},register(t){const{tag:e}=t.prototype;At[e]&&Rt.repeat(e),At[e]=t},get:(t,e)=>new At[t](e)},{list:At}=It;class Dt extends F{constructor(t,e){super(t,e)}}Dt.BEFORE_OPEN="innerEditor.before_open",Dt.OPEN="innerEditor.open",Dt.BEFORE_CLOSE="innerEditor.before_close",Dt.CLOSE="innerEditor.close";class Ft extends F{constructor(t,e){super(t,e)}}Ft.BEFORE_GROUP="editor.before_group",Ft.GROUP="editor.group",Ft.BEFORE_UNGROUP="editor.before_ungroup",Ft.UNGROUP="editor.ungroup",Ft.BEFORE_OPEN="editor.before_open_group",Ft.OPEN="editor.open_group",Ft.BEFORE_CLOSE="editor.before_close_group",Ft.CLOSE="editor.close_group";const{updateMatrix:Zt}=L,zt={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},Wt="top-left";class Gt extends d{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.on(y.CHANGE,(e=>{if(this.checkChange&&zt[e.attrName]){const{attrName:i,newValue:s,oldValue:o}=e,n="s"===i[0]?(s||1)/(o||1):(s||0)-(o||0);this.canChange=!1;const r=this.__;r[i]=o,Zt(this.parent),Zt(this);const a=new b(this.__world);switch(r[i]=s,this.__layout.rotationChange(),Zt(this),this.changedTransform=new b(this.__world).divide(a),i){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(Wt,n);break;case"scaleX":t.scaleOf(Wt,n,1);break;case"scaleY":t.scaleOf(Wt,1,n);break;case"skewX":t.skewOf(Wt,n,0);break;case"skewY":t.skewOf(Wt,0,n)}this.canChange=!0}}))}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class Xt extends l{get mergeConfig(){const{config:t,element:e,dragPoint:i}=this,s=Object.assign({},t);return e&&e.editConfig&&Object.assign(s,e.editConfig),i&&(i.editConfig&&Object.assign(s,i.editConfig),"font-size"===s.editSize&&(s.lockRatio=!0),"resize-rotate"===i.pointType&&(s.around||(s.around="center"),k(s.lockRatio)&&(s.lockRatio=!0))),s}get list(){return this.leafList.list}get dragHoverExclude(){return[this.editBox.rect]}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 moving(){return this.editBox.moving}get dragPoint(){return this.editBox.dragPoint}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,e){super(e),this.config=_.clone(Ot),this.leafList=new g,this.openedGroupList=new g,this.simulateTarget=new Gt(this),this.editBox=new kt(this),this.editToolList={},this.selector=new ot(this),this.editMask=new _t(this),this.targetEventIds=[],t&&(this.config=_.default(t,this.config)),this.addMany(this.editMask,this.selector,this.editBox),V.has("resize")||(this.config.editSize="scale")}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(){if(this.editing){if(!this.element.parent)return this.cancel();this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update()}}updateEditBox(){this.multiple&&St(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]||It.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(C.getValidMove(this.element,this.editBox.dragStartData.point,e))}}onScale(t){const{element:e}=this;let{around:i,lockRatio:s,resizeable:o,flipable:n,editSize:r}=this.mergeConfig;if(t instanceof R)"zoom"===o&&(t.stop(),this.scaleOf(e.getBoxPoint(t),t.scale,t.scale));else{const{direction:o}=t.current;(t.shiftKey||e.lockRatio)&&(s=!0);const a=pt.getScaleData(e,this.editBox.dragStartData.bounds,o,t.getInnerTotal(e),s,pt.getAround(i,t.altKey),n,this.multiple||"scale"===r);this.editTool.onScaleWithDrag?(a.drag=t,this.scaleWithDrag(a)):this.scaleOf(a.origin,a.scaleX,a.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:a}=this,{dragStartData:h}=this.editBox;let l,d;if(t instanceof H){if("rotate"!==i)return;t.stop(),d=t.rotation,l=a.getBoxPoint(t),a.scaleX*a.scaleY<0&&(d=-d)}else{const e=pt.getRotateData(a.boxBounds,n,t.getBoxPoint(a),a.getBoxPoint(h),t.shiftKey?null:a.around||a.origin||s||"center");d=e.rotation,l=e.origin}a.scaleX*a.scaleY<0&&(d=-d),t instanceof C&&(d=h.rotation+d-a.rotation),d=p.float(p.getGapRotation(d,o,a.rotation),2),d&&this.rotateOf(l,d)}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=pt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),pt.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e=0){const{element:i}=this;if(!this.checkTransform("moveable"))return;const s=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0);this.multiple&&i.safeChange((()=>i.move(t,e)));const o={target:i,editor:this,moveX:s.x,moveY:s.y};this.emitEvent(new Z(Z.BEFORE_MOVE,o));const n=new Z(Z.MOVE,o);this.editTool.onMove(n),this.emitEvent(n)}scaleWithDrag(t){if(!this.checkTransform("resizeable"))return;const{element:e}=this;t=Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:e.getWorldPoint(t.origin)}),this.emitEvent(new z(z.BEFORE_SCALE,t));const i=new z(z.SCALE,t);this.editTool.onScaleWithDrag(i),this.emitEvent(i)}scaleOf(t,e,i=e,s){if(!this.checkTransform("resizeable"))return;const{element:o}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>o.safeChange((()=>o.scaleOf(t,e,i))))),a={target:o,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r};this.emitEvent(new z(z.BEFORE_SCALE,a));const h=new z(z.SCALE,a);this.editTool.onScale(h),this.emitEvent(h)}flip(t){if(!this.checkTransform("resizeable"))return;const{element:e}=this,i=this.getWorldOrigin("center"),s=this.multiple?this.getChangedTransform((()=>e.safeChange((()=>e.flip(t))))):new b(L.getFlipTransform(e,t)),o={target:e,editor:this,worldOrigin:i,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:s};this.emitEvent(new z(z.BEFORE_SCALE,o));const n=new z(z.SCALE,o);this.editTool.onScale(n),this.emitEvent(n)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{element:i}=this,s=this.getWorldOrigin(t),o=this.multiple&&this.getChangedTransform((()=>i.safeChange((()=>i.rotateOf(t,e))))),n={target:i,editor:this,worldOrigin:s,rotation:e,transform:o};this.emitEvent(new W(W.BEFORE_ROTATE,n));const r=new W(W.ROTATE,n);this.editTool.onRotate(r),this.emitEvent(r)}skewOf(t,e,i=0,s){if(!this.checkTransform("skewable"))return;const{element:o}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>o.safeChange((()=>o.skewOf(t,e,i))))),a={target:o,editor:this,worldOrigin:n,skewX:e,skewY:i,transform:r};this.emitEvent(new G(G.BEFORE_SKEW,a));const h=new G(G.SKEW,a);this.editTool.onSkew(h),this.emitEvent(h)}checkTransform(t){return this.element&&!this.element.locked&&this.mergeConfig[t]}getWorldOrigin(t){return this.element.getWorldPoint(L.getInnerOrigin(this.element,t))}getChangedTransform(t){const{element:e}=this;if(this.multiple&&!e.canChange)return e.changedTransform;const i=new b(e.worldTransform);return t(),new b(e.worldTransform).divide(i)}group(t){return this.multiple&&(this.emitGroupEvent(Ft.BEFORE_GROUP),this.target=Pt.group(this.list,this.element,t),this.emitGroupEvent(Ft.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(Ft.BEFORE_UNGROUP,t))),this.target=Pt.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(Ft.UNGROUP,t)))),this.list}openGroup(t){this.emitGroupEvent(Ft.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Ft.OPEN,t)}closeGroup(t){this.emitGroupEvent(Ft.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Ft.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!L.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 Ft(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}openInnerEditor(t,e){if(t&&e&&(this.target=t),this.single){const e=t||this.element,i=e.editInner;i&&It.list[i]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[i]||It.get(i,this),this.innerEditor.editTarget=e,this.emitInnerEvent(Dt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Dt.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Dt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Dt.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Dt(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&&(Pt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Pt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{app:t,leafer:e}=this;this.targetEventIds=[e.on_(x.START,this.update,this),t.on_(x.CHILD_START,this.forceRender,this),t.on_(P.BEFORE_MOVE,this.onMove,this,!0),t.on_(R.BEFORE_ZOOM,this.onScale,this,!0),t.on_(H.BEFORE_ROTATE,this.onRotate,this,!0),t.on_([I.HOLD,I.UP],(t=>{Et(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.target=this.hoverTarget=null,Object.values(this.editToolList).forEach((t=>t.destroy())),this.simulateTarget.destroy(),this.editToolList={},this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}A([X((function(t,e){t.emitEvent(new F(F.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Xt.prototype,"hoverTarget",void 0),A([X((function(t,e){const{target:i}=t;if(i){const{list:e}=t.leafList=i instanceof g?i:new g(i);if(!e.every(Mt))return void(t.target=e.filter(Mt));t.multiple&&St(t)}else t.simulateTarget.remove(),t.leafList.reset(),t.closeInnerEditor();t.emitEvent(new F(F.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{vt(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],Xt.prototype,"target",void 0);class Yt{static registerInnerEditor(){It.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new l,this.onCreate()}onLoad(){}load(){const{editor:t}=this;t&&(t.app&&(t.selector.hittable=t.app.tree.hitChildren=!1),this.onLoad())}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){const{editor:t}=this;t&&(t.app&&(t.selector.hittable=t.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 Ut=class extends Yt{static registerEditTool(){It.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="scale"!==o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{x:i,y:s,scaleX:o,scaleY:n,rotation:r,skewX:a,skewY:h,width:l,height:d}=t.element.getLayoutBounds("box",t,!0);e.set({x:i,y:s,scaleX:o,scaleY:n,rotation:r,skewX:a,skewY:h}),e.update({x:0,y:0,width:l,height:d}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};Ut=A([Vt()],Ut);const{left:Nt,right:jt}=u,{move:Kt,copy:$t,toNumberPoints:qt}=m;let Jt=class extends Ut{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===Nt;if(n.pathInputed){const{path:t}=n.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,n.points=t}else{const t=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){const e=qt(t);return{from:{x:e[0],y:e[1]},to:{x:e[2],y:e[3]}}}dragPoint(t,e,i,s,o){const{x:n,y:r}=o;i?(Kt(t,n,r),s&&Kt(e,-n,-r)):(s&&Kt(t,-n,-r),Kt(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,n=this.editor.element;let r,a;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:a}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(a,a,!1,t),o.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),$t(s[7],i),$t(e[7],i),$t(s[3],a),$t(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===Nt||t===jt,s[t].visible=a,e[t].visible=!r&&a}};Jt=A([Vt()],Jt),T.add("editor","resize"),S.editor=function(t){return new Xt(t)},E.addAttr("textBox",!1,M),a.addAttr("editConfig",void 0,M),a.addAttr("editOuter",(t=>t.__.__isLinePath?"LineEditTool":"EditTool"),M),a.addAttr("editInner","PathEditor",M),l.addAttr("editInner","",M),v.addAttr("editInner","TextEditor",M),a.setEditConfig=function(t){this.changeAttr("editConfig",t)},a.setEditOuter=function(t){this.changeAttr("editOuter",t)},a.setEditInner=function(t){this.changeAttr("editInner",t)};export{kt as EditBox,pt as EditDataHelper,wt as EditPoint,ot as EditSelect,tt as EditSelectHelper,Ut as EditTool,It as EditToolCreator,Xt as Editor,F as EditorEvent,Ft as EditorGroupEvent,Pt as EditorHelper,Z as EditorMoveEvent,W as EditorRotateEvent,z as EditorScaleEvent,G as EditorSkewEvent,Yt as InnerEditor,Dt as InnerEditorEvent,Jt as LineEditTool,Q as SelectArea,J as Stroker,Vt as registerEditTool,Ht as registerInnerEditor};
2
2
  //# sourceMappingURL=editor.esm.min.js.map