@leafer-in/editor 1.0.0-rc.23 → 1.0.0-rc.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer-ui/draw"),e=require("@leafer-ui/core");const{M:i,L:s,C:o,Q:n,Z:r,N:a,D:l,X:h,G:d,F:c,O:g,P:u,U:p}=t.PathCommandMap,f={scale(t,e,f){if(!t)return;let m,L=0,y=t.length;for(;L<y;)switch(m=t[L],m){case i:case s:v(t,e,f,L,1),L+=3;break;case o:v(t,e,f,L,3),L+=7;break;case n:v(t,e,f,L,2),L+=5;break;case r:L+=1;break;case a:v(t,e,f,L,2),L+=5;break;case l:v(t,e,f,L,2),L+=9;break;case h:v(t,e,f,L,2),L+=6;break;case d:v(t,e,f,L,2),L+=9;break;case c:v(t,e,f,L,2),L+=5;break;case g:t[L]=d,t.splice(L+4,0,t[L+3],0),v(t,e,f,L,2),L+=9,y+=2;break;case u:t[L]=c,t.splice(L+4,0,t[L+3]),v(t,e,f,L,2),L+=5,y+=1;break;case p:v(t,e,f,L,2),L+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:v}=f;function m(t,e,i){1!==e&&(t.width*=e),1!==i&&(t.height*=i)}t.Leaf.prototype.scaleResize=function(t,e=t,i){const s=this;i?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},t.Leaf.prototype.__scaleResize=function(t,e){m(this,t,e)},t.Path.prototype.__scaleResize=function(t,e){f.scale(this.__.path,t,e),this.path=this.__.path},t.Line.prototype.__scaleResize=function(t,e){if(this.points)f.scalePoints(this.__.points,t,e),this.points=this.__.points;else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},t.Polygon.prototype.__scaleResize=function(t,e){this.points?(f.scalePoints(this.__.points,t,e),this.points=this.__.points):m(this,t,e)};const L=t.MatrixHelper.get();function y(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)L.a=e,L.d=i,s[t].transform(L,!0)}function E(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 w(t){return t?t instanceof Array?t:[t]:[]}t.Group.prototype.__scaleResize=function(t,e){y(this,t,e)},t.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?y(this,t,e):m(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class b extends t.Event{get list(){return w(this.value)}get oldList(){return w(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}b.SELECT="editor.select",b.HOVER="editor.hover";class x extends b{constructor(t,e){super(t,e)}}x.MOVE="editor.move";class _ extends b{constructor(t,e){super(t,e)}}_.SCALE="editor.scale";class k extends b{constructor(t,e){super(t,e)}}k.ROTATE="editor.rotate";class M extends b{constructor(t,e){super(t,e)}}function S(e){return(i,s)=>{const o="_"+s;t.defineKey(i,s,{get(){return this[o]},set(t){const i=this[o];i!==t&&(this[o]=t,e(this,i))}})}}M.SKEW="editor.skew";const T=t.MatrixHelper.get(),{abs:H}=Math,{copy:P,scale:V}=t.MatrixHelper;class O extends t.UI{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(e,i){const{list:s}=this;if(s.length){let o;const{stroke:n,strokeWidth:r,fill:a}=this.__,{bounds:l}=i;for(let h=0;h<s.length;h++)if(o=s[h],l&&l.hit(o.__world,i.matrix)){const s=H(o.__world.scaleX),l=H(o.__world.scaleY);if(s!==l){P(T,o.__world),V(T,1/s,1/l),e.setWorld(T,i.matrix),e.beginPath(),this.__.strokeWidth=r;const{x:t,y:n,width:a,height:h}=o.__layout.boxBounds;e.rect(t*s,n*l,a*s,h*l)}else e.setWorld(o.__world,i.matrix),e.beginPath(),o.__.__useArrow?o.__drawPath(e):o.__.__pathForRender?o.__drawRenderPath(e):o.__drawPathByBox(e),this.__.strokeWidth=r/H(o.__world.scaleX);n&&("string"==typeof n?t.Paint.stroke(n,this,e):t.Paint.strokes(n,this,e)),a&&("string"==typeof a?t.Paint.fill(a,this,e):t.Paint.fills(a,this,e))}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}E([S((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],O.prototype,"target",void 0);class D extends t.Group{constructor(e){super(e),this.strokeArea=new t.Rect({strokeAlign:"center"}),this.fillArea=new t.Rect,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:I,Yes:C,NoAndSkip:R,YesAndSkip:A}=t.Answer,B={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?A:R;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?A:I;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return C}return I}return t.isBranch?R:I}},{findOne:Z}=B;class z 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 O,this.targetStroker=new O,this.bounds=new t.Bounds,this.selectArea=new D,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:s,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.mergeConfig;"press"===e&&this.checkAndSelect(t)}onTap(t){const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i&&this.checkAndSelect(t),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(this.allowDrag(t)){const{editor:e}=this,{stroke:i,area:s}=e.mergeConfig,{x:o,y:n}=t.getInner(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(e){if(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:i}=this,s=e.getInnerTotal(this),o=this.bounds.clone().unsign(),n=new t.LeafList(i.app.find(B.findBounds,o));if(this.bounds.width=s.x,this.bounds.height=s.y,this.selectArea.setBounds(o.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(){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&&!Z(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(e){const i={exclude:new t.LeafList(this.editor.editBox.rect)};return Z(e.target.leafer.interaction.findPath(e,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):Z(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:i}=t;i.selector.proxy=t,this.__eventIds=[t.on_(b.HOVER,this.onHover,this),t.on_(b.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),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:W,top:G,topRight:X,right:Y,bottomRight:U,bottom:K,bottomLeft:F,left:j}=t.Direction9,{toPoint:N}=t.AroundHelper,q={getScaleData(t,e,i,s,o){let n,r={},a=1,l=1;const{width:h,height:d}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===h&&(i.x+=.1),Math.abs(i.y)===d&&(i.y+=.1);const c=(-i.y+d)/d,g=(i.x+h)/h,u=(i.y+d)/d,p=(-i.x+h)/h;switch(e){case G:l=c,n="bottom";break;case Y:a=g,n="left";break;case K:l=u,n="top";break;case j:a=p,n="right";break;case W:l=c,a=p,n="bottom-right";break;case X:l=c,a=g,n="bottom-left";break;case U:l=u,a=g,n="top-left";break;case F:l=u,a=p,n="top-right"}if(s){if(!("corner"===s&&e%2)){const t=Math.sqrt(Math.abs(a*l));a=a<0?-t:t,l=l<0?-t:t}}return N(o||n,t,r),{origin:r,scaleX:a,scaleY:l,direction:e,lockRatio:s,around:o}},getRotateData(e,i,s,o,n){let r,a={};switch(i){case W:r="bottom-right";break;case X:r="bottom-left";break;case U:r="top-left";break;case F:r="top-right";break;default:r="center"}return N(n||r,e,a),{origin:a,rotation:t.PointHelper.getRotation(o,a,s)}},getSkewData(e,i,s,o){let n,r,a={},l=0,h=0;switch(i){case G:r={x:.5,y:0},n="bottom",l=1;break;case K:r={x:.5,y:1},n="top",l=1;break;case j:r={x:0,y:.5},n="right",h=1;break;case Y:r={x:1,y:.5},n="left",h=1}const{x:d,y:c,width:g,height:u}=e;r.x=d+r.x*g,r.y=c+r.y*u,N(o||n,e,a);const p=t.PointHelper.getRotation(r,a,{x:r.x+(l?s.x:0),y:r.y+(h?s.y:0)});return l?l=-p:h=p,{origin:a,skewX:l,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 j:t=Y;break;case W:t=X;break;case F:t=U;break;case Y:t=j;break;case X:t=W;break;case U:t=F}if(i)switch(t){case G:t=K;break;case W:t=F;break;case X:t=U;break;case K:t=G;break;case F:t=W;break;case U:t=X}return t}},$={};function Q(e,i){const{editBox:s}=e,o=s.enterPoint;if(!o||!e.editing||!s.visible)return;if("circle"===o.name)return;let{rotation:n}=s;const{resizeCursor:r,rotateCursor:a,skewCursor:l,resizeable:h,rotateable:d,skewable:c}=e.mergeConfig,{pointType:g}=o,{flippedX:u,flippedY:p}=s;let f="resize"===g;f&&d&&(i.metaKey||i.ctrlKey||!h)&&(f=!1);const v=c&&!f&&"resize-line"===o.name?l:f?r:a;n+=45*(q.getFlipDirection(o.direction,u,p)+1),n=2*Math.round(t.MathHelper.formatRotation(n,!0)/2);const{url:m,x:L,y:y}=v,E=m+n;$[E]?o.cursor=$[E]:$[E]=o.cursor={url:tt(m,n),x:L,y:y}}function J(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function tt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class et extends t.Box{}const it=["top","right","bottom","left"];class st 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 et({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new t.Group({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=e,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:l,buttons:h}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new et({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new et({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new et({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);h.add(l),this.listenPointEvents(l,"rotate",2),s.addMany(...n,a,h,...r,...o),this.add(s)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth:a,moveable:l}=t,h=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:h[t/2%h.length])),t%2||(c.rotation=t/2*90);o.set(this.getPointStyle(t.rotatePoint||h[0])),s.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),s.hittable=!i&&l,e.syncEventer=i&&l?s:null,this.app.interaction.bottomList=i&&l?[{target:s,proxy:e}]:null,this.visible=!e.locked}update(e){if(this.view.worldOpacity){const{mergeConfig:i}=this.editor,{width:s,height:o}=e,{rect:n,circle:r,resizePoints:a,rotatePoints:l,resizeLines:h}=this,{middlePoint:d,resizeable:c,rotateable:g,hideOnSmall:u}=i,p="number"==typeof u?u:10,f=!(u&&s<p&&o<p);let v,m,L,y={};for(let n=0;n<8;n++)t.AroundHelper.toPoint(t.AroundHelper.directionData[n],e,y),m=a[n],v=l[n],L=h[Math.floor(n/2)],m.set(y),v.set(y),L.set(y),m.visible=L.visible=f&&(c||g),v.visible=f&&g&&c&&!i.rotatePoint,n%2&&(m.visible=v.visible=f&&!!d,(n+1)/2%2?(L.width=s,m.width>s-30&&(m.visible=!1)):(L.height=o,m.rotation=90,m.width>o-30&&(m.visible=!1)));r.visible=f&&g&&!!i.rotatePoint,n.set(Object.assign(Object.assign({},e),{visible:!0}));const E=f&&(r.visible||this.buttons.children.length>1);this.buttons.visible=E,E&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.mergeConfig,{flippedX:r,flippedY:a}=this;let l=it.indexOf(i);(l%2&&r||(l+1)%2&&a)&&s&&(l=(l+2)%4);const h=s?q.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,d=e[2*h+1],c=h%2,g=h&&3!==h?1:-1,u=(o+(l%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),s&&(t.rotation=90*(h-l),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.mergeConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=this.app.interaction.bottomList=null)}onDragStart(t){if(this.dragging=!0,"rect"===t.current.name){const{editor:t}=this;this.moving=!0,t.dragStartPoint={x:t.element.x,y:t.element.y},t.opacity=t.mergeConfig.hideOnMove?0:1}}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):e.onScale(t),Q(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,i,s){const{editor:o}=this;t.direction=s,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,Q(o,e)}))}__listenEvents(){const{rect:t,editor:i}=this;this.__eventIds=[i.on_(b.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,(()=>J(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 ot='\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"/>',nt={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${ot}\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${ot}\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${ot}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};const rt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),at=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),lt={group(e,i,s){e.sort(at);const{app:o,parent:n}=e[0];let r;r=s&&s.add?s:new t.Group(s),n.addAt(r,n.children.indexOf(e[0])),e.sort(rt);const a=new t.Matrix(i.worldTransform);return a.divideParent(n.worldTransform),r.setTransform(a),r.editable=!0,r.hitChildren=!1,o.lockLayout(),e.forEach((t=>t.dropTo(r))),o.unlockLayout(),r},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(rt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(at),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},ht=t.Debug.get("EditToolCreator");function dt(){return t=>{gt.register(t)}}const ct=dt,gt={list:{},register(t){const{tag:e}=t.prototype;ut[e]?ht.repeat(e):ut[e]=t},get:(t,e)=>new ut[t](e)},{list:ut}=gt;class pt extends t.Group{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(e,i){super(i),this.config=nt,this.mergeConfig=nt,this.leafList=new t.LeafList,this.openedGroupList=new t.LeafList,this.simulateTarget=new t.Rect({visible:!1}),this.editBox=new st(this),this.editToolList={},this.selector=new z(this),this.targetEventIds=[],e&&(this.config=t.DataHelper.default(e,this.config)),this.addMany(this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||gt.get(t,this);const{editConfig:e}=this.element;this.mergeConfig=this.single&&e?Object.assign(Object.assign({},this.mergeConfig),e):this.config,this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){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.dragStartPoint,i))}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.mergeConfig;t.shiftKey&&(o=!0);const n=q.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,q.getAround(s,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}onRotate(i){const{skewable:s,around:o,rotateGap:n}=this.mergeConfig,{direction:r,name:a}=i.current;if(s&&"resize-line"===a)return this.onSkew(i);const{element:l}=this;let h,d;if(i instanceof e.RotateEvent)d=i.rotation,h=l.getInnerPoint(i);else{const t={x:i.x-i.moveX,y:i.y-i.moveY},e=q.getRotateData(l.boxBounds,r,i.getInner(l),l.getInnerPoint(t),i.shiftKey?null:o||"center");d=e.rotation,h=e.origin}d=t.MathHelper.getGapRotation(d,n,l.rotation),d&&(l.scaleX*l.scaleY<0&&(d=-d),this.rotateOf(h,t.MathHelper.float(d,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=q.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),q.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e=0){if(!this.mergeConfig.moveable||this.element.locked)return;const{element:i}=this,s=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),o=new x(x.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o),this.multiple&&i.move(t,e)}scaleWithDrag(t){const{element:e}=this,i=e.getWorldPoint(t.origin),s=new _(_.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(s),this.emitEvent(s)}scaleOf(e,i,s=i,o){const{element:n}=this,r=n.getWorldPoint(e);let a;if(this.multiple){const o=new t.Matrix(n.worldTransform);n.scaleOf(e,i,s),a=new t.Matrix(n.worldTransform).divide(o)}const l=new _(_.SCALE,{target:n,editor:this,worldOrigin:r,scaleX:i,scaleY:s,transform:a});this.editTool.onScale(l),this.emitEvent(l)}rotateOf(e,i){const{element:s}=this,o=s.getWorldPoint(e);let n;if(this.multiple){const o=new t.Matrix(s.worldTransform);s.rotateOf(e,i),n=new t.Matrix(s.worldTransform).divide(o)}const r=new k(k.ROTATE,{target:s,editor:this,worldOrigin:o,rotation:i,transform:n});this.editTool.onRotate(r),this.emitEvent(r)}skewOf(e,i,s=0,o){const{element:n}=this,r=n.getWorldPoint(e);let a;if(this.multiple){const o=new t.Matrix(n.worldTransform);n.skewOf(e,i,s),a=new t.Matrix(n.worldTransform).divide(o)}const l=new M(M.SKEW,{target:n,editor:this,skewX:i,skewY:s,transform:a,worldOrigin:r});this.editTool.onSkew(l),this.emitEvent(l)}group(t){return this.multiple&&(this.target=lt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=lt.ungroup(this.list)),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1}checkOpenedGroups(){const 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)))}}openInnerEditor(){if(this.single){const t=this.element.editInner;t&&gt.list[t]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[t]||gt.get(t,this),this.innerEditor.load())}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.innerEditor.unload(),this.editTool.load(),this.innerEditor=null)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(lt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(lt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:i}=this.list[0];this.targetEventIds=[i.on_(t.RenderEvent.START,this.update,this),i.on_([e.KeyEvent.HOLD,e.KeyEvent.UP],(t=>{Q(this,t)})),i.on_(e.KeyEvent.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}E([S((function(t,e){t.emitEvent(new b(b.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],pt.prototype,"hoverTarget",void 0),E([S((function(e,i){const{target:s}=e;s?e.leafList=s instanceof t.LeafList?s:new t.LeafList(s):e.leafList.reset(),e.emitEvent(new b(b.SELECT,{editor:e,value:s,oldValue:i})),e.checkOpenedGroups(),e.editing?e.waitLeafer((()=>{e.multiple&&function(e){const{simulateTarget:i,leafList:s}=e,{x:o,y:n,width:r,height:a}=(new t.Bounds).setListWithFn(s.list,(t=>t.worldBoxBounds)),l=i.parent=s.list[0].leafer.zoomLayer,{scaleX:h,scaleY:d,e:c,f:g}=l.__world;i.reset({x:(o-c)/h,y:(n-g)/d,width:r/h,height:a/d})}(e),J(e),e.updateEditTool(),e.update(),e.listenTargetEvents()})):(e.updateEditTool(),e.removeTargetEvents())}))],pt.prototype,"target",void 0);class ft{static registerInnerEditor(){gt.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(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}exports.EditTool=class extends ft{static registerEditTool(){gt.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="size"===o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{simulateTarget:i,element:s}=t;t.multiple&&i.parent.updateLayout();const{x:o,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d,width:c,height:g}=s.getLayoutBounds("box",t,!0);e.set({x:o,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}},exports.EditTool=E([dt()],exports.EditTool);const{left:vt,right:mt}=t.Direction9;exports.LineEditTool=class extends exports.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(e){const{drag:i,direction:s,lockRatio:o,around:n}=e,r=e.target,a=t.getPointData(),{toPoint:l}=r;r.rotation=0;let{x:h,y:d}=i.getInnerMove(r);o&&(Math.abs(h)>Math.abs(d)?d=0:h=0),s===vt?(a.x+=h,a.y+=d,n&&(l.x-=h,l.y-=d)):(n&&(a.x-=h,a.y-=d),l.x+=h,l.y+=d),r.getLocalPointByInner(a,null,null,!0),r.getLocalPointByInner(l,null,null,!0),r.x=a.x,r.y=a.y,r.getInnerPointByLocal(l,null,null,!0),r.toPoint=l}onSkew(t){}onUpdate(){const{rotatePoints:t,resizeLines:e,resizePoints:i}=this.editor.editBox;for(let s=0;s<8;s++)s<4&&(e[s].visible=!1),i[s].visible=t[s].visible=s===vt||s===mt}},exports.LineEditTool=E([dt()],exports.LineEditTool),t.Creator.editor=function(t){return new pt(t)},t.UI.setEditConfig=function(e){t.defineKey(this.prototype,"editConfig",{get(){return"function"==typeof e?e(this):e}})},t.UI.setEditOuter=function(e){t.defineKey(this.prototype,"editOuter",{get(){return"string"==typeof e?e:e(this)}})},t.UI.setEditInner=function(e){t.defineKey(this.prototype,"editInner",{get(){return"string"==typeof e?e:e(this)}})},t.Line.setEditOuter((function(t){return t.points||t.pathInputed?"EditTool":"LineEditTool"})),exports.EditBox=st,exports.EditDataHelper=q,exports.EditPoint=et,exports.EditSelect=z,exports.EditSelectHelper=B,exports.EditToolCreator=gt,exports.Editor=pt,exports.EditorEvent=b,exports.EditorHelper=lt,exports.EditorMoveEvent=x,exports.EditorRotateEvent=k,exports.EditorScaleEvent=_,exports.EditorSkewEvent=M,exports.InnerEditor=ft,exports.SelectArea=D,exports.Stroker=O,exports.registerEditTool=dt,exports.registerInnerEditor=ct;
1
+ "use strict";var t=require("@leafer-ui/draw"),e=require("@leafer-ui/core");const{M:i,L:o,C:s,Q:n,Z:r,N:a,D:l,X:h,G:d,F:c,O:g,P:u,U:p}=t.PathCommandMap,f={scale(t,e,f){if(!t)return;let m,y=0,L=t.length;for(;y<L;)switch(m=t[y],m){case i:case o:v(t,e,f,y,1),y+=3;break;case s:v(t,e,f,y,3),y+=7;break;case n:v(t,e,f,y,2),y+=5;break;case r:y+=1;break;case a:v(t,e,f,y,2),y+=5;break;case l:v(t,e,f,y,2),y+=9;break;case h:v(t,e,f,y,2),y+=6;break;case d:v(t,e,f,y,2),y+=9;break;case c:v(t,e,f,y,2),y+=5;break;case g:t[y]=d,t.splice(y+4,0,t[y+3],0),v(t,e,f,y,2),y+=9,L+=2;break;case u:t[y]=c,t.splice(y+4,0,t[y+3]),v(t,e,f,y,2),y+=5,L+=1;break;case p:v(t,e,f,y,2),y+=6}},scalePoints(t,e,i,o,s){for(let n=s?o+1:0,r=s?n+2*s:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:v}=f,m=t.MatrixHelper.get();function y(t,e,i){t.pathInputed?w(t,e,i):(t.width*=e,t.height*=i)}function L(t,e,i){1!==e?t.fontSize*=e:1!==i&&(t.fontSize*=i)}function w(t,e,i){f.scale(t.__.path,e,i),t.path=t.__.path}function b(t,e,i){f.scalePoints(t.__.points,e,i),t.points=t.__.points}function E(t,e,i){const{children:o}=t;for(let t=0;t<o.length;t++)m.a=e,m.d=i,o[t].transform(m,!0)}function x(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 _(t){return t?t instanceof Array?t:[t]:[]}t.Leaf.prototype.scaleResize=function(t,e=t,i){const o=this;i?(o.scaleX*=t,o.scaleY*=e):(t<0&&(o.scaleX*=-1,t=-t),e<0&&(o.scaleY*=-1,e=-e),this.__scaleResize(t,e))},t.Leaf.prototype.__scaleResize=function(t,e){y(this,t,e)},t.Text.prototype.__scaleResize=function(t,e){this.editConfig&&"font-size"===this.editConfig.editSize?L(this,t,e):y(this,t,e)},t.Path.prototype.__scaleResize=function(t,e){w(this,t,e)},t.Line.prototype.__scaleResize=function(t,e){if(this.pathInputed)w(this,t,e);else if(this.points)b(this,t,e);else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},t.Polygon.prototype.__scaleResize=function(t,e){this.pathInputed?w(this,t,e):this.points?b(this,t,e):y(this,t,e)},t.Group.prototype.__scaleResize=function(t,e){E(this,t,e)},t.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?E(this,t,e):y(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class k extends t.Event{get list(){return _(this.value)}get oldList(){return _(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}k.SELECT="editor.select",k.HOVER="editor.hover";class M extends k{constructor(t,e){super(t,e)}}M.MOVE="editor.move";class T extends k{constructor(t,e){super(t,e)}}T.SCALE="editor.scale";class S extends k{constructor(t,e){super(t,e)}}S.ROTATE="editor.rotate";class P extends k{constructor(t,e){super(t,e)}}function H(e){return(i,o)=>{const s="_"+o;t.defineKey(i,o,{get(){return this[s]},set(t){const i=this[s];i!==t&&(this[s]=t,e(this,i))}})}}P.SKEW="editor.skew";const V=t.MatrixHelper.get(),{abs:O}=Math,{copy:I,scale:D}=t.MatrixHelper;class R extends t.UI{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(e,i){const{list:o}=this;if(o.length){let s;const{stroke:n,strokeWidth:r,fill:a}=this.__,{bounds:l}=i;for(let h=0;h<o.length;h++)if(s=o[h],l&&l.hit(s.__world,i.matrix)){const o=O(s.__world.scaleX),l=O(s.__world.scaleY);if(o!==l){I(V,s.__world),D(V,1/o,1/l),e.setWorld(V,i.matrix),e.beginPath(),this.__.strokeWidth=r;const{x:t,y:n,width:a,height:h}=s.__layout.boxBounds;e.rect(t*o,n*l,a*o,h*l)}else e.setWorld(s.__world,i.matrix),e.beginPath(),s.__.__useArrow?s.__drawPath(e):s.__.__pathForRender?s.__drawRenderPath(e):s.__drawPathByBox(e),this.__.strokeWidth=r/O(s.__world.scaleX);n&&("string"==typeof n?t.Paint.stroke(n,this,e):t.Paint.strokes(n,this,e)),a&&("string"==typeof a?t.Paint.fill(a,this,e):t.Paint.fills(a,this,e))}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}x([H((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],R.prototype,"target",void 0);class C extends t.Group{constructor(e){super(e),this.strokeArea=new t.Rect({strokeAlign:"center"}),this.fillArea=new t.Rect,this.visible=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{No:B,Yes:A,NoAndSkip:Z,YesAndSkip:z}=t.Answer,W={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?z:Z;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?z:B;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return A}return B}return t.isBranch?Z:B}},{findOne:G}=W;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 R,this.targetStroker=new R,this.bounds=new t.Bounds,this.selectArea=new C,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}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,o/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.mergeConfig;"press"===e&&this.checkAndSelect(t)}onTap(t){const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i&&this.checkAndSelect(t),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(this.allowDrag(t)){const{editor:e}=this,{stroke:i,area:o}=e.mergeConfig,{x:s,y:n}=t.getInner(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(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:i}=this,o=e.getInnerTotal(this),s=this.bounds.clone().unsign(),n=new t.LeafList(i.app.find(W.findBounds,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(){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&&!G(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(e){const i={exclude:new t.LeafList(this.editor.editBox.rect)};return G(e.target.leafer.interaction.findPath(e,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):G(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:i}=t;i.selector.proxy=t,this.__eventIds=[t.on_(k.HOVER,this.onHover,this),t.on_(k.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),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:Y,top:F,topRight:U,right:K,bottomRight:j,bottom:N,bottomLeft:q,left:$}=t.Direction9,{toPoint:Q}=t.AroundHelper,J={getScaleData(t,e,i,o,s){let n,r={},a=1,l=1;const{width:h,height:d}=t;s&&(i.x*=2,i.y*=2),Math.abs(i.x)===h&&(i.x+=.1),Math.abs(i.y)===d&&(i.y+=.1);const c=(-i.y+d)/d,g=(i.x+h)/h,u=(i.y+d)/d,p=(-i.x+h)/h;switch(e){case F:l=c,n="bottom";break;case K:a=g,n="left";break;case N:l=u,n="top";break;case $:a=p,n="right";break;case Y:l=c,a=p,n="bottom-right";break;case U:l=c,a=g,n="bottom-left";break;case j:l=u,a=g,n="top-left";break;case q:l=u,a=p,n="top-right"}if(o){if(!("corner"===o&&e%2)){const t=Math.sqrt(Math.abs(a*l));a=a<0?-t:t,l=l<0?-t:t}}return Q(s||n,t,r),{origin:r,scaleX:a,scaleY:l,direction:e,lockRatio:o,around:s}},getRotateData(e,i,o,s,n){let r,a={};switch(i){case Y:r="bottom-right";break;case U:r="bottom-left";break;case j:r="top-left";break;case q:r="top-right";break;default:r="center"}return Q(n||r,e,a),{origin:a,rotation:t.PointHelper.getRotation(s,a,o)}},getSkewData(e,i,o,s){let n,r,a={},l=0,h=0;switch(i){case F:r={x:.5,y:0},n="bottom",l=1;break;case N:r={x:.5,y:1},n="top",l=1;break;case $:r={x:0,y:.5},n="right",h=1;break;case K:r={x:1,y:.5},n="left",h=1}const{x:d,y:c,width:g,height:u}=e;r.x=d+r.x*g,r.y=c+r.y*u,Q(s||n,e,a);const p=t.PointHelper.getRotation(r,a,{x:r.x+(l?o.x:0),y:r.y+(h?o.y:0)});return l?l=-p:h=p,{origin:a,skewX:l,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 $:t=K;break;case Y:t=U;break;case q:t=j;break;case K:t=$;break;case U:t=Y;break;case j:t=q}if(i)switch(t){case F:t=N;break;case Y:t=q;break;case U:t=j;break;case N:t=F;break;case q:t=Y;break;case j:t=U}return t}},tt={};function et(e,i){const{editBox:o}=e,s=o.enterPoint;if(!s||!e.editing||!o.visible)return;if("circle"===s.name)return;let{rotation:n}=o;const{resizeCursor:r,rotateCursor:a,skewCursor:l,resizeable:h,rotateable:d,skewable:c}=e.mergeConfig,{pointType:g}=s,{flippedX:u,flippedY:p}=o;let f="resize"===g;f&&d&&(i.metaKey||i.ctrlKey||!h)&&(f=!1);const v=c&&!f&&"resize-line"===s.name?l:f?r:a;n+=45*(J.getFlipDirection(s.direction,u,p)+1),n=2*Math.round(t.MathHelper.formatRotation(n,!0)/2);const{url:m,x:y,y:L}=v,w=m+n;tt[w]?s.cursor=tt[w]:tt[w]=s.cursor={url:ot(m,n),x:y,y:L}}function it(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function ot(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class st extends t.Box{}const nt=["top","right","bottom","left"];class rt 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 st({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new t.Group({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],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:l,buttons:h}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let o=0;o<8;o++)t=new st({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new st({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",o)),i=new st({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);h.add(l),this.listenPointEvents(l,"rotate",2),o.addMany(...n,a,h,...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,moveable:l}=t,h=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:h[t/2%h.length])),t%2||(c.rotation=t/2*90);s.set(this.getPointStyle(t.rotatePoint||h[0])),o.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),o.hittable=!i&&l,e.syncEventer=i&&l?o:null,this.app.interaction.bottomList=i&&l?[{target:o,proxy:e}]:null,this.visible=!e.locked}update(e){if(this.view.worldOpacity){const{mergeConfig:i}=this.editor,{width:o,height:s}=e,{rect:n,circle:r,resizePoints:a,rotatePoints:l,resizeLines:h}=this,{middlePoint:d,resizeable:c,rotateable:g,hideOnSmall:u}=i,p="number"==typeof u?u:10,f=!(u&&o<p&&s<p);let v,m,y,L={};for(let n=0;n<8;n++)t.AroundHelper.toPoint(t.AroundHelper.directionData[n],e,L),m=a[n],v=l[n],y=h[Math.floor(n/2)],m.set(L),v.set(L),y.set(L),m.visible=y.visible=f&&(c||g),v.visible=f&&g&&c&&!i.rotatePoint,n%2&&(m.visible=v.visible=f&&!!d,(n+1)/2%2?(y.width=o,m.width>o-30&&(m.visible=!1)):(y.height=s,m.rotation=90,m.width>s-30&&(m.visible=!1)));r.visible=f&&g&&!!i.rotatePoint,n.path&&(n.path=null),n.set(Object.assign(Object.assign({},e),{visible:!0}));const w=f&&(r.visible||this.buttons.children.length>1);this.buttons.visible=w,w&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:o,buttonsMargin:s,middlePoint:n}=this.editor.mergeConfig,{flippedX:r,flippedY:a}=this;let l=nt.indexOf(i);(l%2&&r||(l+1)%2&&a)&&o&&(l=(l+2)%4);const h=o?J.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,d=e[2*h+1],c=h%2,g=h&&3!==h?1:-1,u=(s+(l%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),o&&(t.rotation=90*(h-l),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill: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};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=this.app.interaction.bottomList=null)}onDragStart(t){if(this.dragging=!0,"rect"===t.current.name){const{editor:t}=this;this.moving=!0,t.dragStartPoint={x:t.element.x,y:t.element.y},t.opacity=t.mergeConfig.hideOnMove?0:1}}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):e.onScale(t),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;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.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,et(s,e)}))}__listenEvents(){const{rect:t,editor:i}=this;this.__eventIds=[i.on_(k.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,(()=>it(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 at='\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"/>',lt={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${at}\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${at}\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${at}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};const ht=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),dt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),ct={group(e,i,o){e.sort(dt);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(ht);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.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(ht),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(dt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},gt=t.Debug.get("EditToolCreator");function ut(){return t=>{ft.register(t)}}const pt=ut,ft={list:{},register(t){const{tag:e}=t.prototype;vt[e]?gt.repeat(e):vt[e]=t},get:(t,e)=>new vt[t](e)},{list:vt}=ft;class mt extends t.Group{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(e,i){super(i),this.config=lt,this.mergeConfig=lt,this.leafList=new t.LeafList,this.openedGroupList=new t.LeafList,this.simulateTarget=new t.Rect({visible:!1}),this.editBox=new rt(this),this.editToolList={},this.selector=new X(this),this.targetEventIds=[],e&&(this.config=t.DataHelper.default(e,this.config)),this.addMany(this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||ft.get(t,this);const{editConfig:e}=this.element;this.mergeConfig=this.single&&e?Object.assign(Object.assign({},this.mergeConfig),e):this.config,this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){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.dragStartPoint,i))}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:o,lockRatio:s}=this.mergeConfig;t.shiftKey&&(s=!0);const n=J.getScaleData(e.boxBounds,i,t.getInnerMove(e),s,J.getAround(o,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}onRotate(i){const{skewable:o,around:s,rotateGap:n}=this.mergeConfig,{direction:r,name:a}=i.current;if(o&&"resize-line"===a)return this.onSkew(i);const{element:l}=this;let h,d;if(i instanceof e.RotateEvent)d=i.rotation,h=l.getInnerPoint(i);else{const t={x:i.x-i.moveX,y:i.y-i.moveY},e=J.getRotateData(l.boxBounds,r,i.getInner(l),l.getInnerPoint(t),i.shiftKey?null:s||"center");d=e.rotation,h=e.origin}d=t.MathHelper.getGapRotation(d,n,l.rotation),d&&(l.scaleX*l.scaleY<0&&(d=-d),this.rotateOf(h,t.MathHelper.float(d,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:o,skewX:s,skewY:n}=J.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),J.getAround(i,t.altKey));(s||n)&&this.skewOf(o,s,n)}move(t,e=0){if(!this.mergeConfig.moveable||this.element.locked)return;const{element:i}=this,o=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),s=new M(M.MOVE,{target:i,editor:this,moveX:o.x,moveY:o.y});this.editTool.onMove(s),this.emitEvent(s),this.multiple&&i.move(t,e)}scaleWithDrag(t){const{element:e}=this,i=e.getWorldPoint(t.origin),o=new T(T.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(o),this.emitEvent(o)}scaleOf(e,i,o=i,s){const{element:n}=this,r=n.getWorldPoint(e);let a;if(this.multiple){const s=new t.Matrix(n.worldTransform);n.scaleOf(e,i,o),a=new t.Matrix(n.worldTransform).divide(s)}const l=new T(T.SCALE,{target:n,editor:this,worldOrigin:r,scaleX:i,scaleY:o,transform:a});this.editTool.onScale(l),this.emitEvent(l)}rotateOf(e,i){const{element:o}=this,s=o.getWorldPoint(e);let n;if(this.multiple){const s=new t.Matrix(o.worldTransform);o.rotateOf(e,i),n=new t.Matrix(o.worldTransform).divide(s)}const r=new S(S.ROTATE,{target:o,editor:this,worldOrigin:s,rotation:i,transform:n});this.editTool.onRotate(r),this.emitEvent(r)}skewOf(e,i,o=0,s){const{element:n}=this,r=n.getWorldPoint(e);let a;if(this.multiple){const s=new t.Matrix(n.worldTransform);n.skewOf(e,i,o),a=new t.Matrix(n.worldTransform).divide(s)}const l=new P(P.SKEW,{target:n,editor:this,skewX:i,skewY:o,transform:a,worldOrigin:r});this.editTool.onSkew(l),this.emitEvent(l)}group(t){return this.multiple&&(this.target=ct.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=ct.ungroup(this.list)),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1}checkOpenedGroups(){const 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)))}}openInnerEditor(){if(this.single){const t=this.element.editInner;t&&ft.list[t]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[t]||ft.get(t,this),this.innerEditor.load())}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.innerEditor.unload(),this.editTool.load(),this.innerEditor=null)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(ct.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(ct.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:i}=this.list[0];this.targetEventIds=[i.on_(t.RenderEvent.START,this.update,this),i.on_([e.KeyEvent.HOLD,e.KeyEvent.UP],(t=>{et(this,t)})),i.on_(e.KeyEvent.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}x([H((function(t,e){t.emitEvent(new k(k.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],mt.prototype,"hoverTarget",void 0),x([H((function(e,i){const{target:o}=e;o?e.leafList=o instanceof t.LeafList?o:new t.LeafList(o):e.leafList.reset(),e.emitEvent(new k(k.SELECT,{editor:e,value:o,oldValue:i})),e.checkOpenedGroups(),e.editing?e.waitLeafer((()=>{e.multiple&&function(e){const{simulateTarget:i,leafList:o}=e,{x:s,y:n,width:r,height:a}=(new t.Bounds).setListWithFn(o.list,(t=>t.worldBoxBounds)),l=i.parent=o.list[0].leafer.zoomLayer,{scaleX:h,scaleY:d,e:c,f:g}=l.__world;i.reset({x:(s-c)/h,y:(n-g)/d,width:r/h,height:a/d})}(e),it(e),e.updateEditTool(),e.update(),e.listenTargetEvents()})):(e.updateEditTool(),e.removeTargetEvents())}))],mt.prototype,"target",void 0);class yt{static registerInnerEditor(){ft.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(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}exports.EditTool=class extends yt{static registerEditTool(){ft.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,{simulateTarget:i,element:o}=t;t.multiple&&i.parent.updateLayout();const{x:s,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d,width:c,height:g}=o.getLayoutBounds("box",t,!0);e.set({x:s,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}},exports.EditTool=x([ut()],exports.EditTool);const{left:Lt,right:wt}=t.Direction9,{move:bt,copy:Et}=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===Lt;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){return{from:{x:t[0],y:t[1]},to:{x:t[2],y:t[3]}}}dragPoint(t,e,i,o,s){const{x:n,y:r}=s;i?(bt(t,n,r),o&&bt(e,-n,-r)):(o&&bt(t,-n,-r),bt(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),Et(o[7],i),Et(e[7],i),Et(o[3],a),Et(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===Lt||t===wt,o[t].visible=a,e[t].visible=!r&&a}},exports.LineEditTool=x([ut()],exports.LineEditTool),t.Creator.editor=function(t){return new mt(t)},t.UI.setEditConfig=function(e){t.defineKey(this.prototype,"editConfig",{get(){return"function"==typeof e?e(this):e}})},t.UI.setEditOuter=function(e){t.defineKey(this.prototype,"editOuter",{get(){return"string"==typeof e?e:e(this)}})},t.UI.setEditInner=function(e){t.defineKey(this.prototype,"editInner",{get(){return"string"==typeof e?e:e(this)}})},exports.EditBox=rt,exports.EditDataHelper=J,exports.EditPoint=st,exports.EditSelect=X,exports.EditSelectHelper=W,exports.EditToolCreator=ft,exports.Editor=mt,exports.EditorEvent=k,exports.EditorHelper=ct,exports.EditorMoveEvent=M,exports.EditorRotateEvent=S,exports.EditorScaleEvent=T,exports.EditorSkewEvent=P,exports.InnerEditor=yt,exports.PathScaler=f,exports.SelectArea=C,exports.Stroker=R,exports.registerEditTool=ut,exports.registerInnerEditor=pt,exports.scaleResize=y,exports.scaleResizeFont=L,exports.scaleResizeGroup=E,exports.scaleResizePath=w,exports.scaleResizePoints=b;
@@ -1 +1 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.editor=function(t,e,i){"use strict";const{M:s,L:o,C:n,Q:r,Z:a,N:l,D:h,X:d,G:c,F:g,O:u,P:f,U:p}=e.PathCommandMap,v={scale(t,e,i){if(!t)return;let v,L=0,y=t.length;for(;L<y;)switch(v=t[L],v){case s:case o:m(t,e,i,L,1),L+=3;break;case n:m(t,e,i,L,3),L+=7;break;case r:m(t,e,i,L,2),L+=5;break;case a:L+=1;break;case l:m(t,e,i,L,2),L+=5;break;case h:m(t,e,i,L,2),L+=9;break;case d:m(t,e,i,L,2),L+=6;break;case c:m(t,e,i,L,2),L+=9;break;case g:m(t,e,i,L,2),L+=5;break;case u:t[L]=c,t.splice(L+4,0,t[L+3],0),m(t,e,i,L,2),L+=9,y+=2;break;case f:t[L]=g,t.splice(L+4,0,t[L+3]),m(t,e,i,L,2),L+=5,y+=1;break;case p:m(t,e,i,L,2),L+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:m}=v;function L(t,e,i){1!==e&&(t.width*=e),1!==i&&(t.height*=i)}e.Leaf.prototype.scaleResize=function(t,e=t,i){const s=this;i?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},e.Leaf.prototype.__scaleResize=function(t,e){L(this,t,e)},e.Path.prototype.__scaleResize=function(t,e){v.scale(this.__.path,t,e),this.path=this.__.path},e.Line.prototype.__scaleResize=function(t,e){if(this.points)v.scalePoints(this.__.points,t,e),this.points=this.__.points;else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},e.Polygon.prototype.__scaleResize=function(t,e){this.points?(v.scalePoints(this.__.points,t,e),this.points=this.__.points):L(this,t,e)};const y=e.MatrixHelper.get();function E(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)y.a=e,y.d=i,s[t].transform(y,!0)}function b(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 w(t){return t?t instanceof Array?t:[t]:[]}e.Group.prototype.__scaleResize=function(t,e){E(this,t,e)},e.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?E(this,t,e):L(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class _ extends e.Event{get list(){return w(this.value)}get oldList(){return w(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}_.SELECT="editor.select",_.HOVER="editor.hover";class k extends _{constructor(t,e){super(t,e)}}k.MOVE="editor.move";class x extends _{constructor(t,e){super(t,e)}}x.SCALE="editor.scale";class M extends _{constructor(t,e){super(t,e)}}M.ROTATE="editor.rotate";class S extends _{constructor(t,e){super(t,e)}}function T(t){return(i,s)=>{const o="_"+s;e.defineKey(i,s,{get(){return this[o]},set(e){const i=this[o];i!==e&&(this[o]=e,t(this,i))}})}}S.SKEW="editor.skew";const H=e.MatrixHelper.get(),{abs:P}=Math,{copy:V,scale:O}=e.MatrixHelper;class D extends e.UI{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,i){const{list:s}=this;if(s.length){let o;const{stroke:n,strokeWidth:r,fill:a}=this.__,{bounds:l}=i;for(let h=0;h<s.length;h++)if(o=s[h],l&&l.hit(o.__world,i.matrix)){const s=P(o.__world.scaleX),l=P(o.__world.scaleY);if(s!==l){V(H,o.__world),O(H,1/s,1/l),t.setWorld(H,i.matrix),t.beginPath(),this.__.strokeWidth=r;const{x:e,y:n,width:a,height:h}=o.__layout.boxBounds;t.rect(e*s,n*l,a*s,h*l)}else t.setWorld(o.__world,i.matrix),t.beginPath(),o.__.__useArrow?o.__drawPath(t):o.__.__pathForRender?o.__drawRenderPath(t):o.__drawPathByBox(t),this.__.strokeWidth=r/P(o.__world.scaleX);n&&("string"==typeof n?e.Paint.stroke(n,this,t):e.Paint.strokes(n,this,t)),a&&("string"==typeof a?e.Paint.fill(a,this,t):e.Paint.fills(a,this,t))}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}b([T((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],D.prototype,"target",void 0);class I extends e.Group{constructor(t){super(t),this.strokeArea=new e.Rect({strokeAlign:"center"}),this.fillArea=new e.Rect,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:C,Yes:R,NoAndSkip:A,YesAndSkip:B}=e.Answer,Z={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?B:A;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?B:C;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return R}return C}return t.isBranch?A:C}},{findOne:z}=Z;class W extends e.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(t){super(),this.hoverStroker=new D,this.targetStroker=new D,this.bounds=new e.Bounds,this.selectArea=new I,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:s,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.mergeConfig;"press"===e&&this.checkAndSelect(t)}onTap(t){const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i&&this.checkAndSelect(t),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(this.allowDrag(t)){const{editor:e}=this,{stroke:i,area:s}=e.mergeConfig,{x:o,y:n}=t.getInner(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:i}=this,s=t.getInnerTotal(this),o=this.bounds.clone().unsign(),n=new e.LeafList(i.app.find(Z.findBounds,o));if(this.bounds.width=s.x,this.bounds.height=s.y,this.selectArea.setBounds(o.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(){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&&!z(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const i={exclude:new e.LeafList(this.editor.editBox.rect)};return z(t.target.leafer.interaction.findPath(t,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):z(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_(_.HOVER,this.onHover,this),t.on_(_.SELECT,this.onSelect,this),e.on_(i.PointerEvent.MOVE,this.onPointerMove,this),e.on_(i.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this),e.on_(i.PointerEvent.TAP,this.onTap,this),e.on_(i.DragEvent.START,this.onDragStart,this),e.on_(i.DragEvent.DRAG,this.onDrag,this),e.on_(i.DragEvent.END,this.onDragEnd,this),e.on_(i.MoveEvent.MOVE,this.onAutoMove,this),e.on_([i.ZoomEvent.ZOOM,i.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:G,top:X,topRight:Y,right:U,bottomRight:K,bottom:F,bottomLeft:j,left:N}=e.Direction9,{toPoint:$}=e.AroundHelper,q={getScaleData(t,e,i,s,o){let n,r={},a=1,l=1;const{width:h,height:d}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===h&&(i.x+=.1),Math.abs(i.y)===d&&(i.y+=.1);const c=(-i.y+d)/d,g=(i.x+h)/h,u=(i.y+d)/d,f=(-i.x+h)/h;switch(e){case X:l=c,n="bottom";break;case U:a=g,n="left";break;case F:l=u,n="top";break;case N:a=f,n="right";break;case G:l=c,a=f,n="bottom-right";break;case Y:l=c,a=g,n="bottom-left";break;case K:l=u,a=g,n="top-left";break;case j:l=u,a=f,n="top-right"}if(s){if(!("corner"===s&&e%2)){const t=Math.sqrt(Math.abs(a*l));a=a<0?-t:t,l=l<0?-t:t}}return $(o||n,t,r),{origin:r,scaleX:a,scaleY:l,direction:e,lockRatio:s,around:o}},getRotateData(t,i,s,o,n){let r,a={};switch(i){case G:r="bottom-right";break;case Y:r="bottom-left";break;case K:r="top-left";break;case j:r="top-right";break;default:r="center"}return $(n||r,t,a),{origin:a,rotation:e.PointHelper.getRotation(o,a,s)}},getSkewData(t,i,s,o){let n,r,a={},l=0,h=0;switch(i){case X:r={x:.5,y:0},n="bottom",l=1;break;case F:r={x:.5,y:1},n="top",l=1;break;case N:r={x:0,y:.5},n="right",h=1;break;case U:r={x:1,y:.5},n="left",h=1}const{x:d,y:c,width:g,height:u}=t;r.x=d+r.x*g,r.y=c+r.y*u,$(o||n,t,a);const f=e.PointHelper.getRotation(r,a,{x:r.x+(l?s.x:0),y:r.y+(h?s.y:0)});return l?l=-f:h=f,{origin:a,skewX:l,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 N:t=U;break;case G:t=Y;break;case j:t=K;break;case U:t=N;break;case Y:t=G;break;case K:t=j}if(i)switch(t){case X:t=F;break;case G:t=j;break;case Y:t=K;break;case F:t=X;break;case j:t=G;break;case K:t=Y}return t}},Q={};function J(t,i){const{editBox:s}=t,o=s.enterPoint;if(!o||!t.editing||!s.visible)return;if("circle"===o.name)return;let{rotation:n}=s;const{resizeCursor:r,rotateCursor:a,skewCursor:l,resizeable:h,rotateable:d,skewable:c}=t.mergeConfig,{pointType:g}=o,{flippedX:u,flippedY:f}=s;let p="resize"===g;p&&d&&(i.metaKey||i.ctrlKey||!h)&&(p=!1);const v=c&&!p&&"resize-line"===o.name?l:p?r:a;n+=45*(q.getFlipDirection(o.direction,u,f)+1),n=2*Math.round(e.MathHelper.formatRotation(n,!0)/2);const{url:m,x:L,y:y}=v,E=m+n;Q[E]?o.cursor=Q[E]:Q[E]=o.cursor={url:et(m,n),x:L,y:y}}function tt(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function et(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class it extends e.Box{}const st=["top","right","bottom","left"];class ot extends e.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(t){super(),this.view=new e.Group,this.rect=new e.Box({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new it({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new e.Group({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:l,buttons:h}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new it({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new it({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new it({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);h.add(l),this.listenPointEvents(l,"rotate",2),s.addMany(...n,a,h,...r,...o),this.add(s)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth:a,moveable:l}=t,h=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:h[t/2%h.length])),t%2||(c.rotation=t/2*90);o.set(this.getPointStyle(t.rotatePoint||h[0])),s.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),s.hittable=!i&&l,e.syncEventer=i&&l?s:null,this.app.interaction.bottomList=i&&l?[{target:s,proxy:e}]:null,this.visible=!e.locked}update(t){if(this.view.worldOpacity){const{mergeConfig:i}=this.editor,{width:s,height:o}=t,{rect:n,circle:r,resizePoints:a,rotatePoints:l,resizeLines:h}=this,{middlePoint:d,resizeable:c,rotateable:g,hideOnSmall:u}=i,f="number"==typeof u?u:10,p=!(u&&s<f&&o<f);let v,m,L,y={};for(let n=0;n<8;n++)e.AroundHelper.toPoint(e.AroundHelper.directionData[n],t,y),m=a[n],v=l[n],L=h[Math.floor(n/2)],m.set(y),v.set(y),L.set(y),m.visible=L.visible=p&&(c||g),v.visible=p&&g&&c&&!i.rotatePoint,n%2&&(m.visible=v.visible=p&&!!d,(n+1)/2%2?(L.width=s,m.width>s-30&&(m.visible=!1)):(L.height=o,m.rotation=90,m.width>o-30&&(m.visible=!1)));r.visible=p&&g&&!!i.rotatePoint,n.set(Object.assign(Object.assign({},t),{visible:!0}));const E=p&&(r.visible||this.buttons.children.length>1);this.buttons.visible=E,E&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.mergeConfig,{flippedX:r,flippedY:a}=this;let l=st.indexOf(i);(l%2&&r||(l+1)%2&&a)&&s&&(l=(l+2)%4);const h=s?q.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,d=e[2*h+1],c=h%2,g=h&&3!==h?1:-1,u=(o+(l%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),s&&(t.rotation=90*(h-l),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.mergeConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=this.app.interaction.bottomList=null)}onDragStart(t){if(this.dragging=!0,"rect"===t.current.name){const{editor:t}=this;this.moving=!0,t.dragStartPoint={x:t.element.x,y:t.element.y},t.opacity=t.mergeConfig.hideOnMove?0:1}}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):e.onScale(t),J(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,s){const{editor:o}=this;t.direction=s,t.pointType=e,t.on_(i.DragEvent.START,this.onDragStart,this),t.on_(i.DragEvent.DRAG,this.onDrag,this),t.on_(i.DragEvent.END,this.onDragEnd,this),t.on_(i.PointerEvent.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(i.PointerEvent.ENTER,(e=>{this.enterPoint=t,J(o,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(_.SELECT,this.onSelect,this),t.on_(i.DragEvent.START,this.onDragStart,this),t.on_(i.DragEvent.DRAG,e.onMove,e),t.on_(i.DragEvent.END,this.onDragEnd,this),t.on_(i.PointerEvent.ENTER,(()=>tt(e))),t.on_(i.PointerEvent.DOUBLE_TAP,this.onDoubleTap,this),t.on_(i.PointerEvent.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const nt='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',rt={editSize:"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${nt}\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${nt}\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${nt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};const at=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),lt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),ht={group(t,i,s){t.sort(lt);const{app:o,parent:n}=t[0];let r;r=s&&s.add?s:new e.Group(s),n.addAt(r,n.children.indexOf(t[0])),t.sort(at);const a=new e.Matrix(i.worldTransform);return a.divideParent(n.worldTransform),r.setTransform(a),r.editable=!0,r.hitChildren=!1,o.lockLayout(),t.forEach((t=>t.dropTo(r))),o.unlockLayout(),r},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(at),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(lt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},dt=e.Debug.get("EditToolCreator");function ct(){return t=>{ut.register(t)}}const gt=ct,ut={list:{},register(t){const{tag:e}=t.prototype;ft[e]?dt.repeat(e):ft[e]=t},get:(t,e)=>new ft[t](e)},{list:ft}=ut;class pt extends e.Group{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,i){super(i),this.config=rt,this.mergeConfig=rt,this.leafList=new e.LeafList,this.openedGroupList=new e.LeafList,this.simulateTarget=new e.Rect({visible:!1}),this.editBox=new ot(this),this.editToolList={},this.selector=new W(this),this.targetEventIds=[],t&&(this.config=e.DataHelper.default(t,this.config)),this.addMany(this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||ut.get(t,this);const{editConfig:e}=this.element;this.mergeConfig=this.single&&e?Object.assign(Object.assign({},this.mergeConfig),e):this.config,this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){const e={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(i.DragEvent.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.mergeConfig;t.shiftKey&&(o=!0);const n=q.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,q.getAround(s,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}onRotate(t){const{skewable:s,around:o,rotateGap:n}=this.mergeConfig,{direction:r,name:a}=t.current;if(s&&"resize-line"===a)return this.onSkew(t);const{element:l}=this;let h,d;if(t instanceof i.RotateEvent)d=t.rotation,h=l.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=q.getRotateData(l.boxBounds,r,t.getInner(l),l.getInnerPoint(e),t.shiftKey?null:o||"center");d=i.rotation,h=i.origin}d=e.MathHelper.getGapRotation(d,n,l.rotation),d&&(l.scaleX*l.scaleY<0&&(d=-d),this.rotateOf(h,e.MathHelper.float(d,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=q.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),q.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e=0){if(!this.mergeConfig.moveable||this.element.locked)return;const{element:i}=this,s=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),o=new k(k.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o),this.multiple&&i.move(t,e)}scaleWithDrag(t){const{element:e}=this,i=e.getWorldPoint(t.origin),s=new x(x.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(s),this.emitEvent(s)}scaleOf(t,i,s=i,o){const{element:n}=this,r=n.getWorldPoint(t);let a;if(this.multiple){const o=new e.Matrix(n.worldTransform);n.scaleOf(t,i,s),a=new e.Matrix(n.worldTransform).divide(o)}const l=new x(x.SCALE,{target:n,editor:this,worldOrigin:r,scaleX:i,scaleY:s,transform:a});this.editTool.onScale(l),this.emitEvent(l)}rotateOf(t,i){const{element:s}=this,o=s.getWorldPoint(t);let n;if(this.multiple){const o=new e.Matrix(s.worldTransform);s.rotateOf(t,i),n=new e.Matrix(s.worldTransform).divide(o)}const r=new M(M.ROTATE,{target:s,editor:this,worldOrigin:o,rotation:i,transform:n});this.editTool.onRotate(r),this.emitEvent(r)}skewOf(t,i,s=0,o){const{element:n}=this,r=n.getWorldPoint(t);let a;if(this.multiple){const o=new e.Matrix(n.worldTransform);n.skewOf(t,i,s),a=new e.Matrix(n.worldTransform).divide(o)}const l=new S(S.SKEW,{target:n,editor:this,skewX:i,skewY:s,transform:a,worldOrigin:r});this.editTool.onSkew(l),this.emitEvent(l)}group(t){return this.multiple&&(this.target=ht.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=ht.ungroup(this.list)),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:i}=t;this.editing&&(i=[],t.forEach((t=>this.list.every((i=>!e.LeafHelper.hasParent(i,t)))&&i.push(t)))),i.forEach((t=>this.closeGroup(t)))}}openInnerEditor(){if(this.single){const t=this.element.editInner;t&&ut.list[t]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[t]||ut.get(t,this),this.innerEditor.load())}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.innerEditor.unload(),this.editTool.load(),this.innerEditor=null)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(ht.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(ht.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(e.RenderEvent.START,this.update,this),t.on_([i.KeyEvent.HOLD,i.KeyEvent.UP],(t=>{J(this,t)})),t.on_(i.KeyEvent.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}b([T((function(t,e){t.emitEvent(new _(_.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],pt.prototype,"hoverTarget",void 0),b([T((function(t,i){const{target:s}=t;s?t.leafList=s instanceof e.LeafList?s:new e.LeafList(s):t.leafList.reset(),t.emitEvent(new _(_.SELECT,{editor:t,value:s,oldValue:i})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:i,leafList:s}=t,{x:o,y:n,width:r,height:a}=(new e.Bounds).setListWithFn(s.list,(t=>t.worldBoxBounds)),l=i.parent=s.list[0].leafer.zoomLayer,{scaleX:h,scaleY:d,e:c,f:g}=l.__world;i.reset({x:(o-c)/h,y:(n-g)/d,width:r/h,height:a/d})}(t),tt(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],pt.prototype,"target",void 0);class vt{static registerInnerEditor(){ut.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new e.Group,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}t.EditTool=class extends vt{static registerEditTool(){ut.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="size"===o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{simulateTarget:i,element:s}=t;t.multiple&&i.parent.updateLayout();const{x:o,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d,width:c,height:g}=s.getLayoutBounds("box",t,!0);e.set({x:o,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}},t.EditTool=b([ct()],t.EditTool);const{left:mt,right:Lt}=e.Direction9;return t.LineEditTool=class extends t.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:i,direction:s,lockRatio:o,around:n}=t,r=t.target,a=e.getPointData(),{toPoint:l}=r;r.rotation=0;let{x:h,y:d}=i.getInnerMove(r);o&&(Math.abs(h)>Math.abs(d)?d=0:h=0),s===mt?(a.x+=h,a.y+=d,n&&(l.x-=h,l.y-=d)):(n&&(a.x-=h,a.y-=d),l.x+=h,l.y+=d),r.getLocalPointByInner(a,null,null,!0),r.getLocalPointByInner(l,null,null,!0),r.x=a.x,r.y=a.y,r.getInnerPointByLocal(l,null,null,!0),r.toPoint=l}onSkew(t){}onUpdate(){const{rotatePoints:t,resizeLines:e,resizePoints:i}=this.editor.editBox;for(let s=0;s<8;s++)s<4&&(e[s].visible=!1),i[s].visible=t[s].visible=s===mt||s===Lt}},t.LineEditTool=b([ct()],t.LineEditTool),e.Creator.editor=function(t){return new pt(t)},e.UI.setEditConfig=function(t){e.defineKey(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},e.UI.setEditOuter=function(t){e.defineKey(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},e.UI.setEditInner=function(t){e.defineKey(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})},e.Line.setEditOuter((function(t){return t.points||t.pathInputed?"EditTool":"LineEditTool"})),t.EditBox=ot,t.EditDataHelper=q,t.EditPoint=it,t.EditSelect=W,t.EditSelectHelper=Z,t.EditToolCreator=ut,t.Editor=pt,t.EditorEvent=_,t.EditorHelper=ht,t.EditorMoveEvent=k,t.EditorRotateEvent=M,t.EditorScaleEvent=x,t.EditorSkewEvent=S,t.InnerEditor=vt,t.SelectArea=I,t.Stroker=D,t.registerEditTool=ct,t.registerInnerEditor=gt,t}({},LeaferUI,LeaferUI);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.editor=function(t,e,i){"use strict";const{M:o,L:s,C:n,Q:r,Z:a,N:l,D:h,X:d,G:c,F:g,O:u,P:f,U:p}=e.PathCommandMap,v={scale(t,e,i){if(!t)return;let v,L=0,y=t.length;for(;L<y;)switch(v=t[L],v){case o:case s:m(t,e,i,L,1),L+=3;break;case n:m(t,e,i,L,3),L+=7;break;case r:m(t,e,i,L,2),L+=5;break;case a:L+=1;break;case l:m(t,e,i,L,2),L+=5;break;case h:m(t,e,i,L,2),L+=9;break;case d:m(t,e,i,L,2),L+=6;break;case c:m(t,e,i,L,2),L+=9;break;case g:m(t,e,i,L,2),L+=5;break;case u:t[L]=c,t.splice(L+4,0,t[L+3],0),m(t,e,i,L,2),L+=9,y+=2;break;case f:t[L]=g,t.splice(L+4,0,t[L+3]),m(t,e,i,L,2),L+=5,y+=1;break;case p:m(t,e,i,L,2),L+=6}},scalePoints(t,e,i,o,s){for(let n=s?o+1:0,r=s?n+2*s:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:m}=v,L=e.MatrixHelper.get();function y(t,e,i){t.pathInputed?w(t,e,i):(t.width*=e,t.height*=i)}function b(t,e,i){1!==e?t.fontSize*=e:1!==i&&(t.fontSize*=i)}function w(t,e,i){v.scale(t.__.path,e,i),t.path=t.__.path}function E(t,e,i){v.scalePoints(t.__.points,e,i),t.points=t.__.points}function _(t,e,i){const{children:o}=t;for(let t=0;t<o.length;t++)L.a=e,L.d=i,o[t].transform(L,!0)}function k(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 x(t){return t?t instanceof Array?t:[t]:[]}e.Leaf.prototype.scaleResize=function(t,e=t,i){const o=this;i?(o.scaleX*=t,o.scaleY*=e):(t<0&&(o.scaleX*=-1,t=-t),e<0&&(o.scaleY*=-1,e=-e),this.__scaleResize(t,e))},e.Leaf.prototype.__scaleResize=function(t,e){y(this,t,e)},e.Text.prototype.__scaleResize=function(t,e){this.editConfig&&"font-size"===this.editConfig.editSize?b(this,t,e):y(this,t,e)},e.Path.prototype.__scaleResize=function(t,e){w(this,t,e)},e.Line.prototype.__scaleResize=function(t,e){if(this.pathInputed)w(this,t,e);else if(this.points)E(this,t,e);else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},e.Polygon.prototype.__scaleResize=function(t,e){this.pathInputed?w(this,t,e):this.points?E(this,t,e):y(this,t,e)},e.Group.prototype.__scaleResize=function(t,e){_(this,t,e)},e.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?_(this,t,e):y(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class M extends e.Event{get list(){return x(this.value)}get oldList(){return x(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}M.SELECT="editor.select",M.HOVER="editor.hover";class T extends M{constructor(t,e){super(t,e)}}T.MOVE="editor.move";class S extends M{constructor(t,e){super(t,e)}}S.SCALE="editor.scale";class P extends M{constructor(t,e){super(t,e)}}P.ROTATE="editor.rotate";class H extends M{constructor(t,e){super(t,e)}}function V(t){return(i,o)=>{const s="_"+o;e.defineKey(i,o,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}H.SKEW="editor.skew";const I=e.MatrixHelper.get(),{abs:O}=Math,{copy:D,scale:R}=e.MatrixHelper;class C extends e.UI{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,i){const{list:o}=this;if(o.length){let s;const{stroke:n,strokeWidth:r,fill:a}=this.__,{bounds:l}=i;for(let h=0;h<o.length;h++)if(s=o[h],l&&l.hit(s.__world,i.matrix)){const o=O(s.__world.scaleX),l=O(s.__world.scaleY);if(o!==l){D(I,s.__world),R(I,1/o,1/l),t.setWorld(I,i.matrix),t.beginPath(),this.__.strokeWidth=r;const{x:e,y:n,width:a,height:h}=s.__layout.boxBounds;t.rect(e*o,n*l,a*o,h*l)}else t.setWorld(s.__world,i.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),this.__.strokeWidth=r/O(s.__world.scaleX);n&&("string"==typeof n?e.Paint.stroke(n,this,t):e.Paint.strokes(n,this,t)),a&&("string"==typeof a?e.Paint.fill(a,this,t):e.Paint.fills(a,this,t))}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}k([V((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],C.prototype,"target",void 0);class B extends e.Group{constructor(t){super(t),this.strokeArea=new e.Rect({strokeAlign:"center"}),this.fillArea=new e.Rect,this.visible=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{No:A,Yes:Z,NoAndSkip:z,YesAndSkip:W}=e.Answer,G={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?W:z;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?W:A;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return Z}return A}return t.isBranch?z:A}},{findOne:X}=G;class Y extends e.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(t){super(),this.hoverStroker=new C,this.targetStroker=new C,this.bounds=new e.Bounds,this.selectArea=new B,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: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}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,o/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.mergeConfig;"press"===e&&this.checkAndSelect(t)}onTap(t){const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i&&this.checkAndSelect(t),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(this.allowDrag(t)){const{editor:e}=this,{stroke:i,area:o}=e.mergeConfig,{x:s,y:n}=t.getInner(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(t){if(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:i}=this,o=t.getInnerTotal(this),s=this.bounds.clone().unsign(),n=new e.LeafList(i.app.find(G.findBounds,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(){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&&!X(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const i={exclude:new e.LeafList(this.editor.editBox.rect)};return X(t.target.leafer.interaction.findPath(t,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):X(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_(M.HOVER,this.onHover,this),t.on_(M.SELECT,this.onSelect,this),e.on_(i.PointerEvent.MOVE,this.onPointerMove,this),e.on_(i.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this),e.on_(i.PointerEvent.TAP,this.onTap,this),e.on_(i.DragEvent.START,this.onDragStart,this),e.on_(i.DragEvent.DRAG,this.onDrag,this),e.on_(i.DragEvent.END,this.onDragEnd,this),e.on_(i.MoveEvent.MOVE,this.onAutoMove,this),e.on_([i.ZoomEvent.ZOOM,i.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:U,top:F,topRight:K,right:j,bottomRight:N,bottom:$,bottomLeft:q,left:Q}=e.Direction9,{toPoint:J}=e.AroundHelper,tt={getScaleData(t,e,i,o,s){let n,r={},a=1,l=1;const{width:h,height:d}=t;s&&(i.x*=2,i.y*=2),Math.abs(i.x)===h&&(i.x+=.1),Math.abs(i.y)===d&&(i.y+=.1);const c=(-i.y+d)/d,g=(i.x+h)/h,u=(i.y+d)/d,f=(-i.x+h)/h;switch(e){case F:l=c,n="bottom";break;case j:a=g,n="left";break;case $:l=u,n="top";break;case Q:a=f,n="right";break;case U:l=c,a=f,n="bottom-right";break;case K:l=c,a=g,n="bottom-left";break;case N:l=u,a=g,n="top-left";break;case q:l=u,a=f,n="top-right"}if(o){if(!("corner"===o&&e%2)){const t=Math.sqrt(Math.abs(a*l));a=a<0?-t:t,l=l<0?-t:t}}return J(s||n,t,r),{origin:r,scaleX:a,scaleY:l,direction:e,lockRatio:o,around:s}},getRotateData(t,i,o,s,n){let r,a={};switch(i){case U:r="bottom-right";break;case K:r="bottom-left";break;case N:r="top-left";break;case q:r="top-right";break;default:r="center"}return J(n||r,t,a),{origin:a,rotation:e.PointHelper.getRotation(s,a,o)}},getSkewData(t,i,o,s){let n,r,a={},l=0,h=0;switch(i){case F:r={x:.5,y:0},n="bottom",l=1;break;case $:r={x:.5,y:1},n="top",l=1;break;case Q:r={x:0,y:.5},n="right",h=1;break;case j:r={x:1,y:.5},n="left",h=1}const{x:d,y:c,width:g,height:u}=t;r.x=d+r.x*g,r.y=c+r.y*u,J(s||n,t,a);const f=e.PointHelper.getRotation(r,a,{x:r.x+(l?o.x:0),y:r.y+(h?o.y:0)});return l?l=-f:h=f,{origin:a,skewX:l,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 Q:t=j;break;case U:t=K;break;case q:t=N;break;case j:t=Q;break;case K:t=U;break;case N:t=q}if(i)switch(t){case F:t=$;break;case U:t=q;break;case K:t=N;break;case $:t=F;break;case q:t=U;break;case N:t=K}return t}},et={};function it(t,i){const{editBox:o}=t,s=o.enterPoint;if(!s||!t.editing||!o.visible)return;if("circle"===s.name)return;let{rotation:n}=o;const{resizeCursor:r,rotateCursor:a,skewCursor:l,resizeable:h,rotateable:d,skewable:c}=t.mergeConfig,{pointType:g}=s,{flippedX:u,flippedY:f}=o;let p="resize"===g;p&&d&&(i.metaKey||i.ctrlKey||!h)&&(p=!1);const v=c&&!p&&"resize-line"===s.name?l:p?r:a;n+=45*(tt.getFlipDirection(s.direction,u,f)+1),n=2*Math.round(e.MathHelper.formatRotation(n,!0)/2);const{url:m,x:L,y:y}=v,b=m+n;et[b]?s.cursor=et[b]:et[b]=s.cursor={url:st(m,n),x:L,y:y}}function ot(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function st(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class nt extends e.Box{}const rt=["top","right","bottom","left"];class at extends e.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(t){super(),this.view=new e.Group,this.rect=new e.Box({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new nt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new e.Group({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:o,resizePoints:s,rotatePoints:n,resizeLines:r,rect:a,circle:l,buttons:h}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let o=0;o<8;o++)t=new nt({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new nt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",o)),i=new nt({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);h.add(l),this.listenPointEvents(l,"rotate",2),o.addMany(...n,a,h,...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,moveable:l}=t,h=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:h[t/2%h.length])),t%2||(c.rotation=t/2*90);s.set(this.getPointStyle(t.rotatePoint||h[0])),o.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),o.hittable=!i&&l,e.syncEventer=i&&l?o:null,this.app.interaction.bottomList=i&&l?[{target:o,proxy:e}]:null,this.visible=!e.locked}update(t){if(this.view.worldOpacity){const{mergeConfig:i}=this.editor,{width:o,height:s}=t,{rect:n,circle:r,resizePoints:a,rotatePoints:l,resizeLines:h}=this,{middlePoint:d,resizeable:c,rotateable:g,hideOnSmall:u}=i,f="number"==typeof u?u:10,p=!(u&&o<f&&s<f);let v,m,L,y={};for(let n=0;n<8;n++)e.AroundHelper.toPoint(e.AroundHelper.directionData[n],t,y),m=a[n],v=l[n],L=h[Math.floor(n/2)],m.set(y),v.set(y),L.set(y),m.visible=L.visible=p&&(c||g),v.visible=p&&g&&c&&!i.rotatePoint,n%2&&(m.visible=v.visible=p&&!!d,(n+1)/2%2?(L.width=o,m.width>o-30&&(m.visible=!1)):(L.height=s,m.rotation=90,m.width>s-30&&(m.visible=!1)));r.visible=p&&g&&!!i.rotatePoint,n.path&&(n.path=null),n.set(Object.assign(Object.assign({},t),{visible:!0}));const b=p&&(r.visible||this.buttons.children.length>1);this.buttons.visible=b,b&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:o,buttonsMargin:s,middlePoint:n}=this.editor.mergeConfig,{flippedX:r,flippedY:a}=this;let l=rt.indexOf(i);(l%2&&r||(l+1)%2&&a)&&o&&(l=(l+2)%4);const h=o?tt.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,d=e[2*h+1],c=h%2,g=h&&3!==h?1:-1,u=(s+(l%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),o&&(t.rotation=90*(h-l),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill: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};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=this.app.interaction.bottomList=null)}onDragStart(t){if(this.dragging=!0,"rect"===t.current.name){const{editor:t}=this;this.moving=!0,t.dragStartPoint={x:t.element.x,y:t.element.y},t.opacity=t.mergeConfig.hideOnMove?0:1}}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):e.onScale(t),it(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,o){const{editor:s}=this;t.direction=o,t.pointType=e,t.on_(i.DragEvent.START,this.onDragStart,this),t.on_(i.DragEvent.DRAG,this.onDrag,this),t.on_(i.DragEvent.END,this.onDragEnd,this),t.on_(i.PointerEvent.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(i.PointerEvent.ENTER,(e=>{this.enterPoint=t,it(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(M.SELECT,this.onSelect,this),t.on_(i.DragEvent.START,this.onDragStart,this),t.on_(i.DragEvent.DRAG,e.onMove,e),t.on_(i.DragEvent.END,this.onDragEnd,this),t.on_(i.PointerEvent.ENTER,(()=>ot(e))),t.on_(i.PointerEvent.DOUBLE_TAP,this.onDoubleTap,this),t.on_(i.PointerEvent.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const lt='\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"/>',ht={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${lt}\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${lt}\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${lt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};const dt=(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),gt={group(t,i,o){t.sort(ct);const{app:s,parent:n}=t[0];let r;r=o&&o.add?o:new e.Group(o),n.addAt(r,n.children.indexOf(t[0])),t.sort(dt);const a=new e.Matrix(i.worldTransform);return a.divideParent(n.worldTransform),r.setTransform(a),r.editable=!0,r.hitChildren=!1,s.lockLayout(),t.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.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(dt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(ct),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},ut=e.Debug.get("EditToolCreator");function ft(){return t=>{vt.register(t)}}const pt=ft,vt={list:{},register(t){const{tag:e}=t.prototype;mt[e]?ut.repeat(e):mt[e]=t},get:(t,e)=>new mt[t](e)},{list:mt}=vt;class Lt extends e.Group{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,i){super(i),this.config=ht,this.mergeConfig=ht,this.leafList=new e.LeafList,this.openedGroupList=new e.LeafList,this.simulateTarget=new e.Rect({visible:!1}),this.editBox=new at(this),this.editToolList={},this.selector=new Y(this),this.targetEventIds=[],t&&(this.config=e.DataHelper.default(t,this.config)),this.addMany(this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||vt.get(t,this);const{editConfig:e}=this.element;this.mergeConfig=this.single&&e?Object.assign(Object.assign({},this.mergeConfig),e):this.config,this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){const e={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(i.DragEvent.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:o,lockRatio:s}=this.mergeConfig;t.shiftKey&&(s=!0);const n=tt.getScaleData(e.boxBounds,i,t.getInnerMove(e),s,tt.getAround(o,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}onRotate(t){const{skewable:o,around:s,rotateGap:n}=this.mergeConfig,{direction:r,name:a}=t.current;if(o&&"resize-line"===a)return this.onSkew(t);const{element:l}=this;let h,d;if(t instanceof i.RotateEvent)d=t.rotation,h=l.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=tt.getRotateData(l.boxBounds,r,t.getInner(l),l.getInnerPoint(e),t.shiftKey?null:s||"center");d=i.rotation,h=i.origin}d=e.MathHelper.getGapRotation(d,n,l.rotation),d&&(l.scaleX*l.scaleY<0&&(d=-d),this.rotateOf(h,e.MathHelper.float(d,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:o,skewX:s,skewY:n}=tt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),tt.getAround(i,t.altKey));(s||n)&&this.skewOf(o,s,n)}move(t,e=0){if(!this.mergeConfig.moveable||this.element.locked)return;const{element:i}=this,o=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),s=new T(T.MOVE,{target:i,editor:this,moveX:o.x,moveY:o.y});this.editTool.onMove(s),this.emitEvent(s),this.multiple&&i.move(t,e)}scaleWithDrag(t){const{element:e}=this,i=e.getWorldPoint(t.origin),o=new S(S.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(o),this.emitEvent(o)}scaleOf(t,i,o=i,s){const{element:n}=this,r=n.getWorldPoint(t);let a;if(this.multiple){const s=new e.Matrix(n.worldTransform);n.scaleOf(t,i,o),a=new e.Matrix(n.worldTransform).divide(s)}const l=new S(S.SCALE,{target:n,editor:this,worldOrigin:r,scaleX:i,scaleY:o,transform:a});this.editTool.onScale(l),this.emitEvent(l)}rotateOf(t,i){const{element:o}=this,s=o.getWorldPoint(t);let n;if(this.multiple){const s=new e.Matrix(o.worldTransform);o.rotateOf(t,i),n=new e.Matrix(o.worldTransform).divide(s)}const r=new P(P.ROTATE,{target:o,editor:this,worldOrigin:s,rotation:i,transform:n});this.editTool.onRotate(r),this.emitEvent(r)}skewOf(t,i,o=0,s){const{element:n}=this,r=n.getWorldPoint(t);let a;if(this.multiple){const s=new e.Matrix(n.worldTransform);n.skewOf(t,i,o),a=new e.Matrix(n.worldTransform).divide(s)}const l=new H(H.SKEW,{target:n,editor:this,skewX:i,skewY:o,transform:a,worldOrigin:r});this.editTool.onSkew(l),this.emitEvent(l)}group(t){return this.multiple&&(this.target=gt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=gt.ungroup(this.list)),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:i}=t;this.editing&&(i=[],t.forEach((t=>this.list.every((i=>!e.LeafHelper.hasParent(i,t)))&&i.push(t)))),i.forEach((t=>this.closeGroup(t)))}}openInnerEditor(){if(this.single){const t=this.element.editInner;t&&vt.list[t]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[t]||vt.get(t,this),this.innerEditor.load())}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.innerEditor.unload(),this.editTool.load(),this.innerEditor=null)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(gt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(gt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(e.RenderEvent.START,this.update,this),t.on_([i.KeyEvent.HOLD,i.KeyEvent.UP],(t=>{it(this,t)})),t.on_(i.KeyEvent.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}k([V((function(t,e){t.emitEvent(new M(M.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Lt.prototype,"hoverTarget",void 0),k([V((function(t,i){const{target:o}=t;o?t.leafList=o instanceof e.LeafList?o:new e.LeafList(o):t.leafList.reset(),t.emitEvent(new M(M.SELECT,{editor:t,value:o,oldValue:i})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:i,leafList:o}=t,{x:s,y:n,width:r,height:a}=(new e.Bounds).setListWithFn(o.list,(t=>t.worldBoxBounds)),l=i.parent=o.list[0].leafer.zoomLayer,{scaleX:h,scaleY:d,e:c,f:g}=l.__world;i.reset({x:(s-c)/h,y:(n-g)/d,width:r/h,height:a/d})}(t),ot(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],Lt.prototype,"target",void 0);class yt{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 e.Group,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}t.EditTool=class extends yt{static registerEditTool(){vt.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,{simulateTarget:i,element:o}=t;t.multiple&&i.parent.updateLayout();const{x:s,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d,width:c,height:g}=o.getLayoutBounds("box",t,!0);e.set({x:s,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}},t.EditTool=k([ft()],t.EditTool);const{left:bt,right:wt}=e.Direction9,{move:Et,copy:_t}=e.PointHelper;return t.LineEditTool=class extends t.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:i,direction:o,lockRatio:s,around:n}=t,r=t.target,a=o===bt;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 t=e.getPointData(),{toPoint:o}=r;r.rotation=0,this.dragPoint(t,o,a,n,this.getInnerMove(r,i,s)),r.getLocalPointByInner(t,null,null,!0),r.getLocalPointByInner(o,null,null,!0),r.x=t.x,r.y=t.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){return{from:{x:t[0],y:t[1]},to:{x:t[2],y:t[3]}}}dragPoint(t,e,i,o,s){const{x:n,y:r}=s;i?(Et(t,n,r),o&&Et(e,-n,-r)):(o&&Et(t,-n,-r),Et(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),_t(o[7],i),_t(e[7],i),_t(o[3],a),_t(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===bt||t===wt,o[t].visible=a,e[t].visible=!r&&a}},t.LineEditTool=k([ft()],t.LineEditTool),e.Creator.editor=function(t){return new Lt(t)},e.UI.setEditConfig=function(t){e.defineKey(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},e.UI.setEditOuter=function(t){e.defineKey(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},e.UI.setEditInner=function(t){e.defineKey(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})},t.EditBox=at,t.EditDataHelper=tt,t.EditPoint=nt,t.EditSelect=Y,t.EditSelectHelper=G,t.EditToolCreator=vt,t.Editor=Lt,t.EditorEvent=M,t.EditorHelper=gt,t.EditorMoveEvent=T,t.EditorRotateEvent=P,t.EditorScaleEvent=S,t.EditorSkewEvent=H,t.InnerEditor=yt,t.PathScaler=v,t.SelectArea=B,t.Stroker=C,t.registerEditTool=ft,t.registerInnerEditor=pt,t.scaleResize=y,t.scaleResizeFont=b,t.scaleResizeGroup=_,t.scaleResizePath=w,t.scaleResizePoints=E,t}({},LeaferUI,LeaferUI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/editor",
3
- "version": "1.0.0-rc.23",
3
+ "version": "1.0.0-rc.24",
4
4
  "description": "@leafer-in/editor",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,9 +34,9 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "dependencies": {
37
- "@leafer-ui/core": "1.0.0-rc.23",
38
- "@leafer-ui/scale": "1.0.0-rc.23",
39
- "@leafer-ui/interface": "1.0.0-rc.23",
40
- "@leafer-in/interface": "1.0.0-rc.23"
37
+ "@leafer-ui/core": "1.0.0-rc.24",
38
+ "@leafer-ui/scale": "1.0.0-rc.24",
39
+ "@leafer-ui/interface": "1.0.0-rc.24",
40
+ "@leafer-in/interface": "1.0.0-rc.24"
41
41
  }
42
42
  }
@@ -151,6 +151,7 @@ export class EditBox extends Group implements IEditBox {
151
151
  circle.visible = showPoints && rotateable && !!mergeConfig.rotatePoint
152
152
 
153
153
  // rect
154
+ if (rect.path) rect.path = null // line可能会变成path优先模式
154
155
  rect.set({ ...bounds, visible: true })
155
156
 
156
157
  // buttons
package/src/index.ts CHANGED
@@ -24,7 +24,7 @@ export { EditDataHelper } from './helper/EditDataHelper'
24
24
  export { EditSelectHelper } from './helper/EditSelectHelper'
25
25
 
26
26
  import { IEditor, IEditorConfig, IEditToolFunction, IEditorConfigFunction } from '@leafer-in/interface'
27
- import { Creator, UI, Line, defineKey } from '@leafer-ui/draw'
27
+ import { Creator, UI, defineKey } from '@leafer-ui/draw'
28
28
 
29
29
  import { Editor } from './Editor'
30
30
 
@@ -46,8 +46,4 @@ UI.setEditInner = function (editorName: string | IEditToolFunction): void {
46
46
  defineKey(this.prototype, 'editInner', {
47
47
  get(): string { return typeof editorName === 'string' ? editorName : editorName(this) }
48
48
  })
49
- }
50
-
51
- Line.setEditOuter(function (line: Line): string {
52
- return (line.points || line.pathInputed) ? 'EditTool' : 'LineEditTool'
53
- })
49
+ }
@@ -32,7 +32,7 @@ export class EditTool extends InnerEditor implements IEditTool {
32
32
  const { app, list } = editor
33
33
  app.lockLayout()
34
34
  list.forEach(target => {
35
- const resize = editor.getEditSize(target) === 'size'
35
+ const resize = editor.getEditSize(target) !== 'scale'
36
36
  if (transform) {
37
37
  target.transformWorld(transform, resize)
38
38
  } else {
@@ -47,7 +47,7 @@ export class EditTool extends InnerEditor implements IEditTool {
47
47
  const { app, list } = editor
48
48
  app.lockLayout()
49
49
  list.forEach(target => {
50
- const resize = editor.getEditSize(target) === 'size'
50
+ const resize = editor.getEditSize(target) !== 'scale'
51
51
  if (transform) {
52
52
  target.transformWorld(transform, resize)
53
53
  } else {
@@ -62,7 +62,7 @@ export class EditTool extends InnerEditor implements IEditTool {
62
62
  const { app, list } = editor
63
63
  app.lockLayout()
64
64
  list.forEach(target => {
65
- const resize = editor.getEditSize(target) === 'size'
65
+ const resize = editor.getEditSize(target) !== 'scale'
66
66
  if (transform) {
67
67
  target.transformWorld(transform, resize)
68
68
  } else {
@@ -1,13 +1,13 @@
1
- import { IEditorScaleEvent, ILine, IEditorSkewEvent } from '@leafer-in/interface'
1
+ import { IEditorScaleEvent, ILine, IEditorSkewEvent, IPointData, IAround, IPathCommandData, IFromToData, IUI, IDragEvent } from '@leafer-in/interface'
2
2
 
3
- import { getPointData, Direction9 } from '@leafer-ui/draw'
3
+ import { getPointData, Direction9, PointHelper } from '@leafer-ui/draw'
4
4
 
5
5
  import { EditTool } from './EditTool'
6
6
  import { registerEditTool } from './EditToolCreator'
7
7
 
8
8
 
9
-
10
9
  const { left, right } = Direction9
10
+ const { move, copy } = PointHelper
11
11
 
12
12
  @registerEditTool()
13
13
  export class LineEditTool extends EditTool {
@@ -18,53 +18,86 @@ export class LineEditTool extends EditTool {
18
18
 
19
19
  onScaleWithDrag(e: IEditorScaleEvent): void {
20
20
  const { drag, direction, lockRatio, around } = e
21
- const target = e.target as ILine
21
+ const line = e.target as ILine
22
+ const isDragFrom = direction === left
22
23
 
23
- const fromPoint = getPointData()
24
- const { toPoint } = target
24
+ if (line.pathInputed) {
25
25
 
26
- target.rotation = 0
26
+ const { path } = line.__
27
+ const { from, to } = this.getFromToByPath(path)
27
28
 
28
- let { x, y } = drag.getInnerMove(target)
29
+ this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio))
29
30
 
30
- if (lockRatio) {
31
- if (Math.abs(x) > Math.abs(y)) {
32
- y = 0
33
- } else {
34
- x = 0
35
- }
36
- }
31
+ path[1] = from.x, path[2] = from.y
32
+ path[4] = to.x, path[5] = to.y
33
+ line.path = path
37
34
 
38
- if (direction === left) {
35
+ } else if (line.points) {
39
36
 
40
- fromPoint.x += x
41
- fromPoint.y += y
37
+ const { points } = line
38
+ const { from, to } = this.getFromToByPoints(points)
42
39
 
43
- if (around) {
44
- toPoint.x -= x
45
- toPoint.y -= y
46
- }
40
+ this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio))
41
+
42
+ points[0] = from.x, points[1] = from.y
43
+ points[2] = to.x, points[3] = to.y
44
+ line.points = points
47
45
 
48
46
  } else {
49
47
 
50
- if (around) {
51
- fromPoint.x -= x
52
- fromPoint.y -= y
53
- }
48
+ const from = getPointData()
49
+ const { toPoint } = line
50
+ line.rotation = 0
51
+
52
+ this.dragPoint(from, toPoint, isDragFrom, around, this.getInnerMove(line, drag, lockRatio))
53
+
54
+ line.getLocalPointByInner(from, null, null, true)
55
+ line.getLocalPointByInner(toPoint, null, null, true)
56
+ line.x = from.x
57
+ line.y = from.y
58
+
59
+ line.getInnerPointByLocal(toPoint, null, null, true)
60
+ line.toPoint = toPoint
61
+
62
+ }
54
63
 
55
- toPoint.x += x
56
- toPoint.y += y
64
+ }
57
65
 
66
+ getInnerMove(ui: IUI, event: IDragEvent, lockRatio: boolean | 'corner'): IPointData {
67
+ const movePoint = event.getInnerMove(ui)
68
+ if (lockRatio) {
69
+ if (Math.abs(movePoint.x) > Math.abs(movePoint.y)) {
70
+ movePoint.y = 0
71
+ } else {
72
+ movePoint.x = 0
73
+ }
58
74
  }
75
+ return movePoint
76
+ }
59
77
 
60
- target.getLocalPointByInner(fromPoint, null, null, true)
61
- target.getLocalPointByInner(toPoint, null, null, true)
62
- target.x = fromPoint.x
63
- target.y = fromPoint.y
78
+ getFromToByPath(path: IPathCommandData): IFromToData {
79
+ return {
80
+ from: { x: path[1], y: path[2] },
81
+ to: { x: path[4], y: path[5] }
82
+ }
83
+ }
64
84
 
65
- target.getInnerPointByLocal(toPoint, null, null, true)
66
- target.toPoint = toPoint
85
+ getFromToByPoints(points: number[]): IFromToData {
86
+ return {
87
+ from: { x: points[0], y: points[1] },
88
+ to: { x: points[2], y: points[3] }
89
+ }
90
+ }
67
91
 
92
+ dragPoint(fromPoint: IPointData, toPoint: IPointData, isDragFrom: boolean, around: IAround, movePoint: IPointData): void {
93
+ const { x, y } = movePoint
94
+ if (isDragFrom) {
95
+ move(fromPoint, x, y)
96
+ if (around) move(toPoint, -x, -y)
97
+ } else {
98
+ if (around) move(fromPoint, -x, -y)
99
+ move(toPoint, x, y)
100
+ }
68
101
  }
69
102
 
70
103
  onSkew(_e: IEditorSkewEvent): void {
@@ -72,10 +105,29 @@ export class LineEditTool extends EditTool {
72
105
  }
73
106
 
74
107
  onUpdate() {
75
- const { rotatePoints, resizeLines, resizePoints } = this.editor.editBox
108
+ const { editBox } = this, { rotatePoints, resizeLines, resizePoints, rect } = editBox
109
+ const line = this.editor.element as ILine
110
+
111
+ let fromTo: IFromToData, leftOrRight: boolean
112
+ if (line.pathInputed) fromTo = this.getFromToByPath(line.__.path)
113
+ else if (line.points) fromTo = this.getFromToByPoints(line.__.points)
114
+
115
+ if (fromTo) {
116
+ const { from, to } = fromTo
117
+ line.innerToWorld(from, from, false, editBox)
118
+ line.innerToWorld(to, to, false, editBox)
119
+ rect.pen.clearPath().moveTo(from.x, from.y).lineTo(to.x, to.y)
120
+ copy(resizePoints[7] as IPointData, from)
121
+ copy(rotatePoints[7] as IPointData, from)
122
+ copy(resizePoints[3] as IPointData, to)
123
+ copy(rotatePoints[3] as IPointData, to)
124
+ }
125
+
76
126
  for (let i = 0; i < 8; i++) {
77
127
  if (i < 4) resizeLines[i].visible = false
78
- resizePoints[i].visible = rotatePoints[i].visible = (i === left || i === right)
128
+ leftOrRight = i === left || i === right
129
+ resizePoints[i].visible = leftOrRight
130
+ rotatePoints[i].visible = fromTo ? false : leftOrRight
79
131
  }
80
132
  }
81
133
 
package/types/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from '@leafer-ui/scale';
2
2
  import { IBounds, ILeafList, IUI, IEventListenerId, ILeaf, IPointerEvent, IGroup, IObject, IPointData, IGroupInputData, IEditSize, IBox, IBoundsData, IBoxInputData, IKeyEvent, IRect, IRectInputData, ILeaferCanvas, IRenderOptions, IMatrixData, IDragEvent, IAround } from '@leafer-ui/interface';
3
3
  import { Group, Event, Direction9, Box, UI, Answer } from '@leafer-ui/draw';
4
4
  import { PointerEvent, DragEvent, MoveEvent, RotateEvent } from '@leafer-ui/core';
5
- import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditorEvent, IEditPoint, IEditPointType, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent } from '@leafer-in/interface';
5
+ import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditorEvent, IEditPoint, IEditPointType, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent, IUI as IUI$1, IDragEvent as IDragEvent$1, IPointData as IPointData$1, IPathCommandData, IFromToData, IAround as IAround$1 } from '@leafer-in/interface';
6
6
 
7
7
  declare class EditSelect extends Group implements IEditSelect {
8
8
  editor: IEditor;
@@ -250,6 +250,10 @@ declare class LineEditTool extends EditTool {
250
250
  get tag(): string;
251
251
  scaleOfEvent: boolean;
252
252
  onScaleWithDrag(e: IEditorScaleEvent): void;
253
+ getInnerMove(ui: IUI$1, event: IDragEvent$1, lockRatio: boolean | 'corner'): IPointData$1;
254
+ getFromToByPath(path: IPathCommandData): IFromToData;
255
+ getFromToByPoints(points: number[]): IFromToData;
256
+ dragPoint(fromPoint: IPointData$1, toPoint: IPointData$1, isDragFrom: boolean, around: IAround$1, movePoint: IPointData$1): void;
253
257
  onSkew(_e: IEditorSkewEvent): void;
254
258
  onUpdate(): void;
255
259
  }