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

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.
@@ -258,21 +258,17 @@ class Stroker extends UI {
258
258
  for (let i = 0; i < list.length; i++) {
259
259
  leaf = list[i];
260
260
  if (bounds && bounds.hit(leaf.__world, options.matrix)) {
261
- let drewPath;
262
- if (leaf.__.editSize === 'scale') {
263
- const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
264
- if (aScaleX !== aScaleY) {
265
- copy(matrix, leaf.__world);
266
- scale(matrix, 1 / aScaleX, 1 / aScaleY);
267
- canvas.setWorld(matrix, options.matrix);
268
- canvas.beginPath();
269
- this.__.strokeWidth = strokeWidth;
270
- const { x, y, width, height } = leaf.__layout.boxBounds;
271
- canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
272
- drewPath = true;
273
- }
261
+ const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
262
+ if (aScaleX !== aScaleY) {
263
+ copy(matrix, leaf.__world);
264
+ scale(matrix, 1 / aScaleX, 1 / aScaleY);
265
+ canvas.setWorld(matrix, options.matrix);
266
+ canvas.beginPath();
267
+ this.__.strokeWidth = strokeWidth;
268
+ const { x, y, width, height } = leaf.__layout.boxBounds;
269
+ canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
274
270
  }
275
- if (!drewPath) {
271
+ else {
276
272
  canvas.setWorld(leaf.__world, options.matrix);
277
273
  canvas.beginPath();
278
274
  if (leaf.__.__useArrow) {
@@ -550,7 +546,7 @@ const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft,
550
546
  const { toPoint } = AroundHelper;
551
547
  const EditDataHelper = {
552
548
  getScaleData(bounds, direction, pointMove, lockRatio, around) {
553
- let origin, scaleX = 1, scaleY = 1;
549
+ let align, origin = {}, scaleX = 1, scaleY = 1;
554
550
  const { width, height } = bounds;
555
551
  if (around) {
556
552
  pointMove.x *= 2;
@@ -567,97 +563,100 @@ const EditDataHelper = {
567
563
  switch (direction) {
568
564
  case top:
569
565
  scaleY = topScale;
570
- origin = { x: 0.5, y: 1 };
566
+ align = 'bottom';
571
567
  break;
572
568
  case right$1:
573
569
  scaleX = rightScale;
574
- origin = { x: 0, y: 0.5 };
570
+ align = 'left';
575
571
  break;
576
572
  case bottom:
577
573
  scaleY = bottomScale;
578
- origin = { x: 0.5, y: 0 };
574
+ align = 'top';
579
575
  break;
580
576
  case left$1:
581
577
  scaleX = leftScale;
582
- origin = { x: 1, y: 0.5 };
578
+ align = 'right';
583
579
  break;
584
580
  case topLeft:
585
581
  scaleY = topScale;
586
582
  scaleX = leftScale;
587
- origin = { x: 1, y: 1 };
583
+ align = 'bottom-right';
588
584
  break;
589
585
  case topRight:
590
586
  scaleY = topScale;
591
587
  scaleX = rightScale;
592
- origin = { x: 0, y: 1 };
588
+ align = 'bottom-left';
593
589
  break;
594
590
  case bottomRight:
595
591
  scaleY = bottomScale;
596
592
  scaleX = rightScale;
597
- origin = { x: 0, y: 0 };
593
+ align = 'top-left';
598
594
  break;
599
595
  case bottomLeft:
600
596
  scaleY = bottomScale;
601
597
  scaleX = leftScale;
602
- origin = { x: 1, y: 0 };
598
+ align = 'top-right';
603
599
  }
604
600
  if (lockRatio) {
605
601
  const unlockSide = lockRatio === 'corner' && direction % 2;
606
- if (!unlockSide)
607
- scaleX = scaleY = Math.sqrt(scaleX * scaleY);
602
+ if (!unlockSide) {
603
+ const scale = Math.sqrt(Math.abs(scaleX * scaleY));
604
+ scaleX = scaleX < 0 ? -scale : scale;
605
+ scaleY = scaleY < 0 ? -scale : scale;
606
+ }
608
607
  }
609
- toPoint(around || origin, bounds, origin);
608
+ toPoint(around || align, bounds, origin);
610
609
  return { origin, scaleX, scaleY, direction, lockRatio, around };
611
610
  },
612
611
  getRotateData(bounds, direction, current, last, around) {
613
- let origin;
612
+ let align, origin = {};
614
613
  switch (direction) {
615
614
  case topLeft:
616
- origin = { x: 1, y: 1 };
615
+ align = 'bottom-right';
617
616
  break;
618
617
  case topRight:
619
- origin = { x: 0, y: 1 };
618
+ align = 'bottom-left';
620
619
  break;
621
620
  case bottomRight:
622
- origin = { x: 0, y: 0 };
621
+ align = 'top-left';
623
622
  break;
624
623
  case bottomLeft:
625
- origin = { x: 1, y: 0 };
624
+ align = 'top-right';
626
625
  break;
627
626
  default:
628
- origin = { x: 0.5, y: 0.5 };
627
+ align = 'center';
629
628
  }
630
- toPoint(around || origin, bounds, origin);
629
+ toPoint(around || align, bounds, origin);
631
630
  return { origin, rotation: PointHelper.getRotation(last, origin, current) };
632
631
  },
633
632
  getSkewData(bounds, direction, move, around) {
634
- let origin, skewX = 0, skewY = 0;
633
+ let align, origin = {}, skewX = 0, skewY = 0;
635
634
  let last;
636
635
  switch (direction) {
637
636
  case top:
638
637
  last = { x: 0.5, y: 0 };
639
- origin = { x: 0.5, y: 1 };
638
+ align = 'bottom';
640
639
  skewX = 1;
641
640
  break;
642
641
  case bottom:
643
642
  last = { x: 0.5, y: 1 };
644
- origin = { x: 0.5, y: 0 };
643
+ align = 'top';
645
644
  skewX = 1;
646
645
  break;
647
646
  case left$1:
648
647
  last = { x: 0, y: 0.5 };
649
- origin = { x: 1, y: 0.5 };
648
+ align = 'right';
650
649
  skewY = 1;
651
650
  break;
652
651
  case right$1:
653
652
  last = { x: 1, y: 0.5 };
654
- origin = { x: 0, y: 0.5 };
653
+ align = 'left';
655
654
  skewY = 1;
656
655
  }
657
656
  const { x, y, width, height } = bounds;
658
657
  last.x = x + last.x * width;
659
658
  last.y = y + last.y * height;
660
- toPoint(around || origin, bounds, origin);
659
+ toPoint(around || align, bounds, origin);
661
660
  const rotation = PointHelper.getRotation(last, origin, { x: last.x + (skewX ? move.x : 0), y: last.y + (skewY ? move.y : 0) });
662
661
  skewX ? skewX = -rotation : skewY = rotation;
663
662
  return { origin, skewX, skewY };
@@ -780,7 +779,7 @@ class EditBox extends Group {
780
779
  create() {
781
780
  let rotatePoint, resizeLine, resizePoint;
782
781
  const { view, resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this;
783
- const arounds = [{ x: 1, y: 1 }, { x: 0.5, y: 1 }, { x: 0, y: 1 }, { x: 0, y: 0.5 }, { x: 0, y: 0 }, { x: 0.5, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 0.5 }];
782
+ const arounds = ['bottom-right', 'bottom', 'bottom-left', 'left', 'top-left', 'top', 'top-right', 'right'];
784
783
  for (let i = 0; i < 8; i++) {
785
784
  rotatePoint = new EditPoint({ name: 'rotate-point', around: arounds[i], width: 15, height: 15, hitFill: "all" });
786
785
  rotatePoints.push(rotatePoint);
@@ -1064,7 +1063,7 @@ ${filterStyle}
1064
1063
  `;
1065
1064
 
1066
1065
  const config = {
1067
- editSize: 'auto',
1066
+ editSize: 'size',
1068
1067
  keyEvent: true,
1069
1068
  stroke: '#836DFF',
1070
1069
  strokeWidth: 2,
@@ -1275,18 +1274,12 @@ class Editor extends Group {
1275
1274
  this.editTool.load();
1276
1275
  }
1277
1276
  }
1278
- getEditSize(ui) {
1279
- let { editSize } = this.mergeConfig;
1280
- return editSize === 'auto' ? ui.editSize : editSize;
1277
+ getEditSize(_ui) {
1278
+ return this.mergeConfig.editSize;
1281
1279
  }
1282
1280
  onMove(e) {
1283
1281
  const total = { x: e.totalX, y: e.totalY };
1284
- const { lockMove } = this.mergeConfig;
1285
- if (lockMove === 'x')
1286
- total.y = 0;
1287
- else if (lockMove === 'y')
1288
- total.x = 0;
1289
- else if (e.shiftKey) {
1282
+ if (e.shiftKey) {
1290
1283
  if (Math.abs(total.x) > Math.abs(total.y))
1291
1284
  total.y = 0;
1292
1285
  else
@@ -1341,7 +1334,7 @@ class Editor extends Group {
1341
1334
  this.skewOf(origin, skewX, skewY);
1342
1335
  }
1343
1336
  move(x, y = 0) {
1344
- if (!this.mergeConfig.moveable)
1337
+ if (!this.mergeConfig.moveable || this.element.locked)
1345
1338
  return;
1346
1339
  const { element } = this;
1347
1340
  const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
@@ -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,Event as l,defineKey as h,UI as d,Paint as c,Rect as g,Answer as u,Bounds as f,LeafList as p,PointHelper as m,AroundHelper as y,Direction9 as v,MathHelper as L,Matrix as w,Debug as b,DataHelper as _,LeafHelper as k,RenderEvent as x,getPointData as E,Creator as M}from"@leafer-ui/draw";import{PointerEvent as S,DragEvent as T,MoveEvent as V,ZoomEvent as O,RotateEvent as H,KeyEvent as P}from"@leafer-ui/core";const{M:C,L:I,C:D,Q:R,Z:A,N:B,D:Z,X:z,G:W,F:X,O:Y,P:U,U:F}=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 C:case I:j(t,e,i,o,1),o+=3;break;case D:j(t,e,i,o,3),o+=7;break;case R:j(t,e,i,o,2),o+=5;break;case A:o+=1;break;case B:j(t,e,i,o,2),o+=5;break;case Z:j(t,e,i,o,2),o+=9;break;case z:j(t,e,i,o,2),o+=6;break;case W:j(t,e,i,o,2),o+=9;break;case X:j(t,e,i,o,2),o+=5;break;case Y:t[o]=W,t.splice(o+4,0,t[o+3],0),j(t,e,i,o,2),o+=9,n+=2;break;case U:t[o]=X,t.splice(o+4,0,t[o+3]),j(t,e,i,o,2),o+=5,n+=1;break;case F:j(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:j}=G;function K(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){K(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):K(this,t,e)};const N=n.get();function $(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)N.a=e,N.d=i,s[t].transform(N,!0)}function q(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function Q(t){return t?t instanceof Array?t:[t]:[]}r.prototype.__scaleResize=function(t,e){$(this,t,e)},a.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?$(this,t,e):K(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class J extends l{get list(){return Q(this.value)}get oldList(){return Q(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}J.SELECT="editor.select",J.HOVER="editor.hover";class tt extends J{constructor(t,e){super(t,e)}}tt.MOVE="editor.move";class et extends J{constructor(t,e){super(t,e)}}et.SCALE="editor.scale";class it extends J{constructor(t,e){super(t,e)}}it.ROTATE="editor.rotate";class st extends J{constructor(t,e){super(t,e)}}function ot(t){return(e,i)=>{const s="_"+i;h(e,i,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}st.SKEW="editor.skew";const nt=n.get(),{abs:rt}=Math,{copy:at,scale:lt}=n;class ht extends d{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let s;const{stroke:o,strokeWidth:n,fill:r}=this.__,{bounds:a}=e;for(let l=0;l<i.length;l++)if(s=i[l],a&&a.hit(s.__world,e.matrix)){let i;if("scale"===s.__.editSize){const o=rt(s.__world.scaleX),r=rt(s.__world.scaleY);if(o!==r){at(nt,s.__world),lt(nt,1/o,1/r),t.setWorld(nt,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:a,y:l,width:h,height:d}=s.__layout.boxBounds;t.rect(a*o,l*r,h*o,d*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/rt(s.__world.scaleX)),o&&("string"==typeof o?c.stroke(o,this,t):c.strokes(o,this,t)),r&&("string"==typeof r?c.fill(r,this,t):c.fills(r,this,t))}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}q([ot((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],ht.prototype,"target",void 0);class dt extends r{constructor(t){super(t),this.strokeArea=new g({strokeAlign:"center"}),this.fillArea=new g,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:ct,Yes:gt,NoAndSkip:ut,YesAndSkip:ft}=u,pt={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?ft:ut;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?ft:ct;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return gt}return ct}return t.isBranch?ut:ct}},{findOne:mt}=pt;class yt extends r{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new ht,this.targetStroker=new ht,this.bounds=new f,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,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.mergeConfig;"press"===e&&this.checkAndSelect(t)}onTap(t){const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i&&this.checkAndSelect(t),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(this.allowDrag(t)){const{editor:e}=this,{stroke:i,area:s}=e.mergeConfig,{x:o,y:n}=t.getInner(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new p(e.app.find(pt.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}}onDragEnd(){this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!mt(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new p(this.editor.editBox.rect)};return mt(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):mt(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(J.HOVER,this.onHover,this),t.on_(J.SELECT,this.onSelect,this),e.on_(S.MOVE,this.onPointerMove,this),e.on_(S.BEFORE_DOWN,this.onBeforeDown,this),e.on_(S.TAP,this.onTap,this),e.on_(T.START,this.onDragStart,this),e.on_(T.DRAG,this.onDrag,this),e.on_(T.END,this.onDragEnd,this),e.on_(V.MOVE,this.onAutoMove,this),e.on_([O.ZOOM,V.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:vt,top:Lt,topRight:wt,right:bt,bottomRight:_t,bottom:kt,bottomLeft:xt,left:Et}=v,{toPoint:Mt}=y,St={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 Lt:a=d,n={x:.5,y:1};break;case bt:r=c,n={x:0,y:.5};break;case kt:a=g,n={x:.5,y:0};break;case Et:r=u,n={x:1,y:.5};break;case vt:a=d,r=u,n={x:1,y:1};break;case wt:a=d,r=c,n={x:0,y:1};break;case _t:a=g,r=c,n={x:0,y:0};break;case xt:a=g,r=u,n={x:1,y:0}}if(s){"corner"===s&&e%2||(r=a=Math.sqrt(r*a))}return Mt(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 wt:n={x:0,y:1};break;case _t:n={x:0,y:0};break;case xt:n={x:1,y:0};break;default:n={x:.5,y:.5}}return Mt(o||n,t,n),{origin:n,rotation:m.getRotation(s,n,i)}},getSkewData(t,e,i,s){let o,n,r=0,a=0;switch(e){case Lt:n={x:.5,y:0},o={x:.5,y:1},r=1;break;case kt:n={x:.5,y:1},o={x:.5,y:0},r=1;break;case Et:n={x:0,y:.5},o={x:1,y:.5},a=1;break;case bt:n={x:1,y:.5},o={x:0,y:.5},a=1}const{x:l,y:h,width:d,height:c}=t;n.x=l+n.x*d,n.y=h+n.y*c,Mt(s||o,t,o);const g=m.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 Et:t=bt;break;case vt:t=wt;break;case xt:t=_t;break;case bt:t=Et;break;case wt:t=vt;break;case _t:t=xt}if(i)switch(t){case Lt:t=kt;break;case vt:t=xt;break;case wt:t=_t;break;case kt:t=Lt;break;case xt:t=vt;break;case _t:t=wt}return t}},Tt={};function Vt(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.editing||!i.visible)return;if("circle"===s.name)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:l,rotateable:h,skewable:d}=t.mergeConfig,{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*(St.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(L.formatRotation(o,!0)/2);const{url:m,x:y,y:v}=p,w=m+o;Tt[w]?s.cursor=Tt[w]:Tt[w]=s.cursor={url:Ht(m,o),x:y,y:v}}function Ot(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function Ht(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Pt extends a{}const Ct=["top","right","bottom","left"];class It extends r{get flipped(){return this.flippedX||this.flippedY}get flippedX(){return this.scaleX<0}get flippedY(){return this.scaleY<0}get flippedOne(){return this.scaleX*this.scaleY<0}constructor(t){super(),this.view=new r,this.rect=new a({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Pt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new r({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:l,buttons:h}=this,d=[{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 s=0;s<8;s++)t=new Pt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Pt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Pt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);h.add(l),this.listenPointEvents(l,"rotate",2),s.addMany(...n,a,h,...r,...o),this.add(s)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth:a,moveable:l}=t,h=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:h[t/2%h.length])),t%2||(c.rotation=t/2*90);o.set(this.getPointStyle(t.rotatePoint||h[0])),s.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),s.hittable=!i&&l,e.syncEventer=i&&l?s:null,this.app.interaction.bottomList=i&&l?[{target:s,proxy:e}]:null,this.visible=!e.locked}update(t){if(this.view.worldOpacity){const{mergeConfig:e}=this.editor,{width:i,height:s}=t,{rect:o,circle:n,resizePoints:r,rotatePoints:a,resizeLines:l}=this,{middlePoint:h,resizeable:d,rotateable:c,hideOnSmall:g}=e,u="number"==typeof g?g:10,f=!(g&&i<u&&s<u);let p,m,v,L={};for(let o=0;o<8;o++)y.toPoint(y.directionData[o],t,L),m=r[o],p=a[o],v=l[Math.floor(o/2)],m.set(L),p.set(L),v.set(L),m.visible=v.visible=f&&(d||c),p.visible=f&&c&&d&&!e.rotatePoint,o%2&&(m.visible=p.visible=f&&!!h,(o+1)/2%2?(v.width=i,m.width>i-30&&(m.visible=!1)):(v.height=s,m.rotation=90,m.width>s-30&&(m.visible=!1)));n.visible=f&&c&&!!e.rotatePoint,o.set(Object.assign(Object.assign({},t),{visible:!0}));const w=f&&(n.visible||this.buttons.children.length>1);this.buttons.visible=w,w&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.mergeConfig,{flippedX:r,flippedY:a}=this;let l=Ct.indexOf(i);(l%2&&r||(l+1)%2&&a)&&s&&(l=(l+2)%4);const h=s?St.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,d=e[2*h+1],c=h%2,g=h&&3!==h?1:-1,u=(o+(l%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),s&&(t.rotation=90*(h-l),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.mergeConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=this.app.interaction.bottomList=null)}onDragStart(t){if(this.dragging=!0,"rect"===t.current.name){const{editor:t}=this;this.moving=!0,t.dragStartPoint={x:t.element.x,y:t.element.y},t.opacity=t.mergeConfig.hideOnMove?0:1}}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):e.onScale(t),Vt(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(T.START,this.onDragStart,this),t.on_(T.DRAG,this.onDrag,this),t.on_(T.END,this.onDragEnd,this),t.on_(S.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(S.ENTER,(e=>{this.enterPoint=t,Vt(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(J.SELECT,this.onSelect,this),t.on_(T.START,this.onDragStart,this),t.on_(T.DRAG,e.onMove,e),t.on_(T.END,this.onDragEnd,this),t.on_(S.ENTER,(()=>Ot(e))),t.on_(S.DOUBLE_TAP,this.onDoubleTap,this),t.on_(S.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Dt='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',Rt={editSize:"auto",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${Dt}\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${Dt}\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${Dt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};const At=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Bt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Zt={group(t,e,i){t.sort(Bt);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new r(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(At);const a=new w(e.worldTransform);return a.divideParent(o.worldTransform),n.setTransform(a),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(At),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Bt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},zt=b.get("EditToolCreator");function Wt(){return t=>{Yt.register(t)}}const Xt=Wt,Yt={list:{},register(t){const{tag:e}=t.prototype;Ut[e]?zt.repeat(e):Ut[e]=t},get:(t,e)=>new Ut[t](e)},{list:Ut}=Yt;class Ft extends r{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,e){super(e),this.config=Rt,this.mergeConfig=Rt,this.leafList=new p,this.openedGroupList=new p,this.simulateTarget=new g({visible:!1}),this.editBox=new It(this),this.editToolList={},this.selector=new yt(this),this.targetEventIds=[],t&&(this.config=_.default(t,this.config)),this.addMany(this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||Yt.get(t,this);const{editConfig:e}=this.element;this.mergeConfig=this.single&&e?Object.assign(Object.assign({},this.mergeConfig),e):this.config,this.editBox.load(),this.editTool.load()}}getEditSize(t){let{editSize:e}=this.mergeConfig;return"auto"===e?t.editSize:e}onMove(t){const e={x:t.totalX,y:t.totalY},{lockMove:i}=this.mergeConfig;"x"===i?e.y=0:"y"===i?e.x=0:t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(T.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.mergeConfig;t.shiftKey&&(o=!0);const n=St.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,St.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.mergeConfig,{direction:o,name:n}=t.current;if(e&&"resize-line"===n)return this.onSkew(t);const{element:r}=this;let a,l;if(t instanceof H)l=t.rotation,a=r.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},s=St.getRotateData(r.boxBounds,o,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");l=s.rotation,a=s.origin}l=L.getGapRotation(l,s,r.rotation),l&&(r.scaleX*r.scaleY<0&&(l=-l),this.rotateOf(a,L.float(l,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=St.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),St.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e=0){if(!this.mergeConfig.moveable)return;const{element:i}=this,s=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),o=new tt(tt.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 et(et.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 w(o.worldTransform);o.scaleOf(t,e,i),r=new w(o.worldTransform).divide(s)}const a=new et(et.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 w(i.worldTransform);i.rotateOf(t,e),o=new w(i.worldTransform).divide(s)}const n=new it(it.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 w(o.worldTransform);o.skewOf(t,e,i),r=new w(o.worldTransform).divide(s)}const a=new st(st.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=Zt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=Zt.ungroup(this.list)),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!k.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}}openInnerEditor(){if(this.single){const t=this.element.editInner;t&&Yt.list[t]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[t]||Yt.get(t,this),this.innerEditor.load())}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.innerEditor.unload(),this.editTool.load(),this.innerEditor=null)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(Zt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Zt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(x.START,this.update,this),t.on_([P.HOLD,P.UP],(t=>{Vt(this,t)})),t.on_(P.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}q([ot((function(t,e){t.emitEvent(new J(J.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Ft.prototype,"hoverTarget",void 0),q([ot((function(t,e){const{target:i}=t;i?t.leafList=i instanceof p?i:new p(i):t.leafList.reset(),t.emitEvent(new J(J.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:i}=t,{x:s,y:o,width:n,height:r}=(new f).setListWithFn(i.list,(t=>t.worldBoxBounds)),a=e.parent=i.list[0].leafer.zoomLayer,{scaleX:l,scaleY:h,e:d,f:c}=a.__world;e.reset({x:(s-d)/l,y:(o-c)/h,width:n/l,height:r/h})}(t),Ot(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],Ft.prototype,"target",void 0);class Gt{static registerInnerEditor(){Yt.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new r,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let jt=class extends Gt{static registerEditTool(){Yt.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="size"===o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{simulateTarget:i,element:s}=t;t.multiple&&i.parent.updateLayout();const{x:o,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d,width:c,height:g}=s.getLayoutBounds("box",t,!0);e.set({x:o,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};jt=q([Wt()],jt);const{left:Kt,right:Nt}=v;let $t=class extends jt{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=E(),{toPoint:a}=n;n.rotation=0;let{x:l,y:h}=e.getInnerMove(n);s&&(Math.abs(l)>Math.abs(h)?h=0:l=0),i===Kt?(r.x+=l,r.y+=h,o&&(a.x-=l,a.y-=h)):(o&&(r.x-=l,r.y-=h),a.x+=l,a.y+=h),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){}onUpdate(){const{rotatePoints:t,resizeLines:e,resizePoints:i}=this.editor.editBox;for(let s=0;s<8;s++)s<4&&(e[s].visible=!1),i[s].visible=t[s].visible=s===Kt||s===Nt}};$t=q([Wt()],$t),M.editor=function(t){return new Ft(t)},d.setEditConfig=function(t){h(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},d.setEditOuter=function(t){h(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},d.setEditInner=function(t){h(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})},s.setEditOuter((function(t){return t.points||t.pathInputed?"EditTool":"LineEditTool"}));export{It as EditBox,St as EditDataHelper,Pt as EditPoint,yt as EditSelect,pt as EditSelectHelper,jt as EditTool,Yt as EditToolCreator,Ft as Editor,J as EditorEvent,Zt as EditorHelper,tt as EditorMoveEvent,it as EditorRotateEvent,et as EditorScaleEvent,st as EditorSkewEvent,Gt as InnerEditor,$t as LineEditTool,dt as SelectArea,ht as Stroker,Wt as registerEditTool,Xt as registerInnerEditor};
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,Event as l,defineKey as h,UI as d,Paint as c,Rect as g,Answer as u,Bounds as f,LeafList as p,PointHelper as m,AroundHelper as v,Direction9 as L,MathHelper as b,Matrix as w,Debug as y,DataHelper as _,LeafHelper as k,RenderEvent as E,getPointData as x,Creator as M}from"@leafer-ui/draw";import{PointerEvent as S,DragEvent as T,MoveEvent as V,ZoomEvent as O,RotateEvent as H,KeyEvent as P}from"@leafer-ui/core";const{M:C,L:I,C:D,Q:R,Z:A,N:B,D:Z,X:z,G:W,F:X,O:Y,P:U,U:F}=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 C:case I:j(t,e,i,o,1),o+=3;break;case D:j(t,e,i,o,3),o+=7;break;case R:j(t,e,i,o,2),o+=5;break;case A:o+=1;break;case B:j(t,e,i,o,2),o+=5;break;case Z:j(t,e,i,o,2),o+=9;break;case z:j(t,e,i,o,2),o+=6;break;case W:j(t,e,i,o,2),o+=9;break;case X:j(t,e,i,o,2),o+=5;break;case Y:t[o]=W,t.splice(o+4,0,t[o+3],0),j(t,e,i,o,2),o+=9,n+=2;break;case U:t[o]=X,t.splice(o+4,0,t[o+3]),j(t,e,i,o,2),o+=5,n+=1;break;case F:j(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:j}=G;function K(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){K(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):K(this,t,e)};const N=n.get();function $(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)N.a=e,N.d=i,s[t].transform(N,!0)}function q(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function Q(t){return t?t instanceof Array?t:[t]:[]}r.prototype.__scaleResize=function(t,e){$(this,t,e)},a.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?$(this,t,e):K(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class J extends l{get list(){return Q(this.value)}get oldList(){return Q(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}J.SELECT="editor.select",J.HOVER="editor.hover";class tt extends J{constructor(t,e){super(t,e)}}tt.MOVE="editor.move";class et extends J{constructor(t,e){super(t,e)}}et.SCALE="editor.scale";class it extends J{constructor(t,e){super(t,e)}}it.ROTATE="editor.rotate";class st extends J{constructor(t,e){super(t,e)}}function ot(t){return(e,i)=>{const s="_"+i;h(e,i,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}st.SKEW="editor.skew";const nt=n.get(),{abs:rt}=Math,{copy:at,scale:lt}=n;class ht extends d{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let s;const{stroke:o,strokeWidth:n,fill:r}=this.__,{bounds:a}=e;for(let l=0;l<i.length;l++)if(s=i[l],a&&a.hit(s.__world,e.matrix)){const i=rt(s.__world.scaleX),a=rt(s.__world.scaleY);if(i!==a){at(nt,s.__world),lt(nt,1/i,1/a),t.setWorld(nt,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:o,y:r,width:l,height:h}=s.__layout.boxBounds;t.rect(o*i,r*a,l*i,h*a)}else t.setWorld(s.__world,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),this.__.strokeWidth=n/rt(s.__world.scaleX);o&&("string"==typeof o?c.stroke(o,this,t):c.strokes(o,this,t)),r&&("string"==typeof r?c.fill(r,this,t):c.fills(r,this,t))}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}q([ot((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],ht.prototype,"target",void 0);class dt extends r{constructor(t){super(t),this.strokeArea=new g({strokeAlign:"center"}),this.fillArea=new g,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:ct,Yes:gt,NoAndSkip:ut,YesAndSkip:ft}=u,pt={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?ft:ut;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?ft:ct;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return gt}return ct}return t.isBranch?ut:ct}},{findOne:mt}=pt;class vt extends r{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new ht,this.targetStroker=new ht,this.bounds=new f,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,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.mergeConfig;"press"===e&&this.checkAndSelect(t)}onTap(t){const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i&&this.checkAndSelect(t),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(this.allowDrag(t)){const{editor:e}=this,{stroke:i,area:s}=e.mergeConfig,{x:o,y:n}=t.getInner(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new p(e.app.find(pt.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}}onDragEnd(){this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!mt(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new p(this.editor.editBox.rect)};return mt(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):mt(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(J.HOVER,this.onHover,this),t.on_(J.SELECT,this.onSelect,this),e.on_(S.MOVE,this.onPointerMove,this),e.on_(S.BEFORE_DOWN,this.onBeforeDown,this),e.on_(S.TAP,this.onTap,this),e.on_(T.START,this.onDragStart,this),e.on_(T.DRAG,this.onDrag,this),e.on_(T.END,this.onDragEnd,this),e.on_(V.MOVE,this.onAutoMove,this),e.on_([O.ZOOM,V.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:Lt,top:bt,topRight:wt,right:yt,bottomRight:_t,bottom:kt,bottomLeft:Et,left:xt}=L,{toPoint:Mt}=v,St={getScaleData(t,e,i,s,o){let n,r={},a=1,l=1;const{width:h,height:d}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===h&&(i.x+=.1),Math.abs(i.y)===d&&(i.y+=.1);const c=(-i.y+d)/d,g=(i.x+h)/h,u=(i.y+d)/d,f=(-i.x+h)/h;switch(e){case bt:l=c,n="bottom";break;case yt:a=g,n="left";break;case kt:l=u,n="top";break;case xt:a=f,n="right";break;case Lt:l=c,a=f,n="bottom-right";break;case wt:l=c,a=g,n="bottom-left";break;case _t:l=u,a=g,n="top-left";break;case Et:l=u,a=f,n="top-right"}if(s){if(!("corner"===s&&e%2)){const t=Math.sqrt(Math.abs(a*l));a=a<0?-t:t,l=l<0?-t:t}}return Mt(o||n,t,r),{origin:r,scaleX:a,scaleY:l,direction:e,lockRatio:s,around:o}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case Lt:n="bottom-right";break;case wt:n="bottom-left";break;case _t:n="top-left";break;case Et:n="top-right";break;default:n="center"}return Mt(o||n,t,r),{origin:r,rotation:m.getRotation(s,r,i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,l=0;switch(e){case bt:n={x:.5,y:0},o="bottom",a=1;break;case kt:n={x:.5,y:1},o="top",a=1;break;case xt:n={x:0,y:.5},o="right",l=1;break;case yt:n={x:1,y:.5},o="left",l=1}const{x:h,y:d,width:c,height:g}=t;n.x=h+n.x*c,n.y=d+n.y*g,Mt(s||o,t,r);const u=m.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(l?i.y:0)});return a?a=-u:l=u,{origin:r,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 xt:t=yt;break;case Lt:t=wt;break;case Et:t=_t;break;case yt:t=xt;break;case wt:t=Lt;break;case _t:t=Et}if(i)switch(t){case bt:t=kt;break;case Lt:t=Et;break;case wt:t=_t;break;case kt:t=bt;break;case Et:t=Lt;break;case _t:t=wt}return t}},Tt={};function Vt(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.editing||!i.visible)return;if("circle"===s.name)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:l,rotateable:h,skewable:d}=t.mergeConfig,{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*(St.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(b.formatRotation(o,!0)/2);const{url:m,x:v,y:L}=p,w=m+o;Tt[w]?s.cursor=Tt[w]:Tt[w]=s.cursor={url:Ht(m,o),x:v,y:L}}function Ot(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function Ht(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Pt extends a{}const Ct=["top","right","bottom","left"];class It extends r{get flipped(){return this.flippedX||this.flippedY}get flippedX(){return this.scaleX<0}get flippedY(){return this.scaleY<0}get flippedOne(){return this.scaleX*this.scaleY<0}constructor(t){super(),this.view=new r,this.rect=new a({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Pt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new r({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:l,buttons:h}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new Pt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Pt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Pt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);h.add(l),this.listenPointEvents(l,"rotate",2),s.addMany(...n,a,h,...r,...o),this.add(s)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth:a,moveable:l}=t,h=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:h[t/2%h.length])),t%2||(c.rotation=t/2*90);o.set(this.getPointStyle(t.rotatePoint||h[0])),s.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),s.hittable=!i&&l,e.syncEventer=i&&l?s:null,this.app.interaction.bottomList=i&&l?[{target:s,proxy:e}]:null,this.visible=!e.locked}update(t){if(this.view.worldOpacity){const{mergeConfig:e}=this.editor,{width:i,height:s}=t,{rect:o,circle:n,resizePoints:r,rotatePoints:a,resizeLines:l}=this,{middlePoint:h,resizeable:d,rotateable:c,hideOnSmall:g}=e,u="number"==typeof g?g:10,f=!(g&&i<u&&s<u);let p,m,L,b={};for(let o=0;o<8;o++)v.toPoint(v.directionData[o],t,b),m=r[o],p=a[o],L=l[Math.floor(o/2)],m.set(b),p.set(b),L.set(b),m.visible=L.visible=f&&(d||c),p.visible=f&&c&&d&&!e.rotatePoint,o%2&&(m.visible=p.visible=f&&!!h,(o+1)/2%2?(L.width=i,m.width>i-30&&(m.visible=!1)):(L.height=s,m.rotation=90,m.width>s-30&&(m.visible=!1)));n.visible=f&&c&&!!e.rotatePoint,o.set(Object.assign(Object.assign({},t),{visible:!0}));const w=f&&(n.visible||this.buttons.children.length>1);this.buttons.visible=w,w&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.mergeConfig,{flippedX:r,flippedY:a}=this;let l=Ct.indexOf(i);(l%2&&r||(l+1)%2&&a)&&s&&(l=(l+2)%4);const h=s?St.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,d=e[2*h+1],c=h%2,g=h&&3!==h?1:-1,u=(o+(l%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),s&&(t.rotation=90*(h-l),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.mergeConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=this.app.interaction.bottomList=null)}onDragStart(t){if(this.dragging=!0,"rect"===t.current.name){const{editor:t}=this;this.moving=!0,t.dragStartPoint={x:t.element.x,y:t.element.y},t.opacity=t.mergeConfig.hideOnMove?0:1}}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):e.onScale(t),Vt(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(T.START,this.onDragStart,this),t.on_(T.DRAG,this.onDrag,this),t.on_(T.END,this.onDragEnd,this),t.on_(S.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(S.ENTER,(e=>{this.enterPoint=t,Vt(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(J.SELECT,this.onSelect,this),t.on_(T.START,this.onDragStart,this),t.on_(T.DRAG,e.onMove,e),t.on_(T.END,this.onDragEnd,this),t.on_(S.ENTER,(()=>Ot(e))),t.on_(S.DOUBLE_TAP,this.onDoubleTap,this),t.on_(S.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Dt='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',Rt={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${Dt}\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${Dt}\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${Dt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};const At=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Bt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Zt={group(t,e,i){t.sort(Bt);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new r(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(At);const a=new w(e.worldTransform);return a.divideParent(o.worldTransform),n.setTransform(a),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(At),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Bt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},zt=y.get("EditToolCreator");function Wt(){return t=>{Yt.register(t)}}const Xt=Wt,Yt={list:{},register(t){const{tag:e}=t.prototype;Ut[e]?zt.repeat(e):Ut[e]=t},get:(t,e)=>new Ut[t](e)},{list:Ut}=Yt;class Ft extends r{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,e){super(e),this.config=Rt,this.mergeConfig=Rt,this.leafList=new p,this.openedGroupList=new p,this.simulateTarget=new g({visible:!1}),this.editBox=new It(this),this.editToolList={},this.selector=new vt(this),this.targetEventIds=[],t&&(this.config=_.default(t,this.config)),this.addMany(this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||Yt.get(t,this);const{editConfig:e}=this.element;this.mergeConfig=this.single&&e?Object.assign(Object.assign({},this.mergeConfig),e):this.config,this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){const e={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(T.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.mergeConfig;t.shiftKey&&(o=!0);const n=St.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,St.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.mergeConfig,{direction:o,name:n}=t.current;if(e&&"resize-line"===n)return this.onSkew(t);const{element:r}=this;let a,l;if(t instanceof H)l=t.rotation,a=r.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},s=St.getRotateData(r.boxBounds,o,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");l=s.rotation,a=s.origin}l=b.getGapRotation(l,s,r.rotation),l&&(r.scaleX*r.scaleY<0&&(l=-l),this.rotateOf(a,b.float(l,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=St.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),St.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e=0){if(!this.mergeConfig.moveable||this.element.locked)return;const{element:i}=this,s=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),o=new tt(tt.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 et(et.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 w(o.worldTransform);o.scaleOf(t,e,i),r=new w(o.worldTransform).divide(s)}const a=new et(et.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 w(i.worldTransform);i.rotateOf(t,e),o=new w(i.worldTransform).divide(s)}const n=new it(it.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 w(o.worldTransform);o.skewOf(t,e,i),r=new w(o.worldTransform).divide(s)}const a=new st(st.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=Zt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=Zt.ungroup(this.list)),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!k.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}}openInnerEditor(){if(this.single){const t=this.element.editInner;t&&Yt.list[t]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[t]||Yt.get(t,this),this.innerEditor.load())}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.innerEditor.unload(),this.editTool.load(),this.innerEditor=null)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(Zt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Zt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(E.START,this.update,this),t.on_([P.HOLD,P.UP],(t=>{Vt(this,t)})),t.on_(P.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}q([ot((function(t,e){t.emitEvent(new J(J.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Ft.prototype,"hoverTarget",void 0),q([ot((function(t,e){const{target:i}=t;i?t.leafList=i instanceof p?i:new p(i):t.leafList.reset(),t.emitEvent(new J(J.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:i}=t,{x:s,y:o,width:n,height:r}=(new f).setListWithFn(i.list,(t=>t.worldBoxBounds)),a=e.parent=i.list[0].leafer.zoomLayer,{scaleX:l,scaleY:h,e:d,f:c}=a.__world;e.reset({x:(s-d)/l,y:(o-c)/h,width:n/l,height:r/h})}(t),Ot(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],Ft.prototype,"target",void 0);class Gt{static registerInnerEditor(){Yt.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new r,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let jt=class extends Gt{static registerEditTool(){Yt.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="size"===o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="size"===n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{simulateTarget:i,element:s}=t;t.multiple&&i.parent.updateLayout();const{x:o,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d,width:c,height:g}=s.getLayoutBounds("box",t,!0);e.set({x:o,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};jt=q([Wt()],jt);const{left:Kt,right:Nt}=L;let $t=class extends jt{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=x(),{toPoint:a}=n;n.rotation=0;let{x:l,y:h}=e.getInnerMove(n);s&&(Math.abs(l)>Math.abs(h)?h=0:l=0),i===Kt?(r.x+=l,r.y+=h,o&&(a.x-=l,a.y-=h)):(o&&(r.x-=l,r.y-=h),a.x+=l,a.y+=h),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){}onUpdate(){const{rotatePoints:t,resizeLines:e,resizePoints:i}=this.editor.editBox;for(let s=0;s<8;s++)s<4&&(e[s].visible=!1),i[s].visible=t[s].visible=s===Kt||s===Nt}};$t=q([Wt()],$t),M.editor=function(t){return new Ft(t)},d.setEditConfig=function(t){h(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},d.setEditOuter=function(t){h(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},d.setEditInner=function(t){h(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})},s.setEditOuter((function(t){return t.points||t.pathInputed?"EditTool":"LineEditTool"}));export{It as EditBox,St as EditDataHelper,Pt as EditPoint,vt as EditSelect,pt as EditSelectHelper,jt as EditTool,Yt as EditToolCreator,Ft as Editor,J as EditorEvent,Zt as EditorHelper,tt as EditorMoveEvent,it as EditorRotateEvent,et as EditorScaleEvent,st as EditorSkewEvent,Gt as InnerEditor,$t as LineEditTool,dt as SelectArea,ht as Stroker,Wt as registerEditTool,Xt as registerInnerEditor};
package/dist/editor.js CHANGED
@@ -259,21 +259,17 @@ this.LeaferIN.editor = (function (exports, draw, core) {
259
259
  for (let i = 0; i < list.length; i++) {
260
260
  leaf = list[i];
261
261
  if (bounds && bounds.hit(leaf.__world, options.matrix)) {
262
- let drewPath;
263
- if (leaf.__.editSize === 'scale') {
264
- const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
265
- if (aScaleX !== aScaleY) {
266
- copy(matrix, leaf.__world);
267
- scale(matrix, 1 / aScaleX, 1 / aScaleY);
268
- canvas.setWorld(matrix, options.matrix);
269
- canvas.beginPath();
270
- this.__.strokeWidth = strokeWidth;
271
- const { x, y, width, height } = leaf.__layout.boxBounds;
272
- canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
273
- drewPath = true;
274
- }
262
+ const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
263
+ if (aScaleX !== aScaleY) {
264
+ copy(matrix, leaf.__world);
265
+ scale(matrix, 1 / aScaleX, 1 / aScaleY);
266
+ canvas.setWorld(matrix, options.matrix);
267
+ canvas.beginPath();
268
+ this.__.strokeWidth = strokeWidth;
269
+ const { x, y, width, height } = leaf.__layout.boxBounds;
270
+ canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
275
271
  }
276
- if (!drewPath) {
272
+ else {
277
273
  canvas.setWorld(leaf.__world, options.matrix);
278
274
  canvas.beginPath();
279
275
  if (leaf.__.__useArrow) {
@@ -551,7 +547,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
551
547
  const { toPoint } = draw.AroundHelper;
552
548
  const EditDataHelper = {
553
549
  getScaleData(bounds, direction, pointMove, lockRatio, around) {
554
- let origin, scaleX = 1, scaleY = 1;
550
+ let align, origin = {}, scaleX = 1, scaleY = 1;
555
551
  const { width, height } = bounds;
556
552
  if (around) {
557
553
  pointMove.x *= 2;
@@ -568,97 +564,100 @@ this.LeaferIN.editor = (function (exports, draw, core) {
568
564
  switch (direction) {
569
565
  case top:
570
566
  scaleY = topScale;
571
- origin = { x: 0.5, y: 1 };
567
+ align = 'bottom';
572
568
  break;
573
569
  case right$1:
574
570
  scaleX = rightScale;
575
- origin = { x: 0, y: 0.5 };
571
+ align = 'left';
576
572
  break;
577
573
  case bottom:
578
574
  scaleY = bottomScale;
579
- origin = { x: 0.5, y: 0 };
575
+ align = 'top';
580
576
  break;
581
577
  case left$1:
582
578
  scaleX = leftScale;
583
- origin = { x: 1, y: 0.5 };
579
+ align = 'right';
584
580
  break;
585
581
  case topLeft:
586
582
  scaleY = topScale;
587
583
  scaleX = leftScale;
588
- origin = { x: 1, y: 1 };
584
+ align = 'bottom-right';
589
585
  break;
590
586
  case topRight:
591
587
  scaleY = topScale;
592
588
  scaleX = rightScale;
593
- origin = { x: 0, y: 1 };
589
+ align = 'bottom-left';
594
590
  break;
595
591
  case bottomRight:
596
592
  scaleY = bottomScale;
597
593
  scaleX = rightScale;
598
- origin = { x: 0, y: 0 };
594
+ align = 'top-left';
599
595
  break;
600
596
  case bottomLeft:
601
597
  scaleY = bottomScale;
602
598
  scaleX = leftScale;
603
- origin = { x: 1, y: 0 };
599
+ align = 'top-right';
604
600
  }
605
601
  if (lockRatio) {
606
602
  const unlockSide = lockRatio === 'corner' && direction % 2;
607
- if (!unlockSide)
608
- scaleX = scaleY = Math.sqrt(scaleX * scaleY);
603
+ if (!unlockSide) {
604
+ const scale = Math.sqrt(Math.abs(scaleX * scaleY));
605
+ scaleX = scaleX < 0 ? -scale : scale;
606
+ scaleY = scaleY < 0 ? -scale : scale;
607
+ }
609
608
  }
610
- toPoint(around || origin, bounds, origin);
609
+ toPoint(around || align, bounds, origin);
611
610
  return { origin, scaleX, scaleY, direction, lockRatio, around };
612
611
  },
613
612
  getRotateData(bounds, direction, current, last, around) {
614
- let origin;
613
+ let align, origin = {};
615
614
  switch (direction) {
616
615
  case topLeft:
617
- origin = { x: 1, y: 1 };
616
+ align = 'bottom-right';
618
617
  break;
619
618
  case topRight:
620
- origin = { x: 0, y: 1 };
619
+ align = 'bottom-left';
621
620
  break;
622
621
  case bottomRight:
623
- origin = { x: 0, y: 0 };
622
+ align = 'top-left';
624
623
  break;
625
624
  case bottomLeft:
626
- origin = { x: 1, y: 0 };
625
+ align = 'top-right';
627
626
  break;
628
627
  default:
629
- origin = { x: 0.5, y: 0.5 };
628
+ align = 'center';
630
629
  }
631
- toPoint(around || origin, bounds, origin);
630
+ toPoint(around || align, bounds, origin);
632
631
  return { origin, rotation: draw.PointHelper.getRotation(last, origin, current) };
633
632
  },
634
633
  getSkewData(bounds, direction, move, around) {
635
- let origin, skewX = 0, skewY = 0;
634
+ let align, origin = {}, skewX = 0, skewY = 0;
636
635
  let last;
637
636
  switch (direction) {
638
637
  case top:
639
638
  last = { x: 0.5, y: 0 };
640
- origin = { x: 0.5, y: 1 };
639
+ align = 'bottom';
641
640
  skewX = 1;
642
641
  break;
643
642
  case bottom:
644
643
  last = { x: 0.5, y: 1 };
645
- origin = { x: 0.5, y: 0 };
644
+ align = 'top';
646
645
  skewX = 1;
647
646
  break;
648
647
  case left$1:
649
648
  last = { x: 0, y: 0.5 };
650
- origin = { x: 1, y: 0.5 };
649
+ align = 'right';
651
650
  skewY = 1;
652
651
  break;
653
652
  case right$1:
654
653
  last = { x: 1, y: 0.5 };
655
- origin = { x: 0, y: 0.5 };
654
+ align = 'left';
656
655
  skewY = 1;
657
656
  }
658
657
  const { x, y, width, height } = bounds;
659
658
  last.x = x + last.x * width;
660
659
  last.y = y + last.y * height;
661
- toPoint(around || origin, bounds, origin);
660
+ toPoint(around || align, bounds, origin);
662
661
  const rotation = draw.PointHelper.getRotation(last, origin, { x: last.x + (skewX ? move.x : 0), y: last.y + (skewY ? move.y : 0) });
663
662
  skewX ? skewX = -rotation : skewY = rotation;
664
663
  return { origin, skewX, skewY };
@@ -781,7 +780,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
781
780
  create() {
782
781
  let rotatePoint, resizeLine, resizePoint;
783
782
  const { view, resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this;
784
- const arounds = [{ x: 1, y: 1 }, { x: 0.5, y: 1 }, { x: 0, y: 1 }, { x: 0, y: 0.5 }, { x: 0, y: 0 }, { x: 0.5, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 0.5 }];
783
+ const arounds = ['bottom-right', 'bottom', 'bottom-left', 'left', 'top-left', 'top', 'top-right', 'right'];
785
784
  for (let i = 0; i < 8; i++) {
786
785
  rotatePoint = new EditPoint({ name: 'rotate-point', around: arounds[i], width: 15, height: 15, hitFill: "all" });
787
786
  rotatePoints.push(rotatePoint);
@@ -1065,7 +1064,7 @@ ${filterStyle}
1065
1064
  `;
1066
1065
 
1067
1066
  const config = {
1068
- editSize: 'auto',
1067
+ editSize: 'size',
1069
1068
  keyEvent: true,
1070
1069
  stroke: '#836DFF',
1071
1070
  strokeWidth: 2,
@@ -1276,18 +1275,12 @@ ${filterStyle}
1276
1275
  this.editTool.load();
1277
1276
  }
1278
1277
  }
1279
- getEditSize(ui) {
1280
- let { editSize } = this.mergeConfig;
1281
- return editSize === 'auto' ? ui.editSize : editSize;
1278
+ getEditSize(_ui) {
1279
+ return this.mergeConfig.editSize;
1282
1280
  }
1283
1281
  onMove(e) {
1284
1282
  const total = { x: e.totalX, y: e.totalY };
1285
- const { lockMove } = this.mergeConfig;
1286
- if (lockMove === 'x')
1287
- total.y = 0;
1288
- else if (lockMove === 'y')
1289
- total.x = 0;
1290
- else if (e.shiftKey) {
1283
+ if (e.shiftKey) {
1291
1284
  if (Math.abs(total.x) > Math.abs(total.y))
1292
1285
  total.y = 0;
1293
1286
  else
@@ -1342,7 +1335,7 @@ ${filterStyle}
1342
1335
  this.skewOf(origin, skewX, skewY);
1343
1336
  }
1344
1337
  move(x, y = 0) {
1345
- if (!this.mergeConfig.moveable)
1338
+ if (!this.mergeConfig.moveable || this.element.locked)
1346
1339
  return;
1347
1340
  const { element } = this;
1348
1341
  const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);