@leafer-in/editor 1.0.0-rc.26 → 1.0.0-rc.27

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.
package/dist/editor.cjs CHANGED
@@ -1692,6 +1692,7 @@ exports.EditSelectHelper = EditSelectHelper;
1692
1692
  exports.EditToolCreator = EditToolCreator;
1693
1693
  exports.Editor = Editor;
1694
1694
  exports.EditorEvent = EditorEvent;
1695
+ exports.EditorGroupEvent = EditorGroupEvent;
1695
1696
  exports.EditorHelper = EditorHelper;
1696
1697
  exports.EditorMoveEvent = EditorMoveEvent;
1697
1698
  exports.EditorRotateEvent = EditorRotateEvent;
@@ -1682,4 +1682,4 @@ UI.setEditInner = function (editorName) {
1682
1682
  });
1683
1683
  };
1684
1684
 
1685
- export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, registerEditTool, registerInnerEditor };
1685
+ export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, registerEditTool, registerInnerEditor };
@@ -1 +1 @@
1
- export*from"@leafer-in/resize";import{Event as t,defineKey as e,MatrixHelper as i,UI as o,Paint as s,Group as n,Rect as r,Answer as h,Bounds as a,LeafList as l,PointHelper as d,AroundHelper as c,Direction9 as g,MathHelper as u,Box as f,Matrix as p,Debug as m,DataHelper as v,LeafHelper as y,RenderEvent as L,getPointData as w,Creator as E}from"@leafer-ui/draw";import{PointerEvent as b,DragEvent as _,MoveEvent as k,ZoomEvent as x,RotateEvent as O,KeyEvent as M}from"@leafer-ui/core";function S(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 h=t.length-1;h>=0;h--)(s=t[h])&&(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(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class P extends t{get list(){return T(this.value)}get oldList(){return T(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}P.SELECT="editor.select",P.HOVER="editor.hover";class V extends P{constructor(t,e){super(t,e)}}V.MOVE="editor.move";class H extends P{constructor(t,e){super(t,e)}}H.SCALE="editor.scale";class I extends P{constructor(t,e){super(t,e)}}I.ROTATE="editor.rotate";class C extends P{constructor(t,e){super(t,e)}}function B(t){return(i,o)=>{const s="_"+o;e(i,o,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}C.SKEW="editor.skew";const R=i.get(),{abs:D}=Math,{copy:A,scale:Z}=i;class W extends o{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let o;const{stroke:n,strokeWidth:r,fill:h}=this.__,{bounds:a}=e;for(let l=0;l<i.length;l++)if(o=i[l],a&&a.hit(o.__world,e.matrix)){const i=D(o.__world.scaleX),a=D(o.__world.scaleY);if(i!==a){A(R,o.__world),Z(R,1/i,1/a),t.setWorld(R,e.matrix),t.beginPath(),this.__.strokeWidth=r;const{x:s,y:n,width:h,height:l}=o.__layout.boxBounds;t.rect(s*i,n*a,h*i,l*a)}else t.setWorld(o.__world,e.matrix),t.beginPath(),o.__.__useArrow?o.__drawPath(t):o.__.__pathForRender?o.__drawRenderPath(t):o.__drawPathByBox(t),this.__.strokeWidth=r/D(o.__world.scaleX);n&&("string"==typeof n?s.stroke(n,this,t):s.strokes(n,this,t)),h&&("string"==typeof h?s.fill(h,this,t):s.fills(h,this,t))}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}S([B((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],W.prototype,"target",void 0);class z extends n{constructor(t){super(t),this.strokeArea=new r({strokeAlign:"center"}),this.fillArea=new r,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:F,Yes:G,NoAndSkip:U,YesAndSkip:Y}=h,X={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?Y:U;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?Y:F;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return G}return F}return t.isBranch?U:F}},{findOne:N}=X;class j extends n{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 W,this.targetStroker=new W,this.bounds=new a,this.selectArea=new z,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:e}=this,i=t.getInnerTotal(this),o=this.bounds.clone().unsign(),s=new l(e.app.find(X.findBounds,o));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(o.get()),s.length){const t=[];this.originList.forEach((e=>{s.has(e)||t.push(e)})),s.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list}}onDragEnd(){this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!N(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new l(this.editor.editBox.rect)};return N(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):N(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_(P.HOVER,this.onHover,this),t.on_(P.SELECT,this.onSelect,this),e.on_(b.MOVE,this.onPointerMove,this),e.on_(b.BEFORE_DOWN,this.onBeforeDown,this),e.on_(b.TAP,this.onTap,this),e.on_(_.START,this.onDragStart,this),e.on_(_.DRAG,this.onDrag,this),e.on_(_.END,this.onDragEnd,this),e.on_(k.MOVE,this.onAutoMove,this),e.on_([x.ZOOM,k.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:K,top:$,topRight:q,right:J,bottomRight:Q,bottom:tt,bottomLeft:et,left:it}=g,{toPoint:ot}=c,st={getScaleData(t,e,i,o,s){let n,r={},h=1,a=1;const{width:l,height:d}=t;s&&(i.x*=2,i.y*=2),Math.abs(i.x)===l&&(i.x+=.1),Math.abs(i.y)===d&&(i.y+=.1);const c=(-i.y+d)/d,g=(i.x+l)/l,u=(i.y+d)/d,f=(-i.x+l)/l;switch(e){case $:a=c,n="bottom";break;case J:h=g,n="left";break;case tt:a=u,n="top";break;case it:h=f,n="right";break;case K:a=c,h=f,n="bottom-right";break;case q:a=c,h=g,n="bottom-left";break;case Q:a=u,h=g,n="top-left";break;case et:a=u,h=f,n="top-right"}if(o){if(!("corner"===o&&e%2)){const t=Math.sqrt(Math.abs(h*a));h=h<0?-t:t,a=a<0?-t:t}}return ot(s||n,t,r),{origin:r,scaleX:h,scaleY:a,direction:e,lockRatio:o,around:s}},getRotateData(t,e,i,o,s){let n,r={};switch(e){case K:n="bottom-right";break;case q:n="bottom-left";break;case Q:n="top-left";break;case et:n="top-right";break;default:n="center"}return ot(s||n,t,r),{origin:r,rotation:d.getRotation(o,r,i)}},getSkewData(t,e,i,o){let s,n,r={},h=0,a=0;switch(e){case $:n={x:.5,y:0},s="bottom",h=1;break;case tt:n={x:.5,y:1},s="top",h=1;break;case it:n={x:0,y:.5},s="right",a=1;break;case J:n={x:1,y:.5},s="left",a=1}const{x:l,y:c,width:g,height:u}=t;n.x=l+n.x*g,n.y=c+n.y*u,ot(o||s,t,r);const f=d.getRotation(n,r,{x:n.x+(h?i.x:0),y:n.y+(a?i.y:0)});return h?h=-f:a=f,{origin:r,skewX:h,skewY:a}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case it:t=J;break;case K:t=q;break;case et:t=Q;break;case J:t=it;break;case q:t=K;break;case Q:t=et}if(i)switch(t){case $:t=tt;break;case K:t=et;break;case q:t=Q;break;case tt:t=$;break;case et:t=K;break;case Q:t=q}return t}},nt={};function rt(t,e){const{editBox:i}=t,o=i.enterPoint;if(!o||!t.editing||!i.visible)return;if("circle"===o.name)return;let{rotation:s}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:h,resizeable:a,rotateable:l,skewable:d}=t.mergeConfig,{pointType:c}=o,{flippedX:g,flippedY:f}=i;let p="resize"===c;p&&l&&(e.metaKey||e.ctrlKey||!a)&&(p=!1);const m=d&&!p&&"resize-line"===o.name?h:p?n:r;s+=45*(st.getFlipDirection(o.direction,g,f)+1),s=2*Math.round(u.formatRotation(s,!0)/2);const{url:v,x:y,y:L}=m,w=v+s;nt[w]?o.cursor=nt[w]:nt[w]=o.cursor={url:at(v,s),x:y,y:L}}function ht(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function at(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class lt extends f{}const dt=["top","right","bottom","left"];class ct extends n{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 n,this.rect=new f({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new lt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new n({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.rect.syncEventer=t,this.__listenEvents()}create(){let t,e,i;const{view:o,resizePoints:s,rotatePoints:n,resizeLines:r,rect:h,circle:a,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let o=0;o<8;o++)t=new lt({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new lt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",o)),i=new lt({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);l.add(a),this.listenPointEvents(a,"rotate",2),o.addMany(...n,h,l,...r,...s),this.add(o)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:o,circle:s,resizePoints:n}=this,{stroke:r,strokeWidth:h,moveable:a}=t,l=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:l[t/2%l.length])),t%2||(c.rotation=t/2*90);s.set(this.getPointStyle(t.rotatePoint||l[0])),o.set(Object.assign({stroke:r,strokeWidth:h},t.rect||{})),o.hittable=!i&&a,e.syncEventer=i&&a?o:null,this.app.interaction.bottomList=i&&a?[{target:o,proxy:e}]:null}update(t){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:e}=this.editor,{width:i,height:o}=t,{rect:s,circle:n,resizePoints:r,rotatePoints:h,resizeLines:a}=this,{middlePoint:l,resizeable:d,rotateable:g,hideOnSmall:u}=e,f="number"==typeof u?u:10,p=!(u&&i<f&&o<f);let m,v,y,L={};for(let s=0;s<8;s++)c.toPoint(c.directionData[s],t,L),v=r[s],m=h[s],y=a[Math.floor(s/2)],v.set(L),m.set(L),y.set(L),v.visible=y.visible=p&&!(!d&&!g),m.visible=p&&g&&d&&!e.rotatePoint,s%2&&(v.visible=m.visible=p&&!!l,(s+1)/2%2?(y.width=i,v.width>i-30&&(v.visible=!1)):(y.height=o,v.rotation=90,v.width>o-30&&(v.visible=!1)));n.visible=p&&g&&!!e.rotatePoint,s.path&&(s.path=null),s.set(Object.assign(Object.assign({},t),{visible:!0}));const w=p&&(n.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:h}=this;let a=dt.indexOf(i);(a%2&&r||(a+1)%2&&h)&&o&&(a=(a+2)%4);const l=o?st.getRotateDirection(a,this.flippedOne?this.rotation:-this.rotation,4):a,d=e[2*l+1],c=l%2,g=l&&3!==l?1:-1,u=(s+(a%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),o&&(t.rotation=90*(l-a),t.scaleX=r?-1:1,t.scaleY=h?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill: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),rt(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:o}=this;t.direction=i,t.pointType=e,t.on_(_.START,this.onDragStart,this),t.on_(_.DRAG,this.onDrag,this),t.on_(_.END,this.onDragEnd,this),t.on_(b.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(b.ENTER,(e=>{this.enterPoint=t,rt(o,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(P.SELECT,this.onSelect,this),t.on_(_.START,this.onDragStart,this),t.on_(_.DRAG,e.onMove,e),t.on_(_.END,this.onDragEnd,this),t.on_(x.BEFORE_ZOOM,e.onScale,e,!0),t.on_(O.BEFORE_ROTATE,e.onRotate,e,!0),t.on_(b.ENTER,(()=>ht(e))),t.on_(b.DOUBLE_TAP,this.onDoubleTap,this),t.on_(b.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const gt='\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"/>',ut={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${gt}\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${gt}\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${gt}\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 ft=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),pt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),mt={group(t,e,i){t.sort(pt);const{app:o,parent:s}=t[0];let r;r=i&&i.add?i:new n(i),s.addAt(r,s.children.indexOf(t[0])),t.sort(ft);const h=new p(e.worldTransform);return h.divideParent(s.worldTransform),r.setTransform(h),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: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(ft),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(pt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},vt=m.get("EditToolCreator");function yt(){return t=>{wt.register(t)}}const Lt=yt,wt={list:{},register(t){const{tag:e}=t.prototype;Et[e]?vt.repeat(e):Et[e]=t},get:(t,e)=>new Et[t](e)},{list:Et}=wt;class bt extends P{constructor(t,e){super(t,e)}}bt.BEFORE_OPEN="innerEditor.before_open",bt.OPEN="innerEditor.open",bt.BEFORE_CLOSE="innerEditor.before_close",bt.CLOSE="innerEditor.close";class _t extends P{constructor(t,e){super(t,e)}}_t.GROUP="editor.group",_t.BEFORE_UNGROUP="editor.before_ungroup",_t.UNGROUP="editor.ungroup",_t.OPEN="editor.open_group",_t.CLOSE="editor.close_group";class kt extends n{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,e){super(e),this.config=ut,this.mergeConfig=ut,this.leafList=new l,this.openedGroupList=new l,this.simulateTarget=new r({visible:!1}),this.editBox=new ct(this),this.editToolList={},this.selector=new j(this),this.targetEventIds=[],t&&(this.config=v.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]||wt.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(_.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this;if(t instanceof x)"zoom"===this.mergeConfig.resizeable&&(t.stop(),this.scaleOf(e.getInnerPoint(t),t.scale,t.scale));else{const{direction:i}=t.current;let{around:o,lockRatio:s}=this.mergeConfig;(t.shiftKey||e.lockRatio)&&(s=!0);const n=st.getScaleData(e.boxBounds,i,t.getInnerMove(e),s,st.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:e,around:i,rotateGap:o}=this.mergeConfig,{direction:s,name:n}=t.current;if(e&&"resize-line"===n)return this.onSkew(t);const{element:r}=this;let h,a;if(t instanceof O){if("rotate"!==this.mergeConfig.rotateable)return;t.stop(),a=t.rotation,h=r.getInnerPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},o=st.getRotateData(r.boxBounds,s,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");a=o.rotation,h=o.origin}a=u.getGapRotation(a,o,r.rotation),a&&(r.scaleX*r.scaleY<0&&(a=-a),this.rotateOf(h,u.float(a,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:o,skewX:s,skewY:n}=st.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),st.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 V(V.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){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:e}=this,i=e.getWorldPoint(t.origin),o=new H(H.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(o),this.emitEvent(o)}scaleOf(t,e,i=e,o){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:s}=this,n=s.getWorldPoint(y.getInnerOrigin(s,t));let r;if(this.multiple){const o=new p(s.worldTransform);s.scaleOf(t,e,i),r=new p(s.worldTransform).divide(o)}const h=new H(H.SCALE,{target:s,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(h),this.emitEvent(h)}rotateOf(t,e){if(!this.mergeConfig.rotateable||this.element.locked)return;const{element:i}=this,o=i.getWorldPoint(y.getInnerOrigin(i,t));let s;if(this.multiple){const o=new p(i.worldTransform);i.rotateOf(t,e),s=new p(i.worldTransform).divide(o)}const n=new I(I.ROTATE,{target:i,editor:this,worldOrigin:o,rotation:e,transform:s});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,o){if(!this.mergeConfig.skewable||this.element.locked)return;const{element:s}=this,n=s.getWorldPoint(y.getInnerOrigin(s,t));let r;if(this.multiple){const o=new p(s.worldTransform);s.skewOf(t,e,i),r=new p(s.worldTransform).divide(o)}const h=new C(C.SKEW,{target:s,editor:this,skewX:e,skewY:i,transform:r,worldOrigin:n});this.editTool.onSkew(h),this.emitEvent(h)}group(t){return this.multiple&&(this.target=mt.group(this.list,this.element,t),this.emitGroupEvent(_t.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(_t.BEFORE_UNGROUP,t))),this.target=mt.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(_t.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(_t.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(_t.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!y.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new _t(t,{editTarget:e});this.emitEvent(i),e.emitEvent(i)}openInnerEditor(t){if(t&&(this.target=t),this.single){const t=this.element,e=t.editInner;e&&wt.list[e]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[e]||wt.get(e,this),this.innerEditor.editTarget=t,this.emitInnerEvent(bt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(bt.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(bt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(bt.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,o=new bt(t,{editTarget:i,innerEditor:e});this.emitEvent(o),i.emitEvent(o)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(mt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(mt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(L.START,this.update,this),t.on_([M.HOLD,M.UP],(t=>{rt(this,t)})),t.on_(M.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())}}S([B((function(t,e){t.emitEvent(new P(P.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],kt.prototype,"hoverTarget",void 0),S([B((function(t,e){const{target:i}=t;i?t.leafList=i instanceof l?i:new l(i):t.leafList.reset(),t.emitEvent(new P(P.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:i}=t,{x:o,y:s,width:n,height:r}=(new a).setListWithFn(i.list,(t=>t.worldBoxBounds)),h=e.parent=i.list[0].leafer.zoomLayer,{scaleX:l,scaleY:d,e:c,f:g}=h.__world;e.reset({x:(o-c)/l,y:(s-g)/d,width:n/l,height:r/d})}(t),ht(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],kt.prototype,"target",void 0);class xt{static registerInnerEditor(){wt.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new n,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let Ot=class extends xt{static registerEditTool(){wt.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:h}=n;r.lockLayout(),h.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:h}=n;r.lockLayout(),h.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:h,rotation:a,skewX:l,skewY:d,width:c,height:g}=o.getLayoutBounds("box",t,!0);e.set({x:s,y:n,scaleX:r,scaleY:h,rotation:a,skewX:l,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};Ot=S([yt()],Ot);const{left:Mt,right:St}=g,{move:Tt,copy:Pt}=d;let Vt=class extends Ot{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:o,around:s}=t,n=t.target,r=i===Mt;if(n.pathInputed){const{path:t}=n.__,{from:i,to:h}=this.getFromToByPath(t);this.dragPoint(i,h,r,s,this.getInnerMove(n,e,o)),t[1]=i.x,t[2]=i.y,t[4]=h.x,t[5]=h.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:h}=this.getFromToByPoints(t);this.dragPoint(i,h,r,s,this.getInnerMove(n,e,o)),t[0]=i.x,t[1]=i.y,t[2]=h.x,t[3]=h.y,n.points=t}else{const t=w(),{toPoint:i}=n;n.rotation=0,this.dragPoint(t,i,r,s,this.getInnerMove(n,e,o)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(i,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(i,null,null,!0),n.toPoint=i}}getInnerMove(t,e,i){const 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?(Tt(t,n,r),o&&Tt(e,-n,-r)):(o&&Tt(t,-n,-r),Tt(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,h;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:h}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(h,h,!1,t),s.pen.clearPath().moveTo(i.x,i.y).lineTo(h.x,h.y),Pt(o[7],i),Pt(e[7],i),Pt(o[3],h),Pt(e[3],h)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),h=t===Mt||t===St,o[t].visible=h,e[t].visible=!r&&h}};Vt=S([yt()],Vt),E.editor=function(t){return new kt(t)},o.setEditConfig=function(t){e(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},o.setEditOuter=function(t){e(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},o.setEditInner=function(t){e(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})};export{ct as EditBox,st as EditDataHelper,lt as EditPoint,j as EditSelect,X as EditSelectHelper,Ot as EditTool,wt as EditToolCreator,kt as Editor,P as EditorEvent,mt as EditorHelper,V as EditorMoveEvent,I as EditorRotateEvent,H as EditorScaleEvent,C as EditorSkewEvent,xt as InnerEditor,bt as InnerEditorEvent,Vt as LineEditTool,z as SelectArea,W as Stroker,yt as registerEditTool,Lt as registerInnerEditor};
1
+ export*from"@leafer-in/resize";import{Event as t,defineKey as e,MatrixHelper as i,UI as o,Paint as s,Group as n,Rect as r,Answer as h,Bounds as a,LeafList as l,PointHelper as d,AroundHelper as c,Direction9 as g,MathHelper as u,Box as f,Matrix as p,Debug as m,DataHelper as v,LeafHelper as y,RenderEvent as L,getPointData as w,Creator as E}from"@leafer-ui/draw";import{PointerEvent as b,DragEvent as _,MoveEvent as k,ZoomEvent as x,RotateEvent as O,KeyEvent as M}from"@leafer-ui/core";function S(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 h=t.length-1;h>=0;h--)(s=t[h])&&(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(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class P extends t{get list(){return T(this.value)}get oldList(){return T(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}P.SELECT="editor.select",P.HOVER="editor.hover";class V extends P{constructor(t,e){super(t,e)}}V.MOVE="editor.move";class H extends P{constructor(t,e){super(t,e)}}H.SCALE="editor.scale";class I extends P{constructor(t,e){super(t,e)}}I.ROTATE="editor.rotate";class C extends P{constructor(t,e){super(t,e)}}function B(t){return(i,o)=>{const s="_"+o;e(i,o,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}C.SKEW="editor.skew";const R=i.get(),{abs:D}=Math,{copy:A,scale:Z}=i;class W extends o{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let o;const{stroke:n,strokeWidth:r,fill:h}=this.__,{bounds:a}=e;for(let l=0;l<i.length;l++)if(o=i[l],a&&a.hit(o.__world,e.matrix)){const i=D(o.__world.scaleX),a=D(o.__world.scaleY);if(i!==a){A(R,o.__world),Z(R,1/i,1/a),t.setWorld(R,e.matrix),t.beginPath(),this.__.strokeWidth=r;const{x:s,y:n,width:h,height:l}=o.__layout.boxBounds;t.rect(s*i,n*a,h*i,l*a)}else t.setWorld(o.__world,e.matrix),t.beginPath(),o.__.__useArrow?o.__drawPath(t):o.__.__pathForRender?o.__drawRenderPath(t):o.__drawPathByBox(t),this.__.strokeWidth=r/D(o.__world.scaleX);n&&("string"==typeof n?s.stroke(n,this,t):s.strokes(n,this,t)),h&&("string"==typeof h?s.fill(h,this,t):s.fills(h,this,t))}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}S([B((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],W.prototype,"target",void 0);class z extends n{constructor(t){super(t),this.strokeArea=new r({strokeAlign:"center"}),this.fillArea=new r,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:F,Yes:G,NoAndSkip:U,YesAndSkip:Y}=h,X={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?Y:U;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?Y:F;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return G}return F}return t.isBranch?U:F}},{findOne:N}=X;class j extends n{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 W,this.targetStroker=new W,this.bounds=new a,this.selectArea=new z,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:e}=this,i=t.getInnerTotal(this),o=this.bounds.clone().unsign(),s=new l(e.app.find(X.findBounds,o));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(o.get()),s.length){const t=[];this.originList.forEach((e=>{s.has(e)||t.push(e)})),s.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list}}onDragEnd(){this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!N(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new l(this.editor.editBox.rect)};return N(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):N(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_(P.HOVER,this.onHover,this),t.on_(P.SELECT,this.onSelect,this),e.on_(b.MOVE,this.onPointerMove,this),e.on_(b.BEFORE_DOWN,this.onBeforeDown,this),e.on_(b.TAP,this.onTap,this),e.on_(_.START,this.onDragStart,this),e.on_(_.DRAG,this.onDrag,this),e.on_(_.END,this.onDragEnd,this),e.on_(k.MOVE,this.onAutoMove,this),e.on_([x.ZOOM,k.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:K,top:$,topRight:q,right:J,bottomRight:Q,bottom:tt,bottomLeft:et,left:it}=g,{toPoint:ot}=c,st={getScaleData(t,e,i,o,s){let n,r={},h=1,a=1;const{width:l,height:d}=t;s&&(i.x*=2,i.y*=2),Math.abs(i.x)===l&&(i.x+=.1),Math.abs(i.y)===d&&(i.y+=.1);const c=(-i.y+d)/d,g=(i.x+l)/l,u=(i.y+d)/d,f=(-i.x+l)/l;switch(e){case $:a=c,n="bottom";break;case J:h=g,n="left";break;case tt:a=u,n="top";break;case it:h=f,n="right";break;case K:a=c,h=f,n="bottom-right";break;case q:a=c,h=g,n="bottom-left";break;case Q:a=u,h=g,n="top-left";break;case et:a=u,h=f,n="top-right"}if(o){if(!("corner"===o&&e%2)){const t=Math.sqrt(Math.abs(h*a));h=h<0?-t:t,a=a<0?-t:t}}return ot(s||n,t,r),{origin:r,scaleX:h,scaleY:a,direction:e,lockRatio:o,around:s}},getRotateData(t,e,i,o,s){let n,r={};switch(e){case K:n="bottom-right";break;case q:n="bottom-left";break;case Q:n="top-left";break;case et:n="top-right";break;default:n="center"}return ot(s||n,t,r),{origin:r,rotation:d.getRotation(o,r,i)}},getSkewData(t,e,i,o){let s,n,r={},h=0,a=0;switch(e){case $:n={x:.5,y:0},s="bottom",h=1;break;case tt:n={x:.5,y:1},s="top",h=1;break;case it:n={x:0,y:.5},s="right",a=1;break;case J:n={x:1,y:.5},s="left",a=1}const{x:l,y:c,width:g,height:u}=t;n.x=l+n.x*g,n.y=c+n.y*u,ot(o||s,t,r);const f=d.getRotation(n,r,{x:n.x+(h?i.x:0),y:n.y+(a?i.y:0)});return h?h=-f:a=f,{origin:r,skewX:h,skewY:a}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case it:t=J;break;case K:t=q;break;case et:t=Q;break;case J:t=it;break;case q:t=K;break;case Q:t=et}if(i)switch(t){case $:t=tt;break;case K:t=et;break;case q:t=Q;break;case tt:t=$;break;case et:t=K;break;case Q:t=q}return t}},nt={};function rt(t,e){const{editBox:i}=t,o=i.enterPoint;if(!o||!t.editing||!i.visible)return;if("circle"===o.name)return;let{rotation:s}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:h,resizeable:a,rotateable:l,skewable:d}=t.mergeConfig,{pointType:c}=o,{flippedX:g,flippedY:f}=i;let p="resize"===c;p&&l&&(e.metaKey||e.ctrlKey||!a)&&(p=!1);const m=d&&!p&&"resize-line"===o.name?h:p?n:r;s+=45*(st.getFlipDirection(o.direction,g,f)+1),s=2*Math.round(u.formatRotation(s,!0)/2);const{url:v,x:y,y:L}=m,w=v+s;nt[w]?o.cursor=nt[w]:nt[w]=o.cursor={url:at(v,s),x:y,y:L}}function ht(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function at(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class lt extends f{}const dt=["top","right","bottom","left"];class ct extends n{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 n,this.rect=new f({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new lt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new n({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.rect.syncEventer=t,this.__listenEvents()}create(){let t,e,i;const{view:o,resizePoints:s,rotatePoints:n,resizeLines:r,rect:h,circle:a,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let o=0;o<8;o++)t=new lt({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new lt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",o)),i=new lt({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);l.add(a),this.listenPointEvents(a,"rotate",2),o.addMany(...n,h,l,...r,...s),this.add(o)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:o,circle:s,resizePoints:n}=this,{stroke:r,strokeWidth:h,moveable:a}=t,l=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:l[t/2%l.length])),t%2||(c.rotation=t/2*90);s.set(this.getPointStyle(t.rotatePoint||l[0])),o.set(Object.assign({stroke:r,strokeWidth:h},t.rect||{})),o.hittable=!i&&a,e.syncEventer=i&&a?o:null,this.app.interaction.bottomList=i&&a?[{target:o,proxy:e}]:null}update(t){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:e}=this.editor,{width:i,height:o}=t,{rect:s,circle:n,resizePoints:r,rotatePoints:h,resizeLines:a}=this,{middlePoint:l,resizeable:d,rotateable:g,hideOnSmall:u}=e,f="number"==typeof u?u:10,p=!(u&&i<f&&o<f);let m,v,y,L={};for(let s=0;s<8;s++)c.toPoint(c.directionData[s],t,L),v=r[s],m=h[s],y=a[Math.floor(s/2)],v.set(L),m.set(L),y.set(L),v.visible=y.visible=p&&!(!d&&!g),m.visible=p&&g&&d&&!e.rotatePoint,s%2&&(v.visible=m.visible=p&&!!l,(s+1)/2%2?(y.width=i,v.width>i-30&&(v.visible=!1)):(y.height=o,v.rotation=90,v.width>o-30&&(v.visible=!1)));n.visible=p&&g&&!!e.rotatePoint,s.path&&(s.path=null),s.set(Object.assign(Object.assign({},t),{visible:!0}));const w=p&&(n.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:h}=this;let a=dt.indexOf(i);(a%2&&r||(a+1)%2&&h)&&o&&(a=(a+2)%4);const l=o?st.getRotateDirection(a,this.flippedOne?this.rotation:-this.rotation,4):a,d=e[2*l+1],c=l%2,g=l&&3!==l?1:-1,u=(s+(a%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),o&&(t.rotation=90*(l-a),t.scaleX=r?-1:1,t.scaleY=h?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill: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),rt(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:o}=this;t.direction=i,t.pointType=e,t.on_(_.START,this.onDragStart,this),t.on_(_.DRAG,this.onDrag,this),t.on_(_.END,this.onDragEnd,this),t.on_(b.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(b.ENTER,(e=>{this.enterPoint=t,rt(o,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(P.SELECT,this.onSelect,this),t.on_(_.START,this.onDragStart,this),t.on_(_.DRAG,e.onMove,e),t.on_(_.END,this.onDragEnd,this),t.on_(x.BEFORE_ZOOM,e.onScale,e,!0),t.on_(O.BEFORE_ROTATE,e.onRotate,e,!0),t.on_(b.ENTER,(()=>ht(e))),t.on_(b.DOUBLE_TAP,this.onDoubleTap,this),t.on_(b.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const gt='\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"/>',ut={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${gt}\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${gt}\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${gt}\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 ft=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),pt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),mt={group(t,e,i){t.sort(pt);const{app:o,parent:s}=t[0];let r;r=i&&i.add?i:new n(i),s.addAt(r,s.children.indexOf(t[0])),t.sort(ft);const h=new p(e.worldTransform);return h.divideParent(s.worldTransform),r.setTransform(h),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: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(ft),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(pt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},vt=m.get("EditToolCreator");function yt(){return t=>{wt.register(t)}}const Lt=yt,wt={list:{},register(t){const{tag:e}=t.prototype;Et[e]?vt.repeat(e):Et[e]=t},get:(t,e)=>new Et[t](e)},{list:Et}=wt;class bt extends P{constructor(t,e){super(t,e)}}bt.BEFORE_OPEN="innerEditor.before_open",bt.OPEN="innerEditor.open",bt.BEFORE_CLOSE="innerEditor.before_close",bt.CLOSE="innerEditor.close";class _t extends P{constructor(t,e){super(t,e)}}_t.GROUP="editor.group",_t.BEFORE_UNGROUP="editor.before_ungroup",_t.UNGROUP="editor.ungroup",_t.OPEN="editor.open_group",_t.CLOSE="editor.close_group";class kt extends n{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,e){super(e),this.config=ut,this.mergeConfig=ut,this.leafList=new l,this.openedGroupList=new l,this.simulateTarget=new r({visible:!1}),this.editBox=new ct(this),this.editToolList={},this.selector=new j(this),this.targetEventIds=[],t&&(this.config=v.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]||wt.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(_.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this;if(t instanceof x)"zoom"===this.mergeConfig.resizeable&&(t.stop(),this.scaleOf(e.getInnerPoint(t),t.scale,t.scale));else{const{direction:i}=t.current;let{around:o,lockRatio:s}=this.mergeConfig;(t.shiftKey||e.lockRatio)&&(s=!0);const n=st.getScaleData(e.boxBounds,i,t.getInnerMove(e),s,st.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:e,around:i,rotateGap:o}=this.mergeConfig,{direction:s,name:n}=t.current;if(e&&"resize-line"===n)return this.onSkew(t);const{element:r}=this;let h,a;if(t instanceof O){if("rotate"!==this.mergeConfig.rotateable)return;t.stop(),a=t.rotation,h=r.getInnerPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},o=st.getRotateData(r.boxBounds,s,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");a=o.rotation,h=o.origin}a=u.getGapRotation(a,o,r.rotation),a&&(r.scaleX*r.scaleY<0&&(a=-a),this.rotateOf(h,u.float(a,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:o,skewX:s,skewY:n}=st.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),st.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 V(V.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){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:e}=this,i=e.getWorldPoint(t.origin),o=new H(H.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(o),this.emitEvent(o)}scaleOf(t,e,i=e,o){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:s}=this,n=s.getWorldPoint(y.getInnerOrigin(s,t));let r;if(this.multiple){const o=new p(s.worldTransform);s.scaleOf(t,e,i),r=new p(s.worldTransform).divide(o)}const h=new H(H.SCALE,{target:s,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(h),this.emitEvent(h)}rotateOf(t,e){if(!this.mergeConfig.rotateable||this.element.locked)return;const{element:i}=this,o=i.getWorldPoint(y.getInnerOrigin(i,t));let s;if(this.multiple){const o=new p(i.worldTransform);i.rotateOf(t,e),s=new p(i.worldTransform).divide(o)}const n=new I(I.ROTATE,{target:i,editor:this,worldOrigin:o,rotation:e,transform:s});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,o){if(!this.mergeConfig.skewable||this.element.locked)return;const{element:s}=this,n=s.getWorldPoint(y.getInnerOrigin(s,t));let r;if(this.multiple){const o=new p(s.worldTransform);s.skewOf(t,e,i),r=new p(s.worldTransform).divide(o)}const h=new C(C.SKEW,{target:s,editor:this,skewX:e,skewY:i,transform:r,worldOrigin:n});this.editTool.onSkew(h),this.emitEvent(h)}group(t){return this.multiple&&(this.target=mt.group(this.list,this.element,t),this.emitGroupEvent(_t.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(_t.BEFORE_UNGROUP,t))),this.target=mt.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(_t.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(_t.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(_t.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!y.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new _t(t,{editTarget:e});this.emitEvent(i),e.emitEvent(i)}openInnerEditor(t){if(t&&(this.target=t),this.single){const t=this.element,e=t.editInner;e&&wt.list[e]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[e]||wt.get(e,this),this.innerEditor.editTarget=t,this.emitInnerEvent(bt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(bt.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(bt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(bt.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,o=new bt(t,{editTarget:i,innerEditor:e});this.emitEvent(o),i.emitEvent(o)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(mt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(mt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(L.START,this.update,this),t.on_([M.HOLD,M.UP],(t=>{rt(this,t)})),t.on_(M.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())}}S([B((function(t,e){t.emitEvent(new P(P.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],kt.prototype,"hoverTarget",void 0),S([B((function(t,e){const{target:i}=t;i?t.leafList=i instanceof l?i:new l(i):t.leafList.reset(),t.emitEvent(new P(P.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:i}=t,{x:o,y:s,width:n,height:r}=(new a).setListWithFn(i.list,(t=>t.worldBoxBounds)),h=e.parent=i.list[0].leafer.zoomLayer,{scaleX:l,scaleY:d,e:c,f:g}=h.__world;e.reset({x:(o-c)/l,y:(s-g)/d,width:n/l,height:r/d})}(t),ht(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],kt.prototype,"target",void 0);class xt{static registerInnerEditor(){wt.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new n,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let Ot=class extends xt{static registerEditTool(){wt.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:h}=n;r.lockLayout(),h.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:h}=n;r.lockLayout(),h.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:h,rotation:a,skewX:l,skewY:d,width:c,height:g}=o.getLayoutBounds("box",t,!0);e.set({x:s,y:n,scaleX:r,scaleY:h,rotation:a,skewX:l,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};Ot=S([yt()],Ot);const{left:Mt,right:St}=g,{move:Tt,copy:Pt}=d;let Vt=class extends Ot{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:o,around:s}=t,n=t.target,r=i===Mt;if(n.pathInputed){const{path:t}=n.__,{from:i,to:h}=this.getFromToByPath(t);this.dragPoint(i,h,r,s,this.getInnerMove(n,e,o)),t[1]=i.x,t[2]=i.y,t[4]=h.x,t[5]=h.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:h}=this.getFromToByPoints(t);this.dragPoint(i,h,r,s,this.getInnerMove(n,e,o)),t[0]=i.x,t[1]=i.y,t[2]=h.x,t[3]=h.y,n.points=t}else{const t=w(),{toPoint:i}=n;n.rotation=0,this.dragPoint(t,i,r,s,this.getInnerMove(n,e,o)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(i,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(i,null,null,!0),n.toPoint=i}}getInnerMove(t,e,i){const 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?(Tt(t,n,r),o&&Tt(e,-n,-r)):(o&&Tt(t,-n,-r),Tt(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,h;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:h}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(h,h,!1,t),s.pen.clearPath().moveTo(i.x,i.y).lineTo(h.x,h.y),Pt(o[7],i),Pt(e[7],i),Pt(o[3],h),Pt(e[3],h)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),h=t===Mt||t===St,o[t].visible=h,e[t].visible=!r&&h}};Vt=S([yt()],Vt),E.editor=function(t){return new kt(t)},o.setEditConfig=function(t){e(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},o.setEditOuter=function(t){e(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},o.setEditInner=function(t){e(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})};export{ct as EditBox,st as EditDataHelper,lt as EditPoint,j as EditSelect,X as EditSelectHelper,Ot as EditTool,wt as EditToolCreator,kt as Editor,P as EditorEvent,_t as EditorGroupEvent,mt as EditorHelper,V as EditorMoveEvent,I as EditorRotateEvent,H as EditorScaleEvent,C as EditorSkewEvent,xt as InnerEditor,bt as InnerEditorEvent,Vt as LineEditTool,z as SelectArea,W as Stroker,yt as registerEditTool,Lt as registerInnerEditor};
package/dist/editor.js CHANGED
@@ -1690,6 +1690,7 @@ ${filterStyle}
1690
1690
  exports.EditToolCreator = EditToolCreator;
1691
1691
  exports.Editor = Editor;
1692
1692
  exports.EditorEvent = EditorEvent;
1693
+ exports.EditorGroupEvent = EditorGroupEvent;
1693
1694
  exports.EditorHelper = EditorHelper;
1694
1695
  exports.EditorMoveEvent = EditorMoveEvent;
1695
1696
  exports.EditorRotateEvent = EditorRotateEvent;
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer-in/resize"),e=require("@leafer-ui/draw"),i=require("@leafer-ui/core");function o(t,e,i,o){var s,r=arguments.length,n=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,o);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(n=(r<3?s(n):r>3?s(e,i,n):s(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n}function s(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class r extends e.Event{get list(){return s(this.value)}get oldList(){return s(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}r.SELECT="editor.select",r.HOVER="editor.hover";class n extends r{constructor(t,e){super(t,e)}}n.MOVE="editor.move";class a extends r{constructor(t,e){super(t,e)}}a.SCALE="editor.scale";class l extends r{constructor(t,e){super(t,e)}}l.ROTATE="editor.rotate";class h extends r{constructor(t,e){super(t,e)}}function d(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 c=e.MatrixHelper.get(),{abs:g}=Math,{copy:u,scale:p}=e.MatrixHelper;class f 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:r,strokeWidth:n,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=g(s.__world.scaleX),l=g(s.__world.scaleY);if(o!==l){u(c,s.__world),p(c,1/o,1/l),t.setWorld(c,i.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:e,y:r,width:a,height:h}=s.__layout.boxBounds;t.rect(e*o,r*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=n/g(s.__world.scaleX);r&&("string"==typeof r?e.Paint.stroke(r,this,t):e.Paint.strokes(r,this,t)),a&&("string"==typeof a?e.Paint.fill(a,this,t):e.Paint.fills(a,this,t))}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}o([d((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],f.prototype,"target",void 0);class v 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:m,Yes:E,NoAndSkip:L,YesAndSkip:y}=e.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?y:L;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?y:m;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return E}return m}return t.isBranch?L:m}},{findOne:b}=w;class x 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 f,this.targetStroker=new f,this.bounds=new e.Bounds,this.selectArea=new v,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:r}=t.getInner(this);this.bounds.set(s,r),this.selectArea.setStyle({visible:!0,stroke:i,x:s,y:r},o),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:i}=this,o=t.getInnerTotal(this),s=this.bounds.clone().unsign(),r=new e.LeafList(i.app.find(w.findBounds,s));if(this.bounds.width=o.x,this.bounds.height=o.y,this.selectArea.setBounds(s.get()),r.length){const t=[];this.originList.forEach((e=>{r.has(e)||t.push(e)})),r.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&&!b(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const i={exclude:new e.LeafList(this.editor.editBox.rect)};return b(t.target.leafer.interaction.findPath(t,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):b(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_(r.HOVER,this.onHover,this),t.on_(r.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:k,top:_,topRight:M,right:O,bottomRight:T,bottom:S,bottomLeft:P,left:H}=e.Direction9,{toPoint:V}=e.AroundHelper,I={getScaleData(t,e,i,o,s){let r,n={},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 _:l=c,r="bottom";break;case O:a=g,r="left";break;case S:l=u,r="top";break;case H:a=p,r="right";break;case k:l=c,a=p,r="bottom-right";break;case M:l=c,a=g,r="bottom-left";break;case T:l=u,a=g,r="top-left";break;case P:l=u,a=p,r="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 V(s||r,t,n),{origin:n,scaleX:a,scaleY:l,direction:e,lockRatio:o,around:s}},getRotateData(t,i,o,s,r){let n,a={};switch(i){case k:n="bottom-right";break;case M:n="bottom-left";break;case T:n="top-left";break;case P:n="top-right";break;default:n="center"}return V(r||n,t,a),{origin:a,rotation:e.PointHelper.getRotation(s,a,o)}},getSkewData(t,i,o,s){let r,n,a={},l=0,h=0;switch(i){case _:n={x:.5,y:0},r="bottom",l=1;break;case S:n={x:.5,y:1},r="top",l=1;break;case H:n={x:0,y:.5},r="right",h=1;break;case O:n={x:1,y:.5},r="left",h=1}const{x:d,y:c,width:g,height:u}=t;n.x=d+n.x*g,n.y=c+n.y*u,V(s||r,t,a);const p=e.PointHelper.getRotation(n,a,{x:n.x+(l?o.x:0),y:n.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 H:t=O;break;case k:t=M;break;case P:t=T;break;case O:t=H;break;case M:t=k;break;case T:t=P}if(i)switch(t){case _:t=S;break;case k:t=P;break;case M:t=T;break;case S:t=_;break;case P:t=k;break;case T:t=M}return t}},C={};function D(t,i){const{editBox:o}=t,s=o.enterPoint;if(!s||!t.editing||!o.visible)return;if("circle"===s.name)return;let{rotation:r}=o;const{resizeCursor:n,rotateCursor:a,skewCursor:l,resizeable:h,rotateable:d,skewable:c}=t.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?n:a;r+=45*(I.getFlipDirection(s.direction,u,p)+1),r=2*Math.round(e.MathHelper.formatRotation(r,!0)/2);const{url:m,x:E,y:L}=v,y=m+r;C[y]?s.cursor=C[y]:C[y]=s.cursor={url:R(m,r),x:E,y:L}}function B(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function R(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class A extends e.Box{}const Z=["top","right","bottom","left"];class G 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 A({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.rect.syncEventer=t,this.__listenEvents()}create(){let t,e,i;const{view:o,resizePoints:s,rotatePoints:r,resizeLines:n,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 A({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),r.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new A({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",o)),i=new A({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);h.add(l),this.listenPointEvents(l,"rotate",2),o.addMany(...r,a,h,...n,...s),this.add(o)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:o,circle:s,resizePoints:r}=this,{stroke:n,strokeWidth:a,moveable:l}=t,h=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=r[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:n,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}update(t){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:i}=this.editor,{width:o,height:s}=t,{rect:r,circle:n,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,E,L={};for(let r=0;r<8;r++)e.AroundHelper.toPoint(e.AroundHelper.directionData[r],t,L),m=a[r],v=l[r],E=h[Math.floor(r/2)],m.set(L),v.set(L),E.set(L),m.visible=E.visible=f&&!(!c&&!g),v.visible=f&&g&&c&&!i.rotatePoint,r%2&&(m.visible=v.visible=f&&!!d,(r+1)/2%2?(E.width=o,m.width>o-30&&(m.visible=!1)):(E.height=s,m.rotation=90,m.width>s-30&&(m.visible=!1)));n.visible=f&&g&&!!i.rotatePoint,r.path&&(r.path=null),r.set(Object.assign(Object.assign({},t),{visible:!0}));const y=f&&(n.visible||this.buttons.children.length>1);this.buttons.visible=y,y&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:o,buttonsMargin:s,middlePoint:r}=this.editor.mergeConfig,{flippedX:n,flippedY:a}=this;let l=Z.indexOf(i);(l%2&&n||(l+1)%2&&a)&&o&&(l=(l+2)%4);const h=o?I.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?(r?d.width:0)+t.boxBounds.width:(r?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=n?-1:1,t.scaleY=a?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:o,pointSize:s,pointRadius:r}=this.editor.mergeConfig,n={fill:o,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:s,height:s,cornerRadius:r};return t?Object.assign(n,t):n}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),D(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,D(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(r.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.ZoomEvent.BEFORE_ZOOM,e.onScale,e,!0),t.on_(i.RotateEvent.BEFORE_ROTATE,e.onRotate,e,!0),t.on_(i.PointerEvent.ENTER,(()=>B(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 W='\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"/>',z={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${W}\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${W}\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${W}\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 U=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),F=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Y={group(t,i,o){t.sort(F);const{app:s,parent:r}=t[0];let n;n=o&&o.add?o:new e.Group(o),r.addAt(n,r.children.indexOf(t[0])),t.sort(U);const a=new e.Matrix(i.worldTransform);return a.divideParent(r.worldTransform),n.setTransform(a),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children: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(U),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(F),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},X=e.Debug.get("EditToolCreator");function K(){return t=>{N.register(t)}}const j=K,N={list:{},register(t){const{tag:e}=t.prototype;q[e]?X.repeat(e):q[e]=t},get:(t,e)=>new q[t](e)},{list:q}=N;class $ extends r{constructor(t,e){super(t,e)}}$.BEFORE_OPEN="innerEditor.before_open",$.OPEN="innerEditor.open",$.BEFORE_CLOSE="innerEditor.before_close",$.CLOSE="innerEditor.close";class J extends r{constructor(t,e){super(t,e)}}J.GROUP="editor.group",J.BEFORE_UNGROUP="editor.before_ungroup",J.UNGROUP="editor.ungroup",J.OPEN="editor.open_group",J.CLOSE="editor.close_group";class Q 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=z,this.mergeConfig=z,this.leafList=new e.LeafList,this.openedGroupList=new e.LeafList,this.simulateTarget=new e.Rect({visible:!1}),this.editBox=new G(this),this.editToolList={},this.selector=new x(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]||N.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;if(t instanceof i.ZoomEvent)"zoom"===this.mergeConfig.resizeable&&(t.stop(),this.scaleOf(e.getInnerPoint(t),t.scale,t.scale));else{const{direction:i}=t.current;let{around:o,lockRatio:s}=this.mergeConfig;(t.shiftKey||e.lockRatio)&&(s=!0);const r=I.getScaleData(e.boxBounds,i,t.getInnerMove(e),s,I.getAround(o,t.altKey));this.editTool.onScaleWithDrag?(r.drag=t,this.scaleWithDrag(r)):this.scaleOf(r.origin,r.scaleX,r.scaleY)}}onRotate(t){const{skewable:o,around:s,rotateGap:r}=this.mergeConfig,{direction:n,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){if("rotate"!==this.mergeConfig.rotateable)return;t.stop(),d=t.rotation,h=l.getInnerPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=I.getRotateData(l.boxBounds,n,t.getInner(l),l.getInnerPoint(e),t.shiftKey?null:s||"center");d=i.rotation,h=i.origin}d=e.MathHelper.getGapRotation(d,r,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:r}=I.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),I.getAround(i,t.altKey));(s||r)&&this.skewOf(o,s,r)}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 n(n.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){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:e}=this,i=e.getWorldPoint(t.origin),o=new a(a.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){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:r}=this,n=r.getWorldPoint(e.LeafHelper.getInnerOrigin(r,t));let l;if(this.multiple){const s=new e.Matrix(r.worldTransform);r.scaleOf(t,i,o),l=new e.Matrix(r.worldTransform).divide(s)}const h=new a(a.SCALE,{target:r,editor:this,worldOrigin:n,scaleX:i,scaleY:o,transform:l});this.editTool.onScale(h),this.emitEvent(h)}rotateOf(t,i){if(!this.mergeConfig.rotateable||this.element.locked)return;const{element:o}=this,s=o.getWorldPoint(e.LeafHelper.getInnerOrigin(o,t));let r;if(this.multiple){const s=new e.Matrix(o.worldTransform);o.rotateOf(t,i),r=new e.Matrix(o.worldTransform).divide(s)}const n=new l(l.ROTATE,{target:o,editor:this,worldOrigin:s,rotation:i,transform:r});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,i,o=0,s){if(!this.mergeConfig.skewable||this.element.locked)return;const{element:r}=this,n=r.getWorldPoint(e.LeafHelper.getInnerOrigin(r,t));let a;if(this.multiple){const s=new e.Matrix(r.worldTransform);r.skewOf(t,i,o),a=new e.Matrix(r.worldTransform).divide(s)}const l=new h(h.SKEW,{target:r,editor:this,skewX:i,skewY:o,transform:a,worldOrigin:n});this.editTool.onSkew(l),this.emitEvent(l)}group(t){return this.multiple&&(this.target=Y.group(this.list,this.element,t),this.emitGroupEvent(J.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(J.BEFORE_UNGROUP,t))),this.target=Y.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(J.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(J.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(J.CLOSE,t)}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)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new J(t,{editTarget:e});this.emitEvent(i),e.emitEvent(i)}openInnerEditor(t){if(t&&(this.target=t),this.single){const t=this.element,e=t.editInner;e&&N.list[e]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[e]||N.get(e,this),this.innerEditor.editTarget=t,this.emitInnerEvent($.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent($.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent($.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent($.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,o=new $(t,{editTarget:i,innerEditor:e});this.emitEvent(o),i.emitEvent(o)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(Y.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Y.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=>{D(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())}}o([d((function(t,e){t.emitEvent(new r(r.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Q.prototype,"hoverTarget",void 0),o([d((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 r(r.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:r,width:n,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:(r-g)/d,width:n/h,height:a/d})}(t),B(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],Q.prototype,"target",void 0);class tt{static registerInnerEditor(){N.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)}}exports.EditTool=class extends tt{static registerEditTool(){N.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:o}=t,{app:s,list:r}=o;s.lockLayout(),r.forEach((t=>{t.moveWorld(e,i)})),s.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:o,worldOrigin:s,editor:r}=t,{app:n,list:a}=r;n.lockLayout(),a.forEach((t=>{const n="scale"!==r.getEditSize(t);o?t.transformWorld(o,n):t.scaleOfWorld(s,e,i,n)})),n.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:o,editor:s}=t,{app:r,list:n}=s;r.lockLayout(),n.forEach((t=>{const r="scale"!==s.getEditSize(t);i?t.transformWorld(i,r):t.rotateOfWorld(o,e)})),r.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:o,worldOrigin:s,editor:r}=t,{app:n,list:a}=r;n.lockLayout(),a.forEach((t=>{const n="scale"!==r.getEditSize(t);o?t.transformWorld(o,n):t.skewOfWorld(s,e,i,n)})),n.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:r,scaleX:n,scaleY:a,rotation:l,skewX:h,skewY:d,width:c,height:g}=o.getLayoutBounds("box",t,!0);e.set({x:s,y:r,scaleX:n,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=o([K()],exports.EditTool);const{left:et,right:it}=e.Direction9,{move:ot,copy:st}=e.PointHelper;exports.LineEditTool=class extends exports.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:i,direction:o,lockRatio:s,around:r}=t,n=t.target,a=o===et;if(n.pathInputed){const{path:t}=n.__,{from:e,to:o}=this.getFromToByPath(t);this.dragPoint(e,o,a,r,this.getInnerMove(n,i,s)),t[1]=e.x,t[2]=e.y,t[4]=o.x,t[5]=o.y,n.path=t}else if(n.points){const{points:t}=n,{from:e,to:o}=this.getFromToByPoints(t);this.dragPoint(e,o,a,r,this.getInnerMove(n,i,s)),t[0]=e.x,t[1]=e.y,t[2]=o.x,t[3]=o.y,n.points=t}else{const t=e.getPointData(),{toPoint:o}=n;n.rotation=0,this.dragPoint(t,o,a,r,this.getInnerMove(n,i,s)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(o,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(o,null,null,!0),n.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:r,y:n}=s;i?(ot(t,r,n),o&&ot(e,-r,-n)):(o&&ot(t,-r,-n),ot(e,r,n))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:o,rect:s}=t,r=this.editor.element;let n,a;if(r.pathInputed?n=this.getFromToByPath(r.__.path):r.points&&(n=this.getFromToByPoints(r.__.points)),n){const{from:i,to:a}=n;r.innerToWorld(i,i,!1,t),r.innerToWorld(a,a,!1,t),s.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),st(o[7],i),st(e[7],i),st(o[3],a),st(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===et||t===it,o[t].visible=a,e[t].visible=!n&&a}},exports.LineEditTool=o([K()],exports.LineEditTool),e.Creator.editor=function(t){return new Q(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)}})},exports.EditBox=G,exports.EditDataHelper=I,exports.EditPoint=A,exports.EditSelect=x,exports.EditSelectHelper=w,exports.EditToolCreator=N,exports.Editor=Q,exports.EditorEvent=r,exports.EditorHelper=Y,exports.EditorMoveEvent=n,exports.EditorRotateEvent=l,exports.EditorScaleEvent=a,exports.EditorSkewEvent=h,exports.InnerEditor=tt,exports.InnerEditorEvent=$,exports.SelectArea=v,exports.Stroker=f,exports.registerEditTool=K,exports.registerInnerEditor=j,Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
1
+ "use strict";var t=require("@leafer-in/resize"),e=require("@leafer-ui/draw"),i=require("@leafer-ui/core");function o(t,e,i,o){var s,r=arguments.length,n=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,o);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(n=(r<3?s(n):r>3?s(e,i,n):s(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n}function s(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class r extends e.Event{get list(){return s(this.value)}get oldList(){return s(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}r.SELECT="editor.select",r.HOVER="editor.hover";class n extends r{constructor(t,e){super(t,e)}}n.MOVE="editor.move";class a extends r{constructor(t,e){super(t,e)}}a.SCALE="editor.scale";class l extends r{constructor(t,e){super(t,e)}}l.ROTATE="editor.rotate";class h extends r{constructor(t,e){super(t,e)}}function d(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 c=e.MatrixHelper.get(),{abs:g}=Math,{copy:u,scale:p}=e.MatrixHelper;class f 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:r,strokeWidth:n,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=g(s.__world.scaleX),l=g(s.__world.scaleY);if(o!==l){u(c,s.__world),p(c,1/o,1/l),t.setWorld(c,i.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:e,y:r,width:a,height:h}=s.__layout.boxBounds;t.rect(e*o,r*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=n/g(s.__world.scaleX);r&&("string"==typeof r?e.Paint.stroke(r,this,t):e.Paint.strokes(r,this,t)),a&&("string"==typeof a?e.Paint.fill(a,this,t):e.Paint.fills(a,this,t))}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}o([d((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],f.prototype,"target",void 0);class v 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:m,Yes:E,NoAndSkip:L,YesAndSkip:y}=e.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?y:L;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?y:m;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return E}return m}return t.isBranch?L:m}},{findOne:b}=w;class x 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 f,this.targetStroker=new f,this.bounds=new e.Bounds,this.selectArea=new v,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:r}=t.getInner(this);this.bounds.set(s,r),this.selectArea.setStyle({visible:!0,stroke:i,x:s,y:r},o),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:i}=this,o=t.getInnerTotal(this),s=this.bounds.clone().unsign(),r=new e.LeafList(i.app.find(w.findBounds,s));if(this.bounds.width=o.x,this.bounds.height=o.y,this.selectArea.setBounds(s.get()),r.length){const t=[];this.originList.forEach((e=>{r.has(e)||t.push(e)})),r.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&&!b(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const i={exclude:new e.LeafList(this.editor.editBox.rect)};return b(t.target.leafer.interaction.findPath(t,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):b(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_(r.HOVER,this.onHover,this),t.on_(r.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:k,top:_,topRight:M,right:O,bottomRight:T,bottom:S,bottomLeft:P,left:H}=e.Direction9,{toPoint:V}=e.AroundHelper,I={getScaleData(t,e,i,o,s){let r,n={},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 _:l=c,r="bottom";break;case O:a=g,r="left";break;case S:l=u,r="top";break;case H:a=p,r="right";break;case k:l=c,a=p,r="bottom-right";break;case M:l=c,a=g,r="bottom-left";break;case T:l=u,a=g,r="top-left";break;case P:l=u,a=p,r="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 V(s||r,t,n),{origin:n,scaleX:a,scaleY:l,direction:e,lockRatio:o,around:s}},getRotateData(t,i,o,s,r){let n,a={};switch(i){case k:n="bottom-right";break;case M:n="bottom-left";break;case T:n="top-left";break;case P:n="top-right";break;default:n="center"}return V(r||n,t,a),{origin:a,rotation:e.PointHelper.getRotation(s,a,o)}},getSkewData(t,i,o,s){let r,n,a={},l=0,h=0;switch(i){case _:n={x:.5,y:0},r="bottom",l=1;break;case S:n={x:.5,y:1},r="top",l=1;break;case H:n={x:0,y:.5},r="right",h=1;break;case O:n={x:1,y:.5},r="left",h=1}const{x:d,y:c,width:g,height:u}=t;n.x=d+n.x*g,n.y=c+n.y*u,V(s||r,t,a);const p=e.PointHelper.getRotation(n,a,{x:n.x+(l?o.x:0),y:n.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 H:t=O;break;case k:t=M;break;case P:t=T;break;case O:t=H;break;case M:t=k;break;case T:t=P}if(i)switch(t){case _:t=S;break;case k:t=P;break;case M:t=T;break;case S:t=_;break;case P:t=k;break;case T:t=M}return t}},C={};function D(t,i){const{editBox:o}=t,s=o.enterPoint;if(!s||!t.editing||!o.visible)return;if("circle"===s.name)return;let{rotation:r}=o;const{resizeCursor:n,rotateCursor:a,skewCursor:l,resizeable:h,rotateable:d,skewable:c}=t.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?n:a;r+=45*(I.getFlipDirection(s.direction,u,p)+1),r=2*Math.round(e.MathHelper.formatRotation(r,!0)/2);const{url:m,x:E,y:L}=v,y=m+r;C[y]?s.cursor=C[y]:C[y]=s.cursor={url:R(m,r),x:E,y:L}}function B(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function R(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class A extends e.Box{}const Z=["top","right","bottom","left"];class G 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 A({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.rect.syncEventer=t,this.__listenEvents()}create(){let t,e,i;const{view:o,resizePoints:s,rotatePoints:r,resizeLines:n,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 A({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),r.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new A({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",o)),i=new A({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);h.add(l),this.listenPointEvents(l,"rotate",2),o.addMany(...r,a,h,...n,...s),this.add(o)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:o,circle:s,resizePoints:r}=this,{stroke:n,strokeWidth:a,moveable:l}=t,h=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=r[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:n,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}update(t){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:i}=this.editor,{width:o,height:s}=t,{rect:r,circle:n,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,E,L={};for(let r=0;r<8;r++)e.AroundHelper.toPoint(e.AroundHelper.directionData[r],t,L),m=a[r],v=l[r],E=h[Math.floor(r/2)],m.set(L),v.set(L),E.set(L),m.visible=E.visible=f&&!(!c&&!g),v.visible=f&&g&&c&&!i.rotatePoint,r%2&&(m.visible=v.visible=f&&!!d,(r+1)/2%2?(E.width=o,m.width>o-30&&(m.visible=!1)):(E.height=s,m.rotation=90,m.width>s-30&&(m.visible=!1)));n.visible=f&&g&&!!i.rotatePoint,r.path&&(r.path=null),r.set(Object.assign(Object.assign({},t),{visible:!0}));const y=f&&(n.visible||this.buttons.children.length>1);this.buttons.visible=y,y&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:o,buttonsMargin:s,middlePoint:r}=this.editor.mergeConfig,{flippedX:n,flippedY:a}=this;let l=Z.indexOf(i);(l%2&&n||(l+1)%2&&a)&&o&&(l=(l+2)%4);const h=o?I.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?(r?d.width:0)+t.boxBounds.width:(r?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=n?-1:1,t.scaleY=a?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:o,pointSize:s,pointRadius:r}=this.editor.mergeConfig,n={fill:o,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:s,height:s,cornerRadius:r};return t?Object.assign(n,t):n}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),D(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,D(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(r.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.ZoomEvent.BEFORE_ZOOM,e.onScale,e,!0),t.on_(i.RotateEvent.BEFORE_ROTATE,e.onRotate,e,!0),t.on_(i.PointerEvent.ENTER,(()=>B(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 W='\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"/>',z={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${W}\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${W}\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${W}\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 U=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),F=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Y={group(t,i,o){t.sort(F);const{app:s,parent:r}=t[0];let n;n=o&&o.add?o:new e.Group(o),r.addAt(n,r.children.indexOf(t[0])),t.sort(U);const a=new e.Matrix(i.worldTransform);return a.divideParent(r.worldTransform),n.setTransform(a),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children: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(U),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(F),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},X=e.Debug.get("EditToolCreator");function K(){return t=>{N.register(t)}}const j=K,N={list:{},register(t){const{tag:e}=t.prototype;q[e]?X.repeat(e):q[e]=t},get:(t,e)=>new q[t](e)},{list:q}=N;class $ extends r{constructor(t,e){super(t,e)}}$.BEFORE_OPEN="innerEditor.before_open",$.OPEN="innerEditor.open",$.BEFORE_CLOSE="innerEditor.before_close",$.CLOSE="innerEditor.close";class J extends r{constructor(t,e){super(t,e)}}J.GROUP="editor.group",J.BEFORE_UNGROUP="editor.before_ungroup",J.UNGROUP="editor.ungroup",J.OPEN="editor.open_group",J.CLOSE="editor.close_group";class Q 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=z,this.mergeConfig=z,this.leafList=new e.LeafList,this.openedGroupList=new e.LeafList,this.simulateTarget=new e.Rect({visible:!1}),this.editBox=new G(this),this.editToolList={},this.selector=new x(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]||N.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;if(t instanceof i.ZoomEvent)"zoom"===this.mergeConfig.resizeable&&(t.stop(),this.scaleOf(e.getInnerPoint(t),t.scale,t.scale));else{const{direction:i}=t.current;let{around:o,lockRatio:s}=this.mergeConfig;(t.shiftKey||e.lockRatio)&&(s=!0);const r=I.getScaleData(e.boxBounds,i,t.getInnerMove(e),s,I.getAround(o,t.altKey));this.editTool.onScaleWithDrag?(r.drag=t,this.scaleWithDrag(r)):this.scaleOf(r.origin,r.scaleX,r.scaleY)}}onRotate(t){const{skewable:o,around:s,rotateGap:r}=this.mergeConfig,{direction:n,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){if("rotate"!==this.mergeConfig.rotateable)return;t.stop(),d=t.rotation,h=l.getInnerPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=I.getRotateData(l.boxBounds,n,t.getInner(l),l.getInnerPoint(e),t.shiftKey?null:s||"center");d=i.rotation,h=i.origin}d=e.MathHelper.getGapRotation(d,r,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:r}=I.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),I.getAround(i,t.altKey));(s||r)&&this.skewOf(o,s,r)}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 n(n.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){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:e}=this,i=e.getWorldPoint(t.origin),o=new a(a.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){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:r}=this,n=r.getWorldPoint(e.LeafHelper.getInnerOrigin(r,t));let l;if(this.multiple){const s=new e.Matrix(r.worldTransform);r.scaleOf(t,i,o),l=new e.Matrix(r.worldTransform).divide(s)}const h=new a(a.SCALE,{target:r,editor:this,worldOrigin:n,scaleX:i,scaleY:o,transform:l});this.editTool.onScale(h),this.emitEvent(h)}rotateOf(t,i){if(!this.mergeConfig.rotateable||this.element.locked)return;const{element:o}=this,s=o.getWorldPoint(e.LeafHelper.getInnerOrigin(o,t));let r;if(this.multiple){const s=new e.Matrix(o.worldTransform);o.rotateOf(t,i),r=new e.Matrix(o.worldTransform).divide(s)}const n=new l(l.ROTATE,{target:o,editor:this,worldOrigin:s,rotation:i,transform:r});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,i,o=0,s){if(!this.mergeConfig.skewable||this.element.locked)return;const{element:r}=this,n=r.getWorldPoint(e.LeafHelper.getInnerOrigin(r,t));let a;if(this.multiple){const s=new e.Matrix(r.worldTransform);r.skewOf(t,i,o),a=new e.Matrix(r.worldTransform).divide(s)}const l=new h(h.SKEW,{target:r,editor:this,skewX:i,skewY:o,transform:a,worldOrigin:n});this.editTool.onSkew(l),this.emitEvent(l)}group(t){return this.multiple&&(this.target=Y.group(this.list,this.element,t),this.emitGroupEvent(J.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(J.BEFORE_UNGROUP,t))),this.target=Y.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(J.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(J.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(J.CLOSE,t)}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)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new J(t,{editTarget:e});this.emitEvent(i),e.emitEvent(i)}openInnerEditor(t){if(t&&(this.target=t),this.single){const t=this.element,e=t.editInner;e&&N.list[e]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[e]||N.get(e,this),this.innerEditor.editTarget=t,this.emitInnerEvent($.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent($.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent($.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent($.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,o=new $(t,{editTarget:i,innerEditor:e});this.emitEvent(o),i.emitEvent(o)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(Y.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Y.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=>{D(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())}}o([d((function(t,e){t.emitEvent(new r(r.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Q.prototype,"hoverTarget",void 0),o([d((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 r(r.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:r,width:n,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:(r-g)/d,width:n/h,height:a/d})}(t),B(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],Q.prototype,"target",void 0);class tt{static registerInnerEditor(){N.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)}}exports.EditTool=class extends tt{static registerEditTool(){N.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:o}=t,{app:s,list:r}=o;s.lockLayout(),r.forEach((t=>{t.moveWorld(e,i)})),s.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:o,worldOrigin:s,editor:r}=t,{app:n,list:a}=r;n.lockLayout(),a.forEach((t=>{const n="scale"!==r.getEditSize(t);o?t.transformWorld(o,n):t.scaleOfWorld(s,e,i,n)})),n.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:o,editor:s}=t,{app:r,list:n}=s;r.lockLayout(),n.forEach((t=>{const r="scale"!==s.getEditSize(t);i?t.transformWorld(i,r):t.rotateOfWorld(o,e)})),r.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:o,worldOrigin:s,editor:r}=t,{app:n,list:a}=r;n.lockLayout(),a.forEach((t=>{const n="scale"!==r.getEditSize(t);o?t.transformWorld(o,n):t.skewOfWorld(s,e,i,n)})),n.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:r,scaleX:n,scaleY:a,rotation:l,skewX:h,skewY:d,width:c,height:g}=o.getLayoutBounds("box",t,!0);e.set({x:s,y:r,scaleX:n,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=o([K()],exports.EditTool);const{left:et,right:it}=e.Direction9,{move:ot,copy:st}=e.PointHelper;exports.LineEditTool=class extends exports.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:i,direction:o,lockRatio:s,around:r}=t,n=t.target,a=o===et;if(n.pathInputed){const{path:t}=n.__,{from:e,to:o}=this.getFromToByPath(t);this.dragPoint(e,o,a,r,this.getInnerMove(n,i,s)),t[1]=e.x,t[2]=e.y,t[4]=o.x,t[5]=o.y,n.path=t}else if(n.points){const{points:t}=n,{from:e,to:o}=this.getFromToByPoints(t);this.dragPoint(e,o,a,r,this.getInnerMove(n,i,s)),t[0]=e.x,t[1]=e.y,t[2]=o.x,t[3]=o.y,n.points=t}else{const t=e.getPointData(),{toPoint:o}=n;n.rotation=0,this.dragPoint(t,o,a,r,this.getInnerMove(n,i,s)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(o,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(o,null,null,!0),n.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:r,y:n}=s;i?(ot(t,r,n),o&&ot(e,-r,-n)):(o&&ot(t,-r,-n),ot(e,r,n))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:o,rect:s}=t,r=this.editor.element;let n,a;if(r.pathInputed?n=this.getFromToByPath(r.__.path):r.points&&(n=this.getFromToByPoints(r.__.points)),n){const{from:i,to:a}=n;r.innerToWorld(i,i,!1,t),r.innerToWorld(a,a,!1,t),s.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),st(o[7],i),st(e[7],i),st(o[3],a),st(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===et||t===it,o[t].visible=a,e[t].visible=!n&&a}},exports.LineEditTool=o([K()],exports.LineEditTool),e.Creator.editor=function(t){return new Q(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)}})},exports.EditBox=G,exports.EditDataHelper=I,exports.EditPoint=A,exports.EditSelect=x,exports.EditSelectHelper=w,exports.EditToolCreator=N,exports.Editor=Q,exports.EditorEvent=r,exports.EditorGroupEvent=J,exports.EditorHelper=Y,exports.EditorMoveEvent=n,exports.EditorRotateEvent=l,exports.EditorScaleEvent=a,exports.EditorSkewEvent=h,exports.InnerEditor=tt,exports.InnerEditorEvent=$,exports.SelectArea=v,exports.Stroker=f,exports.registerEditTool=K,exports.registerInnerEditor=j,Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
@@ -1 +1 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.editor=function(t,e,i,o){"use strict";function s(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 n(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class r extends i.Event{get list(){return n(this.value)}get oldList(){return n(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}r.SELECT="editor.select",r.HOVER="editor.hover";class a extends r{constructor(t,e){super(t,e)}}a.MOVE="editor.move";class l extends r{constructor(t,e){super(t,e)}}l.SCALE="editor.scale";class h extends r{constructor(t,e){super(t,e)}}h.ROTATE="editor.rotate";class d extends r{constructor(t,e){super(t,e)}}function c(t){return(e,o)=>{const s="_"+o;i.defineKey(e,o,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}d.SKEW="editor.skew";const g=i.MatrixHelper.get(),{abs:u}=Math,{copy:f,scale:p}=i.MatrixHelper;class m extends i.UI{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:o}=this;if(o.length){let s;const{stroke:n,strokeWidth:r,fill:a}=this.__,{bounds:l}=e;for(let h=0;h<o.length;h++)if(s=o[h],l&&l.hit(s.__world,e.matrix)){const o=u(s.__world.scaleX),l=u(s.__world.scaleY);if(o!==l){f(g,s.__world),p(g,1/o,1/l),t.setWorld(g,e.matrix),t.beginPath(),this.__.strokeWidth=r;const{x:i,y:n,width:a,height:h}=s.__layout.boxBounds;t.rect(i*o,n*l,a*o,h*l)}else t.setWorld(s.__world,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),this.__.strokeWidth=r/u(s.__world.scaleX);n&&("string"==typeof n?i.Paint.stroke(n,this,t):i.Paint.strokes(n,this,t)),a&&("string"==typeof a?i.Paint.fill(a,this,t):i.Paint.fills(a,this,t))}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}s([c((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],m.prototype,"target",void 0);class v extends i.Group{constructor(t){super(t),this.strokeArea=new i.Rect({strokeAlign:"center"}),this.fillArea=new i.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:E,Yes:L,NoAndSkip:y,YesAndSkip:b}=i.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?b:y;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?b:E;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return L}return E}return t.isBranch?y:E}},{findOne:k}=w;class _ extends i.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 m,this.targetStroker=new m,this.bounds=new i.Bounds,this.selectArea=new v,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:e}=this,o=t.getInnerTotal(this),s=this.bounds.clone().unsign(),n=new i.LeafList(e.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!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list}}onDragEnd(){this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!k(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new i.LeafList(this.editor.editBox.rect)};return k(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):k(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_(r.HOVER,this.onHover,this),t.on_(r.SELECT,this.onSelect,this),e.on_(o.PointerEvent.MOVE,this.onPointerMove,this),e.on_(o.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this),e.on_(o.PointerEvent.TAP,this.onTap,this),e.on_(o.DragEvent.START,this.onDragStart,this),e.on_(o.DragEvent.DRAG,this.onDrag,this),e.on_(o.DragEvent.END,this.onDragEnd,this),e.on_(o.MoveEvent.MOVE,this.onAutoMove,this),e.on_([o.ZoomEvent.ZOOM,o.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:x,top:M,topRight:O,right:T,bottomRight:S,bottom:P,bottomLeft:H,left:I}=i.Direction9,{toPoint:V}=i.AroundHelper,C={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 M:l=c,n="bottom";break;case T:a=g,n="left";break;case P:l=u,n="top";break;case I:a=f,n="right";break;case x:l=c,a=f,n="bottom-right";break;case O:l=c,a=g,n="bottom-left";break;case S:l=u,a=g,n="top-left";break;case H: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 V(s||n,t,r),{origin:r,scaleX:a,scaleY:l,direction:e,lockRatio:o,around:s}},getRotateData(t,e,o,s,n){let r,a={};switch(e){case x:r="bottom-right";break;case O:r="bottom-left";break;case S:r="top-left";break;case H:r="top-right";break;default:r="center"}return V(n||r,t,a),{origin:a,rotation:i.PointHelper.getRotation(s,a,o)}},getSkewData(t,e,o,s){let n,r,a={},l=0,h=0;switch(e){case M:r={x:.5,y:0},n="bottom",l=1;break;case P:r={x:.5,y:1},n="top",l=1;break;case I:r={x:0,y:.5},n="right",h=1;break;case T: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,V(s||n,t,a);const f=i.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 I:t=T;break;case x:t=O;break;case H:t=S;break;case T:t=I;break;case O:t=x;break;case S:t=H}if(i)switch(t){case M:t=P;break;case x:t=H;break;case O:t=S;break;case P:t=M;break;case H:t=x;break;case S:t=O}return t}},D={};function B(t,e){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&&(e.metaKey||e.ctrlKey||!h)&&(p=!1);const m=c&&!p&&"resize-line"===s.name?l:p?r:a;n+=45*(C.getFlipDirection(s.direction,u,f)+1),n=2*Math.round(i.MathHelper.formatRotation(n,!0)/2);const{url:v,x:E,y:L}=m,y=v+n;D[y]?s.cursor=D[y]:D[y]=s.cursor={url:A(v,n),x:E,y:L}}function R(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function A(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Z extends i.Box{}const G=["top","right","bottom","left"];class W extends i.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 i.Group,this.rect=new i.Box({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Z({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new i.Group({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.rect.syncEventer=t,this.__listenEvents()}create(){let t,e,i;const{view: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 Z({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new Z({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",o)),i=new Z({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);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}update(t){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:e}=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}=e,f="number"==typeof u?u:10,p=!(u&&o<f&&s<f);let m,v,E,L={};for(let n=0;n<8;n++)i.AroundHelper.toPoint(i.AroundHelper.directionData[n],t,L),v=a[n],m=l[n],E=h[Math.floor(n/2)],v.set(L),m.set(L),E.set(L),v.visible=E.visible=p&&!(!c&&!g),m.visible=p&&g&&c&&!e.rotatePoint,n%2&&(v.visible=m.visible=p&&!!d,(n+1)/2%2?(E.width=o,v.width>o-30&&(v.visible=!1)):(E.height=s,v.rotation=90,v.width>s-30&&(v.visible=!1)));r.visible=p&&g&&!!e.rotatePoint,n.path&&(n.path=null),n.set(Object.assign(Object.assign({},t),{visible:!0}));const y=p&&(r.visible||this.buttons.children.length>1);this.buttons.visible=y,y&&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=G.indexOf(i);(l%2&&r||(l+1)%2&&a)&&o&&(l=(l+2)%4);const h=o?C.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),B(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(o.DragEvent.START,this.onDragStart,this),t.on_(o.DragEvent.DRAG,this.onDrag,this),t.on_(o.DragEvent.END,this.onDragEnd,this),t.on_(o.PointerEvent.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(o.PointerEvent.ENTER,(e=>{this.enterPoint=t,B(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(r.SELECT,this.onSelect,this),t.on_(o.DragEvent.START,this.onDragStart,this),t.on_(o.DragEvent.DRAG,e.onMove,e),t.on_(o.DragEvent.END,this.onDragEnd,this),t.on_(o.ZoomEvent.BEFORE_ZOOM,e.onScale,e,!0),t.on_(o.RotateEvent.BEFORE_ROTATE,e.onRotate,e,!0),t.on_(o.PointerEvent.ENTER,(()=>R(e))),t.on_(o.PointerEvent.DOUBLE_TAP,this.onDoubleTap,this),t.on_(o.PointerEvent.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const z='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',U={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${z}\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${z}\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${z}\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 F=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Y=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),X={group(t,e,o){t.sort(Y);const{app:s,parent:n}=t[0];let r;r=o&&o.add?o:new i.Group(o),n.addAt(r,n.children.indexOf(t[0])),t.sort(F);const a=new i.Matrix(e.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(F),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Y),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},N=i.Debug.get("EditToolCreator");function K(){return t=>{$.register(t)}}const j=K,$={list:{},register(t){const{tag:e}=t.prototype;q[e]?N.repeat(e):q[e]=t},get:(t,e)=>new q[t](e)},{list:q}=$;class J extends r{constructor(t,e){super(t,e)}}J.BEFORE_OPEN="innerEditor.before_open",J.OPEN="innerEditor.open",J.BEFORE_CLOSE="innerEditor.before_close",J.CLOSE="innerEditor.close";class Q extends r{constructor(t,e){super(t,e)}}Q.GROUP="editor.group",Q.BEFORE_UNGROUP="editor.before_ungroup",Q.UNGROUP="editor.ungroup",Q.OPEN="editor.open_group",Q.CLOSE="editor.close_group";class tt extends i.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,e){super(e),this.config=U,this.mergeConfig=U,this.leafList=new i.LeafList,this.openedGroupList=new i.LeafList,this.simulateTarget=new i.Rect({visible:!1}),this.editBox=new W(this),this.editToolList={},this.selector=new _(this),this.targetEventIds=[],t&&(this.config=i.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]||$.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(o.DragEvent.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this;if(t instanceof o.ZoomEvent)"zoom"===this.mergeConfig.resizeable&&(t.stop(),this.scaleOf(e.getInnerPoint(t),t.scale,t.scale));else{const{direction:i}=t.current;let{around:o,lockRatio:s}=this.mergeConfig;(t.shiftKey||e.lockRatio)&&(s=!0);const n=C.getScaleData(e.boxBounds,i,t.getInnerMove(e),s,C.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:e,around:s,rotateGap:n}=this.mergeConfig,{direction:r,name:a}=t.current;if(e&&"resize-line"===a)return this.onSkew(t);const{element:l}=this;let h,d;if(t instanceof o.RotateEvent){if("rotate"!==this.mergeConfig.rotateable)return;t.stop(),d=t.rotation,h=l.getInnerPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=C.getRotateData(l.boxBounds,r,t.getInner(l),l.getInnerPoint(e),t.shiftKey?null:s||"center");d=i.rotation,h=i.origin}d=i.MathHelper.getGapRotation(d,n,l.rotation),d&&(l.scaleX*l.scaleY<0&&(d=-d),this.rotateOf(h,i.MathHelper.float(d,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:o,skewX:s,skewY:n}=C.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),C.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 a(a.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){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:e}=this,i=e.getWorldPoint(t.origin),o=new l(l.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(o),this.emitEvent(o)}scaleOf(t,e,o=e,s){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:n}=this,r=n.getWorldPoint(i.LeafHelper.getInnerOrigin(n,t));let a;if(this.multiple){const s=new i.Matrix(n.worldTransform);n.scaleOf(t,e,o),a=new i.Matrix(n.worldTransform).divide(s)}const h=new l(l.SCALE,{target:n,editor:this,worldOrigin:r,scaleX:e,scaleY:o,transform:a});this.editTool.onScale(h),this.emitEvent(h)}rotateOf(t,e){if(!this.mergeConfig.rotateable||this.element.locked)return;const{element:o}=this,s=o.getWorldPoint(i.LeafHelper.getInnerOrigin(o,t));let n;if(this.multiple){const s=new i.Matrix(o.worldTransform);o.rotateOf(t,e),n=new i.Matrix(o.worldTransform).divide(s)}const r=new h(h.ROTATE,{target:o,editor:this,worldOrigin:s,rotation:e,transform:n});this.editTool.onRotate(r),this.emitEvent(r)}skewOf(t,e,o=0,s){if(!this.mergeConfig.skewable||this.element.locked)return;const{element:n}=this,r=n.getWorldPoint(i.LeafHelper.getInnerOrigin(n,t));let a;if(this.multiple){const s=new i.Matrix(n.worldTransform);n.skewOf(t,e,o),a=new i.Matrix(n.worldTransform).divide(s)}const l=new d(d.SKEW,{target:n,editor:this,skewX:e,skewY:o,transform:a,worldOrigin:r});this.editTool.onSkew(l),this.emitEvent(l)}group(t){return this.multiple&&(this.target=X.group(this.list,this.element,t),this.emitGroupEvent(Q.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(Q.BEFORE_UNGROUP,t))),this.target=X.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(Q.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Q.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Q.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!i.LeafHelper.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new Q(t,{editTarget:e});this.emitEvent(i),e.emitEvent(i)}openInnerEditor(t){if(t&&(this.target=t),this.single){const t=this.element,e=t.editInner;e&&$.list[e]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[e]||$.get(e,this),this.innerEditor.editTarget=t,this.emitInnerEvent(J.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(J.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(J.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(J.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,o=new J(t,{editTarget:i,innerEditor:e});this.emitEvent(o),i.emitEvent(o)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(X.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(X.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(i.RenderEvent.START,this.update,this),t.on_([o.KeyEvent.HOLD,o.KeyEvent.UP],(t=>{B(this,t)})),t.on_(o.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())}}s([c((function(t,e){t.emitEvent(new r(r.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],tt.prototype,"hoverTarget",void 0),s([c((function(t,e){const{target:o}=t;o?t.leafList=o instanceof i.LeafList?o:new i.LeafList(o):t.leafList.reset(),t.emitEvent(new r(r.SELECT,{editor:t,value:o,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:o}=t,{x:s,y:n,width:r,height:a}=(new i.Bounds).setListWithFn(o.list,(t=>t.worldBoxBounds)),l=e.parent=o.list[0].leafer.zoomLayer,{scaleX:h,scaleY:d,e:c,f:g}=l.__world;e.reset({x:(s-c)/h,y:(n-g)/d,width:r/h,height:a/d})}(t),R(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],tt.prototype,"target",void 0);class et{static registerInnerEditor(){$.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new i.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 et{static registerEditTool(){$.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=s([K()],t.EditTool);const{left:it,right:ot}=i.Direction9,{move:st,copy:nt}=i.PointHelper;return t.LineEditTool=class extends t.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:o,lockRatio:s,around:n}=t,r=t.target,a=o===it;if(r.pathInputed){const{path:t}=r.__,{from:i,to:o}=this.getFromToByPath(t);this.dragPoint(i,o,a,n,this.getInnerMove(r,e,s)),t[1]=i.x,t[2]=i.y,t[4]=o.x,t[5]=o.y,r.path=t}else if(r.points){const{points:t}=r,{from:i,to:o}=this.getFromToByPoints(t);this.dragPoint(i,o,a,n,this.getInnerMove(r,e,s)),t[0]=i.x,t[1]=i.y,t[2]=o.x,t[3]=o.y,r.points=t}else{const t=i.getPointData(),{toPoint:o}=r;r.rotation=0,this.dragPoint(t,o,a,n,this.getInnerMove(r,e,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?(st(t,n,r),o&&st(e,-n,-r)):(o&&st(t,-n,-r),st(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),nt(o[7],i),nt(e[7],i),nt(o[3],a),nt(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===it||t===ot,o[t].visible=a,e[t].visible=!r&&a}},t.LineEditTool=s([K()],t.LineEditTool),i.Creator.editor=function(t){return new tt(t)},i.UI.setEditConfig=function(t){i.defineKey(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},i.UI.setEditOuter=function(t){i.defineKey(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},i.UI.setEditInner=function(t){i.defineKey(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})},t.EditBox=W,t.EditDataHelper=C,t.EditPoint=Z,t.EditSelect=_,t.EditSelectHelper=w,t.EditToolCreator=$,t.Editor=tt,t.EditorEvent=r,t.EditorHelper=X,t.EditorMoveEvent=a,t.EditorRotateEvent=h,t.EditorScaleEvent=l,t.EditorSkewEvent=d,t.InnerEditor=et,t.InnerEditorEvent=J,t.SelectArea=v,t.Stroker=m,t.registerEditTool=K,t.registerInnerEditor=j,Object.keys(e).forEach((function(i){"default"===i||Object.prototype.hasOwnProperty.call(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:function(){return e[i]}})})),t}({},LeaferIN.resize,LeaferUI,LeaferUI);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.editor=function(t,e,i,o){"use strict";function s(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 n(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class r extends i.Event{get list(){return n(this.value)}get oldList(){return n(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}r.SELECT="editor.select",r.HOVER="editor.hover";class a extends r{constructor(t,e){super(t,e)}}a.MOVE="editor.move";class l extends r{constructor(t,e){super(t,e)}}l.SCALE="editor.scale";class h extends r{constructor(t,e){super(t,e)}}h.ROTATE="editor.rotate";class d extends r{constructor(t,e){super(t,e)}}function c(t){return(e,o)=>{const s="_"+o;i.defineKey(e,o,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}d.SKEW="editor.skew";const g=i.MatrixHelper.get(),{abs:u}=Math,{copy:f,scale:p}=i.MatrixHelper;class v extends i.UI{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:o}=this;if(o.length){let s;const{stroke:n,strokeWidth:r,fill:a}=this.__,{bounds:l}=e;for(let h=0;h<o.length;h++)if(s=o[h],l&&l.hit(s.__world,e.matrix)){const o=u(s.__world.scaleX),l=u(s.__world.scaleY);if(o!==l){f(g,s.__world),p(g,1/o,1/l),t.setWorld(g,e.matrix),t.beginPath(),this.__.strokeWidth=r;const{x:i,y:n,width:a,height:h}=s.__layout.boxBounds;t.rect(i*o,n*l,a*o,h*l)}else t.setWorld(s.__world,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),this.__.strokeWidth=r/u(s.__world.scaleX);n&&("string"==typeof n?i.Paint.stroke(n,this,t):i.Paint.strokes(n,this,t)),a&&("string"==typeof a?i.Paint.fill(a,this,t):i.Paint.fills(a,this,t))}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}s([c((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],v.prototype,"target",void 0);class m extends i.Group{constructor(t){super(t),this.strokeArea=new i.Rect({strokeAlign:"center"}),this.fillArea=new i.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:E,Yes:L,NoAndSkip:y,YesAndSkip:b}=i.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?b:y;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?b:E;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return L}return E}return t.isBranch?y:E}},{findOne:k}=w;class _ extends i.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 v,this.targetStroker=new v,this.bounds=new i.Bounds,this.selectArea=new m,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:e}=this,o=t.getInnerTotal(this),s=this.bounds.clone().unsign(),n=new i.LeafList(e.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!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list}}onDragEnd(){this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!k(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new i.LeafList(this.editor.editBox.rect)};return k(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):k(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_(r.HOVER,this.onHover,this),t.on_(r.SELECT,this.onSelect,this),e.on_(o.PointerEvent.MOVE,this.onPointerMove,this),e.on_(o.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this),e.on_(o.PointerEvent.TAP,this.onTap,this),e.on_(o.DragEvent.START,this.onDragStart,this),e.on_(o.DragEvent.DRAG,this.onDrag,this),e.on_(o.DragEvent.END,this.onDragEnd,this),e.on_(o.MoveEvent.MOVE,this.onAutoMove,this),e.on_([o.ZoomEvent.ZOOM,o.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:x,top:M,topRight:O,right:T,bottomRight:S,bottom:P,bottomLeft:H,left:I}=i.Direction9,{toPoint:V}=i.AroundHelper,C={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 M:l=c,n="bottom";break;case T:a=g,n="left";break;case P:l=u,n="top";break;case I:a=f,n="right";break;case x:l=c,a=f,n="bottom-right";break;case O:l=c,a=g,n="bottom-left";break;case S:l=u,a=g,n="top-left";break;case H: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 V(s||n,t,r),{origin:r,scaleX:a,scaleY:l,direction:e,lockRatio:o,around:s}},getRotateData(t,e,o,s,n){let r,a={};switch(e){case x:r="bottom-right";break;case O:r="bottom-left";break;case S:r="top-left";break;case H:r="top-right";break;default:r="center"}return V(n||r,t,a),{origin:a,rotation:i.PointHelper.getRotation(s,a,o)}},getSkewData(t,e,o,s){let n,r,a={},l=0,h=0;switch(e){case M:r={x:.5,y:0},n="bottom",l=1;break;case P:r={x:.5,y:1},n="top",l=1;break;case I:r={x:0,y:.5},n="right",h=1;break;case T: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,V(s||n,t,a);const f=i.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 I:t=T;break;case x:t=O;break;case H:t=S;break;case T:t=I;break;case O:t=x;break;case S:t=H}if(i)switch(t){case M:t=P;break;case x:t=H;break;case O:t=S;break;case P:t=M;break;case H:t=x;break;case S:t=O}return t}},D={};function B(t,e){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&&(e.metaKey||e.ctrlKey||!h)&&(p=!1);const v=c&&!p&&"resize-line"===s.name?l:p?r:a;n+=45*(C.getFlipDirection(s.direction,u,f)+1),n=2*Math.round(i.MathHelper.formatRotation(n,!0)/2);const{url:m,x:E,y:L}=v,y=m+n;D[y]?s.cursor=D[y]:D[y]=s.cursor={url:A(m,n),x:E,y:L}}function R(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function A(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Z extends i.Box{}const G=["top","right","bottom","left"];class W extends i.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 i.Group,this.rect=new i.Box({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Z({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new i.Group({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.rect.syncEventer=t,this.__listenEvents()}create(){let t,e,i;const{view: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 Z({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new Z({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",o)),i=new Z({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);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}update(t){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:e}=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}=e,f="number"==typeof u?u:10,p=!(u&&o<f&&s<f);let v,m,E,L={};for(let n=0;n<8;n++)i.AroundHelper.toPoint(i.AroundHelper.directionData[n],t,L),m=a[n],v=l[n],E=h[Math.floor(n/2)],m.set(L),v.set(L),E.set(L),m.visible=E.visible=p&&!(!c&&!g),v.visible=p&&g&&c&&!e.rotatePoint,n%2&&(m.visible=v.visible=p&&!!d,(n+1)/2%2?(E.width=o,m.width>o-30&&(m.visible=!1)):(E.height=s,m.rotation=90,m.width>s-30&&(m.visible=!1)));r.visible=p&&g&&!!e.rotatePoint,n.path&&(n.path=null),n.set(Object.assign(Object.assign({},t),{visible:!0}));const y=p&&(r.visible||this.buttons.children.length>1);this.buttons.visible=y,y&&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=G.indexOf(i);(l%2&&r||(l+1)%2&&a)&&o&&(l=(l+2)%4);const h=o?C.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),B(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(o.DragEvent.START,this.onDragStart,this),t.on_(o.DragEvent.DRAG,this.onDrag,this),t.on_(o.DragEvent.END,this.onDragEnd,this),t.on_(o.PointerEvent.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(o.PointerEvent.ENTER,(e=>{this.enterPoint=t,B(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(r.SELECT,this.onSelect,this),t.on_(o.DragEvent.START,this.onDragStart,this),t.on_(o.DragEvent.DRAG,e.onMove,e),t.on_(o.DragEvent.END,this.onDragEnd,this),t.on_(o.ZoomEvent.BEFORE_ZOOM,e.onScale,e,!0),t.on_(o.RotateEvent.BEFORE_ROTATE,e.onRotate,e,!0),t.on_(o.PointerEvent.ENTER,(()=>R(e))),t.on_(o.PointerEvent.DOUBLE_TAP,this.onDoubleTap,this),t.on_(o.PointerEvent.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const z='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',U={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${z}\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${z}\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${z}\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 F=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Y=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),X={group(t,e,o){t.sort(Y);const{app:s,parent:n}=t[0];let r;r=o&&o.add?o:new i.Group(o),n.addAt(r,n.children.indexOf(t[0])),t.sort(F);const a=new i.Matrix(e.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(F),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Y),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},N=i.Debug.get("EditToolCreator");function K(){return t=>{$.register(t)}}const j=K,$={list:{},register(t){const{tag:e}=t.prototype;q[e]?N.repeat(e):q[e]=t},get:(t,e)=>new q[t](e)},{list:q}=$;class J extends r{constructor(t,e){super(t,e)}}J.BEFORE_OPEN="innerEditor.before_open",J.OPEN="innerEditor.open",J.BEFORE_CLOSE="innerEditor.before_close",J.CLOSE="innerEditor.close";class Q extends r{constructor(t,e){super(t,e)}}Q.GROUP="editor.group",Q.BEFORE_UNGROUP="editor.before_ungroup",Q.UNGROUP="editor.ungroup",Q.OPEN="editor.open_group",Q.CLOSE="editor.close_group";class tt extends i.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,e){super(e),this.config=U,this.mergeConfig=U,this.leafList=new i.LeafList,this.openedGroupList=new i.LeafList,this.simulateTarget=new i.Rect({visible:!1}),this.editBox=new W(this),this.editToolList={},this.selector=new _(this),this.targetEventIds=[],t&&(this.config=i.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]||$.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(o.DragEvent.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this;if(t instanceof o.ZoomEvent)"zoom"===this.mergeConfig.resizeable&&(t.stop(),this.scaleOf(e.getInnerPoint(t),t.scale,t.scale));else{const{direction:i}=t.current;let{around:o,lockRatio:s}=this.mergeConfig;(t.shiftKey||e.lockRatio)&&(s=!0);const n=C.getScaleData(e.boxBounds,i,t.getInnerMove(e),s,C.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:e,around:s,rotateGap:n}=this.mergeConfig,{direction:r,name:a}=t.current;if(e&&"resize-line"===a)return this.onSkew(t);const{element:l}=this;let h,d;if(t instanceof o.RotateEvent){if("rotate"!==this.mergeConfig.rotateable)return;t.stop(),d=t.rotation,h=l.getInnerPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=C.getRotateData(l.boxBounds,r,t.getInner(l),l.getInnerPoint(e),t.shiftKey?null:s||"center");d=i.rotation,h=i.origin}d=i.MathHelper.getGapRotation(d,n,l.rotation),d&&(l.scaleX*l.scaleY<0&&(d=-d),this.rotateOf(h,i.MathHelper.float(d,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:o,skewX:s,skewY:n}=C.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),C.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 a(a.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){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:e}=this,i=e.getWorldPoint(t.origin),o=new l(l.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(o),this.emitEvent(o)}scaleOf(t,e,o=e,s){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:n}=this,r=n.getWorldPoint(i.LeafHelper.getInnerOrigin(n,t));let a;if(this.multiple){const s=new i.Matrix(n.worldTransform);n.scaleOf(t,e,o),a=new i.Matrix(n.worldTransform).divide(s)}const h=new l(l.SCALE,{target:n,editor:this,worldOrigin:r,scaleX:e,scaleY:o,transform:a});this.editTool.onScale(h),this.emitEvent(h)}rotateOf(t,e){if(!this.mergeConfig.rotateable||this.element.locked)return;const{element:o}=this,s=o.getWorldPoint(i.LeafHelper.getInnerOrigin(o,t));let n;if(this.multiple){const s=new i.Matrix(o.worldTransform);o.rotateOf(t,e),n=new i.Matrix(o.worldTransform).divide(s)}const r=new h(h.ROTATE,{target:o,editor:this,worldOrigin:s,rotation:e,transform:n});this.editTool.onRotate(r),this.emitEvent(r)}skewOf(t,e,o=0,s){if(!this.mergeConfig.skewable||this.element.locked)return;const{element:n}=this,r=n.getWorldPoint(i.LeafHelper.getInnerOrigin(n,t));let a;if(this.multiple){const s=new i.Matrix(n.worldTransform);n.skewOf(t,e,o),a=new i.Matrix(n.worldTransform).divide(s)}const l=new d(d.SKEW,{target:n,editor:this,skewX:e,skewY:o,transform:a,worldOrigin:r});this.editTool.onSkew(l),this.emitEvent(l)}group(t){return this.multiple&&(this.target=X.group(this.list,this.element,t),this.emitGroupEvent(Q.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(Q.BEFORE_UNGROUP,t))),this.target=X.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(Q.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Q.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Q.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!i.LeafHelper.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new Q(t,{editTarget:e});this.emitEvent(i),e.emitEvent(i)}openInnerEditor(t){if(t&&(this.target=t),this.single){const t=this.element,e=t.editInner;e&&$.list[e]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[e]||$.get(e,this),this.innerEditor.editTarget=t,this.emitInnerEvent(J.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(J.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(J.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(J.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,o=new J(t,{editTarget:i,innerEditor:e});this.emitEvent(o),i.emitEvent(o)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(X.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(X.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(i.RenderEvent.START,this.update,this),t.on_([o.KeyEvent.HOLD,o.KeyEvent.UP],(t=>{B(this,t)})),t.on_(o.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())}}s([c((function(t,e){t.emitEvent(new r(r.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],tt.prototype,"hoverTarget",void 0),s([c((function(t,e){const{target:o}=t;o?t.leafList=o instanceof i.LeafList?o:new i.LeafList(o):t.leafList.reset(),t.emitEvent(new r(r.SELECT,{editor:t,value:o,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:o}=t,{x:s,y:n,width:r,height:a}=(new i.Bounds).setListWithFn(o.list,(t=>t.worldBoxBounds)),l=e.parent=o.list[0].leafer.zoomLayer,{scaleX:h,scaleY:d,e:c,f:g}=l.__world;e.reset({x:(s-c)/h,y:(n-g)/d,width:r/h,height:a/d})}(t),R(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],tt.prototype,"target",void 0);class et{static registerInnerEditor(){$.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new i.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 et{static registerEditTool(){$.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=s([K()],t.EditTool);const{left:it,right:ot}=i.Direction9,{move:st,copy:nt}=i.PointHelper;return t.LineEditTool=class extends t.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:o,lockRatio:s,around:n}=t,r=t.target,a=o===it;if(r.pathInputed){const{path:t}=r.__,{from:i,to:o}=this.getFromToByPath(t);this.dragPoint(i,o,a,n,this.getInnerMove(r,e,s)),t[1]=i.x,t[2]=i.y,t[4]=o.x,t[5]=o.y,r.path=t}else if(r.points){const{points:t}=r,{from:i,to:o}=this.getFromToByPoints(t);this.dragPoint(i,o,a,n,this.getInnerMove(r,e,s)),t[0]=i.x,t[1]=i.y,t[2]=o.x,t[3]=o.y,r.points=t}else{const t=i.getPointData(),{toPoint:o}=r;r.rotation=0,this.dragPoint(t,o,a,n,this.getInnerMove(r,e,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?(st(t,n,r),o&&st(e,-n,-r)):(o&&st(t,-n,-r),st(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),nt(o[7],i),nt(e[7],i),nt(o[3],a),nt(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===it||t===ot,o[t].visible=a,e[t].visible=!r&&a}},t.LineEditTool=s([K()],t.LineEditTool),i.Creator.editor=function(t){return new tt(t)},i.UI.setEditConfig=function(t){i.defineKey(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},i.UI.setEditOuter=function(t){i.defineKey(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},i.UI.setEditInner=function(t){i.defineKey(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})},t.EditBox=W,t.EditDataHelper=C,t.EditPoint=Z,t.EditSelect=_,t.EditSelectHelper=w,t.EditToolCreator=$,t.Editor=tt,t.EditorEvent=r,t.EditorGroupEvent=Q,t.EditorHelper=X,t.EditorMoveEvent=a,t.EditorRotateEvent=h,t.EditorScaleEvent=l,t.EditorSkewEvent=d,t.InnerEditor=et,t.InnerEditorEvent=J,t.SelectArea=m,t.Stroker=v,t.registerEditTool=K,t.registerInnerEditor=j,Object.keys(e).forEach((function(i){"default"===i||Object.prototype.hasOwnProperty.call(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:function(){return e[i]}})})),t}({},LeaferIN.resize,LeaferUI,LeaferUI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/editor",
3
- "version": "1.0.0-rc.26",
3
+ "version": "1.0.0-rc.27",
4
4
  "description": "@leafer-in/editor",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,10 +34,9 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "dependencies": {
37
- "@leafer-ui/core": "1.0.0-rc.26",
38
- "@leafer-ui/scale": "1.0.0-rc.26",
39
- "@leafer-ui/interface": "1.0.0-rc.26",
40
- "@leafer-in/resize": "1.0.0-rc.26",
41
- "@leafer-in/interface": "1.0.0-rc.26"
37
+ "@leafer-ui/core": "1.0.0-rc.27",
38
+ "@leafer-ui/interface": "1.0.0-rc.27",
39
+ "@leafer-in/resize": "1.0.0-rc.27",
40
+ "@leafer-in/interface": "1.0.0-rc.27"
42
41
  }
43
42
  }
package/src/index.ts CHANGED
@@ -8,12 +8,14 @@ export { EditSelect } from './display/EditSelect'
8
8
  export { SelectArea } from './display/SelectArea'
9
9
  export { Stroker } from './display/Stroker'
10
10
 
11
- export { InnerEditorEvent } from './event/InnerEditorEvent'
11
+
12
12
  export { EditorEvent } from './event/EditorEvent'
13
13
  export { EditorMoveEvent } from './event/EditorMoveEvent'
14
14
  export { EditorScaleEvent } from './event/EditorScaleEvent'
15
15
  export { EditorRotateEvent } from './event/EditorRotateEvent'
16
16
  export { EditorSkewEvent } from './event/EditorSkewEvent'
17
+ export { EditorGroupEvent } from './event/EditorGroupEvent'
18
+ export { InnerEditorEvent } from './event/InnerEditorEvent'
17
19
 
18
20
  export { EditToolCreator, registerEditTool, registerInnerEditor } from './tool/EditToolCreator'
19
21
  export { InnerEditor } from './tool/InnerEditor'
package/types/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from '@leafer-in/resize';
2
2
  import { IBounds, ILeafList, IUI, IEventListenerId, ILeaf, IPointerEvent, IGroup, IObject, IPointData, IGroupInputData, IEditSize, IAlign, 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, ZoomEvent, RotateEvent } from '@leafer-ui/core';
5
- import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditorEvent, IEditPoint, IEditPointType, IInnerEditorEvent, 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';
5
+ import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditorEvent, IEditPoint, IEditPointType, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent, IEditorGroupEvent, IInnerEditorEvent, 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;
@@ -177,16 +177,6 @@ declare class Stroker extends UI implements IStroker {
177
177
  destroy(): void;
178
178
  }
179
179
 
180
- declare class InnerEditorEvent extends EditorEvent implements IInnerEditorEvent {
181
- static BEFORE_OPEN: string;
182
- static OPEN: string;
183
- static BEFORE_CLOSE: string;
184
- static CLOSE: string;
185
- readonly editTarget: IUI;
186
- readonly innerEditor: IInnerEditor;
187
- constructor(type: string, data?: IInnerEditorEvent);
188
- }
189
-
190
180
  declare class EditorMoveEvent extends EditorEvent implements IEditorMoveEvent {
191
181
  static MOVE: string;
192
182
  readonly moveX: number;
@@ -219,6 +209,26 @@ declare class EditorSkewEvent extends EditorEvent implements IEditorSkewEvent {
219
209
  constructor(type: string, data?: IEditorSkewEvent);
220
210
  }
221
211
 
212
+ declare class EditorGroupEvent extends EditorEvent implements IEditorGroupEvent {
213
+ static GROUP: string;
214
+ static BEFORE_UNGROUP: string;
215
+ static UNGROUP: string;
216
+ static OPEN: string;
217
+ static CLOSE: string;
218
+ readonly editTarget: IGroup;
219
+ constructor(type: string, data?: IEditorGroupEvent);
220
+ }
221
+
222
+ declare class InnerEditorEvent extends EditorEvent implements IInnerEditorEvent {
223
+ static BEFORE_OPEN: string;
224
+ static OPEN: string;
225
+ static BEFORE_CLOSE: string;
226
+ static CLOSE: string;
227
+ readonly editTarget: IUI;
228
+ readonly innerEditor: IInnerEditor;
229
+ constructor(type: string, data?: IInnerEditorEvent);
230
+ }
231
+
222
232
  declare function registerEditTool(): (target: IObject) => void;
223
233
  declare const registerInnerEditor: typeof registerEditTool;
224
234
  declare const EditToolCreator: {
@@ -294,4 +304,4 @@ declare const EditSelectHelper: {
294
304
  findBounds(leaf: IUI, bounds: IBounds): Answer;
295
305
  };
296
306
 
297
- export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, registerEditTool, registerInnerEditor };
307
+ export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, registerEditTool, registerInnerEditor };