@leafer-in/editor 1.0.0-rc.12 → 1.0.0-rc.16
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.esm.js +7 -2
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +7 -2
- package/dist/editor.min.js +1 -1
- package/package.json +5 -5
- package/src/display/Stroker.ts +7 -1
package/dist/editor.esm.js
CHANGED
|
@@ -141,7 +141,7 @@ Group.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
|
141
141
|
groupScaleResize(this, scaleX, scaleY);
|
|
142
142
|
};
|
|
143
143
|
Box.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
144
|
-
if (this.__.
|
|
144
|
+
if (this.__.__autoSize && this.children.length) {
|
|
145
145
|
groupScaleResize(this, scaleX, scaleY);
|
|
146
146
|
}
|
|
147
147
|
else {
|
|
@@ -271,7 +271,12 @@ class Stroker extends UI {
|
|
|
271
271
|
if (!drewPath) {
|
|
272
272
|
canvas.setWorld(leaf.__world, options.matrix);
|
|
273
273
|
canvas.beginPath();
|
|
274
|
-
leaf.__.
|
|
274
|
+
if (leaf.__.__useArrow) {
|
|
275
|
+
leaf.__drawPath(canvas);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
|
|
279
|
+
}
|
|
275
280
|
this.__.strokeWidth = strokeWidth / abs(leaf.__world.scaleX);
|
|
276
281
|
}
|
|
277
282
|
typeof stroke === 'string' ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas);
|
package/dist/editor.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PathCommandMap as t,Leaf as e,Path as i,Line as s,Polygon as o,MatrixHelper as n,Group as r,Box as a}from"@leafer-ui/draw";import{Event as h,defineKey as l,MatrixHelper as c,UI as d,Paint as g,Group as u,Rect as f,Answer as p,Bounds as y,LeafList as L,PointerEvent as w,DragEvent as k,MoveEvent as v,ZoomEvent as _,PointHelper as b,AroundHelper as m,Box as x,LeafHelper as M,getPointData as E,Line as V,Matrix as S,DataHelper as H,RotateEvent as T,MathHelper as O,RenderEvent as P,KeyEvent as D,Creator as R}from"@leafer-ui/core";const{M:Z,L:B,C:A,Q:z,Z:W,N:I,D:X,X:Y,G:C,F:F,O:K,P:U,U:j}=t,G={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case Z:case B:N(t,e,i,o,1),o+=3;break;case A:N(t,e,i,o,3),o+=7;break;case z:N(t,e,i,o,2),o+=5;break;case W:o+=1;break;case I:N(t,e,i,o,2),o+=5;break;case X:N(t,e,i,o,2),o+=9;break;case Y:N(t,e,i,o,2),o+=6;break;case C:N(t,e,i,o,2),o+=9;break;case F:N(t,e,i,o,2),o+=5;break;case K:t[o]=C,t.splice(o+4,0,t[o+3],0),N(t,e,i,o,2),o+=9,n+=2;break;case U:t[o]=F,t.splice(o+4,0,t[o+3]),N(t,e,i,o,2),o+=5,n+=1;break;case j:N(t,e,i,o,2),o+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:N}=G;function $(t,e,i){1!==e&&(t.width*=e),1!==i&&(t.height*=i)}e.prototype.scaleResize=function(t,e=t,i){const s=this;i?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},e.prototype.__scaleResize=function(t,e){$(this,t,e)},i.prototype.__scaleResize=function(t,e){G.scale(this.__.path,t,e),this.path=this.__.path},s.prototype.__scaleResize=function(t,e){if(this.points)G.scalePoints(this.__.points,t,e),this.points=this.__.points;else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},o.prototype.__scaleResize=function(t,e){this.points?(G.scalePoints(this.__.points,t,e),this.points=this.__.points):$(this,t,e)};const Q=n.get();function q(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)Q.a=e,Q.d=i,s[t].transform(Q,!0)}function J(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}r.prototype.__scaleResize=function(t,e){q(this,t,e)},a.prototype.__scaleResize=function(t,e){this.__.__autoBounds&&this.children.length?q(this,t,e):$(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class tt extends h{constructor(t,e){super(t),e&&Object.assign(this,e)}}tt.SELECT="editor.select",tt.HOVER="editor.hover";class et extends tt{constructor(t,e){super(t,e)}}et.MOVE="editor.move";class it extends tt{constructor(t,e){super(t,e)}}it.SCALE="editor.scale";class st extends tt{constructor(t,e){super(t,e)}}st.ROTATE="editor.rotate";class ot extends tt{constructor(t,e){super(t,e)}}function nt(t){return(e,i)=>{const s="_"+i;l(e,i,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}ot.SKEW="editor.skew";const rt=c.get(),{abs:at}=Math,{copy:ht,scale:lt}=c;class ct extends d{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){const{stroke:i,strokeWidth:s}=e;this.set({stroke:i,strokeWidth:s}),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let s;const{stroke:o,strokeWidth:n}=this.__,{bounds:r}=e;for(let a=0;a<i.length;a++)if(s=i[a],r&&r.hit(s.__world,e.matrix)){let i;if("scale"===s.__.editSize){const o=at(s.__world.scaleX),r=at(s.__world.scaleY);if(o!==r){ht(rt,s.__world),lt(rt,1/o,1/r),t.setWorld(rt,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:a,y:h,width:l,height:c}=s.__layout.boxBounds;t.rect(a*o,h*r,l*o,c*r),i=!0}}i||(t.setWorld(s.__world,e.matrix),t.beginPath(),s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),this.__.strokeWidth=n/at(s.__world.scaleX)),"string"==typeof o?g.stroke(o,this,t):g.strokes(o,this,t)}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}J([nt((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],ct.prototype,"target",void 0);class dt extends u{constructor(t){super(t),this.strokeArea=new f({strokeAlign:"center"}),this.fillArea=new f,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:gt,Yes:ut,NoAndSkip:ft,YesAndSkip:pt}=p,yt={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?pt:ft;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?pt:gt;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return ut}return gt}return t.isBranch?ft:gt}},{findOne:Lt}=yt;class wt extends u{get dragging(){return!!this.originList}get running(){return this.editor.hittable&&this.editor.config.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new ct,this.targetStroker=new ct,this.bounds=new y,this.selectArea=new dt,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:s}=t.config;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,{stroke:e,strokeWidth:i})}}onSelect(){if(this.running){const{config:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/2)}),this.hoverStroker.target=null}}update(){this.running&&this.targetStroker.forceUpdate()}onPointerMove(t){if(this.running&&!this.isMoveMode){const e=t.shiftKey?this.findDeepOne(t):Lt(t.path);this.editor.hoverTarget=this.editor.hasItem(e)?null:e}this.isMoveMode&&(this.editor.hoverTarget=null)}onBeforeDown(t){if(this.running&&!this.isMoveMode&&!t.middle){const e=this.lastDownLeaf=Lt(t.path);e?(t.shiftKey?this.editor.shiftItem(e):this.editor.target=e,this.editor.updateLayout(),e.locked||this.app.interaction.updateDownData(null,{findList:[this.editor.editBox.rect]})):this.allow(t.target)&&(t.shiftKey||(this.editor.target=null))}}onTap(t){if(this.running&&t.shiftKey&&!t.middle&&!this.lastDownLeaf){const e=this.findDeepOne(t);e&&this.editor.shiftItem(e)}else this.isMoveMode&&(this.editor.target=null);this.lastDownLeaf=null}onDragStart(t){if(this.running&&this.allowDrag(t)){const{editor:e}=this,{stroke:i,strokeWidth:s,area:o}=e.config,{x:n,y:r}=t.getInner(this);this.bounds.set(n,r),this.selectArea.setStyle({visible:!0,stroke:i,strokeWidth:s,x:n,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:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new L(e.app.find(yt.findBounds,s));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(s.get()),o.length){const t=[];this.originList.forEach((e=>{o.has(e)||t.push(e)})),o.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list,e.leafList.length&&e.update()}}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.editor.config.boxSelect||t.target.draggable)&&(!this.editor.hasTarget&&this.allow(t.target)||t.shiftKey&&!Lt(t.path))}findDeepOne(t){const e={exclude:new L(this.editor.editBox.rect)};return Lt(t.target.leafer.interaction.findPath(t,e))}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(tt.HOVER,this.onHover,this),t.on_(tt.SELECT,this.onSelect,this),e.on_(w.MOVE,this.onPointerMove,this),e.on_(w.BEFORE_DOWN,this.onBeforeDown,this),e.on_(w.TAP,this.onTap,this),e.on_(k.START,this.onDragStart,this),e.on_(k.DRAG,this.onDrag,this),e.on_(k.END,this.onDragEnd,this),e.on_(v.MOVE,this.onAutoMove,this),e.on_([_.ZOOM,v.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.lastDownLeaf=null,this.__removeListenEvents(),super.destroy()}}var kt;!function(t){t[t.topLeft=0]="topLeft",t[t.top=1]="top",t[t.topRight=2]="topRight",t[t.right=3]="right",t[t.bottomRight=4]="bottomRight",t[t.bottom=5]="bottom",t[t.bottomLeft=6]="bottomLeft",t[t.left=7]="left"}(kt||(kt={}));const{topLeft:vt,top:_t,topRight:bt,right:mt,bottomRight:xt,bottom:Mt,bottomLeft:Et,left:Vt}=kt,{toPoint:St}=m,Ht={getScaleData(t,e,i,s,o){let n,r=1,a=1;const{width:h,height:l}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===h&&(i.x+=.1),Math.abs(i.y)===l&&(i.y+=.1);const c=(-i.y+l)/l,d=(i.x+h)/h,g=(i.y+l)/l,u=(-i.x+h)/h;switch(e){case _t:a=c,n={x:.5,y:1};break;case mt:r=d,n={x:0,y:.5};break;case Mt:a=g,n={x:.5,y:0};break;case Vt:r=u,n={x:1,y:.5};break;case vt:a=c,r=u,n={x:1,y:1};break;case bt:a=c,r=d,n={x:0,y:1};break;case xt:a=g,r=d,n={x:0,y:0};break;case Et:a=g,r=u,n={x:1,y:0}}return s&&(1!==r?a=r:r=a),St(o||n,t,n),{origin:n,scaleX:r,scaleY:a,direction:e,lockRatio:s,around:o}},getRotateData(t,e,i,s,o){let n;switch(e){case vt:n={x:1,y:1};break;case bt:n={x:0,y:1};break;case xt:n={x:0,y:0};break;case Et:n={x:1,y:0};break;default:n={x:.5,y:.5}}return St(o||n,t,n),{origin:n,rotation:b.getRotation(s,n,i)}},getSkewData(t,e,i,s){let o,n,r=0,a=0;switch(e){case _t:n={x:.5,y:0},o={x:.5,y:1},r=1;break;case Mt:n={x:.5,y:1},o={x:.5,y:0},r=1;break;case Vt:n={x:0,y:.5},o={x:1,y:.5},a=1;break;case mt:n={x:1,y:.5},o={x:0,y:.5},a=1}const{x:h,y:l,width:c,height:d}=t;n.x=h+n.x*c,n.y=l+n.y*d,St(s||o,t,o);const g=b.getRotation(n,o,{x:n.x+(r?i.x:0),y:n.y+(a?i.y:0)});return r?r=-g:a=g,{origin:o,skewX:r,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 Vt:t=mt;break;case vt:t=bt;break;case Et:t=xt;break;case mt:t=Vt;break;case bt:t=vt;break;case xt:t=Et}if(i)switch(t){case _t:t=Mt;break;case vt:t=Et;break;case bt:t=xt;break;case Mt:t=_t;break;case Et:t=vt;break;case xt:t=bt}return t}};function Tt(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.hasTarget||!i.visible)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:h,rotateable:l,skewable:c}=t.config,{pointType:d}=s,{flippedX:g,flippedY:u}=i;let f="resize"===d;f&&l&&(e.metaKey||e.ctrlKey||!h)&&(f=!1);const p=c&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(Ht.getFlipDirection(s.direction,g,u)+1);const{url:y,x:L,y:w}=p;s.cursor={url:Pt(y,o),x:L,y:w}}function Ot(t){t.editBox.rect.cursor=t.config.moveCursor}function Pt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Dt extends x{}const Rt=["top","right","bottom","left"];class Zt extends u{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.rect=new x({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Dt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new u({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{resizePoints:s,rotatePoints:o,resizeLines:n,rect:r,circle:a,buttons:h}=this,l=[{x:1,y:1},{x:.5,y:1},{x:0,y:1},{x:0,y:.5},{x:0,y:0},{x:.5,y:0},{x:1,y:0},{x:1,y:.5}];for(let r=0;r<8;r++)t=new Dt({name:"rotate-point",around:l[r],width:15,height:15,hitFill:"all"}),o.push(t),this.listenPointEvents(t,"rotate",r),r%2&&(e=new Dt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",r)),i=new Dt({name:"resize-point",around:"center",strokeAlign:"center",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",r);h.add(a),this.listenPointEvents(a,"rotate",2),this.addMany(...o,r,h,...n,...s)}update(t){const{config:e,list:i}=this.editor,{width:s,height:o}=t,{rect:n,circle:r,resizePoints:a,rotatePoints:h,resizeLines:l}=this,{middlePoint:c,resizeable:d,rotateable:g,stroke:u,strokeWidth:f}=e,p=this.getPointsStyle(),y=this.getMiddlePointsStyle(),L=s>20||o>20;this.visible=i[0]&&!i[0].locked;let w,k,v,_,b={};for(let e=0;e<8;e++)m.toPoint(m.directionData[e],t,b),w=this.getPointStyle(e%2?y[(e-1)/2%y.length]:p[e/2%p.length]),v=a[e],k=h[e],_=l[Math.floor(e/2)],v.set(w),v.set(b),k.set(b),_.set(b),v.visible=_.visible=L&&(d||g),k.visible=L&&g&&d,e%2?(v.visible=k.visible=L&&!!c,(e+1)/2%2?(_.width=s,v.width>s-30&&(v.visible=!1)):(_.height=o,v.rotation=90,v.width>o-30&&(v.visible=!1))):v.rotation=e/2*90;r.visible=L&&g&&!!e.rotatePoint,r.set(this.getPointStyle(e.rotatePoint||p[0])),n.set(Object.assign({stroke:u,strokeWidth:f},e.rect||{})),n.set(Object.assign(Object.assign({},t),{visible:!0})),this.buttons.visible=L,this.layoutButtons()}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.config,{flippedX:r,flippedY:a}=this;let h=Rt.indexOf(i);(h%2&&r||(h+1)%2&&a)&&s&&(h=(h+2)%4);const l=s?Ht.getRotateDirection(h,this.flippedOne?this.rotation:-this.rotation,4):h,c=e[2*l+1],d=l%2,g=l&&3!==l?1:-1,u=(o+(h%2?(n?c.width:0)+t.boxBounds.width:(n?c.height:0)+t.boxBounds.height)/2)*g;d?(t.x=c.x+u,t.y=c.y):(t.x=c.x,t.y=c.y+u),s&&(t.rotation=90*(l-h),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.config,r={fill:s,stroke:e,strokeWidth:i,width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.config;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.config;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onDragStart(t){this.dragging=!0,"rect"===t.target.name&&(this.moving=!0,this.editor.opacity=this.editor.config.hideOnMove?0:1)}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.target.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.config.resizeable?(e.config.rotateable&&e.onRotate(t),Tt(e,t)):e.onScale(t)}onArrow(t){if(this.editor.hasTarget){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}(e.x||e.y)&&this.editor.move(e.x,e.y)}}onDoubleClick(){const{editor:t}=this;t.single&&t.element.isBranch}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(k.START,this.onDragStart,this),t.on_(k.DRAG,this.onDrag,this),t.on_(k.END,this.onDragEnd,this),t.on_(w.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(w.ENTER,(e=>{this.enterPoint=t,Tt(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(tt.SELECT,(()=>{this.visible=e.hasTarget})),t.on_(k.START,this.onDragStart,this),t.on_(k.DRAG,e.onMove,e),t.on_(k.END,this.onDragEnd,this),t.on_(w.ENTER,(()=>Ot(e))),t.on_(w.DOUBLE_CLICK,this.onDoubleClick,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Bt='\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"/>',At={editSize:"auto",stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,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${Bt}\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${Bt}\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${Bt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,boxSelect:!0,resizeable:!0,rotateable:!0,skewable:!0},{transformWorld:zt,zoomOfWorld:Wt,skewOfWorld:It,rotateOfWorld:Xt,moveWorld:Yt}=M;class Ct{constructor(){this.tag="EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{Yt(t,e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?zt(t,s,r):Wt(t,o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="size"===o.getEditSize(t);i?zt(t,i,n):Xt(t,s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?zt(t,s,r):It(t,o,e,i,r)})),r.unlockLayout()}update(t){const{simulateTarget:e,element:i}=t;t.multiple&&e.parent.updateLayout();const{x:s,y:o,scaleX:n,scaleY:r,rotation:a,skewX:h,skewY:l,width:c,height:d}=i.getLayoutBounds("box",t,!0);t.editBox.set({x:s,y:o,scaleX:n,scaleY:r,rotation:a,skewX:h,skewY:l}),t.editBox.update({x:0,y:0,width:c,height:d})}}Ct.list=[];const{left:Ft,right:Kt}=kt;class Ut extends Ct{constructor(){super(...arguments),this.tag="LineEditTool",this.scaleOfEvent=!0}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=E(),{toPoint:a}=n;n.rotation=0;let{x:h,y:l}=e.getInnerMove(n);s&&(Math.abs(h)>Math.abs(l)?l=0:h=0),i===Ft?(r.x+=h,r.y+=l,o&&(a.x-=h,a.y-=l)):(o&&(r.x-=h,r.y-=l),a.x+=h,a.y+=l),n.getLocalPointByInner(r,null,null,!0),n.getLocalPointByInner(a,null,null,!0),n.x=r.x,n.y=r.y,n.getInnerPointByLocal(a,null,null,!0),n.toPoint=a}onSkew(t){}update(t){const{rotatePoints:e,resizeLines:i,resizePoints:s}=t.editBox;super.update(t);for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),s[t].visible=e[t].visible=t===Ft||t===Kt}}const jt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Gt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Nt={group(t,e,i){t.sort(Gt);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new u(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(jt);const r=new S(e.worldTransform);return r.divideParent(o.worldTransform),n.setTransform(r),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(jt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Gt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}};class $t extends u{get list(){return this.leafList.list}get hasTarget(){return!!this.list.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}get dragging(){return this.editBox.dragging}constructor(t,e){super(e),this.config=At,this.leafList=new L,this.simulateTarget=new f({visible:!1}),this.editBox=new Zt(this),this.selector=new wt(this),this.targetEventIds=[],t&&(this.config=H.default(t,this.config)),this.addMany(this.selector,this.editBox)}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.target&&(this.editTool&&this.editTool.update(this),this.selector.update())}updateEditTool(){this.editTool=function(t){if(1===t.length){const e=t[0];return e instanceof V&&!e.points?new Ut:new Ct}return new Ct}(this.list)}getEditSize(t){let{editSize:e}=this.config;return"auto"===e?t.editSize:e}onMove(t){const e=t.getLocalMove(this.element);t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(e.x,e.y)}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.config;t.shiftKey&&(o=!0);const n=Ht.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,Ht.getAround(s,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}onRotate(t){const{skewable:e,around:i,rotateGap:s}=this.config,{direction:o,name:n}=t.current;if(e&&"resize-line"===n)return this.onSkew(t);const{element:r}=this;let a,h;if(t instanceof T)h=t.rotation,a=r.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},s=Ht.getRotateData(r.boxBounds,o,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");h=s.rotation,a=s.origin}h=O.getGapRotation(h,s,r.rotation),h&&(r.scaleX*r.scaleY<0&&(h=-h),this.rotateOf(a,O.float(h,2)))}onSkew(t){const{element:e}=this,{around:i}=this.config,{origin:s,skewX:o,skewY:n}=Ht.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Ht.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e){const{element:i}=this,s=i.getWorldPointByLocal({x:t,y:e},null,!0),o=new et(et.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o),this.multiple&&i.move(t,e)}scaleWithDrag(t){const{element:e}=this,i=e.getWorldPoint(t.origin),s=new it(it.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(s),this.emitEvent(s)}scaleOf(t,e,i=e,s){const{element:o}=this,n=o.getWorldPoint(t);let r;if(this.multiple){const s=new S(o.worldTransform);o.scaleOf(t,e,i),r=new S(o.worldTransform).divide(s)}const a=new it(it.SCALE,{target:o,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(a),this.emitEvent(a)}rotateOf(t,e){const{element:i}=this,s=i.getWorldPoint(t);let o;if(this.multiple){const s=new S(i.worldTransform);i.rotateOf(t,e),o=new S(i.worldTransform).divide(s)}const n=new st(st.ROTATE,{target:i,editor:this,worldOrigin:s,rotation:e,transform:o});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,s){const{element:o}=this,n=o.getWorldPoint(t);let r;if(this.multiple){const s=new S(o.worldTransform);o.skewOf(t,e,i),r=new S(o.worldTransform).divide(s)}const a=new ot(ot.SKEW,{target:o,editor:this,skewX:e,skewY:i,transform:r,worldOrigin:n});this.editTool.onSkew(a),this.emitEvent(a)}group(t){return this.multiple&&(this.target=Nt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=Nt.ungroup(this.list)),this.list}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(Nt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Nt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(P.START,this.update,this),t.on_([D.HOLD,D.UP],(t=>{Tt(this,t)})),t.on_(D.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(),this.target=this.hoverTarget=this.simulateTarget=null,super.destroy())}}J([nt((function(t,e){t.emitEvent(new tt(tt.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],$t.prototype,"hoverTarget",void 0),J([nt((function(t,e){const{target:i}=t;i?t.leafList=i instanceof L?i:new L(i):t.leafList.reset(),t.emitEvent(new tt(tt.SELECT,{editor:t,value:i,oldValue:e})),t.hasTarget?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:i}=t,{x:s,y:o,width:n,height:r}=(new y).setListWithFn(i.list,(t=>t.worldBoxBounds)),a=e.parent=i.list[0].leafer.zoomLayer,{scaleX:h,scaleY:l,e:c,f:d}=a.__world;e.reset({x:(s-c)/h,y:(o-d)/l,width:n/h,height:r/l})}(t),Ot(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):t.removeTargetEvents()}))],$t.prototype,"target",void 0),R.editor=function(t){return new $t(t)};export{Zt as EditBox,Ht as EditDataHelper,Dt as EditPoint,wt as EditSelect,yt as EditSelectHelper,Ct as EditTool,$t as Editor,tt as EditorEvent,Nt as EditorHelper,et as EditorMoveEvent,st as EditorRotateEvent,it as EditorScaleEvent,ot as EditorSkewEvent,Ut as LineEditTool,dt as SelectArea,ct as Stroker};
|
|
1
|
+
import{PathCommandMap as t,Leaf as e,Path as i,Line as s,Polygon as o,MatrixHelper as n,Group as r,Box as a}from"@leafer-ui/draw";import{Event as h,defineKey as l,MatrixHelper as c,UI as d,Paint as g,Group as u,Rect as f,Answer as p,Bounds as y,LeafList as w,PointerEvent as L,DragEvent as _,MoveEvent as k,ZoomEvent as v,PointHelper as b,AroundHelper as m,Box as x,LeafHelper as M,getPointData as E,Line as V,Matrix as S,DataHelper as H,RotateEvent as T,MathHelper as O,RenderEvent as P,KeyEvent as D,Creator as R}from"@leafer-ui/core";const{M:Z,L:A,C:B,Q:z,Z:W,N:I,D:X,X:Y,G:C,F:F,O:K,P:U,U:j}=t,G={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case Z:case A:N(t,e,i,o,1),o+=3;break;case B:N(t,e,i,o,3),o+=7;break;case z:N(t,e,i,o,2),o+=5;break;case W:o+=1;break;case I:N(t,e,i,o,2),o+=5;break;case X:N(t,e,i,o,2),o+=9;break;case Y:N(t,e,i,o,2),o+=6;break;case C:N(t,e,i,o,2),o+=9;break;case F:N(t,e,i,o,2),o+=5;break;case K:t[o]=C,t.splice(o+4,0,t[o+3],0),N(t,e,i,o,2),o+=9,n+=2;break;case U:t[o]=F,t.splice(o+4,0,t[o+3]),N(t,e,i,o,2),o+=5,n+=1;break;case j:N(t,e,i,o,2),o+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:N}=G;function $(t,e,i){1!==e&&(t.width*=e),1!==i&&(t.height*=i)}e.prototype.scaleResize=function(t,e=t,i){const s=this;i?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},e.prototype.__scaleResize=function(t,e){$(this,t,e)},i.prototype.__scaleResize=function(t,e){G.scale(this.__.path,t,e),this.path=this.__.path},s.prototype.__scaleResize=function(t,e){if(this.points)G.scalePoints(this.__.points,t,e),this.points=this.__.points;else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},o.prototype.__scaleResize=function(t,e){this.points?(G.scalePoints(this.__.points,t,e),this.points=this.__.points):$(this,t,e)};const Q=n.get();function q(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)Q.a=e,Q.d=i,s[t].transform(Q,!0)}function J(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}r.prototype.__scaleResize=function(t,e){q(this,t,e)},a.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?q(this,t,e):$(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class tt extends h{constructor(t,e){super(t),e&&Object.assign(this,e)}}tt.SELECT="editor.select",tt.HOVER="editor.hover";class et extends tt{constructor(t,e){super(t,e)}}et.MOVE="editor.move";class it extends tt{constructor(t,e){super(t,e)}}it.SCALE="editor.scale";class st extends tt{constructor(t,e){super(t,e)}}st.ROTATE="editor.rotate";class ot extends tt{constructor(t,e){super(t,e)}}function nt(t){return(e,i)=>{const s="_"+i;l(e,i,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}ot.SKEW="editor.skew";const rt=c.get(),{abs:at}=Math,{copy:ht,scale:lt}=c;class ct extends d{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){const{stroke:i,strokeWidth:s}=e;this.set({stroke:i,strokeWidth:s}),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let s;const{stroke:o,strokeWidth:n}=this.__,{bounds:r}=e;for(let a=0;a<i.length;a++)if(s=i[a],r&&r.hit(s.__world,e.matrix)){let i;if("scale"===s.__.editSize){const o=at(s.__world.scaleX),r=at(s.__world.scaleY);if(o!==r){ht(rt,s.__world),lt(rt,1/o,1/r),t.setWorld(rt,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:a,y:h,width:l,height:c}=s.__layout.boxBounds;t.rect(a*o,h*r,l*o,c*r),i=!0}}i||(t.setWorld(s.__world,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),this.__.strokeWidth=n/at(s.__world.scaleX)),"string"==typeof o?g.stroke(o,this,t):g.strokes(o,this,t)}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}J([nt((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],ct.prototype,"target",void 0);class dt extends u{constructor(t){super(t),this.strokeArea=new f({strokeAlign:"center"}),this.fillArea=new f,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:gt,Yes:ut,NoAndSkip:ft,YesAndSkip:pt}=p,yt={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?pt:ft;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?pt:gt;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return ut}return gt}return t.isBranch?ft:gt}},{findOne:wt}=yt;class Lt extends u{get dragging(){return!!this.originList}get running(){return this.editor.hittable&&this.editor.config.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new ct,this.targetStroker=new ct,this.bounds=new y,this.selectArea=new dt,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:s}=t.config;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,{stroke:e,strokeWidth:i})}}onSelect(){if(this.running){const{config:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/2)}),this.hoverStroker.target=null}}update(){this.running&&this.targetStroker.forceUpdate()}onPointerMove(t){if(this.running&&!this.isMoveMode){const e=t.shiftKey?this.findDeepOne(t):wt(t.path);this.editor.hoverTarget=this.editor.hasItem(e)?null:e}this.isMoveMode&&(this.editor.hoverTarget=null)}onBeforeDown(t){if(this.running&&!this.isMoveMode&&!t.middle){const e=this.lastDownLeaf=wt(t.path);e?(t.shiftKey?this.editor.shiftItem(e):this.editor.target=e,this.editor.updateLayout(),e.locked||this.app.interaction.updateDownData(null,{findList:[this.editor.editBox.rect]})):this.allow(t.target)&&(t.shiftKey||(this.editor.target=null))}}onTap(t){if(this.running&&t.shiftKey&&!t.middle&&!this.lastDownLeaf){const e=this.findDeepOne(t);e&&this.editor.shiftItem(e)}else this.isMoveMode&&(this.editor.target=null);this.lastDownLeaf=null}onDragStart(t){if(this.running&&this.allowDrag(t)){const{editor:e}=this,{stroke:i,strokeWidth:s,area:o}=e.config,{x:n,y:r}=t.getInner(this);this.bounds.set(n,r),this.selectArea.setStyle({visible:!0,stroke:i,strokeWidth:s,x:n,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:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new w(e.app.find(yt.findBounds,s));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(s.get()),o.length){const t=[];this.originList.forEach((e=>{o.has(e)||t.push(e)})),o.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list,e.leafList.length&&e.update()}}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.editor.config.boxSelect||t.target.draggable)&&(!this.editor.hasTarget&&this.allow(t.target)||t.shiftKey&&!wt(t.path))}findDeepOne(t){const e={exclude:new w(this.editor.editBox.rect)};return wt(t.target.leafer.interaction.findPath(t,e))}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(tt.HOVER,this.onHover,this),t.on_(tt.SELECT,this.onSelect,this),e.on_(L.MOVE,this.onPointerMove,this),e.on_(L.BEFORE_DOWN,this.onBeforeDown,this),e.on_(L.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_([v.ZOOM,k.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.lastDownLeaf=null,this.__removeListenEvents(),super.destroy()}}var _t;!function(t){t[t.topLeft=0]="topLeft",t[t.top=1]="top",t[t.topRight=2]="topRight",t[t.right=3]="right",t[t.bottomRight=4]="bottomRight",t[t.bottom=5]="bottom",t[t.bottomLeft=6]="bottomLeft",t[t.left=7]="left"}(_t||(_t={}));const{topLeft:kt,top:vt,topRight:bt,right:mt,bottomRight:xt,bottom:Mt,bottomLeft:Et,left:Vt}=_t,{toPoint:St}=m,Ht={getScaleData(t,e,i,s,o){let n,r=1,a=1;const{width:h,height:l}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===h&&(i.x+=.1),Math.abs(i.y)===l&&(i.y+=.1);const c=(-i.y+l)/l,d=(i.x+h)/h,g=(i.y+l)/l,u=(-i.x+h)/h;switch(e){case vt:a=c,n={x:.5,y:1};break;case mt:r=d,n={x:0,y:.5};break;case Mt:a=g,n={x:.5,y:0};break;case Vt:r=u,n={x:1,y:.5};break;case kt:a=c,r=u,n={x:1,y:1};break;case bt:a=c,r=d,n={x:0,y:1};break;case xt:a=g,r=d,n={x:0,y:0};break;case Et:a=g,r=u,n={x:1,y:0}}return s&&(1!==r?a=r:r=a),St(o||n,t,n),{origin:n,scaleX:r,scaleY:a,direction:e,lockRatio:s,around:o}},getRotateData(t,e,i,s,o){let n;switch(e){case kt:n={x:1,y:1};break;case bt:n={x:0,y:1};break;case xt:n={x:0,y:0};break;case Et:n={x:1,y:0};break;default:n={x:.5,y:.5}}return St(o||n,t,n),{origin:n,rotation:b.getRotation(s,n,i)}},getSkewData(t,e,i,s){let o,n,r=0,a=0;switch(e){case vt:n={x:.5,y:0},o={x:.5,y:1},r=1;break;case Mt:n={x:.5,y:1},o={x:.5,y:0},r=1;break;case Vt:n={x:0,y:.5},o={x:1,y:.5},a=1;break;case mt:n={x:1,y:.5},o={x:0,y:.5},a=1}const{x:h,y:l,width:c,height:d}=t;n.x=h+n.x*c,n.y=l+n.y*d,St(s||o,t,o);const g=b.getRotation(n,o,{x:n.x+(r?i.x:0),y:n.y+(a?i.y:0)});return r?r=-g:a=g,{origin:o,skewX:r,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 Vt:t=mt;break;case kt:t=bt;break;case Et:t=xt;break;case mt:t=Vt;break;case bt:t=kt;break;case xt:t=Et}if(i)switch(t){case vt:t=Mt;break;case kt:t=Et;break;case bt:t=xt;break;case Mt:t=vt;break;case Et:t=kt;break;case xt:t=bt}return t}};function Tt(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.hasTarget||!i.visible)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:h,rotateable:l,skewable:c}=t.config,{pointType:d}=s,{flippedX:g,flippedY:u}=i;let f="resize"===d;f&&l&&(e.metaKey||e.ctrlKey||!h)&&(f=!1);const p=c&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(Ht.getFlipDirection(s.direction,g,u)+1);const{url:y,x:w,y:L}=p;s.cursor={url:Pt(y,o),x:w,y:L}}function Ot(t){t.editBox.rect.cursor=t.config.moveCursor}function Pt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Dt extends x{}const Rt=["top","right","bottom","left"];class Zt extends u{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.rect=new x({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Dt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new u({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{resizePoints:s,rotatePoints:o,resizeLines:n,rect:r,circle:a,buttons:h}=this,l=[{x:1,y:1},{x:.5,y:1},{x:0,y:1},{x:0,y:.5},{x:0,y:0},{x:.5,y:0},{x:1,y:0},{x:1,y:.5}];for(let r=0;r<8;r++)t=new Dt({name:"rotate-point",around:l[r],width:15,height:15,hitFill:"all"}),o.push(t),this.listenPointEvents(t,"rotate",r),r%2&&(e=new Dt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",r)),i=new Dt({name:"resize-point",around:"center",strokeAlign:"center",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",r);h.add(a),this.listenPointEvents(a,"rotate",2),this.addMany(...o,r,h,...n,...s)}update(t){const{config:e,list:i}=this.editor,{width:s,height:o}=t,{rect:n,circle:r,resizePoints:a,rotatePoints:h,resizeLines:l}=this,{middlePoint:c,resizeable:d,rotateable:g,stroke:u,strokeWidth:f}=e,p=this.getPointsStyle(),y=this.getMiddlePointsStyle(),w=s>20||o>20;this.visible=i[0]&&!i[0].locked;let L,_,k,v,b={};for(let e=0;e<8;e++)m.toPoint(m.directionData[e],t,b),L=this.getPointStyle(e%2?y[(e-1)/2%y.length]:p[e/2%p.length]),k=a[e],_=h[e],v=l[Math.floor(e/2)],k.set(L),k.set(b),_.set(b),v.set(b),k.visible=v.visible=w&&(d||g),_.visible=w&&g&&d,e%2?(k.visible=_.visible=w&&!!c,(e+1)/2%2?(v.width=s,k.width>s-30&&(k.visible=!1)):(v.height=o,k.rotation=90,k.width>o-30&&(k.visible=!1))):k.rotation=e/2*90;r.visible=w&&g&&!!e.rotatePoint,r.set(this.getPointStyle(e.rotatePoint||p[0])),n.set(Object.assign({stroke:u,strokeWidth:f},e.rect||{})),n.set(Object.assign(Object.assign({},t),{visible:!0})),this.buttons.visible=w,this.layoutButtons()}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.config,{flippedX:r,flippedY:a}=this;let h=Rt.indexOf(i);(h%2&&r||(h+1)%2&&a)&&s&&(h=(h+2)%4);const l=s?Ht.getRotateDirection(h,this.flippedOne?this.rotation:-this.rotation,4):h,c=e[2*l+1],d=l%2,g=l&&3!==l?1:-1,u=(o+(h%2?(n?c.width:0)+t.boxBounds.width:(n?c.height:0)+t.boxBounds.height)/2)*g;d?(t.x=c.x+u,t.y=c.y):(t.x=c.x,t.y=c.y+u),s&&(t.rotation=90*(l-h),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.config,r={fill:s,stroke:e,strokeWidth:i,width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.config;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.config;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onDragStart(t){this.dragging=!0,"rect"===t.target.name&&(this.moving=!0,this.editor.opacity=this.editor.config.hideOnMove?0:1)}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.target.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.config.resizeable?(e.config.rotateable&&e.onRotate(t),Tt(e,t)):e.onScale(t)}onArrow(t){if(this.editor.hasTarget){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}(e.x||e.y)&&this.editor.move(e.x,e.y)}}onDoubleClick(){const{editor:t}=this;t.single&&t.element.isBranch}listenPointEvents(t,e,i){const{editor:s}=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_(L.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(L.ENTER,(e=>{this.enterPoint=t,Tt(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(tt.SELECT,(()=>{this.visible=e.hasTarget})),t.on_(_.START,this.onDragStart,this),t.on_(_.DRAG,e.onMove,e),t.on_(_.END,this.onDragEnd,this),t.on_(L.ENTER,(()=>Ot(e))),t.on_(L.DOUBLE_CLICK,this.onDoubleClick,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const At='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',Bt={editSize:"auto",stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${At}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},rotateCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(135,12,12),rotate({{rotation}},12,12)">\n<path d="M20.4 8H21.4L20.8 7.1L17.3 2.6L17 2.1L16.6 2.6L13.1 7.1L12.5 8H13.5H15.4C14.9 11.8 11.8 14.9 8 15.4V13.5V12.5L7.1 13.1L2.6 16.6L2.1 17L2.6 17.3L7.1 20.8L8 21.4V20.4V18.4C13.5 17.9 17.9 13.5 18.4 8H20.4Z" stroke="white"/>\n<path fill-rule="evenodd" d="M17 3L20.4 7.5H17.9C17.7 13.1 13.1 17.7 7.5 17.9V20.4L3 17L7.5 13.5V15.9C12.0 15.7 15.7 12.0 15.9 7.5H13.5L17 3Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">\n${At}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},skewCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(90,12,12),rotate({{rotation}},12,12)">\n<path d="M21 10.4L21 11.4L23.8 11.4L21.6 9.6L21 10.4ZM17 10.4V11.4L17 11.4L17 10.4ZM15.5 6L16.1 5.2L14.5 3.9V6H15.5ZM15.5 8.4V9.4H16.5V8.4H15.5ZM6 8.4V7.4H5V8.4H6ZM6 10.4H5V11.4H6V10.4ZM7 14.4V13.4L7 13.4L7 14.4ZM3 14.4L3 13.4L0.1 13.4L2.3 15.2L3 14.4ZM8.5 18.9L7.8 19.7L9.5 21.0V18.9H8.5ZM8.5 16.4V15.4H7.5V16.4H8.5ZM19 16.4V17.4H20V16.4H19ZM19 14.4H20V13.4H19V14.4ZM21 9.4L17 9.4L17 11.4L21 11.4L21 9.4ZM14.8 6.7L20.3 11.2L21.6 9.6L16.1 5.2L14.8 6.7ZM16.5 8.4V6H14.5V8.4H16.5ZM6 9.4H15.5V7.4H6V9.4ZM7 10.4V8.4H5V10.4H7ZM15.5 9.4H6V11.4H15.5V9.4ZM17 9.4H15.5V11.4H17V9.4ZM7 15.4H8.5V13.4H7V15.4ZM3 15.4L7 15.4L7 13.4L3 13.4L3 15.4ZM9.1 18.1L3.6 13.6L2.3 15.2L7.8 19.7L9.1 18.1ZM7.5 16.4V18.9H9.5V16.4H7.5ZM19 15.4H8.5V17.4H19V15.4ZM18 14.4V16.4H20V14.4H18ZM8.5 15.4H19V13.4H8.5V15.4Z" fill="white"/>\n<path fill-rule="evenodd" d="M17 10.4L21 10.4L15.5 6V8.4H6V10.4H15.5H17ZM8.5 14.4H7L3 14.4L8.5 18.9V16.4H19V14.4H8.5Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >\n${At}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,boxSelect:!0,resizeable:!0,rotateable:!0,skewable:!0},{transformWorld:zt,zoomOfWorld:Wt,skewOfWorld:It,rotateOfWorld:Xt,moveWorld:Yt}=M;class Ct{constructor(){this.tag="EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{Yt(t,e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?zt(t,s,r):Wt(t,o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="size"===o.getEditSize(t);i?zt(t,i,n):Xt(t,s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?zt(t,s,r):It(t,o,e,i,r)})),r.unlockLayout()}update(t){const{simulateTarget:e,element:i}=t;t.multiple&&e.parent.updateLayout();const{x:s,y:o,scaleX:n,scaleY:r,rotation:a,skewX:h,skewY:l,width:c,height:d}=i.getLayoutBounds("box",t,!0);t.editBox.set({x:s,y:o,scaleX:n,scaleY:r,rotation:a,skewX:h,skewY:l}),t.editBox.update({x:0,y:0,width:c,height:d})}}Ct.list=[];const{left:Ft,right:Kt}=_t;class Ut extends Ct{constructor(){super(...arguments),this.tag="LineEditTool",this.scaleOfEvent=!0}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=E(),{toPoint:a}=n;n.rotation=0;let{x:h,y:l}=e.getInnerMove(n);s&&(Math.abs(h)>Math.abs(l)?l=0:h=0),i===Ft?(r.x+=h,r.y+=l,o&&(a.x-=h,a.y-=l)):(o&&(r.x-=h,r.y-=l),a.x+=h,a.y+=l),n.getLocalPointByInner(r,null,null,!0),n.getLocalPointByInner(a,null,null,!0),n.x=r.x,n.y=r.y,n.getInnerPointByLocal(a,null,null,!0),n.toPoint=a}onSkew(t){}update(t){const{rotatePoints:e,resizeLines:i,resizePoints:s}=t.editBox;super.update(t);for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),s[t].visible=e[t].visible=t===Ft||t===Kt}}const jt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Gt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Nt={group(t,e,i){t.sort(Gt);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new u(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(jt);const r=new S(e.worldTransform);return r.divideParent(o.worldTransform),n.setTransform(r),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(jt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Gt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}};class $t extends u{get list(){return this.leafList.list}get hasTarget(){return!!this.list.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}get dragging(){return this.editBox.dragging}constructor(t,e){super(e),this.config=Bt,this.leafList=new w,this.simulateTarget=new f({visible:!1}),this.editBox=new Zt(this),this.selector=new Lt(this),this.targetEventIds=[],t&&(this.config=H.default(t,this.config)),this.addMany(this.selector,this.editBox)}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.target&&(this.editTool&&this.editTool.update(this),this.selector.update())}updateEditTool(){this.editTool=function(t){if(1===t.length){const e=t[0];return e instanceof V&&!e.points?new Ut:new Ct}return new Ct}(this.list)}getEditSize(t){let{editSize:e}=this.config;return"auto"===e?t.editSize:e}onMove(t){const e=t.getLocalMove(this.element);t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(e.x,e.y)}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.config;t.shiftKey&&(o=!0);const n=Ht.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,Ht.getAround(s,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}onRotate(t){const{skewable:e,around:i,rotateGap:s}=this.config,{direction:o,name:n}=t.current;if(e&&"resize-line"===n)return this.onSkew(t);const{element:r}=this;let a,h;if(t instanceof T)h=t.rotation,a=r.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},s=Ht.getRotateData(r.boxBounds,o,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");h=s.rotation,a=s.origin}h=O.getGapRotation(h,s,r.rotation),h&&(r.scaleX*r.scaleY<0&&(h=-h),this.rotateOf(a,O.float(h,2)))}onSkew(t){const{element:e}=this,{around:i}=this.config,{origin:s,skewX:o,skewY:n}=Ht.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Ht.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e){const{element:i}=this,s=i.getWorldPointByLocal({x:t,y:e},null,!0),o=new et(et.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o),this.multiple&&i.move(t,e)}scaleWithDrag(t){const{element:e}=this,i=e.getWorldPoint(t.origin),s=new it(it.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(s),this.emitEvent(s)}scaleOf(t,e,i=e,s){const{element:o}=this,n=o.getWorldPoint(t);let r;if(this.multiple){const s=new S(o.worldTransform);o.scaleOf(t,e,i),r=new S(o.worldTransform).divide(s)}const a=new it(it.SCALE,{target:o,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(a),this.emitEvent(a)}rotateOf(t,e){const{element:i}=this,s=i.getWorldPoint(t);let o;if(this.multiple){const s=new S(i.worldTransform);i.rotateOf(t,e),o=new S(i.worldTransform).divide(s)}const n=new st(st.ROTATE,{target:i,editor:this,worldOrigin:s,rotation:e,transform:o});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,s){const{element:o}=this,n=o.getWorldPoint(t);let r;if(this.multiple){const s=new S(o.worldTransform);o.skewOf(t,e,i),r=new S(o.worldTransform).divide(s)}const a=new ot(ot.SKEW,{target:o,editor:this,skewX:e,skewY:i,transform:r,worldOrigin:n});this.editTool.onSkew(a),this.emitEvent(a)}group(t){return this.multiple&&(this.target=Nt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=Nt.ungroup(this.list)),this.list}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(Nt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Nt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(P.START,this.update,this),t.on_([D.HOLD,D.UP],(t=>{Tt(this,t)})),t.on_(D.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(),this.target=this.hoverTarget=this.simulateTarget=null,super.destroy())}}J([nt((function(t,e){t.emitEvent(new tt(tt.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],$t.prototype,"hoverTarget",void 0),J([nt((function(t,e){const{target:i}=t;i?t.leafList=i instanceof w?i:new w(i):t.leafList.reset(),t.emitEvent(new tt(tt.SELECT,{editor:t,value:i,oldValue:e})),t.hasTarget?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:i}=t,{x:s,y:o,width:n,height:r}=(new y).setListWithFn(i.list,(t=>t.worldBoxBounds)),a=e.parent=i.list[0].leafer.zoomLayer,{scaleX:h,scaleY:l,e:c,f:d}=a.__world;e.reset({x:(s-c)/h,y:(o-d)/l,width:n/h,height:r/l})}(t),Ot(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):t.removeTargetEvents()}))],$t.prototype,"target",void 0),R.editor=function(t){return new $t(t)};export{Zt as EditBox,Ht as EditDataHelper,Dt as EditPoint,Lt as EditSelect,yt as EditSelectHelper,Ct as EditTool,$t as Editor,tt as EditorEvent,Nt as EditorHelper,et as EditorMoveEvent,st as EditorRotateEvent,it as EditorScaleEvent,ot as EditorSkewEvent,Ut as LineEditTool,dt as SelectArea,ct as Stroker};
|
package/dist/editor.js
CHANGED
|
@@ -142,7 +142,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
142
142
|
groupScaleResize(this, scaleX, scaleY);
|
|
143
143
|
};
|
|
144
144
|
draw.Box.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
145
|
-
if (this.__.
|
|
145
|
+
if (this.__.__autoSize && this.children.length) {
|
|
146
146
|
groupScaleResize(this, scaleX, scaleY);
|
|
147
147
|
}
|
|
148
148
|
else {
|
|
@@ -272,7 +272,12 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
272
272
|
if (!drewPath) {
|
|
273
273
|
canvas.setWorld(leaf.__world, options.matrix);
|
|
274
274
|
canvas.beginPath();
|
|
275
|
-
leaf.__.
|
|
275
|
+
if (leaf.__.__useArrow) {
|
|
276
|
+
leaf.__drawPath(canvas);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
|
|
280
|
+
}
|
|
276
281
|
this.__.strokeWidth = strokeWidth / abs(leaf.__world.scaleX);
|
|
277
282
|
}
|
|
278
283
|
typeof stroke === 'string' ? core.Paint.stroke(stroke, this, canvas) : core.Paint.strokes(stroke, this, canvas);
|
package/dist/editor.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.editor=function(t,e,i){"use strict";const{M:s,L:o,C:n,Q:r,Z:a,N:l,D:h,X:d,G:c,F:g,O:u,P:f,U:p}=e.PathCommandMap,L={scale(t,e,i){if(!t)return;let L,y=0,w=t.length;for(;y<w;)switch(L=t[y],L){case s:case o:v(t,e,i,y,1),y+=3;break;case n:v(t,e,i,y,3),y+=7;break;case r:v(t,e,i,y,2),y+=5;break;case a:y+=1;break;case l:v(t,e,i,y,2),y+=5;break;case h:v(t,e,i,y,2),y+=9;break;case d:v(t,e,i,y,2),y+=6;break;case c:v(t,e,i,y,2),y+=9;break;case g:v(t,e,i,y,2),y+=5;break;case u:t[y]=c,t.splice(y+4,0,t[y+3],0),v(t,e,i,y,2),y+=9,w+=2;break;case f:t[y]=g,t.splice(y+4,0,t[y+3]),v(t,e,i,y,2),y+=5,w+=1;break;case p:v(t,e,i,y,2),y+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:v}=L;function y(t,e,i){1!==e&&(t.width*=e),1!==i&&(t.height*=i)}e.Leaf.prototype.scaleResize=function(t,e=t,i){const s=this;i?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},e.Leaf.prototype.__scaleResize=function(t,e){y(this,t,e)},e.Path.prototype.__scaleResize=function(t,e){L.scale(this.__.path,t,e),this.path=this.__.path},e.Line.prototype.__scaleResize=function(t,e){if(this.points)L.scalePoints(this.__.points,t,e),this.points=this.__.points;else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},e.Polygon.prototype.__scaleResize=function(t,e){this.points?(L.scalePoints(this.__.points,t,e),this.points=this.__.points):y(this,t,e)};const w=e.MatrixHelper.get();function k(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)w.a=e,w.d=i,s[t].transform(w,!0)}function x(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}e.Group.prototype.__scaleResize=function(t,e){k(this,t,e)},e.Box.prototype.__scaleResize=function(t,e){this.__.__autoBounds&&this.children.length?k(this,t,e):y(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class _ extends i.Event{constructor(t,e){super(t),e&&Object.assign(this,e)}}_.SELECT="editor.select",_.HOVER="editor.hover";class b extends _{constructor(t,e){super(t,e)}}b.MOVE="editor.move";class m extends _{constructor(t,e){super(t,e)}}m.SCALE="editor.scale";class E extends _{constructor(t,e){super(t,e)}}E.ROTATE="editor.rotate";class M extends _{constructor(t,e){super(t,e)}}function H(t){return(e,s)=>{const o="_"+s;i.defineKey(e,s,{get(){return this[o]},set(e){const i=this[o];i!==e&&(this[o]=e,t(this,i))}})}}M.SKEW="editor.skew";const S=i.MatrixHelper.get(),{abs:V}=Math,{copy:P,scale:T}=i.MatrixHelper;class D extends i.UI{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){const{stroke:i,strokeWidth:s}=e;this.set({stroke:i,strokeWidth:s}),this.target=t}__draw(t,e){const{list:s}=this;if(s.length){let o;const{stroke:n,strokeWidth:r}=this.__,{bounds:a}=e;for(let l=0;l<s.length;l++)if(o=s[l],a&&a.hit(o.__world,e.matrix)){let s;if("scale"===o.__.editSize){const i=V(o.__world.scaleX),n=V(o.__world.scaleY);if(i!==n){P(S,o.__world),T(S,1/i,1/n),t.setWorld(S,e.matrix),t.beginPath(),this.__.strokeWidth=r;const{x:a,y:l,width:h,height:d}=o.__layout.boxBounds;t.rect(a*i,l*n,h*i,d*n),s=!0}}s||(t.setWorld(o.__world,e.matrix),t.beginPath(),o.__.__pathForRender?o.__drawRenderPath(t):o.__drawPathByBox(t),this.__.strokeWidth=r/V(o.__world.scaleX)),"string"==typeof n?i.Paint.stroke(n,this,t):i.Paint.strokes(n,this,t)}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}x([H((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],D.prototype,"target",void 0);class O 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:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:R,Yes:B,NoAndSkip:A,YesAndSkip:Z}=i.Answer,z={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?Z:A;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?Z:R;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return B}return R}return t.isBranch?A:R}},{findOne:I}=z;class W extends i.Group{get dragging(){return!!this.originList}get running(){return this.editor.hittable&&this.editor.config.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new D,this.targetStroker=new D,this.bounds=new i.Bounds,this.selectArea=new O,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:s}=t.config;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,{stroke:e,strokeWidth:i})}}onSelect(){if(this.running){const{config:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/2)}),this.hoverStroker.target=null}}update(){this.running&&this.targetStroker.forceUpdate()}onPointerMove(t){if(this.running&&!this.isMoveMode){const e=t.shiftKey?this.findDeepOne(t):I(t.path);this.editor.hoverTarget=this.editor.hasItem(e)?null:e}this.isMoveMode&&(this.editor.hoverTarget=null)}onBeforeDown(t){if(this.running&&!this.isMoveMode&&!t.middle){const e=this.lastDownLeaf=I(t.path);e?(t.shiftKey?this.editor.shiftItem(e):this.editor.target=e,this.editor.updateLayout(),e.locked||this.app.interaction.updateDownData(null,{findList:[this.editor.editBox.rect]})):this.allow(t.target)&&(t.shiftKey||(this.editor.target=null))}}onTap(t){if(this.running&&t.shiftKey&&!t.middle&&!this.lastDownLeaf){const e=this.findDeepOne(t);e&&this.editor.shiftItem(e)}else this.isMoveMode&&(this.editor.target=null);this.lastDownLeaf=null}onDragStart(t){if(this.running&&this.allowDrag(t)){const{editor:e}=this,{stroke:i,strokeWidth:s,area:o}=e.config,{x:n,y:r}=t.getInner(this);this.bounds.set(n,r),this.selectArea.setStyle({visible:!0,stroke:i,strokeWidth:s,x:n,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:e}=this,s=t.getInnerTotal(this),o=this.bounds.clone().unsign(),n=new i.LeafList(e.app.find(z.findBounds,o));if(this.bounds.width=s.x,this.bounds.height=s.y,this.selectArea.setBounds(o.get()),n.length){const t=[];this.originList.forEach((e=>{n.has(e)||t.push(e)})),n.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list,e.leafList.length&&e.update()}}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.editor.config.boxSelect||t.target.draggable)&&(!this.editor.hasTarget&&this.allow(t.target)||t.shiftKey&&!I(t.path))}findDeepOne(t){const e={exclude:new i.LeafList(this.editor.editBox.rect)};return I(t.target.leafer.interaction.findPath(t,e))}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(_.HOVER,this.onHover,this),t.on_(_.SELECT,this.onSelect,this),e.on_(i.PointerEvent.MOVE,this.onPointerMove,this),e.on_(i.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this),e.on_(i.PointerEvent.TAP,this.onTap,this),e.on_(i.DragEvent.START,this.onDragStart,this),e.on_(i.DragEvent.DRAG,this.onDrag,this),e.on_(i.DragEvent.END,this.onDragEnd,this),e.on_(i.MoveEvent.MOVE,this.onAutoMove,this),e.on_([i.ZoomEvent.ZOOM,i.MoveEvent.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.lastDownLeaf=null,this.__removeListenEvents(),super.destroy()}}var C;!function(t){t[t.topLeft=0]="topLeft",t[t.top=1]="top",t[t.topRight=2]="topRight",t[t.right=3]="right",t[t.bottomRight=4]="bottomRight",t[t.bottom=5]="bottom",t[t.bottomLeft=6]="bottomLeft",t[t.left=7]="left"}(C||(C={}));const{topLeft:X,top:Y,topRight:K,right:F,bottomRight:G,bottom:U,bottomLeft:N,left:j}=C,{toPoint:$}=i.AroundHelper,Q={getScaleData(t,e,i,s,o){let n,r=1,a=1;const{width:l,height:h}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===l&&(i.x+=.1),Math.abs(i.y)===h&&(i.y+=.1);const d=(-i.y+h)/h,c=(i.x+l)/l,g=(i.y+h)/h,u=(-i.x+l)/l;switch(e){case Y:a=d,n={x:.5,y:1};break;case F:r=c,n={x:0,y:.5};break;case U:a=g,n={x:.5,y:0};break;case j:r=u,n={x:1,y:.5};break;case X:a=d,r=u,n={x:1,y:1};break;case K:a=d,r=c,n={x:0,y:1};break;case G:a=g,r=c,n={x:0,y:0};break;case N:a=g,r=u,n={x:1,y:0}}return s&&(1!==r?a=r:r=a),$(o||n,t,n),{origin:n,scaleX:r,scaleY:a,direction:e,lockRatio:s,around:o}},getRotateData(t,e,s,o,n){let r;switch(e){case X:r={x:1,y:1};break;case K:r={x:0,y:1};break;case G:r={x:0,y:0};break;case N:r={x:1,y:0};break;default:r={x:.5,y:.5}}return $(n||r,t,r),{origin:r,rotation:i.PointHelper.getRotation(o,r,s)}},getSkewData(t,e,s,o){let n,r,a=0,l=0;switch(e){case Y:r={x:.5,y:0},n={x:.5,y:1},a=1;break;case U:r={x:.5,y:1},n={x:.5,y:0},a=1;break;case j:r={x:0,y:.5},n={x:1,y:.5},l=1;break;case F:r={x:1,y:.5},n={x:0,y:.5},l=1}const{x:h,y:d,width:c,height:g}=t;r.x=h+r.x*c,r.y=d+r.y*g,$(o||n,t,n);const u=i.PointHelper.getRotation(r,n,{x:r.x+(a?s.x:0),y:r.y+(l?s.y:0)});return a?a=-u:l=u,{origin:n,skewX:a,skewY:l}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case j:t=F;break;case X:t=K;break;case N:t=G;break;case F:t=j;break;case K:t=X;break;case G:t=N}if(i)switch(t){case Y:t=U;break;case X:t=N;break;case K:t=G;break;case U:t=Y;break;case N:t=X;break;case G:t=K}return t}};function q(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.hasTarget||!i.visible)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:l,rotateable:h,skewable:d}=t.config,{pointType:c}=s,{flippedX:g,flippedY:u}=i;let f="resize"===c;f&&h&&(e.metaKey||e.ctrlKey||!l)&&(f=!1);const p=d&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(Q.getFlipDirection(s.direction,g,u)+1);const{url:L,x:v,y:y}=p;s.cursor={url:tt(L,o),x:v,y:y}}function J(t){t.editBox.rect.cursor=t.config.moveCursor}function tt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class et extends i.Box{}const it=["top","right","bottom","left"];class st 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.rect=new i.Box({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new et({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new i.Group({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{resizePoints:s,rotatePoints:o,resizeLines:n,rect:r,circle:a,buttons:l}=this,h=[{x:1,y:1},{x:.5,y:1},{x:0,y:1},{x:0,y:.5},{x:0,y:0},{x:.5,y:0},{x:1,y:0},{x:1,y:.5}];for(let r=0;r<8;r++)t=new et({name:"rotate-point",around:h[r],width:15,height:15,hitFill:"all"}),o.push(t),this.listenPointEvents(t,"rotate",r),r%2&&(e=new et({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",r)),i=new et({name:"resize-point",around:"center",strokeAlign:"center",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",r);l.add(a),this.listenPointEvents(a,"rotate",2),this.addMany(...o,r,l,...n,...s)}update(t){const{config:e,list:s}=this.editor,{width:o,height:n}=t,{rect:r,circle:a,resizePoints:l,rotatePoints:h,resizeLines:d}=this,{middlePoint:c,resizeable:g,rotateable:u,stroke:f,strokeWidth:p}=e,L=this.getPointsStyle(),v=this.getMiddlePointsStyle(),y=o>20||n>20;this.visible=s[0]&&!s[0].locked;let w,k,x,_,b={};for(let e=0;e<8;e++)i.AroundHelper.toPoint(i.AroundHelper.directionData[e],t,b),w=this.getPointStyle(e%2?v[(e-1)/2%v.length]:L[e/2%L.length]),x=l[e],k=h[e],_=d[Math.floor(e/2)],x.set(w),x.set(b),k.set(b),_.set(b),x.visible=_.visible=y&&(g||u),k.visible=y&&u&&g,e%2?(x.visible=k.visible=y&&!!c,(e+1)/2%2?(_.width=o,x.width>o-30&&(x.visible=!1)):(_.height=n,x.rotation=90,x.width>n-30&&(x.visible=!1))):x.rotation=e/2*90;a.visible=y&&u&&!!e.rotatePoint,a.set(this.getPointStyle(e.rotatePoint||L[0])),r.set(Object.assign({stroke:f,strokeWidth:p},e.rect||{})),r.set(Object.assign(Object.assign({},t),{visible:!0})),this.buttons.visible=y,this.layoutButtons()}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.config,{flippedX:r,flippedY:a}=this;let l=it.indexOf(i);(l%2&&r||(l+1)%2&&a)&&s&&(l=(l+2)%4);const h=s?Q.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,d=e[2*h+1],c=h%2,g=h&&3!==h?1:-1,u=(o+(l%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),s&&(t.rotation=90*(h-l),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.config,r={fill:s,stroke:e,strokeWidth:i,width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.config;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.config;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onDragStart(t){this.dragging=!0,"rect"===t.target.name&&(this.moving=!0,this.editor.opacity=this.editor.config.hideOnMove?0:1)}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.target.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.config.resizeable?(e.config.rotateable&&e.onRotate(t),q(e,t)):e.onScale(t)}onArrow(t){if(this.editor.hasTarget){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}(e.x||e.y)&&this.editor.move(e.x,e.y)}}onDoubleClick(){const{editor:t}=this;t.single&&t.element.isBranch}listenPointEvents(t,e,s){const{editor:o}=this;t.direction=s,t.pointType=e,t.on_(i.DragEvent.START,this.onDragStart,this),t.on_(i.DragEvent.DRAG,this.onDrag,this),t.on_(i.DragEvent.END,this.onDragEnd,this),t.on_(i.PointerEvent.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(i.PointerEvent.ENTER,(e=>{this.enterPoint=t,q(o,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(_.SELECT,(()=>{this.visible=e.hasTarget})),t.on_(i.DragEvent.START,this.onDragStart,this),t.on_(i.DragEvent.DRAG,e.onMove,e),t.on_(i.DragEvent.END,this.onDragEnd,this),t.on_(i.PointerEvent.ENTER,(()=>J(e))),t.on_(i.PointerEvent.DOUBLE_CLICK,this.onDoubleClick,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const ot='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',nt={editSize:"auto",stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${ot}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},rotateCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(135,12,12),rotate({{rotation}},12,12)">\n<path d="M20.4 8H21.4L20.8 7.1L17.3 2.6L17 2.1L16.6 2.6L13.1 7.1L12.5 8H13.5H15.4C14.9 11.8 11.8 14.9 8 15.4V13.5V12.5L7.1 13.1L2.6 16.6L2.1 17L2.6 17.3L7.1 20.8L8 21.4V20.4V18.4C13.5 17.9 17.9 13.5 18.4 8H20.4Z" stroke="white"/>\n<path fill-rule="evenodd" d="M17 3L20.4 7.5H17.9C17.7 13.1 13.1 17.7 7.5 17.9V20.4L3 17L7.5 13.5V15.9C12.0 15.7 15.7 12.0 15.9 7.5H13.5L17 3Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">\n${ot}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},skewCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(90,12,12),rotate({{rotation}},12,12)">\n<path d="M21 10.4L21 11.4L23.8 11.4L21.6 9.6L21 10.4ZM17 10.4V11.4L17 11.4L17 10.4ZM15.5 6L16.1 5.2L14.5 3.9V6H15.5ZM15.5 8.4V9.4H16.5V8.4H15.5ZM6 8.4V7.4H5V8.4H6ZM6 10.4H5V11.4H6V10.4ZM7 14.4V13.4L7 13.4L7 14.4ZM3 14.4L3 13.4L0.1 13.4L2.3 15.2L3 14.4ZM8.5 18.9L7.8 19.7L9.5 21.0V18.9H8.5ZM8.5 16.4V15.4H7.5V16.4H8.5ZM19 16.4V17.4H20V16.4H19ZM19 14.4H20V13.4H19V14.4ZM21 9.4L17 9.4L17 11.4L21 11.4L21 9.4ZM14.8 6.7L20.3 11.2L21.6 9.6L16.1 5.2L14.8 6.7ZM16.5 8.4V6H14.5V8.4H16.5ZM6 9.4H15.5V7.4H6V9.4ZM7 10.4V8.4H5V10.4H7ZM15.5 9.4H6V11.4H15.5V9.4ZM17 9.4H15.5V11.4H17V9.4ZM7 15.4H8.5V13.4H7V15.4ZM3 15.4L7 15.4L7 13.4L3 13.4L3 15.4ZM9.1 18.1L3.6 13.6L2.3 15.2L7.8 19.7L9.1 18.1ZM7.5 16.4V18.9H9.5V16.4H7.5ZM19 15.4H8.5V17.4H19V15.4ZM18 14.4V16.4H20V14.4H18ZM8.5 15.4H19V13.4H8.5V15.4Z" fill="white"/>\n<path fill-rule="evenodd" d="M17 10.4L21 10.4L15.5 6V8.4H6V10.4H15.5H17ZM8.5 14.4H7L3 14.4L8.5 18.9V16.4H19V14.4H8.5Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >\n${ot}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,boxSelect:!0,resizeable:!0,rotateable:!0,skewable:!0},{transformWorld:rt,zoomOfWorld:at,skewOfWorld:lt,rotateOfWorld:ht,moveWorld:dt}=i.LeafHelper;class ct{constructor(){this.tag="EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{dt(t,e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?rt(t,s,r):at(t,o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="size"===o.getEditSize(t);i?rt(t,i,n):ht(t,s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?rt(t,s,r):lt(t,o,e,i,r)})),r.unlockLayout()}update(t){const{simulateTarget:e,element:i}=t;t.multiple&&e.parent.updateLayout();const{x:s,y:o,scaleX:n,scaleY:r,rotation:a,skewX:l,skewY:h,width:d,height:c}=i.getLayoutBounds("box",t,!0);t.editBox.set({x:s,y:o,scaleX:n,scaleY:r,rotation:a,skewX:l,skewY:h}),t.editBox.update({x:0,y:0,width:d,height:c})}}ct.list=[];const{left:gt,right:ut}=C;class ft extends ct{constructor(){super(...arguments),this.tag="LineEditTool",this.scaleOfEvent=!0}onScaleWithDrag(t){const{drag:e,direction:s,lockRatio:o,around:n}=t,r=t.target,a=i.getPointData(),{toPoint:l}=r;r.rotation=0;let{x:h,y:d}=e.getInnerMove(r);o&&(Math.abs(h)>Math.abs(d)?d=0:h=0),s===gt?(a.x+=h,a.y+=d,n&&(l.x-=h,l.y-=d)):(n&&(a.x-=h,a.y-=d),l.x+=h,l.y+=d),r.getLocalPointByInner(a,null,null,!0),r.getLocalPointByInner(l,null,null,!0),r.x=a.x,r.y=a.y,r.getInnerPointByLocal(l,null,null,!0),r.toPoint=l}onSkew(t){}update(t){const{rotatePoints:e,resizeLines:i,resizePoints:s}=t.editBox;super.update(t);for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),s[t].visible=e[t].visible=t===gt||t===ut}}const pt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Lt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),vt={group(t,e,s){t.sort(Lt);const{app:o,parent:n}=t[0];let r;r=s&&s.add?s:new i.Group(s),n.addAt(r,n.children.indexOf(t[0])),t.sort(pt);const a=new i.Matrix(e.worldTransform);return a.divideParent(n.worldTransform),r.setTransform(a),r.editable=!0,r.hitChildren=!1,o.lockLayout(),t.forEach((t=>t.dropTo(r))),o.unlockLayout(),r},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(pt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Lt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}};class yt extends i.Group{get list(){return this.leafList.list}get hasTarget(){return!!this.list.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}get dragging(){return this.editBox.dragging}constructor(t,e){super(e),this.config=nt,this.leafList=new i.LeafList,this.simulateTarget=new i.Rect({visible:!1}),this.editBox=new st(this),this.selector=new W(this),this.targetEventIds=[],t&&(this.config=i.DataHelper.default(t,this.config)),this.addMany(this.selector,this.editBox)}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.target&&(this.editTool&&this.editTool.update(this),this.selector.update())}updateEditTool(){this.editTool=function(t){if(1===t.length){const e=t[0];return e instanceof i.Line&&!e.points?new ft:new ct}return new ct}(this.list)}getEditSize(t){let{editSize:e}=this.config;return"auto"===e?t.editSize:e}onMove(t){const e=t.getLocalMove(this.element);t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(e.x,e.y)}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.config;t.shiftKey&&(o=!0);const n=Q.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,Q.getAround(s,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}onRotate(t){const{skewable:e,around:s,rotateGap:o}=this.config,{direction:n,name:r}=t.current;if(e&&"resize-line"===r)return this.onSkew(t);const{element:a}=this;let l,h;if(t instanceof i.RotateEvent)h=t.rotation,l=a.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=Q.getRotateData(a.boxBounds,n,t.getInner(a),a.getInnerPoint(e),t.shiftKey?null:s||"center");h=i.rotation,l=i.origin}h=i.MathHelper.getGapRotation(h,o,a.rotation),h&&(a.scaleX*a.scaleY<0&&(h=-h),this.rotateOf(l,i.MathHelper.float(h,2)))}onSkew(t){const{element:e}=this,{around:i}=this.config,{origin:s,skewX:o,skewY:n}=Q.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Q.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e){const{element:i}=this,s=i.getWorldPointByLocal({x:t,y:e},null,!0),o=new b(b.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o),this.multiple&&i.move(t,e)}scaleWithDrag(t){const{element:e}=this,i=e.getWorldPoint(t.origin),s=new m(m.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(s),this.emitEvent(s)}scaleOf(t,e,s=e,o){const{element:n}=this,r=n.getWorldPoint(t);let a;if(this.multiple){const o=new i.Matrix(n.worldTransform);n.scaleOf(t,e,s),a=new i.Matrix(n.worldTransform).divide(o)}const l=new m(m.SCALE,{target:n,editor:this,worldOrigin:r,scaleX:e,scaleY:s,transform:a});this.editTool.onScale(l),this.emitEvent(l)}rotateOf(t,e){const{element:s}=this,o=s.getWorldPoint(t);let n;if(this.multiple){const o=new i.Matrix(s.worldTransform);s.rotateOf(t,e),n=new i.Matrix(s.worldTransform).divide(o)}const r=new E(E.ROTATE,{target:s,editor:this,worldOrigin:o,rotation:e,transform:n});this.editTool.onRotate(r),this.emitEvent(r)}skewOf(t,e,s=0,o){const{element:n}=this,r=n.getWorldPoint(t);let a;if(this.multiple){const o=new i.Matrix(n.worldTransform);n.skewOf(t,e,s),a=new i.Matrix(n.worldTransform).divide(o)}const l=new M(M.SKEW,{target:n,editor:this,skewX:e,skewY:s,transform:a,worldOrigin:r});this.editTool.onSkew(l),this.emitEvent(l)}group(t){return this.multiple&&(this.target=vt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=vt.ungroup(this.list)),this.list}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(vt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(vt.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_([i.KeyEvent.HOLD,i.KeyEvent.UP],(t=>{q(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(),this.target=this.hoverTarget=this.simulateTarget=null,super.destroy())}}return x([H((function(t,e){t.emitEvent(new _(_.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],yt.prototype,"hoverTarget",void 0),x([H((function(t,e){const{target:s}=t;s?t.leafList=s instanceof i.LeafList?s:new i.LeafList(s):t.leafList.reset(),t.emitEvent(new _(_.SELECT,{editor:t,value:s,oldValue:e})),t.hasTarget?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:s}=t,{x:o,y:n,width:r,height:a}=(new i.Bounds).setListWithFn(s.list,(t=>t.worldBoxBounds)),l=e.parent=s.list[0].leafer.zoomLayer,{scaleX:h,scaleY:d,e:c,f:g}=l.__world;e.reset({x:(o-c)/h,y:(n-g)/d,width:r/h,height:a/d})}(t),J(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):t.removeTargetEvents()}))],yt.prototype,"target",void 0),i.Creator.editor=function(t){return new yt(t)},t.EditBox=st,t.EditDataHelper=Q,t.EditPoint=et,t.EditSelect=W,t.EditSelectHelper=z,t.EditTool=ct,t.Editor=yt,t.EditorEvent=_,t.EditorHelper=vt,t.EditorMoveEvent=b,t.EditorRotateEvent=E,t.EditorScaleEvent=m,t.EditorSkewEvent=M,t.LineEditTool=ft,t.SelectArea=O,t.Stroker=D,t}({},LeaferUI,LeaferUI);
|
|
1
|
+
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.editor=function(t,e,i){"use strict";const{M:s,L:o,C:n,Q:r,Z:a,N:l,D:h,X:d,G:c,F:g,O:u,P:f,U:p}=e.PathCommandMap,L={scale(t,e,i){if(!t)return;let L,y=0,w=t.length;for(;y<w;)switch(L=t[y],L){case s:case o:v(t,e,i,y,1),y+=3;break;case n:v(t,e,i,y,3),y+=7;break;case r:v(t,e,i,y,2),y+=5;break;case a:y+=1;break;case l:v(t,e,i,y,2),y+=5;break;case h:v(t,e,i,y,2),y+=9;break;case d:v(t,e,i,y,2),y+=6;break;case c:v(t,e,i,y,2),y+=9;break;case g:v(t,e,i,y,2),y+=5;break;case u:t[y]=c,t.splice(y+4,0,t[y+3],0),v(t,e,i,y,2),y+=9,w+=2;break;case f:t[y]=g,t.splice(y+4,0,t[y+3]),v(t,e,i,y,2),y+=5,w+=1;break;case p:v(t,e,i,y,2),y+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:v}=L;function y(t,e,i){1!==e&&(t.width*=e),1!==i&&(t.height*=i)}e.Leaf.prototype.scaleResize=function(t,e=t,i){const s=this;i?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},e.Leaf.prototype.__scaleResize=function(t,e){y(this,t,e)},e.Path.prototype.__scaleResize=function(t,e){L.scale(this.__.path,t,e),this.path=this.__.path},e.Line.prototype.__scaleResize=function(t,e){if(this.points)L.scalePoints(this.__.points,t,e),this.points=this.__.points;else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},e.Polygon.prototype.__scaleResize=function(t,e){this.points?(L.scalePoints(this.__.points,t,e),this.points=this.__.points):y(this,t,e)};const w=e.MatrixHelper.get();function _(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)w.a=e,w.d=i,s[t].transform(w,!0)}function k(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}e.Group.prototype.__scaleResize=function(t,e){_(this,t,e)},e.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?_(this,t,e):y(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class x extends i.Event{constructor(t,e){super(t),e&&Object.assign(this,e)}}x.SELECT="editor.select",x.HOVER="editor.hover";class b extends x{constructor(t,e){super(t,e)}}b.MOVE="editor.move";class m extends x{constructor(t,e){super(t,e)}}m.SCALE="editor.scale";class E extends x{constructor(t,e){super(t,e)}}E.ROTATE="editor.rotate";class M extends x{constructor(t,e){super(t,e)}}function H(t){return(e,s)=>{const o="_"+s;i.defineKey(e,s,{get(){return this[o]},set(e){const i=this[o];i!==e&&(this[o]=e,t(this,i))}})}}M.SKEW="editor.skew";const S=i.MatrixHelper.get(),{abs:V}=Math,{copy:P,scale:T}=i.MatrixHelper;class D extends i.UI{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){const{stroke:i,strokeWidth:s}=e;this.set({stroke:i,strokeWidth:s}),this.target=t}__draw(t,e){const{list:s}=this;if(s.length){let o;const{stroke:n,strokeWidth:r}=this.__,{bounds:a}=e;for(let l=0;l<s.length;l++)if(o=s[l],a&&a.hit(o.__world,e.matrix)){let s;if("scale"===o.__.editSize){const i=V(o.__world.scaleX),n=V(o.__world.scaleY);if(i!==n){P(S,o.__world),T(S,1/i,1/n),t.setWorld(S,e.matrix),t.beginPath(),this.__.strokeWidth=r;const{x:a,y:l,width:h,height:d}=o.__layout.boxBounds;t.rect(a*i,l*n,h*i,d*n),s=!0}}s||(t.setWorld(o.__world,e.matrix),t.beginPath(),o.__.__useArrow?o.__drawPath(t):o.__.__pathForRender?o.__drawRenderPath(t):o.__drawPathByBox(t),this.__.strokeWidth=r/V(o.__world.scaleX)),"string"==typeof n?i.Paint.stroke(n,this,t):i.Paint.strokes(n,this,t)}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}k([H((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],D.prototype,"target",void 0);class O 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:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:R,Yes:A,NoAndSkip:B,YesAndSkip:Z}=i.Answer,z={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?Z:B;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?Z:R;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return A}return R}return t.isBranch?B:R}},{findOne:I}=z;class W extends i.Group{get dragging(){return!!this.originList}get running(){return this.editor.hittable&&this.editor.config.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new D,this.targetStroker=new D,this.bounds=new i.Bounds,this.selectArea=new O,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:s}=t.config;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,{stroke:e,strokeWidth:i})}}onSelect(){if(this.running){const{config:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/2)}),this.hoverStroker.target=null}}update(){this.running&&this.targetStroker.forceUpdate()}onPointerMove(t){if(this.running&&!this.isMoveMode){const e=t.shiftKey?this.findDeepOne(t):I(t.path);this.editor.hoverTarget=this.editor.hasItem(e)?null:e}this.isMoveMode&&(this.editor.hoverTarget=null)}onBeforeDown(t){if(this.running&&!this.isMoveMode&&!t.middle){const e=this.lastDownLeaf=I(t.path);e?(t.shiftKey?this.editor.shiftItem(e):this.editor.target=e,this.editor.updateLayout(),e.locked||this.app.interaction.updateDownData(null,{findList:[this.editor.editBox.rect]})):this.allow(t.target)&&(t.shiftKey||(this.editor.target=null))}}onTap(t){if(this.running&&t.shiftKey&&!t.middle&&!this.lastDownLeaf){const e=this.findDeepOne(t);e&&this.editor.shiftItem(e)}else this.isMoveMode&&(this.editor.target=null);this.lastDownLeaf=null}onDragStart(t){if(this.running&&this.allowDrag(t)){const{editor:e}=this,{stroke:i,strokeWidth:s,area:o}=e.config,{x:n,y:r}=t.getInner(this);this.bounds.set(n,r),this.selectArea.setStyle({visible:!0,stroke:i,strokeWidth:s,x:n,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:e}=this,s=t.getInnerTotal(this),o=this.bounds.clone().unsign(),n=new i.LeafList(e.app.find(z.findBounds,o));if(this.bounds.width=s.x,this.bounds.height=s.y,this.selectArea.setBounds(o.get()),n.length){const t=[];this.originList.forEach((e=>{n.has(e)||t.push(e)})),n.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list,e.leafList.length&&e.update()}}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.editor.config.boxSelect||t.target.draggable)&&(!this.editor.hasTarget&&this.allow(t.target)||t.shiftKey&&!I(t.path))}findDeepOne(t){const e={exclude:new i.LeafList(this.editor.editBox.rect)};return I(t.target.leafer.interaction.findPath(t,e))}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(x.HOVER,this.onHover,this),t.on_(x.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.lastDownLeaf=null,this.__removeListenEvents(),super.destroy()}}var C;!function(t){t[t.topLeft=0]="topLeft",t[t.top=1]="top",t[t.topRight=2]="topRight",t[t.right=3]="right",t[t.bottomRight=4]="bottomRight",t[t.bottom=5]="bottom",t[t.bottomLeft=6]="bottomLeft",t[t.left=7]="left"}(C||(C={}));const{topLeft:X,top:Y,topRight:K,right:F,bottomRight:G,bottom:U,bottomLeft:N,left:j}=C,{toPoint:$}=i.AroundHelper,Q={getScaleData(t,e,i,s,o){let n,r=1,a=1;const{width:l,height:h}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===l&&(i.x+=.1),Math.abs(i.y)===h&&(i.y+=.1);const d=(-i.y+h)/h,c=(i.x+l)/l,g=(i.y+h)/h,u=(-i.x+l)/l;switch(e){case Y:a=d,n={x:.5,y:1};break;case F:r=c,n={x:0,y:.5};break;case U:a=g,n={x:.5,y:0};break;case j:r=u,n={x:1,y:.5};break;case X:a=d,r=u,n={x:1,y:1};break;case K:a=d,r=c,n={x:0,y:1};break;case G:a=g,r=c,n={x:0,y:0};break;case N:a=g,r=u,n={x:1,y:0}}return s&&(1!==r?a=r:r=a),$(o||n,t,n),{origin:n,scaleX:r,scaleY:a,direction:e,lockRatio:s,around:o}},getRotateData(t,e,s,o,n){let r;switch(e){case X:r={x:1,y:1};break;case K:r={x:0,y:1};break;case G:r={x:0,y:0};break;case N:r={x:1,y:0};break;default:r={x:.5,y:.5}}return $(n||r,t,r),{origin:r,rotation:i.PointHelper.getRotation(o,r,s)}},getSkewData(t,e,s,o){let n,r,a=0,l=0;switch(e){case Y:r={x:.5,y:0},n={x:.5,y:1},a=1;break;case U:r={x:.5,y:1},n={x:.5,y:0},a=1;break;case j:r={x:0,y:.5},n={x:1,y:.5},l=1;break;case F:r={x:1,y:.5},n={x:0,y:.5},l=1}const{x:h,y:d,width:c,height:g}=t;r.x=h+r.x*c,r.y=d+r.y*g,$(o||n,t,n);const u=i.PointHelper.getRotation(r,n,{x:r.x+(a?s.x:0),y:r.y+(l?s.y:0)});return a?a=-u:l=u,{origin:n,skewX:a,skewY:l}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case j:t=F;break;case X:t=K;break;case N:t=G;break;case F:t=j;break;case K:t=X;break;case G:t=N}if(i)switch(t){case Y:t=U;break;case X:t=N;break;case K:t=G;break;case U:t=Y;break;case N:t=X;break;case G:t=K}return t}};function q(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.hasTarget||!i.visible)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:l,rotateable:h,skewable:d}=t.config,{pointType:c}=s,{flippedX:g,flippedY:u}=i;let f="resize"===c;f&&h&&(e.metaKey||e.ctrlKey||!l)&&(f=!1);const p=d&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(Q.getFlipDirection(s.direction,g,u)+1);const{url:L,x:v,y:y}=p;s.cursor={url:tt(L,o),x:v,y:y}}function J(t){t.editBox.rect.cursor=t.config.moveCursor}function tt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class et extends i.Box{}const it=["top","right","bottom","left"];class st 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.rect=new i.Box({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new et({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new i.Group({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{resizePoints:s,rotatePoints:o,resizeLines:n,rect:r,circle:a,buttons:l}=this,h=[{x:1,y:1},{x:.5,y:1},{x:0,y:1},{x:0,y:.5},{x:0,y:0},{x:.5,y:0},{x:1,y:0},{x:1,y:.5}];for(let r=0;r<8;r++)t=new et({name:"rotate-point",around:h[r],width:15,height:15,hitFill:"all"}),o.push(t),this.listenPointEvents(t,"rotate",r),r%2&&(e=new et({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",r)),i=new et({name:"resize-point",around:"center",strokeAlign:"center",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",r);l.add(a),this.listenPointEvents(a,"rotate",2),this.addMany(...o,r,l,...n,...s)}update(t){const{config:e,list:s}=this.editor,{width:o,height:n}=t,{rect:r,circle:a,resizePoints:l,rotatePoints:h,resizeLines:d}=this,{middlePoint:c,resizeable:g,rotateable:u,stroke:f,strokeWidth:p}=e,L=this.getPointsStyle(),v=this.getMiddlePointsStyle(),y=o>20||n>20;this.visible=s[0]&&!s[0].locked;let w,_,k,x,b={};for(let e=0;e<8;e++)i.AroundHelper.toPoint(i.AroundHelper.directionData[e],t,b),w=this.getPointStyle(e%2?v[(e-1)/2%v.length]:L[e/2%L.length]),k=l[e],_=h[e],x=d[Math.floor(e/2)],k.set(w),k.set(b),_.set(b),x.set(b),k.visible=x.visible=y&&(g||u),_.visible=y&&u&&g,e%2?(k.visible=_.visible=y&&!!c,(e+1)/2%2?(x.width=o,k.width>o-30&&(k.visible=!1)):(x.height=n,k.rotation=90,k.width>n-30&&(k.visible=!1))):k.rotation=e/2*90;a.visible=y&&u&&!!e.rotatePoint,a.set(this.getPointStyle(e.rotatePoint||L[0])),r.set(Object.assign({stroke:f,strokeWidth:p},e.rect||{})),r.set(Object.assign(Object.assign({},t),{visible:!0})),this.buttons.visible=y,this.layoutButtons()}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.config,{flippedX:r,flippedY:a}=this;let l=it.indexOf(i);(l%2&&r||(l+1)%2&&a)&&s&&(l=(l+2)%4);const h=s?Q.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,d=e[2*h+1],c=h%2,g=h&&3!==h?1:-1,u=(o+(l%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),s&&(t.rotation=90*(h-l),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.config,r={fill:s,stroke:e,strokeWidth:i,width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.config;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.config;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onDragStart(t){this.dragging=!0,"rect"===t.target.name&&(this.moving=!0,this.editor.opacity=this.editor.config.hideOnMove?0:1)}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.target.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.config.resizeable?(e.config.rotateable&&e.onRotate(t),q(e,t)):e.onScale(t)}onArrow(t){if(this.editor.hasTarget){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}(e.x||e.y)&&this.editor.move(e.x,e.y)}}onDoubleClick(){const{editor:t}=this;t.single&&t.element.isBranch}listenPointEvents(t,e,s){const{editor:o}=this;t.direction=s,t.pointType=e,t.on_(i.DragEvent.START,this.onDragStart,this),t.on_(i.DragEvent.DRAG,this.onDrag,this),t.on_(i.DragEvent.END,this.onDragEnd,this),t.on_(i.PointerEvent.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(i.PointerEvent.ENTER,(e=>{this.enterPoint=t,q(o,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(x.SELECT,(()=>{this.visible=e.hasTarget})),t.on_(i.DragEvent.START,this.onDragStart,this),t.on_(i.DragEvent.DRAG,e.onMove,e),t.on_(i.DragEvent.END,this.onDragEnd,this),t.on_(i.PointerEvent.ENTER,(()=>J(e))),t.on_(i.PointerEvent.DOUBLE_CLICK,this.onDoubleClick,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const ot='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',nt={editSize:"auto",stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${ot}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},rotateCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(135,12,12),rotate({{rotation}},12,12)">\n<path d="M20.4 8H21.4L20.8 7.1L17.3 2.6L17 2.1L16.6 2.6L13.1 7.1L12.5 8H13.5H15.4C14.9 11.8 11.8 14.9 8 15.4V13.5V12.5L7.1 13.1L2.6 16.6L2.1 17L2.6 17.3L7.1 20.8L8 21.4V20.4V18.4C13.5 17.9 17.9 13.5 18.4 8H20.4Z" stroke="white"/>\n<path fill-rule="evenodd" d="M17 3L20.4 7.5H17.9C17.7 13.1 13.1 17.7 7.5 17.9V20.4L3 17L7.5 13.5V15.9C12.0 15.7 15.7 12.0 15.9 7.5H13.5L17 3Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">\n${ot}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},skewCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(90,12,12),rotate({{rotation}},12,12)">\n<path d="M21 10.4L21 11.4L23.8 11.4L21.6 9.6L21 10.4ZM17 10.4V11.4L17 11.4L17 10.4ZM15.5 6L16.1 5.2L14.5 3.9V6H15.5ZM15.5 8.4V9.4H16.5V8.4H15.5ZM6 8.4V7.4H5V8.4H6ZM6 10.4H5V11.4H6V10.4ZM7 14.4V13.4L7 13.4L7 14.4ZM3 14.4L3 13.4L0.1 13.4L2.3 15.2L3 14.4ZM8.5 18.9L7.8 19.7L9.5 21.0V18.9H8.5ZM8.5 16.4V15.4H7.5V16.4H8.5ZM19 16.4V17.4H20V16.4H19ZM19 14.4H20V13.4H19V14.4ZM21 9.4L17 9.4L17 11.4L21 11.4L21 9.4ZM14.8 6.7L20.3 11.2L21.6 9.6L16.1 5.2L14.8 6.7ZM16.5 8.4V6H14.5V8.4H16.5ZM6 9.4H15.5V7.4H6V9.4ZM7 10.4V8.4H5V10.4H7ZM15.5 9.4H6V11.4H15.5V9.4ZM17 9.4H15.5V11.4H17V9.4ZM7 15.4H8.5V13.4H7V15.4ZM3 15.4L7 15.4L7 13.4L3 13.4L3 15.4ZM9.1 18.1L3.6 13.6L2.3 15.2L7.8 19.7L9.1 18.1ZM7.5 16.4V18.9H9.5V16.4H7.5ZM19 15.4H8.5V17.4H19V15.4ZM18 14.4V16.4H20V14.4H18ZM8.5 15.4H19V13.4H8.5V15.4Z" fill="white"/>\n<path fill-rule="evenodd" d="M17 10.4L21 10.4L15.5 6V8.4H6V10.4H15.5H17ZM8.5 14.4H7L3 14.4L8.5 18.9V16.4H19V14.4H8.5Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >\n${ot}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,boxSelect:!0,resizeable:!0,rotateable:!0,skewable:!0},{transformWorld:rt,zoomOfWorld:at,skewOfWorld:lt,rotateOfWorld:ht,moveWorld:dt}=i.LeafHelper;class ct{constructor(){this.tag="EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{dt(t,e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?rt(t,s,r):at(t,o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="size"===o.getEditSize(t);i?rt(t,i,n):ht(t,s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?rt(t,s,r):lt(t,o,e,i,r)})),r.unlockLayout()}update(t){const{simulateTarget:e,element:i}=t;t.multiple&&e.parent.updateLayout();const{x:s,y:o,scaleX:n,scaleY:r,rotation:a,skewX:l,skewY:h,width:d,height:c}=i.getLayoutBounds("box",t,!0);t.editBox.set({x:s,y:o,scaleX:n,scaleY:r,rotation:a,skewX:l,skewY:h}),t.editBox.update({x:0,y:0,width:d,height:c})}}ct.list=[];const{left:gt,right:ut}=C;class ft extends ct{constructor(){super(...arguments),this.tag="LineEditTool",this.scaleOfEvent=!0}onScaleWithDrag(t){const{drag:e,direction:s,lockRatio:o,around:n}=t,r=t.target,a=i.getPointData(),{toPoint:l}=r;r.rotation=0;let{x:h,y:d}=e.getInnerMove(r);o&&(Math.abs(h)>Math.abs(d)?d=0:h=0),s===gt?(a.x+=h,a.y+=d,n&&(l.x-=h,l.y-=d)):(n&&(a.x-=h,a.y-=d),l.x+=h,l.y+=d),r.getLocalPointByInner(a,null,null,!0),r.getLocalPointByInner(l,null,null,!0),r.x=a.x,r.y=a.y,r.getInnerPointByLocal(l,null,null,!0),r.toPoint=l}onSkew(t){}update(t){const{rotatePoints:e,resizeLines:i,resizePoints:s}=t.editBox;super.update(t);for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),s[t].visible=e[t].visible=t===gt||t===ut}}const pt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Lt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),vt={group(t,e,s){t.sort(Lt);const{app:o,parent:n}=t[0];let r;r=s&&s.add?s:new i.Group(s),n.addAt(r,n.children.indexOf(t[0])),t.sort(pt);const a=new i.Matrix(e.worldTransform);return a.divideParent(n.worldTransform),r.setTransform(a),r.editable=!0,r.hitChildren=!1,o.lockLayout(),t.forEach((t=>t.dropTo(r))),o.unlockLayout(),r},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(pt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Lt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}};class yt extends i.Group{get list(){return this.leafList.list}get hasTarget(){return!!this.list.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}get dragging(){return this.editBox.dragging}constructor(t,e){super(e),this.config=nt,this.leafList=new i.LeafList,this.simulateTarget=new i.Rect({visible:!1}),this.editBox=new st(this),this.selector=new W(this),this.targetEventIds=[],t&&(this.config=i.DataHelper.default(t,this.config)),this.addMany(this.selector,this.editBox)}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.target&&(this.editTool&&this.editTool.update(this),this.selector.update())}updateEditTool(){this.editTool=function(t){if(1===t.length){const e=t[0];return e instanceof i.Line&&!e.points?new ft:new ct}return new ct}(this.list)}getEditSize(t){let{editSize:e}=this.config;return"auto"===e?t.editSize:e}onMove(t){const e=t.getLocalMove(this.element);t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(e.x,e.y)}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.config;t.shiftKey&&(o=!0);const n=Q.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,Q.getAround(s,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}onRotate(t){const{skewable:e,around:s,rotateGap:o}=this.config,{direction:n,name:r}=t.current;if(e&&"resize-line"===r)return this.onSkew(t);const{element:a}=this;let l,h;if(t instanceof i.RotateEvent)h=t.rotation,l=a.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=Q.getRotateData(a.boxBounds,n,t.getInner(a),a.getInnerPoint(e),t.shiftKey?null:s||"center");h=i.rotation,l=i.origin}h=i.MathHelper.getGapRotation(h,o,a.rotation),h&&(a.scaleX*a.scaleY<0&&(h=-h),this.rotateOf(l,i.MathHelper.float(h,2)))}onSkew(t){const{element:e}=this,{around:i}=this.config,{origin:s,skewX:o,skewY:n}=Q.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Q.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e){const{element:i}=this,s=i.getWorldPointByLocal({x:t,y:e},null,!0),o=new b(b.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o),this.multiple&&i.move(t,e)}scaleWithDrag(t){const{element:e}=this,i=e.getWorldPoint(t.origin),s=new m(m.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(s),this.emitEvent(s)}scaleOf(t,e,s=e,o){const{element:n}=this,r=n.getWorldPoint(t);let a;if(this.multiple){const o=new i.Matrix(n.worldTransform);n.scaleOf(t,e,s),a=new i.Matrix(n.worldTransform).divide(o)}const l=new m(m.SCALE,{target:n,editor:this,worldOrigin:r,scaleX:e,scaleY:s,transform:a});this.editTool.onScale(l),this.emitEvent(l)}rotateOf(t,e){const{element:s}=this,o=s.getWorldPoint(t);let n;if(this.multiple){const o=new i.Matrix(s.worldTransform);s.rotateOf(t,e),n=new i.Matrix(s.worldTransform).divide(o)}const r=new E(E.ROTATE,{target:s,editor:this,worldOrigin:o,rotation:e,transform:n});this.editTool.onRotate(r),this.emitEvent(r)}skewOf(t,e,s=0,o){const{element:n}=this,r=n.getWorldPoint(t);let a;if(this.multiple){const o=new i.Matrix(n.worldTransform);n.skewOf(t,e,s),a=new i.Matrix(n.worldTransform).divide(o)}const l=new M(M.SKEW,{target:n,editor:this,skewX:e,skewY:s,transform:a,worldOrigin:r});this.editTool.onSkew(l),this.emitEvent(l)}group(t){return this.multiple&&(this.target=vt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=vt.ungroup(this.list)),this.list}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(vt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(vt.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_([i.KeyEvent.HOLD,i.KeyEvent.UP],(t=>{q(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(),this.target=this.hoverTarget=this.simulateTarget=null,super.destroy())}}return k([H((function(t,e){t.emitEvent(new x(x.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],yt.prototype,"hoverTarget",void 0),k([H((function(t,e){const{target:s}=t;s?t.leafList=s instanceof i.LeafList?s:new i.LeafList(s):t.leafList.reset(),t.emitEvent(new x(x.SELECT,{editor:t,value:s,oldValue:e})),t.hasTarget?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:s}=t,{x:o,y:n,width:r,height:a}=(new i.Bounds).setListWithFn(s.list,(t=>t.worldBoxBounds)),l=e.parent=s.list[0].leafer.zoomLayer,{scaleX:h,scaleY:d,e:c,f:g}=l.__world;e.reset({x:(o-c)/h,y:(n-g)/d,width:r/h,height:a/d})}(t),J(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):t.removeTargetEvents()}))],yt.prototype,"target",void 0),i.Creator.editor=function(t){return new yt(t)},t.EditBox=st,t.EditDataHelper=Q,t.EditPoint=et,t.EditSelect=W,t.EditSelectHelper=z,t.EditTool=ct,t.Editor=yt,t.EditorEvent=x,t.EditorHelper=vt,t.EditorMoveEvent=b,t.EditorRotateEvent=E,t.EditorScaleEvent=m,t.EditorSkewEvent=M,t.LineEditTool=ft,t.SelectArea=O,t.Stroker=D,t}({},LeaferUI,LeaferUI);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/editor",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.16",
|
|
4
4
|
"description": "@leafer-in/editor",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"leaferjs"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@leafer-ui/core": "1.0.0-rc.
|
|
32
|
-
"@leafer-ui/scale": "1.0.0-rc.
|
|
31
|
+
"@leafer-ui/core": "1.0.0-rc.16",
|
|
32
|
+
"@leafer-ui/scale": "1.0.0-rc.16"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@leafer-ui/interface": "1.0.0-rc.
|
|
36
|
-
"@leafer-in/interface": "1.0.0-rc.
|
|
35
|
+
"@leafer-ui/interface": "1.0.0-rc.16",
|
|
36
|
+
"@leafer-in/interface": "1.0.0-rc.16"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/src/display/Stroker.ts
CHANGED
|
@@ -63,7 +63,13 @@ export class Stroker extends UI implements IStroker {
|
|
|
63
63
|
if (!drewPath) {
|
|
64
64
|
canvas.setWorld(leaf.__world, options.matrix)
|
|
65
65
|
canvas.beginPath()
|
|
66
|
-
|
|
66
|
+
|
|
67
|
+
if (leaf.__.__useArrow) {
|
|
68
|
+
leaf.__drawPath(canvas)
|
|
69
|
+
} else {
|
|
70
|
+
leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas)
|
|
71
|
+
}
|
|
72
|
+
|
|
67
73
|
this.__.strokeWidth = strokeWidth / abs(leaf.__world.scaleX)
|
|
68
74
|
}
|
|
69
75
|
|