@leafer-in/editor
Version:
3 lines (2 loc) • 41.6 kB
JavaScript
"use strict";var t=require("@leafer-ui/draw"),e=require("@leafer-ui/core");function i(t,e,i,o){var s,n=arguments.length,r=n<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,o);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(n<3?s(r):n>3?s(e,i,r):s(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function o(t){return t?t instanceof Array?t:[t]:[]}require("@leafer-in/resize"),"function"==typeof SuppressedError&&SuppressedError;class s extends t.Event{get list(){return o(this.value)}get oldList(){return o(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}s.BEFORE_SELECT="editor.before_select",s.SELECT="editor.select",s.BEFORE_HOVER="editor.before_hover",s.HOVER="editor.hover";class n extends s{constructor(t,e){super(t,e)}}n.BEFORE_MOVE="editor.before_move",n.MOVE="editor.move";class r extends s{constructor(t,e){super(t,e)}}r.BEFORE_SCALE="editor.before_scale",r.SCALE="editor.scale";class a extends s{constructor(t,e){super(t,e)}}a.BEFORE_ROTATE="editor.before_rotate",a.ROTATE="editor.rotate";class h extends s{constructor(t,e){super(t,e)}}function l(e){return(i,o)=>{const n="_"+o;t.defineKey(i,o,{get(){return this[n]},set(t){const i=this[n];if(i!==t){if(this.config){const e="target"===o;if(e){t instanceof Array&&t.length>1&&t[0].locked&&t.splice(0,1);const{beforeSelect:e}=this.config;if(e){const i=e({target:t});if("object"==typeof i)t=i;else if(!1===i)return}}const n=e?s.BEFORE_SELECT:s.BEFORE_HOVER;this.hasEvent(n)&&this.emitEvent(new s(n,{editor:this,value:t,oldValue:i}))}this[n]=t,e(this,i)}}})}}h.BEFORE_SKEW="editor.before_skew",h.SKEW="editor.skew";const{abs:d}=Math,{copy:c,scale:g}=t.MatrixHelper,{setListWithFn:u}=t.BoundsHelper,{worldBounds:f}=t.LeafBoundsHelper,p=t.getMatrixData(),E=t.getBoundsData();class m extends t.UI{constructor(){super(),this.list=[],this.visible=0,this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t,this.update()}update(){const{list:t}=this;t.length?(u(E,t,f),this.set(E),this.visible=!0):this.visible=0}__draw(e,i){const{list:o}=this;if(o.length){let s;const n=this.__,{stroke:r,strokeWidth:a,fill:h}=n,{bounds:l}=i;for(let u=0;u<o.length;u++){s=o[u];const{worldTransform:f,worldRenderBounds:E}=s;if(E.width&&E.height&&(!l||l.hit(E,i.matrix))){const o=d(f.scaleX),l=d(f.scaleY);if(c(p,f),p.half=a%2,o!==l){g(p,1/o,1/l),e.setWorld(p,i.matrix),e.beginPath(),n.strokeWidth=a;const{x:t,y:r,width:h,height:d}=s.__layout.boxBounds;e.rect(t*o,r*l,h*o,d*l)}else e.setWorld(p,i.matrix),e.beginPath(),s.__.__useArrow?s.__drawPath(e):s.__.__pathForRender?s.__drawRenderPath(e):s.__drawPathByBox(e),n.strokeWidth=a/d(f.scaleX);r&&("string"==typeof r?t.Paint.stroke(r,this,e):t.Paint.strokes(r,this,e)),h&&("string"==typeof h?t.Paint.fill(h,this,e):t.Paint.fills(h,this,e))}}n.strokeWidth=a}}destroy(){this.target=null,super.destroy()}}i([l((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[]}))],m.prototype,"target",void 0);class v extends t.Group{constructor(e){super(e),this.strokeArea=new t.Rect({strokeAlign:"center"}),this.fillArea=new t.Rect,this.visible=0,this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:o,strokeWidth:s}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:o,strokeWidth:s},e||{})),this.fillArea.reset({visible:!e,fill:o,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const b={findOne:t=>t.list.find((t=>t.editable)),findByBounds(t,e){const i=[];return w([t],i,e),i}};function w(t,e,i){let o,s;for(let n=0,r=t.length;n<r;n++)if(o=t[n],s=o.__,s.hittable&&s.visible&&!s.locked&&i.hit(o.__world)){if(s.editable){if(o.isBranch&&!s.hitChildren){s.hitSelf&&e.push(o);continue}if(o.isFrame){if(i.includes(o.__layout.boxBounds,o.__world)){e.push(o);continue}}else i.hit(o.__layout.boxBounds,o.__world)&&s.hitSelf&&e.push(o)}o.isBranch&&w(o.children,e,i)}}const{findOne:L,findByBounds:y}=b;class x extends t.Group{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(e){super(),this.hoverStroker=new m,this.targetStroker=new m,this.bounds=new t.Bounds,this.selectArea=new v,this.__eventIds=[],this.editor=e,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:o,hoverStyle:s}=t.mergeConfig;this.hoverStroker.setTarget(o?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},s||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:o,selectedStyle:s}=t;this.targetStroker.setTarget(e,Object.assign({stroke:i,strokeWidth:Math.max(1,o/2)},s||{})),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:o}=e.mergeConfig,{x:s,y:n}=t.getInnerPoint(this);this.bounds.set(s,n),this.selectArea.setStyle({visible:!0,stroke:i,x:s,y:n},o),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(e){if(!e.multiTouch){if(this.editor.dragging)return this.onDragEnd(e);if(this.dragging){const{editor:i}=this,o=e.getInnerTotal(this),s=this.bounds.clone().unsign(),n=new t.LeafList(y(i.app,s));if(this.bounds.width=o.x,this.bounds.height=o.y,this.selectArea.setBounds(s.get()),n.length){const t=[];this.originList.forEach((e=>{n.has(e)||t.push(e)})),n.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==i.list.length||i.list.some(((e,i)=>e!==t[i])))&&(i.target=t)}else i.target=this.originList.list}}}onDragEnd(t){t.multiTouch||this.dragging&&(this.originList=null,this.selectArea.visible=0)}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){const{boxSelect:e,multipleSelect:i}=this.editor.mergeConfig;return!(!(this.running&&i&&e)||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!L(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(e){const i={exclude:new t.LeafList(this.editor.editBox.rect)};return L(e.target.leafer.interaction.findPath(e,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):L(t.path)}isMultipleSelect(t){const{multipleSelect:e,continuousSelect:i}=this.editor.mergeConfig;return e&&(t.shiftKey||i)}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:i}=t;i.selector.proxy=t,this.__eventIds=[t.on_(s.HOVER,this.onHover,this),t.on_(s.SELECT,this.onSelect,this),i.on_(e.PointerEvent.MOVE,this.onPointerMove,this),i.on_(e.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this),i.on_(e.PointerEvent.TAP,this.onTap,this),i.on_(e.DragEvent.START,this.onDragStart,this,!0),i.on_(e.DragEvent.DRAG,this.onDrag,this),i.on_(e.DragEvent.END,this.onDragEnd,this),i.on_(e.MoveEvent.MOVE,this.onAutoMove,this),i.on_([e.ZoomEvent.ZOOM,e.MoveEvent.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:k,top:_,topRight:O,right:T,bottomRight:S,bottom:M,bottomLeft:B,left:P}=t.Direction9,{toPoint:C}=t.AroundHelper,{within:R}=t.MathHelper,H={getScaleData(e,i,o,s,n,r,a,h){let l,d={},c=1,g=1;const{boxBounds:u,widthRange:f,heightRange:p,dragBounds:E,worldBoxBounds:m}=e,{width:v,height:b}=i;r&&(s.x*=2,s.y*=2);const w=e.scaleX/i.scaleX,L=e.scaleY/i.scaleY,y=w<0?-1:1,x=L<0?-1:1,H=h?w:y*u.width/v,V=h?L:x*u.height/b;s.x*=h?w:y,s.y*=h?L:x;const I=(-s.y+b)/b,D=(s.x+v)/v,A=(s.y+b)/b,z=(-s.x+v)/v;switch(o){case _:g=I,l="bottom";break;case T:c=D,l="left";break;case M:g=A,l="top";break;case P:c=z,l="right";break;case k:g=I,c=z,l="bottom-right";break;case O:g=I,c=D,l="bottom-left";break;case S:g=A,c=D,l="top-left";break;case B:g=A,c=z,l="top-right"}if(n)if("corner"===n&&o%2)n=!1;else{let t;switch(o){case _:case M:t=g;break;case P:case T:t=c;break;default:t=Math.sqrt(Math.abs(c*g))}c=c<0?-t:t,g=g<0?-t:t}const F=1!==c,Z=1!==g;if(F&&(c/=H),Z&&(g/=V),!a){const{worldTransform:t}=e;c<0&&(c=1/u.width/t.scaleX),g<0&&(g=1/u.height/t.scaleY)}if(C(r||l,u,d,!0),E){const i="parent"===E?e.parent.boxBounds:E,o=new t.Bounds(e.__localBoxBounds);if(o.scaleOf(e.getLocalPointByInner(d),c,g),!t.BoundsHelper.includes(i,o)){const t=o.getIntersect(i),e=t.width/o.width,s=t.height/o.height;F&&(c*=e),Z&&(g*=s)}}if(F&&f){const t=u.width*e.scaleX;c=R(t*c,f)/t}if(Z&&p){const t=u.height*e.scaleY;g=R(t*g,p)/t}return F&&Math.abs(c*m.width)<1&&(c=(c<0?-1:1)/m.width),Z&&Math.abs(g*m.height)<1&&(g=(g<0?-1:1)/m.height),n&&c!==g&&(g=c=Math.min(c,g)),{origin:d,scaleX:c,scaleY:g,direction:o,lockRatio:n,around:r}},getRotateData(e,i,o,s,n){let r,a={};switch(i){case k:r="bottom-right";break;case O:r="bottom-left";break;case S:r="top-left";break;case B:r="top-right";break;default:r="center"}return C(n||r,e,a,!0),{origin:a,rotation:t.PointHelper.getRotation(s,a,o)}},getSkewData(e,i,o,s){let n,r,a={},h=0,l=0;switch(i){case _:case k:r={x:.5,y:0},n="bottom",h=1;break;case M:case S:r={x:.5,y:1},n="top",h=1;break;case P:case B:r={x:0,y:.5},n="right",l=1;break;case T:case O:r={x:1,y:.5},n="left",l=1}const{width:d,height:c}=e;r.x=r.x*d,r.y=r.y*c,C(s||n,e,a,!0);const g=t.PointHelper.getRotation(r,a,{x:r.x+(h?o.x:0),y:r.y+(l?o.y:0)});return h?h=-g:l=g,{origin:a,skewX:h,skewY:l}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case P:t=T;break;case k:t=O;break;case B:t=S;break;case T:t=P;break;case O:t=k;break;case S:t=B}if(i)switch(t){case _:t=M;break;case k:t=B;break;case O:t=S;break;case M:t=_;break;case B:t=k;break;case S:t=O}return t}},V={};function I(e,i){const{editBox:o}=e,s=o.enterPoint;if(!s||!e.editing||!o.visible)return;if("circle"===s.name)return;if("button"===s.pointType)return void(s.cursor||(s.cursor="pointer"));let{rotation:n}=o;const{resizeCursor:r,rotateCursor:a,skewCursor:h,resizeable:l,rotateable:d,skewable:c}=e.mergeConfig,{pointType:g}=s,{flippedX:u,flippedY:f}=o;let p=g.includes("resize");p&&d&&(i.metaKey||i.ctrlKey||!l)&&(p=!1);const E=c&&!p&&("resize-line"===s.name||"skew"===g)?h:p?r:a;n+=45*(H.getFlipDirection(s.direction,u,f)+1),n=2*Math.round(t.MathHelper.formatRotation(n,!0)/2);const{url:m,x:v,y:b}=E,w=m+n;V[w]?s.cursor=V[w]:V[w]=s.cursor={url:A(m,n),x:v,y:b}}function D(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.editBox.rect.cursor=i?e:void 0}function A(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class z extends t.Box{}const F=["top","right","bottom","left"],Z=void 0;class G extends t.Group{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(e){super(),this.view=new t.Group,this.rect=new t.Box({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new z({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new t.Group({around:"center",hitSelf:!1,visible:0}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.dragStartData={},this.__eventIds=[],this.editor=e,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:o,resizePoints:s,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 o=0;o<8;o++)t=new z({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new z({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",o)),i=new z({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);this.listenPointEvents(h,"rotate",2),o.addMany(...n,a,h,l,...r,...s),this.add(o)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:o,circle:s,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);s.set(this.getPointStyle(t.circle||t.rotatePoint||h[0])),o.set(Object.assign({stroke:r,strokeWidth:a,editConfig:Z},t.rect||{})),o.hittable=!i,o.syncEventer=i&&this.editor,i&&(e.syncEventer=o,this.app.interaction.bottomList=[{target:o,proxy:e}])}update(e){const{rect:i,circle:o,buttons:s,resizePoints:n,rotatePoints:r,resizeLines:a,editor:h}=this,{mergeConfig:l,element:d,multiple:c,editMask:g}=h,{middlePoint:u,resizeable:f,rotateable:p,hideOnSmall:E,editBox:m,mask:v}=l;if(this.visible=!d.locked,g.visible=!!v||0,this.view.worldOpacity){const{width:h,height:d}=e,g="number"==typeof E?E:10,v=m&&!(E&&h<g&&d<g);let b,w,L,y={};for(let i=0;i<8;i++)t.AroundHelper.toPoint(t.AroundHelper.directionData[i],e,y),w=n[i],b=r[i],L=a[Math.floor(i/2)],w.set(y),b.set(y),L.set(y),w.visible=L.visible=v&&!(!f&&!p),b.visible=v&&p&&f&&!l.rotatePoint,i%2&&(w.visible=b.visible=v&&!!u,(i+1)/2%2?(L.width=h,E&&2*w.width>h&&(w.visible=!1)):(L.height=d,w.rotation=90,E&&2*w.width>d&&(w.visible=!1)));o.visible=v&&p&&!(!l.circle&&!l.rotatePoint),o.visible&&this.layoutCircle(l),i.path&&(i.path=null),i.set(Object.assign(Object.assign({},e),{visible:!!c||m})),s.visible=v&&s.children.length>0||0,s.visible&&this.layoutButtons(l)}else i.set(e)}layoutCircle(t){const{circleDirection:e,circleMargin:i,buttonsMargin:o,buttonsDirection:s,middlePoint:n}=t,r=F.indexOf(e||(this.buttons.children.length&&"bottom"===s?"top":"bottom"));this.setButtonPosition(this.circle,r,i||o,!!n)}layoutButtons(t){const{buttons:e}=this,{buttonsDirection:i,buttonsFixed:o,buttonsMargin:s,middlePoint:n}=t,{flippedX:r,flippedY:a}=this;let h=F.indexOf(i);(h%2&&r||(h+1)%2&&a)&&o&&(h=(h+2)%4);const l=o?H.getRotateDirection(h,this.flippedOne?this.rotation:-this.rotation,4):h;this.setButtonPosition(e,l,s,!!n),o&&(e.rotation=90*(l-h)),e.scaleX=r?-1:1,e.scaleY=a?-1:1}setButtonPosition(t,e,i,o){const s=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,a=(i+(e%2?(o?s.width:0)+t.boxBounds.width:(o?s.height:0)+t.boxBounds.height)/2)*r;n?(t.x=s.x+a,t.y=s.y):(t.x=s.x,t.y=s.y+a)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:o,pointSize:s,pointRadius:n}=this.editor.mergeConfig,r={fill:o,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:s,height:s,cornerRadius:n,offsetX:0,offsetY:0,editConfig:Z};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(e){this.dragging=!0;const i=this.dragPoint=e.current,{pointType:o}=i,{editor:s,dragStartData:n}=this,{element:r}=s;"rect"===i.name&&(this.moving=!0,s.opacity=s.mergeConfig.hideOnMove?0:1),n.x=e.x,n.y=e.y,n.point={x:r.x,y:r.y},n.bounds=Object.assign({},r.getLayoutBounds("box","local")),n.rotation=r.rotation,o&&o.includes("resize")&&(t.ResizeEvent.resizingKeys=s.leafList.keys)}onDragEnd(e){this.dragging=!1,this.dragPoint=null,this.moving=!1;const{name:i,pointType:o}=e.current;"rect"===i&&(this.editor.opacity=1),o&&o.includes("resize")&&(t.ResizeEvent.resizingKeys=null)}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),"resize-rotate"===i&&e.onScale(t)):"resize"===i&&e.onScale(t),"skew"===i&&e.onSkew(t),I(e,t)}onArrow(t){const{editor:e}=this;if(e.editing&&e.mergeConfig.keyEvent){let i=0,o=0;const s=t.shiftKey?10:1;switch(t.code){case"ArrowDown":o=s;break;case"ArrowUp":o=-s;break;case"ArrowLeft":i=-s;break;case"ArrowRight":i=s}(i||o)&&e.move(i,o)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(e){const{editor:i}=this;if(i.single){const{element:o}=i;if(o.locked)return;if(o.isBranch&&!o.editInner){if(o.textBox){const{children:e}=o,s=e.find((e=>e.editable&&e instanceof t.Text))||e.find((e=>e instanceof t.Text));if(s)return i.openInnerEditor(s)}i.openGroup(o),i.target=i.selector.findDeepOne(e)}else i.openInnerEditor()}}listenPointEvents(t,i,o){const{editor:s}=this;t.direction=o,t.pointType=i,t.on_(e.DragEvent.START,this.onDragStart,this),t.on_(e.DragEvent.DRAG,this.onDrag,this),t.on_(e.DragEvent.END,this.onDragEnd,this),t.on_(e.PointerEvent.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(e.PointerEvent.ENTER,(e=>{this.enterPoint=t,I(s,e)}))}__listenEvents(){const{rect:t,editor:i}=this;this.__eventIds=[i.on_(s.SELECT,this.onSelect,this),t.on_(e.DragEvent.START,this.onDragStart,this),t.on_(e.DragEvent.DRAG,i.onMove,i),t.on_(e.DragEvent.END,this.onDragEnd,this),t.on_(e.PointerEvent.ENTER,(()=>D(i))),t.on_(e.PointerEvent.DOUBLE_TAP,this.onDoubleTap,this),t.on_(e.PointerEvent.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const W={x:0,y:0,width:1e5,height:1e5};class X extends t.UI{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,W),Object.assign(this.__world,W)}__draw(t,e){const{editor:i}=this,{mask:o}=i.mergedConfig;if(o&&i.editing){if(t.fillWorld(t.bounds,!0===o?"rgba(0,0,0,0.8)":o),e.bounds&&!e.bounds.hit(i.editBox.rect.__world,e.matrix))return;t.saveBlendMode("destination-out"),i.list.forEach((i=>{i.__renderShape(t,e);const{__box:o,parent:s}=i;((i=o)||(i=s)&&s.textBox)&&i.__renderShape(t,e)})),t.restoreBlendMode()}}destroy(){this.editor=null,super.destroy()}}const Y='\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"/>',U={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${Y}\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${Y}\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${Y}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,editBox:!0,hover:!0,select:"press",openInner:"double",multipleSelect:!0,boxSelect:!0,moveable:!0,resizeable:!0,flipable:!0,rotateable:!0,skewable:!0},K=new t.Bounds;function j(t){const{simulateTarget:e,list:i}=t,{zoomLayer:o}=i[0].leafer.zoomLayer;e.safeChange((()=>{K.setListWithFn(i,(t=>t.getBounds("box","page"))),0===K.width&&(K.width=.1),0===K.height&&(K.height=.1),e.reset(K.get())})),o.add(e)}const N=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),q=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),$={group(e,i,o){e.sort(q);const{app:s,parent:n}=e[0];let r;r=o&&o.add?o:new t.Group(o),n.addAt(r,n.children.indexOf(e[0])),e.sort(N);const a=new t.Matrix(i.worldTransform);return a.divideParent(n.worldTransform),r.setTransform(a),r.editable=!0,r.hitChildren=!1,s.lockLayout(),e.forEach((t=>t.dropTo(r))),s.unlockLayout(),r},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:o}=t;for(;o.length;)i.push(o[0]),o[0].dropTo(e,e.children.indexOf(t));t.isBranchLeaf?i.push(t):t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(N),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(q),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},J=t.Debug.get("EditToolCreator");function Q(){return t=>{et.register(t)}}const tt=Q,et={list:{},register(t){const{tag:e}=t.prototype;it[e]&&J.repeat(e),it[e]=t},get:(t,e)=>new it[t](e)},{list:it}=et;class ot extends s{constructor(t,e){super(t,e)}}ot.BEFORE_OPEN="innerEditor.before_open",ot.OPEN="innerEditor.open",ot.BEFORE_CLOSE="innerEditor.before_close",ot.CLOSE="innerEditor.close";class st extends s{constructor(t,e){super(t,e)}}st.BEFORE_GROUP="editor.before_group",st.GROUP="editor.group",st.BEFORE_UNGROUP="editor.before_ungroup",st.UNGROUP="editor.ungroup",st.BEFORE_OPEN="editor.before_open_group",st.OPEN="editor.open_group",st.BEFORE_CLOSE="editor.before_close_group",st.CLOSE="editor.close_group";const{updateMatrix:nt}=t.LeafHelper,rt={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},at="top-left";class ht extends t.Rect{get __tag(){return"SimulateElement"}constructor(e){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.on(t.PropertyEvent.CHANGE,(i=>{if(this.checkChange&&rt[i.attrName]){const{attrName:o,newValue:s,oldValue:n}=i,r="s"===o[0]?(s||1)/(n||1):(s||0)-(n||0);this.canChange=!1;const a=this.__;a[o]=n,nt(this.parent),nt(this);const h=new t.Matrix(this.__world);switch(a[o]=s,this.__layout.rotationChange(),nt(this),this.changedTransform=new t.Matrix(this.__world).divide(h),o){case"x":e.move(r,0);break;case"y":e.move(0,r);break;case"rotation":e.rotateOf(at,r);break;case"scaleX":e.scaleOf(at,r,1);break;case"scaleY":e.scaleOf(at,1,r);break;case"skewX":e.skewOf(at,r,0);break;case"skewY":e.skewOf(at,0,r)}this.canChange=!0}}))}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class lt extends t.Group{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(i,o){super(o),this.leafList=new t.LeafList,this.openedGroupList=new t.LeafList,this.simulateTarget=new ht(this),this.editBox=new G(this),this.editToolList={},this.selector=new x(this),this.editMask=new X(this),this.targetEventIds=[];let s=t.DataHelper.clone(U);i&&(s=t.DataHelper.default(i,s)),this.mergedConfig=this.config=s,this.addMany(this.editMask,this.selector,this.editBox),e.Plugin.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&&j(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]||et.get(t,this),this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){if(t instanceof e.MoveEvent){if("drag"!==t.moveType){const{moveable:e,resizeable:i}=this.mergeConfig,o=t.getLocalMove(this.element);"move"===e?(t.stop(),this.move(o.x,o.y)):"zoom"===i&&t.stop()}}else{const i={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(i.x)>Math.abs(i.y)?i.y=0:i.x=0),this.move(e.DragEvent.getValidMove(this.element,this.editBox.dragStartData.point,i))}}onScale(t){const{element:i}=this;let{around:o,lockRatio:s,resizeable:n,flipable:r,editSize:a}=this.mergeConfig;if(t instanceof e.ZoomEvent)"zoom"===n&&(t.stop(),this.scaleOf(i.getBoxPoint(t),t.scale,t.scale));else{const{direction:e}=t.current;(t.shiftKey||i.lockRatio)&&(s=!0);const n=H.getScaleData(i,this.editBox.dragStartData.bounds,e,t.getInnerTotal(i),s,H.getAround(o,t.altKey),r,this.multiple||"scale"===a);this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}}onRotate(i){const{skewable:o,rotateable:s,around:n,rotateGap:r}=this.mergeConfig,{direction:a,name:h}=i.current;if(o&&"resize-line"===h)return this.onSkew(i);const{element:l}=this,{dragStartData:d}=this.editBox;let c,g;if(i instanceof e.RotateEvent){if("rotate"!==s)return;i.stop(),g=i.rotation,c=l.getBoxPoint(i),l.scaleX*l.scaleY<0&&(g=-g)}else{const t=H.getRotateData(l.boxBounds,a,i.getBoxPoint(l),l.getBoxPoint(d),i.shiftKey?null:l.around||l.origin||n||"center");g=t.rotation,c=t.origin}l.scaleX*l.scaleY<0&&(g=-g),i instanceof e.DragEvent&&(g=d.rotation+g-l.rotation),g=t.MathHelper.float(t.MathHelper.getGapRotation(g,r,l.rotation),2),g&&this.rotateOf(c,g)}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:o,skewX:s,skewY:n}=H.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),H.getAround(i,t.altKey));(s||n)&&this.skewOf(o,s,n)}move(t,e=0){if(!this.checkTransform("moveable"))return;"object"==typeof t&&(e=t.y,t=t.x);const{element:i}=this,{beforeMove:o}=this.mergeConfig;if(o){const s=o({target:i,x:t,y:e});if("object"==typeof s)t=s.x,e=s.y;else if(!1===s)return}const s=i.getWorldPointByLocal({x:t,y:e},null,!0);this.multiple&&i.safeChange((()=>i.move(t,e)));const r={target:i,editor:this,moveX:s.x,moveY:s.y};this.emitEvent(new n(n.BEFORE_MOVE,r));const a=new n(n.MOVE,r);this.editTool.onMove(a),this.emitEvent(a)}scaleWithDrag(t){if(!this.checkTransform("resizeable"))return;const{element:e}=this,{beforeScale:i}=this.mergeConfig;if(i){const{origin:o,scaleX:s,scaleY:n,drag:r}=t;if(!1===i({target:e,drag:r,origin:o,scaleX:s,scaleY:n}))return}t=Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:e.getWorldPoint(t.origin)}),this.emitEvent(new r(r.BEFORE_SCALE,t));const o=new r(r.SCALE,t);this.editTool.onScaleWithDrag(o),this.emitEvent(o)}scaleOf(t,e,i=e,o){if(!this.checkTransform("resizeable"))return;const{element:s}=this,{beforeScale:n}=this.mergeConfig;if(n){const o=n({target:s,origin:t,scaleX:e,scaleY:i});if("object"==typeof o)e=o.scaleX,i=o.scaleY;else if(!1===o)return}const a=this.getWorldOrigin(t),h=this.multiple&&this.getChangedTransform((()=>s.safeChange((()=>s.scaleOf(t,e,i))))),l={target:s,editor:this,worldOrigin:a,scaleX:e,scaleY:i,transform:h};this.emitEvent(new r(r.BEFORE_SCALE,l));const d=new r(r.SCALE,l);this.editTool.onScale(d),this.emitEvent(d)}flip(e){if(!this.checkTransform("resizeable"))return;const{element:i}=this,o=this.getWorldOrigin("center"),s=this.multiple?this.getChangedTransform((()=>i.safeChange((()=>i.flip(e))))):new t.Matrix(t.LeafHelper.getFlipTransform(i,e)),n={target:i,editor:this,worldOrigin:o,scaleX:"x"===e?-1:1,scaleY:"y"===e?-1:1,transform:s};this.emitEvent(new r(r.BEFORE_SCALE,n));const a=new r(r.SCALE,n);this.editTool.onScale(a),this.emitEvent(a)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{element:i}=this,{beforeRotate:o}=this.mergeConfig;if(o){const s=o({target:i,origin:t,rotation:e});if("number"==typeof s)e=s;else if(!1===s)return}const s=this.getWorldOrigin(t),n=this.multiple&&this.getChangedTransform((()=>i.safeChange((()=>i.rotateOf(t,e))))),r={target:i,editor:this,worldOrigin:s,rotation:e,transform:n};this.emitEvent(new a(a.BEFORE_ROTATE,r));const h=new a(a.ROTATE,r);this.editTool.onRotate(h),this.emitEvent(h)}skewOf(t,e,i=0,o){if(!this.checkTransform("skewable"))return;const{element:s}=this,{beforeSkew:n}=this.mergeConfig;if(n){const o=n({target:s,origin:t,skewX:e,skewY:i});if("object"==typeof o)e=o.skewX,i=o.skewY;else if(!1===o)return}const r=this.getWorldOrigin(t),a=this.multiple&&this.getChangedTransform((()=>s.safeChange((()=>s.skewOf(t,e,i))))),l={target:s,editor:this,worldOrigin:r,skewX:e,skewY:i,transform:a};this.emitEvent(new h(h.BEFORE_SKEW,l));const d=new h(h.SKEW,l);this.editTool.onSkew(d),this.emitEvent(d)}checkTransform(t){return this.element&&!this.element.locked&&this.mergeConfig[t]}getWorldOrigin(e){return this.element.getWorldPoint(t.LeafHelper.getInnerOrigin(this.element,e))}getChangedTransform(e){const{element:i}=this;if(this.multiple&&!i.canChange)return i.changedTransform;const o=new t.Matrix(i.worldTransform);return e(),new t.Matrix(i.worldTransform).divide(o)}group(t){return this.multiple&&(this.emitGroupEvent(st.BEFORE_GROUP),this.target=$.group(this.list,this.element,t),this.emitGroupEvent(st.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(st.BEFORE_UNGROUP,t))),this.target=$.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(st.UNGROUP,t)))),this.list}openGroup(t){this.emitGroupEvent(st.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(st.OPEN,t)}closeGroup(t){this.emitGroupEvent(st.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(st.CLOSE,t)}checkOpenedGroups(){const e=this.openedGroupList;if(e.length){let{list:i}=e;this.editing&&(i=[],e.forEach((e=>this.list.every((i=>!t.LeafHelper.hasParent(i,e)))&&i.push(e)))),i.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 st(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&&et.list[i]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[i]||et.get(i,this),this.innerEditor.editTarget=e,this.emitInnerEvent(ot.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(ot.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(ot.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(ot.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,o=new ot(t,{editTarget:i,innerEditor:e});this.emitEvent(o),i.emitEvent(o)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&($.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&($.toBottom(this.list),this.leafList.update())}onAppRenderStart(t){(this.targetChanged=t.children.some((t=>t!==this.leafer&&t.renderer.changed)))&&this.editBox.forceRender()}onRenderStart(){this.targetChanged&&this.update()}onKey(t){I(this,t)}listenTargetEvents(){if(!this.targetEventIds.length){const{app:i,leafer:o,editBox:s,editMask:n}=this;this.targetEventIds=[o.on_(t.RenderEvent.START,this.onRenderStart,this),i.on_(t.RenderEvent.CHILD_START,this.onAppRenderStart,this),i.on_(e.MoveEvent.BEFORE_MOVE,this.onMove,this,!0),i.on_(e.ZoomEvent.BEFORE_ZOOM,this.onScale,this,!0),i.on_(e.RotateEvent.BEFORE_ROTATE,this.onRotate,this,!0),i.on_([e.KeyEvent.HOLD,e.KeyEvent.UP],this.onKey,this),i.on_(e.KeyEvent.DOWN,s.onArrow,s)],n.visible&&n.forceRender()}}removeTargetEvents(){const{targetEventIds:t,editMask:e}=this;t.length&&(this.off_(t),t.length=0,e.visible&&e.forceRender())}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())}}i([(e,i)=>{t.defineKey(e,i,{get(){const{config:e,element:i,dragPoint:o}=this,s=Object.assign({},e);return i&&i.editConfig&&Object.assign(s,i.editConfig),o&&(o.editConfig&&Object.assign(s,o.editConfig),"font-size"===s.editSize&&(s.lockRatio=!0),"resize-rotate"===o.pointType&&(s.around||(s.around="center"),t.isNull(s.lockRatio)&&(s.lockRatio=!0))),this.mergedConfig=s}})}],lt.prototype,"mergeConfig",void 0),i([l((function(t,e){t.emitEvent(new s(s.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],lt.prototype,"hoverTarget",void 0),i([l((function(e,i){const{target:o}=e;o?(e.leafList=o instanceof t.LeafList?o:new t.LeafList(o),e.multiple&&j(e)):(e.simulateTarget.remove(),e.leafList.reset(),e.closeInnerEditor()),e.emitEvent(new s(s.SELECT,{editor:e,value:o,oldValue:i})),e.checkOpenedGroups(),e.editing?e.waitLeafer((()=>{D(e),e.updateEditTool(),e.update(),e.listenTargetEvents()})):(e.updateEditTool(),e.removeTargetEvents())}))],lt.prototype,"target",void 0);class dt{static registerInnerEditor(){et.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new t.Group,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)}}exports.EditTool=class extends dt{static registerEditTool(){et.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:o}=t,{app:s,list:n}=o;s.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),s.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:o,worldOrigin:s,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);o?t.transformWorld(o,r):t.scaleOfWorld(s,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:o,editor:s}=t,{app:n,list:r}=s;n.lockLayout(),r.forEach((t=>{const n="scale"!==s.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(o,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:o,worldOrigin:s,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);o?t.transformWorld(o,r):t.skewOfWorld(s,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{x:i,y:o,scaleX:s,scaleY:n,rotation:r,skewX:a,skewY:h,width:l,height:d}=t.element.getLayoutBounds("box",t,!0);e.set({x:i,y:o,scaleX:s,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()}},exports.EditTool=i([Q()],exports.EditTool);const{left:ct,right:gt}=t.Direction9,{move:ut,copy:ft,toNumberPoints:pt}=t.PointHelper;exports.LineEditTool=class extends exports.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(e){const{drag:i,direction:o,lockRatio:s,around:n}=e,r=e.target,a=o===ct;if(r.pathInputed){const{path:t}=r.__,{from:e,to:o}=this.getFromToByPath(t);this.dragPoint(e,o,a,n,this.getInnerMove(r,i,s)),t[1]=e.x,t[2]=e.y,t[4]=o.x,t[5]=o.y,r.path=t}else if(r.points){const{points:t}=r,{from:e,to:o}=this.getFromToByPoints(t);this.dragPoint(e,o,a,n,this.getInnerMove(r,i,s)),t[0]=e.x,t[1]=e.y,t[2]=o.x,t[3]=o.y,r.points=t}else{const e=t.getPointData(),{toPoint:o}=r;r.rotation=0,this.dragPoint(e,o,a,n,this.getInnerMove(r,i,s)),r.getLocalPointByInner(e,null,null,!0),r.getLocalPointByInner(o,null,null,!0),r.x=e.x,r.y=e.y,r.getInnerPointByLocal(o,null,null,!0),r.toPoint=o}}getInnerMove(t,e,i){const o=e.getInnerMove(t);return i&&(Math.abs(o.x)>Math.abs(o.y)?o.y=0:o.x=0),o}getFromToByPath(t){return{from:{x:t[1],y:t[2]},to:{x:t[4],y:t[5]}}}getFromToByPoints(t){const e=pt(t);return{from:{x:e[0],y:e[1]},to:{x:e[2],y:e[3]}}}dragPoint(t,e,i,o,s){const{x:n,y:r}=s;i?(ut(t,n,r),o&&ut(e,-n,-r)):(o&&ut(t,-n,-r),ut(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:o,rect:s}=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),s.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),ft(o[7],i),ft(e[7],i),ft(o[3],a),ft(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===ct||t===gt,o[t].visible=a,e[t].visible=!r&&a}},exports.LineEditTool=i([Q()],exports.LineEditTool),t.Plugin.add("editor","resize"),t.Creator.editor=function(t){return new lt(t)},t.Box.addAttr("textBox",!1,t.dataType),t.UI.addAttr("editConfig",void 0,t.dataType),t.UI.addAttr("editOuter",(t=>t.__.__isLinePath?"LineEditTool":"EditTool"),t.dataType),t.UI.addAttr("editInner","PathEditor",t.dataType),t.Group.addAttr("editInner","",t.dataType),t.Text.addAttr("editInner","TextEditor",t.dataType),t.UI.setEditConfig=function(t){this.changeAttr("editConfig",t)},t.UI.setEditOuter=function(t){this.changeAttr("editOuter",t)},t.UI.setEditInner=function(t){this.changeAttr("editInner",t)},exports.EditBox=G,exports.EditDataHelper=H,exports.EditPoint=z,exports.EditSelect=x,exports.EditSelectHelper=b,exports.EditToolCreator=et,exports.Editor=lt,exports.EditorEvent=s,exports.EditorGroupEvent=st,exports.EditorHelper=$,exports.EditorMoveEvent=n,exports.EditorRotateEvent=a,exports.EditorScaleEvent=r,exports.EditorSkewEvent=h,exports.InnerEditor=dt,exports.InnerEditorEvent=ot,exports.SelectArea=v,exports.Stroker=m,exports.registerEditTool=Q,exports.registerInnerEditor=tt;
//# sourceMappingURL=editor.min.cjs.map